David Fletcher
/
cc3100_test
TI's CC3100 host driver and demo. Experimental and a work in progress.
Embed:
(wiki syntax)
Show/hide line numbers
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 /*****************************************************************************/ 00047 /* Macro declarations */ 00048 /*****************************************************************************/ 00049 #define NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT ((_u32)0x1 << 31) 00050 00051 #ifdef SL_TINY 00052 #define NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH 63 00053 #else 00054 #define NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH 255 00055 #endif 00056 00057 00058 /*****************************************************************************/ 00059 /* Functions prototypes */ 00060 /*****************************************************************************/ 00061 void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf); 00062 void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf); 00063 void _sl_HandleAsync_PingResponse(void *pVoidBuf); 00064 void CopyPingResultsToReport(_PingReportResponse_t *pResults,SlPingReport_t *pReport); 00065 _u16 sl_NetAppSendTokenValue(slHttpServerData_t * Token); 00066 _i16 sl_NetAppMDNSRegisterUnregisterService(const _i8* pServiceName, 00067 _u8 ServiceNameLen, 00068 const _i8* pText, 00069 _u8 TextLen, 00070 _u16 Port, 00071 _u32 TTL, 00072 _u32 Options); 00073 00074 00075 /*****************************************************************************/ 00076 /* API functions */ 00077 /*****************************************************************************/ 00078 00079 /***************************************************************************** 00080 sl_NetAppStart 00081 *****************************************************************************/ 00082 typedef union 00083 { 00084 _NetAppStartStopCommand_t Cmd; 00085 _NetAppStartStopResponse_t Rsp; 00086 }_SlNetAppStartStopMsg_u; 00087 00088 const _SlCmdCtrl_t _SlNetAppStartCtrl = 00089 { 00090 SL_OPCODE_NETAPP_START_COMMAND, 00091 sizeof(_NetAppStartStopCommand_t), 00092 sizeof(_NetAppStartStopResponse_t) 00093 }; 00094 00095 const _SlCmdCtrl_t _SlNetAppStopCtrl = 00096 { 00097 SL_OPCODE_NETAPP_STOP_COMMAND, 00098 sizeof(_NetAppStartStopCommand_t), 00099 sizeof(_NetAppStartStopResponse_t) 00100 }; 00101 00102 #if _SL_INCLUDE_FUNC(sl_NetAppStart) 00103 _i16 sl_NetAppStart(_u32 AppBitMap) 00104 { 00105 _SlNetAppStartStopMsg_u Msg; 00106 Msg.Cmd.appId = AppBitMap; 00107 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStartCtrl, &Msg, NULL)); 00108 00109 return Msg.Rsp.status; 00110 } 00111 #endif 00112 00113 /***************************************************************************** 00114 sl_NetAppStop 00115 *****************************************************************************/ 00116 #if _SL_INCLUDE_FUNC(sl_NetAppStop) 00117 _i16 sl_NetAppStop(_u32 AppBitMap) 00118 { 00119 _SlNetAppStartStopMsg_u Msg; 00120 Msg.Cmd.appId = AppBitMap; 00121 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppStopCtrl, &Msg, NULL)); 00122 00123 return Msg.Rsp.status; 00124 } 00125 #endif 00126 00127 00128 /******************************************************************************/ 00129 /* sl_NetAppGetServiceList */ 00130 /******************************************************************************/ 00131 typedef struct 00132 { 00133 _u8 IndexOffest; 00134 _u8 MaxServiceCount; 00135 _u8 Flags; 00136 _i8 Padding; 00137 }NetappGetServiceListCMD_t; 00138 00139 typedef union 00140 { 00141 NetappGetServiceListCMD_t Cmd; 00142 _BasicResponse_t Rsp; 00143 }_SlNetappGetServiceListMsg_u; 00144 00145 const _SlCmdCtrl_t _SlGetServiceListeCtrl = 00146 { 00147 SL_OPCODE_NETAPP_NETAPP_MDNS_LOOKUP_SERVICE, 00148 sizeof(NetappGetServiceListCMD_t), 00149 sizeof(_BasicResponse_t) 00150 }; 00151 00152 00153 #if _SL_INCLUDE_FUNC(sl_NetAppGetServiceList) 00154 _i16 sl_NetAppGetServiceList(_u8 IndexOffest, 00155 _u8 MaxServiceCount, 00156 _u8 Flags, 00157 _i8 *pBuffer, 00158 _u32 RxBufferLength 00159 ) 00160 { 00161 00162 _i32 retVal= 0; 00163 _SlNetappGetServiceListMsg_u Msg; 00164 _SlCmdExt_t CmdExt; 00165 _u16 ServiceSize = 0; 00166 _u16 BufferSize = 0; 00167 00168 /* 00169 Calculate RX pBuffer size 00170 WARNING: 00171 if this size is BufferSize than 1480 error should be returned because there 00172 is no place in the RX packet. 00173 */ 00174 switch(Flags) 00175 { 00176 case SL_NET_APP_FULL_SERVICE_WITH_TEXT_IPV4_TYPE: 00177 ServiceSize = sizeof(SlNetAppGetFullServiceWithTextIpv4List_t); 00178 break; 00179 00180 case SL_NET_APP_FULL_SERVICE_IPV4_TYPE: 00181 ServiceSize = sizeof(SlNetAppGetFullServiceIpv4List_t); 00182 break; 00183 00184 case SL_NET_APP_SHORT_SERVICE_IPV4_TYPE: 00185 ServiceSize = sizeof(SlNetAppGetShortServiceIpv4List_t); 00186 break; 00187 00188 default: 00189 ServiceSize = sizeof(_BasicResponse_t); 00190 break; 00191 } 00192 00193 00194 00195 BufferSize = MaxServiceCount * ServiceSize; 00196 00197 /*Check the size of the requested services is smaller than size of the user buffer. 00198 If not an error is returned in order to avoid overwriting memory. */ 00199 if(RxBufferLength <= BufferSize) 00200 { 00201 return SL_ERROR_NETAPP_RX_BUFFER_LENGTH_ERROR; 00202 } 00203 00204 CmdExt.TxPayloadLen = 0; 00205 CmdExt.RxPayloadLen = BufferSize; 00206 CmdExt.pTxPayload = NULL; 00207 CmdExt.pRxPayload = (_u8 *)pBuffer; 00208 00209 Msg.Cmd.IndexOffest = IndexOffest; 00210 Msg.Cmd.MaxServiceCount = MaxServiceCount; 00211 Msg.Cmd.Flags = Flags; 00212 Msg.Cmd.Padding = 0; 00213 00214 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetServiceListeCtrl, &Msg, &CmdExt)); 00215 retVal = Msg.Rsp.status; 00216 00217 return (_i16)retVal; 00218 } 00219 00220 #endif 00221 00222 /*****************************************************************************/ 00223 /* sl_mDNSRegisterService */ 00224 /*****************************************************************************/ 00225 /* 00226 * The below struct depicts the constant parameters of the command/API RegisterService. 00227 * 00228 1. ServiceLen - The length of the service should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00229 2. TextLen - The length of the text should be smaller than NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00230 3. port - The port on this target host. 00231 4. TTL - The TTL of the service 00232 5. Options - bitwise parameters: 00233 bit 0 - is unique (means if the service needs to be unique) 00234 bit 31 - for internal use if the service should be added or deleted (set means ADD). 00235 bit 1-30 for future. 00236 00237 NOTE: 00238 00239 1. There are another variable parameter is this API which is the service name and the text. 00240 2. According to now there is no warning and Async event to user on if the service is a unique. 00241 * 00242 */ 00243 00244 00245 typedef struct 00246 { 00247 _u8 ServiceNameLen; 00248 _u8 TextLen; 00249 _u16 Port; 00250 _u32 TTL; 00251 _u32 Options; 00252 }NetappMdnsSetService_t; 00253 00254 typedef union 00255 { 00256 NetappMdnsSetService_t Cmd; 00257 _BasicResponse_t Rsp; 00258 }_SlNetappMdnsRegisterServiceMsg_u; 00259 00260 const _SlCmdCtrl_t _SlRegisterServiceCtrl = 00261 { 00262 SL_OPCODE_NETAPP_MDNSREGISTERSERVICE, 00263 sizeof(NetappMdnsSetService_t), 00264 sizeof(_BasicResponse_t) 00265 }; 00266 00267 00268 /****************************************************************************** 00269 00270 sl_NetAppMDNSRegisterService 00271 00272 CALLER user from its host 00273 00274 00275 DESCRIPTION: 00276 Add/delete service 00277 The function manipulates the command that register the service and call 00278 to the NWP in order to add/delete the service to/from the mDNS package and to/from the DB. 00279 00280 This register service is a service offered by the application. 00281 This unregister service is a service offered by the application before. 00282 00283 The service name should be full service name according to RFC 00284 of the DNS-SD - means the value in name field in SRV answer. 00285 00286 Example for service name: 00287 1. PC1._ipp._tcp.local 00288 2. PC2_server._ftp._tcp.local 00289 00290 If the option is_unique is set, mDNS probes the service name to make sure 00291 it is unique before starting to announce the service on the network. 00292 Instance is the instance portion of the service name. 00293 00294 00295 00296 00297 PARAMETERS: 00298 00299 The command is from constant parameters and variables parameters. 00300 00301 Constant parameters are: 00302 00303 ServiceLen - The length of the service. 00304 TextLen - The length of the service should be smaller than 64. 00305 port - The port on this target host. 00306 TTL - The TTL of the service 00307 Options - bitwise parameters: 00308 bit 0 - is unique (means if the service needs to be unique) 00309 bit 31 - for internal use if the service should be added or deleted (set means ADD). 00310 bit 1-30 for future. 00311 00312 The variables parameters are: 00313 00314 Service name(full service name) - The service name. 00315 Example for service name: 00316 1. PC1._ipp._tcp.local 00317 2. PC2_server._ftp._tcp.local 00318 00319 Text - The description of the service. 00320 should be as mentioned in the RFC 00321 (according to type of the service IPP,FTP...) 00322 00323 NOTE - pay attention 00324 00325 1. Temporary - there is an allocation on stack of internal buffer. 00326 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00327 It means that the sum of the text length and service name length cannot be bigger than 00328 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00329 If it is - An error is returned. 00330 00331 2. According to now from certain constraints the variables parameters are set in the 00332 attribute part (contain constant parameters) 00333 00334 00335 00336 RETURNS: Status - the immediate response of the command status. 00337 0 means success. 00338 00339 00340 00341 ******************************************************************************/ 00342 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterUnregisterService) 00343 00344 _i16 sl_NetAppMDNSRegisterUnregisterService( const _i8* pServiceName, 00345 _u8 ServiceNameLen, 00346 const _i8* pText, 00347 _u8 TextLen, 00348 _u16 Port, 00349 _u32 TTL, 00350 _u32 Options) 00351 00352 { 00353 _SlNetappMdnsRegisterServiceMsg_u Msg; 00354 _SlCmdExt_t CmdExt ; 00355 _i8 ServiceNameAndTextBuffer[NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH]; 00356 _i8 *TextPtr; 00357 00358 /* 00359 00360 NOTE - pay attention 00361 00362 1. Temporary - there is an allocation on stack of internal buffer. 00363 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00364 It means that the sum of the text length and service name length cannot be bigger than 00365 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00366 If it is - An error is returned. 00367 00368 2. According to now from certain constraints the variables parameters are set in the 00369 attribute part (contain constant parameters) 00370 00371 00372 */ 00373 00374 /*build the attribute part of the command. 00375 It contains the constant parameters of the command*/ 00376 00377 Msg.Cmd.ServiceNameLen = ServiceNameLen; 00378 Msg.Cmd.Options = Options; 00379 Msg.Cmd.Port = Port; 00380 Msg.Cmd.TextLen = TextLen; 00381 Msg.Cmd.TTL = TTL; 00382 00383 /*Build the payload part of the command 00384 Copy the service name and text to one buffer. 00385 NOTE - pay attention 00386 The size of the service length + the text length should be smaller than 255, 00387 Until the simplelink drive supports to variable length through SPI command. */ 00388 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*/ 00389 { 00390 return -1; 00391 } 00392 00393 sl_Memset(ServiceNameAndTextBuffer,0,NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH); 00394 00395 00396 /*Copy the service name*/ 00397 sl_Memcpy(ServiceNameAndTextBuffer, 00398 pServiceName, 00399 ServiceNameLen); 00400 00401 if(TextLen > 0 ) 00402 { 00403 00404 TextPtr = &ServiceNameAndTextBuffer[ServiceNameLen]; 00405 /*Copy the text just after the service name*/ 00406 sl_Memcpy(TextPtr, 00407 pText, 00408 TextLen); 00409 00410 00411 } 00412 00413 CmdExt.TxPayloadLen = (TextLen + ServiceNameLen); 00414 CmdExt.RxPayloadLen = 0; 00415 CmdExt.pTxPayload = (_u8 *)ServiceNameAndTextBuffer; 00416 CmdExt.pRxPayload = NULL; 00417 00418 00419 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRegisterServiceCtrl, &Msg, &CmdExt)); 00420 00421 return (_i16)Msg.Rsp.status; 00422 00423 00424 } 00425 #endif 00426 00427 /**********************************************************************************************/ 00428 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSRegisterService) 00429 00430 _i16 sl_NetAppMDNSRegisterService( const _i8* pServiceName, 00431 _u8 ServiceNameLen, 00432 const _i8* pText, 00433 _u8 TextLen, 00434 _u16 Port, 00435 _u32 TTL, 00436 _u32 Options) 00437 00438 { 00439 00440 /* 00441 00442 NOTE - pay attention 00443 00444 1. Temporary - there is an allocation on stack of internal buffer. 00445 Its size is NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00446 It means that the sum of the text length and service name length cannot be bigger than 00447 NETAPP_MDNS_MAX_SERVICE_NAME_AND_TEXT_LENGTH. 00448 If it is - An error is returned. 00449 00450 2. According to now from certain constraints the variables parameters are set in the 00451 attribute part (contain constant parameters) 00452 00453 */ 00454 00455 /*Set the add service bit in the options parameter. 00456 In order not use different opcodes for the register service and unregister service 00457 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added 00458 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName 00459 and ServiceNameLen values. */ 00460 Options |= NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT; 00461 00462 return sl_NetAppMDNSRegisterUnregisterService( pServiceName, 00463 ServiceNameLen, 00464 pText, 00465 TextLen, 00466 Port, 00467 TTL, 00468 Options); 00469 00470 00471 } 00472 #endif 00473 /**********************************************************************************************/ 00474 00475 00476 00477 /**********************************************************************************************/ 00478 #if _SL_INCLUDE_FUNC(sl_NetAppMDNSUnRegisterService) 00479 00480 _i16 sl_NetAppMDNSUnRegisterService( const _i8* pServiceName, 00481 _u8 ServiceNameLen) 00482 00483 00484 { 00485 _u32 Options = 0; 00486 00487 /* 00488 00489 NOTE - pay attention 00490 00491 The size of the service length should be smaller than 255, 00492 Until the simplelink drive supports to variable length through SPI command. 00493 00494 00495 */ 00496 00497 /*Clear the add service bit in the options parameter. 00498 In order not use different opcodes for the register service and unregister service 00499 bit 31 in option is taken for this purpose. if it is set it means in NWP that the service should be added 00500 if it is cleared it means that the service should be deleted and there is only meaning to pServiceName 00501 and ServiceNameLen values.*/ 00502 00503 Options &= (~NETAPP_MDNS_OPTIONS_ADD_SERVICE_BIT); 00504 00505 return sl_NetAppMDNSRegisterUnregisterService( pServiceName, 00506 ServiceNameLen, 00507 NULL, 00508 0, 00509 0, 00510 0, 00511 Options); 00512 00513 00514 } 00515 #endif 00516 /**********************************************************************************************/ 00517 00518 00519 00520 /*****************************************************************************/ 00521 /* sl_DnsGetHostByService */ 00522 /*****************************************************************************/ 00523 /* 00524 * The below struct depicts the constant parameters of the command/API sl_DnsGetHostByService. 00525 * 00526 1. ServiceLen - The length of the service should be smaller than 255. 00527 2. AddrLen - TIPv4 or IPv6 (SL_AF_INET , SL_AF_INET6). 00528 * 00529 */ 00530 00531 typedef struct 00532 { 00533 _u8 ServiceLen; 00534 _u8 AddrLen; 00535 _u16 Padding; 00536 }_GetHostByServiceCommand_t; 00537 00538 00539 00540 /* 00541 * The below structure depict the constant parameters that are returned in the Async event answer 00542 * according to command/API sl_DnsGetHostByService for IPv4 and IPv6. 00543 * 00544 1Status - The status of the response. 00545 2.Address - Contains the IP address of the service. 00546 3.Port - Contains the port of the service. 00547 4.TextLen - Contains the max length of the text that the user wants to get. 00548 it means that if the test of service is bigger that its value than 00549 the text is cut to inout_TextLen value. 00550 Output: Contain the length of the text that is returned. Can be full text or part 00551 of the text (see above). 00552 00553 * 00554 */ 00555 typedef struct 00556 { 00557 _u16 Status; 00558 _u16 TextLen; 00559 _u32 Port; 00560 _u32 Address; 00561 }_GetHostByServiceIPv4AsyncResponse_t; 00562 00563 00564 typedef struct 00565 { 00566 _u16 Status; 00567 _u16 TextLen; 00568 _u32 Port; 00569 _u32 Address[4]; 00570 }_GetHostByServiceIPv6AsyncResponse_t; 00571 00572 00573 typedef union 00574 { 00575 _GetHostByServiceIPv4AsyncResponse_t IpV4; 00576 _GetHostByServiceIPv6AsyncResponse_t IpV6; 00577 }_GetHostByServiceAsyncResponseAttribute_u; 00578 00579 /* 00580 * The below struct contains pointers to the output parameters that the user gives 00581 * 00582 */ 00583 typedef struct 00584 { 00585 _i16 Status; 00586 _u32 *out_pAddr; 00587 _u32 *out_pPort; 00588 _u16 *inout_TextLen; // in: max len , out: actual len 00589 _i8 *out_pText; 00590 }_GetHostByServiceAsyncResponse_t; 00591 00592 00593 typedef union 00594 { 00595 _GetHostByServiceCommand_t Cmd; 00596 _BasicResponse_t Rsp; 00597 }_SlGetHostByServiceMsg_u; 00598 00599 const _SlCmdCtrl_t _SlGetHostByServiceCtrl = 00600 { 00601 SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICE, 00602 sizeof(_GetHostByServiceCommand_t), 00603 sizeof(_BasicResponse_t) 00604 }; 00605 00606 00607 00608 /******************************************************************************/ 00609 00610 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByService) 00611 _i32 sl_NetAppDnsGetHostByService(_i8 *pServiceName, /* string containing all (or only part): name + subtype + service */ 00612 _u8 ServiceLen, 00613 _u8 Family, /* 4-IPv4 , 16-IPv6 */ 00614 _u32 pAddr[], 00615 _u32 *pPort, 00616 _u16 *pTextLen, /* in: max len , out: actual len */ 00617 _i8 *pText 00618 ) 00619 { 00620 _SlGetHostByServiceMsg_u Msg; 00621 _SlCmdExt_t CmdExt ; 00622 _GetHostByServiceAsyncResponse_t AsyncRsp; 00623 _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; 00624 00625 /* 00626 Note: 00627 1. The return's attributes are belonged to first service that is found. 00628 It can be other services with the same service name will response to 00629 the query. The results of these responses are saved in the peer cache of the NWP, and 00630 should be read by another API. 00631 00632 2. Text length can be 120 bytes only - not more 00633 It is because of constraints in the NWP on the buffer that is allocated for the Async event. 00634 00635 3.The API waits to Async event by blocking. It means that the API is finished only after an Async event 00636 is sent by the NWP. 00637 00638 4.No rolling option!!! - only PTR type is sent. 00639 00640 00641 */ 00642 /*build the attribute part of the command. 00643 It contains the constant parameters of the command */ 00644 00645 Msg.Cmd.ServiceLen = ServiceLen; 00646 Msg.Cmd.AddrLen = Family; 00647 00648 /*Build the payload part of the command 00649 Copy the service name and text to one buffer.*/ 00650 CmdExt.TxPayloadLen = ServiceLen; 00651 CmdExt.RxPayloadLen = 0; 00652 CmdExt.pTxPayload = (_u8 *)pServiceName; 00653 CmdExt.pRxPayload = NULL; 00654 00655 /*set pointers to the output parameters (the returned parameters). 00656 This pointers are belonged to local struct that is set to global Async response parameter. 00657 It is done in order not to run more than one sl_DnsGetHostByService at the same time. 00658 The API should be run only if global parameter is pointed to NULL. */ 00659 AsyncRsp.out_pText = pText; 00660 AsyncRsp.inout_TextLen = (_u16* )pTextLen; 00661 AsyncRsp.out_pPort = pPort; 00662 AsyncRsp.out_pAddr = (_u32 *)pAddr; 00663 00664 00665 /*Use Obj to issue the command, if not available try later */ 00666 ObjIdx = (_u8)_SlDrvWaitForPoolObj(GETHOSYBYSERVICE_ID,SL_MAX_SOCKETS); 00667 00668 if (MAX_CONCURRENT_ACTIONS == ObjIdx) 00669 { 00670 return SL_POOL_IS_EMPTY; 00671 } 00672 00673 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 00674 00675 g_pCB->ObjPool[ObjIdx].pRespArgs = (unsigned char*)&AsyncRsp;//(unsigned char*) replaced (void*) 00676 00677 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 00678 /* set bit to indicate IPv6 address is expected */ 00679 if (SL_AF_INET6 == Family) 00680 { 00681 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; 00682 } 00683 /* Send the command */ 00684 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByServiceCtrl, &Msg, &CmdExt)); 00685 00686 00687 00688 /* If the immediate reponse is O.K. than wait for aSYNC event response. */ 00689 if(SL_RET_CODE_OK == Msg.Rsp.status) 00690 { 00691 OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); 00692 00693 /* If we are - it means that Async event was sent. 00694 The results are copied in the Async handle return functions */ 00695 00696 Msg.Rsp.status = AsyncRsp.Status; 00697 } 00698 00699 _SlDrvReleasePoolObj(ObjIdx); 00700 return Msg.Rsp.status; 00701 } 00702 #endif 00703 /******************************************************************************/ 00704 00705 /****************************************************************************** 00706 _sl_HandleAsync_DnsGetHostByService 00707 00708 CALLER NWP - Async event on sl_DnsGetHostByService with IPv4 Family 00709 00710 00711 DESCRIPTION: 00712 00713 Async event on sl_DnsGetHostByService command with IPv4 Family. 00714 Return service attributes like IP address, port and text according to service name. 00715 The user sets a service name Full/Part (see example below), and should get the: 00716 1. IP of the service 00717 2. The port of service. 00718 3. The text of service. 00719 00720 Hence it can make a connection to the specific service and use it. 00721 It is similar to get host by name method. 00722 00723 It is done by a single shot query with PTR type on the service name. 00724 00725 00726 00727 Note: 00728 1. The return's attributes are belonged to first service that is found. 00729 It can be other services with the same service name will response to 00730 the query. The results of these responses are saved in the peer cache of the NWP, and 00731 should be read by another API. 00732 00733 00734 PARAMETERS: 00735 00736 pVoidBuf - is point to opcode of the event. 00737 it contains the outputs that are given to the user 00738 00739 outputs description: 00740 00741 1.out_pAddr[] - output: Contain the IP address of the service. 00742 2.out_pPort - output: Contain the port of the service. 00743 3.inout_TextLen - Input: Contain the max length of the text that the user wants to get. 00744 it means that if the test of service is bigger that its value than 00745 the text is cut to inout_TextLen value. 00746 Output: Contain the length of the text that is returned. Can be full text or part 00747 of the text (see above). 00748 00749 4.out_pText - Contain the text of the service (full or part see above- inout_TextLen description). 00750 00751 * 00752 00753 00754 RETURNS: success or fail. 00755 00756 00757 00758 00759 00760 ******************************************************************************/ 00761 void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf) 00762 { 00763 00764 _GetHostByServiceAsyncResponse_t* Res; 00765 _u16 TextLen; 00766 _u16 UserTextLen; 00767 00768 00769 /*pVoidBuf - is point to opcode of the event.*/ 00770 00771 /*set pMsgArgs to point to the attribute of the event.*/ 00772 _GetHostByServiceIPv4AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00773 00774 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00775 00776 /*IPv6*/ 00777 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) 00778 { 00779 return; 00780 } 00781 /*IPv4*/ 00782 else 00783 { 00784 /************************************************************************************************* 00785 00786 1. Copy the attribute part of the evnt to the attribute part of the response 00787 sl_Memcpy(g_pCB->GetHostByServiceCB.pAsyncRsp, pMsgArgs, sizeof(_GetHostByServiceIPv4AsyncResponse_t)); 00788 00789 set to TextLen the text length of the service.*/ 00790 TextLen = pMsgArgs->TextLen; 00791 00792 /*Res pointed to mDNS global object struct */ 00793 Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs; 00794 00795 00796 00797 /*It is 4 bytes so we avoid from memcpy*/ 00798 Res->out_pAddr[0] = pMsgArgs->Address; 00799 Res->out_pPort[0] = pMsgArgs->Port; 00800 Res->Status = pMsgArgs->Status; 00801 00802 /*set to TextLen the text length of the user (input fromthe user).*/ 00803 UserTextLen = Res->inout_TextLen[0]; 00804 00805 /*Cut the service text if the user requested for smaller text.*/ 00806 UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen; 00807 Res->inout_TextLen[0] = UserTextLen ; 00808 00809 /************************************************************************************************** 00810 00811 2. Copy the payload part of the evnt (the text) to the payload part of the response 00812 the lenght of the copy is according to the text length in the attribute part. */ 00813 00814 00815 sl_Memcpy(Res->out_pText , 00816 (_i8 *)(& pMsgArgs[1]) , /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/ 00817 UserTextLen ); 00818 00819 00820 /**************************************************************************************************/ 00821 00822 OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); 00823 return; 00824 } 00825 } 00826 00827 00828 00829 /*****************************************************************************/ 00830 /* _sl_HandleAsync_DnsGetHostByAddr */ 00831 /*****************************************************************************/ 00832 void _sl_HandleAsync_DnsGetHostByAddr(void *pVoidBuf) 00833 { 00834 SL_TRACE0(DBG_MSG, MSG_303, "STUB: _sl_HandleAsync_DnsGetHostByAddr not implemented yet!"); 00835 return; 00836 } 00837 00838 /*****************************************************************************/ 00839 /* sl_DnsGetHostByName */ 00840 /*****************************************************************************/ 00841 typedef union 00842 { 00843 _GetHostByNameIPv4AsyncResponse_t IpV4; 00844 _GetHostByNameIPv6AsyncResponse_t IpV6; 00845 }_GetHostByNameAsyncResponse_u; 00846 00847 typedef union 00848 { 00849 _GetHostByNameCommand_t Cmd; 00850 _BasicResponse_t Rsp; 00851 }_SlGetHostByNameMsg_u; 00852 00853 const _SlCmdCtrl_t _SlGetHostByNameCtrl = 00854 { 00855 SL_OPCODE_NETAPP_DNSGETHOSTBYNAME, 00856 sizeof(_GetHostByNameCommand_t), 00857 sizeof(_BasicResponse_t) 00858 }; 00859 #if _SL_INCLUDE_FUNC(sl_NetAppDnsGetHostByName) 00860 _i16 sl_NetAppDnsGetHostByName(_i8 * hostname, _u16 usNameLen, _u32* out_ip_addr,_u8 family) 00861 { 00862 _SlGetHostByNameMsg_u Msg; 00863 _SlCmdExt_t ExtCtrl; 00864 _GetHostByNameAsyncResponse_u AsyncRsp; 00865 _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; 00866 00867 ExtCtrl.TxPayloadLen = usNameLen; 00868 ExtCtrl.RxPayloadLen = 0; 00869 ExtCtrl.pTxPayload = (_u8 *)hostname; 00870 ExtCtrl.pRxPayload = 0; 00871 00872 Msg.Cmd.Len = usNameLen; 00873 Msg.Cmd.family = family; 00874 00875 /*Use Obj to issue the command, if not available try later */ 00876 ObjIdx = (_u8)_SlDrvWaitForPoolObj(GETHOSYBYNAME_ID,SL_MAX_SOCKETS); 00877 if (MAX_CONCURRENT_ACTIONS == ObjIdx) 00878 { 00879 return SL_POOL_IS_EMPTY; 00880 } 00881 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 00882 00883 g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&AsyncRsp; 00884 /*set bit to indicate IPv6 address is expected */ 00885 if (SL_AF_INET6 == family) 00886 { 00887 g_pCB->ObjPool[ObjIdx].AdditionalData |= SL_NETAPP_FAMILY_MASK; 00888 } 00889 00890 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 00891 00892 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetHostByNameCtrl, &Msg, &ExtCtrl)); 00893 00894 if(SL_RET_CODE_OK == Msg.Rsp.status) 00895 { 00896 OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); 00897 Msg.Rsp.status = AsyncRsp.IpV4.status; 00898 00899 if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status) 00900 { 00901 sl_Memcpy((_i8 *)out_ip_addr, 00902 (_i8 *)&AsyncRsp.IpV4.ip0, 00903 (SL_AF_INET == family) ? SL_IPV4_ADDRESS_SIZE : SL_IPV6_ADDRESS_SIZE); 00904 } 00905 } 00906 _SlDrvReleasePoolObj(ObjIdx); 00907 return Msg.Rsp.status; 00908 } 00909 #endif 00910 /******************************************************************************/ 00911 /* _sl_HandleAsync_DnsGetHostByName */ 00912 /******************************************************************************/ 00913 void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf) 00914 { 00915 _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00916 00917 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 00918 00919 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00920 00921 /*IPv6 */ 00922 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) 00923 { 00924 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t)); 00925 } 00926 /*IPv4 */ 00927 else 00928 { 00929 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t)); 00930 } 00931 OSI_RET_OK_CHECK(sl_SyncObjSignal(&(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj))); 00932 00933 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 00934 return; 00935 } 00936 00937 00938 void CopyPingResultsToReport(_PingReportResponse_t *pResults,SlPingReport_t *pReport) 00939 { 00940 pReport->PacketsSent = pResults->numSendsPings; 00941 pReport->PacketsReceived = pResults->numSuccsessPings; 00942 pReport->MinRoundTime = pResults->rttMin; 00943 pReport->MaxRoundTime = pResults->rttMax; 00944 pReport->AvgRoundTime = pResults->rttAvg; 00945 pReport->TestTime = pResults->testTime; 00946 } 00947 00948 00949 /*****************************************************************************/ 00950 /* _sl_HandleAsync_PingResponse */ 00951 /*****************************************************************************/ 00952 void _sl_HandleAsync_PingResponse(void *pVoidBuf) 00953 { 00954 _PingReportResponse_t *pMsgArgs = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00955 SlPingReport_t pingReport; 00956 00957 if(pPingCallBackFunc) 00958 { 00959 CopyPingResultsToReport(pMsgArgs,&pingReport); 00960 pPingCallBackFunc(&pingReport); 00961 } 00962 else 00963 { 00964 00965 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 00966 VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp); 00967 00968 if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) 00969 { 00970 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t)); 00971 OSI_RET_OK_CHECK(sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj)); 00972 } 00973 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 00974 } 00975 return; 00976 } 00977 00978 00979 /*****************************************************************************/ 00980 /* sl_PingStart */ 00981 /*****************************************************************************/ 00982 typedef union 00983 { 00984 _PingStartCommand_t Cmd; 00985 _PingReportResponse_t Rsp; 00986 }_SlPingStartMsg_u; 00987 00988 00989 typedef enum 00990 { 00991 CMD_PING_TEST_RUNNING = 0, 00992 CMD_PING_TEST_STOPPED 00993 }_SlPingStatus_e; 00994 00995 00996 #if _SL_INCLUDE_FUNC(sl_NetAppPingStart) 00997 _i16 sl_NetAppPingStart(SlPingStartCommand_t* pPingParams,_u8 family,SlPingReport_t *pReport,const P_SL_DEV_PING_CALLBACK pPingCallback) 00998 { 00999 _SlCmdCtrl_t CmdCtrl = {0, sizeof(_PingStartCommand_t), sizeof(_BasicResponse_t)}; 01000 _SlPingStartMsg_u Msg; 01001 _PingReportResponse_t PingRsp; 01002 _u8 ObjIdx = MAX_CONCURRENT_ACTIONS; 01003 01004 if( 0 == pPingParams->Ip ) // stop any ongoing ping 01005 { 01006 return _SlDrvBasicCmd(SL_OPCODE_NETAPP_PINGSTOP); 01007 } 01008 01009 if(SL_AF_INET == family) 01010 { 01011 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART; 01012 sl_Memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV4_ADDRESS_SIZE); 01013 } 01014 else 01015 { 01016 CmdCtrl.Opcode = SL_OPCODE_NETAPP_PINGSTART_V6; 01017 sl_Memcpy(&Msg.Cmd.ip0, &pPingParams->Ip, SL_IPV6_ADDRESS_SIZE); 01018 } 01019 01020 Msg.Cmd.pingIntervalTime = pPingParams->PingIntervalTime; 01021 Msg.Cmd.PingSize = pPingParams->PingSize; 01022 Msg.Cmd.pingRequestTimeout = pPingParams->PingRequestTimeout; 01023 Msg.Cmd.totalNumberOfAttempts = pPingParams->TotalNumberOfAttempts; 01024 Msg.Cmd.flags = pPingParams->Flags; 01025 01026 if( pPingCallback ) 01027 { 01028 pPingCallBackFunc = pPingCallback; 01029 } 01030 else 01031 { 01032 /*Use Obj to issue the command, if not available try later */ 01033 ObjIdx = (_u8)_SlDrvWaitForPoolObj(PING_ID,SL_MAX_SOCKETS); 01034 if (MAX_CONCURRENT_ACTIONS == ObjIdx) 01035 { 01036 return SL_POOL_IS_EMPTY; 01037 } 01038 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER)); 01039 /* async response handler for non callback mode */ 01040 g_pCB->ObjPool[ObjIdx].pRespArgs = (_u8 *)&PingRsp; 01041 pPingCallBackFunc = NULL; 01042 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj)); 01043 } 01044 01045 01046 VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL)); 01047 /*send the command*/ 01048 if(CMD_PING_TEST_RUNNING == (_i16)Msg.Rsp.status || CMD_PING_TEST_STOPPED == (_i16)Msg.Rsp.status ) 01049 { 01050 /* block waiting for results if no callback function is used */ 01051 if( NULL == pPingCallback ) 01052 { 01053 OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, SL_OS_WAIT_FOREVER)); 01054 if( SL_OS_RET_CODE_OK == (_i16)PingRsp.status ) 01055 { 01056 CopyPingResultsToReport(&PingRsp,pReport); 01057 } 01058 _SlDrvReleasePoolObj(ObjIdx); 01059 } 01060 } 01061 else 01062 { /* ping failure, no async response */ 01063 if( NULL == pPingCallback ) 01064 { 01065 _SlDrvReleasePoolObj(ObjIdx); 01066 } 01067 } 01068 01069 return Msg.Rsp.status; 01070 } 01071 #endif 01072 01073 /*****************************************************************************/ 01074 /* sl_NetAppSet */ 01075 /*****************************************************************************/ 01076 typedef union 01077 { 01078 _NetAppSetGet_t Cmd; 01079 _BasicResponse_t Rsp; 01080 }_SlNetAppMsgSet_u; 01081 01082 const _SlCmdCtrl_t _SlNetAppSetCmdCtrl = 01083 { 01084 SL_OPCODE_NETAPP_NETAPPSET, 01085 sizeof(_NetAppSetGet_t), 01086 sizeof(_BasicResponse_t) 01087 }; 01088 01089 #if _SL_INCLUDE_FUNC(sl_NetAppSet) 01090 _i32 sl_NetAppSet(_u8 AppId ,_u8 Option,_u8 OptionLen, _u8 *pOptionValue) 01091 { 01092 _SlNetAppMsgSet_u Msg; 01093 _SlCmdExt_t CmdExt; 01094 01095 CmdExt.TxPayloadLen = (OptionLen+3) & (~3); 01096 CmdExt.RxPayloadLen = 0; 01097 CmdExt.pTxPayload = (_u8 *)pOptionValue; 01098 CmdExt.pRxPayload = NULL; 01099 01100 01101 Msg.Cmd.AppId = AppId; 01102 Msg.Cmd.ConfigLen = OptionLen; 01103 Msg.Cmd.ConfigOpt = Option; 01104 01105 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppSetCmdCtrl, &Msg, &CmdExt)); 01106 01107 return (_i16)Msg.Rsp.status; 01108 } 01109 #endif 01110 01111 /*****************************************************************************/ 01112 /* sl_NetAppSendTokenValue */ 01113 /*****************************************************************************/ 01114 typedef union 01115 { 01116 sl_NetAppHttpServerSendToken_t Cmd; 01117 _BasicResponse_t Rsp; 01118 }_SlNetAppMsgSendTokenValue_u; 01119 01120 const _SlCmdCtrl_t _SlNetAppSendTokenValueCmdCtrl = 01121 { 01122 SL_OPCODE_NETAPP_HTTPSENDTOKENVALUE, 01123 sizeof(sl_NetAppHttpServerSendToken_t), 01124 sizeof(_BasicResponse_t) 01125 }; 01126 01127 _u16 sl_NetAppSendTokenValue(slHttpServerData_t * Token_value) 01128 { 01129 _SlNetAppMsgSendTokenValue_u Msg; 01130 _SlCmdExt_t CmdExt; 01131 01132 CmdExt.TxPayloadLen = (Token_value->value_len+3) & (~3); 01133 CmdExt.RxPayloadLen = 0; 01134 CmdExt.pTxPayload = (_u8 *) Token_value->token_value; 01135 CmdExt.pRxPayload = NULL; 01136 01137 Msg.Cmd.token_value_len = Token_value->value_len; 01138 Msg.Cmd.token_name_len = Token_value->name_len; 01139 sl_Memcpy(&Msg.Cmd.token_name[0], Token_value->token_name, Token_value->name_len); 01140 01141 01142 VERIFY_RET_OK(_SlDrvCmdSend((_SlCmdCtrl_t *)&_SlNetAppSendTokenValueCmdCtrl, &Msg, &CmdExt)); 01143 01144 return Msg.Rsp.status; 01145 } 01146 01147 /*****************************************************************************/ 01148 /* sl_NetAppGet */ 01149 /*****************************************************************************/ 01150 typedef union 01151 { 01152 _NetAppSetGet_t Cmd; 01153 _NetAppSetGet_t Rsp; 01154 }_SlNetAppMsgGet_u; 01155 01156 const _SlCmdCtrl_t _SlNetAppGetCmdCtrl = 01157 { 01158 SL_OPCODE_NETAPP_NETAPPGET, 01159 sizeof(_NetAppSetGet_t), 01160 sizeof(_NetAppSetGet_t) 01161 }; 01162 01163 #if _SL_INCLUDE_FUNC(sl_NetAppGet) 01164 _i32 sl_NetAppGet(_u8 AppId, _u8 Option,_u8 *pOptionLen, _u8 *pOptionValue) 01165 { 01166 _SlNetAppMsgGet_u Msg; 01167 _SlCmdExt_t CmdExt; 01168 01169 if (*pOptionLen == 0) 01170 { 01171 return SL_EZEROLEN; 01172 } 01173 CmdExt.TxPayloadLen = 0; 01174 CmdExt.RxPayloadLen = *pOptionLen; 01175 CmdExt.pTxPayload = NULL; 01176 CmdExt.pRxPayload = (_u8 *)pOptionValue; 01177 CmdExt.ActualRxPayloadLen = 0; 01178 01179 Msg.Cmd.AppId = AppId; 01180 Msg.Cmd.ConfigOpt = Option; 01181 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetAppGetCmdCtrl, &Msg, &CmdExt)); 01182 01183 01184 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) 01185 { 01186 *pOptionLen = (_u8)CmdExt.RxPayloadLen; 01187 return SL_ESMALLBUF; 01188 } 01189 else 01190 { 01191 *pOptionLen = (_u8)CmdExt.ActualRxPayloadLen; 01192 } 01193 01194 return (_i16)Msg.Rsp.Status; 01195 } 01196 #endif 01197 01198 01199 /*****************************************************************************/ 01200 /* _SlDrvNetAppEventHandler */ 01201 /*****************************************************************************/ 01202 void _SlDrvNetAppEventHandler(void *pArgs) 01203 { 01204 _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs; 01205 #ifdef sl_HttpServerCallback 01206 SlHttpServerEvent_t httpServerEvent; 01207 SlHttpServerResponse_t httpServerResponse; 01208 #endif 01209 switch(pHdr->GenHeader.Opcode) 01210 { 01211 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE: 01212 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6: 01213 _sl_HandleAsync_DnsGetHostByName(pArgs); 01214 break; 01215 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE: 01216 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6: 01217 _sl_HandleAsync_DnsGetHostByService(pArgs); 01218 break; 01219 case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE: 01220 _sl_HandleAsync_PingResponse(pArgs); 01221 break; 01222 case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE: 01223 { 01224 #ifdef sl_HttpServerCallback 01225 _u8 *pTokenName; 01226 slHttpServerData_t Token_value; 01227 sl_NetAppHttpServerGetToken_t *httpGetToken = (sl_NetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr); 01228 pTokenName = (_u8 *)((sl_NetAppHttpServerGetToken_t *)httpGetToken + 1); 01229 01230 httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE; 01231 httpServerResponse.ResponseData.token_value.len = MAX_TOKEN_VALUE_LEN; 01232 httpServerResponse.ResponseData.token_value.data = (_u8 *)_SL_RESP_ARGS_START(pHdr) + MAX_TOKEN_NAME_LEN; //Reuse the async buffer for getting the token value response from the user 01233 01234 httpServerEvent.Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT; 01235 httpServerEvent.EventData.httpTokenName.len = httpGetToken->token_name_len; 01236 httpServerEvent.EventData.httpTokenName.data = pTokenName; 01237 01238 Token_value.token_name = pTokenName; 01239 01240 sl_HttpServerCallback (&httpServerEvent, &httpServerResponse); 01241 01242 Token_value.value_len = httpServerResponse.ResponseData.token_value.len; 01243 Token_value.name_len = httpServerEvent.EventData.httpTokenName.len; 01244 01245 Token_value.token_value = httpServerResponse.ResponseData.token_value.data; 01246 01247 01248 sl_NetAppSendTokenValue(&Token_value); 01249 #endif 01250 } 01251 break; 01252 01253 case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE: 01254 { 01255 #ifdef sl_HttpServerCallback 01256 _u8 *pPostParams; 01257 01258 sl_NetAppHttpServerPostToken_t *httpPostTokenArgs = (sl_NetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr); 01259 pPostParams = (_u8 *)((sl_NetAppHttpServerPostToken_t *)httpPostTokenArgs + 1); 01260 01261 httpServerEvent.Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT; 01262 01263 httpServerEvent.EventData.httpPostData.action.len = httpPostTokenArgs->post_action_len; 01264 httpServerEvent.EventData.httpPostData.action.data = pPostParams; 01265 pPostParams+=httpPostTokenArgs->post_action_len; 01266 01267 httpServerEvent.EventData.httpPostData.token_name.len = httpPostTokenArgs->token_name_len; 01268 httpServerEvent.EventData.httpPostData.token_name.data = pPostParams; 01269 pPostParams+=httpPostTokenArgs->token_name_len; 01270 01271 httpServerEvent.EventData.httpPostData.token_value.len = httpPostTokenArgs->token_value_len; 01272 httpServerEvent.EventData.httpPostData.token_value.data = pPostParams; 01273 01274 httpServerResponse.Response = SL_NETAPP_RESPONSE_NONE; 01275 01276 01277 sl_HttpServerCallback (&httpServerEvent, &httpServerResponse); 01278 #endif 01279 } 01280 break; 01281 default: 01282 SL_ERROR_TRACE2(MSG_305, "ASSERT: _SlDrvNetAppEventHandler : invalid opcode = 0x%x = %1", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode); 01283 VERIFY_PROTOCOL(0); 01284 } 01285 } 01286 01287 /*! 01288 \brief This function handles callback for the HTTP server events 01289 01290 \param[in] pHttpEvent - Contains the relevant event information 01291 \param[in] pHttpResponse - Should be filled by the user with the 01292 relevant response information 01293 01294 \return None 01295 01296 \note 01297 01298 \warning 01299 */ 01300 void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, 01301 SlHttpServerResponse_t *pHttpResponse) 01302 { 01303 /* 01304 * This application doesn't work with HTTP server - Hence these 01305 * events are not handled here 01306 */ 01307 // CLI_Write((_u8 *)" [HTTP EVENT] Unexpected event \n\r"); 01308 printf(" [HTTP EVENT] Unexpected event \n\r"); 01309 }
Generated on Tue Jul 12 2022 22:55:20 by 1.7.2