blob: 0ad1362b14e23ccefab8f8d302af69af9cfaa7d9 [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
Luis Carlos Cobob37e5842007-08-02 13:15:40 -040020/* The firmware needs certain bits masked out of the beacon-derviced capability
21 * field when associating/joining to BSSs.
22 */
23#define CAPINFO_MASK (~(0xda00))
Dan Williams8c512762007-08-02 11:40:45 -040024
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020025/**
Dan Williams8c512762007-08-02 11:40:45 -040026 * @brief This function finds common rates between rate1 and card rates.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027 *
28 * It will fill common rates in rate1 as output if found.
29 *
30 * NOTE: Setting the MSB of the basic rates need to be taken
31 * care, either before or after calling this function
32 *
33 * @param adapter A pointer to wlan_adapter structure
34 * @param rate1 the buffer which keeps input and output
Dan Williams8c512762007-08-02 11:40:45 -040035 * @param rate1_size the size of rate1 buffer; new size of buffer on return
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020036 *
37 * @return 0 or -1
38 */
Dan Williams8c512762007-08-02 11:40:45 -040039static int get_common_rates(wlan_adapter * adapter, u8 * rates, u16 *rates_size)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020040{
Dan Williams8c512762007-08-02 11:40:45 -040041 u8 *card_rates = libertas_bg_rates;
42 size_t num_card_rates = sizeof(libertas_bg_rates);
43 int ret = 0, i, j;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020044 u8 tmp[30];
Dan Williams8c512762007-08-02 11:40:45 -040045 size_t tmp_size = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046
Dan Williams8c512762007-08-02 11:40:45 -040047 /* For each rate in card_rates that exists in rate1, copy to tmp */
48 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
49 for (j = 0; rates[j] && (j < *rates_size); j++) {
50 if (rates[j] == card_rates[i])
51 tmp[tmp_size++] = card_rates[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052 }
53 }
54
Holger Schurigece56192007-08-02 11:53:06 -040055 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
56 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates);
57 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size);
Dan Williams8c512762007-08-02 11:40:45 -040058 lbs_deb_join("Tx datarate is currently 0x%X\n", adapter->cur_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020059
Dan Williams8c512762007-08-02 11:40:45 -040060 if (!adapter->auto_rate) {
61 for (i = 0; i < tmp_size; i++) {
62 if (tmp[i] == adapter->cur_rate)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 }
Dan Williams8c512762007-08-02 11:40:45 -040065 lbs_pr_alert("Previously set fixed data rate %#x isn't "
66 "compatible with the network.\n", adapter->cur_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067 ret = -1;
68 goto done;
69 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070 ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -040071
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072done:
Dan Williams8c512762007-08-02 11:40:45 -040073 memset(rates, 0, *rates_size);
74 *rates_size = min_t(int, tmp_size, *rates_size);
75 memcpy(rates, tmp, *rates_size);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 return ret;
77}
78
Dan Williams8c512762007-08-02 11:40:45 -040079
80/**
81 * @brief Sets the MSB on basic rates as the firmware requires
82 *
83 * Scan through an array and set the MSB for basic data rates.
84 *
85 * @param rates buffer of data rates
86 * @param len size of buffer
87 */
88static void libertas_set_basic_rate_flags(u8 * rates, size_t len)
89{
90 int i;
91
92 for (i = 0; i < len; i++) {
93 if (rates[i] == 0x02 || rates[i] == 0x04 ||
94 rates[i] == 0x0b || rates[i] == 0x16)
95 rates[i] |= 0x80;
96 }
97}
98
99/**
100 * @brief Unsets the MSB on basic rates
101 *
102 * Scan through an array and unset the MSB for basic data rates.
103 *
104 * @param rates buffer of data rates
105 * @param len size of buffer
106 */
107void libertas_unset_basic_rate_flags(u8 * rates, size_t len)
108{
109 int i;
110
111 for (i = 0; i < len; i++)
112 rates[i] &= 0x7f;
113}
114
115
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116/**
117 * @brief Associate to a specific BSS discovered in a scan
118 *
119 * @param priv A pointer to wlan_private structure
120 * @param pbssdesc Pointer to the BSS descriptor to associate with.
121 *
122 * @return 0-success, otherwise fail
123 */
Dan Williamse76850d2007-05-25 17:09:41 -0400124int wlan_associate(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125{
126 wlan_adapter *adapter = priv->adapter;
127 int ret;
128
Holger Schurig9012b282007-05-25 11:27:16 -0400129 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
Dan Williams0aef64d2007-08-02 11:31:18 -0400131 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
132 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400133 0, assoc_req->bss.bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134
Holger Schurig9012b282007-05-25 11:27:16 -0400135 if (ret)
136 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137
138 /* set preamble to firmware */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400139 if ( (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
140 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
Dan Williams0aef64d2007-08-02 11:31:18 -0400141 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142 else
Dan Williams0aef64d2007-08-02 11:31:18 -0400143 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144
145 libertas_set_radio_control(priv);
146
Dan Williams0aef64d2007-08-02 11:31:18 -0400147 ret = libertas_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
148 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149
Holger Schurig9012b282007-05-25 11:27:16 -0400150done:
151 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 return ret;
153}
154
155/**
156 * @brief Start an Adhoc Network
157 *
158 * @param priv A pointer to wlan_private structure
159 * @param adhocssid The ssid of the Adhoc Network
160 * @return 0--success, -1--fail
161 */
Dan Williamse76850d2007-05-25 17:09:41 -0400162int libertas_start_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163{
164 wlan_adapter *adapter = priv->adapter;
165 int ret = 0;
166
167 adapter->adhoccreate = 1;
168
Dan Williams0c9ca6902007-08-02 10:43:44 -0400169 if (adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_join("AdhocStart: Short preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400171 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400172 } else {
173 lbs_deb_join("AdhocStart: Long preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400174 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 }
176
177 libertas_set_radio_control(priv);
178
Dan Williamse76850d2007-05-25 17:09:41 -0400179 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
180 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181
Dan Williams0aef64d2007-08-02 11:31:18 -0400182 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
183 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184
185 return ret;
186}
187
188/**
189 * @brief Join an adhoc network found in a previous scan
190 *
191 * @param priv A pointer to wlan_private structure
192 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
193 * to attempt to join
194 *
195 * @return 0--success, -1--fail
196 */
Dan Williamse76850d2007-05-25 17:09:41 -0400197int libertas_join_adhoc_network(wlan_private * priv, struct assoc_request * assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198{
199 wlan_adapter *adapter = priv->adapter;
Dan Williamse76850d2007-05-25 17:09:41 -0400200 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200201 int ret = 0;
202
Dan Williamsd8efea22007-05-28 23:54:55 -0400203 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
204 __func__,
205 escape_essid(adapter->curbssparams.ssid,
206 adapter->curbssparams.ssid_len),
207 adapter->curbssparams.ssid_len);
208 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
209 __func__, escape_essid(bss->ssid, bss->ssid_len),
210 bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211
212 /* check if the requested SSID is already joined */
Dan Williams0edef212007-08-02 13:14:29 -0400213 if ( adapter->curbssparams.ssid_len
Dan Williams717c9332007-05-29 00:03:31 -0400214 && !libertas_ssid_cmp(adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400215 adapter->curbssparams.ssid_len,
216 bss->ssid, bss->ssid_len)
Dan Williams0edef212007-08-02 13:14:29 -0400217 && (adapter->mode == IW_MODE_ADHOC)
218 && (adapter->connect_status == LIBERTAS_CONNECTED)) {
219 union iwreq_data wrqu;
220
221 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
222 "current, not attempting to re-join");
223
224 /* Send the re-association event though, because the association
225 * request really was successful, even if just a null-op.
226 */
227 memset(&wrqu, 0, sizeof(wrqu));
228 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid,
229 ETH_ALEN);
230 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
231 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
232 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233 }
234
Dan Williams0c9ca6902007-08-02 10:43:44 -0400235 /* Use shortpreamble only when both creator and card supports
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236 short preamble */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400237 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
238 || !(adapter->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400239 lbs_deb_join("AdhocJoin: Long preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400240 adapter->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400242 lbs_deb_join("AdhocJoin: Short preamble\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400243 adapter->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 }
245
246 libertas_set_radio_control(priv);
247
Dan Williamse76850d2007-05-25 17:09:41 -0400248 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
249 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250
251 adapter->adhoccreate = 0;
252
Dan Williams0aef64d2007-08-02 11:31:18 -0400253 ret = libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
254 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400255 OID_802_11_SSID, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256
Dan Williams0edef212007-08-02 13:14:29 -0400257out:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258 return ret;
259}
260
261int libertas_stop_adhoc_network(wlan_private * priv)
262{
Dan Williams0aef64d2007-08-02 11:31:18 -0400263 return libertas_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
264 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265}
266
267/**
268 * @brief Send Deauthentication Request
269 *
270 * @param priv A pointer to wlan_private structure
271 * @return 0--success, -1--fail
272 */
273int libertas_send_deauthentication(wlan_private * priv)
274{
Dan Williams0aef64d2007-08-02 11:31:18 -0400275 return libertas_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
276 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200277}
278
279/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280 * @brief This function prepares command of authenticate.
281 *
282 * @param priv A pointer to wlan_private structure
283 * @param cmd A pointer to cmd_ds_command structure
284 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
285 *
286 * @return 0 or -1
287 */
288int libertas_cmd_80211_authenticate(wlan_private * priv,
289 struct cmd_ds_command *cmd,
290 void *pdata_buf)
291{
292 wlan_adapter *adapter = priv->adapter;
Dan Williams6affe782007-05-10 22:56:42 -0400293 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
294 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295 u8 *bssid = pdata_buf;
296
Dan Williams45f43de2007-05-25 22:58:55 -0400297 lbs_deb_enter(LBS_DEB_JOIN);
298
Dan Williams0aef64d2007-08-02 11:31:18 -0400299 cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE);
Dan Williams6affe782007-05-10 22:56:42 -0400300 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
301 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
Dan Williams6affe782007-05-10 22:56:42 -0400303 /* translate auth mode to 802.11 defined wire value */
304 switch (adapter->secinfo.auth_mode) {
305 case IW_AUTH_ALG_OPEN_SYSTEM:
306 pauthenticate->authtype = 0x00;
307 break;
308 case IW_AUTH_ALG_SHARED_KEY:
309 pauthenticate->authtype = 0x01;
310 break;
311 case IW_AUTH_ALG_LEAP:
312 pauthenticate->authtype = 0x80;
313 break;
314 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400315 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
Dan Williams6affe782007-05-10 22:56:42 -0400316 adapter->secinfo.auth_mode);
317 goto out;
318 }
319
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
321
Dan Williams45f43de2007-05-25 22:58:55 -0400322 lbs_deb_join("AUTH_CMD: BSSID is : " MAC_FMT " auth=0x%X\n",
323 MAC_ARG(bssid), pauthenticate->authtype);
Dan Williams6affe782007-05-10 22:56:42 -0400324 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325
Dan Williams6affe782007-05-10 22:56:42 -0400326out:
Dan Williams45f43de2007-05-25 22:58:55 -0400327 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Dan Williams6affe782007-05-10 22:56:42 -0400328 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329}
330
331int libertas_cmd_80211_deauthenticate(wlan_private * priv,
332 struct cmd_ds_command *cmd)
333{
334 wlan_adapter *adapter = priv->adapter;
335 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
336
Holger Schurig9012b282007-05-25 11:27:16 -0400337 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338
Dan Williams0aef64d2007-08-02 11:31:18 -0400339 cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE);
David Woodhouse981f1872007-05-25 23:36:54 -0400340 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341 S_DS_GEN);
342
343 /* set AP MAC address */
David Woodhouse981f1872007-05-25 23:36:54 -0400344 memmove(dauth->macaddr, adapter->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345
346 /* Reason code 3 = Station is leaving */
347#define REASON_CODE_STA_LEAVING 3
348 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
349
Holger Schurig9012b282007-05-25 11:27:16 -0400350 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200351 return 0;
352}
353
354int libertas_cmd_80211_associate(wlan_private * priv,
355 struct cmd_ds_command *cmd, void *pdata_buf)
356{
357 wlan_adapter *adapter = priv->adapter;
358 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
359 int ret = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400360 struct assoc_request * assoc_req = pdata_buf;
361 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362 u8 *pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400363 u16 tmpcap, tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364 struct mrvlietypes_ssidparamset *ssid;
365 struct mrvlietypes_phyparamset *phy;
366 struct mrvlietypes_ssparamset *ss;
367 struct mrvlietypes_ratesparamset *rates;
368 struct mrvlietypes_rsnparamset *rsn;
369
Holger Schurig9012b282007-05-25 11:27:16 -0400370 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372 pos = (u8 *) passo;
373
374 if (!adapter) {
375 ret = -1;
376 goto done;
377 }
378
Dan Williams0aef64d2007-08-02 11:31:18 -0400379 cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
Dan Williamse76850d2007-05-25 17:09:41 -0400381 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382 pos += sizeof(passo->peerstaaddr);
383
384 /* set the listen interval */
Holger Schurig0aabc0a52007-08-02 13:10:59 -0400385 passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386
Dan Williams0c9ca6902007-08-02 10:43:44 -0400387 pos += sizeof(passo->capability);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 pos += sizeof(passo->listeninterval);
389 pos += sizeof(passo->bcnperiod);
390 pos += sizeof(passo->dtimperiod);
391
392 ssid = (struct mrvlietypes_ssidparamset *) pos;
393 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
Dan Williamsd8efea22007-05-28 23:54:55 -0400394 tmplen = bss->ssid_len;
David Woodhouse707985b2007-05-25 23:41:16 -0400395 ssid->header.len = cpu_to_le16(tmplen);
Dan Williamsd8efea22007-05-28 23:54:55 -0400396 memcpy(ssid->ssid, bss->ssid, tmplen);
David Woodhouse707985b2007-05-25 23:41:16 -0400397 pos += sizeof(ssid->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398
399 phy = (struct mrvlietypes_phyparamset *) pos;
400 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
David Woodhouse707985b2007-05-25 23:41:16 -0400401 tmplen = sizeof(phy->fh_ds.dsparamset);
402 phy->header.len = cpu_to_le16(tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 memcpy(&phy->fh_ds.dsparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400404 &bss->phyparamset.dsparamset.currentchan,
David Woodhouse707985b2007-05-25 23:41:16 -0400405 tmplen);
406 pos += sizeof(phy->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200407
408 ss = (struct mrvlietypes_ssparamset *) pos;
409 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
David Woodhouse707985b2007-05-25 23:41:16 -0400410 tmplen = sizeof(ss->cf_ibss.cfparamset);
411 ss->header.len = cpu_to_le16(tmplen);
412 pos += sizeof(ss->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413
414 rates = (struct mrvlietypes_ratesparamset *) pos;
415 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400416 memcpy(&rates->rates, &bss->rates, MAX_RATES);
417 tmplen = MAX_RATES;
418 if (get_common_rates(adapter, rates->rates, &tmplen)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419 ret = -1;
420 goto done;
421 }
David Woodhouse981f1872007-05-25 23:36:54 -0400422 pos += sizeof(rates->header) + tmplen;
423 rates->header.len = cpu_to_le16(tmplen);
Dan Williams8c512762007-08-02 11:40:45 -0400424 lbs_deb_join("ASSOC_CMD: num rates = %u\n", tmplen);
425
426 /* Copy the infra. association rates into Current BSS state structure */
427 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
428 memcpy(&adapter->curbssparams.rates, &rates->rates, tmplen);
429
430 /* Set MSB on basic rates as the firmware requires, but _after_
431 * copying to current bss rates.
432 */
433 libertas_set_basic_rate_flags(rates->rates, tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200434
Dan Williamse76850d2007-05-25 17:09:41 -0400435 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436 rsn = (struct mrvlietypes_rsnparamset *) pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400437 /* WPA_IE or WPA2_IE */
438 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
439 tmplen = (u16) assoc_req->wpa_ie[1];
440 rsn->header.len = cpu_to_le16(tmplen);
441 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
Holger Schurigece56192007-08-02 11:53:06 -0400442 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn,
David Woodhouse981f1872007-05-25 23:36:54 -0400443 sizeof(rsn->header) + tmplen);
444 pos += sizeof(rsn->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445 }
446
447 /* update curbssparams */
David Woodhouse981f1872007-05-25 23:36:54 -0400448 adapter->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200449
Dan Williamse76850d2007-05-25 17:09:41 -0400450 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451 ret = -1;
452 goto done;
453 }
454
455 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
456
Dan Williams0c9ca6902007-08-02 10:43:44 -0400457 /* set the capability info */
458 tmpcap = (bss->capability & CAPINFO_MASK);
459 if (bss->mode == IW_MODE_INFRA)
460 tmpcap |= WLAN_CAPABILITY_ESS;
461 passo->capability = cpu_to_le16(tmpcap);
462 lbs_deb_join("ASSOC_CMD: capability=%4X CAPINFO_MASK=%4X\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400463 tmpcap, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464
Holger Schurig9012b282007-05-25 11:27:16 -0400465done:
466 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467 return ret;
468}
469
470int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400471 struct cmd_ds_command *cmd, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472{
473 wlan_adapter *adapter = priv->adapter;
474 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
475 int ret = 0;
476 int cmdappendsize = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400477 struct assoc_request * assoc_req = pdata_buf;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400478 u16 tmpcap = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400479 size_t ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480
Holger Schurig9012b282007-05-25 11:27:16 -0400481 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200482
483 if (!adapter) {
484 ret = -1;
485 goto done;
486 }
487
Dan Williams0aef64d2007-08-02 11:31:18 -0400488 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490 /*
491 * Fill in the parameters for 2 data structures:
492 * 1. cmd_ds_802_11_ad_hoc_start command
493 * 2. adapter->scantable[i]
494 *
495 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
496 * probe delay, and cap info.
497 *
498 * Firmware will fill up beacon period, DTIM, Basic rates
499 * and operational rates.
500 */
501
Dan Williamsb44898e2007-08-02 11:18:40 -0400502 memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE);
503 memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504
Dan Williamsd8efea22007-05-28 23:54:55 -0400505 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
506 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
507 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509 /* set the BSS type */
Dan Williams0aef64d2007-08-02 11:31:18 -0400510 adhs->bsstype = CMD_BSS_TYPE_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400511 adapter->mode = IW_MODE_ADHOC;
Holger Schurig2c851032007-08-02 13:11:38 -0400512 adhs->beaconperiod = cpu_to_le16(MRVDRV_BEACON_INTERVAL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200513
514 /* set Physical param set */
515#define DS_PARA_IE_ID 3
516#define DS_PARA_IE_LEN 1
517
518 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
519 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
520
Dan Williamse76850d2007-05-25 17:09:41 -0400521 WARN_ON(!assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522
Holger Schurig9012b282007-05-25 11:27:16 -0400523 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400524 assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525
Dan Williamse76850d2007-05-25 17:09:41 -0400526 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527
528 /* set IBSS param set */
529#define IBSS_PARA_IE_ID 6
530#define IBSS_PARA_IE_LEN 2
531
532 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
533 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
Holger Schurigae596ce2007-08-02 13:10:05 -0400534 adhs->ssparamset.ibssparamset.atimwindow = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535
536 /* set capability info */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400537 tmpcap = WLAN_CAPABILITY_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400538 if (assoc_req->secinfo.wep_enabled) {
Holger Schurig9012b282007-05-25 11:27:16 -0400539 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
Dan Williams0c9ca6902007-08-02 10:43:44 -0400540 tmpcap |= WLAN_CAPABILITY_PRIVACY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200541 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400542 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 }
Dan Williams0c9ca6902007-08-02 10:43:44 -0400544 adhs->capability = cpu_to_le16(tmpcap);
545
546 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400547 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200548
Dan Williams8c512762007-08-02 11:40:45 -0400549 memset(adhs->rates, 0, sizeof(adhs->rates));
Brajesh Dave4b04f192007-08-20 13:09:13 -0400550 ratesize = min(sizeof(adhs->rates), sizeof(libertas_bg_rates));
551 memcpy(adhs->rates, libertas_bg_rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 /* Copy the ad-hoc creating rates into Current BSS state structure */
Dan Williams8c512762007-08-02 11:40:45 -0400554 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
555 memcpy(&adapter->curbssparams.rates, &adhs->rates, ratesize);
556
557 /* Set MSB on basic rates as the firmware requires, but _after_
558 * copying to current bss rates.
559 */
560 libertas_set_basic_rate_flags(adhs->rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561
Holger Schurig9012b282007-05-25 11:27:16 -0400562 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
Dan Williams8c512762007-08-02 11:40:45 -0400563 adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200564
Holger Schurig9012b282007-05-25 11:27:16 -0400565 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200566
567 if (libertas_create_dnld_countryinfo_11d(priv)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400568 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 ret = -1;
570 goto done;
571 }
572
David Woodhouse981f1872007-05-25 23:36:54 -0400573 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
574 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575
576 ret = 0;
577done:
Holger Schurig9012b282007-05-25 11:27:16 -0400578 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579 return ret;
580}
581
582int libertas_cmd_80211_ad_hoc_stop(wlan_private * priv,
583 struct cmd_ds_command *cmd)
584{
Dan Williams0aef64d2007-08-02 11:31:18 -0400585 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586 cmd->size = cpu_to_le16(S_DS_GEN);
587
588 return 0;
589}
590
591int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
592 struct cmd_ds_command *cmd, void *pdata_buf)
593{
594 wlan_adapter *adapter = priv->adapter;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400595 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
Dan Williamse76850d2007-05-25 17:09:41 -0400596 struct assoc_request * assoc_req = pdata_buf;
597 struct bss_descriptor *bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598 int cmdappendsize = 0;
599 int ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400600 u16 ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200601
Holger Schurig9012b282007-05-25 11:27:16 -0400602 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603
Dan Williams0aef64d2007-08-02 11:31:18 -0400604 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200605
Dan Williams0aef64d2007-08-02 11:31:18 -0400606 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
Dan Williams0c9ca6902007-08-02 10:43:44 -0400607 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608
Dan Williams0c9ca6902007-08-02 10:43:44 -0400609 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
610 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
Dan Williams0c9ca6902007-08-02 10:43:44 -0400612 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
613 sizeof(union ieeetypes_phyparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614
Dan Williams0c9ca6902007-08-02 10:43:44 -0400615 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
616 sizeof(union IEEEtypes_ssparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617
Dan Williams0c9ca6902007-08-02 10:43:44 -0400618 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
Holger Schurig9012b282007-05-25 11:27:16 -0400619 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400620 bss->capability, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621
622 /* information on BSSID descriptor passed to FW */
Dan Williamse76850d2007-05-25 17:09:41 -0400623 lbs_deb_join(
624 "ADHOC_J_CMD: BSSID = " MAC_FMT ", SSID = '%s'\n",
Dan Williams0c9ca6902007-08-02 10:43:44 -0400625 MAC_ARG(join_cmd->bss.bssid), join_cmd->bss.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 /* failtimeout */
Dan Williams0c9ca6902007-08-02 10:43:44 -0400628 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629
630 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400631 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200632
Dan Williamse76850d2007-05-25 17:09:41 -0400633 adapter->curbssparams.channel = bss->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634
Dan Williams8c512762007-08-02 11:40:45 -0400635 /* Copy Data rates from the rates recorded in scan response */
636 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
637 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
638 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
639 if (get_common_rates(adapter, join_cmd->bss.rates, &ratesize)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400640 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 ret = -1;
642 goto done;
643 }
644
Dan Williams8c512762007-08-02 11:40:45 -0400645 /* Copy the ad-hoc creating rates into Current BSS state structure */
646 memset(&adapter->curbssparams.rates, 0, sizeof(adapter->curbssparams.rates));
647 memcpy(&adapter->curbssparams.rates, join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200648
Dan Williams8c512762007-08-02 11:40:45 -0400649 /* Set MSB on basic rates as the firmware requires, but _after_
650 * copying to current bss rates.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651 */
Dan Williams8c512762007-08-02 11:40:45 -0400652 libertas_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653
Dan Williams0c9ca6902007-08-02 10:43:44 -0400654 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
Dan Williamse76850d2007-05-25 17:09:41 -0400655 cpu_to_le16(bss->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200656
Dan Williamse76850d2007-05-25 17:09:41 -0400657 if (assoc_req->secinfo.wep_enabled) {
Dan Williams0c9ca6902007-08-02 10:43:44 -0400658 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
659 tmp |= WLAN_CAPABILITY_PRIVACY;
660 join_cmd->bss.capability = cpu_to_le16(tmp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200661 }
662
Dan Williams0aef64d2007-08-02 11:31:18 -0400663 if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 /* wake up first */
David Woodhouse981f1872007-05-25 23:36:54 -0400665 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200666
Dan Williams0aef64d2007-08-02 11:31:18 -0400667 Localpsmode = cpu_to_le32(WLAN802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200668 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400669 CMD_802_11_PS_MODE,
670 CMD_ACT_SET,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671 0, 0, &Localpsmode);
672
673 if (ret) {
674 ret = -1;
675 goto done;
676 }
677 }
678
Dan Williamse76850d2007-05-25 17:09:41 -0400679 if (libertas_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200680 ret = -1;
681 goto done;
682 }
683
David Woodhouse981f1872007-05-25 23:36:54 -0400684 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
685 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686
Holger Schurig9012b282007-05-25 11:27:16 -0400687done:
688 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200689 return ret;
690}
691
692int libertas_ret_80211_associate(wlan_private * priv,
693 struct cmd_ds_command *resp)
694{
695 wlan_adapter *adapter = priv->adapter;
696 int ret = 0;
697 union iwreq_data wrqu;
698 struct ieeetypes_assocrsp *passocrsp;
Dan Williamse76850d2007-05-25 17:09:41 -0400699 struct bss_descriptor * bss;
Dan Williamsc7fdf262007-08-02 13:20:29 -0400700 u16 status_code;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701
Holger Schurig9012b282007-05-25 11:27:16 -0400702 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703
Dan Williamse76850d2007-05-25 17:09:41 -0400704 if (!adapter->in_progress_assoc_req) {
705 lbs_deb_join("ASSOC_RESP: no in-progress association request\n");
706 ret = -1;
707 goto done;
708 }
709 bss = &adapter->in_progress_assoc_req->bss;
710
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
712
Dan Williamsc7fdf262007-08-02 13:20:29 -0400713 /*
714 * Older FW versions map the IEEE 802.11 Status Code in the association
715 * response to the following values returned in passocrsp->statuscode:
716 *
717 * IEEE Status Code Marvell Status Code
718 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
719 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
720 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
721 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
722 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
723 * others -> 0x0003 ASSOC_RESULT_REFUSED
724 *
725 * Other response codes:
726 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
727 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
728 * association response from the AP)
729 */
730
731 status_code = le16_to_cpu(passocrsp->statuscode);
732 switch (status_code) {
733 case 0x00:
734 lbs_deb_join("ASSOC_RESP: Association succeeded\n");
735 break;
736 case 0x01:
737 lbs_deb_join("ASSOC_RESP: Association failed; invalid "
738 "parameters (status code %d)\n", status_code);
739 break;
740 case 0x02:
741 lbs_deb_join("ASSOC_RESP: Association failed; internal timer "
742 "expired while waiting for the AP (status code %d)"
743 "\n", status_code);
744 break;
745 case 0x03:
746 lbs_deb_join("ASSOC_RESP: Association failed; association "
747 "was refused by the AP (status code %d)\n",
748 status_code);
749 break;
750 case 0x04:
751 lbs_deb_join("ASSOC_RESP: Association failed; authentication "
752 "was refused by the AP (status code %d)\n",
753 status_code);
754 break;
755 default:
756 lbs_deb_join("ASSOC_RESP: Association failed; reason unknown "
757 "(status code %d)\n", status_code);
758 break;
759 }
760
761 if (status_code) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762 libertas_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763 ret = -1;
764 goto done;
765 }
766
Holger Schurigece56192007-08-02 11:53:06 -0400767 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_RESP", (void *)&resp->params,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768 le16_to_cpu(resp->size) - S_DS_GEN);
769
770 /* Send a Media Connected event, according to the Spec */
Dan Williams0aef64d2007-08-02 11:31:18 -0400771 adapter->connect_status = LIBERTAS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772
Dan Williamsd8efea22007-05-28 23:54:55 -0400773 lbs_deb_join("ASSOC_RESP: assocated to '%s'\n",
774 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200775
Dan Williamse76850d2007-05-25 17:09:41 -0400776 /* Update current SSID and BSSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400777 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
778 adapter->curbssparams.ssid_len = bss->ssid_len;
Dan Williamse76850d2007-05-25 17:09:41 -0400779 memcpy(adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
Holger Schurig9012b282007-05-25 11:27:16 -0400781 lbs_deb_join("ASSOC_RESP: currentpacketfilter is %x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782 adapter->currentpacketfilter);
783
784 adapter->SNR[TYPE_RXPD][TYPE_AVG] = 0;
785 adapter->NF[TYPE_RXPD][TYPE_AVG] = 0;
786
787 memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR));
788 memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF));
789 adapter->nextSNRNF = 0;
790 adapter->numSNRNF = 0;
791
Holger Schurig634b8f42007-05-25 13:05:16 -0400792 netif_carrier_on(priv->dev);
793 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794
Holger Schurig3cf84092007-08-02 11:50:12 -0400795 if (priv->mesh_dev) {
796 netif_carrier_on(priv->mesh_dev);
797 netif_wake_queue(priv->mesh_dev);
798 }
Javier Cardona51d84f52007-05-25 12:06:56 -0400799
Holger Schurig9012b282007-05-25 11:27:16 -0400800 lbs_deb_join("ASSOC_RESP: Associated \n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801
802 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
803 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400804 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805
Holger Schurig9012b282007-05-25 11:27:16 -0400806done:
807 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200808 return ret;
809}
810
811int libertas_ret_80211_disassociate(wlan_private * priv,
812 struct cmd_ds_command *resp)
813{
Holger Schurig9012b282007-05-25 11:27:16 -0400814 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815
816 libertas_mac_event_disconnected(priv);
817
Holger Schurig9012b282007-05-25 11:27:16 -0400818 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200819 return 0;
820}
821
822int libertas_ret_80211_ad_hoc_start(wlan_private * priv,
823 struct cmd_ds_command *resp)
824{
825 wlan_adapter *adapter = priv->adapter;
826 int ret = 0;
827 u16 command = le16_to_cpu(resp->command);
828 u16 result = le16_to_cpu(resp->result);
829 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
830 union iwreq_data wrqu;
Dan Williamse76850d2007-05-25 17:09:41 -0400831 struct bss_descriptor *bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200832
Holger Schurig9012b282007-05-25 11:27:16 -0400833 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200834
835 padhocresult = &resp->params.result;
836
Dan Williamse76850d2007-05-25 17:09:41 -0400837 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
838 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
839 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840
Dan Williamse76850d2007-05-25 17:09:41 -0400841 if (!adapter->in_progress_assoc_req) {
842 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
843 ret = -1;
844 goto done;
845 }
846 bss = &adapter->in_progress_assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200847
848 /*
849 * Join result code 0 --> SUCCESS
850 */
851 if (result) {
Dan Williamse76850d2007-05-25 17:09:41 -0400852 lbs_deb_join("ADHOC_RESP: failed\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400853 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200854 libertas_mac_event_disconnected(priv);
855 }
Holger Schurig9012b282007-05-25 11:27:16 -0400856 ret = -1;
857 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200858 }
859
860 /*
861 * Now the join cmd should be successful
862 * If BSSID has changed use SSID to compare instead of BSSID
863 */
Dan Williamsd8efea22007-05-28 23:54:55 -0400864 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
865 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866
867 /* Send a Media Connected event, according to the Spec */
Dan Williams0aef64d2007-08-02 11:31:18 -0400868 adapter->connect_status = LIBERTAS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200869
Holger Schurig6b63cd02007-08-02 11:53:36 -0400870 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200871 /* Update the created network descriptor with the new BSSID */
Dan Williamsea8da922007-08-02 11:18:23 -0400872 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873 }
874
875 /* Set the BSSID from the joined/started descriptor */
Dan Williamse76850d2007-05-25 17:09:41 -0400876 memcpy(&adapter->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877
878 /* Set the new SSID to current SSID */
Dan Williamsd8efea22007-05-28 23:54:55 -0400879 memcpy(&adapter->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
880 adapter->curbssparams.ssid_len = bss->ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200881
Holger Schurig634b8f42007-05-25 13:05:16 -0400882 netif_carrier_on(priv->dev);
883 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200884
Holger Schurig3cf84092007-08-02 11:50:12 -0400885 if (priv->mesh_dev) {
886 netif_carrier_on(priv->mesh_dev);
887 netif_wake_queue(priv->mesh_dev);
888 }
Javier Cardona51d84f52007-05-25 12:06:56 -0400889
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890 memset(&wrqu, 0, sizeof(wrqu));
891 memcpy(wrqu.ap_addr.sa_data, adapter->curbssparams.bssid, ETH_ALEN);
892 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400893 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894
Holger Schurig9012b282007-05-25 11:27:16 -0400895 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400896 lbs_deb_join("ADHOC_RESP: channel = %d\n", adapter->curbssparams.channel);
Dan Williams02eb2292007-05-25 17:27:31 -0400897 lbs_deb_join("ADHOC_RESP: BSSID = " MAC_FMT "\n",
Dan Williams2ca10e62007-08-02 11:31:49 -0400898 MAC_ARG(padhocresult->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899
Holger Schurig9012b282007-05-25 11:27:16 -0400900done:
901 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200902 return ret;
903}
904
905int libertas_ret_80211_ad_hoc_stop(wlan_private * priv,
906 struct cmd_ds_command *resp)
907{
Holger Schurig9012b282007-05-25 11:27:16 -0400908 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909
910 libertas_mac_event_disconnected(priv);
911
Holger Schurig9012b282007-05-25 11:27:16 -0400912 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913 return 0;
914}