forked from al177/esp8089
-
Notifications
You must be signed in to change notification settings - Fork 10
/
esp_mac80211.c
1727 lines (1495 loc) · 44.3 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
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#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>
#include <net/regulatory.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)
static u8 esp_mac_addr[ETH_ALEN * 2];
static u8 getaddr_index(u8 * addr, struct esp_pub *epub);
static
void
esp_op_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
struct sk_buff *skb)
{
struct esp_pub *epub = (struct esp_pub *) hw->priv;
ESP_IEEE80211_DBG(ESP_DBG_LOG, "%s enter\n", __func__);
if (!mod_support_no_txampdu() &&
cfg80211_get_chandef_type(&epub->hw->conf.chandef) !=
NL80211_CHAN_NO_HT) {
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;
struct esp_node *node =
esp_get_node_by_addr(epub, wh->addr1);
{
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)
ieee80211_queue_work(hw, &epub->tx_work);
}
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);
wiphy_rfkill_start_polling(hw->wiphy);
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);
}
}
#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
static int esp_op_add_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
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: type %d, addr %pM\n",
__func__, vif->type, vif->addr);
memset(&svif, 0, sizeof(struct sip_cmd_setvif));
memcpy(svif.mac, vif->addr, ETH_ALEN);
evif->index = svif.index = getaddr_index(vif->addr, epub);
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_DBG_TRACE, "%s STA \n", __func__);
svif.op_mode = 0;
svif.is_p2p = 0;
break;
case NL80211_IFTYPE_AP:
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s AP \n", __func__);
svif.op_mode = 1;
svif.is_p2p = 0;
break;
case NL80211_IFTYPE_P2P_CLIENT:
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s P2P_CLIENT \n", __func__);
svif.op_mode = 0;
svif.is_p2p = 1;
break;
case NL80211_IFTYPE_P2P_GO:
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s P2P_GO \n", __func__);
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;
}
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_DBG_TRACE, "%s enter,change to AP \n",
__func__);
}
if (vif->type != new_type) {
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%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;
}
static void esp_op_remove_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
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, vif addr %pM, beacon enable %x\n",
__func__, vif->addr,
vif->bss_conf.enable_beacon);
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 */
}
#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, 0, BEACON_TIM_SAVE_MAX);
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;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
static void drv_handle_beacon(struct timer_list *t)
#else
static void drv_handle_beacon(unsigned long data)
#endif
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
struct esp_vif *evif = from_timer(evif, t, beacon_timer);
struct ieee80211_vif *vif = evif->epub->vif;
#else
struct ieee80211_vif *vif = (struct ieee80211_vif *) data;
struct esp_vif *evif = (struct esp_vif *) vif->drv_priv;
#endif
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_DBG_TRACE, " 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;
}
mod_timer(&evif->beacon_timer,
init_jiffies +
msecs_to_jiffies(cycle_beacon_count *
vif->bss_conf.beacon_int * 1024 /
1000));
//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();
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0))
timer_setup(&evif->beacon_timer, drv_handle_beacon, 0);
#else
init_timer(&evif->beacon_timer); //TBD, not init here...
evif->beacon_timer.data = (unsigned long) vif;
evif->beacon_timer.function = drv_handle_beacon;
#endif
cycle_beacon_count = 1;
init_jiffies = jiffies;
evif->beacon_timer.expires =
init_jiffies +
msecs_to_jiffies(cycle_beacon_count *
vif->bss_conf.beacon_int * 1024 / 1000);
add_timer(&evif->beacon_timer);
}
static int esp_op_config(struct ieee80211_hw *hw, u32 changed)
{
//struct ieee80211_conf *conf = &hw->conf;
struct esp_pub *epub = (struct esp_pub *) hw->priv;
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);
}
return 0;
}
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;
// 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 &&
!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
) {
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__);
}
}
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;
}
static void esp_op_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
unsigned int *total_flags,
u64 multicast)
{
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;
}
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)
{
u8 i;
int ret;
struct esp_pub *epub = (struct esp_pub *) hw->priv;
struct esp_vif *evif = (struct esp_vif *) vif->drv_priv;
u8 ifidx = evif->index;
u8 *peer_addr, isvalid;
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);
key->flags = key->flags | IEEE80211_KEY_FLAG_GENERATE_IV;
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;
}
isvalid = (cmd == SET_KEY) ? 1 : 0;
if ((key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
|| (key->cipher == WLAN_CIPHER_SUITE_WEP40
|| key->cipher == WLAN_CIPHER_SUITE_WEP104)) {
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 (key->cipher == WLAN_CIPHER_SUITE_WEP40
|| key->cipher == WLAN_CIPHER_SUITE_WEP104) {
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 ((key->cipher == WLAN_CIPHER_SUITE_WEP40
|| key->cipher == WLAN_CIPHER_SUITE_WEP104)) {
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 ((key->cipher == WLAN_CIPHER_SUITE_TKIP
|| key->cipher == WLAN_CIPHER_SUITE_TKIP)) {
if (ret == 0)
atomic_set(&epub->wl.tkip_key_set, 1);
}
ESP_IEEE80211_DBG(ESP_DBG_OP, "%s exit\n", __func__);
return ret;
}
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__);
}
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(4, 8, 0))
{
struct cfg80211_scan_info info = {
.aborted = aborted,
};
ieee80211_scan_completed(epub->hw, &info);
}
#else
ieee80211_scan_completed(epub->hw, aborted);
#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(4, 8, 0))
{
struct cfg80211_scan_info info = {
.aborted = aborted,
};
ieee80211_scan_completed(epub->hw, &info);
}
#else
ieee80211_scan_completed(epub->hw, aborted);
#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;
}
static int esp_node_attach(struct ieee80211_hw *hw, u8 ifidx,
struct ieee80211_sta *sta)
{
struct esp_pub *epub = (struct esp_pub *) hw->priv;
struct esp_node *node;
u8 tidno;
struct esp_tx_tid *tid;
int i;
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);
node = (struct esp_node *) sta->drv_priv;
epub->enodes[i] = node;
node->sta = sta;
node->ifidx = ifidx;
node->index = i;
for (tidno = 0, tid = &node->tid[tidno];
tidno < WME_NUM_TID; tidno++) {
tid->ssn = 0;
tid->cnt = 0;
tid->state = ESP_TID_STATE_INIT;
}
} else {
i = -1;
}
spin_unlock_bh(&epub->tx_ampdu_lock);
return i;
}
static int esp_node_detach(struct ieee80211_hw *hw, u8 ifidx,
struct ieee80211_sta *sta)
{
struct esp_pub *epub = (struct esp_pub *) hw->priv;
u32 map;
int i;
struct esp_node *node = NULL;
spin_lock_bh(&epub->tx_ampdu_lock);
map = epub->enodes_maps[ifidx];
while (map != 0) {
i = ffs(map) - 1;
if (epub->enodes[i]->sta == sta) {
epub->enodes[i]->sta = NULL;
node = epub->enodes[i];
epub->enodes[i] = NULL;
epub->enodes_map &= ~(1 << i);
epub->enodes_maps[ifidx] &= ~(1 << i);
spin_unlock_bh(&epub->tx_ampdu_lock);
return i;
}
map &= ~(1 << i);
}
spin_unlock_bh(&epub->tx_ampdu_lock);
return -1;
}
struct esp_node *esp_get_node_by_addr(struct esp_pub *epub,
const u8 * addr)
{
int i;
u32 map;
struct esp_node *node = NULL;
if (addr == NULL)
return NULL;
spin_lock_bh(&epub->tx_ampdu_lock);
map = epub->enodes_map;
while (map != 0) {
i = ffs(map) - 1;
if (i < 0) {
spin_unlock_bh(&epub->tx_ampdu_lock);
return NULL;
}
map &= ~(1 << i);
if (memcmp(epub->enodes[i]->sta->addr, addr, ETH_ALEN) ==
0) {
node = epub->enodes[i];
break;
}
}
spin_unlock_bh(&epub->tx_ampdu_lock);
return node;
}
struct esp_node *esp_get_node_by_index(struct esp_pub *epub, u8 index)
{
u32 map;
struct esp_node *node = NULL;
if (epub == NULL)
return NULL;
spin_lock_bh(&epub->tx_ampdu_lock);
map = epub->enodes_map;
if (map & BIT(index)) {
node = epub->enodes[index];
} else {
spin_unlock_bh(&epub->tx_ampdu_lock);
return NULL;
}
spin_unlock_bh(&epub->tx_ampdu_lock);
return node;
}
int esp_get_empty_rxampdu(struct esp_pub *epub, const u8 * addr, u8 tid)
{
int index = -1;
if (addr == NULL)
return index;
spin_lock_bh(&epub->rx_ampdu_lock);
if ((index = ffz(epub->rxampdu_map)) < ESP_PUB_MAX_RXAMPDU) {
epub->rxampdu_map |= BIT(index);
epub->rxampdu_node[index] =
esp_get_node_by_addr(epub, addr);
epub->rxampdu_tid[index] = tid;
} else {
index = -1;
}
spin_unlock_bh(&epub->rx_ampdu_lock);
return index;
}
int esp_get_exist_rxampdu(struct esp_pub *epub, const u8 * addr, u8 tid)
{
u8 map;
int index = -1;
int i;
if (addr == NULL)
return index;
spin_lock_bh(&epub->rx_ampdu_lock);
map = epub->rxampdu_map;
while (map != 0) {
i = ffs(map) - 1;
if (i < 0) {
spin_unlock_bh(&epub->rx_ampdu_lock);
return index;
}
map &= ~BIT(i);
if (epub->rxampdu_tid[i] == tid &&
memcmp(epub->rxampdu_node[i]->sta->addr, addr,
ETH_ALEN) == 0) {
index = i;
break;
}
}
epub->rxampdu_map &= ~BIT(index);
spin_unlock_bh(&epub->rx_ampdu_lock);
return index;
}
static int esp_op_sta_add(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct esp_pub *epub = (struct esp_pub *) hw->priv;
struct esp_vif *evif = (struct esp_vif *) vif->drv_priv;
int index;
ESP_IEEE80211_DBG(ESP_DBG_OP,
"%s enter, vif addr %pM, sta addr %pM\n",
__func__, vif->addr, sta->addr);
index = esp_node_attach(hw, evif->index, sta);
if (index < 0)
return -1;
sip_send_set_sta(epub, evif->index, 1, sta, vif, (u8) index);
return 0;
}
static int esp_op_sta_remove(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct esp_pub *epub = (struct esp_pub *) hw->priv;
struct esp_vif *evif = (struct esp_vif *) vif->drv_priv;
int index;
ESP_IEEE80211_DBG(ESP_DBG_OP,
"%s enter, vif addr %pM, sta addr %pM\n",
__func__, vif->addr, sta->addr);
//remove a connect in target
index = esp_node_detach(hw, evif->index, sta);
sip_send_set_sta(epub, evif->index, 0, sta, vif, (u8) index);
return 0;
}
static void esp_op_sta_notify(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
enum sta_notify_cmd cmd,
struct ieee80211_sta *sta)
{
ESP_IEEE80211_DBG(ESP_DBG_TRACE, "%s enter \n", __func__);
switch (cmd) {
case STA_NOTIFY_SLEEP:
break;
case STA_NOTIFY_AWAKE:
break;
default:
break;
}
}
static int esp_op_conf_tx(struct ieee80211_hw *hw,