blob: 465457653eb321163a1e07674388f1dbcb7571b1 [file] [log] [blame]
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001/* src/prism2/driver/prism2mgmt.c
2*
3* Management request handler functions.
4*
5* Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6* --------------------------------------------------------------------
7*
8* linux-wlan
9*
10* The contents of this file are subject to the Mozilla Public
11* License Version 1.1 (the "License"); you may not use this file
12* except in compliance with the License. You may obtain a copy of
13* the License at http://www.mozilla.org/MPL/
14*
15* Software distributed under the License is distributed on an "AS
16* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17* implied. See the License for the specific language governing
18* rights and limitations under the License.
19*
20* Alternatively, the contents of this file may be used under the
21* terms of the GNU Public License version 2 (the "GPL"), in which
22* case the provisions of the GPL are applicable instead of the
23* above. If you wish to allow the use of your version of this file
24* only under the terms of the GPL and not to allow others to use
25* your version of this file under the MPL, indicate your decision
26* by deleting the provisions above and replace them with the notice
27* and other provisions required by the GPL. If you do not delete
28* the provisions above, a recipient may use your version of this
29* file under either the MPL or the GPL.
30*
31* --------------------------------------------------------------------
32*
33* Inquiries regarding the linux-wlan Open Source project can be
34* made directly to:
35*
36* AbsoluteValue Systems Inc.
37* info@linux-wlan.com
38* http://www.linux-wlan.com
39*
40* --------------------------------------------------------------------
41*
42* Portions of the development of this software were funded by
43* Intersil Corporation as part of PRISM(R) chipset product development.
44*
45* --------------------------------------------------------------------
46*
47* The functions in this file handle management requests sent from
48* user mode.
49*
50* Most of these functions have two separate blocks of code that are
51* conditional on whether this is a station or an AP. This is used
52* to separate out the STA and AP responses to these management primitives.
53* It's a choice (good, bad, indifferent?) to have the code in the same
54* place so it's clear that the same primitive is implemented in both
55* cases but has different behavior.
56*
57* --------------------------------------------------------------------
58*/
59
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070060#include <linux/if_arp.h>
61#include <linux/module.h>
62#include <linux/kernel.h>
63#include <linux/wait.h>
64#include <linux/sched.h>
65#include <linux/types.h>
66#include <linux/slab.h>
67#include <linux/wireless.h>
68#include <linux/netdevice.h>
69#include <linux/delay.h>
70#include <asm/io.h>
71#include <asm/byteorder.h>
72#include <linux/random.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070073#include <linux/usb.h>
Moritz Muehlenhoff7f6e0e42009-01-25 21:54:55 +010074#include <linux/bitops.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070075
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070076/*================================================================*/
77/* Project Includes */
78
79#include "p80211types.h"
80#include "p80211hdr.h"
81#include "p80211mgmt.h"
82#include "p80211conv.h"
83#include "p80211msg.h"
84#include "p80211netdev.h"
85#include "p80211metadef.h"
86#include "p80211metastruct.h"
87#include "hfa384x.h"
88#include "prism2mgmt.h"
89
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070090/* Converts 802.11 format rate specifications to prism2 */
Moritz Muehlenhoff7f6e0e42009-01-25 21:54:55 +010091#define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
92 (((n)&~BIT(7)) == 4) ? BIT(1) : \
93 (((n)&~BIT(7)) == 11) ? BIT(2) : \
94 (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070095
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070096/*----------------------------------------------------------------
97* prism2mgmt_scan
98*
99* Initiate a scan for BSSs.
100*
101* This function corresponds to MLME-scan.request and part of
102* MLME-scan.confirm. As far as I can tell in the standard, there
103* are no restrictions on when a scan.request may be issued. We have
104* to handle in whatever state the driver/MAC happen to be.
105*
106* Arguments:
107* wlandev wlan device structure
108* msgp ptr to msg buffer
109*
110* Returns:
111* 0 success and done
112* <0 success, but we're waiting for something to finish.
113* >0 an error occurred while handling the message.
114* Side effects:
115*
116* Call context:
117* process thread (usually)
118* interrupt
119----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530120int prism2mgmt_scan(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700121{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100122 int result = 0;
123 hfa384x_t *hw = wlandev->priv;
124 p80211msg_dot11req_scan_t *msg = msgp;
125 u16 roamingmode, word;
126 int i, timeout;
127 int istmpenable = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700128
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100129 hfa384x_HostScanRequest_data_t scanreq;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700130
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100131 /* gatekeeper check */
132 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
133 hw->ident_sta_fw.minor,
134 hw->ident_sta_fw.variant) <
135 HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
136 printk(KERN_ERR
137 "HostScan not supported with current firmware (<1.3.2).\n");
138 result = 1;
139 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700140 goto exit;
141 }
142
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100143 memset(&scanreq, 0, sizeof(scanreq));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700144
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100145 /* save current roaming mode */
146 result = hfa384x_drvr_getconfig16(hw,
147 HFA384x_RID_CNFROAMINGMODE,
148 &roamingmode);
149 if (result) {
150 printk(KERN_ERR "getconfig(ROAMMODE) failed. result=%d\n",
151 result);
152 msg->resultcode.data =
153 P80211ENUM_resultcode_implementation_failure;
154 goto exit;
155 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700156
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100157 /* drop into mode 3 for the scan */
158 result = hfa384x_drvr_setconfig16(hw,
159 HFA384x_RID_CNFROAMINGMODE,
160 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
161 if (result) {
162 printk(KERN_ERR "setconfig(ROAMINGMODE) failed. result=%d\n",
163 result);
164 msg->resultcode.data =
165 P80211ENUM_resultcode_implementation_failure;
166 goto exit;
167 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700168
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100169 /* active or passive? */
170 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
171 hw->ident_sta_fw.minor,
172 hw->ident_sta_fw.variant) >
173 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
174 if (msg->scantype.data != P80211ENUM_scantype_active)
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100175 word = cpu_to_le16(msg->maxchanneltime.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100176 else
177 word = 0;
178
179 result =
180 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
181 word);
182 if (result) {
183 printk(KERN_WARNING "Passive scan not supported with "
184 "current firmware. (<1.5.1)\n");
185 }
186 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700187
188 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
189 word = HFA384x_RATEBIT_2;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100190 scanreq.txRate = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700191
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100192 /* set up the channel list */
193 word = 0;
194 for (i = 0; i < msg->channellist.data.len; i++) {
195 u8 channel = msg->channellist.data.data[i];
196 if (channel > 14)
197 continue;
198 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
199 word |= (1 << (channel - 1));
200 }
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100201 scanreq.channelList = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700202
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100203 /* set up the ssid, if present. */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100204 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100205 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700206
207 /* Enable the MAC port if it's not already enabled */
208 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100209 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100210 printk(KERN_ERR "getconfig(PORTSTATUS) failed. "
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100211 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700212 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100213 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700214 goto exit;
215 }
216 if (word == HFA384x_PORTSTATUS_DISABLED) {
Solomon Peachyaaad4302008-10-29 10:42:53 -0400217 u16 wordbuf[17];
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700218
219 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100220 HFA384x_RID_CNFROAMINGMODE,
221 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
222 if (result) {
223 printk(KERN_ERR
224 "setconfig(ROAMINGMODE) failed. result=%d\n",
225 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700226 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100227 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700228 goto exit;
229 }
230 /* Construct a bogus SSID and assign it to OwnSSID and
231 * DesiredSSID
232 */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100233 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700234 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100235 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
236 wordbuf,
237 HFA384x_RID_CNFOWNSSID_LEN);
238 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100239 printk(KERN_ERR "Failed to set OwnSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700240 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100241 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700242 goto exit;
243 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100244 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
245 wordbuf,
246 HFA384x_RID_CNFDESIREDSSID_LEN);
247 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100248 printk(KERN_ERR "Failed to set DesiredSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700249 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100250 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700251 goto exit;
252 }
253 /* bsstype */
254 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100255 HFA384x_RID_CNFPORTTYPE,
256 HFA384x_PORTTYPE_IBSS);
257 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100258 printk(KERN_ERR "Failed to set CNFPORTTYPE.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700259 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100260 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700261 goto exit;
262 }
263 /* ibss options */
264 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100265 HFA384x_RID_CREATEIBSS,
266 HFA384x_CREATEIBSS_JOINCREATEIBSS);
267 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100268 printk(KERN_ERR "Failed to set CREATEIBSS.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700269 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100270 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700271 goto exit;
272 }
273 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100274 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100275 printk(KERN_ERR "drvr_enable(0) failed. "
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100276 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700277 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100278 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700279 goto exit;
280 }
281 istmpenable = 1;
282 }
283
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100284 /* Figure out our timeout first Kus, then HZ */
285 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
286 timeout = (timeout * HZ) / 1000;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700287
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100288 /* Issue the scan request */
289 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700290
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100291 result = hfa384x_drvr_setconfig(hw,
292 HFA384x_RID_HOSTSCAN, &scanreq,
293 sizeof(hfa384x_HostScanRequest_data_t));
294 if (result) {
295 printk(KERN_ERR "setconfig(SCANREQUEST) failed. result=%d\n",
296 result);
297 msg->resultcode.data =
298 P80211ENUM_resultcode_implementation_failure;
299 goto exit;
300 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700301
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100302 /* sleep until info frame arrives */
303 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700304
305 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
306 if (hw->scanflag == -1)
307 hw->scanflag = 0;
308
309 msg->numbss.data = hw->scanflag;
310
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100311 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700312
313 /* Disable port if we temporarily enabled it. */
314 if (istmpenable) {
315 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100316 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100317 printk(KERN_ERR "drvr_disable(0) failed. "
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100318 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700319 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100320 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700321 goto exit;
322 }
323 }
324
325 /* restore original roaming mode */
326 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
327 roamingmode);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100328 if (result) {
329 printk(KERN_ERR "setconfig(ROAMMODE) failed. result=%d\n",
330 result);
331 msg->resultcode.data =
332 P80211ENUM_resultcode_implementation_failure;
333 goto exit;
334 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700335
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100336 result = 0;
337 msg->resultcode.data = P80211ENUM_resultcode_success;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700338
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100339exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700340 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
341
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700342 return result;
343}
344
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700345/*----------------------------------------------------------------
346* prism2mgmt_scan_results
347*
348* Retrieve the BSS description for one of the BSSs identified in
349* a scan.
350*
351* Arguments:
352* wlandev wlan device structure
353* msgp ptr to msg buffer
354*
355* Returns:
356* 0 success and done
357* <0 success, but we're waiting for something to finish.
358* >0 an error occurred while handling the message.
359* Side effects:
360*
361* Call context:
362* process thread (usually)
363* interrupt
364----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530365int prism2mgmt_scan_results(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700366{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100367 int result = 0;
368 p80211msg_dot11req_scan_results_t *req;
369 hfa384x_t *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700370 hfa384x_HScanResultSub_t *item = NULL;
371
372 int count;
373
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100374 req = (p80211msg_dot11req_scan_results_t *) msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700375
376 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
377
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100378 if (!hw->scanresults) {
379 printk(KERN_ERR
380 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700381 result = 2;
382 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
383 goto exit;
384 }
385
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100386 count = (hw->scanresults->framelen - 3) / 32;
387 if (count > 32)
388 count = 32;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700389
390 if (req->bssindex.data >= count) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100391 pr_debug("requested index (%d) out of range (%d)\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530392 req->bssindex.data, count);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700393 result = 2;
394 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
395 goto exit;
396 }
397
398 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
399 /* signal and noise */
400 req->signal.status = P80211ENUM_msgitem_status_data_ok;
401 req->noise.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100402 req->signal.data = le16_to_cpu(item->sl);
403 req->noise.data = le16_to_cpu(item->anl);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700404
405 /* BSSID */
406 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
407 req->bssid.data.len = WLAN_BSSID_LEN;
408 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
409
410 /* SSID */
411 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100412 req->ssid.data.len = le16_to_cpu(item->ssid.len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700413 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
414
415 /* supported rates */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100416 for (count = 0; count < 10; count++)
417 if (item->supprates[count] == 0)
418 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700419
420#define REQBASICRATE(N) \
421 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
422 req->basicrate ## N .data = item->supprates[(N)-1]; \
423 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
424 }
425
426 REQBASICRATE(1);
427 REQBASICRATE(2);
428 REQBASICRATE(3);
429 REQBASICRATE(4);
430 REQBASICRATE(5);
431 REQBASICRATE(6);
432 REQBASICRATE(7);
433 REQBASICRATE(8);
434
435#define REQSUPPRATE(N) \
436 if (count >= N) { \
437 req->supprate ## N .data = item->supprates[(N)-1]; \
438 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
439 }
440
441 REQSUPPRATE(1);
442 REQSUPPRATE(2);
443 REQSUPPRATE(3);
444 REQSUPPRATE(4);
445 REQSUPPRATE(5);
446 REQSUPPRATE(6);
447 REQSUPPRATE(7);
448 REQSUPPRATE(8);
449
450 /* beacon period */
451 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100452 req->beaconperiod.data = le16_to_cpu(item->bcnint);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700453
454 /* timestamps */
455 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
456 req->timestamp.data = jiffies;
457 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
458 req->localtime.data = jiffies;
459
460 /* atim window */
461 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100462 req->ibssatimwindow.data = le16_to_cpu(item->atim);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700463
464 /* Channel */
465 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100466 req->dschannel.data = le16_to_cpu(item->chid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700467
468 /* capinfo bits */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100469 count = le16_to_cpu(item->capinfo);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700470
471 /* privacy flag */
472 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
473 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
474
475 /* cfpollable */
476 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
477 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
478
479 /* cfpollreq */
480 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
481 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
482
483 /* bsstype */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100484 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700485 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100486 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700487
488 result = 0;
489 req->resultcode.data = P80211ENUM_resultcode_success;
490
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100491exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700492 return result;
493}
494
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700495/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700496* prism2mgmt_start
497*
498* Start a BSS. Any station can do this for IBSS, only AP for ESS.
499*
500* Arguments:
501* wlandev wlan device structure
502* msgp ptr to msg buffer
503*
504* Returns:
505* 0 success and done
506* <0 success, but we're waiting for something to finish.
507* >0 an error occurred while handling the message.
508* Side effects:
509*
510* Call context:
511* process thread (usually)
512* interrupt
513----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530514int prism2mgmt_start(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700515{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100516 int result = 0;
517 hfa384x_t *hw = wlandev->priv;
518 p80211msg_dot11req_start_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700519
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100520 p80211pstrd_t *pstr;
521 u8 bytebuf[80];
522 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
523 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700524
525 wlandev->macmode = WLAN_MACMODE_NONE;
526
527 /* Set the SSID */
528 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
529
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400530 /*** ADHOC IBSS ***/
531 /* see if current f/w is less than 8c3 */
532 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
533 hw->ident_sta_fw.minor,
534 hw->ident_sta_fw.variant) <
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100535 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400536 /* Ad-Hoc not quite supported on Prism2 */
537 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
538 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700539 goto done;
540 }
541
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700542 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
543
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400544 /*** STATION ***/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700545 /* Set the REQUIRED config items */
546 /* SSID */
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530547 pstr = (p80211pstrd_t *) & (msg->ssid.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700548 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100549 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
550 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
551 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100552 printk(KERN_ERR "Failed to set CnfOwnSSID\n");
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400553 goto failed;
554 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100555 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
556 bytebuf,
557 HFA384x_RID_CNFDESIREDSSID_LEN);
558 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100559 printk(KERN_ERR "Failed to set CnfDesiredSSID\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700560 goto failed;
561 }
562
563 /* bsstype - we use the default in the ap firmware */
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400564 /* IBSS port */
565 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700566
567 /* beacon period */
568 word = msg->beaconperiod.data;
Solomon Peachyaaad4302008-10-29 10:42:53 -0400569 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100570 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100571 printk(KERN_ERR "Failed to set beacon period=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700572 goto failed;
573 }
574
575 /* dschannel */
576 word = msg->dschannel.data;
577 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100578 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100579 printk(KERN_ERR "Failed to set channel=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700580 goto failed;
581 }
582 /* Basic rates */
583 word = p80211rate_to_p2bit(msg->basicrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100584 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700585 word |= p80211rate_to_p2bit(msg->basicrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100586
587 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700588 word |= p80211rate_to_p2bit(msg->basicrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100589
590 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700591 word |= p80211rate_to_p2bit(msg->basicrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100592
593 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700594 word |= p80211rate_to_p2bit(msg->basicrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100595
596 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700597 word |= p80211rate_to_p2bit(msg->basicrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100598
599 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700600 word |= p80211rate_to_p2bit(msg->basicrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100601
602 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700603 word |= p80211rate_to_p2bit(msg->basicrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100604
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700605 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100606 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100607 printk(KERN_ERR "Failed to set basicrates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700608 goto failed;
609 }
610
611 /* Operational rates (supprates and txratecontrol) */
612 word = p80211rate_to_p2bit(msg->operationalrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100613 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700614 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100615
616 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700617 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100618
619 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700620 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100621
622 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700623 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100624
625 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700626 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100627
628 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700629 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100630
631 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700632 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100633
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700634 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100635 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100636 printk(KERN_ERR "Failed to set supprates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700637 goto failed;
638 }
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400639
640 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100641 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100642 printk(KERN_ERR "Failed to set txrates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700643 goto failed;
644 }
645
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700646 /* Set the macmode so the frame setup code knows what to do */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100647 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400648 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700649 /* lets extend the data length a bit */
650 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
651 }
652
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700653 /* Enable the Port */
654 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100655 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100656 printk(KERN_ERR "Enable macport failed, result=%d.\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700657 goto failed;
658 }
659
660 msg->resultcode.data = P80211ENUM_resultcode_success;
661
662 goto done;
663failed:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100664 pr_debug("Failed to set a config option, result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700665 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
666
667done:
668 result = 0;
669
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700670 return result;
671}
672
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700673/*----------------------------------------------------------------
674* prism2mgmt_readpda
675*
676* Collect the PDA data and put it in the message.
677*
678* Arguments:
679* wlandev wlan device structure
680* msgp ptr to msg buffer
681*
682* Returns:
683* 0 success and done
684* <0 success, but we're waiting for something to finish.
685* >0 an error occurred while handling the message.
686* Side effects:
687*
688* Call context:
689* process thread (usually)
690----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530691int prism2mgmt_readpda(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700692{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100693 hfa384x_t *hw = wlandev->priv;
694 p80211msg_p2req_readpda_t *msg = msgp;
695 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700696
697 /* We only support collecting the PDA when in the FWLOAD
698 * state.
699 */
700 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100701 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100702 "PDA may only be read " "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700703 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100704 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700705 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
706 } else {
707 /* Call drvr_readpda(), it handles the auxport enable
708 * and validating the returned PDA.
709 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100710 result = hfa384x_drvr_readpda(hw,
711 msg->pda.data,
712 HFA384x_PDA_LEN_MAX);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700713 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100714 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100715 "hfa384x_drvr_readpda() failed, "
716 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700717
718 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100719 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700720 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100721 P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700722 return 0;
723 }
724 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
725 msg->resultcode.data = P80211ENUM_resultcode_success;
726 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
727 }
728
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700729 return 0;
730}
731
732/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700733* prism2mgmt_ramdl_state
734*
735* Establishes the beginning/end of a card RAM download session.
736*
737* It is expected that the ramdl_write() function will be called
738* one or more times between the 'enable' and 'disable' calls to
739* this function.
740*
741* Note: This function should not be called when a mac comm port
742* is active.
743*
744* Arguments:
745* wlandev wlan device structure
746* msgp ptr to msg buffer
747*
748* Returns:
749* 0 success and done
750* <0 success, but we're waiting for something to finish.
751* >0 an error occurred while handling the message.
752* Side effects:
753*
754* Call context:
755* process thread (usually)
756----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530757int prism2mgmt_ramdl_state(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700758{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100759 hfa384x_t *hw = wlandev->priv;
760 p80211msg_p2req_ramdl_state_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700761
762 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100763 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100764 "ramdl_state(): may only be called "
765 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700766 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100767 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700768 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700769 return 0;
770 }
771
772 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100773 ** Note: Interrupts are locked out if this is an AP and are NOT
774 ** locked out if this is a station.
775 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700776
777 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100778 if (msg->enable.data == P80211ENUM_truth_true) {
779 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
780 msg->resultcode.data =
781 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700782 } else {
783 msg->resultcode.data = P80211ENUM_resultcode_success;
784 }
785 } else {
786 hfa384x_drvr_ramdl_disable(hw);
787 msg->resultcode.data = P80211ENUM_resultcode_success;
788 }
789
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700790 return 0;
791}
792
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700793/*----------------------------------------------------------------
794* prism2mgmt_ramdl_write
795*
796* Writes a buffer to the card RAM using the download state. This
797* is for writing code to card RAM. To just read or write raw data
798* use the aux functions.
799*
800* Arguments:
801* wlandev wlan device structure
802* msgp ptr to msg buffer
803*
804* Returns:
805* 0 success and done
806* <0 success, but we're waiting for something to finish.
807* >0 an error occurred while handling the message.
808* Side effects:
809*
810* Call context:
811* process thread (usually)
812----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530813int prism2mgmt_ramdl_write(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700814{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100815 hfa384x_t *hw = wlandev->priv;
816 p80211msg_p2req_ramdl_write_t *msg = msgp;
817 u32 addr;
818 u32 len;
819 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700820
821 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100822 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100823 "ramdl_write(): may only be called "
824 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700825 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100826 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700827 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700828 return 0;
829 }
830
831 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
832 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100833 if (msg->len.data > sizeof(msg->data.data)) {
834 msg->resultcode.status =
835 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700836 return 0;
837 }
838 /* call the hfa384x function to do the write */
839 addr = msg->addr.data;
840 len = msg->len.data;
841 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100842 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700843 msg->resultcode.data = P80211ENUM_resultcode_refused;
844
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700845 msg->resultcode.data = P80211ENUM_resultcode_success;
846
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700847 return 0;
848}
849
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700850/*----------------------------------------------------------------
851* prism2mgmt_flashdl_state
852*
853* Establishes the beginning/end of a card Flash download session.
854*
855* It is expected that the flashdl_write() function will be called
856* one or more times between the 'enable' and 'disable' calls to
857* this function.
858*
859* Note: This function should not be called when a mac comm port
860* is active.
861*
862* Arguments:
863* wlandev wlan device structure
864* msgp ptr to msg buffer
865*
866* Returns:
867* 0 success and done
868* <0 success, but we're waiting for something to finish.
869* >0 an error occurred while handling the message.
870* Side effects:
871*
872* Call context:
873* process thread (usually)
874----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530875int prism2mgmt_flashdl_state(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700876{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100877 int result = 0;
878 hfa384x_t *hw = wlandev->priv;
879 p80211msg_p2req_flashdl_state_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700880
881 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100882 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100883 "flashdl_state(): may only be called "
884 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700885 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100886 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700887 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700888 return 0;
889 }
890
891 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100892 ** Note: Interrupts are locked out if this is an AP and are NOT
893 ** locked out if this is a station.
894 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700895
896 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100897 if (msg->enable.data == P80211ENUM_truth_true) {
898 if (hfa384x_drvr_flashdl_enable(hw)) {
899 msg->resultcode.data =
900 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700901 } else {
902 msg->resultcode.data = P80211ENUM_resultcode_success;
903 }
904 } else {
905 hfa384x_drvr_flashdl_disable(hw);
906 msg->resultcode.data = P80211ENUM_resultcode_success;
907 /* NOTE: At this point, the MAC is in the post-reset
908 * state and the driver is in the fwload state.
909 * We need to get the MAC back into the fwload
910 * state. To do this, we set the nsdstate to HWPRESENT
911 * and then call the ifstate function to redo everything
912 * that got us into the fwload state.
913 */
914 wlandev->msdstate = WLAN_MSD_HWPRESENT;
915 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
916 if (result != P80211ENUM_resultcode_success) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100917 printk(KERN_ERR "prism2sta_ifstate(fwload) failed,"
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100918 "P80211ENUM_resultcode=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700919 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100920 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700921 result = -1;
922 }
923 }
924
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700925 return 0;
926}
927
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700928/*----------------------------------------------------------------
929* prism2mgmt_flashdl_write
930*
931*
932*
933* Arguments:
934* wlandev wlan device structure
935* msgp ptr to msg buffer
936*
937* Returns:
938* 0 success and done
939* <0 success, but we're waiting for something to finish.
940* >0 an error occurred while handling the message.
941* Side effects:
942*
943* Call context:
944* process thread (usually)
945----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530946int prism2mgmt_flashdl_write(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700947{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100948 hfa384x_t *hw = wlandev->priv;
949 p80211msg_p2req_flashdl_write_t *msg = msgp;
950 u32 addr;
951 u32 len;
952 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700953
954 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100955 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100956 "flashdl_write(): may only be called "
957 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700958 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100959 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700960 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700961 return 0;
962 }
963
964 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100965 ** Note: Interrupts are locked out if this is an AP and are NOT
966 ** locked out if this is a station.
967 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700968
969 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
970 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100971 if (msg->len.data > sizeof(msg->data.data)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700972 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100973 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700974 return 0;
975 }
976 /* call the hfa384x function to do the write */
977 addr = msg->addr.data;
978 len = msg->len.data;
979 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100980 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700981 msg->resultcode.data = P80211ENUM_resultcode_refused;
982
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700983 msg->resultcode.data = P80211ENUM_resultcode_success;
984
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700985 return 0;
986}
987
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700988/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700989* prism2mgmt_autojoin
990*
991* Associate with an ESS.
992*
993* Arguments:
994* wlandev wlan device structure
995* msgp ptr to msg buffer
996*
997* Returns:
998* 0 success and done
999* <0 success, but we're waiting for something to finish.
1000* >0 an error occurred while handling the message.
1001* Side effects:
1002*
1003* Call context:
1004* process thread (usually)
1005* interrupt
1006----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301007int prism2mgmt_autojoin(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001008{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001009 hfa384x_t *hw = wlandev->priv;
1010 int result = 0;
1011 u16 reg;
1012 u16 port_type;
1013 p80211msg_lnxreq_autojoin_t *msg = msgp;
1014 p80211pstrd_t *pstr;
1015 u8 bytebuf[256];
1016 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001017
1018 wlandev->macmode = WLAN_MACMODE_NONE;
1019
1020 /* Set the SSID */
1021 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1022
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001023 /* Disable the Port */
1024 hfa384x_drvr_disable(hw, 0);
1025
1026 /*** STATION ***/
1027 /* Set the TxRates */
1028 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1029
1030 /* Set the auth type */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001031 if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001032 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001033 else
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001034 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001035
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001036 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1037
1038 /* Set the ssid */
1039 memset(bytebuf, 0, 256);
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301040 pstr = (p80211pstrd_t *) & (msg->ssid.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001041 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001042 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1043 bytebuf,
1044 HFA384x_RID_CNFDESIREDSSID_LEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001045 port_type = HFA384x_PORTTYPE_BSS;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001046 /* Set the PortType */
1047 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1048
1049 /* Enable the Port */
1050 hfa384x_drvr_enable(hw, 0);
1051
1052 /* Set the resultcode */
1053 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1054 msg->resultcode.data = P80211ENUM_resultcode_success;
1055
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001056 return result;
1057}
1058
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001059/*----------------------------------------------------------------
1060* prism2mgmt_wlansniff
1061*
1062* Start or stop sniffing.
1063*
1064* Arguments:
1065* wlandev wlan device structure
1066* msgp ptr to msg buffer
1067*
1068* Returns:
1069* 0 success and done
1070* <0 success, but we're waiting for something to finish.
1071* >0 an error occurred while handling the message.
1072* Side effects:
1073*
1074* Call context:
1075* process thread (usually)
1076* interrupt
1077----------------------------------------------------------------*/
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301078int prism2mgmt_wlansniff(wlandevice_t * wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001079{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001080 int result = 0;
1081 p80211msg_lnxreq_wlansniff_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001082
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001083 hfa384x_t *hw = wlandev->priv;
1084 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001085
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001086 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001087 switch (msg->enable.data) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001088 case P80211ENUM_truth_false:
1089 /* Confirm that we're in monitor mode */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001090 if (wlandev->netdev->type == ARPHRD_ETHER) {
1091 msg->resultcode.data =
1092 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001093 result = 0;
1094 goto exit;
1095 }
1096 /* Disable monitor mode */
1097 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001098 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301099 pr_debug("failed to disable monitor mode, result=%d\n",
1100 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001101 goto failed;
1102 }
1103 /* Disable port 0 */
1104 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001105 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301106 pr_debug
1107 ("failed to disable port 0 after sniffing, result=%d\n",
1108 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001109 goto failed;
1110 }
1111 /* Clear the driver state */
1112 wlandev->netdev->type = ARPHRD_ETHER;
1113
1114 /* Restore the wepflags */
1115 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001116 HFA384x_RID_CNFWEPFLAGS,
1117 hw->presniff_wepflags);
1118 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301119 pr_debug
1120 ("failed to restore wepflags=0x%04x, result=%d\n",
1121 hw->presniff_wepflags, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001122 goto failed;
1123 }
1124
1125 /* Set the port to its prior type and enable (if necessary) */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001126 if (hw->presniff_port_type != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001127 word = hw->presniff_port_type;
1128 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001129 HFA384x_RID_CNFPORTTYPE,
1130 word);
1131 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301132 pr_debug
1133 ("failed to restore porttype, result=%d\n",
1134 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001135 goto failed;
1136 }
1137
1138 /* Enable the port */
1139 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001140 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301141 pr_debug
1142 ("failed to enable port to presniff setting, result=%d\n",
1143 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001144 goto failed;
1145 }
1146 } else {
1147 result = hfa384x_drvr_disable(hw, 0);
1148
1149 }
1150
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01001151 printk(KERN_INFO "monitor mode disabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001152 msg->resultcode.data = P80211ENUM_resultcode_success;
1153 result = 0;
1154 goto exit;
1155 break;
1156 case P80211ENUM_truth_true:
1157 /* Disable the port (if enabled), only check Port 0 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001158 if (hw->port_enabled[0]) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001159 if (wlandev->netdev->type == ARPHRD_ETHER) {
1160 /* Save macport 0 state */
1161 result = hfa384x_drvr_getconfig16(hw,
1162 HFA384x_RID_CNFPORTTYPE,
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301163 &
1164 (hw->
1165 presniff_port_type));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001166 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301167 pr_debug
1168 ("failed to read porttype, result=%d\n",
1169 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001170 goto failed;
1171 }
1172 /* Save the wepflags state */
1173 result = hfa384x_drvr_getconfig16(hw,
1174 HFA384x_RID_CNFWEPFLAGS,
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301175 &
1176 (hw->
1177 presniff_wepflags));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001178 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301179 pr_debug
1180 ("failed to read wepflags, result=%d\n",
1181 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001182 goto failed;
1183 }
1184 hfa384x_drvr_stop(hw);
1185 result = hfa384x_drvr_start(hw);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001186 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301187 pr_debug
1188 ("failed to restart the card for sniffing, result=%d\n",
1189 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001190 goto failed;
1191 }
1192 } else {
1193 /* Disable the port */
1194 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001195 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301196 pr_debug
1197 ("failed to enable port for sniffing, result=%d\n",
1198 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001199 goto failed;
1200 }
1201 }
1202 } else {
1203 hw->presniff_port_type = 0;
1204 }
1205
1206 /* Set the channel we wish to sniff */
1207 word = msg->channel.data;
1208 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001209 HFA384x_RID_CNFOWNCHANNEL,
1210 word);
1211 hw->sniff_channel = word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001212
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001213 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301214 pr_debug("failed to set channel %d, result=%d\n",
1215 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001216 goto failed;
1217 }
1218
1219 /* Now if we're already sniffing, we can skip the rest */
1220 if (wlandev->netdev->type != ARPHRD_ETHER) {
1221 /* Set the port type to pIbss */
1222 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1223 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001224 HFA384x_RID_CNFPORTTYPE,
1225 word);
1226 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301227 pr_debug
1228 ("failed to set porttype %d, result=%d\n",
1229 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001230 goto failed;
1231 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001232 if ((msg->keepwepflags.status ==
1233 P80211ENUM_msgitem_status_data_ok)
1234 && (msg->keepwepflags.data !=
1235 P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001236 /* Set the wepflags for no decryption */
1237 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001238 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1239 result =
1240 hfa384x_drvr_setconfig16(hw,
1241 HFA384x_RID_CNFWEPFLAGS,
1242 word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001243 }
1244
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001245 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301246 pr_debug
1247 ("failed to set wepflags=0x%04x, result=%d\n",
1248 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001249 goto failed;
1250 }
1251 }
1252
1253 /* Do we want to strip the FCS in monitor mode? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001254 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1255 && (msg->stripfcs.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001256 hw->sniff_fcs = 0;
1257 } else {
1258 hw->sniff_fcs = 1;
1259 }
1260
1261 /* Do we want to truncate the packets? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001262 if (msg->packet_trunc.status ==
1263 P80211ENUM_msgitem_status_data_ok) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001264 hw->sniff_truncate = msg->packet_trunc.data;
1265 } else {
1266 hw->sniff_truncate = 0;
1267 }
1268
1269 /* Enable the port */
1270 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001271 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301272 pr_debug
1273 ("failed to enable port for sniffing, result=%d\n",
1274 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001275 goto failed;
1276 }
1277 /* Enable monitor mode */
1278 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001279 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301280 pr_debug("failed to enable monitor mode, result=%d\n",
1281 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001282 goto failed;
1283 }
1284
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001285 if (wlandev->netdev->type == ARPHRD_ETHER)
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01001286 printk(KERN_INFO "monitor mode enabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001287
1288 /* Set the driver state */
1289 /* Do we want the prism2 header? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001290 if ((msg->prismheader.status ==
1291 P80211ENUM_msgitem_status_data_ok)
1292 && (msg->prismheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001293 hw->sniffhdr = 0;
1294 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001295 } else
1296 if ((msg->wlanheader.status ==
1297 P80211ENUM_msgitem_status_data_ok)
1298 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001299 hw->sniffhdr = 1;
1300 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1301 } else {
1302 wlandev->netdev->type = ARPHRD_IEEE80211;
1303 }
1304
1305 msg->resultcode.data = P80211ENUM_resultcode_success;
1306 result = 0;
1307 goto exit;
1308 break;
1309 default:
1310 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1311 result = 0;
1312 goto exit;
1313 break;
1314 }
1315
1316failed:
1317 msg->resultcode.data = P80211ENUM_resultcode_refused;
1318 result = 0;
1319exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001320 return result;
1321}