assoc.c 19 KB

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