Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains ioctl functions |
| 3 | */ |
| 4 | #include <linux/ctype.h> |
| 5 | #include <linux/delay.h> |
| 6 | #include <linux/if.h> |
| 7 | #include <linux/if_arp.h> |
| 8 | #include <linux/wireless.h> |
| 9 | #include <linux/bitops.h> |
| 10 | |
| 11 | #include <net/ieee80211.h> |
| 12 | #include <net/iw_handler.h> |
| 13 | |
| 14 | #include "host.h" |
| 15 | #include "radiotap.h" |
| 16 | #include "decl.h" |
| 17 | #include "defs.h" |
| 18 | #include "dev.h" |
| 19 | #include "join.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 20 | #include "wext.h" |
| 21 | #include "assoc.h" |
| 22 | |
| 23 | |
| 24 | /** |
Holger Schurig | bf68dac | 2007-05-25 00:14:38 -0400 | [diff] [blame] | 25 | * the rates supported by the card |
| 26 | */ |
| 27 | static u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] = |
| 28 | { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12, |
| 29 | 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00 |
| 30 | }; |
| 31 | |
| 32 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 33 | * @brief Convert mw value to dbm value |
| 34 | * |
| 35 | * @param mw the value of mw |
| 36 | * @return the value of dbm |
| 37 | */ |
| 38 | static int mw_to_dbm(int mw) |
| 39 | { |
| 40 | if (mw < 2) |
| 41 | return 0; |
| 42 | else if (mw < 3) |
| 43 | return 3; |
| 44 | else if (mw < 4) |
| 45 | return 5; |
| 46 | else if (mw < 6) |
| 47 | return 7; |
| 48 | else if (mw < 7) |
| 49 | return 8; |
| 50 | else if (mw < 8) |
| 51 | return 9; |
| 52 | else if (mw < 10) |
| 53 | return 10; |
| 54 | else if (mw < 13) |
| 55 | return 11; |
| 56 | else if (mw < 16) |
| 57 | return 12; |
| 58 | else if (mw < 20) |
| 59 | return 13; |
| 60 | else if (mw < 25) |
| 61 | return 14; |
| 62 | else if (mw < 32) |
| 63 | return 15; |
| 64 | else if (mw < 40) |
| 65 | return 16; |
| 66 | else if (mw < 50) |
| 67 | return 17; |
| 68 | else if (mw < 63) |
| 69 | return 18; |
| 70 | else if (mw < 79) |
| 71 | return 19; |
| 72 | else if (mw < 100) |
| 73 | return 20; |
| 74 | else |
| 75 | return 21; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @brief Find the channel frequency power info with specific channel |
| 80 | * |
| 81 | * @param adapter A pointer to wlan_adapter structure |
| 82 | * @param band it can be BAND_A, BAND_G or BAND_B |
| 83 | * @param channel the channel for looking |
| 84 | * @return A pointer to struct chan_freq_power structure or NULL if not find. |
| 85 | */ |
| 86 | struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter, |
| 87 | u8 band, u16 channel) |
| 88 | { |
| 89 | struct chan_freq_power *cfp = NULL; |
| 90 | struct region_channel *rc; |
| 91 | int count = sizeof(adapter->region_channel) / |
| 92 | sizeof(adapter->region_channel[0]); |
| 93 | int i, j; |
| 94 | |
| 95 | for (j = 0; !cfp && (j < count); j++) { |
| 96 | rc = &adapter->region_channel[j]; |
| 97 | |
| 98 | if (adapter->enable11d) |
| 99 | rc = &adapter->universal_channel[j]; |
| 100 | if (!rc->valid || !rc->CFP) |
| 101 | continue; |
| 102 | if (rc->band != band) |
| 103 | continue; |
| 104 | for (i = 0; i < rc->nrcfp; i++) { |
| 105 | if (rc->CFP[i].channel == channel) { |
| 106 | cfp = &rc->CFP[i]; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (!cfp && channel) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 113 | lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find " |
| 114 | "cfp by band %d / channel %d\n", band, channel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 115 | |
| 116 | return cfp; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @brief Find the channel frequency power info with specific frequency |
| 121 | * |
| 122 | * @param adapter A pointer to wlan_adapter structure |
| 123 | * @param band it can be BAND_A, BAND_G or BAND_B |
| 124 | * @param freq the frequency for looking |
| 125 | * @return A pointer to struct chan_freq_power structure or NULL if not find. |
| 126 | */ |
| 127 | static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter, |
| 128 | u8 band, u32 freq) |
| 129 | { |
| 130 | struct chan_freq_power *cfp = NULL; |
| 131 | struct region_channel *rc; |
| 132 | int count = sizeof(adapter->region_channel) / |
| 133 | sizeof(adapter->region_channel[0]); |
| 134 | int i, j; |
| 135 | |
| 136 | for (j = 0; !cfp && (j < count); j++) { |
| 137 | rc = &adapter->region_channel[j]; |
| 138 | |
| 139 | if (adapter->enable11d) |
| 140 | rc = &adapter->universal_channel[j]; |
| 141 | if (!rc->valid || !rc->CFP) |
| 142 | continue; |
| 143 | if (rc->band != band) |
| 144 | continue; |
| 145 | for (i = 0; i < rc->nrcfp; i++) { |
| 146 | if (rc->CFP[i].freq == freq) { |
| 147 | cfp = &rc->CFP[i]; |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if (!cfp && freq) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 154 | lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by " |
| 155 | "band %d / freq %d\n", band, freq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 156 | |
| 157 | return cfp; |
| 158 | } |
| 159 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * @brief Set Radio On/OFF |
| 163 | * |
| 164 | * @param priv A pointer to wlan_private structure |
| 165 | * @option Radio Option |
| 166 | * @return 0 --success, otherwise fail |
| 167 | */ |
| 168 | int wlan_radio_ioctl(wlan_private * priv, u8 option) |
| 169 | { |
| 170 | int ret = 0; |
| 171 | wlan_adapter *adapter = priv->adapter; |
| 172 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 173 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 174 | |
| 175 | if (adapter->radioon != option) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 176 | lbs_deb_wext("switching radio %s\n", option ? "on" : "off"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 177 | adapter->radioon = option; |
| 178 | |
| 179 | ret = libertas_prepare_and_send_command(priv, |
| 180 | cmd_802_11_radio_control, |
| 181 | cmd_act_set, |
| 182 | cmd_option_waitforrsp, 0, NULL); |
| 183 | } |
| 184 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 185 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @brief Copy rates |
| 191 | * |
| 192 | * @param dest A pointer to Dest Buf |
| 193 | * @param src A pointer to Src Buf |
| 194 | * @param len The len of Src Buf |
| 195 | * @return Number of rates copyed |
| 196 | */ |
| 197 | static inline int copyrates(u8 * dest, int pos, u8 * src, int len) |
| 198 | { |
| 199 | int i; |
| 200 | |
| 201 | for (i = 0; i < len && src[i]; i++, pos++) { |
| 202 | if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES) |
| 203 | break; |
| 204 | dest[pos] = src[i]; |
| 205 | } |
| 206 | |
| 207 | return pos; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * @brief Get active data rates |
| 212 | * |
| 213 | * @param adapter A pointer to wlan_adapter structure |
| 214 | * @param rate The buf to return the active rates |
| 215 | * @return The number of rates |
| 216 | */ |
| 217 | static int get_active_data_rates(wlan_adapter * adapter, |
| 218 | u8* rates) |
| 219 | { |
| 220 | int k = 0; |
| 221 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 222 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 223 | |
| 224 | if (adapter->connect_status != libertas_connected) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 225 | if (adapter->mode == IW_MODE_INFRA) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 226 | lbs_deb_wext("infra\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 227 | k = copyrates(rates, k, libertas_supported_rates, |
| 228 | sizeof(libertas_supported_rates)); |
| 229 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 230 | lbs_deb_wext("Adhoc G\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 231 | k = copyrates(rates, k, libertas_adhoc_rates_g, |
| 232 | sizeof(libertas_adhoc_rates_g)); |
| 233 | } |
| 234 | } else { |
| 235 | k = copyrates(rates, 0, adapter->curbssparams.datarates, |
| 236 | adapter->curbssparams.numofrates); |
| 237 | } |
| 238 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 239 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 240 | return k; |
| 241 | } |
| 242 | |
| 243 | static int wlan_get_name(struct net_device *dev, struct iw_request_info *info, |
| 244 | char *cwrq, char *extra) |
| 245 | { |
| 246 | const char *cp; |
| 247 | char comm[6] = { "COMM-" }; |
| 248 | char mrvl[6] = { "MRVL-" }; |
| 249 | int cnt; |
| 250 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 251 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 252 | |
| 253 | strcpy(cwrq, mrvl); |
| 254 | |
| 255 | cp = strstr(libertas_driver_version, comm); |
| 256 | if (cp == libertas_driver_version) //skip leading "COMM-" |
| 257 | cp = libertas_driver_version + strlen(comm); |
| 258 | else |
| 259 | cp = libertas_driver_version; |
| 260 | |
| 261 | cnt = strlen(mrvl); |
| 262 | cwrq += cnt; |
| 263 | while (cnt < 16 && (*cp != '-')) { |
| 264 | *cwrq++ = toupper(*cp++); |
| 265 | cnt++; |
| 266 | } |
| 267 | *cwrq = '\0'; |
| 268 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 269 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info, |
| 274 | struct iw_freq *fwrq, char *extra) |
| 275 | { |
| 276 | wlan_private *priv = dev->priv; |
| 277 | wlan_adapter *adapter = priv->adapter; |
| 278 | struct chan_freq_power *cfp; |
| 279 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 280 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 281 | |
| 282 | cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, |
| 283 | adapter->curbssparams.channel); |
| 284 | |
| 285 | if (!cfp) { |
| 286 | if (adapter->curbssparams.channel) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 287 | lbs_deb_wext("invalid channel %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 288 | adapter->curbssparams.channel); |
| 289 | return -EINVAL; |
| 290 | } |
| 291 | |
| 292 | fwrq->m = (long)cfp->freq * 100000; |
| 293 | fwrq->e = 1; |
| 294 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 295 | lbs_deb_wext("freq %u\n", fwrq->m); |
| 296 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info, |
| 301 | struct sockaddr *awrq, char *extra) |
| 302 | { |
| 303 | wlan_private *priv = dev->priv; |
| 304 | wlan_adapter *adapter = priv->adapter; |
| 305 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 306 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 | |
| 308 | if (adapter->connect_status == libertas_connected) { |
| 309 | memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN); |
| 310 | } else { |
| 311 | memset(awrq->sa_data, 0, ETH_ALEN); |
| 312 | } |
| 313 | awrq->sa_family = ARPHRD_ETHER; |
| 314 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 315 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info, |
| 320 | struct iw_point *dwrq, char *extra) |
| 321 | { |
| 322 | wlan_private *priv = dev->priv; |
| 323 | wlan_adapter *adapter = priv->adapter; |
| 324 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 325 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 326 | |
| 327 | /* |
| 328 | * Check the size of the string |
| 329 | */ |
| 330 | |
| 331 | if (dwrq->length > 16) { |
| 332 | return -E2BIG; |
| 333 | } |
| 334 | |
| 335 | mutex_lock(&adapter->lock); |
| 336 | memset(adapter->nodename, 0, sizeof(adapter->nodename)); |
| 337 | memcpy(adapter->nodename, extra, dwrq->length); |
| 338 | mutex_unlock(&adapter->lock); |
| 339 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 340 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info, |
| 345 | struct iw_point *dwrq, char *extra) |
| 346 | { |
| 347 | wlan_private *priv = dev->priv; |
| 348 | wlan_adapter *adapter = priv->adapter; |
| 349 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 350 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * Get the Nick Name saved |
| 354 | */ |
| 355 | |
| 356 | mutex_lock(&adapter->lock); |
| 357 | strncpy(extra, adapter->nodename, 16); |
| 358 | mutex_unlock(&adapter->lock); |
| 359 | |
| 360 | extra[16] = '\0'; |
| 361 | |
| 362 | /* |
| 363 | * If none, we may want to get the one that was set |
| 364 | */ |
| 365 | |
| 366 | /* |
| 367 | * Push it out ! |
| 368 | */ |
| 369 | dwrq->length = strlen(extra) + 1; |
| 370 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 371 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
Luis Carlos Cobo Rus | f5e05b6 | 2007-05-25 23:08:34 -0400 | [diff] [blame] | 375 | static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info, |
| 376 | struct iw_point *dwrq, char *extra) |
| 377 | { |
| 378 | wlan_private *priv = dev->priv; |
| 379 | wlan_adapter *adapter = priv->adapter; |
| 380 | |
| 381 | lbs_deb_enter(LBS_DEB_WEXT); |
| 382 | |
| 383 | /* Use nickname to indicate that mesh is on */ |
| 384 | |
| 385 | if (adapter->connect_status == libertas_connected) { |
| 386 | strncpy(extra, "Mesh", 12); |
| 387 | extra[12] = '\0'; |
| 388 | dwrq->length = strlen(extra) + 1; |
| 389 | } |
| 390 | |
| 391 | else { |
| 392 | extra[0] = '\0'; |
| 393 | dwrq->length = 1 ; |
| 394 | } |
| 395 | |
| 396 | lbs_deb_leave(LBS_DEB_WEXT); |
| 397 | return 0; |
| 398 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 399 | static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info, |
| 400 | struct iw_param *vwrq, char *extra) |
| 401 | { |
| 402 | int ret = 0; |
| 403 | wlan_private *priv = dev->priv; |
| 404 | wlan_adapter *adapter = priv->adapter; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 405 | u32 rthr = vwrq->value; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 406 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 407 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 408 | |
| 409 | if (vwrq->disabled) { |
| 410 | adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE; |
| 411 | } else { |
| 412 | if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE) |
| 413 | return -EINVAL; |
| 414 | adapter->rtsthsd = rthr; |
| 415 | } |
| 416 | |
| 417 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 418 | cmd_act_set, cmd_option_waitforrsp, |
| 419 | OID_802_11_RTS_THRESHOLD, &rthr); |
| 420 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 421 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info, |
| 426 | struct iw_param *vwrq, char *extra) |
| 427 | { |
| 428 | int ret = 0; |
| 429 | wlan_private *priv = dev->priv; |
| 430 | wlan_adapter *adapter = priv->adapter; |
| 431 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 432 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 433 | |
| 434 | adapter->rtsthsd = 0; |
| 435 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 436 | cmd_act_get, cmd_option_waitforrsp, |
| 437 | OID_802_11_RTS_THRESHOLD, NULL); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 438 | if (ret) |
| 439 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 440 | |
| 441 | vwrq->value = adapter->rtsthsd; |
| 442 | vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE) |
| 443 | || (vwrq->value > MRVDRV_RTS_MAX_VALUE)); |
| 444 | vwrq->fixed = 1; |
| 445 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 446 | out: |
| 447 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 448 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info, |
| 452 | struct iw_param *vwrq, char *extra) |
| 453 | { |
| 454 | int ret = 0; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 455 | u32 fthr = vwrq->value; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 456 | wlan_private *priv = dev->priv; |
| 457 | wlan_adapter *adapter = priv->adapter; |
| 458 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 459 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 460 | |
| 461 | if (vwrq->disabled) { |
| 462 | adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE; |
| 463 | } else { |
| 464 | if (fthr < MRVDRV_FRAG_MIN_VALUE |
| 465 | || fthr > MRVDRV_FRAG_MAX_VALUE) |
| 466 | return -EINVAL; |
| 467 | adapter->fragthsd = fthr; |
| 468 | } |
| 469 | |
| 470 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 471 | cmd_act_set, cmd_option_waitforrsp, |
| 472 | OID_802_11_FRAGMENTATION_THRESHOLD, &fthr); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 473 | |
| 474 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info, |
| 479 | struct iw_param *vwrq, char *extra) |
| 480 | { |
| 481 | int ret = 0; |
| 482 | wlan_private *priv = dev->priv; |
| 483 | wlan_adapter *adapter = priv->adapter; |
| 484 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 485 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 486 | |
| 487 | adapter->fragthsd = 0; |
| 488 | ret = libertas_prepare_and_send_command(priv, |
| 489 | cmd_802_11_snmp_mib, |
| 490 | cmd_act_get, cmd_option_waitforrsp, |
| 491 | OID_802_11_FRAGMENTATION_THRESHOLD, NULL); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 492 | if (ret) |
| 493 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 494 | |
| 495 | vwrq->value = adapter->fragthsd; |
| 496 | vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE) |
| 497 | || (vwrq->value > MRVDRV_FRAG_MAX_VALUE)); |
| 498 | vwrq->fixed = 1; |
| 499 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 500 | out: |
| 501 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | static int wlan_get_mode(struct net_device *dev, |
| 506 | struct iw_request_info *info, u32 * uwrq, char *extra) |
| 507 | { |
| 508 | wlan_private *priv = dev->priv; |
| 509 | wlan_adapter *adapter = priv->adapter; |
| 510 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 511 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 512 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 513 | *uwrq = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 514 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 515 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
Luis Carlos Cobo Rus | f5e05b6 | 2007-05-25 23:08:34 -0400 | [diff] [blame] | 519 | static int mesh_wlan_get_mode(struct net_device *dev, |
| 520 | struct iw_request_info *info, u32 * uwrq, |
| 521 | char *extra) |
| 522 | { |
| 523 | lbs_deb_enter(LBS_DEB_WEXT); |
| 524 | |
| 525 | *uwrq = IW_MODE_REPEAT ; |
| 526 | |
| 527 | lbs_deb_leave(LBS_DEB_WEXT); |
| 528 | return 0; |
| 529 | } |
| 530 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 531 | static int wlan_get_txpow(struct net_device *dev, |
| 532 | struct iw_request_info *info, |
| 533 | struct iw_param *vwrq, char *extra) |
| 534 | { |
| 535 | int ret = 0; |
| 536 | wlan_private *priv = dev->priv; |
| 537 | wlan_adapter *adapter = priv->adapter; |
| 538 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 539 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 540 | |
| 541 | ret = libertas_prepare_and_send_command(priv, |
| 542 | cmd_802_11_rf_tx_power, |
| 543 | cmd_act_tx_power_opt_get, |
| 544 | cmd_option_waitforrsp, 0, NULL); |
| 545 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 546 | if (ret) |
| 547 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 548 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 549 | lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 550 | vwrq->value = adapter->txpowerlevel; |
| 551 | vwrq->fixed = 1; |
| 552 | if (adapter->radioon) { |
| 553 | vwrq->disabled = 0; |
| 554 | vwrq->flags = IW_TXPOW_DBM; |
| 555 | } else { |
| 556 | vwrq->disabled = 1; |
| 557 | } |
| 558 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 559 | out: |
| 560 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 561 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info, |
| 565 | struct iw_param *vwrq, char *extra) |
| 566 | { |
| 567 | int ret = 0; |
| 568 | wlan_private *priv = dev->priv; |
| 569 | wlan_adapter *adapter = priv->adapter; |
| 570 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 571 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 572 | |
| 573 | if (vwrq->flags == IW_RETRY_LIMIT) { |
| 574 | /* The MAC has a 4-bit Total_Tx_Count register |
| 575 | Total_Tx_Count = 1 + Tx_Retry_Count */ |
| 576 | #define TX_RETRY_MIN 0 |
| 577 | #define TX_RETRY_MAX 14 |
| 578 | if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | /* Adding 1 to convert retry count to try count */ |
| 582 | adapter->txretrycount = vwrq->value + 1; |
| 583 | |
| 584 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 585 | cmd_act_set, |
| 586 | cmd_option_waitforrsp, |
| 587 | OID_802_11_TX_RETRYCOUNT, NULL); |
| 588 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 589 | if (ret) |
| 590 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 591 | } else { |
| 592 | return -EOPNOTSUPP; |
| 593 | } |
| 594 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 595 | out: |
| 596 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 597 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info, |
| 601 | struct iw_param *vwrq, char *extra) |
| 602 | { |
| 603 | wlan_private *priv = dev->priv; |
| 604 | wlan_adapter *adapter = priv->adapter; |
| 605 | int ret = 0; |
| 606 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 607 | lbs_deb_enter(LBS_DEB_WEXT); |
| 608 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 609 | adapter->txretrycount = 0; |
| 610 | ret = libertas_prepare_and_send_command(priv, |
| 611 | cmd_802_11_snmp_mib, |
| 612 | cmd_act_get, cmd_option_waitforrsp, |
| 613 | OID_802_11_TX_RETRYCOUNT, NULL); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 614 | if (ret) |
| 615 | goto out; |
| 616 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 617 | vwrq->disabled = 0; |
| 618 | if (!vwrq->flags) { |
| 619 | vwrq->flags = IW_RETRY_LIMIT; |
| 620 | /* Subtract 1 to convert try count to retry count */ |
| 621 | vwrq->value = adapter->txretrycount - 1; |
| 622 | } |
| 623 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 624 | out: |
| 625 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 626 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | static inline void sort_channels(struct iw_freq *freq, int num) |
| 630 | { |
| 631 | int i, j; |
| 632 | struct iw_freq temp; |
| 633 | |
| 634 | for (i = 0; i < num; i++) |
| 635 | for (j = i + 1; j < num; j++) |
| 636 | if (freq[i].i > freq[j].i) { |
| 637 | temp.i = freq[i].i; |
| 638 | temp.m = freq[i].m; |
| 639 | |
| 640 | freq[i].i = freq[j].i; |
| 641 | freq[i].m = freq[j].m; |
| 642 | |
| 643 | freq[j].i = temp.i; |
| 644 | freq[j].m = temp.m; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /* data rate listing |
| 649 | MULTI_BANDS: |
| 650 | abg a b b/g |
| 651 | Infra G(12) A(8) B(4) G(12) |
| 652 | Adhoc A+B(12) A(8) B(4) B(4) |
| 653 | |
| 654 | non-MULTI_BANDS: |
| 655 | b b/g |
| 656 | Infra B(4) G(12) |
| 657 | Adhoc B(4) B(4) |
| 658 | */ |
| 659 | /** |
| 660 | * @brief Get Range Info |
| 661 | * |
| 662 | * @param dev A pointer to net_device structure |
| 663 | * @param info A pointer to iw_request_info structure |
| 664 | * @param vwrq A pointer to iw_param structure |
| 665 | * @param extra A pointer to extra data buf |
| 666 | * @return 0 --success, otherwise fail |
| 667 | */ |
| 668 | static int wlan_get_range(struct net_device *dev, struct iw_request_info *info, |
| 669 | struct iw_point *dwrq, char *extra) |
| 670 | { |
| 671 | int i, j; |
| 672 | wlan_private *priv = dev->priv; |
| 673 | wlan_adapter *adapter = priv->adapter; |
| 674 | struct iw_range *range = (struct iw_range *)extra; |
| 675 | struct chan_freq_power *cfp; |
| 676 | u8 rates[WLAN_SUPPORTED_RATES]; |
| 677 | |
| 678 | u8 flag = 0; |
| 679 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 680 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 681 | |
| 682 | dwrq->length = sizeof(struct iw_range); |
| 683 | memset(range, 0, sizeof(struct iw_range)); |
| 684 | |
| 685 | range->min_nwid = 0; |
| 686 | range->max_nwid = 0; |
| 687 | |
| 688 | memset(rates, 0, sizeof(rates)); |
| 689 | range->num_bitrates = get_active_data_rates(adapter, rates); |
| 690 | |
| 691 | for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i]; |
| 692 | i++) { |
| 693 | range->bitrate[i] = (rates[i] & 0x7f) * 500000; |
| 694 | } |
| 695 | range->num_bitrates = i; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 696 | lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 697 | range->num_bitrates); |
| 698 | |
| 699 | range->num_frequency = 0; |
| 700 | if (priv->adapter->enable11d && |
| 701 | adapter->connect_status == libertas_connected) { |
| 702 | u8 chan_no; |
| 703 | u8 band; |
| 704 | |
| 705 | struct parsed_region_chan_11d *parsed_region_chan = |
| 706 | &adapter->parsed_region_chan; |
| 707 | |
| 708 | if (parsed_region_chan == NULL) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 709 | lbs_deb_wext("11d: parsed_region_chan is NULL\n"); |
| 710 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 711 | } |
| 712 | band = parsed_region_chan->band; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 713 | lbs_deb_wext("band %d, nr_char %d\n", band, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 714 | parsed_region_chan->nr_chan); |
| 715 | |
| 716 | for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES) |
| 717 | && (i < parsed_region_chan->nr_chan); i++) { |
| 718 | chan_no = parsed_region_chan->chanpwr[i].chan; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 719 | lbs_deb_wext("chan_no %d\n", chan_no); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 720 | range->freq[range->num_frequency].i = (long)chan_no; |
| 721 | range->freq[range->num_frequency].m = |
| 722 | (long)libertas_chan_2_freq(chan_no, band) * 100000; |
| 723 | range->freq[range->num_frequency].e = 1; |
| 724 | range->num_frequency++; |
| 725 | } |
| 726 | flag = 1; |
| 727 | } |
| 728 | if (!flag) { |
| 729 | for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES) |
| 730 | && (j < sizeof(adapter->region_channel) |
| 731 | / sizeof(adapter->region_channel[0])); j++) { |
| 732 | cfp = adapter->region_channel[j].CFP; |
| 733 | for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES) |
| 734 | && adapter->region_channel[j].valid |
| 735 | && cfp |
| 736 | && (i < adapter->region_channel[j].nrcfp); i++) { |
| 737 | range->freq[range->num_frequency].i = |
| 738 | (long)cfp->channel; |
| 739 | range->freq[range->num_frequency].m = |
| 740 | (long)cfp->freq * 100000; |
| 741 | range->freq[range->num_frequency].e = 1; |
| 742 | cfp++; |
| 743 | range->num_frequency++; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 748 | lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 749 | IW_MAX_FREQUENCIES, range->num_frequency); |
| 750 | |
| 751 | range->num_channels = range->num_frequency; |
| 752 | |
| 753 | sort_channels(&range->freq[0], range->num_frequency); |
| 754 | |
| 755 | /* |
| 756 | * Set an indication of the max TCP throughput in bit/s that we can |
| 757 | * expect using this interface |
| 758 | */ |
| 759 | if (i > 2) |
| 760 | range->throughput = 5000 * 1000; |
| 761 | else |
| 762 | range->throughput = 1500 * 1000; |
| 763 | |
| 764 | range->min_rts = MRVDRV_RTS_MIN_VALUE; |
| 765 | range->max_rts = MRVDRV_RTS_MAX_VALUE; |
| 766 | range->min_frag = MRVDRV_FRAG_MIN_VALUE; |
| 767 | range->max_frag = MRVDRV_FRAG_MAX_VALUE; |
| 768 | |
| 769 | range->encoding_size[0] = 5; |
| 770 | range->encoding_size[1] = 13; |
| 771 | range->num_encoding_sizes = 2; |
| 772 | range->max_encoding_tokens = 4; |
| 773 | |
| 774 | range->min_pmp = 1000000; |
| 775 | range->max_pmp = 120000000; |
| 776 | range->min_pmt = 1000; |
| 777 | range->max_pmt = 1000000; |
| 778 | range->pmp_flags = IW_POWER_PERIOD; |
| 779 | range->pmt_flags = IW_POWER_TIMEOUT; |
| 780 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R; |
| 781 | |
| 782 | /* |
| 783 | * Minimum version we recommend |
| 784 | */ |
| 785 | range->we_version_source = 15; |
| 786 | |
| 787 | /* |
| 788 | * Version we are compiled with |
| 789 | */ |
| 790 | range->we_version_compiled = WIRELESS_EXT; |
| 791 | |
| 792 | range->retry_capa = IW_RETRY_LIMIT; |
| 793 | range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 794 | |
| 795 | range->min_retry = TX_RETRY_MIN; |
| 796 | range->max_retry = TX_RETRY_MAX; |
| 797 | |
| 798 | /* |
| 799 | * Set the qual, level and noise range values |
| 800 | */ |
| 801 | range->max_qual.qual = 100; |
| 802 | range->max_qual.level = 0; |
| 803 | range->max_qual.noise = 0; |
| 804 | range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 805 | |
| 806 | range->avg_qual.qual = 70; |
| 807 | /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ |
| 808 | range->avg_qual.level = 0; |
| 809 | range->avg_qual.noise = 0; |
| 810 | range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 811 | |
| 812 | range->sensitivity = 0; |
| 813 | |
| 814 | /* |
| 815 | * Setup the supported power level ranges |
| 816 | */ |
| 817 | memset(range->txpower, 0, sizeof(range->txpower)); |
| 818 | range->txpower[0] = 5; |
| 819 | range->txpower[1] = 7; |
| 820 | range->txpower[2] = 9; |
| 821 | range->txpower[3] = 11; |
| 822 | range->txpower[4] = 13; |
| 823 | range->txpower[5] = 15; |
| 824 | range->txpower[6] = 17; |
| 825 | range->txpower[7] = 19; |
| 826 | |
| 827 | range->num_txpower = 8; |
| 828 | range->txpower_capa = IW_TXPOW_DBM; |
| 829 | range->txpower_capa |= IW_TXPOW_RANGE; |
| 830 | |
| 831 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 832 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 833 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
| 834 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
| 835 | |
| 836 | if (adapter->fwcapinfo & FW_CAPINFO_WPA) { |
| 837 | range->enc_capa = IW_ENC_CAPA_WPA |
| 838 | | IW_ENC_CAPA_WPA2 |
| 839 | | IW_ENC_CAPA_CIPHER_TKIP |
| 840 | | IW_ENC_CAPA_CIPHER_CCMP; |
| 841 | } |
| 842 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 843 | out: |
| 844 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | static int wlan_set_power(struct net_device *dev, struct iw_request_info *info, |
| 849 | struct iw_param *vwrq, char *extra) |
| 850 | { |
| 851 | wlan_private *priv = dev->priv; |
| 852 | wlan_adapter *adapter = priv->adapter; |
| 853 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 854 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 855 | |
| 856 | /* PS is currently supported only in Infrastructure mode |
| 857 | * Remove this check if it is to be supported in IBSS mode also |
| 858 | */ |
| 859 | |
| 860 | if (vwrq->disabled) { |
| 861 | adapter->psmode = wlan802_11powermodecam; |
| 862 | if (adapter->psstate != PS_STATE_FULL_POWER) { |
| 863 | libertas_ps_wakeup(priv, cmd_option_waitforrsp); |
| 864 | } |
| 865 | |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 870 | lbs_deb_wext( |
| 871 | "setting power timeout is not supported\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 872 | return -EINVAL; |
| 873 | } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 874 | lbs_deb_wext("setting power period not supported\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 875 | return -EINVAL; |
| 876 | } |
| 877 | |
| 878 | if (adapter->psmode != wlan802_11powermodecam) { |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | adapter->psmode = wlan802_11powermodemax_psp; |
| 883 | |
| 884 | if (adapter->connect_status == libertas_connected) { |
| 885 | libertas_ps_sleep(priv, cmd_option_waitforrsp); |
| 886 | } |
| 887 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 888 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static int wlan_get_power(struct net_device *dev, struct iw_request_info *info, |
| 893 | struct iw_param *vwrq, char *extra) |
| 894 | { |
| 895 | wlan_private *priv = dev->priv; |
| 896 | wlan_adapter *adapter = priv->adapter; |
| 897 | int mode; |
| 898 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 899 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 900 | |
| 901 | mode = adapter->psmode; |
| 902 | |
| 903 | if ((vwrq->disabled = (mode == wlan802_11powermodecam)) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 904 | || adapter->connect_status == libertas_disconnected) |
| 905 | { |
| 906 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | vwrq->value = 0; |
| 910 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 911 | out: |
| 912 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | * iwpriv settable callbacks |
| 918 | */ |
| 919 | |
| 920 | static const iw_handler wlan_private_handler[] = { |
| 921 | NULL, /* SIOCIWFIRSTPRIV */ |
| 922 | }; |
| 923 | |
| 924 | static const struct iw_priv_args wlan_private_args[] = { |
| 925 | /* |
| 926 | * { cmd, set_args, get_args, name } |
| 927 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 928 | /* Using iwpriv sub-command feature */ |
| 929 | { |
| 930 | WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */ |
| 931 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 932 | IW_PRIV_TYPE_NONE, |
| 933 | ""}, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 934 | { |
| 935 | WLANSETREGION, |
| 936 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 937 | IW_PRIV_TYPE_NONE, |
| 938 | "setregioncode"}, |
| 939 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 940 | WLAN_SUBCMD_MESH_SET_TTL, |
| 941 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 942 | IW_PRIV_TYPE_NONE, |
| 943 | "mesh_set_ttl"}, |
| 944 | { |
| 945 | WLAN_SETNONE_GETONEINT, |
| 946 | IW_PRIV_TYPE_NONE, |
| 947 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 948 | ""}, |
| 949 | { |
| 950 | WLANGETREGION, |
| 951 | IW_PRIV_TYPE_NONE, |
| 952 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 953 | "getregioncode"}, |
| 954 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 955 | WLAN_SUBCMD_FWT_CLEANUP, |
| 956 | IW_PRIV_TYPE_NONE, |
| 957 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 958 | "fwt_cleanup"}, |
| 959 | { |
| 960 | WLAN_SUBCMD_FWT_TIME, |
| 961 | IW_PRIV_TYPE_NONE, |
| 962 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 963 | "fwt_time"}, |
| 964 | { |
| 965 | WLAN_SUBCMD_MESH_GET_TTL, |
| 966 | IW_PRIV_TYPE_NONE, |
| 967 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 968 | "mesh_get_ttl"}, |
| 969 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 970 | WLAN_SETNONE_GETNONE, |
| 971 | IW_PRIV_TYPE_NONE, |
| 972 | IW_PRIV_TYPE_NONE, |
| 973 | ""}, |
| 974 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 975 | WLAN_SUBCMD_FWT_RESET, |
| 976 | IW_PRIV_TYPE_NONE, |
| 977 | IW_PRIV_TYPE_NONE, |
| 978 | "fwt_reset"}, |
| 979 | { |
| 980 | WLAN_SUBCMD_BT_RESET, |
| 981 | IW_PRIV_TYPE_NONE, |
| 982 | IW_PRIV_TYPE_NONE, |
| 983 | "bt_reset"}, |
| 984 | { |
| 985 | WLAN_SET128CHAR_GET128CHAR, |
| 986 | IW_PRIV_TYPE_CHAR | 128, |
| 987 | IW_PRIV_TYPE_CHAR | 128, |
| 988 | ""}, |
| 989 | /* BT Management */ |
| 990 | { |
| 991 | WLAN_SUBCMD_BT_ADD, |
| 992 | IW_PRIV_TYPE_CHAR | 128, |
| 993 | IW_PRIV_TYPE_CHAR | 128, |
| 994 | "bt_add"}, |
| 995 | { |
| 996 | WLAN_SUBCMD_BT_DEL, |
| 997 | IW_PRIV_TYPE_CHAR | 128, |
| 998 | IW_PRIV_TYPE_CHAR | 128, |
| 999 | "bt_del"}, |
| 1000 | { |
| 1001 | WLAN_SUBCMD_BT_LIST, |
| 1002 | IW_PRIV_TYPE_CHAR | 128, |
| 1003 | IW_PRIV_TYPE_CHAR | 128, |
| 1004 | "bt_list"}, |
Luis Carlos Cobo | 90e8eaf | 2007-05-25 13:53:26 -0400 | [diff] [blame] | 1005 | { |
| 1006 | WLAN_SUBCMD_BT_SET_INVERT, |
| 1007 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1008 | IW_PRIV_TYPE_NONE, |
| 1009 | "bt_set_invert"}, |
| 1010 | { |
| 1011 | WLAN_SUBCMD_BT_GET_INVERT, |
| 1012 | IW_PRIV_TYPE_NONE, |
| 1013 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1014 | "bt_get_invert"}, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1015 | /* FWT Management */ |
| 1016 | { |
| 1017 | WLAN_SUBCMD_FWT_ADD, |
| 1018 | IW_PRIV_TYPE_CHAR | 128, |
| 1019 | IW_PRIV_TYPE_CHAR | 128, |
| 1020 | "fwt_add"}, |
| 1021 | { |
| 1022 | WLAN_SUBCMD_FWT_DEL, |
| 1023 | IW_PRIV_TYPE_CHAR | 128, |
| 1024 | IW_PRIV_TYPE_CHAR | 128, |
| 1025 | "fwt_del"}, |
| 1026 | { |
| 1027 | WLAN_SUBCMD_FWT_LOOKUP, |
| 1028 | IW_PRIV_TYPE_CHAR | 128, |
| 1029 | IW_PRIV_TYPE_CHAR | 128, |
| 1030 | "fwt_lookup"}, |
| 1031 | { |
| 1032 | WLAN_SUBCMD_FWT_LIST_NEIGHBOR, |
| 1033 | IW_PRIV_TYPE_CHAR | 128, |
| 1034 | IW_PRIV_TYPE_CHAR | 128, |
| 1035 | "fwt_list_neigh"}, |
| 1036 | { |
| 1037 | WLAN_SUBCMD_FWT_LIST, |
| 1038 | IW_PRIV_TYPE_CHAR | 128, |
| 1039 | IW_PRIV_TYPE_CHAR | 128, |
| 1040 | "fwt_list"}, |
| 1041 | { |
| 1042 | WLAN_SUBCMD_FWT_LIST_ROUTE, |
| 1043 | IW_PRIV_TYPE_CHAR | 128, |
| 1044 | IW_PRIV_TYPE_CHAR | 128, |
| 1045 | "fwt_list_route"}, |
| 1046 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1047 | WLAN_SET_GET_SIXTEEN_INT, |
| 1048 | IW_PRIV_TYPE_INT | 16, |
| 1049 | IW_PRIV_TYPE_INT | 16, |
| 1050 | ""}, |
| 1051 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1052 | WLAN_LED_GPIO_CTRL, |
| 1053 | IW_PRIV_TYPE_INT | 16, |
| 1054 | IW_PRIV_TYPE_INT | 16, |
| 1055 | "ledgpio"}, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1056 | }; |
| 1057 | |
| 1058 | static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev) |
| 1059 | { |
| 1060 | enum { |
| 1061 | POOR = 30, |
| 1062 | FAIR = 60, |
| 1063 | GOOD = 80, |
| 1064 | VERY_GOOD = 90, |
| 1065 | EXCELLENT = 95, |
| 1066 | PERFECT = 100 |
| 1067 | }; |
| 1068 | wlan_private *priv = dev->priv; |
| 1069 | wlan_adapter *adapter = priv->adapter; |
| 1070 | u32 rssi_qual; |
| 1071 | u32 tx_qual; |
| 1072 | u32 quality = 0; |
| 1073 | int stats_valid = 0; |
| 1074 | u8 rssi; |
| 1075 | u32 tx_retries; |
| 1076 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1077 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1078 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1079 | priv->wstats.status = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1080 | |
| 1081 | /* If we're not associated, all quality values are meaningless */ |
| 1082 | if (adapter->connect_status != libertas_connected) |
| 1083 | goto out; |
| 1084 | |
| 1085 | /* Quality by RSSI */ |
| 1086 | priv->wstats.qual.level = |
| 1087 | CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG], |
| 1088 | adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 1089 | |
| 1090 | if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) { |
| 1091 | priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 1092 | } else { |
| 1093 | priv->wstats.qual.noise = |
| 1094 | CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 1095 | } |
| 1096 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1097 | lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level); |
| 1098 | lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1099 | |
| 1100 | rssi = priv->wstats.qual.level - priv->wstats.qual.noise; |
| 1101 | if (rssi < 15) |
| 1102 | rssi_qual = rssi * POOR / 10; |
| 1103 | else if (rssi < 20) |
| 1104 | rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR; |
| 1105 | else if (rssi < 30) |
| 1106 | rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR; |
| 1107 | else if (rssi < 40) |
| 1108 | rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) / |
| 1109 | 10 + GOOD; |
| 1110 | else |
| 1111 | rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) / |
| 1112 | 10 + VERY_GOOD; |
| 1113 | quality = rssi_qual; |
| 1114 | |
| 1115 | /* Quality by TX errors */ |
| 1116 | priv->wstats.discard.retries = priv->stats.tx_errors; |
| 1117 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1118 | tx_retries = le16_to_cpu(adapter->logmsg.retry); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1119 | |
| 1120 | if (tx_retries > 75) |
| 1121 | tx_qual = (90 - tx_retries) * POOR / 15; |
| 1122 | else if (tx_retries > 70) |
| 1123 | tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR; |
| 1124 | else if (tx_retries > 65) |
| 1125 | tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR; |
| 1126 | else if (tx_retries > 50) |
| 1127 | tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) / |
| 1128 | 15 + GOOD; |
| 1129 | else |
| 1130 | tx_qual = (50 - tx_retries) * |
| 1131 | (PERFECT - VERY_GOOD) / 50 + VERY_GOOD; |
| 1132 | quality = min(quality, tx_qual); |
| 1133 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1134 | priv->wstats.discard.code = le16_to_cpu(adapter->logmsg.wepundecryptable); |
| 1135 | priv->wstats.discard.fragment = le16_to_cpu(adapter->logmsg.rxfrag); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1136 | priv->wstats.discard.retries = tx_retries; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1137 | priv->wstats.discard.misc = le16_to_cpu(adapter->logmsg.ackfailure); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1138 | |
| 1139 | /* Calculate quality */ |
| 1140 | priv->wstats.qual.qual = max(quality, (u32)100); |
| 1141 | priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 1142 | stats_valid = 1; |
| 1143 | |
| 1144 | /* update stats asynchronously for future calls */ |
| 1145 | libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0, |
| 1146 | 0, 0, NULL); |
| 1147 | libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0, |
| 1148 | 0, 0, NULL); |
| 1149 | out: |
| 1150 | if (!stats_valid) { |
| 1151 | priv->wstats.miss.beacon = 0; |
| 1152 | priv->wstats.discard.retries = 0; |
| 1153 | priv->wstats.qual.qual = 0; |
| 1154 | priv->wstats.qual.level = 0; |
| 1155 | priv->wstats.qual.noise = 0; |
| 1156 | priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED; |
| 1157 | priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID | |
| 1158 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
| 1159 | } |
| 1160 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1161 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1162 | return &priv->wstats; |
| 1163 | |
| 1164 | |
| 1165 | } |
| 1166 | |
| 1167 | static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info, |
| 1168 | struct iw_freq *fwrq, char *extra) |
| 1169 | { |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1170 | int ret = -EINVAL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1171 | wlan_private *priv = dev->priv; |
| 1172 | wlan_adapter *adapter = priv->adapter; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1173 | struct chan_freq_power *cfp; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1174 | struct assoc_request * assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1175 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1176 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1177 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1178 | mutex_lock(&adapter->lock); |
| 1179 | assoc_req = wlan_get_association_request(adapter); |
| 1180 | if (!assoc_req) { |
| 1181 | ret = -ENOMEM; |
| 1182 | goto out; |
| 1183 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1184 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1185 | /* If setting by frequency, convert to a channel */ |
| 1186 | if (fwrq->e == 1) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1187 | long f = fwrq->m / 100000; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1188 | |
| 1189 | cfp = find_cfp_by_band_and_freq(adapter, 0, f); |
| 1190 | if (!cfp) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1191 | lbs_deb_wext("invalid freq %ld\n", f); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1192 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1193 | } |
| 1194 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1195 | fwrq->e = 0; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1196 | fwrq->m = (int) cfp->channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1197 | } |
| 1198 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1199 | /* Setting by channel number */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1200 | if (fwrq->m > 1000 || fwrq->e > 0) { |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1201 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1202 | } |
| 1203 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1204 | cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m); |
| 1205 | if (!cfp) { |
| 1206 | goto out; |
| 1207 | } |
| 1208 | |
| 1209 | assoc_req->channel = fwrq->m; |
| 1210 | ret = 0; |
| 1211 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1212 | out: |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1213 | if (ret == 0) { |
| 1214 | set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags); |
| 1215 | wlan_postpone_association_work(priv); |
| 1216 | } else { |
| 1217 | wlan_cancel_association_work(priv); |
| 1218 | } |
| 1219 | mutex_unlock(&adapter->lock); |
| 1220 | |
| 1221 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 1222 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * @brief use index to get the data rate |
| 1227 | * |
| 1228 | * @param index The index of data rate |
| 1229 | * @return data rate or 0 |
| 1230 | */ |
| 1231 | u32 libertas_index_to_data_rate(u8 index) |
| 1232 | { |
| 1233 | if (index >= sizeof(libertas_wlan_data_rates)) |
| 1234 | index = 0; |
| 1235 | |
| 1236 | return libertas_wlan_data_rates[index]; |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * @brief use rate to get the index |
| 1241 | * |
| 1242 | * @param rate data rate |
| 1243 | * @return index or 0 |
| 1244 | */ |
| 1245 | u8 libertas_data_rate_to_index(u32 rate) |
| 1246 | { |
| 1247 | u8 *ptr; |
| 1248 | |
| 1249 | if (rate) |
| 1250 | if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate, |
| 1251 | sizeof(libertas_wlan_data_rates)))) |
| 1252 | return (ptr - libertas_wlan_data_rates); |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info, |
| 1258 | struct iw_param *vwrq, char *extra) |
| 1259 | { |
| 1260 | wlan_private *priv = dev->priv; |
| 1261 | wlan_adapter *adapter = priv->adapter; |
| 1262 | u32 data_rate; |
| 1263 | u16 action; |
| 1264 | int ret = 0; |
| 1265 | u8 rates[WLAN_SUPPORTED_RATES]; |
| 1266 | u8 *rate; |
| 1267 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1268 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1269 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1270 | lbs_deb_wext("vwrq->value %d\n", vwrq->value); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1271 | |
| 1272 | if (vwrq->value == -1) { |
| 1273 | action = cmd_act_set_tx_auto; // Auto |
| 1274 | adapter->is_datarate_auto = 1; |
| 1275 | adapter->datarate = 0; |
| 1276 | } else { |
| 1277 | if (vwrq->value % 100000) { |
| 1278 | return -EINVAL; |
| 1279 | } |
| 1280 | |
| 1281 | data_rate = vwrq->value / 500000; |
| 1282 | |
| 1283 | memset(rates, 0, sizeof(rates)); |
| 1284 | get_active_data_rates(adapter, rates); |
| 1285 | rate = rates; |
| 1286 | while (*rate) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1287 | lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1288 | data_rate); |
| 1289 | if ((*rate & 0x7f) == (data_rate & 0x7f)) |
| 1290 | break; |
| 1291 | rate++; |
| 1292 | } |
| 1293 | if (!*rate) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1294 | lbs_pr_alert("fixed data rate 0x%X out " |
| 1295 | "of range\n", data_rate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1296 | return -EINVAL; |
| 1297 | } |
| 1298 | |
| 1299 | adapter->datarate = data_rate; |
| 1300 | action = cmd_act_set_tx_fix_rate; |
| 1301 | adapter->is_datarate_auto = 0; |
| 1302 | } |
| 1303 | |
| 1304 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate, |
| 1305 | action, cmd_option_waitforrsp, 0, NULL); |
| 1306 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1307 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1308 | return ret; |
| 1309 | } |
| 1310 | |
| 1311 | static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info, |
| 1312 | struct iw_param *vwrq, char *extra) |
| 1313 | { |
| 1314 | wlan_private *priv = dev->priv; |
| 1315 | wlan_adapter *adapter = priv->adapter; |
| 1316 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1317 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1318 | |
| 1319 | if (adapter->is_datarate_auto) { |
| 1320 | vwrq->fixed = 0; |
| 1321 | } else { |
| 1322 | vwrq->fixed = 1; |
| 1323 | } |
| 1324 | |
| 1325 | vwrq->value = adapter->datarate * 500000; |
| 1326 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1327 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static int wlan_set_mode(struct net_device *dev, |
| 1332 | struct iw_request_info *info, u32 * uwrq, char *extra) |
| 1333 | { |
| 1334 | int ret = 0; |
| 1335 | wlan_private *priv = dev->priv; |
| 1336 | wlan_adapter *adapter = priv->adapter; |
| 1337 | struct assoc_request * assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1338 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1339 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1340 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1341 | if ( (*uwrq != IW_MODE_ADHOC) |
| 1342 | && (*uwrq != IW_MODE_INFRA) |
| 1343 | && (*uwrq != IW_MODE_AUTO)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1344 | lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1345 | ret = -EINVAL; |
| 1346 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | mutex_lock(&adapter->lock); |
| 1350 | assoc_req = wlan_get_association_request(adapter); |
| 1351 | if (!assoc_req) { |
| 1352 | ret = -ENOMEM; |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1353 | wlan_cancel_association_work(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1354 | } else { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1355 | assoc_req->mode = *uwrq; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1356 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 1357 | wlan_postpone_association_work(priv); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1358 | lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1359 | } |
| 1360 | mutex_unlock(&adapter->lock); |
| 1361 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1362 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1363 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1364 | return ret; |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | /** |
| 1369 | * @brief Get Encryption key |
| 1370 | * |
| 1371 | * @param dev A pointer to net_device structure |
| 1372 | * @param info A pointer to iw_request_info structure |
| 1373 | * @param vwrq A pointer to iw_param structure |
| 1374 | * @param extra A pointer to extra data buf |
| 1375 | * @return 0 --success, otherwise fail |
| 1376 | */ |
| 1377 | static int wlan_get_encode(struct net_device *dev, |
| 1378 | struct iw_request_info *info, |
| 1379 | struct iw_point *dwrq, u8 * extra) |
| 1380 | { |
| 1381 | wlan_private *priv = dev->priv; |
| 1382 | wlan_adapter *adapter = priv->adapter; |
| 1383 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 1384 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1385 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1386 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1387 | lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1388 | dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx); |
| 1389 | |
| 1390 | dwrq->flags = 0; |
| 1391 | |
| 1392 | /* Authentication method */ |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1393 | switch (adapter->secinfo.auth_mode) { |
| 1394 | case IW_AUTH_ALG_OPEN_SYSTEM: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1395 | dwrq->flags = IW_ENCODE_OPEN; |
| 1396 | break; |
| 1397 | |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1398 | case IW_AUTH_ALG_SHARED_KEY: |
| 1399 | case IW_AUTH_ALG_LEAP: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1400 | dwrq->flags = IW_ENCODE_RESTRICTED; |
| 1401 | break; |
| 1402 | default: |
| 1403 | dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN; |
| 1404 | break; |
| 1405 | } |
| 1406 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1407 | if ( adapter->secinfo.wep_enabled |
| 1408 | || adapter->secinfo.WPAenabled |
| 1409 | || adapter->secinfo.WPA2enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1410 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
| 1411 | } else { |
| 1412 | dwrq->flags |= IW_ENCODE_DISABLED; |
| 1413 | } |
| 1414 | |
| 1415 | memset(extra, 0, 16); |
| 1416 | |
| 1417 | mutex_lock(&adapter->lock); |
| 1418 | |
| 1419 | /* Default to returning current transmit key */ |
| 1420 | if (index < 0) |
| 1421 | index = adapter->wep_tx_keyidx; |
| 1422 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1423 | if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1424 | memcpy(extra, adapter->wep_keys[index].key, |
| 1425 | adapter->wep_keys[index].len); |
| 1426 | dwrq->length = adapter->wep_keys[index].len; |
| 1427 | |
| 1428 | dwrq->flags |= (index + 1); |
| 1429 | /* Return WEP enabled */ |
| 1430 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
| 1431 | } else if ((adapter->secinfo.WPAenabled) |
| 1432 | || (adapter->secinfo.WPA2enabled)) { |
| 1433 | /* return WPA enabled */ |
| 1434 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
| 1435 | } else { |
| 1436 | dwrq->flags |= IW_ENCODE_DISABLED; |
| 1437 | } |
| 1438 | |
| 1439 | mutex_unlock(&adapter->lock); |
| 1440 | |
| 1441 | dwrq->flags |= IW_ENCODE_NOKEY; |
| 1442 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1443 | lbs_deb_wext("key: " MAC_FMT ", keylen %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1444 | extra[0], extra[1], extra[2], |
| 1445 | extra[3], extra[4], extra[5], dwrq->length); |
| 1446 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1447 | lbs_deb_wext("return flags 0x%x\n", dwrq->flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1448 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1449 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * @brief Set Encryption key (internal) |
| 1455 | * |
| 1456 | * @param priv A pointer to private card structure |
| 1457 | * @param key_material A pointer to key material |
| 1458 | * @param key_length length of key material |
| 1459 | * @param index key index to set |
| 1460 | * @param set_tx_key Force set TX key (1 = yes, 0 = no) |
| 1461 | * @return 0 --success, otherwise fail |
| 1462 | */ |
| 1463 | static int wlan_set_wep_key(struct assoc_request *assoc_req, |
| 1464 | const char *key_material, |
| 1465 | u16 key_length, |
| 1466 | u16 index, |
| 1467 | int set_tx_key) |
| 1468 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1469 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1470 | struct WLAN_802_11_KEY *pkey; |
| 1471 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1472 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1473 | |
| 1474 | /* Paranoid validation of key index */ |
| 1475 | if (index > 3) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1476 | ret = -EINVAL; |
| 1477 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | /* validate max key length */ |
| 1481 | if (key_length > KEY_LEN_WEP_104) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1482 | ret = -EINVAL; |
| 1483 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | pkey = &assoc_req->wep_keys[index]; |
| 1487 | |
| 1488 | if (key_length > 0) { |
| 1489 | memset(pkey, 0, sizeof(struct WLAN_802_11_KEY)); |
| 1490 | pkey->type = KEY_TYPE_ID_WEP; |
| 1491 | |
| 1492 | /* Standardize the key length */ |
| 1493 | pkey->len = (key_length > KEY_LEN_WEP_40) ? |
| 1494 | KEY_LEN_WEP_104 : KEY_LEN_WEP_40; |
| 1495 | memcpy(pkey->key, key_material, key_length); |
| 1496 | } |
| 1497 | |
| 1498 | if (set_tx_key) { |
| 1499 | /* Ensure the chosen key is valid */ |
| 1500 | if (!pkey->len) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1501 | lbs_deb_wext("key not set, so cannot enable it\n"); |
| 1502 | ret = -EINVAL; |
| 1503 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1504 | } |
| 1505 | assoc_req->wep_tx_keyidx = index; |
| 1506 | } |
| 1507 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1508 | assoc_req->secinfo.wep_enabled = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1509 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1510 | out: |
| 1511 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 1512 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | static int validate_key_index(u16 def_index, u16 raw_index, |
| 1516 | u16 *out_index, u16 *is_default) |
| 1517 | { |
| 1518 | if (!out_index || !is_default) |
| 1519 | return -EINVAL; |
| 1520 | |
| 1521 | /* Verify index if present, otherwise use default TX key index */ |
| 1522 | if (raw_index > 0) { |
| 1523 | if (raw_index > 4) |
| 1524 | return -EINVAL; |
| 1525 | *out_index = raw_index - 1; |
| 1526 | } else { |
| 1527 | *out_index = def_index; |
| 1528 | *is_default = 1; |
| 1529 | } |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static void disable_wep(struct assoc_request *assoc_req) |
| 1534 | { |
| 1535 | int i; |
| 1536 | |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1537 | lbs_deb_enter(LBS_DEB_WEXT); |
| 1538 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1539 | /* Set Open System auth mode */ |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1540 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1541 | |
| 1542 | /* Clear WEP keys and mark WEP as disabled */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1543 | assoc_req->secinfo.wep_enabled = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1544 | for (i = 0; i < 4; i++) |
| 1545 | assoc_req->wep_keys[i].len = 0; |
| 1546 | |
| 1547 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1548 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1549 | |
| 1550 | lbs_deb_leave(LBS_DEB_WEXT); |
| 1551 | } |
| 1552 | |
| 1553 | static void disable_wpa(struct assoc_request *assoc_req) |
| 1554 | { |
| 1555 | lbs_deb_enter(LBS_DEB_WEXT); |
| 1556 | |
| 1557 | memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct WLAN_802_11_KEY)); |
| 1558 | assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST; |
| 1559 | set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
| 1560 | |
| 1561 | memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct WLAN_802_11_KEY)); |
| 1562 | assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST; |
| 1563 | set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 1564 | |
| 1565 | assoc_req->secinfo.WPAenabled = 0; |
| 1566 | assoc_req->secinfo.WPA2enabled = 0; |
| 1567 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1568 | |
| 1569 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * @brief Set Encryption key |
| 1574 | * |
| 1575 | * @param dev A pointer to net_device structure |
| 1576 | * @param info A pointer to iw_request_info structure |
| 1577 | * @param vwrq A pointer to iw_param structure |
| 1578 | * @param extra A pointer to extra data buf |
| 1579 | * @return 0 --success, otherwise fail |
| 1580 | */ |
| 1581 | static int wlan_set_encode(struct net_device *dev, |
| 1582 | struct iw_request_info *info, |
| 1583 | struct iw_point *dwrq, char *extra) |
| 1584 | { |
| 1585 | int ret = 0; |
| 1586 | wlan_private *priv = dev->priv; |
| 1587 | wlan_adapter *adapter = priv->adapter; |
| 1588 | struct assoc_request * assoc_req; |
| 1589 | u16 is_default = 0, index = 0, set_tx_key = 0; |
| 1590 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1591 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1592 | |
| 1593 | mutex_lock(&adapter->lock); |
| 1594 | assoc_req = wlan_get_association_request(adapter); |
| 1595 | if (!assoc_req) { |
| 1596 | ret = -ENOMEM; |
| 1597 | goto out; |
| 1598 | } |
| 1599 | |
| 1600 | if (dwrq->flags & IW_ENCODE_DISABLED) { |
| 1601 | disable_wep (assoc_req); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1602 | disable_wpa (assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1603 | goto out; |
| 1604 | } |
| 1605 | |
| 1606 | ret = validate_key_index(assoc_req->wep_tx_keyidx, |
| 1607 | (dwrq->flags & IW_ENCODE_INDEX), |
| 1608 | &index, &is_default); |
| 1609 | if (ret) { |
| 1610 | ret = -EINVAL; |
| 1611 | goto out; |
| 1612 | } |
| 1613 | |
| 1614 | /* If WEP isn't enabled, or if there is no key data but a valid |
| 1615 | * index, set the TX key. |
| 1616 | */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1617 | if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1618 | set_tx_key = 1; |
| 1619 | |
| 1620 | ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key); |
| 1621 | if (ret) |
| 1622 | goto out; |
| 1623 | |
| 1624 | if (dwrq->length) |
| 1625 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 1626 | if (set_tx_key) |
| 1627 | set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags); |
| 1628 | |
| 1629 | if (dwrq->flags & IW_ENCODE_RESTRICTED) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1630 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1631 | } else if (dwrq->flags & IW_ENCODE_OPEN) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1632 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | out: |
| 1636 | if (ret == 0) { |
| 1637 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1638 | wlan_postpone_association_work(priv); |
| 1639 | } else { |
| 1640 | wlan_cancel_association_work(priv); |
| 1641 | } |
| 1642 | mutex_unlock(&adapter->lock); |
| 1643 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1644 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1645 | return ret; |
| 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * @brief Get Extended Encryption key (WPA/802.1x and WEP) |
| 1650 | * |
| 1651 | * @param dev A pointer to net_device structure |
| 1652 | * @param info A pointer to iw_request_info structure |
| 1653 | * @param vwrq A pointer to iw_param structure |
| 1654 | * @param extra A pointer to extra data buf |
| 1655 | * @return 0 on success, otherwise failure |
| 1656 | */ |
| 1657 | static int wlan_get_encodeext(struct net_device *dev, |
| 1658 | struct iw_request_info *info, |
| 1659 | struct iw_point *dwrq, |
| 1660 | char *extra) |
| 1661 | { |
| 1662 | int ret = -EINVAL; |
| 1663 | wlan_private *priv = dev->priv; |
| 1664 | wlan_adapter *adapter = priv->adapter; |
| 1665 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 1666 | int index, max_key_len; |
| 1667 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1668 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1669 | |
| 1670 | max_key_len = dwrq->length - sizeof(*ext); |
| 1671 | if (max_key_len < 0) |
| 1672 | goto out; |
| 1673 | |
| 1674 | index = dwrq->flags & IW_ENCODE_INDEX; |
| 1675 | if (index) { |
| 1676 | if (index < 1 || index > 4) |
| 1677 | goto out; |
| 1678 | index--; |
| 1679 | } else { |
| 1680 | index = adapter->wep_tx_keyidx; |
| 1681 | } |
| 1682 | |
| 1683 | if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY && |
| 1684 | ext->alg != IW_ENCODE_ALG_WEP) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1685 | if (index != 0 || adapter->mode != IW_MODE_INFRA) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1686 | goto out; |
| 1687 | } |
| 1688 | |
| 1689 | dwrq->flags = index + 1; |
| 1690 | memset(ext, 0, sizeof(*ext)); |
| 1691 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1692 | if ( !adapter->secinfo.wep_enabled |
| 1693 | && !adapter->secinfo.WPAenabled |
| 1694 | && !adapter->secinfo.WPA2enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1695 | ext->alg = IW_ENCODE_ALG_NONE; |
| 1696 | ext->key_len = 0; |
| 1697 | dwrq->flags |= IW_ENCODE_DISABLED; |
| 1698 | } else { |
| 1699 | u8 *key = NULL; |
| 1700 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1701 | if ( adapter->secinfo.wep_enabled |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1702 | && !adapter->secinfo.WPAenabled |
| 1703 | && !adapter->secinfo.WPA2enabled) { |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1704 | /* WEP */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1705 | ext->alg = IW_ENCODE_ALG_WEP; |
| 1706 | ext->key_len = adapter->wep_keys[index].len; |
| 1707 | key = &adapter->wep_keys[index].key[0]; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1708 | } else if ( !adapter->secinfo.wep_enabled |
| 1709 | && (adapter->secinfo.WPAenabled || |
| 1710 | adapter->secinfo.WPA2enabled)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1711 | /* WPA */ |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1712 | struct WLAN_802_11_KEY * pkey = NULL; |
| 1713 | |
| 1714 | if ( adapter->wpa_mcast_key.len |
| 1715 | && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED)) |
| 1716 | pkey = &adapter->wpa_mcast_key; |
| 1717 | else if ( adapter->wpa_unicast_key.len |
| 1718 | && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED)) |
| 1719 | pkey = &adapter->wpa_unicast_key; |
| 1720 | |
| 1721 | if (pkey) { |
| 1722 | if (pkey->type == KEY_TYPE_ID_AES) { |
| 1723 | ext->alg = IW_ENCODE_ALG_CCMP; |
| 1724 | } else { |
| 1725 | ext->alg = IW_ENCODE_ALG_TKIP; |
| 1726 | } |
| 1727 | ext->key_len = pkey->len; |
| 1728 | key = &pkey->key[0]; |
| 1729 | } else { |
| 1730 | ext->alg = IW_ENCODE_ALG_TKIP; |
| 1731 | ext->key_len = 0; |
| 1732 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1733 | } else { |
| 1734 | goto out; |
| 1735 | } |
| 1736 | |
| 1737 | if (ext->key_len > max_key_len) { |
| 1738 | ret = -E2BIG; |
| 1739 | goto out; |
| 1740 | } |
| 1741 | |
| 1742 | if (ext->key_len) |
| 1743 | memcpy(ext->key, key, ext->key_len); |
| 1744 | else |
| 1745 | dwrq->flags |= IW_ENCODE_NOKEY; |
| 1746 | dwrq->flags |= IW_ENCODE_ENABLED; |
| 1747 | } |
| 1748 | ret = 0; |
| 1749 | |
| 1750 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1751 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1752 | return ret; |
| 1753 | } |
| 1754 | |
| 1755 | /** |
| 1756 | * @brief Set Encryption key Extended (WPA/802.1x and WEP) |
| 1757 | * |
| 1758 | * @param dev A pointer to net_device structure |
| 1759 | * @param info A pointer to iw_request_info structure |
| 1760 | * @param vwrq A pointer to iw_param structure |
| 1761 | * @param extra A pointer to extra data buf |
| 1762 | * @return 0 --success, otherwise fail |
| 1763 | */ |
| 1764 | static int wlan_set_encodeext(struct net_device *dev, |
| 1765 | struct iw_request_info *info, |
| 1766 | struct iw_point *dwrq, |
| 1767 | char *extra) |
| 1768 | { |
| 1769 | int ret = 0; |
| 1770 | wlan_private *priv = dev->priv; |
| 1771 | wlan_adapter *adapter = priv->adapter; |
| 1772 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 1773 | int alg = ext->alg; |
| 1774 | struct assoc_request * assoc_req; |
| 1775 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1776 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1777 | |
| 1778 | mutex_lock(&adapter->lock); |
| 1779 | assoc_req = wlan_get_association_request(adapter); |
| 1780 | if (!assoc_req) { |
| 1781 | ret = -ENOMEM; |
| 1782 | goto out; |
| 1783 | } |
| 1784 | |
| 1785 | if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) { |
| 1786 | disable_wep (assoc_req); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1787 | disable_wpa (assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1788 | } else if (alg == IW_ENCODE_ALG_WEP) { |
| 1789 | u16 is_default = 0, index, set_tx_key = 0; |
| 1790 | |
| 1791 | ret = validate_key_index(assoc_req->wep_tx_keyidx, |
| 1792 | (dwrq->flags & IW_ENCODE_INDEX), |
| 1793 | &index, &is_default); |
| 1794 | if (ret) |
| 1795 | goto out; |
| 1796 | |
| 1797 | /* If WEP isn't enabled, or if there is no key data but a valid |
| 1798 | * index, or if the set-TX-key flag was passed, set the TX key. |
| 1799 | */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1800 | if ( !assoc_req->secinfo.wep_enabled |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1801 | || (dwrq->length == 0 && !is_default) |
| 1802 | || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) |
| 1803 | set_tx_key = 1; |
| 1804 | |
| 1805 | /* Copy key to driver */ |
| 1806 | ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index, |
| 1807 | set_tx_key); |
| 1808 | if (ret) |
| 1809 | goto out; |
| 1810 | |
| 1811 | if (dwrq->flags & IW_ENCODE_RESTRICTED) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1812 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1813 | } else if (dwrq->flags & IW_ENCODE_OPEN) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1814 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /* Mark the various WEP bits as modified */ |
| 1818 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1819 | if (dwrq->length) |
| 1820 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 1821 | if (set_tx_key) |
| 1822 | set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1823 | } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) { |
| 1824 | struct WLAN_802_11_KEY * pkey; |
| 1825 | |
| 1826 | /* validate key length */ |
| 1827 | if (((alg == IW_ENCODE_ALG_TKIP) |
| 1828 | && (ext->key_len != KEY_LEN_WPA_TKIP)) |
| 1829 | || ((alg == IW_ENCODE_ALG_CCMP) |
| 1830 | && (ext->key_len != KEY_LEN_WPA_AES))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1831 | lbs_deb_wext("invalid size %d for key of alg" |
| 1832 | "type %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1833 | ext->key_len, |
| 1834 | alg); |
| 1835 | ret = -EINVAL; |
| 1836 | goto out; |
| 1837 | } |
| 1838 | |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1839 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1840 | pkey = &assoc_req->wpa_mcast_key; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1841 | set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
| 1842 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1843 | pkey = &assoc_req->wpa_unicast_key; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1844 | set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 1845 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1846 | |
| 1847 | memset(pkey, 0, sizeof (struct WLAN_802_11_KEY)); |
| 1848 | memcpy(pkey->key, ext->key, ext->key_len); |
| 1849 | pkey->len = ext->key_len; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1850 | if (pkey->len) |
| 1851 | pkey->flags |= KEY_INFO_WPA_ENABLED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1852 | |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1853 | /* Do this after zeroing key structure */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1854 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { |
| 1855 | pkey->flags |= KEY_INFO_WPA_MCAST; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1856 | } else { |
| 1857 | pkey->flags |= KEY_INFO_WPA_UNICAST; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1858 | } |
| 1859 | |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1860 | if (alg == IW_ENCODE_ALG_TKIP) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1861 | pkey->type = KEY_TYPE_ID_TKIP; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1862 | } else if (alg == IW_ENCODE_ALG_CCMP) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1863 | pkey->type = KEY_TYPE_ID_AES; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1864 | } else { |
| 1865 | ret = -EINVAL; |
| 1866 | goto out; |
| 1867 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1868 | |
| 1869 | /* If WPA isn't enabled yet, do that now */ |
| 1870 | if ( assoc_req->secinfo.WPAenabled == 0 |
| 1871 | && assoc_req->secinfo.WPA2enabled == 0) { |
| 1872 | assoc_req->secinfo.WPAenabled = 1; |
| 1873 | assoc_req->secinfo.WPA2enabled = 1; |
| 1874 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1875 | } |
| 1876 | |
| 1877 | disable_wep (assoc_req); |
| 1878 | } |
| 1879 | |
| 1880 | out: |
| 1881 | if (ret == 0) { |
| 1882 | wlan_postpone_association_work(priv); |
| 1883 | } else { |
| 1884 | wlan_cancel_association_work(priv); |
| 1885 | } |
| 1886 | mutex_unlock(&adapter->lock); |
| 1887 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1888 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1889 | return ret; |
| 1890 | } |
| 1891 | |
| 1892 | |
| 1893 | static int wlan_set_genie(struct net_device *dev, |
| 1894 | struct iw_request_info *info, |
| 1895 | struct iw_point *dwrq, |
| 1896 | char *extra) |
| 1897 | { |
| 1898 | wlan_private *priv = dev->priv; |
| 1899 | wlan_adapter *adapter = priv->adapter; |
| 1900 | int ret = 0; |
| 1901 | struct assoc_request * assoc_req; |
| 1902 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1903 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1904 | |
| 1905 | mutex_lock(&adapter->lock); |
| 1906 | assoc_req = wlan_get_association_request(adapter); |
| 1907 | if (!assoc_req) { |
| 1908 | ret = -ENOMEM; |
| 1909 | goto out; |
| 1910 | } |
| 1911 | |
| 1912 | if (dwrq->length > MAX_WPA_IE_LEN || |
| 1913 | (dwrq->length && extra == NULL)) { |
| 1914 | ret = -EINVAL; |
| 1915 | goto out; |
| 1916 | } |
| 1917 | |
| 1918 | if (dwrq->length) { |
| 1919 | memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length); |
| 1920 | assoc_req->wpa_ie_len = dwrq->length; |
| 1921 | } else { |
| 1922 | memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie)); |
| 1923 | assoc_req->wpa_ie_len = 0; |
| 1924 | } |
| 1925 | |
| 1926 | out: |
| 1927 | if (ret == 0) { |
| 1928 | set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags); |
| 1929 | wlan_postpone_association_work(priv); |
| 1930 | } else { |
| 1931 | wlan_cancel_association_work(priv); |
| 1932 | } |
| 1933 | mutex_unlock(&adapter->lock); |
| 1934 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1935 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1936 | return ret; |
| 1937 | } |
| 1938 | |
| 1939 | static int wlan_get_genie(struct net_device *dev, |
| 1940 | struct iw_request_info *info, |
| 1941 | struct iw_point *dwrq, |
| 1942 | char *extra) |
| 1943 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1944 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1945 | wlan_private *priv = dev->priv; |
| 1946 | wlan_adapter *adapter = priv->adapter; |
| 1947 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1948 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1949 | |
| 1950 | if (adapter->wpa_ie_len == 0) { |
| 1951 | dwrq->length = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1952 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | if (dwrq->length < adapter->wpa_ie_len) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1956 | ret = -E2BIG; |
| 1957 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | dwrq->length = adapter->wpa_ie_len; |
| 1961 | memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len); |
| 1962 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1963 | out: |
| 1964 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 1965 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | |
| 1969 | static int wlan_set_auth(struct net_device *dev, |
| 1970 | struct iw_request_info *info, |
| 1971 | struct iw_param *dwrq, |
| 1972 | char *extra) |
| 1973 | { |
| 1974 | wlan_private *priv = dev->priv; |
| 1975 | wlan_adapter *adapter = priv->adapter; |
| 1976 | struct assoc_request * assoc_req; |
| 1977 | int ret = 0; |
| 1978 | int updated = 0; |
| 1979 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1980 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1981 | |
| 1982 | mutex_lock(&adapter->lock); |
| 1983 | assoc_req = wlan_get_association_request(adapter); |
| 1984 | if (!assoc_req) { |
| 1985 | ret = -ENOMEM; |
| 1986 | goto out; |
| 1987 | } |
| 1988 | |
| 1989 | switch (dwrq->flags & IW_AUTH_INDEX) { |
| 1990 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 1991 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1992 | case IW_AUTH_CIPHER_GROUP: |
| 1993 | case IW_AUTH_KEY_MGMT: |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1994 | case IW_AUTH_DROP_UNENCRYPTED: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1995 | /* |
| 1996 | * libertas does not use these parameters |
| 1997 | */ |
| 1998 | break; |
| 1999 | |
| 2000 | case IW_AUTH_WPA_VERSION: |
| 2001 | if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) { |
| 2002 | assoc_req->secinfo.WPAenabled = 0; |
| 2003 | assoc_req->secinfo.WPA2enabled = 0; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 2004 | disable_wpa (assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2005 | } |
| 2006 | if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) { |
| 2007 | assoc_req->secinfo.WPAenabled = 1; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2008 | assoc_req->secinfo.wep_enabled = 0; |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2009 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2010 | } |
| 2011 | if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) { |
| 2012 | assoc_req->secinfo.WPA2enabled = 1; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2013 | assoc_req->secinfo.wep_enabled = 0; |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2014 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2015 | } |
| 2016 | updated = 1; |
| 2017 | break; |
| 2018 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2019 | case IW_AUTH_80211_AUTH_ALG: |
| 2020 | if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2021 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2022 | } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2023 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2024 | } else if (dwrq->value & IW_AUTH_ALG_LEAP) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2025 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2026 | } else { |
| 2027 | ret = -EINVAL; |
| 2028 | } |
| 2029 | updated = 1; |
| 2030 | break; |
| 2031 | |
| 2032 | case IW_AUTH_WPA_ENABLED: |
| 2033 | if (dwrq->value) { |
| 2034 | if (!assoc_req->secinfo.WPAenabled && |
| 2035 | !assoc_req->secinfo.WPA2enabled) { |
| 2036 | assoc_req->secinfo.WPAenabled = 1; |
| 2037 | assoc_req->secinfo.WPA2enabled = 1; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2038 | assoc_req->secinfo.wep_enabled = 0; |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2039 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2040 | } |
| 2041 | } else { |
| 2042 | assoc_req->secinfo.WPAenabled = 0; |
| 2043 | assoc_req->secinfo.WPA2enabled = 0; |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 2044 | disable_wpa (assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2045 | } |
| 2046 | updated = 1; |
| 2047 | break; |
| 2048 | |
| 2049 | default: |
| 2050 | ret = -EOPNOTSUPP; |
| 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | out: |
| 2055 | if (ret == 0) { |
| 2056 | if (updated) |
| 2057 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 2058 | wlan_postpone_association_work(priv); |
| 2059 | } else if (ret != -EOPNOTSUPP) { |
| 2060 | wlan_cancel_association_work(priv); |
| 2061 | } |
| 2062 | mutex_unlock(&adapter->lock); |
| 2063 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2064 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2065 | return ret; |
| 2066 | } |
| 2067 | |
| 2068 | static int wlan_get_auth(struct net_device *dev, |
| 2069 | struct iw_request_info *info, |
| 2070 | struct iw_param *dwrq, |
| 2071 | char *extra) |
| 2072 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2073 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2074 | wlan_private *priv = dev->priv; |
| 2075 | wlan_adapter *adapter = priv->adapter; |
| 2076 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2077 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2078 | |
| 2079 | switch (dwrq->flags & IW_AUTH_INDEX) { |
| 2080 | case IW_AUTH_WPA_VERSION: |
| 2081 | dwrq->value = 0; |
| 2082 | if (adapter->secinfo.WPAenabled) |
| 2083 | dwrq->value |= IW_AUTH_WPA_VERSION_WPA; |
| 2084 | if (adapter->secinfo.WPA2enabled) |
| 2085 | dwrq->value |= IW_AUTH_WPA_VERSION_WPA2; |
| 2086 | if (!dwrq->value) |
| 2087 | dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED; |
| 2088 | break; |
| 2089 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2090 | case IW_AUTH_80211_AUTH_ALG: |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2091 | dwrq->value = adapter->secinfo.auth_mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2092 | break; |
| 2093 | |
| 2094 | case IW_AUTH_WPA_ENABLED: |
| 2095 | if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled) |
| 2096 | dwrq->value = 1; |
| 2097 | break; |
| 2098 | |
| 2099 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2100 | ret = -EOPNOTSUPP; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2101 | } |
| 2102 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2103 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 2104 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | |
| 2108 | static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info, |
| 2109 | struct iw_param *vwrq, char *extra) |
| 2110 | { |
| 2111 | int ret = 0; |
| 2112 | wlan_private *priv = dev->priv; |
| 2113 | wlan_adapter *adapter = priv->adapter; |
| 2114 | |
| 2115 | u16 dbm; |
| 2116 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2117 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2118 | |
| 2119 | if (vwrq->disabled) { |
| 2120 | wlan_radio_ioctl(priv, RADIO_OFF); |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
| 2124 | adapter->preamble = cmd_type_auto_preamble; |
| 2125 | |
| 2126 | wlan_radio_ioctl(priv, RADIO_ON); |
| 2127 | |
| 2128 | if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) { |
| 2129 | dbm = (u16) mw_to_dbm(vwrq->value); |
| 2130 | } else |
| 2131 | dbm = (u16) vwrq->value; |
| 2132 | |
| 2133 | /* auto tx power control */ |
| 2134 | |
| 2135 | if (vwrq->fixed == 0) |
| 2136 | dbm = 0xffff; |
| 2137 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2138 | lbs_deb_wext("txpower set %d dbm\n", dbm); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2139 | |
| 2140 | ret = libertas_prepare_and_send_command(priv, |
| 2141 | cmd_802_11_rf_tx_power, |
| 2142 | cmd_act_tx_power_opt_set_low, |
| 2143 | cmd_option_waitforrsp, 0, (void *)&dbm); |
| 2144 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2145 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2146 | return ret; |
| 2147 | } |
| 2148 | |
| 2149 | static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info, |
| 2150 | struct iw_point *dwrq, char *extra) |
| 2151 | { |
| 2152 | wlan_private *priv = dev->priv; |
| 2153 | wlan_adapter *adapter = priv->adapter; |
| 2154 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2155 | lbs_deb_enter(LBS_DEB_WEXT); |
| 2156 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2157 | /* |
| 2158 | * Note : if dwrq->flags != 0, we should get the relevant SSID from |
| 2159 | * the SSID list... |
| 2160 | */ |
| 2161 | |
| 2162 | /* |
| 2163 | * Get the current SSID |
| 2164 | */ |
| 2165 | if (adapter->connect_status == libertas_connected) { |
| 2166 | memcpy(extra, adapter->curbssparams.ssid.ssid, |
| 2167 | adapter->curbssparams.ssid.ssidlength); |
| 2168 | extra[adapter->curbssparams.ssid.ssidlength] = '\0'; |
| 2169 | } else { |
| 2170 | memset(extra, 0, 32); |
| 2171 | extra[adapter->curbssparams.ssid.ssidlength] = '\0'; |
| 2172 | } |
| 2173 | /* |
| 2174 | * If none, we may want to get the one that was set |
| 2175 | */ |
| 2176 | |
| 2177 | /* To make the driver backward compatible with WPA supplicant v0.2.4 */ |
| 2178 | if (dwrq->length == 32) /* check with WPA supplicant buffer size */ |
| 2179 | dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength, |
| 2180 | IW_ESSID_MAX_SIZE); |
| 2181 | else |
| 2182 | dwrq->length = adapter->curbssparams.ssid.ssidlength + 1; |
| 2183 | |
| 2184 | dwrq->flags = 1; /* active */ |
| 2185 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2186 | lbs_deb_leave(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2187 | return 0; |
| 2188 | } |
| 2189 | |
| 2190 | static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info, |
| 2191 | struct iw_point *dwrq, char *extra) |
| 2192 | { |
| 2193 | wlan_private *priv = dev->priv; |
| 2194 | wlan_adapter *adapter = priv->adapter; |
| 2195 | int ret = 0; |
| 2196 | struct WLAN_802_11_SSID ssid; |
| 2197 | struct assoc_request * assoc_req; |
| 2198 | int ssid_len = dwrq->length; |
| 2199 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2200 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2201 | |
| 2202 | /* |
| 2203 | * WE-20 and earlier NULL pad the end of the SSID and increment |
| 2204 | * SSID length so it can be used like a string. WE-21 and later don't, |
| 2205 | * but some userspace tools aren't able to cope with the change. |
| 2206 | */ |
| 2207 | if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0')) |
| 2208 | ssid_len--; |
| 2209 | |
| 2210 | /* Check the size of the string */ |
| 2211 | if (ssid_len > IW_ESSID_MAX_SIZE) { |
| 2212 | ret = -E2BIG; |
| 2213 | goto out; |
| 2214 | } |
| 2215 | |
| 2216 | memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID)); |
| 2217 | |
| 2218 | if (!dwrq->flags || !ssid_len) { |
| 2219 | /* "any" SSID requested; leave SSID blank */ |
| 2220 | } else { |
| 2221 | /* Specific SSID requested */ |
| 2222 | memcpy(&ssid.ssid, extra, ssid_len); |
| 2223 | ssid.ssidlength = ssid_len; |
| 2224 | } |
| 2225 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2226 | lbs_deb_wext("requested new SSID '%s'\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2227 | (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any"); |
| 2228 | |
| 2229 | out: |
| 2230 | mutex_lock(&adapter->lock); |
| 2231 | if (ret == 0) { |
| 2232 | /* Get or create the current association request */ |
| 2233 | assoc_req = wlan_get_association_request(adapter); |
| 2234 | if (!assoc_req) { |
| 2235 | ret = -ENOMEM; |
| 2236 | } else { |
| 2237 | /* Copy the SSID to the association request */ |
| 2238 | memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID)); |
| 2239 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
| 2240 | wlan_postpone_association_work(priv); |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | /* Cancel the association request if there was an error */ |
| 2245 | if (ret != 0) { |
| 2246 | wlan_cancel_association_work(priv); |
| 2247 | } |
| 2248 | |
| 2249 | mutex_unlock(&adapter->lock); |
| 2250 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2251 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2252 | return ret; |
| 2253 | } |
| 2254 | |
| 2255 | /** |
| 2256 | * @brief Connect to the AP or Ad-hoc Network with specific bssid |
| 2257 | * |
| 2258 | * @param dev A pointer to net_device structure |
| 2259 | * @param info A pointer to iw_request_info structure |
| 2260 | * @param awrq A pointer to iw_param structure |
| 2261 | * @param extra A pointer to extra data buf |
| 2262 | * @return 0 --success, otherwise fail |
| 2263 | */ |
| 2264 | static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info, |
| 2265 | struct sockaddr *awrq, char *extra) |
| 2266 | { |
| 2267 | wlan_private *priv = dev->priv; |
| 2268 | wlan_adapter *adapter = priv->adapter; |
| 2269 | struct assoc_request * assoc_req; |
| 2270 | int ret = 0; |
| 2271 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2272 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2273 | |
| 2274 | if (awrq->sa_family != ARPHRD_ETHER) |
| 2275 | return -EINVAL; |
| 2276 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2277 | lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2278 | |
| 2279 | mutex_lock(&adapter->lock); |
| 2280 | |
| 2281 | /* Get or create the current association request */ |
| 2282 | assoc_req = wlan_get_association_request(adapter); |
| 2283 | if (!assoc_req) { |
| 2284 | wlan_cancel_association_work(priv); |
| 2285 | ret = -ENOMEM; |
| 2286 | } else { |
| 2287 | /* Copy the BSSID to the association request */ |
| 2288 | memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN); |
| 2289 | set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags); |
| 2290 | wlan_postpone_association_work(priv); |
| 2291 | } |
| 2292 | |
| 2293 | mutex_unlock(&adapter->lock); |
| 2294 | |
| 2295 | return ret; |
| 2296 | } |
| 2297 | |
| 2298 | void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen) |
| 2299 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2300 | char fwver[32]; |
| 2301 | |
| 2302 | mutex_lock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2303 | |
David Woodhouse | e5b3d47 | 2007-05-25 23:40:21 -0400 | [diff] [blame^] | 2304 | if (adapter->fwreleasenumber[3] == 0) |
| 2305 | sprintf(fwver, "%u.%u.%u", |
| 2306 | adapter->fwreleasenumber[2], |
| 2307 | adapter->fwreleasenumber[1], |
| 2308 | adapter->fwreleasenumber[0]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2309 | else |
| 2310 | sprintf(fwver, "%u.%u.%u.p%u", |
David Woodhouse | e5b3d47 | 2007-05-25 23:40:21 -0400 | [diff] [blame^] | 2311 | adapter->fwreleasenumber[2], |
| 2312 | adapter->fwreleasenumber[1], |
| 2313 | adapter->fwreleasenumber[0], |
| 2314 | adapter->fwreleasenumber[3]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2315 | |
David Woodhouse | e5b3d47 | 2007-05-25 23:40:21 -0400 | [diff] [blame^] | 2316 | mutex_unlock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2317 | snprintf(fwversion, maxlen, fwver); |
| 2318 | } |
| 2319 | |
| 2320 | |
| 2321 | /* |
| 2322 | * iwconfig settable callbacks |
| 2323 | */ |
| 2324 | static const iw_handler wlan_handler[] = { |
| 2325 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
| 2326 | (iw_handler) wlan_get_name, /* SIOCGIWNAME */ |
| 2327 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 2328 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 2329 | (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */ |
| 2330 | (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */ |
| 2331 | (iw_handler) wlan_set_mode, /* SIOCSIWMODE */ |
| 2332 | (iw_handler) wlan_get_mode, /* SIOCGIWMODE */ |
| 2333 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 2334 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 2335 | (iw_handler) NULL, /* SIOCSIWRANGE */ |
| 2336 | (iw_handler) wlan_get_range, /* SIOCGIWRANGE */ |
| 2337 | (iw_handler) NULL, /* SIOCSIWPRIV */ |
| 2338 | (iw_handler) NULL, /* SIOCGIWPRIV */ |
| 2339 | (iw_handler) NULL, /* SIOCSIWSTATS */ |
| 2340 | (iw_handler) NULL, /* SIOCGIWSTATS */ |
| 2341 | iw_handler_set_spy, /* SIOCSIWSPY */ |
| 2342 | iw_handler_get_spy, /* SIOCGIWSPY */ |
| 2343 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ |
| 2344 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ |
| 2345 | (iw_handler) wlan_set_wap, /* SIOCSIWAP */ |
| 2346 | (iw_handler) wlan_get_wap, /* SIOCGIWAP */ |
| 2347 | (iw_handler) NULL, /* SIOCSIWMLME */ |
| 2348 | (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */ |
| 2349 | (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */ |
| 2350 | (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */ |
| 2351 | (iw_handler) wlan_set_essid, /* SIOCSIWESSID */ |
| 2352 | (iw_handler) wlan_get_essid, /* SIOCGIWESSID */ |
| 2353 | (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */ |
| 2354 | (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */ |
| 2355 | (iw_handler) NULL, /* -- hole -- */ |
| 2356 | (iw_handler) NULL, /* -- hole -- */ |
| 2357 | (iw_handler) wlan_set_rate, /* SIOCSIWRATE */ |
| 2358 | (iw_handler) wlan_get_rate, /* SIOCGIWRATE */ |
| 2359 | (iw_handler) wlan_set_rts, /* SIOCSIWRTS */ |
| 2360 | (iw_handler) wlan_get_rts, /* SIOCGIWRTS */ |
| 2361 | (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */ |
| 2362 | (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */ |
| 2363 | (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */ |
| 2364 | (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */ |
| 2365 | (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */ |
| 2366 | (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */ |
| 2367 | (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */ |
| 2368 | (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */ |
| 2369 | (iw_handler) wlan_set_power, /* SIOCSIWPOWER */ |
| 2370 | (iw_handler) wlan_get_power, /* SIOCGIWPOWER */ |
| 2371 | (iw_handler) NULL, /* -- hole -- */ |
| 2372 | (iw_handler) NULL, /* -- hole -- */ |
| 2373 | (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */ |
| 2374 | (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */ |
| 2375 | (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */ |
| 2376 | (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */ |
| 2377 | (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */ |
| 2378 | (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */ |
| 2379 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 2380 | }; |
| 2381 | |
Luis Carlos Cobo Rus | f5e05b6 | 2007-05-25 23:08:34 -0400 | [diff] [blame] | 2382 | static const iw_handler mesh_wlan_handler[] = { |
| 2383 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
| 2384 | (iw_handler) wlan_get_name, /* SIOCGIWNAME */ |
| 2385 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 2386 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 2387 | (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */ |
| 2388 | (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */ |
| 2389 | (iw_handler) NULL, /* SIOCSIWMODE */ |
| 2390 | (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */ |
| 2391 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 2392 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 2393 | (iw_handler) NULL, /* SIOCSIWRANGE */ |
| 2394 | (iw_handler) wlan_get_range, /* SIOCGIWRANGE */ |
| 2395 | (iw_handler) NULL, /* SIOCSIWPRIV */ |
| 2396 | (iw_handler) NULL, /* SIOCGIWPRIV */ |
| 2397 | (iw_handler) NULL, /* SIOCSIWSTATS */ |
| 2398 | (iw_handler) NULL, /* SIOCGIWSTATS */ |
| 2399 | iw_handler_set_spy, /* SIOCSIWSPY */ |
| 2400 | iw_handler_get_spy, /* SIOCGIWSPY */ |
| 2401 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ |
| 2402 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ |
| 2403 | (iw_handler) NULL, /* SIOCSIWAP */ |
| 2404 | (iw_handler) NULL, /* SIOCGIWAP */ |
| 2405 | (iw_handler) NULL, /* SIOCSIWMLME */ |
| 2406 | (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */ |
| 2407 | (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */ |
| 2408 | (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */ |
| 2409 | (iw_handler) NULL, /* SIOCSIWESSID */ |
| 2410 | (iw_handler) NULL, /* SIOCGIWESSID */ |
| 2411 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 2412 | (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */ |
| 2413 | (iw_handler) NULL, /* -- hole -- */ |
| 2414 | (iw_handler) NULL, /* -- hole -- */ |
| 2415 | (iw_handler) wlan_set_rate, /* SIOCSIWRATE */ |
| 2416 | (iw_handler) wlan_get_rate, /* SIOCGIWRATE */ |
| 2417 | (iw_handler) wlan_set_rts, /* SIOCSIWRTS */ |
| 2418 | (iw_handler) wlan_get_rts, /* SIOCGIWRTS */ |
| 2419 | (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */ |
| 2420 | (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */ |
| 2421 | (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */ |
| 2422 | (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */ |
| 2423 | (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */ |
| 2424 | (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */ |
| 2425 | (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */ |
| 2426 | (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */ |
| 2427 | (iw_handler) wlan_set_power, /* SIOCSIWPOWER */ |
| 2428 | (iw_handler) wlan_get_power, /* SIOCGIWPOWER */ |
| 2429 | (iw_handler) NULL, /* -- hole -- */ |
| 2430 | (iw_handler) NULL, /* -- hole -- */ |
| 2431 | (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */ |
| 2432 | (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */ |
| 2433 | (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */ |
| 2434 | (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */ |
| 2435 | (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */ |
| 2436 | (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */ |
| 2437 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 2438 | }; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2439 | struct iw_handler_def libertas_handler_def = { |
| 2440 | .num_standard = sizeof(wlan_handler) / sizeof(iw_handler), |
| 2441 | .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler), |
| 2442 | .num_private_args = sizeof(wlan_private_args) / |
| 2443 | sizeof(struct iw_priv_args), |
| 2444 | .standard = (iw_handler *) wlan_handler, |
| 2445 | .private = (iw_handler *) wlan_private_handler, |
| 2446 | .private_args = (struct iw_priv_args *)wlan_private_args, |
| 2447 | .get_wireless_stats = wlan_get_wireless_stats, |
| 2448 | }; |
Luis Carlos Cobo Rus | f5e05b6 | 2007-05-25 23:08:34 -0400 | [diff] [blame] | 2449 | |
| 2450 | struct iw_handler_def mesh_handler_def = { |
| 2451 | .num_standard = sizeof(mesh_wlan_handler) / sizeof(iw_handler), |
| 2452 | .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler), |
| 2453 | .num_private_args = sizeof(wlan_private_args) / |
| 2454 | sizeof(struct iw_priv_args), |
| 2455 | .standard = (iw_handler *) mesh_wlan_handler, |
| 2456 | .private = (iw_handler *) wlan_private_handler, |
| 2457 | .private_args = (struct iw_priv_args *)wlan_private_args, |
| 2458 | .get_wireless_stats = wlan_get_wireless_stats, |
| 2459 | }; |