assoc.c 19 KB

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