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