~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to drivers/net/wireless/rtlwifi/core.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-57i0gl3v99b3lkfg
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * Hsinchu 300, Taiwan.
25
25
 *
26
26
 * Larry Finger <Larry.Finger@lwfinger.net>
 
27
 *
27
28
 *****************************************************************************/
28
29
 
29
30
#include "wifi.h"
35
36
/*mutex for start & stop is must here. */
36
37
static int rtl_op_start(struct ieee80211_hw *hw)
37
38
{
38
 
        int err = 0;
 
39
        int err;
39
40
        struct rtl_priv *rtlpriv = rtl_priv(hw);
40
41
        struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
41
42
 
45
46
                return 0;
46
47
        mutex_lock(&rtlpriv->locks.conf_mutex);
47
48
        err = rtlpriv->intf_ops->adapter_start(hw);
48
 
        if (err)
49
 
                goto out;
50
 
        rtl_watch_dog_timer_callback((unsigned long)hw);
51
 
out:
 
49
        if (!err)
 
50
                rtl_watch_dog_timer_callback((unsigned long)hw);
52
51
        mutex_unlock(&rtlpriv->locks.conf_mutex);
53
52
        return err;
54
53
}
72
71
 
73
72
        mac->link_state = MAC80211_NOLINK;
74
73
        memset(mac->bssid, 0, 6);
 
74
        mac->vendor = PEER_UNKNOWN;
75
75
 
76
76
        /*reset sec info */
77
77
        rtl_cam_reset_sec_info(hw);
87
87
        struct rtl_priv *rtlpriv = rtl_priv(hw);
88
88
        struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
89
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));
90
92
 
91
93
        if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
92
94
                goto err_free;
94
96
        if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
95
97
                goto err_free;
96
98
 
97
 
 
98
 
        rtlpriv->intf_ops->adapter_tx(hw, skb);
 
99
        if (!rtlpriv->intf_ops->waitq_insert(hw, skb))
 
100
                rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
99
101
 
100
102
        return;
101
103
 
136
138
 
137
139
                mac->link_state = MAC80211_LINKED;
138
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
 
139
148
                break;
140
149
        case NL80211_IFTYPE_AP:
141
150
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
142
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));
143
161
                break;
144
162
        default:
145
163
                RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
186
204
        mac->vif = NULL;
187
205
        mac->link_state = MAC80211_NOLINK;
188
206
        memset(mac->bssid, 0, 6);
 
207
        mac->vendor = PEER_UNKNOWN;
189
208
        mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
190
209
        rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
191
 
 
192
210
        mutex_unlock(&rtlpriv->locks.conf_mutex);
193
211
}
194
212
 
195
 
 
196
213
static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
197
214
{
198
215
        struct rtl_priv *rtlpriv = rtl_priv(hw);
224
241
 
225
242
        /*For LPS */
226
243
        if (changed & IEEE80211_CONF_CHANGE_PS) {
227
 
                if (conf->flags & IEEE80211_CONF_PS)
228
 
                        rtl_lps_enter(hw);
229
 
                else
230
 
                        rtl_lps_leave(hw);
 
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
                }
231
263
        }
232
264
 
233
265
        if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
259
291
                case NL80211_CHAN_NO_HT:
260
292
                        /* SC */
261
293
                        mac->cur_40_prime_sc =
262
 
                            PRIME_CHNL_OFFSET_DONT_CARE;
 
294
                                PRIME_CHNL_OFFSET_DONT_CARE;
263
295
                        rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
264
296
                        mac->bw_40 = false;
265
297
                        break;
267
299
                        /* SC */
268
300
                        mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
269
301
                        rtlphy->current_chan_bw =
270
 
                            HT_CHANNEL_WIDTH_20_40;
 
302
                                HT_CHANNEL_WIDTH_20_40;
271
303
                        mac->bw_40 = true;
272
304
 
273
305
                        /*wide channel */
278
310
                        /* SC */
279
311
                        mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
280
312
                        rtlphy->current_chan_bw =
281
 
                            HT_CHANNEL_WIDTH_20_40;
 
313
                                HT_CHANNEL_WIDTH_20_40;
282
314
                        mac->bw_40 = true;
283
315
 
284
316
                        /*wide channel */
288
320
                default:
289
321
                        mac->bw_40 = false;
290
322
                        RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
291
 
                                 ("switch case not processed\n"));
 
323
                                        ("switch case not processed\n"));
292
324
                        break;
