blob: f222e78a922c8dc409cb17fa3ae475ab985b614d [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
Dan Williams889c05b2007-05-10 22:57:23 -040020#define AD_HOC_CAP_PRIVACY_ON 1
21
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022/**
23 * @brief This function finds out the common rates between rate1 and rate2.
24 *
25 * It will fill common rates in rate1 as output if found.
26 *
27 * NOTE: Setting the MSB of the basic rates need to be taken
28 * care, either before or after calling this function
29 *
30 * @param adapter A pointer to wlan_adapter structure
31 * @param rate1 the buffer which keeps input and output
32 * @param rate1_size the size of rate1 buffer
33 * @param rate2 the buffer which keeps rate2
34 * @param rate2_size the size of rate2 buffer.
35 *
36 * @return 0 or -1
37 */
38static int get_common_rates(wlan_adapter * adapter, u8 * rate1,
39 int rate1_size, u8 * rate2, int rate2_size)
40{
41 u8 *ptr = rate1;
42 int ret = 0;
43 u8 tmp[30];
44 int i;
45
46 memset(&tmp, 0, sizeof(tmp));
47 memcpy(&tmp, rate1, min_t(size_t, rate1_size, sizeof(tmp)));
48 memset(rate1, 0, rate1_size);
49
50 /* Mask the top bit of the original values */
51 for (i = 0; tmp[i] && i < sizeof(tmp); i++)
52 tmp[i] &= 0x7F;
53
54 for (i = 0; rate2[i] && i < rate2_size; i++) {
55 /* Check for Card Rate in tmp, excluding the top bit */
56 if (strchr(tmp, rate2[i] & 0x7F)) {
57 /* values match, so copy the Card Rate to rate1 */
58 *rate1++ = rate2[i];
59 }
60 }
61
62 lbs_dbg_hex("rate1 (AP) rates:", tmp, sizeof(tmp));
63 lbs_dbg_hex("rate2 (Card) rates:", rate2, rate2_size);
64 lbs_dbg_hex("Common rates:", ptr, rate1_size);
Holger Schurig9012b282007-05-25 11:27:16 -040065 lbs_deb_join("Tx datarate is set to 0x%X\n", adapter->datarate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066
67 if (!adapter->is_datarate_auto) {
68 while (*ptr) {
69 if ((*ptr & 0x7f) == adapter->datarate) {
70 ret = 0;
71 goto done;
72 }
73 ptr++;
74 }
75 lbs_pr_alert( "Previously set fixed data rate %#x isn't "
76 "compatible with the network.\n", adapter->datarate);
77
78 ret = -1;
79 goto done;
80 }
81
82 ret = 0;
83done:
84 return ret;
85}
86
87int libertas_send_deauth(wlan_private * priv)
88{
89 wlan_adapter *adapter = priv->adapter;
90 int ret = 0;
91
Dan Williams0dc5a292007-05-10 22:58:02 -040092 if (adapter->mode == IW_MODE_INFRA &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093 adapter->connect_status == libertas_connected)
94 ret = libertas_send_deauthentication(priv);
95 else
96 ret = -ENOTSUPP;
97
98 return ret;
99}
100
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200101/**
102 * @brief Associate to a specific BSS discovered in a scan
103 *
104 * @param priv A pointer to wlan_private structure
105 * @param pbssdesc Pointer to the BSS descriptor to associate with.
106 *
107 * @return 0-success, otherwise fail
108 */
Dan Williamse76850d2007-05-25 17:09:41 -0400109int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110{
111 wlan_adapter *adapter = priv->adapter;
112 int ret;
113
Holger Schurig9012b282007-05-25 11:27:16 -0400114 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
116 ret = libertas_prepare_and_send_command(priv, cmd_802_11_authenticate,
117 0, cmd_option_waitforrsp,
Dan Williamse76850d2007-05-25 17:09:41 -0400118 0, assoc_req->bss.bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200119
Holger Schurig9012b282007-05-25 11:27:16 -0400120 if (ret)
121 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
123 /* set preamble to firmware */
Dan Williamse76850d2007-05-25 17:09:41 -0400124 if (adapter->capinfo.shortpreamble && assoc_req->bss.cap.shortpreamble)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125 adapter->preamble = cmd_type_short_preamble;
126 else
127 adapter->preamble = cmd_type_long_preamble;
128
129 libertas_set_radio_control(priv);
130
131 ret = libertas_prepare_and_send_command(priv, cmd_802_11_associate,
Dan Williamse76850d2007-05-25 17:09:41 -0400132 0, cmd_option_waitforrsp, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133
Holger Schurig9012b282007-05-25 11:27:16 -0400134done:
135 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 return ret;
137}
138
139/**
140 * @brief Start an Adhoc Network
141 *
142 * @param priv A pointer to wlan_private structure
143 * @param adhocssid The ssid of the Adhoc Network
144 * @return 0--success, -1--fail
145 */
Dan Williamse76850d2007-05-25 17:09:41 -0400146int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147{
148 wlan_adapter *adapter = priv->adapter;
149 int ret = 0;
150
151 adapter->adhoccreate = 1;
152
153 if (!adapter->capinfo.shortpreamble) {
Holger Schurig9012b282007-05-25 11:27:16 -0400154 lbs_deb_join("AdhocStart: Long preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 adapter->preamble = cmd_type_long_preamble;
156 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400157 lbs_deb_join("AdhocStart: Short preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 adapter->preamble = cmd_type_short_preamble;
159 }
160
161 libertas_set_radio_control(priv);
162
Dan Williamse76850d2007-05-25 17:09:41 -0400163 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
164 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
166 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_start,
Dan Williamse76850d2007-05-25 17:09:41 -0400167 0, cmd_option_waitforrsp, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168
169 return ret;
170}
171
172/**
173 * @brief Join an adhoc network found in a previous scan
174 *
175 * @param priv A pointer to wlan_private structure
176 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
177 * to attempt to join
178 *
179 * @return 0--success, -1--fail
180 */
Dan Williamse76850d2007-05-25 17:09:41 -0400181int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182{
183 wlan_adapter *adapter = priv->adapter;
Dan Williamse76850d2007-05-25 17:09:41 -0400184 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 int ret = 0;
186
Holger Schurig9012b282007-05-25 11:27:16 -0400187 lbs_deb_join("libertas_join_adhoc_network: CurBss.ssid =%s\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188 adapter->curbssparams.ssid.ssid);
Holger Schurig9012b282007-05-25 11:27:16 -0400189 lbs_deb_join("libertas_join_adhoc_network: CurBss.ssid_len =%u\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 adapter->curbssparams.ssid.ssidlength);
Dan Williamse76850d2007-05-25 17:09:41 -0400191 lbs_deb_join("libertas_join_adhoc_network: ssid = '%s'\n",
192 bss->ssid.ssid);
193 lbs_deb_join("libertas_join_adhoc_network: ssid len = %u\n",
194 bss->ssid.ssidlength);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
196 /* check if the requested SSID is already joined */
197 if (adapter->curbssparams.ssid.ssidlength
Dan Williamse76850d2007-05-25 17:09:41 -0400198 && !libertas_SSID_cmp(&bss->ssid, &adapter->curbssparams.ssid)
Dan Williams0dc5a292007-05-10 22:58:02 -0400199 && (adapter->mode == IW_MODE_ADHOC)) {
Dan Williamse76850d2007-05-25 17:09:41 -0400200 lbs_deb_join(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200201 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
202 "not attempting to re-join");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203 return -1;
204 }
205
206 /*Use shortpreamble only when both creator and card supports
207 short preamble */
Dan Williamse76850d2007-05-25 17:09:41 -0400208 if (!bss->cap.shortpreamble || !adapter->capinfo.shortpreamble) {
Holger Schurig9012b282007-05-25 11:27:16 -0400209 lbs_deb_join("AdhocJoin: Long preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200210 adapter->preamble = cmd_type_long_preamble;
211 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400212 lbs_deb_join("AdhocJoin: Short preamble\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213 adapter->preamble = cmd_type_short_preamble;
214 }
215
216 libertas_set_radio_control(priv);
217
Dan Williamse76850d2007-05-25 17:09:41 -0400218 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
219 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220
221 adapter->adhoccreate = 0;
222
223 ret = libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_join,
224 0, cmd_option_waitforrsp,
Dan Williamse76850d2007-05-25 17:09:41 -0400225 OID_802_11_SSID, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226
227 return ret;
228}
229
230int libertas_stop_adhoc_network(wlan_private * priv)
231{
232 return libertas_prepare_and_send_command(priv, cmd_802_11_ad_hoc_stop,
233 0, cmd_option_waitforrsp, 0, NULL);
234}
235
236/**
237 * @brief Send Deauthentication Request
238 *
239 * @param priv A pointer to wlan_private structure
240 * @return 0--success, -1--fail
241 */
242int libertas_send_deauthentication(wlan_private * priv)
243{
244 return libertas_prepare_and_send_command(priv, cmd_802_11_deauthenticate,
245 0, cmd_option_waitforrsp, 0, NULL);
246}
247
248/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 * @brief This function prepares command of authenticate.
250 *
251 * @param priv A pointer to wlan_private structure
252 * @param cmd A pointer to cmd_ds_command structure
253 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
254 *
255 * @return 0 or -1
256 */
257int libertas_cmd_80211_authenticate(wlan_private * priv,
258 struct cmd_ds_command *cmd,
259 void *pdata_buf)
260{
261 wlan_adapter *adapter = priv->adapter;
Dan Williams6affe782007-05-10 22:56:42 -0400262 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
263 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264 u8 *bssid = pdata_buf;
265
Dan Williams45f43de2007-05-25 22:58:55 -0400266 lbs_deb_enter(LBS_DEB_JOIN);
267
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200268 cmd->command = cpu_to_le16(cmd_802_11_authenticate);
Dan Williams6affe782007-05-10 22:56:42 -0400269 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
270 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200271
Dan Williams6affe782007-05-10 22:56:42 -0400272 /* translate auth mode to 802.11 defined wire value */
273 switch (adapter->secinfo.auth_mode) {
274 case IW_AUTH_ALG_OPEN_SYSTEM:
275 pauthenticate->authtype = 0x00;
276 break;
277 case IW_AUTH_ALG_SHARED_KEY:
278 pauthenticate->authtype = 0x01;
279 break;
280 case IW_AUTH_ALG_LEAP:
281 pauthenticate->authtype = 0x80;
282 break;
283 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400284 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
Dan Williams6affe782007-05-10 22:56:42 -0400285 adapter->secinfo.auth_mode);
286 goto out;
287 }
288
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
290
Dan Williams45f43de2007-05-25 22:58:55 -0400291 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
292 MAC_ARG(bssid), pauthenticate->authtype);
Dan Williams6affe782007-05-10 22:56:42 -0400293 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294
Dan Williams6affe782007-05-10 22:56:42 -0400295out:
Dan Williams45f43de2007-05-25 22:58:55 -0400296 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Dan Williams6affe782007-05-10 22:56:42 -0400297 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298}
299
300int libertas_cmd_80211_deauthenticate(wlan_private * priv,
301 struct cmd_ds_command *cmd)
302{
303 wlan_adapter *adapter = priv->adapter;
304 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
305
Holger Schurig9012b282007-05-25 11:27:16 -0400306 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307
308 cmd->command = cpu_to_le16(cmd_802_11_deauthenticate);
309 cmd->size =
310 cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
311 S_DS_GEN);
312
313 /* set AP MAC address */
314 memmove(dauth->macaddr, adapter->curbssparams.bssid,
315 ETH_ALEN);
316
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;
336 u16 tmpcap;
337 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 */
358 passo->listeninterval = adapter->listeninterval;
359
360 pos += sizeof(passo->capinfo);
361 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 Williamse76850d2007-05-25 17:09:41 -0400367 ssid->header.len = bss->ssid.ssidlength;
368 memcpy(ssid->ssid, bss->ssid.ssid, ssid->header.len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 pos += sizeof(ssid->header) + ssid->header.len;
370 ssid->header.len = cpu_to_le16(ssid->header.len);
371
372 phy = (struct mrvlietypes_phyparamset *) pos;
373 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
374 phy->header.len = sizeof(phy->fh_ds.dsparamset);
375 memcpy(&phy->fh_ds.dsparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400376 &bss->phyparamset.dsparamset.currentchan,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200377 sizeof(phy->fh_ds.dsparamset));
378 pos += sizeof(phy->header) + phy->header.len;
379 phy->header.len = cpu_to_le16(phy->header.len);
380
381 ss = (struct mrvlietypes_ssparamset *) pos;
382 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
383 ss->header.len = sizeof(ss->cf_ibss.cfparamset);
384 pos += sizeof(ss->header) + ss->header.len;
385 ss->header.len = cpu_to_le16(ss->header.len);
386
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
401 rates->header.len = min_t(size_t, strlen(rates->rates), WLAN_SUPPORTED_RATES);
402 adapter->curbssparams.numofrates = rates->header.len;
403
404 pos += sizeof(rates->header) + rates->header.len;
405 rates->header.len = cpu_to_le16(rates->header.len);
406
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;
Dan Williamse76850d2007-05-25 17:09:41 -0400409 rsn->header.type = (u16) assoc_req->wpa_ie[0]; /* WPA_IE or WPA2_IE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 rsn->header.type = cpu_to_le16(rsn->header.type);
Dan Williamse76850d2007-05-25 17:09:41 -0400411 rsn->header.len = (u16) assoc_req->wpa_ie[1];
412 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], rsn->header.len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413 lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
414 sizeof(rsn->header) + rsn->header.len);
415 pos += sizeof(rsn->header) + rsn->header.len;
416 rsn->header.len = cpu_to_le16(rsn->header.len);
417 }
418
419 /* update curbssparams */
420 adapter->curbssparams.channel =
Dan Williamse76850d2007-05-25 17:09:41 -0400421 (bss->phyparamset.dsparamset.currentchan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422
423 /* Copy the infra. association rates into Current BSS state structure */
424 memcpy(&adapter->curbssparams.datarates, &rates->rates,
425 min_t(size_t, sizeof(adapter->curbssparams.datarates), rates->header.len));
426
Holger Schurig9012b282007-05-25 11:27:16 -0400427 lbs_deb_join("ASSOC_CMD: rates->header.len = %d\n", rates->header.len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428
429 /* set IBSS field */
Dan Williamse76850d2007-05-25 17:09:41 -0400430 if (bss->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431#define CAPINFO_ESS_MODE 1
432 passo->capinfo.ess = CAPINFO_ESS_MODE;
433 }
434
Dan Williamse76850d2007-05-25 17:09:41 -0400435 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436 ret = -1;
437 goto done;
438 }
439
440 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
441
442 /* set the capability info at last */
Dan Williamse76850d2007-05-25 17:09:41 -0400443 memcpy(&tmpcap, &bss->cap, sizeof(passo->capinfo));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444 tmpcap &= CAPINFO_MASK;
Holger Schurig9012b282007-05-25 11:27:16 -0400445 lbs_deb_join("ASSOC_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446 tmpcap, CAPINFO_MASK);
447 tmpcap = cpu_to_le16(tmpcap);
448 memcpy(&passo->capinfo, &tmpcap, sizeof(passo->capinfo));
449
Holger Schurig9012b282007-05-25 11:27:16 -0400450done:
451 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 return ret;
453}
454
455int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400456 struct cmd_ds_command *cmd, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457{
458 wlan_adapter *adapter = priv->adapter;
459 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
460 int ret = 0;
461 int cmdappendsize = 0;
462 int i;
463 u16 tmpcap;
Dan Williamse76850d2007-05-25 17:09:41 -0400464 struct assoc_request * assoc_req = pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465
Holger Schurig9012b282007-05-25 11:27:16 -0400466 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467
468 if (!adapter) {
469 ret = -1;
470 goto done;
471 }
472
473 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_start);
474
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475 /*
476 * Fill in the parameters for 2 data structures:
477 * 1. cmd_ds_802_11_ad_hoc_start command
478 * 2. adapter->scantable[i]
479 *
480 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
481 * probe delay, and cap info.
482 *
483 * Firmware will fill up beacon period, DTIM, Basic rates
484 * and operational rates.
485 */
486
487 memset(adhs->SSID, 0, IW_ESSID_MAX_SIZE);
Dan Williamse76850d2007-05-25 17:09:41 -0400488 memcpy(adhs->SSID, assoc_req->ssid.ssid, assoc_req->ssid.ssidlength);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489
Holger Schurig9012b282007-05-25 11:27:16 -0400490 lbs_deb_join("ADHOC_S_CMD: SSID = %s\n", adhs->SSID);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200492 /* set the BSS type */
493 adhs->bsstype = cmd_bss_type_ibss;
Dan Williamse76850d2007-05-25 17:09:41 -0400494 adapter->mode = IW_MODE_ADHOC;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495 adhs->beaconperiod = adapter->beaconperiod;
496
497 /* set Physical param set */
498#define DS_PARA_IE_ID 3
499#define DS_PARA_IE_LEN 1
500
501 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
502 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
503
Dan Williamse76850d2007-05-25 17:09:41 -0400504 WARN_ON(!assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505
Holger Schurig9012b282007-05-25 11:27:16 -0400506 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
Dan Williamse76850d2007-05-25 17:09:41 -0400507 assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508
Dan Williamse76850d2007-05-25 17:09:41 -0400509 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510
511 /* set IBSS param set */
512#define IBSS_PARA_IE_ID 6
513#define IBSS_PARA_IE_LEN 2
514
515 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
516 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
517 adhs->ssparamset.ibssparamset.atimwindow = adapter->atimwindow;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200518
519 /* set capability info */
520 adhs->cap.ess = 0;
521 adhs->cap.ibss = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522
523 /* probedelay */
524 adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
525
526 /* set up privacy in adapter->scantable[i] */
Dan Williamse76850d2007-05-25 17:09:41 -0400527 if (assoc_req->secinfo.wep_enabled) {
Holger Schurig9012b282007-05-25 11:27:16 -0400528 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529 adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
530 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400531 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 }
533
534 memset(adhs->datarate, 0, sizeof(adhs->datarate));
535
536 if (adapter->adhoc_grate_enabled) {
537 memcpy(adhs->datarate, libertas_adhoc_rates_g,
538 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_g)));
539 } else {
540 memcpy(adhs->datarate, libertas_adhoc_rates_b,
541 min(sizeof(adhs->datarate), sizeof(libertas_adhoc_rates_b)));
542 }
543
544 /* Find the last non zero */
545 for (i = 0; i < sizeof(adhs->datarate) && adhs->datarate[i]; i++) ;
546
547 adapter->curbssparams.numofrates = i;
548
549 /* Copy the ad-hoc creating rates into Current BSS state structure */
550 memcpy(&adapter->curbssparams.datarates,
551 &adhs->datarate, adapter->curbssparams.numofrates);
552
Holger Schurig9012b282007-05-25 11:27:16 -0400553 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554 adhs->datarate[0], adhs->datarate[1],
555 adhs->datarate[2], adhs->datarate[3]);
556
Holger Schurig9012b282007-05-25 11:27:16 -0400557 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558
559 if (libertas_create_dnld_countryinfo_11d(priv)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400560 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561 ret = -1;
562 goto done;
563 }
564
565 cmd->size =
566 cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start)
567 + S_DS_GEN + cmdappendsize);
568
569 memcpy(&tmpcap, &adhs->cap, sizeof(u16));
570 tmpcap = cpu_to_le16(tmpcap);
571 memcpy(&adhs->cap, &tmpcap, sizeof(u16));
572
573 ret = 0;
574done:
Holger Schurig9012b282007-05-25 11:27:16 -0400575 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 return ret;
577}
578
579int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
580 struct cmd_ds_command *cmd)
581{
582 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_stop);
583 cmd->size = cpu_to_le16(S_DS_GEN);
584
585 return 0;
586}
587
588int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
589 struct cmd_ds_command *cmd, void *pdata_buf)
590{
591 wlan_adapter *adapter = priv->adapter;
592 struct cmd_ds_802_11_ad_hoc_join *padhocjoin = &cmd->params.adj;
Dan Williamse76850d2007-05-25 17:09:41 -0400593 struct assoc_request * assoc_req = pdata_buf;
594 struct bss_descriptor *bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 int cmdappendsize = 0;
596 int ret = 0;
597 u8 *card_rates;
598 int card_rates_size;
599 u16 tmpcap;
600 int i;
601
Holger Schurig9012b282007-05-25 11:27:16 -0400602 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 cmd->command = cpu_to_le16(cmd_802_11_ad_hoc_join);
605
606 padhocjoin->bssdescriptor.bsstype = cmd_bss_type_ibss;
607
Dan Williamse76850d2007-05-25 17:09:41 -0400608 padhocjoin->bssdescriptor.beaconperiod = bss->beaconperiod;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609
Dan Williamse76850d2007-05-25 17:09:41 -0400610 memcpy(&padhocjoin->bssdescriptor.BSSID, &bss->bssid, ETH_ALEN);
611 memcpy(&padhocjoin->bssdescriptor.SSID, &bss->ssid.ssid, bss->ssid.ssidlength);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200612
613 memcpy(&padhocjoin->bssdescriptor.phyparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400614 &bss->phyparamset, sizeof(union ieeetypes_phyparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615
616 memcpy(&padhocjoin->bssdescriptor.ssparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400617 &bss->ssparamset, sizeof(union IEEEtypes_ssparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618
Dan Williamse76850d2007-05-25 17:09:41 -0400619 memcpy(&tmpcap, &bss->cap, sizeof(struct ieeetypes_capinfo));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620 tmpcap &= CAPINFO_MASK;
621
Holger Schurig9012b282007-05-25 11:27:16 -0400622 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623 tmpcap, CAPINFO_MASK);
624 memcpy(&padhocjoin->bssdescriptor.cap, &tmpcap,
625 sizeof(struct ieeetypes_capinfo));
626
627 /* information on BSSID descriptor passed to FW */
Dan Williamse76850d2007-05-25 17:09:41 -0400628 lbs_deb_join(
629 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
630 MAC_ARG(padhocjoin->bssdescriptor.BSSID),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 padhocjoin->bssdescriptor.SSID);
632
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 /* failtimeout */
634 padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
635
636 /* probedelay */
637 padhocjoin->probedelay =
638 cpu_to_le16(cmd_scan_probe_delay_time);
639
640 /* Copy Data rates from the rates recorded in scan response */
641 memset(padhocjoin->bssdescriptor.datarates, 0,
642 sizeof(padhocjoin->bssdescriptor.datarates));
Dan Williamse76850d2007-05-25 17:09:41 -0400643 memcpy(padhocjoin->bssdescriptor.datarates, bss->datarates,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 min(sizeof(padhocjoin->bssdescriptor.datarates),
Dan Williamse76850d2007-05-25 17:09:41 -0400645 sizeof(bss->datarates)));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200646
647 card_rates = libertas_supported_rates;
648 card_rates_size = sizeof(libertas_supported_rates);
649
Dan Williamse76850d2007-05-25 17:09:41 -0400650 adapter->curbssparams.channel = bss->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651
652 if (get_common_rates(adapter, padhocjoin->bssdescriptor.datarates,
653 sizeof(padhocjoin->bssdescriptor.datarates),
654 card_rates, card_rates_size)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400655 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200656 ret = -1;
657 goto done;
658 }
659
660 /* Find the last non zero */
661 for (i = 0; i < sizeof(padhocjoin->bssdescriptor.datarates)
662 && padhocjoin->bssdescriptor.datarates[i]; i++) ;
663
664 adapter->curbssparams.numofrates = i;
665
666 /*
667 * Copy the adhoc joining rates to Current BSS State structure
668 */
669 memcpy(adapter->curbssparams.datarates,
670 padhocjoin->bssdescriptor.datarates,
671 adapter->curbssparams.numofrates);
672
673 padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
Dan Williamse76850d2007-05-25 17:09:41 -0400674 cpu_to_le16(bss->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675
Dan Williamse76850d2007-05-25 17:09:41 -0400676 if (assoc_req->secinfo.wep_enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677 padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
678 }
679
680 if (adapter->psmode == wlan802_11powermodemax_psp) {
681 /* wake up first */
682 enum WLAN_802_11_POWER_MODE Localpsmode;
683
684 Localpsmode = wlan802_11powermodecam;
685 ret = libertas_prepare_and_send_command(priv,
686 cmd_802_11_ps_mode,
687 cmd_act_set,
688 0, 0, &Localpsmode);
689
690 if (ret) {
691 ret = -1;
692 goto done;
693 }
694 }
695
Dan Williamse76850d2007-05-25 17:09:41 -0400696 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200697 ret = -1;
698 goto done;
699 }
700
701 cmd->size =
702 cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join)
703 + S_DS_GEN + cmdappendsize);
704
705 memcpy(&tmpcap, &padhocjoin->bssdescriptor.cap,
706 sizeof(struct ieeetypes_capinfo));
707 tmpcap = cpu_to_le16(tmpcap);
708
709 memcpy(&padhocjoin->bssdescriptor.cap,
710 &tmpcap, sizeof(struct ieeetypes_capinfo));
711
Holger Schurig9012b282007-05-25 11:27:16 -0400712done:
713 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200714 return ret;
715}
716
717int libertas_ret_80211_associate(wlan_private * priv,
718 struct cmd_ds_command *resp)
719{
720 wlan_adapter *adapter = priv->adapter;
721 int ret = 0;
722 union iwreq_data wrqu;
723 struct ieeetypes_assocrsp *passocrsp;
Dan Williamse76850d2007-05-25 17:09:41 -0400724 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200725
Holger Schurig9012b282007-05-25 11:27:16 -0400726 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727
Dan Williamse76850d2007-05-25 17:09:41 -0400728 if (!adapter->in_progress_assoc_req) {
729 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
730 ret = -1;
731 goto done;
732 }
733 bss = &adapter->in_progress_assoc_req->bss;
734
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200735 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
736
737 if (passocrsp->statuscode) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 libertas_mac_event_disconnected(priv);
739
Dan Williamse76850d2007-05-25 17:09:41 -0400740 lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
Holger Schurig9012b282007-05-25 11:27:16 -0400741 passocrsp->statuscode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200742
743 ret = -1;
744 goto done;
745 }
746
747 lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
748 le16_to_cpu(resp->size) - S_DS_GEN);
749
750 /* Send a Media Connected event, according to the Spec */
751 adapter->connect_status = libertas_connected;
752
Dan Williamse76850d2007-05-25 17:09:41 -0400753 lbs_deb_join("ASSOC_RESP: %s\n", bss->ssid.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754
Dan Williamse76850d2007-05-25 17:09:41 -0400755 /* Update current SSID and BSSID */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756 memcpy(&adapter->curbssparams.ssid,
Dan Williamse76850d2007-05-25 17:09:41 -0400757 &bss->ssid, sizeof(struct WLAN_802_11_SSID));
758 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759
Holger Schurig9012b282007-05-25 11:27:16 -0400760 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 adapter->currentpacketfilter);
762
763 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
764 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
765
766 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
767 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
768 adapter->nextSNRNF = 0;
769 adapter->numSNRNF = 0;
770
Holger Schurig634b8f42007-05-25 13:05:16 -0400771 netif_carrier_on(priv->dev);
772 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200773
Javier Cardona51d84f52007-05-25 12:06:56 -0400774 netif_carrier_on(priv->mesh_dev);
775 netif_wake_queue(priv->mesh_dev);
776
Holger Schurig9012b282007-05-25 11:27:16 -0400777 lbs_deb_join("ASSOC_RESP: Associated \n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778
779 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
780 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400781 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
Holger Schurig9012b282007-05-25 11:27:16 -0400783done:
784 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 return ret;
786}
787
788int libertas_ret_80211_disassociate(wlan_private * priv,
789 struct cmd_ds_command *resp)
790{
Holger Schurig9012b282007-05-25 11:27:16 -0400791 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792
793 libertas_mac_event_disconnected(priv);
794
Holger Schurig9012b282007-05-25 11:27:16 -0400795 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200796 return 0;
797}
798
799int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
800 struct cmd_ds_command *resp)
801{
802 wlan_adapter *adapter = priv->adapter;
803 int ret = 0;
804 u16 command = le16_to_cpu(resp->command);
805 u16 result = le16_to_cpu(resp->result);
806 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
807 union iwreq_data wrqu;
Dan Williamse76850d2007-05-25 17:09:41 -0400808 struct bss_descriptor *bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809
Holger Schurig9012b282007-05-25 11:27:16 -0400810 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200811
812 padhocresult = &resp->params.result;
813
Dan Williamse76850d2007-05-25 17:09:41 -0400814 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
815 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
816 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
Dan Williamse76850d2007-05-25 17:09:41 -0400818 if (!adapter->in_progress_assoc_req) {
819 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
820 ret = -1;
821 goto done;
822 }
823 bss = &adapter->in_progress_assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200824
825 /*
826 * Join result code 0 --> SUCCESS
827 */
828 if (result) {
Dan Williamse76850d2007-05-25 17:09:41 -0400829 lbs_deb_join("ADHOC_RESP: failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200830 if (adapter->connect_status == libertas_connected) {
831 libertas_mac_event_disconnected(priv);
832 }
Holger Schurig9012b282007-05-25 11:27:16 -0400833 ret = -1;
834 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200835 }
836
837 /*
838 * Now the join cmd should be successful
839 * If BSSID has changed use SSID to compare instead of BSSID
840 */
Dan Williamse76850d2007-05-25 17:09:41 -0400841 lbs_deb_join("ADHOC_RESP: %s\n", bss->ssid.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200842
843 /* Send a Media Connected event, according to the Spec */
844 adapter->connect_status = libertas_connected;
845
846 if (command == cmd_ret_802_11_ad_hoc_start) {
847 /* Update the created network descriptor with the new BSSID */
Dan Williamse76850d2007-05-25 17:09:41 -0400848 memcpy(bss->bssid, padhocresult->BSSID, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200849 }
850
851 /* Set the BSSID from the joined/started descriptor */
Dan Williamse76850d2007-05-25 17:09:41 -0400852 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853
854 /* Set the new SSID to current SSID */
Dan Williamse76850d2007-05-25 17:09:41 -0400855 memcpy(&adapter->curbssparams.ssid, &bss->ssid,
856 sizeof(struct WLAN_802_11_SSID));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857
Holger Schurig634b8f42007-05-25 13:05:16 -0400858 netif_carrier_on(priv->dev);
859 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860
Javier Cardona51d84f52007-05-25 12:06:56 -0400861 netif_carrier_on(priv->mesh_dev);
862 netif_wake_queue(priv->mesh_dev);
863
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200864 memset(&wrqu, 0, sizeof(wrqu));
865 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
866 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400867 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200868
Holger Schurig9012b282007-05-25 11:27:16 -0400869 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400870 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
Dan Williams02eb2292007-05-25 17:27:31 -0400871 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
872 MAC_ARG(padhocresult->BSSID));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873
Holger Schurig9012b282007-05-25 11:27:16 -0400874done:
875 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200876 return ret;
877}
878
879int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
880 struct cmd_ds_command *resp)
881{
Holger Schurig9012b282007-05-25 11:27:16 -0400882 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883
884 libertas_mac_event_disconnected(priv);
885
Holger Schurig9012b282007-05-25 11:27:16 -0400886 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887 return 0;
888}