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>
10 #include <linux/etherdevice.h>
12 #include <net/iw_handler.h>
20 #define AD_HOC_CAP_PRIVACY_ON 1
23 * @brief This function finds out the common rates between rate1 and rate2.
25 * It will fill common rates in rate1 as output if found.
27 * NOTE: Setting the MSB of the basic rates need to be taken
28 * care, either before or after calling this function
30 * @param adapter A pointer to wlan_adapter structure
31 * @param rate1 the buffer which keeps input and output
32 * @param rate1_size the size of rate1 buffer
33 * @param rate2 the buffer which keeps rate2
34 * @param rate2_size the size of rate2 buffer.
38 static int get_common_rates(wlan_adapter * adapter, u8 * rate1,
39 int rate1_size, u8 * rate2, int rate2_size)
46 memset(&tmp, 0, sizeof(tmp));
47 memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
48 memset(rate1, 0, rate1_size);
50 /* Mask the top bit of the original values */
51 for (i = 0; tmp[i] && i < sizeof(tmp); i++)
54 for (i = 0; rate2[i] && i < rate2_size; i++) {
55 /* Check for Card Rate in tmp, excluding the top bit */
56 if (strchr(tmp, rate2[i] & 0x7F)) {
57 /* values match, so copy the Card Rate to rate1 */
62 lbs_dbg_hex("rate1 (AP) rates:", tmp, sizeof(tmp));
63 lbs_dbg_hex("rate2 (Card) rates:", rate2, rate2_size);
64 lbs_dbg_hex("Common rates:", ptr, rate1_size);
65 lbs_deb_join("Tx datarate is set to 0x%X\n", adapter->datarate);
67 if (!adapter->is_datarate_auto) {
69 if ((*ptr & 0x7f) == adapter->datarate) {
75 lbs_pr_alert( "Previously set fixed data rate %#x isn't "
76 "compatible with the network.\n", adapter->datarate);
87 int libertas_send_deauth(wlan_private * priv)
89 wlan_adapter *adapter = priv->adapter;
92 if (adapter->mode == IW_MODE_INFRA &&
93 adapter->connect_status == libertas_connected)
94 ret = libertas_send_deauthentication(priv);
102 * @brief Associate to a specific BSS discovered in a scan
104 * @param priv A pointer to wlan_private structure
105 * @param pbssdesc Pointer to the BSS descriptor to associate with.
107 * @return 0-success, otherwise fail
109 int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
111 wlan_adapter *adapter = priv->adapter;
114 lbs_deb_enter(LBS_DEB_JOIN);
116 ret = libertas_prepare_and_send_command(priv, cmd_802_11_authenticate,
117 0, cmd_option_waitforrsp,
118 0, assoc_req->bss.bssid);
123 /* set preamble to firmware */
124 if (adapter->capinfo.shortpreamble && assoc_req->bss.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, assoc_req);
135 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
140 * @brief Start an Adhoc Network
142 * @param priv A pointer to wlan_private structure
143 * @param adhocssid The ssid of the Adhoc Network
144 * @return 0--success, -1--fail
146 int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
148 wlan_adapter *adapter = priv->adapter;
151 adapter->adhoccreate = 1;
153 if (!adapter->capinfo.shortpreamble) {
154 lbs_deb_join("AdhocStart: Long preamble\n");
155 adapter->preamble = cmd_type_long_preamble;
157 lbs_deb_join("AdhocStart: Short preamble\n");
158 adapter->preamble = cmd_type_short_preamble;
161 libertas_set_radio_control(priv);
163 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
164 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
166 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
167 0, cmd_option_waitforrsp, 0, assoc_req);
173 * @brief Join an adhoc network found in a previous scan
175 * @param priv A pointer to wlan_private structure
176 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
179 * @return 0--success, -1--fail
181 int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
183 wlan_adapter *adapter = priv->adapter;
184 struct bss_descriptor * bss = &assoc_req->bss;
187 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
189 escape_essid(adapter->curbssparams.ssid,
190 adapter->curbssparams.ssid_len),
191 adapter->curbssparams.ssid_len);
192 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
193 __func__, escape_essid(bss->ssid, bss->ssid_len),
196 /* check if the requested SSID is already joined */
197 if (adapter->curbssparams.ssid_len
198 && !libertas_ssid_cmp(adapter->curbssparams.ssid,
199 adapter->curbssparams.ssid_len,
200 bss->ssid, bss->ssid_len)
201 && (adapter->mode == IW_MODE_ADHOC)) {
203 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
204 "not attempting to re-join");
208 /*Use shortpreamble only when both creator and card supports
210 if (!bss->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
211 lbs_deb_join("AdhocJoin: Long preamble\n");
212 adapter->preamble = cmd_type_long_preamble;
214 lbs_deb_join("AdhocJoin: Short preamble\n");
215 adapter->preamble = cmd_type_short_preamble;
218 libertas_set_radio_control(priv);
220 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
221 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->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, assoc_req);
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 lbs_deb_enter(LBS_DEB_JOIN);
270 cmd->command = cpu_to_le16(cmd_802_11_authenticate);
271 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
274 /* translate auth mode to 802.11 defined wire value */
275 switch (adapter->secinfo.auth_mode) {
276 case IW_AUTH_ALG_OPEN_SYSTEM:
277 pauthenticate->authtype = 0x00;
279 case IW_AUTH_ALG_SHARED_KEY:
280 pauthenticate->authtype = 0x01;
282 case IW_AUTH_ALG_LEAP:
283 pauthenticate->authtype = 0x80;
286 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
287 adapter->secinfo.auth_mode);
291 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
293 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
294 MAC_ARG(bssid), pauthenticate->authtype);
298 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
302 int libertas_cmd_80211_deauthenticate(wlan_private * priv,
303 struct cmd_ds_command *cmd)
305 wlan_adapter *adapter = priv->adapter;
306 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
308 lbs_deb_enter(LBS_DEB_JOIN);
310 cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
311 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
314 /* set AP MAC address */
315 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
317 /* Reason code 3 = Station is leaving */
318 #define REASON_CODE_STA_LEAVING 3
319 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
321 lbs_deb_leave(LBS_DEB_JOIN);
325 int libertas_cmd_80211_associate(wlan_private * priv,
326 struct cmd_ds_command *cmd, void *pdata_buf)
328 wlan_adapter *adapter = priv->adapter;
329 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
331 struct assoc_request * assoc_req = pdata_buf;
332 struct bss_descriptor * bss = &assoc_req->bss;
337 struct mrvlietypes_ssidparamset *ssid;
338 struct mrvlietypes_phyparamset *phy;
339 struct mrvlietypes_ssparamset *ss;
340 struct mrvlietypes_ratesparamset *rates;
341 struct mrvlietypes_rsnparamset *rsn;
343 lbs_deb_enter(LBS_DEB_JOIN);
352 cmd->command = cpu_to_le16(cmd_802_11_associate);
354 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
355 pos += sizeof(passo->peerstaaddr);
357 /* set the listen interval */
358 passo->listeninterval = cpu_to_le16(adapter->listeninterval);
360 pos += sizeof(passo->capinfo);
361 pos += sizeof(passo->listeninterval);
362 pos += sizeof(passo->bcnperiod);
363 pos += sizeof(passo->dtimperiod);
365 ssid = (struct mrvlietypes_ssidparamset *) pos;
366 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
367 tmplen = bss->ssid_len;
368 ssid->header.len = cpu_to_le16(tmplen);
369 memcpy(ssid->ssid, bss->ssid, tmplen);
370 pos += sizeof(ssid->header) + tmplen;
372 phy = (struct mrvlietypes_phyparamset *) pos;
373 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
374 tmplen = sizeof(phy->fh_ds.dsparamset);
375 phy->header.len = cpu_to_le16(tmplen);
376 memcpy(&phy->fh_ds.dsparamset,
377 &bss->phyparamset.dsparamset.currentchan,
379 pos += sizeof(phy->header) + tmplen;
381 ss = (struct mrvlietypes_ssparamset *) pos;
382 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
383 tmplen = sizeof(ss->cf_ibss.cfparamset);
384 ss->header.len = cpu_to_le16(tmplen);
385 pos += sizeof(ss->header) + tmplen;
387 rates = (struct mrvlietypes_ratesparamset *) pos;
388 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
390 memcpy(&rates->rates, &bss->libertas_supported_rates, WLAN_SUPPORTED_RATES);
392 card_rates = libertas_supported_rates;
393 card_rates_size = sizeof(libertas_supported_rates);
395 if (get_common_rates(adapter, rates->rates, WLAN_SUPPORTED_RATES,
396 card_rates, card_rates_size)) {
401 tmplen = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
402 adapter->curbssparams.numofrates = tmplen;
404 pos += sizeof(rates->header) + tmplen;
405 rates->header.len = cpu_to_le16(tmplen);
407 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
408 rsn = (struct mrvlietypes_rsnparamset *) pos;
409 /* WPA_IE or WPA2_IE */
410 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
411 tmplen = (u16) assoc_req->wpa_ie[1];
412 rsn->header.len = cpu_to_le16(tmplen);
413 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
414 lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
415 sizeof(rsn->header) + tmplen);
416 pos += sizeof(rsn->header) + tmplen;
419 /* update curbssparams */
420 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
422 /* Copy the infra. association rates into Current BSS state structure */
423 memcpy(&adapter->curbssparams.datarates, &rates->rates,
424 min_t(size_t, sizeof(adapter->curbssparams.datarates),
425 cpu_to_le16(rates->header.len)));
427 lbs_deb_join("ASSOC_CMD: rates->header.len = %d\n",
428 cpu_to_le16(rates->header.len));
431 if (bss->mode == IW_MODE_INFRA) {
432 #define CAPINFO_ESS_MODE 1
433 passo->capinfo.ess = CAPINFO_ESS_MODE;
436 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
441 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
443 /* set the capability info at last */
444 memcpy(&tmpcap, &bss->cap, sizeof(passo->capinfo));
445 tmpcap &= CAPINFO_MASK;
446 lbs_deb_join("ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
447 tmpcap, CAPINFO_MASK);
448 memcpy(&passo->capinfo, &tmpcap, sizeof(passo->capinfo));
451 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
455 int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
456 struct cmd_ds_command *cmd, void *pdata_buf)
458 wlan_adapter *adapter = priv->adapter;
459 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
461 int cmdappendsize = 0;
463 struct assoc_request * assoc_req = pdata_buf;
465 lbs_deb_enter(LBS_DEB_JOIN);
472 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
475 * Fill in the parameters for 2 data structures:
476 * 1. cmd_ds_802_11_ad_hoc_start command
477 * 2. adapter->scantable[i]
479 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
480 * probe delay, and cap info.
482 * Firmware will fill up beacon period, DTIM, Basic rates
483 * and operational rates.
486 memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
487 memcpy(adhs->SSID, assoc_req->ssid, assoc_req->ssid_len);
489 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
490 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
491 assoc_req->ssid_len);
493 /* set the BSS type */
494 adhs->bsstype = cmd_bss_type_ibss;
495 adapter->mode = IW_MODE_ADHOC;
496 adhs->beaconperiod = cpu_to_le16(adapter->beaconperiod);
498 /* set Physical param set */
499 #define DS_PARA_IE_ID 3
500 #define DS_PARA_IE_LEN 1
502 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
503 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
505 WARN_ON(!assoc_req->channel);
507 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
510 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
512 /* set IBSS param set */
513 #define IBSS_PARA_IE_ID 6
514 #define IBSS_PARA_IE_LEN 2
516 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
517 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
518 adhs->ssparamset.ibssparamset.atimwindow = cpu_to_le16(adapter->atimwindow);
520 /* set capability info */
525 adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
527 /* set up privacy in adapter->scantable[i] */
528 if (assoc_req->secinfo.wep_enabled) {
529 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
530 adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
532 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
535 memset(adhs->datarate, 0, sizeof(adhs->datarate));
537 if (adapter->adhoc_grate_enabled) {
538 memcpy(adhs->datarate, libertas_adhoc_rates_g,
539 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_g)));
541 memcpy(adhs->datarate, libertas_adhoc_rates_b,
542 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_b)));
545 /* Find the last non zero */
546 for (i = 0; i < sizeof(adhs->datarate) && adhs->datarate[i]; i++) ;
548 adapter->curbssparams.numofrates = i;
550 /* Copy the ad-hoc creating rates into Current BSS state structure */
551 memcpy(&adapter->curbssparams.datarates,
552 &adhs->datarate, adapter->curbssparams.numofrates);
554 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
555 adhs->datarate[0], adhs->datarate[1],
556 adhs->datarate[2], adhs->datarate[3]);
558 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
560 if (libertas_create_dnld_countryinfo_11d(priv)) {
561 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
566 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
567 S_DS_GEN + cmdappendsize);
571 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
575 int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
576 struct cmd_ds_command *cmd)
578 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_stop);
579 cmd->size = cpu_to_le16(S_DS_GEN);
584 int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
585 struct cmd_ds_command *cmd, void *pdata_buf)
587 wlan_adapter *adapter = priv->adapter;
588 struct cmd_ds_802_11_ad_hoc_join *padhocjoin = &cmd->params.adj;
589 struct assoc_request * assoc_req = pdata_buf;
590 struct bss_descriptor *bss = &assoc_req->bss;
591 int cmdappendsize = 0;
598 lbs_deb_enter(LBS_DEB_JOIN);
600 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
602 padhocjoin->bssdescriptor.bsstype = cmd_bss_type_ibss;
604 padhocjoin->bssdescriptor.beaconperiod = cpu_to_le16(bss->beaconperiod);
606 memcpy(&padhocjoin->bssdescriptor.BSSID, &bss->bssid, ETH_ALEN);
607 memcpy(&padhocjoin->bssdescriptor.SSID, &bss->ssid, bss->ssid_len);
609 memcpy(&padhocjoin->bssdescriptor.phyparamset,
610 &bss->phyparamset, sizeof(union ieeetypes_phyparamset));
612 memcpy(&padhocjoin->bssdescriptor.ssparamset,
613 &bss->ssparamset, sizeof(union IEEEtypes_ssparamset));
615 memcpy(&tmpcap, &bss->cap, sizeof(struct ieeetypes_capinfo));
616 tmpcap &= CAPINFO_MASK;
618 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
619 tmpcap, CAPINFO_MASK);
620 memcpy(&padhocjoin->bssdescriptor.cap, &tmpcap,
621 sizeof(struct ieeetypes_capinfo));
623 /* information on BSSID descriptor passed to FW */
625 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
626 MAC_ARG(padhocjoin->bssdescriptor.BSSID),
627 padhocjoin->bssdescriptor.SSID);
630 padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
633 padhocjoin->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
635 /* Copy Data rates from the rates recorded in scan response */
636 memset(padhocjoin->bssdescriptor.datarates, 0,
637 sizeof(padhocjoin->bssdescriptor.datarates));
638 memcpy(padhocjoin->bssdescriptor.datarates, bss->datarates,
639 min(sizeof(padhocjoin->bssdescriptor.datarates),
640 sizeof(bss->datarates)));
642 card_rates = libertas_supported_rates;
643 card_rates_size = sizeof(libertas_supported_rates);
645 adapter->curbssparams.channel = bss->channel;
647 if (get_common_rates(adapter, padhocjoin->bssdescriptor.datarates,
648 sizeof(padhocjoin->bssdescriptor.datarates),
649 card_rates, card_rates_size)) {
650 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
655 /* Find the last non zero */
656 for (i = 0; i < sizeof(padhocjoin->bssdescriptor.datarates)
657 && padhocjoin->bssdescriptor.datarates[i]; i++) ;
659 adapter->curbssparams.numofrates = i;
662 * Copy the adhoc joining rates to Current BSS State structure
664 memcpy(adapter->curbssparams.datarates,
665 padhocjoin->bssdescriptor.datarates,
666 adapter->curbssparams.numofrates);
668 padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
669 cpu_to_le16(bss->atimwindow);
671 if (assoc_req->secinfo.wep_enabled) {
672 padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
675 if (adapter->psmode == wlan802_11powermodemax_psp) {
679 Localpsmode = cpu_to_le32(wlan802_11powermodecam);
680 ret = libertas_prepare_and_send_command(priv,
691 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
696 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
697 S_DS_GEN + cmdappendsize);
700 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
704 int libertas_ret_80211_associate(wlan_private * priv,
705 struct cmd_ds_command *resp)
707 wlan_adapter *adapter = priv->adapter;
709 union iwreq_data wrqu;
710 struct ieeetypes_assocrsp *passocrsp;
711 struct bss_descriptor * bss;
713 lbs_deb_enter(LBS_DEB_JOIN);
715 if (!adapter->in_progress_assoc_req) {
716 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
720 bss = &adapter->in_progress_assoc_req->bss;
722 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
724 if (le16_to_cpu(passocrsp->statuscode)) {
725 libertas_mac_event_disconnected(priv);
727 lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
728 le16_to_cpu(passocrsp->statuscode));
734 lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
735 le16_to_cpu(resp->size) - S_DS_GEN);
737 /* Send a Media Connected event, according to the Spec */
738 adapter->connect_status = libertas_connected;
740 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
741 escape_essid(bss->ssid, bss->ssid_len));
743 /* Update current SSID and BSSID */
744 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
745 adapter->curbssparams.ssid_len = bss->ssid_len;
746 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
748 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
749 adapter->currentpacketfilter);
751 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
752 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
754 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
755 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
756 adapter->nextSNRNF = 0;
757 adapter->numSNRNF = 0;
759 netif_carrier_on(priv->dev);
760 netif_wake_queue(priv->dev);
762 netif_carrier_on(priv->mesh_dev);
763 netif_wake_queue(priv->mesh_dev);
765 lbs_deb_join("ASSOC_RESP: Associated \n");
767 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
768 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
769 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
772 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
776 int libertas_ret_80211_disassociate(wlan_private * priv,
777 struct cmd_ds_command *resp)
779 lbs_deb_enter(LBS_DEB_JOIN);
781 libertas_mac_event_disconnected(priv);
783 lbs_deb_leave(LBS_DEB_JOIN);
787 int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
788 struct cmd_ds_command *resp)
790 wlan_adapter *adapter = priv->adapter;
792 u16 command = le16_to_cpu(resp->command);
793 u16 result = le16_to_cpu(resp->result);
794 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
795 union iwreq_data wrqu;
796 struct bss_descriptor *bss;
798 lbs_deb_enter(LBS_DEB_JOIN);
800 padhocresult = &resp->params.result;
802 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
803 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
804 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
806 if (!adapter->in_progress_assoc_req) {
807 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
811 bss = &adapter->in_progress_assoc_req->bss;
814 * Join result code 0 --> SUCCESS
817 lbs_deb_join("ADHOC_RESP: failed\n");
818 if (adapter->connect_status == libertas_connected) {
819 libertas_mac_event_disconnected(priv);
826 * Now the join cmd should be successful
827 * If BSSID has changed use SSID to compare instead of BSSID
829 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
830 escape_essid(bss->ssid, bss->ssid_len));
832 /* Send a Media Connected event, according to the Spec */
833 adapter->connect_status = libertas_connected;
835 if (command == cmd_ret_802_11_ad_hoc_start) {
836 /* Update the created network descriptor with the new BSSID */
837 memcpy(bss->bssid, padhocresult->BSSID, ETH_ALEN);
840 /* Set the BSSID from the joined/started descriptor */
841 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
843 /* Set the new SSID to current SSID */
844 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
845 adapter->curbssparams.ssid_len = bss->ssid_len;
847 netif_carrier_on(priv->dev);
848 netif_wake_queue(priv->dev);
850 netif_carrier_on(priv->mesh_dev);
851 netif_wake_queue(priv->mesh_dev);
853 memset(&wrqu, 0, sizeof(wrqu));
854 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
855 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
856 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
858 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
859 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
860 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
861 MAC_ARG(padhocresult->BSSID));
864 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
868 int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
869 struct cmd_ds_command *resp)
871 lbs_deb_enter(LBS_DEB_JOIN);
873 libertas_mac_event_disconnected(priv);
875 lbs_deb_leave(LBS_DEB_JOIN);