293
325
                }
294
326
 
295
327
                if (wide_chan <= 0)
296
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_deley) {
 
339
                        rtlpriv->mac80211.offchan_deley = false;
 
340
                        mdelay(50);
 
341
                }
297
342
                rtlphy->current_channel = wide_chan;
298
343
 
 
344
                rtlpriv->cfg->ops->switch_channel(hw);
299
345
                rtlpriv->cfg->ops->set_channel_access(hw);
300
 
                rtlpriv->cfg->ops->switch_channel(hw);
301
346
                rtlpriv->cfg->ops->set_bw_mode(hw,
302
347
                                               hw->conf.channel_type);
303
348
        }
345
390
                }
346
391
        }
347
392
 
348
 
        if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
349
 
                /*
350
 
                 *TODO: BIT(5) is probe response BIT(8) is beacon
351
 
                 *TODO: Use define for BIT(5) and BIT(8)
352
 
                 */
353
 
                if (*new_flags & FIF_BCN_PRBRESP_PROMISC)
354
 
                        mac->rx_mgt_filter |= (BIT(5) | BIT(8));
355
 
                else
356
 
                        mac->rx_mgt_filter &= ~(BIT(5) | BIT(8));
 
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
                }
357
405
        }
358
406
 
359
407
        if (changed_flags & FIF_CONTROL) {
360
408
                if (*new_flags & FIF_CONTROL) {
361
409
                        mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
362
 
                        mac->rx_ctrl_filter |= RTL_SUPPORTED_CTRL_FILTER;
363
410
 
364
411
                        RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
365
412
                                 ("Enable receive control frame.\n"));
366
413
                } else {
367
414
                        mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
368
 
                        mac->rx_ctrl_filter &= ~RTL_SUPPORTED_CTRL_FILTER;
369
415
                        RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
370
416
                                 ("Disable receive control frame.\n"));
371
417
                }
382
428
                                 ("Disable receive other BSS's frame.\n"));
383
429
                }
384
430
        }
385
 
 
386
 
        rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
387
 
        rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_MGT_FILTER,
388
 
                                      (u8 *) (&mac->rx_mgt_filter));
389
 
        rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CTRL_FILTER,
390
 
                                      (u8 *) (&mac->rx_ctrl_filter));
391
 
}
392
 
 
 
431
}
 
432
static 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 == true)
 
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 == true)
 
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 "MAC_FMT"\n", MAC_ARG(sta->addr)));
 
460
                rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
 
461
        }
 
462
        return 0;
 
463
}
 
464
static 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 "MAC_FMT"\n", MAC_ARG(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
}
393
479
static int _rtl_get_hal_qnum(u16 queue)
394
480
{
395
481
        int qnum;
446
532
                             struct ieee80211_bss_conf *bss_conf, u32 changed)
447
533
{
448
534
        struct rtl_priv *rtlpriv = rtl_priv(hw);
 
535
        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
449
536
        struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
450
537
        struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
 
538
        struct ieee80211_sta *sta = NULL;
451
539
 
452
540
        mutex_lock(&rtlpriv->locks.conf_mutex);
453
 
 
454
541
        if ((vif->type == NL80211_IFTYPE_ADHOC) ||
455
542
            (vif->type == NL80211_IFTYPE_AP) ||
456
543
            (vif->type == NL80211_IFTYPE_MESH_POINT)) {
457
 
 
458
544
                if ((changed & BSS_CHANGED_BEACON) ||
459
545
                    (changed & BSS_CHANGED_BEACON_ENABLED &&
460
546
                     bss_conf->enable_beacon)) {
461
 
 
462
547
                        if (mac->beacon_enabled == 0) {
463
548
                                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
464
549
                                         ("BSS_CHANGED_BEACON_ENABLED\n"));
470
555
                                                rtlpriv->cfg->maps
471
556
                                                [RTL_IBSS_INT_MASKS],
472
557
                                                0);
 
558
 
 
559
                                if (rtlpriv->cfg->ops->linked_set_reg)
 
560
                                        rtlpriv->cfg->ops->linked_set_reg(hw);
473
561
                        }
474
 
                } else {
 
562
                }
 
563
                if ((changed & BSS_CHANGED_BEACON_ENABLED &&
 
564
                        !bss_conf->enable_beacon)) {
475
565
                        if (mac->beacon_enabled == 1) {
476
566
                                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
477
567
                                         ("ADHOC DISABLE BEACON\n"));
482
572
                                                [RTL_IBSS_INT_MASKS]);
