assoc.c 20 KB

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