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