1 /*
2 * wlan.c - CC31xx/CC32xx Host Driver Implementation
3 *
4 * Copyright (C) 2017 Texas Instruments Incorporated - http://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 /* Include files */
40 /*****************************************************************************/
41 #include <ti/drivers/net/wifi/simplelink.h>
42 #include <ti/drivers/net/wifi/source/protocol.h>
43 #include <ti/drivers/net/wifi/source/driver.h>
44
45 /*****************************************************************************/
46 /* Macro declarations */
47 /*****************************************************************************/
48 #define MAX_SSID_LEN (32)
49 #define MAX_KEY_LEN (64)
50 #define MAX_USER_LEN (64)
51 #define MAX_ANON_USER_LEN (64)
52 #define MAX_SMART_CONFIG_KEY (16)
53
54
55 /*****************************************************************************
56 sl_WlanConnect
57 *****************************************************************************/
58 typedef struct
59 {
60 SlWlanConnectEapCommand_t Args;
61 _i8 Strings[SL_WLAN_SSID_MAX_LENGTH + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
62 }_WlanConnectCmd_t;
63
64 typedef union
65 {
66 _WlanConnectCmd_t Cmd;
67 _BasicResponse_t Rsp;
68 }_SlWlanConnectMsg_u;
69
70
71 #if _SL_INCLUDE_FUNC(sl_WlanConnect)
sl_WlanConnect(const _i8 * pName,const _i16 NameLen,const _u8 * pMacAddr,const SlWlanSecParams_t * pSecParams,const SlWlanSecParamsExt_t * pSecExtParams)72 _i16 sl_WlanConnect(const _i8* pName,const _i16 NameLen,const _u8 *pMacAddr,const SlWlanSecParams_t* pSecParams ,const SlWlanSecParamsExt_t* pSecExtParams)
73 {
74 _SlWlanConnectMsg_u Msg;
75 _SlCmdCtrl_t CmdCtrl = {0,0,0};
76
77 _SlDrvMemZero(&Msg, (_u16)sizeof(_SlWlanConnectMsg_u));
78
79 /* verify that this api is allowed. if not allowed then
80 ignore the API execution and return immediately with an error */
81 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
82 CmdCtrl.TxDescLen = 0;/* init */
83 CmdCtrl.RxDescLen = (_SlArgSize_t)sizeof(_BasicResponse_t);
84
85 /* verify SSID length */
86 VERIFY_PROTOCOL(NameLen <= SL_WLAN_SSID_MAX_LENGTH);
87 /* verify SSID is not NULL */
88 if( NULL == pName )
89 {
90 return SL_INVALPARAM;
91 }
92 /* update SSID length */
93 Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen;
94
95 /* Profile with no security */
96 /* Enterprise security profile */
97 if (NULL != pSecExtParams)
98 {
99 /* Update command opcode */
100 CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTEAPCOMMAND;
101 CmdCtrl.TxDescLen += sizeof(SlWlanConnectEapCommand_t);
102 /* copy SSID */
103 sl_Memcpy(EAP_SSID_STRING(&Msg), pName, NameLen);
104 CmdCtrl.TxDescLen += NameLen;
105 /* Copy password if supplied */
106 if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
107 {
108 /* update security type */
109 Msg.Cmd.Args.Common.SecType = pSecParams->Type;
110 /* verify key length */
111 if (pSecParams->KeyLen > MAX_KEY_LEN)
112 {
113 return SL_INVALPARAM;
114 }
115 /* update key length */
116 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
117 ARG_CHECK_PTR(pSecParams->Key);
118 /* copy key */
119 sl_Memcpy(EAP_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
120 CmdCtrl.TxDescLen += pSecParams->KeyLen;
121 }
122 else
123 {
124 Msg.Cmd.Args.Common.PasswordLen = 0;
125 }
126
127 ARG_CHECK_PTR(pSecExtParams);
128 /* Update Eap bitmask */
129 Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
130 /* Update Certificate file ID index - currently not supported */
131 Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
132 /* verify user length */
133 if (pSecExtParams->UserLen > MAX_USER_LEN)
134 {
135 return SL_INVALPARAM;
136 }
137 Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
138 /* copy user name (identity) */
139 if(pSecExtParams->UserLen > 0)
140 {
141 sl_Memcpy(EAP_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
142 CmdCtrl.TxDescLen += pSecExtParams->UserLen;
143 }
144 /* verify Anonymous user length */
145 if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
146 {
147 return SL_INVALPARAM;
148 }
149 Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
150 /* copy Anonymous user */
151 if(pSecExtParams->AnonUserLen > 0)
152 {
153 sl_Memcpy(EAP_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
154 CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
155 }
156
157 }
158
159 /* Regular or open security profile */
160 else
161 {
162 /* Update command opcode */
163 CmdCtrl.Opcode = SL_OPCODE_WLAN_WLANCONNECTCOMMAND;
164 CmdCtrl.TxDescLen += sizeof(SlWlanConnectCommon_t);
165 /* copy SSID */
166 sl_Memcpy(SSID_STRING(&Msg), pName, NameLen);
167 CmdCtrl.TxDescLen += NameLen;
168 /* Copy password if supplied */
169 if( NULL != pSecParams )
170 {
171 /* update security type */
172 Msg.Cmd.Args.Common.SecType = pSecParams->Type;
173 /* verify key length is valid */
174 if (pSecParams->KeyLen > MAX_KEY_LEN)
175 {
176 return SL_INVALPARAM;
177 }
178 /* update key length */
179 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
180 CmdCtrl.TxDescLen += pSecParams->KeyLen;
181 /* copy key (could be no key in case of WPS pin) */
182 if( NULL != pSecParams->Key )
183 {
184 sl_Memcpy(PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
185 }
186 }
187 /* Profile with no security */
188 else
189 {
190 Msg.Cmd.Args.Common.PasswordLen = 0;
191 Msg.Cmd.Args.Common.SecType = SL_WLAN_SEC_TYPE_OPEN;
192 }
193 }
194 /* If BSSID is not null, copy to buffer, otherwise set to 0 */
195 if(NULL != pMacAddr)
196 {
197 sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
198 }
199 else
200 {
201 _SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, (_u16)sizeof(Msg.Cmd.Args.Common.Bssid));
202 }
203
204 VERIFY_RET_OK ( _SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
205
206 return (_i16)Msg.Rsp.status;
207 }
208 #endif
209
210 /*******************************************************************************/
211 /* sl_Disconnect */
212 /* ******************************************************************************/
213 #if _SL_INCLUDE_FUNC(sl_WlanDisconnect)
sl_WlanDisconnect(void)214 _i16 sl_WlanDisconnect(void)
215 {
216 /* verify that this api is allowed. if not allowed then
217 ignore the API execution and return immediately with an error */
218 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
219
220 return _SlDrvBasicCmd(SL_OPCODE_WLAN_WLANDISCONNECTCOMMAND);
221 }
222 #endif
223
224 /******************************************************************************/
225 /* sl_PolicySet */
226 /******************************************************************************/
227 typedef union
228 {
229 SlWlanPolicySetGet_t Cmd;
230 _BasicResponse_t Rsp;
231 }_SlPolicyMsg_u;
232
233 #if _SL_INCLUDE_FUNC(sl_WlanPolicySet)
234
235 static const _SlCmdCtrl_t _SlPolicySetCmdCtrl =
236 {
237 SL_OPCODE_WLAN_POLICYSETCOMMAND,
238 (_SlArgSize_t)sizeof(SlWlanPolicySetGet_t),
239 (_SlArgSize_t)sizeof(_BasicResponse_t)
240 };
241
sl_WlanPolicySet(const _u8 Type,const _u8 Policy,_u8 * pVal,const _u8 ValLen)242 _i16 sl_WlanPolicySet(const _u8 Type , const _u8 Policy, _u8 *pVal,const _u8 ValLen)
243 {
244 _SlPolicyMsg_u Msg;
245 _SlCmdExt_t CmdExt;
246
247 /* verify that this api is allowed. if not allowed then
248 ignore the API execution and return immediately with an error */
249 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
250
251 _SlDrvResetCmdExt(&CmdExt);
252 CmdExt.TxPayload1Len = ValLen;
253 CmdExt.pTxPayload1 = (_u8 *)pVal;
254
255 Msg.Cmd.PolicyType = Type;
256 Msg.Cmd.PolicyOption = Policy;
257 Msg.Cmd.PolicyOptionLen = ValLen;
258
259 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicySetCmdCtrl, &Msg, &CmdExt));
260
261 return (_i16)Msg.Rsp.status;
262 }
263 #endif
264
265
266 /******************************************************************************/
267 /* sl_PolicyGet */
268 /******************************************************************************/
269 typedef union
270 {
271 SlWlanPolicySetGet_t Cmd;
272 SlWlanPolicySetGet_t Rsp;
273 }_SlPolicyGetMsg_u;
274
275 #if _SL_INCLUDE_FUNC(sl_WlanPolicyGet)
276
277 static const _SlCmdCtrl_t _SlPolicyGetCmdCtrl =
278 {
279 SL_OPCODE_WLAN_POLICYGETCOMMAND,
280 (_SlArgSize_t)sizeof(SlWlanPolicySetGet_t),
281 (_SlArgSize_t)sizeof(SlWlanPolicySetGet_t)
282 };
283
sl_WlanPolicyGet(const _u8 Type,_u8 * pPolicy,_u8 * pVal,_u8 * pValLen)284 _i16 sl_WlanPolicyGet(const _u8 Type ,_u8 *pPolicy,_u8 *pVal,_u8 *pValLen)
285 {
286 _SlPolicyGetMsg_u Msg;
287 _SlCmdExt_t CmdExt;
288
289 /* verify that this api is allowed. if not allowed then
290 ignore the API execution and return immediately with an error */
291 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
292
293 if (*pValLen == 0)
294 {
295 return SL_EZEROLEN;
296 }
297
298 _SlDrvResetCmdExt(&CmdExt);
299 CmdExt.RxPayloadLen = (_i16)(*pValLen);
300 CmdExt.pRxPayload = pVal;
301
302 Msg.Cmd.PolicyType = Type;
303
304 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlPolicyGetCmdCtrl, &Msg, &CmdExt));
305
306
307 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
308 {
309 *pValLen = Msg.Rsp.PolicyOptionLen;
310 return SL_ESMALLBUF;
311 }
312 else
313 {
314 /* no pointer valus, fill the results into _i8 */
315 *pValLen = (_u8)CmdExt.ActualRxPayloadLen;
316 *pPolicy = Msg.Rsp.PolicyOption;
317
318 if( 0 == CmdExt.ActualRxPayloadLen )
319 {
320 *pValLen = 1;
321 }
322
323 }
324 return (_i16)SL_OS_RET_CODE_OK;
325 }
326 #endif
327
328
329 /*******************************************************************************/
330 /* sl_ProfileAdd */
331 /*******************************************************************************/
332 typedef struct
333 {
334 SlWlanAddGetEapProfile_t Args;
335 _i8 Strings[SL_WLAN_SSID_MAX_LENGTH + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
336 }_SlProfileParams_t;
337
338 typedef union
339 {
340 _SlProfileParams_t Cmd;
341 _BasicResponse_t Rsp;
342 }_SlProfileAddMsg_u;
343
344
345 #if _SL_INCLUDE_FUNC(sl_WlanProfileAdd)
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)346 _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)
347 {
348 _SlProfileAddMsg_u Msg;
349 _SlCmdCtrl_t CmdCtrl = {0,0,0};
350 CmdCtrl.TxDescLen = 0;/* init */
351 CmdCtrl.RxDescLen = (_SlArgSize_t)(sizeof(_BasicResponse_t));
352
353
354 /* Options parameter is currently not in use */
355 (void)Options;
356
357 /* verify that this api is allowed. if not allowed then
358 ignore the API execution and return immediately with an error */
359 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
360
361 _SlDrvMemZero(&Msg,sizeof(_SlProfileAddMsg_u));
362
363 /* update priority */
364 Msg.Cmd.Args.Common.Priority = (_u8)Priority;
365 /* verify SSID is not NULL */
366 if( NULL == pName )
367 {
368 return SL_INVALPARAM;
369 }
370 /* verify SSID length */
371 VERIFY_PROTOCOL(NameLen <= SL_WLAN_SSID_MAX_LENGTH);
372 /* update SSID length */
373 Msg.Cmd.Args.Common.SsidLen = (_u8)NameLen;
374
375 /* Enterprise security profile */
376 if (NULL != pSecExtParams)
377 {
378 /* Update command opcode */
379 CmdCtrl.Opcode = SL_OPCODE_WLAN_EAP_PROFILEADDCOMMAND;
380 CmdCtrl.TxDescLen += sizeof(SlWlanAddGetEapProfile_t);
381
382 /* copy SSID */
383 sl_Memcpy(EAP_PROFILE_SSID_STRING(&Msg), pName, NameLen);
384 CmdCtrl.TxDescLen += NameLen;
385
386 /* Copy password if supplied */
387 if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
388 {
389 /* update security type */
390 Msg.Cmd.Args.Common.SecType = (_i8)(pSecParams->Type);
391
392 if( SL_WLAN_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType )
393 {
394 Msg.Cmd.Args.Common.WepKeyId = 0;
395 }
396
397 /* verify key length */
398 if (pSecParams->KeyLen > MAX_KEY_LEN)
399 {
400 return SL_INVALPARAM;
401 }
402 VERIFY_PROTOCOL(pSecParams->KeyLen <= MAX_KEY_LEN);
403 /* update key length */
404 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
405 CmdCtrl.TxDescLen += pSecParams->KeyLen;
406 ARG_CHECK_PTR(pSecParams->Key);
407 /* copy key */
408 sl_Memcpy(EAP_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
409 }
410 else
411 {
412 Msg.Cmd.Args.Common.PasswordLen = 0;
413 }
414
415 ARG_CHECK_PTR(pSecExtParams);
416 /* Update Eap bitmask */
417 Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
418 /* Update Certificate file ID index - currently not supported */
419 Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
420 /* verify user length */
421 if (pSecExtParams->UserLen > MAX_USER_LEN)
422 {
423 return SL_INVALPARAM;
424 }
425 Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
426 /* copy user name (identity) */
427 if(pSecExtParams->UserLen > 0)
428 {
429 sl_Memcpy(EAP_PROFILE_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
430 CmdCtrl.TxDescLen += pSecExtParams->UserLen;
431 }
432
433 /* verify Anonymous user length (for tunneled) */
434 if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
435 {
436 return SL_INVALPARAM;
437 }
438 Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
439
440 /* copy Anonymous user */
441 if(pSecExtParams->AnonUserLen > 0)
442 {
443 sl_Memcpy(EAP_PROFILE_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
444 CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
445 }
446
447 }
448 /* Regular or open security profile */
449 else
450 {
451 /* Update command opcode */
452 CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEADDCOMMAND;
453 /* update commnad length */
454 CmdCtrl.TxDescLen += sizeof(SlWlanAddGetProfile_t);
455
456 if (NULL != pName)
457 {
458 /* copy SSID */
459 sl_Memcpy(PROFILE_SSID_STRING(&Msg), pName, NameLen);
460 CmdCtrl.TxDescLen += NameLen;
461 }
462
463 /* Copy password if supplied */
464 if( NULL != pSecParams )
465 {
466 /* update security type */
467 Msg.Cmd.Args.Common.SecType = (_i8)(pSecParams->Type);
468
469 if( SL_WLAN_SEC_TYPE_WEP == Msg.Cmd.Args.Common.SecType )
470 {
471 Msg.Cmd.Args.Common.WepKeyId = 0;
472 }
473
474 /* verify key length */
475 if (pSecParams->KeyLen > MAX_KEY_LEN)
476 {
477 return SL_INVALPARAM;
478 }
479 /* update key length */
480 Msg.Cmd.Args.Common.PasswordLen = pSecParams->KeyLen;
481 CmdCtrl.TxDescLen += pSecParams->KeyLen;
482 /* copy key (could be no key in case of WPS pin) */
483 if( NULL != pSecParams->Key )
484 {
485 sl_Memcpy(PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
486 }
487 }
488 else
489 {
490 Msg.Cmd.Args.Common.SecType = SL_WLAN_SEC_TYPE_OPEN;
491 Msg.Cmd.Args.Common.PasswordLen = 0;
492 }
493 }
494
495 /* If BSSID is not null, copy to buffer, otherwise set to 0 */
496 if(NULL != pMacAddr)
497 {
498 sl_Memcpy(Msg.Cmd.Args.Common.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Common.Bssid));
499 }
500 else
501 {
502 _SlDrvMemZero(Msg.Cmd.Args.Common.Bssid, (_u16)sizeof(Msg.Cmd.Args.Common.Bssid));
503 }
504
505 VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
506
507 return (_i16)Msg.Rsp.status;
508 }
509 #endif
510
511
512 /*******************************************************************************/
513 /* sl_ProfileUpdate */
514 /*******************************************************************************/
515
516 typedef struct
517 {
518 SlWlanUpdateProfile_t Args;
519 _i8 Strings[MAX_SSID_LEN + MAX_KEY_LEN + MAX_USER_LEN + MAX_ANON_USER_LEN];
520 }_SlProfileUpdateParams_t;
521
522 typedef union
523 {
524 _SlProfileUpdateParams_t Cmd;
525 _BasicResponse_t Rsp;
526 }_SlProfileUpdateMsg_u;
527
528 #if _SL_INCLUDE_FUNC(sl_WlanProfileUpdate)
sl_WlanProfileUpdate(const _u32 Index,const _i8 * pName,const _i16 NameLen,const _u8 * pMacAddr,const SlWlanSecParams_t * pSecParams,const SlWlanSecParamsExt_t * pSecExtParams,const _u32 Priority)529 _i16 sl_WlanProfileUpdate(const _u32 Index, const _i8* pName,const _i16 NameLen,const _u8 *pMacAddr,const SlWlanSecParams_t* pSecParams ,const SlWlanSecParamsExt_t* pSecExtParams,const _u32 Priority)
530 {
531 _SlProfileUpdateMsg_u Msg;
532 _SlCmdCtrl_t CmdCtrl = {0,0,0};
533 CmdCtrl.TxDescLen = 0;/* init */
534 CmdCtrl.RxDescLen = (_SlArgSize_t)(sizeof(_BasicResponse_t));
535
536
537 /* verify that this api is allowed. if not allowed then
538 ignore the API execution and return immediately with an error */
539 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
540
541 _SlDrvMemZero(&Msg,sizeof(_SlProfileUpdateParams_t));
542
543 Msg.Cmd.Args.Index = Index;
544 /* update priority */
545 Msg.Cmd.Args.Priority = (_u8)Priority;
546
547 /* verify SSID length */
548 VERIFY_PROTOCOL(NameLen <= MAX_SSID_LEN);
549 /* update SSID length */
550 Msg.Cmd.Args.SsidLen = (_u8)NameLen;
551
552
553 /* Enterprise security profile */
554 if (NULL != pSecExtParams)
555 {
556 /* Update command opcode */
557 CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEEAPUPDATECOMMAND;
558 CmdCtrl.TxDescLen += sizeof(SlWlanUpdateProfile_t);
559
560 /* If SSID is supplied, copy it */
561 if (NULL != pName)
562 {
563 sl_Memcpy(UPDATE_PROFILE_SSID_STRING(&Msg), pName, NameLen);
564 CmdCtrl.TxDescLen += NameLen;
565 }
566 else
567 {
568 Msg.Cmd.Args.SsidLen = 0;
569 }
570
571
572 /* Copy password if supplied */
573 if ((NULL != pSecParams) && (pSecParams->KeyLen > 0))
574 {
575 /* update security type */
576 Msg.Cmd.Args.SecType = (_i8)(pSecParams->Type);
577
578 if( SL_WLAN_SEC_TYPE_WEP == Msg.Cmd.Args.SecType )
579 {
580 Msg.Cmd.Args.WepKeyId = 0;
581 }
582
583 /* verify key length */
584 if (pSecParams->KeyLen > MAX_KEY_LEN)
585 {
586 return SL_INVALPARAM;
587 }
588 VERIFY_PROTOCOL(pSecParams->KeyLen <= MAX_KEY_LEN);
589 /* update key length */
590 Msg.Cmd.Args.PasswordLen = pSecParams->KeyLen;
591 CmdCtrl.TxDescLen += pSecParams->KeyLen;
592 ARG_CHECK_PTR(pSecParams->Key);
593 /* copy key */
594 sl_Memcpy(UPDATE_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
595 }
596 else
597 {
598 Msg.Cmd.Args.PasswordLen = 0;
599 }
600
601 ARG_CHECK_PTR(pSecExtParams);
602 /* Update Eap bitmask */
603 Msg.Cmd.Args.EapBitmask = pSecExtParams->EapMethod;
604 /* Update Certificate file ID index - currently not supported */
605 Msg.Cmd.Args.CertIndex = pSecExtParams->CertIndex;
606 /* verify user length */
607 if (pSecExtParams->UserLen > MAX_USER_LEN)
608 {
609 return SL_INVALPARAM;
610 }
611 Msg.Cmd.Args.UserLen = pSecExtParams->UserLen;
612 /* copy user name (identity) */
613 if(pSecExtParams->UserLen > 0)
614 {
615 sl_Memcpy(UPDATE_PROFILE_USER_STRING(&Msg), pSecExtParams->User, pSecExtParams->UserLen);
616 CmdCtrl.TxDescLen += pSecExtParams->UserLen;
617 }
618
619 /* verify Anonymous user length (for tunneled) */
620 if (pSecExtParams->AnonUserLen > MAX_ANON_USER_LEN)
621 {
622 return SL_INVALPARAM;
623 }
624 Msg.Cmd.Args.AnonUserLen = pSecExtParams->AnonUserLen;
625
626 /* copy Anonymous user */
627 if(pSecExtParams->AnonUserLen > 0)
628 {
629 sl_Memcpy(UPDATE_PROFILE_ANON_USER_STRING(&Msg), pSecExtParams->AnonUser, pSecExtParams->AnonUserLen);
630 CmdCtrl.TxDescLen += pSecExtParams->AnonUserLen;
631 }
632
633 }
634 /* Regular or open security profile */
635 else
636 {
637 /* Update command opcode */
638 CmdCtrl.Opcode = SL_OPCODE_WLAN_PROFILEUPDATECOMMAND;
639 /* update commnad length */
640 CmdCtrl.TxDescLen += sizeof(SlWlanUpdateProfile_t);
641
642 if (NULL != pName)
643 {
644 /* copy SSID */
645 sl_Memcpy(UPDATE_PROFILE_SSID_STRING(&Msg), pName, NameLen);
646 CmdCtrl.TxDescLen += NameLen;
647 }
648 else
649 {
650 Msg.Cmd.Args.SsidLen = 0;
651 }
652
653 /* Copy password if supplied */
654 if( NULL != pSecParams )
655 {
656 /* update security type */
657 Msg.Cmd.Args.SecType = (_i8)(pSecParams->Type);
658
659 if( SL_WLAN_SEC_TYPE_WEP == Msg.Cmd.Args.SecType )
660 {
661 Msg.Cmd.Args.WepKeyId = 0;
662 }
663
664 /* verify key length */
665 if (pSecParams->KeyLen > MAX_KEY_LEN)
666 {
667 return SL_INVALPARAM;
668 }
669 /* update key length */
670 Msg.Cmd.Args.PasswordLen = pSecParams->KeyLen;
671 CmdCtrl.TxDescLen += pSecParams->KeyLen;
672 /* copy key (could be no key in case of WPS pin) */
673 if( NULL != pSecParams->Key )
674 {
675 sl_Memcpy(UPDATE_PROFILE_PASSWORD_STRING(&Msg), pSecParams->Key, pSecParams->KeyLen);
676 }
677 }
678 else
679 {
680 Msg.Cmd.Args.SecType = SL_WLAN_SEC_TYPE_OPEN;
681 Msg.Cmd.Args.PasswordLen = 0;
682 }
683
684 }
685
686
687 /* If BSSID is not null, copy to buffer, otherwise set to 0 */
688 if(NULL != pMacAddr)
689 {
690 sl_Memcpy(Msg.Cmd.Args.Bssid, pMacAddr, sizeof(Msg.Cmd.Args.Bssid));
691 }
692 else
693 {
694 _SlDrvMemZero(Msg.Cmd.Args.Bssid, (_u16)sizeof(Msg.Cmd.Args.Bssid));
695 }
696
697 VERIFY_RET_OK(_SlDrvCmdOp(&CmdCtrl, &Msg, NULL));
698
699 return (_i16)Msg.Rsp.status;
700 }
701 #endif
702 /*******************************************************************************/
703 /* sl_ProfileGet */
704 /*******************************************************************************/
705 typedef union
706 {
707 SlWlanProfileDelGetCommand_t Cmd;
708 _SlProfileParams_t Rsp;
709 }_SlProfileGetMsg_u;
710
711 #if _SL_INCLUDE_FUNC(sl_WlanProfileGet)
712
713 static const _SlCmdCtrl_t _SlProfileGetCmdCtrl =
714 {
715 SL_OPCODE_WLAN_PROFILEGETCOMMAND,
716 (_SlArgSize_t)sizeof(SlWlanProfileDelGetCommand_t),
717 (_SlArgSize_t)sizeof(_SlProfileParams_t)
718 };
719
sl_WlanProfileGet(const _i16 Index,_i8 * pName,_i16 * pNameLen,_u8 * pMacAddr,SlWlanSecParams_t * pSecParams,SlWlanGetSecParamsExt_t * pEntParams,_u32 * pPriority)720 _i16 sl_WlanProfileGet(const _i16 Index,_i8* pName, _i16 *pNameLen, _u8 *pMacAddr, SlWlanSecParams_t* pSecParams, SlWlanGetSecParamsExt_t* pEntParams, _u32 *pPriority)
721 {
722 _SlProfileGetMsg_u Msg;
723 Msg.Cmd.Index = (_u8)Index;
724
725 /* verify that this api is allowed. if not allowed then
726 ignore the API execution and return immediately with an error */
727 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
728
729 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileGetCmdCtrl, &Msg, NULL));
730
731 pSecParams->Type = (_u8)(Msg.Rsp.Args.Common.SecType);
732 if (Msg.Rsp.Args.Common.SecType >= 0)
733 {
734 /* since password is not transferred in getprofile, password length should always be zero */
735 pSecParams->KeyLen = Msg.Rsp.Args.Common.PasswordLen;
736 if (NULL != pEntParams)
737 {
738 pEntParams->EapMethod = Msg.Rsp.Args.EapBitmask;
739 pEntParams->UserLen = Msg.Rsp.Args.UserLen;
740 /* copy user name */
741 if (pEntParams->UserLen > 0)
742 {
743 sl_Memcpy(pEntParams->User, EAP_PROFILE_USER_STRING(&Msg), pEntParams->UserLen);
744 }
745 pEntParams->AnonUserLen = Msg.Rsp.Args.AnonUserLen;
746 /* copy anonymous user name */
747 if (pEntParams->AnonUserLen > 0)
748 {
749 sl_Memcpy(pEntParams->AnonUser, EAP_PROFILE_ANON_USER_STRING(&Msg), pEntParams->AnonUserLen);
750 }
751 }
752
753 *pNameLen = (_i16)(Msg.Rsp.Args.Common.SsidLen);
754 *pPriority = Msg.Rsp.Args.Common.Priority;
755 if (NULL != pMacAddr)
756 {
757 sl_Memcpy(pMacAddr, Msg.Rsp.Args.Common.Bssid, sizeof(Msg.Rsp.Args.Common.Bssid));
758 }
759 sl_Memset(pName, 0, SL_WLAN_SSID_MAX_LENGTH);
760 sl_Memcpy(pName, EAP_PROFILE_SSID_STRING(&Msg), *pNameLen);
761 }
762 return (_i16)Msg.Rsp.Args.Common.SecType;
763 }
764 #endif
765 /*******************************************************************************/
766 /* sl_ProfileDel */
767 /*******************************************************************************/
768 typedef union
769 {
770 SlWlanProfileDelGetCommand_t Cmd;
771 _BasicResponse_t Rsp;
772 }_SlProfileDelMsg_u;
773
774
775 #if _SL_INCLUDE_FUNC(sl_WlanProfileDel)
776
777 static const _SlCmdCtrl_t _SlProfileDelCmdCtrl =
778 {
779 SL_OPCODE_WLAN_PROFILEDELCOMMAND,
780 (_SlArgSize_t)sizeof(SlWlanProfileDelGetCommand_t),
781 (_SlArgSize_t)sizeof(_BasicResponse_t)
782 };
783
sl_WlanProfileDel(const _i16 Index)784 _i16 sl_WlanProfileDel(const _i16 Index)
785 {
786 _SlProfileDelMsg_u Msg;
787
788 /* verify that this api is allowed. if not allowed then
789 ignore the API execution and return immediately with an error */
790 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
791
792 Msg.Cmd.Index = (_u8)Index;
793
794 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProfileDelCmdCtrl, &Msg, NULL));
795
796 return (_i16)Msg.Rsp.status;
797 }
798 #endif
799
800
801 /******************************************************************************/
802 /* sl_WlanGetNetworkList */
803 /******************************************************************************/
804 typedef union
805 {
806 SlWlanGetNetworkListCommand_t Cmd;
807 _WlanGetNetworkListResponse_t Rsp;
808 }_SlWlanGetNetworkListMsg_u;
809
810
811 #if _SL_INCLUDE_FUNC(sl_WlanGetNetworkList)
812
813 static const _SlCmdCtrl_t _SlWlanGetNetworkListCtrl =
814 {
815 SL_OPCODE_WLAN_SCANRESULTSGETCOMMAND,
816 (_SlArgSize_t)sizeof(SlWlanGetNetworkListCommand_t),
817 (_SlArgSize_t)sizeof(_WlanGetNetworkListResponse_t)
818 };
819
sl_WlanGetNetworkList(const _u8 Index,const _u8 Count,SlWlanNetworkEntry_t * pEntries)820 _i16 sl_WlanGetNetworkList(const _u8 Index,const _u8 Count, SlWlanNetworkEntry_t *pEntries)
821 {
822 _i16 retVal = 0;
823 _SlWlanGetNetworkListMsg_u Msg;
824 _SlCmdExt_t CmdExt;
825
826 /* verify that this api is allowed. if not allowed then
827 ignore the API execution and return immediately with an error */
828 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
829
830 if (Count == 0)
831 {
832 return SL_EZEROLEN;
833 }
834
835 _SlDrvResetCmdExt(&CmdExt);
836 CmdExt.RxPayloadLen = (_i16)(sizeof(SlWlanNetworkEntry_t)*(Count));
837 CmdExt.pRxPayload = (_u8 *)pEntries;
838
839 Msg.Cmd.Index = Index;
840 Msg.Cmd.Count = Count;
841
842 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanGetNetworkListCtrl, &Msg, &CmdExt));
843 retVal = Msg.Rsp.status;
844
845 return (_i16)retVal;
846 }
847 #endif
848
849 /******************************************************************************/
850 /* sl_WlanGetExtNetworkList */
851 /******************************************************************************/
852 typedef union
853 {
854 SlWlanGetExtNetworkListCommand_t Cmd;
855 _WlanGetExtNetworkListResponse_t Rsp;
856 }_SlWlanGetExtNetworkListMsg_u;
857
858
859 #if _SL_INCLUDE_FUNC(sl_WlanGetExtNetworkList)
860
861 static const _SlCmdCtrl_t _SlWlanGetExtNetworkListCtrl =
862 {
863 SL_OPCODE_WLAN_EXTSCANRESULTSGETCOMMAND,
864 (_SlArgSize_t)sizeof(SlWlanGetExtNetworkListCommand_t),
865 (_SlArgSize_t)sizeof(_WlanGetExtNetworkListResponse_t)
866 };
867
sl_WlanGetExtNetworkList(const _u8 Index,const _u8 Count,SlWlanExtNetworkEntry_t * pEntries)868 _i16 sl_WlanGetExtNetworkList(const _u8 Index,const _u8 Count, SlWlanExtNetworkEntry_t *pEntries)
869 {
870 _i16 retVal = 0;
871 _SlWlanGetExtNetworkListMsg_u Msg;
872 _SlCmdExt_t CmdExt;
873
874 /* verify that this api is allowed. if not allowed then
875 ignore the API execution and return immediately with an error */
876 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
877
878 if (Count == 0)
879 {
880 return SL_EZEROLEN;
881 }
882
883 _SlDrvResetCmdExt(&CmdExt);
884 CmdExt.RxPayloadLen = (_i16)(sizeof(SlWlanExtNetworkEntry_t)*(Count));
885 CmdExt.pRxPayload = (_u8 *)pEntries;
886
887 Msg.Cmd.Index = Index;
888 Msg.Cmd.Count = Count;
889
890 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanGetExtNetworkListCtrl, &Msg, &CmdExt));
891 retVal = Msg.Rsp.status;
892
893 return (_i16)retVal;
894 }
895 #endif
896
897
898 /******************************************************************************/
899 /* RX filters message command response structures */
900 /******************************************************************************/
901
902
903 typedef union
904 {
905 SlWlanRxFilterAddCommand_t Cmd;
906 SlWlanRxFilterAddCommandReponse_t Rsp;
907 }_SlWlanRxFilterAddMsg_u;
908
909
910 #if _SL_INCLUDE_FUNC(sl_WlanRxFilterAdd)
911
912 static const _SlCmdCtrl_t _SlWlanRxFilterAddtCmdCtrl =
913 {
914 SL_OPCODE_WLAN_WLANRXFILTERADDCOMMAND,
915 (_SlArgSize_t)sizeof(SlWlanRxFilterAddCommand_t),
916 (_SlArgSize_t)sizeof(SlWlanRxFilterAddCommandReponse_t)
917 };
918
919
920 /*****************************************************************************
921 RX filters
922 *****************************************************************************/
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)923 _i16 sl_WlanRxFilterAdd(SlWlanRxFilterRuleType_t RuleType,
924 SlWlanRxFilterFlags_u Flags,
925 const SlWlanRxFilterRule_u* const pRule,
926 const SlWlanRxFilterTrigger_t* const pTrigger,
927 const SlWlanRxFilterAction_t* const pAction,
928 SlWlanRxFilterID_t* pFilterId)
929 {
930 _SlWlanRxFilterAddMsg_u Msg;
931
932 /* verify that this api is allowed. if not allowed then
933 ignore the API execution and return immediately with an error */
934 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
935
936 Msg.Cmd.RuleType = RuleType;
937 /* filterId is zero */
938 Msg.Cmd.FilterId = 0;
939 Msg.Cmd.Flags = Flags;
940 sl_Memcpy( &(Msg.Cmd.Rule), pRule, sizeof(SlWlanRxFilterRule_u) );
941 sl_Memcpy( &(Msg.Cmd.Trigger), pTrigger, sizeof(SlWlanRxFilterTrigger_t) );
942 sl_Memcpy( &(Msg.Cmd.Action), pAction, sizeof(SlWlanRxFilterAction_t) );
943 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanRxFilterAddtCmdCtrl, &Msg, NULL) );
944 *pFilterId = Msg.Rsp.FilterId;
945 return (_i16)Msg.Rsp.Status;
946 }
947 #endif
948
949
950 /*******************************************************************************/
951 /* sl_WlanRxStatStart */
952 /*******************************************************************************/
953 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStart)
sl_WlanRxStatStart(void)954 _i16 sl_WlanRxStatStart(void)
955 {
956 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
957 if(SL_IS_DEVICE_STAT_IN_PROGRESS)
958 {
959 SL_DRV_PROTECTION_OBJ_UNLOCK();
960 return SL_RET_CODE_DEVICE_STAT_IN_PROGRESS;
961 }
962 else
963 {
964 /* turn on flag indication for RX statistics is in progress
965 * to avoid parallel "starts" between
966 * Device statistics API and RX statistics API */
967 SL_SET_WLAN_RX_STAT_IN_PROGRESS;
968 SL_DRV_PROTECTION_OBJ_UNLOCK();
969 /* verify that this api is allowed. if not allowed then
970 ignore the API execution and return immediately with an error */
971 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
972
973 }
974 return _SlDrvBasicCmd(SL_OPCODE_WLAN_STARTRXSTATCOMMAND);
975 }
976 #endif
977
978
979
980 #if _SL_INCLUDE_FUNC(sl_WlanRxStatGet)
sl_WlanRxStatGet(SlWlanGetRxStatResponse_t * pRxStat,const _u32 Flags)981 _i16 sl_WlanRxStatGet(SlWlanGetRxStatResponse_t *pRxStat,const _u32 Flags)
982 {
983 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
984 if(SL_IS_DEVICE_STAT_IN_PROGRESS)
985 {
986 SL_DRV_PROTECTION_OBJ_UNLOCK();
987 return SL_RET_CODE_DEVICE_STAT_IN_PROGRESS;
988 }
989 SL_DRV_PROTECTION_OBJ_UNLOCK();
990
991 _SlCmdCtrl_t CmdCtrl = {SL_OPCODE_WLAN_GETRXSTATCOMMAND, 0, (_SlArgSize_t)sizeof(SlWlanGetRxStatResponse_t)};
992 /* Flags parameter is currently not in use */
993 (void)Flags;
994
995 /* verify that this api is allowed. if not allowed then
996 ignore the API execution and return immediately with an error */
997 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
998
999 _SlDrvMemZero(pRxStat, (_u16)sizeof(SlWlanGetRxStatResponse_t));
1000 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, pRxStat, NULL));
1001 return 0;
1002 }
1003 #endif
1004
1005
1006 #if _SL_INCLUDE_FUNC(sl_WlanRxStatStop)
sl_WlanRxStatStop(void)1007 _i16 sl_WlanRxStatStop(void)
1008 {
1009 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
1010 if(SL_IS_DEVICE_STAT_IN_PROGRESS)
1011 {
1012 SL_DRV_PROTECTION_OBJ_UNLOCK();
1013 return SL_RET_CODE_DEVICE_STAT_IN_PROGRESS;
1014 }
1015
1016 else
1017 {
1018 SL_UNSET_WLAN_RX_STAT_IN_PROGRESS;
1019 SL_DRV_PROTECTION_OBJ_UNLOCK();
1020 /* verify that this api is allowed. if not allowed then
1021 ignore the API execution and return immediately with an error */
1022 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
1023 return _SlDrvBasicCmd(SL_OPCODE_WLAN_STOPRXSTATCOMMAND);
1024
1025 }
1026 }
1027 #endif
1028
1029 /******************************************************************************/
1030 /* sl_WlanProvisioning */
1031 /******************************************************************************/
1032
1033 typedef struct
1034 {
1035 SlWlanSmartConfigParams_t Args;
1036 _i8 Key[MAX_SMART_CONFIG_KEY]; /* public key + groupId1 key + groupId2 key */
1037 }_SlSmartConfigArgs_t;
1038
1039 typedef struct
1040 {
1041 SlWlanProvisioningParams_t ProvParams;
1042 _SlSmartConfigArgs_t SmartConfigParams;
1043 }_SlProvisioning_t;
1044
1045 typedef union
1046 {
1047 _SlProvisioning_t Cmd;
1048 _BasicResponse_t Rsp;
1049 }_SlProvisioningStartMsg_u;
1050
1051 #if _SL_INCLUDE_FUNC(sl_WlanProvisioning)
1052
1053 const _SlCmdCtrl_t _SlProvisioningCmdCtrl =
1054 {
1055 SL_OPCODE_WLAN_PROVISIONING_COMMAND,
1056 sizeof(_SlProvisioning_t),
1057 sizeof(_BasicResponse_t)
1058 };
1059
sl_WlanProvisioning(_u8 ProvisioningCmd,_u8 RequestedRoleAfterSuccess,_u16 InactivityTimeoutSec,char * pSmartConfigKey,_u32 Flags)1060 _i16 sl_WlanProvisioning(_u8 ProvisioningCmd, _u8 RequestedRoleAfterSuccess, _u16 InactivityTimeoutSec, char *pSmartConfigKey, _u32 Flags)
1061 {
1062 _SlProvisioningStartMsg_u Msg;
1063
1064 /* Verify if we can send this command to the NWP
1065 We can send only prov. stop command if command is not allowed */
1066 if ((!SL_IS_COMMAND_ALLOWED) && (!SL_IS_PROVISIONING_ACTIVE) && (InactivityTimeoutSec != 0))
1067 {
1068 /* return with the correct error code */
1069 return _SlDrvDriverIsApiAllowed(SL_OPCODE_SILO_WLAN);
1070 }
1071
1072 /* If there is an API in progress and the timeout is not zero (it means the
1073 command is not prov. stop) then abort and return an error code */
1074 if (_SlDrvIsApiInProgress() && (InactivityTimeoutSec !=0))
1075 {
1076 return SL_RET_CODE_API_COMMAND_IN_PROGRESS;
1077 }
1078
1079 _SlDrvMemZero(&Msg, (_u16)sizeof (_SlProvisioningStartMsg_u));
1080
1081 Msg.Cmd.ProvParams.ProvisioningCmd = (_u8)ProvisioningCmd;
1082 Msg.Cmd.ProvParams.RequestedRoleAfterSuccess = (_u8)RequestedRoleAfterSuccess;
1083 Msg.Cmd.ProvParams.InactivityTimeoutSec = (_u16)InactivityTimeoutSec;
1084 Msg.Cmd.ProvParams.Flags = Flags;
1085
1086 /* Smart Config parameters */
1087 if (NULL != pSmartConfigKey)
1088 {
1089 Msg.Cmd.SmartConfigParams.Args.GroupIdBitmask = SL_WLAN_SMART_CONFIG_DEFAULT_GROUP;
1090 Msg.Cmd.SmartConfigParams.Args.Cipher = SL_WLAN_SMART_CONFIG_DEFAULT_CIPHER;
1091 Msg.Cmd.SmartConfigParams.Args.PublicKeyLen = SL_WLAN_SMART_CONFIG_KEY_LENGTH;
1092
1093 /* copy keys (if exist) after command (one after another) */
1094 sl_Memcpy(Msg.Cmd.SmartConfigParams.Key, pSmartConfigKey, SL_WLAN_SMART_CONFIG_KEY_LENGTH);
1095 }
1096 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlProvisioningCmdCtrl , &Msg, NULL));
1097
1098 return (_i16)Msg.Rsp.status;
1099 }
1100 #endif
1101
1102 /*******************************************************************************/
1103 /* sl_WlanSetMode */
1104 /*******************************************************************************/
1105 typedef union
1106 {
1107 SlWlanSetMode_t Cmd;
1108 _BasicResponse_t Rsp;
1109 }_SlwlanSetModeMsg_u;
1110
1111 #if _SL_INCLUDE_FUNC(sl_WlanSetMode)
1112
1113 static const _SlCmdCtrl_t _SlWlanSetModeCmdCtrl =
1114 {
1115 SL_OPCODE_WLAN_SET_MODE,
1116 (_SlArgSize_t)sizeof(SlWlanSetMode_t),
1117 (_SlArgSize_t)sizeof(_BasicResponse_t)
1118 };
1119
1120 /* possible values are:
1121 WLAN_SET_STA_MODE = 1
1122 WLAN_SET_AP_MODE = 2
1123 WLAN_SET_P2P_MODE = 3 */
sl_WlanSetMode(const _u8 Mode)1124 _i16 sl_WlanSetMode(const _u8 Mode)
1125 {
1126 _SlwlanSetModeMsg_u Msg;
1127
1128 /* verify that this api is allowed. if not allowed then
1129 ignore the API execution and return immediately with an error */
1130 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
1131
1132 Msg.Cmd.Mode = Mode;
1133
1134 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanSetModeCmdCtrl , &Msg, NULL));
1135
1136 return (_i16)Msg.Rsp.status;
1137 }
1138 #endif
1139
1140 /*******************************************************************************/
1141 /* sl_WlanSet */
1142 /* ******************************************************************************/
1143 typedef union
1144 {
1145 SlWlanCfgSetGet_t Cmd;
1146 _BasicResponse_t Rsp;
1147 }_SlWlanCfgSetMsg_u;
1148
1149
1150 #if _SL_INCLUDE_FUNC(sl_WlanSet)
1151
1152 static const _SlCmdCtrl_t _SlWlanCfgSetCmdCtrl =
1153 {
1154 SL_OPCODE_WLAN_CFG_SET,
1155 (_SlArgSize_t)sizeof(SlWlanCfgSetGet_t),
1156 (_SlArgSize_t)sizeof(_BasicResponse_t)
1157 };
1158
sl_WlanSet(const _u16 ConfigId,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 * pValues)1159 _i16 sl_WlanSet(const _u16 ConfigId ,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 *pValues)
1160 {
1161 _SlWlanCfgSetMsg_u Msg;
1162 _SlCmdExt_t CmdExt;
1163
1164 /* verify that this api is allowed. if not allowed then
1165 ignore the API execution and return immediately with an error */
1166 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
1167
1168 _SlDrvResetCmdExt(&CmdExt);
1169 CmdExt.TxPayload1Len = (_u16)((ConfigLen+3) & (~3));
1170 CmdExt.pTxPayload1 = (_u8 *)pValues;
1171
1172 Msg.Cmd.ConfigId = ConfigId;
1173 Msg.Cmd.ConfigLen = ConfigLen;
1174 Msg.Cmd.ConfigOpt = ConfigOpt;
1175
1176 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgSetCmdCtrl, &Msg, &CmdExt));
1177
1178 return (_i16)Msg.Rsp.status;
1179 }
1180 #endif
1181
1182
1183 /******************************************************************************/
1184 /* sl_WlanGet */
1185 /******************************************************************************/
1186 typedef union
1187 {
1188 SlWlanCfgSetGet_t Cmd;
1189 SlWlanCfgSetGet_t Rsp;
1190 }_SlWlanCfgMsgGet_u;
1191
1192 #if _SL_INCLUDE_FUNC(sl_WlanGet)
1193
1194 static const _SlCmdCtrl_t _SlWlanCfgGetCmdCtrl =
1195 {
1196 SL_OPCODE_WLAN_CFG_GET,
1197 (_SlArgSize_t)sizeof(SlWlanCfgSetGet_t),
1198 (_SlArgSize_t)sizeof(SlWlanCfgSetGet_t)
1199 };
1200
sl_WlanGet(const _u16 ConfigId,_u16 * pConfigOpt,_u16 * pConfigLen,_u8 * pValues)1201 _i16 sl_WlanGet(const _u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues)
1202 {
1203 _SlWlanCfgMsgGet_u Msg;
1204 _SlCmdExt_t CmdExt;
1205
1206 /* verify that this api is allowed. if not allowed then
1207 ignore the API execution and return immediately with an error */
1208 VERIFY_API_ALLOWED(SL_OPCODE_SILO_WLAN);
1209
1210 if (*pConfigLen == 0)
1211 {
1212 return SL_EZEROLEN;
1213 }
1214
1215 _SlDrvResetCmdExt(&CmdExt);
1216 CmdExt.RxPayloadLen = (_i16)*pConfigLen;
1217 CmdExt.pRxPayload = (_u8 *)pValues;
1218 Msg.Cmd.ConfigLen = *pConfigLen;
1219 Msg.Cmd.ConfigId = ConfigId;
1220 if( pConfigOpt )
1221 {
1222 Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt;
1223 }
1224 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlWlanCfgGetCmdCtrl, &Msg, &CmdExt));
1225
1226 if( pConfigOpt )
1227 {
1228 *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt;
1229 }
1230 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
1231 {
1232 *pConfigLen = (_u8)CmdExt.RxPayloadLen;
1233 return SL_ESMALLBUF;
1234 }
1235 else
1236 {
1237 *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
1238 }
1239
1240 return (_i16)Msg.Rsp.Status;
1241 }
1242 #endif
1243