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