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