Commit 176f36086e8a00bdf701dc6e4c5a8784ef6529df

Authored by Thomas Pedersen
Committed by John W. Linville
1 parent 42e7aa7711

mac80211: add HT IEs to mesh frames

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
Signed-off-by: Ashok Nagarajan <anagar6@uic.edu>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

Showing 4 changed files with 60 additions and 0 deletions Inline Diff

1 /* 1 /*
2 * Copyright (c) 2008, 2009 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com> 3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com> 4 * Javier Cardona <javier@cozybit.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11 #include <linux/slab.h> 11 #include <linux/slab.h>
12 #include <asm/unaligned.h> 12 #include <asm/unaligned.h>
13 #include "ieee80211_i.h" 13 #include "ieee80211_i.h"
14 #include "mesh.h" 14 #include "mesh.h"
15 15
16 #define MESHCONF_CAPAB_ACCEPT_PLINKS 0x01 16 #define MESHCONF_CAPAB_ACCEPT_PLINKS 0x01
17 #define MESHCONF_CAPAB_FORWARDING 0x08 17 #define MESHCONF_CAPAB_FORWARDING 0x08
18 18
19 #define TMR_RUNNING_HK 0 19 #define TMR_RUNNING_HK 0
20 #define TMR_RUNNING_MP 1 20 #define TMR_RUNNING_MP 1
21 #define TMR_RUNNING_MPR 2 21 #define TMR_RUNNING_MPR 2
22 22
23 int mesh_allocated; 23 int mesh_allocated;
24 static struct kmem_cache *rm_cache; 24 static struct kmem_cache *rm_cache;
25 25
26 #ifdef CONFIG_MAC80211_MESH 26 #ifdef CONFIG_MAC80211_MESH
27 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt) 27 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
28 { 28 {
29 return (mgmt->u.action.u.mesh_action.action_code == 29 return (mgmt->u.action.u.mesh_action.action_code ==
30 WLAN_MESH_ACTION_HWMP_PATH_SELECTION); 30 WLAN_MESH_ACTION_HWMP_PATH_SELECTION);
31 } 31 }
32 #else 32 #else
33 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt) 33 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
34 { return false; } 34 { return false; }
35 #endif 35 #endif
36 36
37 void ieee80211s_init(void) 37 void ieee80211s_init(void)
38 { 38 {
39 mesh_pathtbl_init(); 39 mesh_pathtbl_init();
40 mesh_allocated = 1; 40 mesh_allocated = 1;
41 rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry), 41 rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
42 0, 0, NULL); 42 0, 0, NULL);
43 } 43 }
44 44
45 void ieee80211s_stop(void) 45 void ieee80211s_stop(void)
46 { 46 {
47 mesh_pathtbl_unregister(); 47 mesh_pathtbl_unregister();
48 kmem_cache_destroy(rm_cache); 48 kmem_cache_destroy(rm_cache);
49 } 49 }
50 50
51 static void ieee80211_mesh_housekeeping_timer(unsigned long data) 51 static void ieee80211_mesh_housekeeping_timer(unsigned long data)
52 { 52 {
53 struct ieee80211_sub_if_data *sdata = (void *) data; 53 struct ieee80211_sub_if_data *sdata = (void *) data;
54 struct ieee80211_local *local = sdata->local; 54 struct ieee80211_local *local = sdata->local;
55 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 55 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
56 56
57 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); 57 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
58 58
59 if (local->quiescing) { 59 if (local->quiescing) {
60 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running); 60 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
61 return; 61 return;
62 } 62 }
63 63
64 ieee80211_queue_work(&local->hw, &sdata->work); 64 ieee80211_queue_work(&local->hw, &sdata->work);
65 } 65 }
66 66
67 /** 67 /**
68 * mesh_matches_local - check if the config of a mesh point matches ours 68 * mesh_matches_local - check if the config of a mesh point matches ours
69 * 69 *
70 * @ie: information elements of a management frame from the mesh peer 70 * @ie: information elements of a management frame from the mesh peer
71 * @sdata: local mesh subif 71 * @sdata: local mesh subif
72 * 72 *
73 * This function checks if the mesh configuration of a mesh point matches the 73 * This function checks if the mesh configuration of a mesh point matches the
74 * local mesh configuration, i.e. if both nodes belong to the same mesh network. 74 * local mesh configuration, i.e. if both nodes belong to the same mesh network.
75 */ 75 */
76 bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata) 76 bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata)
77 { 77 {
78 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 78 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
79 79
80 /* 80 /*
81 * As support for each feature is added, check for matching 81 * As support for each feature is added, check for matching
82 * - On mesh config capabilities 82 * - On mesh config capabilities
83 * - Power Save Support En 83 * - Power Save Support En
84 * - Sync support enabled 84 * - Sync support enabled
85 * - Sync support active 85 * - Sync support active
86 * - Sync support required from peer 86 * - Sync support required from peer
87 * - MDA enabled 87 * - MDA enabled
88 * - Power management control on fc 88 * - Power management control on fc
89 */ 89 */
90 if (ifmsh->mesh_id_len == ie->mesh_id_len && 90 if (ifmsh->mesh_id_len == ie->mesh_id_len &&
91 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 && 91 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
92 (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) && 92 (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
93 (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) && 93 (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
94 (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) && 94 (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
95 (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) && 95 (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
96 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)) 96 (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))
97 return true; 97 return true;
98 98
99 return false; 99 return false;
100 } 100 }
101 101
102 /** 102 /**
103 * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links 103 * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
104 * 104 *
105 * @ie: information elements of a management frame from the mesh peer 105 * @ie: information elements of a management frame from the mesh peer
106 */ 106 */
107 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie) 107 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
108 { 108 {
109 return (ie->mesh_config->meshconf_cap & 109 return (ie->mesh_config->meshconf_cap &
110 MESHCONF_CAPAB_ACCEPT_PLINKS) != 0; 110 MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
111 } 111 }
112 112
113 /** 113 /**
114 * mesh_accept_plinks_update: update accepting_plink in local mesh beacons 114 * mesh_accept_plinks_update: update accepting_plink in local mesh beacons
115 * 115 *
116 * @sdata: mesh interface in which mesh beacons are going to be updated 116 * @sdata: mesh interface in which mesh beacons are going to be updated
117 */ 117 */
118 void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata) 118 void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
119 { 119 {
120 bool free_plinks; 120 bool free_plinks;
121 121
122 /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0, 122 /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
123 * the mesh interface might be able to establish plinks with peers that 123 * the mesh interface might be able to establish plinks with peers that
124 * are already on the table but are not on PLINK_ESTAB state. However, 124 * are already on the table but are not on PLINK_ESTAB state. However,
125 * in general the mesh interface is not accepting peer link requests 125 * in general the mesh interface is not accepting peer link requests
126 * from new peers, and that must be reflected in the beacon 126 * from new peers, and that must be reflected in the beacon
127 */ 127 */
128 free_plinks = mesh_plink_availables(sdata); 128 free_plinks = mesh_plink_availables(sdata);
129 129
130 if (free_plinks != sdata->u.mesh.accepting_plinks) 130 if (free_plinks != sdata->u.mesh.accepting_plinks)
131 ieee80211_mesh_housekeeping_timer((unsigned long) sdata); 131 ieee80211_mesh_housekeeping_timer((unsigned long) sdata);
132 } 132 }
133 133
134 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata) 134 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
135 { 135 {
136 int i; 136 int i;
137 137
138 sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL); 138 sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
139 if (!sdata->u.mesh.rmc) 139 if (!sdata->u.mesh.rmc)
140 return -ENOMEM; 140 return -ENOMEM;
141 sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1; 141 sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
142 for (i = 0; i < RMC_BUCKETS; i++) 142 for (i = 0; i < RMC_BUCKETS; i++)
143 INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list); 143 INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list);
144 return 0; 144 return 0;
145 } 145 }
146 146
147 void mesh_rmc_free(struct ieee80211_sub_if_data *sdata) 147 void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
148 { 148 {
149 struct mesh_rmc *rmc = sdata->u.mesh.rmc; 149 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
150 struct rmc_entry *p, *n; 150 struct rmc_entry *p, *n;
151 int i; 151 int i;
152 152
153 if (!sdata->u.mesh.rmc) 153 if (!sdata->u.mesh.rmc)
154 return; 154 return;
155 155
156 for (i = 0; i < RMC_BUCKETS; i++) 156 for (i = 0; i < RMC_BUCKETS; i++)
157 list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) { 157 list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
158 list_del(&p->list); 158 list_del(&p->list);
159 kmem_cache_free(rm_cache, p); 159 kmem_cache_free(rm_cache, p);
160 } 160 }
161 161
162 kfree(rmc); 162 kfree(rmc);
163 sdata->u.mesh.rmc = NULL; 163 sdata->u.mesh.rmc = NULL;
164 } 164 }
165 165
166 /** 166 /**
167 * mesh_rmc_check - Check frame in recent multicast cache and add if absent. 167 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
168 * 168 *
169 * @sa: source address 169 * @sa: source address
170 * @mesh_hdr: mesh_header 170 * @mesh_hdr: mesh_header
171 * 171 *
172 * Returns: 0 if the frame is not in the cache, nonzero otherwise. 172 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
173 * 173 *
174 * Checks using the source address and the mesh sequence number if we have 174 * Checks using the source address and the mesh sequence number if we have
175 * received this frame lately. If the frame is not in the cache, it is added to 175 * received this frame lately. If the frame is not in the cache, it is added to
176 * it. 176 * it.
177 */ 177 */
178 int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr, 178 int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
179 struct ieee80211_sub_if_data *sdata) 179 struct ieee80211_sub_if_data *sdata)
180 { 180 {
181 struct mesh_rmc *rmc = sdata->u.mesh.rmc; 181 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
182 u32 seqnum = 0; 182 u32 seqnum = 0;
183 int entries = 0; 183 int entries = 0;
184 u8 idx; 184 u8 idx;
185 struct rmc_entry *p, *n; 185 struct rmc_entry *p, *n;
186 186
187 /* Don't care about endianness since only match matters */ 187 /* Don't care about endianness since only match matters */
188 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum)); 188 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
189 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask; 189 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
190 list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) { 190 list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
191 ++entries; 191 ++entries;
192 if (time_after(jiffies, p->exp_time) || 192 if (time_after(jiffies, p->exp_time) ||
193 (entries == RMC_QUEUE_MAX_LEN)) { 193 (entries == RMC_QUEUE_MAX_LEN)) {
194 list_del(&p->list); 194 list_del(&p->list);
195 kmem_cache_free(rm_cache, p); 195 kmem_cache_free(rm_cache, p);
196 --entries; 196 --entries;
197 } else if ((seqnum == p->seqnum) && 197 } else if ((seqnum == p->seqnum) &&
198 (memcmp(sa, p->sa, ETH_ALEN) == 0)) 198 (memcmp(sa, p->sa, ETH_ALEN) == 0))
199 return -1; 199 return -1;
200 } 200 }
201 201
202 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC); 202 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
203 if (!p) 203 if (!p)
204 return 0; 204 return 0;
205 205
206 p->seqnum = seqnum; 206 p->seqnum = seqnum;
207 p->exp_time = jiffies + RMC_TIMEOUT; 207 p->exp_time = jiffies + RMC_TIMEOUT;
208 memcpy(p->sa, sa, ETH_ALEN); 208 memcpy(p->sa, sa, ETH_ALEN);
209 list_add(&p->list, &rmc->bucket[idx].list); 209 list_add(&p->list, &rmc->bucket[idx].list);
210 return 0; 210 return 0;
211 } 211 }
212 212
213 int 213 int
214 mesh_add_meshconf_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) 214 mesh_add_meshconf_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
215 { 215 {
216 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 216 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
217 u8 *pos, neighbors; 217 u8 *pos, neighbors;
218 u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie); 218 u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie);
219 219
220 if (skb_tailroom(skb) < 2 + meshconf_len) 220 if (skb_tailroom(skb) < 2 + meshconf_len)
221 return -ENOMEM; 221 return -ENOMEM;
222 222
223 pos = skb_put(skb, 2 + meshconf_len); 223 pos = skb_put(skb, 2 + meshconf_len);
224 *pos++ = WLAN_EID_MESH_CONFIG; 224 *pos++ = WLAN_EID_MESH_CONFIG;
225 *pos++ = meshconf_len; 225 *pos++ = meshconf_len;
226 226
227 /* Active path selection protocol ID */ 227 /* Active path selection protocol ID */
228 *pos++ = ifmsh->mesh_pp_id; 228 *pos++ = ifmsh->mesh_pp_id;
229 /* Active path selection metric ID */ 229 /* Active path selection metric ID */
230 *pos++ = ifmsh->mesh_pm_id; 230 *pos++ = ifmsh->mesh_pm_id;
231 /* Congestion control mode identifier */ 231 /* Congestion control mode identifier */
232 *pos++ = ifmsh->mesh_cc_id; 232 *pos++ = ifmsh->mesh_cc_id;
233 /* Synchronization protocol identifier */ 233 /* Synchronization protocol identifier */
234 *pos++ = ifmsh->mesh_sp_id; 234 *pos++ = ifmsh->mesh_sp_id;
235 /* Authentication Protocol identifier */ 235 /* Authentication Protocol identifier */
236 *pos++ = ifmsh->mesh_auth_id; 236 *pos++ = ifmsh->mesh_auth_id;
237 /* Mesh Formation Info - number of neighbors */ 237 /* Mesh Formation Info - number of neighbors */
238 neighbors = atomic_read(&ifmsh->mshstats.estab_plinks); 238 neighbors = atomic_read(&ifmsh->mshstats.estab_plinks);
239 /* Number of neighbor mesh STAs or 15 whichever is smaller */ 239 /* Number of neighbor mesh STAs or 15 whichever is smaller */
240 neighbors = (neighbors > 15) ? 15 : neighbors; 240 neighbors = (neighbors > 15) ? 15 : neighbors;
241 *pos++ = neighbors << 1; 241 *pos++ = neighbors << 1;
242 /* Mesh capability */ 242 /* Mesh capability */
243 ifmsh->accepting_plinks = mesh_plink_availables(sdata); 243 ifmsh->accepting_plinks = mesh_plink_availables(sdata);
244 *pos = MESHCONF_CAPAB_FORWARDING; 244 *pos = MESHCONF_CAPAB_FORWARDING;
245 *pos++ |= ifmsh->accepting_plinks ? 245 *pos++ |= ifmsh->accepting_plinks ?
246 MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00; 246 MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
247 *pos++ = 0x00; 247 *pos++ = 0x00;
248 248
249 return 0; 249 return 0;
250 } 250 }
251 251
252 int 252 int
253 mesh_add_meshid_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) 253 mesh_add_meshid_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
254 { 254 {
255 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 255 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
256 u8 *pos; 256 u8 *pos;
257 257
258 if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len) 258 if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
259 return -ENOMEM; 259 return -ENOMEM;
260 260
261 pos = skb_put(skb, 2 + ifmsh->mesh_id_len); 261 pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
262 *pos++ = WLAN_EID_MESH_ID; 262 *pos++ = WLAN_EID_MESH_ID;
263 *pos++ = ifmsh->mesh_id_len; 263 *pos++ = ifmsh->mesh_id_len;
264 if (ifmsh->mesh_id_len) 264 if (ifmsh->mesh_id_len)
265 memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len); 265 memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
266 266
267 return 0; 267 return 0;
268 } 268 }
269 269
270 int 270 int
271 mesh_add_vendor_ies(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) 271 mesh_add_vendor_ies(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
272 { 272 {
273 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 273 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
274 u8 offset, len; 274 u8 offset, len;
275 const u8 *data; 275 const u8 *data;
276 276
277 if (!ifmsh->ie || !ifmsh->ie_len) 277 if (!ifmsh->ie || !ifmsh->ie_len)
278 return 0; 278 return 0;
279 279
280 /* fast-forward to vendor IEs */ 280 /* fast-forward to vendor IEs */
281 offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0); 281 offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
282 282
283 if (offset) { 283 if (offset) {
284 len = ifmsh->ie_len - offset; 284 len = ifmsh->ie_len - offset;
285 data = ifmsh->ie + offset; 285 data = ifmsh->ie + offset;
286 if (skb_tailroom(skb) < len) 286 if (skb_tailroom(skb) < len)
287 return -ENOMEM; 287 return -ENOMEM;
288 memcpy(skb_put(skb, len), data, len); 288 memcpy(skb_put(skb, len), data, len);
289 } 289 }
290 290
291 return 0; 291 return 0;
292 } 292 }
293 293
294 int 294 int
295 mesh_add_rsn_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) 295 mesh_add_rsn_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
296 { 296 {
297 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 297 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
298 u8 len = 0; 298 u8 len = 0;
299 const u8 *data; 299 const u8 *data;
300 300
301 if (!ifmsh->ie || !ifmsh->ie_len) 301 if (!ifmsh->ie || !ifmsh->ie_len)
302 return 0; 302 return 0;
303 303
304 /* find RSN IE */ 304 /* find RSN IE */
305 data = ifmsh->ie; 305 data = ifmsh->ie;
306 while (data < ifmsh->ie + ifmsh->ie_len) { 306 while (data < ifmsh->ie + ifmsh->ie_len) {
307 if (*data == WLAN_EID_RSN) { 307 if (*data == WLAN_EID_RSN) {
308 len = data[1] + 2; 308 len = data[1] + 2;
309 break; 309 break;
310 } 310 }
311 data++; 311 data++;
312 } 312 }
313 313
314 if (len) { 314 if (len) {
315 if (skb_tailroom(skb) < len) 315 if (skb_tailroom(skb) < len)
316 return -ENOMEM; 316 return -ENOMEM;
317 memcpy(skb_put(skb, len), data, len); 317 memcpy(skb_put(skb, len), data, len);
318 } 318 }
319 319
320 return 0; 320 return 0;
321 } 321 }
322 322
323 int mesh_add_ds_params_ie(struct sk_buff *skb, 323 int mesh_add_ds_params_ie(struct sk_buff *skb,
324 struct ieee80211_sub_if_data *sdata) 324 struct ieee80211_sub_if_data *sdata)
325 { 325 {
326 struct ieee80211_local *local = sdata->local; 326 struct ieee80211_local *local = sdata->local;
327 struct ieee80211_supported_band *sband; 327 struct ieee80211_supported_band *sband;
328 u8 *pos; 328 u8 *pos;
329 329
330 if (skb_tailroom(skb) < 3) 330 if (skb_tailroom(skb) < 3)
331 return -ENOMEM; 331 return -ENOMEM;
332 332
333 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 333 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
334 if (sband->band == IEEE80211_BAND_2GHZ) { 334 if (sband->band == IEEE80211_BAND_2GHZ) {
335 pos = skb_put(skb, 2 + 1); 335 pos = skb_put(skb, 2 + 1);
336 *pos++ = WLAN_EID_DS_PARAMS; 336 *pos++ = WLAN_EID_DS_PARAMS;
337 *pos++ = 1; 337 *pos++ = 1;
338 *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq); 338 *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
339 } 339 }
340 340
341 return 0; 341 return 0;
342 } 342 }
343 343
344 int mesh_add_ht_cap_ie(struct sk_buff *skb,
345 struct ieee80211_sub_if_data *sdata)
346 {
347 struct ieee80211_local *local = sdata->local;
348 struct ieee80211_supported_band *sband;
349 u8 *pos;
350
351 sband = local->hw.wiphy->bands[local->oper_channel->band];
352 if (!sband->ht_cap.ht_supported ||
353 local->_oper_channel_type == NL80211_CHAN_NO_HT)
354 return 0;
355
356 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
357 return -ENOMEM;
358
359 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
360 ieee80211_ie_build_ht_cap(pos, sband, sband->ht_cap.cap);
361
362 return 0;
363 }
364
365 int mesh_add_ht_info_ie(struct sk_buff *skb,
366 struct ieee80211_sub_if_data *sdata)
367 {
368 struct ieee80211_local *local = sdata->local;
369 struct ieee80211_channel *channel = local->oper_channel;
370 enum nl80211_channel_type channel_type = local->_oper_channel_type;
371 struct ieee80211_supported_band *sband =
372 local->hw.wiphy->bands[channel->band];
373 struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap;
374 u8 *pos;
375
376 if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
377 return 0;
378
379 if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_info))
380 return -ENOMEM;
381
382 pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_info));
383 ieee80211_ie_build_ht_info(pos, ht_cap, channel, channel_type);
384
385 return 0;
386 }
344 static void ieee80211_mesh_path_timer(unsigned long data) 387 static void ieee80211_mesh_path_timer(unsigned long data)
345 { 388 {
346 struct ieee80211_sub_if_data *sdata = 389 struct ieee80211_sub_if_data *sdata =
347 (struct ieee80211_sub_if_data *) data; 390 (struct ieee80211_sub_if_data *) data;
348 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 391 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
349 struct ieee80211_local *local = sdata->local; 392 struct ieee80211_local *local = sdata->local;
350 393
351 if (local->quiescing) { 394 if (local->quiescing) {
352 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running); 395 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
353 return; 396 return;
354 } 397 }
355 398
356 ieee80211_queue_work(&local->hw, &sdata->work); 399 ieee80211_queue_work(&local->hw, &sdata->work);
357 } 400 }
358 401
359 static void ieee80211_mesh_path_root_timer(unsigned long data) 402 static void ieee80211_mesh_path_root_timer(unsigned long data)
360 { 403 {
361 struct ieee80211_sub_if_data *sdata = 404 struct ieee80211_sub_if_data *sdata =
362 (struct ieee80211_sub_if_data *) data; 405 (struct ieee80211_sub_if_data *) data;
363 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 406 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
364 struct ieee80211_local *local = sdata->local; 407 struct ieee80211_local *local = sdata->local;
365 408
366 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); 409 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
367 410
368 if (local->quiescing) { 411 if (local->quiescing) {
369 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running); 412 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
370 return; 413 return;
371 } 414 }
372 415
373 ieee80211_queue_work(&local->hw, &sdata->work); 416 ieee80211_queue_work(&local->hw, &sdata->work);
374 } 417 }
375 418
376 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh) 419 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
377 { 420 {
378 if (ifmsh->mshcfg.dot11MeshHWMPRootMode) 421 if (ifmsh->mshcfg.dot11MeshHWMPRootMode)
379 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); 422 set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
380 else { 423 else {
381 clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); 424 clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
382 /* stop running timer */ 425 /* stop running timer */
383 del_timer_sync(&ifmsh->mesh_path_root_timer); 426 del_timer_sync(&ifmsh->mesh_path_root_timer);
384 } 427 }
385 } 428 }
386 429
387 /** 430 /**
388 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame 431 * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
389 * @hdr: 802.11 frame header 432 * @hdr: 802.11 frame header
390 * @fc: frame control field 433 * @fc: frame control field
391 * @meshda: destination address in the mesh 434 * @meshda: destination address in the mesh
392 * @meshsa: source address address in the mesh. Same as TA, as frame is 435 * @meshsa: source address address in the mesh. Same as TA, as frame is
393 * locally originated. 436 * locally originated.
394 * 437 *
395 * Return the length of the 802.11 (does not include a mesh control header) 438 * Return the length of the 802.11 (does not include a mesh control header)
396 */ 439 */
397 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, 440 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
398 const u8 *meshda, const u8 *meshsa) 441 const u8 *meshda, const u8 *meshsa)
399 { 442 {
400 if (is_multicast_ether_addr(meshda)) { 443 if (is_multicast_ether_addr(meshda)) {
401 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 444 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
402 /* DA TA SA */ 445 /* DA TA SA */
403 memcpy(hdr->addr1, meshda, ETH_ALEN); 446 memcpy(hdr->addr1, meshda, ETH_ALEN);
404 memcpy(hdr->addr2, meshsa, ETH_ALEN); 447 memcpy(hdr->addr2, meshsa, ETH_ALEN);
405 memcpy(hdr->addr3, meshsa, ETH_ALEN); 448 memcpy(hdr->addr3, meshsa, ETH_ALEN);
406 return 24; 449 return 24;
407 } else { 450 } else {
408 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 451 *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
409 /* RA TA DA SA */ 452 /* RA TA DA SA */
410 memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */ 453 memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
411 memcpy(hdr->addr2, meshsa, ETH_ALEN); 454 memcpy(hdr->addr2, meshsa, ETH_ALEN);
412 memcpy(hdr->addr3, meshda, ETH_ALEN); 455 memcpy(hdr->addr3, meshda, ETH_ALEN);
413 memcpy(hdr->addr4, meshsa, ETH_ALEN); 456 memcpy(hdr->addr4, meshsa, ETH_ALEN);
414 return 30; 457 return 30;
415 } 458 }
416 } 459 }
417 460
418 /** 461 /**
419 * ieee80211_new_mesh_header - create a new mesh header 462 * ieee80211_new_mesh_header - create a new mesh header
420 * @meshhdr: uninitialized mesh header 463 * @meshhdr: uninitialized mesh header
421 * @sdata: mesh interface to be used 464 * @sdata: mesh interface to be used
422 * @addr4or5: 1st address in the ae header, which may correspond to address 4 465 * @addr4or5: 1st address in the ae header, which may correspond to address 4
423 * (if addr6 is NULL) or address 5 (if addr6 is present). It may 466 * (if addr6 is NULL) or address 5 (if addr6 is present). It may
424 * be NULL. 467 * be NULL.
425 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the 468 * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
426 * mesh frame 469 * mesh frame
427 * 470 *
428 * Return the header length. 471 * Return the header length.
429 */ 472 */
430 int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr, 473 int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
431 struct ieee80211_sub_if_data *sdata, char *addr4or5, 474 struct ieee80211_sub_if_data *sdata, char *addr4or5,
432 char *addr6) 475 char *addr6)
433 { 476 {
434 int aelen = 0; 477 int aelen = 0;
435 BUG_ON(!addr4or5 && addr6); 478 BUG_ON(!addr4or5 && addr6);
436 memset(meshhdr, 0, sizeof(*meshhdr)); 479 memset(meshhdr, 0, sizeof(*meshhdr));
437 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; 480 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
438 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum); 481 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
439 sdata->u.mesh.mesh_seqnum++; 482 sdata->u.mesh.mesh_seqnum++;
440 if (addr4or5 && !addr6) { 483 if (addr4or5 && !addr6) {
441 meshhdr->flags |= MESH_FLAGS_AE_A4; 484 meshhdr->flags |= MESH_FLAGS_AE_A4;
442 aelen += ETH_ALEN; 485 aelen += ETH_ALEN;
443 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); 486 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
444 } else if (addr4or5 && addr6) { 487 } else if (addr4or5 && addr6) {
445 meshhdr->flags |= MESH_FLAGS_AE_A5_A6; 488 meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
446 aelen += 2 * ETH_ALEN; 489 aelen += 2 * ETH_ALEN;
447 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN); 490 memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
448 memcpy(meshhdr->eaddr2, addr6, ETH_ALEN); 491 memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
449 } 492 }
450 return 6 + aelen; 493 return 6 + aelen;
451 } 494 }
452 495
453 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata, 496 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
454 struct ieee80211_if_mesh *ifmsh) 497 struct ieee80211_if_mesh *ifmsh)
455 { 498 {
456 bool free_plinks; 499 bool free_plinks;
457 500
458 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 501 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
459 printk(KERN_DEBUG "%s: running mesh housekeeping\n", 502 printk(KERN_DEBUG "%s: running mesh housekeeping\n",
460 sdata->name); 503 sdata->name);
461 #endif 504 #endif
462 505
463 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); 506 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
464 mesh_path_expire(sdata); 507 mesh_path_expire(sdata);
465 508
466 free_plinks = mesh_plink_availables(sdata); 509 free_plinks = mesh_plink_availables(sdata);
467 if (free_plinks != sdata->u.mesh.accepting_plinks) 510 if (free_plinks != sdata->u.mesh.accepting_plinks)
468 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); 511 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
469 512
470 mod_timer(&ifmsh->housekeeping_timer, 513 mod_timer(&ifmsh->housekeeping_timer,
471 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); 514 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
472 } 515 }
473 516
474 static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata) 517 static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
475 { 518 {
476 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 519 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
477 520
478 mesh_path_tx_root_frame(sdata); 521 mesh_path_tx_root_frame(sdata);
479 mod_timer(&ifmsh->mesh_path_root_timer, 522 mod_timer(&ifmsh->mesh_path_root_timer,
480 round_jiffies(TU_TO_EXP_TIME( 523 round_jiffies(TU_TO_EXP_TIME(
481 ifmsh->mshcfg.dot11MeshHWMPRannInterval))); 524 ifmsh->mshcfg.dot11MeshHWMPRannInterval)));
482 } 525 }
483 526
484 #ifdef CONFIG_PM 527 #ifdef CONFIG_PM
485 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata) 528 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
486 { 529 {
487 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 530 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
488 531
489 /* use atomic bitops in case all timers fire at the same time */ 532 /* use atomic bitops in case all timers fire at the same time */
490 533
491 if (del_timer_sync(&ifmsh->housekeeping_timer)) 534 if (del_timer_sync(&ifmsh->housekeeping_timer))
492 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running); 535 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
493 if (del_timer_sync(&ifmsh->mesh_path_timer)) 536 if (del_timer_sync(&ifmsh->mesh_path_timer))
494 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running); 537 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
495 if (del_timer_sync(&ifmsh->mesh_path_root_timer)) 538 if (del_timer_sync(&ifmsh->mesh_path_root_timer))
496 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running); 539 set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
497 } 540 }
498 541
499 void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata) 542 void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
500 { 543 {
501 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 544 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
502 545
503 if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running)) 546 if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
504 add_timer(&ifmsh->housekeeping_timer); 547 add_timer(&ifmsh->housekeeping_timer);
505 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running)) 548 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
506 add_timer(&ifmsh->mesh_path_timer); 549 add_timer(&ifmsh->mesh_path_timer);
507 if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running)) 550 if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
508 add_timer(&ifmsh->mesh_path_root_timer); 551 add_timer(&ifmsh->mesh_path_root_timer);
509 ieee80211_mesh_root_setup(ifmsh); 552 ieee80211_mesh_root_setup(ifmsh);
510 } 553 }
511 #endif 554 #endif
512 555
513 void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) 556 void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
514 { 557 {
515 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 558 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
516 struct ieee80211_local *local = sdata->local; 559 struct ieee80211_local *local = sdata->local;
517 560
518 local->fif_other_bss++; 561 local->fif_other_bss++;
519 /* mesh ifaces must set allmulti to forward mcast traffic */ 562 /* mesh ifaces must set allmulti to forward mcast traffic */
520 atomic_inc(&local->iff_allmultis); 563 atomic_inc(&local->iff_allmultis);
521 ieee80211_configure_filter(local); 564 ieee80211_configure_filter(local);
522 565
523 ifmsh->mesh_cc_id = 0; /* Disabled */ 566 ifmsh->mesh_cc_id = 0; /* Disabled */
524 ifmsh->mesh_sp_id = 0; /* Neighbor Offset */ 567 ifmsh->mesh_sp_id = 0; /* Neighbor Offset */
525 ifmsh->mesh_auth_id = 0; /* Disabled */ 568 ifmsh->mesh_auth_id = 0; /* Disabled */
526 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); 569 set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
527 ieee80211_mesh_root_setup(ifmsh); 570 ieee80211_mesh_root_setup(ifmsh);
528 ieee80211_queue_work(&local->hw, &sdata->work); 571 ieee80211_queue_work(&local->hw, &sdata->work);
529 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL; 572 sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
530 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON | 573 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
531 BSS_CHANGED_BEACON_ENABLED | 574 BSS_CHANGED_BEACON_ENABLED |
532 BSS_CHANGED_BEACON_INT); 575 BSS_CHANGED_BEACON_INT);
533 } 576 }
534 577
535 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) 578 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
536 { 579 {
537 struct ieee80211_local *local = sdata->local; 580 struct ieee80211_local *local = sdata->local;
538 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 581 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
539 582
540 ifmsh->mesh_id_len = 0; 583 ifmsh->mesh_id_len = 0;
541 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); 584 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
542 sta_info_flush(local, NULL); 585 sta_info_flush(local, NULL);
543 586
544 del_timer_sync(&sdata->u.mesh.housekeeping_timer); 587 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
545 del_timer_sync(&sdata->u.mesh.mesh_path_root_timer); 588 del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
546 /* 589 /*
547 * If the timer fired while we waited for it, it will have 590 * If the timer fired while we waited for it, it will have
548 * requeued the work. Now the work will be running again 591 * requeued the work. Now the work will be running again
549 * but will not rearm the timer again because it checks 592 * but will not rearm the timer again because it checks
550 * whether the interface is running, which, at this point, 593 * whether the interface is running, which, at this point,
551 * it no longer is. 594 * it no longer is.
552 */ 595 */
553 cancel_work_sync(&sdata->work); 596 cancel_work_sync(&sdata->work);
554 597
555 local->fif_other_bss--; 598 local->fif_other_bss--;
556 atomic_dec(&local->iff_allmultis); 599 atomic_dec(&local->iff_allmultis);
557 ieee80211_configure_filter(local); 600 ieee80211_configure_filter(local);
558 } 601 }
559 602
560 static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, 603 static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
561 u16 stype, 604 u16 stype,
562 struct ieee80211_mgmt *mgmt, 605 struct ieee80211_mgmt *mgmt,
563 size_t len, 606 size_t len,
564 struct ieee80211_rx_status *rx_status) 607 struct ieee80211_rx_status *rx_status)
565 { 608 {
566 struct ieee80211_local *local = sdata->local; 609 struct ieee80211_local *local = sdata->local;
567 struct ieee802_11_elems elems; 610 struct ieee802_11_elems elems;
568 struct ieee80211_channel *channel; 611 struct ieee80211_channel *channel;
569 u32 supp_rates = 0; 612 u32 supp_rates = 0;
570 size_t baselen; 613 size_t baselen;
571 int freq; 614 int freq;
572 enum ieee80211_band band = rx_status->band; 615 enum ieee80211_band band = rx_status->band;
573 616
574 /* ignore ProbeResp to foreign address */ 617 /* ignore ProbeResp to foreign address */
575 if (stype == IEEE80211_STYPE_PROBE_RESP && 618 if (stype == IEEE80211_STYPE_PROBE_RESP &&
576 compare_ether_addr(mgmt->da, sdata->vif.addr)) 619 compare_ether_addr(mgmt->da, sdata->vif.addr))
577 return; 620 return;
578 621
579 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 622 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
580 if (baselen > len) 623 if (baselen > len)
581 return; 624 return;
582 625
583 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, 626 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
584 &elems); 627 &elems);
585 628
586 /* ignore beacons from secure mesh peers if our security is off */ 629 /* ignore beacons from secure mesh peers if our security is off */
587 if (elems.rsn_len && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) 630 if (elems.rsn_len && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE)
588 return; 631 return;
589 632
590 if (elems.ds_params && elems.ds_params_len == 1) 633 if (elems.ds_params && elems.ds_params_len == 1)
591 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band); 634 freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
592 else 635 else
593 freq = rx_status->freq; 636 freq = rx_status->freq;
594 637
595 channel = ieee80211_get_channel(local->hw.wiphy, freq); 638 channel = ieee80211_get_channel(local->hw.wiphy, freq);
596 639
597 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) 640 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
598 return; 641 return;
599 642
600 if (elems.mesh_id && elems.mesh_config && 643 if (elems.mesh_id && elems.mesh_config &&
601 mesh_matches_local(&elems, sdata)) { 644 mesh_matches_local(&elems, sdata)) {
602 supp_rates = ieee80211_sta_get_rates(local, &elems, band); 645 supp_rates = ieee80211_sta_get_rates(local, &elems, band);
603 mesh_neighbour_update(mgmt->sa, supp_rates, sdata, &elems); 646 mesh_neighbour_update(mgmt->sa, supp_rates, sdata, &elems);
604 } 647 }
605 } 648 }
606 649
607 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, 650 static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
608 struct ieee80211_mgmt *mgmt, 651 struct ieee80211_mgmt *mgmt,
609 size_t len, 652 size_t len,
610 struct ieee80211_rx_status *rx_status) 653 struct ieee80211_rx_status *rx_status)
611 { 654 {
612 switch (mgmt->u.action.category) { 655 switch (mgmt->u.action.category) {
613 case WLAN_CATEGORY_SELF_PROTECTED: 656 case WLAN_CATEGORY_SELF_PROTECTED:
614 switch (mgmt->u.action.u.self_prot.action_code) { 657 switch (mgmt->u.action.u.self_prot.action_code) {
615 case WLAN_SP_MESH_PEERING_OPEN: 658 case WLAN_SP_MESH_PEERING_OPEN:
616 case WLAN_SP_MESH_PEERING_CLOSE: 659 case WLAN_SP_MESH_PEERING_CLOSE:
617 case WLAN_SP_MESH_PEERING_CONFIRM: 660 case WLAN_SP_MESH_PEERING_CONFIRM:
618 mesh_rx_plink_frame(sdata, mgmt, len, rx_status); 661 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
619 break; 662 break;
620 } 663 }
621 break; 664 break;
622 case WLAN_CATEGORY_MESH_ACTION: 665 case WLAN_CATEGORY_MESH_ACTION:
623 if (mesh_action_is_path_sel(mgmt)) 666 if (mesh_action_is_path_sel(mgmt))
624 mesh_rx_path_sel_frame(sdata, mgmt, len); 667 mesh_rx_path_sel_frame(sdata, mgmt, len);
625 break; 668 break;
626 } 669 }
627 } 670 }
628 671
629 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 672 void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
630 struct sk_buff *skb) 673 struct sk_buff *skb)
631 { 674 {
632 struct ieee80211_rx_status *rx_status; 675 struct ieee80211_rx_status *rx_status;
633 struct ieee80211_mgmt *mgmt; 676 struct ieee80211_mgmt *mgmt;
634 u16 stype; 677 u16 stype;
635 678
636 rx_status = IEEE80211_SKB_RXCB(skb); 679 rx_status = IEEE80211_SKB_RXCB(skb);
637 mgmt = (struct ieee80211_mgmt *) skb->data; 680 mgmt = (struct ieee80211_mgmt *) skb->data;
638 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; 681 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
639 682
640 switch (stype) { 683 switch (stype) {
641 case IEEE80211_STYPE_PROBE_RESP: 684 case IEEE80211_STYPE_PROBE_RESP:
642 case IEEE80211_STYPE_BEACON: 685 case IEEE80211_STYPE_BEACON:
643 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len, 686 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
644 rx_status); 687 rx_status);
645 break; 688 break;
646 case IEEE80211_STYPE_ACTION: 689 case IEEE80211_STYPE_ACTION:
647 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status); 690 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
648 break; 691 break;
649 } 692 }
650 } 693 }
651 694
652 void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata) 695 void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
653 { 696 {
654 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 697 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
655 698
656 if (ifmsh->preq_queue_len && 699 if (ifmsh->preq_queue_len &&
657 time_after(jiffies, 700 time_after(jiffies,
658 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval))) 701 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
659 mesh_path_start_discovery(sdata); 702 mesh_path_start_discovery(sdata);
660 703
661 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags)) 704 if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
662 mesh_mpath_table_grow(); 705 mesh_mpath_table_grow();
663 706
664 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags)) 707 if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
665 mesh_mpp_table_grow(); 708 mesh_mpp_table_grow();
666 709
667 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags)) 710 if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
668 ieee80211_mesh_housekeeping(sdata, ifmsh); 711 ieee80211_mesh_housekeeping(sdata, ifmsh);
669 712
670 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags)) 713 if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
671 ieee80211_mesh_rootpath(sdata); 714 ieee80211_mesh_rootpath(sdata);
672 } 715 }
673 716
674 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) 717 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
675 { 718 {
676 struct ieee80211_sub_if_data *sdata; 719 struct ieee80211_sub_if_data *sdata;
677 720
678 rcu_read_lock(); 721 rcu_read_lock();
679 list_for_each_entry_rcu(sdata, &local->interfaces, list) 722 list_for_each_entry_rcu(sdata, &local->interfaces, list)
680 if (ieee80211_vif_is_mesh(&sdata->vif)) 723 if (ieee80211_vif_is_mesh(&sdata->vif))
681 ieee80211_queue_work(&local->hw, &sdata->work); 724 ieee80211_queue_work(&local->hw, &sdata->work);
682 rcu_read_unlock(); 725 rcu_read_unlock();
683 } 726 }
684 727
685 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) 728 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
686 { 729 {
687 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 730 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
688 731
689 setup_timer(&ifmsh->housekeeping_timer, 732 setup_timer(&ifmsh->housekeeping_timer,
690 ieee80211_mesh_housekeeping_timer, 733 ieee80211_mesh_housekeeping_timer,
691 (unsigned long) sdata); 734 (unsigned long) sdata);
692 735
693 ifmsh->accepting_plinks = true; 736 ifmsh->accepting_plinks = true;
694 ifmsh->preq_id = 0; 737 ifmsh->preq_id = 0;
695 ifmsh->sn = 0; 738 ifmsh->sn = 0;
696 ifmsh->num_gates = 0; 739 ifmsh->num_gates = 0;
697 atomic_set(&ifmsh->mpaths, 0); 740 atomic_set(&ifmsh->mpaths, 0);
698 mesh_rmc_init(sdata); 741 mesh_rmc_init(sdata);
699 ifmsh->last_preq = jiffies; 742 ifmsh->last_preq = jiffies;
700 /* Allocate all mesh structures when creating the first mesh interface. */ 743 /* Allocate all mesh structures when creating the first mesh interface. */
701 if (!mesh_allocated) 744 if (!mesh_allocated)
702 ieee80211s_init(); 745 ieee80211s_init();
703 setup_timer(&ifmsh->mesh_path_timer, 746 setup_timer(&ifmsh->mesh_path_timer,
704 ieee80211_mesh_path_timer, 747 ieee80211_mesh_path_timer,
705 (unsigned long) sdata); 748 (unsigned long) sdata);
706 setup_timer(&ifmsh->mesh_path_root_timer, 749 setup_timer(&ifmsh->mesh_path_root_timer,
707 ieee80211_mesh_path_root_timer, 750 ieee80211_mesh_path_root_timer,
708 (unsigned long) sdata); 751 (unsigned long) sdata);
709 INIT_LIST_HEAD(&ifmsh->preq_queue.list); 752 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
710 spin_lock_init(&ifmsh->mesh_preq_queue_lock); 753 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
711 } 754 }
712 755
1 /* 1 /*
2 * Copyright (c) 2008, 2009 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com> 3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com> 4 * Javier Cardona <javier@cozybit.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11 #ifndef IEEE80211S_H 11 #ifndef IEEE80211S_H
12 #define IEEE80211S_H 12 #define IEEE80211S_H
13 13
14 #include <linux/types.h> 14 #include <linux/types.h>
15 #include <linux/jhash.h> 15 #include <linux/jhash.h>
16 #include <asm/unaligned.h> 16 #include <asm/unaligned.h>
17 #include "ieee80211_i.h" 17 #include "ieee80211_i.h"
18 18
19 19
20 /* Data structures */ 20 /* Data structures */
21 21
22 /** 22 /**
23 * enum mesh_path_flags - mac80211 mesh path flags 23 * enum mesh_path_flags - mac80211 mesh path flags
24 * 24 *
25 * 25 *
26 * 26 *
27 * @MESH_PATH_ACTIVE: the mesh path can be used for forwarding 27 * @MESH_PATH_ACTIVE: the mesh path can be used for forwarding
28 * @MESH_PATH_RESOLVING: the discovery process is running for this mesh path 28 * @MESH_PATH_RESOLVING: the discovery process is running for this mesh path
29 * @MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence 29 * @MESH_PATH_SN_VALID: the mesh path contains a valid destination sequence
30 * number 30 * number
31 * @MESH_PATH_FIXED: the mesh path has been manually set and should not be 31 * @MESH_PATH_FIXED: the mesh path has been manually set and should not be
32 * modified 32 * modified
33 * @MESH_PATH_RESOLVED: the mesh path can has been resolved 33 * @MESH_PATH_RESOLVED: the mesh path can has been resolved
34 * 34 *
35 * MESH_PATH_RESOLVED is used by the mesh path timer to 35 * MESH_PATH_RESOLVED is used by the mesh path timer to
36 * decide when to stop or cancel the mesh path discovery. 36 * decide when to stop or cancel the mesh path discovery.
37 */ 37 */
38 enum mesh_path_flags { 38 enum mesh_path_flags {
39 MESH_PATH_ACTIVE = BIT(0), 39 MESH_PATH_ACTIVE = BIT(0),
40 MESH_PATH_RESOLVING = BIT(1), 40 MESH_PATH_RESOLVING = BIT(1),
41 MESH_PATH_SN_VALID = BIT(2), 41 MESH_PATH_SN_VALID = BIT(2),
42 MESH_PATH_FIXED = BIT(3), 42 MESH_PATH_FIXED = BIT(3),
43 MESH_PATH_RESOLVED = BIT(4), 43 MESH_PATH_RESOLVED = BIT(4),
44 }; 44 };
45 45
46 /** 46 /**
47 * enum mesh_deferred_task_flags - mac80211 mesh deferred tasks 47 * enum mesh_deferred_task_flags - mac80211 mesh deferred tasks
48 * 48 *
49 * 49 *
50 * 50 *
51 * @MESH_WORK_HOUSEKEEPING: run the periodic mesh housekeeping tasks 51 * @MESH_WORK_HOUSEKEEPING: run the periodic mesh housekeeping tasks
52 * @MESH_WORK_GROW_MPATH_TABLE: the mesh path table is full and needs 52 * @MESH_WORK_GROW_MPATH_TABLE: the mesh path table is full and needs
53 * to grow. 53 * to grow.
54 * @MESH_WORK_GROW_MPP_TABLE: the mesh portals table is full and needs to 54 * @MESH_WORK_GROW_MPP_TABLE: the mesh portals table is full and needs to
55 * grow 55 * grow
56 * @MESH_WORK_ROOT: the mesh root station needs to send a frame 56 * @MESH_WORK_ROOT: the mesh root station needs to send a frame
57 */ 57 */
58 enum mesh_deferred_task_flags { 58 enum mesh_deferred_task_flags {
59 MESH_WORK_HOUSEKEEPING, 59 MESH_WORK_HOUSEKEEPING,
60 MESH_WORK_GROW_MPATH_TABLE, 60 MESH_WORK_GROW_MPATH_TABLE,
61 MESH_WORK_GROW_MPP_TABLE, 61 MESH_WORK_GROW_MPP_TABLE,
62 MESH_WORK_ROOT, 62 MESH_WORK_ROOT,
63 }; 63 };
64 64
65 /** 65 /**
66 * struct mesh_path - mac80211 mesh path structure 66 * struct mesh_path - mac80211 mesh path structure
67 * 67 *
68 * @dst: mesh path destination mac address 68 * @dst: mesh path destination mac address
69 * @sdata: mesh subif 69 * @sdata: mesh subif
70 * @next_hop: mesh neighbor to which frames for this destination will be 70 * @next_hop: mesh neighbor to which frames for this destination will be
71 * forwarded 71 * forwarded
72 * @timer: mesh path discovery timer 72 * @timer: mesh path discovery timer
73 * @frame_queue: pending queue for frames sent to this destination while the 73 * @frame_queue: pending queue for frames sent to this destination while the
74 * path is unresolved 74 * path is unresolved
75 * @sn: target sequence number 75 * @sn: target sequence number
76 * @metric: current metric to this destination 76 * @metric: current metric to this destination
77 * @hop_count: hops to destination 77 * @hop_count: hops to destination
78 * @exp_time: in jiffies, when the path will expire or when it expired 78 * @exp_time: in jiffies, when the path will expire or when it expired
79 * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery 79 * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
80 * retry 80 * retry
81 * @discovery_retries: number of discovery retries 81 * @discovery_retries: number of discovery retries
82 * @flags: mesh path flags, as specified on &enum mesh_path_flags 82 * @flags: mesh path flags, as specified on &enum mesh_path_flags
83 * @state_lock: mesh path state lock used to protect changes to the 83 * @state_lock: mesh path state lock used to protect changes to the
84 * mpath itself. No need to take this lock when adding or removing 84 * mpath itself. No need to take this lock when adding or removing
85 * an mpath to a hash bucket on a path table. 85 * an mpath to a hash bucket on a path table.
86 * @is_gate: the destination station of this path is a mesh gate 86 * @is_gate: the destination station of this path is a mesh gate
87 * 87 *
88 * 88 *
89 * The combination of dst and sdata is unique in the mesh path table. Since the 89 * The combination of dst and sdata is unique in the mesh path table. Since the
90 * next_hop STA is only protected by RCU as well, deleting the STA must also 90 * next_hop STA is only protected by RCU as well, deleting the STA must also
91 * remove/substitute the mesh_path structure and wait until that is no longer 91 * remove/substitute the mesh_path structure and wait until that is no longer
92 * reachable before destroying the STA completely. 92 * reachable before destroying the STA completely.
93 */ 93 */
94 struct mesh_path { 94 struct mesh_path {
95 u8 dst[ETH_ALEN]; 95 u8 dst[ETH_ALEN];
96 u8 mpp[ETH_ALEN]; /* used for MPP or MAP */ 96 u8 mpp[ETH_ALEN]; /* used for MPP or MAP */
97 struct ieee80211_sub_if_data *sdata; 97 struct ieee80211_sub_if_data *sdata;
98 struct sta_info __rcu *next_hop; 98 struct sta_info __rcu *next_hop;
99 struct timer_list timer; 99 struct timer_list timer;
100 struct sk_buff_head frame_queue; 100 struct sk_buff_head frame_queue;
101 struct rcu_head rcu; 101 struct rcu_head rcu;
102 u32 sn; 102 u32 sn;
103 u32 metric; 103 u32 metric;
104 u8 hop_count; 104 u8 hop_count;
105 unsigned long exp_time; 105 unsigned long exp_time;
106 u32 discovery_timeout; 106 u32 discovery_timeout;
107 u8 discovery_retries; 107 u8 discovery_retries;
108 enum mesh_path_flags flags; 108 enum mesh_path_flags flags;
109 spinlock_t state_lock; 109 spinlock_t state_lock;
110 bool is_gate; 110 bool is_gate;
111 }; 111 };
112 112
113 /** 113 /**
114 * struct mesh_table 114 * struct mesh_table
115 * 115 *
116 * @hash_buckets: array of hash buckets of the table 116 * @hash_buckets: array of hash buckets of the table
117 * @hashwlock: array of locks to protect write operations, one per bucket 117 * @hashwlock: array of locks to protect write operations, one per bucket
118 * @hash_mask: 2^size_order - 1, used to compute hash idx 118 * @hash_mask: 2^size_order - 1, used to compute hash idx
119 * @hash_rnd: random value used for hash computations 119 * @hash_rnd: random value used for hash computations
120 * @entries: number of entries in the table 120 * @entries: number of entries in the table
121 * @free_node: function to free nodes of the table 121 * @free_node: function to free nodes of the table
122 * @copy_node: function to copy nodes of the table 122 * @copy_node: function to copy nodes of the table
123 * @size_order: determines size of the table, there will be 2^size_order hash 123 * @size_order: determines size of the table, there will be 2^size_order hash
124 * buckets 124 * buckets
125 * @mean_chain_len: maximum average length for the hash buckets' list, if it is 125 * @mean_chain_len: maximum average length for the hash buckets' list, if it is
126 * reached, the table will grow 126 * reached, the table will grow
127 * @known_gates: list of known mesh gates and their mpaths by the station. The 127 * @known_gates: list of known mesh gates and their mpaths by the station. The
128 * gate's mpath may or may not be resolved and active. 128 * gate's mpath may or may not be resolved and active.
129 * 129 *
130 * rcu_head: RCU head to free the table 130 * rcu_head: RCU head to free the table
131 */ 131 */
132 struct mesh_table { 132 struct mesh_table {
133 /* Number of buckets will be 2^N */ 133 /* Number of buckets will be 2^N */
134 struct hlist_head *hash_buckets; 134 struct hlist_head *hash_buckets;
135 spinlock_t *hashwlock; /* One per bucket, for add/del */ 135 spinlock_t *hashwlock; /* One per bucket, for add/del */
136 unsigned int hash_mask; /* (2^size_order) - 1 */ 136 unsigned int hash_mask; /* (2^size_order) - 1 */
137 __u32 hash_rnd; /* Used for hash generation */ 137 __u32 hash_rnd; /* Used for hash generation */
138 atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */ 138 atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
139 void (*free_node) (struct hlist_node *p, bool free_leafs); 139 void (*free_node) (struct hlist_node *p, bool free_leafs);
140 int (*copy_node) (struct hlist_node *p, struct mesh_table *newtbl); 140 int (*copy_node) (struct hlist_node *p, struct mesh_table *newtbl);
141 int size_order; 141 int size_order;
142 int mean_chain_len; 142 int mean_chain_len;
143 struct hlist_head *known_gates; 143 struct hlist_head *known_gates;
144 spinlock_t gates_lock; 144 spinlock_t gates_lock;
145 145
146 struct rcu_head rcu_head; 146 struct rcu_head rcu_head;
147 }; 147 };
148 148
149 /* Recent multicast cache */ 149 /* Recent multicast cache */
150 /* RMC_BUCKETS must be a power of 2, maximum 256 */ 150 /* RMC_BUCKETS must be a power of 2, maximum 256 */
151 #define RMC_BUCKETS 256 151 #define RMC_BUCKETS 256
152 #define RMC_QUEUE_MAX_LEN 4 152 #define RMC_QUEUE_MAX_LEN 4
153 #define RMC_TIMEOUT (3 * HZ) 153 #define RMC_TIMEOUT (3 * HZ)
154 154
155 /** 155 /**
156 * struct rmc_entry - entry in the Recent Multicast Cache 156 * struct rmc_entry - entry in the Recent Multicast Cache
157 * 157 *
158 * @seqnum: mesh sequence number of the frame 158 * @seqnum: mesh sequence number of the frame
159 * @exp_time: expiration time of the entry, in jiffies 159 * @exp_time: expiration time of the entry, in jiffies
160 * @sa: source address of the frame 160 * @sa: source address of the frame
161 * 161 *
162 * The Recent Multicast Cache keeps track of the latest multicast frames that 162 * The Recent Multicast Cache keeps track of the latest multicast frames that
163 * have been received by a mesh interface and discards received multicast frames 163 * have been received by a mesh interface and discards received multicast frames
164 * that are found in the cache. 164 * that are found in the cache.
165 */ 165 */
166 struct rmc_entry { 166 struct rmc_entry {
167 struct list_head list; 167 struct list_head list;
168 u32 seqnum; 168 u32 seqnum;
169 unsigned long exp_time; 169 unsigned long exp_time;
170 u8 sa[ETH_ALEN]; 170 u8 sa[ETH_ALEN];
171 }; 171 };
172 172
173 struct mesh_rmc { 173 struct mesh_rmc {
174 struct rmc_entry bucket[RMC_BUCKETS]; 174 struct rmc_entry bucket[RMC_BUCKETS];
175 u32 idx_mask; 175 u32 idx_mask;
176 }; 176 };
177 177
178 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) 178 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
179 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) 179 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
180 180
181 #define MESH_DEFAULT_BEACON_INTERVAL 1000 /* in 1024 us units */ 181 #define MESH_DEFAULT_BEACON_INTERVAL 1000 /* in 1024 us units */
182 182
183 #define MESH_PATH_EXPIRE (600 * HZ) 183 #define MESH_PATH_EXPIRE (600 * HZ)
184 184
185 /* Default maximum number of plinks per interface */ 185 /* Default maximum number of plinks per interface */
186 #define MESH_MAX_PLINKS 256 186 #define MESH_MAX_PLINKS 256
187 187
188 /* Maximum number of paths per interface */ 188 /* Maximum number of paths per interface */
189 #define MESH_MAX_MPATHS 1024 189 #define MESH_MAX_MPATHS 1024
190 190
191 /* Public interfaces */ 191 /* Public interfaces */
192 /* Various */ 192 /* Various */
193 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, 193 int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
194 const u8 *da, const u8 *sa); 194 const u8 *da, const u8 *sa);
195 int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr, 195 int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
196 struct ieee80211_sub_if_data *sdata, char *addr4or5, 196 struct ieee80211_sub_if_data *sdata, char *addr4or5,
197 char *addr6); 197 char *addr6);
198 int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr, 198 int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr,
199 struct ieee80211_sub_if_data *sdata); 199 struct ieee80211_sub_if_data *sdata);
200 bool mesh_matches_local(struct ieee802_11_elems *ie, 200 bool mesh_matches_local(struct ieee802_11_elems *ie,
201 struct ieee80211_sub_if_data *sdata); 201 struct ieee80211_sub_if_data *sdata);
202 void mesh_ids_set_default(struct ieee80211_if_mesh *mesh); 202 void mesh_ids_set_default(struct ieee80211_if_mesh *mesh);
203 void mesh_mgmt_ies_add(struct sk_buff *skb, 203 void mesh_mgmt_ies_add(struct sk_buff *skb,
204 struct ieee80211_sub_if_data *sdata); 204 struct ieee80211_sub_if_data *sdata);
205 int mesh_add_meshconf_ie(struct sk_buff *skb, 205 int mesh_add_meshconf_ie(struct sk_buff *skb,
206 struct ieee80211_sub_if_data *sdata); 206 struct ieee80211_sub_if_data *sdata);
207 int mesh_add_meshid_ie(struct sk_buff *skb, 207 int mesh_add_meshid_ie(struct sk_buff *skb,
208 struct ieee80211_sub_if_data *sdata); 208 struct ieee80211_sub_if_data *sdata);
209 int mesh_add_rsn_ie(struct sk_buff *skb, 209 int mesh_add_rsn_ie(struct sk_buff *skb,
210 struct ieee80211_sub_if_data *sdata); 210 struct ieee80211_sub_if_data *sdata);
211 int mesh_add_vendor_ies(struct sk_buff *skb, 211 int mesh_add_vendor_ies(struct sk_buff *skb,
212 struct ieee80211_sub_if_data *sdata); 212 struct ieee80211_sub_if_data *sdata);
213 int mesh_add_ds_params_ie(struct sk_buff *skb, 213 int mesh_add_ds_params_ie(struct sk_buff *skb,
214 struct ieee80211_sub_if_data *sdata); 214 struct ieee80211_sub_if_data *sdata);
215 int mesh_add_ht_cap_ie(struct sk_buff *skb,
216 struct ieee80211_sub_if_data *sdata);
217 int mesh_add_ht_info_ie(struct sk_buff *skb,
218 struct ieee80211_sub_if_data *sdata);
215 void mesh_rmc_free(struct ieee80211_sub_if_data *sdata); 219 void mesh_rmc_free(struct ieee80211_sub_if_data *sdata);
216 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata); 220 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata);
217 void ieee80211s_init(void); 221 void ieee80211s_init(void);
218 void ieee80211s_update_metric(struct ieee80211_local *local, 222 void ieee80211s_update_metric(struct ieee80211_local *local,
219 struct sta_info *stainfo, struct sk_buff *skb); 223 struct sta_info *stainfo, struct sk_buff *skb);
220 void ieee80211s_stop(void); 224 void ieee80211s_stop(void);
221 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata); 225 void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
222 void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); 226 void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
223 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata); 227 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
224 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh); 228 void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh);
225 229
226 /* Mesh paths */ 230 /* Mesh paths */
227 int mesh_nexthop_lookup(struct sk_buff *skb, 231 int mesh_nexthop_lookup(struct sk_buff *skb,
228 struct ieee80211_sub_if_data *sdata); 232 struct ieee80211_sub_if_data *sdata);
229 void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata); 233 void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata);
230 struct mesh_path *mesh_path_lookup(u8 *dst, 234 struct mesh_path *mesh_path_lookup(u8 *dst,
231 struct ieee80211_sub_if_data *sdata); 235 struct ieee80211_sub_if_data *sdata);
232 struct mesh_path *mpp_path_lookup(u8 *dst, 236 struct mesh_path *mpp_path_lookup(u8 *dst,
233 struct ieee80211_sub_if_data *sdata); 237 struct ieee80211_sub_if_data *sdata);
234 int mpp_path_add(u8 *dst, u8 *mpp, struct ieee80211_sub_if_data *sdata); 238 int mpp_path_add(u8 *dst, u8 *mpp, struct ieee80211_sub_if_data *sdata);
235 struct mesh_path *mesh_path_lookup_by_idx(int idx, 239 struct mesh_path *mesh_path_lookup_by_idx(int idx,
236 struct ieee80211_sub_if_data *sdata); 240 struct ieee80211_sub_if_data *sdata);
237 void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop); 241 void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
238 void mesh_path_expire(struct ieee80211_sub_if_data *sdata); 242 void mesh_path_expire(struct ieee80211_sub_if_data *sdata);
239 void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata, 243 void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
240 struct ieee80211_mgmt *mgmt, size_t len); 244 struct ieee80211_mgmt *mgmt, size_t len);
241 int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata); 245 int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata);
242 246
243 int mesh_path_add_gate(struct mesh_path *mpath); 247 int mesh_path_add_gate(struct mesh_path *mpath);
244 int mesh_path_send_to_gates(struct mesh_path *mpath); 248 int mesh_path_send_to_gates(struct mesh_path *mpath);
245 int mesh_gate_num(struct ieee80211_sub_if_data *sdata); 249 int mesh_gate_num(struct ieee80211_sub_if_data *sdata);
246 /* Mesh plinks */ 250 /* Mesh plinks */
247 void mesh_neighbour_update(u8 *hw_addr, u32 rates, 251 void mesh_neighbour_update(u8 *hw_addr, u32 rates,
248 struct ieee80211_sub_if_data *sdata, 252 struct ieee80211_sub_if_data *sdata,
249 struct ieee802_11_elems *ie); 253 struct ieee802_11_elems *ie);
250 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie); 254 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie);
251 void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata); 255 void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
252 void mesh_plink_broken(struct sta_info *sta); 256 void mesh_plink_broken(struct sta_info *sta);
253 void mesh_plink_deactivate(struct sta_info *sta); 257 void mesh_plink_deactivate(struct sta_info *sta);
254 int mesh_plink_open(struct sta_info *sta); 258 int mesh_plink_open(struct sta_info *sta);
255 void mesh_plink_block(struct sta_info *sta); 259 void mesh_plink_block(struct sta_info *sta);
256 void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, 260 void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
257 struct ieee80211_mgmt *mgmt, size_t len, 261 struct ieee80211_mgmt *mgmt, size_t len,
258 struct ieee80211_rx_status *rx_status); 262 struct ieee80211_rx_status *rx_status);
259 263
260 /* Private interfaces */ 264 /* Private interfaces */
261 /* Mesh tables */ 265 /* Mesh tables */
262 void mesh_mpath_table_grow(void); 266 void mesh_mpath_table_grow(void);
263 void mesh_mpp_table_grow(void); 267 void mesh_mpp_table_grow(void);
264 /* Mesh paths */ 268 /* Mesh paths */
265 int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn, __le16 target_rcode, 269 int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn, __le16 target_rcode,
266 const u8 *ra, struct ieee80211_sub_if_data *sdata); 270 const u8 *ra, struct ieee80211_sub_if_data *sdata);
267 void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta); 271 void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
268 void mesh_path_flush_pending(struct mesh_path *mpath); 272 void mesh_path_flush_pending(struct mesh_path *mpath);
269 void mesh_path_tx_pending(struct mesh_path *mpath); 273 void mesh_path_tx_pending(struct mesh_path *mpath);
270 int mesh_pathtbl_init(void); 274 int mesh_pathtbl_init(void);
271 void mesh_pathtbl_unregister(void); 275 void mesh_pathtbl_unregister(void);
272 int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata); 276 int mesh_path_del(u8 *addr, struct ieee80211_sub_if_data *sdata);
273 void mesh_path_timer(unsigned long data); 277 void mesh_path_timer(unsigned long data);
274 void mesh_path_flush_by_nexthop(struct sta_info *sta); 278 void mesh_path_flush_by_nexthop(struct sta_info *sta);
275 void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata); 279 void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata);
276 void mesh_path_discard_frame(struct sk_buff *skb, 280 void mesh_path_discard_frame(struct sk_buff *skb,
277 struct ieee80211_sub_if_data *sdata); 281 struct ieee80211_sub_if_data *sdata);
278 void mesh_path_quiesce(struct ieee80211_sub_if_data *sdata); 282 void mesh_path_quiesce(struct ieee80211_sub_if_data *sdata);
279 void mesh_path_restart(struct ieee80211_sub_if_data *sdata); 283 void mesh_path_restart(struct ieee80211_sub_if_data *sdata);
280 void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata); 284 void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
281 285
282 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt); 286 bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
283 extern int mesh_paths_generation; 287 extern int mesh_paths_generation;
284 288
285 #ifdef CONFIG_MAC80211_MESH 289 #ifdef CONFIG_MAC80211_MESH
286 extern int mesh_allocated; 290 extern int mesh_allocated;
287 291
288 static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata) 292 static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
289 { 293 {
290 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks - 294 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks -
291 atomic_read(&sdata->u.mesh.mshstats.estab_plinks); 295 atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
292 } 296 }
293 297
294 static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata) 298 static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
295 { 299 {
296 return (min_t(long, mesh_plink_free_count(sdata), 300 return (min_t(long, mesh_plink_free_count(sdata),
297 MESH_MAX_PLINKS - sdata->local->num_sta)) > 0; 301 MESH_MAX_PLINKS - sdata->local->num_sta)) > 0;
298 } 302 }
299 303
300 static inline void mesh_path_activate(struct mesh_path *mpath) 304 static inline void mesh_path_activate(struct mesh_path *mpath)
301 { 305 {
302 mpath->flags |= MESH_PATH_ACTIVE | MESH_PATH_RESOLVED; 306 mpath->flags |= MESH_PATH_ACTIVE | MESH_PATH_RESOLVED;
303 } 307 }
304 308
305 static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata) 309 static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
306 { 310 {
307 return sdata->u.mesh.mesh_pp_id == IEEE80211_PATH_PROTOCOL_HWMP; 311 return sdata->u.mesh.mesh_pp_id == IEEE80211_PATH_PROTOCOL_HWMP;
308 } 312 }
309 313
310 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local); 314 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local);
311 315
312 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata); 316 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata);
313 void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata); 317 void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata);
314 void mesh_plink_quiesce(struct sta_info *sta); 318 void mesh_plink_quiesce(struct sta_info *sta);
315 void mesh_plink_restart(struct sta_info *sta); 319 void mesh_plink_restart(struct sta_info *sta);
316 #else 320 #else
317 #define mesh_allocated 0 321 #define mesh_allocated 0
318 static inline void 322 static inline void
319 ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {} 323 ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {}
320 static inline void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata) 324 static inline void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
321 {} 325 {}
322 static inline void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata) 326 static inline void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
323 {} 327 {}
324 static inline void mesh_plink_quiesce(struct sta_info *sta) {} 328 static inline void mesh_plink_quiesce(struct sta_info *sta) {}
325 static inline void mesh_plink_restart(struct sta_info *sta) {} 329 static inline void mesh_plink_restart(struct sta_info *sta) {}
326 static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata) 330 static inline bool mesh_path_sel_is_hwmp(struct ieee80211_sub_if_data *sdata)
327 { return false; } 331 { return false; }
328 #endif 332 #endif
329 333
330 #endif /* IEEE80211S_H */ 334 #endif /* IEEE80211S_H */
331 335
net/mac80211/mesh_plink.c
1 /* 1 /*
2 * Copyright (c) 2008, 2009 open80211s Ltd. 2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com> 3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as 6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 */ 8 */
9 #include <linux/gfp.h> 9 #include <linux/gfp.h>
10 #include <linux/kernel.h> 10 #include <linux/kernel.h>
11 #include <linux/random.h> 11 #include <linux/random.h>
12 #include "ieee80211_i.h" 12 #include "ieee80211_i.h"
13 #include "rate.h" 13 #include "rate.h"
14 #include "mesh.h" 14 #include "mesh.h"
15 15
16 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG 16 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17 #define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args) 17 #define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
18 #else 18 #else
19 #define mpl_dbg(fmt, args...) do { (void)(0); } while (0) 19 #define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
20 #endif 20 #endif
21 21
22 #define PLINK_GET_LLID(p) (p + 2) 22 #define PLINK_GET_LLID(p) (p + 2)
23 #define PLINK_GET_PLID(p) (p + 4) 23 #define PLINK_GET_PLID(p) (p + 4)
24 24
25 #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \ 25 #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000)) 26 jiffies + HZ * t / 1000))
27 27
28 #define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries) 28 #define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
29 #define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout) 29 #define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
30 #define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout) 30 #define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
31 #define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout) 31 #define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
32 #define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks) 32 #define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
33 33
34 enum plink_event { 34 enum plink_event {
35 PLINK_UNDEFINED, 35 PLINK_UNDEFINED,
36 OPN_ACPT, 36 OPN_ACPT,
37 OPN_RJCT, 37 OPN_RJCT,
38 OPN_IGNR, 38 OPN_IGNR,
39 CNF_ACPT, 39 CNF_ACPT,
40 CNF_RJCT, 40 CNF_RJCT,
41 CNF_IGNR, 41 CNF_IGNR,
42 CLS_ACPT, 42 CLS_ACPT,
43 CLS_IGNR 43 CLS_IGNR
44 }; 44 };
45 45
46 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, 46 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
47 enum ieee80211_self_protected_actioncode action, 47 enum ieee80211_self_protected_actioncode action,
48 u8 *da, __le16 llid, __le16 plid, __le16 reason); 48 u8 *da, __le16 llid, __le16 plid, __le16 reason);
49 49
50 static inline 50 static inline
51 void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata) 51 void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
52 { 52 {
53 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks); 53 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
54 mesh_accept_plinks_update(sdata); 54 mesh_accept_plinks_update(sdata);
55 } 55 }
56 56
57 static inline 57 static inline
58 void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata) 58 void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
59 { 59 {
60 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks); 60 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
61 mesh_accept_plinks_update(sdata); 61 mesh_accept_plinks_update(sdata);
62 } 62 }
63 63
64 /** 64 /**
65 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine 65 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
66 * 66 *
67 * @sta: mesh peer link to restart 67 * @sta: mesh peer link to restart
68 * 68 *
69 * Locking: this function must be called holding sta->lock 69 * Locking: this function must be called holding sta->lock
70 */ 70 */
71 static inline void mesh_plink_fsm_restart(struct sta_info *sta) 71 static inline void mesh_plink_fsm_restart(struct sta_info *sta)
72 { 72 {
73 sta->plink_state = NL80211_PLINK_LISTEN; 73 sta->plink_state = NL80211_PLINK_LISTEN;
74 sta->llid = sta->plid = sta->reason = 0; 74 sta->llid = sta->plid = sta->reason = 0;
75 sta->plink_retries = 0; 75 sta->plink_retries = 0;
76 } 76 }
77 77
78 /* 78 /*
79 * NOTE: This is just an alias for sta_info_alloc(), see notes 79 * NOTE: This is just an alias for sta_info_alloc(), see notes
80 * on it in the lifecycle management section! 80 * on it in the lifecycle management section!
81 */ 81 */
82 static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata, 82 static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
83 u8 *hw_addr, u32 rates) 83 u8 *hw_addr, u32 rates)
84 { 84 {
85 struct ieee80211_local *local = sdata->local; 85 struct ieee80211_local *local = sdata->local;
86 struct sta_info *sta; 86 struct sta_info *sta;
87 87
88 if (local->num_sta >= MESH_MAX_PLINKS) 88 if (local->num_sta >= MESH_MAX_PLINKS)
89 return NULL; 89 return NULL;
90 90
91 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL); 91 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
92 if (!sta) 92 if (!sta)
93 return NULL; 93 return NULL;
94 94
95 set_sta_flag(sta, WLAN_STA_AUTH); 95 set_sta_flag(sta, WLAN_STA_AUTH);
96 set_sta_flag(sta, WLAN_STA_AUTHORIZED); 96 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
97 set_sta_flag(sta, WLAN_STA_WME); 97 set_sta_flag(sta, WLAN_STA_WME);
98 sta->sta.supp_rates[local->hw.conf.channel->band] = rates; 98 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
99 rate_control_rate_init(sta); 99 rate_control_rate_init(sta);
100 100
101 return sta; 101 return sta;
102 } 102 }
103 103
104 /** 104 /**
105 * __mesh_plink_deactivate - deactivate mesh peer link 105 * __mesh_plink_deactivate - deactivate mesh peer link
106 * 106 *
107 * @sta: mesh peer link to deactivate 107 * @sta: mesh peer link to deactivate
108 * 108 *
109 * All mesh paths with this peer as next hop will be flushed 109 * All mesh paths with this peer as next hop will be flushed
110 * 110 *
111 * Locking: the caller must hold sta->lock 111 * Locking: the caller must hold sta->lock
112 */ 112 */
113 static bool __mesh_plink_deactivate(struct sta_info *sta) 113 static bool __mesh_plink_deactivate(struct sta_info *sta)
114 { 114 {
115 struct ieee80211_sub_if_data *sdata = sta->sdata; 115 struct ieee80211_sub_if_data *sdata = sta->sdata;
116 bool deactivated = false; 116 bool deactivated = false;
117 117
118 if (sta->plink_state == NL80211_PLINK_ESTAB) { 118 if (sta->plink_state == NL80211_PLINK_ESTAB) {
119 mesh_plink_dec_estab_count(sdata); 119 mesh_plink_dec_estab_count(sdata);
120 deactivated = true; 120 deactivated = true;
121 } 121 }
122 sta->plink_state = NL80211_PLINK_BLOCKED; 122 sta->plink_state = NL80211_PLINK_BLOCKED;
123 mesh_path_flush_by_nexthop(sta); 123 mesh_path_flush_by_nexthop(sta);
124 124
125 return deactivated; 125 return deactivated;
126 } 126 }
127 127
128 /** 128 /**
129 * mesh_plink_deactivate - deactivate mesh peer link 129 * mesh_plink_deactivate - deactivate mesh peer link
130 * 130 *
131 * @sta: mesh peer link to deactivate 131 * @sta: mesh peer link to deactivate
132 * 132 *
133 * All mesh paths with this peer as next hop will be flushed 133 * All mesh paths with this peer as next hop will be flushed
134 */ 134 */
135 void mesh_plink_deactivate(struct sta_info *sta) 135 void mesh_plink_deactivate(struct sta_info *sta)
136 { 136 {
137 struct ieee80211_sub_if_data *sdata = sta->sdata; 137 struct ieee80211_sub_if_data *sdata = sta->sdata;
138 bool deactivated; 138 bool deactivated;
139 139
140 spin_lock_bh(&sta->lock); 140 spin_lock_bh(&sta->lock);
141 deactivated = __mesh_plink_deactivate(sta); 141 deactivated = __mesh_plink_deactivate(sta);
142 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED); 142 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
143 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, 143 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
144 sta->sta.addr, sta->llid, sta->plid, 144 sta->sta.addr, sta->llid, sta->plid,
145 sta->reason); 145 sta->reason);
146 spin_unlock_bh(&sta->lock); 146 spin_unlock_bh(&sta->lock);
147 147
148 if (deactivated) 148 if (deactivated)
149 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); 149 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
150 } 150 }
151 151
152 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, 152 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
153 enum ieee80211_self_protected_actioncode action, 153 enum ieee80211_self_protected_actioncode action,
154 u8 *da, __le16 llid, __le16 plid, __le16 reason) { 154 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
155 struct ieee80211_local *local = sdata->local; 155 struct ieee80211_local *local = sdata->local;
156 struct sk_buff *skb; 156 struct sk_buff *skb;
157 struct ieee80211_mgmt *mgmt; 157 struct ieee80211_mgmt *mgmt;
158 bool include_plid = false; 158 bool include_plid = false;
159 u16 peering_proto = 0; 159 u16 peering_proto = 0;
160 u8 *pos, ie_len = 4; 160 u8 *pos, ie_len = 4;
161 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) + 161 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
162 sizeof(mgmt->u.action.u.self_prot); 162 sizeof(mgmt->u.action.u.self_prot);
163 163
164 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 164 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
165 hdr_len + 165 hdr_len +
166 2 + /* capability info */ 166 2 + /* capability info */
167 2 + /* AID */ 167 2 + /* AID */
168 2 + 8 + /* supported rates */ 168 2 + 8 + /* supported rates */
169 2 + (IEEE80211_MAX_SUPP_RATES - 8) + 169 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
170 2 + sdata->u.mesh.mesh_id_len + 170 2 + sdata->u.mesh.mesh_id_len +
171 2 + sizeof(struct ieee80211_meshconf_ie) + 171 2 + sizeof(struct ieee80211_meshconf_ie) +
172 2 + sizeof(struct ieee80211_ht_cap) +
173 2 + sizeof(struct ieee80211_ht_info) +
172 2 + 8 + /* peering IE */ 174 2 + 8 + /* peering IE */
173 sdata->u.mesh.ie_len); 175 sdata->u.mesh.ie_len);
174 if (!skb) 176 if (!skb)
175 return -1; 177 return -1;
176 skb_reserve(skb, local->hw.extra_tx_headroom); 178 skb_reserve(skb, local->hw.extra_tx_headroom);
177 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); 179 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
178 memset(mgmt, 0, hdr_len); 180 memset(mgmt, 0, hdr_len);
179 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 181 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
180 IEEE80211_STYPE_ACTION); 182 IEEE80211_STYPE_ACTION);
181 memcpy(mgmt->da, da, ETH_ALEN); 183 memcpy(mgmt->da, da, ETH_ALEN);
182 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 184 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
183 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); 185 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
184 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED; 186 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
185 mgmt->u.action.u.self_prot.action_code = action; 187 mgmt->u.action.u.self_prot.action_code = action;
186 188
187 if (action != WLAN_SP_MESH_PEERING_CLOSE) { 189 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
188 /* capability info */ 190 /* capability info */
189 pos = skb_put(skb, 2); 191 pos = skb_put(skb, 2);
190 memset(pos, 0, 2); 192 memset(pos, 0, 2);
191 if (action == WLAN_SP_MESH_PEERING_CONFIRM) { 193 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
192 /* AID */ 194 /* AID */
193 pos = skb_put(skb, 2); 195 pos = skb_put(skb, 2);
194 memcpy(pos + 2, &plid, 2); 196 memcpy(pos + 2, &plid, 2);
195 } 197 }
196 if (ieee80211_add_srates_ie(&sdata->vif, skb) || 198 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
197 ieee80211_add_ext_srates_ie(&sdata->vif, skb) || 199 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
198 mesh_add_rsn_ie(skb, sdata) || 200 mesh_add_rsn_ie(skb, sdata) ||
199 mesh_add_meshid_ie(skb, sdata) || 201 mesh_add_meshid_ie(skb, sdata) ||
200 mesh_add_meshconf_ie(skb, sdata)) 202 mesh_add_meshconf_ie(skb, sdata))
201 return -1; 203 return -1;
202 } else { /* WLAN_SP_MESH_PEERING_CLOSE */ 204 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
203 if (mesh_add_meshid_ie(skb, sdata)) 205 if (mesh_add_meshid_ie(skb, sdata))
204 return -1; 206 return -1;
205 } 207 }
206 208
207 /* Add Mesh Peering Management element */ 209 /* Add Mesh Peering Management element */
208 switch (action) { 210 switch (action) {
209 case WLAN_SP_MESH_PEERING_OPEN: 211 case WLAN_SP_MESH_PEERING_OPEN:
210 break; 212 break;
211 case WLAN_SP_MESH_PEERING_CONFIRM: 213 case WLAN_SP_MESH_PEERING_CONFIRM:
212 ie_len += 2; 214 ie_len += 2;
213 include_plid = true; 215 include_plid = true;
214 break; 216 break;
215 case WLAN_SP_MESH_PEERING_CLOSE: 217 case WLAN_SP_MESH_PEERING_CLOSE:
216 if (plid) { 218 if (plid) {
217 ie_len += 2; 219 ie_len += 2;
218 include_plid = true; 220 include_plid = true;
219 } 221 }
220 ie_len += 2; /* reason code */ 222 ie_len += 2; /* reason code */
221 break; 223 break;
222 default: 224 default:
223 return -EINVAL; 225 return -EINVAL;
224 } 226 }
225 227
226 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len)) 228 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
227 return -ENOMEM; 229 return -ENOMEM;
228 230
229 pos = skb_put(skb, 2 + ie_len); 231 pos = skb_put(skb, 2 + ie_len);
230 *pos++ = WLAN_EID_PEER_MGMT; 232 *pos++ = WLAN_EID_PEER_MGMT;
231 *pos++ = ie_len; 233 *pos++ = ie_len;
232 memcpy(pos, &peering_proto, 2); 234 memcpy(pos, &peering_proto, 2);
233 pos += 2; 235 pos += 2;
234 memcpy(pos, &llid, 2); 236 memcpy(pos, &llid, 2);
235 pos += 2; 237 pos += 2;
236 if (include_plid) { 238 if (include_plid) {
237 memcpy(pos, &plid, 2); 239 memcpy(pos, &plid, 2);
238 pos += 2; 240 pos += 2;
239 } 241 }
240 if (action == WLAN_SP_MESH_PEERING_CLOSE) { 242 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
241 memcpy(pos, &reason, 2); 243 memcpy(pos, &reason, 2);
242 pos += 2; 244 pos += 2;
243 } 245 }
246
247 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
248 if (mesh_add_ht_cap_ie(skb, sdata) ||
249 mesh_add_ht_info_ie(skb, sdata))
250 return -1;
251 }
252
244 if (mesh_add_vendor_ies(skb, sdata)) 253 if (mesh_add_vendor_ies(skb, sdata))
245 return -1; 254 return -1;
246 255
247 ieee80211_tx_skb(sdata, skb); 256 ieee80211_tx_skb(sdata, skb);
248 return 0; 257 return 0;
249 } 258 }
250 259
251 void mesh_neighbour_update(u8 *hw_addr, u32 rates, 260 void mesh_neighbour_update(u8 *hw_addr, u32 rates,
252 struct ieee80211_sub_if_data *sdata, 261 struct ieee80211_sub_if_data *sdata,
253 struct ieee802_11_elems *elems) 262 struct ieee802_11_elems *elems)
254 { 263 {
255 struct ieee80211_local *local = sdata->local; 264 struct ieee80211_local *local = sdata->local;
256 struct sta_info *sta; 265 struct sta_info *sta;
257 266
258 rcu_read_lock(); 267 rcu_read_lock();
259 268
260 sta = sta_info_get(sdata, hw_addr); 269 sta = sta_info_get(sdata, hw_addr);
261 if (!sta) { 270 if (!sta) {
262 rcu_read_unlock(); 271 rcu_read_unlock();
263 /* Userspace handles peer allocation when security is enabled 272 /* Userspace handles peer allocation when security is enabled
264 * */ 273 * */
265 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) 274 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
266 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr, 275 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
267 elems->ie_start, elems->total_len, 276 elems->ie_start, elems->total_len,
268 GFP_KERNEL); 277 GFP_KERNEL);
269 else 278 else
270 sta = mesh_plink_alloc(sdata, hw_addr, rates); 279 sta = mesh_plink_alloc(sdata, hw_addr, rates);
271 if (!sta) 280 if (!sta)
272 return; 281 return;
273 if (sta_info_insert_rcu(sta)) { 282 if (sta_info_insert_rcu(sta)) {
274 rcu_read_unlock(); 283 rcu_read_unlock();
275 return; 284 return;
276 } 285 }
277 } 286 }
278 287
279 sta->last_rx = jiffies; 288 sta->last_rx = jiffies;
280 sta->sta.supp_rates[local->hw.conf.channel->band] = rates; 289 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
281 if (mesh_peer_accepts_plinks(elems) && 290 if (mesh_peer_accepts_plinks(elems) &&
282 sta->plink_state == NL80211_PLINK_LISTEN && 291 sta->plink_state == NL80211_PLINK_LISTEN &&
283 sdata->u.mesh.accepting_plinks && 292 sdata->u.mesh.accepting_plinks &&
284 sdata->u.mesh.mshcfg.auto_open_plinks) 293 sdata->u.mesh.mshcfg.auto_open_plinks)
285 mesh_plink_open(sta); 294 mesh_plink_open(sta);
286 295
287 rcu_read_unlock(); 296 rcu_read_unlock();
288 } 297 }
289 298
290 static void mesh_plink_timer(unsigned long data) 299 static void mesh_plink_timer(unsigned long data)
291 { 300 {
292 struct sta_info *sta; 301 struct sta_info *sta;
293 __le16 llid, plid, reason; 302 __le16 llid, plid, reason;
294 struct ieee80211_sub_if_data *sdata; 303 struct ieee80211_sub_if_data *sdata;
295 304
296 /* 305 /*
297 * This STA is valid because sta_info_destroy() will 306 * This STA is valid because sta_info_destroy() will
298 * del_timer_sync() this timer after having made sure 307 * del_timer_sync() this timer after having made sure
299 * it cannot be readded (by deleting the plink.) 308 * it cannot be readded (by deleting the plink.)
300 */ 309 */
301 sta = (struct sta_info *) data; 310 sta = (struct sta_info *) data;
302 311
303 if (sta->sdata->local->quiescing) { 312 if (sta->sdata->local->quiescing) {
304 sta->plink_timer_was_running = true; 313 sta->plink_timer_was_running = true;
305 return; 314 return;
306 } 315 }
307 316
308 spin_lock_bh(&sta->lock); 317 spin_lock_bh(&sta->lock);
309 if (sta->ignore_plink_timer) { 318 if (sta->ignore_plink_timer) {
310 sta->ignore_plink_timer = false; 319 sta->ignore_plink_timer = false;
311 spin_unlock_bh(&sta->lock); 320 spin_unlock_bh(&sta->lock);
312 return; 321 return;
313 } 322 }
314 mpl_dbg("Mesh plink timer for %pM fired on state %d\n", 323 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
315 sta->sta.addr, sta->plink_state); 324 sta->sta.addr, sta->plink_state);
316 reason = 0; 325 reason = 0;
317 llid = sta->llid; 326 llid = sta->llid;
318 plid = sta->plid; 327 plid = sta->plid;
319 sdata = sta->sdata; 328 sdata = sta->sdata;
320 329
321 switch (sta->plink_state) { 330 switch (sta->plink_state) {
322 case NL80211_PLINK_OPN_RCVD: 331 case NL80211_PLINK_OPN_RCVD:
323 case NL80211_PLINK_OPN_SNT: 332 case NL80211_PLINK_OPN_SNT:
324 /* retry timer */ 333 /* retry timer */
325 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) { 334 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
326 u32 rand; 335 u32 rand;
327 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n", 336 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
328 sta->sta.addr, sta->plink_retries, 337 sta->sta.addr, sta->plink_retries,
329 sta->plink_timeout); 338 sta->plink_timeout);
330 get_random_bytes(&rand, sizeof(u32)); 339 get_random_bytes(&rand, sizeof(u32));
331 sta->plink_timeout = sta->plink_timeout + 340 sta->plink_timeout = sta->plink_timeout +
332 rand % sta->plink_timeout; 341 rand % sta->plink_timeout;
333 ++sta->plink_retries; 342 ++sta->plink_retries;
334 mod_plink_timer(sta, sta->plink_timeout); 343 mod_plink_timer(sta, sta->plink_timeout);
335 spin_unlock_bh(&sta->lock); 344 spin_unlock_bh(&sta->lock);
336 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, 345 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
337 sta->sta.addr, llid, 0, 0); 346 sta->sta.addr, llid, 0, 0);
338 break; 347 break;
339 } 348 }
340 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES); 349 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
341 /* fall through on else */ 350 /* fall through on else */
342 case NL80211_PLINK_CNF_RCVD: 351 case NL80211_PLINK_CNF_RCVD:
343 /* confirm timer */ 352 /* confirm timer */
344 if (!reason) 353 if (!reason)
345 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT); 354 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
346 sta->plink_state = NL80211_PLINK_HOLDING; 355 sta->plink_state = NL80211_PLINK_HOLDING;
347 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); 356 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
348 spin_unlock_bh(&sta->lock); 357 spin_unlock_bh(&sta->lock);
349 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, 358 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
350 sta->sta.addr, llid, plid, reason); 359 sta->sta.addr, llid, plid, reason);
351 break; 360 break;
352 case NL80211_PLINK_HOLDING: 361 case NL80211_PLINK_HOLDING:
353 /* holding timer */ 362 /* holding timer */
354 del_timer(&sta->plink_timer); 363 del_timer(&sta->plink_timer);
355 mesh_plink_fsm_restart(sta); 364 mesh_plink_fsm_restart(sta);
356 spin_unlock_bh(&sta->lock); 365 spin_unlock_bh(&sta->lock);
357 break; 366 break;
358 default: 367 default:
359 spin_unlock_bh(&sta->lock); 368 spin_unlock_bh(&sta->lock);
360 break; 369 break;
361 } 370 }
362 } 371 }
363 372
364 #ifdef CONFIG_PM 373 #ifdef CONFIG_PM
365 void mesh_plink_quiesce(struct sta_info *sta) 374 void mesh_plink_quiesce(struct sta_info *sta)
366 { 375 {
367 if (del_timer_sync(&sta->plink_timer)) 376 if (del_timer_sync(&sta->plink_timer))
368 sta->plink_timer_was_running = true; 377 sta->plink_timer_was_running = true;
369 } 378 }
370 379
371 void mesh_plink_restart(struct sta_info *sta) 380 void mesh_plink_restart(struct sta_info *sta)
372 { 381 {
373 if (sta->plink_timer_was_running) { 382 if (sta->plink_timer_was_running) {
374 add_timer(&sta->plink_timer); 383 add_timer(&sta->plink_timer);
375 sta->plink_timer_was_running = false; 384 sta->plink_timer_was_running = false;
376 } 385 }
377 } 386 }
378 #endif 387 #endif
379 388
380 static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) 389 static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
381 { 390 {
382 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000); 391 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
383 sta->plink_timer.data = (unsigned long) sta; 392 sta->plink_timer.data = (unsigned long) sta;
384 sta->plink_timer.function = mesh_plink_timer; 393 sta->plink_timer.function = mesh_plink_timer;
385 sta->plink_timeout = timeout; 394 sta->plink_timeout = timeout;
386 add_timer(&sta->plink_timer); 395 add_timer(&sta->plink_timer);
387 } 396 }
388 397
389 int mesh_plink_open(struct sta_info *sta) 398 int mesh_plink_open(struct sta_info *sta)
390 { 399 {
391 __le16 llid; 400 __le16 llid;
392 struct ieee80211_sub_if_data *sdata = sta->sdata; 401 struct ieee80211_sub_if_data *sdata = sta->sdata;
393 402
394 if (!test_sta_flag(sta, WLAN_STA_AUTH)) 403 if (!test_sta_flag(sta, WLAN_STA_AUTH))
395 return -EPERM; 404 return -EPERM;
396 405
397 spin_lock_bh(&sta->lock); 406 spin_lock_bh(&sta->lock);
398 get_random_bytes(&llid, 2); 407 get_random_bytes(&llid, 2);
399 sta->llid = llid; 408 sta->llid = llid;
400 if (sta->plink_state != NL80211_PLINK_LISTEN) { 409 if (sta->plink_state != NL80211_PLINK_LISTEN) {
401 spin_unlock_bh(&sta->lock); 410 spin_unlock_bh(&sta->lock);
402 return -EBUSY; 411 return -EBUSY;
403 } 412 }
404 sta->plink_state = NL80211_PLINK_OPN_SNT; 413 sta->plink_state = NL80211_PLINK_OPN_SNT;
405 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); 414 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
406 spin_unlock_bh(&sta->lock); 415 spin_unlock_bh(&sta->lock);
407 mpl_dbg("Mesh plink: starting establishment with %pM\n", 416 mpl_dbg("Mesh plink: starting establishment with %pM\n",
408 sta->sta.addr); 417 sta->sta.addr);
409 418
410 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, 419 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
411 sta->sta.addr, llid, 0, 0); 420 sta->sta.addr, llid, 0, 0);
412 } 421 }
413 422
414 void mesh_plink_block(struct sta_info *sta) 423 void mesh_plink_block(struct sta_info *sta)
415 { 424 {
416 struct ieee80211_sub_if_data *sdata = sta->sdata; 425 struct ieee80211_sub_if_data *sdata = sta->sdata;
417 bool deactivated; 426 bool deactivated;
418 427
419 spin_lock_bh(&sta->lock); 428 spin_lock_bh(&sta->lock);
420 deactivated = __mesh_plink_deactivate(sta); 429 deactivated = __mesh_plink_deactivate(sta);
421 sta->plink_state = NL80211_PLINK_BLOCKED; 430 sta->plink_state = NL80211_PLINK_BLOCKED;
422 spin_unlock_bh(&sta->lock); 431 spin_unlock_bh(&sta->lock);
423 432
424 if (deactivated) 433 if (deactivated)
425 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); 434 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
426 } 435 }
427 436
428 437
429 void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt, 438 void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
430 size_t len, struct ieee80211_rx_status *rx_status) 439 size_t len, struct ieee80211_rx_status *rx_status)
431 { 440 {
432 struct ieee80211_local *local = sdata->local; 441 struct ieee80211_local *local = sdata->local;
433 struct ieee802_11_elems elems; 442 struct ieee802_11_elems elems;
434 struct sta_info *sta; 443 struct sta_info *sta;
435 enum plink_event event; 444 enum plink_event event;
436 enum ieee80211_self_protected_actioncode ftype; 445 enum ieee80211_self_protected_actioncode ftype;
437 size_t baselen; 446 size_t baselen;
438 bool deactivated, matches_local = true; 447 bool deactivated, matches_local = true;
439 u8 ie_len; 448 u8 ie_len;
440 u8 *baseaddr; 449 u8 *baseaddr;
441 __le16 plid, llid, reason; 450 __le16 plid, llid, reason;
442 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG 451 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
443 static const char *mplstates[] = { 452 static const char *mplstates[] = {
444 [NL80211_PLINK_LISTEN] = "LISTEN", 453 [NL80211_PLINK_LISTEN] = "LISTEN",
445 [NL80211_PLINK_OPN_SNT] = "OPN-SNT", 454 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
446 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD", 455 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
447 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD", 456 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
448 [NL80211_PLINK_ESTAB] = "ESTAB", 457 [NL80211_PLINK_ESTAB] = "ESTAB",
449 [NL80211_PLINK_HOLDING] = "HOLDING", 458 [NL80211_PLINK_HOLDING] = "HOLDING",
450 [NL80211_PLINK_BLOCKED] = "BLOCKED" 459 [NL80211_PLINK_BLOCKED] = "BLOCKED"
451 }; 460 };
452 #endif 461 #endif
453 462
454 /* need action_code, aux */ 463 /* need action_code, aux */
455 if (len < IEEE80211_MIN_ACTION_SIZE + 3) 464 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
456 return; 465 return;
457 466
458 if (is_multicast_ether_addr(mgmt->da)) { 467 if (is_multicast_ether_addr(mgmt->da)) {
459 mpl_dbg("Mesh plink: ignore frame from multicast address"); 468 mpl_dbg("Mesh plink: ignore frame from multicast address");
460 return; 469 return;
461 } 470 }
462 471
463 baseaddr = mgmt->u.action.u.self_prot.variable; 472 baseaddr = mgmt->u.action.u.self_prot.variable;
464 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt; 473 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
465 if (mgmt->u.action.u.self_prot.action_code == 474 if (mgmt->u.action.u.self_prot.action_code ==
466 WLAN_SP_MESH_PEERING_CONFIRM) { 475 WLAN_SP_MESH_PEERING_CONFIRM) {
467 baseaddr += 4; 476 baseaddr += 4;
468 baselen += 4; 477 baselen += 4;
469 } 478 }
470 ieee802_11_parse_elems(baseaddr, len - baselen, &elems); 479 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
471 if (!elems.peering) { 480 if (!elems.peering) {
472 mpl_dbg("Mesh plink: missing necessary peer link ie\n"); 481 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
473 return; 482 return;
474 } 483 }
475 if (elems.rsn_len && 484 if (elems.rsn_len &&
476 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) { 485 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
477 mpl_dbg("Mesh plink: can't establish link with secure peer\n"); 486 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
478 return; 487 return;
479 } 488 }
480 489
481 ftype = mgmt->u.action.u.self_prot.action_code; 490 ftype = mgmt->u.action.u.self_prot.action_code;
482 ie_len = elems.peering_len; 491 ie_len = elems.peering_len;
483 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) || 492 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
484 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) || 493 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
485 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6 494 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
486 && ie_len != 8)) { 495 && ie_len != 8)) {
487 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n", 496 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
488 ftype, ie_len); 497 ftype, ie_len);
489 return; 498 return;
490 } 499 }
491 500
492 if (ftype != WLAN_SP_MESH_PEERING_CLOSE && 501 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
493 (!elems.mesh_id || !elems.mesh_config)) { 502 (!elems.mesh_id || !elems.mesh_config)) {
494 mpl_dbg("Mesh plink: missing necessary ie\n"); 503 mpl_dbg("Mesh plink: missing necessary ie\n");
495 return; 504 return;
496 } 505 }
497 /* Note the lines below are correct, the llid in the frame is the plid 506 /* Note the lines below are correct, the llid in the frame is the plid
498 * from the point of view of this host. 507 * from the point of view of this host.
499 */ 508 */
500 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2); 509 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
501 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM || 510 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
502 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8)) 511 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
503 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2); 512 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
504 513
505 rcu_read_lock(); 514 rcu_read_lock();
506 515
507 sta = sta_info_get(sdata, mgmt->sa); 516 sta = sta_info_get(sdata, mgmt->sa);
508 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) { 517 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
509 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n"); 518 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
510 rcu_read_unlock(); 519 rcu_read_unlock();
511 return; 520 return;
512 } 521 }
513 522
514 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) { 523 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
515 mpl_dbg("Mesh plink: Action frame from non-authed peer\n"); 524 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
516 rcu_read_unlock(); 525 rcu_read_unlock();
517 return; 526 return;
518 } 527 }
519 528
520 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) { 529 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
521 rcu_read_unlock(); 530 rcu_read_unlock();
522 return; 531 return;
523 } 532 }
524 533
525 /* Now we will figure out the appropriate event... */ 534 /* Now we will figure out the appropriate event... */
526 event = PLINK_UNDEFINED; 535 event = PLINK_UNDEFINED;
527 if (ftype != WLAN_SP_MESH_PEERING_CLOSE && 536 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
528 (!mesh_matches_local(&elems, sdata))) { 537 (!mesh_matches_local(&elems, sdata))) {
529 matches_local = false; 538 matches_local = false;
530 switch (ftype) { 539 switch (ftype) {
531 case WLAN_SP_MESH_PEERING_OPEN: 540 case WLAN_SP_MESH_PEERING_OPEN:
532 event = OPN_RJCT; 541 event = OPN_RJCT;
533 break; 542 break;
534 case WLAN_SP_MESH_PEERING_CONFIRM: 543 case WLAN_SP_MESH_PEERING_CONFIRM:
535 event = CNF_RJCT; 544 event = CNF_RJCT;
536 break; 545 break;
537 default: 546 default:
538 break; 547 break;
539 } 548 }
540 } 549 }
541 550
542 if (!sta && !matches_local) { 551 if (!sta && !matches_local) {
543 rcu_read_unlock(); 552 rcu_read_unlock();
544 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); 553 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
545 llid = 0; 554 llid = 0;
546 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, 555 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
547 mgmt->sa, llid, plid, reason); 556 mgmt->sa, llid, plid, reason);
548 return; 557 return;
549 } else if (!sta) { 558 } else if (!sta) {
550 /* ftype == WLAN_SP_MESH_PEERING_OPEN */ 559 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
551 u32 rates; 560 u32 rates;
552 561
553 rcu_read_unlock(); 562 rcu_read_unlock();
554 563
555 if (!mesh_plink_free_count(sdata)) { 564 if (!mesh_plink_free_count(sdata)) {
556 mpl_dbg("Mesh plink error: no more free plinks\n"); 565 mpl_dbg("Mesh plink error: no more free plinks\n");
557 return; 566 return;
558 } 567 }
559 568
560 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band); 569 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
561 sta = mesh_plink_alloc(sdata, mgmt->sa, rates); 570 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
562 if (!sta) { 571 if (!sta) {
563 mpl_dbg("Mesh plink error: plink table full\n"); 572 mpl_dbg("Mesh plink error: plink table full\n");
564 return; 573 return;
565 } 574 }
566 if (sta_info_insert_rcu(sta)) { 575 if (sta_info_insert_rcu(sta)) {
567 rcu_read_unlock(); 576 rcu_read_unlock();
568 return; 577 return;
569 } 578 }
570 event = OPN_ACPT; 579 event = OPN_ACPT;
571 spin_lock_bh(&sta->lock); 580 spin_lock_bh(&sta->lock);
572 } else if (matches_local) { 581 } else if (matches_local) {
573 spin_lock_bh(&sta->lock); 582 spin_lock_bh(&sta->lock);
574 switch (ftype) { 583 switch (ftype) {
575 case WLAN_SP_MESH_PEERING_OPEN: 584 case WLAN_SP_MESH_PEERING_OPEN:
576 if (!mesh_plink_free_count(sdata) || 585 if (!mesh_plink_free_count(sdata) ||
577 (sta->plid && sta->plid != plid)) 586 (sta->plid && sta->plid != plid))
578 event = OPN_IGNR; 587 event = OPN_IGNR;
579 else 588 else
580 event = OPN_ACPT; 589 event = OPN_ACPT;
581 break; 590 break;
582 case WLAN_SP_MESH_PEERING_CONFIRM: 591 case WLAN_SP_MESH_PEERING_CONFIRM:
583 if (!mesh_plink_free_count(sdata) || 592 if (!mesh_plink_free_count(sdata) ||
584 (sta->llid != llid || sta->plid != plid)) 593 (sta->llid != llid || sta->plid != plid))
585 event = CNF_IGNR; 594 event = CNF_IGNR;
586 else 595 else
587 event = CNF_ACPT; 596 event = CNF_ACPT;
588 break; 597 break;
589 case WLAN_SP_MESH_PEERING_CLOSE: 598 case WLAN_SP_MESH_PEERING_CLOSE:
590 if (sta->plink_state == NL80211_PLINK_ESTAB) 599 if (sta->plink_state == NL80211_PLINK_ESTAB)
591 /* Do not check for llid or plid. This does not 600 /* Do not check for llid or plid. This does not
592 * follow the standard but since multiple plinks 601 * follow the standard but since multiple plinks
593 * per sta are not supported, it is necessary in 602 * per sta are not supported, it is necessary in
594 * order to avoid a livelock when MP A sees an 603 * order to avoid a livelock when MP A sees an
595 * establish peer link to MP B but MP B does not 604 * establish peer link to MP B but MP B does not
596 * see it. This can be caused by a timeout in 605 * see it. This can be caused by a timeout in
597 * B's peer link establishment or B beign 606 * B's peer link establishment or B beign
598 * restarted. 607 * restarted.
599 */ 608 */
600 event = CLS_ACPT; 609 event = CLS_ACPT;
601 else if (sta->plid != plid) 610 else if (sta->plid != plid)
602 event = CLS_IGNR; 611 event = CLS_IGNR;
603 else if (ie_len == 7 && sta->llid != llid) 612 else if (ie_len == 7 && sta->llid != llid)
604 event = CLS_IGNR; 613 event = CLS_IGNR;
605 else 614 else
606 event = CLS_ACPT; 615 event = CLS_ACPT;
607 break; 616 break;
608 default: 617 default:
609 mpl_dbg("Mesh plink: unknown frame subtype\n"); 618 mpl_dbg("Mesh plink: unknown frame subtype\n");
610 spin_unlock_bh(&sta->lock); 619 spin_unlock_bh(&sta->lock);
611 rcu_read_unlock(); 620 rcu_read_unlock();
612 return; 621 return;
613 } 622 }
614 } else { 623 } else {
615 spin_lock_bh(&sta->lock); 624 spin_lock_bh(&sta->lock);
616 } 625 }
617 626
618 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n", 627 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
619 mgmt->sa, mplstates[sta->plink_state], 628 mgmt->sa, mplstates[sta->plink_state],
620 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid), 629 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
621 event); 630 event);
622 reason = 0; 631 reason = 0;
623 switch (sta->plink_state) { 632 switch (sta->plink_state) {
624 /* spin_unlock as soon as state is updated at each case */ 633 /* spin_unlock as soon as state is updated at each case */
625 case NL80211_PLINK_LISTEN: 634 case NL80211_PLINK_LISTEN:
626 switch (event) { 635 switch (event) {
627 case CLS_ACPT: 636 case CLS_ACPT:
628 mesh_plink_fsm_restart(sta); 637 mesh_plink_fsm_restart(sta);
629 spin_unlock_bh(&sta->lock); 638 spin_unlock_bh(&sta->lock);
630 break; 639 break;
631 case OPN_ACPT: 640 case OPN_ACPT:
632 sta->plink_state = NL80211_PLINK_OPN_RCVD; 641 sta->plink_state = NL80211_PLINK_OPN_RCVD;
633 sta->plid = plid; 642 sta->plid = plid;
634 get_random_bytes(&llid, 2); 643 get_random_bytes(&llid, 2);
635 sta->llid = llid; 644 sta->llid = llid;
636 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); 645 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
637 spin_unlock_bh(&sta->lock); 646 spin_unlock_bh(&sta->lock);
638 mesh_plink_frame_tx(sdata, 647 mesh_plink_frame_tx(sdata,
639 WLAN_SP_MESH_PEERING_OPEN, 648 WLAN_SP_MESH_PEERING_OPEN,
640 sta->sta.addr, llid, 0, 0); 649 sta->sta.addr, llid, 0, 0);
641 mesh_plink_frame_tx(sdata, 650 mesh_plink_frame_tx(sdata,
642 WLAN_SP_MESH_PEERING_CONFIRM, 651 WLAN_SP_MESH_PEERING_CONFIRM,
643 sta->sta.addr, llid, plid, 0); 652 sta->sta.addr, llid, plid, 0);
644 break; 653 break;
645 default: 654 default:
646 spin_unlock_bh(&sta->lock); 655 spin_unlock_bh(&sta->lock);
647 break; 656 break;
648 } 657 }
649 break; 658 break;
650 659
651 case NL80211_PLINK_OPN_SNT: 660 case NL80211_PLINK_OPN_SNT:
652 switch (event) { 661 switch (event) {
653 case OPN_RJCT: 662 case OPN_RJCT:
654 case CNF_RJCT: 663 case CNF_RJCT:
655 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); 664 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
656 case CLS_ACPT: 665 case CLS_ACPT:
657 if (!reason) 666 if (!reason)
658 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); 667 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
659 sta->reason = reason; 668 sta->reason = reason;
660 sta->plink_state = NL80211_PLINK_HOLDING; 669 sta->plink_state = NL80211_PLINK_HOLDING;
661 if (!mod_plink_timer(sta, 670 if (!mod_plink_timer(sta,
662 dot11MeshHoldingTimeout(sdata))) 671 dot11MeshHoldingTimeout(sdata)))
663 sta->ignore_plink_timer = true; 672 sta->ignore_plink_timer = true;
664 673
665 llid = sta->llid; 674 llid = sta->llid;
666 spin_unlock_bh(&sta->lock); 675 spin_unlock_bh(&sta->lock);
667 mesh_plink_frame_tx(sdata, 676 mesh_plink_frame_tx(sdata,
668 WLAN_SP_MESH_PEERING_CLOSE, 677 WLAN_SP_MESH_PEERING_CLOSE,
669 sta->sta.addr, llid, plid, reason); 678 sta->sta.addr, llid, plid, reason);
670 break; 679 break;
671 case OPN_ACPT: 680 case OPN_ACPT:
672 /* retry timer is left untouched */ 681 /* retry timer is left untouched */
673 sta->plink_state = NL80211_PLINK_OPN_RCVD; 682 sta->plink_state = NL80211_PLINK_OPN_RCVD;
674 sta->plid = plid; 683 sta->plid = plid;
675 llid = sta->llid; 684 llid = sta->llid;
676 spin_unlock_bh(&sta->lock); 685 spin_unlock_bh(&sta->lock);
677 mesh_plink_frame_tx(sdata, 686 mesh_plink_frame_tx(sdata,
678 WLAN_SP_MESH_PEERING_CONFIRM, 687 WLAN_SP_MESH_PEERING_CONFIRM,
679 sta->sta.addr, llid, plid, 0); 688 sta->sta.addr, llid, plid, 0);
680 break; 689 break;
681 case CNF_ACPT: 690 case CNF_ACPT:
682 sta->plink_state = NL80211_PLINK_CNF_RCVD; 691 sta->plink_state = NL80211_PLINK_CNF_RCVD;
683 if (!mod_plink_timer(sta, 692 if (!mod_plink_timer(sta,
684 dot11MeshConfirmTimeout(sdata))) 693 dot11MeshConfirmTimeout(sdata)))
685 sta->ignore_plink_timer = true; 694 sta->ignore_plink_timer = true;
686 695
687 spin_unlock_bh(&sta->lock); 696 spin_unlock_bh(&sta->lock);
688 break; 697 break;
689 default: 698 default:
690 spin_unlock_bh(&sta->lock); 699 spin_unlock_bh(&sta->lock);
691 break; 700 break;
692 } 701 }
693 break; 702 break;
694 703
695 case NL80211_PLINK_OPN_RCVD: 704 case NL80211_PLINK_OPN_RCVD:
696 switch (event) { 705 switch (event) {
697 case OPN_RJCT: 706 case OPN_RJCT:
698 case CNF_RJCT: 707 case CNF_RJCT:
699 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); 708 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
700 case CLS_ACPT: 709 case CLS_ACPT:
701 if (!reason) 710 if (!reason)
702 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); 711 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
703 sta->reason = reason; 712 sta->reason = reason;
704 sta->plink_state = NL80211_PLINK_HOLDING; 713 sta->plink_state = NL80211_PLINK_HOLDING;
705 if (!mod_plink_timer(sta, 714 if (!mod_plink_timer(sta,
706 dot11MeshHoldingTimeout(sdata))) 715 dot11MeshHoldingTimeout(sdata)))
707 sta->ignore_plink_timer = true; 716 sta->ignore_plink_timer = true;
708 717
709 llid = sta->llid; 718 llid = sta->llid;
710 spin_unlock_bh(&sta->lock); 719 spin_unlock_bh(&sta->lock);
711 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, 720 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
712 sta->sta.addr, llid, plid, reason); 721 sta->sta.addr, llid, plid, reason);
713 break; 722 break;
714 case OPN_ACPT: 723 case OPN_ACPT:
715 llid = sta->llid; 724 llid = sta->llid;
716 spin_unlock_bh(&sta->lock); 725 spin_unlock_bh(&sta->lock);
717 mesh_plink_frame_tx(sdata, 726 mesh_plink_frame_tx(sdata,
718 WLAN_SP_MESH_PEERING_CONFIRM, 727 WLAN_SP_MESH_PEERING_CONFIRM,
719 sta->sta.addr, llid, plid, 0); 728 sta->sta.addr, llid, plid, 0);
720 break; 729 break;
721 case CNF_ACPT: 730 case CNF_ACPT:
722 del_timer(&sta->plink_timer); 731 del_timer(&sta->plink_timer);
723 sta->plink_state = NL80211_PLINK_ESTAB; 732 sta->plink_state = NL80211_PLINK_ESTAB;
724 spin_unlock_bh(&sta->lock); 733 spin_unlock_bh(&sta->lock);
725 mesh_plink_inc_estab_count(sdata); 734 mesh_plink_inc_estab_count(sdata);
726 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); 735 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
727 mpl_dbg("Mesh plink with %pM ESTABLISHED\n", 736 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
728 sta->sta.addr); 737 sta->sta.addr);
729 break; 738 break;
730 default: 739 default:
731 spin_unlock_bh(&sta->lock); 740 spin_unlock_bh(&sta->lock);
732 break; 741 break;
733 } 742 }
734 break; 743 break;
735 744
736 case NL80211_PLINK_CNF_RCVD: 745 case NL80211_PLINK_CNF_RCVD:
737 switch (event) { 746 switch (event) {
738 case OPN_RJCT: 747 case OPN_RJCT:
739 case CNF_RJCT: 748 case CNF_RJCT:
740 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); 749 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
741 case CLS_ACPT: 750 case CLS_ACPT:
742 if (!reason) 751 if (!reason)
743 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); 752 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
744 sta->reason = reason; 753 sta->reason = reason;
745 sta->plink_state = NL80211_PLINK_HOLDING; 754 sta->plink_state = NL80211_PLINK_HOLDING;
746 if (!mod_plink_timer(sta, 755 if (!mod_plink_timer(sta,
747 dot11MeshHoldingTimeout(sdata))) 756 dot11MeshHoldingTimeout(sdata)))
748 sta->ignore_plink_timer = true; 757 sta->ignore_plink_timer = true;
749 758
750 llid = sta->llid; 759 llid = sta->llid;
751 spin_unlock_bh(&sta->lock); 760 spin_unlock_bh(&sta->lock);
752 mesh_plink_frame_tx(sdata, 761 mesh_plink_frame_tx(sdata,
753 WLAN_SP_MESH_PEERING_CLOSE, 762 WLAN_SP_MESH_PEERING_CLOSE,
754 sta->sta.addr, llid, plid, reason); 763 sta->sta.addr, llid, plid, reason);
755 break; 764 break;
756 case OPN_ACPT: 765 case OPN_ACPT:
757 del_timer(&sta->plink_timer); 766 del_timer(&sta->plink_timer);
758 sta->plink_state = NL80211_PLINK_ESTAB; 767 sta->plink_state = NL80211_PLINK_ESTAB;
759 spin_unlock_bh(&sta->lock); 768 spin_unlock_bh(&sta->lock);
760 mesh_plink_inc_estab_count(sdata); 769 mesh_plink_inc_estab_count(sdata);
761 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); 770 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
762 mpl_dbg("Mesh plink with %pM ESTABLISHED\n", 771 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
763 sta->sta.addr); 772 sta->sta.addr);
764 mesh_plink_frame_tx(sdata, 773 mesh_plink_frame_tx(sdata,
765 WLAN_SP_MESH_PEERING_CONFIRM, 774 WLAN_SP_MESH_PEERING_CONFIRM,
766 sta->sta.addr, llid, plid, 0); 775 sta->sta.addr, llid, plid, 0);
767 break; 776 break;
768 default: 777 default:
769 spin_unlock_bh(&sta->lock); 778 spin_unlock_bh(&sta->lock);
770 break; 779 break;
771 } 780 }
772 break; 781 break;
773 782
774 case NL80211_PLINK_ESTAB: 783 case NL80211_PLINK_ESTAB:
775 switch (event) { 784 switch (event) {
776 case CLS_ACPT: 785 case CLS_ACPT:
777 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); 786 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
778 sta->reason = reason; 787 sta->reason = reason;
779 deactivated = __mesh_plink_deactivate(sta); 788 deactivated = __mesh_plink_deactivate(sta);
780 sta->plink_state = NL80211_PLINK_HOLDING; 789 sta->plink_state = NL80211_PLINK_HOLDING;
781 llid = sta->llid; 790 llid = sta->llid;
782 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); 791 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
783 spin_unlock_bh(&sta->lock); 792 spin_unlock_bh(&sta->lock);
784 if (deactivated) 793 if (deactivated)
785 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); 794 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
786 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, 795 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
787 sta->sta.addr, llid, plid, reason); 796 sta->sta.addr, llid, plid, reason);
788 break; 797 break;
789 case OPN_ACPT: 798 case OPN_ACPT:
790 llid = sta->llid; 799 llid = sta->llid;
791 spin_unlock_bh(&sta->lock); 800 spin_unlock_bh(&sta->lock);
792 mesh_plink_frame_tx(sdata, 801 mesh_plink_frame_tx(sdata,
793 WLAN_SP_MESH_PEERING_CONFIRM, 802 WLAN_SP_MESH_PEERING_CONFIRM,
794 sta->sta.addr, llid, plid, 0); 803 sta->sta.addr, llid, plid, 0);
795 break; 804 break;
796 default: 805 default:
797 spin_unlock_bh(&sta->lock); 806 spin_unlock_bh(&sta->lock);
798 break; 807 break;
799 } 808 }
800 break; 809 break;
801 case NL80211_PLINK_HOLDING: 810 case NL80211_PLINK_HOLDING:
802 switch (event) { 811 switch (event) {
803 case CLS_ACPT: 812 case CLS_ACPT:
804 if (del_timer(&sta->plink_timer)) 813 if (del_timer(&sta->plink_timer))
805 sta->ignore_plink_timer = 1; 814 sta->ignore_plink_timer = 1;
806 mesh_plink_fsm_restart(sta); 815 mesh_plink_fsm_restart(sta);
807 spin_unlock_bh(&sta->lock); 816 spin_unlock_bh(&sta->lock);
808 break; 817 break;
809 case OPN_ACPT: 818 case OPN_ACPT:
810 case CNF_ACPT: 819 case CNF_ACPT:
811 case OPN_RJCT: 820 case OPN_RJCT:
812 case CNF_RJCT: 821 case CNF_RJCT:
813 llid = sta->llid; 822 llid = sta->llid;
814 reason = sta->reason; 823 reason = sta->reason;
815 spin_unlock_bh(&sta->lock); 824 spin_unlock_bh(&sta->lock);
816 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, 825 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
817 sta->sta.addr, llid, plid, reason); 826 sta->sta.addr, llid, plid, reason);
818 break; 827 break;
819 default: 828 default:
820 spin_unlock_bh(&sta->lock); 829 spin_unlock_bh(&sta->lock);
821 } 830 }
822 break; 831 break;
823 default: 832 default:
824 /* should not get here, PLINK_BLOCKED is dealt with at the 833 /* should not get here, PLINK_BLOCKED is dealt with at the
825 * beginning of the function 834 * beginning of the function
826 */ 835 */
827 spin_unlock_bh(&sta->lock); 836 spin_unlock_bh(&sta->lock);
828 break; 837 break;
829 } 838 }
830 839
831 rcu_read_unlock(); 840 rcu_read_unlock();
832 } 841 }
833 842
1 /* 1 /*
2 * Copyright 2002-2005, Instant802 Networks, Inc. 2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc. 3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 * 10 *
11 * 11 *
12 * Transmit and frame generation functions. 12 * Transmit and frame generation functions.
13 */ 13 */
14 14
15 #include <linux/kernel.h> 15 #include <linux/kernel.h>
16 #include <linux/slab.h> 16 #include <linux/slab.h>
17 #include <linux/skbuff.h> 17 #include <linux/skbuff.h>
18 #include <linux/etherdevice.h> 18 #include <linux/etherdevice.h>
19 #include <linux/bitmap.h> 19 #include <linux/bitmap.h>
20 #include <linux/rcupdate.h> 20 #include <linux/rcupdate.h>
21 #include <net/net_namespace.h> 21 #include <net/net_namespace.h>
22 #include <net/ieee80211_radiotap.h> 22 #include <net/ieee80211_radiotap.h>
23 #include <net/cfg80211.h> 23 #include <net/cfg80211.h>
24 #include <net/mac80211.h> 24 #include <net/mac80211.h>
25 #include <asm/unaligned.h> 25 #include <asm/unaligned.h>
26 26
27 #include "ieee80211_i.h" 27 #include "ieee80211_i.h"
28 #include "driver-ops.h" 28 #include "driver-ops.h"
29 #include "led.h" 29 #include "led.h"
30 #include "mesh.h" 30 #include "mesh.h"
31 #include "wep.h" 31 #include "wep.h"
32 #include "wpa.h" 32 #include "wpa.h"
33 #include "wme.h" 33 #include "wme.h"
34 #include "rate.h" 34 #include "rate.h"
35 35
36 /* misc utils */ 36 /* misc utils */
37 37
38 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr, 38 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
39 int next_frag_len) 39 int next_frag_len)
40 { 40 {
41 int rate, mrate, erp, dur, i; 41 int rate, mrate, erp, dur, i;
42 struct ieee80211_rate *txrate; 42 struct ieee80211_rate *txrate;
43 struct ieee80211_local *local = tx->local; 43 struct ieee80211_local *local = tx->local;
44 struct ieee80211_supported_band *sband; 44 struct ieee80211_supported_band *sband;
45 struct ieee80211_hdr *hdr; 45 struct ieee80211_hdr *hdr;
46 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 46 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
47 47
48 /* assume HW handles this */ 48 /* assume HW handles this */
49 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS) 49 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
50 return 0; 50 return 0;
51 51
52 /* uh huh? */ 52 /* uh huh? */
53 if (WARN_ON_ONCE(info->control.rates[0].idx < 0)) 53 if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
54 return 0; 54 return 0;
55 55
56 sband = local->hw.wiphy->bands[tx->channel->band]; 56 sband = local->hw.wiphy->bands[tx->channel->band];
57 txrate = &sband->bitrates[info->control.rates[0].idx]; 57 txrate = &sband->bitrates[info->control.rates[0].idx];
58 58
59 erp = txrate->flags & IEEE80211_RATE_ERP_G; 59 erp = txrate->flags & IEEE80211_RATE_ERP_G;
60 60
61 /* 61 /*
62 * data and mgmt (except PS Poll): 62 * data and mgmt (except PS Poll):
63 * - during CFP: 32768 63 * - during CFP: 32768
64 * - during contention period: 64 * - during contention period:
65 * if addr1 is group address: 0 65 * if addr1 is group address: 0
66 * if more fragments = 0 and addr1 is individual address: time to 66 * if more fragments = 0 and addr1 is individual address: time to
67 * transmit one ACK plus SIFS 67 * transmit one ACK plus SIFS
68 * if more fragments = 1 and addr1 is individual address: time to 68 * if more fragments = 1 and addr1 is individual address: time to
69 * transmit next fragment plus 2 x ACK plus 3 x SIFS 69 * transmit next fragment plus 2 x ACK plus 3 x SIFS
70 * 70 *
71 * IEEE 802.11, 9.6: 71 * IEEE 802.11, 9.6:
72 * - control response frame (CTS or ACK) shall be transmitted using the 72 * - control response frame (CTS or ACK) shall be transmitted using the
73 * same rate as the immediately previous frame in the frame exchange 73 * same rate as the immediately previous frame in the frame exchange
74 * sequence, if this rate belongs to the PHY mandatory rates, or else 74 * sequence, if this rate belongs to the PHY mandatory rates, or else
75 * at the highest possible rate belonging to the PHY rates in the 75 * at the highest possible rate belonging to the PHY rates in the
76 * BSSBasicRateSet 76 * BSSBasicRateSet
77 */ 77 */
78 hdr = (struct ieee80211_hdr *)tx->skb->data; 78 hdr = (struct ieee80211_hdr *)tx->skb->data;
79 if (ieee80211_is_ctl(hdr->frame_control)) { 79 if (ieee80211_is_ctl(hdr->frame_control)) {
80 /* TODO: These control frames are not currently sent by 80 /* TODO: These control frames are not currently sent by
81 * mac80211, but should they be implemented, this function 81 * mac80211, but should they be implemented, this function
82 * needs to be updated to support duration field calculation. 82 * needs to be updated to support duration field calculation.
83 * 83 *
84 * RTS: time needed to transmit pending data/mgmt frame plus 84 * RTS: time needed to transmit pending data/mgmt frame plus
85 * one CTS frame plus one ACK frame plus 3 x SIFS 85 * one CTS frame plus one ACK frame plus 3 x SIFS
86 * CTS: duration of immediately previous RTS minus time 86 * CTS: duration of immediately previous RTS minus time
87 * required to transmit CTS and its SIFS 87 * required to transmit CTS and its SIFS
88 * ACK: 0 if immediately previous directed data/mgmt had 88 * ACK: 0 if immediately previous directed data/mgmt had
89 * more=0, with more=1 duration in ACK frame is duration 89 * more=0, with more=1 duration in ACK frame is duration
90 * from previous frame minus time needed to transmit ACK 90 * from previous frame minus time needed to transmit ACK
91 * and its SIFS 91 * and its SIFS
92 * PS Poll: BIT(15) | BIT(14) | aid 92 * PS Poll: BIT(15) | BIT(14) | aid
93 */ 93 */
94 return 0; 94 return 0;
95 } 95 }
96 96
97 /* data/mgmt */ 97 /* data/mgmt */
98 if (0 /* FIX: data/mgmt during CFP */) 98 if (0 /* FIX: data/mgmt during CFP */)
99 return cpu_to_le16(32768); 99 return cpu_to_le16(32768);
100 100
101 if (group_addr) /* Group address as the destination - no ACK */ 101 if (group_addr) /* Group address as the destination - no ACK */
102 return 0; 102 return 0;
103 103
104 /* Individual destination address: 104 /* Individual destination address:
105 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes) 105 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
106 * CTS and ACK frames shall be transmitted using the highest rate in 106 * CTS and ACK frames shall be transmitted using the highest rate in
107 * basic rate set that is less than or equal to the rate of the 107 * basic rate set that is less than or equal to the rate of the
108 * immediately previous frame and that is using the same modulation 108 * immediately previous frame and that is using the same modulation
109 * (CCK or OFDM). If no basic rate set matches with these requirements, 109 * (CCK or OFDM). If no basic rate set matches with these requirements,
110 * the highest mandatory rate of the PHY that is less than or equal to 110 * the highest mandatory rate of the PHY that is less than or equal to
111 * the rate of the previous frame is used. 111 * the rate of the previous frame is used.
112 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps 112 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
113 */ 113 */
114 rate = -1; 114 rate = -1;
115 /* use lowest available if everything fails */ 115 /* use lowest available if everything fails */
116 mrate = sband->bitrates[0].bitrate; 116 mrate = sband->bitrates[0].bitrate;
117 for (i = 0; i < sband->n_bitrates; i++) { 117 for (i = 0; i < sband->n_bitrates; i++) {
118 struct ieee80211_rate *r = &sband->bitrates[i]; 118 struct ieee80211_rate *r = &sband->bitrates[i];
119 119
120 if (r->bitrate > txrate->bitrate) 120 if (r->bitrate > txrate->bitrate)
121 break; 121 break;
122 122
123 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i)) 123 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
124 rate = r->bitrate; 124 rate = r->bitrate;
125 125
126 switch (sband->band) { 126 switch (sband->band) {
127 case IEEE80211_BAND_2GHZ: { 127 case IEEE80211_BAND_2GHZ: {
128 u32 flag; 128 u32 flag;
129 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 129 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
130 flag = IEEE80211_RATE_MANDATORY_G; 130 flag = IEEE80211_RATE_MANDATORY_G;
131 else 131 else
132 flag = IEEE80211_RATE_MANDATORY_B; 132 flag = IEEE80211_RATE_MANDATORY_B;
133 if (r->flags & flag) 133 if (r->flags & flag)
134 mrate = r->bitrate; 134 mrate = r->bitrate;
135 break; 135 break;
136 } 136 }
137 case IEEE80211_BAND_5GHZ: 137 case IEEE80211_BAND_5GHZ:
138 if (r->flags & IEEE80211_RATE_MANDATORY_A) 138 if (r->flags & IEEE80211_RATE_MANDATORY_A)
139 mrate = r->bitrate; 139 mrate = r->bitrate;
140 break; 140 break;
141 case IEEE80211_NUM_BANDS: 141 case IEEE80211_NUM_BANDS:
142 WARN_ON(1); 142 WARN_ON(1);
143 break; 143 break;
144 } 144 }
145 } 145 }
146 if (rate == -1) { 146 if (rate == -1) {
147 /* No matching basic rate found; use highest suitable mandatory 147 /* No matching basic rate found; use highest suitable mandatory
148 * PHY rate */ 148 * PHY rate */
149 rate = mrate; 149 rate = mrate;
150 } 150 }
151 151
152 /* Time needed to transmit ACK 152 /* Time needed to transmit ACK
153 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up 153 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
154 * to closest integer */ 154 * to closest integer */
155 155
156 dur = ieee80211_frame_duration(local, 10, rate, erp, 156 dur = ieee80211_frame_duration(local, 10, rate, erp,
157 tx->sdata->vif.bss_conf.use_short_preamble); 157 tx->sdata->vif.bss_conf.use_short_preamble);
158 158
159 if (next_frag_len) { 159 if (next_frag_len) {
160 /* Frame is fragmented: duration increases with time needed to 160 /* Frame is fragmented: duration increases with time needed to
161 * transmit next fragment plus ACK and 2 x SIFS. */ 161 * transmit next fragment plus ACK and 2 x SIFS. */
162 dur *= 2; /* ACK + SIFS */ 162 dur *= 2; /* ACK + SIFS */
163 /* next fragment */ 163 /* next fragment */
164 dur += ieee80211_frame_duration(local, next_frag_len, 164 dur += ieee80211_frame_duration(local, next_frag_len,
165 txrate->bitrate, erp, 165 txrate->bitrate, erp,
166 tx->sdata->vif.bss_conf.use_short_preamble); 166 tx->sdata->vif.bss_conf.use_short_preamble);
167 } 167 }
168 168
169 return cpu_to_le16(dur); 169 return cpu_to_le16(dur);
170 } 170 }
171 171
172 static inline int is_ieee80211_device(struct ieee80211_local *local, 172 static inline int is_ieee80211_device(struct ieee80211_local *local,
173 struct net_device *dev) 173 struct net_device *dev)
174 { 174 {
175 return local == wdev_priv(dev->ieee80211_ptr); 175 return local == wdev_priv(dev->ieee80211_ptr);
176 } 176 }
177 177
178 /* tx handlers */ 178 /* tx handlers */
179 static ieee80211_tx_result debug_noinline 179 static ieee80211_tx_result debug_noinline
180 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) 180 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
181 { 181 {
182 struct ieee80211_local *local = tx->local; 182 struct ieee80211_local *local = tx->local;
183 struct ieee80211_if_managed *ifmgd; 183 struct ieee80211_if_managed *ifmgd;
184 184
185 /* driver doesn't support power save */ 185 /* driver doesn't support power save */
186 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) 186 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
187 return TX_CONTINUE; 187 return TX_CONTINUE;
188 188
189 /* hardware does dynamic power save */ 189 /* hardware does dynamic power save */
190 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) 190 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
191 return TX_CONTINUE; 191 return TX_CONTINUE;
192 192
193 /* dynamic power save disabled */ 193 /* dynamic power save disabled */
194 if (local->hw.conf.dynamic_ps_timeout <= 0) 194 if (local->hw.conf.dynamic_ps_timeout <= 0)
195 return TX_CONTINUE; 195 return TX_CONTINUE;
196 196
197 /* we are scanning, don't enable power save */ 197 /* we are scanning, don't enable power save */
198 if (local->scanning) 198 if (local->scanning)
199 return TX_CONTINUE; 199 return TX_CONTINUE;
200 200
201 if (!local->ps_sdata) 201 if (!local->ps_sdata)
202 return TX_CONTINUE; 202 return TX_CONTINUE;
203 203
204 /* No point if we're going to suspend */ 204 /* No point if we're going to suspend */
205 if (local->quiescing) 205 if (local->quiescing)
206 return TX_CONTINUE; 206 return TX_CONTINUE;
207 207
208 /* dynamic ps is supported only in managed mode */ 208 /* dynamic ps is supported only in managed mode */
209 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION) 209 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
210 return TX_CONTINUE; 210 return TX_CONTINUE;
211 211
212 ifmgd = &tx->sdata->u.mgd; 212 ifmgd = &tx->sdata->u.mgd;
213 213
214 /* 214 /*
215 * Don't wakeup from power save if u-apsd is enabled, voip ac has 215 * Don't wakeup from power save if u-apsd is enabled, voip ac has
216 * u-apsd enabled and the frame is in voip class. This effectively 216 * u-apsd enabled and the frame is in voip class. This effectively
217 * means that even if all access categories have u-apsd enabled, in 217 * means that even if all access categories have u-apsd enabled, in
218 * practise u-apsd is only used with the voip ac. This is a 218 * practise u-apsd is only used with the voip ac. This is a
219 * workaround for the case when received voip class packets do not 219 * workaround for the case when received voip class packets do not
220 * have correct qos tag for some reason, due the network or the 220 * have correct qos tag for some reason, due the network or the
221 * peer application. 221 * peer application.
222 * 222 *
223 * Note: local->uapsd_queues access is racy here. If the value is 223 * Note: local->uapsd_queues access is racy here. If the value is
224 * changed via debugfs, user needs to reassociate manually to have 224 * changed via debugfs, user needs to reassociate manually to have
225 * everything in sync. 225 * everything in sync.
226 */ 226 */
227 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) 227 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
228 && (local->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) 228 && (local->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
229 && skb_get_queue_mapping(tx->skb) == 0) 229 && skb_get_queue_mapping(tx->skb) == 0)
230 return TX_CONTINUE; 230 return TX_CONTINUE;
231 231
232 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 232 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
233 ieee80211_stop_queues_by_reason(&local->hw, 233 ieee80211_stop_queues_by_reason(&local->hw,
234 IEEE80211_QUEUE_STOP_REASON_PS); 234 IEEE80211_QUEUE_STOP_REASON_PS);
235 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; 235 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
236 ieee80211_queue_work(&local->hw, 236 ieee80211_queue_work(&local->hw,
237 &local->dynamic_ps_disable_work); 237 &local->dynamic_ps_disable_work);
238 } 238 }
239 239
240 /* Don't restart the timer if we're not disassociated */ 240 /* Don't restart the timer if we're not disassociated */
241 if (!ifmgd->associated) 241 if (!ifmgd->associated)
242 return TX_CONTINUE; 242 return TX_CONTINUE;
243 243
244 mod_timer(&local->dynamic_ps_timer, jiffies + 244 mod_timer(&local->dynamic_ps_timer, jiffies +
245 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); 245 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
246 246
247 return TX_CONTINUE; 247 return TX_CONTINUE;
248 } 248 }
249 249
250 static ieee80211_tx_result debug_noinline 250 static ieee80211_tx_result debug_noinline
251 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) 251 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
252 { 252 {
253 253
254 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 254 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
255 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 255 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
256 bool assoc = false; 256 bool assoc = false;
257 257
258 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) 258 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
259 return TX_CONTINUE; 259 return TX_CONTINUE;
260 260
261 if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) && 261 if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) &&
262 test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) && 262 test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) &&
263 !ieee80211_is_probe_req(hdr->frame_control) && 263 !ieee80211_is_probe_req(hdr->frame_control) &&
264 !ieee80211_is_nullfunc(hdr->frame_control)) 264 !ieee80211_is_nullfunc(hdr->frame_control))
265 /* 265 /*
266 * When software scanning only nullfunc frames (to notify 266 * When software scanning only nullfunc frames (to notify
267 * the sleep state to the AP) and probe requests (for the 267 * the sleep state to the AP) and probe requests (for the
268 * active scan) are allowed, all other frames should not be 268 * active scan) are allowed, all other frames should not be
269 * sent and we should not get here, but if we do 269 * sent and we should not get here, but if we do
270 * nonetheless, drop them to avoid sending them 270 * nonetheless, drop them to avoid sending them
271 * off-channel. See the link below and 271 * off-channel. See the link below and
272 * ieee80211_start_scan() for more. 272 * ieee80211_start_scan() for more.
273 * 273 *
274 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089 274 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
275 */ 275 */
276 return TX_DROP; 276 return TX_DROP;
277 277
278 if (tx->sdata->vif.type == NL80211_IFTYPE_WDS) 278 if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
279 return TX_CONTINUE; 279 return TX_CONTINUE;
280 280
281 if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT) 281 if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
282 return TX_CONTINUE; 282 return TX_CONTINUE;
283 283
284 if (tx->flags & IEEE80211_TX_PS_BUFFERED) 284 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
285 return TX_CONTINUE; 285 return TX_CONTINUE;
286 286
287 if (tx->sta) 287 if (tx->sta)
288 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); 288 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
289 289
290 if (likely(tx->flags & IEEE80211_TX_UNICAST)) { 290 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
291 if (unlikely(!assoc && 291 if (unlikely(!assoc &&
292 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC && 292 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
293 ieee80211_is_data(hdr->frame_control))) { 293 ieee80211_is_data(hdr->frame_control))) {
294 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 294 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
295 printk(KERN_DEBUG "%s: dropped data frame to not " 295 printk(KERN_DEBUG "%s: dropped data frame to not "
296 "associated station %pM\n", 296 "associated station %pM\n",
297 tx->sdata->name, hdr->addr1); 297 tx->sdata->name, hdr->addr1);
298 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 298 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
299 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); 299 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
300 return TX_DROP; 300 return TX_DROP;
301 } 301 }
302 } else { 302 } else {
303 if (unlikely(ieee80211_is_data(hdr->frame_control) && 303 if (unlikely(ieee80211_is_data(hdr->frame_control) &&
304 tx->local->num_sta == 0 && 304 tx->local->num_sta == 0 &&
305 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) { 305 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
306 /* 306 /*
307 * No associated STAs - no need to send multicast 307 * No associated STAs - no need to send multicast
308 * frames. 308 * frames.
309 */ 309 */
310 return TX_DROP; 310 return TX_DROP;
311 } 311 }
312 return TX_CONTINUE; 312 return TX_CONTINUE;
313 } 313 }
314 314
315 return TX_CONTINUE; 315 return TX_CONTINUE;
316 } 316 }
317 317
318 /* This function is called whenever the AP is about to exceed the maximum limit 318 /* This function is called whenever the AP is about to exceed the maximum limit
319 * of buffered frames for power saving STAs. This situation should not really 319 * of buffered frames for power saving STAs. This situation should not really
320 * happen often during normal operation, so dropping the oldest buffered packet 320 * happen often during normal operation, so dropping the oldest buffered packet
321 * from each queue should be OK to make some room for new frames. */ 321 * from each queue should be OK to make some room for new frames. */
322 static void purge_old_ps_buffers(struct ieee80211_local *local) 322 static void purge_old_ps_buffers(struct ieee80211_local *local)
323 { 323 {
324 int total = 0, purged = 0; 324 int total = 0, purged = 0;
325 struct sk_buff *skb; 325 struct sk_buff *skb;
326 struct ieee80211_sub_if_data *sdata; 326 struct ieee80211_sub_if_data *sdata;
327 struct sta_info *sta; 327 struct sta_info *sta;
328 328
329 /* 329 /*
330 * virtual interfaces are protected by RCU 330 * virtual interfaces are protected by RCU
331 */ 331 */
332 rcu_read_lock(); 332 rcu_read_lock();
333 333
334 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 334 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
335 struct ieee80211_if_ap *ap; 335 struct ieee80211_if_ap *ap;
336 if (sdata->vif.type != NL80211_IFTYPE_AP) 336 if (sdata->vif.type != NL80211_IFTYPE_AP)
337 continue; 337 continue;
338 ap = &sdata->u.ap; 338 ap = &sdata->u.ap;
339 skb = skb_dequeue(&ap->ps_bc_buf); 339 skb = skb_dequeue(&ap->ps_bc_buf);
340 if (skb) { 340 if (skb) {
341 purged++; 341 purged++;
342 dev_kfree_skb(skb); 342 dev_kfree_skb(skb);
343 } 343 }
344 total += skb_queue_len(&ap->ps_bc_buf); 344 total += skb_queue_len(&ap->ps_bc_buf);
345 } 345 }
346 346
347 /* 347 /*
348 * Drop one frame from each station from the lowest-priority 348 * Drop one frame from each station from the lowest-priority
349 * AC that has frames at all. 349 * AC that has frames at all.
350 */ 350 */
351 list_for_each_entry_rcu(sta, &local->sta_list, list) { 351 list_for_each_entry_rcu(sta, &local->sta_list, list) {
352 int ac; 352 int ac;
353 353
354 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) { 354 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
355 skb = skb_dequeue(&sta->ps_tx_buf[ac]); 355 skb = skb_dequeue(&sta->ps_tx_buf[ac]);
356 total += skb_queue_len(&sta->ps_tx_buf[ac]); 356 total += skb_queue_len(&sta->ps_tx_buf[ac]);
357 if (skb) { 357 if (skb) {
358 purged++; 358 purged++;
359 dev_kfree_skb(skb); 359 dev_kfree_skb(skb);
360 break; 360 break;
361 } 361 }
362 } 362 }
363 } 363 }
364 364
365 rcu_read_unlock(); 365 rcu_read_unlock();
366 366
367 local->total_ps_buffered = total; 367 local->total_ps_buffered = total;
368 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 368 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
369 wiphy_debug(local->hw.wiphy, "PS buffers full - purged %d frames\n", 369 wiphy_debug(local->hw.wiphy, "PS buffers full - purged %d frames\n",
370 purged); 370 purged);
371 #endif 371 #endif
372 } 372 }
373 373
374 static ieee80211_tx_result 374 static ieee80211_tx_result
375 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx) 375 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
376 { 376 {
377 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 377 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
378 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 378 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
379 379
380 /* 380 /*
381 * broadcast/multicast frame 381 * broadcast/multicast frame
382 * 382 *
383 * If any of the associated stations is in power save mode, 383 * If any of the associated stations is in power save mode,
384 * the frame is buffered to be sent after DTIM beacon frame. 384 * the frame is buffered to be sent after DTIM beacon frame.
385 * This is done either by the hardware or us. 385 * This is done either by the hardware or us.
386 */ 386 */
387 387
388 /* powersaving STAs only in AP/VLAN mode */ 388 /* powersaving STAs only in AP/VLAN mode */
389 if (!tx->sdata->bss) 389 if (!tx->sdata->bss)
390 return TX_CONTINUE; 390 return TX_CONTINUE;
391 391
392 /* no buffering for ordered frames */ 392 /* no buffering for ordered frames */
393 if (ieee80211_has_order(hdr->frame_control)) 393 if (ieee80211_has_order(hdr->frame_control))
394 return TX_CONTINUE; 394 return TX_CONTINUE;
395 395
396 /* no stations in PS mode */ 396 /* no stations in PS mode */
397 if (!atomic_read(&tx->sdata->bss->num_sta_ps)) 397 if (!atomic_read(&tx->sdata->bss->num_sta_ps))
398 return TX_CONTINUE; 398 return TX_CONTINUE;
399 399
400 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM; 400 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
401 401
402 /* device releases frame after DTIM beacon */ 402 /* device releases frame after DTIM beacon */
403 if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)) 403 if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING))
404 return TX_CONTINUE; 404 return TX_CONTINUE;
405 405
406 /* buffered in mac80211 */ 406 /* buffered in mac80211 */
407 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 407 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
408 purge_old_ps_buffers(tx->local); 408 purge_old_ps_buffers(tx->local);
409 409
410 if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= AP_MAX_BC_BUFFER) { 410 if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= AP_MAX_BC_BUFFER) {
411 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 411 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
412 if (net_ratelimit()) 412 if (net_ratelimit())
413 printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n", 413 printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n",
414 tx->sdata->name); 414 tx->sdata->name);
415 #endif 415 #endif
416 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf)); 416 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
417 } else 417 } else
418 tx->local->total_ps_buffered++; 418 tx->local->total_ps_buffered++;
419 419
420 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb); 420 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
421 421
422 return TX_QUEUED; 422 return TX_QUEUED;
423 } 423 }
424 424
425 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta, 425 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
426 struct sk_buff *skb) 426 struct sk_buff *skb)
427 { 427 {
428 if (!ieee80211_is_mgmt(fc)) 428 if (!ieee80211_is_mgmt(fc))
429 return 0; 429 return 0;
430 430
431 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP)) 431 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
432 return 0; 432 return 0;
433 433
434 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) 434 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
435 skb->data)) 435 skb->data))
436 return 0; 436 return 0;
437 437
438 return 1; 438 return 1;
439 } 439 }
440 440
441 static ieee80211_tx_result 441 static ieee80211_tx_result
442 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx) 442 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
443 { 443 {
444 struct sta_info *sta = tx->sta; 444 struct sta_info *sta = tx->sta;
445 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 445 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
446 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 446 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
447 struct ieee80211_local *local = tx->local; 447 struct ieee80211_local *local = tx->local;
448 448
449 if (unlikely(!sta || 449 if (unlikely(!sta ||
450 ieee80211_is_probe_resp(hdr->frame_control) || 450 ieee80211_is_probe_resp(hdr->frame_control) ||
451 ieee80211_is_auth(hdr->frame_control) || 451 ieee80211_is_auth(hdr->frame_control) ||
452 ieee80211_is_assoc_resp(hdr->frame_control) || 452 ieee80211_is_assoc_resp(hdr->frame_control) ||
453 ieee80211_is_reassoc_resp(hdr->frame_control))) 453 ieee80211_is_reassoc_resp(hdr->frame_control)))
454 return TX_CONTINUE; 454 return TX_CONTINUE;
455 455
456 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) || 456 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
457 test_sta_flag(sta, WLAN_STA_PS_DRIVER)) && 457 test_sta_flag(sta, WLAN_STA_PS_DRIVER)) &&
458 !(info->flags & IEEE80211_TX_CTL_POLL_RESPONSE))) { 458 !(info->flags & IEEE80211_TX_CTL_POLL_RESPONSE))) {
459 int ac = skb_get_queue_mapping(tx->skb); 459 int ac = skb_get_queue_mapping(tx->skb);
460 460
461 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 461 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
462 printk(KERN_DEBUG "STA %pM aid %d: PS buffer for AC %d\n", 462 printk(KERN_DEBUG "STA %pM aid %d: PS buffer for AC %d\n",
463 sta->sta.addr, sta->sta.aid, ac); 463 sta->sta.addr, sta->sta.aid, ac);
464 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 464 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
465 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 465 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
466 purge_old_ps_buffers(tx->local); 466 purge_old_ps_buffers(tx->local);
467 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) { 467 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
468 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]); 468 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
469 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 469 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
470 if (net_ratelimit()) 470 if (net_ratelimit())
471 printk(KERN_DEBUG "%s: STA %pM TX buffer for " 471 printk(KERN_DEBUG "%s: STA %pM TX buffer for "
472 "AC %d full - dropping oldest frame\n", 472 "AC %d full - dropping oldest frame\n",
473 tx->sdata->name, sta->sta.addr, ac); 473 tx->sdata->name, sta->sta.addr, ac);
474 #endif 474 #endif
475 dev_kfree_skb(old); 475 dev_kfree_skb(old);
476 } else 476 } else
477 tx->local->total_ps_buffered++; 477 tx->local->total_ps_buffered++;
478 478
479 info->control.jiffies = jiffies; 479 info->control.jiffies = jiffies;
480 info->control.vif = &tx->sdata->vif; 480 info->control.vif = &tx->sdata->vif;
481 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 481 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
482 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb); 482 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
483 483
484 if (!timer_pending(&local->sta_cleanup)) 484 if (!timer_pending(&local->sta_cleanup))
485 mod_timer(&local->sta_cleanup, 485 mod_timer(&local->sta_cleanup,
486 round_jiffies(jiffies + 486 round_jiffies(jiffies +
487 STA_INFO_CLEANUP_INTERVAL)); 487 STA_INFO_CLEANUP_INTERVAL));
488 488
489 /* 489 /*
490 * We queued up some frames, so the TIM bit might 490 * We queued up some frames, so the TIM bit might
491 * need to be set, recalculate it. 491 * need to be set, recalculate it.
492 */ 492 */
493 sta_info_recalc_tim(sta); 493 sta_info_recalc_tim(sta);
494 494
495 return TX_QUEUED; 495 return TX_QUEUED;
496 } 496 }
497 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 497 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
498 else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) { 498 else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
499 printk(KERN_DEBUG 499 printk(KERN_DEBUG
500 "%s: STA %pM in PS mode, but polling/in SP -> send frame\n", 500 "%s: STA %pM in PS mode, but polling/in SP -> send frame\n",
501 tx->sdata->name, sta->sta.addr); 501 tx->sdata->name, sta->sta.addr);
502 } 502 }
503 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 503 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
504 504
505 return TX_CONTINUE; 505 return TX_CONTINUE;
506 } 506 }
507 507
508 static ieee80211_tx_result debug_noinline 508 static ieee80211_tx_result debug_noinline
509 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx) 509 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
510 { 510 {
511 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED)) 511 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
512 return TX_CONTINUE; 512 return TX_CONTINUE;
513 513
514 if (tx->flags & IEEE80211_TX_UNICAST) 514 if (tx->flags & IEEE80211_TX_UNICAST)
515 return ieee80211_tx_h_unicast_ps_buf(tx); 515 return ieee80211_tx_h_unicast_ps_buf(tx);
516 else 516 else
517 return ieee80211_tx_h_multicast_ps_buf(tx); 517 return ieee80211_tx_h_multicast_ps_buf(tx);
518 } 518 }
519 519
520 static ieee80211_tx_result debug_noinline 520 static ieee80211_tx_result debug_noinline
521 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx) 521 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
522 { 522 {
523 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 523 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
524 524
525 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol && 525 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol &&
526 tx->sdata->control_port_no_encrypt)) 526 tx->sdata->control_port_no_encrypt))
527 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 527 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
528 528
529 return TX_CONTINUE; 529 return TX_CONTINUE;
530 } 530 }
531 531
532 static ieee80211_tx_result debug_noinline 532 static ieee80211_tx_result debug_noinline
533 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) 533 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
534 { 534 {
535 struct ieee80211_key *key = NULL; 535 struct ieee80211_key *key = NULL;
536 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 536 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
537 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 537 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
538 538
539 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) 539 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
540 tx->key = NULL; 540 tx->key = NULL;
541 else if (tx->sta && (key = rcu_dereference(tx->sta->ptk))) 541 else if (tx->sta && (key = rcu_dereference(tx->sta->ptk)))
542 tx->key = key; 542 tx->key = key;
543 else if (ieee80211_is_mgmt(hdr->frame_control) && 543 else if (ieee80211_is_mgmt(hdr->frame_control) &&
544 is_multicast_ether_addr(hdr->addr1) && 544 is_multicast_ether_addr(hdr->addr1) &&
545 ieee80211_is_robust_mgmt_frame(hdr) && 545 ieee80211_is_robust_mgmt_frame(hdr) &&
546 (key = rcu_dereference(tx->sdata->default_mgmt_key))) 546 (key = rcu_dereference(tx->sdata->default_mgmt_key)))
547 tx->key = key; 547 tx->key = key;
548 else if (is_multicast_ether_addr(hdr->addr1) && 548 else if (is_multicast_ether_addr(hdr->addr1) &&
549 (key = rcu_dereference(tx->sdata->default_multicast_key))) 549 (key = rcu_dereference(tx->sdata->default_multicast_key)))
550 tx->key = key; 550 tx->key = key;
551 else if (!is_multicast_ether_addr(hdr->addr1) && 551 else if (!is_multicast_ether_addr(hdr->addr1) &&
552 (key = rcu_dereference(tx->sdata->default_unicast_key))) 552 (key = rcu_dereference(tx->sdata->default_unicast_key)))
553 tx->key = key; 553 tx->key = key;
554 else if (tx->sdata->drop_unencrypted && 554 else if (tx->sdata->drop_unencrypted &&
555 (tx->skb->protocol != tx->sdata->control_port_protocol) && 555 (tx->skb->protocol != tx->sdata->control_port_protocol) &&
556 !(info->flags & IEEE80211_TX_CTL_INJECTED) && 556 !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
557 (!ieee80211_is_robust_mgmt_frame(hdr) || 557 (!ieee80211_is_robust_mgmt_frame(hdr) ||
558 (ieee80211_is_action(hdr->frame_control) && 558 (ieee80211_is_action(hdr->frame_control) &&
559 tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))) { 559 tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))) {
560 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted); 560 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
561 return TX_DROP; 561 return TX_DROP;
562 } else 562 } else
563 tx->key = NULL; 563 tx->key = NULL;
564 564
565 if (tx->key) { 565 if (tx->key) {
566 bool skip_hw = false; 566 bool skip_hw = false;
567 567
568 tx->key->tx_rx_count++; 568 tx->key->tx_rx_count++;
569 /* TODO: add threshold stuff again */ 569 /* TODO: add threshold stuff again */
570 570
571 switch (tx->key->conf.cipher) { 571 switch (tx->key->conf.cipher) {
572 case WLAN_CIPHER_SUITE_WEP40: 572 case WLAN_CIPHER_SUITE_WEP40:
573 case WLAN_CIPHER_SUITE_WEP104: 573 case WLAN_CIPHER_SUITE_WEP104:
574 if (ieee80211_is_auth(hdr->frame_control)) 574 if (ieee80211_is_auth(hdr->frame_control))
575 break; 575 break;
576 case WLAN_CIPHER_SUITE_TKIP: 576 case WLAN_CIPHER_SUITE_TKIP:
577 if (!ieee80211_is_data_present(hdr->frame_control)) 577 if (!ieee80211_is_data_present(hdr->frame_control))
578 tx->key = NULL; 578 tx->key = NULL;
579 break; 579 break;
580 case WLAN_CIPHER_SUITE_CCMP: 580 case WLAN_CIPHER_SUITE_CCMP:
581 if (!ieee80211_is_data_present(hdr->frame_control) && 581 if (!ieee80211_is_data_present(hdr->frame_control) &&
582 !ieee80211_use_mfp(hdr->frame_control, tx->sta, 582 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
583 tx->skb)) 583 tx->skb))
584 tx->key = NULL; 584 tx->key = NULL;
585 else 585 else
586 skip_hw = (tx->key->conf.flags & 586 skip_hw = (tx->key->conf.flags &
587 IEEE80211_KEY_FLAG_SW_MGMT) && 587 IEEE80211_KEY_FLAG_SW_MGMT) &&
588 ieee80211_is_mgmt(hdr->frame_control); 588 ieee80211_is_mgmt(hdr->frame_control);
589 break; 589 break;
590 case WLAN_CIPHER_SUITE_AES_CMAC: 590 case WLAN_CIPHER_SUITE_AES_CMAC:
591 if (!ieee80211_is_mgmt(hdr->frame_control)) 591 if (!ieee80211_is_mgmt(hdr->frame_control))
592 tx->key = NULL; 592 tx->key = NULL;
593 break; 593 break;
594 } 594 }
595 595
596 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED)) 596 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED))
597 return TX_DROP; 597 return TX_DROP;
598 598
599 if (!skip_hw && tx->key && 599 if (!skip_hw && tx->key &&
600 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) 600 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
601 info->control.hw_key = &tx->key->conf; 601 info->control.hw_key = &tx->key->conf;
602 } 602 }
603 603
604 return TX_CONTINUE; 604 return TX_CONTINUE;
605 } 605 }
606 606
607 static ieee80211_tx_result debug_noinline 607 static ieee80211_tx_result debug_noinline
608 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) 608 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
609 { 609 {
610 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 610 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
611 struct ieee80211_hdr *hdr = (void *)tx->skb->data; 611 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
612 struct ieee80211_supported_band *sband; 612 struct ieee80211_supported_band *sband;
613 struct ieee80211_rate *rate; 613 struct ieee80211_rate *rate;
614 int i; 614 int i;
615 u32 len; 615 u32 len;
616 bool inval = false, rts = false, short_preamble = false; 616 bool inval = false, rts = false, short_preamble = false;
617 struct ieee80211_tx_rate_control txrc; 617 struct ieee80211_tx_rate_control txrc;
618 bool assoc = false; 618 bool assoc = false;
619 619
620 memset(&txrc, 0, sizeof(txrc)); 620 memset(&txrc, 0, sizeof(txrc));
621 621
622 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 622 sband = tx->local->hw.wiphy->bands[tx->channel->band];
623 623
624 len = min_t(u32, tx->skb->len + FCS_LEN, 624 len = min_t(u32, tx->skb->len + FCS_LEN,
625 tx->local->hw.wiphy->frag_threshold); 625 tx->local->hw.wiphy->frag_threshold);
626 626
627 /* set up the tx rate control struct we give the RC algo */ 627 /* set up the tx rate control struct we give the RC algo */
628 txrc.hw = local_to_hw(tx->local); 628 txrc.hw = local_to_hw(tx->local);
629 txrc.sband = sband; 629 txrc.sband = sband;
630 txrc.bss_conf = &tx->sdata->vif.bss_conf; 630 txrc.bss_conf = &tx->sdata->vif.bss_conf;
631 txrc.skb = tx->skb; 631 txrc.skb = tx->skb;
632 txrc.reported_rate.idx = -1; 632 txrc.reported_rate.idx = -1;
633 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[tx->channel->band]; 633 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[tx->channel->band];
634 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1) 634 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
635 txrc.max_rate_idx = -1; 635 txrc.max_rate_idx = -1;
636 else 636 else
637 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1; 637 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
638 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP || 638 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
639 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC); 639 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
640 640
641 /* set up RTS protection if desired */ 641 /* set up RTS protection if desired */
642 if (len > tx->local->hw.wiphy->rts_threshold) { 642 if (len > tx->local->hw.wiphy->rts_threshold) {
643 txrc.rts = rts = true; 643 txrc.rts = rts = true;
644 } 644 }
645 645
646 /* 646 /*
647 * Use short preamble if the BSS can handle it, but not for 647 * Use short preamble if the BSS can handle it, but not for
648 * management frames unless we know the receiver can handle 648 * management frames unless we know the receiver can handle
649 * that -- the management frame might be to a station that 649 * that -- the management frame might be to a station that
650 * just wants a probe response. 650 * just wants a probe response.
651 */ 651 */
652 if (tx->sdata->vif.bss_conf.use_short_preamble && 652 if (tx->sdata->vif.bss_conf.use_short_preamble &&
653 (ieee80211_is_data(hdr->frame_control) || 653 (ieee80211_is_data(hdr->frame_control) ||
654 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE)))) 654 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
655 txrc.short_preamble = short_preamble = true; 655 txrc.short_preamble = short_preamble = true;
656 656
657 if (tx->sta) 657 if (tx->sta)
658 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); 658 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
659 659
660 /* 660 /*
661 * Lets not bother rate control if we're associated and cannot 661 * Lets not bother rate control if we're associated and cannot
662 * talk to the sta. This should not happen. 662 * talk to the sta. This should not happen.
663 */ 663 */
664 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc && 664 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
665 !rate_usable_index_exists(sband, &tx->sta->sta), 665 !rate_usable_index_exists(sband, &tx->sta->sta),
666 "%s: Dropped data frame as no usable bitrate found while " 666 "%s: Dropped data frame as no usable bitrate found while "
667 "scanning and associated. Target station: " 667 "scanning and associated. Target station: "
668 "%pM on %d GHz band\n", 668 "%pM on %d GHz band\n",
669 tx->sdata->name, hdr->addr1, 669 tx->sdata->name, hdr->addr1,
670 tx->channel->band ? 5 : 2)) 670 tx->channel->band ? 5 : 2))
671 return TX_DROP; 671 return TX_DROP;
672 672
673 /* 673 /*
674 * If we're associated with the sta at this point we know we can at 674 * If we're associated with the sta at this point we know we can at
675 * least send the frame at the lowest bit rate. 675 * least send the frame at the lowest bit rate.
676 */ 676 */
677 rate_control_get_rate(tx->sdata, tx->sta, &txrc); 677 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
678 678
679 if (unlikely(info->control.rates[0].idx < 0)) 679 if (unlikely(info->control.rates[0].idx < 0))
680 return TX_DROP; 680 return TX_DROP;
681 681
682 if (txrc.reported_rate.idx < 0) { 682 if (txrc.reported_rate.idx < 0) {
683 txrc.reported_rate = info->control.rates[0]; 683 txrc.reported_rate = info->control.rates[0];
684 if (tx->sta && ieee80211_is_data(hdr->frame_control)) 684 if (tx->sta && ieee80211_is_data(hdr->frame_control))
685 tx->sta->last_tx_rate = txrc.reported_rate; 685 tx->sta->last_tx_rate = txrc.reported_rate;
686 } else if (tx->sta) 686 } else if (tx->sta)
687 tx->sta->last_tx_rate = txrc.reported_rate; 687 tx->sta->last_tx_rate = txrc.reported_rate;
688 688
689 if (unlikely(!info->control.rates[0].count)) 689 if (unlikely(!info->control.rates[0].count))
690 info->control.rates[0].count = 1; 690 info->control.rates[0].count = 1;
691 691
692 if (WARN_ON_ONCE((info->control.rates[0].count > 1) && 692 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
693 (info->flags & IEEE80211_TX_CTL_NO_ACK))) 693 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
694 info->control.rates[0].count = 1; 694 info->control.rates[0].count = 1;
695 695
696 if (is_multicast_ether_addr(hdr->addr1)) { 696 if (is_multicast_ether_addr(hdr->addr1)) {
697 /* 697 /*
698 * XXX: verify the rate is in the basic rateset 698 * XXX: verify the rate is in the basic rateset
699 */ 699 */
700 return TX_CONTINUE; 700 return TX_CONTINUE;
701 } 701 }
702 702
703 /* 703 /*
704 * set up the RTS/CTS rate as the fastest basic rate 704 * set up the RTS/CTS rate as the fastest basic rate
705 * that is not faster than the data rate 705 * that is not faster than the data rate
706 * 706 *
707 * XXX: Should this check all retry rates? 707 * XXX: Should this check all retry rates?
708 */ 708 */
709 if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) { 709 if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
710 s8 baserate = 0; 710 s8 baserate = 0;
711 711
712 rate = &sband->bitrates[info->control.rates[0].idx]; 712 rate = &sband->bitrates[info->control.rates[0].idx];
713 713
714 for (i = 0; i < sband->n_bitrates; i++) { 714 for (i = 0; i < sband->n_bitrates; i++) {
715 /* must be a basic rate */ 715 /* must be a basic rate */
716 if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i))) 716 if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
717 continue; 717 continue;
718 /* must not be faster than the data rate */ 718 /* must not be faster than the data rate */
719 if (sband->bitrates[i].bitrate > rate->bitrate) 719 if (sband->bitrates[i].bitrate > rate->bitrate)
720 continue; 720 continue;
721 /* maximum */ 721 /* maximum */
722 if (sband->bitrates[baserate].bitrate < 722 if (sband->bitrates[baserate].bitrate <
723 sband->bitrates[i].bitrate) 723 sband->bitrates[i].bitrate)
724 baserate = i; 724 baserate = i;
725 } 725 }
726 726
727 info->control.rts_cts_rate_idx = baserate; 727 info->control.rts_cts_rate_idx = baserate;
728 } 728 }
729 729
730 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 730 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
731 /* 731 /*
732 * make sure there's no valid rate following 732 * make sure there's no valid rate following
733 * an invalid one, just in case drivers don't 733 * an invalid one, just in case drivers don't
734 * take the API seriously to stop at -1. 734 * take the API seriously to stop at -1.
735 */ 735 */
736 if (inval) { 736 if (inval) {
737 info->control.rates[i].idx = -1; 737 info->control.rates[i].idx = -1;
738 continue; 738 continue;
739 } 739 }
740 if (info->control.rates[i].idx < 0) { 740 if (info->control.rates[i].idx < 0) {
741 inval = true; 741 inval = true;
742 continue; 742 continue;
743 } 743 }
744 744
745 /* 745 /*
746 * For now assume MCS is already set up correctly, this 746 * For now assume MCS is already set up correctly, this
747 * needs to be fixed. 747 * needs to be fixed.
748 */ 748 */
749 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) { 749 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
750 WARN_ON(info->control.rates[i].idx > 76); 750 WARN_ON(info->control.rates[i].idx > 76);
751 continue; 751 continue;
752 } 752 }
753 753
754 /* set up RTS protection if desired */ 754 /* set up RTS protection if desired */
755 if (rts) 755 if (rts)
756 info->control.rates[i].flags |= 756 info->control.rates[i].flags |=
757 IEEE80211_TX_RC_USE_RTS_CTS; 757 IEEE80211_TX_RC_USE_RTS_CTS;
758 758
759 /* RC is busted */ 759 /* RC is busted */
760 if (WARN_ON_ONCE(info->control.rates[i].idx >= 760 if (WARN_ON_ONCE(info->control.rates[i].idx >=
761 sband->n_bitrates)) { 761 sband->n_bitrates)) {
762 info->control.rates[i].idx = -1; 762 info->control.rates[i].idx = -1;
763 continue; 763 continue;
764 } 764 }
765 765
766 rate = &sband->bitrates[info->control.rates[i].idx]; 766 rate = &sband->bitrates[info->control.rates[i].idx];
767 767
768 /* set up short preamble */ 768 /* set up short preamble */
769 if (short_preamble && 769 if (short_preamble &&
770 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) 770 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
771 info->control.rates[i].flags |= 771 info->control.rates[i].flags |=
772 IEEE80211_TX_RC_USE_SHORT_PREAMBLE; 772 IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
773 773
774 /* set up G protection */ 774 /* set up G protection */
775 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot && 775 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
776 rate->flags & IEEE80211_RATE_ERP_G) 776 rate->flags & IEEE80211_RATE_ERP_G)
777 info->control.rates[i].flags |= 777 info->control.rates[i].flags |=
778 IEEE80211_TX_RC_USE_CTS_PROTECT; 778 IEEE80211_TX_RC_USE_CTS_PROTECT;
779 } 779 }
780 780
781 return TX_CONTINUE; 781 return TX_CONTINUE;
782 } 782 }
783 783
784 static ieee80211_tx_result debug_noinline 784 static ieee80211_tx_result debug_noinline
785 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) 785 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
786 { 786 {
787 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 787 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
788 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 788 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
789 u16 *seq; 789 u16 *seq;
790 u8 *qc; 790 u8 *qc;
791 int tid; 791 int tid;
792 792
793 /* 793 /*
794 * Packet injection may want to control the sequence 794 * Packet injection may want to control the sequence
795 * number, if we have no matching interface then we 795 * number, if we have no matching interface then we
796 * neither assign one ourselves nor ask the driver to. 796 * neither assign one ourselves nor ask the driver to.
797 */ 797 */
798 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR)) 798 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
799 return TX_CONTINUE; 799 return TX_CONTINUE;
800 800
801 if (unlikely(ieee80211_is_ctl(hdr->frame_control))) 801 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
802 return TX_CONTINUE; 802 return TX_CONTINUE;
803 803
804 if (ieee80211_hdrlen(hdr->frame_control) < 24) 804 if (ieee80211_hdrlen(hdr->frame_control) < 24)
805 return TX_CONTINUE; 805 return TX_CONTINUE;
806 806
807 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) 807 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
808 return TX_CONTINUE; 808 return TX_CONTINUE;
809 809
810 /* 810 /*
811 * Anything but QoS data that has a sequence number field 811 * Anything but QoS data that has a sequence number field
812 * (is long enough) gets a sequence number from the global 812 * (is long enough) gets a sequence number from the global
813 * counter. 813 * counter.
814 */ 814 */
815 if (!ieee80211_is_data_qos(hdr->frame_control)) { 815 if (!ieee80211_is_data_qos(hdr->frame_control)) {
816 /* driver should assign sequence number */ 816 /* driver should assign sequence number */
817 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; 817 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
818 /* for pure STA mode without beacons, we can do it */ 818 /* for pure STA mode without beacons, we can do it */
819 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number); 819 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
820 tx->sdata->sequence_number += 0x10; 820 tx->sdata->sequence_number += 0x10;
821 return TX_CONTINUE; 821 return TX_CONTINUE;
822 } 822 }
823 823
824 /* 824 /*
825 * This should be true for injected/management frames only, for 825 * This should be true for injected/management frames only, for
826 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ 826 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
827 * above since they are not QoS-data frames. 827 * above since they are not QoS-data frames.
828 */ 828 */
829 if (!tx->sta) 829 if (!tx->sta)
830 return TX_CONTINUE; 830 return TX_CONTINUE;
831 831
832 /* include per-STA, per-TID sequence counter */ 832 /* include per-STA, per-TID sequence counter */
833 833
834 qc = ieee80211_get_qos_ctl(hdr); 834 qc = ieee80211_get_qos_ctl(hdr);
835 tid = *qc & IEEE80211_QOS_CTL_TID_MASK; 835 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
836 seq = &tx->sta->tid_seq[tid]; 836 seq = &tx->sta->tid_seq[tid];
837 837
838 hdr->seq_ctrl = cpu_to_le16(*seq); 838 hdr->seq_ctrl = cpu_to_le16(*seq);
839 839
840 /* Increase the sequence number. */ 840 /* Increase the sequence number. */
841 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ; 841 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
842 842
843 return TX_CONTINUE; 843 return TX_CONTINUE;
844 } 844 }
845 845
846 static int ieee80211_fragment(struct ieee80211_local *local, 846 static int ieee80211_fragment(struct ieee80211_local *local,
847 struct sk_buff *skb, int hdrlen, 847 struct sk_buff *skb, int hdrlen,
848 int frag_threshold) 848 int frag_threshold)
849 { 849 {
850 struct sk_buff *tail = skb, *tmp; 850 struct sk_buff *tail = skb, *tmp;
851 int per_fragm = frag_threshold - hdrlen - FCS_LEN; 851 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
852 int pos = hdrlen + per_fragm; 852 int pos = hdrlen + per_fragm;
853 int rem = skb->len - hdrlen - per_fragm; 853 int rem = skb->len - hdrlen - per_fragm;
854 854
855 if (WARN_ON(rem < 0)) 855 if (WARN_ON(rem < 0))
856 return -EINVAL; 856 return -EINVAL;
857 857
858 while (rem) { 858 while (rem) {
859 int fraglen = per_fragm; 859 int fraglen = per_fragm;
860 860
861 if (fraglen > rem) 861 if (fraglen > rem)
862 fraglen = rem; 862 fraglen = rem;
863 rem -= fraglen; 863 rem -= fraglen;
864 tmp = dev_alloc_skb(local->tx_headroom + 864 tmp = dev_alloc_skb(local->tx_headroom +
865 frag_threshold + 865 frag_threshold +
866 IEEE80211_ENCRYPT_HEADROOM + 866 IEEE80211_ENCRYPT_HEADROOM +
867 IEEE80211_ENCRYPT_TAILROOM); 867 IEEE80211_ENCRYPT_TAILROOM);
868 if (!tmp) 868 if (!tmp)
869 return -ENOMEM; 869 return -ENOMEM;
870 tail->next = tmp; 870 tail->next = tmp;
871 tail = tmp; 871 tail = tmp;
872 skb_reserve(tmp, local->tx_headroom + 872 skb_reserve(tmp, local->tx_headroom +
873 IEEE80211_ENCRYPT_HEADROOM); 873 IEEE80211_ENCRYPT_HEADROOM);
874 /* copy control information */ 874 /* copy control information */
875 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb)); 875 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
876 skb_copy_queue_mapping(tmp, skb); 876 skb_copy_queue_mapping(tmp, skb);
877 tmp->priority = skb->priority; 877 tmp->priority = skb->priority;
878 tmp->dev = skb->dev; 878 tmp->dev = skb->dev;
879 879
880 /* copy header and data */ 880 /* copy header and data */
881 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen); 881 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
882 memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen); 882 memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
883 883
884 pos += fraglen; 884 pos += fraglen;
885 } 885 }
886 886
887 skb->len = hdrlen + per_fragm; 887 skb->len = hdrlen + per_fragm;
888 return 0; 888 return 0;
889 } 889 }
890 890
891 static ieee80211_tx_result debug_noinline 891 static ieee80211_tx_result debug_noinline
892 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx) 892 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
893 { 893 {
894 struct sk_buff *skb = tx->skb; 894 struct sk_buff *skb = tx->skb;
895 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 895 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
896 struct ieee80211_hdr *hdr = (void *)skb->data; 896 struct ieee80211_hdr *hdr = (void *)skb->data;
897 int frag_threshold = tx->local->hw.wiphy->frag_threshold; 897 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
898 int hdrlen; 898 int hdrlen;
899 int fragnum; 899 int fragnum;
900 900
901 if (info->flags & IEEE80211_TX_CTL_DONTFRAG) 901 if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
902 return TX_CONTINUE; 902 return TX_CONTINUE;
903 903
904 if (tx->local->ops->set_frag_threshold) 904 if (tx->local->ops->set_frag_threshold)
905 return TX_CONTINUE; 905 return TX_CONTINUE;
906 906
907 /* 907 /*
908 * Warn when submitting a fragmented A-MPDU frame and drop it. 908 * Warn when submitting a fragmented A-MPDU frame and drop it.
909 * This scenario is handled in ieee80211_tx_prepare but extra 909 * This scenario is handled in ieee80211_tx_prepare but extra
910 * caution taken here as fragmented ampdu may cause Tx stop. 910 * caution taken here as fragmented ampdu may cause Tx stop.
911 */ 911 */
912 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU)) 912 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
913 return TX_DROP; 913 return TX_DROP;
914 914
915 hdrlen = ieee80211_hdrlen(hdr->frame_control); 915 hdrlen = ieee80211_hdrlen(hdr->frame_control);
916 916
917 /* internal error, why isn't DONTFRAG set? */ 917 /* internal error, why isn't DONTFRAG set? */
918 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold)) 918 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
919 return TX_DROP; 919 return TX_DROP;
920 920
921 /* 921 /*
922 * Now fragment the frame. This will allocate all the fragments and 922 * Now fragment the frame. This will allocate all the fragments and
923 * chain them (using skb as the first fragment) to skb->next. 923 * chain them (using skb as the first fragment) to skb->next.
924 * During transmission, we will remove the successfully transmitted 924 * During transmission, we will remove the successfully transmitted
925 * fragments from this list. When the low-level driver rejects one 925 * fragments from this list. When the low-level driver rejects one
926 * of the fragments then we will simply pretend to accept the skb 926 * of the fragments then we will simply pretend to accept the skb
927 * but store it away as pending. 927 * but store it away as pending.
928 */ 928 */
929 if (ieee80211_fragment(tx->local, skb, hdrlen, frag_threshold)) 929 if (ieee80211_fragment(tx->local, skb, hdrlen, frag_threshold))
930 return TX_DROP; 930 return TX_DROP;
931 931
932 /* update duration/seq/flags of fragments */ 932 /* update duration/seq/flags of fragments */
933 fragnum = 0; 933 fragnum = 0;
934 do { 934 do {
935 int next_len; 935 int next_len;
936 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); 936 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
937 937
938 hdr = (void *)skb->data; 938 hdr = (void *)skb->data;
939 info = IEEE80211_SKB_CB(skb); 939 info = IEEE80211_SKB_CB(skb);
940 940
941 if (skb->next) { 941 if (skb->next) {
942 hdr->frame_control |= morefrags; 942 hdr->frame_control |= morefrags;
943 next_len = skb->next->len; 943 next_len = skb->next->len;
944 /* 944 /*
945 * No multi-rate retries for fragmented frames, that 945 * No multi-rate retries for fragmented frames, that
946 * would completely throw off the NAV at other STAs. 946 * would completely throw off the NAV at other STAs.
947 */ 947 */
948 info->control.rates[1].idx = -1; 948 info->control.rates[1].idx = -1;
949 info->control.rates[2].idx = -1; 949 info->control.rates[2].idx = -1;
950 info->control.rates[3].idx = -1; 950 info->control.rates[3].idx = -1;
951 info->control.rates[4].idx = -1; 951 info->control.rates[4].idx = -1;
952 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5); 952 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
953 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; 953 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
954 } else { 954 } else {
955 hdr->frame_control &= ~morefrags; 955 hdr->frame_control &= ~morefrags;
956 next_len = 0; 956 next_len = 0;
957 } 957 }
958 hdr->duration_id = ieee80211_duration(tx, 0, next_len); 958 hdr->duration_id = ieee80211_duration(tx, 0, next_len);
959 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG); 959 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
960 fragnum++; 960 fragnum++;
961 } while ((skb = skb->next)); 961 } while ((skb = skb->next));
962 962
963 return TX_CONTINUE; 963 return TX_CONTINUE;
964 } 964 }
965 965
966 static ieee80211_tx_result debug_noinline 966 static ieee80211_tx_result debug_noinline
967 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx) 967 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
968 { 968 {
969 struct sk_buff *skb = tx->skb; 969 struct sk_buff *skb = tx->skb;
970 970
971 if (!tx->sta) 971 if (!tx->sta)
972 return TX_CONTINUE; 972 return TX_CONTINUE;
973 973
974 tx->sta->tx_packets++; 974 tx->sta->tx_packets++;
975 do { 975 do {
976 tx->sta->tx_fragments++; 976 tx->sta->tx_fragments++;
977 tx->sta->tx_bytes += skb->len; 977 tx->sta->tx_bytes += skb->len;
978 } while ((skb = skb->next)); 978 } while ((skb = skb->next));
979 979
980 return TX_CONTINUE; 980 return TX_CONTINUE;
981 } 981 }
982 982
983 static ieee80211_tx_result debug_noinline 983 static ieee80211_tx_result debug_noinline
984 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx) 984 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
985 { 985 {
986 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 986 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
987 987
988 if (!tx->key) 988 if (!tx->key)
989 return TX_CONTINUE; 989 return TX_CONTINUE;
990 990
991 switch (tx->key->conf.cipher) { 991 switch (tx->key->conf.cipher) {
992 case WLAN_CIPHER_SUITE_WEP40: 992 case WLAN_CIPHER_SUITE_WEP40:
993 case WLAN_CIPHER_SUITE_WEP104: 993 case WLAN_CIPHER_SUITE_WEP104:
994 return ieee80211_crypto_wep_encrypt(tx); 994 return ieee80211_crypto_wep_encrypt(tx);
995 case WLAN_CIPHER_SUITE_TKIP: 995 case WLAN_CIPHER_SUITE_TKIP:
996 return ieee80211_crypto_tkip_encrypt(tx); 996 return ieee80211_crypto_tkip_encrypt(tx);
997 case WLAN_CIPHER_SUITE_CCMP: 997 case WLAN_CIPHER_SUITE_CCMP:
998 return ieee80211_crypto_ccmp_encrypt(tx); 998 return ieee80211_crypto_ccmp_encrypt(tx);
999 case WLAN_CIPHER_SUITE_AES_CMAC: 999 case WLAN_CIPHER_SUITE_AES_CMAC:
1000 return ieee80211_crypto_aes_cmac_encrypt(tx); 1000 return ieee80211_crypto_aes_cmac_encrypt(tx);
1001 default: 1001 default:
1002 /* handle hw-only algorithm */ 1002 /* handle hw-only algorithm */
1003 if (info->control.hw_key) { 1003 if (info->control.hw_key) {
1004 ieee80211_tx_set_protected(tx); 1004 ieee80211_tx_set_protected(tx);
1005 return TX_CONTINUE; 1005 return TX_CONTINUE;
1006 } 1006 }
1007 break; 1007 break;
1008 1008
1009 } 1009 }
1010 1010
1011 return TX_DROP; 1011 return TX_DROP;
1012 } 1012 }
1013 1013
1014 static ieee80211_tx_result debug_noinline 1014 static ieee80211_tx_result debug_noinline
1015 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx) 1015 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
1016 { 1016 {
1017 struct sk_buff *skb = tx->skb; 1017 struct sk_buff *skb = tx->skb;
1018 struct ieee80211_hdr *hdr; 1018 struct ieee80211_hdr *hdr;
1019 int next_len; 1019 int next_len;
1020 bool group_addr; 1020 bool group_addr;
1021 1021
1022 do { 1022 do {
1023 hdr = (void *) skb->data; 1023 hdr = (void *) skb->data;
1024 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) 1024 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
1025 break; /* must not overwrite AID */ 1025 break; /* must not overwrite AID */
1026 next_len = skb->next ? skb->next->len : 0; 1026 next_len = skb->next ? skb->next->len : 0;
1027 group_addr = is_multicast_ether_addr(hdr->addr1); 1027 group_addr = is_multicast_ether_addr(hdr->addr1);
1028 1028
1029 hdr->duration_id = 1029 hdr->duration_id =
1030 ieee80211_duration(tx, group_addr, next_len); 1030 ieee80211_duration(tx, group_addr, next_len);
1031 } while ((skb = skb->next)); 1031 } while ((skb = skb->next));
1032 1032
1033 return TX_CONTINUE; 1033 return TX_CONTINUE;
1034 } 1034 }
1035 1035
1036 /* actual transmit path */ 1036 /* actual transmit path */
1037 1037
1038 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx, 1038 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
1039 struct sk_buff *skb, 1039 struct sk_buff *skb,
1040 struct ieee80211_tx_info *info, 1040 struct ieee80211_tx_info *info,
1041 struct tid_ampdu_tx *tid_tx, 1041 struct tid_ampdu_tx *tid_tx,
1042 int tid) 1042 int tid)
1043 { 1043 {
1044 bool queued = false; 1044 bool queued = false;
1045 1045
1046 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { 1046 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1047 info->flags |= IEEE80211_TX_CTL_AMPDU; 1047 info->flags |= IEEE80211_TX_CTL_AMPDU;
1048 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) { 1048 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
1049 /* 1049 /*
1050 * nothing -- this aggregation session is being started 1050 * nothing -- this aggregation session is being started
1051 * but that might still fail with the driver 1051 * but that might still fail with the driver
1052 */ 1052 */
1053 } else { 1053 } else {
1054 spin_lock(&tx->sta->lock); 1054 spin_lock(&tx->sta->lock);
1055 /* 1055 /*
1056 * Need to re-check now, because we may get here 1056 * Need to re-check now, because we may get here
1057 * 1057 *
1058 * 1) in the window during which the setup is actually 1058 * 1) in the window during which the setup is actually
1059 * already done, but not marked yet because not all 1059 * already done, but not marked yet because not all
1060 * packets are spliced over to the driver pending 1060 * packets are spliced over to the driver pending
1061 * queue yet -- if this happened we acquire the lock 1061 * queue yet -- if this happened we acquire the lock
1062 * either before or after the splice happens, but 1062 * either before or after the splice happens, but
1063 * need to recheck which of these cases happened. 1063 * need to recheck which of these cases happened.
1064 * 1064 *
1065 * 2) during session teardown, if the OPERATIONAL bit 1065 * 2) during session teardown, if the OPERATIONAL bit
1066 * was cleared due to the teardown but the pointer 1066 * was cleared due to the teardown but the pointer
1067 * hasn't been assigned NULL yet (or we loaded it 1067 * hasn't been assigned NULL yet (or we loaded it
1068 * before it was assigned) -- in this case it may 1068 * before it was assigned) -- in this case it may
1069 * now be NULL which means we should just let the 1069 * now be NULL which means we should just let the
1070 * packet pass through because splicing the frames 1070 * packet pass through because splicing the frames
1071 * back is already done. 1071 * back is already done.
1072 */ 1072 */
1073 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid); 1073 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
1074 1074
1075 if (!tid_tx) { 1075 if (!tid_tx) {
1076 /* do nothing, let packet pass through */ 1076 /* do nothing, let packet pass through */
1077 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { 1077 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1078 info->flags |= IEEE80211_TX_CTL_AMPDU; 1078 info->flags |= IEEE80211_TX_CTL_AMPDU;
1079 } else { 1079 } else {
1080 queued = true; 1080 queued = true;
1081 info->control.vif = &tx->sdata->vif; 1081 info->control.vif = &tx->sdata->vif;
1082 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 1082 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1083 __skb_queue_tail(&tid_tx->pending, skb); 1083 __skb_queue_tail(&tid_tx->pending, skb);
1084 } 1084 }
1085 spin_unlock(&tx->sta->lock); 1085 spin_unlock(&tx->sta->lock);
1086 } 1086 }
1087 1087
1088 return queued; 1088 return queued;
1089 } 1089 }
1090 1090
1091 /* 1091 /*
1092 * initialises @tx 1092 * initialises @tx
1093 */ 1093 */
1094 static ieee80211_tx_result 1094 static ieee80211_tx_result
1095 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata, 1095 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1096 struct ieee80211_tx_data *tx, 1096 struct ieee80211_tx_data *tx,
1097 struct sk_buff *skb) 1097 struct sk_buff *skb)
1098 { 1098 {
1099 struct ieee80211_local *local = sdata->local; 1099 struct ieee80211_local *local = sdata->local;
1100 struct ieee80211_hdr *hdr; 1100 struct ieee80211_hdr *hdr;
1101 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1101 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1102 int tid; 1102 int tid;
1103 u8 *qc; 1103 u8 *qc;
1104 1104
1105 memset(tx, 0, sizeof(*tx)); 1105 memset(tx, 0, sizeof(*tx));
1106 tx->skb = skb; 1106 tx->skb = skb;
1107 tx->local = local; 1107 tx->local = local;
1108 tx->sdata = sdata; 1108 tx->sdata = sdata;
1109 tx->channel = local->hw.conf.channel; 1109 tx->channel = local->hw.conf.channel;
1110 1110
1111 /* 1111 /*
1112 * If this flag is set to true anywhere, and we get here, 1112 * If this flag is set to true anywhere, and we get here,
1113 * we are doing the needed processing, so remove the flag 1113 * we are doing the needed processing, so remove the flag
1114 * now. 1114 * now.
1115 */ 1115 */
1116 info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING; 1116 info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1117 1117
1118 hdr = (struct ieee80211_hdr *) skb->data; 1118 hdr = (struct ieee80211_hdr *) skb->data;
1119 1119
1120 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { 1120 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1121 tx->sta = rcu_dereference(sdata->u.vlan.sta); 1121 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1122 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr) 1122 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
1123 return TX_DROP; 1123 return TX_DROP;
1124 } else if (info->flags & IEEE80211_TX_CTL_INJECTED) { 1124 } else if (info->flags & IEEE80211_TX_CTL_INJECTED) {
1125 tx->sta = sta_info_get_bss(sdata, hdr->addr1); 1125 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1126 } 1126 }
1127 if (!tx->sta) 1127 if (!tx->sta)
1128 tx->sta = sta_info_get(sdata, hdr->addr1); 1128 tx->sta = sta_info_get(sdata, hdr->addr1);
1129 1129
1130 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) && 1130 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1131 !ieee80211_is_qos_nullfunc(hdr->frame_control) && 1131 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
1132 (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) && 1132 (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) &&
1133 !(local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)) { 1133 !(local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)) {
1134 struct tid_ampdu_tx *tid_tx; 1134 struct tid_ampdu_tx *tid_tx;
1135 1135
1136 qc = ieee80211_get_qos_ctl(hdr); 1136 qc = ieee80211_get_qos_ctl(hdr);
1137 tid = *qc & IEEE80211_QOS_CTL_TID_MASK; 1137 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
1138 1138
1139 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]); 1139 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1140 if (tid_tx) { 1140 if (tid_tx) {
1141 bool queued; 1141 bool queued;
1142 1142
1143 queued = ieee80211_tx_prep_agg(tx, skb, info, 1143 queued = ieee80211_tx_prep_agg(tx, skb, info,
1144 tid_tx, tid); 1144 tid_tx, tid);
1145 1145
1146 if (unlikely(queued)) 1146 if (unlikely(queued))
1147 return TX_QUEUED; 1147 return TX_QUEUED;
1148 } 1148 }
1149 } 1149 }
1150 1150
1151 if (is_multicast_ether_addr(hdr->addr1)) { 1151 if (is_multicast_ether_addr(hdr->addr1)) {
1152 tx->flags &= ~IEEE80211_TX_UNICAST; 1152 tx->flags &= ~IEEE80211_TX_UNICAST;
1153 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1153 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1154 } else { 1154 } else {
1155 tx->flags |= IEEE80211_TX_UNICAST; 1155 tx->flags |= IEEE80211_TX_UNICAST;
1156 if (unlikely(local->wifi_wme_noack_test)) 1156 if (unlikely(local->wifi_wme_noack_test))
1157 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1157 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1158 /* 1158 /*
1159 * Flags are initialized to 0. Hence, no need to 1159 * Flags are initialized to 0. Hence, no need to
1160 * explicitly unset IEEE80211_TX_CTL_NO_ACK since 1160 * explicitly unset IEEE80211_TX_CTL_NO_ACK since
1161 * it might already be set for injected frames. 1161 * it might already be set for injected frames.
1162 */ 1162 */
1163 } 1163 }
1164 1164
1165 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) { 1165 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1166 if (!(tx->flags & IEEE80211_TX_UNICAST) || 1166 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1167 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold || 1167 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1168 info->flags & IEEE80211_TX_CTL_AMPDU) 1168 info->flags & IEEE80211_TX_CTL_AMPDU)
1169 info->flags |= IEEE80211_TX_CTL_DONTFRAG; 1169 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
1170 } 1170 }
1171 1171
1172 if (!tx->sta) 1172 if (!tx->sta)
1173 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; 1173 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1174 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) 1174 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT))
1175 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; 1175 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1176 1176
1177 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT; 1177 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1178 1178
1179 return TX_CONTINUE; 1179 return TX_CONTINUE;
1180 } 1180 }
1181 1181
1182 /* 1182 /*
1183 * Returns false if the frame couldn't be transmitted but was queued instead. 1183 * Returns false if the frame couldn't be transmitted but was queued instead.
1184 */ 1184 */
1185 static bool __ieee80211_tx(struct ieee80211_local *local, struct sk_buff **skbp, 1185 static bool __ieee80211_tx(struct ieee80211_local *local, struct sk_buff **skbp,
1186 struct sta_info *sta, bool txpending) 1186 struct sta_info *sta, bool txpending)
1187 { 1187 {
1188 struct sk_buff *skb = *skbp, *next; 1188 struct sk_buff *skb = *skbp, *next;
1189 struct ieee80211_tx_info *info; 1189 struct ieee80211_tx_info *info;
1190 struct ieee80211_sub_if_data *sdata; 1190 struct ieee80211_sub_if_data *sdata;
1191 unsigned long flags; 1191 unsigned long flags;
1192 int len; 1192 int len;
1193 bool fragm = false; 1193 bool fragm = false;
1194 1194
1195 while (skb) { 1195 while (skb) {
1196 int q = skb_get_queue_mapping(skb); 1196 int q = skb_get_queue_mapping(skb);
1197 __le16 fc; 1197 __le16 fc;
1198 1198
1199 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 1199 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1200 if (local->queue_stop_reasons[q] || 1200 if (local->queue_stop_reasons[q] ||
1201 (!txpending && !skb_queue_empty(&local->pending[q]))) { 1201 (!txpending && !skb_queue_empty(&local->pending[q]))) {
1202 /* 1202 /*
1203 * Since queue is stopped, queue up frames for later 1203 * Since queue is stopped, queue up frames for later
1204 * transmission from the tx-pending tasklet when the 1204 * transmission from the tx-pending tasklet when the
1205 * queue is woken again. 1205 * queue is woken again.
1206 */ 1206 */
1207 1207
1208 do { 1208 do {
1209 next = skb->next; 1209 next = skb->next;
1210 skb->next = NULL; 1210 skb->next = NULL;
1211 /* 1211 /*
1212 * NB: If txpending is true, next must already 1212 * NB: If txpending is true, next must already
1213 * be NULL since we must've gone through this 1213 * be NULL since we must've gone through this
1214 * loop before already; therefore we can just 1214 * loop before already; therefore we can just
1215 * queue the frame to the head without worrying 1215 * queue the frame to the head without worrying
1216 * about reordering of fragments. 1216 * about reordering of fragments.
1217 */ 1217 */
1218 if (unlikely(txpending)) 1218 if (unlikely(txpending))
1219 __skb_queue_head(&local->pending[q], 1219 __skb_queue_head(&local->pending[q],
1220 skb); 1220 skb);
1221 else 1221 else
1222 __skb_queue_tail(&local->pending[q], 1222 __skb_queue_tail(&local->pending[q],
1223 skb); 1223 skb);
1224 } while ((skb = next)); 1224 } while ((skb = next));
1225 1225
1226 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 1226 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1227 flags); 1227 flags);
1228 return false; 1228 return false;
1229 } 1229 }
1230 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 1230 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1231 1231
1232 info = IEEE80211_SKB_CB(skb); 1232 info = IEEE80211_SKB_CB(skb);
1233 1233
1234 if (fragm) 1234 if (fragm)
1235 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT | 1235 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
1236 IEEE80211_TX_CTL_FIRST_FRAGMENT); 1236 IEEE80211_TX_CTL_FIRST_FRAGMENT);
1237 1237
1238 next = skb->next; 1238 next = skb->next;
1239 len = skb->len; 1239 len = skb->len;
1240 1240
1241 if (next) 1241 if (next)
1242 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES; 1242 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
1243 1243
1244 sdata = vif_to_sdata(info->control.vif); 1244 sdata = vif_to_sdata(info->control.vif);
1245 1245
1246 switch (sdata->vif.type) { 1246 switch (sdata->vif.type) {
1247 case NL80211_IFTYPE_MONITOR: 1247 case NL80211_IFTYPE_MONITOR:
1248 info->control.vif = NULL; 1248 info->control.vif = NULL;
1249 break; 1249 break;
1250 case NL80211_IFTYPE_AP_VLAN: 1250 case NL80211_IFTYPE_AP_VLAN:
1251 info->control.vif = &container_of(sdata->bss, 1251 info->control.vif = &container_of(sdata->bss,
1252 struct ieee80211_sub_if_data, u.ap)->vif; 1252 struct ieee80211_sub_if_data, u.ap)->vif;
1253 break; 1253 break;
1254 default: 1254 default:
1255 /* keep */ 1255 /* keep */
1256 break; 1256 break;
1257 } 1257 }
1258 1258
1259 if (sta && sta->uploaded) 1259 if (sta && sta->uploaded)
1260 info->control.sta = &sta->sta; 1260 info->control.sta = &sta->sta;
1261 else 1261 else
1262 info->control.sta = NULL; 1262 info->control.sta = NULL;
1263 1263
1264 fc = ((struct ieee80211_hdr *)skb->data)->frame_control; 1264 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
1265 drv_tx(local, skb); 1265 drv_tx(local, skb);
1266 1266
1267 ieee80211_tpt_led_trig_tx(local, fc, len); 1267 ieee80211_tpt_led_trig_tx(local, fc, len);
1268 *skbp = skb = next; 1268 *skbp = skb = next;
1269 ieee80211_led_tx(local, 1); 1269 ieee80211_led_tx(local, 1);
1270 fragm = true; 1270 fragm = true;
1271 } 1271 }
1272 1272
1273 return true; 1273 return true;
1274 } 1274 }
1275 1275
1276 /* 1276 /*
1277 * Invoke TX handlers, return 0 on success and non-zero if the 1277 * Invoke TX handlers, return 0 on success and non-zero if the
1278 * frame was dropped or queued. 1278 * frame was dropped or queued.
1279 */ 1279 */
1280 static int invoke_tx_handlers(struct ieee80211_tx_data *tx) 1280 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1281 { 1281 {
1282 struct sk_buff *skb = tx->skb; 1282 struct sk_buff *skb = tx->skb;
1283 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1283 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1284 ieee80211_tx_result res = TX_DROP; 1284 ieee80211_tx_result res = TX_DROP;
1285 1285
1286 #define CALL_TXH(txh) \ 1286 #define CALL_TXH(txh) \
1287 do { \ 1287 do { \
1288 res = txh(tx); \ 1288 res = txh(tx); \
1289 if (res != TX_CONTINUE) \ 1289 if (res != TX_CONTINUE) \
1290 goto txh_done; \ 1290 goto txh_done; \
1291 } while (0) 1291 } while (0)
1292 1292
1293 CALL_TXH(ieee80211_tx_h_dynamic_ps); 1293 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1294 CALL_TXH(ieee80211_tx_h_check_assoc); 1294 CALL_TXH(ieee80211_tx_h_check_assoc);
1295 CALL_TXH(ieee80211_tx_h_ps_buf); 1295 CALL_TXH(ieee80211_tx_h_ps_buf);
1296 CALL_TXH(ieee80211_tx_h_check_control_port_protocol); 1296 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
1297 CALL_TXH(ieee80211_tx_h_select_key); 1297 CALL_TXH(ieee80211_tx_h_select_key);
1298 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)) 1298 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
1299 CALL_TXH(ieee80211_tx_h_rate_ctrl); 1299 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1300 1300
1301 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) 1301 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION))
1302 goto txh_done; 1302 goto txh_done;
1303 1303
1304 CALL_TXH(ieee80211_tx_h_michael_mic_add); 1304 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1305 CALL_TXH(ieee80211_tx_h_sequence); 1305 CALL_TXH(ieee80211_tx_h_sequence);
1306 CALL_TXH(ieee80211_tx_h_fragment); 1306 CALL_TXH(ieee80211_tx_h_fragment);
1307 /* handlers after fragment must be aware of tx info fragmentation! */ 1307 /* handlers after fragment must be aware of tx info fragmentation! */
1308 CALL_TXH(ieee80211_tx_h_stats); 1308 CALL_TXH(ieee80211_tx_h_stats);
1309 CALL_TXH(ieee80211_tx_h_encrypt); 1309 CALL_TXH(ieee80211_tx_h_encrypt);
1310 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)) 1310 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
1311 CALL_TXH(ieee80211_tx_h_calculate_duration); 1311 CALL_TXH(ieee80211_tx_h_calculate_duration);
1312 #undef CALL_TXH 1312 #undef CALL_TXH
1313 1313
1314 txh_done: 1314 txh_done:
1315 if (unlikely(res == TX_DROP)) { 1315 if (unlikely(res == TX_DROP)) {
1316 I802_DEBUG_INC(tx->local->tx_handlers_drop); 1316 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1317 while (skb) { 1317 while (skb) {
1318 struct sk_buff *next; 1318 struct sk_buff *next;
1319 1319
1320 next = skb->next; 1320 next = skb->next;
1321 dev_kfree_skb(skb); 1321 dev_kfree_skb(skb);
1322 skb = next; 1322 skb = next;
1323 } 1323 }
1324 return -1; 1324 return -1;
1325 } else if (unlikely(res == TX_QUEUED)) { 1325 } else if (unlikely(res == TX_QUEUED)) {
1326 I802_DEBUG_INC(tx->local->tx_handlers_queued); 1326 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1327 return -1; 1327 return -1;
1328 } 1328 }
1329 1329
1330 return 0; 1330 return 0;
1331 } 1331 }
1332 1332
1333 /* 1333 /*
1334 * Returns false if the frame couldn't be transmitted but was queued instead. 1334 * Returns false if the frame couldn't be transmitted but was queued instead.
1335 */ 1335 */
1336 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, 1336 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1337 struct sk_buff *skb, bool txpending) 1337 struct sk_buff *skb, bool txpending)
1338 { 1338 {
1339 struct ieee80211_local *local = sdata->local; 1339 struct ieee80211_local *local = sdata->local;
1340 struct ieee80211_tx_data tx; 1340 struct ieee80211_tx_data tx;
1341 ieee80211_tx_result res_prepare; 1341 ieee80211_tx_result res_prepare;
1342 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1342 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1343 bool result = true; 1343 bool result = true;
1344 1344
1345 if (unlikely(skb->len < 10)) { 1345 if (unlikely(skb->len < 10)) {
1346 dev_kfree_skb(skb); 1346 dev_kfree_skb(skb);
1347 return true; 1347 return true;
1348 } 1348 }
1349 1349
1350 rcu_read_lock(); 1350 rcu_read_lock();
1351 1351
1352 /* initialises tx */ 1352 /* initialises tx */
1353 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb); 1353 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
1354 1354
1355 if (unlikely(res_prepare == TX_DROP)) { 1355 if (unlikely(res_prepare == TX_DROP)) {
1356 dev_kfree_skb(skb); 1356 dev_kfree_skb(skb);
1357 goto out; 1357 goto out;
1358 } else if (unlikely(res_prepare == TX_QUEUED)) { 1358 } else if (unlikely(res_prepare == TX_QUEUED)) {
1359 goto out; 1359 goto out;
1360 } 1360 }
1361 1361
1362 tx.channel = local->hw.conf.channel; 1362 tx.channel = local->hw.conf.channel;
1363 info->band = tx.channel->band; 1363 info->band = tx.channel->band;
1364 1364
1365 if (!invoke_tx_handlers(&tx)) 1365 if (!invoke_tx_handlers(&tx))
1366 result = __ieee80211_tx(local, &tx.skb, tx.sta, txpending); 1366 result = __ieee80211_tx(local, &tx.skb, tx.sta, txpending);
1367 out: 1367 out:
1368 rcu_read_unlock(); 1368 rcu_read_unlock();
1369 return result; 1369 return result;
1370 } 1370 }
1371 1371
1372 /* device xmit handlers */ 1372 /* device xmit handlers */
1373 1373
1374 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata, 1374 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
1375 struct sk_buff *skb, 1375 struct sk_buff *skb,
1376 int head_need, bool may_encrypt) 1376 int head_need, bool may_encrypt)
1377 { 1377 {
1378 struct ieee80211_local *local = sdata->local; 1378 struct ieee80211_local *local = sdata->local;
1379 int tail_need = 0; 1379 int tail_need = 0;
1380 1380
1381 if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) { 1381 if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) {
1382 tail_need = IEEE80211_ENCRYPT_TAILROOM; 1382 tail_need = IEEE80211_ENCRYPT_TAILROOM;
1383 tail_need -= skb_tailroom(skb); 1383 tail_need -= skb_tailroom(skb);
1384 tail_need = max_t(int, tail_need, 0); 1384 tail_need = max_t(int, tail_need, 0);
1385 } 1385 }
1386 1386
1387 if (skb_cloned(skb)) 1387 if (skb_cloned(skb))
1388 I802_DEBUG_INC(local->tx_expand_skb_head_cloned); 1388 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
1389 else if (head_need || tail_need) 1389 else if (head_need || tail_need)
1390 I802_DEBUG_INC(local->tx_expand_skb_head); 1390 I802_DEBUG_INC(local->tx_expand_skb_head);
1391 else 1391 else
1392 return 0; 1392 return 0;
1393 1393
1394 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) { 1394 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
1395 wiphy_debug(local->hw.wiphy, 1395 wiphy_debug(local->hw.wiphy,
1396 "failed to reallocate TX buffer\n"); 1396 "failed to reallocate TX buffer\n");
1397 return -ENOMEM; 1397 return -ENOMEM;
1398 } 1398 }
1399 1399
1400 return 0; 1400 return 0;
1401 } 1401 }
1402 1402
1403 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) 1403 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
1404 { 1404 {
1405 struct ieee80211_local *local = sdata->local; 1405 struct ieee80211_local *local = sdata->local;
1406 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1406 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1407 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1407 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1408 int headroom; 1408 int headroom;
1409 bool may_encrypt; 1409 bool may_encrypt;
1410 1410
1411 rcu_read_lock(); 1411 rcu_read_lock();
1412 1412
1413 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT); 1413 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
1414 1414
1415 headroom = local->tx_headroom; 1415 headroom = local->tx_headroom;
1416 if (may_encrypt) 1416 if (may_encrypt)
1417 headroom += IEEE80211_ENCRYPT_HEADROOM; 1417 headroom += IEEE80211_ENCRYPT_HEADROOM;
1418 headroom -= skb_headroom(skb); 1418 headroom -= skb_headroom(skb);
1419 headroom = max_t(int, 0, headroom); 1419 headroom = max_t(int, 0, headroom);
1420 1420
1421 if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) { 1421 if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
1422 dev_kfree_skb(skb); 1422 dev_kfree_skb(skb);
1423 rcu_read_unlock(); 1423 rcu_read_unlock();
1424 return; 1424 return;
1425 } 1425 }
1426 1426
1427 hdr = (struct ieee80211_hdr *) skb->data; 1427 hdr = (struct ieee80211_hdr *) skb->data;
1428 info->control.vif = &sdata->vif; 1428 info->control.vif = &sdata->vif;
1429 1429
1430 if (ieee80211_vif_is_mesh(&sdata->vif) && 1430 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1431 ieee80211_is_data(hdr->frame_control) && 1431 ieee80211_is_data(hdr->frame_control) &&
1432 !is_multicast_ether_addr(hdr->addr1)) 1432 !is_multicast_ether_addr(hdr->addr1))
1433 if (mesh_nexthop_lookup(skb, sdata)) { 1433 if (mesh_nexthop_lookup(skb, sdata)) {
1434 /* skb queued: don't free */ 1434 /* skb queued: don't free */
1435 rcu_read_unlock(); 1435 rcu_read_unlock();
1436 return; 1436 return;
1437 } 1437 }
1438 1438
1439 ieee80211_set_qos_hdr(sdata, skb); 1439 ieee80211_set_qos_hdr(sdata, skb);
1440 ieee80211_tx(sdata, skb, false); 1440 ieee80211_tx(sdata, skb, false);
1441 rcu_read_unlock(); 1441 rcu_read_unlock();
1442 } 1442 }
1443 1443
1444 static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb) 1444 static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
1445 { 1445 {
1446 struct ieee80211_radiotap_iterator iterator; 1446 struct ieee80211_radiotap_iterator iterator;
1447 struct ieee80211_radiotap_header *rthdr = 1447 struct ieee80211_radiotap_header *rthdr =
1448 (struct ieee80211_radiotap_header *) skb->data; 1448 (struct ieee80211_radiotap_header *) skb->data;
1449 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1449 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1450 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, 1450 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
1451 NULL); 1451 NULL);
1452 u16 txflags; 1452 u16 txflags;
1453 1453
1454 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | 1454 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1455 IEEE80211_TX_CTL_DONTFRAG; 1455 IEEE80211_TX_CTL_DONTFRAG;
1456 1456
1457 /* 1457 /*
1458 * for every radiotap entry that is present 1458 * for every radiotap entry that is present
1459 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more 1459 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
1460 * entries present, or -EINVAL on error) 1460 * entries present, or -EINVAL on error)
1461 */ 1461 */
1462 1462
1463 while (!ret) { 1463 while (!ret) {
1464 ret = ieee80211_radiotap_iterator_next(&iterator); 1464 ret = ieee80211_radiotap_iterator_next(&iterator);
1465 1465
1466 if (ret) 1466 if (ret)
1467 continue; 1467 continue;
1468 1468
1469 /* see if this argument is something we can use */ 1469 /* see if this argument is something we can use */
1470 switch (iterator.this_arg_index) { 1470 switch (iterator.this_arg_index) {
1471 /* 1471 /*
1472 * You must take care when dereferencing iterator.this_arg 1472 * You must take care when dereferencing iterator.this_arg
1473 * for multibyte types... the pointer is not aligned. Use 1473 * for multibyte types... the pointer is not aligned. Use
1474 * get_unaligned((type *)iterator.this_arg) to dereference 1474 * get_unaligned((type *)iterator.this_arg) to dereference
1475 * iterator.this_arg for type "type" safely on all arches. 1475 * iterator.this_arg for type "type" safely on all arches.
1476 */ 1476 */
1477 case IEEE80211_RADIOTAP_FLAGS: 1477 case IEEE80211_RADIOTAP_FLAGS:
1478 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { 1478 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
1479 /* 1479 /*
1480 * this indicates that the skb we have been 1480 * this indicates that the skb we have been
1481 * handed has the 32-bit FCS CRC at the end... 1481 * handed has the 32-bit FCS CRC at the end...
1482 * we should react to that by snipping it off 1482 * we should react to that by snipping it off
1483 * because it will be recomputed and added 1483 * because it will be recomputed and added
1484 * on transmission 1484 * on transmission
1485 */ 1485 */
1486 if (skb->len < (iterator._max_length + FCS_LEN)) 1486 if (skb->len < (iterator._max_length + FCS_LEN))
1487 return false; 1487 return false;
1488 1488
1489 skb_trim(skb, skb->len - FCS_LEN); 1489 skb_trim(skb, skb->len - FCS_LEN);
1490 } 1490 }
1491 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP) 1491 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
1492 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT; 1492 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
1493 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) 1493 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
1494 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG; 1494 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
1495 break; 1495 break;
1496 1496
1497 case IEEE80211_RADIOTAP_TX_FLAGS: 1497 case IEEE80211_RADIOTAP_TX_FLAGS:
1498 txflags = get_unaligned_le16(iterator.this_arg); 1498 txflags = get_unaligned_le16(iterator.this_arg);
1499 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK) 1499 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
1500 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1500 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1501 break; 1501 break;
1502 1502
1503 /* 1503 /*
1504 * Please update the file 1504 * Please update the file
1505 * Documentation/networking/mac80211-injection.txt 1505 * Documentation/networking/mac80211-injection.txt
1506 * when parsing new fields here. 1506 * when parsing new fields here.
1507 */ 1507 */
1508 1508
1509 default: 1509 default:
1510 break; 1510 break;
1511 } 1511 }
1512 } 1512 }
1513 1513
1514 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */ 1514 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
1515 return false; 1515 return false;
1516 1516
1517 /* 1517 /*
1518 * remove the radiotap header 1518 * remove the radiotap header
1519 * iterator->_max_length was sanity-checked against 1519 * iterator->_max_length was sanity-checked against
1520 * skb->len by iterator init 1520 * skb->len by iterator init
1521 */ 1521 */
1522 skb_pull(skb, iterator._max_length); 1522 skb_pull(skb, iterator._max_length);
1523 1523
1524 return true; 1524 return true;
1525 } 1525 }
1526 1526
1527 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, 1527 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1528 struct net_device *dev) 1528 struct net_device *dev)
1529 { 1529 {
1530 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1530 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1531 struct ieee80211_channel *chan = local->hw.conf.channel; 1531 struct ieee80211_channel *chan = local->hw.conf.channel;
1532 struct ieee80211_radiotap_header *prthdr = 1532 struct ieee80211_radiotap_header *prthdr =
1533 (struct ieee80211_radiotap_header *)skb->data; 1533 (struct ieee80211_radiotap_header *)skb->data;
1534 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1534 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1535 struct ieee80211_hdr *hdr; 1535 struct ieee80211_hdr *hdr;
1536 struct ieee80211_sub_if_data *tmp_sdata, *sdata; 1536 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
1537 u16 len_rthdr; 1537 u16 len_rthdr;
1538 int hdrlen; 1538 int hdrlen;
1539 1539
1540 /* 1540 /*
1541 * Frame injection is not allowed if beaconing is not allowed 1541 * Frame injection is not allowed if beaconing is not allowed
1542 * or if we need radar detection. Beaconing is usually not allowed when 1542 * or if we need radar detection. Beaconing is usually not allowed when
1543 * the mode or operation (Adhoc, AP, Mesh) does not support DFS. 1543 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
1544 * Passive scan is also used in world regulatory domains where 1544 * Passive scan is also used in world regulatory domains where
1545 * your country is not known and as such it should be treated as 1545 * your country is not known and as such it should be treated as
1546 * NO TX unless the channel is explicitly allowed in which case 1546 * NO TX unless the channel is explicitly allowed in which case
1547 * your current regulatory domain would not have the passive scan 1547 * your current regulatory domain would not have the passive scan
1548 * flag. 1548 * flag.
1549 * 1549 *
1550 * Since AP mode uses monitor interfaces to inject/TX management 1550 * Since AP mode uses monitor interfaces to inject/TX management
1551 * frames we can make AP mode the exception to this rule once it 1551 * frames we can make AP mode the exception to this rule once it
1552 * supports radar detection as its implementation can deal with 1552 * supports radar detection as its implementation can deal with
1553 * radar detection by itself. We can do that later by adding a 1553 * radar detection by itself. We can do that later by adding a
1554 * monitor flag interfaces used for AP support. 1554 * monitor flag interfaces used for AP support.
1555 */ 1555 */
1556 if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR | 1556 if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
1557 IEEE80211_CHAN_PASSIVE_SCAN))) 1557 IEEE80211_CHAN_PASSIVE_SCAN)))
1558 goto fail; 1558 goto fail;
1559 1559
1560 /* check for not even having the fixed radiotap header part */ 1560 /* check for not even having the fixed radiotap header part */
1561 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) 1561 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
1562 goto fail; /* too short to be possibly valid */ 1562 goto fail; /* too short to be possibly valid */
1563 1563
1564 /* is it a header version we can trust to find length from? */ 1564 /* is it a header version we can trust to find length from? */
1565 if (unlikely(prthdr->it_version)) 1565 if (unlikely(prthdr->it_version))
1566 goto fail; /* only version 0 is supported */ 1566 goto fail; /* only version 0 is supported */
1567 1567
1568 /* then there must be a radiotap header with a length we can use */ 1568 /* then there must be a radiotap header with a length we can use */
1569 len_rthdr = ieee80211_get_radiotap_len(skb->data); 1569 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1570 1570
1571 /* does the skb contain enough to deliver on the alleged length? */ 1571 /* does the skb contain enough to deliver on the alleged length? */
1572 if (unlikely(skb->len < len_rthdr)) 1572 if (unlikely(skb->len < len_rthdr))
1573 goto fail; /* skb too short for claimed rt header extent */ 1573 goto fail; /* skb too short for claimed rt header extent */
1574 1574
1575 /* 1575 /*
1576 * fix up the pointers accounting for the radiotap 1576 * fix up the pointers accounting for the radiotap
1577 * header still being in there. We are being given 1577 * header still being in there. We are being given
1578 * a precooked IEEE80211 header so no need for 1578 * a precooked IEEE80211 header so no need for
1579 * normal processing 1579 * normal processing
1580 */ 1580 */
1581 skb_set_mac_header(skb, len_rthdr); 1581 skb_set_mac_header(skb, len_rthdr);
1582 /* 1582 /*
1583 * these are just fixed to the end of the rt area since we 1583 * these are just fixed to the end of the rt area since we
1584 * don't have any better information and at this point, nobody cares 1584 * don't have any better information and at this point, nobody cares
1585 */ 1585 */
1586 skb_set_network_header(skb, len_rthdr); 1586 skb_set_network_header(skb, len_rthdr);
1587 skb_set_transport_header(skb, len_rthdr); 1587 skb_set_transport_header(skb, len_rthdr);
1588 1588
1589 if (skb->len < len_rthdr + 2) 1589 if (skb->len < len_rthdr + 2)
1590 goto fail; 1590 goto fail;
1591 1591
1592 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); 1592 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
1593 hdrlen = ieee80211_hdrlen(hdr->frame_control); 1593 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1594 1594
1595 if (skb->len < len_rthdr + hdrlen) 1595 if (skb->len < len_rthdr + hdrlen)
1596 goto fail; 1596 goto fail;
1597 1597
1598 /* 1598 /*
1599 * Initialize skb->protocol if the injected frame is a data frame 1599 * Initialize skb->protocol if the injected frame is a data frame
1600 * carrying a rfc1042 header 1600 * carrying a rfc1042 header
1601 */ 1601 */
1602 if (ieee80211_is_data(hdr->frame_control) && 1602 if (ieee80211_is_data(hdr->frame_control) &&
1603 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) { 1603 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
1604 u8 *payload = (u8 *)hdr + hdrlen; 1604 u8 *payload = (u8 *)hdr + hdrlen;
1605 1605
1606 if (compare_ether_addr(payload, rfc1042_header) == 0) 1606 if (compare_ether_addr(payload, rfc1042_header) == 0)
1607 skb->protocol = cpu_to_be16((payload[6] << 8) | 1607 skb->protocol = cpu_to_be16((payload[6] << 8) |
1608 payload[7]); 1608 payload[7]);
1609 } 1609 }
1610 1610
1611 memset(info, 0, sizeof(*info)); 1611 memset(info, 0, sizeof(*info));
1612 1612
1613 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS | 1613 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
1614 IEEE80211_TX_CTL_INJECTED; 1614 IEEE80211_TX_CTL_INJECTED;
1615 1615
1616 /* process and remove the injection radiotap header */ 1616 /* process and remove the injection radiotap header */
1617 if (!ieee80211_parse_tx_radiotap(skb)) 1617 if (!ieee80211_parse_tx_radiotap(skb))
1618 goto fail; 1618 goto fail;
1619 1619
1620 rcu_read_lock(); 1620 rcu_read_lock();
1621 1621
1622 /* 1622 /*
1623 * We process outgoing injected frames that have a local address 1623 * We process outgoing injected frames that have a local address
1624 * we handle as though they are non-injected frames. 1624 * we handle as though they are non-injected frames.
1625 * This code here isn't entirely correct, the local MAC address 1625 * This code here isn't entirely correct, the local MAC address
1626 * isn't always enough to find the interface to use; for proper 1626 * isn't always enough to find the interface to use; for proper
1627 * VLAN/WDS support we will need a different mechanism (which 1627 * VLAN/WDS support we will need a different mechanism (which
1628 * likely isn't going to be monitor interfaces). 1628 * likely isn't going to be monitor interfaces).
1629 */ 1629 */
1630 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1630 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1631 1631
1632 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) { 1632 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
1633 if (!ieee80211_sdata_running(tmp_sdata)) 1633 if (!ieee80211_sdata_running(tmp_sdata))
1634 continue; 1634 continue;
1635 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR || 1635 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
1636 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN || 1636 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1637 tmp_sdata->vif.type == NL80211_IFTYPE_WDS) 1637 tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
1638 continue; 1638 continue;
1639 if (compare_ether_addr(tmp_sdata->vif.addr, hdr->addr2) == 0) { 1639 if (compare_ether_addr(tmp_sdata->vif.addr, hdr->addr2) == 0) {
1640 sdata = tmp_sdata; 1640 sdata = tmp_sdata;
1641 break; 1641 break;
1642 } 1642 }
1643 } 1643 }
1644 1644
1645 ieee80211_xmit(sdata, skb); 1645 ieee80211_xmit(sdata, skb);
1646 rcu_read_unlock(); 1646 rcu_read_unlock();
1647 1647
1648 return NETDEV_TX_OK; 1648 return NETDEV_TX_OK;
1649 1649
1650 fail: 1650 fail:
1651 dev_kfree_skb(skb); 1651 dev_kfree_skb(skb);
1652 return NETDEV_TX_OK; /* meaning, we dealt with the skb */ 1652 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
1653 } 1653 }
1654 1654
1655 /** 1655 /**
1656 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type 1656 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1657 * subinterfaces (wlan#, WDS, and VLAN interfaces) 1657 * subinterfaces (wlan#, WDS, and VLAN interfaces)
1658 * @skb: packet to be sent 1658 * @skb: packet to be sent
1659 * @dev: incoming interface 1659 * @dev: incoming interface
1660 * 1660 *
1661 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will 1661 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1662 * not be freed, and caller is responsible for either retrying later or freeing 1662 * not be freed, and caller is responsible for either retrying later or freeing
1663 * skb). 1663 * skb).
1664 * 1664 *
1665 * This function takes in an Ethernet header and encapsulates it with suitable 1665 * This function takes in an Ethernet header and encapsulates it with suitable
1666 * IEEE 802.11 header based on which interface the packet is coming in. The 1666 * IEEE 802.11 header based on which interface the packet is coming in. The
1667 * encapsulated packet will then be passed to master interface, wlan#.11, for 1667 * encapsulated packet will then be passed to master interface, wlan#.11, for
1668 * transmission (through low-level driver). 1668 * transmission (through low-level driver).
1669 */ 1669 */
1670 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, 1670 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1671 struct net_device *dev) 1671 struct net_device *dev)
1672 { 1672 {
1673 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1673 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1674 struct ieee80211_local *local = sdata->local; 1674 struct ieee80211_local *local = sdata->local;
1675 struct ieee80211_tx_info *info; 1675 struct ieee80211_tx_info *info;
1676 int ret = NETDEV_TX_BUSY, head_need; 1676 int ret = NETDEV_TX_BUSY, head_need;
1677 u16 ethertype, hdrlen, meshhdrlen = 0; 1677 u16 ethertype, hdrlen, meshhdrlen = 0;
1678 __le16 fc; 1678 __le16 fc;
1679 struct ieee80211_hdr hdr; 1679 struct ieee80211_hdr hdr;
1680 struct ieee80211s_hdr mesh_hdr __maybe_unused; 1680 struct ieee80211s_hdr mesh_hdr __maybe_unused;
1681 struct mesh_path __maybe_unused *mppath = NULL; 1681 struct mesh_path __maybe_unused *mppath = NULL;
1682 const u8 *encaps_data; 1682 const u8 *encaps_data;
1683 int encaps_len, skip_header_bytes; 1683 int encaps_len, skip_header_bytes;
1684 int nh_pos, h_pos; 1684 int nh_pos, h_pos;
1685 struct sta_info *sta = NULL; 1685 struct sta_info *sta = NULL;
1686 bool wme_sta = false, authorized = false, tdls_auth = false; 1686 bool wme_sta = false, authorized = false, tdls_auth = false;
1687 struct sk_buff *tmp_skb; 1687 struct sk_buff *tmp_skb;
1688 bool tdls_direct = false; 1688 bool tdls_direct = false;
1689 1689
1690 if (unlikely(skb->len < ETH_HLEN)) { 1690 if (unlikely(skb->len < ETH_HLEN)) {
1691 ret = NETDEV_TX_OK; 1691 ret = NETDEV_TX_OK;
1692 goto fail; 1692 goto fail;
1693 } 1693 }
1694 1694
1695 /* convert Ethernet header to proper 802.11 header (based on 1695 /* convert Ethernet header to proper 802.11 header (based on
1696 * operation mode) */ 1696 * operation mode) */
1697 ethertype = (skb->data[12] << 8) | skb->data[13]; 1697 ethertype = (skb->data[12] << 8) | skb->data[13];
1698 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); 1698 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
1699 1699
1700 switch (sdata->vif.type) { 1700 switch (sdata->vif.type) {
1701 case NL80211_IFTYPE_AP_VLAN: 1701 case NL80211_IFTYPE_AP_VLAN:
1702 rcu_read_lock(); 1702 rcu_read_lock();
1703 sta = rcu_dereference(sdata->u.vlan.sta); 1703 sta = rcu_dereference(sdata->u.vlan.sta);
1704 if (sta) { 1704 if (sta) {
1705 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1705 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1706 /* RA TA DA SA */ 1706 /* RA TA DA SA */
1707 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN); 1707 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
1708 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 1708 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1709 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1709 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1710 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1710 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1711 hdrlen = 30; 1711 hdrlen = 30;
1712 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 1712 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1713 wme_sta = test_sta_flag(sta, WLAN_STA_WME); 1713 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
1714 } 1714 }
1715 rcu_read_unlock(); 1715 rcu_read_unlock();
1716 if (sta) 1716 if (sta)
1717 break; 1717 break;
1718 /* fall through */ 1718 /* fall through */
1719 case NL80211_IFTYPE_AP: 1719 case NL80211_IFTYPE_AP:
1720 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 1720 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
1721 /* DA BSSID SA */ 1721 /* DA BSSID SA */
1722 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1722 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1723 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 1723 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1724 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); 1724 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1725 hdrlen = 24; 1725 hdrlen = 24;
1726 break; 1726 break;
1727 case NL80211_IFTYPE_WDS: 1727 case NL80211_IFTYPE_WDS:
1728 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1728 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1729 /* RA TA DA SA */ 1729 /* RA TA DA SA */
1730 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN); 1730 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
1731 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 1731 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1732 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1732 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1733 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1733 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1734 hdrlen = 30; 1734 hdrlen = 30;
1735 break; 1735 break;
1736 #ifdef CONFIG_MAC80211_MESH 1736 #ifdef CONFIG_MAC80211_MESH
1737 case NL80211_IFTYPE_MESH_POINT: 1737 case NL80211_IFTYPE_MESH_POINT:
1738 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) { 1738 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
1739 /* Do not send frames with mesh_ttl == 0 */ 1739 /* Do not send frames with mesh_ttl == 0 */
1740 sdata->u.mesh.mshstats.dropped_frames_ttl++; 1740 sdata->u.mesh.mshstats.dropped_frames_ttl++;
1741 ret = NETDEV_TX_OK; 1741 ret = NETDEV_TX_OK;
1742 goto fail; 1742 goto fail;
1743 } 1743 }
1744 rcu_read_lock(); 1744 rcu_read_lock();
1745 if (!is_multicast_ether_addr(skb->data)) 1745 if (!is_multicast_ether_addr(skb->data))
1746 mppath = mpp_path_lookup(skb->data, sdata); 1746 mppath = mpp_path_lookup(skb->data, sdata);
1747 1747
1748 /* 1748 /*
1749 * Use address extension if it is a packet from 1749 * Use address extension if it is a packet from
1750 * another interface or if we know the destination 1750 * another interface or if we know the destination
1751 * is being proxied by a portal (i.e. portal address 1751 * is being proxied by a portal (i.e. portal address
1752 * differs from proxied address) 1752 * differs from proxied address)
1753 */ 1753 */
1754 if (compare_ether_addr(sdata->vif.addr, 1754 if (compare_ether_addr(sdata->vif.addr,
1755 skb->data + ETH_ALEN) == 0 && 1755 skb->data + ETH_ALEN) == 0 &&
1756 !(mppath && compare_ether_addr(mppath->mpp, skb->data))) { 1756 !(mppath && compare_ether_addr(mppath->mpp, skb->data))) {
1757 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 1757 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1758 skb->data, skb->data + ETH_ALEN); 1758 skb->data, skb->data + ETH_ALEN);
1759 rcu_read_unlock(); 1759 rcu_read_unlock();
1760 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, 1760 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
1761 sdata, NULL, NULL); 1761 sdata, NULL, NULL);
1762 } else { 1762 } else {
1763 int is_mesh_mcast = 1; 1763 int is_mesh_mcast = 1;
1764 const u8 *mesh_da; 1764 const u8 *mesh_da;
1765 1765
1766 if (is_multicast_ether_addr(skb->data)) 1766 if (is_multicast_ether_addr(skb->data))
1767 /* DA TA mSA AE:SA */ 1767 /* DA TA mSA AE:SA */
1768 mesh_da = skb->data; 1768 mesh_da = skb->data;
1769 else { 1769 else {
1770 static const u8 bcast[ETH_ALEN] = 1770 static const u8 bcast[ETH_ALEN] =
1771 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 1771 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1772 if (mppath) { 1772 if (mppath) {
1773 /* RA TA mDA mSA AE:DA SA */ 1773 /* RA TA mDA mSA AE:DA SA */
1774 mesh_da = mppath->mpp; 1774 mesh_da = mppath->mpp;
1775 is_mesh_mcast = 0; 1775 is_mesh_mcast = 0;
1776 } else { 1776 } else {
1777 /* DA TA mSA AE:SA */ 1777 /* DA TA mSA AE:SA */
1778 mesh_da = bcast; 1778 mesh_da = bcast;
1779 } 1779 }
1780 } 1780 }
1781 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 1781 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1782 mesh_da, sdata->vif.addr); 1782 mesh_da, sdata->vif.addr);
1783 rcu_read_unlock(); 1783 rcu_read_unlock();
1784 if (is_mesh_mcast) 1784 if (is_mesh_mcast)
1785 meshhdrlen = 1785 meshhdrlen =
1786 ieee80211_new_mesh_header(&mesh_hdr, 1786 ieee80211_new_mesh_header(&mesh_hdr,
1787 sdata, 1787 sdata,
1788 skb->data + ETH_ALEN, 1788 skb->data + ETH_ALEN,
1789 NULL); 1789 NULL);
1790 else 1790 else
1791 meshhdrlen = 1791 meshhdrlen =
1792 ieee80211_new_mesh_header(&mesh_hdr, 1792 ieee80211_new_mesh_header(&mesh_hdr,
1793 sdata, 1793 sdata,
1794 skb->data, 1794 skb->data,
1795 skb->data + ETH_ALEN); 1795 skb->data + ETH_ALEN);
1796 1796
1797 } 1797 }
1798 break; 1798 break;
1799 #endif 1799 #endif
1800 case NL80211_IFTYPE_STATION: 1800 case NL80211_IFTYPE_STATION:
1801 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) { 1801 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1802 bool tdls_peer = false; 1802 bool tdls_peer = false;
1803 1803
1804 rcu_read_lock(); 1804 rcu_read_lock();
1805 sta = sta_info_get(sdata, skb->data); 1805 sta = sta_info_get(sdata, skb->data);
1806 if (sta) { 1806 if (sta) {
1807 authorized = test_sta_flag(sta, 1807 authorized = test_sta_flag(sta,
1808 WLAN_STA_AUTHORIZED); 1808 WLAN_STA_AUTHORIZED);
1809 wme_sta = test_sta_flag(sta, WLAN_STA_WME); 1809 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
1810 tdls_peer = test_sta_flag(sta, 1810 tdls_peer = test_sta_flag(sta,
1811 WLAN_STA_TDLS_PEER); 1811 WLAN_STA_TDLS_PEER);
1812 tdls_auth = test_sta_flag(sta, 1812 tdls_auth = test_sta_flag(sta,
1813 WLAN_STA_TDLS_PEER_AUTH); 1813 WLAN_STA_TDLS_PEER_AUTH);
1814 } 1814 }
1815 rcu_read_unlock(); 1815 rcu_read_unlock();
1816 1816
1817 /* 1817 /*
1818 * If the TDLS link is enabled, send everything 1818 * If the TDLS link is enabled, send everything
1819 * directly. Otherwise, allow TDLS setup frames 1819 * directly. Otherwise, allow TDLS setup frames
1820 * to be transmitted indirectly. 1820 * to be transmitted indirectly.
1821 */ 1821 */
1822 tdls_direct = tdls_peer && (tdls_auth || 1822 tdls_direct = tdls_peer && (tdls_auth ||
1823 !(ethertype == ETH_P_TDLS && skb->len > 14 && 1823 !(ethertype == ETH_P_TDLS && skb->len > 14 &&
1824 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE)); 1824 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE));
1825 } 1825 }
1826 1826
1827 if (tdls_direct) { 1827 if (tdls_direct) {
1828 /* link during setup - throw out frames to peer */ 1828 /* link during setup - throw out frames to peer */
1829 if (!tdls_auth) { 1829 if (!tdls_auth) {
1830 ret = NETDEV_TX_OK; 1830 ret = NETDEV_TX_OK;
1831 goto fail; 1831 goto fail;
1832 } 1832 }
1833 1833
1834 /* DA SA BSSID */ 1834 /* DA SA BSSID */
1835 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1835 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1836 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 1836 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1837 memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN); 1837 memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
1838 hdrlen = 24; 1838 hdrlen = 24;
1839 } else if (sdata->u.mgd.use_4addr && 1839 } else if (sdata->u.mgd.use_4addr &&
1840 cpu_to_be16(ethertype) != sdata->control_port_protocol) { 1840 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
1841 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | 1841 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
1842 IEEE80211_FCTL_TODS); 1842 IEEE80211_FCTL_TODS);
1843 /* RA TA DA SA */ 1843 /* RA TA DA SA */
1844 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); 1844 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
1845 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 1845 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1846 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1846 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1847 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1847 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1848 hdrlen = 30; 1848 hdrlen = 30;
1849 } else { 1849 } else {
1850 fc |= cpu_to_le16(IEEE80211_FCTL_TODS); 1850 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
1851 /* BSSID SA DA */ 1851 /* BSSID SA DA */
1852 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); 1852 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
1853 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 1853 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1854 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1854 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1855 hdrlen = 24; 1855 hdrlen = 24;
1856 } 1856 }
1857 break; 1857 break;
1858 case NL80211_IFTYPE_ADHOC: 1858 case NL80211_IFTYPE_ADHOC:
1859 /* DA SA BSSID */ 1859 /* DA SA BSSID */
1860 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1860 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1861 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 1861 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1862 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN); 1862 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
1863 hdrlen = 24; 1863 hdrlen = 24;
1864 break; 1864 break;
1865 default: 1865 default:
1866 ret = NETDEV_TX_OK; 1866 ret = NETDEV_TX_OK;
1867 goto fail; 1867 goto fail;
1868 } 1868 }
1869 1869
1870 /* 1870 /*
1871 * There's no need to try to look up the destination 1871 * There's no need to try to look up the destination
1872 * if it is a multicast address (which can only happen 1872 * if it is a multicast address (which can only happen
1873 * in AP mode) 1873 * in AP mode)
1874 */ 1874 */
1875 if (!is_multicast_ether_addr(hdr.addr1)) { 1875 if (!is_multicast_ether_addr(hdr.addr1)) {
1876 rcu_read_lock(); 1876 rcu_read_lock();
1877 sta = sta_info_get(sdata, hdr.addr1); 1877 sta = sta_info_get(sdata, hdr.addr1);
1878 if (sta) { 1878 if (sta) {
1879 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 1879 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1880 wme_sta = test_sta_flag(sta, WLAN_STA_WME); 1880 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
1881 } 1881 }
1882 rcu_read_unlock(); 1882 rcu_read_unlock();
1883 } 1883 }
1884 1884
1885 /* For mesh, the use of the QoS header is mandatory */ 1885 /* For mesh, the use of the QoS header is mandatory */
1886 if (ieee80211_vif_is_mesh(&sdata->vif)) 1886 if (ieee80211_vif_is_mesh(&sdata->vif))
1887 wme_sta = true; 1887 wme_sta = true;
1888 1888
1889 /* receiver and we are QoS enabled, use a QoS type frame */ 1889 /* receiver and we are QoS enabled, use a QoS type frame */
1890 if (wme_sta && local->hw.queues >= 4) { 1890 if (wme_sta && local->hw.queues >= 4) {
1891 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); 1891 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1892 hdrlen += 2; 1892 hdrlen += 2;
1893 } 1893 }
1894 1894
1895 /* 1895 /*
1896 * Drop unicast frames to unauthorised stations unless they are 1896 * Drop unicast frames to unauthorised stations unless they are
1897 * EAPOL frames from the local station. 1897 * EAPOL frames from the local station.
1898 */ 1898 */
1899 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) && 1899 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
1900 !is_multicast_ether_addr(hdr.addr1) && !authorized && 1900 !is_multicast_ether_addr(hdr.addr1) && !authorized &&
1901 (cpu_to_be16(ethertype) != sdata->control_port_protocol || 1901 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
1902 compare_ether_addr(sdata->vif.addr, skb->data + ETH_ALEN)))) { 1902 compare_ether_addr(sdata->vif.addr, skb->data + ETH_ALEN)))) {
1903 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1903 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1904 if (net_ratelimit()) 1904 if (net_ratelimit())
1905 printk(KERN_DEBUG "%s: dropped frame to %pM" 1905 printk(KERN_DEBUG "%s: dropped frame to %pM"
1906 " (unauthorized port)\n", dev->name, 1906 " (unauthorized port)\n", dev->name,
1907 hdr.addr1); 1907 hdr.addr1);
1908 #endif 1908 #endif
1909 1909
1910 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 1910 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
1911 1911
1912 ret = NETDEV_TX_OK; 1912 ret = NETDEV_TX_OK;
1913 goto fail; 1913 goto fail;
1914 } 1914 }
1915 1915
1916 /* 1916 /*
1917 * If the skb is shared we need to obtain our own copy. 1917 * If the skb is shared we need to obtain our own copy.
1918 */ 1918 */
1919 if (skb_shared(skb)) { 1919 if (skb_shared(skb)) {
1920 tmp_skb = skb; 1920 tmp_skb = skb;
1921 skb = skb_clone(skb, GFP_ATOMIC); 1921 skb = skb_clone(skb, GFP_ATOMIC);
1922 kfree_skb(tmp_skb); 1922 kfree_skb(tmp_skb);
1923 1923
1924 if (!skb) { 1924 if (!skb) {
1925 ret = NETDEV_TX_OK; 1925 ret = NETDEV_TX_OK;
1926 goto fail; 1926 goto fail;
1927 } 1927 }
1928 } 1928 }
1929 1929
1930 hdr.frame_control = fc; 1930 hdr.frame_control = fc;
1931 hdr.duration_id = 0; 1931 hdr.duration_id = 0;
1932 hdr.seq_ctrl = 0; 1932 hdr.seq_ctrl = 0;
1933 1933
1934 skip_header_bytes = ETH_HLEN; 1934 skip_header_bytes = ETH_HLEN;
1935 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { 1935 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
1936 encaps_data = bridge_tunnel_header; 1936 encaps_data = bridge_tunnel_header;
1937 encaps_len = sizeof(bridge_tunnel_header); 1937 encaps_len = sizeof(bridge_tunnel_header);
1938 skip_header_bytes -= 2; 1938 skip_header_bytes -= 2;
1939 } else if (ethertype >= 0x600) { 1939 } else if (ethertype >= 0x600) {
1940 encaps_data = rfc1042_header; 1940 encaps_data = rfc1042_header;
1941 encaps_len = sizeof(rfc1042_header); 1941 encaps_len = sizeof(rfc1042_header);
1942 skip_header_bytes -= 2; 1942 skip_header_bytes -= 2;
1943 } else { 1943 } else {
1944 encaps_data = NULL; 1944 encaps_data = NULL;
1945 encaps_len = 0; 1945 encaps_len = 0;
1946 } 1946 }
1947 1947
1948 nh_pos = skb_network_header(skb) - skb->data; 1948 nh_pos = skb_network_header(skb) - skb->data;
1949 h_pos = skb_transport_header(skb) - skb->data; 1949 h_pos = skb_transport_header(skb) - skb->data;
1950 1950
1951 skb_pull(skb, skip_header_bytes); 1951 skb_pull(skb, skip_header_bytes);
1952 nh_pos -= skip_header_bytes; 1952 nh_pos -= skip_header_bytes;
1953 h_pos -= skip_header_bytes; 1953 h_pos -= skip_header_bytes;
1954 1954
1955 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb); 1955 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
1956 1956
1957 /* 1957 /*
1958 * So we need to modify the skb header and hence need a copy of 1958 * So we need to modify the skb header and hence need a copy of
1959 * that. The head_need variable above doesn't, so far, include 1959 * that. The head_need variable above doesn't, so far, include
1960 * the needed header space that we don't need right away. If we 1960 * the needed header space that we don't need right away. If we
1961 * can, then we don't reallocate right now but only after the 1961 * can, then we don't reallocate right now but only after the
1962 * frame arrives at the master device (if it does...) 1962 * frame arrives at the master device (if it does...)
1963 * 1963 *
1964 * If we cannot, however, then we will reallocate to include all 1964 * If we cannot, however, then we will reallocate to include all
1965 * the ever needed space. Also, if we need to reallocate it anyway, 1965 * the ever needed space. Also, if we need to reallocate it anyway,
1966 * make it big enough for everything we may ever need. 1966 * make it big enough for everything we may ever need.
1967 */ 1967 */
1968 1968
1969 if (head_need > 0 || skb_cloned(skb)) { 1969 if (head_need > 0 || skb_cloned(skb)) {
1970 head_need += IEEE80211_ENCRYPT_HEADROOM; 1970 head_need += IEEE80211_ENCRYPT_HEADROOM;
1971 head_need += local->tx_headroom; 1971 head_need += local->tx_headroom;
1972 head_need = max_t(int, 0, head_need); 1972 head_need = max_t(int, 0, head_need);
1973 if (ieee80211_skb_resize(sdata, skb, head_need, true)) 1973 if (ieee80211_skb_resize(sdata, skb, head_need, true))
1974 goto fail; 1974 goto fail;
1975 } 1975 }
1976 1976
1977 if (encaps_data) { 1977 if (encaps_data) {
1978 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); 1978 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
1979 nh_pos += encaps_len; 1979 nh_pos += encaps_len;
1980 h_pos += encaps_len; 1980 h_pos += encaps_len;
1981 } 1981 }
1982 1982
1983 #ifdef CONFIG_MAC80211_MESH 1983 #ifdef CONFIG_MAC80211_MESH
1984 if (meshhdrlen > 0) { 1984 if (meshhdrlen > 0) {
1985 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen); 1985 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
1986 nh_pos += meshhdrlen; 1986 nh_pos += meshhdrlen;
1987 h_pos += meshhdrlen; 1987 h_pos += meshhdrlen;
1988 } 1988 }
1989 #endif 1989 #endif
1990 1990
1991 if (ieee80211_is_data_qos(fc)) { 1991 if (ieee80211_is_data_qos(fc)) {
1992 __le16 *qos_control; 1992 __le16 *qos_control;
1993 1993
1994 qos_control = (__le16*) skb_push(skb, 2); 1994 qos_control = (__le16*) skb_push(skb, 2);
1995 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2); 1995 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
1996 /* 1996 /*
1997 * Maybe we could actually set some fields here, for now just 1997 * Maybe we could actually set some fields here, for now just
1998 * initialise to zero to indicate no special operation. 1998 * initialise to zero to indicate no special operation.
1999 */ 1999 */
2000 *qos_control = 0; 2000 *qos_control = 0;
2001 } else 2001 } else
2002 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen); 2002 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2003 2003
2004 nh_pos += hdrlen; 2004 nh_pos += hdrlen;
2005 h_pos += hdrlen; 2005 h_pos += hdrlen;
2006 2006
2007 dev->stats.tx_packets++; 2007 dev->stats.tx_packets++;
2008 dev->stats.tx_bytes += skb->len; 2008 dev->stats.tx_bytes += skb->len;
2009 2009
2010 /* Update skb pointers to various headers since this modified frame 2010 /* Update skb pointers to various headers since this modified frame
2011 * is going to go through Linux networking code that may potentially 2011 * is going to go through Linux networking code that may potentially
2012 * need things like pointer to IP header. */ 2012 * need things like pointer to IP header. */
2013 skb_set_mac_header(skb, 0); 2013 skb_set_mac_header(skb, 0);
2014 skb_set_network_header(skb, nh_pos); 2014 skb_set_network_header(skb, nh_pos);
2015 skb_set_transport_header(skb, h_pos); 2015 skb_set_transport_header(skb, h_pos);
2016 2016
2017 info = IEEE80211_SKB_CB(skb); 2017 info = IEEE80211_SKB_CB(skb);
2018 memset(info, 0, sizeof(*info)); 2018 memset(info, 0, sizeof(*info));
2019 2019
2020 dev->trans_start = jiffies; 2020 dev->trans_start = jiffies;
2021 ieee80211_xmit(sdata, skb); 2021 ieee80211_xmit(sdata, skb);
2022 2022
2023 return NETDEV_TX_OK; 2023 return NETDEV_TX_OK;
2024 2024
2025 fail: 2025 fail:
2026 if (ret == NETDEV_TX_OK) 2026 if (ret == NETDEV_TX_OK)
2027 dev_kfree_skb(skb); 2027 dev_kfree_skb(skb);
2028 2028
2029 return ret; 2029 return ret;
2030 } 2030 }
2031 2031
2032 2032
2033 /* 2033 /*
2034 * ieee80211_clear_tx_pending may not be called in a context where 2034 * ieee80211_clear_tx_pending may not be called in a context where
2035 * it is possible that it packets could come in again. 2035 * it is possible that it packets could come in again.
2036 */ 2036 */
2037 void ieee80211_clear_tx_pending(struct ieee80211_local *local) 2037 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
2038 { 2038 {
2039 int i; 2039 int i;
2040 2040
2041 for (i = 0; i < local->hw.queues; i++) 2041 for (i = 0; i < local->hw.queues; i++)
2042 skb_queue_purge(&local->pending[i]); 2042 skb_queue_purge(&local->pending[i]);
2043 } 2043 }
2044 2044
2045 /* 2045 /*
2046 * Returns false if the frame couldn't be transmitted but was queued instead, 2046 * Returns false if the frame couldn't be transmitted but was queued instead,
2047 * which in this case means re-queued -- take as an indication to stop sending 2047 * which in this case means re-queued -- take as an indication to stop sending
2048 * more pending frames. 2048 * more pending frames.
2049 */ 2049 */
2050 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local, 2050 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
2051 struct sk_buff *skb) 2051 struct sk_buff *skb)
2052 { 2052 {
2053 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2053 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2054 struct ieee80211_sub_if_data *sdata; 2054 struct ieee80211_sub_if_data *sdata;
2055 struct sta_info *sta; 2055 struct sta_info *sta;
2056 struct ieee80211_hdr *hdr; 2056 struct ieee80211_hdr *hdr;
2057 bool result; 2057 bool result;
2058 2058
2059 sdata = vif_to_sdata(info->control.vif); 2059 sdata = vif_to_sdata(info->control.vif);
2060 2060
2061 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) { 2061 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
2062 result = ieee80211_tx(sdata, skb, true); 2062 result = ieee80211_tx(sdata, skb, true);
2063 } else { 2063 } else {
2064 hdr = (struct ieee80211_hdr *)skb->data; 2064 hdr = (struct ieee80211_hdr *)skb->data;
2065 sta = sta_info_get(sdata, hdr->addr1); 2065 sta = sta_info_get(sdata, hdr->addr1);
2066 2066
2067 result = __ieee80211_tx(local, &skb, sta, true); 2067 result = __ieee80211_tx(local, &skb, sta, true);
2068 } 2068 }
2069 2069
2070 return result; 2070 return result;
2071 } 2071 }
2072 2072
2073 /* 2073 /*
2074 * Transmit all pending packets. Called from tasklet. 2074 * Transmit all pending packets. Called from tasklet.
2075 */ 2075 */
2076 void ieee80211_tx_pending(unsigned long data) 2076 void ieee80211_tx_pending(unsigned long data)
2077 { 2077 {
2078 struct ieee80211_local *local = (struct ieee80211_local *)data; 2078 struct ieee80211_local *local = (struct ieee80211_local *)data;
2079 struct ieee80211_sub_if_data *sdata; 2079 struct ieee80211_sub_if_data *sdata;
2080 unsigned long flags; 2080 unsigned long flags;
2081 int i; 2081 int i;
2082 bool txok; 2082 bool txok;
2083 2083
2084 rcu_read_lock(); 2084 rcu_read_lock();
2085 2085
2086 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 2086 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2087 for (i = 0; i < local->hw.queues; i++) { 2087 for (i = 0; i < local->hw.queues; i++) {
2088 /* 2088 /*
2089 * If queue is stopped by something other than due to pending 2089 * If queue is stopped by something other than due to pending
2090 * frames, or we have no pending frames, proceed to next queue. 2090 * frames, or we have no pending frames, proceed to next queue.
2091 */ 2091 */
2092 if (local->queue_stop_reasons[i] || 2092 if (local->queue_stop_reasons[i] ||
2093 skb_queue_empty(&local->pending[i])) 2093 skb_queue_empty(&local->pending[i]))
2094 continue; 2094 continue;
2095 2095
2096 while (!skb_queue_empty(&local->pending[i])) { 2096 while (!skb_queue_empty(&local->pending[i])) {
2097 struct sk_buff *skb = __skb_dequeue(&local->pending[i]); 2097 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
2098 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2098 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2099 2099
2100 if (WARN_ON(!info->control.vif)) { 2100 if (WARN_ON(!info->control.vif)) {
2101 kfree_skb(skb); 2101 kfree_skb(skb);
2102 continue; 2102 continue;
2103 } 2103 }
2104 2104
2105 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 2105 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2106 flags); 2106 flags);
2107 2107
2108 txok = ieee80211_tx_pending_skb(local, skb); 2108 txok = ieee80211_tx_pending_skb(local, skb);
2109 spin_lock_irqsave(&local->queue_stop_reason_lock, 2109 spin_lock_irqsave(&local->queue_stop_reason_lock,
2110 flags); 2110 flags);
2111 if (!txok) 2111 if (!txok)
2112 break; 2112 break;
2113 } 2113 }
2114 2114
2115 if (skb_queue_empty(&local->pending[i])) 2115 if (skb_queue_empty(&local->pending[i]))
2116 list_for_each_entry_rcu(sdata, &local->interfaces, list) 2116 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2117 netif_wake_subqueue(sdata->dev, i); 2117 netif_wake_subqueue(sdata->dev, i);
2118 } 2118 }
2119 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 2119 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2120 2120
2121 rcu_read_unlock(); 2121 rcu_read_unlock();
2122 } 2122 }
2123 2123
2124 /* functions for drivers to get certain frames */ 2124 /* functions for drivers to get certain frames */
2125 2125
2126 static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss, 2126 static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
2127 struct sk_buff *skb, 2127 struct sk_buff *skb,
2128 struct beacon_data *beacon) 2128 struct beacon_data *beacon)
2129 { 2129 {
2130 u8 *pos, *tim; 2130 u8 *pos, *tim;
2131 int aid0 = 0; 2131 int aid0 = 0;
2132 int i, have_bits = 0, n1, n2; 2132 int i, have_bits = 0, n1, n2;
2133 2133
2134 /* Generate bitmap for TIM only if there are any STAs in power save 2134 /* Generate bitmap for TIM only if there are any STAs in power save
2135 * mode. */ 2135 * mode. */
2136 if (atomic_read(&bss->num_sta_ps) > 0) 2136 if (atomic_read(&bss->num_sta_ps) > 0)
2137 /* in the hope that this is faster than 2137 /* in the hope that this is faster than
2138 * checking byte-for-byte */ 2138 * checking byte-for-byte */
2139 have_bits = !bitmap_empty((unsigned long*)bss->tim, 2139 have_bits = !bitmap_empty((unsigned long*)bss->tim,
2140 IEEE80211_MAX_AID+1); 2140 IEEE80211_MAX_AID+1);
2141 2141
2142 if (bss->dtim_count == 0) 2142 if (bss->dtim_count == 0)
2143 bss->dtim_count = beacon->dtim_period - 1; 2143 bss->dtim_count = beacon->dtim_period - 1;
2144 else 2144 else
2145 bss->dtim_count--; 2145 bss->dtim_count--;
2146 2146
2147 tim = pos = (u8 *) skb_put(skb, 6); 2147 tim = pos = (u8 *) skb_put(skb, 6);
2148 *pos++ = WLAN_EID_TIM; 2148 *pos++ = WLAN_EID_TIM;
2149 *pos++ = 4; 2149 *pos++ = 4;
2150 *pos++ = bss->dtim_count; 2150 *pos++ = bss->dtim_count;
2151 *pos++ = beacon->dtim_period; 2151 *pos++ = beacon->dtim_period;
2152 2152
2153 if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) 2153 if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
2154 aid0 = 1; 2154 aid0 = 1;
2155 2155
2156 bss->dtim_bc_mc = aid0 == 1; 2156 bss->dtim_bc_mc = aid0 == 1;
2157 2157
2158 if (have_bits) { 2158 if (have_bits) {
2159 /* Find largest even number N1 so that bits numbered 1 through 2159 /* Find largest even number N1 so that bits numbered 1 through
2160 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits 2160 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
2161 * (N2 + 1) x 8 through 2007 are 0. */ 2161 * (N2 + 1) x 8 through 2007 are 0. */
2162 n1 = 0; 2162 n1 = 0;
2163 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) { 2163 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
2164 if (bss->tim[i]) { 2164 if (bss->tim[i]) {
2165 n1 = i & 0xfe; 2165 n1 = i & 0xfe;
2166 break; 2166 break;
2167 } 2167 }
2168 } 2168 }
2169 n2 = n1; 2169 n2 = n1;
2170 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) { 2170 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
2171 if (bss->tim[i]) { 2171 if (bss->tim[i]) {
2172 n2 = i; 2172 n2 = i;
2173 break; 2173 break;
2174 } 2174 }
2175 } 2175 }
2176 2176
2177 /* Bitmap control */ 2177 /* Bitmap control */
2178 *pos++ = n1 | aid0; 2178 *pos++ = n1 | aid0;
2179 /* Part Virt Bitmap */ 2179 /* Part Virt Bitmap */
2180 memcpy(pos, bss->tim + n1, n2 - n1 + 1); 2180 memcpy(pos, bss->tim + n1, n2 - n1 + 1);
2181 2181
2182 tim[1] = n2 - n1 + 4; 2182 tim[1] = n2 - n1 + 4;
2183 skb_put(skb, n2 - n1); 2183 skb_put(skb, n2 - n1);
2184 } else { 2184 } else {
2185 *pos++ = aid0; /* Bitmap control */ 2185 *pos++ = aid0; /* Bitmap control */
2186 *pos++ = 0; /* Part Virt Bitmap */ 2186 *pos++ = 0; /* Part Virt Bitmap */
2187 } 2187 }
2188 } 2188 }
2189 2189
2190 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw, 2190 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2191 struct ieee80211_vif *vif, 2191 struct ieee80211_vif *vif,
2192 u16 *tim_offset, u16 *tim_length) 2192 u16 *tim_offset, u16 *tim_length)
2193 { 2193 {
2194 struct ieee80211_local *local = hw_to_local(hw); 2194 struct ieee80211_local *local = hw_to_local(hw);
2195 struct sk_buff *skb = NULL; 2195 struct sk_buff *skb = NULL;
2196 struct ieee80211_tx_info *info; 2196 struct ieee80211_tx_info *info;
2197 struct ieee80211_sub_if_data *sdata = NULL; 2197 struct ieee80211_sub_if_data *sdata = NULL;
2198 struct ieee80211_if_ap *ap = NULL; 2198 struct ieee80211_if_ap *ap = NULL;
2199 struct beacon_data *beacon; 2199 struct beacon_data *beacon;
2200 struct ieee80211_supported_band *sband; 2200 struct ieee80211_supported_band *sband;
2201 enum ieee80211_band band = local->hw.conf.channel->band; 2201 enum ieee80211_band band = local->hw.conf.channel->band;
2202 struct ieee80211_tx_rate_control txrc; 2202 struct ieee80211_tx_rate_control txrc;
2203 2203
2204 sband = local->hw.wiphy->bands[band]; 2204 sband = local->hw.wiphy->bands[band];
2205 2205
2206 rcu_read_lock(); 2206 rcu_read_lock();
2207 2207
2208 sdata = vif_to_sdata(vif); 2208 sdata = vif_to_sdata(vif);
2209 2209
2210 if (!ieee80211_sdata_running(sdata)) 2210 if (!ieee80211_sdata_running(sdata))
2211 goto out; 2211 goto out;
2212 2212
2213 if (tim_offset) 2213 if (tim_offset)
2214 *tim_offset = 0; 2214 *tim_offset = 0;
2215 if (tim_length) 2215 if (tim_length)
2216 *tim_length = 0; 2216 *tim_length = 0;
2217 2217
2218 if (sdata->vif.type == NL80211_IFTYPE_AP) { 2218 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2219 ap = &sdata->u.ap; 2219 ap = &sdata->u.ap;
2220 beacon = rcu_dereference(ap->beacon); 2220 beacon = rcu_dereference(ap->beacon);
2221 if (beacon) { 2221 if (beacon) {
2222 /* 2222 /*
2223 * headroom, head length, 2223 * headroom, head length,
2224 * tail length and maximum TIM length 2224 * tail length and maximum TIM length
2225 */ 2225 */
2226 skb = dev_alloc_skb(local->tx_headroom + 2226 skb = dev_alloc_skb(local->tx_headroom +
2227 beacon->head_len + 2227 beacon->head_len +
2228 beacon->tail_len + 256); 2228 beacon->tail_len + 256);
2229 if (!skb) 2229 if (!skb)
2230 goto out; 2230 goto out;
2231 2231
2232 skb_reserve(skb, local->tx_headroom); 2232 skb_reserve(skb, local->tx_headroom);
2233 memcpy(skb_put(skb, beacon->head_len), beacon->head, 2233 memcpy(skb_put(skb, beacon->head_len), beacon->head,
2234 beacon->head_len); 2234 beacon->head_len);
2235 2235
2236 /* 2236 /*
2237 * Not very nice, but we want to allow the driver to call 2237 * Not very nice, but we want to allow the driver to call
2238 * ieee80211_beacon_get() as a response to the set_tim() 2238 * ieee80211_beacon_get() as a response to the set_tim()
2239 * callback. That, however, is already invoked under the 2239 * callback. That, however, is already invoked under the
2240 * sta_lock to guarantee consistent and race-free update 2240 * sta_lock to guarantee consistent and race-free update
2241 * of the tim bitmap in mac80211 and the driver. 2241 * of the tim bitmap in mac80211 and the driver.
2242 */ 2242 */
2243 if (local->tim_in_locked_section) { 2243 if (local->tim_in_locked_section) {
2244 ieee80211_beacon_add_tim(ap, skb, beacon); 2244 ieee80211_beacon_add_tim(ap, skb, beacon);
2245 } else { 2245 } else {
2246 unsigned long flags; 2246 unsigned long flags;
2247 2247
2248 spin_lock_irqsave(&local->sta_lock, flags); 2248 spin_lock_irqsave(&local->sta_lock, flags);
2249 ieee80211_beacon_add_tim(ap, skb, beacon); 2249 ieee80211_beacon_add_tim(ap, skb, beacon);
2250 spin_unlock_irqrestore(&local->sta_lock, flags); 2250 spin_unlock_irqrestore(&local->sta_lock, flags);
2251 } 2251 }
2252 2252
2253 if (tim_offset) 2253 if (tim_offset)
2254 *tim_offset = beacon->head_len; 2254 *tim_offset = beacon->head_len;
2255 if (tim_length) 2255 if (tim_length)
2256 *tim_length = skb->len - beacon->head_len; 2256 *tim_length = skb->len - beacon->head_len;
2257 2257
2258 if (beacon->tail) 2258 if (beacon->tail)
2259 memcpy(skb_put(skb, beacon->tail_len), 2259 memcpy(skb_put(skb, beacon->tail_len),
2260 beacon->tail, beacon->tail_len); 2260 beacon->tail, beacon->tail_len);
2261 } else 2261 } else
2262 goto out; 2262 goto out;
2263 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 2263 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2264 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 2264 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2265 struct ieee80211_hdr *hdr; 2265 struct ieee80211_hdr *hdr;
2266 struct sk_buff *presp = rcu_dereference(ifibss->presp); 2266 struct sk_buff *presp = rcu_dereference(ifibss->presp);
2267 2267
2268 if (!presp) 2268 if (!presp)
2269 goto out; 2269 goto out;
2270 2270
2271 skb = skb_copy(presp, GFP_ATOMIC); 2271 skb = skb_copy(presp, GFP_ATOMIC);
2272 if (!skb) 2272 if (!skb)
2273 goto out; 2273 goto out;
2274 2274
2275 hdr = (struct ieee80211_hdr *) skb->data; 2275 hdr = (struct ieee80211_hdr *) skb->data;
2276 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2276 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2277 IEEE80211_STYPE_BEACON); 2277 IEEE80211_STYPE_BEACON);
2278 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 2278 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2279 struct ieee80211_mgmt *mgmt; 2279 struct ieee80211_mgmt *mgmt;
2280 u8 *pos; 2280 u8 *pos;
2281 int hdr_len = offsetof(struct ieee80211_mgmt, u.beacon) + 2281 int hdr_len = offsetof(struct ieee80211_mgmt, u.beacon) +
2282 sizeof(mgmt->u.beacon); 2282 sizeof(mgmt->u.beacon);
2283 2283
2284 #ifdef CONFIG_MAC80211_MESH 2284 #ifdef CONFIG_MAC80211_MESH
2285 if (!sdata->u.mesh.mesh_id_len) 2285 if (!sdata->u.mesh.mesh_id_len)
2286 goto out; 2286 goto out;
2287 #endif 2287 #endif
2288 2288
2289 skb = dev_alloc_skb(local->tx_headroom + 2289 skb = dev_alloc_skb(local->tx_headroom +
2290 hdr_len + 2290 hdr_len +
2291 2 + /* NULL SSID */ 2291 2 + /* NULL SSID */
2292 2 + 8 + /* supported rates */ 2292 2 + 8 + /* supported rates */
2293 2 + 3 + /* DS params */ 2293 2 + 3 + /* DS params */
2294 2 + (IEEE80211_MAX_SUPP_RATES - 8) + 2294 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
2295 2 + sizeof(struct ieee80211_ht_cap) +
2296 2 + sizeof(struct ieee80211_ht_info) +
2295 2 + sdata->u.mesh.mesh_id_len + 2297 2 + sdata->u.mesh.mesh_id_len +
2296 2 + sizeof(struct ieee80211_meshconf_ie) + 2298 2 + sizeof(struct ieee80211_meshconf_ie) +
2297 sdata->u.mesh.ie_len); 2299 sdata->u.mesh.ie_len);
2298 if (!skb) 2300 if (!skb)
2299 goto out; 2301 goto out;
2300 2302
2301 skb_reserve(skb, local->hw.extra_tx_headroom); 2303 skb_reserve(skb, local->hw.extra_tx_headroom);
2302 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); 2304 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
2303 memset(mgmt, 0, hdr_len); 2305 memset(mgmt, 0, hdr_len);
2304 mgmt->frame_control = 2306 mgmt->frame_control =
2305 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON); 2307 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
2306 memset(mgmt->da, 0xff, ETH_ALEN); 2308 memset(mgmt->da, 0xff, ETH_ALEN);
2307 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 2309 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2308 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); 2310 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
2309 mgmt->u.beacon.beacon_int = 2311 mgmt->u.beacon.beacon_int =
2310 cpu_to_le16(sdata->vif.bss_conf.beacon_int); 2312 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
2311 mgmt->u.beacon.capab_info |= cpu_to_le16( 2313 mgmt->u.beacon.capab_info |= cpu_to_le16(
2312 sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0); 2314 sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
2313 2315
2314 pos = skb_put(skb, 2); 2316 pos = skb_put(skb, 2);
2315 *pos++ = WLAN_EID_SSID; 2317 *pos++ = WLAN_EID_SSID;
2316 *pos++ = 0x0; 2318 *pos++ = 0x0;
2317 2319
2318 if (ieee80211_add_srates_ie(&sdata->vif, skb) || 2320 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
2319 mesh_add_ds_params_ie(skb, sdata) || 2321 mesh_add_ds_params_ie(skb, sdata) ||
2320 ieee80211_add_ext_srates_ie(&sdata->vif, skb) || 2322 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
2321 mesh_add_rsn_ie(skb, sdata) || 2323 mesh_add_rsn_ie(skb, sdata) ||
2324 mesh_add_ht_cap_ie(skb, sdata) ||
2325 mesh_add_ht_info_ie(skb, sdata) ||
2322 mesh_add_meshid_ie(skb, sdata) || 2326 mesh_add_meshid_ie(skb, sdata) ||
2323 mesh_add_meshconf_ie(skb, sdata) || 2327 mesh_add_meshconf_ie(skb, sdata) ||
2324 mesh_add_vendor_ies(skb, sdata)) { 2328 mesh_add_vendor_ies(skb, sdata)) {
2325 pr_err("o11s: couldn't add ies!\n"); 2329 pr_err("o11s: couldn't add ies!\n");
2326 goto out; 2330 goto out;
2327 } 2331 }
2328 } else { 2332 } else {
2329 WARN_ON(1); 2333 WARN_ON(1);
2330 goto out; 2334 goto out;
2331 } 2335 }
2332 2336
2333 info = IEEE80211_SKB_CB(skb); 2337 info = IEEE80211_SKB_CB(skb);
2334 2338
2335 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2339 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2336 info->flags |= IEEE80211_TX_CTL_NO_ACK; 2340 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2337 info->band = band; 2341 info->band = band;
2338 2342
2339 memset(&txrc, 0, sizeof(txrc)); 2343 memset(&txrc, 0, sizeof(txrc));
2340 txrc.hw = hw; 2344 txrc.hw = hw;
2341 txrc.sband = sband; 2345 txrc.sband = sband;
2342 txrc.bss_conf = &sdata->vif.bss_conf; 2346 txrc.bss_conf = &sdata->vif.bss_conf;
2343 txrc.skb = skb; 2347 txrc.skb = skb;
2344 txrc.reported_rate.idx = -1; 2348 txrc.reported_rate.idx = -1;
2345 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band]; 2349 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
2346 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1) 2350 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
2347 txrc.max_rate_idx = -1; 2351 txrc.max_rate_idx = -1;
2348 else 2352 else
2349 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1; 2353 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
2350 txrc.bss = true; 2354 txrc.bss = true;
2351 rate_control_get_rate(sdata, NULL, &txrc); 2355 rate_control_get_rate(sdata, NULL, &txrc);
2352 2356
2353 info->control.vif = vif; 2357 info->control.vif = vif;
2354 2358
2355 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT | 2359 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
2356 IEEE80211_TX_CTL_ASSIGN_SEQ | 2360 IEEE80211_TX_CTL_ASSIGN_SEQ |
2357 IEEE80211_TX_CTL_FIRST_FRAGMENT; 2361 IEEE80211_TX_CTL_FIRST_FRAGMENT;
2358 out: 2362 out:
2359 rcu_read_unlock(); 2363 rcu_read_unlock();
2360 return skb; 2364 return skb;
2361 } 2365 }
2362 EXPORT_SYMBOL(ieee80211_beacon_get_tim); 2366 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
2363 2367
2364 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw, 2368 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
2365 struct ieee80211_vif *vif) 2369 struct ieee80211_vif *vif)
2366 { 2370 {
2367 struct ieee80211_sub_if_data *sdata; 2371 struct ieee80211_sub_if_data *sdata;
2368 struct ieee80211_if_managed *ifmgd; 2372 struct ieee80211_if_managed *ifmgd;
2369 struct ieee80211_pspoll *pspoll; 2373 struct ieee80211_pspoll *pspoll;
2370 struct ieee80211_local *local; 2374 struct ieee80211_local *local;
2371 struct sk_buff *skb; 2375 struct sk_buff *skb;
2372 2376
2373 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) 2377 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
2374 return NULL; 2378 return NULL;
2375 2379
2376 sdata = vif_to_sdata(vif); 2380 sdata = vif_to_sdata(vif);
2377 ifmgd = &sdata->u.mgd; 2381 ifmgd = &sdata->u.mgd;
2378 local = sdata->local; 2382 local = sdata->local;
2379 2383
2380 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); 2384 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
2381 if (!skb) 2385 if (!skb)
2382 return NULL; 2386 return NULL;
2383 2387
2384 skb_reserve(skb, local->hw.extra_tx_headroom); 2388 skb_reserve(skb, local->hw.extra_tx_headroom);
2385 2389
2386 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll)); 2390 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
2387 memset(pspoll, 0, sizeof(*pspoll)); 2391 memset(pspoll, 0, sizeof(*pspoll));
2388 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | 2392 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
2389 IEEE80211_STYPE_PSPOLL); 2393 IEEE80211_STYPE_PSPOLL);
2390 pspoll->aid = cpu_to_le16(ifmgd->aid); 2394 pspoll->aid = cpu_to_le16(ifmgd->aid);
2391 2395
2392 /* aid in PS-Poll has its two MSBs each set to 1 */ 2396 /* aid in PS-Poll has its two MSBs each set to 1 */
2393 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); 2397 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
2394 2398
2395 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); 2399 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
2396 memcpy(pspoll->ta, vif->addr, ETH_ALEN); 2400 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
2397 2401
2398 return skb; 2402 return skb;
2399 } 2403 }
2400 EXPORT_SYMBOL(ieee80211_pspoll_get); 2404 EXPORT_SYMBOL(ieee80211_pspoll_get);
2401 2405
2402 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw, 2406 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
2403 struct ieee80211_vif *vif) 2407 struct ieee80211_vif *vif)
2404 { 2408 {
2405 struct ieee80211_hdr_3addr *nullfunc; 2409 struct ieee80211_hdr_3addr *nullfunc;
2406 struct ieee80211_sub_if_data *sdata; 2410 struct ieee80211_sub_if_data *sdata;
2407 struct ieee80211_if_managed *ifmgd; 2411 struct ieee80211_if_managed *ifmgd;
2408 struct ieee80211_local *local; 2412 struct ieee80211_local *local;
2409 struct sk_buff *skb; 2413 struct sk_buff *skb;
2410 2414
2411 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) 2415 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
2412 return NULL; 2416 return NULL;
2413 2417
2414 sdata = vif_to_sdata(vif); 2418 sdata = vif_to_sdata(vif);
2415 ifmgd = &sdata->u.mgd; 2419 ifmgd = &sdata->u.mgd;
2416 local = sdata->local; 2420 local = sdata->local;
2417 2421
2418 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc)); 2422 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
2419 if (!skb) 2423 if (!skb)
2420 return NULL; 2424 return NULL;
2421 2425
2422 skb_reserve(skb, local->hw.extra_tx_headroom); 2426 skb_reserve(skb, local->hw.extra_tx_headroom);
2423 2427
2424 nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb, 2428 nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
2425 sizeof(*nullfunc)); 2429 sizeof(*nullfunc));
2426 memset(nullfunc, 0, sizeof(*nullfunc)); 2430 memset(nullfunc, 0, sizeof(*nullfunc));
2427 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 2431 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
2428 IEEE80211_STYPE_NULLFUNC | 2432 IEEE80211_STYPE_NULLFUNC |
2429 IEEE80211_FCTL_TODS); 2433 IEEE80211_FCTL_TODS);
2430 memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN); 2434 memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
2431 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN); 2435 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
2432 memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN); 2436 memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
2433 2437
2434 return skb; 2438 return skb;
2435 } 2439 }
2436 EXPORT_SYMBOL(ieee80211_nullfunc_get); 2440 EXPORT_SYMBOL(ieee80211_nullfunc_get);
2437 2441
2438 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw, 2442 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
2439 struct ieee80211_vif *vif, 2443 struct ieee80211_vif *vif,
2440 const u8 *ssid, size_t ssid_len, 2444 const u8 *ssid, size_t ssid_len,
2441 const u8 *ie, size_t ie_len) 2445 const u8 *ie, size_t ie_len)
2442 { 2446 {
2443 struct ieee80211_sub_if_data *sdata; 2447 struct ieee80211_sub_if_data *sdata;
2444 struct ieee80211_local *local; 2448 struct ieee80211_local *local;
2445 struct ieee80211_hdr_3addr *hdr; 2449 struct ieee80211_hdr_3addr *hdr;
2446 struct sk_buff *skb; 2450 struct sk_buff *skb;
2447 size_t ie_ssid_len; 2451 size_t ie_ssid_len;
2448 u8 *pos; 2452 u8 *pos;
2449 2453
2450 sdata = vif_to_sdata(vif); 2454 sdata = vif_to_sdata(vif);
2451 local = sdata->local; 2455 local = sdata->local;
2452 ie_ssid_len = 2 + ssid_len; 2456 ie_ssid_len = 2 + ssid_len;
2453 2457
2454 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) + 2458 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
2455 ie_ssid_len + ie_len); 2459 ie_ssid_len + ie_len);
2456 if (!skb) 2460 if (!skb)
2457 return NULL; 2461 return NULL;
2458 2462
2459 skb_reserve(skb, local->hw.extra_tx_headroom); 2463 skb_reserve(skb, local->hw.extra_tx_headroom);
2460 2464
2461 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); 2465 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
2462 memset(hdr, 0, sizeof(*hdr)); 2466 memset(hdr, 0, sizeof(*hdr));
2463 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2467 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2464 IEEE80211_STYPE_PROBE_REQ); 2468 IEEE80211_STYPE_PROBE_REQ);
2465 memset(hdr->addr1, 0xff, ETH_ALEN); 2469 memset(hdr->addr1, 0xff, ETH_ALEN);
2466 memcpy(hdr->addr2, vif->addr, ETH_ALEN); 2470 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
2467 memset(hdr->addr3, 0xff, ETH_ALEN); 2471 memset(hdr->addr3, 0xff, ETH_ALEN);
2468 2472
2469 pos = skb_put(skb, ie_ssid_len); 2473 pos = skb_put(skb, ie_ssid_len);
2470 *pos++ = WLAN_EID_SSID; 2474 *pos++ = WLAN_EID_SSID;
2471 *pos++ = ssid_len; 2475 *pos++ = ssid_len;
2472 if (ssid) 2476 if (ssid)
2473 memcpy(pos, ssid, ssid_len); 2477 memcpy(pos, ssid, ssid_len);
2474 pos += ssid_len; 2478 pos += ssid_len;
2475 2479
2476 if (ie) { 2480 if (ie) {
2477 pos = skb_put(skb, ie_len); 2481 pos = skb_put(skb, ie_len);
2478 memcpy(pos, ie, ie_len); 2482 memcpy(pos, ie, ie_len);
2479 } 2483 }
2480 2484
2481 return skb; 2485 return skb;
2482 } 2486 }
2483 EXPORT_SYMBOL(ieee80211_probereq_get); 2487 EXPORT_SYMBOL(ieee80211_probereq_get);
2484 2488
2485 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2489 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2486 const void *frame, size_t frame_len, 2490 const void *frame, size_t frame_len,
2487 const struct ieee80211_tx_info *frame_txctl, 2491 const struct ieee80211_tx_info *frame_txctl,
2488 struct ieee80211_rts *rts) 2492 struct ieee80211_rts *rts)
2489 { 2493 {
2490 const struct ieee80211_hdr *hdr = frame; 2494 const struct ieee80211_hdr *hdr = frame;
2491 2495
2492 rts->frame_control = 2496 rts->frame_control =
2493 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); 2497 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
2494 rts->duration = ieee80211_rts_duration(hw, vif, frame_len, 2498 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
2495 frame_txctl); 2499 frame_txctl);
2496 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra)); 2500 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
2497 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta)); 2501 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
2498 } 2502 }
2499 EXPORT_SYMBOL(ieee80211_rts_get); 2503 EXPORT_SYMBOL(ieee80211_rts_get);
2500 2504
2501 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2505 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2502 const void *frame, size_t frame_len, 2506 const void *frame, size_t frame_len,
2503 const struct ieee80211_tx_info *frame_txctl, 2507 const struct ieee80211_tx_info *frame_txctl,
2504 struct ieee80211_cts *cts) 2508 struct ieee80211_cts *cts)
2505 { 2509 {
2506 const struct ieee80211_hdr *hdr = frame; 2510 const struct ieee80211_hdr *hdr = frame;
2507 2511
2508 cts->frame_control = 2512 cts->frame_control =
2509 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); 2513 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
2510 cts->duration = ieee80211_ctstoself_duration(hw, vif, 2514 cts->duration = ieee80211_ctstoself_duration(hw, vif,
2511 frame_len, frame_txctl); 2515 frame_len, frame_txctl);
2512 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra)); 2516 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
2513 } 2517 }
2514 EXPORT_SYMBOL(ieee80211_ctstoself_get); 2518 EXPORT_SYMBOL(ieee80211_ctstoself_get);
2515 2519
2516 struct sk_buff * 2520 struct sk_buff *
2517 ieee80211_get_buffered_bc(struct ieee80211_hw *hw, 2521 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2518 struct ieee80211_vif *vif) 2522 struct ieee80211_vif *vif)
2519 { 2523 {
2520 struct ieee80211_local *local = hw_to_local(hw); 2524 struct ieee80211_local *local = hw_to_local(hw);
2521 struct sk_buff *skb = NULL; 2525 struct sk_buff *skb = NULL;
2522 struct ieee80211_tx_data tx; 2526 struct ieee80211_tx_data tx;
2523 struct ieee80211_sub_if_data *sdata; 2527 struct ieee80211_sub_if_data *sdata;
2524 struct ieee80211_if_ap *bss = NULL; 2528 struct ieee80211_if_ap *bss = NULL;
2525 struct beacon_data *beacon; 2529 struct beacon_data *beacon;
2526 struct ieee80211_tx_info *info; 2530 struct ieee80211_tx_info *info;
2527 2531
2528 sdata = vif_to_sdata(vif); 2532 sdata = vif_to_sdata(vif);
2529 bss = &sdata->u.ap; 2533 bss = &sdata->u.ap;
2530 2534
2531 rcu_read_lock(); 2535 rcu_read_lock();
2532 beacon = rcu_dereference(bss->beacon); 2536 beacon = rcu_dereference(bss->beacon);
2533 2537
2534 if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head) 2538 if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
2535 goto out; 2539 goto out;
2536 2540
2537 if (bss->dtim_count != 0 || !bss->dtim_bc_mc) 2541 if (bss->dtim_count != 0 || !bss->dtim_bc_mc)
2538 goto out; /* send buffered bc/mc only after DTIM beacon */ 2542 goto out; /* send buffered bc/mc only after DTIM beacon */
2539 2543
2540 while (1) { 2544 while (1) {
2541 skb = skb_dequeue(&bss->ps_bc_buf); 2545 skb = skb_dequeue(&bss->ps_bc_buf);
2542 if (!skb) 2546 if (!skb)
2543 goto out; 2547 goto out;
2544 local->total_ps_buffered--; 2548 local->total_ps_buffered--;
2545 2549
2546 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) { 2550 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
2547 struct ieee80211_hdr *hdr = 2551 struct ieee80211_hdr *hdr =
2548 (struct ieee80211_hdr *) skb->data; 2552 (struct ieee80211_hdr *) skb->data;
2549 /* more buffered multicast/broadcast frames ==> set 2553 /* more buffered multicast/broadcast frames ==> set
2550 * MoreData flag in IEEE 802.11 header to inform PS 2554 * MoreData flag in IEEE 802.11 header to inform PS
2551 * STAs */ 2555 * STAs */
2552 hdr->frame_control |= 2556 hdr->frame_control |=
2553 cpu_to_le16(IEEE80211_FCTL_MOREDATA); 2557 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2554 } 2558 }
2555 2559
2556 if (!ieee80211_tx_prepare(sdata, &tx, skb)) 2560 if (!ieee80211_tx_prepare(sdata, &tx, skb))
2557 break; 2561 break;
2558 dev_kfree_skb_any(skb); 2562 dev_kfree_skb_any(skb);
2559 } 2563 }
2560 2564
2561 info = IEEE80211_SKB_CB(skb); 2565 info = IEEE80211_SKB_CB(skb);
2562 2566
2563 tx.flags |= IEEE80211_TX_PS_BUFFERED; 2567 tx.flags |= IEEE80211_TX_PS_BUFFERED;
2564 tx.channel = local->hw.conf.channel; 2568 tx.channel = local->hw.conf.channel;
2565 info->band = tx.channel->band; 2569 info->band = tx.channel->band;
2566 2570
2567 if (invoke_tx_handlers(&tx)) 2571 if (invoke_tx_handlers(&tx))
2568 skb = NULL; 2572 skb = NULL;
2569 out: 2573 out:
2570 rcu_read_unlock(); 2574 rcu_read_unlock();
2571 2575
2572 return skb; 2576 return skb;
2573 } 2577 }
2574 EXPORT_SYMBOL(ieee80211_get_buffered_bc); 2578 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
2575 2579
2576 void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) 2580 void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
2577 { 2581 {
2578 skb_set_mac_header(skb, 0); 2582 skb_set_mac_header(skb, 0);
2579 skb_set_network_header(skb, 0); 2583 skb_set_network_header(skb, 0);
2580 skb_set_transport_header(skb, 0); 2584 skb_set_transport_header(skb, 0);
2581 2585
2582 /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */ 2586 /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
2583 skb_set_queue_mapping(skb, IEEE80211_AC_VO); 2587 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2584 skb->priority = 7; 2588 skb->priority = 7;
2585 2589
2586 /* 2590 /*
2587 * The other path calling ieee80211_xmit is from the tasklet, 2591 * The other path calling ieee80211_xmit is from the tasklet,
2588 * and while we can handle concurrent transmissions locking 2592 * and while we can handle concurrent transmissions locking
2589 * requirements are that we do not come into tx with bhs on. 2593 * requirements are that we do not come into tx with bhs on.
2590 */ 2594 */
2591 local_bh_disable(); 2595 local_bh_disable();
2592 ieee80211_xmit(sdata, skb); 2596 ieee80211_xmit(sdata, skb);
2593 local_bh_enable(); 2597 local_bh_enable();
2594 } 2598 }
2595 2599