Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.
cc3100_netapp.cpp
00001 /* 00002 * netapp.c - CC31xx/CC32xx Host Driver Implementation 00003 * 00004 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * Neither the name of Texas Instruments Incorporated nor the names of 00020 * its contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 */ 00036 00037 00038 00039 /*****************************************************************************/ 00040 /* Include files */ 00041 /*****************************************************************************/ 00042 #include "cc3100_simplelink.h" 00043 #include "cc3100_protocol.h" 00044 #include "cc3100_driver.h" 00045 00046 #include "cc3100_netapp.h" 00047 #include "fPtr_func.h" 00048 #include "cli_uart.h" 00049 00050 namespace mbed_cc3100 { 00051 00052 /*****************************************************************************/ 00053 /* Macro declarations */ 00054 /*****************************************************************************/ 00055 const uint32_t NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT = ((uint32_t)0x1 << 31); 00056 00057 #ifdef SL_TINY 00058 const uint8_t NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH = 63; 00059 #else 00060 const uint8_t NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH = 255; 00061 #endif 00062 00063 //#ifndef SL_PLATFORM_MULTI_THREADED 00064 #if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) 00065 cc3100_netapp::cc3100_netapp(cc3100_driver &driver, cc3100_nonos &nonos) 00066 : _driver(driver), _nonos(nonos) 00067 { 00068 } 00069 #else 00070 cc3100_netapp::cc3100_netapp(cc3100_driver &driver) 00071 : _driver(driver) 00072 { 00073 } 00074 #endif 00075 cc3100_netapp::~cc3100_netapp() 00076 { 00077 00078 } 00079 00080 00081 /*****************************************************************************/ 00082 /* API functions */ 00083 /*****************************************************************************/ 00084 00085 /***************************************************************************** 00086 sl_NetAppStart 00087 *****************************************************************************/ 00088 typedef union { 00089 _NetAppStartStopCommand_t Cmd; 00090 _NetAppStartStopResponse_t Rsp; 00091 } _SlNetAppStartStopMsg_u; 00092 00093 #if _SL_INCLUDE_FUNC(sl_NetAppStart) 00094 const _SlCmdCtrl_t _SlNetAppStartCtrl = { 00095 SL_OPCODE_NETAPP_START_COMMAND, 00096 sizeof(_NetAppStartStopCommand_t), 00097 sizeof(_NetAppStartStopResponse_t) 00098 }; 00099 00100 int16_t cc3100_netapp::sl_NetAppStart(const uint32_t AppBitMap) 00101 { 00102 _SlNetAppStartStopMsg_u Msg; 00103 Msg.Cmd.appId = AppBitMap; 00104 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStartCtrl, &Msg, NULL)); 00105 00106 return Msg.Rsp.status; 00107 } 00108 #endif 00109 00110 /***************************************************************************** 00111 sl_NetAppStop 00112 *****************************************************************************/ 00113 #if _SL_INCLUDE_FUNC(sl_NetAppStop) 00114 const _SlCmdCtrl_t _SlNetAppStopCtrl = 00115 { 00116 SL_OPCODE_NETAPP_STOP_COMMAND, 00117 sizeof(_NetAppStartStopCommand_t), 00118 sizeof(_NetAppStartStopResponse_t) 00119 }; 00120 int16_t cc3100_netapp::sl_NetAppStop(const uint32_t AppBitMap) 00121 { 00122 00123 _SlNetAppStartStopMsg_u Msg; 00124 Msg.Cmd.appId = AppBitMap; 00125 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStopCtrl, &Msg, NULL)); 00126 00127 return Msg.Rsp.status; 00128 } 00129 #endif 00130 00131 00132 /******************************************************************************/ 00133 /* sl_NetAppGetServiceList */ 00134 /******************************************************************************/ 00135 typedef struct { 00136 uint8_t IndexOffest; 00137 uint8_t MaxServiceCount; 00138 uint8_t Flags; 00139 int8_t Padding; 00140 } NetappGetServiceListCMD_t; 00141 00142 typedef union { 00143 NetappGetServiceListCMD_t Cmd; 00144 _BasicResponse_t Rsp; 00145 } _SlNetappGetServiceListMsg_u; 00146 00147 #if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList) 00148 const _SlCmdCtrl_t _SlGetServiceListeCtrl = { 00149 SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE, 00150 sizeof(NetappGetServiceListCMD_t), 00151 sizeof(_BasicResponse_t) 00152 }; 00153 00154 int16_t cc3100_netapp::sl_NetAppGetServiceList(const uint8_t IndexOffest, 00155 const uint8_t MaxServiceCount, 00156 const uint8_t Flags, 00157 int8_t *pBuffer, 00158 const uint32_t RxBufferLength 00159 ) 00160 { 00161 int32_t retVal= 0; 00162 _SlNetappGetServiceListMsg_u Msg; 00163 _SlCmdExt_t CmdExt; 00164 uint16_t ServiceSize = 0; 00165 uint16_t BufferSize = 0; 00166 00167 /* 00168 Calculate RX pBuffer size 00169 WARNING: 00170 if this size is BufferSize than 1480 error should be returned because there 00171 is no place in the RX packet. 00172 */ 00173 switch(Flags) { 00174 case SL_NET_APP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE: 00175 ServiceSize = sizeof(SlNetAppGetFullServiceWithTextIpv4List_t); 00176 break; 00177 00178 case SL_NET_APP_FULL_SERVICE_IPV4_TYPE: 00179 ServiceSize = sizeof(SlNetAppGetFullServiceIpv4List_t); 00180 break; 00181 00182 case SL_NET_APP_SHORT_SERVICE_IPV4_TYPE: 00183 ServiceSize = sizeof(SlNetAppGetShortServiceIpv4List_t); 00184 break; 00185 00186 default: 00187 ServiceSize = sizeof(_BasicResponse_t); 00188 break; 00189 } 00190 00191 00192 00193 BufferSize = MaxServiceCount * ServiceSize; 00194 00195 /*Check the size of the requested services is smaller than size of the user buffer. 00196 If not an error is returned in order to avoid overwriting memory. */ 00197 if(RxBufferLength <= BufferSize) { 00198 return SL_ERROR_NETAPP_RX_BUFFER_LENGTH_ERROR; 00199 } 00200 00201 _driver._SlDrvResetCmdExt(&CmdExt); 00202 CmdExt.RxPayloadLen = BufferSize; 00203 00204 CmdExt.pRxPayload = (uint8_t *)pBuffer; 00205 00206 Msg.Cmd.IndexOffest = IndexOffest; 00207 Msg.Cmd.MaxServiceCount = MaxServiceCount; 00208 Msg.Cmd.Flags = Flags; 00209 Msg.Cmd.Padding = 0; 00210 00211 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetServiceListeCtrl, &Msg, &CmdExt)); 00212 retVal = Msg.Rsp.status; 00213 00214 return (int16_t)retVal; 00215 } 00216 00217 #endif 00218 00219 /*****************************************************************************/ 00220 /* sl_mDNSRegisterService */ 00221 /*****************************************************************************/ 00222 /* 00223 * The below struct depicts the constant parameters of the command/API RegisterService. 00224 * 00225 1. ServiceLen - The length of the service should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00226 2. TextLen - The length of the text should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00227 3. port - The port on this target host. 00228 4. TTL - The TTL of the service 00229 5. Options - bitwise parameters: 00230 bit 0 - is unique (means if the service needs to be unique) 00231 bit 31 - for internal use if the service should be added or deleted (set means ADD). 00232 bit 1-30 for future. 00233 00234 NOTE: 00235 00236 1. There are another variable parameter is this API which is the service name and the text. 00237 2. According to now there is no warning and Async event to user on if the service is a unique. 00238 * 00239 */ 00240 00241 typedef struct { 00242 uint8_t ServiceNameLen; 00243 uint8_t TextLen; 00244 uint16_t Port; 00245 uint32_t TTL; 00246 uint32_t Options; 00247 } NetappMdnsSetService_t; 00248 00249 typedef union { 00250 NetappMdnsSetService_t Cmd; 00251 _BasicResponse_t Rsp; 00252 } _SlNetappMdnsRegisterServiceMsg_u; 00253 00254 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterUnregisterService) 00255 const _SlCmdCtrl_t _SlRegisterServiceCtrl = { 00256 SL_OPCODE_NETAPP_MDNSREGISTERSERVICE, 00257 sizeof(NetappMdnsSetService_t), 00258 sizeof(_BasicResponse_t) 00259 }; 00260 00261 /****************************************************************************** 00262 00263 sl_NetAppMDNSRegisterService 00264 00265 CALLER user from its host 00266 00267 00268 DESCRIPTION: 00269 Add/delete service 00270 The function manipulates the command that register the service and call 00271 to the NWP in order to add/delete the service to/from the mDNS package and to/from the DB. 00272 00273 This register service is a service offered by the application. 00274 This unregister service is a service offered by the application before. 00275 00276 The service name should be full service name according to RFC 00277 of the DNS-SD - means the value in name field in SRV answer. 00278 00279 Example for service name: 00280 1. PC1._ipp._tcp.local 00281 2. PC2_server._ftp._tcp.local 00282 00283 If the option is_unique is set, mDNS probes the service name to make sure 00284 it is unique before starting to announce the service on the network. 00285 Instance is the instance portion of the service name. 00286 00287 00288 00289 00290 PARAMETERS: 00291 00292 The command is from constant parameters and variables parameters. 00293 00294 Constant parameters are: 00295 00296 ServiceLen - The length of the service. 00297 TextLen - The length of the service should be smaller than 64. 00298 port - The port on this target host. 00299 TTL - The TTL of the service 00300 Options - bitwise parameters: 00301 bit 0 - is unique (means if the service needs to be unique) 00302 bit 31 - for internal use if the service should be added or deleted (set means ADD). 00303 bit 1-30 for future. 00304 00305 The variables parameters are: 00306 00307 Service name(full service name) - The service name. 00308 Example for service name: 00309 1. PC1._ipp._tcp.local 00310 2. PC2_server._ftp._tcp.local 00311 00312 Text - The description of the service. 00313 should be as mentioned in the RFC 00314 (according to type of the service IPP,FTP...) 00315 00316 NOTE - pay attention 00317 00318 1. Temporary - there is an allocation on stack of internal buffer. 00319 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00320 It means that the sum of the text length and service name length cannot be bigger than 00321 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00322 If it is - An error is returned. 00323 00324 2. According to now from certain constraints the variables parameters are set in the 00325 attribute part (contain constant parameters) 00326 00327 00328 00329 RETURNS: Status - the immediate response of the command status. 00330 0 means success. 00331 00332 00333 00334 ******************************************************************************/ 00335 int16_t cc3100_netapp::sl_NetAppMDNSRegisterUnregisterService(const char* pServiceName, 00336 const uint8_t ServiceNameLen, 00337 const char* pText, 00338 const uint8_t TextLen, 00339 const uint16_t Port, 00340 const uint32_t TTL, 00341 const uint32_t Options) 00342 { 00343 00344 _SlNetappMdnsRegisterServiceMsg_u Msg; 00345 _SlCmdExt_t CmdExt ; 00346 unsigned char ServiceNameAndTextBuffer[NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH]; 00347 unsigned char *TextPtr; 00348 00349 /* 00350 00351 NOTE - pay attention 00352 00353 1. Temporary - there is an allocation on stack of internal buffer. 00354 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00355 It means that the sum of the text length and service name length cannot be bigger than 00356 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00357 If it is - An error is returned. 00358 00359 2. According to now from certain constraints the variables parameters are set in the 00360 attribute part (contain constant parameters) 00361 00362 00363 */ 00364 00365 /*build the attribute part of the command. 00366 It contains the constant parameters of the command*/ 00367 00368 Msg.Cmd.ServiceNameLen = ServiceNameLen; 00369 Msg.Cmd.Options = Options; 00370 Msg.Cmd.Port = Port; 00371 Msg.Cmd.TextLen = TextLen; 00372 Msg.Cmd.TTL = TTL; 00373 00374 /*Build the payload part of the command 00375 Copy the service name and text to one buffer. 00376 NOTE - pay attention 00377 The size of the service length + the text length should be smaller than 255, 00378 Until the simplelink drive supports to variable length through SPI command. */ 00379 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*/ 00380 return -1; 00381 } 00382 00383 _driver._SlDrvMemZero(ServiceNameAndTextBuffer, NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH); 00384 00385 00386 /*Copy the service name*/ 00387 memcpy(ServiceNameAndTextBuffer, 00388 pServiceName, 00389 ServiceNameLen); 00390 00391 if(TextLen > 0 ) { 00392 00393 TextPtr = &ServiceNameAndTextBuffer[ServiceNameLen]; 00394 /*Copy the text just after the service name*/ 00395 memcpy(TextPtr, pText, TextLen); 00396 } 00397 00398 _driver._SlDrvResetCmdExt(&CmdExt); 00399 CmdExt.TxPayloadLen = (TextLen + ServiceNameLen); 00400 CmdExt.pTxPayload = (uint8_t *)ServiceNameAndTextBuffer; 00401 00402 00403 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRegisterServiceCtrl, &Msg, &CmdExt)); 00404 00405 return (int16_t)Msg.Rsp.status; 00406 00407 00408 } 00409 #endif 00410 00411 /**********************************************************************************************/ 00412 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService) 00413 int16_t cc3100_netapp::sl_NetAppMDNSRegisterService(const char* pServiceName, 00414 const uint8_t ServiceNameLen, 00415 const char* pText, 00416 const uint8_t TextLen, 00417 const uint16_t Port, 00418 const uint32_t TTL, 00419 uint32_t Options) 00420 { 00421 00422 /* 00423 00424 NOTE - pay attention 00425 00426 1. Temporary - there is an allocation on stack of internal buffer. 00427 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00428 It means that the sum of the text length and service name length cannot be bigger than 00429 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00430 If it is - An error is returned. 00431 00432 2. According to now from certain constraints the variables parameters are set in the 00433 attribute part (contain constant parameters) 00434 00435 */ 00436 00437 /*Set the add service bit in the options parameter. 00438 In order not use different opcodes for the register service and unregister service 00439 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added 00440 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName 00441 and ServiceNameLen values. */ 00442 Options |= NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT; 00443 00444 return (sl_NetAppMDNSRegisterUnregisterService( pServiceName, ServiceNameLen, pText, TextLen, Port, TTL, Options)); 00445 00446 00447 } 00448 #endif 00449 /**********************************************************************************************/ 00450 00451 00452 00453 /**********************************************************************************************/ 00454 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService) 00455 int16_t cc3100_netapp::sl_NetAppMDNSUnRegisterService(const char* pServiceName, const uint8_t ServiceNameLen) 00456 { 00457 uint32_t Options = 0; 00458 00459 /* 00460 00461 NOTE - pay attention 00462 00463 The size of the service length should be smaller than 255, 00464 Until the simplelink drive supports to variable length through SPI command. 00465 00466 00467 */ 00468 00469 /*Clear the add service bit in the options parameter. 00470 In order not use different opcodes for the register service and unregister service 00471 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added 00472 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName 00473 and ServiceNameLen values.*/ 00474 00475 Options &= (~NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT); 00476 00477 return (sl_NetAppMDNSRegisterUnregisterService(pServiceName, ServiceNameLen, NULL, 0, 0, 0, Options)); 00478 00479 00480 } 00481 #endif 00482 /**********************************************************************************************/ 00483 00484 00485 00486 /*****************************************************************************/ 00487 /* sl_DnsGetHostByService */ 00488 /*****************************************************************************/ 00489 /* 00490 * The below struct depicts the constant parameters of the command/API sl_DnsGetHostByService. 00491 * 00492 1. ServiceLen - The length of the service should be smaller than 255. 00493 2. AddrLen - TIPv4 or IPv6 (SL_AF_INET , SL_AF_INET6). 00494 * 00495 */ 00496 00497 typedef struct { 00498 uint8_t ServiceLen; 00499 uint8_t AddrLen; 00500 uint16_t Padding; 00501 } _GetHostByServiceCommand_t; 00502 00503 00504 00505 /* 00506 * The below structure depict the constant parameters that are returned in the Async event answer 00507 * according to command/API sl_DnsGetHostByService for IPv4 and IPv6. 00508 * 00509 1Status - The status of the response. 00510 2.Address - Contains the IP address of the service. 00511 3.Port - Contains the port of the service. 00512 4.TextLen - Contains the max length of the text that the user wants to get. 00513 it means that if the test of service is bigger that its value than 00514 the text is cut to inout_TextLen value. 00515 Output: Contain the length of the text that is returned. Can be full text or part 00516 of the text (see above). 00517 00518 * 00519 00520 typedef struct { 00521 uint16_t Status; 00522 uint16_t TextLen; 00523 uint32_t Port; 00524 uint32_t Address; 00525 } _GetHostByServiceIPv4AsyncResponse_t; 00526 */ 00527 00528 typedef struct { 00529 uint16_t Status; 00530 uint16_t TextLen; 00531 uint32_t Port; 00532 uint32_t Address[4]; 00533 } _GetHostByServiceIPv6AsyncResponse_t; 00534 00535 00536 typedef union { 00537 _GetHostByServiceIPv4AsyncResponse_t IpV4; 00538 _GetHostByServiceIPv6AsyncResponse_t IpV6; 00539 } _GetHostByServiceAsyncResponseAttribute_u; 00540 00541 typedef union { 00542 _GetHostByServiceCommand_t Cmd; 00543 _BasicResponse_t Rsp; 00544 } _SlGetHostByServiceMsg_u; 00545 00546 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService) 00547 const _SlCmdCtrl_t _SlGetHostByServiceCtrl = { 00548 SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICE, 00549 sizeof(_GetHostByServiceCommand_t), 00550 sizeof(_BasicResponse_t) 00551 }; 00552 00553 int32_t cc3100_netapp::sl_NetAppDnsGetHostByService(unsigned char *pServiceName, /* string containing all (or only part): name + subtype + service */ 00554 const uint8_t ServiceLen, 00555 const uint8_t Family, /* 4-IPv4 , 16-IPv6 */ 00556 uint32_t pAddr[], 00557 uint32_t *pPort, 00558 uint16_t *pTextLen, /* in: max len , out: actual len */ 00559 unsigned char *pText) 00560 { 00561 00562 _SlGetHostByServiceMsg_u Msg; 00563 _SlCmdExt_t CmdExt ; 00564 _GetHostByServiceAsyncResponse_t AsyncRsp; 00565 uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS; 00566 00567 /* 00568 Note: 00569 1. The return's attributes are belonged to first service that is found. 00570 It can be other services with the same service name will response to 00571 the query. The results of these responses are saved in the peer cache of the NWP, and 00572 should be read by another API. 00573 00574 2. Text length can be 120 bytes only - not more 00575 It is because of constraints in the NWP on the buffer that is allocated for the Async event. 00576 00577 3.The API waits to Async event by blocking. It means that the API is finished only after an Async event 00578 is sent by the NWP. 00579 00580 4.No rolling option!!! - only PTR type is sent. 00581 00582 00583 */ 00584 /*build the attribute part of the command. 00585 It contains the constant parameters of the command */ 00586 00587 Msg.Cmd.ServiceLen = ServiceLen; 00588 Msg.Cmd.AddrLen = Family; 00589 00590 /*Build the payload part of the command 00591 Copy the service name and text to one buffer.*/ 00592 _driver._SlDrvResetCmdExt(&CmdExt); 00593 CmdExt.TxPayloadLen = ServiceLen; 00594 00595 CmdExt.pTxPayload = (uint8_t *)pServiceName; 00596 00597 00598 /*set pointers to the output parameters (the returned parameters). 00599 This pointers are belonged to local struct that is set to global Async response parameter. 00600 It is done in order not to run more than one sl_DnsGetHostByService at the same time. 00601 The API should be run only if global parameter is pointed to NULL. */ 00602 AsyncRsp.out_pText = pText; 00603 AsyncRsp.inout_TextLen = (uint16_t* )pTextLen; 00604 AsyncRsp.out_pPort = pPort; 00605 AsyncRsp.out_pAddr = (uint32_t *)pAddr; 00606 00607 00608 ObjIdx = _driver._SlDrvProtectAsyncRespSetting((uint8_t*)&AsyncRsp, GETHOSYBYSERVICE_ID, SL_MAX_SOCKETS); 00609 00610 if (MAX_CONCURRENT_ACTIONS == ObjIdx) 00611 { 00612 return SL_POOL_IS_EMPTY; 00613 } 00614 00615 if (SL_AF_INET6 == Family) { 00616 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; 00617 } 00618 /* Send the command */ 00619 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByServiceCtrl, &Msg, &CmdExt)); 00620 00621 00622 00623 /* If the immediate reponse is O.K. than wait for aSYNC event response. */ 00624 if(SL_RET_CODE_OK == Msg.Rsp.status) { 00625 _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj); 00626 00627 /* If we are - it means that Async event was sent. 00628 The results are copied in the Async handle return functions */ 00629 00630 Msg.Rsp.status = AsyncRsp.Status; 00631 } 00632 00633 _driver._SlDrvReleasePoolObj(ObjIdx); 00634 return Msg.Rsp.status; 00635 } 00636 #endif 00637 00638 /*****************************************************************************/ 00639 /* _sl_HandleAsync_DnsGetHostByAddr */ 00640 /*****************************************************************************/ 00641 #ifndef SL_TINY_EXT 00642 void cc3100_netapp::_sl_HandleAsync_DnsGetHostByAddr(void *pVoidBuf) 00643 { 00644 SL_TRACE0(DBG_MSG, MSG_303, "STUB: _sl_HandleAsync_DnsGetHostByAddr not implemented yet!"); 00645 return; 00646 } 00647 #endif 00648 /*****************************************************************************/ 00649 /* sl_DnsGetHostByName */ 00650 /*****************************************************************************/ 00651 typedef union { 00652 _GetHostByNameIPv4AsyncResponse_t IpV4; 00653 _GetHostByNameIPv6AsyncResponse_t IpV6; 00654 } _GetHostByNameAsyncResponse_u; 00655 00656 typedef union { 00657 _GetHostByNameCommand_t Cmd; 00658 _BasicResponse_t Rsp; 00659 } _SlGetHostByNameMsg_u; 00660 00661 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName) 00662 const _SlCmdCtrl_t _SlGetHostByNameCtrl = { 00663 SL_OPCODE_NETAPP_DNSGETHOSTBYNAME, 00664 sizeof(_GetHostByNameCommand_t), 00665 sizeof(_BasicResponse_t) 00666 }; 00667 00668 int16_t cc3100_netapp::sl_NetAppDnsGetHostByName(unsigned char * hostname, const uint16_t usNameLen, uint32_t* out_ip_addr, const uint8_t family) 00669 { 00670 _SlGetHostByNameMsg_u Msg; 00671 _SlCmdExt_t ExtCtrl; 00672 _GetHostByNameAsyncResponse_u AsyncRsp; 00673 uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS; 00674 00675 _driver._SlDrvResetCmdExt(&ExtCtrl); 00676 ExtCtrl.TxPayloadLen = usNameLen; 00677 00678 ExtCtrl.pTxPayload = (unsigned char *)hostname; 00679 00680 00681 Msg.Cmd.Len = usNameLen; 00682 Msg.Cmd.family = family; 00683 00684 /*Use Obj to issue the command, if not available try later */ 00685 ObjIdx = (uint8_t)_driver._SlDrvWaitForPoolObj(GETHOSYBYNAME_ID,SL_MAX_SOCKETS); 00686 if (MAX_CONCURRENT_ACTIONS == ObjIdx) { 00687 printf("SL_POOL_IS_EMPTY \r\n"); 00688 return SL_POOL_IS_EMPTY; 00689 } 00690 00691 _driver._SlDrvProtectionObjLockWaitForever(); 00692 00693 g_pCB->ObjPool[ObjIdx].pRespArgs = (uint8_t *)&AsyncRsp; 00694 /*set bit to indicate IPv6 address is expected */ 00695 if (SL_AF_INET6 == family) { 00696 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; 00697 } 00698 00699 _driver._SlDrvProtectionObjUnLock(); 00700 00701 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByNameCtrl, &Msg, &ExtCtrl)); 00702 00703 if(SL_RET_CODE_OK == Msg.Rsp.status) { 00704 _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj); 00705 Msg.Rsp.status = AsyncRsp.IpV4.status; 00706 00707 if(SL_OS_RET_CODE_OK == (int16_t)Msg.Rsp.status) { 00708 memcpy((int8_t *)out_ip_addr, (signed char *)&AsyncRsp.IpV4.ip0, (SL_AF_INET == family) ? SL_IPV4_ADDRESS_SIZE : SL_IPV6_ADDRESS_SIZE); 00709 } 00710 } 00711 _driver._SlDrvReleasePoolObj(ObjIdx); 00712 return Msg.Rsp.status; 00713 } 00714 #endif 00715 00716 #ifndef SL_TINY_EXT 00717 void cc3100_netapp::CopyPingResultsToReport(_PingReportResponse_t *pResults,SlPingReport_t *pReport) 00718 { 00719 pReport->PacketsSent = pResults->numSendsPings; 00720 pReport->PacketsReceived = pResults->numSuccsessPings; 00721 pReport->MinRoundTime = pResults->rttMin; 00722 pReport->MaxRoundTime = pResults->rttMax; 00723 pReport->AvgRoundTime = pResults->rttAvg; 00724 pReport->TestTime = pResults->testTime; 00725 } 00726 #endif 00727 /*****************************************************************************/ 00728 /* sl_PingStart */ 00729 /*****************************************************************************/ 00730 typedef union { 00731 _PingStartCommand_t Cmd; 00732 _PingReportResponse_t Rsp; 00733 } _SlPingStartMsg_u; 00734 00735 00736 typedef enum { 00737 CMD_PING_TEST_RUNNING = 0, 00738 CMD_PING_TEST_STOPPED 00739 } _SlPingStatus_e; 00740 00741 P_SL_DEV_PING_CALLBACK pPingCallBackFunc; 00742 00743 #if _SL_INCLUDE_FUNC(sl_NetAppPingStart) 00744 int16_t cc3100_netapp::sl_NetAppPingStart(const SlPingStartCommand_t* pPingParams, const uint8_t family, SlPingReport_t *pReport, const P_SL_DEV_PING_CALLBACK pPingCallback) 00745 { 00746 00747 _SlCmdCtrl_t CmdCtrl = {0, sizeof(_PingStartCommand_t), sizeof(_BasicResponse_t)}; 00748 _SlPingStartMsg_u Msg; 00749 _PingReportResponse_t PingRsp; 00750 uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS; 00751 00752 if( 0 == pPingParams->Ip ) 00753 { /* stop any ongoing ping */ 00754 return _driver._SlDrvBasicCmd(SL_OPCODE_NETAPP_PINGSTOP); 00755 } 00756 00757 if(SL_AF_INET == family) { 00758 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART; 00759 memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV4_ADDRESS_SIZE); 00760 } else { 00761 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART_V6; 00762 memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV6_ADDRESS_SIZE); 00763 } 00764 00765 Msg.Cmd.pingIntervalTime = pPingParams->PingIntervalTime; 00766 Msg.Cmd.PingSize = pPingParams->PingSize; 00767 Msg.Cmd.pingRequestTimeout = pPingParams->PingRequestTimeout; 00768 Msg.Cmd.totalNumberOfAttempts = pPingParams->TotalNumberOfAttempts; 00769 Msg.Cmd.flags = pPingParams->Flags; 00770 00771 if( pPingCallback ) { 00772 pPingCallBackFunc = pPingCallback; 00773 } else { 00774 /*Use Obj to issue the command, if not available try later */ 00775 ObjIdx = (uint8_t)_driver._SlDrvWaitForPoolObj(PING_ID,SL_MAX_SOCKETS); 00776 if (MAX_CONCURRENT_ACTIONS == ObjIdx) { 00777 return SL_POOL_IS_EMPTY; 00778 } 00779 //#ifndef SL_PLATFORM_MULTI_THREADED 00780 #if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) 00781 OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 00782 #else 00783 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 00784 #endif 00785 /* async response handler for non callback mode */ 00786 g_pCB->ObjPool[ObjIdx].pRespArgs = (uint8_t *)&PingRsp; 00787 pPingCallBackFunc = NULL; 00788 //#ifndef SL_PLATFORM_MULTI_THREADED 00789 #if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) 00790 OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 00791 #else 00792 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 00793 #endif 00794 } 00795 00796 00797 VERIFY_RET_OK(_driver._SlDrvCmdOp(&CmdCtrl, &Msg, NULL)); 00798 /*send the command*/ 00799 if(CMD_PING_TEST_RUNNING == (int16_t)Msg.Rsp.status || CMD_PING_TEST_STOPPED == (int16_t)Msg.Rsp.status ) { 00800 /* block waiting for results if no callback function is used */ 00801 if( NULL == pPingCallback ) { 00802 _driver._SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj); 00803 if( SL_OS_RET_CODE_OK == (int16_t)PingRsp.status ) { 00804 CopyPingResultsToReport(&PingRsp,pReport); 00805 } 00806 _driver._SlDrvReleasePoolObj(ObjIdx); 00807 } 00808 } else { 00809 /* ping failure, no async response */ 00810 if( NULL == pPingCallback ) { 00811 _driver._SlDrvReleasePoolObj(ObjIdx); 00812 } 00813 } 00814 00815 return Msg.Rsp.status; 00816 } 00817 #endif 00818 00819 /*****************************************************************************/ 00820 /* sl_NetAppSet */ 00821 /*****************************************************************************/ 00822 typedef union { 00823 _NetAppSetGet_t Cmd; 00824 _BasicResponse_t Rsp; 00825 } _SlNetAppMsgSet_u; 00826 00827 #if _SL_INCLUDE_FUNC(sl_NetAppSet) 00828 const _SlCmdCtrl_t _SlNetAppSetCmdCtrl = { 00829 SL_OPCODE_NETAPP_NETAPPSET, 00830 sizeof(_NetAppSetGet_t), 00831 sizeof(_BasicResponse_t) 00832 }; 00833 00834 int32_t cc3100_netapp::sl_NetAppSet(const uint8_t AppId ,const uint8_t Option, const uint8_t OptionLen, const uint8_t *pOptionValue) 00835 { 00836 00837 _SlNetAppMsgSet_u Msg; 00838 _SlCmdExt_t CmdExt; 00839 00840 _driver._SlDrvResetCmdExt(&CmdExt); 00841 CmdExt.TxPayloadLen = (OptionLen+3) & (~3); 00842 00843 CmdExt.pTxPayload = (uint8_t *)pOptionValue; 00844 00845 Msg.Cmd.AppId = AppId; 00846 Msg.Cmd.ConfigLen = OptionLen; 00847 Msg.Cmd.ConfigOpt = Option; 00848 00849 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppSetCmdCtrl, &Msg, &CmdExt)); 00850 00851 return (int16_t)Msg.Rsp.status; 00852 } 00853 #endif 00854 00855 /*****************************************************************************/ 00856 /* sl_NetAppSendTokenValue */ 00857 /*****************************************************************************/ 00858 typedef union { 00859 sl_NetAppHttpServerSendToken_t Cmd; 00860 _BasicResponse_t Rsp; 00861 } _SlNetAppMsgSendTokenValue_u; 00862 00863 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS) 00864 const _SlCmdCtrl_t _SlNetAppSendTokenValueCmdCtrl = { 00865 SL_OPCODE_NETAPP_HTTPSENDTOKENVALUE, 00866 sizeof(sl_NetAppHttpServerSendToken_t), 00867 sizeof(_BasicResponse_t) 00868 }; 00869 00870 uint16_t cc3100_netapp::sl_NetAppSendTokenValue(slHttpServerData_t * Token_value) 00871 { 00872 00873 _SlNetAppMsgSendTokenValue_u Msg; 00874 _SlCmdExt_t CmdExt; 00875 00876 CmdExt.TxPayloadLen = (Token_value->value_len+3) & (~3); 00877 CmdExt.RxPayloadLen = 0; 00878 CmdExt.pTxPayload = (uint8_t *) Token_value->token_value; 00879 CmdExt.pRxPayload = NULL; 00880 00881 Msg.Cmd.token_value_len = Token_value->value_len; 00882 Msg.Cmd.token_name_len = Token_value->name_len; 00883 memcpy(&Msg.Cmd.token_name[0], Token_value->token_name, Token_value->name_len); 00884 00885 00886 VERIFY_RET_OK(_driver._SlDrvCmdSend((_SlCmdCtrl_t *)&_SlNetAppSendTokenValueCmdCtrl, &Msg, &CmdExt)); 00887 00888 return Msg.Rsp.status; 00889 } 00890 #endif 00891 00892 /*****************************************************************************/ 00893 /* sl_NetAppGet */ 00894 /*****************************************************************************/ 00895 typedef union { 00896 _NetAppSetGet_t Cmd; 00897 _NetAppSetGet_t Rsp; 00898 } _SlNetAppMsgGet_u; 00899 00900 #if _SL_INCLUDE_FUNC(sl_NetAppGet) 00901 const _SlCmdCtrl_t _SlNetAppGetCmdCtrl = { 00902 SL_OPCODE_NETAPP_NETAPPGET, 00903 sizeof(_NetAppSetGet_t), 00904 sizeof(_NetAppSetGet_t) 00905 }; 00906 00907 int32_t cc3100_netapp::sl_NetAppGet(const uint8_t AppId, const uint8_t Option, uint8_t *pOptionLen, uint8_t *pOptionValue) 00908 { 00909 _SlNetAppMsgGet_u Msg; 00910 _SlCmdExt_t CmdExt; 00911 00912 if (*pOptionLen == 0) { 00913 return SL_EZEROLEN; 00914 } 00915 00916 _driver._SlDrvResetCmdExt(&CmdExt); 00917 CmdExt.RxPayloadLen = *pOptionLen; 00918 00919 CmdExt.pRxPayload = (uint8_t *)pOptionValue; 00920 00921 Msg.Cmd.AppId = AppId; 00922 Msg.Cmd.ConfigOpt = Option; 00923 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppGetCmdCtrl, &Msg, &CmdExt)); 00924 00925 00926 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) { 00927 *pOptionLen = (uint8_t)CmdExt.RxPayloadLen; 00928 return SL_ESMALLBUF; 00929 } else { 00930 *pOptionLen = (uint8_t)CmdExt.ActualRxPayloadLen; 00931 } 00932 00933 return (int16_t)Msg.Rsp.Status; 00934 } 00935 #endif 00936 00937 //#ifndef SL_PLATFORM_MULTI_THREADED 00938 #if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN)) 00939 cc3100_flowcont::cc3100_flowcont(cc3100_driver &driver, cc3100_nonos &nonos) 00940 : _driver(driver), _nonos(nonos) 00941 { 00942 } 00943 #else 00944 cc3100_flowcont::cc3100_flowcont(cc3100_driver &driver) 00945 : _driver(driver) 00946 { 00947 } 00948 #endif 00949 cc3100_flowcont::~cc3100_flowcont() 00950 { 00951 00952 } 00953 #if 0 00954 /*****************************************************************************/ 00955 /* _SlDrvFlowContInit */ 00956 /*****************************************************************************/ 00957 void cc3100_flowcont::_SlDrvFlowContInit(void) 00958 { 00959 g_pCB->FlowContCB.TxPoolCnt = FLOW_CONT_MIN; 00960 00961 OSI_RET_OK_CHECK(_nonos.sl_LockObjCreate(&g_pCB->FlowContCB.TxLockObj, "TxLockObj")); 00962 00963 OSI_RET_OK_CHECK(_nonos.sl_SyncObjCreate(&g_pCB->FlowContCB.TxSyncObj, "TxSyncObj")); 00964 } 00965 00966 /*****************************************************************************/ 00967 /* _SlDrvFlowContDeinit */ 00968 /*****************************************************************************/ 00969 void cc3100_flowcont::_SlDrvFlowContDeinit(void) 00970 { 00971 g_pCB->FlowContCB.TxPoolCnt = 0; 00972 00973 OSI_RET_OK_CHECK(_nonos.sl_LockObjDelete(&g_pCB->FlowContCB.TxLockObj, 0)); 00974 00975 OSI_RET_OK_CHECK(_nonos.sl_SyncObjDelete(&g_pCB->FlowContCB.TxSyncObj, 0)); 00976 } 00977 #endif 00978 }//namespace mbed_cc3100 00979 00980
Generated on Tue Jul 12 2022 22:22:38 by 1.7.2