diff options
author | Dan Williams <dcbw@redhat.com> | 2008-08-21 21:46:59 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-08-29 16:24:07 -0400 |
commit | f5fe1fdaae86a74d6977fafd8fdd8697e398dafd (patch) | |
tree | a341d45ea902bb9b8ed1ca07934f62d43951d741 /drivers/net/wireless/libertas/assoc.c | |
parent | d5db2dfa660de13c3643149b89c7602dd49aa168 (diff) |
libertas: convert adhoc operations to direct commands
with fixes for v9 and later firmware too.
Signed-off-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/libertas/assoc.c')
-rw-r--r-- | drivers/net/wireless/libertas/assoc.c | 632 |
1 files changed, 278 insertions, 354 deletions
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c index d47e4d5734cd..4ddf44b2758b 100644 --- a/drivers/net/wireless/libertas/assoc.c +++ b/drivers/net/wireless/libertas/assoc.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "scan.h" | 8 | #include "scan.h" |
9 | #include "cmd.h" | 9 | #include "cmd.h" |
10 | 10 | ||
11 | static int lbs_adhoc_post(struct lbs_private *priv, struct cmd_header *resp); | ||
11 | 12 | ||
12 | static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) = | 13 | static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) = |
13 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; | 14 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
@@ -20,6 +21,82 @@ static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) = | |||
20 | #define CAPINFO_MASK (~(0xda00)) | 21 | #define CAPINFO_MASK (~(0xda00)) |
21 | 22 | ||
22 | 23 | ||
24 | /** | ||
25 | * @brief This function finds common rates between rates and card rates. | ||
26 | * | ||
27 | * It will fill common rates in rates as output if found. | ||
28 | * | ||
29 | * NOTE: Setting the MSB of the basic rates need to be taken | ||
30 | * care, either before or after calling this function | ||
31 | * | ||
32 | * @param priv A pointer to struct lbs_private structure | ||
33 | * @param rates the buffer which keeps input and output | ||
34 | * @param rates_size the size of rate1 buffer; new size of buffer on return | ||
35 | * | ||
36 | * @return 0 on success, or -1 on error | ||
37 | */ | ||
38 | static int get_common_rates(struct lbs_private *priv, | ||
39 | u8 *rates, | ||
40 | u16 *rates_size) | ||
41 | { | ||
42 | u8 *card_rates = lbs_bg_rates; | ||
43 | size_t num_card_rates = sizeof(lbs_bg_rates); | ||
44 | int ret = 0, i, j; | ||
45 | u8 tmp[30]; | ||
46 | size_t tmp_size = 0; | ||
47 | |||
48 | /* For each rate in card_rates that exists in rate1, copy to tmp */ | ||
49 | for (i = 0; card_rates[i] && (i < num_card_rates); i++) { | ||
50 | for (j = 0; rates[j] && (j < *rates_size); j++) { | ||
51 | if (rates[j] == card_rates[i]) | ||
52 | tmp[tmp_size++] = card_rates[i]; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); | ||
57 | lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); | ||
58 | lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); | ||
59 | lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); | ||
60 | |||
61 | if (!priv->enablehwauto) { | ||
62 | for (i = 0; i < tmp_size; i++) { | ||
63 | if (tmp[i] == priv->cur_rate) | ||
64 | goto done; | ||
65 | } | ||
66 | lbs_pr_alert("Previously set fixed data rate %#x isn't " | ||
67 | "compatible with the network.\n", priv->cur_rate); | ||
68 | ret = -1; | ||
69 | goto done; | ||
70 | } | ||
71 | ret = 0; | ||
72 | |||
73 | done: | ||
74 | memset(rates, 0, *rates_size); | ||
75 | *rates_size = min_t(int, tmp_size, *rates_size); | ||
76 | memcpy(rates, tmp, *rates_size); | ||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | |||
81 | /** | ||
82 | * @brief Sets the MSB on basic rates as the firmware requires | ||
83 | * | ||
84 | * Scan through an array and set the MSB for basic data rates. | ||
85 | * | ||
86 | * @param rates buffer of data rates | ||
87 | * @param len size of buffer | ||
88 | */ | ||
89 | static void lbs_set_basic_rate_flags(u8 *rates, size_t len) | ||
90 | { | ||
91 | int i; | ||
92 | |||
93 | for (i = 0; i < len; i++) { | ||
94 | if (rates[i] == 0x02 || rates[i] == 0x04 || | ||
95 | rates[i] == 0x0b || rates[i] == 0x16) | ||
96 | rates[i] |= 0x80; | ||
97 | } | ||
98 | } | ||
99 | |||
23 | 100 | ||
24 | /** | 101 | /** |
25 | * @brief Associate to a specific BSS discovered in a scan | 102 | * @brief Associate to a specific BSS discovered in a scan |
@@ -66,14 +143,17 @@ out: | |||
66 | * @param priv A pointer to struct lbs_private structure | 143 | * @param priv A pointer to struct lbs_private structure |
67 | * @param assoc_req The association request describing the BSS to join | 144 | * @param assoc_req The association request describing the BSS to join |
68 | * | 145 | * |
69 | * @return 0--success, -1--fail | 146 | * @return 0 on success, error on failure |
70 | */ | 147 | */ |
71 | static int lbs_join_adhoc_network(struct lbs_private *priv, | 148 | static int lbs_adhoc_join(struct lbs_private *priv, |
72 | struct assoc_request *assoc_req) | 149 | struct assoc_request *assoc_req) |
73 | { | 150 | { |
151 | struct cmd_ds_802_11_ad_hoc_join cmd; | ||
74 | struct bss_descriptor *bss = &assoc_req->bss; | 152 | struct bss_descriptor *bss = &assoc_req->bss; |
75 | int ret = 0; | ||
76 | u8 preamble = RADIO_PREAMBLE_LONG; | 153 | u8 preamble = RADIO_PREAMBLE_LONG; |
154 | DECLARE_MAC_BUF(mac); | ||
155 | u16 ratesize = 0; | ||
156 | int ret = 0; | ||
77 | 157 | ||
78 | lbs_deb_enter(LBS_DEB_ASSOC); | 158 | lbs_deb_enter(LBS_DEB_ASSOC); |
79 | 159 | ||
@@ -123,10 +203,88 @@ static int lbs_join_adhoc_network(struct lbs_private *priv, | |||
123 | lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band); | 203 | lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band); |
124 | 204 | ||
125 | priv->adhoccreate = 0; | 205 | priv->adhoccreate = 0; |
206 | priv->curbssparams.channel = bss->channel; | ||
126 | 207 | ||
127 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN, | 208 | /* Build the join command */ |
128 | 0, CMD_OPTION_WAITFORRSP, | 209 | memset(&cmd, 0, sizeof(cmd)); |
129 | OID_802_11_SSID, assoc_req); | 210 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
211 | |||
212 | cmd.bss.type = CMD_BSS_TYPE_IBSS; | ||
213 | cmd.bss.beaconperiod = cpu_to_le16(bss->beaconperiod); | ||
214 | |||
215 | memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN); | ||
216 | memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len); | ||
217 | |||
218 | memcpy(&cmd.bss.phyparamset, &bss->phyparamset, | ||
219 | sizeof(union ieeetypes_phyparamset)); | ||
220 | |||
221 | memcpy(&cmd.bss.ssparamset, &bss->ssparamset, | ||
222 | sizeof(union IEEEtypes_ssparamset)); | ||
223 | |||
224 | cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); | ||
225 | lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", | ||
226 | bss->capability, CAPINFO_MASK); | ||
227 | |||
228 | /* information on BSSID descriptor passed to FW */ | ||
229 | lbs_deb_join("ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n", | ||
230 | print_mac(mac, cmd.bss.bssid), cmd.bss.ssid); | ||
231 | |||
232 | /* Only v8 and below support setting these */ | ||
233 | if (priv->fwrelease < 0x09000000) { | ||
234 | /* failtimeout */ | ||
235 | cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); | ||
236 | /* probedelay */ | ||
237 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | ||
238 | } | ||
239 | |||
240 | /* Copy Data rates from the rates recorded in scan response */ | ||
241 | memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates)); | ||
242 | ratesize = min_t(u16, sizeof(cmd.bss.rates), MAX_RATES); | ||
243 | memcpy(cmd.bss.rates, bss->rates, ratesize); | ||
244 | if (get_common_rates(priv, cmd.bss.rates, &ratesize)) { | ||
245 | lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n"); | ||
246 | ret = -1; | ||
247 | goto out; | ||
248 | } | ||
249 | |||
250 | /* Copy the ad-hoc creation rates into Current BSS state structure */ | ||
251 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | ||
252 | memcpy(&priv->curbssparams.rates, cmd.bss.rates, ratesize); | ||
253 | |||
254 | /* Set MSB on basic rates as the firmware requires, but _after_ | ||
255 | * copying to current bss rates. | ||
256 | */ | ||
257 | lbs_set_basic_rate_flags(cmd.bss.rates, ratesize); | ||
258 | |||
259 | cmd.bss.ssparamset.ibssparamset.atimwindow = cpu_to_le16(bss->atimwindow); | ||
260 | |||
261 | if (assoc_req->secinfo.wep_enabled) { | ||
262 | u16 tmp = le16_to_cpu(cmd.bss.capability); | ||
263 | tmp |= WLAN_CAPABILITY_PRIVACY; | ||
264 | cmd.bss.capability = cpu_to_le16(tmp); | ||
265 | } | ||
266 | |||
267 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { | ||
268 | __le32 local_ps_mode = cpu_to_le32(LBS802_11POWERMODECAM); | ||
269 | |||
270 | /* wake up first */ | ||
271 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, | ||
272 | CMD_ACT_SET, 0, 0, | ||
273 | &local_ps_mode); | ||
274 | if (ret) { | ||
275 | ret = -1; | ||
276 | goto out; | ||
277 | } | ||
278 | } | ||
279 | |||
280 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { | ||
281 | ret = -1; | ||
282 | goto out; | ||
283 | } | ||
284 | |||
285 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd); | ||
286 | if (ret == 0) | ||
287 | ret = lbs_adhoc_post(priv, (struct cmd_header *) &cmd); | ||
130 | 288 | ||
131 | out: | 289 | out: |
132 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | 290 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
@@ -138,20 +296,22 @@ out: | |||
138 | * | 296 | * |
139 | * @param priv A pointer to struct lbs_private structure | 297 | * @param priv A pointer to struct lbs_private structure |
140 | * @param assoc_req The association request describing the BSS to start | 298 | * @param assoc_req The association request describing the BSS to start |
141 | * @return 0--success, -1--fail | 299 | * |
300 | * @return 0 on success, error on failure | ||
142 | */ | 301 | */ |
143 | static int lbs_start_adhoc_network(struct lbs_private *priv, | 302 | static int lbs_adhoc_start(struct lbs_private *priv, |
144 | struct assoc_request *assoc_req) | 303 | struct assoc_request *assoc_req) |
145 | { | 304 | { |
146 | int ret = 0; | 305 | struct cmd_ds_802_11_ad_hoc_start cmd; |
147 | u8 preamble = RADIO_PREAMBLE_LONG; | 306 | u8 preamble = RADIO_PREAMBLE_LONG; |
307 | size_t ratesize = 0; | ||
308 | u16 tmpcap = 0; | ||
309 | int ret = 0; | ||
148 | 310 | ||
149 | lbs_deb_enter(LBS_DEB_ASSOC); | 311 | lbs_deb_enter(LBS_DEB_ASSOC); |
150 | 312 | ||
151 | priv->adhoccreate = 1; | ||
152 | |||
153 | if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) { | 313 | if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) { |
154 | lbs_deb_join("AdhocStart: Short preamble\n"); | 314 | lbs_deb_join("ADHOC_START: Will use short preamble\n"); |
155 | preamble = RADIO_PREAMBLE_SHORT; | 315 | preamble = RADIO_PREAMBLE_SHORT; |
156 | } | 316 | } |
157 | 317 | ||
@@ -159,21 +319,107 @@ static int lbs_start_adhoc_network(struct lbs_private *priv, | |||
159 | if (ret) | 319 | if (ret) |
160 | goto out; | 320 | goto out; |
161 | 321 | ||
162 | lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel); | 322 | /* Build the start command */ |
163 | lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band); | 323 | memset(&cmd, 0, sizeof(cmd)); |
324 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | ||
164 | 325 | ||
165 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START, | 326 | memcpy(cmd.ssid, assoc_req->ssid, assoc_req->ssid_len); |
166 | 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); | 327 | |
328 | lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n", | ||
329 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), | ||
330 | assoc_req->ssid_len); | ||
331 | |||
332 | cmd.bsstype = CMD_BSS_TYPE_IBSS; | ||
333 | |||
334 | if (priv->beacon_period == 0) | ||
335 | priv->beacon_period = MRVDRV_BEACON_INTERVAL; | ||
336 | cmd.beaconperiod = cpu_to_le16(priv->beacon_period); | ||
337 | |||
338 | WARN_ON(!assoc_req->channel); | ||
339 | |||
340 | /* set Physical parameter set */ | ||
341 | cmd.phyparamset.dsparamset.elementid = MFIE_TYPE_DS_SET; | ||
342 | cmd.phyparamset.dsparamset.len = 1; | ||
343 | cmd.phyparamset.dsparamset.currentchan = assoc_req->channel; | ||
344 | |||
345 | /* set IBSS parameter set */ | ||
346 | cmd.ssparamset.ibssparamset.elementid = MFIE_TYPE_IBSS_SET; | ||
347 | cmd.ssparamset.ibssparamset.len = 2; | ||
348 | cmd.ssparamset.ibssparamset.atimwindow = 0; | ||
349 | |||
350 | /* set capability info */ | ||
351 | tmpcap = WLAN_CAPABILITY_IBSS; | ||
352 | if (assoc_req->secinfo.wep_enabled) { | ||
353 | lbs_deb_join("ADHOC_START: WEP enabled, setting privacy on\n"); | ||
354 | tmpcap |= WLAN_CAPABILITY_PRIVACY; | ||
355 | } else | ||
356 | lbs_deb_join("ADHOC_START: WEP disabled, setting privacy off\n"); | ||
357 | |||
358 | cmd.capability = cpu_to_le16(tmpcap); | ||
359 | |||
360 | /* Only v8 and below support setting probe delay */ | ||
361 | if (priv->fwrelease < 0x09000000) | ||
362 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | ||
363 | |||
364 | ratesize = min(sizeof(cmd.rates), sizeof(lbs_bg_rates)); | ||
365 | memcpy(cmd.rates, lbs_bg_rates, ratesize); | ||
366 | |||
367 | /* Copy the ad-hoc creating rates into Current BSS state structure */ | ||
368 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | ||
369 | memcpy(&priv->curbssparams.rates, &cmd.rates, ratesize); | ||
370 | |||
371 | /* Set MSB on basic rates as the firmware requires, but _after_ | ||
372 | * copying to current bss rates. | ||
373 | */ | ||
374 | lbs_set_basic_rate_flags(cmd.rates, ratesize); | ||
375 | |||
376 | lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n", | ||
377 | cmd.rates[0], cmd.rates[1], cmd.rates[2], cmd.rates[3]); | ||
378 | |||
379 | if (lbs_create_dnld_countryinfo_11d(priv)) { | ||
380 | lbs_deb_join("ADHOC_START: dnld_countryinfo_11d failed\n"); | ||
381 | ret = -1; | ||
382 | goto out; | ||
383 | } | ||
384 | |||
385 | lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n", | ||
386 | assoc_req->channel, assoc_req->band); | ||
387 | |||
388 | priv->adhoccreate = 1; | ||
389 | priv->mode = IW_MODE_ADHOC; | ||
390 | |||
391 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd); | ||
392 | if (ret == 0) | ||
393 | ret = lbs_adhoc_post(priv, (struct cmd_header *) &cmd); | ||
167 | 394 | ||
168 | out: | 395 | out: |
169 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | 396 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
170 | return ret; | 397 | return ret; |
171 | } | 398 | } |
172 | 399 | ||
173 | int lbs_stop_adhoc_network(struct lbs_private *priv) | 400 | /** |
401 | * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode | ||
402 | * | ||
403 | * @param priv A pointer to struct lbs_private structure | ||
404 | * @return 0 on success, or an error | ||
405 | */ | ||
406 | int lbs_adhoc_stop(struct lbs_private *priv) | ||
174 | { | 407 | { |
175 | return lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP, | 408 | struct cmd_ds_802_11_ad_hoc_stop cmd; |
176 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); | 409 | int ret; |
410 | |||
411 | lbs_deb_enter(LBS_DEB_JOIN); | ||
412 | |||
413 | memset(&cmd, 0, sizeof (cmd)); | ||
414 | cmd.hdr.size = cpu_to_le16 (sizeof (cmd)); | ||
415 | |||
416 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd); | ||
417 | |||
418 | /* Clean up everything even if there was an error */ | ||
419 | lbs_mac_event_disconnected(priv); | ||
420 | |||
421 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | ||
422 | return ret; | ||
177 | } | 423 | } |
178 | 424 | ||
179 | static inline int match_bss_no_security(struct lbs_802_11_security *secinfo, | 425 | static inline int match_bss_no_security(struct lbs_802_11_security *secinfo, |
@@ -485,14 +731,14 @@ static int assoc_helper_essid(struct lbs_private *priv, | |||
485 | if (bss != NULL) { | 731 | if (bss != NULL) { |
486 | lbs_deb_assoc("SSID found, will join\n"); | 732 | lbs_deb_assoc("SSID found, will join\n"); |
487 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); | 733 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
488 | lbs_join_adhoc_network(priv, assoc_req); | 734 | lbs_adhoc_join(priv, assoc_req); |
489 | } else { | 735 | } else { |
490 | /* else send START command */ | 736 | /* else send START command */ |
491 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); | 737 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); |
492 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, | 738 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
493 | IW_ESSID_MAX_SIZE); | 739 | IW_ESSID_MAX_SIZE); |
494 | assoc_req->bss.ssid_len = assoc_req->ssid_len; | 740 | assoc_req->bss.ssid_len = assoc_req->ssid_len; |
495 | lbs_start_adhoc_network(priv, assoc_req); | 741 | lbs_adhoc_start(priv, assoc_req); |
496 | } | 742 | } |
497 | } | 743 | } |
498 | 744 | ||
@@ -525,7 +771,7 @@ static int assoc_helper_bssid(struct lbs_private *priv, | |||
525 | ret = lbs_associate(priv, assoc_req); | 771 | ret = lbs_associate(priv, assoc_req); |
526 | lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret); | 772 | lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret); |
527 | } else if (assoc_req->mode == IW_MODE_ADHOC) { | 773 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
528 | lbs_join_adhoc_network(priv, assoc_req); | 774 | lbs_adhoc_join(priv, assoc_req); |
529 | } | 775 | } |
530 | 776 | ||
531 | out: | 777 | out: |
@@ -1045,7 +1291,7 @@ void lbs_association_worker(struct work_struct *work) | |||
1045 | } | 1291 | } |
1046 | } else if (priv->mode == IW_MODE_ADHOC) { | 1292 | } else if (priv->mode == IW_MODE_ADHOC) { |
1047 | if (should_stop_adhoc(priv, assoc_req)) { | 1293 | if (should_stop_adhoc(priv, assoc_req)) { |
1048 | ret = lbs_stop_adhoc_network(priv); | 1294 | ret = lbs_adhoc_stop(priv); |
1049 | if (ret) { | 1295 | if (ret) { |
1050 | lbs_deb_assoc("Teardown of AdHoc network due to " | 1296 | lbs_deb_assoc("Teardown of AdHoc network due to " |
1051 | "new configuration request failed: %d\n", | 1297 | "new configuration request failed: %d\n", |
@@ -1221,82 +1467,6 @@ struct assoc_request *lbs_get_association_request(struct lbs_private *priv) | |||
1221 | 1467 | ||
1222 | 1468 | ||
1223 | /** | 1469 | /** |
1224 | * @brief This function finds common rates between rate1 and card rates. | ||
1225 | * | ||
1226 | * It will fill common rates in rate1 as output if found. | ||
1227 | * | ||
1228 | * NOTE: Setting the MSB of the basic rates need to be taken | ||
1229 | * care, either before or after calling this function | ||
1230 | * | ||
1231 | * @param priv A pointer to struct lbs_private structure | ||
1232 | * @param rate1 the buffer which keeps input and output | ||
1233 | * @param rate1_size the size of rate1 buffer; new size of buffer on return | ||
1234 | * | ||
1235 | * @return 0 or -1 | ||
1236 | */ | ||
1237 | static int get_common_rates(struct lbs_private *priv, | ||
1238 | u8 *rates, | ||
1239 | u16 *rates_size) | ||
1240 | { | ||
1241 | u8 *card_rates = lbs_bg_rates; | ||
1242 | size_t num_card_rates = sizeof(lbs_bg_rates); | ||
1243 | int ret = 0, i, j; | ||
1244 | u8 tmp[30]; | ||
1245 | size_t tmp_size = 0; | ||
1246 | |||
1247 | /* For each rate in card_rates that exists in rate1, copy to tmp */ | ||
1248 | for (i = 0; card_rates[i] && (i < num_card_rates); i++) { | ||
1249 | for (j = 0; rates[j] && (j < *rates_size); j++) { | ||
1250 | if (rates[j] == card_rates[i]) | ||
1251 | tmp[tmp_size++] = card_rates[i]; | ||
1252 | } | ||
1253 | } | ||
1254 | |||
1255 | lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); | ||
1256 | lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); | ||
1257 | lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); | ||
1258 | lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); | ||
1259 | |||
1260 | if (!priv->enablehwauto) { | ||
1261 | for (i = 0; i < tmp_size; i++) { | ||
1262 | if (tmp[i] == priv->cur_rate) | ||
1263 | goto done; | ||
1264 | } | ||
1265 | lbs_pr_alert("Previously set fixed data rate %#x isn't " | ||
1266 | "compatible with the network.\n", priv->cur_rate); | ||
1267 | ret = -1; | ||
1268 | goto done; | ||
1269 | } | ||
1270 | ret = 0; | ||
1271 | |||
1272 | done: | ||
1273 | memset(rates, 0, *rates_size); | ||
1274 | *rates_size = min_t(int, tmp_size, *rates_size); | ||
1275 | memcpy(rates, tmp, *rates_size); | ||
1276 | return ret; | ||
1277 | } | ||
1278 | |||
1279 | |||
1280 | /** | ||
1281 | * @brief Sets the MSB on basic rates as the firmware requires | ||
1282 | * | ||
1283 | * Scan through an array and set the MSB for basic data rates. | ||
1284 | * | ||
1285 | * @param rates buffer of data rates | ||
1286 | * @param len size of buffer | ||
1287 | */ | ||
1288 | static void lbs_set_basic_rate_flags(u8 *rates, size_t len) | ||
1289 | { | ||
1290 | int i; | ||
1291 | |||
1292 | for (i = 0; i < len; i++) { | ||
1293 | if (rates[i] == 0x02 || rates[i] == 0x04 || | ||
1294 | rates[i] == 0x0b || rates[i] == 0x16) | ||
1295 | rates[i] |= 0x80; | ||
1296 | } | ||
1297 | } | ||
1298 | |||
1299 | /** | ||
1300 | * @brief This function prepares command of authenticate. | 1470 | * @brief This function prepares command of authenticate. |
1301 | * | 1471 | * |
1302 | * @param priv A pointer to struct lbs_private structure | 1472 | * @param priv A pointer to struct lbs_private structure |
@@ -1495,231 +1665,6 @@ done: | |||
1495 | return ret; | 1665 | return ret; |
1496 | } | 1666 | } |
1497 | 1667 | ||
1498 | int lbs_cmd_80211_ad_hoc_start(struct lbs_private *priv, | ||
1499 | struct cmd_ds_command *cmd, void *pdata_buf) | ||
1500 | { | ||
1501 | struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads; | ||
1502 | int ret = 0; | ||
1503 | int cmdappendsize = 0; | ||
1504 | struct assoc_request *assoc_req = pdata_buf; | ||
1505 | u16 tmpcap = 0; | ||
1506 | size_t ratesize = 0; | ||
1507 | |||
1508 | lbs_deb_enter(LBS_DEB_JOIN); | ||
1509 | |||
1510 | if (!priv) { | ||
1511 | ret = -1; | ||
1512 | goto done; | ||
1513 | } | ||
1514 | |||
1515 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START); | ||
1516 | |||
1517 | /* | ||
1518 | * Fill in the parameters for 2 data structures: | ||
1519 | * 1. cmd_ds_802_11_ad_hoc_start command | ||
1520 | * 2. priv->scantable[i] | ||
1521 | * | ||
1522 | * Driver will fill up SSID, bsstype,IBSS param, Physical Param, | ||
1523 | * probe delay, and cap info. | ||
1524 | * | ||
1525 | * Firmware will fill up beacon period, DTIM, Basic rates | ||
1526 | * and operational rates. | ||
1527 | */ | ||
1528 | |||
1529 | memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE); | ||
1530 | memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len); | ||
1531 | |||
1532 | lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n", | ||
1533 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), | ||
1534 | assoc_req->ssid_len); | ||
1535 | |||
1536 | /* set the BSS type */ | ||
1537 | adhs->bsstype = CMD_BSS_TYPE_IBSS; | ||
1538 | priv->mode = IW_MODE_ADHOC; | ||
1539 | if (priv->beacon_period == 0) | ||
1540 | priv->beacon_period = MRVDRV_BEACON_INTERVAL; | ||
1541 | adhs->beaconperiod = cpu_to_le16(priv->beacon_period); | ||
1542 | |||
1543 | /* set Physical param set */ | ||
1544 | #define DS_PARA_IE_ID 3 | ||
1545 | #define DS_PARA_IE_LEN 1 | ||
1546 | |||
1547 | adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID; | ||
1548 | adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN; | ||
1549 | |||
1550 | WARN_ON(!assoc_req->channel); | ||
1551 | |||
1552 | lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n", | ||
1553 | assoc_req->channel); | ||
1554 | |||
1555 | adhs->phyparamset.dsparamset.currentchan = assoc_req->channel; | ||
1556 | |||
1557 | /* set IBSS param set */ | ||
1558 | #define IBSS_PARA_IE_ID 6 | ||
1559 | #define IBSS_PARA_IE_LEN 2 | ||
1560 | |||
1561 | adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID; | ||
1562 | adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN; | ||
1563 | adhs->ssparamset.ibssparamset.atimwindow = 0; | ||
1564 | |||
1565 | /* set capability info */ | ||
1566 | tmpcap = WLAN_CAPABILITY_IBSS; | ||
1567 | if (assoc_req->secinfo.wep_enabled) { | ||
1568 | lbs_deb_join("ADHOC_S_CMD: WEP enabled, " | ||
1569 | "setting privacy on\n"); | ||
1570 | tmpcap |= WLAN_CAPABILITY_PRIVACY; | ||
1571 | } else { | ||
1572 | lbs_deb_join("ADHOC_S_CMD: WEP disabled, " | ||
1573 | "setting privacy off\n"); | ||
1574 | } | ||
1575 | adhs->capability = cpu_to_le16(tmpcap); | ||
1576 | |||
1577 | /* probedelay */ | ||
1578 | adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | ||
1579 | |||
1580 | memset(adhs->rates, 0, sizeof(adhs->rates)); | ||
1581 | ratesize = min(sizeof(adhs->rates), sizeof(lbs_bg_rates)); | ||
1582 | memcpy(adhs->rates, lbs_bg_rates, ratesize); | ||
1583 | |||
1584 | /* Copy the ad-hoc creating rates into Current BSS state structure */ | ||
1585 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | ||
1586 | memcpy(&priv->curbssparams.rates, &adhs->rates, ratesize); | ||
1587 | |||
1588 | /* Set MSB on basic rates as the firmware requires, but _after_ | ||
1589 | * copying to current bss rates. | ||
1590 | */ | ||
1591 | lbs_set_basic_rate_flags(adhs->rates, ratesize); | ||
1592 | |||
1593 | lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n", | ||
1594 | adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]); | ||
1595 | |||
1596 | lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n"); | ||
1597 | |||
1598 | if (lbs_create_dnld_countryinfo_11d(priv)) { | ||
1599 | lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n"); | ||
1600 | ret = -1; | ||
1601 | goto done; | ||
1602 | } | ||
1603 | |||
1604 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) + | ||
1605 | S_DS_GEN + cmdappendsize); | ||
1606 | |||
1607 | ret = 0; | ||
1608 | done: | ||
1609 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | ||
1610 | return ret; | ||
1611 | } | ||
1612 | |||
1613 | int lbs_cmd_80211_ad_hoc_stop(struct cmd_ds_command *cmd) | ||
1614 | { | ||
1615 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP); | ||
1616 | cmd->size = cpu_to_le16(S_DS_GEN); | ||
1617 | |||
1618 | return 0; | ||
1619 | } | ||
1620 | |||
1621 | int lbs_cmd_80211_ad_hoc_join(struct lbs_private *priv, | ||
1622 | struct cmd_ds_command *cmd, void *pdata_buf) | ||
1623 | { | ||
1624 | struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj; | ||
1625 | struct assoc_request *assoc_req = pdata_buf; | ||
1626 | struct bss_descriptor *bss = &assoc_req->bss; | ||
1627 | int cmdappendsize = 0; | ||
1628 | int ret = 0; | ||
1629 | u16 ratesize = 0; | ||
1630 | DECLARE_MAC_BUF(mac); | ||
1631 | |||
1632 | lbs_deb_enter(LBS_DEB_JOIN); | ||
1633 | |||
1634 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN); | ||
1635 | |||
1636 | join_cmd->bss.type = CMD_BSS_TYPE_IBSS; | ||
1637 | join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod); | ||
1638 | |||
1639 | memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN); | ||
1640 | memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len); | ||
1641 | |||
1642 | memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset, | ||
1643 | sizeof(union ieeetypes_phyparamset)); | ||
1644 | |||
1645 | memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset, | ||
1646 | sizeof(union IEEEtypes_ssparamset)); | ||
1647 | |||
1648 | join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); | ||
1649 | lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", | ||
1650 | bss->capability, CAPINFO_MASK); | ||
1651 | |||
1652 | /* information on BSSID descriptor passed to FW */ | ||
1653 | lbs_deb_join( | ||
1654 | "ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n", | ||
1655 | print_mac(mac, join_cmd->bss.bssid), | ||
1656 | join_cmd->bss.ssid); | ||
1657 | |||
1658 | /* failtimeout */ | ||
1659 | join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); | ||
1660 | |||
1661 | /* probedelay */ | ||
1662 | join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | ||
1663 | |||
1664 | priv->curbssparams.channel = bss->channel; | ||
1665 | |||
1666 | /* Copy Data rates from the rates recorded in scan response */ | ||
1667 | memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates)); | ||
1668 | ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES); | ||
1669 | memcpy(join_cmd->bss.rates, bss->rates, ratesize); | ||
1670 | if (get_common_rates(priv, join_cmd->bss.rates, &ratesize)) { | ||
1671 | lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n"); | ||
1672 | ret = -1; | ||
1673 | goto done; | ||
1674 | } | ||
1675 | |||
1676 | /* Copy the ad-hoc creating rates into Current BSS state structure */ | ||
1677 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | ||
1678 | memcpy(&priv->curbssparams.rates, join_cmd->bss.rates, ratesize); | ||
1679 | |||
1680 | /* Set MSB on basic rates as the firmware requires, but _after_ | ||
1681 | * copying to current bss rates. | ||
1682 | */ | ||
1683 | lbs_set_basic_rate_flags(join_cmd->bss.rates, ratesize); | ||
1684 | |||
1685 | join_cmd->bss.ssparamset.ibssparamset.atimwindow = | ||
1686 | cpu_to_le16(bss->atimwindow); | ||
1687 | |||
1688 | if (assoc_req->secinfo.wep_enabled) { | ||
1689 | u16 tmp = le16_to_cpu(join_cmd->bss.capability); | ||
1690 | tmp |= WLAN_CAPABILITY_PRIVACY; | ||
1691 | join_cmd->bss.capability = cpu_to_le16(tmp); | ||
1692 | } | ||
1693 | |||
1694 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { | ||
1695 | /* wake up first */ | ||
1696 | __le32 Localpsmode; | ||
1697 | |||
1698 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); | ||
1699 | ret = lbs_prepare_and_send_command(priv, | ||
1700 | CMD_802_11_PS_MODE, | ||
1701 | CMD_ACT_SET, | ||
1702 | 0, 0, &Localpsmode); | ||
1703 | |||
1704 | if (ret) { | ||
1705 | ret = -1; | ||
1706 | goto done; | ||
1707 | } | ||
1708 | } | ||
1709 | |||
1710 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { | ||
1711 | ret = -1; | ||
1712 | goto done; | ||
1713 | } | ||
1714 | |||
1715 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) + | ||
1716 | S_DS_GEN + cmdappendsize); | ||
1717 | |||
1718 | done: | ||
1719 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | ||
1720 | return ret; | ||
1721 | } | ||
1722 | |||
1723 | int lbs_ret_80211_associate(struct lbs_private *priv, | 1668 | int lbs_ret_80211_associate(struct lbs_private *priv, |
1724 | struct cmd_ds_command *resp) | 1669 | struct cmd_ds_command *resp) |
1725 | { | 1670 | { |
@@ -1821,24 +1766,19 @@ done: | |||
1821 | return ret; | 1766 | return ret; |
1822 | } | 1767 | } |
1823 | 1768 | ||
1824 | int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv, | 1769 | static int lbs_adhoc_post(struct lbs_private *priv, struct cmd_header *resp) |
1825 | struct cmd_ds_command *resp) | ||
1826 | { | 1770 | { |
1827 | int ret = 0; | 1771 | int ret = 0; |
1828 | u16 command = le16_to_cpu(resp->command); | 1772 | u16 command = le16_to_cpu(resp->command); |
1829 | u16 result = le16_to_cpu(resp->result); | 1773 | u16 result = le16_to_cpu(resp->result); |
1830 | struct cmd_ds_802_11_ad_hoc_result *padhocresult; | 1774 | struct cmd_ds_802_11_ad_hoc_result *adhoc_resp; |
1831 | union iwreq_data wrqu; | 1775 | union iwreq_data wrqu; |
1832 | struct bss_descriptor *bss; | 1776 | struct bss_descriptor *bss; |
1833 | DECLARE_MAC_BUF(mac); | 1777 | DECLARE_MAC_BUF(mac); |
1834 | 1778 | ||
1835 | lbs_deb_enter(LBS_DEB_JOIN); | 1779 | lbs_deb_enter(LBS_DEB_JOIN); |
1836 | 1780 | ||
1837 | padhocresult = &resp->params.result; | 1781 | adhoc_resp = (struct cmd_ds_802_11_ad_hoc_result *) resp; |
1838 | |||
1839 | lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size)); | ||
1840 | lbs_deb_join("ADHOC_RESP: command = %x\n", command); | ||
1841 | lbs_deb_join("ADHOC_RESP: result = %x\n", result); | ||
1842 | 1782 | ||
1843 | if (!priv->in_progress_assoc_req) { | 1783 | if (!priv->in_progress_assoc_req) { |
1844 | lbs_deb_join("ADHOC_RESP: no in-progress association " | 1784 | lbs_deb_join("ADHOC_RESP: no in-progress association " |
@@ -1852,26 +1792,19 @@ int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv, | |||
1852 | * Join result code 0 --> SUCCESS | 1792 | * Join result code 0 --> SUCCESS |
1853 | */ | 1793 | */ |
1854 | if (result) { | 1794 | if (result) { |
1855 | lbs_deb_join("ADHOC_RESP: failed\n"); | 1795 | lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result); |
1856 | if (priv->connect_status == LBS_CONNECTED) | 1796 | if (priv->connect_status == LBS_CONNECTED) |
1857 | lbs_mac_event_disconnected(priv); | 1797 | lbs_mac_event_disconnected(priv); |
1858 | ret = -1; | 1798 | ret = -1; |
1859 | goto done; | 1799 | goto done; |
1860 | } | 1800 | } |
1861 | 1801 | ||
1862 | /* | ||
1863 | * Now the join cmd should be successful | ||
1864 | * If BSSID has changed use SSID to compare instead of BSSID | ||
1865 | */ | ||
1866 | lbs_deb_join("ADHOC_RESP: associated to '%s'\n", | ||
1867 | escape_essid(bss->ssid, bss->ssid_len)); | ||
1868 | |||
1869 | /* Send a Media Connected event, according to the Spec */ | 1802 | /* Send a Media Connected event, according to the Spec */ |
1870 | priv->connect_status = LBS_CONNECTED; | 1803 | priv->connect_status = LBS_CONNECTED; |
1871 | 1804 | ||
1872 | if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { | 1805 | if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { |
1873 | /* Update the created network descriptor with the new BSSID */ | 1806 | /* Update the created network descriptor with the new BSSID */ |
1874 | memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN); | 1807 | memcpy(bss->bssid, adhoc_resp->bssid, ETH_ALEN); |
1875 | } | 1808 | } |
1876 | 1809 | ||
1877 | /* Set the BSSID from the joined/started descriptor */ | 1810 | /* Set the BSSID from the joined/started descriptor */ |
@@ -1890,22 +1823,13 @@ int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv, | |||
1890 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | 1823 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
1891 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | 1824 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
1892 | 1825 | ||
1893 | lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n"); | 1826 | lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %s, channel %d\n", |
1894 | lbs_deb_join("ADHOC_RESP: channel = %d\n", priv->curbssparams.channel); | 1827 | escape_essid(bss->ssid, bss->ssid_len), |
1895 | lbs_deb_join("ADHOC_RESP: BSSID = %s\n", | 1828 | print_mac(mac, priv->curbssparams.bssid), |
1896 | print_mac(mac, padhocresult->bssid)); | 1829 | priv->curbssparams.channel); |
1897 | 1830 | ||
1898 | done: | 1831 | done: |
1899 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | 1832 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
1900 | return ret; | 1833 | return ret; |
1901 | } | 1834 | } |
1902 | 1835 | ||
1903 | int lbs_ret_80211_ad_hoc_stop(struct lbs_private *priv) | ||
1904 | { | ||
1905 | lbs_deb_enter(LBS_DEB_JOIN); | ||
1906 | |||
1907 | lbs_mac_event_disconnected(priv); | ||
1908 | |||
1909 | lbs_deb_leave(LBS_DEB_JOIN); | ||
1910 | return 0; | ||
1911 | } | ||