join.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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_deb_join("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. lbs_deb_enter(LBS_DEB_JOIN);
  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. goto done;
  102. /* set preamble to firmware */
  103. if (adapter->capinfo.shortpreamble && pbssdesc->cap.shortpreamble)
  104. adapter->preamble = cmd_type_short_preamble;
  105. else
  106. adapter->preamble = cmd_type_long_preamble;
  107. libertas_set_radio_control(priv);
  108. ret = libertas_prepare_and_send_command(priv, cmd_802_11_associate,
  109. 0, cmd_option_waitforrsp, 0, pbssdesc);
  110. done:
  111. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  112. return ret;
  113. }
  114. /**
  115. * @brief Start an Adhoc Network
  116. *
  117. * @param priv A pointer to wlan_private structure
  118. * @param adhocssid The ssid of the Adhoc Network
  119. * @return 0--success, -1--fail
  120. */
  121. int libertas_start_adhoc_network(wlan_private * priv, struct WLAN_802_11_SSID *adhocssid)
  122. {
  123. wlan_adapter *adapter = priv->adapter;
  124. int ret = 0;
  125. adapter->adhoccreate = 1;
  126. if (!adapter->capinfo.shortpreamble) {
  127. lbs_deb_join("AdhocStart: Long preamble\n");
  128. adapter->preamble = cmd_type_long_preamble;
  129. } else {
  130. lbs_deb_join("AdhocStart: Short preamble\n");
  131. adapter->preamble = cmd_type_short_preamble;
  132. }
  133. libertas_set_radio_control(priv);
  134. lbs_deb_join("Adhoc channel = %d\n", adapter->adhocchannel);
  135. lbs_deb_join("curbssparams.channel = %d\n",
  136. adapter->curbssparams.channel);
  137. lbs_deb_join("curbssparams.band = %d\n", adapter->curbssparams.band);
  138. ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
  139. 0, cmd_option_waitforrsp, 0, adhocssid);
  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 bss_descriptor * pbssdesc)
  152. {
  153. wlan_adapter *adapter = priv->adapter;
  154. int ret = 0;
  155. lbs_deb_join("libertas_join_adhoc_network: CurBss.ssid =%s\n",
  156. adapter->curbssparams.ssid.ssid);
  157. lbs_deb_join("libertas_join_adhoc_network: CurBss.ssid_len =%u\n",
  158. adapter->curbssparams.ssid.ssidlength);
  159. lbs_deb_join("libertas_join_adhoc_network: ssid =%s\n", pbssdesc->ssid.ssid);
  160. lbs_deb_join("libertas_join_adhoc_network: ssid len =%u\n",
  161. pbssdesc->ssid.ssidlength);
  162. /* check if the requested SSID is already joined */
  163. if (adapter->curbssparams.ssid.ssidlength
  164. && !libertas_SSID_cmp(&pbssdesc->ssid, &adapter->curbssparams.ssid)
  165. && (adapter->mode == IW_MODE_ADHOC)) {
  166. lbs_deb_join(
  167. "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
  168. "not attempting to re-join");
  169. return -1;
  170. }
  171. /*Use shortpreamble only when both creator and card supports
  172. short preamble */
  173. if (!pbssdesc->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
  174. lbs_deb_join("AdhocJoin: Long preamble\n");
  175. adapter->preamble = cmd_type_long_preamble;
  176. } else {
  177. lbs_deb_join("AdhocJoin: Short preamble\n");
  178. adapter->preamble = cmd_type_short_preamble;
  179. }
  180. libertas_set_radio_control(priv);
  181. lbs_deb_join("curbssparams.channel = %d\n",
  182. adapter->curbssparams.channel);
  183. lbs_deb_join("curbssparams.band = %c\n", adapter->curbssparams.band);
  184. adapter->adhoccreate = 0;
  185. ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_join,
  186. 0, cmd_option_waitforrsp,
  187. OID_802_11_SSID, pbssdesc);
  188. return ret;
  189. }
  190. int libertas_stop_adhoc_network(wlan_private * priv)
  191. {
  192. return libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_stop,
  193. 0, cmd_option_waitforrsp, 0, NULL);
  194. }
  195. /**
  196. * @brief Send Deauthentication Request
  197. *
  198. * @param priv A pointer to wlan_private structure
  199. * @return 0--success, -1--fail
  200. */
  201. int libertas_send_deauthentication(wlan_private * priv)
  202. {
  203. return libertas_prepare_and_send_command(priv, cmd_802_11_deauthenticate,
  204. 0, cmd_option_waitforrsp, 0, NULL);
  205. }
  206. /**
  207. * @brief This function prepares command of authenticate.
  208. *
  209. * @param priv A pointer to wlan_private structure
  210. * @param cmd A pointer to cmd_ds_command structure
  211. * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
  212. *
  213. * @return 0 or -1
  214. */
  215. int libertas_cmd_80211_authenticate(wlan_private * priv,
  216. struct cmd_ds_command *cmd,
  217. void *pdata_buf)
  218. {
  219. wlan_adapter *adapter = priv->adapter;
  220. struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
  221. int ret = -1;
  222. u8 *bssid = pdata_buf;
  223. cmd->command = cpu_to_le16(cmd_802_11_authenticate);
  224. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
  225. + S_DS_GEN);
  226. /* translate auth mode to 802.11 defined wire value */
  227. switch (adapter->secinfo.auth_mode) {
  228. case IW_AUTH_ALG_OPEN_SYSTEM:
  229. pauthenticate->authtype = 0x00;
  230. break;
  231. case IW_AUTH_ALG_SHARED_KEY:
  232. pauthenticate->authtype = 0x01;
  233. break;
  234. case IW_AUTH_ALG_LEAP:
  235. pauthenticate->authtype = 0x80;
  236. break;
  237. default:
  238. lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
  239. adapter->secinfo.auth_mode);
  240. goto out;
  241. }
  242. memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
  243. lbs_deb_join("AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n",
  244. bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
  245. ret = 0;
  246. out:
  247. return ret;
  248. }
  249. int libertas_cmd_80211_deauthenticate(wlan_private * priv,
  250. struct cmd_ds_command *cmd)
  251. {
  252. wlan_adapter *adapter = priv->adapter;
  253. struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
  254. lbs_deb_enter(LBS_DEB_JOIN);
  255. cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
  256. cmd->size =
  257. cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
  258. S_DS_GEN);
  259. /* set AP MAC address */
  260. memmove(dauth->macaddr, adapter->curbssparams.bssid,
  261. ETH_ALEN);
  262. /* Reason code 3 = Station is leaving */
  263. #define REASON_CODE_STA_LEAVING 3
  264. dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
  265. lbs_deb_leave(LBS_DEB_JOIN);
  266. return 0;
  267. }
  268. int libertas_cmd_80211_associate(wlan_private * priv,
  269. struct cmd_ds_command *cmd, void *pdata_buf)
  270. {
  271. wlan_adapter *adapter = priv->adapter;
  272. struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
  273. int ret = 0;
  274. struct bss_descriptor *pbssdesc;
  275. u8 *card_rates;
  276. u8 *pos;
  277. int card_rates_size;
  278. u16 tmpcap;
  279. struct mrvlietypes_ssidparamset *ssid;
  280. struct mrvlietypes_phyparamset *phy;
  281. struct mrvlietypes_ssparamset *ss;
  282. struct mrvlietypes_ratesparamset *rates;
  283. struct mrvlietypes_rsnparamset *rsn;
  284. lbs_deb_enter(LBS_DEB_JOIN);
  285. pbssdesc = pdata_buf;
  286. pos = (u8 *) passo;
  287. if (!adapter) {
  288. ret = -1;
  289. goto done;
  290. }
  291. cmd->command = cpu_to_le16(cmd_802_11_associate);
  292. /* Save so we know which BSS Desc to use in the response handler */
  293. adapter->pattemptedbssdesc = pbssdesc;
  294. memcpy(passo->peerstaaddr,
  295. pbssdesc->macaddress, sizeof(passo->peerstaaddr));
  296. pos += sizeof(passo->peerstaaddr);
  297. /* set the listen interval */
  298. passo->listeninterval = adapter->listeninterval;
  299. pos += sizeof(passo->capinfo);
  300. pos += sizeof(passo->listeninterval);
  301. pos += sizeof(passo->bcnperiod);
  302. pos += sizeof(passo->dtimperiod);
  303. ssid = (struct mrvlietypes_ssidparamset *) pos;
  304. ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
  305. ssid->header.len = pbssdesc->ssid.ssidlength;
  306. memcpy(ssid->ssid, pbssdesc->ssid.ssid, ssid->header.len);
  307. pos += sizeof(ssid->header) + ssid->header.len;
  308. ssid->header.len = cpu_to_le16(ssid->header.len);
  309. phy = (struct mrvlietypes_phyparamset *) pos;
  310. phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
  311. phy->header.len = sizeof(phy->fh_ds.dsparamset);
  312. memcpy(&phy->fh_ds.dsparamset,
  313. &pbssdesc->phyparamset.dsparamset.currentchan,
  314. sizeof(phy->fh_ds.dsparamset));
  315. pos += sizeof(phy->header) + phy->header.len;
  316. phy->header.len = cpu_to_le16(phy->header.len);
  317. ss = (struct mrvlietypes_ssparamset *) pos;
  318. ss->header.type = cpu_to_le16(TLV_TYPE_CF);
  319. ss->header.len = sizeof(ss->cf_ibss.cfparamset);
  320. pos += sizeof(ss->header) + ss->header.len;
  321. ss->header.len = cpu_to_le16(ss->header.len);
  322. rates = (struct mrvlietypes_ratesparamset *) pos;
  323. rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
  324. memcpy(&rates->rates, &pbssdesc->libertas_supported_rates, WLAN_SUPPORTED_RATES);
  325. card_rates = libertas_supported_rates;
  326. card_rates_size = sizeof(libertas_supported_rates);
  327. if (get_common_rates(adapter, rates->rates, WLAN_SUPPORTED_RATES,
  328. card_rates, card_rates_size)) {
  329. ret = -1;
  330. goto done;
  331. }
  332. rates->header.len = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
  333. adapter->curbssparams.numofrates = rates->header.len;
  334. pos += sizeof(rates->header) + rates->header.len;
  335. rates->header.len = cpu_to_le16(rates->header.len);
  336. if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
  337. rsn = (struct mrvlietypes_rsnparamset *) pos;
  338. rsn->header.type = (u16) adapter->wpa_ie[0]; /* WPA_IE or WPA2_IE */
  339. rsn->header.type = cpu_to_le16(rsn->header.type);
  340. rsn->header.len = (u16) adapter->wpa_ie[1];
  341. memcpy(rsn->rsnie, &adapter->wpa_ie[2], rsn->header.len);
  342. lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
  343. sizeof(rsn->header) + rsn->header.len);
  344. pos += sizeof(rsn->header) + rsn->header.len;
  345. rsn->header.len = cpu_to_le16(rsn->header.len);
  346. }
  347. /* update curbssparams */
  348. adapter->curbssparams.channel =
  349. (pbssdesc->phyparamset.dsparamset.currentchan);
  350. /* Copy the infra. association rates into Current BSS state structure */
  351. memcpy(&adapter->curbssparams.datarates, &rates->rates,
  352. min_t(size_t, sizeof(adapter->curbssparams.datarates), rates->header.len));
  353. lbs_deb_join("ASSOC_CMD: rates->header.len = %d\n", rates->header.len);
  354. /* set IBSS field */
  355. if (pbssdesc->mode == IW_MODE_INFRA) {
  356. #define CAPINFO_ESS_MODE 1
  357. passo->capinfo.ess = CAPINFO_ESS_MODE;
  358. }
  359. if (libertas_parse_dnld_countryinfo_11d(priv)) {
  360. ret = -1;
  361. goto done;
  362. }
  363. cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
  364. /* set the capability info at last */
  365. memcpy(&tmpcap, &pbssdesc->cap, sizeof(passo->capinfo));
  366. tmpcap &= CAPINFO_MASK;
  367. lbs_deb_join("ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
  368. tmpcap, CAPINFO_MASK);
  369. tmpcap = cpu_to_le16(tmpcap);
  370. memcpy(&passo->capinfo, &tmpcap, sizeof(passo->capinfo));
  371. done:
  372. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  373. return ret;
  374. }
  375. int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
  376. struct cmd_ds_command *cmd, void *pssid)
  377. {
  378. wlan_adapter *adapter = priv->adapter;
  379. struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
  380. int ret = 0;
  381. int cmdappendsize = 0;
  382. int i;
  383. u16 tmpcap;
  384. struct bss_descriptor *pbssdesc;
  385. struct WLAN_802_11_SSID *ssid = pssid;
  386. lbs_deb_enter(LBS_DEB_JOIN);
  387. if (!adapter) {
  388. ret = -1;
  389. goto done;
  390. }
  391. cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
  392. pbssdesc = &adapter->curbssparams.bssdescriptor;
  393. adapter->pattemptedbssdesc = pbssdesc;
  394. /*
  395. * Fill in the parameters for 2 data structures:
  396. * 1. cmd_ds_802_11_ad_hoc_start command
  397. * 2. adapter->scantable[i]
  398. *
  399. * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
  400. * probe delay, and cap info.
  401. *
  402. * Firmware will fill up beacon period, DTIM, Basic rates
  403. * and operational rates.
  404. */
  405. memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
  406. memcpy(adhs->SSID, ssid->ssid, ssid->ssidlength);
  407. lbs_deb_join("ADHOC_S_CMD: SSID = %s\n", adhs->SSID);
  408. memset(pbssdesc->ssid.ssid, 0, IW_ESSID_MAX_SIZE);
  409. memcpy(pbssdesc->ssid.ssid, ssid->ssid, ssid->ssidlength);
  410. pbssdesc->ssid.ssidlength = ssid->ssidlength;
  411. /* set the BSS type */
  412. adhs->bsstype = cmd_bss_type_ibss;
  413. pbssdesc->mode = IW_MODE_ADHOC;
  414. adhs->beaconperiod = adapter->beaconperiod;
  415. /* set Physical param set */
  416. #define DS_PARA_IE_ID 3
  417. #define DS_PARA_IE_LEN 1
  418. adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
  419. adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
  420. WARN_ON(!adapter->adhocchannel);
  421. lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
  422. adapter->adhocchannel);
  423. adapter->curbssparams.channel = adapter->adhocchannel;
  424. pbssdesc->channel = adapter->adhocchannel;
  425. adhs->phyparamset.dsparamset.currentchan = adapter->adhocchannel;
  426. memcpy(&pbssdesc->phyparamset,
  427. &adhs->phyparamset, sizeof(union ieeetypes_phyparamset));
  428. /* set IBSS param set */
  429. #define IBSS_PARA_IE_ID 6
  430. #define IBSS_PARA_IE_LEN 2
  431. adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
  432. adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
  433. adhs->ssparamset.ibssparamset.atimwindow = adapter->atimwindow;
  434. memcpy(&pbssdesc->ssparamset,
  435. &adhs->ssparamset, sizeof(union IEEEtypes_ssparamset));
  436. /* set capability info */
  437. adhs->cap.ess = 0;
  438. adhs->cap.ibss = 1;
  439. pbssdesc->cap.ibss = 1;
  440. /* probedelay */
  441. adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
  442. /* set up privacy in adapter->scantable[i] */
  443. if (adapter->secinfo.wep_enabled) {
  444. lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
  445. pbssdesc->privacy = wlan802_11privfilter8021xWEP;
  446. adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
  447. } else {
  448. lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
  449. pbssdesc->privacy = wlan802_11privfilteracceptall;
  450. }
  451. memset(adhs->datarate, 0, sizeof(adhs->datarate));
  452. if (adapter->adhoc_grate_enabled) {
  453. memcpy(adhs->datarate, libertas_adhoc_rates_g,
  454. min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_g)));
  455. } else {
  456. memcpy(adhs->datarate, libertas_adhoc_rates_b,
  457. min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_b)));
  458. }
  459. /* Find the last non zero */
  460. for (i = 0; i < sizeof(adhs->datarate) && adhs->datarate[i]; i++) ;
  461. adapter->curbssparams.numofrates = i;
  462. /* Copy the ad-hoc creating rates into Current BSS state structure */
  463. memcpy(&adapter->curbssparams.datarates,
  464. &adhs->datarate, adapter->curbssparams.numofrates);
  465. lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
  466. adhs->datarate[0], adhs->datarate[1],
  467. adhs->datarate[2], adhs->datarate[3]);
  468. lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
  469. if (libertas_create_dnld_countryinfo_11d(priv)) {
  470. lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
  471. ret = -1;
  472. goto done;
  473. }
  474. cmd->size =
  475. cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start)
  476. + S_DS_GEN + cmdappendsize);
  477. memcpy(&tmpcap, &adhs->cap, sizeof(u16));
  478. tmpcap = cpu_to_le16(tmpcap);
  479. memcpy(&adhs->cap, &tmpcap, sizeof(u16));
  480. ret = 0;
  481. done:
  482. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  483. return ret;
  484. }
  485. int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
  486. struct cmd_ds_command *cmd)
  487. {
  488. cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_stop);
  489. cmd->size = cpu_to_le16(S_DS_GEN);
  490. return 0;
  491. }
  492. int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
  493. struct cmd_ds_command *cmd, void *pdata_buf)
  494. {
  495. wlan_adapter *adapter = priv->adapter;
  496. struct cmd_ds_802_11_ad_hoc_join *padhocjoin = &cmd->params.adj;
  497. struct bss_descriptor *pbssdesc = pdata_buf;
  498. int cmdappendsize = 0;
  499. int ret = 0;
  500. u8 *card_rates;
  501. int card_rates_size;
  502. u16 tmpcap;
  503. int i;
  504. lbs_deb_enter(LBS_DEB_JOIN);
  505. adapter->pattemptedbssdesc = pbssdesc;
  506. cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
  507. padhocjoin->bssdescriptor.bsstype = cmd_bss_type_ibss;
  508. padhocjoin->bssdescriptor.beaconperiod = pbssdesc->beaconperiod;
  509. memcpy(&padhocjoin->bssdescriptor.BSSID,
  510. &pbssdesc->macaddress, ETH_ALEN);
  511. memcpy(&padhocjoin->bssdescriptor.SSID,
  512. &pbssdesc->ssid.ssid, pbssdesc->ssid.ssidlength);
  513. memcpy(&padhocjoin->bssdescriptor.phyparamset,
  514. &pbssdesc->phyparamset, sizeof(union ieeetypes_phyparamset));
  515. memcpy(&padhocjoin->bssdescriptor.ssparamset,
  516. &pbssdesc->ssparamset, sizeof(union IEEEtypes_ssparamset));
  517. memcpy(&tmpcap, &pbssdesc->cap, sizeof(struct ieeetypes_capinfo));
  518. tmpcap &= CAPINFO_MASK;
  519. lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
  520. tmpcap, CAPINFO_MASK);
  521. memcpy(&padhocjoin->bssdescriptor.cap, &tmpcap,
  522. sizeof(struct ieeetypes_capinfo));
  523. /* information on BSSID descriptor passed to FW */
  524. lbs_deb_join(
  525. "ADHOC_J_CMD: BSSID = %2x-%2x-%2x-%2x-%2x-%2x, SSID = %s\n",
  526. padhocjoin->bssdescriptor.BSSID[0],
  527. padhocjoin->bssdescriptor.BSSID[1],
  528. padhocjoin->bssdescriptor.BSSID[2],
  529. padhocjoin->bssdescriptor.BSSID[3],
  530. padhocjoin->bssdescriptor.BSSID[4],
  531. padhocjoin->bssdescriptor.BSSID[5],
  532. padhocjoin->bssdescriptor.SSID);
  533. /* failtimeout */
  534. padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
  535. /* probedelay */
  536. padhocjoin->probedelay =
  537. cpu_to_le16(cmd_scan_probe_delay_time);
  538. /* Copy Data rates from the rates recorded in scan response */
  539. memset(padhocjoin->bssdescriptor.datarates, 0,
  540. sizeof(padhocjoin->bssdescriptor.datarates));
  541. memcpy(padhocjoin->bssdescriptor.datarates, pbssdesc->datarates,
  542. min(sizeof(padhocjoin->bssdescriptor.datarates),
  543. sizeof(pbssdesc->datarates)));
  544. card_rates = libertas_supported_rates;
  545. card_rates_size = sizeof(libertas_supported_rates);
  546. adapter->curbssparams.channel = pbssdesc->channel;
  547. if (get_common_rates(adapter, padhocjoin->bssdescriptor.datarates,
  548. sizeof(padhocjoin->bssdescriptor.datarates),
  549. card_rates, card_rates_size)) {
  550. lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
  551. ret = -1;
  552. goto done;
  553. }
  554. /* Find the last non zero */
  555. for (i = 0; i < sizeof(padhocjoin->bssdescriptor.datarates)
  556. && padhocjoin->bssdescriptor.datarates[i]; i++) ;
  557. adapter->curbssparams.numofrates = i;
  558. /*
  559. * Copy the adhoc joining rates to Current BSS State structure
  560. */
  561. memcpy(adapter->curbssparams.datarates,
  562. padhocjoin->bssdescriptor.datarates,
  563. adapter->curbssparams.numofrates);
  564. padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
  565. cpu_to_le16(pbssdesc->atimwindow);
  566. if (adapter->secinfo.wep_enabled) {
  567. padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
  568. }
  569. if (adapter->psmode == wlan802_11powermodemax_psp) {
  570. /* wake up first */
  571. enum WLAN_802_11_POWER_MODE Localpsmode;
  572. Localpsmode = wlan802_11powermodecam;
  573. ret = libertas_prepare_and_send_command(priv,
  574. cmd_802_11_ps_mode,
  575. cmd_act_set,
  576. 0, 0, &Localpsmode);
  577. if (ret) {
  578. ret = -1;
  579. goto done;
  580. }
  581. }
  582. if (libertas_parse_dnld_countryinfo_11d(priv)) {
  583. ret = -1;
  584. goto done;
  585. }
  586. cmd->size =
  587. cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join)
  588. + S_DS_GEN + cmdappendsize);
  589. memcpy(&tmpcap, &padhocjoin->bssdescriptor.cap,
  590. sizeof(struct ieeetypes_capinfo));
  591. tmpcap = cpu_to_le16(tmpcap);
  592. memcpy(&padhocjoin->bssdescriptor.cap,
  593. &tmpcap, sizeof(struct ieeetypes_capinfo));
  594. done:
  595. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  596. return ret;
  597. }
  598. int libertas_ret_80211_associate(wlan_private * priv,
  599. struct cmd_ds_command *resp)
  600. {
  601. wlan_adapter *adapter = priv->adapter;
  602. int ret = 0;
  603. union iwreq_data wrqu;
  604. struct ieeetypes_assocrsp *passocrsp;
  605. struct bss_descriptor *pbssdesc;
  606. lbs_deb_enter(LBS_DEB_JOIN);
  607. passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
  608. if (passocrsp->statuscode) {
  609. libertas_mac_event_disconnected(priv);
  610. lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
  611. passocrsp->statuscode);
  612. ret = -1;
  613. goto done;
  614. }
  615. lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
  616. le16_to_cpu(resp->size) - S_DS_GEN);
  617. /* Send a Media Connected event, according to the Spec */
  618. adapter->connect_status = libertas_connected;
  619. /* Set the attempted BSSID Index to current */
  620. pbssdesc = adapter->pattemptedbssdesc;
  621. lbs_deb_join("ASSOC_RESP: %s\n", pbssdesc->ssid.ssid);
  622. /* Set the new SSID to current SSID */
  623. memcpy(&adapter->curbssparams.ssid,
  624. &pbssdesc->ssid, sizeof(struct WLAN_802_11_SSID));
  625. /* Set the new BSSID (AP's MAC address) to current BSSID */
  626. memcpy(adapter->curbssparams.bssid,
  627. pbssdesc->macaddress, ETH_ALEN);
  628. /* Make a copy of current BSSID descriptor */
  629. memcpy(&adapter->curbssparams.bssdescriptor,
  630. pbssdesc, sizeof(struct bss_descriptor));
  631. lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
  632. adapter->currentpacketfilter);
  633. adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
  634. adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
  635. memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
  636. memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
  637. adapter->nextSNRNF = 0;
  638. adapter->numSNRNF = 0;
  639. netif_carrier_on(priv->dev);
  640. netif_wake_queue(priv->dev);
  641. netif_carrier_on(priv->mesh_dev);
  642. netif_wake_queue(priv->mesh_dev);
  643. lbs_deb_join("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->dev, SIOCGIWAP, &wrqu, NULL);
  647. done:
  648. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  649. return ret;
  650. }
  651. int libertas_ret_80211_disassociate(wlan_private * priv,
  652. struct cmd_ds_command *resp)
  653. {
  654. lbs_deb_enter(LBS_DEB_JOIN);
  655. libertas_mac_event_disconnected(priv);
  656. lbs_deb_leave(LBS_DEB_JOIN);
  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. lbs_deb_enter(LBS_DEB_JOIN);
  670. padhocresult = &resp->params.result;
  671. lbs_deb_join("ADHOC_S_RESP: size = %d\n", le16_to_cpu(resp->size));
  672. lbs_deb_join("ADHOC_S_RESP: command = %x\n", command);
  673. lbs_deb_join("ADHOC_S_RESP: result = %x\n", result);
  674. pbssdesc = adapter->pattemptedbssdesc;
  675. /*
  676. * Join result code 0 --> SUCCESS
  677. */
  678. if (result) {
  679. lbs_deb_join("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. ret = -1;
  686. goto done;
  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_deb_join("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->dev);
  713. netif_wake_queue(priv->dev);
  714. netif_carrier_on(priv->mesh_dev);
  715. netif_wake_queue(priv->mesh_dev);
  716. memset(&wrqu, 0, sizeof(wrqu));
  717. memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
  718. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  719. wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
  720. lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
  721. lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->adhocchannel);
  722. lbs_deb_join("ADHOC_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
  723. padhocresult->BSSID[0], padhocresult->BSSID[1],
  724. padhocresult->BSSID[2], padhocresult->BSSID[3],
  725. padhocresult->BSSID[4], padhocresult->BSSID[5]);
  726. done:
  727. lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
  728. return ret;
  729. }
  730. int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
  731. struct cmd_ds_command *resp)
  732. {
  733. lbs_deb_enter(LBS_DEB_JOIN);
  734. libertas_mac_event_disconnected(priv);
  735. lbs_deb_leave(LBS_DEB_JOIN);
  736. return 0;
  737. }