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 /* The firmware needs certain bits masked out of the beacon-derviced capability
21 * field when associating/joining to BSSs.
23 #define CAPINFO_MASK (~(0xda00))
26 * @brief This function finds common rates between rate1 and card rates.
28 * It will fill common rates in rate1 as output if found.
30 * NOTE: Setting the MSB of the basic rates need to be taken
31 * care, either before or after calling this function
33 * @param adapter A pointer to lbs_adapter structure
34 * @param rate1 the buffer which keeps input and output
35 * @param rate1_size the size of rate1 buffer; new size of buffer on return
39 static int get_common_rates(lbs_adapter *adapter, u8 *rates, u16 *rates_size)
41 u8 *card_rates = lbs_bg_rates;
42 size_t num_card_rates = sizeof(lbs_bg_rates);
47 /* For each rate in card_rates that exists in rate1, copy to tmp */
48 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
49 for (j = 0; rates[j] && (j < *rates_size); j++) {
50 if (rates[j] == card_rates[i])
51 tmp[tmp_size++] = card_rates[i];
55 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
56 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates);
57 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size);
58 lbs_deb_join("Tx datarate is currently 0x%X\n", adapter->cur_rate);
60 if (!adapter->auto_rate) {
61 for (i = 0; i < tmp_size; i++) {
62 if (tmp[i] == adapter->cur_rate)
65 lbs_pr_alert("Previously set fixed data rate %#x isn't "
66 "compatible with the network.\n", adapter->cur_rate);
73 memset(rates, 0, *rates_size);
74 *rates_size = min_t(int, tmp_size, *rates_size);
75 memcpy(rates, tmp, *rates_size);
81 * @brief Sets the MSB on basic rates as the firmware requires
83 * Scan through an array and set the MSB for basic data rates.
85 * @param rates buffer of data rates
86 * @param len size of buffer
88 static void lbs_set_basic_rate_flags(u8 *rates, size_t len)
92 for (i = 0; i < len; i++) {
93 if (rates[i] == 0x02 || rates[i] == 0x04 ||
94 rates[i] == 0x0b || rates[i] == 0x16)
100 * @brief Unsets the MSB on basic rates
102 * Scan through an array and unset the MSB for basic data rates.
104 * @param rates buffer of data rates
105 * @param len size of buffer
107 void lbs_unset_basic_rate_flags(u8 *rates, size_t len)
111 for (i = 0; i < len; i++)
117 * @brief Associate to a specific BSS discovered in a scan
119 * @param priv A pointer to lbs_private structure
120 * @param pbssdesc Pointer to the BSS descriptor to associate with.
122 * @return 0-success, otherwise fail
124 int lbs_associate(lbs_private *priv, struct assoc_request *assoc_req)
126 lbs_adapter *adapter = priv->adapter;
129 lbs_deb_enter(LBS_DEB_JOIN);
131 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
132 0, CMD_OPTION_WAITFORRSP,
133 0, assoc_req->bss.bssid);
138 /* set preamble to firmware */
139 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
140 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
141 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
143 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
145 lbs_set_radio_control(priv);
147 ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
148 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
151 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
156 * @brief Start an Adhoc Network
158 * @param priv A pointer to lbs_private structure
159 * @param adhocssid The ssid of the Adhoc Network
160 * @return 0--success, -1--fail
162 int lbs_start_adhoc_network(lbs_private *priv, struct assoc_request *assoc_req)
164 lbs_adapter *adapter = priv->adapter;
167 adapter->adhoccreate = 1;
169 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
170 lbs_deb_join("AdhocStart: Short preamble\n");
171 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
173 lbs_deb_join("AdhocStart: Long preamble\n");
174 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
177 lbs_set_radio_control(priv);
179 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
180 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
182 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
183 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
189 * @brief Join an adhoc network found in a previous scan
191 * @param priv A pointer to lbs_private structure
192 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
195 * @return 0--success, -1--fail
197 int lbs_join_adhoc_network(lbs_private *priv, struct assoc_request *assoc_req)
199 lbs_adapter *adapter = priv->adapter;
200 struct bss_descriptor * bss = &assoc_req->bss;
203 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
205 escape_essid(adapter->curbssparams.ssid,
206 adapter->curbssparams.ssid_len),
207 adapter->curbssparams.ssid_len);
208 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
209 __func__, escape_essid(bss->ssid, bss->ssid_len),
212 /* check if the requested SSID is already joined */
213 if ( adapter->curbssparams.ssid_len
214 && !lbs_ssid_cmp(adapter->curbssparams.ssid,
215 adapter->curbssparams.ssid_len,
216 bss->ssid, bss->ssid_len)
217 && (adapter->mode == IW_MODE_ADHOC)
218 && (adapter->connect_status == LBS_CONNECTED)) {
219 union iwreq_data wrqu;
221 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
222 "current, not attempting to re-join");
224 /* Send the re-association event though, because the association
225 * request really was successful, even if just a null-op.
227 memset(&wrqu, 0, sizeof(wrqu));
228 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid,
230 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
231 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
235 /* Use shortpreamble only when both creator and card supports
237 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
238 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
239 lbs_deb_join("AdhocJoin: Long preamble\n");
240 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
242 lbs_deb_join("AdhocJoin: Short preamble\n");
243 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
246 lbs_set_radio_control(priv);
248 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
249 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
251 adapter->adhoccreate = 0;
253 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
254 0, CMD_OPTION_WAITFORRSP,
255 OID_802_11_SSID, assoc_req);
261 int lbs_stop_adhoc_network(lbs_private * priv)
263 return lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
264 0, CMD_OPTION_WAITFORRSP, 0, NULL);
268 * @brief Send Deauthentication Request
270 * @param priv A pointer to lbs_private structure
271 * @return 0--success, -1--fail
273 int lbs_send_deauthentication(lbs_private *priv)
275 return lbs_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
276 0, CMD_OPTION_WAITFORRSP, 0, NULL);
280 * @brief This function prepares command of authenticate.
282 * @param priv A pointer to lbs_private structure
283 * @param cmd A pointer to cmd_ds_command structure
284 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
288 int lbs_cmd_80211_authenticate(lbs_private *priv,
289 struct cmd_ds_command *cmd,
292 lbs_adapter *adapter = priv->adapter;
293 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
295 u8 *bssid = pdata_buf;
296 DECLARE_MAC_BUF(mac);
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 : %s auth=0x%X\n",
324 print_mac(mac, bssid), pauthenticate->authtype);
328 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
332 int lbs_cmd_80211_deauthenticate(lbs_private *priv,
333 struct cmd_ds_command *cmd)
335 lbs_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 lbs_cmd_80211_associate(lbs_private *priv,
356 struct cmd_ds_command *cmd, void *pdata_buf)
358 lbs_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(MRVDRV_DEFAULT_LISTEN_INTERVAL);
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 lbs_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_deb_hex(LBS_DEB_JOIN, "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 (lbs_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 lbs_cmd_80211_ad_hoc_start(lbs_private *priv,
472 struct cmd_ds_command *cmd, void *pdata_buf)
474 lbs_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 if (adapter->beacon_period == 0)
514 adapter->beacon_period = MRVDRV_BEACON_INTERVAL;
515 adhs->beaconperiod = cpu_to_le16(adapter->beacon_period);
517 /* set Physical param set */
518 #define DS_PARA_IE_ID 3
519 #define DS_PARA_IE_LEN 1
521 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
522 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
524 WARN_ON(!assoc_req->channel);
526 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
529 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
531 /* set IBSS param set */
532 #define IBSS_PARA_IE_ID 6
533 #define IBSS_PARA_IE_LEN 2
535 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
536 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
537 adhs->ssparamset.ibssparamset.atimwindow = 0;
539 /* set capability info */
540 tmpcap = WLAN_CAPABILITY_IBSS;
541 if (assoc_req->secinfo.wep_enabled) {
542 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
543 tmpcap |= WLAN_CAPABILITY_PRIVACY;
545 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
547 adhs->capability = cpu_to_le16(tmpcap);
550 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
552 memset(adhs->rates, 0, sizeof(adhs->rates));
553 ratesize = min(sizeof(adhs->rates), sizeof(lbs_bg_rates));
554 memcpy(adhs->rates, lbs_bg_rates, ratesize);
556 /* Copy the ad-hoc creating rates into Current BSS state structure */
557 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
558 memcpy(&adapter->curbssparams.rates, &adhs->rates, ratesize);
560 /* Set MSB on basic rates as the firmware requires, but _after_
561 * copying to current bss rates.
563 lbs_set_basic_rate_flags(adhs->rates, ratesize);
565 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
566 adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]);
568 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
570 if (lbs_create_dnld_countryinfo_11d(priv)) {
571 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
576 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
577 S_DS_GEN + cmdappendsize);
581 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
585 int lbs_cmd_80211_ad_hoc_stop(lbs_private *priv,
586 struct cmd_ds_command *cmd)
588 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP);
589 cmd->size = cpu_to_le16(S_DS_GEN);
594 int lbs_cmd_80211_ad_hoc_join(lbs_private *priv,
595 struct cmd_ds_command *cmd, void *pdata_buf)
597 lbs_adapter *adapter = priv->adapter;
598 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
599 struct assoc_request * assoc_req = pdata_buf;
600 struct bss_descriptor *bss = &assoc_req->bss;
601 int cmdappendsize = 0;
604 DECLARE_MAC_BUF(mac);
606 lbs_deb_enter(LBS_DEB_JOIN);
608 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
610 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
611 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
613 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
614 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
616 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
617 sizeof(union ieeetypes_phyparamset));
619 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
620 sizeof(union IEEEtypes_ssparamset));
622 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
623 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
624 bss->capability, CAPINFO_MASK);
626 /* information on BSSID descriptor passed to FW */
628 "ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n",
629 print_mac(mac, join_cmd->bss.bssid),
633 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
636 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
638 adapter->curbssparams.channel = bss->channel;
640 /* Copy Data rates from the rates recorded in scan response */
641 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
642 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
643 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
644 if (get_common_rates(adapter, join_cmd->bss.rates, &ratesize)) {
645 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
650 /* Copy the ad-hoc creating rates into Current BSS state structure */
651 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
652 memcpy(&adapter->curbssparams.rates, join_cmd->bss.rates, ratesize);
654 /* Set MSB on basic rates as the firmware requires, but _after_
655 * copying to current bss rates.
657 lbs_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
659 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
660 cpu_to_le16(bss->atimwindow);
662 if (assoc_req->secinfo.wep_enabled) {
663 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
664 tmp |= WLAN_CAPABILITY_PRIVACY;
665 join_cmd->bss.capability = cpu_to_le16(tmp);
668 if (adapter->psmode == LBS802_11POWERMODEMAX_PSP) {
672 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
673 ret = lbs_prepare_and_send_command(priv,
684 if (lbs_parse_dnld_countryinfo_11d(priv, bss)) {
689 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
690 S_DS_GEN + cmdappendsize);
693 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
697 int lbs_ret_80211_associate(lbs_private *priv,
698 struct cmd_ds_command *resp)
700 lbs_adapter *adapter = priv->adapter;
702 union iwreq_data wrqu;
703 struct ieeetypes_assocrsp *passocrsp;
704 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;
719 * Older FW versions map the IEEE 802.11 Status Code in the association
720 * response to the following values returned in passocrsp->statuscode:
722 * IEEE Status Code Marvell Status Code
723 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
724 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
725 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
726 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
727 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
728 * others -> 0x0003 ASSOC_RESULT_REFUSED
730 * Other response codes:
731 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
732 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
733 * association response from the AP)
736 status_code = le16_to_cpu(passocrsp->statuscode);
737 switch (status_code) {
739 lbs_deb_join("ASSOC_RESP: Association succeeded\n");
742 lbs_deb_join("ASSOC_RESP: Association failed; invalid "
743 "parameters (status code %d)\n", status_code);
746 lbs_deb_join("ASSOC_RESP: Association failed; internal timer "
747 "expired while waiting for the AP (status code %d)"
751 lbs_deb_join("ASSOC_RESP: Association failed; association "
752 "was refused by the AP (status code %d)\n",
756 lbs_deb_join("ASSOC_RESP: Association failed; authentication "
757 "was refused by the AP (status code %d)\n",
761 lbs_deb_join("ASSOC_RESP: Association failed; reason unknown "
762 "(status code %d)\n", status_code);
767 lbs_mac_event_disconnected(priv);
772 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_RESP", (void *)&resp->params,
773 le16_to_cpu(resp->size) - S_DS_GEN);
775 /* Send a Media Connected event, according to the Spec */
776 adapter->connect_status = LBS_CONNECTED;
778 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
779 escape_essid(bss->ssid, bss->ssid_len));
781 /* Update current SSID and BSSID */
782 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
783 adapter->curbssparams.ssid_len = bss->ssid_len;
784 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
786 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
787 adapter->currentpacketfilter);
789 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
790 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
792 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
793 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
794 adapter->nextSNRNF = 0;
795 adapter->numSNRNF = 0;
797 netif_carrier_on(priv->dev);
798 netif_wake_queue(priv->dev);
801 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
802 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
803 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
806 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
810 int lbs_ret_80211_disassociate(lbs_private *priv,
811 struct cmd_ds_command *resp)
813 lbs_deb_enter(LBS_DEB_JOIN);
815 lbs_mac_event_disconnected(priv);
817 lbs_deb_leave(LBS_DEB_JOIN);
821 int lbs_ret_80211_ad_hoc_start(lbs_private *priv,
822 struct cmd_ds_command *resp)
824 lbs_adapter *adapter = priv->adapter;
826 u16 command = le16_to_cpu(resp->command);
827 u16 result = le16_to_cpu(resp->result);
828 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
829 union iwreq_data wrqu;
830 struct bss_descriptor *bss;
831 DECLARE_MAC_BUF(mac);
833 lbs_deb_enter(LBS_DEB_JOIN);
835 padhocresult = &resp->params.result;
837 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
838 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
839 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
841 if (!adapter->in_progress_assoc_req) {
842 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
846 bss = &adapter->in_progress_assoc_req->bss;
849 * Join result code 0 --> SUCCESS
852 lbs_deb_join("ADHOC_RESP: failed\n");
853 if (adapter->connect_status == LBS_CONNECTED) {
854 lbs_mac_event_disconnected(priv);
861 * Now the join cmd should be successful
862 * If BSSID has changed use SSID to compare instead of BSSID
864 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
865 escape_essid(bss->ssid, bss->ssid_len));
867 /* Send a Media Connected event, according to the Spec */
868 adapter->connect_status = LBS_CONNECTED;
870 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
871 /* Update the created network descriptor with the new BSSID */
872 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
875 /* Set the BSSID from the joined/started descriptor */
876 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
878 /* Set the new SSID to current SSID */
879 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
880 adapter->curbssparams.ssid_len = bss->ssid_len;
882 netif_carrier_on(priv->dev);
883 netif_wake_queue(priv->dev);
885 memset(&wrqu, 0, sizeof(wrqu));
886 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
887 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
888 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
890 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
891 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
892 lbs_deb_join("ADHOC_RESP: BSSID = %s\n",
893 print_mac(mac, padhocresult->bssid));
896 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
900 int lbs_ret_80211_ad_hoc_stop(lbs_private *priv,
901 struct cmd_ds_command *resp)
903 lbs_deb_enter(LBS_DEB_JOIN);
905 lbs_mac_event_disconnected(priv);
907 lbs_deb_leave(LBS_DEB_JOIN);