blob: 56e64a697c37fd1d39257d216f6aec8d50106956 [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 *
David Woodhouseaa21c002007-12-08 20:04:36 +000033 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020034 * @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 */
David Woodhouseaa21c002007-12-08 20:04:36 +000039static int get_common_rates(struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010040 u8 *rates,
41 u16 *rates_size)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020042{
Holger Schurig10078322007-11-15 18:05:47 -050043 u8 *card_rates = lbs_bg_rates;
44 size_t num_card_rates = sizeof(lbs_bg_rates);
Dan Williams8c512762007-08-02 11:40:45 -040045 int ret = 0, i, j;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046 u8 tmp[30];
Dan Williams8c512762007-08-02 11:40:45 -040047 size_t tmp_size = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048
Dan Williams8c512762007-08-02 11:40:45 -040049 /* For each rate in card_rates that exists in rate1, copy to tmp */
50 for (i = 0; card_rates[i] && (i < num_card_rates); i++) {
51 for (j = 0; rates[j] && (j < *rates_size); j++) {
52 if (rates[j] == card_rates[i])
53 tmp[tmp_size++] = card_rates[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054 }
55 }
56
Holger Schurigece56192007-08-02 11:53:06 -040057 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
58 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates);
59 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size);
David Woodhouseaa21c002007-12-08 20:04:36 +000060 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061
David Woodhouseaa21c002007-12-08 20:04:36 +000062 if (!priv->auto_rate) {
Dan Williams8c512762007-08-02 11:40:45 -040063 for (i = 0; i < tmp_size; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +000064 if (tmp[i] == priv->cur_rate)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 }
Dan Williams8c512762007-08-02 11:40:45 -040067 lbs_pr_alert("Previously set fixed data rate %#x isn't "
David Woodhouseaa21c002007-12-08 20:04:36 +000068 "compatible with the network.\n", priv->cur_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069 ret = -1;
70 goto done;
71 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -040073
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074done:
Dan Williams8c512762007-08-02 11:40:45 -040075 memset(rates, 0, *rates_size);
76 *rates_size = min_t(int, tmp_size, *rates_size);
77 memcpy(rates, tmp, *rates_size);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078 return ret;
79}
80
Dan Williams8c512762007-08-02 11:40:45 -040081
82/**
83 * @brief Sets the MSB on basic rates as the firmware requires
84 *
85 * Scan through an array and set the MSB for basic data rates.
86 *
87 * @param rates buffer of data rates
88 * @param len size of buffer
89 */
Holger Schurig10078322007-11-15 18:05:47 -050090static void lbs_set_basic_rate_flags(u8 *rates, size_t len)
Dan Williams8c512762007-08-02 11:40:45 -040091{
92 int i;
93
94 for (i = 0; i < len; i++) {
95 if (rates[i] == 0x02 || rates[i] == 0x04 ||
96 rates[i] == 0x0b || rates[i] == 0x16)
97 rates[i] |= 0x80;
98 }
99}
100
101/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102 * @brief Associate to a specific BSS discovered in a scan
103 *
Holger Schurig69f90322007-11-23 15:43:44 +0100104 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105 * @param pbssdesc Pointer to the BSS descriptor to associate with.
106 *
107 * @return 0-success, otherwise fail
108 */
Holger Schurig69f90322007-11-23 15:43:44 +0100109int lbs_associate(struct lbs_private *priv, struct assoc_request *assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111 int ret;
112
Holger Schurig91843462007-11-28 14:05:02 +0100113 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114
Holger Schurig10078322007-11-15 18:05:47 -0500115 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE,
Dan Williams0aef64d2007-08-02 11:31:18 -0400116 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400117 0, assoc_req->bss.bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118
Holger Schurig9012b282007-05-25 11:27:16 -0400119 if (ret)
120 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200121
122 /* set preamble to firmware */
David Woodhouseaa21c002007-12-08 20:04:36 +0000123 if ( (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Dan Williams0c9ca692007-08-02 10:43:44 -0400124 && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
David Woodhouseaa21c002007-12-08 20:04:36 +0000125 priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000127 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200128
Holger Schurig10078322007-11-15 18:05:47 -0500129 lbs_set_radio_control(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
Holger Schurig10078322007-11-15 18:05:47 -0500131 ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE,
Dan Williams0aef64d2007-08-02 11:31:18 -0400132 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133
Holger Schurig9012b282007-05-25 11:27:16 -0400134done:
Holger Schurig91843462007-11-28 14:05:02 +0100135 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 return ret;
137}
138
139/**
140 * @brief Start an Adhoc Network
141 *
Holger Schurig69f90322007-11-23 15:43:44 +0100142 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143 * @param adhocssid The ssid of the Adhoc Network
144 * @return 0--success, -1--fail
145 */
Holger Schurig69f90322007-11-23 15:43:44 +0100146int lbs_start_adhoc_network(struct lbs_private *priv,
147 struct assoc_request *assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 int ret = 0;
150
David Woodhouseaa21c002007-12-08 20:04:36 +0000151 priv->adhoccreate = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152
David Woodhouseaa21c002007-12-08 20:04:36 +0000153 if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
Holger Schurig9012b282007-05-25 11:27:16 -0400154 lbs_deb_join("AdhocStart: Short preamble\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000155 priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
Dan Williams0c9ca692007-08-02 10:43:44 -0400156 } else {
157 lbs_deb_join("AdhocStart: Long preamble\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000158 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 }
160
Holger Schurig10078322007-11-15 18:05:47 -0500161 lbs_set_radio_control(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162
Dan Williamse76850d2007-05-25 17:09:41 -0400163 lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel);
164 lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
Holger Schurig10078322007-11-15 18:05:47 -0500166 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START,
Dan Williams0aef64d2007-08-02 11:31:18 -0400167 0, CMD_OPTION_WAITFORRSP, 0, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168
169 return ret;
170}
171
172/**
173 * @brief Join an adhoc network found in a previous scan
174 *
Holger Schurig69f90322007-11-23 15:43:44 +0100175 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200176 * @param pbssdesc Pointer to a BSS descriptor found in a previous scan
177 * to attempt to join
178 *
179 * @return 0--success, -1--fail
180 */
Holger Schurig69f90322007-11-23 15:43:44 +0100181int lbs_join_adhoc_network(struct lbs_private *priv,
182 struct assoc_request *assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183{
Dan Williamse76850d2007-05-25 17:09:41 -0400184 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 int ret = 0;
186
Dan Williamsd8efea22007-05-28 23:54:55 -0400187 lbs_deb_join("%s: Current SSID '%s', ssid length %u\n",
188 __func__,
David Woodhouseaa21c002007-12-08 20:04:36 +0000189 escape_essid(priv->curbssparams.ssid,
190 priv->curbssparams.ssid_len),
191 priv->curbssparams.ssid_len);
Dan Williamsd8efea22007-05-28 23:54:55 -0400192 lbs_deb_join("%s: requested ssid '%s', ssid length %u\n",
193 __func__, escape_essid(bss->ssid, bss->ssid_len),
194 bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
196 /* check if the requested SSID is already joined */
David Woodhouseaa21c002007-12-08 20:04:36 +0000197 if ( priv->curbssparams.ssid_len
198 && !lbs_ssid_cmp(priv->curbssparams.ssid,
199 priv->curbssparams.ssid_len,
Dan Williamsd8efea22007-05-28 23:54:55 -0400200 bss->ssid, bss->ssid_len)
David Woodhouseaa21c002007-12-08 20:04:36 +0000201 && (priv->mode == IW_MODE_ADHOC)
202 && (priv->connect_status == LBS_CONNECTED)) {
Dan Williams0edef212007-08-02 13:14:29 -0400203 union iwreq_data wrqu;
204
205 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
206 "current, not attempting to re-join");
207
208 /* Send the re-association event though, because the association
209 * request really was successful, even if just a null-op.
210 */
211 memset(&wrqu, 0, sizeof(wrqu));
David Woodhouseaa21c002007-12-08 20:04:36 +0000212 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid,
Dan Williams0edef212007-08-02 13:14:29 -0400213 ETH_ALEN);
214 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
215 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
216 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 }
218
Dan Williams0c9ca692007-08-02 10:43:44 -0400219 /* Use shortpreamble only when both creator and card supports
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 short preamble */
Dan Williams0c9ca692007-08-02 10:43:44 -0400221 if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
David Woodhouseaa21c002007-12-08 20:04:36 +0000222 || !(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400223 lbs_deb_join("AdhocJoin: Long preamble\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000224 priv->preamble = CMD_TYPE_LONG_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400226 lbs_deb_join("AdhocJoin: Short preamble\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000227 priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 }
229
Holger Schurig10078322007-11-15 18:05:47 -0500230 lbs_set_radio_control(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231
Dan Williamse76850d2007-05-25 17:09:41 -0400232 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
233 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
David Woodhouseaa21c002007-12-08 20:04:36 +0000235 priv->adhoccreate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236
Holger Schurig10078322007-11-15 18:05:47 -0500237 ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN,
Dan Williams0aef64d2007-08-02 11:31:18 -0400238 0, CMD_OPTION_WAITFORRSP,
Dan Williamse76850d2007-05-25 17:09:41 -0400239 OID_802_11_SSID, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240
Dan Williams0edef212007-08-02 13:14:29 -0400241out:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242 return ret;
243}
244
Holger Schurig69f90322007-11-23 15:43:44 +0100245int lbs_stop_adhoc_network(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246{
Holger Schurig10078322007-11-15 18:05:47 -0500247 return lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP,
Dan Williams0aef64d2007-08-02 11:31:18 -0400248 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249}
250
251/**
252 * @brief Send Deauthentication Request
253 *
Holger Schurig69f90322007-11-23 15:43:44 +0100254 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255 * @return 0--success, -1--fail
256 */
Holger Schurig69f90322007-11-23 15:43:44 +0100257int lbs_send_deauthentication(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258{
Holger Schurig10078322007-11-15 18:05:47 -0500259 return lbs_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE,
Dan Williams0aef64d2007-08-02 11:31:18 -0400260 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200261}
262
263/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264 * @brief This function prepares command of authenticate.
265 *
Holger Schurig69f90322007-11-23 15:43:44 +0100266 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200267 * @param cmd A pointer to cmd_ds_command structure
268 * @param pdata_buf Void cast of pointer to a BSSID to authenticate with
269 *
270 * @return 0 or -1
271 */
Holger Schurig69f90322007-11-23 15:43:44 +0100272int lbs_cmd_80211_authenticate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273 struct cmd_ds_command *cmd,
274 void *pdata_buf)
275{
Dan Williams6affe782007-05-10 22:56:42 -0400276 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
277 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278 u8 *bssid = pdata_buf;
Joe Perches0795af52007-10-03 17:59:30 -0700279 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280
Dan Williams45f43de2007-05-25 22:58:55 -0400281 lbs_deb_enter(LBS_DEB_JOIN);
282
Dan Williams0aef64d2007-08-02 11:31:18 -0400283 cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE);
Dan Williams6affe782007-05-10 22:56:42 -0400284 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
285 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286
Dan Williams6affe782007-05-10 22:56:42 -0400287 /* translate auth mode to 802.11 defined wire value */
David Woodhouseaa21c002007-12-08 20:04:36 +0000288 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -0400289 case IW_AUTH_ALG_OPEN_SYSTEM:
290 pauthenticate->authtype = 0x00;
291 break;
292 case IW_AUTH_ALG_SHARED_KEY:
293 pauthenticate->authtype = 0x01;
294 break;
295 case IW_AUTH_ALG_LEAP:
296 pauthenticate->authtype = 0x80;
297 break;
298 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400299 lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000300 priv->secinfo.auth_mode);
Dan Williams6affe782007-05-10 22:56:42 -0400301 goto out;
302 }
303
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
305
Holger Schurig91843462007-11-28 14:05:02 +0100306 lbs_deb_join("AUTH_CMD: BSSID %s, auth 0x%x\n",
Joe Perches0795af52007-10-03 17:59:30 -0700307 print_mac(mac, bssid), pauthenticate->authtype);
Dan Williams6affe782007-05-10 22:56:42 -0400308 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309
Dan Williams6affe782007-05-10 22:56:42 -0400310out:
Dan Williams45f43de2007-05-25 22:58:55 -0400311 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Dan Williams6affe782007-05-10 22:56:42 -0400312 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313}
314
Holger Schurig69f90322007-11-23 15:43:44 +0100315int lbs_cmd_80211_deauthenticate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316 struct cmd_ds_command *cmd)
317{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200318 struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth;
319
Holger Schurig9012b282007-05-25 11:27:16 -0400320 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
Dan Williams0aef64d2007-08-02 11:31:18 -0400322 cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE);
David Woodhouse981f1872007-05-25 23:36:54 -0400323 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324 S_DS_GEN);
325
326 /* set AP MAC address */
David Woodhouseaa21c002007-12-08 20:04:36 +0000327 memmove(dauth->macaddr, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328
329 /* Reason code 3 = Station is leaving */
330#define REASON_CODE_STA_LEAVING 3
331 dauth->reasoncode = cpu_to_le16(REASON_CODE_STA_LEAVING);
332
Holger Schurig9012b282007-05-25 11:27:16 -0400333 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 return 0;
335}
336
Holger Schurig69f90322007-11-23 15:43:44 +0100337int lbs_cmd_80211_associate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 struct cmd_ds_command *cmd, void *pdata_buf)
339{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200340 struct cmd_ds_802_11_associate *passo = &cmd->params.associate;
341 int ret = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400342 struct assoc_request * assoc_req = pdata_buf;
343 struct bss_descriptor * bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 u8 *pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400345 u16 tmpcap, tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346 struct mrvlietypes_ssidparamset *ssid;
347 struct mrvlietypes_phyparamset *phy;
348 struct mrvlietypes_ssparamset *ss;
349 struct mrvlietypes_ratesparamset *rates;
350 struct mrvlietypes_rsnparamset *rsn;
351
Holger Schurig91843462007-11-28 14:05:02 +0100352 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354 pos = (u8 *) passo;
355
David Woodhouseaa21c002007-12-08 20:04:36 +0000356 if (!priv) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 ret = -1;
358 goto done;
359 }
360
Dan Williams0aef64d2007-08-02 11:31:18 -0400361 cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362
Dan Williamse76850d2007-05-25 17:09:41 -0400363 memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364 pos += sizeof(passo->peerstaaddr);
365
366 /* set the listen interval */
Holger Schurig0aabc0a52007-08-02 13:10:59 -0400367 passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368
Dan Williams0c9ca692007-08-02 10:43:44 -0400369 pos += sizeof(passo->capability);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 pos += sizeof(passo->listeninterval);
371 pos += sizeof(passo->bcnperiod);
372 pos += sizeof(passo->dtimperiod);
373
374 ssid = (struct mrvlietypes_ssidparamset *) pos;
375 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
Dan Williamsd8efea22007-05-28 23:54:55 -0400376 tmplen = bss->ssid_len;
David Woodhouse707985b2007-05-25 23:41:16 -0400377 ssid->header.len = cpu_to_le16(tmplen);
Dan Williamsd8efea22007-05-28 23:54:55 -0400378 memcpy(ssid->ssid, bss->ssid, tmplen);
David Woodhouse707985b2007-05-25 23:41:16 -0400379 pos += sizeof(ssid->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
381 phy = (struct mrvlietypes_phyparamset *) pos;
382 phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
David Woodhouse707985b2007-05-25 23:41:16 -0400383 tmplen = sizeof(phy->fh_ds.dsparamset);
384 phy->header.len = cpu_to_le16(tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385 memcpy(&phy->fh_ds.dsparamset,
Dan Williamse76850d2007-05-25 17:09:41 -0400386 &bss->phyparamset.dsparamset.currentchan,
David Woodhouse707985b2007-05-25 23:41:16 -0400387 tmplen);
388 pos += sizeof(phy->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389
390 ss = (struct mrvlietypes_ssparamset *) pos;
391 ss->header.type = cpu_to_le16(TLV_TYPE_CF);
David Woodhouse707985b2007-05-25 23:41:16 -0400392 tmplen = sizeof(ss->cf_ibss.cfparamset);
393 ss->header.len = cpu_to_le16(tmplen);
394 pos += sizeof(ss->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395
396 rates = (struct mrvlietypes_ratesparamset *) pos;
397 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400398 memcpy(&rates->rates, &bss->rates, MAX_RATES);
399 tmplen = MAX_RATES;
David Woodhouseaa21c002007-12-08 20:04:36 +0000400 if (get_common_rates(priv, rates->rates, &tmplen)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401 ret = -1;
402 goto done;
403 }
David Woodhouse981f1872007-05-25 23:36:54 -0400404 pos += sizeof(rates->header) + tmplen;
405 rates->header.len = cpu_to_le16(tmplen);
Holger Schurig91843462007-11-28 14:05:02 +0100406 lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen);
Dan Williams8c512762007-08-02 11:40:45 -0400407
408 /* Copy the infra. association rates into Current BSS state structure */
David Woodhouseaa21c002007-12-08 20:04:36 +0000409 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
410 memcpy(&priv->curbssparams.rates, &rates->rates, tmplen);
Dan Williams8c512762007-08-02 11:40:45 -0400411
412 /* Set MSB on basic rates as the firmware requires, but _after_
413 * copying to current bss rates.
414 */
Holger Schurig10078322007-11-15 18:05:47 -0500415 lbs_set_basic_rate_flags(rates->rates, tmplen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416
Dan Williamse76850d2007-05-25 17:09:41 -0400417 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418 rsn = (struct mrvlietypes_rsnparamset *) pos;
David Woodhouse981f1872007-05-25 23:36:54 -0400419 /* WPA_IE or WPA2_IE */
420 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
421 tmplen = (u16) assoc_req->wpa_ie[1];
422 rsn->header.len = cpu_to_le16(tmplen);
423 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
Holger Schurigece56192007-08-02 11:53:06 -0400424 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn,
David Woodhouse981f1872007-05-25 23:36:54 -0400425 sizeof(rsn->header) + tmplen);
426 pos += sizeof(rsn->header) + tmplen;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200427 }
428
429 /* update curbssparams */
David Woodhouseaa21c002007-12-08 20:04:36 +0000430 priv->curbssparams.channel = bss->phyparamset.dsparamset.currentchan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431
Holger Schurig10078322007-11-15 18:05:47 -0500432 if (lbs_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433 ret = -1;
434 goto done;
435 }
436
437 cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN);
438
Dan Williams0c9ca692007-08-02 10:43:44 -0400439 /* set the capability info */
440 tmpcap = (bss->capability & CAPINFO_MASK);
441 if (bss->mode == IW_MODE_INFRA)
442 tmpcap |= WLAN_CAPABILITY_ESS;
443 passo->capability = cpu_to_le16(tmpcap);
Holger Schurig91843462007-11-28 14:05:02 +0100444 lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445
Holger Schurig9012b282007-05-25 11:27:16 -0400446done:
Holger Schurig91843462007-11-28 14:05:02 +0100447 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200448 return ret;
449}
450
Holger Schurig69f90322007-11-23 15:43:44 +0100451int lbs_cmd_80211_ad_hoc_start(struct lbs_private *priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400452 struct cmd_ds_command *cmd, void *pdata_buf)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200454 struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads;
455 int ret = 0;
456 int cmdappendsize = 0;
Dan Williamse76850d2007-05-25 17:09:41 -0400457 struct assoc_request * assoc_req = pdata_buf;
Dan Williams0c9ca692007-08-02 10:43:44 -0400458 u16 tmpcap = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400459 size_t ratesize = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460
Holger Schurig9012b282007-05-25 11:27:16 -0400461 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462
David Woodhouseaa21c002007-12-08 20:04:36 +0000463 if (!priv) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464 ret = -1;
465 goto done;
466 }
467
Dan Williams0aef64d2007-08-02 11:31:18 -0400468 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470 /*
471 * Fill in the parameters for 2 data structures:
472 * 1. cmd_ds_802_11_ad_hoc_start command
David Woodhouseaa21c002007-12-08 20:04:36 +0000473 * 2. priv->scantable[i]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200474 *
475 * Driver will fill up SSID, bsstype,IBSS param, Physical Param,
476 * probe delay, and cap info.
477 *
478 * Firmware will fill up beacon period, DTIM, Basic rates
479 * and operational rates.
480 */
481
Dan Williamsb44898e2007-08-02 11:18:40 -0400482 memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE);
483 memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484
Dan Williamsd8efea22007-05-28 23:54:55 -0400485 lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n",
486 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
487 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489 /* set the BSS type */
Dan Williams0aef64d2007-08-02 11:31:18 -0400490 adhs->bsstype = CMD_BSS_TYPE_IBSS;
David Woodhouseaa21c002007-12-08 20:04:36 +0000491 priv->mode = IW_MODE_ADHOC;
492 if (priv->beacon_period == 0)
493 priv->beacon_period = MRVDRV_BEACON_INTERVAL;
494 adhs->beaconperiod = cpu_to_le16(priv->beacon_period);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495
496 /* set Physical param set */
497#define DS_PARA_IE_ID 3
498#define DS_PARA_IE_LEN 1
499
500 adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID;
501 adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN;
502
Dan Williamse76850d2007-05-25 17:09:41 -0400503 WARN_ON(!assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504
Holger Schurig9012b282007-05-25 11:27:16 -0400505 lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n",
David Woodhouse981f1872007-05-25 23:36:54 -0400506 assoc_req->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
Dan Williamse76850d2007-05-25 17:09:41 -0400508 adhs->phyparamset.dsparamset.currentchan = assoc_req->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
510 /* set IBSS param set */
511#define IBSS_PARA_IE_ID 6
512#define IBSS_PARA_IE_LEN 2
513
514 adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID;
515 adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN;
Holger Schurigae596ce2007-08-02 13:10:05 -0400516 adhs->ssparamset.ibssparamset.atimwindow = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200517
518 /* set capability info */
Dan Williams0c9ca692007-08-02 10:43:44 -0400519 tmpcap = WLAN_CAPABILITY_IBSS;
Dan Williamse76850d2007-05-25 17:09:41 -0400520 if (assoc_req->secinfo.wep_enabled) {
Holger Schurig9012b282007-05-25 11:27:16 -0400521 lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n");
Dan Williams0c9ca692007-08-02 10:43:44 -0400522 tmpcap |= WLAN_CAPABILITY_PRIVACY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400524 lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525 }
Dan Williams0c9ca692007-08-02 10:43:44 -0400526 adhs->capability = cpu_to_le16(tmpcap);
527
528 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400529 adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530
Dan Williams8c512762007-08-02 11:40:45 -0400531 memset(adhs->rates, 0, sizeof(adhs->rates));
Holger Schurig10078322007-11-15 18:05:47 -0500532 ratesize = min(sizeof(adhs->rates), sizeof(lbs_bg_rates));
533 memcpy(adhs->rates, lbs_bg_rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535 /* Copy the ad-hoc creating rates into Current BSS state structure */
David Woodhouseaa21c002007-12-08 20:04:36 +0000536 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
537 memcpy(&priv->curbssparams.rates, &adhs->rates, ratesize);
Dan Williams8c512762007-08-02 11:40:45 -0400538
539 /* Set MSB on basic rates as the firmware requires, but _after_
540 * copying to current bss rates.
541 */
Holger Schurig10078322007-11-15 18:05:47 -0500542 lbs_set_basic_rate_flags(adhs->rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543
Holger Schurig9012b282007-05-25 11:27:16 -0400544 lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n",
Dan Williams8c512762007-08-02 11:40:45 -0400545 adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200546
Holger Schurig9012b282007-05-25 11:27:16 -0400547 lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200548
Holger Schurig10078322007-11-15 18:05:47 -0500549 if (lbs_create_dnld_countryinfo_11d(priv)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400550 lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 ret = -1;
552 goto done;
553 }
554
David Woodhouse981f1872007-05-25 23:36:54 -0400555 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) +
556 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557
558 ret = 0;
559done:
Holger Schurig9012b282007-05-25 11:27:16 -0400560 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561 return ret;
562}
563
Holger Schurig69f90322007-11-23 15:43:44 +0100564int lbs_cmd_80211_ad_hoc_stop(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 struct cmd_ds_command *cmd)
566{
Dan Williams0aef64d2007-08-02 11:31:18 -0400567 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 cmd->size = cpu_to_le16(S_DS_GEN);
569
570 return 0;
571}
572
Holger Schurig69f90322007-11-23 15:43:44 +0100573int lbs_cmd_80211_ad_hoc_join(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574 struct cmd_ds_command *cmd, void *pdata_buf)
575{
Dan Williams0c9ca692007-08-02 10:43:44 -0400576 struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj;
Dan Williamse76850d2007-05-25 17:09:41 -0400577 struct assoc_request * assoc_req = pdata_buf;
578 struct bss_descriptor *bss = &assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579 int cmdappendsize = 0;
580 int ret = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400581 u16 ratesize = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700582 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200583
Holger Schurig9012b282007-05-25 11:27:16 -0400584 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585
Dan Williams0aef64d2007-08-02 11:31:18 -0400586 cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587
Dan Williams0aef64d2007-08-02 11:31:18 -0400588 join_cmd->bss.type = CMD_BSS_TYPE_IBSS;
Dan Williams0c9ca692007-08-02 10:43:44 -0400589 join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590
Dan Williams0c9ca692007-08-02 10:43:44 -0400591 memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN);
592 memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593
Dan Williams0c9ca692007-08-02 10:43:44 -0400594 memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset,
595 sizeof(union ieeetypes_phyparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596
Dan Williams0c9ca692007-08-02 10:43:44 -0400597 memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset,
598 sizeof(union IEEEtypes_ssparamset));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599
Dan Williams0c9ca692007-08-02 10:43:44 -0400600 join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
Holger Schurig9012b282007-05-25 11:27:16 -0400601 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
Dan Williams0c9ca692007-08-02 10:43:44 -0400602 bss->capability, CAPINFO_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603
604 /* information on BSSID descriptor passed to FW */
Dan Williamse76850d2007-05-25 17:09:41 -0400605 lbs_deb_join(
Joe Perches0795af52007-10-03 17:59:30 -0700606 "ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n",
607 print_mac(mac, join_cmd->bss.bssid),
608 join_cmd->bss.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 /* failtimeout */
Dan Williams0c9ca692007-08-02 10:43:44 -0400611 join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200612
613 /* probedelay */
Dan Williams0aef64d2007-08-02 11:31:18 -0400614 join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615
David Woodhouseaa21c002007-12-08 20:04:36 +0000616 priv->curbssparams.channel = bss->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617
Dan Williams8c512762007-08-02 11:40:45 -0400618 /* Copy Data rates from the rates recorded in scan response */
619 memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates));
620 ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES);
621 memcpy(join_cmd->bss.rates, bss->rates, ratesize);
David Woodhouseaa21c002007-12-08 20:04:36 +0000622 if (get_common_rates(priv, join_cmd->bss.rates, &ratesize)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400623 lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624 ret = -1;
625 goto done;
626 }
627
Dan Williams8c512762007-08-02 11:40:45 -0400628 /* Copy the ad-hoc creating rates into Current BSS state structure */
David Woodhouseaa21c002007-12-08 20:04:36 +0000629 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
630 memcpy(&priv->curbssparams.rates, join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631
Dan Williams8c512762007-08-02 11:40:45 -0400632 /* Set MSB on basic rates as the firmware requires, but _after_
633 * copying to current bss rates.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634 */
Holger Schurig10078322007-11-15 18:05:47 -0500635 lbs_set_basic_rate_flags(join_cmd->bss.rates, ratesize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200636
Dan Williams0c9ca692007-08-02 10:43:44 -0400637 join_cmd->bss.ssparamset.ibssparamset.atimwindow =
Dan Williamse76850d2007-05-25 17:09:41 -0400638 cpu_to_le16(bss->atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639
Dan Williamse76850d2007-05-25 17:09:41 -0400640 if (assoc_req->secinfo.wep_enabled) {
Dan Williams0c9ca692007-08-02 10:43:44 -0400641 u16 tmp = le16_to_cpu(join_cmd->bss.capability);
642 tmp |= WLAN_CAPABILITY_PRIVACY;
643 join_cmd->bss.capability = cpu_to_le16(tmp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 }
645
David Woodhouseaa21c002007-12-08 20:04:36 +0000646 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 /* wake up first */
David Woodhouse981f1872007-05-25 23:36:54 -0400648 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649
Holger Schurig10078322007-11-15 18:05:47 -0500650 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
651 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400652 CMD_802_11_PS_MODE,
653 CMD_ACT_SET,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200654 0, 0, &Localpsmode);
655
656 if (ret) {
657 ret = -1;
658 goto done;
659 }
660 }
661
Holger Schurig10078322007-11-15 18:05:47 -0500662 if (lbs_parse_dnld_countryinfo_11d(priv, bss)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663 ret = -1;
664 goto done;
665 }
666
David Woodhouse981f1872007-05-25 23:36:54 -0400667 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) +
668 S_DS_GEN + cmdappendsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200669
Holger Schurig9012b282007-05-25 11:27:16 -0400670done:
671 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672 return ret;
673}
674
Holger Schurig69f90322007-11-23 15:43:44 +0100675int lbs_ret_80211_associate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200676 struct cmd_ds_command *resp)
677{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 int ret = 0;
679 union iwreq_data wrqu;
680 struct ieeetypes_assocrsp *passocrsp;
Dan Williamse76850d2007-05-25 17:09:41 -0400681 struct bss_descriptor * bss;
Dan Williamsc7fdf262007-08-02 13:20:29 -0400682 u16 status_code;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200683
Holger Schurig91843462007-11-28 14:05:02 +0100684 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200685
David Woodhouseaa21c002007-12-08 20:04:36 +0000686 if (!priv->in_progress_assoc_req) {
Holger Schurig91843462007-11-28 14:05:02 +0100687 lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n");
Dan Williamse76850d2007-05-25 17:09:41 -0400688 ret = -1;
689 goto done;
690 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000691 bss = &priv->in_progress_assoc_req->bss;
Dan Williamse76850d2007-05-25 17:09:41 -0400692
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200693 passocrsp = (struct ieeetypes_assocrsp *) & resp->params;
694
Dan Williamsc7fdf262007-08-02 13:20:29 -0400695 /*
696 * Older FW versions map the IEEE 802.11 Status Code in the association
697 * response to the following values returned in passocrsp->statuscode:
698 *
699 * IEEE Status Code Marvell Status Code
700 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
701 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
702 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
703 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
704 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
705 * others -> 0x0003 ASSOC_RESULT_REFUSED
706 *
707 * Other response codes:
708 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
709 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
710 * association response from the AP)
711 */
712
713 status_code = le16_to_cpu(passocrsp->statuscode);
714 switch (status_code) {
715 case 0x00:
Dan Williamsc7fdf262007-08-02 13:20:29 -0400716 break;
717 case 0x01:
Holger Schurig91843462007-11-28 14:05:02 +0100718 lbs_deb_assoc("ASSOC_RESP: invalid parameters\n");
Dan Williamsc7fdf262007-08-02 13:20:29 -0400719 break;
720 case 0x02:
Holger Schurig91843462007-11-28 14:05:02 +0100721 lbs_deb_assoc("ASSOC_RESP: internal timer "
722 "expired while waiting for the AP\n");
Dan Williamsc7fdf262007-08-02 13:20:29 -0400723 break;
724 case 0x03:
Holger Schurig91843462007-11-28 14:05:02 +0100725 lbs_deb_assoc("ASSOC_RESP: association "
726 "refused by AP\n");
Dan Williamsc7fdf262007-08-02 13:20:29 -0400727 break;
728 case 0x04:
Holger Schurig91843462007-11-28 14:05:02 +0100729 lbs_deb_assoc("ASSOC_RESP: authentication "
730 "refused by AP\n");
Dan Williamsc7fdf262007-08-02 13:20:29 -0400731 break;
732 default:
Holger Schurig91843462007-11-28 14:05:02 +0100733 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x "
734 " unknown\n", status_code);
Dan Williamsc7fdf262007-08-02 13:20:29 -0400735 break;
736 }
737
738 if (status_code) {
Holger Schurig10078322007-11-15 18:05:47 -0500739 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740 ret = -1;
741 goto done;
742 }
743
Holger Schurig91843462007-11-28 14:05:02 +0100744 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", (void *)&resp->params,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 le16_to_cpu(resp->size) - S_DS_GEN);
746
747 /* Send a Media Connected event, according to the Spec */
David Woodhouseaa21c002007-12-08 20:04:36 +0000748 priv->connect_status = LBS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749
Dan Williamse76850d2007-05-25 17:09:41 -0400750 /* Update current SSID and BSSID */
David Woodhouseaa21c002007-12-08 20:04:36 +0000751 memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
752 priv->curbssparams.ssid_len = bss->ssid_len;
753 memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754
David Woodhouseaa21c002007-12-08 20:04:36 +0000755 priv->SNR[TYPE_RXPD][TYPE_AVG] = 0;
756 priv->NF[TYPE_RXPD][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757
David Woodhouseaa21c002007-12-08 20:04:36 +0000758 memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
759 memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
760 priv->nextSNRNF = 0;
761 priv->numSNRNF = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762
Holger Schurig634b8f42007-05-25 13:05:16 -0400763 netif_carrier_on(priv->dev);
David Woodhousea27b9f92007-12-12 00:41:51 -0500764 if (!priv->tx_pending_len)
765 netif_wake_queue(priv->dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400766
David Woodhouseaa21c002007-12-08 20:04:36 +0000767 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400769 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770
Holger Schurig9012b282007-05-25 11:27:16 -0400771done:
Holger Schurig91843462007-11-28 14:05:02 +0100772 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200773 return ret;
774}
775
Holger Schurig69f90322007-11-23 15:43:44 +0100776int lbs_ret_80211_disassociate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200777 struct cmd_ds_command *resp)
778{
Holger Schurig9012b282007-05-25 11:27:16 -0400779 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
Holger Schurig10078322007-11-15 18:05:47 -0500781 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
Holger Schurig9012b282007-05-25 11:27:16 -0400783 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200784 return 0;
785}
786
Holger Schurig69f90322007-11-23 15:43:44 +0100787int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200788 struct cmd_ds_command *resp)
789{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200790 int ret = 0;
791 u16 command = le16_to_cpu(resp->command);
792 u16 result = le16_to_cpu(resp->result);
793 struct cmd_ds_802_11_ad_hoc_result *padhocresult;
794 union iwreq_data wrqu;
Dan Williamse76850d2007-05-25 17:09:41 -0400795 struct bss_descriptor *bss;
Joe Perches0795af52007-10-03 17:59:30 -0700796 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797
Holger Schurig9012b282007-05-25 11:27:16 -0400798 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799
800 padhocresult = &resp->params.result;
801
Dan Williamse76850d2007-05-25 17:09:41 -0400802 lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size));
803 lbs_deb_join("ADHOC_RESP: command = %x\n", command);
804 lbs_deb_join("ADHOC_RESP: result = %x\n", result);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805
David Woodhouseaa21c002007-12-08 20:04:36 +0000806 if (!priv->in_progress_assoc_req) {
Dan Williamse76850d2007-05-25 17:09:41 -0400807 lbs_deb_join("ADHOC_RESP: no in-progress association request\n");
808 ret = -1;
809 goto done;
810 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000811 bss = &priv->in_progress_assoc_req->bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812
813 /*
814 * Join result code 0 --> SUCCESS
815 */
816 if (result) {
Dan Williamse76850d2007-05-25 17:09:41 -0400817 lbs_deb_join("ADHOC_RESP: failed\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000818 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500819 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 }
Holger Schurig9012b282007-05-25 11:27:16 -0400821 ret = -1;
822 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200823 }
824
825 /*
826 * Now the join cmd should be successful
827 * If BSSID has changed use SSID to compare instead of BSSID
828 */
Dan Williamsd8efea22007-05-28 23:54:55 -0400829 lbs_deb_join("ADHOC_RESP: associated to '%s'\n",
830 escape_essid(bss->ssid, bss->ssid_len));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831
832 /* Send a Media Connected event, according to the Spec */
David Woodhouseaa21c002007-12-08 20:04:36 +0000833 priv->connect_status = LBS_CONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200834
Holger Schurig6b63cd02007-08-02 11:53:36 -0400835 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836 /* Update the created network descriptor with the new BSSID */
Dan Williamsea8da922007-08-02 11:18:23 -0400837 memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200838 }
839
840 /* Set the BSSID from the joined/started descriptor */
David Woodhouseaa21c002007-12-08 20:04:36 +0000841 memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200842
843 /* Set the new SSID to current SSID */
David Woodhouseaa21c002007-12-08 20:04:36 +0000844 memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE);
845 priv->curbssparams.ssid_len = bss->ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200846
Holger Schurig634b8f42007-05-25 13:05:16 -0400847 netif_carrier_on(priv->dev);
David Woodhousea27b9f92007-12-12 00:41:51 -0500848 if (!priv->tx_pending_len)
849 netif_wake_queue(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200850
851 memset(&wrqu, 0, sizeof(wrqu));
David Woodhouseaa21c002007-12-08 20:04:36 +0000852 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Holger Schurig634b8f42007-05-25 13:05:16 -0400854 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200855
Holger Schurig9012b282007-05-25 11:27:16 -0400856 lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n");
David Woodhouseaa21c002007-12-08 20:04:36 +0000857 lbs_deb_join("ADHOC_RESP: channel = %d\n", priv->curbssparams.channel);
Joe Perches0795af52007-10-03 17:59:30 -0700858 lbs_deb_join("ADHOC_RESP: BSSID = %s\n",
859 print_mac(mac, padhocresult->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860
Holger Schurig9012b282007-05-25 11:27:16 -0400861done:
862 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863 return ret;
864}
865
Holger Schurig69f90322007-11-23 15:43:44 +0100866int lbs_ret_80211_ad_hoc_stop(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867 struct cmd_ds_command *resp)
868{
Holger Schurig9012b282007-05-25 11:27:16 -0400869 lbs_deb_enter(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870
Holger Schurig10078322007-11-15 18:05:47 -0500871 lbs_mac_event_disconnected(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200872
Holger Schurig9012b282007-05-25 11:27:16 -0400873 lbs_deb_leave(LBS_DEB_JOIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200874 return 0;
875}