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 * 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 *****************************************************************************/
36 /*mutex for start & stop is must here. */
37 static int rtl_op_start(struct ieee80211_hw
*hw
)
40 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
41 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
43 if (!is_hal_stop(rtlhal
))
45 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
47 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
48 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
50 rtl_watch_dog_timer_callback((unsigned long)hw
);
51 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
55 static void rtl_op_stop(struct ieee80211_hw
*hw
)
57 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
58 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
59 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
60 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
62 if (is_hal_stop(rtlhal
))
65 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
)) {
70 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
72 mac
->link_state
= MAC80211_NOLINK
;
73 memset(mac
->bssid
, 0, 6);
74 mac
->vendor
= PEER_UNKNOWN
;
77 rtl_cam_reset_sec_info(hw
);
79 rtl_deinit_deferred_work(hw
);
80 rtlpriv
->intf_ops
->adapter_stop(hw
);
82 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
85 static void rtl_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
87 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
88 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
89 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
90 struct rtl_tcb_desc tcb_desc
;
91 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
93 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
96 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
99 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, skb
))
100 rtlpriv
->intf_ops
->adapter_tx(hw
, skb
, &tcb_desc
);
105 dev_kfree_skb_any(skb
);
108 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
109 struct ieee80211_vif
*vif
)
111 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
112 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
116 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
117 ("vif has been set!! mac->vif = 0x%p\n", mac
->vif
));
123 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
125 case NL80211_IFTYPE_STATION
:
126 if (mac
->beacon_enabled
== 1) {
127 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
128 ("NL80211_IFTYPE_STATION\n"));
129 mac
->beacon_enabled
= 0;
130 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
132 [RTL_IBSS_INT_MASKS
]);
135 case NL80211_IFTYPE_ADHOC
:
136 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
137 ("NL80211_IFTYPE_ADHOC\n"));
139 mac
->link_state
= MAC80211_LINKED
;
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
));
149 case NL80211_IFTYPE_AP
:
150 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
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
));
163 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
164 ("operation mode %d is not support!\n", vif
->type
));
170 mac
->opmode
= vif
->type
;
171 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
172 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
173 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
176 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
180 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
181 struct ieee80211_vif
*vif
)
183 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
184 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
186 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
188 /* Free beacon resources */
189 if ((mac
->opmode
== NL80211_IFTYPE_AP
) ||
190 (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
191 (mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)) {
192 if (mac
->beacon_enabled
== 1) {
193 mac
->beacon_enabled
= 0;
194 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
196 [RTL_IBSS_INT_MASKS
]);
201 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
202 *NO LINK for our hardware.
205 mac
->link_state
= MAC80211_NOLINK
;
206 memset(mac
->bssid
, 0, 6);
207 mac
->vendor
= PEER_UNKNOWN
;
208 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
209 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
210 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
213 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
215 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
216 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
217 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
218 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
219 struct ieee80211_conf
*conf
= &hw
->conf
;
221 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
222 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /*BIT(2)*/
223 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
224 ("IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"));
228 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
229 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
235 *although rfoff may not cause by ips, but we will
236 *check the reason in set_rf_power_state function
238 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
243 if (changed
& IEEE80211_CONF_CHANGE_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;
265 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
266 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
267 ("IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
268 hw
->conf
.long_frame_max_tx_count
));
269 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
270 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
271 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
273 long_frame_max_tx_count
));
276 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
277 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
278 u8 wide_chan
= (u8
) channel
->hw_value
;
281 *because we should back channel to
282 *current_network.chan in in scanning,
283 *So if set_chan == current_network.chan
285 *because mac80211 tell us wrong bw40
286 *info for cisco1253 bw20, so we modify
287 *it here based on UPPER & LOWER
289 switch (hw
->conf
.channel_type
) {
290 case NL80211_CHAN_HT20
:
291 case NL80211_CHAN_NO_HT
:
293 mac
->cur_40_prime_sc
=
294 PRIME_CHNL_OFFSET_DONT_CARE
;
295 rtlphy
->current_chan_bw
= HT_CHANNEL_WIDTH_20
;
298 case NL80211_CHAN_HT40MINUS
:
300 mac
->cur_40_prime_sc
= PRIME_CHNL_OFFSET_UPPER
;
301 rtlphy
->current_chan_bw
=
302 HT_CHANNEL_WIDTH_20_40
;
309 case NL80211_CHAN_HT40PLUS
:
311 mac
->cur_40_prime_sc
= PRIME_CHNL_OFFSET_LOWER
;
312 rtlphy
->current_chan_bw
=
313 HT_CHANNEL_WIDTH_20_40
;
322 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
323 ("switch case not processed\n"));
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_delay
) {
339 rtlpriv
->mac80211
.offchan_delay
= false;
342 rtlphy
->current_channel
= wide_chan
;
344 rtlpriv
->cfg
->ops
->switch_channel(hw
);
345 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
346 rtlpriv
->cfg
->ops
->set_bw_mode(hw
,
347 hw
->conf
.channel_type
);
350 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
355 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
356 unsigned int changed_flags
,
357 unsigned int *new_flags
, u64 multicast
)
359 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
360 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
362 *new_flags
&= RTL_SUPPORTED_FILTERS
;
366 /*TODO: we disable broadcase now, so enable here */
367 if (changed_flags
& FIF_ALLMULTI
) {
368 if (*new_flags
& FIF_ALLMULTI
) {
369 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
370 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
371 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
372 ("Enable receive multicast frame.\n"));
374 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
375 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
376 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
377 ("Disable receive multicast frame.\n"));
381 if (changed_flags
& FIF_FCSFAIL
) {
382 if (*new_flags
& FIF_FCSFAIL
) {
383 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
384 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
385 ("Enable receive FCS error frame.\n"));
387 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
388 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
389 ("Disable receive FCS error frame.\n"));
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);
407 if (changed_flags
& FIF_CONTROL
) {
408 if (*new_flags
& FIF_CONTROL
) {
409 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
411 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
412 ("Enable receive control frame.\n"));
414 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
415 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
416 ("Disable receive control frame.\n"));
420 if (changed_flags
& FIF_OTHER_BSS
) {
421 if (*new_flags
& FIF_OTHER_BSS
) {
422 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
423 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
424 ("Enable receive other BSS's frame.\n"));
426 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
427 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
428 ("Disable receive other BSS's frame.\n"));
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
)
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
)
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 %pM\n", 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 %pM\n", sta
->addr
));
473 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
474 sta_entry
->wireless_mode
= 0;
475 sta_entry
->ratr_index
= 0;
479 static int _rtl_get_hal_qnum(u16 queue
)
504 *for mac80211 VO=0, VI=1, BE=2, BK=3
505 *for rtl819x BE=0, BK=1, VI=2, VO=3
507 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
508 const struct ieee80211_tx_queue_params
*param
)
510 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
511 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
514 if (queue
>= AC_MAX
) {
515 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
516 ("queue number %d is incorrect!\n", queue
));
520 aci
= _rtl_get_hal_qnum(queue
);
521 mac
->ac
[aci
].aifs
= param
->aifs
;
522 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
523 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
524 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
525 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
526 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
530 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
531 struct ieee80211_vif
*vif
,
532 struct ieee80211_bss_conf
*bss_conf
, u32 changed
)
534 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
535 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
536 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
537 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
538 struct ieee80211_sta
*sta
= NULL
;
540 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
541 if ((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
542 (vif
->type
== NL80211_IFTYPE_AP
) ||
543 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
544 if ((changed
& BSS_CHANGED_BEACON
) ||
545 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
546 bss_conf
->enable_beacon
)) {
547 if (mac
->beacon_enabled
== 0) {
548 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
549 ("BSS_CHANGED_BEACON_ENABLED\n"));
551 /*start hw beacon interrupt. */
552 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
553 mac
->beacon_enabled
= 1;
554 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
556 [RTL_IBSS_INT_MASKS
],
559 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
560 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
563 if ((changed
& BSS_CHANGED_BEACON_ENABLED
&&
564 !bss_conf
->enable_beacon
)) {
565 if (mac
->beacon_enabled
== 1) {
566 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
567 ("ADHOC DISABLE BEACON\n"));
569 mac
->beacon_enabled
= 0;
570 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
572 [RTL_IBSS_INT_MASKS
]);
575 if (changed
& BSS_CHANGED_BEACON_INT
) {
576 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
577 ("BSS_CHANGED_BEACON_INT\n"));
578 mac
->beacon_interval
= bss_conf
->beacon_int
;
579 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
583 /*TODO: reference to enum ieee80211_bss_change */
584 if (changed
& BSS_CHANGED_ASSOC
) {
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
);
596 mac
->link_state
= MAC80211_LINKED
;
597 mac
->cnt_after_linked
= 0;
598 mac
->assoc_id
= bss_conf
->aid
;
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);
605 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
606 ("BSS_CHANGED_ASSOC\n"));
608 if (mac
->link_state
== MAC80211_LINKED
)
611 mac
->link_state
= MAC80211_NOLINK
;
612 memset(mac
->bssid
, 0, 6);
613 mac
->vendor
= PEER_UNKNOWN
;
615 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
616 ("BSS_CHANGED_UN_ASSOC\n"));
620 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
621 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
622 ("BSS_CHANGED_ERP_CTS_PROT\n"));
623 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
626 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
627 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
628 ("BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
629 bss_conf
->use_short_preamble
));
631 mac
->short_preamble
= bss_conf
->use_short_preamble
;
632 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
633 (u8
*) (&mac
->short_preamble
));
636 if (changed
& BSS_CHANGED_ERP_SLOT
) {
637 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
638 ("BSS_CHANGED_ERP_SLOT\n"));
640 if (bss_conf
->use_short_slot
)
641 mac
->slot_time
= RTL_SLOT_TIME_9
;
643 mac
->slot_time
= RTL_SLOT_TIME_20
;
645 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
646 (u8
*) (&mac
->slot_time
));
649 if (changed
& BSS_CHANGED_HT
) {
650 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
651 ("BSS_CHANGED_HT\n"));
653 sta
= get_sta(hw
, vif
, bss_conf
->bssid
);
655 if (sta
->ht_cap
.ampdu_density
>
656 mac
->current_ampdu_density
)
657 mac
->current_ampdu_density
=
658 sta
->ht_cap
.ampdu_density
;
659 if (sta
->ht_cap
.ampdu_factor
<
660 mac
->current_ampdu_factor
)
661 mac
->current_ampdu_factor
=
662 sta
->ht_cap
.ampdu_factor
;
666 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
667 (u8
*) (&mac
->max_mss_density
));
668 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
669 &mac
->current_ampdu_factor
);
670 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
671 &mac
->current_ampdu_density
);
674 if (changed
& BSS_CHANGED_BSSID
) {
677 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
678 (u8
*) bss_conf
->bssid
);
680 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
681 ("%pM\n", bss_conf
->bssid
));
683 mac
->vendor
= PEER_UNKNOWN
;
684 memcpy(mac
->bssid
, bss_conf
->bssid
, 6);
685 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
688 sta
= get_sta(hw
, vif
, 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
)
705 mac
->mode
= WIRELESS_MODE_N_24G
;
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) {
729 if (changed
& BSS_CHANGED_BASIC_RATES
) {
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;
735 basic_rates
= sta
->supp_rates
[0];
737 mac
->basic_rates
= basic_rates
;
738 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
739 (u8
*) (&basic_rates
));
746 * To tell firmware we have connected
747 * to an AP. For 92SE/CE power save v2.
749 if (changed
& BSS_CHANGED_ASSOC
) {
750 if (bss_conf
->assoc
) {
751 if (ppsc
->fwctrl_lps
) {
752 u8 mstatus
= RT_MEDIA_CONNECT
;
753 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
754 HW_VAR_H2C_FW_JOINBSSRPT
,
756 ppsc
->report_linked
= true;
759 if (ppsc
->fwctrl_lps
) {
760 u8 mstatus
= RT_MEDIA_DISCONNECT
;
761 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
762 HW_VAR_H2C_FW_JOINBSSRPT
,
764 ppsc
->report_linked
= false;
770 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
773 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
)
775 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
778 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*) (&tsf
));
782 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
784 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
785 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
786 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
789 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*) (&bibss
));
792 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
)
794 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
797 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*) (&tmp
));
800 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
801 struct ieee80211_vif
*vif
,
802 enum sta_notify_cmd cmd
,
803 struct ieee80211_sta
*sta
)
806 case STA_NOTIFY_SLEEP
:
808 case STA_NOTIFY_AWAKE
:
815 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
816 struct ieee80211_vif
*vif
,
817 enum ieee80211_ampdu_mlme_action action
,
818 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
821 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
824 case IEEE80211_AMPDU_TX_START
:
825 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
826 ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid
));
827 return rtl_tx_agg_start(hw
, sta
, tid
, ssn
);
829 case IEEE80211_AMPDU_TX_STOP
:
830 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
831 ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
));
832 return rtl_tx_agg_stop(hw
, sta
, tid
);
834 case IEEE80211_AMPDU_TX_OPERATIONAL
:
835 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
836 ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
));
837 rtl_tx_agg_oper(hw
, sta
, tid
);
839 case IEEE80211_AMPDU_RX_START
:
840 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
841 ("IEEE80211_AMPDU_RX_START:TID:%d\n", tid
));
843 case IEEE80211_AMPDU_RX_STOP
:
844 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
845 ("IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
));
848 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
849 ("IEEE80211_AMPDU_ERR!!!!:\n"));
855 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
)
857 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
858 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
860 mac
->act_scanning
= true;
862 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("\n"));
864 if (mac
->link_state
== MAC80211_LINKED
) {
866 mac
->link_state
= MAC80211_LINKED_SCANNING
;
872 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
874 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
875 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP
);
878 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
)
880 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
881 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
883 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("\n"));
884 mac
->act_scanning
= false;
886 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
888 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
889 mac
->link_state
= MAC80211_LINKED
;
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
);
899 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
900 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
901 struct ieee80211_key_conf
*key
)
903 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
904 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
905 u8 key_type
= NO_ENCRYPTION
;
907 bool group_key
= false;
908 bool wep_only
= false;
910 u8 mac_addr
[ETH_ALEN
];
911 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
912 u8 zero_addr
[ETH_ALEN
] = { 0 };
914 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
915 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
916 ("not open hw encryption\n"));
917 return -ENOSPC
; /*User disabled HW-crypto */
919 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
920 ("%s hardware based encryption for keyidx: %d, mac: %pM\n",
921 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
922 sta
? sta
->addr
: bcast_addr
));
923 rtlpriv
->sec
.being_setkey
= true;
925 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
926 /* <1> get encryption alg */
928 switch (key
->cipher
) {
929 case WLAN_CIPHER_SUITE_WEP40
:
930 key_type
= WEP40_ENCRYPTION
;
931 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, ("alg:WEP40\n"));
933 case WLAN_CIPHER_SUITE_WEP104
:
934 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
936 key_type
= WEP104_ENCRYPTION
;
938 case WLAN_CIPHER_SUITE_TKIP
:
939 key_type
= TKIP_ENCRYPTION
;
940 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, ("alg:TKIP\n"));
942 case WLAN_CIPHER_SUITE_CCMP
:
943 key_type
= AESCCMP_ENCRYPTION
;
944 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, ("alg:CCMP\n"));
947 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
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;
956 /* <2> get key_idx */
957 key_idx
= (u8
) (key
->keyidx
);
960 /* <3> if pairwise key enable_hw_sec */
961 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
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
);
995 /* <4> set key based on cmd */
999 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1000 ("set WEP(group/pairwise) key\n"));
1001 /* Pairwise key with an assigned MAC address. */
1002 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1003 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1004 /*set local buf about wep key. */
1005 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1006 key
->key
, key
->keylen
);
1007 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1008 memcpy(mac_addr
, zero_addr
, ETH_ALEN
);
1009 } else if (group_key
) { /* group key */
1010 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1011 ("set group key\n"));
1013 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1014 /*set local buf about group key. */
1015 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1016 key
->key
, key
->keylen
);
1017 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1018 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
1019 } else { /* pairwise key */
1020 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1021 ("set pairwise key\n"));
1023 RT_ASSERT(false, ("pairwise key withnot"
1029 /* Pairwise key with an assigned MAC address. */
1030 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1031 /*set local buf about pairwise key. */
1032 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1033 key
->key
, key
->keylen
);
1034 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1035 rtlpriv
->sec
.pairwise_key
=
1036 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1037 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
1039 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1040 group_key
, key_type
, wep_only
,
1042 /* <5> tell mac80211 do something: */
1043 /*must use sw generate IV, or can not work !!!!. */
1044 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1045 key
->hw_key_idx
= key_idx
;
1046 if (key_type
== TKIP_ENCRYPTION
)
1047 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1050 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1051 ("disable key delete one entry\n"));
1052 /*set local buf about wep key. */
1053 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
1055 rtl_cam_del_entry(hw
, sta
->addr
);
1057 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1058 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1059 memcpy(mac_addr
, zero_addr
, ETH_ALEN
);
1061 *mac80211 will delete entrys one by one,
1062 *so don't use rtl_cam_reset_all_entry
1063 *or clear all entry here.
1065 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1068 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1069 ("cmd_err:%x!!!!:\n", cmd
));
1072 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1073 rtlpriv
->sec
.being_setkey
= false;
1077 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1079 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1085 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1088 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1090 /*if Radio On return true here */
1091 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1094 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1095 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1097 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
1098 (KERN_INFO
"wireless radio switch turned %s\n",
1099 radio_state
? "on" : "off"));
1101 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1102 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
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
);
1121 const struct ieee80211_ops rtl_ops
= {
1122 .start
= rtl_op_start
,
1123 .stop
= rtl_op_stop
,
1125 .add_interface
= rtl_op_add_interface
,
1126 .remove_interface
= rtl_op_remove_interface
,
1127 .config
= rtl_op_config
,
1128 .configure_filter
= rtl_op_configure_filter
,
1129 .sta_add
= rtl_op_sta_add
,
1130 .sta_remove
= rtl_op_sta_remove
,
1131 .set_key
= rtl_op_set_key
,
1132 .conf_tx
= rtl_op_conf_tx
,
1133 .bss_info_changed
= rtl_op_bss_info_changed
,
1134 .get_tsf
= rtl_op_get_tsf
,
1135 .set_tsf
= rtl_op_set_tsf
,
1136 .reset_tsf
= rtl_op_reset_tsf
,
1137 .sta_notify
= rtl_op_sta_notify
,
1138 .ampdu_action
= rtl_op_ampdu_action
,
1139 .sw_scan_start
= rtl_op_sw_scan_start
,
1140 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1141 .rfkill_poll
= rtl_op_rfkill_poll
,
1142 .flush
= rtl_op_flush
,