Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 1 | #include <linux/slab.h> |
| 2 | |
Adrian Bunk | 5fad5a2 | 2006-01-14 03:09:34 +0100 | [diff] [blame] | 3 | #include "hostap_80211.h" |
| 4 | #include "hostap_common.h" |
| 5 | #include "hostap_wlan.h" |
| 6 | #include "hostap.h" |
| 7 | #include "hostap_ap.h" |
| 8 | |
| 9 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 10 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
| 11 | static unsigned char rfc1042_header[] = |
| 12 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 13 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
| 14 | static unsigned char bridge_tunnel_header[] = |
| 15 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 16 | /* No encapsulation header if EtherType < 0x600 (=length) */ |
| 17 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 18 | void hostap_dump_tx_80211(const char *name, struct sk_buff *skb) |
| 19 | { |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 20 | struct ieee80211_hdr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 21 | u16 fc; |
| 22 | |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 23 | hdr = (struct ieee80211_hdr *) skb->data; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 24 | |
| 25 | printk(KERN_DEBUG "%s: TX len=%d jiffies=%ld\n", |
| 26 | name, skb->len, jiffies); |
| 27 | |
| 28 | if (skb->len < 2) |
| 29 | return; |
| 30 | |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 31 | fc = le16_to_cpu(hdr->frame_control); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 32 | printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s", |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 33 | fc, (fc & IEEE80211_FCTL_FTYPE) >> 2, |
| 34 | (fc & IEEE80211_FCTL_STYPE) >> 4, |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 35 | fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "", |
| 36 | fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : ""); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 37 | |
| 38 | if (skb->len < IEEE80211_DATA_HDR3_LEN) { |
| 39 | printk("\n"); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id), |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 44 | le16_to_cpu(hdr->seq_ctrl)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 45 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 46 | printk(KERN_DEBUG " A1=%pM", hdr->addr1); |
| 47 | printk(" A2=%pM", hdr->addr2); |
| 48 | printk(" A3=%pM", hdr->addr3); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 49 | if (skb->len >= 30) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 50 | printk(" A4=%pM", hdr->addr4); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 51 | printk("\n"); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /* hard_start_xmit function for data interfaces (wlan#, wlan#wds#, wlan#sta) |
| 56 | * Convert Ethernet header into a suitable IEEE 802.11 header depending on |
| 57 | * device configuration. */ |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 58 | netdev_tx_t hostap_data_start_xmit(struct sk_buff *skb, |
| 59 | struct net_device *dev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 60 | { |
| 61 | struct hostap_interface *iface; |
| 62 | local_info_t *local; |
| 63 | int need_headroom, need_tailroom = 0; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 64 | struct ieee80211_hdr hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 65 | u16 fc, ethertype = 0; |
| 66 | enum { |
| 67 | WDS_NO = 0, WDS_OWN_FRAME, WDS_COMPLIANT_FRAME |
| 68 | } use_wds = WDS_NO; |
| 69 | u8 *encaps_data; |
| 70 | int hdr_len, encaps_len, skip_header_bytes; |
| 71 | int to_assoc_ap = 0; |
| 72 | struct hostap_skb_tx_data *meta; |
| 73 | |
| 74 | iface = netdev_priv(dev); |
| 75 | local = iface->local; |
| 76 | |
| 77 | if (skb->len < ETH_HLEN) { |
| 78 | printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb " |
| 79 | "(len=%d)\n", dev->name, skb->len); |
| 80 | kfree_skb(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 81 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (local->ddev != dev) { |
| 85 | use_wds = (local->iw_mode == IW_MODE_MASTER && |
| 86 | !(local->wds_type & HOSTAP_WDS_STANDARD_FRAME)) ? |
| 87 | WDS_OWN_FRAME : WDS_COMPLIANT_FRAME; |
| 88 | if (dev == local->stadev) { |
| 89 | to_assoc_ap = 1; |
| 90 | use_wds = WDS_NO; |
| 91 | } else if (dev == local->apdev) { |
| 92 | printk(KERN_DEBUG "%s: prism2_tx: trying to use " |
| 93 | "AP device with Ethernet net dev\n", dev->name); |
| 94 | kfree_skb(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 95 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 96 | } |
| 97 | } else { |
| 98 | if (local->iw_mode == IW_MODE_REPEAT) { |
| 99 | printk(KERN_DEBUG "%s: prism2_tx: trying to use " |
| 100 | "non-WDS link in Repeater mode\n", dev->name); |
| 101 | kfree_skb(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 102 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 103 | } else if (local->iw_mode == IW_MODE_INFRA && |
| 104 | (local->wds_type & HOSTAP_WDS_AP_CLIENT) && |
| 105 | memcmp(skb->data + ETH_ALEN, dev->dev_addr, |
| 106 | ETH_ALEN) != 0) { |
| 107 | /* AP client mode: send frames with foreign src addr |
| 108 | * using 4-addr WDS frames */ |
| 109 | use_wds = WDS_COMPLIANT_FRAME; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* Incoming skb->data: dst_addr[6], src_addr[6], proto[2], payload |
| 114 | * ==> |
| 115 | * Prism2 TX frame with 802.11 header: |
| 116 | * txdesc (address order depending on used mode; includes dst_addr and |
| 117 | * src_addr), possible encapsulation (RFC1042/Bridge-Tunnel; |
| 118 | * proto[2], payload {, possible addr4[6]} */ |
| 119 | |
| 120 | ethertype = (skb->data[12] << 8) | skb->data[13]; |
| 121 | |
| 122 | memset(&hdr, 0, sizeof(hdr)); |
| 123 | |
| 124 | /* Length of data after IEEE 802.11 header */ |
| 125 | encaps_data = NULL; |
| 126 | encaps_len = 0; |
| 127 | skip_header_bytes = ETH_HLEN; |
| 128 | if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { |
| 129 | encaps_data = bridge_tunnel_header; |
| 130 | encaps_len = sizeof(bridge_tunnel_header); |
| 131 | skip_header_bytes -= 2; |
| 132 | } else if (ethertype >= 0x600) { |
| 133 | encaps_data = rfc1042_header; |
| 134 | encaps_len = sizeof(rfc1042_header); |
| 135 | skip_header_bytes -= 2; |
| 136 | } |
| 137 | |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 138 | fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 139 | hdr_len = IEEE80211_DATA_HDR3_LEN; |
| 140 | |
| 141 | if (use_wds != WDS_NO) { |
| 142 | /* Note! Prism2 station firmware has problems with sending real |
| 143 | * 802.11 frames with four addresses; until these problems can |
| 144 | * be fixed or worked around, 4-addr frames needed for WDS are |
| 145 | * using incompatible format: FromDS flag is not set and the |
| 146 | * fourth address is added after the frame payload; it is |
| 147 | * assumed, that the receiving station knows how to handle this |
| 148 | * frame format */ |
| 149 | |
| 150 | if (use_wds == WDS_COMPLIANT_FRAME) { |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 151 | fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 152 | /* From&To DS: Addr1 = RA, Addr2 = TA, Addr3 = DA, |
| 153 | * Addr4 = SA */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 154 | skb_copy_from_linear_data_offset(skb, ETH_ALEN, |
| 155 | &hdr.addr4, ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 156 | hdr_len += ETH_ALEN; |
| 157 | } else { |
| 158 | /* bogus 4-addr format to workaround Prism2 station |
| 159 | * f/w bug */ |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 160 | fc |= IEEE80211_FCTL_TODS; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 161 | /* From DS: Addr1 = DA (used as RA), |
| 162 | * Addr2 = BSSID (used as TA), Addr3 = SA (used as DA), |
| 163 | */ |
| 164 | |
| 165 | /* SA from skb->data + ETH_ALEN will be added after |
| 166 | * frame payload; use hdr.addr4 as a temporary buffer |
| 167 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 168 | skb_copy_from_linear_data_offset(skb, ETH_ALEN, |
| 169 | &hdr.addr4, ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 170 | need_tailroom += ETH_ALEN; |
| 171 | } |
| 172 | |
| 173 | /* send broadcast and multicast frames to broadcast RA, if |
| 174 | * configured; otherwise, use unicast RA of the WDS link */ |
| 175 | if ((local->wds_type & HOSTAP_WDS_BROADCAST_RA) && |
| 176 | skb->data[0] & 0x01) |
| 177 | memset(&hdr.addr1, 0xff, ETH_ALEN); |
| 178 | else if (iface->type == HOSTAP_INTERFACE_WDS) |
| 179 | memcpy(&hdr.addr1, iface->u.wds.remote_addr, |
| 180 | ETH_ALEN); |
| 181 | else |
| 182 | memcpy(&hdr.addr1, local->bssid, ETH_ALEN); |
| 183 | memcpy(&hdr.addr2, dev->dev_addr, ETH_ALEN); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 184 | skb_copy_from_linear_data(skb, &hdr.addr3, ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 185 | } else if (local->iw_mode == IW_MODE_MASTER && !to_assoc_ap) { |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 186 | fc |= IEEE80211_FCTL_FROMDS; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 187 | /* From DS: Addr1 = DA, Addr2 = BSSID, Addr3 = SA */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 188 | skb_copy_from_linear_data(skb, &hdr.addr1, ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 189 | memcpy(&hdr.addr2, dev->dev_addr, ETH_ALEN); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 190 | skb_copy_from_linear_data_offset(skb, ETH_ALEN, &hdr.addr3, |
| 191 | ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 192 | } else if (local->iw_mode == IW_MODE_INFRA || to_assoc_ap) { |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 193 | fc |= IEEE80211_FCTL_TODS; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 194 | /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */ |
| 195 | memcpy(&hdr.addr1, to_assoc_ap ? |
| 196 | local->assoc_ap_addr : local->bssid, ETH_ALEN); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 197 | skb_copy_from_linear_data_offset(skb, ETH_ALEN, &hdr.addr2, |
| 198 | ETH_ALEN); |
| 199 | skb_copy_from_linear_data(skb, &hdr.addr3, ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 200 | } else if (local->iw_mode == IW_MODE_ADHOC) { |
| 201 | /* not From/To DS: Addr1 = DA, Addr2 = SA, Addr3 = BSSID */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 202 | skb_copy_from_linear_data(skb, &hdr.addr1, ETH_ALEN); |
| 203 | skb_copy_from_linear_data_offset(skb, ETH_ALEN, &hdr.addr2, |
| 204 | ETH_ALEN); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 205 | memcpy(&hdr.addr3, local->bssid, ETH_ALEN); |
| 206 | } |
| 207 | |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 208 | hdr.frame_control = cpu_to_le16(fc); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 209 | |
| 210 | skb_pull(skb, skip_header_bytes); |
| 211 | need_headroom = local->func->need_tx_headroom + hdr_len + encaps_len; |
| 212 | if (skb_tailroom(skb) < need_tailroom) { |
| 213 | skb = skb_unshare(skb, GFP_ATOMIC); |
| 214 | if (skb == NULL) { |
| 215 | iface->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 216 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 217 | } |
| 218 | if (pskb_expand_head(skb, need_headroom, need_tailroom, |
| 219 | GFP_ATOMIC)) { |
| 220 | kfree_skb(skb); |
| 221 | iface->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 222 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 223 | } |
| 224 | } else if (skb_headroom(skb) < need_headroom) { |
| 225 | struct sk_buff *tmp = skb; |
| 226 | skb = skb_realloc_headroom(skb, need_headroom); |
| 227 | kfree_skb(tmp); |
| 228 | if (skb == NULL) { |
| 229 | iface->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 230 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 231 | } |
| 232 | } else { |
| 233 | skb = skb_unshare(skb, GFP_ATOMIC); |
| 234 | if (skb == NULL) { |
| 235 | iface->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 236 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | if (encaps_data) |
| 241 | memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); |
| 242 | memcpy(skb_push(skb, hdr_len), &hdr, hdr_len); |
| 243 | if (use_wds == WDS_OWN_FRAME) { |
| 244 | memcpy(skb_put(skb, ETH_ALEN), &hdr.addr4, ETH_ALEN); |
| 245 | } |
| 246 | |
| 247 | iface->stats.tx_packets++; |
| 248 | iface->stats.tx_bytes += skb->len; |
| 249 | |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 250 | skb_reset_mac_header(skb); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 251 | meta = (struct hostap_skb_tx_data *) skb->cb; |
| 252 | memset(meta, 0, sizeof(*meta)); |
| 253 | meta->magic = HOSTAP_SKB_TX_DATA_MAGIC; |
Jouni Malinen | 5bee720 | 2005-08-14 19:08:39 -0700 | [diff] [blame] | 254 | if (use_wds) |
| 255 | meta->flags |= HOSTAP_TX_FLAGS_WDS; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 256 | meta->ethertype = ethertype; |
| 257 | meta->iface = iface; |
| 258 | |
| 259 | /* Send IEEE 802.11 encapsulated frame using the master radio device */ |
| 260 | skb->dev = local->dev; |
| 261 | dev_queue_xmit(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 262 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
| 266 | /* hard_start_xmit function for hostapd wlan#ap interfaces */ |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 267 | netdev_tx_t hostap_mgmt_start_xmit(struct sk_buff *skb, |
| 268 | struct net_device *dev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 269 | { |
| 270 | struct hostap_interface *iface; |
| 271 | local_info_t *local; |
| 272 | struct hostap_skb_tx_data *meta; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 273 | struct ieee80211_hdr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 274 | u16 fc; |
| 275 | |
| 276 | iface = netdev_priv(dev); |
| 277 | local = iface->local; |
| 278 | |
| 279 | if (skb->len < 10) { |
| 280 | printk(KERN_DEBUG "%s: hostap_mgmt_start_xmit: short skb " |
| 281 | "(len=%d)\n", dev->name, skb->len); |
| 282 | kfree_skb(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 283 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | iface->stats.tx_packets++; |
| 287 | iface->stats.tx_bytes += skb->len; |
| 288 | |
| 289 | meta = (struct hostap_skb_tx_data *) skb->cb; |
| 290 | memset(meta, 0, sizeof(*meta)); |
| 291 | meta->magic = HOSTAP_SKB_TX_DATA_MAGIC; |
| 292 | meta->iface = iface; |
| 293 | |
| 294 | if (skb->len >= IEEE80211_DATA_HDR3_LEN + sizeof(rfc1042_header) + 2) { |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 295 | hdr = (struct ieee80211_hdr *) skb->data; |
| 296 | fc = le16_to_cpu(hdr->frame_control); |
| 297 | if (ieee80211_is_data(hdr->frame_control) && |
| 298 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DATA) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 299 | u8 *pos = &skb->data[IEEE80211_DATA_HDR3_LEN + |
| 300 | sizeof(rfc1042_header)]; |
| 301 | meta->ethertype = (pos[0] << 8) | pos[1]; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /* Send IEEE 802.11 encapsulated frame using the master radio device */ |
| 306 | skb->dev = local->dev; |
| 307 | dev_queue_xmit(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 308 | return NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
| 312 | /* Called only from software IRQ */ |
Jouni Malinen | 79058ac | 2006-03-24 21:24:54 -0800 | [diff] [blame] | 313 | static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb, |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 314 | struct lib80211_crypt_data *crypt) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 315 | { |
| 316 | struct hostap_interface *iface; |
| 317 | local_info_t *local; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 318 | struct ieee80211_hdr *hdr; |
Brandon Craig Rhodes | d7ea3be | 2007-05-28 09:38:46 -0700 | [diff] [blame] | 319 | int prefix_len, postfix_len, hdr_len, res; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 320 | |
| 321 | iface = netdev_priv(skb->dev); |
| 322 | local = iface->local; |
| 323 | |
| 324 | if (skb->len < IEEE80211_DATA_HDR3_LEN) { |
| 325 | kfree_skb(skb); |
| 326 | return NULL; |
| 327 | } |
| 328 | |
| 329 | if (local->tkip_countermeasures && |
Jouni Malinen | 79058ac | 2006-03-24 21:24:54 -0800 | [diff] [blame] | 330 | strcmp(crypt->ops->name, "TKIP") == 0) { |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 331 | hdr = (struct ieee80211_hdr *) skb->data; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 332 | if (net_ratelimit()) { |
| 333 | printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 334 | "TX packet to %pM\n", |
| 335 | local->dev->name, hdr->addr1); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 336 | } |
| 337 | kfree_skb(skb); |
| 338 | return NULL; |
| 339 | } |
| 340 | |
| 341 | skb = skb_unshare(skb, GFP_ATOMIC); |
| 342 | if (skb == NULL) |
| 343 | return NULL; |
| 344 | |
Brandon Craig Rhodes | d7ea3be | 2007-05-28 09:38:46 -0700 | [diff] [blame] | 345 | prefix_len = crypt->ops->extra_mpdu_prefix_len + |
| 346 | crypt->ops->extra_msdu_prefix_len; |
| 347 | postfix_len = crypt->ops->extra_mpdu_postfix_len + |
| 348 | crypt->ops->extra_msdu_postfix_len; |
| 349 | if ((skb_headroom(skb) < prefix_len || |
| 350 | skb_tailroom(skb) < postfix_len) && |
| 351 | pskb_expand_head(skb, prefix_len, postfix_len, GFP_ATOMIC)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 352 | kfree_skb(skb); |
| 353 | return NULL; |
| 354 | } |
| 355 | |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 356 | hdr = (struct ieee80211_hdr *) skb->data; |
| 357 | hdr_len = hostap_80211_get_hdrlen(hdr->frame_control); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 358 | |
| 359 | /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so |
| 360 | * call both MSDU and MPDU encryption functions from here. */ |
| 361 | atomic_inc(&crypt->refcnt); |
| 362 | res = 0; |
| 363 | if (crypt->ops->encrypt_msdu) |
| 364 | res = crypt->ops->encrypt_msdu(skb, hdr_len, crypt->priv); |
| 365 | if (res == 0 && crypt->ops->encrypt_mpdu) |
| 366 | res = crypt->ops->encrypt_mpdu(skb, hdr_len, crypt->priv); |
| 367 | atomic_dec(&crypt->refcnt); |
| 368 | if (res < 0) { |
| 369 | kfree_skb(skb); |
| 370 | return NULL; |
| 371 | } |
| 372 | |
| 373 | return skb; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /* hard_start_xmit function for master radio interface wifi#. |
| 378 | * AP processing (TX rate control, power save buffering, etc.). |
| 379 | * Use hardware TX function to send the frame. */ |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 380 | netdev_tx_t hostap_master_start_xmit(struct sk_buff *skb, |
| 381 | struct net_device *dev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 382 | { |
| 383 | struct hostap_interface *iface; |
| 384 | local_info_t *local; |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 385 | netdev_tx_t ret = NETDEV_TX_BUSY; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 386 | u16 fc; |
| 387 | struct hostap_tx_data tx; |
| 388 | ap_tx_ret tx_ret; |
| 389 | struct hostap_skb_tx_data *meta; |
| 390 | int no_encrypt = 0; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 391 | struct ieee80211_hdr *hdr; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 392 | |
| 393 | iface = netdev_priv(dev); |
| 394 | local = iface->local; |
| 395 | |
| 396 | tx.skb = skb; |
| 397 | tx.sta_ptr = NULL; |
| 398 | |
| 399 | meta = (struct hostap_skb_tx_data *) skb->cb; |
| 400 | if (meta->magic != HOSTAP_SKB_TX_DATA_MAGIC) { |
| 401 | printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, " |
| 402 | "expected 0x%08x)\n", |
| 403 | dev->name, meta->magic, HOSTAP_SKB_TX_DATA_MAGIC); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 404 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 405 | iface->stats.tx_dropped++; |
| 406 | goto fail; |
| 407 | } |
| 408 | |
| 409 | if (local->host_encrypt) { |
| 410 | /* Set crypt to default algorithm and key; will be replaced in |
| 411 | * AP code if STA has own alg/key */ |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 412 | tx.crypt = local->crypt_info.crypt[local->crypt_info.tx_keyidx]; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 413 | tx.host_encrypt = 1; |
| 414 | } else { |
| 415 | tx.crypt = NULL; |
| 416 | tx.host_encrypt = 0; |
| 417 | } |
| 418 | |
| 419 | if (skb->len < 24) { |
| 420 | printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb " |
| 421 | "(len=%d)\n", dev->name, skb->len); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 422 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 423 | iface->stats.tx_dropped++; |
| 424 | goto fail; |
| 425 | } |
| 426 | |
| 427 | /* FIX (?): |
| 428 | * Wi-Fi 802.11b test plan suggests that AP should ignore power save |
| 429 | * bit in authentication and (re)association frames and assume tha |
| 430 | * STA remains awake for the response. */ |
| 431 | tx_ret = hostap_handle_sta_tx(local, &tx); |
| 432 | skb = tx.skb; |
| 433 | meta = (struct hostap_skb_tx_data *) skb->cb; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 434 | hdr = (struct ieee80211_hdr *) skb->data; |
| 435 | fc = le16_to_cpu(hdr->frame_control); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 436 | switch (tx_ret) { |
| 437 | case AP_TX_CONTINUE: |
| 438 | break; |
| 439 | case AP_TX_CONTINUE_NOT_AUTHORIZED: |
| 440 | if (local->ieee_802_1x && |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 441 | ieee80211_is_data(hdr->frame_control) && |
Jouni Malinen | 5bee720 | 2005-08-14 19:08:39 -0700 | [diff] [blame] | 442 | meta->ethertype != ETH_P_PAE && |
| 443 | !(meta->flags & HOSTAP_TX_FLAGS_WDS)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 444 | printk(KERN_DEBUG "%s: dropped frame to unauthorized " |
| 445 | "port (IEEE 802.1X): ethertype=0x%04x\n", |
| 446 | dev->name, meta->ethertype); |
| 447 | hostap_dump_tx_80211(dev->name, skb); |
| 448 | |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 449 | ret = NETDEV_TX_OK; /* drop packet */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 450 | iface->stats.tx_dropped++; |
| 451 | goto fail; |
| 452 | } |
| 453 | break; |
| 454 | case AP_TX_DROP: |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 455 | ret = NETDEV_TX_OK; /* drop packet */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 456 | iface->stats.tx_dropped++; |
| 457 | goto fail; |
| 458 | case AP_TX_RETRY: |
| 459 | goto fail; |
| 460 | case AP_TX_BUFFERED: |
| 461 | /* do not free skb here, it will be freed when the |
| 462 | * buffered frame is sent/timed out */ |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 463 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 464 | goto tx_exit; |
| 465 | } |
| 466 | |
| 467 | /* Request TX callback if protocol version is 2 in 802.11 header; |
| 468 | * this version 2 is a special case used between hostapd and kernel |
| 469 | * driver */ |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 470 | if (((fc & IEEE80211_FCTL_VERS) == BIT(1)) && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 471 | local->ap && local->ap->tx_callback_idx && meta->tx_cb_idx == 0) { |
| 472 | meta->tx_cb_idx = local->ap->tx_callback_idx; |
| 473 | |
| 474 | /* remove special version from the frame header */ |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 475 | fc &= ~IEEE80211_FCTL_VERS; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 476 | hdr->frame_control = cpu_to_le16(fc); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 477 | } |
| 478 | |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 479 | if (!ieee80211_is_data(hdr->frame_control)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 480 | no_encrypt = 1; |
| 481 | tx.crypt = NULL; |
| 482 | } |
| 483 | |
| 484 | if (local->ieee_802_1x && meta->ethertype == ETH_P_PAE && tx.crypt && |
Jouni Malinen | cfa146e | 2006-03-24 21:24:55 -0800 | [diff] [blame] | 485 | !(fc & IEEE80211_FCTL_PROTECTED)) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 486 | no_encrypt = 1; |
| 487 | PDEBUG(DEBUG_EXTRA2, "%s: TX: IEEE 802.1X - passing " |
| 488 | "unencrypted EAPOL frame\n", dev->name); |
| 489 | tx.crypt = NULL; /* no encryption for IEEE 802.1X frames */ |
| 490 | } |
| 491 | |
| 492 | if (tx.crypt && (!tx.crypt->ops || !tx.crypt->ops->encrypt_mpdu)) |
| 493 | tx.crypt = NULL; |
John W. Linville | 274bfb8 | 2008-10-29 11:35:05 -0400 | [diff] [blame] | 494 | else if ((tx.crypt || |
| 495 | local->crypt_info.crypt[local->crypt_info.tx_keyidx]) && |
| 496 | !no_encrypt) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 497 | /* Add ISWEP flag both for firmware and host based encryption |
| 498 | */ |
Jeff Garzik | 831a179 | 2005-08-25 20:59:10 -0400 | [diff] [blame] | 499 | fc |= IEEE80211_FCTL_PROTECTED; |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 500 | hdr->frame_control = cpu_to_le16(fc); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 501 | } else if (local->drop_unencrypted && |
Dan Williams | 1ea893f | 2009-02-11 17:17:10 -0500 | [diff] [blame] | 502 | ieee80211_is_data(hdr->frame_control) && |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 503 | meta->ethertype != ETH_P_PAE) { |
| 504 | if (net_ratelimit()) { |
| 505 | printk(KERN_DEBUG "%s: dropped unencrypted TX data " |
| 506 | "frame (drop_unencrypted=1)\n", dev->name); |
| 507 | } |
| 508 | iface->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 509 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 510 | goto fail; |
| 511 | } |
| 512 | |
| 513 | if (tx.crypt) { |
| 514 | skb = hostap_tx_encrypt(skb, tx.crypt); |
| 515 | if (skb == NULL) { |
| 516 | printk(KERN_DEBUG "%s: TX - encryption failed\n", |
| 517 | dev->name); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 518 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 519 | goto fail; |
| 520 | } |
| 521 | meta = (struct hostap_skb_tx_data *) skb->cb; |
| 522 | if (meta->magic != HOSTAP_SKB_TX_DATA_MAGIC) { |
| 523 | printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, " |
| 524 | "expected 0x%08x) after hostap_tx_encrypt\n", |
| 525 | dev->name, meta->magic, |
| 526 | HOSTAP_SKB_TX_DATA_MAGIC); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 527 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 528 | iface->stats.tx_dropped++; |
| 529 | goto fail; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (local->func->tx == NULL || local->func->tx(skb, dev)) { |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 534 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 535 | iface->stats.tx_dropped++; |
| 536 | } else { |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 537 | ret = NETDEV_TX_OK; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 538 | iface->stats.tx_packets++; |
| 539 | iface->stats.tx_bytes += skb->len; |
| 540 | } |
| 541 | |
| 542 | fail: |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 543 | if (ret == NETDEV_TX_OK && skb) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 544 | dev_kfree_skb(skb); |
| 545 | tx_exit: |
| 546 | if (tx.sta_ptr) |
| 547 | hostap_handle_sta_release(tx.sta_ptr); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 552 | EXPORT_SYMBOL(hostap_master_start_xmit); |