DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers netapp.c Source File

netapp.c

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