Loading...
1/******************************************************************************
2 *
3 * Copyright(c) 2009-2010 Realtek Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
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
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
30#include "wifi.h"
31#include "core.h"
32#include "cam.h"
33#include "base.h"
34#include "ps.h"
35
36/*mutex for start & stop is must here. */
37static int rtl_op_start(struct ieee80211_hw *hw)
38{
39 int err;
40 struct rtl_priv *rtlpriv = rtl_priv(hw);
41 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
42
43 if (!is_hal_stop(rtlhal))
44 return 0;
45 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
46 return 0;
47 mutex_lock(&rtlpriv->locks.conf_mutex);
48 err = rtlpriv->intf_ops->adapter_start(hw);
49 if (!err)
50 rtl_watch_dog_timer_callback((unsigned long)hw);
51 mutex_unlock(&rtlpriv->locks.conf_mutex);
52 return err;
53}
54
55static void rtl_op_stop(struct ieee80211_hw *hw)
56{
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));
61
62 if (is_hal_stop(rtlhal))
63 return;
64
65 if (unlikely(ppsc->rfpwr_state == ERFOFF)) {
66 rtl_ips_nic_on(hw);
67 mdelay(1);
68 }
69
70 mutex_lock(&rtlpriv->locks.conf_mutex);
71
72 mac->link_state = MAC80211_NOLINK;
73 memset(mac->bssid, 0, 6);
74 mac->vendor = PEER_UNKNOWN;
75
76 /*reset sec info */
77 rtl_cam_reset_sec_info(hw);
78
79 rtl_deinit_deferred_work(hw);
80 rtlpriv->intf_ops->adapter_stop(hw);
81
82 mutex_unlock(&rtlpriv->locks.conf_mutex);
83}
84
85static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
86{
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));
92
93 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
94 goto err_free;
95
96 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
97 goto err_free;
98
99 if (!rtlpriv->intf_ops->waitq_insert(hw, skb))
100 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
101
102 return;
103
104err_free:
105 dev_kfree_skb_any(skb);
106}
107
108static int rtl_op_add_interface(struct ieee80211_hw *hw,
109 struct ieee80211_vif *vif)
110{
111 struct rtl_priv *rtlpriv = rtl_priv(hw);
112 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
113 int err = 0;
114
115 if (mac->vif) {
116 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
117 ("vif has been set!! mac->vif = 0x%p\n", mac->vif));
118 return -EOPNOTSUPP;
119 }
120
121 rtl_ips_nic_on(hw);
122
123 mutex_lock(&rtlpriv->locks.conf_mutex);
124 switch (vif->type) {
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,
131 rtlpriv->cfg->maps
132 [RTL_IBSS_INT_MASKS]);
133 }
134 break;
135 case NL80211_IFTYPE_ADHOC:
136 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
137 ("NL80211_IFTYPE_ADHOC\n"));
138
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;
143 else
144 mac->basic_rates = 0xff0;
145 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
146 (u8 *) (&mac->basic_rates));
147
148 break;
149 case NL80211_IFTYPE_AP:
150 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
151 ("NL80211_IFTYPE_AP\n"));
152
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;
157 else
158 mac->basic_rates = 0xff0;
159 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
160 (u8 *) (&mac->basic_rates));
161 break;
162 default:
163 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
164 ("operation mode %d is not support!\n", vif->type));
165 err = -EOPNOTSUPP;
166 goto out;
167 }
168
169 mac->vif = vif;
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);
174
175out:
176 mutex_unlock(&rtlpriv->locks.conf_mutex);
177 return err;
178}
179
180static void rtl_op_remove_interface(struct ieee80211_hw *hw,
181 struct ieee80211_vif *vif)
182{
183 struct rtl_priv *rtlpriv = rtl_priv(hw);
184 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
185
186 mutex_lock(&rtlpriv->locks.conf_mutex);
187
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,
195 rtlpriv->cfg->maps
196 [RTL_IBSS_INT_MASKS]);
197 }
198 }
199
200 /*
201 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
202 *NO LINK for our hardware.
203 */
204 mac->vif = NULL;
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);
211}
212
213static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
214{
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;
220
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"));
225 }
226
227 /*For IPS */
228 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
229 if (hw->conf.flags & IEEE80211_CONF_IDLE)
230 rtl_ips_nic_off(hw);
231 else
232 rtl_ips_nic_on(hw);
233 } else {
234 /*
235 *although rfoff may not cause by ips, but we will
236 *check the reason in set_rf_power_state function
237 */
238 if (unlikely(ppsc->rfpwr_state == ERFOFF))
239 rtl_ips_nic_on(hw);
240 }
241
242 /*For LPS */
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,
258 MSECS(5));
259 } else {
260 rtl_swlps_rf_awake(hw);
261 rtlpriv->psc.sw_ps_enabled = false;
262 }
263 }
264
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,
272 (u8 *) (&hw->conf.
273 long_frame_max_tx_count));
274 }
275
276 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
277 struct ieee80211_channel *channel = hw->conf.channel;
278 u8 wide_chan = (u8) channel->hw_value;
279
280 /*
281 *because we should back channel to
282 *current_network.chan in in scanning,
283 *So if set_chan == current_network.chan
284 *we should set it.
285 *because mac80211 tell us wrong bw40
286 *info for cisco1253 bw20, so we modify
287 *it here based on UPPER & LOWER
288 */
289 switch (hw->conf.channel_type) {
290 case NL80211_CHAN_HT20:
291 case NL80211_CHAN_NO_HT:
292 /* SC */
293 mac->cur_40_prime_sc =
294 PRIME_CHNL_OFFSET_DONT_CARE;
295 rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
296 mac->bw_40 = false;
297 break;
298 case NL80211_CHAN_HT40MINUS:
299 /* SC */
300 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
301 rtlphy->current_chan_bw =
302 HT_CHANNEL_WIDTH_20_40;
303 mac->bw_40 = true;
304
305 /*wide channel */
306 wide_chan -= 2;
307
308 break;
309 case NL80211_CHAN_HT40PLUS:
310 /* SC */
311 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
312 rtlphy->current_chan_bw =
313 HT_CHANNEL_WIDTH_20_40;
314 mac->bw_40 = true;
315
316 /*wide channel */
317 wide_chan += 2;
318
319 break;
320 default:
321 mac->bw_40 = false;
322 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
323 ("switch case not processed\n"));
324 break;
325 }
326
327 if (wide_chan <= 0)
328 wide_chan = 1;
329
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
336 * happen by AP
337 */
338 if (rtlpriv->mac80211.offchan_delay) {
339 rtlpriv->mac80211.offchan_delay = false;
340 mdelay(50);
341 }
342 rtlphy->current_channel = wide_chan;
343
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);
348 }
349
350 mutex_unlock(&rtlpriv->locks.conf_mutex);
351
352 return 0;
353}
354
355static void rtl_op_configure_filter(struct ieee80211_hw *hw,
356 unsigned int changed_flags,
357 unsigned int *new_flags, u64 multicast)
358{
359 struct rtl_priv *rtlpriv = rtl_priv(hw);
360 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
361
362 *new_flags &= RTL_SUPPORTED_FILTERS;
363 if (!changed_flags)
364 return;
365
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"));
373 } else {
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"));
378 }
379 }
380
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"));
386 } else {
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"));
390 }
391 }
392
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);
401 } else {
402 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
403 }
404 }
405 }
406
407 if (changed_flags & FIF_CONTROL) {
408 if (*new_flags & FIF_CONTROL) {
409 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
410
411 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
412 ("Enable receive control frame.\n"));
413 } else {
414 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
415 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
416 ("Disable receive control frame.\n"));
417 }
418 }
419
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"));
425 } else {
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"));
429 }
430 }
431}
432static int rtl_op_sta_add(struct ieee80211_hw *hw,
433 struct ieee80211_vif *vif,
434 struct ieee80211_sta *sta)
435{
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;
439
440 if (sta) {
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;
452 }
453
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;
457
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);
461 }
462 return 0;
463}
464static int rtl_op_sta_remove(struct ieee80211_hw *hw,
465 struct ieee80211_vif *vif,
466 struct ieee80211_sta *sta)
467{
468 struct rtl_priv *rtlpriv = rtl_priv(hw);
469 struct rtl_sta_info *sta_entry;
470 if (sta) {
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;
476 }
477 return 0;
478}
479static int _rtl_get_hal_qnum(u16 queue)
480{
481 int qnum;
482
483 switch (queue) {
484 case 0:
485 qnum = AC3_VO;
486 break;
487 case 1:
488 qnum = AC2_VI;
489 break;
490 case 2:
491 qnum = AC0_BE;
492 break;
493 case 3:
494 qnum = AC1_BK;
495 break;
496 default:
497 qnum = AC0_BE;
498 break;
499 }
500 return qnum;
501}
502
503/*
504 *for mac80211 VO=0, VI=1, BE=2, BK=3
505 *for rtl819x BE=0, BK=1, VI=2, VO=3
506 */
507static int rtl_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
508 const struct ieee80211_tx_queue_params *param)
509{
510 struct rtl_priv *rtlpriv = rtl_priv(hw);
511 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
512 int aci;
513
514 if (queue >= AC_MAX) {
515 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
516 ("queue number %d is incorrect!\n", queue));
517 return -EINVAL;
518 }
519
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);
527 return 0;
528}
529
530static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
531 struct ieee80211_vif *vif,
532 struct ieee80211_bss_conf *bss_conf, u32 changed)
533{
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;
539
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"));
550
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,
555 rtlpriv->cfg->maps
556 [RTL_IBSS_INT_MASKS],
557 0);
558
559 if (rtlpriv->cfg->ops->linked_set_reg)
560 rtlpriv->cfg->ops->linked_set_reg(hw);
561 }
562 }
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"));
568
569 mac->beacon_enabled = 0;
570 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
571 rtlpriv->cfg->maps
572 [RTL_IBSS_INT_MASKS]);
573 }
574 }
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);
580 }
581 }
582
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 */
590 /* reset sec info */
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);
595
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);
600
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"));
607 } else {
608 if (mac->link_state == MAC80211_LINKED)
609 rtl_lps_leave(hw);
610
611 mac->link_state = MAC80211_NOLINK;
612 memset(mac->bssid, 0, 6);
613
614 /* reset sec info */
615 rtl_cam_reset_sec_info(hw);
616
617 rtl_cam_reset_all_entry(hw);
618 mac->vendor = PEER_UNKNOWN;
619
620 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
621 ("BSS_CHANGED_UN_ASSOC\n"));
622 }
623 }
624
625 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
626 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
627 ("BSS_CHANGED_ERP_CTS_PROT\n"));
628 mac->use_cts_protect = bss_conf->use_cts_prot;
629 }
630
631 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
632 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
633 ("BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
634 bss_conf->use_short_preamble));
635
636 mac->short_preamble = bss_conf->use_short_preamble;
637 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
638 (u8 *) (&mac->short_preamble));
639 }
640
641 if (changed & BSS_CHANGED_ERP_SLOT) {
642 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
643 ("BSS_CHANGED_ERP_SLOT\n"));
644
645 if (bss_conf->use_short_slot)
646 mac->slot_time = RTL_SLOT_TIME_9;
647 else
648 mac->slot_time = RTL_SLOT_TIME_20;
649
650 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
651 (u8 *) (&mac->slot_time));
652 }
653
654 if (changed & BSS_CHANGED_HT) {
655 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
656 ("BSS_CHANGED_HT\n"));
657 rcu_read_lock();
658 sta = get_sta(hw, vif, bss_conf->bssid);
659 if (sta) {
660 if (sta->ht_cap.ampdu_density >
661 mac->current_ampdu_density)
662 mac->current_ampdu_density =
663 sta->ht_cap.ampdu_density;
664 if (sta->ht_cap.ampdu_factor <
665 mac->current_ampdu_factor)
666 mac->current_ampdu_factor =
667 sta->ht_cap.ampdu_factor;
668 }
669 rcu_read_unlock();
670
671 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
672 (u8 *) (&mac->max_mss_density));
673 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
674 &mac->current_ampdu_factor);
675 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
676 &mac->current_ampdu_density);
677 }
678
679 if (changed & BSS_CHANGED_BSSID) {
680 u32 basic_rates;
681
682 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
683 (u8 *) bss_conf->bssid);
684
685 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
686 ("%pM\n", bss_conf->bssid));
687
688 mac->vendor = PEER_UNKNOWN;
689 memcpy(mac->bssid, bss_conf->bssid, 6);
690 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
691
692 rcu_read_lock();
693 sta = get_sta(hw, vif, bss_conf->bssid);
694 if (!sta) {
695 rcu_read_unlock();
696 goto out;
697 }
698
699 if (rtlhal->current_bandtype == BAND_ON_5G) {
700 mac->mode = WIRELESS_MODE_A;
701 } else {
702 if (sta->supp_rates[0] <= 0xf)
703 mac->mode = WIRELESS_MODE_B;
704 else
705 mac->mode = WIRELESS_MODE_G;
706 }
707
708 if (sta->ht_cap.ht_supported) {
709 if (rtlhal->current_bandtype == BAND_ON_2_4G)
710 mac->mode = WIRELESS_MODE_N_24G;
711 else
712 mac->mode = WIRELESS_MODE_N_5G;
713 }
714
715 /* just station need it, because ibss & ap mode will
716 * set in sta_add, and will be NULL here */
717 if (mac->opmode == NL80211_IFTYPE_STATION) {
718 struct rtl_sta_info *sta_entry;
719 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
720 sta_entry->wireless_mode = mac->mode;
721 }
722
723 if (sta->ht_cap.ht_supported) {
724 mac->ht_enable = true;
725
726 /*
727 * for cisco 1252 bw20 it's wrong
728 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
729 * mac->bw_40 = true;
730 * }
731 * */
732 }
733
734 if (changed & BSS_CHANGED_BASIC_RATES) {
735 /* for 5G must << RATE_6M_INDEX=4,
736 * because 5G have no cck rate*/
737 if (rtlhal->current_bandtype == BAND_ON_5G)
738 basic_rates = sta->supp_rates[1] << 4;
739 else
740 basic_rates = sta->supp_rates[0];
741
742 mac->basic_rates = basic_rates;
743 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
744 (u8 *) (&basic_rates));
745 }
746 rcu_read_unlock();
747 }
748
749 /*
750 * For FW LPS:
751 * To tell firmware we have connected
752 * to an AP. For 92SE/CE power save v2.
753 */
754 if (changed & BSS_CHANGED_ASSOC) {
755 if (bss_conf->assoc) {
756 if (ppsc->fwctrl_lps) {
757 u8 mstatus = RT_MEDIA_CONNECT;
758 rtlpriv->cfg->ops->set_hw_reg(hw,
759 HW_VAR_H2C_FW_JOINBSSRPT,
760 (u8 *) (&mstatus));
761 ppsc->report_linked = true;
762 }
763 } else {
764 if (ppsc->fwctrl_lps) {
765 u8 mstatus = RT_MEDIA_DISCONNECT;
766 rtlpriv->cfg->ops->set_hw_reg(hw,
767 HW_VAR_H2C_FW_JOINBSSRPT,
768 (u8 *)(&mstatus));
769 ppsc->report_linked = false;
770 }
771 }
772 }
773
774out:
775 mutex_unlock(&rtlpriv->locks.conf_mutex);
776}
777
778static u64 rtl_op_get_tsf(struct ieee80211_hw *hw)
779{
780 struct rtl_priv *rtlpriv = rtl_priv(hw);
781 u64 tsf;
782
783 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
784 return tsf;
785}
786
787static void rtl_op_set_tsf(struct ieee80211_hw *hw, u64 tsf)
788{
789 struct rtl_priv *rtlpriv = rtl_priv(hw);
790 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
791 u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
792
793 mac->tsf = tsf;
794 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss));
795}
796
797static void rtl_op_reset_tsf(struct ieee80211_hw *hw)
798{
799 struct rtl_priv *rtlpriv = rtl_priv(hw);
800 u8 tmp = 0;
801
802 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *) (&tmp));
803}
804
805static void rtl_op_sta_notify(struct ieee80211_hw *hw,
806 struct ieee80211_vif *vif,
807 enum sta_notify_cmd cmd,
808 struct ieee80211_sta *sta)
809{
810 switch (cmd) {
811 case STA_NOTIFY_SLEEP:
812 break;
813 case STA_NOTIFY_AWAKE:
814 break;
815 default:
816 break;
817 }
818}
819
820static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
821 struct ieee80211_vif *vif,
822 enum ieee80211_ampdu_mlme_action action,
823 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
824 u8 buf_size)
825{
826 struct rtl_priv *rtlpriv = rtl_priv(hw);
827
828 switch (action) {
829 case IEEE80211_AMPDU_TX_START:
830 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
831 ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid));
832 return rtl_tx_agg_start(hw, sta, tid, ssn);
833 break;
834 case IEEE80211_AMPDU_TX_STOP:
835 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
836 ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid));
837 return rtl_tx_agg_stop(hw, sta, tid);
838 break;
839 case IEEE80211_AMPDU_TX_OPERATIONAL:
840 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
841 ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid));
842 rtl_tx_agg_oper(hw, sta, tid);
843 break;
844 case IEEE80211_AMPDU_RX_START:
845 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
846 ("IEEE80211_AMPDU_RX_START:TID:%d\n", tid));
847 break;
848 case IEEE80211_AMPDU_RX_STOP:
849 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
850 ("IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid));
851 break;
852 default:
853 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
854 ("IEEE80211_AMPDU_ERR!!!!:\n"));
855 return -EOPNOTSUPP;
856 }
857 return 0;
858}
859
860static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
861{
862 struct rtl_priv *rtlpriv = rtl_priv(hw);
863 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
864
865 mac->act_scanning = true;
866
867 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
868
869 if (mac->link_state == MAC80211_LINKED) {
870 rtl_lps_leave(hw);
871 mac->link_state = MAC80211_LINKED_SCANNING;
872 } else {
873 rtl_ips_nic_on(hw);
874 }
875
876 /* Dual mac */
877 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
878
879 rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
880 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
881}
882
883static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
884{
885 struct rtl_priv *rtlpriv = rtl_priv(hw);
886 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
887
888 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
889 mac->act_scanning = false;
890 /* Dual mac */
891 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
892
893 if (mac->link_state == MAC80211_LINKED_SCANNING) {
894 mac->link_state = MAC80211_LINKED;
895 if (mac->opmode == NL80211_IFTYPE_STATION) {
896 /* fix fwlps issue */
897 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
898 }
899 }
900
901 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
902}
903
904static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
905 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
906 struct ieee80211_key_conf *key)
907{
908 struct rtl_priv *rtlpriv = rtl_priv(hw);
909 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
910 u8 key_type = NO_ENCRYPTION;
911 u8 key_idx;
912 bool group_key = false;
913 bool wep_only = false;
914 int err = 0;
915 u8 mac_addr[ETH_ALEN];
916 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
917 u8 zero_addr[ETH_ALEN] = { 0 };
918
919 if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
920 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
921 ("not open hw encryption\n"));
922 return -ENOSPC; /*User disabled HW-crypto */
923 }
924 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
925 ("%s hardware based encryption for keyidx: %d, mac: %pM\n",
926 cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
927 sta ? sta->addr : bcast_addr));
928 rtlpriv->sec.being_setkey = true;
929 rtl_ips_nic_on(hw);
930 mutex_lock(&rtlpriv->locks.conf_mutex);
931 /* <1> get encryption alg */
932
933 switch (key->cipher) {
934 case WLAN_CIPHER_SUITE_WEP40:
935 key_type = WEP40_ENCRYPTION;
936 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n"));
937 break;
938 case WLAN_CIPHER_SUITE_WEP104:
939 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
940 ("alg:WEP104\n"));
941 key_type = WEP104_ENCRYPTION;
942 break;
943 case WLAN_CIPHER_SUITE_TKIP:
944 key_type = TKIP_ENCRYPTION;
945 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n"));
946 break;
947 case WLAN_CIPHER_SUITE_CCMP:
948 key_type = AESCCMP_ENCRYPTION;
949 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n"));
950 break;
951 default:
952 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
953 ("alg_err:%x!!!!:\n", key->cipher));
954 goto out_unlock;
955 }
956 if (key_type == WEP40_ENCRYPTION ||
957 key_type == WEP104_ENCRYPTION ||
958 mac->opmode == NL80211_IFTYPE_ADHOC)
959 rtlpriv->sec.use_defaultkey = true;
960
961 /* <2> get key_idx */
962 key_idx = (u8) (key->keyidx);
963 if (key_idx > 3)
964 goto out_unlock;
965 /* <3> if pairwise key enable_hw_sec */
966 group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
967
968 /* wep always be group key, but there are two conditions:
969 * 1) wep only: is just for wep enc, in this condition
970 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
971 * will be true & enable_hw_sec will be set when wep
972 * ke setting.
973 * 2) wep(group) + AES(pairwise): some AP like cisco
974 * may use it, in this condition enable_hw_sec will not
975 * be set when wep key setting */
976 /* we must reset sec_info after lingked before set key,
977 * or some flag will be wrong*/
978 if (mac->opmode == NL80211_IFTYPE_AP) {
979 if (!group_key || key_type == WEP40_ENCRYPTION ||
980 key_type == WEP104_ENCRYPTION) {
981 if (group_key)
982 wep_only = true;
983 rtlpriv->cfg->ops->enable_hw_sec(hw);
984 }
985 } else {
986 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
987 rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
988 if (rtlpriv->sec.pairwise_enc_algorithm ==
989 NO_ENCRYPTION &&
990 (key_type == WEP40_ENCRYPTION ||
991 key_type == WEP104_ENCRYPTION))
992 wep_only = true;
993 rtlpriv->sec.pairwise_enc_algorithm = key_type;
994 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
995 ("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1"
996 " TKIP:2 AES:4 WEP104:5)\n", key_type));
997 rtlpriv->cfg->ops->enable_hw_sec(hw);
998 }
999 }
1000 /* <4> set key based on cmd */
1001 switch (cmd) {
1002 case SET_KEY:
1003 if (wep_only) {
1004 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1005 ("set WEP(group/pairwise) key\n"));
1006 /* Pairwise key with an assigned MAC address. */
1007 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1008 rtlpriv->sec.group_enc_algorithm = key_type;
1009 /*set local buf about wep key. */
1010 memcpy(rtlpriv->sec.key_buf[key_idx],
1011 key->key, key->keylen);
1012 rtlpriv->sec.key_len[key_idx] = key->keylen;
1013 memcpy(mac_addr, zero_addr, ETH_ALEN);
1014 } else if (group_key) { /* group key */
1015 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1016 ("set group key\n"));
1017 /* group key */
1018 rtlpriv->sec.group_enc_algorithm = key_type;
1019 /*set local buf about group key. */
1020 memcpy(rtlpriv->sec.key_buf[key_idx],
1021 key->key, key->keylen);
1022 rtlpriv->sec.key_len[key_idx] = key->keylen;
1023 memcpy(mac_addr, bcast_addr, ETH_ALEN);
1024 } else { /* pairwise key */
1025 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1026 ("set pairwise key\n"));
1027 if (!sta) {
1028 RT_ASSERT(false, ("pairwise key withnot"
1029 "mac_addr\n"));
1030
1031 err = -EOPNOTSUPP;
1032 goto out_unlock;
1033 }
1034 /* Pairwise key with an assigned MAC address. */
1035 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1036 /*set local buf about pairwise key. */
1037 memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
1038 key->key, key->keylen);
1039 rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
1040 rtlpriv->sec.pairwise_key =
1041 rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
1042 memcpy(mac_addr, sta->addr, ETH_ALEN);
1043 }
1044 rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
1045 group_key, key_type, wep_only,
1046 false);
1047 /* <5> tell mac80211 do something: */
1048 /*must use sw generate IV, or can not work !!!!. */
1049 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1050 key->hw_key_idx = key_idx;
1051 if (key_type == TKIP_ENCRYPTION)
1052 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1053 break;
1054 case DISABLE_KEY:
1055 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1056 ("disable key delete one entry\n"));
1057 /*set local buf about wep key. */
1058 if (mac->opmode == NL80211_IFTYPE_AP) {
1059 if (sta)
1060 rtl_cam_del_entry(hw, sta->addr);
1061 }
1062 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
1063 rtlpriv->sec.key_len[key_idx] = 0;
1064 memcpy(mac_addr, zero_addr, ETH_ALEN);
1065 /*
1066 *mac80211 will delete entrys one by one,
1067 *so don't use rtl_cam_reset_all_entry
1068 *or clear all entry here.
1069 */
1070 rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
1071
1072 rtl_cam_reset_sec_info(hw);
1073
1074 break;
1075 default:
1076 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1077 ("cmd_err:%x!!!!:\n", cmd));
1078 }
1079out_unlock:
1080 mutex_unlock(&rtlpriv->locks.conf_mutex);
1081 rtlpriv->sec.being_setkey = false;
1082 return err;
1083}
1084
1085static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1086{
1087 struct rtl_priv *rtlpriv = rtl_priv(hw);
1088
1089 bool radio_state;
1090 bool blocked;
1091 u8 valid = 0;
1092
1093 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1094 return;
1095
1096 mutex_lock(&rtlpriv->locks.conf_mutex);
1097
1098 /*if Radio On return true here */
1099 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
1100
1101 if (valid) {
1102 if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
1103 rtlpriv->rfkill.rfkill_state = radio_state;
1104
1105 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1106 (KERN_INFO "wireless radio switch turned %s\n",
1107 radio_state ? "on" : "off"));
1108
1109 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
1110 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1111 }
1112 }
1113
1114 mutex_unlock(&rtlpriv->locks.conf_mutex);
1115}
1116
1117/* this function is called by mac80211 to flush tx buffer
1118 * before switch channle or power save, or tx buffer packet
1119 * maybe send after offchannel or rf sleep, this may cause
1120 * dis-association by AP */
1121static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
1122{
1123 struct rtl_priv *rtlpriv = rtl_priv(hw);
1124
1125 if (rtlpriv->intf_ops->flush)
1126 rtlpriv->intf_ops->flush(hw, drop);
1127}
1128
1129const struct ieee80211_ops rtl_ops = {
1130 .start = rtl_op_start,
1131 .stop = rtl_op_stop,
1132 .tx = rtl_op_tx,
1133 .add_interface = rtl_op_add_interface,
1134 .remove_interface = rtl_op_remove_interface,
1135 .config = rtl_op_config,
1136 .configure_filter = rtl_op_configure_filter,
1137 .sta_add = rtl_op_sta_add,
1138 .sta_remove = rtl_op_sta_remove,
1139 .set_key = rtl_op_set_key,
1140 .conf_tx = rtl_op_conf_tx,
1141 .bss_info_changed = rtl_op_bss_info_changed,
1142 .get_tsf = rtl_op_get_tsf,
1143 .set_tsf = rtl_op_set_tsf,
1144 .reset_tsf = rtl_op_reset_tsf,
1145 .sta_notify = rtl_op_sta_notify,
1146 .ampdu_action = rtl_op_ampdu_action,
1147 .sw_scan_start = rtl_op_sw_scan_start,
1148 .sw_scan_complete = rtl_op_sw_scan_complete,
1149 .rfkill_poll = rtl_op_rfkill_poll,
1150 .flush = rtl_op_flush,
1151};
1/******************************************************************************
2 *
3 * Copyright(c) 2009-2012 Realtek Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
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
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
30#include "wifi.h"
31#include "core.h"
32#include "cam.h"
33#include "base.h"
34#include "pci.h"
35#include "ps.h"
36
37#include <linux/export.h>
38
39void rtl_addr_delay(u32 addr)
40{
41 if (addr == 0xfe)
42 mdelay(50);
43 else if (addr == 0xfd)
44 mdelay(5);
45 else if (addr == 0xfc)
46 mdelay(1);
47 else if (addr == 0xfb)
48 udelay(50);
49 else if (addr == 0xfa)
50 udelay(5);
51 else if (addr == 0xf9)
52 udelay(1);
53}
54EXPORT_SYMBOL(rtl_addr_delay);
55
56void rtl_rfreg_delay(struct ieee80211_hw *hw, enum radio_path rfpath, u32 addr,
57 u32 mask, u32 data)
58{
59 if (addr == 0xfe) {
60 mdelay(50);
61 } else if (addr == 0xfd) {
62 mdelay(5);
63 } else if (addr == 0xfc) {
64 mdelay(1);
65 } else if (addr == 0xfb) {
66 udelay(50);
67 } else if (addr == 0xfa) {
68 udelay(5);
69 } else if (addr == 0xf9) {
70 udelay(1);
71 } else {
72 rtl_set_rfreg(hw, rfpath, addr, mask, data);
73 udelay(1);
74 }
75}
76EXPORT_SYMBOL(rtl_rfreg_delay);
77
78void rtl_bb_delay(struct ieee80211_hw *hw, u32 addr, u32 data)
79{
80 if (addr == 0xfe) {
81 mdelay(50);
82 } else if (addr == 0xfd) {
83 mdelay(5);
84 } else if (addr == 0xfc) {
85 mdelay(1);
86 } else if (addr == 0xfb) {
87 udelay(50);
88 } else if (addr == 0xfa) {
89 udelay(5);
90 } else if (addr == 0xf9) {
91 udelay(1);
92 } else {
93 rtl_set_bbreg(hw, addr, MASKDWORD, data);
94 udelay(1);
95 }
96}
97EXPORT_SYMBOL(rtl_bb_delay);
98
99void rtl_fw_cb(const struct firmware *firmware, void *context)
100{
101 struct ieee80211_hw *hw = context;
102 struct rtl_priv *rtlpriv = rtl_priv(hw);
103 int err;
104
105 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
106 "Firmware callback routine entered!\n");
107 complete(&rtlpriv->firmware_loading_complete);
108 if (!firmware) {
109 if (rtlpriv->cfg->alt_fw_name) {
110 err = request_firmware(&firmware,
111 rtlpriv->cfg->alt_fw_name,
112 rtlpriv->io.dev);
113 pr_info("Loading alternative firmware %s\n",
114 rtlpriv->cfg->alt_fw_name);
115 if (!err)
116 goto found_alt;
117 }
118 pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name);
119 rtlpriv->max_fw_size = 0;
120 return;
121 }
122found_alt:
123 if (firmware->size > rtlpriv->max_fw_size) {
124 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
125 "Firmware is too big!\n");
126 release_firmware(firmware);
127 return;
128 }
129 memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, firmware->size);
130 rtlpriv->rtlhal.fwsize = firmware->size;
131 release_firmware(firmware);
132
133 err = ieee80211_register_hw(hw);
134 if (err) {
135 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
136 "Can't register mac80211 hw\n");
137 return;
138 } else {
139 rtlpriv->mac80211.mac80211_registered = 1;
140 }
141 set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
142
143 /*init rfkill */
144 rtl_init_rfkill(hw);
145}
146EXPORT_SYMBOL(rtl_fw_cb);
147
148/*mutex for start & stop is must here. */
149static int rtl_op_start(struct ieee80211_hw *hw)
150{
151 int err;
152 struct rtl_priv *rtlpriv = rtl_priv(hw);
153 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
154
155 if (!is_hal_stop(rtlhal))
156 return 0;
157 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
158 return 0;
159 mutex_lock(&rtlpriv->locks.conf_mutex);
160 err = rtlpriv->intf_ops->adapter_start(hw);
161 if (!err)
162 rtl_watch_dog_timer_callback((unsigned long)hw);
163 mutex_unlock(&rtlpriv->locks.conf_mutex);
164 return err;
165}
166
167static void rtl_op_stop(struct ieee80211_hw *hw)
168{
169 struct rtl_priv *rtlpriv = rtl_priv(hw);
170 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
171 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
172 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
173
174 if (is_hal_stop(rtlhal))
175 return;
176
177 /* here is must, because adhoc do stop and start,
178 * but stop with RFOFF may cause something wrong,
179 * like adhoc TP
180 */
181 if (unlikely(ppsc->rfpwr_state == ERFOFF)) {
182 rtl_ips_nic_on(hw);
183 }
184
185 mutex_lock(&rtlpriv->locks.conf_mutex);
186
187 mac->link_state = MAC80211_NOLINK;
188 memset(mac->bssid, 0, ETH_ALEN);
189 mac->vendor = PEER_UNKNOWN;
190
191 /*reset sec info */
192 rtl_cam_reset_sec_info(hw);
193
194 rtl_deinit_deferred_work(hw);
195 rtlpriv->intf_ops->adapter_stop(hw);
196
197 mutex_unlock(&rtlpriv->locks.conf_mutex);
198}
199
200static void rtl_op_tx(struct ieee80211_hw *hw,
201 struct ieee80211_tx_control *control,
202 struct sk_buff *skb)
203{
204 struct rtl_priv *rtlpriv = rtl_priv(hw);
205 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
206 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
207 struct rtl_tcb_desc tcb_desc;
208 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
209
210 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
211 goto err_free;
212
213 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
214 goto err_free;
215
216 if (!rtlpriv->intf_ops->waitq_insert(hw, control->sta, skb))
217 rtlpriv->intf_ops->adapter_tx(hw, control->sta, skb, &tcb_desc);
218
219 return;
220
221err_free:
222 dev_kfree_skb_any(skb);
223}
224
225static int rtl_op_add_interface(struct ieee80211_hw *hw,
226 struct ieee80211_vif *vif)
227{
228 struct rtl_priv *rtlpriv = rtl_priv(hw);
229 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
230 int err = 0;
231
232 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
233
234 if (mac->vif) {
235 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
236 "vif has been set!! mac->vif = 0x%p\n", mac->vif);
237 return -EOPNOTSUPP;
238 }
239
240 rtl_ips_nic_on(hw);
241
242 mutex_lock(&rtlpriv->locks.conf_mutex);
243
244 switch (ieee80211_vif_type_p2p(vif)) {
245 case NL80211_IFTYPE_P2P_CLIENT:
246 mac->p2p = P2P_ROLE_CLIENT;
247 /*fall through*/
248 case NL80211_IFTYPE_STATION:
249 if (mac->beacon_enabled == 1) {
250 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
251 "NL80211_IFTYPE_STATION\n");
252 mac->beacon_enabled = 0;
253 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
254 rtlpriv->cfg->maps
255 [RTL_IBSS_INT_MASKS]);
256 }
257 mac->link_state = MAC80211_LINKED;
258 break;
259 case NL80211_IFTYPE_ADHOC:
260 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
261 "NL80211_IFTYPE_ADHOC\n");
262
263 mac->link_state = MAC80211_LINKED;
264 rtlpriv->cfg->ops->set_bcn_reg(hw);
265 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
266 mac->basic_rates = 0xfff;
267 else
268 mac->basic_rates = 0xff0;
269 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
270 (u8 *) (&mac->basic_rates));
271
272 break;
273 case NL80211_IFTYPE_P2P_GO:
274 mac->p2p = P2P_ROLE_GO;
275 /*fall through*/
276 case NL80211_IFTYPE_AP:
277 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
278 "NL80211_IFTYPE_AP\n");
279
280 mac->link_state = MAC80211_LINKED;
281 rtlpriv->cfg->ops->set_bcn_reg(hw);
282 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
283 mac->basic_rates = 0xfff;
284 else
285 mac->basic_rates = 0xff0;
286 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
287 (u8 *) (&mac->basic_rates));
288 break;
289 case NL80211_IFTYPE_MESH_POINT:
290 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
291 "NL80211_IFTYPE_MESH_POINT\n");
292
293 mac->link_state = MAC80211_LINKED;
294 rtlpriv->cfg->ops->set_bcn_reg(hw);
295 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
296 mac->basic_rates = 0xfff;
297 else
298 mac->basic_rates = 0xff0;
299 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
300 (u8 *)(&mac->basic_rates));
301 break;
302 default:
303 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
304 "operation mode %d is not supported!\n", vif->type);
305 err = -EOPNOTSUPP;
306 goto out;
307 }
308
309 if (mac->p2p) {
310 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
311 "p2p role %x\n", vif->type);
312 mac->basic_rates = 0xff0;/*disable cck rate for p2p*/
313 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
314 (u8 *)(&mac->basic_rates));
315 }
316 mac->vif = vif;
317 mac->opmode = vif->type;
318 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
319 memcpy(mac->mac_addr, vif->addr, ETH_ALEN);
320 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
321
322out:
323 mutex_unlock(&rtlpriv->locks.conf_mutex);
324 return err;
325}
326
327static void rtl_op_remove_interface(struct ieee80211_hw *hw,
328 struct ieee80211_vif *vif)
329{
330 struct rtl_priv *rtlpriv = rtl_priv(hw);
331 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
332
333 mutex_lock(&rtlpriv->locks.conf_mutex);
334
335 /* Free beacon resources */
336 if ((vif->type == NL80211_IFTYPE_AP) ||
337 (vif->type == NL80211_IFTYPE_ADHOC) ||
338 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
339 if (mac->beacon_enabled == 1) {
340 mac->beacon_enabled = 0;
341 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
342 rtlpriv->cfg->maps
343 [RTL_IBSS_INT_MASKS]);
344 }
345 }
346
347 /*
348 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
349 *NO LINK for our hardware.
350 */
351 mac->p2p = 0;
352 mac->vif = NULL;
353 mac->link_state = MAC80211_NOLINK;
354 memset(mac->bssid, 0, ETH_ALEN);
355 mac->vendor = PEER_UNKNOWN;
356 mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
357 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
358 mutex_unlock(&rtlpriv->locks.conf_mutex);
359}
360
361static int rtl_op_change_interface(struct ieee80211_hw *hw,
362 struct ieee80211_vif *vif,
363 enum nl80211_iftype new_type, bool p2p)
364{
365 struct rtl_priv *rtlpriv = rtl_priv(hw);
366 int ret;
367 rtl_op_remove_interface(hw, vif);
368
369 vif->type = new_type;
370 vif->p2p = p2p;
371 ret = rtl_op_add_interface(hw, vif);
372 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
373 "p2p %x\n", p2p);
374 return ret;
375}
376
377static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
378{
379 struct rtl_priv *rtlpriv = rtl_priv(hw);
380 struct rtl_phy *rtlphy = &(rtlpriv->phy);
381 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
382 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
383 struct ieee80211_conf *conf = &hw->conf;
384
385 if (mac->skip_scan)
386 return 1;
387
388 mutex_lock(&rtlpriv->locks.conf_mutex);
389 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /*BIT(2)*/
390 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
391 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
392 }
393
394 /*For IPS */
395 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
396 if (hw->conf.flags & IEEE80211_CONF_IDLE)
397 rtl_ips_nic_off(hw);
398 else
399 rtl_ips_nic_on(hw);
400 } else {
401 /*
402 *although rfoff may not cause by ips, but we will
403 *check the reason in set_rf_power_state function
404 */
405 if (unlikely(ppsc->rfpwr_state == ERFOFF))
406 rtl_ips_nic_on(hw);
407 }
408
409 /*For LPS */
410 if (changed & IEEE80211_CONF_CHANGE_PS) {
411 cancel_delayed_work(&rtlpriv->works.ps_work);
412 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
413 if (conf->flags & IEEE80211_CONF_PS) {
414 rtlpriv->psc.sw_ps_enabled = true;
415 /* sleep here is must, or we may recv the beacon and
416 * cause mac80211 into wrong ps state, this will cause
417 * power save nullfunc send fail, and further cause
418 * pkt loss, So sleep must quickly but not immediatly
419 * because that will cause nullfunc send by mac80211
420 * fail, and cause pkt loss, we have tested that 5mA
421 * is worked very well */
422 if (!rtlpriv->psc.multi_buffered)
423 queue_delayed_work(rtlpriv->works.rtl_wq,
424 &rtlpriv->works.ps_work,
425 MSECS(5));
426 } else {
427 rtl_swlps_rf_awake(hw);
428 rtlpriv->psc.sw_ps_enabled = false;
429 }
430 }
431
432 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
433 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
434 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
435 hw->conf.long_frame_max_tx_count);
436 mac->retry_long = hw->conf.long_frame_max_tx_count;
437 mac->retry_short = hw->conf.long_frame_max_tx_count;
438 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
439 (u8 *) (&hw->conf.
440 long_frame_max_tx_count));
441 }
442
443 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
444 struct ieee80211_channel *channel = hw->conf.chandef.chan;
445 u8 wide_chan = (u8) channel->hw_value;
446
447 if (mac->act_scanning)
448 mac->n_channels++;
449
450 if (rtlpriv->dm.supp_phymode_switch &&
451 mac->link_state < MAC80211_LINKED &&
452 !mac->act_scanning) {
453 if (rtlpriv->cfg->ops->chk_switch_dmdp)
454 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
455 }
456
457 /*
458 *because we should back channel to
459 *current_network.chan in in scanning,
460 *So if set_chan == current_network.chan
461 *we should set it.
462 *because mac80211 tell us wrong bw40
463 *info for cisco1253 bw20, so we modify
464 *it here based on UPPER & LOWER
465 */
466 switch (cfg80211_get_chandef_type(&hw->conf.chandef)) {
467 case NL80211_CHAN_HT20:
468 case NL80211_CHAN_NO_HT:
469 /* SC */
470 mac->cur_40_prime_sc =
471 PRIME_CHNL_OFFSET_DONT_CARE;
472 rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
473 mac->bw_40 = false;
474 break;
475 case NL80211_CHAN_HT40MINUS:
476 /* SC */
477 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
478 rtlphy->current_chan_bw =
479 HT_CHANNEL_WIDTH_20_40;
480 mac->bw_40 = true;
481
482 /*wide channel */
483 wide_chan -= 2;
484
485 break;
486 case NL80211_CHAN_HT40PLUS:
487 /* SC */
488 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
489 rtlphy->current_chan_bw =
490 HT_CHANNEL_WIDTH_20_40;
491 mac->bw_40 = true;
492
493 /*wide channel */
494 wide_chan += 2;
495
496 break;
497 default:
498 mac->bw_40 = false;
499 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
500 "switch case not processed\n");
501 break;
502 }
503
504 if (wide_chan <= 0)
505 wide_chan = 1;
506
507 /* In scanning, before we go offchannel we may send a ps = 1
508 * null to AP, and then we may send a ps = 0 null to AP quickly,
509 * but first null may have caused AP to put lots of packet to
510 * hw tx buffer. These packets must be tx'd before we go off
511 * channel so we must delay more time to let AP flush these
512 * packets before going offchannel, or dis-association or
513 * delete BA will be caused by AP
514 */
515 if (rtlpriv->mac80211.offchan_delay) {
516 rtlpriv->mac80211.offchan_delay = false;
517 mdelay(50);
518 }
519 rtlphy->current_channel = wide_chan;
520
521 rtlpriv->cfg->ops->switch_channel(hw);
522 rtlpriv->cfg->ops->set_channel_access(hw);
523 rtlpriv->cfg->ops->set_bw_mode(hw,
524 cfg80211_get_chandef_type(&hw->conf.chandef));
525 }
526
527 mutex_unlock(&rtlpriv->locks.conf_mutex);
528
529 return 0;
530}
531
532static void rtl_op_configure_filter(struct ieee80211_hw *hw,
533 unsigned int changed_flags,
534 unsigned int *new_flags, u64 multicast)
535{
536 struct rtl_priv *rtlpriv = rtl_priv(hw);
537 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
538 u32 rx_conf;
539
540 *new_flags &= RTL_SUPPORTED_FILTERS;
541 if (!changed_flags)
542 return;
543
544 /* if ssid not set to hw don't check bssid
545 * here just used for linked scanning, & linked
546 * and nolink check bssid is set in set network_type */
547 if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
548 (mac->link_state >= MAC80211_LINKED)) {
549 if (mac->opmode != NL80211_IFTYPE_AP &&
550 mac->opmode != NL80211_IFTYPE_MESH_POINT) {
551 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
552 rtlpriv->cfg->ops->set_chk_bssid(hw, false);
553 } else {
554 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
555 }
556 }
557 }
558
559 /* must be called after set_chk_bssid since that function modifies the
560 * RCR register too. */
561 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&rx_conf));
562
563 /*TODO: we disable broadcase now, so enable here */
564 if (changed_flags & FIF_ALLMULTI) {
565 if (*new_flags & FIF_ALLMULTI) {
566 rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] |
567 rtlpriv->cfg->maps[MAC_RCR_AB];
568 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
569 "Enable receive multicast frame\n");
570 } else {
571 rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] |
572 rtlpriv->cfg->maps[MAC_RCR_AB]);
573 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
574 "Disable receive multicast frame\n");
575 }
576 }
577
578 if (changed_flags & FIF_FCSFAIL) {
579 if (*new_flags & FIF_FCSFAIL) {
580 rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32];
581 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
582 "Enable receive FCS error frame\n");
583 } else {
584 rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32];
585 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
586 "Disable receive FCS error frame\n");
587 }
588 }
589
590
591 if (changed_flags & FIF_CONTROL) {
592 if (*new_flags & FIF_CONTROL) {
593 rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
594
595 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
596 "Enable receive control frame\n");
597 } else {
598 rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
599 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
600 "Disable receive control frame\n");
601 }
602 }
603
604 if (changed_flags & FIF_OTHER_BSS) {
605 if (*new_flags & FIF_OTHER_BSS) {
606 rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP];
607 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
608 "Enable receive other BSS's frame\n");
609 } else {
610 rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP];
611 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
612 "Disable receive other BSS's frame\n");
613 }
614 }
615
616 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&rx_conf));
617}
618static int rtl_op_sta_add(struct ieee80211_hw *hw,
619 struct ieee80211_vif *vif,
620 struct ieee80211_sta *sta)
621{
622 struct rtl_priv *rtlpriv = rtl_priv(hw);
623 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
624 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
625 struct rtl_sta_info *sta_entry;
626
627 if (sta) {
628 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
629 spin_lock_bh(&rtlpriv->locks.entry_list_lock);
630 list_add_tail(&sta_entry->list, &rtlpriv->entry_list);
631 spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
632 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
633 sta_entry->wireless_mode = WIRELESS_MODE_G;
634 if (sta->supp_rates[0] <= 0xf)
635 sta_entry->wireless_mode = WIRELESS_MODE_B;
636 if (sta->ht_cap.ht_supported == true)
637 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
638
639 if (vif->type == NL80211_IFTYPE_ADHOC)
640 sta_entry->wireless_mode = WIRELESS_MODE_G;
641 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
642 sta_entry->wireless_mode = WIRELESS_MODE_A;
643 if (sta->ht_cap.ht_supported == true)
644 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
645
646 if (vif->type == NL80211_IFTYPE_ADHOC)
647 sta_entry->wireless_mode = WIRELESS_MODE_A;
648 }
649 /*disable cck rate for p2p*/
650 if (mac->p2p)
651 sta->supp_rates[0] &= 0xfffffff0;
652
653 memcpy(sta_entry->mac_addr, sta->addr, ETH_ALEN);
654 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
655 "Add sta addr is %pM\n", sta->addr);
656 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
657 }
658 return 0;
659}
660
661static int rtl_op_sta_remove(struct ieee80211_hw *hw,
662 struct ieee80211_vif *vif,
663 struct ieee80211_sta *sta)
664{
665 struct rtl_priv *rtlpriv = rtl_priv(hw);
666 struct rtl_sta_info *sta_entry;
667 if (sta) {
668 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
669 "Remove sta addr is %pM\n", sta->addr);
670 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
671 sta_entry->wireless_mode = 0;
672 sta_entry->ratr_index = 0;
673
674 spin_lock_bh(&rtlpriv->locks.entry_list_lock);
675 list_del(&sta_entry->list);
676 spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
677 }
678 return 0;
679}
680
681static int _rtl_get_hal_qnum(u16 queue)
682{
683 int qnum;
684
685 switch (queue) {
686 case 0:
687 qnum = AC3_VO;
688 break;
689 case 1:
690 qnum = AC2_VI;
691 break;
692 case 2:
693 qnum = AC0_BE;
694 break;
695 case 3:
696 qnum = AC1_BK;
697 break;
698 default:
699 qnum = AC0_BE;
700 break;
701 }
702 return qnum;
703}
704
705/*
706 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
707 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
708 */
709static int rtl_op_conf_tx(struct ieee80211_hw *hw,
710 struct ieee80211_vif *vif, u16 queue,
711 const struct ieee80211_tx_queue_params *param)
712{
713 struct rtl_priv *rtlpriv = rtl_priv(hw);
714 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
715 int aci;
716
717 if (queue >= AC_MAX) {
718 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
719 "queue number %d is incorrect!\n", queue);
720 return -EINVAL;
721 }
722
723 aci = _rtl_get_hal_qnum(queue);
724 mac->ac[aci].aifs = param->aifs;
725 mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
726 mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
727 mac->ac[aci].tx_op = cpu_to_le16(param->txop);
728 memcpy(&mac->edca_param[aci], param, sizeof(*param));
729 rtlpriv->cfg->ops->set_qos(hw, aci);
730 return 0;
731}
732
733static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
734 struct ieee80211_vif *vif,
735 struct ieee80211_bss_conf *bss_conf, u32 changed)
736{
737 struct rtl_priv *rtlpriv = rtl_priv(hw);
738 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
739 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
740 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
741 struct ieee80211_sta *sta = NULL;
742
743 mutex_lock(&rtlpriv->locks.conf_mutex);
744 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
745 (vif->type == NL80211_IFTYPE_AP) ||
746 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
747 if ((changed & BSS_CHANGED_BEACON) ||
748 (changed & BSS_CHANGED_BEACON_ENABLED &&
749 bss_conf->enable_beacon)) {
750 if (mac->beacon_enabled == 0) {
751 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
752 "BSS_CHANGED_BEACON_ENABLED\n");
753
754 /*start hw beacon interrupt. */
755 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
756 mac->beacon_enabled = 1;
757 rtlpriv->cfg->ops->update_interrupt_mask(hw,
758 rtlpriv->cfg->maps
759 [RTL_IBSS_INT_MASKS],
760 0);
761
762 if (rtlpriv->cfg->ops->linked_set_reg)
763 rtlpriv->cfg->ops->linked_set_reg(hw);
764 }
765 }
766 if ((changed & BSS_CHANGED_BEACON_ENABLED &&
767 !bss_conf->enable_beacon)) {
768 if (mac->beacon_enabled == 1) {
769 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
770 "ADHOC DISABLE BEACON\n");
771
772 mac->beacon_enabled = 0;
773 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
774 rtlpriv->cfg->maps
775 [RTL_IBSS_INT_MASKS]);
776 }
777 }
778 if (changed & BSS_CHANGED_BEACON_INT) {
779 RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
780 "BSS_CHANGED_BEACON_INT\n");
781 mac->beacon_interval = bss_conf->beacon_int;
782 rtlpriv->cfg->ops->set_bcn_intv(hw);
783 }
784 }
785
786 /*TODO: reference to enum ieee80211_bss_change */
787 if (changed & BSS_CHANGED_ASSOC) {
788 if (bss_conf->assoc) {
789 struct ieee80211_sta *sta = NULL;
790 /* we should reset all sec info & cam
791 * before set cam after linked, we should not
792 * reset in disassoc, that will cause tkip->wep
793 * fail because some flag will be wrong */
794 /* reset sec info */
795 rtl_cam_reset_sec_info(hw);
796 /* reset cam to fix wep fail issue
797 * when change from wpa to wep */
798 rtl_cam_reset_all_entry(hw);
799
800 mac->link_state = MAC80211_LINKED;
801 mac->cnt_after_linked = 0;
802 mac->assoc_id = bss_conf->aid;
803 memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
804
805 if (rtlpriv->cfg->ops->linked_set_reg)
806 rtlpriv->cfg->ops->linked_set_reg(hw);
807 rcu_read_lock();
808 sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
809 if (!sta) {
810 pr_err("ieee80211_find_sta returned NULL\n");
811 rcu_read_unlock();
812 goto out;
813 }
814
815 if (vif->type == NL80211_IFTYPE_STATION && sta)
816 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
817 RT_TRACE(rtlpriv, COMP_EASY_CONCURRENT, DBG_LOUD,
818 "send PS STATIC frame\n");
819 if (rtlpriv->dm.supp_phymode_switch) {
820 if (sta->ht_cap.ht_supported)
821 rtl_send_smps_action(hw, sta,
822 IEEE80211_SMPS_STATIC);
823 }
824 rcu_read_unlock();
825
826 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
827 "BSS_CHANGED_ASSOC\n");
828 } else {
829 if (mac->link_state == MAC80211_LINKED) {
830 rtlpriv->enter_ps = false;
831 schedule_work(&rtlpriv->works.lps_change_work);
832 }
833
834 if (ppsc->p2p_ps_info.p2p_ps_mode > P2P_PS_NONE)
835 rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE);
836 mac->link_state = MAC80211_NOLINK;
837 memset(mac->bssid, 0, ETH_ALEN);
838 mac->vendor = PEER_UNKNOWN;
839
840 if (rtlpriv->dm.supp_phymode_switch) {
841 if (rtlpriv->cfg->ops->chk_switch_dmdp)
842 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
843 }
844
845 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
846 "BSS_CHANGED_UN_ASSOC\n");
847 }
848 }
849
850 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
851 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
852 "BSS_CHANGED_ERP_CTS_PROT\n");
853 mac->use_cts_protect = bss_conf->use_cts_prot;
854 }
855
856 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
857 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
858 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
859 bss_conf->use_short_preamble);
860
861 mac->short_preamble = bss_conf->use_short_preamble;
862 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
863 &mac->short_preamble);
864 }
865
866 if (changed & BSS_CHANGED_ERP_SLOT) {
867 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
868 "BSS_CHANGED_ERP_SLOT\n");
869
870 if (bss_conf->use_short_slot)
871 mac->slot_time = RTL_SLOT_TIME_9;
872 else
873 mac->slot_time = RTL_SLOT_TIME_20;
874
875 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
876 &mac->slot_time);
877 }
878
879 if (changed & BSS_CHANGED_HT) {
880 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, "BSS_CHANGED_HT\n");
881 rcu_read_lock();
882 sta = get_sta(hw, vif, bss_conf->bssid);
883 if (sta) {
884 if (sta->ht_cap.ampdu_density >
885 mac->current_ampdu_density)
886 mac->current_ampdu_density =
887 sta->ht_cap.ampdu_density;
888 if (sta->ht_cap.ampdu_factor <
889 mac->current_ampdu_factor)
890 mac->current_ampdu_factor =
891 sta->ht_cap.ampdu_factor;
892 }
893 rcu_read_unlock();
894
895 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
896 &mac->max_mss_density);
897 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
898 &mac->current_ampdu_factor);
899 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
900 &mac->current_ampdu_density);
901 }
902
903 if (changed & BSS_CHANGED_BSSID) {
904 u32 basic_rates;
905
906 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
907 (u8 *) bss_conf->bssid);
908
909 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, "%pM\n",
910 bss_conf->bssid);
911
912 mac->vendor = PEER_UNKNOWN;
913 memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
914 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
915
916 rcu_read_lock();
917 sta = get_sta(hw, vif, bss_conf->bssid);
918 if (!sta) {
919 rcu_read_unlock();
920 goto out;
921 }
922
923 if (rtlhal->current_bandtype == BAND_ON_5G) {
924 mac->mode = WIRELESS_MODE_A;
925 } else {
926 if (sta->supp_rates[0] <= 0xf)
927 mac->mode = WIRELESS_MODE_B;
928 else
929 mac->mode = WIRELESS_MODE_G;
930 }
931
932 if (sta->ht_cap.ht_supported) {
933 if (rtlhal->current_bandtype == BAND_ON_2_4G)
934 mac->mode = WIRELESS_MODE_N_24G;
935 else
936 mac->mode = WIRELESS_MODE_N_5G;
937 }
938
939 /* just station need it, because ibss & ap mode will
940 * set in sta_add, and will be NULL here */
941 if (mac->opmode == NL80211_IFTYPE_STATION) {
942 struct rtl_sta_info *sta_entry;
943 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
944 sta_entry->wireless_mode = mac->mode;
945 }
946
947 if (sta->ht_cap.ht_supported) {
948 mac->ht_enable = true;
949
950 /*
951 * for cisco 1252 bw20 it's wrong
952 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
953 * mac->bw_40 = true;
954 * }
955 * */
956 }
957
958 if (changed & BSS_CHANGED_BASIC_RATES) {
959 /* for 5G must << RATE_6M_INDEX = 4,
960 * because 5G have no cck rate*/
961 if (rtlhal->current_bandtype == BAND_ON_5G)
962 basic_rates = sta->supp_rates[1] << 4;
963 else
964 basic_rates = sta->supp_rates[0];
965
966 mac->basic_rates = basic_rates;
967 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
968 (u8 *)(&basic_rates));
969 }
970 rcu_read_unlock();
971 }
972
973 /*
974 * For FW LPS:
975 * To tell firmware we have connected
976 * to an AP. For 92SE/CE power save v2.
977 */
978 if (changed & BSS_CHANGED_ASSOC) {
979 if (bss_conf->assoc) {
980 if (ppsc->fwctrl_lps) {
981 u8 mstatus = RT_MEDIA_CONNECT;
982 u8 keep_alive = 10;
983 rtlpriv->cfg->ops->set_hw_reg(hw,
984 HW_VAR_KEEP_ALIVE,
985 &keep_alive);
986
987 rtlpriv->cfg->ops->set_hw_reg(hw,
988 HW_VAR_H2C_FW_JOINBSSRPT,
989 &mstatus);
990 ppsc->report_linked = true;
991 }
992 } else {
993 if (ppsc->fwctrl_lps) {
994 u8 mstatus = RT_MEDIA_DISCONNECT;
995 rtlpriv->cfg->ops->set_hw_reg(hw,
996 HW_VAR_H2C_FW_JOINBSSRPT,
997 &mstatus);
998 ppsc->report_linked = false;
999 }
1000 }
1001 if (rtlpriv->cfg->ops->bt_wifi_media_status_notify)
1002 rtlpriv->cfg->ops->bt_wifi_media_status_notify(hw,
1003 ppsc->report_linked);
1004 }
1005
1006out:
1007 mutex_unlock(&rtlpriv->locks.conf_mutex);
1008}
1009
1010static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1011{
1012 struct rtl_priv *rtlpriv = rtl_priv(hw);
1013 u64 tsf;
1014
1015 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
1016 return tsf;
1017}
1018
1019static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1020 u64 tsf)
1021{
1022 struct rtl_priv *rtlpriv = rtl_priv(hw);
1023 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1024 u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
1025
1026 mac->tsf = tsf;
1027 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, &bibss);
1028}
1029
1030static void rtl_op_reset_tsf(struct ieee80211_hw *hw,
1031 struct ieee80211_vif *vif)
1032{
1033 struct rtl_priv *rtlpriv = rtl_priv(hw);
1034 u8 tmp = 0;
1035
1036 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, &tmp);
1037}
1038
1039static void rtl_op_sta_notify(struct ieee80211_hw *hw,
1040 struct ieee80211_vif *vif,
1041 enum sta_notify_cmd cmd,
1042 struct ieee80211_sta *sta)
1043{
1044 switch (cmd) {
1045 case STA_NOTIFY_SLEEP:
1046 break;
1047 case STA_NOTIFY_AWAKE:
1048 break;
1049 default:
1050 break;
1051 }
1052}
1053
1054static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
1055 struct ieee80211_vif *vif,
1056 enum ieee80211_ampdu_mlme_action action,
1057 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
1058 u8 buf_size)
1059{
1060 struct rtl_priv *rtlpriv = rtl_priv(hw);
1061
1062 switch (action) {
1063 case IEEE80211_AMPDU_TX_START:
1064 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1065 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid);
1066 return rtl_tx_agg_start(hw, sta, tid, ssn);
1067 break;
1068 case IEEE80211_AMPDU_TX_STOP_CONT:
1069 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1070 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1071 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1072 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
1073 return rtl_tx_agg_stop(hw, sta, tid);
1074 case IEEE80211_AMPDU_TX_OPERATIONAL:
1075 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1076 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
1077 rtl_tx_agg_oper(hw, sta, tid);
1078 break;
1079 case IEEE80211_AMPDU_RX_START:
1080 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1081 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
1082 return rtl_rx_agg_start(hw, sta, tid);
1083 case IEEE80211_AMPDU_RX_STOP:
1084 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1085 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
1086 return rtl_rx_agg_stop(hw, sta, tid);
1087 default:
1088 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1089 "IEEE80211_AMPDU_ERR!!!!:\n");
1090 return -EOPNOTSUPP;
1091 }
1092 return 0;
1093}
1094
1095static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
1096{
1097 struct rtl_priv *rtlpriv = rtl_priv(hw);
1098 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1099
1100 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
1101 mac->act_scanning = true;
1102 if (rtlpriv->link_info.higher_busytraffic) {
1103 mac->skip_scan = true;
1104 return;
1105 }
1106
1107 if (rtlpriv->dm.supp_phymode_switch) {
1108 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1109 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1110 }
1111 if (mac->link_state == MAC80211_LINKED) {
1112 rtlpriv->enter_ps = false;
1113 schedule_work(&rtlpriv->works.lps_change_work);
1114 mac->link_state = MAC80211_LINKED_SCANNING;
1115 } else {
1116 rtl_ips_nic_on(hw);
1117 }
1118
1119 /* Dual mac */
1120 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
1121
1122 rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
1123 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
1124}
1125
1126static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
1127{
1128 struct rtl_priv *rtlpriv = rtl_priv(hw);
1129 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1130
1131 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
1132 mac->act_scanning = false;
1133 mac->skip_scan = false;
1134 if (rtlpriv->link_info.higher_busytraffic)
1135 return;
1136
1137 /*p2p will use 1/6/11 to scan */
1138 if (mac->n_channels == 3)
1139 mac->p2p_in_use = true;
1140 else
1141 mac->p2p_in_use = false;
1142 mac->n_channels = 0;
1143 /* Dual mac */
1144 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
1145
1146 if (mac->link_state == MAC80211_LINKED_SCANNING) {
1147 mac->link_state = MAC80211_LINKED;
1148 if (mac->opmode == NL80211_IFTYPE_STATION) {
1149 /* fix fwlps issue */
1150 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
1151 }
1152 }
1153
1154 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
1155}
1156
1157static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1158 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1159 struct ieee80211_key_conf *key)
1160{
1161 struct rtl_priv *rtlpriv = rtl_priv(hw);
1162 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1163 u8 key_type = NO_ENCRYPTION;
1164 u8 key_idx;
1165 bool group_key = false;
1166 bool wep_only = false;
1167 int err = 0;
1168 u8 mac_addr[ETH_ALEN];
1169 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1170
1171 if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
1172 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1173 "not open hw encryption\n");
1174 return -ENOSPC; /*User disabled HW-crypto */
1175 }
1176 /* To support IBSS, use sw-crypto for GTK */
1177 if (((vif->type == NL80211_IFTYPE_ADHOC) ||
1178 (vif->type == NL80211_IFTYPE_MESH_POINT)) &&
1179 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
1180 return -ENOSPC;
1181 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1182 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
1183 cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
1184 sta ? sta->addr : bcast_addr);
1185 rtlpriv->sec.being_setkey = true;
1186 rtl_ips_nic_on(hw);
1187 mutex_lock(&rtlpriv->locks.conf_mutex);
1188 /* <1> get encryption alg */
1189
1190 switch (key->cipher) {
1191 case WLAN_CIPHER_SUITE_WEP40:
1192 key_type = WEP40_ENCRYPTION;
1193 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
1194 break;
1195 case WLAN_CIPHER_SUITE_WEP104:
1196 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
1197 key_type = WEP104_ENCRYPTION;
1198 break;
1199 case WLAN_CIPHER_SUITE_TKIP:
1200 key_type = TKIP_ENCRYPTION;
1201 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
1202 break;
1203 case WLAN_CIPHER_SUITE_CCMP:
1204 key_type = AESCCMP_ENCRYPTION;
1205 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
1206 break;
1207 case WLAN_CIPHER_SUITE_AES_CMAC:
1208 /*HW doesn't support CMAC encryption, use software CMAC */
1209 key_type = AESCMAC_ENCRYPTION;
1210 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n");
1211 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1212 "HW don't support CMAC encryption, use software CMAC\n");
1213 err = -EOPNOTSUPP;
1214 goto out_unlock;
1215 default:
1216 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n",
1217 key->cipher);
1218 goto out_unlock;
1219 }
1220 if (key_type == WEP40_ENCRYPTION ||
1221 key_type == WEP104_ENCRYPTION ||
1222 mac->opmode == NL80211_IFTYPE_ADHOC)
1223 rtlpriv->sec.use_defaultkey = true;
1224
1225 /* <2> get key_idx */
1226 key_idx = (u8) (key->keyidx);
1227 if (key_idx > 3)
1228 goto out_unlock;
1229 /* <3> if pairwise key enable_hw_sec */
1230 group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
1231
1232 /* wep always be group key, but there are two conditions:
1233 * 1) wep only: is just for wep enc, in this condition
1234 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1235 * will be true & enable_hw_sec will be set when wep
1236 * key setting.
1237 * 2) wep(group) + AES(pairwise): some AP like cisco
1238 * may use it, in this condition enable_hw_sec will not
1239 * be set when wep key setting */
1240 /* we must reset sec_info after lingked before set key,
1241 * or some flag will be wrong*/
1242 if (vif->type == NL80211_IFTYPE_AP ||
1243 vif->type == NL80211_IFTYPE_MESH_POINT) {
1244 if (!group_key || key_type == WEP40_ENCRYPTION ||
1245 key_type == WEP104_ENCRYPTION) {
1246 if (group_key)
1247 wep_only = true;
1248 rtlpriv->cfg->ops->enable_hw_sec(hw);
1249 }
1250 } else {
1251 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
1252 rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
1253 if (rtlpriv->sec.pairwise_enc_algorithm ==
1254 NO_ENCRYPTION &&
1255 (key_type == WEP40_ENCRYPTION ||
1256 key_type == WEP104_ENCRYPTION))
1257 wep_only = true;
1258 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1259 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1260 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1261 key_type);
1262 rtlpriv->cfg->ops->enable_hw_sec(hw);
1263 }
1264 }
1265 /* <4> set key based on cmd */
1266 switch (cmd) {
1267 case SET_KEY:
1268 if (wep_only) {
1269 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1270 "set WEP(group/pairwise) key\n");
1271 /* Pairwise key with an assigned MAC address. */
1272 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1273 rtlpriv->sec.group_enc_algorithm = key_type;
1274 /*set local buf about wep key. */
1275 memcpy(rtlpriv->sec.key_buf[key_idx],
1276 key->key, key->keylen);
1277 rtlpriv->sec.key_len[key_idx] = key->keylen;
1278 eth_zero_addr(mac_addr);
1279 } else if (group_key) { /* group key */
1280 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1281 "set group key\n");
1282 /* group key */
1283 rtlpriv->sec.group_enc_algorithm = key_type;
1284 /*set local buf about group key. */
1285 memcpy(rtlpriv->sec.key_buf[key_idx],
1286 key->key, key->keylen);
1287 rtlpriv->sec.key_len[key_idx] = key->keylen;
1288 memcpy(mac_addr, bcast_addr, ETH_ALEN);
1289 } else { /* pairwise key */
1290 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1291 "set pairwise key\n");
1292 if (!sta) {
1293 RT_ASSERT(false,
1294 "pairwise key without mac_addr\n");
1295
1296 err = -EOPNOTSUPP;
1297 goto out_unlock;
1298 }
1299 /* Pairwise key with an assigned MAC address. */
1300 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1301 /*set local buf about pairwise key. */
1302 memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
1303 key->key, key->keylen);
1304 rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
1305 rtlpriv->sec.pairwise_key =
1306 rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
1307 memcpy(mac_addr, sta->addr, ETH_ALEN);
1308 }
1309 rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
1310 group_key, key_type, wep_only,
1311 false);
1312 /* <5> tell mac80211 do something: */
1313 /*must use sw generate IV, or can not work !!!!. */
1314 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1315 key->hw_key_idx = key_idx;
1316 if (key_type == TKIP_ENCRYPTION)
1317 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1318 /*use software CCMP encryption for management frames (MFP) */
1319 if (key_type == AESCCMP_ENCRYPTION)
1320 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1321 break;
1322 case DISABLE_KEY:
1323 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1324 "disable key delete one entry\n");
1325 /*set local buf about wep key. */
1326 if (vif->type == NL80211_IFTYPE_AP ||
1327 vif->type == NL80211_IFTYPE_MESH_POINT) {
1328 if (sta)
1329 rtl_cam_del_entry(hw, sta->addr);
1330 }
1331 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
1332 rtlpriv->sec.key_len[key_idx] = 0;
1333 eth_zero_addr(mac_addr);
1334 /*
1335 *mac80211 will delete entrys one by one,
1336 *so don't use rtl_cam_reset_all_entry
1337 *or clear all entry here.
1338 */
1339 rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
1340
1341 rtl_cam_reset_sec_info(hw);
1342
1343 break;
1344 default:
1345 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1346 "cmd_err:%x!!!!\n", cmd);
1347 }
1348out_unlock:
1349 mutex_unlock(&rtlpriv->locks.conf_mutex);
1350 rtlpriv->sec.being_setkey = false;
1351 return err;
1352}
1353
1354static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1355{
1356 struct rtl_priv *rtlpriv = rtl_priv(hw);
1357
1358 bool radio_state;
1359 bool blocked;
1360 u8 valid = 0;
1361
1362 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1363 return;
1364
1365 mutex_lock(&rtlpriv->locks.conf_mutex);
1366
1367 /*if Radio On return true here */
1368 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
1369
1370 if (valid) {
1371 if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
1372 rtlpriv->rfkill.rfkill_state = radio_state;
1373
1374 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1375 "wireless radio switch turned %s\n",
1376 radio_state ? "on" : "off");
1377
1378 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
1379 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1380 }
1381 }
1382
1383 mutex_unlock(&rtlpriv->locks.conf_mutex);
1384}
1385
1386/* this function is called by mac80211 to flush tx buffer
1387 * before switch channel or power save, or tx buffer packet
1388 * maybe send after offchannel or rf sleep, this may cause
1389 * dis-association by AP */
1390static void rtl_op_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1391{
1392 struct rtl_priv *rtlpriv = rtl_priv(hw);
1393
1394 if (rtlpriv->intf_ops->flush)
1395 rtlpriv->intf_ops->flush(hw, drop);
1396}
1397
1398const struct ieee80211_ops rtl_ops = {
1399 .start = rtl_op_start,
1400 .stop = rtl_op_stop,
1401 .tx = rtl_op_tx,
1402 .add_interface = rtl_op_add_interface,
1403 .remove_interface = rtl_op_remove_interface,
1404 .change_interface = rtl_op_change_interface,
1405 .config = rtl_op_config,
1406 .configure_filter = rtl_op_configure_filter,
1407 .sta_add = rtl_op_sta_add,
1408 .sta_remove = rtl_op_sta_remove,
1409 .set_key = rtl_op_set_key,
1410 .conf_tx = rtl_op_conf_tx,
1411 .bss_info_changed = rtl_op_bss_info_changed,
1412 .get_tsf = rtl_op_get_tsf,
1413 .set_tsf = rtl_op_set_tsf,
1414 .reset_tsf = rtl_op_reset_tsf,
1415 .sta_notify = rtl_op_sta_notify,
1416 .ampdu_action = rtl_op_ampdu_action,
1417 .sw_scan_start = rtl_op_sw_scan_start,
1418 .sw_scan_complete = rtl_op_sw_scan_complete,
1419 .rfkill_poll = rtl_op_rfkill_poll,
1420 .flush = rtl_op_flush,
1421};
1422EXPORT_SYMBOL_GPL(rtl_ops);