blob: 078a010f39a0835c765d5e706f7f53600aa8d30a [file] [log] [blame]
Adrian Bunk5fad5a22006-01-14 03:09:34 +01001#include "hostap_80211.h"
2#include "hostap_common.h"
3#include "hostap_wlan.h"
4#include "hostap.h"
5#include "hostap_ap.h"
6
7/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
8/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
9static unsigned char rfc1042_header[] =
10{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
11/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
12static unsigned char bridge_tunnel_header[] =
13{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
14/* No encapsulation header if EtherType < 0x600 (=length) */
15
Jouni Malinenff1d2762005-05-12 22:54:16 -040016void hostap_dump_tx_80211(const char *name, struct sk_buff *skb)
17{
James Ketrenosd0416742005-09-21 12:23:49 -050018 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -040019 u16 fc;
20
James Ketrenosd0416742005-09-21 12:23:49 -050021 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -040022
23 printk(KERN_DEBUG "%s: TX len=%d jiffies=%ld\n",
24 name, skb->len, jiffies);
25
26 if (skb->len < 2)
27 return;
28
Jouni Malinenc0f72ca2005-08-14 19:08:43 -070029 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenff1d2762005-05-12 22:54:16 -040030 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s",
Jouni Malinen4339d322005-08-14 19:08:44 -070031 fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4,
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -070032 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
33 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
Jouni Malinenff1d2762005-05-12 22:54:16 -040034
35 if (skb->len < IEEE80211_DATA_HDR3_LEN) {
36 printk("\n");
37 return;
38 }
39
40 printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
Jouni Malinenc0f72ca2005-08-14 19:08:43 -070041 le16_to_cpu(hdr->seq_ctl));
Jouni Malinenff1d2762005-05-12 22:54:16 -040042
Johannes Berge1749612008-10-27 15:59:26 -070043 printk(KERN_DEBUG " A1=%pM", hdr->addr1);
44 printk(" A2=%pM", hdr->addr2);
45 printk(" A3=%pM", hdr->addr3);
Jouni Malinenff1d2762005-05-12 22:54:16 -040046 if (skb->len >= 30)
Johannes Berge1749612008-10-27 15:59:26 -070047 printk(" A4=%pM", hdr->addr4);
Jouni Malinenff1d2762005-05-12 22:54:16 -040048 printk("\n");
49}
50
51
52/* hard_start_xmit function for data interfaces (wlan#, wlan#wds#, wlan#sta)
53 * Convert Ethernet header into a suitable IEEE 802.11 header depending on
54 * device configuration. */
55int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
56{
57 struct hostap_interface *iface;
58 local_info_t *local;
59 int need_headroom, need_tailroom = 0;
James Ketrenosd0416742005-09-21 12:23:49 -050060 struct ieee80211_hdr_4addr hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -040061 u16 fc, ethertype = 0;
62 enum {
63 WDS_NO = 0, WDS_OWN_FRAME, WDS_COMPLIANT_FRAME
64 } use_wds = WDS_NO;
65 u8 *encaps_data;
66 int hdr_len, encaps_len, skip_header_bytes;
67 int to_assoc_ap = 0;
68 struct hostap_skb_tx_data *meta;
69
70 iface = netdev_priv(dev);
71 local = iface->local;
72
73 if (skb->len < ETH_HLEN) {
74 printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb "
75 "(len=%d)\n", dev->name, skb->len);
76 kfree_skb(skb);
77 return 0;
78 }
79
80 if (local->ddev != dev) {
81 use_wds = (local->iw_mode == IW_MODE_MASTER &&
82 !(local->wds_type & HOSTAP_WDS_STANDARD_FRAME)) ?
83 WDS_OWN_FRAME : WDS_COMPLIANT_FRAME;
84 if (dev == local->stadev) {
85 to_assoc_ap = 1;
86 use_wds = WDS_NO;
87 } else if (dev == local->apdev) {
88 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
89 "AP device with Ethernet net dev\n", dev->name);
90 kfree_skb(skb);
91 return 0;
92 }
93 } else {
94 if (local->iw_mode == IW_MODE_REPEAT) {
95 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
96 "non-WDS link in Repeater mode\n", dev->name);
97 kfree_skb(skb);
98 return 0;
99 } else if (local->iw_mode == IW_MODE_INFRA &&
100 (local->wds_type & HOSTAP_WDS_AP_CLIENT) &&
101 memcmp(skb->data + ETH_ALEN, dev->dev_addr,
102 ETH_ALEN) != 0) {
103 /* AP client mode: send frames with foreign src addr
104 * using 4-addr WDS frames */
105 use_wds = WDS_COMPLIANT_FRAME;
106 }
107 }
108
109 /* Incoming skb->data: dst_addr[6], src_addr[6], proto[2], payload
110 * ==>
111 * Prism2 TX frame with 802.11 header:
112 * txdesc (address order depending on used mode; includes dst_addr and
113 * src_addr), possible encapsulation (RFC1042/Bridge-Tunnel;
114 * proto[2], payload {, possible addr4[6]} */
115
116 ethertype = (skb->data[12] << 8) | skb->data[13];
117
118 memset(&hdr, 0, sizeof(hdr));
119
120 /* Length of data after IEEE 802.11 header */
121 encaps_data = NULL;
122 encaps_len = 0;
123 skip_header_bytes = ETH_HLEN;
124 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
125 encaps_data = bridge_tunnel_header;
126 encaps_len = sizeof(bridge_tunnel_header);
127 skip_header_bytes -= 2;
128 } else if (ethertype >= 0x600) {
129 encaps_data = rfc1042_header;
130 encaps_len = sizeof(rfc1042_header);
131 skip_header_bytes -= 2;
132 }
133
Jouni Malinen4339d322005-08-14 19:08:44 -0700134 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400135 hdr_len = IEEE80211_DATA_HDR3_LEN;
136
137 if (use_wds != WDS_NO) {
138 /* Note! Prism2 station firmware has problems with sending real
139 * 802.11 frames with four addresses; until these problems can
140 * be fixed or worked around, 4-addr frames needed for WDS are
141 * using incompatible format: FromDS flag is not set and the
142 * fourth address is added after the frame payload; it is
143 * assumed, that the receiving station knows how to handle this
144 * frame format */
145
146 if (use_wds == WDS_COMPLIANT_FRAME) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700147 fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400148 /* From&To DS: Addr1 = RA, Addr2 = TA, Addr3 = DA,
149 * Addr4 = SA */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300150 skb_copy_from_linear_data_offset(skb, ETH_ALEN,
151 &hdr.addr4, ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400152 hdr_len += ETH_ALEN;
153 } else {
154 /* bogus 4-addr format to workaround Prism2 station
155 * f/w bug */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700156 fc |= IEEE80211_FCTL_TODS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400157 /* From DS: Addr1 = DA (used as RA),
158 * Addr2 = BSSID (used as TA), Addr3 = SA (used as DA),
159 */
160
161 /* SA from skb->data + ETH_ALEN will be added after
162 * frame payload; use hdr.addr4 as a temporary buffer
163 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300164 skb_copy_from_linear_data_offset(skb, ETH_ALEN,
165 &hdr.addr4, ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400166 need_tailroom += ETH_ALEN;
167 }
168
169 /* send broadcast and multicast frames to broadcast RA, if
170 * configured; otherwise, use unicast RA of the WDS link */
171 if ((local->wds_type & HOSTAP_WDS_BROADCAST_RA) &&
172 skb->data[0] & 0x01)
173 memset(&hdr.addr1, 0xff, ETH_ALEN);
174 else if (iface->type == HOSTAP_INTERFACE_WDS)
175 memcpy(&hdr.addr1, iface->u.wds.remote_addr,
176 ETH_ALEN);
177 else
178 memcpy(&hdr.addr1, local->bssid, ETH_ALEN);
179 memcpy(&hdr.addr2, dev->dev_addr, ETH_ALEN);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300180 skb_copy_from_linear_data(skb, &hdr.addr3, ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400181 } else if (local->iw_mode == IW_MODE_MASTER && !to_assoc_ap) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700182 fc |= IEEE80211_FCTL_FROMDS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400183 /* From DS: Addr1 = DA, Addr2 = BSSID, Addr3 = SA */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300184 skb_copy_from_linear_data(skb, &hdr.addr1, ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400185 memcpy(&hdr.addr2, dev->dev_addr, ETH_ALEN);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300186 skb_copy_from_linear_data_offset(skb, ETH_ALEN, &hdr.addr3,
187 ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400188 } else if (local->iw_mode == IW_MODE_INFRA || to_assoc_ap) {
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700189 fc |= IEEE80211_FCTL_TODS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400190 /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */
191 memcpy(&hdr.addr1, to_assoc_ap ?
192 local->assoc_ap_addr : local->bssid, ETH_ALEN);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300193 skb_copy_from_linear_data_offset(skb, ETH_ALEN, &hdr.addr2,
194 ETH_ALEN);
195 skb_copy_from_linear_data(skb, &hdr.addr3, ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400196 } else if (local->iw_mode == IW_MODE_ADHOC) {
197 /* not From/To DS: Addr1 = DA, Addr2 = SA, Addr3 = BSSID */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300198 skb_copy_from_linear_data(skb, &hdr.addr1, ETH_ALEN);
199 skb_copy_from_linear_data_offset(skb, ETH_ALEN, &hdr.addr2,
200 ETH_ALEN);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400201 memcpy(&hdr.addr3, local->bssid, ETH_ALEN);
202 }
203
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700204 hdr.frame_ctl = cpu_to_le16(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400205
206 skb_pull(skb, skip_header_bytes);
207 need_headroom = local->func->need_tx_headroom + hdr_len + encaps_len;
208 if (skb_tailroom(skb) < need_tailroom) {
209 skb = skb_unshare(skb, GFP_ATOMIC);
210 if (skb == NULL) {
211 iface->stats.tx_dropped++;
212 return 0;
213 }
214 if (pskb_expand_head(skb, need_headroom, need_tailroom,
215 GFP_ATOMIC)) {
216 kfree_skb(skb);
217 iface->stats.tx_dropped++;
218 return 0;
219 }
220 } else if (skb_headroom(skb) < need_headroom) {
221 struct sk_buff *tmp = skb;
222 skb = skb_realloc_headroom(skb, need_headroom);
223 kfree_skb(tmp);
224 if (skb == NULL) {
225 iface->stats.tx_dropped++;
226 return 0;
227 }
228 } else {
229 skb = skb_unshare(skb, GFP_ATOMIC);
230 if (skb == NULL) {
231 iface->stats.tx_dropped++;
232 return 0;
233 }
234 }
235
236 if (encaps_data)
237 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
238 memcpy(skb_push(skb, hdr_len), &hdr, hdr_len);
239 if (use_wds == WDS_OWN_FRAME) {
240 memcpy(skb_put(skb, ETH_ALEN), &hdr.addr4, ETH_ALEN);
241 }
242
243 iface->stats.tx_packets++;
244 iface->stats.tx_bytes += skb->len;
245
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700246 skb_reset_mac_header(skb);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400247 meta = (struct hostap_skb_tx_data *) skb->cb;
248 memset(meta, 0, sizeof(*meta));
249 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
Jouni Malinen5bee7202005-08-14 19:08:39 -0700250 if (use_wds)
251 meta->flags |= HOSTAP_TX_FLAGS_WDS;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400252 meta->ethertype = ethertype;
253 meta->iface = iface;
254
255 /* Send IEEE 802.11 encapsulated frame using the master radio device */
256 skb->dev = local->dev;
257 dev_queue_xmit(skb);
258 return 0;
259}
260
261
262/* hard_start_xmit function for hostapd wlan#ap interfaces */
263int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
264{
265 struct hostap_interface *iface;
266 local_info_t *local;
267 struct hostap_skb_tx_data *meta;
James Ketrenosd0416742005-09-21 12:23:49 -0500268 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400269 u16 fc;
270
271 iface = netdev_priv(dev);
272 local = iface->local;
273
274 if (skb->len < 10) {
275 printk(KERN_DEBUG "%s: hostap_mgmt_start_xmit: short skb "
276 "(len=%d)\n", dev->name, skb->len);
277 kfree_skb(skb);
278 return 0;
279 }
280
281 iface->stats.tx_packets++;
282 iface->stats.tx_bytes += skb->len;
283
284 meta = (struct hostap_skb_tx_data *) skb->cb;
285 memset(meta, 0, sizeof(*meta));
286 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
287 meta->iface = iface;
288
289 if (skb->len >= IEEE80211_DATA_HDR3_LEN + sizeof(rfc1042_header) + 2) {
James Ketrenosd0416742005-09-21 12:23:49 -0500290 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700291 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinen4339d322005-08-14 19:08:44 -0700292 if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA &&
293 WLAN_FC_GET_STYPE(fc) == IEEE80211_STYPE_DATA) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400294 u8 *pos = &skb->data[IEEE80211_DATA_HDR3_LEN +
295 sizeof(rfc1042_header)];
296 meta->ethertype = (pos[0] << 8) | pos[1];
297 }
298 }
299
300 /* Send IEEE 802.11 encapsulated frame using the master radio device */
301 skb->dev = local->dev;
302 dev_queue_xmit(skb);
303 return 0;
304}
305
306
307/* Called only from software IRQ */
Jouni Malinen79058ac2006-03-24 21:24:54 -0800308static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
John W. Linville274bfb82008-10-29 11:35:05 -0400309 struct lib80211_crypt_data *crypt)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400310{
311 struct hostap_interface *iface;
312 local_info_t *local;
James Ketrenosd0416742005-09-21 12:23:49 -0500313 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400314 u16 fc;
Brandon Craig Rhodesd7ea3be2007-05-28 09:38:46 -0700315 int prefix_len, postfix_len, hdr_len, res;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400316
317 iface = netdev_priv(skb->dev);
318 local = iface->local;
319
320 if (skb->len < IEEE80211_DATA_HDR3_LEN) {
321 kfree_skb(skb);
322 return NULL;
323 }
324
325 if (local->tkip_countermeasures &&
Jouni Malinen79058ac2006-03-24 21:24:54 -0800326 strcmp(crypt->ops->name, "TKIP") == 0) {
James Ketrenosd0416742005-09-21 12:23:49 -0500327 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400328 if (net_ratelimit()) {
329 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
Johannes Berge1749612008-10-27 15:59:26 -0700330 "TX packet to %pM\n",
331 local->dev->name, hdr->addr1);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400332 }
333 kfree_skb(skb);
334 return NULL;
335 }
336
337 skb = skb_unshare(skb, GFP_ATOMIC);
338 if (skb == NULL)
339 return NULL;
340
Brandon Craig Rhodesd7ea3be2007-05-28 09:38:46 -0700341 prefix_len = crypt->ops->extra_mpdu_prefix_len +
342 crypt->ops->extra_msdu_prefix_len;
343 postfix_len = crypt->ops->extra_mpdu_postfix_len +
344 crypt->ops->extra_msdu_postfix_len;
345 if ((skb_headroom(skb) < prefix_len ||
346 skb_tailroom(skb) < postfix_len) &&
347 pskb_expand_head(skb, prefix_len, postfix_len, GFP_ATOMIC)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400348 kfree_skb(skb);
349 return NULL;
350 }
351
James Ketrenosd0416742005-09-21 12:23:49 -0500352 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700353 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400354 hdr_len = hostap_80211_get_hdrlen(fc);
355
356 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
357 * call both MSDU and MPDU encryption functions from here. */
358 atomic_inc(&crypt->refcnt);
359 res = 0;
360 if (crypt->ops->encrypt_msdu)
361 res = crypt->ops->encrypt_msdu(skb, hdr_len, crypt->priv);
362 if (res == 0 && crypt->ops->encrypt_mpdu)
363 res = crypt->ops->encrypt_mpdu(skb, hdr_len, crypt->priv);
364 atomic_dec(&crypt->refcnt);
365 if (res < 0) {
366 kfree_skb(skb);
367 return NULL;
368 }
369
370 return skb;
371}
372
373
374/* hard_start_xmit function for master radio interface wifi#.
375 * AP processing (TX rate control, power save buffering, etc.).
376 * Use hardware TX function to send the frame. */
377int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
378{
379 struct hostap_interface *iface;
380 local_info_t *local;
381 int ret = 1;
382 u16 fc;
383 struct hostap_tx_data tx;
384 ap_tx_ret tx_ret;
385 struct hostap_skb_tx_data *meta;
386 int no_encrypt = 0;
James Ketrenosd0416742005-09-21 12:23:49 -0500387 struct ieee80211_hdr_4addr *hdr;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400388
389 iface = netdev_priv(dev);
390 local = iface->local;
391
392 tx.skb = skb;
393 tx.sta_ptr = NULL;
394
395 meta = (struct hostap_skb_tx_data *) skb->cb;
396 if (meta->magic != HOSTAP_SKB_TX_DATA_MAGIC) {
397 printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, "
398 "expected 0x%08x)\n",
399 dev->name, meta->magic, HOSTAP_SKB_TX_DATA_MAGIC);
400 ret = 0;
401 iface->stats.tx_dropped++;
402 goto fail;
403 }
404
405 if (local->host_encrypt) {
406 /* Set crypt to default algorithm and key; will be replaced in
407 * AP code if STA has own alg/key */
John W. Linville274bfb82008-10-29 11:35:05 -0400408 tx.crypt = local->crypt_info.crypt[local->crypt_info.tx_keyidx];
Jouni Malinenff1d2762005-05-12 22:54:16 -0400409 tx.host_encrypt = 1;
410 } else {
411 tx.crypt = NULL;
412 tx.host_encrypt = 0;
413 }
414
415 if (skb->len < 24) {
416 printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb "
417 "(len=%d)\n", dev->name, skb->len);
418 ret = 0;
419 iface->stats.tx_dropped++;
420 goto fail;
421 }
422
423 /* FIX (?):
424 * Wi-Fi 802.11b test plan suggests that AP should ignore power save
425 * bit in authentication and (re)association frames and assume tha
426 * STA remains awake for the response. */
427 tx_ret = hostap_handle_sta_tx(local, &tx);
428 skb = tx.skb;
429 meta = (struct hostap_skb_tx_data *) skb->cb;
James Ketrenosd0416742005-09-21 12:23:49 -0500430 hdr = (struct ieee80211_hdr_4addr *) skb->data;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700431 fc = le16_to_cpu(hdr->frame_ctl);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400432 switch (tx_ret) {
433 case AP_TX_CONTINUE:
434 break;
435 case AP_TX_CONTINUE_NOT_AUTHORIZED:
436 if (local->ieee_802_1x &&
Jouni Malinen4339d322005-08-14 19:08:44 -0700437 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA &&
Jouni Malinen5bee7202005-08-14 19:08:39 -0700438 meta->ethertype != ETH_P_PAE &&
439 !(meta->flags & HOSTAP_TX_FLAGS_WDS)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400440 printk(KERN_DEBUG "%s: dropped frame to unauthorized "
441 "port (IEEE 802.1X): ethertype=0x%04x\n",
442 dev->name, meta->ethertype);
443 hostap_dump_tx_80211(dev->name, skb);
444
445 ret = 0; /* drop packet */
446 iface->stats.tx_dropped++;
447 goto fail;
448 }
449 break;
450 case AP_TX_DROP:
451 ret = 0; /* drop packet */
452 iface->stats.tx_dropped++;
453 goto fail;
454 case AP_TX_RETRY:
455 goto fail;
456 case AP_TX_BUFFERED:
457 /* do not free skb here, it will be freed when the
458 * buffered frame is sent/timed out */
459 ret = 0;
460 goto tx_exit;
461 }
462
463 /* Request TX callback if protocol version is 2 in 802.11 header;
464 * this version 2 is a special case used between hostapd and kernel
465 * driver */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700466 if (((fc & IEEE80211_FCTL_VERS) == BIT(1)) &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400467 local->ap && local->ap->tx_callback_idx && meta->tx_cb_idx == 0) {
468 meta->tx_cb_idx = local->ap->tx_callback_idx;
469
470 /* remove special version from the frame header */
Jouni Malinenb2f4a2e2005-08-14 21:00:01 -0700471 fc &= ~IEEE80211_FCTL_VERS;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700472 hdr->frame_ctl = cpu_to_le16(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400473 }
474
Jouni Malinen4339d322005-08-14 19:08:44 -0700475 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_DATA) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400476 no_encrypt = 1;
477 tx.crypt = NULL;
478 }
479
480 if (local->ieee_802_1x && meta->ethertype == ETH_P_PAE && tx.crypt &&
Jouni Malinencfa146e2006-03-24 21:24:55 -0800481 !(fc & IEEE80211_FCTL_PROTECTED)) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400482 no_encrypt = 1;
483 PDEBUG(DEBUG_EXTRA2, "%s: TX: IEEE 802.1X - passing "
484 "unencrypted EAPOL frame\n", dev->name);
485 tx.crypt = NULL; /* no encryption for IEEE 802.1X frames */
486 }
487
488 if (tx.crypt && (!tx.crypt->ops || !tx.crypt->ops->encrypt_mpdu))
489 tx.crypt = NULL;
John W. Linville274bfb82008-10-29 11:35:05 -0400490 else if ((tx.crypt ||
491 local->crypt_info.crypt[local->crypt_info.tx_keyidx]) &&
492 !no_encrypt) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400493 /* Add ISWEP flag both for firmware and host based encryption
494 */
Jeff Garzik831a1792005-08-25 20:59:10 -0400495 fc |= IEEE80211_FCTL_PROTECTED;
Jouni Malinenc0f72ca2005-08-14 19:08:43 -0700496 hdr->frame_ctl = cpu_to_le16(fc);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400497 } else if (local->drop_unencrypted &&
Jouni Malinen4339d322005-08-14 19:08:44 -0700498 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA &&
Jouni Malinenff1d2762005-05-12 22:54:16 -0400499 meta->ethertype != ETH_P_PAE) {
500 if (net_ratelimit()) {
501 printk(KERN_DEBUG "%s: dropped unencrypted TX data "
502 "frame (drop_unencrypted=1)\n", dev->name);
503 }
504 iface->stats.tx_dropped++;
505 ret = 0;
506 goto fail;
507 }
508
509 if (tx.crypt) {
510 skb = hostap_tx_encrypt(skb, tx.crypt);
511 if (skb == NULL) {
512 printk(KERN_DEBUG "%s: TX - encryption failed\n",
513 dev->name);
514 ret = 0;
515 goto fail;
516 }
517 meta = (struct hostap_skb_tx_data *) skb->cb;
518 if (meta->magic != HOSTAP_SKB_TX_DATA_MAGIC) {
519 printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, "
520 "expected 0x%08x) after hostap_tx_encrypt\n",
521 dev->name, meta->magic,
522 HOSTAP_SKB_TX_DATA_MAGIC);
523 ret = 0;
524 iface->stats.tx_dropped++;
525 goto fail;
526 }
527 }
528
529 if (local->func->tx == NULL || local->func->tx(skb, dev)) {
530 ret = 0;
531 iface->stats.tx_dropped++;
532 } else {
533 ret = 0;
534 iface->stats.tx_packets++;
535 iface->stats.tx_bytes += skb->len;
536 }
537
538 fail:
539 if (!ret && skb)
540 dev_kfree_skb(skb);
541 tx_exit:
542 if (tx.sta_ptr)
543 hostap_handle_sta_release(tx.sta_ptr);
544 return ret;
545}
546
547
Jouni Malinenff1d2762005-05-12 22:54:16 -0400548EXPORT_SYMBOL(hostap_master_start_xmit);