ieee80211_tx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /******************************************************************************
  2. Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of version 2 of the GNU General Public License as
  5. published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  9. more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc., 59
  12. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  13. The full GNU General Public License is included in this distribution in the
  14. file called LICENSE.
  15. Contact Information:
  16. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. ******************************************************************************/
  19. #include <linux/compiler.h>
  20. #include <linux/errno.h>
  21. #include <linux/if_arp.h>
  22. #include <linux/in6.h>
  23. #include <linux/in.h>
  24. #include <linux/ip.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/slab.h>
  31. #include <linux/tcp.h>
  32. #include <linux/types.h>
  33. #include <linux/wireless.h>
  34. #include <linux/etherdevice.h>
  35. #include <asm/uaccess.h>
  36. #include <net/ieee80211.h>
  37. /*
  38. 802.11 Data Frame
  39. ,-------------------------------------------------------------------.
  40. Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
  41. |------|------|---------|---------|---------|------|---------|------|
  42. Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
  43. | | tion | (BSSID) | | | ence | data | |
  44. `--------------------------------------------------| |------'
  45. Total: 28 non-data bytes `----.----'
  46. |
  47. .- 'Frame data' expands, if WEP enabled, to <----------'
  48. |
  49. V
  50. ,-----------------------.
  51. Bytes | 4 | 0-2296 | 4 |
  52. |-----|-----------|-----|
  53. Desc. | IV | Encrypted | ICV |
  54. | | Packet | |
  55. `-----| |-----'
  56. `-----.-----'
  57. |
  58. .- 'Encrypted Packet' expands to
  59. |
  60. V
  61. ,---------------------------------------------------.
  62. Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
  63. |------|------|---------|----------|------|---------|
  64. Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
  65. | DSAP | SSAP | | | | Packet |
  66. | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
  67. `----------------------------------------------------
  68. Total: 8 non-data bytes
  69. 802.3 Ethernet Data Frame
  70. ,-----------------------------------------.
  71. Bytes | 6 | 6 | 2 | Variable | 4 |
  72. |-------|-------|------|-----------|------|
  73. Desc. | Dest. | Source| Type | IP Packet | fcs |
  74. | MAC | MAC | | | |
  75. `-----------------------------------------'
  76. Total: 18 non-data bytes
  77. In the event that fragmentation is required, the incoming payload is split into
  78. N parts of size ieee->fts. The first fragment contains the SNAP header and the
  79. remaining packets are just data.
  80. If encryption is enabled, each fragment payload size is reduced by enough space
  81. to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP)
  82. So if you have 1500 bytes of payload with ieee->fts set to 500 without
  83. encryption it will take 3 frames. With WEP it will take 4 frames as the
  84. payload of each frame is reduced to 492 bytes.
  85. * SKB visualization
  86. *
  87. * ,- skb->data
  88. * |
  89. * | ETHERNET HEADER ,-<-- PAYLOAD
  90. * | | 14 bytes from skb->data
  91. * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
  92. * | | | |
  93. * |,-Dest.--. ,--Src.---. | | |
  94. * | 6 bytes| | 6 bytes | | | |
  95. * v | | | | | |
  96. * 0 | v 1 | v | v 2
  97. * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  98. * ^ | ^ | ^ |
  99. * | | | | | |
  100. * | | | | `T' <---- 2 bytes for Type
  101. * | | | |
  102. * | | '---SNAP--' <-------- 6 bytes for SNAP
  103. * | |
  104. * `-IV--' <-------------------- 4 bytes for IV (WEP)
  105. *
  106. * SNAP HEADER
  107. *
  108. */
  109. static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
  110. static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
  111. static int ieee80211_copy_snap(u8 * data, u16 h_proto)
  112. {
  113. struct ieee80211_snap_hdr *snap;
  114. u8 *oui;
  115. snap = (struct ieee80211_snap_hdr *)data;
  116. snap->dsap = 0xaa;
  117. snap->ssap = 0xaa;
  118. snap->ctrl = 0x03;
  119. if (h_proto == 0x8137 || h_proto == 0x80f3)
  120. oui = P802_1H_OUI;
  121. else
  122. oui = RFC1042_OUI;
  123. snap->oui[0] = oui[0];
  124. snap->oui[1] = oui[1];
  125. snap->oui[2] = oui[2];
  126. *(u16 *) (data + SNAP_SIZE) = htons(h_proto);
  127. return SNAP_SIZE + sizeof(u16);
  128. }
  129. static int ieee80211_encrypt_fragment(struct ieee80211_device *ieee,
  130. struct sk_buff *frag, int hdr_len)
  131. {
  132. struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
  133. int res;
  134. if (crypt == NULL)
  135. return -1;
  136. /* To encrypt, frame format is:
  137. * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
  138. atomic_inc(&crypt->refcnt);
  139. res = 0;
  140. if (crypt->ops && crypt->ops->encrypt_mpdu)
  141. res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv);
  142. atomic_dec(&crypt->refcnt);
  143. if (res < 0) {
  144. printk(KERN_INFO "%s: Encryption failed: len=%d.\n",
  145. ieee->dev->name, frag->len);
  146. ieee->ieee_stats.tx_discards++;
  147. return -1;
  148. }
  149. return 0;
  150. }
  151. void ieee80211_txb_free(struct ieee80211_txb *txb)
  152. {
  153. int i;
  154. if (unlikely(!txb))
  155. return;
  156. for (i = 0; i < txb->nr_frags; i++)
  157. if (txb->fragments[i])
  158. dev_kfree_skb_any(txb->fragments[i]);
  159. kfree(txb);
  160. }
  161. static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
  162. int headroom, gfp_t gfp_mask)
  163. {
  164. struct ieee80211_txb *txb;
  165. int i;
  166. txb = kmalloc(sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags),
  167. gfp_mask);
  168. if (!txb)
  169. return NULL;
  170. memset(txb, 0, sizeof(struct ieee80211_txb));
  171. txb->nr_frags = nr_frags;
  172. txb->frag_size = txb_size;
  173. for (i = 0; i < nr_frags; i++) {
  174. txb->fragments[i] = __dev_alloc_skb(txb_size + headroom,
  175. gfp_mask);
  176. if (unlikely(!txb->fragments[i])) {
  177. i--;
  178. break;
  179. }
  180. skb_reserve(txb->fragments[i], headroom);
  181. }
  182. if (unlikely(i != nr_frags)) {
  183. while (i >= 0)
  184. dev_kfree_skb_any(txb->fragments[i--]);
  185. kfree(txb);
  186. return NULL;
  187. }
  188. return txb;
  189. }
  190. static int ieee80211_classify(struct sk_buff *skb)
  191. {
  192. struct ethhdr *eth;
  193. struct iphdr *ip;
  194. eth = (struct ethhdr *)skb->data;
  195. if (eth->h_proto != __constant_htons(ETH_P_IP))
  196. return 0;
  197. ip = skb->nh.iph;
  198. switch (ip->tos & 0xfc) {
  199. case 0x20:
  200. return 2;
  201. case 0x40:
  202. return 1;
  203. case 0x60:
  204. return 3;
  205. case 0x80:
  206. return 4;
  207. case 0xa0:
  208. return 5;
  209. case 0xc0:
  210. return 6;
  211. case 0xe0:
  212. return 7;
  213. default:
  214. return 0;
  215. }
  216. }
  217. /* Incoming skb is converted to a txb which consists of
  218. * a block of 802.11 fragment packets (stored as skbs) */
  219. int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
  220. {
  221. struct ieee80211_device *ieee = netdev_priv(dev);
  222. struct ieee80211_txb *txb = NULL;
  223. struct ieee80211_hdr_3addrqos *frag_hdr;
  224. int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size,
  225. rts_required;
  226. unsigned long flags;
  227. struct net_device_stats *stats = &ieee->stats;
  228. int ether_type, encrypt, host_encrypt, host_encrypt_msdu, host_build_iv;
  229. int bytes, fc, hdr_len;
  230. struct sk_buff *skb_frag;
  231. struct ieee80211_hdr_3addrqos header = {/* Ensure zero initialized */
  232. .duration_id = 0,
  233. .seq_ctl = 0,
  234. .qos_ctl = 0
  235. };
  236. u8 dest[ETH_ALEN], src[ETH_ALEN];
  237. struct ieee80211_crypt_data *crypt;
  238. int priority = skb->priority;
  239. int snapped = 0;
  240. if (ieee->is_queue_full && (*ieee->is_queue_full) (dev, priority))
  241. return NETDEV_TX_BUSY;
  242. spin_lock_irqsave(&ieee->lock, flags);
  243. /* If there is no driver handler to take the TXB, dont' bother
  244. * creating it... */
  245. if (!ieee->hard_start_xmit) {
  246. printk(KERN_WARNING "%s: No xmit handler.\n", ieee->dev->name);
  247. goto success;
  248. }
  249. if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) {
  250. printk(KERN_WARNING "%s: skb too small (%d).\n",
  251. ieee->dev->name, skb->len);
  252. goto success;
  253. }
  254. ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto);
  255. crypt = ieee->crypt[ieee->tx_keyidx];
  256. encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
  257. ieee->sec.encrypt;
  258. host_encrypt = ieee->host_encrypt && encrypt && crypt;
  259. host_encrypt_msdu = ieee->host_encrypt_msdu && encrypt && crypt;
  260. host_build_iv = ieee->host_build_iv && encrypt && crypt;
  261. if (!encrypt && ieee->ieee802_1x &&
  262. ieee->drop_unencrypted && ether_type != ETH_P_PAE) {
  263. stats->tx_dropped++;
  264. goto success;
  265. }
  266. /* Save source and destination addresses */
  267. memcpy(dest, skb->data, ETH_ALEN);
  268. memcpy(src, skb->data + ETH_ALEN, ETH_ALEN);
  269. if (host_encrypt || host_build_iv)
  270. fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA |
  271. IEEE80211_FCTL_PROTECTED;
  272. else
  273. fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA;
  274. if (ieee->iw_mode == IW_MODE_INFRA) {
  275. fc |= IEEE80211_FCTL_TODS;
  276. /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */
  277. memcpy(header.addr1, ieee->bssid, ETH_ALEN);
  278. memcpy(header.addr2, src, ETH_ALEN);
  279. memcpy(header.addr3, dest, ETH_ALEN);
  280. } else if (ieee->iw_mode == IW_MODE_ADHOC) {
  281. /* not From/To DS: Addr1 = DA, Addr2 = SA, Addr3 = BSSID */
  282. memcpy(header.addr1, dest, ETH_ALEN);
  283. memcpy(header.addr2, src, ETH_ALEN);
  284. memcpy(header.addr3, ieee->bssid, ETH_ALEN);
  285. }
  286. hdr_len = IEEE80211_3ADDR_LEN;
  287. if (ieee->is_qos_active && ieee->is_qos_active(dev, skb)) {
  288. fc |= IEEE80211_STYPE_QOS_DATA;
  289. hdr_len += 2;
  290. skb->priority = ieee80211_classify(skb);
  291. header.qos_ctl |= cpu_to_le16(skb->priority & IEEE80211_QCTL_TID);
  292. }
  293. header.frame_ctl = cpu_to_le16(fc);
  294. /* Advance the SKB to the start of the payload */
  295. skb_pull(skb, sizeof(struct ethhdr));
  296. /* Determine total amount of storage required for TXB packets */
  297. bytes = skb->len + SNAP_SIZE + sizeof(u16);
  298. /* Encrypt msdu first on the whole data packet. */
  299. if ((host_encrypt || host_encrypt_msdu) &&
  300. crypt && crypt->ops && crypt->ops->encrypt_msdu) {
  301. int res = 0;
  302. int len = bytes + hdr_len + crypt->ops->extra_msdu_prefix_len +
  303. crypt->ops->extra_msdu_postfix_len;
  304. struct sk_buff *skb_new = dev_alloc_skb(len);
  305. if (unlikely(!skb_new))
  306. goto failed;
  307. skb_reserve(skb_new, crypt->ops->extra_msdu_prefix_len);
  308. memcpy(skb_put(skb_new, hdr_len), &header, hdr_len);
  309. snapped = 1;
  310. ieee80211_copy_snap(skb_put(skb_new, SNAP_SIZE + sizeof(u16)),
  311. ether_type);
  312. memcpy(skb_put(skb_new, skb->len), skb->data, skb->len);
  313. res = crypt->ops->encrypt_msdu(skb_new, hdr_len, crypt->priv);
  314. if (res < 0) {
  315. IEEE80211_ERROR("msdu encryption failed\n");
  316. dev_kfree_skb_any(skb_new);
  317. goto failed;
  318. }
  319. dev_kfree_skb_any(skb);
  320. skb = skb_new;
  321. bytes += crypt->ops->extra_msdu_prefix_len +
  322. crypt->ops->extra_msdu_postfix_len;
  323. skb_pull(skb, hdr_len);
  324. }
  325. if (host_encrypt || ieee->host_open_frag) {
  326. /* Determine fragmentation size based on destination (multicast
  327. * and broadcast are not fragmented) */
  328. if (is_multicast_ether_addr(dest) ||
  329. is_broadcast_ether_addr(dest))
  330. frag_size = MAX_FRAG_THRESHOLD;
  331. else
  332. frag_size = ieee->fts;
  333. /* Determine amount of payload per fragment. Regardless of if
  334. * this stack is providing the full 802.11 header, one will
  335. * eventually be affixed to this fragment -- so we must account
  336. * for it when determining the amount of payload space. */
  337. bytes_per_frag = frag_size - hdr_len;
  338. if (ieee->config &
  339. (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
  340. bytes_per_frag -= IEEE80211_FCS_LEN;
  341. /* Each fragment may need to have room for encryptiong
  342. * pre/postfix */
  343. if (host_encrypt)
  344. bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len +
  345. crypt->ops->extra_mpdu_postfix_len;
  346. /* Number of fragments is the total
  347. * bytes_per_frag / payload_per_fragment */
  348. nr_frags = bytes / bytes_per_frag;
  349. bytes_last_frag = bytes % bytes_per_frag;
  350. if (bytes_last_frag)
  351. nr_frags++;
  352. else
  353. bytes_last_frag = bytes_per_frag;
  354. } else {
  355. nr_frags = 1;
  356. bytes_per_frag = bytes_last_frag = bytes;
  357. frag_size = bytes + hdr_len;
  358. }
  359. rts_required = (frag_size > ieee->rts
  360. && ieee->config & CFG_IEEE80211_RTS);
  361. if (rts_required)
  362. nr_frags++;
  363. /* When we allocate the TXB we allocate enough space for the reserve
  364. * and full fragment bytes (bytes_per_frag doesn't include prefix,
  365. * postfix, header, FCS, etc.) */
  366. txb = ieee80211_alloc_txb(nr_frags, frag_size,
  367. ieee->tx_headroom, GFP_ATOMIC);
  368. if (unlikely(!txb)) {
  369. printk(KERN_WARNING "%s: Could not allocate TXB\n",
  370. ieee->dev->name);
  371. goto failed;
  372. }
  373. txb->encrypted = encrypt;
  374. if (host_encrypt)
  375. txb->payload_size = frag_size * (nr_frags - 1) +
  376. bytes_last_frag;
  377. else
  378. txb->payload_size = bytes;
  379. if (rts_required) {
  380. skb_frag = txb->fragments[0];
  381. frag_hdr =
  382. (struct ieee80211_hdr_3addrqos *)skb_put(skb_frag, hdr_len);
  383. /*
  384. * Set header frame_ctl to the RTS.
  385. */
  386. header.frame_ctl =
  387. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  388. memcpy(frag_hdr, &header, hdr_len);
  389. /*
  390. * Restore header frame_ctl to the original data setting.
  391. */
  392. header.frame_ctl = cpu_to_le16(fc);
  393. if (ieee->config &
  394. (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
  395. skb_put(skb_frag, 4);
  396. txb->rts_included = 1;
  397. i = 1;
  398. } else
  399. i = 0;
  400. for (; i < nr_frags; i++) {
  401. skb_frag = txb->fragments[i];
  402. if (host_encrypt || host_build_iv)
  403. skb_reserve(skb_frag,
  404. crypt->ops->extra_mpdu_prefix_len);
  405. frag_hdr =
  406. (struct ieee80211_hdr_3addrqos *)skb_put(skb_frag, hdr_len);
  407. memcpy(frag_hdr, &header, hdr_len);
  408. /* If this is not the last fragment, then add the MOREFRAGS
  409. * bit to the frame control */
  410. if (i != nr_frags - 1) {
  411. frag_hdr->frame_ctl =
  412. cpu_to_le16(fc | IEEE80211_FCTL_MOREFRAGS);
  413. bytes = bytes_per_frag;
  414. } else {
  415. /* The last fragment takes the remaining length */
  416. bytes = bytes_last_frag;
  417. }
  418. if (i == 0 && !snapped) {
  419. ieee80211_copy_snap(skb_put
  420. (skb_frag, SNAP_SIZE + sizeof(u16)),
  421. ether_type);
  422. bytes -= SNAP_SIZE + sizeof(u16);
  423. }
  424. memcpy(skb_put(skb_frag, bytes), skb->data, bytes);
  425. /* Advance the SKB... */
  426. skb_pull(skb, bytes);
  427. /* Encryption routine will move the header forward in order
  428. * to insert the IV between the header and the payload */
  429. if (host_encrypt)
  430. ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
  431. else if (host_build_iv) {
  432. atomic_inc(&crypt->refcnt);
  433. if (crypt->ops->build_iv)
  434. crypt->ops->build_iv(skb_frag, hdr_len,
  435. ieee->sec.keys[ieee->sec.active_key],
  436. ieee->sec.key_sizes[ieee->sec.active_key],
  437. crypt->priv);
  438. atomic_dec(&crypt->refcnt);
  439. }
  440. if (ieee->config &
  441. (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
  442. skb_put(skb_frag, 4);
  443. }
  444. success:
  445. spin_unlock_irqrestore(&ieee->lock, flags);
  446. dev_kfree_skb_any(skb);
  447. if (txb) {
  448. int ret = (*ieee->hard_start_xmit) (txb, dev, priority);
  449. if (ret == 0) {
  450. stats->tx_packets++;
  451. stats->tx_bytes += txb->payload_size;
  452. return 0;
  453. }
  454. ieee80211_txb_free(txb);
  455. }
  456. return 0;
  457. failed:
  458. spin_unlock_irqrestore(&ieee->lock, flags);
  459. netif_stop_queue(dev);
  460. stats->tx_errors++;
  461. return 1;
  462. }
  463. /* Incoming 802.11 strucure is converted to a TXB
  464. * a block of 802.11 fragment packets (stored as skbs) */
  465. int ieee80211_tx_frame(struct ieee80211_device *ieee,
  466. struct ieee80211_hdr *frame, int hdr_len, int total_len,
  467. int encrypt_mpdu)
  468. {
  469. struct ieee80211_txb *txb = NULL;
  470. unsigned long flags;
  471. struct net_device_stats *stats = &ieee->stats;
  472. struct sk_buff *skb_frag;
  473. int priority = -1;
  474. int fraglen = total_len;
  475. int headroom = ieee->tx_headroom;
  476. struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
  477. spin_lock_irqsave(&ieee->lock, flags);
  478. if (encrypt_mpdu && (!ieee->sec.encrypt || !crypt))
  479. encrypt_mpdu = 0;
  480. /* If there is no driver handler to take the TXB, dont' bother
  481. * creating it... */
  482. if (!ieee->hard_start_xmit) {
  483. printk(KERN_WARNING "%s: No xmit handler.\n", ieee->dev->name);
  484. goto success;
  485. }
  486. if (unlikely(total_len < 24)) {
  487. printk(KERN_WARNING "%s: skb too small (%d).\n",
  488. ieee->dev->name, total_len);
  489. goto success;
  490. }
  491. if (encrypt_mpdu) {
  492. frame->frame_ctl |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  493. fraglen += crypt->ops->extra_mpdu_prefix_len +
  494. crypt->ops->extra_mpdu_postfix_len;
  495. headroom += crypt->ops->extra_mpdu_prefix_len;
  496. }
  497. /* When we allocate the TXB we allocate enough space for the reserve
  498. * and full fragment bytes (bytes_per_frag doesn't include prefix,
  499. * postfix, header, FCS, etc.) */
  500. txb = ieee80211_alloc_txb(1, fraglen, headroom, GFP_ATOMIC);
  501. if (unlikely(!txb)) {
  502. printk(KERN_WARNING "%s: Could not allocate TXB\n",
  503. ieee->dev->name);
  504. goto failed;
  505. }
  506. txb->encrypted = 0;
  507. txb->payload_size = fraglen;
  508. skb_frag = txb->fragments[0];
  509. memcpy(skb_put(skb_frag, total_len), frame, total_len);
  510. if (ieee->config &
  511. (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
  512. skb_put(skb_frag, 4);
  513. /* To avoid overcomplicating things, we do the corner-case frame
  514. * encryption in software. The only real situation where encryption is
  515. * needed here is during software-based shared key authentication. */
  516. if (encrypt_mpdu)
  517. ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
  518. success:
  519. spin_unlock_irqrestore(&ieee->lock, flags);
  520. if (txb) {
  521. if ((*ieee->hard_start_xmit) (txb, ieee->dev, priority) == 0) {
  522. stats->tx_packets++;
  523. stats->tx_bytes += txb->payload_size;
  524. return 0;
  525. }
  526. ieee80211_txb_free(txb);
  527. }
  528. return 0;
  529. failed:
  530. spin_unlock_irqrestore(&ieee->lock, flags);
  531. stats->tx_errors++;
  532. return 1;
  533. }
  534. EXPORT_SYMBOL(ieee80211_tx_frame);
  535. EXPORT_SYMBOL(ieee80211_txb_free);