assoc.c 20 KB

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