00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <linux/kernel.h>
00016 #include <linux/slab.h>
00017 #include <linux/skbuff.h>
00018 #include <linux/etherdevice.h>
00019 #include <linux/bitmap.h>
00020 #include <linux/rcupdate.h>
00021 #include <linux/export.h>
00022 #include <net/net_namespace.h>
00023 #include <net/ieee80211_radiotap.h>
00024 #include <net/cfg80211.h>
00025 #include <net/mac80211.h>
00026 #include <asm/unaligned.h>
00027
00028 #include "ieee80211_i.h"
00029 #include "driver-ops.h"
00030 #include "led.h"
00031 #include "mesh.h"
00032 #include "wep.h"
00033 #include "wpa.h"
00034 #include "wme.h"
00035 #include "rate.h"
00036
00037
00038
00039 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
00040 int next_frag_len)
00041 {
00042 int rate, mrate, erp, dur, i;
00043 struct ieee80211_rate *txrate;
00044 struct ieee80211_local *local = tx->local;
00045 struct ieee80211_supported_band *sband;
00046 struct ieee80211_hdr *hdr;
00047 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00048
00049
00050 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
00051 return 0;
00052
00053
00054 if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
00055 return 0;
00056
00057 sband = local->hw.wiphy->bands[tx->channel->band];
00058 txrate = &sband->bitrates[info->control.rates[0].idx];
00059
00060 erp = txrate->flags & IEEE80211_RATE_ERP_G;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 hdr = (struct ieee80211_hdr *)tx->skb->data;
00080 if (ieee80211_is_ctl(hdr->frame_control)) {
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 return 0;
00096 }
00097
00098
00099 if (0 )
00100 return cpu_to_le16(32768);
00101
00102 if (group_addr)
00103 return 0;
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 rate = -1;
00116
00117 mrate = sband->bitrates[0].bitrate;
00118 for (i = 0; i < sband->n_bitrates; i++) {
00119 struct ieee80211_rate *r = &sband->bitrates[i];
00120
00121 if (r->bitrate > txrate->bitrate)
00122 break;
00123
00124 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
00125 rate = r->bitrate;
00126
00127 switch (sband->band) {
00128 case IEEE80211_BAND_2GHZ: {
00129 u32 flag;
00130 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
00131 flag = IEEE80211_RATE_MANDATORY_G;
00132 else
00133 flag = IEEE80211_RATE_MANDATORY_B;
00134 if (r->flags & flag)
00135 mrate = r->bitrate;
00136 break;
00137 }
00138 case IEEE80211_BAND_5GHZ:
00139 if (r->flags & IEEE80211_RATE_MANDATORY_A)
00140 mrate = r->bitrate;
00141 break;
00142 case IEEE80211_NUM_BANDS:
00143 WARN_ON(1);
00144 break;
00145 }
00146 }
00147 if (rate == -1) {
00148
00149
00150 rate = mrate;
00151 }
00152
00153
00154
00155
00156
00157 dur = ieee80211_frame_duration(local, 10, rate, erp,
00158 tx->sdata->vif.bss_conf.use_short_preamble);
00159
00160 if (next_frag_len) {
00161
00162
00163 dur *= 2;
00164
00165 dur += ieee80211_frame_duration(local, next_frag_len,
00166 txrate->bitrate, erp,
00167 tx->sdata->vif.bss_conf.use_short_preamble);
00168 }
00169
00170 return cpu_to_le16(dur);
00171 }
00172
00173 static inline int is_ieee80211_device(struct ieee80211_local *local,
00174 struct net_device *dev)
00175 {
00176 return local == wdev_priv(dev->ieee80211_ptr);
00177 }
00178
00179
00180 static ieee80211_tx_result debug_noinline
00181 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
00182 {
00183 struct ieee80211_local *local = tx->local;
00184 struct ieee80211_if_managed *ifmgd;
00185
00186
00187 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
00188 return TX_CONTINUE;
00189
00190
00191 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
00192 return TX_CONTINUE;
00193
00194
00195 if (local->hw.conf.dynamic_ps_timeout <= 0)
00196 return TX_CONTINUE;
00197
00198
00199 if (local->scanning)
00200 return TX_CONTINUE;
00201
00202 if (!local->ps_sdata)
00203 return TX_CONTINUE;
00204
00205
00206 if (local->quiescing)
00207 return TX_CONTINUE;
00208
00209
00210 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
00211 return TX_CONTINUE;
00212
00213 ifmgd = &tx->sdata->u.mgd;
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
00229 && (local->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
00230 && skb_get_queue_mapping(tx->skb) == 0)
00231 return TX_CONTINUE;
00232
00233 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
00234 ieee80211_stop_queues_by_reason(&local->hw,
00235 IEEE80211_QUEUE_STOP_REASON_PS);
00236 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
00237 ieee80211_queue_work(&local->hw,
00238 &local->dynamic_ps_disable_work);
00239 }
00240
00241
00242 if (!ifmgd->associated)
00243 return TX_CONTINUE;
00244
00245 mod_timer(&local->dynamic_ps_timer, jiffies +
00246 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
00247
00248 return TX_CONTINUE;
00249 }
00250
00251 static ieee80211_tx_result debug_noinline
00252 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
00253 {
00254
00255 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00256 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00257 bool assoc = false;
00258
00259 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
00260 return TX_CONTINUE;
00261
00262 if (unlikely(test_bit(SCAN_OFF_CHANNEL, &tx->local->scanning)) &&
00263 !ieee80211_is_probe_req(hdr->frame_control) &&
00264 !ieee80211_is_nullfunc(hdr->frame_control))
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 return TX_DROP;
00277
00278 if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
00279 return TX_CONTINUE;
00280
00281 if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
00282 return TX_CONTINUE;
00283
00284 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
00285 return TX_CONTINUE;
00286
00287 if (tx->sta)
00288 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
00289
00290 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
00291 if (unlikely(!assoc &&
00292 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
00293 ieee80211_is_data(hdr->frame_control))) {
00294 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00295 printk(KERN_DEBUG "%s: dropped data frame to not "
00296 "associated station %pM\n",
00297 tx->sdata->name, hdr->addr1);
00298 #endif
00299 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
00300 return TX_DROP;
00301 }
00302 } else {
00303 if (unlikely(ieee80211_is_data(hdr->frame_control) &&
00304 tx->local->num_sta == 0 &&
00305 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
00306
00307
00308
00309
00310 return TX_DROP;
00311 }
00312 return TX_CONTINUE;
00313 }
00314
00315 return TX_CONTINUE;
00316 }
00317
00318
00319
00320
00321
00322 static void purge_old_ps_buffers(struct ieee80211_local *local)
00323 {
00324 int total = 0, purged = 0;
00325 struct sk_buff *skb;
00326 struct ieee80211_sub_if_data *sdata;
00327 struct sta_info *sta;
00328
00329
00330
00331
00332 rcu_read_lock();
00333
00334 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
00335 struct ieee80211_if_ap *ap;
00336 if (sdata->vif.type != NL80211_IFTYPE_AP)
00337 continue;
00338 ap = &sdata->u.ap;
00339 skb = skb_dequeue(&ap->ps_bc_buf);
00340 if (skb) {
00341 purged++;
00342 dev_kfree_skb(skb);
00343 }
00344 total += skb_queue_len(&ap->ps_bc_buf);
00345 }
00346
00347
00348
00349
00350
00351 list_for_each_entry_rcu(sta, &local->sta_list, list) {
00352 int ac;
00353
00354 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
00355 skb = skb_dequeue(&sta->ps_tx_buf[ac]);
00356 total += skb_queue_len(&sta->ps_tx_buf[ac]);
00357 if (skb) {
00358 purged++;
00359 dev_kfree_skb(skb);
00360 break;
00361 }
00362 }
00363 }
00364
00365 rcu_read_unlock();
00366
00367 local->total_ps_buffered = total;
00368 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00369 wiphy_debug(local->hw.wiphy, "PS buffers full - purged %d frames\n",
00370 purged);
00371 #endif
00372 }
00373
00374 static ieee80211_tx_result
00375 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
00376 {
00377 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00378 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 if (!tx->sdata->bss)
00390 return TX_CONTINUE;
00391
00392
00393 if (ieee80211_has_order(hdr->frame_control))
00394 return TX_CONTINUE;
00395
00396
00397 if (!atomic_read(&tx->sdata->bss->num_sta_ps))
00398 return TX_CONTINUE;
00399
00400 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
00401
00402
00403 if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING))
00404 return TX_CONTINUE;
00405
00406
00407 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
00408 purge_old_ps_buffers(tx->local);
00409
00410 if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= AP_MAX_BC_BUFFER) {
00411 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00412 if (net_ratelimit())
00413 printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n",
00414 tx->sdata->name);
00415 #endif
00416 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
00417 } else
00418 tx->local->total_ps_buffered++;
00419
00420 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
00421
00422 return TX_QUEUED;
00423 }
00424
00425 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
00426 struct sk_buff *skb)
00427 {
00428 if (!ieee80211_is_mgmt(fc))
00429 return 0;
00430
00431 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
00432 return 0;
00433
00434 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
00435 skb->data))
00436 return 0;
00437
00438 return 1;
00439 }
00440
00441 static ieee80211_tx_result
00442 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
00443 {
00444 struct sta_info *sta = tx->sta;
00445 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00446 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00447 struct ieee80211_local *local = tx->local;
00448
00449 if (unlikely(!sta ||
00450 ieee80211_is_probe_resp(hdr->frame_control) ||
00451 ieee80211_is_auth(hdr->frame_control) ||
00452 ieee80211_is_assoc_resp(hdr->frame_control) ||
00453 ieee80211_is_reassoc_resp(hdr->frame_control)))
00454 return TX_CONTINUE;
00455
00456 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
00457 test_sta_flag(sta, WLAN_STA_PS_DRIVER)) &&
00458 !(info->flags & IEEE80211_TX_CTL_POLL_RESPONSE))) {
00459 int ac = skb_get_queue_mapping(tx->skb);
00460
00461 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00462 printk(KERN_DEBUG "STA %pM aid %d: PS buffer for AC %d\n",
00463 sta->sta.addr, sta->sta.aid, ac);
00464 #endif
00465 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
00466 purge_old_ps_buffers(tx->local);
00467 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
00468 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
00469 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00470 if (net_ratelimit())
00471 printk(KERN_DEBUG "%s: STA %pM TX buffer for "
00472 "AC %d full - dropping oldest frame\n",
00473 tx->sdata->name, sta->sta.addr, ac);
00474 #endif
00475 dev_kfree_skb(old);
00476 } else
00477 tx->local->total_ps_buffered++;
00478
00479 info->control.jiffies = jiffies;
00480 info->control.vif = &tx->sdata->vif;
00481 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
00482 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
00483
00484 if (!timer_pending(&local->sta_cleanup))
00485 mod_timer(&local->sta_cleanup,
00486 round_jiffies(jiffies +
00487 STA_INFO_CLEANUP_INTERVAL));
00488
00489
00490
00491
00492
00493 sta_info_recalc_tim(sta);
00494
00495 return TX_QUEUED;
00496 }
00497 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00498 else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
00499 printk(KERN_DEBUG
00500 "%s: STA %pM in PS mode, but polling/in SP -> send frame\n",
00501 tx->sdata->name, sta->sta.addr);
00502 }
00503 #endif
00504
00505 return TX_CONTINUE;
00506 }
00507
00508 static ieee80211_tx_result debug_noinline
00509 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
00510 {
00511 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
00512 return TX_CONTINUE;
00513
00514 if (tx->flags & IEEE80211_TX_UNICAST)
00515 return ieee80211_tx_h_unicast_ps_buf(tx);
00516 else
00517 return ieee80211_tx_h_multicast_ps_buf(tx);
00518 }
00519
00520 static ieee80211_tx_result debug_noinline
00521 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
00522 {
00523 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00524
00525 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol &&
00526 tx->sdata->control_port_no_encrypt))
00527 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00528
00529 return TX_CONTINUE;
00530 }
00531
00532 static ieee80211_tx_result debug_noinline
00533 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
00534 {
00535 struct ieee80211_key *key = NULL;
00536 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00537 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00538
00539 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
00540 tx->key = NULL;
00541 else if (tx->sta && (key = rcu_dereference(tx->sta->ptk)))
00542 tx->key = key;
00543 else if (ieee80211_is_mgmt(hdr->frame_control) &&
00544 is_multicast_ether_addr(hdr->addr1) &&
00545 ieee80211_is_robust_mgmt_frame(hdr) &&
00546 (key = rcu_dereference(tx->sdata->default_mgmt_key)))
00547 tx->key = key;
00548 else if (is_multicast_ether_addr(hdr->addr1) &&
00549 (key = rcu_dereference(tx->sdata->default_multicast_key)))
00550 tx->key = key;
00551 else if (!is_multicast_ether_addr(hdr->addr1) &&
00552 (key = rcu_dereference(tx->sdata->default_unicast_key)))
00553 tx->key = key;
00554 else if (tx->sdata->drop_unencrypted &&
00555 (tx->skb->protocol != tx->sdata->control_port_protocol) &&
00556 !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
00557 (!ieee80211_is_robust_mgmt_frame(hdr) ||
00558 (ieee80211_is_action(hdr->frame_control) &&
00559 tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))) {
00560 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
00561 return TX_DROP;
00562 } else
00563 tx->key = NULL;
00564
00565 if (tx->key) {
00566 bool skip_hw = false;
00567
00568 tx->key->tx_rx_count++;
00569
00570
00571 switch (tx->key->conf.cipher) {
00572 case WLAN_CIPHER_SUITE_WEP40:
00573 case WLAN_CIPHER_SUITE_WEP104:
00574 if (ieee80211_is_auth(hdr->frame_control))
00575 break;
00576 case WLAN_CIPHER_SUITE_TKIP:
00577 if (!ieee80211_is_data_present(hdr->frame_control))
00578 tx->key = NULL;
00579 break;
00580 case WLAN_CIPHER_SUITE_CCMP:
00581 if (!ieee80211_is_data_present(hdr->frame_control) &&
00582 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
00583 tx->skb))
00584 tx->key = NULL;
00585 else
00586 skip_hw = (tx->key->conf.flags &
00587 IEEE80211_KEY_FLAG_SW_MGMT) &&
00588 ieee80211_is_mgmt(hdr->frame_control);
00589 break;
00590 case WLAN_CIPHER_SUITE_AES_CMAC:
00591 if (!ieee80211_is_mgmt(hdr->frame_control))
00592 tx->key = NULL;
00593 break;
00594 }
00595
00596 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED))
00597 return TX_DROP;
00598
00599 if (!skip_hw && tx->key &&
00600 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
00601 info->control.hw_key = &tx->key->conf;
00602 }
00603
00604 return TX_CONTINUE;
00605 }
00606
00607 static ieee80211_tx_result debug_noinline
00608 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
00609 {
00610 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00611 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
00612 struct ieee80211_supported_band *sband;
00613 struct ieee80211_rate *rate;
00614 int i;
00615 u32 len;
00616 bool inval = false, rts = false, short_preamble = false;
00617 struct ieee80211_tx_rate_control txrc;
00618 bool assoc = false;
00619
00620 memset(&txrc, 0, sizeof(txrc));
00621
00622 sband = tx->local->hw.wiphy->bands[tx->channel->band];
00623
00624 len = min_t(u32, tx->skb->len + FCS_LEN,
00625 tx->local->hw.wiphy->frag_threshold);
00626
00627
00628 txrc.hw = local_to_hw(tx->local);
00629 txrc.sband = sband;
00630 txrc.bss_conf = &tx->sdata->vif.bss_conf;
00631 txrc.skb = tx->skb;
00632 txrc.reported_rate.idx = -1;
00633 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[tx->channel->band];
00634 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
00635 txrc.max_rate_idx = -1;
00636 else
00637 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
00638 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
00639 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
00640
00641
00642 if (len > tx->local->hw.wiphy->rts_threshold) {
00643 txrc.rts = rts = true;
00644 }
00645
00646
00647
00648
00649
00650
00651
00652 if (tx->sdata->vif.bss_conf.use_short_preamble &&
00653 (ieee80211_is_data(hdr->frame_control) ||
00654 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
00655 txrc.short_preamble = short_preamble = true;
00656
00657 if (tx->sta)
00658 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
00659
00660
00661
00662
00663
00664 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
00665 !rate_usable_index_exists(sband, &tx->sta->sta),
00666 "%s: Dropped data frame as no usable bitrate found while "
00667 "scanning and associated. Target station: "
00668 "%pM on %d GHz band\n",
00669 tx->sdata->name, hdr->addr1,
00670 tx->channel->band ? 5 : 2))
00671 return TX_DROP;
00672
00673
00674
00675
00676
00677 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
00678
00679 if (unlikely(info->control.rates[0].idx < 0))
00680 return TX_DROP;
00681
00682 if (txrc.reported_rate.idx < 0) {
00683 txrc.reported_rate = info->control.rates[0];
00684 if (tx->sta && ieee80211_is_data(hdr->frame_control))
00685 tx->sta->last_tx_rate = txrc.reported_rate;
00686 } else if (tx->sta)
00687 tx->sta->last_tx_rate = txrc.reported_rate;
00688
00689 if (unlikely(!info->control.rates[0].count))
00690 info->control.rates[0].count = 1;
00691
00692 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
00693 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
00694 info->control.rates[0].count = 1;
00695
00696 if (is_multicast_ether_addr(hdr->addr1)) {
00697
00698
00699
00700 return TX_CONTINUE;
00701 }
00702
00703
00704
00705
00706
00707
00708
00709 if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
00710 s8 baserate = 0;
00711
00712 rate = &sband->bitrates[info->control.rates[0].idx];
00713
00714 for (i = 0; i < sband->n_bitrates; i++) {
00715
00716 if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
00717 continue;
00718
00719 if (sband->bitrates[i].bitrate > rate->bitrate)
00720 continue;
00721
00722 if (sband->bitrates[baserate].bitrate <
00723 sband->bitrates[i].bitrate)
00724 baserate = i;
00725 }
00726
00727 info->control.rts_cts_rate_idx = baserate;
00728 }
00729
00730 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
00731
00732
00733
00734
00735
00736 if (inval) {
00737 info->control.rates[i].idx = -1;
00738 continue;
00739 }
00740 if (info->control.rates[i].idx < 0) {
00741 inval = true;
00742 continue;
00743 }
00744
00745
00746
00747
00748
00749 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
00750 WARN_ON(info->control.rates[i].idx > 76);
00751 continue;
00752 }
00753
00754
00755 if (rts)
00756 info->control.rates[i].flags |=
00757 IEEE80211_TX_RC_USE_RTS_CTS;
00758
00759
00760 if (WARN_ON_ONCE(info->control.rates[i].idx >=
00761 sband->n_bitrates)) {
00762 info->control.rates[i].idx = -1;
00763 continue;
00764 }
00765
00766 rate = &sband->bitrates[info->control.rates[i].idx];
00767
00768
00769 if (short_preamble &&
00770 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
00771 info->control.rates[i].flags |=
00772 IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
00773
00774
00775 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
00776 rate->flags & IEEE80211_RATE_ERP_G)
00777 info->control.rates[i].flags |=
00778 IEEE80211_TX_RC_USE_CTS_PROTECT;
00779 }
00780
00781 return TX_CONTINUE;
00782 }
00783
00784 static ieee80211_tx_result debug_noinline
00785 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
00786 {
00787 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00788 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00789 u16 *seq;
00790 u8 *qc;
00791 int tid;
00792
00793
00794
00795
00796
00797
00798 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
00799 return TX_CONTINUE;
00800
00801 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
00802 return TX_CONTINUE;
00803
00804 if (ieee80211_hdrlen(hdr->frame_control) < 24)
00805 return TX_CONTINUE;
00806
00807 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
00808 return TX_CONTINUE;
00809
00810
00811
00812
00813
00814
00815 if (!ieee80211_is_data_qos(hdr->frame_control)) {
00816
00817 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
00818
00819 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
00820 tx->sdata->sequence_number += 0x10;
00821 return TX_CONTINUE;
00822 }
00823
00824
00825
00826
00827
00828
00829 if (!tx->sta)
00830 return TX_CONTINUE;
00831
00832
00833
00834 qc = ieee80211_get_qos_ctl(hdr);
00835 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
00836 seq = &tx->sta->tid_seq[tid];
00837
00838 hdr->seq_ctrl = cpu_to_le16(*seq);
00839
00840
00841 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
00842
00843 return TX_CONTINUE;
00844 }
00845
00846 static int ieee80211_fragment(struct ieee80211_local *local,
00847 struct sk_buff *skb, int hdrlen,
00848 int frag_threshold)
00849 {
00850 struct sk_buff *tail = skb, *tmp;
00851 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
00852 int pos = hdrlen + per_fragm;
00853 int rem = skb->len - hdrlen - per_fragm;
00854
00855 if (WARN_ON(rem < 0))
00856 return -EINVAL;
00857
00858 while (rem) {
00859 int fraglen = per_fragm;
00860
00861 if (fraglen > rem)
00862 fraglen = rem;
00863 rem -= fraglen;
00864 tmp = dev_alloc_skb(local->tx_headroom +
00865 frag_threshold +
00866 IEEE80211_ENCRYPT_HEADROOM +
00867 IEEE80211_ENCRYPT_TAILROOM);
00868 if (!tmp)
00869 return -ENOMEM;
00870 tail->next = tmp;
00871 tail = tmp;
00872 skb_reserve(tmp, local->tx_headroom +
00873 IEEE80211_ENCRYPT_HEADROOM);
00874
00875 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
00876 skb_copy_queue_mapping(tmp, skb);
00877 tmp->priority = skb->priority;
00878 tmp->dev = skb->dev;
00879
00880
00881 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
00882 memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
00883
00884 pos += fraglen;
00885 }
00886
00887 skb->len = hdrlen + per_fragm;
00888 return 0;
00889 }
00890
00891 static ieee80211_tx_result debug_noinline
00892 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
00893 {
00894 struct sk_buff *skb = tx->skb;
00895 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
00896 struct ieee80211_hdr *hdr = (void *)skb->data;
00897 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
00898 int hdrlen;
00899 int fragnum;
00900
00901 if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
00902 return TX_CONTINUE;
00903
00904 if (tx->local->ops->set_frag_threshold)
00905 return TX_CONTINUE;
00906
00907
00908
00909
00910
00911
00912 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
00913 return TX_DROP;
00914
00915 hdrlen = ieee80211_hdrlen(hdr->frame_control);
00916
00917
00918 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
00919 return TX_DROP;
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929 if (ieee80211_fragment(tx->local, skb, hdrlen, frag_threshold))
00930 return TX_DROP;
00931
00932
00933 fragnum = 0;
00934 do {
00935 int next_len;
00936 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
00937
00938 hdr = (void *)skb->data;
00939 info = IEEE80211_SKB_CB(skb);
00940
00941 if (skb->next) {
00942 hdr->frame_control |= morefrags;
00943 next_len = skb->next->len;
00944
00945
00946
00947
00948 info->control.rates[1].idx = -1;
00949 info->control.rates[2].idx = -1;
00950 info->control.rates[3].idx = -1;
00951 info->control.rates[4].idx = -1;
00952 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
00953 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
00954 } else {
00955 hdr->frame_control &= ~morefrags;
00956 next_len = 0;
00957 }
00958 hdr->duration_id = ieee80211_duration(tx, 0, next_len);
00959 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
00960 fragnum++;
00961 } while ((skb = skb->next));
00962
00963 return TX_CONTINUE;
00964 }
00965
00966 static ieee80211_tx_result debug_noinline
00967 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
00968 {
00969 struct sk_buff *skb = tx->skb;
00970
00971 if (!tx->sta)
00972 return TX_CONTINUE;
00973
00974 tx->sta->tx_packets++;
00975 do {
00976 tx->sta->tx_fragments++;
00977 tx->sta->tx_bytes += skb->len;
00978 } while ((skb = skb->next));
00979
00980 return TX_CONTINUE;
00981 }
00982
00983 static ieee80211_tx_result debug_noinline
00984 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
00985 {
00986 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00987
00988 if (!tx->key)
00989 return TX_CONTINUE;
00990
00991 switch (tx->key->conf.cipher) {
00992 case WLAN_CIPHER_SUITE_WEP40:
00993 case WLAN_CIPHER_SUITE_WEP104:
00994 return ieee80211_crypto_wep_encrypt(tx);
00995 case WLAN_CIPHER_SUITE_TKIP:
00996 return ieee80211_crypto_tkip_encrypt(tx);
00997 case WLAN_CIPHER_SUITE_CCMP:
00998 return ieee80211_crypto_ccmp_encrypt(tx);
00999 case WLAN_CIPHER_SUITE_AES_CMAC:
01000 return ieee80211_crypto_aes_cmac_encrypt(tx);
01001 default:
01002
01003 if (info->control.hw_key) {
01004 ieee80211_tx_set_protected(tx);
01005 return TX_CONTINUE;
01006 }
01007 break;
01008
01009 }
01010
01011 return TX_DROP;
01012 }
01013
01014 static ieee80211_tx_result debug_noinline
01015 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
01016 {
01017 struct sk_buff *skb = tx->skb;
01018 struct ieee80211_hdr *hdr;
01019 int next_len;
01020 bool group_addr;
01021
01022 do {
01023 hdr = (void *) skb->data;
01024 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
01025 break;
01026 next_len = skb->next ? skb->next->len : 0;
01027 group_addr = is_multicast_ether_addr(hdr->addr1);
01028
01029 hdr->duration_id =
01030 ieee80211_duration(tx, group_addr, next_len);
01031 } while ((skb = skb->next));
01032
01033 return TX_CONTINUE;
01034 }
01035
01036
01037
01038 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
01039 struct sk_buff *skb,
01040 struct ieee80211_tx_info *info,
01041 struct tid_ampdu_tx *tid_tx,
01042 int tid)
01043 {
01044 bool queued = false;
01045
01046 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
01047 info->flags |= IEEE80211_TX_CTL_AMPDU;
01048 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
01049
01050
01051
01052
01053 } else {
01054 spin_lock(&tx->sta->lock);
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
01074
01075 if (!tid_tx) {
01076
01077 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
01078 info->flags |= IEEE80211_TX_CTL_AMPDU;
01079 } else {
01080 queued = true;
01081 info->control.vif = &tx->sdata->vif;
01082 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
01083 __skb_queue_tail(&tid_tx->pending, skb);
01084 }
01085 spin_unlock(&tx->sta->lock);
01086 }
01087
01088 return queued;
01089 }
01090
01091
01092
01093
01094 static ieee80211_tx_result
01095 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
01096 struct ieee80211_tx_data *tx,
01097 struct sk_buff *skb)
01098 {
01099 struct ieee80211_local *local = sdata->local;
01100 struct ieee80211_hdr *hdr;
01101 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01102 int tid;
01103 u8 *qc;
01104
01105 memset(tx, 0, sizeof(*tx));
01106 tx->skb = skb;
01107 tx->local = local;
01108 tx->sdata = sdata;
01109 tx->channel = local->hw.conf.channel;
01110
01111
01112
01113
01114
01115
01116 info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
01117
01118 hdr = (struct ieee80211_hdr *) skb->data;
01119
01120 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
01121 tx->sta = rcu_dereference(sdata->u.vlan.sta);
01122 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
01123 return TX_DROP;
01124 } else if (info->flags & IEEE80211_TX_CTL_INJECTED ||
01125 tx->sdata->control_port_protocol == tx->skb->protocol) {
01126 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
01127 }
01128 if (!tx->sta)
01129 tx->sta = sta_info_get(sdata, hdr->addr1);
01130
01131 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
01132 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
01133 (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) &&
01134 !(local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)) {
01135 struct tid_ampdu_tx *tid_tx;
01136
01137 qc = ieee80211_get_qos_ctl(hdr);
01138 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
01139
01140 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
01141 if (tid_tx) {
01142 bool queued;
01143
01144 queued = ieee80211_tx_prep_agg(tx, skb, info,
01145 tid_tx, tid);
01146
01147 if (unlikely(queued))
01148 return TX_QUEUED;
01149 }
01150 }
01151
01152 if (is_multicast_ether_addr(hdr->addr1)) {
01153 tx->flags &= ~IEEE80211_TX_UNICAST;
01154 info->flags |= IEEE80211_TX_CTL_NO_ACK;
01155 } else {
01156 tx->flags |= IEEE80211_TX_UNICAST;
01157 if (unlikely(local->wifi_wme_noack_test))
01158 info->flags |= IEEE80211_TX_CTL_NO_ACK;
01159
01160
01161
01162
01163
01164 }
01165
01166 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
01167 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
01168 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
01169 info->flags & IEEE80211_TX_CTL_AMPDU)
01170 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
01171 }
01172
01173 if (!tx->sta)
01174 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
01175 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT))
01176 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
01177
01178 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
01179
01180 return TX_CONTINUE;
01181 }
01182
01183
01184
01185
01186 static bool __ieee80211_tx(struct ieee80211_local *local, struct sk_buff **skbp,
01187 struct sta_info *sta, bool txpending)
01188 {
01189 struct sk_buff *skb = *skbp, *next;
01190 struct ieee80211_tx_info *info;
01191 struct ieee80211_sub_if_data *sdata;
01192 unsigned long flags;
01193 int len;
01194 bool fragm = false;
01195
01196 while (skb) {
01197 int q = skb_get_queue_mapping(skb);
01198 __le16 fc;
01199
01200 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
01201 if (local->queue_stop_reasons[q] ||
01202 (!txpending && !skb_queue_empty(&local->pending[q]))) {
01203
01204
01205
01206
01207
01208
01209 do {
01210 next = skb->next;
01211 skb->next = NULL;
01212
01213
01214
01215
01216
01217
01218
01219 if (unlikely(txpending))
01220 __skb_queue_head(&local->pending[q],
01221 skb);
01222 else
01223 __skb_queue_tail(&local->pending[q],
01224 skb);
01225 } while ((skb = next));
01226
01227 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
01228 flags);
01229 return false;
01230 }
01231 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
01232
01233 info = IEEE80211_SKB_CB(skb);
01234
01235 if (fragm)
01236 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
01237 IEEE80211_TX_CTL_FIRST_FRAGMENT);
01238
01239 next = skb->next;
01240 len = skb->len;
01241
01242 if (next)
01243 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
01244
01245 sdata = vif_to_sdata(info->control.vif);
01246
01247 switch (sdata->vif.type) {
01248 case NL80211_IFTYPE_MONITOR:
01249 info->control.vif = NULL;
01250 break;
01251 case NL80211_IFTYPE_AP_VLAN:
01252 info->control.vif = &container_of(sdata->bss,
01253 struct ieee80211_sub_if_data, u.ap)->vif;
01254 break;
01255 default:
01256
01257 break;
01258 }
01259
01260 if (sta && sta->uploaded)
01261 info->control.sta = &sta->sta;
01262 else
01263 info->control.sta = NULL;
01264
01265 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
01266 drv_tx(local, skb);
01267
01268 ieee80211_tpt_led_trig_tx(local, fc, len);
01269 *skbp = skb = next;
01270 ieee80211_led_tx(local, 1);
01271 fragm = true;
01272 }
01273
01274 return true;
01275 }
01276
01277
01278
01279
01280
01281 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
01282 {
01283 struct sk_buff *skb = tx->skb;
01284 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01285 ieee80211_tx_result res = TX_DROP;
01286
01287 #define CALL_TXH(txh) \
01288 do { \
01289 res = txh(tx); \
01290 if (res != TX_CONTINUE) \
01291 goto txh_done; \
01292 } while (0)
01293
01294 CALL_TXH(ieee80211_tx_h_dynamic_ps);
01295 CALL_TXH(ieee80211_tx_h_check_assoc);
01296 CALL_TXH(ieee80211_tx_h_ps_buf);
01297 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
01298 CALL_TXH(ieee80211_tx_h_select_key);
01299 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
01300 CALL_TXH(ieee80211_tx_h_rate_ctrl);
01301
01302 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION))
01303 goto txh_done;
01304
01305 CALL_TXH(ieee80211_tx_h_michael_mic_add);
01306 CALL_TXH(ieee80211_tx_h_sequence);
01307 CALL_TXH(ieee80211_tx_h_fragment);
01308
01309 CALL_TXH(ieee80211_tx_h_stats);
01310 CALL_TXH(ieee80211_tx_h_encrypt);
01311 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
01312 CALL_TXH(ieee80211_tx_h_calculate_duration);
01313 #undef CALL_TXH
01314
01315 txh_done:
01316 if (unlikely(res == TX_DROP)) {
01317 I802_DEBUG_INC(tx->local->tx_handlers_drop);
01318 while (skb) {
01319 struct sk_buff *next;
01320
01321 next = skb->next;
01322 dev_kfree_skb(skb);
01323 skb = next;
01324 }
01325 return -1;
01326 } else if (unlikely(res == TX_QUEUED)) {
01327 I802_DEBUG_INC(tx->local->tx_handlers_queued);
01328 return -1;
01329 }
01330
01331 return 0;
01332 }
01333
01334
01335
01336
01337 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
01338 struct sk_buff *skb, bool txpending)
01339 {
01340 struct ieee80211_local *local = sdata->local;
01341 struct ieee80211_tx_data tx;
01342 ieee80211_tx_result res_prepare;
01343 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01344 bool result = true;
01345
01346 if (unlikely(skb->len < 10)) {
01347 dev_kfree_skb(skb);
01348 return true;
01349 }
01350
01351 rcu_read_lock();
01352
01353
01354 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
01355
01356 if (unlikely(res_prepare == TX_DROP)) {
01357 dev_kfree_skb(skb);
01358 goto out;
01359 } else if (unlikely(res_prepare == TX_QUEUED)) {
01360 goto out;
01361 }
01362
01363 tx.channel = local->hw.conf.channel;
01364 info->band = tx.channel->band;
01365
01366 if (!invoke_tx_handlers(&tx))
01367 result = __ieee80211_tx(local, &tx.skb, tx.sta, txpending);
01368 out:
01369 rcu_read_unlock();
01370 return result;
01371 }
01372
01373
01374
01375 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
01376 struct sk_buff *skb,
01377 int head_need, bool may_encrypt)
01378 {
01379 struct ieee80211_local *local = sdata->local;
01380 int tail_need = 0;
01381
01382 if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) {
01383 tail_need = IEEE80211_ENCRYPT_TAILROOM;
01384 tail_need -= skb_tailroom(skb);
01385 tail_need = max_t(int, tail_need, 0);
01386 }
01387
01388 if (skb_cloned(skb))
01389 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
01390 else if (head_need || tail_need)
01391 I802_DEBUG_INC(local->tx_expand_skb_head);
01392 else
01393 return 0;
01394
01395 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
01396 wiphy_debug(local->hw.wiphy,
01397 "failed to reallocate TX buffer\n");
01398 return -ENOMEM;
01399 }
01400
01401 return 0;
01402 }
01403
01404 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
01405 {
01406 struct ieee80211_local *local = sdata->local;
01407 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01408 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
01409 int headroom;
01410 bool may_encrypt;
01411
01412 rcu_read_lock();
01413
01414 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
01415
01416 headroom = local->tx_headroom;
01417 if (may_encrypt)
01418 headroom += IEEE80211_ENCRYPT_HEADROOM;
01419 headroom -= skb_headroom(skb);
01420 headroom = max_t(int, 0, headroom);
01421
01422 if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
01423 dev_kfree_skb(skb);
01424 rcu_read_unlock();
01425 return;
01426 }
01427
01428 hdr = (struct ieee80211_hdr *) skb->data;
01429 info->control.vif = &sdata->vif;
01430
01431 if (ieee80211_vif_is_mesh(&sdata->vif) &&
01432 ieee80211_is_data(hdr->frame_control) &&
01433 !is_multicast_ether_addr(hdr->addr1))
01434 if (mesh_nexthop_lookup(skb, sdata)) {
01435
01436 rcu_read_unlock();
01437 return;
01438 }
01439
01440 ieee80211_set_qos_hdr(sdata, skb);
01441 ieee80211_tx(sdata, skb, false);
01442 rcu_read_unlock();
01443 }
01444
01445 static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
01446 {
01447 struct ieee80211_radiotap_iterator iterator;
01448 struct ieee80211_radiotap_header *rthdr =
01449 (struct ieee80211_radiotap_header *) skb->data;
01450 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01451 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
01452 NULL);
01453 u16 txflags;
01454
01455 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
01456 IEEE80211_TX_CTL_DONTFRAG;
01457
01458
01459
01460
01461
01462
01463
01464 while (!ret) {
01465 ret = ieee80211_radiotap_iterator_next(&iterator);
01466
01467 if (ret)
01468 continue;
01469
01470
01471 switch (iterator.this_arg_index) {
01472
01473
01474
01475
01476
01477
01478 case IEEE80211_RADIOTAP_FLAGS:
01479 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
01480
01481
01482
01483
01484
01485
01486
01487 if (skb->len < (iterator._max_length + FCS_LEN))
01488 return false;
01489
01490 skb_trim(skb, skb->len - FCS_LEN);
01491 }
01492 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
01493 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
01494 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
01495 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
01496 break;
01497
01498 case IEEE80211_RADIOTAP_TX_FLAGS:
01499 txflags = get_unaligned_le16(iterator.this_arg);
01500 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
01501 info->flags |= IEEE80211_TX_CTL_NO_ACK;
01502 break;
01503
01504
01505
01506
01507
01508
01509
01510 default:
01511 break;
01512 }
01513 }
01514
01515 if (ret != -ENOENT)
01516 return false;
01517
01518
01519
01520
01521
01522
01523 skb_pull(skb, iterator._max_length);
01524
01525 return true;
01526 }
01527
01528 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
01529 struct net_device *dev)
01530 {
01531 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
01532 struct ieee80211_channel *chan = local->hw.conf.channel;
01533 struct ieee80211_radiotap_header *prthdr =
01534 (struct ieee80211_radiotap_header *)skb->data;
01535 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01536 struct ieee80211_hdr *hdr;
01537 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
01538 u16 len_rthdr;
01539 int hdrlen;
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557 if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
01558 IEEE80211_CHAN_PASSIVE_SCAN)))
01559 goto fail;
01560
01561
01562 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
01563 goto fail;
01564
01565
01566 if (unlikely(prthdr->it_version))
01567 goto fail;
01568
01569
01570 len_rthdr = ieee80211_get_radiotap_len(skb->data);
01571
01572
01573 if (unlikely(skb->len < len_rthdr))
01574 goto fail;
01575
01576
01577
01578
01579
01580
01581
01582 skb_set_mac_header(skb, len_rthdr);
01583
01584
01585
01586
01587 skb_set_network_header(skb, len_rthdr);
01588 skb_set_transport_header(skb, len_rthdr);
01589
01590 if (skb->len < len_rthdr + 2)
01591 goto fail;
01592
01593 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
01594 hdrlen = ieee80211_hdrlen(hdr->frame_control);
01595
01596 if (skb->len < len_rthdr + hdrlen)
01597 goto fail;
01598
01599
01600
01601
01602
01603 if (ieee80211_is_data(hdr->frame_control) &&
01604 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
01605 u8 *payload = (u8 *)hdr + hdrlen;
01606
01607 if (compare_ether_addr(payload, rfc1042_header) == 0)
01608 skb->protocol = cpu_to_be16((payload[6] << 8) |
01609 payload[7]);
01610 }
01611
01612 memset(info, 0, sizeof(*info));
01613
01614 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
01615 IEEE80211_TX_CTL_INJECTED;
01616
01617
01618 if (!ieee80211_parse_tx_radiotap(skb))
01619 goto fail;
01620
01621 rcu_read_lock();
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
01632
01633 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
01634 if (!ieee80211_sdata_running(tmp_sdata))
01635 continue;
01636 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
01637 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
01638 tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
01639 continue;
01640 if (compare_ether_addr(tmp_sdata->vif.addr, hdr->addr2) == 0) {
01641 sdata = tmp_sdata;
01642 break;
01643 }
01644 }
01645
01646 ieee80211_xmit(sdata, skb);
01647 rcu_read_unlock();
01648
01649 return NETDEV_TX_OK;
01650
01651 fail:
01652 dev_kfree_skb(skb);
01653 return NETDEV_TX_OK;
01654 }
01655
01671 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
01672 struct net_device *dev)
01673 {
01674 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
01675 struct ieee80211_local *local = sdata->local;
01676 struct ieee80211_tx_info *info;
01677 int ret = NETDEV_TX_BUSY, head_need;
01678 u16 ethertype, hdrlen, meshhdrlen = 0;
01679 __le16 fc;
01680 struct ieee80211_hdr hdr;
01681 struct ieee80211s_hdr mesh_hdr __maybe_unused;
01682 struct mesh_path __maybe_unused *mppath = NULL;
01683 const u8 *encaps_data;
01684 int encaps_len, skip_header_bytes;
01685 int nh_pos, h_pos;
01686 struct sta_info *sta = NULL;
01687 bool wme_sta = false, authorized = false, tdls_auth = false;
01688 struct sk_buff *tmp_skb;
01689 bool tdls_direct = false;
01690
01691 if (unlikely(skb->len < ETH_HLEN)) {
01692 ret = NETDEV_TX_OK;
01693 goto fail;
01694 }
01695
01696
01697
01698 ethertype = (skb->data[12] << 8) | skb->data[13];
01699 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
01700
01701 switch (sdata->vif.type) {
01702 case NL80211_IFTYPE_AP_VLAN:
01703 rcu_read_lock();
01704 sta = rcu_dereference(sdata->u.vlan.sta);
01705 if (sta) {
01706 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
01707
01708 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
01709 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01710 memcpy(hdr.addr3, skb->data, ETH_ALEN);
01711 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
01712 hdrlen = 30;
01713 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
01714 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
01715 }
01716 rcu_read_unlock();
01717 if (sta)
01718 break;
01719
01720 case NL80211_IFTYPE_AP:
01721 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
01722
01723 memcpy(hdr.addr1, skb->data, ETH_ALEN);
01724 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01725 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
01726 hdrlen = 24;
01727 break;
01728 case NL80211_IFTYPE_WDS:
01729 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
01730
01731 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
01732 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01733 memcpy(hdr.addr3, skb->data, ETH_ALEN);
01734 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
01735 hdrlen = 30;
01736 break;
01737 #ifdef CONFIG_MAC80211_MESH
01738 case NL80211_IFTYPE_MESH_POINT:
01739 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
01740
01741 sdata->u.mesh.mshstats.dropped_frames_ttl++;
01742 ret = NETDEV_TX_OK;
01743 goto fail;
01744 }
01745 rcu_read_lock();
01746 if (!is_multicast_ether_addr(skb->data))
01747 mppath = mpp_path_lookup(skb->data, sdata);
01748
01749
01750
01751
01752
01753
01754
01755 if (compare_ether_addr(sdata->vif.addr,
01756 skb->data + ETH_ALEN) == 0 &&
01757 !(mppath && compare_ether_addr(mppath->mpp, skb->data))) {
01758 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
01759 skb->data, skb->data + ETH_ALEN);
01760 rcu_read_unlock();
01761 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
01762 sdata, NULL, NULL);
01763 } else {
01764 int is_mesh_mcast = 1;
01765 const u8 *mesh_da;
01766
01767 if (is_multicast_ether_addr(skb->data))
01768
01769 mesh_da = skb->data;
01770 else {
01771 static const u8 bcast[ETH_ALEN] =
01772 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
01773 if (mppath) {
01774
01775 mesh_da = mppath->mpp;
01776 is_mesh_mcast = 0;
01777 } else {
01778
01779 mesh_da = bcast;
01780 }
01781 }
01782 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
01783 mesh_da, sdata->vif.addr);
01784 rcu_read_unlock();
01785 if (is_mesh_mcast)
01786 meshhdrlen =
01787 ieee80211_new_mesh_header(&mesh_hdr,
01788 sdata,
01789 skb->data + ETH_ALEN,
01790 NULL);
01791 else
01792 meshhdrlen =
01793 ieee80211_new_mesh_header(&mesh_hdr,
01794 sdata,
01795 skb->data,
01796 skb->data + ETH_ALEN);
01797
01798 }
01799 break;
01800 #endif
01801 case NL80211_IFTYPE_STATION:
01802 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
01803 bool tdls_peer = false;
01804
01805 rcu_read_lock();
01806 sta = sta_info_get(sdata, skb->data);
01807 if (sta) {
01808 authorized = test_sta_flag(sta,
01809 WLAN_STA_AUTHORIZED);
01810 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
01811 tdls_peer = test_sta_flag(sta,
01812 WLAN_STA_TDLS_PEER);
01813 tdls_auth = test_sta_flag(sta,
01814 WLAN_STA_TDLS_PEER_AUTH);
01815 }
01816 rcu_read_unlock();
01817
01818
01819
01820
01821
01822
01823 tdls_direct = tdls_peer && (tdls_auth ||
01824 !(ethertype == ETH_P_TDLS && skb->len > 14 &&
01825 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE));
01826 }
01827
01828 if (tdls_direct) {
01829
01830 if (!tdls_auth) {
01831 ret = NETDEV_TX_OK;
01832 goto fail;
01833 }
01834
01835
01836 memcpy(hdr.addr1, skb->data, ETH_ALEN);
01837 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
01838 memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
01839 hdrlen = 24;
01840 } else if (sdata->u.mgd.use_4addr &&
01841 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
01842 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
01843 IEEE80211_FCTL_TODS);
01844
01845 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
01846 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01847 memcpy(hdr.addr3, skb->data, ETH_ALEN);
01848 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
01849 hdrlen = 30;
01850 } else {
01851 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
01852
01853 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
01854 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
01855 memcpy(hdr.addr3, skb->data, ETH_ALEN);
01856 hdrlen = 24;
01857 }
01858 break;
01859 case NL80211_IFTYPE_ADHOC:
01860
01861 memcpy(hdr.addr1, skb->data, ETH_ALEN);
01862 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
01863 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
01864 hdrlen = 24;
01865 break;
01866 default:
01867 ret = NETDEV_TX_OK;
01868 goto fail;
01869 }
01870
01871
01872
01873
01874
01875
01876 if (!is_multicast_ether_addr(hdr.addr1)) {
01877 rcu_read_lock();
01878 sta = sta_info_get(sdata, hdr.addr1);
01879 if (sta) {
01880 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
01881 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
01882 }
01883 rcu_read_unlock();
01884 }
01885
01886
01887 if (ieee80211_vif_is_mesh(&sdata->vif))
01888 wme_sta = true;
01889
01890
01891 if (wme_sta && local->hw.queues >= 4) {
01892 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
01893 hdrlen += 2;
01894 }
01895
01896
01897
01898
01899
01900 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
01901 !is_multicast_ether_addr(hdr.addr1) && !authorized &&
01902 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
01903 compare_ether_addr(sdata->vif.addr, skb->data + ETH_ALEN)))) {
01904 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01905 if (net_ratelimit())
01906 printk(KERN_DEBUG "%s: dropped frame to %pM"
01907 " (unauthorized port)\n", dev->name,
01908 hdr.addr1);
01909 #endif
01910
01911 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
01912
01913 ret = NETDEV_TX_OK;
01914 goto fail;
01915 }
01916
01917
01918
01919
01920 if (skb_shared(skb)) {
01921 tmp_skb = skb;
01922 skb = skb_clone(skb, GFP_ATOMIC);
01923 kfree_skb(tmp_skb);
01924
01925 if (!skb) {
01926 ret = NETDEV_TX_OK;
01927 goto fail;
01928 }
01929 }
01930
01931 hdr.frame_control = fc;
01932 hdr.duration_id = 0;
01933 hdr.seq_ctrl = 0;
01934
01935 skip_header_bytes = ETH_HLEN;
01936 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
01937 encaps_data = bridge_tunnel_header;
01938 encaps_len = sizeof(bridge_tunnel_header);
01939 skip_header_bytes -= 2;
01940 } else if (ethertype >= 0x600) {
01941 encaps_data = rfc1042_header;
01942 encaps_len = sizeof(rfc1042_header);
01943 skip_header_bytes -= 2;
01944 } else {
01945 encaps_data = NULL;
01946 encaps_len = 0;
01947 }
01948
01949 nh_pos = skb_network_header(skb) - skb->data;
01950 h_pos = skb_transport_header(skb) - skb->data;
01951
01952 skb_pull(skb, skip_header_bytes);
01953 nh_pos -= skip_header_bytes;
01954 h_pos -= skip_header_bytes;
01955
01956 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970 if (head_need > 0 || skb_cloned(skb)) {
01971 head_need += IEEE80211_ENCRYPT_HEADROOM;
01972 head_need += local->tx_headroom;
01973 head_need = max_t(int, 0, head_need);
01974 if (ieee80211_skb_resize(sdata, skb, head_need, true))
01975 goto fail;
01976 }
01977
01978 if (encaps_data) {
01979 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
01980 nh_pos += encaps_len;
01981 h_pos += encaps_len;
01982 }
01983
01984 #ifdef CONFIG_MAC80211_MESH
01985 if (meshhdrlen > 0) {
01986 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
01987 nh_pos += meshhdrlen;
01988 h_pos += meshhdrlen;
01989 }
01990 #endif
01991
01992 if (ieee80211_is_data_qos(fc)) {
01993 __le16 *qos_control;
01994
01995 qos_control = (__le16*) skb_push(skb, 2);
01996 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
01997
01998
01999
02000
02001 *qos_control = 0;
02002 } else
02003 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
02004
02005 nh_pos += hdrlen;
02006 h_pos += hdrlen;
02007
02008 dev->stats.tx_packets++;
02009 dev->stats.tx_bytes += skb->len;
02010
02011
02012
02013
02014 skb_set_mac_header(skb, 0);
02015 skb_set_network_header(skb, nh_pos);
02016 skb_set_transport_header(skb, h_pos);
02017
02018 info = IEEE80211_SKB_CB(skb);
02019 memset(info, 0, sizeof(*info));
02020
02021 dev->trans_start = jiffies;
02022 ieee80211_xmit(sdata, skb);
02023
02024 return NETDEV_TX_OK;
02025
02026 fail:
02027 if (ret == NETDEV_TX_OK)
02028 dev_kfree_skb(skb);
02029
02030 return ret;
02031 }
02032
02033
02034
02035
02036
02037
02038 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
02039 {
02040 int i;
02041
02042 for (i = 0; i < local->hw.queues; i++)
02043 skb_queue_purge(&local->pending[i]);
02044 }
02045
02046
02047
02048
02049
02050
02051 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
02052 struct sk_buff *skb)
02053 {
02054 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
02055 struct ieee80211_sub_if_data *sdata;
02056 struct sta_info *sta;
02057 struct ieee80211_hdr *hdr;
02058 bool result;
02059
02060 sdata = vif_to_sdata(info->control.vif);
02061
02062 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
02063 result = ieee80211_tx(sdata, skb, true);
02064 } else {
02065 hdr = (struct ieee80211_hdr *)skb->data;
02066 sta = sta_info_get(sdata, hdr->addr1);
02067
02068 result = __ieee80211_tx(local, &skb, sta, true);
02069 }
02070
02071 return result;
02072 }
02073
02074
02075
02076
02077 void ieee80211_tx_pending(unsigned long data)
02078 {
02079 struct ieee80211_local *local = (struct ieee80211_local *)data;
02080 struct ieee80211_sub_if_data *sdata;
02081 unsigned long flags;
02082 int i;
02083 bool txok;
02084
02085 rcu_read_lock();
02086
02087 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
02088 for (i = 0; i < local->hw.queues; i++) {
02089
02090
02091
02092
02093 if (local->queue_stop_reasons[i] ||
02094 skb_queue_empty(&local->pending[i]))
02095 continue;
02096
02097 while (!skb_queue_empty(&local->pending[i])) {
02098 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
02099 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
02100
02101 if (WARN_ON(!info->control.vif)) {
02102 kfree_skb(skb);
02103 continue;
02104 }
02105
02106 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
02107 flags);
02108
02109 txok = ieee80211_tx_pending_skb(local, skb);
02110 spin_lock_irqsave(&local->queue_stop_reason_lock,
02111 flags);
02112 if (!txok)
02113 break;
02114 }
02115
02116 if (skb_queue_empty(&local->pending[i]))
02117 list_for_each_entry_rcu(sdata, &local->interfaces, list)
02118 netif_wake_subqueue(sdata->dev, i);
02119 }
02120 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
02121
02122 rcu_read_unlock();
02123 }
02124
02125
02126
02127 static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
02128 struct sk_buff *skb,
02129 struct beacon_data *beacon)
02130 {
02131 u8 *pos, *tim;
02132 int aid0 = 0;
02133 int i, have_bits = 0, n1, n2;
02134
02135
02136
02137 if (atomic_read(&bss->num_sta_ps) > 0)
02138
02139
02140 have_bits = !bitmap_empty((unsigned long*)bss->tim,
02141 IEEE80211_MAX_AID+1);
02142
02143 if (bss->dtim_count == 0)
02144 bss->dtim_count = beacon->dtim_period - 1;
02145 else
02146 bss->dtim_count--;
02147
02148 tim = pos = (u8 *) skb_put(skb, 6);
02149 *pos++ = WLAN_EID_TIM;
02150 *pos++ = 4;
02151 *pos++ = bss->dtim_count;
02152 *pos++ = beacon->dtim_period;
02153
02154 if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
02155 aid0 = 1;
02156
02157 bss->dtim_bc_mc = aid0 == 1;
02158
02159 if (have_bits) {
02160
02161
02162
02163 n1 = 0;
02164 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
02165 if (bss->tim[i]) {
02166 n1 = i & 0xfe;
02167 break;
02168 }
02169 }
02170 n2 = n1;
02171 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
02172 if (bss->tim[i]) {
02173 n2 = i;
02174 break;
02175 }
02176 }
02177
02178
02179 *pos++ = n1 | aid0;
02180
02181 memcpy(pos, bss->tim + n1, n2 - n1 + 1);
02182
02183 tim[1] = n2 - n1 + 4;
02184 skb_put(skb, n2 - n1);
02185 } else {
02186 *pos++ = aid0;
02187 *pos++ = 0;
02188 }
02189 }
02190
02191 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
02192 struct ieee80211_vif *vif,
02193 u16 *tim_offset, u16 *tim_length)
02194 {
02195 struct ieee80211_local *local = hw_to_local(hw);
02196 struct sk_buff *skb = NULL;
02197 struct ieee80211_tx_info *info;
02198 struct ieee80211_sub_if_data *sdata = NULL;
02199 struct ieee80211_if_ap *ap = NULL;
02200 struct beacon_data *beacon;
02201 struct ieee80211_supported_band *sband;
02202 enum ieee80211_band band = local->hw.conf.channel->band;
02203 struct ieee80211_tx_rate_control txrc;
02204
02205 sband = local->hw.wiphy->bands[band];
02206
02207 rcu_read_lock();
02208
02209 sdata = vif_to_sdata(vif);
02210
02211 if (!ieee80211_sdata_running(sdata))
02212 goto out;
02213
02214 if (tim_offset)
02215 *tim_offset = 0;
02216 if (tim_length)
02217 *tim_length = 0;
02218
02219 if (sdata->vif.type == NL80211_IFTYPE_AP) {
02220 ap = &sdata->u.ap;
02221 beacon = rcu_dereference(ap->beacon);
02222 if (beacon) {
02223
02224
02225
02226
02227 skb = dev_alloc_skb(local->tx_headroom +
02228 beacon->head_len +
02229 beacon->tail_len + 256);
02230 if (!skb)
02231 goto out;
02232
02233 skb_reserve(skb, local->tx_headroom);
02234 memcpy(skb_put(skb, beacon->head_len), beacon->head,
02235 beacon->head_len);
02236
02237
02238
02239
02240
02241
02242
02243
02244 if (local->tim_in_locked_section) {
02245 ieee80211_beacon_add_tim(ap, skb, beacon);
02246 } else {
02247 unsigned long flags;
02248
02249 spin_lock_irqsave(&local->sta_lock, flags);
02250 ieee80211_beacon_add_tim(ap, skb, beacon);
02251 spin_unlock_irqrestore(&local->sta_lock, flags);
02252 }
02253
02254 if (tim_offset)
02255 *tim_offset = beacon->head_len;
02256 if (tim_length)
02257 *tim_length = skb->len - beacon->head_len;
02258
02259 if (beacon->tail)
02260 memcpy(skb_put(skb, beacon->tail_len),
02261 beacon->tail, beacon->tail_len);
02262 } else
02263 goto out;
02264 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
02265 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
02266 struct ieee80211_hdr *hdr;
02267 struct sk_buff *presp = rcu_dereference(ifibss->presp);
02268
02269 if (!presp)
02270 goto out;
02271
02272 skb = skb_copy(presp, GFP_ATOMIC);
02273 if (!skb)
02274 goto out;
02275
02276 hdr = (struct ieee80211_hdr *) skb->data;
02277 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
02278 IEEE80211_STYPE_BEACON);
02279 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
02280 struct ieee80211_mgmt *mgmt;
02281 u8 *pos;
02282
02283 #ifdef CONFIG_MAC80211_MESH
02284 if (!sdata->u.mesh.mesh_id_len)
02285 goto out;
02286 #endif
02287
02288
02289 skb = dev_alloc_skb(local->tx_headroom + 400 +
02290 sdata->u.mesh.ie_len);
02291 if (!skb)
02292 goto out;
02293
02294 skb_reserve(skb, local->hw.extra_tx_headroom);
02295 mgmt = (struct ieee80211_mgmt *)
02296 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
02297 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
02298 mgmt->frame_control =
02299 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
02300 memset(mgmt->da, 0xff, ETH_ALEN);
02301 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
02302 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
02303 mgmt->u.beacon.beacon_int =
02304 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
02305 mgmt->u.beacon.capab_info |= cpu_to_le16(
02306 sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
02307
02308 pos = skb_put(skb, 2);
02309 *pos++ = WLAN_EID_SSID;
02310 *pos++ = 0x0;
02311
02312 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
02313 mesh_add_ds_params_ie(skb, sdata) ||
02314 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
02315 mesh_add_rsn_ie(skb, sdata) ||
02316 mesh_add_meshid_ie(skb, sdata) ||
02317 mesh_add_meshconf_ie(skb, sdata) ||
02318 mesh_add_vendor_ies(skb, sdata)) {
02319 pr_err("o11s: couldn't add ies!\n");
02320 goto out;
02321 }
02322 } else {
02323 WARN_ON(1);
02324 goto out;
02325 }
02326
02327 info = IEEE80211_SKB_CB(skb);
02328
02329 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
02330 info->flags |= IEEE80211_TX_CTL_NO_ACK;
02331 info->band = band;
02332
02333 memset(&txrc, 0, sizeof(txrc));
02334 txrc.hw = hw;
02335 txrc.sband = sband;
02336 txrc.bss_conf = &sdata->vif.bss_conf;
02337 txrc.skb = skb;
02338 txrc.reported_rate.idx = -1;
02339 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
02340 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
02341 txrc.max_rate_idx = -1;
02342 else
02343 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
02344 txrc.bss = true;
02345 rate_control_get_rate(sdata, NULL, &txrc);
02346
02347 info->control.vif = vif;
02348
02349 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
02350 IEEE80211_TX_CTL_ASSIGN_SEQ |
02351 IEEE80211_TX_CTL_FIRST_FRAGMENT;
02352 out:
02353 rcu_read_unlock();
02354 return skb;
02355 }
02356 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
02357
02358 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
02359 struct ieee80211_vif *vif)
02360 {
02361 struct ieee80211_sub_if_data *sdata;
02362 struct ieee80211_if_managed *ifmgd;
02363 struct ieee80211_pspoll *pspoll;
02364 struct ieee80211_local *local;
02365 struct sk_buff *skb;
02366
02367 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
02368 return NULL;
02369
02370 sdata = vif_to_sdata(vif);
02371 ifmgd = &sdata->u.mgd;
02372 local = sdata->local;
02373
02374 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
02375 if (!skb)
02376 return NULL;
02377
02378 skb_reserve(skb, local->hw.extra_tx_headroom);
02379
02380 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
02381 memset(pspoll, 0, sizeof(*pspoll));
02382 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
02383 IEEE80211_STYPE_PSPOLL);
02384 pspoll->aid = cpu_to_le16(ifmgd->aid);
02385
02386
02387 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
02388
02389 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
02390 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
02391
02392 return skb;
02393 }
02394 EXPORT_SYMBOL(ieee80211_pspoll_get);
02395
02396 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
02397 struct ieee80211_vif *vif)
02398 {
02399 struct ieee80211_hdr_3addr *nullfunc;
02400 struct ieee80211_sub_if_data *sdata;
02401 struct ieee80211_if_managed *ifmgd;
02402 struct ieee80211_local *local;
02403 struct sk_buff *skb;
02404
02405 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
02406 return NULL;
02407
02408 sdata = vif_to_sdata(vif);
02409 ifmgd = &sdata->u.mgd;
02410 local = sdata->local;
02411
02412 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
02413 if (!skb)
02414 return NULL;
02415
02416 skb_reserve(skb, local->hw.extra_tx_headroom);
02417
02418 nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
02419 sizeof(*nullfunc));
02420 memset(nullfunc, 0, sizeof(*nullfunc));
02421 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
02422 IEEE80211_STYPE_NULLFUNC |
02423 IEEE80211_FCTL_TODS);
02424 memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
02425 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
02426 memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
02427
02428 return skb;
02429 }
02430 EXPORT_SYMBOL(ieee80211_nullfunc_get);
02431
02432 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
02433 struct ieee80211_vif *vif,
02434 const u8 *ssid, size_t ssid_len,
02435 const u8 *ie, size_t ie_len)
02436 {
02437 struct ieee80211_sub_if_data *sdata;
02438 struct ieee80211_local *local;
02439 struct ieee80211_hdr_3addr *hdr;
02440 struct sk_buff *skb;
02441 size_t ie_ssid_len;
02442 u8 *pos;
02443
02444 sdata = vif_to_sdata(vif);
02445 local = sdata->local;
02446 ie_ssid_len = 2 + ssid_len;
02447
02448 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
02449 ie_ssid_len + ie_len);
02450 if (!skb)
02451 return NULL;
02452
02453 skb_reserve(skb, local->hw.extra_tx_headroom);
02454
02455 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
02456 memset(hdr, 0, sizeof(*hdr));
02457 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
02458 IEEE80211_STYPE_PROBE_REQ);
02459 memset(hdr->addr1, 0xff, ETH_ALEN);
02460 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
02461 memset(hdr->addr3, 0xff, ETH_ALEN);
02462
02463 pos = skb_put(skb, ie_ssid_len);
02464 *pos++ = WLAN_EID_SSID;
02465 *pos++ = ssid_len;
02466 if (ssid)
02467 memcpy(pos, ssid, ssid_len);
02468 pos += ssid_len;
02469
02470 if (ie) {
02471 pos = skb_put(skb, ie_len);
02472 memcpy(pos, ie, ie_len);
02473 }
02474
02475 return skb;
02476 }
02477 EXPORT_SYMBOL(ieee80211_probereq_get);
02478
02479 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
02480 const void *frame, size_t frame_len,
02481 const struct ieee80211_tx_info *frame_txctl,
02482 struct ieee80211_rts *rts)
02483 {
02484 const struct ieee80211_hdr *hdr = frame;
02485
02486 rts->frame_control =
02487 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
02488 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
02489 frame_txctl);
02490 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
02491 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
02492 }
02493 EXPORT_SYMBOL(ieee80211_rts_get);
02494
02495 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
02496 const void *frame, size_t frame_len,
02497 const struct ieee80211_tx_info *frame_txctl,
02498 struct ieee80211_cts *cts)
02499 {
02500 const struct ieee80211_hdr *hdr = frame;
02501
02502 cts->frame_control =
02503 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
02504 cts->duration = ieee80211_ctstoself_duration(hw, vif,
02505 frame_len, frame_txctl);
02506 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
02507 }
02508 EXPORT_SYMBOL(ieee80211_ctstoself_get);
02509
02510 struct sk_buff *
02511 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
02512 struct ieee80211_vif *vif)
02513 {
02514 struct ieee80211_local *local = hw_to_local(hw);
02515 struct sk_buff *skb = NULL;
02516 struct ieee80211_tx_data tx;
02517 struct ieee80211_sub_if_data *sdata;
02518 struct ieee80211_if_ap *bss = NULL;
02519 struct beacon_data *beacon;
02520 struct ieee80211_tx_info *info;
02521
02522 sdata = vif_to_sdata(vif);
02523 bss = &sdata->u.ap;
02524
02525 rcu_read_lock();
02526 beacon = rcu_dereference(bss->beacon);
02527
02528 if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
02529 goto out;
02530
02531 if (bss->dtim_count != 0 || !bss->dtim_bc_mc)
02532 goto out;
02533
02534 while (1) {
02535 skb = skb_dequeue(&bss->ps_bc_buf);
02536 if (!skb)
02537 goto out;
02538 local->total_ps_buffered--;
02539
02540 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
02541 struct ieee80211_hdr *hdr =
02542 (struct ieee80211_hdr *) skb->data;
02543
02544
02545
02546 hdr->frame_control |=
02547 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
02548 }
02549
02550 if (!ieee80211_tx_prepare(sdata, &tx, skb))
02551 break;
02552 dev_kfree_skb_any(skb);
02553 }
02554
02555 info = IEEE80211_SKB_CB(skb);
02556
02557 tx.flags |= IEEE80211_TX_PS_BUFFERED;
02558 tx.channel = local->hw.conf.channel;
02559 info->band = tx.channel->band;
02560
02561 if (invoke_tx_handlers(&tx))
02562 skb = NULL;
02563 out:
02564 rcu_read_unlock();
02565
02566 return skb;
02567 }
02568 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
02569
02570 void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
02571 {
02572 skb_set_mac_header(skb, 0);
02573 skb_set_network_header(skb, 0);
02574 skb_set_transport_header(skb, 0);
02575
02576
02577 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
02578 skb->priority = 7;
02579
02580
02581
02582
02583
02584
02585 local_bh_disable();
02586 ieee80211_xmit(sdata, skb);
02587 local_bh_enable();
02588 }