assoc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. DECLARE_MAC_BUF(mac);
  15. lbs_deb_assoc(
  16. "#### Association Request: %s\n"
  17. " flags: 0x%08lX\n"
  18. " SSID: '%s'\n"
  19. " channel: %d\n"
  20. " band: %d\n"
  21. " mode: %d\n"
  22. " BSSID: %s\n"
  23. " Encryption:%s%s%s\n"
  24. " auth: %d\n",
  25. extra, assoc_req->flags,
  26. escape_essid(assoc_req->ssid, assoc_req->ssid_len),
  27. assoc_req->channel, assoc_req->band, assoc_req->mode,
  28. print_mac(mac, assoc_req->bssid),
  29. assoc_req->secinfo.WPAenabled ? " WPA" : "",
  30. assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
  31. assoc_req->secinfo.wep_enabled ? " WEP" : "",
  32. assoc_req->secinfo.auth_mode);
  33. }
  34. static int assoc_helper_essid(wlan_private *priv,
  35. struct assoc_request * assoc_req)
  36. {
  37. wlan_adapter *adapter = priv->adapter;
  38. int ret = 0;
  39. struct bss_descriptor * bss;
  40. int channel = -1;
  41. lbs_deb_enter(LBS_DEB_ASSOC);
  42. /* FIXME: take channel into account when picking SSIDs if a channel
  43. * is set.
  44. */
  45. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  46. channel = assoc_req->channel;
  47. lbs_deb_assoc("New SSID requested: '%s'\n",
  48. escape_essid(assoc_req->ssid, assoc_req->ssid_len));
  49. if (assoc_req->mode == IW_MODE_INFRA) {
  50. libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
  51. assoc_req->ssid_len, 0);
  52. bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
  53. assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
  54. if (bss != NULL) {
  55. lbs_deb_assoc("SSID found in scan list, associating\n");
  56. memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
  57. ret = wlan_associate(priv, assoc_req);
  58. } else {
  59. lbs_deb_assoc("SSID not found; cannot associate\n");
  60. }
  61. } else if (assoc_req->mode == IW_MODE_ADHOC) {
  62. /* Scan for the network, do not save previous results. Stale
  63. * scan data will cause us to join a non-existant adhoc network
  64. */
  65. libertas_send_specific_ssid_scan(priv, assoc_req->ssid,
  66. assoc_req->ssid_len, 1);
  67. /* Search for the requested SSID in the scan table */
  68. bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid,
  69. assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
  70. if (bss != NULL) {
  71. lbs_deb_assoc("SSID found, will join\n");
  72. memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
  73. libertas_join_adhoc_network(priv, assoc_req);
  74. } else {
  75. /* else send START command */
  76. lbs_deb_assoc("SSID not found, creating adhoc network\n");
  77. memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
  78. IW_ESSID_MAX_SIZE);
  79. assoc_req->bss.ssid_len = assoc_req->ssid_len;
  80. libertas_start_adhoc_network(priv, assoc_req);
  81. }
  82. }
  83. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  84. return ret;
  85. }
  86. static int assoc_helper_bssid(wlan_private *priv,
  87. struct assoc_request * assoc_req)
  88. {
  89. wlan_adapter *adapter = priv->adapter;
  90. int ret = 0;
  91. struct bss_descriptor * bss;
  92. DECLARE_MAC_BUF(mac);
  93. lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s",
  94. print_mac(mac, 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 %s not found, "
  100. "cannot associate.\n", print_mac(mac, 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 enc_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_GET,
  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. unsigned int flags = assoc_req->flags;
  309. lbs_deb_enter(LBS_DEB_ASSOC);
  310. /* Work around older firmware bug where WPA unicast and multicast
  311. * keys must be set independently. Seen in SDIO parts with firmware
  312. * version 5.0.11p0.
  313. */
  314. if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  315. clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  316. ret = libertas_prepare_and_send_command(priv,
  317. CMD_802_11_KEY_MATERIAL,
  318. CMD_ACT_SET,
  319. CMD_OPTION_WAITFORRSP,
  320. 0, assoc_req);
  321. assoc_req->flags = flags;
  322. }
  323. if (ret)
  324. goto out;
  325. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  326. clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  327. ret = libertas_prepare_and_send_command(priv,
  328. CMD_802_11_KEY_MATERIAL,
  329. CMD_ACT_SET,
  330. CMD_OPTION_WAITFORRSP,
  331. 0, assoc_req);
  332. assoc_req->flags = flags;
  333. }
  334. out:
  335. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  336. return ret;
  337. }
  338. static int assoc_helper_wpa_ie(wlan_private *priv,
  339. struct assoc_request * assoc_req)
  340. {
  341. wlan_adapter *adapter = priv->adapter;
  342. int ret = 0;
  343. lbs_deb_enter(LBS_DEB_ASSOC);
  344. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  345. memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  346. adapter->wpa_ie_len = assoc_req->wpa_ie_len;
  347. } else {
  348. memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
  349. adapter->wpa_ie_len = 0;
  350. }
  351. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  352. return ret;
  353. }
  354. static int should_deauth_infrastructure(wlan_adapter *adapter,
  355. struct assoc_request * assoc_req)
  356. {
  357. if (adapter->connect_status != LIBERTAS_CONNECTED)
  358. return 0;
  359. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  360. lbs_deb_assoc("Deauthenticating due to new SSID in "
  361. " configuration request.\n");
  362. return 1;
  363. }
  364. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  365. if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  366. lbs_deb_assoc("Deauthenticating due to updated security "
  367. "info in configuration request.\n");
  368. return 1;
  369. }
  370. }
  371. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  372. lbs_deb_assoc("Deauthenticating due to new BSSID in "
  373. " configuration request.\n");
  374. return 1;
  375. }
  376. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  377. lbs_deb_assoc("Deauthenticating due to channel switch.\n");
  378. return 1;
  379. }
  380. /* FIXME: deal with 'auto' mode somehow */
  381. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  382. if (assoc_req->mode != IW_MODE_INFRA)
  383. return 1;
  384. }
  385. return 0;
  386. }
  387. static int should_stop_adhoc(wlan_adapter *adapter,
  388. struct assoc_request * assoc_req)
  389. {
  390. if (adapter->connect_status != LIBERTAS_CONNECTED)
  391. return 0;
  392. if (libertas_ssid_cmp(adapter->curbssparams.ssid,
  393. adapter->curbssparams.ssid_len,
  394. assoc_req->ssid, assoc_req->ssid_len) != 0)
  395. return 1;
  396. /* FIXME: deal with 'auto' mode somehow */
  397. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  398. if (assoc_req->mode != IW_MODE_ADHOC)
  399. return 1;
  400. }
  401. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  402. if (assoc_req->channel != adapter->curbssparams.channel)
  403. return 1;
  404. }
  405. return 0;
  406. }
  407. void libertas_association_worker(struct work_struct *work)
  408. {
  409. wlan_private *priv = container_of(work, wlan_private, assoc_work.work);
  410. wlan_adapter *adapter = priv->adapter;
  411. struct assoc_request * assoc_req = NULL;
  412. int ret = 0;
  413. int find_any_ssid = 0;
  414. DECLARE_MAC_BUF(mac);
  415. lbs_deb_enter(LBS_DEB_ASSOC);
  416. mutex_lock(&adapter->lock);
  417. assoc_req = adapter->pending_assoc_req;
  418. adapter->pending_assoc_req = NULL;
  419. adapter->in_progress_assoc_req = assoc_req;
  420. mutex_unlock(&adapter->lock);
  421. if (!assoc_req)
  422. goto done;
  423. print_assoc_req(__func__, assoc_req);
  424. /* If 'any' SSID was specified, find an SSID to associate with */
  425. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  426. && !assoc_req->ssid_len)
  427. find_any_ssid = 1;
  428. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  429. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  430. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  431. && compare_ether_addr(assoc_req->bssid, bssid_off))
  432. find_any_ssid = 0;
  433. }
  434. if (find_any_ssid) {
  435. u8 new_mode;
  436. ret = libertas_find_best_network_ssid(priv, assoc_req->ssid,
  437. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  438. if (ret) {
  439. lbs_deb_assoc("Could not find best network\n");
  440. ret = -ENETUNREACH;
  441. goto out;
  442. }
  443. /* Ensure we switch to the mode of the AP */
  444. if (assoc_req->mode == IW_MODE_AUTO) {
  445. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  446. assoc_req->mode = new_mode;
  447. }
  448. }
  449. /*
  450. * Check if the attributes being changing require deauthentication
  451. * from the currently associated infrastructure access point.
  452. */
  453. if (adapter->mode == IW_MODE_INFRA) {
  454. if (should_deauth_infrastructure(adapter, assoc_req)) {
  455. ret = libertas_send_deauthentication(priv);
  456. if (ret) {
  457. lbs_deb_assoc("Deauthentication due to new "
  458. "configuration request failed: %d\n",
  459. ret);
  460. }
  461. }
  462. } else if (adapter->mode == IW_MODE_ADHOC) {
  463. if (should_stop_adhoc(adapter, assoc_req)) {
  464. ret = libertas_stop_adhoc_network(priv);
  465. if (ret) {
  466. lbs_deb_assoc("Teardown of AdHoc network due to "
  467. "new configuration request failed: %d\n",
  468. ret);
  469. }
  470. }
  471. }
  472. /* Send the various configuration bits to the firmware */
  473. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  474. ret = assoc_helper_mode(priv, assoc_req);
  475. if (ret) {
  476. lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n",
  477. __LINE__, ret);
  478. goto out;
  479. }
  480. }
  481. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  482. ret = assoc_helper_channel(priv, assoc_req);
  483. if (ret) {
  484. lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n",
  485. __LINE__, ret);
  486. goto out;
  487. }
  488. }
  489. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  490. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  491. ret = assoc_helper_wep_keys(priv, assoc_req);
  492. if (ret) {
  493. lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n",
  494. __LINE__, ret);
  495. goto out;
  496. }
  497. }
  498. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  499. ret = assoc_helper_secinfo(priv, assoc_req);
  500. if (ret) {
  501. lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n",
  502. __LINE__, ret);
  503. goto out;
  504. }
  505. }
  506. if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  507. ret = assoc_helper_wpa_ie(priv, assoc_req);
  508. if (ret) {
  509. lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n",
  510. __LINE__, ret);
  511. goto out;
  512. }
  513. }
  514. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  515. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  516. ret = assoc_helper_wpa_keys(priv, assoc_req);
  517. if (ret) {
  518. lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n",
  519. __LINE__, ret);
  520. goto out;
  521. }
  522. }
  523. /* SSID/BSSID should be the _last_ config option set, because they
  524. * trigger the association attempt.
  525. */
  526. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  527. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  528. int success = 1;
  529. ret = assoc_helper_associate(priv, assoc_req);
  530. if (ret) {
  531. lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
  532. ret);
  533. success = 0;
  534. }
  535. if (adapter->connect_status != LIBERTAS_CONNECTED) {
  536. lbs_deb_assoc("ASSOC: association attempt unsuccessful, "
  537. "not connected.\n");
  538. success = 0;
  539. }
  540. if (success) {
  541. lbs_deb_assoc("ASSOC: association attempt successful. "
  542. "Associated to '%s' (%s)\n",
  543. escape_essid(adapter->curbssparams.ssid,
  544. adapter->curbssparams.ssid_len),
  545. print_mac(mac, adapter->curbssparams.bssid));
  546. libertas_prepare_and_send_command(priv,
  547. CMD_802_11_RSSI,
  548. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  549. libertas_prepare_and_send_command(priv,
  550. CMD_802_11_GET_LOG,
  551. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  552. } else {
  553. ret = -1;
  554. }
  555. }
  556. out:
  557. if (ret) {
  558. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  559. ret);
  560. }
  561. mutex_lock(&adapter->lock);
  562. adapter->in_progress_assoc_req = NULL;
  563. mutex_unlock(&adapter->lock);
  564. kfree(assoc_req);
  565. done:
  566. lbs_deb_leave(LBS_DEB_ASSOC);
  567. }
  568. /*
  569. * Caller MUST hold any necessary locks
  570. */
  571. struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
  572. {
  573. struct assoc_request * assoc_req;
  574. if (!adapter->pending_assoc_req) {
  575. adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  576. GFP_KERNEL);
  577. if (!adapter->pending_assoc_req) {
  578. lbs_pr_info("Not enough memory to allocate association"
  579. " request!\n");
  580. return NULL;
  581. }
  582. }
  583. /* Copy current configuration attributes to the association request,
  584. * but don't overwrite any that are already set.
  585. */
  586. assoc_req = adapter->pending_assoc_req;
  587. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  588. memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
  589. IW_ESSID_MAX_SIZE);
  590. assoc_req->ssid_len = adapter->curbssparams.ssid_len;
  591. }
  592. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  593. assoc_req->channel = adapter->curbssparams.channel;
  594. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  595. assoc_req->band = adapter->curbssparams.band;
  596. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  597. assoc_req->mode = adapter->mode;
  598. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  599. memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
  600. ETH_ALEN);
  601. }
  602. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  603. int i;
  604. for (i = 0; i < 4; i++) {
  605. memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
  606. sizeof(struct enc_key));
  607. }
  608. }
  609. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  610. assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
  611. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  612. memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
  613. sizeof(struct enc_key));
  614. }
  615. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  616. memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
  617. sizeof(struct enc_key));
  618. }
  619. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  620. memcpy(&assoc_req->secinfo, &adapter->secinfo,
  621. sizeof(struct wlan_802_11_security));
  622. }
  623. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  624. memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
  625. MAX_WPA_IE_LEN);
  626. assoc_req->wpa_ie_len = adapter->wpa_ie_len;
  627. }
  628. print_assoc_req(__func__, assoc_req);
  629. return assoc_req;
  630. }