1 /* Copyright (C) 2006, Red Hat, Inc. */
3 #include <linux/types.h>
4 #include <linux/etherdevice.h>
5 #include <linux/ieee80211.h>
6 #include <linux/if_arp.h>
7 #include <linux/slab.h>
8 #include <net/lib80211.h>
16 static const u8 bssid_any
[ETH_ALEN
] __attribute__ ((aligned (2))) =
17 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
18 static const u8 bssid_off
[ETH_ALEN
] __attribute__ ((aligned (2))) =
19 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
21 /* The firmware needs the following bits masked out of the beacon-derived
22 * capability field when associating/joining to a BSS:
23 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
25 #define CAPINFO_MASK (~(0xda00))
28 * 802.11b/g supported bitrates (in 500Kb/s units)
30 u8 lbs_bg_rates
[MAX_RATES
] =
31 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
36 * @brief This function finds common rates between rates and card rates.
38 * It will fill common rates in rates as output if found.
40 * NOTE: Setting the MSB of the basic rates need to be taken
41 * care, either before or after calling this function
43 * @param priv A pointer to struct lbs_private structure
44 * @param rates the buffer which keeps input and output
45 * @param rates_size the size of rates buffer; new size of buffer on return,
46 * which will be less than or equal to original rates_size
48 * @return 0 on success, or -1 on error
50 static int get_common_rates(struct lbs_private
*priv
,
55 u8 intersection
[MAX_RATES
];
56 u16 intersection_size
;
59 intersection_size
= min_t(u16
, *rates_size
, ARRAY_SIZE(intersection
));
61 /* Allow each rate from 'rates' that is supported by the hardware */
62 for (i
= 0; i
< ARRAY_SIZE(lbs_bg_rates
) && lbs_bg_rates
[i
]; i
++) {
63 for (j
= 0; j
< intersection_size
&& rates
[j
]; j
++) {
64 if (rates
[j
] == lbs_bg_rates
[i
])
65 intersection
[num_rates
++] = rates
[j
];
69 lbs_deb_hex(LBS_DEB_JOIN
, "AP rates ", rates
, *rates_size
);
70 lbs_deb_hex(LBS_DEB_JOIN
, "card rates ", lbs_bg_rates
,
71 ARRAY_SIZE(lbs_bg_rates
));
72 lbs_deb_hex(LBS_DEB_JOIN
, "common rates", intersection
, num_rates
);
73 lbs_deb_join("TX data rate 0x%02x\n", priv
->cur_rate
);
75 if (!priv
->enablehwauto
) {
76 for (i
= 0; i
< num_rates
; i
++) {
77 if (intersection
[i
] == priv
->cur_rate
)
80 lbs_pr_alert("Previously set fixed data rate %#x isn't "
81 "compatible with the network.\n", priv
->cur_rate
);
86 memset(rates
, 0, *rates_size
);
87 *rates_size
= num_rates
;
88 memcpy(rates
, intersection
, num_rates
);
94 * @brief Sets the MSB on basic rates as the firmware requires
96 * Scan through an array and set the MSB for basic data rates.
98 * @param rates buffer of data rates
99 * @param len size of buffer
101 static void lbs_set_basic_rate_flags(u8
*rates
, size_t len
)
105 for (i
= 0; i
< len
; i
++) {
106 if (rates
[i
] == 0x02 || rates
[i
] == 0x04 ||
107 rates
[i
] == 0x0b || rates
[i
] == 0x16)
113 static u8
iw_auth_to_ieee_auth(u8 auth
)
115 if (auth
== IW_AUTH_ALG_OPEN_SYSTEM
)
117 else if (auth
== IW_AUTH_ALG_SHARED_KEY
)
119 else if (auth
== IW_AUTH_ALG_LEAP
)
122 lbs_deb_join("%s: invalid auth alg 0x%X\n", __func__
, auth
);
127 * @brief This function prepares the authenticate command. AUTHENTICATE only
128 * sets the authentication suite for future associations, as the firmware
129 * handles authentication internally during the ASSOCIATE command.
131 * @param priv A pointer to struct lbs_private structure
132 * @param bssid The peer BSSID with which to authenticate
133 * @param auth The authentication mode to use (from wireless.h)
137 static int lbs_set_authentication(struct lbs_private
*priv
, u8 bssid
[6], u8 auth
)
139 struct cmd_ds_802_11_authenticate cmd
;
142 lbs_deb_enter(LBS_DEB_JOIN
);
144 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
145 memcpy(cmd
.bssid
, bssid
, ETH_ALEN
);
147 cmd
.authtype
= iw_auth_to_ieee_auth(auth
);
149 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", bssid
, cmd
.authtype
);
151 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AUTHENTICATE
, &cmd
);
153 lbs_deb_leave_args(LBS_DEB_JOIN
, "ret %d", ret
);
158 int lbs_cmd_802_11_set_wep(struct lbs_private
*priv
, uint16_t cmd_action
,
159 struct assoc_request
*assoc
)
161 struct cmd_ds_802_11_set_wep cmd
;
164 lbs_deb_enter(LBS_DEB_CMD
);
166 memset(&cmd
, 0, sizeof(cmd
));
167 cmd
.hdr
.command
= cpu_to_le16(CMD_802_11_SET_WEP
);
168 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
170 cmd
.action
= cpu_to_le16(cmd_action
);
172 if (cmd_action
== CMD_ACT_ADD
) {
175 /* default tx key index */
176 cmd
.keyindex
= cpu_to_le16(assoc
->wep_tx_keyidx
&
177 CMD_WEP_KEY_INDEX_MASK
);
179 /* Copy key types and material to host command structure */
180 for (i
= 0; i
< 4; i
++) {
181 struct enc_key
*pkey
= &assoc
->wep_keys
[i
];
185 cmd
.keytype
[i
] = CMD_TYPE_WEP_40_BIT
;
186 memmove(cmd
.keymaterial
[i
], pkey
->key
, pkey
->len
);
187 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i
);
189 case KEY_LEN_WEP_104
:
190 cmd
.keytype
[i
] = CMD_TYPE_WEP_104_BIT
;
191 memmove(cmd
.keymaterial
[i
], pkey
->key
, pkey
->len
);
192 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i
);
197 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
204 } else if (cmd_action
== CMD_ACT_REMOVE
) {
205 /* ACT_REMOVE clears _all_ WEP keys */
207 /* default tx key index */
208 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_keyidx
&
209 CMD_WEP_KEY_INDEX_MASK
);
210 lbs_deb_cmd("SET_WEP: remove key %d\n", priv
->wep_tx_keyidx
);
213 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
215 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
219 int lbs_cmd_802_11_enable_rsn(struct lbs_private
*priv
, uint16_t cmd_action
,
222 struct cmd_ds_802_11_enable_rsn cmd
;
225 lbs_deb_enter(LBS_DEB_CMD
);
227 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
228 cmd
.action
= cpu_to_le16(cmd_action
);
230 if (cmd_action
== CMD_ACT_GET
)
234 cmd
.enable
= cpu_to_le16(CMD_ENABLE_RSN
);
236 cmd
.enable
= cpu_to_le16(CMD_DISABLE_RSN
);
237 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable
);
240 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ENABLE_RSN
, &cmd
);
241 if (!ret
&& cmd_action
== CMD_ACT_GET
)
242 *enable
= le16_to_cpu(cmd
.enable
);
244 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
248 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet
*keyparam
,
251 lbs_deb_enter(LBS_DEB_CMD
);
253 if (key
->flags
& KEY_INFO_WPA_ENABLED
)
254 keyparam
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_ENABLED
);
255 if (key
->flags
& KEY_INFO_WPA_UNICAST
)
256 keyparam
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_UNICAST
);
257 if (key
->flags
& KEY_INFO_WPA_MCAST
)
258 keyparam
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_MCAST
);
260 keyparam
->type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
261 keyparam
->keytypeid
= cpu_to_le16(key
->type
);
262 keyparam
->keylen
= cpu_to_le16(key
->len
);
263 memcpy(keyparam
->key
, key
->key
, key
->len
);
265 /* Length field doesn't include the {type,length} header */
266 keyparam
->length
= cpu_to_le16(sizeof(*keyparam
) - 4);
267 lbs_deb_leave(LBS_DEB_CMD
);
270 int lbs_cmd_802_11_key_material(struct lbs_private
*priv
, uint16_t cmd_action
,
271 struct assoc_request
*assoc
)
273 struct cmd_ds_802_11_key_material cmd
;
277 lbs_deb_enter(LBS_DEB_CMD
);
279 cmd
.action
= cpu_to_le16(cmd_action
);
280 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
282 if (cmd_action
== CMD_ACT_GET
) {
283 cmd
.hdr
.size
= cpu_to_le16(sizeof(struct cmd_header
) + 2);
285 memset(cmd
.keyParamSet
, 0, sizeof(cmd
.keyParamSet
));
287 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc
->flags
)) {
288 set_one_wpa_key(&cmd
.keyParamSet
[index
],
289 &assoc
->wpa_unicast_key
);
293 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc
->flags
)) {
294 set_one_wpa_key(&cmd
.keyParamSet
[index
],
295 &assoc
->wpa_mcast_key
);
299 /* The common header and as many keys as we included */
300 cmd
.hdr
.size
= cpu_to_le16(offsetof(typeof(cmd
),
301 keyParamSet
[index
]));
303 ret
= lbs_cmd_with_response(priv
, CMD_802_11_KEY_MATERIAL
, &cmd
);
304 /* Copy the returned key to driver private data */
305 if (!ret
&& cmd_action
== CMD_ACT_GET
) {
306 void *buf_ptr
= cmd
.keyParamSet
;
307 void *resp_end
= &(&cmd
)[1];
309 while (buf_ptr
< resp_end
) {
310 struct MrvlIEtype_keyParamSet
*keyparam
= buf_ptr
;
312 uint16_t param_set_len
= le16_to_cpu(keyparam
->length
);
313 uint16_t key_len
= le16_to_cpu(keyparam
->keylen
);
314 uint16_t key_flags
= le16_to_cpu(keyparam
->keyinfo
);
315 uint16_t key_type
= le16_to_cpu(keyparam
->keytypeid
);
318 end
= (void *)keyparam
+ sizeof(keyparam
->type
)
319 + sizeof(keyparam
->length
) + param_set_len
;
321 /* Make sure we don't access past the end of the IEs */
325 if (key_flags
& KEY_INFO_WPA_UNICAST
)
326 key
= &priv
->wpa_unicast_key
;
327 else if (key_flags
& KEY_INFO_WPA_MCAST
)
328 key
= &priv
->wpa_mcast_key
;
332 /* Copy returned key into driver */
333 memset(key
, 0, sizeof(struct enc_key
));
334 if (key_len
> sizeof(key
->key
))
336 key
->type
= key_type
;
337 key
->flags
= key_flags
;
339 memcpy(key
->key
, keyparam
->key
, key
->len
);
345 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
349 static __le16
lbs_rate_to_fw_bitmap(int rate
, int lower_rates_ok
)
369 int i
= lbs_data_rate_to_fw_index(rate
);
371 ratemask
= (0x1fef >> (12 - i
));
374 return cpu_to_le16(ratemask
);
377 int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private
*priv
,
380 struct cmd_ds_802_11_rate_adapt_rateset cmd
;
383 lbs_deb_enter(LBS_DEB_CMD
);
385 if (!priv
->cur_rate
&& !priv
->enablehwauto
)
388 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
390 cmd
.action
= cpu_to_le16(cmd_action
);
391 cmd
.enablehwauto
= cpu_to_le16(priv
->enablehwauto
);
392 cmd
.bitmap
= lbs_rate_to_fw_bitmap(priv
->cur_rate
, priv
->enablehwauto
);
393 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RATE_ADAPT_RATESET
, &cmd
);
394 if (!ret
&& cmd_action
== CMD_ACT_GET
)
395 priv
->enablehwauto
= le16_to_cpu(cmd
.enablehwauto
);
397 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
402 * @brief Set the data rate
404 * @param priv A pointer to struct lbs_private structure
405 * @param rate The desired data rate, or 0 to clear a locked rate
407 * @return 0 on success, error on failure
409 int lbs_set_data_rate(struct lbs_private
*priv
, u8 rate
)
411 struct cmd_ds_802_11_data_rate cmd
;
414 lbs_deb_enter(LBS_DEB_CMD
);
416 memset(&cmd
, 0, sizeof(cmd
));
417 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
420 cmd
.action
= cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE
);
421 cmd
.rates
[0] = lbs_data_rate_to_fw_index(rate
);
422 if (cmd
.rates
[0] == 0) {
423 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
428 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd
.rates
[0]);
430 cmd
.action
= cpu_to_le16(CMD_ACT_SET_TX_AUTO
);
431 lbs_deb_cmd("DATA_RATE: setting auto\n");
434 ret
= lbs_cmd_with_response(priv
, CMD_802_11_DATA_RATE
, &cmd
);
438 lbs_deb_hex(LBS_DEB_CMD
, "DATA_RATE_RESP", (u8
*) &cmd
, sizeof(cmd
));
440 /* FIXME: get actual rates FW can do if this command actually returns
441 * all data rates supported.
443 priv
->cur_rate
= lbs_fw_index_to_data_rate(cmd
.rates
[0]);
444 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv
->cur_rate
);
447 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
452 int lbs_cmd_802_11_rssi(struct lbs_private
*priv
,
453 struct cmd_ds_command
*cmd
)
456 lbs_deb_enter(LBS_DEB_CMD
);
457 cmd
->command
= cpu_to_le16(CMD_802_11_RSSI
);
458 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi
) +
459 sizeof(struct cmd_header
));
460 cmd
->params
.rssi
.N
= cpu_to_le16(DEFAULT_BCN_AVG_FACTOR
);
462 /* reset Beacon SNR/NF/RSSI values */
463 priv
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
464 priv
->SNR
[TYPE_BEACON
][TYPE_AVG
] = 0;
465 priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
466 priv
->NF
[TYPE_BEACON
][TYPE_AVG
] = 0;
467 priv
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
468 priv
->RSSI
[TYPE_BEACON
][TYPE_AVG
] = 0;
470 lbs_deb_leave(LBS_DEB_CMD
);
474 int lbs_ret_802_11_rssi(struct lbs_private
*priv
,
475 struct cmd_ds_command
*resp
)
477 struct cmd_ds_802_11_rssi_rsp
*rssirsp
= &resp
->params
.rssirsp
;
479 lbs_deb_enter(LBS_DEB_CMD
);
481 /* store the non average value */
482 priv
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = get_unaligned_le16(&rssirsp
->SNR
);
483 priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
] =
484 get_unaligned_le16(&rssirsp
->noisefloor
);
486 priv
->SNR
[TYPE_BEACON
][TYPE_AVG
] = get_unaligned_le16(&rssirsp
->avgSNR
);
487 priv
->NF
[TYPE_BEACON
][TYPE_AVG
] =
488 get_unaligned_le16(&rssirsp
->avgnoisefloor
);
490 priv
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] =
491 CAL_RSSI(priv
->SNR
[TYPE_BEACON
][TYPE_NOAVG
],
492 priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
]);
494 priv
->RSSI
[TYPE_BEACON
][TYPE_AVG
] =
495 CAL_RSSI(priv
->SNR
[TYPE_BEACON
][TYPE_AVG
] / AVG_SCALE
,
496 priv
->NF
[TYPE_BEACON
][TYPE_AVG
] / AVG_SCALE
);
498 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
499 priv
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
],
500 priv
->RSSI
[TYPE_BEACON
][TYPE_AVG
]);
502 lbs_deb_leave(LBS_DEB_CMD
);
507 int lbs_cmd_bcn_ctrl(struct lbs_private
*priv
,
508 struct cmd_ds_command
*cmd
,
511 struct cmd_ds_802_11_beacon_control
512 *bcn_ctrl
= &cmd
->params
.bcn_ctrl
;
514 lbs_deb_enter(LBS_DEB_CMD
);
516 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control
)
517 + sizeof(struct cmd_header
));
518 cmd
->command
= cpu_to_le16(CMD_802_11_BEACON_CTRL
);
520 bcn_ctrl
->action
= cpu_to_le16(cmd_action
);
521 bcn_ctrl
->beacon_enable
= cpu_to_le16(priv
->beacon_enable
);
522 bcn_ctrl
->beacon_period
= cpu_to_le16(priv
->beacon_period
);
524 lbs_deb_leave(LBS_DEB_CMD
);
528 int lbs_ret_802_11_bcn_ctrl(struct lbs_private
*priv
,
529 struct cmd_ds_command
*resp
)
531 struct cmd_ds_802_11_beacon_control
*bcn_ctrl
=
532 &resp
->params
.bcn_ctrl
;
534 lbs_deb_enter(LBS_DEB_CMD
);
536 if (bcn_ctrl
->action
== CMD_ACT_GET
) {
537 priv
->beacon_enable
= (u8
) le16_to_cpu(bcn_ctrl
->beacon_enable
);
538 priv
->beacon_period
= le16_to_cpu(bcn_ctrl
->beacon_period
);
541 lbs_deb_enter(LBS_DEB_CMD
);
547 static int lbs_assoc_post(struct lbs_private
*priv
,
548 struct cmd_ds_802_11_associate_response
*resp
)
551 union iwreq_data wrqu
;
552 struct bss_descriptor
*bss
;
555 lbs_deb_enter(LBS_DEB_ASSOC
);
557 if (!priv
->in_progress_assoc_req
) {
558 lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n");
562 bss
= &priv
->in_progress_assoc_req
->bss
;
565 * Older FW versions map the IEEE 802.11 Status Code in the association
566 * response to the following values returned in resp->statuscode:
568 * IEEE Status Code Marvell Status Code
569 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
570 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
571 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
572 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
573 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
574 * others -> 0x0003 ASSOC_RESULT_REFUSED
576 * Other response codes:
577 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
578 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
579 * association response from the AP)
582 status_code
= le16_to_cpu(resp
->statuscode
);
583 if (priv
->fwrelease
< 0x09000000) {
584 switch (status_code
) {
588 lbs_deb_assoc("ASSOC_RESP: invalid parameters\n");
591 lbs_deb_assoc("ASSOC_RESP: internal timer "
592 "expired while waiting for the AP\n");
595 lbs_deb_assoc("ASSOC_RESP: association "
599 lbs_deb_assoc("ASSOC_RESP: authentication "
603 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x "
604 " unknown\n", status_code
);
608 /* v9+ returns the AP's association response */
609 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x\n", status_code
);
613 lbs_mac_event_disconnected(priv
);
618 lbs_deb_hex(LBS_DEB_ASSOC
, "ASSOC_RESP",
619 (void *) (resp
+ sizeof (resp
->hdr
)),
620 le16_to_cpu(resp
->hdr
.size
) - sizeof (resp
->hdr
));
622 /* Send a Media Connected event, according to the Spec */
623 priv
->connect_status
= LBS_CONNECTED
;
625 /* Update current SSID and BSSID */
626 memcpy(&priv
->curbssparams
.ssid
, &bss
->ssid
, IEEE80211_MAX_SSID_LEN
);
627 priv
->curbssparams
.ssid_len
= bss
->ssid_len
;
628 memcpy(priv
->curbssparams
.bssid
, bss
->bssid
, ETH_ALEN
);
630 priv
->SNR
[TYPE_RXPD
][TYPE_AVG
] = 0;
631 priv
->NF
[TYPE_RXPD
][TYPE_AVG
] = 0;
633 memset(priv
->rawSNR
, 0x00, sizeof(priv
->rawSNR
));
634 memset(priv
->rawNF
, 0x00, sizeof(priv
->rawNF
));
638 netif_carrier_on(priv
->dev
);
639 if (!priv
->tx_pending_len
)
640 netif_wake_queue(priv
->dev
);
642 memcpy(wrqu
.ap_addr
.sa_data
, priv
->curbssparams
.bssid
, ETH_ALEN
);
643 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
644 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
647 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
652 * @brief This function prepares an association-class command.
654 * @param priv A pointer to struct lbs_private structure
655 * @param assoc_req The association request describing the BSS to associate
656 * or reassociate with
657 * @param command The actual command, either CMD_802_11_ASSOCIATE or
658 * CMD_802_11_REASSOCIATE
662 static int lbs_associate(struct lbs_private
*priv
,
663 struct assoc_request
*assoc_req
,
666 struct cmd_ds_802_11_associate cmd
;
668 struct bss_descriptor
*bss
= &assoc_req
->bss
;
669 u8
*pos
= &(cmd
.iebuf
[0]);
670 u16 tmpcap
, tmplen
, tmpauth
;
671 struct mrvl_ie_ssid_param_set
*ssid
;
672 struct mrvl_ie_ds_param_set
*ds
;
673 struct mrvl_ie_cf_param_set
*cf
;
674 struct mrvl_ie_rates_param_set
*rates
;
675 struct mrvl_ie_rsn_param_set
*rsn
;
676 struct mrvl_ie_auth_type
*auth
;
678 lbs_deb_enter(LBS_DEB_ASSOC
);
680 BUG_ON((command
!= CMD_802_11_ASSOCIATE
) &&
681 (command
!= CMD_802_11_REASSOCIATE
));
683 memset(&cmd
, 0, sizeof(cmd
));
684 cmd
.hdr
.command
= cpu_to_le16(command
);
686 /* Fill in static fields */
687 memcpy(cmd
.bssid
, bss
->bssid
, ETH_ALEN
);
688 cmd
.listeninterval
= cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL
);
690 /* Capability info */
691 tmpcap
= (bss
->capability
& CAPINFO_MASK
);
692 if (bss
->mode
== IW_MODE_INFRA
)
693 tmpcap
|= WLAN_CAPABILITY_ESS
;
694 cmd
.capability
= cpu_to_le16(tmpcap
);
695 lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap
);
698 ssid
= (struct mrvl_ie_ssid_param_set
*) pos
;
699 ssid
->header
.type
= cpu_to_le16(TLV_TYPE_SSID
);
700 tmplen
= bss
->ssid_len
;
701 ssid
->header
.len
= cpu_to_le16(tmplen
);
702 memcpy(ssid
->ssid
, bss
->ssid
, tmplen
);
703 pos
+= sizeof(ssid
->header
) + tmplen
;
705 ds
= (struct mrvl_ie_ds_param_set
*) pos
;
706 ds
->header
.type
= cpu_to_le16(TLV_TYPE_PHY_DS
);
707 ds
->header
.len
= cpu_to_le16(1);
708 ds
->channel
= bss
->phy
.ds
.channel
;
709 pos
+= sizeof(ds
->header
) + 1;
711 cf
= (struct mrvl_ie_cf_param_set
*) pos
;
712 cf
->header
.type
= cpu_to_le16(TLV_TYPE_CF
);
713 tmplen
= sizeof(*cf
) - sizeof (cf
->header
);
714 cf
->header
.len
= cpu_to_le16(tmplen
);
715 /* IE payload should be zeroed, firmware fills it in for us */
718 rates
= (struct mrvl_ie_rates_param_set
*) pos
;
719 rates
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
720 tmplen
= min_t(u16
, ARRAY_SIZE(bss
->rates
), MAX_RATES
);
721 memcpy(&rates
->rates
, &bss
->rates
, tmplen
);
722 if (get_common_rates(priv
, rates
->rates
, &tmplen
)) {
726 pos
+= sizeof(rates
->header
) + tmplen
;
727 rates
->header
.len
= cpu_to_le16(tmplen
);
728 lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen
);
730 /* Copy the infra. association rates into Current BSS state structure */
731 memset(&priv
->curbssparams
.rates
, 0, sizeof(priv
->curbssparams
.rates
));
732 memcpy(&priv
->curbssparams
.rates
, &rates
->rates
, tmplen
);
734 /* Set MSB on basic rates as the firmware requires, but _after_
735 * copying to current bss rates.
737 lbs_set_basic_rate_flags(rates
->rates
, tmplen
);
739 /* Firmware v9+ indicate authentication suites as a TLV */
740 if (priv
->fwrelease
>= 0x09000000) {
741 auth
= (struct mrvl_ie_auth_type
*) pos
;
742 auth
->header
.type
= cpu_to_le16(TLV_TYPE_AUTH_TYPE
);
743 auth
->header
.len
= cpu_to_le16(2);
744 tmpauth
= iw_auth_to_ieee_auth(priv
->secinfo
.auth_mode
);
745 auth
->auth
= cpu_to_le16(tmpauth
);
746 pos
+= sizeof(auth
->header
) + 2;
748 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n",
749 bss
->bssid
, priv
->secinfo
.auth_mode
);
753 if (assoc_req
->secinfo
.WPAenabled
|| assoc_req
->secinfo
.WPA2enabled
) {
754 rsn
= (struct mrvl_ie_rsn_param_set
*) pos
;
755 /* WPA_IE or WPA2_IE */
756 rsn
->header
.type
= cpu_to_le16((u16
) assoc_req
->wpa_ie
[0]);
757 tmplen
= (u16
) assoc_req
->wpa_ie
[1];
758 rsn
->header
.len
= cpu_to_le16(tmplen
);
759 memcpy(rsn
->rsnie
, &assoc_req
->wpa_ie
[2], tmplen
);
760 lbs_deb_hex(LBS_DEB_JOIN
, "ASSOC_CMD: WPA/RSN IE", (u8
*) rsn
,
761 sizeof(rsn
->header
) + tmplen
);
762 pos
+= sizeof(rsn
->header
) + tmplen
;
765 cmd
.hdr
.size
= cpu_to_le16((sizeof(cmd
) - sizeof(cmd
.iebuf
)) +
766 (u16
)(pos
- (u8
*) &cmd
.iebuf
));
768 /* update curbssparams */
769 priv
->channel
= bss
->phy
.ds
.channel
;
771 ret
= lbs_cmd_with_response(priv
, command
, &cmd
);
773 ret
= lbs_assoc_post(priv
,
774 (struct cmd_ds_802_11_associate_response
*) &cmd
);
778 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
783 * @brief Associate to a specific BSS discovered in a scan
785 * @param priv A pointer to struct lbs_private structure
786 * @param assoc_req The association request describing the BSS to associate with
788 * @return 0-success, otherwise fail
790 static int lbs_try_associate(struct lbs_private
*priv
,
791 struct assoc_request
*assoc_req
)
794 u8 preamble
= RADIO_PREAMBLE_LONG
;
796 lbs_deb_enter(LBS_DEB_ASSOC
);
798 /* FW v9 and higher indicate authentication suites as a TLV in the
799 * association command, not as a separate authentication command.
801 if (priv
->fwrelease
< 0x09000000) {
802 ret
= lbs_set_authentication(priv
, assoc_req
->bss
.bssid
,
803 priv
->secinfo
.auth_mode
);
808 /* Use short preamble only when both the BSS and firmware support it */
809 if (assoc_req
->bss
.capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
810 preamble
= RADIO_PREAMBLE_SHORT
;
812 ret
= lbs_set_radio(priv
, preamble
, 1);
816 ret
= lbs_associate(priv
, assoc_req
, CMD_802_11_ASSOCIATE
);
819 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
823 static int lbs_adhoc_post(struct lbs_private
*priv
,
824 struct cmd_ds_802_11_ad_hoc_result
*resp
)
827 u16 command
= le16_to_cpu(resp
->hdr
.command
);
828 u16 result
= le16_to_cpu(resp
->hdr
.result
);
829 union iwreq_data wrqu
;
830 struct bss_descriptor
*bss
;
831 DECLARE_SSID_BUF(ssid
);
833 lbs_deb_enter(LBS_DEB_JOIN
);
835 if (!priv
->in_progress_assoc_req
) {
836 lbs_deb_join("ADHOC_RESP: no in-progress association "
841 bss
= &priv
->in_progress_assoc_req
->bss
;
844 * Join result code 0 --> SUCCESS
847 lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result
);
848 if (priv
->connect_status
== LBS_CONNECTED
)
849 lbs_mac_event_disconnected(priv
);
854 /* Send a Media Connected event, according to the Spec */
855 priv
->connect_status
= LBS_CONNECTED
;
857 if (command
== CMD_RET(CMD_802_11_AD_HOC_START
)) {
858 /* Update the created network descriptor with the new BSSID */
859 memcpy(bss
->bssid
, resp
->bssid
, ETH_ALEN
);
862 /* Set the BSSID from the joined/started descriptor */
863 memcpy(&priv
->curbssparams
.bssid
, bss
->bssid
, ETH_ALEN
);
865 /* Set the new SSID to current SSID */
866 memcpy(&priv
->curbssparams
.ssid
, &bss
->ssid
, IEEE80211_MAX_SSID_LEN
);
867 priv
->curbssparams
.ssid_len
= bss
->ssid_len
;
869 netif_carrier_on(priv
->dev
);
870 if (!priv
->tx_pending_len
)
871 netif_wake_queue(priv
->dev
);
873 memset(&wrqu
, 0, sizeof(wrqu
));
874 memcpy(wrqu
.ap_addr
.sa_data
, priv
->curbssparams
.bssid
, ETH_ALEN
);
875 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
876 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
878 lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n",
879 print_ssid(ssid
, bss
->ssid
, bss
->ssid_len
),
880 priv
->curbssparams
.bssid
,
884 lbs_deb_leave_args(LBS_DEB_JOIN
, "ret %d", ret
);
889 * @brief Join an adhoc network found in a previous scan
891 * @param priv A pointer to struct lbs_private structure
892 * @param assoc_req The association request describing the BSS to join
894 * @return 0 on success, error on failure
896 static int lbs_adhoc_join(struct lbs_private
*priv
,
897 struct assoc_request
*assoc_req
)
899 struct cmd_ds_802_11_ad_hoc_join cmd
;
900 struct bss_descriptor
*bss
= &assoc_req
->bss
;
901 u8 preamble
= RADIO_PREAMBLE_LONG
;
902 DECLARE_SSID_BUF(ssid
);
906 lbs_deb_enter(LBS_DEB_ASSOC
);
908 lbs_deb_join("current SSID '%s', ssid length %u\n",
909 print_ssid(ssid
, priv
->curbssparams
.ssid
,
910 priv
->curbssparams
.ssid_len
),
911 priv
->curbssparams
.ssid_len
);
912 lbs_deb_join("requested ssid '%s', ssid length %u\n",
913 print_ssid(ssid
, bss
->ssid
, bss
->ssid_len
),
916 /* check if the requested SSID is already joined */
917 if (priv
->curbssparams
.ssid_len
&&
918 !lbs_ssid_cmp(priv
->curbssparams
.ssid
,
919 priv
->curbssparams
.ssid_len
,
920 bss
->ssid
, bss
->ssid_len
) &&
921 (priv
->mode
== IW_MODE_ADHOC
) &&
922 (priv
->connect_status
== LBS_CONNECTED
)) {
923 union iwreq_data wrqu
;
925 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
926 "current, not attempting to re-join");
928 /* Send the re-association event though, because the association
929 * request really was successful, even if just a null-op.
931 memset(&wrqu
, 0, sizeof(wrqu
));
932 memcpy(wrqu
.ap_addr
.sa_data
, priv
->curbssparams
.bssid
,
934 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
935 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
939 /* Use short preamble only when both the BSS and firmware support it */
940 if (bss
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
) {
941 lbs_deb_join("AdhocJoin: Short preamble\n");
942 preamble
= RADIO_PREAMBLE_SHORT
;
945 ret
= lbs_set_radio(priv
, preamble
, 1);
949 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req
->channel
);
950 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req
->band
);
952 priv
->adhoccreate
= 0;
953 priv
->channel
= bss
->channel
;
955 /* Build the join command */
956 memset(&cmd
, 0, sizeof(cmd
));
957 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
959 cmd
.bss
.type
= CMD_BSS_TYPE_IBSS
;
960 cmd
.bss
.beaconperiod
= cpu_to_le16(bss
->beaconperiod
);
962 memcpy(&cmd
.bss
.bssid
, &bss
->bssid
, ETH_ALEN
);
963 memcpy(&cmd
.bss
.ssid
, &bss
->ssid
, bss
->ssid_len
);
965 memcpy(&cmd
.bss
.ds
, &bss
->phy
.ds
, sizeof(struct ieee_ie_ds_param_set
));
967 memcpy(&cmd
.bss
.ibss
, &bss
->ss
.ibss
,
968 sizeof(struct ieee_ie_ibss_param_set
));
970 cmd
.bss
.capability
= cpu_to_le16(bss
->capability
& CAPINFO_MASK
);
971 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
972 bss
->capability
, CAPINFO_MASK
);
974 /* information on BSSID descriptor passed to FW */
975 lbs_deb_join("ADHOC_J_CMD: BSSID = %pM, SSID = '%s'\n",
976 cmd
.bss
.bssid
, cmd
.bss
.ssid
);
978 /* Only v8 and below support setting these */
979 if (priv
->fwrelease
< 0x09000000) {
981 cmd
.failtimeout
= cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT
);
983 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
986 /* Copy Data rates from the rates recorded in scan response */
987 memset(cmd
.bss
.rates
, 0, sizeof(cmd
.bss
.rates
));
988 ratesize
= min_t(u16
, ARRAY_SIZE(cmd
.bss
.rates
), ARRAY_SIZE (bss
->rates
));
989 memcpy(cmd
.bss
.rates
, bss
->rates
, ratesize
);
990 if (get_common_rates(priv
, cmd
.bss
.rates
, &ratesize
)) {
991 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");
996 /* Copy the ad-hoc creation rates into Current BSS state structure */
997 memset(&priv
->curbssparams
.rates
, 0, sizeof(priv
->curbssparams
.rates
));
998 memcpy(&priv
->curbssparams
.rates
, cmd
.bss
.rates
, ratesize
);
1000 /* Set MSB on basic rates as the firmware requires, but _after_
1001 * copying to current bss rates.
1003 lbs_set_basic_rate_flags(cmd
.bss
.rates
, ratesize
);
1005 cmd
.bss
.ibss
.atimwindow
= bss
->atimwindow
;
1007 if (assoc_req
->secinfo
.wep_enabled
) {
1008 u16 tmp
= le16_to_cpu(cmd
.bss
.capability
);
1009 tmp
|= WLAN_CAPABILITY_PRIVACY
;
1010 cmd
.bss
.capability
= cpu_to_le16(tmp
);
1013 if (priv
->psmode
== LBS802_11POWERMODEMAX_PSP
) {
1014 __le32 local_ps_mode
= cpu_to_le32(LBS802_11POWERMODECAM
);
1017 ret
= lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1026 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_JOIN
, &cmd
);
1028 ret
= lbs_adhoc_post(priv
,
1029 (struct cmd_ds_802_11_ad_hoc_result
*)&cmd
);
1033 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1038 * @brief Start an Adhoc Network
1040 * @param priv A pointer to struct lbs_private structure
1041 * @param assoc_req The association request describing the BSS to start
1043 * @return 0 on success, error on failure
1045 static int lbs_adhoc_start(struct lbs_private
*priv
,
1046 struct assoc_request
*assoc_req
)
1048 struct cmd_ds_802_11_ad_hoc_start cmd
;
1049 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1050 size_t ratesize
= 0;
1053 DECLARE_SSID_BUF(ssid
);
1055 lbs_deb_enter(LBS_DEB_ASSOC
);
1057 ret
= lbs_set_radio(priv
, preamble
, 1);
1061 /* Build the start command */
1062 memset(&cmd
, 0, sizeof(cmd
));
1063 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1065 memcpy(cmd
.ssid
, assoc_req
->ssid
, assoc_req
->ssid_len
);
1067 lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n",
1068 print_ssid(ssid
, assoc_req
->ssid
, assoc_req
->ssid_len
),
1069 assoc_req
->ssid_len
);
1071 cmd
.bsstype
= CMD_BSS_TYPE_IBSS
;
1073 if (priv
->beacon_period
== 0)
1074 priv
->beacon_period
= MRVDRV_BEACON_INTERVAL
;
1075 cmd
.beaconperiod
= cpu_to_le16(priv
->beacon_period
);
1077 WARN_ON(!assoc_req
->channel
);
1079 /* set Physical parameter set */
1080 cmd
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1081 cmd
.ds
.header
.len
= 1;
1082 cmd
.ds
.channel
= assoc_req
->channel
;
1084 /* set IBSS parameter set */
1085 cmd
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1086 cmd
.ibss
.header
.len
= 2;
1087 cmd
.ibss
.atimwindow
= cpu_to_le16(0);
1089 /* set capability info */
1090 tmpcap
= WLAN_CAPABILITY_IBSS
;
1091 if (assoc_req
->secinfo
.wep_enabled
||
1092 assoc_req
->secinfo
.WPAenabled
||
1093 assoc_req
->secinfo
.WPA2enabled
) {
1094 lbs_deb_join("ADHOC_START: WEP/WPA enabled, privacy on\n");
1095 tmpcap
|= WLAN_CAPABILITY_PRIVACY
;
1097 lbs_deb_join("ADHOC_START: WEP disabled, privacy off\n");
1099 cmd
.capability
= cpu_to_le16(tmpcap
);
1101 /* Only v8 and below support setting probe delay */
1102 if (priv
->fwrelease
< 0x09000000)
1103 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1105 ratesize
= min(sizeof(cmd
.rates
), sizeof(lbs_bg_rates
));
1106 memcpy(cmd
.rates
, lbs_bg_rates
, ratesize
);
1108 /* Copy the ad-hoc creating rates into Current BSS state structure */
1109 memset(&priv
->curbssparams
.rates
, 0, sizeof(priv
->curbssparams
.rates
));
1110 memcpy(&priv
->curbssparams
.rates
, &cmd
.rates
, ratesize
);
1112 /* Set MSB on basic rates as the firmware requires, but _after_
1113 * copying to current bss rates.
1115 lbs_set_basic_rate_flags(cmd
.rates
, ratesize
);
1117 lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n",
1118 cmd
.rates
[0], cmd
.rates
[1], cmd
.rates
[2], cmd
.rates
[3]);
1120 lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n",
1121 assoc_req
->channel
, assoc_req
->band
);
1123 priv
->adhoccreate
= 1;
1124 priv
->mode
= IW_MODE_ADHOC
;
1126 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_START
, &cmd
);
1128 ret
= lbs_adhoc_post(priv
,
1129 (struct cmd_ds_802_11_ad_hoc_result
*)&cmd
);
1132 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1137 * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode
1139 * @param priv A pointer to struct lbs_private structure
1140 * @return 0 on success, or an error
1142 int lbs_adhoc_stop(struct lbs_private
*priv
)
1144 struct cmd_ds_802_11_ad_hoc_stop cmd
;
1147 lbs_deb_enter(LBS_DEB_JOIN
);
1149 memset(&cmd
, 0, sizeof (cmd
));
1150 cmd
.hdr
.size
= cpu_to_le16 (sizeof (cmd
));
1152 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_STOP
, &cmd
);
1154 /* Clean up everything even if there was an error */
1155 lbs_mac_event_disconnected(priv
);
1157 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1161 static inline int match_bss_no_security(struct lbs_802_11_security
*secinfo
,
1162 struct bss_descriptor
*match_bss
)
1164 if (!secinfo
->wep_enabled
&&
1165 !secinfo
->WPAenabled
&& !secinfo
->WPA2enabled
&&
1166 match_bss
->wpa_ie
[0] != WLAN_EID_GENERIC
&&
1167 match_bss
->rsn_ie
[0] != WLAN_EID_RSN
&&
1168 !(match_bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
1174 static inline int match_bss_static_wep(struct lbs_802_11_security
*secinfo
,
1175 struct bss_descriptor
*match_bss
)
1177 if (secinfo
->wep_enabled
&&
1178 !secinfo
->WPAenabled
&& !secinfo
->WPA2enabled
&&
1179 (match_bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
1185 static inline int match_bss_wpa(struct lbs_802_11_security
*secinfo
,
1186 struct bss_descriptor
*match_bss
)
1188 if (!secinfo
->wep_enabled
&& secinfo
->WPAenabled
&&
1189 (match_bss
->wpa_ie
[0] == WLAN_EID_GENERIC
)
1190 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1191 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1198 static inline int match_bss_wpa2(struct lbs_802_11_security
*secinfo
,
1199 struct bss_descriptor
*match_bss
)
1201 if (!secinfo
->wep_enabled
&& secinfo
->WPA2enabled
&&
1202 (match_bss
->rsn_ie
[0] == WLAN_EID_RSN
)
1203 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1204 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1211 static inline int match_bss_dynamic_wep(struct lbs_802_11_security
*secinfo
,
1212 struct bss_descriptor
*match_bss
)
1214 if (!secinfo
->wep_enabled
&&
1215 !secinfo
->WPAenabled
&& !secinfo
->WPA2enabled
&&
1216 (match_bss
->wpa_ie
[0] != WLAN_EID_GENERIC
) &&
1217 (match_bss
->rsn_ie
[0] != WLAN_EID_RSN
) &&
1218 (match_bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
1225 * @brief Check if a scanned network compatible with the driver settings
1227 * WEP WPA WPA2 ad-hoc encrypt Network
1228 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
1229 * 0 0 0 0 NONE 0 0 0 yes No security
1230 * 1 0 0 0 NONE 1 0 0 yes Static WEP
1231 * 0 1 0 0 x 1x 1 x yes WPA
1232 * 0 0 1 0 x 1x x 1 yes WPA2
1233 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
1234 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
1237 * @param priv A pointer to struct lbs_private
1238 * @param index Index in scantable to check against current driver settings
1239 * @param mode Network mode: Infrastructure or IBSS
1241 * @return Index in scantable, or error code if negative
1243 static int is_network_compatible(struct lbs_private
*priv
,
1244 struct bss_descriptor
*bss
, uint8_t mode
)
1248 lbs_deb_enter(LBS_DEB_SCAN
);
1250 if (bss
->mode
!= mode
)
1253 matched
= match_bss_no_security(&priv
->secinfo
, bss
);
1256 matched
= match_bss_static_wep(&priv
->secinfo
, bss
);
1259 matched
= match_bss_wpa(&priv
->secinfo
, bss
);
1261 lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x "
1262 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1263 "privacy 0x%x\n", bss
->wpa_ie
[0], bss
->rsn_ie
[0],
1264 priv
->secinfo
.wep_enabled
? "e" : "d",
1265 priv
->secinfo
.WPAenabled
? "e" : "d",
1266 priv
->secinfo
.WPA2enabled
? "e" : "d",
1267 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
1270 matched
= match_bss_wpa2(&priv
->secinfo
, bss
);
1272 lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x "
1273 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1274 "privacy 0x%x\n", bss
->wpa_ie
[0], bss
->rsn_ie
[0],
1275 priv
->secinfo
.wep_enabled
? "e" : "d",
1276 priv
->secinfo
.WPAenabled
? "e" : "d",
1277 priv
->secinfo
.WPA2enabled
? "e" : "d",
1278 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
1281 matched
= match_bss_dynamic_wep(&priv
->secinfo
, bss
);
1283 lbs_deb_scan("is_network_compatible() dynamic WEP: "
1284 "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
1285 bss
->wpa_ie
[0], bss
->rsn_ie
[0],
1286 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
1290 /* bss security settings don't match those configured on card */
1291 lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x "
1292 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
1293 bss
->wpa_ie
[0], bss
->rsn_ie
[0],
1294 priv
->secinfo
.wep_enabled
? "e" : "d",
1295 priv
->secinfo
.WPAenabled
? "e" : "d",
1296 priv
->secinfo
.WPA2enabled
? "e" : "d",
1297 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
1300 lbs_deb_leave_args(LBS_DEB_SCAN
, "matched: %d", matched
);
1305 * @brief This function finds a specific compatible BSSID in the scan list
1307 * Used in association code
1309 * @param priv A pointer to struct lbs_private
1310 * @param bssid BSSID to find in the scan list
1311 * @param mode Network mode: Infrastructure or IBSS
1313 * @return index in BSSID list, or error return code (< 0)
1315 static struct bss_descriptor
*lbs_find_bssid_in_list(struct lbs_private
*priv
,
1316 uint8_t *bssid
, uint8_t mode
)
1318 struct bss_descriptor
*iter_bss
;
1319 struct bss_descriptor
*found_bss
= NULL
;
1321 lbs_deb_enter(LBS_DEB_SCAN
);
1326 lbs_deb_hex(LBS_DEB_SCAN
, "looking for", bssid
, ETH_ALEN
);
1328 /* Look through the scan table for a compatible match. The loop will
1329 * continue past a matched bssid that is not compatible in case there
1330 * is an AP with multiple SSIDs assigned to the same BSSID
1332 mutex_lock(&priv
->lock
);
1333 list_for_each_entry(iter_bss
, &priv
->network_list
, list
) {
1334 if (compare_ether_addr(iter_bss
->bssid
, bssid
))
1335 continue; /* bssid doesn't match */
1339 if (!is_network_compatible(priv
, iter_bss
, mode
))
1341 found_bss
= iter_bss
;
1344 found_bss
= iter_bss
;
1348 mutex_unlock(&priv
->lock
);
1351 lbs_deb_leave_args(LBS_DEB_SCAN
, "found_bss %p", found_bss
);
1356 * @brief This function finds ssid in ssid list.
1358 * Used in association code
1360 * @param priv A pointer to struct lbs_private
1361 * @param ssid SSID to find in the list
1362 * @param bssid BSSID to qualify the SSID selection (if provided)
1363 * @param mode Network mode: Infrastructure or IBSS
1365 * @return index in BSSID list
1367 static struct bss_descriptor
*lbs_find_ssid_in_list(struct lbs_private
*priv
,
1368 uint8_t *ssid
, uint8_t ssid_len
,
1369 uint8_t *bssid
, uint8_t mode
,
1373 struct bss_descriptor
*iter_bss
= NULL
;
1374 struct bss_descriptor
*found_bss
= NULL
;
1375 struct bss_descriptor
*tmp_oldest
= NULL
;
1377 lbs_deb_enter(LBS_DEB_SCAN
);
1379 mutex_lock(&priv
->lock
);
1381 list_for_each_entry(iter_bss
, &priv
->network_list
, list
) {
1383 (iter_bss
->last_scanned
< tmp_oldest
->last_scanned
))
1384 tmp_oldest
= iter_bss
;
1386 if (lbs_ssid_cmp(iter_bss
->ssid
, iter_bss
->ssid_len
,
1387 ssid
, ssid_len
) != 0)
1388 continue; /* ssid doesn't match */
1389 if (bssid
&& compare_ether_addr(iter_bss
->bssid
, bssid
) != 0)
1390 continue; /* bssid doesn't match */
1391 if ((channel
> 0) && (iter_bss
->channel
!= channel
))
1392 continue; /* channel doesn't match */
1397 if (!is_network_compatible(priv
, iter_bss
, mode
))
1401 /* Found requested BSSID */
1402 found_bss
= iter_bss
;
1406 if (SCAN_RSSI(iter_bss
->rssi
) > bestrssi
) {
1407 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1408 found_bss
= iter_bss
;
1413 if (SCAN_RSSI(iter_bss
->rssi
) > bestrssi
) {
1414 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1415 found_bss
= iter_bss
;
1422 mutex_unlock(&priv
->lock
);
1423 lbs_deb_leave_args(LBS_DEB_SCAN
, "found_bss %p", found_bss
);
1427 static int assoc_helper_essid(struct lbs_private
*priv
,
1428 struct assoc_request
* assoc_req
)
1431 struct bss_descriptor
* bss
;
1433 DECLARE_SSID_BUF(ssid
);
1435 lbs_deb_enter(LBS_DEB_ASSOC
);
1437 /* FIXME: take channel into account when picking SSIDs if a channel
1441 if (test_bit(ASSOC_FLAG_CHANNEL
, &assoc_req
->flags
))
1442 channel
= assoc_req
->channel
;
1444 lbs_deb_assoc("SSID '%s' requested\n",
1445 print_ssid(ssid
, assoc_req
->ssid
, assoc_req
->ssid_len
));
1446 if (assoc_req
->mode
== IW_MODE_INFRA
) {
1447 lbs_send_specific_ssid_scan(priv
, assoc_req
->ssid
,
1448 assoc_req
->ssid_len
);
1450 bss
= lbs_find_ssid_in_list(priv
, assoc_req
->ssid
,
1451 assoc_req
->ssid_len
, NULL
, IW_MODE_INFRA
, channel
);
1453 memcpy(&assoc_req
->bss
, bss
, sizeof(struct bss_descriptor
));
1454 ret
= lbs_try_associate(priv
, assoc_req
);
1456 lbs_deb_assoc("SSID not found; cannot associate\n");
1458 } else if (assoc_req
->mode
== IW_MODE_ADHOC
) {
1459 /* Scan for the network, do not save previous results. Stale
1460 * scan data will cause us to join a non-existant adhoc network
1462 lbs_send_specific_ssid_scan(priv
, assoc_req
->ssid
,
1463 assoc_req
->ssid_len
);
1465 /* Search for the requested SSID in the scan table */
1466 bss
= lbs_find_ssid_in_list(priv
, assoc_req
->ssid
,
1467 assoc_req
->ssid_len
, NULL
, IW_MODE_ADHOC
, channel
);
1469 lbs_deb_assoc("SSID found, will join\n");
1470 memcpy(&assoc_req
->bss
, bss
, sizeof(struct bss_descriptor
));
1471 lbs_adhoc_join(priv
, assoc_req
);
1473 /* else send START command */
1474 lbs_deb_assoc("SSID not found, creating adhoc network\n");
1475 memcpy(&assoc_req
->bss
.ssid
, &assoc_req
->ssid
,
1476 IEEE80211_MAX_SSID_LEN
);
1477 assoc_req
->bss
.ssid_len
= assoc_req
->ssid_len
;
1478 lbs_adhoc_start(priv
, assoc_req
);
1482 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1487 static int assoc_helper_bssid(struct lbs_private
*priv
,
1488 struct assoc_request
* assoc_req
)
1491 struct bss_descriptor
* bss
;
1493 lbs_deb_enter_args(LBS_DEB_ASSOC
, "BSSID %pM", assoc_req
->bssid
);
1495 /* Search for index position in list for requested MAC */
1496 bss
= lbs_find_bssid_in_list(priv
, assoc_req
->bssid
,
1499 lbs_deb_assoc("ASSOC: WAP: BSSID %pM not found, "
1500 "cannot associate.\n", assoc_req
->bssid
);
1504 memcpy(&assoc_req
->bss
, bss
, sizeof(struct bss_descriptor
));
1505 if (assoc_req
->mode
== IW_MODE_INFRA
) {
1506 ret
= lbs_try_associate(priv
, assoc_req
);
1507 lbs_deb_assoc("ASSOC: lbs_try_associate(bssid) returned %d\n",
1509 } else if (assoc_req
->mode
== IW_MODE_ADHOC
) {
1510 lbs_adhoc_join(priv
, assoc_req
);
1514 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1519 static int assoc_helper_associate(struct lbs_private
*priv
,
1520 struct assoc_request
* assoc_req
)
1522 int ret
= 0, done
= 0;
1524 lbs_deb_enter(LBS_DEB_ASSOC
);
1526 /* If we're given and 'any' BSSID, try associating based on SSID */
1528 if (test_bit(ASSOC_FLAG_BSSID
, &assoc_req
->flags
)) {
1529 if (compare_ether_addr(bssid_any
, assoc_req
->bssid
) &&
1530 compare_ether_addr(bssid_off
, assoc_req
->bssid
)) {
1531 ret
= assoc_helper_bssid(priv
, assoc_req
);
1536 if (!done
&& test_bit(ASSOC_FLAG_SSID
, &assoc_req
->flags
)) {
1537 ret
= assoc_helper_essid(priv
, assoc_req
);
1540 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1545 static int assoc_helper_mode(struct lbs_private
*priv
,
1546 struct assoc_request
* assoc_req
)
1550 lbs_deb_enter(LBS_DEB_ASSOC
);
1552 if (assoc_req
->mode
== priv
->mode
)
1555 if (assoc_req
->mode
== IW_MODE_INFRA
) {
1556 if (priv
->psstate
!= PS_STATE_FULL_POWER
)
1557 lbs_ps_wakeup(priv
, CMD_OPTION_WAITFORRSP
);
1558 priv
->psmode
= LBS802_11POWERMODECAM
;
1561 priv
->mode
= assoc_req
->mode
;
1562 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
,
1563 assoc_req
->mode
== IW_MODE_ADHOC
? 2 : 1);
1566 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1570 static int assoc_helper_channel(struct lbs_private
*priv
,
1571 struct assoc_request
* assoc_req
)
1575 lbs_deb_enter(LBS_DEB_ASSOC
);
1577 ret
= lbs_update_channel(priv
);
1579 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
1583 if (assoc_req
->channel
== priv
->channel
)
1586 if (priv
->mesh_dev
) {
1587 /* Change mesh channel first; 21.p21 firmware won't let
1588 you change channel otherwise (even though it'll return
1590 lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_STOP
,
1591 assoc_req
->channel
);
1594 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
1595 priv
->channel
, assoc_req
->channel
);
1597 ret
= lbs_set_channel(priv
, assoc_req
->channel
);
1599 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
1601 /* FIXME: shouldn't need to grab the channel _again_ after setting
1602 * it since the firmware is supposed to return the new channel, but
1604 ret
= lbs_update_channel(priv
);
1606 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
1610 if (assoc_req
->channel
!= priv
->channel
) {
1611 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
1612 assoc_req
->channel
);
1616 if (assoc_req
->secinfo
.wep_enabled
&&
1617 (assoc_req
->wep_keys
[0].len
|| assoc_req
->wep_keys
[1].len
||
1618 assoc_req
->wep_keys
[2].len
|| assoc_req
->wep_keys
[3].len
)) {
1619 /* Make sure WEP keys are re-sent to firmware */
1620 set_bit(ASSOC_FLAG_WEP_KEYS
, &assoc_req
->flags
);
1623 /* Must restart/rejoin adhoc networks after channel change */
1624 set_bit(ASSOC_FLAG_SSID
, &assoc_req
->flags
);
1628 lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
1632 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1637 static int assoc_helper_wep_keys(struct lbs_private
*priv
,
1638 struct assoc_request
*assoc_req
)
1643 lbs_deb_enter(LBS_DEB_ASSOC
);
1645 /* Set or remove WEP keys */
1646 if (assoc_req
->wep_keys
[0].len
|| assoc_req
->wep_keys
[1].len
||
1647 assoc_req
->wep_keys
[2].len
|| assoc_req
->wep_keys
[3].len
)
1648 ret
= lbs_cmd_802_11_set_wep(priv
, CMD_ACT_ADD
, assoc_req
);
1650 ret
= lbs_cmd_802_11_set_wep(priv
, CMD_ACT_REMOVE
, assoc_req
);
1655 /* enable/disable the MAC's WEP packet filter */
1656 if (assoc_req
->secinfo
.wep_enabled
)
1657 priv
->mac_control
|= CMD_ACT_MAC_WEP_ENABLE
;
1659 priv
->mac_control
&= ~CMD_ACT_MAC_WEP_ENABLE
;
1661 lbs_set_mac_control(priv
);
1663 mutex_lock(&priv
->lock
);
1665 /* Copy WEP keys into priv wep key fields */
1666 for (i
= 0; i
< 4; i
++) {
1667 memcpy(&priv
->wep_keys
[i
], &assoc_req
->wep_keys
[i
],
1668 sizeof(struct enc_key
));
1670 priv
->wep_tx_keyidx
= assoc_req
->wep_tx_keyidx
;
1672 mutex_unlock(&priv
->lock
);
1675 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1679 static int assoc_helper_secinfo(struct lbs_private
*priv
,
1680 struct assoc_request
* assoc_req
)
1686 lbs_deb_enter(LBS_DEB_ASSOC
);
1688 memcpy(&priv
->secinfo
, &assoc_req
->secinfo
,
1689 sizeof(struct lbs_802_11_security
));
1691 lbs_set_mac_control(priv
);
1693 /* If RSN is already enabled, don't try to enable it again, since
1694 * ENABLE_RSN resets internal state machines and will clobber the
1695 * 4-way WPA handshake.
1698 /* Get RSN enabled/disabled */
1699 ret
= lbs_cmd_802_11_enable_rsn(priv
, CMD_ACT_GET
, &rsn
);
1701 lbs_deb_assoc("Failed to get RSN status: %d\n", ret
);
1705 /* Don't re-enable RSN if it's already enabled */
1706 do_wpa
= assoc_req
->secinfo
.WPAenabled
|| assoc_req
->secinfo
.WPA2enabled
;
1710 /* Set RSN enabled/disabled */
1711 ret
= lbs_cmd_802_11_enable_rsn(priv
, CMD_ACT_SET
, &do_wpa
);
1714 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1719 static int assoc_helper_wpa_keys(struct lbs_private
*priv
,
1720 struct assoc_request
* assoc_req
)
1723 unsigned int flags
= assoc_req
->flags
;
1725 lbs_deb_enter(LBS_DEB_ASSOC
);
1727 /* Work around older firmware bug where WPA unicast and multicast
1728 * keys must be set independently. Seen in SDIO parts with firmware
1732 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc_req
->flags
)) {
1733 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc_req
->flags
);
1734 ret
= lbs_cmd_802_11_key_material(priv
, CMD_ACT_SET
, assoc_req
);
1735 assoc_req
->flags
= flags
;
1741 memcpy(&priv
->wpa_unicast_key
, &assoc_req
->wpa_unicast_key
,
1742 sizeof(struct enc_key
));
1744 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc_req
->flags
)) {
1745 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc_req
->flags
);
1747 ret
= lbs_cmd_802_11_key_material(priv
, CMD_ACT_SET
, assoc_req
);
1748 assoc_req
->flags
= flags
;
1750 memcpy(&priv
->wpa_mcast_key
, &assoc_req
->wpa_mcast_key
,
1751 sizeof(struct enc_key
));
1755 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1760 static int assoc_helper_wpa_ie(struct lbs_private
*priv
,
1761 struct assoc_request
* assoc_req
)
1765 lbs_deb_enter(LBS_DEB_ASSOC
);
1767 if (assoc_req
->secinfo
.WPAenabled
|| assoc_req
->secinfo
.WPA2enabled
) {
1768 memcpy(&priv
->wpa_ie
, &assoc_req
->wpa_ie
, assoc_req
->wpa_ie_len
);
1769 priv
->wpa_ie_len
= assoc_req
->wpa_ie_len
;
1771 memset(&priv
->wpa_ie
, 0, MAX_WPA_IE_LEN
);
1772 priv
->wpa_ie_len
= 0;
1775 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1780 static int should_deauth_infrastructure(struct lbs_private
*priv
,
1781 struct assoc_request
* assoc_req
)
1785 if (priv
->connect_status
!= LBS_CONNECTED
)
1788 lbs_deb_enter(LBS_DEB_ASSOC
);
1789 if (test_bit(ASSOC_FLAG_SSID
, &assoc_req
->flags
)) {
1790 lbs_deb_assoc("Deauthenticating due to new SSID\n");
1795 if (test_bit(ASSOC_FLAG_SECINFO
, &assoc_req
->flags
)) {
1796 if (priv
->secinfo
.auth_mode
!= assoc_req
->secinfo
.auth_mode
) {
1797 lbs_deb_assoc("Deauthenticating due to new security\n");
1803 if (test_bit(ASSOC_FLAG_BSSID
, &assoc_req
->flags
)) {
1804 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
1809 if (test_bit(ASSOC_FLAG_CHANNEL
, &assoc_req
->flags
)) {
1810 lbs_deb_assoc("Deauthenticating due to channel switch\n");
1815 /* FIXME: deal with 'auto' mode somehow */
1816 if (test_bit(ASSOC_FLAG_MODE
, &assoc_req
->flags
)) {
1817 if (assoc_req
->mode
!= IW_MODE_INFRA
) {
1818 lbs_deb_assoc("Deauthenticating due to leaving "
1826 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
1831 static int should_stop_adhoc(struct lbs_private
*priv
,
1832 struct assoc_request
* assoc_req
)
1834 lbs_deb_enter(LBS_DEB_ASSOC
);
1836 if (priv
->connect_status
!= LBS_CONNECTED
)
1839 if (lbs_ssid_cmp(priv
->curbssparams
.ssid
,
1840 priv
->curbssparams
.ssid_len
,
1841 assoc_req
->ssid
, assoc_req
->ssid_len
) != 0)
1844 /* FIXME: deal with 'auto' mode somehow */
1845 if (test_bit(ASSOC_FLAG_MODE
, &assoc_req
->flags
)) {
1846 if (assoc_req
->mode
!= IW_MODE_ADHOC
)
1850 if (test_bit(ASSOC_FLAG_CHANNEL
, &assoc_req
->flags
)) {
1851 if (assoc_req
->channel
!= priv
->channel
)
1855 lbs_deb_leave(LBS_DEB_ASSOC
);
1861 * @brief This function finds the best SSID in the Scan List
1863 * Search the scan table for the best SSID that also matches the current
1864 * adapter network preference (infrastructure or adhoc)
1866 * @param priv A pointer to struct lbs_private
1868 * @return index in BSSID list
1870 static struct bss_descriptor
*lbs_find_best_ssid_in_list(
1871 struct lbs_private
*priv
, uint8_t mode
)
1873 uint8_t bestrssi
= 0;
1874 struct bss_descriptor
*iter_bss
;
1875 struct bss_descriptor
*best_bss
= NULL
;
1877 lbs_deb_enter(LBS_DEB_SCAN
);
1879 mutex_lock(&priv
->lock
);
1881 list_for_each_entry(iter_bss
, &priv
->network_list
, list
) {
1885 if (!is_network_compatible(priv
, iter_bss
, mode
))
1887 if (SCAN_RSSI(iter_bss
->rssi
) <= bestrssi
)
1889 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1890 best_bss
= iter_bss
;
1894 if (SCAN_RSSI(iter_bss
->rssi
) <= bestrssi
)
1896 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1897 best_bss
= iter_bss
;
1902 mutex_unlock(&priv
->lock
);
1903 lbs_deb_leave_args(LBS_DEB_SCAN
, "best_bss %p", best_bss
);
1908 * @brief Find the best AP
1910 * Used from association worker.
1912 * @param priv A pointer to struct lbs_private structure
1913 * @param pSSID A pointer to AP's ssid
1915 * @return 0--success, otherwise--fail
1917 static int lbs_find_best_network_ssid(struct lbs_private
*priv
,
1918 uint8_t *out_ssid
, uint8_t *out_ssid_len
, uint8_t preferred_mode
,
1922 struct bss_descriptor
*found
;
1924 lbs_deb_enter(LBS_DEB_SCAN
);
1926 priv
->scan_ssid_len
= 0;
1927 lbs_scan_networks(priv
, 1);
1928 if (priv
->surpriseremoved
)
1931 found
= lbs_find_best_ssid_in_list(priv
, preferred_mode
);
1932 if (found
&& (found
->ssid_len
> 0)) {
1933 memcpy(out_ssid
, &found
->ssid
, IEEE80211_MAX_SSID_LEN
);
1934 *out_ssid_len
= found
->ssid_len
;
1935 *out_mode
= found
->mode
;
1940 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
1945 void lbs_association_worker(struct work_struct
*work
)
1947 struct lbs_private
*priv
= container_of(work
, struct lbs_private
,
1949 struct assoc_request
* assoc_req
= NULL
;
1951 int find_any_ssid
= 0;
1952 DECLARE_SSID_BUF(ssid
);
1954 lbs_deb_enter(LBS_DEB_ASSOC
);
1956 mutex_lock(&priv
->lock
);
1957 assoc_req
= priv
->pending_assoc_req
;
1958 priv
->pending_assoc_req
= NULL
;
1959 priv
->in_progress_assoc_req
= assoc_req
;
1960 mutex_unlock(&priv
->lock
);
1966 "Association Request:\n"
1973 " secinfo: %s%s%s\n"
1976 print_ssid(ssid
, assoc_req
->ssid
, assoc_req
->ssid_len
),
1977 assoc_req
->channel
, assoc_req
->band
, assoc_req
->mode
,
1979 assoc_req
->secinfo
.WPAenabled
? " WPA" : "",
1980 assoc_req
->secinfo
.WPA2enabled
? " WPA2" : "",
1981 assoc_req
->secinfo
.wep_enabled
? " WEP" : "",
1982 assoc_req
->secinfo
.auth_mode
);
1984 /* If 'any' SSID was specified, find an SSID to associate with */
1985 if (test_bit(ASSOC_FLAG_SSID
, &assoc_req
->flags
) &&
1986 !assoc_req
->ssid_len
)
1989 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
1990 if (test_bit(ASSOC_FLAG_BSSID
, &assoc_req
->flags
)) {
1991 if (compare_ether_addr(assoc_req
->bssid
, bssid_any
) &&
1992 compare_ether_addr(assoc_req
->bssid
, bssid_off
))
1996 if (find_any_ssid
) {
1997 u8 new_mode
= assoc_req
->mode
;
1999 ret
= lbs_find_best_network_ssid(priv
, assoc_req
->ssid
,
2000 &assoc_req
->ssid_len
, assoc_req
->mode
, &new_mode
);
2002 lbs_deb_assoc("Could not find best network\n");
2007 /* Ensure we switch to the mode of the AP */
2008 if (assoc_req
->mode
== IW_MODE_AUTO
) {
2009 set_bit(ASSOC_FLAG_MODE
, &assoc_req
->flags
);
2010 assoc_req
->mode
= new_mode
;
2015 * Check if the attributes being changing require deauthentication
2016 * from the currently associated infrastructure access point.
2018 if (priv
->mode
== IW_MODE_INFRA
) {
2019 if (should_deauth_infrastructure(priv
, assoc_req
)) {
2020 ret
= lbs_cmd_80211_deauthenticate(priv
,
2021 priv
->curbssparams
.bssid
,
2022 WLAN_REASON_DEAUTH_LEAVING
);
2024 lbs_deb_assoc("Deauthentication due to new "
2025 "configuration request failed: %d\n",
2029 } else if (priv
->mode
== IW_MODE_ADHOC
) {
2030 if (should_stop_adhoc(priv
, assoc_req
)) {
2031 ret
= lbs_adhoc_stop(priv
);
2033 lbs_deb_assoc("Teardown of AdHoc network due to "
2034 "new configuration request failed: %d\n",
2041 /* Send the various configuration bits to the firmware */
2042 if (test_bit(ASSOC_FLAG_MODE
, &assoc_req
->flags
)) {
2043 ret
= assoc_helper_mode(priv
, assoc_req
);
2048 if (test_bit(ASSOC_FLAG_CHANNEL
, &assoc_req
->flags
)) {
2049 ret
= assoc_helper_channel(priv
, assoc_req
);
2054 if (test_bit(ASSOC_FLAG_SECINFO
, &assoc_req
->flags
)) {
2055 ret
= assoc_helper_secinfo(priv
, assoc_req
);
2060 if (test_bit(ASSOC_FLAG_WPA_IE
, &assoc_req
->flags
)) {
2061 ret
= assoc_helper_wpa_ie(priv
, assoc_req
);
2067 * v10 FW wants WPA keys to be set/cleared before WEP key operations,
2068 * otherwise it will fail to correctly associate to WEP networks.
2069 * Other firmware versions don't appear to care.
2071 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc_req
->flags
) ||
2072 test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc_req
->flags
)) {
2073 ret
= assoc_helper_wpa_keys(priv
, assoc_req
);
2078 if (test_bit(ASSOC_FLAG_WEP_KEYS
, &assoc_req
->flags
) ||
2079 test_bit(ASSOC_FLAG_WEP_TX_KEYIDX
, &assoc_req
->flags
)) {
2080 ret
= assoc_helper_wep_keys(priv
, assoc_req
);
2086 /* SSID/BSSID should be the _last_ config option set, because they
2087 * trigger the association attempt.
2089 if (test_bit(ASSOC_FLAG_BSSID
, &assoc_req
->flags
) ||
2090 test_bit(ASSOC_FLAG_SSID
, &assoc_req
->flags
)) {
2093 ret
= assoc_helper_associate(priv
, assoc_req
);
2095 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
2100 if (priv
->connect_status
!= LBS_CONNECTED
) {
2101 lbs_deb_assoc("ASSOC: association unsuccessful, "
2107 lbs_deb_assoc("associated to %pM\n",
2108 priv
->curbssparams
.bssid
);
2109 lbs_prepare_and_send_command(priv
,
2111 0, CMD_OPTION_WAITFORRSP
, 0, NULL
);
2119 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
2123 mutex_lock(&priv
->lock
);
2124 priv
->in_progress_assoc_req
= NULL
;
2125 mutex_unlock(&priv
->lock
);
2129 lbs_deb_leave(LBS_DEB_ASSOC
);
2134 * Caller MUST hold any necessary locks
2136 struct assoc_request
*lbs_get_association_request(struct lbs_private
*priv
)
2138 struct assoc_request
* assoc_req
;
2140 lbs_deb_enter(LBS_DEB_ASSOC
);
2141 if (!priv
->pending_assoc_req
) {
2142 priv
->pending_assoc_req
= kzalloc(sizeof(struct assoc_request
),
2144 if (!priv
->pending_assoc_req
) {
2145 lbs_pr_info("Not enough memory to allocate association"
2151 /* Copy current configuration attributes to the association request,
2152 * but don't overwrite any that are already set.
2154 assoc_req
= priv
->pending_assoc_req
;
2155 if (!test_bit(ASSOC_FLAG_SSID
, &assoc_req
->flags
)) {
2156 memcpy(&assoc_req
->ssid
, &priv
->curbssparams
.ssid
,
2157 IEEE80211_MAX_SSID_LEN
);
2158 assoc_req
->ssid_len
= priv
->curbssparams
.ssid_len
;
2161 if (!test_bit(ASSOC_FLAG_CHANNEL
, &assoc_req
->flags
))
2162 assoc_req
->channel
= priv
->channel
;
2164 if (!test_bit(ASSOC_FLAG_BAND
, &assoc_req
->flags
))
2165 assoc_req
->band
= priv
->curbssparams
.band
;
2167 if (!test_bit(ASSOC_FLAG_MODE
, &assoc_req
->flags
))
2168 assoc_req
->mode
= priv
->mode
;
2170 if (!test_bit(ASSOC_FLAG_BSSID
, &assoc_req
->flags
)) {
2171 memcpy(&assoc_req
->bssid
, priv
->curbssparams
.bssid
,
2175 if (!test_bit(ASSOC_FLAG_WEP_KEYS
, &assoc_req
->flags
)) {
2177 for (i
= 0; i
< 4; i
++) {
2178 memcpy(&assoc_req
->wep_keys
[i
], &priv
->wep_keys
[i
],
2179 sizeof(struct enc_key
));
2183 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX
, &assoc_req
->flags
))
2184 assoc_req
->wep_tx_keyidx
= priv
->wep_tx_keyidx
;
2186 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc_req
->flags
)) {
2187 memcpy(&assoc_req
->wpa_mcast_key
, &priv
->wpa_mcast_key
,
2188 sizeof(struct enc_key
));
2191 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc_req
->flags
)) {
2192 memcpy(&assoc_req
->wpa_unicast_key
, &priv
->wpa_unicast_key
,
2193 sizeof(struct enc_key
));
2196 if (!test_bit(ASSOC_FLAG_SECINFO
, &assoc_req
->flags
)) {
2197 memcpy(&assoc_req
->secinfo
, &priv
->secinfo
,
2198 sizeof(struct lbs_802_11_security
));
2201 if (!test_bit(ASSOC_FLAG_WPA_IE
, &assoc_req
->flags
)) {
2202 memcpy(&assoc_req
->wpa_ie
, &priv
->wpa_ie
,
2204 assoc_req
->wpa_ie_len
= priv
->wpa_ie_len
;
2207 lbs_deb_leave(LBS_DEB_ASSOC
);
2213 * @brief Deauthenticate from a specific BSS
2215 * @param priv A pointer to struct lbs_private structure
2216 * @param bssid The specific BSS to deauthenticate from
2217 * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating
2219 * @return 0 on success, error on failure
2221 int lbs_cmd_80211_deauthenticate(struct lbs_private
*priv
, u8 bssid
[ETH_ALEN
],
2224 struct cmd_ds_802_11_deauthenticate cmd
;
2227 lbs_deb_enter(LBS_DEB_JOIN
);
2229 memset(&cmd
, 0, sizeof(cmd
));
2230 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
2231 memcpy(cmd
.macaddr
, &bssid
[0], ETH_ALEN
);
2232 cmd
.reasoncode
= cpu_to_le16(reason
);
2234 ret
= lbs_cmd_with_response(priv
, CMD_802_11_DEAUTHENTICATE
, &cmd
);
2236 /* Clean up everything even if there was an error; can't assume that
2237 * we're still authenticated to the AP after trying to deauth.
2239 lbs_mac_event_disconnected(priv
);
2241 lbs_deb_leave(LBS_DEB_JOIN
);