blob: ad163da72ae466d1a5de12cefdb73e29fe2c67a5 [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>
Andrew Elwellef1a0ed2010-02-18 23:56:12 +010070#include <linux/io.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070071#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#include "p80211types.h"
77#include "p80211hdr.h"
78#include "p80211mgmt.h"
79#include "p80211conv.h"
80#include "p80211msg.h"
81#include "p80211netdev.h"
82#include "p80211metadef.h"
83#include "p80211metastruct.h"
84#include "hfa384x.h"
85#include "prism2mgmt.h"
86
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070087/* Converts 802.11 format rate specifications to prism2 */
Moritz Muehlenhoff7f6e0e42009-01-25 21:54:55 +010088#define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
89 (((n)&~BIT(7)) == 4) ? BIT(1) : \
90 (((n)&~BIT(7)) == 11) ? BIT(2) : \
91 (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070092
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070093/*----------------------------------------------------------------
94* prism2mgmt_scan
95*
96* Initiate a scan for BSSs.
97*
98* This function corresponds to MLME-scan.request and part of
99* MLME-scan.confirm. As far as I can tell in the standard, there
100* are no restrictions on when a scan.request may be issued. We have
101* to handle in whatever state the driver/MAC happen to be.
102*
103* Arguments:
104* wlandev wlan device structure
105* msgp ptr to msg buffer
106*
107* Returns:
108* 0 success and done
109* <0 success, but we're waiting for something to finish.
110* >0 an error occurred while handling the message.
111* Side effects:
112*
113* Call context:
114* process thread (usually)
115* interrupt
116----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530117int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700118{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100119 int result = 0;
120 hfa384x_t *hw = wlandev->priv;
121 p80211msg_dot11req_scan_t *msg = msgp;
122 u16 roamingmode, word;
123 int i, timeout;
124 int istmpenable = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700125
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100126 hfa384x_HostScanRequest_data_t scanreq;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700127
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100128 /* gatekeeper check */
129 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
130 hw->ident_sta_fw.minor,
131 hw->ident_sta_fw.variant) <
132 HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
133 printk(KERN_ERR
134 "HostScan not supported with current firmware (<1.3.2).\n");
135 result = 1;
136 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700137 goto exit;
138 }
139
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100140 memset(&scanreq, 0, sizeof(scanreq));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700141
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100142 /* save current roaming mode */
143 result = hfa384x_drvr_getconfig16(hw,
144 HFA384x_RID_CNFROAMINGMODE,
145 &roamingmode);
146 if (result) {
147 printk(KERN_ERR "getconfig(ROAMMODE) failed. result=%d\n",
148 result);
149 msg->resultcode.data =
150 P80211ENUM_resultcode_implementation_failure;
151 goto exit;
152 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700153
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100154 /* drop into mode 3 for the scan */
155 result = hfa384x_drvr_setconfig16(hw,
156 HFA384x_RID_CNFROAMINGMODE,
157 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
158 if (result) {
159 printk(KERN_ERR "setconfig(ROAMINGMODE) failed. result=%d\n",
160 result);
161 msg->resultcode.data =
162 P80211ENUM_resultcode_implementation_failure;
163 goto exit;
164 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700165
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100166 /* active or passive? */
167 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
168 hw->ident_sta_fw.minor,
169 hw->ident_sta_fw.variant) >
170 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
171 if (msg->scantype.data != P80211ENUM_scantype_active)
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100172 word = cpu_to_le16(msg->maxchanneltime.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100173 else
174 word = 0;
175
176 result =
177 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
178 word);
179 if (result) {
180 printk(KERN_WARNING "Passive scan not supported with "
181 "current firmware. (<1.5.1)\n");
182 }
183 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700184
185 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
186 word = HFA384x_RATEBIT_2;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100187 scanreq.txRate = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700188
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100189 /* set up the channel list */
190 word = 0;
191 for (i = 0; i < msg->channellist.data.len; i++) {
192 u8 channel = msg->channellist.data.data[i];
193 if (channel > 14)
194 continue;
195 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
196 word |= (1 << (channel - 1));
197 }
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100198 scanreq.channelList = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700199
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100200 /* set up the ssid, if present. */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100201 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100202 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700203
204 /* Enable the MAC port if it's not already enabled */
205 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100206 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100207 printk(KERN_ERR "getconfig(PORTSTATUS) failed. "
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100208 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700209 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100210 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700211 goto exit;
212 }
213 if (word == HFA384x_PORTSTATUS_DISABLED) {
Solomon Peachyaaad4302008-10-29 10:42:53 -0400214 u16 wordbuf[17];
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700215
216 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100217 HFA384x_RID_CNFROAMINGMODE,
218 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
219 if (result) {
220 printk(KERN_ERR
221 "setconfig(ROAMINGMODE) failed. result=%d\n",
222 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700223 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100224 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700225 goto exit;
226 }
227 /* Construct a bogus SSID and assign it to OwnSSID and
228 * DesiredSSID
229 */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100230 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700231 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100232 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
233 wordbuf,
234 HFA384x_RID_CNFOWNSSID_LEN);
235 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100236 printk(KERN_ERR "Failed to set OwnSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700237 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100238 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700239 goto exit;
240 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100241 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
242 wordbuf,
243 HFA384x_RID_CNFDESIREDSSID_LEN);
244 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100245 printk(KERN_ERR "Failed to set DesiredSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700246 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100247 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700248 goto exit;
249 }
250 /* bsstype */
251 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100252 HFA384x_RID_CNFPORTTYPE,
253 HFA384x_PORTTYPE_IBSS);
254 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100255 printk(KERN_ERR "Failed to set CNFPORTTYPE.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700256 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100257 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700258 goto exit;
259 }
260 /* ibss options */
261 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100262 HFA384x_RID_CREATEIBSS,
263 HFA384x_CREATEIBSS_JOINCREATEIBSS);
264 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100265 printk(KERN_ERR "Failed to set CREATEIBSS.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700266 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100267 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700268 goto exit;
269 }
270 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100271 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100272 printk(KERN_ERR "drvr_enable(0) failed. "
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100273 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700274 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100275 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700276 goto exit;
277 }
278 istmpenable = 1;
279 }
280
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100281 /* Figure out our timeout first Kus, then HZ */
282 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
283 timeout = (timeout * HZ) / 1000;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700284
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100285 /* Issue the scan request */
286 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700287
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100288 result = hfa384x_drvr_setconfig(hw,
289 HFA384x_RID_HOSTSCAN, &scanreq,
290 sizeof(hfa384x_HostScanRequest_data_t));
291 if (result) {
292 printk(KERN_ERR "setconfig(SCANREQUEST) failed. result=%d\n",
293 result);
294 msg->resultcode.data =
295 P80211ENUM_resultcode_implementation_failure;
296 goto exit;
297 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700298
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100299 /* sleep until info frame arrives */
300 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700301
302 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
303 if (hw->scanflag == -1)
304 hw->scanflag = 0;
305
306 msg->numbss.data = hw->scanflag;
307
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100308 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700309
310 /* Disable port if we temporarily enabled it. */
311 if (istmpenable) {
312 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100313 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100314 printk(KERN_ERR "drvr_disable(0) failed. "
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100315 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700316 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100317 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700318 goto exit;
319 }
320 }
321
322 /* restore original roaming mode */
323 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
324 roamingmode);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100325 if (result) {
326 printk(KERN_ERR "setconfig(ROAMMODE) failed. result=%d\n",
327 result);
328 msg->resultcode.data =
329 P80211ENUM_resultcode_implementation_failure;
330 goto exit;
331 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700332
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100333 result = 0;
334 msg->resultcode.data = P80211ENUM_resultcode_success;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700335
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100336exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700337 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
338
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700339 return result;
340}
341
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700342/*----------------------------------------------------------------
343* prism2mgmt_scan_results
344*
345* Retrieve the BSS description for one of the BSSs identified in
346* a scan.
347*
348* Arguments:
349* wlandev wlan device structure
350* msgp ptr to msg buffer
351*
352* Returns:
353* 0 success and done
354* <0 success, but we're waiting for something to finish.
355* >0 an error occurred while handling the message.
356* Side effects:
357*
358* Call context:
359* process thread (usually)
360* interrupt
361----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530362int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700363{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100364 int result = 0;
365 p80211msg_dot11req_scan_results_t *req;
366 hfa384x_t *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700367 hfa384x_HScanResultSub_t *item = NULL;
368
369 int count;
370
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100371 req = (p80211msg_dot11req_scan_results_t *) msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700372
373 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
374
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100375 if (!hw->scanresults) {
376 printk(KERN_ERR
377 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700378 result = 2;
379 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
380 goto exit;
381 }
382
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100383 count = (hw->scanresults->framelen - 3) / 32;
384 if (count > 32)
385 count = 32;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700386
387 if (req->bssindex.data >= count) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100388 pr_debug("requested index (%d) out of range (%d)\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530389 req->bssindex.data, count);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700390 result = 2;
391 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
392 goto exit;
393 }
394
395 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
396 /* signal and noise */
397 req->signal.status = P80211ENUM_msgitem_status_data_ok;
398 req->noise.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100399 req->signal.data = le16_to_cpu(item->sl);
400 req->noise.data = le16_to_cpu(item->anl);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700401
402 /* BSSID */
403 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
404 req->bssid.data.len = WLAN_BSSID_LEN;
405 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
406
407 /* SSID */
408 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100409 req->ssid.data.len = le16_to_cpu(item->ssid.len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700410 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
411
412 /* supported rates */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100413 for (count = 0; count < 10; count++)
414 if (item->supprates[count] == 0)
415 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700416
417#define REQBASICRATE(N) \
418 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
419 req->basicrate ## N .data = item->supprates[(N)-1]; \
420 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \
421 }
422
423 REQBASICRATE(1);
424 REQBASICRATE(2);
425 REQBASICRATE(3);
426 REQBASICRATE(4);
427 REQBASICRATE(5);
428 REQBASICRATE(6);
429 REQBASICRATE(7);
430 REQBASICRATE(8);
431
432#define REQSUPPRATE(N) \
433 if (count >= N) { \
434 req->supprate ## N .data = item->supprates[(N)-1]; \
435 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \
436 }
437
438 REQSUPPRATE(1);
439 REQSUPPRATE(2);
440 REQSUPPRATE(3);
441 REQSUPPRATE(4);
442 REQSUPPRATE(5);
443 REQSUPPRATE(6);
444 REQSUPPRATE(7);
445 REQSUPPRATE(8);
446
447 /* beacon period */
448 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100449 req->beaconperiod.data = le16_to_cpu(item->bcnint);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700450
451 /* timestamps */
452 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
453 req->timestamp.data = jiffies;
454 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
455 req->localtime.data = jiffies;
456
457 /* atim window */
458 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100459 req->ibssatimwindow.data = le16_to_cpu(item->atim);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700460
461 /* Channel */
462 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100463 req->dschannel.data = le16_to_cpu(item->chid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700464
465 /* capinfo bits */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100466 count = le16_to_cpu(item->capinfo);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700467
468 /* privacy flag */
469 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
470 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
471
472 /* cfpollable */
473 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
474 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
475
476 /* cfpollreq */
477 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
478 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
479
480 /* bsstype */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100481 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700482 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100483 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700484
485 result = 0;
486 req->resultcode.data = P80211ENUM_resultcode_success;
487
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100488exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700489 return result;
490}
491
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700492/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700493* prism2mgmt_start
494*
495* Start a BSS. Any station can do this for IBSS, only AP for ESS.
496*
497* Arguments:
498* wlandev wlan device structure
499* msgp ptr to msg buffer
500*
501* Returns:
502* 0 success and done
503* <0 success, but we're waiting for something to finish.
504* >0 an error occurred while handling the message.
505* Side effects:
506*
507* Call context:
508* process thread (usually)
509* interrupt
510----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530511int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700512{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100513 int result = 0;
514 hfa384x_t *hw = wlandev->priv;
515 p80211msg_dot11req_start_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700516
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100517 p80211pstrd_t *pstr;
518 u8 bytebuf[80];
519 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
520 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700521
522 wlandev->macmode = WLAN_MACMODE_NONE;
523
524 /* Set the SSID */
525 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
526
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400527 /*** ADHOC IBSS ***/
528 /* see if current f/w is less than 8c3 */
529 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
530 hw->ident_sta_fw.minor,
531 hw->ident_sta_fw.variant) <
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100532 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400533 /* Ad-Hoc not quite supported on Prism2 */
534 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
535 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700536 goto done;
537 }
538
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700539 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
540
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400541 /*** STATION ***/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700542 /* Set the REQUIRED config items */
543 /* SSID */
Andrew Elwellef1a0ed2010-02-18 23:56:12 +0100544 pstr = (p80211pstrd_t *) &(msg->ssid.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700545 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100546 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
547 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
548 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100549 printk(KERN_ERR "Failed to set CnfOwnSSID\n");
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400550 goto failed;
551 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100552 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
553 bytebuf,
554 HFA384x_RID_CNFDESIREDSSID_LEN);
555 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100556 printk(KERN_ERR "Failed to set CnfDesiredSSID\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700557 goto failed;
558 }
559
560 /* bsstype - we use the default in the ap firmware */
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400561 /* IBSS port */
562 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700563
564 /* beacon period */
565 word = msg->beaconperiod.data;
Solomon Peachyaaad4302008-10-29 10:42:53 -0400566 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100567 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100568 printk(KERN_ERR "Failed to set beacon period=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700569 goto failed;
570 }
571
572 /* dschannel */
573 word = msg->dschannel.data;
574 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100575 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100576 printk(KERN_ERR "Failed to set channel=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700577 goto failed;
578 }
579 /* Basic rates */
580 word = p80211rate_to_p2bit(msg->basicrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100581 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700582 word |= p80211rate_to_p2bit(msg->basicrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100583
584 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700585 word |= p80211rate_to_p2bit(msg->basicrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100586
587 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700588 word |= p80211rate_to_p2bit(msg->basicrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100589
590 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700591 word |= p80211rate_to_p2bit(msg->basicrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100592
593 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700594 word |= p80211rate_to_p2bit(msg->basicrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100595
596 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700597 word |= p80211rate_to_p2bit(msg->basicrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100598
599 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700600 word |= p80211rate_to_p2bit(msg->basicrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100601
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700602 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100603 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100604 printk(KERN_ERR "Failed to set basicrates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700605 goto failed;
606 }
607
608 /* Operational rates (supprates and txratecontrol) */
609 word = p80211rate_to_p2bit(msg->operationalrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100610 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700611 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100612
613 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700614 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100615
616 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700617 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100618
619 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700620 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100621
622 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700623 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100624
625 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700626 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100627
628 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700629 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100630
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700631 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100632 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100633 printk(KERN_ERR "Failed to set supprates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700634 goto failed;
635 }
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400636
637 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100638 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100639 printk(KERN_ERR "Failed to set txrates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700640 goto failed;
641 }
642
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700643 /* Set the macmode so the frame setup code knows what to do */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100644 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400645 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700646 /* lets extend the data length a bit */
647 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
648 }
649
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700650 /* Enable the Port */
651 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100652 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100653 printk(KERN_ERR "Enable macport failed, result=%d.\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700654 goto failed;
655 }
656
657 msg->resultcode.data = P80211ENUM_resultcode_success;
658
659 goto done;
660failed:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100661 pr_debug("Failed to set a config option, result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700662 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
663
664done:
665 result = 0;
666
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700667 return result;
668}
669
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700670/*----------------------------------------------------------------
671* prism2mgmt_readpda
672*
673* Collect the PDA data and put it in the message.
674*
675* Arguments:
676* wlandev wlan device structure
677* msgp ptr to msg buffer
678*
679* Returns:
680* 0 success and done
681* <0 success, but we're waiting for something to finish.
682* >0 an error occurred while handling the message.
683* Side effects:
684*
685* Call context:
686* process thread (usually)
687----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530688int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700689{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100690 hfa384x_t *hw = wlandev->priv;
691 p80211msg_p2req_readpda_t *msg = msgp;
692 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700693
694 /* We only support collecting the PDA when in the FWLOAD
695 * state.
696 */
697 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100698 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100699 "PDA may only be read " "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700700 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100701 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700702 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
703 } else {
704 /* Call drvr_readpda(), it handles the auxport enable
705 * and validating the returned PDA.
706 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100707 result = hfa384x_drvr_readpda(hw,
708 msg->pda.data,
709 HFA384x_PDA_LEN_MAX);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700710 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100711 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100712 "hfa384x_drvr_readpda() failed, "
713 "result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700714
715 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100716 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700717 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100718 P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700719 return 0;
720 }
721 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
722 msg->resultcode.data = P80211ENUM_resultcode_success;
723 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
724 }
725
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700726 return 0;
727}
728
729/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700730* prism2mgmt_ramdl_state
731*
732* Establishes the beginning/end of a card RAM download session.
733*
734* It is expected that the ramdl_write() function will be called
735* one or more times between the 'enable' and 'disable' calls to
736* this function.
737*
738* Note: This function should not be called when a mac comm port
739* is active.
740*
741* Arguments:
742* wlandev wlan device structure
743* msgp ptr to msg buffer
744*
745* Returns:
746* 0 success and done
747* <0 success, but we're waiting for something to finish.
748* >0 an error occurred while handling the message.
749* Side effects:
750*
751* Call context:
752* process thread (usually)
753----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530754int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700755{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100756 hfa384x_t *hw = wlandev->priv;
757 p80211msg_p2req_ramdl_state_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700758
759 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100760 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100761 "ramdl_state(): may only be called "
762 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700763 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100764 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700765 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700766 return 0;
767 }
768
769 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100770 ** Note: Interrupts are locked out if this is an AP and are NOT
771 ** locked out if this is a station.
772 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700773
774 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100775 if (msg->enable.data == P80211ENUM_truth_true) {
776 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
777 msg->resultcode.data =
778 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700779 } else {
780 msg->resultcode.data = P80211ENUM_resultcode_success;
781 }
782 } else {
783 hfa384x_drvr_ramdl_disable(hw);
784 msg->resultcode.data = P80211ENUM_resultcode_success;
785 }
786
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700787 return 0;
788}
789
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700790/*----------------------------------------------------------------
791* prism2mgmt_ramdl_write
792*
793* Writes a buffer to the card RAM using the download state. This
794* is for writing code to card RAM. To just read or write raw data
795* use the aux functions.
796*
797* Arguments:
798* wlandev wlan device structure
799* msgp ptr to msg buffer
800*
801* Returns:
802* 0 success and done
803* <0 success, but we're waiting for something to finish.
804* >0 an error occurred while handling the message.
805* Side effects:
806*
807* Call context:
808* process thread (usually)
809----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530810int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700811{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100812 hfa384x_t *hw = wlandev->priv;
813 p80211msg_p2req_ramdl_write_t *msg = msgp;
814 u32 addr;
815 u32 len;
816 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700817
818 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100819 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100820 "ramdl_write(): may only be called "
821 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700822 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100823 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700824 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700825 return 0;
826 }
827
828 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
829 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100830 if (msg->len.data > sizeof(msg->data.data)) {
831 msg->resultcode.status =
832 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700833 return 0;
834 }
835 /* call the hfa384x function to do the write */
836 addr = msg->addr.data;
837 len = msg->len.data;
838 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100839 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700840 msg->resultcode.data = P80211ENUM_resultcode_refused;
841
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700842 msg->resultcode.data = P80211ENUM_resultcode_success;
843
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700844 return 0;
845}
846
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700847/*----------------------------------------------------------------
848* prism2mgmt_flashdl_state
849*
850* Establishes the beginning/end of a card Flash download session.
851*
852* It is expected that the flashdl_write() function will be called
853* one or more times between the 'enable' and 'disable' calls to
854* this function.
855*
856* Note: This function should not be called when a mac comm port
857* is active.
858*
859* Arguments:
860* wlandev wlan device structure
861* msgp ptr to msg buffer
862*
863* Returns:
864* 0 success and done
865* <0 success, but we're waiting for something to finish.
866* >0 an error occurred while handling the message.
867* Side effects:
868*
869* Call context:
870* process thread (usually)
871----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530872int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700873{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100874 int result = 0;
875 hfa384x_t *hw = wlandev->priv;
876 p80211msg_p2req_flashdl_state_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700877
878 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100879 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100880 "flashdl_state(): may only be called "
881 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700882 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100883 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700884 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700885 return 0;
886 }
887
888 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100889 ** Note: Interrupts are locked out if this is an AP and are NOT
890 ** locked out if this is a station.
891 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700892
893 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100894 if (msg->enable.data == P80211ENUM_truth_true) {
895 if (hfa384x_drvr_flashdl_enable(hw)) {
896 msg->resultcode.data =
897 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700898 } else {
899 msg->resultcode.data = P80211ENUM_resultcode_success;
900 }
901 } else {
902 hfa384x_drvr_flashdl_disable(hw);
903 msg->resultcode.data = P80211ENUM_resultcode_success;
904 /* NOTE: At this point, the MAC is in the post-reset
905 * state and the driver is in the fwload state.
906 * We need to get the MAC back into the fwload
907 * state. To do this, we set the nsdstate to HWPRESENT
908 * and then call the ifstate function to redo everything
909 * that got us into the fwload state.
910 */
911 wlandev->msdstate = WLAN_MSD_HWPRESENT;
912 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
913 if (result != P80211ENUM_resultcode_success) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100914 printk(KERN_ERR "prism2sta_ifstate(fwload) failed,"
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100915 "P80211ENUM_resultcode=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700916 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100917 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700918 result = -1;
919 }
920 }
921
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700922 return 0;
923}
924
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700925/*----------------------------------------------------------------
926* prism2mgmt_flashdl_write
927*
928*
929*
930* Arguments:
931* wlandev wlan device structure
932* msgp ptr to msg buffer
933*
934* Returns:
935* 0 success and done
936* <0 success, but we're waiting for something to finish.
937* >0 an error occurred while handling the message.
938* Side effects:
939*
940* Call context:
941* process thread (usually)
942----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530943int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700944{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100945 hfa384x_t *hw = wlandev->priv;
946 p80211msg_p2req_flashdl_write_t *msg = msgp;
947 u32 addr;
948 u32 len;
949 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700950
951 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +0100952 printk(KERN_ERR
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100953 "flashdl_write(): may only be called "
954 "in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700955 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100956 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700957 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700958 return 0;
959 }
960
961 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100962 ** Note: Interrupts are locked out if this is an AP and are NOT
963 ** locked out if this is a station.
964 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700965
966 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
967 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100968 if (msg->len.data > sizeof(msg->data.data)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700969 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100970 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700971 return 0;
972 }
973 /* call the hfa384x function to do the write */
974 addr = msg->addr.data;
975 len = msg->len.data;
976 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100977 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700978 msg->resultcode.data = P80211ENUM_resultcode_refused;
979
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700980 msg->resultcode.data = P80211ENUM_resultcode_success;
981
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700982 return 0;
983}
984
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700985/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700986* prism2mgmt_autojoin
987*
988* Associate with an ESS.
989*
990* Arguments:
991* wlandev wlan device structure
992* msgp ptr to msg buffer
993*
994* Returns:
995* 0 success and done
996* <0 success, but we're waiting for something to finish.
997* >0 an error occurred while handling the message.
998* Side effects:
999*
1000* Call context:
1001* process thread (usually)
1002* interrupt
1003----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301004int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001005{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001006 hfa384x_t *hw = wlandev->priv;
1007 int result = 0;
1008 u16 reg;
1009 u16 port_type;
1010 p80211msg_lnxreq_autojoin_t *msg = msgp;
1011 p80211pstrd_t *pstr;
1012 u8 bytebuf[256];
1013 hfa384x_bytestr_t *p2bytestr = (hfa384x_bytestr_t *) bytebuf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001014
1015 wlandev->macmode = WLAN_MACMODE_NONE;
1016
1017 /* Set the SSID */
1018 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1019
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001020 /* Disable the Port */
1021 hfa384x_drvr_disable(hw, 0);
1022
1023 /*** STATION ***/
1024 /* Set the TxRates */
1025 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1026
1027 /* Set the auth type */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001028 if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001029 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001030 else
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001031 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001032
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001033 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1034
1035 /* Set the ssid */
1036 memset(bytebuf, 0, 256);
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001037 pstr = (p80211pstrd_t *) &(msg->ssid.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001038 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001039 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1040 bytebuf,
1041 HFA384x_RID_CNFDESIREDSSID_LEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001042 port_type = HFA384x_PORTTYPE_BSS;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001043 /* Set the PortType */
1044 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1045
1046 /* Enable the Port */
1047 hfa384x_drvr_enable(hw, 0);
1048
1049 /* Set the resultcode */
1050 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1051 msg->resultcode.data = P80211ENUM_resultcode_success;
1052
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001053 return result;
1054}
1055
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001056/*----------------------------------------------------------------
1057* prism2mgmt_wlansniff
1058*
1059* Start or stop sniffing.
1060*
1061* Arguments:
1062* wlandev wlan device structure
1063* msgp ptr to msg buffer
1064*
1065* Returns:
1066* 0 success and done
1067* <0 success, but we're waiting for something to finish.
1068* >0 an error occurred while handling the message.
1069* Side effects:
1070*
1071* Call context:
1072* process thread (usually)
1073* interrupt
1074----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301075int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001076{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001077 int result = 0;
1078 p80211msg_lnxreq_wlansniff_t *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001079
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001080 hfa384x_t *hw = wlandev->priv;
1081 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001082
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001083 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001084 switch (msg->enable.data) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001085 case P80211ENUM_truth_false:
1086 /* Confirm that we're in monitor mode */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001087 if (wlandev->netdev->type == ARPHRD_ETHER) {
1088 msg->resultcode.data =
1089 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001090 result = 0;
1091 goto exit;
1092 }
1093 /* Disable monitor mode */
1094 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001095 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301096 pr_debug("failed to disable monitor mode, result=%d\n",
1097 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001098 goto failed;
1099 }
1100 /* Disable port 0 */
1101 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001102 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301103 pr_debug
1104 ("failed to disable port 0 after sniffing, result=%d\n",
1105 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001106 goto failed;
1107 }
1108 /* Clear the driver state */
1109 wlandev->netdev->type = ARPHRD_ETHER;
1110
1111 /* Restore the wepflags */
1112 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001113 HFA384x_RID_CNFWEPFLAGS,
1114 hw->presniff_wepflags);
1115 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301116 pr_debug
1117 ("failed to restore wepflags=0x%04x, result=%d\n",
1118 hw->presniff_wepflags, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001119 goto failed;
1120 }
1121
1122 /* Set the port to its prior type and enable (if necessary) */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001123 if (hw->presniff_port_type != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001124 word = hw->presniff_port_type;
1125 result = hfa384x_drvr_setconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001126 HFA384x_RID_CNFPORTTYPE,
1127 word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001128 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301129 pr_debug
1130 ("failed to restore porttype, result=%d\n",
1131 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001132 goto failed;
1133 }
1134
1135 /* Enable the port */
1136 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001137 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301138 pr_debug
1139 ("failed to enable port to presniff setting, result=%d\n",
1140 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001141 goto failed;
1142 }
1143 } else {
1144 result = hfa384x_drvr_disable(hw, 0);
1145
1146 }
1147
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01001148 printk(KERN_INFO "monitor mode disabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001149 msg->resultcode.data = P80211ENUM_resultcode_success;
1150 result = 0;
1151 goto exit;
1152 break;
1153 case P80211ENUM_truth_true:
1154 /* Disable the port (if enabled), only check Port 0 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001155 if (hw->port_enabled[0]) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001156 if (wlandev->netdev->type == ARPHRD_ETHER) {
1157 /* Save macport 0 state */
1158 result = hfa384x_drvr_getconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001159 HFA384x_RID_CNFPORTTYPE,
1160 &(hw->presniff_port_type));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001161 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301162 pr_debug
1163 ("failed to read porttype, result=%d\n",
1164 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001165 goto failed;
1166 }
1167 /* Save the wepflags state */
1168 result = hfa384x_drvr_getconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001169 HFA384x_RID_CNFWEPFLAGS,
1170 &(hw->presniff_wepflags));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001171 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301172 pr_debug
1173 ("failed to read wepflags, result=%d\n",
1174 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001175 goto failed;
1176 }
1177 hfa384x_drvr_stop(hw);
1178 result = hfa384x_drvr_start(hw);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001179 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301180 pr_debug
1181 ("failed to restart the card for sniffing, result=%d\n",
1182 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001183 goto failed;
1184 }
1185 } else {
1186 /* Disable the port */
1187 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001188 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301189 pr_debug
1190 ("failed to enable port for sniffing, result=%d\n",
1191 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001192 goto failed;
1193 }
1194 }
1195 } else {
1196 hw->presniff_port_type = 0;
1197 }
1198
1199 /* Set the channel we wish to sniff */
1200 word = msg->channel.data;
1201 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001202 HFA384x_RID_CNFOWNCHANNEL,
1203 word);
1204 hw->sniff_channel = word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001205
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001206 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301207 pr_debug("failed to set channel %d, result=%d\n",
1208 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001209 goto failed;
1210 }
1211
1212 /* Now if we're already sniffing, we can skip the rest */
1213 if (wlandev->netdev->type != ARPHRD_ETHER) {
1214 /* Set the port type to pIbss */
1215 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1216 result = hfa384x_drvr_setconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001217 HFA384x_RID_CNFPORTTYPE,
1218 word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001219 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301220 pr_debug
1221 ("failed to set porttype %d, result=%d\n",
1222 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001223 goto failed;
1224 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001225 if ((msg->keepwepflags.status ==
1226 P80211ENUM_msgitem_status_data_ok)
1227 && (msg->keepwepflags.data !=
1228 P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001229 /* Set the wepflags for no decryption */
1230 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001231 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1232 result =
1233 hfa384x_drvr_setconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001234 HFA384x_RID_CNFWEPFLAGS,
1235 word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001236 }
1237
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001238 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301239 pr_debug
1240 ("failed to set wepflags=0x%04x, result=%d\n",
1241 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001242 goto failed;
1243 }
1244 }
1245
1246 /* Do we want to strip the FCS in monitor mode? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001247 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1248 && (msg->stripfcs.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001249 hw->sniff_fcs = 0;
1250 } else {
1251 hw->sniff_fcs = 1;
1252 }
1253
1254 /* Do we want to truncate the packets? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001255 if (msg->packet_trunc.status ==
1256 P80211ENUM_msgitem_status_data_ok) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001257 hw->sniff_truncate = msg->packet_trunc.data;
1258 } else {
1259 hw->sniff_truncate = 0;
1260 }
1261
1262 /* Enable the port */
1263 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001264 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301265 pr_debug
1266 ("failed to enable port for sniffing, result=%d\n",
1267 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001268 goto failed;
1269 }
1270 /* Enable monitor mode */
1271 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001272 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301273 pr_debug("failed to enable monitor mode, result=%d\n",
1274 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001275 goto failed;
1276 }
1277
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001278 if (wlandev->netdev->type == ARPHRD_ETHER)
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01001279 printk(KERN_INFO "monitor mode enabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001280
1281 /* Set the driver state */
1282 /* Do we want the prism2 header? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001283 if ((msg->prismheader.status ==
1284 P80211ENUM_msgitem_status_data_ok)
1285 && (msg->prismheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001286 hw->sniffhdr = 0;
1287 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001288 } else
1289 if ((msg->wlanheader.status ==
1290 P80211ENUM_msgitem_status_data_ok)
1291 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001292 hw->sniffhdr = 1;
1293 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1294 } else {
1295 wlandev->netdev->type = ARPHRD_IEEE80211;
1296 }
1297
1298 msg->resultcode.data = P80211ENUM_resultcode_success;
1299 result = 0;
1300 goto exit;
1301 break;
1302 default:
1303 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1304 result = 0;
1305 goto exit;
1306 break;
1307 }
1308
1309failed:
1310 msg->resultcode.data = P80211ENUM_resultcode_refused;
1311 result = 0;
1312exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001313 return result;
1314}