Commit | Line | Data |
---|---|---|
a0a954b1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
13a9930d WS |
2 | /* |
3 | * Driver for KeyStream 11b/g wireless LAN | |
4 | * | |
13a9930d WS |
5 | * Copyright (C) 2005-2008 KeyStream Corp. |
6 | * Copyright (C) 2009 Renesas Technology Corp. | |
13a9930d WS |
7 | */ |
8 | ||
8a4e6ab3 | 9 | #include <linux/atomic.h> |
13a9930d | 10 | #include <linux/completion.h> |
8a4e6ab3 SP |
11 | #include <linux/if_arp.h> |
12 | #include <linux/netdevice.h> | |
13a9930d | 13 | #include <linux/timer.h> |
99a751c7 | 14 | #include <linux/uaccess.h> |
13a9930d WS |
15 | |
16 | static int wep_on_off; | |
17 | #define WEP_OFF 0 | |
18 | #define WEP_ON_64BIT 1 | |
19 | #define WEP_ON_128BIT 2 | |
20 | ||
21 | #include "ks_wlan.h" | |
22 | #include "ks_hostif.h" | |
23 | #include "ks_wlan_ioctl.h" | |
13a9930d WS |
24 | |
25 | /* Include Wireless Extension definition and check version */ | |
26 | #include <linux/wireless.h> | |
1df65547 | 27 | #define WIRELESS_SPY /* enable iwspy support */ |
13a9930d WS |
28 | #include <net/iw_handler.h> /* New driver API */ |
29 | ||
13a9930d | 30 | /* Frequency list (map channels to frequencies) */ |
60d4125d SP |
31 | static const long frequency_list[] = { |
32 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, | |
1df65547 WS |
33 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 |
34 | }; | |
13a9930d WS |
35 | |
36 | /* A few details needed for WEP (Wireless Equivalent Privacy) */ | |
37 | #define MAX_KEY_SIZE 13 /* 128 (?) bits */ | |
38 | #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */ | |
acefb645 | 39 | struct wep_key { |
1df65547 WS |
40 | u16 len; |
41 | u8 key[16]; /* 40-bit and 104-bit keys */ | |
acefb645 | 42 | }; |
13a9930d | 43 | |
13a9930d WS |
44 | /* |
45 | * function prototypes | |
46 | */ | |
1df65547 WS |
47 | static int ks_wlan_open(struct net_device *dev); |
48 | static void ks_wlan_tx_timeout(struct net_device *dev); | |
49 | static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
50 | static int ks_wlan_close(struct net_device *dev); | |
582475a2 | 51 | static void ks_wlan_set_rx_mode(struct net_device *dev); |
1df65547 | 52 | static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev); |
13a9930d | 53 | static int ks_wlan_set_mac_address(struct net_device *dev, void *addr); |
1df65547 WS |
54 | static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, |
55 | int cmd); | |
13a9930d WS |
56 | |
57 | static atomic_t update_phyinfo; | |
58 | static struct timer_list update_phyinfo_timer; | |
59 | static | |
feedcf1a | 60 | int ks_wlan_update_phy_information(struct ks_wlan_private *priv) |
13a9930d | 61 | { |
1df65547 | 62 | struct iw_statistics *wstats = &priv->wstats; |
13a9930d | 63 | |
5259b329 | 64 | netdev_dbg(priv->net_dev, "in_interrupt = %ld\n", in_interrupt()); |
13a9930d | 65 | |
6b750fac | 66 | if (priv->dev_state < DEVICE_STATE_READY) |
aa6ca807 | 67 | return -EBUSY; /* not finished initialize */ |
6b750fac | 68 | |
1df65547 | 69 | if (atomic_read(&update_phyinfo)) |
aa6ca807 | 70 | return -EPERM; |
13a9930d WS |
71 | |
72 | /* The status */ | |
73 | wstats->status = priv->reg.operation_mode; /* Operation mode */ | |
74 | ||
75 | /* Signal quality and co. But where is the noise level ??? */ | |
76 | hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST); | |
77 | ||
78 | /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */ | |
1df65547 WS |
79 | if (!wait_for_completion_interruptible_timeout |
80 | (&priv->confirm_wait, HZ / 2)) { | |
5259b329 | 81 | netdev_dbg(priv->net_dev, "wait time out!!\n"); |
13a9930d WS |
82 | } |
83 | ||
84 | atomic_inc(&update_phyinfo); | |
1df65547 | 85 | update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */ |
13a9930d WS |
86 | add_timer(&update_phyinfo_timer); |
87 | ||
88 | return 0; | |
89 | } | |
90 | ||
91 | static | |
8a81f749 | 92 | void ks_wlan_update_phyinfo_timeout(struct timer_list *unused) |
13a9930d | 93 | { |
5259b329 | 94 | pr_debug("in_interrupt = %ld\n", in_interrupt()); |
1df65547 | 95 | atomic_set(&update_phyinfo, 0); |
13a9930d WS |
96 | } |
97 | ||
1df65547 WS |
98 | int ks_wlan_setup_parameter(struct ks_wlan_private *priv, |
99 | unsigned int commit_flag) | |
13a9930d | 100 | { |
13a9930d WS |
101 | hostif_sme_enqueue(priv, SME_STOP_REQUEST); |
102 | ||
1df65547 | 103 | if (commit_flag & SME_RTS) |
13a9930d | 104 | hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST); |
1df65547 | 105 | if (commit_flag & SME_FRAG) |
13a9930d WS |
106 | hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST); |
107 | ||
1df65547 | 108 | if (commit_flag & SME_WEP_INDEX) |
13a9930d | 109 | hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST); |
1df65547 | 110 | if (commit_flag & SME_WEP_VAL1) |
13a9930d | 111 | hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST); |
1df65547 | 112 | if (commit_flag & SME_WEP_VAL2) |
13a9930d | 113 | hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST); |
1df65547 | 114 | if (commit_flag & SME_WEP_VAL3) |
13a9930d | 115 | hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST); |
1df65547 | 116 | if (commit_flag & SME_WEP_VAL4) |
13a9930d | 117 | hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST); |
1df65547 | 118 | if (commit_flag & SME_WEP_FLAG) |
13a9930d WS |
119 | hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST); |
120 | ||
1df65547 | 121 | if (commit_flag & SME_RSN) { |
13a9930d WS |
122 | hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST); |
123 | hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST); | |
124 | } | |
1df65547 | 125 | if (commit_flag & SME_RSN_MULTICAST) |
13a9930d | 126 | hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST); |
1df65547 | 127 | if (commit_flag & SME_RSN_UNICAST) |
13a9930d | 128 | hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST); |
1df65547 | 129 | if (commit_flag & SME_RSN_AUTH) |
13a9930d WS |
130 | hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST); |
131 | ||
132 | hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST); | |
133 | ||
134 | hostif_sme_enqueue(priv, SME_START_REQUEST); | |
135 | ||
136 | return 0; | |
137 | } | |
138 | ||
13a9930d WS |
139 | /* |
140 | * Initial Wireless Extension code for Ks_Wlannet driver by : | |
141 | * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00 | |
142 | * Conversion to new driver API by : | |
143 | * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02 | |
144 | * Javier also did a good amount of work here, adding some new extensions | |
145 | * and fixing my code. Let's just say that without him this code just | |
146 | * would not work at all... - Jean II | |
147 | */ | |
148 | ||
1df65547 | 149 | static int ks_wlan_get_name(struct net_device *dev, |
18e76e23 SP |
150 | struct iw_request_info *info, |
151 | union iwreq_data *cwrq, | |
1df65547 | 152 | char *extra) |
13a9930d | 153 | { |
2b0d92b2 | 154 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 155 | |
6b750fac | 156 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 157 | return -EPERM; |
6b750fac | 158 | |
1df65547 | 159 | /* for SLEEP MODE */ |
6b750fac | 160 | if (priv->dev_state < DEVICE_STATE_READY) |
18e76e23 | 161 | strcpy(cwrq->name, "NOT READY!"); |
6b750fac | 162 | else if (priv->reg.phy_type == D_11B_ONLY_MODE) |
18e76e23 | 163 | strcpy(cwrq->name, "IEEE 802.11b"); |
6b750fac | 164 | else if (priv->reg.phy_type == D_11G_ONLY_MODE) |
18e76e23 | 165 | strcpy(cwrq->name, "IEEE 802.11g"); |
6b750fac | 166 | else |
18e76e23 | 167 | strcpy(cwrq->name, "IEEE 802.11b/g"); |
13a9930d WS |
168 | |
169 | return 0; | |
170 | } | |
171 | ||
1df65547 | 172 | static int ks_wlan_set_freq(struct net_device *dev, |
18e76e23 SP |
173 | struct iw_request_info *info, |
174 | union iwreq_data *fwrq, char *extra) | |
13a9930d | 175 | { |
2b0d92b2 | 176 | struct ks_wlan_private *priv = netdev_priv(dev); |
ba932876 | 177 | int channel; |
13a9930d | 178 | |
6b750fac | 179 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 180 | return -EPERM; |
13a9930d | 181 | |
1df65547 | 182 | /* for SLEEP MODE */ |
13a9930d | 183 | /* If setting by frequency, convert to a channel */ |
18e76e23 SP |
184 | if ((fwrq->freq.e == 1) && |
185 | (fwrq->freq.m >= (int)2.412e8) && (fwrq->freq.m <= (int)2.487e8)) { | |
186 | int f = fwrq->freq.m / 100000; | |
13a9930d | 187 | int c = 0; |
fe497530 | 188 | |
1df65547 | 189 | while ((c < 14) && (f != frequency_list[c])) |
13a9930d WS |
190 | c++; |
191 | /* Hack to fall through... */ | |
18e76e23 SP |
192 | fwrq->freq.e = 0; |
193 | fwrq->freq.m = c + 1; | |
13a9930d WS |
194 | } |
195 | /* Setting by channel number */ | |
18e76e23 | 196 | if ((fwrq->freq.m > 1000) || (fwrq->freq.e > 0)) |
13b05e46 | 197 | return -EOPNOTSUPP; |
ba932876 | 198 | |
18e76e23 | 199 | channel = fwrq->freq.m; |
ba932876 TH |
200 | /* We should do a better check than that, |
201 | * based on the card capability !!! | |
202 | */ | |
203 | if ((channel < 1) || (channel > 14)) { | |
204 | netdev_dbg(dev, "%s: New channel value of %d is invalid!\n", | |
18e76e23 | 205 | dev->name, fwrq->freq.m); |
ba932876 | 206 | return -EINVAL; |
13a9930d WS |
207 | } |
208 | ||
ba932876 TH |
209 | /* Yes ! We can set it !!! */ |
210 | priv->reg.channel = (u8)(channel); | |
211 | priv->need_commit |= SME_MODE_SET; | |
212 | ||
13b05e46 | 213 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
214 | } |
215 | ||
1df65547 | 216 | static int ks_wlan_get_freq(struct net_device *dev, |
18e76e23 SP |
217 | struct iw_request_info *info, |
218 | union iwreq_data *fwrq, char *extra) | |
13a9930d | 219 | { |
2b0d92b2 | 220 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
221 | int f; |
222 | ||
6b750fac | 223 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 224 | return -EPERM; |
6b750fac | 225 | |
1df65547 | 226 | /* for SLEEP MODE */ |
0e24eb8a | 227 | if (is_connect_status(priv->connect_status)) |
1df65547 | 228 | f = (int)priv->current_ap.channel; |
0e24eb8a | 229 | else |
13a9930d | 230 | f = (int)priv->reg.channel; |
0e24eb8a | 231 | |
18e76e23 SP |
232 | fwrq->freq.m = frequency_list[f - 1] * 100000; |
233 | fwrq->freq.e = 1; | |
13a9930d WS |
234 | |
235 | return 0; | |
236 | } | |
237 | ||
1df65547 WS |
238 | static int ks_wlan_set_essid(struct net_device *dev, |
239 | struct iw_request_info *info, | |
18e76e23 | 240 | union iwreq_data *dwrq, char *extra) |
13a9930d | 241 | { |
2b0d92b2 | 242 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
243 | size_t len; |
244 | ||
6b750fac | 245 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 246 | return -EPERM; |
6b750fac | 247 | |
1df65547 | 248 | /* for SLEEP MODE */ |
13a9930d | 249 | /* Check if we asked for `any' */ |
18e76e23 | 250 | if (!dwrq->essid.flags) { |
13a9930d WS |
251 | /* Just send an empty SSID list */ |
252 | memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body)); | |
253 | priv->reg.ssid.size = 0; | |
254 | } else { | |
18e76e23 | 255 | len = dwrq->essid.length; |
13a9930d WS |
256 | /* iwconfig uses nul termination in SSID.. */ |
257 | if (len > 0 && extra[len - 1] == '\0') | |
258 | len--; | |
259 | ||
260 | /* Check the size of the string */ | |
6b750fac | 261 | if (len > IW_ESSID_MAX_SIZE) |
13a9930d | 262 | return -EINVAL; |
6b750fac | 263 | |
13a9930d WS |
264 | /* Set the SSID */ |
265 | memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body)); | |
13a9930d WS |
266 | memcpy(priv->reg.ssid.body, extra, len); |
267 | priv->reg.ssid.size = len; | |
13a9930d WS |
268 | } |
269 | /* Write it to the card */ | |
270 | priv->need_commit |= SME_MODE_SET; | |
271 | ||
13a9930d | 272 | ks_wlan_setup_parameter(priv, priv->need_commit); |
1df65547 WS |
273 | priv->need_commit = 0; |
274 | return 0; | |
13a9930d WS |
275 | } |
276 | ||
1df65547 WS |
277 | static int ks_wlan_get_essid(struct net_device *dev, |
278 | struct iw_request_info *info, | |
18e76e23 | 279 | union iwreq_data *dwrq, char *extra) |
13a9930d | 280 | { |
2b0d92b2 | 281 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 282 | |
6b750fac | 283 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 284 | return -EPERM; |
6b750fac | 285 | |
1df65547 | 286 | /* for SLEEP MODE */ |
13a9930d | 287 | /* Note : if dwrq->flags != 0, we should |
64068bc3 TH |
288 | * get the relevant SSID from the SSID list... |
289 | */ | |
310e916f | 290 | if (priv->reg.ssid.size != 0) { |
13a9930d WS |
291 | /* Get the current SSID */ |
292 | memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size); | |
6cdd6538 | 293 | |
13a9930d WS |
294 | /* If none, we may want to get the one that was set */ |
295 | ||
296 | /* Push it out ! */ | |
18e76e23 SP |
297 | dwrq->essid.length = priv->reg.ssid.size; |
298 | dwrq->essid.flags = 1; /* active */ | |
1df65547 | 299 | } else { |
18e76e23 SP |
300 | dwrq->essid.length = 0; |
301 | dwrq->essid.flags = 0; /* ANY */ | |
13a9930d WS |
302 | } |
303 | ||
304 | return 0; | |
305 | } | |
306 | ||
13a9930d | 307 | static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info, |
18e76e23 | 308 | union iwreq_data *awrq, char *extra) |
13a9930d | 309 | { |
2b0d92b2 | 310 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 311 | |
6b750fac | 312 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 313 | return -EPERM; |
6b750fac | 314 | |
1df65547 | 315 | /* for SLEEP MODE */ |
90db5912 SP |
316 | if (priv->reg.operation_mode != MODE_ADHOC && |
317 | priv->reg.operation_mode != MODE_INFRASTRUCTURE) { | |
30b48e2d | 318 | eth_zero_addr(priv->reg.bssid); |
13a9930d WS |
319 | return -EOPNOTSUPP; |
320 | } | |
321 | ||
90db5912 SP |
322 | ether_addr_copy(priv->reg.bssid, awrq->ap_addr.sa_data); |
323 | if (is_valid_ether_addr((u8 *)priv->reg.bssid)) | |
324 | priv->need_commit |= SME_MODE_SET; | |
325 | ||
5259b329 | 326 | netdev_dbg(dev, "bssid = %pM\n", priv->reg.bssid); |
13a9930d WS |
327 | |
328 | /* Write it to the card */ | |
329 | if (priv->need_commit) { | |
330 | priv->need_commit |= SME_MODE_SET; | |
1df65547 | 331 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
332 | } |
333 | return 0; | |
334 | } | |
335 | ||
13a9930d | 336 | static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info, |
18e76e23 | 337 | union iwreq_data *awrq, char *extra) |
13a9930d | 338 | { |
2b0d92b2 | 339 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 340 | |
6b750fac | 341 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 342 | return -EPERM; |
6b750fac | 343 | |
1df65547 | 344 | /* for SLEEP MODE */ |
0e24eb8a | 345 | if (is_connect_status(priv->connect_status)) |
afa10db0 | 346 | ether_addr_copy(awrq->ap_addr.sa_data, priv->current_ap.bssid); |
6b750fac | 347 | else |
18e76e23 | 348 | eth_zero_addr(awrq->ap_addr.sa_data); |
13a9930d | 349 | |
18e76e23 | 350 | awrq->ap_addr.sa_family = ARPHRD_ETHER; |
13a9930d WS |
351 | |
352 | return 0; | |
353 | } | |
354 | ||
1df65547 | 355 | static int ks_wlan_set_nick(struct net_device *dev, |
18e76e23 SP |
356 | struct iw_request_info *info, |
357 | union iwreq_data *dwrq, char *extra) | |
13a9930d | 358 | { |
2b0d92b2 | 359 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 360 | |
6b750fac | 361 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 362 | return -EPERM; |
13a9930d | 363 | |
1df65547 | 364 | /* for SLEEP MODE */ |
13a9930d | 365 | /* Check the size of the string */ |
18e76e23 | 366 | if (dwrq->data.length > 16 + 1) |
13a9930d | 367 | return -E2BIG; |
6b750fac | 368 | |
13a9930d | 369 | memset(priv->nick, 0, sizeof(priv->nick)); |
18e76e23 | 370 | memcpy(priv->nick, extra, dwrq->data.length); |
13a9930d WS |
371 | |
372 | return -EINPROGRESS; /* Call commit handler */ | |
373 | } | |
374 | ||
1df65547 | 375 | static int ks_wlan_get_nick(struct net_device *dev, |
18e76e23 SP |
376 | struct iw_request_info *info, |
377 | union iwreq_data *dwrq, char *extra) | |
13a9930d | 378 | { |
2b0d92b2 | 379 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 380 | |
6b750fac | 381 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 382 | return -EPERM; |
6b750fac | 383 | |
1df65547 | 384 | /* for SLEEP MODE */ |
13a9930d WS |
385 | strncpy(extra, priv->nick, 16); |
386 | extra[16] = '\0'; | |
18e76e23 | 387 | dwrq->data.length = strlen(extra) + 1; |
13a9930d WS |
388 | |
389 | return 0; | |
390 | } | |
391 | ||
1df65547 | 392 | static int ks_wlan_set_rate(struct net_device *dev, |
18e76e23 SP |
393 | struct iw_request_info *info, |
394 | union iwreq_data *vwrq, char *extra) | |
13a9930d | 395 | { |
2b0d92b2 | 396 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
397 | int i = 0; |
398 | ||
6b750fac | 399 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 400 | return -EPERM; |
6b750fac | 401 | |
1df65547 WS |
402 | /* for SLEEP MODE */ |
403 | if (priv->reg.phy_type == D_11B_ONLY_MODE) { | |
18e76e23 SP |
404 | if (vwrq->bitrate.fixed == 1) { |
405 | switch (vwrq->bitrate.value) { | |
13a9930d | 406 | case 11000000: |
1df65547 WS |
407 | case 5500000: |
408 | priv->reg.rate_set.body[0] = | |
255d4e1d | 409 | (u8)(vwrq->bitrate.value / 500000); |
13a9930d | 410 | break; |
1df65547 WS |
411 | case 2000000: |
412 | case 1000000: | |
413 | priv->reg.rate_set.body[0] = | |
255d4e1d | 414 | ((u8)(vwrq->bitrate.value / 500000)) | |
1df65547 | 415 | BASIC_RATE; |
13a9930d WS |
416 | break; |
417 | default: | |
418 | return -EINVAL; | |
419 | } | |
420 | priv->reg.tx_rate = TX_RATE_FIXED; | |
421 | priv->reg.rate_set.size = 1; | |
1df65547 | 422 | } else { /* vwrq->fixed == 0 */ |
18e76e23 SP |
423 | if (vwrq->bitrate.value > 0) { |
424 | switch (vwrq->bitrate.value) { | |
13a9930d | 425 | case 11000000: |
1df65547 WS |
426 | priv->reg.rate_set.body[3] = |
427 | TX_RATE_11M; | |
428 | i++; | |
583d6a93 | 429 | /* fall through */ |
1df65547 WS |
430 | case 5500000: |
431 | priv->reg.rate_set.body[2] = TX_RATE_5M; | |
432 | i++; | |
583d6a93 | 433 | /* fall through */ |
1df65547 WS |
434 | case 2000000: |
435 | priv->reg.rate_set.body[1] = | |
436 | TX_RATE_2M | BASIC_RATE; | |
437 | i++; | |
583d6a93 | 438 | /* fall through */ |
1df65547 WS |
439 | case 1000000: |
440 | priv->reg.rate_set.body[0] = | |
441 | TX_RATE_1M | BASIC_RATE; | |
442 | i++; | |
13a9930d WS |
443 | break; |
444 | default: | |
445 | return -EINVAL; | |
446 | } | |
447 | priv->reg.tx_rate = TX_RATE_MANUAL_AUTO; | |
448 | priv->reg.rate_set.size = i; | |
1df65547 | 449 | } else { |
13a9930d WS |
450 | priv->reg.rate_set.body[3] = TX_RATE_11M; |
451 | priv->reg.rate_set.body[2] = TX_RATE_5M; | |
1df65547 WS |
452 | priv->reg.rate_set.body[1] = |
453 | TX_RATE_2M | BASIC_RATE; | |
454 | priv->reg.rate_set.body[0] = | |
455 | TX_RATE_1M | BASIC_RATE; | |
13a9930d WS |
456 | priv->reg.tx_rate = TX_RATE_FULL_AUTO; |
457 | priv->reg.rate_set.size = 4; | |
458 | } | |
459 | } | |
1df65547 | 460 | } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */ |
18e76e23 SP |
461 | if (vwrq->bitrate.fixed == 1) { |
462 | switch (vwrq->bitrate.value) { | |
13a9930d WS |
463 | case 54000000: |
464 | case 48000000: | |
465 | case 36000000: | |
466 | case 18000000: | |
1df65547 WS |
467 | case 9000000: |
468 | priv->reg.rate_set.body[0] = | |
255d4e1d | 469 | (u8)(vwrq->bitrate.value / 500000); |
13a9930d WS |
470 | break; |
471 | case 24000000: | |
472 | case 12000000: | |
473 | case 11000000: | |
1df65547 WS |
474 | case 6000000: |
475 | case 5500000: | |
476 | case 2000000: | |
477 | case 1000000: | |
478 | priv->reg.rate_set.body[0] = | |
255d4e1d | 479 | ((u8)(vwrq->bitrate.value / 500000)) | |
1df65547 | 480 | BASIC_RATE; |
13a9930d WS |
481 | break; |
482 | default: | |
483 | return -EINVAL; | |
484 | } | |
485 | priv->reg.tx_rate = TX_RATE_FIXED; | |
486 | priv->reg.rate_set.size = 1; | |
1df65547 | 487 | } else { /* vwrq->fixed == 0 */ |
18e76e23 SP |
488 | if (vwrq->bitrate.value > 0) { |
489 | switch (vwrq->bitrate.value) { | |
13a9930d | 490 | case 54000000: |
1df65547 WS |
491 | priv->reg.rate_set.body[11] = |
492 | TX_RATE_54M; | |
493 | i++; | |
583d6a93 | 494 | /* fall through */ |
13a9930d | 495 | case 48000000: |
1df65547 WS |
496 | priv->reg.rate_set.body[10] = |
497 | TX_RATE_48M; | |
498 | i++; | |
583d6a93 | 499 | /* fall through */ |
13a9930d | 500 | case 36000000: |
1df65547 WS |
501 | priv->reg.rate_set.body[9] = |
502 | TX_RATE_36M; | |
503 | i++; | |
583d6a93 | 504 | /* fall through */ |
1df65547 WS |
505 | case 24000000: |
506 | case 18000000: | |
507 | case 12000000: | |
508 | case 11000000: | |
509 | case 9000000: | |
510 | case 6000000: | |
18e76e23 | 511 | if (vwrq->bitrate.value == 24000000) { |
1df65547 WS |
512 | priv->reg.rate_set.body[8] = |
513 | TX_RATE_18M; | |
514 | i++; | |
515 | priv->reg.rate_set.body[7] = | |
516 | TX_RATE_9M; | |
517 | i++; | |
518 | priv->reg.rate_set.body[6] = | |
519 | TX_RATE_24M | BASIC_RATE; | |
520 | i++; | |
521 | priv->reg.rate_set.body[5] = | |
522 | TX_RATE_12M | BASIC_RATE; | |
523 | i++; | |
524 | priv->reg.rate_set.body[4] = | |
525 | TX_RATE_6M | BASIC_RATE; | |
526 | i++; | |
527 | priv->reg.rate_set.body[3] = | |
528 | TX_RATE_11M | BASIC_RATE; | |
529 | i++; | |
18e76e23 | 530 | } else if (vwrq->bitrate.value == 18000000) { |
1df65547 WS |
531 | priv->reg.rate_set.body[7] = |
532 | TX_RATE_18M; | |
533 | i++; | |
534 | priv->reg.rate_set.body[6] = | |
535 | TX_RATE_9M; | |
536 | i++; | |
537 | priv->reg.rate_set.body[5] = | |
538 | TX_RATE_12M | BASIC_RATE; | |
539 | i++; | |
540 | priv->reg.rate_set.body[4] = | |
541 | TX_RATE_6M | BASIC_RATE; | |
542 | i++; | |
543 | priv->reg.rate_set.body[3] = | |
544 | TX_RATE_11M | BASIC_RATE; | |
545 | i++; | |
18e76e23 | 546 | } else if (vwrq->bitrate.value == 12000000) { |
1df65547 WS |
547 | priv->reg.rate_set.body[6] = |
548 | TX_RATE_9M; | |
549 | i++; | |
550 | priv->reg.rate_set.body[5] = | |
551 | TX_RATE_12M | BASIC_RATE; | |
552 | i++; | |
553 | priv->reg.rate_set.body[4] = | |
554 | TX_RATE_6M | BASIC_RATE; | |
555 | i++; | |
556 | priv->reg.rate_set.body[3] = | |
557 | TX_RATE_11M | BASIC_RATE; | |
558 | i++; | |
18e76e23 | 559 | } else if (vwrq->bitrate.value == 11000000) { |
1df65547 WS |
560 | priv->reg.rate_set.body[5] = |
561 | TX_RATE_9M; | |
562 | i++; | |
563 | priv->reg.rate_set.body[4] = | |
564 | TX_RATE_6M | BASIC_RATE; | |
565 | i++; | |
566 | priv->reg.rate_set.body[3] = | |
567 | TX_RATE_11M | BASIC_RATE; | |
568 | i++; | |
18e76e23 | 569 | } else if (vwrq->bitrate.value == 9000000) { |
1df65547 WS |
570 | priv->reg.rate_set.body[4] = |
571 | TX_RATE_9M; | |
572 | i++; | |
573 | priv->reg.rate_set.body[3] = | |
574 | TX_RATE_6M | BASIC_RATE; | |
575 | i++; | |
576 | } else { /* vwrq->value == 6000000 */ | |
577 | priv->reg.rate_set.body[3] = | |
578 | TX_RATE_6M | BASIC_RATE; | |
579 | i++; | |
13a9930d | 580 | } |
583d6a93 | 581 | /* fall through */ |
1df65547 WS |
582 | case 5500000: |
583 | priv->reg.rate_set.body[2] = | |
584 | TX_RATE_5M | BASIC_RATE; | |
585 | i++; | |
583d6a93 | 586 | /* fall through */ |
1df65547 WS |
587 | case 2000000: |
588 | priv->reg.rate_set.body[1] = | |
589 | TX_RATE_2M | BASIC_RATE; | |
590 | i++; | |
583d6a93 | 591 | /* fall through */ |
1df65547 WS |
592 | case 1000000: |
593 | priv->reg.rate_set.body[0] = | |
594 | TX_RATE_1M | BASIC_RATE; | |
595 | i++; | |
13a9930d WS |
596 | break; |
597 | default: | |
598 | return -EINVAL; | |
599 | } | |
600 | priv->reg.tx_rate = TX_RATE_MANUAL_AUTO; | |
601 | priv->reg.rate_set.size = i; | |
1df65547 | 602 | } else { |
13a9930d WS |
603 | priv->reg.rate_set.body[11] = TX_RATE_54M; |
604 | priv->reg.rate_set.body[10] = TX_RATE_48M; | |
605 | priv->reg.rate_set.body[9] = TX_RATE_36M; | |
606 | priv->reg.rate_set.body[8] = TX_RATE_18M; | |
607 | priv->reg.rate_set.body[7] = TX_RATE_9M; | |
1df65547 WS |
608 | priv->reg.rate_set.body[6] = |
609 | TX_RATE_24M | BASIC_RATE; | |
610 | priv->reg.rate_set.body[5] = | |
611 | TX_RATE_12M | BASIC_RATE; | |
612 | priv->reg.rate_set.body[4] = | |
613 | TX_RATE_6M | BASIC_RATE; | |
614 | priv->reg.rate_set.body[3] = | |
615 | TX_RATE_11M | BASIC_RATE; | |
616 | priv->reg.rate_set.body[2] = | |
617 | TX_RATE_5M | BASIC_RATE; | |
618 | priv->reg.rate_set.body[1] = | |
619 | TX_RATE_2M | BASIC_RATE; | |
620 | priv->reg.rate_set.body[0] = | |
621 | TX_RATE_1M | BASIC_RATE; | |
13a9930d WS |
622 | priv->reg.tx_rate = TX_RATE_FULL_AUTO; |
623 | priv->reg.rate_set.size = 12; | |
624 | } | |
625 | } | |
626 | } | |
627 | ||
628 | priv->need_commit |= SME_MODE_SET; | |
629 | ||
630 | return -EINPROGRESS; /* Call commit handler */ | |
631 | } | |
632 | ||
1df65547 | 633 | static int ks_wlan_get_rate(struct net_device *dev, |
18e76e23 SP |
634 | struct iw_request_info *info, |
635 | union iwreq_data *vwrq, char *extra) | |
13a9930d | 636 | { |
2b0d92b2 | 637 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 638 | |
5259b329 SP |
639 | netdev_dbg(dev, "in_interrupt = %ld update_phyinfo = %d\n", |
640 | in_interrupt(), atomic_read(&update_phyinfo)); | |
13a9930d | 641 | |
6b750fac | 642 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 643 | return -EPERM; |
6b750fac | 644 | |
1df65547 | 645 | /* for SLEEP MODE */ |
6b750fac | 646 | if (!atomic_read(&update_phyinfo)) |
13a9930d | 647 | ks_wlan_update_phy_information(priv); |
6b750fac | 648 | |
18e76e23 SP |
649 | vwrq->bitrate.value = ((priv->current_rate) & RATE_MASK) * 500000; |
650 | vwrq->bitrate.fixed = (priv->reg.tx_rate == TX_RATE_FIXED) ? 1 : 0; | |
13a9930d WS |
651 | |
652 | return 0; | |
653 | } | |
654 | ||
13a9930d | 655 | static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info, |
18e76e23 | 656 | union iwreq_data *vwrq, char *extra) |
13a9930d | 657 | { |
2b0d92b2 | 658 | struct ks_wlan_private *priv = netdev_priv(dev); |
18e76e23 | 659 | int rthr = vwrq->rts.value; |
13a9930d | 660 | |
6b750fac | 661 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 662 | return -EPERM; |
6b750fac | 663 | |
1df65547 | 664 | /* for SLEEP MODE */ |
18e76e23 | 665 | if (vwrq->rts.disabled) |
13a9930d | 666 | rthr = 2347; |
6b750fac | 667 | if ((rthr < 0) || (rthr > 2347)) |
13a9930d | 668 | return -EINVAL; |
6b750fac | 669 | |
13a9930d WS |
670 | priv->reg.rts = rthr; |
671 | priv->need_commit |= SME_RTS; | |
672 | ||
673 | return -EINPROGRESS; /* Call commit handler */ | |
674 | } | |
675 | ||
13a9930d | 676 | static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info, |
18e76e23 | 677 | union iwreq_data *vwrq, char *extra) |
13a9930d | 678 | { |
2b0d92b2 | 679 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 680 | |
6b750fac | 681 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 682 | return -EPERM; |
6b750fac | 683 | |
1df65547 | 684 | /* for SLEEP MODE */ |
18e76e23 SP |
685 | vwrq->rts.value = priv->reg.rts; |
686 | vwrq->rts.disabled = (vwrq->rts.value >= 2347); | |
687 | vwrq->rts.fixed = 1; | |
13a9930d WS |
688 | |
689 | return 0; | |
690 | } | |
691 | ||
1df65547 | 692 | static int ks_wlan_set_frag(struct net_device *dev, |
18e76e23 SP |
693 | struct iw_request_info *info, |
694 | union iwreq_data *vwrq, char *extra) | |
13a9930d | 695 | { |
2b0d92b2 | 696 | struct ks_wlan_private *priv = netdev_priv(dev); |
18e76e23 | 697 | int fthr = vwrq->frag.value; |
13a9930d | 698 | |
6b750fac | 699 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 700 | return -EPERM; |
6b750fac | 701 | |
1df65547 | 702 | /* for SLEEP MODE */ |
18e76e23 | 703 | if (vwrq->frag.disabled) |
13a9930d | 704 | fthr = 2346; |
6b750fac | 705 | if ((fthr < 256) || (fthr > 2346)) |
13a9930d | 706 | return -EINVAL; |
6b750fac | 707 | |
13a9930d WS |
708 | fthr &= ~0x1; /* Get an even value - is it really needed ??? */ |
709 | priv->reg.fragment = fthr; | |
710 | priv->need_commit |= SME_FRAG; | |
711 | ||
712 | return -EINPROGRESS; /* Call commit handler */ | |
713 | } | |
714 | ||
1df65547 | 715 | static int ks_wlan_get_frag(struct net_device *dev, |
18e76e23 SP |
716 | struct iw_request_info *info, |
717 | union iwreq_data *vwrq, char *extra) | |
13a9930d | 718 | { |
2b0d92b2 | 719 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 720 | |
6b750fac | 721 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 722 | return -EPERM; |
6b750fac | 723 | |
1df65547 | 724 | /* for SLEEP MODE */ |
18e76e23 SP |
725 | vwrq->frag.value = priv->reg.fragment; |
726 | vwrq->frag.disabled = (vwrq->frag.value >= 2346); | |
727 | vwrq->frag.fixed = 1; | |
13a9930d WS |
728 | |
729 | return 0; | |
730 | } | |
731 | ||
1df65547 | 732 | static int ks_wlan_set_mode(struct net_device *dev, |
18e76e23 SP |
733 | struct iw_request_info *info, |
734 | union iwreq_data *uwrq, char *extra) | |
13a9930d | 735 | { |
2b0d92b2 | 736 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 737 | |
6b750fac | 738 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 739 | return -EPERM; |
6b750fac | 740 | |
1e4c7fb3 SP |
741 | if (uwrq->mode != IW_MODE_ADHOC && |
742 | uwrq->mode != IW_MODE_INFRA) | |
13a9930d | 743 | return -EINVAL; |
1e4c7fb3 SP |
744 | |
745 | priv->reg.operation_mode = (uwrq->mode == IW_MODE_ADHOC) ? | |
746 | MODE_ADHOC : MODE_INFRASTRUCTURE; | |
747 | priv->need_commit |= SME_MODE_SET; | |
13a9930d | 748 | |
1df65547 | 749 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
750 | } |
751 | ||
1df65547 | 752 | static int ks_wlan_get_mode(struct net_device *dev, |
18e76e23 SP |
753 | struct iw_request_info *info, |
754 | union iwreq_data *uwrq, char *extra) | |
13a9930d | 755 | { |
2b0d92b2 | 756 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 757 | |
6b750fac | 758 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 759 | return -EPERM; |
13a9930d WS |
760 | |
761 | /* If not managed, assume it's ad-hoc */ | |
ca946972 SP |
762 | uwrq->mode = (priv->reg.operation_mode == MODE_INFRASTRUCTURE) ? |
763 | IW_MODE_INFRA : IW_MODE_ADHOC; | |
13a9930d WS |
764 | |
765 | return 0; | |
766 | } | |
767 | ||
1df65547 WS |
768 | static int ks_wlan_set_encode(struct net_device *dev, |
769 | struct iw_request_info *info, | |
18e76e23 | 770 | union iwreq_data *dwrq, char *extra) |
13a9930d | 771 | { |
2b0d92b2 | 772 | struct ks_wlan_private *priv = netdev_priv(dev); |
18e76e23 | 773 | struct iw_point *enc = &dwrq->encoding; |
acefb645 | 774 | struct wep_key key; |
18e76e23 | 775 | int index = (enc->flags & IW_ENCODE_INDEX); |
13a9930d | 776 | |
6b750fac | 777 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 778 | return -EPERM; |
13a9930d | 779 | |
18e76e23 | 780 | if (enc->length > MAX_KEY_SIZE) |
6cf070d2 SP |
781 | return -EINVAL; |
782 | ||
1df65547 | 783 | /* for SLEEP MODE */ |
1df65547 | 784 | if ((index < 0) || (index > 4)) |
13a9930d | 785 | return -EINVAL; |
6cf070d2 SP |
786 | |
787 | index = (index == 0) ? priv->reg.wep_index : (index - 1); | |
13a9930d WS |
788 | |
789 | /* Is WEP supported ? */ | |
790 | /* Basic checking: do we have a key to set ? */ | |
18e76e23 SP |
791 | if (enc->length > 0) { |
792 | key.len = (enc->length > MIN_KEY_SIZE) ? | |
6cf070d2 SP |
793 | MAX_KEY_SIZE : MIN_KEY_SIZE; |
794 | priv->reg.privacy_invoked = 0x01; | |
795 | priv->need_commit |= SME_WEP_FLAG; | |
18e76e23 | 796 | wep_on_off = (enc->length > MIN_KEY_SIZE) ? |
6cf070d2 | 797 | WEP_ON_128BIT : WEP_ON_64BIT; |
13a9930d | 798 | /* Check if the key is not marked as invalid */ |
18e76e23 | 799 | if (enc->flags & IW_ENCODE_NOKEY) |
6cf070d2 SP |
800 | return 0; |
801 | ||
802 | /* Cleanup */ | |
803 | memset(key.key, 0, MAX_KEY_SIZE); | |
804 | /* Copy the key in the driver */ | |
18e76e23 | 805 | if (copy_from_user(key.key, enc->pointer, enc->length)) { |
6cf070d2 SP |
806 | key.len = 0; |
807 | return -EFAULT; | |
13a9930d | 808 | } |
6cf070d2 SP |
809 | /* Send the key to the card */ |
810 | priv->reg.wep_key[index].size = key.len; | |
811 | memcpy(&priv->reg.wep_key[index].val[0], &key.key[0], | |
812 | priv->reg.wep_key[index].size); | |
813 | priv->need_commit |= (SME_WEP_VAL1 << index); | |
814 | priv->reg.wep_index = index; | |
815 | priv->need_commit |= SME_WEP_INDEX; | |
13a9930d | 816 | } else { |
18e76e23 | 817 | if (enc->flags & IW_ENCODE_DISABLED) { |
13a9930d WS |
818 | priv->reg.wep_key[0].size = 0; |
819 | priv->reg.wep_key[1].size = 0; | |
820 | priv->reg.wep_key[2].size = 0; | |
821 | priv->reg.wep_key[3].size = 0; | |
822 | priv->reg.privacy_invoked = 0x00; | |
6b750fac | 823 | if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) |
13a9930d | 824 | priv->need_commit |= SME_MODE_SET; |
6b750fac | 825 | |
13a9930d WS |
826 | priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; |
827 | wep_on_off = WEP_OFF; | |
828 | priv->need_commit |= SME_WEP_FLAG; | |
1df65547 | 829 | } else { |
6cf070d2 SP |
830 | /* set_wep_key(priv, index, 0, 0, 1); xxx */ |
831 | if (priv->reg.wep_key[index].size == 0) | |
832 | return -EINVAL; | |
833 | priv->reg.wep_index = index; | |
834 | priv->need_commit |= SME_WEP_INDEX; | |
13a9930d WS |
835 | } |
836 | } | |
837 | ||
838 | /* Commit the changes if needed */ | |
18e76e23 | 839 | if (enc->flags & IW_ENCODE_MODE) |
13a9930d WS |
840 | priv->need_commit |= SME_WEP_FLAG; |
841 | ||
18e76e23 | 842 | if (enc->flags & IW_ENCODE_OPEN) { |
6b750fac | 843 | if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) |
13a9930d | 844 | priv->need_commit |= SME_MODE_SET; |
6b750fac | 845 | |
13a9930d | 846 | priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; |
18e76e23 | 847 | } else if (enc->flags & IW_ENCODE_RESTRICTED) { |
6b750fac | 848 | if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) |
13a9930d | 849 | priv->need_commit |= SME_MODE_SET; |
6b750fac | 850 | |
13a9930d WS |
851 | priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY; |
852 | } | |
1df65547 | 853 | if (priv->need_commit) { |
13a9930d | 854 | ks_wlan_setup_parameter(priv, priv->need_commit); |
1df65547 | 855 | priv->need_commit = 0; |
13a9930d WS |
856 | } |
857 | return 0; | |
858 | } | |
859 | ||
1df65547 WS |
860 | static int ks_wlan_get_encode(struct net_device *dev, |
861 | struct iw_request_info *info, | |
18e76e23 | 862 | union iwreq_data *dwrq, char *extra) |
13a9930d | 863 | { |
2b0d92b2 | 864 | struct ks_wlan_private *priv = netdev_priv(dev); |
18e76e23 SP |
865 | struct iw_point *enc = &dwrq->encoding; |
866 | int index = (enc->flags & IW_ENCODE_INDEX) - 1; | |
13a9930d | 867 | |
6b750fac | 868 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 869 | return -EPERM; |
6b750fac | 870 | |
1df65547 | 871 | /* for SLEEP MODE */ |
18e76e23 | 872 | enc->flags = IW_ENCODE_DISABLED; |
13a9930d WS |
873 | |
874 | /* Check encryption mode */ | |
1df65547 | 875 | switch (priv->reg.authenticate_type) { |
13a9930d | 876 | case AUTH_TYPE_OPEN_SYSTEM: |
18e76e23 | 877 | enc->flags = IW_ENCODE_OPEN; |
13a9930d WS |
878 | break; |
879 | case AUTH_TYPE_SHARED_KEY: | |
18e76e23 | 880 | enc->flags = IW_ENCODE_RESTRICTED; |
13a9930d WS |
881 | break; |
882 | } | |
883 | ||
13a9930d | 884 | /* Which key do we want ? -1 -> tx index */ |
1df65547 | 885 | if ((index < 0) || (index >= 4)) |
13a9930d | 886 | index = priv->reg.wep_index; |
1df65547 | 887 | if (priv->reg.privacy_invoked) { |
18e76e23 | 888 | enc->flags &= ~IW_ENCODE_DISABLED; |
13a9930d WS |
889 | /* dwrq->flags |= IW_ENCODE_NOKEY; */ |
890 | } | |
18e76e23 | 891 | enc->flags |= index + 1; |
13a9930d | 892 | /* Copy the key to the user buffer */ |
fffe8bec | 893 | if (index >= 0 && index < 4) { |
18e76e23 | 894 | enc->length = (priv->reg.wep_key[index].size <= 16) ? |
fffe8bec | 895 | priv->reg.wep_key[index].size : 0; |
18e76e23 | 896 | memcpy(extra, priv->reg.wep_key[index].val, enc->length); |
8f4d00cd | 897 | } |
9b512431 | 898 | |
13a9930d WS |
899 | return 0; |
900 | } | |
901 | ||
1df65547 WS |
902 | static int ks_wlan_get_range(struct net_device *dev, |
903 | struct iw_request_info *info, | |
18e76e23 | 904 | union iwreq_data *dwrq, char *extra) |
13a9930d | 905 | { |
2b0d92b2 | 906 | struct ks_wlan_private *priv = netdev_priv(dev); |
1df65547 WS |
907 | struct iw_range *range = (struct iw_range *)extra; |
908 | int i, k; | |
13a9930d | 909 | |
6b750fac | 910 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 911 | return -EPERM; |
6b750fac | 912 | |
1df65547 | 913 | /* for SLEEP MODE */ |
18e76e23 | 914 | dwrq->data.length = sizeof(struct iw_range); |
13a9930d WS |
915 | memset(range, 0, sizeof(*range)); |
916 | range->min_nwid = 0x0000; | |
917 | range->max_nwid = 0x0000; | |
918 | range->num_channels = 14; | |
919 | /* Should be based on cap_rid.country to give only | |
64068bc3 TH |
920 | * what the current card support |
921 | */ | |
13a9930d | 922 | k = 0; |
1df65547 WS |
923 | for (i = 0; i < 13; i++) { /* channel 1 -- 13 */ |
924 | range->freq[k].i = i + 1; /* List index */ | |
13a9930d WS |
925 | range->freq[k].m = frequency_list[i] * 100000; |
926 | range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ | |
927 | } | |
928 | range->num_frequency = k; | |
e83cfca1 SP |
929 | if (priv->reg.phy_type == D_11B_ONLY_MODE || |
930 | priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */ | |
1df65547 | 931 | range->freq[13].i = 14; /* List index */ |
13a9930d WS |
932 | range->freq[13].m = frequency_list[13] * 100000; |
933 | range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ | |
934 | range->num_frequency = 14; | |
935 | } | |
936 | ||
937 | /* Hum... Should put the right values there */ | |
938 | range->max_qual.qual = 100; | |
939 | range->max_qual.level = 256 - 128; /* 0 dBm? */ | |
940 | range->max_qual.noise = 256 - 128; | |
1df65547 | 941 | range->sensitivity = 1; |
13a9930d | 942 | |
1df65547 | 943 | if (priv->reg.phy_type == D_11B_ONLY_MODE) { |
13a9930d WS |
944 | range->bitrate[0] = 1e6; |
945 | range->bitrate[1] = 2e6; | |
946 | range->bitrate[2] = 5.5e6; | |
947 | range->bitrate[3] = 11e6; | |
948 | range->num_bitrates = 4; | |
1df65547 | 949 | } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */ |
13a9930d WS |
950 | range->bitrate[0] = 1e6; |
951 | range->bitrate[1] = 2e6; | |
952 | range->bitrate[2] = 5.5e6; | |
953 | range->bitrate[3] = 11e6; | |
954 | ||
955 | range->bitrate[4] = 6e6; | |
956 | range->bitrate[5] = 9e6; | |
957 | range->bitrate[6] = 12e6; | |
1df65547 | 958 | if (IW_MAX_BITRATES < 9) { |
13a9930d WS |
959 | range->bitrate[7] = 54e6; |
960 | range->num_bitrates = 8; | |
1df65547 | 961 | } else { |
13a9930d WS |
962 | range->bitrate[7] = 18e6; |
963 | range->bitrate[8] = 24e6; | |
964 | range->bitrate[9] = 36e6; | |
965 | range->bitrate[10] = 48e6; | |
966 | range->bitrate[11] = 54e6; | |
967 | ||
968 | range->num_bitrates = 12; | |
969 | } | |
970 | } | |
971 | ||
972 | /* Set an indication of the max TCP throughput | |
973 | * in bit/s that we can expect using this interface. | |
64068bc3 TH |
974 | * May be use for QoS stuff... Jean II |
975 | */ | |
1df65547 | 976 | if (i > 2) |
13a9930d WS |
977 | range->throughput = 5000 * 1000; |
978 | else | |
979 | range->throughput = 1500 * 1000; | |
980 | ||
981 | range->min_rts = 0; | |
982 | range->max_rts = 2347; | |
983 | range->min_frag = 256; | |
984 | range->max_frag = 2346; | |
985 | ||
1df65547 WS |
986 | range->encoding_size[0] = 5; /* WEP: RC4 40 bits */ |
987 | range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */ | |
988 | range->num_encoding_sizes = 2; | |
13a9930d WS |
989 | range->max_encoding_tokens = 4; |
990 | ||
991 | /* power management not support */ | |
992 | range->pmp_flags = IW_POWER_ON; | |
993 | range->pmt_flags = IW_POWER_ON; | |
994 | range->pm_capa = 0; | |
995 | ||
996 | /* Transmit Power - values are in dBm( or mW) */ | |
1df65547 | 997 | range->txpower[0] = -256; |
13a9930d WS |
998 | range->num_txpower = 1; |
999 | range->txpower_capa = IW_TXPOW_DBM; | |
1000 | /* range->txpower_capa = IW_TXPOW_MWATT; */ | |
1001 | ||
1002 | range->we_version_source = 21; | |
1003 | range->we_version_compiled = WIRELESS_EXT; | |
1004 | ||
1005 | range->retry_capa = IW_RETRY_ON; | |
1df65547 WS |
1006 | range->retry_flags = IW_RETRY_ON; |
1007 | range->r_time_flags = IW_RETRY_ON; | |
13a9930d | 1008 | |
64068bc3 TH |
1009 | /* Experimental measurements - boundary 11/5.5 Mb/s |
1010 | * | |
1011 | * Note : with or without the (local->rssi), results | |
1012 | * are somewhat different. - Jean II | |
1013 | */ | |
13a9930d WS |
1014 | range->avg_qual.qual = 50; |
1015 | range->avg_qual.level = 186; /* -70 dBm */ | |
1016 | range->avg_qual.noise = 0; | |
1017 | ||
13a9930d WS |
1018 | /* Event capability (kernel + driver) */ |
1019 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | |
1020 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | | |
1021 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); | |
1022 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
1023 | range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) | | |
1024 | IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE)); | |
1025 | ||
1026 | /* encode extension (WPA) capability */ | |
1df65547 | 1027 | range->enc_capa = (IW_ENC_CAPA_WPA | |
13a9930d | 1028 | IW_ENC_CAPA_WPA2 | |
1df65547 | 1029 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP); |
13a9930d WS |
1030 | return 0; |
1031 | } | |
1032 | ||
1df65547 WS |
1033 | static int ks_wlan_set_power(struct net_device *dev, |
1034 | struct iw_request_info *info, | |
18e76e23 | 1035 | union iwreq_data *vwrq, char *extra) |
13a9930d | 1036 | { |
2b0d92b2 | 1037 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1038 | |
6b750fac | 1039 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1040 | return -EPERM; |
6b750fac | 1041 | |
18e76e23 | 1042 | if (vwrq->power.disabled) { |
8fb8e05c | 1043 | priv->reg.power_mgmt = POWER_MGMT_ACTIVE; |
dc59ef2a | 1044 | } else { |
f3b0bd23 | 1045 | if (priv->reg.operation_mode != MODE_INFRASTRUCTURE) |
1df65547 | 1046 | return -EINVAL; |
f3b0bd23 | 1047 | priv->reg.power_mgmt = POWER_MGMT_SAVE1; |
8f4d00cd | 1048 | } |
13a9930d WS |
1049 | |
1050 | hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST); | |
1051 | ||
1052 | return 0; | |
1053 | } | |
1054 | ||
1df65547 WS |
1055 | static int ks_wlan_get_power(struct net_device *dev, |
1056 | struct iw_request_info *info, | |
18e76e23 | 1057 | union iwreq_data *vwrq, char *extra) |
13a9930d | 1058 | { |
2b0d92b2 | 1059 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1060 | |
e0d64815 | 1061 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1062 | return -EPERM; |
1df65547 | 1063 | /* for SLEEP MODE */ |
1df964ac | 1064 | vwrq->power.disabled = (priv->reg.power_mgmt <= 0); |
13a9930d WS |
1065 | |
1066 | return 0; | |
1067 | } | |
1068 | ||
1df65547 WS |
1069 | static int ks_wlan_get_iwstats(struct net_device *dev, |
1070 | struct iw_request_info *info, | |
18e76e23 | 1071 | union iwreq_data *vwrq, char *extra) |
13a9930d | 1072 | { |
2b0d92b2 | 1073 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1074 | |
e0d64815 | 1075 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1076 | return -EPERM; |
1df65547 | 1077 | /* for SLEEP MODE */ |
18e76e23 SP |
1078 | vwrq->qual.qual = 0; /* not supported */ |
1079 | vwrq->qual.level = priv->wstats.qual.level; | |
1080 | vwrq->qual.noise = 0; /* not supported */ | |
1081 | vwrq->qual.updated = 0; | |
13a9930d WS |
1082 | |
1083 | return 0; | |
1084 | } | |
1085 | ||
13a9930d | 1086 | /* Note : this is deprecated in favor of IWSCAN */ |
1df65547 WS |
1087 | static int ks_wlan_get_aplist(struct net_device *dev, |
1088 | struct iw_request_info *info, | |
18e76e23 | 1089 | union iwreq_data *dwrq, char *extra) |
13a9930d | 1090 | { |
2b0d92b2 | 1091 | struct ks_wlan_private *priv = netdev_priv(dev); |
1df65547 | 1092 | struct sockaddr *address = (struct sockaddr *)extra; |
13a9930d | 1093 | struct iw_quality qual[LOCAL_APLIST_MAX]; |
13a9930d WS |
1094 | int i; |
1095 | ||
e0d64815 | 1096 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1097 | return -EPERM; |
1df65547 | 1098 | /* for SLEEP MODE */ |
13a9930d | 1099 | for (i = 0; i < priv->aplist.size; i++) { |
77b948df | 1100 | ether_addr_copy(address[i].sa_data, priv->aplist.ap[i].bssid); |
13a9930d WS |
1101 | address[i].sa_family = ARPHRD_ETHER; |
1102 | qual[i].level = 256 - priv->aplist.ap[i].rssi; | |
1103 | qual[i].qual = priv->aplist.ap[i].sq; | |
1df65547 | 1104 | qual[i].noise = 0; /* invalid noise value */ |
13a9930d WS |
1105 | qual[i].updated = 7; |
1106 | } | |
1df65547 | 1107 | if (i) { |
18e76e23 | 1108 | dwrq->data.flags = 1; /* Should be define'd */ |
1df65547 WS |
1109 | memcpy(extra + sizeof(struct sockaddr) * i, |
1110 | &qual, sizeof(struct iw_quality) * i); | |
13a9930d | 1111 | } |
18e76e23 | 1112 | dwrq->data.length = i; |
13a9930d WS |
1113 | |
1114 | return 0; | |
1115 | } | |
1116 | ||
1df65547 WS |
1117 | static int ks_wlan_set_scan(struct net_device *dev, |
1118 | struct iw_request_info *info, | |
1119 | union iwreq_data *wrqu, char *extra) | |
13a9930d | 1120 | { |
2b0d92b2 | 1121 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1122 | struct iw_scan_req *req = NULL; |
fe497530 | 1123 | |
e0d64815 | 1124 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1125 | return -EPERM; |
13a9930d | 1126 | |
1df65547 | 1127 | /* for SLEEP MODE */ |
13a9930d | 1128 | /* specified SSID SCAN */ |
a359491a TH |
1129 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
1130 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
1df65547 | 1131 | req = (struct iw_scan_req *)extra; |
13a9930d WS |
1132 | priv->scan_ssid_len = req->essid_len; |
1133 | memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len); | |
1df65547 | 1134 | } else { |
13a9930d WS |
1135 | priv->scan_ssid_len = 0; |
1136 | } | |
1137 | ||
13a9930d WS |
1138 | priv->sme_i.sme_flag |= SME_AP_SCAN; |
1139 | hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST); | |
1140 | ||
1141 | /* At this point, just return to the user. */ | |
1142 | ||
1143 | return 0; | |
1144 | } | |
1145 | ||
bcb53e8a SP |
1146 | static char *ks_wlan_add_leader_event(const char *rsn_leader, char *end_buf, |
1147 | char *current_ev, struct rsn_ie *rsn, | |
1148 | struct iw_event *iwe, | |
1149 | struct iw_request_info *info) | |
1150 | { | |
1151 | char buffer[RSN_IE_BODY_MAX * 2 + 30]; | |
1152 | char *pbuf; | |
1153 | int i; | |
1154 | ||
1155 | pbuf = &buffer[0]; | |
1156 | memset(iwe, 0, sizeof(*iwe)); | |
1157 | iwe->cmd = IWEVCUSTOM; | |
1158 | memcpy(buffer, rsn_leader, sizeof(rsn_leader) - 1); | |
1159 | iwe->u.data.length += sizeof(rsn_leader) - 1; | |
1160 | pbuf += sizeof(rsn_leader) - 1; | |
1161 | pbuf += sprintf(pbuf, "%02x", rsn->id); | |
1162 | pbuf += sprintf(pbuf, "%02x", rsn->size); | |
1163 | iwe->u.data.length += 4; | |
1164 | ||
1165 | for (i = 0; i < rsn->size; i++) | |
1166 | pbuf += sprintf(pbuf, "%02x", rsn->body[i]); | |
1167 | ||
1168 | iwe->u.data.length += rsn->size * 2; | |
1169 | ||
1170 | return iwe_stream_add_point(info, current_ev, end_buf, iwe, &buffer[0]); | |
1171 | } | |
1172 | ||
13a9930d WS |
1173 | /* |
1174 | * Translate scan data returned from the card to a card independent | |
1175 | * format that the Wireless Tools will understand - Jean II | |
1176 | */ | |
1df65547 WS |
1177 | static inline char *ks_wlan_translate_scan(struct net_device *dev, |
1178 | struct iw_request_info *info, | |
1179 | char *current_ev, char *end_buf, | |
01d391d4 | 1180 | struct local_ap *ap) |
13a9930d | 1181 | { |
feedcf1a | 1182 | /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */ |
bcb53e8a SP |
1183 | static const char rsn_leader[] = "rsn_ie="; |
1184 | static const char wpa_leader[] = "wpa_ie="; | |
1df65547 | 1185 | struct iw_event iwe; /* Temporary buffer */ |
13a9930d WS |
1186 | u16 capabilities; |
1187 | char *current_val; /* For rates */ | |
1188 | int i; | |
bcb53e8a | 1189 | |
13a9930d WS |
1190 | /* First entry *MUST* be the AP MAC address */ |
1191 | iwe.cmd = SIOCGIWAP; | |
1192 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
bcb53e8a SP |
1193 | ether_addr_copy(iwe.u.ap_addr.sa_data, ap->bssid); |
1194 | current_ev = iwe_stream_add_event(info, current_ev, | |
1195 | end_buf, &iwe, IW_EV_ADDR_LEN); | |
13a9930d WS |
1196 | |
1197 | /* Other entries will be displayed in the order we give them */ | |
1198 | ||
1199 | /* Add the ESSID */ | |
1200 | iwe.u.data.length = ap->ssid.size; | |
1df65547 | 1201 | if (iwe.u.data.length > 32) |
13a9930d WS |
1202 | iwe.u.data.length = 32; |
1203 | iwe.cmd = SIOCGIWESSID; | |
1204 | iwe.u.data.flags = 1; | |
bcb53e8a SP |
1205 | current_ev = iwe_stream_add_point(info, current_ev, |
1206 | end_buf, &iwe, ap->ssid.body); | |
13a9930d WS |
1207 | |
1208 | /* Add mode */ | |
1209 | iwe.cmd = SIOCGIWMODE; | |
7b379dba | 1210 | capabilities = ap->capability; |
c468d584 | 1211 | if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { |
bcb53e8a SP |
1212 | iwe.u.mode = (capabilities & WLAN_CAPABILITY_ESS) ? |
1213 | IW_MODE_INFRA : IW_MODE_ADHOC; | |
1214 | current_ev = iwe_stream_add_event(info, current_ev, | |
1215 | end_buf, &iwe, IW_EV_UINT_LEN); | |
13a9930d WS |
1216 | } |
1217 | ||
1218 | /* Add frequency */ | |
1219 | iwe.cmd = SIOCGIWFREQ; | |
1220 | iwe.u.freq.m = ap->channel; | |
1df65547 | 1221 | iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000; |
13a9930d | 1222 | iwe.u.freq.e = 1; |
bcb53e8a SP |
1223 | current_ev = iwe_stream_add_event(info, current_ev, |
1224 | end_buf, &iwe, IW_EV_FREQ_LEN); | |
13a9930d WS |
1225 | |
1226 | /* Add quality statistics */ | |
1227 | iwe.cmd = IWEVQUAL; | |
1228 | iwe.u.qual.level = 256 - ap->rssi; | |
1229 | iwe.u.qual.qual = ap->sq; | |
1df65547 | 1230 | iwe.u.qual.noise = 0; /* invalid noise value */ |
bcb53e8a SP |
1231 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
1232 | &iwe, IW_EV_QUAL_LEN); | |
13a9930d WS |
1233 | |
1234 | /* Add encryption capability */ | |
1235 | iwe.cmd = SIOCGIWENCODE; | |
bcb53e8a SP |
1236 | iwe.u.data.flags = (capabilities & WLAN_CAPABILITY_PRIVACY) ? |
1237 | (IW_ENCODE_ENABLED | IW_ENCODE_NOKEY) : | |
1238 | IW_ENCODE_DISABLED; | |
13a9930d | 1239 | iwe.u.data.length = 0; |
bcb53e8a SP |
1240 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
1241 | &iwe, ap->ssid.body); | |
13a9930d | 1242 | |
bcb53e8a SP |
1243 | /* |
1244 | * Rate : stuffing multiple values in a single event | |
1245 | * require a bit more of magic - Jean II | |
64068bc3 | 1246 | */ |
13a9930d WS |
1247 | current_val = current_ev + IW_EV_LCP_LEN; |
1248 | ||
1249 | iwe.cmd = SIOCGIWRATE; | |
e00b9bb3 TH |
1250 | |
1251 | /* These two flags are ignored... */ | |
1252 | iwe.u.bitrate.fixed = 0; | |
1253 | iwe.u.bitrate.disabled = 0; | |
13a9930d WS |
1254 | |
1255 | /* Max 16 values */ | |
1df65547 | 1256 | for (i = 0; i < 16; i++) { |
13a9930d | 1257 | /* NULL terminated */ |
1df65547 | 1258 | if (i >= ap->rate_set.size) |
13a9930d WS |
1259 | break; |
1260 | /* Bit rate given in 500 kb/s units (+ 0x80) */ | |
1261 | iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000); | |
1262 | /* Add new value to event */ | |
bcb53e8a SP |
1263 | current_val = iwe_stream_add_value(info, current_ev, |
1264 | current_val, end_buf, &iwe, | |
1265 | IW_EV_PARAM_LEN); | |
13a9930d WS |
1266 | } |
1267 | /* Check if we added any event */ | |
1df65547 | 1268 | if ((current_val - current_ev) > IW_EV_LCP_LEN) |
13a9930d WS |
1269 | current_ev = current_val; |
1270 | ||
bcb53e8a SP |
1271 | if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) |
1272 | current_ev = ks_wlan_add_leader_event(rsn_leader, end_buf, | |
1273 | current_ev, &ap->rsn_ie, | |
1274 | &iwe, info); | |
1275 | ||
1c800aab | 1276 | if (ap->wpa_ie.id == WPA_INFO_ELEM_ID && ap->wpa_ie.size != 0) |
bcb53e8a SP |
1277 | current_ev = ks_wlan_add_leader_event(wpa_leader, end_buf, |
1278 | current_ev, &ap->wpa_ie, | |
1279 | &iwe, info); | |
1280 | ||
1281 | /* | |
1282 | * The other data in the scan result are not really | |
64068bc3 TH |
1283 | * interesting, so for now drop it - Jean II |
1284 | */ | |
13a9930d WS |
1285 | return current_ev; |
1286 | } | |
1287 | ||
1df65547 | 1288 | static int ks_wlan_get_scan(struct net_device *dev, |
18e76e23 SP |
1289 | struct iw_request_info *info, |
1290 | union iwreq_data *dwrq, char *extra) | |
13a9930d | 1291 | { |
2b0d92b2 | 1292 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
1293 | int i; |
1294 | char *current_ev = extra; | |
fe497530 | 1295 | |
e0d64815 | 1296 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1297 | return -EPERM; |
1df65547 | 1298 | /* for SLEEP MODE */ |
7acf4002 | 1299 | if (priv->sme_i.sme_flag & SME_AP_SCAN) |
13a9930d | 1300 | return -EAGAIN; |
13a9930d | 1301 | |
310e916f | 1302 | if (priv->aplist.size == 0) { |
13a9930d | 1303 | /* Client error, no scan results... |
64068bc3 TH |
1304 | * The caller need to restart the scan. |
1305 | */ | |
13a9930d WS |
1306 | return -ENODATA; |
1307 | } | |
6cdd6538 | 1308 | |
13a9930d | 1309 | /* Read and parse all entries */ |
1df65547 | 1310 | for (i = 0; i < priv->aplist.size; i++) { |
18e76e23 SP |
1311 | if ((extra + dwrq->data.length) - current_ev <= IW_EV_ADDR_LEN) { |
1312 | dwrq->data.length = 0; | |
13a9930d WS |
1313 | return -E2BIG; |
1314 | } | |
1315 | /* Translate to WE format this entry */ | |
1316 | current_ev = ks_wlan_translate_scan(dev, info, current_ev, | |
18e76e23 | 1317 | extra + dwrq->data.length, |
be046617 | 1318 | &priv->aplist.ap[i]); |
13a9930d WS |
1319 | } |
1320 | /* Length of data */ | |
18e76e23 SP |
1321 | dwrq->data.length = (current_ev - extra); |
1322 | dwrq->data.flags = 0; | |
13a9930d WS |
1323 | |
1324 | return 0; | |
1325 | } | |
13a9930d | 1326 | |
f160bc20 | 1327 | /* called after a bunch of SET operations */ |
1df65547 | 1328 | static int ks_wlan_config_commit(struct net_device *dev, |
18e76e23 SP |
1329 | struct iw_request_info *info, |
1330 | union iwreq_data *zwrq, | |
1df65547 | 1331 | char *extra) |
13a9930d | 1332 | { |
2b0d92b2 | 1333 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
1334 | |
1335 | if (!priv->need_commit) | |
1336 | return 0; | |
1337 | ||
1338 | ks_wlan_setup_parameter(priv, priv->need_commit); | |
1df65547 | 1339 | priv->need_commit = 0; |
13a9930d WS |
1340 | return 0; |
1341 | } | |
1342 | ||
f160bc20 | 1343 | /* set association ie params */ |
1df65547 WS |
1344 | static int ks_wlan_set_genie(struct net_device *dev, |
1345 | struct iw_request_info *info, | |
18e76e23 | 1346 | union iwreq_data *dwrq, char *extra) |
13a9930d | 1347 | { |
2b0d92b2 | 1348 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1349 | |
e0d64815 | 1350 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1351 | return -EPERM; |
1df65547 | 1352 | /* for SLEEP MODE */ |
13a9930d | 1353 | return 0; |
1df65547 | 1354 | // return -EOPNOTSUPP; |
13a9930d WS |
1355 | } |
1356 | ||
1df65547 WS |
1357 | static int ks_wlan_set_auth_mode(struct net_device *dev, |
1358 | struct iw_request_info *info, | |
18e76e23 | 1359 | union iwreq_data *vwrq, char *extra) |
13a9930d | 1360 | { |
2b0d92b2 | 1361 | struct ks_wlan_private *priv = netdev_priv(dev); |
18e76e23 SP |
1362 | struct iw_param *param = &vwrq->param; |
1363 | int index = (param->flags & IW_AUTH_INDEX); | |
1364 | int value = param->value; | |
13a9930d | 1365 | |
e0d64815 | 1366 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1367 | return -EPERM; |
1df65547 WS |
1368 | /* for SLEEP MODE */ |
1369 | switch (index) { | |
1370 | case IW_AUTH_WPA_VERSION: /* 0 */ | |
1371 | switch (value) { | |
13a9930d WS |
1372 | case IW_AUTH_WPA_VERSION_DISABLED: |
1373 | priv->wpa.version = value; | |
e0d64815 | 1374 | if (priv->wpa.rsn_enabled) |
d96f3a7c | 1375 | priv->wpa.rsn_enabled = false; |
13a9930d WS |
1376 | priv->need_commit |= SME_RSN; |
1377 | break; | |
1378 | case IW_AUTH_WPA_VERSION_WPA: | |
1379 | case IW_AUTH_WPA_VERSION_WPA2: | |
1380 | priv->wpa.version = value; | |
e0d64815 | 1381 | if (!(priv->wpa.rsn_enabled)) |
d96f3a7c | 1382 | priv->wpa.rsn_enabled = true; |
13a9930d WS |
1383 | priv->need_commit |= SME_RSN; |
1384 | break; | |
1385 | default: | |
1386 | return -EOPNOTSUPP; | |
1387 | } | |
1388 | break; | |
1df65547 WS |
1389 | case IW_AUTH_CIPHER_PAIRWISE: /* 1 */ |
1390 | switch (value) { | |
13a9930d | 1391 | case IW_AUTH_CIPHER_NONE: |
1df65547 | 1392 | if (priv->reg.privacy_invoked) { |
13a9930d WS |
1393 | priv->reg.privacy_invoked = 0x00; |
1394 | priv->need_commit |= SME_WEP_FLAG; | |
1395 | } | |
1396 | break; | |
1397 | case IW_AUTH_CIPHER_WEP40: | |
1398 | case IW_AUTH_CIPHER_TKIP: | |
1399 | case IW_AUTH_CIPHER_CCMP: | |
1400 | case IW_AUTH_CIPHER_WEP104: | |
1df65547 | 1401 | if (!priv->reg.privacy_invoked) { |
13a9930d WS |
1402 | priv->reg.privacy_invoked = 0x01; |
1403 | priv->need_commit |= SME_WEP_FLAG; | |
1404 | } | |
1405 | priv->wpa.pairwise_suite = value; | |
1406 | priv->need_commit |= SME_RSN_UNICAST; | |
1407 | break; | |
1408 | default: | |
1409 | return -EOPNOTSUPP; | |
1410 | } | |
1411 | break; | |
1df65547 WS |
1412 | case IW_AUTH_CIPHER_GROUP: /* 2 */ |
1413 | switch (value) { | |
13a9930d | 1414 | case IW_AUTH_CIPHER_NONE: |
1df65547 | 1415 | if (priv->reg.privacy_invoked) { |
13a9930d WS |
1416 | priv->reg.privacy_invoked = 0x00; |
1417 | priv->need_commit |= SME_WEP_FLAG; | |
1418 | } | |
1419 | break; | |
1420 | case IW_AUTH_CIPHER_WEP40: | |
1421 | case IW_AUTH_CIPHER_TKIP: | |
1422 | case IW_AUTH_CIPHER_CCMP: | |
1423 | case IW_AUTH_CIPHER_WEP104: | |
1df65547 | 1424 | if (!priv->reg.privacy_invoked) { |
13a9930d WS |
1425 | priv->reg.privacy_invoked = 0x01; |
1426 | priv->need_commit |= SME_WEP_FLAG; | |
1427 | } | |
1428 | priv->wpa.group_suite = value; | |
1429 | priv->need_commit |= SME_RSN_MULTICAST; | |
1430 | break; | |
1431 | default: | |
1432 | return -EOPNOTSUPP; | |
1433 | } | |
1434 | break; | |
1df65547 WS |
1435 | case IW_AUTH_KEY_MGMT: /* 3 */ |
1436 | switch (value) { | |
13a9930d WS |
1437 | case IW_AUTH_KEY_MGMT_802_1X: |
1438 | case IW_AUTH_KEY_MGMT_PSK: | |
1df65547 WS |
1439 | case 0: /* NONE or 802_1X_NO_WPA */ |
1440 | case 4: /* WPA_NONE */ | |
13a9930d WS |
1441 | priv->wpa.key_mgmt_suite = value; |
1442 | priv->need_commit |= SME_RSN_AUTH; | |
1443 | break; | |
1444 | default: | |
1445 | return -EOPNOTSUPP; | |
1446 | } | |
1447 | break; | |
1df65547 WS |
1448 | case IW_AUTH_80211_AUTH_ALG: /* 6 */ |
1449 | switch (value) { | |
13a9930d WS |
1450 | case IW_AUTH_ALG_OPEN_SYSTEM: |
1451 | priv->wpa.auth_alg = value; | |
1452 | priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; | |
1453 | break; | |
1454 | case IW_AUTH_ALG_SHARED_KEY: | |
1455 | priv->wpa.auth_alg = value; | |
1456 | priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY; | |
1457 | break; | |
1458 | case IW_AUTH_ALG_LEAP: | |
1459 | default: | |
1460 | return -EOPNOTSUPP; | |
1461 | } | |
1462 | priv->need_commit |= SME_MODE_SET; | |
1463 | break; | |
1df65547 | 1464 | case IW_AUTH_WPA_ENABLED: /* 7 */ |
13a9930d WS |
1465 | priv->wpa.wpa_enabled = value; |
1466 | break; | |
1df65547 WS |
1467 | case IW_AUTH_PRIVACY_INVOKED: /* 10 */ |
1468 | if ((value && !priv->reg.privacy_invoked) || | |
1469 | (!value && priv->reg.privacy_invoked)) { | |
1470 | priv->reg.privacy_invoked = value ? 0x01 : 0x00; | |
13a9930d WS |
1471 | priv->need_commit |= SME_WEP_FLAG; |
1472 | } | |
1473 | break; | |
1df65547 WS |
1474 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */ |
1475 | case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */ | |
1476 | case IW_AUTH_DROP_UNENCRYPTED: /* 8 */ | |
1477 | case IW_AUTH_ROAMING_CONTROL: /* 9 */ | |
13a9930d WS |
1478 | default: |
1479 | break; | |
1480 | } | |
1481 | ||
1482 | /* return -EINPROGRESS; */ | |
1df65547 | 1483 | if (priv->need_commit) { |
13a9930d | 1484 | ks_wlan_setup_parameter(priv, priv->need_commit); |
1df65547 | 1485 | priv->need_commit = 0; |
13a9930d WS |
1486 | } |
1487 | return 0; | |
1488 | } | |
1489 | ||
1df65547 WS |
1490 | static int ks_wlan_get_auth_mode(struct net_device *dev, |
1491 | struct iw_request_info *info, | |
18e76e23 | 1492 | union iwreq_data *vwrq, char *extra) |
13a9930d | 1493 | { |
2b0d92b2 | 1494 | struct ks_wlan_private *priv = netdev_priv(dev); |
18e76e23 SP |
1495 | struct iw_param *param = &vwrq->param; |
1496 | int index = (param->flags & IW_AUTH_INDEX); | |
fe497530 | 1497 | |
e0d64815 | 1498 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1499 | return -EPERM; |
13a9930d | 1500 | |
1df65547 | 1501 | /* for SLEEP MODE */ |
13a9930d | 1502 | /* WPA (not used ?? wpa_supplicant) */ |
1df65547 | 1503 | switch (index) { |
13a9930d | 1504 | case IW_AUTH_WPA_VERSION: |
18e76e23 | 1505 | param->value = priv->wpa.version; |
13a9930d WS |
1506 | break; |
1507 | case IW_AUTH_CIPHER_PAIRWISE: | |
18e76e23 | 1508 | param->value = priv->wpa.pairwise_suite; |
13a9930d WS |
1509 | break; |
1510 | case IW_AUTH_CIPHER_GROUP: | |
18e76e23 | 1511 | param->value = priv->wpa.group_suite; |
13a9930d WS |
1512 | break; |
1513 | case IW_AUTH_KEY_MGMT: | |
18e76e23 | 1514 | param->value = priv->wpa.key_mgmt_suite; |
13a9930d WS |
1515 | break; |
1516 | case IW_AUTH_80211_AUTH_ALG: | |
18e76e23 | 1517 | param->value = priv->wpa.auth_alg; |
13a9930d WS |
1518 | break; |
1519 | case IW_AUTH_WPA_ENABLED: | |
18e76e23 | 1520 | param->value = priv->wpa.rsn_enabled; |
13a9930d | 1521 | break; |
1df65547 | 1522 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */ |
13a9930d WS |
1523 | case IW_AUTH_TKIP_COUNTERMEASURES: |
1524 | case IW_AUTH_DROP_UNENCRYPTED: | |
1525 | default: | |
1526 | /* return -EOPNOTSUPP; */ | |
1527 | break; | |
1528 | } | |
1529 | return 0; | |
1530 | } | |
1531 | ||
f160bc20 | 1532 | /* set encoding token & mode (WPA)*/ |
1df65547 WS |
1533 | static int ks_wlan_set_encode_ext(struct net_device *dev, |
1534 | struct iw_request_info *info, | |
18e76e23 | 1535 | union iwreq_data *dwrq, char *extra) |
13a9930d | 1536 | { |
2b0d92b2 | 1537 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1538 | struct iw_encode_ext *enc; |
18e76e23 | 1539 | int index = dwrq->encoding.flags & IW_ENCODE_INDEX; |
1df65547 | 1540 | unsigned int commit = 0; |
8b76eb09 | 1541 | struct wpa_key *key; |
13a9930d WS |
1542 | |
1543 | enc = (struct iw_encode_ext *)extra; | |
9ff19a6e TH |
1544 | if (!enc) |
1545 | return -EINVAL; | |
13a9930d | 1546 | |
e0d64815 | 1547 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1548 | return -EPERM; |
e0d64815 | 1549 | |
1df65547 WS |
1550 | /* for SLEEP MODE */ |
1551 | if (index < 1 || index > 4) | |
13a9930d | 1552 | return -EINVAL; |
44dc9c86 | 1553 | index--; |
b121d848 | 1554 | key = &priv->wpa.key[index]; |
13a9930d | 1555 | |
18e76e23 | 1556 | if (dwrq->encoding.flags & IW_ENCODE_DISABLED) |
3da1b237 | 1557 | key->key_len = 0; |
13a9930d | 1558 | |
3da1b237 | 1559 | key->ext_flags = enc->ext_flags; |
f0a4c596 TH |
1560 | if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { |
1561 | priv->wpa.txkey = index; | |
1562 | commit |= SME_WEP_INDEX; | |
1563 | } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { | |
b121d848 | 1564 | memcpy(&key->rx_seq[0], &enc->rx_seq[0], IW_ENCODE_SEQ_MAX_SIZE); |
f0a4c596 | 1565 | } |
13a9930d | 1566 | |
b8cbbc12 | 1567 | ether_addr_copy(&key->addr.sa_data[0], &enc->addr.sa_data[0]); |
13a9930d | 1568 | |
f0a4c596 TH |
1569 | switch (enc->alg) { |
1570 | case IW_ENCODE_ALG_NONE: | |
1571 | if (priv->reg.privacy_invoked) { | |
1572 | priv->reg.privacy_invoked = 0x00; | |
1573 | commit |= SME_WEP_FLAG; | |
1574 | } | |
3da1b237 | 1575 | key->key_len = 0; |
f0a4c596 TH |
1576 | |
1577 | break; | |
1578 | case IW_ENCODE_ALG_WEP: | |
1579 | case IW_ENCODE_ALG_CCMP: | |
1580 | if (!priv->reg.privacy_invoked) { | |
1581 | priv->reg.privacy_invoked = 0x01; | |
1582 | commit |= SME_WEP_FLAG; | |
1583 | } | |
1584 | if (enc->key_len) { | |
b121d848 TH |
1585 | memcpy(&key->key_val[0], &enc->key[0], enc->key_len); |
1586 | key->key_len = enc->key_len; | |
f0a4c596 TH |
1587 | commit |= (SME_WEP_VAL1 << index); |
1588 | } | |
1589 | break; | |
1590 | case IW_ENCODE_ALG_TKIP: | |
1591 | if (!priv->reg.privacy_invoked) { | |
1592 | priv->reg.privacy_invoked = 0x01; | |
1593 | commit |= SME_WEP_FLAG; | |
1594 | } | |
1595 | if (enc->key_len == 32) { | |
b121d848 TH |
1596 | memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16); |
1597 | key->key_len = enc->key_len - 16; | |
f0a4c596 | 1598 | if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */ |
b121d848 TH |
1599 | memcpy(&key->tx_mic_key[0], &enc->key[16], 8); |
1600 | memcpy(&key->rx_mic_key[0], &enc->key[16], 8); | |
f0a4c596 | 1601 | } else { |
b121d848 TH |
1602 | memcpy(&key->tx_mic_key[0], &enc->key[16], 8); |
1603 | memcpy(&key->rx_mic_key[0], &enc->key[24], 8); | |
13a9930d | 1604 | } |
f0a4c596 | 1605 | commit |= (SME_WEP_VAL1 << index); |
13a9930d | 1606 | } |
f0a4c596 TH |
1607 | break; |
1608 | default: | |
13a9930d | 1609 | return -EINVAL; |
8f4d00cd | 1610 | } |
3da1b237 | 1611 | key->alg = enc->alg; |
13a9930d | 1612 | |
1df65547 WS |
1613 | if (commit) { |
1614 | if (commit & SME_WEP_INDEX) | |
13a9930d | 1615 | hostif_sme_enqueue(priv, SME_SET_TXKEY); |
1df65547 WS |
1616 | if (commit & SME_WEP_VAL_MASK) |
1617 | hostif_sme_enqueue(priv, SME_SET_KEY1 + index); | |
1618 | if (commit & SME_WEP_FLAG) | |
13a9930d WS |
1619 | hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST); |
1620 | } | |
1621 | ||
1622 | return 0; | |
1623 | } | |
1624 | ||
f160bc20 | 1625 | /* get encoding token & mode (WPA)*/ |
1df65547 WS |
1626 | static int ks_wlan_get_encode_ext(struct net_device *dev, |
1627 | struct iw_request_info *info, | |
18e76e23 | 1628 | union iwreq_data *dwrq, char *extra) |
13a9930d | 1629 | { |
2b0d92b2 | 1630 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1631 | |
e0d64815 | 1632 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1633 | return -EPERM; |
13a9930d | 1634 | |
1df65547 | 1635 | /* for SLEEP MODE */ |
64068bc3 TH |
1636 | /* WPA (not used ?? wpa_supplicant) |
1637 | * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; | |
1638 | * struct iw_encode_ext *enc; | |
1639 | * enc = (struct iw_encode_ext *)extra; | |
1640 | * int index = dwrq->flags & IW_ENCODE_INDEX; | |
1641 | * WPA (not used ?? wpa_supplicant) | |
1642 | */ | |
13a9930d WS |
1643 | return 0; |
1644 | } | |
1645 | ||
1df65547 WS |
1646 | static int ks_wlan_set_pmksa(struct net_device *dev, |
1647 | struct iw_request_info *info, | |
18e76e23 | 1648 | union iwreq_data *dwrq, char *extra) |
13a9930d | 1649 | { |
2b0d92b2 | 1650 | struct ks_wlan_private *priv = netdev_priv(dev); |
1df65547 | 1651 | struct iw_pmksa *pmksa; |
13a9930d | 1652 | int i; |
b7402474 | 1653 | struct pmk *pmk; |
13a9930d WS |
1654 | struct list_head *ptr; |
1655 | ||
e0d64815 | 1656 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1657 | return -EPERM; |
e0d64815 | 1658 | |
1df65547 | 1659 | /* for SLEEP MODE */ |
e0d64815 | 1660 | if (!extra) |
13a9930d | 1661 | return -EINVAL; |
e0d64815 | 1662 | |
13a9930d | 1663 | pmksa = (struct iw_pmksa *)extra; |
13a9930d | 1664 | |
1df65547 | 1665 | switch (pmksa->cmd) { |
13a9930d | 1666 | case IW_PMKSA_ADD: |
092f239e | 1667 | if (list_empty(&priv->pmklist.head)) { |
1df65547 | 1668 | for (i = 0; i < PMK_LIST_MAX; i++) { |
13a9930d | 1669 | pmk = &priv->pmklist.pmk[i]; |
092f239e SP |
1670 | if (is_zero_ether_addr(pmk->bssid)) |
1671 | break; | |
13a9930d | 1672 | } |
092f239e | 1673 | ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data); |
13a9930d | 1674 | memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); |
1df65547 | 1675 | list_add(&pmk->list, &priv->pmklist.head); |
13a9930d | 1676 | priv->pmklist.size++; |
092f239e | 1677 | break; |
f0a4c596 TH |
1678 | } |
1679 | /* search cache data */ | |
1680 | list_for_each(ptr, &priv->pmklist.head) { | |
b7402474 | 1681 | pmk = list_entry(ptr, struct pmk, list); |
092f239e | 1682 | if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) { |
902f49ca TH |
1683 | memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); |
1684 | list_move(&pmk->list, &priv->pmklist.head); | |
092f239e | 1685 | break; |
13a9930d | 1686 | } |
f0a4c596 | 1687 | } |
092f239e SP |
1688 | /* not find address. */ |
1689 | if (ptr != &priv->pmklist.head) | |
1690 | break; | |
1691 | /* new cache data */ | |
1692 | if (priv->pmklist.size < PMK_LIST_MAX) { | |
f0a4c596 TH |
1693 | for (i = 0; i < PMK_LIST_MAX; i++) { |
1694 | pmk = &priv->pmklist.pmk[i]; | |
092f239e SP |
1695 | if (is_zero_ether_addr(pmk->bssid)) |
1696 | break; | |
13a9930d | 1697 | } |
092f239e | 1698 | ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data); |
902f49ca TH |
1699 | memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); |
1700 | list_add(&pmk->list, &priv->pmklist.head); | |
f0a4c596 | 1701 | priv->pmklist.size++; |
092f239e | 1702 | } else { /* overwrite old cache data */ |
b7402474 | 1703 | pmk = list_entry(priv->pmklist.head.prev, struct pmk, |
902f49ca | 1704 | list); |
092f239e | 1705 | ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data); |
902f49ca TH |
1706 | memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); |
1707 | list_move(&pmk->list, &priv->pmklist.head); | |
13a9930d WS |
1708 | } |
1709 | break; | |
1710 | case IW_PMKSA_REMOVE: | |
092f239e | 1711 | if (list_empty(&priv->pmklist.head)) |
13a9930d | 1712 | return -EINVAL; |
44dc9c86 TH |
1713 | /* search cache data */ |
1714 | list_for_each(ptr, &priv->pmklist.head) { | |
b7402474 | 1715 | pmk = list_entry(ptr, struct pmk, list); |
092f239e | 1716 | if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) { |
44dc9c86 TH |
1717 | eth_zero_addr(pmk->bssid); |
1718 | memset(pmk->pmkid, 0, IW_PMKID_LEN); | |
1719 | list_del_init(&pmk->list); | |
1720 | break; | |
13a9930d WS |
1721 | } |
1722 | } | |
092f239e SP |
1723 | /* not find address. */ |
1724 | if (ptr == &priv->pmklist.head) | |
44dc9c86 | 1725 | return 0; |
13a9930d WS |
1726 | break; |
1727 | case IW_PMKSA_FLUSH: | |
be046617 | 1728 | memset(&priv->pmklist, 0, sizeof(priv->pmklist)); |
13a9930d | 1729 | INIT_LIST_HEAD(&priv->pmklist.head); |
1df65547 | 1730 | for (i = 0; i < PMK_LIST_MAX; i++) |
13a9930d WS |
1731 | INIT_LIST_HEAD(&priv->pmklist.pmk[i].list); |
1732 | break; | |
1733 | default: | |
1734 | return -EINVAL; | |
1735 | } | |
1736 | ||
1737 | hostif_sme_enqueue(priv, SME_SET_PMKSA); | |
1738 | return 0; | |
1739 | } | |
1740 | ||
1741 | static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev) | |
1742 | { | |
2b0d92b2 | 1743 | struct ks_wlan_private *priv = netdev_priv(dev); |
1df65547 | 1744 | struct iw_statistics *wstats = &priv->wstats; |
13a9930d | 1745 | |
203ad5a1 SP |
1746 | if (!atomic_read(&update_phyinfo)) |
1747 | return (priv->dev_state < DEVICE_STATE_READY) ? NULL : wstats; | |
13a9930d | 1748 | |
203ad5a1 SP |
1749 | /* |
1750 | * Packets discarded in the wireless adapter due to wireless | |
64068bc3 TH |
1751 | * specific problems |
1752 | */ | |
1df65547 WS |
1753 | wstats->discard.nwid = 0; /* Rx invalid nwid */ |
1754 | wstats->discard.code = 0; /* Rx invalid crypt */ | |
1755 | wstats->discard.fragment = 0; /* Rx invalid frag */ | |
1756 | wstats->discard.retries = 0; /* Tx excessive retries */ | |
1757 | wstats->discard.misc = 0; /* Invalid misc */ | |
1758 | wstats->miss.beacon = 0; /* Missed beacon */ | |
13a9930d | 1759 | |
1df65547 | 1760 | return wstats; |
13a9930d WS |
1761 | } |
1762 | ||
1df65547 | 1763 | static int ks_wlan_set_stop_request(struct net_device *dev, |
96268418 | 1764 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1765 | char *extra) |
13a9930d | 1766 | { |
2b0d92b2 TH |
1767 | struct ks_wlan_private *priv = netdev_priv(dev); |
1768 | ||
e0d64815 | 1769 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1770 | return -EPERM; |
e0d64815 | 1771 | |
1df65547 WS |
1772 | /* for SLEEP MODE */ |
1773 | if (!(*uwrq)) | |
1774 | return -EINVAL; | |
13a9930d WS |
1775 | |
1776 | hostif_sme_enqueue(priv, SME_STOP_REQUEST); | |
1777 | return 0; | |
1778 | } | |
1779 | ||
13a9930d | 1780 | #include <linux/ieee80211.h> |
1df65547 | 1781 | static int ks_wlan_set_mlme(struct net_device *dev, |
18e76e23 SP |
1782 | struct iw_request_info *info, |
1783 | union iwreq_data *dwrq, char *extra) | |
13a9930d | 1784 | { |
2b0d92b2 | 1785 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1786 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
2d1de1e3 | 1787 | __u32 mode = 1; |
13a9930d | 1788 | |
e0d64815 | 1789 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1790 | return -EPERM; |
e0d64815 | 1791 | |
2d1de1e3 SP |
1792 | if (mlme->cmd != IW_MLME_DEAUTH && |
1793 | mlme->cmd != IW_MLME_DISASSOC) | |
1794 | return -EOPNOTSUPP; | |
1795 | ||
1796 | if (mlme->cmd == IW_MLME_DEAUTH && | |
1797 | mlme->reason_code == WLAN_REASON_MIC_FAILURE) | |
1798 | return 0; | |
1799 | ||
1800 | return ks_wlan_set_stop_request(dev, NULL, &mode, NULL); | |
13a9930d | 1801 | } |
13a9930d | 1802 | |
1df65547 WS |
1803 | static int ks_wlan_get_firmware_version(struct net_device *dev, |
1804 | struct iw_request_info *info, | |
13a9930d WS |
1805 | struct iw_point *dwrq, char *extra) |
1806 | { | |
2b0d92b2 TH |
1807 | struct ks_wlan_private *priv = netdev_priv(dev); |
1808 | ||
be046617 | 1809 | strcpy(extra, priv->firmware_version); |
1df65547 | 1810 | dwrq->length = priv->version_size + 1; |
13a9930d WS |
1811 | return 0; |
1812 | } | |
1813 | ||
1df65547 | 1814 | static int ks_wlan_set_preamble(struct net_device *dev, |
96268418 | 1815 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1816 | char *extra) |
13a9930d | 1817 | { |
2b0d92b2 | 1818 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1819 | |
e0d64815 | 1820 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1821 | return -EPERM; |
e0d64815 | 1822 | |
1df65547 | 1823 | /* for SLEEP MODE */ |
8521b4e6 | 1824 | if (*uwrq != LONG_PREAMBLE && *uwrq != SHORT_PREAMBLE) |
1df65547 | 1825 | return -EINVAL; |
13a9930d | 1826 | |
8521b4e6 | 1827 | priv->reg.preamble = *uwrq; |
13a9930d | 1828 | priv->need_commit |= SME_MODE_SET; |
1df65547 | 1829 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
1830 | } |
1831 | ||
1df65547 | 1832 | static int ks_wlan_get_preamble(struct net_device *dev, |
96268418 | 1833 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1834 | char *extra) |
13a9930d | 1835 | { |
2b0d92b2 | 1836 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1837 | |
e0d64815 | 1838 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1839 | return -EPERM; |
e0d64815 | 1840 | |
1df65547 | 1841 | /* for SLEEP MODE */ |
13a9930d WS |
1842 | *uwrq = priv->reg.preamble; |
1843 | return 0; | |
1844 | } | |
1845 | ||
8fb8e05c TH |
1846 | static int ks_wlan_set_power_mgmt(struct net_device *dev, |
1847 | struct iw_request_info *info, __u32 *uwrq, | |
1848 | char *extra) | |
13a9930d | 1849 | { |
2b0d92b2 | 1850 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1851 | |
e0d64815 | 1852 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1853 | return -EPERM; |
e0d64815 | 1854 | |
c8712580 SP |
1855 | if (*uwrq != POWER_MGMT_ACTIVE && |
1856 | *uwrq != POWER_MGMT_SAVE1 && | |
1857 | *uwrq != POWER_MGMT_SAVE2) | |
1858 | return -EINVAL; | |
1859 | ||
1860 | if ((*uwrq == POWER_MGMT_SAVE1 || *uwrq == POWER_MGMT_SAVE2) && | |
1861 | (priv->reg.operation_mode != MODE_INFRASTRUCTURE)) | |
1df65547 | 1862 | return -EINVAL; |
13a9930d | 1863 | |
c8712580 | 1864 | priv->reg.power_mgmt = *uwrq; |
13a9930d WS |
1865 | hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST); |
1866 | ||
1867 | return 0; | |
1868 | } | |
1869 | ||
8fb8e05c TH |
1870 | static int ks_wlan_get_power_mgmt(struct net_device *dev, |
1871 | struct iw_request_info *info, __u32 *uwrq, | |
1872 | char *extra) | |
13a9930d | 1873 | { |
2b0d92b2 | 1874 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1875 | |
e0d64815 | 1876 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1877 | return -EPERM; |
e0d64815 | 1878 | |
1df65547 | 1879 | /* for SLEEP MODE */ |
8fb8e05c | 1880 | *uwrq = priv->reg.power_mgmt; |
13a9930d WS |
1881 | return 0; |
1882 | } | |
1883 | ||
1df65547 | 1884 | static int ks_wlan_set_scan_type(struct net_device *dev, |
96268418 | 1885 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1886 | char *extra) |
13a9930d | 1887 | { |
2b0d92b2 | 1888 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1889 | |
e0d64815 | 1890 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1891 | return -EPERM; |
1df65547 | 1892 | /* for SLEEP MODE */ |
7a2cc8db SP |
1893 | |
1894 | if (*uwrq != ACTIVE_SCAN && *uwrq != PASSIVE_SCAN) | |
1df65547 | 1895 | return -EINVAL; |
13a9930d | 1896 | |
7a2cc8db | 1897 | priv->reg.scan_type = *uwrq; |
13a9930d WS |
1898 | return 0; |
1899 | } | |
1900 | ||
1df65547 | 1901 | static int ks_wlan_get_scan_type(struct net_device *dev, |
96268418 | 1902 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1903 | char *extra) |
13a9930d | 1904 | { |
2b0d92b2 | 1905 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1906 | |
e0d64815 | 1907 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1908 | return -EPERM; |
1df65547 | 1909 | /* for SLEEP MODE */ |
13a9930d WS |
1910 | *uwrq = priv->reg.scan_type; |
1911 | return 0; | |
1912 | } | |
1df65547 | 1913 | |
1df65547 | 1914 | static int ks_wlan_set_beacon_lost(struct net_device *dev, |
96268418 | 1915 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1916 | char *extra) |
13a9930d | 1917 | { |
2b0d92b2 | 1918 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1919 | |
e0d64815 | 1920 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1921 | return -EPERM; |
1df65547 | 1922 | /* for SLEEP MODE */ |
6d6612de | 1923 | if (*uwrq > BEACON_LOST_COUNT_MAX) |
1df65547 | 1924 | return -EINVAL; |
13a9930d | 1925 | |
25ee63eb SP |
1926 | priv->reg.beacon_lost_count = *uwrq; |
1927 | ||
1df65547 | 1928 | if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) { |
13a9930d | 1929 | priv->need_commit |= SME_MODE_SET; |
1df65547 | 1930 | return -EINPROGRESS; /* Call commit handler */ |
8f4d00cd | 1931 | } |
25ee63eb SP |
1932 | |
1933 | return 0; | |
13a9930d WS |
1934 | } |
1935 | ||
1df65547 | 1936 | static int ks_wlan_get_beacon_lost(struct net_device *dev, |
96268418 | 1937 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1938 | char *extra) |
13a9930d | 1939 | { |
2b0d92b2 | 1940 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1941 | |
e0d64815 | 1942 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1943 | return -EPERM; |
1df65547 | 1944 | /* for SLEEP MODE */ |
13a9930d WS |
1945 | *uwrq = priv->reg.beacon_lost_count; |
1946 | return 0; | |
1947 | } | |
1948 | ||
1df65547 | 1949 | static int ks_wlan_set_phy_type(struct net_device *dev, |
96268418 | 1950 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1951 | char *extra) |
13a9930d | 1952 | { |
2b0d92b2 | 1953 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1954 | |
e0d64815 | 1955 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1956 | return -EPERM; |
81255d86 SP |
1957 | |
1958 | if (*uwrq != D_11B_ONLY_MODE && | |
1959 | *uwrq != D_11G_ONLY_MODE && | |
1960 | *uwrq != D_11BG_COMPATIBLE_MODE) | |
1df65547 | 1961 | return -EINVAL; |
13a9930d | 1962 | |
81255d86 SP |
1963 | /* for SLEEP MODE */ |
1964 | priv->reg.phy_type = *uwrq; | |
13a9930d | 1965 | priv->need_commit |= SME_MODE_SET; |
1df65547 | 1966 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
1967 | } |
1968 | ||
1df65547 | 1969 | static int ks_wlan_get_phy_type(struct net_device *dev, |
96268418 | 1970 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1971 | char *extra) |
13a9930d | 1972 | { |
2b0d92b2 | 1973 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1974 | |
e0d64815 | 1975 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1976 | return -EPERM; |
1df65547 | 1977 | /* for SLEEP MODE */ |
13a9930d WS |
1978 | *uwrq = priv->reg.phy_type; |
1979 | return 0; | |
1980 | } | |
1981 | ||
1df65547 | 1982 | static int ks_wlan_set_cts_mode(struct net_device *dev, |
96268418 | 1983 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 1984 | char *extra) |
13a9930d | 1985 | { |
2b0d92b2 | 1986 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 1987 | |
e0d64815 | 1988 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 1989 | return -EPERM; |
1df65547 | 1990 | /* for SLEEP MODE */ |
bf338a90 | 1991 | if (*uwrq != CTS_MODE_FALSE && *uwrq != CTS_MODE_TRUE) |
1df65547 | 1992 | return -EINVAL; |
bf338a90 SP |
1993 | |
1994 | priv->reg.cts_mode = (*uwrq == CTS_MODE_FALSE) ? *uwrq : | |
1995 | (priv->reg.phy_type == D_11G_ONLY_MODE || | |
1996 | priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) ? | |
1997 | *uwrq : !*uwrq; | |
13a9930d WS |
1998 | |
1999 | priv->need_commit |= SME_MODE_SET; | |
1df65547 | 2000 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
2001 | } |
2002 | ||
1df65547 | 2003 | static int ks_wlan_get_cts_mode(struct net_device *dev, |
96268418 | 2004 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2005 | char *extra) |
13a9930d | 2006 | { |
2b0d92b2 | 2007 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2008 | |
e0d64815 | 2009 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2010 | return -EPERM; |
1df65547 | 2011 | /* for SLEEP MODE */ |
13a9930d WS |
2012 | *uwrq = priv->reg.cts_mode; |
2013 | return 0; | |
2014 | } | |
2015 | ||
13a9930d | 2016 | static int ks_wlan_set_sleep_mode(struct net_device *dev, |
1df65547 | 2017 | struct iw_request_info *info, |
96268418 | 2018 | __u32 *uwrq, char *extra) |
13a9930d | 2019 | { |
2b0d92b2 | 2020 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2021 | |
7f3c8bb5 SP |
2022 | if (*uwrq != SLP_SLEEP && |
2023 | *uwrq != SLP_ACTIVE) { | |
a9cbe2ad | 2024 | netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq); |
1df65547 | 2025 | return -EINVAL; |
13a9930d WS |
2026 | } |
2027 | ||
7f3c8bb5 SP |
2028 | priv->sleep_mode = *uwrq; |
2029 | netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode); | |
2030 | ||
2031 | if (*uwrq == SLP_SLEEP) | |
2032 | hostif_sme_enqueue(priv, SME_STOP_REQUEST); | |
2033 | ||
2034 | hostif_sme_enqueue(priv, SME_SLEEP_REQUEST); | |
2035 | ||
13a9930d WS |
2036 | return 0; |
2037 | } | |
1df65547 | 2038 | |
13a9930d | 2039 | static int ks_wlan_get_sleep_mode(struct net_device *dev, |
1df65547 | 2040 | struct iw_request_info *info, |
96268418 | 2041 | __u32 *uwrq, char *extra) |
13a9930d | 2042 | { |
2b0d92b2 | 2043 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2044 | |
13a9930d WS |
2045 | *uwrq = priv->sleep_mode; |
2046 | ||
2047 | return 0; | |
2048 | } | |
44f2bf55 | 2049 | |
1df65547 | 2050 | static int ks_wlan_set_wps_enable(struct net_device *dev, |
96268418 | 2051 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2052 | char *extra) |
13a9930d | 2053 | { |
2b0d92b2 TH |
2054 | struct ks_wlan_private *priv = netdev_priv(dev); |
2055 | ||
e0d64815 | 2056 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2057 | return -EPERM; |
1df65547 | 2058 | /* for SLEEP MODE */ |
6519967b | 2059 | if (*uwrq != 0 && *uwrq != 1) |
1df65547 | 2060 | return -EINVAL; |
13a9930d | 2061 | |
6519967b | 2062 | priv->wps.wps_enabled = *uwrq; |
13a9930d WS |
2063 | hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST); |
2064 | ||
2065 | return 0; | |
2066 | } | |
1df65547 | 2067 | |
1df65547 | 2068 | static int ks_wlan_get_wps_enable(struct net_device *dev, |
96268418 | 2069 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2070 | char *extra) |
13a9930d | 2071 | { |
2b0d92b2 TH |
2072 | struct ks_wlan_private *priv = netdev_priv(dev); |
2073 | ||
e0d64815 | 2074 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2075 | return -EPERM; |
1df65547 | 2076 | /* for SLEEP MODE */ |
13a9930d | 2077 | *uwrq = priv->wps.wps_enabled; |
c8be6461 | 2078 | netdev_info(dev, "return=%d\n", *uwrq); |
13a9930d WS |
2079 | |
2080 | return 0; | |
2081 | } | |
1df65547 | 2082 | |
13a9930d WS |
2083 | static int ks_wlan_set_wps_probe_req(struct net_device *dev, |
2084 | struct iw_request_info *info, | |
2085 | struct iw_point *dwrq, char *extra) | |
2086 | { | |
184eb0c5 | 2087 | u8 *p = extra; |
13a9930d | 2088 | unsigned char len; |
2b0d92b2 | 2089 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2090 | |
e0d64815 | 2091 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2092 | return -EPERM; |
13a9930d WS |
2093 | |
2094 | /* length check */ | |
e0d64815 | 2095 | if (p[1] + 2 != dwrq->length || dwrq->length > 256) |
13a9930d | 2096 | return -EINVAL; |
13a9930d | 2097 | |
1df65547 WS |
2098 | priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */ |
2099 | len = p[1] + 2; /* IE header + IE */ | |
13a9930d WS |
2100 | |
2101 | memcpy(priv->wps.ie, &len, sizeof(len)); | |
1df65547 | 2102 | p = memcpy(priv->wps.ie + 1, p, len); |
13a9930d | 2103 | |
5259b329 SP |
2104 | netdev_dbg(dev, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n", |
2105 | priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3], | |
2106 | p[priv->wps.ielen - 3], p[priv->wps.ielen - 2], | |
2107 | p[priv->wps.ielen - 1]); | |
13a9930d WS |
2108 | |
2109 | hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST); | |
2110 | ||
2111 | return 0; | |
2112 | } | |
13a9930d | 2113 | |
1df65547 | 2114 | static int ks_wlan_set_tx_gain(struct net_device *dev, |
96268418 | 2115 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2116 | char *extra) |
13a9930d | 2117 | { |
2b0d92b2 | 2118 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2119 | |
e0d64815 | 2120 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2121 | return -EPERM; |
1df65547 | 2122 | /* for SLEEP MODE */ |
6d6612de | 2123 | if (*uwrq > 0xFF) |
1df65547 | 2124 | return -EINVAL; |
13a9930d | 2125 | |
ace98ed0 | 2126 | priv->gain.tx_gain = (u8)*uwrq; |
86357f79 | 2127 | priv->gain.tx_mode = (priv->gain.tx_gain < 0xFF) ? 1 : 0; |
13a9930d | 2128 | hostif_sme_enqueue(priv, SME_SET_GAIN); |
1df65547 | 2129 | return 0; |
13a9930d WS |
2130 | } |
2131 | ||
1df65547 | 2132 | static int ks_wlan_get_tx_gain(struct net_device *dev, |
96268418 | 2133 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2134 | char *extra) |
13a9930d | 2135 | { |
2b0d92b2 | 2136 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2137 | |
e0d64815 | 2138 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2139 | return -EPERM; |
1df65547 | 2140 | /* for SLEEP MODE */ |
93270634 | 2141 | *uwrq = priv->gain.tx_gain; |
13a9930d WS |
2142 | hostif_sme_enqueue(priv, SME_GET_GAIN); |
2143 | return 0; | |
2144 | } | |
2145 | ||
1df65547 | 2146 | static int ks_wlan_set_rx_gain(struct net_device *dev, |
96268418 | 2147 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2148 | char *extra) |
13a9930d | 2149 | { |
2b0d92b2 | 2150 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2151 | |
e0d64815 | 2152 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2153 | return -EPERM; |
1df65547 | 2154 | /* for SLEEP MODE */ |
6d6612de | 2155 | if (*uwrq > 0xFF) |
1df65547 | 2156 | return -EINVAL; |
13a9930d | 2157 | |
f647b8e1 | 2158 | priv->gain.rx_gain = (u8)*uwrq; |
6cb3e606 | 2159 | priv->gain.rx_mode = (priv->gain.rx_gain < 0xFF) ? 1 : 0; |
13a9930d | 2160 | hostif_sme_enqueue(priv, SME_SET_GAIN); |
1df65547 | 2161 | return 0; |
13a9930d WS |
2162 | } |
2163 | ||
1df65547 | 2164 | static int ks_wlan_get_rx_gain(struct net_device *dev, |
96268418 | 2165 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2166 | char *extra) |
13a9930d | 2167 | { |
2b0d92b2 | 2168 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2169 | |
e0d64815 | 2170 | if (priv->sleep_mode == SLP_SLEEP) |
1df65547 | 2171 | return -EPERM; |
1df65547 | 2172 | /* for SLEEP MODE */ |
93270634 | 2173 | *uwrq = priv->gain.rx_gain; |
13a9930d WS |
2174 | hostif_sme_enqueue(priv, SME_GET_GAIN); |
2175 | return 0; | |
2176 | } | |
1df65547 | 2177 | |
1df65547 | 2178 | static int ks_wlan_get_eeprom_cksum(struct net_device *dev, |
96268418 | 2179 | struct iw_request_info *info, __u32 *uwrq, |
1df65547 | 2180 | char *extra) |
13a9930d | 2181 | { |
2b0d92b2 | 2182 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
2183 | |
2184 | *uwrq = priv->eeprom_checksum; | |
2185 | return 0; | |
2186 | } | |
2187 | ||
03806ab3 | 2188 | static void print_hif_event(struct net_device *dev, int event) |
1df65547 | 2189 | { |
1df65547 WS |
2190 | switch (event) { |
2191 | case HIF_DATA_REQ: | |
03806ab3 | 2192 | netdev_info(dev, "HIF_DATA_REQ\n"); |
13a9930d | 2193 | break; |
1df65547 | 2194 | case HIF_DATA_IND: |
03806ab3 | 2195 | netdev_info(dev, "HIF_DATA_IND\n"); |
13a9930d | 2196 | break; |
1df65547 | 2197 | case HIF_MIB_GET_REQ: |
03806ab3 | 2198 | netdev_info(dev, "HIF_MIB_GET_REQ\n"); |
13a9930d | 2199 | break; |
1df65547 | 2200 | case HIF_MIB_GET_CONF: |
03806ab3 | 2201 | netdev_info(dev, "HIF_MIB_GET_CONF\n"); |
13a9930d | 2202 | break; |
1df65547 | 2203 | case HIF_MIB_SET_REQ: |
03806ab3 | 2204 | netdev_info(dev, "HIF_MIB_SET_REQ\n"); |
13a9930d | 2205 | break; |
1df65547 | 2206 | case HIF_MIB_SET_CONF: |
03806ab3 | 2207 | netdev_info(dev, "HIF_MIB_SET_CONF\n"); |
13a9930d | 2208 | break; |
8fb8e05c TH |
2209 | case HIF_POWER_MGMT_REQ: |
2210 | netdev_info(dev, "HIF_POWER_MGMT_REQ\n"); | |
13a9930d | 2211 | break; |
8fb8e05c TH |
2212 | case HIF_POWER_MGMT_CONF: |
2213 | netdev_info(dev, "HIF_POWER_MGMT_CONF\n"); | |
13a9930d | 2214 | break; |
1df65547 | 2215 | case HIF_START_REQ: |
03806ab3 | 2216 | netdev_info(dev, "HIF_START_REQ\n"); |
13a9930d | 2217 | break; |
1df65547 | 2218 | case HIF_START_CONF: |
03806ab3 | 2219 | netdev_info(dev, "HIF_START_CONF\n"); |
13a9930d | 2220 | break; |
1df65547 | 2221 | case HIF_CONNECT_IND: |
03806ab3 | 2222 | netdev_info(dev, "HIF_CONNECT_IND\n"); |
13a9930d | 2223 | break; |
1df65547 | 2224 | case HIF_STOP_REQ: |
03806ab3 | 2225 | netdev_info(dev, "HIF_STOP_REQ\n"); |
13a9930d | 2226 | break; |
1df65547 | 2227 | case HIF_STOP_CONF: |
03806ab3 | 2228 | netdev_info(dev, "HIF_STOP_CONF\n"); |
13a9930d | 2229 | break; |
1df65547 | 2230 | case HIF_PS_ADH_SET_REQ: |
03806ab3 | 2231 | netdev_info(dev, "HIF_PS_ADH_SET_REQ\n"); |
13a9930d WS |
2232 | break; |
2233 | case HIF_PS_ADH_SET_CONF: | |
03806ab3 | 2234 | netdev_info(dev, "HIF_PS_ADH_SET_CONF\n"); |
13a9930d | 2235 | break; |
1df65547 | 2236 | case HIF_INFRA_SET_REQ: |
03806ab3 | 2237 | netdev_info(dev, "HIF_INFRA_SET_REQ\n"); |
13a9930d | 2238 | break; |
1df65547 | 2239 | case HIF_INFRA_SET_CONF: |
03806ab3 | 2240 | netdev_info(dev, "HIF_INFRA_SET_CONF\n"); |
13a9930d | 2241 | break; |
1df65547 | 2242 | case HIF_ADH_SET_REQ: |
03806ab3 | 2243 | netdev_info(dev, "HIF_ADH_SET_REQ\n"); |
13a9930d | 2244 | break; |
1df65547 | 2245 | case HIF_ADH_SET_CONF: |
03806ab3 | 2246 | netdev_info(dev, "HIF_ADH_SET_CONF\n"); |
13a9930d | 2247 | break; |
1df65547 | 2248 | case HIF_AP_SET_REQ: |
03806ab3 | 2249 | netdev_info(dev, "HIF_AP_SET_REQ\n"); |
13a9930d | 2250 | break; |
1df65547 | 2251 | case HIF_AP_SET_CONF: |
03806ab3 | 2252 | netdev_info(dev, "HIF_AP_SET_CONF\n"); |
13a9930d | 2253 | break; |
1df65547 | 2254 | case HIF_ASSOC_INFO_IND: |
03806ab3 | 2255 | netdev_info(dev, "HIF_ASSOC_INFO_IND\n"); |
13a9930d WS |
2256 | break; |
2257 | case HIF_MIC_FAILURE_REQ: | |
03806ab3 | 2258 | netdev_info(dev, "HIF_MIC_FAILURE_REQ\n"); |
13a9930d | 2259 | break; |
1df65547 | 2260 | case HIF_MIC_FAILURE_CONF: |
03806ab3 | 2261 | netdev_info(dev, "HIF_MIC_FAILURE_CONF\n"); |
13a9930d | 2262 | break; |
1df65547 | 2263 | case HIF_SCAN_REQ: |
03806ab3 | 2264 | netdev_info(dev, "HIF_SCAN_REQ\n"); |
13a9930d | 2265 | break; |
1df65547 | 2266 | case HIF_SCAN_CONF: |
03806ab3 | 2267 | netdev_info(dev, "HIF_SCAN_CONF\n"); |
13a9930d | 2268 | break; |
1df65547 | 2269 | case HIF_PHY_INFO_REQ: |
03806ab3 | 2270 | netdev_info(dev, "HIF_PHY_INFO_REQ\n"); |
13a9930d | 2271 | break; |
1df65547 | 2272 | case HIF_PHY_INFO_CONF: |
03806ab3 | 2273 | netdev_info(dev, "HIF_PHY_INFO_CONF\n"); |
13a9930d | 2274 | break; |
1df65547 | 2275 | case HIF_SLEEP_REQ: |
03806ab3 | 2276 | netdev_info(dev, "HIF_SLEEP_REQ\n"); |
13a9930d | 2277 | break; |
1df65547 | 2278 | case HIF_SLEEP_CONF: |
03806ab3 | 2279 | netdev_info(dev, "HIF_SLEEP_CONF\n"); |
13a9930d | 2280 | break; |
1df65547 | 2281 | case HIF_PHY_INFO_IND: |
03806ab3 | 2282 | netdev_info(dev, "HIF_PHY_INFO_IND\n"); |
13a9930d | 2283 | break; |
1df65547 | 2284 | case HIF_SCAN_IND: |
03806ab3 | 2285 | netdev_info(dev, "HIF_SCAN_IND\n"); |
13a9930d | 2286 | break; |
1df65547 | 2287 | case HIF_INFRA_SET2_REQ: |
03806ab3 | 2288 | netdev_info(dev, "HIF_INFRA_SET2_REQ\n"); |
13a9930d WS |
2289 | break; |
2290 | case HIF_INFRA_SET2_CONF: | |
03806ab3 | 2291 | netdev_info(dev, "HIF_INFRA_SET2_CONF\n"); |
13a9930d | 2292 | break; |
1df65547 | 2293 | case HIF_ADH_SET2_REQ: |
03806ab3 | 2294 | netdev_info(dev, "HIF_ADH_SET2_REQ\n"); |
13a9930d | 2295 | break; |
1df65547 | 2296 | case HIF_ADH_SET2_CONF: |
03806ab3 | 2297 | netdev_info(dev, "HIF_ADH_SET2_CONF\n"); |
13a9930d WS |
2298 | } |
2299 | } | |
2300 | ||
f160bc20 | 2301 | /* get host command history */ |
13a9930d | 2302 | static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info, |
96268418 | 2303 | __u32 *uwrq, char *extra) |
13a9930d | 2304 | { |
1df65547 | 2305 | int i, event; |
2b0d92b2 | 2306 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2307 | |
1df65547 WS |
2308 | for (i = 63; i >= 0; i--) { |
2309 | event = | |
2310 | priv->hostt.buff[(priv->hostt.qtail - 1 - i) % | |
2311 | SME_EVENT_BUFF_SIZE]; | |
03806ab3 | 2312 | print_hif_event(dev, event); |
13a9930d WS |
2313 | } |
2314 | return 0; | |
2315 | } | |
2316 | ||
2317 | /* Structures to export the Wireless Handlers */ | |
2318 | ||
2319 | static const struct iw_priv_args ks_wlan_private_args[] = { | |
2320 | /*{ cmd, set_args, get_args, name[16] } */ | |
1df65547 WS |
2321 | {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE, |
2322 | IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"}, | |
1df65547 WS |
2323 | {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
2324 | IW_PRIV_TYPE_NONE, "SetWPSEnable"}, | |
2325 | {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE, | |
2326 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"}, | |
2327 | {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE, | |
2328 | "SetWPSProbeReq"}, | |
1df65547 WS |
2329 | {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
2330 | IW_PRIV_TYPE_NONE, "SetPreamble"}, | |
2331 | {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE, | |
2332 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"}, | |
2333 | {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2334 | IW_PRIV_TYPE_NONE, "SetPowerSave"}, | |
2335 | {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE, | |
2336 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"}, | |
2337 | {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2338 | IW_PRIV_TYPE_NONE, "SetScanType"}, | |
2339 | {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE, | |
2340 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"}, | |
2341 | {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2342 | IW_PRIV_TYPE_NONE, "SetRxGain"}, | |
2343 | {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE, | |
2344 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"}, | |
2345 | {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1), | |
2346 | "hostt"}, | |
2347 | {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2348 | IW_PRIV_TYPE_NONE, "SetBeaconLost"}, | |
2349 | {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE, | |
2350 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"}, | |
2351 | {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2352 | IW_PRIV_TYPE_NONE, "SetSleepMode"}, | |
2353 | {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE, | |
2354 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"}, | |
2355 | {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2356 | IW_PRIV_TYPE_NONE, "SetTxGain"}, | |
2357 | {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE, | |
2358 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"}, | |
2359 | {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2360 | IW_PRIV_TYPE_NONE, "SetPhyType"}, | |
2361 | {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE, | |
2362 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"}, | |
2363 | {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
2364 | IW_PRIV_TYPE_NONE, "SetCtsMode"}, | |
2365 | {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE, | |
2366 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"}, | |
2367 | {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE, | |
2368 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"}, | |
13a9930d | 2369 | }; |
1df65547 WS |
2370 | |
2371 | static const iw_handler ks_wlan_handler[] = { | |
18e76e23 SP |
2372 | IW_HANDLER(SIOCSIWCOMMIT, ks_wlan_config_commit), |
2373 | IW_HANDLER(SIOCGIWNAME, ks_wlan_get_name), | |
2374 | IW_HANDLER(SIOCSIWFREQ, ks_wlan_set_freq), | |
2375 | IW_HANDLER(SIOCGIWFREQ, ks_wlan_get_freq), | |
2376 | IW_HANDLER(SIOCSIWMODE, ks_wlan_set_mode), | |
2377 | IW_HANDLER(SIOCGIWMODE, ks_wlan_get_mode), | |
18e76e23 SP |
2378 | IW_HANDLER(SIOCGIWRANGE, ks_wlan_get_range), |
2379 | IW_HANDLER(SIOCGIWSTATS, ks_wlan_get_iwstats), | |
2380 | IW_HANDLER(SIOCSIWAP, ks_wlan_set_wap), | |
2381 | IW_HANDLER(SIOCGIWAP, ks_wlan_get_wap), | |
2382 | IW_HANDLER(SIOCSIWMLME, ks_wlan_set_mlme), | |
2383 | IW_HANDLER(SIOCGIWAPLIST, ks_wlan_get_aplist), | |
2384 | IW_HANDLER(SIOCSIWSCAN, ks_wlan_set_scan), | |
2385 | IW_HANDLER(SIOCGIWSCAN, ks_wlan_get_scan), | |
2386 | IW_HANDLER(SIOCSIWESSID, ks_wlan_set_essid), | |
2387 | IW_HANDLER(SIOCGIWESSID, ks_wlan_get_essid), | |
2388 | IW_HANDLER(SIOCSIWNICKN, ks_wlan_set_nick), | |
2389 | IW_HANDLER(SIOCGIWNICKN, ks_wlan_get_nick), | |
2390 | IW_HANDLER(SIOCSIWRATE, ks_wlan_set_rate), | |
2391 | IW_HANDLER(SIOCGIWRATE, ks_wlan_get_rate), | |
2392 | IW_HANDLER(SIOCSIWRTS, ks_wlan_set_rts), | |
2393 | IW_HANDLER(SIOCGIWRTS, ks_wlan_get_rts), | |
2394 | IW_HANDLER(SIOCSIWFRAG, ks_wlan_set_frag), | |
2395 | IW_HANDLER(SIOCGIWFRAG, ks_wlan_get_frag), | |
18e76e23 SP |
2396 | IW_HANDLER(SIOCSIWENCODE, ks_wlan_set_encode), |
2397 | IW_HANDLER(SIOCGIWENCODE, ks_wlan_get_encode), | |
2398 | IW_HANDLER(SIOCSIWPOWER, ks_wlan_set_power), | |
2399 | IW_HANDLER(SIOCGIWPOWER, ks_wlan_get_power), | |
2400 | IW_HANDLER(SIOCSIWGENIE, ks_wlan_set_genie), | |
2401 | IW_HANDLER(SIOCSIWAUTH, ks_wlan_set_auth_mode), | |
2402 | IW_HANDLER(SIOCGIWAUTH, ks_wlan_get_auth_mode), | |
2403 | IW_HANDLER(SIOCSIWENCODEEXT, ks_wlan_set_encode_ext), | |
2404 | IW_HANDLER(SIOCGIWENCODEEXT, ks_wlan_get_encode_ext), | |
2405 | IW_HANDLER(SIOCSIWPMKSA, ks_wlan_set_pmksa), | |
13a9930d WS |
2406 | }; |
2407 | ||
2408 | /* private_handler */ | |
1df65547 | 2409 | static const iw_handler ks_wlan_private_handler[] = { |
5e8779dc SP |
2410 | (iw_handler)NULL, /* 0 */ |
2411 | (iw_handler)NULL, /* 1, KS_WLAN_GET_DRIVER_VERSION */ | |
2412 | (iw_handler)NULL, /* 2 */ | |
2413 | (iw_handler)ks_wlan_get_firmware_version,/* 3 KS_WLAN_GET_FIRM_VERSION */ | |
5e8779dc SP |
2414 | (iw_handler)ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */ |
2415 | (iw_handler)ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */ | |
2416 | (iw_handler)ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */ | |
5e8779dc SP |
2417 | (iw_handler)ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */ |
2418 | (iw_handler)ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */ | |
2419 | (iw_handler)ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */ | |
8fb8e05c TH |
2420 | (iw_handler)ks_wlan_set_power_mgmt, /* 10 KS_WLAN_SET_POWER_SAVE */ |
2421 | (iw_handler)ks_wlan_get_power_mgmt, /* 11 KS_WLAN_GET_POWER_SAVE */ | |
03d55ab9 TH |
2422 | (iw_handler)ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */ |
2423 | (iw_handler)ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */ | |
2424 | (iw_handler)ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */ | |
2425 | (iw_handler)ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */ | |
5e8779dc SP |
2426 | (iw_handler)ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */ |
2427 | (iw_handler)NULL, /* 17 */ | |
03d55ab9 TH |
2428 | (iw_handler)ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */ |
2429 | (iw_handler)ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */ | |
2430 | (iw_handler)ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */ | |
2431 | (iw_handler)ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */ | |
2432 | (iw_handler)ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */ | |
2433 | (iw_handler)ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */ | |
2434 | (iw_handler)ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */ | |
2435 | (iw_handler)ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */ | |
5e8779dc SP |
2436 | (iw_handler)NULL, /* 26 */ |
2437 | (iw_handler)NULL, /* 27 */ | |
03d55ab9 TH |
2438 | (iw_handler)ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */ |
2439 | (iw_handler)ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */ | |
5e8779dc SP |
2440 | (iw_handler)NULL, /* 30 */ |
2441 | (iw_handler)NULL, /* 31 */ | |
13a9930d WS |
2442 | }; |
2443 | ||
1df65547 | 2444 | static const struct iw_handler_def ks_wlan_handler_def = { |
5312af9e QK |
2445 | .num_standard = ARRAY_SIZE(ks_wlan_handler), |
2446 | .num_private = ARRAY_SIZE(ks_wlan_private_handler), | |
2447 | .num_private_args = ARRAY_SIZE(ks_wlan_private_args), | |
e9f83033 QK |
2448 | .standard = ks_wlan_handler, |
2449 | .private = ks_wlan_private_handler, | |
2450 | .private_args = ks_wlan_private_args, | |
13a9930d WS |
2451 | .get_wireless_stats = ks_get_wireless_stats, |
2452 | }; | |
2453 | ||
1df65547 WS |
2454 | static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, |
2455 | int cmd) | |
13a9930d | 2456 | { |
1770ae9d | 2457 | int ret; |
1df65547 | 2458 | struct iwreq *wrq = (struct iwreq *)rq; |
fe497530 | 2459 | |
13a9930d | 2460 | switch (cmd) { |
1df65547 | 2461 | case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */ |
1770ae9d | 2462 | ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL); |
13a9930d | 2463 | break; |
1df65547 | 2464 | // All other calls are currently unsupported |
13a9930d | 2465 | default: |
1770ae9d | 2466 | ret = -EOPNOTSUPP; |
13a9930d WS |
2467 | } |
2468 | ||
1770ae9d | 2469 | return ret; |
13a9930d WS |
2470 | } |
2471 | ||
13a9930d WS |
2472 | static |
2473 | struct net_device_stats *ks_wlan_get_stats(struct net_device *dev) | |
2474 | { | |
feedcf1a | 2475 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2476 | |
e0d64815 | 2477 | if (priv->dev_state < DEVICE_STATE_READY) |
1df65547 | 2478 | return NULL; /* not finished initialize */ |
13a9930d WS |
2479 | |
2480 | return &priv->nstats; | |
2481 | } | |
2482 | ||
2483 | static | |
2484 | int ks_wlan_set_mac_address(struct net_device *dev, void *addr) | |
2485 | { | |
feedcf1a | 2486 | struct ks_wlan_private *priv = netdev_priv(dev); |
1df65547 | 2487 | struct sockaddr *mac_addr = (struct sockaddr *)addr; |
fe497530 | 2488 | |
13a9930d WS |
2489 | if (netif_running(dev)) |
2490 | return -EBUSY; | |
2491 | memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); | |
3ec51bb2 | 2492 | ether_addr_copy(priv->eth_addr, mac_addr->sa_data); |
13a9930d | 2493 | |
f40cd66b | 2494 | priv->mac_address_valid = false; |
13a9930d | 2495 | hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST); |
7a98abcc | 2496 | netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr); |
13a9930d WS |
2497 | return 0; |
2498 | } | |
2499 | ||
13a9930d WS |
2500 | static |
2501 | void ks_wlan_tx_timeout(struct net_device *dev) | |
2502 | { | |
1df65547 | 2503 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2504 | |
5259b329 SP |
2505 | netdev_dbg(dev, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead, |
2506 | priv->tx_dev.qtail); | |
e0d64815 | 2507 | if (!netif_queue_stopped(dev)) |
13a9930d | 2508 | netif_stop_queue(dev); |
13a9930d WS |
2509 | priv->nstats.tx_errors++; |
2510 | netif_wake_queue(dev); | |
13a9930d WS |
2511 | } |
2512 | ||
2513 | static | |
2514 | int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
2515 | { | |
feedcf1a | 2516 | struct ks_wlan_private *priv = netdev_priv(dev); |
03b02449 | 2517 | int ret; |
13a9930d | 2518 | |
5259b329 | 2519 | netdev_dbg(dev, "in_interrupt()=%ld\n", in_interrupt()); |
13a9930d | 2520 | |
c7e65f4d | 2521 | if (!skb) { |
c8be6461 | 2522 | netdev_err(dev, "ks_wlan: skb == NULL!!!\n"); |
13a9930d WS |
2523 | return 0; |
2524 | } | |
2525 | if (priv->dev_state < DEVICE_STATE_READY) { | |
2526 | dev_kfree_skb(skb); | |
1df65547 WS |
2527 | return 0; /* not finished initialize */ |
2528 | } | |
13a9930d | 2529 | |
1df65547 | 2530 | if (netif_running(dev)) |
13a9930d WS |
2531 | netif_stop_queue(dev); |
2532 | ||
03b02449 | 2533 | ret = hostif_data_request(priv, skb); |
4e66308e | 2534 | netif_trans_update(dev); |
13a9930d | 2535 | |
03b02449 | 2536 | if (ret) |
5259b329 | 2537 | netdev_err(dev, "hostif_data_request error: =%d\n", ret); |
13a9930d | 2538 | |
03b02449 | 2539 | return 0; |
13a9930d WS |
2540 | } |
2541 | ||
055da4f9 | 2542 | void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb) |
13a9930d | 2543 | { |
13a9930d WS |
2544 | priv->nstats.tx_packets++; |
2545 | ||
1df65547 WS |
2546 | if (netif_queue_stopped(priv->net_dev)) |
2547 | netif_wake_queue(priv->net_dev); | |
13a9930d | 2548 | |
055da4f9 TH |
2549 | if (skb) { |
2550 | priv->nstats.tx_bytes += skb->len; | |
2551 | dev_kfree_skb(skb); | |
13a9930d | 2552 | } |
13a9930d WS |
2553 | } |
2554 | ||
64068bc3 TH |
2555 | /* |
2556 | * Set or clear the multicast filter for this adaptor. | |
2557 | * This routine is not state sensitive and need not be SMP locked. | |
2558 | */ | |
13a9930d | 2559 | static |
582475a2 | 2560 | void ks_wlan_set_rx_mode(struct net_device *dev) |
13a9930d | 2561 | { |
feedcf1a | 2562 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2563 | |
e0d64815 | 2564 | if (priv->dev_state < DEVICE_STATE_READY) |
1df65547 | 2565 | return; /* not finished initialize */ |
13a9930d | 2566 | hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST); |
13a9930d WS |
2567 | } |
2568 | ||
2569 | static | |
2570 | int ks_wlan_open(struct net_device *dev) | |
2571 | { | |
feedcf1a | 2572 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
2573 | |
2574 | priv->cur_rx = 0; | |
2575 | ||
1df65547 | 2576 | if (!priv->mac_address_valid) { |
c8be6461 | 2577 | netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name); |
13a9930d | 2578 | return -EBUSY; |
e33c759a EA |
2579 | } |
2580 | netif_start_queue(dev); | |
13a9930d WS |
2581 | |
2582 | return 0; | |
2583 | } | |
2584 | ||
2585 | static | |
2586 | int ks_wlan_close(struct net_device *dev) | |
2587 | { | |
1df65547 | 2588 | netif_stop_queue(dev); |
13a9930d | 2589 | |
13a9930d WS |
2590 | return 0; |
2591 | } | |
2592 | ||
13a9930d WS |
2593 | /* Operational parameters that usually are not changed. */ |
2594 | /* Time in jiffies before concluding the transmitter is hung. */ | |
db224d31 | 2595 | #define TX_TIMEOUT (3 * HZ) |
9a8936d6 DW |
2596 | static const unsigned char dummy_addr[] = { |
2597 | 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 | |
2598 | }; | |
13a9930d WS |
2599 | |
2600 | static const struct net_device_ops ks_wlan_netdev_ops = { | |
1df65547 WS |
2601 | .ndo_start_xmit = ks_wlan_start_xmit, |
2602 | .ndo_open = ks_wlan_open, | |
2603 | .ndo_stop = ks_wlan_close, | |
2604 | .ndo_do_ioctl = ks_wlan_netdev_ioctl, | |
2605 | .ndo_set_mac_address = ks_wlan_set_mac_address, | |
2606 | .ndo_get_stats = ks_wlan_get_stats, | |
2607 | .ndo_tx_timeout = ks_wlan_tx_timeout, | |
582475a2 | 2608 | .ndo_set_rx_mode = ks_wlan_set_rx_mode, |
13a9930d WS |
2609 | }; |
2610 | ||
2611 | int ks_wlan_net_start(struct net_device *dev) | |
2612 | { | |
feedcf1a | 2613 | struct ks_wlan_private *priv; |
13a9930d WS |
2614 | /* int rc; */ |
2615 | ||
2616 | priv = netdev_priv(dev); | |
f40cd66b | 2617 | priv->mac_address_valid = false; |
d892cc1c | 2618 | priv->is_device_open = true; |
13a9930d | 2619 | priv->need_commit = 0; |
13a9930d | 2620 | /* phy information update timer */ |
1df65547 | 2621 | atomic_set(&update_phyinfo, 0); |
8a81f749 | 2622 | timer_setup(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout, 0); |
13a9930d WS |
2623 | |
2624 | /* dummy address set */ | |
97d173c6 | 2625 | ether_addr_copy(priv->eth_addr, dummy_addr); |
07335253 | 2626 | ether_addr_copy(dev->dev_addr, priv->eth_addr); |
13a9930d WS |
2627 | |
2628 | /* The ks_wlan-specific entries in the device structure. */ | |
2629 | dev->netdev_ops = &ks_wlan_netdev_ops; | |
019ec785 | 2630 | dev->wireless_handlers = &ks_wlan_handler_def; |
13a9930d WS |
2631 | dev->watchdog_timeo = TX_TIMEOUT; |
2632 | ||
2633 | netif_carrier_off(dev); | |
2634 | ||
2635 | return 0; | |
2636 | } | |
2637 | ||
13a9930d WS |
2638 | int ks_wlan_net_stop(struct net_device *dev) |
2639 | { | |
feedcf1a | 2640 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 2641 | |
d892cc1c | 2642 | priv->is_device_open = false; |
13a9930d WS |
2643 | del_timer_sync(&update_phyinfo_timer); |
2644 | ||
1df65547 | 2645 | if (netif_running(dev)) |
13a9930d WS |
2646 | netif_stop_queue(dev); |
2647 | ||
55adb7bf | 2648 | return 0; |
13a9930d | 2649 | } |
0e24eb8a TH |
2650 | |
2651 | /** | |
2652 | * is_connect_status() - return true if status is 'connected' | |
2653 | * @status: high bit is used as FORCE_DISCONNECT, low bits used for | |
0a20a614 | 2654 | * connect status. |
0e24eb8a TH |
2655 | */ |
2656 | bool is_connect_status(u32 status) | |
2657 | { | |
2658 | return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS; | |
2659 | } | |
2660 | ||
2661 | /** | |
2662 | * is_disconnect_status() - return true if status is 'disconnected' | |
2663 | * @status: high bit is used as FORCE_DISCONNECT, low bits used for | |
0a20a614 | 2664 | * disconnect status. |
0e24eb8a TH |
2665 | */ |
2666 | bool is_disconnect_status(u32 status) | |
2667 | { | |
2668 | return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS; | |
2669 | } |