join.c 26 KB

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