ath9k: Print the correct channel mode
[deliverable/linux.git] / drivers / net / wireless / rtlwifi / core.c
CommitLineData
0c817338
LF
1/******************************************************************************
2 *
a8d76066 3 * Copyright(c) 2009-2012 Realtek Corporation.
0c817338
LF
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>
0baa0fd7 27 *
0c817338
LF
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{
32473284 39 int err;
0c817338
LF
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;
8a09d6d8 47 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338 48 err = rtlpriv->intf_ops->adapter_start(hw);
32473284
LF
49 if (!err)
50 rtl_watch_dog_timer_callback((unsigned long)hw);
8a09d6d8 51 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
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
8a09d6d8 70 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338
LF
71
72 mac->link_state = MAC80211_NOLINK;
73 memset(mac->bssid, 0, 6);
0baa0fd7 74 mac->vendor = PEER_UNKNOWN;
0c817338
LF
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
8a09d6d8 82 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
83}
84
7bb45683 85static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
0c817338
LF
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));
0baa0fd7
C
90 struct rtl_tcb_desc tcb_desc;
91 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
0c817338
LF
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
0baa0fd7
C
99 if (!rtlpriv->intf_ops->waitq_insert(hw, skb))
100 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
0c817338 101
7bb45683 102 return;
0c817338
LF
103
104err_free:
105 dev_kfree_skb_any(skb);
0c817338
LF
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
c1288b12
JB
115 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
116
0c817338
LF
117 if (mac->vif) {
118 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
f30d7507 119 "vif has been set!! mac->vif = 0x%p\n", mac->vif);
0c817338
LF
120 return -EOPNOTSUPP;
121 }
122
123 rtl_ips_nic_on(hw);
124
8a09d6d8 125 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338
LF
126 switch (vif->type) {
127 case NL80211_IFTYPE_STATION:
128 if (mac->beacon_enabled == 1) {
129 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 130 "NL80211_IFTYPE_STATION\n");
0c817338
LF
131 mac->beacon_enabled = 0;
132 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
133 rtlpriv->cfg->maps
134 [RTL_IBSS_INT_MASKS]);
135 }
136 break;
137 case NL80211_IFTYPE_ADHOC:
138 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 139 "NL80211_IFTYPE_ADHOC\n");
0c817338
LF
140
141 mac->link_state = MAC80211_LINKED;
142 rtlpriv->cfg->ops->set_bcn_reg(hw);
0baa0fd7
C
143 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
144 mac->basic_rates = 0xfff;
145 else
146 mac->basic_rates = 0xff0;
147 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
148 (u8 *) (&mac->basic_rates));
149
0c817338
LF
150 break;
151 case NL80211_IFTYPE_AP:
152 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 153 "NL80211_IFTYPE_AP\n");
0baa0fd7
C
154
155 mac->link_state = MAC80211_LINKED;
156 rtlpriv->cfg->ops->set_bcn_reg(hw);
157 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
158 mac->basic_rates = 0xfff;
159 else
160 mac->basic_rates = 0xff0;
161 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
162 (u8 *) (&mac->basic_rates));
0c817338
LF
163 break;
164 default:
165 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
f30d7507 166 "operation mode %d is not supported!\n", vif->type);
0c817338
LF
167 err = -EOPNOTSUPP;
168 goto out;
169 }
170
171 mac->vif = vif;
172 mac->opmode = vif->type;
173 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
174 memcpy(mac->mac_addr, vif->addr, ETH_ALEN);
175 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
176
177out:
8a09d6d8 178 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
179 return err;
180}
181
182static void rtl_op_remove_interface(struct ieee80211_hw *hw,
183 struct ieee80211_vif *vif)
184{
185 struct rtl_priv *rtlpriv = rtl_priv(hw);
186 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
187
8a09d6d8 188 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338
LF
189
190 /* Free beacon resources */
191 if ((mac->opmode == NL80211_IFTYPE_AP) ||
192 (mac->opmode == NL80211_IFTYPE_ADHOC) ||
193 (mac->opmode == NL80211_IFTYPE_MESH_POINT)) {
194 if (mac->beacon_enabled == 1) {
195 mac->beacon_enabled = 0;
196 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
197 rtlpriv->cfg->maps
198 [RTL_IBSS_INT_MASKS]);
199 }
200 }
201
202 /*
203 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
204 *NO LINK for our hardware.
205 */
206 mac->vif = NULL;
207 mac->link_state = MAC80211_NOLINK;
208 memset(mac->bssid, 0, 6);
0baa0fd7 209 mac->vendor = PEER_UNKNOWN;
0c817338
LF
210 mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
211 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
8a09d6d8 212 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
213}
214
0c817338
LF
215static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
216{
217 struct rtl_priv *rtlpriv = rtl_priv(hw);
218 struct rtl_phy *rtlphy = &(rtlpriv->phy);
219 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
220 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
221 struct ieee80211_conf *conf = &hw->conf;
222
8a09d6d8 223 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338
LF
224 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /*BIT(2)*/
225 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 226 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
0c817338
LF
227 }
228
229 /*For IPS */
230 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
231 if (hw->conf.flags & IEEE80211_CONF_IDLE)
232 rtl_ips_nic_off(hw);
233 else
234 rtl_ips_nic_on(hw);
235 } else {
236 /*
237 *although rfoff may not cause by ips, but we will
238 *check the reason in set_rf_power_state function
239 */
240 if (unlikely(ppsc->rfpwr_state == ERFOFF))
241 rtl_ips_nic_on(hw);
242 }
243
244 /*For LPS */
245 if (changed & IEEE80211_CONF_CHANGE_PS) {
0baa0fd7
C
246 cancel_delayed_work(&rtlpriv->works.ps_work);
247 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
248 if (conf->flags & IEEE80211_CONF_PS) {
249 rtlpriv->psc.sw_ps_enabled = true;
250 /* sleep here is must, or we may recv the beacon and
251 * cause mac80211 into wrong ps state, this will cause
252 * power save nullfunc send fail, and further cause
253 * pkt loss, So sleep must quickly but not immediatly
254 * because that will cause nullfunc send by mac80211
255 * fail, and cause pkt loss, we have tested that 5mA
256 * is worked very well */
257 if (!rtlpriv->psc.multi_buffered)
258 queue_delayed_work(rtlpriv->works.rtl_wq,
259 &rtlpriv->works.ps_work,
260 MSECS(5));
261 } else {
262 rtl_swlps_rf_awake(hw);
263 rtlpriv->psc.sw_ps_enabled = false;
264 }
0c817338
LF
265 }
266
267 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
268 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507
JP
269 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
270 hw->conf.long_frame_max_tx_count);
0c817338
LF
271 mac->retry_long = hw->conf.long_frame_max_tx_count;
272 mac->retry_short = hw->conf.long_frame_max_tx_count;
273 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
274 (u8 *) (&hw->conf.
275 long_frame_max_tx_count));
276 }
277
278 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
279 struct ieee80211_channel *channel = hw->conf.channel;
280 u8 wide_chan = (u8) channel->hw_value;
281
282 /*
283 *because we should back channel to
284 *current_network.chan in in scanning,
285 *So if set_chan == current_network.chan
286 *we should set it.
287 *because mac80211 tell us wrong bw40
288 *info for cisco1253 bw20, so we modify
289 *it here based on UPPER & LOWER
290 */
291 switch (hw->conf.channel_type) {
292 case NL80211_CHAN_HT20:
293 case NL80211_CHAN_NO_HT:
294 /* SC */
295 mac->cur_40_prime_sc =
0baa0fd7 296 PRIME_CHNL_OFFSET_DONT_CARE;
0c817338
LF
297 rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
298 mac->bw_40 = false;
299 break;
300 case NL80211_CHAN_HT40MINUS:
301 /* SC */
302 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
303 rtlphy->current_chan_bw =
0baa0fd7 304 HT_CHANNEL_WIDTH_20_40;
0c817338
LF
305 mac->bw_40 = true;
306
307 /*wide channel */
308 wide_chan -= 2;
309
310 break;
311 case NL80211_CHAN_HT40PLUS:
312 /* SC */
313 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
314 rtlphy->current_chan_bw =
0baa0fd7 315 HT_CHANNEL_WIDTH_20_40;
0c817338
LF
316 mac->bw_40 = true;
317
318 /*wide channel */
319 wide_chan += 2;
320
321 break;
322 default:
323 mac->bw_40 = false;
324 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
f30d7507 325 "switch case not processed\n");
0c817338
LF
326 break;
327 }
328
329 if (wide_chan <= 0)
330 wide_chan = 1;
0baa0fd7
C
331
332 /* In scanning, before we go offchannel we may send a ps=1 null
333 * to AP, and then we may send a ps = 0 null to AP quickly, but
334 * first null may have caused AP to put lots of packet to hw tx
335 * buffer. These packets must be tx'd before we go off channel
336 * so we must delay more time to let AP flush these packets
337 * before going offchannel, or dis-association or delete BA will
338 * happen by AP
339 */
9c050440
MM
340 if (rtlpriv->mac80211.offchan_delay) {
341 rtlpriv->mac80211.offchan_delay = false;
0baa0fd7
C
342 mdelay(50);
343 }
0c817338
LF
344 rtlphy->current_channel = wide_chan;
345
0c817338 346 rtlpriv->cfg->ops->switch_channel(hw);
0baa0fd7 347 rtlpriv->cfg->ops->set_channel_access(hw);
0c817338
LF
348 rtlpriv->cfg->ops->set_bw_mode(hw,
349 hw->conf.channel_type);
350 }
351
8a09d6d8 352 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
353
354 return 0;
355}
356
357static void rtl_op_configure_filter(struct ieee80211_hw *hw,
358 unsigned int changed_flags,
359 unsigned int *new_flags, u64 multicast)
360{
361 struct rtl_priv *rtlpriv = rtl_priv(hw);
362 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
363
364 *new_flags &= RTL_SUPPORTED_FILTERS;
365 if (!changed_flags)
366 return;
367
368 /*TODO: we disable broadcase now, so enable here */
369 if (changed_flags & FIF_ALLMULTI) {
370 if (*new_flags & FIF_ALLMULTI) {
371 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] |
372 rtlpriv->cfg->maps[MAC_RCR_AB];
373 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 374 "Enable receive multicast frame\n");
0c817338
LF
375 } else {
376 mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] |
377 rtlpriv->cfg->maps[MAC_RCR_AB]);
378 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 379 "Disable receive multicast frame\n");
0c817338
LF
380 }
381 }
382
383 if (changed_flags & FIF_FCSFAIL) {
384 if (*new_flags & FIF_FCSFAIL) {
385 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32];
386 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 387 "Enable receive FCS error frame\n");
0c817338
LF
388 } else {
389 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32];
390 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 391 "Disable receive FCS error frame\n");
0c817338
LF
392 }
393 }
394
0baa0fd7
C
395 /* if ssid not set to hw don't check bssid
396 * here just used for linked scanning, & linked
397 * and nolink check bssid is set in set network_type */
398 if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
399 (mac->link_state >= MAC80211_LINKED)) {
400 if (mac->opmode != NL80211_IFTYPE_AP) {
401 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
402 rtlpriv->cfg->ops->set_chk_bssid(hw, false);
403 } else {
404 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
405 }
406 }
0c817338
LF
407 }
408
409 if (changed_flags & FIF_CONTROL) {
410 if (*new_flags & FIF_CONTROL) {
411 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
0c817338
LF
412
413 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 414 "Enable receive control frame\n");
0c817338
LF
415 } else {
416 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
0c817338 417 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 418 "Disable receive control frame\n");
0c817338
LF
419 }
420 }
421
422 if (changed_flags & FIF_OTHER_BSS) {
423 if (*new_flags & FIF_OTHER_BSS) {
424 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP];
425 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 426 "Enable receive other BSS's frame\n");
0c817338
LF
427 } else {
428 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP];
429 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507 430 "Disable receive other BSS's frame\n");
0c817338
LF
431 }
432 }
0c817338 433}
0baa0fd7
C
434static int rtl_op_sta_add(struct ieee80211_hw *hw,
435 struct ieee80211_vif *vif,
436 struct ieee80211_sta *sta)
437{
438 struct rtl_priv *rtlpriv = rtl_priv(hw);
439 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
440 struct rtl_sta_info *sta_entry;
441
442 if (sta) {
443 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
444 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
445 sta_entry->wireless_mode = WIRELESS_MODE_G;
446 if (sta->supp_rates[0] <= 0xf)
447 sta_entry->wireless_mode = WIRELESS_MODE_B;
e10542c4 448 if (sta->ht_cap.ht_supported)
0baa0fd7
C
449 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
450 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
451 sta_entry->wireless_mode = WIRELESS_MODE_A;
e10542c4 452 if (sta->ht_cap.ht_supported)
0baa0fd7
C
453 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
454 }
455
456 /* I found some times mac80211 give wrong supp_rates for adhoc*/
457 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC)
458 sta_entry->wireless_mode = WIRELESS_MODE_G;
0c817338 459
0baa0fd7 460 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
f30d7507 461 "Add sta addr is %pM\n", sta->addr);
0baa0fd7
C
462 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
463 }
464 return 0;
465}
466static int rtl_op_sta_remove(struct ieee80211_hw *hw,
467 struct ieee80211_vif *vif,
468 struct ieee80211_sta *sta)
469{
470 struct rtl_priv *rtlpriv = rtl_priv(hw);
471 struct rtl_sta_info *sta_entry;
472 if (sta) {
473 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
f30d7507 474 "Remove sta addr is %pM\n", sta->addr);
0baa0fd7
C
475 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
476 sta_entry->wireless_mode = 0;
477 sta_entry->ratr_index = 0;
478 }
479 return 0;
480}
0c817338
LF
481static int _rtl_get_hal_qnum(u16 queue)
482{
483 int qnum;
484
485 switch (queue) {
486 case 0:
487 qnum = AC3_VO;
488 break;
489 case 1:
490 qnum = AC2_VI;
491 break;
492 case 2:
493 qnum = AC0_BE;
494 break;
495 case 3:
496 qnum = AC1_BK;
497 break;
498 default:
499 qnum = AC0_BE;
500 break;
501 }
502 return qnum;
503}
504
505/*
506 *for mac80211 VO=0, VI=1, BE=2, BK=3
507 *for rtl819x BE=0, BK=1, VI=2, VO=3
508 */
8a3a3c85
EP
509static int rtl_op_conf_tx(struct ieee80211_hw *hw,
510 struct ieee80211_vif *vif, u16 queue,
0c817338
LF
511 const struct ieee80211_tx_queue_params *param)
512{
513 struct rtl_priv *rtlpriv = rtl_priv(hw);
514 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
515 int aci;
516
517 if (queue >= AC_MAX) {
518 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
f30d7507 519 "queue number %d is incorrect!\n", queue);
0c817338
LF
520 return -EINVAL;
521 }
522
523 aci = _rtl_get_hal_qnum(queue);
524 mac->ac[aci].aifs = param->aifs;
17c9ac62
LF
525 mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
526 mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
527 mac->ac[aci].tx_op = cpu_to_le16(param->txop);
0c817338
LF
528 memcpy(&mac->edca_param[aci], param, sizeof(*param));
529 rtlpriv->cfg->ops->set_qos(hw, aci);
530 return 0;
531}
532
533static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
534 struct ieee80211_vif *vif,
535 struct ieee80211_bss_conf *bss_conf, u32 changed)
536{
537 struct rtl_priv *rtlpriv = rtl_priv(hw);
0baa0fd7 538 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
0c817338
LF
539 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
540 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
0baa0fd7 541 struct ieee80211_sta *sta = NULL;
0c817338 542
8a09d6d8 543 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338
LF
544 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
545 (vif->type == NL80211_IFTYPE_AP) ||
546 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
0c817338
LF
547 if ((changed & BSS_CHANGED_BEACON) ||
548 (changed & BSS_CHANGED_BEACON_ENABLED &&
549 bss_conf->enable_beacon)) {
0c817338
LF
550 if (mac->beacon_enabled == 0) {
551 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
f30d7507 552 "BSS_CHANGED_BEACON_ENABLED\n");
0c817338
LF
553
554 /*start hw beacon interrupt. */
555 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
556 mac->beacon_enabled = 1;
557 rtlpriv->cfg->ops->update_interrupt_mask(hw,
558 rtlpriv->cfg->maps
559 [RTL_IBSS_INT_MASKS],
560 0);
0baa0fd7
C
561
562 if (rtlpriv->cfg->ops->linked_set_reg)
563 rtlpriv->cfg->ops->linked_set_reg(hw);
0c817338 564 }
0baa0fd7
C
565 }
566 if ((changed & BSS_CHANGED_BEACON_ENABLED &&
567 !bss_conf->enable_beacon)) {
0c817338
LF
568 if (mac->beacon_enabled == 1) {
569 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
f30d7507 570 "ADHOC DISABLE BEACON\n");
0c817338
LF
571
572 mac->beacon_enabled = 0;
573 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
574 rtlpriv->cfg->maps
575 [RTL_IBSS_INT_MASKS]);
576 }
577 }
0c817338
LF
578 if (changed & BSS_CHANGED_BEACON_INT) {
579 RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
f30d7507 580 "BSS_CHANGED_BEACON_INT\n");
0c817338
LF
581 mac->beacon_interval = bss_conf->beacon_int;
582 rtlpriv->cfg->ops->set_bcn_intv(hw);
583 }
584 }
585
586 /*TODO: reference to enum ieee80211_bss_change */
587 if (changed & BSS_CHANGED_ASSOC) {
588 if (bss_conf->assoc) {
0baa0fd7
C
589 /* we should reset all sec info & cam
590 * before set cam after linked, we should not
591 * reset in disassoc, that will cause tkip->wep
592 * fail because some flag will be wrong */
593 /* reset sec info */
594 rtl_cam_reset_sec_info(hw);
595 /* reset cam to fix wep fail issue
596 * when change from wpa to wep */
597 rtl_cam_reset_all_entry(hw);
598
0c817338
LF
599 mac->link_state = MAC80211_LINKED;
600 mac->cnt_after_linked = 0;
601 mac->assoc_id = bss_conf->aid;
602 memcpy(mac->bssid, bss_conf->bssid, 6);
603
0baa0fd7
C
604 if (rtlpriv->cfg->ops->linked_set_reg)
605 rtlpriv->cfg->ops->linked_set_reg(hw);
606 if (mac->opmode == NL80211_IFTYPE_STATION && sta)
607 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
0c817338 608 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
f30d7507 609 "BSS_CHANGED_ASSOC\n");
0c817338
LF
610 } else {
611 if (mac->link_state == MAC80211_LINKED)
612 rtl_lps_leave(hw);
613
614 mac->link_state = MAC80211_NOLINK;
615 memset(mac->bssid, 0, 6);
bac2555c
G
616
617 /* reset sec info */
618 rtl_cam_reset_sec_info(hw);
619
620 rtl_cam_reset_all_entry(hw);
0baa0fd7 621 mac->vendor = PEER_UNKNOWN;
0c817338
LF
622
623 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
f30d7507 624 "BSS_CHANGED_UN_ASSOC\n");
0c817338
LF
625 }
626 }
627
628 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
629 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 630 "BSS_CHANGED_ERP_CTS_PROT\n");
0c817338
LF
631 mac->use_cts_protect = bss_conf->use_cts_prot;
632 }
633
634 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
635 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
f30d7507
JP
636 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
637 bss_conf->use_short_preamble);
0c817338
LF
638
639 mac->short_preamble = bss_conf->use_short_preamble;
640 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
641 (u8 *) (&mac->short_preamble));
642 }
643
644 if (changed & BSS_CHANGED_ERP_SLOT) {
645 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 646 "BSS_CHANGED_ERP_SLOT\n");
0c817338
LF
647
648 if (bss_conf->use_short_slot)
649 mac->slot_time = RTL_SLOT_TIME_9;
650 else
651 mac->slot_time = RTL_SLOT_TIME_20;
652
653 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
654 (u8 *) (&mac->slot_time));
655 }
656
657 if (changed & BSS_CHANGED_HT) {
f30d7507 658 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, "BSS_CHANGED_HT\n");
701c2be0 659 rcu_read_lock();
7101f404 660 sta = get_sta(hw, vif, bss_conf->bssid);
0c817338
LF
661 if (sta) {
662 if (sta->ht_cap.ampdu_density >
663 mac->current_ampdu_density)
664 mac->current_ampdu_density =
665 sta->ht_cap.ampdu_density;
666 if (sta->ht_cap.ampdu_factor <
667 mac->current_ampdu_factor)
668 mac->current_ampdu_factor =
669 sta->ht_cap.ampdu_factor;
670 }
701c2be0 671 rcu_read_unlock();
0c817338
LF
672
673 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
674 (u8 *) (&mac->max_mss_density));
675 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
676 &mac->current_ampdu_factor);
677 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
678 &mac->current_ampdu_density);
679 }
680
681 if (changed & BSS_CHANGED_BSSID) {
0c817338 682 u32 basic_rates;
0c817338
LF
683
684 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
685 (u8 *) bss_conf->bssid);
686
f30d7507
JP
687 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, "%pM\n",
688 bss_conf->bssid);
0c817338 689
0baa0fd7 690 mac->vendor = PEER_UNKNOWN;
0c817338 691 memcpy(mac->bssid, bss_conf->bssid, 6);
0baa0fd7 692 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
0c817338 693
701c2be0 694 rcu_read_lock();
7101f404 695 sta = get_sta(hw, vif, bss_conf->bssid);
0baa0fd7
C
696 if (!sta) {
697 rcu_read_unlock();
698 goto out;
699 }
0c817338 700
0baa0fd7
C
701 if (rtlhal->current_bandtype == BAND_ON_5G) {
702 mac->mode = WIRELESS_MODE_A;
703 } else {
704 if (sta->supp_rates[0] <= 0xf)
705 mac->mode = WIRELESS_MODE_B;
706 else
707 mac->mode = WIRELESS_MODE_G;
708 }
709
710 if (sta->ht_cap.ht_supported) {
711 if (rtlhal->current_bandtype == BAND_ON_2_4G)
0c817338 712 mac->mode = WIRELESS_MODE_N_24G;
0baa0fd7
C
713 else
714 mac->mode = WIRELESS_MODE_N_5G;
715 }
0c817338 716
0baa0fd7
C
717 /* just station need it, because ibss & ap mode will
718 * set in sta_add, and will be NULL here */
719 if (mac->opmode == NL80211_IFTYPE_STATION) {
720 struct rtl_sta_info *sta_entry;
721 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
722 sta_entry->wireless_mode = mac->mode;
723 }
724
725 if (sta->ht_cap.ht_supported) {
726 mac->ht_enable = true;
727
728 /*
729 * for cisco 1252 bw20 it's wrong
730 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
731 * mac->bw_40 = true;
732 * }
733 * */
0c817338
LF
734 }
735
0c817338 736 if (changed & BSS_CHANGED_BASIC_RATES) {
0baa0fd7
C
737 /* for 5G must << RATE_6M_INDEX=4,
738 * because 5G have no cck rate*/
739 if (rtlhal->current_bandtype == BAND_ON_5G)
740 basic_rates = sta->supp_rates[1] << 4;
0c817338 741 else
0baa0fd7 742 basic_rates = sta->supp_rates[0];
0c817338
LF
743
744 mac->basic_rates = basic_rates;
745 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
746 (u8 *) (&basic_rates));
0c817338 747 }
0baa0fd7 748 rcu_read_unlock();
0c817338
LF
749 }
750
751 /*
752 * For FW LPS:
753 * To tell firmware we have connected
754 * to an AP. For 92SE/CE power save v2.
755 */
756 if (changed & BSS_CHANGED_ASSOC) {
757 if (bss_conf->assoc) {
7ea47240 758 if (ppsc->fwctrl_lps) {
0c817338
LF
759 u8 mstatus = RT_MEDIA_CONNECT;
760 rtlpriv->cfg->ops->set_hw_reg(hw,
761 HW_VAR_H2C_FW_JOINBSSRPT,
762 (u8 *) (&mstatus));
763 ppsc->report_linked = true;
764 }
765 } else {
7ea47240 766 if (ppsc->fwctrl_lps) {
0c817338
LF
767 u8 mstatus = RT_MEDIA_DISCONNECT;
768 rtlpriv->cfg->ops->set_hw_reg(hw,
769 HW_VAR_H2C_FW_JOINBSSRPT,
770 (u8 *)(&mstatus));
771 ppsc->report_linked = false;
772 }
773 }
774 }
775
776out:
8a09d6d8 777 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
778}
779
37a41b4a 780static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
0c817338
LF
781{
782 struct rtl_priv *rtlpriv = rtl_priv(hw);
783 u64 tsf;
784
785 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
786 return tsf;
787}
788
37a41b4a
EP
789static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
790 u64 tsf)
0c817338
LF
791{
792 struct rtl_priv *rtlpriv = rtl_priv(hw);
793 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
6eab04a8 794 u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
0c817338
LF
795
796 mac->tsf = tsf;
797 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss));
798}
799
37a41b4a
EP
800static void rtl_op_reset_tsf(struct ieee80211_hw *hw,
801 struct ieee80211_vif *vif)
0c817338
LF
802{
803 struct rtl_priv *rtlpriv = rtl_priv(hw);
804 u8 tmp = 0;
805
806 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *) (&tmp));
807}
808
809static void rtl_op_sta_notify(struct ieee80211_hw *hw,
810 struct ieee80211_vif *vif,
811 enum sta_notify_cmd cmd,
812 struct ieee80211_sta *sta)
813{
814 switch (cmd) {
815 case STA_NOTIFY_SLEEP:
816 break;
817 case STA_NOTIFY_AWAKE:
818 break;
819 default:
820 break;
821 }
822}
823
824static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
825 struct ieee80211_vif *vif,
826 enum ieee80211_ampdu_mlme_action action,
0b01f030
JB
827 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
828 u8 buf_size)
0c817338
LF
829{
830 struct rtl_priv *rtlpriv = rtl_priv(hw);
831
832 switch (action) {
833 case IEEE80211_AMPDU_TX_START:
834 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 835 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid);
0baa0fd7 836 return rtl_tx_agg_start(hw, sta, tid, ssn);
0c817338
LF
837 break;
838 case IEEE80211_AMPDU_TX_STOP:
839 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 840 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid);
0baa0fd7 841 return rtl_tx_agg_stop(hw, sta, tid);
0c817338
LF
842 break;
843 case IEEE80211_AMPDU_TX_OPERATIONAL:
844 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 845 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid);
0baa0fd7 846 rtl_tx_agg_oper(hw, sta, tid);
0c817338
LF
847 break;
848 case IEEE80211_AMPDU_RX_START:
849 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 850 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid);
0c817338
LF
851 break;
852 case IEEE80211_AMPDU_RX_STOP:
853 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
f30d7507 854 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid);
0c817338
LF
855 break;
856 default:
857 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
f30d7507 858 "IEEE80211_AMPDU_ERR!!!!:\n");
0c817338
LF
859 return -EOPNOTSUPP;
860 }
861 return 0;
862}
863
864static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
865{
866 struct rtl_priv *rtlpriv = rtl_priv(hw);
867 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
868
869 mac->act_scanning = true;
870
f30d7507 871 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
0c817338
LF
872
873 if (mac->link_state == MAC80211_LINKED) {
874 rtl_lps_leave(hw);
875 mac->link_state = MAC80211_LINKED_SCANNING;
0baa0fd7 876 } else {
0c817338 877 rtl_ips_nic_on(hw);
0baa0fd7
C
878 }
879
880 /* Dual mac */
881 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
0c817338
LF
882
883 rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
884 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
885}
886
887static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
888{
889 struct rtl_priv *rtlpriv = rtl_priv(hw);
890 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
891
f30d7507 892 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n");
0c817338 893 mac->act_scanning = false;
0baa0fd7
C
894 /* Dual mac */
895 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
896
0c817338
LF
897 if (mac->link_state == MAC80211_LINKED_SCANNING) {
898 mac->link_state = MAC80211_LINKED;
0baa0fd7
C
899 if (mac->opmode == NL80211_IFTYPE_STATION) {
900 /* fix fwlps issue */
901 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
902 }
0c817338
LF
903 }
904
0baa0fd7 905 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
0c817338
LF
906}
907
908static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
909 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
910 struct ieee80211_key_conf *key)
911{
912 struct rtl_priv *rtlpriv = rtl_priv(hw);
913 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
914 u8 key_type = NO_ENCRYPTION;
915 u8 key_idx;
916 bool group_key = false;
917 bool wep_only = false;
918 int err = 0;
919 u8 mac_addr[ETH_ALEN];
920 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
921 u8 zero_addr[ETH_ALEN] = { 0 };
922
923 if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
924 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
f30d7507 925 "not open hw encryption\n");
0c817338
LF
926 return -ENOSPC; /*User disabled HW-crypto */
927 }
928 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
f30d7507
JP
929 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
930 cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
931 sta ? sta->addr : bcast_addr);
0c817338
LF
932 rtlpriv->sec.being_setkey = true;
933 rtl_ips_nic_on(hw);
8a09d6d8 934 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338 935 /* <1> get encryption alg */
0baa0fd7 936
0c817338
LF
937 switch (key->cipher) {
938 case WLAN_CIPHER_SUITE_WEP40:
939 key_type = WEP40_ENCRYPTION;
f30d7507 940 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n");
0c817338
LF
941 break;
942 case WLAN_CIPHER_SUITE_WEP104:
f30d7507 943 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
0c817338 944 key_type = WEP104_ENCRYPTION;
0c817338
LF
945 break;
946 case WLAN_CIPHER_SUITE_TKIP:
947 key_type = TKIP_ENCRYPTION;
f30d7507 948 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
0c817338
LF
949 break;
950 case WLAN_CIPHER_SUITE_CCMP:
951 key_type = AESCCMP_ENCRYPTION;
f30d7507 952 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
0c817338
LF
953 break;
954 default:
f30d7507
JP
955 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "alg_err:%x!!!!\n",
956 key->cipher);
0c817338
LF
957 goto out_unlock;
958 }
0baa0fd7
C
959 if (key_type == WEP40_ENCRYPTION ||
960 key_type == WEP104_ENCRYPTION ||
961 mac->opmode == NL80211_IFTYPE_ADHOC)
962 rtlpriv->sec.use_defaultkey = true;
963
0c817338
LF
964 /* <2> get key_idx */
965 key_idx = (u8) (key->keyidx);
966 if (key_idx > 3)
967 goto out_unlock;
968 /* <3> if pairwise key enable_hw_sec */
969 group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
0baa0fd7
C
970
971 /* wep always be group key, but there are two conditions:
972 * 1) wep only: is just for wep enc, in this condition
973 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
974 * will be true & enable_hw_sec will be set when wep
975 * ke setting.
976 * 2) wep(group) + AES(pairwise): some AP like cisco
977 * may use it, in this condition enable_hw_sec will not
978 * be set when wep key setting */
979 /* we must reset sec_info after lingked before set key,
980 * or some flag will be wrong*/
981 if (mac->opmode == NL80211_IFTYPE_AP) {
982 if (!group_key || key_type == WEP40_ENCRYPTION ||
983 key_type == WEP104_ENCRYPTION) {
984 if (group_key)
985 wep_only = true;
986 rtlpriv->cfg->ops->enable_hw_sec(hw);
987 }
988 } else {
989 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
990 rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
991 if (rtlpriv->sec.pairwise_enc_algorithm ==
992 NO_ENCRYPTION &&
993 (key_type == WEP40_ENCRYPTION ||
994 key_type == WEP104_ENCRYPTION))
995 wep_only = true;
996 rtlpriv->sec.pairwise_enc_algorithm = key_type;
997 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
f30d7507
JP
998 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
999 key_type);
0baa0fd7
C
1000 rtlpriv->cfg->ops->enable_hw_sec(hw);
1001 }
0c817338
LF
1002 }
1003 /* <4> set key based on cmd */
1004 switch (cmd) {
1005 case SET_KEY:
1006 if (wep_only) {
1007 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
f30d7507 1008 "set WEP(group/pairwise) key\n");
0c817338
LF
1009 /* Pairwise key with an assigned MAC address. */
1010 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1011 rtlpriv->sec.group_enc_algorithm = key_type;
1012 /*set local buf about wep key. */
1013 memcpy(rtlpriv->sec.key_buf[key_idx],
1014 key->key, key->keylen);
1015 rtlpriv->sec.key_len[key_idx] = key->keylen;
1016 memcpy(mac_addr, zero_addr, ETH_ALEN);
1017 } else if (group_key) { /* group key */
1018 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
f30d7507 1019 "set group key\n");
0c817338
LF
1020 /* group key */
1021 rtlpriv->sec.group_enc_algorithm = key_type;
1022 /*set local buf about group key. */
1023 memcpy(rtlpriv->sec.key_buf[key_idx],
1024 key->key, key->keylen);
1025 rtlpriv->sec.key_len[key_idx] = key->keylen;
1026 memcpy(mac_addr, bcast_addr, ETH_ALEN);
1027 } else { /* pairwise key */
1028 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
f30d7507 1029 "set pairwise key\n");
0c817338 1030 if (!sta) {
9d833ed7
JP
1031 RT_ASSERT(false,
1032 "pairwise key without mac_addr\n");
0baa0fd7 1033
0c817338
LF
1034 err = -EOPNOTSUPP;
1035 goto out_unlock;
1036 }
1037 /* Pairwise key with an assigned MAC address. */
1038 rtlpriv->sec.pairwise_enc_algorithm = key_type;
1039 /*set local buf about pairwise key. */
1040 memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
1041 key->key, key->keylen);
1042 rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
1043 rtlpriv->sec.pairwise_key =
1044 rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
1045 memcpy(mac_addr, sta->addr, ETH_ALEN);
1046 }
1047 rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
1048 group_key, key_type, wep_only,
1049 false);
1050 /* <5> tell mac80211 do something: */
1051 /*must use sw generate IV, or can not work !!!!. */
1052 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1053 key->hw_key_idx = key_idx;
1054 if (key_type == TKIP_ENCRYPTION)
1055 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1056 break;
1057 case DISABLE_KEY:
1058 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
f30d7507 1059 "disable key delete one entry\n");
0c817338 1060 /*set local buf about wep key. */
0baa0fd7
C
1061 if (mac->opmode == NL80211_IFTYPE_AP) {
1062 if (sta)
1063 rtl_cam_del_entry(hw, sta->addr);
1064 }
0c817338
LF
1065 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
1066 rtlpriv->sec.key_len[key_idx] = 0;
1067 memcpy(mac_addr, zero_addr, ETH_ALEN);
1068 /*
1069 *mac80211 will delete entrys one by one,
1070 *so don't use rtl_cam_reset_all_entry
1071 *or clear all entry here.
1072 */
1073 rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
bac2555c
G
1074
1075 rtl_cam_reset_sec_info(hw);
1076
0c817338
LF
1077 break;
1078 default:
1079 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
f30d7507 1080 "cmd_err:%x!!!!\n", cmd);
0c817338
LF
1081 }
1082out_unlock:
8a09d6d8 1083 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
1084 rtlpriv->sec.being_setkey = false;
1085 return err;
1086}
1087
1088static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1089{
1090 struct rtl_priv *rtlpriv = rtl_priv(hw);
1091
1092 bool radio_state;
1093 bool blocked;
1094 u8 valid = 0;
1095
1096 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1097 return;
1098
8a09d6d8 1099 mutex_lock(&rtlpriv->locks.conf_mutex);
0c817338
LF
1100
1101 /*if Radio On return true here */
1102 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
1103
1104 if (valid) {
1105 if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
1106 rtlpriv->rfkill.rfkill_state = radio_state;
1107
1108 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
f30d7507
JP
1109 "wireless radio switch turned %s\n",
1110 radio_state ? "on" : "off");
0c817338
LF
1111
1112 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
1113 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1114 }
1115 }
1116
8a09d6d8 1117 mutex_unlock(&rtlpriv->locks.conf_mutex);
0c817338
LF
1118}
1119
0baa0fd7
C
1120/* this function is called by mac80211 to flush tx buffer
1121 * before switch channle or power save, or tx buffer packet
1122 * maybe send after offchannel or rf sleep, this may cause
1123 * dis-association by AP */
1124static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
1125{
1126 struct rtl_priv *rtlpriv = rtl_priv(hw);
1127
1128 if (rtlpriv->intf_ops->flush)
1129 rtlpriv->intf_ops->flush(hw, drop);
1130}
1131
0c817338
LF
1132const struct ieee80211_ops rtl_ops = {
1133 .start = rtl_op_start,
1134 .stop = rtl_op_stop,
1135 .tx = rtl_op_tx,
1136 .add_interface = rtl_op_add_interface,
1137 .remove_interface = rtl_op_remove_interface,
1138 .config = rtl_op_config,
1139 .configure_filter = rtl_op_configure_filter,
0baa0fd7
C
1140 .sta_add = rtl_op_sta_add,
1141 .sta_remove = rtl_op_sta_remove,
0c817338
LF
1142 .set_key = rtl_op_set_key,
1143 .conf_tx = rtl_op_conf_tx,
1144 .bss_info_changed = rtl_op_bss_info_changed,
1145 .get_tsf = rtl_op_get_tsf,
1146 .set_tsf = rtl_op_set_tsf,
1147 .reset_tsf = rtl_op_reset_tsf,
1148 .sta_notify = rtl_op_sta_notify,
1149 .ampdu_action = rtl_op_ampdu_action,
1150 .sw_scan_start = rtl_op_sw_scan_start,
1151 .sw_scan_complete = rtl_op_sw_scan_complete,
1152 .rfkill_poll = rtl_op_rfkill_poll,
0baa0fd7 1153 .flush = rtl_op_flush,
0c817338 1154};
This page took 0.193611 seconds and 5 git commands to generate.