prism2mgmt.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /* src/prism2/driver/prism2mgmt.c
  2. *
  3. * Management request handler functions.
  4. *
  5. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  6. * --------------------------------------------------------------------
  7. *
  8. * linux-wlan
  9. *
  10. * The contents of this file are subject to the Mozilla Public
  11. * License Version 1.1 (the "License"); you may not use this file
  12. * except in compliance with the License. You may obtain a copy of
  13. * the License at http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS
  16. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  17. * implied. See the License for the specific language governing
  18. * rights and limitations under the License.
  19. *
  20. * Alternatively, the contents of this file may be used under the
  21. * terms of the GNU Public License version 2 (the "GPL"), in which
  22. * case the provisions of the GPL are applicable instead of the
  23. * above. If you wish to allow the use of your version of this file
  24. * only under the terms of the GPL and not to allow others to use
  25. * your version of this file under the MPL, indicate your decision
  26. * by deleting the provisions above and replace them with the notice
  27. * and other provisions required by the GPL. If you do not delete
  28. * the provisions above, a recipient may use your version of this
  29. * file under either the MPL or the GPL.
  30. *
  31. * --------------------------------------------------------------------
  32. *
  33. * Inquiries regarding the linux-wlan Open Source project can be
  34. * made directly to:
  35. *
  36. * AbsoluteValue Systems Inc.
  37. * info@linux-wlan.com
  38. * http://www.linux-wlan.com
  39. *
  40. * --------------------------------------------------------------------
  41. *
  42. * Portions of the development of this software were funded by
  43. * Intersil Corporation as part of PRISM(R) chipset product development.
  44. *
  45. * --------------------------------------------------------------------
  46. *
  47. * The functions in this file handle management requests sent from
  48. * user mode.
  49. *
  50. * Most of these functions have two separate blocks of code that are
  51. * conditional on whether this is a station or an AP. This is used
  52. * to separate out the STA and AP responses to these management primitives.
  53. * It's a choice (good, bad, indifferent?) to have the code in the same
  54. * place so it's clear that the same primitive is implemented in both
  55. * cases but has different behavior.
  56. *
  57. * --------------------------------------------------------------------
  58. */
  59. #include <linux/if_arp.h>
  60. #include <linux/module.h>
  61. #include <linux/kernel.h>
  62. #include <linux/wait.h>
  63. #include <linux/sched.h>
  64. #include <linux/types.h>
  65. #include <linux/wireless.h>
  66. #include <linux/netdevice.h>
  67. #include <linux/delay.h>
  68. #include <linux/io.h>
  69. #include <asm/byteorder.h>
  70. #include <linux/random.h>
  71. #include <linux/usb.h>
  72. #include <linux/bitops.h>
  73. #include "p80211types.h"
  74. #include "p80211hdr.h"
  75. #include "p80211mgmt.h"
  76. #include "p80211conv.h"
  77. #include "p80211msg.h"
  78. #include "p80211netdev.h"
  79. #include "p80211metadef.h"
  80. #include "p80211metastruct.h"
  81. #include "hfa384x.h"
  82. #include "prism2mgmt.h"
  83. /* Converts 802.11 format rate specifications to prism2 */
  84. #define p80211rate_to_p2bit(n) ((((n)&~BIT(7)) == 2) ? BIT(0) : \
  85. (((n)&~BIT(7)) == 4) ? BIT(1) : \
  86. (((n)&~BIT(7)) == 11) ? BIT(2) : \
  87. (((n)&~BIT(7)) == 22) ? BIT(3) : 0)
  88. /*----------------------------------------------------------------
  89. * prism2mgmt_scan
  90. *
  91. * Initiate a scan for BSSs.
  92. *
  93. * This function corresponds to MLME-scan.request and part of
  94. * MLME-scan.confirm. As far as I can tell in the standard, there
  95. * are no restrictions on when a scan.request may be issued. We have
  96. * to handle in whatever state the driver/MAC happen to be.
  97. *
  98. * Arguments:
  99. * wlandev wlan device structure
  100. * msgp ptr to msg buffer
  101. *
  102. * Returns:
  103. * 0 success and done
  104. * <0 success, but we're waiting for something to finish.
  105. * >0 an error occurred while handling the message.
  106. * Side effects:
  107. *
  108. * Call context:
  109. * process thread (usually)
  110. * interrupt
  111. ----------------------------------------------------------------*/
  112. int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
  113. {
  114. int result = 0;
  115. hfa384x_t *hw = wlandev->priv;
  116. struct p80211msg_dot11req_scan *msg = msgp;
  117. u16 roamingmode, word;
  118. int i, timeout;
  119. int istmpenable = 0;
  120. hfa384x_HostScanRequest_data_t scanreq;
  121. /* gatekeeper check */
  122. if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
  123. hw->ident_sta_fw.minor,
  124. hw->ident_sta_fw.variant) <
  125. HFA384x_FIRMWARE_VERSION(1, 3, 2)) {
  126. netdev_err(wlandev->netdev,
  127. "HostScan not supported with current firmware (<1.3.2).\n");
  128. result = 1;
  129. msg->resultcode.data = P80211ENUM_resultcode_not_supported;
  130. goto exit;
  131. }
  132. memset(&scanreq, 0, sizeof(scanreq));
  133. /* save current roaming mode */
  134. result = hfa384x_drvr_getconfig16(hw,
  135. HFA384x_RID_CNFROAMINGMODE,
  136. &roamingmode);
  137. if (result) {
  138. netdev_err(wlandev->netdev,
  139. "getconfig(ROAMMODE) failed. result=%d\n", result);
  140. msg->resultcode.data =
  141. P80211ENUM_resultcode_implementation_failure;
  142. goto exit;
  143. }
  144. /* drop into mode 3 for the scan */
  145. result = hfa384x_drvr_setconfig16(hw,
  146. HFA384x_RID_CNFROAMINGMODE,
  147. HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
  148. if (result) {
  149. netdev_err(wlandev->netdev,
  150. "setconfig(ROAMINGMODE) failed. result=%d\n",
  151. result);
  152. msg->resultcode.data =
  153. P80211ENUM_resultcode_implementation_failure;
  154. goto exit;
  155. }
  156. /* active or passive? */
  157. if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
  158. hw->ident_sta_fw.minor,
  159. hw->ident_sta_fw.variant) >
  160. HFA384x_FIRMWARE_VERSION(1, 5, 0)) {
  161. if (msg->scantype.data != P80211ENUM_scantype_active)
  162. word = msg->maxchanneltime.data;
  163. else
  164. word = 0;
  165. result =
  166. hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL,
  167. word);
  168. if (result) {
  169. netdev_warn(wlandev->netdev,
  170. "Passive scan not supported with current firmware. (<1.5.1)\n");
  171. }
  172. }
  173. /* set up the txrate to be 2MBPS. Should be fastest basicrate... */
  174. word = HFA384x_RATEBIT_2;
  175. scanreq.txRate = cpu_to_le16(word);
  176. /* set up the channel list */
  177. word = 0;
  178. for (i = 0; i < msg->channellist.data.len; i++) {
  179. u8 channel = msg->channellist.data.data[i];
  180. if (channel > 14)
  181. continue;
  182. /* channel 1 is BIT 0 ... channel 14 is BIT 13 */
  183. word |= (1 << (channel - 1));
  184. }
  185. scanreq.channelList = cpu_to_le16(word);
  186. /* set up the ssid, if present. */
  187. scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len);
  188. memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len);
  189. /* Enable the MAC port if it's not already enabled */
  190. result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word);
  191. if (result) {
  192. netdev_err(wlandev->netdev,
  193. "getconfig(PORTSTATUS) failed. result=%d\n", result);
  194. msg->resultcode.data =
  195. P80211ENUM_resultcode_implementation_failure;
  196. goto exit;
  197. }
  198. if (word == HFA384x_PORTSTATUS_DISABLED) {
  199. u16 wordbuf[17];
  200. result = hfa384x_drvr_setconfig16(hw,
  201. HFA384x_RID_CNFROAMINGMODE,
  202. HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
  203. if (result) {
  204. netdev_err(wlandev->netdev,
  205. "setconfig(ROAMINGMODE) failed. result=%d\n",
  206. result);
  207. msg->resultcode.data =
  208. P80211ENUM_resultcode_implementation_failure;
  209. goto exit;
  210. }
  211. /* Construct a bogus SSID and assign it to OwnSSID and
  212. * DesiredSSID
  213. */
  214. wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN);
  215. get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN);
  216. result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
  217. wordbuf,
  218. HFA384x_RID_CNFOWNSSID_LEN);
  219. if (result) {
  220. netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n");
  221. msg->resultcode.data =
  222. P80211ENUM_resultcode_implementation_failure;
  223. goto exit;
  224. }
  225. result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
  226. wordbuf,
  227. HFA384x_RID_CNFDESIREDSSID_LEN);
  228. if (result) {
  229. netdev_err(wlandev->netdev,
  230. "Failed to set DesiredSSID.\n");
  231. msg->resultcode.data =
  232. P80211ENUM_resultcode_implementation_failure;
  233. goto exit;
  234. }
  235. /* bsstype */
  236. result = hfa384x_drvr_setconfig16(hw,
  237. HFA384x_RID_CNFPORTTYPE,
  238. HFA384x_PORTTYPE_IBSS);
  239. if (result) {
  240. netdev_err(wlandev->netdev,
  241. "Failed to set CNFPORTTYPE.\n");
  242. msg->resultcode.data =
  243. P80211ENUM_resultcode_implementation_failure;
  244. goto exit;
  245. }
  246. /* ibss options */
  247. result = hfa384x_drvr_setconfig16(hw,
  248. HFA384x_RID_CREATEIBSS,
  249. HFA384x_CREATEIBSS_JOINCREATEIBSS);
  250. if (result) {
  251. netdev_err(wlandev->netdev,
  252. "Failed to set CREATEIBSS.\n");
  253. msg->resultcode.data =
  254. P80211ENUM_resultcode_implementation_failure;
  255. goto exit;
  256. }
  257. result = hfa384x_drvr_enable(hw, 0);
  258. if (result) {
  259. netdev_err(wlandev->netdev,
  260. "drvr_enable(0) failed. result=%d\n",
  261. result);
  262. msg->resultcode.data =
  263. P80211ENUM_resultcode_implementation_failure;
  264. goto exit;
  265. }
  266. istmpenable = 1;
  267. }
  268. /* Figure out our timeout first Kus, then HZ */
  269. timeout = msg->channellist.data.len * msg->maxchanneltime.data;
  270. timeout = (timeout * HZ) / 1000;
  271. /* Issue the scan request */
  272. hw->scanflag = 0;
  273. result = hfa384x_drvr_setconfig(hw,
  274. HFA384x_RID_HOSTSCAN, &scanreq,
  275. sizeof(hfa384x_HostScanRequest_data_t));
  276. if (result) {
  277. netdev_err(wlandev->netdev,
  278. "setconfig(SCANREQUEST) failed. result=%d\n",
  279. result);
  280. msg->resultcode.data =
  281. P80211ENUM_resultcode_implementation_failure;
  282. goto exit;
  283. }
  284. /* sleep until info frame arrives */
  285. wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout);
  286. msg->numbss.status = P80211ENUM_msgitem_status_data_ok;
  287. if (hw->scanflag == -1)
  288. hw->scanflag = 0;
  289. msg->numbss.data = hw->scanflag;
  290. hw->scanflag = 0;
  291. /* Disable port if we temporarily enabled it. */
  292. if (istmpenable) {
  293. result = hfa384x_drvr_disable(hw, 0);
  294. if (result) {
  295. netdev_err(wlandev->netdev,
  296. "drvr_disable(0) failed. result=%d\n",
  297. result);
  298. msg->resultcode.data =
  299. P80211ENUM_resultcode_implementation_failure;
  300. goto exit;
  301. }
  302. }
  303. /* restore original roaming mode */
  304. result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE,
  305. roamingmode);
  306. if (result) {
  307. netdev_err(wlandev->netdev,
  308. "setconfig(ROAMMODE) failed. result=%d\n", result);
  309. msg->resultcode.data =
  310. P80211ENUM_resultcode_implementation_failure;
  311. goto exit;
  312. }
  313. result = 0;
  314. msg->resultcode.data = P80211ENUM_resultcode_success;
  315. exit:
  316. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  317. return result;
  318. }
  319. /*----------------------------------------------------------------
  320. * prism2mgmt_scan_results
  321. *
  322. * Retrieve the BSS description for one of the BSSs identified in
  323. * a scan.
  324. *
  325. * Arguments:
  326. * wlandev wlan device structure
  327. * msgp ptr to msg buffer
  328. *
  329. * Returns:
  330. * 0 success and done
  331. * <0 success, but we're waiting for something to finish.
  332. * >0 an error occurred while handling the message.
  333. * Side effects:
  334. *
  335. * Call context:
  336. * process thread (usually)
  337. * interrupt
  338. ----------------------------------------------------------------*/
  339. int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
  340. {
  341. int result = 0;
  342. struct p80211msg_dot11req_scan_results *req;
  343. hfa384x_t *hw = wlandev->priv;
  344. hfa384x_HScanResultSub_t *item = NULL;
  345. int count;
  346. req = (struct p80211msg_dot11req_scan_results *) msgp;
  347. req->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  348. if (!hw->scanresults) {
  349. netdev_err(wlandev->netdev,
  350. "dot11req_scan_results can only be used after a successful dot11req_scan.\n");
  351. result = 2;
  352. req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
  353. goto exit;
  354. }
  355. count = (hw->scanresults->framelen - 3) / 32;
  356. if (count > HFA384x_SCANRESULT_MAX)
  357. count = HFA384x_SCANRESULT_MAX;
  358. if (req->bssindex.data >= count) {
  359. pr_debug("requested index (%d) out of range (%d)\n",
  360. req->bssindex.data, count);
  361. result = 2;
  362. req->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
  363. goto exit;
  364. }
  365. item = &(hw->scanresults->info.hscanresult.result[req->bssindex.data]);
  366. /* signal and noise */
  367. req->signal.status = P80211ENUM_msgitem_status_data_ok;
  368. req->noise.status = P80211ENUM_msgitem_status_data_ok;
  369. req->signal.data = le16_to_cpu(item->sl);
  370. req->noise.data = le16_to_cpu(item->anl);
  371. /* BSSID */
  372. req->bssid.status = P80211ENUM_msgitem_status_data_ok;
  373. req->bssid.data.len = WLAN_BSSID_LEN;
  374. memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN);
  375. /* SSID */
  376. req->ssid.status = P80211ENUM_msgitem_status_data_ok;
  377. req->ssid.data.len = le16_to_cpu(item->ssid.len);
  378. req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN);
  379. memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len);
  380. /* supported rates */
  381. for (count = 0; count < 10; count++)
  382. if (item->supprates[count] == 0)
  383. break;
  384. #define REQBASICRATE(N) \
  385. do { \
  386. if ((count >= N) && DOT11_RATE5_ISBASIC_GET( \
  387. item->supprates[(N)-1])) { \
  388. req->basicrate ## N .data = item->supprates[(N)-1]; \
  389. req->basicrate ## N .status = \
  390. P80211ENUM_msgitem_status_data_ok; \
  391. } \
  392. } while (0)
  393. REQBASICRATE(1);
  394. REQBASICRATE(2);
  395. REQBASICRATE(3);
  396. REQBASICRATE(4);
  397. REQBASICRATE(5);
  398. REQBASICRATE(6);
  399. REQBASICRATE(7);
  400. REQBASICRATE(8);
  401. #define REQSUPPRATE(N) \
  402. do { \
  403. if (count >= N) { \
  404. req->supprate ## N .data = item->supprates[(N)-1]; \
  405. req->supprate ## N .status = \
  406. P80211ENUM_msgitem_status_data_ok; \
  407. } \
  408. } while (0)
  409. REQSUPPRATE(1);
  410. REQSUPPRATE(2);
  411. REQSUPPRATE(3);
  412. REQSUPPRATE(4);
  413. REQSUPPRATE(5);
  414. REQSUPPRATE(6);
  415. REQSUPPRATE(7);
  416. REQSUPPRATE(8);
  417. /* beacon period */
  418. req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok;
  419. req->beaconperiod.data = le16_to_cpu(item->bcnint);
  420. /* timestamps */
  421. req->timestamp.status = P80211ENUM_msgitem_status_data_ok;
  422. req->timestamp.data = jiffies;
  423. req->localtime.status = P80211ENUM_msgitem_status_data_ok;
  424. req->localtime.data = jiffies;
  425. /* atim window */
  426. req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok;
  427. req->ibssatimwindow.data = le16_to_cpu(item->atim);
  428. /* Channel */
  429. req->dschannel.status = P80211ENUM_msgitem_status_data_ok;
  430. req->dschannel.data = le16_to_cpu(item->chid);
  431. /* capinfo bits */
  432. count = le16_to_cpu(item->capinfo);
  433. req->capinfo.status = P80211ENUM_msgitem_status_data_ok;
  434. req->capinfo.data = count;
  435. /* privacy flag */
  436. req->privacy.status = P80211ENUM_msgitem_status_data_ok;
  437. req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count);
  438. /* cfpollable */
  439. req->cfpollable.status = P80211ENUM_msgitem_status_data_ok;
  440. req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count);
  441. /* cfpollreq */
  442. req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok;
  443. req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count);
  444. /* bsstype */
  445. req->bsstype.status = P80211ENUM_msgitem_status_data_ok;
  446. req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ?
  447. P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent;
  448. result = 0;
  449. req->resultcode.data = P80211ENUM_resultcode_success;
  450. exit:
  451. return result;
  452. }
  453. /*----------------------------------------------------------------
  454. * prism2mgmt_start
  455. *
  456. * Start a BSS. Any station can do this for IBSS, only AP for ESS.
  457. *
  458. * Arguments:
  459. * wlandev wlan device structure
  460. * msgp ptr to msg buffer
  461. *
  462. * Returns:
  463. * 0 success and done
  464. * <0 success, but we're waiting for something to finish.
  465. * >0 an error occurred while handling the message.
  466. * Side effects:
  467. *
  468. * Call context:
  469. * process thread (usually)
  470. * interrupt
  471. ----------------------------------------------------------------*/
  472. int prism2mgmt_start(wlandevice_t *wlandev, void *msgp)
  473. {
  474. int result = 0;
  475. hfa384x_t *hw = wlandev->priv;
  476. struct p80211msg_dot11req_start *msg = msgp;
  477. p80211pstrd_t *pstr;
  478. u8 bytebuf[80];
  479. struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
  480. u16 word;
  481. wlandev->macmode = WLAN_MACMODE_NONE;
  482. /* Set the SSID */
  483. memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
  484. /*** ADHOC IBSS ***/
  485. /* see if current f/w is less than 8c3 */
  486. if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major,
  487. hw->ident_sta_fw.minor,
  488. hw->ident_sta_fw.variant) <
  489. HFA384x_FIRMWARE_VERSION(0, 8, 3)) {
  490. /* Ad-Hoc not quite supported on Prism2 */
  491. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  492. msg->resultcode.data = P80211ENUM_resultcode_not_supported;
  493. goto done;
  494. }
  495. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  496. /*** STATION ***/
  497. /* Set the REQUIRED config items */
  498. /* SSID */
  499. pstr = (p80211pstrd_t *) &(msg->ssid.data);
  500. prism2mgmt_pstr2bytestr(p2bytestr, pstr);
  501. result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID,
  502. bytebuf, HFA384x_RID_CNFOWNSSID_LEN);
  503. if (result) {
  504. netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n");
  505. goto failed;
  506. }
  507. result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
  508. bytebuf,
  509. HFA384x_RID_CNFDESIREDSSID_LEN);
  510. if (result) {
  511. netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n");
  512. goto failed;
  513. }
  514. /* bsstype - we use the default in the ap firmware */
  515. /* IBSS port */
  516. hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0);
  517. /* beacon period */
  518. word = msg->beaconperiod.data;
  519. result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNint, word);
  520. if (result) {
  521. netdev_err(wlandev->netdev,
  522. "Failed to set beacon period=%d.\n", word);
  523. goto failed;
  524. }
  525. /* dschannel */
  526. word = msg->dschannel.data;
  527. result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word);
  528. if (result) {
  529. netdev_err(wlandev->netdev,
  530. "Failed to set channel=%d.\n", word);
  531. goto failed;
  532. }
  533. /* Basic rates */
  534. word = p80211rate_to_p2bit(msg->basicrate1.data);
  535. if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok)
  536. word |= p80211rate_to_p2bit(msg->basicrate2.data);
  537. if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok)
  538. word |= p80211rate_to_p2bit(msg->basicrate3.data);
  539. if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok)
  540. word |= p80211rate_to_p2bit(msg->basicrate4.data);
  541. if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok)
  542. word |= p80211rate_to_p2bit(msg->basicrate5.data);
  543. if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok)
  544. word |= p80211rate_to_p2bit(msg->basicrate6.data);
  545. if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok)
  546. word |= p80211rate_to_p2bit(msg->basicrate7.data);
  547. if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok)
  548. word |= p80211rate_to_p2bit(msg->basicrate8.data);
  549. result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word);
  550. if (result) {
  551. netdev_err(wlandev->netdev,
  552. "Failed to set basicrates=%d.\n", word);
  553. goto failed;
  554. }
  555. /* Operational rates (supprates and txratecontrol) */
  556. word = p80211rate_to_p2bit(msg->operationalrate1.data);
  557. if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok)
  558. word |= p80211rate_to_p2bit(msg->operationalrate2.data);
  559. if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok)
  560. word |= p80211rate_to_p2bit(msg->operationalrate3.data);
  561. if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok)
  562. word |= p80211rate_to_p2bit(msg->operationalrate4.data);
  563. if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok)
  564. word |= p80211rate_to_p2bit(msg->operationalrate5.data);
  565. if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok)
  566. word |= p80211rate_to_p2bit(msg->operationalrate6.data);
  567. if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok)
  568. word |= p80211rate_to_p2bit(msg->operationalrate7.data);
  569. if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok)
  570. word |= p80211rate_to_p2bit(msg->operationalrate8.data);
  571. result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word);
  572. if (result) {
  573. netdev_err(wlandev->netdev,
  574. "Failed to set supprates=%d.\n", word);
  575. goto failed;
  576. }
  577. result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word);
  578. if (result) {
  579. netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n",
  580. word);
  581. goto failed;
  582. }
  583. /* Set the macmode so the frame setup code knows what to do */
  584. if (msg->bsstype.data == P80211ENUM_bsstype_independent) {
  585. wlandev->macmode = WLAN_MACMODE_IBSS_STA;
  586. /* lets extend the data length a bit */
  587. hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304);
  588. }
  589. /* Enable the Port */
  590. result = hfa384x_drvr_enable(hw, 0);
  591. if (result) {
  592. netdev_err(wlandev->netdev,
  593. "Enable macport failed, result=%d.\n", result);
  594. goto failed;
  595. }
  596. msg->resultcode.data = P80211ENUM_resultcode_success;
  597. goto done;
  598. failed:
  599. pr_debug("Failed to set a config option, result=%d\n", result);
  600. msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
  601. done:
  602. result = 0;
  603. return result;
  604. }
  605. /*----------------------------------------------------------------
  606. * prism2mgmt_readpda
  607. *
  608. * Collect the PDA data and put it in the message.
  609. *
  610. * Arguments:
  611. * wlandev wlan device structure
  612. * msgp ptr to msg buffer
  613. *
  614. * Returns:
  615. * 0 success and done
  616. * <0 success, but we're waiting for something to finish.
  617. * >0 an error occurred while handling the message.
  618. * Side effects:
  619. *
  620. * Call context:
  621. * process thread (usually)
  622. ----------------------------------------------------------------*/
  623. int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp)
  624. {
  625. hfa384x_t *hw = wlandev->priv;
  626. struct p80211msg_p2req_readpda *msg = msgp;
  627. int result;
  628. /* We only support collecting the PDA when in the FWLOAD
  629. * state.
  630. */
  631. if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
  632. netdev_err(wlandev->netdev,
  633. "PDA may only be read in the fwload state.\n");
  634. msg->resultcode.data =
  635. P80211ENUM_resultcode_implementation_failure;
  636. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  637. } else {
  638. /* Call drvr_readpda(), it handles the auxport enable
  639. * and validating the returned PDA.
  640. */
  641. result = hfa384x_drvr_readpda(hw,
  642. msg->pda.data,
  643. HFA384x_PDA_LEN_MAX);
  644. if (result) {
  645. netdev_err(wlandev->netdev,
  646. "hfa384x_drvr_readpda() failed, result=%d\n",
  647. result);
  648. msg->resultcode.data =
  649. P80211ENUM_resultcode_implementation_failure;
  650. msg->resultcode.status =
  651. P80211ENUM_msgitem_status_data_ok;
  652. return 0;
  653. }
  654. msg->pda.status = P80211ENUM_msgitem_status_data_ok;
  655. msg->resultcode.data = P80211ENUM_resultcode_success;
  656. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  657. }
  658. return 0;
  659. }
  660. /*----------------------------------------------------------------
  661. * prism2mgmt_ramdl_state
  662. *
  663. * Establishes the beginning/end of a card RAM download session.
  664. *
  665. * It is expected that the ramdl_write() function will be called
  666. * one or more times between the 'enable' and 'disable' calls to
  667. * this function.
  668. *
  669. * Note: This function should not be called when a mac comm port
  670. * is active.
  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. int prism2mgmt_ramdl_state(wlandevice_t *wlandev, void *msgp)
  686. {
  687. hfa384x_t *hw = wlandev->priv;
  688. struct p80211msg_p2req_ramdl_state *msg = msgp;
  689. if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
  690. netdev_err(wlandev->netdev,
  691. "ramdl_state(): may only be called in the fwload state.\n");
  692. msg->resultcode.data =
  693. P80211ENUM_resultcode_implementation_failure;
  694. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  695. return 0;
  696. }
  697. /*
  698. ** Note: Interrupts are locked out if this is an AP and are NOT
  699. ** locked out if this is a station.
  700. */
  701. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  702. if (msg->enable.data == P80211ENUM_truth_true) {
  703. if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) {
  704. msg->resultcode.data =
  705. P80211ENUM_resultcode_implementation_failure;
  706. } else {
  707. msg->resultcode.data = P80211ENUM_resultcode_success;
  708. }
  709. } else {
  710. hfa384x_drvr_ramdl_disable(hw);
  711. msg->resultcode.data = P80211ENUM_resultcode_success;
  712. }
  713. return 0;
  714. }
  715. /*----------------------------------------------------------------
  716. * prism2mgmt_ramdl_write
  717. *
  718. * Writes a buffer to the card RAM using the download state. This
  719. * is for writing code to card RAM. To just read or write raw data
  720. * use the aux functions.
  721. *
  722. * Arguments:
  723. * wlandev wlan device structure
  724. * msgp ptr to msg buffer
  725. *
  726. * Returns:
  727. * 0 success and done
  728. * <0 success, but we're waiting for something to finish.
  729. * >0 an error occurred while handling the message.
  730. * Side effects:
  731. *
  732. * Call context:
  733. * process thread (usually)
  734. ----------------------------------------------------------------*/
  735. int prism2mgmt_ramdl_write(wlandevice_t *wlandev, void *msgp)
  736. {
  737. hfa384x_t *hw = wlandev->priv;
  738. struct p80211msg_p2req_ramdl_write *msg = msgp;
  739. u32 addr;
  740. u32 len;
  741. u8 *buf;
  742. if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
  743. netdev_err(wlandev->netdev,
  744. "ramdl_write(): may only be called in the fwload state.\n");
  745. msg->resultcode.data =
  746. P80211ENUM_resultcode_implementation_failure;
  747. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  748. return 0;
  749. }
  750. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  751. /* first validate the length */
  752. if (msg->len.data > sizeof(msg->data.data)) {
  753. msg->resultcode.status =
  754. P80211ENUM_resultcode_invalid_parameters;
  755. return 0;
  756. }
  757. /* call the hfa384x function to do the write */
  758. addr = msg->addr.data;
  759. len = msg->len.data;
  760. buf = msg->data.data;
  761. if (hfa384x_drvr_ramdl_write(hw, addr, buf, len))
  762. msg->resultcode.data = P80211ENUM_resultcode_refused;
  763. msg->resultcode.data = P80211ENUM_resultcode_success;
  764. return 0;
  765. }
  766. /*----------------------------------------------------------------
  767. * prism2mgmt_flashdl_state
  768. *
  769. * Establishes the beginning/end of a card Flash download session.
  770. *
  771. * It is expected that the flashdl_write() function will be called
  772. * one or more times between the 'enable' and 'disable' calls to
  773. * this function.
  774. *
  775. * Note: This function should not be called when a mac comm port
  776. * is active.
  777. *
  778. * Arguments:
  779. * wlandev wlan device structure
  780. * msgp ptr to msg buffer
  781. *
  782. * Returns:
  783. * 0 success and done
  784. * <0 success, but we're waiting for something to finish.
  785. * >0 an error occurred while handling the message.
  786. * Side effects:
  787. *
  788. * Call context:
  789. * process thread (usually)
  790. ----------------------------------------------------------------*/
  791. int prism2mgmt_flashdl_state(wlandevice_t *wlandev, void *msgp)
  792. {
  793. int result = 0;
  794. hfa384x_t *hw = wlandev->priv;
  795. struct p80211msg_p2req_flashdl_state *msg = msgp;
  796. if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
  797. netdev_err(wlandev->netdev,
  798. "flashdl_state(): may only be called in the fwload state.\n");
  799. msg->resultcode.data =
  800. P80211ENUM_resultcode_implementation_failure;
  801. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  802. return 0;
  803. }
  804. /*
  805. ** Note: Interrupts are locked out if this is an AP and are NOT
  806. ** locked out if this is a station.
  807. */
  808. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  809. if (msg->enable.data == P80211ENUM_truth_true) {
  810. if (hfa384x_drvr_flashdl_enable(hw)) {
  811. msg->resultcode.data =
  812. P80211ENUM_resultcode_implementation_failure;
  813. } else {
  814. msg->resultcode.data = P80211ENUM_resultcode_success;
  815. }
  816. } else {
  817. hfa384x_drvr_flashdl_disable(hw);
  818. msg->resultcode.data = P80211ENUM_resultcode_success;
  819. /* NOTE: At this point, the MAC is in the post-reset
  820. * state and the driver is in the fwload state.
  821. * We need to get the MAC back into the fwload
  822. * state. To do this, we set the nsdstate to HWPRESENT
  823. * and then call the ifstate function to redo everything
  824. * that got us into the fwload state.
  825. */
  826. wlandev->msdstate = WLAN_MSD_HWPRESENT;
  827. result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
  828. if (result != P80211ENUM_resultcode_success) {
  829. netdev_err(wlandev->netdev,
  830. "prism2sta_ifstate(fwload) failed, P80211ENUM_resultcode=%d\n",
  831. result);
  832. msg->resultcode.data =
  833. P80211ENUM_resultcode_implementation_failure;
  834. result = -1;
  835. }
  836. }
  837. return 0;
  838. }
  839. /*----------------------------------------------------------------
  840. * prism2mgmt_flashdl_write
  841. *
  842. *
  843. *
  844. * Arguments:
  845. * wlandev wlan device structure
  846. * msgp ptr to msg buffer
  847. *
  848. * Returns:
  849. * 0 success and done
  850. * <0 success, but we're waiting for something to finish.
  851. * >0 an error occurred while handling the message.
  852. * Side effects:
  853. *
  854. * Call context:
  855. * process thread (usually)
  856. ----------------------------------------------------------------*/
  857. int prism2mgmt_flashdl_write(wlandevice_t *wlandev, void *msgp)
  858. {
  859. hfa384x_t *hw = wlandev->priv;
  860. struct p80211msg_p2req_flashdl_write *msg = msgp;
  861. u32 addr;
  862. u32 len;
  863. u8 *buf;
  864. if (wlandev->msdstate != WLAN_MSD_FWLOAD) {
  865. netdev_err(wlandev->netdev,
  866. "flashdl_write(): may only be called in the fwload state.\n");
  867. msg->resultcode.data =
  868. P80211ENUM_resultcode_implementation_failure;
  869. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  870. return 0;
  871. }
  872. /*
  873. ** Note: Interrupts are locked out if this is an AP and are NOT
  874. ** locked out if this is a station.
  875. */
  876. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  877. /* first validate the length */
  878. if (msg->len.data > sizeof(msg->data.data)) {
  879. msg->resultcode.status =
  880. P80211ENUM_resultcode_invalid_parameters;
  881. return 0;
  882. }
  883. /* call the hfa384x function to do the write */
  884. addr = msg->addr.data;
  885. len = msg->len.data;
  886. buf = msg->data.data;
  887. if (hfa384x_drvr_flashdl_write(hw, addr, buf, len))
  888. msg->resultcode.data = P80211ENUM_resultcode_refused;
  889. msg->resultcode.data = P80211ENUM_resultcode_success;
  890. return 0;
  891. }
  892. /*----------------------------------------------------------------
  893. * prism2mgmt_autojoin
  894. *
  895. * Associate with an ESS.
  896. *
  897. * Arguments:
  898. * wlandev wlan device structure
  899. * msgp ptr to msg buffer
  900. *
  901. * Returns:
  902. * 0 success and done
  903. * <0 success, but we're waiting for something to finish.
  904. * >0 an error occurred while handling the message.
  905. * Side effects:
  906. *
  907. * Call context:
  908. * process thread (usually)
  909. * interrupt
  910. ----------------------------------------------------------------*/
  911. int prism2mgmt_autojoin(wlandevice_t *wlandev, void *msgp)
  912. {
  913. hfa384x_t *hw = wlandev->priv;
  914. int result = 0;
  915. u16 reg;
  916. u16 port_type;
  917. struct p80211msg_lnxreq_autojoin *msg = msgp;
  918. p80211pstrd_t *pstr;
  919. u8 bytebuf[256];
  920. struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *) bytebuf;
  921. wlandev->macmode = WLAN_MACMODE_NONE;
  922. /* Set the SSID */
  923. memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data));
  924. /* Disable the Port */
  925. hfa384x_drvr_disable(hw, 0);
  926. /*** STATION ***/
  927. /* Set the TxRates */
  928. hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f);
  929. /* Set the auth type */
  930. if (msg->authtype.data == P80211ENUM_authalg_sharedkey)
  931. reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY;
  932. else
  933. reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM;
  934. hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg);
  935. /* Set the ssid */
  936. memset(bytebuf, 0, 256);
  937. pstr = (p80211pstrd_t *) &(msg->ssid.data);
  938. prism2mgmt_pstr2bytestr(p2bytestr, pstr);
  939. result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID,
  940. bytebuf,
  941. HFA384x_RID_CNFDESIREDSSID_LEN);
  942. port_type = HFA384x_PORTTYPE_BSS;
  943. /* Set the PortType */
  944. hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type);
  945. /* Enable the Port */
  946. hfa384x_drvr_enable(hw, 0);
  947. /* Set the resultcode */
  948. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  949. msg->resultcode.data = P80211ENUM_resultcode_success;
  950. return result;
  951. }
  952. /*----------------------------------------------------------------
  953. * prism2mgmt_wlansniff
  954. *
  955. * Start or stop sniffing.
  956. *
  957. * Arguments:
  958. * wlandev wlan device structure
  959. * msgp ptr to msg buffer
  960. *
  961. * Returns:
  962. * 0 success and done
  963. * <0 success, but we're waiting for something to finish.
  964. * >0 an error occurred while handling the message.
  965. * Side effects:
  966. *
  967. * Call context:
  968. * process thread (usually)
  969. * interrupt
  970. ----------------------------------------------------------------*/
  971. int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
  972. {
  973. int result = 0;
  974. struct p80211msg_lnxreq_wlansniff *msg = msgp;
  975. hfa384x_t *hw = wlandev->priv;
  976. u16 word;
  977. msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
  978. switch (msg->enable.data) {
  979. case P80211ENUM_truth_false:
  980. /* Confirm that we're in monitor mode */
  981. if (wlandev->netdev->type == ARPHRD_ETHER) {
  982. msg->resultcode.data =
  983. P80211ENUM_resultcode_invalid_parameters;
  984. return 0;
  985. }
  986. /* Disable monitor mode */
  987. result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE);
  988. if (result) {
  989. pr_debug("failed to disable monitor mode, result=%d\n",
  990. result);
  991. goto failed;
  992. }
  993. /* Disable port 0 */
  994. result = hfa384x_drvr_disable(hw, 0);
  995. if (result) {
  996. pr_debug
  997. ("failed to disable port 0 after sniffing, result=%d\n",
  998. result);
  999. goto failed;
  1000. }
  1001. /* Clear the driver state */
  1002. wlandev->netdev->type = ARPHRD_ETHER;
  1003. /* Restore the wepflags */
  1004. result = hfa384x_drvr_setconfig16(hw,
  1005. HFA384x_RID_CNFWEPFLAGS,
  1006. hw->presniff_wepflags);
  1007. if (result) {
  1008. pr_debug
  1009. ("failed to restore wepflags=0x%04x, result=%d\n",
  1010. hw->presniff_wepflags, result);
  1011. goto failed;
  1012. }
  1013. /* Set the port to its prior type and enable (if necessary) */
  1014. if (hw->presniff_port_type != 0) {
  1015. word = hw->presniff_port_type;
  1016. result = hfa384x_drvr_setconfig16(hw,
  1017. HFA384x_RID_CNFPORTTYPE,
  1018. word);
  1019. if (result) {
  1020. pr_debug
  1021. ("failed to restore porttype, result=%d\n",
  1022. result);
  1023. goto failed;
  1024. }
  1025. /* Enable the port */
  1026. result = hfa384x_drvr_enable(hw, 0);
  1027. if (result) {
  1028. pr_debug("failed to enable port to presniff setting, result=%d\n",
  1029. result);
  1030. goto failed;
  1031. }
  1032. } else {
  1033. result = hfa384x_drvr_disable(hw, 0);
  1034. }
  1035. netdev_info(wlandev->netdev, "monitor mode disabled\n");
  1036. msg->resultcode.data = P80211ENUM_resultcode_success;
  1037. return 0;
  1038. case P80211ENUM_truth_true:
  1039. /* Disable the port (if enabled), only check Port 0 */
  1040. if (hw->port_enabled[0]) {
  1041. if (wlandev->netdev->type == ARPHRD_ETHER) {
  1042. /* Save macport 0 state */
  1043. result = hfa384x_drvr_getconfig16(hw,
  1044. HFA384x_RID_CNFPORTTYPE,
  1045. &(hw->presniff_port_type));
  1046. if (result) {
  1047. pr_debug
  1048. ("failed to read porttype, result=%d\n",
  1049. result);
  1050. goto failed;
  1051. }
  1052. /* Save the wepflags state */
  1053. result = hfa384x_drvr_getconfig16(hw,
  1054. HFA384x_RID_CNFWEPFLAGS,
  1055. &(hw->presniff_wepflags));
  1056. if (result) {
  1057. pr_debug
  1058. ("failed to read wepflags, result=%d\n",
  1059. result);
  1060. goto failed;
  1061. }
  1062. hfa384x_drvr_stop(hw);
  1063. result = hfa384x_drvr_start(hw);
  1064. if (result) {
  1065. pr_debug("failed to restart the card for sniffing, result=%d\n",
  1066. result);
  1067. goto failed;
  1068. }
  1069. } else {
  1070. /* Disable the port */
  1071. result = hfa384x_drvr_disable(hw, 0);
  1072. if (result) {
  1073. pr_debug("failed to enable port for sniffing, result=%d\n",
  1074. result);
  1075. goto failed;
  1076. }
  1077. }
  1078. } else {
  1079. hw->presniff_port_type = 0;
  1080. }
  1081. /* Set the channel we wish to sniff */
  1082. word = msg->channel.data;
  1083. result = hfa384x_drvr_setconfig16(hw,
  1084. HFA384x_RID_CNFOWNCHANNEL,
  1085. word);
  1086. hw->sniff_channel = word;
  1087. if (result) {
  1088. pr_debug("failed to set channel %d, result=%d\n",
  1089. word, result);
  1090. goto failed;
  1091. }
  1092. /* Now if we're already sniffing, we can skip the rest */
  1093. if (wlandev->netdev->type != ARPHRD_ETHER) {
  1094. /* Set the port type to pIbss */
  1095. word = HFA384x_PORTTYPE_PSUEDOIBSS;
  1096. result = hfa384x_drvr_setconfig16(hw,
  1097. HFA384x_RID_CNFPORTTYPE,
  1098. word);
  1099. if (result) {
  1100. pr_debug
  1101. ("failed to set porttype %d, result=%d\n",
  1102. word, result);
  1103. goto failed;
  1104. }
  1105. if ((msg->keepwepflags.status ==
  1106. P80211ENUM_msgitem_status_data_ok)
  1107. && (msg->keepwepflags.data !=
  1108. P80211ENUM_truth_true)) {
  1109. /* Set the wepflags for no decryption */
  1110. word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT |
  1111. HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
  1112. result =
  1113. hfa384x_drvr_setconfig16(hw,
  1114. HFA384x_RID_CNFWEPFLAGS,
  1115. word);
  1116. }
  1117. if (result) {
  1118. pr_debug
  1119. ("failed to set wepflags=0x%04x, result=%d\n",
  1120. word, result);
  1121. goto failed;
  1122. }
  1123. }
  1124. /* Do we want to strip the FCS in monitor mode? */
  1125. if ((msg->stripfcs.status == P80211ENUM_msgitem_status_data_ok)
  1126. && (msg->stripfcs.data == P80211ENUM_truth_true)) {
  1127. hw->sniff_fcs = 0;
  1128. } else {
  1129. hw->sniff_fcs = 1;
  1130. }
  1131. /* Do we want to truncate the packets? */
  1132. if (msg->packet_trunc.status ==
  1133. P80211ENUM_msgitem_status_data_ok) {
  1134. hw->sniff_truncate = msg->packet_trunc.data;
  1135. } else {
  1136. hw->sniff_truncate = 0;
  1137. }
  1138. /* Enable the port */
  1139. result = hfa384x_drvr_enable(hw, 0);
  1140. if (result) {
  1141. pr_debug
  1142. ("failed to enable port for sniffing, result=%d\n",
  1143. result);
  1144. goto failed;
  1145. }
  1146. /* Enable monitor mode */
  1147. result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE);
  1148. if (result) {
  1149. pr_debug("failed to enable monitor mode, result=%d\n",
  1150. result);
  1151. goto failed;
  1152. }
  1153. if (wlandev->netdev->type == ARPHRD_ETHER)
  1154. netdev_info(wlandev->netdev, "monitor mode enabled\n");
  1155. /* Set the driver state */
  1156. /* Do we want the prism2 header? */
  1157. if ((msg->prismheader.status ==
  1158. P80211ENUM_msgitem_status_data_ok)
  1159. && (msg->prismheader.data == P80211ENUM_truth_true)) {
  1160. hw->sniffhdr = 0;
  1161. wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
  1162. } else
  1163. if ((msg->wlanheader.status ==
  1164. P80211ENUM_msgitem_status_data_ok)
  1165. && (msg->wlanheader.data == P80211ENUM_truth_true)) {
  1166. hw->sniffhdr = 1;
  1167. wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
  1168. } else {
  1169. wlandev->netdev->type = ARPHRD_IEEE80211;
  1170. }
  1171. msg->resultcode.data = P80211ENUM_resultcode_success;
  1172. return 0;
  1173. default:
  1174. msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;
  1175. return 0;
  1176. }
  1177. failed:
  1178. msg->resultcode.data = P80211ENUM_resultcode_refused;
  1179. return 0;
  1180. }