assoc.c 19 KB

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