blob: 78e398d6f5f365ed65b68d00faa5d7c7af0e8671 [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 Williams8c512762007-08-02 11:40:45 -040020/* Supported rates for ad-hoc B mode */
21u8 adhoc_rates_b[5] = { 0x02, 0x04, 0x0b, 0x16, 0x00 };
22
23
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024/**
Dan Williams8c512762007-08-02 11:40:45 -040025 * @brief This function finds common rates between rate1 and card rates.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026 *
27 * It will fill common rates in rate1 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 adapter A pointer to wlan_adapter structure
33 * @param rate1 the buffer which keeps input and output
Dan Williams8c512762007-08-02 11:40:45 -040034 * @param rate1_size the size of rate1 buffer; new size of buffer on return
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020035 *
36 * @return 0 or -1
37 */
Dan Williams8c512762007-08-02 11:40:45 -040038static int get_common_rates(wlan_adapter * adapter, u8 * rates, u16 *rates_size)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039{
Dan Williams8c512762007-08-02 11:40:45 -040040 u8 *card_rates = libertas_bg_rates;
41 size_t num_card_rates = sizeof(libertas_bg_rates);
42 int ret = 0, i, j;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020043 u8 tmp[30];
Dan Williams8c512762007-08-02 11:40:45 -040044 size_t tmp_size = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045
Dan Williams8c512762007-08-02 11:40:45 -040046 /* For each rate in card_rates that exists in rate1, copy to tmp */
47 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
48 for (j = 0; rates[j] && (j < *rates_size); j++) {
49 if (rates[j] == card_rates[i])
50 tmp[tmp_size++] = card_rates[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 }
52 }
53
Dan Williams8c512762007-08-02 11:40:45 -040054 lbs_dbg_hex("rate1 (AP) rates:", rates, *rates_size);
55 lbs_dbg_hex("rate2 (Card) rates:", card_rates, num_card_rates);
56 lbs_dbg_hex("Common rates:", tmp, tmp_size);
57 lbs_deb_join("Tx datarate is currently 0x%X\n", adapter->cur_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020058
Dan Williams8c512762007-08-02 11:40:45 -040059 if (!adapter->auto_rate) {
60 for (i = 0; i < tmp_size; i++) {
61 if (tmp[i] == adapter->cur_rate)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 }
Dan Williams8c512762007-08-02 11:40:45 -040064 lbs_pr_alert("Previously set fixed data rate %#x isn't "
65 "compatible with the network.\n", adapter->cur_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 ret = -1;
67 goto done;
68 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069 ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -040070
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071done:
Dan Williams8c512762007-08-02 11:40:45 -040072 memset(rates, 0, *rates_size);
73 *rates_size = min_t(int, tmp_size, *rates_size);
74 memcpy(rates, tmp, *rates_size);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 return ret;
76}
77
Dan Williams8c512762007-08-02 11:40:45 -040078
79/**
80 * @brief Sets the MSB on basic rates as the firmware requires
81 *
82 * Scan through an array and set the MSB for basic data rates.
83 *
84 * @param rates buffer of data rates
85 * @param len size of buffer
86 */
87static void libertas_set_basic_rate_flags(u8 * rates, size_t len)
88{
89 int i;
90
91 for (i = 0; i < len; i++) {
92 if (rates[i] == 0x02 || rates[i] == 0x04 ||
93 rates[i] == 0x0b || rates[i] == 0x16)
94 rates[i] |= 0x80;
95 }
96}
97
98/**
99 * @brief Unsets the MSB on basic rates
100 *
101 * Scan through an array and unset the MSB for basic data rates.
102 *
103 * @param rates buffer of data rates
104 * @param len size of buffer
105 */
106void libertas_unset_basic_rate_flags(u8 * rates, size_t len)
107{
108 int i;
109
110 for (i = 0; i < len; i++)
111 rates[i] &= 0x7f;
112}
113
114
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115int libertas_send_deauth(wlan_private * priv)
116{
117 wlan_adapter *adapter = priv->adapter;
118 int ret = 0;
119
Dan Williams0dc5a292007-05-10 22:58:02 -0400120 if (adapter->mode == IW_MODE_INFRA &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400121 adapter->connect_status == LIBERTAS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122 ret = libertas_send_deauthentication(priv);
123 else
124 ret = -ENOTSUPP;
125
126 return ret;
127}
128
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129/**
130 * @brief Associate to a specific BSS discovered in a scan
131 *
132 * @param priv A pointer to wlan_private structure
133 * @param pbssdesc Pointer to the BSS descriptor to associate with.
134 *
135 * @return 0-success, otherwise fail
136 */
Dan Williamse76850d2007-05-25 17:09:41 -0400137int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138{
139 wlan_adapter *adapter = priv->adapter;
140 int ret;
141
Holger Schurig9012b282007-05-25 11:27:16 -0400142 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143
Dan Williams0aef64d2007-08-02 11:31:18 -0400144 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
145 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400146 0, assoc_req->bss.bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147
Holger Schurig9012b282007-05-25 11:27:16 -0400148 if (ret)
149 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150
151 /* set preamble to firmware */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400152 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
153 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
Dan Williams0aef64d2007-08-02 11:31:18 -0400154 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 else
Dan Williams0aef64d2007-08-02 11:31:18 -0400156 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157
158 libertas_set_radio_control(priv);
159
Dan Williams0aef64d2007-08-02 11:31:18 -0400160 ret = libertas_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
161 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162
Holger Schurig9012b282007-05-25 11:27:16 -0400163done:
164 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165 return ret;
166}
167
168/**
169 * @brief Start an Adhoc Network
170 *
171 * @param priv A pointer to wlan_private structure
172 * @param adhocssid The ssid of the Adhoc Network
173 * @return 0--success, -1--fail
174 */
Dan Williamse76850d2007-05-25 17:09:41 -0400175int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200176{
177 wlan_adapter *adapter = priv->adapter;
178 int ret = 0;
179
180 adapter->adhoccreate = 1;
181
Dan Williams0c9ca6902007-08-02 10:43:44 -0400182 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400183 lbs_deb_join("AdhocStart: Short preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400184 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400185 } else {
186 lbs_deb_join("AdhocStart: Long preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400187 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188 }
189
190 libertas_set_radio_control(priv);
191
Dan Williamse76850d2007-05-25 17:09:41 -0400192 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
193 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194
Dan Williams0aef64d2007-08-02 11:31:18 -0400195 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
196 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197
198 return ret;
199}
200
201/**
202 * @brief Join an adhoc network found in a previous scan
203 *
204 * @param priv A pointer to wlan_private structure
205 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
206 * to attempt to join
207 *
208 * @return 0--success, -1--fail
209 */
Dan Williamse76850d2007-05-25 17:09:41 -0400210int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211{
212 wlan_adapter *adapter = priv->adapter;
Dan Williamse76850d2007-05-25 17:09:41 -0400213 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214 int ret = 0;
215
Dan Williamsd8efea22007-05-28 23:54:55 -0400216 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
217 __func__,
218 escape_essid(adapter->curbssparams.ssid,
219 adapter->curbssparams.ssid_len),
220 adapter->curbssparams.ssid_len);
221 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
222 __func__, escape_essid(bss->ssid, bss->ssid_len),
223 bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224
225 /* check if the requested SSID is already joined */
Dan Williamsd8efea22007-05-28 23:54:55 -0400226 if (adapter->curbssparams.ssid_len
Dan Williams717c9332007-05-29 00:03:31 -0400227 && !libertas_ssid_cmp(adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400228 adapter->curbssparams.ssid_len,
229 bss->ssid, bss->ssid_len)
Dan Williams0dc5a292007-05-10 22:58:02 -0400230 && (adapter->mode == IW_MODE_ADHOC)) {
Dan Williamse76850d2007-05-25 17:09:41 -0400231 lbs_deb_join(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
233 "not attempting to re-join");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 return -1;
235 }
236
Dan Williams0c9ca6902007-08-02 10:43:44 -0400237 /* Use shortpreamble only when both creator and card supports
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238 short preamble */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400239 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
240 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400241 lbs_deb_join("AdhocJoin: Long preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400242 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400244 lbs_deb_join("AdhocJoin: Short preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400245 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 }
247
248 libertas_set_radio_control(priv);
249
Dan Williamse76850d2007-05-25 17:09:41 -0400250 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
251 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252
253 adapter->adhoccreate = 0;
254
Dan Williams0aef64d2007-08-02 11:31:18 -0400255 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
256 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400257 OID_802_11_SSID, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258
259 return ret;
260}
261
262int libertas_stop_adhoc_network(wlan_private * priv)
263{
Dan Williams0aef64d2007-08-02 11:31:18 -0400264 return libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
265 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266}
267
268/**
269 * @brief Send Deauthentication Request
270 *
271 * @param priv A pointer to wlan_private structure
272 * @return 0--success, -1--fail
273 */
274int libertas_send_deauthentication(wlan_private * priv)
275{
Dan Williams0aef64d2007-08-02 11:31:18 -0400276 return libertas_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
277 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278}
279
280/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281 * @brief This function prepares command of authenticate.
282 *
283 * @param priv A pointer to wlan_private structure
284 * @param cmd A pointer to cmd_ds_command structure
285 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
286 *
287 * @return 0 or -1
288 */
289int libertas_cmd_80211_authenticate(wlan_private * priv,
290 struct cmd_ds_command *cmd,
291 void *pdata_buf)
292{
293 wlan_adapter *adapter = priv->adapter;
Dan Williams6affe782007-05-10 22:56:42 -0400294 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
295 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296 u8 *bssid = pdata_buf;
297
Dan Williams45f43de2007-05-25 22:58:55 -0400298 lbs_deb_enter(LBS_DEB_JOIN);
299
Dan Williams0aef64d2007-08-02 11:31:18 -0400300 cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE);
Dan Williams6affe782007-05-10 22:56:42 -0400301 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
302 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303
Dan Williams6affe782007-05-10 22:56:42 -0400304 /* translate auth mode to 802.11 defined wire value */
305 switch (adapter->secinfo.auth_mode) {
306 case IW_AUTH_ALG_OPEN_SYSTEM:
307 pauthenticate->authtype = 0x00;
308 break;
309 case IW_AUTH_ALG_SHARED_KEY:
310 pauthenticate->authtype = 0x01;
311 break;
312 case IW_AUTH_ALG_LEAP:
313 pauthenticate->authtype = 0x80;
314 break;
315 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400316 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
Dan Williams6affe782007-05-10 22:56:42 -0400317 adapter->secinfo.auth_mode);
318 goto out;
319 }
320
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
322
Dan Williams45f43de2007-05-25 22:58:55 -0400323 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
324 MAC_ARG(bssid), pauthenticate->authtype);
Dan Williams6affe782007-05-10 22:56:42 -0400325 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326
Dan Williams6affe782007-05-10 22:56:42 -0400327out:
Dan Williams45f43de2007-05-25 22:58:55 -0400328 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Dan Williams6affe782007-05-10 22:56:42 -0400329 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330}
331
332int libertas_cmd_80211_deauthenticate(wlan_private * priv,
333 struct cmd_ds_command *cmd)
334{
335 wlan_adapter *adapter = priv->adapter;
336 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
337
Holger Schurig9012b282007-05-25 11:27:16 -0400338 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339
Dan Williams0aef64d2007-08-02 11:31:18 -0400340 cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE);
David Woodhouse981f1872007-05-25 23:36:54 -0400341 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342 S_DS_GEN);
343
344 /* set AP MAC address */
David Woodhouse981f1872007-05-25 23:36:54 -0400345 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346
347 /* Reason code 3 = Station is leaving */
348#define REASON_CODE_STA_LEAVING 3
349 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
350
Holger Schurig9012b282007-05-25 11:27:16 -0400351 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 return 0;
353}
354
355int libertas_cmd_80211_associate(wlan_private * priv,
356 struct cmd_ds_command *cmd, void *pdata_buf)
357{
358 wlan_adapter *adapter = priv->adapter;
359 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
360 int ret = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400361 struct assoc_request * assoc_req = pdata_buf;
362 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363 u8 *pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400364 u16 tmpcap, tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200365 struct mrvlietypes_ssidparamset *ssid;
366 struct mrvlietypes_phyparamset *phy;
367 struct mrvlietypes_ssparamset *ss;
368 struct mrvlietypes_ratesparamset *rates;
369 struct mrvlietypes_rsnparamset *rsn;
370
Holger Schurig9012b282007-05-25 11:27:16 -0400371 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 pos = (u8 *) passo;
374
375 if (!adapter) {
376 ret = -1;
377 goto done;
378 }
379
Dan Williams0aef64d2007-08-02 11:31:18 -0400380 cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381
Dan Williamse76850d2007-05-25 17:09:41 -0400382 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383 pos += sizeof(passo->peerstaaddr);
384
385 /* set the listen interval */
David Woodhouse981f1872007-05-25 23:36:54 -0400386 passo->listeninterval = cpu_to_le16(adapter->listeninterval);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387
Dan Williams0c9ca6902007-08-02 10:43:44 -0400388 pos += sizeof(passo->capability);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389 pos += sizeof(passo->listeninterval);
390 pos += sizeof(passo->bcnperiod);
391 pos += sizeof(passo->dtimperiod);
392
393 ssid = (struct mrvlietypes_ssidparamset *) pos;
394 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
Dan Williamsd8efea22007-05-28 23:54:55 -0400395 tmplen = bss->ssid_len;
David Woodhouse707985b2007-05-25 23:41:16 -0400396 ssid->header.len = cpu_to_le16(tmplen);
Dan Williamsd8efea22007-05-28 23:54:55 -0400397 memcpy(ssid->ssid, bss->ssid, tmplen);
David Woodhouse707985b2007-05-25 23:41:16 -0400398 pos += sizeof(ssid->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399
400 phy = (struct mrvlietypes_phyparamset *) pos;
401 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
David Woodhouse707985b2007-05-25 23:41:16 -0400402 tmplen = sizeof(phy->fh_ds.dsparamset);
403 phy->header.len = cpu_to_le16(tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 memcpy(&phy->fh_ds.dsparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400405 &bss->phyparamset.dsparamset.currentchan,
David Woodhouse707985b2007-05-25 23:41:16 -0400406 tmplen);
407 pos += sizeof(phy->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408
409 ss = (struct mrvlietypes_ssparamset *) pos;
410 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
David Woodhouse707985b2007-05-25 23:41:16 -0400411 tmplen = sizeof(ss->cf_ibss.cfparamset);
412 ss->header.len = cpu_to_le16(tmplen);
413 pos += sizeof(ss->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414
415 rates = (struct mrvlietypes_ratesparamset *) pos;
416 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400417 memcpy(&rates->rates, &bss->rates, MAX_RATES);
418 tmplen = MAX_RATES;
419 if (get_common_rates(adapter, rates->rates, &tmplen)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420 ret = -1;
421 goto done;
422 }
David Woodhouse981f1872007-05-25 23:36:54 -0400423 pos += sizeof(rates->header) + tmplen;
424 rates->header.len = cpu_to_le16(tmplen);
Dan Williams8c512762007-08-02 11:40:45 -0400425 lbs_deb_join("ASSOC_CMD: num rates = %u\n", tmplen);
426
427 /* Copy the infra. association rates into Current BSS state structure */
428 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
429 memcpy(&adapter->curbssparams.rates, &rates->rates, tmplen);
430
431 /* Set MSB on basic rates as the firmware requires, but _after_
432 * copying to current bss rates.
433 */
434 libertas_set_basic_rate_flags(rates->rates, tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435
Dan Williamse76850d2007-05-25 17:09:41 -0400436 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437 rsn = (struct mrvlietypes_rsnparamset *) pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400438 /* WPA_IE or WPA2_IE */
439 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
440 tmplen = (u16) assoc_req->wpa_ie[1];
441 rsn->header.len = cpu_to_le16(tmplen);
442 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443 lbs_dbg_hex("ASSOC_CMD: RSN IE", (u8 *) rsn,
David Woodhouse981f1872007-05-25 23:36:54 -0400444 sizeof(rsn->header) + tmplen);
445 pos += sizeof(rsn->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446 }
447
448 /* update curbssparams */
David Woodhouse981f1872007-05-25 23:36:54 -0400449 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450
Dan Williamse76850d2007-05-25 17:09:41 -0400451 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 ret = -1;
453 goto done;
454 }
455
456 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
457
Dan Williams0c9ca6902007-08-02 10:43:44 -0400458 /* set the capability info */
459 tmpcap = (bss->capability & CAPINFO_MASK);
460 if (bss->mode == IW_MODE_INFRA)
461 tmpcap |= WLAN_CAPABILITY_ESS;
462 passo->capability = cpu_to_le16(tmpcap);
463 lbs_deb_join("ASSOC_CMD: capability=%4X CAPINFO_MASK=%4X\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400464 tmpcap, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465
Holger Schurig9012b282007-05-25 11:27:16 -0400466done:
467 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468 return ret;
469}
470
471int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400472 struct cmd_ds_command *cmd, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473{
474 wlan_adapter *adapter = priv->adapter;
475 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
476 int ret = 0;
477 int cmdappendsize = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400478 struct assoc_request * assoc_req = pdata_buf;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400479 u16 tmpcap = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400480 size_t ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
Holger Schurig9012b282007-05-25 11:27:16 -0400482 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
484 if (!adapter) {
485 ret = -1;
486 goto done;
487 }
488
Dan Williams0aef64d2007-08-02 11:31:18 -0400489 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491 /*
492 * Fill in the parameters for 2 data structures:
493 * 1. cmd_ds_802_11_ad_hoc_start command
494 * 2. adapter->scantable[i]
495 *
496 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
497 * probe delay, and cap info.
498 *
499 * Firmware will fill up beacon period, DTIM, Basic rates
500 * and operational rates.
501 */
502
Dan Williamsb44898e2007-08-02 11:18:40 -0400503 memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE);
504 memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505
Dan Williamsd8efea22007-05-28 23:54:55 -0400506 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
507 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
508 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510 /* set the BSS type */
Dan Williams0aef64d2007-08-02 11:31:18 -0400511 adhs->bsstype = CMD_BSS_TYPE_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400512 adapter->mode = IW_MODE_ADHOC;
David Woodhouse981f1872007-05-25 23:36:54 -0400513 adhs->beaconperiod = cpu_to_le16(adapter->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514
515 /* set Physical param set */
516#define DS_PARA_IE_ID 3
517#define DS_PARA_IE_LEN 1
518
519 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
520 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
521
Dan Williamse76850d2007-05-25 17:09:41 -0400522 WARN_ON(!assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523
Holger Schurig9012b282007-05-25 11:27:16 -0400524 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400525 assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200526
Dan Williamse76850d2007-05-25 17:09:41 -0400527 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528
529 /* set IBSS param set */
530#define IBSS_PARA_IE_ID 6
531#define IBSS_PARA_IE_LEN 2
532
533 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
534 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
David Woodhouse981f1872007-05-25 23:36:54 -0400535 adhs->ssparamset.ibssparamset.atimwindow = cpu_to_le16(adapter->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536
537 /* set capability info */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400538 tmpcap = WLAN_CAPABILITY_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400539 if (assoc_req->secinfo.wep_enabled) {
Holger Schurig9012b282007-05-25 11:27:16 -0400540 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
Dan Williams0c9ca6902007-08-02 10:43:44 -0400541 tmpcap |= WLAN_CAPABILITY_PRIVACY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400543 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200544 }
Dan Williams0c9ca6902007-08-02 10:43:44 -0400545 adhs->capability = cpu_to_le16(tmpcap);
546
547 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400548 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549
Dan Williams8c512762007-08-02 11:40:45 -0400550 memset(adhs->rates, 0, sizeof(adhs->rates));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 if (adapter->adhoc_grate_enabled) {
Dan Williams8c512762007-08-02 11:40:45 -0400552 ratesize = min(sizeof(adhs->rates), sizeof(libertas_bg_rates));
553 memcpy(adhs->rates, libertas_bg_rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554 } else {
Dan Williams8c512762007-08-02 11:40:45 -0400555 ratesize = min(sizeof(adhs->rates), sizeof(adhoc_rates_b));
556 memcpy(adhs->rates, adhoc_rates_b, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557 }
558
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200559 /* Copy the ad-hoc creating rates into Current BSS state structure */
Dan Williams8c512762007-08-02 11:40:45 -0400560 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
561 memcpy(&adapter->curbssparams.rates, &adhs->rates, ratesize);
562
563 /* Set MSB on basic rates as the firmware requires, but _after_
564 * copying to current bss rates.
565 */
566 libertas_set_basic_rate_flags(adhs->rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567
Holger Schurig9012b282007-05-25 11:27:16 -0400568 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
Dan Williams8c512762007-08-02 11:40:45 -0400569 adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570
Holger Schurig9012b282007-05-25 11:27:16 -0400571 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200572
573 if (libertas_create_dnld_countryinfo_11d(priv)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400574 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 ret = -1;
576 goto done;
577 }
578
David Woodhouse981f1872007-05-25 23:36:54 -0400579 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
580 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581
582 ret = 0;
583done:
Holger Schurig9012b282007-05-25 11:27:16 -0400584 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585 return ret;
586}
587
588int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
589 struct cmd_ds_command *cmd)
590{
Dan Williams0aef64d2007-08-02 11:31:18 -0400591 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200592 cmd->size = cpu_to_le16(S_DS_GEN);
593
594 return 0;
595}
596
597int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
598 struct cmd_ds_command *cmd, void *pdata_buf)
599{
600 wlan_adapter *adapter = priv->adapter;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400601 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
Dan Williamse76850d2007-05-25 17:09:41 -0400602 struct assoc_request * assoc_req = pdata_buf;
603 struct bss_descriptor *bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 int cmdappendsize = 0;
605 int ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400606 u16 ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607
Holger Schurig9012b282007-05-25 11:27:16 -0400608 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609
Dan Williams0aef64d2007-08-02 11:31:18 -0400610 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
Dan Williams0aef64d2007-08-02 11:31:18 -0400612 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400613 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614
Dan Williams0c9ca6902007-08-02 10:43:44 -0400615 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
616 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617
Dan Williams0c9ca6902007-08-02 10:43:44 -0400618 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
619 sizeof(union ieeetypes_phyparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620
Dan Williams0c9ca6902007-08-02 10:43:44 -0400621 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
622 sizeof(union IEEEtypes_ssparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623
Dan Williams0c9ca6902007-08-02 10:43:44 -0400624 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
Holger Schurig9012b282007-05-25 11:27:16 -0400625 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400626 bss->capability, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627
628 /* information on BSSID descriptor passed to FW */
Dan Williamse76850d2007-05-25 17:09:41 -0400629 lbs_deb_join(
630 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400631 MAC_ARG(join_cmd->bss.bssid), join_cmd->bss.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200632
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 /* failtimeout */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400634 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635
636 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400637 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638
Dan Williamse76850d2007-05-25 17:09:41 -0400639 adapter->curbssparams.channel = bss->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200640
Dan Williams8c512762007-08-02 11:40:45 -0400641 /* Copy Data rates from the rates recorded in scan response */
642 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
643 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
644 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
645 if (get_common_rates(adapter, join_cmd->bss.rates, &ratesize)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400646 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 ret = -1;
648 goto done;
649 }
650
Dan Williams8c512762007-08-02 11:40:45 -0400651 /* Copy the ad-hoc creating rates into Current BSS state structure */
652 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
653 memcpy(&adapter->curbssparams.rates, join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200654
Dan Williams8c512762007-08-02 11:40:45 -0400655 /* Set MSB on basic rates as the firmware requires, but _after_
656 * copying to current bss rates.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 */
Dan Williams8c512762007-08-02 11:40:45 -0400658 libertas_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200659
Dan Williams0c9ca6902007-08-02 10:43:44 -0400660 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
Dan Williamse76850d2007-05-25 17:09:41 -0400661 cpu_to_le16(bss->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200662
Dan Williamse76850d2007-05-25 17:09:41 -0400663 if (assoc_req->secinfo.wep_enabled) {
Dan Williams0c9ca6902007-08-02 10:43:44 -0400664 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
665 tmp |= WLAN_CAPABILITY_PRIVACY;
666 join_cmd->bss.capability = cpu_to_le16(tmp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200667 }
668
Dan Williams0aef64d2007-08-02 11:31:18 -0400669 if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200670 /* wake up first */
David Woodhouse981f1872007-05-25 23:36:54 -0400671 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672
Dan Williams0aef64d2007-08-02 11:31:18 -0400673 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400675 CMD_802_11_PS_MODE,
676 CMD_ACT_SET,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677 0, 0, &Localpsmode);
678
679 if (ret) {
680 ret = -1;
681 goto done;
682 }
683 }
684
Dan Williamse76850d2007-05-25 17:09:41 -0400685 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 ret = -1;
687 goto done;
688 }
689
David Woodhouse981f1872007-05-25 23:36:54 -0400690 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
691 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200692
Holger Schurig9012b282007-05-25 11:27:16 -0400693done:
694 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200695 return ret;
696}
697
698int libertas_ret_80211_associate(wlan_private * priv,
699 struct cmd_ds_command *resp)
700{
701 wlan_adapter *adapter = priv->adapter;
702 int ret = 0;
703 union iwreq_data wrqu;
704 struct ieeetypes_assocrsp *passocrsp;
Dan Williamse76850d2007-05-25 17:09:41 -0400705 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706
Holger Schurig9012b282007-05-25 11:27:16 -0400707 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200708
Dan Williamse76850d2007-05-25 17:09:41 -0400709 if (!adapter->in_progress_assoc_req) {
710 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
711 ret = -1;
712 goto done;
713 }
714 bss = &adapter->in_progress_assoc_req->bss;
715
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
717
David Woodhouse981f1872007-05-25 23:36:54 -0400718 if (le16_to_cpu(passocrsp->statuscode)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200719 libertas_mac_event_disconnected(priv);
720
Dan Williamse76850d2007-05-25 17:09:41 -0400721 lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400722 le16_to_cpu(passocrsp->statuscode));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200723
724 ret = -1;
725 goto done;
726 }
727
728 lbs_dbg_hex("ASSOC_RESP:", (void *)&resp->params,
729 le16_to_cpu(resp->size) - S_DS_GEN);
730
731 /* Send a Media Connected event, according to the Spec */
Dan Williams0aef64d2007-08-02 11:31:18 -0400732 adapter->connect_status = LIBERTAS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200733
Dan Williamsd8efea22007-05-28 23:54:55 -0400734 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
735 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200736
Dan Williamse76850d2007-05-25 17:09:41 -0400737 /* Update current SSID and BSSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400738 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
739 adapter->curbssparams.ssid_len = bss->ssid_len;
Dan Williamse76850d2007-05-25 17:09:41 -0400740 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741
Holger Schurig9012b282007-05-25 11:27:16 -0400742 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743 adapter->currentpacketfilter);
744
745 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
746 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
747
748 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
749 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
750 adapter->nextSNRNF = 0;
751 adapter->numSNRNF = 0;
752
Holger Schurig634b8f42007-05-25 13:05:16 -0400753 netif_carrier_on(priv->dev);
754 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755
Javier Cardona51d84f52007-05-25 12:06:56 -0400756 netif_carrier_on(priv->mesh_dev);
757 netif_wake_queue(priv->mesh_dev);
758
Holger Schurig9012b282007-05-25 11:27:16 -0400759 lbs_deb_join("ASSOC_RESP: Associated \n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760
761 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
762 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400763 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764
Holger Schurig9012b282007-05-25 11:27:16 -0400765done:
766 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200767 return ret;
768}
769
770int libertas_ret_80211_disassociate(wlan_private * priv,
771 struct cmd_ds_command *resp)
772{
Holger Schurig9012b282007-05-25 11:27:16 -0400773 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774
775 libertas_mac_event_disconnected(priv);
776
Holger Schurig9012b282007-05-25 11:27:16 -0400777 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778 return 0;
779}
780
781int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
782 struct cmd_ds_command *resp)
783{
784 wlan_adapter *adapter = priv->adapter;
785 int ret = 0;
786 u16 command = le16_to_cpu(resp->command);
787 u16 result = le16_to_cpu(resp->result);
788 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
789 union iwreq_data wrqu;
Dan Williamse76850d2007-05-25 17:09:41 -0400790 struct bss_descriptor *bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791
Holger Schurig9012b282007-05-25 11:27:16 -0400792 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
794 padhocresult = &resp->params.result;
795
Dan Williamse76850d2007-05-25 17:09:41 -0400796 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
797 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
798 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799
Dan Williamse76850d2007-05-25 17:09:41 -0400800 if (!adapter->in_progress_assoc_req) {
801 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
802 ret = -1;
803 goto done;
804 }
805 bss = &adapter->in_progress_assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200806
807 /*
808 * Join result code 0 --> SUCCESS
809 */
810 if (result) {
Dan Williamse76850d2007-05-25 17:09:41 -0400811 lbs_deb_join("ADHOC_RESP: failed\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400812 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813 libertas_mac_event_disconnected(priv);
814 }
Holger Schurig9012b282007-05-25 11:27:16 -0400815 ret = -1;
816 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817 }
818
819 /*
820 * Now the join cmd should be successful
821 * If BSSID has changed use SSID to compare instead of BSSID
822 */
Dan Williamsd8efea22007-05-28 23:54:55 -0400823 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
824 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200825
826 /* Send a Media Connected event, according to the Spec */
Dan Williams0aef64d2007-08-02 11:31:18 -0400827 adapter->connect_status = LIBERTAS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200828
Dan Williams0aef64d2007-08-02 11:31:18 -0400829 if (command == CMD_RET_802_11_AD_HOC_START) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200830 /* Update the created network descriptor with the new BSSID */
Dan Williamsea8da922007-08-02 11:18:23 -0400831 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200832 }
833
834 /* Set the BSSID from the joined/started descriptor */
Dan Williamse76850d2007-05-25 17:09:41 -0400835 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836
837 /* Set the new SSID to current SSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400838 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
839 adapter->curbssparams.ssid_len = bss->ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840
Holger Schurig634b8f42007-05-25 13:05:16 -0400841 netif_carrier_on(priv->dev);
842 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200843
Javier Cardona51d84f52007-05-25 12:06:56 -0400844 netif_carrier_on(priv->mesh_dev);
845 netif_wake_queue(priv->mesh_dev);
846
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200847 memset(&wrqu, 0, sizeof(wrqu));
848 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
849 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400850 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200851
Holger Schurig9012b282007-05-25 11:27:16 -0400852 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400853 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
Dan Williams02eb2292007-05-25 17:27:31 -0400854 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
Dan Williams2ca10e62007-08-02 11:31:49 -0400855 MAC_ARG(padhocresult->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856
Holger Schurig9012b282007-05-25 11:27:16 -0400857done:
858 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859 return ret;
860}
861
862int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
863 struct cmd_ds_command *resp)
864{
Holger Schurig9012b282007-05-25 11:27:16 -0400865 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866
867 libertas_mac_event_disconnected(priv);
868
Holger Schurig9012b282007-05-25 11:27:16 -0400869 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870 return 0;
871}