forked from idor/ti-utils
-
Notifications
You must be signed in to change notification settings - Fork 13
/
plt.c
1353 lines (1069 loc) · 32.1 KB
/
plt.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
/*
* PLT utility for wireless chip supported by TI's driver wl12xx
*
* See README and COPYING for more details.
*/
#include <sys/ioctl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <netlink/msg.h>
#include <netlink/attr.h>
#include <linux/wireless.h>
#include <linux/ethtool.h>
#include "nl80211.h"
#include "calibrator.h"
#include "plt.h"
#include "ini.h"
#include "nvs.h"
#define ZERO_MAC "00:00:00:00:00:00"
#ifndef SIOCETHTOOL
#define SIOCETHTOOL 0x8946
#endif
SECTION(plt);
#define CMDBUF_SIZE 200
static int insmod(char *filename)
{
int ret;
char cmd[CMDBUF_SIZE];
snprintf(cmd, CMDBUF_SIZE, "%s %s", INSMOD_PATH, filename);
ret = system(cmd);
if (ret)
fprintf(stderr, "Failed to load kernel module using command %s\n", cmd);
return ret;
}
static int rmmod(char *name)
{
char cmd[CMDBUF_SIZE];
char *tmp;
int i, ret;
/* "basename" */
tmp = strrchr(name, '/');
if (!tmp)
tmp = name;
else
tmp++;
tmp = strdup(tmp);
if (!tmp)
return -ENOMEM;
/* strip trailing .ko if there */
i = strlen(tmp);
if (i < 4) {
ret = -EINVAL;
goto out;
}
if (!strcmp(tmp + i - 3, ".ko"))
tmp[i-3] = 0;
snprintf(cmd, CMDBUF_SIZE, "%s %s", RMMOD_PATH, tmp);
ret = system(cmd);
if (ret)
fprintf(stderr, "Failed to remove kernel module using command %s\n", cmd);
out:
free(tmp);
return ret;
}
static void str2mac(unsigned char *pmac, char *pch)
{
int i;
for (i = 0; i < MAC_ADDR_LEN; i++) {
pmac[i] = (unsigned char)strtoul(pch, &pch, 16);
pch++;
}
}
static int plt_power_mode(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
unsigned int pmode;
if (argc != 1) {
fprintf(stderr, "%s> Missing arguments\n", __func__);
return 2;
}
if (strcmp(argv[0], "on") == 0)
pmode = 1;
else if (strcmp(argv[0], "off") == 0)
pmode = 0;
else {
fprintf(stderr, "%s> Invalid parameter\n", __func__);
return 2;
}
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "%s> fail to nla_nest_start()\n", __func__);
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_SET_PLT_MODE);
NLA_PUT_U32(msg, WL1271_TM_ATTR_PLT_MODE, pmode);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, power_mode, "<on|off>",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_power_mode,
"Set PLT power mode\n");
static int plt_tune_channel(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_cal_channel_tune prms;
if (argc < 1 || argc > 2)
return 1;
prms.test.id = TEST_CMD_CHANNEL_TUNE;
prms.band = (unsigned char)atoi(argv[0]);
prms.channel = (unsigned char)atoi(argv[1]);
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA,
sizeof(struct wl1271_cmd_cal_channel_tune),
&prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, tune_channel, "<band> <channel>",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_tune_channel,
"Set band and channel for PLT\n");
static int plt_ref_point(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_cal_update_ref_point prms;
if (argc < 1 || argc > 3)
return 1;
prms.test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
prms.ref_detector = atoi(argv[0]);
prms.ref_power = atoi(argv[1]);
prms.sub_band = atoi(argv[2]);
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, ref_point, "<voltage> <power> <subband>",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_ref_point,
"Set reference point for PLT\n");
static int calib_valid_handler(struct nl_msg *msg, void *arg)
{
struct nlattr *tb[NL80211_ATTR_MAX + 1];
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
struct nlattr *td[WL1271_TM_ATTR_MAX + 1];
struct wl1271_cmd_cal_p2g *prms;
#if 0
int i; unsigned char *pc;
#endif
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
if (!tb[NL80211_ATTR_TESTDATA]) {
fprintf(stderr, "no data!\n");
return NL_SKIP;
}
nla_parse(td, WL1271_TM_ATTR_MAX, nla_data(tb[NL80211_ATTR_TESTDATA]),
nla_len(tb[NL80211_ATTR_TESTDATA]), NULL);
prms = (struct wl1271_cmd_cal_p2g *)nla_data(td[WL1271_TM_ATTR_DATA]);
if (prms->radio_status) {
fprintf(stderr, "Fail to calibrate ith radio status (%d)\n",
(signed short)prms->radio_status);
return 2;
}
#if 0
printf("%s> id %04x status %04x\ntest id %02x ver %08x len %04x=%d\n",
__func__,
prms->header.id, prms->header.status, prms->test.id,
prms->ver, prms->len, prms->len);
pc = (unsigned char *)prms->buf;
printf("++++++++++++++++++++++++\n");
for (i = 0; i < prms->len; i++) {
if (i%0xf == 0)
printf("\n");
printf("%02x ", *(unsigned char *)pc);
pc += 1;
}
printf("++++++++++++++++++++++++\n");
#endif
printf("Writing calibration data to %s\n", (char*) arg);
if (prepare_nvs_file(prms, arg)) {
fprintf(stderr, "Fail to prepare calibrated NVS file\n");
return 2;
}
#if 0
printf("\n\tThe NVS file (%s) is ready\n\tCopy it to %s and "
"reboot the system\n\n",
NEW_NVS_NAME, CURRENT_NVS_NAME);
#endif
return NL_SKIP;
}
static void dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs)
{
printf("\n\tDriver %s\n\t"
"version %s\n\t"
"FW version %s\n\t"
"Bus info %s\n\t"
"HW version 0x%X\n",
info->driver, info->version,
info->fw_version, info->bus_info, regs->version);
}
int do_get_drv_info(char *dev_name, int *hw_ver)
{
struct ifreq ifr;
int fd, err;
struct ethtool_drvinfo drvinfo;
struct ethtool_regs *regs;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, dev_name);
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
fprintf(stderr, "Cannot get control socket\n");
return 1;
}
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr.ifr_data = (caddr_t)&drvinfo;
err = ioctl(fd, SIOCETHTOOL, &ifr);
if (err < 0) {
fprintf(stderr, "Cannot get driver information\n");
goto error_out;
}
regs = calloc(1, sizeof(*regs)+drvinfo.regdump_len);
if (!regs) {
fprintf(stderr, "Cannot allocate memory for register dump\n");
goto error_out;
}
regs->cmd = ETHTOOL_GREGS;
regs->len = drvinfo.regdump_len;
ifr.ifr_data = (caddr_t)regs;
err = ioctl(fd, SIOCETHTOOL, &ifr);
if (err < 0) {
fprintf(stderr, "Cannot get register dump\n");
goto error_out2;
}
if (hw_ver)
*hw_ver = regs->version;
else
dump_regs(&drvinfo, regs);
free(regs);
return 0;
error_out2:
free(regs);
error_out:
close(fd);
return 1;
}
static int get_chip_arch(char *dev_name, enum wl12xx_arch *arch)
{
int hw_ver, ret;
ret = do_get_drv_info(dev_name, &hw_ver);
if (ret)
return 1;
*arch = hw_ver >> 16;
return 0;
}
static int do_nvs_ver21(struct nl_msg *msg, enum wl12xx_arch arch)
{
struct nlattr *key;
struct wl1271_cmd_set_nvs_ver prms;
memset(&prms, 0, sizeof(struct wl1271_cmd_set_nvs_ver));
if (arch == WL1271_ARCH)
prms.test.id = TEST_CMD_SET_NVS_VERSION;
else if(arch == WL128X_ARCH)
prms.test.id = TEST_CMD_SET_NVS_VERSION - 1;
else {
fprintf(stderr, "Unkown arch %x\n", arch);
return 1;
}
prms.nvs_ver = NVS_VERSION_2_1;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
static int plt_nvs_ver(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
enum wl12xx_arch arch = UNKNOWN_ARCH;
int ret;
if (argc < 1) {
fprintf(stderr, "Missing device name\n");
return 2;
}
ret = get_chip_arch(argv[0], &arch);
if (ret || (arch == UNKNOWN_ARCH)) {
fprintf(stderr, "Unknown chip arch\n");
return 2;
}
return do_nvs_ver21(msg, arch);
}
COMMAND(plt, nvs_ver, "<device name>",
NL80211_CMD_TESTMODE, 0, CIB_PHY, plt_nvs_ver,
"Set NVS version\n");
static int plt_nvs_ver2(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
enum wl12xx_arch arch = UNKNOWN_ARCH;
int ret;
if (argc < 1) {
fprintf(stderr, "Missing device name\n");
return 2;
}
ret = sscanf(argv[0], "%x", &arch);
if(ret != 1) {
fprintf(stderr, "Unknown chip arch\n");
return 2;
}
return do_nvs_ver21(msg, arch);
}
COMMAND(plt, nvs_ver, "<arch>",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_nvs_ver2,
"Set NVS version\n");
static int plt_tx_bip(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_cal_p2g prms;
int i;
char nvs_path[PATH_MAX];
if (argc < 8) {
fprintf(stderr, "%s> Missing arguments\n", __func__);
return 2;
}
if (argc > 8)
strncpy(nvs_path, argv[8], strlen(argv[8]));
else
nvs_path[0] = '\0';
memset(&prms, 0, sizeof(struct wl1271_cmd_cal_p2g));
prms.test.id = TEST_CMD_P2G_CAL;
for (i = 0; i < 8; i++)
prms.sub_band_mask |= (atoi(argv[i]) & 0x1)<<i;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
NLA_PUT_U8(msg, WL1271_TM_ATTR_ANSWER, 1);
nla_nest_end(msg, key);
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, calib_valid_handler, nvs_path);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, tx_bip,
"<0|1> <0|1> <0|1> <0|1> <0|1> <0|1> <0|1> <0|1> [<nvs file>]",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_tx_bip,
"Do calibrate\n");
static int plt_tx_tone(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_cal_tx_tone prms;
if (argc < 2) {
fprintf(stderr, "%s> Missing arguments\n", __func__);
return 2;
}
memset(&prms, 0, sizeof(struct wl1271_cmd_cal_tx_tone));
prms.test.id = TEST_CMD_TELEC;
prms.tone_type = atoi(argv[0]);
if (prms.tone_type < 1 || prms.tone_type > 2) {
fprintf(stderr, "%s> Invalit tone type parameter %d\n",
__func__, prms.tone_type);
return 2;
}
prms.power = atoi(argv[1]);
if (prms.power > 10000) {
fprintf(stderr, "%s> Invalit power parameter %d\n",
__func__, prms.power);
return 2;
}
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, tx_tone, "<tone type 1|2> <power 0 - 10000>",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_tx_tone,
"Do command tx_tone to transmit a tone\n");
static int plt_tx_cont(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_pkt_params prms = {
.src_mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};
if (argc != 15)
return 1;
#if 0
printf("%s> delay (%d) rate (%08x) size (%d) amount (%d) power (%d) "
"seed (%d) pkt_mode (%d) DCF (%d) GI (%d) preamble (%d) type "
"(%d) scramble (%d) CLPC (%d), SeqNbrMode (%d) DestMAC (%s)\n",
__func__,
atoi(argv[0]), atoi(argv[1]), atoi(argv[2]), atoi(argv[3]),
atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]),
atoi(argv[8]), atoi(argv[9]), atoi(argv[10]), atoi(argv[11]),
atoi(argv[12]), atoi(argv[13]), argv[14]
);
#endif
memset((void *)&prms, 0, sizeof(struct wl1271_cmd_pkt_params));
prms.test.id = TEST_CMD_FCC;
prms.delay = atoi(argv[0]);
prms.rate = strtol(argv[1], NULL, 0);
prms.size = (unsigned short)atoi(argv[2]);
prms.amount = (unsigned short)atoi(argv[3]);
prms.power = atoi(argv[4]);
prms.seed = (unsigned short)atoi(argv[5]);
prms.pkt_mode = (unsigned char)atoi(argv[6]);
prms.dcf_enable = (unsigned char)atoi(argv[7]);
prms.g_interval = (unsigned char)atoi(argv[8]);
prms.preamble = (unsigned char)atoi(argv[9]);
prms.type = (unsigned char)atoi(argv[10]);
prms.scramble = (unsigned char)atoi(argv[11]);
prms.clpc_enable = (unsigned char)atoi(argv[12]);
prms.seq_nbr_mode = (unsigned char)atoi(argv[13]);
str2mac(prms.dst_mac, argv[14]);
if (get_mac_addr(0, prms.src_mac))
fprintf(stderr, "fail to get MAC addr\n");
printf("%02X:%02X:%02X:%02X:%02X:%02X\n",
prms.src_mac[0], prms.src_mac[1], prms.src_mac[2],
prms.src_mac[3], prms.src_mac[4], prms.src_mac[5]);
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, tx_cont, "<delay> <rate> <size> <amount> <power>\n\t\t<seed> "
"<pkt mode> <DC on/off> <gi> <preamble>\n\t\t<type> <scramble> "
"<clpc> <seq nbr mode> <dest mac>",
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_tx_cont,
"Start Tx Cont\n");
static int plt_tx_stop(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_pkt_params prms;
prms.test.id = TEST_CMD_STOP_TX;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "fail to nla_nest_start()\n");
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, tx_stop, NULL,
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_tx_stop,
"Stop Tx Cont\n");
static int plt_start_rx_statcs(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_pkt_params prms;
prms.test.id = TEST_CMD_RX_STAT_START;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "%s> fail to nla_nest_start()\n", __func__);
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, start_rx_statcs, NULL,
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_start_rx_statcs,
"Start Rx statistics collection\n");
static int plt_stop_rx_statcs(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_pkt_params prms;
prms.test.id = TEST_CMD_RX_STAT_STOP;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "%s> fail to nla_nest_start()\n", __func__);
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, stop_rx_statcs, NULL,
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_stop_rx_statcs,
"Stop Rx statistics collection\n");
static int plt_reset_rx_statcs(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_cmd_pkt_params prms;
prms.test.id = TEST_CMD_RX_STAT_RESET;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "%s> fail to nla_nest_start()\n", __func__);
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
nla_nest_end(msg, key);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, reset_rx_statcs, NULL,
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_reset_rx_statcs,
"Reset Rx statistics collection\n");
static int display_rx_statcs(struct nl_msg *msg, void *arg)
{
struct nlattr *tb[NL80211_ATTR_MAX + 1];
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
struct nlattr *td[WL1271_TM_ATTR_MAX + 1];
struct wl1271_radio_rx_statcs *prms;
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
if (!tb[NL80211_ATTR_TESTDATA]) {
fprintf(stderr, "no data!\n");
return NL_SKIP;
}
nla_parse(td, WL1271_TM_ATTR_MAX, nla_data(tb[NL80211_ATTR_TESTDATA]),
nla_len(tb[NL80211_ATTR_TESTDATA]), NULL);
prms =
(struct wl1271_radio_rx_statcs *)
nla_data(td[WL1271_TM_ATTR_DATA]);
printf("\n\tTotal number of pkts\t- %d\n\tAccepted pkts\t\t- %d\n\t"
"FCS error pkts\t\t- %d\n\tAddress mismatch pkts\t- %d\n\t"
"Average SNR\t\t- % d dBm\n\tAverage RSSI\t\t- % d dBm\n\n",
prms->base_pkt_id, prms->rx_path_statcs.nbr_rx_valid_pkts,
prms->rx_path_statcs.nbr_rx_fcs_err_pkts,
prms->rx_path_statcs.nbr_rx_plcp_err_pkts,
(signed short)prms->rx_path_statcs.ave_snr/8,
(signed short)prms->rx_path_statcs.ave_rssi/8);
return NL_SKIP;
}
static int plt_get_rx_statcs(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
struct nlattr *key;
struct wl1271_radio_rx_statcs prms;
prms.test.id = TEST_CMD_RX_STAT_GET;
key = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
if (!key) {
fprintf(stderr, "%s> fail to nla_nest_start()\n", __func__);
return 1;
}
NLA_PUT_U32(msg, WL1271_TM_ATTR_CMD_ID, WL1271_TM_CMD_TEST);
NLA_PUT(msg, WL1271_TM_ATTR_DATA, sizeof(prms), &prms);
NLA_PUT_U8(msg, WL1271_TM_ATTR_ANSWER, 1);
nla_nest_end(msg, key);
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, display_rx_statcs, NULL);
/* Important: needed gap between tx_start and tx_get */
sleep(2);
return 0;
nla_put_failure:
fprintf(stderr, "%s> building message failed\n", __func__);
return 2;
}
COMMAND(plt, get_rx_statcs, NULL,
NL80211_CMD_TESTMODE, 0, CIB_NETDEV, plt_get_rx_statcs,
"Get Rx statistics\n");
static int plt_rx_statistics(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
int ret;
/* power mode on */
{
char *prms[4] = { "wlan0", "plt", "power_mode", "on" };
ret = handle_cmd(state, II_NETDEV, 4, prms);
if (ret < 0) {
fprintf(stderr, "Fail to set PLT power mode on\n");
return 1;
}
}
/* start_rx_statcs */
{
char *prms[3] = { "wlan0", "plt", "start_rx_statcs" };
ret = handle_cmd(state, II_NETDEV, 3, prms);
if (ret < 0) {
fprintf(stderr, "Fail to start Rx statistics\n");
goto fail_out;
}
}
/* get_rx_statcs */
{
int err;
char *prms[3] = { "wlan0", "plt", "get_rx_statcs" };
err = handle_cmd(state, II_NETDEV, 3, prms);
if (err < 0) {
fprintf(stderr, "Fail to get Rx statistics\n");
ret = err;
}
}
/* stop_rx_statcs */
{
int err;
char *prms[3] = { "wlan0", "plt", "stop_rx_statcs" };
err = handle_cmd(state, II_NETDEV, 3, prms);
if (err < 0) {
fprintf(stderr, "Fail to stop Rx statistics\n");
ret = err;
}
}
fail_out:
/* power mode off */
{
int err;
char *prms[4] = { "wlan0", "plt", "power_mode", "off"};
err = handle_cmd(state, II_NETDEV, 4, prms);
if (err < 0) {
fprintf(stderr, "Fail to set PLT power mode on\n");
return 1;
}
}
if (ret < 0)
return 1;
return 0;
}
COMMAND(plt, rx_statistics, NULL, 0, 0, CIB_NONE, plt_rx_statistics,
"Get Rx statistics\n");
static int plt_do_power_on(struct nl80211_state *state, char *devname)
{
int err;
char *pm_on[4] = { devname, "plt", "power_mode", "on" };
err = handle_cmd(state, II_NETDEV, ARRAY_SIZE(pm_on), pm_on);
if (err < 0)
fprintf(stderr, "Fail to set PLT power mode on\n");
return err;
}
static int plt_do_power_off(struct nl80211_state *state, char *devname)
{
int err;
char *prms[4] = { devname, "plt", "power_mode", "off"};
err = handle_cmd(state, II_NETDEV, ARRAY_SIZE(prms), prms);
if (err < 0)
fprintf(stderr, "Failed to set PLT power mode on\n");
return err;
}
static int plt_do_calibrate(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int single_dual, char *nvs_file,
char *devname, enum wl12xx_arch arch)
{
int ret = 0, err;
/* tune channel */
{
char *tune[5] = {
devname, "plt", "tune_channel", "0", "7"
};
err = handle_cmd(state, II_NETDEV, ARRAY_SIZE(tune), tune);
if (err < 0) {
fprintf(stderr, "Fail to tune channel\n");
ret = err;
goto fail_out;
}
}
/* Set nvs version 2.1 */
if (arch == UNKNOWN_ARCH) {
fprintf(stderr, "Unknown arch. Not setting nvs ver 2.1");
}
else {
size_t ret;
char archstr[5] = "";
char *prms[4] = {
"wlan0", "plt", "nvs_ver", archstr
};
ret = snprintf(archstr, sizeof(archstr), "%x", arch);
if (ret > sizeof(archstr)) {
fprintf(stderr, "Bad arch\n");
goto fail_out;
}
printf("Using nvs version 2.1\n");
err = handle_cmd(state, II_NETDEV, 4, prms);
if (err < 0) {
fprintf(stderr, "Fail to set nvs ver 2.1\n");
ret = err;
}
}
/* calibrate it */
{
char *prms[12] = {
devname, "plt", "tx_bip", "1", "0", "0", "0",
"0", "0", "0", "0", nvs_file
};
printf("Calibrate %s\n", nvs_file);
/* set flags in case of dual band */
if (single_dual) {
prms[4] = prms[5] = prms[6] = prms[7] = prms[8] =
prms[9] = prms[10] = "1";
}
err = handle_cmd(state, II_NETDEV, ARRAY_SIZE(prms), prms);
if (err < 0) {
fprintf(stderr, "Failed to calibrate\n");
ret = err;
}
}
fail_out:
if (ret < 0)
return 1;
return 0;
}
static int plt_calibrate(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{
int ret, err;
int single_dual = 0;
if (argc > 2 && (strncmp(argv[2], "dual", 4) == 0))
single_dual = 1; /* going for dual band calibration */
else
single_dual = 0; /* going for single band calibration */
err = plt_do_power_on(state, "wlan0");
if (err < 0)
goto out;
err = plt_do_calibrate(state, cb, msg, single_dual, NEW_NVS_NAME,
"wlan0", UNKNOWN_ARCH);
ret = plt_do_power_off(state, "wlan0");
if (ret < 0)
err = ret;
out:
return err;
}
COMMAND(plt, calibrate, "[<single|dual>]", 0, 0, CIB_NONE,
plt_calibrate, "Do calibrate for single or dual band chip\n");
static int plt_autocalibrate(struct nl80211_state *state, struct nl_cb *cb,
struct nl_msg *msg, int argc, char **argv)
{