Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * utilities for mac80211 |
| 12 | */ |
| 13 | |
| 14 | #include <net/mac80211.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/etherdevice.h> |
| 20 | #include <linux/if_arp.h> |
| 21 | #include <linux/wireless.h> |
| 22 | #include <linux/bitmap.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 23 | #include <net/net_namespace.h> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 24 | #include <net/cfg80211.h> |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 25 | #include <net/rtnetlink.h> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 26 | |
| 27 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 28 | #include "rate.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 29 | #include "mesh.h" |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 30 | #include "wme.h" |
| 31 | |
| 32 | /* privid for wiphys to determine whether they belong to us or not */ |
| 33 | void *mac80211_wiphy_privid = &mac80211_wiphy_privid; |
| 34 | |
| 35 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 36 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 37 | const unsigned char rfc1042_header[] __aligned(2) = |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 38 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 39 | |
| 40 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 41 | const unsigned char bridge_tunnel_header[] __aligned(2) = |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 42 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 43 | |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 44 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 45 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 46 | enum nl80211_iftype type) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 47 | { |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 48 | __le16 fc = hdr->frame_control; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 49 | |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 50 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
| 51 | if (len < 16) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 52 | return NULL; |
| 53 | |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 54 | if (ieee80211_is_data(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 55 | if (len < 24) /* drop incorrect hdr len (data) */ |
| 56 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 57 | |
| 58 | if (ieee80211_has_a4(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 59 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 60 | if (ieee80211_has_tods(fc)) |
| 61 | return hdr->addr1; |
| 62 | if (ieee80211_has_fromds(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 63 | return hdr->addr2; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 64 | |
| 65 | return hdr->addr3; |
| 66 | } |
| 67 | |
| 68 | if (ieee80211_is_mgmt(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 69 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
| 70 | return NULL; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 71 | return hdr->addr3; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | if (ieee80211_is_ctl(fc)) { |
| 75 | if(ieee80211_is_pspoll(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 76 | return hdr->addr1; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 77 | |
| 78 | if (ieee80211_is_back_req(fc)) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 79 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 80 | case NL80211_IFTYPE_STATION: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 81 | return hdr->addr2; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 82 | case NL80211_IFTYPE_AP: |
| 83 | case NL80211_IFTYPE_AP_VLAN: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 84 | return hdr->addr1; |
| 85 | default: |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 86 | break; /* fall through to the return */ |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 87 | } |
| 88 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | return NULL; |
| 92 | } |
| 93 | |
Harvey Harrison | 6693be7 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 94 | unsigned int ieee80211_hdrlen(__le16 fc) |
| 95 | { |
| 96 | unsigned int hdrlen = 24; |
| 97 | |
| 98 | if (ieee80211_is_data(fc)) { |
| 99 | if (ieee80211_has_a4(fc)) |
| 100 | hdrlen = 30; |
| 101 | if (ieee80211_is_data_qos(fc)) |
| 102 | hdrlen += IEEE80211_QOS_CTL_LEN; |
| 103 | goto out; |
| 104 | } |
| 105 | |
| 106 | if (ieee80211_is_ctl(fc)) { |
| 107 | /* |
| 108 | * ACK and CTS are 10 bytes, all others 16. To see how |
| 109 | * to get this condition consider |
| 110 | * subtype mask: 0b0000000011110000 (0x00F0) |
| 111 | * ACK subtype: 0b0000000011010000 (0x00D0) |
| 112 | * CTS subtype: 0b0000000011000000 (0x00C0) |
| 113 | * bits that matter: ^^^ (0x00E0) |
| 114 | * value of those: 0b0000000011000000 (0x00C0) |
| 115 | */ |
| 116 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) |
| 117 | hdrlen = 10; |
| 118 | else |
| 119 | hdrlen = 16; |
| 120 | } |
| 121 | out: |
| 122 | return hdrlen; |
| 123 | } |
| 124 | EXPORT_SYMBOL(ieee80211_hdrlen); |
| 125 | |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 126 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 127 | { |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 128 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data; |
| 129 | unsigned int hdrlen; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 130 | |
| 131 | if (unlikely(skb->len < 10)) |
| 132 | return 0; |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 133 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 134 | if (unlikely(hdrlen > skb->len)) |
| 135 | return 0; |
| 136 | return hdrlen; |
| 137 | } |
| 138 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); |
| 139 | |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 140 | int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) |
| 141 | { |
| 142 | int ae = meshhdr->flags & IEEE80211S_FLAGS_AE; |
| 143 | /* 7.1.3.5a.2 */ |
| 144 | switch (ae) { |
| 145 | case 0: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 146 | return 6; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 147 | case 1: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 148 | return 12; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 149 | case 2: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 150 | return 18; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 151 | case 3: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 152 | return 24; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 153 | default: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 154 | return 6; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 155 | } |
| 156 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 157 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 158 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 159 | { |
| 160 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; |
| 161 | |
| 162 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 163 | if (tx->extra_frag) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 164 | struct ieee80211_hdr *fhdr; |
| 165 | int i; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 166 | for (i = 0; i < tx->num_extra_frag; i++) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 167 | fhdr = (struct ieee80211_hdr *) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 168 | tx->extra_frag[i]->data; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 169 | fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, |
| 175 | int rate, int erp, int short_preamble) |
| 176 | { |
| 177 | int dur; |
| 178 | |
| 179 | /* calculate duration (in microseconds, rounded up to next higher |
| 180 | * integer if it includes a fractional microsecond) to send frame of |
| 181 | * len bytes (does not include FCS) at the given rate. Duration will |
| 182 | * also include SIFS. |
| 183 | * |
| 184 | * rate is in 100 kbps, so divident is multiplied by 10 in the |
| 185 | * DIV_ROUND_UP() operations. |
| 186 | */ |
| 187 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 188 | if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 189 | /* |
| 190 | * OFDM: |
| 191 | * |
| 192 | * N_DBPS = DATARATE x 4 |
| 193 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) |
| 194 | * (16 = SIGNAL time, 6 = tail bits) |
| 195 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext |
| 196 | * |
| 197 | * T_SYM = 4 usec |
| 198 | * 802.11a - 17.5.2: aSIFSTime = 16 usec |
| 199 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + |
| 200 | * signal ext = 6 usec |
| 201 | */ |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 202 | dur = 16; /* SIFS + signal ext */ |
| 203 | dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ |
| 204 | dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ |
| 205 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, |
| 206 | 4 * rate); /* T_SYM x N_SYM */ |
| 207 | } else { |
| 208 | /* |
| 209 | * 802.11b or 802.11g with 802.11b compatibility: |
| 210 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + |
| 211 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. |
| 212 | * |
| 213 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 |
| 214 | * aSIFSTime = 10 usec |
| 215 | * aPreambleLength = 144 usec or 72 usec with short preamble |
| 216 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble |
| 217 | */ |
| 218 | dur = 10; /* aSIFSTime = 10 usec */ |
| 219 | dur += short_preamble ? (72 + 24) : (144 + 48); |
| 220 | |
| 221 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); |
| 222 | } |
| 223 | |
| 224 | return dur; |
| 225 | } |
| 226 | |
| 227 | /* Exported duration function for driver use */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 228 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
| 229 | struct ieee80211_vif *vif, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 230 | size_t frame_len, |
| 231 | struct ieee80211_rate *rate) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 232 | { |
| 233 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 234 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 235 | u16 dur; |
| 236 | int erp; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 237 | bool short_preamble = false; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 238 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 239 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 240 | if (vif) { |
| 241 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 242 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 243 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 244 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 245 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 246 | |
| 247 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 248 | short_preamble); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 249 | |
| 250 | return cpu_to_le16(dur); |
| 251 | } |
| 252 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); |
| 253 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 254 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
| 255 | struct ieee80211_vif *vif, size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 256 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 257 | { |
| 258 | struct ieee80211_local *local = hw_to_local(hw); |
| 259 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 260 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 261 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 262 | int erp; |
| 263 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 264 | struct ieee80211_supported_band *sband; |
| 265 | |
| 266 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 267 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 268 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 269 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 270 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 271 | |
| 272 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 273 | if (vif) { |
| 274 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 275 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 276 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 277 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 278 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 279 | |
| 280 | /* CTS duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 281 | dur = ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 282 | erp, short_preamble); |
| 283 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 284 | dur += ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 285 | erp, short_preamble); |
| 286 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 287 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 288 | erp, short_preamble); |
| 289 | |
| 290 | return cpu_to_le16(dur); |
| 291 | } |
| 292 | EXPORT_SYMBOL(ieee80211_rts_duration); |
| 293 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 294 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
| 295 | struct ieee80211_vif *vif, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 296 | size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 297 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 298 | { |
| 299 | struct ieee80211_local *local = hw_to_local(hw); |
| 300 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 301 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 302 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 303 | int erp; |
| 304 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 305 | struct ieee80211_supported_band *sband; |
| 306 | |
| 307 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 308 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 309 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 310 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 311 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 312 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 313 | if (vif) { |
| 314 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 315 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 316 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 317 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 318 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 319 | |
| 320 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 321 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 322 | erp, short_preamble); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 323 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 324 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 325 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 326 | erp, short_preamble); |
| 327 | } |
| 328 | |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 329 | return cpu_to_le16(dur); |
| 330 | } |
| 331 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); |
| 332 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 333 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
| 334 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 335 | { |
| 336 | struct ieee80211_local *local = hw_to_local(hw); |
| 337 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 338 | /* we don't need to track ampdu queues */ |
| 339 | if (queue < ieee80211_num_regular_queues(hw)) { |
| 340 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
| 341 | |
| 342 | if (local->queue_stop_reasons[queue] != 0) |
| 343 | /* someone still has this queue stopped */ |
| 344 | return; |
| 345 | } |
| 346 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 347 | if (test_bit(queue, local->queues_pending)) { |
Tomas Winkler | f8e79dd | 2008-07-24 18:46:44 +0300 | [diff] [blame] | 348 | set_bit(queue, local->queues_pending_run); |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 349 | tasklet_schedule(&local->tx_pending_tasklet); |
| 350 | } else { |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 351 | netif_wake_subqueue(local->mdev, queue); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 352 | } |
| 353 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 354 | |
| 355 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 356 | enum queue_stop_reason reason) |
| 357 | { |
| 358 | struct ieee80211_local *local = hw_to_local(hw); |
| 359 | unsigned long flags; |
| 360 | |
| 361 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 362 | __ieee80211_wake_queue(hw, queue, reason); |
| 363 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 364 | } |
| 365 | |
| 366 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) |
| 367 | { |
| 368 | ieee80211_wake_queue_by_reason(hw, queue, |
| 369 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 370 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 371 | EXPORT_SYMBOL(ieee80211_wake_queue); |
| 372 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 373 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
| 374 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 375 | { |
| 376 | struct ieee80211_local *local = hw_to_local(hw); |
| 377 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 378 | /* we don't need to track ampdu queues */ |
| 379 | if (queue < ieee80211_num_regular_queues(hw)) |
| 380 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
| 381 | |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 382 | netif_stop_subqueue(local->mdev, queue); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 383 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 384 | |
| 385 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 386 | enum queue_stop_reason reason) |
| 387 | { |
| 388 | struct ieee80211_local *local = hw_to_local(hw); |
| 389 | unsigned long flags; |
| 390 | |
| 391 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 392 | __ieee80211_stop_queue(hw, queue, reason); |
| 393 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 394 | } |
| 395 | |
| 396 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) |
| 397 | { |
| 398 | ieee80211_stop_queue_by_reason(hw, queue, |
| 399 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 400 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 401 | EXPORT_SYMBOL(ieee80211_stop_queue); |
| 402 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 403 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
| 404 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 405 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 406 | struct ieee80211_local *local = hw_to_local(hw); |
| 407 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 408 | int i; |
| 409 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 410 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 411 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 412 | for (i = 0; i < ieee80211_num_queues(hw); i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 413 | __ieee80211_stop_queue(hw, i, reason); |
| 414 | |
| 415 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 416 | } |
| 417 | |
| 418 | void ieee80211_stop_queues(struct ieee80211_hw *hw) |
| 419 | { |
| 420 | ieee80211_stop_queues_by_reason(hw, |
| 421 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 422 | } |
| 423 | EXPORT_SYMBOL(ieee80211_stop_queues); |
| 424 | |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 425 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
| 426 | { |
| 427 | struct ieee80211_local *local = hw_to_local(hw); |
| 428 | return __netif_subqueue_stopped(local->mdev, queue); |
| 429 | } |
| 430 | EXPORT_SYMBOL(ieee80211_queue_stopped); |
| 431 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 432 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
| 433 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 434 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 435 | struct ieee80211_local *local = hw_to_local(hw); |
| 436 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 437 | int i; |
| 438 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 439 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 440 | |
Johannes Berg | c4680470 | 2008-05-15 12:55:25 +0200 | [diff] [blame] | 441 | for (i = 0; i < hw->queues + hw->ampdu_queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 442 | __ieee80211_wake_queue(hw, i, reason); |
| 443 | |
| 444 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 445 | } |
| 446 | |
| 447 | void ieee80211_wake_queues(struct ieee80211_hw *hw) |
| 448 | { |
| 449 | ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 450 | } |
| 451 | EXPORT_SYMBOL(ieee80211_wake_queues); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 452 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 453 | void ieee80211_iterate_active_interfaces( |
| 454 | struct ieee80211_hw *hw, |
| 455 | void (*iterator)(void *data, u8 *mac, |
| 456 | struct ieee80211_vif *vif), |
| 457 | void *data) |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 458 | { |
| 459 | struct ieee80211_local *local = hw_to_local(hw); |
| 460 | struct ieee80211_sub_if_data *sdata; |
| 461 | |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 462 | rtnl_lock(); |
| 463 | |
| 464 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 465 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 466 | case __NL80211_IFTYPE_AFTER_LAST: |
| 467 | case NL80211_IFTYPE_UNSPECIFIED: |
| 468 | case NL80211_IFTYPE_MONITOR: |
| 469 | case NL80211_IFTYPE_AP_VLAN: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 470 | continue; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 471 | case NL80211_IFTYPE_AP: |
| 472 | case NL80211_IFTYPE_STATION: |
| 473 | case NL80211_IFTYPE_ADHOC: |
| 474 | case NL80211_IFTYPE_WDS: |
| 475 | case NL80211_IFTYPE_MESH_POINT: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 476 | break; |
| 477 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 478 | if (netif_running(sdata->dev)) |
| 479 | iterator(data, sdata->dev->dev_addr, |
| 480 | &sdata->vif); |
| 481 | } |
| 482 | |
| 483 | rtnl_unlock(); |
| 484 | } |
| 485 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); |
| 486 | |
| 487 | void ieee80211_iterate_active_interfaces_atomic( |
| 488 | struct ieee80211_hw *hw, |
| 489 | void (*iterator)(void *data, u8 *mac, |
| 490 | struct ieee80211_vif *vif), |
| 491 | void *data) |
| 492 | { |
| 493 | struct ieee80211_local *local = hw_to_local(hw); |
| 494 | struct ieee80211_sub_if_data *sdata; |
| 495 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 496 | rcu_read_lock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 497 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 498 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 499 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 500 | case __NL80211_IFTYPE_AFTER_LAST: |
| 501 | case NL80211_IFTYPE_UNSPECIFIED: |
| 502 | case NL80211_IFTYPE_MONITOR: |
| 503 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 504 | continue; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 505 | case NL80211_IFTYPE_AP: |
| 506 | case NL80211_IFTYPE_STATION: |
| 507 | case NL80211_IFTYPE_ADHOC: |
| 508 | case NL80211_IFTYPE_WDS: |
| 509 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 510 | break; |
| 511 | } |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 512 | if (netif_running(sdata->dev)) |
| 513 | iterator(data, sdata->dev->dev_addr, |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 514 | &sdata->vif); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 515 | } |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 516 | |
| 517 | rcu_read_unlock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 518 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 519 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 520 | |
| 521 | void ieee802_11_parse_elems(u8 *start, size_t len, |
| 522 | struct ieee802_11_elems *elems) |
| 523 | { |
| 524 | size_t left = len; |
| 525 | u8 *pos = start; |
| 526 | |
| 527 | memset(elems, 0, sizeof(*elems)); |
| 528 | elems->ie_start = start; |
| 529 | elems->total_len = len; |
| 530 | |
| 531 | while (left >= 2) { |
| 532 | u8 id, elen; |
| 533 | |
| 534 | id = *pos++; |
| 535 | elen = *pos++; |
| 536 | left -= 2; |
| 537 | |
| 538 | if (elen > left) |
| 539 | return; |
| 540 | |
| 541 | switch (id) { |
| 542 | case WLAN_EID_SSID: |
| 543 | elems->ssid = pos; |
| 544 | elems->ssid_len = elen; |
| 545 | break; |
| 546 | case WLAN_EID_SUPP_RATES: |
| 547 | elems->supp_rates = pos; |
| 548 | elems->supp_rates_len = elen; |
| 549 | break; |
| 550 | case WLAN_EID_FH_PARAMS: |
| 551 | elems->fh_params = pos; |
| 552 | elems->fh_params_len = elen; |
| 553 | break; |
| 554 | case WLAN_EID_DS_PARAMS: |
| 555 | elems->ds_params = pos; |
| 556 | elems->ds_params_len = elen; |
| 557 | break; |
| 558 | case WLAN_EID_CF_PARAMS: |
| 559 | elems->cf_params = pos; |
| 560 | elems->cf_params_len = elen; |
| 561 | break; |
| 562 | case WLAN_EID_TIM: |
| 563 | elems->tim = pos; |
| 564 | elems->tim_len = elen; |
| 565 | break; |
| 566 | case WLAN_EID_IBSS_PARAMS: |
| 567 | elems->ibss_params = pos; |
| 568 | elems->ibss_params_len = elen; |
| 569 | break; |
| 570 | case WLAN_EID_CHALLENGE: |
| 571 | elems->challenge = pos; |
| 572 | elems->challenge_len = elen; |
| 573 | break; |
| 574 | case WLAN_EID_WPA: |
| 575 | if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && |
| 576 | pos[2] == 0xf2) { |
| 577 | /* Microsoft OUI (00:50:F2) */ |
| 578 | if (pos[3] == 1) { |
| 579 | /* OUI Type 1 - WPA IE */ |
| 580 | elems->wpa = pos; |
| 581 | elems->wpa_len = elen; |
| 582 | } else if (elen >= 5 && pos[3] == 2) { |
| 583 | if (pos[4] == 0) { |
| 584 | elems->wmm_info = pos; |
| 585 | elems->wmm_info_len = elen; |
| 586 | } else if (pos[4] == 1) { |
| 587 | elems->wmm_param = pos; |
| 588 | elems->wmm_param_len = elen; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | break; |
| 593 | case WLAN_EID_RSN: |
| 594 | elems->rsn = pos; |
| 595 | elems->rsn_len = elen; |
| 596 | break; |
| 597 | case WLAN_EID_ERP_INFO: |
| 598 | elems->erp_info = pos; |
| 599 | elems->erp_info_len = elen; |
| 600 | break; |
| 601 | case WLAN_EID_EXT_SUPP_RATES: |
| 602 | elems->ext_supp_rates = pos; |
| 603 | elems->ext_supp_rates_len = elen; |
| 604 | break; |
| 605 | case WLAN_EID_HT_CAPABILITY: |
Johannes Berg | 0991481 | 2008-10-07 19:31:17 +0200 | [diff] [blame] | 606 | if (elen >= sizeof(struct ieee80211_ht_cap)) |
| 607 | elems->ht_cap_elem = (void *)pos; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 608 | break; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 609 | case WLAN_EID_HT_INFORMATION: |
| 610 | if (elen >= sizeof(struct ieee80211_ht_info)) |
Johannes Berg | 0991481 | 2008-10-07 19:31:17 +0200 | [diff] [blame] | 611 | elems->ht_info_elem = (void *)pos; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 612 | break; |
| 613 | case WLAN_EID_MESH_ID: |
| 614 | elems->mesh_id = pos; |
| 615 | elems->mesh_id_len = elen; |
| 616 | break; |
| 617 | case WLAN_EID_MESH_CONFIG: |
| 618 | elems->mesh_config = pos; |
| 619 | elems->mesh_config_len = elen; |
| 620 | break; |
| 621 | case WLAN_EID_PEER_LINK: |
| 622 | elems->peer_link = pos; |
| 623 | elems->peer_link_len = elen; |
| 624 | break; |
| 625 | case WLAN_EID_PREQ: |
| 626 | elems->preq = pos; |
| 627 | elems->preq_len = elen; |
| 628 | break; |
| 629 | case WLAN_EID_PREP: |
| 630 | elems->prep = pos; |
| 631 | elems->prep_len = elen; |
| 632 | break; |
| 633 | case WLAN_EID_PERR: |
| 634 | elems->perr = pos; |
| 635 | elems->perr_len = elen; |
| 636 | break; |
| 637 | case WLAN_EID_CHANNEL_SWITCH: |
| 638 | elems->ch_switch_elem = pos; |
| 639 | elems->ch_switch_elem_len = elen; |
| 640 | break; |
| 641 | case WLAN_EID_QUIET: |
| 642 | if (!elems->quiet_elem) { |
| 643 | elems->quiet_elem = pos; |
| 644 | elems->quiet_elem_len = elen; |
| 645 | } |
| 646 | elems->num_of_quiet_elem++; |
| 647 | break; |
| 648 | case WLAN_EID_COUNTRY: |
| 649 | elems->country_elem = pos; |
| 650 | elems->country_elem_len = elen; |
| 651 | break; |
| 652 | case WLAN_EID_PWR_CONSTRAINT: |
| 653 | elems->pwr_constr_elem = pos; |
| 654 | elems->pwr_constr_elem_len = elen; |
| 655 | break; |
| 656 | default: |
| 657 | break; |
| 658 | } |
| 659 | |
| 660 | left -= elen; |
| 661 | pos += elen; |
| 662 | } |
| 663 | } |
Johannes Berg | 5825fe10 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 664 | |
| 665 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) |
| 666 | { |
| 667 | struct ieee80211_local *local = sdata->local; |
| 668 | struct ieee80211_tx_queue_params qparam; |
| 669 | int i; |
| 670 | |
| 671 | if (!local->ops->conf_tx) |
| 672 | return; |
| 673 | |
| 674 | memset(&qparam, 0, sizeof(qparam)); |
| 675 | |
| 676 | qparam.aifs = 2; |
| 677 | |
| 678 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 679 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) |
| 680 | qparam.cw_min = 31; |
| 681 | else |
| 682 | qparam.cw_min = 15; |
| 683 | |
| 684 | qparam.cw_max = 1023; |
| 685 | qparam.txop = 0; |
| 686 | |
| 687 | for (i = 0; i < local_to_hw(local)->queues; i++) |
| 688 | local->ops->conf_tx(local_to_hw(local), i, &qparam); |
| 689 | } |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 690 | |
| 691 | void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
| 692 | int encrypt) |
| 693 | { |
| 694 | skb->dev = sdata->local->mdev; |
| 695 | skb_set_mac_header(skb, 0); |
| 696 | skb_set_network_header(skb, 0); |
| 697 | skb_set_transport_header(skb, 0); |
| 698 | |
| 699 | skb->iif = sdata->dev->ifindex; |
| 700 | skb->do_not_encrypt = !encrypt; |
| 701 | |
| 702 | dev_queue_xmit(skb); |
| 703 | } |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 704 | |
| 705 | int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz) |
| 706 | { |
| 707 | int ret = -EINVAL; |
| 708 | struct ieee80211_channel *chan; |
| 709 | struct ieee80211_local *local = sdata->local; |
| 710 | |
| 711 | chan = ieee80211_get_channel(local->hw.wiphy, freqMHz); |
| 712 | |
| 713 | if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 714 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | d73782f | 2008-10-07 12:04:34 +0200 | [diff] [blame] | 715 | chan->flags & IEEE80211_CHAN_NO_IBSS) |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 716 | return ret; |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 717 | local->oper_channel = chan; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 718 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 719 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 720 | if (local->sw_scanning || local->hw_scanning) |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 721 | ret = 0; |
| 722 | else |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 723 | ret = ieee80211_hw_config( |
| 724 | local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | return ret; |
| 728 | } |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 729 | |
| 730 | u64 ieee80211_mandatory_rates(struct ieee80211_local *local, |
| 731 | enum ieee80211_band band) |
| 732 | { |
| 733 | struct ieee80211_supported_band *sband; |
| 734 | struct ieee80211_rate *bitrates; |
| 735 | u64 mandatory_rates; |
| 736 | enum ieee80211_rate_flags mandatory_flag; |
| 737 | int i; |
| 738 | |
| 739 | sband = local->hw.wiphy->bands[band]; |
| 740 | if (!sband) { |
| 741 | WARN_ON(1); |
| 742 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 743 | } |
| 744 | |
| 745 | if (band == IEEE80211_BAND_2GHZ) |
| 746 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; |
| 747 | else |
| 748 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
| 749 | |
| 750 | bitrates = sband->bitrates; |
| 751 | mandatory_rates = 0; |
| 752 | for (i = 0; i < sband->n_bitrates; i++) |
| 753 | if (bitrates[i].flags & mandatory_flag) |
| 754 | mandatory_rates |= BIT(i); |
| 755 | return mandatory_rates; |
| 756 | } |