1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
37 #include <linux/export.h>
39 void rtl_fw_cb(const struct firmware
*firmware
, void *context
)
41 struct ieee80211_hw
*hw
= context
;
42 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
45 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
46 "Firmware callback routine entered!\n");
47 complete(&rtlpriv
->firmware_loading_complete
);
49 pr_err("Firmware %s not available\n", rtlpriv
->cfg
->fw_name
);
50 rtlpriv
->max_fw_size
= 0;
53 if (firmware
->size
> rtlpriv
->max_fw_size
) {
54 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
55 "Firmware is too big!\n");
56 release_firmware(firmware
);
59 memcpy(rtlpriv
->rtlhal
.pfirmware
, firmware
->data
, firmware
->size
);
60 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
61 release_firmware(firmware
);
63 err
= ieee80211_register_hw(hw
);
65 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
66 "Can't register mac80211 hw\n");
69 rtlpriv
->mac80211
.mac80211_registered
= 1;
71 set_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
);
76 EXPORT_SYMBOL(rtl_fw_cb
);
78 /*mutex for start & stop is must here. */
79 static int rtl_op_start(struct ieee80211_hw
*hw
)
82 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
83 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
85 if (!is_hal_stop(rtlhal
))
87 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
89 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
90 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
92 rtl_watch_dog_timer_callback((unsigned long)hw
);
93 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
97 static void rtl_op_stop(struct ieee80211_hw
*hw
)
99 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
100 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
101 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
102 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
104 if (is_hal_stop(rtlhal
))
107 /* here is must, because adhoc do stop and start,
108 * but stop with RFOFF may cause something wrong,
111 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
)) {
115 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
117 mac
->link_state
= MAC80211_NOLINK
;
118 memset(mac
->bssid
, 0, 6);
119 mac
->vendor
= PEER_UNKNOWN
;
122 rtl_cam_reset_sec_info(hw
);
124 rtl_deinit_deferred_work(hw
);
125 rtlpriv
->intf_ops
->adapter_stop(hw
);
127 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
130 static void rtl_op_tx(struct ieee80211_hw
*hw
,
131 struct ieee80211_tx_control
*control
,
134 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
135 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
136 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
137 struct rtl_tcb_desc tcb_desc
;
138 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
140 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
143 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
146 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, control
->sta
, skb
))
147 rtlpriv
->intf_ops
->adapter_tx(hw
, control
->sta
, skb
, &tcb_desc
);
152 dev_kfree_skb_any(skb
);
155 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
156 struct ieee80211_vif
*vif
)
158 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
159 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
162 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
165 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
166 "vif has been set!! mac->vif = 0x%p\n", mac
->vif
);
172 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
174 switch (ieee80211_vif_type_p2p(vif
)) {
175 case NL80211_IFTYPE_P2P_CLIENT
:
176 mac
->p2p
= P2P_ROLE_CLIENT
;
178 case NL80211_IFTYPE_STATION
:
179 if (mac
->beacon_enabled
== 1) {
180 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
181 "NL80211_IFTYPE_STATION\n");
182 mac
->beacon_enabled
= 0;
183 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
185 [RTL_IBSS_INT_MASKS
]);
188 case NL80211_IFTYPE_ADHOC
:
189 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
190 "NL80211_IFTYPE_ADHOC\n");
192 mac
->link_state
= MAC80211_LINKED
;
193 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
194 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
195 mac
->basic_rates
= 0xfff;
197 mac
->basic_rates
= 0xff0;
198 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
199 (u8
*) (&mac
->basic_rates
));
202 case NL80211_IFTYPE_P2P_GO
:
203 mac
->p2p
= P2P_ROLE_GO
;
205 case NL80211_IFTYPE_AP
:
206 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
207 "NL80211_IFTYPE_AP\n");
209 mac
->link_state
= MAC80211_LINKED
;
210 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
211 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
212 mac
->basic_rates
= 0xfff;
214 mac
->basic_rates
= 0xff0;
215 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
216 (u8
*) (&mac
->basic_rates
));
218 case NL80211_IFTYPE_MESH_POINT
:
219 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
220 "NL80211_IFTYPE_MESH_POINT\n");
222 mac
->link_state
= MAC80211_LINKED
;
223 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
224 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
225 mac
->basic_rates
= 0xfff;
227 mac
->basic_rates
= 0xff0;
228 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
229 (u8
*)(&mac
->basic_rates
));
232 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
233 "operation mode %d is not supported!\n", vif
->type
);
239 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
240 "p2p role %x\n", vif
->type
);
241 mac
->basic_rates
= 0xff0;/*disable cck rate for p2p*/
242 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
243 (u8
*)(&mac
->basic_rates
));
246 mac
->opmode
= vif
->type
;
247 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
248 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
249 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
252 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
256 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
257 struct ieee80211_vif
*vif
)
259 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
260 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
262 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
264 /* Free beacon resources */
265 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
266 (vif
->type
== NL80211_IFTYPE_ADHOC
) ||
267 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
268 if (mac
->beacon_enabled
== 1) {
269 mac
->beacon_enabled
= 0;
270 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
272 [RTL_IBSS_INT_MASKS
]);
277 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
278 *NO LINK for our hardware.
282 mac
->link_state
= MAC80211_NOLINK
;
283 memset(mac
->bssid
, 0, 6);
284 mac
->vendor
= PEER_UNKNOWN
;
285 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
286 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
287 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
290 static int rtl_op_change_interface(struct ieee80211_hw
*hw
,
291 struct ieee80211_vif
*vif
,
292 enum nl80211_iftype new_type
, bool p2p
)
294 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
296 rtl_op_remove_interface(hw
, vif
);
298 vif
->type
= new_type
;
300 ret
= rtl_op_add_interface(hw
, vif
);
301 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
306 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
308 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
309 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
310 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
311 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
312 struct ieee80211_conf
*conf
= &hw
->conf
;
317 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
318 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /*BIT(2)*/
319 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
320 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
324 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
325 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
331 *although rfoff may not cause by ips, but we will
332 *check the reason in set_rf_power_state function
334 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
339 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
340 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
341 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
342 if (conf
->flags
& IEEE80211_CONF_PS
) {
343 rtlpriv
->psc
.sw_ps_enabled
= true;
344 /* sleep here is must, or we may recv the beacon and
345 * cause mac80211 into wrong ps state, this will cause
346 * power save nullfunc send fail, and further cause
347 * pkt loss, So sleep must quickly but not immediatly
348 * because that will cause nullfunc send by mac80211
349 * fail, and cause pkt loss, we have tested that 5mA
350 * is worked very well */
351 if (!rtlpriv
->psc
.multi_buffered
)
352 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
353 &rtlpriv
->works
.ps_work
,
356 rtl_swlps_rf_awake(hw
);
357 rtlpriv
->psc
.sw_ps_enabled
= false;
361 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
362 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
363 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
364 hw
->conf
.long_frame_max_tx_count
);
365 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
366 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
367 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
369 long_frame_max_tx_count
));
372 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
373 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
374 u8 wide_chan
= (u8
) channel
->hw_value
;
376 if (mac
->act_scanning
)
379 if (rtlpriv
->dm
.supp_phymode_switch
&&
380 mac
->link_state
< MAC80211_LINKED
&&
381 !mac
->act_scanning
) {
382 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
383 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
387 *because we should back channel to
388 *current_network.chan in in scanning,
389 *So if set_chan == current_network.chan
391 *because mac80211 tell us wrong bw40
392 *info for cisco1253 bw20, so we modify
393 *it here based on UPPER & LOWER
395 switch (cfg80211_get_chandef_type(&hw
->conf
.chandef
)) {
396 case NL80211_CHAN_HT20
:
397 case NL80211_CHAN_NO_HT
:
399 mac
->cur_40_prime_sc
=
400 PRIME_CHNL_OFFSET_DONT_CARE
;
401 rtlphy
->current_chan_bw
= HT_CHANNEL_WIDTH_20
;
404 case NL80211_CHAN_HT40MINUS
:
406 mac
->cur_40_prime_sc
= PRIME_CHNL_OFFSET_UPPER
;
407 rtlphy
->current_chan_bw
=
408 HT_CHANNEL_WIDTH_20_40
;
415 case NL80211_CHAN_HT40PLUS
:
417 mac
->cur_40_prime_sc
= PRIME_CHNL_OFFSET_LOWER
;
418 rtlphy
->current_chan_bw
=
419 HT_CHANNEL_WIDTH_20_40
;
428 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
429 "switch case not processed\n");
436 /* In scanning, before we go offchannel we may send a ps = 1
437 * null to AP, and then we may send a ps = 0 null to AP quickly,
438 * but first null may have caused AP to put lots of packet to
439 * hw tx buffer. These packets must be tx'd before we go off
440 * channel so we must delay more time to let AP flush these
441 * packets before going offchannel, or dis-association or
442 * delete BA will be caused by AP
444 if (rtlpriv
->mac80211
.offchan_delay
) {
445 rtlpriv
->mac80211
.offchan_delay
= false;
448 rtlphy
->current_channel
= wide_chan
;
450 rtlpriv
->cfg
->ops
->switch_channel(hw
);
451 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
452 rtlpriv
->cfg
->ops
->set_bw_mode(hw
,
453 cfg80211_get_chandef_type(&hw
->conf
.chandef
));
456 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
461 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
462 unsigned int changed_flags
,
463 unsigned int *new_flags
, u64 multicast
)
465 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
466 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
468 *new_flags
&= RTL_SUPPORTED_FILTERS
;
472 /*TODO: we disable broadcase now, so enable here */
473 if (changed_flags
& FIF_ALLMULTI
) {
474 if (*new_flags
& FIF_ALLMULTI
) {
475 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
476 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
477 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
478 "Enable receive multicast frame\n");
480 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
481 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
482 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
483 "Disable receive multicast frame\n");
487 if (changed_flags
& FIF_FCSFAIL
) {
488 if (*new_flags
& FIF_FCSFAIL
) {
489 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
490 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
491 "Enable receive FCS error frame\n");
493 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
494 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
495 "Disable receive FCS error frame\n");
499 /* if ssid not set to hw don't check bssid
500 * here just used for linked scanning, & linked
501 * and nolink check bssid is set in set network_type */
502 if ((changed_flags
& FIF_BCN_PRBRESP_PROMISC
) &&
503 (mac
->link_state
>= MAC80211_LINKED
)) {
504 if (mac
->opmode
!= NL80211_IFTYPE_AP
&&
505 mac
->opmode
!= NL80211_IFTYPE_MESH_POINT
) {
506 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
) {
507 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, false);
509 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, true);
514 if (changed_flags
& FIF_CONTROL
) {
515 if (*new_flags
& FIF_CONTROL
) {
516 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
518 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
519 "Enable receive control frame\n");
521 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
522 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
523 "Disable receive control frame\n");
527 if (changed_flags
& FIF_OTHER_BSS
) {
528 if (*new_flags
& FIF_OTHER_BSS
) {
529 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
530 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
531 "Enable receive other BSS's frame\n");
533 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
534 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
535 "Disable receive other BSS's frame\n");
539 static int rtl_op_sta_add(struct ieee80211_hw
*hw
,
540 struct ieee80211_vif
*vif
,
541 struct ieee80211_sta
*sta
)
543 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
544 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
545 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
546 struct rtl_sta_info
*sta_entry
;
549 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
550 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
551 list_add_tail(&sta_entry
->list
, &rtlpriv
->entry_list
);
552 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
553 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
554 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
555 if (sta
->supp_rates
[0] <= 0xf)
556 sta_entry
->wireless_mode
= WIRELESS_MODE_B
;
557 if (sta
->ht_cap
.ht_supported
== true)
558 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
560 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
561 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
562 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
563 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
564 if (sta
->ht_cap
.ht_supported
== true)
565 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
567 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
568 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
570 /*disable cck rate for p2p*/
572 sta
->supp_rates
[0] &= 0xfffffff0;
574 memcpy(sta_entry
->mac_addr
, sta
->addr
, ETH_ALEN
);
575 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
576 "Add sta addr is %pM\n", sta
->addr
);
577 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
582 static int rtl_op_sta_remove(struct ieee80211_hw
*hw
,
583 struct ieee80211_vif
*vif
,
584 struct ieee80211_sta
*sta
)
586 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
587 struct rtl_sta_info
*sta_entry
;
589 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
590 "Remove sta addr is %pM\n", sta
->addr
);
591 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
592 sta_entry
->wireless_mode
= 0;
593 sta_entry
->ratr_index
= 0;
595 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
596 list_del(&sta_entry
->list
);
597 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
602 static int _rtl_get_hal_qnum(u16 queue
)
627 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
628 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
630 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
,
631 struct ieee80211_vif
*vif
, u16 queue
,
632 const struct ieee80211_tx_queue_params
*param
)
634 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
635 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
638 if (queue
>= AC_MAX
) {
639 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
640 "queue number %d is incorrect!\n", queue
);
644 aci
= _rtl_get_hal_qnum(queue
);
645 mac
->ac
[aci
].aifs
= param
->aifs
;
646 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
647 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
648 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
649 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
650 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
654 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
655 struct ieee80211_vif
*vif
,
656 struct ieee80211_bss_conf
*bss_conf
, u32 changed
)
658 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
659 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
660 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
661 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
662 struct ieee80211_sta
*sta
= NULL
;
664 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
665 if ((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
666 (vif
->type
== NL80211_IFTYPE_AP
) ||
667 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
668 if ((changed
& BSS_CHANGED_BEACON
) ||
669 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
670 bss_conf
->enable_beacon
)) {
671 if (mac
->beacon_enabled
== 0) {
672 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
673 "BSS_CHANGED_BEACON_ENABLED\n");
675 /*start hw beacon interrupt. */
676 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
677 mac
->beacon_enabled
= 1;
678 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
680 [RTL_IBSS_INT_MASKS
],
683 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
684 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
687 if ((changed
& BSS_CHANGED_BEACON_ENABLED
&&
688 !bss_conf
->enable_beacon
)) {
689 if (mac
->beacon_enabled
== 1) {
690 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
691 "ADHOC DISABLE BEACON\n");
693 mac
->beacon_enabled
= 0;
694 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
696 [RTL_IBSS_INT_MASKS
]);
699 if (changed
& BSS_CHANGED_BEACON_INT
) {
700 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
701 "BSS_CHANGED_BEACON_INT\n");
702 mac
->beacon_interval
= bss_conf
->beacon_int
;
703 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
707 /*TODO: reference to enum ieee80211_bss_change */
708 if (changed
& BSS_CHANGED_ASSOC
) {
709 if (bss_conf
->assoc
) {
710 struct ieee80211_sta
*sta
= NULL
;
711 /* we should reset all sec info & cam
712 * before set cam after linked, we should not
713 * reset in disassoc, that will cause tkip->wep
714 * fail because some flag will be wrong */
716 rtl_cam_reset_sec_info(hw
);
717 /* reset cam to fix wep fail issue
718 * when change from wpa to wep */
719 rtl_cam_reset_all_entry(hw
);
721 mac
->link_state
= MAC80211_LINKED
;
722 mac
->cnt_after_linked
= 0;
723 mac
->assoc_id
= bss_conf
->aid
;
724 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
726 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
727 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
729 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
731 if (vif
->type
== NL80211_IFTYPE_STATION
&& sta
)
732 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
733 RT_TRACE(rtlpriv
, COMP_EASY_CONCURRENT
, DBG_LOUD
,
734 "send PS STATIC frame\n");
735 if (rtlpriv
->dm
.supp_phymode_switch
) {
736 if (sta
->ht_cap
.ht_supported
)
737 rtl_send_smps_action(hw
, sta
,
738 IEEE80211_SMPS_STATIC
);
742 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
743 "BSS_CHANGED_ASSOC\n");
745 if (mac
->link_state
== MAC80211_LINKED
) {
746 rtlpriv
->enter_ps
= false;
747 schedule_work(&rtlpriv
->works
.lps_change_work
);
750 if (ppsc
->p2p_ps_info
.p2p_ps_mode
> P2P_PS_NONE
)
751 rtl_p2p_ps_cmd(hw
, P2P_PS_DISABLE
);
752 mac
->link_state
= MAC80211_NOLINK
;
753 memset(mac
->bssid
, 0, 6);
754 mac
->vendor
= PEER_UNKNOWN
;
756 if (rtlpriv
->dm
.supp_phymode_switch
) {
757 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
758 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
761 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
762 "BSS_CHANGED_UN_ASSOC\n");
766 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
767 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
768 "BSS_CHANGED_ERP_CTS_PROT\n");
769 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
772 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
773 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
774 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
775 bss_conf
->use_short_preamble
);
777 mac
->short_preamble
= bss_conf
->use_short_preamble
;
778 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
779 &mac
->short_preamble
);
782 if (changed
& BSS_CHANGED_ERP_SLOT
) {
783 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
784 "BSS_CHANGED_ERP_SLOT\n");
786 if (bss_conf
->use_short_slot
)
787 mac
->slot_time
= RTL_SLOT_TIME_9
;
789 mac
->slot_time
= RTL_SLOT_TIME_20
;
791 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
795 if (changed
& BSS_CHANGED_HT
) {
796 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
, "BSS_CHANGED_HT\n");
798 sta
= get_sta(hw
, vif
, bss_conf
->bssid
);
800 if (sta
->ht_cap
.ampdu_density
>
801 mac
->current_ampdu_density
)
802 mac
->current_ampdu_density
=
803 sta
->ht_cap
.ampdu_density
;
804 if (sta
->ht_cap
.ampdu_factor
<
805 mac
->current_ampdu_factor
)
806 mac
->current_ampdu_factor
=
807 sta
->ht_cap
.ampdu_factor
;
811 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
812 &mac
->max_mss_density
);
813 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
814 &mac
->current_ampdu_factor
);
815 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
816 &mac
->current_ampdu_density
);
819 if (changed
& BSS_CHANGED_BSSID
) {
822 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
823 (u8
*) bss_conf
->bssid
);
825 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
, "%pM\n",
828 mac
->vendor
= PEER_UNKNOWN
;
829 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
830 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
833 sta
= get_sta(hw
, vif
, bss_conf
->bssid
);
839 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
840 mac
->mode
= WIRELESS_MODE_A
;
842 if (sta
->supp_rates
[0] <= 0xf)
843 mac
->mode
= WIRELESS_MODE_B
;
845 mac
->mode
= WIRELESS_MODE_G
;
848 if (sta
->ht_cap
.ht_supported
) {
849 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
850 mac
->mode
= WIRELESS_MODE_N_24G
;
852 mac
->mode
= WIRELESS_MODE_N_5G
;
855 /* just station need it, because ibss & ap mode will
856 * set in sta_add, and will be NULL here */
857 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
858 struct rtl_sta_info
*sta_entry
;
859 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
860 sta_entry
->wireless_mode
= mac
->mode
;
863 if (sta
->ht_cap
.ht_supported
) {
864 mac
->ht_enable
= true;
867 * for cisco 1252 bw20 it's wrong
868 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
874 if (changed
& BSS_CHANGED_BASIC_RATES
) {
875 /* for 5G must << RATE_6M_INDEX = 4,
876 * because 5G have no cck rate*/
877 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
878 basic_rates
= sta
->supp_rates
[1] << 4;
880 basic_rates
= sta
->supp_rates
[0];
882 mac
->basic_rates
= basic_rates
;
883 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
884 (u8
*) (&basic_rates
));
891 * To tell firmware we have connected
892 * to an AP. For 92SE/CE power save v2.
894 if (changed
& BSS_CHANGED_ASSOC
) {
895 if (bss_conf
->assoc
) {
896 if (ppsc
->fwctrl_lps
) {
897 u8 mstatus
= RT_MEDIA_CONNECT
;
898 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
899 HW_VAR_H2C_FW_JOINBSSRPT
,
901 ppsc
->report_linked
= true;
904 if (ppsc
->fwctrl_lps
) {
905 u8 mstatus
= RT_MEDIA_DISCONNECT
;
906 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
907 HW_VAR_H2C_FW_JOINBSSRPT
,
909 ppsc
->report_linked
= false;
912 if (rtlpriv
->cfg
->ops
->bt_wifi_media_status_notify
)
913 rtlpriv
->cfg
->ops
->bt_wifi_media_status_notify(hw
,
914 ppsc
->report_linked
);
918 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
921 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
923 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
926 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*) (&tsf
));
930 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
933 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
934 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
935 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
938 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, &bibss
);
941 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
,
942 struct ieee80211_vif
*vif
)
944 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
947 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, &tmp
);
950 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
951 struct ieee80211_vif
*vif
,
952 enum sta_notify_cmd cmd
,
953 struct ieee80211_sta
*sta
)
956 case STA_NOTIFY_SLEEP
:
958 case STA_NOTIFY_AWAKE
:
965 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
966 struct ieee80211_vif
*vif
,
967 enum ieee80211_ampdu_mlme_action action
,
968 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
971 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
974 case IEEE80211_AMPDU_TX_START
:
975 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
976 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid
);
977 return rtl_tx_agg_start(hw
, sta
, tid
, ssn
);
979 case IEEE80211_AMPDU_TX_STOP_CONT
:
980 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
981 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
982 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
983 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
);
984 return rtl_tx_agg_stop(hw
, sta
, tid
);
985 case IEEE80211_AMPDU_TX_OPERATIONAL
:
986 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
987 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
);
988 rtl_tx_agg_oper(hw
, sta
, tid
);
990 case IEEE80211_AMPDU_RX_START
:
991 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
992 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid
);
993 return rtl_rx_agg_start(hw
, sta
, tid
);
994 case IEEE80211_AMPDU_RX_STOP
:
995 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
996 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
);
997 return rtl_rx_agg_stop(hw
, sta
, tid
);
999 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1000 "IEEE80211_AMPDU_ERR!!!!:\n");
1006 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
)
1008 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1009 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1011 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1012 mac
->act_scanning
= true;
1013 if (rtlpriv
->link_info
.higher_busytraffic
) {
1014 mac
->skip_scan
= true;
1018 if (rtlpriv
->dm
.supp_phymode_switch
) {
1019 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1020 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1022 if (mac
->link_state
== MAC80211_LINKED
) {
1023 rtlpriv
->enter_ps
= false;
1024 schedule_work(&rtlpriv
->works
.lps_change_work
);
1025 mac
->link_state
= MAC80211_LINKED_SCANNING
;
1031 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1033 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
1034 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP
);
1037 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
)
1039 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1040 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1042 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1043 mac
->act_scanning
= false;
1044 mac
->skip_scan
= false;
1045 if (rtlpriv
->link_info
.higher_busytraffic
)
1048 /*p2p will use 1/6/11 to scan */
1049 if (mac
->n_channels
== 3)
1050 mac
->p2p_in_use
= true;
1052 mac
->p2p_in_use
= false;
1053 mac
->n_channels
= 0;
1055 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1057 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
1058 mac
->link_state
= MAC80211_LINKED
;
1059 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
1060 /* fix fwlps issue */
1061 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
1065 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
1068 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1069 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1070 struct ieee80211_key_conf
*key
)
1072 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1073 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1074 u8 key_type
= NO_ENCRYPTION
;
1076 bool group_key
= false;
1077 bool wep_only
= false;
1079 u8 mac_addr
[ETH_ALEN
];
1080 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1082 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1083 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1084 "not open hw encryption\n");
1085 return -ENOSPC
; /*User disabled HW-crypto */
1087 /* To support IBSS, use sw-crypto for GTK */
1088 if (((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1089 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) &&
1090 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1092 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1093 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
1094 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
1095 sta
? sta
->addr
: bcast_addr
);
1096 rtlpriv
->sec
.being_setkey
= true;
1098 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1099 /* <1> get encryption alg */
1101 switch (key
->cipher
) {
1102 case WLAN_CIPHER_SUITE_WEP40
:
1103 key_type
= WEP40_ENCRYPTION
;
1104 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP40\n");
1106 case WLAN_CIPHER_SUITE_WEP104
:
1107 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP104\n");
1108 key_type
= WEP104_ENCRYPTION
;
1110 case WLAN_CIPHER_SUITE_TKIP
:
1111 key_type
= TKIP_ENCRYPTION
;
1112 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:TKIP\n");
1114 case WLAN_CIPHER_SUITE_CCMP
:
1115 key_type
= AESCCMP_ENCRYPTION
;
1116 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CCMP\n");
1118 case WLAN_CIPHER_SUITE_AES_CMAC
:
1119 /*HW doesn't support CMAC encryption, use software CMAC */
1120 key_type
= AESCMAC_ENCRYPTION
;
1121 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CMAC\n");
1122 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1123 "HW don't support CMAC encryption, use software CMAC\n");
1127 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "alg_err:%x!!!!\n",
1131 if (key_type
== WEP40_ENCRYPTION
||
1132 key_type
== WEP104_ENCRYPTION
||
1133 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1134 rtlpriv
->sec
.use_defaultkey
= true;
1136 /* <2> get key_idx */
1137 key_idx
= (u8
) (key
->keyidx
);
1140 /* <3> if pairwise key enable_hw_sec */
1141 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1143 /* wep always be group key, but there are two conditions:
1144 * 1) wep only: is just for wep enc, in this condition
1145 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1146 * will be true & enable_hw_sec will be set when wep
1148 * 2) wep(group) + AES(pairwise): some AP like cisco
1149 * may use it, in this condition enable_hw_sec will not
1150 * be set when wep key setting */
1151 /* we must reset sec_info after lingked before set key,
1152 * or some flag will be wrong*/
1153 if (vif
->type
== NL80211_IFTYPE_AP
||
1154 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1155 if (!group_key
|| key_type
== WEP40_ENCRYPTION
||
1156 key_type
== WEP104_ENCRYPTION
) {
1159 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1162 if ((!group_key
) || (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
1163 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
1164 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
1166 (key_type
== WEP40_ENCRYPTION
||
1167 key_type
== WEP104_ENCRYPTION
))
1169 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1170 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1171 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1173 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1176 /* <4> set key based on cmd */
1180 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1181 "set WEP(group/pairwise) key\n");
1182 /* Pairwise key with an assigned MAC address. */
1183 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1184 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1185 /*set local buf about wep key. */
1186 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1187 key
->key
, key
->keylen
);
1188 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1189 eth_zero_addr(mac_addr
);
1190 } else if (group_key
) { /* group key */
1191 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1194 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1195 /*set local buf about group key. */
1196 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1197 key
->key
, key
->keylen
);
1198 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1199 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
1200 } else { /* pairwise key */
1201 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1202 "set pairwise key\n");
1205 "pairwise key without mac_addr\n");
1210 /* Pairwise key with an assigned MAC address. */
1211 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1212 /*set local buf about pairwise key. */
1213 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1214 key
->key
, key
->keylen
);
1215 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1216 rtlpriv
->sec
.pairwise_key
=
1217 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1218 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
1220 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1221 group_key
, key_type
, wep_only
,
1223 /* <5> tell mac80211 do something: */
1224 /*must use sw generate IV, or can not work !!!!. */
1225 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1226 key
->hw_key_idx
= key_idx
;
1227 if (key_type
== TKIP_ENCRYPTION
)
1228 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1229 /*use software CCMP encryption for management frames (MFP) */
1230 if (key_type
== AESCCMP_ENCRYPTION
)
1231 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1234 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1235 "disable key delete one entry\n");
1236 /*set local buf about wep key. */
1237 if (vif
->type
== NL80211_IFTYPE_AP
||
1238 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1240 rtl_cam_del_entry(hw
, sta
->addr
);
1242 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1243 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1244 eth_zero_addr(mac_addr
);
1246 *mac80211 will delete entrys one by one,
1247 *so don't use rtl_cam_reset_all_entry
1248 *or clear all entry here.
1250 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1252 rtl_cam_reset_sec_info(hw
);
1256 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1257 "cmd_err:%x!!!!\n", cmd
);
1260 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1261 rtlpriv
->sec
.being_setkey
= false;
1265 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1267 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1273 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1276 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1278 /*if Radio On return true here */
1279 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1282 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1283 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1285 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
1286 "wireless radio switch turned %s\n",
1287 radio_state
? "on" : "off");
1289 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1290 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1294 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1297 /* this function is called by mac80211 to flush tx buffer
1298 * before switch channel or power save, or tx buffer packet
1299 * maybe send after offchannel or rf sleep, this may cause
1300 * dis-association by AP */
1301 static void rtl_op_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
1303 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1305 if (rtlpriv
->intf_ops
->flush
)
1306 rtlpriv
->intf_ops
->flush(hw
, drop
);
1309 const struct ieee80211_ops rtl_ops
= {
1310 .start
= rtl_op_start
,
1311 .stop
= rtl_op_stop
,
1313 .add_interface
= rtl_op_add_interface
,
1314 .remove_interface
= rtl_op_remove_interface
,
1315 .change_interface
= rtl_op_change_interface
,
1316 .config
= rtl_op_config
,
1317 .configure_filter
= rtl_op_configure_filter
,
1318 .sta_add
= rtl_op_sta_add
,
1319 .sta_remove
= rtl_op_sta_remove
,
1320 .set_key
= rtl_op_set_key
,
1321 .conf_tx
= rtl_op_conf_tx
,
1322 .bss_info_changed
= rtl_op_bss_info_changed
,
1323 .get_tsf
= rtl_op_get_tsf
,
1324 .set_tsf
= rtl_op_set_tsf
,
1325 .reset_tsf
= rtl_op_reset_tsf
,
1326 .sta_notify
= rtl_op_sta_notify
,
1327 .ampdu_action
= rtl_op_ampdu_action
,
1328 .sw_scan_start
= rtl_op_sw_scan_start
,
1329 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1330 .rfkill_poll
= rtl_op_rfkill_poll
,
1331 .flush
= rtl_op_flush
,