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 /* Supported rates for ad-hoc B mode */
21 static u8 adhoc_rates_b[5] = { 0x02, 0x04, 0x0b, 0x16, 0x00 };
25 * @brief This function finds common rates between rate1 and card rates.
27 * It will fill common rates in rate1 as output if found.
29 * NOTE: Setting the MSB of the basic rates need to be taken
30 * care, either before or after calling this function
32 * @param adapter A pointer to wlan_adapter structure
33 * @param rate1 the buffer which keeps input and output
34 * @param rate1_size the size of rate1 buffer; new size of buffer on return
38 static int get_common_rates(wlan_adapter * adapter, u8 * rates, u16 *rates_size)
40 u8 *card_rates = libertas_bg_rates;
41 size_t num_card_rates = sizeof(libertas_bg_rates);
46 /* For each rate in card_rates that exists in rate1, copy to tmp */
47 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
48 for (j = 0; rates[j] && (j < *rates_size); j++) {
49 if (rates[j] == card_rates[i])
50 tmp[tmp_size++] = card_rates[i];
54 lbs_dbg_hex("rate1 (AP) rates:", rates, *rates_size);
55 lbs_dbg_hex("rate2 (Card) rates:", card_rates, num_card_rates);
56 lbs_dbg_hex("Common rates:", tmp, tmp_size);
57 lbs_deb_join("Tx datarate is currently 0x%X\n", adapter->cur_rate);
59 if (!adapter->auto_rate) {
60 for (i = 0; i < tmp_size; i++) {
61 if (tmp[i] == adapter->cur_rate)
64 lbs_pr_alert("Previously set fixed data rate %#x isn't "
65 "compatible with the network.\n", adapter->cur_rate);
72 memset(rates, 0, *rates_size);
73 *rates_size = min_t(int, tmp_size, *rates_size);
74 memcpy(rates, tmp, *rates_size);
80 * @brief Sets the MSB on basic rates as the firmware requires
82 * Scan through an array and set the MSB for basic data rates.
84 * @param rates buffer of data rates
85 * @param len size of buffer
87 static void libertas_set_basic_rate_flags(u8 * rates, size_t len)
91 for (i = 0; i < len; i++) {
92 if (rates[i] == 0x02 || rates[i] == 0x04 ||
93 rates[i] == 0x0b || rates[i] == 0x16)
99 * @brief Unsets the MSB on basic rates
101 * Scan through an array and unset the MSB for basic data rates.
103 * @param rates buffer of data rates
104 * @param len size of buffer
106 void libertas_unset_basic_rate_flags(u8 * rates, size_t len)
110 for (i = 0; i < len; i++)
115 int libertas_send_deauth(wlan_private * priv)
117 wlan_adapter *adapter = priv->adapter;
120 if (adapter->mode == IW_MODE_INFRA &&
121 adapter->connect_status == LIBERTAS_CONNECTED)
122 ret = libertas_send_deauthentication(priv);
130 * @brief Associate to a specific BSS discovered in a scan
132 * @param priv A pointer to wlan_private structure
133 * @param pbssdesc Pointer to the BSS descriptor to associate with.
135 * @return 0-success, otherwise fail
137 int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
139 wlan_adapter *adapter = priv->adapter;
142 lbs_deb_enter(LBS_DEB_JOIN);
144 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
145 0, CMD_OPTION_WAITFORRSP,
146 0, assoc_req->bss.bssid);
151 /* set preamble to firmware */
152 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
153 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
154 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
156 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
158 libertas_set_radio_control(priv);
160 ret = libertas_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
161 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
164 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
169 * @brief Start an Adhoc Network
171 * @param priv A pointer to wlan_private structure
172 * @param adhocssid The ssid of the Adhoc Network
173 * @return 0--success, -1--fail
175 int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
177 wlan_adapter *adapter = priv->adapter;
180 adapter->adhoccreate = 1;
182 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
183 lbs_deb_join("AdhocStart: Short preamble\n");
184 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
186 lbs_deb_join("AdhocStart: Long preamble\n");
187 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
190 libertas_set_radio_control(priv);
192 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
193 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
195 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
196 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
202 * @brief Join an adhoc network found in a previous scan
204 * @param priv A pointer to wlan_private structure
205 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
208 * @return 0--success, -1--fail
210 int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
212 wlan_adapter *adapter = priv->adapter;
213 struct bss_descriptor * bss = &assoc_req->bss;
216 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
218 escape_essid(adapter->curbssparams.ssid,
219 adapter->curbssparams.ssid_len),
220 adapter->curbssparams.ssid_len);
221 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
222 __func__, escape_essid(bss->ssid, bss->ssid_len),
225 /* check if the requested SSID is already joined */
226 if (adapter->curbssparams.ssid_len
227 && !libertas_ssid_cmp(adapter->curbssparams.ssid,
228 adapter->curbssparams.ssid_len,
229 bss->ssid, bss->ssid_len)
230 && (adapter->mode == IW_MODE_ADHOC)) {
232 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
233 "not attempting to re-join");
237 /* Use shortpreamble only when both creator and card supports
239 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
240 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
241 lbs_deb_join("AdhocJoin: Long preamble\n");
242 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
244 lbs_deb_join("AdhocJoin: Short preamble\n");
245 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
248 libertas_set_radio_control(priv);
250 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
251 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
253 adapter->adhoccreate = 0;
255 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
256 0, CMD_OPTION_WAITFORRSP,
257 OID_802_11_SSID, assoc_req);
262 int libertas_stop_adhoc_network(wlan_private * priv)
264 return libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
265 0, CMD_OPTION_WAITFORRSP, 0, NULL);
269 * @brief Send Deauthentication Request
271 * @param priv A pointer to wlan_private structure
272 * @return 0--success, -1--fail
274 int libertas_send_deauthentication(wlan_private * priv)
276 return libertas_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
277 0, CMD_OPTION_WAITFORRSP, 0, NULL);
281 * @brief This function prepares command of authenticate.
283 * @param priv A pointer to wlan_private structure
284 * @param cmd A pointer to cmd_ds_command structure
285 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
289 int libertas_cmd_80211_authenticate(wlan_private * priv,
290 struct cmd_ds_command *cmd,
293 wlan_adapter *adapter = priv->adapter;
294 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
296 u8 *bssid = pdata_buf;
298 lbs_deb_enter(LBS_DEB_JOIN);
300 cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE);
301 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
304 /* translate auth mode to 802.11 defined wire value */
305 switch (adapter->secinfo.auth_mode) {
306 case IW_AUTH_ALG_OPEN_SYSTEM:
307 pauthenticate->authtype = 0x00;
309 case IW_AUTH_ALG_SHARED_KEY:
310 pauthenticate->authtype = 0x01;
312 case IW_AUTH_ALG_LEAP:
313 pauthenticate->authtype = 0x80;
316 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
317 adapter->secinfo.auth_mode);
321 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
323 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
324 MAC_ARG(bssid), pauthenticate->authtype);
328 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
332 int libertas_cmd_80211_deauthenticate(wlan_private * priv,
333 struct cmd_ds_command *cmd)
335 wlan_adapter *adapter = priv->adapter;
336 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
338 lbs_deb_enter(LBS_DEB_JOIN);
340 cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE);
341 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
344 /* set AP MAC address */
345 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
347 /* Reason code 3 = Station is leaving */
348 #define REASON_CODE_STA_LEAVING 3
349 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
351 lbs_deb_leave(LBS_DEB_JOIN);
355 int libertas_cmd_80211_associate(wlan_private * priv,
356 struct cmd_ds_command *cmd, void *pdata_buf)
358 wlan_adapter *adapter = priv->adapter;
359 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
361 struct assoc_request * assoc_req = pdata_buf;
362 struct bss_descriptor * bss = &assoc_req->bss;
365 struct mrvlietypes_ssidparamset *ssid;
366 struct mrvlietypes_phyparamset *phy;
367 struct mrvlietypes_ssparamset *ss;
368 struct mrvlietypes_ratesparamset *rates;
369 struct mrvlietypes_rsnparamset *rsn;
371 lbs_deb_enter(LBS_DEB_JOIN);
380 cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE);
382 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
383 pos += sizeof(passo->peerstaaddr);
385 /* set the listen interval */
386 passo->listeninterval = cpu_to_le16(adapter->listeninterval);
388 pos += sizeof(passo->capability);
389 pos += sizeof(passo->listeninterval);
390 pos += sizeof(passo->bcnperiod);
391 pos += sizeof(passo->dtimperiod);
393 ssid = (struct mrvlietypes_ssidparamset *) pos;
394 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
395 tmplen = bss->ssid_len;
396 ssid->header.len = cpu_to_le16(tmplen);
397 memcpy(ssid->ssid, bss->ssid, tmplen);
398 pos += sizeof(ssid->header) + tmplen;
400 phy = (struct mrvlietypes_phyparamset *) pos;
401 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
402 tmplen = sizeof(phy->fh_ds.dsparamset);
403 phy->header.len = cpu_to_le16(tmplen);
404 memcpy(&phy->fh_ds.dsparamset,
405 &bss->phyparamset.dsparamset.currentchan,
407 pos += sizeof(phy->header) + tmplen;
409 ss = (struct mrvlietypes_ssparamset *) pos;
410 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
411 tmplen = sizeof(ss->cf_ibss.cfparamset);
412 ss->header.len = cpu_to_le16(tmplen);
413 pos += sizeof(ss->header) + tmplen;
415 rates = (struct mrvlietypes_ratesparamset *) pos;
416 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
417 memcpy(&rates->rates, &bss->rates, MAX_RATES);
419 if (get_common_rates(adapter, rates->rates, &tmplen)) {
423 pos += sizeof(rates->header) + tmplen;
424 rates->header.len = cpu_to_le16(tmplen);
425 lbs_deb_join("ASSOC_CMD: num rates = %u\n", tmplen);
427 /* Copy the infra. association rates into Current BSS state structure */
428 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
429 memcpy(&adapter->curbssparams.rates, &rates->rates, tmplen);
431 /* Set MSB on basic rates as the firmware requires, but _after_
432 * copying to current bss rates.
434 libertas_set_basic_rate_flags(rates->rates, tmplen);
436 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
437 rsn = (struct mrvlietypes_rsnparamset *) pos;
438 /* WPA_IE or WPA2_IE */
439 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
440 tmplen = (u16) assoc_req->wpa_ie[1];
441 rsn->header.len = cpu_to_le16(tmplen);
442 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
443 lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
444 sizeof(rsn->header) + tmplen);
445 pos += sizeof(rsn->header) + tmplen;
448 /* update curbssparams */
449 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
451 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
456 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
458 /* set the capability info */
459 tmpcap = (bss->capability & CAPINFO_MASK);
460 if (bss->mode == IW_MODE_INFRA)
461 tmpcap |= WLAN_CAPABILITY_ESS;
462 passo->capability = cpu_to_le16(tmpcap);
463 lbs_deb_join("ASSOC_CMD: capability=%4X CAPINFO_MASK=%4X\n",
464 tmpcap, CAPINFO_MASK);
467 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
471 int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
472 struct cmd_ds_command *cmd, void *pdata_buf)
474 wlan_adapter *adapter = priv->adapter;
475 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
477 int cmdappendsize = 0;
478 struct assoc_request * assoc_req = pdata_buf;
482 lbs_deb_enter(LBS_DEB_JOIN);
489 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START);
492 * Fill in the parameters for 2 data structures:
493 * 1. cmd_ds_802_11_ad_hoc_start command
494 * 2. adapter->scantable[i]
496 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
497 * probe delay, and cap info.
499 * Firmware will fill up beacon period, DTIM, Basic rates
500 * and operational rates.
503 memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE);
504 memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len);
506 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
507 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
508 assoc_req->ssid_len);
510 /* set the BSS type */
511 adhs->bsstype = CMD_BSS_TYPE_IBSS;
512 adapter->mode = IW_MODE_ADHOC;
513 adhs->beaconperiod = cpu_to_le16(adapter->beaconperiod);
515 /* set Physical param set */
516 #define DS_PARA_IE_ID 3
517 #define DS_PARA_IE_LEN 1
519 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
520 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
522 WARN_ON(!assoc_req->channel);
524 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
527 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
529 /* set IBSS param set */
530 #define IBSS_PARA_IE_ID 6
531 #define IBSS_PARA_IE_LEN 2
533 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
534 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
535 adhs->ssparamset.ibssparamset.atimwindow = cpu_to_le16(adapter->atimwindow);
537 /* set capability info */
538 tmpcap = WLAN_CAPABILITY_IBSS;
539 if (assoc_req->secinfo.wep_enabled) {
540 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
541 tmpcap |= WLAN_CAPABILITY_PRIVACY;
543 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
545 adhs->capability = cpu_to_le16(tmpcap);
548 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
550 memset(adhs->rates, 0, sizeof(adhs->rates));
551 if (adapter->adhoc_grate_enabled) {
552 ratesize = min(sizeof(adhs->rates), sizeof(libertas_bg_rates));
553 memcpy(adhs->rates, libertas_bg_rates, ratesize);
555 ratesize = min(sizeof(adhs->rates), sizeof(adhoc_rates_b));
556 memcpy(adhs->rates, adhoc_rates_b, ratesize);
559 /* Copy the ad-hoc creating rates into Current BSS state structure */
560 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
561 memcpy(&adapter->curbssparams.rates, &adhs->rates, ratesize);
563 /* Set MSB on basic rates as the firmware requires, but _after_
564 * copying to current bss rates.
566 libertas_set_basic_rate_flags(adhs->rates, ratesize);
568 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
569 adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]);
571 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
573 if (libertas_create_dnld_countryinfo_11d(priv)) {
574 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
579 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
580 S_DS_GEN + cmdappendsize);
584 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
588 int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
589 struct cmd_ds_command *cmd)
591 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP);
592 cmd->size = cpu_to_le16(S_DS_GEN);
597 int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
598 struct cmd_ds_command *cmd, void *pdata_buf)
600 wlan_adapter *adapter = priv->adapter;
601 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
602 struct assoc_request * assoc_req = pdata_buf;
603 struct bss_descriptor *bss = &assoc_req->bss;
604 int cmdappendsize = 0;
608 lbs_deb_enter(LBS_DEB_JOIN);
610 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
612 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
613 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
615 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
616 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
618 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
619 sizeof(union ieeetypes_phyparamset));
621 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
622 sizeof(union IEEEtypes_ssparamset));
624 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
625 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
626 bss->capability, CAPINFO_MASK);
628 /* information on BSSID descriptor passed to FW */
630 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
631 MAC_ARG(join_cmd->bss.bssid), join_cmd->bss.ssid);
634 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
637 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
639 adapter->curbssparams.channel = bss->channel;
641 /* Copy Data rates from the rates recorded in scan response */
642 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
643 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
644 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
645 if (get_common_rates(adapter, join_cmd->bss.rates, &ratesize)) {
646 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
651 /* Copy the ad-hoc creating rates into Current BSS state structure */
652 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
653 memcpy(&adapter->curbssparams.rates, join_cmd->bss.rates, ratesize);
655 /* Set MSB on basic rates as the firmware requires, but _after_
656 * copying to current bss rates.
658 libertas_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
660 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
661 cpu_to_le16(bss->atimwindow);
663 if (assoc_req->secinfo.wep_enabled) {
664 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
665 tmp |= WLAN_CAPABILITY_PRIVACY;
666 join_cmd->bss.capability = cpu_to_le16(tmp);
669 if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) {
673 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
674 ret = libertas_prepare_and_send_command(priv,
685 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
690 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
691 S_DS_GEN + cmdappendsize);
694 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
698 int libertas_ret_80211_associate(wlan_private * priv,
699 struct cmd_ds_command *resp)
701 wlan_adapter *adapter = priv->adapter;
703 union iwreq_data wrqu;
704 struct ieeetypes_assocrsp *passocrsp;
705 struct bss_descriptor * bss;
707 lbs_deb_enter(LBS_DEB_JOIN);
709 if (!adapter->in_progress_assoc_req) {
710 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
714 bss = &adapter->in_progress_assoc_req->bss;
716 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
718 if (le16_to_cpu(passocrsp->statuscode)) {
719 libertas_mac_event_disconnected(priv);
721 lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
722 le16_to_cpu(passocrsp->statuscode));
728 lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
729 le16_to_cpu(resp->size) - S_DS_GEN);
731 /* Send a Media Connected event, according to the Spec */
732 adapter->connect_status = LIBERTAS_CONNECTED;
734 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
735 escape_essid(bss->ssid, bss->ssid_len));
737 /* Update current SSID and BSSID */
738 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
739 adapter->curbssparams.ssid_len = bss->ssid_len;
740 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
742 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
743 adapter->currentpacketfilter);
745 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
746 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
748 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
749 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
750 adapter->nextSNRNF = 0;
751 adapter->numSNRNF = 0;
753 netif_carrier_on(priv->dev);
754 netif_wake_queue(priv->dev);
756 netif_carrier_on(priv->mesh_dev);
757 netif_wake_queue(priv->mesh_dev);
759 lbs_deb_join("ASSOC_RESP: Associated \n");
761 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
762 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
763 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
766 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
770 int libertas_ret_80211_disassociate(wlan_private * priv,
771 struct cmd_ds_command *resp)
773 lbs_deb_enter(LBS_DEB_JOIN);
775 libertas_mac_event_disconnected(priv);
777 lbs_deb_leave(LBS_DEB_JOIN);
781 int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
782 struct cmd_ds_command *resp)
784 wlan_adapter *adapter = priv->adapter;
786 u16 command = le16_to_cpu(resp->command);
787 u16 result = le16_to_cpu(resp->result);
788 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
789 union iwreq_data wrqu;
790 struct bss_descriptor *bss;
792 lbs_deb_enter(LBS_DEB_JOIN);
794 padhocresult = &resp->params.result;
796 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
797 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
798 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
800 if (!adapter->in_progress_assoc_req) {
801 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
805 bss = &adapter->in_progress_assoc_req->bss;
808 * Join result code 0 --> SUCCESS
811 lbs_deb_join("ADHOC_RESP: failed\n");
812 if (adapter->connect_status == LIBERTAS_CONNECTED) {
813 libertas_mac_event_disconnected(priv);
820 * Now the join cmd should be successful
821 * If BSSID has changed use SSID to compare instead of BSSID
823 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
824 escape_essid(bss->ssid, bss->ssid_len));
826 /* Send a Media Connected event, according to the Spec */
827 adapter->connect_status = LIBERTAS_CONNECTED;
829 if (command == CMD_RET_802_11_AD_HOC_START) {
830 /* Update the created network descriptor with the new BSSID */
831 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
834 /* Set the BSSID from the joined/started descriptor */
835 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
837 /* Set the new SSID to current SSID */
838 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
839 adapter->curbssparams.ssid_len = bss->ssid_len;
841 netif_carrier_on(priv->dev);
842 netif_wake_queue(priv->dev);
844 netif_carrier_on(priv->mesh_dev);
845 netif_wake_queue(priv->mesh_dev);
847 memset(&wrqu, 0, sizeof(wrqu));
848 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
849 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
850 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
852 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
853 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
854 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
855 MAC_ARG(padhocresult->bssid));
858 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
862 int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
863 struct cmd_ds_command *resp)
865 lbs_deb_enter(LBS_DEB_JOIN);
867 libertas_mac_event_disconnected(priv);
869 lbs_deb_leave(LBS_DEB_JOIN);