assoc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /* Copyright (C) 2006, Red Hat, Inc. */
  2. #include <linux/bitops.h>
  3. #include <net/ieee80211.h>
  4. #include <linux/etherdevice.h>
  5. #include "assoc.h"
  6. #include "join.h"
  7. #include "decl.h"
  8. #include "hostcmd.h"
  9. #include "host.h"
  10. static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  11. static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  12. static void print_assoc_req(const char * extra, struct assoc_request * assoc_req)
  13. {
  14. lbs_deb_assoc(
  15. "#### Association Request: %s\n"
  16. " flags: 0x%08lX\n"
  17. " SSID: '%s'\n"
  18. " channel: %d\n"
  19. " band: %d\n"
  20. " mode: %d\n"
  21. " BSSID: " MAC_FMT "\n"
  22. " Encryption:%s%s%s\n"
  23. " auth: %d\n",
  24. extra, assoc_req->flags,
  25. escape_essid(assoc_req->ssid, assoc_req->ssid_len),
  26. assoc_req->channel, assoc_req->band, assoc_req->mode,
  27. MAC_ARG(assoc_req->bssid),
  28. assoc_req->secinfo.WPAenabled ? " WPA" : "",
  29. assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
  30. assoc_req->secinfo.wep_enabled ? " WEP" : "",
  31. assoc_req->secinfo.auth_mode);
  32. }
  33. static int assoc_helper_essid(wlan_private *priv,
  34. struct assoc_request * assoc_req)
  35. {
  36. wlan_adapter *adapter = priv->adapter;
  37. int ret = 0;
  38. struct bss_descriptor * bss;
  39. int channel = -1;
  40. lbs_deb_enter(LBS_DEB_ASSOC);
  41. /* FIXME: take channel into account when picking SSIDs if a channel
  42. * is set.
  43. */
  44. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  45. channel = assoc_req->channel;
  46. lbs_deb_assoc("New SSID requested: '%s'\n",
  47. escape_essid(assoc_req->ssid, assoc_req->ssid_len));
  48. if (assoc_req->mode == IW_MODE_INFRA) {
  49. if (adapter->prescan) {
  50. libertas_send_specific_SSID_scan(priv, assoc_req->ssid,
  51. assoc_req->ssid_len, 0);
  52. }
  53. bss = libertas_find_SSID_in_list(adapter, assoc_req->ssid,
  54. assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
  55. if (bss != NULL) {
  56. lbs_deb_assoc("SSID found in scan list, associating\n");
  57. memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
  58. ret = wlan_associate(priv, assoc_req);
  59. } else {
  60. lbs_deb_assoc("SSID not found; cannot associate\n");
  61. }
  62. } else if (assoc_req->mode == IW_MODE_ADHOC) {
  63. /* Scan for the network, do not save previous results. Stale
  64. * scan data will cause us to join a non-existant adhoc network
  65. */
  66. libertas_send_specific_SSID_scan(priv, assoc_req->ssid,
  67. assoc_req->ssid_len, 1);
  68. /* Search for the requested SSID in the scan table */
  69. bss = libertas_find_SSID_in_list(adapter, assoc_req->ssid,
  70. assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
  71. if (bss != NULL) {
  72. lbs_deb_assoc("SSID found, will join\n");
  73. memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
  74. libertas_join_adhoc_network(priv, assoc_req);
  75. } else {
  76. /* else send START command */
  77. lbs_deb_assoc("SSID not found, creating adhoc network\n");
  78. memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
  79. IW_ESSID_MAX_SIZE);
  80. assoc_req->bss.ssid_len = assoc_req->ssid_len;
  81. libertas_start_adhoc_network(priv, assoc_req);
  82. }
  83. }
  84. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  85. return ret;
  86. }
  87. static int assoc_helper_bssid(wlan_private *priv,
  88. struct assoc_request * assoc_req)
  89. {
  90. wlan_adapter *adapter = priv->adapter;
  91. int ret = 0;
  92. struct bss_descriptor * bss;
  93. lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID " MAC_FMT,
  94. MAC_ARG(assoc_req->bssid));
  95. /* Search for index position in list for requested MAC */
  96. bss = libertas_find_BSSID_in_list(adapter, assoc_req->bssid,
  97. assoc_req->mode);
  98. if (bss == NULL) {
  99. lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, "
  100. "cannot associate.\n", MAC_ARG(assoc_req->bssid));
  101. goto out;
  102. }
  103. memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
  104. if (assoc_req->mode == IW_MODE_INFRA) {
  105. ret = wlan_associate(priv, assoc_req);
  106. lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret);
  107. } else if (assoc_req->mode == IW_MODE_ADHOC) {
  108. libertas_join_adhoc_network(priv, assoc_req);
  109. }
  110. out:
  111. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  112. return ret;
  113. }
  114. static int assoc_helper_associate(wlan_private *priv,
  115. struct assoc_request * assoc_req)
  116. {
  117. int ret = 0, done = 0;
  118. /* If we're given and 'any' BSSID, try associating based on SSID */
  119. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  120. if (compare_ether_addr(bssid_any, assoc_req->bssid)
  121. && compare_ether_addr(bssid_off, assoc_req->bssid)) {
  122. ret = assoc_helper_bssid(priv, assoc_req);
  123. done = 1;
  124. if (ret) {
  125. lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
  126. }
  127. }
  128. }
  129. if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  130. ret = assoc_helper_essid(priv, assoc_req);
  131. if (ret) {
  132. lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret);
  133. }
  134. }
  135. return ret;
  136. }
  137. static int assoc_helper_mode(wlan_private *priv,
  138. struct assoc_request * assoc_req)
  139. {
  140. wlan_adapter *adapter = priv->adapter;
  141. int ret = 0;
  142. lbs_deb_enter(LBS_DEB_ASSOC);
  143. if (assoc_req->mode == adapter->mode)
  144. goto done;
  145. if (assoc_req->mode == IW_MODE_INFRA) {
  146. if (adapter->psstate != PS_STATE_FULL_POWER)
  147. libertas_ps_wakeup(priv, cmd_option_waitforrsp);
  148. adapter->psmode = wlan802_11powermodecam;
  149. }
  150. adapter->mode = assoc_req->mode;
  151. ret = libertas_prepare_and_send_command(priv,
  152. cmd_802_11_snmp_mib,
  153. 0, cmd_option_waitforrsp,
  154. OID_802_11_INFRASTRUCTURE_MODE,
  155. /* Shoot me now */ (void *) (size_t) assoc_req->mode);
  156. done:
  157. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  158. return ret;
  159. }
  160. static int update_channel(wlan_private * priv)
  161. {
  162. /* the channel in f/w could be out of sync, get the current channel */
  163. return libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
  164. cmd_opt_802_11_rf_channel_get,
  165. cmd_option_waitforrsp, 0, NULL);
  166. }
  167. static int assoc_helper_channel(wlan_private *priv,
  168. struct assoc_request * assoc_req)
  169. {
  170. wlan_adapter *adapter = priv->adapter;
  171. int ret = 0;
  172. lbs_deb_enter(LBS_DEB_ASSOC);
  173. ret = update_channel(priv);
  174. if (ret < 0) {
  175. lbs_deb_assoc("ASSOC: channel: error getting channel.");
  176. }
  177. if (assoc_req->channel == adapter->curbssparams.channel)
  178. goto done;
  179. lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
  180. adapter->curbssparams.channel, assoc_req->channel);
  181. ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
  182. cmd_opt_802_11_rf_channel_set,
  183. cmd_option_waitforrsp, 0, &assoc_req->channel);
  184. if (ret < 0) {
  185. lbs_deb_assoc("ASSOC: channel: error setting channel.");
  186. }
  187. ret = update_channel(priv);
  188. if (ret < 0) {
  189. lbs_deb_assoc("ASSOC: channel: error getting channel.");
  190. }
  191. if (assoc_req->channel != adapter->curbssparams.channel) {
  192. lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
  193. assoc_req->channel);
  194. goto done;
  195. }
  196. if ( assoc_req->secinfo.wep_enabled
  197. && (assoc_req->wep_keys[0].len
  198. || assoc_req->wep_keys[1].len
  199. || assoc_req->wep_keys[2].len
  200. || assoc_req->wep_keys[3].len)) {
  201. /* Make sure WEP keys are re-sent to firmware */
  202. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  203. }
  204. /* Must restart/rejoin adhoc networks after channel change */
  205. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  206. done:
  207. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  208. return ret;
  209. }
  210. static int assoc_helper_wep_keys(wlan_private *priv,
  211. struct assoc_request * assoc_req)
  212. {
  213. wlan_adapter *adapter = priv->adapter;
  214. int i;
  215. int ret = 0;
  216. lbs_deb_enter(LBS_DEB_ASSOC);
  217. /* Set or remove WEP keys */
  218. if ( assoc_req->wep_keys[0].len
  219. || assoc_req->wep_keys[1].len
  220. || assoc_req->wep_keys[2].len
  221. || assoc_req->wep_keys[3].len) {
  222. ret = libertas_prepare_and_send_command(priv,
  223. cmd_802_11_set_wep,
  224. cmd_act_add,
  225. cmd_option_waitforrsp,
  226. 0, assoc_req);
  227. } else {
  228. ret = libertas_prepare_and_send_command(priv,
  229. cmd_802_11_set_wep,
  230. cmd_act_remove,
  231. cmd_option_waitforrsp,
  232. 0, NULL);
  233. }
  234. if (ret)
  235. goto out;
  236. /* enable/disable the MAC's WEP packet filter */
  237. if (assoc_req->secinfo.wep_enabled)
  238. adapter->currentpacketfilter |= cmd_act_mac_wep_enable;
  239. else
  240. adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable;
  241. ret = libertas_set_mac_packet_filter(priv);
  242. if (ret)
  243. goto out;
  244. mutex_lock(&adapter->lock);
  245. /* Copy WEP keys into adapter wep key fields */
  246. for (i = 0; i < 4; i++) {
  247. memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
  248. sizeof(struct WLAN_802_11_KEY));
  249. }
  250. adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
  251. mutex_unlock(&adapter->lock);
  252. out:
  253. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  254. return ret;
  255. }
  256. static int assoc_helper_secinfo(wlan_private *priv,
  257. struct assoc_request * assoc_req)
  258. {
  259. wlan_adapter *adapter = priv->adapter;
  260. int ret = 0;
  261. lbs_deb_enter(LBS_DEB_ASSOC);
  262. memcpy(&adapter->secinfo, &assoc_req->secinfo,
  263. sizeof(struct wlan_802_11_security));
  264. ret = libertas_set_mac_packet_filter(priv);
  265. if (ret)
  266. goto out;
  267. /* enable/disable RSN */
  268. ret = libertas_prepare_and_send_command(priv,
  269. cmd_802_11_enable_rsn,
  270. cmd_act_set,
  271. cmd_option_waitforrsp,
  272. 0, assoc_req);
  273. out:
  274. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  275. return ret;
  276. }
  277. static int assoc_helper_wpa_keys(wlan_private *priv,
  278. struct assoc_request * assoc_req)
  279. {
  280. int ret = 0;
  281. lbs_deb_enter(LBS_DEB_ASSOC);
  282. ret = libertas_prepare_and_send_command(priv,
  283. cmd_802_11_key_material,
  284. cmd_act_set,
  285. cmd_option_waitforrsp,
  286. 0, assoc_req);
  287. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  288. return ret;
  289. }
  290. static int assoc_helper_wpa_ie(wlan_private *priv,
  291. struct assoc_request * assoc_req)
  292. {
  293. wlan_adapter *adapter = priv->adapter;
  294. int ret = 0;
  295. lbs_deb_enter(LBS_DEB_ASSOC);
  296. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  297. memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  298. adapter->wpa_ie_len = assoc_req->wpa_ie_len;
  299. } else {
  300. memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
  301. adapter->wpa_ie_len = 0;
  302. }
  303. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  304. return ret;
  305. }
  306. static int should_deauth_infrastructure(wlan_adapter *adapter,
  307. struct assoc_request * assoc_req)
  308. {
  309. if (adapter->connect_status != libertas_connected)
  310. return 0;
  311. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  312. lbs_deb_assoc("Deauthenticating due to new SSID in "
  313. " configuration request.\n");
  314. return 1;
  315. }
  316. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  317. if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  318. lbs_deb_assoc("Deauthenticating due to updated security "
  319. "info in configuration request.\n");
  320. return 1;
  321. }
  322. }
  323. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  324. lbs_deb_assoc("Deauthenticating due to new BSSID in "
  325. " configuration request.\n");
  326. return 1;
  327. }
  328. /* FIXME: deal with 'auto' mode somehow */
  329. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  330. if (assoc_req->mode != IW_MODE_INFRA)
  331. return 1;
  332. }
  333. return 0;
  334. }
  335. static int should_stop_adhoc(wlan_adapter *adapter,
  336. struct assoc_request * assoc_req)
  337. {
  338. if (adapter->connect_status != libertas_connected)
  339. return 0;
  340. if (libertas_SSID_cmp(adapter->curbssparams.ssid,
  341. adapter->curbssparams.ssid_len,
  342. assoc_req->ssid, assoc_req->ssid_len) != 0)
  343. return 1;
  344. /* FIXME: deal with 'auto' mode somehow */
  345. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  346. if (assoc_req->mode != IW_MODE_ADHOC)
  347. return 1;
  348. }
  349. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  350. if (assoc_req->channel != adapter->curbssparams.channel)
  351. return 1;
  352. }
  353. return 0;
  354. }
  355. void libertas_association_worker(struct work_struct *work)
  356. {
  357. wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
  358. wlan_adapter *adapter = priv->adapter;
  359. struct assoc_request * assoc_req = NULL;
  360. int ret = 0;
  361. int find_any_ssid = 0;
  362. lbs_deb_enter(LBS_DEB_ASSOC);
  363. mutex_lock(&adapter->lock);
  364. assoc_req = adapter->pending_assoc_req;
  365. adapter->pending_assoc_req = NULL;
  366. adapter->in_progress_assoc_req = assoc_req;
  367. mutex_unlock(&adapter->lock);
  368. if (!assoc_req)
  369. goto done;
  370. print_assoc_req(__func__, assoc_req);
  371. /* If 'any' SSID was specified, find an SSID to associate with */
  372. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  373. && !assoc_req->ssid_len)
  374. find_any_ssid = 1;
  375. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  376. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  377. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  378. && compare_ether_addr(assoc_req->bssid, bssid_off))
  379. find_any_ssid = 0;
  380. }
  381. if (find_any_ssid) {
  382. u8 new_mode;
  383. ret = libertas_find_best_network_SSID(priv, assoc_req->ssid,
  384. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  385. if (ret) {
  386. lbs_deb_assoc("Could not find best network\n");
  387. ret = -ENETUNREACH;
  388. goto out;
  389. }
  390. /* Ensure we switch to the mode of the AP */
  391. if (assoc_req->mode == IW_MODE_AUTO) {
  392. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  393. assoc_req->mode = new_mode;
  394. }
  395. }
  396. /*
  397. * Check if the attributes being changing require deauthentication
  398. * from the currently associated infrastructure access point.
  399. */
  400. if (adapter->mode == IW_MODE_INFRA) {
  401. if (should_deauth_infrastructure(adapter, assoc_req)) {
  402. ret = libertas_send_deauthentication(priv);
  403. if (ret) {
  404. lbs_deb_assoc("Deauthentication due to new "
  405. "configuration request failed: %d\n",
  406. ret);
  407. }
  408. }
  409. } else if (adapter->mode == IW_MODE_ADHOC) {
  410. if (should_stop_adhoc(adapter, assoc_req)) {
  411. ret = libertas_stop_adhoc_network(priv);
  412. if (ret) {
  413. lbs_deb_assoc("Teardown of AdHoc network due to "
  414. "new configuration request failed: %d\n",
  415. ret);
  416. }
  417. }
  418. }
  419. /* Send the various configuration bits to the firmware */
  420. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  421. ret = assoc_helper_mode(priv, assoc_req);
  422. if (ret) {
  423. lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
  424. goto out;
  425. }
  426. }
  427. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  428. ret = assoc_helper_channel(priv, assoc_req);
  429. if (ret) {
  430. lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
  431. __LINE__, ret);
  432. goto out;
  433. }
  434. }
  435. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  436. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  437. ret = assoc_helper_wep_keys(priv, assoc_req);
  438. if (ret) {
  439. lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
  440. goto out;
  441. }
  442. }
  443. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  444. ret = assoc_helper_secinfo(priv, assoc_req);
  445. if (ret) {
  446. lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
  447. goto out;
  448. }
  449. }
  450. if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  451. ret = assoc_helper_wpa_ie(priv, assoc_req);
  452. if (ret) {
  453. lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
  454. goto out;
  455. }
  456. }
  457. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  458. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  459. ret = assoc_helper_wpa_keys(priv, assoc_req);
  460. if (ret) {
  461. lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
  462. goto out;
  463. }
  464. }
  465. /* SSID/BSSID should be the _last_ config option set, because they
  466. * trigger the association attempt.
  467. */
  468. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  469. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  470. int success = 1;
  471. ret = assoc_helper_associate(priv, assoc_req);
  472. if (ret) {
  473. lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
  474. ret);
  475. success = 0;
  476. }
  477. if (adapter->connect_status != libertas_connected) {
  478. lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
  479. "not connected.\n");
  480. success = 0;
  481. }
  482. if (success) {
  483. lbs_deb_assoc("ASSOC: association attempt successful. "
  484. "Associated to '%s' (" MAC_FMT ")\n",
  485. escape_essid(adapter->curbssparams.ssid,
  486. adapter->curbssparams.ssid_len),
  487. MAC_ARG(adapter->curbssparams.bssid));
  488. libertas_prepare_and_send_command(priv,
  489. cmd_802_11_rssi,
  490. 0, cmd_option_waitforrsp, 0, NULL);
  491. libertas_prepare_and_send_command(priv,
  492. cmd_802_11_get_log,
  493. 0, cmd_option_waitforrsp, 0, NULL);
  494. } else {
  495. ret = -1;
  496. }
  497. }
  498. out:
  499. if (ret) {
  500. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  501. ret);
  502. }
  503. mutex_lock(&adapter->lock);
  504. adapter->in_progress_assoc_req = NULL;
  505. mutex_unlock(&adapter->lock);
  506. kfree(assoc_req);
  507. done:
  508. lbs_deb_leave(LBS_DEB_ASSOC);
  509. }
  510. /*
  511. * Caller MUST hold any necessary locks
  512. */
  513. struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
  514. {
  515. struct assoc_request * assoc_req;
  516. if (!adapter->pending_assoc_req) {
  517. adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  518. GFP_KERNEL);
  519. if (!adapter->pending_assoc_req) {
  520. lbs_pr_info("Not enough memory to allocate association"
  521. " request!\n");
  522. return NULL;
  523. }
  524. }
  525. /* Copy current configuration attributes to the association request,
  526. * but don't overwrite any that are already set.
  527. */
  528. assoc_req = adapter->pending_assoc_req;
  529. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  530. memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
  531. IW_ESSID_MAX_SIZE);
  532. assoc_req->ssid_len = adapter->curbssparams.ssid_len;
  533. }
  534. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  535. assoc_req->channel = adapter->curbssparams.channel;
  536. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  537. assoc_req->band = adapter->curbssparams.band;
  538. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  539. assoc_req->mode = adapter->mode;
  540. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  541. memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
  542. ETH_ALEN);
  543. }
  544. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  545. int i;
  546. for (i = 0; i < 4; i++) {
  547. memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
  548. sizeof(struct WLAN_802_11_KEY));
  549. }
  550. }
  551. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  552. assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
  553. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  554. memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
  555. sizeof(struct WLAN_802_11_KEY));
  556. }
  557. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  558. memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
  559. sizeof(struct WLAN_802_11_KEY));
  560. }
  561. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  562. memcpy(&assoc_req->secinfo, &adapter->secinfo,
  563. sizeof(struct wlan_802_11_security));
  564. }
  565. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  566. memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
  567. MAX_WPA_IE_LEN);
  568. assoc_req->wpa_ie_len = adapter->wpa_ie_len;
  569. }
  570. print_assoc_req(__func__, assoc_req);
  571. return assoc_req;
  572. }