assoc.c 19 KB

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