2 * PS3 gelic network driver.
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/etherdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/if_vlan.h>
31 #include <linux/tcp.h>
32 #include <linux/wireless.h>
33 #include <linux/ctype.h>
34 #include <linux/string.h>
35 #include <net/iw_handler.h>
36 #include <net/ieee80211.h>
38 #include <linux/dma-mapping.h>
39 #include <net/checksum.h>
40 #include <asm/firmware.h>
42 #include <asm/lv1call.h>
44 #include "ps3_gelic_net.h"
45 #include "ps3_gelic_wireless.h"
48 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
49 u8 *essid, size_t essid_len);
50 static int gelic_wl_try_associate(struct net_device *netdev);
56 /* 802.11b/g channel to freq in MHz */
57 static const int channel_freq[] = {
58 2412, 2417, 2422, 2427, 2432,
59 2437, 2442, 2447, 2452, 2457,
60 2462, 2467, 2472, 2484
62 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
65 static const int bitrate_list[] = {
79 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
82 * wpa2 support requires the hypervisor version 2.0 or later
84 static inline int wpa2_capable(void)
86 return (0 <= ps3_compare_firmware_version(2, 0, 0));
89 static inline int precise_ie(void)
91 return (0 <= ps3_compare_firmware_version(2, 2, 0));
94 * post_eurus_cmd helpers
96 struct eurus_cmd_arg_info {
97 int pre_arg; /* command requres arg1, arg2 at POST COMMAND */
98 int post_arg; /* command requires arg1, arg2 at GET_RESULT */
101 static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
102 [GELIC_EURUS_CMD_SET_COMMON_CFG] = { .pre_arg = 1},
103 [GELIC_EURUS_CMD_SET_WEP_CFG] = { .pre_arg = 1},
104 [GELIC_EURUS_CMD_SET_WPA_CFG] = { .pre_arg = 1},
105 [GELIC_EURUS_CMD_GET_COMMON_CFG] = { .post_arg = 1},
106 [GELIC_EURUS_CMD_GET_WEP_CFG] = { .post_arg = 1},
107 [GELIC_EURUS_CMD_GET_WPA_CFG] = { .post_arg = 1},
108 [GELIC_EURUS_CMD_GET_RSSI_CFG] = { .post_arg = 1},
109 [GELIC_EURUS_CMD_START_SCAN] = { .pre_arg = 1},
110 [GELIC_EURUS_CMD_GET_SCAN] = { .post_arg = 1},
114 static const char *cmdstr(enum gelic_eurus_command ix)
117 case GELIC_EURUS_CMD_ASSOC:
119 case GELIC_EURUS_CMD_DISASSOC:
121 case GELIC_EURUS_CMD_START_SCAN:
123 case GELIC_EURUS_CMD_GET_SCAN:
125 case GELIC_EURUS_CMD_SET_COMMON_CFG:
126 return "SET_COMMON_CFG";
127 case GELIC_EURUS_CMD_GET_COMMON_CFG:
128 return "GET_COMMON_CFG";
129 case GELIC_EURUS_CMD_SET_WEP_CFG:
130 return "SET_WEP_CFG";
131 case GELIC_EURUS_CMD_GET_WEP_CFG:
132 return "GET_WEP_CFG";
133 case GELIC_EURUS_CMD_SET_WPA_CFG:
134 return "SET_WPA_CFG";
135 case GELIC_EURUS_CMD_GET_WPA_CFG:
136 return "GET_WPA_CFG";
137 case GELIC_EURUS_CMD_GET_RSSI_CFG:
145 static inline const char *cmdstr(enum gelic_eurus_command ix)
151 /* synchronously do eurus commands */
152 static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
154 struct gelic_eurus_cmd *cmd;
155 struct gelic_card *card;
156 struct gelic_wl_info *wl;
160 pr_debug("%s: <-\n", __func__);
161 cmd = container_of(work, struct gelic_eurus_cmd, work);
162 BUG_ON(cmd_info[cmd->cmd].pre_arg &&
163 cmd_info[cmd->cmd].post_arg);
165 card = port_to_card(wl_port(wl));
167 if (cmd_info[cmd->cmd].pre_arg) {
168 arg1 = (cmd->buffer) ?
169 ps3_mm_phys_to_lpar(__pa(cmd->buffer)) :
171 arg2 = cmd->buf_size;
176 init_completion(&wl->cmd_done_intr);
177 pr_debug("%s: cmd='%s' start\n", __func__, cmdstr(cmd->cmd));
178 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
179 GELIC_LV1_POST_WLAN_CMD,
180 cmd->cmd, arg1, arg2,
181 &cmd->tag, &cmd->size);
183 complete(&cmd->done);
184 pr_info("%s: cmd issue failed\n", __func__);
188 wait_for_completion(&wl->cmd_done_intr);
190 if (cmd_info[cmd->cmd].post_arg) {
191 arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
192 arg2 = cmd->buf_size;
198 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
199 GELIC_LV1_GET_WLAN_CMD_RESULT,
200 cmd->tag, arg1, arg2,
201 &cmd->cmd_status, &cmd->size);
203 if (cmd->status || cmd->cmd_status) {
204 pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__,
205 cmd->tag, arg1, arg2);
206 pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
207 __func__, cmd->status, cmd->cmd_status, cmd->size);
210 complete(&cmd->done);
211 pr_debug("%s: cmd='%s' done\n", __func__, cmdstr(cmd->cmd));
214 static struct gelic_eurus_cmd *gelic_eurus_sync_cmd(struct gelic_wl_info *wl,
215 unsigned int eurus_cmd,
217 unsigned int buf_size)
219 struct gelic_eurus_cmd *cmd;
222 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
226 /* initialize members */
227 cmd->cmd = eurus_cmd;
228 cmd->buffer = buffer;
229 cmd->buf_size = buf_size;
231 INIT_WORK(&cmd->work, gelic_eurus_sync_cmd_worker);
232 init_completion(&cmd->done);
233 queue_work(wl->eurus_cmd_queue, &cmd->work);
235 /* wait for command completion */
236 wait_for_completion(&cmd->done);
241 static u32 gelic_wl_get_link(struct net_device *netdev)
243 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
246 pr_debug("%s: <-\n", __func__);
247 mutex_lock(&wl->assoc_stat_lock);
248 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
252 mutex_unlock(&wl->assoc_stat_lock);
253 pr_debug("%s: ->\n", __func__);
257 static void gelic_wl_send_iwap_event(struct gelic_wl_info *wl, u8 *bssid)
259 union iwreq_data data;
261 memset(&data, 0, sizeof(data));
263 memcpy(data.ap_addr.sa_data, bssid, ETH_ALEN);
264 data.ap_addr.sa_family = ARPHRD_ETHER;
265 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWAP,
270 * wireless extension handlers and helpers
274 static int gelic_wl_get_name(struct net_device *dev,
275 struct iw_request_info *info,
276 union iwreq_data *iwreq, char *extra)
278 strcpy(iwreq->name, "IEEE 802.11bg");
282 static void gelic_wl_get_ch_info(struct gelic_wl_info *wl)
284 struct gelic_card *card = port_to_card(wl_port(wl));
285 u64 ch_info_raw, tmp;
288 if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO, &wl->stat)) {
289 status = lv1_net_control(bus_id(card), dev_id(card),
290 GELIC_LV1_GET_CHANNEL, 0, 0, 0,
293 /* some fw versions may return error */
295 if (status != LV1_NO_ENTRY)
296 pr_info("%s: available ch unknown\n", __func__);
297 wl->ch_info = 0x07ff;/* 11 ch */
299 /* 16 bits of MSB has available channels */
300 wl->ch_info = ch_info_raw >> 48;
306 static int gelic_wl_get_range(struct net_device *netdev,
307 struct iw_request_info *info,
308 union iwreq_data *iwreq, char *extra)
310 struct iw_point *point = &iwreq->data;
311 struct iw_range *range = (struct iw_range *)extra;
312 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
315 pr_debug("%s: <-\n", __func__);
316 point->length = sizeof(struct iw_range);
317 memset(range, 0, sizeof(struct iw_range));
319 range->we_version_compiled = WIRELESS_EXT;
320 range->we_version_source = 22;
322 /* available channels and frequencies */
323 gelic_wl_get_ch_info(wl);
326 i < NUM_CHANNELS && chs < IW_MAX_FREQUENCIES; i++)
327 if (wl->ch_info & (1 << i)) {
328 range->freq[chs].i = i + 1;
329 range->freq[chs].m = channel_freq[i];
330 range->freq[chs].e = 6;
333 range->num_frequency = chs;
334 range->old_num_frequency = chs;
335 range->num_channels = chs;
336 range->old_num_channels = chs;
339 for (i = 0; i < NUM_BITRATES; i++)
340 range->bitrate[i] = bitrate_list[i];
341 range->num_bitrates = i;
344 range->max_qual.qual = 100; /* relative value */
345 range->max_qual.level = 100;
346 range->avg_qual.qual = 50;
347 range->avg_qual.level = 50;
348 range->sensitivity = 0;
350 /* Event capability */
351 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
352 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
353 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
355 /* encryption capability */
356 range->enc_capa = IW_ENC_CAPA_WPA |
357 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP |
358 IW_ENC_CAPA_4WAY_HANDSHAKE;
360 range->enc_capa |= IW_ENC_CAPA_WPA2;
361 range->encoding_size[0] = 5; /* 40bit WEP */
362 range->encoding_size[1] = 13; /* 104bit WEP */
363 range->encoding_size[2] = 32; /* WPA-PSK */
364 range->num_encoding_sizes = 3;
365 range->max_encoding_tokens = GELIC_WEP_KEYS;
367 /* scan capability */
368 range->scan_capa = IW_SCAN_CAPA_ESSID;
370 pr_debug("%s: ->\n", __func__);
375 /* SIOC{G,S}IWSCAN */
376 static int gelic_wl_set_scan(struct net_device *netdev,
377 struct iw_request_info *info,
378 union iwreq_data *wrqu, char *extra)
380 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
381 struct iw_scan_req *req;
383 size_t essid_len = 0;
385 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
386 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
387 req = (struct iw_scan_req*)extra;
389 essid_len = req->essid_len;
390 pr_debug("%s: ESSID scan =%s\n", __func__, essid);
392 return gelic_wl_start_scan(wl, 1, essid, essid_len);
396 static const u8 rsn_oui[OUI_LEN] = { 0x00, 0x0f, 0xac };
397 static const u8 wpa_oui[OUI_LEN] = { 0x00, 0x50, 0xf2 };
400 * synthesize WPA/RSN IE data
401 * See WiFi WPA specification and IEEE 802.11-2007 7.3.2.25
404 static size_t gelic_wl_synthesize_ie(u8 *buf,
405 struct gelic_eurus_scan_info *scan)
408 const u8 *oui_header;
413 pr_debug("%s: <- sec=%16x\n", __func__, scan->security);
414 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_MASK) {
415 case GELIC_EURUS_SCAN_SEC_WPA:
418 case GELIC_EURUS_SCAN_SEC_WPA2:
422 /* WEP or none. No IE returned */
426 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_WPA_MASK) {
427 case GELIC_EURUS_SCAN_SEC_WPA_TKIP:
430 case GELIC_EURUS_SCAN_SEC_WPA_AES:
436 pr_info("%s: no cipher info. defaulted to CCMP\n",
440 pr_info("%s: no cipher info. defaulted to TKIP\n",
446 oui_header = rsn_oui;
448 oui_header = wpa_oui;
452 *buf++ = MFIE_TYPE_RSN;
454 *buf++ = MFIE_TYPE_GENERIC;
456 /* length filed; set later */
459 /* wpa special header */
461 memcpy(buf, wpa_oui, OUI_LEN);
467 *buf++ = 0x01; /* version 1.0 */
471 memcpy(buf, oui_header, OUI_LEN);
475 *buf++ = 0x04; /* CCMP */
477 *buf++ = 0x02; /* TKIP */
479 /* pairwise key count always 1 */
483 /* pairwise key suit */
484 memcpy(buf, oui_header, OUI_LEN);
487 *buf++ = 0x04; /* CCMP */
489 *buf++ = 0x02; /* TKIP */
495 /* AKM suite is assumed as PSK*/
496 memcpy(buf, oui_header, OUI_LEN);
498 *buf++ = 0x02; /* PSK */
500 /* RSN capabilities is 0 */
504 /* set length field */
505 start[1] = (buf - start - 2);
507 pr_debug("%s: ->\n", __func__);
508 return (buf - start);
521 static void gelic_wl_parse_ie(u8 *data, size_t len,
522 struct ie_info *ie_info)
524 size_t data_left = len;
529 pr_debug("%s: data=%p len=%ld \n", __func__,
531 memset(ie_info, 0, sizeof(struct ie_info));
533 while (2 <= data_left) {
538 if (data_left < item_len)
542 case MFIE_TYPE_GENERIC:
543 if ((OUI_LEN + 1 <= item_len) &&
544 !memcmp(pos, wpa_oui, OUI_LEN) &&
545 pos[OUI_LEN] == 0x01) {
546 ie_info->wpa.data = pos - 2;
547 ie_info->wpa.len = item_len + 2;
551 ie_info->rsn.data = pos - 2;
552 /* length includes the header */
553 ie_info->rsn.len = item_len + 2;
556 pr_debug("%s: ignore %#x,%d\n", __func__,
561 data_left -= item_len;
563 pr_debug("%s: wpa=%p,%d wpa2=%p,%d\n", __func__,
564 ie_info->wpa.data, ie_info->wpa.len,
565 ie_info->rsn.data, ie_info->rsn.len);
570 * translate the scan informations from hypervisor to a
573 static char *gelic_wl_translate_scan(struct net_device *netdev,
576 struct gelic_wl_scan_info *network)
579 struct gelic_eurus_scan_info *scan = network->hwinfo;
582 unsigned int i, j, len;
583 u8 buf[MAX_WPA_IE_LEN];
585 pr_debug("%s: <-\n", __func__);
587 /* first entry should be AP's mac address */
589 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
590 memcpy(iwe.u.ap_addr.sa_data, &scan->bssid[2], ETH_ALEN);
591 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_ADDR_LEN);
594 iwe.cmd = SIOCGIWESSID;
595 iwe.u.data.flags = 1;
596 iwe.u.data.length = strnlen(scan->essid, 32);
597 ev = iwe_stream_add_point(ev, stop, &iwe, scan->essid);
600 iwe.cmd = SIOCGIWFREQ;
601 iwe.u.freq.m = be16_to_cpu(scan->channel);
602 iwe.u.freq.e = 0; /* table value in MHz */
604 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_FREQ_LEN);
607 iwe.cmd = SIOCGIWRATE;
608 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
609 /* to stuff multiple values in one event */
610 tmp = ev + IW_EV_LCP_LEN;
611 /* put them in ascendant order (older is first) */
614 pr_debug("%s: rates=%d rate=%d\n", __func__,
615 network->rate_len, network->rate_ext_len);
616 while (i < network->rate_len) {
617 if (j < network->rate_ext_len &&
618 ((scan->ext_rate[j] & 0x7f) < (scan->rate[i] & 0x7f)))
619 rate = scan->ext_rate[j++] & 0x7f;
621 rate = scan->rate[i++] & 0x7f;
622 iwe.u.bitrate.value = rate * 500000; /* 500kbps unit */
623 tmp = iwe_stream_add_value(ev, tmp, stop, &iwe,
626 while (j < network->rate_ext_len) {
627 iwe.u.bitrate.value = (scan->ext_rate[j++] & 0x7f) * 500000;
628 tmp = iwe_stream_add_value(ev, tmp, stop, &iwe,
631 /* Check if we added any rate */
632 if (IW_EV_LCP_LEN < (tmp - ev))
636 iwe.cmd = SIOCGIWENCODE;
637 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_PRIVACY)
638 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
640 iwe.u.data.flags = IW_ENCODE_DISABLED;
641 iwe.u.data.length = 0;
642 ev = iwe_stream_add_point(ev, stop, &iwe, scan->essid);
645 iwe.cmd = SIOCGIWMODE;
646 if (be16_to_cpu(scan->capability) &
647 (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
648 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_ESS)
649 iwe.u.mode = IW_MODE_MASTER;
651 iwe.u.mode = IW_MODE_ADHOC;
652 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_UINT_LEN);
657 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED |
658 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
659 iwe.u.qual.level = be16_to_cpu(scan->rssi);
660 iwe.u.qual.qual = be16_to_cpu(scan->rssi);
661 iwe.u.qual.noise = 0;
662 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_QUAL_LEN);
665 memset(&iwe, 0, sizeof(iwe));
666 if (be16_to_cpu(scan->size) <= sizeof(*scan)) {
667 /* If wpa[2] capable station, synthesize IE and put it */
668 len = gelic_wl_synthesize_ie(buf, scan);
671 iwe.u.data.length = len;
672 ev = iwe_stream_add_point(ev, stop, &iwe, buf);
675 /* this scan info has IE data */
676 struct ie_info ie_info;
679 data_len = be16_to_cpu(scan->size) - sizeof(*scan);
681 gelic_wl_parse_ie(scan->elements, data_len, &ie_info);
683 if (ie_info.wpa.len && (ie_info.wpa.len <= sizeof(buf))) {
684 memcpy(buf, ie_info.wpa.data, ie_info.wpa.len);
686 iwe.u.data.length = ie_info.wpa.len;
687 ev = iwe_stream_add_point(ev, stop, &iwe, buf);
690 if (ie_info.rsn.len && (ie_info.rsn.len <= sizeof(buf))) {
691 memset(&iwe, 0, sizeof(iwe));
692 memcpy(buf, ie_info.rsn.data, ie_info.rsn.len);
694 iwe.u.data.length = ie_info.rsn.len;
695 ev = iwe_stream_add_point(ev, stop, &iwe, buf);
699 pr_debug("%s: ->\n", __func__);
704 static int gelic_wl_get_scan(struct net_device *netdev,
705 struct iw_request_info *info,
706 union iwreq_data *wrqu, char *extra)
708 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
709 struct gelic_wl_scan_info *scan_info;
711 char *stop = ev + wrqu->data.length;
713 unsigned long this_time = jiffies;
715 pr_debug("%s: <-\n", __func__);
716 if (mutex_lock_interruptible(&wl->scan_lock))
719 switch (wl->scan_stat) {
720 case GELIC_WL_SCAN_STAT_SCANNING:
721 /* If a scan in progress, caller should call me again */
726 case GELIC_WL_SCAN_STAT_INIT:
727 /* last scan request failed or never issued */
731 case GELIC_WL_SCAN_STAT_GOT_LIST:
732 /* ok, use current list */
736 list_for_each_entry(scan_info, &wl->network_list, list) {
737 if (wl->scan_age == 0 ||
738 time_after(scan_info->last_scanned + wl->scan_age,
740 ev = gelic_wl_translate_scan(netdev, ev, stop,
743 pr_debug("%s:entry too old\n", __func__);
745 if (stop - ev <= IW_EV_ADDR_LEN) {
751 wrqu->data.length = ev - extra;
752 wrqu->data.flags = 0;
754 mutex_unlock(&wl->scan_lock);
755 pr_debug("%s: -> %d %d\n", __func__, ret, wrqu->data.length);
760 static void scan_list_dump(struct gelic_wl_info *wl)
762 struct gelic_wl_scan_info *scan_info;
764 DECLARE_MAC_BUF(mac);
767 list_for_each_entry(scan_info, &wl->network_list, list) {
768 pr_debug("%s: item %d\n", __func__, i++);
769 pr_debug("valid=%d eurusindex=%d last=%lx\n",
770 scan_info->valid, scan_info->eurus_index,
771 scan_info->last_scanned);
772 pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
773 scan_info->rate_len, scan_info->rate_ext_len,
774 scan_info->essid_len);
776 pr_debug("bssid=%s\n",
777 print_mac(mac, &scan_info->hwinfo->bssid[2]));
778 pr_debug("essid=%s\n", scan_info->hwinfo->essid);
783 static int gelic_wl_set_auth(struct net_device *netdev,
784 struct iw_request_info *info,
785 union iwreq_data *data, char *extra)
787 struct iw_param *param = &data->param;
788 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
789 unsigned long irqflag;
792 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
793 spin_lock_irqsave(&wl->lock, irqflag);
794 switch (param->flags & IW_AUTH_INDEX) {
795 case IW_AUTH_WPA_VERSION:
796 if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
797 pr_debug("%s: NO WPA selected\n", __func__);
798 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
799 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
800 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
802 if (param->value & IW_AUTH_WPA_VERSION_WPA) {
803 pr_debug("%s: WPA version 1 selected\n", __func__);
804 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
805 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
806 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
807 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
809 if (param->value & IW_AUTH_WPA_VERSION_WPA2) {
811 * As the hypervisor may not tell the cipher
812 * information of the AP if it is WPA2,
813 * you will not decide suitable cipher from
815 * You should have knowledge about the AP's
816 * cipher infomation in other method prior to
820 pr_info("%s: WPA2 may not work\n", __func__);
821 if (wpa2_capable()) {
822 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
823 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
824 wl->pairwise_cipher_method =
826 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
832 case IW_AUTH_CIPHER_PAIRWISE:
834 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
835 pr_debug("%s: WEP selected\n", __func__);
836 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
838 if (param->value & IW_AUTH_CIPHER_TKIP) {
839 pr_debug("%s: TKIP selected\n", __func__);
840 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
842 if (param->value & IW_AUTH_CIPHER_CCMP) {
843 pr_debug("%s: CCMP selected\n", __func__);
844 wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
846 if (param->value & IW_AUTH_CIPHER_NONE) {
847 pr_debug("%s: no auth selected\n", __func__);
848 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
851 case IW_AUTH_CIPHER_GROUP:
853 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
854 pr_debug("%s: WEP selected\n", __func__);
855 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
857 if (param->value & IW_AUTH_CIPHER_TKIP) {
858 pr_debug("%s: TKIP selected\n", __func__);
859 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
861 if (param->value & IW_AUTH_CIPHER_CCMP) {
862 pr_debug("%s: CCMP selected\n", __func__);
863 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
865 if (param->value & IW_AUTH_CIPHER_NONE) {
866 pr_debug("%s: no auth selected\n", __func__);
867 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
870 case IW_AUTH_80211_AUTH_ALG:
871 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
872 pr_debug("%s: shared key specified\n", __func__);
873 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
874 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
875 pr_debug("%s: open system specified\n", __func__);
876 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
881 case IW_AUTH_WPA_ENABLED:
883 pr_debug("%s: WPA enabled\n", __func__);
884 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
886 pr_debug("%s: WPA disabled\n", __func__);
887 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
891 case IW_AUTH_KEY_MGMT:
892 if (param->value & IW_AUTH_KEY_MGMT_PSK)
894 /* intentionally fall through */
901 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
903 spin_unlock_irqrestore(&wl->lock, irqflag);
904 pr_debug("%s: -> %d\n", __func__, ret);
908 static int gelic_wl_get_auth(struct net_device *netdev,
909 struct iw_request_info *info,
910 union iwreq_data *iwreq, char *extra)
912 struct iw_param *param = &iwreq->param;
913 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
914 unsigned long irqflag;
917 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
918 spin_lock_irqsave(&wl->lock, irqflag);
919 switch (param->flags & IW_AUTH_INDEX) {
920 case IW_AUTH_WPA_VERSION:
921 switch (wl->wpa_level) {
922 case GELIC_WL_WPA_LEVEL_WPA:
923 param->value |= IW_AUTH_WPA_VERSION_WPA;
925 case GELIC_WL_WPA_LEVEL_WPA2:
926 param->value |= IW_AUTH_WPA_VERSION_WPA2;
929 param->value |= IW_AUTH_WPA_VERSION_DISABLED;
933 case IW_AUTH_80211_AUTH_ALG:
934 if (wl->auth_method == GELIC_EURUS_AUTH_SHARED)
935 param->value = IW_AUTH_ALG_SHARED_KEY;
936 else if (wl->auth_method == GELIC_EURUS_AUTH_OPEN)
937 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
940 case IW_AUTH_WPA_ENABLED:
941 switch (wl->wpa_level) {
942 case GELIC_WL_WPA_LEVEL_WPA:
943 case GELIC_WL_WPA_LEVEL_WPA2:
955 spin_unlock_irqrestore(&wl->lock, irqflag);
956 pr_debug("%s: -> %d\n", __func__, ret);
960 /* SIOC{S,G}IWESSID */
961 static int gelic_wl_set_essid(struct net_device *netdev,
962 struct iw_request_info *info,
963 union iwreq_data *data, char *extra)
965 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
966 unsigned long irqflag;
968 pr_debug("%s: <- l=%d f=%d\n", __func__,
969 data->essid.length, data->essid.flags);
970 if (IW_ESSID_MAX_SIZE < data->essid.length)
973 spin_lock_irqsave(&wl->lock, irqflag);
974 if (data->essid.flags) {
975 wl->essid_len = data->essid.length;
976 memcpy(wl->essid, extra, wl->essid_len);
977 pr_debug("%s: essid = '%s'\n", __func__, extra);
978 set_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
980 pr_debug("%s: ESSID any \n", __func__);
981 clear_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
983 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
984 spin_unlock_irqrestore(&wl->lock, irqflag);
987 gelic_wl_try_associate(netdev); /* FIXME */
988 pr_debug("%s: -> \n", __func__);
992 static int gelic_wl_get_essid(struct net_device *netdev,
993 struct iw_request_info *info,
994 union iwreq_data *data, char *extra)
996 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
997 unsigned long irqflag;
999 pr_debug("%s: <- \n", __func__);
1000 mutex_lock(&wl->assoc_stat_lock);
1001 spin_lock_irqsave(&wl->lock, irqflag);
1002 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat) ||
1003 wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1004 memcpy(extra, wl->essid, wl->essid_len);
1005 data->essid.length = wl->essid_len;
1006 data->essid.flags = 1;
1008 data->essid.flags = 0;
1010 mutex_unlock(&wl->assoc_stat_lock);
1011 spin_unlock_irqrestore(&wl->lock, irqflag);
1012 pr_debug("%s: -> len=%d \n", __func__, data->essid.length);
1017 /* SIO{S,G}IWENCODE */
1018 static int gelic_wl_set_encode(struct net_device *netdev,
1019 struct iw_request_info *info,
1020 union iwreq_data *data, char *extra)
1022 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1023 struct iw_point *enc = &data->encoding;
1025 unsigned int irqflag;
1026 int key_index, index_specified;
1029 pr_debug("%s: <- \n", __func__);
1030 flags = enc->flags & IW_ENCODE_FLAGS;
1031 key_index = enc->flags & IW_ENCODE_INDEX;
1033 pr_debug("%s: key_index = %d\n", __func__, key_index);
1034 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1035 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1037 if (GELIC_WEP_KEYS < key_index)
1040 spin_lock_irqsave(&wl->lock, irqflag);
1042 index_specified = 1;
1045 index_specified = 0;
1046 key_index = wl->current_key;
1049 if (flags & IW_ENCODE_NOKEY) {
1050 /* if just IW_ENCODE_NOKEY, change current key index */
1051 if (!flags && index_specified) {
1052 wl->current_key = key_index;
1056 if (flags & IW_ENCODE_DISABLED) {
1057 if (!index_specified) {
1058 /* disable encryption */
1059 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1060 wl->pairwise_cipher_method =
1061 GELIC_WL_CIPHER_NONE;
1062 /* invalidate all key */
1063 wl->key_enabled = 0;
1065 clear_bit(key_index, &wl->key_enabled);
1068 if (flags & IW_ENCODE_OPEN)
1069 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1070 if (flags & IW_ENCODE_RESTRICTED) {
1071 pr_info("%s: shared key mode enabled\n", __func__);
1072 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1075 if (IW_ENCODING_TOKEN_MAX < enc->length) {
1079 wl->key_len[key_index] = enc->length;
1080 memcpy(wl->key[key_index], extra, enc->length);
1081 set_bit(key_index, &wl->key_enabled);
1082 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
1083 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
1085 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1087 spin_unlock_irqrestore(&wl->lock, irqflag);
1088 pr_debug("%s: -> \n", __func__);
1092 static int gelic_wl_get_encode(struct net_device *netdev,
1093 struct iw_request_info *info,
1094 union iwreq_data *data, char *extra)
1096 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1097 struct iw_point *enc = &data->encoding;
1098 unsigned int irqflag;
1099 unsigned int key_index, index_specified;
1102 pr_debug("%s: <- \n", __func__);
1103 key_index = enc->flags & IW_ENCODE_INDEX;
1104 pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
1105 enc->flags, enc->pointer, enc->length, extra);
1106 if (GELIC_WEP_KEYS < key_index)
1109 spin_lock_irqsave(&wl->lock, irqflag);
1111 index_specified = 1;
1114 index_specified = 0;
1115 key_index = wl->current_key;
1118 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1119 switch (wl->auth_method) {
1120 case GELIC_EURUS_AUTH_OPEN:
1121 enc->flags = IW_ENCODE_OPEN;
1123 case GELIC_EURUS_AUTH_SHARED:
1124 enc->flags = IW_ENCODE_RESTRICTED;
1128 enc->flags = IW_ENCODE_DISABLED;
1130 if (test_bit(key_index, &wl->key_enabled)) {
1131 if (enc->length < wl->key_len[key_index]) {
1135 enc->length = wl->key_len[key_index];
1136 memcpy(extra, wl->key[key_index], wl->key_len[key_index]);
1139 enc->flags |= IW_ENCODE_NOKEY;
1141 enc->flags |= key_index + 1;
1142 pr_debug("%s: -> flag=%x len=%d\n", __func__,
1143 enc->flags, enc->length);
1146 spin_unlock_irqrestore(&wl->lock, irqflag);
1151 static int gelic_wl_set_ap(struct net_device *netdev,
1152 struct iw_request_info *info,
1153 union iwreq_data *data, char *extra)
1155 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1156 unsigned long irqflag;
1158 pr_debug("%s: <-\n", __func__);
1159 if (data->ap_addr.sa_family != ARPHRD_ETHER)
1162 spin_lock_irqsave(&wl->lock, irqflag);
1163 if (is_valid_ether_addr(data->ap_addr.sa_data)) {
1164 memcpy(wl->bssid, data->ap_addr.sa_data,
1166 set_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1167 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1168 pr_debug("%s: bss=%02x:%02x:%02x:%02x:%02x:%02x\n",
1170 wl->bssid[0], wl->bssid[1],
1171 wl->bssid[2], wl->bssid[3],
1172 wl->bssid[4], wl->bssid[5]);
1174 pr_debug("%s: clear bssid\n", __func__);
1175 clear_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1176 memset(wl->bssid, 0, ETH_ALEN);
1178 spin_unlock_irqrestore(&wl->lock, irqflag);
1179 pr_debug("%s: ->\n", __func__);
1183 static int gelic_wl_get_ap(struct net_device *netdev,
1184 struct iw_request_info *info,
1185 union iwreq_data *data, char *extra)
1187 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1188 unsigned long irqflag;
1190 pr_debug("%s: <-\n", __func__);
1191 mutex_lock(&wl->assoc_stat_lock);
1192 spin_lock_irqsave(&wl->lock, irqflag);
1193 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1194 data->ap_addr.sa_family = ARPHRD_ETHER;
1195 memcpy(data->ap_addr.sa_data, wl->active_bssid,
1198 memset(data->ap_addr.sa_data, 0, ETH_ALEN);
1200 spin_unlock_irqrestore(&wl->lock, irqflag);
1201 mutex_unlock(&wl->assoc_stat_lock);
1202 pr_debug("%s: ->\n", __func__);
1206 /* SIOC{S,G}IWENCODEEXT */
1207 static int gelic_wl_set_encodeext(struct net_device *netdev,
1208 struct iw_request_info *info,
1209 union iwreq_data *data, char *extra)
1211 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1212 struct iw_point *enc = &data->encoding;
1213 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1216 unsigned int irqflag;
1220 pr_debug("%s: <- \n", __func__);
1221 flags = enc->flags & IW_ENCODE_FLAGS;
1223 key_index = enc->flags & IW_ENCODE_INDEX;
1225 pr_debug("%s: key_index = %d\n", __func__, key_index);
1226 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1227 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1228 pr_debug("%s: ext_flag=%x\n", __func__, ext->ext_flags);
1229 pr_debug("%s: ext_key_len=%x\n", __func__, ext->key_len);
1231 if (GELIC_WEP_KEYS < key_index)
1234 spin_lock_irqsave(&wl->lock, irqflag);
1238 key_index = wl->current_key;
1240 if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
1241 /* reques to change default key index */
1242 pr_debug("%s: request to change default key to %d\n",
1243 __func__, key_index);
1244 wl->current_key = key_index;
1248 if (alg == IW_ENCODE_ALG_NONE || (flags & IW_ENCODE_DISABLED)) {
1249 pr_debug("%s: alg disabled\n", __func__);
1250 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
1251 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1252 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
1253 wl->auth_method = GELIC_EURUS_AUTH_OPEN; /* should be open */
1254 } else if (alg == IW_ENCODE_ALG_WEP) {
1255 pr_debug("%s: WEP requested\n", __func__);
1256 if (flags & IW_ENCODE_OPEN) {
1257 pr_debug("%s: open key mode\n", __func__);
1258 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1260 if (flags & IW_ENCODE_RESTRICTED) {
1261 pr_debug("%s: shared key mode\n", __func__);
1262 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1264 if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
1265 pr_info("%s: key is too long %d\n", __func__,
1270 /* OK, update the key */
1271 wl->key_len[key_index] = ext->key_len;
1272 memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
1273 memcpy(wl->key[key_index], ext->key, ext->key_len);
1274 set_bit(key_index, &wl->key_enabled);
1275 /* remember wep info changed */
1276 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1277 } else if (alg == IW_ENCODE_ALG_PMK) {
1278 if (ext->key_len != WPA_PSK_LEN) {
1279 pr_err("%s: PSK length wrong %d\n", __func__,
1284 memset(wl->psk, 0, sizeof(wl->psk));
1285 memcpy(wl->psk, ext->key, ext->key_len);
1286 wl->psk_len = ext->key_len;
1287 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1288 /* remember PSK configured */
1289 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1292 spin_unlock_irqrestore(&wl->lock, irqflag);
1293 pr_debug("%s: -> \n", __func__);
1297 static int gelic_wl_get_encodeext(struct net_device *netdev,
1298 struct iw_request_info *info,
1299 union iwreq_data *data, char *extra)
1301 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1302 struct iw_point *enc = &data->encoding;
1303 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1304 unsigned int irqflag;
1309 pr_debug("%s: <- \n", __func__);
1311 max_key_len = enc->length - sizeof(struct iw_encode_ext);
1312 if (max_key_len < 0)
1314 key_index = enc->flags & IW_ENCODE_INDEX;
1316 pr_debug("%s: key_index = %d\n", __func__, key_index);
1317 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1318 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1320 if (GELIC_WEP_KEYS < key_index)
1323 spin_lock_irqsave(&wl->lock, irqflag);
1327 key_index = wl->current_key;
1329 memset(ext, 0, sizeof(struct iw_encode_ext));
1330 switch (wl->group_cipher_method) {
1331 case GELIC_WL_CIPHER_WEP:
1332 ext->alg = IW_ENCODE_ALG_WEP;
1333 enc->flags |= IW_ENCODE_ENABLED;
1335 case GELIC_WL_CIPHER_TKIP:
1336 ext->alg = IW_ENCODE_ALG_TKIP;
1337 enc->flags |= IW_ENCODE_ENABLED;
1339 case GELIC_WL_CIPHER_AES:
1340 ext->alg = IW_ENCODE_ALG_CCMP;
1341 enc->flags |= IW_ENCODE_ENABLED;
1343 case GELIC_WL_CIPHER_NONE:
1345 ext->alg = IW_ENCODE_ALG_NONE;
1346 enc->flags |= IW_ENCODE_NOKEY;
1350 if (!(enc->flags & IW_ENCODE_NOKEY)) {
1351 if (max_key_len < wl->key_len[key_index]) {
1355 if (test_bit(key_index, &wl->key_enabled))
1356 memcpy(ext->key, wl->key[key_index],
1357 wl->key_len[key_index]);
1359 pr_debug("%s: disabled key requested ix=%d\n",
1360 __func__, key_index);
1363 spin_unlock_irqrestore(&wl->lock, irqflag);
1364 pr_debug("%s: -> \n", __func__);
1367 /* SIOC{S,G}IWMODE */
1368 static int gelic_wl_set_mode(struct net_device *netdev,
1369 struct iw_request_info *info,
1370 union iwreq_data *data, char *extra)
1372 __u32 mode = data->mode;
1375 pr_debug("%s: <- \n", __func__);
1376 if (mode == IW_MODE_INFRA)
1380 pr_debug("%s: -> %d\n", __func__, ret);
1384 static int gelic_wl_get_mode(struct net_device *netdev,
1385 struct iw_request_info *info,
1386 union iwreq_data *data, char *extra)
1388 __u32 *mode = &data->mode;
1389 pr_debug("%s: <- \n", __func__);
1390 *mode = IW_MODE_INFRA;
1391 pr_debug("%s: ->\n", __func__);
1395 #ifdef CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE
1396 /* SIOCIWFIRSTPRIV */
1397 static int hex2bin(u8 *str, u8 *bin, unsigned int len)
1400 static unsigned char *hex = "0123456789ABCDEF";
1401 unsigned char *p, *q;
1404 if (len != WPA_PSK_LEN * 2)
1407 for (i = 0; i < WPA_PSK_LEN * 2; i += 2) {
1408 p = strchr(hex, toupper(str[i]));
1409 q = strchr(hex, toupper(str[i + 1]));
1411 pr_info("%s: unconvertible PSK digit=%d\n",
1415 tmp = ((p - hex) << 4) + (q - hex);
1421 static int gelic_wl_priv_set_psk(struct net_device *net_dev,
1422 struct iw_request_info *info,
1423 union iwreq_data *data, char *extra)
1425 struct gelic_wl_info *wl = port_wl(netdev_priv(net_dev));
1427 unsigned int irqflag;
1430 pr_debug("%s:<- len=%d\n", __func__, data->data.length);
1431 len = data->data.length - 1;
1435 spin_lock_irqsave(&wl->lock, irqflag);
1436 if (extra[0] == '"' && extra[len - 1] == '"') {
1437 pr_debug("%s: passphrase mode\n", __func__);
1439 if (GELIC_WL_EURUS_PSK_MAX_LEN < (len - 2)) {
1440 pr_info("%s: passphrase too long\n", __func__);
1444 memset(wl->psk, 0, sizeof(wl->psk));
1445 wl->psk_len = len - 2;
1446 memcpy(wl->psk, &(extra[1]), wl->psk_len);
1447 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
1449 ret = hex2bin(extra, wl->psk, len);
1452 wl->psk_len = WPA_PSK_LEN;
1453 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1455 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1457 spin_unlock_irqrestore(&wl->lock, irqflag);
1458 pr_debug("%s:->\n", __func__);
1462 static int gelic_wl_priv_get_psk(struct net_device *net_dev,
1463 struct iw_request_info *info,
1464 union iwreq_data *data, char *extra)
1466 struct gelic_wl_info *wl = port_wl(netdev_priv(net_dev));
1468 unsigned int irqflag;
1471 pr_debug("%s:<-\n", __func__);
1472 if (!capable(CAP_NET_ADMIN))
1475 spin_lock_irqsave(&wl->lock, irqflag);
1477 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat)) {
1478 if (wl->psk_type == GELIC_EURUS_WPA_PSK_BIN) {
1479 for (i = 0; i < wl->psk_len; i++) {
1480 sprintf(p, "%02xu", wl->psk[i]);
1484 data->data.length = wl->psk_len * 2;
1487 memcpy(p, wl->psk, wl->psk_len);
1491 data->data.length = wl->psk_len + 2;
1495 data->data.length = 0;
1496 spin_unlock_irqrestore(&wl->lock, irqflag);
1497 pr_debug("%s:-> %d\n", __func__, data->data.length);
1503 static int gelic_wl_get_nick(struct net_device *net_dev,
1504 struct iw_request_info *info,
1505 union iwreq_data *data, char *extra)
1507 strcpy(extra, "gelic_wl");
1508 data->data.length = strlen(extra);
1509 data->data.flags = 1;
1516 static struct iw_statistics *gelic_wl_get_wireless_stats(
1517 struct net_device *netdev)
1520 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1521 struct gelic_eurus_cmd *cmd;
1522 struct iw_statistics *is;
1523 struct gelic_eurus_rssi_info *rssi;
1526 pr_debug("%s: <-\n", __func__);
1528 buf = (void *)__get_free_page(GFP_KERNEL);
1533 memset(is, 0, sizeof(*is));
1534 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
1535 buf, sizeof(*rssi));
1536 if (cmd && !cmd->status && !cmd->cmd_status) {
1538 is->qual.level = be16_to_cpu(rssi->rssi);
1539 is->qual.updated = IW_QUAL_LEVEL_UPDATED |
1540 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
1542 /* not associated */
1543 is->qual.updated = IW_QUAL_ALL_INVALID;
1546 free_page((unsigned long)buf);
1547 pr_debug("%s: ->\n", __func__);
1554 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
1555 u8 *essid, size_t essid_len)
1557 struct gelic_eurus_cmd *cmd;
1562 pr_debug("%s: <- always=%d\n", __func__, always_scan);
1563 if (mutex_lock_interruptible(&wl->scan_lock))
1564 return -ERESTARTSYS;
1567 * If already a scan in progress, do not trigger more
1569 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING) {
1570 pr_debug("%s: scanning now\n", __func__);
1574 init_completion(&wl->scan_done);
1576 * If we have already a bss list, don't try to get new
1578 if (!always_scan && wl->scan_stat == GELIC_WL_SCAN_STAT_GOT_LIST) {
1579 pr_debug("%s: already has the list\n", __func__);
1580 complete(&wl->scan_done);
1585 if (essid_len && essid) {
1586 buf = (void *)__get_free_page(GFP_KERNEL);
1591 len = IW_ESSID_MAX_SIZE; /* hypervisor always requires 32 */
1592 memset(buf, 0, len);
1593 memcpy(buf, essid, essid_len);
1594 pr_debug("%s: essid scan='%s'\n", __func__, (char *)buf);
1599 * issue start scan request
1601 wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
1602 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
1604 if (!cmd || cmd->status || cmd->cmd_status) {
1605 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1606 complete(&wl->scan_done);
1612 free_page((unsigned long)buf);
1613 mutex_unlock(&wl->scan_lock);
1614 pr_debug("%s: ->\n", __func__);
1619 * retrieve scan result from the chip (hypervisor)
1620 * this function is invoked by schedule work.
1622 static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
1624 struct gelic_eurus_cmd *cmd = NULL;
1625 struct gelic_wl_scan_info *target, *tmp;
1626 struct gelic_wl_scan_info *oldest = NULL;
1627 struct gelic_eurus_scan_info *scan_info;
1628 unsigned int scan_info_size;
1629 union iwreq_data data;
1630 unsigned long this_time = jiffies;
1631 unsigned int data_len, i, found, r;
1633 DECLARE_MAC_BUF(mac);
1635 pr_debug("%s:start\n", __func__);
1636 mutex_lock(&wl->scan_lock);
1638 buf = (void *)__get_free_page(GFP_KERNEL);
1640 pr_info("%s: scan buffer alloc failed\n", __func__);
1644 if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
1646 * stop() may be called while scanning, ignore result
1648 pr_debug("%s: scan complete when stat != scanning(%d)\n",
1649 __func__, wl->scan_stat);
1653 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
1655 if (!cmd || cmd->status || cmd->cmd_status) {
1656 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1657 pr_info("%s:cmd failed\n", __func__);
1661 data_len = cmd->size;
1662 pr_debug("%s: data_len = %d\n", __func__, data_len);
1665 /* OK, bss list retrieved */
1666 wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST;
1668 /* mark all entries are old */
1669 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
1671 /* expire too old entries */
1672 if (time_before(target->last_scanned + wl->scan_age,
1674 kfree(target->hwinfo);
1675 target->hwinfo = NULL;
1676 list_move_tail(&target->list, &wl->network_free_list);
1680 /* put them in the newtork_list */
1681 for (i = 0, scan_info_size = 0, scan_info = buf;
1682 scan_info_size < data_len;
1683 i++, scan_info_size += be16_to_cpu(scan_info->size),
1684 scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
1685 pr_debug("%s:size=%d bssid=%s scan_info=%p\n", __func__,
1686 be16_to_cpu(scan_info->size),
1687 print_mac(mac, &scan_info->bssid[2]), scan_info);
1690 * The wireless firmware may return invalid channel 0 and/or
1691 * invalid rate if the AP emits zero length SSID ie. As this
1692 * scan information is useless, ignore it
1694 if (!be16_to_cpu(scan_info->channel) || !scan_info->rate[0]) {
1695 pr_debug("%s: invalid scan info\n", __func__);
1701 list_for_each_entry(target, &wl->network_list, list) {
1702 if (!compare_ether_addr(&target->hwinfo->bssid[2],
1703 &scan_info->bssid[2])) {
1705 pr_debug("%s: same BBS found scanned list\n",
1710 (target->last_scanned < oldest->last_scanned))
1715 /* not found in the list */
1716 if (list_empty(&wl->network_free_list)) {
1720 target = list_entry(wl->network_free_list.next,
1721 struct gelic_wl_scan_info,
1726 /* update the item */
1727 target->last_scanned = this_time;
1729 target->eurus_index = i;
1730 kfree(target->hwinfo);
1731 target->hwinfo = kzalloc(be16_to_cpu(scan_info->size),
1733 if (!target->hwinfo) {
1734 pr_info("%s: kzalloc failed\n", __func__);
1737 /* copy hw scan info */
1738 memcpy(target->hwinfo, scan_info, scan_info->size);
1739 target->essid_len = strnlen(scan_info->essid,
1740 sizeof(scan_info->essid));
1741 target->rate_len = 0;
1742 for (r = 0; r < MAX_RATES_LENGTH; r++)
1743 if (scan_info->rate[r])
1745 if (8 < target->rate_len)
1746 pr_info("%s: AP returns %d rates\n", __func__,
1748 target->rate_ext_len = 0;
1749 for (r = 0; r < MAX_RATES_EX_LENGTH; r++)
1750 if (scan_info->ext_rate[r])
1751 target->rate_ext_len++;
1752 list_move_tail(&target->list, &wl->network_list);
1754 memset(&data, 0, sizeof(data));
1755 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
1758 free_page((unsigned long)buf);
1759 complete(&wl->scan_done);
1760 mutex_unlock(&wl->scan_lock);
1761 pr_debug("%s:end\n", __func__);
1765 * Select an appropriate bss from current scan list regarding
1766 * current settings from userspace.
1767 * The caller must hold wl->scan_lock,
1768 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1770 static void update_best(struct gelic_wl_scan_info **best,
1771 struct gelic_wl_scan_info *candid,
1775 if (*best_weight < ++(*weight)) {
1776 *best_weight = *weight;
1782 struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
1784 struct gelic_wl_scan_info *scan_info;
1785 struct gelic_wl_scan_info *best_bss;
1786 int weight, best_weight;
1788 DECLARE_MAC_BUF(mac);
1790 pr_debug("%s: <-\n", __func__);
1795 list_for_each_entry(scan_info, &wl->network_list, list) {
1796 pr_debug("%s: station %p\n", __func__, scan_info);
1798 if (!scan_info->valid) {
1799 pr_debug("%s: station invalid\n", __func__);
1803 /* If bss specified, check it only */
1804 if (test_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat)) {
1805 if (!compare_ether_addr(&scan_info->hwinfo->bssid[2],
1807 best_bss = scan_info;
1808 pr_debug("%s: bssid matched\n", __func__);
1811 pr_debug("%s: bssid unmached\n", __func__);
1819 security = be16_to_cpu(scan_info->hwinfo->security) &
1820 GELIC_EURUS_SCAN_SEC_MASK;
1821 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1822 if (security == GELIC_EURUS_SCAN_SEC_WPA2)
1823 update_best(&best_bss, scan_info,
1824 &best_weight, &weight);
1827 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA) {
1828 if (security == GELIC_EURUS_SCAN_SEC_WPA)
1829 update_best(&best_bss, scan_info,
1830 &best_weight, &weight);
1833 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_NONE &&
1834 wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1835 if (security == GELIC_EURUS_SCAN_SEC_WEP)
1836 update_best(&best_bss, scan_info,
1837 &best_weight, &weight);
1842 /* If ESSID is set, check it */
1843 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
1844 if ((scan_info->essid_len == wl->essid_len) &&
1846 scan_info->hwinfo->essid,
1847 scan_info->essid_len))
1848 update_best(&best_bss, scan_info,
1849 &best_weight, &weight);
1856 pr_debug("%s: -> bss=%p\n", __func__, best_bss);
1858 pr_debug("%s:addr=%s\n", __func__,
1859 print_mac(mac, &best_bss->hwinfo->bssid[2]));
1866 * Setup WEP configuration to the chip
1867 * The caller must hold wl->scan_lock,
1868 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1870 static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
1873 struct gelic_eurus_wep_cfg *wep;
1874 struct gelic_eurus_cmd *cmd;
1879 pr_debug("%s: <-\n", __func__);
1880 /* we can assume no one should uses the buffer */
1881 wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
1885 memset(wep, 0, sizeof(*wep));
1887 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1888 pr_debug("%s: WEP mode\n", __func__);
1889 for (i = 0; i < GELIC_WEP_KEYS; i++) {
1890 if (!test_bit(i, &wl->key_enabled))
1893 pr_debug("%s: key#%d enabled\n", __func__, i);
1895 if (wl->key_len[i] == 13)
1897 else if (wl->key_len[i] != 5) {
1898 pr_info("%s: wrong wep key[%d]=%d\n",
1899 __func__, i, wl->key_len[i]);
1903 memcpy(wep->key[i], wl->key[i], wl->key_len[i]);
1907 pr_info("%s: all wep key disabled\n", __func__);
1913 pr_debug("%s: 104bit key\n", __func__);
1914 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT);
1916 pr_debug("%s: 40bit key\n", __func__);
1917 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT);
1920 pr_debug("%s: NO encryption\n", __func__);
1921 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE);
1924 /* issue wep setup */
1925 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WEP_CFG,
1929 else if (cmd->status || cmd->cmd_status)
1934 free_page((unsigned long)wep);
1935 pr_debug("%s: ->\n", __func__);
1940 static const char *wpasecstr(enum gelic_eurus_wpa_security sec)
1943 case GELIC_EURUS_WPA_SEC_NONE:
1946 case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP:
1947 return "WPA_TKIP_TKIP";
1949 case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES:
1950 return "WPA_TKIP_AES";
1952 case GELIC_EURUS_WPA_SEC_WPA_AES_AES:
1953 return "WPA_AES_AES";
1955 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP:
1956 return "WPA2_TKIP_TKIP";
1958 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES:
1959 return "WPA2_TKIP_AES";
1961 case GELIC_EURUS_WPA_SEC_WPA2_AES_AES:
1962 return "WPA2_AES_AES";
1969 static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
1971 struct gelic_eurus_wpa_cfg *wpa;
1972 struct gelic_eurus_cmd *cmd;
1976 pr_debug("%s: <-\n", __func__);
1977 /* we can assume no one should uses the buffer */
1978 wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
1982 memset(wpa, 0, sizeof(*wpa));
1984 if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
1985 pr_info("%s: PSK not configured yet\n", __func__);
1988 memcpy(wpa->psk, wl->psk, wl->psk_len);
1990 /* set security level */
1991 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1992 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1993 security = GELIC_EURUS_WPA_SEC_WPA2_AES_AES;
1995 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1997 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES;
1999 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP;
2002 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
2003 security = GELIC_EURUS_WPA_SEC_WPA_AES_AES;
2005 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
2007 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_AES;
2009 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP;
2012 wpa->security = cpu_to_be16(security);
2015 wpa->psk_type = cpu_to_be16(wl->psk_type);
2017 pr_debug("%s: sec=%s psktype=%s\nn", __func__,
2018 wpasecstr(wpa->security),
2019 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
2020 "BIN" : "passphrase");
2023 * don't enable here if you plan to submit
2024 * the debug log because this dumps your precious
2027 pr_debug("%s: psk=%s\n",
2028 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
2029 (char *)"N/A" : (char *)wpa->psk);
2032 /* issue wpa setup */
2033 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WPA_CFG,
2037 else if (cmd->status || cmd->cmd_status)
2040 free_page((unsigned long)wpa);
2041 pr_debug("%s: --> %d\n", __func__, ret);
2046 * Start association. caller must hold assoc_stat_lock
2048 static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
2049 struct gelic_wl_scan_info *bss)
2051 struct gelic_eurus_cmd *cmd;
2052 struct gelic_eurus_common_cfg *common;
2056 pr_debug("%s: <-\n", __func__);
2058 /* do common config */
2059 common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
2063 memset(common, 0, sizeof(*common));
2064 common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
2065 common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
2067 common->scan_index = cpu_to_be16(bss->eurus_index);
2068 switch (wl->auth_method) {
2069 case GELIC_EURUS_AUTH_OPEN:
2070 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_OPEN);
2072 case GELIC_EURUS_AUTH_SHARED:
2073 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_SHARED);
2080 pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
2081 be16_to_cpu(common->scan_index),
2082 be16_to_cpu(common->bss_type),
2083 be16_to_cpu(common->auth_method));
2085 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_COMMON_CFG,
2086 common, sizeof(*common));
2087 if (!cmd || cmd->status || cmd->cmd_status) {
2095 switch (wl->wpa_level) {
2096 case GELIC_WL_WPA_LEVEL_NONE:
2097 /* If WEP or no security, setup WEP config */
2098 ret = gelic_wl_do_wep_setup(wl);
2100 case GELIC_WL_WPA_LEVEL_WPA:
2101 case GELIC_WL_WPA_LEVEL_WPA2:
2102 ret = gelic_wl_do_wpa_setup(wl);
2107 pr_debug("%s: WEP/WPA setup failed %d\n", __func__,
2111 /* start association */
2112 init_completion(&wl->assoc_done);
2113 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATING;
2114 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_ASSOC,
2116 if (!cmd || cmd->status || cmd->cmd_status) {
2117 pr_debug("%s: assoc request failed\n", __func__);
2118 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2121 gelic_wl_send_iwap_event(wl, NULL);
2126 /* wait for connected event */
2127 rc = wait_for_completion_timeout(&wl->assoc_done, HZ * 4);/*FIXME*/
2130 /* timeouted. Maybe key or cyrpt mode is wrong */
2131 pr_info("%s: connect timeout \n", __func__);
2132 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC,
2135 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2136 gelic_wl_send_iwap_event(wl, NULL);
2139 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATED;
2141 memcpy(wl->active_bssid, &bss->hwinfo->bssid[2], ETH_ALEN);
2143 /* send connect event */
2144 gelic_wl_send_iwap_event(wl, wl->active_bssid);
2145 pr_info("%s: connected\n", __func__);
2148 free_page((unsigned long)common);
2149 pr_debug("%s: ->\n", __func__);
2156 static void gelic_wl_connected_event(struct gelic_wl_info *wl,
2159 u64 desired_event = 0;
2161 switch (wl->wpa_level) {
2162 case GELIC_WL_WPA_LEVEL_NONE:
2163 desired_event = GELIC_LV1_WL_EVENT_CONNECTED;
2165 case GELIC_WL_WPA_LEVEL_WPA:
2166 case GELIC_WL_WPA_LEVEL_WPA2:
2167 desired_event = GELIC_LV1_WL_EVENT_WPA_CONNECTED;
2171 if (desired_event == event) {
2172 pr_debug("%s: completed \n", __func__);
2173 complete(&wl->assoc_done);
2174 netif_carrier_on(port_to_netdev(wl_port(wl)));
2176 pr_debug("%s: event %#lx under wpa\n",
2183 static void gelic_wl_disconnect_event(struct gelic_wl_info *wl,
2186 struct gelic_eurus_cmd *cmd;
2190 * If we fall here in the middle of association,
2191 * associate_bss() should be waiting for complation of
2193 * As it waits with timeout, just leave assoc_done
2194 * uncompleted, then it terminates with timeout
2196 if (!mutex_trylock(&wl->assoc_stat_lock)) {
2197 pr_debug("%s: already locked\n", __func__);
2200 pr_debug("%s: obtain lock\n", __func__);
2204 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2207 /* send disconnected event to the supplicant */
2208 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2209 gelic_wl_send_iwap_event(wl, NULL);
2211 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2212 netif_carrier_off(port_to_netdev(wl_port(wl)));
2215 mutex_unlock(&wl->assoc_stat_lock);
2221 static const char *eventstr(enum gelic_lv1_wl_event event)
2223 static char buf[32];
2225 if (event & GELIC_LV1_WL_EVENT_DEVICE_READY)
2226 ret = "EURUS_READY";
2227 else if (event & GELIC_LV1_WL_EVENT_SCAN_COMPLETED)
2228 ret = "SCAN_COMPLETED";
2229 else if (event & GELIC_LV1_WL_EVENT_DEAUTH)
2231 else if (event & GELIC_LV1_WL_EVENT_BEACON_LOST)
2232 ret = "BEACON_LOST";
2233 else if (event & GELIC_LV1_WL_EVENT_CONNECTED)
2235 else if (event & GELIC_LV1_WL_EVENT_WPA_CONNECTED)
2236 ret = "WPA_CONNECTED";
2237 else if (event & GELIC_LV1_WL_EVENT_WPA_ERROR)
2240 sprintf(buf, "Unknown(%#x)", event);
2246 static const char *eventstr(enum gelic_lv1_wl_event event)
2251 static void gelic_wl_event_worker(struct work_struct *work)
2253 struct gelic_wl_info *wl;
2254 struct gelic_port *port;
2258 pr_debug("%s:start\n", __func__);
2259 wl = container_of(work, struct gelic_wl_info, event_work.work);
2262 status = lv1_net_control(bus_id(port->card), dev_id(port->card),
2263 GELIC_LV1_GET_WLAN_EVENT, 0, 0, 0,
2266 if (status != LV1_NO_ENTRY)
2267 pr_debug("%s:wlan event failed %d\n",
2269 /* got all events */
2270 pr_debug("%s:end\n", __func__);
2273 pr_debug("%s: event=%s\n", __func__, eventstr(event));
2275 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
2276 gelic_wl_scan_complete_event(wl);
2278 case GELIC_LV1_WL_EVENT_BEACON_LOST:
2279 case GELIC_LV1_WL_EVENT_DEAUTH:
2280 gelic_wl_disconnect_event(wl, event);
2282 case GELIC_LV1_WL_EVENT_CONNECTED:
2283 case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
2284 gelic_wl_connected_event(wl, event);
2292 * association worker
2294 static void gelic_wl_assoc_worker(struct work_struct *work)
2296 struct gelic_wl_info *wl;
2298 struct gelic_wl_scan_info *best_bss;
2300 unsigned long irqflag;
2304 wl = container_of(work, struct gelic_wl_info, assoc_work.work);
2306 mutex_lock(&wl->assoc_stat_lock);
2308 if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
2311 spin_lock_irqsave(&wl->lock, irqflag);
2312 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
2313 pr_debug("%s: assoc ESSID configured %s\n", __func__,
2316 essid_len = wl->essid_len;
2321 spin_unlock_irqrestore(&wl->lock, irqflag);
2323 ret = gelic_wl_start_scan(wl, 0, essid, essid_len);
2324 if (ret == -ERESTARTSYS) {
2325 pr_debug("%s: scan start failed association\n", __func__);
2326 schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
2329 pr_info("%s: scan prerequisite failed\n", __func__);
2334 * Wait for bss scan completion
2335 * If we have scan list already, gelic_wl_start_scan()
2336 * returns OK and raises the complete. Thus,
2337 * it's ok to wait unconditionally here
2339 wait_for_completion(&wl->scan_done);
2341 pr_debug("%s: scan done\n", __func__);
2342 mutex_lock(&wl->scan_lock);
2343 if (wl->scan_stat != GELIC_WL_SCAN_STAT_GOT_LIST) {
2344 gelic_wl_send_iwap_event(wl, NULL);
2345 pr_info("%s: no scan list. association failed\n", __func__);
2349 /* find best matching bss */
2350 best_bss = gelic_wl_find_best_bss(wl);
2352 gelic_wl_send_iwap_event(wl, NULL);
2353 pr_info("%s: no bss matched. association failed\n", __func__);
2357 /* ok, do association */
2358 ret = gelic_wl_associate_bss(wl, best_bss);
2360 pr_info("%s: association failed %d\n", __func__, ret);
2362 mutex_unlock(&wl->scan_lock);
2364 mutex_unlock(&wl->assoc_stat_lock);
2368 * Called from the ethernet interrupt handler
2369 * Processes wireless specific virtual interrupts only
2371 void gelic_wl_interrupt(struct net_device *netdev, u64 status)
2373 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2375 if (status & GELIC_CARD_WLAN_COMMAND_COMPLETED) {
2376 pr_debug("%s:cmd complete\n", __func__);
2377 complete(&wl->cmd_done_intr);
2380 if (status & GELIC_CARD_WLAN_EVENT_RECEIVED) {
2381 pr_debug("%s:event received\n", __func__);
2382 queue_delayed_work(wl->event_queue, &wl->event_work, 0);
2389 #define IW_IOCTL(n) [(n) - SIOCSIWCOMMIT]
2390 static const iw_handler gelic_wl_wext_handler[] =
2392 IW_IOCTL(SIOCGIWNAME) = gelic_wl_get_name,
2393 IW_IOCTL(SIOCGIWRANGE) = gelic_wl_get_range,
2394 IW_IOCTL(SIOCSIWSCAN) = gelic_wl_set_scan,
2395 IW_IOCTL(SIOCGIWSCAN) = gelic_wl_get_scan,
2396 IW_IOCTL(SIOCSIWAUTH) = gelic_wl_set_auth,
2397 IW_IOCTL(SIOCGIWAUTH) = gelic_wl_get_auth,
2398 IW_IOCTL(SIOCSIWESSID) = gelic_wl_set_essid,
2399 IW_IOCTL(SIOCGIWESSID) = gelic_wl_get_essid,
2400 IW_IOCTL(SIOCSIWENCODE) = gelic_wl_set_encode,
2401 IW_IOCTL(SIOCGIWENCODE) = gelic_wl_get_encode,
2402 IW_IOCTL(SIOCSIWAP) = gelic_wl_set_ap,
2403 IW_IOCTL(SIOCGIWAP) = gelic_wl_get_ap,
2404 IW_IOCTL(SIOCSIWENCODEEXT) = gelic_wl_set_encodeext,
2405 IW_IOCTL(SIOCGIWENCODEEXT) = gelic_wl_get_encodeext,
2406 IW_IOCTL(SIOCSIWMODE) = gelic_wl_set_mode,
2407 IW_IOCTL(SIOCGIWMODE) = gelic_wl_get_mode,
2408 IW_IOCTL(SIOCGIWNICKN) = gelic_wl_get_nick,
2411 #ifdef CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE
2412 static struct iw_priv_args gelic_wl_private_args[] =
2415 .cmd = GELIC_WL_PRIV_SET_PSK,
2416 .set_args = IW_PRIV_TYPE_CHAR |
2417 (GELIC_WL_EURUS_PSK_MAX_LEN + 2),
2421 .cmd = GELIC_WL_PRIV_GET_PSK,
2422 .get_args = IW_PRIV_TYPE_CHAR |
2423 (GELIC_WL_EURUS_PSK_MAX_LEN + 2),
2428 static const iw_handler gelic_wl_private_handler[] =
2430 gelic_wl_priv_set_psk,
2431 gelic_wl_priv_get_psk,
2435 static const struct iw_handler_def gelic_wl_wext_handler_def = {
2436 .num_standard = ARRAY_SIZE(gelic_wl_wext_handler),
2437 .standard = gelic_wl_wext_handler,
2438 .get_wireless_stats = gelic_wl_get_wireless_stats,
2439 #ifdef CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE
2440 .num_private = ARRAY_SIZE(gelic_wl_private_handler),
2441 .num_private_args = ARRAY_SIZE(gelic_wl_private_args),
2442 .private = gelic_wl_private_handler,
2443 .private_args = gelic_wl_private_args,
2447 static struct net_device *gelic_wl_alloc(struct gelic_card *card)
2449 struct net_device *netdev;
2450 struct gelic_port *port;
2451 struct gelic_wl_info *wl;
2454 pr_debug("%s:start\n", __func__);
2455 netdev = alloc_etherdev(sizeof(struct gelic_port) +
2456 sizeof(struct gelic_wl_info));
2457 pr_debug("%s: netdev =%p card=%p \np", __func__, netdev, card);
2461 strcpy(netdev->name, "wlan%d");
2463 port = netdev_priv(netdev);
2464 port->netdev = netdev;
2466 port->type = GELIC_PORT_WIRELESS;
2469 pr_debug("%s: wl=%p port=%p\n", __func__, wl, port);
2471 /* allocate scan list */
2472 wl->networks = kzalloc(sizeof(struct gelic_wl_scan_info) *
2473 GELIC_WL_BSS_MAX_ENT, GFP_KERNEL);
2478 wl->eurus_cmd_queue = create_singlethread_workqueue("gelic_cmd");
2479 if (!wl->eurus_cmd_queue)
2480 goto fail_cmd_workqueue;
2482 wl->event_queue = create_singlethread_workqueue("gelic_event");
2483 if (!wl->event_queue)
2484 goto fail_event_workqueue;
2486 INIT_LIST_HEAD(&wl->network_free_list);
2487 INIT_LIST_HEAD(&wl->network_list);
2488 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++)
2489 list_add_tail(&wl->networks[i].list,
2490 &wl->network_free_list);
2491 init_completion(&wl->cmd_done_intr);
2493 INIT_DELAYED_WORK(&wl->event_work, gelic_wl_event_worker);
2494 INIT_DELAYED_WORK(&wl->assoc_work, gelic_wl_assoc_worker);
2495 mutex_init(&wl->scan_lock);
2496 mutex_init(&wl->assoc_stat_lock);
2498 init_completion(&wl->scan_done);
2499 /* for the case that no scan request is issued and stop() is called */
2500 complete(&wl->scan_done);
2502 spin_lock_init(&wl->lock);
2504 wl->scan_age = 5*HZ; /* FIXME */
2506 /* buffer for receiving scanned list etc */
2507 BUILD_BUG_ON(PAGE_SIZE <
2508 sizeof(struct gelic_eurus_scan_info) *
2509 GELIC_EURUS_MAX_SCAN);
2510 pr_debug("%s:end\n", __func__);
2513 fail_event_workqueue:
2514 destroy_workqueue(wl->eurus_cmd_queue);
2516 kfree(wl->networks);
2518 free_netdev(netdev);
2519 pr_debug("%s:end error\n", __func__);
2524 static void gelic_wl_free(struct gelic_wl_info *wl)
2526 struct gelic_wl_scan_info *scan_info;
2529 pr_debug("%s: <-\n", __func__);
2531 pr_debug("%s: destroy queues\n", __func__);
2532 destroy_workqueue(wl->eurus_cmd_queue);
2533 destroy_workqueue(wl->event_queue);
2535 scan_info = wl->networks;
2536 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++, scan_info++)
2537 kfree(scan_info->hwinfo);
2538 kfree(wl->networks);
2540 free_netdev(port_to_netdev(wl_port(wl)));
2542 pr_debug("%s: ->\n", __func__);
2545 static int gelic_wl_try_associate(struct net_device *netdev)
2547 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2551 pr_debug("%s: <-\n", __func__);
2553 /* check constraits for start association */
2554 /* for no access restriction AP */
2555 if (wl->group_cipher_method == GELIC_WL_CIPHER_NONE) {
2556 if (test_bit(GELIC_WL_STAT_CONFIGURED,
2560 pr_debug("%s: no wep, not configured\n", __func__);
2565 /* for WEP, one of four keys should be set */
2566 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
2567 /* one of keys set */
2568 for (i = 0; i < GELIC_WEP_KEYS; i++) {
2569 if (test_bit(i, &wl->key_enabled))
2572 pr_debug("%s: WEP, but no key specified\n", __func__);
2576 /* for WPA[2], psk should be set */
2577 if ((wl->group_cipher_method == GELIC_WL_CIPHER_TKIP) ||
2578 (wl->group_cipher_method == GELIC_WL_CIPHER_AES)) {
2579 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET,
2583 pr_debug("%s: AES/TKIP, but PSK not configured\n",
2590 ret = schedule_delayed_work(&wl->assoc_work, 0);
2591 pr_debug("%s: start association work %d\n", __func__, ret);
2598 static int gelic_wl_open(struct net_device *netdev)
2600 struct gelic_card *card = netdev_card(netdev);
2602 pr_debug("%s:->%p\n", __func__, netdev);
2604 gelic_card_up(card);
2606 /* try to associate */
2607 gelic_wl_try_associate(netdev);
2609 netif_start_queue(netdev);
2611 pr_debug("%s:<-\n", __func__);
2616 * reset state machine
2618 static int gelic_wl_reset_state(struct gelic_wl_info *wl)
2620 struct gelic_wl_scan_info *target;
2621 struct gelic_wl_scan_info *tmp;
2623 /* empty scan list */
2624 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
2625 list_move_tail(&target->list, &wl->network_free_list);
2627 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
2629 /* clear configuration */
2630 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
2631 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
2632 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
2633 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
2635 wl->key_enabled = 0;
2636 wl->current_key = 0;
2638 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
2642 memset(wl->essid, 0, sizeof(wl->essid));
2643 memset(wl->bssid, 0, sizeof(wl->bssid));
2644 memset(wl->active_bssid, 0, sizeof(wl->active_bssid));
2646 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2648 memset(&wl->iwstat, 0, sizeof(wl->iwstat));
2649 /* all status bit clear */
2655 * Tell eurus to terminate association
2657 static void gelic_wl_disconnect(struct net_device *netdev)
2659 struct gelic_port *port = netdev_priv(netdev);
2660 struct gelic_wl_info *wl = port_wl(port);
2661 struct gelic_eurus_cmd *cmd;
2664 * If scann process is running on chip,
2665 * further requests will be rejected
2667 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING)
2668 wait_for_completion_timeout(&wl->scan_done, HZ);
2670 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2672 gelic_wl_send_iwap_event(wl, NULL);
2675 static int gelic_wl_stop(struct net_device *netdev)
2677 struct gelic_port *port = netdev_priv(netdev);
2678 struct gelic_wl_info *wl = port_wl(port);
2679 struct gelic_card *card = netdev_card(netdev);
2681 pr_debug("%s:<-\n", __func__);
2684 * Cancel pending association work.
2685 * event work can run after netdev down
2687 cancel_delayed_work(&wl->assoc_work);
2689 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2690 gelic_wl_disconnect(netdev);
2692 /* reset our state machine */
2693 gelic_wl_reset_state(wl);
2695 netif_stop_queue(netdev);
2697 gelic_card_down(card);
2699 pr_debug("%s:->\n", __func__);
2705 static struct ethtool_ops gelic_wl_ethtool_ops = {
2706 .get_drvinfo = gelic_net_get_drvinfo,
2707 .get_link = gelic_wl_get_link,
2708 .get_tx_csum = ethtool_op_get_tx_csum,
2709 .set_tx_csum = ethtool_op_set_tx_csum,
2710 .get_rx_csum = gelic_net_get_rx_csum,
2711 .set_rx_csum = gelic_net_set_rx_csum,
2714 static void gelic_wl_setup_netdev_ops(struct net_device *netdev)
2716 struct gelic_wl_info *wl;
2717 wl = port_wl(netdev_priv(netdev));
2719 netdev->open = &gelic_wl_open;
2720 netdev->stop = &gelic_wl_stop;
2721 netdev->hard_start_xmit = &gelic_net_xmit;
2722 netdev->set_multicast_list = &gelic_net_set_multi;
2723 netdev->change_mtu = &gelic_net_change_mtu;
2724 netdev->wireless_data = &wl->wireless_data;
2725 netdev->wireless_handlers = &gelic_wl_wext_handler_def;
2727 netdev->tx_timeout = &gelic_net_tx_timeout;
2728 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
2730 netdev->ethtool_ops = &gelic_wl_ethtool_ops;
2731 #ifdef CONFIG_NET_POLL_CONTROLLER
2732 netdev->poll_controller = gelic_net_poll_controller;
2737 * driver probe/remove
2739 int gelic_wl_driver_probe(struct gelic_card *card)
2742 struct net_device *netdev;
2744 pr_debug("%s:start\n", __func__);
2746 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2748 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2751 /* alloc netdevice for wireless */
2752 netdev = gelic_wl_alloc(card);
2756 /* setup net_device structure */
2757 SET_NETDEV_DEV(netdev, &card->dev->core);
2758 gelic_wl_setup_netdev_ops(netdev);
2760 /* setup some of net_device and register it */
2761 ret = gelic_net_setup_netdev(netdev, card);
2764 card->netdev[GELIC_PORT_WIRELESS] = netdev;
2766 /* add enable wireless interrupt */
2767 card->irq_mask |= GELIC_CARD_WLAN_EVENT_RECEIVED |
2768 GELIC_CARD_WLAN_COMMAND_COMPLETED;
2769 /* to allow wireless commands while both interfaces are down */
2770 gelic_card_set_irq_mask(card, GELIC_CARD_WLAN_EVENT_RECEIVED |
2771 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2772 pr_debug("%s:end\n", __func__);
2776 gelic_wl_free(port_wl(netdev_port(netdev)));
2781 int gelic_wl_driver_remove(struct gelic_card *card)
2783 struct gelic_wl_info *wl;
2784 struct net_device *netdev;
2786 pr_debug("%s:start\n", __func__);
2788 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2790 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2793 netdev = card->netdev[GELIC_PORT_WIRELESS];
2794 wl = port_wl(netdev_priv(netdev));
2796 /* if the interface was not up, but associated */
2797 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2798 gelic_wl_disconnect(netdev);
2800 complete(&wl->cmd_done_intr);
2802 /* cancel all work queue */
2803 cancel_delayed_work(&wl->assoc_work);
2804 cancel_delayed_work(&wl->event_work);
2805 flush_workqueue(wl->eurus_cmd_queue);
2806 flush_workqueue(wl->event_queue);
2808 unregister_netdev(netdev);
2810 /* disable wireless interrupt */
2811 pr_debug("%s: disable intr\n", __func__);
2812 card->irq_mask &= ~(GELIC_CARD_WLAN_EVENT_RECEIVED |
2813 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2814 /* free bss list, netdev*/
2816 pr_debug("%s:end\n", __func__);