blob: 26c35253be334266680a01aa1579f794945b779f [file] [log] [blame]
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +09001/*
Johannes Berg370121e2006-01-04 16:32:16 +01002 * Some parts based on code from net80211
3 * Copyright (c) 2001 Atsushi Onoe
4 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090032 *
Johannes Berg370121e2006-01-04 16:32:16 +010033 */
34
35#include "ieee80211softmac_priv.h"
36
37/* Helper functions for inserting data into the frames */
38
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090039/*
Johannes Berg370121e2006-01-04 16:32:16 +010040 * Adds an ESSID element to the frame
41 *
42 */
43static u8 *
44ieee80211softmac_add_essid(u8 *dst, struct ieee80211softmac_essid *essid)
45{
46 if (essid) {
47 *dst++ = MFIE_TYPE_SSID;
48 *dst++ = essid->len;
49 memcpy(dst, essid->data, essid->len);
50 return dst+essid->len;
51 } else {
52 *dst++ = MFIE_TYPE_SSID;
53 *dst++ = 0;
54 return dst;
55 }
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090056}
Johannes Berg370121e2006-01-04 16:32:16 +010057
58/* Adds Supported Rates and if required Extended Rates Information Element
59 * to the frame, ASSUMES WE HAVE A SORTED LIST OF RATES */
60static u8 *
61ieee80211softmac_frame_add_rates(u8 *dst, const struct ieee80211softmac_ratesinfo *r)
62{
63 int cck_len, ofdm_len;
64 *dst++ = MFIE_TYPE_RATES;
65
66 for(cck_len=0; ieee80211_is_cck_rate(r->rates[cck_len]) && (cck_len < r->count);cck_len++);
67
68 if(cck_len > IEEE80211SOFTMAC_MAX_RATES_LEN)
69 cck_len = IEEE80211SOFTMAC_MAX_RATES_LEN;
70 *dst++ = cck_len;
71 memcpy(dst, r->rates, cck_len);
72 dst += cck_len;
73
74 if(cck_len < r->count){
75 for (ofdm_len=0; ieee80211_is_ofdm_rate(r->rates[ofdm_len + cck_len]) && (ofdm_len + cck_len < r->count); ofdm_len++);
76 if (ofdm_len > 0) {
77 if (ofdm_len > IEEE80211SOFTMAC_MAX_EX_RATES_LEN)
78 ofdm_len = IEEE80211SOFTMAC_MAX_EX_RATES_LEN;
79 *dst++ = MFIE_TYPE_RATES_EX;
80 *dst++ = ofdm_len;
81 memcpy(dst, r->rates + cck_len, ofdm_len);
82 dst += ofdm_len;
83 }
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090084 }
Johannes Berg370121e2006-01-04 16:32:16 +010085 return dst;
86}
87
88/* Allocate a management frame */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090089static u8 *
Johannes Berg370121e2006-01-04 16:32:16 +010090ieee80211softmac_alloc_mgt(u32 size)
91{
92 u8 * data;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090093
Johannes Berg370121e2006-01-04 16:32:16 +010094 /* Add the header and FCS to the size */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +090095 size = size + IEEE80211_3ADDR_LEN;
Johannes Berg370121e2006-01-04 16:32:16 +010096 if(size > IEEE80211_DATA_LEN)
97 return NULL;
98 /* Allocate the frame */
Panagiotis Issaris0da974f2006-07-21 14:51:30 -070099 data = kzalloc(size, GFP_ATOMIC);
Johannes Berg370121e2006-01-04 16:32:16 +0100100 return data;
101}
102
103/*
104 * Add a 2 Address Header
105 */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900106static void
Johannes Berg370121e2006-01-04 16:32:16 +0100107ieee80211softmac_hdr_2addr(struct ieee80211softmac_device *mac,
108 struct ieee80211_hdr_2addr *header, u32 type, u8 *dest)
109{
110 /* Fill in the frame control flags */
111 header->frame_ctl = cpu_to_le16(type);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900112 /* Control packets always have WEP turned off */
Johannes Berg370121e2006-01-04 16:32:16 +0100113 if(type > IEEE80211_STYPE_CFENDACK && type < IEEE80211_STYPE_PSPOLL)
114 header->frame_ctl |= mac->ieee->sec.level ? cpu_to_le16(IEEE80211_FCTL_PROTECTED) : 0;
115
116 /* Fill in the duration */
117 header->duration_id = 0;
118 /* FIXME: How do I find this?
119 * calculate. But most drivers just fill in 0 (except if it's a station id of course) */
120
121 /* Fill in the Destination Address */
122 if(dest == NULL)
123 memset(header->addr1, 0xFF, ETH_ALEN);
124 else
125 memcpy(header->addr1, dest, ETH_ALEN);
126 /* Fill in the Source Address */
127 memcpy(header->addr2, mac->ieee->dev->dev_addr, ETH_ALEN);
128
129}
130
131
132/* Add a 3 Address Header */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900133static void
Johannes Berg370121e2006-01-04 16:32:16 +0100134ieee80211softmac_hdr_3addr(struct ieee80211softmac_device *mac,
135 struct ieee80211_hdr_3addr *header, u32 type, u8 *dest, u8 *bssid)
136{
137 /* This is common with 2addr, so use that instead */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900138 ieee80211softmac_hdr_2addr(mac, (struct ieee80211_hdr_2addr *)header, type, dest);
139
Johannes Berg370121e2006-01-04 16:32:16 +0100140 /* Fill in the BSS ID */
141 if(bssid == NULL)
142 memset(header->addr3, 0xFF, ETH_ALEN);
143 else
144 memcpy(header->addr3, bssid, ETH_ALEN);
145
146 /* Fill in the sequence # */
147 /* FIXME: I need to add this to the softmac struct
148 * shouldn't the sequence number be in ieee80211? */
149}
150
Joseph Jezakc4b3d1b2006-06-01 17:12:49 +0100151static u16
152ieee80211softmac_capabilities(struct ieee80211softmac_device *mac,
153 struct ieee80211softmac_network *net)
154{
155 u16 capability = 0;
156
157 /* ESS and IBSS bits are set according to the current mode */
158 switch (mac->ieee->iw_mode) {
159 case IW_MODE_INFRA:
160 capability = cpu_to_le16(WLAN_CAPABILITY_ESS);
161 break;
162 case IW_MODE_ADHOC:
163 capability = cpu_to_le16(WLAN_CAPABILITY_IBSS);
164 break;
165 case IW_MODE_AUTO:
166 capability = net->capabilities &
167 (WLAN_CAPABILITY_ESS|WLAN_CAPABILITY_IBSS);
168 break;
169 default:
170 /* bleh. we don't ever go to these modes */
171 printk(KERN_ERR PFX "invalid iw_mode!\n");
172 break;
173 }
174
175 /* CF Pollable / CF Poll Request */
176 /* Needs to be implemented, for now, the 0's == not supported */
177
178 /* Privacy Bit */
179 capability |= mac->ieee->sec.level ?
180 cpu_to_le16(WLAN_CAPABILITY_PRIVACY) : 0;
181
182 /* Short Preamble */
183 /* Always supported: we probably won't ever be powering devices which
184 * dont support this... */
185 capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
186
187 /* PBCC */
188 /* Not widely used */
189
190 /* Channel Agility */
191 /* Not widely used */
192
193 /* Short Slot */
194 /* Will be implemented later */
195
196 /* DSSS-OFDM */
197 /* Not widely used */
198
199 return capability;
200}
Johannes Berg370121e2006-01-04 16:32:16 +0100201
202/*****************************************************************************
203 * Create Management packets
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900204 *****************************************************************************/
Johannes Berg370121e2006-01-04 16:32:16 +0100205
206/* Creates an association request packet */
Johannes Berg714e1a52006-01-04 21:06:28 +0100207static u32
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900208ieee80211softmac_assoc_req(struct ieee80211_assoc_request **pkt,
Johannes Berg370121e2006-01-04 16:32:16 +0100209 struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net)
210{
211 u8 *data;
212 (*pkt) = (struct ieee80211_assoc_request *)ieee80211softmac_alloc_mgt(
213 2 + /* Capability Info */
214 2 + /* Listen Interval */
215 /* SSID IE */
216 1 + 1 + IW_ESSID_MAX_SIZE +
217 /* Rates IE */
218 1 + 1 + IEEE80211SOFTMAC_MAX_RATES_LEN +
219 /* Extended Rates IE */
220 1 + 1 + IEEE80211SOFTMAC_MAX_EX_RATES_LEN +
221 /* WPA IE if present */
222 mac->wpa.IElen
223 /* Other IE's? Optional?
224 * Yeah, probably need an extra IE parameter -- lots of vendors like to
225 * fill in their own IEs */
226 );
227 if (unlikely((*pkt) == NULL))
228 return 0;
229 ieee80211softmac_hdr_3addr(mac, &((*pkt)->header), IEEE80211_STYPE_ASSOC_REQ, net->bssid, net->bssid);
230
Larry Finger6d41e262006-06-20 09:19:18 -0500231 /* Fill in the capabilities */
232 (*pkt)->capability = ieee80211softmac_capabilities(mac, net);
233
Johannes Berg370121e2006-01-04 16:32:16 +0100234 /* Fill in Listen Interval (?) */
235 (*pkt)->listen_interval = cpu_to_le16(10);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900236
Johannes Berg370121e2006-01-04 16:32:16 +0100237 data = (u8 *)(*pkt)->info_element;
238 /* Add SSID */
239 data = ieee80211softmac_add_essid(data, &net->essid);
240 /* Add Rates */
241 data = ieee80211softmac_frame_add_rates(data, &mac->ratesinfo);
242 /* Add WPA IE */
243 if (mac->wpa.IElen && mac->wpa.IE) {
244 memcpy(data, mac->wpa.IE, mac->wpa.IElen);
245 data += mac->wpa.IElen;
246 }
247 /* Return the number of used bytes */
248 return (data - (u8*)(*pkt));
249}
250
251/* Create a reassociation request packet */
Johannes Berg714e1a52006-01-04 21:06:28 +0100252static u32
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900253ieee80211softmac_reassoc_req(struct ieee80211_reassoc_request **pkt,
Johannes Berg370121e2006-01-04 16:32:16 +0100254 struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net)
255{
256 u8 *data;
257 (*pkt) = (struct ieee80211_reassoc_request *)ieee80211softmac_alloc_mgt(
258 2 + /* Capability Info */
259 2 + /* Listen Interval */
260 ETH_ALEN + /* AP MAC */
261 /* SSID IE */
262 1 + 1 + IW_ESSID_MAX_SIZE +
263 /* Rates IE */
264 1 + 1 + IEEE80211SOFTMAC_MAX_RATES_LEN +
265 /* Extended Rates IE */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900266 1 + 1 + IEEE80211SOFTMAC_MAX_EX_RATES_LEN
Johannes Berg370121e2006-01-04 16:32:16 +0100267 /* Other IE's? */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900268 );
Johannes Berg370121e2006-01-04 16:32:16 +0100269 if (unlikely((*pkt) == NULL))
270 return 0;
271 ieee80211softmac_hdr_3addr(mac, &((*pkt)->header), IEEE80211_STYPE_REASSOC_REQ, net->bssid, net->bssid);
272
Joseph Jezakc4b3d1b2006-06-01 17:12:49 +0100273 /* Fill in the capabilities */
274 (*pkt)->capability = ieee80211softmac_capabilities(mac, net);
275
Johannes Berg370121e2006-01-04 16:32:16 +0100276 /* Fill in Listen Interval (?) */
277 (*pkt)->listen_interval = cpu_to_le16(10);
278 /* Fill in the current AP MAC */
279 memcpy((*pkt)->current_ap, mac->ieee->bssid, ETH_ALEN);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900280
Johannes Berg370121e2006-01-04 16:32:16 +0100281 data = (u8 *)(*pkt)->info_element;
282 /* Add SSID */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900283 data = ieee80211softmac_add_essid(data, &net->essid);
Johannes Berg370121e2006-01-04 16:32:16 +0100284 /* Add Rates */
285 data = ieee80211softmac_frame_add_rates(data, &mac->ratesinfo);
286 /* Return packet size */
287 return (data - (u8 *)(*pkt));
288}
289
290/* Create an authentication packet */
Johannes Berg714e1a52006-01-04 21:06:28 +0100291static u32
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900292ieee80211softmac_auth(struct ieee80211_auth **pkt,
Johannes Berg370121e2006-01-04 16:32:16 +0100293 struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net,
Daniel Drake76ea4c72006-06-01 15:34:26 +0100294 u16 transaction, u16 status, int *encrypt_mpdu)
Johannes Berg370121e2006-01-04 16:32:16 +0100295{
296 u8 *data;
Daniel Drake76ea4c72006-06-01 15:34:26 +0100297 int auth_mode = mac->ieee->sec.auth_mode;
298 int is_shared_response = (auth_mode == WLAN_AUTH_SHARED_KEY
299 && transaction == IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE);
300
Johannes Berg370121e2006-01-04 16:32:16 +0100301 /* Allocate Packet */
302 (*pkt) = (struct ieee80211_auth *)ieee80211softmac_alloc_mgt(
303 2 + /* Auth Algorithm */
304 2 + /* Auth Transaction Seq */
305 2 + /* Status Code */
306 /* Challenge Text IE */
Laurent Riffard6684e592006-10-12 00:17:36 +0200307 (is_shared_response ? 1 + 1 + net->challenge_len : 0)
Daniel Drake76ea4c72006-06-01 15:34:26 +0100308 );
Johannes Berg370121e2006-01-04 16:32:16 +0100309 if (unlikely((*pkt) == NULL))
310 return 0;
311 ieee80211softmac_hdr_3addr(mac, &((*pkt)->header), IEEE80211_STYPE_AUTH, net->bssid, net->bssid);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900312
Johannes Berg370121e2006-01-04 16:32:16 +0100313 /* Algorithm */
Daniel Drake76ea4c72006-06-01 15:34:26 +0100314 (*pkt)->algorithm = cpu_to_le16(auth_mode);
Johannes Berg370121e2006-01-04 16:32:16 +0100315 /* Transaction */
316 (*pkt)->transaction = cpu_to_le16(transaction);
317 /* Status */
318 (*pkt)->status = cpu_to_le16(status);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900319
Johannes Berg370121e2006-01-04 16:32:16 +0100320 data = (u8 *)(*pkt)->info_element;
321 /* Challenge Text */
Daniel Drake76ea4c72006-06-01 15:34:26 +0100322 if (is_shared_response) {
Johannes Berg370121e2006-01-04 16:32:16 +0100323 *data = MFIE_TYPE_CHALLENGE;
324 data++;
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900325
Johannes Berg370121e2006-01-04 16:32:16 +0100326 /* Copy the challenge in */
Daniel Drake76ea4c72006-06-01 15:34:26 +0100327 *data = net->challenge_len;
328 data++;
329 memcpy(data, net->challenge, net->challenge_len);
330 data += net->challenge_len;
331
332 /* Make sure this frame gets encrypted with the shared key */
333 *encrypt_mpdu = 1;
334 } else
335 *encrypt_mpdu = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100336
337 /* Return the packet size */
338 return (data - (u8 *)(*pkt));
339}
340
341/* Create a disassocation or deauthentication packet */
Johannes Berg714e1a52006-01-04 21:06:28 +0100342static u32
Johannes Berg370121e2006-01-04 16:32:16 +0100343ieee80211softmac_disassoc_deauth(struct ieee80211_disassoc **pkt,
344 struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net,
345 u16 type, u16 reason)
346{
347 /* Allocate Packet */
348 (*pkt) = (struct ieee80211_disassoc *)ieee80211softmac_alloc_mgt(2);
Johannes Bergbba52d52006-01-11 11:01:22 +0100349 if (unlikely((*pkt) == NULL))
Johannes Berg370121e2006-01-04 16:32:16 +0100350 return 0;
351 ieee80211softmac_hdr_3addr(mac, &((*pkt)->header), type, net->bssid, net->bssid);
352 /* Reason */
353 (*pkt)->reason = cpu_to_le16(reason);
354 /* Return the packet size */
355 return (2 + IEEE80211_3ADDR_LEN);
356}
357
358/* Create a probe request packet */
Johannes Berg714e1a52006-01-04 21:06:28 +0100359static u32
Johannes Berg370121e2006-01-04 16:32:16 +0100360ieee80211softmac_probe_req(struct ieee80211_probe_request **pkt,
361 struct ieee80211softmac_device *mac, struct ieee80211softmac_essid *essid)
362{
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900363 u8 *data;
Johannes Berg370121e2006-01-04 16:32:16 +0100364 /* Allocate Packet */
365 (*pkt) = (struct ieee80211_probe_request *)ieee80211softmac_alloc_mgt(
366 /* SSID of requested network */
367 1 + 1 + IW_ESSID_MAX_SIZE +
368 /* Rates IE */
369 1 + 1 + IEEE80211SOFTMAC_MAX_RATES_LEN +
370 /* Extended Rates IE */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900371 1 + 1 + IEEE80211SOFTMAC_MAX_EX_RATES_LEN
Johannes Berg370121e2006-01-04 16:32:16 +0100372 );
373 if (unlikely((*pkt) == NULL))
374 return 0;
375 ieee80211softmac_hdr_3addr(mac, &((*pkt)->header), IEEE80211_STYPE_PROBE_REQ, NULL, NULL);
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900376
Johannes Berg370121e2006-01-04 16:32:16 +0100377 data = (u8 *)(*pkt)->info_element;
378 /* Add ESSID (can be NULL) */
379 data = ieee80211softmac_add_essid(data, essid);
380 /* Add Rates */
381 data = ieee80211softmac_frame_add_rates(data, &mac->ratesinfo);
382 /* Return packet size */
383 return (data - (u8 *)(*pkt));
384}
385
386/* Create a probe response packet */
387/* FIXME: Not complete */
Johannes Berg714e1a52006-01-04 21:06:28 +0100388static u32
Johannes Berg370121e2006-01-04 16:32:16 +0100389ieee80211softmac_probe_resp(struct ieee80211_probe_response **pkt,
390 struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net)
391{
392 u8 *data;
393 /* Allocate Packet */
394 (*pkt) = (struct ieee80211_probe_response *)ieee80211softmac_alloc_mgt(
395 8 + /* Timestamp */
396 2 + /* Beacon Interval */
397 2 + /* Capability Info */
398 /* SSID IE */
399 1 + 1 + IW_ESSID_MAX_SIZE +
400 7 + /* FH Parameter Set */
401 2 + /* DS Parameter Set */
402 8 + /* CF Parameter Set */
403 4 /* IBSS Parameter Set */
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900404 );
Johannes Berg370121e2006-01-04 16:32:16 +0100405 if (unlikely((*pkt) == NULL))
406 return 0;
407 ieee80211softmac_hdr_3addr(mac, &((*pkt)->header), IEEE80211_STYPE_PROBE_RESP, net->bssid, net->bssid);
408 data = (u8 *)(*pkt)->info_element;
409
410 /* Return the packet size */
411 return (data - (u8 *)(*pkt));
412}
413
414
415/* Sends a manangement packet
416 * FIXME: document the use of the arg parameter
417 * for _AUTH: (transaction #) | (status << 16)
418 */
419int
420ieee80211softmac_send_mgt_frame(struct ieee80211softmac_device *mac,
421 void *ptrarg, u32 type, u32 arg)
422{
423 void *pkt = NULL;
424 u32 pkt_size = 0;
Daniel Drake76ea4c72006-06-01 15:34:26 +0100425 int encrypt_mpdu = 0;
Johannes Berg370121e2006-01-04 16:32:16 +0100426
427 switch(type) {
428 case IEEE80211_STYPE_ASSOC_REQ:
429 pkt_size = ieee80211softmac_assoc_req((struct ieee80211_assoc_request **)(&pkt), mac, (struct ieee80211softmac_network *)ptrarg);
430 break;
431 case IEEE80211_STYPE_REASSOC_REQ:
432 pkt_size = ieee80211softmac_reassoc_req((struct ieee80211_reassoc_request **)(&pkt), mac, (struct ieee80211softmac_network *)ptrarg);
433 break;
434 case IEEE80211_STYPE_AUTH:
Daniel Drake76ea4c72006-06-01 15:34:26 +0100435 pkt_size = ieee80211softmac_auth((struct ieee80211_auth **)(&pkt), mac, (struct ieee80211softmac_network *)ptrarg, (u16)(arg & 0xFFFF), (u16) (arg >> 16), &encrypt_mpdu);
Johannes Berg370121e2006-01-04 16:32:16 +0100436 break;
437 case IEEE80211_STYPE_DISASSOC:
438 case IEEE80211_STYPE_DEAUTH:
439 pkt_size = ieee80211softmac_disassoc_deauth((struct ieee80211_disassoc **)(&pkt), mac, (struct ieee80211softmac_network *)ptrarg, type, (u16)(arg & 0xFFFF));
440 break;
441 case IEEE80211_STYPE_PROBE_REQ:
442 pkt_size = ieee80211softmac_probe_req((struct ieee80211_probe_request **)(&pkt), mac, (struct ieee80211softmac_essid *)ptrarg);
443 break;
444 case IEEE80211_STYPE_PROBE_RESP:
445 pkt_size = ieee80211softmac_probe_resp((struct ieee80211_probe_response **)(&pkt), mac, (struct ieee80211softmac_network *)ptrarg);
446 break;
447 default:
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900448 printkl(KERN_DEBUG PFX "Unsupported Management Frame type: %i\n", type);
449 return -EINVAL;
Johannes Berg370121e2006-01-04 16:32:16 +0100450 };
451
452 if(pkt_size == 0 || pkt == NULL) {
453 printkl(KERN_DEBUG PFX "Error, packet is nonexistant or 0 length\n");
454 return -ENOMEM;
455 }
YOSHIFUJI Hideaki64265652007-02-09 23:24:46 +0900456
Johannes Berg370121e2006-01-04 16:32:16 +0100457 /* Send the packet to the ieee80211 layer for tx */
458 /* we defined softmac->mgmt_xmit for this. Should we keep it
459 * as it is (that means we'd need to wrap this into a txb),
460 * modify the prototype (so it matches this function),
461 * or get rid of it alltogether?
462 * Does this work for you now?
463 */
Daniel Drake76ea4c72006-06-01 15:34:26 +0100464 ieee80211_tx_frame(mac->ieee, (struct ieee80211_hdr *)pkt,
465 IEEE80211_3ADDR_LEN, pkt_size, encrypt_mpdu);
Johannes Berg370121e2006-01-04 16:32:16 +0100466
467 kfree(pkt);
468 return 0;
469}
Daniel Drake5acd0c42006-07-18 21:33:27 +0100470
471/* Beacon handling */
472int ieee80211softmac_handle_beacon(struct net_device *dev,
473 struct ieee80211_beacon *beacon,
474 struct ieee80211_network *network)
475{
476 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
477
Michael Buesch7c28ad22006-09-27 15:26:33 +0300478 /* This might race, but we don't really care and it's not worth
479 * adding heavyweight locking in this fastpath.
480 */
481 if (mac->associnfo.associated) {
482 if (memcmp(network->bssid, mac->associnfo.bssid, ETH_ALEN) == 0)
483 ieee80211softmac_process_erp(mac, network->erp_value);
484 }
Daniel Drake5acd0c42006-07-18 21:33:27 +0100485
486 return 0;
487}
488