Commit | Line | Data |
---|---|---|
13a9930d WS |
1 | /* |
2 | * Driver for KeyStream 11b/g wireless LAN | |
3 | * | |
13a9930d WS |
4 | * Copyright (C) 2005-2008 KeyStream Corp. |
5 | * Copyright (C) 2009 Renesas Technology Corp. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
c5d9a030 WS |
8 | * it under the terms of the GNU General Public License version 2 as |
9 | * published by the Free Software Foundation. | |
13a9930d WS |
10 | */ |
11 | ||
12 | #include <linux/version.h> | |
13a9930d WS |
13 | #include <linux/module.h> |
14 | #include <linux/kernel.h> | |
15 | #include <linux/compiler.h> | |
16 | #include <linux/init.h> | |
17 | #include <linux/ioport.h> | |
18 | #include <linux/netdevice.h> | |
19 | #include <linux/etherdevice.h> | |
20 | #include <linux/if_arp.h> | |
21 | #include <linux/rtnetlink.h> | |
22 | #include <linux/delay.h> | |
23 | #include <linux/completion.h> | |
24 | #include <linux/mii.h> | |
25 | #include <linux/pci.h> | |
26 | #include <linux/ctype.h> | |
27 | #include <linux/timer.h> | |
28 | #include <asm/atomic.h> | |
29 | #include <linux/io.h> | |
30 | #include <asm/uaccess.h> | |
31 | ||
32 | static int wep_on_off; | |
33 | #define WEP_OFF 0 | |
34 | #define WEP_ON_64BIT 1 | |
35 | #define WEP_ON_128BIT 2 | |
36 | ||
37 | #include "ks_wlan.h" | |
38 | #include "ks_hostif.h" | |
39 | #include "ks_wlan_ioctl.h" | |
13a9930d WS |
40 | |
41 | /* Include Wireless Extension definition and check version */ | |
42 | #include <linux/wireless.h> | |
1df65547 | 43 | #define WIRELESS_SPY /* enable iwspy support */ |
13a9930d WS |
44 | #include <net/iw_handler.h> /* New driver API */ |
45 | ||
13a9930d WS |
46 | /* Frequency list (map channels to frequencies) */ |
47 | static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, | |
1df65547 WS |
48 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 |
49 | }; | |
13a9930d WS |
50 | |
51 | /* A few details needed for WEP (Wireless Equivalent Privacy) */ | |
52 | #define MAX_KEY_SIZE 13 /* 128 (?) bits */ | |
53 | #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */ | |
54 | typedef struct wep_key_t { | |
1df65547 WS |
55 | u16 len; |
56 | u8 key[16]; /* 40-bit and 104-bit keys */ | |
13a9930d WS |
57 | } wep_key_t; |
58 | ||
59 | /* Backward compatibility */ | |
60 | #ifndef IW_ENCODE_NOKEY | |
1df65547 | 61 | #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */ |
13a9930d WS |
62 | #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN) |
63 | #endif /* IW_ENCODE_NOKEY */ | |
64 | ||
65 | /* List of Wireless Handlers (new API) */ | |
1df65547 | 66 | static const struct iw_handler_def ks_wlan_handler_def; |
13a9930d | 67 | |
1df65547 | 68 | #define KSC_OPNOTSUPP /* Operation Not Support */ |
13a9930d WS |
69 | |
70 | /* | |
71 | * function prototypes | |
72 | */ | |
1df65547 WS |
73 | extern int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, |
74 | unsigned long size, | |
75 | void (*complete_handler) (void *arg1, void *arg2), | |
76 | void *arg1, void *arg2); | |
77 | static int ks_wlan_open(struct net_device *dev); | |
78 | static void ks_wlan_tx_timeout(struct net_device *dev); | |
79 | static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev); | |
80 | static int ks_wlan_close(struct net_device *dev); | |
81 | static void ks_wlan_set_multicast_list(struct net_device *dev); | |
82 | static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev); | |
13a9930d | 83 | static int ks_wlan_set_mac_address(struct net_device *dev, void *addr); |
1df65547 WS |
84 | static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, |
85 | int cmd); | |
13a9930d WS |
86 | |
87 | static atomic_t update_phyinfo; | |
88 | static struct timer_list update_phyinfo_timer; | |
89 | static | |
feedcf1a | 90 | int ks_wlan_update_phy_information(struct ks_wlan_private *priv) |
13a9930d | 91 | { |
1df65547 | 92 | struct iw_statistics *wstats = &priv->wstats; |
13a9930d WS |
93 | |
94 | DPRINTK(4, "in_interrupt = %ld\n", in_interrupt()); | |
95 | ||
96 | if (priv->dev_state < DEVICE_STATE_READY) { | |
1df65547 WS |
97 | return -1; /* not finished initialize */ |
98 | } | |
99 | if (atomic_read(&update_phyinfo)) | |
13a9930d WS |
100 | return 1; |
101 | ||
102 | /* The status */ | |
103 | wstats->status = priv->reg.operation_mode; /* Operation mode */ | |
104 | ||
105 | /* Signal quality and co. But where is the noise level ??? */ | |
106 | hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST); | |
107 | ||
108 | /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */ | |
1df65547 WS |
109 | if (!wait_for_completion_interruptible_timeout |
110 | (&priv->confirm_wait, HZ / 2)) { | |
111 | DPRINTK(1, "wait time out!!\n"); | |
13a9930d WS |
112 | } |
113 | ||
114 | atomic_inc(&update_phyinfo); | |
1df65547 | 115 | update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */ |
13a9930d WS |
116 | add_timer(&update_phyinfo_timer); |
117 | ||
118 | return 0; | |
119 | } | |
120 | ||
121 | static | |
122 | void ks_wlan_update_phyinfo_timeout(unsigned long ptr) | |
123 | { | |
124 | DPRINTK(4, "in_interrupt = %ld\n", in_interrupt()); | |
1df65547 | 125 | atomic_set(&update_phyinfo, 0); |
13a9930d WS |
126 | } |
127 | ||
1df65547 WS |
128 | int ks_wlan_setup_parameter(struct ks_wlan_private *priv, |
129 | unsigned int commit_flag) | |
13a9930d | 130 | { |
1df65547 | 131 | DPRINTK(2, "\n"); |
13a9930d WS |
132 | |
133 | hostif_sme_enqueue(priv, SME_STOP_REQUEST); | |
134 | ||
1df65547 | 135 | if (commit_flag & SME_RTS) |
13a9930d | 136 | hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST); |
1df65547 | 137 | if (commit_flag & SME_FRAG) |
13a9930d WS |
138 | hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST); |
139 | ||
1df65547 | 140 | if (commit_flag & SME_WEP_INDEX) |
13a9930d | 141 | hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST); |
1df65547 | 142 | if (commit_flag & SME_WEP_VAL1) |
13a9930d | 143 | hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST); |
1df65547 | 144 | if (commit_flag & SME_WEP_VAL2) |
13a9930d | 145 | hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST); |
1df65547 | 146 | if (commit_flag & SME_WEP_VAL3) |
13a9930d | 147 | hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST); |
1df65547 | 148 | if (commit_flag & SME_WEP_VAL4) |
13a9930d | 149 | hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST); |
1df65547 | 150 | if (commit_flag & SME_WEP_FLAG) |
13a9930d WS |
151 | hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST); |
152 | ||
1df65547 | 153 | if (commit_flag & SME_RSN) { |
13a9930d WS |
154 | hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST); |
155 | hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST); | |
156 | } | |
1df65547 | 157 | if (commit_flag & SME_RSN_MULTICAST) |
13a9930d | 158 | hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST); |
1df65547 | 159 | if (commit_flag & SME_RSN_UNICAST) |
13a9930d | 160 | hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST); |
1df65547 | 161 | if (commit_flag & SME_RSN_AUTH) |
13a9930d WS |
162 | hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST); |
163 | ||
164 | hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST); | |
165 | ||
166 | hostif_sme_enqueue(priv, SME_START_REQUEST); | |
167 | ||
168 | return 0; | |
169 | } | |
170 | ||
13a9930d WS |
171 | /* |
172 | * Initial Wireless Extension code for Ks_Wlannet driver by : | |
173 | * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00 | |
174 | * Conversion to new driver API by : | |
175 | * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02 | |
176 | * Javier also did a good amount of work here, adding some new extensions | |
177 | * and fixing my code. Let's just say that without him this code just | |
178 | * would not work at all... - Jean II | |
179 | */ | |
180 | ||
181 | /*------------------------------------------------------------------*/ | |
182 | /* Wireless Handler : get protocol name */ | |
1df65547 WS |
183 | static int ks_wlan_get_name(struct net_device *dev, |
184 | struct iw_request_info *info, char *cwrq, | |
185 | char *extra) | |
13a9930d | 186 | { |
1df65547 WS |
187 | struct ks_wlan_private *priv = |
188 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 189 | |
1df65547 WS |
190 | if (priv->sleep_mode == SLP_SLEEP) { |
191 | return -EPERM; | |
192 | } | |
193 | /* for SLEEP MODE */ | |
13a9930d WS |
194 | if (priv->dev_state < DEVICE_STATE_READY) { |
195 | strcpy(cwrq, "NOT READY!"); | |
1df65547 | 196 | } else if (priv->reg.phy_type == D_11B_ONLY_MODE) { |
13a9930d | 197 | strcpy(cwrq, "IEEE 802.11b"); |
1df65547 | 198 | } else if (priv->reg.phy_type == D_11G_ONLY_MODE) { |
13a9930d | 199 | strcpy(cwrq, "IEEE 802.11g"); |
1df65547 | 200 | } else { |
13a9930d WS |
201 | strcpy(cwrq, "IEEE 802.11b/g"); |
202 | } | |
203 | ||
204 | return 0; | |
205 | } | |
206 | ||
207 | /*------------------------------------------------------------------*/ | |
208 | /* Wireless Handler : set frequency */ | |
1df65547 WS |
209 | static int ks_wlan_set_freq(struct net_device *dev, |
210 | struct iw_request_info *info, struct iw_freq *fwrq, | |
211 | char *extra) | |
13a9930d | 212 | { |
1df65547 WS |
213 | struct ks_wlan_private *priv = |
214 | (struct ks_wlan_private *)netdev_priv(dev); | |
215 | int rc = -EINPROGRESS; /* Call commit handler */ | |
13a9930d | 216 | |
1df65547 WS |
217 | if (priv->sleep_mode == SLP_SLEEP) { |
218 | return -EPERM; | |
219 | } | |
13a9930d | 220 | |
1df65547 | 221 | /* for SLEEP MODE */ |
13a9930d | 222 | /* If setting by frequency, convert to a channel */ |
1df65547 WS |
223 | if ((fwrq->e == 1) && |
224 | (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) { | |
13a9930d WS |
225 | int f = fwrq->m / 100000; |
226 | int c = 0; | |
1df65547 | 227 | while ((c < 14) && (f != frequency_list[c])) |
13a9930d WS |
228 | c++; |
229 | /* Hack to fall through... */ | |
230 | fwrq->e = 0; | |
231 | fwrq->m = c + 1; | |
232 | } | |
233 | /* Setting by channel number */ | |
1df65547 | 234 | if ((fwrq->m > 1000) || (fwrq->e > 0)) |
13a9930d WS |
235 | rc = -EOPNOTSUPP; |
236 | else { | |
237 | int channel = fwrq->m; | |
238 | /* We should do a better check than that, | |
239 | * based on the card capability !!! */ | |
1df65547 WS |
240 | if ((channel < 1) || (channel > 14)) { |
241 | printk(KERN_DEBUG | |
242 | "%s: New channel value of %d is invalid!\n", | |
243 | dev->name, fwrq->m); | |
13a9930d WS |
244 | rc = -EINVAL; |
245 | } else { | |
246 | /* Yes ! We can set it !!! */ | |
1df65547 | 247 | priv->reg.channel = (u8) (channel); |
13a9930d WS |
248 | priv->need_commit |= SME_MODE_SET; |
249 | } | |
250 | } | |
251 | ||
252 | return rc; | |
253 | } | |
254 | ||
255 | /*------------------------------------------------------------------*/ | |
256 | /* Wireless Handler : get frequency */ | |
1df65547 WS |
257 | static int ks_wlan_get_freq(struct net_device *dev, |
258 | struct iw_request_info *info, struct iw_freq *fwrq, | |
259 | char *extra) | |
13a9930d | 260 | { |
1df65547 WS |
261 | struct ks_wlan_private *priv = |
262 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
263 | int f; |
264 | ||
1df65547 WS |
265 | if (priv->sleep_mode == SLP_SLEEP) { |
266 | return -EPERM; | |
13a9930d | 267 | } |
1df65547 WS |
268 | /* for SLEEP MODE */ |
269 | if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) { | |
270 | f = (int)priv->current_ap.channel; | |
271 | } else | |
13a9930d | 272 | f = (int)priv->reg.channel; |
1df65547 | 273 | fwrq->m = frequency_list[f - 1] * 100000; |
13a9930d WS |
274 | fwrq->e = 1; |
275 | ||
276 | return 0; | |
277 | } | |
278 | ||
279 | /*------------------------------------------------------------------*/ | |
280 | /* Wireless Handler : set ESSID */ | |
1df65547 WS |
281 | static int ks_wlan_set_essid(struct net_device *dev, |
282 | struct iw_request_info *info, | |
283 | struct iw_point *dwrq, char *extra) | |
13a9930d | 284 | { |
1df65547 WS |
285 | struct ks_wlan_private *priv = |
286 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
287 | size_t len; |
288 | ||
1df65547 | 289 | DPRINTK(2, " %d\n", dwrq->flags); |
13a9930d | 290 | |
1df65547 WS |
291 | if (priv->sleep_mode == SLP_SLEEP) { |
292 | return -EPERM; | |
293 | } | |
13a9930d | 294 | |
1df65547 | 295 | /* for SLEEP MODE */ |
13a9930d | 296 | /* Check if we asked for `any' */ |
1df65547 | 297 | if (dwrq->flags == 0) { |
13a9930d WS |
298 | /* Just send an empty SSID list */ |
299 | memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body)); | |
300 | priv->reg.ssid.size = 0; | |
301 | } else { | |
302 | #if 1 | |
303 | len = dwrq->length; | |
304 | /* iwconfig uses nul termination in SSID.. */ | |
305 | if (len > 0 && extra[len - 1] == '\0') | |
306 | len--; | |
307 | ||
308 | /* Check the size of the string */ | |
1df65547 | 309 | if (len > IW_ESSID_MAX_SIZE) { |
13a9930d WS |
310 | return -EINVAL; |
311 | } | |
312 | #else | |
313 | /* Check the size of the string */ | |
1df65547 WS |
314 | if (dwrq->length > IW_ESSID_MAX_SIZE + 1) { |
315 | return -E2BIG; | |
13a9930d WS |
316 | } |
317 | #endif | |
318 | ||
319 | /* Set the SSID */ | |
320 | memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body)); | |
321 | ||
322 | #if 1 | |
323 | memcpy(priv->reg.ssid.body, extra, len); | |
324 | priv->reg.ssid.size = len; | |
325 | #else | |
326 | memcpy(priv->reg.ssid.body, extra, dwrq->length); | |
327 | priv->reg.ssid.size = dwrq->length; | |
328 | #endif | |
329 | } | |
330 | /* Write it to the card */ | |
331 | priv->need_commit |= SME_MODE_SET; | |
332 | ||
1df65547 | 333 | // return -EINPROGRESS; /* Call commit handler */ |
13a9930d | 334 | ks_wlan_setup_parameter(priv, priv->need_commit); |
1df65547 WS |
335 | priv->need_commit = 0; |
336 | return 0; | |
13a9930d WS |
337 | } |
338 | ||
339 | /*------------------------------------------------------------------*/ | |
340 | /* Wireless Handler : get ESSID */ | |
1df65547 WS |
341 | static int ks_wlan_get_essid(struct net_device *dev, |
342 | struct iw_request_info *info, | |
343 | struct iw_point *dwrq, char *extra) | |
13a9930d | 344 | { |
1df65547 WS |
345 | struct ks_wlan_private *priv = |
346 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 347 | |
1df65547 WS |
348 | if (priv->sleep_mode == SLP_SLEEP) { |
349 | return -EPERM; | |
350 | } | |
13a9930d | 351 | |
1df65547 | 352 | /* for SLEEP MODE */ |
13a9930d WS |
353 | /* Note : if dwrq->flags != 0, we should |
354 | * get the relevant SSID from the SSID list... */ | |
1df65547 | 355 | if (priv->reg.ssid.size) { |
13a9930d WS |
356 | /* Get the current SSID */ |
357 | memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size); | |
358 | #if 0 | |
359 | extra[priv->reg.ssid.size] = '\0'; | |
360 | #endif | |
361 | /* If none, we may want to get the one that was set */ | |
362 | ||
363 | /* Push it out ! */ | |
364 | #if 1 | |
365 | dwrq->length = priv->reg.ssid.size; | |
366 | #else | |
1df65547 | 367 | dwrq->length = priv->reg.ssid.size + 1; |
13a9930d | 368 | #endif |
1df65547 WS |
369 | dwrq->flags = 1; /* active */ |
370 | } else { | |
13a9930d WS |
371 | #if 1 |
372 | dwrq->length = 0; | |
373 | #else | |
374 | extra[0] = '\0'; | |
375 | dwrq->length = 1; | |
376 | #endif | |
1df65547 | 377 | dwrq->flags = 0; /* ANY */ |
13a9930d WS |
378 | } |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | /*------------------------------------------------------------------*/ | |
384 | /* Wireless Handler : set AP address */ | |
385 | static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info, | |
386 | struct sockaddr *ap_addr, char *extra) | |
387 | { | |
1df65547 WS |
388 | struct ks_wlan_private *priv = |
389 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 390 | |
1df65547 | 391 | DPRINTK(2, "\n"); |
13a9930d | 392 | |
1df65547 WS |
393 | if (priv->sleep_mode == SLP_SLEEP) { |
394 | return -EPERM; | |
395 | } | |
396 | /* for SLEEP MODE */ | |
13a9930d | 397 | if (priv->reg.operation_mode == MODE_ADHOC || |
1df65547 WS |
398 | priv->reg.operation_mode == MODE_INFRASTRUCTURE) { |
399 | memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN); | |
13a9930d | 400 | |
1df65547 | 401 | if (is_valid_ether_addr((u8 *) priv->reg.bssid)) { |
13a9930d WS |
402 | priv->need_commit |= SME_MODE_SET; |
403 | } | |
1df65547 | 404 | } else { |
13a9930d WS |
405 | memset(priv->reg.bssid, 0x0, ETH_ALEN); |
406 | return -EOPNOTSUPP; | |
407 | } | |
408 | ||
409 | DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
1df65547 WS |
410 | priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2], |
411 | priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]); | |
13a9930d WS |
412 | |
413 | /* Write it to the card */ | |
414 | if (priv->need_commit) { | |
415 | priv->need_commit |= SME_MODE_SET; | |
1df65547 | 416 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
417 | } |
418 | return 0; | |
419 | } | |
420 | ||
421 | /*------------------------------------------------------------------*/ | |
422 | /* Wireless Handler : get AP address */ | |
423 | static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info, | |
424 | struct sockaddr *awrq, char *extra) | |
425 | { | |
1df65547 WS |
426 | struct ks_wlan_private *priv = |
427 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 428 | |
1df65547 WS |
429 | if (priv->sleep_mode == SLP_SLEEP) { |
430 | return -EPERM; | |
13a9930d | 431 | } |
1df65547 WS |
432 | /* for SLEEP MODE */ |
433 | if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) { | |
434 | memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN); | |
435 | } else { | |
13a9930d WS |
436 | memset(awrq->sa_data, 0, ETH_ALEN); |
437 | } | |
438 | ||
439 | awrq->sa_family = ARPHRD_ETHER; | |
440 | ||
441 | return 0; | |
442 | } | |
443 | ||
444 | /*------------------------------------------------------------------*/ | |
445 | /* Wireless Handler : set Nickname */ | |
1df65547 WS |
446 | static int ks_wlan_set_nick(struct net_device *dev, |
447 | struct iw_request_info *info, struct iw_point *dwrq, | |
448 | char *extra) | |
13a9930d | 449 | { |
1df65547 WS |
450 | struct ks_wlan_private *priv = |
451 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 452 | |
1df65547 WS |
453 | if (priv->sleep_mode == SLP_SLEEP) { |
454 | return -EPERM; | |
455 | } | |
13a9930d | 456 | |
1df65547 | 457 | /* for SLEEP MODE */ |
13a9930d | 458 | /* Check the size of the string */ |
1df65547 | 459 | if (dwrq->length > 16 + 1) { |
13a9930d WS |
460 | return -E2BIG; |
461 | } | |
462 | memset(priv->nick, 0, sizeof(priv->nick)); | |
463 | memcpy(priv->nick, extra, dwrq->length); | |
464 | ||
465 | return -EINPROGRESS; /* Call commit handler */ | |
466 | } | |
467 | ||
468 | /*------------------------------------------------------------------*/ | |
469 | /* Wireless Handler : get Nickname */ | |
1df65547 WS |
470 | static int ks_wlan_get_nick(struct net_device *dev, |
471 | struct iw_request_info *info, struct iw_point *dwrq, | |
472 | char *extra) | |
13a9930d | 473 | { |
1df65547 WS |
474 | struct ks_wlan_private *priv = |
475 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 476 | |
1df65547 WS |
477 | if (priv->sleep_mode == SLP_SLEEP) { |
478 | return -EPERM; | |
479 | } | |
480 | /* for SLEEP MODE */ | |
13a9930d WS |
481 | strncpy(extra, priv->nick, 16); |
482 | extra[16] = '\0'; | |
483 | dwrq->length = strlen(extra) + 1; | |
484 | ||
485 | return 0; | |
486 | } | |
487 | ||
488 | /*------------------------------------------------------------------*/ | |
489 | /* Wireless Handler : set Bit-Rate */ | |
1df65547 WS |
490 | static int ks_wlan_set_rate(struct net_device *dev, |
491 | struct iw_request_info *info, struct iw_param *vwrq, | |
492 | char *extra) | |
13a9930d | 493 | { |
1df65547 WS |
494 | struct ks_wlan_private *priv = |
495 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
496 | int i = 0; |
497 | ||
1df65547 WS |
498 | if (priv->sleep_mode == SLP_SLEEP) { |
499 | return -EPERM; | |
500 | } | |
501 | /* for SLEEP MODE */ | |
502 | if (priv->reg.phy_type == D_11B_ONLY_MODE) { | |
503 | if (vwrq->fixed == 1) { | |
504 | switch (vwrq->value) { | |
13a9930d | 505 | case 11000000: |
1df65547 WS |
506 | case 5500000: |
507 | priv->reg.rate_set.body[0] = | |
508 | (uint8_t) (vwrq->value / 500000); | |
13a9930d | 509 | break; |
1df65547 WS |
510 | case 2000000: |
511 | case 1000000: | |
512 | priv->reg.rate_set.body[0] = | |
513 | ((uint8_t) (vwrq->value / 500000)) | | |
514 | BASIC_RATE; | |
13a9930d WS |
515 | break; |
516 | default: | |
517 | return -EINVAL; | |
518 | } | |
519 | priv->reg.tx_rate = TX_RATE_FIXED; | |
520 | priv->reg.rate_set.size = 1; | |
1df65547 WS |
521 | } else { /* vwrq->fixed == 0 */ |
522 | if (vwrq->value > 0) { | |
523 | switch (vwrq->value) { | |
13a9930d | 524 | case 11000000: |
1df65547 WS |
525 | priv->reg.rate_set.body[3] = |
526 | TX_RATE_11M; | |
527 | i++; | |
528 | case 5500000: | |
529 | priv->reg.rate_set.body[2] = TX_RATE_5M; | |
530 | i++; | |
531 | case 2000000: | |
532 | priv->reg.rate_set.body[1] = | |
533 | TX_RATE_2M | BASIC_RATE; | |
534 | i++; | |
535 | case 1000000: | |
536 | priv->reg.rate_set.body[0] = | |
537 | TX_RATE_1M | BASIC_RATE; | |
538 | i++; | |
13a9930d WS |
539 | break; |
540 | default: | |
541 | return -EINVAL; | |
542 | } | |
543 | priv->reg.tx_rate = TX_RATE_MANUAL_AUTO; | |
544 | priv->reg.rate_set.size = i; | |
1df65547 | 545 | } else { |
13a9930d WS |
546 | priv->reg.rate_set.body[3] = TX_RATE_11M; |
547 | priv->reg.rate_set.body[2] = TX_RATE_5M; | |
1df65547 WS |
548 | priv->reg.rate_set.body[1] = |
549 | TX_RATE_2M | BASIC_RATE; | |
550 | priv->reg.rate_set.body[0] = | |
551 | TX_RATE_1M | BASIC_RATE; | |
13a9930d WS |
552 | priv->reg.tx_rate = TX_RATE_FULL_AUTO; |
553 | priv->reg.rate_set.size = 4; | |
554 | } | |
555 | } | |
1df65547 WS |
556 | } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */ |
557 | if (vwrq->fixed == 1) { | |
558 | switch (vwrq->value) { | |
13a9930d WS |
559 | case 54000000: |
560 | case 48000000: | |
561 | case 36000000: | |
562 | case 18000000: | |
1df65547 WS |
563 | case 9000000: |
564 | priv->reg.rate_set.body[0] = | |
565 | (uint8_t) (vwrq->value / 500000); | |
13a9930d WS |
566 | break; |
567 | case 24000000: | |
568 | case 12000000: | |
569 | case 11000000: | |
1df65547 WS |
570 | case 6000000: |
571 | case 5500000: | |
572 | case 2000000: | |
573 | case 1000000: | |
574 | priv->reg.rate_set.body[0] = | |
575 | ((uint8_t) (vwrq->value / 500000)) | | |
576 | BASIC_RATE; | |
13a9930d WS |
577 | break; |
578 | default: | |
579 | return -EINVAL; | |
580 | } | |
581 | priv->reg.tx_rate = TX_RATE_FIXED; | |
582 | priv->reg.rate_set.size = 1; | |
1df65547 WS |
583 | } else { /* vwrq->fixed == 0 */ |
584 | if (vwrq->value > 0) { | |
585 | switch (vwrq->value) { | |
13a9930d | 586 | case 54000000: |
1df65547 WS |
587 | priv->reg.rate_set.body[11] = |
588 | TX_RATE_54M; | |
589 | i++; | |
13a9930d | 590 | case 48000000: |
1df65547 WS |
591 | priv->reg.rate_set.body[10] = |
592 | TX_RATE_48M; | |
593 | i++; | |
13a9930d | 594 | case 36000000: |
1df65547 WS |
595 | priv->reg.rate_set.body[9] = |
596 | TX_RATE_36M; | |
597 | i++; | |
598 | case 24000000: | |
599 | case 18000000: | |
600 | case 12000000: | |
601 | case 11000000: | |
602 | case 9000000: | |
603 | case 6000000: | |
604 | if (vwrq->value == 24000000) { | |
605 | priv->reg.rate_set.body[8] = | |
606 | TX_RATE_18M; | |
607 | i++; | |
608 | priv->reg.rate_set.body[7] = | |
609 | TX_RATE_9M; | |
610 | i++; | |
611 | priv->reg.rate_set.body[6] = | |
612 | TX_RATE_24M | BASIC_RATE; | |
613 | i++; | |
614 | priv->reg.rate_set.body[5] = | |
615 | TX_RATE_12M | BASIC_RATE; | |
616 | i++; | |
617 | priv->reg.rate_set.body[4] = | |
618 | TX_RATE_6M | BASIC_RATE; | |
619 | i++; | |
620 | priv->reg.rate_set.body[3] = | |
621 | TX_RATE_11M | BASIC_RATE; | |
622 | i++; | |
623 | } else if (vwrq->value == 18000000) { | |
624 | priv->reg.rate_set.body[7] = | |
625 | TX_RATE_18M; | |
626 | i++; | |
627 | priv->reg.rate_set.body[6] = | |
628 | TX_RATE_9M; | |
629 | i++; | |
630 | priv->reg.rate_set.body[5] = | |
631 | TX_RATE_12M | BASIC_RATE; | |
632 | i++; | |
633 | priv->reg.rate_set.body[4] = | |
634 | TX_RATE_6M | BASIC_RATE; | |
635 | i++; | |
636 | priv->reg.rate_set.body[3] = | |
637 | TX_RATE_11M | BASIC_RATE; | |
638 | i++; | |
639 | } else if (vwrq->value == 12000000) { | |
640 | priv->reg.rate_set.body[6] = | |
641 | TX_RATE_9M; | |
642 | i++; | |
643 | priv->reg.rate_set.body[5] = | |
644 | TX_RATE_12M | BASIC_RATE; | |
645 | i++; | |
646 | priv->reg.rate_set.body[4] = | |
647 | TX_RATE_6M | BASIC_RATE; | |
648 | i++; | |
649 | priv->reg.rate_set.body[3] = | |
650 | TX_RATE_11M | BASIC_RATE; | |
651 | i++; | |
652 | } else if (vwrq->value == 11000000) { | |
653 | priv->reg.rate_set.body[5] = | |
654 | TX_RATE_9M; | |
655 | i++; | |
656 | priv->reg.rate_set.body[4] = | |
657 | TX_RATE_6M | BASIC_RATE; | |
658 | i++; | |
659 | priv->reg.rate_set.body[3] = | |
660 | TX_RATE_11M | BASIC_RATE; | |
661 | i++; | |
662 | } else if (vwrq->value == 9000000) { | |
663 | priv->reg.rate_set.body[4] = | |
664 | TX_RATE_9M; | |
665 | i++; | |
666 | priv->reg.rate_set.body[3] = | |
667 | TX_RATE_6M | BASIC_RATE; | |
668 | i++; | |
669 | } else { /* vwrq->value == 6000000 */ | |
670 | priv->reg.rate_set.body[3] = | |
671 | TX_RATE_6M | BASIC_RATE; | |
672 | i++; | |
13a9930d | 673 | } |
1df65547 WS |
674 | case 5500000: |
675 | priv->reg.rate_set.body[2] = | |
676 | TX_RATE_5M | BASIC_RATE; | |
677 | i++; | |
678 | case 2000000: | |
679 | priv->reg.rate_set.body[1] = | |
680 | TX_RATE_2M | BASIC_RATE; | |
681 | i++; | |
682 | case 1000000: | |
683 | priv->reg.rate_set.body[0] = | |
684 | TX_RATE_1M | BASIC_RATE; | |
685 | i++; | |
13a9930d WS |
686 | break; |
687 | default: | |
688 | return -EINVAL; | |
689 | } | |
690 | priv->reg.tx_rate = TX_RATE_MANUAL_AUTO; | |
691 | priv->reg.rate_set.size = i; | |
1df65547 | 692 | } else { |
13a9930d WS |
693 | priv->reg.rate_set.body[11] = TX_RATE_54M; |
694 | priv->reg.rate_set.body[10] = TX_RATE_48M; | |
695 | priv->reg.rate_set.body[9] = TX_RATE_36M; | |
696 | priv->reg.rate_set.body[8] = TX_RATE_18M; | |
697 | priv->reg.rate_set.body[7] = TX_RATE_9M; | |
1df65547 WS |
698 | priv->reg.rate_set.body[6] = |
699 | TX_RATE_24M | BASIC_RATE; | |
700 | priv->reg.rate_set.body[5] = | |
701 | TX_RATE_12M | BASIC_RATE; | |
702 | priv->reg.rate_set.body[4] = | |
703 | TX_RATE_6M | BASIC_RATE; | |
704 | priv->reg.rate_set.body[3] = | |
705 | TX_RATE_11M | BASIC_RATE; | |
706 | priv->reg.rate_set.body[2] = | |
707 | TX_RATE_5M | BASIC_RATE; | |
708 | priv->reg.rate_set.body[1] = | |
709 | TX_RATE_2M | BASIC_RATE; | |
710 | priv->reg.rate_set.body[0] = | |
711 | TX_RATE_1M | BASIC_RATE; | |
13a9930d WS |
712 | priv->reg.tx_rate = TX_RATE_FULL_AUTO; |
713 | priv->reg.rate_set.size = 12; | |
714 | } | |
715 | } | |
716 | } | |
717 | ||
718 | priv->need_commit |= SME_MODE_SET; | |
719 | ||
720 | return -EINPROGRESS; /* Call commit handler */ | |
721 | } | |
722 | ||
723 | /*------------------------------------------------------------------*/ | |
724 | /* Wireless Handler : get Bit-Rate */ | |
1df65547 WS |
725 | static int ks_wlan_get_rate(struct net_device *dev, |
726 | struct iw_request_info *info, struct iw_param *vwrq, | |
727 | char *extra) | |
13a9930d | 728 | { |
1df65547 WS |
729 | struct ks_wlan_private *priv = |
730 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
731 | |
732 | DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n", | |
1df65547 | 733 | in_interrupt(), atomic_read(&update_phyinfo)); |
13a9930d | 734 | |
1df65547 WS |
735 | if (priv->sleep_mode == SLP_SLEEP) { |
736 | return -EPERM; | |
737 | } | |
738 | /* for SLEEP MODE */ | |
739 | if (!atomic_read(&update_phyinfo)) { | |
13a9930d WS |
740 | ks_wlan_update_phy_information(priv); |
741 | } | |
742 | vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000; | |
1df65547 | 743 | if (priv->reg.tx_rate == TX_RATE_FIXED) |
13a9930d WS |
744 | vwrq->fixed = 1; |
745 | else | |
746 | vwrq->fixed = 0; | |
747 | ||
748 | return 0; | |
749 | } | |
750 | ||
751 | /*------------------------------------------------------------------*/ | |
752 | /* Wireless Handler : set RTS threshold */ | |
753 | static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info, | |
754 | struct iw_param *vwrq, char *extra) | |
755 | { | |
1df65547 WS |
756 | struct ks_wlan_private *priv = |
757 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
758 | int rthr = vwrq->value; |
759 | ||
1df65547 WS |
760 | if (priv->sleep_mode == SLP_SLEEP) { |
761 | return -EPERM; | |
762 | } | |
763 | /* for SLEEP MODE */ | |
764 | if (vwrq->disabled) | |
13a9930d | 765 | rthr = 2347; |
1df65547 | 766 | if ((rthr < 0) || (rthr > 2347)) { |
13a9930d WS |
767 | return -EINVAL; |
768 | } | |
769 | priv->reg.rts = rthr; | |
770 | priv->need_commit |= SME_RTS; | |
771 | ||
772 | return -EINPROGRESS; /* Call commit handler */ | |
773 | } | |
774 | ||
775 | /*------------------------------------------------------------------*/ | |
776 | /* Wireless Handler : get RTS threshold */ | |
777 | static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info, | |
778 | struct iw_param *vwrq, char *extra) | |
779 | { | |
1df65547 WS |
780 | struct ks_wlan_private *priv = |
781 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 782 | |
1df65547 WS |
783 | if (priv->sleep_mode == SLP_SLEEP) { |
784 | return -EPERM; | |
785 | } | |
786 | /* for SLEEP MODE */ | |
13a9930d WS |
787 | vwrq->value = priv->reg.rts; |
788 | vwrq->disabled = (vwrq->value >= 2347); | |
789 | vwrq->fixed = 1; | |
790 | ||
791 | return 0; | |
792 | } | |
793 | ||
794 | /*------------------------------------------------------------------*/ | |
795 | /* Wireless Handler : set Fragmentation threshold */ | |
1df65547 WS |
796 | static int ks_wlan_set_frag(struct net_device *dev, |
797 | struct iw_request_info *info, struct iw_param *vwrq, | |
798 | char *extra) | |
13a9930d | 799 | { |
1df65547 WS |
800 | struct ks_wlan_private *priv = |
801 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
802 | int fthr = vwrq->value; |
803 | ||
1df65547 WS |
804 | if (priv->sleep_mode == SLP_SLEEP) { |
805 | return -EPERM; | |
806 | } | |
807 | /* for SLEEP MODE */ | |
808 | if (vwrq->disabled) | |
13a9930d | 809 | fthr = 2346; |
1df65547 | 810 | if ((fthr < 256) || (fthr > 2346)) { |
13a9930d WS |
811 | return -EINVAL; |
812 | } | |
813 | fthr &= ~0x1; /* Get an even value - is it really needed ??? */ | |
814 | priv->reg.fragment = fthr; | |
815 | priv->need_commit |= SME_FRAG; | |
816 | ||
817 | return -EINPROGRESS; /* Call commit handler */ | |
818 | } | |
819 | ||
820 | /*------------------------------------------------------------------*/ | |
821 | /* Wireless Handler : get Fragmentation threshold */ | |
1df65547 WS |
822 | static int ks_wlan_get_frag(struct net_device *dev, |
823 | struct iw_request_info *info, struct iw_param *vwrq, | |
824 | char *extra) | |
13a9930d | 825 | { |
1df65547 WS |
826 | struct ks_wlan_private *priv = |
827 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 828 | |
1df65547 WS |
829 | if (priv->sleep_mode == SLP_SLEEP) { |
830 | return -EPERM; | |
831 | } | |
832 | /* for SLEEP MODE */ | |
13a9930d WS |
833 | vwrq->value = priv->reg.fragment; |
834 | vwrq->disabled = (vwrq->value >= 2346); | |
835 | vwrq->fixed = 1; | |
836 | ||
837 | return 0; | |
838 | } | |
839 | ||
840 | /*------------------------------------------------------------------*/ | |
841 | /* Wireless Handler : set Mode of Operation */ | |
1df65547 WS |
842 | static int ks_wlan_set_mode(struct net_device *dev, |
843 | struct iw_request_info *info, __u32 * uwrq, | |
844 | char *extra) | |
13a9930d | 845 | { |
1df65547 WS |
846 | struct ks_wlan_private *priv = |
847 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 848 | |
1df65547 | 849 | DPRINTK(2, "mode=%d\n", *uwrq); |
13a9930d | 850 | |
1df65547 WS |
851 | if (priv->sleep_mode == SLP_SLEEP) { |
852 | return -EPERM; | |
853 | } | |
854 | /* for SLEEP MODE */ | |
855 | switch (*uwrq) { | |
13a9930d WS |
856 | case IW_MODE_ADHOC: |
857 | priv->reg.operation_mode = MODE_ADHOC; | |
858 | priv->need_commit |= SME_MODE_SET; | |
859 | break; | |
860 | case IW_MODE_INFRA: | |
861 | priv->reg.operation_mode = MODE_INFRASTRUCTURE; | |
862 | priv->need_commit |= SME_MODE_SET; | |
863 | break; | |
864 | case IW_MODE_AUTO: | |
865 | case IW_MODE_MASTER: | |
866 | case IW_MODE_REPEAT: | |
867 | case IW_MODE_SECOND: | |
868 | case IW_MODE_MONITOR: | |
869 | default: | |
870 | return -EINVAL; | |
871 | } | |
872 | ||
1df65547 | 873 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
874 | } |
875 | ||
876 | /*------------------------------------------------------------------*/ | |
877 | /* Wireless Handler : get Mode of Operation */ | |
1df65547 WS |
878 | static int ks_wlan_get_mode(struct net_device *dev, |
879 | struct iw_request_info *info, __u32 * uwrq, | |
880 | char *extra) | |
13a9930d | 881 | { |
1df65547 WS |
882 | struct ks_wlan_private *priv = |
883 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 884 | |
1df65547 WS |
885 | if (priv->sleep_mode == SLP_SLEEP) { |
886 | return -EPERM; | |
887 | } | |
13a9930d | 888 | |
1df65547 | 889 | /* for SLEEP MODE */ |
13a9930d WS |
890 | /* If not managed, assume it's ad-hoc */ |
891 | switch (priv->reg.operation_mode) { | |
1df65547 WS |
892 | case MODE_INFRASTRUCTURE: |
893 | *uwrq = IW_MODE_INFRA; | |
894 | break; | |
895 | case MODE_ADHOC: | |
896 | *uwrq = IW_MODE_ADHOC; | |
897 | break; | |
898 | default: | |
899 | *uwrq = IW_MODE_ADHOC; | |
13a9930d WS |
900 | } |
901 | ||
902 | return 0; | |
903 | } | |
904 | ||
905 | /*------------------------------------------------------------------*/ | |
906 | /* Wireless Handler : set Encryption Key */ | |
1df65547 WS |
907 | static int ks_wlan_set_encode(struct net_device *dev, |
908 | struct iw_request_info *info, | |
909 | struct iw_point *dwrq, char *extra) | |
13a9930d | 910 | { |
1df65547 WS |
911 | struct ks_wlan_private *priv = |
912 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
913 | |
914 | wep_key_t key; | |
915 | int index = (dwrq->flags & IW_ENCODE_INDEX); | |
916 | int current_index = priv->reg.wep_index; | |
917 | int i; | |
918 | ||
1df65547 | 919 | DPRINTK(2, "flags=%04X\n", dwrq->flags); |
13a9930d | 920 | |
1df65547 WS |
921 | if (priv->sleep_mode == SLP_SLEEP) { |
922 | return -EPERM; | |
923 | } | |
13a9930d | 924 | |
1df65547 | 925 | /* for SLEEP MODE */ |
13a9930d | 926 | /* index check */ |
1df65547 | 927 | if ((index < 0) || (index > 4)) |
13a9930d | 928 | return -EINVAL; |
1df65547 | 929 | else if (index == 0) |
13a9930d WS |
930 | index = current_index; |
931 | else | |
932 | index--; | |
933 | ||
934 | /* Is WEP supported ? */ | |
935 | /* Basic checking: do we have a key to set ? */ | |
936 | if (dwrq->length > 0) { | |
1df65547 | 937 | if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */ |
13a9930d WS |
938 | return -EINVAL; |
939 | } | |
1df65547 | 940 | if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */ |
13a9930d WS |
941 | key.len = MAX_KEY_SIZE; |
942 | priv->reg.privacy_invoked = 0x01; | |
943 | priv->need_commit |= SME_WEP_FLAG; | |
944 | wep_on_off = WEP_ON_128BIT; | |
945 | } else { | |
946 | if (dwrq->length > 0) { | |
947 | key.len = MIN_KEY_SIZE; | |
948 | priv->reg.privacy_invoked = 0x01; | |
949 | priv->need_commit |= SME_WEP_FLAG; | |
950 | wep_on_off = WEP_ON_64BIT; | |
1df65547 | 951 | } else { /* Disable the key */ |
13a9930d WS |
952 | key.len = 0; |
953 | } | |
954 | } | |
955 | /* Check if the key is not marked as invalid */ | |
1df65547 | 956 | if (!(dwrq->flags & IW_ENCODE_NOKEY)) { |
13a9930d WS |
957 | /* Cleanup */ |
958 | memset(key.key, 0, MAX_KEY_SIZE); | |
959 | /* Copy the key in the driver */ | |
1df65547 WS |
960 | if (copy_from_user |
961 | (key.key, dwrq->pointer, dwrq->length)) { | |
13a9930d WS |
962 | key.len = 0; |
963 | return -EFAULT; | |
964 | } | |
965 | /* Send the key to the card */ | |
966 | priv->reg.wep_key[index].size = key.len; | |
1df65547 | 967 | for (i = 0; i < (priv->reg.wep_key[index].size); i++) { |
13a9930d WS |
968 | priv->reg.wep_key[index].val[i] = key.key[i]; |
969 | } | |
1df65547 | 970 | priv->need_commit |= (SME_WEP_VAL1 << index); |
13a9930d WS |
971 | priv->reg.wep_index = index; |
972 | priv->need_commit |= SME_WEP_INDEX; | |
973 | } | |
974 | } else { | |
1df65547 | 975 | if (dwrq->flags & IW_ENCODE_DISABLED) { |
13a9930d WS |
976 | priv->reg.wep_key[0].size = 0; |
977 | priv->reg.wep_key[1].size = 0; | |
978 | priv->reg.wep_key[2].size = 0; | |
979 | priv->reg.wep_key[3].size = 0; | |
980 | priv->reg.privacy_invoked = 0x00; | |
1df65547 | 981 | if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) { |
13a9930d WS |
982 | priv->need_commit |= SME_MODE_SET; |
983 | } | |
984 | priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; | |
985 | wep_on_off = WEP_OFF; | |
986 | priv->need_commit |= SME_WEP_FLAG; | |
1df65547 | 987 | } else { |
13a9930d | 988 | /* Do we want to just set the transmit key index ? */ |
1df65547 WS |
989 | if ((index >= 0) && (index < 4)) { |
990 | /* set_wep_key(priv, index, 0, 0, 1); xxx */ | |
991 | if (priv->reg.wep_key[index].size) { | |
13a9930d WS |
992 | priv->reg.wep_index = index; |
993 | priv->need_commit |= SME_WEP_INDEX; | |
1df65547 | 994 | } else |
13a9930d WS |
995 | return -EINVAL; |
996 | } | |
997 | } | |
998 | } | |
999 | ||
1000 | /* Commit the changes if needed */ | |
1df65547 | 1001 | if (dwrq->flags & IW_ENCODE_MODE) |
13a9930d WS |
1002 | priv->need_commit |= SME_WEP_FLAG; |
1003 | ||
1df65547 WS |
1004 | if (dwrq->flags & IW_ENCODE_OPEN) { |
1005 | if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) { | |
13a9930d WS |
1006 | priv->need_commit |= SME_MODE_SET; |
1007 | } | |
1008 | priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; | |
1df65547 WS |
1009 | } else if (dwrq->flags & IW_ENCODE_RESTRICTED) { |
1010 | if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) { | |
13a9930d WS |
1011 | priv->need_commit |= SME_MODE_SET; |
1012 | } | |
1013 | priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY; | |
1014 | } | |
1df65547 WS |
1015 | // return -EINPROGRESS; /* Call commit handler */ |
1016 | if (priv->need_commit) { | |
13a9930d | 1017 | ks_wlan_setup_parameter(priv, priv->need_commit); |
1df65547 | 1018 | priv->need_commit = 0; |
13a9930d WS |
1019 | } |
1020 | return 0; | |
1021 | } | |
1022 | ||
1023 | /*------------------------------------------------------------------*/ | |
1024 | /* Wireless Handler : get Encryption Key */ | |
1df65547 WS |
1025 | static int ks_wlan_get_encode(struct net_device *dev, |
1026 | struct iw_request_info *info, | |
1027 | struct iw_point *dwrq, char *extra) | |
13a9930d | 1028 | { |
1df65547 WS |
1029 | struct ks_wlan_private *priv = |
1030 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1031 | char zeros[16]; |
1032 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
1033 | ||
1df65547 WS |
1034 | if (priv->sleep_mode == SLP_SLEEP) { |
1035 | return -EPERM; | |
1036 | } | |
1037 | /* for SLEEP MODE */ | |
13a9930d WS |
1038 | dwrq->flags = IW_ENCODE_DISABLED; |
1039 | ||
1040 | /* Check encryption mode */ | |
1df65547 | 1041 | switch (priv->reg.authenticate_type) { |
13a9930d WS |
1042 | case AUTH_TYPE_OPEN_SYSTEM: |
1043 | dwrq->flags = IW_ENCODE_OPEN; | |
1044 | break; | |
1045 | case AUTH_TYPE_SHARED_KEY: | |
1046 | dwrq->flags = IW_ENCODE_RESTRICTED; | |
1047 | break; | |
1048 | } | |
1049 | ||
1df65547 | 1050 | memset(zeros, 0, sizeof(zeros)); |
13a9930d WS |
1051 | |
1052 | /* Which key do we want ? -1 -> tx index */ | |
1df65547 | 1053 | if ((index < 0) || (index >= 4)) |
13a9930d | 1054 | index = priv->reg.wep_index; |
1df65547 | 1055 | if (priv->reg.privacy_invoked) { |
13a9930d WS |
1056 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
1057 | /* dwrq->flags |= IW_ENCODE_NOKEY; */ | |
1058 | } | |
1059 | dwrq->flags |= index + 1; | |
1df65547 | 1060 | DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags); |
13a9930d | 1061 | /* Copy the key to the user buffer */ |
1df65547 | 1062 | if ((index >= 0) && (index < 4)) |
13a9930d WS |
1063 | dwrq->length = priv->reg.wep_key[index].size; |
1064 | if (dwrq->length > 16) { | |
1df65547 | 1065 | dwrq->length = 0; |
13a9930d | 1066 | } |
1df65547 | 1067 | #if 1 /* IW_ENCODE_NOKEY; */ |
13a9930d | 1068 | if (dwrq->length) { |
1df65547 WS |
1069 | if ((index >= 0) && (index < 4)) |
1070 | memcpy(extra, priv->reg.wep_key[index].val, | |
1071 | dwrq->length); | |
13a9930d | 1072 | } else |
1df65547 | 1073 | memcpy(extra, zeros, dwrq->length); |
13a9930d WS |
1074 | #endif |
1075 | return 0; | |
1076 | } | |
1077 | ||
1078 | #ifndef KSC_OPNOTSUPP | |
1079 | /*------------------------------------------------------------------*/ | |
1080 | /* Wireless Handler : set Tx-Power */ | |
1df65547 WS |
1081 | static int ks_wlan_set_txpow(struct net_device *dev, |
1082 | struct iw_request_info *info, | |
1083 | struct iw_param *vwrq, char *extra) | |
13a9930d | 1084 | { |
1df65547 | 1085 | return -EOPNOTSUPP; /* Not Support */ |
13a9930d WS |
1086 | } |
1087 | ||
1088 | /*------------------------------------------------------------------*/ | |
1089 | /* Wireless Handler : get Tx-Power */ | |
1df65547 WS |
1090 | static int ks_wlan_get_txpow(struct net_device *dev, |
1091 | struct iw_request_info *info, | |
1092 | struct iw_param *vwrq, char *extra) | |
13a9930d | 1093 | { |
1df65547 WS |
1094 | if (priv->sleep_mode == SLP_SLEEP) { |
1095 | return -EPERM; | |
1096 | } | |
13a9930d | 1097 | |
1df65547 | 1098 | /* for SLEEP MODE */ |
13a9930d WS |
1099 | /* Not Support */ |
1100 | vwrq->value = 0; | |
1101 | vwrq->disabled = (vwrq->value == 0); | |
1102 | vwrq->fixed = 1; | |
1103 | return 0; | |
1104 | } | |
1105 | ||
1106 | /*------------------------------------------------------------------*/ | |
1107 | /* Wireless Handler : set Retry limits */ | |
1df65547 WS |
1108 | static int ks_wlan_set_retry(struct net_device *dev, |
1109 | struct iw_request_info *info, | |
1110 | struct iw_param *vwrq, char *extra) | |
13a9930d | 1111 | { |
1df65547 | 1112 | return -EOPNOTSUPP; /* Not Support */ |
13a9930d WS |
1113 | } |
1114 | ||
1115 | /*------------------------------------------------------------------*/ | |
1116 | /* Wireless Handler : get Retry limits */ | |
1df65547 WS |
1117 | static int ks_wlan_get_retry(struct net_device *dev, |
1118 | struct iw_request_info *info, | |
1119 | struct iw_param *vwrq, char *extra) | |
13a9930d | 1120 | { |
1df65547 WS |
1121 | if (priv->sleep_mode == SLP_SLEEP) { |
1122 | return -EPERM; | |
1123 | } | |
13a9930d | 1124 | |
1df65547 | 1125 | /* for SLEEP MODE */ |
13a9930d WS |
1126 | /* Not Support */ |
1127 | vwrq->value = 0; | |
1128 | vwrq->disabled = (vwrq->value == 0); | |
1129 | vwrq->fixed = 1; | |
1130 | return 0; | |
1131 | } | |
1132 | #endif /* KSC_OPNOTSUPP */ | |
1133 | ||
1134 | /*------------------------------------------------------------------*/ | |
1135 | /* Wireless Handler : get range info */ | |
1df65547 WS |
1136 | static int ks_wlan_get_range(struct net_device *dev, |
1137 | struct iw_request_info *info, | |
1138 | struct iw_point *dwrq, char *extra) | |
13a9930d | 1139 | { |
1df65547 WS |
1140 | struct ks_wlan_private *priv = |
1141 | (struct ks_wlan_private *)netdev_priv(dev); | |
1142 | struct iw_range *range = (struct iw_range *)extra; | |
1143 | int i, k; | |
13a9930d | 1144 | |
1df65547 | 1145 | DPRINTK(2, "\n"); |
13a9930d | 1146 | |
1df65547 WS |
1147 | if (priv->sleep_mode == SLP_SLEEP) { |
1148 | return -EPERM; | |
1149 | } | |
1150 | /* for SLEEP MODE */ | |
13a9930d WS |
1151 | dwrq->length = sizeof(struct iw_range); |
1152 | memset(range, 0, sizeof(*range)); | |
1153 | range->min_nwid = 0x0000; | |
1154 | range->max_nwid = 0x0000; | |
1155 | range->num_channels = 14; | |
1156 | /* Should be based on cap_rid.country to give only | |
1157 | * what the current card support */ | |
1158 | k = 0; | |
1df65547 WS |
1159 | for (i = 0; i < 13; i++) { /* channel 1 -- 13 */ |
1160 | range->freq[k].i = i + 1; /* List index */ | |
13a9930d WS |
1161 | range->freq[k].m = frequency_list[i] * 100000; |
1162 | range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ | |
1163 | } | |
1164 | range->num_frequency = k; | |
1df65547 WS |
1165 | if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */ |
1166 | range->freq[13].i = 14; /* List index */ | |
13a9930d WS |
1167 | range->freq[13].m = frequency_list[13] * 100000; |
1168 | range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ | |
1169 | range->num_frequency = 14; | |
1170 | } | |
1171 | ||
1172 | /* Hum... Should put the right values there */ | |
1173 | range->max_qual.qual = 100; | |
1174 | range->max_qual.level = 256 - 128; /* 0 dBm? */ | |
1175 | range->max_qual.noise = 256 - 128; | |
1df65547 | 1176 | range->sensitivity = 1; |
13a9930d | 1177 | |
1df65547 | 1178 | if (priv->reg.phy_type == D_11B_ONLY_MODE) { |
13a9930d WS |
1179 | range->bitrate[0] = 1e6; |
1180 | range->bitrate[1] = 2e6; | |
1181 | range->bitrate[2] = 5.5e6; | |
1182 | range->bitrate[3] = 11e6; | |
1183 | range->num_bitrates = 4; | |
1df65547 | 1184 | } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */ |
13a9930d WS |
1185 | range->bitrate[0] = 1e6; |
1186 | range->bitrate[1] = 2e6; | |
1187 | range->bitrate[2] = 5.5e6; | |
1188 | range->bitrate[3] = 11e6; | |
1189 | ||
1190 | range->bitrate[4] = 6e6; | |
1191 | range->bitrate[5] = 9e6; | |
1192 | range->bitrate[6] = 12e6; | |
1df65547 | 1193 | if (IW_MAX_BITRATES < 9) { |
13a9930d WS |
1194 | range->bitrate[7] = 54e6; |
1195 | range->num_bitrates = 8; | |
1df65547 | 1196 | } else { |
13a9930d WS |
1197 | range->bitrate[7] = 18e6; |
1198 | range->bitrate[8] = 24e6; | |
1199 | range->bitrate[9] = 36e6; | |
1200 | range->bitrate[10] = 48e6; | |
1201 | range->bitrate[11] = 54e6; | |
1202 | ||
1203 | range->num_bitrates = 12; | |
1204 | } | |
1205 | } | |
1206 | ||
1207 | /* Set an indication of the max TCP throughput | |
1208 | * in bit/s that we can expect using this interface. | |
1209 | * May be use for QoS stuff... Jean II */ | |
1df65547 | 1210 | if (i > 2) |
13a9930d WS |
1211 | range->throughput = 5000 * 1000; |
1212 | else | |
1213 | range->throughput = 1500 * 1000; | |
1214 | ||
1215 | range->min_rts = 0; | |
1216 | range->max_rts = 2347; | |
1217 | range->min_frag = 256; | |
1218 | range->max_frag = 2346; | |
1219 | ||
1df65547 WS |
1220 | range->encoding_size[0] = 5; /* WEP: RC4 40 bits */ |
1221 | range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */ | |
1222 | range->num_encoding_sizes = 2; | |
13a9930d WS |
1223 | range->max_encoding_tokens = 4; |
1224 | ||
1225 | /* power management not support */ | |
1226 | range->pmp_flags = IW_POWER_ON; | |
1227 | range->pmt_flags = IW_POWER_ON; | |
1228 | range->pm_capa = 0; | |
1229 | ||
1230 | /* Transmit Power - values are in dBm( or mW) */ | |
1df65547 | 1231 | range->txpower[0] = -256; |
13a9930d WS |
1232 | range->num_txpower = 1; |
1233 | range->txpower_capa = IW_TXPOW_DBM; | |
1234 | /* range->txpower_capa = IW_TXPOW_MWATT; */ | |
1235 | ||
1236 | range->we_version_source = 21; | |
1237 | range->we_version_compiled = WIRELESS_EXT; | |
1238 | ||
1239 | range->retry_capa = IW_RETRY_ON; | |
1df65547 WS |
1240 | range->retry_flags = IW_RETRY_ON; |
1241 | range->r_time_flags = IW_RETRY_ON; | |
13a9930d WS |
1242 | |
1243 | /* Experimental measurements - boundary 11/5.5 Mb/s */ | |
1244 | /* Note : with or without the (local->rssi), results | |
1245 | * are somewhat different. - Jean II */ | |
1246 | range->avg_qual.qual = 50; | |
1247 | range->avg_qual.level = 186; /* -70 dBm */ | |
1248 | range->avg_qual.noise = 0; | |
1249 | ||
13a9930d WS |
1250 | /* Event capability (kernel + driver) */ |
1251 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | |
1252 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | | |
1253 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); | |
1254 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
1255 | range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) | | |
1256 | IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE)); | |
1257 | ||
1258 | /* encode extension (WPA) capability */ | |
1df65547 | 1259 | range->enc_capa = (IW_ENC_CAPA_WPA | |
13a9930d | 1260 | IW_ENC_CAPA_WPA2 | |
1df65547 | 1261 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP); |
13a9930d WS |
1262 | return 0; |
1263 | } | |
1264 | ||
13a9930d WS |
1265 | /*------------------------------------------------------------------*/ |
1266 | /* Wireless Handler : set Power Management */ | |
1df65547 WS |
1267 | static int ks_wlan_set_power(struct net_device *dev, |
1268 | struct iw_request_info *info, | |
1269 | struct iw_param *vwrq, char *extra) | |
13a9930d | 1270 | { |
1df65547 WS |
1271 | struct ks_wlan_private *priv = |
1272 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1273 | short enabled; |
1274 | ||
1df65547 WS |
1275 | if (priv->sleep_mode == SLP_SLEEP) { |
1276 | return -EPERM; | |
1277 | } | |
1278 | /* for SLEEP MODE */ | |
13a9930d | 1279 | enabled = vwrq->disabled ? 0 : 1; |
1df65547 | 1280 | if (enabled == 0) { /* 0 */ |
13a9930d | 1281 | priv->reg.powermgt = POWMGT_ACTIVE_MODE; |
1df65547 WS |
1282 | } else if (enabled) { /* 1 */ |
1283 | if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) | |
1284 | priv->reg.powermgt = POWMGT_SAVE1_MODE; | |
1285 | else | |
1286 | return -EINVAL; | |
1287 | } else if (enabled) { /* 2 */ | |
1288 | if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) | |
13a9930d WS |
1289 | priv->reg.powermgt = POWMGT_SAVE2_MODE; |
1290 | else | |
1291 | return -EINVAL; | |
1df65547 WS |
1292 | } else |
1293 | return -EINVAL; | |
13a9930d WS |
1294 | |
1295 | hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST); | |
1296 | ||
1297 | return 0; | |
1298 | } | |
1299 | ||
1300 | /*------------------------------------------------------------------*/ | |
1301 | /* Wireless Handler : get Power Management */ | |
1df65547 WS |
1302 | static int ks_wlan_get_power(struct net_device *dev, |
1303 | struct iw_request_info *info, | |
1304 | struct iw_param *vwrq, char *extra) | |
13a9930d | 1305 | { |
1df65547 WS |
1306 | struct ks_wlan_private *priv = |
1307 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 1308 | |
1df65547 WS |
1309 | if (priv->sleep_mode == SLP_SLEEP) { |
1310 | return -EPERM; | |
1311 | } | |
1312 | /* for SLEEP MODE */ | |
1313 | if (priv->reg.powermgt > 0) | |
1314 | vwrq->disabled = 0; | |
13a9930d | 1315 | else |
1df65547 | 1316 | vwrq->disabled = 1; |
13a9930d WS |
1317 | |
1318 | return 0; | |
1319 | } | |
1320 | ||
1321 | /*------------------------------------------------------------------*/ | |
1322 | /* Wireless Handler : get wirless statistics */ | |
1df65547 WS |
1323 | static int ks_wlan_get_iwstats(struct net_device *dev, |
1324 | struct iw_request_info *info, | |
1325 | struct iw_quality *vwrq, char *extra) | |
13a9930d | 1326 | { |
1df65547 WS |
1327 | struct ks_wlan_private *priv = |
1328 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 1329 | |
1df65547 WS |
1330 | if (priv->sleep_mode == SLP_SLEEP) { |
1331 | return -EPERM; | |
1332 | } | |
1333 | /* for SLEEP MODE */ | |
1334 | vwrq->qual = 0; /* not supported */ | |
1335 | vwrq->level = priv->wstats.qual.level; | |
1336 | vwrq->noise = 0; /* not supported */ | |
13a9930d WS |
1337 | vwrq->updated = 0; |
1338 | ||
1339 | return 0; | |
1340 | } | |
1341 | ||
1342 | #ifndef KSC_OPNOTSUPP | |
1343 | /*------------------------------------------------------------------*/ | |
1344 | /* Wireless Handler : set Sensitivity */ | |
1df65547 WS |
1345 | static int ks_wlan_set_sens(struct net_device *dev, |
1346 | struct iw_request_info *info, struct iw_param *vwrq, | |
1347 | char *extra) | |
13a9930d | 1348 | { |
1df65547 | 1349 | return -EOPNOTSUPP; /* Not Support */ |
13a9930d WS |
1350 | } |
1351 | ||
1352 | /*------------------------------------------------------------------*/ | |
1353 | /* Wireless Handler : get Sensitivity */ | |
1df65547 WS |
1354 | static int ks_wlan_get_sens(struct net_device *dev, |
1355 | struct iw_request_info *info, struct iw_param *vwrq, | |
1356 | char *extra) | |
13a9930d WS |
1357 | { |
1358 | /* Not Support */ | |
1359 | vwrq->value = 0; | |
1360 | vwrq->disabled = (vwrq->value == 0); | |
1361 | vwrq->fixed = 1; | |
1362 | return 0; | |
1363 | } | |
1364 | #endif /* KSC_OPNOTSUPP */ | |
1365 | ||
13a9930d WS |
1366 | /*------------------------------------------------------------------*/ |
1367 | /* Wireless Handler : get AP List */ | |
1368 | /* Note : this is deprecated in favor of IWSCAN */ | |
1df65547 WS |
1369 | static int ks_wlan_get_aplist(struct net_device *dev, |
1370 | struct iw_request_info *info, | |
1371 | struct iw_point *dwrq, char *extra) | |
13a9930d | 1372 | { |
1df65547 WS |
1373 | struct ks_wlan_private *priv = |
1374 | (struct ks_wlan_private *)netdev_priv(dev); | |
1375 | struct sockaddr *address = (struct sockaddr *)extra; | |
13a9930d WS |
1376 | struct iw_quality qual[LOCAL_APLIST_MAX]; |
1377 | ||
1378 | int i; | |
1379 | ||
1df65547 WS |
1380 | if (priv->sleep_mode == SLP_SLEEP) { |
1381 | return -EPERM; | |
1382 | } | |
1383 | /* for SLEEP MODE */ | |
13a9930d | 1384 | for (i = 0; i < priv->aplist.size; i++) { |
1df65547 WS |
1385 | memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]), |
1386 | ETH_ALEN); | |
13a9930d WS |
1387 | address[i].sa_family = ARPHRD_ETHER; |
1388 | qual[i].level = 256 - priv->aplist.ap[i].rssi; | |
1389 | qual[i].qual = priv->aplist.ap[i].sq; | |
1df65547 | 1390 | qual[i].noise = 0; /* invalid noise value */ |
13a9930d WS |
1391 | qual[i].updated = 7; |
1392 | } | |
1df65547 WS |
1393 | if (i) { |
1394 | dwrq->flags = 1; /* Should be define'd */ | |
1395 | memcpy(extra + sizeof(struct sockaddr) * i, | |
1396 | &qual, sizeof(struct iw_quality) * i); | |
13a9930d WS |
1397 | } |
1398 | dwrq->length = i; | |
1399 | ||
1400 | return 0; | |
1401 | } | |
1402 | ||
13a9930d WS |
1403 | /*------------------------------------------------------------------*/ |
1404 | /* Wireless Handler : Initiate Scan */ | |
1df65547 WS |
1405 | static int ks_wlan_set_scan(struct net_device *dev, |
1406 | struct iw_request_info *info, | |
1407 | union iwreq_data *wrqu, char *extra) | |
13a9930d | 1408 | { |
1df65547 WS |
1409 | struct ks_wlan_private *priv = |
1410 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 1411 | struct iw_scan_req *req = NULL; |
1df65547 | 1412 | DPRINTK(2, "\n"); |
13a9930d | 1413 | |
1df65547 WS |
1414 | if (priv->sleep_mode == SLP_SLEEP) { |
1415 | return -EPERM; | |
1416 | } | |
13a9930d | 1417 | |
1df65547 | 1418 | /* for SLEEP MODE */ |
13a9930d | 1419 | /* specified SSID SCAN */ |
1df65547 WS |
1420 | if (wrqu->data.length == sizeof(struct iw_scan_req) |
1421 | && wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
1422 | req = (struct iw_scan_req *)extra; | |
13a9930d WS |
1423 | priv->scan_ssid_len = req->essid_len; |
1424 | memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len); | |
1df65547 | 1425 | } else { |
13a9930d WS |
1426 | priv->scan_ssid_len = 0; |
1427 | } | |
1428 | ||
13a9930d WS |
1429 | priv->sme_i.sme_flag |= SME_AP_SCAN; |
1430 | hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST); | |
1431 | ||
1432 | /* At this point, just return to the user. */ | |
1433 | ||
1434 | return 0; | |
1435 | } | |
1436 | ||
1437 | /*------------------------------------------------------------------*/ | |
1438 | /* | |
1439 | * Translate scan data returned from the card to a card independent | |
1440 | * format that the Wireless Tools will understand - Jean II | |
1441 | */ | |
1df65547 WS |
1442 | static inline char *ks_wlan_translate_scan(struct net_device *dev, |
1443 | struct iw_request_info *info, | |
1444 | char *current_ev, char *end_buf, | |
1445 | struct local_ap_t *ap) | |
13a9930d | 1446 | { |
feedcf1a | 1447 | /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */ |
1df65547 | 1448 | struct iw_event iwe; /* Temporary buffer */ |
13a9930d WS |
1449 | u16 capabilities; |
1450 | char *current_val; /* For rates */ | |
1451 | int i; | |
1452 | static const char rsn_leader[] = "rsn_ie="; | |
1453 | static const char wpa_leader[] = "wpa_ie="; | |
1df65547 WS |
1454 | char buf0[RSN_IE_BODY_MAX * 2 + 30]; |
1455 | char buf1[RSN_IE_BODY_MAX * 2 + 30]; | |
13a9930d WS |
1456 | char *pbuf; |
1457 | /* First entry *MUST* be the AP MAC address */ | |
1458 | iwe.cmd = SIOCGIWAP; | |
1459 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
1460 | memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN); | |
1df65547 WS |
1461 | current_ev = |
1462 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1463 | IW_EV_ADDR_LEN); | |
13a9930d WS |
1464 | |
1465 | /* Other entries will be displayed in the order we give them */ | |
1466 | ||
1467 | /* Add the ESSID */ | |
1468 | iwe.u.data.length = ap->ssid.size; | |
1df65547 | 1469 | if (iwe.u.data.length > 32) |
13a9930d WS |
1470 | iwe.u.data.length = 32; |
1471 | iwe.cmd = SIOCGIWESSID; | |
1472 | iwe.u.data.flags = 1; | |
1df65547 WS |
1473 | current_ev = |
1474 | iwe_stream_add_point(info, current_ev, end_buf, &iwe, | |
1475 | &(ap->ssid.body[0])); | |
13a9930d WS |
1476 | |
1477 | /* Add mode */ | |
1478 | iwe.cmd = SIOCGIWMODE; | |
1479 | capabilities = le16_to_cpu(ap->capability); | |
1df65547 WS |
1480 | if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) { |
1481 | if (capabilities & BSS_CAP_ESS) | |
13a9930d WS |
1482 | iwe.u.mode = IW_MODE_INFRA; |
1483 | else | |
1484 | iwe.u.mode = IW_MODE_ADHOC; | |
1df65547 WS |
1485 | current_ev = |
1486 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1487 | IW_EV_UINT_LEN); | |
13a9930d WS |
1488 | } |
1489 | ||
1490 | /* Add frequency */ | |
1491 | iwe.cmd = SIOCGIWFREQ; | |
1492 | iwe.u.freq.m = ap->channel; | |
1df65547 | 1493 | iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000; |
13a9930d | 1494 | iwe.u.freq.e = 1; |
1df65547 WS |
1495 | current_ev = |
1496 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1497 | IW_EV_FREQ_LEN); | |
13a9930d WS |
1498 | |
1499 | /* Add quality statistics */ | |
1500 | iwe.cmd = IWEVQUAL; | |
1501 | iwe.u.qual.level = 256 - ap->rssi; | |
1502 | iwe.u.qual.qual = ap->sq; | |
1df65547 WS |
1503 | iwe.u.qual.noise = 0; /* invalid noise value */ |
1504 | current_ev = | |
1505 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1506 | IW_EV_QUAL_LEN); | |
13a9930d WS |
1507 | |
1508 | /* Add encryption capability */ | |
1509 | iwe.cmd = SIOCGIWENCODE; | |
1df65547 | 1510 | if (capabilities & BSS_CAP_PRIVACY) |
13a9930d WS |
1511 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
1512 | else | |
1513 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
1514 | iwe.u.data.length = 0; | |
1df65547 WS |
1515 | current_ev = |
1516 | iwe_stream_add_point(info, current_ev, end_buf, &iwe, | |
1517 | &(ap->ssid.body[0])); | |
13a9930d WS |
1518 | |
1519 | /* Rate : stuffing multiple values in a single event require a bit | |
1520 | * more of magic - Jean II */ | |
1521 | current_val = current_ev + IW_EV_LCP_LEN; | |
1522 | ||
1523 | iwe.cmd = SIOCGIWRATE; | |
1524 | /* Those two flags are ignored... */ | |
1525 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
1526 | ||
1527 | /* Max 16 values */ | |
1df65547 | 1528 | for (i = 0; i < 16; i++) { |
13a9930d | 1529 | /* NULL terminated */ |
1df65547 | 1530 | if (i >= ap->rate_set.size) |
13a9930d WS |
1531 | break; |
1532 | /* Bit rate given in 500 kb/s units (+ 0x80) */ | |
1533 | iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000); | |
1534 | /* Add new value to event */ | |
1df65547 WS |
1535 | current_val = |
1536 | iwe_stream_add_value(info, current_ev, current_val, end_buf, | |
1537 | &iwe, IW_EV_PARAM_LEN); | |
13a9930d WS |
1538 | } |
1539 | /* Check if we added any event */ | |
1df65547 | 1540 | if ((current_val - current_ev) > IW_EV_LCP_LEN) |
13a9930d WS |
1541 | current_ev = current_val; |
1542 | ||
1543 | #define GENERIC_INFO_ELEM_ID 0xdd | |
1544 | #define RSN_INFO_ELEM_ID 0x30 | |
1df65547 WS |
1545 | if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) { |
1546 | pbuf = &buf0[0]; | |
1547 | memset(&iwe, 0, sizeof(iwe)); | |
1548 | iwe.cmd = IWEVCUSTOM; | |
1549 | memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1); | |
1550 | iwe.u.data.length += sizeof(rsn_leader) - 1; | |
1551 | pbuf += sizeof(rsn_leader) - 1; | |
13a9930d | 1552 | |
1df65547 WS |
1553 | pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id); |
1554 | pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size); | |
1555 | iwe.u.data.length += 4; | |
13a9930d | 1556 | |
1df65547 WS |
1557 | for (i = 0; i < ap->rsn_ie.size; i++) |
1558 | pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]); | |
1559 | iwe.u.data.length += (ap->rsn_ie.size) * 2; | |
13a9930d | 1560 | |
1df65547 | 1561 | DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size); |
13a9930d | 1562 | |
1df65547 WS |
1563 | current_ev = |
1564 | iwe_stream_add_point(info, current_ev, end_buf, &iwe, | |
1565 | &buf0[0]); | |
1566 | } | |
1567 | if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) { | |
1568 | pbuf = &buf1[0]; | |
1569 | memset(&iwe, 0, sizeof(iwe)); | |
1570 | iwe.cmd = IWEVCUSTOM; | |
1571 | memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1); | |
1572 | iwe.u.data.length += sizeof(wpa_leader) - 1; | |
1573 | pbuf += sizeof(wpa_leader) - 1; | |
1574 | ||
1575 | pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id); | |
1576 | pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size); | |
1577 | iwe.u.data.length += 4; | |
1578 | ||
1579 | for (i = 0; i < ap->wpa_ie.size; i++) | |
1580 | pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]); | |
1581 | iwe.u.data.length += (ap->wpa_ie.size) * 2; | |
1582 | ||
1583 | DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size); | |
1584 | DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length); | |
1585 | ||
1586 | current_ev = | |
1587 | iwe_stream_add_point(info, current_ev, end_buf, &iwe, | |
1588 | &buf1[0]); | |
1589 | } | |
13a9930d WS |
1590 | |
1591 | /* The other data in the scan result are not really | |
1592 | * interesting, so for now drop it - Jean II */ | |
1593 | return current_ev; | |
1594 | } | |
1595 | ||
1596 | /*------------------------------------------------------------------*/ | |
1597 | /* Wireless Handler : Read Scan Results */ | |
1df65547 WS |
1598 | static int ks_wlan_get_scan(struct net_device *dev, |
1599 | struct iw_request_info *info, struct iw_point *dwrq, | |
1600 | char *extra) | |
13a9930d | 1601 | { |
1df65547 WS |
1602 | struct ks_wlan_private *priv = |
1603 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1604 | int i; |
1605 | char *current_ev = extra; | |
1df65547 | 1606 | DPRINTK(2, "\n"); |
13a9930d | 1607 | |
1df65547 WS |
1608 | if (priv->sleep_mode == SLP_SLEEP) { |
1609 | return -EPERM; | |
1610 | } | |
1611 | /* for SLEEP MODE */ | |
1612 | if (priv->sme_i.sme_flag & SME_AP_SCAN) { | |
1613 | DPRINTK(2, "flag AP_SCAN\n"); | |
13a9930d WS |
1614 | return -EAGAIN; |
1615 | } | |
1616 | ||
1df65547 | 1617 | if (priv->aplist.size == 0) { |
13a9930d WS |
1618 | /* Client error, no scan results... |
1619 | * The caller need to restart the scan. */ | |
1df65547 | 1620 | DPRINTK(2, "aplist 0\n"); |
13a9930d WS |
1621 | return -ENODATA; |
1622 | } | |
1623 | #if 0 | |
1624 | /* current connect ap */ | |
1df65547 | 1625 | if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) { |
13a9930d WS |
1626 | if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) { |
1627 | dwrq->length = 0; | |
1628 | return -E2BIG; | |
1629 | } | |
1630 | current_ev = ks_wlan_translate_scan(dev, current_ev, | |
1df65547 | 1631 | // extra + IW_SCAN_MAX_DATA, |
13a9930d WS |
1632 | extra + dwrq->length, |
1633 | &(priv->current_ap)); | |
1634 | } | |
1635 | #endif | |
1636 | /* Read and parse all entries */ | |
1df65547 | 1637 | for (i = 0; i < priv->aplist.size; i++) { |
13a9930d WS |
1638 | if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) { |
1639 | dwrq->length = 0; | |
1640 | return -E2BIG; | |
1641 | } | |
1642 | /* Translate to WE format this entry */ | |
1643 | current_ev = ks_wlan_translate_scan(dev, info, current_ev, | |
1df65547 | 1644 | // extra + IW_SCAN_MAX_DATA, |
13a9930d WS |
1645 | extra + dwrq->length, |
1646 | &(priv->aplist.ap[i])); | |
1647 | } | |
1648 | /* Length of data */ | |
1649 | dwrq->length = (current_ev - extra); | |
1650 | dwrq->flags = 0; | |
1651 | ||
1652 | return 0; | |
1653 | } | |
13a9930d WS |
1654 | |
1655 | /*------------------------------------------------------------------*/ | |
1656 | /* Commit handler : called after a bunch of SET operations */ | |
1df65547 WS |
1657 | static int ks_wlan_config_commit(struct net_device *dev, |
1658 | struct iw_request_info *info, void *zwrq, | |
1659 | char *extra) | |
13a9930d | 1660 | { |
1df65547 WS |
1661 | struct ks_wlan_private *priv = |
1662 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1663 | |
1664 | if (!priv->need_commit) | |
1665 | return 0; | |
1666 | ||
1667 | ks_wlan_setup_parameter(priv, priv->need_commit); | |
1df65547 | 1668 | priv->need_commit = 0; |
13a9930d WS |
1669 | return 0; |
1670 | } | |
1671 | ||
13a9930d WS |
1672 | /*------------------------------------------------------------------*/ |
1673 | /* Wireless handler : set association ie params */ | |
1df65547 WS |
1674 | static int ks_wlan_set_genie(struct net_device *dev, |
1675 | struct iw_request_info *info, | |
1676 | struct iw_point *dwrq, char *extra) | |
13a9930d | 1677 | { |
1df65547 WS |
1678 | struct ks_wlan_private *priv = |
1679 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1680 | |
1681 | DPRINTK(2, "\n"); | |
1682 | ||
1df65547 WS |
1683 | if (priv->sleep_mode == SLP_SLEEP) { |
1684 | return -EPERM; | |
1685 | } | |
1686 | /* for SLEEP MODE */ | |
13a9930d | 1687 | return 0; |
1df65547 | 1688 | // return -EOPNOTSUPP; |
13a9930d WS |
1689 | } |
1690 | ||
1691 | /*------------------------------------------------------------------*/ | |
1692 | /* Wireless handler : set authentication mode params */ | |
1df65547 WS |
1693 | static int ks_wlan_set_auth_mode(struct net_device *dev, |
1694 | struct iw_request_info *info, | |
13a9930d WS |
1695 | struct iw_param *vwrq, char *extra) |
1696 | { | |
1df65547 WS |
1697 | struct ks_wlan_private *priv = |
1698 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1699 | int index = (vwrq->flags & IW_AUTH_INDEX); |
1700 | int value = vwrq->value; | |
1701 | ||
1df65547 | 1702 | DPRINTK(2, "index=%d:value=%08X\n", index, value); |
13a9930d | 1703 | |
1df65547 WS |
1704 | if (priv->sleep_mode == SLP_SLEEP) { |
1705 | return -EPERM; | |
1706 | } | |
1707 | /* for SLEEP MODE */ | |
1708 | switch (index) { | |
1709 | case IW_AUTH_WPA_VERSION: /* 0 */ | |
1710 | switch (value) { | |
13a9930d WS |
1711 | case IW_AUTH_WPA_VERSION_DISABLED: |
1712 | priv->wpa.version = value; | |
1df65547 | 1713 | if (priv->wpa.rsn_enabled) { |
13a9930d WS |
1714 | priv->wpa.rsn_enabled = 0; |
1715 | } | |
1716 | priv->need_commit |= SME_RSN; | |
1717 | break; | |
1718 | case IW_AUTH_WPA_VERSION_WPA: | |
1719 | case IW_AUTH_WPA_VERSION_WPA2: | |
1720 | priv->wpa.version = value; | |
1df65547 | 1721 | if (!(priv->wpa.rsn_enabled)) { |
13a9930d WS |
1722 | priv->wpa.rsn_enabled = 1; |
1723 | } | |
1724 | priv->need_commit |= SME_RSN; | |
1725 | break; | |
1726 | default: | |
1727 | return -EOPNOTSUPP; | |
1728 | } | |
1729 | break; | |
1df65547 WS |
1730 | case IW_AUTH_CIPHER_PAIRWISE: /* 1 */ |
1731 | switch (value) { | |
13a9930d | 1732 | case IW_AUTH_CIPHER_NONE: |
1df65547 | 1733 | if (priv->reg.privacy_invoked) { |
13a9930d WS |
1734 | priv->reg.privacy_invoked = 0x00; |
1735 | priv->need_commit |= SME_WEP_FLAG; | |
1736 | } | |
1737 | break; | |
1738 | case IW_AUTH_CIPHER_WEP40: | |
1739 | case IW_AUTH_CIPHER_TKIP: | |
1740 | case IW_AUTH_CIPHER_CCMP: | |
1741 | case IW_AUTH_CIPHER_WEP104: | |
1df65547 | 1742 | if (!priv->reg.privacy_invoked) { |
13a9930d WS |
1743 | priv->reg.privacy_invoked = 0x01; |
1744 | priv->need_commit |= SME_WEP_FLAG; | |
1745 | } | |
1746 | priv->wpa.pairwise_suite = value; | |
1747 | priv->need_commit |= SME_RSN_UNICAST; | |
1748 | break; | |
1749 | default: | |
1750 | return -EOPNOTSUPP; | |
1751 | } | |
1752 | break; | |
1df65547 WS |
1753 | case IW_AUTH_CIPHER_GROUP: /* 2 */ |
1754 | switch (value) { | |
13a9930d | 1755 | case IW_AUTH_CIPHER_NONE: |
1df65547 | 1756 | if (priv->reg.privacy_invoked) { |
13a9930d WS |
1757 | priv->reg.privacy_invoked = 0x00; |
1758 | priv->need_commit |= SME_WEP_FLAG; | |
1759 | } | |
1760 | break; | |
1761 | case IW_AUTH_CIPHER_WEP40: | |
1762 | case IW_AUTH_CIPHER_TKIP: | |
1763 | case IW_AUTH_CIPHER_CCMP: | |
1764 | case IW_AUTH_CIPHER_WEP104: | |
1df65547 | 1765 | if (!priv->reg.privacy_invoked) { |
13a9930d WS |
1766 | priv->reg.privacy_invoked = 0x01; |
1767 | priv->need_commit |= SME_WEP_FLAG; | |
1768 | } | |
1769 | priv->wpa.group_suite = value; | |
1770 | priv->need_commit |= SME_RSN_MULTICAST; | |
1771 | break; | |
1772 | default: | |
1773 | return -EOPNOTSUPP; | |
1774 | } | |
1775 | break; | |
1df65547 WS |
1776 | case IW_AUTH_KEY_MGMT: /* 3 */ |
1777 | switch (value) { | |
13a9930d WS |
1778 | case IW_AUTH_KEY_MGMT_802_1X: |
1779 | case IW_AUTH_KEY_MGMT_PSK: | |
1df65547 WS |
1780 | case 0: /* NONE or 802_1X_NO_WPA */ |
1781 | case 4: /* WPA_NONE */ | |
13a9930d WS |
1782 | priv->wpa.key_mgmt_suite = value; |
1783 | priv->need_commit |= SME_RSN_AUTH; | |
1784 | break; | |
1785 | default: | |
1786 | return -EOPNOTSUPP; | |
1787 | } | |
1788 | break; | |
1df65547 WS |
1789 | case IW_AUTH_80211_AUTH_ALG: /* 6 */ |
1790 | switch (value) { | |
13a9930d WS |
1791 | case IW_AUTH_ALG_OPEN_SYSTEM: |
1792 | priv->wpa.auth_alg = value; | |
1793 | priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; | |
1794 | break; | |
1795 | case IW_AUTH_ALG_SHARED_KEY: | |
1796 | priv->wpa.auth_alg = value; | |
1797 | priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY; | |
1798 | break; | |
1799 | case IW_AUTH_ALG_LEAP: | |
1800 | default: | |
1801 | return -EOPNOTSUPP; | |
1802 | } | |
1803 | priv->need_commit |= SME_MODE_SET; | |
1804 | break; | |
1df65547 | 1805 | case IW_AUTH_WPA_ENABLED: /* 7 */ |
13a9930d WS |
1806 | priv->wpa.wpa_enabled = value; |
1807 | break; | |
1df65547 WS |
1808 | case IW_AUTH_PRIVACY_INVOKED: /* 10 */ |
1809 | if ((value && !priv->reg.privacy_invoked) || | |
1810 | (!value && priv->reg.privacy_invoked)) { | |
1811 | priv->reg.privacy_invoked = value ? 0x01 : 0x00; | |
13a9930d WS |
1812 | priv->need_commit |= SME_WEP_FLAG; |
1813 | } | |
1814 | break; | |
1df65547 WS |
1815 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */ |
1816 | case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */ | |
1817 | case IW_AUTH_DROP_UNENCRYPTED: /* 8 */ | |
1818 | case IW_AUTH_ROAMING_CONTROL: /* 9 */ | |
13a9930d WS |
1819 | default: |
1820 | break; | |
1821 | } | |
1822 | ||
1823 | /* return -EINPROGRESS; */ | |
1df65547 | 1824 | if (priv->need_commit) { |
13a9930d | 1825 | ks_wlan_setup_parameter(priv, priv->need_commit); |
1df65547 | 1826 | priv->need_commit = 0; |
13a9930d WS |
1827 | } |
1828 | return 0; | |
1829 | } | |
1830 | ||
1831 | /*------------------------------------------------------------------*/ | |
1832 | /* Wireless handler : get authentication mode params */ | |
1df65547 WS |
1833 | static int ks_wlan_get_auth_mode(struct net_device *dev, |
1834 | struct iw_request_info *info, | |
13a9930d WS |
1835 | struct iw_param *vwrq, char *extra) |
1836 | { | |
1df65547 WS |
1837 | struct ks_wlan_private *priv = |
1838 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 1839 | int index = (vwrq->flags & IW_AUTH_INDEX); |
1df65547 | 1840 | DPRINTK(2, "index=%d\n", index); |
13a9930d | 1841 | |
1df65547 WS |
1842 | if (priv->sleep_mode == SLP_SLEEP) { |
1843 | return -EPERM; | |
1844 | } | |
13a9930d | 1845 | |
1df65547 | 1846 | /* for SLEEP MODE */ |
13a9930d | 1847 | /* WPA (not used ?? wpa_supplicant) */ |
1df65547 | 1848 | switch (index) { |
13a9930d WS |
1849 | case IW_AUTH_WPA_VERSION: |
1850 | vwrq->value = priv->wpa.version; | |
1851 | break; | |
1852 | case IW_AUTH_CIPHER_PAIRWISE: | |
1853 | vwrq->value = priv->wpa.pairwise_suite; | |
1854 | break; | |
1855 | case IW_AUTH_CIPHER_GROUP: | |
1856 | vwrq->value = priv->wpa.group_suite; | |
1857 | break; | |
1858 | case IW_AUTH_KEY_MGMT: | |
1859 | vwrq->value = priv->wpa.key_mgmt_suite; | |
1860 | break; | |
1861 | case IW_AUTH_80211_AUTH_ALG: | |
1862 | vwrq->value = priv->wpa.auth_alg; | |
1863 | break; | |
1864 | case IW_AUTH_WPA_ENABLED: | |
1865 | vwrq->value = priv->wpa.rsn_enabled; | |
1866 | break; | |
1df65547 | 1867 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */ |
13a9930d WS |
1868 | case IW_AUTH_TKIP_COUNTERMEASURES: |
1869 | case IW_AUTH_DROP_UNENCRYPTED: | |
1870 | default: | |
1871 | /* return -EOPNOTSUPP; */ | |
1872 | break; | |
1873 | } | |
1874 | return 0; | |
1875 | } | |
1876 | ||
1877 | /*------------------------------------------------------------------*/ | |
1878 | /* Wireless Handler : set encoding token & mode (WPA)*/ | |
1df65547 WS |
1879 | static int ks_wlan_set_encode_ext(struct net_device *dev, |
1880 | struct iw_request_info *info, | |
13a9930d WS |
1881 | struct iw_point *dwrq, char *extra) |
1882 | { | |
1df65547 WS |
1883 | struct ks_wlan_private *priv = |
1884 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
1885 | struct iw_encode_ext *enc; |
1886 | int index = dwrq->flags & IW_ENCODE_INDEX; | |
1df65547 | 1887 | unsigned int commit = 0; |
13a9930d WS |
1888 | |
1889 | enc = (struct iw_encode_ext *)extra; | |
1890 | ||
1df65547 WS |
1891 | DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags, |
1892 | enc->ext_flags); | |
13a9930d | 1893 | |
1df65547 WS |
1894 | if (priv->sleep_mode == SLP_SLEEP) { |
1895 | return -EPERM; | |
1896 | } | |
1897 | /* for SLEEP MODE */ | |
1898 | if (index < 1 || index > 4) | |
13a9930d WS |
1899 | return -EINVAL; |
1900 | else | |
1901 | index--; | |
1902 | ||
1df65547 WS |
1903 | if (dwrq->flags & IW_ENCODE_DISABLED) { |
1904 | priv->wpa.key[index].key_len = 0; | |
13a9930d WS |
1905 | } |
1906 | ||
1df65547 WS |
1907 | if (enc) { |
1908 | priv->wpa.key[index].ext_flags = enc->ext_flags; | |
1909 | if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
1910 | priv->wpa.txkey = index; | |
13a9930d | 1911 | commit |= SME_WEP_INDEX; |
1df65547 | 1912 | } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { |
453e102d DC |
1913 | memcpy(&priv->wpa.key[index].rx_seq[0], |
1914 | enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE); | |
13a9930d WS |
1915 | } |
1916 | ||
1917 | memcpy(&priv->wpa.key[index].addr.sa_data[0], | |
1df65547 | 1918 | &enc->addr.sa_data[0], ETH_ALEN); |
13a9930d WS |
1919 | |
1920 | switch (enc->alg) { | |
1921 | case IW_ENCODE_ALG_NONE: | |
1df65547 | 1922 | if (priv->reg.privacy_invoked) { |
13a9930d WS |
1923 | priv->reg.privacy_invoked = 0x00; |
1924 | commit |= SME_WEP_FLAG; | |
1925 | } | |
1926 | priv->wpa.key[index].key_len = 0; | |
1927 | ||
1928 | break; | |
1929 | case IW_ENCODE_ALG_WEP: | |
1930 | case IW_ENCODE_ALG_CCMP: | |
1df65547 | 1931 | if (!priv->reg.privacy_invoked) { |
13a9930d WS |
1932 | priv->reg.privacy_invoked = 0x01; |
1933 | commit |= SME_WEP_FLAG; | |
1934 | } | |
453e102d | 1935 | if (enc->key_len) { |
13a9930d WS |
1936 | memcpy(&priv->wpa.key[index].key_val[0], |
1937 | &enc->key[0], enc->key_len); | |
1938 | priv->wpa.key[index].key_len = enc->key_len; | |
1939 | commit |= (SME_WEP_VAL1 << index); | |
1940 | } | |
1941 | break; | |
1942 | case IW_ENCODE_ALG_TKIP: | |
1df65547 | 1943 | if (!priv->reg.privacy_invoked) { |
13a9930d WS |
1944 | priv->reg.privacy_invoked = 0x01; |
1945 | commit |= SME_WEP_FLAG; | |
1946 | } | |
453e102d | 1947 | if (enc->key_len == 32) { |
13a9930d | 1948 | memcpy(&priv->wpa.key[index].key_val[0], |
1df65547 WS |
1949 | &enc->key[0], enc->key_len - 16); |
1950 | priv->wpa.key[index].key_len = | |
1951 | enc->key_len - 16; | |
1952 | if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */ | |
1953 | memcpy(&priv->wpa.key[index]. | |
1954 | tx_mic_key[0], &enc->key[16], 8); | |
1955 | memcpy(&priv->wpa.key[index]. | |
1956 | rx_mic_key[0], &enc->key[16], 8); | |
1957 | } else { | |
1958 | memcpy(&priv->wpa.key[index]. | |
1959 | tx_mic_key[0], &enc->key[16], 8); | |
1960 | memcpy(&priv->wpa.key[index]. | |
1961 | rx_mic_key[0], &enc->key[24], 8); | |
13a9930d WS |
1962 | } |
1963 | commit |= (SME_WEP_VAL1 << index); | |
1964 | } | |
1965 | break; | |
1966 | default: | |
1967 | return -EINVAL; | |
1968 | } | |
1df65547 WS |
1969 | priv->wpa.key[index].alg = enc->alg; |
1970 | } else | |
13a9930d WS |
1971 | return -EINVAL; |
1972 | ||
1df65547 WS |
1973 | if (commit) { |
1974 | if (commit & SME_WEP_INDEX) | |
13a9930d | 1975 | hostif_sme_enqueue(priv, SME_SET_TXKEY); |
1df65547 WS |
1976 | if (commit & SME_WEP_VAL_MASK) |
1977 | hostif_sme_enqueue(priv, SME_SET_KEY1 + index); | |
1978 | if (commit & SME_WEP_FLAG) | |
13a9930d WS |
1979 | hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST); |
1980 | } | |
1981 | ||
1982 | return 0; | |
1983 | } | |
1984 | ||
1985 | /*------------------------------------------------------------------*/ | |
1986 | /* Wireless Handler : get encoding token & mode (WPA)*/ | |
1df65547 WS |
1987 | static int ks_wlan_get_encode_ext(struct net_device *dev, |
1988 | struct iw_request_info *info, | |
13a9930d WS |
1989 | struct iw_point *dwrq, char *extra) |
1990 | { | |
1df65547 WS |
1991 | struct ks_wlan_private *priv = |
1992 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 1993 | |
1df65547 WS |
1994 | if (priv->sleep_mode == SLP_SLEEP) { |
1995 | return -EPERM; | |
1996 | } | |
13a9930d | 1997 | |
1df65547 | 1998 | /* for SLEEP MODE */ |
13a9930d | 1999 | /* WPA (not used ?? wpa_supplicant) |
1df65547 WS |
2000 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
2001 | struct iw_encode_ext *enc; | |
2002 | enc = (struct iw_encode_ext *)extra; | |
2003 | int index = dwrq->flags & IW_ENCODE_INDEX; | |
2004 | WPA (not used ?? wpa_supplicant) */ | |
13a9930d WS |
2005 | return 0; |
2006 | } | |
2007 | ||
2008 | /*------------------------------------------------------------------*/ | |
2009 | /* Wireless Handler : PMKSA cache operation (WPA2) */ | |
1df65547 WS |
2010 | static int ks_wlan_set_pmksa(struct net_device *dev, |
2011 | struct iw_request_info *info, | |
2012 | struct iw_point *dwrq, char *extra) | |
13a9930d | 2013 | { |
1df65547 WS |
2014 | struct ks_wlan_private *priv = |
2015 | (struct ks_wlan_private *)netdev_priv(dev); | |
2016 | struct iw_pmksa *pmksa; | |
13a9930d WS |
2017 | int i; |
2018 | struct pmk_t *pmk; | |
2019 | struct list_head *ptr; | |
2020 | ||
1df65547 | 2021 | DPRINTK(2, "\n"); |
13a9930d | 2022 | |
1df65547 WS |
2023 | if (priv->sleep_mode == SLP_SLEEP) { |
2024 | return -EPERM; | |
2025 | } | |
2026 | /* for SLEEP MODE */ | |
2027 | if (!extra) { | |
13a9930d WS |
2028 | return -EINVAL; |
2029 | } | |
2030 | pmksa = (struct iw_pmksa *)extra; | |
1df65547 | 2031 | DPRINTK(2, "cmd=%d\n", pmksa->cmd); |
13a9930d | 2032 | |
1df65547 | 2033 | switch (pmksa->cmd) { |
13a9930d | 2034 | case IW_PMKSA_ADD: |
1df65547 WS |
2035 | if (list_empty(&priv->pmklist.head)) { /* new list */ |
2036 | for (i = 0; i < PMK_LIST_MAX; i++) { | |
13a9930d | 2037 | pmk = &priv->pmklist.pmk[i]; |
1df65547 WS |
2038 | if (!memcmp |
2039 | ("\x00\x00\x00\x00\x00\x00", pmk->bssid, | |
2040 | ETH_ALEN)) | |
13a9930d WS |
2041 | break; |
2042 | } | |
2043 | memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); | |
2044 | memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); | |
1df65547 | 2045 | list_add(&pmk->list, &priv->pmklist.head); |
13a9930d | 2046 | priv->pmklist.size++; |
1df65547 WS |
2047 | } else { /* search cache data */ |
2048 | list_for_each(ptr, &priv->pmklist.head) { | |
13a9930d | 2049 | pmk = list_entry(ptr, struct pmk_t, list); |
1df65547 WS |
2050 | if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */ |
2051 | memcpy(pmk->pmkid, pmksa->pmkid, | |
2052 | IW_PMKID_LEN); | |
2053 | list_move(&pmk->list, | |
2054 | &priv->pmklist.head); | |
13a9930d WS |
2055 | break; |
2056 | } | |
2057 | } | |
1df65547 WS |
2058 | if (ptr == &priv->pmklist.head) { /* not find address. */ |
2059 | if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */ | |
2060 | for (i = 0; i < PMK_LIST_MAX; i++) { | |
13a9930d | 2061 | pmk = &priv->pmklist.pmk[i]; |
1df65547 WS |
2062 | if (!memcmp |
2063 | ("\x00\x00\x00\x00\x00\x00", | |
2064 | pmk->bssid, ETH_ALEN)) | |
13a9930d WS |
2065 | break; |
2066 | } | |
1df65547 WS |
2067 | memcpy(pmk->bssid, pmksa->bssid.sa_data, |
2068 | ETH_ALEN); | |
2069 | memcpy(pmk->pmkid, pmksa->pmkid, | |
2070 | IW_PMKID_LEN); | |
2071 | list_add(&pmk->list, | |
2072 | &priv->pmklist.head); | |
13a9930d | 2073 | priv->pmklist.size++; |
1df65547 WS |
2074 | } else { /* overwrite old cache data */ |
2075 | pmk = | |
2076 | list_entry(priv->pmklist.head.prev, | |
2077 | struct pmk_t, list); | |
2078 | memcpy(pmk->bssid, pmksa->bssid.sa_data, | |
2079 | ETH_ALEN); | |
2080 | memcpy(pmk->pmkid, pmksa->pmkid, | |
2081 | IW_PMKID_LEN); | |
2082 | list_move(&pmk->list, | |
2083 | &priv->pmklist.head); | |
13a9930d WS |
2084 | } |
2085 | } | |
2086 | } | |
2087 | break; | |
2088 | case IW_PMKSA_REMOVE: | |
1df65547 | 2089 | if (list_empty(&priv->pmklist.head)) { /* list empty */ |
13a9930d | 2090 | return -EINVAL; |
1df65547 WS |
2091 | } else { /* search cache data */ |
2092 | list_for_each(ptr, &priv->pmklist.head) { | |
13a9930d | 2093 | pmk = list_entry(ptr, struct pmk_t, list); |
1df65547 | 2094 | if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */ |
13a9930d WS |
2095 | memset(pmk->bssid, 0, ETH_ALEN); |
2096 | memset(pmk->pmkid, 0, IW_PMKID_LEN); | |
2097 | list_del_init(&pmk->list); | |
2098 | break; | |
2099 | } | |
2100 | } | |
1df65547 | 2101 | if (ptr == &priv->pmklist.head) { /* not find address. */ |
13a9930d WS |
2102 | return 0; |
2103 | } | |
2104 | } | |
2105 | break; | |
2106 | case IW_PMKSA_FLUSH: | |
2107 | memset(&(priv->pmklist), 0, sizeof(priv->pmklist)); | |
2108 | INIT_LIST_HEAD(&priv->pmklist.head); | |
1df65547 | 2109 | for (i = 0; i < PMK_LIST_MAX; i++) |
13a9930d WS |
2110 | INIT_LIST_HEAD(&priv->pmklist.pmk[i].list); |
2111 | break; | |
2112 | default: | |
2113 | return -EINVAL; | |
2114 | } | |
2115 | ||
2116 | hostif_sme_enqueue(priv, SME_SET_PMKSA); | |
2117 | return 0; | |
2118 | } | |
2119 | ||
2120 | static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev) | |
2121 | { | |
2122 | ||
1df65547 WS |
2123 | struct ks_wlan_private *priv = |
2124 | (struct ks_wlan_private *)netdev_priv(dev); | |
2125 | struct iw_statistics *wstats = &priv->wstats; | |
13a9930d | 2126 | |
1df65547 | 2127 | if (!atomic_read(&update_phyinfo)) { |
13a9930d | 2128 | if (priv->dev_state < DEVICE_STATE_READY) |
1df65547 | 2129 | return NULL; /* not finished initialize */ |
13a9930d WS |
2130 | else |
2131 | return wstats; | |
2132 | } | |
2133 | ||
2134 | /* Packets discarded in the wireless adapter due to wireless | |
2135 | * specific problems */ | |
1df65547 WS |
2136 | wstats->discard.nwid = 0; /* Rx invalid nwid */ |
2137 | wstats->discard.code = 0; /* Rx invalid crypt */ | |
2138 | wstats->discard.fragment = 0; /* Rx invalid frag */ | |
2139 | wstats->discard.retries = 0; /* Tx excessive retries */ | |
2140 | wstats->discard.misc = 0; /* Invalid misc */ | |
2141 | wstats->miss.beacon = 0; /* Missed beacon */ | |
13a9930d | 2142 | |
1df65547 | 2143 | return wstats; |
13a9930d WS |
2144 | } |
2145 | ||
2146 | /*------------------------------------------------------------------*/ | |
2147 | /* Private handler : set stop request */ | |
1df65547 WS |
2148 | static int ks_wlan_set_stop_request(struct net_device *dev, |
2149 | struct iw_request_info *info, __u32 * uwrq, | |
2150 | char *extra) | |
13a9930d | 2151 | { |
1df65547 WS |
2152 | struct ks_wlan_private *priv = |
2153 | (struct ks_wlan_private *)netdev_priv(dev); | |
2154 | DPRINTK(2, "\n"); | |
13a9930d | 2155 | |
1df65547 WS |
2156 | if (priv->sleep_mode == SLP_SLEEP) { |
2157 | return -EPERM; | |
2158 | } | |
2159 | /* for SLEEP MODE */ | |
2160 | if (!(*uwrq)) | |
2161 | return -EINVAL; | |
13a9930d WS |
2162 | |
2163 | hostif_sme_enqueue(priv, SME_STOP_REQUEST); | |
2164 | return 0; | |
2165 | } | |
2166 | ||
2167 | /*------------------------------------------------------------------*/ | |
2168 | /* Wireless Handler : set MLME */ | |
2169 | #include <linux/ieee80211.h> | |
1df65547 WS |
2170 | static int ks_wlan_set_mlme(struct net_device *dev, |
2171 | struct iw_request_info *info, struct iw_point *dwrq, | |
2172 | char *extra) | |
13a9930d | 2173 | { |
1df65547 WS |
2174 | struct ks_wlan_private *priv = |
2175 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
2176 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
2177 | __u32 mode; | |
2178 | ||
2179 | DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code); | |
2180 | ||
1df65547 WS |
2181 | if (priv->sleep_mode == SLP_SLEEP) { |
2182 | return -EPERM; | |
2183 | } | |
2184 | /* for SLEEP MODE */ | |
13a9930d WS |
2185 | switch (mlme->cmd) { |
2186 | case IW_MLME_DEAUTH: | |
2187 | if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) { | |
2188 | return 0; | |
2189 | } | |
2190 | case IW_MLME_DISASSOC: | |
2191 | mode = 1; | |
2192 | return ks_wlan_set_stop_request(dev, NULL, &mode, NULL); | |
2193 | default: | |
1df65547 | 2194 | return -EOPNOTSUPP; /* Not Support */ |
13a9930d WS |
2195 | } |
2196 | } | |
13a9930d | 2197 | |
13a9930d WS |
2198 | /*------------------------------------------------------------------*/ |
2199 | /* Private handler : get firemware version */ | |
1df65547 WS |
2200 | static int ks_wlan_get_firmware_version(struct net_device *dev, |
2201 | struct iw_request_info *info, | |
13a9930d WS |
2202 | struct iw_point *dwrq, char *extra) |
2203 | { | |
1df65547 WS |
2204 | struct ks_wlan_private *priv = |
2205 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2206 | strcpy(extra, &(priv->firmware_version[0])); |
1df65547 | 2207 | dwrq->length = priv->version_size + 1; |
13a9930d WS |
2208 | return 0; |
2209 | } | |
2210 | ||
2211 | #if 0 | |
2212 | /*------------------------------------------------------------------*/ | |
2213 | /* Private handler : set force disconnect status */ | |
1df65547 WS |
2214 | static int ks_wlan_set_detach(struct net_device *dev, |
2215 | struct iw_request_info *info, __u32 * uwrq, | |
2216 | char *extra) | |
13a9930d | 2217 | { |
feedcf1a | 2218 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d | 2219 | |
1df65547 WS |
2220 | if (priv->sleep_mode == SLP_SLEEP) { |
2221 | return -EPERM; | |
2222 | } | |
2223 | /* for SLEEP MODE */ | |
2224 | if (*uwrq == CONNECT_STATUS) { /* 0 */ | |
13a9930d | 2225 | priv->connect_status &= ~FORCE_DISCONNECT; |
1df65547 WS |
2226 | if ((priv->connect_status & CONNECT_STATUS_MASK) == |
2227 | CONNECT_STATUS) | |
13a9930d | 2228 | netif_carrier_on(dev); |
1df65547 | 2229 | } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */ |
13a9930d WS |
2230 | priv->connect_status |= FORCE_DISCONNECT; |
2231 | netif_carrier_off(dev); | |
1df65547 WS |
2232 | } else |
2233 | return -EINVAL; | |
13a9930d WS |
2234 | return 0; |
2235 | } | |
2236 | ||
2237 | /*------------------------------------------------------------------*/ | |
2238 | /* Private handler : get force disconnect status */ | |
1df65547 WS |
2239 | static int ks_wlan_get_detach(struct net_device *dev, |
2240 | struct iw_request_info *info, __u32 * uwrq, | |
2241 | char *extra) | |
13a9930d | 2242 | { |
feedcf1a | 2243 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d | 2244 | |
1df65547 WS |
2245 | if (priv->sleep_mode == SLP_SLEEP) { |
2246 | return -EPERM; | |
2247 | } | |
2248 | /* for SLEEP MODE */ | |
2249 | *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0); | |
13a9930d WS |
2250 | return 0; |
2251 | } | |
2252 | ||
2253 | /*------------------------------------------------------------------*/ | |
2254 | /* Private handler : get connect status */ | |
1df65547 WS |
2255 | static int ks_wlan_get_connect(struct net_device *dev, |
2256 | struct iw_request_info *info, __u32 * uwrq, | |
2257 | char *extra) | |
13a9930d | 2258 | { |
feedcf1a | 2259 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d | 2260 | |
1df65547 WS |
2261 | if (priv->sleep_mode == SLP_SLEEP) { |
2262 | return -EPERM; | |
2263 | } | |
2264 | /* for SLEEP MODE */ | |
13a9930d WS |
2265 | *uwrq = (priv->connect_status & CONNECT_STATUS_MASK); |
2266 | return 0; | |
2267 | } | |
2268 | #endif | |
2269 | ||
2270 | /*------------------------------------------------------------------*/ | |
2271 | /* Private handler : set preamble */ | |
1df65547 WS |
2272 | static int ks_wlan_set_preamble(struct net_device *dev, |
2273 | struct iw_request_info *info, __u32 * uwrq, | |
2274 | char *extra) | |
13a9930d | 2275 | { |
1df65547 WS |
2276 | struct ks_wlan_private *priv = |
2277 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2278 | |
1df65547 WS |
2279 | if (priv->sleep_mode == SLP_SLEEP) { |
2280 | return -EPERM; | |
2281 | } | |
2282 | /* for SLEEP MODE */ | |
2283 | if (*uwrq == LONG_PREAMBLE) { /* 0 */ | |
13a9930d | 2284 | priv->reg.preamble = LONG_PREAMBLE; |
1df65547 | 2285 | } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */ |
13a9930d | 2286 | priv->reg.preamble = SHORT_PREAMBLE; |
1df65547 WS |
2287 | } else |
2288 | return -EINVAL; | |
13a9930d WS |
2289 | |
2290 | priv->need_commit |= SME_MODE_SET; | |
1df65547 | 2291 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
2292 | |
2293 | } | |
2294 | ||
2295 | /*------------------------------------------------------------------*/ | |
2296 | /* Private handler : get preamble */ | |
1df65547 WS |
2297 | static int ks_wlan_get_preamble(struct net_device *dev, |
2298 | struct iw_request_info *info, __u32 * uwrq, | |
2299 | char *extra) | |
13a9930d | 2300 | { |
1df65547 WS |
2301 | struct ks_wlan_private *priv = |
2302 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2303 | |
1df65547 WS |
2304 | if (priv->sleep_mode == SLP_SLEEP) { |
2305 | return -EPERM; | |
2306 | } | |
2307 | /* for SLEEP MODE */ | |
13a9930d WS |
2308 | *uwrq = priv->reg.preamble; |
2309 | return 0; | |
2310 | } | |
2311 | ||
2312 | /*------------------------------------------------------------------*/ | |
2313 | /* Private handler : set power save mode */ | |
1df65547 WS |
2314 | static int ks_wlan_set_powermgt(struct net_device *dev, |
2315 | struct iw_request_info *info, __u32 * uwrq, | |
2316 | char *extra) | |
13a9930d | 2317 | { |
1df65547 WS |
2318 | struct ks_wlan_private *priv = |
2319 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2320 | |
1df65547 WS |
2321 | if (priv->sleep_mode == SLP_SLEEP) { |
2322 | return -EPERM; | |
2323 | } | |
2324 | /* for SLEEP MODE */ | |
2325 | if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */ | |
13a9930d | 2326 | priv->reg.powermgt = POWMGT_ACTIVE_MODE; |
1df65547 WS |
2327 | } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */ |
2328 | if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) | |
2329 | priv->reg.powermgt = POWMGT_SAVE1_MODE; | |
2330 | else | |
2331 | return -EINVAL; | |
2332 | } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */ | |
2333 | if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) | |
13a9930d WS |
2334 | priv->reg.powermgt = POWMGT_SAVE2_MODE; |
2335 | else | |
2336 | return -EINVAL; | |
1df65547 WS |
2337 | } else |
2338 | return -EINVAL; | |
13a9930d WS |
2339 | |
2340 | hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST); | |
2341 | ||
2342 | return 0; | |
2343 | } | |
2344 | ||
2345 | /*------------------------------------------------------------------*/ | |
2346 | /* Private handler : get power save made */ | |
1df65547 WS |
2347 | static int ks_wlan_get_powermgt(struct net_device *dev, |
2348 | struct iw_request_info *info, __u32 * uwrq, | |
2349 | char *extra) | |
13a9930d | 2350 | { |
1df65547 WS |
2351 | struct ks_wlan_private *priv = |
2352 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2353 | |
1df65547 WS |
2354 | if (priv->sleep_mode == SLP_SLEEP) { |
2355 | return -EPERM; | |
2356 | } | |
2357 | /* for SLEEP MODE */ | |
13a9930d WS |
2358 | *uwrq = priv->reg.powermgt; |
2359 | return 0; | |
2360 | } | |
2361 | ||
2362 | /*------------------------------------------------------------------*/ | |
2363 | /* Private handler : set scan type */ | |
1df65547 WS |
2364 | static int ks_wlan_set_scan_type(struct net_device *dev, |
2365 | struct iw_request_info *info, __u32 * uwrq, | |
2366 | char *extra) | |
13a9930d | 2367 | { |
1df65547 WS |
2368 | struct ks_wlan_private *priv = |
2369 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2370 | |
1df65547 WS |
2371 | if (priv->sleep_mode == SLP_SLEEP) { |
2372 | return -EPERM; | |
2373 | } | |
2374 | /* for SLEEP MODE */ | |
2375 | if (*uwrq == ACTIVE_SCAN) { /* 0 */ | |
13a9930d | 2376 | priv->reg.scan_type = ACTIVE_SCAN; |
1df65547 | 2377 | } else if (*uwrq == PASSIVE_SCAN) { /* 1 */ |
13a9930d | 2378 | priv->reg.scan_type = PASSIVE_SCAN; |
1df65547 WS |
2379 | } else |
2380 | return -EINVAL; | |
13a9930d WS |
2381 | |
2382 | return 0; | |
2383 | } | |
2384 | ||
2385 | /*------------------------------------------------------------------*/ | |
2386 | /* Private handler : get scan type */ | |
1df65547 WS |
2387 | static int ks_wlan_get_scan_type(struct net_device *dev, |
2388 | struct iw_request_info *info, __u32 * uwrq, | |
2389 | char *extra) | |
13a9930d | 2390 | { |
1df65547 WS |
2391 | struct ks_wlan_private *priv = |
2392 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2393 | |
1df65547 WS |
2394 | if (priv->sleep_mode == SLP_SLEEP) { |
2395 | return -EPERM; | |
2396 | } | |
2397 | /* for SLEEP MODE */ | |
13a9930d WS |
2398 | *uwrq = priv->reg.scan_type; |
2399 | return 0; | |
2400 | } | |
1df65547 | 2401 | |
13a9930d WS |
2402 | #if 0 |
2403 | /*------------------------------------------------------------------*/ | |
2404 | /* Private handler : write raw data to device */ | |
1df65547 WS |
2405 | static int ks_wlan_data_write(struct net_device *dev, |
2406 | struct iw_request_info *info, | |
2407 | struct iw_point *dwrq, char *extra) | |
13a9930d | 2408 | { |
feedcf1a | 2409 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d WS |
2410 | unsigned char *wbuff = NULL; |
2411 | ||
1df65547 WS |
2412 | if (priv->sleep_mode == SLP_SLEEP) { |
2413 | return -EPERM; | |
2414 | } | |
2415 | /* for SLEEP MODE */ | |
13a9930d | 2416 | wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC); |
1df65547 WS |
2417 | if (!wbuff) |
2418 | return -EFAULT; | |
13a9930d WS |
2419 | memcpy(wbuff, extra, dwrq->length); |
2420 | ||
2421 | /* write to device */ | |
1df65547 | 2422 | ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL); |
13a9930d WS |
2423 | |
2424 | return 0; | |
2425 | } | |
2426 | ||
2427 | /*------------------------------------------------------------------*/ | |
2428 | /* Private handler : read raw data form device */ | |
1df65547 WS |
2429 | static int ks_wlan_data_read(struct net_device *dev, |
2430 | struct iw_request_info *info, | |
2431 | struct iw_point *dwrq, char *extra) | |
13a9930d | 2432 | { |
feedcf1a | 2433 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d WS |
2434 | unsigned short read_length; |
2435 | ||
1df65547 WS |
2436 | if (priv->sleep_mode == SLP_SLEEP) { |
2437 | return -EPERM; | |
2438 | } | |
2439 | /* for SLEEP MODE */ | |
2440 | if (!atomic_read(&priv->event_count)) { | |
2441 | if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */ | |
2442 | read_length = 4; | |
2443 | memset(extra, 0xff, read_length); | |
13a9930d WS |
2444 | dwrq->length = read_length; |
2445 | return 0; | |
2446 | } | |
2447 | read_length = 0; | |
1df65547 | 2448 | memset(extra, 0, 1); |
13a9930d WS |
2449 | dwrq->length = 0; |
2450 | return 0; | |
2451 | } | |
2452 | ||
1df65547 WS |
2453 | if (atomic_read(&priv->event_count) > 0) |
2454 | atomic_dec(&priv->event_count); | |
13a9930d WS |
2455 | |
2456 | spin_lock(&priv->dev_read_lock); /* request spin lock */ | |
2457 | ||
1df65547 WS |
2458 | /* Copy length max size 0x07ff */ |
2459 | if (priv->dev_size[priv->dev_count] > 2047) | |
13a9930d WS |
2460 | read_length = 2047; |
2461 | else | |
2462 | read_length = priv->dev_size[priv->dev_count]; | |
2463 | ||
2464 | /* Copy data */ | |
2465 | memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length); | |
2466 | ||
1df65547 | 2467 | spin_unlock(&priv->dev_read_lock); /* release spin lock */ |
13a9930d WS |
2468 | |
2469 | /* Initialize */ | |
2470 | priv->dev_data[priv->dev_count] = 0; | |
2471 | priv->dev_size[priv->dev_count] = 0; | |
2472 | ||
2473 | priv->dev_count++; | |
1df65547 WS |
2474 | if (priv->dev_count == DEVICE_STOCK_COUNT) |
2475 | priv->dev_count = 0; | |
13a9930d WS |
2476 | |
2477 | /* Set read size */ | |
2478 | dwrq->length = read_length; | |
2479 | ||
2480 | return 0; | |
2481 | } | |
2482 | #endif | |
2483 | ||
2484 | #if 0 | |
2485 | /*------------------------------------------------------------------*/ | |
2486 | /* Private handler : get wep string */ | |
2487 | #define WEP_ASCII_BUFF_SIZE (17+64*4+1) | |
1df65547 WS |
2488 | static int ks_wlan_get_wep_ascii(struct net_device *dev, |
2489 | struct iw_request_info *info, | |
13a9930d WS |
2490 | struct iw_point *dwrq, char *extra) |
2491 | { | |
feedcf1a | 2492 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
1df65547 | 2493 | int i, j, len = 0; |
13a9930d WS |
2494 | char tmp[WEP_ASCII_BUFF_SIZE]; |
2495 | ||
1df65547 WS |
2496 | if (priv->sleep_mode == SLP_SLEEP) { |
2497 | return -EPERM; | |
2498 | } | |
2499 | /* for SLEEP MODE */ | |
2500 | strcpy(tmp, " WEP keys ASCII \n"); | |
2501 | len += strlen(" WEP keys ASCII \n"); | |
13a9930d | 2502 | |
1df65547 WS |
2503 | for (i = 0; i < 4; i++) { |
2504 | strcpy(tmp + len, "\t["); | |
2505 | len += strlen("\t["); | |
2506 | tmp[len] = '1' + i; | |
13a9930d | 2507 | len++; |
1df65547 WS |
2508 | strcpy(tmp + len, "] "); |
2509 | len += strlen("] "); | |
2510 | if (priv->reg.wep_key[i].size) { | |
2511 | strcpy(tmp + len, | |
2512 | (priv->reg.wep_key[i].size < | |
2513 | 6 ? "(40bits) [" : "(104bits) [")); | |
2514 | len += | |
2515 | strlen((priv->reg.wep_key[i].size < | |
2516 | 6 ? "(40bits) [" : "(104bits) [")); | |
2517 | for (j = 0; j < priv->reg.wep_key[i].size; j++, len++) | |
2518 | tmp[len] = | |
2519 | (isprint(priv->reg.wep_key[i].val[j]) ? | |
2520 | priv->reg.wep_key[i].val[j] : ' '); | |
2521 | ||
2522 | strcpy(tmp + len, "]\n"); | |
2523 | len += strlen("]\n"); | |
2524 | } else { | |
2525 | strcpy(tmp + len, "off\n"); | |
2526 | len += strlen("off\n"); | |
13a9930d WS |
2527 | } |
2528 | } | |
2529 | ||
2530 | memcpy(extra, tmp, len); | |
1df65547 | 2531 | dwrq->length = len + 1; |
13a9930d WS |
2532 | return 0; |
2533 | } | |
2534 | #endif | |
2535 | ||
2536 | /*------------------------------------------------------------------*/ | |
2537 | /* Private handler : set beacon lost count */ | |
1df65547 WS |
2538 | static int ks_wlan_set_beacon_lost(struct net_device *dev, |
2539 | struct iw_request_info *info, __u32 * uwrq, | |
2540 | char *extra) | |
13a9930d | 2541 | { |
1df65547 WS |
2542 | struct ks_wlan_private *priv = |
2543 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2544 | |
1df65547 WS |
2545 | if (priv->sleep_mode == SLP_SLEEP) { |
2546 | return -EPERM; | |
2547 | } | |
2548 | /* for SLEEP MODE */ | |
2549 | if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) { | |
13a9930d | 2550 | priv->reg.beacon_lost_count = *uwrq; |
1df65547 WS |
2551 | } else |
2552 | return -EINVAL; | |
13a9930d | 2553 | |
1df65547 | 2554 | if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) { |
13a9930d | 2555 | priv->need_commit |= SME_MODE_SET; |
1df65547 WS |
2556 | return -EINPROGRESS; /* Call commit handler */ |
2557 | } else | |
13a9930d WS |
2558 | return 0; |
2559 | } | |
2560 | ||
2561 | /*------------------------------------------------------------------*/ | |
2562 | /* Private handler : get beacon lost count */ | |
1df65547 WS |
2563 | static int ks_wlan_get_beacon_lost(struct net_device *dev, |
2564 | struct iw_request_info *info, __u32 * uwrq, | |
2565 | char *extra) | |
13a9930d | 2566 | { |
1df65547 WS |
2567 | struct ks_wlan_private *priv = |
2568 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2569 | |
1df65547 WS |
2570 | if (priv->sleep_mode == SLP_SLEEP) { |
2571 | return -EPERM; | |
2572 | } | |
2573 | /* for SLEEP MODE */ | |
13a9930d WS |
2574 | *uwrq = priv->reg.beacon_lost_count; |
2575 | return 0; | |
2576 | } | |
2577 | ||
2578 | /*------------------------------------------------------------------*/ | |
2579 | /* Private handler : set phy type */ | |
1df65547 WS |
2580 | static int ks_wlan_set_phy_type(struct net_device *dev, |
2581 | struct iw_request_info *info, __u32 * uwrq, | |
2582 | char *extra) | |
13a9930d | 2583 | { |
1df65547 WS |
2584 | struct ks_wlan_private *priv = |
2585 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2586 | |
1df65547 WS |
2587 | if (priv->sleep_mode == SLP_SLEEP) { |
2588 | return -EPERM; | |
2589 | } | |
2590 | /* for SLEEP MODE */ | |
2591 | if (*uwrq == D_11B_ONLY_MODE) { /* 0 */ | |
13a9930d | 2592 | priv->reg.phy_type = D_11B_ONLY_MODE; |
1df65547 | 2593 | } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */ |
13a9930d | 2594 | priv->reg.phy_type = D_11G_ONLY_MODE; |
1df65547 | 2595 | } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */ |
13a9930d | 2596 | priv->reg.phy_type = D_11BG_COMPATIBLE_MODE; |
1df65547 WS |
2597 | } else |
2598 | return -EINVAL; | |
13a9930d WS |
2599 | |
2600 | priv->need_commit |= SME_MODE_SET; | |
1df65547 | 2601 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
2602 | } |
2603 | ||
2604 | /*------------------------------------------------------------------*/ | |
2605 | /* Private handler : get phy type */ | |
1df65547 WS |
2606 | static int ks_wlan_get_phy_type(struct net_device *dev, |
2607 | struct iw_request_info *info, __u32 * uwrq, | |
2608 | char *extra) | |
13a9930d | 2609 | { |
1df65547 WS |
2610 | struct ks_wlan_private *priv = |
2611 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2612 | |
1df65547 WS |
2613 | if (priv->sleep_mode == SLP_SLEEP) { |
2614 | return -EPERM; | |
2615 | } | |
2616 | /* for SLEEP MODE */ | |
13a9930d WS |
2617 | *uwrq = priv->reg.phy_type; |
2618 | return 0; | |
2619 | } | |
2620 | ||
2621 | /*------------------------------------------------------------------*/ | |
2622 | /* Private handler : set cts mode */ | |
1df65547 WS |
2623 | static int ks_wlan_set_cts_mode(struct net_device *dev, |
2624 | struct iw_request_info *info, __u32 * uwrq, | |
2625 | char *extra) | |
13a9930d | 2626 | { |
1df65547 WS |
2627 | struct ks_wlan_private *priv = |
2628 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2629 | |
1df65547 WS |
2630 | if (priv->sleep_mode == SLP_SLEEP) { |
2631 | return -EPERM; | |
2632 | } | |
2633 | /* for SLEEP MODE */ | |
2634 | if (*uwrq == CTS_MODE_FALSE) { /* 0 */ | |
13a9930d | 2635 | priv->reg.cts_mode = CTS_MODE_FALSE; |
1df65547 WS |
2636 | } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */ |
2637 | if (priv->reg.phy_type == D_11G_ONLY_MODE || | |
2638 | priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) | |
13a9930d WS |
2639 | priv->reg.cts_mode = CTS_MODE_TRUE; |
2640 | else | |
2641 | priv->reg.cts_mode = CTS_MODE_FALSE; | |
1df65547 WS |
2642 | } else |
2643 | return -EINVAL; | |
13a9930d WS |
2644 | |
2645 | priv->need_commit |= SME_MODE_SET; | |
1df65547 | 2646 | return -EINPROGRESS; /* Call commit handler */ |
13a9930d WS |
2647 | } |
2648 | ||
2649 | /*------------------------------------------------------------------*/ | |
2650 | /* Private handler : get cts mode */ | |
1df65547 WS |
2651 | static int ks_wlan_get_cts_mode(struct net_device *dev, |
2652 | struct iw_request_info *info, __u32 * uwrq, | |
2653 | char *extra) | |
13a9930d | 2654 | { |
1df65547 WS |
2655 | struct ks_wlan_private *priv = |
2656 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2657 | |
1df65547 WS |
2658 | if (priv->sleep_mode == SLP_SLEEP) { |
2659 | return -EPERM; | |
2660 | } | |
2661 | /* for SLEEP MODE */ | |
13a9930d WS |
2662 | *uwrq = priv->reg.cts_mode; |
2663 | return 0; | |
2664 | } | |
2665 | ||
2666 | /*------------------------------------------------------------------*/ | |
2667 | /* Private handler : set sleep mode */ | |
2668 | static int ks_wlan_set_sleep_mode(struct net_device *dev, | |
1df65547 WS |
2669 | struct iw_request_info *info, |
2670 | __u32 * uwrq, char *extra) | |
13a9930d | 2671 | { |
1df65547 WS |
2672 | struct ks_wlan_private *priv = |
2673 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2674 | |
1df65547 | 2675 | DPRINTK(2, "\n"); |
13a9930d | 2676 | |
1df65547 | 2677 | if (*uwrq == SLP_SLEEP) { |
13a9930d WS |
2678 | priv->sleep_mode = *uwrq; |
2679 | printk("SET_SLEEP_MODE %d\n", priv->sleep_mode); | |
2680 | ||
2681 | hostif_sme_enqueue(priv, SME_STOP_REQUEST); | |
2682 | hostif_sme_enqueue(priv, SME_SLEEP_REQUEST); | |
2683 | ||
1df65547 | 2684 | } else if (*uwrq == SLP_ACTIVE) { |
13a9930d WS |
2685 | priv->sleep_mode = *uwrq; |
2686 | printk("SET_SLEEP_MODE %d\n", priv->sleep_mode); | |
2687 | hostif_sme_enqueue(priv, SME_SLEEP_REQUEST); | |
1df65547 | 2688 | } else { |
13a9930d | 2689 | printk("SET_SLEEP_MODE %d errror\n", *uwrq); |
1df65547 | 2690 | return -EINVAL; |
13a9930d WS |
2691 | } |
2692 | ||
2693 | return 0; | |
2694 | } | |
1df65547 | 2695 | |
13a9930d WS |
2696 | /*------------------------------------------------------------------*/ |
2697 | /* Private handler : get sleep mode */ | |
2698 | static int ks_wlan_get_sleep_mode(struct net_device *dev, | |
1df65547 WS |
2699 | struct iw_request_info *info, |
2700 | __u32 * uwrq, char *extra) | |
13a9930d | 2701 | { |
1df65547 WS |
2702 | struct ks_wlan_private *priv = |
2703 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
2704 | |
2705 | DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode); | |
2706 | *uwrq = priv->sleep_mode; | |
2707 | ||
2708 | return 0; | |
2709 | } | |
2710 | ||
2711 | #if 0 | |
2712 | /*------------------------------------------------------------------*/ | |
2713 | /* Private handler : set phy information timer */ | |
1df65547 WS |
2714 | static int ks_wlan_set_phy_information_timer(struct net_device *dev, |
2715 | struct iw_request_info *info, | |
2716 | __u32 * uwrq, char *extra) | |
13a9930d | 2717 | { |
feedcf1a | 2718 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d | 2719 | |
1df65547 WS |
2720 | if (priv->sleep_mode == SLP_SLEEP) { |
2721 | return -EPERM; | |
2722 | } | |
2723 | /* for SLEEP MODE */ | |
2724 | if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */ | |
2725 | priv->reg.phy_info_timer = (uint16_t) * uwrq; | |
13a9930d | 2726 | else |
1df65547 | 2727 | return -EINVAL; |
13a9930d WS |
2728 | |
2729 | hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST); | |
2730 | ||
2731 | return 0; | |
2732 | } | |
2733 | ||
2734 | /*------------------------------------------------------------------*/ | |
2735 | /* Private handler : get phy information timer */ | |
1df65547 WS |
2736 | static int ks_wlan_get_phy_information_timer(struct net_device *dev, |
2737 | struct iw_request_info *info, | |
2738 | __u32 * uwrq, char *extra) | |
13a9930d | 2739 | { |
feedcf1a | 2740 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d | 2741 | |
1df65547 WS |
2742 | if (priv->sleep_mode == SLP_SLEEP) { |
2743 | return -EPERM; | |
2744 | } | |
2745 | /* for SLEEP MODE */ | |
13a9930d WS |
2746 | *uwrq = priv->reg.phy_info_timer; |
2747 | return 0; | |
2748 | } | |
2749 | #endif | |
2750 | ||
2751 | #ifdef WPS | |
2752 | /*------------------------------------------------------------------*/ | |
2753 | /* Private handler : set WPS enable */ | |
1df65547 WS |
2754 | static int ks_wlan_set_wps_enable(struct net_device *dev, |
2755 | struct iw_request_info *info, __u32 * uwrq, | |
2756 | char *extra) | |
13a9930d | 2757 | { |
1df65547 WS |
2758 | struct ks_wlan_private *priv = |
2759 | (struct ks_wlan_private *)netdev_priv(dev); | |
2760 | DPRINTK(2, "\n"); | |
13a9930d | 2761 | |
1df65547 WS |
2762 | if (priv->sleep_mode == SLP_SLEEP) { |
2763 | return -EPERM; | |
2764 | } | |
2765 | /* for SLEEP MODE */ | |
2766 | if (*uwrq == 0 || *uwrq == 1) | |
13a9930d WS |
2767 | priv->wps.wps_enabled = *uwrq; |
2768 | else | |
1df65547 | 2769 | return -EINVAL; |
13a9930d WS |
2770 | |
2771 | hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST); | |
2772 | ||
2773 | return 0; | |
2774 | } | |
1df65547 | 2775 | |
13a9930d WS |
2776 | /*------------------------------------------------------------------*/ |
2777 | /* Private handler : get WPS enable */ | |
1df65547 WS |
2778 | static int ks_wlan_get_wps_enable(struct net_device *dev, |
2779 | struct iw_request_info *info, __u32 * uwrq, | |
2780 | char *extra) | |
13a9930d | 2781 | { |
1df65547 WS |
2782 | struct ks_wlan_private *priv = |
2783 | (struct ks_wlan_private *)netdev_priv(dev); | |
2784 | DPRINTK(2, "\n"); | |
13a9930d | 2785 | |
1df65547 WS |
2786 | if (priv->sleep_mode == SLP_SLEEP) { |
2787 | return -EPERM; | |
2788 | } | |
2789 | /* for SLEEP MODE */ | |
13a9930d WS |
2790 | *uwrq = priv->wps.wps_enabled; |
2791 | printk("return=%d\n", *uwrq); | |
2792 | ||
2793 | return 0; | |
2794 | } | |
1df65547 | 2795 | |
13a9930d WS |
2796 | /*------------------------------------------------------------------*/ |
2797 | /* Private handler : set WPS probe req */ | |
2798 | static int ks_wlan_set_wps_probe_req(struct net_device *dev, | |
2799 | struct iw_request_info *info, | |
2800 | struct iw_point *dwrq, char *extra) | |
2801 | { | |
2802 | uint8_t *p = extra; | |
2803 | unsigned char len; | |
1df65547 WS |
2804 | struct ks_wlan_private *priv = |
2805 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2806 | |
1df65547 | 2807 | DPRINTK(2, "\n"); |
13a9930d | 2808 | |
1df65547 WS |
2809 | if (priv->sleep_mode == SLP_SLEEP) { |
2810 | return -EPERM; | |
2811 | } | |
2812 | /* for SLEEP MODE */ | |
2813 | DPRINTK(2, "dwrq->length=%d\n", dwrq->length); | |
13a9930d WS |
2814 | |
2815 | /* length check */ | |
1df65547 | 2816 | if (p[1] + 2 != dwrq->length || dwrq->length > 256) { |
13a9930d WS |
2817 | return -EINVAL; |
2818 | } | |
2819 | ||
1df65547 WS |
2820 | priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */ |
2821 | len = p[1] + 2; /* IE header + IE */ | |
13a9930d WS |
2822 | |
2823 | memcpy(priv->wps.ie, &len, sizeof(len)); | |
1df65547 | 2824 | p = memcpy(priv->wps.ie + 1, p, len); |
13a9930d | 2825 | |
1df65547 | 2826 | DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n", |
13a9930d | 2827 | priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3], |
1df65547 WS |
2828 | p[priv->wps.ielen - 3], p[priv->wps.ielen - 2], |
2829 | p[priv->wps.ielen - 1]); | |
13a9930d WS |
2830 | |
2831 | hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST); | |
2832 | ||
2833 | return 0; | |
2834 | } | |
1df65547 | 2835 | |
13a9930d WS |
2836 | #if 0 |
2837 | /*------------------------------------------------------------------*/ | |
2838 | /* Private handler : get WPS probe req */ | |
2839 | static int ks_wlan_get_wps_probe_req(struct net_device *dev, | |
2840 | struct iw_request_info *info, | |
1df65547 | 2841 | __u32 * uwrq, char *extra) |
13a9930d | 2842 | { |
feedcf1a | 2843 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
1df65547 | 2844 | DPRINTK(2, "\n"); |
13a9930d | 2845 | |
1df65547 WS |
2846 | if (priv->sleep_mode == SLP_SLEEP) { |
2847 | return -EPERM; | |
2848 | } | |
2849 | /* for SLEEP MODE */ | |
13a9930d WS |
2850 | return 0; |
2851 | } | |
2852 | #endif | |
2853 | #endif /* WPS */ | |
2854 | ||
2855 | /*------------------------------------------------------------------*/ | |
2856 | /* Private handler : set tx gain control value */ | |
1df65547 WS |
2857 | static int ks_wlan_set_tx_gain(struct net_device *dev, |
2858 | struct iw_request_info *info, __u32 * uwrq, | |
2859 | char *extra) | |
13a9930d | 2860 | { |
1df65547 WS |
2861 | struct ks_wlan_private *priv = |
2862 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2863 | |
1df65547 WS |
2864 | if (priv->sleep_mode == SLP_SLEEP) { |
2865 | return -EPERM; | |
2866 | } | |
2867 | /* for SLEEP MODE */ | |
2868 | if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */ | |
2869 | priv->gain.TxGain = (uint8_t) * uwrq; | |
13a9930d | 2870 | else |
1df65547 | 2871 | return -EINVAL; |
13a9930d | 2872 | |
1df65547 | 2873 | if (priv->gain.TxGain < 0xFF) |
13a9930d WS |
2874 | priv->gain.TxMode = 1; |
2875 | else | |
2876 | priv->gain.TxMode = 0; | |
2877 | ||
13a9930d | 2878 | hostif_sme_enqueue(priv, SME_SET_GAIN); |
1df65547 | 2879 | return 0; |
13a9930d WS |
2880 | } |
2881 | ||
2882 | /*------------------------------------------------------------------*/ | |
2883 | /* Private handler : get tx gain control value */ | |
1df65547 WS |
2884 | static int ks_wlan_get_tx_gain(struct net_device *dev, |
2885 | struct iw_request_info *info, __u32 * uwrq, | |
2886 | char *extra) | |
13a9930d | 2887 | { |
1df65547 WS |
2888 | struct ks_wlan_private *priv = |
2889 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2890 | |
1df65547 WS |
2891 | if (priv->sleep_mode == SLP_SLEEP) { |
2892 | return -EPERM; | |
2893 | } | |
2894 | /* for SLEEP MODE */ | |
13a9930d WS |
2895 | *uwrq = priv->gain.TxGain; |
2896 | hostif_sme_enqueue(priv, SME_GET_GAIN); | |
2897 | return 0; | |
2898 | } | |
2899 | ||
2900 | /*------------------------------------------------------------------*/ | |
2901 | /* Private handler : set rx gain control value */ | |
1df65547 WS |
2902 | static int ks_wlan_set_rx_gain(struct net_device *dev, |
2903 | struct iw_request_info *info, __u32 * uwrq, | |
2904 | char *extra) | |
13a9930d | 2905 | { |
1df65547 WS |
2906 | struct ks_wlan_private *priv = |
2907 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2908 | |
1df65547 WS |
2909 | if (priv->sleep_mode == SLP_SLEEP) { |
2910 | return -EPERM; | |
2911 | } | |
2912 | /* for SLEEP MODE */ | |
2913 | if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */ | |
2914 | priv->gain.RxGain = (uint8_t) * uwrq; | |
13a9930d | 2915 | else |
1df65547 | 2916 | return -EINVAL; |
13a9930d | 2917 | |
1df65547 | 2918 | if (priv->gain.RxGain < 0xFF) |
13a9930d WS |
2919 | priv->gain.RxMode = 1; |
2920 | else | |
2921 | priv->gain.RxMode = 0; | |
2922 | ||
2923 | hostif_sme_enqueue(priv, SME_SET_GAIN); | |
1df65547 | 2924 | return 0; |
13a9930d WS |
2925 | } |
2926 | ||
2927 | /*------------------------------------------------------------------*/ | |
2928 | /* Private handler : get rx gain control value */ | |
1df65547 WS |
2929 | static int ks_wlan_get_rx_gain(struct net_device *dev, |
2930 | struct iw_request_info *info, __u32 * uwrq, | |
2931 | char *extra) | |
13a9930d | 2932 | { |
1df65547 WS |
2933 | struct ks_wlan_private *priv = |
2934 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 2935 | |
1df65547 WS |
2936 | if (priv->sleep_mode == SLP_SLEEP) { |
2937 | return -EPERM; | |
2938 | } | |
2939 | /* for SLEEP MODE */ | |
13a9930d WS |
2940 | *uwrq = priv->gain.RxGain; |
2941 | hostif_sme_enqueue(priv, SME_GET_GAIN); | |
2942 | return 0; | |
2943 | } | |
1df65547 | 2944 | |
13a9930d WS |
2945 | #if 0 |
2946 | /*------------------------------------------------------------------*/ | |
2947 | /* Private handler : set region value */ | |
1df65547 WS |
2948 | static int ks_wlan_set_region(struct net_device *dev, |
2949 | struct iw_request_info *info, __u32 * uwrq, | |
2950 | char *extra) | |
13a9930d | 2951 | { |
feedcf1a | 2952 | struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; |
13a9930d | 2953 | |
1df65547 WS |
2954 | if (priv->sleep_mode == SLP_SLEEP) { |
2955 | return -EPERM; | |
2956 | } | |
2957 | /* for SLEEP MODE */ | |
2958 | if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */ | |
2959 | priv->region = (uint8_t) * uwrq; | |
13a9930d | 2960 | else |
1df65547 | 2961 | return -EINVAL; |
13a9930d WS |
2962 | |
2963 | hostif_sme_enqueue(priv, SME_SET_REGION); | |
1df65547 | 2964 | return 0; |
13a9930d WS |
2965 | } |
2966 | #endif | |
2967 | ||
2968 | /*------------------------------------------------------------------*/ | |
2969 | /* Private handler : get eeprom checksum result */ | |
1df65547 WS |
2970 | static int ks_wlan_get_eeprom_cksum(struct net_device *dev, |
2971 | struct iw_request_info *info, __u32 * uwrq, | |
2972 | char *extra) | |
13a9930d | 2973 | { |
1df65547 WS |
2974 | struct ks_wlan_private *priv = |
2975 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d WS |
2976 | |
2977 | *uwrq = priv->eeprom_checksum; | |
2978 | return 0; | |
2979 | } | |
2980 | ||
1df65547 WS |
2981 | static void print_hif_event(int event) |
2982 | { | |
13a9930d | 2983 | |
1df65547 WS |
2984 | switch (event) { |
2985 | case HIF_DATA_REQ: | |
13a9930d WS |
2986 | printk("HIF_DATA_REQ\n"); |
2987 | break; | |
1df65547 | 2988 | case HIF_DATA_IND: |
13a9930d WS |
2989 | printk("HIF_DATA_IND\n"); |
2990 | break; | |
1df65547 | 2991 | case HIF_MIB_GET_REQ: |
13a9930d WS |
2992 | printk("HIF_MIB_GET_REQ\n"); |
2993 | break; | |
1df65547 | 2994 | case HIF_MIB_GET_CONF: |
13a9930d WS |
2995 | printk("HIF_MIB_GET_CONF\n"); |
2996 | break; | |
1df65547 | 2997 | case HIF_MIB_SET_REQ: |
13a9930d WS |
2998 | printk("HIF_MIB_SET_REQ\n"); |
2999 | break; | |
1df65547 | 3000 | case HIF_MIB_SET_CONF: |
13a9930d WS |
3001 | printk("HIF_MIB_SET_CONF\n"); |
3002 | break; | |
1df65547 | 3003 | case HIF_POWERMGT_REQ: |
13a9930d WS |
3004 | printk("HIF_POWERMGT_REQ\n"); |
3005 | break; | |
1df65547 | 3006 | case HIF_POWERMGT_CONF: |
13a9930d WS |
3007 | printk("HIF_POWERMGT_CONF\n"); |
3008 | break; | |
1df65547 | 3009 | case HIF_START_REQ: |
13a9930d WS |
3010 | printk("HIF_START_REQ\n"); |
3011 | break; | |
1df65547 | 3012 | case HIF_START_CONF: |
13a9930d WS |
3013 | printk("HIF_START_CONF\n"); |
3014 | break; | |
1df65547 | 3015 | case HIF_CONNECT_IND: |
13a9930d WS |
3016 | printk("HIF_CONNECT_IND\n"); |
3017 | break; | |
1df65547 | 3018 | case HIF_STOP_REQ: |
13a9930d WS |
3019 | printk("HIF_STOP_REQ\n"); |
3020 | break; | |
1df65547 | 3021 | case HIF_STOP_CONF: |
13a9930d WS |
3022 | printk("HIF_STOP_CONF\n"); |
3023 | break; | |
1df65547 | 3024 | case HIF_PS_ADH_SET_REQ: |
13a9930d WS |
3025 | printk("HIF_PS_ADH_SET_REQ\n"); |
3026 | break; | |
3027 | case HIF_PS_ADH_SET_CONF: | |
3028 | printk("HIF_PS_ADH_SET_CONF\n"); | |
3029 | break; | |
1df65547 | 3030 | case HIF_INFRA_SET_REQ: |
13a9930d WS |
3031 | printk("HIF_INFRA_SET_REQ\n"); |
3032 | break; | |
1df65547 | 3033 | case HIF_INFRA_SET_CONF: |
13a9930d WS |
3034 | printk("HIF_INFRA_SET_CONF\n"); |
3035 | break; | |
1df65547 | 3036 | case HIF_ADH_SET_REQ: |
13a9930d WS |
3037 | printk("HIF_ADH_SET_REQ\n"); |
3038 | break; | |
1df65547 | 3039 | case HIF_ADH_SET_CONF: |
13a9930d WS |
3040 | printk("HIF_ADH_SET_CONF\n"); |
3041 | break; | |
1df65547 | 3042 | case HIF_AP_SET_REQ: |
13a9930d WS |
3043 | printk("HIF_AP_SET_REQ\n"); |
3044 | break; | |
1df65547 | 3045 | case HIF_AP_SET_CONF: |
13a9930d WS |
3046 | printk("HIF_AP_SET_CONF\n"); |
3047 | break; | |
1df65547 | 3048 | case HIF_ASSOC_INFO_IND: |
13a9930d WS |
3049 | printk("HIF_ASSOC_INFO_IND\n"); |
3050 | break; | |
3051 | case HIF_MIC_FAILURE_REQ: | |
3052 | printk("HIF_MIC_FAILURE_REQ\n"); | |
3053 | break; | |
1df65547 | 3054 | case HIF_MIC_FAILURE_CONF: |
13a9930d WS |
3055 | printk("HIF_MIC_FAILURE_CONF\n"); |
3056 | break; | |
1df65547 | 3057 | case HIF_SCAN_REQ: |
13a9930d WS |
3058 | printk("HIF_SCAN_REQ\n"); |
3059 | break; | |
1df65547 | 3060 | case HIF_SCAN_CONF: |
13a9930d WS |
3061 | printk("HIF_SCAN_CONF\n"); |
3062 | break; | |
1df65547 | 3063 | case HIF_PHY_INFO_REQ: |
13a9930d WS |
3064 | printk("HIF_PHY_INFO_REQ\n"); |
3065 | break; | |
1df65547 | 3066 | case HIF_PHY_INFO_CONF: |
13a9930d WS |
3067 | printk("HIF_PHY_INFO_CONF\n"); |
3068 | break; | |
1df65547 | 3069 | case HIF_SLEEP_REQ: |
13a9930d WS |
3070 | printk("HIF_SLEEP_REQ\n"); |
3071 | break; | |
1df65547 | 3072 | case HIF_SLEEP_CONF: |
13a9930d WS |
3073 | printk("HIF_SLEEP_CONF\n"); |
3074 | break; | |
1df65547 | 3075 | case HIF_PHY_INFO_IND: |
13a9930d WS |
3076 | printk("HIF_PHY_INFO_IND\n"); |
3077 | break; | |
1df65547 | 3078 | case HIF_SCAN_IND: |
13a9930d WS |
3079 | printk("HIF_SCAN_IND\n"); |
3080 | break; | |
1df65547 | 3081 | case HIF_INFRA_SET2_REQ: |
13a9930d WS |
3082 | printk("HIF_INFRA_SET2_REQ\n"); |
3083 | break; | |
3084 | case HIF_INFRA_SET2_CONF: | |
3085 | printk("HIF_INFRA_SET2_CONF\n"); | |
3086 | break; | |
1df65547 | 3087 | case HIF_ADH_SET2_REQ: |
13a9930d WS |
3088 | printk("HIF_ADH_SET2_REQ\n"); |
3089 | break; | |
1df65547 | 3090 | case HIF_ADH_SET2_CONF: |
13a9930d WS |
3091 | printk("HIF_ADH_SET2_CONF\n"); |
3092 | } | |
3093 | } | |
3094 | ||
3095 | /*------------------------------------------------------------------*/ | |
3096 | /* Private handler : get host command history */ | |
3097 | static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info, | |
1df65547 | 3098 | __u32 * uwrq, char *extra) |
13a9930d | 3099 | { |
1df65547 WS |
3100 | int i, event; |
3101 | struct ks_wlan_private *priv = | |
3102 | (struct ks_wlan_private *)netdev_priv(dev); | |
13a9930d | 3103 | |
1df65547 WS |
3104 | for (i = 63; i >= 0; i--) { |
3105 | event = | |
3106 | priv->hostt.buff[(priv->hostt.qtail - 1 - i) % | |
3107 | SME_EVENT_BUFF_SIZE]; | |
13a9930d WS |
3108 | print_hif_event(event); |
3109 | } | |
3110 | return 0; | |
3111 | } | |
3112 | ||
3113 | /* Structures to export the Wireless Handlers */ | |
3114 | ||
3115 | static const struct iw_priv_args ks_wlan_private_args[] = { | |
3116 | /*{ cmd, set_args, get_args, name[16] } */ | |
1df65547 WS |
3117 | {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE, |
3118 | IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"}, | |
13a9930d | 3119 | #ifdef WPS |
1df65547 WS |
3120 | {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
3121 | IW_PRIV_TYPE_NONE, "SetWPSEnable"}, | |
3122 | {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE, | |
3123 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"}, | |
3124 | {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE, | |
3125 | "SetWPSProbeReq"}, | |
13a9930d | 3126 | #endif /* WPS */ |
1df65547 WS |
3127 | {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
3128 | IW_PRIV_TYPE_NONE, "SetPreamble"}, | |
3129 | {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE, | |
3130 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"}, | |
3131 | {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3132 | IW_PRIV_TYPE_NONE, "SetPowerSave"}, | |
3133 | {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE, | |
3134 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"}, | |
3135 | {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3136 | IW_PRIV_TYPE_NONE, "SetScanType"}, | |
3137 | {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE, | |
3138 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"}, | |
3139 | {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3140 | IW_PRIV_TYPE_NONE, "SetRxGain"}, | |
3141 | {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE, | |
3142 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"}, | |
3143 | {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1), | |
3144 | "hostt"}, | |
3145 | {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3146 | IW_PRIV_TYPE_NONE, "SetBeaconLost"}, | |
3147 | {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE, | |
3148 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"}, | |
3149 | {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3150 | IW_PRIV_TYPE_NONE, "SetSleepMode"}, | |
3151 | {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE, | |
3152 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"}, | |
3153 | {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3154 | IW_PRIV_TYPE_NONE, "SetTxGain"}, | |
3155 | {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE, | |
3156 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"}, | |
3157 | {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3158 | IW_PRIV_TYPE_NONE, "SetPhyType"}, | |
3159 | {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE, | |
3160 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"}, | |
3161 | {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3162 | IW_PRIV_TYPE_NONE, "SetCtsMode"}, | |
3163 | {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE, | |
3164 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"}, | |
3165 | {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE, | |
3166 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"}, | |
13a9930d | 3167 | }; |
1df65547 WS |
3168 | |
3169 | static const iw_handler ks_wlan_handler[] = { | |
13a9930d | 3170 | (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */ |
1df65547 WS |
3171 | (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */ |
3172 | (iw_handler) NULL, /* SIOCSIWNWID */ | |
3173 | (iw_handler) NULL, /* SIOCGIWNWID */ | |
3174 | (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */ | |
3175 | (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */ | |
3176 | (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */ | |
3177 | (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */ | |
13a9930d | 3178 | #ifndef KSC_OPNOTSUPP |
1df65547 WS |
3179 | (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */ |
3180 | (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */ | |
13a9930d | 3181 | #else /* KSC_OPNOTSUPP */ |
1df65547 WS |
3182 | (iw_handler) NULL, /* SIOCSIWSENS */ |
3183 | (iw_handler) NULL, /* SIOCGIWSENS */ | |
13a9930d | 3184 | #endif /* KSC_OPNOTSUPP */ |
1df65547 WS |
3185 | (iw_handler) NULL, /* SIOCSIWRANGE */ |
3186 | (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */ | |
3187 | (iw_handler) NULL, /* SIOCSIWPRIV */ | |
3188 | (iw_handler) NULL, /* SIOCGIWPRIV */ | |
3189 | (iw_handler) NULL, /* SIOCSIWSTATS */ | |
13a9930d | 3190 | (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */ |
1df65547 WS |
3191 | (iw_handler) NULL, /* SIOCSIWSPY */ |
3192 | (iw_handler) NULL, /* SIOCGIWSPY */ | |
3193 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ | |
3194 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ | |
3195 | (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */ | |
3196 | (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */ | |
3197 | // (iw_handler) NULL, /* SIOCSIWMLME */ | |
3198 | (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */ | |
13a9930d | 3199 | (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */ |
1df65547 WS |
3200 | (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */ |
3201 | (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */ | |
3202 | (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */ | |
3203 | (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */ | |
3204 | (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */ | |
3205 | (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */ | |
3206 | (iw_handler) NULL, /* -- hole -- */ | |
3207 | (iw_handler) NULL, /* -- hole -- */ | |
3208 | (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */ | |
3209 | (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */ | |
3210 | (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */ | |
3211 | (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */ | |
3212 | (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */ | |
3213 | (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */ | |
13a9930d | 3214 | #ifndef KSC_OPNOTSUPP |
1df65547 WS |
3215 | (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */ |
3216 | (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */ | |
3217 | (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */ | |
3218 | (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */ | |
13a9930d | 3219 | #else /* KSC_OPNOTSUPP */ |
1df65547 WS |
3220 | (iw_handler) NULL, /* SIOCSIWTXPOW */ |
3221 | (iw_handler) NULL, /* SIOCGIWTXPOW */ | |
3222 | (iw_handler) NULL, /* SIOCSIWRETRY */ | |
3223 | (iw_handler) NULL, /* SIOCGIWRETRY */ | |
13a9930d WS |
3224 | #endif /* KSC_OPNOTSUPP */ |
3225 | (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */ | |
3226 | (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */ | |
1df65547 WS |
3227 | (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */ |
3228 | (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */ | |
3229 | (iw_handler) NULL, /* -- hole -- */ | |
3230 | (iw_handler) NULL, /* -- hole -- */ | |
3231 | // (iw_handler) NULL, /* SIOCSIWGENIE */ | |
3232 | (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */ | |
3233 | (iw_handler) NULL, /* SIOCGIWGENIE */ | |
13a9930d WS |
3234 | (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */ |
3235 | (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */ | |
3236 | (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */ | |
3237 | (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */ | |
1df65547 WS |
3238 | (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */ |
3239 | (iw_handler) NULL, /* -- hole -- */ | |
13a9930d WS |
3240 | }; |
3241 | ||
3242 | /* private_handler */ | |
1df65547 WS |
3243 | static const iw_handler ks_wlan_private_handler[] = { |
3244 | (iw_handler) NULL, /* 0 */ | |
516a4f04 | 3245 | (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */ |
1df65547 | 3246 | (iw_handler) NULL, /* 2 */ |
13a9930d WS |
3247 | (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */ |
3248 | #ifdef WPS | |
1df65547 WS |
3249 | (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */ |
3250 | (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */ | |
3251 | (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */ | |
13a9930d | 3252 | #else |
1df65547 WS |
3253 | (iw_handler) NULL, /* 4 */ |
3254 | (iw_handler) NULL, /* 5 */ | |
3255 | (iw_handler) NULL, /* 6 */ | |
13a9930d WS |
3256 | #endif /* WPS */ |
3257 | ||
1df65547 WS |
3258 | (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */ |
3259 | (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */ | |
3260 | (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */ | |
3261 | (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */ | |
3262 | (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */ | |
3263 | (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */ | |
3264 | (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */ | |
3265 | (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */ | |
3266 | (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */ | |
3267 | (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */ | |
3268 | (iw_handler) NULL, /* 17 */ | |
3269 | (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */ | |
3270 | (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */ | |
3271 | (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */ | |
3272 | (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */ | |
3273 | (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */ | |
3274 | (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */ | |
3275 | (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */ | |
3276 | (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */ | |
3277 | (iw_handler) NULL, /* 26 */ | |
3278 | (iw_handler) NULL, /* 27 */ | |
3279 | (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */ | |
3280 | (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */ | |
3281 | (iw_handler) NULL, /* 30 */ | |
3282 | (iw_handler) NULL, /* 31 */ | |
13a9930d WS |
3283 | }; |
3284 | ||
1df65547 WS |
3285 | static const struct iw_handler_def ks_wlan_handler_def = { |
3286 | .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler), | |
3287 | .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler), | |
3288 | .num_private_args = | |
3289 | sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args), | |
3290 | .standard = (iw_handler *) ks_wlan_handler, | |
3291 | .private = (iw_handler *) ks_wlan_private_handler, | |
3292 | .private_args = (struct iw_priv_args *)ks_wlan_private_args, | |
13a9930d WS |
3293 | .get_wireless_stats = ks_get_wireless_stats, |
3294 | }; | |
3295 | ||
1df65547 WS |
3296 | static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, |
3297 | int cmd) | |
13a9930d WS |
3298 | { |
3299 | int rc = 0; | |
1df65547 | 3300 | struct iwreq *wrq = (struct iwreq *)rq; |
13a9930d | 3301 | switch (cmd) { |
1df65547 | 3302 | case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */ |
13a9930d WS |
3303 | rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL); |
3304 | break; | |
1df65547 | 3305 | // All other calls are currently unsupported |
13a9930d WS |
3306 | default: |
3307 | rc = -EOPNOTSUPP; | |
3308 | } | |
3309 | ||
1df65547 | 3310 | DPRINTK(5, "return=%d\n", rc); |
13a9930d WS |
3311 | return rc; |
3312 | } | |
3313 | ||
13a9930d WS |
3314 | static |
3315 | struct net_device_stats *ks_wlan_get_stats(struct net_device *dev) | |
3316 | { | |
feedcf1a | 3317 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
3318 | |
3319 | if (priv->dev_state < DEVICE_STATE_READY) { | |
1df65547 WS |
3320 | return NULL; /* not finished initialize */ |
3321 | } | |
13a9930d WS |
3322 | |
3323 | return &priv->nstats; | |
3324 | } | |
3325 | ||
3326 | static | |
3327 | int ks_wlan_set_mac_address(struct net_device *dev, void *addr) | |
3328 | { | |
feedcf1a | 3329 | struct ks_wlan_private *priv = netdev_priv(dev); |
1df65547 | 3330 | struct sockaddr *mac_addr = (struct sockaddr *)addr; |
13a9930d WS |
3331 | if (netif_running(dev)) |
3332 | return -EBUSY; | |
3333 | memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); | |
3334 | memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN); | |
3335 | ||
3336 | priv->mac_address_valid = 0; | |
3337 | hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST); | |
1df65547 WS |
3338 | printk(KERN_INFO |
3339 | "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
3340 | priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2], | |
3341 | priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]); | |
13a9930d WS |
3342 | return 0; |
3343 | } | |
3344 | ||
13a9930d WS |
3345 | static |
3346 | void ks_wlan_tx_timeout(struct net_device *dev) | |
3347 | { | |
1df65547 | 3348 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 3349 | |
1df65547 WS |
3350 | DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead, |
3351 | priv->tx_dev.qtail); | |
3352 | if (!netif_queue_stopped(dev)) { | |
13a9930d WS |
3353 | netif_stop_queue(dev); |
3354 | } | |
3355 | priv->nstats.tx_errors++; | |
3356 | netif_wake_queue(dev); | |
3357 | ||
3358 | return; | |
3359 | } | |
3360 | ||
3361 | static | |
3362 | int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
3363 | { | |
feedcf1a | 3364 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
3365 | int rc = 0; |
3366 | ||
1df65547 | 3367 | DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt()); |
13a9930d | 3368 | |
1df65547 WS |
3369 | if (skb == NULL) { |
3370 | printk(KERN_ERR "ks_wlan: skb == NULL!!!\n"); | |
13a9930d WS |
3371 | return 0; |
3372 | } | |
3373 | if (priv->dev_state < DEVICE_STATE_READY) { | |
3374 | dev_kfree_skb(skb); | |
1df65547 WS |
3375 | return 0; /* not finished initialize */ |
3376 | } | |
13a9930d | 3377 | |
1df65547 | 3378 | if (netif_running(dev)) |
13a9930d WS |
3379 | netif_stop_queue(dev); |
3380 | ||
3381 | rc = hostif_data_request(priv, skb); | |
4e66308e | 3382 | netif_trans_update(dev); |
13a9930d | 3383 | |
1df65547 WS |
3384 | DPRINTK(4, "rc=%d\n", rc); |
3385 | if (rc) { | |
3386 | rc = 0; | |
13a9930d WS |
3387 | } |
3388 | ||
3389 | return rc; | |
3390 | } | |
3391 | ||
3392 | void send_packet_complete(void *arg1, void *arg2) | |
3393 | { | |
feedcf1a | 3394 | struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1; |
13a9930d WS |
3395 | struct sk_buff *packet = (struct sk_buff *)arg2; |
3396 | ||
1df65547 | 3397 | DPRINTK(3, "\n"); |
13a9930d | 3398 | |
13a9930d WS |
3399 | priv->nstats.tx_packets++; |
3400 | ||
1df65547 WS |
3401 | if (netif_queue_stopped(priv->net_dev)) |
3402 | netif_wake_queue(priv->net_dev); | |
13a9930d | 3403 | |
1df65547 | 3404 | if (packet) { |
8defffb2 | 3405 | priv->nstats.tx_bytes += packet->len; |
13a9930d | 3406 | dev_kfree_skb(packet); |
1df65547 | 3407 | packet = NULL; |
13a9930d WS |
3408 | } |
3409 | ||
3410 | } | |
3411 | ||
3412 | /* Set or clear the multicast filter for this adaptor. | |
3413 | This routine is not state sensitive and need not be SMP locked. */ | |
3414 | static | |
3415 | void ks_wlan_set_multicast_list(struct net_device *dev) | |
3416 | { | |
feedcf1a | 3417 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d | 3418 | |
1df65547 | 3419 | DPRINTK(4, "\n"); |
13a9930d | 3420 | if (priv->dev_state < DEVICE_STATE_READY) { |
1df65547 | 3421 | return; /* not finished initialize */ |
13a9930d WS |
3422 | } |
3423 | hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST); | |
3424 | ||
3425 | return; | |
3426 | } | |
3427 | ||
3428 | static | |
3429 | int ks_wlan_open(struct net_device *dev) | |
3430 | { | |
feedcf1a | 3431 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
3432 | |
3433 | priv->cur_rx = 0; | |
3434 | ||
1df65547 | 3435 | if (!priv->mac_address_valid) { |
13a9930d WS |
3436 | printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name); |
3437 | return -EBUSY; | |
1df65547 WS |
3438 | } else |
3439 | netif_start_queue(dev); | |
13a9930d WS |
3440 | |
3441 | return 0; | |
3442 | } | |
3443 | ||
3444 | static | |
3445 | int ks_wlan_close(struct net_device *dev) | |
3446 | { | |
3447 | ||
1df65547 | 3448 | netif_stop_queue(dev); |
13a9930d WS |
3449 | |
3450 | DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n", | |
3451 | dev->name, 0x00); | |
3452 | ||
3453 | return 0; | |
3454 | } | |
3455 | ||
13a9930d WS |
3456 | /* Operational parameters that usually are not changed. */ |
3457 | /* Time in jiffies before concluding the transmitter is hung. */ | |
3458 | #define TX_TIMEOUT (3*HZ) | |
1df65547 WS |
3459 | static const unsigned char dummy_addr[] = |
3460 | { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 }; | |
13a9930d WS |
3461 | |
3462 | static const struct net_device_ops ks_wlan_netdev_ops = { | |
1df65547 WS |
3463 | .ndo_start_xmit = ks_wlan_start_xmit, |
3464 | .ndo_open = ks_wlan_open, | |
3465 | .ndo_stop = ks_wlan_close, | |
3466 | .ndo_do_ioctl = ks_wlan_netdev_ioctl, | |
3467 | .ndo_set_mac_address = ks_wlan_set_mac_address, | |
3468 | .ndo_get_stats = ks_wlan_get_stats, | |
3469 | .ndo_tx_timeout = ks_wlan_tx_timeout, | |
3470 | .ndo_set_rx_mode = ks_wlan_set_multicast_list, | |
13a9930d WS |
3471 | }; |
3472 | ||
3473 | int ks_wlan_net_start(struct net_device *dev) | |
3474 | { | |
feedcf1a | 3475 | struct ks_wlan_private *priv; |
13a9930d WS |
3476 | /* int rc; */ |
3477 | ||
3478 | priv = netdev_priv(dev); | |
3479 | priv->mac_address_valid = 0; | |
3480 | priv->need_commit = 0; | |
3481 | ||
3482 | priv->device_open_status = 1; | |
3483 | ||
3484 | /* phy information update timer */ | |
1df65547 | 3485 | atomic_set(&update_phyinfo, 0); |
13a9930d | 3486 | init_timer(&update_phyinfo_timer); |
1df65547 | 3487 | update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout; |
13a9930d WS |
3488 | update_phyinfo_timer.data = (unsigned long)priv; |
3489 | ||
3490 | /* dummy address set */ | |
3491 | memcpy(priv->eth_addr, dummy_addr, ETH_ALEN); | |
3492 | dev->dev_addr[0] = priv->eth_addr[0]; | |
3493 | dev->dev_addr[1] = priv->eth_addr[1]; | |
3494 | dev->dev_addr[2] = priv->eth_addr[2]; | |
3495 | dev->dev_addr[3] = priv->eth_addr[3]; | |
3496 | dev->dev_addr[4] = priv->eth_addr[4]; | |
3497 | dev->dev_addr[5] = priv->eth_addr[5]; | |
3498 | dev->dev_addr[6] = 0x00; | |
3499 | dev->dev_addr[7] = 0x00; | |
3500 | ||
3501 | /* The ks_wlan-specific entries in the device structure. */ | |
3502 | dev->netdev_ops = &ks_wlan_netdev_ops; | |
3503 | dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def; | |
3504 | dev->watchdog_timeo = TX_TIMEOUT; | |
3505 | ||
3506 | netif_carrier_off(dev); | |
3507 | ||
3508 | return 0; | |
3509 | } | |
3510 | ||
13a9930d WS |
3511 | int ks_wlan_net_stop(struct net_device *dev) |
3512 | { | |
feedcf1a | 3513 | struct ks_wlan_private *priv = netdev_priv(dev); |
13a9930d WS |
3514 | |
3515 | int ret = 0; | |
3516 | priv->device_open_status = 0; | |
3517 | del_timer_sync(&update_phyinfo_timer); | |
3518 | ||
1df65547 | 3519 | if (netif_running(dev)) |
13a9930d WS |
3520 | netif_stop_queue(dev); |
3521 | ||
3522 | return ret; | |
3523 | } | |
3524 | ||
3525 | int ks_wlan_reset(struct net_device *dev) | |
3526 | { | |
3527 | return 0; | |
3528 | } |