-
Notifications
You must be signed in to change notification settings - Fork 2
/
testmode.c
1431 lines (1195 loc) · 41.1 KB
/
testmode.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
/*
* Copyright (c) 2011-2014 Espressif System.
*
* test mode
*/
#ifdef TEST_MODE
#include <linux/kernel.h>
#include <linux/etherdevice.h>
#include <linux/workqueue.h>
#include <linux/completion.h>
#include <linux/nl80211.h>
#include <linux/ieee80211.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/mmc/host.h>
#include <net/cfg80211.h>
#include <net/mac80211.h>
#include <net/genetlink.h>
#include "esp_pub.h"
#include "esp_sip.h"
#include "esp_ctrl.h"
#include "esp_sif.h"
#include "esp_debug.h"
#include "esp_wl.h"
#include "testmode.h"
#include "esp_path.h"
#include "esp_file.h"
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
#include <net/regulatory.h>
#endif
static int queue_flag = 0;
static u32 connected_nl;
static struct genl_info info_copy;
static struct esp_sip *sip_copy = NULL;
static u8 *sdio_buff = NULL;
static struct sdiotest_param sdioTest;
static u8 *sdiotest_buf = NULL;
#define SIP sip_copy
#define OUT_DONE() \
do { \
printk(KERN_DEBUG "esp_sdio: error occured in %s\n", __func__); \
} while(0)
/* ESP TEST netlinf family */
static struct genl_family test_genl_family = {
.id = GENL_ID_GENERATE,
.hdrsize = 0,
.name = "esp_sdio",
.version = 1,
.maxattr = TEST_ATTR_MAX,
};
struct loopback_param_s {
u32 packet_num;
u32 packet_id;
};
static struct loopback_param_s loopback_param;
u32 get_loopback_num()
{
return loopback_param.packet_num;
}
u32 get_loopback_id()
{
return loopback_param.packet_id;
}
void inc_loopback_id()
{
loopback_param.packet_id++;
}
#define REGISTER_REPLY(info) \
memcpy((char *)&info_copy, (char *)(info), sizeof(struct genl_info))
static void sip_send_test_cmd(struct esp_sip *sip, struct sk_buff *skb)
{
if (queue_flag == 0)
skb_queue_tail(&sip->epub->txq, skb);
else
skb_queue_head(&sip->epub->txq, skb);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
if(sif_get_ate_config() == 0){
ieee80211_queue_work(sip->epub->hw, &sip->epub->tx_work);
} else {
queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
}
#else
queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
#endif
}
static int esp_test_cmd_reply(struct genl_info *info, u32 cmd_type, char *reply_info)
{
struct sk_buff *skb;
void *hdr;
/*directly send ask_info to target, and waiting for report*/
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (skb == NULL)
goto out;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
hdr = genlmsg_put(skb, info->snd_portid, info->snd_seq, &test_genl_family, 0, cmd_type);
#else
hdr = genlmsg_put(skb, info->snd_pid, info->snd_seq, &test_genl_family, 0, cmd_type);
#endif
if (hdr == NULL)
goto nla_put_failure;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
nla_put_string(skb, TEST_ATTR_STR, reply_info);
#else
NLA_PUT_STRING(skb, TEST_ATTR_STR, reply_info);
#endif
genlmsg_end(skb, hdr);
genlmsg_reply(skb, info);
return 0;
nla_put_failure:
nlmsg_free(skb);
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_echo(struct sk_buff *skb_2,
struct genl_info *info)
{
char *echo_info;
int res;
if (info == NULL)
goto out;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
connected_nl = info->snd_portid;
printk(KERN_DEBUG "esp_sdio: received a echo, "
"from portid %d\n", info->snd_portid);
#else
connected_nl = info->snd_pid;
esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a echo, "
"from pid %d\n", info->snd_pid);
#endif
sip_debug_show(SIP);
/*get echo info*/
echo_info = nla_data(info->attrs[TEST_ATTR_STR]);
if (strncmp(echo_info, "queue_head", 10) == 0) {
esp_dbg(ESP_DBG_ERROR, "echo : change to queue head");
queue_flag = 1;
}
if (strncmp(echo_info, "queue_tail", 10) == 0) {
esp_dbg(ESP_DBG_ERROR, "echo : change to queue head");
queue_flag = 0;
}
res=esp_test_cmd_reply(info, TEST_CMD_ECHO, echo_info);
return res;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_sdiospeed(struct sk_buff *skb_2,
struct genl_info *info)
{
char *speed_info;
int res;
if (info == NULL)
goto out;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
connected_nl = info->snd_portid;
#else
connected_nl = info->snd_pid;
#endif
/*get echo info*/
speed_info = nla_data(info->attrs[TEST_ATTR_STR]);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a sdio speed %s, "
"from portid %d\n", speed_info, info->snd_portid);
#else
esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a sdio speed %s, "
"from pid %d\n", speed_info, info->snd_pid);
#endif
if (!strcmp(speed_info, "high")) {
sif_platform_target_speed(1);
} else if (!strcmp(speed_info, "low")) {
sif_platform_target_speed(0);
} else {
esp_dbg(ESP_DBG_ERROR, "%s: %s unsupported\n", __func__, speed_info);
}
res=esp_test_cmd_reply(info, TEST_CMD_SDIOSPEED, speed_info);
return res;
out:
OUT_DONE();
return -EINVAL;
}
static void * ate_done_data;
static char ate_reply_str[128];
void esp_test_ate_done_cb(char *ep)
{
memset(ate_reply_str, 0, sizeof(ate_reply_str));
strcpy(ate_reply_str, ep);
esp_dbg(ESP_DBG_ERROR, "%s %s\n", __func__, ate_reply_str);
if (ate_done_data)
complete(ate_done_data);
}
static int esp_test_ate(struct sk_buff *skb_2,
struct genl_info *info)
{
char *ate_info = NULL;
u16 len = 0;
int res = 0;
struct sk_buff *skb;
char *str;
bool stop_sdt = false;
DECLARE_COMPLETION_ONSTACK(complete);
if (info == NULL)
goto out;
ate_done_data = &complete;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
connected_nl = info->snd_portid;
#else
connected_nl = info->snd_pid;
#endif
//esp_dbg(ESP_DBG_ERROR, "esp_sdio: received a ate cmd, "
// "from pid %d\n", info->snd_pid);
/*get echo info*/
ate_info = nla_data(info->attrs[TEST_ATTR_STR]);
if (!ate_info)
goto out;
len = nla_len(info->attrs[TEST_ATTR_STR]);
//esp_dbg(ESP_DBG_ERROR, "%s str %s len %d cmd %d\n", __func__, ate_info, len, SIP_CMD_ATE);
skb = sip_alloc_ctrl_skbuf(SIP, (sizeof(struct sip_hdr)+len), SIP_CMD_ATE);
if (!skb)
goto out;
//atecmd = (struct sip_cmd_ate*)(skb->data + sizeof(struct sip_hdr));
str = (char *)(skb->data + sizeof(struct sip_hdr));
//atecmd->len = len;
strcpy(str, ate_info);
//esp_dbg(ESP_DBG_ERROR, "%s cmdstr %s \n", __func__, str);
if (atomic_read(&sdioTest.start)) {
atomic_set(&sdioTest.start, 0);
stop_sdt = true;
msleep(10);
//esp_dbg(ESP_DBG_ERROR, "%s stop sdt \n", __func__);
}
sip_send_test_cmd(SIP, skb);
//esp_dbg(ESP_DBG_ERROR, "%s sent cmd \n", __func__);
wait_for_completion(&complete);
//esp_dbg(ESP_DBG_ERROR, "%s completed \n", __func__);
esp_test_cmd_reply(info, TEST_CMD_ATE, ate_reply_str);
if (stop_sdt) {
//esp_dbg(ESP_DBG_ERROR, "%s restart sdt \n", __func__);
atomic_set(&sdioTest.start, 1);
wake_up_process(sdioTest.thread);
}
return res;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_process_sdio_test(struct sdiotest_param *param)
{
//#define sdiotest_BASE_ADDR 0x7f80 //MAC 5.0
#define SDIOTEST_FLAG_ADDR 0xc000
#define SDIOTEST_BASE_ADDR (SDIOTEST_FLAG_ADDR+4) //MAC 6.0
#define SDIO_BUF_SIZE (16*1024-4)
int ret = 0;
static int counter = 0;
//esp_dbg(ESP_DBG_ERROR, "idle_period %d mode %d addr 0x%08x\n", param->idle_period,
// param->mode, param->addr);
if (sdioTest.mode == 1) { //read mode
ret = esp_common_read_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, SDIO_BUF_SIZE, ESP_SIF_SYNC);
} else if ((sdioTest.mode >= 3)&&(sdioTest.mode <= 7)) { //write mode
ret = esp_common_write_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, SDIO_BUF_SIZE, ESP_SIF_SYNC);
/*
} else if (sdioTest.mode == 3) { //read & write mode
ret = esp_common_read_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, 16*1024, ESP_SIF_SYNC);
sdiotest_buf[0]++;
ret = esp_common_write_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, 16*1024, ESP_SIF_SYNC);
*/
} else if (sdioTest.mode == 2) { //byte read mode(to test sdio_cmd)
ret = esp_common_read_with_addr(SIP->epub, SDIOTEST_BASE_ADDR, sdiotest_buf, 8, ESP_SIF_SYNC);
}
if (sdioTest.idle_period > 1000) {
show_buf(sdiotest_buf, 128);
} else if (sdioTest.idle_period == 0) {
if (sdioTest.mode == 1) {//read mode
if (!(counter++%5000)) {
esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
}
} else if (sdioTest.mode == 2) { //byte read mode
if (!(counter++%5000)) {
esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
}
} else {//write mode
//msleep(3);
if (!(counter++%30000)) {
esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
}
}
} else {
if (!(counter++%1000)) {
esp_dbg(ESP_DBG_ERROR, "%s %d\n", __func__, counter);
}
}
if (ret)
esp_dbg(ESP_DBG_ERROR, "%s mode %d err %d \n", __func__, sdioTest.mode, ret);
return ret;
}
static int esp_test_sdiotest_thread(void *param)
{
struct sdiotest_param *testParam = (struct sdiotest_param *)param;
struct sched_param schedParam = { .sched_priority = 1 };
unsigned long idle_period = MAX_SCHEDULE_TIMEOUT;
int ret = 0;
sched_setscheduler(current, SCHED_FIFO, &schedParam);
while (!kthread_should_stop()) {
if (0 == atomic_read(&testParam->start)) {
esp_dbg(ESP_DBG_ERROR, "%s suspend\n", __func__);
set_current_state(TASK_INTERRUPTIBLE);
if (!kthread_should_stop())
schedule_timeout(MAX_SCHEDULE_TIMEOUT);
set_current_state(TASK_RUNNING);
}
if (testParam->idle_period)
idle_period = msecs_to_jiffies(testParam->idle_period);
else
idle_period = 0;
ret = esp_process_sdio_test(testParam);
/*
* Give other threads a chance to run in the presence of
* errors.
*/
if (ret < 0) {
set_current_state(TASK_INTERRUPTIBLE);
if (!kthread_should_stop())
schedule_timeout(2*HZ);
set_current_state(TASK_RUNNING);
atomic_set(&testParam->start, 0);
}
//esp_dbg(ESP_DBG_ERROR, "%s idle_period %lu\n", __func__, idle_period);
if (idle_period) {
set_current_state(TASK_INTERRUPTIBLE);
if (!kthread_should_stop()) {
schedule_timeout(idle_period);
}
set_current_state(TASK_RUNNING);
}
};
esp_dbg(ESP_DBG_ERROR, "%s exit\n", __func__);
return ret;
}
static int esp_test_sdiotest(struct sk_buff *skb_2,
struct genl_info *info)
{
int res = 0;
char reply_str[32];
u32 start = 0;
int para_num = 0;
int i;
u32 data_mask = 0xffffffff;
u8 * sdio_test_flag = NULL;
int ret = 0;
bool stop_sdt = false;
if (info == NULL)
goto out;
start = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
esp_dbg(ESP_DBG_ERROR, "%s start 0x%08x\n", __func__, start);
para_num = start & 0xf;
start >>= 31;
if (!start)
goto _turnoff;
esp_dbg(ESP_DBG_ERROR, "%s paranum %d start %u\n", __func__, para_num, start);
para_num--;
do {
if ((para_num--) > 0) {
sdioTest.mode = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
if ((sdioTest.mode >= 3)&&(sdioTest.mode <= 7)) { // write mode, fill the test buf
data_mask = (sdioTest.mode == 3)? 0xffffffff : (0x11111111<<(sdioTest.mode-4));
for (i = 0; i<SDIO_BUF_SIZE/ 4; i++) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
*(u32 *)&sdiotest_buf[i*4] = get_random_int() & data_mask;
#else
*(u32 *)&sdiotest_buf[i*4] = random32() & data_mask;
#endif
}
}
esp_dbg(ESP_DBG_ERROR, "%s mode %d \n", __func__, sdioTest.mode);
}
if ((para_num--) > 0) {
sdioTest.addr = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
esp_dbg(ESP_DBG_ERROR, "%s addr 0x%x \n", __func__, sdioTest.addr);
}
if ((para_num--) > 0) {
sdioTest.idle_period = nla_get_u32(info->attrs[TEST_ATTR_PARA3]);
esp_dbg(ESP_DBG_ERROR, "%s idle_period %u \n", __func__, sdioTest.idle_period);
}
} while (0);
esp_test_cmd_reply(info, TEST_CMD_SDIOTEST, reply_str);
msleep(10);
#if 1
if (start == 1) {
//esp_dbg(ESP_DBG_ERROR, "%s start== 1\n", __func__);
if((sdioTest.mode == 8)|(sdioTest.mode == 9)) {
if (atomic_read(&sdioTest.start)) {
atomic_set(&sdioTest.start, 0);
stop_sdt = true;
msleep(10);
}
sdio_test_flag = kzalloc(4, GFP_KERNEL);
if (sdio_test_flag == NULL) {
esp_dbg(ESP_DBG_ERROR, "no mem for sdio_tst_flag!!\n");
goto out;
}
if(sdioTest.mode == 8){
ret = esp_common_read_with_addr(SIP->epub, sdioTest.addr, sdio_test_flag, 4, ESP_SIF_SYNC);
esp_dbg(ESP_DBG_ERROR, "%s sdio read: 0x%x 0x%x\n", __func__, sdioTest.addr, *(u32 *)sdio_test_flag);
}else{
*(u32 *)sdio_test_flag = sdioTest.idle_period;
ret = esp_common_write_with_addr(SIP->epub, sdioTest.addr, sdio_test_flag, 4, ESP_SIF_SYNC);
esp_dbg(ESP_DBG_ERROR, "%s sdio : write 0x%x 0x%x done!\n", __func__, sdioTest.addr, *(u32 *)sdio_test_flag);
}
kfree(sdio_test_flag);
sdio_test_flag = NULL;
} else {
//set flag to inform firmware sdio-test start
sdio_test_flag = kzalloc(4, GFP_KERNEL);
if (sdio_test_flag == NULL) {
esp_dbg(ESP_DBG_ERROR, "no mem for sdio_tst_flag!!\n");
goto out;
}
*(u32 *)sdio_test_flag = 0x56781234;
if (atomic_read(&sdioTest.start)) {
atomic_set(&sdioTest.start, 0);
stop_sdt = true;
msleep(10);
//esp_dbg(ESP_DBG_ERROR, "%s stop sdt \n", __func__);
}
ret = esp_common_write_with_addr(SIP->epub, SDIOTEST_FLAG_ADDR, sdio_test_flag, 4, ESP_SIF_SYNC);
/*
if (stop_sdt) {
//esp_dbg(ESP_DBG_ERROR, "%s restart sdt \n", __func__);
atomic_set(&sdioTest.start, 1);
wake_up_process(sdioTest.thread);
}
*/
//esp_dbg(ESP_SHOW, "%s sdio_test_flag sent to target \n", __func__);
//esp_dbg(ESP_DBG_ERROR, "%s sdio_test_flag sent to target \n", __func__);
kfree(sdio_test_flag);
sdio_test_flag = NULL;
atomic_set(&sdioTest.start, 1);
if (sdioTest.thread == NULL) {
sdioTest.thread = kthread_run(esp_test_sdiotest_thread,
&sdioTest,
"kespsdiotestd");
} else {
wake_up_process(sdioTest.thread);
}
strcpy(reply_str, "sdt started\n");
}
} else {
//esp_dbg(ESP_DBG_ERROR, "%s start== 0\n", __func__);
_turnoff:
atomic_set(&sdioTest.start, 0);
strcpy(reply_str, "sdt stopped\n");
}
#endif
return res;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_ask(struct sk_buff *skb_2,
struct genl_info *info)
{
char *ask_info;
int res;
if (info == NULL)
goto out;
/*get echo info*/
ask_info = nla_data(info->attrs[TEST_ATTR_STR]);
/*directly send ask_info to target, and waiting for report*/
res=esp_test_cmd_reply(info, TEST_CMD_ASK, "ok");
return res;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_sleep(struct sk_buff *skb_2,
struct genl_info *info)
{
struct sip_cmd_sleep *sleepcmd;
struct sk_buff *skb = NULL;
int res;
if (info == NULL)
goto out;
skb = sip_alloc_ctrl_skbuf(SIP, sizeof(struct sip_cmd_sleep), SIP_CMD_SLEEP);
if (!skb)
goto out;
sleepcmd = (struct sip_cmd_sleep *)(skb->data + sizeof(struct sip_tx_info));
sleepcmd->sleep_mode = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
sleepcmd->sleep_tm_ms = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
sleepcmd->wakeup_tm_ms = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
sleepcmd->sleep_times = nla_get_u32(info->attrs[TEST_ATTR_PARA3]);
sip_send_test_cmd(SIP, skb);
/*directly send ask_info to target, and waiting for report*/
res=esp_test_cmd_reply(info, TEST_CMD_SLEEP, "ok");
return res;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_wakeup(struct sk_buff *skb_2,
struct genl_info *info)
{
struct sip_cmd_wakeup *wakeupcmd;
struct sk_buff *skb = NULL;
//int res;
if (info == NULL)
goto out;
skb = sip_alloc_ctrl_skbuf(SIP, sizeof(struct sip_cmd_wakeup), SIP_CMD_WAKEUP);
if (!skb)
goto out;
wakeupcmd = (struct sip_cmd_wakeup *)(skb->data + sizeof(struct sip_tx_info));
wakeupcmd->check_data = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
/*directly send reply_info to target, and waiting for report*/
REGISTER_REPLY(info);
//res=esp_test_cmd_reply(info, TEST_CMD_WAKEUP, "ok");
sip_send_test_cmd(SIP, skb);
return 0;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_loopback(struct sk_buff *skb_2,
struct genl_info *info)
{
u32 txpacket_len;
u32 rxpacket_len;
if (info == NULL)
goto out;
txpacket_len = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
rxpacket_len = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
loopback_param.packet_num = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
loopback_param.packet_id=0;
REGISTER_REPLY(info);
return sip_send_loopback_mblk(SIP, txpacket_len, rxpacket_len, 0);
out:
OUT_DONE();
return -EINVAL;
}
/*
u8 probe_req_frm[] = {0x40,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x03,0x8F,0x11,0x22,0x88,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x01,0x08,0x82,0x84,0x8B,0x96,
0x0C,0x12,0x18,0x24,0x32,0x04,0x30,0x48,0x60,0x6C
};
*/
static int sip_send_tx_frame(struct esp_sip *sip, u32 packet_len)
{
struct sk_buff *skb = NULL;
u8 *ptr = NULL;
int i;
skb = alloc_skb(packet_len, GFP_KERNEL);
skb->len = packet_len;
ptr = skb->data;
/* fill up pkt payload */
for (i = 0; i < skb->len; i++) {
ptr[i] = i;
}
if(sif_get_ate_config() == 0){
sip_tx_data_pkt_enqueue(sip->epub, skb);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
ieee80211_queue_work(sip->epub->hw, &sip->epub->tx_work);
#else
queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
#endif
} else {
skb_queue_tail(&sip->epub->txq, skb);
queue_work(sip->epub->esp_wkq, &sip->epub->tx_work);
}
return 0;
}
static int esp_test_tx(struct sk_buff *skb_2,
struct genl_info *info)
{
u32 txpacket_len;
u32 res;
if (info == NULL)
goto out;
txpacket_len = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
REGISTER_REPLY(info);
sip_send_tx_frame(SIP, txpacket_len);
res=esp_test_cmd_reply(info, TEST_CMD_TX, "tx out");
return res;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_genl(struct sk_buff *skb_2,
struct genl_info *info)
{
struct sip_cmd_debug *dbgcmd;
struct sk_buff *skb = NULL;
int i;
if (info == NULL)
goto out;
skb = sip_alloc_ctrl_skbuf(SIP, sizeof(struct sip_hdr) + sizeof(struct sip_cmd_debug), SIP_CMD_DEBUG);
if (!skb)
goto out;
dbgcmd = (struct sip_cmd_debug *)(skb->data + sizeof(struct sip_hdr));
dbgcmd->cmd_type = nla_get_u32(info->attrs[TEST_ATTR_CMD_TYPE]);
dbgcmd->para_num = nla_get_u32(info->attrs[TEST_ATTR_PARA_NUM]);
esp_dbg(ESP_DBG_ERROR, "%s dbgcmdType %d paraNum %d\n", __func__, dbgcmd->cmd_type, dbgcmd->para_num);
for (i=0; i<dbgcmd->para_num; i++)
dbgcmd->para[i] = nla_get_u32(info->attrs[TEST_ATTR_PARA(i)]);
/*directly send reply_info to target, and waiting for report*/
REGISTER_REPLY(info);
sip_send_test_cmd(SIP, skb);
return 0;
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_sdio_wr(struct sk_buff *skb_2,
struct genl_info *info)
{
int res;
u32 func_no, addr, value;
if (info == NULL)
goto out;
func_no = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
addr = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
value = nla_get_u32(info->attrs[TEST_ATTR_PARA2]);
if(!func_no) {
res = esp_common_writebyte_with_addr(SIP->epub, addr, (u8)value, ESP_SIF_SYNC);
} else {
memcpy(sdio_buff, (u8 *)&value, 4);
res = esp_common_write_with_addr(SIP->epub, addr, sdio_buff, 4, ESP_SIF_SYNC);
}
/*directly send reply_info to target, and waiting for report*/
REGISTER_REPLY(info);
if (!res)
esp_test_cmd_reply(info, TEST_CMD_SDIO_WR, "write ok!");
else
esp_test_cmd_reply(info, TEST_CMD_SDIO_WR, "write fail!");
out:
OUT_DONE();
return -EINVAL;
}
static int esp_test_sdio_rd(struct sk_buff *skb_2,
struct genl_info *info)
{
int res;
u32 func_no, addr, value;
char value_str[12];
if (info == NULL)
goto out;
func_no = nla_get_u32(info->attrs[TEST_ATTR_PARA0]);
addr = nla_get_u32(info->attrs[TEST_ATTR_PARA1]);
if(!func_no) {
memset(sdio_buff, 0, 4);
res = esp_common_readbyte_with_addr(SIP->epub, addr, &sdio_buff[0], ESP_SIF_SYNC);
} else {
res = esp_common_read_with_addr(SIP->epub, addr, sdio_buff, 4, ESP_SIF_SYNC);
}
memcpy((u8 *)&value, sdio_buff, 4);
/*directly send reply_info to target, and waiting for report*/
REGISTER_REPLY(info);
if (!res) {
sprintf((char *)&value_str, "0x%x", value);
esp_test_cmd_reply(info, TEST_CMD_SDIO_RD, value_str);
} else
esp_test_cmd_reply(info, TEST_CMD_SDIO_RD, "read fail!");
out:
OUT_DONE();
return -EINVAL;
}
/* TEST_CMD netlink policy */
static struct nla_policy test_genl_policy[TEST_ATTR_MAX + 1] = {
[TEST_ATTR_CMD_NAME]= { .type = NLA_NUL_STRING, .len = GENL_NAMSIZ - 1 },
[TEST_ATTR_CMD_TYPE] = { .type = NLA_U32 },
[TEST_ATTR_PARA_NUM] = { .type = NLA_U32 },
[TEST_ATTR_PARA0] = { .type = NLA_U32 },
[TEST_ATTR_PARA1] = { .type = NLA_U32 },
[TEST_ATTR_PARA2] = { .type = NLA_U32 },
[TEST_ATTR_PARA3] = { .type = NLA_U32 },
[TEST_ATTR_PARA4] = { .type = NLA_U32 },
[TEST_ATTR_PARA5] = { .type = NLA_U32 },
[TEST_ATTR_PARA6] = { .type = NLA_U32 },
[TEST_ATTR_PARA7] = { .type = NLA_U32 },
[TEST_ATTR_STR] = { .type = NLA_NUL_STRING, .len = 256-1 },
};
/* Generic Netlink operations array */
static struct genl_ops esp_test_ops[] = {
{
.cmd = TEST_CMD_ECHO,
.policy = test_genl_policy,
.doit = esp_test_echo,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_ASK,
.policy = test_genl_policy,
.doit = esp_test_ask,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_SLEEP,
.policy = test_genl_policy,
.doit = esp_test_sleep,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_WAKEUP,
.policy = test_genl_policy,
.doit = esp_test_wakeup,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_LOOPBACK,
.policy = test_genl_policy,
.doit = esp_test_loopback,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_TX,
.policy = test_genl_policy,
.doit = esp_test_tx,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_DEBUG,
.policy = test_genl_policy,
.doit = esp_test_genl,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_SDIO_WR,
.policy = test_genl_policy,
.doit = esp_test_sdio_wr,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_SDIO_RD,
.policy = test_genl_policy,
.doit = esp_test_sdio_rd,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_ATE,
.policy = test_genl_policy,
.doit = esp_test_ate,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_SDIOTEST,
.policy = test_genl_policy,
.doit = esp_test_sdiotest,
.flags = GENL_ADMIN_PERM,
},
{
.cmd = TEST_CMD_SDIOSPEED,
.policy = test_genl_policy,
.doit = esp_test_sdiospeed,
.flags = GENL_ADMIN_PERM,
},
};
static int esp_test_netlink_notify(struct notifier_block *nb,
unsigned long state,
void *_notify)
{
struct netlink_notify *notify = _notify;
if (state != NETLINK_URELEASE)
return NOTIFY_DONE;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
if (notify->portid == connected_nl) {
#else
if (notify->pid == connected_nl) {
#endif
esp_dbg(ESP_DBG_ERROR, "esp_sdio: user released netlink"
" socket \n");
connected_nl = 0;
}
return NOTIFY_DONE;
}
static struct notifier_block test_netlink_notifier = {
.notifier_call = esp_test_netlink_notify,
};
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
/**
* copy from net/netlink/genetlink.c(linux kernel 2.6.32)
*
* genl_register_family_with_ops - register a generic netlink family
* @family: generic netlink family
* @ops: operations to be registered
* @n_ops: number of elements to register
*
* Registers the specified family and operations from the specified table.
* Only one family may be registered with the same family name or identifier.
*
* The family id may equal GENL_ID_GENERATE causing an unique id to
* be automatically generated and assigned.
*
* Either a doit or dumpit callback must be specified for every registered
* operation or the function will fail. Only one operation structure per
* command identifier may be registered.
*
* See include/net/genetlink.h for more documenation on the operations
* structure.
*
* This is equivalent to calling genl_register_family() followed by
* genl_register_ops() for every operation entry in the table taking
* care to unregister the family on error path.
*
* Return 0 on success or a negative error code.
*/
int genl_register_family_with_ops(struct genl_family *family,
struct genl_ops *ops, size_t n_ops)
{
int err, i;
err = genl_register_family(family);
if (err)
return err;
for (i = 0; i < n_ops; ++i, ++ops) {
err = genl_register_ops(family, ops);
if (err)
goto err_out;
}
return 0;
err_out:
genl_unregister_family(family);
return err;
}
#endif
int test_init_netlink(struct esp_sip *sip)
{
int rc;
esp_dbg(ESP_DBG_ERROR, "esp_sdio: initializing netlink\n");
sip_copy=sip;
/* temp buffer for sdio test */
sdio_buff = kzalloc(8, GFP_KERNEL);
sdiotest_buf = kzalloc(16*1024, GFP_KERNEL);
rc = genl_register_family_with_ops(&test_genl_family,
esp_test_ops, ARRAY_SIZE(esp_test_ops));
if (rc)
goto failure;
rc = netlink_register_notifier(&test_netlink_notifier);
if (rc)
goto failure;
return 0;
failure:
esp_dbg(ESP_DBG_ERROR, "esp_sdio: error occured in %s\n", __func__);
if (sdio_buff) {
kfree(sdio_buff);
sdio_buff = NULL;