483
573
                        }
484
574
                }
485
 
 
486
575
                if (changed & BSS_CHANGED_BEACON_INT) {
487
576
                        RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
488
577
                                 ("BSS_CHANGED_BEACON_INT\n"));
494
583
        /*TODO: reference to enum ieee80211_bss_change */
495
584
        if (changed & BSS_CHANGED_ASSOC) {
496
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
 
497
596
                        mac->link_state = MAC80211_LINKED;
498
597
                        mac->cnt_after_linked = 0;
499
598
                        mac->assoc_id = bss_conf->aid;
500
599
                        memcpy(mac->bssid, bss_conf->bssid, 6);
501
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);
502
605
                        RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
503
606
                                 ("BSS_CHANGED_ASSOC\n"));
504
607
                } else {
507
610
 
508
611
                        mac->link_state = MAC80211_NOLINK;
509
612
                        memset(mac->bssid, 0, 6);
510
 
 
511
 
                        /* reset sec info */
512
 
                        rtl_cam_reset_sec_info(hw);
 
613
                        mac->vendor = PEER_UNKNOWN;
513
614
 
514
615
                        RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
515
616
                                 ("BSS_CHANGED_UN_ASSOC\n"));
546
647
        }
547
648
 
548
649
        if (changed & BSS_CHANGED_HT) {
549
 
                struct ieee80211_sta *sta = NULL;
550
 
 
551
650
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
552
651
                         ("BSS_CHANGED_HT\n"));
553
 
 
554
652
                rcu_read_lock();
555
 
                sta = ieee80211_find_sta(mac->vif, mac->bssid);
556
 
 
 
653
                sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
557
654
                if (sta) {
558
655
                        if (sta->ht_cap.ampdu_density >
559
656
                            mac->current_ampdu_density)
575
672
        }
576
673
 
577
674
        if (changed & BSS_CHANGED_BSSID) {
578
 
                struct ieee80211_sta *sta = NULL;
579
675
                u32 basic_rates;
580
 
                u8 i;
581
676
 
582
677
                rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
583
678
                                              (u8 *) bss_conf->bssid);
585
680
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
586
681
                         (MAC_FMT "\n", MAC_ARG(bss_conf->bssid)));
587
682
 
 
683
                mac->vendor = PEER_UNKNOWN;
588
684
                memcpy(mac->bssid, bss_conf->bssid, 6);
589
 
                if (is_valid_ether_addr(bss_conf->bssid)) {
590
 
                        switch (vif->type) {
591
 
                        case NL80211_IFTYPE_UNSPECIFIED:
592
 
                                break;
593
 
                        case NL80211_IFTYPE_ADHOC:
594
 
                                break;
595
 
                        case NL80211_IFTYPE_STATION:
596
 
                                break;
597
 
                        case NL80211_IFTYPE_AP:
598
 
                                break;
599
 
                        default:
600
 
                                RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
601
 
                                         ("switch case not process\n"));
602
 
                                break;
603
 
                        }
604
 
                        rtlpriv->cfg->ops->set_network_type(hw, vif->type);
605
 
                } else
606
 
                        rtlpriv->cfg->ops->set_network_type(hw,
607
 
                                        NL80211_IFTYPE_UNSPECIFIED);
608
 
 
609
 
                memset(mac->mcs, 0, 16);
610
 
                mac->ht_enable = false;
611
 
                mac->sgi_40 = false;
612
 
                mac->sgi_20 = false;
613
 
 
614
 
                if (!bss_conf->use_short_slot)
615
 
                        mac->mode = WIRELESS_MODE_B;
616
 
                else
617
 
                        mac->mode = WIRELESS_MODE_G;
 
685
                rtlpriv->cfg->ops->set_network_type(hw, vif->type);
618
686
 
619
687
                rcu_read_lock();
620
 
                sta = ieee80211_find_sta(mac->vif, mac->bssid);
