join.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /**
  2. * Functions implementing wlan infrastructure and adhoc join routines,
  3. * IOCTL handlers as well as command preperation and response routines
  4. * for sending adhoc start, adhoc join, and association commands
  5. * to the firmware.
  6. */
  7. #include <linux/netdevice.h>
  8. #include <linux/if_arp.h>
  9. #include <linux/wireless.h>
  10. #include <linux/etherdevice.h>
  11. #include <net/iw_handler.h>
  12. #include "host.h"
  13. #include "decl.h"
  14. #include "join.h"
  15. #include "dev.h"
  16. #include "assoc.h"
  17. #define AD_HOC_CAP_PRIVACY_ON 1
  18. /**
  19. * @brief This function finds out the common rates between rate1 and rate2.
  20. *
  21. * It will fill common rates in rate1 as output if found.
  22. *
  23. * NOTE: Setting the MSB of the basic rates need to be taken
  24. * care, either before or after calling this function
  25. *
  26. * @param adapter A pointer to wlan_adapter structure
  27. * @param rate1 the buffer which keeps input and output
  28. * @param rate1_size the size of rate1 buffer
  29. * @param rate2 the buffer which keeps rate2
  30. * @param rate2_size the size of rate2 buffer.
  31. *
  32. * @return 0 or -1
  33. */
  34. static int get_common_rates(wlan_adapter * adapter, u8 * rate1,
  35. int rate1_size, u8 * rate2, int rate2_size)
  36. {
  37. u8 *ptr = rate1;
  38. int ret = 0;
  39. u8 tmp[30];
  40. int i;
  41. memset(&tmp, 0, sizeof(tmp));
  42. memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
  43. memset(rate1, 0, rate1_size);
  44. /* Mask the top bit of the original values */
  45. for (i = 0; tmp[i] && i < sizeof(tmp); i++)
  46. tmp[i] &= 0x7F;
  47. for (i = 0; rate2[i] && i < rate2_size; i++) {
  48. /* Check for Card Rate in tmp, excluding the top bit */
  49. if (strchr(tmp, rate2[i] & 0x7F)) {
  50. /* values match, so copy the Card Rate to rate1 */
  51. *rate1++ = rate2[i];
  52. }
  53. }
  54. lbs_dbg_hex("rate1 (AP) rates:", tmp, sizeof(tmp));
  55. lbs_dbg_hex("rate2 (Card) rates:", rate2, rate2_size);
  56. lbs_dbg_hex("Common rates:", ptr, rate1_size);
  57. lbs_deb_join("Tx datarate is set to 0x%X\n", adapter->datarate);
  58. if (!adapter->is_datarate_auto) {
  59. while (*ptr) {
  60. if ((*ptr & 0x7f) == adapter->datarate) {
  61. ret = 0;
  62. goto done;
  63. }
  64. ptr++;
  65. }
  66. lbs_pr_alert( "Previously set fixed data rate %#x isn't "
  67. "compatible with the network.\n", adapter->datarate);
  68. ret = -1;
  69. goto done;
  70. }
  71. ret = 0;
  72. done:
  73. return ret;
  74. }
  75. int libertas_send_deauth(wlan_private * priv)
  76. {
  77. wlan_adapter *adapter = priv->adapter;
  78. int ret = 0;
  79. if (adapter->mode == IW_MODE_INFRA &&
  80. adapter->connect_status == libertas_connected)
  81. ret = libertas_send_deauthentication(priv);
  82. else
  83. ret = -ENOTSUPP;
  84. return ret;
  85. }
  86. /**
  87. * @brief Associate to a specific BSS discovered in a scan
  88. *
  89. * @param priv A pointer to wlan_private structure
  90. * @param pbssdesc Pointer to the BSS descriptor to associate with.
  91. *
  92. * @return 0-success, otherwise fail
  93. */
  94. int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
  95. {
  96. wlan_adapter *adapter = priv->adapter;
  97. int ret;
  98. lbs_deb_enter(LBS_DEB_JOIN);
  99. ret = libertas_prepare_and_send_command(priv, cmd_802_11_authenticate,
  100. 0, cmd_option_waitforrsp,
  101. 0, assoc_req->bss.bssid);
  102. if (ret)
  103. goto done;
  104. /* set preamble to firmware */
  105. if (adapter->capinfo.shortpreamble && assoc_req->bss.cap.shortpreamble)
  106. adapter->preamble = cmd_type_short_preamble;
  107. else
  108. adapter->preamble = cmd_type_long_preamble;
  109. libertas_set_radio_control(priv);
  110. ret = libertas_prepare_and_send_command(priv, cmd_802_11_associate,
  111. 0, cmd_option_waitforrsp, 0, assoc_req);
  112. done:
  113. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  114. return ret;
  115. }
  116. /**
  117. * @brief Start an Adhoc Network
  118. *
  119. * @param priv A pointer to wlan_private structure
  120. * @param adhocssid The ssid of the Adhoc Network
  121. * @return 0--success, -1--fail
  122. */
  123. int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
  124. {
  125. wlan_adapter *adapter = priv->adapter;
  126. int ret = 0;
  127. adapter->adhoccreate = 1;
  128. if (!adapter->capinfo.shortpreamble) {
  129. lbs_deb_join("AdhocStart: Long preamble\n");
  130. adapter->preamble = cmd_type_long_preamble;
  131. } else {
  132. lbs_deb_join("AdhocStart: Short preamble\n");
  133. adapter->preamble = cmd_type_short_preamble;
  134. }
  135. libertas_set_radio_control(priv);
  136. lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
  137. lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
  138. ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
  139. 0, cmd_option_waitforrsp, 0, assoc_req);
  140. return ret;
  141. }
  142. /**
  143. * @brief Join an adhoc network found in a previous scan
  144. *
  145. * @param priv A pointer to wlan_private structure
  146. * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
  147. * to attempt to join
  148. *
  149. * @return 0--success, -1--fail
  150. */
  151. int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
  152. {
  153. wlan_adapter *adapter = priv->adapter;
  154. struct bss_descriptor * bss = &assoc_req->bss;
  155. int ret = 0;
  156. lbs_deb_join("libertas_join_adhoc_network: CurBss.ssid =%s\n",
  157. adapter->curbssparams.ssid.ssid);
  158. lbs_deb_join("libertas_join_adhoc_network: CurBss.ssid_len =%u\n",
  159. adapter->curbssparams.ssid.ssidlength);
  160. lbs_deb_join("libertas_join_adhoc_network: ssid = '%s'\n",
  161. bss->ssid.ssid);
  162. lbs_deb_join("libertas_join_adhoc_network: ssid len = %u\n",
  163. bss->ssid.ssidlength);
  164. /* check if the requested SSID is already joined */
  165. if (adapter->curbssparams.ssid.ssidlength
  166. && !libertas_SSID_cmp(&bss->ssid, &adapter->curbssparams.ssid)
  167. && (adapter->mode == IW_MODE_ADHOC)) {
  168. lbs_deb_join(
  169. "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
  170. "not attempting to re-join");
  171. return -1;
  172. }
  173. /*Use shortpreamble only when both creator and card supports
  174. short preamble */
  175. if (!bss->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
  176. lbs_deb_join("AdhocJoin: Long preamble\n");
  177. adapter->preamble = cmd_type_long_preamble;
  178. } else {
  179. lbs_deb_join("AdhocJoin: Short preamble\n");
  180. adapter->preamble = cmd_type_short_preamble;
  181. }
  182. libertas_set_radio_control(priv);
  183. lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
  184. lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
  185. adapter->adhoccreate = 0;
  186. ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_join,
  187. 0, cmd_option_waitforrsp,
  188. OID_802_11_SSID, assoc_req);
  189. return ret;
  190. }
  191. int libertas_stop_adhoc_network(wlan_private * priv)
  192. {
  193. return libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_stop,
  194. 0, cmd_option_waitforrsp, 0, NULL);
  195. }
  196. /**
  197. * @brief Send Deauthentication Request
  198. *
  199. * @param priv A pointer to wlan_private structure
  200. * @return 0--success, -1--fail
  201. */
  202. int libertas_send_deauthentication(wlan_private * priv)
  203. {
  204. return libertas_prepare_and_send_command(priv, cmd_802_11_deauthenticate,
  205. 0, cmd_option_waitforrsp, 0, NULL);
  206. }
  207. /**
  208. * @brief This function prepares command of authenticate.
  209. *
  210. * @param priv A pointer to wlan_private structure
  211. * @param cmd A pointer to cmd_ds_command structure
  212. * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
  213. *
  214. * @return 0 or -1
  215. */
  216. int libertas_cmd_80211_authenticate(wlan_private * priv,
  217. struct cmd_ds_command *cmd,
  218. void *pdata_buf)
  219. {
  220. wlan_adapter *adapter = priv->adapter;
  221. struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
  222. int ret = -1;
  223. u8 *bssid = pdata_buf;
  224. cmd->command = cpu_to_le16(cmd_802_11_authenticate);
  225. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
  226. + S_DS_GEN);
  227. /* translate auth mode to 802.11 defined wire value */
  228. switch (adapter->secinfo.auth_mode) {
  229. case IW_AUTH_ALG_OPEN_SYSTEM:
  230. pauthenticate->authtype = 0x00;
  231. break;
  232. case IW_AUTH_ALG_SHARED_KEY:
  233. pauthenticate->authtype = 0x01;
  234. break;
  235. case IW_AUTH_ALG_LEAP:
  236. pauthenticate->authtype = 0x80;
  237. break;
  238. default:
  239. lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
  240. adapter->secinfo.auth_mode);
  241. goto out;
  242. }
  243. memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
  244. lbs_deb_join("AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n",
  245. bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
  246. ret = 0;
  247. out:
  248. return ret;
  249. }
  250. int libertas_cmd_80211_deauthenticate(wlan_private * priv,
  251. struct cmd_ds_command *cmd)
  252. {
  253. wlan_adapter *adapter = priv->adapter;
  254. struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
  255. lbs_deb_enter(LBS_DEB_JOIN);
  256. cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
  257. cmd->size =
  258. cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
  259. S_DS_GEN);
  260. /* set AP MAC address */
  261. memmove(dauth->macaddr, adapter->curbssparams.bssid,
  262. ETH_ALEN);
  263. /* Reason code 3 = Station is leaving */
  264. #define REASON_CODE_STA_LEAVING 3
  265. dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
  266. lbs_deb_leave(LBS_DEB_JOIN);
  267. return 0;
  268. }
  269. int libertas_cmd_80211_associate(wlan_private * priv,
  270. struct cmd_ds_command *cmd, void *pdata_buf)
  271. {
  272. wlan_adapter *adapter = priv->adapter;
  273. struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
  274. int ret = 0;
  275. struct assoc_request * assoc_req = pdata_buf;
  276. struct bss_descriptor * bss = &assoc_req->bss;
  277. u8 *card_rates;
  278. u8 *pos;
  279. int card_rates_size;
  280. u16 tmpcap;
  281. struct mrvlietypes_ssidparamset *ssid;
  282. struct mrvlietypes_phyparamset *phy;
  283. struct mrvlietypes_ssparamset *ss;
  284. struct mrvlietypes_ratesparamset *rates;
  285. struct mrvlietypes_rsnparamset *rsn;
  286. lbs_deb_enter(LBS_DEB_JOIN);
  287. pos = (u8 *) passo;
  288. if (!adapter) {
  289. ret = -1;
  290. goto done;
  291. }
  292. cmd->command = cpu_to_le16(cmd_802_11_associate);
  293. memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
  294. pos += sizeof(passo->peerstaaddr);
  295. /* set the listen interval */
  296. passo->listeninterval = adapter->listeninterval;
  297. pos += sizeof(passo->capinfo);
  298. pos += sizeof(passo->listeninterval);
  299. pos += sizeof(passo->bcnperiod);
  300. pos += sizeof(passo->dtimperiod);
  301. ssid = (struct mrvlietypes_ssidparamset *) pos;
  302. ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
  303. ssid->header.len = bss->ssid.ssidlength;
  304. memcpy(ssid->ssid, bss->ssid.ssid, ssid->header.len);
  305. pos += sizeof(ssid->header) + ssid->header.len;
  306. ssid->header.len = cpu_to_le16(ssid->header.len);
  307. phy = (struct mrvlietypes_phyparamset *) pos;
  308. phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
  309. phy->header.len = sizeof(phy->fh_ds.dsparamset);
  310. memcpy(&phy->fh_ds.dsparamset,
  311. &bss->phyparamset.dsparamset.currentchan,
  312. sizeof(phy->fh_ds.dsparamset));
  313. pos += sizeof(phy->header) + phy->header.len;
  314. phy->header.len = cpu_to_le16(phy->header.len);
  315. ss = (struct mrvlietypes_ssparamset *) pos;
  316. ss->header.type = cpu_to_le16(TLV_TYPE_CF);
  317. ss->header.len = sizeof(ss->cf_ibss.cfparamset);
  318. pos += sizeof(ss->header) + ss->header.len;
  319. ss->header.len = cpu_to_le16(ss->header.len);
  320. rates = (struct mrvlietypes_ratesparamset *) pos;
  321. rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
  322. memcpy(&rates->rates, &bss->libertas_supported_rates, WLAN_SUPPORTED_RATES);
  323. card_rates = libertas_supported_rates;
  324. card_rates_size = sizeof(libertas_supported_rates);
  325. if (get_common_rates(adapter, rates->rates, WLAN_SUPPORTED_RATES,
  326. card_rates, card_rates_size)) {
  327. ret = -1;
  328. goto done;
  329. }
  330. rates->header.len = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
  331. adapter->curbssparams.numofrates = rates->header.len;
  332. pos += sizeof(rates->header) + rates->header.len;
  333. rates->header.len = cpu_to_le16(rates->header.len);
  334. if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
  335. rsn = (struct mrvlietypes_rsnparamset *) pos;
  336. rsn->header.type = (u16) assoc_req->wpa_ie[0]; /* WPA_IE or WPA2_IE */
  337. rsn->header.type = cpu_to_le16(rsn->header.type);
  338. rsn->header.len = (u16) assoc_req->wpa_ie[1];
  339. memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], rsn->header.len);
  340. lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
  341. sizeof(rsn->header) + rsn->header.len);
  342. pos += sizeof(rsn->header) + rsn->header.len;
  343. rsn->header.len = cpu_to_le16(rsn->header.len);
  344. }
  345. /* update curbssparams */
  346. adapter->curbssparams.channel =
  347. (bss->phyparamset.dsparamset.currentchan);
  348. /* Copy the infra. association rates into Current BSS state structure */
  349. memcpy(&adapter->curbssparams.datarates, &rates->rates,
  350. min_t(size_t, sizeof(adapter->curbssparams.datarates), rates->header.len));
  351. lbs_deb_join("ASSOC_CMD: rates->header.len = %d\n", rates->header.len);
  352. /* set IBSS field */
  353. if (bss->mode == IW_MODE_INFRA) {
  354. #define CAPINFO_ESS_MODE 1
  355. passo->capinfo.ess = CAPINFO_ESS_MODE;
  356. }
  357. if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
  358. ret = -1;
  359. goto done;
  360. }
  361. cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
  362. /* set the capability info at last */
  363. memcpy(&tmpcap, &bss->cap, sizeof(passo->capinfo));
  364. tmpcap &= CAPINFO_MASK;
  365. lbs_deb_join("ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
  366. tmpcap, CAPINFO_MASK);
  367. tmpcap = cpu_to_le16(tmpcap);
  368. memcpy(&passo->capinfo, &tmpcap, sizeof(passo->capinfo));
  369. done:
  370. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  371. return ret;
  372. }
  373. int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
  374. struct cmd_ds_command *cmd, void *pdata_buf)
  375. {
  376. wlan_adapter *adapter = priv->adapter;
  377. struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
  378. int ret = 0;
  379. int cmdappendsize = 0;
  380. int i;
  381. u16 tmpcap;
  382. struct assoc_request * assoc_req = pdata_buf;
  383. lbs_deb_enter(LBS_DEB_JOIN);
  384. if (!adapter) {
  385. ret = -1;
  386. goto done;
  387. }
  388. cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
  389. /*
  390. * Fill in the parameters for 2 data structures:
  391. * 1. cmd_ds_802_11_ad_hoc_start command
  392. * 2. adapter->scantable[i]
  393. *
  394. * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
  395. * probe delay, and cap info.
  396. *
  397. * Firmware will fill up beacon period, DTIM, Basic rates
  398. * and operational rates.
  399. */
  400. memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
  401. memcpy(adhs->SSID, assoc_req->ssid.ssid, assoc_req->ssid.ssidlength);
  402. lbs_deb_join("ADHOC_S_CMD: SSID = %s\n", adhs->SSID);
  403. /* set the BSS type */
  404. adhs->bsstype = cmd_bss_type_ibss;
  405. adapter->mode = IW_MODE_ADHOC;
  406. adhs->beaconperiod = adapter->beaconperiod;
  407. /* set Physical param set */
  408. #define DS_PARA_IE_ID 3
  409. #define DS_PARA_IE_LEN 1
  410. adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
  411. adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
  412. WARN_ON(!assoc_req->channel);
  413. lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
  414. assoc_req->channel);
  415. adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
  416. /* set IBSS param set */
  417. #define IBSS_PARA_IE_ID 6
  418. #define IBSS_PARA_IE_LEN 2
  419. adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
  420. adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
  421. adhs->ssparamset.ibssparamset.atimwindow = adapter->atimwindow;
  422. /* set capability info */
  423. adhs->cap.ess = 0;
  424. adhs->cap.ibss = 1;
  425. /* probedelay */
  426. adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
  427. /* set up privacy in adapter->scantable[i] */
  428. if (assoc_req->secinfo.wep_enabled) {
  429. lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
  430. adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
  431. } else {
  432. lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
  433. }
  434. memset(adhs->datarate, 0, sizeof(adhs->datarate));
  435. if (adapter->adhoc_grate_enabled) {
  436. memcpy(adhs->datarate, libertas_adhoc_rates_g,
  437. min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_g)));
  438. } else {
  439. memcpy(adhs->datarate, libertas_adhoc_rates_b,
  440. min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_b)));
  441. }
  442. /* Find the last non zero */
  443. for (i = 0; i < sizeof(adhs->datarate) && adhs->datarate[i]; i++) ;
  444. adapter->curbssparams.numofrates = i;
  445. /* Copy the ad-hoc creating rates into Current BSS state structure */
  446. memcpy(&adapter->curbssparams.datarates,
  447. &adhs->datarate, adapter->curbssparams.numofrates);
  448. lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
  449. adhs->datarate[0], adhs->datarate[1],
  450. adhs->datarate[2], adhs->datarate[3]);
  451. lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
  452. if (libertas_create_dnld_countryinfo_11d(priv)) {
  453. lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
  454. ret = -1;
  455. goto done;
  456. }
  457. cmd->size =
  458. cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start)
  459. + S_DS_GEN + cmdappendsize);
  460. memcpy(&tmpcap, &adhs->cap, sizeof(u16));
  461. tmpcap = cpu_to_le16(tmpcap);
  462. memcpy(&adhs->cap, &tmpcap, sizeof(u16));
  463. ret = 0;
  464. done:
  465. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  466. return ret;
  467. }
  468. int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
  469. struct cmd_ds_command *cmd)
  470. {
  471. cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_stop);
  472. cmd->size = cpu_to_le16(S_DS_GEN);
  473. return 0;
  474. }
  475. int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
  476. struct cmd_ds_command *cmd, void *pdata_buf)
  477. {
  478. wlan_adapter *adapter = priv->adapter;
  479. struct cmd_ds_802_11_ad_hoc_join *padhocjoin = &cmd->params.adj;
  480. struct assoc_request * assoc_req = pdata_buf;
  481. struct bss_descriptor *bss = &assoc_req->bss;
  482. int cmdappendsize = 0;
  483. int ret = 0;
  484. u8 *card_rates;
  485. int card_rates_size;
  486. u16 tmpcap;
  487. int i;
  488. lbs_deb_enter(LBS_DEB_JOIN);
  489. cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
  490. padhocjoin->bssdescriptor.bsstype = cmd_bss_type_ibss;
  491. padhocjoin->bssdescriptor.beaconperiod = bss->beaconperiod;
  492. memcpy(&padhocjoin->bssdescriptor.BSSID, &bss->bssid, ETH_ALEN);
  493. memcpy(&padhocjoin->bssdescriptor.SSID, &bss->ssid.ssid, bss->ssid.ssidlength);
  494. memcpy(&padhocjoin->bssdescriptor.phyparamset,
  495. &bss->phyparamset, sizeof(union ieeetypes_phyparamset));
  496. memcpy(&padhocjoin->bssdescriptor.ssparamset,
  497. &bss->ssparamset, sizeof(union IEEEtypes_ssparamset));
  498. memcpy(&tmpcap, &bss->cap, sizeof(struct ieeetypes_capinfo));
  499. tmpcap &= CAPINFO_MASK;
  500. lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
  501. tmpcap, CAPINFO_MASK);
  502. memcpy(&padhocjoin->bssdescriptor.cap, &tmpcap,
  503. sizeof(struct ieeetypes_capinfo));
  504. /* information on BSSID descriptor passed to FW */
  505. lbs_deb_join(
  506. "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
  507. MAC_ARG(padhocjoin->bssdescriptor.BSSID),
  508. padhocjoin->bssdescriptor.SSID);
  509. /* failtimeout */
  510. padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
  511. /* probedelay */
  512. padhocjoin->probedelay =
  513. cpu_to_le16(cmd_scan_probe_delay_time);
  514. /* Copy Data rates from the rates recorded in scan response */
  515. memset(padhocjoin->bssdescriptor.datarates, 0,
  516. sizeof(padhocjoin->bssdescriptor.datarates));
  517. memcpy(padhocjoin->bssdescriptor.datarates, bss->datarates,
  518. min(sizeof(padhocjoin->bssdescriptor.datarates),
  519. sizeof(bss->datarates)));
  520. card_rates = libertas_supported_rates;
  521. card_rates_size = sizeof(libertas_supported_rates);
  522. adapter->curbssparams.channel = bss->channel;
  523. if (get_common_rates(adapter, padhocjoin->bssdescriptor.datarates,
  524. sizeof(padhocjoin->bssdescriptor.datarates),
  525. card_rates, card_rates_size)) {
  526. lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
  527. ret = -1;
  528. goto done;
  529. }
  530. /* Find the last non zero */
  531. for (i = 0; i < sizeof(padhocjoin->bssdescriptor.datarates)
  532. && padhocjoin->bssdescriptor.datarates[i]; i++) ;
  533. adapter->curbssparams.numofrates = i;
  534. /*
  535. * Copy the adhoc joining rates to Current BSS State structure
  536. */
  537. memcpy(adapter->curbssparams.datarates,
  538. padhocjoin->bssdescriptor.datarates,
  539. adapter->curbssparams.numofrates);
  540. padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
  541. cpu_to_le16(bss->atimwindow);
  542. if (assoc_req->secinfo.wep_enabled) {
  543. padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
  544. }
  545. if (adapter->psmode == wlan802_11powermodemax_psp) {
  546. /* wake up first */
  547. enum WLAN_802_11_POWER_MODE Localpsmode;
  548. Localpsmode = wlan802_11powermodecam;
  549. ret = libertas_prepare_and_send_command(priv,
  550. cmd_802_11_ps_mode,
  551. cmd_act_set,
  552. 0, 0, &Localpsmode);
  553. if (ret) {
  554. ret = -1;
  555. goto done;
  556. }
  557. }
  558. if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
  559. ret = -1;
  560. goto done;
  561. }
  562. cmd->size =
  563. cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join)
  564. + S_DS_GEN + cmdappendsize);
  565. memcpy(&tmpcap, &padhocjoin->bssdescriptor.cap,
  566. sizeof(struct ieeetypes_capinfo));
  567. tmpcap = cpu_to_le16(tmpcap);
  568. memcpy(&padhocjoin->bssdescriptor.cap,
  569. &tmpcap, sizeof(struct ieeetypes_capinfo));
  570. done:
  571. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  572. return ret;
  573. }
  574. int libertas_ret_80211_associate(wlan_private * priv,
  575. struct cmd_ds_command *resp)
  576. {
  577. wlan_adapter *adapter = priv->adapter;
  578. int ret = 0;
  579. union iwreq_data wrqu;
  580. struct ieeetypes_assocrsp *passocrsp;
  581. struct bss_descriptor * bss;
  582. lbs_deb_enter(LBS_DEB_JOIN);
  583. if (!adapter->in_progress_assoc_req) {
  584. lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
  585. ret = -1;
  586. goto done;
  587. }
  588. bss = &adapter->in_progress_assoc_req->bss;
  589. passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
  590. if (passocrsp->statuscode) {
  591. libertas_mac_event_disconnected(priv);
  592. lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
  593. passocrsp->statuscode);
  594. ret = -1;
  595. goto done;
  596. }
  597. lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
  598. le16_to_cpu(resp->size) - S_DS_GEN);
  599. /* Send a Media Connected event, according to the Spec */
  600. adapter->connect_status = libertas_connected;
  601. lbs_deb_join("ASSOC_RESP: %s\n", bss->ssid.ssid);
  602. /* Update current SSID and BSSID */
  603. memcpy(&adapter->curbssparams.ssid,
  604. &bss->ssid, sizeof(struct WLAN_802_11_SSID));
  605. memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
  606. lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
  607. adapter->currentpacketfilter);
  608. adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
  609. adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
  610. memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
  611. memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
  612. adapter->nextSNRNF = 0;
  613. adapter->numSNRNF = 0;
  614. netif_carrier_on(priv->dev);
  615. netif_wake_queue(priv->dev);
  616. netif_carrier_on(priv->mesh_dev);
  617. netif_wake_queue(priv->mesh_dev);
  618. lbs_deb_join("ASSOC_RESP: Associated \n");
  619. memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
  620. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  621. wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
  622. done:
  623. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  624. return ret;
  625. }
  626. int libertas_ret_80211_disassociate(wlan_private * priv,
  627. struct cmd_ds_command *resp)
  628. {
  629. lbs_deb_enter(LBS_DEB_JOIN);
  630. libertas_mac_event_disconnected(priv);
  631. lbs_deb_leave(LBS_DEB_JOIN);
  632. return 0;
  633. }
  634. int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
  635. struct cmd_ds_command *resp)
  636. {
  637. wlan_adapter *adapter = priv->adapter;
  638. int ret = 0;
  639. u16 command = le16_to_cpu(resp->command);
  640. u16 result = le16_to_cpu(resp->result);
  641. struct cmd_ds_802_11_ad_hoc_result *padhocresult;
  642. union iwreq_data wrqu;
  643. struct bss_descriptor *bss;
  644. lbs_deb_enter(LBS_DEB_JOIN);
  645. padhocresult = &resp->params.result;
  646. lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
  647. lbs_deb_join("ADHOC_RESP: command = %x\n", command);
  648. lbs_deb_join("ADHOC_RESP: result = %x\n", result);
  649. if (!adapter->in_progress_assoc_req) {
  650. lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
  651. ret = -1;
  652. goto done;
  653. }
  654. bss = &adapter->in_progress_assoc_req->bss;
  655. /*
  656. * Join result code 0 --> SUCCESS
  657. */
  658. if (result) {
  659. lbs_deb_join("ADHOC_RESP: failed\n");
  660. if (adapter->connect_status == libertas_connected) {
  661. libertas_mac_event_disconnected(priv);
  662. }
  663. ret = -1;
  664. goto done;
  665. }
  666. /*
  667. * Now the join cmd should be successful
  668. * If BSSID has changed use SSID to compare instead of BSSID
  669. */
  670. lbs_deb_join("ADHOC_RESP: %s\n", bss->ssid.ssid);
  671. /* Send a Media Connected event, according to the Spec */
  672. adapter->connect_status = libertas_connected;
  673. if (command == cmd_ret_802_11_ad_hoc_start) {
  674. /* Update the created network descriptor with the new BSSID */
  675. memcpy(bss->bssid, padhocresult->BSSID, ETH_ALEN);
  676. }
  677. /* Set the BSSID from the joined/started descriptor */
  678. memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
  679. /* Set the new SSID to current SSID */
  680. memcpy(&adapter->curbssparams.ssid, &bss->ssid,
  681. sizeof(struct WLAN_802_11_SSID));
  682. netif_carrier_on(priv->dev);
  683. netif_wake_queue(priv->dev);
  684. netif_carrier_on(priv->mesh_dev);
  685. netif_wake_queue(priv->mesh_dev);
  686. memset(&wrqu, 0, sizeof(wrqu));
  687. memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
  688. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  689. wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
  690. lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
  691. lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
  692. lbs_deb_join("ADHOC_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
  693. padhocresult->BSSID[0], padhocresult->BSSID[1],
  694. padhocresult->BSSID[2], padhocresult->BSSID[3],
  695. padhocresult->BSSID[4], padhocresult->BSSID[5]);
  696. done:
  697. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  698. return ret;
  699. }
  700. int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
  701. struct cmd_ds_command *resp)
  702. {
  703. lbs_deb_enter(LBS_DEB_JOIN);
  704. libertas_mac_event_disconnected(priv);
  705. lbs_deb_leave(LBS_DEB_JOIN);
  706. return 0;
  707. }