assoc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
  216. else
  217. priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
  218. lbs_set_mac_control(priv);
  219. mutex_lock(&priv->lock);
  220. /* Copy WEP keys into priv wep key fields */
  221. for (i = 0; i < 4; i++) {
  222. memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
  223. sizeof(struct enc_key));
  224. }
  225. priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
  226. mutex_unlock(&priv->lock);
  227. out:
  228. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  229. return ret;
  230. }
  231. static int assoc_helper_secinfo(struct lbs_private *priv,
  232. struct assoc_request * assoc_req)
  233. {
  234. int ret = 0;
  235. uint16_t do_wpa;
  236. uint16_t rsn = 0;
  237. lbs_deb_enter(LBS_DEB_ASSOC);
  238. memcpy(&priv->secinfo, &assoc_req->secinfo,
  239. sizeof(struct lbs_802_11_security));
  240. lbs_set_mac_control(priv);
  241. /* If RSN is already enabled, don't try to enable it again, since
  242. * ENABLE_RSN resets internal state machines and will clobber the
  243. * 4-way WPA handshake.
  244. */
  245. /* Get RSN enabled/disabled */
  246. ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
  247. if (ret) {
  248. lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
  249. goto out;
  250. }
  251. /* Don't re-enable RSN if it's already enabled */
  252. do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
  253. if (do_wpa == rsn)
  254. goto out;
  255. /* Set RSN enabled/disabled */
  256. ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
  257. out:
  258. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  259. return ret;
  260. }
  261. static int assoc_helper_wpa_keys(struct lbs_private *priv,
  262. struct assoc_request * assoc_req)
  263. {
  264. int ret = 0;
  265. unsigned int flags = assoc_req->flags;
  266. lbs_deb_enter(LBS_DEB_ASSOC);
  267. /* Work around older firmware bug where WPA unicast and multicast
  268. * keys must be set independently. Seen in SDIO parts with firmware
  269. * version 5.0.11p0.
  270. */
  271. if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  272. clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  273. ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
  274. assoc_req->flags = flags;
  275. }
  276. if (ret)
  277. goto out;
  278. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  279. clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  280. ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
  281. assoc_req->flags = flags;
  282. }
  283. out:
  284. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  285. return ret;
  286. }
  287. static int assoc_helper_wpa_ie(struct lbs_private *priv,
  288. struct assoc_request * assoc_req)
  289. {
  290. int ret = 0;
  291. lbs_deb_enter(LBS_DEB_ASSOC);
  292. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  293. memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  294. priv->wpa_ie_len = assoc_req->wpa_ie_len;
  295. } else {
  296. memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
  297. priv->wpa_ie_len = 0;
  298. }
  299. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  300. return ret;
  301. }
  302. static int should_deauth_infrastructure(struct lbs_private *priv,
  303. struct assoc_request * assoc_req)
  304. {
  305. int ret = 0;
  306. if (priv->connect_status != LBS_CONNECTED)
  307. return 0;
  308. lbs_deb_enter(LBS_DEB_ASSOC);
  309. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  310. lbs_deb_assoc("Deauthenticating due to new SSID\n");
  311. ret = 1;
  312. goto out;
  313. }
  314. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  315. if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  316. lbs_deb_assoc("Deauthenticating due to new security\n");
  317. ret = 1;
  318. goto out;
  319. }
  320. }
  321. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  322. lbs_deb_assoc("Deauthenticating due to new BSSID\n");
  323. ret = 1;
  324. goto out;
  325. }
  326. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  327. lbs_deb_assoc("Deauthenticating due to channel switch\n");
  328. ret = 1;
  329. goto out;
  330. }
  331. /* FIXME: deal with 'auto' mode somehow */
  332. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  333. if (assoc_req->mode != IW_MODE_INFRA) {
  334. lbs_deb_assoc("Deauthenticating due to leaving "
  335. "infra mode\n");
  336. ret = 1;
  337. goto out;
  338. }
  339. }
  340. out:
  341. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  342. return ret;
  343. }
  344. static int should_stop_adhoc(struct lbs_private *priv,
  345. struct assoc_request * assoc_req)
  346. {
  347. lbs_deb_enter(LBS_DEB_ASSOC);
  348. if (priv->connect_status != LBS_CONNECTED)
  349. return 0;
  350. if (lbs_ssid_cmp(priv->curbssparams.ssid,
  351. priv->curbssparams.ssid_len,
  352. assoc_req->ssid, assoc_req->ssid_len) != 0)
  353. return 1;
  354. /* FIXME: deal with 'auto' mode somehow */
  355. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  356. if (assoc_req->mode != IW_MODE_ADHOC)
  357. return 1;
  358. }
  359. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  360. if (assoc_req->channel != priv->curbssparams.channel)
  361. return 1;
  362. }
  363. lbs_deb_leave(LBS_DEB_ASSOC);
  364. return 0;
  365. }
  366. void lbs_association_worker(struct work_struct *work)
  367. {
  368. struct lbs_private *priv = container_of(work, struct lbs_private,
  369. assoc_work.work);
  370. struct assoc_request * assoc_req = NULL;
  371. int ret = 0;
  372. int find_any_ssid = 0;
  373. DECLARE_MAC_BUF(mac);
  374. lbs_deb_enter(LBS_DEB_ASSOC);
  375. mutex_lock(&priv->lock);
  376. assoc_req = priv->pending_assoc_req;
  377. priv->pending_assoc_req = NULL;
  378. priv->in_progress_assoc_req = assoc_req;
  379. mutex_unlock(&priv->lock);
  380. if (!assoc_req)
  381. goto done;
  382. lbs_deb_assoc(
  383. "Association Request:\n"
  384. " flags: 0x%08lx\n"
  385. " SSID: '%s'\n"
  386. " chann: %d\n"
  387. " band: %d\n"
  388. " mode: %d\n"
  389. " BSSID: %s\n"
  390. " secinfo: %s%s%s\n"
  391. " auth_mode: %d\n",
  392. assoc_req->flags,
  393. escape_essid(assoc_req->ssid, assoc_req->ssid_len),
  394. assoc_req->channel, assoc_req->band, assoc_req->mode,
  395. print_mac(mac, assoc_req->bssid),
  396. assoc_req->secinfo.WPAenabled ? " WPA" : "",
  397. assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
  398. assoc_req->secinfo.wep_enabled ? " WEP" : "",
  399. assoc_req->secinfo.auth_mode);
  400. /* If 'any' SSID was specified, find an SSID to associate with */
  401. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  402. && !assoc_req->ssid_len)
  403. find_any_ssid = 1;
  404. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  405. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  406. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  407. && compare_ether_addr(assoc_req->bssid, bssid_off))
  408. find_any_ssid = 0;
  409. }
  410. if (find_any_ssid) {
  411. u8 new_mode;
  412. ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
  413. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  414. if (ret) {
  415. lbs_deb_assoc("Could not find best network\n");
  416. ret = -ENETUNREACH;
  417. goto out;
  418. }
  419. /* Ensure we switch to the mode of the AP */
  420. if (assoc_req->mode == IW_MODE_AUTO) {
  421. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  422. assoc_req->mode = new_mode;
  423. }
  424. }
  425. /*
  426. * Check if the attributes being changing require deauthentication
  427. * from the currently associated infrastructure access point.
  428. */
  429. if (priv->mode == IW_MODE_INFRA) {
  430. if (should_deauth_infrastructure(priv, assoc_req)) {
  431. ret = lbs_send_deauthentication(priv);
  432. if (ret) {
  433. lbs_deb_assoc("Deauthentication due to new "
  434. "configuration request failed: %d\n",
  435. ret);
  436. }
  437. }
  438. } else if (priv->mode == IW_MODE_ADHOC) {
  439. if (should_stop_adhoc(priv, assoc_req)) {
  440. ret = lbs_stop_adhoc_network(priv);
  441. if (ret) {
  442. lbs_deb_assoc("Teardown of AdHoc network due to "
  443. "new configuration request failed: %d\n",
  444. ret);
  445. }
  446. }
  447. }
  448. /* Send the various configuration bits to the firmware */
  449. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  450. ret = assoc_helper_mode(priv, assoc_req);
  451. if (ret)
  452. goto out;
  453. }
  454. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  455. ret = assoc_helper_channel(priv, assoc_req);
  456. if (ret)
  457. goto out;
  458. }
  459. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  460. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  461. ret = assoc_helper_wep_keys(priv, assoc_req);
  462. if (ret)
  463. goto out;
  464. }
  465. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  466. ret = assoc_helper_secinfo(priv, assoc_req);
  467. if (ret)
  468. goto out;
  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. goto out;
  474. }
  475. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  476. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  477. ret = assoc_helper_wpa_keys(priv, assoc_req);
  478. if (ret)
  479. goto out;
  480. }
  481. /* SSID/BSSID should be the _last_ config option set, because they
  482. * trigger the association attempt.
  483. */
  484. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  485. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  486. int success = 1;
  487. ret = assoc_helper_associate(priv, assoc_req);
  488. if (ret) {
  489. lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
  490. ret);
  491. success = 0;
  492. }
  493. if (priv->connect_status != LBS_CONNECTED) {
  494. lbs_deb_assoc("ASSOC: association unsuccessful, "
  495. "not connected\n");
  496. success = 0;
  497. }
  498. if (success) {
  499. lbs_deb_assoc("associated to %s\n",
  500. print_mac(mac, priv->curbssparams.bssid));
  501. lbs_prepare_and_send_command(priv,
  502. CMD_802_11_RSSI,
  503. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  504. lbs_prepare_and_send_command(priv,
  505. CMD_802_11_GET_LOG,
  506. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  507. } else {
  508. ret = -1;
  509. }
  510. }
  511. out:
  512. if (ret) {
  513. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  514. ret);
  515. }
  516. mutex_lock(&priv->lock);
  517. priv->in_progress_assoc_req = NULL;
  518. mutex_unlock(&priv->lock);
  519. kfree(assoc_req);
  520. done:
  521. lbs_deb_leave(LBS_DEB_ASSOC);
  522. }
  523. /*
  524. * Caller MUST hold any necessary locks
  525. */
  526. struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
  527. {
  528. struct assoc_request * assoc_req;
  529. lbs_deb_enter(LBS_DEB_ASSOC);
  530. if (!priv->pending_assoc_req) {
  531. priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  532. GFP_KERNEL);
  533. if (!priv->pending_assoc_req) {
  534. lbs_pr_info("Not enough memory to allocate association"
  535. " request!\n");
  536. return NULL;
  537. }
  538. }
  539. /* Copy current configuration attributes to the association request,
  540. * but don't overwrite any that are already set.
  541. */
  542. assoc_req = priv->pending_assoc_req;
  543. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  544. memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
  545. IW_ESSID_MAX_SIZE);
  546. assoc_req->ssid_len = priv->curbssparams.ssid_len;
  547. }
  548. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  549. assoc_req->channel = priv->curbssparams.channel;
  550. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  551. assoc_req->band = priv->curbssparams.band;
  552. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  553. assoc_req->mode = priv->mode;
  554. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  555. memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
  556. ETH_ALEN);
  557. }
  558. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  559. int i;
  560. for (i = 0; i < 4; i++) {
  561. memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
  562. sizeof(struct enc_key));
  563. }
  564. }
  565. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  566. assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
  567. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  568. memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
  569. sizeof(struct enc_key));
  570. }
  571. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  572. memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
  573. sizeof(struct enc_key));
  574. }
  575. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  576. memcpy(&assoc_req->secinfo, &priv->secinfo,
  577. sizeof(struct lbs_802_11_security));
  578. }
  579. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  580. memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
  581. MAX_WPA_IE_LEN);
  582. assoc_req->wpa_ie_len = priv->wpa_ie_len;
  583. }
  584. lbs_deb_leave(LBS_DEB_ASSOC);
  585. return assoc_req;
  586. }