621
 
 
622
 
                if (sta) {
623
 
                        if (sta->ht_cap.ht_supported) {
 
688
                sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
 
689
                if (!sta) {
 
690
                        rcu_read_unlock();
 
691
                        goto out;
 
692
                }
 
693
 
 
694
                if (rtlhal->current_bandtype == BAND_ON_5G) {
 
695
                        mac->mode = WIRELESS_MODE_A;
 
696
                } else {
 
697
                        if (sta->supp_rates[0] <= 0xf)
 
698
                                mac->mode = WIRELESS_MODE_B;
 
699
                        else
 
700
                                mac->mode = WIRELESS_MODE_G;
 
701
                }
 
702
 
 
703
                if (sta->ht_cap.ht_supported) {
 
704
                        if (rtlhal->current_bandtype == BAND_ON_2_4G)
624
705
                                mac->mode = WIRELESS_MODE_N_24G;
625
 
                                mac->ht_enable = true;
626
 
                        }
627
 
 
628
 
                        if (mac->ht_enable) {
629
 
                                u16 ht_cap = sta->ht_cap.cap;
630
 
                                memcpy(mac->mcs, (u8 *) (&sta->ht_cap.mcs), 16);
631
 
 
632
 
                                for (i = 0; i < 16; i++)
633
 
                                        RT_TRACE(rtlpriv, COMP_MAC80211,
634
 
                                                 DBG_LOUD, ("%x ",
635
 
                                                            mac->mcs[i]));
636
 
                                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
637
 
                                         ("\n"));
638
 
 
639
 
                                if (ht_cap & IEEE80211_HT_CAP_SGI_40)
640
 
                                        mac->sgi_40 = true;
641
 
 
642
 
                                if (ht_cap & IEEE80211_HT_CAP_SGI_20)
643
 
                                        mac->sgi_20 = true;
644
 
 
645
 
                                /*
646
 
                                 * for cisco 1252 bw20 it's wrong
647
 
                                 * if (ht_cap &
648
 
                                 *     IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
649
 
                                 *      mac->bw_40 = true;
650
 
                                 * }
651
 
                                 */
652
 
                        }
653
 
                }
654
 
                rcu_read_unlock();
655
 
 
656
 
                /*mac80211 just give us CCK rates any time
657
 
                 *So we add G rate in basic rates when
658
 
                 not in B mode*/
 
706
                        else
 
707
                                mac->mode = WIRELESS_MODE_N_5G;
 
708
                }
 
709
 
 
710
                /* just station need it, because ibss & ap mode will
 
711
                 * set in sta_add, and will be NULL here */
 
712
                if (mac->opmode == NL80211_IFTYPE_STATION) {
 
713
                        struct rtl_sta_info *sta_entry;
 
714
                        sta_entry = (struct rtl_sta_info *) sta->drv_priv;
 
715
                        sta_entry->wireless_mode = mac->mode;
 
716
                }
 
717
 
 
718
                if (sta->ht_cap.ht_supported) {
 
719
                        mac->ht_enable = true;
 
720
 
 
721
                        /*
 
722
                         * for cisco 1252 bw20 it's wrong
 
723
                         * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
 
724
                         *      mac->bw_40 = true;
 
725
                         * }
 
726
                         * */
 
727
                }
 
728
 
659
729
                if (changed & BSS_CHANGED_BASIC_RATES) {
660
 
                        if (mac->mode == WIRELESS_MODE_B)
661
 
                                basic_rates = bss_conf->basic_rates | 0x00f;
 
730
                        /* for 5G must << RATE_6M_INDEX=4,
 
731
                         * because 5G have no cck rate*/
 
732
                        if (rtlhal->current_bandtype == BAND_ON_5G)
 
733
                                basic_rates = sta->supp_rates[1] << 4;
662
734
                        else
663
 
                                basic_rates = bss_conf->basic_rates | 0xff0;
664
 
 
665
 
                        if (!vif)
666
 
                                goto out;
 
735
                                basic_rates = sta->supp_rates[0];
667
736
 
668
737
                        mac->basic_rates = basic_rates;
669
738
                        rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
670
739
                                        (u8 *) (&basic_rates));
671
 
 
672
 
                        if (rtlpriv->dm.useramask)
673
 
                                rtlpriv->cfg->ops->update_rate_mask(hw, 0);
674
 
                        else
675
 
                                rtlpriv->cfg->ops->update_rate_table(hw);
676
 
 
677
740
                }
 
741
                rcu_read_unlock();
678
742
        }
679
743
 
