Simple LED control project using CC3100 as Access Point and socket

Dependencies:   mbed

Fork of cc3100_Test_Demo by David Fletcher

Committer:
dflet
Date:
Tue Feb 10 12:09:29 2015 +0000
Revision:
0:e89ba455dbcf
Child:
2:b3fd5b3d9860
For test only! Not much has been tested, but the 2 demo apps run ok. Alot more work needs to be done!

Who changed what in which revision?

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