SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.22
Simplifies the implementation of Internet connectivity
wlan.c
1 /*
2  * wlan.c - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
5  *
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 
38 
39 /*****************************************************************************/
40 /* Include files */
41 /*****************************************************************************/
42 #include <ti/drivers/net/wifi/simplelink.h>
43 #include <ti/drivers/net/wifi/source/protocol.h>
44 #include <ti/drivers/net/wifi/source/driver.h>
45 
46 /*****************************************************************************/
47 /* Macro declarations */
48 /*****************************************************************************/
49 #define MAX_SSID_LEN (32)
50 #define MAX_KEY_LEN (64)
51 #define MAX_USER_LEN (64)
52 #define MAX_ANON_USER_LEN (64)
53 #define MAX_SMART_CONFIG_KEY (16)
54 
55 
56 /*****************************************************************************
57 sl_WlanConnect
58 *****************************************************************************/
59 typedef struct
60 {
62  _i8 Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
63 }_WlanConnectCmd_t;
64 
65 typedef union
66 {
67  _WlanConnectCmd_t Cmd;
68  _BasicResponse_t Rsp;
69 }_SlWlanConnectMsg_u;
70 
71 
72 #if _SL_INCLUDE_FUNC(sl_WlanConnect)
73 _i16 sl_WlanConnect(const _i8* pName,const _i16 NameLen,const _u8 *pMacAddr,const SlWlanSecParams_t* pSecParams ,const SlWlanSecParamsExt_t* pSecExtParams)
74 {
75  _SlWlanConnectMsg_u Msg;
76  _SlCmdCtrl_t CmdCtrl = {0,0,0};
77 
78  _SlDrvMemZero(&Msg, (_u16)sizeof(_SlWlanConnectMsg_u));
79 
80  /* verify that this api is allowed. if not allowed then
81  ignore the API execution and return immediately with an error */
82  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
83  CmdCtrl.TxDescLen = 0;/* init */
84  CmdCtrl.RxDescLen = (_SlArgSize_t)sizeof(_BasicResponse_t);
85 
86  /* verify SSID length */
87  VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
88  /* verify SSID is not NULL */
89  if( NULL == pName )
90  {
91  return SL_INVALPARAM;
92  }
93  /* update SSID length */
94  Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen;
95 
96  /* Profile with no security */
97  /* Enterprise security profile */
98  if (NULL != pSecExtParams)
99  {
100  /* Update command opcode */
101  CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTEAPCOMMAND;
102  CmdCtrl.TxDescLen += sizeof(SlWlanConnectEapCommand_t);
103  /* copy SSID */
104  sl_Memcpy(EAP_SSID_STRING(&Msg), pName, NameLen);
105  CmdCtrl.TxDescLen += NameLen;
106  /* Copy password if supplied */
107  if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
108  {
109  /* update security type */
110  Msg.Cmd.Args.Common.SecType = pSecParams->Type;
111  /* verify key length */
112  if (pSecParams->KeyLen > MAX_KEY_LEN)
113  {
114  return SL_INVALPARAM;
115  }
116  /* update key length */
117  Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
118  ARG_CHECK_PTR(pSecParams->Key);
119  /* copy key */
120  sl_Memcpy(EAP_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
121  CmdCtrl.TxDescLen += pSecParams->KeyLen;
122  }
123  else
124  {
125  Msg.Cmd.Args.Common.PasswordLen = 0;
126  }
127 
128  ARG_CHECK_PTR(pSecExtParams);
129  /* Update Eap bitmask */
130  Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
131  /* Update Certificate file ID index - currently not supported */
132  Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
133  /* verify user length */
134  if (pSecExtParams->UserLen > MAX_USER_LEN)
135  {
136  return SL_INVALPARAM;
137  }
138  Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
139  /* copy user name (identity) */
140  if(pSecExtParams->UserLen > 0)
141  {
142  sl_Memcpy(EAP_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
143  CmdCtrl.TxDescLen += pSecExtParams->UserLen;
144  }
145  /* verify Anonymous user length */
146  if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
147  {
148  return SL_INVALPARAM;
149  }
150  Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
151  /* copy Anonymous user */
152  if(pSecExtParams->AnonUserLen > 0)
153  {
154  sl_Memcpy(EAP_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
155  CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
156  }
157 
158  }
159 
160  /* Regular or open security profile */
161  else
162  {
163  /* Update command opcode */
164  CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTCOMMAND;
165  CmdCtrl.TxDescLen += sizeof(SlWlanConnectCommon_t);
166  /* copy SSID */
167  sl_Memcpy(SSID_STRING(&Msg), pName, NameLen);
168  CmdCtrl.TxDescLen += NameLen;
169  /* Copy password if supplied */
170  if( NULL != pSecParams )
171  {
172  /* update security type */
173  Msg.Cmd.Args.Common.SecType = pSecParams->Type;
174  /* verify key length is valid */
175  if (pSecParams->KeyLen > MAX_KEY_LEN)
176  {
177  return SL_INVALPARAM;
178  }
179  /* update key length */
180  Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
181  CmdCtrl.TxDescLen += pSecParams->KeyLen;
182  /* copy key (could be no key in case of WPS pin) */
183  if( NULL != pSecParams->Key )
184  {
185  sl_Memcpy(PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
186  }
187  }
188  /* Profile with no security */
189  else
190  {
191  Msg.Cmd.Args.Common.PasswordLen = 0;
192  Msg.Cmd.Args.Common.SecType = SL_WLAN_SEC_TYPE_OPEN;
193  }
194  }
195  /* If BSSID is not null, copy to buffer, otherwise set to 0 */
196  if(NULL != pMacAddr)
197  {
198  sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
199  }
200  else
201  {
202  _SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, (_u16)sizeof(Msg.Cmd.Args.Common.Bssid));
203  }
204 
205 
206  VERIFY_RET_OK ( _SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
207 
208  return (_i16)Msg.Rsp.status;
209 }
210 #endif
211 
212 /*******************************************************************************/
213 /* sl_Disconnect */
214 /* ******************************************************************************/
215 #if _SL_INCLUDE_FUNC(sl_WlanDisconnect)
217 {
218  /* verify that this api is allowed. if not allowed then
219  ignore the API execution and return immediately with an error */
220  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
221 
222  return _SlDrvBasicCmd(SL_OPCODE_WLAN_WLANDISCONNECTCOMMAND);
223 }
224 #endif
225 
226 /******************************************************************************/
227 /* sl_PolicySet */
228 /******************************************************************************/
229 typedef union
230 {
232  _BasicResponse_t Rsp;
233 }_SlPolicyMsg_u;
234 
235 #if _SL_INCLUDE_FUNC(sl_WlanPolicySet)
236 
237 static const _SlCmdCtrl_t _SlPolicySetCmdCtrl =
238 {
239  SL_OPCODE_WLAN_POLICYSETCOMMAND,
240  (_SlArgSize_t)sizeof(SlWlanPolicySetGet_t),
241  (_SlArgSize_t)sizeof(_BasicResponse_t)
242 };
243 
244 _i16 sl_WlanPolicySet(const _u8 Type , const _u8 Policy, _u8 *pVal,const _u8 ValLen)
245 {
246  _SlPolicyMsg_u Msg;
247  _SlCmdExt_t CmdExt;
248 
249  /* verify that this api is allowed. if not allowed then
250  ignore the API execution and return immediately with an error */
251  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
252 
253  _SlDrvResetCmdExt(&CmdExt);
254  CmdExt.TxPayload1Len = ValLen;
255  CmdExt.pTxPayload1 = (_u8 *)pVal;
256 
257 
258  Msg.Cmd.PolicyType = Type;
259  Msg.Cmd.PolicyOption = Policy;
260  Msg.Cmd.PolicyOptionLen = ValLen;
261 
262  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicySetCmdCtrl, &Msg, &CmdExt));
263 
264  return (_i16)Msg.Rsp.status;
265 }
266 #endif
267 
268 
269 /******************************************************************************/
270 /* sl_PolicyGet */
271 /******************************************************************************/
272 typedef union
273 {
276 }_SlPolicyGetMsg_u;
277 
278 #if _SL_INCLUDE_FUNC(sl_WlanPolicyGet)
279 
280 static const _SlCmdCtrl_t _SlPolicyGetCmdCtrl =
281 {
282  SL_OPCODE_WLAN_POLICYGETCOMMAND,
283  (_SlArgSize_t)sizeof(SlWlanPolicySetGet_t),
284  (_SlArgSize_t)sizeof(SlWlanPolicySetGet_t)
285 };
286 
287 
288 _i16 sl_WlanPolicyGet(const _u8 Type ,_u8 *pPolicy,_u8 *pVal,_u8 *pValLen)
289 {
290  _SlPolicyGetMsg_u Msg;
291  _SlCmdExt_t CmdExt;
292 
293  /* verify that this api is allowed. if not allowed then
294  ignore the API execution and return immediately with an error */
295  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
296 
297  if (*pValLen == 0)
298  {
299  return SL_EZEROLEN;
300  }
301 
302  _SlDrvResetCmdExt(&CmdExt);
303  CmdExt.RxPayloadLen = (_i16)(*pValLen);
304  CmdExt.pRxPayload = pVal;
305 
306  Msg.Cmd.PolicyType = Type;
307 
308  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicyGetCmdCtrl, &Msg, &CmdExt));
309 
310 
311  if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
312  {
313  *pValLen = Msg.Rsp.PolicyOptionLen;
314  return SL_ESMALLBUF;
315  }
316  else
317  {
318  /* no pointer valus, fill the results into _i8 */
319  *pValLen = (_u8)CmdExt.ActualRxPayloadLen;
320  *pPolicy = Msg.Rsp.PolicyOption;
321 
322  if( 0 == CmdExt.ActualRxPayloadLen )
323  {
324  *pValLen = 1;
325  }
326 
327  }
328  return (_i16)SL_OS_RET_CODE_OK;
329 }
330 #endif
331 
332 
333 /*******************************************************************************/
334 /* sl_ProfileAdd */
335 /*******************************************************************************/
336 typedef struct
337 {
339  _i8 Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
340 }_SlProfileParams_t;
341 
342 typedef union
343 {
344  _SlProfileParams_t Cmd;
345  _BasicResponse_t Rsp;
346 }_SlProfileAddMsg_u;
347 
348 
349 
350 #if _SL_INCLUDE_FUNC(sl_WlanProfileAdd)
351 _i16 sl_WlanProfileAdd(const _i8* pName,const _i16 NameLen,const _u8 *pMacAddr,const SlWlanSecParams_t* pSecParams ,const SlWlanSecParamsExt_t* pSecExtParams,const _u32 Priority,const _u32 Options)
352 {
353  _SlProfileAddMsg_u Msg;
354  _SlCmdCtrl_t CmdCtrl = {0,0,0};
355  CmdCtrl.TxDescLen = 0;/* init */
356  CmdCtrl.RxDescLen = (_SlArgSize_t)(sizeof(_BasicResponse_t));
357 
358 
359  /* Options paramater is currently not in use */
360  (void)Options;
361 
362  /* verify that this api is allowed. if not allowed then
363  ignore the API execution and return immediately with an error */
364  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
365 
366  _SlDrvMemZero(&Msg,sizeof(_SlProfileAddMsg_u));
367 
368  /* update priority */
369  Msg.Cmd.Args.Common.Priority = (_u8)Priority;
370  /* verify SSID is not NULL */
371  if( NULL == pName )
372  {
373  return SL_INVALPARAM;
374  }
375  /* verify SSID length */
376  VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
377  /* update SSID length */
378  Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen;
379 
380 
381  /* Enterprise security profile */
382  if (NULL != pSecExtParams)
383  {
384  /* Update command opcode */
385  CmdCtrl.Opcode = SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND;
386  CmdCtrl.TxDescLen += sizeof(SlWlanAddGetEapProfile_t);
387 
388  /* copy SSID */
389  sl_Memcpy(EAP_PROFILE_SSID_STRING(&Msg), pName, NameLen);
390  CmdCtrl.TxDescLen += NameLen;
391 
392  /* Copy password if supplied */
393  if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
394  {
395  /* update security type */
396  Msg.Cmd.Args.Common.SecType = (_i8)(pSecParams->Type);
397 
398  if( SL_WLAN_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType )
399  {
400  Msg.Cmd.Args.Common.WepKeyId = 0;
401  }
402 
403  /* verify key length */
404  if (pSecParams->KeyLen > MAX_KEY_LEN)
405  {
406  return SL_INVALPARAM;
407  }
408  VERIFY_PROTOCOL(pSecParams->KeyLen <= MAX_KEY_LEN);
409  /* update key length */
410  Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
411  CmdCtrl.TxDescLen += pSecParams->KeyLen;
412  ARG_CHECK_PTR(pSecParams->Key);
413  /* copy key */
414  sl_Memcpy(EAP_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
415  }
416  else
417  {
418  Msg.Cmd.Args.Common.PasswordLen = 0;
419  }
420 
421  ARG_CHECK_PTR(pSecExtParams);
422  /* Update Eap bitmask */
423  Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
424  /* Update Certificate file ID index - currently not supported */
425  Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
426  /* verify user length */
427  if (pSecExtParams->UserLen > MAX_USER_LEN)
428  {
429  return SL_INVALPARAM;
430  }
431  Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
432  /* copy user name (identity) */
433  if(pSecExtParams->UserLen > 0)
434  {
435  sl_Memcpy(EAP_PROFILE_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
436  CmdCtrl.TxDescLen += pSecExtParams->UserLen;
437  }
438 
439  /* verify Anonymous user length (for tunneled) */
440  if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
441  {
442  return SL_INVALPARAM;
443  }
444  Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
445 
446  /* copy Anonymous user */
447  if(pSecExtParams->AnonUserLen > 0)
448  {
449  sl_Memcpy(EAP_PROFILE_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
450  CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
451  }
452 
453  }
454  /* Regular or open security profile */
455  else
456  {
457  /* Update command opcode */
458  CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEADDCOMMAND;
459  /* update commnad length */
460  CmdCtrl.TxDescLen += sizeof(SlWlanAddGetProfile_t);
461 
462  if (NULL != pName)
463  {
464  /* copy SSID */
465  sl_Memcpy(PROFILE_SSID_STRING(&Msg), pName, NameLen);
466  CmdCtrl.TxDescLen += NameLen;
467  }
468 
469  /* Copy password if supplied */
470  if( NULL != pSecParams )
471  {
472  /* update security type */
473  Msg.Cmd.Args.Common.SecType = (_i8)(pSecParams->Type);
474 
475  if( SL_WLAN_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType )
476  {
477  Msg.Cmd.Args.Common.WepKeyId = 0;
478  }
479 
480  /* verify key length */
481  if (pSecParams->KeyLen > MAX_KEY_LEN)
482  {
483  return SL_INVALPARAM;
484  }
485  /* update key length */
486  Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
487  CmdCtrl.TxDescLen += pSecParams->KeyLen;
488  /* copy key (could be no key in case of WPS pin) */
489  if( NULL != pSecParams->Key )
490  {
491  sl_Memcpy(PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
492  }
493  }
494  else
495  {
496  Msg.Cmd.Args.Common.SecType = SL_WLAN_SEC_TYPE_OPEN;
497  Msg.Cmd.Args.Common.PasswordLen = 0;
498  }
499 
500  }
501 
502 
503  /* If BSSID is not null, copy to buffer, otherwise set to 0 */
504  if(NULL != pMacAddr)
505  {
506  sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
507  }
508  else
509  {
510  _SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, (_u16)sizeof(Msg.Cmd.Args.Common.Bssid));
511  }
512 
513  VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
514 
515  return (_i16)Msg.Rsp.status;
516 }
517 #endif
518 /*******************************************************************************/
519 /* sl_ProfileGet */
520 /*******************************************************************************/
521 typedef union
522 {
524  _SlProfileParams_t Rsp;
525 }_SlProfileGetMsg_u;
526 
527 
528 #if _SL_INCLUDE_FUNC(sl_WlanProfileGet)
529 
530 static const _SlCmdCtrl_t _SlProfileGetCmdCtrl =
531 {
532  SL_OPCODE_WLAN_PROFILEGETCOMMAND,
533  (_SlArgSize_t)sizeof(SlWlanProfileDelGetCommand_t),
534  (_SlArgSize_t)sizeof(_SlProfileParams_t)
535 };
536 
537 _i16 sl_WlanProfileGet(const _i16 Index,_i8* pName, _i16 *pNameLen, _u8 *pMacAddr, SlWlanSecParams_t* pSecParams, SlWlanGetSecParamsExt_t* pEntParams, _u32 *pPriority)
538 {
539  _SlProfileGetMsg_u Msg;
540  Msg.Cmd.Index = (_u8)Index;
541 
542  /* verify that this api is allowed. if not allowed then
543  ignore the API execution and return immediately with an error */
544  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
545 
546  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileGetCmdCtrl, &Msg, NULL));
547 
548  pSecParams->Type = (_u8)(Msg.Rsp.Args.Common.SecType);
549  if (Msg.Rsp.Args.Common.SecType >= 0)
550  {
551  /* since password is not transferred in getprofile, password length should always be zero */
552  pSecParams->KeyLen = Msg.Rsp.Args.Common.PasswordLen;
553  if (NULL != pEntParams)
554  {
555  pEntParams->EapMethod = Msg.Rsp.Args.EapBitmask;
556  pEntParams->UserLen = Msg.Rsp.Args.UserLen;
557  /* copy user name */
558  if (pEntParams->UserLen > 0)
559  {
560  sl_Memcpy(pEntParams->User, EAP_PROFILE_USER_STRING(&Msg), pEntParams->UserLen);
561  }
562  pEntParams->AnonUserLen = Msg.Rsp.Args.AnonUserLen;
563  /* copy anonymous user name */
564  if (pEntParams->AnonUserLen > 0)
565  {
566  sl_Memcpy(pEntParams->AnonUser, EAP_PROFILE_ANON_USER_STRING(&Msg), pEntParams->AnonUserLen);
567  }
568  }
569 
570  *pNameLen = (_i16)(Msg.Rsp.Args.Common.SsidLen);
571  *pPriority = Msg.Rsp.Args.Common.Priority;
572 
573  if (NULL != Msg.Rsp.Args.Common.Bssid)
574  {
575  sl_Memcpy(pMacAddr, Msg.Rsp.Args.Common.Bssid, sizeof(Msg.Rsp.Args.Common.Bssid));
576  }
577 
578  sl_Memset(pName, 0, SL_WLAN_SSID_MAX_LENGTH);
579  sl_Memcpy(pName, EAP_PROFILE_SSID_STRING(&Msg), *pNameLen);
580  }
581  return (_i16)Msg.Rsp.Args.Common.SecType;
582 
583 }
584 #endif
585 /*******************************************************************************/
586 /* sl_ProfileDel */
587 /*******************************************************************************/
588 typedef union
589 {
591  _BasicResponse_t Rsp;
592 }_SlProfileDelMsg_u;
593 
594 
595 #if _SL_INCLUDE_FUNC(sl_WlanProfileDel)
596 
597 static const _SlCmdCtrl_t _SlProfileDelCmdCtrl =
598 {
599  SL_OPCODE_WLAN_PROFILEDELCOMMAND,
600  (_SlArgSize_t)sizeof(SlWlanProfileDelGetCommand_t),
601  (_SlArgSize_t)sizeof(_BasicResponse_t)
602 };
603 
604 _i16 sl_WlanProfileDel(const _i16 Index)
605 {
606  _SlProfileDelMsg_u Msg;
607 
608  /* verify that this api is allowed. if not allowed then
609  ignore the API execution and return immediately with an error */
610  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
611 
612  Msg.Cmd.Index = (_u8)Index;
613 
614  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileDelCmdCtrl, &Msg, NULL));
615 
616  return (_i16)Msg.Rsp.status;
617 }
618 #endif
619 
620 
621 /******************************************************************************/
622 /* sl_WlanGetNetworkList */
623 /******************************************************************************/
624 typedef union
625 {
628 }_SlWlanGetNetworkListMsg_u;
629 
630 
631 #if _SL_INCLUDE_FUNC(sl_WlanGetNetworkList)
632 
633 static const _SlCmdCtrl_t _SlWlanGetNetworkListCtrl =
634 {
635  SL_OPCODE_WLAN_SCANRESULTSGETCOMMAND,
636  (_SlArgSize_t)sizeof(SlWlanGetNetworkListCommand_t),
637  (_SlArgSize_t)sizeof(_WlanGetNetworkListResponse_t)
638 };
639 
640 _i16 sl_WlanGetNetworkList(const _u8 Index,const _u8 Count, SlWlanNetworkEntry_t *pEntries)
641 {
642  _i16 retVal = 0;
643  _SlWlanGetNetworkListMsg_u Msg;
644  _SlCmdExt_t CmdExt;
645 
646  /* verify that this api is allowed. if not allowed then
647  ignore the API execution and return immediately with an error */
648  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
649 
650  if (Count == 0)
651  {
652  return SL_EZEROLEN;
653  }
654 
655  _SlDrvResetCmdExt(&CmdExt);
656  CmdExt.RxPayloadLen = (_i16)(sizeof(SlWlanNetworkEntry_t)*(Count));
657  CmdExt.pRxPayload = (_u8 *)pEntries;
658 
659  Msg.Cmd.Index = Index;
660  Msg.Cmd.Count = Count;
661 
662  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanGetNetworkListCtrl, &Msg, &CmdExt));
663  retVal = Msg.Rsp.status;
664 
665  return (_i16)retVal;
666 }
667 #endif
668 
669 
670 
671 
672 
673 /******************************************************************************/
674 /* RX filters message command response structures */
675 /******************************************************************************/
676 
677 /* Set command */
678 typedef union
679 {
682 }_SlWlanRxFilterAddMsg_u;
683 
684 
685 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterAdd)
686 
687 static const _SlCmdCtrl_t _SlWlanRxFilterAddtCmdCtrl =
688 {
689  SL_OPCODE_WLAN_WLANRXFILTERADDCOMMAND,
690  (_SlArgSize_t)sizeof(SlWlanRxFilterAddCommand_t),
691  (_SlArgSize_t)sizeof(SlWlanRxFilterAddCommandReponse_t)
692 };
693 
694 
695 /*****************************************************************************
696  RX filters
697 *****************************************************************************/
698 _i16 sl_WlanRxFilterAdd( SlWlanRxFilterRuleType_t RuleType,
699  SlWlanRxFilterFlags_u Flags,
700  const SlWlanRxFilterRule_u* const pRule,
701  const SlWlanRxFilterTrigger_t* const pTrigger,
702  const SlWlanRxFilterAction_t* const pAction,
703  SlWlanRxFilterID_t* pFilterId)
704 {
705 
706 
707  _SlWlanRxFilterAddMsg_u Msg;
708 
709  /* verify that this api is allowed. if not allowed then
710  ignore the API execution and return immediately with an error */
711  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
712 
713  Msg.Cmd.RuleType = RuleType;
714  /* filterId is zero */
715  Msg.Cmd.FilterId = 0;
716  Msg.Cmd.Flags = Flags;
717  sl_Memcpy( &(Msg.Cmd.Rule), pRule, sizeof(SlWlanRxFilterRule_u) );
718  sl_Memcpy( &(Msg.Cmd.Trigger), pTrigger, sizeof(SlWlanRxFilterTrigger_t) );
719  sl_Memcpy( &(Msg.Cmd.Action), pAction, sizeof(SlWlanRxFilterAction_t) );
720  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanRxFilterAddtCmdCtrl, &Msg, NULL) );
721  *pFilterId = Msg.Rsp.FilterId;
722  return (_i16)Msg.Rsp.Status;
723 
724 }
725 #endif
726 
727 
728 
729 /*******************************************************************************/
730 /* sl_WlanRxStatStart */
731 /*******************************************************************************/
732 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStart)
734 {
735  /* verify that this api is allowed. if not allowed then
736  ignore the API execution and return immediately with an error */
737  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
738 
739  return _SlDrvBasicCmd(SL_OPCODE_WLAN_STARTRXSTATCOMMAND);
740 }
741 #endif
742 
743 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStop)
745 {
746  /* verify that this api is allowed. if not allowed then
747  ignore the API execution and return immediately with an error */
748  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
749 
750  return _SlDrvBasicCmd(SL_OPCODE_WLAN_STOPRXSTATCOMMAND);
751 }
752 #endif
753 
754 #if _SL_INCLUDE_FUNC(sl_WlanRxStatGet)
755 _i16 sl_WlanRxStatGet(SlWlanGetRxStatResponse_t *pRxStat,const _u32 Flags)
756 {
757  _SlCmdCtrl_t CmdCtrl = {SL_OPCODE_WLAN_GETRXSTATCOMMAND, 0, (_SlArgSize_t)sizeof(SlWlanGetRxStatResponse_t)};
758  /* Flags paramater is currently not in use */
759  (void)Flags;
760 
761  /* verify that this api is allowed. if not allowed then
762  ignore the API execution and return immediately with an error */
763  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
764 
765  _SlDrvMemZero(pRxStat, (_u16)sizeof(SlWlanGetRxStatResponse_t));
766  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, pRxStat, NULL));
767 
768  return 0;
769 }
770 #endif
771 
772 /******************************************************************************/
773 /* sl_WlanProvisioning */
774 /******************************************************************************/
775 
776 
777 typedef struct
778 {
780  _i8 Key[MAX_SMART_CONFIG_KEY]; /* public key + groupId1 key + groupId2 key */
781 }_SlSmartConfigArgs_t;
782 
783 
784 typedef struct
785 {
786  SlWlanProvisioningParams_t ProvParams;
787  _SlSmartConfigArgs_t SmartConfigParams;
788 
789 }_SlProvisioning_t;
790 
791 typedef union
792 {
793  _SlProvisioning_t Cmd;
794  _BasicResponse_t Rsp;
795 }_SlProvisioningStartMsg_u;
796 
797 #if _SL_INCLUDE_FUNC(sl_WlanProvisioning)
798 
799 const _SlCmdCtrl_t _SlProvisioningCmdCtrl =
800 {
801  SL_OPCODE_WLAN_PROVISIONING_COMMAND,
802  sizeof(_SlProvisioning_t),
803  sizeof(_BasicResponse_t)
804 };
805 
806 _i16 sl_WlanProvisioning(_u8 ProvisioningCmd, _u8 RequestedRoleAfterSuccess, _u16 InactivityTimeoutSec, char *pSmartConfigKey, _u32 Flags)
807 {
808  _SlProvisioningStartMsg_u Msg;
809 
810 
811  /* Verify if we can send this command to the NWP
812  We can send only prov. stop command if command is not allowed */
813  if ((!SL_IS_COMMAND_ALLOWED) && (!SL_IS_PROVISIONING_ACTIVE) && (InactivityTimeoutSec != 0))
814  {
815  /* return with the correct error code */
816  return _SlDrvDriverIsApiAllowed(SL_OPCODE_SILO_WLAN);
817  }
818 
819  /* If there is an API in progress and the timeout is not zero (it means the
820  command is not prov. stop) then abort and return an error code */
821  if (_SlDrvIsApiInProgress() && (InactivityTimeoutSec !=0))
822  {
823  return SL_RET_CODE_API_COMMAND_IN_PROGRESS;
824  }
825 
826 
827  _SlDrvMemZero(&Msg, (_u16)sizeof (_SlProvisioningStartMsg_u));
828 
829  Msg.Cmd.ProvParams.ProvisioningCmd = (_u8)ProvisioningCmd;
830  Msg.Cmd.ProvParams.RequestedRoleAfterSuccess = (_u8)RequestedRoleAfterSuccess;
831  Msg.Cmd.ProvParams.InactivityTimeoutSec = (_u16)InactivityTimeoutSec;
832  Msg.Cmd.ProvParams.Flags = Flags;
833 
834  /* Smart Config parameters */
835  if (NULL != pSmartConfigKey)
836  {
837  Msg.Cmd.SmartConfigParams.Args.GroupIdBitmask = SL_WLAN_SMART_CONFIG_DEFAULT_GROUP;
838  Msg.Cmd.SmartConfigParams.Args.Cipher = SL_WLAN_SMART_CONFIG_DEFAULT_CIPHER;
839  Msg.Cmd.SmartConfigParams.Args.PublicKeyLen = SL_WLAN_SMART_CONFIG_KEY_LENGTH;
840 
841  /* copy keys (if exist) after command (one after another) */
842  sl_Memcpy(SMART_CONFIG_START_PUBLIC_KEY_STRING(&Msg.Cmd.SmartConfigParams.Args), pSmartConfigKey, SL_WLAN_SMART_CONFIG_KEY_LENGTH);
843  }
844  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProvisioningCmdCtrl , &Msg, NULL));
845 
846  return (_i16)Msg.Rsp.status;
847 }
848 #endif
849 
850 
851 /*******************************************************************************/
852 /* sl_WlanSetMode */
853 /*******************************************************************************/
854 typedef union
855 {
856  SlWlanSetMode_t Cmd;
857  _BasicResponse_t Rsp;
858 }_SlwlanSetModeMsg_u;
859 
860 #if _SL_INCLUDE_FUNC(sl_WlanSetMode)
861 
862 static const _SlCmdCtrl_t _SlWlanSetModeCmdCtrl =
863 {
864  SL_OPCODE_WLAN_SET_MODE,
865  (_SlArgSize_t)sizeof(SlWlanSetMode_t),
866  (_SlArgSize_t)sizeof(_BasicResponse_t)
867 };
868 
869 /* possible values are:
870 WLAN_SET_STA_MODE = 1
871 WLAN_SET_AP_MODE = 2
872 WLAN_SET_P2P_MODE = 3 */
873 _i16 sl_WlanSetMode(const _u8 Mode)
874 {
875  _SlwlanSetModeMsg_u Msg;
876 
877  /* verify that this api is allowed. if not allowed then
878  ignore the API execution and return immediately with an error */
879  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
880 
881  Msg.Cmd.Mode = Mode;
882 
883  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanSetModeCmdCtrl , &Msg, NULL));
884 
885  return (_i16)Msg.Rsp.status;
886 }
887 #endif
888 
889 
890 
891 
892 /*******************************************************************************/
893 /* sl_WlanSet */
894 /* ******************************************************************************/
895 typedef union
896 {
897  SlWlanCfgSetGet_t Cmd;
898  _BasicResponse_t Rsp;
899 }_SlWlanCfgSetMsg_u;
900 
901 
902 #if _SL_INCLUDE_FUNC(sl_WlanSet)
903 
904 static const _SlCmdCtrl_t _SlWlanCfgSetCmdCtrl =
905 {
906  SL_OPCODE_WLAN_CFG_SET,
907  (_SlArgSize_t)sizeof(SlWlanCfgSetGet_t),
908  (_SlArgSize_t)sizeof(_BasicResponse_t)
909 };
910 
911 _i16 sl_WlanSet(const _u16 ConfigId ,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 *pValues)
912 {
913  _SlWlanCfgSetMsg_u Msg;
914  _SlCmdExt_t CmdExt;
915 
916  /* verify that this api is allowed. if not allowed then
917  ignore the API execution and return immediately with an error */
918  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
919 
920  _SlDrvResetCmdExt(&CmdExt);
921  CmdExt.TxPayload1Len = (_u16)((ConfigLen+3) & (~3));
922  CmdExt.pTxPayload1 = (_u8 *)pValues;
923 
924  Msg.Cmd.ConfigId = ConfigId;
925  Msg.Cmd.ConfigLen = ConfigLen;
926  Msg.Cmd.ConfigOpt = ConfigOpt;
927 
928  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgSetCmdCtrl, &Msg, &CmdExt));
929 
930  return (_i16)Msg.Rsp.status;
931 }
932 #endif
933 
934 
935 /******************************************************************************/
936 /* sl_WlanGet */
937 /******************************************************************************/
938 typedef union
939 {
940  SlWlanCfgSetGet_t Cmd;
941  SlWlanCfgSetGet_t Rsp;
942 }_SlWlanCfgMsgGet_u;
943 
944 #if _SL_INCLUDE_FUNC(sl_WlanGet)
945 
946 static const _SlCmdCtrl_t _SlWlanCfgGetCmdCtrl =
947 {
948  SL_OPCODE_WLAN_CFG_GET,
949  (_SlArgSize_t)sizeof(SlWlanCfgSetGet_t),
950  (_SlArgSize_t)sizeof(SlWlanCfgSetGet_t)
951 };
952 
953 _i16 sl_WlanGet(const _u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues)
954 {
955  _SlWlanCfgMsgGet_u Msg;
956  _SlCmdExt_t CmdExt;
957 
958  /* verify that this api is allowed. if not allowed then
959  ignore the API execution and return immediately with an error */
960  VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
961 
962  if (*pConfigLen == 0)
963  {
964  return SL_EZEROLEN;
965  }
966 
967  _SlDrvResetCmdExt(&CmdExt);
968  CmdExt.RxPayloadLen = (_i16)*pConfigLen;
969  CmdExt.pRxPayload = (_u8 *)pValues;
970  Msg.Cmd.ConfigLen = *pConfigLen;
971  Msg.Cmd.ConfigId = ConfigId;
972  if( pConfigOpt )
973  {
974  Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt;
975  }
976  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgGetCmdCtrl, &Msg, &CmdExt));
977 
978  if( pConfigOpt )
979  {
980  *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt;
981  }
982  if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
983  {
984  *pConfigLen = (_u8)CmdExt.RxPayloadLen;
985  return SL_ESMALLBUF;
986  }
987  else
988  {
989  *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
990  }
991 
992 
993  return (_i16)Msg.Rsp.Status;
994 }
995 #endif
_i16 sl_WlanSetMode(const _u8 Mode)
Wlan set mode.
Definition: wlan.c:873
_i16 sl_WlanRxFilterAdd(SlWlanRxFilterRuleType_t RuleType, SlWlanRxFilterFlags_u Flags, const SlWlanRxFilterRule_u *const pRule, const SlWlanRxFilterTrigger_t *const pTrigger, const SlWlanRxFilterAction_t *const pAction, SlWlanRxFilterID_t *pFilterId)
Adds new filter rule to the system.
Definition: wlan.c:698
_i16 sl_WlanConnect(const _i8 *pName, const _i16 NameLen, const _u8 *pMacAddr, const SlWlanSecParams_t *pSecParams, const SlWlanSecParamsExt_t *pSecExtParams)
Connect to wlan network as a station.
Definition: wlan.c:73
_i16 sl_WlanGet(const _u16 ConfigId, _u16 *pConfigOpt, _u16 *pConfigLen, _u8 *pValues)
Getting WLAN configurations.
Definition: wlan.c:953
_i16 sl_WlanProvisioning(_u8 ProvisioningCmd, _u8 RequestedRoleAfterSuccess, _u16 InactivityTimeoutSec, char *pSmartConfigKey, _u32 Flags)
The simpleLink will switch to the appropriate role according to the provisioning mode requested and w...
Definition: wlan.c:806
Definition: wlan.h:653
_i16 sl_WlanPolicySet(const _u8 Type, const _u8 Policy, _u8 *pVal, const _u8 ValLen)
Set policy values.
Definition: wlan.c:244
_i16 sl_WlanProfileAdd(const _i8 *pName, const _i16 NameLen, const _u8 *pMacAddr, const SlWlanSecParams_t *pSecParams, const SlWlanSecParamsExt_t *pSecExtParams, const _u32 Priority, const _u32 Options)
Add profile.
Definition: wlan.c:351
_i16 sl_WlanRxStatStop(void)
Stop collecting wlan RX statistic, (if previous called sl_WlanRxStatStart)
Definition: wlan.c:744
_i16 sl_WlanProfileGet(const _i16 Index, _i8 *pName, _i16 *pNameLen, _u8 *pMacAddr, SlWlanSecParams_t *pSecParams, SlWlanGetSecParamsExt_t *pEntParams, _u32 *pPriority)
Get profile.
Definition: wlan.c:537
_i16 sl_WlanSet(const _u16 ConfigId, const _u16 ConfigOpt, const _u16 ConfigLen, const _u8 *pValues)
Setting WLAN configurations.
Definition: wlan.c:911
_i16 sl_WlanProfileDel(const _i16 Index)
Delete WLAN profile.
Definition: wlan.c:604
_i16 sl_WlanDisconnect(void)
Wlan disconnect.
Definition: wlan.c:216
_i16 sl_WlanPolicyGet(const _u8 Type, _u8 *pPolicy, _u8 *pVal, _u8 *pValLen)
Get policy values.
Definition: wlan.c:288
_i16 sl_WlanRxStatStart(void)
Start collecting wlan RX statistics, for unlimited time.
Definition: wlan.c:733
_i16 sl_WlanRxStatGet(SlWlanGetRxStatResponse_t *pRxStat, const _u32 Flags)
Get wlan RX statistics. Upon calling this command, the statistics counters will be cleared...
Definition: wlan.c:755
_i16 sl_WlanGetNetworkList(const _u8 Index, const _u8 Count, SlWlanNetworkEntry_t *pEntries)
Gets the WLAN scan operation results.
Definition: wlan.c:640