assoc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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, 0);
  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, 1);
  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_prepare_and_send_command(priv,
  278. CMD_802_11_KEY_MATERIAL,
  279. CMD_ACT_SET,
  280. CMD_OPTION_WAITFORRSP,
  281. 0, assoc_req);
  282. assoc_req->flags = flags;
  283. }
  284. if (ret)
  285. goto out;
  286. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  287. clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  288. ret = lbs_prepare_and_send_command(priv,
  289. CMD_802_11_KEY_MATERIAL,
  290. CMD_ACT_SET,
  291. CMD_OPTION_WAITFORRSP,
  292. 0, assoc_req);
  293. assoc_req->flags = flags;
  294. }
  295. out:
  296. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  297. return ret;
  298. }
  299. static int assoc_helper_wpa_ie(struct lbs_private *priv,
  300. struct assoc_request * assoc_req)
  301. {
  302. int ret = 0;
  303. lbs_deb_enter(LBS_DEB_ASSOC);
  304. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  305. memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  306. priv->wpa_ie_len = assoc_req->wpa_ie_len;
  307. } else {
  308. memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
  309. priv->wpa_ie_len = 0;
  310. }
  311. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  312. return ret;
  313. }
  314. static int should_deauth_infrastructure(struct lbs_private *priv,
  315. struct assoc_request * assoc_req)
  316. {
  317. int ret = 0;
  318. if (priv->connect_status != LBS_CONNECTED)
  319. return 0;
  320. lbs_deb_enter(LBS_DEB_ASSOC);
  321. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  322. lbs_deb_assoc("Deauthenticating due to new SSID\n");
  323. ret = 1;
  324. goto out;
  325. }
  326. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  327. if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  328. lbs_deb_assoc("Deauthenticating due to new security\n");
  329. ret = 1;
  330. goto out;
  331. }
  332. }
  333. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  334. lbs_deb_assoc("Deauthenticating due to new BSSID\n");
  335. ret = 1;
  336. goto out;
  337. }
  338. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  339. lbs_deb_assoc("Deauthenticating due to channel switch\n");
  340. ret = 1;
  341. goto out;
  342. }
  343. /* FIXME: deal with 'auto' mode somehow */
  344. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  345. if (assoc_req->mode != IW_MODE_INFRA) {
  346. lbs_deb_assoc("Deauthenticating due to leaving "
  347. "infra mode\n");
  348. ret = 1;
  349. goto out;
  350. }
  351. }
  352. out:
  353. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  354. return ret;
  355. }
  356. static int should_stop_adhoc(struct lbs_private *priv,
  357. struct assoc_request * assoc_req)
  358. {
  359. lbs_deb_enter(LBS_DEB_ASSOC);
  360. if (priv->connect_status != LBS_CONNECTED)
  361. return 0;
  362. if (lbs_ssid_cmp(priv->curbssparams.ssid,
  363. priv->curbssparams.ssid_len,
  364. assoc_req->ssid, assoc_req->ssid_len) != 0)
  365. return 1;
  366. /* FIXME: deal with 'auto' mode somehow */
  367. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  368. if (assoc_req->mode != IW_MODE_ADHOC)
  369. return 1;
  370. }
  371. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  372. if (assoc_req->channel != priv->curbssparams.channel)
  373. return 1;
  374. }
  375. lbs_deb_leave(LBS_DEB_ASSOC);
  376. return 0;
  377. }
  378. void lbs_association_worker(struct work_struct *work)
  379. {
  380. struct lbs_private *priv = container_of(work, struct lbs_private,
  381. assoc_work.work);
  382. struct assoc_request * assoc_req = NULL;
  383. int ret = 0;
  384. int find_any_ssid = 0;
  385. DECLARE_MAC_BUF(mac);
  386. lbs_deb_enter(LBS_DEB_ASSOC);
  387. mutex_lock(&priv->lock);
  388. assoc_req = priv->pending_assoc_req;
  389. priv->pending_assoc_req = NULL;
  390. priv->in_progress_assoc_req = assoc_req;
  391. mutex_unlock(&priv->lock);
  392. if (!assoc_req)
  393. goto done;
  394. lbs_deb_assoc(
  395. "Association Request:\n"
  396. " flags: 0x%08lx\n"
  397. " SSID: '%s'\n"
  398. " chann: %d\n"
  399. " band: %d\n"
  400. " mode: %d\n"
  401. " BSSID: %s\n"
  402. " secinfo: %s%s%s\n"
  403. " auth_mode: %d\n",
  404. assoc_req->flags,
  405. escape_essid(assoc_req->ssid, assoc_req->ssid_len),
  406. assoc_req->channel, assoc_req->band, assoc_req->mode,
  407. print_mac(mac, assoc_req->bssid),
  408. assoc_req->secinfo.WPAenabled ? " WPA" : "",
  409. assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
  410. assoc_req->secinfo.wep_enabled ? " WEP" : "",
  411. assoc_req->secinfo.auth_mode);
  412. /* If 'any' SSID was specified, find an SSID to associate with */
  413. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  414. && !assoc_req->ssid_len)
  415. find_any_ssid = 1;
  416. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  417. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  418. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  419. && compare_ether_addr(assoc_req->bssid, bssid_off))
  420. find_any_ssid = 0;
  421. }
  422. if (find_any_ssid) {
  423. u8 new_mode;
  424. ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
  425. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  426. if (ret) {
  427. lbs_deb_assoc("Could not find best network\n");
  428. ret = -ENETUNREACH;
  429. goto out;
  430. }
  431. /* Ensure we switch to the mode of the AP */
  432. if (assoc_req->mode == IW_MODE_AUTO) {
  433. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  434. assoc_req->mode = new_mode;
  435. }
  436. }
  437. /*
  438. * Check if the attributes being changing require deauthentication
  439. * from the currently associated infrastructure access point.
  440. */
  441. if (priv->mode == IW_MODE_INFRA) {
  442. if (should_deauth_infrastructure(priv, assoc_req)) {
  443. ret = lbs_send_deauthentication(priv);
  444. if (ret) {
  445. lbs_deb_assoc("Deauthentication due to new "
  446. "configuration request failed: %d\n",
  447. ret);
  448. }
  449. }
  450. } else if (priv->mode == IW_MODE_ADHOC) {
  451. if (should_stop_adhoc(priv, assoc_req)) {
  452. ret = lbs_stop_adhoc_network(priv);
  453. if (ret) {
  454. lbs_deb_assoc("Teardown of AdHoc network due to "
  455. "new configuration request failed: %d\n",
  456. ret);
  457. }
  458. }
  459. }
  460. /* Send the various configuration bits to the firmware */
  461. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  462. ret = assoc_helper_mode(priv, assoc_req);
  463. if (ret)
  464. goto out;
  465. }
  466. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  467. ret = assoc_helper_channel(priv, assoc_req);
  468. if (ret)
  469. goto out;
  470. }
  471. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  472. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  473. ret = assoc_helper_wep_keys(priv, assoc_req);
  474. if (ret)
  475. goto out;
  476. }
  477. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  478. ret = assoc_helper_secinfo(priv, assoc_req);
  479. if (ret)
  480. goto out;
  481. }
  482. if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  483. ret = assoc_helper_wpa_ie(priv, assoc_req);
  484. if (ret)
  485. goto out;
  486. }
  487. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  488. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  489. ret = assoc_helper_wpa_keys(priv, assoc_req);
  490. if (ret)
  491. goto out;
  492. }
  493. /* SSID/BSSID should be the _last_ config option set, because they
  494. * trigger the association attempt.
  495. */
  496. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  497. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  498. int success = 1;
  499. ret = assoc_helper_associate(priv, assoc_req);
  500. if (ret) {
  501. lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
  502. ret);
  503. success = 0;
  504. }
  505. if (priv->connect_status != LBS_CONNECTED) {
  506. lbs_deb_assoc("ASSOC: association unsuccessful, "
  507. "not connected\n");
  508. success = 0;
  509. }
  510. if (success) {
  511. lbs_deb_assoc("associated to %s\n",
  512. print_mac(mac, priv->curbssparams.bssid));
  513. lbs_prepare_and_send_command(priv,
  514. CMD_802_11_RSSI,
  515. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  516. lbs_prepare_and_send_command(priv,
  517. CMD_802_11_GET_LOG,
  518. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  519. } else {
  520. ret = -1;
  521. }
  522. }
  523. out:
  524. if (ret) {
  525. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  526. ret);
  527. }
  528. mutex_lock(&priv->lock);
  529. priv->in_progress_assoc_req = NULL;
  530. mutex_unlock(&priv->lock);
  531. kfree(assoc_req);
  532. done:
  533. lbs_deb_leave(LBS_DEB_ASSOC);
  534. }
  535. /*
  536. * Caller MUST hold any necessary locks
  537. */
  538. struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
  539. {
  540. struct assoc_request * assoc_req;
  541. lbs_deb_enter(LBS_DEB_ASSOC);
  542. if (!priv->pending_assoc_req) {
  543. priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  544. GFP_KERNEL);
  545. if (!priv->pending_assoc_req) {
  546. lbs_pr_info("Not enough memory to allocate association"
  547. " request!\n");
  548. return NULL;
  549. }
  550. }
  551. /* Copy current configuration attributes to the association request,
  552. * but don't overwrite any that are already set.
  553. */
  554. assoc_req = priv->pending_assoc_req;
  555. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  556. memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
  557. IW_ESSID_MAX_SIZE);
  558. assoc_req->ssid_len = priv->curbssparams.ssid_len;
  559. }
  560. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  561. assoc_req->channel = priv->curbssparams.channel;
  562. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  563. assoc_req->band = priv->curbssparams.band;
  564. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  565. assoc_req->mode = priv->mode;
  566. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  567. memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
  568. ETH_ALEN);
  569. }
  570. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  571. int i;
  572. for (i = 0; i < 4; i++) {
  573. memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
  574. sizeof(struct enc_key));
  575. }
  576. }
  577. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  578. assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
  579. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  580. memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
  581. sizeof(struct enc_key));
  582. }
  583. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  584. memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
  585. sizeof(struct enc_key));
  586. }
  587. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  588. memcpy(&assoc_req->secinfo, &priv->secinfo,
  589. sizeof(struct lbs_802_11_security));
  590. }
  591. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  592. memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
  593. MAX_WPA_IE_LEN);
  594. assoc_req->wpa_ie_len = priv->wpa_ie_len;
  595. }
  596. lbs_deb_leave(LBS_DEB_ASSOC);
  597. return assoc_req;
  598. }