1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
4 * Management request handler functions.
6 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
7 * --------------------------------------------------------------------
11 * --------------------------------------------------------------------
13 * Inquiries regarding the linux-wlan Open Source project can be
16 * AbsoluteValue Systems Inc.
18 * http://www.linux-wlan.com
20 * --------------------------------------------------------------------
22 * Portions of the development of this software were funded by
23 * Intersil Corporation as part of PRISM(R) chipset product development.
25 * --------------------------------------------------------------------
27 * The functions in this file handle management requests sent from
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.
37 * --------------------------------------------------------------------
40 #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>
46 #include <linux/wireless.h>
47 #include <linux/netdevice.h>
48 #include <linux/delay.h>
50 #include <asm/byteorder.h>
51 #include <linux/random.h>
52 #include <linux/usb.h>
53 #include <linux/bitops.h>
55 #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"
64 #include "prism2mgmt.h"
66 /* Converts 802.11 format rate specifications to prism2 */
67 static inline u16 p80211rate_to_p2bit(u32 rate)
69 switch (rate & ~BIT(7)) {
83 /*----------------------------------------------------------------
86 * Initiate a scan for BSSs.
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.
94 * wlandev wlan device structure
95 * msgp ptr to msg buffer
99 * <0 success, but we're waiting for something to finish.
100 * >0 an error occurred while handling the message.
104 * process thread (usually)
106 *----------------------------------------------------------------
108 int prism2mgmt_scan(struct wlandevice *wlandev, void *msgp)
111 struct hfa384x *hw = wlandev->priv;
112 struct p80211msg_dot11req_scan *msg = msgp;
113 u16 roamingmode, word;
117 struct hfa384x_host_scan_request_data scanreq;
119 /* 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)) {
124 netdev_err(wlandev->netdev,
125 "HostScan not supported with current firmware (<1.3.2).\n");
127 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
131 memset(&scanreq, 0, sizeof(scanreq));
133 /* save current roaming mode */
134 result = hfa384x_drvr_getconfig16(hw,
135 HFA384x_RID_CNFROAMINGMODE,
138 netdev_err(wlandev->netdev,
139 "getconfig(ROAMMODE) failed. result=%d\n", result);
140 msg->resultcode.data =
141 P80211ENUM_resultcode_implementation_failure;
145 /* drop into mode 3 for the scan */
146 result = hfa384x_drvr_setconfig16(hw,
147 HFA384x_RID_CNFROAMINGMODE,
148 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
150 netdev_err(wlandev->netdev,
151 "setconfig(ROAMINGMODE) failed. result=%d\n",
153 msg->resultcode.data =
154 P80211ENUM_resultcode_implementation_failure;
158 /* 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)
164 word = msg->maxchanneltime.data;
169 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
172 netdev_warn(wlandev->netdev,
173 "Passive scan not supported with current firmware. (<1.5.1)\n");
177 /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
178 word = HFA384x_RATEBIT_2;
179 scanreq.tx_rate = cpu_to_le16(word);
181 /* set up the channel list */
183 for (i = 0; i < msg->channellist.data.len; i++) {
184 u8 channel = msg->channellist.data.data[i];
188 /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
189 word |= (1 << (channel - 1));
191 scanreq.channel_list = cpu_to_le16(word);
193 /* set up the ssid, if present. */
194 scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
195 memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
197 /* Enable the MAC port if it's not already enabled */
198 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
200 netdev_err(wlandev->netdev,
201 "getconfig(PORTSTATUS) failed. result=%d\n", result);
202 msg->resultcode.data =
203 P80211ENUM_resultcode_implementation_failure;
206 if (word == HFA384x_PORTSTATUS_DISABLED) {
209 result = hfa384x_drvr_setconfig16(hw,
210 HFA384x_RID_CNFROAMINGMODE,
211 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
213 netdev_err(wlandev->netdev,
214 "setconfig(ROAMINGMODE) failed. result=%d\n",
216 msg->resultcode.data =
217 P80211ENUM_resultcode_implementation_failure;
220 /* Construct a bogus SSID and assign it to OwnSSID and
223 wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
224 get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
225 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
227 HFA384x_RID_CNFOWNSSID_LEN);
229 netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n");
230 msg->resultcode.data =
231 P80211ENUM_resultcode_implementation_failure;
234 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
236 HFA384x_RID_CNFDESIREDSSID_LEN);
238 netdev_err(wlandev->netdev,
239 "Failed to set DesiredSSID.\n");
240 msg->resultcode.data =
241 P80211ENUM_resultcode_implementation_failure;
245 result = hfa384x_drvr_setconfig16(hw,
246 HFA384x_RID_CNFPORTTYPE,
247 HFA384x_PORTTYPE_IBSS);
249 netdev_err(wlandev->netdev,
250 "Failed to set CNFPORTTYPE.\n");
251 msg->resultcode.data =
252 P80211ENUM_resultcode_implementation_failure;
256 result = hfa384x_drvr_setconfig16(hw,
257 HFA384x_RID_CREATEIBSS,
258 HFA384x_CREATEIBSS_JOINCREATEIBSS);
260 netdev_err(wlandev->netdev,
261 "Failed to set CREATEIBSS.\n");
262 msg->resultcode.data =
263 P80211ENUM_resultcode_implementation_failure;
266 result = hfa384x_drvr_enable(hw, 0);
268 netdev_err(wlandev->netdev,
269 "drvr_enable(0) failed. result=%d\n",
271 msg->resultcode.data =
272 P80211ENUM_resultcode_implementation_failure;
278 /* Figure out our timeout first Kus, then HZ */
279 timeout = msg->channellist.data.len * msg->maxchanneltime.data;
280 timeout = (timeout * HZ) / 1000;
282 /* Issue the scan request */
285 result = hfa384x_drvr_setconfig(hw,
286 HFA384x_RID_HOSTSCAN, &scanreq,
289 netdev_err(wlandev->netdev,
290 "setconfig(SCANREQUEST) failed. result=%d\n",
292 msg->resultcode.data =
293 P80211ENUM_resultcode_implementation_failure;
297 /* sleep until info frame arrives */
298 wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
300 msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
301 if (hw->scanflag == -1)
304 msg->numbss.data = hw->scanflag;
308 /* Disable port if we temporarily enabled it. */
310 result = hfa384x_drvr_disable(hw, 0);
312 netdev_err(wlandev->netdev,
313 "drvr_disable(0) failed. result=%d\n",
315 msg->resultcode.data =
316 P80211ENUM_resultcode_implementation_failure;
321 /* restore original roaming mode */
322 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
325 netdev_err(wlandev->netdev,
326 "setconfig(ROAMMODE) failed. result=%d\n", result);
327 msg->resultcode.data =
328 P80211ENUM_resultcode_implementation_failure;
333 msg->resultcode.data = P80211ENUM_resultcode_success;
336 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
341 /*----------------------------------------------------------------
342 * prism2mgmt_scan_results
344 * Retrieve the BSS description for one of the BSSs identified in
348 * wlandev wlan device structure
349 * msgp ptr to msg buffer
353 * <0 success, but we're waiting for something to finish.
354 * >0 an error occurred while handling the message.
358 * process thread (usually)
360 *----------------------------------------------------------------
362 int prism2mgmt_scan_results(struct wlandevice *wlandev, void *msgp)
365 struct p80211msg_dot11req_scan_results *req;
366 struct hfa384x *hw = wlandev->priv;
367 struct hfa384x_hscan_result_sub *item = NULL;
373 req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
375 if (!hw->scanresults) {
376 netdev_err(wlandev->netdev,
377 "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
379 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
383 count = (hw->scanresults->framelen - 3) / 32;
384 if (count > HFA384x_SCANRESULT_MAX)
385 count = HFA384x_SCANRESULT_MAX;
387 if (req->bssindex.data >= count) {
388 netdev_dbg(wlandev->netdev,
389 "requested index (%d) out of range (%d)\n",
390 req->bssindex.data, count);
392 req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
396 item = &hw->scanresults->info.hscanresult.result[req->bssindex.data];
397 /* signal and noise */
398 req->signal.status = P80211ENUM_msgitem_status_data_ok;
399 req->noise.status = P80211ENUM_msgitem_status_data_ok;
400 req->signal.data = le16_to_cpu(item->sl);
401 req->noise.data = le16_to_cpu(item->anl);
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);
409 req->ssid.status = P80211ENUM_msgitem_status_data_ok;
410 req->ssid.data.len = le16_to_cpu(item->ssid.len);
411 req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN);
412 memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
414 /* supported rates */
415 for (count = 0; count < 10; count++)
416 if (item->supprates[count] == 0)
419 for (int i = 0; i < 8; 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;
428 for (int i = 0; i < 8; i++) {
430 req->supprate[i].data = item->supprates[i];
431 req->supprate[i].status =
432 P80211ENUM_msgitem_status_data_ok;
437 req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
438 req->beaconperiod.data = le16_to_cpu(item->bcnint);
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;
447 req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
448 req->ibssatimwindow.data = le16_to_cpu(item->atim);
451 req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
452 req->dschannel.data = le16_to_cpu(item->chid);
455 count = le16_to_cpu(item->capinfo);
456 req->capinfo.status = P80211ENUM_msgitem_status_data_ok;
457 req->capinfo.data = count;
460 req->privacy.status = P80211ENUM_msgitem_status_data_ok;
461 req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
464 req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
465 req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
468 req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
469 req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
472 req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
473 req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
474 P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
477 req->resultcode.data = P80211ENUM_resultcode_success;
483 /*----------------------------------------------------------------
486 * Start a BSS. Any station can do this for IBSS, only AP for ESS.
489 * wlandev wlan device structure
490 * msgp ptr to msg buffer
494 * <0 success, but we're waiting for something to finish.
495 * >0 an error occurred while handling the message.
499 * process thread (usually)
501 *----------------------------------------------------------------
503 int prism2mgmt_start(struct wlandevice *wlandev, void *msgp)
506 struct hfa384x *hw = wlandev->priv;
507 struct p80211msg_dot11req_start *msg = msgp;
509 struct p80211pstrd *pstr;
511 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *)bytebuf;
514 wlandev->macmode = WLAN_MACMODE_NONE;
517 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
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) <
524 HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
525 /* Ad-Hoc not quite supported on Prism2 */
526 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
527 msg->resultcode.data = P80211ENUM_resultcode_not_supported;
531 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
534 /* Set the REQUIRED config items */
536 pstr = (struct p80211pstrd *)&msg->ssid.data;
537 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
538 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
539 bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
541 netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n");
544 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
546 HFA384x_RID_CNFDESIREDSSID_LEN);
548 netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n");
552 /* bsstype - we use the default in the ap firmware */
554 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
557 word = msg->beaconperiod.data;
558 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNINT, word);
560 netdev_err(wlandev->netdev,
561 "Failed to set beacon period=%d.\n", word);
566 word = msg->dschannel.data;
567 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
569 netdev_err(wlandev->netdev,
570 "Failed to set channel=%d.\n", word);
574 word = p80211rate_to_p2bit(msg->basicrate1.data);
575 if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
576 word |= p80211rate_to_p2bit(msg->basicrate2.data);
578 if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
579 word |= p80211rate_to_p2bit(msg->basicrate3.data);
581 if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
582 word |= p80211rate_to_p2bit(msg->basicrate4.data);
584 if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
585 word |= p80211rate_to_p2bit(msg->basicrate5.data);
587 if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
588 word |= p80211rate_to_p2bit(msg->basicrate6.data);
590 if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
591 word |= p80211rate_to_p2bit(msg->basicrate7.data);
593 if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
594 word |= p80211rate_to_p2bit(msg->basicrate8.data);
596 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
598 netdev_err(wlandev->netdev,
599 "Failed to set basicrates=%d.\n", word);
603 /* Operational rates (supprates and txratecontrol) */
604 word = p80211rate_to_p2bit(msg->operationalrate1.data);
605 if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
606 word |= p80211rate_to_p2bit(msg->operationalrate2.data);
608 if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
609 word |= p80211rate_to_p2bit(msg->operationalrate3.data);
611 if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
612 word |= p80211rate_to_p2bit(msg->operationalrate4.data);
614 if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
615 word |= p80211rate_to_p2bit(msg->operationalrate5.data);
617 if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
618 word |= p80211rate_to_p2bit(msg->operationalrate6.data);
620 if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
621 word |= p80211rate_to_p2bit(msg->operationalrate7.data);
623 if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
624 word |= p80211rate_to_p2bit(msg->operationalrate8.data);
626 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
628 netdev_err(wlandev->netdev,
629 "Failed to set supprates=%d.\n", word);
633 result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
635 netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n",
640 /* Set the macmode so the frame setup code knows what to do */
641 if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
642 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
643 /* lets extend the data length a bit */
644 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
647 /* Enable the Port */
648 result = hfa384x_drvr_enable(hw, 0);
650 netdev_err(wlandev->netdev,
651 "Enable macport failed, result=%d.\n", result);
655 msg->resultcode.data = P80211ENUM_resultcode_success;
659 netdev_dbg(wlandev->netdev,
660 "Failed to set a config option, result=%d\n", result);
661 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
667 /*----------------------------------------------------------------
670 * Collect the PDA data and put it in the message.
673 * wlandev wlan device structure
674 * msgp ptr to msg buffer
678 * <0 success, but we're waiting for something to finish.
679 * >0 an error occurred while handling the message.
683 * process thread (usually)
684 *----------------------------------------------------------------
686 int prism2mgmt_readpda(struct wlandevice *wlandev, void *msgp)
688 struct hfa384x *hw = wlandev->priv;
689 struct p80211msg_p2req_readpda *msg = msgp;
692 /* We only support collecting the PDA when in the FWLOAD
695 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
696 netdev_err(wlandev->netdev,
697 "PDA may only be read in the fwload state.\n");
698 msg->resultcode.data =
699 P80211ENUM_resultcode_implementation_failure;
700 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
702 /* Call drvr_readpda(), it handles the auxport enable
703 * and validating the returned PDA.
705 result = hfa384x_drvr_readpda(hw,
707 HFA384x_PDA_LEN_MAX);
709 netdev_err(wlandev->netdev,
710 "hfa384x_drvr_readpda() failed, result=%d\n",
713 msg->resultcode.data =
714 P80211ENUM_resultcode_implementation_failure;
715 msg->resultcode.status =
716 P80211ENUM_msgitem_status_data_ok;
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;
727 /*----------------------------------------------------------------
728 * prism2mgmt_ramdl_state
730 * Establishes the beginning/end of a card RAM download session.
732 * It is expected that the ramdl_write() function will be called
733 * one or more times between the 'enable' and 'disable' calls to
736 * Note: This function should not be called when a mac comm port
740 * wlandev wlan device structure
741 * msgp ptr to msg buffer
745 * <0 success, but we're waiting for something to finish.
746 * >0 an error occurred while handling the message.
750 * process thread (usually)
751 *----------------------------------------------------------------
753 int prism2mgmt_ramdl_state(struct wlandevice *wlandev, void *msgp)
755 struct hfa384x *hw = wlandev->priv;
756 struct p80211msg_p2req_ramdl_state *msg = msgp;
758 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
759 netdev_err(wlandev->netdev,
760 "ramdl_state(): may only be called in the fwload state.\n");
761 msg->resultcode.data =
762 P80211ENUM_resultcode_implementation_failure;
763 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
768 ** Note: Interrupts are locked out if this is an AP and are NOT
769 ** locked out if this is a station.
772 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
773 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;
778 msg->resultcode.data = P80211ENUM_resultcode_success;
781 hfa384x_drvr_ramdl_disable(hw);
782 msg->resultcode.data = P80211ENUM_resultcode_success;
788 /*----------------------------------------------------------------
789 * prism2mgmt_ramdl_write
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.
796 * wlandev wlan device structure
797 * msgp ptr to msg buffer
801 * <0 success, but we're waiting for something to finish.
802 * >0 an error occurred while handling the message.
806 * process thread (usually)
807 *----------------------------------------------------------------
809 int prism2mgmt_ramdl_write(struct wlandevice *wlandev, void *msgp)
811 struct hfa384x *hw = wlandev->priv;
812 struct p80211msg_p2req_ramdl_write *msg = msgp;
817 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
818 netdev_err(wlandev->netdev,
819 "ramdl_write(): may only be called in the fwload state.\n");
820 msg->resultcode.data =
821 P80211ENUM_resultcode_implementation_failure;
822 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
826 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
827 /* first validate the length */
828 if (msg->len.data > sizeof(msg->data.data)) {
829 msg->resultcode.status =
830 P80211ENUM_resultcode_invalid_parameters;
833 /* call the hfa384x function to do the write */
834 addr = msg->addr.data;
836 buf = msg->data.data;
837 if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
838 msg->resultcode.data = P80211ENUM_resultcode_refused;
840 msg->resultcode.data = P80211ENUM_resultcode_success;
845 /*----------------------------------------------------------------
846 * prism2mgmt_flashdl_state
848 * Establishes the beginning/end of a card Flash download session.
850 * It is expected that the flashdl_write() function will be called
851 * one or more times between the 'enable' and 'disable' calls to
854 * Note: This function should not be called when a mac comm port
858 * wlandev wlan device structure
859 * msgp ptr to msg buffer
863 * <0 success, but we're waiting for something to finish.
864 * >0 an error occurred while handling the message.
868 * process thread (usually)
869 *----------------------------------------------------------------
871 int prism2mgmt_flashdl_state(struct wlandevice *wlandev, void *msgp)
874 struct hfa384x *hw = wlandev->priv;
875 struct p80211msg_p2req_flashdl_state *msg = msgp;
877 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
878 netdev_err(wlandev->netdev,
879 "flashdl_state(): may only be called in the fwload state.\n");
880 msg->resultcode.data =
881 P80211ENUM_resultcode_implementation_failure;
882 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
887 ** Note: Interrupts are locked out if this is an AP and are NOT
888 ** locked out if this is a station.
891 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
892 if (msg->enable.data == P80211ENUM_truth_true) {
893 if (hfa384x_drvr_flashdl_enable(hw)) {
894 msg->resultcode.data =
895 P80211ENUM_resultcode_implementation_failure;
897 msg->resultcode.data = P80211ENUM_resultcode_success;
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.
909 wlandev->msdstate = WLAN_MSD_HWPRESENT;
910 result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
911 if (result != P80211ENUM_resultcode_success) {
912 netdev_err(wlandev->netdev,
913 "prism2sta_ifstate(fwload) failed, P80211ENUM_resultcode=%d\n",
915 msg->resultcode.data =
916 P80211ENUM_resultcode_implementation_failure;
924 /*----------------------------------------------------------------
925 * prism2mgmt_flashdl_write
930 * wlandev wlan device structure
931 * msgp ptr to msg buffer
935 * <0 success, but we're waiting for something to finish.
936 * >0 an error occurred while handling the message.
940 * process thread (usually)
941 *----------------------------------------------------------------
943 int prism2mgmt_flashdl_write(struct wlandevice *wlandev, void *msgp)
945 struct hfa384x *hw = wlandev->priv;
946 struct p80211msg_p2req_flashdl_write *msg = msgp;
951 if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
952 netdev_err(wlandev->netdev,
953 "flashdl_write(): may only be called in the fwload state.\n");
954 msg->resultcode.data =
955 P80211ENUM_resultcode_implementation_failure;
956 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
961 ** Note: Interrupts are locked out if this is an AP and are NOT
962 ** locked out if this is a station.
965 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
966 /* first validate the length */
967 if (msg->len.data > sizeof(msg->data.data)) {
968 msg->resultcode.status =
969 P80211ENUM_resultcode_invalid_parameters;
972 /* call the hfa384x function to do the write */
973 addr = msg->addr.data;
975 buf = msg->data.data;
976 if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
977 msg->resultcode.data = P80211ENUM_resultcode_refused;
979 msg->resultcode.data = P80211ENUM_resultcode_success;
984 /*----------------------------------------------------------------
985 * prism2mgmt_autojoin
987 * Associate with an ESS.
990 * wlandev wlan device structure
991 * msgp ptr to msg buffer
995 * <0 success, but we're waiting for something to finish.
996 * >0 an error occurred while handling the message.
1000 * process thread (usually)
1002 *----------------------------------------------------------------
1004 int prism2mgmt_autojoin(struct wlandevice *wlandev, void *msgp)
1006 struct hfa384x *hw = wlandev->priv;
1010 struct p80211msg_lnxreq_autojoin *msg = msgp;
1011 struct p80211pstrd *pstr;
1013 struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *)bytebuf;
1015 wlandev->macmode = WLAN_MACMODE_NONE;
1018 memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
1020 /* Disable the Port */
1021 hfa384x_drvr_disable(hw, 0);
1024 /* Set the TxRates */
1025 hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
1027 /* Set the auth type */
1028 if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
1029 reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
1031 reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
1033 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
1036 memset(bytebuf, 0, 256);
1037 pstr = (struct p80211pstrd *)&msg->ssid.data;
1038 prism2mgmt_pstr2bytestr(p2bytestr, pstr);
1039 result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
1041 HFA384x_RID_CNFDESIREDSSID_LEN);
1042 port_type = HFA384x_PORTTYPE_BSS;
1043 /* Set the PortType */
1044 hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
1046 /* Enable the Port */
1047 hfa384x_drvr_enable(hw, 0);
1049 /* Set the resultcode */
1050 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1051 msg->resultcode.data = P80211ENUM_resultcode_success;
1056 /*----------------------------------------------------------------
1057 * prism2mgmt_wlansniff
1059 * Start or stop sniffing.
1062 * wlandev wlan device structure
1063 * msgp ptr to msg buffer
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.
1072 * process thread (usually)
1074 *----------------------------------------------------------------
1076 int prism2mgmt_wlansniff(struct wlandevice *wlandev, void *msgp)
1079 struct p80211msg_lnxreq_wlansniff *msg = msgp;
1081 struct hfa384x *hw = wlandev->priv;
1084 msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
1085 switch (msg->enable.data) {
1086 case P80211ENUM_truth_false:
1087 /* Confirm that we're in monitor mode */
1088 if (wlandev->netdev->type == ARPHRD_ETHER) {
1089 msg->resultcode.data =
1090 P80211ENUM_resultcode_invalid_parameters;
1093 /* Disable monitor mode */
1094 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
1096 netdev_dbg(wlandev->netdev,
1097 "failed to disable monitor mode, result=%d\n",
1101 /* Disable port 0 */
1102 result = hfa384x_drvr_disable(hw, 0);
1106 "failed to disable port 0 after sniffing, result=%d\n",
1110 /* Clear the driver state */
1111 wlandev->netdev->type = ARPHRD_ETHER;
1113 /* Restore the wepflags */
1114 result = hfa384x_drvr_setconfig16(hw,
1115 HFA384x_RID_CNFWEPFLAGS,
1116 hw->presniff_wepflags);
1120 "failed to restore wepflags=0x%04x, result=%d\n",
1121 hw->presniff_wepflags, result);
1125 /* Set the port to its prior type and enable (if necessary) */
1126 if (hw->presniff_port_type != 0) {
1127 word = hw->presniff_port_type;
1128 result = hfa384x_drvr_setconfig16(hw,
1129 HFA384x_RID_CNFPORTTYPE,
1134 "failed to restore porttype, result=%d\n",
1139 /* Enable the port */
1140 result = hfa384x_drvr_enable(hw, 0);
1142 netdev_dbg(wlandev->netdev,
1143 "failed to enable port to presniff setting, result=%d\n",
1148 result = hfa384x_drvr_disable(hw, 0);
1151 netdev_info(wlandev->netdev, "monitor mode disabled\n");
1152 msg->resultcode.data = P80211ENUM_resultcode_success;
1154 case P80211ENUM_truth_true:
1155 /* Disable the port (if enabled), only check Port 0 */
1156 if (hw->port_enabled[0]) {
1157 if (wlandev->netdev->type == ARPHRD_ETHER) {
1158 /* Save macport 0 state */
1159 result = hfa384x_drvr_getconfig16(hw,
1160 HFA384x_RID_CNFPORTTYPE,
1161 &hw->presniff_port_type);
1165 "failed to read porttype, result=%d\n",
1169 /* Save the wepflags state */
1170 result = hfa384x_drvr_getconfig16(hw,
1171 HFA384x_RID_CNFWEPFLAGS,
1172 &hw->presniff_wepflags);
1176 "failed to read wepflags, result=%d\n",
1180 hfa384x_drvr_stop(hw);
1181 result = hfa384x_drvr_start(hw);
1183 netdev_dbg(wlandev->netdev,
1184 "failed to restart the card for sniffing, result=%d\n",
1189 /* Disable the port */
1190 result = hfa384x_drvr_disable(hw, 0);
1192 netdev_dbg(wlandev->netdev,
1193 "failed to enable port for sniffing, result=%d\n",
1199 hw->presniff_port_type = 0;
1202 /* Set the channel we wish to sniff */
1203 word = msg->channel.data;
1204 result = hfa384x_drvr_setconfig16(hw,
1205 HFA384x_RID_CNFOWNCHANNEL,
1207 hw->sniff_channel = word;
1210 netdev_dbg(wlandev->netdev,
1211 "failed to set channel %d, result=%d\n",
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,
1221 HFA384x_RID_CNFPORTTYPE,
1226 "failed to set porttype %d, result=%d\n",
1230 if ((msg->keepwepflags.status ==
1231 P80211ENUM_msgitem_status_data_ok) &&
1232 (msg->keepwepflags.data != P80211ENUM_truth_true)) {
1233 /* Set the wepflags for no decryption */
1234 word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
1235 HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
1237 hfa384x_drvr_setconfig16(hw,
1238 HFA384x_RID_CNFWEPFLAGS,
1245 "failed to set wepflags=0x%04x, result=%d\n",
1251 /* Do we want to strip the FCS in monitor mode? */
1252 if ((msg->stripfcs.status ==
1253 P80211ENUM_msgitem_status_data_ok) &&
1254 (msg->stripfcs.data == P80211ENUM_truth_true)) {
1260 /* Do we want to truncate the packets? */
1261 if (msg->packet_trunc.status ==
1262 P80211ENUM_msgitem_status_data_ok) {
1263 hw->sniff_truncate = msg->packet_trunc.data;
1265 hw->sniff_truncate = 0;
1268 /* Enable the port */
1269 result = hfa384x_drvr_enable(hw, 0);
1273 "failed to enable port for sniffing, result=%d\n",
1277 /* Enable monitor mode */
1278 result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
1280 netdev_dbg(wlandev->netdev,
1281 "failed to enable monitor mode, result=%d\n",
1286 if (wlandev->netdev->type == ARPHRD_ETHER)
1287 netdev_info(wlandev->netdev, "monitor mode enabled\n");
1289 /* Set the driver state */
1290 /* Do we want the prism2 header? */
1291 if ((msg->prismheader.status ==
1292 P80211ENUM_msgitem_status_data_ok) &&
1293 (msg->prismheader.data == P80211ENUM_truth_true)) {
1295 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1296 } else if ((msg->wlanheader.status ==
1297 P80211ENUM_msgitem_status_data_ok) &&
1298 (msg->wlanheader.data == P80211ENUM_truth_true)) {
1300 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1302 wlandev->netdev->type = ARPHRD_IEEE80211;
1305 msg->resultcode.data = P80211ENUM_resultcode_success;
1308 msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
1313 msg->resultcode.data = P80211ENUM_resultcode_refused;