680
744
        /*
719
783
{
720
784
        struct rtl_priv *rtlpriv = rtl_priv(hw);
721
785
        struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
722
 
        u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;;
 
786
        u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
723
787
 
724
788
        mac->tsf = tsf;
725
789
        rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss));
760
824
        case IEEE80211_AMPDU_TX_START:
761
825
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
762
826
                         ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid));
763
 
                return rtl_tx_agg_start(hw, sta->addr, tid, ssn);
 
827
                return rtl_tx_agg_start(hw, sta, tid, ssn);
764
828
                break;
765
829
        case IEEE80211_AMPDU_TX_STOP:
766
830
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
767
831
                         ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid));
768
 
                return rtl_tx_agg_stop(hw, sta->addr, tid);
 
832
                return rtl_tx_agg_stop(hw, sta, tid);
769
833
                break;
770
834
        case IEEE80211_AMPDU_TX_OPERATIONAL:
771
835
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
772
836
                         ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid));
 
837
                rtl_tx_agg_oper(hw, sta, tid);
773
838
                break;
774
839
        case IEEE80211_AMPDU_RX_START:
775
840
                RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
799
864
        if (mac->link_state == MAC80211_LINKED) {
800
865
                rtl_lps_leave(hw);
801
866
                mac->link_state = MAC80211_LINKED_SCANNING;
802
 
        } else
 
867
        } else {
803
868
                rtl_ips_nic_on(hw);
 
869
        }
 
870
 
 
871
        /* Dual mac */
 
872
        rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
804
873
 
805
874
        rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
806
875
        rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
812
881
        struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
813
882
 
814
883
        RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
815
 
 
816
 
        rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
817
884
        mac->act_scanning = false;
 
885
        /* Dual mac */
 
886
        rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
 
887
 
818
888
        if (mac->link_state == MAC80211_LINKED_SCANNING) {
819
889
                mac->link_state = MAC80211_LINKED;
820
 
 
821
 
                /* fix fwlps issue */
822
 
                rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
823
 
 
824
 
                if (rtlpriv->dm.useramask)
825
 
                        rtlpriv->cfg->ops->update_rate_mask(hw, 0);
826
 
                else
827
 
                        rtlpriv->cfg->ops->update_rate_table(hw);
828
 
 
 
890
                if (mac->opmode == NL80211_IFTYPE_STATION) {
 
891
                        /* fix fwlps issue */
 
892
                        rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
 
893
                }
829
894
        }
830
895
 
 
896
        rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
831
897
}
832
898
 
833
899
static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
858
924
        rtl_ips_nic_on(hw);
859
925
        mutex_lock(&rtlpriv->locks.conf_mutex);
860
926
        /* <1> get encryption alg */
 
927
 
861
928
        switch (key->cipher) {
862
929
        case WLAN_CIPHER_SUITE_WEP40:
863
930
                key_type = WEP40_ENCRYPTION;
864
931
                RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n"));
865
 
                rtlpriv->sec.use_defaultkey = true;
866
932
                break;
867
933
        case WLAN_CIPHER_SUITE_WEP104:
868
934
                RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
869
935
                         ("alg:WEP104\n"));
870
936
                key_type = WEP104_ENCRYPTION;
871
 
                rtlpriv->sec.use_defaultkey = true;
872
937
                break;
873
938
        case WLAN_CIPHER_SUITE_TKIP:
874
939
                key_type = TKIP_ENCRYPTION;
875
940
                RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n"));
876
 
                if (mac->opmode == NL80211_IFTYPE_ADHOC)
877
 
                        rtlpriv->sec.use_defaultkey = true;
878
941
                break;
879
942
        case WLAN_CIPHER_SUITE_CCMP:
880
943
                key_type = AESCCMP_ENCRYPTION;
881
944
                RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n"));
882
 
                if (mac->opmode == NL80211_IFTYPE_ADHOC)
883
 
                        rtlpriv->sec.use_defaultkey = true;
884
945
                break;
885
946
        default:
886
947
                RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
887
948
                         ("alg_err:%x!!!!:\n", key->cipher));
888
949
                goto out_unlock;
889
950
        }
 
951
        if (key_type == WEP40_ENCRYPTION ||
 
952
                        key_type == WEP104_ENCRYPTION ||
 
953
                        mac->opmode == NL80211_IFTYPE_ADHOC)
 
954
                rtlpriv->sec.use_defaultkey = true;
 
955
 
890
956
        /* <2> get key_idx */
891
957
        key_idx = (u8) (key->keyidx);
892
958
        if (key_idx > 3)
893
959
                goto out_unlock;
894
960
        /* <3> if pairwise key enable_hw_sec */
895
961
        group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
896
 
        if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
897
 
            rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
898
 
                if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION &&
899
 
                    (key_type == WEP40_ENCRYPTION ||
900
 
                     key_type == WEP104_ENCRYPTION))
