forked from al177/esp8089
-
Notifications
You must be signed in to change notification settings - Fork 14
/
esp_mac80211.c
executable file
·2272 lines (1998 loc) · 73.5 KB
/
esp_mac80211.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.
*
* MAC80211 support module
*/
#include <linux/etherdevice.h>
#include <linux/workqueue.h>
#include <linux/nl80211.h>
#include <linux/ieee80211.h>
#include <linux/slab.h>
#include <net/cfg80211.h>
#include <net/mac80211.h>
#include <linux/version.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
#include <net/regulatory.h>
#endif
/* for support scan in p2p concurrent */
#include <../net/mac80211/ieee80211_i.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 "esp_utils.h"
#define ESP_IEEE80211_DBG esp_dbg
#define GET_NEXT_SEQ(seq) (((seq) +1) & 0x0fff)
#ifdef P2P_CONCURRENT
static u8 esp_mac_addr[ETH_ALEN * 2];
#endif
static u8 getaddr_index(u8 * addr, struct esp_pub *epub);
static
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
void
esp_op_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb)
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
void
esp_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
#else
int
esp_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
#endif /* NEW_KERNEL */
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
ESP_IEEE80211_DBG(ESP_DBG_LOG, "%s enter\n", __func__);
if (!mod_support_no_txampdu() &&
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
cfg80211_get_chandef_type(&epub->hw->conf.chandef) != NL80211_CHAN_NO_HT
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
hw->conf.channel_type != NL80211_CHAN_NO_HT
#else
!(hw->conf.flags&IEEE80211_CONF_SUPPORT_HT_MODE)
#endif
) {
struct ieee80211_tx_info * tx_info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr * wh = (struct ieee80211_hdr *)skb->data;
if(ieee80211_is_data_qos(wh->frame_control)) {
if(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
u8 tidno = ieee80211_get_qos_ctl(wh)[0] & IEEE80211_QOS_CTL_TID_MASK;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
struct esp_node * node = esp_get_node_by_addr(epub, wh->addr1);
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
struct ieee80211_sta *sta = tx_info->control.sta;
struct esp_node * node = (struct esp_node *)sta->drv_priv;
if(sta->ht_cap.ht_supported)
#else
struct esp_node * node = esp_get_node_by_addr(epub, wh->addr1);
if(node->ht_info.ht_supported)
#endif
{
struct esp_tx_tid *tid = &node->tid[tidno];
//record ssn
spin_lock_bh(&epub->tx_ampdu_lock);
tid->ssn = GET_NEXT_SEQ(le16_to_cpu(wh->seq_ctrl)>>4);
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "tidno:%u,ssn:%u\n", tidno, tid->ssn);
spin_unlock_bh(&epub->tx_ampdu_lock);
}
} else {
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "tx ampdu pkt, sn:%u, %u\n", le16_to_cpu(wh->seq_ctrl)>>4, skb->len);
}
}
}
#ifdef GEN_ERR_CHECKSUM
esp_gen_err_checksum(skb);
#endif
sip_tx_data_pkt_enqueue(epub, skb);
if (epub)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
ieee80211_queue_work(hw, &epub->tx_work);
#else
queue_work(hw->workqueue,&epub->tx_work);
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
return NETDEV_TX_OK;
#endif /*2.6.39*/
}
static int esp_op_start(struct ieee80211_hw *hw)
{
struct esp_pub *epub;
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
if (!hw) {
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no hw!\n", __func__);
return -EINVAL;
}
epub = (struct esp_pub *)hw->priv;
if (!epub) {
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no epub!\n", __func__);
return EINVAL;
}
/*add rfkill poll function*/
atomic_set(&epub->wl.off, 0);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
wiphy_rfkill_start_polling(hw->wiphy);
#endif
return 0;
}
static void esp_op_stop(struct ieee80211_hw *hw)
{
struct esp_pub *epub;
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s\n", __func__);
if (!hw) {
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no hw!\n", __func__);
return;
}
epub = (struct esp_pub *)hw->priv;
if (!epub) {
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s no epub!\n", __func__);
return;
}
atomic_set(&epub->wl.off, 1);
#ifdef HOST_RESET_BUG
mdelay(200);
#endif
if (epub->wl.scan_req) {
hw_scan_done(epub, true);
epub->wl.scan_req=NULL;
//msleep(2);
}
}
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39))
#ifdef CONFIG_PM
static int esp_op_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
{
esp_dbg(ESP_DBG_OP, "%s\n", __func__);
return 0;
}
static int esp_op_resume(struct ieee80211_hw *hw)
{
esp_dbg(ESP_DBG_OP, "%s\n", __func__);
return 0;
}
#endif //CONFIG_PM
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
static int esp_op_add_interface(struct ieee80211_hw *hw,
struct ieee80211_if_init_conf *conf)
#else
static int esp_op_add_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
#endif
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
struct ieee80211_vif *vif = conf->vif;
#endif
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
struct sip_cmd_setvif svif;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter: type %d, addr %pM\n", __func__, vif->type, conf->mac_addr);
#else
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter: type %d, addr %pM\n", __func__, vif->type, vif->addr);
#endif
memset(&svif, 0, sizeof(struct sip_cmd_setvif));
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
memcpy(svif.mac, conf->mac_addr, ETH_ALEN);
evif->index = svif.index = getaddr_index(conf->mac_addr, epub);
#else
memcpy(svif.mac, vif->addr, ETH_ALEN);
evif->index = svif.index = getaddr_index(vif->addr, epub);
#endif
evif->epub = epub;
epub->vif = vif;
svif.set = 1;
if((1 << svif.index) & epub->vif_slot){
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s interface %d already used\n", __func__, svif.index);
return -EOPNOTSUPP;
}
epub->vif_slot |= 1 << svif.index;
if (svif.index == ESP_PUB_MAX_VIF) {
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s only support MAX %d interface\n", __func__, ESP_PUB_MAX_VIF);
return -EOPNOTSUPP;
}
switch (vif->type) {
case NL80211_IFTYPE_STATION:
//if (svif.index == 1)
// vif->type = NL80211_IFTYPE_UNSPECIFIED;
ESP_IEEE80211_DBG(ESP_SHOW, "%s STA \n", __func__);
svif.op_mode = 0;
svif.is_p2p = 0;
break;
case NL80211_IFTYPE_AP:
ESP_IEEE80211_DBG(ESP_SHOW, "%s AP \n", __func__);
svif.op_mode = 1;
svif.is_p2p = 0;
break;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
case NL80211_IFTYPE_P2P_CLIENT:
ESP_IEEE80211_DBG(ESP_SHOW, "%s P2P_CLIENT \n", __func__);
svif.op_mode = 0;
svif.is_p2p = 1;
break;
case NL80211_IFTYPE_P2P_GO:
ESP_IEEE80211_DBG(ESP_SHOW, "%s P2P_GO \n", __func__);
svif.op_mode = 1;
svif.is_p2p = 1;
break;
#endif
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MONITOR:
default:
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s does NOT support type %d\n", __func__, vif->type);
return -EOPNOTSUPP;
}
sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
return 0;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
static int esp_op_change_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
enum nl80211_iftype new_type, bool p2p)
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
struct sip_cmd_setvif svif;
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter,change to if:%d \n", __func__, new_type);
if (new_type == NL80211_IFTYPE_AP) {
ESP_IEEE80211_DBG(ESP_SHOW, "%s enter,change to AP \n", __func__);
}
if (vif->type != new_type) {
ESP_IEEE80211_DBG(ESP_SHOW, "%s type from %d to %d\n", __func__, vif->type, new_type);
}
memset(&svif, 0, sizeof(struct sip_cmd_setvif));
memcpy(svif.mac, vif->addr, ETH_ALEN);
svif.index = evif->index;
svif.set = 2;
switch (new_type) {
case NL80211_IFTYPE_STATION:
svif.op_mode = 0;
svif.is_p2p = p2p;
break;
case NL80211_IFTYPE_AP:
svif.op_mode = 1;
svif.is_p2p = p2p;
break;
case NL80211_IFTYPE_P2P_CLIENT:
svif.op_mode = 0;
svif.is_p2p = 1;
break;
case NL80211_IFTYPE_P2P_GO:
svif.op_mode = 1;
svif.is_p2p = 1;
break;
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_AP_VLAN:
case NL80211_IFTYPE_WDS:
case NL80211_IFTYPE_MONITOR:
default:
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s does NOT support type %d\n", __func__, vif->type);
return -EOPNOTSUPP;
}
sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
return 0;
}
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
static void esp_op_remove_interface(struct ieee80211_hw *hw,
struct ieee80211_if_init_conf *conf)
#else
static void esp_op_remove_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
#endif
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
struct ieee80211_vif *vif = conf->vif;
#endif
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
struct sip_cmd_setvif svif;
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 30))
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM\n", __func__, conf->mac_addr);
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, beacon enable %x\n", __func__, conf->mac_addr, vif->bss_conf.enable_beacon);
#else
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, vif addr %pM, beacon enable %x\n", __func__, vif->addr, vif->bss_conf.enable_beacon);
#endif
memset(&svif, 0, sizeof(struct sip_cmd_setvif));
svif.index = evif->index;
epub->vif_slot &= ~(1 << svif.index);
if(evif->ap_up){
evif->beacon_interval = 0;
del_timer_sync(&evif->beacon_timer);
evif->ap_up = false;
}
epub->vif = NULL;
evif->epub = NULL;
sip_cmd(epub, SIP_CMD_SETVIF, (u8 *)&svif, sizeof(struct sip_cmd_setvif));
/* clean up tx/rx queue */
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
#define BEACON_TIM_SAVE_MAX 20
u8 beacon_tim_saved[BEACON_TIM_SAVE_MAX];
int beacon_tim_count;
static void beacon_tim_init(void)
{
memset(beacon_tim_saved, BEACON_TIM_SAVE_MAX, 0);
beacon_tim_count = 0;
}
static u8 beacon_tim_save(u8 this_tim)
{
u8 all_tim = 0;
int i;
beacon_tim_saved[beacon_tim_count] = this_tim;
if(++beacon_tim_count >= BEACON_TIM_SAVE_MAX)
beacon_tim_count = 0;
for(i = 0; i < BEACON_TIM_SAVE_MAX; i++)
all_tim |= beacon_tim_saved[i];
return all_tim;
}
static bool beacon_tim_alter(struct sk_buff *beacon)
{
u8 *p, *tim_end;
u8 tim_count;
int len;
int remain_len;
struct ieee80211_mgmt * mgmt;
if (beacon == NULL)
return false;
mgmt = (struct ieee80211_mgmt *)((u8 *)beacon->data);
remain_len = beacon->len - ((u8 *)mgmt->u.beacon.variable - (u8 *)mgmt + 12);
p = mgmt->u.beacon.variable;
while (remain_len > 0) {
len = *(++p);
if (*p == WLAN_EID_TIM) { // tim field
tim_end = p + len;
tim_count = *(++p);
p += 2;
//multicast
if(tim_count == 0)
*p |= 0x1;
if((*p & 0xfe) == 0 && tim_end >= p+1){// we only support 8 sta in this case
p++;
*p = beacon_tim_save(*p);
}
return tim_count == 0;
}
p += (len + 1);
remain_len -= (2 + len);
}
return false;
}
unsigned long init_jiffies;
unsigned long cycle_beacon_count;
static void drv_handle_beacon(unsigned long data)
{
struct ieee80211_vif *vif = (struct ieee80211_vif *) data;
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
struct sk_buff *beacon;
struct sk_buff *skb;
static int dbgcnt = 0;
bool tim_reach = false;
if(evif->epub == NULL)
return;
mdelay(2400 * (cycle_beacon_count % 25) % 10000 /1000);
beacon = ieee80211_beacon_get(evif->epub->hw, vif);
tim_reach = beacon_tim_alter(beacon);
if (beacon && !(dbgcnt++ % 600)) {
ESP_IEEE80211_DBG(ESP_SHOW, " beacon length:%d,fc:0x%x\n", beacon->len,
((struct ieee80211_mgmt *)(beacon->data))->frame_control);
}
if(beacon)
sip_tx_data_pkt_enqueue(evif->epub, beacon);
if(cycle_beacon_count++ == 100){
init_jiffies = jiffies;
cycle_beacon_count -= 100;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
mod_timer(&evif->beacon_timer, init_jiffies + msecs_to_jiffies(cycle_beacon_count * vif->bss_conf.beacon_int*1024/1000));
#else
mod_timer(&evif->beacon_timer, init_jiffies +msecs_to_jiffies(cycle_beacon_count * evif->beacon_interval*1024/1000));
#endif
//FIXME:the packets must be sent at home channel
//send buffer mcast frames
if(tim_reach){
skb = ieee80211_get_buffered_bc(evif->epub->hw, vif);
while (skb) {
sip_tx_data_pkt_enqueue(evif->epub, skb);
skb = ieee80211_get_buffered_bc(evif->epub->hw, vif);
}
}
}
static void init_beacon_timer(struct ieee80211_vif *vif)
{
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, evif->beacon_interval);
beacon_tim_init();
init_timer(&evif->beacon_timer); //TBD, not init here...
cycle_beacon_count = 1;
init_jiffies = jiffies;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
evif->beacon_timer.expires = init_jiffies + msecs_to_jiffies(cycle_beacon_count * vif->bss_conf.beacon_int*1024/1000);
#else
evif->beacon_timer.expires = init_jiffies + msecs_to_jiffies(cycle_beacon_count * evif->beacon_interval*1024/1000);
#endif
evif->beacon_timer.data = (unsigned long) vif;
evif->beacon_timer.function = drv_handle_beacon;
add_timer(&evif->beacon_timer);
}
#endif
/*
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
static void init_beacon_timer(struct ieee80211_vif *vif)
#else
static void init_beacon_timer(struct ieee80211_conf *conf)
#endif
{
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, vif->bss_conf.beacon_int);
#else
ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: beacon interval %x\n", __func__, conf->beacon_int);
#endif
init_timer(&evif->beacon_timer); //TBD, not init here...
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
evif->beacon_timer.expires=jiffies+msecs_to_jiffies(vif->bss_conf.beacon_int*102/100);
evif->beacon_timer.data = (unsigned long) vif;
#else
evif->beacon_timer.expires=jiffies+msecs_to_jiffies(conf->beacon_int*102/100);
evif->beacon_timer.data = (unsigned long) conf;
#endif
//evif->beacon_timer.data = (unsigned long) vif;
evif->beacon_timer.function = drv_handle_beacon;
add_timer(&evif->beacon_timer);
}
*/
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
static int esp_op_config(struct ieee80211_hw *hw, u32 changed)
#else
static int esp_op_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
#endif
{
//struct ieee80211_conf *conf = &hw->conf;
struct esp_pub *epub = (struct esp_pub *)hw->priv;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29))
//struct esp_vif *evif = (struct esp_vif *)epub->vif->drv_priv;
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter 0x%08x\n", __func__, changed);
if (changed & (IEEE80211_CONF_CHANGE_CHANNEL | IEEE80211_CONF_CHANGE_IDLE)) {
sip_send_config(epub, &hw->conf);
}
#else
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter 0x%08x\n", __func__, conf->flags);
sip_send_config(epub, &hw->conf);
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29))
//evif->beacon_interval = conf->beacon_int;
//init_beacon_timer(epub->vif);
#endif
#if 0
if (changed & IEEE80211_CONF_CHANGE_PS) {
struct esp_ps *ps = &epub->ps;
ps->dtim_period = conf->ps_dtim_period;
ps->max_sleep_period = conf->max_sleep_period;
esp_ps_config(epub, ps, (conf->flags & IEEE80211_CONF_PS));
}
#endif
return 0;
}
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
static int esp_op_config_interface (struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_if_conf *conf)
{
// assoc = 2 means AP
struct esp_pub *epub = (struct esp_pub *)hw->priv;
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
//struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: changed %x, bssid %pM,vif->type = %d\n", __func__, conf->changed, conf->bssid,vif->type);
if(conf->bssid)
memcpy(epub->wl.bssid, conf->bssid, ETH_ALEN);
else
memset(epub->wl.bssid, 0, ETH_ALEN);
if(vif->type == NL80211_IFTYPE_AP){
if((conf->changed & IEEE80211_IFCC_BEACON)){
sip_send_bss_info_update(epub, evif, (u8*)conf->bssid, 2);
//evif->beacon_interval = conf->beacon_int;
}
else{
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op----1-- mode unspecified\n", __func__);
}
}
else{
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op----2-- mode unspecified\n", __func__);
}
return 0;
}
#endif
static void esp_op_bss_info_changed(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *info,
u32 changed)
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
struct sta_info *sta;
struct esp_node *node;
struct ieee80211_ht_info *ht_info;
u8 addr_0[ETH_ALEN];
memset(addr_0,0,ETH_ALEN);
ESP_IEEE80211_DBG(ESP_DBG_OP,"%s enter, changed %x\n",__func__,changed);
if((changed & BSS_CHANGED_ASSOC) && (memcmp(epub->wl.bssid,addr_0, ETH_ALEN)))
{
rcu_read_lock();
node = esp_get_node_by_addr(epub, epub->wl.bssid );
sta = sta_info_get(container_of(hw,struct ieee80211_local,hw), epub->wl.bssid);
ht_info = &sta->ht_info;
memcpy(node->supp_rates, sta->supp_rates, sizeof(node->supp_rates));
memcpy(&node->ht_info.cap, &ht_info->cap, sizeof(node->ht_info.cap));
memcpy(&node->ht_info.ht_supported, &ht_info->ht_supported, sizeof(node->ht_info.ht_supported));
memcpy(&node->ht_info.ampdu_density, &ht_info->ampdu_density, sizeof(node->ht_info.ampdu_density));
memcpy(&node->ht_info.ampdu_factor, &ht_info->ampdu_factor, sizeof(node->ht_info.ampdu_factor));
if(sta->aid == 0)
memcpy(&node->aid, &info->aid, sizeof(node->aid));
else
memcpy(&node->aid, &sta->aid, sizeof(node->aid));
rcu_read_unlock();
sip_send_set_sta(epub, evif->index, 1, node, vif, (u8)node->index);
}
#else
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
#endif
// ieee80211_bss_conf(include/net/mac80211.h) is included in ieee80211_sub_if_data(net/mac80211/ieee80211_i.h) , does bssid=ieee80211_if_ap's ssid ?
// in 2.6.27, ieee80211_sub_if_data has ieee80211_bss_conf while in 2.6.32 ieee80211_sub_if_data don't have ieee80211_bss_conf
// in 2.6.27, ieee80211_bss_conf->enable_beacon don't exist, does it mean it support beacon always?
// ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: vif addr %pM, changed %x, assoc %x, bssid %pM\n", __func__, vif->addr, changed, info->assoc, info->bssid);
// sdata->u.sta.bssid
ESP_IEEE80211_DBG(ESP_DBG_OP, " %s enter: changed %x, assoc %x, bssid %pM\n", __func__, changed, info->assoc, info->bssid);
if (vif->type == NL80211_IFTYPE_STATION) {
if ((changed & BSS_CHANGED_BSSID) ||
((changed & BSS_CHANGED_ASSOC) && (info->assoc)))
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s STA change bssid or assoc\n", __func__);
evif->beacon_interval = info->aid;
memcpy(epub->wl.bssid, (u8*)info->bssid, ETH_ALEN);
sip_send_bss_info_update(epub, evif, (u8*)info->bssid, info->assoc);
} else if ((changed & BSS_CHANGED_ASSOC) && (!info->assoc)) {
ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s STA change disassoc\n", __func__);
evif->beacon_interval = 0;
memset(epub->wl.bssid, 0, ETH_ALEN);
sip_send_bss_info_update(epub, evif, (u8*)info->bssid, info->assoc);
} else {
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s wrong mode of STA mode\n", __func__);
}
} else if (vif->type == NL80211_IFTYPE_AP) {
if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
(changed & BSS_CHANGED_BEACON_INT)) {
ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s AP change enable %d, interval is %d, bssid %pM\n", __func__, info->enable_beacon, info->beacon_int, info->bssid);
if (info->enable_beacon && evif->ap_up != true) {
evif->beacon_interval = info->beacon_int;
init_beacon_timer(vif);
sip_send_bss_info_update(epub, evif, (u8*)info->bssid, 2);
evif->ap_up = true;
} else if (!info->enable_beacon && evif->ap_up &&
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
!test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)
#else
true
#endif
) {
ESP_IEEE80211_DBG(ESP_DBG_TRACE, " %s AP disable beacon, interval is %d\n", __func__, info->beacon_int);
evif->beacon_interval = 0;
del_timer_sync(&evif->beacon_timer);
sip_send_bss_info_update(epub, evif, (u8*)info->bssid, 2);
evif->ap_up = false;
}
}
} else {
ESP_IEEE80211_DBG(ESP_DBG_ERROR, "%s op mode unspecified\n", __func__);
}
#endif
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35))
static u64 esp_op_prepare_multicast(struct ieee80211_hw *hw,
int mc_count, struct dev_addr_list *mc_list)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
return 0;
}
#else
static u64 esp_op_prepare_multicast(struct ieee80211_hw *hw,
struct netdev_hw_addr_list *mc_list)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
return 0;
}
#endif /* NEW_KERNEL && KERNEL_35 */
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
static void esp_op_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
unsigned int *total_flags,
u64 multicast)
#else
static void esp_op_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
unsigned int *total_flags,
int mc_count,
struct dev_addr_list *mc_list)
#endif
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
epub->rx_filter = 0;
if (*total_flags & FIF_ALLMULTI)
epub->rx_filter |= FIF_ALLMULTI;
*total_flags = epub->rx_filter;
}
#if 0
static int esp_op_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
bool set)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
return 0;
}
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
static int esp_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
struct ieee80211_vif *vif, struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
#else
static int esp_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
const u8 *local_address,const u8 *address,
struct ieee80211_key_conf *key)
#endif
{
u8 i;
int ret;
struct esp_pub *epub = (struct esp_pub *)hw->priv;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
struct esp_vif *evif = (struct esp_vif *)vif->drv_priv;
u8 ifidx = evif->index;
#else
u8 ifidx = getaddr_index((u8 *)(local_address), epub);
#endif
u8 *peer_addr,isvalid;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, flags = %x keyindx = %x cmd = %x mac = %pM cipher = %x\n", __func__, key->flags, key->keyidx, cmd, vif->addr, key->cipher);
#else
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s enter, flags = %x keyindx = %x cmd = %x cipher = %x\n", __func__, key->flags, key->keyidx, cmd, key->alg);
#endif
key->flags= key->flags|IEEE80211_KEY_FLAG_GENERATE_IV;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
if (sta) {
if (memcmp(sta->addr, epub->wl.bssid, ETH_ALEN))
peer_addr = sta->addr;
else
peer_addr = epub->wl.bssid;
} else {
peer_addr=epub->wl.bssid;
}
#else
peer_addr = (u8 *)address;
#endif
isvalid = (cmd==SET_KEY) ? 1 : 0;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
if ((key->flags&IEEE80211_KEY_FLAG_PAIRWISE) || (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104))
#else
if ((key->flags&IEEE80211_KEY_FLAG_PAIRWISE) || (key->alg == ALG_WEP))
#endif
{
if (isvalid) {
for (i = 0; i < 19; i++) {
if (epub->hi_map[i].flag == 0) {
epub->hi_map[i].flag = 1;
key->hw_key_idx = i + 6;
memcpy(epub->hi_map[i].mac, peer_addr, ETH_ALEN);
break;
}
}
} else {
u8 index = key->hw_key_idx - 6;
epub->hi_map[index].flag = 0;
memset(epub->hi_map[index].mac, 0, ETH_ALEN);
}
} else {
if(isvalid){
for(i = 0; i < 2; i++)
if (epub->low_map[ifidx][i].flag == 0) {
epub->low_map[ifidx][i].flag = 1;
key->hw_key_idx = i + ifidx * 2 + 2;
memcpy(epub->low_map[ifidx][i].mac, peer_addr, ETH_ALEN);
break;
}
} else {
u8 index = key->hw_key_idx - 2 - ifidx * 2;
epub->low_map[ifidx][index].flag = 0;
memset(epub->low_map[ifidx][index].mac, 0, ETH_ALEN);
}
//key->hw_key_idx = key->keyidx + ifidx * 2 + 1;
}
if (key->hw_key_idx >= 6) {
/*send sub_scan task to target*/
//epub->wl.ptk = (cmd==SET_KEY) ? key : NULL;
if(isvalid)
atomic_inc(&epub->wl.ptk_cnt);
else
atomic_dec(&epub->wl.ptk_cnt);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104)
#else
if (key->alg == ALG_WEP)
#endif
{
if(isvalid)
atomic_inc(&epub->wl.gtk_cnt);
else
atomic_dec(&epub->wl.gtk_cnt);
}
} else {
/*send sub_scan task to target*/
if(isvalid)
atomic_inc(&epub->wl.gtk_cnt);
else
atomic_dec(&epub->wl.gtk_cnt);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
if((key->cipher == WLAN_CIPHER_SUITE_WEP40 || key->cipher == WLAN_CIPHER_SUITE_WEP104))
#else
if((key->alg == ALG_WEP))
#endif
{
if(isvalid)
atomic_inc(&epub->wl.ptk_cnt);
else
atomic_dec(&epub->wl.ptk_cnt);
//epub->wl.ptk = (cmd==SET_KEY) ? key : NULL;
}
}
ret = sip_send_setkey(epub, ifidx, peer_addr, key, isvalid);
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
if((key->cipher == WLAN_CIPHER_SUITE_TKIP || key->cipher == WLAN_CIPHER_SUITE_TKIP))
#else
if((key->alg == ALG_TKIP))
#endif
{
if(ret == 0)
atomic_set(&epub->wl.tkip_key_set, 1);
}
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s exit\n", __func__);
return ret;
}
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34))
static void esp_op_update_tkip_key(struct ieee80211_hw *hw,
struct ieee80211_key_conf *conf, const u8 *address,
u32 iv32, u16 *phase1key)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
}
#else
static void esp_op_update_tkip_key(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_key_conf *conf,
struct ieee80211_sta *sta,
u32 iv32, u16 *phase1key)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
}
#endif /* KERNEL_35 NEW_KERNEL*/
void hw_scan_done(struct esp_pub *epub, bool aborted)
{
cancel_delayed_work_sync(&epub->scan_timeout_work);
ESSERT(epub->wl.scan_req != NULL);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
ieee80211_scan_completed(epub->hw, aborted);
#else
ieee80211_scan_completed(epub->hw);
#endif
if (test_and_clear_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags)) {
sip_trigger_txq_process(epub->sip);
}
}
static void hw_scan_timeout_report(struct work_struct *work)
{
struct esp_pub *epub =
container_of(work, struct esp_pub, scan_timeout_work.work);
bool aborted;
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "eagle hw scan done\n");
if (test_and_clear_bit(ESP_WL_FLAG_STOP_TXQ, &epub->wl.flags)) {
sip_trigger_txq_process(epub->sip);
}
/*check if normally complete or aborted like timeout/hw error */
aborted = (epub->wl.scan_req) ? true : false;
if (aborted==true) {
epub->wl.scan_req = NULL;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
ieee80211_scan_completed(epub->hw, aborted);
#else
ieee80211_scan_completed(epub->hw);
#endif
}
#if 0
static void esp_op_sw_scan_start(struct ieee80211_hw *hw)
{}
static void esp_op_sw_scan_complete(struct ieee80211_hw *hw)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
}
#endif
#if 0
static int esp_op_get_stats(struct ieee80211_hw *hw,
struct ieee80211_low_level_stats *stats)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
return 0;
}
static void esp_op_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
u32 *iv32, u16 *iv16)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
}
#endif
static int esp_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
return 0;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx, struct ieee80211_sta *sta)
#else
static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx, const u8 *addr)
#endif
{
struct esp_pub *epub = (struct esp_pub *)hw->priv;
struct esp_node *node;
u8 tidno;
struct esp_tx_tid *tid;
int i;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
struct sta_info *info = sta_info_get(container_of(hw,struct ieee80211_local,hw),(u8 *)addr);
struct ieee80211_ht_info *ht_info = &info->ht_info;
#endif
spin_lock_bh(&epub->tx_ampdu_lock);
if(hweight32(epub->enodes_maps[ifidx]) < ESP_PUB_MAX_STA && (i = ffz(epub->enodes_map)) < ESP_PUB_MAX_STA + 1){
epub->enodes_map |= (1 << i);
epub->enodes_maps[ifidx] |= (1 << i);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
node = (struct esp_node *)sta->drv_priv;
epub->enodes[i] = node;
node->sta = sta;
#else
node = &epub->nodes[i];
epub->enodes[i] = node;