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
7 #include <linux/netdevice.h>
8 #include <linux/if_arp.h>
9 #include <linux/wireless.h>
11 #include <net/iw_handler.h>
18 #define AD_HOC_CAP_PRIVACY_ON 1
21 * @brief This function finds out the common rates between rate1 and rate2.
23 * It will fill common rates in rate1 as output if found.
25 * NOTE: Setting the MSB of the basic rates need to be taken
26 * care, either before or after calling this function
28 * @param adapter A pointer to wlan_adapter structure
29 * @param rate1 the buffer which keeps input and output
30 * @param rate1_size the size of rate1 buffer
31 * @param rate2 the buffer which keeps rate2
32 * @param rate2_size the size of rate2 buffer.
36 static int get_common_rates(wlan_adapter * adapter, u8 * rate1,
37 int rate1_size, u8 * rate2, int rate2_size)
44 memset(&tmp, 0, sizeof(tmp));
45 memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
46 memset(rate1, 0, rate1_size);
48 /* Mask the top bit of the original values */
49 for (i = 0; tmp[i] && i < sizeof(tmp); i++)
52 for (i = 0; rate2[i] && i < rate2_size; i++) {
53 /* Check for Card Rate in tmp, excluding the top bit */
54 if (strchr(tmp, rate2[i] & 0x7F)) {
55 /* values match, so copy the Card Rate to rate1 */
60 lbs_dbg_hex("rate1 (AP) rates:", tmp, sizeof(tmp));
61 lbs_dbg_hex("rate2 (Card) rates:", rate2, rate2_size);
62 lbs_dbg_hex("Common rates:", ptr, rate1_size);
63 lbs_pr_debug(1, "Tx datarate is set to 0x%X\n", adapter->datarate);
65 if (!adapter->is_datarate_auto) {
67 if ((*ptr & 0x7f) == adapter->datarate) {
73 lbs_pr_alert( "Previously set fixed data rate %#x isn't "
74 "compatible with the network.\n", adapter->datarate);
85 int libertas_send_deauth(wlan_private * priv)
87 wlan_adapter *adapter = priv->adapter;
90 if (adapter->mode == IW_MODE_INFRA &&
91 adapter->connect_status == libertas_connected)
92 ret = libertas_send_deauthentication(priv);
100 * @brief Associate to a specific BSS discovered in a scan
102 * @param priv A pointer to wlan_private structure
103 * @param pbssdesc Pointer to the BSS descriptor to associate with.
105 * @return 0-success, otherwise fail
107 int wlan_associate(wlan_private * priv, struct bss_descriptor * pbssdesc)
109 wlan_adapter *adapter = priv->adapter;
114 ret = libertas_prepare_and_send_command(priv, cmd_802_11_authenticate,
115 0, cmd_option_waitforrsp,
116 0, pbssdesc->macaddress);
123 /* set preamble to firmware */
124 if (adapter->capinfo.shortpreamble && pbssdesc->cap.shortpreamble)
125 adapter->preamble = cmd_type_short_preamble;
127 adapter->preamble = cmd_type_long_preamble;
129 libertas_set_radio_control(priv);
131 ret = libertas_prepare_and_send_command(priv, cmd_802_11_associate,
132 0, cmd_option_waitforrsp, 0, pbssdesc);
139 * @brief Start an Adhoc Network
141 * @param priv A pointer to wlan_private structure
142 * @param adhocssid The ssid of the Adhoc Network
143 * @return 0--success, -1--fail
145 int libertas_start_adhoc_network(wlan_private * priv, struct WLAN_802_11_SSID *adhocssid)
147 wlan_adapter *adapter = priv->adapter;
150 adapter->adhoccreate = 1;
152 if (!adapter->capinfo.shortpreamble) {
153 lbs_pr_debug(1, "AdhocStart: Long preamble\n");
154 adapter->preamble = cmd_type_long_preamble;
156 lbs_pr_debug(1, "AdhocStart: Short preamble\n");
157 adapter->preamble = cmd_type_short_preamble;
160 libertas_set_radio_control(priv);
162 lbs_pr_debug(1, "Adhoc channel = %d\n", adapter->adhocchannel);
163 lbs_pr_debug(1, "curbssparams.channel = %d\n",
164 adapter->curbssparams.channel);
165 lbs_pr_debug(1, "curbssparams.band = %d\n", adapter->curbssparams.band);
167 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
168 0, cmd_option_waitforrsp, 0, adhocssid);
174 * @brief Join an adhoc network found in a previous scan
176 * @param priv A pointer to wlan_private structure
177 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
180 * @return 0--success, -1--fail
182 int libertas_join_adhoc_network(wlan_private * priv, struct bss_descriptor * pbssdesc)
184 wlan_adapter *adapter = priv->adapter;
187 lbs_pr_debug(1, "libertas_join_adhoc_network: CurBss.ssid =%s\n",
188 adapter->curbssparams.ssid.ssid);
189 lbs_pr_debug(1, "libertas_join_adhoc_network: CurBss.ssid_len =%u\n",
190 adapter->curbssparams.ssid.ssidlength);
191 lbs_pr_debug(1, "libertas_join_adhoc_network: ssid =%s\n", pbssdesc->ssid.ssid);
192 lbs_pr_debug(1, "libertas_join_adhoc_network: ssid len =%u\n",
193 pbssdesc->ssid.ssidlength);
195 /* check if the requested SSID is already joined */
196 if (adapter->curbssparams.ssid.ssidlength
197 && !libertas_SSID_cmp(&pbssdesc->ssid, &adapter->curbssparams.ssid)
198 && (adapter->mode == IW_MODE_ADHOC)) {
201 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
202 "not attempting to re-join");
207 /*Use shortpreamble only when both creator and card supports
209 if (!pbssdesc->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
210 lbs_pr_debug(1, "AdhocJoin: Long preamble\n");
211 adapter->preamble = cmd_type_long_preamble;
213 lbs_pr_debug(1, "AdhocJoin: Short preamble\n");
214 adapter->preamble = cmd_type_short_preamble;
217 libertas_set_radio_control(priv);
219 lbs_pr_debug(1, "curbssparams.channel = %d\n",
220 adapter->curbssparams.channel);
221 lbs_pr_debug(1, "curbssparams.band = %c\n", adapter->curbssparams.band);
223 adapter->adhoccreate = 0;
225 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_join,
226 0, cmd_option_waitforrsp,
227 OID_802_11_SSID, pbssdesc);
232 int libertas_stop_adhoc_network(wlan_private * priv)
234 return libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_stop,
235 0, cmd_option_waitforrsp, 0, NULL);
239 * @brief Send Deauthentication Request
241 * @param priv A pointer to wlan_private structure
242 * @return 0--success, -1--fail
244 int libertas_send_deauthentication(wlan_private * priv)
246 return libertas_prepare_and_send_command(priv, cmd_802_11_deauthenticate,
247 0, cmd_option_waitforrsp, 0, NULL);
251 * @brief This function prepares command of authenticate.
253 * @param priv A pointer to wlan_private structure
254 * @param cmd A pointer to cmd_ds_command structure
255 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
259 int libertas_cmd_80211_authenticate(wlan_private * priv,
260 struct cmd_ds_command *cmd,
263 wlan_adapter *adapter = priv->adapter;
264 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
266 u8 *bssid = pdata_buf;
268 cmd->command = cpu_to_le16(cmd_802_11_authenticate);
269 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
272 /* translate auth mode to 802.11 defined wire value */
273 switch (adapter->secinfo.auth_mode) {
274 case IW_AUTH_ALG_OPEN_SYSTEM:
275 pauthenticate->authtype = 0x00;
277 case IW_AUTH_ALG_SHARED_KEY:
278 pauthenticate->authtype = 0x01;
280 case IW_AUTH_ALG_LEAP:
281 pauthenticate->authtype = 0x80;
284 lbs_pr_debug(1, "AUTH_CMD: invalid auth alg 0x%X\n",
285 adapter->secinfo.auth_mode);
289 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
291 lbs_pr_debug(1, "AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n",
292 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
299 int libertas_cmd_80211_deauthenticate(wlan_private * priv,
300 struct cmd_ds_command *cmd)
302 wlan_adapter *adapter = priv->adapter;
303 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
307 cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
309 cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
312 /* set AP MAC address */
313 memmove(dauth->macaddr, adapter->curbssparams.bssid,
316 /* Reason code 3 = Station is leaving */
317 #define REASON_CODE_STA_LEAVING 3
318 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
324 int libertas_cmd_80211_associate(wlan_private * priv,
325 struct cmd_ds_command *cmd, void *pdata_buf)
327 wlan_adapter *adapter = priv->adapter;
328 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
330 struct bss_descriptor *pbssdesc;
335 struct mrvlietypes_ssidparamset *ssid;
336 struct mrvlietypes_phyparamset *phy;
337 struct mrvlietypes_ssparamset *ss;
338 struct mrvlietypes_ratesparamset *rates;
339 struct mrvlietypes_rsnparamset *rsn;
343 pbssdesc = pdata_buf;
351 cmd->command = cpu_to_le16(cmd_802_11_associate);
353 /* Save so we know which BSS Desc to use in the response handler */
354 adapter->pattemptedbssdesc = pbssdesc;
356 memcpy(passo->peerstaaddr,
357 pbssdesc->macaddress, sizeof(passo->peerstaaddr));
358 pos += sizeof(passo->peerstaaddr);
360 /* set the listen interval */
361 passo->listeninterval = adapter->listeninterval;
363 pos += sizeof(passo->capinfo);
364 pos += sizeof(passo->listeninterval);
365 pos += sizeof(passo->bcnperiod);
366 pos += sizeof(passo->dtimperiod);
368 ssid = (struct mrvlietypes_ssidparamset *) pos;
369 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
370 ssid->header.len = pbssdesc->ssid.ssidlength;
371 memcpy(ssid->ssid, pbssdesc->ssid.ssid, ssid->header.len);
372 pos += sizeof(ssid->header) + ssid->header.len;
373 ssid->header.len = cpu_to_le16(ssid->header.len);
375 phy = (struct mrvlietypes_phyparamset *) pos;
376 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
377 phy->header.len = sizeof(phy->fh_ds.dsparamset);
378 memcpy(&phy->fh_ds.dsparamset,
379 &pbssdesc->phyparamset.dsparamset.currentchan,
380 sizeof(phy->fh_ds.dsparamset));
381 pos += sizeof(phy->header) + phy->header.len;
382 phy->header.len = cpu_to_le16(phy->header.len);
384 ss = (struct mrvlietypes_ssparamset *) pos;
385 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
386 ss->header.len = sizeof(ss->cf_ibss.cfparamset);
387 pos += sizeof(ss->header) + ss->header.len;
388 ss->header.len = cpu_to_le16(ss->header.len);
390 rates = (struct mrvlietypes_ratesparamset *) pos;
391 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
393 memcpy(&rates->rates, &pbssdesc->libertas_supported_rates, WLAN_SUPPORTED_RATES);
395 card_rates = libertas_supported_rates;
396 card_rates_size = sizeof(libertas_supported_rates);
398 if (get_common_rates(adapter, rates->rates, WLAN_SUPPORTED_RATES,
399 card_rates, card_rates_size)) {
404 rates->header.len = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
405 adapter->curbssparams.numofrates = rates->header.len;
407 pos += sizeof(rates->header) + rates->header.len;
408 rates->header.len = cpu_to_le16(rates->header.len);
410 if (adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
411 rsn = (struct mrvlietypes_rsnparamset *) pos;
412 rsn->header.type = (u16) adapter->wpa_ie[0]; /* WPA_IE or WPA2_IE */
413 rsn->header.type = cpu_to_le16(rsn->header.type);
414 rsn->header.len = (u16) adapter->wpa_ie[1];
415 memcpy(rsn->rsnie, &adapter->wpa_ie[2], rsn->header.len);
416 lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
417 sizeof(rsn->header) + rsn->header.len);
418 pos += sizeof(rsn->header) + rsn->header.len;
419 rsn->header.len = cpu_to_le16(rsn->header.len);
422 /* update curbssparams */
423 adapter->curbssparams.channel =
424 (pbssdesc->phyparamset.dsparamset.currentchan);
426 /* Copy the infra. association rates into Current BSS state structure */
427 memcpy(&adapter->curbssparams.datarates, &rates->rates,
428 min_t(size_t, sizeof(adapter->curbssparams.datarates), rates->header.len));
430 lbs_pr_debug(1, "ASSOC_CMD: rates->header.len = %d\n", rates->header.len);
433 if (pbssdesc->mode == IW_MODE_INFRA) {
434 #define CAPINFO_ESS_MODE 1
435 passo->capinfo.ess = CAPINFO_ESS_MODE;
438 if (libertas_parse_dnld_countryinfo_11d(priv)) {
443 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
445 /* set the capability info at last */
446 memcpy(&tmpcap, &pbssdesc->cap, sizeof(passo->capinfo));
447 tmpcap &= CAPINFO_MASK;
448 lbs_pr_debug(1, "ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
449 tmpcap, CAPINFO_MASK);
450 tmpcap = cpu_to_le16(tmpcap);
451 memcpy(&passo->capinfo, &tmpcap, sizeof(passo->capinfo));
458 int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
459 struct cmd_ds_command *cmd, void *pssid)
461 wlan_adapter *adapter = priv->adapter;
462 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
464 int cmdappendsize = 0;
467 struct bss_descriptor *pbssdesc;
468 struct WLAN_802_11_SSID *ssid = pssid;
477 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
479 pbssdesc = &adapter->curbssparams.bssdescriptor;
480 adapter->pattemptedbssdesc = pbssdesc;
483 * Fill in the parameters for 2 data structures:
484 * 1. cmd_ds_802_11_ad_hoc_start command
485 * 2. adapter->scantable[i]
487 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
488 * probe delay, and cap info.
490 * Firmware will fill up beacon period, DTIM, Basic rates
491 * and operational rates.
494 memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
496 memcpy(adhs->SSID, ssid->ssid, ssid->ssidlength);
498 lbs_pr_debug(1, "ADHOC_S_CMD: SSID = %s\n", adhs->SSID);
500 memset(pbssdesc->ssid.ssid, 0, IW_ESSID_MAX_SIZE);
501 memcpy(pbssdesc->ssid.ssid, ssid->ssid, ssid->ssidlength);
503 pbssdesc->ssid.ssidlength = ssid->ssidlength;
505 /* set the BSS type */
506 adhs->bsstype = cmd_bss_type_ibss;
507 pbssdesc->mode = IW_MODE_ADHOC;
508 adhs->beaconperiod = adapter->beaconperiod;
510 /* set Physical param set */
511 #define DS_PARA_IE_ID 3
512 #define DS_PARA_IE_LEN 1
514 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
515 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
517 WARN_ON(!adapter->adhocchannel);
519 lbs_pr_debug(1, "ADHOC_S_CMD: Creating ADHOC on channel %d\n",
520 adapter->adhocchannel);
522 adapter->curbssparams.channel = adapter->adhocchannel;
524 pbssdesc->channel = adapter->adhocchannel;
525 adhs->phyparamset.dsparamset.currentchan = adapter->adhocchannel;
527 memcpy(&pbssdesc->phyparamset,
528 &adhs->phyparamset, sizeof(union ieeetypes_phyparamset));
530 /* set IBSS param set */
531 #define IBSS_PARA_IE_ID 6
532 #define IBSS_PARA_IE_LEN 2
534 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
535 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
536 adhs->ssparamset.ibssparamset.atimwindow = adapter->atimwindow;
537 memcpy(&pbssdesc->ssparamset,
538 &adhs->ssparamset, sizeof(union IEEEtypes_ssparamset));
540 /* set capability info */
543 pbssdesc->cap.ibss = 1;
546 adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
548 /* set up privacy in adapter->scantable[i] */
549 if (adapter->secinfo.wep_enabled) {
550 lbs_pr_debug(1, "ADHOC_S_CMD: WEP enabled, setting privacy on\n");
551 pbssdesc->privacy = wlan802_11privfilter8021xWEP;
552 adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
554 lbs_pr_debug(1, "ADHOC_S_CMD: WEP disabled, setting privacy off\n");
555 pbssdesc->privacy = wlan802_11privfilteracceptall;
558 memset(adhs->datarate, 0, sizeof(adhs->datarate));
560 if (adapter->adhoc_grate_enabled) {
561 memcpy(adhs->datarate, libertas_adhoc_rates_g,
562 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_g)));
564 memcpy(adhs->datarate, libertas_adhoc_rates_b,
565 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_b)));
568 /* Find the last non zero */
569 for (i = 0; i < sizeof(adhs->datarate) && adhs->datarate[i]; i++) ;
571 adapter->curbssparams.numofrates = i;
573 /* Copy the ad-hoc creating rates into Current BSS state structure */
574 memcpy(&adapter->curbssparams.datarates,
575 &adhs->datarate, adapter->curbssparams.numofrates);
577 lbs_pr_debug(1, "ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
578 adhs->datarate[0], adhs->datarate[1],
579 adhs->datarate[2], adhs->datarate[3]);
581 lbs_pr_debug(1, "ADHOC_S_CMD: AD HOC Start command is ready\n");
583 if (libertas_create_dnld_countryinfo_11d(priv)) {
584 lbs_pr_debug(1, "ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
590 cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start)
591 + S_DS_GEN + cmdappendsize);
593 memcpy(&tmpcap, &adhs->cap, sizeof(u16));
594 tmpcap = cpu_to_le16(tmpcap);
595 memcpy(&adhs->cap, &tmpcap, sizeof(u16));
603 int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
604 struct cmd_ds_command *cmd)
606 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_stop);
607 cmd->size = cpu_to_le16(S_DS_GEN);
612 int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
613 struct cmd_ds_command *cmd, void *pdata_buf)
615 wlan_adapter *adapter = priv->adapter;
616 struct cmd_ds_802_11_ad_hoc_join *padhocjoin = &cmd->params.adj;
617 struct bss_descriptor *pbssdesc = pdata_buf;
618 int cmdappendsize = 0;
627 adapter->pattemptedbssdesc = pbssdesc;
629 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
631 padhocjoin->bssdescriptor.bsstype = cmd_bss_type_ibss;
633 padhocjoin->bssdescriptor.beaconperiod = pbssdesc->beaconperiod;
635 memcpy(&padhocjoin->bssdescriptor.BSSID,
636 &pbssdesc->macaddress, ETH_ALEN);
638 memcpy(&padhocjoin->bssdescriptor.SSID,
639 &pbssdesc->ssid.ssid, pbssdesc->ssid.ssidlength);
641 memcpy(&padhocjoin->bssdescriptor.phyparamset,
642 &pbssdesc->phyparamset, sizeof(union ieeetypes_phyparamset));
644 memcpy(&padhocjoin->bssdescriptor.ssparamset,
645 &pbssdesc->ssparamset, sizeof(union IEEEtypes_ssparamset));
647 memcpy(&tmpcap, &pbssdesc->cap, sizeof(struct ieeetypes_capinfo));
648 tmpcap &= CAPINFO_MASK;
650 lbs_pr_debug(1, "ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
651 tmpcap, CAPINFO_MASK);
652 memcpy(&padhocjoin->bssdescriptor.cap, &tmpcap,
653 sizeof(struct ieeetypes_capinfo));
655 /* information on BSSID descriptor passed to FW */
657 "ADHOC_J_CMD: BSSID = %2x-%2x-%2x-%2x-%2x-%2x, SSID = %s\n",
658 padhocjoin->bssdescriptor.BSSID[0],
659 padhocjoin->bssdescriptor.BSSID[1],
660 padhocjoin->bssdescriptor.BSSID[2],
661 padhocjoin->bssdescriptor.BSSID[3],
662 padhocjoin->bssdescriptor.BSSID[4],
663 padhocjoin->bssdescriptor.BSSID[5],
664 padhocjoin->bssdescriptor.SSID);
667 padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
670 padhocjoin->probedelay =
671 cpu_to_le16(cmd_scan_probe_delay_time);
673 /* Copy Data rates from the rates recorded in scan response */
674 memset(padhocjoin->bssdescriptor.datarates, 0,
675 sizeof(padhocjoin->bssdescriptor.datarates));
676 memcpy(padhocjoin->bssdescriptor.datarates, pbssdesc->datarates,
677 min(sizeof(padhocjoin->bssdescriptor.datarates),
678 sizeof(pbssdesc->datarates)));
680 card_rates = libertas_supported_rates;
681 card_rates_size = sizeof(libertas_supported_rates);
683 adapter->curbssparams.channel = pbssdesc->channel;
685 if (get_common_rates(adapter, padhocjoin->bssdescriptor.datarates,
686 sizeof(padhocjoin->bssdescriptor.datarates),
687 card_rates, card_rates_size)) {
688 lbs_pr_debug(1, "ADHOC_J_CMD: get_common_rates returns error.\n");
693 /* Find the last non zero */
694 for (i = 0; i < sizeof(padhocjoin->bssdescriptor.datarates)
695 && padhocjoin->bssdescriptor.datarates[i]; i++) ;
697 adapter->curbssparams.numofrates = i;
700 * Copy the adhoc joining rates to Current BSS State structure
702 memcpy(adapter->curbssparams.datarates,
703 padhocjoin->bssdescriptor.datarates,
704 adapter->curbssparams.numofrates);
706 padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
707 cpu_to_le16(pbssdesc->atimwindow);
709 if (adapter->secinfo.wep_enabled) {
710 padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
713 if (adapter->psmode == wlan802_11powermodemax_psp) {
715 enum WLAN_802_11_POWER_MODE Localpsmode;
717 Localpsmode = wlan802_11powermodecam;
718 ret = libertas_prepare_and_send_command(priv,
729 if (libertas_parse_dnld_countryinfo_11d(priv)) {
735 cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join)
736 + S_DS_GEN + cmdappendsize);
738 memcpy(&tmpcap, &padhocjoin->bssdescriptor.cap,
739 sizeof(struct ieeetypes_capinfo));
740 tmpcap = cpu_to_le16(tmpcap);
742 memcpy(&padhocjoin->bssdescriptor.cap,
743 &tmpcap, sizeof(struct ieeetypes_capinfo));
750 int libertas_ret_80211_associate(wlan_private * priv,
751 struct cmd_ds_command *resp)
753 wlan_adapter *adapter = priv->adapter;
755 union iwreq_data wrqu;
756 struct ieeetypes_assocrsp *passocrsp;
757 struct bss_descriptor *pbssdesc;
761 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
763 if (passocrsp->statuscode) {
765 libertas_mac_event_disconnected(priv);
768 "ASSOC_RESP: Association failed, status code = %d\n",
769 passocrsp->statuscode);
775 lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
776 le16_to_cpu(resp->size) - S_DS_GEN);
778 /* Send a Media Connected event, according to the Spec */
779 adapter->connect_status = libertas_connected;
781 /* Set the attempted BSSID Index to current */
782 pbssdesc = adapter->pattemptedbssdesc;
784 lbs_pr_debug(1, "ASSOC_RESP: %s\n", pbssdesc->ssid.ssid);
786 /* Set the new SSID to current SSID */
787 memcpy(&adapter->curbssparams.ssid,
788 &pbssdesc->ssid, sizeof(struct WLAN_802_11_SSID));
790 /* Set the new BSSID (AP's MAC address) to current BSSID */
791 memcpy(adapter->curbssparams.bssid,
792 pbssdesc->macaddress, ETH_ALEN);
794 /* Make a copy of current BSSID descriptor */
795 memcpy(&adapter->curbssparams.bssdescriptor,
796 pbssdesc, sizeof(struct bss_descriptor));
798 lbs_pr_debug(1, "ASSOC_RESP: currentpacketfilter is %x\n",
799 adapter->currentpacketfilter);
801 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
802 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
804 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
805 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
806 adapter->nextSNRNF = 0;
807 adapter->numSNRNF = 0;
809 netif_carrier_on(priv->wlan_dev.netdev);
810 netif_wake_queue(priv->wlan_dev.netdev);
812 lbs_pr_debug(1, "ASSOC_RESP: Associated \n");
814 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
815 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
816 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
823 int libertas_ret_80211_disassociate(wlan_private * priv,
824 struct cmd_ds_command *resp)
828 libertas_mac_event_disconnected(priv);
834 int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
835 struct cmd_ds_command *resp)
837 wlan_adapter *adapter = priv->adapter;
839 u16 command = le16_to_cpu(resp->command);
840 u16 result = le16_to_cpu(resp->result);
841 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
842 union iwreq_data wrqu;
843 struct bss_descriptor *pbssdesc;
847 padhocresult = &resp->params.result;
849 lbs_pr_debug(1, "ADHOC_S_RESP: size = %d\n", le16_to_cpu(resp->size));
850 lbs_pr_debug(1, "ADHOC_S_RESP: command = %x\n", command);
851 lbs_pr_debug(1, "ADHOC_S_RESP: result = %x\n", result);
853 pbssdesc = adapter->pattemptedbssdesc;
856 * Join result code 0 --> SUCCESS
859 lbs_pr_debug(1, "ADHOC_RESP failed\n");
860 if (adapter->connect_status == libertas_connected) {
861 libertas_mac_event_disconnected(priv);
864 memset(&adapter->curbssparams.bssdescriptor,
865 0x00, sizeof(adapter->curbssparams.bssdescriptor));
872 * Now the join cmd should be successful
873 * If BSSID has changed use SSID to compare instead of BSSID
875 lbs_pr_debug(1, "ADHOC_J_RESP %s\n", pbssdesc->ssid.ssid);
877 /* Send a Media Connected event, according to the Spec */
878 adapter->connect_status = libertas_connected;
880 if (command == cmd_ret_802_11_ad_hoc_start) {
881 /* Update the created network descriptor with the new BSSID */
882 memcpy(pbssdesc->macaddress,
883 padhocresult->BSSID, ETH_ALEN);
886 /* Make a copy of current BSSID descriptor, only needed for join since
887 * the current descriptor is already being used for adhoc start
889 memmove(&adapter->curbssparams.bssdescriptor,
890 pbssdesc, sizeof(struct bss_descriptor));
893 /* Set the BSSID from the joined/started descriptor */
894 memcpy(&adapter->curbssparams.bssid,
895 pbssdesc->macaddress, ETH_ALEN);
897 /* Set the new SSID to current SSID */
898 memcpy(&adapter->curbssparams.ssid,
899 &pbssdesc->ssid, sizeof(struct WLAN_802_11_SSID));
901 netif_carrier_on(priv->wlan_dev.netdev);
902 netif_wake_queue(priv->wlan_dev.netdev);
904 memset(&wrqu, 0, sizeof(wrqu));
905 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
906 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
907 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);
909 lbs_pr_debug(1, "ADHOC_RESP: - Joined/Started Ad Hoc\n");
910 lbs_pr_debug(1, "ADHOC_RESP: channel = %d\n", adapter->adhocchannel);
911 lbs_pr_debug(1, "ADHOC_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
912 padhocresult->BSSID[0], padhocresult->BSSID[1],
913 padhocresult->BSSID[2], padhocresult->BSSID[3],
914 padhocresult->BSSID[4], padhocresult->BSSID[5]);
920 int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
921 struct cmd_ds_command *resp)
925 libertas_mac_event_disconnected(priv);