assoc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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. int lbs_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 = ret;
  139. ret = 0;
  140. }
  141. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  142. return ret;
  143. }
  144. void lbs_sync_channel(struct work_struct *work)
  145. {
  146. struct lbs_private *priv = container_of(work, struct lbs_private,
  147. sync_channel);
  148. lbs_deb_enter(LBS_DEB_ASSOC);
  149. if (lbs_update_channel(priv))
  150. lbs_pr_info("Channel synchronization failed.");
  151. lbs_deb_leave(LBS_DEB_ASSOC);
  152. }
  153. static int assoc_helper_channel(struct lbs_private *priv,
  154. struct assoc_request * assoc_req)
  155. {
  156. int ret = 0;
  157. lbs_deb_enter(LBS_DEB_ASSOC);
  158. ret = lbs_update_channel(priv);
  159. if (ret) {
  160. lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
  161. goto done;
  162. }
  163. if (assoc_req->channel == priv->curbssparams.channel)
  164. goto done;
  165. if (priv->mesh_dev) {
  166. /* Change mesh channel first; 21.p21 firmware won't let
  167. you change channel otherwise (even though it'll return
  168. an error to this */
  169. lbs_mesh_config(priv, 0, assoc_req->channel);
  170. }
  171. lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
  172. priv->curbssparams.channel, assoc_req->channel);
  173. ret = lbs_set_channel(priv, assoc_req->channel);
  174. if (ret < 0)
  175. lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
  176. /* FIXME: shouldn't need to grab the channel _again_ after setting
  177. * it since the firmware is supposed to return the new channel, but
  178. * whatever... */
  179. ret = lbs_update_channel(priv);
  180. if (ret) {
  181. lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
  182. goto done;
  183. }
  184. if (assoc_req->channel != priv->curbssparams.channel) {
  185. lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
  186. assoc_req->channel);
  187. goto restore_mesh;
  188. }
  189. if ( assoc_req->secinfo.wep_enabled
  190. && (assoc_req->wep_keys[0].len
  191. || assoc_req->wep_keys[1].len
  192. || assoc_req->wep_keys[2].len
  193. || assoc_req->wep_keys[3].len)) {
  194. /* Make sure WEP keys are re-sent to firmware */
  195. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  196. }
  197. /* Must restart/rejoin adhoc networks after channel change */
  198. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  199. restore_mesh:
  200. if (priv->mesh_dev)
  201. lbs_mesh_config(priv, 1, priv->curbssparams.channel);
  202. done:
  203. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  204. return ret;
  205. }
  206. static int assoc_helper_wep_keys(struct lbs_private *priv,
  207. struct assoc_request * assoc_req)
  208. {
  209. int i;
  210. int ret = 0;
  211. lbs_deb_enter(LBS_DEB_ASSOC);
  212. /* Set or remove WEP keys */
  213. if ( assoc_req->wep_keys[0].len
  214. || assoc_req->wep_keys[1].len
  215. || assoc_req->wep_keys[2].len
  216. || assoc_req->wep_keys[3].len) {
  217. ret = lbs_prepare_and_send_command(priv,
  218. CMD_802_11_SET_WEP,
  219. CMD_ACT_ADD,
  220. CMD_OPTION_WAITFORRSP,
  221. 0, assoc_req);
  222. } else {
  223. ret = lbs_prepare_and_send_command(priv,
  224. CMD_802_11_SET_WEP,
  225. CMD_ACT_REMOVE,
  226. CMD_OPTION_WAITFORRSP,
  227. 0, NULL);
  228. }
  229. if (ret)
  230. goto out;
  231. /* enable/disable the MAC's WEP packet filter */
  232. if (assoc_req->secinfo.wep_enabled)
  233. priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
  234. else
  235. priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
  236. ret = lbs_set_mac_packet_filter(priv);
  237. if (ret)
  238. goto out;
  239. mutex_lock(&priv->lock);
  240. /* Copy WEP keys into priv wep key fields */
  241. for (i = 0; i < 4; i++) {
  242. memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
  243. sizeof(struct enc_key));
  244. }
  245. priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
  246. mutex_unlock(&priv->lock);
  247. out:
  248. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  249. return ret;
  250. }
  251. static int assoc_helper_secinfo(struct lbs_private *priv,
  252. struct assoc_request * assoc_req)
  253. {
  254. int ret = 0;
  255. u32 do_wpa;
  256. u32 rsn = 0;
  257. lbs_deb_enter(LBS_DEB_ASSOC);
  258. memcpy(&priv->secinfo, &assoc_req->secinfo,
  259. sizeof(struct lbs_802_11_security));
  260. ret = lbs_set_mac_packet_filter(priv);
  261. if (ret)
  262. goto out;
  263. /* If RSN is already enabled, don't try to enable it again, since
  264. * ENABLE_RSN resets internal state machines and will clobber the
  265. * 4-way WPA handshake.
  266. */
  267. /* Get RSN enabled/disabled */
  268. ret = lbs_prepare_and_send_command(priv,
  269. CMD_802_11_ENABLE_RSN,
  270. CMD_ACT_GET,
  271. CMD_OPTION_WAITFORRSP,
  272. 0, &rsn);
  273. if (ret) {
  274. lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
  275. goto out;
  276. }
  277. /* Don't re-enable RSN if it's already enabled */
  278. do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
  279. if (do_wpa == rsn)
  280. goto out;
  281. /* Set RSN enabled/disabled */
  282. rsn = do_wpa;
  283. ret = lbs_prepare_and_send_command(priv,
  284. CMD_802_11_ENABLE_RSN,
  285. CMD_ACT_SET,
  286. CMD_OPTION_WAITFORRSP,
  287. 0, &rsn);
  288. out:
  289. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  290. return ret;
  291. }
  292. static int assoc_helper_wpa_keys(struct lbs_private *priv,
  293. struct assoc_request * assoc_req)
  294. {
  295. int ret = 0;
  296. unsigned int flags = assoc_req->flags;
  297. lbs_deb_enter(LBS_DEB_ASSOC);
  298. /* Work around older firmware bug where WPA unicast and multicast
  299. * keys must be set independently. Seen in SDIO parts with firmware
  300. * version 5.0.11p0.
  301. */
  302. if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  303. clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  304. ret = lbs_prepare_and_send_command(priv,
  305. CMD_802_11_KEY_MATERIAL,
  306. CMD_ACT_SET,
  307. CMD_OPTION_WAITFORRSP,
  308. 0, assoc_req);
  309. assoc_req->flags = flags;
  310. }
  311. if (ret)
  312. goto out;
  313. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  314. clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  315. ret = lbs_prepare_and_send_command(priv,
  316. CMD_802_11_KEY_MATERIAL,
  317. CMD_ACT_SET,
  318. CMD_OPTION_WAITFORRSP,
  319. 0, assoc_req);
  320. assoc_req->flags = flags;
  321. }
  322. out:
  323. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  324. return ret;
  325. }
  326. static int assoc_helper_wpa_ie(struct lbs_private *priv,
  327. struct assoc_request * assoc_req)
  328. {
  329. int ret = 0;
  330. lbs_deb_enter(LBS_DEB_ASSOC);
  331. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  332. memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  333. priv->wpa_ie_len = assoc_req->wpa_ie_len;
  334. } else {
  335. memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
  336. priv->wpa_ie_len = 0;
  337. }
  338. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  339. return ret;
  340. }
  341. static int should_deauth_infrastructure(struct lbs_private *priv,
  342. struct assoc_request * assoc_req)
  343. {
  344. int ret = 0;
  345. lbs_deb_enter(LBS_DEB_ASSOC);
  346. if (priv->connect_status != LBS_CONNECTED)
  347. return 0;
  348. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  349. lbs_deb_assoc("Deauthenticating due to new SSID\n");
  350. ret = 1;
  351. goto out;
  352. }
  353. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  354. if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  355. lbs_deb_assoc("Deauthenticating due to new security\n");
  356. ret = 1;
  357. goto out;
  358. }
  359. }
  360. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  361. lbs_deb_assoc("Deauthenticating due to new BSSID\n");
  362. ret = 1;
  363. goto out;
  364. }
  365. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  366. lbs_deb_assoc("Deauthenticating due to channel switch\n");
  367. ret = 1;
  368. goto out;
  369. }
  370. /* FIXME: deal with 'auto' mode somehow */
  371. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  372. if (assoc_req->mode != IW_MODE_INFRA) {
  373. lbs_deb_assoc("Deauthenticating due to leaving "
  374. "infra mode\n");
  375. ret = 1;
  376. goto out;
  377. }
  378. }
  379. out:
  380. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  381. return 0;
  382. }
  383. static int should_stop_adhoc(struct lbs_private *priv,
  384. struct assoc_request * assoc_req)
  385. {
  386. lbs_deb_enter(LBS_DEB_ASSOC);
  387. if (priv->connect_status != LBS_CONNECTED)
  388. return 0;
  389. if (lbs_ssid_cmp(priv->curbssparams.ssid,
  390. priv->curbssparams.ssid_len,
  391. assoc_req->ssid, assoc_req->ssid_len) != 0)
  392. return 1;
  393. /* FIXME: deal with 'auto' mode somehow */
  394. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  395. if (assoc_req->mode != IW_MODE_ADHOC)
  396. return 1;
  397. }
  398. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  399. if (assoc_req->channel != priv->curbssparams.channel)
  400. return 1;
  401. }
  402. lbs_deb_leave(LBS_DEB_ASSOC);
  403. return 0;
  404. }
  405. void lbs_association_worker(struct work_struct *work)
  406. {
  407. struct lbs_private *priv = container_of(work, struct lbs_private,
  408. assoc_work.work);
  409. struct assoc_request * assoc_req = NULL;
  410. int ret = 0;
  411. int find_any_ssid = 0;
  412. DECLARE_MAC_BUF(mac);
  413. lbs_deb_enter(LBS_DEB_ASSOC);
  414. mutex_lock(&priv->lock);
  415. assoc_req = priv->pending_assoc_req;
  416. priv->pending_assoc_req = NULL;
  417. priv->in_progress_assoc_req = assoc_req;
  418. mutex_unlock(&priv->lock);
  419. if (!assoc_req)
  420. goto done;
  421. lbs_deb_assoc(
  422. "Association Request:\n"
  423. " flags: 0x%08lx\n"
  424. " SSID: '%s'\n"
  425. " chann: %d\n"
  426. " band: %d\n"
  427. " mode: %d\n"
  428. " BSSID: %s\n"
  429. " secinfo: %s%s%s\n"
  430. " auth_mode: %d\n",
  431. assoc_req->flags,
  432. escape_essid(assoc_req->ssid, assoc_req->ssid_len),
  433. assoc_req->channel, assoc_req->band, assoc_req->mode,
  434. print_mac(mac, assoc_req->bssid),
  435. assoc_req->secinfo.WPAenabled ? " WPA" : "",
  436. assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
  437. assoc_req->secinfo.wep_enabled ? " WEP" : "",
  438. assoc_req->secinfo.auth_mode);
  439. /* If 'any' SSID was specified, find an SSID to associate with */
  440. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
  441. && !assoc_req->ssid_len)
  442. find_any_ssid = 1;
  443. /* But don't use 'any' SSID if there's a valid locked BSSID to use */
  444. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  445. if (compare_ether_addr(assoc_req->bssid, bssid_any)
  446. && compare_ether_addr(assoc_req->bssid, bssid_off))
  447. find_any_ssid = 0;
  448. }
  449. if (find_any_ssid) {
  450. u8 new_mode;
  451. ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
  452. &assoc_req->ssid_len, assoc_req->mode, &new_mode);
  453. if (ret) {
  454. lbs_deb_assoc("Could not find best network\n");
  455. ret = -ENETUNREACH;
  456. goto out;
  457. }
  458. /* Ensure we switch to the mode of the AP */
  459. if (assoc_req->mode == IW_MODE_AUTO) {
  460. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  461. assoc_req->mode = new_mode;
  462. }
  463. }
  464. /*
  465. * Check if the attributes being changing require deauthentication
  466. * from the currently associated infrastructure access point.
  467. */
  468. if (priv->mode == IW_MODE_INFRA) {
  469. if (should_deauth_infrastructure(priv, assoc_req)) {
  470. ret = lbs_send_deauthentication(priv);
  471. if (ret) {
  472. lbs_deb_assoc("Deauthentication due to new "
  473. "configuration request failed: %d\n",
  474. ret);
  475. }
  476. }
  477. } else if (priv->mode == IW_MODE_ADHOC) {
  478. if (should_stop_adhoc(priv, assoc_req)) {
  479. ret = lbs_stop_adhoc_network(priv);
  480. if (ret) {
  481. lbs_deb_assoc("Teardown of AdHoc network due to "
  482. "new configuration request failed: %d\n",
  483. ret);
  484. }
  485. }
  486. }
  487. /* Send the various configuration bits to the firmware */
  488. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  489. ret = assoc_helper_mode(priv, assoc_req);
  490. if (ret)
  491. goto out;
  492. }
  493. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  494. ret = assoc_helper_channel(priv, assoc_req);
  495. if (ret)
  496. goto out;
  497. }
  498. if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
  499. || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
  500. ret = assoc_helper_wep_keys(priv, assoc_req);
  501. if (ret)
  502. goto out;
  503. }
  504. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  505. ret = assoc_helper_secinfo(priv, assoc_req);
  506. if (ret)
  507. goto out;
  508. }
  509. if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  510. ret = assoc_helper_wpa_ie(priv, assoc_req);
  511. if (ret)
  512. goto out;
  513. }
  514. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
  515. || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  516. ret = assoc_helper_wpa_keys(priv, assoc_req);
  517. if (ret)
  518. goto out;
  519. }
  520. /* SSID/BSSID should be the _last_ config option set, because they
  521. * trigger the association attempt.
  522. */
  523. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
  524. || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  525. int success = 1;
  526. ret = assoc_helper_associate(priv, assoc_req);
  527. if (ret) {
  528. lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
  529. ret);
  530. success = 0;
  531. }
  532. if (priv->connect_status != LBS_CONNECTED) {
  533. lbs_deb_assoc("ASSOC: association unsuccessful, "
  534. "not connected\n");
  535. success = 0;
  536. }
  537. if (success) {
  538. lbs_deb_assoc("ASSOC: associated to '%s', %s\n",
  539. escape_essid(priv->curbssparams.ssid,
  540. priv->curbssparams.ssid_len),
  541. print_mac(mac, priv->curbssparams.bssid));
  542. lbs_prepare_and_send_command(priv,
  543. CMD_802_11_RSSI,
  544. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  545. lbs_prepare_and_send_command(priv,
  546. CMD_802_11_GET_LOG,
  547. 0, CMD_OPTION_WAITFORRSP, 0, NULL);
  548. } else {
  549. ret = -1;
  550. }
  551. }
  552. out:
  553. if (ret) {
  554. lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
  555. ret);
  556. }
  557. mutex_lock(&priv->lock);
  558. priv->in_progress_assoc_req = NULL;
  559. mutex_unlock(&priv->lock);
  560. kfree(assoc_req);
  561. done:
  562. lbs_deb_leave(LBS_DEB_ASSOC);
  563. }
  564. /*
  565. * Caller MUST hold any necessary locks
  566. */
  567. struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
  568. {
  569. struct assoc_request * assoc_req;
  570. lbs_deb_enter(LBS_DEB_ASSOC);
  571. if (!priv->pending_assoc_req) {
  572. priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  573. GFP_KERNEL);
  574. if (!priv->pending_assoc_req) {
  575. lbs_pr_info("Not enough memory to allocate association"
  576. " request!\n");
  577. return NULL;
  578. }
  579. }
  580. /* Copy current configuration attributes to the association request,
  581. * but don't overwrite any that are already set.
  582. */
  583. assoc_req = priv->pending_assoc_req;
  584. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  585. memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
  586. IW_ESSID_MAX_SIZE);
  587. assoc_req->ssid_len = priv->curbssparams.ssid_len;
  588. }
  589. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  590. assoc_req->channel = priv->curbssparams.channel;
  591. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  592. assoc_req->band = priv->curbssparams.band;
  593. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  594. assoc_req->mode = priv->mode;
  595. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  596. memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
  597. ETH_ALEN);
  598. }
  599. if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
  600. int i;
  601. for (i = 0; i < 4; i++) {
  602. memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
  603. sizeof(struct enc_key));
  604. }
  605. }
  606. if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
  607. assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
  608. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  609. memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
  610. sizeof(struct enc_key));
  611. }
  612. if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  613. memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
  614. sizeof(struct enc_key));
  615. }
  616. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  617. memcpy(&assoc_req->secinfo, &priv->secinfo,
  618. sizeof(struct lbs_802_11_security));
  619. }
  620. if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
  621. memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
  622. MAX_WPA_IE_LEN);
  623. assoc_req->wpa_ie_len = priv->wpa_ie_len;
  624. }
  625. lbs_deb_leave(LBS_DEB_ASSOC);
  626. return assoc_req;
  627. }