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