assoc.c 19 KB

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