assoc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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(struct lbs_private *priv,
  13. struct assoc_request * assoc_req)
  14. {
  15. struct 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(struct lbs_private *priv,
  64. struct assoc_request * assoc_req)
  65. {
  66. struct 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(struct 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(struct lbs_private *priv,
  111. struct assoc_request * assoc_req)
  112. {
  113. struct 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(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_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. struct lbs_private *priv = container_of(work, struct lbs_private,
  147. sync_channel);
  148. lbs_deb_enter(LBS_DEB_ASSOC);
  149. if (update_channel(priv) != 0)
  150. lbs_pr_info("Channel synchronization failed.");
  151. lbs_deb_leave(LBS_DEB_ASSOC);
  152. }
  153. static int assoc_helper_channel(struct lbs_private *priv,
  154. struct assoc_request * assoc_req)
  155. {
  156. struct lbs_adapter *adapter = priv->adapter;
  157. int ret = 0;
  158. lbs_deb_enter(LBS_DEB_ASSOC);
  159. ret = update_channel(priv);
  160. if (ret < 0) {
  161. lbs_deb_assoc("ASSOC: channel: error getting channel.");
  162. }
  163. if (assoc_req->channel == adapter->curbssparams.channel)
  164. goto done;
  165. lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
  166. adapter->curbssparams.channel, assoc_req->channel);
  167. ret = lbs_prepare_and_send_command(priv, CMD_802_11_RF_CHANNEL,
  168. CMD_OPT_802_11_RF_CHANNEL_SET,
  169. CMD_OPTION_WAITFORRSP, 0, &assoc_req->channel);
  170. if (ret < 0) {
  171. lbs_deb_assoc("ASSOC: channel: error setting channel.");
  172. }
  173. ret = update_channel(priv);
  174. if (ret < 0) {
  175. lbs_deb_assoc("ASSOC: channel: error getting channel.");
  176. }
  177. if (assoc_req->channel != adapter->curbssparams.channel) {
  178. lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
  179. assoc_req->channel);
  180. goto done;
  181. }
  182. if ( assoc_req->secinfo.wep_enabled
  183. && (assoc_req->wep_keys[0].len
  184. || assoc_req->wep_keys[1].len
  185. || assoc_req->wep_keys[2].len
  186. || assoc_req->wep_keys[3].len)) {
  187. /* Make sure WEP keys are re-sent to firmware */
  188. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  189. }
  190. /* Must restart/rejoin adhoc networks after channel change */
  191. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  192. done:
  193. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  194. return ret;
  195. }
  196. static int assoc_helper_wep_keys(struct lbs_private *priv,
  197. struct assoc_request * assoc_req)
  198. {
  199. struct lbs_adapter *adapter = priv->adapter;
  200. int i;
  201. int ret = 0;
  202. lbs_deb_enter(LBS_DEB_ASSOC);
  203. /* Set or remove WEP keys */
  204. if ( assoc_req->wep_keys[0].len
  205. || assoc_req->wep_keys[1].len
  206. || assoc_req->wep_keys[2].len
  207. || assoc_req->wep_keys[3].len) {
  208. ret = lbs_prepare_and_send_command(priv,
  209. CMD_802_11_SET_WEP,
  210. CMD_ACT_ADD,
  211. CMD_OPTION_WAITFORRSP,
  212. 0, assoc_req);
  213. } else {
  214. ret = lbs_prepare_and_send_command(priv,
  215. CMD_802_11_SET_WEP,
  216. CMD_ACT_REMOVE,
  217. CMD_OPTION_WAITFORRSP,
  218. 0, NULL);
  219. }
  220. if (ret)
  221. goto out;
  222. /* enable/disable the MAC's WEP packet filter */
  223. if (assoc_req->secinfo.wep_enabled)
  224. adapter->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
  225. else
  226. adapter->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
  227. ret = lbs_set_mac_packet_filter(priv);
  228. if (ret)
  229. goto out;
  230. mutex_lock(&adapter->lock);
  231. /* Copy WEP keys into adapter wep key fields */
  232. for (i = 0; i < 4; i++) {
  233. memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
  234. sizeof(struct enc_key));
  235. }
  236. adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
  237. mutex_unlock(&adapter->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. struct lbs_adapter *adapter = priv->adapter;
  246. int ret = 0;
  247. u32 do_wpa;
  248. u32 rsn = 0;
  249. lbs_deb_enter(LBS_DEB_ASSOC);
  250. memcpy(&adapter->secinfo, &assoc_req->secinfo,
  251. sizeof(struct lbs_802_11_security));
  252. ret = lbs_set_mac_packet_filter(priv);
  253. if (ret)
  254. goto out;
  255. /* If RSN is already enabled, don't try to enable it again, since
  256. * ENABLE_RSN resets internal state machines and will clobber the
  257. * 4-way WPA handshake.
  258. */
  259. /* Get RSN enabled/disabled */
  260. ret = lbs_prepare_and_send_command(priv,
  261. CMD_802_11_ENABLE_RSN,
  262. CMD_ACT_GET,
  263. CMD_OPTION_WAITFORRSP,
  264. 0, &rsn);
  265. if (ret) {
  266. lbs_deb_assoc("Failed to get RSN status: %d", ret);
  267. goto out;
  268. }
  269. /* Don't re-enable RSN if it's already enabled */
  270. do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
  271. if (do_wpa == rsn)
  272. goto out;
  273. /* Set RSN enabled/disabled */
  274. rsn = do_wpa;
  275. ret = lbs_prepare_and_send_command(priv,
  276. CMD_802_11_ENABLE_RSN,
  277. CMD_ACT_SET,
  278. CMD_OPTION_WAITFORRSP,
  279. 0, &rsn);
  280. out:
  281. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  282. return ret;
  283. }
  284. static int assoc_helper_wpa_keys(struct lbs_private *priv,
  285. struct assoc_request * assoc_req)
  286. {
  287. int ret = 0;
  288. unsigned int flags = assoc_req->flags;
  289. lbs_deb_enter(LBS_DEB_ASSOC);
  290. /* Work around older firmware bug where WPA unicast and multicast
  291. * keys must be set independently. Seen in SDIO parts with firmware
  292. * version 5.0.11p0.
  293. */
  294. if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
  295. clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  296. ret = lbs_prepare_and_send_command(priv,
  297. CMD_802_11_KEY_MATERIAL,
  298. CMD_ACT_SET,
  299. CMD_OPTION_WAITFORRSP,
  300. 0, assoc_req);
  301. assoc_req->flags = flags;
  302. }
  303. if (ret)
  304. goto out;
  305. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  306. clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  307. ret = lbs_prepare_and_send_command(priv,
  308. CMD_802_11_KEY_MATERIAL,
  309. CMD_ACT_SET,
  310. CMD_OPTION_WAITFORRSP,
  311. 0, assoc_req);
  312. assoc_req->flags = flags;
  313. }
  314. out:
  315. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  316. return ret;
  317. }
  318. static int assoc_helper_wpa_ie(struct lbs_private *priv,
  319. struct assoc_request * assoc_req)
  320. {
  321. struct lbs_adapter *adapter = priv->adapter;
  322. int ret = 0;
  323. lbs_deb_enter(LBS_DEB_ASSOC);
  324. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  325. memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
  326. adapter->wpa_ie_len = assoc_req->wpa_ie_len;
  327. } else {
  328. memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
  329. adapter->wpa_ie_len = 0;
  330. }
  331. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  332. return ret;
  333. }
  334. static int should_deauth_infrastructure(struct lbs_adapter *adapter,
  335. struct assoc_request * assoc_req)
  336. {
  337. int ret = 0;
  338. lbs_deb_enter(LBS_DEB_ASSOC);
  339. if (adapter->connect_status != LBS_CONNECTED)
  340. return 0;
  341. if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  342. lbs_deb_assoc("Deauthenticating due to new SSID\n");
  343. ret = 1;
  344. goto out;
  345. }
  346. if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  347. if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
  348. lbs_deb_assoc("Deauthenticating due to new security\n");
  349. ret = 1;
  350. goto out;
  351. }
  352. }
  353. if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  354. lbs_deb_assoc("Deauthenticating due to new BSSID\n");
  355. ret = 1;
  356. goto out;
  357. }
  358. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  359. lbs_deb_assoc("Deauthenticating due to channel switch\n");
  360. ret = 1;
  361. goto out;
  362. }
  363. /* FIXME: deal with 'auto' mode somehow */
  364. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  365. if (assoc_req->mode != IW_MODE_INFRA) {
  366. lbs_deb_assoc("Deauthenticating due to leaving "
  367. "infra mode\n");
  368. ret = 1;
  369. goto out;
  370. }
  371. }
  372. out:
  373. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  374. return 0;
  375. }
  376. static int should_stop_adhoc(struct lbs_adapter *adapter,
  377. struct assoc_request * assoc_req)
  378. {
  379. lbs_deb_enter(LBS_DEB_ASSOC);
  380. if (adapter->connect_status != LBS_CONNECTED)
  381. return 0;
  382. if (lbs_ssid_cmp(adapter->curbssparams.ssid,
  383. adapter->curbssparams.ssid_len,
  384. assoc_req->ssid, assoc_req->ssid_len) != 0)
  385. return 1;
  386. /* FIXME: deal with 'auto' mode somehow */
  387. if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
  388. if (assoc_req->mode != IW_MODE_ADHOC)
  389. return 1;
  390. }
  391. if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
  392. if (assoc_req->channel != adapter->curbssparams.channel)
  393. return 1;
  394. }
  395. lbs_deb_leave(LBS_DEB_ASSOC);
  396. return 0;
  397. }
  398. void lbs_association_worker(struct work_struct *work)
  399. {
  400. struct lbs_private *priv = container_of(work, struct lbs_private,
  401. assoc_work.work);
  402. struct lbs_adapter *adapter = priv->adapter;
  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(&adapter->lock);
  409. assoc_req = adapter->pending_assoc_req;
  410. adapter->pending_assoc_req = NULL;
  411. adapter->in_progress_assoc_req = assoc_req;
  412. mutex_unlock(&adapter->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 (adapter->mode == IW_MODE_INFRA) {
  463. if (should_deauth_infrastructure(adapter, 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 (adapter->mode == IW_MODE_ADHOC) {
  472. if (should_stop_adhoc(adapter, 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 (adapter->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(adapter->curbssparams.ssid,
  534. adapter->curbssparams.ssid_len),
  535. print_mac(mac, adapter->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(&adapter->lock);
  552. adapter->in_progress_assoc_req = NULL;
  553. mutex_unlock(&adapter->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_adapter *adapter)
  562. {
  563. struct assoc_request * assoc_req;
  564. lbs_deb_enter(LBS_DEB_ASSOC);
  565. if (!adapter->pending_assoc_req) {
  566. adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
  567. GFP_KERNEL);
  568. if (!adapter->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 = adapter->pending_assoc_req;
  578. if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
  579. memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
  580. IW_ESSID_MAX_SIZE);
  581. assoc_req->ssid_len = adapter->curbssparams.ssid_len;
  582. }
  583. if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
  584. assoc_req->channel = adapter->curbssparams.channel;
  585. if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
  586. assoc_req->band = adapter->curbssparams.band;
  587. if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
  588. assoc_req->mode = adapter->mode;
  589. if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
  590. memcpy(&assoc_req->bssid, adapter->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], &adapter->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 = adapter->wep_tx_keyidx;
  602. if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
  603. memcpy(&assoc_req->wpa_mcast_key, &adapter->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, &adapter->wpa_unicast_key,
  608. sizeof(struct enc_key));
  609. }
  610. if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
  611. memcpy(&assoc_req->secinfo, &adapter->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, &adapter->wpa_ie,
  616. MAX_WPA_IE_LEN);
  617. assoc_req->wpa_ie_len = adapter->wpa_ie_len;
  618. }
  619. lbs_deb_leave(LBS_DEB_ASSOC);
  620. return assoc_req;
  621. }