1 /******************************************************************************
3 * Copyright(c) 2009-2010 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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
32 #include "btcoexist/rtl_btc.h"
34 /*mutex for start & stop is must here. */
35 static int rtl_op_start(struct ieee80211_hw
*hw
)
38 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
39 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
41 if (!is_hal_stop(rtlhal
))
43 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
45 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
46 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
49 rtl92e_watch_dog_timer_callback((unsigned long)hw
);
52 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
56 static void rtl_op_stop(struct ieee80211_hw
*hw
)
58 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
59 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
60 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
61 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
62 bool b_support_remote_wakeup
= false;
64 if (is_hal_stop(rtlhal
))
67 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
68 (u8
*)(&b_support_remote_wakeup
));
69 /* here is must, because adhoc do stop and start,
70 * but stop with RFOFF may cause something wrong,
72 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
73 rtl92e_ips_nic_on(hw
);
75 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
76 /* if wowlan supported, DON'T clear connected info */
77 if (!(b_support_remote_wakeup
&&
78 rtlhal
->b_enter_pnp_sleep
)) {
79 mac
->link_state
= MAC80211_NOLINK
;
80 memset(mac
->bssid
, 0, 6);
81 mac
->vendor
= PEER_UNKNOWN
;
84 rtl92e_cam_reset_sec_info(hw
);
86 rtl92e_deinit_deferred_work(hw
);
88 rtlpriv
->intf_ops
->adapter_stop(hw
);
90 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
93 static void rtl_op_tx(struct ieee80211_hw
*hw
,
94 struct ieee80211_tx_control
*control
,
97 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
98 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
99 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
100 struct rtl_tcb_desc tcb_desc
;
101 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
103 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
106 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
109 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, control
->sta
, skb
))
110 rtlpriv
->intf_ops
->adapter_tx(hw
, control
->sta
, skb
, &tcb_desc
);
114 dev_kfree_skb_any(skb
);
118 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
119 struct ieee80211_vif
*vif
)
121 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
122 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
126 RT_TRACE(COMP_ERR
, DBG_WARNING
,
127 ("vif has been set!! mac->vif = 0x%p\n", mac
->vif
));
131 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
133 rtl92e_ips_nic_on(hw
);
135 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
136 switch (ieee80211_vif_type_p2p(vif
)) {
137 case NL80211_IFTYPE_P2P_CLIENT
:
138 mac
->p2p
= P2P_ROLE_CLIENT
;
140 case NL80211_IFTYPE_STATION
:
141 if (mac
->beacon_enabled
== 1) {
142 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
143 ("NL80211_IFTYPE_STATION\n"));
144 mac
->beacon_enabled
= 0;
145 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
146 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
149 case NL80211_IFTYPE_ADHOC
:
150 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
151 ("NL80211_IFTYPE_ADHOC\n"));
152 mac
->link_state
= MAC80211_LINKED
;
153 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
154 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
155 mac
->basic_rates
= 0xfff;
157 mac
->basic_rates
= 0xff0;
158 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
159 (u8
*)(&mac
->basic_rates
));
161 case NL80211_IFTYPE_P2P_GO
:
162 mac
->p2p
= P2P_ROLE_GO
;
164 case NL80211_IFTYPE_AP
:
165 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
166 ("NL80211_IFTYPE_AP\n"));
168 mac
->link_state
= MAC80211_LINKED
;
169 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
170 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
171 mac
->basic_rates
= 0xfff;
173 mac
->basic_rates
= 0xff0;
174 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
175 (u8
*)(&mac
->basic_rates
));
177 case NL80211_IFTYPE_MESH_POINT
:
178 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
179 ("NL80211_IFTYPE_MESH_POINT\n"));
181 mac
->link_state
= MAC80211_LINKED
;
182 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
183 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
184 mac
->basic_rates
= 0xfff;
186 mac
->basic_rates
= 0xff0;
187 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
188 (u8
*)(&mac
->basic_rates
));
191 RT_TRACE(COMP_ERR
, DBG_EMERG
,
192 ("operation mode %d is not support!\n", vif
->type
));
198 if (!rtl_set_vif_info(hw
, vif
))
203 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
204 ("p2p role %x\n", vif
->type
));
205 mac
->basic_rates
= 0xff0;/*disable cck rate for p2p*/
206 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
207 (u8
*)(&mac
->basic_rates
));
210 mac
->opmode
= vif
->type
;
211 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
212 ether_addr_copy(mac
->mac_addr
, vif
->addr
);
213 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
216 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
220 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
221 struct ieee80211_vif
*vif
)
223 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
224 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
226 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
228 /* Free beacon resources */
229 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
230 (vif
->type
== NL80211_IFTYPE_ADHOC
) ||
231 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
232 if (mac
->beacon_enabled
== 1) {
233 mac
->beacon_enabled
= 0;
234 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
235 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
240 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
241 *NO LINK for our hardware.
245 mac
->link_state
= MAC80211_NOLINK
;
246 memset(mac
->bssid
, 0, 6);
247 mac
->vendor
= PEER_UNKNOWN
;
248 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
249 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
251 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
253 /*<delete in kernel start>*/
254 static int rtl_op_change_interface(struct ieee80211_hw
*hw
,
255 struct ieee80211_vif
*vif
,
256 enum nl80211_iftype new_type
, bool p2p
)
258 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
260 rtl_op_remove_interface(hw
, vif
);
262 vif
->type
= new_type
;
264 ret
= rtl_op_add_interface(hw
, vif
);
265 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
271 static u16
crc16_ccitt(u8 data
, u16 crc
)
273 u8 shift_in
, data_bit
, crc_bit11
, crc_bit4
, crc_bit15
;
277 for (i
= 0; i
< 8; i
++) {
278 crc_bit15
= ((crc
& BIT(15)) ? 1 : 0);
279 data_bit
= (data
& (BIT(0) << i
) ? 1 : 0);
280 shift_in
= crc_bit15
^ data_bit
;
288 crc_bit11
= ((crc
& BIT(11)) ? 1 : 0) ^ shift_in
;
290 result
&= (~BIT(12));
294 crc_bit4
= ((crc
& BIT(4)) ? 1 : 0) ^ shift_in
;
306 static u16
_calculate_wol_pattern_crc(u8
*pattern
, u16 len
)
311 for (i
= 0; i
< len
; i
++)
312 crc
= crc16_ccitt(pattern
[i
], crc
);
318 static void _rtl_add_wowlan_patterns(struct ieee80211_hw
*hw
,
319 struct cfg80211_wowlan
*wow
)
321 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
322 struct rtl_mac
*mac
= &(rtlpriv
->mac80211
);
323 struct cfg80211_pkt_pattern
*patterns
= wow
->patterns
;
324 struct rtl_wow_pattern rtl_pattern
;
325 const u8
*pattern_os
, *mask_os
;
326 u8 mask
[MAX_WOL_BIT_MASK_SIZE
] = {0};
327 u8 content
[MAX_WOL_PATTERN_SIZE
] = {0};
328 u8 broadcast_addr
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
329 u8 multicast_addr1
[2] = {0x33, 0x33};
330 u8 multicast_addr2
[3] = {0x01, 0x00, 0x5e};
334 for (i
= 0; i
< wow
->n_patterns
; i
++) {
335 memset(&rtl_pattern
, 0, sizeof(struct rtl_wow_pattern
));
336 memset(mask
, 0, MAX_WOL_BIT_MASK_SIZE
);
337 if (patterns
[i
].pattern_len
> MAX_WOL_PATTERN_SIZE
) {
338 RT_TRACE(COMP_POWER
, DBG_WARNING
,
339 ("Pattern[%d] is too long\n", i
));
342 pattern_os
= patterns
[i
].pattern
;
343 mask_len
= DIV_ROUND_UP(patterns
[i
].pattern_len
, 8);
344 mask_os
= patterns
[i
].mask
;
345 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
346 "pattern content\n", pattern_os
,
347 patterns
[i
].pattern_len
);
348 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
349 "mask content\n", mask_os
, mask_len
);
350 /* 1. unicast? multicast? or broadcast? */
351 if (memcmp(pattern_os
, broadcast_addr
, 6) == 0)
352 rtl_pattern
.type
= BROADCAST_PATTERN
;
353 else if (memcmp(pattern_os
, multicast_addr1
, 2) == 0 ||
354 memcmp(pattern_os
, multicast_addr2
, 3) == 0)
355 rtl_pattern
.type
= MULTICAST_PATTERN
;
356 else if (memcmp(pattern_os
, mac
->mac_addr
, 6) == 0)
357 rtl_pattern
.type
= UNICAST_PATTERN
;
359 rtl_pattern
.type
= UNKNOWN_TYPE
;
361 /* 2. translate mask_from_os to mask_for_hw */
363 /******************************************************************************
364 * pattern from OS uses 'ethenet frame', like this:
366 | 6 | 6 | 2 | 20 | Variable | 4 |
367 |--------+--------+------+-----------+------------+-----|
368 | 802.3 Mac Header | IP Header | TCP Packet | FCS |
371 * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
373 | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
374 |-------------------+--------+------+-----------+------------+-----|
375 | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
378 * Therefore, we need translate mask_from_OS to mask_to_hw.
379 * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0,
380 * because new mask[0~5] means 'SA', but our HW packet begins from LLC,
381 * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match.
382 ******************************************************************************/
385 for (j
= 0; j
< mask_len
- 1; j
++) {
386 mask
[j
] = mask_os
[j
] >> 6;
387 mask
[j
] |= (mask_os
[j
+ 1] & 0x3F) << 2;
389 mask
[j
] = (mask_os
[j
] >> 6) & 0x3F;
390 /* Set bit 0-5 to zero */
393 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
394 "mask to hw\n", mask
, mask_len
);
395 for (j
= 0; j
< (MAX_WOL_BIT_MASK_SIZE
+ 1) / 4; j
++) {
396 rtl_pattern
.mask
[j
] = mask
[j
* 4];
397 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 1] << 8);
398 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 2] << 16);
399 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 3] << 24);
402 /* To get the wake up pattern from the mask.
403 * We do not count first 12 bits which means
404 * DA[6] and SA[6] in the pattern to match HW design. */
406 for (j
= 12; j
< patterns
[i
].pattern_len
; j
++) {
407 if ((mask_os
[j
/ 8] >> (j
% 8)) & 0x01) {
408 content
[len
] = pattern_os
[j
];
413 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
414 "pattern to hw\n", content
, len
);
415 /* 3. calculate crc */
416 rtl_pattern
.crc
= _calculate_wol_pattern_crc(content
, len
);
417 RT_TRACE(COMP_POWER
, DBG_TRACE
,
418 ("CRC_Remainder = 0x%x", rtl_pattern
.crc
));
420 /* 4. write crc & mask_for_hw to hw */
421 rtlpriv
->cfg
->ops
->add_wowlan_pattern(hw
, &rtl_pattern
, i
);
423 rtl_write_byte(rtlpriv
, 0x698, wow
->n_patterns
);
426 static int rtl_op_suspend(struct ieee80211_hw
*hw
,
427 struct cfg80211_wowlan
*wow
)
429 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
430 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
431 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
434 RT_TRACE(COMP_POWER
, DBG_DMESG
, ("\n"));
438 /* to resolve s4 can not wake up*/
439 do_gettimeofday(&ts
);
440 rtlhal
->last_suspend_sec
= ts
.tv_sec
;
442 if ((ppsc
->wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) && wow
->n_patterns
)
443 _rtl_add_wowlan_patterns(hw
, wow
);
445 rtlhal
->driver_is_goingto_unload
= true;
446 rtlhal
->b_enter_pnp_sleep
= true;
448 rtl92e_lps_leave(hw
);
450 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), true);
454 static int rtl_op_resume(struct ieee80211_hw
*hw
)
456 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
457 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
458 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
461 RT_TRACE(COMP_POWER
, DBG_DMESG
, ("\n"));
462 rtlhal
->driver_is_goingto_unload
= false;
463 rtlhal
->b_enter_pnp_sleep
= false;
464 rtlhal
->b_wake_from_pnp_sleep
= true;
466 /* to resovle s4 can not wake up*/
467 do_gettimeofday(&ts
);
468 if (ts
.tv_sec
- rtlhal
->last_suspend_sec
< 5)
472 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), false);
473 ieee80211_resume_disconnect(mac
->vif
);
474 rtlhal
->b_wake_from_pnp_sleep
= false;
479 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
481 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
482 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
483 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
484 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
485 struct ieee80211_conf
*conf
= &hw
->conf
;
491 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
492 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /* BIT(2) */
493 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
494 ("IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"));
498 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
499 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
500 rtl92e_ips_nic_off(hw
);
502 rtl92e_ips_nic_on(hw
);
505 *although rfoff may not cause by ips, but we will
506 *check the reason in set_rf_power_state function
508 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
509 rtl92e_ips_nic_on(hw
);
513 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
514 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
515 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
516 if (conf
->flags
& IEEE80211_CONF_PS
) {
517 rtlpriv
->psc
.sw_ps_enabled
= true;
518 /* sleep here is must, or we may recv the beacon and
519 * cause mac80211 into wrong ps state, this will cause
520 * power save nullfunc send fail, and further cause
521 * pkt loss, So sleep must quickly but not immediatly
522 * because that will cause nullfunc send by mac80211
523 * fail, and cause pkt loss, we have tested that 5mA
524 * is worked very well */
525 if (!rtlpriv
->psc
.multi_buffered
)
526 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
527 &rtlpriv
->works
.ps_work
,
530 rtl92e_swlps_rf_awake(hw
);
531 rtlpriv
->psc
.sw_ps_enabled
= false;
535 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
536 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
537 ("IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
538 hw
->conf
.long_frame_max_tx_count
));
539 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
540 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
541 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
542 (u8
*)(&hw
->conf
.long_frame_max_tx_count
));
544 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
545 !rtlpriv
->proximity
.proxim_on
) {
546 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
547 enum nl80211_chan_width width
= hw
->conf
.chandef
.width
;
548 u8 wide_chan
= (u8
) channel
->hw_value
;
549 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
551 /* channel_type is for 20&40M */
552 if (width
< NL80211_CHAN_WIDTH_80
)
553 channel_type
= cfg80211_get_chandef_type(&(hw
->conf
.chandef
));
554 if (mac
->act_scanning
)
557 if (rtlpriv
->dm
.supp_phymode_switch
&&
558 mac
->link_state
< MAC80211_LINKED
&&
559 !mac
->act_scanning
) {
560 if (rtlpriv
->cfg
->ops
->check_switch_to_dmdp
)
561 rtlpriv
->cfg
->ops
->check_switch_to_dmdp(hw
);
565 *because we should back channel to
566 *current_network.chan in in scanning,
567 *So if set_chan == current_network.chan
569 *because mac80211 tell us wrong bw40
570 *info for cisco1253 bw20, so we modify
571 *it here based on UPPER & LOWER
574 if (width
>= NL80211_CHAN_WIDTH_80
) {
575 if (width
== NL80211_CHAN_WIDTH_80
) {
576 u32 center_freq
= hw
->conf
.chandef
.center_freq1
;
578 (u32
)hw
->conf
.chandef
.chan
->center_freq
;
580 rtlphy
->current_chan_bw
=
584 if (center_freq
> primary_freq
) {
585 mac
->cur_80_prime_sc
=
586 PRIME_CHNL_OFFSET_LOWER
;
587 if (center_freq
- primary_freq
== 10) {
588 mac
->cur_40_prime_sc
=
589 PRIME_CHNL_OFFSET_UPPER
;
592 } else if (center_freq
- primary_freq
== 30) {
593 mac
->cur_40_prime_sc
=
594 PRIME_CHNL_OFFSET_LOWER
;
599 mac
->cur_80_prime_sc
=
600 PRIME_CHNL_OFFSET_UPPER
;
601 if (primary_freq
- center_freq
== 10) {
602 mac
->cur_40_prime_sc
=
603 PRIME_CHNL_OFFSET_LOWER
;
606 } else if (primary_freq
- center_freq
== 30) {
607 mac
->cur_40_prime_sc
=
608 PRIME_CHNL_OFFSET_UPPER
;
615 switch (channel_type
) {
616 case NL80211_CHAN_HT20
:
617 case NL80211_CHAN_NO_HT
:
619 mac
->cur_40_prime_sc
=
620 PRIME_CHNL_OFFSET_DONT_CARE
;
621 rtlphy
->current_chan_bw
=
626 case NL80211_CHAN_HT40MINUS
:
628 mac
->cur_40_prime_sc
=
629 PRIME_CHNL_OFFSET_UPPER
;
630 rtlphy
->current_chan_bw
=
631 HT_CHANNEL_WIDTH_20_40
;
638 case NL80211_CHAN_HT40PLUS
:
640 mac
->cur_40_prime_sc
=
641 PRIME_CHNL_OFFSET_LOWER
;
642 rtlphy
->current_chan_bw
=
643 HT_CHANNEL_WIDTH_20_40
;
652 RT_TRACE(COMP_ERR
, DBG_EMERG
,
653 ("switch case not processed\n"));
661 /* in scanning, when before we offchannel we may send a ps=1
662 * null to AP, and then we may send a ps = 0 null to AP quickly,
663 * but first null have cause AP's put lots of packet to hw tx
664 * buffer, these packet must be tx before off channel so we must
665 * delay more time to let AP flush these packets before
666 * offchannel, or dis-association or delete BA will happen by AP
668 if (rtlpriv
->mac80211
.offchan_deley
) {
669 rtlpriv
->mac80211
.offchan_deley
= false;
673 rtlphy
->current_channel
= wide_chan
;
675 rtlpriv
->cfg
->ops
->switch_channel(hw
);
676 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
677 rtlpriv
->cfg
->ops
->set_bw_mode(hw
,
681 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
686 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
687 unsigned int changed_flags
,
688 unsigned int *new_flags
, u64 multicast
)
690 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
691 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
693 *new_flags
&= RTL_SUPPORTED_FILTERS
;
694 if (0 == changed_flags
)
697 /*TODO: we disable broadcase now, so enable here */
698 if (changed_flags
& FIF_ALLMULTI
) {
699 if (*new_flags
& FIF_ALLMULTI
) {
700 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
701 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
702 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
703 ("Enable receive multicast frame.\n"));
705 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
706 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
707 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
708 ("Disable receive multicast frame.\n"));
712 if (changed_flags
& FIF_FCSFAIL
) {
713 if (*new_flags
& FIF_FCSFAIL
) {
714 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
715 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
716 ("Enable receive FCS error frame.\n"));
718 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
719 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
720 ("Disable receive FCS error frame.\n"));
724 /* if ssid not set to hw don't check bssid
725 * here just used for linked scanning, & linked
726 * and nolink check bssid is set in set network_type */
727 if ((changed_flags
& FIF_BCN_PRBRESP_PROMISC
) &&
728 (mac
->link_state
>= MAC80211_LINKED
)) {
729 if (mac
->opmode
!= NL80211_IFTYPE_AP
&&
730 mac
->opmode
!= NL80211_IFTYPE_MESH_POINT
) {
731 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
)
732 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, false);
734 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, true);
738 if (changed_flags
& FIF_CONTROL
) {
739 if (*new_flags
& FIF_CONTROL
) {
740 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
742 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
743 ("Enable receive control frame.\n"));
745 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
746 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
747 ("Disable receive control frame.\n"));
751 if (changed_flags
& FIF_OTHER_BSS
) {
752 if (*new_flags
& FIF_OTHER_BSS
) {
753 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
754 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
755 ("Enable receive other BSS's frame.\n"));
757 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
758 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
759 ("Disable receive other BSS's frame.\n"));
763 static int rtl_op_sta_add(struct ieee80211_hw
*hw
,
764 struct ieee80211_vif
*vif
,
765 struct ieee80211_sta
*sta
)
767 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
768 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
769 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
770 struct rtl_sta_info
*sta_entry
;
773 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
774 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
775 list_add_tail(&sta_entry
->list
, &rtlpriv
->entry_list
);
776 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
777 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
778 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
779 if (sta
->supp_rates
[0] <= 0xf)
780 sta_entry
->wireless_mode
= WIRELESS_MODE_B
;
781 if (sta
->ht_cap
.ht_supported
)
782 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
784 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
785 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
786 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
787 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
788 if (sta
->ht_cap
.ht_supported
)
789 sta_entry
->wireless_mode
= WIRELESS_MODE_N_5G
;
790 if (sta
->vht_cap
.vht_supported
)
791 sta_entry
->wireless_mode
= WIRELESS_MODE_AC_5G
;
793 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
794 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
796 /*disable cck rate for p2p*/
798 sta
->supp_rates
[0] &= 0xfffffff0;
800 ether_addr_copy(sta_entry
->mac_addr
, sta
->addr
);
801 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
802 ("Add sta addr is %pM\n", sta
->addr
));
803 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
809 static int rtl_op_sta_remove(struct ieee80211_hw
*hw
,
810 struct ieee80211_vif
*vif
,
811 struct ieee80211_sta
*sta
)
813 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
814 struct rtl_sta_info
*sta_entry
;
816 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
817 ("Remove sta addr is %pM\n", sta
->addr
));
818 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
819 sta_entry
->wireless_mode
= 0;
820 sta_entry
->ratr_index
= 0;
821 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
822 list_del(&sta_entry
->list
);
823 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
827 static int _rtl_get_hal_qnum(u16 queue
)
852 *for mac80211 VO=0, VI=1, BE=2, BK=3
853 *for rtl819x BE=0, BK=1, VI=2, VO=3
855 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
,
856 struct ieee80211_vif
*vif
, u16 queue
,
857 const struct ieee80211_tx_queue_params
*param
)
859 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
860 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
863 if (queue
>= AC_MAX
) {
864 RT_TRACE(COMP_ERR
, DBG_WARNING
,
865 ("queue number %d is incorrect!\n", queue
));
869 aci
= _rtl_get_hal_qnum(queue
);
870 mac
->ac
[aci
].aifs
= param
->aifs
;
871 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
872 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
873 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
874 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
875 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
879 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
880 struct ieee80211_vif
*vif
,
881 struct ieee80211_bss_conf
*bss_conf
,
884 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
885 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
886 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
887 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
889 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
890 if ((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
891 (vif
->type
== NL80211_IFTYPE_AP
) ||
892 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
893 if ((changed
& BSS_CHANGED_BEACON
) ||
894 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
895 bss_conf
->enable_beacon
)) {
896 if (mac
->beacon_enabled
== 0) {
897 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
898 ("BSS_CHANGED_BEACON_ENABLED\n"));
900 /*start hw beacon interrupt. */
901 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
902 mac
->beacon_enabled
= 1;
903 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
905 [RTL_IBSS_INT_MASKS
], 0);
907 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
908 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
911 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
912 !bss_conf
->enable_beacon
) {
913 if (mac
->beacon_enabled
== 1) {
914 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
915 ("ADHOC DISABLE BEACON\n"));
917 mac
->beacon_enabled
= 0;
918 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
920 [RTL_IBSS_INT_MASKS
]);
923 if (changed
& BSS_CHANGED_BEACON_INT
) {
924 RT_TRACE(COMP_BEACON
, DBG_TRACE
,
925 ("BSS_CHANGED_BEACON_INT\n"));
926 mac
->beacon_interval
= bss_conf
->beacon_int
;
927 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
931 /*TODO: reference to enum ieee80211_bss_change */
932 if (changed
& BSS_CHANGED_ASSOC
) {
934 if (bss_conf
->assoc
) {
935 struct ieee80211_sta
*sta
= NULL
;
938 mstatus
= RT_MEDIA_CONNECT
;
939 /* we should reset all sec info & cam
940 * before set cam after linked, we should not
941 * reset in disassoc, that will cause tkip->wep
942 * fail because some flag will be wrong */
944 rtl92e_cam_reset_sec_info(hw
);
945 /* reset cam to fix wep fail issue
946 * when change from wpa to wep */
947 stg_rtl_cam_reset_all_entry(hw
);
949 mac
->link_state
= MAC80211_LINKED
;
950 mac
->cnt_after_linked
= 0;
951 mac
->assoc_id
= bss_conf
->aid
;
952 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
954 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
955 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
958 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
960 pr_err("ieee80211_find_sta returned NULL\n");
965 if (vif
->type
== NL80211_IFTYPE_STATION
&& sta
)
966 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
967 RT_TRACE(COMP_EASY_CONCURRENT
, DBG_LOUD
,
968 ("send PS STATIC frame\n"));
969 if (rtlpriv
->dm
.supp_phymode_switch
) {
970 if (sta
->ht_cap
.ht_supported
)
971 stg_rtl_send_smps_action(hw
, sta
,
972 IEEE80211_SMPS_STATIC
);
975 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
976 mac
->mode
= WIRELESS_MODE_A
;
978 if (sta
->supp_rates
[0] <= 0xf)
979 mac
->mode
= WIRELESS_MODE_B
;
981 mac
->mode
= WIRELESS_MODE_G
;
984 if (sta
->ht_cap
.ht_supported
) {
985 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
986 mac
->mode
= WIRELESS_MODE_N_24G
;
988 mac
->mode
= WIRELESS_MODE_N_5G
;
991 if (sta
->vht_cap
.vht_supported
) {
992 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
993 mac
->mode
= WIRELESS_MODE_AC_5G
;
995 mac
->mode
= WIRELESS_MODE_AC_24G
;
1000 /* to avoid AP Disassociation caused by inactivity */
1001 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1003 (u8
*)(&keep_alive
));
1005 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
1006 ("BSS_CHANGED_ASSOC\n"));
1008 mstatus
= RT_MEDIA_DISCONNECT
;
1010 if (mac
->link_state
== MAC80211_LINKED
)
1011 rtl92e_lps_leave(hw
);
1012 if (ppsc
->p2p_ps_info
.p2p_ps_mode
> P2P_PS_NONE
)
1013 rtl92e_p2p_ps_cmd(hw
, P2P_PS_DISABLE
);
1014 mac
->link_state
= MAC80211_NOLINK
;
1015 memset(mac
->bssid
, 0, 6);
1016 mac
->vendor
= PEER_UNKNOWN
;
1019 if (rtlpriv
->dm
.supp_phymode_switch
) {
1020 if (rtlpriv
->cfg
->ops
->check_switch_to_dmdp
)
1021 rtlpriv
->cfg
->ops
->check_switch_to_dmdp(hw
);
1023 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
1024 ("BSS_CHANGED_UN_ASSOC\n"));
1026 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
1028 * To tell firmware we have connected or disconnected*/
1029 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1030 HW_VAR_H2C_FW_JOINBSSRPT
,
1032 ppsc
->report_linked
= (mstatus
== RT_MEDIA_CONNECT
) ?
1035 if (rtlpriv
->cfg
->ops
->get_btc_status())
1036 rtlpriv
->btcoexist
.btc_ops
->btc_mediastatus_notify(
1040 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1041 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1042 ("BSS_CHANGED_ERP_CTS_PROT\n"));
1043 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
1046 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1047 RT_TRACE(COMP_MAC80211
, DBG_LOUD
,
1048 ("BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
1049 bss_conf
->use_short_preamble
));
1051 mac
->short_preamble
= bss_conf
->use_short_preamble
;
1052 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
1053 (u8
*)(&mac
->short_preamble
));
1056 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1057 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1058 ("BSS_CHANGED_ERP_SLOT\n"));
1060 if (bss_conf
->use_short_slot
)
1061 mac
->slot_time
= RTL_SLOT_TIME_9
;
1063 mac
->slot_time
= RTL_SLOT_TIME_20
;
1065 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
1066 (u8
*)(&mac
->slot_time
));
1069 if (changed
& BSS_CHANGED_HT
) {
1070 struct ieee80211_sta
*sta
= NULL
;
1072 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1073 ("BSS_CHANGED_HT\n"));
1076 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1078 if (sta
->ht_cap
.ampdu_density
>
1079 mac
->current_ampdu_density
)
1080 mac
->current_ampdu_density
=
1081 sta
->ht_cap
.ampdu_density
;
1082 if (sta
->ht_cap
.ampdu_factor
<
1083 mac
->current_ampdu_factor
)
1084 mac
->current_ampdu_factor
=
1085 sta
->ht_cap
.ampdu_factor
;
1089 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
1090 (u8
*)(&mac
->max_mss_density
));
1091 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
1092 &mac
->current_ampdu_factor
);
1093 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
1094 &mac
->current_ampdu_density
);
1097 if (changed
& BSS_CHANGED_BSSID
) {
1099 struct ieee80211_sta
*sta
= NULL
;
1101 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
1102 (u8
*)bss_conf
->bssid
);
1104 RT_TRACE(COMP_MAC80211
, DBG_DMESG
,
1105 ("bssid: %pM\n", bss_conf
->bssid
));
1107 mac
->vendor
= PEER_UNKNOWN
;
1108 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
1111 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1117 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1118 mac
->mode
= WIRELESS_MODE_A
;
1120 if (sta
->supp_rates
[0] <= 0xf)
1121 mac
->mode
= WIRELESS_MODE_B
;
1123 mac
->mode
= WIRELESS_MODE_G
;
1126 if (sta
->ht_cap
.ht_supported
) {
1127 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1128 mac
->mode
= WIRELESS_MODE_N_24G
;
1130 mac
->mode
= WIRELESS_MODE_N_5G
;
1133 if (sta
->vht_cap
.vht_supported
) {
1134 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1135 mac
->mode
= WIRELESS_MODE_AC_5G
;
1137 mac
->mode
= WIRELESS_MODE_AC_24G
;
1140 /* just station need it, because ibss & ap mode will
1141 * set in sta_add, and will be NULL here */
1142 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1143 struct rtl_sta_info
*sta_entry
;
1144 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1145 sta_entry
->wireless_mode
= mac
->mode
;
1148 if (sta
->ht_cap
.ht_supported
) {
1149 mac
->ht_enable
= true;
1152 * for cisco 1252 bw20 it's wrong
1153 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
1154 * mac->bw_40 = true;
1159 if (sta
->vht_cap
.vht_supported
)
1160 mac
->vht_enable
= true;
1162 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1163 /* for 5G must << RATE_6M_INDEX=4,
1164 * because 5G have no cck rate*/
1165 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1166 basic_rates
= sta
->supp_rates
[1] << 4;
1168 basic_rates
= sta
->supp_rates
[0];
1170 mac
->basic_rates
= basic_rates
;
1171 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
1172 (u8
*)(&basic_rates
));
1177 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1180 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1182 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1185 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&tsf
));
1189 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
,
1190 struct ieee80211_vif
*vif
, u64 tsf
)
1192 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1193 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1194 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
1197 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&bibss
));
1200 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1202 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1205 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*)(&tmp
));
1208 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
1209 struct ieee80211_vif
*vif
,
1210 enum sta_notify_cmd cmd
,
1211 struct ieee80211_sta
*sta
)
1214 case STA_NOTIFY_SLEEP
:
1216 case STA_NOTIFY_AWAKE
:
1223 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
1224 struct ieee80211_vif
*vif
,
1225 enum ieee80211_ampdu_mlme_action action
,
1226 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
1229 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1232 case IEEE80211_AMPDU_TX_START
:
1233 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1234 ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid
));
1235 return rtl92e_tx_agg_start(hw
, vif
, sta
, tid
, ssn
);
1237 case IEEE80211_AMPDU_TX_STOP_CONT
:
1238 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1239 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1240 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1241 ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
));
1242 return rtl92e_tx_agg_stop(hw
, vif
, sta
, tid
);
1244 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1245 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1246 ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
));
1247 rtl92e_tx_agg_oper(hw
, sta
, tid
);
1249 case IEEE80211_AMPDU_RX_START
:
1250 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1251 ("IEEE80211_AMPDU_RX_START:TID:%d\n", tid
));
1252 return rtl92e_rx_agg_start(hw
, sta
, tid
);
1254 case IEEE80211_AMPDU_RX_STOP
:
1255 RT_TRACE(COMP_MAC80211
, DBG_TRACE
,
1256 ("IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
));
1257 return rtl92e_rx_agg_stop(hw
, sta
, tid
);
1260 RT_TRACE(COMP_ERR
, DBG_EMERG
,
1261 ("IEEE80211_AMPDU_ERR!!!!:\n"));
1267 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
)
1269 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1270 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1272 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("\n"));
1273 mac
->act_scanning
= true;
1274 if (rtlpriv
->link_info
.b_higher_busytraffic
) {
1275 mac
->skip_scan
= true;
1279 if (rtlpriv
->cfg
->ops
->get_btc_status())
1280 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 1);
1282 if (rtlpriv
->dm
.supp_phymode_switch
) {
1283 if (rtlpriv
->cfg
->ops
->check_switch_to_dmdp
)
1284 rtlpriv
->cfg
->ops
->check_switch_to_dmdp(hw
);
1287 if (mac
->link_state
== MAC80211_LINKED
) {
1288 rtl92e_lps_leave(hw
);
1289 mac
->link_state
= MAC80211_LINKED_SCANNING
;
1291 rtl92e_ips_nic_on(hw
);
1295 rtlpriv
->rtlhal
.b_load_imrandiqk_setting_for2g
= false;
1297 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
1298 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP_BAND0
);
1301 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
)
1303 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1304 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1306 RT_TRACE(COMP_MAC80211
, DBG_LOUD
, ("\n"));
1307 mac
->act_scanning
= false;
1308 mac
->skip_scan
= false;
1309 if (rtlpriv
->link_info
.b_higher_busytraffic
)
1312 /* p2p will use 1/6/11 to scan */
1313 if (mac
->n_channels
== 3)
1314 mac
->p2p_in_use
= true;
1316 mac
->p2p_in_use
= false;
1317 mac
->n_channels
= 0;
1319 rtlpriv
->rtlhal
.b_load_imrandiqk_setting_for2g
= false;
1321 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
1322 mac
->link_state
= MAC80211_LINKED
;
1323 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
1324 /* fix fwlps issue */
1325 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
1329 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
1330 if (rtlpriv
->cfg
->ops
->get_btc_status())
1331 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 0);
1334 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1335 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1336 struct ieee80211_key_conf
*key
)
1338 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1339 u8 key_type
= NO_ENCRYPTION
;
1341 bool group_key
= false;
1342 bool wep_only
= false;
1344 u8 mac_addr
[ETH_ALEN
];
1345 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1347 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1348 RT_TRACE(COMP_ERR
, DBG_WARNING
,
1349 ("not open hw encryption\n"));
1350 return -ENOSPC
; /*User disabled HW-crypto */
1352 /* To support IBSS, use sw-crypto for GTK */
1353 if (((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1354 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) &&
1355 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1357 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1358 ("%s hardware based encryption for keyidx: %d, mac: %pM\n",
1359 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
1360 sta
? sta
->addr
: bcast_addr
));
1361 rtlpriv
->sec
.being_setkey
= true;
1362 rtl92e_ips_nic_on(hw
);
1363 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1364 /* <1> get encryption alg */
1366 switch (key
->cipher
) {
1367 case WLAN_CIPHER_SUITE_WEP40
:
1368 key_type
= WEP40_ENCRYPTION
;
1369 RT_TRACE(COMP_SEC
, DBG_DMESG
, ("alg:WEP40\n"));
1371 case WLAN_CIPHER_SUITE_WEP104
:
1372 RT_TRACE(COMP_SEC
, DBG_DMESG
, ("alg:WEP104\n"));
1373 key_type
= WEP104_ENCRYPTION
;
1375 case WLAN_CIPHER_SUITE_TKIP
:
1376 key_type
= TKIP_ENCRYPTION
;
1377 RT_TRACE(COMP_SEC
, DBG_DMESG
, ("alg:TKIP\n"));
1379 case WLAN_CIPHER_SUITE_CCMP
:
1380 key_type
= AESCCMP_ENCRYPTION
;
1381 RT_TRACE(COMP_SEC
, DBG_DMESG
, ("alg:CCMP\n"));
1383 case WLAN_CIPHER_SUITE_AES_CMAC
:
1384 /* HW don't support CMAC encryption,
1385 * use software CMAC encryption */
1386 key_type
= AESCMAC_ENCRYPTION
;
1387 RT_TRACE(COMP_SEC
, DBG_DMESG
, ("alg:CMAC\n"));
1388 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1389 ("HW don't support CMAC encrypiton, use software CMAC encryption\n"));
1393 RT_TRACE(COMP_ERR
, DBG_EMERG
,
1394 ("alg_err:%x!!!!:\n", key
->cipher
));
1397 if (key_type
== WEP40_ENCRYPTION
||
1398 key_type
== WEP104_ENCRYPTION
||
1399 vif
->type
== NL80211_IFTYPE_ADHOC
)
1400 rtlpriv
->sec
.use_defaultkey
= true;
1402 /* <2> get key_idx */
1403 key_idx
= (u8
) (key
->keyidx
);
1406 /* <3> if pairwise key enable_hw_sec */
1407 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1409 /* wep always be group key, but there are two conditions:
1410 * 1) wep only: is just for wep enc, in this condition
1411 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1412 * will be true & enable_hw_sec will be set when wep
1414 * 2) wep(group) + AES(pairwise): some AP like cisco
1415 * may use it, in this condition enable_hw_sec will not
1416 * be set when wep key setting */
1417 /* we must reset sec_info after lingked before set key,
1418 * or some flag will be wrong*/
1419 if (vif
->type
== NL80211_IFTYPE_AP
||
1420 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1421 if (!group_key
|| key_type
== WEP40_ENCRYPTION
||
1422 key_type
== WEP104_ENCRYPTION
) {
1425 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1428 if ((!group_key
) || (vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1429 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
1430 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
1432 (key_type
== WEP40_ENCRYPTION
||
1433 key_type
== WEP104_ENCRYPTION
))
1435 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1436 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1437 ("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1439 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1442 /* <4> set key based on cmd */
1446 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1447 ("set WEP(group/pairwise) key\n"));
1448 /* Pairwise key with an assigned MAC address. */
1449 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1450 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1451 /*set local buf about wep key. */
1452 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1453 key
->key
, key
->keylen
);
1454 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1455 eth_zero_addr(mac_addr
);
1456 } else if (group_key
) { /* group key */
1457 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1458 ("set group key\n"));
1460 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1461 /*set local buf about group key. */
1462 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1463 key
->key
, key
->keylen
);
1464 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1465 ether_addr_copy(mac_addr
, bcast_addr
);
1466 } else { /* pairwise key */
1467 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1468 ("set pairwise key\n"));
1471 ("pairwise key without mac_addr\n"));
1476 /* Pairwise key with an assigned MAC address. */
1477 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1478 /*set local buf about pairwise key. */
1479 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1480 key
->key
, key
->keylen
);
1481 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1482 rtlpriv
->sec
.pairwise_key
=
1483 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1484 ether_addr_copy(mac_addr
, sta
->addr
);
1486 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1487 group_key
, key_type
, wep_only
,
1489 /* <5> tell mac80211 do something: */
1490 /*must use sw generate IV, or can not work !!!!. */
1491 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1492 key
->hw_key_idx
= key_idx
;
1493 if (key_type
== TKIP_ENCRYPTION
)
1494 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1495 /*use software CCMP encryption for management frames (MFP) */
1496 if (key_type
== AESCCMP_ENCRYPTION
)
1497 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1500 RT_TRACE(COMP_SEC
, DBG_DMESG
,
1501 ("disable key delete one entry\n"));
1502 /*set local buf about wep key. */
1503 if (vif
->type
== NL80211_IFTYPE_AP
||
1504 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1506 stg_rtl_cam_del_entry(hw
, sta
->addr
);
1508 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1509 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1510 eth_zero_addr(mac_addr
);
1512 *mac80211 will delete entrys one by one,
1513 *so don't use stg_rtl_cam_reset_all_entry
1514 *or clear all entry here.
1516 stg_rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1519 RT_TRACE(COMP_ERR
, DBG_EMERG
,
1520 ("cmd_err:%x!!!!:\n", cmd
));
1523 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1524 rtlpriv
->sec
.being_setkey
= false;
1528 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1530 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1536 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1539 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1541 /*if Radio On return true here */
1542 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1545 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1546 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1548 RT_TRACE(COMP_RF
, DBG_DMESG
,
1549 (KERN_INFO
"wireless radio switch turned %s\n",
1550 radio_state
? "on" : "off"));
1552 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1553 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1557 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1560 /* this function is called by mac80211 to flush tx buffer
1561 * before switch channle or power save, or tx buffer packet
1562 * maybe send after offchannel or rf sleep, this may cause
1563 * dis-association by AP */
1564 static void rtl_op_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1565 u32 queues
, bool drop
)
1567 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1569 if (rtlpriv
->intf_ops
->flush
)
1570 rtlpriv
->intf_ops
->flush(hw
, queues
, drop
);
1573 const struct ieee80211_ops rtl92e_ops
= {
1574 .start
= rtl_op_start
,
1575 .stop
= rtl_op_stop
,
1577 .add_interface
= rtl_op_add_interface
,
1578 .remove_interface
= rtl_op_remove_interface
,
1579 .change_interface
= rtl_op_change_interface
,
1581 .suspend
= rtl_op_suspend
,
1582 .resume
= rtl_op_resume
,
1584 .config
= rtl_op_config
,
1585 .configure_filter
= rtl_op_configure_filter
,
1586 .set_key
= rtl_op_set_key
,
1587 .conf_tx
= rtl_op_conf_tx
,
1588 .bss_info_changed
= rtl_op_bss_info_changed
,
1589 .get_tsf
= rtl_op_get_tsf
,
1590 .set_tsf
= rtl_op_set_tsf
,
1591 .reset_tsf
= rtl_op_reset_tsf
,
1592 .sta_notify
= rtl_op_sta_notify
,
1593 .ampdu_action
= rtl_op_ampdu_action
,
1594 .sw_scan_start
= rtl_op_sw_scan_start
,
1595 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1596 .rfkill_poll
= rtl_op_rfkill_poll
,
1597 .sta_add
= rtl_op_sta_add
,
1598 .sta_remove
= rtl_op_sta_remove
,
1599 .flush
= rtl_op_flush
,