blob: 0bded0c91495075e6eb225619fddc132e1d7e02b [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 */
Holger Schurigc23a24f2007-08-02 11:45:30 -040021static u8 adhoc_rates_b[5] = { 0x02, 0x04, 0x0b, 0x16, 0x00 };
Dan Williams8c512762007-08-02 11:40:45 -040022
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
Holger Schurigece56192007-08-02 11:53:06 -040054 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
55 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates);
56 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size);
Dan Williams8c512762007-08-02 11:40:45 -040057 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 -0200115/**
116 * @brief Associate to a specific BSS discovered in a scan
117 *
118 * @param priv A pointer to wlan_private structure
119 * @param pbssdesc Pointer to the BSS descriptor to associate with.
120 *
121 * @return 0-success, otherwise fail
122 */
Dan Williamse76850d2007-05-25 17:09:41 -0400123int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124{
125 wlan_adapter *adapter = priv->adapter;
126 int ret;
127
Holger Schurig9012b282007-05-25 11:27:16 -0400128 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129
Dan Williams0aef64d2007-08-02 11:31:18 -0400130 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
131 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400132 0, assoc_req->bss.bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133
Holger Schurig9012b282007-05-25 11:27:16 -0400134 if (ret)
135 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136
137 /* set preamble to firmware */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400138 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
139 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
Dan Williams0aef64d2007-08-02 11:31:18 -0400140 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141 else
Dan Williams0aef64d2007-08-02 11:31:18 -0400142 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143
144 libertas_set_radio_control(priv);
145
Dan Williams0aef64d2007-08-02 11:31:18 -0400146 ret = libertas_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
147 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148
Holger Schurig9012b282007-05-25 11:27:16 -0400149done:
150 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200151 return ret;
152}
153
154/**
155 * @brief Start an Adhoc Network
156 *
157 * @param priv A pointer to wlan_private structure
158 * @param adhocssid The ssid of the Adhoc Network
159 * @return 0--success, -1--fail
160 */
Dan Williamse76850d2007-05-25 17:09:41 -0400161int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162{
163 wlan_adapter *adapter = priv->adapter;
164 int ret = 0;
165
166 adapter->adhoccreate = 1;
167
Dan Williams0c9ca6902007-08-02 10:43:44 -0400168 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400169 lbs_deb_join("AdhocStart: Short preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400170 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400171 } else {
172 lbs_deb_join("AdhocStart: Long preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400173 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174 }
175
176 libertas_set_radio_control(priv);
177
Dan Williamse76850d2007-05-25 17:09:41 -0400178 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
179 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180
Dan Williams0aef64d2007-08-02 11:31:18 -0400181 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
182 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183
184 return ret;
185}
186
187/**
188 * @brief Join an adhoc network found in a previous scan
189 *
190 * @param priv A pointer to wlan_private structure
191 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
192 * to attempt to join
193 *
194 * @return 0--success, -1--fail
195 */
Dan Williamse76850d2007-05-25 17:09:41 -0400196int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197{
198 wlan_adapter *adapter = priv->adapter;
Dan Williamse76850d2007-05-25 17:09:41 -0400199 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200 int ret = 0;
201
Dan Williamsd8efea22007-05-28 23:54:55 -0400202 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
203 __func__,
204 escape_essid(adapter->curbssparams.ssid,
205 adapter->curbssparams.ssid_len),
206 adapter->curbssparams.ssid_len);
207 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
208 __func__, escape_essid(bss->ssid, bss->ssid_len),
209 bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200210
211 /* check if the requested SSID is already joined */
Dan Williamsd8efea22007-05-28 23:54:55 -0400212 if (adapter->curbssparams.ssid_len
Dan Williams717c9332007-05-29 00:03:31 -0400213 && !libertas_ssid_cmp(adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400214 adapter->curbssparams.ssid_len,
215 bss->ssid, bss->ssid_len)
Dan Williams0dc5a292007-05-10 22:58:02 -0400216 && (adapter->mode == IW_MODE_ADHOC)) {
Dan Williamse76850d2007-05-25 17:09:41 -0400217 lbs_deb_join(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200218 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
219 "not attempting to re-join");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 return -1;
221 }
222
Dan Williams0c9ca6902007-08-02 10:43:44 -0400223 /* Use shortpreamble only when both creator and card supports
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224 short preamble */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400225 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
226 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400227 lbs_deb_join("AdhocJoin: Long preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400228 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400230 lbs_deb_join("AdhocJoin: Short preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400231 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232 }
233
234 libertas_set_radio_control(priv);
235
Dan Williamse76850d2007-05-25 17:09:41 -0400236 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
237 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238
239 adapter->adhoccreate = 0;
240
Dan Williams0aef64d2007-08-02 11:31:18 -0400241 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
242 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400243 OID_802_11_SSID, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244
245 return ret;
246}
247
248int libertas_stop_adhoc_network(wlan_private * priv)
249{
Dan Williams0aef64d2007-08-02 11:31:18 -0400250 return libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
251 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252}
253
254/**
255 * @brief Send Deauthentication Request
256 *
257 * @param priv A pointer to wlan_private structure
258 * @return 0--success, -1--fail
259 */
260int libertas_send_deauthentication(wlan_private * priv)
261{
Dan Williams0aef64d2007-08-02 11:31:18 -0400262 return libertas_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
263 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264}
265
266/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200267 * @brief This function prepares command of authenticate.
268 *
269 * @param priv A pointer to wlan_private structure
270 * @param cmd A pointer to cmd_ds_command structure
271 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
272 *
273 * @return 0 or -1
274 */
275int libertas_cmd_80211_authenticate(wlan_private * priv,
276 struct cmd_ds_command *cmd,
277 void *pdata_buf)
278{
279 wlan_adapter *adapter = priv->adapter;
Dan Williams6affe782007-05-10 22:56:42 -0400280 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
281 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 u8 *bssid = pdata_buf;
283
Dan Williams45f43de2007-05-25 22:58:55 -0400284 lbs_deb_enter(LBS_DEB_JOIN);
285
Dan Williams0aef64d2007-08-02 11:31:18 -0400286 cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE);
Dan Williams6affe782007-05-10 22:56:42 -0400287 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
288 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289
Dan Williams6affe782007-05-10 22:56:42 -0400290 /* translate auth mode to 802.11 defined wire value */
291 switch (adapter->secinfo.auth_mode) {
292 case IW_AUTH_ALG_OPEN_SYSTEM:
293 pauthenticate->authtype = 0x00;
294 break;
295 case IW_AUTH_ALG_SHARED_KEY:
296 pauthenticate->authtype = 0x01;
297 break;
298 case IW_AUTH_ALG_LEAP:
299 pauthenticate->authtype = 0x80;
300 break;
301 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400302 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
Dan Williams6affe782007-05-10 22:56:42 -0400303 adapter->secinfo.auth_mode);
304 goto out;
305 }
306
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
308
Dan Williams45f43de2007-05-25 22:58:55 -0400309 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
310 MAC_ARG(bssid), pauthenticate->authtype);
Dan Williams6affe782007-05-10 22:56:42 -0400311 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312
Dan Williams6affe782007-05-10 22:56:42 -0400313out:
Dan Williams45f43de2007-05-25 22:58:55 -0400314 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Dan Williams6affe782007-05-10 22:56:42 -0400315 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316}
317
318int libertas_cmd_80211_deauthenticate(wlan_private * priv,
319 struct cmd_ds_command *cmd)
320{
321 wlan_adapter *adapter = priv->adapter;
322 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
323
Holger Schurig9012b282007-05-25 11:27:16 -0400324 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325
Dan Williams0aef64d2007-08-02 11:31:18 -0400326 cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE);
David Woodhouse981f1872007-05-25 23:36:54 -0400327 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328 S_DS_GEN);
329
330 /* set AP MAC address */
David Woodhouse981f1872007-05-25 23:36:54 -0400331 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200332
333 /* Reason code 3 = Station is leaving */
334#define REASON_CODE_STA_LEAVING 3
335 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
336
Holger Schurig9012b282007-05-25 11:27:16 -0400337 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 return 0;
339}
340
341int libertas_cmd_80211_associate(wlan_private * priv,
342 struct cmd_ds_command *cmd, void *pdata_buf)
343{
344 wlan_adapter *adapter = priv->adapter;
345 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
346 int ret = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400347 struct assoc_request * assoc_req = pdata_buf;
348 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 u8 *pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400350 u16 tmpcap, tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200351 struct mrvlietypes_ssidparamset *ssid;
352 struct mrvlietypes_phyparamset *phy;
353 struct mrvlietypes_ssparamset *ss;
354 struct mrvlietypes_ratesparamset *rates;
355 struct mrvlietypes_rsnparamset *rsn;
356
Holger Schurig9012b282007-05-25 11:27:16 -0400357 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359 pos = (u8 *) passo;
360
361 if (!adapter) {
362 ret = -1;
363 goto done;
364 }
365
Dan Williams0aef64d2007-08-02 11:31:18 -0400366 cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367
Dan Williamse76850d2007-05-25 17:09:41 -0400368 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 pos += sizeof(passo->peerstaaddr);
370
371 /* set the listen interval */
David Woodhouse981f1872007-05-25 23:36:54 -0400372 passo->listeninterval = cpu_to_le16(adapter->listeninterval);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373
Dan Williams0c9ca6902007-08-02 10:43:44 -0400374 pos += sizeof(passo->capability);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375 pos += sizeof(passo->listeninterval);
376 pos += sizeof(passo->bcnperiod);
377 pos += sizeof(passo->dtimperiod);
378
379 ssid = (struct mrvlietypes_ssidparamset *) pos;
380 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
Dan Williamsd8efea22007-05-28 23:54:55 -0400381 tmplen = bss->ssid_len;
David Woodhouse707985b2007-05-25 23:41:16 -0400382 ssid->header.len = cpu_to_le16(tmplen);
Dan Williamsd8efea22007-05-28 23:54:55 -0400383 memcpy(ssid->ssid, bss->ssid, tmplen);
David Woodhouse707985b2007-05-25 23:41:16 -0400384 pos += sizeof(ssid->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385
386 phy = (struct mrvlietypes_phyparamset *) pos;
387 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
David Woodhouse707985b2007-05-25 23:41:16 -0400388 tmplen = sizeof(phy->fh_ds.dsparamset);
389 phy->header.len = cpu_to_le16(tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390 memcpy(&phy->fh_ds.dsparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400391 &bss->phyparamset.dsparamset.currentchan,
David Woodhouse707985b2007-05-25 23:41:16 -0400392 tmplen);
393 pos += sizeof(phy->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394
395 ss = (struct mrvlietypes_ssparamset *) pos;
396 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
David Woodhouse707985b2007-05-25 23:41:16 -0400397 tmplen = sizeof(ss->cf_ibss.cfparamset);
398 ss->header.len = cpu_to_le16(tmplen);
399 pos += sizeof(ss->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
401 rates = (struct mrvlietypes_ratesparamset *) pos;
402 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400403 memcpy(&rates->rates, &bss->rates, MAX_RATES);
404 tmplen = MAX_RATES;
405 if (get_common_rates(adapter, rates->rates, &tmplen)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406 ret = -1;
407 goto done;
408 }
David Woodhouse981f1872007-05-25 23:36:54 -0400409 pos += sizeof(rates->header) + tmplen;
410 rates->header.len = cpu_to_le16(tmplen);
Dan Williams8c512762007-08-02 11:40:45 -0400411 lbs_deb_join("ASSOC_CMD: num rates = %u\n", tmplen);
412
413 /* Copy the infra. association rates into Current BSS state structure */
414 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
415 memcpy(&adapter->curbssparams.rates, &rates->rates, tmplen);
416
417 /* Set MSB on basic rates as the firmware requires, but _after_
418 * copying to current bss rates.
419 */
420 libertas_set_basic_rate_flags(rates->rates, tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421
Dan Williamse76850d2007-05-25 17:09:41 -0400422 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423 rsn = (struct mrvlietypes_rsnparamset *) pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400424 /* WPA_IE or WPA2_IE */
425 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
426 tmplen = (u16) assoc_req->wpa_ie[1];
427 rsn->header.len = cpu_to_le16(tmplen);
428 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
Holger Schurigece56192007-08-02 11:53:06 -0400429 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn,
David Woodhouse981f1872007-05-25 23:36:54 -0400430 sizeof(rsn->header) + tmplen);
431 pos += sizeof(rsn->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432 }
433
434 /* update curbssparams */
David Woodhouse981f1872007-05-25 23:36:54 -0400435 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436
Dan Williamse76850d2007-05-25 17:09:41 -0400437 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438 ret = -1;
439 goto done;
440 }
441
442 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
443
Dan Williams0c9ca6902007-08-02 10:43:44 -0400444 /* set the capability info */
445 tmpcap = (bss->capability & CAPINFO_MASK);
446 if (bss->mode == IW_MODE_INFRA)
447 tmpcap |= WLAN_CAPABILITY_ESS;
448 passo->capability = cpu_to_le16(tmpcap);
449 lbs_deb_join("ASSOC_CMD: capability=%4X CAPINFO_MASK=%4X\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400450 tmpcap, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451
Holger Schurig9012b282007-05-25 11:27:16 -0400452done:
453 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200454 return ret;
455}
456
457int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400458 struct cmd_ds_command *cmd, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459{
460 wlan_adapter *adapter = priv->adapter;
461 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
462 int ret = 0;
463 int cmdappendsize = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400464 struct assoc_request * assoc_req = pdata_buf;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400465 u16 tmpcap = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400466 size_t ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467
Holger Schurig9012b282007-05-25 11:27:16 -0400468 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469
470 if (!adapter) {
471 ret = -1;
472 goto done;
473 }
474
Dan Williams0aef64d2007-08-02 11:31:18 -0400475 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477 /*
478 * Fill in the parameters for 2 data structures:
479 * 1. cmd_ds_802_11_ad_hoc_start command
480 * 2. adapter->scantable[i]
481 *
482 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
483 * probe delay, and cap info.
484 *
485 * Firmware will fill up beacon period, DTIM, Basic rates
486 * and operational rates.
487 */
488
Dan Williamsb44898e2007-08-02 11:18:40 -0400489 memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE);
490 memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491
Dan Williamsd8efea22007-05-28 23:54:55 -0400492 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
493 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
494 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 /* set the BSS type */
Dan Williams0aef64d2007-08-02 11:31:18 -0400497 adhs->bsstype = CMD_BSS_TYPE_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400498 adapter->mode = IW_MODE_ADHOC;
David Woodhouse981f1872007-05-25 23:36:54 -0400499 adhs->beaconperiod = cpu_to_le16(adapter->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200500
501 /* set Physical param set */
502#define DS_PARA_IE_ID 3
503#define DS_PARA_IE_LEN 1
504
505 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
506 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
507
Dan Williamse76850d2007-05-25 17:09:41 -0400508 WARN_ON(!assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
Holger Schurig9012b282007-05-25 11:27:16 -0400510 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400511 assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512
Dan Williamse76850d2007-05-25 17:09:41 -0400513 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514
515 /* set IBSS param set */
516#define IBSS_PARA_IE_ID 6
517#define IBSS_PARA_IE_LEN 2
518
519 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
520 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
Holger Schurigae596ce2007-08-02 13:10:05 -0400521 adhs->ssparamset.ibssparamset.atimwindow = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522
523 /* set capability info */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400524 tmpcap = WLAN_CAPABILITY_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400525 if (assoc_req->secinfo.wep_enabled) {
Holger Schurig9012b282007-05-25 11:27:16 -0400526 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
Dan Williams0c9ca6902007-08-02 10:43:44 -0400527 tmpcap |= WLAN_CAPABILITY_PRIVACY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400529 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530 }
Dan Williams0c9ca6902007-08-02 10:43:44 -0400531 adhs->capability = cpu_to_le16(tmpcap);
532
533 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400534 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535
Dan Williams8c512762007-08-02 11:40:45 -0400536 memset(adhs->rates, 0, sizeof(adhs->rates));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537 if (adapter->adhoc_grate_enabled) {
Dan Williams8c512762007-08-02 11:40:45 -0400538 ratesize = min(sizeof(adhs->rates), sizeof(libertas_bg_rates));
539 memcpy(adhs->rates, libertas_bg_rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200540 } else {
Dan Williams8c512762007-08-02 11:40:45 -0400541 ratesize = min(sizeof(adhs->rates), sizeof(adhoc_rates_b));
542 memcpy(adhs->rates, adhoc_rates_b, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 }
544
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545 /* Copy the ad-hoc creating rates into Current BSS state structure */
Dan Williams8c512762007-08-02 11:40:45 -0400546 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
547 memcpy(&adapter->curbssparams.rates, &adhs->rates, ratesize);
548
549 /* Set MSB on basic rates as the firmware requires, but _after_
550 * copying to current bss rates.
551 */
552 libertas_set_basic_rate_flags(adhs->rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553
Holger Schurig9012b282007-05-25 11:27:16 -0400554 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
Dan Williams8c512762007-08-02 11:40:45 -0400555 adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556
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
David Woodhouse981f1872007-05-25 23:36:54 -0400565 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
566 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567
568 ret = 0;
569done:
Holger Schurig9012b282007-05-25 11:27:16 -0400570 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571 return ret;
572}
573
574int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
575 struct cmd_ds_command *cmd)
576{
Dan Williams0aef64d2007-08-02 11:31:18 -0400577 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578 cmd->size = cpu_to_le16(S_DS_GEN);
579
580 return 0;
581}
582
583int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
584 struct cmd_ds_command *cmd, void *pdata_buf)
585{
586 wlan_adapter *adapter = priv->adapter;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400587 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
Dan Williamse76850d2007-05-25 17:09:41 -0400588 struct assoc_request * assoc_req = pdata_buf;
589 struct bss_descriptor *bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590 int cmdappendsize = 0;
591 int ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400592 u16 ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593
Holger Schurig9012b282007-05-25 11:27:16 -0400594 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595
Dan Williams0aef64d2007-08-02 11:31:18 -0400596 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597
Dan Williams0aef64d2007-08-02 11:31:18 -0400598 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400599 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600
Dan Williams0c9ca6902007-08-02 10:43:44 -0400601 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
602 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603
Dan Williams0c9ca6902007-08-02 10:43:44 -0400604 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
605 sizeof(union ieeetypes_phyparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606
Dan Williams0c9ca6902007-08-02 10:43:44 -0400607 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
608 sizeof(union IEEEtypes_ssparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609
Dan Williams0c9ca6902007-08-02 10:43:44 -0400610 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
Holger Schurig9012b282007-05-25 11:27:16 -0400611 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400612 bss->capability, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613
614 /* information on BSSID descriptor passed to FW */
Dan Williamse76850d2007-05-25 17:09:41 -0400615 lbs_deb_join(
616 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400617 MAC_ARG(join_cmd->bss.bssid), join_cmd->bss.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619 /* failtimeout */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400620 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621
622 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400623 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624
Dan Williamse76850d2007-05-25 17:09:41 -0400625 adapter->curbssparams.channel = bss->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626
Dan Williams8c512762007-08-02 11:40:45 -0400627 /* Copy Data rates from the rates recorded in scan response */
628 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
629 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
630 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
631 if (get_common_rates(adapter, join_cmd->bss.rates, &ratesize)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400632 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 ret = -1;
634 goto done;
635 }
636
Dan Williams8c512762007-08-02 11:40:45 -0400637 /* Copy the ad-hoc creating rates into Current BSS state structure */
638 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
639 memcpy(&adapter->curbssparams.rates, join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200640
Dan Williams8c512762007-08-02 11:40:45 -0400641 /* Set MSB on basic rates as the firmware requires, but _after_
642 * copying to current bss rates.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 */
Dan Williams8c512762007-08-02 11:40:45 -0400644 libertas_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645
Dan Williams0c9ca6902007-08-02 10:43:44 -0400646 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
Dan Williamse76850d2007-05-25 17:09:41 -0400647 cpu_to_le16(bss->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200648
Dan Williamse76850d2007-05-25 17:09:41 -0400649 if (assoc_req->secinfo.wep_enabled) {
Dan Williams0c9ca6902007-08-02 10:43:44 -0400650 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
651 tmp |= WLAN_CAPABILITY_PRIVACY;
652 join_cmd->bss.capability = cpu_to_le16(tmp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 }
654
Dan Williams0aef64d2007-08-02 11:31:18 -0400655 if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200656 /* wake up first */
David Woodhouse981f1872007-05-25 23:36:54 -0400657 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200658
Dan Williams0aef64d2007-08-02 11:31:18 -0400659 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400661 CMD_802_11_PS_MODE,
662 CMD_ACT_SET,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663 0, 0, &Localpsmode);
664
665 if (ret) {
666 ret = -1;
667 goto done;
668 }
669 }
670
Dan Williamse76850d2007-05-25 17:09:41 -0400671 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672 ret = -1;
673 goto done;
674 }
675
David Woodhouse981f1872007-05-25 23:36:54 -0400676 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
677 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678
Holger Schurig9012b282007-05-25 11:27:16 -0400679done:
680 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200681 return ret;
682}
683
684int libertas_ret_80211_associate(wlan_private * priv,
685 struct cmd_ds_command *resp)
686{
687 wlan_adapter *adapter = priv->adapter;
688 int ret = 0;
689 union iwreq_data wrqu;
690 struct ieeetypes_assocrsp *passocrsp;
Dan Williamse76850d2007-05-25 17:09:41 -0400691 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200692
Holger Schurig9012b282007-05-25 11:27:16 -0400693 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694
Dan Williamse76850d2007-05-25 17:09:41 -0400695 if (!adapter->in_progress_assoc_req) {
696 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
697 ret = -1;
698 goto done;
699 }
700 bss = &adapter->in_progress_assoc_req->bss;
701
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200702 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
703
David Woodhouse981f1872007-05-25 23:36:54 -0400704 if (le16_to_cpu(passocrsp->statuscode)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705 libertas_mac_event_disconnected(priv);
706
Dan Williamse76850d2007-05-25 17:09:41 -0400707 lbs_deb_join("ASSOC_RESP: Association failed, status code = %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400708 le16_to_cpu(passocrsp->statuscode));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709
710 ret = -1;
711 goto done;
712 }
713
Holger Schurigece56192007-08-02 11:53:06 -0400714 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_RESP", (void *)&resp->params,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715 le16_to_cpu(resp->size) - S_DS_GEN);
716
717 /* Send a Media Connected event, according to the Spec */
Dan Williams0aef64d2007-08-02 11:31:18 -0400718 adapter->connect_status = LIBERTAS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200719
Dan Williamsd8efea22007-05-28 23:54:55 -0400720 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
721 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722
Dan Williamse76850d2007-05-25 17:09:41 -0400723 /* Update current SSID and BSSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400724 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
725 adapter->curbssparams.ssid_len = bss->ssid_len;
Dan Williamse76850d2007-05-25 17:09:41 -0400726 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727
Holger Schurig9012b282007-05-25 11:27:16 -0400728 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729 adapter->currentpacketfilter);
730
731 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
732 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
733
734 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
735 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
736 adapter->nextSNRNF = 0;
737 adapter->numSNRNF = 0;
738
Holger Schurig634b8f42007-05-25 13:05:16 -0400739 netif_carrier_on(priv->dev);
740 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741
Holger Schurig3cf84092007-08-02 11:50:12 -0400742 if (priv->mesh_dev) {
743 netif_carrier_on(priv->mesh_dev);
744 netif_wake_queue(priv->mesh_dev);
745 }
Javier Cardona51d84f52007-05-25 12:06:56 -0400746
Holger Schurig9012b282007-05-25 11:27:16 -0400747 lbs_deb_join("ASSOC_RESP: Associated \n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748
749 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
750 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400751 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752
Holger Schurig9012b282007-05-25 11:27:16 -0400753done:
754 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755 return ret;
756}
757
758int libertas_ret_80211_disassociate(wlan_private * priv,
759 struct cmd_ds_command *resp)
760{
Holger Schurig9012b282007-05-25 11:27:16 -0400761 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762
763 libertas_mac_event_disconnected(priv);
764
Holger Schurig9012b282007-05-25 11:27:16 -0400765 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766 return 0;
767}
768
769int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
770 struct cmd_ds_command *resp)
771{
772 wlan_adapter *adapter = priv->adapter;
773 int ret = 0;
774 u16 command = le16_to_cpu(resp->command);
775 u16 result = le16_to_cpu(resp->result);
776 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
777 union iwreq_data wrqu;
Dan Williamse76850d2007-05-25 17:09:41 -0400778 struct bss_descriptor *bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779
Holger Schurig9012b282007-05-25 11:27:16 -0400780 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781
782 padhocresult = &resp->params.result;
783
Dan Williamse76850d2007-05-25 17:09:41 -0400784 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
785 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
786 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200787
Dan Williamse76850d2007-05-25 17:09:41 -0400788 if (!adapter->in_progress_assoc_req) {
789 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
790 ret = -1;
791 goto done;
792 }
793 bss = &adapter->in_progress_assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794
795 /*
796 * Join result code 0 --> SUCCESS
797 */
798 if (result) {
Dan Williamse76850d2007-05-25 17:09:41 -0400799 lbs_deb_join("ADHOC_RESP: failed\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400800 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 libertas_mac_event_disconnected(priv);
802 }
Holger Schurig9012b282007-05-25 11:27:16 -0400803 ret = -1;
804 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805 }
806
807 /*
808 * Now the join cmd should be successful
809 * If BSSID has changed use SSID to compare instead of BSSID
810 */
Dan Williamsd8efea22007-05-28 23:54:55 -0400811 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
812 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813
814 /* Send a Media Connected event, according to the Spec */
Dan Williams0aef64d2007-08-02 11:31:18 -0400815 adapter->connect_status = LIBERTAS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816
Holger Schurig6b63cd02007-08-02 11:53:36 -0400817 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818 /* Update the created network descriptor with the new BSSID */
Dan Williamsea8da922007-08-02 11:18:23 -0400819 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 }
821
822 /* Set the BSSID from the joined/started descriptor */
Dan Williamse76850d2007-05-25 17:09:41 -0400823 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200824
825 /* Set the new SSID to current SSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400826 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
827 adapter->curbssparams.ssid_len = bss->ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200828
Holger Schurig634b8f42007-05-25 13:05:16 -0400829 netif_carrier_on(priv->dev);
830 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831
Holger Schurig3cf84092007-08-02 11:50:12 -0400832 if (priv->mesh_dev) {
833 netif_carrier_on(priv->mesh_dev);
834 netif_wake_queue(priv->mesh_dev);
835 }
Javier Cardona51d84f52007-05-25 12:06:56 -0400836
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200837 memset(&wrqu, 0, sizeof(wrqu));
838 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
839 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400840 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200841
Holger Schurig9012b282007-05-25 11:27:16 -0400842 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400843 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
Dan Williams02eb2292007-05-25 17:27:31 -0400844 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
Dan Williams2ca10e62007-08-02 11:31:49 -0400845 MAC_ARG(padhocresult->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200846
Holger Schurig9012b282007-05-25 11:27:16 -0400847done:
848 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200849 return ret;
850}
851
852int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
853 struct cmd_ds_command *resp)
854{
Holger Schurig9012b282007-05-25 11:27:16 -0400855 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856
857 libertas_mac_event_disconnected(priv);
858
Holger Schurig9012b282007-05-25 11:27:16 -0400859 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860 return 0;
861}