901
 
                        wep_only = true;
902
 
                rtlpriv->sec.pairwise_enc_algorithm = key_type;
903
 
                rtlpriv->cfg->ops->enable_hw_sec(hw);
 
962
 
 
963
        /* wep always be group key, but there are two conditions:
 
964
         * 1) wep only: is just for wep enc, in this condition
 
965
         * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
 
966
         * will be true & enable_hw_sec will be set when wep
 
967
         * ke setting.
 
968
         * 2) wep(group) + AES(pairwise): some AP like cisco
 
969
         * may use it, in this condition enable_hw_sec will not
 
970
         * be set when wep key setting */
 
971
        /* we must reset sec_info after lingked before set key,
 
972
         * or some flag will be wrong*/
 
973
        if (mac->opmode == NL80211_IFTYPE_AP) {
 
974
                if (!group_key || key_type == WEP40_ENCRYPTION ||
 
975
                        key_type == WEP104_ENCRYPTION) {
 
976
                        if (group_key)
 
977
                                wep_only = true;
 
978
                        rtlpriv->cfg->ops->enable_hw_sec(hw);
 
979
                }
 
980
        } else {
 
981
                if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
 
982
                     rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
 
983
                        if (rtlpriv->sec.pairwise_enc_algorithm ==
 
984
                            NO_ENCRYPTION &&
 
985
                            (key_type == WEP40_ENCRYPTION ||
 
986
                            key_type == WEP104_ENCRYPTION))
 
987
                                wep_only = true;
 
988
                        rtlpriv->sec.pairwise_enc_algorithm = key_type;
 
989
                        RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
 
990
                                ("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1"
 
991
                                " TKIP:2 AES:4 WEP104:5)\n", key_type));
 
992
                        rtlpriv->cfg->ops->enable_hw_sec(hw);
 
993
                }
904
994
        }
905
995
        /* <4> set key based on cmd */
906
996
        switch (cmd) {
932
1022
                        if (!sta) {
933
1023
                                RT_ASSERT(false, ("pairwise key withnot"
934
1024
                                                  "mac_addr\n"));
 
1025
 
935
1026
                                err = -EOPNOTSUPP;
936
1027
                                goto out_unlock;
937
1028
                        }
959
1050
                RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
960
1051
                         ("disable key delete one entry\n"));
961
1052
                /*set local buf about wep key. */
 
1053
                if (mac->opmode == NL80211_IFTYPE_AP) {
 
1054
                        if (sta)
 
1055
                                rtl_cam_del_entry(hw, sta->addr);
 
1056
                }
962
1057
                memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
963
1058
                rtlpriv->sec.key_len[key_idx] = 0;
964
1059
                memcpy(mac_addr, zero_addr, ETH_ALEN);
1011
1106
        mutex_unlock(&rtlpriv->locks.conf_mutex);
1012
1107
}
1013
1108
 
 
1109
/* this function is called by mac80211 to flush tx buffer
 
1110
 * before switch channle or power save, or tx buffer packet
 
1111
 * maybe send after offchannel or rf sleep, this may cause
 
1112
 * dis-association by AP */
 
1113
static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
 
1114
{
 
1115
        struct rtl_priv *rtlpriv = rtl_priv(hw);
 
1116
 
 
1117
        if (rtlpriv->intf_ops->flush)
 
1118
                rtlpriv->intf_ops->flush(hw, drop);
 
1119
}
 
1120
 
1014
1121
const struct ieee80211_ops rtl_ops = {
1015
1122
        .start = rtl_op_start,
1016
1123
        .stop = rtl_op_stop,
1019
1126
        .remove_interface = rtl_op_remove_interface,
1020
1127
        .config = rtl_op_config,
1021
1128
        .configure_filter = rtl_op_configure_filter,
 
1129
        .sta_add = rtl_op_sta_add,
 
1130
        .sta_remove = rtl_op_sta_remove,
1022
1131
        .set_key = rtl_op_set_key,
1023
1132
        .conf_tx = rtl_op_conf_tx,
1024
1133
        .bss_info_changed = rtl_op_bss_info_changed,
1030
1139
        .sw_scan_start = rtl_op_sw_scan_start,
1031
1140
        .sw_scan_complete = rtl_op_sw_scan_complete,
1032
1141
        .rfkill_poll = rtl_op_rfkill_poll,
 
1142
        .flush = rtl_op_flush,
1033
1143
};