libertas: tweak association debug output
[linux-2.6/openmoko-kernel/knife-kernel.git] / drivers / net / wireless / libertas / join.c
blob1550e6afb0537bfa4ef53d7e4041a9288be47e4e
1 /**
2 * Functions implementing wlan infrastructure and adhoc join routines,
3 * IOCTL handlers as well as command preperation and response routines
4 * for sending adhoc start, adhoc join, and association commands
5 * to the firmware.
6 */
7 #include <linux/netdevice.h>
8 #include <linux/if_arp.h>
9 #include <linux/wireless.h>
10 #include <linux/etherdevice.h>
12 #include <net/iw_handler.h>
14 #include "host.h"
15 #include "decl.h"
16 #include "join.h"
17 #include "dev.h"
18 #include "assoc.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))
25 /**
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 struct 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
37 * @return 0 or -1
39 static int get_common_rates(struct lbs_adapter *adapter,
40 u8 *rates,
41 u16 *rates_size)
43 u8 *card_rates = lbs_bg_rates;
44 size_t num_card_rates = sizeof(lbs_bg_rates);
45 int ret = 0, i, j;
46 u8 tmp[30];
47 size_t tmp_size = 0;
49 /* For each rate in card_rates that exists in rate1, copy to tmp */
50 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
51 for (j = 0; rates[j] && (j < *rates_size); j++) {
52 if (rates[j] == card_rates[i])
53 tmp[tmp_size++] = card_rates[i];
57 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
58 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates);
59 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size);
60 lbs_deb_join("TX data rate 0x%02x\n", adapter->cur_rate);
62 if (!adapter->auto_rate) {
63 for (i = 0; i < tmp_size; i++) {
64 if (tmp[i] == adapter->cur_rate)
65 goto done;
67 lbs_pr_alert("Previously set fixed data rate %#x isn't "
68 "compatible with the network.\n", adapter->cur_rate);
69 ret = -1;
70 goto done;
72 ret = 0;
74 done:
75 memset(rates, 0, *rates_size);
76 *rates_size = min_t(int, tmp_size, *rates_size);
77 memcpy(rates, tmp, *rates_size);
78 return ret;
82 /**
83 * @brief Sets the MSB on basic rates as the firmware requires
85 * Scan through an array and set the MSB for basic data rates.
87 * @param rates buffer of data rates
88 * @param len size of buffer
90 static void lbs_set_basic_rate_flags(u8 *rates, size_t len)
92 int i;
94 for (i = 0; i < len; i++) {
95 if (rates[i] == 0x02 || rates[i] == 0x04 ||
96 rates[i] == 0x0b || rates[i] == 0x16)
97 rates[i] |= 0x80;
102 * @brief Unsets the MSB on basic rates
104 * Scan through an array and unset the MSB for basic data rates.
106 * @param rates buffer of data rates
107 * @param len size of buffer
109 void lbs_unset_basic_rate_flags(u8 *rates, size_t len)
111 int i;
113 for (i = 0; i < len; i++)
114 rates[i] &= 0x7f;
119 * @brief Associate to a specific BSS discovered in a scan
121 * @param priv A pointer to struct lbs_private structure
122 * @param pbssdesc Pointer to the BSS descriptor to associate with.
124 * @return 0-success, otherwise fail
126 int lbs_associate(struct lbs_private *priv, struct assoc_request *assoc_req)
128 struct lbs_adapter *adapter = priv->adapter;
129 int ret;
131 lbs_deb_enter(LBS_DEB_ASSOC);
133 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
134 0, CMD_OPTION_WAITFORRSP,
135 0, assoc_req->bss.bssid);
137 if (ret)
138 goto done;
140 /* set preamble to firmware */
141 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
142 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
143 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
144 else
145 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
147 lbs_set_radio_control(priv);
149 ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
150 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
152 done:
153 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
154 return ret;
158 * @brief Start an Adhoc Network
160 * @param priv A pointer to struct lbs_private structure
161 * @param adhocssid The ssid of the Adhoc Network
162 * @return 0--success, -1--fail
164 int lbs_start_adhoc_network(struct lbs_private *priv,
165 struct assoc_request *assoc_req)
167 struct lbs_adapter *adapter = priv->adapter;
168 int ret = 0;
170 adapter->adhoccreate = 1;
172 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
173 lbs_deb_join("AdhocStart: Short preamble\n");
174 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
175 } else {
176 lbs_deb_join("AdhocStart: Long preamble\n");
177 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
180 lbs_set_radio_control(priv);
182 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
183 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
185 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
186 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
188 return ret;
192 * @brief Join an adhoc network found in a previous scan
194 * @param priv A pointer to struct lbs_private structure
195 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
196 * to attempt to join
198 * @return 0--success, -1--fail
200 int lbs_join_adhoc_network(struct lbs_private *priv,
201 struct assoc_request *assoc_req)
203 struct lbs_adapter *adapter = priv->adapter;
204 struct bss_descriptor * bss = &assoc_req->bss;
205 int ret = 0;
207 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
208 __func__,
209 escape_essid(adapter->curbssparams.ssid,
210 adapter->curbssparams.ssid_len),
211 adapter->curbssparams.ssid_len);
212 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
213 __func__, escape_essid(bss->ssid, bss->ssid_len),
214 bss->ssid_len);
216 /* check if the requested SSID is already joined */
217 if ( adapter->curbssparams.ssid_len
218 && !lbs_ssid_cmp(adapter->curbssparams.ssid,
219 adapter->curbssparams.ssid_len,
220 bss->ssid, bss->ssid_len)
221 && (adapter->mode == IW_MODE_ADHOC)
222 && (adapter->connect_status == LBS_CONNECTED)) {
223 union iwreq_data wrqu;
225 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
226 "current, not attempting to re-join");
228 /* Send the re-association event though, because the association
229 * request really was successful, even if just a null-op.
231 memset(&wrqu, 0, sizeof(wrqu));
232 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid,
233 ETH_ALEN);
234 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
235 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
236 goto out;
239 /* Use shortpreamble only when both creator and card supports
240 short preamble */
241 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
242 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
243 lbs_deb_join("AdhocJoin: Long preamble\n");
244 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
245 } else {
246 lbs_deb_join("AdhocJoin: Short preamble\n");
247 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
250 lbs_set_radio_control(priv);
252 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
253 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
255 adapter->adhoccreate = 0;
257 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
258 0, CMD_OPTION_WAITFORRSP,
259 OID_802_11_SSID, assoc_req);
261 out:
262 return ret;
265 int lbs_stop_adhoc_network(struct lbs_private *priv)
267 return lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
268 0, CMD_OPTION_WAITFORRSP, 0, NULL);
272 * @brief Send Deauthentication Request
274 * @param priv A pointer to struct lbs_private structure
275 * @return 0--success, -1--fail
277 int lbs_send_deauthentication(struct lbs_private *priv)
279 return lbs_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
280 0, CMD_OPTION_WAITFORRSP, 0, NULL);
284 * @brief This function prepares command of authenticate.
286 * @param priv A pointer to struct lbs_private structure
287 * @param cmd A pointer to cmd_ds_command structure
288 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
290 * @return 0 or -1
292 int lbs_cmd_80211_authenticate(struct lbs_private *priv,
293 struct cmd_ds_command *cmd,
294 void *pdata_buf)
296 struct lbs_adapter *adapter = priv->adapter;
297 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
298 int ret = -1;
299 u8 *bssid = pdata_buf;
300 DECLARE_MAC_BUF(mac);
302 lbs_deb_enter(LBS_DEB_JOIN);
304 cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE);
305 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
306 + S_DS_GEN);
308 /* translate auth mode to 802.11 defined wire value */
309 switch (adapter->secinfo.auth_mode) {
310 case IW_AUTH_ALG_OPEN_SYSTEM:
311 pauthenticate->authtype = 0x00;
312 break;
313 case IW_AUTH_ALG_SHARED_KEY:
314 pauthenticate->authtype = 0x01;
315 break;
316 case IW_AUTH_ALG_LEAP:
317 pauthenticate->authtype = 0x80;
318 break;
319 default:
320 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
321 adapter->secinfo.auth_mode);
322 goto out;
325 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
327 lbs_deb_join("AUTH_CMD: BSSID %s, auth 0x%x\n",
328 print_mac(mac, bssid), pauthenticate->authtype);
329 ret = 0;
331 out:
332 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
333 return ret;
336 int lbs_cmd_80211_deauthenticate(struct lbs_private *priv,
337 struct cmd_ds_command *cmd)
339 struct lbs_adapter *adapter = priv->adapter;
340 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
342 lbs_deb_enter(LBS_DEB_JOIN);
344 cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE);
345 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
346 S_DS_GEN);
348 /* set AP MAC address */
349 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
351 /* Reason code 3 = Station is leaving */
352 #define REASON_CODE_STA_LEAVING 3
353 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
355 lbs_deb_leave(LBS_DEB_JOIN);
356 return 0;
359 int lbs_cmd_80211_associate(struct lbs_private *priv,
360 struct cmd_ds_command *cmd, void *pdata_buf)
362 struct lbs_adapter *adapter = priv->adapter;
363 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
364 int ret = 0;
365 struct assoc_request * assoc_req = pdata_buf;
366 struct bss_descriptor * bss = &assoc_req->bss;
367 u8 *pos;
368 u16 tmpcap, tmplen;
369 struct mrvlietypes_ssidparamset *ssid;
370 struct mrvlietypes_phyparamset *phy;
371 struct mrvlietypes_ssparamset *ss;
372 struct mrvlietypes_ratesparamset *rates;
373 struct mrvlietypes_rsnparamset *rsn;
375 lbs_deb_enter(LBS_DEB_ASSOC);
377 pos = (u8 *) passo;
379 if (!adapter) {
380 ret = -1;
381 goto done;
384 cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE);
386 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
387 pos += sizeof(passo->peerstaaddr);
389 /* set the listen interval */
390 passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
392 pos += sizeof(passo->capability);
393 pos += sizeof(passo->listeninterval);
394 pos += sizeof(passo->bcnperiod);
395 pos += sizeof(passo->dtimperiod);
397 ssid = (struct mrvlietypes_ssidparamset *) pos;
398 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
399 tmplen = bss->ssid_len;
400 ssid->header.len = cpu_to_le16(tmplen);
401 memcpy(ssid->ssid, bss->ssid, tmplen);
402 pos += sizeof(ssid->header) + tmplen;
404 phy = (struct mrvlietypes_phyparamset *) pos;
405 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
406 tmplen = sizeof(phy->fh_ds.dsparamset);
407 phy->header.len = cpu_to_le16(tmplen);
408 memcpy(&phy->fh_ds.dsparamset,
409 &bss->phyparamset.dsparamset.currentchan,
410 tmplen);
411 pos += sizeof(phy->header) + tmplen;
413 ss = (struct mrvlietypes_ssparamset *) pos;
414 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
415 tmplen = sizeof(ss->cf_ibss.cfparamset);
416 ss->header.len = cpu_to_le16(tmplen);
417 pos += sizeof(ss->header) + tmplen;
419 rates = (struct mrvlietypes_ratesparamset *) pos;
420 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
421 memcpy(&rates->rates, &bss->rates, MAX_RATES);
422 tmplen = MAX_RATES;
423 if (get_common_rates(adapter, rates->rates, &tmplen)) {
424 ret = -1;
425 goto done;
427 pos += sizeof(rates->header) + tmplen;
428 rates->header.len = cpu_to_le16(tmplen);
429 lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen);
431 /* Copy the infra. association rates into Current BSS state structure */
432 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
433 memcpy(&adapter->curbssparams.rates, &rates->rates, tmplen);
435 /* Set MSB on basic rates as the firmware requires, but _after_
436 * copying to current bss rates.
438 lbs_set_basic_rate_flags(rates->rates, tmplen);
440 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
441 rsn = (struct mrvlietypes_rsnparamset *) pos;
442 /* WPA_IE or WPA2_IE */
443 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
444 tmplen = (u16) assoc_req->wpa_ie[1];
445 rsn->header.len = cpu_to_le16(tmplen);
446 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
447 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn,
448 sizeof(rsn->header) + tmplen);
449 pos += sizeof(rsn->header) + tmplen;
452 /* update curbssparams */
453 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
455 if (lbs_parse_dnld_countryinfo_11d(priv, bss)) {
456 ret = -1;
457 goto done;
460 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
462 /* set the capability info */
463 tmpcap = (bss->capability & CAPINFO_MASK);
464 if (bss->mode == IW_MODE_INFRA)
465 tmpcap |= WLAN_CAPABILITY_ESS;
466 passo->capability = cpu_to_le16(tmpcap);
467 lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap);
469 done:
470 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
471 return ret;
474 int lbs_cmd_80211_ad_hoc_start(struct lbs_private *priv,
475 struct cmd_ds_command *cmd, void *pdata_buf)
477 struct lbs_adapter *adapter = priv->adapter;
478 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
479 int ret = 0;
480 int cmdappendsize = 0;
481 struct assoc_request * assoc_req = pdata_buf;
482 u16 tmpcap = 0;
483 size_t ratesize = 0;
485 lbs_deb_enter(LBS_DEB_JOIN);
487 if (!adapter) {
488 ret = -1;
489 goto done;
492 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START);
495 * Fill in the parameters for 2 data structures:
496 * 1. cmd_ds_802_11_ad_hoc_start command
497 * 2. adapter->scantable[i]
499 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
500 * probe delay, and cap info.
502 * Firmware will fill up beacon period, DTIM, Basic rates
503 * and operational rates.
506 memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE);
507 memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len);
509 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
510 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
511 assoc_req->ssid_len);
513 /* set the BSS type */
514 adhs->bsstype = CMD_BSS_TYPE_IBSS;
515 adapter->mode = IW_MODE_ADHOC;
516 if (adapter->beacon_period == 0)
517 adapter->beacon_period = MRVDRV_BEACON_INTERVAL;
518 adhs->beaconperiod = cpu_to_le16(adapter->beacon_period);
520 /* set Physical param set */
521 #define DS_PARA_IE_ID 3
522 #define DS_PARA_IE_LEN 1
524 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
525 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
527 WARN_ON(!assoc_req->channel);
529 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
530 assoc_req->channel);
532 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
534 /* set IBSS param set */
535 #define IBSS_PARA_IE_ID 6
536 #define IBSS_PARA_IE_LEN 2
538 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
539 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
540 adhs->ssparamset.ibssparamset.atimwindow = 0;
542 /* set capability info */
543 tmpcap = WLAN_CAPABILITY_IBSS;
544 if (assoc_req->secinfo.wep_enabled) {
545 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
546 tmpcap |= WLAN_CAPABILITY_PRIVACY;
547 } else {
548 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
550 adhs->capability = cpu_to_le16(tmpcap);
552 /* probedelay */
553 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
555 memset(adhs->rates, 0, sizeof(adhs->rates));
556 ratesize = min(sizeof(adhs->rates), sizeof(lbs_bg_rates));
557 memcpy(adhs->rates, lbs_bg_rates, 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 lbs_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 (lbs_create_dnld_countryinfo_11d(priv)) {
574 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
575 ret = -1;
576 goto done;
579 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
580 S_DS_GEN + cmdappendsize);
582 ret = 0;
583 done:
584 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
585 return ret;
588 int lbs_cmd_80211_ad_hoc_stop(struct lbs_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);
594 return 0;
597 int lbs_cmd_80211_ad_hoc_join(struct lbs_private *priv,
598 struct cmd_ds_command *cmd, void *pdata_buf)
600 struct lbs_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;
605 int ret = 0;
606 u16 ratesize = 0;
607 DECLARE_MAC_BUF(mac);
609 lbs_deb_enter(LBS_DEB_JOIN);
611 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
613 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
614 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
616 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
617 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
619 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
620 sizeof(union ieeetypes_phyparamset));
622 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
623 sizeof(union IEEEtypes_ssparamset));
625 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
626 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
627 bss->capability, CAPINFO_MASK);
629 /* information on BSSID descriptor passed to FW */
630 lbs_deb_join(
631 "ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n",
632 print_mac(mac, join_cmd->bss.bssid),
633 join_cmd->bss.ssid);
635 /* failtimeout */
636 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
638 /* probedelay */
639 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
641 adapter->curbssparams.channel = bss->channel;
643 /* Copy Data rates from the rates recorded in scan response */
644 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
645 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
646 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
647 if (get_common_rates(adapter, join_cmd->bss.rates, &ratesize)) {
648 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
649 ret = -1;
650 goto done;
653 /* Copy the ad-hoc creating rates into Current BSS state structure */
654 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
655 memcpy(&adapter->curbssparams.rates, join_cmd->bss.rates, ratesize);
657 /* Set MSB on basic rates as the firmware requires, but _after_
658 * copying to current bss rates.
660 lbs_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
662 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
663 cpu_to_le16(bss->atimwindow);
665 if (assoc_req->secinfo.wep_enabled) {
666 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
667 tmp |= WLAN_CAPABILITY_PRIVACY;
668 join_cmd->bss.capability = cpu_to_le16(tmp);
671 if (adapter->psmode == LBS802_11POWERMODEMAX_PSP) {
672 /* wake up first */
673 __le32 Localpsmode;
675 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
676 ret = lbs_prepare_and_send_command(priv,
677 CMD_802_11_PS_MODE,
678 CMD_ACT_SET,
679 0, 0, &Localpsmode);
681 if (ret) {
682 ret = -1;
683 goto done;
687 if (lbs_parse_dnld_countryinfo_11d(priv, bss)) {
688 ret = -1;
689 goto done;
692 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
693 S_DS_GEN + cmdappendsize);
695 done:
696 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
697 return ret;
700 int lbs_ret_80211_associate(struct lbs_private *priv,
701 struct cmd_ds_command *resp)
703 struct lbs_adapter *adapter = priv->adapter;
704 int ret = 0;
705 union iwreq_data wrqu;
706 struct ieeetypes_assocrsp *passocrsp;
707 struct bss_descriptor * bss;
708 u16 status_code;
710 lbs_deb_enter(LBS_DEB_ASSOC);
712 if (!adapter->in_progress_assoc_req) {
713 lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n");
714 ret = -1;
715 goto done;
717 bss = &adapter->in_progress_assoc_req->bss;
719 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
722 * Older FW versions map the IEEE 802.11 Status Code in the association
723 * response to the following values returned in passocrsp->statuscode:
725 * IEEE Status Code Marvell Status Code
726 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
727 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
728 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
729 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
730 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
731 * others -> 0x0003 ASSOC_RESULT_REFUSED
733 * Other response codes:
734 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
735 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
736 * association response from the AP)
739 status_code = le16_to_cpu(passocrsp->statuscode);
740 switch (status_code) {
741 case 0x00:
742 break;
743 case 0x01:
744 lbs_deb_assoc("ASSOC_RESP: invalid parameters\n");
745 break;
746 case 0x02:
747 lbs_deb_assoc("ASSOC_RESP: internal timer "
748 "expired while waiting for the AP\n");
749 break;
750 case 0x03:
751 lbs_deb_assoc("ASSOC_RESP: association "
752 "refused by AP\n");
753 break;
754 case 0x04:
755 lbs_deb_assoc("ASSOC_RESP: authentication "
756 "refused by AP\n");
757 break;
758 default:
759 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x "
760 " unknown\n", status_code);
761 break;
764 if (status_code) {
765 lbs_mac_event_disconnected(priv);
766 ret = -1;
767 goto done;
770 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", (void *)&resp->params,
771 le16_to_cpu(resp->size) - S_DS_GEN);
773 /* Send a Media Connected event, according to the Spec */
774 adapter->connect_status = LBS_CONNECTED;
776 /* Update current SSID and BSSID */
777 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
778 adapter->curbssparams.ssid_len = bss->ssid_len;
779 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
781 lbs_deb_assoc("ASSOC_RESP: currentpacketfilter is 0x%x\n",
782 adapter->currentpacketfilter);
784 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
785 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
787 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
788 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
789 adapter->nextSNRNF = 0;
790 adapter->numSNRNF = 0;
792 netif_carrier_on(priv->dev);
793 netif_wake_queue(priv->dev);
796 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
797 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
798 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
800 done:
801 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
802 return ret;
805 int lbs_ret_80211_disassociate(struct lbs_private *priv,
806 struct cmd_ds_command *resp)
808 lbs_deb_enter(LBS_DEB_JOIN);
810 lbs_mac_event_disconnected(priv);
812 lbs_deb_leave(LBS_DEB_JOIN);
813 return 0;
816 int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv,
817 struct cmd_ds_command *resp)
819 struct lbs_adapter *adapter = priv->adapter;
820 int ret = 0;
821 u16 command = le16_to_cpu(resp->command);
822 u16 result = le16_to_cpu(resp->result);
823 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
824 union iwreq_data wrqu;
825 struct bss_descriptor *bss;
826 DECLARE_MAC_BUF(mac);
828 lbs_deb_enter(LBS_DEB_JOIN);
830 padhocresult = &resp->params.result;
832 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
833 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
834 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
836 if (!adapter->in_progress_assoc_req) {
837 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
838 ret = -1;
839 goto done;
841 bss = &adapter->in_progress_assoc_req->bss;
844 * Join result code 0 --> SUCCESS
846 if (result) {
847 lbs_deb_join("ADHOC_RESP: failed\n");
848 if (adapter->connect_status == LBS_CONNECTED) {
849 lbs_mac_event_disconnected(priv);
851 ret = -1;
852 goto done;
856 * Now the join cmd should be successful
857 * If BSSID has changed use SSID to compare instead of BSSID
859 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
860 escape_essid(bss->ssid, bss->ssid_len));
862 /* Send a Media Connected event, according to the Spec */
863 adapter->connect_status = LBS_CONNECTED;
865 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
866 /* Update the created network descriptor with the new BSSID */
867 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
870 /* Set the BSSID from the joined/started descriptor */
871 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
873 /* Set the new SSID to current SSID */
874 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
875 adapter->curbssparams.ssid_len = bss->ssid_len;
877 netif_carrier_on(priv->dev);
878 netif_wake_queue(priv->dev);
880 memset(&wrqu, 0, sizeof(wrqu));
881 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
882 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
883 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
885 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
886 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
887 lbs_deb_join("ADHOC_RESP: BSSID = %s\n",
888 print_mac(mac, padhocresult->bssid));
890 done:
891 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
892 return ret;
895 int lbs_ret_80211_ad_hoc_stop(struct lbs_private *priv,
896 struct cmd_ds_command *resp)
898 lbs_deb_enter(LBS_DEB_JOIN);
900 lbs_mac_event_disconnected(priv);
902 lbs_deb_leave(LBS_DEB_JOIN);
903 return 0;