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