-
Notifications
You must be signed in to change notification settings - Fork 1
/
uapcmd.c
4704 lines (4442 loc) · 141 KB
/
uapcmd.c
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
/** @file uapcmd.c
*
* @brief This file contains the handling of command.
*
* Copyright (C) 2008-2009, Marvell International Ltd.
*
* This software file (the "File") is distributed by Marvell International
* Ltd. under the terms of the GNU General Public License Version 2, June 1991
* (the "License"). You may use, redistribute and/or modify this File in
* accordance with the terms and conditions of the License, a copy of which
* is available along with the File in the gpl.txt file or by writing to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 or on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*
*/
/****************************************************************************
Change log:
03/01/08: Initial creation
****************************************************************************/
/****************************************************************************
Header files
****************************************************************************/
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <stdio.h>
#include <getopt.h>
#include <netinet/in.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>
#include "uaputl.h"
#include "uapcmd.h"
extern struct option cmd_options[];
/****************************************************************************
Local functions
****************************************************************************/
/**
* @brief Show usage information for the sys_cfg_ap_mac_address
* command
*
* $return N/A
*/
void
print_sys_cfg_ap_mac_address_usage(void)
{
printf("\nUsage : sys_cfg_ap_mac_address [AP_MAC_ADDRESS]\n");
printf
("\nIf AP_MAC_ADDRESS is provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_ssid command
*
* $return N/A
*/
void
print_sys_cfg_ssid_usage(void)
{
printf("\nUsage : sys_cfg_ssid [SSID]\n");
printf
("\nIf SSID is provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_beacon_period
* command
*
* $return N/A
*/
void
print_sys_cfg_beacon_period_usage(void)
{
printf("\nUsage : sys_cfg_beacon_period [BEACON_PERIOD]\n");
printf
("\nIf BEACON_PERIOD is provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_dtim_period
* command
*
* $return N/A
*/
void
print_sys_cfg_dtim_period_usage(void)
{
printf("\nUsage : sys_cfg_dtim_period [DTIM_PERIOD]\n");
printf
("\nIf DTIM_PERIOD is provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_channel
* command
*
* $return N/A
*/
void
print_sys_cfg_channel_usage(void)
{
printf("\nUsage : sys_cfg_channel [CHANNEL] [MODE]\n");
printf
("\nIf CHANNEL is provided, a 'set' is performed, else a 'get' is performed.");
printf("\nIf MODE is provided, 0 for manual channel selection,");
printf("\nelse ACS (automatic channel selection) is performed\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_scan_channels
* command
*
* $return N/A
*/
void
print_sys_cfg_scan_channels_usage(void)
{
printf("\nUsage : sys_cfg_scan_channels [CHANNELS]\n");
printf
("\nIf CHANNELS are provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_rates_ext command
*
* $return N/A
*/
void
print_sys_cfg_rates_ext_usage(void)
{
printf
("\nUsage : sys_cfg_rates_ext [rates RATES] [mbrate RATE] [urate RATE]\n");
printf
("\nIf 'Rate' provided, a 'set' is performed else a 'get' is performed");
printf
("\nRATES is provided as a set of data rates, in unit of 500 kilobits");
printf("\nA rate with MSB bit is basic rate, i.e 0x82 is basic rate.\n");
printf("\nFollowing is the list of supported rates in units of 500 Kbps:");
printf("\nDecimal: (2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108)");
printf
("\nHex: (0x02, 0x04, 0x0b, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c)");
printf
("\nBasic rates: (0x82, 0x84, 0x8b, 0x96, 0x8C, 0x92, 0x98, 0xA4, 0xB0, 0xC8, 0xE0, 0xEc)\n");
printf
("\nRates 2, 4, 11 and 22 (in units of 500 Kbps) must be present in either of basic or");
printf
("\nnon-basic rates. If OFDM rates are enabled then 12, 24 and 48 (in units of 500 Kbps)");
printf("\nmust be present in either basic or non-basic rates");
printf("\nEach rate must be separated by a space.");
printf("\nrates followed by RATES for setting operational rates.");
printf
("\nmbrate followed by RATE for setting multicast and broadcast rate.");
printf("\nurate followed by RATE for setting unicast rate.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_rates command
*
* $return N/A
*/
void
print_sys_cfg_rates_usage(void)
{
printf("\nUsage : sys_cfg_rates [RATES]\n");
printf
("\n[RATES] is set of data rates in unit of 500 kbps and each rate can be");
printf
("\nentered in hexadecimal or decimal format. Rates must be separated by");
printf("\nspace. Duplicate Rate fields are not allowed");
printf("\nA rate with MSB bit is basic rate, i.e 0x82 is basic rate.");
printf("\nFollowing is the list of supported rates in units of 500 Kbps:");
printf("\nDecimal: (2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108)");
printf
("\nHex: (0x02, 0x04, 0x0b, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c)");
printf
("\nBasic rates: (0x82, 0x84, 0x8b, 0x96, 0x8C, 0x92, 0x98, 0xA4, 0xB0, 0xC8, 0xE0, 0xEc)\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_tx_power
* command
*
* $return N/A
*/
void
print_sys_cfg_tx_power_usage(void)
{
printf("\nUsage : sys_cfg_tx_power [TX_POWER]\n");
printf
("\nIf TX_POWER is provided, a 'set' is performed, else a 'get' is performed.");
printf("\nTX_POWER is represented in dBm.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_bcast_ssid_ctl
* command
*
* $return N/A
*/
void
print_sys_cfg_bcast_ssid_ctl_usage(void)
{
printf("\nUsage : sys_cfg_bcast_ssid_ctl [0|1]\n");
printf("\nOptions: 0 - Disable SSID broadcast");
printf("\n 1 - Enable SSID broadcast");
printf("\n empty - Get current SSID broadcast setting\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_rsn_replay_prot
* command
*
* $return N/A
*/
void
print_sys_cfg_rsn_replay_prot_usage(void)
{
printf("\nUsage : sys_cfg_rsn_replay_prot [0|1]\n");
printf("\nOptions: 0 - Disable RSN replay protection");
printf("\n 1 - Enable RSN replay protection");
printf("\n empty - Get current RSN replay protection setting\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_preamble_ctl
* command
*
* $return N/A
*/
void
print_sys_cfg_preamble_ctl_usage(void)
{
printf("\nUsage : sys_cfg_preamble_ctl\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_antenna_ctl
* command
*
* $return N/A
*/
void
print_sys_cfg_antenna_ctl_usage(void)
{
printf("\nUsage : sys_cfg_antenna_ctl <ANTENNA> [MODE]\n");
printf("\nOptions: ANTENNA : 0 - Rx antenna");
printf("\n 1 - Tx antenna");
printf("\n MODE : 0 - Antenna A");
printf("\n 1 - Antenna B");
printf("\n empty - Get current antenna settings\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_rts_threshold
* command
*
* $return N/A
*/
void
print_sys_cfg_rts_threshold_usage(void)
{
printf("\nUsage : sys_cfg_rts_threshold [RTS_THRESHOLD]\n");
printf
("\nIf RTS_THRESHOLD is provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_frag_threshold
* command
*
* $return N/A
*/
void
print_sys_cfg_frag_threshold_usage(void)
{
printf("\nUsage : sys_cfg_frag_threshold [FRAG_THRESHOLD]\n");
printf
("\nIf FRAG_THRESHOLD is provided, a 'set' is performed, else a 'get' is performed.");
printf("\nFragment threshold should between 256 and 2346.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_radio_ctl
* command
*
* $return N/A
*/
void
print_sys_cfg_radio_ctl_usage(void)
{
printf("\nUsage : sys_cfg_radio_ctl [0|1]\n");
printf("\nOptions: 0 - Turn radio on");
printf("\n 1 - Turn radio off");
printf("\n empty - Get current radio setting\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_tx_data_rate
* command
*
* $return N/A
*/
void
print_sys_cfg_tx_data_rates_usage(void)
{
printf("\nUsage : sys_cfg_tx_data_rate [TX_DATA_RATE]\n");
printf("\nOptions: 0 - Auto rate");
printf("\n >0 - Set specified data rate");
printf("\n empty - Get current data rate");
printf("\nFollowing is the list of supported rates in units of 500 Kbps");
printf("\nDecimal: (2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108)");
printf
("\nHex: (0x02, 0x04, 0x0b, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c)");
printf("\nOnly zero or rates currently configured are allowed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_mcbc_data_rate
* command
*
* $return N/A
*/
void
print_sys_cfg_mcbc_data_rates_usage(void)
{
printf("\nUsage : sys_cfg_mcbc_data_rate [MCBC_DATA_RATE]\n");
printf("\nOptions: 0 - Auto rate");
printf("\n >0 - Set specified MCBC data rate");
printf("\n empty - Get current MCBC data rate");
printf("\nFollowing is the list of supported rates in units of 500 Kbps");
printf("\nDecimal: (2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108)");
printf
("\nHex: (0x02, 0x04, 0x0b, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c)");
printf
("\nOnly zero or one of the basic rates currently configured are allowed.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_auth command
*
* $return N/A
*/
void
print_sys_cfg_auth_usage(void)
{
printf("\nUsage : sys_cfg_auth [AUTHMODE]\n");
printf("\nOptions: AUTHMODE : 0 - Open authentication");
printf("\n 1 - Shared key authentication");
printf("\n empty - Get current authenticaton mode\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_pkt_fwd_ctl command
*
* $return N/A
*/
void
print_sys_cfg_pkt_fwd_ctl_usage(void)
{
printf("\nUsage : sys_cfg_pkt_fwd_ctl [0|1]\n");
printf("\nOptions: 0 - Forward all packets to the host");
printf("\n 1 - Firmware handles intra-BSS packets");
printf("\n empty - Get current packet forwarding setting\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_sta_ageout_timer
* command
*
* $return N/A
*/
void
print_sys_cfg_sta_ageout_timer_usage(void)
{
printf("\nUsage : sys_cfg_sta_ageout_timer [STA_AGEOUT_TIMER]\n");
printf
("\nIf STA_AGEOUT_TIMER is provided, a 'set' is performed, else a 'get' is performed.");
printf("\nSTA_AGEOUT_TIMER is represented in units of 100 ms.");
printf("\nValue of 0 will mean that stations will never be aged out.");
printf("\nThe value should between 300 and 864000.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_protocol command
*
* $return N/A
*/
void
print_sys_cfg_protocol_usage(void)
{
printf("\nUsage : sys_cfg_protocol [PROTOCOL]\n");
printf("\nOptions: PROTOCOL: 1 - No RSN");
printf("\n 2 - WEP Static");
printf("\n 8 - WPA");
printf("\n 32 - WPA2");
printf("\n 40 - WPA2 Mixed");
printf("\n empty - Get current protocol\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_wep_key
* command
*
* $return N/A
*/
void
print_sys_cfg_wep_key_usage(void)
{
printf("\nUsage : sys_cfg_wep_key ");
printf
("[INDEX_0 IS_DEFAULT KEY_0] [INDEX_1 IS_DEFAULT KEY_1] [INDEX_2 IS_DEFAULT KEY_2] [INDEX_3 IS_DEFAULT KEY_3]\n");
printf("[Index_0] [Index_1] [Index_2] [Index_3]\n");
printf("\nOptions: INDEX_* : 0 - KeyIndex is 0");
printf("\n 1 - KeyIndex is 1");
printf("\n 2 - KeyIndex is 2");
printf("\n 3 - KeyIndex is 3");
printf("\n IS_DEFAULT : 0 - KeyIndex is not the default");
printf
("\n 1 - KeyIndex is the default transmit key");
printf("\n KEY_* : Key value");
printf("\n Index_*: 0 - Get key 0 setting");
printf("\n 1 - Get key 1 setting");
printf("\n 2 - Get key 2 setting");
printf("\n 3 - Get key 3 setting");
printf("\n empty - Get current WEP key settings\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_custom_ie
* command
*
* $return N/A
*/
void
print_sys_cfg_custom_ie_usage(void)
{
printf("\nUsage : sys_cfg_custom_ie [INDEX] [MASK] [IEBuffer]");
printf("\n empty - Get all IE settings\n");
printf("\n INDEX: 0 - Get/Set IE index 0 setting");
printf("\n 1 - Get/Set IE index 1 setting");
printf("\n 2 - Get/Set IE index 2 setting");
printf("\n 3 - Get/Set IE index 3 setting");
printf
("\n MASK : Management subtype mask value as per bit defintions");
printf("\n : Bit 0 - Association request.");
printf("\n : Bit 1 - Association response.");
printf("\n : Bit 2 - Reassociation request.");
printf("\n : Bit 3 - Reassociation response.");
printf("\n : Bit 4 - Probe request.");
printf("\n : Bit 5 - Probe response.");
printf("\n : Bit 8 - Beacon.");
printf("\n MASK : MASK = 0 to clear the mask and the IE buffer");
printf("\n IEBuffer : IE Buffer in hex (max 256 bytes)\n\n");
return;
}
/* @brief Show usage information for the sys_cfg_cipher * command * * $return
N/A */
void
print_sys_cfg_cipher_usage(void)
{
printf("\nUsage : sys_cfg_cipher [PAIRWISE_CIPHER GROUP_CIPHER]\n");
printf("\nOptions: PAIRWISE_CIPHER: 0 - NONE");
printf("\n 4 - TKIP");
printf("\n 8 - AES CCMP");
printf("\n 12 - AES CCMP + TKIP");
printf("\n GROUP_CIPHER : 0 - NONE");
printf("\n 4 - TKIP");
printf("\n 8 - AES CCMP");
printf("\n empty - Get current cipher settings\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_group_rekey_timer command
*
* $return N/A
*/
void
print_sys_cfg_group_rekey_timer_usage(void)
{
printf("\nUsage : sys_cfg_group_rekey_timer [GROUP_REKEY_TIMER]\n");
printf("\nOptions: GROUP_REKEY_TIME is represented in seconds");
printf("\n empty - Get current group re-key time\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_wpa_passphrase
* command
*
* $return N/A
*/
void
print_sys_cfg_wpa_passphrase_usage(void)
{
printf("\nUsage : sys_cfg_wpa_passphrase [PASSPHRASE]\n");
printf
("\nIf PASSPHRASE is provided, a 'set' is performed, else a 'get' is performed.\n");
return;
}
/**
* @brief Show usage information for the sta_filter_table command
*
* $return N/A
*/
void
print_sta_filter_table_usage(void)
{
printf("\nUsage : sta_filter_table <FILTERMODE> <MACADDRESS_LIST>\n");
printf("\nOptions: FILTERMODE : 0 - Disable filter table");
printf
("\n 1 - allow MAC addresses specified in the allowed list");
printf
("\n 2 - block MAC addresses specified in the banned list");
printf
("\n MACADDRESS_LIST is the list of MAC addresses to be acted upon. Each");
printf
("\n MAC address must be separated with a space. Maximum of");
printf("\n 16 MAC addresses are supported.");
printf("\n empty - Get current mac filter settings\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_max_sta_num command
*
* $return N/A
*/
void
print_sys_cfg_max_sta_num_usage(void)
{
printf("\nUsage : sys_cfg_max_sta_num [STA_NUM]\n");
printf
("\nIf STA_NUM is provided, a 'set' is performed, else a 'get' is performed.");
printf("\nSTA_NUM should not bigger than 8.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_retry_limit command
*
* $return N/A
*/
void
print_sys_cfg_retry_limit_usage(void)
{
printf("\nUsage : sys_cfg_retry_limit [RETRY_LIMIT]\n");
printf
("\nIf RETRY_LIMIT is provided, a 'set' is performed, else a 'get' is performed.");
printf("\nRETRY_LIMIT should not bigger than 14.\n");
return;
}
/**
* @brief Show usage information for the sys_cfg_retry_limit command
*
* $return N/A
*/
void
print_cfg_data_usage(void)
{
printf("\nUsage : cfg_data <type> [*.conf]\n");
printf("\n type : 2 -- cal data");
printf("\n *.conf : file contain configuration data");
printf("\n empty - get current configuration data\n");
return;
}
/**
* @brief get configured operational rates.
*
* @param rates Operational rates allowed are
* stored at this pointer
* @return number of basic rates allowed.
* -1 if a failure
*/
int
get_sys_cfg_rates(u8 * rates)
{
APCMDBUF_SYS_CONFIGURE *cmd_buf = NULL;
TLVBUF_RATES *tlv = NULL;
u8 *buffer = NULL;
u16 cmd_len;
int ret = UAP_FAILURE;
int i = 0;
int rate_cnt = 0;
/* Initialize the command length */
cmd_len =
sizeof(APCMDBUF_SYS_CONFIGURE) + sizeof(TLVBUF_RATES) + MAX_DATA_RATES;
/* Initialize the command buffer */
buffer = (u8 *) malloc(cmd_len);
if (!buffer) {
printf("ERR:Cannot allocate buffer for command!\n");
return -1;
}
bzero((char *) buffer, cmd_len);
/* Locate headers */
cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
tlv = (TLVBUF_RATES *) (buffer + sizeof(APCMDBUF_SYS_CONFIGURE));
/* Fill the command buffer */
cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
cmd_buf->Size = cmd_len;
cmd_buf->SeqNum = 0;
cmd_buf->Result = 0;
tlv->Tag = MRVL_RATES_TLV_ID;
cmd_buf->Action = ACTION_GET;
tlv->Length = MAX_DATA_RATES;
endian_convert_tlv_header_out(tlv);
/* Send the command */
ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
endian_convert_tlv_header_in(tlv);
/* Process response */
if (ret == UAP_SUCCESS) {
/* Verify response */
if ((cmd_buf->CmdCode != (APCMD_SYS_CONFIGURE | APCMD_RESP_CHECK)) ||
(tlv->Tag != MRVL_RATES_TLV_ID)) {
printf("ERR:Corrupted response! CmdCode=%x, Tlv->Tag=%x\n",
cmd_buf->CmdCode, tlv->Tag);
free(buffer);
return -1;
}
/* copy response */
if (cmd_buf->Result == CMD_SUCCESS) {
for (i = 0; i < tlv->Length; i++) {
if (tlv->OperationalRates[i] != 0) {
rates[rate_cnt++] = tlv->OperationalRates[i];
}
}
} else {
printf("ERR:Could not get operational rates!\n");
}
} else {
printf("ERR:Command sending failed!\n");
}
if (buffer)
free(buffer);
return rate_cnt;
}
/**
* @brief check rate is valid or not.
*
* @param rate rate for check
*
* @return UAP_SUCCESS or UAP_FAILURE
*/
int
is_tx_rate_valid(u8 rate)
{
int rate_cnt = 0;
int i;
u8 rates[MAX_DATA_RATES];
rate_cnt = get_sys_cfg_rates((u8 *) & rates);
if (rate_cnt > 0) {
for (i = 0; i < rate_cnt; i++) {
if (rate == (rates[i] & ~BASIC_RATE_SET_BIT)) {
return UAP_SUCCESS;
}
}
}
return UAP_FAILURE;
}
/**
* @brief check mcbc rate is valid or not.
*
* @param rate rate for check
*
* @return UAP_SUCCESS or UAP_FAILURE
*/
int
is_mcbc_rate_valid(u8 rate)
{
int rate_cnt = 0;
int i;
u8 rates[MAX_DATA_RATES];
rate_cnt = get_sys_cfg_rates((u8 *) & rates);
if (rate_cnt > 0) {
for (i = 0; i < rate_cnt; i++) {
if (rates[i] & BASIC_RATE_SET_BIT) {
if (rate == (rates[i] & ~BASIC_RATE_SET_BIT)) {
return UAP_SUCCESS;
}
}
}
}
return UAP_FAILURE;
}
/****************************************************************************
Global functions
****************************************************************************/
/**
* @brief Creates a sys_cfg request for AP MAC address
* and sends to the driver
*
* Usage: "sys_cfg_ap_mac_address [AP_MAC_ADDRESS]"
* if AP_MAC_ADDRESS is provided, a 'set' is performed,
* else a 'get' is performed.
*
* @param argc Number of arguments
* @param argv Pointer to the arguments
* @return N/A
*/
void
apcmd_sys_cfg_ap_mac_address(int argc, char *argv[])
{
APCMDBUF_SYS_CONFIGURE *cmd_buf = NULL;
TLVBUF_AP_MAC_ADDRESS *tlv = NULL;
u8 *buffer = NULL;
u16 cmd_len;
int ret = UAP_FAILURE;
int opt;
while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
switch (opt) {
default:
print_sys_cfg_ap_mac_address_usage();
return;
}
}
argc -= optind;
argv += optind;
/* Check arguments */
if (argc > 1) {
printf("ERR:Too many arguments.\n");
print_sys_cfg_ap_mac_address_usage();
return;
}
/* Initialize the command length */
cmd_len = sizeof(APCMDBUF_SYS_CONFIGURE) + sizeof(TLVBUF_AP_MAC_ADDRESS);
/* Initialize the command buffer */
buffer = (u8 *) malloc(cmd_len);
if (!buffer) {
printf("ERR:Cannot allocate buffer for command!\n");
return;
}
bzero((char *) buffer, cmd_len);
/* Locate headers */
cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
tlv = (TLVBUF_AP_MAC_ADDRESS *) (buffer + sizeof(APCMDBUF_SYS_CONFIGURE));
/* Fill the command buffer */
cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
cmd_buf->Size = cmd_len;
cmd_buf->SeqNum = 0;
cmd_buf->Result = 0;
tlv->Tag = MRVL_AP_MAC_ADDRESS_TLV_ID;
tlv->Length = ETH_ALEN;
if (argc == 0) {
cmd_buf->Action = ACTION_GET;
} else {
cmd_buf->Action = ACTION_SET;
if ((ret = mac2raw(argv[0], tlv->ApMacAddr)) != UAP_SUCCESS) {
printf("ERR: %s Address \n", ret == UAP_FAILURE ? "Invalid MAC" :
ret == UAP_RET_MAC_BROADCAST ? "Broadcast" : "Multicast");
free(buffer);
return;
}
}
endian_convert_tlv_header_out(tlv);
/* Send the command */
ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
endian_convert_tlv_header_in(tlv);
/* Process response */
if (ret == UAP_SUCCESS) {
/* Verify response */
if ((cmd_buf->CmdCode != (APCMD_SYS_CONFIGURE | APCMD_RESP_CHECK)) ||
(tlv->Tag != MRVL_AP_MAC_ADDRESS_TLV_ID)) {
printf("ERR:Corrupted response! CmdCode=%x, Tlv->Tag=%x\n",
cmd_buf->CmdCode, tlv->Tag);
free(buffer);
return;
}
/* Print response */
if (cmd_buf->Result == CMD_SUCCESS) {
if (argc == 0) {
printf("AP MAC address = ");
print_mac(tlv->ApMacAddr);
printf("\n");
} else {
printf("AP MAC address setting successful\n");
}
} else {
if (argc == 0) {
printf("ERR:Could not get AP MAC address!\n");
} else {
printf("ERR:Could not set AP MAC address!\n");
}
}
} else {
printf("ERR:Command sending failed!\n");
}
if (buffer)
free(buffer);
return;
}
/**
* @brief Creates a sys_cfg request for SSID
* and sends to the driver
*
* Usage: "sys_cfg_ssid [SSID]"
* if SSID is provided, a 'set' is performed
* else a 'get' is performed
*
* @param argc Number of arguments
* @param argv Pointer to the arguments
* @return N/A
*/
void
apcmd_sys_cfg_ssid(int argc, char *argv[])
{
APCMDBUF_SYS_CONFIGURE *cmd_buf = NULL;
TLVBUF_SSID *tlv = NULL;
u8 *buffer = NULL;
u16 cmd_len;
int ret = UAP_FAILURE;
int opt;
u8 ssid[33];
while ((opt = getopt_long(argc, argv, "+", cmd_options, NULL)) != -1) {
switch (opt) {
default:
print_sys_cfg_ssid_usage();
return;
}
}
argc -= optind;
argv += optind;
/* Check arguments */
if (argc > 1) {
printf("ERR:Too many arguments.\n");
print_sys_cfg_ssid_usage();
return;
}
if (argc == 0) {
/* Initialize the command length */
cmd_len =
sizeof(APCMDBUF_SYS_CONFIGURE) + sizeof(TLVBUF_SSID) +
MAX_SSID_LENGTH;
} else {
if (strlen(argv[0]) > MAX_SSID_LENGTH) {
printf("ERR:SSID too long.\n");
return;
}
/* Initialize the command length */
if (argv[0][1] == '"') {
argv[0]++;
}
if (argv[0][strlen(argv[0])] == '"') {
argv[0][strlen(argv[0])] = '\0';
}
if (!strlen(argv[0])) {
printf("ERR:NULL SSID not allowed.\n");
return;
}
cmd_len =
sizeof(APCMDBUF_SYS_CONFIGURE) + sizeof(TLVBUF_SSID) +
strlen(argv[0]);
}
/* Initialize the command buffer */
buffer = (u8 *) malloc(cmd_len);
if (!buffer) {
printf("ERR:Cannot allocate buffer for command!\n");
return;
}
bzero((char *) buffer, cmd_len);
/* Locate headers */
cmd_buf = (APCMDBUF_SYS_CONFIGURE *) buffer;
tlv = (TLVBUF_SSID *) (buffer + sizeof(APCMDBUF_SYS_CONFIGURE));
/* Fill the command buffer */
cmd_buf->CmdCode = APCMD_SYS_CONFIGURE;
cmd_buf->Size = cmd_len;
cmd_buf->SeqNum = 0;
cmd_buf->Result = 0;
tlv->Tag = MRVL_SSID_TLV_ID;
if (argc == 0) {
cmd_buf->Action = ACTION_GET;
tlv->Length = MAX_SSID_LENGTH;
} else {
cmd_buf->Action = ACTION_SET;
tlv->Length = strlen(argv[0]);
memcpy(tlv->Ssid, argv[0], tlv->Length);
}
endian_convert_tlv_header_out(tlv);
/* Send the command */
ret = uap_ioctl((u8 *) cmd_buf, &cmd_len, cmd_len);
endian_convert_tlv_header_in(tlv);
/* Process response */
if (ret == UAP_SUCCESS) {
/* Verify response */
if ((cmd_buf->CmdCode != (APCMD_SYS_CONFIGURE | APCMD_RESP_CHECK)) ||
(tlv->Tag != MRVL_SSID_TLV_ID)) {
printf("ERR:Corrupted response! CmdCode=%x, Tlv->Tag=%x\n",
cmd_buf->CmdCode, tlv->Tag);
free(buffer);
return;
}
/* Print response */
if (cmd_buf->Result == CMD_SUCCESS) {
if (argc == 0) {
memset(ssid, 0, sizeof(ssid));
memcpy(ssid, tlv->Ssid, tlv->Length);
printf("SSID = %s\n", ssid);
} else {
printf("SSID setting successful\n");
}
} else {
if (argc == 0) {
printf("ERR:Could not get SSID!\n");
} else {
printf("ERR:Could not set SSID!\n");
}
}
} else {
printf("ERR:Command sending failed!\n");
}
if (buffer)
free(buffer);
return;
}
/**
* @brief Creates a sys_cfg request for beacon period
* and sends to the driver
*
* Usage: "sys_cfg_beacon_period [BEACON_PERIOD]"
* if BEACON_PERIOD is provided, a 'set' is performed
* else a 'get' is performed.
*
* BEACON_PERIOD is represented in ms
*
* @param argc Number of arguments
* @param argv Pointer to the arguments
* @return N/A
*/