137
139
mac->link_state = MAC80211_LINKED;
138
140
rtlpriv->cfg->ops->set_bcn_reg(hw);
141
if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
142
mac->basic_rates = 0xfff;
144
mac->basic_rates = 0xff0;
145
rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
146
(u8 *) (&mac->basic_rates));
140
149
case NL80211_IFTYPE_AP:
141
150
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
142
151
("NL80211_IFTYPE_AP\n"));
153
mac->link_state = MAC80211_LINKED;
154
rtlpriv->cfg->ops->set_bcn_reg(hw);
155
if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
156
mac->basic_rates = 0xfff;
158
mac->basic_rates = 0xff0;
159
rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
160
(u8 *) (&mac->basic_rates));
145
163
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
226
243
if (changed & IEEE80211_CONF_CHANGE_PS) {
227
if (conf->flags & IEEE80211_CONF_PS)
244
cancel_delayed_work(&rtlpriv->works.ps_work);
245
cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
246
if (conf->flags & IEEE80211_CONF_PS) {
247
rtlpriv->psc.sw_ps_enabled = true;
248
/* sleep here is must, or we may recv the beacon and
249
* cause mac80211 into wrong ps state, this will cause
250
* power save nullfunc send fail, and further cause
251
* pkt loss, So sleep must quickly but not immediatly
252
* because that will cause nullfunc send by mac80211
253
* fail, and cause pkt loss, we have tested that 5mA
254
* is worked very well */
255
if (!rtlpriv->psc.multi_buffered)
256
queue_delayed_work(rtlpriv->works.rtl_wq,
257
&rtlpriv->works.ps_work,
260
rtl_swlps_rf_awake(hw);
261
rtlpriv->psc.sw_ps_enabled = false;
233
265
if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
289
321
mac->bw_40 = false;
290
322
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
291
("switch case not processed\n"));
323
("switch case not processed\n"));
295
327
if (wide_chan <= 0)
330
/* In scanning, before we go offchannel we may send a ps=1 null
331
* to AP, and then we may send a ps = 0 null to AP quickly, but
332
* first null may have caused AP to put lots of packet to hw tx
333
* buffer. These packets must be tx'd before we go off channel
334
* so we must delay more time to let AP flush these packets
335
* before going offchannel, or dis-association or delete BA will
338
if (rtlpriv->mac80211.offchan_deley) {
339
rtlpriv->mac80211.offchan_deley = false;
297
342
rtlphy->current_channel = wide_chan;
344
rtlpriv->cfg->ops->switch_channel(hw);
299
345
rtlpriv->cfg->ops->set_channel_access(hw);
300
rtlpriv->cfg->ops->switch_channel(hw);
301
346
rtlpriv->cfg->ops->set_bw_mode(hw,
302
347
hw->conf.channel_type);
348
if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
350
*TODO: BIT(5) is probe response BIT(8) is beacon
351
*TODO: Use define for BIT(5) and BIT(8)
353
if (*new_flags & FIF_BCN_PRBRESP_PROMISC)
354
mac->rx_mgt_filter |= (BIT(5) | BIT(8));
356
mac->rx_mgt_filter &= ~(BIT(5) | BIT(8));
393
/* if ssid not set to hw don't check bssid
394
* here just used for linked scanning, & linked
395
* and nolink check bssid is set in set network_type */
396
if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
397
(mac->link_state >= MAC80211_LINKED)) {
398
if (mac->opmode != NL80211_IFTYPE_AP) {
399
if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
400
rtlpriv->cfg->ops->set_chk_bssid(hw, false);
402
rtlpriv->cfg->ops->set_chk_bssid(hw, true);
359
407
if (changed_flags & FIF_CONTROL) {
360
408
if (*new_flags & FIF_CONTROL) {
361
409
mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
362
mac->rx_ctrl_filter |= RTL_SUPPORTED_CTRL_FILTER;
364
411
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
365
412
("Enable receive control frame.\n"));
367
414
mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
368
mac->rx_ctrl_filter &= ~RTL_SUPPORTED_CTRL_FILTER;
369
415
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
370
416
("Disable receive control frame.\n"));
382
428
("Disable receive other BSS's frame.\n"));
386
rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
387
rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_MGT_FILTER,
388
(u8 *) (&mac->rx_mgt_filter));
389
rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CTRL_FILTER,
390
(u8 *) (&mac->rx_ctrl_filter));
432
static int rtl_op_sta_add(struct ieee80211_hw *hw,
433
struct ieee80211_vif *vif,
434
struct ieee80211_sta *sta)
436
struct rtl_priv *rtlpriv = rtl_priv(hw);
437
struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
438
struct rtl_sta_info *sta_entry;
441
sta_entry = (struct rtl_sta_info *) sta->drv_priv;
442
if (rtlhal->current_bandtype == BAND_ON_2_4G) {
443
sta_entry->wireless_mode = WIRELESS_MODE_G;
444
if (sta->supp_rates[0] <= 0xf)
445
sta_entry->wireless_mode = WIRELESS_MODE_B;
446
if (sta->ht_cap.ht_supported == true)
447
sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
448
} else if (rtlhal->current_bandtype == BAND_ON_5G) {
449
sta_entry->wireless_mode = WIRELESS_MODE_A;
450
if (sta->ht_cap.ht_supported == true)
451
sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
454
/* I found some times mac80211 give wrong supp_rates for adhoc*/
455
if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC)
456
sta_entry->wireless_mode = WIRELESS_MODE_G;
458
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
459
("Add sta addr is "MAC_FMT"\n", MAC_ARG(sta->addr)));
460
rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
464
static int rtl_op_sta_remove(struct ieee80211_hw *hw,
465
struct ieee80211_vif *vif,
466
struct ieee80211_sta *sta)
468
struct rtl_priv *rtlpriv = rtl_priv(hw);
469
struct rtl_sta_info *sta_entry;
471
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
472
("Remove sta addr is "MAC_FMT"\n", MAC_ARG(sta->addr)));
473
sta_entry = (struct rtl_sta_info *) sta->drv_priv;
474
sta_entry->wireless_mode = 0;
475
sta_entry->ratr_index = 0;
393
479
static int _rtl_get_hal_qnum(u16 queue)
446
532
struct ieee80211_bss_conf *bss_conf, u32 changed)
448
534
struct rtl_priv *rtlpriv = rtl_priv(hw);
535
struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
449
536
struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
450
537
struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
538
struct ieee80211_sta *sta = NULL;
452
540
mutex_lock(&rtlpriv->locks.conf_mutex);
454
541
if ((vif->type == NL80211_IFTYPE_ADHOC) ||
455
542
(vif->type == NL80211_IFTYPE_AP) ||
456
543
(vif->type == NL80211_IFTYPE_MESH_POINT)) {
458
544
if ((changed & BSS_CHANGED_BEACON) ||
459
545
(changed & BSS_CHANGED_BEACON_ENABLED &&
460
546
bss_conf->enable_beacon)) {
462
547
if (mac->beacon_enabled == 0) {
463
548
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
464
549
("BSS_CHANGED_BEACON_ENABLED\n"));
494
583
/*TODO: reference to enum ieee80211_bss_change */
495
584
if (changed & BSS_CHANGED_ASSOC) {
496
585
if (bss_conf->assoc) {
586
/* we should reset all sec info & cam
587
* before set cam after linked, we should not
588
* reset in disassoc, that will cause tkip->wep
589
* fail because some flag will be wrong */
591
rtl_cam_reset_sec_info(hw);
592
/* reset cam to fix wep fail issue
593
* when change from wpa to wep */
594
rtl_cam_reset_all_entry(hw);
497
596
mac->link_state = MAC80211_LINKED;
498
597
mac->cnt_after_linked = 0;
499
598
mac->assoc_id = bss_conf->aid;
500
599
memcpy(mac->bssid, bss_conf->bssid, 6);
601
if (rtlpriv->cfg->ops->linked_set_reg)
602
rtlpriv->cfg->ops->linked_set_reg(hw);
603
if (mac->opmode == NL80211_IFTYPE_STATION && sta)
604
rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
502
605
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
503
606
("BSS_CHANGED_ASSOC\n"));
585
680
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
586
681
(MAC_FMT "\n", MAC_ARG(bss_conf->bssid)));
683
mac->vendor = PEER_UNKNOWN;
588
684
memcpy(mac->bssid, bss_conf->bssid, 6);
589
if (is_valid_ether_addr(bss_conf->bssid)) {
591
case NL80211_IFTYPE_UNSPECIFIED:
593
case NL80211_IFTYPE_ADHOC:
595
case NL80211_IFTYPE_STATION:
597
case NL80211_IFTYPE_AP:
600
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
601
("switch case not process\n"));
604
rtlpriv->cfg->ops->set_network_type(hw, vif->type);
606
rtlpriv->cfg->ops->set_network_type(hw,
607
NL80211_IFTYPE_UNSPECIFIED);
609
memset(mac->mcs, 0, 16);
610
mac->ht_enable = false;
614
if (!bss_conf->use_short_slot)
615
mac->mode = WIRELESS_MODE_B;
617
mac->mode = WIRELESS_MODE_G;
685
rtlpriv->cfg->ops->set_network_type(hw, vif->type);
620
sta = ieee80211_find_sta(mac->vif, mac->bssid);
623
if (sta->ht_cap.ht_supported) {
688
sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
694
if (rtlhal->current_bandtype == BAND_ON_5G) {
695
mac->mode = WIRELESS_MODE_A;
697
if (sta->supp_rates[0] <= 0xf)
698
mac->mode = WIRELESS_MODE_B;
700
mac->mode = WIRELESS_MODE_G;
703
if (sta->ht_cap.ht_supported) {
704
if (rtlhal->current_bandtype == BAND_ON_2_4G)
624
705
mac->mode = WIRELESS_MODE_N_24G;
625
mac->ht_enable = true;
628
if (mac->ht_enable) {
629
u16 ht_cap = sta->ht_cap.cap;
630
memcpy(mac->mcs, (u8 *) (&sta->ht_cap.mcs), 16);
632
for (i = 0; i < 16; i++)
633
RT_TRACE(rtlpriv, COMP_MAC80211,
636
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
639
if (ht_cap & IEEE80211_HT_CAP_SGI_40)
642
if (ht_cap & IEEE80211_HT_CAP_SGI_20)
646
* for cisco 1252 bw20 it's wrong
648
* IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
656
/*mac80211 just give us CCK rates any time
657
*So we add G rate in basic rates when
707
mac->mode = WIRELESS_MODE_N_5G;
710
/* just station need it, because ibss & ap mode will
711
* set in sta_add, and will be NULL here */
712
if (mac->opmode == NL80211_IFTYPE_STATION) {
713
struct rtl_sta_info *sta_entry;
714
sta_entry = (struct rtl_sta_info *) sta->drv_priv;
715
sta_entry->wireless_mode = mac->mode;
718
if (sta->ht_cap.ht_supported) {
719
mac->ht_enable = true;
722
* for cisco 1252 bw20 it's wrong
723
* if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
659
729
if (changed & BSS_CHANGED_BASIC_RATES) {
660
if (mac->mode == WIRELESS_MODE_B)
661
basic_rates = bss_conf->basic_rates | 0x00f;
730
/* for 5G must << RATE_6M_INDEX=4,
731
* because 5G have no cck rate*/
732
if (rtlhal->current_bandtype == BAND_ON_5G)
733
basic_rates = sta->supp_rates[1] << 4;
663
basic_rates = bss_conf->basic_rates | 0xff0;
735
basic_rates = sta->supp_rates[0];
668
737
mac->basic_rates = basic_rates;
669
738
rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
670
739
(u8 *) (&basic_rates));
672
if (rtlpriv->dm.useramask)
673
rtlpriv->cfg->ops->update_rate_mask(hw, 0);
675
rtlpriv->cfg->ops->update_rate_table(hw);
760
824
case IEEE80211_AMPDU_TX_START:
761
825
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
762
826
("IEEE80211_AMPDU_TX_START: TID:%d\n", tid));
763
return rtl_tx_agg_start(hw, sta->addr, tid, ssn);
827
return rtl_tx_agg_start(hw, sta, tid, ssn);
765
829
case IEEE80211_AMPDU_TX_STOP:
766
830
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
767
831
("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid));
768
return rtl_tx_agg_stop(hw, sta->addr, tid);
832
return rtl_tx_agg_stop(hw, sta, tid);
770
834
case IEEE80211_AMPDU_TX_OPERATIONAL:
771
835
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
772
836
("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid));
837
rtl_tx_agg_oper(hw, sta, tid);
774
839
case IEEE80211_AMPDU_RX_START:
775
840
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
812
881
struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
814
883
RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
816
rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
817
884
mac->act_scanning = false;
886
rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
818
888
if (mac->link_state == MAC80211_LINKED_SCANNING) {
819
889
mac->link_state = MAC80211_LINKED;
821
/* fix fwlps issue */
822
rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
824
if (rtlpriv->dm.useramask)
825
rtlpriv->cfg->ops->update_rate_mask(hw, 0);
827
rtlpriv->cfg->ops->update_rate_table(hw);
890
if (mac->opmode == NL80211_IFTYPE_STATION) {
891
/* fix fwlps issue */
892
rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
896
rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
833
899
static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
858
924
rtl_ips_nic_on(hw);
859
925
mutex_lock(&rtlpriv->locks.conf_mutex);
860
926
/* <1> get encryption alg */
861
928
switch (key->cipher) {
862
929
case WLAN_CIPHER_SUITE_WEP40:
863
930
key_type = WEP40_ENCRYPTION;
864
931
RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n"));
865
rtlpriv->sec.use_defaultkey = true;
867
933
case WLAN_CIPHER_SUITE_WEP104:
868
934
RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
869
935
("alg:WEP104\n"));
870
936
key_type = WEP104_ENCRYPTION;
871
rtlpriv->sec.use_defaultkey = true;
873
938
case WLAN_CIPHER_SUITE_TKIP:
874
939
key_type = TKIP_ENCRYPTION;
875
940
RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n"));
876
if (mac->opmode == NL80211_IFTYPE_ADHOC)
877
rtlpriv->sec.use_defaultkey = true;
879
942
case WLAN_CIPHER_SUITE_CCMP:
880
943
key_type = AESCCMP_ENCRYPTION;
881
944
RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n"));
882
if (mac->opmode == NL80211_IFTYPE_ADHOC)
883
rtlpriv->sec.use_defaultkey = true;
886
947
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
887
948
("alg_err:%x!!!!:\n", key->cipher));
951
if (key_type == WEP40_ENCRYPTION ||
952
key_type == WEP104_ENCRYPTION ||
953
mac->opmode == NL80211_IFTYPE_ADHOC)
954
rtlpriv->sec.use_defaultkey = true;
890
956
/* <2> get key_idx */
891
957
key_idx = (u8) (key->keyidx);
894
960
/* <3> if pairwise key enable_hw_sec */
895
961
group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
896
if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
897
rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
898
if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION &&
899
(key_type == WEP40_ENCRYPTION ||
900
key_type == WEP104_ENCRYPTION))
902
rtlpriv->sec.pairwise_enc_algorithm = key_type;
903
rtlpriv->cfg->ops->enable_hw_sec(hw);
963
/* wep always be group key, but there are two conditions:
964
* 1) wep only: is just for wep enc, in this condition
965
* rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
966
* will be true & enable_hw_sec will be set when wep
968
* 2) wep(group) + AES(pairwise): some AP like cisco
969
* may use it, in this condition enable_hw_sec will not
970
* be set when wep key setting */
971
/* we must reset sec_info after lingked before set key,
972
* or some flag will be wrong*/
973
if (mac->opmode == NL80211_IFTYPE_AP) {
974
if (!group_key || key_type == WEP40_ENCRYPTION ||
975
key_type == WEP104_ENCRYPTION) {
978
rtlpriv->cfg->ops->enable_hw_sec(hw);
981
if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
982
rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
983
if (rtlpriv->sec.pairwise_enc_algorithm ==
985
(key_type == WEP40_ENCRYPTION ||
986
key_type == WEP104_ENCRYPTION))
988
rtlpriv->sec.pairwise_enc_algorithm = key_type;
989
RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
990
("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1"
991
" TKIP:2 AES:4 WEP104:5)\n", key_type));
992
rtlpriv->cfg->ops->enable_hw_sec(hw);
905
995
/* <4> set key based on cmd */
959
1050
RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
960
1051
("disable key delete one entry\n"));
961
1052
/*set local buf about wep key. */
1053
if (mac->opmode == NL80211_IFTYPE_AP) {
1055
rtl_cam_del_entry(hw, sta->addr);
962
1057
memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
963
1058
rtlpriv->sec.key_len[key_idx] = 0;
964
1059
memcpy(mac_addr, zero_addr, ETH_ALEN);
1011
1106
mutex_unlock(&rtlpriv->locks.conf_mutex);
1109
/* this function is called by mac80211 to flush tx buffer
1110
* before switch channle or power save, or tx buffer packet
1111
* maybe send after offchannel or rf sleep, this may cause
1112
* dis-association by AP */
1113
static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
1115
struct rtl_priv *rtlpriv = rtl_priv(hw);
1117
if (rtlpriv->intf_ops->flush)
1118
rtlpriv->intf_ops->flush(hw, drop);
1014
1121
const struct ieee80211_ops rtl_ops = {
1015
1122
.start = rtl_op_start,
1016
1123
.stop = rtl_op_stop,