David Fletcher / Mbed 2 deprecated cc3100_Test_websock_Camera_CM4F

Dependencies:   mbed

Committer:
dflet
Date:
Wed Jun 24 09:54:16 2015 +0000
Revision:
0:50cedd586816
Child:
19:3dd3e7f30f8b
First commit work in progress

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 0:50cedd586816 1 /*
dflet 0:50cedd586816 2 * netapp.c - CC31xx/CC32xx Host Driver Implementation
dflet 0:50cedd586816 3 *
dflet 0:50cedd586816 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 0:50cedd586816 5 *
dflet 0:50cedd586816 6 *
dflet 0:50cedd586816 7 * Redistribution and use in source and binary forms, with or without
dflet 0:50cedd586816 8 * modification, are permitted provided that the following conditions
dflet 0:50cedd586816 9 * are met:
dflet 0:50cedd586816 10 *
dflet 0:50cedd586816 11 * Redistributions of source code must retain the above copyright
dflet 0:50cedd586816 12 * notice, this list of conditions and the following disclaimer.
dflet 0:50cedd586816 13 *
dflet 0:50cedd586816 14 * Redistributions in binary form must reproduce the above copyright
dflet 0:50cedd586816 15 * notice, this list of conditions and the following disclaimer in the
dflet 0:50cedd586816 16 * documentation and/or other materials provided with the
dflet 0:50cedd586816 17 * distribution.
dflet 0:50cedd586816 18 *
dflet 0:50cedd586816 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 0:50cedd586816 20 * its contributors may be used to endorse or promote products derived
dflet 0:50cedd586816 21 * from this software without specific prior written permission.
dflet 0:50cedd586816 22 *
dflet 0:50cedd586816 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 0:50cedd586816 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 0:50cedd586816 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 0:50cedd586816 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 0:50cedd586816 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 0:50cedd586816 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 0:50cedd586816 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 0:50cedd586816 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 0:50cedd586816 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 0:50cedd586816 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 0:50cedd586816 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 0:50cedd586816 34 *
dflet 0:50cedd586816 35 */
dflet 0:50cedd586816 36
dflet 0:50cedd586816 37
dflet 0:50cedd586816 38
dflet 0:50cedd586816 39 /*****************************************************************************/
dflet 0:50cedd586816 40 /* Include files */
dflet 0:50cedd586816 41 /*****************************************************************************/
dflet 0:50cedd586816 42 #include "cc3100_simplelink.h"
dflet 0:50cedd586816 43 #include "cc3100_protocol.h"
dflet 0:50cedd586816 44 #include "cc3100_driver.h"
dflet 0:50cedd586816 45
dflet 0:50cedd586816 46 #include "cc3100_netapp.h"
dflet 0:50cedd586816 47 #include "fPtr_func.h"
dflet 0:50cedd586816 48 #include "cli_uart.h"
dflet 0:50cedd586816 49
dflet 0:50cedd586816 50 namespace mbed_cc3100 {
dflet 0:50cedd586816 51
dflet 0:50cedd586816 52 /*****************************************************************************/
dflet 0:50cedd586816 53 /* Macro declarations */
dflet 0:50cedd586816 54 /*****************************************************************************/
dflet 0:50cedd586816 55 const uint32_t NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT = ((uint32_t)0x1 << 31);
dflet 0:50cedd586816 56
dflet 0:50cedd586816 57 #ifdef SL_TINY
dflet 0:50cedd586816 58 const uint8_t NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH = 63;
dflet 0:50cedd586816 59 #else
dflet 0:50cedd586816 60 const uint8_t NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH = 255;
dflet 0:50cedd586816 61 #endif
dflet 0:50cedd586816 62
dflet 0:50cedd586816 63 #ifndef SL_PLATFORM_MULTI_THREADED
dflet 0:50cedd586816 64 cc3100_netapp::cc3100_netapp(cc3100_driver &driver, cc3100_nonos &nonos)
dflet 0:50cedd586816 65 : _driver(driver), _nonos(nonos)
dflet 0:50cedd586816 66 {
dflet 0:50cedd586816 67 }
dflet 0:50cedd586816 68 #else
dflet 0:50cedd586816 69 cc3100_netapp::cc3100_netapp(cc3100_driver &driver)
dflet 0:50cedd586816 70 : _driver(driver)
dflet 0:50cedd586816 71 {
dflet 0:50cedd586816 72 }
dflet 0:50cedd586816 73 #endif
dflet 0:50cedd586816 74 cc3100_netapp::~cc3100_netapp()
dflet 0:50cedd586816 75 {
dflet 0:50cedd586816 76
dflet 0:50cedd586816 77 }
dflet 0:50cedd586816 78
dflet 0:50cedd586816 79
dflet 0:50cedd586816 80 /*****************************************************************************/
dflet 0:50cedd586816 81 /* API functions */
dflet 0:50cedd586816 82 /*****************************************************************************/
dflet 0:50cedd586816 83
dflet 0:50cedd586816 84 /*****************************************************************************
dflet 0:50cedd586816 85 sl_NetAppStart
dflet 0:50cedd586816 86 *****************************************************************************/
dflet 0:50cedd586816 87 typedef union {
dflet 0:50cedd586816 88 _NetAppStartStopCommand_t Cmd;
dflet 0:50cedd586816 89 _NetAppStartStopResponse_t Rsp;
dflet 0:50cedd586816 90 } _SlNetAppStartStopMsg_u;
dflet 0:50cedd586816 91
dflet 0:50cedd586816 92 #if _SL_INCLUDE_FUNC(sl_NetAppStart)
dflet 0:50cedd586816 93 const _SlCmdCtrl_t _SlNetAppStartCtrl = {
dflet 0:50cedd586816 94 SL_OPCODE_NETAPP_START_COMMAND,
dflet 0:50cedd586816 95 sizeof(_NetAppStartStopCommand_t),
dflet 0:50cedd586816 96 sizeof(_NetAppStartStopResponse_t)
dflet 0:50cedd586816 97 };
dflet 0:50cedd586816 98
dflet 0:50cedd586816 99 int16_t cc3100_netapp::sl_NetAppStart(const uint32_t AppBitMap)
dflet 0:50cedd586816 100 {
dflet 0:50cedd586816 101 _SlNetAppStartStopMsg_u Msg;
dflet 0:50cedd586816 102 Msg.Cmd.appId = AppBitMap;
dflet 0:50cedd586816 103 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStartCtrl, &Msg, NULL));
dflet 0:50cedd586816 104
dflet 0:50cedd586816 105 return Msg.Rsp.status;
dflet 0:50cedd586816 106 }
dflet 0:50cedd586816 107 #endif
dflet 0:50cedd586816 108
dflet 0:50cedd586816 109 /*****************************************************************************
dflet 0:50cedd586816 110 sl_NetAppStop
dflet 0:50cedd586816 111 *****************************************************************************/
dflet 0:50cedd586816 112 #if _SL_INCLUDE_FUNC(sl_NetAppStop)
dflet 0:50cedd586816 113 const _SlCmdCtrl_t _SlNetAppStopCtrl =
dflet 0:50cedd586816 114 {
dflet 0:50cedd586816 115 SL_OPCODE_NETAPP_STOP_COMMAND,
dflet 0:50cedd586816 116 sizeof(_NetAppStartStopCommand_t),
dflet 0:50cedd586816 117 sizeof(_NetAppStartStopResponse_t)
dflet 0:50cedd586816 118 };
dflet 0:50cedd586816 119 int16_t cc3100_netapp::sl_NetAppStop(const uint32_t AppBitMap)
dflet 0:50cedd586816 120 {
dflet 0:50cedd586816 121
dflet 0:50cedd586816 122 _SlNetAppStartStopMsg_u Msg;
dflet 0:50cedd586816 123 Msg.Cmd.appId = AppBitMap;
dflet 0:50cedd586816 124 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStopCtrl, &Msg, NULL));
dflet 0:50cedd586816 125
dflet 0:50cedd586816 126 return Msg.Rsp.status;
dflet 0:50cedd586816 127 }
dflet 0:50cedd586816 128 #endif
dflet 0:50cedd586816 129
dflet 0:50cedd586816 130
dflet 0:50cedd586816 131 /******************************************************************************/
dflet 0:50cedd586816 132 /* sl_NetAppGetServiceList */
dflet 0:50cedd586816 133 /******************************************************************************/
dflet 0:50cedd586816 134 typedef struct {
dflet 0:50cedd586816 135 uint8_t IndexOffest;
dflet 0:50cedd586816 136 uint8_t MaxServiceCount;
dflet 0:50cedd586816 137 uint8_t Flags;
dflet 0:50cedd586816 138 int8_t Padding;
dflet 0:50cedd586816 139 } NetappGetServiceListCMD_t;
dflet 0:50cedd586816 140
dflet 0:50cedd586816 141 typedef union {
dflet 0:50cedd586816 142 NetappGetServiceListCMD_t Cmd;
dflet 0:50cedd586816 143 _BasicResponse_t Rsp;
dflet 0:50cedd586816 144 } _SlNetappGetServiceListMsg_u;
dflet 0:50cedd586816 145
dflet 0:50cedd586816 146 #if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList)
dflet 0:50cedd586816 147 const _SlCmdCtrl_t _SlGetServiceListeCtrl = {
dflet 0:50cedd586816 148 SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE,
dflet 0:50cedd586816 149 sizeof(NetappGetServiceListCMD_t),
dflet 0:50cedd586816 150 sizeof(_BasicResponse_t)
dflet 0:50cedd586816 151 };
dflet 0:50cedd586816 152
dflet 0:50cedd586816 153 int16_t cc3100_netapp::sl_NetAppGetServiceList(const uint8_t IndexOffest,
dflet 0:50cedd586816 154 const uint8_t MaxServiceCount,
dflet 0:50cedd586816 155 const uint8_t Flags,
dflet 0:50cedd586816 156 int8_t *pBuffer,
dflet 0:50cedd586816 157 const uint32_t RxBufferLength
dflet 0:50cedd586816 158 )
dflet 0:50cedd586816 159 {
dflet 0:50cedd586816 160 int32_t retVal= 0;
dflet 0:50cedd586816 161 _SlNetappGetServiceListMsg_u Msg;
dflet 0:50cedd586816 162 _SlCmdExt_t CmdExt;
dflet 0:50cedd586816 163 uint16_t ServiceSize = 0;
dflet 0:50cedd586816 164 uint16_t BufferSize = 0;
dflet 0:50cedd586816 165
dflet 0:50cedd586816 166 /*
dflet 0:50cedd586816 167 Calculate RX pBuffer size
dflet 0:50cedd586816 168 WARNING:
dflet 0:50cedd586816 169 if this size is BufferSize than 1480 error should be returned because there
dflet 0:50cedd586816 170 is no place in the RX packet.
dflet 0:50cedd586816 171 */
dflet 0:50cedd586816 172 switch(Flags) {
dflet 0:50cedd586816 173 case SL_NET_APP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE:
dflet 0:50cedd586816 174 ServiceSize = sizeof(SlNetAppGetFullServiceWithTextIpv4List_t);
dflet 0:50cedd586816 175 break;
dflet 0:50cedd586816 176
dflet 0:50cedd586816 177 case SL_NET_APP_FULL_SERVICE_IPV4_TYPE:
dflet 0:50cedd586816 178 ServiceSize = sizeof(SlNetAppGetFullServiceIpv4List_t);
dflet 0:50cedd586816 179 break;
dflet 0:50cedd586816 180
dflet 0:50cedd586816 181 case SL_NET_APP_SHORT_SERVICE_IPV4_TYPE:
dflet 0:50cedd586816 182 ServiceSize = sizeof(SlNetAppGetShortServiceIpv4List_t);
dflet 0:50cedd586816 183 break;
dflet 0:50cedd586816 184
dflet 0:50cedd586816 185 default:
dflet 0:50cedd586816 186 ServiceSize = sizeof(_BasicResponse_t);
dflet 0:50cedd586816 187 break;
dflet 0:50cedd586816 188 }
dflet 0:50cedd586816 189
dflet 0:50cedd586816 190
dflet 0:50cedd586816 191
dflet 0:50cedd586816 192 BufferSize = MaxServiceCount * ServiceSize;
dflet 0:50cedd586816 193
dflet 0:50cedd586816 194 /*Check the size of the requested services is smaller than size of the user buffer.
dflet 0:50cedd586816 195 If not an error is returned in order to avoid overwriting memory. */
dflet 0:50cedd586816 196 if(RxBufferLength <= BufferSize) {
dflet 0:50cedd586816 197 return SL_ERROR_NETAPP_RX_BUFFER_LENGTH_ERROR;
dflet 0:50cedd586816 198 }
dflet 0:50cedd586816 199
dflet 0:50cedd586816 200 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:50cedd586816 201 CmdExt.RxPayloadLen = BufferSize;
dflet 0:50cedd586816 202
dflet 0:50cedd586816 203 CmdExt.pRxPayload = (uint8_t *)pBuffer;
dflet 0:50cedd586816 204
dflet 0:50cedd586816 205 Msg.Cmd.IndexOffest = IndexOffest;
dflet 0:50cedd586816 206 Msg.Cmd.MaxServiceCount = MaxServiceCount;
dflet 0:50cedd586816 207 Msg.Cmd.Flags = Flags;
dflet 0:50cedd586816 208 Msg.Cmd.Padding = 0;
dflet 0:50cedd586816 209
dflet 0:50cedd586816 210 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetServiceListeCtrl, &Msg, &CmdExt));
dflet 0:50cedd586816 211 retVal = Msg.Rsp.status;
dflet 0:50cedd586816 212
dflet 0:50cedd586816 213 return (int16_t)retVal;
dflet 0:50cedd586816 214 }
dflet 0:50cedd586816 215
dflet 0:50cedd586816 216 #endif
dflet 0:50cedd586816 217
dflet 0:50cedd586816 218 /*****************************************************************************/
dflet 0:50cedd586816 219 /* sl_mDNSRegisterService */
dflet 0:50cedd586816 220 /*****************************************************************************/
dflet 0:50cedd586816 221 /*
dflet 0:50cedd586816 222 * The below struct depicts the constant parameters of the command/API RegisterService.
dflet 0:50cedd586816 223 *
dflet 0:50cedd586816 224 1. ServiceLen - The length of the service should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 225 2. TextLen - The length of the text should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 226 3. port - The port on this target host.
dflet 0:50cedd586816 227 4. TTL - The TTL of the service
dflet 0:50cedd586816 228 5. Options - bitwise parameters:
dflet 0:50cedd586816 229 bit 0 - is unique (means if the service needs to be unique)
dflet 0:50cedd586816 230 bit 31 - for internal use if the service should be added or deleted (set means ADD).
dflet 0:50cedd586816 231 bit 1-30 for future.
dflet 0:50cedd586816 232
dflet 0:50cedd586816 233 NOTE:
dflet 0:50cedd586816 234
dflet 0:50cedd586816 235 1. There are another variable parameter is this API which is the service name and the text.
dflet 0:50cedd586816 236 2. According to now there is no warning and Async event to user on if the service is a unique.
dflet 0:50cedd586816 237 *
dflet 0:50cedd586816 238 */
dflet 0:50cedd586816 239
dflet 0:50cedd586816 240 typedef struct {
dflet 0:50cedd586816 241 uint8_t ServiceNameLen;
dflet 0:50cedd586816 242 uint8_t TextLen;
dflet 0:50cedd586816 243 uint16_t Port;
dflet 0:50cedd586816 244 uint32_t TTL;
dflet 0:50cedd586816 245 uint32_t Options;
dflet 0:50cedd586816 246 } NetappMdnsSetService_t;
dflet 0:50cedd586816 247
dflet 0:50cedd586816 248 typedef union {
dflet 0:50cedd586816 249 NetappMdnsSetService_t Cmd;
dflet 0:50cedd586816 250 _BasicResponse_t Rsp;
dflet 0:50cedd586816 251 } _SlNetappMdnsRegisterServiceMsg_u;
dflet 0:50cedd586816 252
dflet 0:50cedd586816 253 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterUnregisterService)
dflet 0:50cedd586816 254 const _SlCmdCtrl_t _SlRegisterServiceCtrl = {
dflet 0:50cedd586816 255 SL_OPCODE_NETAPP_MDNSREGISTERSERVICE,
dflet 0:50cedd586816 256 sizeof(NetappMdnsSetService_t),
dflet 0:50cedd586816 257 sizeof(_BasicResponse_t)
dflet 0:50cedd586816 258 };
dflet 0:50cedd586816 259
dflet 0:50cedd586816 260 /******************************************************************************
dflet 0:50cedd586816 261
dflet 0:50cedd586816 262 sl_NetAppMDNSRegisterService
dflet 0:50cedd586816 263
dflet 0:50cedd586816 264 CALLER user from its host
dflet 0:50cedd586816 265
dflet 0:50cedd586816 266
dflet 0:50cedd586816 267 DESCRIPTION:
dflet 0:50cedd586816 268 Add/delete service
dflet 0:50cedd586816 269 The function manipulates the command that register the service and call
dflet 0:50cedd586816 270 to the NWP in order to add/delete the service to/from the mDNS package and to/from the DB.
dflet 0:50cedd586816 271
dflet 0:50cedd586816 272 This register service is a service offered by the application.
dflet 0:50cedd586816 273 This unregister service is a service offered by the application before.
dflet 0:50cedd586816 274
dflet 0:50cedd586816 275 The service name should be full service name according to RFC
dflet 0:50cedd586816 276 of the DNS-SD - means the value in name field in SRV answer.
dflet 0:50cedd586816 277
dflet 0:50cedd586816 278 Example for service name:
dflet 0:50cedd586816 279 1. PC1._ipp._tcp.local
dflet 0:50cedd586816 280 2. PC2_server._ftp._tcp.local
dflet 0:50cedd586816 281
dflet 0:50cedd586816 282 If the option is_unique is set, mDNS probes the service name to make sure
dflet 0:50cedd586816 283 it is unique before starting to announce the service on the network.
dflet 0:50cedd586816 284 Instance is the instance portion of the service name.
dflet 0:50cedd586816 285
dflet 0:50cedd586816 286
dflet 0:50cedd586816 287
dflet 0:50cedd586816 288
dflet 0:50cedd586816 289 PARAMETERS:
dflet 0:50cedd586816 290
dflet 0:50cedd586816 291 The command is from constant parameters and variables parameters.
dflet 0:50cedd586816 292
dflet 0:50cedd586816 293 Constant parameters are:
dflet 0:50cedd586816 294
dflet 0:50cedd586816 295 ServiceLen - The length of the service.
dflet 0:50cedd586816 296 TextLen - The length of the service should be smaller than 64.
dflet 0:50cedd586816 297 port - The port on this target host.
dflet 0:50cedd586816 298 TTL - The TTL of the service
dflet 0:50cedd586816 299 Options - bitwise parameters:
dflet 0:50cedd586816 300 bit 0 - is unique (means if the service needs to be unique)
dflet 0:50cedd586816 301 bit 31 - for internal use if the service should be added or deleted (set means ADD).
dflet 0:50cedd586816 302 bit 1-30 for future.
dflet 0:50cedd586816 303
dflet 0:50cedd586816 304 The variables parameters are:
dflet 0:50cedd586816 305
dflet 0:50cedd586816 306 Service name(full service name) - The service name.
dflet 0:50cedd586816 307 Example for service name:
dflet 0:50cedd586816 308 1. PC1._ipp._tcp.local
dflet 0:50cedd586816 309 2. PC2_server._ftp._tcp.local
dflet 0:50cedd586816 310
dflet 0:50cedd586816 311 Text - The description of the service.
dflet 0:50cedd586816 312 should be as mentioned in the RFC
dflet 0:50cedd586816 313 (according to type of the service IPP,FTP...)
dflet 0:50cedd586816 314
dflet 0:50cedd586816 315 NOTE - pay attention
dflet 0:50cedd586816 316
dflet 0:50cedd586816 317 1. Temporary - there is an allocation on stack of internal buffer.
dflet 0:50cedd586816 318 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 319 It means that the sum of the text length and service name length cannot be bigger than
dflet 0:50cedd586816 320 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 321 If it is - An error is returned.
dflet 0:50cedd586816 322
dflet 0:50cedd586816 323 2. According to now from certain constraints the variables parameters are set in the
dflet 0:50cedd586816 324 attribute part (contain constant parameters)
dflet 0:50cedd586816 325
dflet 0:50cedd586816 326
dflet 0:50cedd586816 327
dflet 0:50cedd586816 328 RETURNS: Status - the immediate response of the command status.
dflet 0:50cedd586816 329 0 means success.
dflet 0:50cedd586816 330
dflet 0:50cedd586816 331
dflet 0:50cedd586816 332
dflet 0:50cedd586816 333 ******************************************************************************/
dflet 0:50cedd586816 334 int16_t cc3100_netapp::sl_NetAppMDNSRegisterUnregisterService(const char* pServiceName,
dflet 0:50cedd586816 335 const uint8_t ServiceNameLen,
dflet 0:50cedd586816 336 const char* pText,
dflet 0:50cedd586816 337 const uint8_t TextLen,
dflet 0:50cedd586816 338 const uint16_t Port,
dflet 0:50cedd586816 339 const uint32_t TTL,
dflet 0:50cedd586816 340 const uint32_t Options)
dflet 0:50cedd586816 341 {
dflet 0:50cedd586816 342
dflet 0:50cedd586816 343 _SlNetappMdnsRegisterServiceMsg_u Msg;
dflet 0:50cedd586816 344 _SlCmdExt_t CmdExt ;
dflet 0:50cedd586816 345 unsigned char ServiceNameAndTextBuffer[NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH];
dflet 0:50cedd586816 346 unsigned char *TextPtr;
dflet 0:50cedd586816 347
dflet 0:50cedd586816 348 /*
dflet 0:50cedd586816 349
dflet 0:50cedd586816 350 NOTE - pay attention
dflet 0:50cedd586816 351
dflet 0:50cedd586816 352 1. Temporary - there is an allocation on stack of internal buffer.
dflet 0:50cedd586816 353 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 354 It means that the sum of the text length and service name length cannot be bigger than
dflet 0:50cedd586816 355 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 356 If it is - An error is returned.
dflet 0:50cedd586816 357
dflet 0:50cedd586816 358 2. According to now from certain constraints the variables parameters are set in the
dflet 0:50cedd586816 359 attribute part (contain constant parameters)
dflet 0:50cedd586816 360
dflet 0:50cedd586816 361
dflet 0:50cedd586816 362 */
dflet 0:50cedd586816 363
dflet 0:50cedd586816 364 /*build the attribute part of the command.
dflet 0:50cedd586816 365 It contains the constant parameters of the command*/
dflet 0:50cedd586816 366
dflet 0:50cedd586816 367 Msg.Cmd.ServiceNameLen = ServiceNameLen;
dflet 0:50cedd586816 368 Msg.Cmd.Options = Options;
dflet 0:50cedd586816 369 Msg.Cmd.Port = Port;
dflet 0:50cedd586816 370 Msg.Cmd.TextLen = TextLen;
dflet 0:50cedd586816 371 Msg.Cmd.TTL = TTL;
dflet 0:50cedd586816 372
dflet 0:50cedd586816 373 /*Build the payload part of the command
dflet 0:50cedd586816 374 Copy the service name and text to one buffer.
dflet 0:50cedd586816 375 NOTE - pay attention
dflet 0:50cedd586816 376 The size of the service length + the text length should be smaller than 255,
dflet 0:50cedd586816 377 Until the simplelink drive supports to variable length through SPI command. */
dflet 0:50cedd586816 378 if(TextLen + ServiceNameLen > (NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH - 1 )) { /*-1 is for giving a place to set null termination at the end of the text*/
dflet 0:50cedd586816 379 return -1;
dflet 0:50cedd586816 380 }
dflet 0:50cedd586816 381
dflet 0:50cedd586816 382 _driver._SlDrvMemZero(ServiceNameAndTextBuffer, NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH);
dflet 0:50cedd586816 383
dflet 0:50cedd586816 384
dflet 0:50cedd586816 385 /*Copy the service name*/
dflet 0:50cedd586816 386 memcpy(ServiceNameAndTextBuffer,
dflet 0:50cedd586816 387 pServiceName,
dflet 0:50cedd586816 388 ServiceNameLen);
dflet 0:50cedd586816 389
dflet 0:50cedd586816 390 if(TextLen > 0 ) {
dflet 0:50cedd586816 391
dflet 0:50cedd586816 392 TextPtr = &ServiceNameAndTextBuffer[ServiceNameLen];
dflet 0:50cedd586816 393 /*Copy the text just after the service name*/
dflet 0:50cedd586816 394 memcpy(TextPtr, pText, TextLen);
dflet 0:50cedd586816 395 }
dflet 0:50cedd586816 396
dflet 0:50cedd586816 397 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:50cedd586816 398 CmdExt.TxPayloadLen = (TextLen + ServiceNameLen);
dflet 0:50cedd586816 399 CmdExt.pTxPayload = (uint8_t *)ServiceNameAndTextBuffer;
dflet 0:50cedd586816 400
dflet 0:50cedd586816 401
dflet 0:50cedd586816 402 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRegisterServiceCtrl, &Msg, &CmdExt));
dflet 0:50cedd586816 403
dflet 0:50cedd586816 404 return (int16_t)Msg.Rsp.status;
dflet 0:50cedd586816 405
dflet 0:50cedd586816 406
dflet 0:50cedd586816 407 }
dflet 0:50cedd586816 408 #endif
dflet 0:50cedd586816 409
dflet 0:50cedd586816 410 /**********************************************************************************************/
dflet 0:50cedd586816 411 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService)
dflet 0:50cedd586816 412 int16_t cc3100_netapp::sl_NetAppMDNSRegisterService(const char* pServiceName,
dflet 0:50cedd586816 413 const uint8_t ServiceNameLen,
dflet 0:50cedd586816 414 const char* pText,
dflet 0:50cedd586816 415 const uint8_t TextLen,
dflet 0:50cedd586816 416 const uint16_t Port,
dflet 0:50cedd586816 417 const uint32_t TTL,
dflet 0:50cedd586816 418 uint32_t Options)
dflet 0:50cedd586816 419 {
dflet 0:50cedd586816 420
dflet 0:50cedd586816 421 /*
dflet 0:50cedd586816 422
dflet 0:50cedd586816 423 NOTE - pay attention
dflet 0:50cedd586816 424
dflet 0:50cedd586816 425 1. Temporary - there is an allocation on stack of internal buffer.
dflet 0:50cedd586816 426 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 427 It means that the sum of the text length and service name length cannot be bigger than
dflet 0:50cedd586816 428 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH.
dflet 0:50cedd586816 429 If it is - An error is returned.
dflet 0:50cedd586816 430
dflet 0:50cedd586816 431 2. According to now from certain constraints the variables parameters are set in the
dflet 0:50cedd586816 432 attribute part (contain constant parameters)
dflet 0:50cedd586816 433
dflet 0:50cedd586816 434 */
dflet 0:50cedd586816 435
dflet 0:50cedd586816 436 /*Set the add service bit in the options parameter.
dflet 0:50cedd586816 437 In order not use different opcodes for the register service and unregister service
dflet 0:50cedd586816 438 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added
dflet 0:50cedd586816 439 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName
dflet 0:50cedd586816 440 and ServiceNameLen values. */
dflet 0:50cedd586816 441 Options |= NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT;
dflet 0:50cedd586816 442
dflet 0:50cedd586816 443 return (sl_NetAppMDNSRegisterUnregisterService( pServiceName, ServiceNameLen, pText, TextLen, Port, TTL, Options));
dflet 0:50cedd586816 444
dflet 0:50cedd586816 445
dflet 0:50cedd586816 446 }
dflet 0:50cedd586816 447 #endif
dflet 0:50cedd586816 448 /**********************************************************************************************/
dflet 0:50cedd586816 449
dflet 0:50cedd586816 450
dflet 0:50cedd586816 451
dflet 0:50cedd586816 452 /**********************************************************************************************/
dflet 0:50cedd586816 453 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService)
dflet 0:50cedd586816 454 int16_t cc3100_netapp::sl_NetAppMDNSUnRegisterService(const char* pServiceName, const uint8_t ServiceNameLen)
dflet 0:50cedd586816 455 {
dflet 0:50cedd586816 456 uint32_t Options = 0;
dflet 0:50cedd586816 457
dflet 0:50cedd586816 458 /*
dflet 0:50cedd586816 459
dflet 0:50cedd586816 460 NOTE - pay attention
dflet 0:50cedd586816 461
dflet 0:50cedd586816 462 The size of the service length should be smaller than 255,
dflet 0:50cedd586816 463 Until the simplelink drive supports to variable length through SPI command.
dflet 0:50cedd586816 464
dflet 0:50cedd586816 465
dflet 0:50cedd586816 466 */
dflet 0:50cedd586816 467
dflet 0:50cedd586816 468 /*Clear the add service bit in the options parameter.
dflet 0:50cedd586816 469 In order not use different opcodes for the register service and unregister service
dflet 0:50cedd586816 470 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added
dflet 0:50cedd586816 471 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName
dflet 0:50cedd586816 472 and ServiceNameLen values.*/
dflet 0:50cedd586816 473
dflet 0:50cedd586816 474 Options &= (~NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT);
dflet 0:50cedd586816 475
dflet 0:50cedd586816 476 return (sl_NetAppMDNSRegisterUnregisterService(pServiceName, ServiceNameLen, NULL, 0, 0, 0, Options));
dflet 0:50cedd586816 477
dflet 0:50cedd586816 478
dflet 0:50cedd586816 479 }
dflet 0:50cedd586816 480 #endif
dflet 0:50cedd586816 481 /**********************************************************************************************/
dflet 0:50cedd586816 482
dflet 0:50cedd586816 483
dflet 0:50cedd586816 484
dflet 0:50cedd586816 485 /*****************************************************************************/
dflet 0:50cedd586816 486 /* sl_DnsGetHostByService */
dflet 0:50cedd586816 487 /*****************************************************************************/
dflet 0:50cedd586816 488 /*
dflet 0:50cedd586816 489 * The below struct depicts the constant parameters of the command/API sl_DnsGetHostByService.
dflet 0:50cedd586816 490 *
dflet 0:50cedd586816 491 1. ServiceLen - The length of the service should be smaller than 255.
dflet 0:50cedd586816 492 2. AddrLen - TIPv4 or IPv6 (SL_AF_INET , SL_AF_INET6).
dflet 0:50cedd586816 493 *
dflet 0:50cedd586816 494 */
dflet 0:50cedd586816 495
dflet 0:50cedd586816 496 typedef struct {
dflet 0:50cedd586816 497 uint8_t ServiceLen;
dflet 0:50cedd586816 498 uint8_t AddrLen;
dflet 0:50cedd586816 499 uint16_t Padding;
dflet 0:50cedd586816 500 } _GetHostByServiceCommand_t;
dflet 0:50cedd586816 501
dflet 0:50cedd586816 502
dflet 0:50cedd586816 503
dflet 0:50cedd586816 504 /*
dflet 0:50cedd586816 505 * The below structure depict the constant parameters that are returned in the Async event answer
dflet 0:50cedd586816 506 * according to command/API sl_DnsGetHostByService for IPv4 and IPv6.
dflet 0:50cedd586816 507 *
dflet 0:50cedd586816 508 1Status - The status of the response.
dflet 0:50cedd586816 509 2.Address - Contains the IP address of the service.
dflet 0:50cedd586816 510 3.Port - Contains the port of the service.
dflet 0:50cedd586816 511 4.TextLen - Contains the max length of the text that the user wants to get.
dflet 0:50cedd586816 512 it means that if the test of service is bigger that its value than
dflet 0:50cedd586816 513 the text is cut to inout_TextLen value.
dflet 0:50cedd586816 514 Output: Contain the length of the text that is returned. Can be full text or part
dflet 0:50cedd586816 515 of the text (see above).
dflet 0:50cedd586816 516
dflet 0:50cedd586816 517 *
dflet 0:50cedd586816 518
dflet 0:50cedd586816 519 typedef struct {
dflet 0:50cedd586816 520 uint16_t Status;
dflet 0:50cedd586816 521 uint16_t TextLen;
dflet 0:50cedd586816 522 uint32_t Port;
dflet 0:50cedd586816 523 uint32_t Address;
dflet 0:50cedd586816 524 } _GetHostByServiceIPv4AsyncResponse_t;
dflet 0:50cedd586816 525 */
dflet 0:50cedd586816 526
dflet 0:50cedd586816 527 typedef struct {
dflet 0:50cedd586816 528 uint16_t Status;
dflet 0:50cedd586816 529 uint16_t TextLen;
dflet 0:50cedd586816 530 uint32_t Port;
dflet 0:50cedd586816 531 uint32_t Address[4];
dflet 0:50cedd586816 532 } _GetHostByServiceIPv6AsyncResponse_t;
dflet 0:50cedd586816 533
dflet 0:50cedd586816 534
dflet 0:50cedd586816 535 typedef union {
dflet 0:50cedd586816 536 _GetHostByServiceIPv4AsyncResponse_t IpV4;
dflet 0:50cedd586816 537 _GetHostByServiceIPv6AsyncResponse_t IpV6;
dflet 0:50cedd586816 538 } _GetHostByServiceAsyncResponseAttribute_u;
dflet 0:50cedd586816 539
dflet 0:50cedd586816 540 typedef union {
dflet 0:50cedd586816 541 _GetHostByServiceCommand_t Cmd;
dflet 0:50cedd586816 542 _BasicResponse_t Rsp;
dflet 0:50cedd586816 543 } _SlGetHostByServiceMsg_u;
dflet 0:50cedd586816 544
dflet 0:50cedd586816 545 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService)
dflet 0:50cedd586816 546 const _SlCmdCtrl_t _SlGetHostByServiceCtrl = {
dflet 0:50cedd586816 547 SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICE,
dflet 0:50cedd586816 548 sizeof(_GetHostByServiceCommand_t),
dflet 0:50cedd586816 549 sizeof(_BasicResponse_t)
dflet 0:50cedd586816 550 };
dflet 0:50cedd586816 551
dflet 0:50cedd586816 552 int32_t cc3100_netapp::sl_NetAppDnsGetHostByService(unsigned char *pServiceName, /* string containing all (or only part): name + subtype + service */
dflet 0:50cedd586816 553 const uint8_t ServiceLen,
dflet 0:50cedd586816 554 const uint8_t Family, /* 4-IPv4 , 16-IPv6 */
dflet 0:50cedd586816 555 uint32_t pAddr[],
dflet 0:50cedd586816 556 uint32_t *pPort,
dflet 0:50cedd586816 557 uint16_t *pTextLen, /* in: max len , out: actual len */
dflet 0:50cedd586816 558 unsigned char *pText)
dflet 0:50cedd586816 559 {
dflet 0:50cedd586816 560
dflet 0:50cedd586816 561 _SlGetHostByServiceMsg_u Msg;
dflet 0:50cedd586816 562 _SlCmdExt_t CmdExt ;
dflet 0:50cedd586816 563 _GetHostByServiceAsyncResponse_t AsyncRsp;
dflet 0:50cedd586816 564 uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS;
dflet 0:50cedd586816 565
dflet 0:50cedd586816 566 /*
dflet 0:50cedd586816 567 Note:
dflet 0:50cedd586816 568 1. The return's attributes are belonged to first service that is found.
dflet 0:50cedd586816 569 It can be other services with the same service name will response to
dflet 0:50cedd586816 570 the query. The results of these responses are saved in the peer cache of the NWP, and
dflet 0:50cedd586816 571 should be read by another API.
dflet 0:50cedd586816 572
dflet 0:50cedd586816 573 2. Text length can be 120 bytes only - not more
dflet 0:50cedd586816 574 It is because of constraints in the NWP on the buffer that is allocated for the Async event.
dflet 0:50cedd586816 575
dflet 0:50cedd586816 576 3.The API waits to Async event by blocking. It means that the API is finished only after an Async event
dflet 0:50cedd586816 577 is sent by the NWP.
dflet 0:50cedd586816 578
dflet 0:50cedd586816 579 4.No rolling option!!! - only PTR type is sent.
dflet 0:50cedd586816 580
dflet 0:50cedd586816 581
dflet 0:50cedd586816 582 */
dflet 0:50cedd586816 583 /*build the attribute part of the command.
dflet 0:50cedd586816 584 It contains the constant parameters of the command */
dflet 0:50cedd586816 585
dflet 0:50cedd586816 586 Msg.Cmd.ServiceLen = ServiceLen;
dflet 0:50cedd586816 587 Msg.Cmd.AddrLen = Family;
dflet 0:50cedd586816 588
dflet 0:50cedd586816 589 /*Build the payload part of the command
dflet 0:50cedd586816 590 Copy the service name and text to one buffer.*/
dflet 0:50cedd586816 591 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:50cedd586816 592 CmdExt.TxPayloadLen = ServiceLen;
dflet 0:50cedd586816 593
dflet 0:50cedd586816 594 CmdExt.pTxPayload = (uint8_t *)pServiceName;
dflet 0:50cedd586816 595
dflet 0:50cedd586816 596
dflet 0:50cedd586816 597 /*set pointers to the output parameters (the returned parameters).
dflet 0:50cedd586816 598 This pointers are belonged to local struct that is set to global Async response parameter.
dflet 0:50cedd586816 599 It is done in order not to run more than one sl_DnsGetHostByService at the same time.
dflet 0:50cedd586816 600 The API should be run only if global parameter is pointed to NULL. */
dflet 0:50cedd586816 601 AsyncRsp.out_pText = pText;
dflet 0:50cedd586816 602 AsyncRsp.inout_TextLen = (uint16_t* )pTextLen;
dflet 0:50cedd586816 603 AsyncRsp.out_pPort = pPort;
dflet 0:50cedd586816 604 AsyncRsp.out_pAddr = (uint32_t *)pAddr;
dflet 0:50cedd586816 605
dflet 0:50cedd586816 606
dflet 0:50cedd586816 607 ObjIdx = _driver._SlDrvProtectAsyncRespSetting((uint8_t*)&AsyncRsp, GETHOSYBYSERVICE_ID, SL_MAX_SOCKETS);
dflet 0:50cedd586816 608
dflet 0:50cedd586816 609 if (MAX_CONCURRENT_ACTIONS == ObjIdx)
dflet 0:50cedd586816 610 {
dflet 0:50cedd586816 611 return SL_POOL_IS_EMPTY;
dflet 0:50cedd586816 612 }
dflet 0:50cedd586816 613
dflet 0:50cedd586816 614 if (SL_AF_INET6 == Family) {
dflet 0:50cedd586816 615 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK;
dflet 0:50cedd586816 616 }
dflet 0:50cedd586816 617 /* Send the command */
dflet 0:50cedd586816 618 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByServiceCtrl, &Msg, &CmdExt));
dflet 0:50cedd586816 619
dflet 0:50cedd586816 620
dflet 0:50cedd586816 621
dflet 0:50cedd586816 622 /* If the immediate reponse is O.K. than wait for aSYNC event response. */
dflet 0:50cedd586816 623 if(SL_RET_CODE_OK == Msg.Rsp.status) {
dflet 0:50cedd586816 624 _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
dflet 0:50cedd586816 625
dflet 0:50cedd586816 626 /* If we are - it means that Async event was sent.
dflet 0:50cedd586816 627 The results are copied in the Async handle return functions */
dflet 0:50cedd586816 628
dflet 0:50cedd586816 629 Msg.Rsp.status = AsyncRsp.Status;
dflet 0:50cedd586816 630 }
dflet 0:50cedd586816 631
dflet 0:50cedd586816 632 _driver._SlDrvReleasePoolObj(ObjIdx);
dflet 0:50cedd586816 633 return Msg.Rsp.status;
dflet 0:50cedd586816 634 }
dflet 0:50cedd586816 635 #endif
dflet 0:50cedd586816 636
dflet 0:50cedd586816 637 /*****************************************************************************/
dflet 0:50cedd586816 638 /* _sl_HandleAsync_DnsGetHostByAddr */
dflet 0:50cedd586816 639 /*****************************************************************************/
dflet 0:50cedd586816 640 #ifndef SL_TINY_EXT
dflet 0:50cedd586816 641 void cc3100_netapp::_sl_HandleAsync_DnsGetHostByAddr(void *pVoidBuf)
dflet 0:50cedd586816 642 {
dflet 0:50cedd586816 643 SL_TRACE0(DBG_MSG, MSG_303, "STUB: _sl_HandleAsync_DnsGetHostByAddr not implemented yet!");
dflet 0:50cedd586816 644 return;
dflet 0:50cedd586816 645 }
dflet 0:50cedd586816 646 #endif
dflet 0:50cedd586816 647 /*****************************************************************************/
dflet 0:50cedd586816 648 /* sl_DnsGetHostByName */
dflet 0:50cedd586816 649 /*****************************************************************************/
dflet 0:50cedd586816 650 typedef union {
dflet 0:50cedd586816 651 _GetHostByNameIPv4AsyncResponse_t IpV4;
dflet 0:50cedd586816 652 _GetHostByNameIPv6AsyncResponse_t IpV6;
dflet 0:50cedd586816 653 } _GetHostByNameAsyncResponse_u;
dflet 0:50cedd586816 654
dflet 0:50cedd586816 655 typedef union {
dflet 0:50cedd586816 656 _GetHostByNameCommand_t Cmd;
dflet 0:50cedd586816 657 _BasicResponse_t Rsp;
dflet 0:50cedd586816 658 } _SlGetHostByNameMsg_u;
dflet 0:50cedd586816 659
dflet 0:50cedd586816 660 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName)
dflet 0:50cedd586816 661 const _SlCmdCtrl_t _SlGetHostByNameCtrl = {
dflet 0:50cedd586816 662 SL_OPCODE_NETAPP_DNSGETHOSTBYNAME,
dflet 0:50cedd586816 663 sizeof(_GetHostByNameCommand_t),
dflet 0:50cedd586816 664 sizeof(_BasicResponse_t)
dflet 0:50cedd586816 665 };
dflet 0:50cedd586816 666
dflet 0:50cedd586816 667 int16_t cc3100_netapp::sl_NetAppDnsGetHostByName(unsigned char * hostname, const uint16_t usNameLen, uint32_t* out_ip_addr, const uint8_t family)
dflet 0:50cedd586816 668 {
dflet 0:50cedd586816 669 _SlGetHostByNameMsg_u Msg;
dflet 0:50cedd586816 670 _SlCmdExt_t ExtCtrl;
dflet 0:50cedd586816 671 _GetHostByNameAsyncResponse_u AsyncRsp;
dflet 0:50cedd586816 672 uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS;
dflet 0:50cedd586816 673
dflet 0:50cedd586816 674 _driver._SlDrvResetCmdExt(&ExtCtrl);
dflet 0:50cedd586816 675 ExtCtrl.TxPayloadLen = usNameLen;
dflet 0:50cedd586816 676
dflet 0:50cedd586816 677 ExtCtrl.pTxPayload = (unsigned char *)hostname;
dflet 0:50cedd586816 678
dflet 0:50cedd586816 679
dflet 0:50cedd586816 680 Msg.Cmd.Len = usNameLen;
dflet 0:50cedd586816 681 Msg.Cmd.family = family;
dflet 0:50cedd586816 682
dflet 0:50cedd586816 683 /*Use Obj to issue the command, if not available try later */
dflet 0:50cedd586816 684 ObjIdx = (uint8_t)_driver._SlDrvWaitForPoolObj(GETHOSYBYNAME_ID,SL_MAX_SOCKETS);
dflet 0:50cedd586816 685 if (MAX_CONCURRENT_ACTIONS == ObjIdx) {
dflet 0:50cedd586816 686 printf("SL_POOL_IS_EMPTY \r\n");
dflet 0:50cedd586816 687 return SL_POOL_IS_EMPTY;
dflet 0:50cedd586816 688 }
dflet 0:50cedd586816 689
dflet 0:50cedd586816 690 _driver._SlDrvProtectionObjLockWaitForever();
dflet 0:50cedd586816 691
dflet 0:50cedd586816 692 g_pCB->ObjPool[ObjIdx].pRespArgs = (uint8_t *)&AsyncRsp;
dflet 0:50cedd586816 693 /*set bit to indicate IPv6 address is expected */
dflet 0:50cedd586816 694 if (SL_AF_INET6 == family) {
dflet 0:50cedd586816 695 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK;
dflet 0:50cedd586816 696 }
dflet 0:50cedd586816 697
dflet 0:50cedd586816 698 _driver._SlDrvProtectionObjUnLock();
dflet 0:50cedd586816 699
dflet 0:50cedd586816 700 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByNameCtrl, &Msg, &ExtCtrl));
dflet 0:50cedd586816 701
dflet 0:50cedd586816 702 if(SL_RET_CODE_OK == Msg.Rsp.status) {
dflet 0:50cedd586816 703 _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
dflet 0:50cedd586816 704 Msg.Rsp.status = AsyncRsp.IpV4.status;
dflet 0:50cedd586816 705
dflet 0:50cedd586816 706 if(SL_OS_RET_CODE_OK == (int16_t)Msg.Rsp.status) {
dflet 0:50cedd586816 707 memcpy((int8_t *)out_ip_addr, (signed char *)&AsyncRsp.IpV4.ip0, (SL_AF_INET == family) ? SL_IPV4_ADDRESS_SIZE : SL_IPV6_ADDRESS_SIZE);
dflet 0:50cedd586816 708 }
dflet 0:50cedd586816 709 }
dflet 0:50cedd586816 710 _driver._SlDrvReleasePoolObj(ObjIdx);
dflet 0:50cedd586816 711 return Msg.Rsp.status;
dflet 0:50cedd586816 712 }
dflet 0:50cedd586816 713 #endif
dflet 0:50cedd586816 714
dflet 0:50cedd586816 715 #ifndef SL_TINY_EXT
dflet 0:50cedd586816 716 void cc3100_netapp::CopyPingResultsToReport(_PingReportResponse_t *pResults,SlPingReport_t *pReport)
dflet 0:50cedd586816 717 {
dflet 0:50cedd586816 718 pReport->PacketsSent = pResults->numSendsPings;
dflet 0:50cedd586816 719 pReport->PacketsReceived = pResults->numSuccsessPings;
dflet 0:50cedd586816 720 pReport->MinRoundTime = pResults->rttMin;
dflet 0:50cedd586816 721 pReport->MaxRoundTime = pResults->rttMax;
dflet 0:50cedd586816 722 pReport->AvgRoundTime = pResults->rttAvg;
dflet 0:50cedd586816 723 pReport->TestTime = pResults->testTime;
dflet 0:50cedd586816 724 }
dflet 0:50cedd586816 725 #endif
dflet 0:50cedd586816 726 /*****************************************************************************/
dflet 0:50cedd586816 727 /* sl_PingStart */
dflet 0:50cedd586816 728 /*****************************************************************************/
dflet 0:50cedd586816 729 typedef union {
dflet 0:50cedd586816 730 _PingStartCommand_t Cmd;
dflet 0:50cedd586816 731 _PingReportResponse_t Rsp;
dflet 0:50cedd586816 732 } _SlPingStartMsg_u;
dflet 0:50cedd586816 733
dflet 0:50cedd586816 734
dflet 0:50cedd586816 735 typedef enum {
dflet 0:50cedd586816 736 CMD_PING_TEST_RUNNING = 0,
dflet 0:50cedd586816 737 CMD_PING_TEST_STOPPED
dflet 0:50cedd586816 738 } _SlPingStatus_e;
dflet 0:50cedd586816 739
dflet 0:50cedd586816 740 P_SL_DEV_PING_CALLBACK pPingCallBackFunc;
dflet 0:50cedd586816 741
dflet 0:50cedd586816 742 #if _SL_INCLUDE_FUNC(sl_NetAppPingStart)
dflet 0:50cedd586816 743 int16_t cc3100_netapp::sl_NetAppPingStart(const SlPingStartCommand_t* pPingParams, const uint8_t family, SlPingReport_t *pReport, const P_SL_DEV_PING_CALLBACK pPingCallback)
dflet 0:50cedd586816 744 {
dflet 0:50cedd586816 745
dflet 0:50cedd586816 746 _SlCmdCtrl_t CmdCtrl = {0, sizeof(_PingStartCommand_t), sizeof(_BasicResponse_t)};
dflet 0:50cedd586816 747 _SlPingStartMsg_u Msg;
dflet 0:50cedd586816 748 _PingReportResponse_t PingRsp;
dflet 0:50cedd586816 749 uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS;
dflet 0:50cedd586816 750
dflet 0:50cedd586816 751 if( 0 == pPingParams->Ip )
dflet 0:50cedd586816 752 { /* stop any ongoing ping */
dflet 0:50cedd586816 753 return _driver._SlDrvBasicCmd(SL_OPCODE_NETAPP_PINGSTOP);
dflet 0:50cedd586816 754 }
dflet 0:50cedd586816 755
dflet 0:50cedd586816 756 if(SL_AF_INET == family) {
dflet 0:50cedd586816 757 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART;
dflet 0:50cedd586816 758 memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV4_ADDRESS_SIZE);
dflet 0:50cedd586816 759 } else {
dflet 0:50cedd586816 760 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART_V6;
dflet 0:50cedd586816 761 memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV6_ADDRESS_SIZE);
dflet 0:50cedd586816 762 }
dflet 0:50cedd586816 763
dflet 0:50cedd586816 764 Msg.Cmd.pingIntervalTime = pPingParams->PingIntervalTime;
dflet 0:50cedd586816 765 Msg.Cmd.PingSize = pPingParams->PingSize;
dflet 0:50cedd586816 766 Msg.Cmd.pingRequestTimeout = pPingParams->PingRequestTimeout;
dflet 0:50cedd586816 767 Msg.Cmd.totalNumberOfAttempts = pPingParams->TotalNumberOfAttempts;
dflet 0:50cedd586816 768 Msg.Cmd.flags = pPingParams->Flags;
dflet 0:50cedd586816 769
dflet 0:50cedd586816 770 if( pPingCallback ) {
dflet 0:50cedd586816 771 pPingCallBackFunc = pPingCallback;
dflet 0:50cedd586816 772 } else {
dflet 0:50cedd586816 773 /*Use Obj to issue the command, if not available try later */
dflet 0:50cedd586816 774 ObjIdx = (uint8_t)_driver._SlDrvWaitForPoolObj(PING_ID,SL_MAX_SOCKETS);
dflet 0:50cedd586816 775 if (MAX_CONCURRENT_ACTIONS == ObjIdx) {
dflet 0:50cedd586816 776 return SL_POOL_IS_EMPTY;
dflet 0:50cedd586816 777 }
dflet 0:50cedd586816 778 #ifndef SL_PLATFORM_MULTI_THREADED
dflet 0:50cedd586816 779 OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER));
dflet 0:50cedd586816 780 #else
dflet 0:50cedd586816 781 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER));
dflet 0:50cedd586816 782 #endif
dflet 0:50cedd586816 783 /* async response handler for non callback mode */
dflet 0:50cedd586816 784 g_pCB->ObjPool[ObjIdx].pRespArgs = (uint8_t *)&PingRsp;
dflet 0:50cedd586816 785 pPingCallBackFunc = NULL;
dflet 0:50cedd586816 786 #ifndef SL_PLATFORM_MULTI_THREADED
dflet 0:50cedd586816 787 OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj));
dflet 0:50cedd586816 788 #else
dflet 0:50cedd586816 789 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj));
dflet 0:50cedd586816 790 #endif
dflet 0:50cedd586816 791 }
dflet 0:50cedd586816 792
dflet 0:50cedd586816 793
dflet 0:50cedd586816 794 VERIFY_RET_OK(_driver._SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
dflet 0:50cedd586816 795 /*send the command*/
dflet 0:50cedd586816 796 if(CMD_PING_TEST_RUNNING == (int16_t)Msg.Rsp.status || CMD_PING_TEST_STOPPED == (int16_t)Msg.Rsp.status ) {
dflet 0:50cedd586816 797 /* block waiting for results if no callback function is used */
dflet 0:50cedd586816 798 if( NULL == pPingCallback ) {
dflet 0:50cedd586816 799 _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
dflet 0:50cedd586816 800 if( SL_OS_RET_CODE_OK == (int16_t)PingRsp.status ) {
dflet 0:50cedd586816 801 CopyPingResultsToReport(&PingRsp,pReport);
dflet 0:50cedd586816 802 }
dflet 0:50cedd586816 803 _driver._SlDrvReleasePoolObj(ObjIdx);
dflet 0:50cedd586816 804 }
dflet 0:50cedd586816 805 } else {
dflet 0:50cedd586816 806 /* ping failure, no async response */
dflet 0:50cedd586816 807 if( NULL == pPingCallback ) {
dflet 0:50cedd586816 808 _driver._SlDrvReleasePoolObj(ObjIdx);
dflet 0:50cedd586816 809 }
dflet 0:50cedd586816 810 }
dflet 0:50cedd586816 811
dflet 0:50cedd586816 812 return Msg.Rsp.status;
dflet 0:50cedd586816 813 }
dflet 0:50cedd586816 814 #endif
dflet 0:50cedd586816 815
dflet 0:50cedd586816 816 /*****************************************************************************/
dflet 0:50cedd586816 817 /* sl_NetAppSet */
dflet 0:50cedd586816 818 /*****************************************************************************/
dflet 0:50cedd586816 819 typedef union {
dflet 0:50cedd586816 820 _NetAppSetGet_t Cmd;
dflet 0:50cedd586816 821 _BasicResponse_t Rsp;
dflet 0:50cedd586816 822 } _SlNetAppMsgSet_u;
dflet 0:50cedd586816 823
dflet 0:50cedd586816 824 #if _SL_INCLUDE_FUNC(sl_NetAppSet)
dflet 0:50cedd586816 825 const _SlCmdCtrl_t _SlNetAppSetCmdCtrl = {
dflet 0:50cedd586816 826 SL_OPCODE_NETAPP_NETAPPSET,
dflet 0:50cedd586816 827 sizeof(_NetAppSetGet_t),
dflet 0:50cedd586816 828 sizeof(_BasicResponse_t)
dflet 0:50cedd586816 829 };
dflet 0:50cedd586816 830
dflet 0:50cedd586816 831 int32_t cc3100_netapp::sl_NetAppSet(const uint8_t AppId ,const uint8_t Option, const uint8_t OptionLen, const uint8_t *pOptionValue)
dflet 0:50cedd586816 832 {
dflet 0:50cedd586816 833
dflet 0:50cedd586816 834 _SlNetAppMsgSet_u Msg;
dflet 0:50cedd586816 835 _SlCmdExt_t CmdExt;
dflet 0:50cedd586816 836
dflet 0:50cedd586816 837 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:50cedd586816 838 CmdExt.TxPayloadLen = (OptionLen+3) & (~3);
dflet 0:50cedd586816 839
dflet 0:50cedd586816 840 CmdExt.pTxPayload = (uint8_t *)pOptionValue;
dflet 0:50cedd586816 841
dflet 0:50cedd586816 842 Msg.Cmd.AppId = AppId;
dflet 0:50cedd586816 843 Msg.Cmd.ConfigLen = OptionLen;
dflet 0:50cedd586816 844 Msg.Cmd.ConfigOpt = Option;
dflet 0:50cedd586816 845
dflet 0:50cedd586816 846 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppSetCmdCtrl, &Msg, &CmdExt));
dflet 0:50cedd586816 847
dflet 0:50cedd586816 848 return (int16_t)Msg.Rsp.status;
dflet 0:50cedd586816 849 }
dflet 0:50cedd586816 850 #endif
dflet 0:50cedd586816 851
dflet 0:50cedd586816 852 /*****************************************************************************/
dflet 0:50cedd586816 853 /* sl_NetAppSendTokenValue */
dflet 0:50cedd586816 854 /*****************************************************************************/
dflet 0:50cedd586816 855 typedef union {
dflet 0:50cedd586816 856 sl_NetAppHttpServerSendToken_t Cmd;
dflet 0:50cedd586816 857 _BasicResponse_t Rsp;
dflet 0:50cedd586816 858 } _SlNetAppMsgSendTokenValue_u;
dflet 0:50cedd586816 859
dflet 0:50cedd586816 860 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
dflet 0:50cedd586816 861 const _SlCmdCtrl_t _SlNetAppSendTokenValueCmdCtrl = {
dflet 0:50cedd586816 862 SL_OPCODE_NETAPP_HTTPSENDTOKENVALUE,
dflet 0:50cedd586816 863 sizeof(sl_NetAppHttpServerSendToken_t),
dflet 0:50cedd586816 864 sizeof(_BasicResponse_t)
dflet 0:50cedd586816 865 };
dflet 0:50cedd586816 866
dflet 0:50cedd586816 867 uint16_t cc3100_netapp::sl_NetAppSendTokenValue(slHttpServerData_t * Token_value)
dflet 0:50cedd586816 868 {
dflet 0:50cedd586816 869
dflet 0:50cedd586816 870 _SlNetAppMsgSendTokenValue_u Msg;
dflet 0:50cedd586816 871 _SlCmdExt_t CmdExt;
dflet 0:50cedd586816 872
dflet 0:50cedd586816 873 CmdExt.TxPayloadLen = (Token_value->value_len+3) & (~3);
dflet 0:50cedd586816 874 CmdExt.RxPayloadLen = 0;
dflet 0:50cedd586816 875 CmdExt.pTxPayload = (uint8_t *) Token_value->token_value;
dflet 0:50cedd586816 876 CmdExt.pRxPayload = NULL;
dflet 0:50cedd586816 877
dflet 0:50cedd586816 878 Msg.Cmd.token_value_len = Token_value->value_len;
dflet 0:50cedd586816 879 Msg.Cmd.token_name_len = Token_value->name_len;
dflet 0:50cedd586816 880 memcpy(&Msg.Cmd.token_name[0], Token_value->token_name, Token_value->name_len);
dflet 0:50cedd586816 881
dflet 0:50cedd586816 882
dflet 0:50cedd586816 883 VERIFY_RET_OK(_driver._SlDrvCmdSend((_SlCmdCtrl_t *)&_SlNetAppSendTokenValueCmdCtrl, &Msg, &CmdExt));
dflet 0:50cedd586816 884
dflet 0:50cedd586816 885 return Msg.Rsp.status;
dflet 0:50cedd586816 886 }
dflet 0:50cedd586816 887 #endif
dflet 0:50cedd586816 888
dflet 0:50cedd586816 889 /*****************************************************************************/
dflet 0:50cedd586816 890 /* sl_NetAppGet */
dflet 0:50cedd586816 891 /*****************************************************************************/
dflet 0:50cedd586816 892 typedef union {
dflet 0:50cedd586816 893 _NetAppSetGet_t Cmd;
dflet 0:50cedd586816 894 _NetAppSetGet_t Rsp;
dflet 0:50cedd586816 895 } _SlNetAppMsgGet_u;
dflet 0:50cedd586816 896
dflet 0:50cedd586816 897 #if _SL_INCLUDE_FUNC(sl_NetAppGet)
dflet 0:50cedd586816 898 const _SlCmdCtrl_t _SlNetAppGetCmdCtrl = {
dflet 0:50cedd586816 899 SL_OPCODE_NETAPP_NETAPPGET,
dflet 0:50cedd586816 900 sizeof(_NetAppSetGet_t),
dflet 0:50cedd586816 901 sizeof(_NetAppSetGet_t)
dflet 0:50cedd586816 902 };
dflet 0:50cedd586816 903
dflet 0:50cedd586816 904 int32_t cc3100_netapp::sl_NetAppGet(const uint8_t AppId, const uint8_t Option, uint8_t *pOptionLen, uint8_t *pOptionValue)
dflet 0:50cedd586816 905 {
dflet 0:50cedd586816 906 _SlNetAppMsgGet_u Msg;
dflet 0:50cedd586816 907 _SlCmdExt_t CmdExt;
dflet 0:50cedd586816 908
dflet 0:50cedd586816 909 if (*pOptionLen == 0) {
dflet 0:50cedd586816 910 return SL_EZEROLEN;
dflet 0:50cedd586816 911 }
dflet 0:50cedd586816 912
dflet 0:50cedd586816 913 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:50cedd586816 914 CmdExt.RxPayloadLen = *pOptionLen;
dflet 0:50cedd586816 915
dflet 0:50cedd586816 916 CmdExt.pRxPayload = (uint8_t *)pOptionValue;
dflet 0:50cedd586816 917
dflet 0:50cedd586816 918 Msg.Cmd.AppId = AppId;
dflet 0:50cedd586816 919 Msg.Cmd.ConfigOpt = Option;
dflet 0:50cedd586816 920 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppGetCmdCtrl, &Msg, &CmdExt));
dflet 0:50cedd586816 921
dflet 0:50cedd586816 922
dflet 0:50cedd586816 923 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) {
dflet 0:50cedd586816 924 *pOptionLen = (uint8_t)CmdExt.RxPayloadLen;
dflet 0:50cedd586816 925 return SL_ESMALLBUF;
dflet 0:50cedd586816 926 } else {
dflet 0:50cedd586816 927 *pOptionLen = (uint8_t)CmdExt.ActualRxPayloadLen;
dflet 0:50cedd586816 928 }
dflet 0:50cedd586816 929
dflet 0:50cedd586816 930 return (int16_t)Msg.Rsp.Status;
dflet 0:50cedd586816 931 }
dflet 0:50cedd586816 932 #endif
dflet 0:50cedd586816 933
dflet 0:50cedd586816 934 #ifndef SL_PLATFORM_MULTI_THREADED
dflet 0:50cedd586816 935 cc3100_flowcont::cc3100_flowcont(cc3100_driver &driver, cc3100_nonos &nonos)
dflet 0:50cedd586816 936 : _driver(driver), _nonos(nonos)
dflet 0:50cedd586816 937 {
dflet 0:50cedd586816 938 }
dflet 0:50cedd586816 939 #else
dflet 0:50cedd586816 940 cc3100_flowcont::cc3100_flowcont(cc3100_driver &driver)
dflet 0:50cedd586816 941 : _driver(driver)
dflet 0:50cedd586816 942 {
dflet 0:50cedd586816 943 }
dflet 0:50cedd586816 944 #endif
dflet 0:50cedd586816 945 cc3100_flowcont::~cc3100_flowcont()
dflet 0:50cedd586816 946 {
dflet 0:50cedd586816 947
dflet 0:50cedd586816 948 }
dflet 0:50cedd586816 949 #if 0
dflet 0:50cedd586816 950 /*****************************************************************************/
dflet 0:50cedd586816 951 /* _SlDrvFlowContInit */
dflet 0:50cedd586816 952 /*****************************************************************************/
dflet 0:50cedd586816 953 void cc3100_flowcont::_SlDrvFlowContInit(void)
dflet 0:50cedd586816 954 {
dflet 0:50cedd586816 955 g_pCB->FlowContCB.TxPoolCnt = FLOW_CONT_MIN;
dflet 0:50cedd586816 956
dflet 0:50cedd586816 957 OSI_RET_OK_CHECK(_nonos.sl_LockObjCreate(&g_pCB->FlowContCB.TxLockObj, "TxLockObj"));
dflet 0:50cedd586816 958
dflet 0:50cedd586816 959 OSI_RET_OK_CHECK(_nonos.sl_SyncObjCreate(&g_pCB->FlowContCB.TxSyncObj, "TxSyncObj"));
dflet 0:50cedd586816 960 }
dflet 0:50cedd586816 961
dflet 0:50cedd586816 962 /*****************************************************************************/
dflet 0:50cedd586816 963 /* _SlDrvFlowContDeinit */
dflet 0:50cedd586816 964 /*****************************************************************************/
dflet 0:50cedd586816 965 void cc3100_flowcont::_SlDrvFlowContDeinit(void)
dflet 0:50cedd586816 966 {
dflet 0:50cedd586816 967 g_pCB->FlowContCB.TxPoolCnt = 0;
dflet 0:50cedd586816 968
dflet 0:50cedd586816 969 OSI_RET_OK_CHECK(_nonos.sl_LockObjDelete(&g_pCB->FlowContCB.TxLockObj, 0));
dflet 0:50cedd586816 970
dflet 0:50cedd586816 971 OSI_RET_OK_CHECK(_nonos.sl_SyncObjDelete(&g_pCB->FlowContCB.TxSyncObj, 0));
dflet 0:50cedd586816 972 }
dflet 0:50cedd586816 973 #endif
dflet 0:50cedd586816 974 }//namespace mbed_cc3100
dflet 0:50cedd586816 975
dflet 0:50cedd586816 976