assoc.c 19 KB

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