blob: 526b0b9db944c36205706809746f65b0556576d4 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * Functions implementing wlan infrastructure and adhoc join routines,
3 * IOCTL handlers as well as command preperation and response routines
4 * for sending adhoc start, adhoc join, and association commands
5 * to the firmware.
6 */
7#include <linux/netdevice.h>
8#include <linux/if_arp.h>
9#include <linux/wireless.h>
Dan Williamse76850d2007-05-25 17:09:41 -040010#include <linux/etherdevice.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011
12#include <net/iw_handler.h>
13
14#include "host.h"
15#include "decl.h"
16#include "join.h"
17#include "dev.h"
Dan Williamse76850d2007-05-25 17:09:41 -040018#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019
20/**
21 * @brief This function finds out the common rates between rate1 and rate2.
22 *
23 * It will fill common rates in rate1 as output if found.
24 *
25 * NOTE: Setting the MSB of the basic rates need to be taken
26 * care, either before or after calling this function
27 *
28 * @param adapter A pointer to wlan_adapter structure
29 * @param rate1 the buffer which keeps input and output
30 * @param rate1_size the size of rate1 buffer
31 * @param rate2 the buffer which keeps rate2
32 * @param rate2_size the size of rate2 buffer.
33 *
34 * @return 0 or -1
35 */
36static int get_common_rates(wlan_adapter * adapter, u8 * rate1,
37 int rate1_size, u8 * rate2, int rate2_size)
38{
39 u8 *ptr = rate1;
40 int ret = 0;
41 u8 tmp[30];
42 int i;
43
44 memset(&tmp, 0, sizeof(tmp));
45 memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
46 memset(rate1, 0, rate1_size);
47
48 /* Mask the top bit of the original values */
49 for (i = 0; tmp[i] && i < sizeof(tmp); i++)
50 tmp[i] &= 0x7F;
51
52 for (i = 0; rate2[i] && i < rate2_size; i++) {
53 /* Check for Card Rate in tmp, excluding the top bit */
54 if (strchr(tmp, rate2[i] & 0x7F)) {
55 /* values match, so copy the Card Rate to rate1 */
56 *rate1++ = rate2[i];
57 }
58 }
59
60 lbs_dbg_hex("rate1 (AP) rates:", tmp, sizeof(tmp));
61 lbs_dbg_hex("rate2 (Card) rates:", rate2, rate2_size);
62 lbs_dbg_hex("Common rates:", ptr, rate1_size);
Holger Schurig9012b282007-05-25 11:27:16 -040063 lbs_deb_join("Tx datarate is set to 0x%X\n", adapter->datarate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064
65 if (!adapter->is_datarate_auto) {
66 while (*ptr) {
67 if ((*ptr & 0x7f) == adapter->datarate) {
68 ret = 0;
69 goto done;
70 }
71 ptr++;
72 }
73 lbs_pr_alert( "Previously set fixed data rate %#x isn't "
74 "compatible with the network.\n", adapter->datarate);
75
76 ret = -1;
77 goto done;
78 }
79
80 ret = 0;
81done:
82 return ret;
83}
84
85int libertas_send_deauth(wlan_private * priv)
86{
87 wlan_adapter *adapter = priv->adapter;
88 int ret = 0;
89
Dan Williams0dc5a292007-05-10 22:58:02 -040090 if (adapter->mode == IW_MODE_INFRA &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091 adapter->connect_status == libertas_connected)
92 ret = libertas_send_deauthentication(priv);
93 else
94 ret = -ENOTSUPP;
95
96 return ret;
97}
98
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099/**
100 * @brief Associate to a specific BSS discovered in a scan
101 *
102 * @param priv A pointer to wlan_private structure
103 * @param pbssdesc Pointer to the BSS descriptor to associate with.
104 *
105 * @return 0-success, otherwise fail
106 */
Dan Williamse76850d2007-05-25 17:09:41 -0400107int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108{
109 wlan_adapter *adapter = priv->adapter;
110 int ret;
111
Holger Schurig9012b282007-05-25 11:27:16 -0400112 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113
114 ret = libertas_prepare_and_send_command(priv, cmd_802_11_authenticate,
115 0, cmd_option_waitforrsp,
Dan Williamse76850d2007-05-25 17:09:41 -0400116 0, assoc_req->bss.bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117
Holger Schurig9012b282007-05-25 11:27:16 -0400118 if (ret)
119 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120
121 /* set preamble to firmware */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400122 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
123 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124 adapter->preamble = cmd_type_short_preamble;
125 else
126 adapter->preamble = cmd_type_long_preamble;
127
128 libertas_set_radio_control(priv);
129
130 ret = libertas_prepare_and_send_command(priv, cmd_802_11_associate,
Dan Williamse76850d2007-05-25 17:09:41 -0400131 0, cmd_option_waitforrsp, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132
Holger Schurig9012b282007-05-25 11:27:16 -0400133done:
134 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135 return ret;
136}
137
138/**
139 * @brief Start an Adhoc Network
140 *
141 * @param priv A pointer to wlan_private structure
142 * @param adhocssid The ssid of the Adhoc Network
143 * @return 0--success, -1--fail
144 */
Dan Williamse76850d2007-05-25 17:09:41 -0400145int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146{
147 wlan_adapter *adapter = priv->adapter;
148 int ret = 0;
149
150 adapter->adhoccreate = 1;
151
Dan Williams0c9ca6902007-08-02 10:43:44 -0400152 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400153 lbs_deb_join("AdhocStart: Short preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 adapter->preamble = cmd_type_short_preamble;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400155 } else {
156 lbs_deb_join("AdhocStart: Long preamble\n");
157 adapter->preamble = cmd_type_long_preamble;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 }
159
160 libertas_set_radio_control(priv);
161
Dan Williamse76850d2007-05-25 17:09:41 -0400162 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
163 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164
165 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
Dan Williamse76850d2007-05-25 17:09:41 -0400166 0, cmd_option_waitforrsp, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167
168 return ret;
169}
170
171/**
172 * @brief Join an adhoc network found in a previous scan
173 *
174 * @param priv A pointer to wlan_private structure
175 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
176 * to attempt to join
177 *
178 * @return 0--success, -1--fail
179 */
Dan Williamse76850d2007-05-25 17:09:41 -0400180int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181{
182 wlan_adapter *adapter = priv->adapter;
Dan Williamse76850d2007-05-25 17:09:41 -0400183 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184 int ret = 0;
185
Dan Williamsd8efea22007-05-28 23:54:55 -0400186 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
187 __func__,
188 escape_essid(adapter->curbssparams.ssid,
189 adapter->curbssparams.ssid_len),
190 adapter->curbssparams.ssid_len);
191 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
192 __func__, escape_essid(bss->ssid, bss->ssid_len),
193 bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194
195 /* check if the requested SSID is already joined */
Dan Williamsd8efea22007-05-28 23:54:55 -0400196 if (adapter->curbssparams.ssid_len
Dan Williams717c9332007-05-29 00:03:31 -0400197 && !libertas_ssid_cmp(adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400198 adapter->curbssparams.ssid_len,
199 bss->ssid, bss->ssid_len)
Dan Williams0dc5a292007-05-10 22:58:02 -0400200 && (adapter->mode == IW_MODE_ADHOC)) {
Dan Williamse76850d2007-05-25 17:09:41 -0400201 lbs_deb_join(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
203 "not attempting to re-join");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 return -1;
205 }
206
Dan Williams0c9ca6902007-08-02 10:43:44 -0400207 /* Use shortpreamble only when both creator and card supports
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208 short preamble */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400209 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
210 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400211 lbs_deb_join("AdhocJoin: Long preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212 adapter->preamble = cmd_type_long_preamble;
213 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400214 lbs_deb_join("AdhocJoin: Short preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215 adapter->preamble = cmd_type_short_preamble;
216 }
217
218 libertas_set_radio_control(priv);
219
Dan Williamse76850d2007-05-25 17:09:41 -0400220 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
221 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222
223 adapter->adhoccreate = 0;
224
225 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_join,
226 0, cmd_option_waitforrsp,
Dan Williamse76850d2007-05-25 17:09:41 -0400227 OID_802_11_SSID, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228
229 return ret;
230}
231
232int libertas_stop_adhoc_network(wlan_private * priv)
233{
234 return libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_stop,
235 0, cmd_option_waitforrsp, 0, NULL);
236}
237
238/**
239 * @brief Send Deauthentication Request
240 *
241 * @param priv A pointer to wlan_private structure
242 * @return 0--success, -1--fail
243 */
244int libertas_send_deauthentication(wlan_private * priv)
245{
246 return libertas_prepare_and_send_command(priv, cmd_802_11_deauthenticate,
247 0, cmd_option_waitforrsp, 0, NULL);
248}
249
250/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 * @brief This function prepares command of authenticate.
252 *
253 * @param priv A pointer to wlan_private structure
254 * @param cmd A pointer to cmd_ds_command structure
255 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
256 *
257 * @return 0 or -1
258 */
259int libertas_cmd_80211_authenticate(wlan_private * priv,
260 struct cmd_ds_command *cmd,
261 void *pdata_buf)
262{
263 wlan_adapter *adapter = priv->adapter;
Dan Williams6affe782007-05-10 22:56:42 -0400264 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
265 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266 u8 *bssid = pdata_buf;
267
Dan Williams45f43de2007-05-25 22:58:55 -0400268 lbs_deb_enter(LBS_DEB_JOIN);
269
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270 cmd->command = cpu_to_le16(cmd_802_11_authenticate);
Dan Williams6affe782007-05-10 22:56:42 -0400271 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
272 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273
Dan Williams6affe782007-05-10 22:56:42 -0400274 /* translate auth mode to 802.11 defined wire value */
275 switch (adapter->secinfo.auth_mode) {
276 case IW_AUTH_ALG_OPEN_SYSTEM:
277 pauthenticate->authtype = 0x00;
278 break;
279 case IW_AUTH_ALG_SHARED_KEY:
280 pauthenticate->authtype = 0x01;
281 break;
282 case IW_AUTH_ALG_LEAP:
283 pauthenticate->authtype = 0x80;
284 break;
285 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400286 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
Dan Williams6affe782007-05-10 22:56:42 -0400287 adapter->secinfo.auth_mode);
288 goto out;
289 }
290
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
292
Dan Williams45f43de2007-05-25 22:58:55 -0400293 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
294 MAC_ARG(bssid), pauthenticate->authtype);
Dan Williams6affe782007-05-10 22:56:42 -0400295 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296
Dan Williams6affe782007-05-10 22:56:42 -0400297out:
Dan Williams45f43de2007-05-25 22:58:55 -0400298 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Dan Williams6affe782007-05-10 22:56:42 -0400299 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300}
301
302int libertas_cmd_80211_deauthenticate(wlan_private * priv,
303 struct cmd_ds_command *cmd)
304{
305 wlan_adapter *adapter = priv->adapter;
306 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
307
Holger Schurig9012b282007-05-25 11:27:16 -0400308 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309
310 cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
David Woodhouse981f1872007-05-25 23:36:54 -0400311 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312 S_DS_GEN);
313
314 /* set AP MAC address */
David Woodhouse981f1872007-05-25 23:36:54 -0400315 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316
317 /* Reason code 3 = Station is leaving */
318#define REASON_CODE_STA_LEAVING 3
319 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
320
Holger Schurig9012b282007-05-25 11:27:16 -0400321 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322 return 0;
323}
324
325int libertas_cmd_80211_associate(wlan_private * priv,
326 struct cmd_ds_command *cmd, void *pdata_buf)
327{
328 wlan_adapter *adapter = priv->adapter;
329 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
330 int ret = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400331 struct assoc_request * assoc_req = pdata_buf;
332 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333 u8 *card_rates;
334 u8 *pos;
335 int card_rates_size;
David Woodhouse981f1872007-05-25 23:36:54 -0400336 u16 tmpcap, tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 struct mrvlietypes_ssidparamset *ssid;
338 struct mrvlietypes_phyparamset *phy;
339 struct mrvlietypes_ssparamset *ss;
340 struct mrvlietypes_ratesparamset *rates;
341 struct mrvlietypes_rsnparamset *rsn;
342
Holger Schurig9012b282007-05-25 11:27:16 -0400343 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345 pos = (u8 *) passo;
346
347 if (!adapter) {
348 ret = -1;
349 goto done;
350 }
351
352 cmd->command = cpu_to_le16(cmd_802_11_associate);
353
Dan Williamse76850d2007-05-25 17:09:41 -0400354 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200355 pos += sizeof(passo->peerstaaddr);
356
357 /* set the listen interval */
David Woodhouse981f1872007-05-25 23:36:54 -0400358 passo->listeninterval = cpu_to_le16(adapter->listeninterval);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359
Dan Williams0c9ca6902007-08-02 10:43:44 -0400360 pos += sizeof(passo->capability);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361 pos += sizeof(passo->listeninterval);
362 pos += sizeof(passo->bcnperiod);
363 pos += sizeof(passo->dtimperiod);
364
365 ssid = (struct mrvlietypes_ssidparamset *) pos;
366 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
Dan Williamsd8efea22007-05-28 23:54:55 -0400367 tmplen = bss->ssid_len;
David Woodhouse707985b2007-05-25 23:41:16 -0400368 ssid->header.len = cpu_to_le16(tmplen);
Dan Williamsd8efea22007-05-28 23:54:55 -0400369 memcpy(ssid->ssid, bss->ssid, tmplen);
David Woodhouse707985b2007-05-25 23:41:16 -0400370 pos += sizeof(ssid->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371
372 phy = (struct mrvlietypes_phyparamset *) pos;
373 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
David Woodhouse707985b2007-05-25 23:41:16 -0400374 tmplen = sizeof(phy->fh_ds.dsparamset);
375 phy->header.len = cpu_to_le16(tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 memcpy(&phy->fh_ds.dsparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400377 &bss->phyparamset.dsparamset.currentchan,
David Woodhouse707985b2007-05-25 23:41:16 -0400378 tmplen);
379 pos += sizeof(phy->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
381 ss = (struct mrvlietypes_ssparamset *) pos;
382 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
David Woodhouse707985b2007-05-25 23:41:16 -0400383 tmplen = sizeof(ss->cf_ibss.cfparamset);
384 ss->header.len = cpu_to_le16(tmplen);
385 pos += sizeof(ss->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386
387 rates = (struct mrvlietypes_ratesparamset *) pos;
388 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
389
Dan Williamse76850d2007-05-25 17:09:41 -0400390 memcpy(&rates->rates, &bss->libertas_supported_rates, WLAN_SUPPORTED_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391
392 card_rates = libertas_supported_rates;
393 card_rates_size = sizeof(libertas_supported_rates);
394
395 if (get_common_rates(adapter, rates->rates, WLAN_SUPPORTED_RATES,
396 card_rates, card_rates_size)) {
397 ret = -1;
398 goto done;
399 }
400
David Woodhouse981f1872007-05-25 23:36:54 -0400401 tmplen = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
402 adapter->curbssparams.numofrates = tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403
David Woodhouse981f1872007-05-25 23:36:54 -0400404 pos += sizeof(rates->header) + tmplen;
405 rates->header.len = cpu_to_le16(tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406
Dan Williamse76850d2007-05-25 17:09:41 -0400407 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408 rsn = (struct mrvlietypes_rsnparamset *) pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400409 /* WPA_IE or WPA2_IE */
410 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
411 tmplen = (u16) assoc_req->wpa_ie[1];
412 rsn->header.len = cpu_to_le16(tmplen);
413 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414 lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
David Woodhouse981f1872007-05-25 23:36:54 -0400415 sizeof(rsn->header) + tmplen);
416 pos += sizeof(rsn->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417 }
418
419 /* update curbssparams */
David Woodhouse981f1872007-05-25 23:36:54 -0400420 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421
422 /* Copy the infra. association rates into Current BSS state structure */
423 memcpy(&adapter->curbssparams.datarates, &rates->rates,
David Woodhouse981f1872007-05-25 23:36:54 -0400424 min_t(size_t, sizeof(adapter->curbssparams.datarates),
425 cpu_to_le16(rates->header.len)));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426
David Woodhouse981f1872007-05-25 23:36:54 -0400427 lbs_deb_join("ASSOC_CMD: rates->header.len = %d\n",
428 cpu_to_le16(rates->header.len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429
Dan Williamse76850d2007-05-25 17:09:41 -0400430 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 ret = -1;
432 goto done;
433 }
434
435 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
436
Dan Williams0c9ca6902007-08-02 10:43:44 -0400437 /* set the capability info */
438 tmpcap = (bss->capability & CAPINFO_MASK);
439 if (bss->mode == IW_MODE_INFRA)
440 tmpcap |= WLAN_CAPABILITY_ESS;
441 passo->capability = cpu_to_le16(tmpcap);
442 lbs_deb_join("ASSOC_CMD: capability=%4X CAPINFO_MASK=%4X\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400443 tmpcap, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444
Holger Schurig9012b282007-05-25 11:27:16 -0400445done:
446 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 return ret;
448}
449
450int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400451 struct cmd_ds_command *cmd, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452{
453 wlan_adapter *adapter = priv->adapter;
454 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
455 int ret = 0;
456 int cmdappendsize = 0;
457 int i;
Dan Williamse76850d2007-05-25 17:09:41 -0400458 struct assoc_request * assoc_req = pdata_buf;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400459 u16 tmpcap = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460
Holger Schurig9012b282007-05-25 11:27:16 -0400461 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462
463 if (!adapter) {
464 ret = -1;
465 goto done;
466 }
467
468 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
469
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470 /*
471 * Fill in the parameters for 2 data structures:
472 * 1. cmd_ds_802_11_ad_hoc_start command
473 * 2. adapter->scantable[i]
474 *
475 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
476 * probe delay, and cap info.
477 *
478 * Firmware will fill up beacon period, DTIM, Basic rates
479 * and operational rates.
480 */
481
482 memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
Dan Williamsd8efea22007-05-28 23:54:55 -0400483 memcpy(adhs->SSID, assoc_req->ssid, assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484
Dan Williamsd8efea22007-05-28 23:54:55 -0400485 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
486 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
487 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489 /* set the BSS type */
490 adhs->bsstype = cmd_bss_type_ibss;
Dan Williamse76850d2007-05-25 17:09:41 -0400491 adapter->mode = IW_MODE_ADHOC;
David Woodhouse981f1872007-05-25 23:36:54 -0400492 adhs->beaconperiod = cpu_to_le16(adapter->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200493
494 /* set Physical param set */
495#define DS_PARA_IE_ID 3
496#define DS_PARA_IE_LEN 1
497
498 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
499 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
500
Dan Williamse76850d2007-05-25 17:09:41 -0400501 WARN_ON(!assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502
Holger Schurig9012b282007-05-25 11:27:16 -0400503 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400504 assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505
Dan Williamse76850d2007-05-25 17:09:41 -0400506 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
508 /* set IBSS param set */
509#define IBSS_PARA_IE_ID 6
510#define IBSS_PARA_IE_LEN 2
511
512 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
513 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
David Woodhouse981f1872007-05-25 23:36:54 -0400514 adhs->ssparamset.ibssparamset.atimwindow = cpu_to_le16(adapter->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200515
516 /* set capability info */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400517 tmpcap = WLAN_CAPABILITY_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400518 if (assoc_req->secinfo.wep_enabled) {
Holger Schurig9012b282007-05-25 11:27:16 -0400519 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
Dan Williams0c9ca6902007-08-02 10:43:44 -0400520 tmpcap |= WLAN_CAPABILITY_PRIVACY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400522 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523 }
Dan Williams0c9ca6902007-08-02 10:43:44 -0400524 adhs->capability = cpu_to_le16(tmpcap);
525
526 /* probedelay */
527 adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528
529 memset(adhs->datarate, 0, sizeof(adhs->datarate));
530
531 if (adapter->adhoc_grate_enabled) {
532 memcpy(adhs->datarate, libertas_adhoc_rates_g,
533 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_g)));
534 } else {
535 memcpy(adhs->datarate, libertas_adhoc_rates_b,
536 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_b)));
537 }
538
539 /* Find the last non zero */
540 for (i = 0; i < sizeof(adhs->datarate) && adhs->datarate[i]; i++) ;
541
542 adapter->curbssparams.numofrates = i;
543
544 /* Copy the ad-hoc creating rates into Current BSS state structure */
545 memcpy(&adapter->curbssparams.datarates,
546 &adhs->datarate, adapter->curbssparams.numofrates);
547
Holger Schurig9012b282007-05-25 11:27:16 -0400548 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549 adhs->datarate[0], adhs->datarate[1],
550 adhs->datarate[2], adhs->datarate[3]);
551
Holger Schurig9012b282007-05-25 11:27:16 -0400552 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553
554 if (libertas_create_dnld_countryinfo_11d(priv)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400555 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556 ret = -1;
557 goto done;
558 }
559
David Woodhouse981f1872007-05-25 23:36:54 -0400560 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
561 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200562
563 ret = 0;
564done:
Holger Schurig9012b282007-05-25 11:27:16 -0400565 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200566 return ret;
567}
568
569int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
570 struct cmd_ds_command *cmd)
571{
572 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_stop);
573 cmd->size = cpu_to_le16(S_DS_GEN);
574
575 return 0;
576}
577
578int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
579 struct cmd_ds_command *cmd, void *pdata_buf)
580{
581 wlan_adapter *adapter = priv->adapter;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400582 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
Dan Williamse76850d2007-05-25 17:09:41 -0400583 struct assoc_request * assoc_req = pdata_buf;
584 struct bss_descriptor *bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585 int cmdappendsize = 0;
586 int ret = 0;
587 u8 *card_rates;
588 int card_rates_size;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 int i;
590
Holger Schurig9012b282007-05-25 11:27:16 -0400591 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200592
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
594
Dan Williams0c9ca6902007-08-02 10:43:44 -0400595 join_cmd->bss.type = cmd_bss_type_ibss;
596 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597
Dan Williams0c9ca6902007-08-02 10:43:44 -0400598 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
599 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600
Dan Williams0c9ca6902007-08-02 10:43:44 -0400601 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
602 sizeof(union ieeetypes_phyparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603
Dan Williams0c9ca6902007-08-02 10:43:44 -0400604 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
605 sizeof(union IEEEtypes_ssparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606
Dan Williams0c9ca6902007-08-02 10:43:44 -0400607 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
Holger Schurig9012b282007-05-25 11:27:16 -0400608 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400609 bss->capability, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610
611 /* information on BSSID descriptor passed to FW */
Dan Williamse76850d2007-05-25 17:09:41 -0400612 lbs_deb_join(
613 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400614 MAC_ARG(join_cmd->bss.bssid), join_cmd->bss.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 /* failtimeout */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400617 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618
619 /* probedelay */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400620 join_cmd->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621
622 /* Copy Data rates from the rates recorded in scan response */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400623 memset(join_cmd->bss.datarates, 0, sizeof(join_cmd->bss.datarates));
624 memcpy(join_cmd->bss.datarates, bss->datarates,
625 min(sizeof(join_cmd->bss.datarates), sizeof(bss->datarates)));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626
627 card_rates = libertas_supported_rates;
628 card_rates_size = sizeof(libertas_supported_rates);
629
Dan Williamse76850d2007-05-25 17:09:41 -0400630 adapter->curbssparams.channel = bss->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631
Dan Williams0c9ca6902007-08-02 10:43:44 -0400632 if (get_common_rates(adapter, join_cmd->bss.datarates,
633 sizeof(join_cmd->bss.datarates),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634 card_rates, card_rates_size)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400635 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200636 ret = -1;
637 goto done;
638 }
639
640 /* Find the last non zero */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400641 for (i = 0; i < sizeof(join_cmd->bss.datarates)
642 && join_cmd->bss.datarates[i]; i++) ;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643
644 adapter->curbssparams.numofrates = i;
645
646 /*
647 * Copy the adhoc joining rates to Current BSS State structure
648 */
649 memcpy(adapter->curbssparams.datarates,
Dan Williams0c9ca6902007-08-02 10:43:44 -0400650 join_cmd->bss.datarates,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651 adapter->curbssparams.numofrates);
652
Dan Williams0c9ca6902007-08-02 10:43:44 -0400653 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
Dan Williamse76850d2007-05-25 17:09:41 -0400654 cpu_to_le16(bss->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655
Dan Williamse76850d2007-05-25 17:09:41 -0400656 if (assoc_req->secinfo.wep_enabled) {
Dan Williams0c9ca6902007-08-02 10:43:44 -0400657 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
658 tmp |= WLAN_CAPABILITY_PRIVACY;
659 join_cmd->bss.capability = cpu_to_le16(tmp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660 }
661
662 if (adapter->psmode == wlan802_11powermodemax_psp) {
663 /* wake up first */
David Woodhouse981f1872007-05-25 23:36:54 -0400664 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665
David Woodhouse981f1872007-05-25 23:36:54 -0400666 Localpsmode = cpu_to_le32(wlan802_11powermodecam);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200667 ret = libertas_prepare_and_send_command(priv,
668 cmd_802_11_ps_mode,
669 cmd_act_set,
670 0, 0, &Localpsmode);
671
672 if (ret) {
673 ret = -1;
674 goto done;
675 }
676 }
677
Dan Williamse76850d2007-05-25 17:09:41 -0400678 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200679 ret = -1;
680 goto done;
681 }
682
David Woodhouse981f1872007-05-25 23:36:54 -0400683 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
684 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200685
Holger Schurig9012b282007-05-25 11:27:16 -0400686done:
687 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200688 return ret;
689}
690
691int libertas_ret_80211_associate(wlan_private * priv,
692 struct cmd_ds_command *resp)
693{
694 wlan_adapter *adapter = priv->adapter;
695 int ret = 0;
696 union iwreq_data wrqu;
697 struct ieeetypes_assocrsp *passocrsp;
Dan Williamse76850d2007-05-25 17:09:41 -0400698 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200699
Holger Schurig9012b282007-05-25 11:27:16 -0400700 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701
Dan Williamse76850d2007-05-25 17:09:41 -0400702 if (!adapter->in_progress_assoc_req) {
703 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
704 ret = -1;
705 goto done;
706 }
707 bss = &adapter->in_progress_assoc_req->bss;
708
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
710
David Woodhouse981f1872007-05-25 23:36:54 -0400711 if (le16_to_cpu(passocrsp->statuscode)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200712 libertas_mac_event_disconnected(priv);
713
Dan Williamse76850d2007-05-25 17:09:41 -0400714 lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400715 le16_to_cpu(passocrsp->statuscode));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716
717 ret = -1;
718 goto done;
719 }
720
721 lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
722 le16_to_cpu(resp->size) - S_DS_GEN);
723
724 /* Send a Media Connected event, according to the Spec */
725 adapter->connect_status = libertas_connected;
726
Dan Williamsd8efea22007-05-28 23:54:55 -0400727 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
728 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729
Dan Williamse76850d2007-05-25 17:09:41 -0400730 /* Update current SSID and BSSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400731 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
732 adapter->curbssparams.ssid_len = bss->ssid_len;
Dan Williamse76850d2007-05-25 17:09:41 -0400733 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734
Holger Schurig9012b282007-05-25 11:27:16 -0400735 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200736 adapter->currentpacketfilter);
737
738 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
739 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
740
741 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
742 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
743 adapter->nextSNRNF = 0;
744 adapter->numSNRNF = 0;
745
Holger Schurig634b8f42007-05-25 13:05:16 -0400746 netif_carrier_on(priv->dev);
747 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748
Javier Cardona51d84f52007-05-25 12:06:56 -0400749 netif_carrier_on(priv->mesh_dev);
750 netif_wake_queue(priv->mesh_dev);
751
Holger Schurig9012b282007-05-25 11:27:16 -0400752 lbs_deb_join("ASSOC_RESP: Associated \n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753
754 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
755 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400756 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757
Holger Schurig9012b282007-05-25 11:27:16 -0400758done:
759 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760 return ret;
761}
762
763int libertas_ret_80211_disassociate(wlan_private * priv,
764 struct cmd_ds_command *resp)
765{
Holger Schurig9012b282007-05-25 11:27:16 -0400766 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200767
768 libertas_mac_event_disconnected(priv);
769
Holger Schurig9012b282007-05-25 11:27:16 -0400770 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771 return 0;
772}
773
774int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
775 struct cmd_ds_command *resp)
776{
777 wlan_adapter *adapter = priv->adapter;
778 int ret = 0;
779 u16 command = le16_to_cpu(resp->command);
780 u16 result = le16_to_cpu(resp->result);
781 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
782 union iwreq_data wrqu;
Dan Williamse76850d2007-05-25 17:09:41 -0400783 struct bss_descriptor *bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200784
Holger Schurig9012b282007-05-25 11:27:16 -0400785 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786
787 padhocresult = &resp->params.result;
788
Dan Williamse76850d2007-05-25 17:09:41 -0400789 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
790 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
791 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792
Dan Williamse76850d2007-05-25 17:09:41 -0400793 if (!adapter->in_progress_assoc_req) {
794 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
795 ret = -1;
796 goto done;
797 }
798 bss = &adapter->in_progress_assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799
800 /*
801 * Join result code 0 --> SUCCESS
802 */
803 if (result) {
Dan Williamse76850d2007-05-25 17:09:41 -0400804 lbs_deb_join("ADHOC_RESP: failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805 if (adapter->connect_status == libertas_connected) {
806 libertas_mac_event_disconnected(priv);
807 }
Holger Schurig9012b282007-05-25 11:27:16 -0400808 ret = -1;
809 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200810 }
811
812 /*
813 * Now the join cmd should be successful
814 * If BSSID has changed use SSID to compare instead of BSSID
815 */
Dan Williamsd8efea22007-05-28 23:54:55 -0400816 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
817 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818
819 /* Send a Media Connected event, according to the Spec */
820 adapter->connect_status = libertas_connected;
821
822 if (command == cmd_ret_802_11_ad_hoc_start) {
823 /* Update the created network descriptor with the new BSSID */
Dan Williamsea8da922007-08-02 11:18:23 -0400824 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825 }
826
827 /* Set the BSSID from the joined/started descriptor */
Dan Williamse76850d2007-05-25 17:09:41 -0400828 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200829
830 /* Set the new SSID to current SSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400831 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
832 adapter->curbssparams.ssid_len = bss->ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833
Holger Schurig634b8f42007-05-25 13:05:16 -0400834 netif_carrier_on(priv->dev);
835 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836
Javier Cardona51d84f52007-05-25 12:06:56 -0400837 netif_carrier_on(priv->mesh_dev);
838 netif_wake_queue(priv->mesh_dev);
839
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840 memset(&wrqu, 0, sizeof(wrqu));
841 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
842 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400843 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200844
Holger Schurig9012b282007-05-25 11:27:16 -0400845 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400846 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
Dan Williams02eb2292007-05-25 17:27:31 -0400847 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
848 MAC_ARG(padhocresult->BSSID));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200849
Holger Schurig9012b282007-05-25 11:27:16 -0400850done:
851 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200852 return ret;
853}
854
855int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
856 struct cmd_ds_command *resp)
857{
Holger Schurig9012b282007-05-25 11:27:16 -0400858 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859
860 libertas_mac_event_disconnected(priv);
861
Holger Schurig9012b282007-05-25 11:27:16 -0400862 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863 return 0;
864}