assoc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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. void libertas_sync_channel(struct work_struct *work)
  168. {
  169. wlan_private *priv = container_of(work, wlan_private, sync_channel);
  170. if (update_channel(priv) != 0)
  171. lbs_pr_info("Channel synchronization failed.");
  172. }
  173. static int assoc_helper_channel(wlan_private *priv,
  174. struct assoc_request * assoc_req)
  175. {
  176. wlan_adapter *adapter = priv->adapter;
  177. int ret = 0;
  178. lbs_deb_enter(LBS_DEB_ASSOC);
  179. ret = update_channel(priv);
  180. if (ret < 0) {
  181. lbs_deb_assoc("ASSOC: channel: error getting channel.");
  182. }
  183. if (assoc_req->channel == adapter->curbssparams.channel)
  184. goto done;
  185. lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
  186. adapter->curbssparams.channel, assoc_req->channel);
  187. ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
  188. cmd_opt_802_11_rf_channel_set,
  189. cmd_option_waitforrsp, 0, &assoc_req->channel);
  190. if (ret < 0) {
  191. lbs_deb_assoc("ASSOC: channel: error setting channel.");
  192. }
  193. ret = update_channel(priv);
  194. if (ret < 0) {
  195. lbs_deb_assoc("ASSOC: channel: error getting channel.");
  196. }
  197. if (assoc_req->channel != adapter->curbssparams.channel) {
  198. lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
  199. assoc_req->channel);
  200. goto done;
  201. }
  202. if ( assoc_req->secinfo.wep_enabled
  203. && (assoc_req->wep_keys[0].len
  204. || assoc_req->wep_keys[1].len
  205. || assoc_req->wep_keys[2].len
  206. || assoc_req->wep_keys[3].len)) {
  207. /* Make sure WEP keys are re-sent to firmware */
  208. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  209. }
  210. /* Must restart/rejoin adhoc networks after channel change */
  211. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  212. done:
  213. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  214. return ret;
  215. }
  216. static int assoc_helper_wep_keys(wlan_private *priv,
  217. struct assoc_request * assoc_req)
  218. {
  219. wlan_adapter *adapter = priv->adapter;
  220. int i;
  221. int ret = 0;
  222. lbs_deb_enter(LBS_DEB_ASSOC);
  223. /* Set or remove WEP keys */
  224. if ( assoc_req->wep_keys[0].len
  225. || assoc_req->wep_keys[1].len
  226. || assoc_req->wep_keys[2].len
  227. || assoc_req->wep_keys[3].len) {
  228. ret = libertas_prepare_and_send_command(priv,
  229. cmd_802_11_set_wep,
  230. cmd_act_add,
  231. cmd_option_waitforrsp,
  232. 0, assoc_req);
  233. } else {
  234. ret = libertas_prepare_and_send_command(priv,
  235. cmd_802_11_set_wep,
  236. cmd_act_remove,
  237. cmd_option_waitforrsp,
  238. 0, NULL);
  239. }
  240. if (ret)
  241. goto out;
  242. /* enable/disable the MAC's WEP packet filter */
  243. if (assoc_req->secinfo.wep_enabled)
  244. adapter->currentpacketfilter |= cmd_act_mac_wep_enable;
  245. else
  246. adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable;
  247. ret = libertas_set_mac_packet_filter(priv);
  248. if (ret)
  249. goto out;
  250. mutex_lock(&adapter->lock);
  251. /* Copy WEP keys into adapter wep key fields */
  252. for (i = 0; i < 4; i++) {
  253. memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
  254. sizeof(struct WLAN_802_11_KEY));
  255. }
  256. adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
  257. mutex_unlock(&adapter->lock);
  258. out:
  259. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  260. return ret;
  261. }
  262. static int assoc_helper_secinfo(wlan_private *priv,
  263. struct assoc_request * assoc_req)
  264. {
  265. wlan_adapter *adapter = priv->adapter;
  266. int ret = 0;
  267. lbs_deb_enter(LBS_DEB_ASSOC);
  268. memcpy(&adapter->secinfo, &assoc_req->secinfo,
  269. sizeof(struct wlan_802_11_security));
  270. ret = libertas_set_mac_packet_filter(priv);
  271. if (ret)
  272. goto out;
  273. /* enable/disable RSN */
  274. ret = libertas_prepare_and_send_command(priv,
  275. cmd_802_11_enable_rsn,
  276. cmd_act_set,
  277. cmd_option_waitforrsp,
  278. 0, assoc_req);
  279. out:
  280. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  281. return ret;
  282. }
  283. static int assoc_helper_wpa_keys(wlan_private *priv,
  284. struct assoc_request * assoc_req)
  285. {
  286. int ret = 0;
  287. lbs_deb_enter(LBS_DEB_ASSOC);
  288. ret = libertas_prepare_and_send_command(priv,
  289. cmd_802_11_key_material,
  290. cmd_act_set,
  291. cmd_option_waitforrsp,
  292. 0, assoc_req);
  293. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  294. return ret;
  295. }
  296. static int assoc_helper_wpa_ie(wlan_private *priv,
  297. struct assoc_request * assoc_req)
  298. {
  299. wlan_adapter *adapter = priv->adapter;
  300. int ret = 0;
  301. lbs_deb_enter(LBS_DEB_ASSOC);
  302. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  303. memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  304. adapter->wpa_ie_len = assoc_req->wpa_ie_len;
  305. } else {
  306. memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
  307. adapter->wpa_ie_len = 0;
  308. }
  309. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  310. return ret;
  311. }
  312. static int should_deauth_infrastructure(wlan_adapter *adapter,
  313. struct assoc_request * assoc_req)
  314. {
  315. if (adapter->connect_status != libertas_connected)
  316. return 0;
  317. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  318. lbs_deb_assoc("Deauthenticating due to new SSID in "
  319. " configuration request.\n");
  320. return 1;
  321. }
  322. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  323. if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  324. lbs_deb_assoc("Deauthenticating due to updated security "
  325. "info in configuration request.\n");
  326. return 1;
  327. }
  328. }
  329. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  330. lbs_deb_assoc("Deauthenticating due to new BSSID in "
  331. " configuration request.\n");
  332. return 1;
  333. }
  334. /* FIXME: deal with 'auto' mode somehow */
  335. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  336. if (assoc_req->mode != IW_MODE_INFRA)
  337. return 1;
  338. }
  339. return 0;
  340. }
  341. static int should_stop_adhoc(wlan_adapter *adapter,
  342. struct assoc_request * assoc_req)
  343. {
  344. if (adapter->connect_status != libertas_connected)
  345. return 0;
  346. if (libertas_ssid_cmp(adapter->curbssparams.ssid,
  347. adapter->curbssparams.ssid_len,
  348. assoc_req->ssid, assoc_req->ssid_len) != 0)
  349. return 1;
  350. /* FIXME: deal with 'auto' mode somehow */
  351. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  352. if (assoc_req->mode != IW_MODE_ADHOC)
  353. return 1;
  354. }
  355. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  356. if (assoc_req->channel != adapter->curbssparams.channel)
  357. return 1;
  358. }
  359. return 0;
  360. }
  361. void libertas_association_worker(struct work_struct *work)
  362. {
  363. wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
  364. wlan_adapter *adapter = priv->adapter;
  365. struct assoc_request * assoc_req = NULL;
  366. int ret = 0;
  367. int find_any_ssid = 0;
  368. lbs_deb_enter(LBS_DEB_ASSOC);
  369. mutex_lock(&adapter->lock);
  370. assoc_req = adapter->pending_assoc_req;
  371. adapter->pending_assoc_req = NULL;
  372. adapter->in_progress_assoc_req = assoc_req;
  373. mutex_unlock(&adapter->lock);
  374. if (!assoc_req)
  375. goto done;
  376. print_assoc_req(__func__, assoc_req);
  377. /* If 'any' SSID was specified, find an SSID to associate with */
  378. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  379. && !assoc_req->ssid_len)
  380. find_any_ssid = 1;
  381. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  382. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  383. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  384. && compare_ether_addr(assoc_req->bssid, bssid_off))
  385. find_any_ssid = 0;
  386. }
  387. if (find_any_ssid) {
  388. u8 new_mode;
  389. ret = libertas_find_best_network_ssid(priv, assoc_req->ssid,
  390. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  391. if (ret) {
  392. lbs_deb_assoc("Could not find best network\n");
  393. ret = -ENETUNREACH;
  394. goto out;
  395. }
  396. /* Ensure we switch to the mode of the AP */
  397. if (assoc_req->mode == IW_MODE_AUTO) {
  398. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  399. assoc_req->mode = new_mode;
  400. }
  401. }
  402. /*
  403. * Check if the attributes being changing require deauthentication
  404. * from the currently associated infrastructure access point.
  405. */
  406. if (adapter->mode == IW_MODE_INFRA) {
  407. if (should_deauth_infrastructure(adapter, assoc_req)) {
  408. ret = libertas_send_deauthentication(priv);
  409. if (ret) {
  410. lbs_deb_assoc("Deauthentication due to new "
  411. "configuration request failed: %d\n",
  412. ret);
  413. }
  414. }
  415. } else if (adapter->mode == IW_MODE_ADHOC) {
  416. if (should_stop_adhoc(adapter, assoc_req)) {
  417. ret = libertas_stop_adhoc_network(priv);
  418. if (ret) {
  419. lbs_deb_assoc("Teardown of AdHoc network due to "
  420. "new configuration request failed: %d\n",
  421. ret);
  422. }
  423. }
  424. }
  425. /* Send the various configuration bits to the firmware */
  426. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  427. ret = assoc_helper_mode(priv, assoc_req);
  428. if (ret) {
  429. lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
  430. goto out;
  431. }
  432. }
  433. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  434. ret = assoc_helper_channel(priv, assoc_req);
  435. if (ret) {
  436. lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
  437. __LINE__, ret);
  438. goto out;
  439. }
  440. }
  441. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  442. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  443. ret = assoc_helper_wep_keys(priv, assoc_req);
  444. if (ret) {
  445. lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret);
  446. goto out;
  447. }
  448. }
  449. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  450. ret = assoc_helper_secinfo(priv, assoc_req);
  451. if (ret) {
  452. lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret);
  453. goto out;
  454. }
  455. }
  456. if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  457. ret = assoc_helper_wpa_ie(priv, assoc_req);
  458. if (ret) {
  459. lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
  460. goto out;
  461. }
  462. }
  463. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  464. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  465. ret = assoc_helper_wpa_keys(priv, assoc_req);
  466. if (ret) {
  467. lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
  468. goto out;
  469. }
  470. }
  471. /* SSID/BSSID should be the _last_ config option set, because they
  472. * trigger the association attempt.
  473. */
  474. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  475. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  476. int success = 1;
  477. ret = assoc_helper_associate(priv, assoc_req);
  478. if (ret) {
  479. lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
  480. ret);
  481. success = 0;
  482. }
  483. if (adapter->connect_status != libertas_connected) {
  484. lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
  485. "not connected.\n");
  486. success = 0;
  487. }
  488. if (success) {
  489. lbs_deb_assoc("ASSOC: association attempt successful. "
  490. "Associated to '%s' (" MAC_FMT ")\n",
  491. escape_essid(adapter->curbssparams.ssid,
  492. adapter->curbssparams.ssid_len),
  493. MAC_ARG(adapter->curbssparams.bssid));
  494. libertas_prepare_and_send_command(priv,
  495. cmd_802_11_rssi,
  496. 0, cmd_option_waitforrsp, 0, NULL);
  497. libertas_prepare_and_send_command(priv,
  498. cmd_802_11_get_log,
  499. 0, cmd_option_waitforrsp, 0, NULL);
  500. } else {
  501. ret = -1;
  502. }
  503. }
  504. out:
  505. if (ret) {
  506. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  507. ret);
  508. }
  509. mutex_lock(&adapter->lock);
  510. adapter->in_progress_assoc_req = NULL;
  511. mutex_unlock(&adapter->lock);
  512. kfree(assoc_req);
  513. done:
  514. lbs_deb_leave(LBS_DEB_ASSOC);
  515. }
  516. /*
  517. * Caller MUST hold any necessary locks
  518. */
  519. struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
  520. {
  521. struct assoc_request * assoc_req;
  522. if (!adapter->pending_assoc_req) {
  523. adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  524. GFP_KERNEL);
  525. if (!adapter->pending_assoc_req) {
  526. lbs_pr_info("Not enough memory to allocate association"
  527. " request!\n");
  528. return NULL;
  529. }
  530. }
  531. /* Copy current configuration attributes to the association request,
  532. * but don't overwrite any that are already set.
  533. */
  534. assoc_req = adapter->pending_assoc_req;
  535. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  536. memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
  537. IW_ESSID_MAX_SIZE);
  538. assoc_req->ssid_len = adapter->curbssparams.ssid_len;
  539. }
  540. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  541. assoc_req->channel = adapter->curbssparams.channel;
  542. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  543. assoc_req->band = adapter->curbssparams.band;
  544. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  545. assoc_req->mode = adapter->mode;
  546. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  547. memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
  548. ETH_ALEN);
  549. }
  550. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  551. int i;
  552. for (i = 0; i < 4; i++) {
  553. memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
  554. sizeof(struct WLAN_802_11_KEY));
  555. }
  556. }
  557. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  558. assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
  559. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  560. memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
  561. sizeof(struct WLAN_802_11_KEY));
  562. }
  563. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  564. memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
  565. sizeof(struct WLAN_802_11_KEY));
  566. }
  567. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  568. memcpy(&assoc_req->secinfo, &adapter->secinfo,
  569. sizeof(struct wlan_802_11_security));
  570. }
  571. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  572. memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
  573. MAX_WPA_IE_LEN);
  574. assoc_req->wpa_ie_len = adapter->wpa_ie_len;
  575. }
  576. print_assoc_req(__func__, assoc_req);
  577. return assoc_req;
  578. }