Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Committer:
dflet
Date:
Tue Sep 15 16:45:04 2015 +0000
Revision:
22:f9b5e0b80bf2
Parent:
19:3dd3e7f30f8b
Removed some debug.

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