1 // SPDX-License-Identifier: GPL-2.0-only
3 * PS3 gelic network driver.
5 * Copyright (C) 2007 Sony Computer Entertainment Inc.
6 * Copyright 2007 Sony Corporation
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
14 #include <linux/etherdevice.h>
15 #include <linux/ethtool.h>
16 #include <linux/if_vlan.h>
20 #include <linux/tcp.h>
21 #include <linux/wireless.h>
22 #include <linux/ieee80211.h>
23 #include <linux/if_arp.h>
24 #include <linux/ctype.h>
25 #include <linux/string.h>
26 #include <net/iw_handler.h>
28 #include <linux/dma-mapping.h>
29 #include <net/checksum.h>
30 #include <asm/firmware.h>
32 #include <asm/lv1call.h>
34 #include "ps3_gelic_net.h"
35 #include "ps3_gelic_wireless.h"
38 static int gelic_wl_start_scan(struct gelic_wl_info
*wl
, int always_scan
,
39 u8
*essid
, size_t essid_len
);
40 static int gelic_wl_try_associate(struct net_device
*netdev
);
46 /* 802.11b/g channel to freq in MHz */
47 static const int channel_freq
[] = {
48 2412, 2417, 2422, 2427, 2432,
49 2437, 2442, 2447, 2452, 2457,
50 2462, 2467, 2472, 2484
52 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
55 static const int bitrate_list
[] = {
69 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
72 * wpa2 support requires the hypervisor version 2.0 or later
74 static inline int wpa2_capable(void)
76 return 0 <= ps3_compare_firmware_version(2, 0, 0);
79 static inline int precise_ie(void)
81 return 0 <= ps3_compare_firmware_version(2, 2, 0);
84 * post_eurus_cmd helpers
86 struct eurus_cmd_arg_info
{
87 int pre_arg
; /* command requires arg1, arg2 at POST COMMAND */
88 int post_arg
; /* command requires arg1, arg2 at GET_RESULT */
91 static const struct eurus_cmd_arg_info cmd_info
[GELIC_EURUS_CMD_MAX_INDEX
] = {
92 [GELIC_EURUS_CMD_SET_COMMON_CFG
] = { .pre_arg
= 1},
93 [GELIC_EURUS_CMD_SET_WEP_CFG
] = { .pre_arg
= 1},
94 [GELIC_EURUS_CMD_SET_WPA_CFG
] = { .pre_arg
= 1},
95 [GELIC_EURUS_CMD_GET_COMMON_CFG
] = { .post_arg
= 1},
96 [GELIC_EURUS_CMD_GET_WEP_CFG
] = { .post_arg
= 1},
97 [GELIC_EURUS_CMD_GET_WPA_CFG
] = { .post_arg
= 1},
98 [GELIC_EURUS_CMD_GET_RSSI_CFG
] = { .post_arg
= 1},
99 [GELIC_EURUS_CMD_START_SCAN
] = { .pre_arg
= 1},
100 [GELIC_EURUS_CMD_GET_SCAN
] = { .post_arg
= 1},
104 static const char *cmdstr(enum gelic_eurus_command ix
)
107 case GELIC_EURUS_CMD_ASSOC
:
109 case GELIC_EURUS_CMD_DISASSOC
:
111 case GELIC_EURUS_CMD_START_SCAN
:
113 case GELIC_EURUS_CMD_GET_SCAN
:
115 case GELIC_EURUS_CMD_SET_COMMON_CFG
:
116 return "SET_COMMON_CFG";
117 case GELIC_EURUS_CMD_GET_COMMON_CFG
:
118 return "GET_COMMON_CFG";
119 case GELIC_EURUS_CMD_SET_WEP_CFG
:
120 return "SET_WEP_CFG";
121 case GELIC_EURUS_CMD_GET_WEP_CFG
:
122 return "GET_WEP_CFG";
123 case GELIC_EURUS_CMD_SET_WPA_CFG
:
124 return "SET_WPA_CFG";
125 case GELIC_EURUS_CMD_GET_WPA_CFG
:
126 return "GET_WPA_CFG";
127 case GELIC_EURUS_CMD_GET_RSSI_CFG
:
135 static inline const char *cmdstr(enum gelic_eurus_command ix
)
141 /* synchronously do eurus commands */
142 static void gelic_eurus_sync_cmd_worker(struct work_struct
*work
)
144 struct gelic_eurus_cmd
*cmd
;
145 struct gelic_card
*card
;
146 struct gelic_wl_info
*wl
;
150 pr_debug("%s: <-\n", __func__
);
151 cmd
= container_of(work
, struct gelic_eurus_cmd
, work
);
152 BUG_ON(cmd_info
[cmd
->cmd
].pre_arg
&&
153 cmd_info
[cmd
->cmd
].post_arg
);
155 card
= port_to_card(wl_port(wl
));
157 if (cmd_info
[cmd
->cmd
].pre_arg
) {
158 arg1
= (cmd
->buffer
) ?
159 ps3_mm_phys_to_lpar(__pa(cmd
->buffer
)) :
161 arg2
= cmd
->buf_size
;
166 init_completion(&wl
->cmd_done_intr
);
167 pr_debug("%s: cmd='%s' start\n", __func__
, cmdstr(cmd
->cmd
));
168 cmd
->status
= lv1_net_control(bus_id(card
), dev_id(card
),
169 GELIC_LV1_POST_WLAN_CMD
,
170 cmd
->cmd
, arg1
, arg2
,
171 &cmd
->tag
, &cmd
->size
);
173 complete(&cmd
->done
);
174 pr_info("%s: cmd issue failed\n", __func__
);
178 wait_for_completion(&wl
->cmd_done_intr
);
180 if (cmd_info
[cmd
->cmd
].post_arg
) {
181 arg1
= ps3_mm_phys_to_lpar(__pa(cmd
->buffer
));
182 arg2
= cmd
->buf_size
;
188 cmd
->status
= lv1_net_control(bus_id(card
), dev_id(card
),
189 GELIC_LV1_GET_WLAN_CMD_RESULT
,
190 cmd
->tag
, arg1
, arg2
,
191 &cmd
->cmd_status
, &cmd
->size
);
193 if (cmd
->status
|| cmd
->cmd_status
) {
194 pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__
,
195 cmd
->tag
, arg1
, arg2
);
196 pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
197 __func__
, cmd
->status
, cmd
->cmd_status
, cmd
->size
);
200 complete(&cmd
->done
);
201 pr_debug("%s: cmd='%s' done\n", __func__
, cmdstr(cmd
->cmd
));
204 static struct gelic_eurus_cmd
*gelic_eurus_sync_cmd(struct gelic_wl_info
*wl
,
205 unsigned int eurus_cmd
,
207 unsigned int buf_size
)
209 struct gelic_eurus_cmd
*cmd
;
212 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
216 /* initialize members */
217 cmd
->cmd
= eurus_cmd
;
218 cmd
->buffer
= buffer
;
219 cmd
->buf_size
= buf_size
;
221 INIT_WORK(&cmd
->work
, gelic_eurus_sync_cmd_worker
);
222 init_completion(&cmd
->done
);
223 queue_work(wl
->eurus_cmd_queue
, &cmd
->work
);
225 /* wait for command completion */
226 wait_for_completion(&cmd
->done
);
231 static u32
gelic_wl_get_link(struct net_device
*netdev
)
233 struct gelic_wl_info
*wl
= port_wl(netdev_port(netdev
));
236 pr_debug("%s: <-\n", __func__
);
237 mutex_lock(&wl
->assoc_stat_lock
);
238 if (wl
->assoc_stat
== GELIC_WL_ASSOC_STAT_ASSOCIATED
)
242 mutex_unlock(&wl
->assoc_stat_lock
);
243 pr_debug("%s: ->\n", __func__
);
247 static void gelic_wl_send_iwap_event(struct gelic_wl_info
*wl
, u8
*bssid
)
249 union iwreq_data data
;
251 memset(&data
, 0, sizeof(data
));
253 memcpy(data
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
254 data
.ap_addr
.sa_family
= ARPHRD_ETHER
;
255 wireless_send_event(port_to_netdev(wl_port(wl
)), SIOCGIWAP
,
260 * wireless extension handlers and helpers
264 static int gelic_wl_get_name(struct net_device
*dev
,
265 struct iw_request_info
*info
,
266 union iwreq_data
*iwreq
, char *extra
)
268 strcpy(iwreq
->name
, "IEEE 802.11bg");
272 static void gelic_wl_get_ch_info(struct gelic_wl_info
*wl
)
274 struct gelic_card
*card
= port_to_card(wl_port(wl
));
275 u64 ch_info_raw
, tmp
;
278 if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO
, &wl
->stat
)) {
279 status
= lv1_net_control(bus_id(card
), dev_id(card
),
280 GELIC_LV1_GET_CHANNEL
, 0, 0, 0,
283 /* some fw versions may return error */
285 if (status
!= LV1_NO_ENTRY
)
286 pr_info("%s: available ch unknown\n", __func__
);
287 wl
->ch_info
= 0x07ff;/* 11 ch */
289 /* 16 bits of MSB has available channels */
290 wl
->ch_info
= ch_info_raw
>> 48;
295 static int gelic_wl_get_range(struct net_device
*netdev
,
296 struct iw_request_info
*info
,
297 union iwreq_data
*iwreq
, char *extra
)
299 struct iw_point
*point
= &iwreq
->data
;
300 struct iw_range
*range
= (struct iw_range
*)extra
;
301 struct gelic_wl_info
*wl
= port_wl(netdev_port(netdev
));
304 pr_debug("%s: <-\n", __func__
);
305 point
->length
= sizeof(struct iw_range
);
306 memset(range
, 0, sizeof(struct iw_range
));
308 range
->we_version_compiled
= WIRELESS_EXT
;
309 range
->we_version_source
= 22;
311 /* available channels and frequencies */
312 gelic_wl_get_ch_info(wl
);
315 i
< NUM_CHANNELS
&& chs
< IW_MAX_FREQUENCIES
; i
++)
316 if (wl
->ch_info
& (1 << i
)) {
317 range
->freq
[chs
].i
= i
+ 1;
318 range
->freq
[chs
].m
= channel_freq
[i
];
319 range
->freq
[chs
].e
= 6;
322 range
->num_frequency
= chs
;
323 range
->old_num_frequency
= chs
;
324 range
->num_channels
= chs
;
325 range
->old_num_channels
= chs
;
328 for (i
= 0; i
< NUM_BITRATES
; i
++)
329 range
->bitrate
[i
] = bitrate_list
[i
];
330 range
->num_bitrates
= i
;
333 range
->max_qual
.qual
= 100; /* relative value */
334 range
->max_qual
.level
= 100;
335 range
->avg_qual
.qual
= 50;
336 range
->avg_qual
.level
= 50;
337 range
->sensitivity
= 0;
339 /* Event capability */
340 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
341 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
342 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
344 /* encryption capability */
345 range
->enc_capa
= IW_ENC_CAPA_WPA
|
346 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
|
347 IW_ENC_CAPA_4WAY_HANDSHAKE
;
349 range
->enc_capa
|= IW_ENC_CAPA_WPA2
;
350 range
->encoding_size
[0] = 5; /* 40bit WEP */
351 range
->encoding_size
[1] = 13; /* 104bit WEP */
352 range
->encoding_size
[2] = 32; /* WPA-PSK */
353 range
->num_encoding_sizes
= 3;
354 range
->max_encoding_tokens
= GELIC_WEP_KEYS
;
356 /* scan capability */
357 range
->scan_capa
= IW_SCAN_CAPA_ESSID
;
359 pr_debug("%s: ->\n", __func__
);
364 /* SIOC{G,S}IWSCAN */
365 static int gelic_wl_set_scan(struct net_device
*netdev
,
366 struct iw_request_info
*info
,
367 union iwreq_data
*wrqu
, char *extra
)
369 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
370 struct iw_scan_req
*req
;
372 size_t essid_len
= 0;
374 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
) &&
375 wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
376 req
= (struct iw_scan_req
*)extra
;
378 essid_len
= req
->essid_len
;
379 pr_debug("%s: ESSID scan =%s\n", __func__
, essid
);
381 return gelic_wl_start_scan(wl
, 1, essid
, essid_len
);
385 static const u8 rsn_oui
[OUI_LEN
] = { 0x00, 0x0f, 0xac };
386 static const u8 wpa_oui
[OUI_LEN
] = { 0x00, 0x50, 0xf2 };
389 * synthesize WPA/RSN IE data
390 * See WiFi WPA specification and IEEE 802.11-2007 7.3.2.25
393 static size_t gelic_wl_synthesize_ie(u8
*buf
,
394 struct gelic_eurus_scan_info
*scan
)
397 const u8
*oui_header
;
402 pr_debug("%s: <- sec=%16x\n", __func__
, scan
->security
);
403 switch (be16_to_cpu(scan
->security
) & GELIC_EURUS_SCAN_SEC_MASK
) {
404 case GELIC_EURUS_SCAN_SEC_WPA
:
407 case GELIC_EURUS_SCAN_SEC_WPA2
:
411 /* WEP or none. No IE returned */
415 switch (be16_to_cpu(scan
->security
) & GELIC_EURUS_SCAN_SEC_WPA_MASK
) {
416 case GELIC_EURUS_SCAN_SEC_WPA_TKIP
:
419 case GELIC_EURUS_SCAN_SEC_WPA_AES
:
425 pr_info("%s: no cipher info. defaulted to CCMP\n",
429 pr_info("%s: no cipher info. defaulted to TKIP\n",
435 oui_header
= rsn_oui
;
437 oui_header
= wpa_oui
;
441 *buf
++ = WLAN_EID_RSN
;
443 *buf
++ = WLAN_EID_VENDOR_SPECIFIC
;
445 /* length filed; set later */
448 /* wpa special header */
450 memcpy(buf
, wpa_oui
, OUI_LEN
);
456 *buf
++ = 0x01; /* version 1.0 */
460 memcpy(buf
, oui_header
, OUI_LEN
);
464 *buf
++ = 0x04; /* CCMP */
466 *buf
++ = 0x02; /* TKIP */
468 /* pairwise key count always 1 */
472 /* pairwise key suit */
473 memcpy(buf
, oui_header
, OUI_LEN
);
476 *buf
++ = 0x04; /* CCMP */
478 *buf
++ = 0x02; /* TKIP */
484 /* AKM suite is assumed as PSK*/
485 memcpy(buf
, oui_header
, OUI_LEN
);
487 *buf
++ = 0x02; /* PSK */
489 /* RSN capabilities is 0 */
493 /* set length field */
494 start
[1] = (buf
- start
- 2);
496 pr_debug("%s: ->\n", __func__
);
510 static void gelic_wl_parse_ie(u8
*data
, size_t len
,
511 struct ie_info
*ie_info
)
513 size_t data_left
= len
;
518 pr_debug("%s: data=%p len=%ld\n", __func__
,
520 memset(ie_info
, 0, sizeof(struct ie_info
));
522 while (2 <= data_left
) {
527 if (data_left
< item_len
)
531 case WLAN_EID_VENDOR_SPECIFIC
:
532 if ((OUI_LEN
+ 1 <= item_len
) &&
533 !memcmp(pos
, wpa_oui
, OUI_LEN
) &&
534 pos
[OUI_LEN
] == 0x01) {
535 ie_info
->wpa
.data
= pos
- 2;
536 ie_info
->wpa
.len
= item_len
+ 2;
540 ie_info
->rsn
.data
= pos
- 2;
541 /* length includes the header */
542 ie_info
->rsn
.len
= item_len
+ 2;
545 pr_debug("%s: ignore %#x,%d\n", __func__
,
550 data_left
-= item_len
;
552 pr_debug("%s: wpa=%p,%d wpa2=%p,%d\n", __func__
,
553 ie_info
->wpa
.data
, ie_info
->wpa
.len
,
554 ie_info
->rsn
.data
, ie_info
->rsn
.len
);
559 * translate the scan informations from hypervisor to a
562 static char *gelic_wl_translate_scan(struct net_device
*netdev
,
563 struct iw_request_info
*info
,
566 struct gelic_wl_scan_info
*network
)
569 struct gelic_eurus_scan_info
*scan
= network
->hwinfo
;
572 unsigned int i
, j
, len
;
573 u8 buf
[64]; /* arbitrary size large enough */
575 pr_debug("%s: <-\n", __func__
);
577 /* first entry should be AP's mac address */
579 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
580 memcpy(iwe
.u
.ap_addr
.sa_data
, &scan
->bssid
[2], ETH_ALEN
);
581 ev
= iwe_stream_add_event(info
, ev
, stop
, &iwe
, IW_EV_ADDR_LEN
);
584 iwe
.cmd
= SIOCGIWESSID
;
585 iwe
.u
.data
.flags
= 1;
586 iwe
.u
.data
.length
= strnlen(scan
->essid
, 32);
587 ev
= iwe_stream_add_point(info
, ev
, stop
, &iwe
, scan
->essid
);
590 iwe
.cmd
= SIOCGIWFREQ
;
591 iwe
.u
.freq
.m
= be16_to_cpu(scan
->channel
);
592 iwe
.u
.freq
.e
= 0; /* table value in MHz */
594 ev
= iwe_stream_add_event(info
, ev
, stop
, &iwe
, IW_EV_FREQ_LEN
);
597 iwe
.cmd
= SIOCGIWRATE
;
598 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
599 /* to stuff multiple values in one event */
600 tmp
= ev
+ iwe_stream_lcp_len(info
);
601 /* put them in ascendant order (older is first) */
604 pr_debug("%s: rates=%d rate=%d\n", __func__
,
605 network
->rate_len
, network
->rate_ext_len
);
606 while (i
< network
->rate_len
) {
607 if (j
< network
->rate_ext_len
&&
608 ((scan
->ext_rate
[j
] & 0x7f) < (scan
->rate
[i
] & 0x7f)))
609 rate
= scan
->ext_rate
[j
++] & 0x7f;
611 rate
= scan
->rate
[i
++] & 0x7f;
612 iwe
.u
.bitrate
.value
= rate
* 500000; /* 500kbps unit */
613 tmp
= iwe_stream_add_value(info
, ev
, tmp
, stop
, &iwe
,
616 while (j
< network
->rate_ext_len
) {
617 iwe
.u
.bitrate
.value
= (scan
->ext_rate
[j
++] & 0x7f) * 500000;
618 tmp
= iwe_stream_add_value(info
, ev
, tmp
, stop
, &iwe
,
621 /* Check if we added any rate */
622 if (iwe_stream_lcp_len(info
) < (tmp
- ev
))
626 iwe
.cmd
= SIOCGIWENCODE
;
627 if (be16_to_cpu(scan
->capability
) & WLAN_CAPABILITY_PRIVACY
)
628 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
630 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
631 iwe
.u
.data
.length
= 0;
632 ev
= iwe_stream_add_point(info
, ev
, stop
, &iwe
, scan
->essid
);
635 iwe
.cmd
= SIOCGIWMODE
;
636 if (be16_to_cpu(scan
->capability
) &
637 (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
638 if (be16_to_cpu(scan
->capability
) & WLAN_CAPABILITY_ESS
)
639 iwe
.u
.mode
= IW_MODE_MASTER
;
641 iwe
.u
.mode
= IW_MODE_ADHOC
;
642 ev
= iwe_stream_add_event(info
, ev
, stop
, &iwe
, IW_EV_UINT_LEN
);
647 iwe
.u
.qual
.updated
= IW_QUAL_ALL_UPDATED
|
648 IW_QUAL_QUAL_INVALID
| IW_QUAL_NOISE_INVALID
;
649 iwe
.u
.qual
.level
= be16_to_cpu(scan
->rssi
);
650 iwe
.u
.qual
.qual
= be16_to_cpu(scan
->rssi
);
651 iwe
.u
.qual
.noise
= 0;
652 ev
= iwe_stream_add_event(info
, ev
, stop
, &iwe
, IW_EV_QUAL_LEN
);
655 memset(&iwe
, 0, sizeof(iwe
));
656 if (be16_to_cpu(scan
->size
) <= sizeof(*scan
)) {
657 /* If wpa[2] capable station, synthesize IE and put it */
658 len
= gelic_wl_synthesize_ie(buf
, scan
);
661 iwe
.u
.data
.length
= len
;
662 ev
= iwe_stream_add_point(info
, ev
, stop
, &iwe
, buf
);
665 /* this scan info has IE data */
666 struct ie_info ie_info
;
669 data_len
= be16_to_cpu(scan
->size
) - sizeof(*scan
);
671 gelic_wl_parse_ie(scan
->elements
, data_len
, &ie_info
);
673 if (ie_info
.wpa
.len
&& (ie_info
.wpa
.len
<= sizeof(buf
))) {
674 memcpy(buf
, ie_info
.wpa
.data
, ie_info
.wpa
.len
);
676 iwe
.u
.data
.length
= ie_info
.wpa
.len
;
677 ev
= iwe_stream_add_point(info
, ev
, stop
, &iwe
, buf
);
680 if (ie_info
.rsn
.len
&& (ie_info
.rsn
.len
<= sizeof(buf
))) {
681 memset(&iwe
, 0, sizeof(iwe
));
682 memcpy(buf
, ie_info
.rsn
.data
, ie_info
.rsn
.len
);
684 iwe
.u
.data
.length
= ie_info
.rsn
.len
;
685 ev
= iwe_stream_add_point(info
, ev
, stop
, &iwe
, buf
);
689 pr_debug("%s: ->\n", __func__
);
694 static int gelic_wl_get_scan(struct net_device
*netdev
,
695 struct iw_request_info
*info
,
696 union iwreq_data
*wrqu
, char *extra
)
698 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
699 struct gelic_wl_scan_info
*scan_info
;
701 char *stop
= ev
+ wrqu
->data
.length
;
703 unsigned long this_time
= jiffies
;
705 pr_debug("%s: <-\n", __func__
);
706 if (mutex_lock_interruptible(&wl
->scan_lock
))
709 switch (wl
->scan_stat
) {
710 case GELIC_WL_SCAN_STAT_SCANNING
:
711 /* If a scan in progress, caller should call me again */
714 case GELIC_WL_SCAN_STAT_INIT
:
715 /* last scan request failed or never issued */
718 case GELIC_WL_SCAN_STAT_GOT_LIST
:
719 /* ok, use current list */
723 list_for_each_entry(scan_info
, &wl
->network_list
, list
) {
724 if (wl
->scan_age
== 0 ||
725 time_after(scan_info
->last_scanned
+ wl
->scan_age
,
727 ev
= gelic_wl_translate_scan(netdev
, info
,
731 pr_debug("%s:entry too old\n", __func__
);
733 if (stop
- ev
<= IW_EV_ADDR_LEN
) {
739 wrqu
->data
.length
= ev
- extra
;
740 wrqu
->data
.flags
= 0;
742 mutex_unlock(&wl
->scan_lock
);
743 pr_debug("%s: -> %d %d\n", __func__
, ret
, wrqu
->data
.length
);
748 static void scan_list_dump(struct gelic_wl_info
*wl
)
750 struct gelic_wl_scan_info
*scan_info
;
754 list_for_each_entry(scan_info
, &wl
->network_list
, list
) {
755 pr_debug("%s: item %d\n", __func__
, i
++);
756 pr_debug("valid=%d eurusindex=%d last=%lx\n",
757 scan_info
->valid
, scan_info
->eurus_index
,
758 scan_info
->last_scanned
);
759 pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
760 scan_info
->rate_len
, scan_info
->rate_ext_len
,
761 scan_info
->essid_len
);
763 pr_debug("bssid=%pM\n", &scan_info
->hwinfo
->bssid
[2]);
764 pr_debug("essid=%s\n", scan_info
->hwinfo
->essid
);
769 static int gelic_wl_set_auth(struct net_device
*netdev
,
770 struct iw_request_info
*info
,
771 union iwreq_data
*data
, char *extra
)
773 struct iw_param
*param
= &data
->param
;
774 struct gelic_wl_info
*wl
= port_wl(netdev_port(netdev
));
775 unsigned long irqflag
;
778 pr_debug("%s: <- %d\n", __func__
, param
->flags
& IW_AUTH_INDEX
);
779 spin_lock_irqsave(&wl
->lock
, irqflag
);
780 switch (param
->flags
& IW_AUTH_INDEX
) {
781 case IW_AUTH_WPA_VERSION
:
782 if (param
->value
& IW_AUTH_WPA_VERSION_DISABLED
) {
783 pr_debug("%s: NO WPA selected\n", __func__
);
784 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_NONE
;
785 wl
->group_cipher_method
= GELIC_WL_CIPHER_WEP
;
786 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_WEP
;
788 if (param
->value
& IW_AUTH_WPA_VERSION_WPA
) {
789 pr_debug("%s: WPA version 1 selected\n", __func__
);
790 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_WPA
;
791 wl
->group_cipher_method
= GELIC_WL_CIPHER_TKIP
;
792 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_TKIP
;
793 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
;
795 if (param
->value
& IW_AUTH_WPA_VERSION_WPA2
) {
797 * As the hypervisor may not tell the cipher
798 * information of the AP if it is WPA2,
799 * you will not decide suitable cipher from
801 * You should have knowledge about the AP's
802 * cipher information in other method prior to
806 pr_info("%s: WPA2 may not work\n", __func__
);
807 if (wpa2_capable()) {
808 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_WPA2
;
809 wl
->group_cipher_method
= GELIC_WL_CIPHER_AES
;
810 wl
->pairwise_cipher_method
=
812 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
;
818 case IW_AUTH_CIPHER_PAIRWISE
:
820 (IW_AUTH_CIPHER_WEP104
| IW_AUTH_CIPHER_WEP40
)) {
821 pr_debug("%s: WEP selected\n", __func__
);
822 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_WEP
;
824 if (param
->value
& IW_AUTH_CIPHER_TKIP
) {
825 pr_debug("%s: TKIP selected\n", __func__
);
826 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_TKIP
;
828 if (param
->value
& IW_AUTH_CIPHER_CCMP
) {
829 pr_debug("%s: CCMP selected\n", __func__
);
830 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_AES
;
832 if (param
->value
& IW_AUTH_CIPHER_NONE
) {
833 pr_debug("%s: no auth selected\n", __func__
);
834 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_NONE
;
837 case IW_AUTH_CIPHER_GROUP
:
839 (IW_AUTH_CIPHER_WEP104
| IW_AUTH_CIPHER_WEP40
)) {
840 pr_debug("%s: WEP selected\n", __func__
);
841 wl
->group_cipher_method
= GELIC_WL_CIPHER_WEP
;
843 if (param
->value
& IW_AUTH_CIPHER_TKIP
) {
844 pr_debug("%s: TKIP selected\n", __func__
);
845 wl
->group_cipher_method
= GELIC_WL_CIPHER_TKIP
;
847 if (param
->value
& IW_AUTH_CIPHER_CCMP
) {
848 pr_debug("%s: CCMP selected\n", __func__
);
849 wl
->group_cipher_method
= GELIC_WL_CIPHER_AES
;
851 if (param
->value
& IW_AUTH_CIPHER_NONE
) {
852 pr_debug("%s: no auth selected\n", __func__
);
853 wl
->group_cipher_method
= GELIC_WL_CIPHER_NONE
;
856 case IW_AUTH_80211_AUTH_ALG
:
857 if (param
->value
& IW_AUTH_ALG_SHARED_KEY
) {
858 pr_debug("%s: shared key specified\n", __func__
);
859 wl
->auth_method
= GELIC_EURUS_AUTH_SHARED
;
860 } else if (param
->value
& IW_AUTH_ALG_OPEN_SYSTEM
) {
861 pr_debug("%s: open system specified\n", __func__
);
862 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
;
867 case IW_AUTH_WPA_ENABLED
:
869 pr_debug("%s: WPA enabled\n", __func__
);
870 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_WPA
;
872 pr_debug("%s: WPA disabled\n", __func__
);
873 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_NONE
;
877 case IW_AUTH_KEY_MGMT
:
878 if (param
->value
& IW_AUTH_KEY_MGMT_PSK
)
880 /* intentionally fall through */
887 set_bit(GELIC_WL_STAT_CONFIGURED
, &wl
->stat
);
889 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
890 pr_debug("%s: -> %d\n", __func__
, ret
);
894 static int gelic_wl_get_auth(struct net_device
*netdev
,
895 struct iw_request_info
*info
,
896 union iwreq_data
*iwreq
, char *extra
)
898 struct iw_param
*param
= &iwreq
->param
;
899 struct gelic_wl_info
*wl
= port_wl(netdev_port(netdev
));
900 unsigned long irqflag
;
903 pr_debug("%s: <- %d\n", __func__
, param
->flags
& IW_AUTH_INDEX
);
904 spin_lock_irqsave(&wl
->lock
, irqflag
);
905 switch (param
->flags
& IW_AUTH_INDEX
) {
906 case IW_AUTH_WPA_VERSION
:
907 switch (wl
->wpa_level
) {
908 case GELIC_WL_WPA_LEVEL_WPA
:
909 param
->value
|= IW_AUTH_WPA_VERSION_WPA
;
911 case GELIC_WL_WPA_LEVEL_WPA2
:
912 param
->value
|= IW_AUTH_WPA_VERSION_WPA2
;
915 param
->value
|= IW_AUTH_WPA_VERSION_DISABLED
;
919 case IW_AUTH_80211_AUTH_ALG
:
920 if (wl
->auth_method
== GELIC_EURUS_AUTH_SHARED
)
921 param
->value
= IW_AUTH_ALG_SHARED_KEY
;
922 else if (wl
->auth_method
== GELIC_EURUS_AUTH_OPEN
)
923 param
->value
= IW_AUTH_ALG_OPEN_SYSTEM
;
926 case IW_AUTH_WPA_ENABLED
:
927 switch (wl
->wpa_level
) {
928 case GELIC_WL_WPA_LEVEL_WPA
:
929 case GELIC_WL_WPA_LEVEL_WPA2
:
941 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
942 pr_debug("%s: -> %d\n", __func__
, ret
);
946 /* SIOC{S,G}IWESSID */
947 static int gelic_wl_set_essid(struct net_device
*netdev
,
948 struct iw_request_info
*info
,
949 union iwreq_data
*data
, char *extra
)
951 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
952 unsigned long irqflag
;
954 pr_debug("%s: <- l=%d f=%d\n", __func__
,
955 data
->essid
.length
, data
->essid
.flags
);
956 if (IW_ESSID_MAX_SIZE
< data
->essid
.length
)
959 spin_lock_irqsave(&wl
->lock
, irqflag
);
960 if (data
->essid
.flags
) {
961 wl
->essid_len
= data
->essid
.length
;
962 memcpy(wl
->essid
, extra
, wl
->essid_len
);
963 pr_debug("%s: essid = '%s'\n", __func__
, extra
);
964 set_bit(GELIC_WL_STAT_ESSID_SET
, &wl
->stat
);
966 pr_debug("%s: ESSID any\n", __func__
);
967 clear_bit(GELIC_WL_STAT_ESSID_SET
, &wl
->stat
);
969 set_bit(GELIC_WL_STAT_CONFIGURED
, &wl
->stat
);
970 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
973 gelic_wl_try_associate(netdev
); /* FIXME */
974 pr_debug("%s: ->\n", __func__
);
978 static int gelic_wl_get_essid(struct net_device
*netdev
,
979 struct iw_request_info
*info
,
980 union iwreq_data
*data
, char *extra
)
982 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
983 unsigned long irqflag
;
985 pr_debug("%s: <-\n", __func__
);
986 mutex_lock(&wl
->assoc_stat_lock
);
987 spin_lock_irqsave(&wl
->lock
, irqflag
);
988 if (test_bit(GELIC_WL_STAT_ESSID_SET
, &wl
->stat
) ||
989 wl
->assoc_stat
== GELIC_WL_ASSOC_STAT_ASSOCIATED
) {
990 memcpy(extra
, wl
->essid
, wl
->essid_len
);
991 data
->essid
.length
= wl
->essid_len
;
992 data
->essid
.flags
= 1;
994 data
->essid
.flags
= 0;
996 mutex_unlock(&wl
->assoc_stat_lock
);
997 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
998 pr_debug("%s: -> len=%d\n", __func__
, data
->essid
.length
);
1003 /* SIO{S,G}IWENCODE */
1004 static int gelic_wl_set_encode(struct net_device
*netdev
,
1005 struct iw_request_info
*info
,
1006 union iwreq_data
*data
, char *extra
)
1008 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1009 struct iw_point
*enc
= &data
->encoding
;
1011 unsigned long irqflag
;
1012 int key_index
, index_specified
;
1015 pr_debug("%s: <-\n", __func__
);
1016 flags
= enc
->flags
& IW_ENCODE_FLAGS
;
1017 key_index
= enc
->flags
& IW_ENCODE_INDEX
;
1019 pr_debug("%s: key_index = %d\n", __func__
, key_index
);
1020 pr_debug("%s: key_len = %d\n", __func__
, enc
->length
);
1021 pr_debug("%s: flag=%x\n", __func__
, enc
->flags
& IW_ENCODE_FLAGS
);
1023 if (GELIC_WEP_KEYS
< key_index
)
1026 spin_lock_irqsave(&wl
->lock
, irqflag
);
1028 index_specified
= 1;
1031 index_specified
= 0;
1032 key_index
= wl
->current_key
;
1035 if (flags
& IW_ENCODE_NOKEY
) {
1036 /* if just IW_ENCODE_NOKEY, change current key index */
1037 if (!flags
&& index_specified
) {
1038 wl
->current_key
= key_index
;
1042 if (flags
& IW_ENCODE_DISABLED
) {
1043 if (!index_specified
) {
1044 /* disable encryption */
1045 wl
->group_cipher_method
= GELIC_WL_CIPHER_NONE
;
1046 wl
->pairwise_cipher_method
=
1047 GELIC_WL_CIPHER_NONE
;
1048 /* invalidate all key */
1049 wl
->key_enabled
= 0;
1051 clear_bit(key_index
, &wl
->key_enabled
);
1054 if (flags
& IW_ENCODE_OPEN
)
1055 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
;
1056 if (flags
& IW_ENCODE_RESTRICTED
) {
1057 pr_info("%s: shared key mode enabled\n", __func__
);
1058 wl
->auth_method
= GELIC_EURUS_AUTH_SHARED
;
1061 if (IW_ENCODING_TOKEN_MAX
< enc
->length
) {
1065 wl
->key_len
[key_index
] = enc
->length
;
1066 memcpy(wl
->key
[key_index
], extra
, enc
->length
);
1067 set_bit(key_index
, &wl
->key_enabled
);
1068 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_WEP
;
1069 wl
->group_cipher_method
= GELIC_WL_CIPHER_WEP
;
1071 set_bit(GELIC_WL_STAT_CONFIGURED
, &wl
->stat
);
1073 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
1074 pr_debug("%s: ->\n", __func__
);
1078 static int gelic_wl_get_encode(struct net_device
*netdev
,
1079 struct iw_request_info
*info
,
1080 union iwreq_data
*data
, char *extra
)
1082 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1083 struct iw_point
*enc
= &data
->encoding
;
1084 unsigned long irqflag
;
1085 unsigned int key_index
;
1088 pr_debug("%s: <-\n", __func__
);
1089 key_index
= enc
->flags
& IW_ENCODE_INDEX
;
1090 pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__
,
1091 enc
->flags
, enc
->pointer
, enc
->length
, extra
);
1092 if (GELIC_WEP_KEYS
< key_index
)
1095 spin_lock_irqsave(&wl
->lock
, irqflag
);
1099 key_index
= wl
->current_key
;
1101 if (wl
->group_cipher_method
== GELIC_WL_CIPHER_WEP
) {
1102 switch (wl
->auth_method
) {
1103 case GELIC_EURUS_AUTH_OPEN
:
1104 enc
->flags
= IW_ENCODE_OPEN
;
1106 case GELIC_EURUS_AUTH_SHARED
:
1107 enc
->flags
= IW_ENCODE_RESTRICTED
;
1111 enc
->flags
= IW_ENCODE_DISABLED
;
1113 if (test_bit(key_index
, &wl
->key_enabled
)) {
1114 if (enc
->length
< wl
->key_len
[key_index
]) {
1118 enc
->length
= wl
->key_len
[key_index
];
1119 memcpy(extra
, wl
->key
[key_index
], wl
->key_len
[key_index
]);
1122 enc
->flags
|= IW_ENCODE_NOKEY
;
1124 enc
->flags
|= key_index
+ 1;
1125 pr_debug("%s: -> flag=%x len=%d\n", __func__
,
1126 enc
->flags
, enc
->length
);
1129 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
1134 static int gelic_wl_set_ap(struct net_device
*netdev
,
1135 struct iw_request_info
*info
,
1136 union iwreq_data
*data
, char *extra
)
1138 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1139 unsigned long irqflag
;
1141 pr_debug("%s: <-\n", __func__
);
1142 if (data
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
1145 spin_lock_irqsave(&wl
->lock
, irqflag
);
1146 if (is_valid_ether_addr(data
->ap_addr
.sa_data
)) {
1147 memcpy(wl
->bssid
, data
->ap_addr
.sa_data
,
1149 set_bit(GELIC_WL_STAT_BSSID_SET
, &wl
->stat
);
1150 set_bit(GELIC_WL_STAT_CONFIGURED
, &wl
->stat
);
1151 pr_debug("%s: bss=%pM\n", __func__
, wl
->bssid
);
1153 pr_debug("%s: clear bssid\n", __func__
);
1154 clear_bit(GELIC_WL_STAT_BSSID_SET
, &wl
->stat
);
1155 eth_zero_addr(wl
->bssid
);
1157 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
1158 pr_debug("%s: ->\n", __func__
);
1162 static int gelic_wl_get_ap(struct net_device
*netdev
,
1163 struct iw_request_info
*info
,
1164 union iwreq_data
*data
, char *extra
)
1166 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1167 unsigned long irqflag
;
1169 pr_debug("%s: <-\n", __func__
);
1170 mutex_lock(&wl
->assoc_stat_lock
);
1171 spin_lock_irqsave(&wl
->lock
, irqflag
);
1172 if (wl
->assoc_stat
== GELIC_WL_ASSOC_STAT_ASSOCIATED
) {
1173 data
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1174 memcpy(data
->ap_addr
.sa_data
, wl
->active_bssid
,
1177 eth_zero_addr(data
->ap_addr
.sa_data
);
1179 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
1180 mutex_unlock(&wl
->assoc_stat_lock
);
1181 pr_debug("%s: ->\n", __func__
);
1185 /* SIOC{S,G}IWENCODEEXT */
1186 static int gelic_wl_set_encodeext(struct net_device
*netdev
,
1187 struct iw_request_info
*info
,
1188 union iwreq_data
*data
, char *extra
)
1190 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1191 struct iw_point
*enc
= &data
->encoding
;
1192 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1195 unsigned long irqflag
;
1199 pr_debug("%s: <-\n", __func__
);
1200 flags
= enc
->flags
& IW_ENCODE_FLAGS
;
1202 key_index
= enc
->flags
& IW_ENCODE_INDEX
;
1204 pr_debug("%s: key_index = %d\n", __func__
, key_index
);
1205 pr_debug("%s: key_len = %d\n", __func__
, enc
->length
);
1206 pr_debug("%s: flag=%x\n", __func__
, enc
->flags
& IW_ENCODE_FLAGS
);
1207 pr_debug("%s: ext_flag=%x\n", __func__
, ext
->ext_flags
);
1208 pr_debug("%s: ext_key_len=%x\n", __func__
, ext
->key_len
);
1210 if (GELIC_WEP_KEYS
< key_index
)
1213 spin_lock_irqsave(&wl
->lock
, irqflag
);
1217 key_index
= wl
->current_key
;
1219 if (!enc
->length
&& (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)) {
1220 /* reques to change default key index */
1221 pr_debug("%s: request to change default key to %d\n",
1222 __func__
, key_index
);
1223 wl
->current_key
= key_index
;
1227 if (alg
== IW_ENCODE_ALG_NONE
|| (flags
& IW_ENCODE_DISABLED
)) {
1228 pr_debug("%s: alg disabled\n", __func__
);
1229 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_NONE
;
1230 wl
->group_cipher_method
= GELIC_WL_CIPHER_NONE
;
1231 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_NONE
;
1232 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
; /* should be open */
1233 } else if (alg
== IW_ENCODE_ALG_WEP
) {
1234 pr_debug("%s: WEP requested\n", __func__
);
1235 if (flags
& IW_ENCODE_OPEN
) {
1236 pr_debug("%s: open key mode\n", __func__
);
1237 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
;
1239 if (flags
& IW_ENCODE_RESTRICTED
) {
1240 pr_debug("%s: shared key mode\n", __func__
);
1241 wl
->auth_method
= GELIC_EURUS_AUTH_SHARED
;
1243 if (IW_ENCODING_TOKEN_MAX
< ext
->key_len
) {
1244 pr_info("%s: key is too long %d\n", __func__
,
1249 /* OK, update the key */
1250 wl
->key_len
[key_index
] = ext
->key_len
;
1251 memset(wl
->key
[key_index
], 0, IW_ENCODING_TOKEN_MAX
);
1252 memcpy(wl
->key
[key_index
], ext
->key
, ext
->key_len
);
1253 set_bit(key_index
, &wl
->key_enabled
);
1254 /* remember wep info changed */
1255 set_bit(GELIC_WL_STAT_CONFIGURED
, &wl
->stat
);
1256 } else if (alg
== IW_ENCODE_ALG_PMK
) {
1257 if (ext
->key_len
!= WPA_PSK_LEN
) {
1258 pr_err("%s: PSK length wrong %d\n", __func__
,
1263 memset(wl
->psk
, 0, sizeof(wl
->psk
));
1264 memcpy(wl
->psk
, ext
->key
, ext
->key_len
);
1265 wl
->psk_len
= ext
->key_len
;
1266 wl
->psk_type
= GELIC_EURUS_WPA_PSK_BIN
;
1267 /* remember PSK configured */
1268 set_bit(GELIC_WL_STAT_WPA_PSK_SET
, &wl
->stat
);
1271 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
1272 pr_debug("%s: ->\n", __func__
);
1276 static int gelic_wl_get_encodeext(struct net_device
*netdev
,
1277 struct iw_request_info
*info
,
1278 union iwreq_data
*data
, char *extra
)
1280 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1281 struct iw_point
*enc
= &data
->encoding
;
1282 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1283 unsigned long irqflag
;
1288 pr_debug("%s: <-\n", __func__
);
1290 max_key_len
= enc
->length
- sizeof(struct iw_encode_ext
);
1291 if (max_key_len
< 0)
1293 key_index
= enc
->flags
& IW_ENCODE_INDEX
;
1295 pr_debug("%s: key_index = %d\n", __func__
, key_index
);
1296 pr_debug("%s: key_len = %d\n", __func__
, enc
->length
);
1297 pr_debug("%s: flag=%x\n", __func__
, enc
->flags
& IW_ENCODE_FLAGS
);
1299 if (GELIC_WEP_KEYS
< key_index
)
1302 spin_lock_irqsave(&wl
->lock
, irqflag
);
1306 key_index
= wl
->current_key
;
1308 memset(ext
, 0, sizeof(struct iw_encode_ext
));
1309 switch (wl
->group_cipher_method
) {
1310 case GELIC_WL_CIPHER_WEP
:
1311 ext
->alg
= IW_ENCODE_ALG_WEP
;
1312 enc
->flags
|= IW_ENCODE_ENABLED
;
1314 case GELIC_WL_CIPHER_TKIP
:
1315 ext
->alg
= IW_ENCODE_ALG_TKIP
;
1316 enc
->flags
|= IW_ENCODE_ENABLED
;
1318 case GELIC_WL_CIPHER_AES
:
1319 ext
->alg
= IW_ENCODE_ALG_CCMP
;
1320 enc
->flags
|= IW_ENCODE_ENABLED
;
1322 case GELIC_WL_CIPHER_NONE
:
1324 ext
->alg
= IW_ENCODE_ALG_NONE
;
1325 enc
->flags
|= IW_ENCODE_NOKEY
;
1329 if (!(enc
->flags
& IW_ENCODE_NOKEY
)) {
1330 if (max_key_len
< wl
->key_len
[key_index
]) {
1334 if (test_bit(key_index
, &wl
->key_enabled
))
1335 memcpy(ext
->key
, wl
->key
[key_index
],
1336 wl
->key_len
[key_index
]);
1338 pr_debug("%s: disabled key requested ix=%d\n",
1339 __func__
, key_index
);
1342 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
1343 pr_debug("%s: ->\n", __func__
);
1346 /* SIOC{S,G}IWMODE */
1347 static int gelic_wl_set_mode(struct net_device
*netdev
,
1348 struct iw_request_info
*info
,
1349 union iwreq_data
*data
, char *extra
)
1351 __u32 mode
= data
->mode
;
1354 pr_debug("%s: <-\n", __func__
);
1355 if (mode
== IW_MODE_INFRA
)
1359 pr_debug("%s: -> %d\n", __func__
, ret
);
1363 static int gelic_wl_get_mode(struct net_device
*netdev
,
1364 struct iw_request_info
*info
,
1365 union iwreq_data
*data
, char *extra
)
1367 __u32
*mode
= &data
->mode
;
1368 pr_debug("%s: <-\n", __func__
);
1369 *mode
= IW_MODE_INFRA
;
1370 pr_debug("%s: ->\n", __func__
);
1375 static int gelic_wl_get_nick(struct net_device
*net_dev
,
1376 struct iw_request_info
*info
,
1377 union iwreq_data
*data
, char *extra
)
1379 strcpy(extra
, "gelic_wl");
1380 data
->data
.length
= strlen(extra
);
1381 data
->data
.flags
= 1;
1388 static struct iw_statistics
*gelic_wl_get_wireless_stats(
1389 struct net_device
*netdev
)
1392 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
1393 struct gelic_eurus_cmd
*cmd
;
1394 struct iw_statistics
*is
;
1395 struct gelic_eurus_rssi_info
*rssi
;
1398 pr_debug("%s: <-\n", __func__
);
1400 buf
= (void *)__get_free_page(GFP_KERNEL
);
1405 memset(is
, 0, sizeof(*is
));
1406 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_GET_RSSI_CFG
,
1407 buf
, sizeof(*rssi
));
1408 if (cmd
&& !cmd
->status
&& !cmd
->cmd_status
) {
1410 is
->qual
.level
= be16_to_cpu(rssi
->rssi
);
1411 is
->qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
1412 IW_QUAL_QUAL_INVALID
| IW_QUAL_NOISE_INVALID
;
1414 /* not associated */
1415 is
->qual
.updated
= IW_QUAL_ALL_INVALID
;
1418 free_page((unsigned long)buf
);
1419 pr_debug("%s: ->\n", __func__
);
1426 static int gelic_wl_start_scan(struct gelic_wl_info
*wl
, int always_scan
,
1427 u8
*essid
, size_t essid_len
)
1429 struct gelic_eurus_cmd
*cmd
;
1434 pr_debug("%s: <- always=%d\n", __func__
, always_scan
);
1435 if (mutex_lock_interruptible(&wl
->scan_lock
))
1436 return -ERESTARTSYS
;
1439 * If already a scan in progress, do not trigger more
1441 if (wl
->scan_stat
== GELIC_WL_SCAN_STAT_SCANNING
) {
1442 pr_debug("%s: scanning now\n", __func__
);
1446 init_completion(&wl
->scan_done
);
1448 * If we have already a bss list, don't try to get new
1449 * unless we are doing an ESSID scan
1451 if ((!essid_len
&& !always_scan
)
1452 && wl
->scan_stat
== GELIC_WL_SCAN_STAT_GOT_LIST
) {
1453 pr_debug("%s: already has the list\n", __func__
);
1454 complete(&wl
->scan_done
);
1459 if (essid_len
&& essid
) {
1460 buf
= (void *)__get_free_page(GFP_KERNEL
);
1465 len
= IW_ESSID_MAX_SIZE
; /* hypervisor always requires 32 */
1466 memset(buf
, 0, len
);
1467 memcpy(buf
, essid
, essid_len
);
1468 pr_debug("%s: essid scan='%s'\n", __func__
, (char *)buf
);
1473 * issue start scan request
1475 wl
->scan_stat
= GELIC_WL_SCAN_STAT_SCANNING
;
1476 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_START_SCAN
,
1478 if (!cmd
|| cmd
->status
|| cmd
->cmd_status
) {
1479 wl
->scan_stat
= GELIC_WL_SCAN_STAT_INIT
;
1480 complete(&wl
->scan_done
);
1486 free_page((unsigned long)buf
);
1487 mutex_unlock(&wl
->scan_lock
);
1488 pr_debug("%s: ->\n", __func__
);
1493 * retrieve scan result from the chip (hypervisor)
1494 * this function is invoked by schedule work.
1496 static void gelic_wl_scan_complete_event(struct gelic_wl_info
*wl
)
1498 struct gelic_eurus_cmd
*cmd
= NULL
;
1499 struct gelic_wl_scan_info
*target
, *tmp
;
1500 struct gelic_wl_scan_info
*oldest
= NULL
;
1501 struct gelic_eurus_scan_info
*scan_info
;
1502 unsigned int scan_info_size
;
1503 union iwreq_data data
;
1504 unsigned long this_time
= jiffies
;
1505 unsigned int data_len
, i
, found
, r
;
1508 pr_debug("%s:start\n", __func__
);
1509 mutex_lock(&wl
->scan_lock
);
1511 buf
= (void *)__get_free_page(GFP_KERNEL
);
1513 pr_info("%s: scan buffer alloc failed\n", __func__
);
1517 if (wl
->scan_stat
!= GELIC_WL_SCAN_STAT_SCANNING
) {
1519 * stop() may be called while scanning, ignore result
1521 pr_debug("%s: scan complete when stat != scanning(%d)\n",
1522 __func__
, wl
->scan_stat
);
1526 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_GET_SCAN
,
1528 if (!cmd
|| cmd
->status
|| cmd
->cmd_status
) {
1529 wl
->scan_stat
= GELIC_WL_SCAN_STAT_INIT
;
1530 pr_info("%s:cmd failed\n", __func__
);
1534 data_len
= cmd
->size
;
1535 pr_debug("%s: data_len = %d\n", __func__
, data_len
);
1538 /* OK, bss list retrieved */
1539 wl
->scan_stat
= GELIC_WL_SCAN_STAT_GOT_LIST
;
1541 /* mark all entries are old */
1542 list_for_each_entry_safe(target
, tmp
, &wl
->network_list
, list
) {
1544 /* expire too old entries */
1545 if (time_before(target
->last_scanned
+ wl
->scan_age
,
1547 kfree(target
->hwinfo
);
1548 target
->hwinfo
= NULL
;
1549 list_move_tail(&target
->list
, &wl
->network_free_list
);
1553 /* put them in the network_list */
1554 for (i
= 0, scan_info_size
= 0, scan_info
= buf
;
1555 scan_info_size
< data_len
;
1556 i
++, scan_info_size
+= be16_to_cpu(scan_info
->size
),
1557 scan_info
= (void *)scan_info
+ be16_to_cpu(scan_info
->size
)) {
1558 pr_debug("%s:size=%d bssid=%pM scan_info=%p\n", __func__
,
1559 be16_to_cpu(scan_info
->size
),
1560 &scan_info
->bssid
[2], scan_info
);
1563 * The wireless firmware may return invalid channel 0 and/or
1564 * invalid rate if the AP emits zero length SSID ie. As this
1565 * scan information is useless, ignore it
1567 if (!be16_to_cpu(scan_info
->channel
) || !scan_info
->rate
[0]) {
1568 pr_debug("%s: invalid scan info\n", __func__
);
1574 list_for_each_entry(target
, &wl
->network_list
, list
) {
1575 if (ether_addr_equal(&target
->hwinfo
->bssid
[2],
1576 &scan_info
->bssid
[2])) {
1578 pr_debug("%s: same BBS found scanned list\n",
1583 (target
->last_scanned
< oldest
->last_scanned
))
1588 /* not found in the list */
1589 if (list_empty(&wl
->network_free_list
)) {
1593 target
= list_entry(wl
->network_free_list
.next
,
1594 struct gelic_wl_scan_info
,
1599 /* update the item */
1600 target
->last_scanned
= this_time
;
1602 target
->eurus_index
= i
;
1603 kfree(target
->hwinfo
);
1604 target
->hwinfo
= kmemdup(scan_info
,
1605 be16_to_cpu(scan_info
->size
),
1607 if (!target
->hwinfo
)
1610 /* copy hw scan info */
1611 target
->essid_len
= strnlen(scan_info
->essid
,
1612 sizeof(scan_info
->essid
));
1613 target
->rate_len
= 0;
1614 for (r
= 0; r
< 12; r
++)
1615 if (scan_info
->rate
[r
])
1617 if (8 < target
->rate_len
)
1618 pr_info("%s: AP returns %d rates\n", __func__
,
1620 target
->rate_ext_len
= 0;
1621 for (r
= 0; r
< 16; r
++)
1622 if (scan_info
->ext_rate
[r
])
1623 target
->rate_ext_len
++;
1624 list_move_tail(&target
->list
, &wl
->network_list
);
1626 memset(&data
, 0, sizeof(data
));
1627 wireless_send_event(port_to_netdev(wl_port(wl
)), SIOCGIWSCAN
, &data
,
1630 free_page((unsigned long)buf
);
1631 complete(&wl
->scan_done
);
1632 mutex_unlock(&wl
->scan_lock
);
1633 pr_debug("%s:end\n", __func__
);
1637 * Select an appropriate bss from current scan list regarding
1638 * current settings from userspace.
1639 * The caller must hold wl->scan_lock,
1640 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1642 static void update_best(struct gelic_wl_scan_info
**best
,
1643 struct gelic_wl_scan_info
*candid
,
1647 if (*best_weight
< ++(*weight
)) {
1648 *best_weight
= *weight
;
1654 struct gelic_wl_scan_info
*gelic_wl_find_best_bss(struct gelic_wl_info
*wl
)
1656 struct gelic_wl_scan_info
*scan_info
;
1657 struct gelic_wl_scan_info
*best_bss
;
1658 int weight
, best_weight
;
1661 pr_debug("%s: <-\n", __func__
);
1666 list_for_each_entry(scan_info
, &wl
->network_list
, list
) {
1667 pr_debug("%s: station %p\n", __func__
, scan_info
);
1669 if (!scan_info
->valid
) {
1670 pr_debug("%s: station invalid\n", __func__
);
1674 /* If bss specified, check it only */
1675 if (test_bit(GELIC_WL_STAT_BSSID_SET
, &wl
->stat
)) {
1676 if (ether_addr_equal(&scan_info
->hwinfo
->bssid
[2],
1678 best_bss
= scan_info
;
1679 pr_debug("%s: bssid matched\n", __func__
);
1682 pr_debug("%s: bssid unmatched\n", __func__
);
1690 security
= be16_to_cpu(scan_info
->hwinfo
->security
) &
1691 GELIC_EURUS_SCAN_SEC_MASK
;
1692 if (wl
->wpa_level
== GELIC_WL_WPA_LEVEL_WPA2
) {
1693 if (security
== GELIC_EURUS_SCAN_SEC_WPA2
)
1694 update_best(&best_bss
, scan_info
,
1695 &best_weight
, &weight
);
1698 } else if (wl
->wpa_level
== GELIC_WL_WPA_LEVEL_WPA
) {
1699 if (security
== GELIC_EURUS_SCAN_SEC_WPA
)
1700 update_best(&best_bss
, scan_info
,
1701 &best_weight
, &weight
);
1704 } else if (wl
->wpa_level
== GELIC_WL_WPA_LEVEL_NONE
&&
1705 wl
->group_cipher_method
== GELIC_WL_CIPHER_WEP
) {
1706 if (security
== GELIC_EURUS_SCAN_SEC_WEP
)
1707 update_best(&best_bss
, scan_info
,
1708 &best_weight
, &weight
);
1713 /* If ESSID is set, check it */
1714 if (test_bit(GELIC_WL_STAT_ESSID_SET
, &wl
->stat
)) {
1715 if ((scan_info
->essid_len
== wl
->essid_len
) &&
1717 scan_info
->hwinfo
->essid
,
1718 scan_info
->essid_len
))
1719 update_best(&best_bss
, scan_info
,
1720 &best_weight
, &weight
);
1727 pr_debug("%s: -> bss=%p\n", __func__
, best_bss
);
1729 pr_debug("%s:addr=%pM\n", __func__
,
1730 &best_bss
->hwinfo
->bssid
[2]);
1737 * Setup WEP configuration to the chip
1738 * The caller must hold wl->scan_lock,
1739 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1741 static int gelic_wl_do_wep_setup(struct gelic_wl_info
*wl
)
1744 struct gelic_eurus_wep_cfg
*wep
;
1745 struct gelic_eurus_cmd
*cmd
;
1750 pr_debug("%s: <-\n", __func__
);
1751 /* we can assume no one should uses the buffer */
1752 wep
= (struct gelic_eurus_wep_cfg
*)__get_free_page(GFP_KERNEL
);
1756 memset(wep
, 0, sizeof(*wep
));
1758 if (wl
->group_cipher_method
== GELIC_WL_CIPHER_WEP
) {
1759 pr_debug("%s: WEP mode\n", __func__
);
1760 for (i
= 0; i
< GELIC_WEP_KEYS
; i
++) {
1761 if (!test_bit(i
, &wl
->key_enabled
))
1764 pr_debug("%s: key#%d enabled\n", __func__
, i
);
1766 if (wl
->key_len
[i
] == 13)
1768 else if (wl
->key_len
[i
] != 5) {
1769 pr_info("%s: wrong wep key[%d]=%d\n",
1770 __func__
, i
, wl
->key_len
[i
]);
1774 memcpy(wep
->key
[i
], wl
->key
[i
], wl
->key_len
[i
]);
1778 pr_info("%s: all wep key disabled\n", __func__
);
1784 pr_debug("%s: 104bit key\n", __func__
);
1785 wep
->security
= cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT
);
1787 pr_debug("%s: 40bit key\n", __func__
);
1788 wep
->security
= cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT
);
1791 pr_debug("%s: NO encryption\n", __func__
);
1792 wep
->security
= cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE
);
1795 /* issue wep setup */
1796 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_SET_WEP_CFG
,
1800 else if (cmd
->status
|| cmd
->cmd_status
)
1805 free_page((unsigned long)wep
);
1806 pr_debug("%s: ->\n", __func__
);
1811 static const char *wpasecstr(enum gelic_eurus_wpa_security sec
)
1814 case GELIC_EURUS_WPA_SEC_NONE
:
1816 case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP
:
1817 return "WPA_TKIP_TKIP";
1818 case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES
:
1819 return "WPA_TKIP_AES";
1820 case GELIC_EURUS_WPA_SEC_WPA_AES_AES
:
1821 return "WPA_AES_AES";
1822 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP
:
1823 return "WPA2_TKIP_TKIP";
1824 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES
:
1825 return "WPA2_TKIP_AES";
1826 case GELIC_EURUS_WPA_SEC_WPA2_AES_AES
:
1827 return "WPA2_AES_AES";
1833 static int gelic_wl_do_wpa_setup(struct gelic_wl_info
*wl
)
1835 struct gelic_eurus_wpa_cfg
*wpa
;
1836 struct gelic_eurus_cmd
*cmd
;
1840 pr_debug("%s: <-\n", __func__
);
1841 /* we can assume no one should uses the buffer */
1842 wpa
= (struct gelic_eurus_wpa_cfg
*)__get_free_page(GFP_KERNEL
);
1846 memset(wpa
, 0, sizeof(*wpa
));
1848 if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET
, &wl
->stat
))
1849 pr_info("%s: PSK not configured yet\n", __func__
);
1852 memcpy(wpa
->psk
, wl
->psk
, wl
->psk_len
);
1854 /* set security level */
1855 if (wl
->wpa_level
== GELIC_WL_WPA_LEVEL_WPA2
) {
1856 if (wl
->group_cipher_method
== GELIC_WL_CIPHER_AES
) {
1857 security
= GELIC_EURUS_WPA_SEC_WPA2_AES_AES
;
1859 if (wl
->pairwise_cipher_method
== GELIC_WL_CIPHER_AES
&&
1861 security
= GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES
;
1863 security
= GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP
;
1866 if (wl
->group_cipher_method
== GELIC_WL_CIPHER_AES
) {
1867 security
= GELIC_EURUS_WPA_SEC_WPA_AES_AES
;
1869 if (wl
->pairwise_cipher_method
== GELIC_WL_CIPHER_AES
&&
1871 security
= GELIC_EURUS_WPA_SEC_WPA_TKIP_AES
;
1873 security
= GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP
;
1876 wpa
->security
= cpu_to_be16(security
);
1879 wpa
->psk_type
= cpu_to_be16(wl
->psk_type
);
1881 pr_debug("%s: sec=%s psktype=%s\n", __func__
,
1882 wpasecstr(wpa
->security
),
1883 (wpa
->psk_type
== GELIC_EURUS_WPA_PSK_BIN
) ?
1884 "BIN" : "passphrase");
1887 * don't enable here if you plan to submit
1888 * the debug log because this dumps your precious
1891 pr_debug("%s: psk=%s\n", __func__
,
1892 (wpa
->psk_type
== GELIC_EURUS_WPA_PSK_BIN
) ?
1896 /* issue wpa setup */
1897 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_SET_WPA_CFG
,
1901 else if (cmd
->status
|| cmd
->cmd_status
)
1904 free_page((unsigned long)wpa
);
1905 pr_debug("%s: --> %d\n", __func__
, ret
);
1910 * Start association. caller must hold assoc_stat_lock
1912 static int gelic_wl_associate_bss(struct gelic_wl_info
*wl
,
1913 struct gelic_wl_scan_info
*bss
)
1915 struct gelic_eurus_cmd
*cmd
;
1916 struct gelic_eurus_common_cfg
*common
;
1920 pr_debug("%s: <-\n", __func__
);
1922 /* do common config */
1923 common
= (struct gelic_eurus_common_cfg
*)__get_free_page(GFP_KERNEL
);
1927 memset(common
, 0, sizeof(*common
));
1928 common
->bss_type
= cpu_to_be16(GELIC_EURUS_BSS_INFRA
);
1929 common
->op_mode
= cpu_to_be16(GELIC_EURUS_OPMODE_11BG
);
1931 common
->scan_index
= cpu_to_be16(bss
->eurus_index
);
1932 switch (wl
->auth_method
) {
1933 case GELIC_EURUS_AUTH_OPEN
:
1934 common
->auth_method
= cpu_to_be16(GELIC_EURUS_AUTH_OPEN
);
1936 case GELIC_EURUS_AUTH_SHARED
:
1937 common
->auth_method
= cpu_to_be16(GELIC_EURUS_AUTH_SHARED
);
1944 pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__
,
1945 be16_to_cpu(common
->scan_index
),
1946 be16_to_cpu(common
->bss_type
),
1947 be16_to_cpu(common
->auth_method
));
1949 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_SET_COMMON_CFG
,
1950 common
, sizeof(*common
));
1951 if (!cmd
|| cmd
->status
|| cmd
->cmd_status
) {
1959 switch (wl
->wpa_level
) {
1960 case GELIC_WL_WPA_LEVEL_NONE
:
1961 /* If WEP or no security, setup WEP config */
1962 ret
= gelic_wl_do_wep_setup(wl
);
1964 case GELIC_WL_WPA_LEVEL_WPA
:
1965 case GELIC_WL_WPA_LEVEL_WPA2
:
1966 ret
= gelic_wl_do_wpa_setup(wl
);
1971 pr_debug("%s: WEP/WPA setup failed %d\n", __func__
,
1974 gelic_wl_send_iwap_event(wl
, NULL
);
1978 /* start association */
1979 init_completion(&wl
->assoc_done
);
1980 wl
->assoc_stat
= GELIC_WL_ASSOC_STAT_ASSOCIATING
;
1981 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_ASSOC
,
1983 if (!cmd
|| cmd
->status
|| cmd
->cmd_status
) {
1984 pr_debug("%s: assoc request failed\n", __func__
);
1985 wl
->assoc_stat
= GELIC_WL_ASSOC_STAT_DISCONN
;
1988 gelic_wl_send_iwap_event(wl
, NULL
);
1993 /* wait for connected event */
1994 rc
= wait_for_completion_timeout(&wl
->assoc_done
, HZ
* 4);/*FIXME*/
1997 /* timeouted. Maybe key or cyrpt mode is wrong */
1998 pr_info("%s: connect timeout\n", __func__
);
1999 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_DISASSOC
,
2002 wl
->assoc_stat
= GELIC_WL_ASSOC_STAT_DISCONN
;
2003 gelic_wl_send_iwap_event(wl
, NULL
);
2006 wl
->assoc_stat
= GELIC_WL_ASSOC_STAT_ASSOCIATED
;
2008 memcpy(wl
->active_bssid
, &bss
->hwinfo
->bssid
[2], ETH_ALEN
);
2010 /* send connect event */
2011 gelic_wl_send_iwap_event(wl
, wl
->active_bssid
);
2012 pr_info("%s: connected\n", __func__
);
2015 free_page((unsigned long)common
);
2016 pr_debug("%s: ->\n", __func__
);
2023 static void gelic_wl_connected_event(struct gelic_wl_info
*wl
,
2026 u64 desired_event
= 0;
2028 switch (wl
->wpa_level
) {
2029 case GELIC_WL_WPA_LEVEL_NONE
:
2030 desired_event
= GELIC_LV1_WL_EVENT_CONNECTED
;
2032 case GELIC_WL_WPA_LEVEL_WPA
:
2033 case GELIC_WL_WPA_LEVEL_WPA2
:
2034 desired_event
= GELIC_LV1_WL_EVENT_WPA_CONNECTED
;
2038 if (desired_event
== event
) {
2039 pr_debug("%s: completed\n", __func__
);
2040 complete(&wl
->assoc_done
);
2041 netif_carrier_on(port_to_netdev(wl_port(wl
)));
2043 pr_debug("%s: event %#llx under wpa\n",
2050 static void gelic_wl_disconnect_event(struct gelic_wl_info
*wl
,
2053 struct gelic_eurus_cmd
*cmd
;
2057 * If we fall here in the middle of association,
2058 * associate_bss() should be waiting for complation of
2060 * As it waits with timeout, just leave assoc_done
2061 * uncompleted, then it terminates with timeout
2063 if (!mutex_trylock(&wl
->assoc_stat_lock
)) {
2064 pr_debug("%s: already locked\n", __func__
);
2067 pr_debug("%s: obtain lock\n", __func__
);
2071 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_DISASSOC
, NULL
, 0);
2074 /* send disconnected event to the supplicant */
2075 if (wl
->assoc_stat
== GELIC_WL_ASSOC_STAT_ASSOCIATED
)
2076 gelic_wl_send_iwap_event(wl
, NULL
);
2078 wl
->assoc_stat
= GELIC_WL_ASSOC_STAT_DISCONN
;
2079 netif_carrier_off(port_to_netdev(wl_port(wl
)));
2082 mutex_unlock(&wl
->assoc_stat_lock
);
2088 static const char *eventstr(enum gelic_lv1_wl_event event
)
2090 static char buf
[32];
2092 if (event
& GELIC_LV1_WL_EVENT_DEVICE_READY
)
2093 ret
= "EURUS_READY";
2094 else if (event
& GELIC_LV1_WL_EVENT_SCAN_COMPLETED
)
2095 ret
= "SCAN_COMPLETED";
2096 else if (event
& GELIC_LV1_WL_EVENT_DEAUTH
)
2098 else if (event
& GELIC_LV1_WL_EVENT_BEACON_LOST
)
2099 ret
= "BEACON_LOST";
2100 else if (event
& GELIC_LV1_WL_EVENT_CONNECTED
)
2102 else if (event
& GELIC_LV1_WL_EVENT_WPA_CONNECTED
)
2103 ret
= "WPA_CONNECTED";
2104 else if (event
& GELIC_LV1_WL_EVENT_WPA_ERROR
)
2107 sprintf(buf
, "Unknown(%#x)", event
);
2113 static const char *eventstr(enum gelic_lv1_wl_event event
)
2118 static void gelic_wl_event_worker(struct work_struct
*work
)
2120 struct gelic_wl_info
*wl
;
2121 struct gelic_port
*port
;
2125 pr_debug("%s:start\n", __func__
);
2126 wl
= container_of(work
, struct gelic_wl_info
, event_work
.work
);
2129 status
= lv1_net_control(bus_id(port
->card
), dev_id(port
->card
),
2130 GELIC_LV1_GET_WLAN_EVENT
, 0, 0, 0,
2133 if (status
!= LV1_NO_ENTRY
)
2134 pr_debug("%s:wlan event failed %d\n",
2136 /* got all events */
2137 pr_debug("%s:end\n", __func__
);
2140 pr_debug("%s: event=%s\n", __func__
, eventstr(event
));
2142 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED
:
2143 gelic_wl_scan_complete_event(wl
);
2145 case GELIC_LV1_WL_EVENT_BEACON_LOST
:
2146 case GELIC_LV1_WL_EVENT_DEAUTH
:
2147 gelic_wl_disconnect_event(wl
, event
);
2149 case GELIC_LV1_WL_EVENT_CONNECTED
:
2150 case GELIC_LV1_WL_EVENT_WPA_CONNECTED
:
2151 gelic_wl_connected_event(wl
, event
);
2159 * association worker
2161 static void gelic_wl_assoc_worker(struct work_struct
*work
)
2163 struct gelic_wl_info
*wl
;
2165 struct gelic_wl_scan_info
*best_bss
;
2167 unsigned long irqflag
;
2171 wl
= container_of(work
, struct gelic_wl_info
, assoc_work
.work
);
2173 mutex_lock(&wl
->assoc_stat_lock
);
2175 if (wl
->assoc_stat
!= GELIC_WL_ASSOC_STAT_DISCONN
)
2178 spin_lock_irqsave(&wl
->lock
, irqflag
);
2179 if (test_bit(GELIC_WL_STAT_ESSID_SET
, &wl
->stat
)) {
2180 pr_debug("%s: assoc ESSID configured %s\n", __func__
,
2183 essid_len
= wl
->essid_len
;
2188 spin_unlock_irqrestore(&wl
->lock
, irqflag
);
2190 ret
= gelic_wl_start_scan(wl
, 0, essid
, essid_len
);
2191 if (ret
== -ERESTARTSYS
) {
2192 pr_debug("%s: scan start failed association\n", __func__
);
2193 schedule_delayed_work(&wl
->assoc_work
, HZ
/10); /*FIXME*/
2196 pr_info("%s: scan prerequisite failed\n", __func__
);
2201 * Wait for bss scan completion
2202 * If we have scan list already, gelic_wl_start_scan()
2203 * returns OK and raises the complete. Thus,
2204 * it's ok to wait unconditionally here
2206 wait_for_completion(&wl
->scan_done
);
2208 pr_debug("%s: scan done\n", __func__
);
2209 mutex_lock(&wl
->scan_lock
);
2210 if (wl
->scan_stat
!= GELIC_WL_SCAN_STAT_GOT_LIST
) {
2211 gelic_wl_send_iwap_event(wl
, NULL
);
2212 pr_info("%s: no scan list. association failed\n", __func__
);
2216 /* find best matching bss */
2217 best_bss
= gelic_wl_find_best_bss(wl
);
2219 gelic_wl_send_iwap_event(wl
, NULL
);
2220 pr_info("%s: no bss matched. association failed\n", __func__
);
2224 /* ok, do association */
2225 ret
= gelic_wl_associate_bss(wl
, best_bss
);
2227 pr_info("%s: association failed %d\n", __func__
, ret
);
2229 mutex_unlock(&wl
->scan_lock
);
2231 mutex_unlock(&wl
->assoc_stat_lock
);
2235 * Called from the ethernet interrupt handler
2236 * Processes wireless specific virtual interrupts only
2238 void gelic_wl_interrupt(struct net_device
*netdev
, u64 status
)
2240 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
2242 if (status
& GELIC_CARD_WLAN_COMMAND_COMPLETED
) {
2243 pr_debug("%s:cmd complete\n", __func__
);
2244 complete(&wl
->cmd_done_intr
);
2247 if (status
& GELIC_CARD_WLAN_EVENT_RECEIVED
) {
2248 pr_debug("%s:event received\n", __func__
);
2249 queue_delayed_work(wl
->event_queue
, &wl
->event_work
, 0);
2256 static const iw_handler gelic_wl_wext_handler
[] =
2258 IW_HANDLER(SIOCGIWNAME
, gelic_wl_get_name
),
2259 IW_HANDLER(SIOCGIWRANGE
, gelic_wl_get_range
),
2260 IW_HANDLER(SIOCSIWSCAN
, gelic_wl_set_scan
),
2261 IW_HANDLER(SIOCGIWSCAN
, gelic_wl_get_scan
),
2262 IW_HANDLER(SIOCSIWAUTH
, gelic_wl_set_auth
),
2263 IW_HANDLER(SIOCGIWAUTH
, gelic_wl_get_auth
),
2264 IW_HANDLER(SIOCSIWESSID
, gelic_wl_set_essid
),
2265 IW_HANDLER(SIOCGIWESSID
, gelic_wl_get_essid
),
2266 IW_HANDLER(SIOCSIWENCODE
, gelic_wl_set_encode
),
2267 IW_HANDLER(SIOCGIWENCODE
, gelic_wl_get_encode
),
2268 IW_HANDLER(SIOCSIWAP
, gelic_wl_set_ap
),
2269 IW_HANDLER(SIOCGIWAP
, gelic_wl_get_ap
),
2270 IW_HANDLER(SIOCSIWENCODEEXT
, gelic_wl_set_encodeext
),
2271 IW_HANDLER(SIOCGIWENCODEEXT
, gelic_wl_get_encodeext
),
2272 IW_HANDLER(SIOCSIWMODE
, gelic_wl_set_mode
),
2273 IW_HANDLER(SIOCGIWMODE
, gelic_wl_get_mode
),
2274 IW_HANDLER(SIOCGIWNICKN
, gelic_wl_get_nick
),
2277 static const struct iw_handler_def gelic_wl_wext_handler_def
= {
2278 .num_standard
= ARRAY_SIZE(gelic_wl_wext_handler
),
2279 .standard
= gelic_wl_wext_handler
,
2280 .get_wireless_stats
= gelic_wl_get_wireless_stats
,
2283 static struct net_device
*gelic_wl_alloc(struct gelic_card
*card
)
2285 struct net_device
*netdev
;
2286 struct gelic_port
*port
;
2287 struct gelic_wl_info
*wl
;
2290 pr_debug("%s:start\n", __func__
);
2291 netdev
= alloc_etherdev(sizeof(struct gelic_port
) +
2292 sizeof(struct gelic_wl_info
));
2293 pr_debug("%s: netdev =%p card=%p\n", __func__
, netdev
, card
);
2297 strcpy(netdev
->name
, "wlan%d");
2299 port
= netdev_priv(netdev
);
2300 port
->netdev
= netdev
;
2302 port
->type
= GELIC_PORT_WIRELESS
;
2305 pr_debug("%s: wl=%p port=%p\n", __func__
, wl
, port
);
2307 /* allocate scan list */
2308 wl
->networks
= kcalloc(GELIC_WL_BSS_MAX_ENT
,
2309 sizeof(struct gelic_wl_scan_info
),
2315 wl
->eurus_cmd_queue
= create_singlethread_workqueue("gelic_cmd");
2316 if (!wl
->eurus_cmd_queue
)
2317 goto fail_cmd_workqueue
;
2319 wl
->event_queue
= create_singlethread_workqueue("gelic_event");
2320 if (!wl
->event_queue
)
2321 goto fail_event_workqueue
;
2323 INIT_LIST_HEAD(&wl
->network_free_list
);
2324 INIT_LIST_HEAD(&wl
->network_list
);
2325 for (i
= 0; i
< GELIC_WL_BSS_MAX_ENT
; i
++)
2326 list_add_tail(&wl
->networks
[i
].list
,
2327 &wl
->network_free_list
);
2328 init_completion(&wl
->cmd_done_intr
);
2330 INIT_DELAYED_WORK(&wl
->event_work
, gelic_wl_event_worker
);
2331 INIT_DELAYED_WORK(&wl
->assoc_work
, gelic_wl_assoc_worker
);
2332 mutex_init(&wl
->scan_lock
);
2333 mutex_init(&wl
->assoc_stat_lock
);
2335 init_completion(&wl
->scan_done
);
2336 /* for the case that no scan request is issued and stop() is called */
2337 complete(&wl
->scan_done
);
2339 spin_lock_init(&wl
->lock
);
2341 wl
->scan_age
= 5*HZ
; /* FIXME */
2343 /* buffer for receiving scanned list etc */
2344 BUILD_BUG_ON(PAGE_SIZE
<
2345 sizeof(struct gelic_eurus_scan_info
) *
2346 GELIC_EURUS_MAX_SCAN
);
2347 pr_debug("%s:end\n", __func__
);
2350 fail_event_workqueue
:
2351 destroy_workqueue(wl
->eurus_cmd_queue
);
2353 kfree(wl
->networks
);
2355 free_netdev(netdev
);
2356 pr_debug("%s:end error\n", __func__
);
2361 static void gelic_wl_free(struct gelic_wl_info
*wl
)
2363 struct gelic_wl_scan_info
*scan_info
;
2366 pr_debug("%s: <-\n", __func__
);
2368 pr_debug("%s: destroy queues\n", __func__
);
2369 destroy_workqueue(wl
->eurus_cmd_queue
);
2370 destroy_workqueue(wl
->event_queue
);
2372 scan_info
= wl
->networks
;
2373 for (i
= 0; i
< GELIC_WL_BSS_MAX_ENT
; i
++, scan_info
++)
2374 kfree(scan_info
->hwinfo
);
2375 kfree(wl
->networks
);
2377 free_netdev(port_to_netdev(wl_port(wl
)));
2379 pr_debug("%s: ->\n", __func__
);
2382 static int gelic_wl_try_associate(struct net_device
*netdev
)
2384 struct gelic_wl_info
*wl
= port_wl(netdev_priv(netdev
));
2388 pr_debug("%s: <-\n", __func__
);
2390 /* check constraits for start association */
2391 /* for no access restriction AP */
2392 if (wl
->group_cipher_method
== GELIC_WL_CIPHER_NONE
) {
2393 if (test_bit(GELIC_WL_STAT_CONFIGURED
,
2397 pr_debug("%s: no wep, not configured\n", __func__
);
2402 /* for WEP, one of four keys should be set */
2403 if (wl
->group_cipher_method
== GELIC_WL_CIPHER_WEP
) {
2404 /* one of keys set */
2405 for (i
= 0; i
< GELIC_WEP_KEYS
; i
++) {
2406 if (test_bit(i
, &wl
->key_enabled
))
2409 pr_debug("%s: WEP, but no key specified\n", __func__
);
2413 /* for WPA[2], psk should be set */
2414 if ((wl
->group_cipher_method
== GELIC_WL_CIPHER_TKIP
) ||
2415 (wl
->group_cipher_method
== GELIC_WL_CIPHER_AES
)) {
2416 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET
,
2420 pr_debug("%s: AES/TKIP, but PSK not configured\n",
2427 ret
= schedule_delayed_work(&wl
->assoc_work
, 0);
2428 pr_debug("%s: start association work %d\n", __func__
, ret
);
2435 static int gelic_wl_open(struct net_device
*netdev
)
2437 struct gelic_card
*card
= netdev_card(netdev
);
2439 pr_debug("%s:->%p\n", __func__
, netdev
);
2441 gelic_card_up(card
);
2443 /* try to associate */
2444 gelic_wl_try_associate(netdev
);
2446 netif_start_queue(netdev
);
2448 pr_debug("%s:<-\n", __func__
);
2453 * reset state machine
2455 static int gelic_wl_reset_state(struct gelic_wl_info
*wl
)
2457 struct gelic_wl_scan_info
*target
;
2458 struct gelic_wl_scan_info
*tmp
;
2460 /* empty scan list */
2461 list_for_each_entry_safe(target
, tmp
, &wl
->network_list
, list
) {
2462 list_move_tail(&target
->list
, &wl
->network_free_list
);
2464 wl
->scan_stat
= GELIC_WL_SCAN_STAT_INIT
;
2466 /* clear configuration */
2467 wl
->auth_method
= GELIC_EURUS_AUTH_OPEN
;
2468 wl
->group_cipher_method
= GELIC_WL_CIPHER_NONE
;
2469 wl
->pairwise_cipher_method
= GELIC_WL_CIPHER_NONE
;
2470 wl
->wpa_level
= GELIC_WL_WPA_LEVEL_NONE
;
2472 wl
->key_enabled
= 0;
2473 wl
->current_key
= 0;
2475 wl
->psk_type
= GELIC_EURUS_WPA_PSK_PASSPHRASE
;
2479 memset(wl
->essid
, 0, sizeof(wl
->essid
));
2480 memset(wl
->bssid
, 0, sizeof(wl
->bssid
));
2481 memset(wl
->active_bssid
, 0, sizeof(wl
->active_bssid
));
2483 wl
->assoc_stat
= GELIC_WL_ASSOC_STAT_DISCONN
;
2485 memset(&wl
->iwstat
, 0, sizeof(wl
->iwstat
));
2486 /* all status bit clear */
2492 * Tell eurus to terminate association
2494 static void gelic_wl_disconnect(struct net_device
*netdev
)
2496 struct gelic_port
*port
= netdev_priv(netdev
);
2497 struct gelic_wl_info
*wl
= port_wl(port
);
2498 struct gelic_eurus_cmd
*cmd
;
2501 * If scann process is running on chip,
2502 * further requests will be rejected
2504 if (wl
->scan_stat
== GELIC_WL_SCAN_STAT_SCANNING
)
2505 wait_for_completion_timeout(&wl
->scan_done
, HZ
);
2507 cmd
= gelic_eurus_sync_cmd(wl
, GELIC_EURUS_CMD_DISASSOC
, NULL
, 0);
2509 gelic_wl_send_iwap_event(wl
, NULL
);
2512 static int gelic_wl_stop(struct net_device
*netdev
)
2514 struct gelic_port
*port
= netdev_priv(netdev
);
2515 struct gelic_wl_info
*wl
= port_wl(port
);
2516 struct gelic_card
*card
= netdev_card(netdev
);
2518 pr_debug("%s:<-\n", __func__
);
2521 * Cancel pending association work.
2522 * event work can run after netdev down
2524 cancel_delayed_work(&wl
->assoc_work
);
2526 if (wl
->assoc_stat
== GELIC_WL_ASSOC_STAT_ASSOCIATED
)
2527 gelic_wl_disconnect(netdev
);
2529 /* reset our state machine */
2530 gelic_wl_reset_state(wl
);
2532 netif_stop_queue(netdev
);
2534 gelic_card_down(card
);
2536 pr_debug("%s:->\n", __func__
);
2542 static const struct net_device_ops gelic_wl_netdevice_ops
= {
2543 .ndo_open
= gelic_wl_open
,
2544 .ndo_stop
= gelic_wl_stop
,
2545 .ndo_start_xmit
= gelic_net_xmit
,
2546 .ndo_set_rx_mode
= gelic_net_set_multi
,
2547 .ndo_tx_timeout
= gelic_net_tx_timeout
,
2548 .ndo_set_mac_address
= eth_mac_addr
,
2549 .ndo_validate_addr
= eth_validate_addr
,
2550 #ifdef CONFIG_NET_POLL_CONTROLLER
2551 .ndo_poll_controller
= gelic_net_poll_controller
,
2555 static const struct ethtool_ops gelic_wl_ethtool_ops
= {
2556 .get_drvinfo
= gelic_net_get_drvinfo
,
2557 .get_link
= gelic_wl_get_link
,
2560 static void gelic_wl_setup_netdev_ops(struct net_device
*netdev
)
2562 struct gelic_wl_info
*wl
;
2563 wl
= port_wl(netdev_priv(netdev
));
2565 netdev
->watchdog_timeo
= GELIC_NET_WATCHDOG_TIMEOUT
;
2567 netdev
->ethtool_ops
= &gelic_wl_ethtool_ops
;
2568 netdev
->netdev_ops
= &gelic_wl_netdevice_ops
;
2569 netdev
->wireless_data
= &wl
->wireless_data
;
2570 netdev
->wireless_handlers
= &gelic_wl_wext_handler_def
;
2574 * driver probe/remove
2576 int gelic_wl_driver_probe(struct gelic_card
*card
)
2579 struct net_device
*netdev
;
2581 pr_debug("%s:start\n", __func__
);
2583 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2585 if (!card
->vlan
[GELIC_PORT_WIRELESS
].tx
)
2588 /* alloc netdevice for wireless */
2589 netdev
= gelic_wl_alloc(card
);
2593 /* setup net_device structure */
2594 SET_NETDEV_DEV(netdev
, &card
->dev
->core
);
2595 gelic_wl_setup_netdev_ops(netdev
);
2597 /* setup some of net_device and register it */
2598 ret
= gelic_net_setup_netdev(netdev
, card
);
2601 card
->netdev
[GELIC_PORT_WIRELESS
] = netdev
;
2603 /* add enable wireless interrupt */
2604 card
->irq_mask
|= GELIC_CARD_WLAN_EVENT_RECEIVED
|
2605 GELIC_CARD_WLAN_COMMAND_COMPLETED
;
2606 /* to allow wireless commands while both interfaces are down */
2607 gelic_card_set_irq_mask(card
, GELIC_CARD_WLAN_EVENT_RECEIVED
|
2608 GELIC_CARD_WLAN_COMMAND_COMPLETED
);
2609 pr_debug("%s:end\n", __func__
);
2613 gelic_wl_free(port_wl(netdev_port(netdev
)));
2618 int gelic_wl_driver_remove(struct gelic_card
*card
)
2620 struct gelic_wl_info
*wl
;
2621 struct net_device
*netdev
;
2623 pr_debug("%s:start\n", __func__
);
2625 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2627 if (!card
->vlan
[GELIC_PORT_WIRELESS
].tx
)
2630 netdev
= card
->netdev
[GELIC_PORT_WIRELESS
];
2631 wl
= port_wl(netdev_priv(netdev
));
2633 /* if the interface was not up, but associated */
2634 if (wl
->assoc_stat
== GELIC_WL_ASSOC_STAT_ASSOCIATED
)
2635 gelic_wl_disconnect(netdev
);
2637 complete(&wl
->cmd_done_intr
);
2639 /* cancel all work queue */
2640 cancel_delayed_work(&wl
->assoc_work
);
2641 cancel_delayed_work(&wl
->event_work
);
2642 flush_workqueue(wl
->eurus_cmd_queue
);
2643 flush_workqueue(wl
->event_queue
);
2645 unregister_netdev(netdev
);
2647 /* disable wireless interrupt */
2648 pr_debug("%s: disable intr\n", __func__
);
2649 card
->irq_mask
&= ~(GELIC_CARD_WLAN_EVENT_RECEIVED
|
2650 GELIC_CARD_WLAN_COMMAND_COMPLETED
);
2651 /* free bss list, netdev*/
2653 pr_debug("%s:end\n", __func__
);