Maxim Integrated / Mbed OS MAXREFDES155#

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wlan.c Source File

wlan.c

00001 /*
00002  * wlan.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 MAX_SSID_LEN           (32)
00050 #define MAX_KEY_LEN            (63)
00051 #define MAX_USER_LEN           (32)
00052 #define MAX_ANON_USER_LEN      (32)
00053 #define MAX_SMART_CONFIG_KEY   (16)
00054 
00055 
00056 /*****************************************************************************
00057 sl_WlanConnect
00058 *****************************************************************************/
00059 typedef struct 
00060 {
00061     _WlanConnectEapCommand_t    Args;
00062     _i8                        Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
00063 }_WlanConnectCmd_t;
00064 
00065 typedef union
00066 {
00067     _WlanConnectCmd_t   Cmd;
00068     _BasicResponse_t    Rsp;
00069 }_SlWlanConnectMsg_u;
00070 
00071 
00072 #if _SL_INCLUDE_FUNC(sl_WlanConnect)
00073 _i16 sl_WlanConnect(const _i8*  pName,const _i16 NameLen,const _u8 *pMacAddr,const SlSecParams_t* pSecParams ,const SlSecParamsExt_t* pSecExtParams)
00074 {
00075     _SlWlanConnectMsg_u    Msg;
00076     _SlCmdCtrl_t           CmdCtrl = {0,0,0};
00077 
00078     _SlDrvMemZero(&Msg, (_u16)sizeof(_SlWlanConnectMsg_u));
00079     
00080     /* verify no erorr handling in progress. if in progress than
00081     ignore the API execution and return immediately with an error */
00082     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00083 
00084     CmdCtrl.TxDescLen = 0;/* init */
00085     CmdCtrl.RxDescLen = (_SlArgSize_t)sizeof(_BasicResponse_t);
00086 
00087     /* verify SSID length */
00088     VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
00089     /* verify SSID is not NULL */
00090     if( NULL == pName )
00091     {
00092        return SL_INVALPARAM;
00093     }
00094     /* update SSID length */
00095     Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen;
00096 
00097     /* Profile with no security */
00098     /* Enterprise security profile */
00099     if (NULL != pSecExtParams)
00100     {
00101         /* Update command opcode */
00102         CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTEAPCOMMAND;
00103         CmdCtrl.TxDescLen += sizeof(_WlanConnectEapCommand_t);
00104         /* copy SSID */
00105         sl_Memcpy(EAP_SSID_STRING(&Msg), pName, NameLen);
00106         CmdCtrl.TxDescLen += NameLen;
00107         /* Copy password if supplied */
00108         if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
00109         {
00110             /* update security type */
00111             Msg.Cmd.Args.Common.SecType = pSecParams->Type;
00112             /* verify key length */
00113             if (pSecParams->KeyLen > MAX_KEY_LEN)
00114             {
00115                 return SL_INVALPARAM;
00116             }
00117             /* update key length */
00118             Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
00119             ARG_CHECK_PTR(pSecParams->Key);
00120             /* copy key      */
00121             sl_Memcpy(EAP_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
00122             CmdCtrl.TxDescLen += pSecParams->KeyLen;
00123         }
00124         else
00125         {
00126             Msg.Cmd.Args.Common.PasswordLen = 0;
00127         }
00128 
00129         ARG_CHECK_PTR(pSecExtParams);
00130         /* Update Eap bitmask */
00131         Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
00132         /* Update Certificate file ID index - currently not supported */
00133         Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
00134         /* verify user length */
00135         if (pSecExtParams->UserLen > MAX_USER_LEN)
00136         {
00137             return SL_INVALPARAM;
00138         }
00139         Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
00140         /* copy user name (identity) */
00141         if(pSecExtParams->UserLen > 0)
00142         {
00143             sl_Memcpy(EAP_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
00144             CmdCtrl.TxDescLen += pSecExtParams->UserLen;
00145         }
00146         /* verify Anonymous user length  */
00147         if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
00148         {
00149             return SL_INVALPARAM;
00150         }
00151         Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
00152         /* copy Anonymous user */
00153         if(pSecExtParams->AnonUserLen > 0)
00154         {
00155             sl_Memcpy(EAP_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
00156             CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
00157         }
00158 
00159     }
00160 
00161     /* Regular or open security profile */
00162     else
00163     {
00164         /* Update command opcode */
00165         CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTCOMMAND;
00166         CmdCtrl.TxDescLen += sizeof(_WlanConnectCommon_t);
00167         /* copy SSID */
00168         sl_Memcpy(SSID_STRING(&Msg), pName, NameLen);   
00169         CmdCtrl.TxDescLen += NameLen;
00170         /* Copy password if supplied */
00171         if( NULL != pSecParams )
00172         {
00173             /* update security type */
00174             Msg.Cmd.Args.Common.SecType = pSecParams->Type;
00175             /* verify key length is valid */
00176             if (pSecParams->KeyLen > MAX_KEY_LEN)
00177             {
00178                 return SL_INVALPARAM;
00179             }
00180             /* update key length */
00181             Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
00182             CmdCtrl.TxDescLen += pSecParams->KeyLen;
00183             /* copy key (could be no key in case of WPS pin) */
00184             if( NULL != pSecParams->Key )
00185             {
00186                 sl_Memcpy(PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
00187             }
00188         }
00189         /* Profile with no security */
00190         else
00191         {
00192             Msg.Cmd.Args.Common.PasswordLen = 0;
00193             Msg.Cmd.Args.Common.SecType = SL_SEC_TYPE_OPEN;
00194         }   
00195     }
00196     /* If BSSID is not null, copy to buffer, otherwise set to 0 */
00197     if(NULL != pMacAddr)
00198     {
00199         sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
00200     }
00201     else
00202     {
00203         _SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, (_u16)sizeof(Msg.Cmd.Args.Common.Bssid));
00204     }
00205 
00206 
00207     VERIFY_RET_OK ( _SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
00208 
00209     return (_i16)Msg.Rsp.status;
00210 }
00211 #endif
00212 
00213 /*******************************************************************************/
00214 /*   sl_Disconnect  */
00215 /* ******************************************************************************/
00216 #if _SL_INCLUDE_FUNC(sl_WlanDisconnect)
00217 _i16 sl_WlanDisconnect(void)
00218 {
00219     /* verify no erorr handling in progress. if in progress than
00220     ignore the API execution and return immediately with an error */
00221     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00222 
00223     return _SlDrvBasicCmd(SL_OPCODE_WLAN_WLANDISCONNECTCOMMAND);
00224 }
00225 #endif
00226 
00227 /******************************************************************************/
00228 /*  sl_PolicySet  */
00229 /******************************************************************************/
00230 typedef union
00231 {
00232     _WlanPoliciySetGet_t    Cmd;
00233     _BasicResponse_t        Rsp;
00234 }_SlPolicyMsg_u;
00235 
00236 #if _SL_INCLUDE_FUNC(sl_WlanPolicySet)
00237 
00238 static const _SlCmdCtrl_t _SlPolicySetCmdCtrl =
00239 {
00240     SL_OPCODE_WLAN_POLICYSETCOMMAND,
00241     (_SlArgSize_t)sizeof(_WlanPoliciySetGet_t),
00242     (_SlArgSize_t)sizeof(_BasicResponse_t)
00243 };
00244 
00245 _i16 sl_WlanPolicySet(const _u8 Type , const _u8 Policy, _u8 *pVal,const _u8 ValLen)
00246 {
00247     _SlPolicyMsg_u         Msg;
00248     _SlCmdExt_t            CmdExt;
00249 
00250     /* verify no erorr handling in progress. if in progress than
00251     ignore the API execution and return immediately with an error */
00252     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00253 
00254     _SlDrvResetCmdExt(&CmdExt);
00255     CmdExt.TxPayloadLen = ValLen;
00256     CmdExt.pTxPayload = (_u8 *)pVal;
00257 
00258 
00259     Msg.Cmd.PolicyType        = Type;
00260     Msg.Cmd.PolicyOption      = Policy;
00261     Msg.Cmd.PolicyOptionLen   = ValLen;
00262 
00263     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicySetCmdCtrl, &Msg, &CmdExt));
00264 
00265     return (_i16)Msg.Rsp.status;
00266 }
00267 #endif
00268 
00269 
00270 /******************************************************************************/
00271 /*  sl_PolicyGet  */
00272 /******************************************************************************/
00273 typedef union
00274 {
00275     _WlanPoliciySetGet_t        Cmd;
00276     _WlanPoliciySetGet_t        Rsp;
00277 }_SlPolicyGetMsg_u;
00278 
00279 #if _SL_INCLUDE_FUNC(sl_WlanPolicyGet)
00280 
00281 static const _SlCmdCtrl_t _SlPolicyGetCmdCtrl =
00282 {
00283     SL_OPCODE_WLAN_POLICYGETCOMMAND,
00284     (_SlArgSize_t)sizeof(_WlanPoliciySetGet_t),
00285     (_SlArgSize_t)sizeof(_WlanPoliciySetGet_t)
00286 };
00287 
00288 _i16 sl_WlanPolicyGet(const _u8 Type ,_u8 Policy,_u8 *pVal,_u8 *pValLen)
00289 {
00290     _SlPolicyGetMsg_u      Msg;
00291     _SlCmdExt_t            CmdExt;
00292 
00293     /* verify no erorr handling in progress. if in progress than
00294     ignore the API execution and return immediately with an error */
00295     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00296 
00297     if (*pValLen == 0)
00298     {
00299         return SL_EZEROLEN;
00300     }
00301 
00302     _SlDrvResetCmdExt(&CmdExt);
00303     CmdExt.RxPayloadLen = (_i16)(*pValLen);
00304     CmdExt.pRxPayload = pVal;
00305 
00306     Msg.Cmd.PolicyType = Type;
00307     Msg.Cmd.PolicyOption = Policy;
00308     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicyGetCmdCtrl, &Msg, &CmdExt));
00309 
00310 
00311     if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) 
00312     {
00313         *pValLen = Msg.Rsp.PolicyOptionLen;
00314         return SL_ESMALLBUF;
00315     }
00316     else
00317     {
00318         /*  no pointer valus, fill the results into _i8 */
00319         *pValLen = (_u8)CmdExt.ActualRxPayloadLen;
00320         if( 0 == CmdExt.ActualRxPayloadLen )
00321         {
00322             *pValLen = 1;
00323             pVal[0] = Msg.Rsp.PolicyOption;
00324         }
00325     }
00326     return (_i16)SL_OS_RET_CODE_OK;
00327 }
00328 #endif
00329 
00330 
00331 /*******************************************************************************/
00332 /*  sl_ProfileAdd  */
00333 /*******************************************************************************/
00334 typedef struct
00335 {
00336     _WlanAddGetEapProfile_t Args;
00337     _i8                    Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
00338 }_SlProfileParams_t;
00339 
00340 typedef union
00341 {
00342     _SlProfileParams_t      Cmd;
00343     _BasicResponse_t        Rsp;
00344 }_SlProfileAddMsg_u;
00345 
00346 
00347 
00348 #if _SL_INCLUDE_FUNC(sl_WlanProfileAdd)
00349 _i16 sl_WlanProfileAdd(const _i8*  pName,const  _i16 NameLen,const  _u8 *pMacAddr,const  SlSecParams_t* pSecParams ,const SlSecParamsExt_t* pSecExtParams,const _u32  Priority,const _u32  Options)
00350 {
00351     _SlProfileAddMsg_u      Msg;
00352     _SlCmdCtrl_t           CmdCtrl = {0,0,0};
00353     CmdCtrl.TxDescLen = 0;/* init */
00354     CmdCtrl.RxDescLen = (_SlArgSize_t)(sizeof(_BasicResponse_t));
00355 
00356 
00357     /* Options paramater is currently not in use */
00358     (void)Options;
00359 
00360     /* verify no erorr handling in progress. if in progress than
00361     ignore the API execution and return immediately with an error */
00362     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00363 
00364     /* update priority */
00365     Msg.Cmd.Args.Common.Priority = (_u8)Priority; 
00366     /* verify SSID is not NULL */
00367     if( NULL == pName )
00368     {
00369        return SL_INVALPARAM;
00370     }
00371     /* verify SSID length */
00372     VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
00373     /* update SSID length */
00374     Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen;
00375 
00376 
00377     /* Enterprise security profile */
00378     if  (NULL != pSecExtParams)
00379     {
00380         /* Update command opcode */
00381         CmdCtrl.Opcode = SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND;
00382         CmdCtrl.TxDescLen += sizeof(_WlanAddGetEapProfile_t);
00383 
00384         /* copy SSID */
00385         sl_Memcpy(EAP_PROFILE_SSID_STRING(&Msg), pName, NameLen);   
00386         CmdCtrl.TxDescLen += NameLen;
00387 
00388         /* Copy password if supplied */
00389         if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
00390         {
00391             /* update security type */
00392             Msg.Cmd.Args.Common.SecType = (_i8)(pSecParams->Type);
00393 
00394             if( SL_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType )
00395             {
00396                 Msg.Cmd.Args.Common.WepKeyId = 0;
00397             }
00398 
00399             /* verify key length */
00400             if (pSecParams->KeyLen > MAX_KEY_LEN)
00401             {
00402                 return SL_INVALPARAM;
00403             }
00404             VERIFY_PROTOCOL(pSecParams->KeyLen <= MAX_KEY_LEN);
00405             /* update key length */
00406             Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;   
00407             CmdCtrl.TxDescLen += pSecParams->KeyLen;
00408             ARG_CHECK_PTR(pSecParams->Key);
00409             /* copy key  */
00410             sl_Memcpy(EAP_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
00411         }
00412         else
00413         {
00414             Msg.Cmd.Args.Common.PasswordLen = 0;
00415         }
00416 
00417         ARG_CHECK_PTR(pSecExtParams);
00418         /* Update Eap bitmask */
00419         Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
00420         /* Update Certificate file ID index - currently not supported */
00421         Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
00422         /* verify user length */
00423         if (pSecExtParams->UserLen > MAX_USER_LEN)
00424         {
00425             return SL_INVALPARAM;
00426         }
00427         Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
00428         /* copy user name (identity) */
00429         if(pSecExtParams->UserLen > 0)
00430         {
00431             sl_Memcpy(EAP_PROFILE_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
00432             CmdCtrl.TxDescLen += pSecExtParams->UserLen;
00433         }
00434 
00435         /* verify Anonymous user length (for tunneled) */
00436         if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
00437         {
00438             return SL_INVALPARAM;
00439         }
00440         Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
00441 
00442         /* copy Anonymous user */
00443         if(pSecExtParams->AnonUserLen > 0)
00444         {
00445             sl_Memcpy(EAP_PROFILE_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
00446             CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
00447         }
00448 
00449     }
00450     /* Regular or open security profile */
00451     else
00452     {
00453         /* Update command opcode */
00454         CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEADDCOMMAND;
00455         /* update commnad length */
00456         CmdCtrl.TxDescLen += sizeof(_WlanAddGetProfile_t);
00457 
00458         if (NULL != pName)
00459         {
00460             /* copy SSID */
00461             sl_Memcpy(PROFILE_SSID_STRING(&Msg), pName, NameLen);
00462             CmdCtrl.TxDescLen += NameLen;
00463         }
00464 
00465         /* Copy password if supplied */
00466         if( NULL != pSecParams )
00467         {
00468             /* update security type */
00469             Msg.Cmd.Args.Common.SecType = (_i8)(pSecParams->Type);
00470 
00471             if( SL_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType )
00472             {
00473                 Msg.Cmd.Args.Common.WepKeyId = 0;
00474             }
00475 
00476             /* verify key length */
00477             if (pSecParams->KeyLen > MAX_KEY_LEN)
00478             {
00479                 return SL_INVALPARAM;
00480             }
00481             /* update key length */
00482             Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
00483             CmdCtrl.TxDescLen += pSecParams->KeyLen;
00484             /* copy key (could be no key in case of WPS pin) */
00485             if( NULL != pSecParams->Key )
00486             {
00487                 sl_Memcpy(PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
00488             }
00489         }
00490         else
00491         {
00492             Msg.Cmd.Args.Common.SecType = SL_SEC_TYPE_OPEN;
00493             Msg.Cmd.Args.Common.PasswordLen = 0;
00494         }
00495 
00496     }
00497 
00498 
00499     /* If BSSID is not null, copy to buffer, otherwise set to 0  */
00500     if(NULL != pMacAddr)
00501     {
00502         sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
00503     }
00504     else
00505     {
00506         _SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, (_u16)sizeof(Msg.Cmd.Args.Common.Bssid));
00507     }
00508 
00509     VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
00510 
00511     return (_i16)Msg.Rsp.status;
00512 }
00513 #endif
00514 /*******************************************************************************/
00515 /*   sl_ProfileGet */
00516 /*******************************************************************************/
00517 typedef union
00518 {
00519     _WlanProfileDelGetCommand_t Cmd;
00520     _SlProfileParams_t          Rsp;
00521 }_SlProfileGetMsg_u;
00522 
00523 
00524 #if _SL_INCLUDE_FUNC(sl_WlanProfileGet)
00525 
00526 static const _SlCmdCtrl_t _SlProfileGetCmdCtrl =
00527 {
00528     SL_OPCODE_WLAN_PROFILEGETCOMMAND,
00529     (_SlArgSize_t)sizeof(_WlanProfileDelGetCommand_t),
00530     (_SlArgSize_t)sizeof(_SlProfileParams_t)
00531 };
00532 
00533 _i16 sl_WlanProfileGet(const _i16 Index,_i8*  pName, _i16 *pNameLen, _u8 *pMacAddr, SlSecParams_t* pSecParams, SlGetSecParamsExt_t* pEntParams, _u32 *pPriority)
00534 {
00535     _SlProfileGetMsg_u      Msg;
00536     Msg.Cmd.index = (_u8)Index;
00537 
00538     /* verify no erorr handling in progress. if in progress than
00539     ignore the API execution and return immediately with an error */
00540     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00541 
00542     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileGetCmdCtrl, &Msg, NULL));
00543 
00544     pSecParams->Type = (_u8)(Msg.Rsp.Args.Common.SecType);
00545     /* since password is not transferred in getprofile, password length should always be zero */
00546     pSecParams->KeyLen = Msg.Rsp.Args.Common.PasswordLen;
00547     if (NULL != pEntParams)
00548     {
00549         pEntParams->UserLen = Msg.Rsp.Args.UserLen;
00550         /* copy user name */
00551         if (pEntParams->UserLen > 0)
00552         {    
00553             sl_Memcpy(pEntParams->User, EAP_PROFILE_USER_STRING(&Msg), pEntParams->UserLen);
00554         }
00555         pEntParams->AnonUserLen = Msg.Rsp.Args.AnonUserLen;
00556         /* copy anonymous user name */
00557         if (pEntParams->AnonUserLen > 0)
00558         {
00559             sl_Memcpy(pEntParams->AnonUser, EAP_PROFILE_ANON_USER_STRING(&Msg), pEntParams->AnonUserLen);
00560         }
00561     }
00562 
00563     *pNameLen  = (_i16)(Msg.Rsp.Args.Common.SsidLen);      
00564     *pPriority = Msg.Rsp.Args.Common.Priority;       
00565 
00566     if (NULL != Msg.Rsp.Args.Common.Bssid)
00567     {
00568         sl_Memcpy(pMacAddr, Msg.Rsp.Args.Common.Bssid, sizeof(Msg.Rsp.Args.Common.Bssid));
00569     }
00570 
00571     sl_Memcpy(pName, EAP_PROFILE_SSID_STRING(&Msg), *pNameLen);
00572 
00573     return (_i16)Msg.Rsp.Args.Common.SecType;
00574 
00575 }
00576 #endif
00577 /*******************************************************************************/
00578 /*   sl_ProfileDel  */
00579 /*******************************************************************************/
00580 typedef union
00581 {
00582     _WlanProfileDelGetCommand_t     Cmd;
00583     _BasicResponse_t                Rsp;
00584 }_SlProfileDelMsg_u;
00585 
00586 
00587 #if _SL_INCLUDE_FUNC(sl_WlanProfileDel)
00588 
00589 static const _SlCmdCtrl_t _SlProfileDelCmdCtrl =
00590 {
00591     SL_OPCODE_WLAN_PROFILEDELCOMMAND,
00592     (_SlArgSize_t)sizeof(_WlanProfileDelGetCommand_t),
00593     (_SlArgSize_t)sizeof(_BasicResponse_t)
00594 };
00595 
00596 _i16 sl_WlanProfileDel(const _i16 Index)
00597 {
00598     _SlProfileDelMsg_u Msg;
00599 
00600     /* verify no erorr handling in progress. if in progress than
00601     ignore the API execution and return immediately with an error */
00602     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00603 
00604     Msg.Cmd.index = (_u8)Index;
00605 
00606     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileDelCmdCtrl, &Msg, NULL));
00607 
00608     return (_i16)Msg.Rsp.status;
00609 }
00610 #endif
00611 
00612 
00613 /******************************************************************************/
00614 /*  sl_WlanGetNetworkList  */
00615 /******************************************************************************/
00616 typedef union
00617 {
00618     _WlanGetNetworkListCommand_t    Cmd;
00619     _WlanGetNetworkListResponse_t   Rsp;
00620 }_SlWlanGetNetworkListMsg_u;
00621 
00622 
00623 #if _SL_INCLUDE_FUNC(sl_WlanGetNetworkList)
00624 
00625 static const _SlCmdCtrl_t _SlWlanGetNetworkListCtrl =
00626 {
00627     SL_OPCODE_WLAN_SCANRESULTSGETCOMMAND,
00628     (_SlArgSize_t)sizeof(_WlanGetNetworkListCommand_t),
00629     (_SlArgSize_t)sizeof(_WlanGetNetworkListResponse_t)
00630 };
00631 
00632 _i16 sl_WlanGetNetworkList(const _u8 Index,const _u8 Count, Sl_WlanNetworkEntry_t *pEntries)
00633 {
00634     _i16 retVal = 0;
00635     _SlWlanGetNetworkListMsg_u Msg;
00636     _SlCmdExt_t    CmdExt;
00637 
00638     /* verify no erorr handling in progress. if in progress than
00639     ignore the API execution and return immediately with an error */
00640     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00641 
00642     if (Count == 0)
00643     {
00644         return SL_EZEROLEN;
00645     }
00646 
00647     _SlDrvResetCmdExt(&CmdExt);
00648     CmdExt.RxPayloadLen = (_i16)(sizeof(Sl_WlanNetworkEntry_t)*(Count));
00649     CmdExt.pRxPayload = (_u8 *)pEntries; 
00650 
00651     Msg.Cmd.index = Index;
00652     Msg.Cmd.count = Count;
00653 
00654     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanGetNetworkListCtrl, &Msg, &CmdExt));
00655     retVal = Msg.Rsp.status;
00656 
00657     return (_i16)retVal;
00658 }
00659 #endif
00660 
00661 
00662 
00663 
00664 
00665 /******************************************************************************/
00666 /*     RX filters message command response structures  */
00667 /******************************************************************************/
00668 
00669 /* Set command */
00670 typedef union
00671 {
00672     _WlanRxFilterAddCommand_t             Cmd;
00673     _WlanRxFilterAddCommandReponse_t      Rsp;
00674 }_SlrxFilterAddMsg_u;
00675 
00676 
00677 /* Set command */
00678 typedef union _SlRxFilterSetMsg_u
00679 {
00680     _WlanRxFilterSetCommand_t               Cmd;
00681     _WlanRxFilterSetCommandReponse_t        Rsp;
00682 }_SlRxFilterSetMsg_u;
00683 
00684 
00685 /* Get command */
00686 typedef union _SlRxFilterGetMsg_u
00687 {
00688     _WlanRxFilterGetCommand_t               Cmd;
00689     _WlanRxFilterGetCommandReponse_t        Rsp;
00690 }_SlRxFilterGetMsg_u;
00691 
00692 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterAdd)
00693 
00694 static const _SlCmdCtrl_t _SlRxFilterAddtCmdCtrl =
00695 {
00696     SL_OPCODE_WLAN_WLANRXFILTERADDCOMMAND,
00697     (_SlArgSize_t)sizeof(_WlanRxFilterAddCommand_t),
00698     (_SlArgSize_t)sizeof(_WlanRxFilterAddCommandReponse_t)
00699 };
00700 
00701 
00702 /*****************************************************************************
00703     RX filters
00704 *****************************************************************************/
00705 _i16 sl_WlanRxFilterAdd(    SlrxFilterRuleType_t                RuleType,
00706     SlrxFilterFlags_t                   FilterFlags,
00707     const SlrxFilterRule_t* const       Rule,
00708     const SlrxFilterTrigger_t* const    Trigger,
00709     const SlrxFilterAction_t* const     Action,
00710     SlrxFilterID_t*                     pFilterId)
00711 {
00712 
00713 
00714     _SlrxFilterAddMsg_u Msg;
00715 
00716     /* verify no erorr handling in progress. if in progress than
00717     ignore the API execution and return immediately with an error */
00718     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00719 
00720     Msg.Cmd.RuleType = RuleType;
00721     /* filterId is zero */
00722     Msg.Cmd.FilterId = 0;
00723     Msg.Cmd.FilterFlags = FilterFlags;
00724     sl_Memcpy( &(Msg.Cmd.Rule), Rule, sizeof(SlrxFilterRule_t) );
00725     sl_Memcpy( &(Msg.Cmd.Trigger), Trigger, sizeof(SlrxFilterTrigger_t) );
00726     sl_Memcpy( &(Msg.Cmd.Action), Action, sizeof(SlrxFilterAction_t) );
00727     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterAddtCmdCtrl, &Msg, NULL) );
00728     *pFilterId = Msg.Rsp.FilterId;
00729     return (_i16)Msg.Rsp.Status;
00730 
00731 }
00732 #endif
00733 
00734 
00735 
00736 /*******************************************************************************/
00737 /*     RX filters    */
00738 /*******************************************************************************/
00739 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterSet)
00740 
00741 static const _SlCmdCtrl_t _SlRxFilterSetCmdCtrl =
00742 {
00743     SL_OPCODE_WLAN_WLANRXFILTERSETCOMMAND,
00744     (_SlArgSize_t)sizeof(_WlanRxFilterSetCommand_t),
00745     (_SlArgSize_t)sizeof(_WlanRxFilterSetCommandReponse_t)
00746 };
00747 
00748 _i16 sl_WlanRxFilterSet(const SLrxFilterOperation_t RxFilterOperation,
00749     const _u8*  const pInputBuffer,
00750     _u16 InputbufferLength)
00751 {
00752     _SlRxFilterSetMsg_u   Msg;
00753     _SlCmdExt_t           CmdExt;
00754 
00755     /* verify no erorr handling in progress. if in progress than
00756     ignore the API execution and return immediately with an error */
00757     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00758 
00759     _SlDrvResetCmdExt(&CmdExt);
00760     CmdExt.TxPayloadLen = InputbufferLength;
00761     CmdExt.pTxPayload   = (_u8 *)pInputBuffer;
00762 
00763     Msg.Cmd.RxFilterOperation = RxFilterOperation;
00764     Msg.Cmd.InputBufferLength = InputbufferLength;
00765 
00766 
00767     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterSetCmdCtrl, &Msg, &CmdExt) );
00768 
00769 
00770     return (_i16)Msg.Rsp.Status;
00771 }
00772 #endif
00773 
00774 /******************************************************************************/
00775 /*     RX filters  */
00776 /******************************************************************************/
00777 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterGet)
00778 
00779 static const _SlCmdCtrl_t _SlRxFilterGetCmdCtrl =
00780 {
00781     SL_OPCODE_WLAN_WLANRXFILTERGETCOMMAND,
00782     (_SlArgSize_t)sizeof(_WlanRxFilterGetCommand_t),
00783     (_SlArgSize_t)sizeof(_WlanRxFilterGetCommandReponse_t)
00784 };
00785 
00786 
00787 _i16 sl_WlanRxFilterGet(const SLrxFilterOperation_t RxFilterOperation,
00788     _u8*  pOutputBuffer,
00789     _u16 OutputbufferLength)
00790 {
00791     _SlRxFilterGetMsg_u   Msg;
00792     _SlCmdExt_t           CmdExt;
00793 
00794     /* verify no erorr handling in progress. if in progress than
00795     ignore the API execution and return immediately with an error */
00796     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00797 
00798     if (OutputbufferLength == 0)
00799     {
00800         return SL_EZEROLEN;
00801     }
00802 
00803     _SlDrvResetCmdExt(&CmdExt);
00804     CmdExt.RxPayloadLen = (_i16)OutputbufferLength;
00805     CmdExt.pRxPayload   = (_u8 *)pOutputBuffer;
00806 
00807     Msg.Cmd.RxFilterOperation = RxFilterOperation;
00808     Msg.Cmd.OutputBufferLength = OutputbufferLength;
00809 
00810 
00811     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlRxFilterGetCmdCtrl, &Msg, &CmdExt) );
00812 
00813     if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) 
00814     {
00815         return SL_ESMALLBUF;
00816     }
00817 
00818     return (_i16)Msg.Rsp.Status;
00819 }
00820 #endif
00821 
00822 /*******************************************************************************/
00823 /*             sl_WlanRxStatStart                                              */
00824 /*******************************************************************************/
00825 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStart)
00826 _i16 sl_WlanRxStatStart(void)
00827 {
00828     /* verify no erorr handling in progress. if in progress than
00829     ignore the API execution and return immediately with an error */
00830     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00831 
00832     return _SlDrvBasicCmd(SL_OPCODE_WLAN_STARTRXSTATCOMMAND);
00833 }
00834 #endif
00835 
00836 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStop)
00837 _i16 sl_WlanRxStatStop(void)
00838 {
00839     /* verify no erorr handling in progress. if in progress than
00840     ignore the API execution and return immediately with an error */
00841     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00842 
00843     return _SlDrvBasicCmd(SL_OPCODE_WLAN_STOPRXSTATCOMMAND);
00844 }
00845 #endif
00846 
00847 #if _SL_INCLUDE_FUNC(sl_WlanRxStatGet)
00848 _i16 sl_WlanRxStatGet(SlGetRxStatResponse_t *pRxStat,const _u32 Flags)
00849 {
00850     _SlCmdCtrl_t            CmdCtrl = {SL_OPCODE_WLAN_GETRXSTATCOMMAND, 0, (_SlArgSize_t)sizeof(SlGetRxStatResponse_t)};
00851 
00852    /* Flags paramater is currently not in use */
00853    (void)Flags;
00854     
00855     /* verify no erorr handling in progress. if in progress than
00856       ignore the API execution and return immediately with an error */
00857     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00858     
00859     _SlDrvMemZero(pRxStat, (_u16)sizeof(SlGetRxStatResponse_t));
00860     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, pRxStat, NULL)); 
00861 
00862     return 0;
00863 }
00864 #endif
00865 
00866 
00867 
00868 /******************************************************************************/
00869 /*   sl_WlanSmartConfigStop                                                   */
00870 /******************************************************************************/
00871 #if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStop)
00872 _i16 sl_WlanSmartConfigStop(void)
00873 {
00874     /* verify no erorr handling in progress. if in progress than
00875     ignore the API execution and return immediately with an error */
00876     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00877 
00878     return _SlDrvBasicCmd(SL_OPCODE_WLAN_SMART_CONFIG_STOP_COMMAND);
00879 }
00880 #endif
00881 
00882 
00883 /******************************************************************************/
00884 /*   sl_WlanSmartConfigStart                                                  */
00885 /******************************************************************************/
00886 
00887 
00888 typedef struct
00889 {
00890     _WlanSmartConfigStartCommand_t  Args;
00891     _i8                            Strings[3 * MAX_SMART_CONFIG_KEY]; /* public key + groupId1 key + groupId2 key */
00892 }_SlSmartConfigStart_t;
00893 
00894 typedef union
00895 {
00896     _SlSmartConfigStart_t       Cmd;
00897     _BasicResponse_t            Rsp;
00898 }_SlSmartConfigStartMsg_u;
00899 
00900 #if _SL_INCLUDE_FUNC(sl_WlanSmartConfigStart)
00901 
00902 static const _SlCmdCtrl_t _SlSmartConfigStartCmdCtrl =
00903 {
00904     SL_OPCODE_WLAN_SMART_CONFIG_START_COMMAND,
00905     (_SlArgSize_t)sizeof(_SlSmartConfigStart_t),
00906     (_SlArgSize_t)sizeof(_BasicResponse_t)
00907 };
00908 
00909 _i16 sl_WlanSmartConfigStart( const _u32    groupIdBitmask,
00910     const _u8    cipher,
00911     const _u8    publicKeyLen,
00912     const _u8    group1KeyLen,
00913     const _u8    group2KeyLen,
00914     const _u8*    pPublicKey,
00915     const _u8*    pGroup1Key,
00916     const _u8*    pGroup2Key)
00917 {
00918     _SlSmartConfigStartMsg_u      Msg;
00919 
00920     /* verify no erorr handling in progress. if in progress than
00921     ignore the API execution and return immediately with an error */
00922     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00923 
00924     Msg.Cmd.Args.groupIdBitmask = (_u8)groupIdBitmask;
00925     Msg.Cmd.Args.cipher         = (_u8)cipher;
00926     Msg.Cmd.Args.publicKeyLen   = (_u8)publicKeyLen;
00927     Msg.Cmd.Args.group1KeyLen   = (_u8)group1KeyLen;
00928     Msg.Cmd.Args.group2KeyLen   = (_u8)group2KeyLen;
00929 
00930     /* copy keys (if exist) after command (one after another) */
00931     sl_Memcpy(SMART_CONFIG_START_PUBLIC_KEY_STRING(&Msg), pPublicKey, publicKeyLen);
00932     sl_Memcpy(SMART_CONFIG_START_GROUP1_KEY_STRING(&Msg), pGroup1Key, group1KeyLen);
00933     sl_Memcpy(SMART_CONFIG_START_GROUP2_KEY_STRING(&Msg), pGroup2Key, group2KeyLen);
00934 
00935     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSmartConfigStartCmdCtrl , &Msg, NULL));
00936 
00937     return (_i16)Msg.Rsp.status;
00938 
00939 
00940 }
00941 #endif
00942 
00943 
00944 /*******************************************************************************/
00945 /*   sl_WlanSetMode  */
00946 /*******************************************************************************/
00947 typedef union
00948 {
00949     _WlanSetMode_t          Cmd;
00950     _BasicResponse_t        Rsp;
00951 }_SlwlanSetModeMsg_u;
00952 
00953 #if _SL_INCLUDE_FUNC(sl_WlanSetMode)
00954 
00955 static const _SlCmdCtrl_t _SlWlanSetModeCmdCtrl =
00956 {
00957     SL_OPCODE_WLAN_SET_MODE,
00958     (_SlArgSize_t)sizeof(_WlanSetMode_t),
00959     (_SlArgSize_t)sizeof(_BasicResponse_t)
00960 };
00961 
00962 /* possible values are: 
00963 WLAN_SET_STA_MODE   =   1
00964 WLAN_SET_AP_MODE    =   2
00965 WLAN_SET_P2P_MODE   =   3  */
00966 _i16 sl_WlanSetMode(const _u8    mode)
00967 {
00968     _SlwlanSetModeMsg_u      Msg;
00969 
00970     /* verify no erorr handling in progress. if in progress than
00971     ignore the API execution and return immediately with an error */
00972     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
00973 
00974     Msg.Cmd.mode  = mode;
00975 
00976     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanSetModeCmdCtrl , &Msg, NULL));
00977 
00978     return (_i16)Msg.Rsp.status;
00979 }
00980 #endif
00981 
00982 
00983 
00984 
00985 /*******************************************************************************/
00986 /*   sl_WlanSet  */
00987 /* ******************************************************************************/
00988 typedef union
00989 {
00990     _WlanCfgSetGet_t        Cmd;
00991     _BasicResponse_t        Rsp;
00992 }_SlWlanCfgSetMsg_u;
00993 
00994 
00995 #if _SL_INCLUDE_FUNC(sl_WlanSet)
00996 
00997 static const _SlCmdCtrl_t _SlWlanCfgSetCmdCtrl =
00998 {
00999     SL_OPCODE_WLAN_CFG_SET,
01000     (_SlArgSize_t)sizeof(_WlanCfgSetGet_t),
01001     (_SlArgSize_t)sizeof(_BasicResponse_t)
01002 };
01003 
01004 _i16 sl_WlanSet(const _u16 ConfigId ,const _u16 ConfigOpt,const _u16 ConfigLen,const  _u8 *pValues)
01005 {
01006     _SlWlanCfgSetMsg_u         Msg;
01007     _SlCmdExt_t                CmdExt;
01008 
01009     /* verify no erorr handling in progress. if in progress than
01010     ignore the API execution and return immediately with an error */
01011     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
01012 
01013     _SlDrvResetCmdExt(&CmdExt);
01014     CmdExt.TxPayloadLen = (_u16)((ConfigLen+3) & (~3));
01015     CmdExt.pTxPayload = (_u8 *)pValues;
01016 
01017     Msg.Cmd.ConfigId    = ConfigId;
01018     Msg.Cmd.ConfigLen   = ConfigLen;
01019     Msg.Cmd.ConfigOpt   = ConfigOpt;
01020 
01021     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgSetCmdCtrl, &Msg, &CmdExt));
01022 
01023     return (_i16)Msg.Rsp.status;
01024 }
01025 #endif
01026 
01027 
01028 /******************************************************************************/
01029 /*  sl_WlanGet  */
01030 /******************************************************************************/
01031 typedef union
01032 {
01033     _WlanCfgSetGet_t        Cmd;
01034     _WlanCfgSetGet_t        Rsp;
01035 }_SlWlanCfgMsgGet_u;
01036 
01037 #if _SL_INCLUDE_FUNC(sl_WlanGet)
01038 
01039 static const _SlCmdCtrl_t _SlWlanCfgGetCmdCtrl =
01040 {
01041     SL_OPCODE_WLAN_CFG_GET,
01042     (_SlArgSize_t)sizeof(_WlanCfgSetGet_t),
01043     (_SlArgSize_t)sizeof(_WlanCfgSetGet_t)
01044 };
01045 
01046 _i16 sl_WlanGet(const _u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues)
01047 {
01048     _SlWlanCfgMsgGet_u        Msg;
01049     _SlCmdExt_t               CmdExt;
01050 
01051     /* verify no erorr handling in progress. if in progress than
01052     ignore the API execution and return immediately with an error */
01053     VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
01054 
01055     if (*pConfigLen == 0)
01056     {
01057         return SL_EZEROLEN;
01058     }
01059 
01060     _SlDrvResetCmdExt(&CmdExt);
01061     CmdExt.RxPayloadLen = (_i16)*pConfigLen;
01062     CmdExt.pRxPayload = (_u8 *)pValues;
01063 
01064     Msg.Cmd.ConfigId    = ConfigId;
01065     Msg.Cmd.ConfigLen  = *pConfigLen;
01066     
01067     if( pConfigOpt )
01068     {
01069         Msg.Cmd.ConfigOpt   = (_u16)*pConfigOpt;
01070     }
01071     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgGetCmdCtrl, &Msg, &CmdExt));
01072 
01073     if( pConfigOpt )
01074     {
01075         *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt;
01076     }
01077     if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) 
01078     {
01079         *pConfigLen = (_u8)CmdExt.RxPayloadLen;
01080         return SL_ESMALLBUF;
01081     }
01082     else
01083     {
01084         *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
01085     }
01086 
01087 
01088     return (_i16)Msg.Rsp.Status;
01089 }
01090 #endif