blob: 013a6240f193a3d96ce4aacacdf9d0548e3b4c42 [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>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070066#include <linux/wireless.h>
67#include <linux/netdevice.h>
68#include <linux/delay.h>
Andrew Elwellef1a0ed2010-02-18 23:56:12 +010069#include <linux/io.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070070#include <asm/byteorder.h>
71#include <linux/random.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070072#include <linux/usb.h>
Moritz Muehlenhoff7f6e0e42009-01-25 21:54:55 +010073#include <linux/bitops.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070074
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070075#include "p80211types.h"
76#include "p80211hdr.h"
77#include "p80211mgmt.h"
78#include "p80211conv.h"
79#include "p80211msg.h"
80#include "p80211netdev.h"
81#include "p80211metadef.h"
82#include "p80211metastruct.h"
83#include "hfa384x.h"
84#include "prism2mgmt.h"
85
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070086/* Converts 802.11 format rate specifications to prism2 */
Moritz Muehlenhoff7f6e0e42009-01-25 21:54:55 +010087#define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
88 (((n)&~BIT(7)) == 4) ? BIT(1) : \
89 (((n)&~BIT(7)) == 11) ? BIT(2) : \
90 (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070091
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070092/*----------------------------------------------------------------
93* prism2mgmt_scan
94*
95* Initiate a scan for BSSs.
96*
97* This function corresponds to MLME-scan.request and part of
98* MLME-scan.confirm. As far as I can tell in the standard, there
99* are no restrictions on when a scan.request may be issued. We have
100* to handle in whatever state the driver/MAC happen to be.
101*
102* Arguments:
103* wlandev wlan device structure
104* msgp ptr to msg buffer
105*
106* Returns:
107* 0 success and done
108* <0 success, but we're waiting for something to finish.
109* >0 an error occurred while handling the message.
110* Side effects:
111*
112* Call context:
113* process thread (usually)
114* interrupt
115----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530116int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700117{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100118 int result = 0;
119 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300120 struct p80211msg_dot11req_scan *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100121 u16 roamingmode, word;
122 int i, timeout;
123 int istmpenable = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700124
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100125 hfa384x_HostScanRequest_data_t scanreq;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700126
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100127 /* gatekeeper check */
128 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
129 hw->ident_sta_fw.minor,
130 hw->ident_sta_fw.variant) <
131 HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000132 netdev_err(wlandev->netdev,
133 "HostScan not supported with current firmware (<1.3.2).\n");
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100134 result = 1;
135 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700136 goto exit;
137 }
138
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100139 memset(&scanreq, 0, sizeof(scanreq));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700140
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100141 /* save current roaming mode */
142 result = hfa384x_drvr_getconfig16(hw,
143 HFA384x_RID_CNFROAMINGMODE,
144 &roamingmode);
145 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000146 netdev_err(wlandev->netdev,
147 "getconfig(ROAMMODE) failed. result=%d\n", result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100148 msg->resultcode.data =
149 P80211ENUM_resultcode_implementation_failure;
150 goto exit;
151 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700152
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100153 /* drop into mode 3 for the scan */
154 result = hfa384x_drvr_setconfig16(hw,
155 HFA384x_RID_CNFROAMINGMODE,
156 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
157 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000158 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200159 "setconfig(ROAMINGMODE) failed. result=%d\n",
160 result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100161 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) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000180 netdev_warn(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200181 "Passive scan not supported with current firmware. (<1.5.1)\n");
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100182 }
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];
Johannes Stadlinger5d9c8d52014-06-19 21:20:15 +0200193
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100194 if (channel > 14)
195 continue;
196 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
197 word |= (1 << (channel - 1));
198 }
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100199 scanreq.channelList = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700200
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100201 /* set up the ssid, if present. */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100202 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100203 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700204
205 /* Enable the MAC port if it's not already enabled */
206 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100207 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000208 netdev_err(wlandev->netdev,
209 "getconfig(PORTSTATUS) failed. result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700210 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100211 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700212 goto exit;
213 }
214 if (word == HFA384x_PORTSTATUS_DISABLED) {
Solomon Peachyaaad4302008-10-29 10:42:53 -0400215 u16 wordbuf[17];
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700216
217 result = hfa384x_drvr_setconfig16(hw,
Johan Meiringf83dfd02010-11-06 18:23:44 +0200218 HFA384x_RID_CNFROAMINGMODE,
219 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100220 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000221 netdev_err(wlandev->netdev,
222 "setconfig(ROAMINGMODE) failed. result=%d\n",
223 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700224 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100225 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700226 goto exit;
227 }
228 /* Construct a bogus SSID and assign it to OwnSSID and
229 * DesiredSSID
230 */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100231 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700232 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100233 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
234 wordbuf,
235 HFA384x_RID_CNFOWNSSID_LEN);
236 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000237 netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700238 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100239 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700240 goto exit;
241 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100242 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
243 wordbuf,
244 HFA384x_RID_CNFDESIREDSSID_LEN);
245 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000246 netdev_err(wlandev->netdev,
247 "Failed to set DesiredSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700248 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100249 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700250 goto exit;
251 }
252 /* bsstype */
253 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100254 HFA384x_RID_CNFPORTTYPE,
255 HFA384x_PORTTYPE_IBSS);
256 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000257 netdev_err(wlandev->netdev,
258 "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,
Johan Meiringf83dfd02010-11-06 18:23:44 +0200265 HFA384x_RID_CREATEIBSS,
266 HFA384x_CREATEIBSS_JOINCREATEIBSS);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100267 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000268 netdev_err(wlandev->netdev,
269 "Failed to set CREATEIBSS.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700270 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100271 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700272 goto exit;
273 }
274 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100275 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000276 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200277 "drvr_enable(0) failed. result=%d\n",
278 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700279 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100280 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700281 goto exit;
282 }
283 istmpenable = 1;
284 }
285
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100286 /* Figure out our timeout first Kus, then HZ */
287 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
288 timeout = (timeout * HZ) / 1000;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700289
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100290 /* Issue the scan request */
291 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700292
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100293 result = hfa384x_drvr_setconfig(hw,
294 HFA384x_RID_HOSTSCAN, &scanreq,
295 sizeof(hfa384x_HostScanRequest_data_t));
296 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000297 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200298 "setconfig(SCANREQUEST) failed. result=%d\n",
299 result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100300 msg->resultcode.data =
301 P80211ENUM_resultcode_implementation_failure;
302 goto exit;
303 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700304
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100305 /* sleep until info frame arrives */
306 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700307
308 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
309 if (hw->scanflag == -1)
310 hw->scanflag = 0;
311
312 msg->numbss.data = hw->scanflag;
313
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100314 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700315
316 /* Disable port if we temporarily enabled it. */
317 if (istmpenable) {
318 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100319 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000320 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200321 "drvr_disable(0) failed. result=%d\n",
322 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700323 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100324 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700325 goto exit;
326 }
327 }
328
329 /* restore original roaming mode */
330 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
331 roamingmode);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100332 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000333 netdev_err(wlandev->netdev,
334 "setconfig(ROAMMODE) failed. result=%d\n", result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100335 msg->resultcode.data =
336 P80211ENUM_resultcode_implementation_failure;
337 goto exit;
338 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700339
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100340 result = 0;
341 msg->resultcode.data = P80211ENUM_resultcode_success;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700342
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100343exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700344 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
345
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700346 return result;
347}
348
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700349/*----------------------------------------------------------------
350* prism2mgmt_scan_results
351*
352* Retrieve the BSS description for one of the BSSs identified in
353* a scan.
354*
355* Arguments:
356* wlandev wlan device structure
357* msgp ptr to msg buffer
358*
359* Returns:
360* 0 success and done
361* <0 success, but we're waiting for something to finish.
362* >0 an error occurred while handling the message.
363* Side effects:
364*
365* Call context:
366* process thread (usually)
367* interrupt
368----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530369int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700370{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100371 int result = 0;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300372 struct p80211msg_dot11req_scan_results *req;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100373 hfa384x_t *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700374 hfa384x_HScanResultSub_t *item = NULL;
375
376 int count;
377
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300378 req = (struct p80211msg_dot11req_scan_results *) msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700379
380 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
381
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100382 if (!hw->scanresults) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000383 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200384 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700385 result = 2;
386 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
387 goto exit;
388 }
389
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100390 count = (hw->scanresults->framelen - 3) / 32;
Dan Carpenterbb46f132012-04-18 09:48:59 +0300391 if (count > HFA384x_SCANRESULT_MAX)
392 count = HFA384x_SCANRESULT_MAX;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700393
394 if (req->bssindex.data >= count) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100395 pr_debug("requested index (%d) out of range (%d)\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530396 req->bssindex.data, count);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700397 result = 2;
398 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
399 goto exit;
400 }
401
402 item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
403 /* signal and noise */
404 req->signal.status = P80211ENUM_msgitem_status_data_ok;
405 req->noise.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100406 req->signal.data = le16_to_cpu(item->sl);
407 req->noise.data = le16_to_cpu(item->anl);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700408
409 /* BSSID */
410 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
411 req->bssid.data.len = WLAN_BSSID_LEN;
412 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
413
414 /* SSID */
415 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100416 req->ssid.data.len = le16_to_cpu(item->ssid.len);
Tormod Volden811a37e2013-01-09 22:23:32 +0100417 req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700418 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
419
420 /* supported rates */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100421 for (count = 0; count < 10; count++)
422 if (item->supprates[count] == 0)
423 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700424
425#define REQBASICRATE(N) \
Sebastian Wankerl52070c72013-01-20 16:24:45 +0100426 do { \
427 if ((count >= N) && DOT11_RATE5_ISBASIC_GET( \
428 item->supprates[(N)-1])) { \
429 req->basicrate ## N .data = item->supprates[(N)-1]; \
430 req->basicrate ## N .status = \
431 P80211ENUM_msgitem_status_data_ok; \
432 } \
433 } while (0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700434
435 REQBASICRATE(1);
436 REQBASICRATE(2);
437 REQBASICRATE(3);
438 REQBASICRATE(4);
439 REQBASICRATE(5);
440 REQBASICRATE(6);
441 REQBASICRATE(7);
442 REQBASICRATE(8);
443
444#define REQSUPPRATE(N) \
Sebastian Wankerl52070c72013-01-20 16:24:45 +0100445 do { \
446 if (count >= N) { \
447 req->supprate ## N .data = item->supprates[(N)-1]; \
448 req->supprate ## N .status = \
449 P80211ENUM_msgitem_status_data_ok; \
450 } \
451 } while (0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700452
453 REQSUPPRATE(1);
454 REQSUPPRATE(2);
455 REQSUPPRATE(3);
456 REQSUPPRATE(4);
457 REQSUPPRATE(5);
458 REQSUPPRATE(6);
459 REQSUPPRATE(7);
460 REQSUPPRATE(8);
461
462 /* beacon period */
463 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100464 req->beaconperiod.data = le16_to_cpu(item->bcnint);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700465
466 /* timestamps */
467 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
468 req->timestamp.data = jiffies;
469 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
470 req->localtime.data = jiffies;
471
472 /* atim window */
473 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100474 req->ibssatimwindow.data = le16_to_cpu(item->atim);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700475
476 /* Channel */
477 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100478 req->dschannel.data = le16_to_cpu(item->chid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700479
480 /* capinfo bits */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100481 count = le16_to_cpu(item->capinfo);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100482 req->capinfo.status = P80211ENUM_msgitem_status_data_ok;
483 req->capinfo.data = count;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700484
485 /* privacy flag */
486 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
487 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
488
489 /* cfpollable */
490 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
491 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
492
493 /* cfpollreq */
494 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
495 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
496
497 /* bsstype */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100498 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700499 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100500 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700501
502 result = 0;
503 req->resultcode.data = P80211ENUM_resultcode_success;
504
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100505exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700506 return result;
507}
508
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700509/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700510* prism2mgmt_start
511*
512* Start a BSS. Any station can do this for IBSS, only AP for ESS.
513*
514* Arguments:
515* wlandev wlan device structure
516* msgp ptr to msg buffer
517*
518* Returns:
519* 0 success and done
520* <0 success, but we're waiting for something to finish.
521* >0 an error occurred while handling the message.
522* Side effects:
523*
524* Call context:
525* process thread (usually)
526* interrupt
527----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530528int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700529{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100530 int result = 0;
531 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300532 struct p80211msg_dot11req_start *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700533
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100534 p80211pstrd_t *pstr;
535 u8 bytebuf[80];
Himangi Saraogib2119912013-11-02 18:11:44 +0530536 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100537 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700538
539 wlandev->macmode = WLAN_MACMODE_NONE;
540
541 /* Set the SSID */
542 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
543
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400544 /*** ADHOC IBSS ***/
545 /* see if current f/w is less than 8c3 */
546 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
547 hw->ident_sta_fw.minor,
548 hw->ident_sta_fw.variant) <
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100549 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400550 /* Ad-Hoc not quite supported on Prism2 */
551 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
552 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700553 goto done;
554 }
555
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700556 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
557
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400558 /*** STATION ***/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700559 /* Set the REQUIRED config items */
560 /* SSID */
Andrew Elwellef1a0ed2010-02-18 23:56:12 +0100561 pstr = (p80211pstrd_t *) &(msg->ssid.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700562 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100563 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
564 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
565 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000566 netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n");
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400567 goto failed;
568 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100569 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
570 bytebuf,
571 HFA384x_RID_CNFDESIREDSSID_LEN);
572 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000573 netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700574 goto failed;
575 }
576
577 /* bsstype - we use the default in the ap firmware */
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400578 /* IBSS port */
579 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700580
581 /* beacon period */
582 word = msg->beaconperiod.data;
Solomon Peachyaaad4302008-10-29 10:42:53 -0400583 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100584 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000585 netdev_err(wlandev->netdev,
586 "Failed to set beacon period=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700587 goto failed;
588 }
589
590 /* dschannel */
591 word = msg->dschannel.data;
592 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100593 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000594 netdev_err(wlandev->netdev,
595 "Failed to set channel=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700596 goto failed;
597 }
598 /* Basic rates */
599 word = p80211rate_to_p2bit(msg->basicrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100600 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700601 word |= p80211rate_to_p2bit(msg->basicrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100602
603 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700604 word |= p80211rate_to_p2bit(msg->basicrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100605
606 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700607 word |= p80211rate_to_p2bit(msg->basicrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100608
609 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700610 word |= p80211rate_to_p2bit(msg->basicrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100611
612 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700613 word |= p80211rate_to_p2bit(msg->basicrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100614
615 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700616 word |= p80211rate_to_p2bit(msg->basicrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100617
618 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700619 word |= p80211rate_to_p2bit(msg->basicrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100620
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700621 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100622 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000623 netdev_err(wlandev->netdev,
624 "Failed to set basicrates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700625 goto failed;
626 }
627
628 /* Operational rates (supprates and txratecontrol) */
629 word = p80211rate_to_p2bit(msg->operationalrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100630 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700631 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100632
633 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700634 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100635
636 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700637 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100638
639 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700640 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100641
642 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700643 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100644
645 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700646 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100647
648 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700649 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100650
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700651 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100652 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000653 netdev_err(wlandev->netdev,
654 "Failed to set supprates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700655 goto failed;
656 }
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400657
658 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100659 if (result) {
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200660 netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n",
661 word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700662 goto failed;
663 }
664
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700665 /* Set the macmode so the frame setup code knows what to do */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100666 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400667 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700668 /* lets extend the data length a bit */
669 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
670 }
671
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700672 /* Enable the Port */
673 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100674 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000675 netdev_err(wlandev->netdev,
676 "Enable macport failed, result=%d.\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700677 goto failed;
678 }
679
680 msg->resultcode.data = P80211ENUM_resultcode_success;
681
682 goto done;
683failed:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100684 pr_debug("Failed to set a config option, result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700685 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
686
687done:
688 result = 0;
689
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700690 return result;
691}
692
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700693/*----------------------------------------------------------------
694* prism2mgmt_readpda
695*
696* Collect the PDA data and put it in the message.
697*
698* Arguments:
699* wlandev wlan device structure
700* msgp ptr to msg buffer
701*
702* Returns:
703* 0 success and done
704* <0 success, but we're waiting for something to finish.
705* >0 an error occurred while handling the message.
706* Side effects:
707*
708* Call context:
709* process thread (usually)
710----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530711int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700712{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100713 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300714 struct p80211msg_p2req_readpda *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100715 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700716
717 /* We only support collecting the PDA when in the FWLOAD
718 * state.
719 */
720 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000721 netdev_err(wlandev->netdev,
722 "PDA may only be read in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700723 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100724 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700725 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
726 } else {
727 /* Call drvr_readpda(), it handles the auxport enable
728 * and validating the returned PDA.
729 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100730 result = hfa384x_drvr_readpda(hw,
731 msg->pda.data,
732 HFA384x_PDA_LEN_MAX);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700733 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000734 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200735 "hfa384x_drvr_readpda() failed, result=%d\n",
736 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700737
738 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100739 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700740 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100741 P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700742 return 0;
743 }
744 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
745 msg->resultcode.data = P80211ENUM_resultcode_success;
746 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
747 }
748
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700749 return 0;
750}
751
752/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700753* prism2mgmt_ramdl_state
754*
755* Establishes the beginning/end of a card RAM download session.
756*
757* It is expected that the ramdl_write() function will be called
758* one or more times between the 'enable' and 'disable' calls to
759* this function.
760*
761* Note: This function should not be called when a mac comm port
762* is active.
763*
764* Arguments:
765* wlandev wlan device structure
766* msgp ptr to msg buffer
767*
768* Returns:
769* 0 success and done
770* <0 success, but we're waiting for something to finish.
771* >0 an error occurred while handling the message.
772* Side effects:
773*
774* Call context:
775* process thread (usually)
776----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530777int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700778{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100779 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300780 struct p80211msg_p2req_ramdl_state *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700781
782 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000783 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200784 "ramdl_state(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700785 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100786 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700787 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700788 return 0;
789 }
790
791 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100792 ** Note: Interrupts are locked out if this is an AP and are NOT
793 ** locked out if this is a station.
794 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700795
796 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100797 if (msg->enable.data == P80211ENUM_truth_true) {
798 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
799 msg->resultcode.data =
800 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700801 } else {
802 msg->resultcode.data = P80211ENUM_resultcode_success;
803 }
804 } else {
805 hfa384x_drvr_ramdl_disable(hw);
806 msg->resultcode.data = P80211ENUM_resultcode_success;
807 }
808
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700809 return 0;
810}
811
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700812/*----------------------------------------------------------------
813* prism2mgmt_ramdl_write
814*
815* Writes a buffer to the card RAM using the download state. This
816* is for writing code to card RAM. To just read or write raw data
817* use the aux functions.
818*
819* Arguments:
820* wlandev wlan device structure
821* msgp ptr to msg buffer
822*
823* Returns:
824* 0 success and done
825* <0 success, but we're waiting for something to finish.
826* >0 an error occurred while handling the message.
827* Side effects:
828*
829* Call context:
830* process thread (usually)
831----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530832int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700833{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100834 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300835 struct p80211msg_p2req_ramdl_write *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100836 u32 addr;
837 u32 len;
838 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700839
840 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000841 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200842 "ramdl_write(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700843 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100844 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700845 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700846 return 0;
847 }
848
849 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
850 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100851 if (msg->len.data > sizeof(msg->data.data)) {
852 msg->resultcode.status =
853 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700854 return 0;
855 }
856 /* call the hfa384x function to do the write */
857 addr = msg->addr.data;
858 len = msg->len.data;
859 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100860 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700861 msg->resultcode.data = P80211ENUM_resultcode_refused;
862
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700863 msg->resultcode.data = P80211ENUM_resultcode_success;
864
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700865 return 0;
866}
867
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700868/*----------------------------------------------------------------
869* prism2mgmt_flashdl_state
870*
871* Establishes the beginning/end of a card Flash download session.
872*
873* It is expected that the flashdl_write() function will be called
874* one or more times between the 'enable' and 'disable' calls to
875* this function.
876*
877* Note: This function should not be called when a mac comm port
878* is active.
879*
880* Arguments:
881* wlandev wlan device structure
882* msgp ptr to msg buffer
883*
884* Returns:
885* 0 success and done
886* <0 success, but we're waiting for something to finish.
887* >0 an error occurred while handling the message.
888* Side effects:
889*
890* Call context:
891* process thread (usually)
892----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530893int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700894{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100895 int result = 0;
896 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300897 struct p80211msg_p2req_flashdl_state *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700898
899 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000900 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200901 "flashdl_state(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700902 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100903 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700904 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700905 return 0;
906 }
907
908 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100909 ** Note: Interrupts are locked out if this is an AP and are NOT
910 ** locked out if this is a station.
911 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700912
913 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100914 if (msg->enable.data == P80211ENUM_truth_true) {
915 if (hfa384x_drvr_flashdl_enable(hw)) {
916 msg->resultcode.data =
917 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700918 } else {
919 msg->resultcode.data = P80211ENUM_resultcode_success;
920 }
921 } else {
922 hfa384x_drvr_flashdl_disable(hw);
923 msg->resultcode.data = P80211ENUM_resultcode_success;
924 /* NOTE: At this point, the MAC is in the post-reset
925 * state and the driver is in the fwload state.
926 * We need to get the MAC back into the fwload
927 * state. To do this, we set the nsdstate to HWPRESENT
928 * and then call the ifstate function to redo everything
929 * that got us into the fwload state.
930 */
931 wlandev->msdstate = WLAN_MSD_HWPRESENT;
932 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
933 if (result != P80211ENUM_resultcode_success) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000934 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200935 "prism2sta_ifstate(fwload) failed, P80211ENUM_resultcode=%d\n",
936 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700937 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100938 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700939 result = -1;
940 }
941 }
942
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700943 return 0;
944}
945
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700946/*----------------------------------------------------------------
947* prism2mgmt_flashdl_write
948*
949*
950*
951* Arguments:
952* wlandev wlan device structure
953* msgp ptr to msg buffer
954*
955* Returns:
956* 0 success and done
957* <0 success, but we're waiting for something to finish.
958* >0 an error occurred while handling the message.
959* Side effects:
960*
961* Call context:
962* process thread (usually)
963----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530964int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700965{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100966 hfa384x_t *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300967 struct p80211msg_p2req_flashdl_write *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100968 u32 addr;
969 u32 len;
970 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700971
972 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000973 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200974 "flashdl_write(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700975 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100976 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700977 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700978 return 0;
979 }
980
981 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100982 ** Note: Interrupts are locked out if this is an AP and are NOT
983 ** locked out if this is a station.
984 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700985
986 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
987 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100988 if (msg->len.data > sizeof(msg->data.data)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700989 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100990 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700991 return 0;
992 }
993 /* call the hfa384x function to do the write */
994 addr = msg->addr.data;
995 len = msg->len.data;
996 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100997 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700998 msg->resultcode.data = P80211ENUM_resultcode_refused;
999
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001000 msg->resultcode.data = P80211ENUM_resultcode_success;
1001
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001002 return 0;
1003}
1004
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001005/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001006* prism2mgmt_autojoin
1007*
1008* Associate with an ESS.
1009*
1010* Arguments:
1011* wlandev wlan device structure
1012* msgp ptr to msg buffer
1013*
1014* Returns:
1015* 0 success and done
1016* <0 success, but we're waiting for something to finish.
1017* >0 an error occurred while handling the message.
1018* Side effects:
1019*
1020* Call context:
1021* process thread (usually)
1022* interrupt
1023----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301024int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001025{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001026 hfa384x_t *hw = wlandev->priv;
1027 int result = 0;
1028 u16 reg;
1029 u16 port_type;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -03001030 struct p80211msg_lnxreq_autojoin *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001031 p80211pstrd_t *pstr;
1032 u8 bytebuf[256];
Himangi Saraogib2119912013-11-02 18:11:44 +05301033 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001034
1035 wlandev->macmode = WLAN_MACMODE_NONE;
1036
1037 /* Set the SSID */
1038 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1039
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001040 /* Disable the Port */
1041 hfa384x_drvr_disable(hw, 0);
1042
1043 /*** STATION ***/
1044 /* Set the TxRates */
1045 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1046
1047 /* Set the auth type */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001048 if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001049 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001050 else
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001051 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001052
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001053 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1054
1055 /* Set the ssid */
1056 memset(bytebuf, 0, 256);
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001057 pstr = (p80211pstrd_t *) &(msg->ssid.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001058 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001059 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1060 bytebuf,
1061 HFA384x_RID_CNFDESIREDSSID_LEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001062 port_type = HFA384x_PORTTYPE_BSS;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001063 /* Set the PortType */
1064 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1065
1066 /* Enable the Port */
1067 hfa384x_drvr_enable(hw, 0);
1068
1069 /* Set the resultcode */
1070 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1071 msg->resultcode.data = P80211ENUM_resultcode_success;
1072
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001073 return result;
1074}
1075
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001076/*----------------------------------------------------------------
1077* prism2mgmt_wlansniff
1078*
1079* Start or stop sniffing.
1080*
1081* Arguments:
1082* wlandev wlan device structure
1083* msgp ptr to msg buffer
1084*
1085* Returns:
1086* 0 success and done
1087* <0 success, but we're waiting for something to finish.
1088* >0 an error occurred while handling the message.
1089* Side effects:
1090*
1091* Call context:
1092* process thread (usually)
1093* interrupt
1094----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301095int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001096{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001097 int result = 0;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -03001098 struct p80211msg_lnxreq_wlansniff *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001099
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001100 hfa384x_t *hw = wlandev->priv;
1101 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001102
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001103 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001104 switch (msg->enable.data) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001105 case P80211ENUM_truth_false:
1106 /* Confirm that we're in monitor mode */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001107 if (wlandev->netdev->type == ARPHRD_ETHER) {
1108 msg->resultcode.data =
1109 P80211ENUM_resultcode_invalid_parameters;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301110 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001111 }
1112 /* Disable monitor mode */
1113 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001114 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301115 pr_debug("failed to disable monitor mode, result=%d\n",
1116 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001117 goto failed;
1118 }
1119 /* Disable port 0 */
1120 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001121 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301122 pr_debug
Johan Meiringf83dfd02010-11-06 18:23:44 +02001123 ("failed to disable port 0 after sniffing, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301124 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001125 goto failed;
1126 }
1127 /* Clear the driver state */
1128 wlandev->netdev->type = ARPHRD_ETHER;
1129
1130 /* Restore the wepflags */
1131 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001132 HFA384x_RID_CNFWEPFLAGS,
1133 hw->presniff_wepflags);
1134 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301135 pr_debug
1136 ("failed to restore wepflags=0x%04x, result=%d\n",
1137 hw->presniff_wepflags, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001138 goto failed;
1139 }
1140
1141 /* Set the port to its prior type and enable (if necessary) */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001142 if (hw->presniff_port_type != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001143 word = hw->presniff_port_type;
1144 result = hfa384x_drvr_setconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001145 HFA384x_RID_CNFPORTTYPE,
1146 word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001147 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301148 pr_debug
1149 ("failed to restore porttype, result=%d\n",
1150 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001151 goto failed;
1152 }
1153
1154 /* Enable the port */
1155 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001156 if (result) {
Sebastian Wankerl25c97da2013-01-20 16:30:54 +01001157 pr_debug("failed to enable port to presniff setting, result=%d\n",
1158 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001159 goto failed;
1160 }
1161 } else {
1162 result = hfa384x_drvr_disable(hw, 0);
1163
1164 }
1165
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +10001166 netdev_info(wlandev->netdev, "monitor mode disabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001167 msg->resultcode.data = P80211ENUM_resultcode_success;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301168 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001169 case P80211ENUM_truth_true:
1170 /* Disable the port (if enabled), only check Port 0 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001171 if (hw->port_enabled[0]) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001172 if (wlandev->netdev->type == ARPHRD_ETHER) {
1173 /* Save macport 0 state */
1174 result = hfa384x_drvr_getconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001175 HFA384x_RID_CNFPORTTYPE,
1176 &(hw->presniff_port_type));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001177 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301178 pr_debug
Johan Meiringf83dfd02010-11-06 18:23:44 +02001179 ("failed to read porttype, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301180 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001181 goto failed;
1182 }
1183 /* Save the wepflags state */
1184 result = hfa384x_drvr_getconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001185 HFA384x_RID_CNFWEPFLAGS,
1186 &(hw->presniff_wepflags));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001187 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301188 pr_debug
Johan Meiringf83dfd02010-11-06 18:23:44 +02001189 ("failed to read wepflags, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301190 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001191 goto failed;
1192 }
1193 hfa384x_drvr_stop(hw);
1194 result = hfa384x_drvr_start(hw);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001195 if (result) {
Sebastian Wankerl25c97da2013-01-20 16:30:54 +01001196 pr_debug("failed to restart the card for sniffing, result=%d\n",
1197 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001198 goto failed;
1199 }
1200 } else {
1201 /* Disable the port */
1202 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001203 if (result) {
Sebastian Wankerl25c97da2013-01-20 16:30:54 +01001204 pr_debug("failed to enable port for sniffing, result=%d\n",
1205 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001206 goto failed;
1207 }
1208 }
1209 } else {
1210 hw->presniff_port_type = 0;
1211 }
1212
1213 /* Set the channel we wish to sniff */
1214 word = msg->channel.data;
1215 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001216 HFA384x_RID_CNFOWNCHANNEL,
1217 word);
1218 hw->sniff_channel = word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001219
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001220 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301221 pr_debug("failed to set channel %d, result=%d\n",
1222 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001223 goto failed;
1224 }
1225
1226 /* Now if we're already sniffing, we can skip the rest */
1227 if (wlandev->netdev->type != ARPHRD_ETHER) {
1228 /* Set the port type to pIbss */
1229 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1230 result = hfa384x_drvr_setconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001231 HFA384x_RID_CNFPORTTYPE,
1232 word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001233 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301234 pr_debug
1235 ("failed to set porttype %d, result=%d\n",
1236 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001237 goto failed;
1238 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001239 if ((msg->keepwepflags.status ==
1240 P80211ENUM_msgitem_status_data_ok)
1241 && (msg->keepwepflags.data !=
1242 P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001243 /* Set the wepflags for no decryption */
1244 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001245 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1246 result =
1247 hfa384x_drvr_setconfig16(hw,
Andrew Elwellef1a0ed2010-02-18 23:56:12 +01001248 HFA384x_RID_CNFWEPFLAGS,
1249 word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001250 }
1251
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001252 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301253 pr_debug
Johan Meiringf83dfd02010-11-06 18:23:44 +02001254 ("failed to set wepflags=0x%04x, result=%d\n",
1255 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001256 goto failed;
1257 }
1258 }
1259
1260 /* Do we want to strip the FCS in monitor mode? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001261 if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
1262 && (msg->stripfcs.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001263 hw->sniff_fcs = 0;
1264 } else {
1265 hw->sniff_fcs = 1;
1266 }
1267
1268 /* Do we want to truncate the packets? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001269 if (msg->packet_trunc.status ==
1270 P80211ENUM_msgitem_status_data_ok) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001271 hw->sniff_truncate = msg->packet_trunc.data;
1272 } else {
1273 hw->sniff_truncate = 0;
1274 }
1275
1276 /* Enable the port */
1277 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001278 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301279 pr_debug
1280 ("failed to enable port for sniffing, result=%d\n",
1281 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001282 goto failed;
1283 }
1284 /* Enable monitor mode */
1285 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001286 if (result) {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301287 pr_debug("failed to enable monitor mode, result=%d\n",
1288 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001289 goto failed;
1290 }
1291
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001292 if (wlandev->netdev->type == ARPHRD_ETHER)
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +10001293 netdev_info(wlandev->netdev, "monitor mode enabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001294
1295 /* Set the driver state */
1296 /* Do we want the prism2 header? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001297 if ((msg->prismheader.status ==
1298 P80211ENUM_msgitem_status_data_ok)
1299 && (msg->prismheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001300 hw->sniffhdr = 0;
1301 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001302 } else
1303 if ((msg->wlanheader.status ==
1304 P80211ENUM_msgitem_status_data_ok)
1305 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001306 hw->sniffhdr = 1;
1307 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1308 } else {
1309 wlandev->netdev->type = ARPHRD_IEEE80211;
1310 }
1311
1312 msg->resultcode.data = P80211ENUM_resultcode_success;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301313 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001314 default:
1315 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301316 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001317 }
1318
1319failed:
1320 msg->resultcode.data = P80211ENUM_resultcode_refused;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301321 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001322}