assoc.c 20 KB

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