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