blob: d5737166564eb40aa7b10a6ddb88669f218aa489 [file] [log] [blame]
Greg Kroah-Hartmanf7056d32017-11-07 21:07:51 +01001// SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
Aldas Taraškevičius8ffd91d2021-08-28 22:53:24 +03002/*
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +02003 *
4 * Management request handler functions.
5 *
6 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
7 * --------------------------------------------------------------------
8 *
9 * linux-wlan
10 *
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +020011 * --------------------------------------------------------------------
12 *
13 * Inquiries regarding the linux-wlan Open Source project can be
14 * made directly to:
15 *
16 * AbsoluteValue Systems Inc.
17 * info@linux-wlan.com
18 * http://www.linux-wlan.com
19 *
20 * --------------------------------------------------------------------
21 *
22 * Portions of the development of this software were funded by
23 * Intersil Corporation as part of PRISM(R) chipset product development.
24 *
25 * --------------------------------------------------------------------
26 *
27 * The functions in this file handle management requests sent from
28 * user mode.
29 *
30 * Most of these functions have two separate blocks of code that are
31 * conditional on whether this is a station or an AP. This is used
32 * to separate out the STA and AP responses to these management primitives.
33 * It's a choice (good, bad, indifferent?) to have the code in the same
34 * place so it's clear that the same primitive is implemented in both
35 * cases but has different behavior.
36 *
37 * --------------------------------------------------------------------
38 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070039
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070040#include <linux/if_arp.h>
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/wait.h>
44#include <linux/sched.h>
45#include <linux/types.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070046#include <linux/wireless.h>
47#include <linux/netdevice.h>
48#include <linux/delay.h>
Andrew Elwellef1a0ed2010-02-18 23:56:12 +010049#include <linux/io.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070050#include <asm/byteorder.h>
51#include <linux/random.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070052#include <linux/usb.h>
Moritz Muehlenhoff7f6e0e42009-01-25 21:54:55 +010053#include <linux/bitops.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070054
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070055#include "p80211types.h"
56#include "p80211hdr.h"
57#include "p80211mgmt.h"
58#include "p80211conv.h"
59#include "p80211msg.h"
60#include "p80211netdev.h"
61#include "p80211metadef.h"
62#include "p80211metastruct.h"
63#include "hfa384x.h"
64#include "prism2mgmt.h"
65
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070066/* Converts 802.11 format rate specifications to prism2 */
Tim Collierb2679002018-06-22 20:39:33 +010067static inline u16 p80211rate_to_p2bit(u32 rate)
68{
69 switch (rate & ~BIT(7)) {
70 case 2:
71 return BIT(0);
72 case 4:
73 return BIT(1);
74 case 11:
75 return BIT(2);
76 case 22:
77 return BIT(3);
78 default:
79 return 0;
80 }
81}
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070082
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070083/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +020084 * prism2mgmt_scan
85 *
86 * Initiate a scan for BSSs.
87 *
88 * This function corresponds to MLME-scan.request and part of
89 * MLME-scan.confirm. As far as I can tell in the standard, there
90 * are no restrictions on when a scan.request may be issued. We have
91 * to handle in whatever state the driver/MAC happen to be.
92 *
93 * Arguments:
94 * wlandev wlan device structure
95 * msgp ptr to msg buffer
96 *
97 * Returns:
98 * 0 success and done
99 * <0 success, but we're waiting for something to finish.
100 * >0 an error occurred while handling the message.
101 * Side effects:
102 *
103 * Call context:
104 * process thread (usually)
105 * interrupt
106 *----------------------------------------------------------------
107 */
sayli karnikc9573a82016-09-18 15:11:14 +0530108int prism2mgmt_scan(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700109{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100110 int result = 0;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200111 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300112 struct p80211msg_dot11req_scan *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100113 u16 roamingmode, word;
114 int i, timeout;
115 int istmpenable = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700116
Sergio Paracuellose474b4d2016-10-19 17:59:13 +0200117 struct hfa384x_host_scan_request_data scanreq;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700118
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100119 /* gatekeeper check */
120 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
121 hw->ident_sta_fw.minor,
122 hw->ident_sta_fw.variant) <
123 HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000124 netdev_err(wlandev->netdev,
125 "HostScan not supported with current firmware (<1.3.2).\n");
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100126 result = 1;
127 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700128 goto exit;
129 }
130
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100131 memset(&scanreq, 0, sizeof(scanreq));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700132
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100133 /* save current roaming mode */
134 result = hfa384x_drvr_getconfig16(hw,
135 HFA384x_RID_CNFROAMINGMODE,
136 &roamingmode);
137 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000138 netdev_err(wlandev->netdev,
139 "getconfig(ROAMMODE) failed. result=%d\n", result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100140 msg->resultcode.data =
141 P80211ENUM_resultcode_implementation_failure;
142 goto exit;
143 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700144
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100145 /* drop into mode 3 for the scan */
146 result = hfa384x_drvr_setconfig16(hw,
147 HFA384x_RID_CNFROAMINGMODE,
148 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
149 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000150 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200151 "setconfig(ROAMINGMODE) failed. result=%d\n",
152 result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100153 msg->resultcode.data =
154 P80211ENUM_resultcode_implementation_failure;
155 goto exit;
156 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700157
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100158 /* active or passive? */
159 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
160 hw->ident_sta_fw.minor,
161 hw->ident_sta_fw.variant) >
162 HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
163 if (msg->scantype.data != P80211ENUM_scantype_active)
Andrea della Portadea20572017-04-29 07:30:23 +0100164 word = msg->maxchanneltime.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100165 else
166 word = 0;
167
168 result =
169 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
170 word);
171 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000172 netdev_warn(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200173 "Passive scan not supported with current firmware. (<1.5.1)\n");
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100174 }
175 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700176
177 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
178 word = HFA384x_RATEBIT_2;
Sergio Paracuellose474b4d2016-10-19 17:59:13 +0200179 scanreq.tx_rate = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700180
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100181 /* set up the channel list */
182 word = 0;
183 for (i = 0; i < msg->channellist.data.len; i++) {
184 u8 channel = msg->channellist.data.data[i];
Johannes Stadlinger5d9c8d52014-06-19 21:20:15 +0200185
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100186 if (channel > 14)
187 continue;
188 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
189 word |= (1 << (channel - 1));
190 }
Sergio Paracuellose474b4d2016-10-19 17:59:13 +0200191 scanreq.channel_list = cpu_to_le16(word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700192
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100193 /* set up the ssid, if present. */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100194 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100195 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700196
197 /* Enable the MAC port if it's not already enabled */
198 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100199 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000200 netdev_err(wlandev->netdev,
201 "getconfig(PORTSTATUS) failed. result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700202 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100203 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700204 goto exit;
205 }
206 if (word == HFA384x_PORTSTATUS_DISABLED) {
Suniel Mahesh18cd9022017-06-16 11:01:45 +0530207 __le16 wordbuf[17];
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700208
209 result = hfa384x_drvr_setconfig16(hw,
Steff Richards1eb76a02020-08-24 18:53:56 +0200210 HFA384x_RID_CNFROAMINGMODE,
211 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100212 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000213 netdev_err(wlandev->netdev,
214 "setconfig(ROAMINGMODE) failed. result=%d\n",
215 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700216 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100217 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700218 goto exit;
219 }
220 /* Construct a bogus SSID and assign it to OwnSSID and
221 * DesiredSSID
222 */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100223 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700224 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100225 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
226 wordbuf,
227 HFA384x_RID_CNFOWNSSID_LEN);
228 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000229 netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700230 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100231 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700232 goto exit;
233 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100234 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
235 wordbuf,
236 HFA384x_RID_CNFDESIREDSSID_LEN);
237 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000238 netdev_err(wlandev->netdev,
239 "Failed to set DesiredSSID.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700240 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100241 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700242 goto exit;
243 }
244 /* bsstype */
245 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100246 HFA384x_RID_CNFPORTTYPE,
247 HFA384x_PORTTYPE_IBSS);
248 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000249 netdev_err(wlandev->netdev,
250 "Failed to set CNFPORTTYPE.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700251 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100252 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700253 goto exit;
254 }
255 /* ibss options */
256 result = hfa384x_drvr_setconfig16(hw,
Steff Richards1eb76a02020-08-24 18:53:56 +0200257 HFA384x_RID_CREATEIBSS,
258 HFA384x_CREATEIBSS_JOINCREATEIBSS);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100259 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000260 netdev_err(wlandev->netdev,
261 "Failed to set CREATEIBSS.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700262 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100263 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700264 goto exit;
265 }
266 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100267 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000268 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200269 "drvr_enable(0) failed. result=%d\n",
270 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700271 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100272 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700273 goto exit;
274 }
275 istmpenable = 1;
276 }
277
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100278 /* Figure out our timeout first Kus, then HZ */
279 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
280 timeout = (timeout * HZ) / 1000;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700281
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100282 /* Issue the scan request */
283 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700284
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100285 result = hfa384x_drvr_setconfig(hw,
286 HFA384x_RID_HOSTSCAN, &scanreq,
Sergio Paracuellose0e69642016-10-19 17:51:30 +0200287 sizeof(scanreq));
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100288 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000289 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200290 "setconfig(SCANREQUEST) failed. result=%d\n",
291 result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100292 msg->resultcode.data =
293 P80211ENUM_resultcode_implementation_failure;
294 goto exit;
295 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700296
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100297 /* sleep until info frame arrives */
298 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700299
300 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
301 if (hw->scanflag == -1)
302 hw->scanflag = 0;
303
304 msg->numbss.data = hw->scanflag;
305
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100306 hw->scanflag = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700307
308 /* Disable port if we temporarily enabled it. */
309 if (istmpenable) {
310 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100311 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000312 netdev_err(wlandev->netdev,
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200313 "drvr_disable(0) failed. result=%d\n",
314 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700315 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100316 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700317 goto exit;
318 }
319 }
320
321 /* restore original roaming mode */
322 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
323 roamingmode);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100324 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000325 netdev_err(wlandev->netdev,
326 "setconfig(ROAMMODE) failed. result=%d\n", result);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100327 msg->resultcode.data =
328 P80211ENUM_resultcode_implementation_failure;
329 goto exit;
330 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700331
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100332 result = 0;
333 msg->resultcode.data = P80211ENUM_resultcode_success;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700334
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100335exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700336 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
337
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700338 return result;
339}
340
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700341/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200342 * prism2mgmt_scan_results
343 *
344 * Retrieve the BSS description for one of the BSSs identified in
345 * a scan.
346 *
347 * Arguments:
348 * wlandev wlan device structure
349 * msgp ptr to msg buffer
350 *
351 * Returns:
352 * 0 success and done
353 * <0 success, but we're waiting for something to finish.
354 * >0 an error occurred while handling the message.
355 * Side effects:
356 *
357 * Call context:
358 * process thread (usually)
359 * interrupt
360 *----------------------------------------------------------------
361 */
sayli karnikc9573a82016-09-18 15:11:14 +0530362int prism2mgmt_scan_results(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700363{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100364 int result = 0;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300365 struct p80211msg_dot11req_scan_results *req;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200366 struct hfa384x *hw = wlandev->priv;
Sergio Paracuellos8f8149d2016-10-19 17:59:18 +0200367 struct hfa384x_hscan_result_sub *item = NULL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700368
369 int count;
370
Janani Ravichandran3cfcb952016-02-25 14:22:27 -0500371 req = 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) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000376 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200377 "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;
Dan Carpenterbb46f132012-04-18 09:48:59 +0300384 if (count > HFA384x_SCANRESULT_MAX)
385 count = HFA384x_SCANRESULT_MAX;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700386
387 if (req->bssindex.data >= count) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -0600388 netdev_dbg(wlandev->netdev,
389 "requested index (%d) out of range (%d)\n",
390 req->bssindex.data, count);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700391 result = 2;
392 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
393 goto exit;
394 }
395
Tim Collier460f6f82018-07-06 20:38:15 +0100396 item = &hw->scanresults->info.hscanresult.result[req->bssindex.data];
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700397 /* signal and noise */
398 req->signal.status = P80211ENUM_msgitem_status_data_ok;
399 req->noise.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100400 req->signal.data = le16_to_cpu(item->sl);
401 req->noise.data = le16_to_cpu(item->anl);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700402
403 /* BSSID */
404 req->bssid.status = P80211ENUM_msgitem_status_data_ok;
405 req->bssid.data.len = WLAN_BSSID_LEN;
406 memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
407
408 /* SSID */
409 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100410 req->ssid.data.len = le16_to_cpu(item->ssid.len);
Tormod Volden811a37e2013-01-09 22:23:32 +0100411 req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700412 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
413
414 /* supported rates */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100415 for (count = 0; count < 10; count++)
416 if (item->supprates[count] == 0)
417 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700418
Luke Koch9fd32102023-04-20 18:50:00 +0200419 for (int i = 0; i < 8; i++) {
420 if (count > i &&
421 DOT11_RATE5_ISBASIC_GET(item->supprates[i])) {
422 req->basicrate[i].data = item->supprates[i];
423 req->basicrate[i].status =
424 P80211ENUM_msgitem_status_data_ok;
425 }
426 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700427
Luke Koch9fd32102023-04-20 18:50:00 +0200428 for (int i = 0; i < 8; i++) {
429 if (count > i) {
430 req->supprate[i].data = item->supprates[i];
431 req->supprate[i].status =
432 P80211ENUM_msgitem_status_data_ok;
433 }
434 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700435
436 /* beacon period */
437 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100438 req->beaconperiod.data = le16_to_cpu(item->bcnint);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700439
440 /* timestamps */
441 req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
442 req->timestamp.data = jiffies;
443 req->localtime.status = P80211ENUM_msgitem_status_data_ok;
444 req->localtime.data = jiffies;
445
446 /* atim window */
447 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100448 req->ibssatimwindow.data = le16_to_cpu(item->atim);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700449
450 /* Channel */
451 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100452 req->dschannel.data = le16_to_cpu(item->chid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700453
454 /* capinfo bits */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100455 count = le16_to_cpu(item->capinfo);
Karl Reltoncb3126e2010-06-03 23:04:06 +0100456 req->capinfo.status = P80211ENUM_msgitem_status_data_ok;
457 req->capinfo.data = count;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700458
459 /* privacy flag */
460 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
461 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
462
463 /* cfpollable */
464 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
465 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
466
467 /* cfpollreq */
468 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
469 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
470
471 /* bsstype */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100472 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700473 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100474 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700475
476 result = 0;
477 req->resultcode.data = P80211ENUM_resultcode_success;
478
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100479exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700480 return result;
481}
482
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700483/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200484 * prism2mgmt_start
485 *
486 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
487 *
488 * Arguments:
489 * wlandev wlan device structure
490 * msgp ptr to msg buffer
491 *
492 * Returns:
493 * 0 success and done
494 * <0 success, but we're waiting for something to finish.
495 * >0 an error occurred while handling the message.
496 * Side effects:
497 *
498 * Call context:
499 * process thread (usually)
500 * interrupt
501 *----------------------------------------------------------------
502 */
sayli karnikc9573a82016-09-18 15:11:14 +0530503int prism2mgmt_start(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700504{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100505 int result = 0;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200506 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300507 struct p80211msg_dot11req_start *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700508
Sergio Paracuellos3fd1e3f2016-09-25 15:34:52 +0200509 struct p80211pstrd *pstr;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100510 u8 bytebuf[80];
Jannik Becher0e21fa42016-09-23 01:02:10 +0200511 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *)bytebuf;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100512 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700513
514 wlandev->macmode = WLAN_MACMODE_NONE;
515
516 /* Set the SSID */
517 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
518
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400519 /*** ADHOC IBSS ***/
520 /* see if current f/w is less than 8c3 */
521 if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
522 hw->ident_sta_fw.minor,
523 hw->ident_sta_fw.variant) <
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100524 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400525 /* Ad-Hoc not quite supported on Prism2 */
526 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
527 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700528 goto done;
529 }
530
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700531 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
532
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400533 /*** STATION ***/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700534 /* Set the REQUIRED config items */
535 /* SSID */
Yash Omerbeb7b032018-02-16 13:05:20 +0530536 pstr = (struct p80211pstrd *)&msg->ssid.data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700537 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100538 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
539 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
540 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000541 netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n");
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400542 goto failed;
543 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100544 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
545 bytebuf,
546 HFA384x_RID_CNFDESIREDSSID_LEN);
547 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000548 netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700549 goto failed;
550 }
551
552 /* bsstype - we use the default in the ap firmware */
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400553 /* IBSS port */
554 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700555
556 /* beacon period */
557 word = msg->beaconperiod.data;
Sergio Paracuellosb9376122016-10-19 17:59:12 +0200558 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNINT, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100559 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000560 netdev_err(wlandev->netdev,
561 "Failed to set beacon period=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700562 goto failed;
563 }
564
565 /* dschannel */
566 word = msg->dschannel.data;
567 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100568 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000569 netdev_err(wlandev->netdev,
570 "Failed to set channel=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700571 goto failed;
572 }
573 /* Basic rates */
574 word = p80211rate_to_p2bit(msg->basicrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100575 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700576 word |= p80211rate_to_p2bit(msg->basicrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100577
578 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700579 word |= p80211rate_to_p2bit(msg->basicrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100580
581 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700582 word |= p80211rate_to_p2bit(msg->basicrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100583
584 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700585 word |= p80211rate_to_p2bit(msg->basicrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100586
587 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700588 word |= p80211rate_to_p2bit(msg->basicrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100589
590 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700591 word |= p80211rate_to_p2bit(msg->basicrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100592
593 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700594 word |= p80211rate_to_p2bit(msg->basicrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100595
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700596 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100597 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000598 netdev_err(wlandev->netdev,
599 "Failed to set basicrates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700600 goto failed;
601 }
602
603 /* Operational rates (supprates and txratecontrol) */
604 word = p80211rate_to_p2bit(msg->operationalrate1.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100605 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700606 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100607
608 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700609 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100610
611 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700612 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100613
614 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700615 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100616
617 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700618 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100619
620 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700621 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100622
623 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700624 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100625
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700626 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100627 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000628 netdev_err(wlandev->netdev,
629 "Failed to set supprates=%d.\n", word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700630 goto failed;
631 }
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400632
633 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100634 if (result) {
Johannes Stadlinger2cf1ba42014-06-19 21:20:13 +0200635 netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n",
636 word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700637 goto failed;
638 }
639
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700640 /* Set the macmode so the frame setup code knows what to do */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100641 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
Solomon Peachy5db8dcc2008-10-27 11:14:02 -0400642 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700643 /* lets extend the data length a bit */
644 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
645 }
646
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700647 /* Enable the Port */
648 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100649 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000650 netdev_err(wlandev->netdev,
651 "Enable macport failed, result=%d.\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700652 goto failed;
653 }
654
655 msg->resultcode.data = P80211ENUM_resultcode_success;
656
657 goto done;
658failed:
Haneen Mohammed0fb89972017-09-12 22:32:25 -0600659 netdev_dbg(wlandev->netdev,
660 "Failed to set a config option, result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700661 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
662
663done:
Rehas Sachdevaf4353ee2016-09-20 01:05:54 +0530664 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700665}
666
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700667/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200668 * prism2mgmt_readpda
669 *
670 * Collect the PDA data and put it in the message.
671 *
672 * Arguments:
673 * wlandev wlan device structure
674 * msgp ptr to msg buffer
675 *
676 * Returns:
677 * 0 success and done
678 * <0 success, but we're waiting for something to finish.
679 * >0 an error occurred while handling the message.
680 * Side effects:
681 *
682 * Call context:
683 * process thread (usually)
684 *----------------------------------------------------------------
685 */
sayli karnikc9573a82016-09-18 15:11:14 +0530686int prism2mgmt_readpda(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700687{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200688 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300689 struct p80211msg_p2req_readpda *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100690 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700691
692 /* We only support collecting the PDA when in the FWLOAD
693 * state.
694 */
695 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000696 netdev_err(wlandev->netdev,
697 "PDA may only be read in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700698 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100699 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700700 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
701 } else {
702 /* Call drvr_readpda(), it handles the auxport enable
703 * and validating the returned PDA.
704 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100705 result = hfa384x_drvr_readpda(hw,
706 msg->pda.data,
707 HFA384x_PDA_LEN_MAX);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700708 if (result) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000709 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200710 "hfa384x_drvr_readpda() failed, result=%d\n",
711 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700712
713 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100714 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700715 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100716 P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700717 return 0;
718 }
719 msg->pda.status = P80211ENUM_msgitem_status_data_ok;
720 msg->resultcode.data = P80211ENUM_resultcode_success;
721 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
722 }
723
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700724 return 0;
725}
726
727/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200728 * prism2mgmt_ramdl_state
729 *
730 * Establishes the beginning/end of a card RAM download session.
731 *
732 * It is expected that the ramdl_write() function will be called
733 * one or more times between the 'enable' and 'disable' calls to
734 * this function.
735 *
736 * Note: This function should not be called when a mac comm port
737 * is active.
738 *
739 * Arguments:
740 * wlandev wlan device structure
741 * msgp ptr to msg buffer
742 *
743 * Returns:
744 * 0 success and done
745 * <0 success, but we're waiting for something to finish.
746 * >0 an error occurred while handling the message.
747 * Side effects:
748 *
749 * Call context:
750 * process thread (usually)
751 *----------------------------------------------------------------
752 */
sayli karnikc9573a82016-09-18 15:11:14 +0530753int prism2mgmt_ramdl_state(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700754{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200755 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300756 struct p80211msg_p2req_ramdl_state *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700757
758 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000759 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200760 "ramdl_state(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700761 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100762 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700763 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700764 return 0;
765 }
766
767 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100768 ** Note: Interrupts are locked out if this is an AP and are NOT
769 ** locked out if this is a station.
770 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700771
772 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100773 if (msg->enable.data == P80211ENUM_truth_true) {
774 if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
775 msg->resultcode.data =
776 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700777 } else {
778 msg->resultcode.data = P80211ENUM_resultcode_success;
779 }
780 } else {
781 hfa384x_drvr_ramdl_disable(hw);
782 msg->resultcode.data = P80211ENUM_resultcode_success;
783 }
784
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700785 return 0;
786}
787
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700788/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200789 * prism2mgmt_ramdl_write
790 *
791 * Writes a buffer to the card RAM using the download state. This
792 * is for writing code to card RAM. To just read or write raw data
793 * use the aux functions.
794 *
795 * Arguments:
796 * wlandev wlan device structure
797 * msgp ptr to msg buffer
798 *
799 * Returns:
800 * 0 success and done
801 * <0 success, but we're waiting for something to finish.
802 * >0 an error occurred while handling the message.
803 * Side effects:
804 *
805 * Call context:
806 * process thread (usually)
807 *----------------------------------------------------------------
808 */
sayli karnikc9573a82016-09-18 15:11:14 +0530809int prism2mgmt_ramdl_write(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700810{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200811 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300812 struct p80211msg_p2req_ramdl_write *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100813 u32 addr;
814 u32 len;
815 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700816
817 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000818 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200819 "ramdl_write(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700820 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100821 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700822 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700823 return 0;
824 }
825
826 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
827 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100828 if (msg->len.data > sizeof(msg->data.data)) {
829 msg->resultcode.status =
830 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700831 return 0;
832 }
833 /* call the hfa384x function to do the write */
834 addr = msg->addr.data;
835 len = msg->len.data;
836 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100837 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700838 msg->resultcode.data = P80211ENUM_resultcode_refused;
839
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700840 msg->resultcode.data = P80211ENUM_resultcode_success;
841
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700842 return 0;
843}
844
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700845/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200846 * prism2mgmt_flashdl_state
847 *
848 * Establishes the beginning/end of a card Flash download session.
849 *
850 * It is expected that the flashdl_write() function will be called
851 * one or more times between the 'enable' and 'disable' calls to
852 * this function.
853 *
854 * Note: This function should not be called when a mac comm port
855 * is active.
856 *
857 * Arguments:
858 * wlandev wlan device structure
859 * msgp ptr to msg buffer
860 *
861 * Returns:
862 * 0 success and done
863 * <0 success, but we're waiting for something to finish.
864 * >0 an error occurred while handling the message.
865 * Side effects:
866 *
867 * Call context:
868 * process thread (usually)
869 *----------------------------------------------------------------
870 */
sayli karnikc9573a82016-09-18 15:11:14 +0530871int prism2mgmt_flashdl_state(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700872{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100873 int result = 0;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200874 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300875 struct p80211msg_p2req_flashdl_state *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700876
877 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000878 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200879 "flashdl_state(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700880 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100881 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700882 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700883 return 0;
884 }
885
886 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100887 ** Note: Interrupts are locked out if this is an AP and are NOT
888 ** locked out if this is a station.
889 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700890
891 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100892 if (msg->enable.data == P80211ENUM_truth_true) {
893 if (hfa384x_drvr_flashdl_enable(hw)) {
894 msg->resultcode.data =
895 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700896 } else {
897 msg->resultcode.data = P80211ENUM_resultcode_success;
898 }
899 } else {
900 hfa384x_drvr_flashdl_disable(hw);
901 msg->resultcode.data = P80211ENUM_resultcode_success;
902 /* NOTE: At this point, the MAC is in the post-reset
903 * state and the driver is in the fwload state.
904 * We need to get the MAC back into the fwload
905 * state. To do this, we set the nsdstate to HWPRESENT
906 * and then call the ifstate function to redo everything
907 * that got us into the fwload state.
908 */
909 wlandev->msdstate = WLAN_MSD_HWPRESENT;
910 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
911 if (result != P80211ENUM_resultcode_success) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000912 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200913 "prism2sta_ifstate(fwload) failed, P80211ENUM_resultcode=%d\n",
914 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700915 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100916 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700917 result = -1;
918 }
919 }
920
Colin Ian King4cc41cb2020-01-14 18:16:04 +0000921 return result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700922}
923
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700924/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200925 * prism2mgmt_flashdl_write
926 *
927 *
928 *
929 * Arguments:
930 * wlandev wlan device structure
931 * msgp ptr to msg buffer
932 *
933 * Returns:
934 * 0 success and done
935 * <0 success, but we're waiting for something to finish.
936 * >0 an error occurred while handling the message.
937 * Side effects:
938 *
939 * Call context:
940 * process thread (usually)
941 *----------------------------------------------------------------
942 */
sayli karnikc9573a82016-09-18 15:11:14 +0530943int prism2mgmt_flashdl_write(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700944{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200945 struct hfa384x *hw = wlandev->priv;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300946 struct p80211msg_p2req_flashdl_write *msg = msgp;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100947 u32 addr;
948 u32 len;
949 u8 *buf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700950
951 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +1000952 netdev_err(wlandev->netdev,
Johannes Stadlinger17b37542014-06-19 21:20:14 +0200953 "flashdl_write(): may only be called in the fwload state.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700954 msg->resultcode.data =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100955 P80211ENUM_resultcode_implementation_failure;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700956 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700957 return 0;
958 }
959
960 /*
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100961 ** Note: Interrupts are locked out if this is an AP and are NOT
962 ** locked out if this is a station.
963 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700964
965 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
966 /* first validate the length */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100967 if (msg->len.data > sizeof(msg->data.data)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700968 msg->resultcode.status =
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100969 P80211ENUM_resultcode_invalid_parameters;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700970 return 0;
971 }
972 /* call the hfa384x function to do the write */
973 addr = msg->addr.data;
974 len = msg->len.data;
975 buf = msg->data.data;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +0100976 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700977 msg->resultcode.data = P80211ENUM_resultcode_refused;
978
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700979 msg->resultcode.data = P80211ENUM_resultcode_success;
980
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700981 return 0;
982}
983
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700984/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +0200985 * prism2mgmt_autojoin
986 *
987 * Associate with an ESS.
988 *
989 * Arguments:
990 * wlandev wlan device structure
991 * msgp ptr to msg buffer
992 *
993 * Returns:
994 * 0 success and done
995 * <0 success, but we're waiting for something to finish.
996 * >0 an error occurred while handling the message.
997 * Side effects:
998 *
999 * Call context:
1000 * process thread (usually)
1001 * interrupt
1002 *----------------------------------------------------------------
1003 */
sayli karnikc9573a82016-09-18 15:11:14 +05301004int prism2mgmt_autojoin(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001005{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001006 struct hfa384x *hw = wlandev->priv;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001007 int result = 0;
1008 u16 reg;
1009 u16 port_type;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -03001010 struct p80211msg_lnxreq_autojoin *msg = msgp;
Sergio Paracuellos3fd1e3f2016-09-25 15:34:52 +02001011 struct p80211pstrd *pstr;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001012 u8 bytebuf[256];
Jannik Becher0e21fa42016-09-23 01:02:10 +02001013 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *)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);
Tim Collier460f6f82018-07-06 20:38:15 +01001037 pstr = (struct p80211pstrd *)&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/*----------------------------------------------------------------
Sergio Paracuellos01fe9c92016-10-09 17:10:28 +02001057 * 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 *----------------------------------------------------------------
1075 */
sayli karnikc9573a82016-09-18 15:11:14 +05301076int prism2mgmt_wlansniff(struct wlandevice *wlandev, void *msgp)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001077{
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001078 int result = 0;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -03001079 struct p80211msg_lnxreq_wlansniff *msg = msgp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001080
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001081 struct hfa384x *hw = wlandev->priv;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001082 u16 word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001083
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001084 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001085 switch (msg->enable.data) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001086 case P80211ENUM_truth_false:
1087 /* Confirm that we're in monitor mode */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001088 if (wlandev->netdev->type == ARPHRD_ETHER) {
1089 msg->resultcode.data =
1090 P80211ENUM_resultcode_invalid_parameters;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301091 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001092 }
1093 /* Disable monitor mode */
1094 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001095 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001096 netdev_dbg(wlandev->netdev,
1097 "failed to disable monitor mode, result=%d\n",
1098 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001099 goto failed;
1100 }
1101 /* Disable port 0 */
1102 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001103 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001104 netdev_dbg
1105 (wlandev->netdev,
1106 "failed to disable port 0 after sniffing, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301107 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001108 goto failed;
1109 }
1110 /* Clear the driver state */
1111 wlandev->netdev->type = ARPHRD_ETHER;
1112
1113 /* Restore the wepflags */
1114 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001115 HFA384x_RID_CNFWEPFLAGS,
1116 hw->presniff_wepflags);
1117 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001118 netdev_dbg
1119 (wlandev->netdev,
1120 "failed to restore wepflags=0x%04x, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301121 hw->presniff_wepflags, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001122 goto failed;
1123 }
1124
1125 /* Set the port to its prior type and enable (if necessary) */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001126 if (hw->presniff_port_type != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001127 word = hw->presniff_port_type;
1128 result = hfa384x_drvr_setconfig16(hw,
Steff Richards1eb76a02020-08-24 18:53:56 +02001129 HFA384x_RID_CNFPORTTYPE,
1130 word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001131 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001132 netdev_dbg
1133 (wlandev->netdev,
1134 "failed to restore porttype, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301135 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001136 goto failed;
1137 }
1138
1139 /* Enable the port */
1140 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001141 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001142 netdev_dbg(wlandev->netdev,
1143 "failed to enable port to presniff setting, result=%d\n",
1144 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001145 goto failed;
1146 }
1147 } else {
1148 result = hfa384x_drvr_disable(hw, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001149 }
1150
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +10001151 netdev_info(wlandev->netdev, "monitor mode disabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001152 msg->resultcode.data = P80211ENUM_resultcode_success;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301153 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001154 case P80211ENUM_truth_true:
1155 /* Disable the port (if enabled), only check Port 0 */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001156 if (hw->port_enabled[0]) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001157 if (wlandev->netdev->type == ARPHRD_ETHER) {
1158 /* Save macport 0 state */
1159 result = hfa384x_drvr_getconfig16(hw,
Izabela Bakollari16b37e7b2020-10-22 15:22:18 +02001160 HFA384x_RID_CNFPORTTYPE,
1161 &hw->presniff_port_type);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001162 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001163 netdev_dbg
1164 (wlandev->netdev,
1165 "failed to read porttype, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301166 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001167 goto failed;
1168 }
1169 /* Save the wepflags state */
1170 result = hfa384x_drvr_getconfig16(hw,
Steff Richards1eb76a02020-08-24 18:53:56 +02001171 HFA384x_RID_CNFWEPFLAGS,
1172 &hw->presniff_wepflags);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001173 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001174 netdev_dbg
1175 (wlandev->netdev,
1176 "failed to read wepflags, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301177 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001178 goto failed;
1179 }
1180 hfa384x_drvr_stop(hw);
1181 result = hfa384x_drvr_start(hw);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001182 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001183 netdev_dbg(wlandev->netdev,
1184 "failed to restart the card for sniffing, result=%d\n",
1185 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001186 goto failed;
1187 }
1188 } else {
1189 /* Disable the port */
1190 result = hfa384x_drvr_disable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001191 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001192 netdev_dbg(wlandev->netdev,
1193 "failed to enable port for sniffing, result=%d\n",
1194 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001195 goto failed;
1196 }
1197 }
1198 } else {
1199 hw->presniff_port_type = 0;
1200 }
1201
1202 /* Set the channel we wish to sniff */
1203 word = msg->channel.data;
1204 result = hfa384x_drvr_setconfig16(hw,
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001205 HFA384x_RID_CNFOWNCHANNEL,
1206 word);
1207 hw->sniff_channel = word;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001208
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001209 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001210 netdev_dbg(wlandev->netdev,
1211 "failed to set channel %d, result=%d\n",
1212 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001213 goto failed;
1214 }
1215
1216 /* Now if we're already sniffing, we can skip the rest */
1217 if (wlandev->netdev->type != ARPHRD_ETHER) {
1218 /* Set the port type to pIbss */
1219 word = HFA384x_PORTTYPE_PSUEDOIBSS;
1220 result = hfa384x_drvr_setconfig16(hw,
Steff Richards1eb76a02020-08-24 18:53:56 +02001221 HFA384x_RID_CNFPORTTYPE,
1222 word);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001223 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001224 netdev_dbg
1225 (wlandev->netdev,
1226 "failed to set porttype %d, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301227 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001228 goto failed;
1229 }
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001230 if ((msg->keepwepflags.status ==
Tim Colliere47b3742018-07-06 20:38:14 +01001231 P80211ENUM_msgitem_status_data_ok) &&
1232 (msg->keepwepflags.data != P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001233 /* Set the wepflags for no decryption */
1234 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001235 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1236 result =
1237 hfa384x_drvr_setconfig16(hw,
Steff Richards1eb76a02020-08-24 18:53:56 +02001238 HFA384x_RID_CNFWEPFLAGS,
1239 word);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001240 }
1241
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001242 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001243 netdev_dbg
1244 (wlandev->netdev,
1245 "failed to set wepflags=0x%04x, result=%d\n",
Johan Meiringf83dfd02010-11-06 18:23:44 +02001246 word, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001247 goto failed;
1248 }
1249 }
1250
1251 /* Do we want to strip the FCS in monitor mode? */
Tim Colliere47b3742018-07-06 20:38:14 +01001252 if ((msg->stripfcs.status ==
1253 P80211ENUM_msgitem_status_data_ok) &&
1254 (msg->stripfcs.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001255 hw->sniff_fcs = 0;
1256 } else {
1257 hw->sniff_fcs = 1;
1258 }
1259
1260 /* Do we want to truncate the packets? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001261 if (msg->packet_trunc.status ==
1262 P80211ENUM_msgitem_status_data_ok) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001263 hw->sniff_truncate = msg->packet_trunc.data;
1264 } else {
1265 hw->sniff_truncate = 0;
1266 }
1267
1268 /* Enable the port */
1269 result = hfa384x_drvr_enable(hw, 0);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001270 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001271 netdev_dbg
1272 (wlandev->netdev,
1273 "failed to enable port for sniffing, result=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301274 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001275 goto failed;
1276 }
1277 /* Enable monitor mode */
1278 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001279 if (result) {
Haneen Mohammed0fb89972017-09-12 22:32:25 -06001280 netdev_dbg(wlandev->netdev,
1281 "failed to enable monitor mode, result=%d\n",
1282 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001283 goto failed;
1284 }
1285
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001286 if (wlandev->netdev->type == ARPHRD_ETHER)
Vitaly Osipov02d9b1e2014-05-18 16:59:36 +10001287 netdev_info(wlandev->netdev, "monitor mode enabled\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001288
1289 /* Set the driver state */
1290 /* Do we want the prism2 header? */
Moritz Muehlenhoff450238e2009-02-08 02:20:48 +01001291 if ((msg->prismheader.status ==
Frans Klaver55dd5a32017-02-09 22:58:21 +01001292 P80211ENUM_msgitem_status_data_ok) &&
1293 (msg->prismheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001294 hw->sniffhdr = 0;
1295 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
Frans Klaver55dd5a32017-02-09 22:58:21 +01001296 } else if ((msg->wlanheader.status ==
1297 P80211ENUM_msgitem_status_data_ok) &&
1298 (msg->wlanheader.data == P80211ENUM_truth_true)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001299 hw->sniffhdr = 1;
1300 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1301 } else {
1302 wlandev->netdev->type = ARPHRD_IEEE80211;
1303 }
1304
1305 msg->resultcode.data = P80211ENUM_resultcode_success;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301306 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001307 default:
1308 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301309 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001310 }
1311
1312failed:
1313 msg->resultcode.data = P80211ENUM_resultcode_refused;
Jeshwanth Kumar N K230fa112014-08-15 01:41:04 +05301314 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001315}