Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 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 Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 10 | #include <linux/etherdevice.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 11 | |
| 12 | #include <net/iw_handler.h> |
| 13 | |
| 14 | #include "host.h" |
| 15 | #include "decl.h" |
| 16 | #include "join.h" |
| 17 | #include "dev.h" |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 18 | #include "assoc.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 19 | |
Luis Carlos Cobo | b37e584 | 2007-08-02 13:15:40 -0400 | [diff] [blame] | 20 | /* 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 Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 24 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 25 | /** |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 26 | * @brief This function finds common rates between rate1 and card rates. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 27 | * |
| 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 Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 33 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 34 | * @param rate1 the buffer which keeps input and output |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 35 | * @param rate1_size the size of rate1 buffer; new size of buffer on return |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 36 | * |
| 37 | * @return 0 or -1 |
| 38 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 39 | static int get_common_rates(struct lbs_private *priv, |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 40 | u8 *rates, |
| 41 | u16 *rates_size) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 42 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 43 | u8 *card_rates = lbs_bg_rates; |
| 44 | size_t num_card_rates = sizeof(lbs_bg_rates); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 45 | int ret = 0, i, j; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 46 | u8 tmp[30]; |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 47 | size_t tmp_size = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 48 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 49 | /* 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 57 | 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 Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 60 | lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 61 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 62 | if (!priv->auto_rate) { |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 63 | for (i = 0; i < tmp_size; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 64 | if (tmp[i] == priv->cur_rate) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 65 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 66 | } |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 67 | lbs_pr_alert("Previously set fixed data rate %#x isn't " |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 68 | "compatible with the network.\n", priv->cur_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 69 | ret = -1; |
| 70 | goto done; |
| 71 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 72 | ret = 0; |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 73 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 74 | done: |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 75 | memset(rates, 0, *rates_size); |
| 76 | *rates_size = min_t(int, tmp_size, *rates_size); |
| 77 | memcpy(rates, tmp, *rates_size); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 78 | return ret; |
| 79 | } |
| 80 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 81 | |
| 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 Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 90 | static void lbs_set_basic_rate_flags(u8 *rates, size_t len) |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 91 | { |
| 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 | /** |
| 102 | * @brief Unsets the MSB on basic rates |
| 103 | * |
| 104 | * Scan through an array and unset the MSB for basic data rates. |
| 105 | * |
| 106 | * @param rates buffer of data rates |
| 107 | * @param len size of buffer |
| 108 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 109 | void lbs_unset_basic_rate_flags(u8 *rates, size_t len) |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 110 | { |
| 111 | int i; |
| 112 | |
| 113 | for (i = 0; i < len; i++) |
| 114 | rates[i] &= 0x7f; |
| 115 | } |
| 116 | |
| 117 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 118 | /** |
| 119 | * @brief Associate to a specific BSS discovered in a scan |
| 120 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 121 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 122 | * @param pbssdesc Pointer to the BSS descriptor to associate with. |
| 123 | * |
| 124 | * @return 0-success, otherwise fail |
| 125 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 126 | int lbs_associate(struct lbs_private *priv, struct assoc_request *assoc_req) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 127 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 128 | int ret; |
| 129 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 130 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 131 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 132 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 133 | 0, CMD_OPTION_WAITFORRSP, |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 134 | 0, assoc_req->bss.bssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 135 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 136 | if (ret) |
| 137 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 138 | |
| 139 | /* set preamble to firmware */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 140 | if ( (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 141 | && (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 142 | priv->preamble = CMD_TYPE_SHORT_PREAMBLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | else |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 144 | priv->preamble = CMD_TYPE_LONG_PREAMBLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 145 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 146 | lbs_set_radio_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 147 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 148 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 149 | 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 150 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 151 | done: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 152 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @brief Start an Adhoc Network |
| 158 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 159 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 160 | * @param adhocssid The ssid of the Adhoc Network |
| 161 | * @return 0--success, -1--fail |
| 162 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 163 | int lbs_start_adhoc_network(struct lbs_private *priv, |
| 164 | struct assoc_request *assoc_req) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 165 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 166 | int ret = 0; |
| 167 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 168 | priv->adhoccreate = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 169 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 170 | if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 171 | lbs_deb_join("AdhocStart: Short preamble\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 172 | priv->preamble = CMD_TYPE_SHORT_PREAMBLE; |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 173 | } else { |
| 174 | lbs_deb_join("AdhocStart: Long preamble\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 175 | priv->preamble = CMD_TYPE_LONG_PREAMBLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 176 | } |
| 177 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 178 | lbs_set_radio_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 179 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 180 | lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel); |
| 181 | lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 182 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 183 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 184 | 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 185 | |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @brief Join an adhoc network found in a previous scan |
| 191 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 192 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 193 | * @param pbssdesc Pointer to a BSS descriptor found in a previous scan |
| 194 | * to attempt to join |
| 195 | * |
| 196 | * @return 0--success, -1--fail |
| 197 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 198 | int lbs_join_adhoc_network(struct lbs_private *priv, |
| 199 | struct assoc_request *assoc_req) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 200 | { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 201 | struct bss_descriptor * bss = &assoc_req->bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 202 | int ret = 0; |
| 203 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 204 | lbs_deb_join("%s: Current SSID '%s', ssid length %u\n", |
| 205 | __func__, |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 206 | escape_essid(priv->curbssparams.ssid, |
| 207 | priv->curbssparams.ssid_len), |
| 208 | priv->curbssparams.ssid_len); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 209 | lbs_deb_join("%s: requested ssid '%s', ssid length %u\n", |
| 210 | __func__, escape_essid(bss->ssid, bss->ssid_len), |
| 211 | bss->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 212 | |
| 213 | /* check if the requested SSID is already joined */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 214 | if ( priv->curbssparams.ssid_len |
| 215 | && !lbs_ssid_cmp(priv->curbssparams.ssid, |
| 216 | priv->curbssparams.ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 217 | bss->ssid, bss->ssid_len) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 218 | && (priv->mode == IW_MODE_ADHOC) |
| 219 | && (priv->connect_status == LBS_CONNECTED)) { |
Dan Williams | 0edef21 | 2007-08-02 13:14:29 -0400 | [diff] [blame] | 220 | union iwreq_data wrqu; |
| 221 | |
| 222 | lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as " |
| 223 | "current, not attempting to re-join"); |
| 224 | |
| 225 | /* Send the re-association event though, because the association |
| 226 | * request really was successful, even if just a null-op. |
| 227 | */ |
| 228 | memset(&wrqu, 0, sizeof(wrqu)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 229 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, |
Dan Williams | 0edef21 | 2007-08-02 13:14:29 -0400 | [diff] [blame] | 230 | ETH_ALEN); |
| 231 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 232 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 233 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 234 | } |
| 235 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 236 | /* Use shortpreamble only when both creator and card supports |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 237 | short preamble */ |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 238 | if ( !(bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 239 | || !(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 240 | lbs_deb_join("AdhocJoin: Long preamble\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 241 | priv->preamble = CMD_TYPE_LONG_PREAMBLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 242 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 243 | lbs_deb_join("AdhocJoin: Short preamble\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 244 | priv->preamble = CMD_TYPE_SHORT_PREAMBLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 245 | } |
| 246 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 247 | lbs_set_radio_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 248 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 249 | lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel); |
| 250 | lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 251 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 252 | priv->adhoccreate = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 253 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 254 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 255 | 0, CMD_OPTION_WAITFORRSP, |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 256 | OID_802_11_SSID, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 257 | |
Dan Williams | 0edef21 | 2007-08-02 13:14:29 -0400 | [diff] [blame] | 258 | out: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 259 | return ret; |
| 260 | } |
| 261 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 262 | int lbs_stop_adhoc_network(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 263 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 264 | return lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 265 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @brief Send Deauthentication Request |
| 270 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 271 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 272 | * @return 0--success, -1--fail |
| 273 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 274 | int lbs_send_deauthentication(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 275 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 276 | return lbs_prepare_and_send_command(priv, CMD_802_11_DEAUTHENTICATE, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 277 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 281 | * @brief This function prepares command of authenticate. |
| 282 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 283 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 284 | * @param cmd A pointer to cmd_ds_command structure |
| 285 | * @param pdata_buf Void cast of pointer to a BSSID to authenticate with |
| 286 | * |
| 287 | * @return 0 or -1 |
| 288 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 289 | int lbs_cmd_80211_authenticate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 290 | struct cmd_ds_command *cmd, |
| 291 | void *pdata_buf) |
| 292 | { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 293 | struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth; |
| 294 | int ret = -1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 295 | u8 *bssid = pdata_buf; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 296 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 297 | |
Dan Williams | 45f43de | 2007-05-25 22:58:55 -0400 | [diff] [blame] | 298 | lbs_deb_enter(LBS_DEB_JOIN); |
| 299 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 300 | cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE); |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 301 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate) |
| 302 | + S_DS_GEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 303 | |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 304 | /* translate auth mode to 802.11 defined wire value */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 305 | switch (priv->secinfo.auth_mode) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 306 | case IW_AUTH_ALG_OPEN_SYSTEM: |
| 307 | pauthenticate->authtype = 0x00; |
| 308 | break; |
| 309 | case IW_AUTH_ALG_SHARED_KEY: |
| 310 | pauthenticate->authtype = 0x01; |
| 311 | break; |
| 312 | case IW_AUTH_ALG_LEAP: |
| 313 | pauthenticate->authtype = 0x80; |
| 314 | break; |
| 315 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 316 | lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 317 | priv->secinfo.auth_mode); |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 318 | goto out; |
| 319 | } |
| 320 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 321 | memcpy(pauthenticate->macaddr, bssid, ETH_ALEN); |
| 322 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 323 | lbs_deb_join("AUTH_CMD: BSSID %s, auth 0x%x\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 324 | print_mac(mac, bssid), pauthenticate->authtype); |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 325 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 326 | |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 327 | out: |
Dan Williams | 45f43de | 2007-05-25 22:58:55 -0400 | [diff] [blame] | 328 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 329 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 330 | } |
| 331 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 332 | int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 333 | struct cmd_ds_command *cmd) |
| 334 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 335 | struct cmd_ds_802_11_deauthenticate *dauth = &cmd->params.deauth; |
| 336 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 337 | lbs_deb_enter(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 338 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 339 | cmd->command = cpu_to_le16(CMD_802_11_DEAUTHENTICATE); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 340 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_deauthenticate) + |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 341 | S_DS_GEN); |
| 342 | |
| 343 | /* set AP MAC address */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 344 | memmove(dauth->macaddr, priv->curbssparams.bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 345 | |
| 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 Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 350 | lbs_deb_leave(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 354 | int lbs_cmd_80211_associate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 355 | struct cmd_ds_command *cmd, void *pdata_buf) |
| 356 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 357 | struct cmd_ds_802_11_associate *passo = &cmd->params.associate; |
| 358 | int ret = 0; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 359 | struct assoc_request * assoc_req = pdata_buf; |
| 360 | struct bss_descriptor * bss = &assoc_req->bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 361 | u8 *pos; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 362 | u16 tmpcap, tmplen; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 363 | struct mrvlietypes_ssidparamset *ssid; |
| 364 | struct mrvlietypes_phyparamset *phy; |
| 365 | struct mrvlietypes_ssparamset *ss; |
| 366 | struct mrvlietypes_ratesparamset *rates; |
| 367 | struct mrvlietypes_rsnparamset *rsn; |
| 368 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 369 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 370 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 371 | pos = (u8 *) passo; |
| 372 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 373 | if (!priv) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 374 | ret = -1; |
| 375 | goto done; |
| 376 | } |
| 377 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 378 | cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 379 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 380 | memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 381 | pos += sizeof(passo->peerstaaddr); |
| 382 | |
| 383 | /* set the listen interval */ |
Holger Schurig | 0aabc0a5 | 2007-08-02 13:10:59 -0400 | [diff] [blame] | 384 | passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 385 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 386 | pos += sizeof(passo->capability); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 387 | pos += sizeof(passo->listeninterval); |
| 388 | pos += sizeof(passo->bcnperiod); |
| 389 | pos += sizeof(passo->dtimperiod); |
| 390 | |
| 391 | ssid = (struct mrvlietypes_ssidparamset *) pos; |
| 392 | ssid->header.type = cpu_to_le16(TLV_TYPE_SSID); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 393 | tmplen = bss->ssid_len; |
David Woodhouse | 707985b | 2007-05-25 23:41:16 -0400 | [diff] [blame] | 394 | ssid->header.len = cpu_to_le16(tmplen); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 395 | memcpy(ssid->ssid, bss->ssid, tmplen); |
David Woodhouse | 707985b | 2007-05-25 23:41:16 -0400 | [diff] [blame] | 396 | pos += sizeof(ssid->header) + tmplen; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 397 | |
| 398 | phy = (struct mrvlietypes_phyparamset *) pos; |
| 399 | phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); |
David Woodhouse | 707985b | 2007-05-25 23:41:16 -0400 | [diff] [blame] | 400 | tmplen = sizeof(phy->fh_ds.dsparamset); |
| 401 | phy->header.len = cpu_to_le16(tmplen); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 402 | memcpy(&phy->fh_ds.dsparamset, |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 403 | &bss->phyparamset.dsparamset.currentchan, |
David Woodhouse | 707985b | 2007-05-25 23:41:16 -0400 | [diff] [blame] | 404 | tmplen); |
| 405 | pos += sizeof(phy->header) + tmplen; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 406 | |
| 407 | ss = (struct mrvlietypes_ssparamset *) pos; |
| 408 | ss->header.type = cpu_to_le16(TLV_TYPE_CF); |
David Woodhouse | 707985b | 2007-05-25 23:41:16 -0400 | [diff] [blame] | 409 | tmplen = sizeof(ss->cf_ibss.cfparamset); |
| 410 | ss->header.len = cpu_to_le16(tmplen); |
| 411 | pos += sizeof(ss->header) + tmplen; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 412 | |
| 413 | rates = (struct mrvlietypes_ratesparamset *) pos; |
| 414 | rates->header.type = cpu_to_le16(TLV_TYPE_RATES); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 415 | memcpy(&rates->rates, &bss->rates, MAX_RATES); |
| 416 | tmplen = MAX_RATES; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 417 | if (get_common_rates(priv, rates->rates, &tmplen)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 418 | ret = -1; |
| 419 | goto done; |
| 420 | } |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 421 | pos += sizeof(rates->header) + tmplen; |
| 422 | rates->header.len = cpu_to_le16(tmplen); |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 423 | lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 424 | |
| 425 | /* Copy the infra. association rates into Current BSS state structure */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 426 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 427 | memcpy(&priv->curbssparams.rates, &rates->rates, tmplen); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 428 | |
| 429 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 430 | * copying to current bss rates. |
| 431 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 432 | lbs_set_basic_rate_flags(rates->rates, tmplen); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 433 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 434 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 435 | rsn = (struct mrvlietypes_rsnparamset *) pos; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 436 | /* WPA_IE or WPA2_IE */ |
| 437 | rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]); |
| 438 | tmplen = (u16) assoc_req->wpa_ie[1]; |
| 439 | rsn->header.len = cpu_to_le16(tmplen); |
| 440 | memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 441 | lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn, |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 442 | sizeof(rsn->header) + tmplen); |
| 443 | pos += sizeof(rsn->header) + tmplen; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /* update curbssparams */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 447 | priv->curbssparams.channel = bss->phyparamset.dsparamset.currentchan; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 448 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 449 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 450 | ret = -1; |
| 451 | goto done; |
| 452 | } |
| 453 | |
| 454 | cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN); |
| 455 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 456 | /* set the capability info */ |
| 457 | tmpcap = (bss->capability & CAPINFO_MASK); |
| 458 | if (bss->mode == IW_MODE_INFRA) |
| 459 | tmpcap |= WLAN_CAPABILITY_ESS; |
| 460 | passo->capability = cpu_to_le16(tmpcap); |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 461 | lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 462 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 463 | done: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 464 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 465 | return ret; |
| 466 | } |
| 467 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 468 | int lbs_cmd_80211_ad_hoc_start(struct lbs_private *priv, |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 469 | struct cmd_ds_command *cmd, void *pdata_buf) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 470 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 471 | struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads; |
| 472 | int ret = 0; |
| 473 | int cmdappendsize = 0; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 474 | struct assoc_request * assoc_req = pdata_buf; |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 475 | u16 tmpcap = 0; |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 476 | size_t ratesize = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 477 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 478 | lbs_deb_enter(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 479 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 480 | if (!priv) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 481 | ret = -1; |
| 482 | goto done; |
| 483 | } |
| 484 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 485 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 486 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 487 | /* |
| 488 | * Fill in the parameters for 2 data structures: |
| 489 | * 1. cmd_ds_802_11_ad_hoc_start command |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 490 | * 2. priv->scantable[i] |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 491 | * |
| 492 | * Driver will fill up SSID, bsstype,IBSS param, Physical Param, |
| 493 | * probe delay, and cap info. |
| 494 | * |
| 495 | * Firmware will fill up beacon period, DTIM, Basic rates |
| 496 | * and operational rates. |
| 497 | */ |
| 498 | |
Dan Williams | b44898e | 2007-08-02 11:18:40 -0400 | [diff] [blame] | 499 | memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE); |
| 500 | memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 501 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 502 | lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n", |
| 503 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), |
| 504 | assoc_req->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 505 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 506 | /* set the BSS type */ |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 507 | adhs->bsstype = CMD_BSS_TYPE_IBSS; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 508 | priv->mode = IW_MODE_ADHOC; |
| 509 | if (priv->beacon_period == 0) |
| 510 | priv->beacon_period = MRVDRV_BEACON_INTERVAL; |
| 511 | adhs->beaconperiod = cpu_to_le16(priv->beacon_period); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 512 | |
| 513 | /* set Physical param set */ |
| 514 | #define DS_PARA_IE_ID 3 |
| 515 | #define DS_PARA_IE_LEN 1 |
| 516 | |
| 517 | adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID; |
| 518 | adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN; |
| 519 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 520 | WARN_ON(!assoc_req->channel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 521 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 522 | lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 523 | assoc_req->channel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 524 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 525 | adhs->phyparamset.dsparamset.currentchan = assoc_req->channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 526 | |
| 527 | /* set IBSS param set */ |
| 528 | #define IBSS_PARA_IE_ID 6 |
| 529 | #define IBSS_PARA_IE_LEN 2 |
| 530 | |
| 531 | adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID; |
| 532 | adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN; |
Holger Schurig | ae596ce | 2007-08-02 13:10:05 -0400 | [diff] [blame] | 533 | adhs->ssparamset.ibssparamset.atimwindow = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 534 | |
| 535 | /* set capability info */ |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 536 | tmpcap = WLAN_CAPABILITY_IBSS; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 537 | if (assoc_req->secinfo.wep_enabled) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 538 | lbs_deb_join("ADHOC_S_CMD: WEP enabled, setting privacy on\n"); |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 539 | tmpcap |= WLAN_CAPABILITY_PRIVACY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 540 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 541 | lbs_deb_join("ADHOC_S_CMD: WEP disabled, setting privacy off\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 542 | } |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 543 | adhs->capability = cpu_to_le16(tmpcap); |
| 544 | |
| 545 | /* probedelay */ |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 546 | adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 547 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 548 | memset(adhs->rates, 0, sizeof(adhs->rates)); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 549 | ratesize = min(sizeof(adhs->rates), sizeof(lbs_bg_rates)); |
| 550 | memcpy(adhs->rates, lbs_bg_rates, ratesize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 551 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 552 | /* Copy the ad-hoc creating rates into Current BSS state structure */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 553 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 554 | memcpy(&priv->curbssparams.rates, &adhs->rates, ratesize); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 555 | |
| 556 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 557 | * copying to current bss rates. |
| 558 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 559 | lbs_set_basic_rate_flags(adhs->rates, ratesize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 560 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 561 | lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n", |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 562 | adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 563 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 564 | lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 565 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 566 | if (lbs_create_dnld_countryinfo_11d(priv)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 567 | lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 568 | ret = -1; |
| 569 | goto done; |
| 570 | } |
| 571 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 572 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) + |
| 573 | S_DS_GEN + cmdappendsize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 574 | |
| 575 | ret = 0; |
| 576 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 577 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 578 | return ret; |
| 579 | } |
| 580 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 581 | int lbs_cmd_80211_ad_hoc_stop(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 582 | struct cmd_ds_command *cmd) |
| 583 | { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 584 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 585 | cmd->size = cpu_to_le16(S_DS_GEN); |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 590 | int lbs_cmd_80211_ad_hoc_join(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 591 | struct cmd_ds_command *cmd, void *pdata_buf) |
| 592 | { |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 593 | struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 594 | struct assoc_request * assoc_req = pdata_buf; |
| 595 | struct bss_descriptor *bss = &assoc_req->bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 596 | int cmdappendsize = 0; |
| 597 | int ret = 0; |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 598 | u16 ratesize = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 599 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 600 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 601 | lbs_deb_enter(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 602 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 603 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 604 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 605 | join_cmd->bss.type = CMD_BSS_TYPE_IBSS; |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 606 | join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 607 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 608 | memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN); |
| 609 | memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 610 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 611 | memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset, |
| 612 | sizeof(union ieeetypes_phyparamset)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 613 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 614 | memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset, |
| 615 | sizeof(union IEEEtypes_ssparamset)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 616 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 617 | join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 618 | lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 619 | bss->capability, CAPINFO_MASK); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 620 | |
| 621 | /* information on BSSID descriptor passed to FW */ |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 622 | lbs_deb_join( |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 623 | "ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n", |
| 624 | print_mac(mac, join_cmd->bss.bssid), |
| 625 | join_cmd->bss.ssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 626 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 627 | /* failtimeout */ |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 628 | join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 629 | |
| 630 | /* probedelay */ |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 631 | join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 632 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 633 | priv->curbssparams.channel = bss->channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 635 | /* 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); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 639 | if (get_common_rates(priv, join_cmd->bss.rates, &ratesize)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 640 | lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 641 | ret = -1; |
| 642 | goto done; |
| 643 | } |
| 644 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 645 | /* Copy the ad-hoc creating rates into Current BSS state structure */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 646 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 647 | memcpy(&priv->curbssparams.rates, join_cmd->bss.rates, ratesize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 648 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 649 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 650 | * copying to current bss rates. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 651 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 652 | lbs_set_basic_rate_flags(join_cmd->bss.rates, ratesize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 653 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 654 | join_cmd->bss.ssparamset.ibssparamset.atimwindow = |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 655 | cpu_to_le16(bss->atimwindow); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 656 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 657 | if (assoc_req->secinfo.wep_enabled) { |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 658 | u16 tmp = le16_to_cpu(join_cmd->bss.capability); |
| 659 | tmp |= WLAN_CAPABILITY_PRIVACY; |
| 660 | join_cmd->bss.capability = cpu_to_le16(tmp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 661 | } |
| 662 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 663 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 664 | /* wake up first */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 665 | __le32 Localpsmode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 666 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 667 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); |
| 668 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 669 | CMD_802_11_PS_MODE, |
| 670 | CMD_ACT_SET, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | 0, 0, &Localpsmode); |
| 672 | |
| 673 | if (ret) { |
| 674 | ret = -1; |
| 675 | goto done; |
| 676 | } |
| 677 | } |
| 678 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 679 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 680 | ret = -1; |
| 681 | goto done; |
| 682 | } |
| 683 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 684 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) + |
| 685 | S_DS_GEN + cmdappendsize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 686 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 687 | done: |
| 688 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 689 | return ret; |
| 690 | } |
| 691 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 692 | int lbs_ret_80211_associate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 693 | struct cmd_ds_command *resp) |
| 694 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 695 | int ret = 0; |
| 696 | union iwreq_data wrqu; |
| 697 | struct ieeetypes_assocrsp *passocrsp; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 698 | struct bss_descriptor * bss; |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 699 | u16 status_code; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 700 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 701 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 702 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 703 | if (!priv->in_progress_assoc_req) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 704 | lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 705 | ret = -1; |
| 706 | goto done; |
| 707 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 708 | bss = &priv->in_progress_assoc_req->bss; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 709 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 710 | passocrsp = (struct ieeetypes_assocrsp *) & resp->params; |
| 711 | |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 712 | /* |
| 713 | * Older FW versions map the IEEE 802.11 Status Code in the association |
| 714 | * response to the following values returned in passocrsp->statuscode: |
| 715 | * |
| 716 | * IEEE Status Code Marvell Status Code |
| 717 | * 0 -> 0x0000 ASSOC_RESULT_SUCCESS |
| 718 | * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 719 | * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 720 | * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 721 | * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 722 | * others -> 0x0003 ASSOC_RESULT_REFUSED |
| 723 | * |
| 724 | * Other response codes: |
| 725 | * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused) |
| 726 | * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for |
| 727 | * association response from the AP) |
| 728 | */ |
| 729 | |
| 730 | status_code = le16_to_cpu(passocrsp->statuscode); |
| 731 | switch (status_code) { |
| 732 | case 0x00: |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 733 | break; |
| 734 | case 0x01: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 735 | lbs_deb_assoc("ASSOC_RESP: invalid parameters\n"); |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 736 | break; |
| 737 | case 0x02: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 738 | lbs_deb_assoc("ASSOC_RESP: internal timer " |
| 739 | "expired while waiting for the AP\n"); |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 740 | break; |
| 741 | case 0x03: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 742 | lbs_deb_assoc("ASSOC_RESP: association " |
| 743 | "refused by AP\n"); |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 744 | break; |
| 745 | case 0x04: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 746 | lbs_deb_assoc("ASSOC_RESP: authentication " |
| 747 | "refused by AP\n"); |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 748 | break; |
| 749 | default: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 750 | lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x " |
| 751 | " unknown\n", status_code); |
Dan Williams | c7fdf26 | 2007-08-02 13:20:29 -0400 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | |
| 755 | if (status_code) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 756 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 757 | ret = -1; |
| 758 | goto done; |
| 759 | } |
| 760 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 761 | lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", (void *)&resp->params, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 762 | le16_to_cpu(resp->size) - S_DS_GEN); |
| 763 | |
| 764 | /* Send a Media Connected event, according to the Spec */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 765 | priv->connect_status = LBS_CONNECTED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 766 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 767 | /* Update current SSID and BSSID */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 768 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); |
| 769 | priv->curbssparams.ssid_len = bss->ssid_len; |
| 770 | memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 771 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 772 | lbs_deb_assoc("ASSOC_RESP: currentpacketfilter is 0x%x\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 773 | priv->currentpacketfilter); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 774 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 775 | priv->SNR[TYPE_RXPD][TYPE_AVG] = 0; |
| 776 | priv->NF[TYPE_RXPD][TYPE_AVG] = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 777 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 778 | memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); |
| 779 | memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); |
| 780 | priv->nextSNRNF = 0; |
| 781 | priv->numSNRNF = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 782 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 783 | netif_carrier_on(priv->dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 784 | if (!priv->tx_pending_len) |
| 785 | netif_wake_queue(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 786 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 787 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 788 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 789 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 790 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 791 | done: |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 792 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 793 | return ret; |
| 794 | } |
| 795 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 796 | int lbs_ret_80211_disassociate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 797 | struct cmd_ds_command *resp) |
| 798 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 799 | lbs_deb_enter(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 800 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 801 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 802 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 803 | lbs_deb_leave(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 804 | return 0; |
| 805 | } |
| 806 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 807 | int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 808 | struct cmd_ds_command *resp) |
| 809 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 810 | int ret = 0; |
| 811 | u16 command = le16_to_cpu(resp->command); |
| 812 | u16 result = le16_to_cpu(resp->result); |
| 813 | struct cmd_ds_802_11_ad_hoc_result *padhocresult; |
| 814 | union iwreq_data wrqu; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 815 | struct bss_descriptor *bss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 816 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 817 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 818 | lbs_deb_enter(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 819 | |
| 820 | padhocresult = &resp->params.result; |
| 821 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 822 | lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size)); |
| 823 | lbs_deb_join("ADHOC_RESP: command = %x\n", command); |
| 824 | lbs_deb_join("ADHOC_RESP: result = %x\n", result); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 825 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 826 | if (!priv->in_progress_assoc_req) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 827 | lbs_deb_join("ADHOC_RESP: no in-progress association request\n"); |
| 828 | ret = -1; |
| 829 | goto done; |
| 830 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 831 | bss = &priv->in_progress_assoc_req->bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 832 | |
| 833 | /* |
| 834 | * Join result code 0 --> SUCCESS |
| 835 | */ |
| 836 | if (result) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 837 | lbs_deb_join("ADHOC_RESP: failed\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 838 | if (priv->connect_status == LBS_CONNECTED) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 839 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 840 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 841 | ret = -1; |
| 842 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /* |
| 846 | * Now the join cmd should be successful |
| 847 | * If BSSID has changed use SSID to compare instead of BSSID |
| 848 | */ |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 849 | lbs_deb_join("ADHOC_RESP: associated to '%s'\n", |
| 850 | escape_essid(bss->ssid, bss->ssid_len)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 851 | |
| 852 | /* Send a Media Connected event, according to the Spec */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 853 | priv->connect_status = LBS_CONNECTED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 854 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 855 | if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 856 | /* Update the created network descriptor with the new BSSID */ |
Dan Williams | ea8da92 | 2007-08-02 11:18:23 -0400 | [diff] [blame] | 857 | memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* Set the BSSID from the joined/started descriptor */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 861 | memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 862 | |
| 863 | /* Set the new SSID to current SSID */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 864 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); |
| 865 | priv->curbssparams.ssid_len = bss->ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 866 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 867 | netif_carrier_on(priv->dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 868 | if (!priv->tx_pending_len) |
| 869 | netif_wake_queue(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 870 | |
| 871 | memset(&wrqu, 0, sizeof(wrqu)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 872 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 873 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 874 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 875 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 876 | lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 877 | lbs_deb_join("ADHOC_RESP: channel = %d\n", priv->curbssparams.channel); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 878 | lbs_deb_join("ADHOC_RESP: BSSID = %s\n", |
| 879 | print_mac(mac, padhocresult->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 880 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 881 | done: |
| 882 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 883 | return ret; |
| 884 | } |
| 885 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 886 | int lbs_ret_80211_ad_hoc_stop(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 887 | struct cmd_ds_command *resp) |
| 888 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 889 | lbs_deb_enter(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 890 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 891 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 892 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 893 | lbs_deb_leave(LBS_DEB_JOIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 894 | return 0; |
| 895 | } |