Updated to use external spawn.

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:48:29 2015 +0000
Revision:
1:9b68e650b3f6
Parent:
0:1a07906111ec
Oppps

Who changed what in which revision?

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