-
Notifications
You must be signed in to change notification settings - Fork 2
/
bl_msg_tx.c
1310 lines (1067 loc) · 44.4 KB
/
bl_msg_tx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
******************************************************************************
*
* @file bl_msg_tx.c
*
* @brief TX function definitions
*
* Copyright (C) BouffaloLab 2017-2018
*
******************************************************************************
*/
#include <linux/version.h>
#include "bl_msg_tx.h"
#include "bl_mod_params.h"
#ifdef CONFIG_BL_BFMER
#include "bl_bfmer.h"
#endif //(CONFIG_BL_BFMER)
const struct mac_addr mac_addr_bcst = {{0xFFFF, 0xFFFF, 0xFFFF}};
/* Default MAC Rx filters that can be changed by mac80211
* (via the configure_filter() callback) */
#define BL_MAC80211_CHANGEABLE ( \
NXMAC_ACCEPT_BA_BIT | \
NXMAC_ACCEPT_BAR_BIT | \
NXMAC_ACCEPT_OTHER_DATA_FRAMES_BIT | \
NXMAC_ACCEPT_PROBE_REQ_BIT | \
NXMAC_ACCEPT_PS_POLL_BIT \
)
/* Default MAC Rx filters that cannot be changed by mac80211 */
#define BL_MAC80211_NOT_CHANGEABLE ( \
NXMAC_ACCEPT_QO_S_NULL_BIT | \
NXMAC_ACCEPT_Q_DATA_BIT | \
NXMAC_ACCEPT_DATA_BIT | \
NXMAC_ACCEPT_OTHER_MGMT_FRAMES_BIT | \
NXMAC_ACCEPT_MY_UNICAST_BIT | \
NXMAC_ACCEPT_BROADCAST_BIT | \
NXMAC_ACCEPT_BEACON_BIT | \
NXMAC_ACCEPT_PROBE_RESP_BIT \
)
/* Default MAC Rx filter */
#define BL_DEFAULT_RX_FILTER (BL_MAC80211_CHANGEABLE | BL_MAC80211_NOT_CHANGEABLE)
static const int bw2chnl[] = {
[NL80211_CHAN_WIDTH_20_NOHT] = PHY_CHNL_BW_20,
[NL80211_CHAN_WIDTH_20] = PHY_CHNL_BW_20,
[NL80211_CHAN_WIDTH_40] = PHY_CHNL_BW_40,
[NL80211_CHAN_WIDTH_80] = PHY_CHNL_BW_80,
[NL80211_CHAN_WIDTH_160] = PHY_CHNL_BW_160,
[NL80211_CHAN_WIDTH_80P80] = PHY_CHNL_BW_80P80,
};
static const int chnl2bw[] = {
[PHY_CHNL_BW_20] = NL80211_CHAN_WIDTH_20,
[PHY_CHNL_BW_40] = NL80211_CHAN_WIDTH_40,
[PHY_CHNL_BW_80] = NL80211_CHAN_WIDTH_80,
[PHY_CHNL_BW_160] = NL80211_CHAN_WIDTH_160,
[PHY_CHNL_BW_80P80] = NL80211_CHAN_WIDTH_80P80,
};
/*****************************************************************************/
/*
* Parse the ampdu density to retrieve the value in usec, according to the
* values defined in ieee80211.h
*/
static inline u8 bl_ampdudensity2usec(u8 ampdudensity)
{
switch (ampdudensity) {
case IEEE80211_HT_MPDU_DENSITY_NONE:
return 0;
/* 1 microsecond is our granularity */
case IEEE80211_HT_MPDU_DENSITY_0_25:
case IEEE80211_HT_MPDU_DENSITY_0_5:
case IEEE80211_HT_MPDU_DENSITY_1:
return 1;
case IEEE80211_HT_MPDU_DENSITY_2:
return 2;
case IEEE80211_HT_MPDU_DENSITY_4:
return 4;
case IEEE80211_HT_MPDU_DENSITY_8:
return 8;
case IEEE80211_HT_MPDU_DENSITY_16:
return 16;
default:
return 0;
}
}
static inline bool use_pairwise_key(struct cfg80211_crypto_settings *crypto)
{
if ((crypto->cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
(crypto->cipher_group == WLAN_CIPHER_SUITE_WEP104))
return false;
return true;
}
static inline bool is_non_blocking_msg(int id) {
return ((id == MM_TIM_UPDATE_REQ) || (id == ME_RC_SET_RATE_REQ) ||
(id == ME_TRAFFIC_IND_REQ));
}
static inline uint8_t passive_scan_flag(uint32_t flags) {
if (flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR))
return SCAN_PASSIVE_BIT;
return 0;
}
/**
******************************************************************************
* @brief Allocate memory for a message
*
* This primitive allocates memory for a message that has to be sent. The memory
* is allocated dynamically on the heap and the length of the variable parameter
* structure has to be provided in order to allocate the correct size.
*
* Several additional parameters are provided which will be preset in the message
* and which may be used internally to choose the kind of memory to allocate.
*
* The memory allocated will be automatically freed by the kernel, after the
* pointer has been sent to ke_msg_send(). If the message is not sent, it must
* be freed explicitly with ke_msg_free().
*
* Allocation failure is considered critical and should not happen.
*
* @param[in] id Message identifier
* @param[in] dest_id Destination Task Identifier
* @param[in] src_id Source Task Identifier
* @param[in] param_len Size of the message parameters to be allocated
*
* @return Pointer to the parameter member of the ke_msg. If the parameter
* structure is empty, the pointer will point to the end of the message
* and should not be used (except to retrieve the message pointer or to
* send the message)
******************************************************************************
*/
static inline void *bl_msg_zalloc(lmac_msg_id_t const id,
lmac_task_id_t const dest_id,
lmac_task_id_t const src_id,
uint16_t const param_len)
{
struct lmac_msg *msg;
gfp_t flags;
if (is_non_blocking_msg(id) && in_softirq())
flags = GFP_ATOMIC;
else
flags = GFP_KERNEL;
msg = (struct lmac_msg *)kzalloc(sizeof(struct lmac_msg) + param_len,
flags);
if (msg == NULL) {
printk(KERN_CRIT "%s: msg allocation failed\n", __func__);
return NULL;
}
msg->sdio_hdr.type = BL_TYPE_MSG;
msg->sdio_hdr.len = sizeof(struct lmac_msg) + param_len;
msg->sdio_hdr.queue_idx = 0;
msg->id = id;
msg->dest_id = dest_id;
msg->src_id = src_id;
msg->param_len = param_len;
return msg->param;
}
static int bl_send_msg(struct bl_hw *bl_hw, const void *msg_params,
int reqcfm, lmac_msg_id_t reqid, void *cfm)
{
struct lmac_msg *msg;
struct bl_cmd *cmd;
bool nonblock;
int ret;
BL_DBG(BL_FN_ENTRY_STR);
msg = container_of((void *)msg_params, struct lmac_msg, param);
if (!test_bit(BL_DEV_STARTED, &bl_hw->drv_flags) &&
reqid != MM_RESET_CFM && reqid != MM_VERSION_CFM &&
reqid != MM_START_CFM && reqid != MM_SET_IDLE_CFM &&
reqid != ME_CONFIG_CFM && reqid != MM_SET_PS_MODE_CFM &&
reqid != ME_CHAN_CONFIG_CFM) {
printk(KERN_CRIT "%s: bypassing (BL_DEV_RESTARTING set) 0x%02x\n",
__func__, reqid);
kfree(msg);
return -EBUSY;
} else if (!bl_hw->ipc_env) {
printk(KERN_CRIT "%s: bypassing (restart must have failed)\n", __func__);
kfree(msg);
return -EBUSY;
}
nonblock = is_non_blocking_msg(msg->id);
cmd = kzalloc(sizeof(struct bl_cmd), nonblock ? GFP_ATOMIC : GFP_KERNEL);
cmd->result = -EINTR;
cmd->id = msg->id;
cmd->reqid = reqid;
cmd->a2e_msg = msg;
cmd->e2a_msg = cfm;
if (nonblock)
cmd->flags = BL_CMD_FLAG_NONBLOCK;
if (reqcfm)
cmd->flags |= BL_CMD_FLAG_REQ_CFM;
ret = bl_hw->cmd_mgr.queue(&bl_hw->cmd_mgr, cmd);
if (!nonblock)
kfree(cmd);
else
ret = cmd->result;
return ret;
}
/******************************************************************************
* Control messages handling functions (SOFTMAC and FULLMAC)
*****************************************************************************/
int bl_send_reset(struct bl_hw *bl_hw)
{
void *void_param;
BL_DBG(BL_FN_ENTRY_STR);
/* RESET REQ has no parameter */
void_param = bl_msg_zalloc(MM_RESET_REQ, TASK_MM, DRV_TASK_ID, 0);
if (!void_param)
return -ENOMEM;
return bl_send_msg(bl_hw, void_param, 1, MM_RESET_CFM, NULL);
}
int bl_send_start(struct bl_hw *bl_hw)
{
struct mm_start_req *start_req_param;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the START REQ message */
start_req_param = bl_msg_zalloc(MM_START_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_start_req));
if (!start_req_param)
return -ENOMEM;
/* Set parameters for the START message */
memcpy(&start_req_param->phy_cfg, &bl_hw->phy_config, sizeof(bl_hw->phy_config));
start_req_param->uapsd_timeout = (u32_l)bl_hw->mod_params->uapsd_timeout;
start_req_param->lp_clk_accuracy = (u16_l)bl_hw->mod_params->lp_clk_ppm;
/* Send the START REQ message to LMAC FW */
return bl_send_msg(bl_hw, start_req_param, 1, MM_START_CFM, NULL);
}
int bl_send_version_req(struct bl_hw *bl_hw, struct mm_version_cfm *cfm)
{
void *void_param;
BL_DBG(BL_FN_ENTRY_STR);
/* VERSION REQ has no parameter */
void_param = bl_msg_zalloc(MM_VERSION_REQ, TASK_MM, DRV_TASK_ID, 0);
if (!void_param)
return -ENOMEM;
return bl_send_msg(bl_hw, void_param, 1, MM_VERSION_CFM, cfm);
}
int bl_send_add_if(struct bl_hw *bl_hw, const unsigned char *mac,
enum nl80211_iftype iftype, bool p2p, struct mm_add_if_cfm *cfm)
{
struct mm_add_if_req *add_if_req_param;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ADD_IF_REQ message */
add_if_req_param = bl_msg_zalloc(MM_ADD_IF_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_add_if_req));
if (!add_if_req_param)
return -ENOMEM;
/* Set parameters for the ADD_IF_REQ message */
memcpy(&(add_if_req_param->addr.array[0]), mac, ETH_ALEN);
switch (iftype) {
#ifdef CONFIG_BL_FULLMAC
case NL80211_IFTYPE_P2P_CLIENT:
add_if_req_param->p2p = true;
// no break
#endif /* CONFIG_BL_FULLMAC */
case NL80211_IFTYPE_STATION:
add_if_req_param->type = MM_STA;
break;
case NL80211_IFTYPE_ADHOC:
add_if_req_param->type = MM_IBSS;
break;
#ifdef CONFIG_BL_FULLMAC
case NL80211_IFTYPE_P2P_GO:
add_if_req_param->p2p = true;
// no break
#endif /* CONFIG_BL_FULLMAC */
case NL80211_IFTYPE_AP:
add_if_req_param->type = MM_AP;
break;
case NL80211_IFTYPE_MESH_POINT:
add_if_req_param->type = MM_MESH_POINT;
break;
case NL80211_IFTYPE_AP_VLAN:
return -1;
default:
add_if_req_param->type = MM_STA;
break;
}
/* Send the ADD_IF_REQ message to LMAC FW */
return bl_send_msg(bl_hw, add_if_req_param, 1, MM_ADD_IF_CFM, cfm);
}
int bl_send_remove_if(struct bl_hw *bl_hw, u8 vif_index)
{
struct mm_remove_if_req *remove_if_req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_REMOVE_IF_REQ message */
remove_if_req = bl_msg_zalloc(MM_REMOVE_IF_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_remove_if_req));
if (!remove_if_req)
return -ENOMEM;
/* Set parameters for the MM_REMOVE_IF_REQ message */
remove_if_req->inst_nbr = vif_index;
/* Send the MM_REMOVE_IF_REQ message to LMAC FW */
return bl_send_msg(bl_hw, remove_if_req, 1, MM_REMOVE_IF_CFM, NULL);
}
int bl_send_set_channel(struct bl_hw *bl_hw, int phy_idx,
struct mm_set_channel_cfm *cfm)
{
struct mm_set_channel_req *set_chnl_par;
enum nl80211_chan_width width;
u16 center_freq, center_freq1, center_freq2;
s8 tx_power = 0;
enum nl80211_band band;
BL_DBG(BL_FN_ENTRY_STR);
if (phy_idx >= bl_hw->phy_cnt)
return -ENOTSUPP;
set_chnl_par = bl_msg_zalloc(MM_SET_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_channel_req));
if (!set_chnl_par)
return -ENOMEM;
if (phy_idx == 0) {
/* On FULLMAC only setting channel of secondary chain */
wiphy_err(bl_hw->wiphy, "Trying to set channel of primary chain");
return 0;
} else {
struct bl_sec_phy_chan *chan = &bl_hw->sec_phy_chan;
width = chnl2bw[chan->type];
band = chan->band;
center_freq = chan->prim20_freq;
center_freq1 = chan->center_freq1;
center_freq2 = chan->center_freq2;
}
set_chnl_par->band = band;
set_chnl_par->type = bw2chnl[width];
set_chnl_par->prim20_freq = center_freq;
set_chnl_par->center1_freq = center_freq1;
set_chnl_par->center2_freq = center_freq2;
set_chnl_par->index = phy_idx;
set_chnl_par->tx_power = tx_power;
if (bl_hw->use_phy_bw_tweaks) {
/* XXX Tweak for 80MHz VHT */
if (width > NL80211_CHAN_WIDTH_40) {
int _offs = center_freq1 - center_freq;
set_chnl_par->type = PHY_CHNL_BW_40;
set_chnl_par->center1_freq = center_freq + 10 *
(_offs > 0 ? 1 : -1) * (abs(_offs) > 10 ? 1 : -1);
BL_DBG("Tweak for 80MHz VHT: 80MHz chan requested\n");
}
}
BL_DBG("mac80211: freq=%d(c1:%d - c2:%d)/width=%d - band=%d\n"
" hw(%d): prim20=%d(c1:%d - c2:%d)/ type=%d - band=%d\n",
center_freq, center_freq1,
center_freq2, width, band,
phy_idx, set_chnl_par->prim20_freq, set_chnl_par->center1_freq,
set_chnl_par->center2_freq, set_chnl_par->type, set_chnl_par->band);
/* Send the MM_SET_CHANNEL_REQ REQ message to LMAC FW */
return bl_send_msg(bl_hw, set_chnl_par, 1, MM_SET_CHANNEL_CFM, cfm);
}
int bl_send_key_add(struct bl_hw *bl_hw, u8 vif_idx, u8 sta_idx, bool pairwise,
u8 *key, u8 key_len, u8 key_idx, u8 cipher_suite,
struct mm_key_add_cfm *cfm)
{
struct mm_key_add_req *key_add_req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_KEY_ADD_REQ message */
key_add_req = bl_msg_zalloc(MM_KEY_ADD_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_key_add_req));
if (!key_add_req)
return -ENOMEM;
/* Set parameters for the MM_KEY_ADD_REQ message */
if (sta_idx != 0xFF) {
/* Pairwise key */
key_add_req->sta_idx = sta_idx;
} else {
/* Default key */
key_add_req->sta_idx = sta_idx;
key_add_req->key_idx = (u8_l)key_idx; /* only useful for default keys */
}
key_add_req->pairwise = pairwise;
key_add_req->inst_nbr = vif_idx;
key_add_req->key.length = key_len;
memcpy(&(key_add_req->key.array[0]), key, key_len);
key_add_req->cipher_suite = cipher_suite;
BL_DBG("%s: sta_idx:%d key_idx:%d inst_nbr:%d cipher:%d key_len:%d\n", __func__,
key_add_req->sta_idx, key_add_req->key_idx, key_add_req->inst_nbr,
key_add_req->cipher_suite, key_add_req->key.length);
#if defined(CONFIG_BL_DBG) || defined(CONFIG_DYNAMIC_DEBUG)
print_hex_dump_bytes("key: ", DUMP_PREFIX_OFFSET, key_add_req->key.array, key_add_req->key.length);
#endif
/* Send the MM_KEY_ADD_REQ message to LMAC FW */
return bl_send_msg(bl_hw, key_add_req, 1, MM_KEY_ADD_CFM, cfm);
}
int bl_send_key_del(struct bl_hw *bl_hw, uint8_t hw_key_idx)
{
struct mm_key_del_req *key_del_req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_KEY_DEL_REQ message */
key_del_req = bl_msg_zalloc(MM_KEY_DEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_key_del_req));
if (!key_del_req)
return -ENOMEM;
/* Set parameters for the MM_KEY_DEL_REQ message */
key_del_req->hw_key_idx = hw_key_idx;
/* Send the MM_KEY_DEL_REQ message to LMAC FW */
return bl_send_msg(bl_hw, key_del_req, 1, MM_KEY_DEL_CFM, NULL);
}
int bl_send_bcn_change(struct bl_hw *bl_hw, u8 vif_idx, u8 *buf,
u16 bcn_len, u16 tim_oft, u16 tim_len, u16 *csa_oft)
{
struct mm_bcn_change_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_BCN_CHANGE_REQ message */
req = bl_msg_zalloc(MM_BCN_CHANGE_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_bcn_change_req) + bcn_len);
if (!req)
return -ENOMEM;
memcpy(req->bcn_buf, buf, bcn_len);
/* Set parameters for the MM_BCN_CHANGE_REQ message */
req->bcn_len = bcn_len;
req->tim_oft = tim_oft;
req->tim_len = tim_len;
req->inst_nbr = vif_idx;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
if (csa_oft) {
int i;
for (i = 0; i < BCN_MAX_CSA_CPT; i++) {
req->csa_oft[i] = csa_oft[i];
}
}
#endif /* VERSION >= 3.16.0 */
/* Send the MM_BCN_CHANGE_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, MM_BCN_CHANGE_CFM, NULL);
}
int bl_send_roc(struct bl_hw *bl_hw, struct bl_vif *vif,
struct ieee80211_channel *chan, unsigned int duration)
{
struct mm_remain_on_channel_req *req;
struct cfg80211_chan_def chandef;
BL_DBG(BL_FN_ENTRY_STR);
/* Create channel definition structure */
cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
/* Build the MM_REMAIN_ON_CHANNEL_REQ message */
req = bl_msg_zalloc(MM_REMAIN_ON_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_remain_on_channel_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_REMAIN_ON_CHANNEL_REQ message */
req->op_code = MM_ROC_OP_START;
req->vif_index = vif->vif_index;
req->duration_ms = duration;
req->band = chan->band;
req->type = bw2chnl[chandef.width];
req->prim20_freq = chan->center_freq;
req->center1_freq = chandef.center_freq1;
req->center2_freq = chandef.center_freq2;
req->tx_power = chan->max_power;
/* Send the MM_REMAIN_ON_CHANNEL_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, MM_REMAIN_ON_CHANNEL_CFM, NULL);
}
int bl_send_cancel_roc(struct bl_hw *bl_hw)
{
struct mm_remain_on_channel_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_REMAIN_ON_CHANNEL_REQ message */
req = bl_msg_zalloc(MM_REMAIN_ON_CHANNEL_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_remain_on_channel_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_REMAIN_ON_CHANNEL_REQ message */
req->op_code = MM_ROC_OP_CANCEL;
/* Send the MM_REMAIN_ON_CHANNEL_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 0, 0, NULL);
}
int bl_send_set_power(struct bl_hw *bl_hw, u8 vif_idx, s8 pwr,
struct mm_set_power_cfm *cfm)
{
struct mm_set_power_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_SET_POWER_REQ message */
req = bl_msg_zalloc(MM_SET_POWER_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_power_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_SET_POWER_REQ message */
req->inst_nbr = vif_idx;
req->power = pwr;
/* Send the MM_SET_POWER_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, MM_SET_POWER_CFM, cfm);
}
int bl_send_set_edca(struct bl_hw *bl_hw, u8 hw_queue, u32 param,
bool uapsd, u8 inst_nbr)
{
struct mm_set_edca_req *set_edca_req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_SET_EDCA_REQ message */
set_edca_req = bl_msg_zalloc(MM_SET_EDCA_REQ, TASK_MM, DRV_TASK_ID,
sizeof(struct mm_set_edca_req));
if (!set_edca_req)
return -ENOMEM;
/* Set parameters for the MM_SET_EDCA_REQ message */
set_edca_req->ac_param = param;
set_edca_req->uapsd = uapsd;
set_edca_req->hw_queue = hw_queue;
set_edca_req->inst_nbr = inst_nbr;
/* Send the MM_SET_EDCA_REQ message to LMAC FW */
return bl_send_msg(bl_hw, set_edca_req, 1, MM_SET_EDCA_CFM, NULL);
}
/******************************************************************************
* Control messages handling functions (FULLMAC only)
*****************************************************************************/
#ifdef CONFIG_BL_FULLMAC
int bl_send_me_config_req(struct bl_hw *bl_hw)
{
struct me_config_req *req;
struct wiphy *wiphy = bl_hw->wiphy;
struct ieee80211_sta_ht_cap *ht_cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap;
uint8_t *ht_mcs = (uint8_t *)&ht_cap->mcs;
int i;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ME_CONFIG_REQ message */
req = bl_msg_zalloc(ME_CONFIG_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_config_req));
if (!req)
return -ENOMEM;
/* Set parameters for the ME_CONFIG_REQ message */
BL_DBG("HT supp %d\n", ht_cap->ht_supported);
req->ht_supp = ht_cap->ht_supported;
req->ht_cap.ht_capa_info = cpu_to_le16(ht_cap->cap);
req->ht_cap.a_mpdu_param = ht_cap->ampdu_factor |
(ht_cap->ampdu_density <<
IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
for (i = 0; i < sizeof(ht_cap->mcs); i++)
req->ht_cap.mcs_rate[i] = ht_mcs[i];
req->ht_cap.ht_extended_capa = 0;
req->ht_cap.tx_beamforming_capa = 0;
req->ht_cap.asel_capa = 0;
req->ps_on = bl_hw->mod_params->ps_on;
req->tx_lft = bl_hw->mod_params->tx_lft;
/* Send the ME_CONFIG_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_CONFIG_CFM, NULL);
}
int bl_send_me_chan_config_req(struct bl_hw *bl_hw)
{
struct me_chan_config_req *req;
struct wiphy *wiphy = bl_hw->wiphy;
int i;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ME_CHAN_CONFIG_REQ message */
req = bl_msg_zalloc(ME_CHAN_CONFIG_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_chan_config_req));
if (!req)
return -ENOMEM;
req->chan2G4_cnt= 0;
if (wiphy->bands[NL80211_BAND_2GHZ] != NULL) {
struct ieee80211_supported_band *b = wiphy->bands[NL80211_BAND_2GHZ];
for (i = 0; i < b->n_channels; i++) {
req->chan2G4[req->chan2G4_cnt].flags = 0;
if (b->channels[i].flags & IEEE80211_CHAN_DISABLED)
req->chan2G4[req->chan2G4_cnt].flags |= SCAN_DISABLED_BIT;
req->chan2G4[req->chan2G4_cnt].flags |= passive_scan_flag(b->channels[i].flags);
req->chan2G4[req->chan2G4_cnt].band = NL80211_BAND_2GHZ;
req->chan2G4[req->chan2G4_cnt].freq = b->channels[i].center_freq;
req->chan2G4[req->chan2G4_cnt].tx_power = b->channels[i].max_power;
req->chan2G4_cnt++;
if (req->chan2G4_cnt == SCAN_CHANNEL_2G4)
break;
}
}
req->chan5G_cnt = 0;
if (wiphy->bands[NL80211_BAND_5GHZ] != NULL) {
struct ieee80211_supported_band *b = wiphy->bands[NL80211_BAND_5GHZ];
for (i = 0; i < b->n_channels; i++) {
req->chan5G[req->chan5G_cnt].flags = 0;
if (b->channels[i].flags & IEEE80211_CHAN_DISABLED)
req->chan5G[req->chan5G_cnt].flags |= SCAN_DISABLED_BIT;
req->chan5G[req->chan5G_cnt].flags |= passive_scan_flag(b->channels[i].flags);
req->chan5G[req->chan5G_cnt].band = NL80211_BAND_5GHZ;
req->chan5G[req->chan5G_cnt].freq = b->channels[i].center_freq;
req->chan5G[req->chan5G_cnt].tx_power = b->channels[i].max_power;
req->chan5G_cnt++;
if (req->chan5G_cnt == SCAN_CHANNEL_5G)
break;
}
}
/* Send the ME_CHAN_CONFIG_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_CHAN_CONFIG_CFM, NULL);
}
int bl_send_me_set_control_port_req(struct bl_hw *bl_hw, bool opened, u8 sta_idx)
{
struct me_set_control_port_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ME_SET_CONTROL_PORT_REQ message */
req = bl_msg_zalloc(ME_SET_CONTROL_PORT_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_set_control_port_req));
if (!req)
return -ENOMEM;
/* Set parameters for the ME_SET_CONTROL_PORT_REQ message */
req->sta_idx = sta_idx;
req->control_port_open = opened;
/* Send the ME_SET_CONTROL_PORT_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_SET_CONTROL_PORT_CFM, NULL);
}
int bl_send_me_sta_add(struct bl_hw *bl_hw, struct station_parameters *params,
const u8 *mac, u8 inst_nbr, struct me_sta_add_cfm *cfm)
{
struct me_sta_add_req *req;
u8 *ht_mcs = (u8 *)¶ms->ht_capa->mcs;
int i;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_STA_ADD_REQ message */
req = bl_msg_zalloc(ME_STA_ADD_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_sta_add_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_STA_ADD_REQ message */
memcpy(&(req->mac_addr.array[0]), mac, ETH_ALEN);
req->rate_set.length = params->supported_rates_len;
for (i = 0; i < params->supported_rates_len; i++)
req->rate_set.array[i] = params->supported_rates[i];
req->flags = 0;
if (params->ht_capa) {
const struct ieee80211_ht_cap *ht_capa = params->ht_capa;
req->flags |= STA_HT_CAPA;
req->ht_cap.ht_capa_info = cpu_to_le16(ht_capa->cap_info);
req->ht_cap.a_mpdu_param = ht_capa->ampdu_params_info;
for (i = 0; i < sizeof(ht_capa->mcs); i++)
req->ht_cap.mcs_rate[i] = ht_mcs[i];
req->ht_cap.ht_extended_capa = cpu_to_le16(ht_capa->extended_ht_cap_info);
req->ht_cap.tx_beamforming_capa = cpu_to_le32(ht_capa->tx_BF_cap_info);
req->ht_cap.asel_capa = ht_capa->antenna_selection_info;
}
if (params->vht_capa) {
const struct ieee80211_vht_cap *vht_capa = params->vht_capa;
req->flags |= STA_VHT_CAPA;
req->vht_cap.vht_capa_info = cpu_to_le32(vht_capa->vht_cap_info);
req->vht_cap.rx_highest = cpu_to_le16(vht_capa->supp_mcs.rx_highest);
req->vht_cap.rx_mcs_map = cpu_to_le16(vht_capa->supp_mcs.rx_mcs_map);
req->vht_cap.tx_highest = cpu_to_le16(vht_capa->supp_mcs.tx_highest);
req->vht_cap.tx_mcs_map = cpu_to_le16(vht_capa->supp_mcs.tx_mcs_map);
}
if (params->sta_flags_set & BIT(NL80211_STA_FLAG_WME))
req->flags |= STA_QOS_CAPA;
if (params->sta_flags_set & BIT(NL80211_STA_FLAG_MFP))
req->flags |= STA_MFP_CAPA;
if (params->opmode_notif_used) {
req->flags |= STA_OPMOD_NOTIF;
req->opmode = params->opmode_notif;
}
req->aid = cpu_to_le16(params->aid);
req->uapsd_queues = params->uapsd_queues;
req->max_sp_len = params->max_sp * 2;
req->vif_idx = inst_nbr;
if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
req->tdls_sta = true;
/* Send the ME_STA_ADD_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_STA_ADD_CFM, cfm);
}
int bl_send_me_sta_del(struct bl_hw *bl_hw, u8 sta_idx, bool tdls_sta)
{
struct me_sta_del_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the MM_STA_DEL_REQ message */
req = bl_msg_zalloc(ME_STA_DEL_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_sta_del_req));
if (!req)
return -ENOMEM;
/* Set parameters for the MM_STA_DEL_REQ message */
req->sta_idx = sta_idx;
req->tdls_sta = tdls_sta;
/* Send the ME_STA_DEL_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_STA_DEL_CFM, NULL);
}
int bl_send_me_traffic_ind(struct bl_hw *bl_hw, u8 sta_idx, bool uapsd, u8 tx_status)
{
struct me_traffic_ind_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ME_UTRAFFIC_IND_REQ message */
req = bl_msg_zalloc(ME_TRAFFIC_IND_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_traffic_ind_req));
if (!req)
return -ENOMEM;
/* Set parameters for the ME_TRAFFIC_IND_REQ message */
req->sta_idx = sta_idx;
req->tx_avail = tx_status;
req->uapsd = uapsd;
/* Send the ME_TRAFFIC_IND_REQ to UMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_TRAFFIC_IND_CFM, NULL);
}
int bl_send_me_rc_stats(struct bl_hw *bl_hw,
u8 sta_idx,
struct me_rc_stats_cfm *cfm)
{
struct me_rc_stats_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ME_RC_STATS_REQ message */
req = bl_msg_zalloc(ME_RC_STATS_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_rc_stats_req));
if (!req)
return -ENOMEM;
/* Set parameters for the ME_RC_STATS_REQ message */
req->sta_idx = sta_idx;
/* Send the ME_RC_STATS_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, ME_RC_STATS_CFM, cfm);
}
int bl_send_me_rc_set_rate(struct bl_hw *bl_hw,
u8 sta_idx,
u16 rate_cfg)
{
struct me_rc_set_rate_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the ME_RC_SET_RATE_REQ message */
req = bl_msg_zalloc(ME_RC_SET_RATE_REQ, TASK_ME, DRV_TASK_ID,
sizeof(struct me_rc_set_rate_req));
if (!req)
return -ENOMEM;
/* Set parameters for the ME_RC_SET_RATE_REQ message */
req->sta_idx = sta_idx;
req->fixed_rate_cfg = rate_cfg;
/* Send the ME_RC_SET_RATE_REQ message to FW */
return bl_send_msg(bl_hw, req, 0, 0, NULL);
}
int bl_send_sm_connect_req(struct bl_hw *bl_hw,
struct bl_vif *bl_vif,
struct cfg80211_connect_params *sme,
struct sm_connect_cfm *cfm)
{
struct sm_connect_req *req;
int i;
u32_l flags = 0;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the SM_CONNECT_REQ message */
req = bl_msg_zalloc(SM_CONNECT_REQ, TASK_SM, DRV_TASK_ID,
sizeof(struct sm_connect_req));
if (!req)
return -ENOMEM;
/* Set parameters for the SM_CONNECT_REQ message */
if (sme->crypto.n_ciphers_pairwise &&
((sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP40) ||
(sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_TKIP) ||
(sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP104)))
flags |= DISABLE_HT;
if (sme->crypto.control_port)
flags |= CONTROL_PORT_HOST;
if (sme->crypto.control_port_no_encrypt)
flags |= CONTROL_PORT_NO_ENC;
if (use_pairwise_key(&sme->crypto))
flags |= WPA_WPA2_IN_USE;
if (sme->mfp == NL80211_MFP_REQUIRED)
flags |= MFP_IN_USE;
if (sme->crypto.control_port_ethertype)
req->ctrl_port_ethertype = sme->crypto.control_port_ethertype;
else
req->ctrl_port_ethertype = ETH_P_PAE;
if (sme->bssid)
memcpy(&req->bssid, sme->bssid, ETH_ALEN);
else
req->bssid = mac_addr_bcst;
req->vif_idx = bl_vif->vif_index;
if (sme->channel) {
req->chan.band = sme->channel->band;
req->chan.freq = sme->channel->center_freq;
req->chan.flags = passive_scan_flag(sme->channel->flags);
} else {
req->chan.freq = (u16_l)-1;
}
for (i = 0; i < sme->ssid_len; i++)
req->ssid.array[i] = sme->ssid[i];
req->ssid.length = sme->ssid_len;
req->flags = flags;
if (WARN_ON(sme->ie_len > sizeof(req->ie_buf)))
return -EINVAL;
if (sme->ie_len)
memcpy(req->ie_buf, sme->ie, sme->ie_len);
req->ie_len = sme->ie_len;
req->listen_interval = bl_mod_params.listen_itv;
req->dont_wait_bcmc = !bl_mod_params.listen_bcmc;
/* Set auth_type */
if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC)
req->auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
else
req->auth_type = sme->auth_type;
/* Set UAPSD queues */
req->uapsd_queues = bl_mod_params.uapsd_queues;
/* Send the SM_CONNECT_REQ message to LMAC FW */
return bl_send_msg(bl_hw, req, 1, SM_CONNECT_CFM, cfm);
}
int bl_send_sm_disconnect_req(struct bl_hw *bl_hw,
struct bl_vif *bl_vif,
u16 reason)
{
struct sm_disconnect_req *req;
BL_DBG(BL_FN_ENTRY_STR);
/* Build the SM_DISCONNECT_REQ message */
req = bl_msg_zalloc(SM_DISCONNECT_REQ, TASK_SM, DRV_TASK_ID,
sizeof(struct sm_disconnect_req));
if (!req)
return -ENOMEM;
/* Set parameters for the SM_DISCONNECT_REQ message */
req->reason_code = reason;
req->vif_idx = bl_vif->vif_index;
/* Send the SM_DISCONNECT_REQ message to LMAC FW */
//return bl_send_msg(bl_hw, req, 1, SM_DISCONNECT_IND, NULL);
return bl_send_msg(bl_hw, req, 1, SM_DISCONNECT_CFM, NULL);
}
int bl_send_apm_start_req(struct bl_hw *bl_hw, struct bl_vif *vif,
struct cfg80211_ap_settings *settings,
struct apm_start_cfm *cfm, struct bl_dma_elem *elem)
{
struct apm_start_req *req;
struct bl_bcn *bcn = &vif->ap.bcn;
u8 *buf;
u32 flags = 0;
const u8 *rate_ie;
u8 rate_len = 0;
int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
const u8 *var_pos;
int len, i;
BL_DBG(BL_FN_ENTRY_STR);
// Build the beacon
bcn->dtim = (u8)settings->dtim_period;
buf = bl_build_bcn(bcn, &settings->beacon);
if (!buf) {
return -ENOMEM;
}
/* Build the APM_START_REQ message */
req = bl_msg_zalloc(APM_START_REQ, TASK_APM, DRV_TASK_ID,
sizeof(struct apm_start_req) + bcn->len);
if (!req)
return -ENOMEM;
// Retrieve the basic rate set from the beacon buffer
len = bcn->len - var_offset;
var_pos = buf + var_offset;
rate_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
if (rate_ie) {
const u8 *rates = rate_ie + 2;
for (i = 0; i < rate_ie[1]; i++) {
if (rates[i] & 0x80)