assoc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. u32 do_wpa;
  268. u32 rsn = 0;
  269. lbs_deb_enter(LBS_DEB_ASSOC);
  270. memcpy(&adapter->secinfo, &assoc_req->secinfo,
  271. sizeof(struct wlan_802_11_security));
  272. ret = libertas_set_mac_packet_filter(priv);
  273. if (ret)
  274. goto out;
  275. /* If RSN is already enabled, don't try to enable it again, since
  276. * ENABLE_RSN resets internal state machines and will clobber the
  277. * 4-way WPA handshake.
  278. */
  279. /* Get RSN enabled/disabled */
  280. ret = libertas_prepare_and_send_command(priv,
  281. cmd_802_11_enable_rsn,
  282. cmd_act_set,
  283. cmd_option_waitforrsp,
  284. 0, &rsn);
  285. if (ret) {
  286. lbs_deb_assoc("Failed to get RSN status: %d", ret);
  287. goto out;
  288. }
  289. /* Don't re-enable RSN if it's already enabled */
  290. do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
  291. if (do_wpa == rsn)
  292. goto out;
  293. /* Set RSN enabled/disabled */
  294. rsn = do_wpa;
  295. ret = libertas_prepare_and_send_command(priv,
  296. cmd_802_11_enable_rsn,
  297. cmd_act_set,
  298. cmd_option_waitforrsp,
  299. 0, &rsn);
  300. out:
  301. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  302. return ret;
  303. }
  304. static int assoc_helper_wpa_keys(wlan_private *priv,
  305. struct assoc_request * assoc_req)
  306. {
  307. int ret = 0;
  308. lbs_deb_enter(LBS_DEB_ASSOC);
  309. ret = libertas_prepare_and_send_command(priv,
  310. cmd_802_11_key_material,
  311. cmd_act_set,
  312. cmd_option_waitforrsp,
  313. 0, assoc_req);
  314. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  315. return ret;
  316. }
  317. static int assoc_helper_wpa_ie(wlan_private *priv,
  318. struct assoc_request * assoc_req)
  319. {
  320. wlan_adapter *adapter = priv->adapter;
  321. int ret = 0;
  322. lbs_deb_enter(LBS_DEB_ASSOC);
  323. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  324. memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  325. adapter->wpa_ie_len = assoc_req->wpa_ie_len;
  326. } else {
  327. memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
  328. adapter->wpa_ie_len = 0;
  329. }
  330. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  331. return ret;
  332. }
  333. static int should_deauth_infrastructure(wlan_adapter *adapter,
  334. struct assoc_request * assoc_req)
  335. {
  336. if (adapter->connect_status != libertas_connected)
  337. return 0;
  338. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  339. lbs_deb_assoc("Deauthenticating due to new SSID in "
  340. " configuration request.\n");
  341. return 1;
  342. }
  343. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  344. if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  345. lbs_deb_assoc("Deauthenticating due to updated security "
  346. "info in configuration request.\n");
  347. return 1;
  348. }
  349. }
  350. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  351. lbs_deb_assoc("Deauthenticating due to new BSSID in "
  352. " configuration request.\n");
  353. return 1;
  354. }
  355. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  356. lbs_deb_assoc("Deauthenticating due to channel switch.\n");
  357. return 1;
  358. }
  359. /* FIXME: deal with 'auto' mode somehow */
  360. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  361. if (assoc_req->mode != IW_MODE_INFRA)
  362. return 1;
  363. }
  364. return 0;
  365. }
  366. static int should_stop_adhoc(wlan_adapter *adapter,
  367. struct assoc_request * assoc_req)
  368. {
  369. if (adapter->connect_status != libertas_connected)
  370. return 0;
  371. if (libertas_ssid_cmp(adapter->curbssparams.ssid,
  372. adapter->curbssparams.ssid_len,
  373. assoc_req->ssid, assoc_req->ssid_len) != 0)
  374. return 1;
  375. /* FIXME: deal with 'auto' mode somehow */
  376. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  377. if (assoc_req->mode != IW_MODE_ADHOC)
  378. return 1;
  379. }
  380. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  381. if (assoc_req->channel != adapter->curbssparams.channel)
  382. return 1;
  383. }
  384. return 0;
  385. }
  386. void libertas_association_worker(struct work_struct *work)
  387. {
  388. wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
  389. wlan_adapter *adapter = priv->adapter;
  390. struct assoc_request * assoc_req = NULL;
  391. int ret = 0;
  392. int find_any_ssid = 0;
  393. lbs_deb_enter(LBS_DEB_ASSOC);
  394. mutex_lock(&adapter->lock);
  395. assoc_req = adapter->pending_assoc_req;
  396. adapter->pending_assoc_req = NULL;
  397. adapter->in_progress_assoc_req = assoc_req;
  398. mutex_unlock(&adapter->lock);
  399. if (!assoc_req)
  400. goto done;
  401. print_assoc_req(__func__, assoc_req);
  402. /* If 'any' SSID was specified, find an SSID to associate with */
  403. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  404. && !assoc_req->ssid_len)
  405. find_any_ssid = 1;
  406. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  407. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  408. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  409. && compare_ether_addr(assoc_req->bssid, bssid_off))
  410. find_any_ssid = 0;
  411. }
  412. if (find_any_ssid) {
  413. u8 new_mode;
  414. ret = libertas_find_best_network_ssid(priv, assoc_req->ssid,
  415. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  416. if (ret) {
  417. lbs_deb_assoc("Could not find best network\n");
  418. ret = -ENETUNREACH;
  419. goto out;
  420. }
  421. /* Ensure we switch to the mode of the AP */
  422. if (assoc_req->mode == IW_MODE_AUTO) {
  423. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  424. assoc_req->mode = new_mode;
  425. }
  426. }
  427. /*
  428. * Check if the attributes being changing require deauthentication
  429. * from the currently associated infrastructure access point.
  430. */
  431. if (adapter->mode == IW_MODE_INFRA) {
  432. if (should_deauth_infrastructure(adapter, assoc_req)) {
  433. ret = libertas_send_deauthentication(priv);
  434. if (ret) {
  435. lbs_deb_assoc("Deauthentication due to new "
  436. "configuration request failed: %d\n",
  437. ret);
  438. }
  439. }
  440. } else if (adapter->mode == IW_MODE_ADHOC) {
  441. if (should_stop_adhoc(adapter, assoc_req)) {
  442. ret = libertas_stop_adhoc_network(priv);
  443. if (ret) {
  444. lbs_deb_assoc("Teardown of AdHoc network due to "
  445. "new configuration request failed: %d\n",
  446. ret);
  447. }
  448. }
  449. }
  450. /* Send the various configuration bits to the firmware */
  451. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  452. ret = assoc_helper_mode(priv, assoc_req);
  453. if (ret) {
  454. lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret);
  455. goto out;
  456. }
  457. }
  458. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  459. ret = assoc_helper_channel(priv, assoc_req);
  460. if (ret) {
  461. lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
  462. __LINE__, ret);
  463. goto out;
  464. }
  465. }
  466. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  467. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  468. ret = assoc_helper_wep_keys(priv, assoc_req);
  469. if (ret) {
  470. lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __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", __LINE__, ret);
  478. goto out;
  479. }
  480. }
  481. if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  482. ret = assoc_helper_wpa_ie(priv, assoc_req);
  483. if (ret) {
  484. lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret);
  485. goto out;
  486. }
  487. }
  488. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  489. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  490. ret = assoc_helper_wpa_keys(priv, assoc_req);
  491. if (ret) {
  492. lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret);
  493. goto out;
  494. }
  495. }
  496. /* SSID/BSSID should be the _last_ config option set, because they
  497. * trigger the association attempt.
  498. */
  499. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  500. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  501. int success = 1;
  502. ret = assoc_helper_associate(priv, assoc_req);
  503. if (ret) {
  504. lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
  505. ret);
  506. success = 0;
  507. }
  508. if (adapter->connect_status != libertas_connected) {
  509. lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, "
  510. "not connected.\n");
  511. success = 0;
  512. }
  513. if (success) {
  514. lbs_deb_assoc("ASSOC: association attempt successful. "
  515. "Associated to '%s' (" MAC_FMT ")\n",
  516. escape_essid(adapter->curbssparams.ssid,
  517. adapter->curbssparams.ssid_len),
  518. MAC_ARG(adapter->curbssparams.bssid));
  519. libertas_prepare_and_send_command(priv,
  520. cmd_802_11_rssi,
  521. 0, cmd_option_waitforrsp, 0, NULL);
  522. libertas_prepare_and_send_command(priv,
  523. cmd_802_11_get_log,
  524. 0, cmd_option_waitforrsp, 0, NULL);
  525. } else {
  526. ret = -1;
  527. }
  528. }
  529. out:
  530. if (ret) {
  531. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  532. ret);
  533. }
  534. mutex_lock(&adapter->lock);
  535. adapter->in_progress_assoc_req = NULL;
  536. mutex_unlock(&adapter->lock);
  537. kfree(assoc_req);
  538. done:
  539. lbs_deb_leave(LBS_DEB_ASSOC);
  540. }
  541. /*
  542. * Caller MUST hold any necessary locks
  543. */
  544. struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
  545. {
  546. struct assoc_request * assoc_req;
  547. if (!adapter->pending_assoc_req) {
  548. adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  549. GFP_KERNEL);
  550. if (!adapter->pending_assoc_req) {
  551. lbs_pr_info("Not enough memory to allocate association"
  552. " request!\n");
  553. return NULL;
  554. }
  555. }
  556. /* Copy current configuration attributes to the association request,
  557. * but don't overwrite any that are already set.
  558. */
  559. assoc_req = adapter->pending_assoc_req;
  560. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  561. memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
  562. IW_ESSID_MAX_SIZE);
  563. assoc_req->ssid_len = adapter->curbssparams.ssid_len;
  564. }
  565. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  566. assoc_req->channel = adapter->curbssparams.channel;
  567. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  568. assoc_req->band = adapter->curbssparams.band;
  569. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  570. assoc_req->mode = adapter->mode;
  571. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  572. memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
  573. ETH_ALEN);
  574. }
  575. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  576. int i;
  577. for (i = 0; i < 4; i++) {
  578. memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
  579. sizeof(struct WLAN_802_11_KEY));
  580. }
  581. }
  582. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  583. assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
  584. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  585. memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
  586. sizeof(struct WLAN_802_11_KEY));
  587. }
  588. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  589. memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
  590. sizeof(struct WLAN_802_11_KEY));
  591. }
  592. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  593. memcpy(&assoc_req->secinfo, &adapter->secinfo,
  594. sizeof(struct wlan_802_11_security));
  595. }
  596. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  597. memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
  598. MAX_WPA_IE_LEN);
  599. assoc_req->wpa_ie_len = adapter->wpa_ie_len;
  600. }
  601. print_assoc_req(__func__, assoc_req);
  602. return assoc_req;
  603. }