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>
24 #include <linux/slab.h>
26 #include <linux/etherdevice.h>
27 #include <linux/ethtool.h>
28 #include <linux/if_vlan.h>
32 #include <linux/tcp.h>
33 #include <linux/wireless.h>
34 #include <linux/ieee80211.h>
35 #include <linux/if_arp.h>
36 #include <linux/ctype.h>
37 #include <linux/string.h>
38 #include <net/iw_handler.h>
40 #include <linux/dma-mapping.h>
41 #include <net/checksum.h>
42 #include <asm/firmware.h>
44 #include <asm/lv1call.h>
46 #include "ps3_gelic_net.h"
47 #include "ps3_gelic_wireless.h"
50 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
51 u8 *essid, size_t essid_len);
52 static int gelic_wl_try_associate(struct net_device *netdev);
58 /* 802.11b/g channel to freq in MHz */
59 static const int channel_freq[] = {
60 2412, 2417, 2422, 2427, 2432,
61 2437, 2442, 2447, 2452, 2457,
62 2462, 2467, 2472, 2484
64 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
67 static const int bitrate_list[] = {
81 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
84 * wpa2 support requires the hypervisor version 2.0 or later
86 static inline int wpa2_capable(void)
88 return 0 <= ps3_compare_firmware_version(2, 0, 0);
91 static inline int precise_ie(void)
93 return 0 <= ps3_compare_firmware_version(2, 2, 0);
96 * post_eurus_cmd helpers
98 struct eurus_cmd_arg_info {
99 int pre_arg; /* command requires arg1, arg2 at POST COMMAND */
100 int post_arg; /* command requires arg1, arg2 at GET_RESULT */
103 static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
104 [GELIC_EURUS_CMD_SET_COMMON_CFG] = { .pre_arg = 1},
105 [GELIC_EURUS_CMD_SET_WEP_CFG] = { .pre_arg = 1},
106 [GELIC_EURUS_CMD_SET_WPA_CFG] = { .pre_arg = 1},
107 [GELIC_EURUS_CMD_GET_COMMON_CFG] = { .post_arg = 1},
108 [GELIC_EURUS_CMD_GET_WEP_CFG] = { .post_arg = 1},
109 [GELIC_EURUS_CMD_GET_WPA_CFG] = { .post_arg = 1},
110 [GELIC_EURUS_CMD_GET_RSSI_CFG] = { .post_arg = 1},
111 [GELIC_EURUS_CMD_START_SCAN] = { .pre_arg = 1},
112 [GELIC_EURUS_CMD_GET_SCAN] = { .post_arg = 1},
116 static const char *cmdstr(enum gelic_eurus_command ix)
119 case GELIC_EURUS_CMD_ASSOC:
121 case GELIC_EURUS_CMD_DISASSOC:
123 case GELIC_EURUS_CMD_START_SCAN:
125 case GELIC_EURUS_CMD_GET_SCAN:
127 case GELIC_EURUS_CMD_SET_COMMON_CFG:
128 return "SET_COMMON_CFG";
129 case GELIC_EURUS_CMD_GET_COMMON_CFG:
130 return "GET_COMMON_CFG";
131 case GELIC_EURUS_CMD_SET_WEP_CFG:
132 return "SET_WEP_CFG";
133 case GELIC_EURUS_CMD_GET_WEP_CFG:
134 return "GET_WEP_CFG";
135 case GELIC_EURUS_CMD_SET_WPA_CFG:
136 return "SET_WPA_CFG";
137 case GELIC_EURUS_CMD_GET_WPA_CFG:
138 return "GET_WPA_CFG";
139 case GELIC_EURUS_CMD_GET_RSSI_CFG:
147 static inline const char *cmdstr(enum gelic_eurus_command ix)
153 /* synchronously do eurus commands */
154 static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
156 struct gelic_eurus_cmd *cmd;
157 struct gelic_card *card;
158 struct gelic_wl_info *wl;
162 pr_debug("%s: <-\n", __func__);
163 cmd = container_of(work, struct gelic_eurus_cmd, work);
164 BUG_ON(cmd_info[cmd->cmd].pre_arg &&
165 cmd_info[cmd->cmd].post_arg);
167 card = port_to_card(wl_port(wl));
169 if (cmd_info[cmd->cmd].pre_arg) {
170 arg1 = (cmd->buffer) ?
171 ps3_mm_phys_to_lpar(__pa(cmd->buffer)) :
173 arg2 = cmd->buf_size;
178 init_completion(&wl->cmd_done_intr);
179 pr_debug("%s: cmd='%s' start\n", __func__, cmdstr(cmd->cmd));
180 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
181 GELIC_LV1_POST_WLAN_CMD,
182 cmd->cmd, arg1, arg2,
183 &cmd->tag, &cmd->size);
185 complete(&cmd->done);
186 pr_info("%s: cmd issue failed\n", __func__);
190 wait_for_completion(&wl->cmd_done_intr);
192 if (cmd_info[cmd->cmd].post_arg) {
193 arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
194 arg2 = cmd->buf_size;
200 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
201 GELIC_LV1_GET_WLAN_CMD_RESULT,
202 cmd->tag, arg1, arg2,
203 &cmd->cmd_status, &cmd->size);
205 if (cmd->status || cmd->cmd_status) {
206 pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__,
207 cmd->tag, arg1, arg2);
208 pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
209 __func__, cmd->status, cmd->cmd_status, cmd->size);
212 complete(&cmd->done);
213 pr_debug("%s: cmd='%s' done\n", __func__, cmdstr(cmd->cmd));
216 static struct gelic_eurus_cmd *gelic_eurus_sync_cmd(struct gelic_wl_info *wl,
217 unsigned int eurus_cmd,
219 unsigned int buf_size)
221 struct gelic_eurus_cmd *cmd;
224 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
228 /* initialize members */
229 cmd->cmd = eurus_cmd;
230 cmd->buffer = buffer;
231 cmd->buf_size = buf_size;
233 INIT_WORK(&cmd->work, gelic_eurus_sync_cmd_worker);
234 init_completion(&cmd->done);
235 queue_work(wl->eurus_cmd_queue, &cmd->work);
237 /* wait for command completion */
238 wait_for_completion(&cmd->done);
243 static u32 gelic_wl_get_link(struct net_device *netdev)
245 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
248 pr_debug("%s: <-\n", __func__);
249 mutex_lock(&wl->assoc_stat_lock);
250 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
254 mutex_unlock(&wl->assoc_stat_lock);
255 pr_debug("%s: ->\n", __func__);
259 static void gelic_wl_send_iwap_event(struct gelic_wl_info *wl, u8 *bssid)
261 union iwreq_data data;
263 memset(&data, 0, sizeof(data));
265 memcpy(data.ap_addr.sa_data, bssid, ETH_ALEN);
266 data.ap_addr.sa_family = ARPHRD_ETHER;
267 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWAP,
272 * wireless extension handlers and helpers
276 static int gelic_wl_get_name(struct net_device *dev,
277 struct iw_request_info *info,
278 union iwreq_data *iwreq, char *extra)
280 strcpy(iwreq->name, "IEEE 802.11bg");
284 static void gelic_wl_get_ch_info(struct gelic_wl_info *wl)
286 struct gelic_card *card = port_to_card(wl_port(wl));
287 u64 ch_info_raw, tmp;
290 if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO, &wl->stat)) {
291 status = lv1_net_control(bus_id(card), dev_id(card),
292 GELIC_LV1_GET_CHANNEL, 0, 0, 0,
295 /* some fw versions may return error */
297 if (status != LV1_NO_ENTRY)
298 pr_info("%s: available ch unknown\n", __func__);
299 wl->ch_info = 0x07ff;/* 11 ch */
301 /* 16 bits of MSB has available channels */
302 wl->ch_info = ch_info_raw >> 48;
307 static int gelic_wl_get_range(struct net_device *netdev,
308 struct iw_request_info *info,
309 union iwreq_data *iwreq, char *extra)
311 struct iw_point *point = &iwreq->data;
312 struct iw_range *range = (struct iw_range *)extra;
313 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
316 pr_debug("%s: <-\n", __func__);
317 point->length = sizeof(struct iw_range);
318 memset(range, 0, sizeof(struct iw_range));
320 range->we_version_compiled = WIRELESS_EXT;
321 range->we_version_source = 22;
323 /* available channels and frequencies */
324 gelic_wl_get_ch_info(wl);
327 i < NUM_CHANNELS && chs < IW_MAX_FREQUENCIES; i++)
328 if (wl->ch_info & (1 << i)) {
329 range->freq[chs].i = i + 1;
330 range->freq[chs].m = channel_freq[i];
331 range->freq[chs].e = 6;
334 range->num_frequency = chs;
335 range->old_num_frequency = chs;
336 range->num_channels = chs;
337 range->old_num_channels = chs;
340 for (i = 0; i < NUM_BITRATES; i++)
341 range->bitrate[i] = bitrate_list[i];
342 range->num_bitrates = i;
345 range->max_qual.qual = 100; /* relative value */
346 range->max_qual.level = 100;
347 range->avg_qual.qual = 50;
348 range->avg_qual.level = 50;
349 range->sensitivity = 0;
351 /* Event capability */
352 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
353 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
354 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
356 /* encryption capability */
357 range->enc_capa = IW_ENC_CAPA_WPA |
358 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP |
359 IW_ENC_CAPA_4WAY_HANDSHAKE;
361 range->enc_capa |= IW_ENC_CAPA_WPA2;
362 range->encoding_size[0] = 5; /* 40bit WEP */
363 range->encoding_size[1] = 13; /* 104bit WEP */
364 range->encoding_size[2] = 32; /* WPA-PSK */
365 range->num_encoding_sizes = 3;
366 range->max_encoding_tokens = GELIC_WEP_KEYS;
368 /* scan capability */
369 range->scan_capa = IW_SCAN_CAPA_ESSID;
371 pr_debug("%s: ->\n", __func__);
376 /* SIOC{G,S}IWSCAN */
377 static int gelic_wl_set_scan(struct net_device *netdev,
378 struct iw_request_info *info,
379 union iwreq_data *wrqu, char *extra)
381 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
382 struct iw_scan_req *req;
384 size_t essid_len = 0;
386 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
387 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
388 req = (struct iw_scan_req*)extra;
390 essid_len = req->essid_len;
391 pr_debug("%s: ESSID scan =%s\n", __func__, essid);
393 return gelic_wl_start_scan(wl, 1, essid, essid_len);
397 static const u8 rsn_oui[OUI_LEN] = { 0x00, 0x0f, 0xac };
398 static const u8 wpa_oui[OUI_LEN] = { 0x00, 0x50, 0xf2 };
401 * synthesize WPA/RSN IE data
402 * See WiFi WPA specification and IEEE 802.11-2007 7.3.2.25
405 static size_t gelic_wl_synthesize_ie(u8 *buf,
406 struct gelic_eurus_scan_info *scan)
409 const u8 *oui_header;
414 pr_debug("%s: <- sec=%16x\n", __func__, scan->security);
415 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_MASK) {
416 case GELIC_EURUS_SCAN_SEC_WPA:
419 case GELIC_EURUS_SCAN_SEC_WPA2:
423 /* WEP or none. No IE returned */
427 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_WPA_MASK) {
428 case GELIC_EURUS_SCAN_SEC_WPA_TKIP:
431 case GELIC_EURUS_SCAN_SEC_WPA_AES:
437 pr_info("%s: no cipher info. defaulted to CCMP\n",
441 pr_info("%s: no cipher info. defaulted to TKIP\n",
447 oui_header = rsn_oui;
449 oui_header = wpa_oui;
453 *buf++ = WLAN_EID_RSN;
455 *buf++ = WLAN_EID_VENDOR_SPECIFIC;
457 /* length filed; set later */
460 /* wpa special header */
462 memcpy(buf, wpa_oui, OUI_LEN);
468 *buf++ = 0x01; /* version 1.0 */
472 memcpy(buf, oui_header, OUI_LEN);
476 *buf++ = 0x04; /* CCMP */
478 *buf++ = 0x02; /* TKIP */
480 /* pairwise key count always 1 */
484 /* pairwise key suit */
485 memcpy(buf, oui_header, OUI_LEN);
488 *buf++ = 0x04; /* CCMP */
490 *buf++ = 0x02; /* TKIP */
496 /* AKM suite is assumed as PSK*/
497 memcpy(buf, oui_header, OUI_LEN);
499 *buf++ = 0x02; /* PSK */
501 /* RSN capabilities is 0 */
505 /* set length field */
506 start[1] = (buf - start - 2);
508 pr_debug("%s: ->\n", __func__);
522 static void gelic_wl_parse_ie(u8 *data, size_t len,
523 struct ie_info *ie_info)
525 size_t data_left = len;
530 pr_debug("%s: data=%p len=%ld\n", __func__,
532 memset(ie_info, 0, sizeof(struct ie_info));
534 while (2 <= data_left) {
539 if (data_left < item_len)
543 case WLAN_EID_VENDOR_SPECIFIC:
544 if ((OUI_LEN + 1 <= item_len) &&
545 !memcmp(pos, wpa_oui, OUI_LEN) &&
546 pos[OUI_LEN] == 0x01) {
547 ie_info->wpa.data = pos - 2;
548 ie_info->wpa.len = item_len + 2;
552 ie_info->rsn.data = pos - 2;
553 /* length includes the header */
554 ie_info->rsn.len = item_len + 2;
557 pr_debug("%s: ignore %#x,%d\n", __func__,
562 data_left -= item_len;
564 pr_debug("%s: wpa=%p,%d wpa2=%p,%d\n", __func__,
565 ie_info->wpa.data, ie_info->wpa.len,
566 ie_info->rsn.data, ie_info->rsn.len);
571 * translate the scan informations from hypervisor to a
574 static char *gelic_wl_translate_scan(struct net_device *netdev,
575 struct iw_request_info *info,
578 struct gelic_wl_scan_info *network)
581 struct gelic_eurus_scan_info *scan = network->hwinfo;
584 unsigned int i, j, len;
585 u8 buf[64]; /* arbitrary size large enough */
587 pr_debug("%s: <-\n", __func__);
589 /* first entry should be AP's mac address */
591 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
592 memcpy(iwe.u.ap_addr.sa_data, &scan->bssid[2], ETH_ALEN);
593 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_ADDR_LEN);
596 iwe.cmd = SIOCGIWESSID;
597 iwe.u.data.flags = 1;
598 iwe.u.data.length = strnlen(scan->essid, 32);
599 ev = iwe_stream_add_point(info, ev, stop, &iwe, scan->essid);
602 iwe.cmd = SIOCGIWFREQ;
603 iwe.u.freq.m = be16_to_cpu(scan->channel);
604 iwe.u.freq.e = 0; /* table value in MHz */
606 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_FREQ_LEN);
609 iwe.cmd = SIOCGIWRATE;
610 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
611 /* to stuff multiple values in one event */
612 tmp = ev + iwe_stream_lcp_len(info);
613 /* put them in ascendant order (older is first) */
616 pr_debug("%s: rates=%d rate=%d\n", __func__,
617 network->rate_len, network->rate_ext_len);
618 while (i < network->rate_len) {
619 if (j < network->rate_ext_len &&
620 ((scan->ext_rate[j] & 0x7f) < (scan->rate[i] & 0x7f)))
621 rate = scan->ext_rate[j++] & 0x7f;
623 rate = scan->rate[i++] & 0x7f;
624 iwe.u.bitrate.value = rate * 500000; /* 500kbps unit */
625 tmp = iwe_stream_add_value(info, ev, tmp, stop, &iwe,
628 while (j < network->rate_ext_len) {
629 iwe.u.bitrate.value = (scan->ext_rate[j++] & 0x7f) * 500000;
630 tmp = iwe_stream_add_value(info, ev, tmp, stop, &iwe,
633 /* Check if we added any rate */
634 if (iwe_stream_lcp_len(info) < (tmp - ev))
638 iwe.cmd = SIOCGIWENCODE;
639 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_PRIVACY)
640 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
642 iwe.u.data.flags = IW_ENCODE_DISABLED;
643 iwe.u.data.length = 0;
644 ev = iwe_stream_add_point(info, ev, stop, &iwe, scan->essid);
647 iwe.cmd = SIOCGIWMODE;
648 if (be16_to_cpu(scan->capability) &
649 (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
650 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_ESS)
651 iwe.u.mode = IW_MODE_MASTER;
653 iwe.u.mode = IW_MODE_ADHOC;
654 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_UINT_LEN);
659 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED |
660 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
661 iwe.u.qual.level = be16_to_cpu(scan->rssi);
662 iwe.u.qual.qual = be16_to_cpu(scan->rssi);
663 iwe.u.qual.noise = 0;
664 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_QUAL_LEN);
667 memset(&iwe, 0, sizeof(iwe));
668 if (be16_to_cpu(scan->size) <= sizeof(*scan)) {
669 /* If wpa[2] capable station, synthesize IE and put it */
670 len = gelic_wl_synthesize_ie(buf, scan);
673 iwe.u.data.length = len;
674 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
677 /* this scan info has IE data */
678 struct ie_info ie_info;
681 data_len = be16_to_cpu(scan->size) - sizeof(*scan);
683 gelic_wl_parse_ie(scan->elements, data_len, &ie_info);
685 if (ie_info.wpa.len && (ie_info.wpa.len <= sizeof(buf))) {
686 memcpy(buf, ie_info.wpa.data, ie_info.wpa.len);
688 iwe.u.data.length = ie_info.wpa.len;
689 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
692 if (ie_info.rsn.len && (ie_info.rsn.len <= sizeof(buf))) {
693 memset(&iwe, 0, sizeof(iwe));
694 memcpy(buf, ie_info.rsn.data, ie_info.rsn.len);
696 iwe.u.data.length = ie_info.rsn.len;
697 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
701 pr_debug("%s: ->\n", __func__);
706 static int gelic_wl_get_scan(struct net_device *netdev,
707 struct iw_request_info *info,
708 union iwreq_data *wrqu, char *extra)
710 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
711 struct gelic_wl_scan_info *scan_info;
713 char *stop = ev + wrqu->data.length;
715 unsigned long this_time = jiffies;
717 pr_debug("%s: <-\n", __func__);
718 if (mutex_lock_interruptible(&wl->scan_lock))
721 switch (wl->scan_stat) {
722 case GELIC_WL_SCAN_STAT_SCANNING:
723 /* 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 */
730 case GELIC_WL_SCAN_STAT_GOT_LIST:
731 /* ok, use current list */
735 list_for_each_entry(scan_info, &wl->network_list, list) {
736 if (wl->scan_age == 0 ||
737 time_after(scan_info->last_scanned + wl->scan_age,
739 ev = gelic_wl_translate_scan(netdev, info,
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;
766 list_for_each_entry(scan_info, &wl->network_list, list) {
767 pr_debug("%s: item %d\n", __func__, i++);
768 pr_debug("valid=%d eurusindex=%d last=%lx\n",
769 scan_info->valid, scan_info->eurus_index,
770 scan_info->last_scanned);
771 pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
772 scan_info->rate_len, scan_info->rate_ext_len,
773 scan_info->essid_len);
775 pr_debug("bssid=%pM\n", &scan_info->hwinfo->bssid[2]);
776 pr_debug("essid=%s\n", scan_info->hwinfo->essid);
781 static int gelic_wl_set_auth(struct net_device *netdev,
782 struct iw_request_info *info,
783 union iwreq_data *data, char *extra)
785 struct iw_param *param = &data->param;
786 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
787 unsigned long irqflag;
790 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
791 spin_lock_irqsave(&wl->lock, irqflag);
792 switch (param->flags & IW_AUTH_INDEX) {
793 case IW_AUTH_WPA_VERSION:
794 if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
795 pr_debug("%s: NO WPA selected\n", __func__);
796 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
797 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
798 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
800 if (param->value & IW_AUTH_WPA_VERSION_WPA) {
801 pr_debug("%s: WPA version 1 selected\n", __func__);
802 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
803 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
804 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
805 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
807 if (param->value & IW_AUTH_WPA_VERSION_WPA2) {
809 * As the hypervisor may not tell the cipher
810 * information of the AP if it is WPA2,
811 * you will not decide suitable cipher from
813 * You should have knowledge about the AP's
814 * cipher information in other method prior to
818 pr_info("%s: WPA2 may not work\n", __func__);
819 if (wpa2_capable()) {
820 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
821 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
822 wl->pairwise_cipher_method =
824 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
830 case IW_AUTH_CIPHER_PAIRWISE:
832 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
833 pr_debug("%s: WEP selected\n", __func__);
834 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
836 if (param->value & IW_AUTH_CIPHER_TKIP) {
837 pr_debug("%s: TKIP selected\n", __func__);
838 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
840 if (param->value & IW_AUTH_CIPHER_CCMP) {
841 pr_debug("%s: CCMP selected\n", __func__);
842 wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
844 if (param->value & IW_AUTH_CIPHER_NONE) {
845 pr_debug("%s: no auth selected\n", __func__);
846 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
849 case IW_AUTH_CIPHER_GROUP:
851 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
852 pr_debug("%s: WEP selected\n", __func__);
853 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
855 if (param->value & IW_AUTH_CIPHER_TKIP) {
856 pr_debug("%s: TKIP selected\n", __func__);
857 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
859 if (param->value & IW_AUTH_CIPHER_CCMP) {
860 pr_debug("%s: CCMP selected\n", __func__);
861 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
863 if (param->value & IW_AUTH_CIPHER_NONE) {
864 pr_debug("%s: no auth selected\n", __func__);
865 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
868 case IW_AUTH_80211_AUTH_ALG:
869 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
870 pr_debug("%s: shared key specified\n", __func__);
871 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
872 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
873 pr_debug("%s: open system specified\n", __func__);
874 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
879 case IW_AUTH_WPA_ENABLED:
881 pr_debug("%s: WPA enabled\n", __func__);
882 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
884 pr_debug("%s: WPA disabled\n", __func__);
885 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
889 case IW_AUTH_KEY_MGMT:
890 if (param->value & IW_AUTH_KEY_MGMT_PSK)
892 /* intentionally fall through */
899 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
901 spin_unlock_irqrestore(&wl->lock, irqflag);
902 pr_debug("%s: -> %d\n", __func__, ret);
906 static int gelic_wl_get_auth(struct net_device *netdev,
907 struct iw_request_info *info,
908 union iwreq_data *iwreq, char *extra)
910 struct iw_param *param = &iwreq->param;
911 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
912 unsigned long irqflag;
915 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
916 spin_lock_irqsave(&wl->lock, irqflag);
917 switch (param->flags & IW_AUTH_INDEX) {
918 case IW_AUTH_WPA_VERSION:
919 switch (wl->wpa_level) {
920 case GELIC_WL_WPA_LEVEL_WPA:
921 param->value |= IW_AUTH_WPA_VERSION_WPA;
923 case GELIC_WL_WPA_LEVEL_WPA2:
924 param->value |= IW_AUTH_WPA_VERSION_WPA2;
927 param->value |= IW_AUTH_WPA_VERSION_DISABLED;
931 case IW_AUTH_80211_AUTH_ALG:
932 if (wl->auth_method == GELIC_EURUS_AUTH_SHARED)
933 param->value = IW_AUTH_ALG_SHARED_KEY;
934 else if (wl->auth_method == GELIC_EURUS_AUTH_OPEN)
935 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
938 case IW_AUTH_WPA_ENABLED:
939 switch (wl->wpa_level) {
940 case GELIC_WL_WPA_LEVEL_WPA:
941 case GELIC_WL_WPA_LEVEL_WPA2:
953 spin_unlock_irqrestore(&wl->lock, irqflag);
954 pr_debug("%s: -> %d\n", __func__, ret);
958 /* SIOC{S,G}IWESSID */
959 static int gelic_wl_set_essid(struct net_device *netdev,
960 struct iw_request_info *info,
961 union iwreq_data *data, char *extra)
963 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
964 unsigned long irqflag;
966 pr_debug("%s: <- l=%d f=%d\n", __func__,
967 data->essid.length, data->essid.flags);
968 if (IW_ESSID_MAX_SIZE < data->essid.length)
971 spin_lock_irqsave(&wl->lock, irqflag);
972 if (data->essid.flags) {
973 wl->essid_len = data->essid.length;
974 memcpy(wl->essid, extra, wl->essid_len);
975 pr_debug("%s: essid = '%s'\n", __func__, extra);
976 set_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
978 pr_debug("%s: ESSID any\n", __func__);
979 clear_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
981 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
982 spin_unlock_irqrestore(&wl->lock, irqflag);
985 gelic_wl_try_associate(netdev); /* FIXME */
986 pr_debug("%s: ->\n", __func__);
990 static int gelic_wl_get_essid(struct net_device *netdev,
991 struct iw_request_info *info,
992 union iwreq_data *data, char *extra)
994 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
995 unsigned long irqflag;
997 pr_debug("%s: <-\n", __func__);
998 mutex_lock(&wl->assoc_stat_lock);
999 spin_lock_irqsave(&wl->lock, irqflag);
1000 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat) ||
1001 wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1002 memcpy(extra, wl->essid, wl->essid_len);
1003 data->essid.length = wl->essid_len;
1004 data->essid.flags = 1;
1006 data->essid.flags = 0;
1008 mutex_unlock(&wl->assoc_stat_lock);
1009 spin_unlock_irqrestore(&wl->lock, irqflag);
1010 pr_debug("%s: -> len=%d\n", __func__, data->essid.length);
1015 /* SIO{S,G}IWENCODE */
1016 static int gelic_wl_set_encode(struct net_device *netdev,
1017 struct iw_request_info *info,
1018 union iwreq_data *data, char *extra)
1020 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1021 struct iw_point *enc = &data->encoding;
1023 unsigned long irqflag;
1024 int key_index, index_specified;
1027 pr_debug("%s: <-\n", __func__);
1028 flags = enc->flags & IW_ENCODE_FLAGS;
1029 key_index = enc->flags & IW_ENCODE_INDEX;
1031 pr_debug("%s: key_index = %d\n", __func__, key_index);
1032 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1033 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1035 if (GELIC_WEP_KEYS < key_index)
1038 spin_lock_irqsave(&wl->lock, irqflag);
1040 index_specified = 1;
1043 index_specified = 0;
1044 key_index = wl->current_key;
1047 if (flags & IW_ENCODE_NOKEY) {
1048 /* if just IW_ENCODE_NOKEY, change current key index */
1049 if (!flags && index_specified) {
1050 wl->current_key = key_index;
1054 if (flags & IW_ENCODE_DISABLED) {
1055 if (!index_specified) {
1056 /* disable encryption */
1057 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1058 wl->pairwise_cipher_method =
1059 GELIC_WL_CIPHER_NONE;
1060 /* invalidate all key */
1061 wl->key_enabled = 0;
1063 clear_bit(key_index, &wl->key_enabled);
1066 if (flags & IW_ENCODE_OPEN)
1067 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1068 if (flags & IW_ENCODE_RESTRICTED) {
1069 pr_info("%s: shared key mode enabled\n", __func__);
1070 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1073 if (IW_ENCODING_TOKEN_MAX < enc->length) {
1077 wl->key_len[key_index] = enc->length;
1078 memcpy(wl->key[key_index], extra, enc->length);
1079 set_bit(key_index, &wl->key_enabled);
1080 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
1081 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
1083 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1085 spin_unlock_irqrestore(&wl->lock, irqflag);
1086 pr_debug("%s: ->\n", __func__);
1090 static int gelic_wl_get_encode(struct net_device *netdev,
1091 struct iw_request_info *info,
1092 union iwreq_data *data, char *extra)
1094 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1095 struct iw_point *enc = &data->encoding;
1096 unsigned long irqflag;
1097 unsigned int key_index, index_specified;
1100 pr_debug("%s: <-\n", __func__);
1101 key_index = enc->flags & IW_ENCODE_INDEX;
1102 pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
1103 enc->flags, enc->pointer, enc->length, extra);
1104 if (GELIC_WEP_KEYS < key_index)
1107 spin_lock_irqsave(&wl->lock, irqflag);
1109 index_specified = 1;
1112 index_specified = 0;
1113 key_index = wl->current_key;
1116 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1117 switch (wl->auth_method) {
1118 case GELIC_EURUS_AUTH_OPEN:
1119 enc->flags = IW_ENCODE_OPEN;
1121 case GELIC_EURUS_AUTH_SHARED:
1122 enc->flags = IW_ENCODE_RESTRICTED;
1126 enc->flags = IW_ENCODE_DISABLED;
1128 if (test_bit(key_index, &wl->key_enabled)) {
1129 if (enc->length < wl->key_len[key_index]) {
1133 enc->length = wl->key_len[key_index];
1134 memcpy(extra, wl->key[key_index], wl->key_len[key_index]);
1137 enc->flags |= IW_ENCODE_NOKEY;
1139 enc->flags |= key_index + 1;
1140 pr_debug("%s: -> flag=%x len=%d\n", __func__,
1141 enc->flags, enc->length);
1144 spin_unlock_irqrestore(&wl->lock, irqflag);
1149 static int gelic_wl_set_ap(struct net_device *netdev,
1150 struct iw_request_info *info,
1151 union iwreq_data *data, char *extra)
1153 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1154 unsigned long irqflag;
1156 pr_debug("%s: <-\n", __func__);
1157 if (data->ap_addr.sa_family != ARPHRD_ETHER)
1160 spin_lock_irqsave(&wl->lock, irqflag);
1161 if (is_valid_ether_addr(data->ap_addr.sa_data)) {
1162 memcpy(wl->bssid, data->ap_addr.sa_data,
1164 set_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1165 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1166 pr_debug("%s: bss=%pM\n", __func__, wl->bssid);
1168 pr_debug("%s: clear bssid\n", __func__);
1169 clear_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1170 eth_zero_addr(wl->bssid);
1172 spin_unlock_irqrestore(&wl->lock, irqflag);
1173 pr_debug("%s: ->\n", __func__);
1177 static int gelic_wl_get_ap(struct net_device *netdev,
1178 struct iw_request_info *info,
1179 union iwreq_data *data, char *extra)
1181 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1182 unsigned long irqflag;
1184 pr_debug("%s: <-\n", __func__);
1185 mutex_lock(&wl->assoc_stat_lock);
1186 spin_lock_irqsave(&wl->lock, irqflag);
1187 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1188 data->ap_addr.sa_family = ARPHRD_ETHER;
1189 memcpy(data->ap_addr.sa_data, wl->active_bssid,
1192 eth_zero_addr(data->ap_addr.sa_data);
1194 spin_unlock_irqrestore(&wl->lock, irqflag);
1195 mutex_unlock(&wl->assoc_stat_lock);
1196 pr_debug("%s: ->\n", __func__);
1200 /* SIOC{S,G}IWENCODEEXT */
1201 static int gelic_wl_set_encodeext(struct net_device *netdev,
1202 struct iw_request_info *info,
1203 union iwreq_data *data, char *extra)
1205 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1206 struct iw_point *enc = &data->encoding;
1207 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1210 unsigned long irqflag;
1214 pr_debug("%s: <-\n", __func__);
1215 flags = enc->flags & IW_ENCODE_FLAGS;
1217 key_index = enc->flags & IW_ENCODE_INDEX;
1219 pr_debug("%s: key_index = %d\n", __func__, key_index);
1220 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1221 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1222 pr_debug("%s: ext_flag=%x\n", __func__, ext->ext_flags);
1223 pr_debug("%s: ext_key_len=%x\n", __func__, ext->key_len);
1225 if (GELIC_WEP_KEYS < key_index)
1228 spin_lock_irqsave(&wl->lock, irqflag);
1232 key_index = wl->current_key;
1234 if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
1235 /* reques to change default key index */
1236 pr_debug("%s: request to change default key to %d\n",
1237 __func__, key_index);
1238 wl->current_key = key_index;
1242 if (alg == IW_ENCODE_ALG_NONE || (flags & IW_ENCODE_DISABLED)) {
1243 pr_debug("%s: alg disabled\n", __func__);
1244 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
1245 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1246 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
1247 wl->auth_method = GELIC_EURUS_AUTH_OPEN; /* should be open */
1248 } else if (alg == IW_ENCODE_ALG_WEP) {
1249 pr_debug("%s: WEP requested\n", __func__);
1250 if (flags & IW_ENCODE_OPEN) {
1251 pr_debug("%s: open key mode\n", __func__);
1252 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1254 if (flags & IW_ENCODE_RESTRICTED) {
1255 pr_debug("%s: shared key mode\n", __func__);
1256 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1258 if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
1259 pr_info("%s: key is too long %d\n", __func__,
1264 /* OK, update the key */
1265 wl->key_len[key_index] = ext->key_len;
1266 memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
1267 memcpy(wl->key[key_index], ext->key, ext->key_len);
1268 set_bit(key_index, &wl->key_enabled);
1269 /* remember wep info changed */
1270 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1271 } else if (alg == IW_ENCODE_ALG_PMK) {
1272 if (ext->key_len != WPA_PSK_LEN) {
1273 pr_err("%s: PSK length wrong %d\n", __func__,
1278 memset(wl->psk, 0, sizeof(wl->psk));
1279 memcpy(wl->psk, ext->key, ext->key_len);
1280 wl->psk_len = ext->key_len;
1281 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1282 /* remember PSK configured */
1283 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1286 spin_unlock_irqrestore(&wl->lock, irqflag);
1287 pr_debug("%s: ->\n", __func__);
1291 static int gelic_wl_get_encodeext(struct net_device *netdev,
1292 struct iw_request_info *info,
1293 union iwreq_data *data, char *extra)
1295 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1296 struct iw_point *enc = &data->encoding;
1297 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1298 unsigned long irqflag;
1303 pr_debug("%s: <-\n", __func__);
1305 max_key_len = enc->length - sizeof(struct iw_encode_ext);
1306 if (max_key_len < 0)
1308 key_index = enc->flags & IW_ENCODE_INDEX;
1310 pr_debug("%s: key_index = %d\n", __func__, key_index);
1311 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1312 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1314 if (GELIC_WEP_KEYS < key_index)
1317 spin_lock_irqsave(&wl->lock, irqflag);
1321 key_index = wl->current_key;
1323 memset(ext, 0, sizeof(struct iw_encode_ext));
1324 switch (wl->group_cipher_method) {
1325 case GELIC_WL_CIPHER_WEP:
1326 ext->alg = IW_ENCODE_ALG_WEP;
1327 enc->flags |= IW_ENCODE_ENABLED;
1329 case GELIC_WL_CIPHER_TKIP:
1330 ext->alg = IW_ENCODE_ALG_TKIP;
1331 enc->flags |= IW_ENCODE_ENABLED;
1333 case GELIC_WL_CIPHER_AES:
1334 ext->alg = IW_ENCODE_ALG_CCMP;
1335 enc->flags |= IW_ENCODE_ENABLED;
1337 case GELIC_WL_CIPHER_NONE:
1339 ext->alg = IW_ENCODE_ALG_NONE;
1340 enc->flags |= IW_ENCODE_NOKEY;
1344 if (!(enc->flags & IW_ENCODE_NOKEY)) {
1345 if (max_key_len < wl->key_len[key_index]) {
1349 if (test_bit(key_index, &wl->key_enabled))
1350 memcpy(ext->key, wl->key[key_index],
1351 wl->key_len[key_index]);
1353 pr_debug("%s: disabled key requested ix=%d\n",
1354 __func__, key_index);
1357 spin_unlock_irqrestore(&wl->lock, irqflag);
1358 pr_debug("%s: ->\n", __func__);
1361 /* SIOC{S,G}IWMODE */
1362 static int gelic_wl_set_mode(struct net_device *netdev,
1363 struct iw_request_info *info,
1364 union iwreq_data *data, char *extra)
1366 __u32 mode = data->mode;
1369 pr_debug("%s: <-\n", __func__);
1370 if (mode == IW_MODE_INFRA)
1374 pr_debug("%s: -> %d\n", __func__, ret);
1378 static int gelic_wl_get_mode(struct net_device *netdev,
1379 struct iw_request_info *info,
1380 union iwreq_data *data, char *extra)
1382 __u32 *mode = &data->mode;
1383 pr_debug("%s: <-\n", __func__);
1384 *mode = IW_MODE_INFRA;
1385 pr_debug("%s: ->\n", __func__);
1390 static int gelic_wl_get_nick(struct net_device *net_dev,
1391 struct iw_request_info *info,
1392 union iwreq_data *data, char *extra)
1394 strcpy(extra, "gelic_wl");
1395 data->data.length = strlen(extra);
1396 data->data.flags = 1;
1403 static struct iw_statistics *gelic_wl_get_wireless_stats(
1404 struct net_device *netdev)
1407 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1408 struct gelic_eurus_cmd *cmd;
1409 struct iw_statistics *is;
1410 struct gelic_eurus_rssi_info *rssi;
1413 pr_debug("%s: <-\n", __func__);
1415 buf = (void *)__get_free_page(GFP_KERNEL);
1420 memset(is, 0, sizeof(*is));
1421 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
1422 buf, sizeof(*rssi));
1423 if (cmd && !cmd->status && !cmd->cmd_status) {
1425 is->qual.level = be16_to_cpu(rssi->rssi);
1426 is->qual.updated = IW_QUAL_LEVEL_UPDATED |
1427 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
1429 /* not associated */
1430 is->qual.updated = IW_QUAL_ALL_INVALID;
1433 free_page((unsigned long)buf);
1434 pr_debug("%s: ->\n", __func__);
1441 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
1442 u8 *essid, size_t essid_len)
1444 struct gelic_eurus_cmd *cmd;
1449 pr_debug("%s: <- always=%d\n", __func__, always_scan);
1450 if (mutex_lock_interruptible(&wl->scan_lock))
1451 return -ERESTARTSYS;
1454 * If already a scan in progress, do not trigger more
1456 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING) {
1457 pr_debug("%s: scanning now\n", __func__);
1461 init_completion(&wl->scan_done);
1463 * If we have already a bss list, don't try to get new
1464 * unless we are doing an ESSID scan
1466 if ((!essid_len && !always_scan)
1467 && wl->scan_stat == GELIC_WL_SCAN_STAT_GOT_LIST) {
1468 pr_debug("%s: already has the list\n", __func__);
1469 complete(&wl->scan_done);
1474 if (essid_len && essid) {
1475 buf = (void *)__get_free_page(GFP_KERNEL);
1480 len = IW_ESSID_MAX_SIZE; /* hypervisor always requires 32 */
1481 memset(buf, 0, len);
1482 memcpy(buf, essid, essid_len);
1483 pr_debug("%s: essid scan='%s'\n", __func__, (char *)buf);
1488 * issue start scan request
1490 wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
1491 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
1493 if (!cmd || cmd->status || cmd->cmd_status) {
1494 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1495 complete(&wl->scan_done);
1501 free_page((unsigned long)buf);
1502 mutex_unlock(&wl->scan_lock);
1503 pr_debug("%s: ->\n", __func__);
1508 * retrieve scan result from the chip (hypervisor)
1509 * this function is invoked by schedule work.
1511 static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
1513 struct gelic_eurus_cmd *cmd = NULL;
1514 struct gelic_wl_scan_info *target, *tmp;
1515 struct gelic_wl_scan_info *oldest = NULL;
1516 struct gelic_eurus_scan_info *scan_info;
1517 unsigned int scan_info_size;
1518 union iwreq_data data;
1519 unsigned long this_time = jiffies;
1520 unsigned int data_len, i, found, r;
1523 pr_debug("%s:start\n", __func__);
1524 mutex_lock(&wl->scan_lock);
1526 buf = (void *)__get_free_page(GFP_KERNEL);
1528 pr_info("%s: scan buffer alloc failed\n", __func__);
1532 if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
1534 * stop() may be called while scanning, ignore result
1536 pr_debug("%s: scan complete when stat != scanning(%d)\n",
1537 __func__, wl->scan_stat);
1541 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
1543 if (!cmd || cmd->status || cmd->cmd_status) {
1544 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1545 pr_info("%s:cmd failed\n", __func__);
1549 data_len = cmd->size;
1550 pr_debug("%s: data_len = %d\n", __func__, data_len);
1553 /* OK, bss list retrieved */
1554 wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST;
1556 /* mark all entries are old */
1557 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
1559 /* expire too old entries */
1560 if (time_before(target->last_scanned + wl->scan_age,
1562 kfree(target->hwinfo);
1563 target->hwinfo = NULL;
1564 list_move_tail(&target->list, &wl->network_free_list);
1568 /* put them in the network_list */
1569 for (i = 0, scan_info_size = 0, scan_info = buf;
1570 scan_info_size < data_len;
1571 i++, scan_info_size += be16_to_cpu(scan_info->size),
1572 scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
1573 pr_debug("%s:size=%d bssid=%pM scan_info=%p\n", __func__,
1574 be16_to_cpu(scan_info->size),
1575 &scan_info->bssid[2], scan_info);
1578 * The wireless firmware may return invalid channel 0 and/or
1579 * invalid rate if the AP emits zero length SSID ie. As this
1580 * scan information is useless, ignore it
1582 if (!be16_to_cpu(scan_info->channel) || !scan_info->rate[0]) {
1583 pr_debug("%s: invalid scan info\n", __func__);
1589 list_for_each_entry(target, &wl->network_list, list) {
1590 if (ether_addr_equal(&target->hwinfo->bssid[2],
1591 &scan_info->bssid[2])) {
1593 pr_debug("%s: same BBS found scanned list\n",
1598 (target->last_scanned < oldest->last_scanned))
1603 /* not found in the list */
1604 if (list_empty(&wl->network_free_list)) {
1608 target = list_entry(wl->network_free_list.next,
1609 struct gelic_wl_scan_info,
1614 /* update the item */
1615 target->last_scanned = this_time;
1617 target->eurus_index = i;
1618 kfree(target->hwinfo);
1619 target->hwinfo = kmemdup(scan_info,
1620 be16_to_cpu(scan_info->size),
1622 if (!target->hwinfo)
1625 /* copy hw scan info */
1626 target->essid_len = strnlen(scan_info->essid,
1627 sizeof(scan_info->essid));
1628 target->rate_len = 0;
1629 for (r = 0; r < 12; r++)
1630 if (scan_info->rate[r])
1632 if (8 < target->rate_len)
1633 pr_info("%s: AP returns %d rates\n", __func__,
1635 target->rate_ext_len = 0;
1636 for (r = 0; r < 16; r++)
1637 if (scan_info->ext_rate[r])
1638 target->rate_ext_len++;
1639 list_move_tail(&target->list, &wl->network_list);
1641 memset(&data, 0, sizeof(data));
1642 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
1645 free_page((unsigned long)buf);
1646 complete(&wl->scan_done);
1647 mutex_unlock(&wl->scan_lock);
1648 pr_debug("%s:end\n", __func__);
1652 * Select an appropriate bss from current scan list regarding
1653 * current settings from userspace.
1654 * The caller must hold wl->scan_lock,
1655 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1657 static void update_best(struct gelic_wl_scan_info **best,
1658 struct gelic_wl_scan_info *candid,
1662 if (*best_weight < ++(*weight)) {
1663 *best_weight = *weight;
1669 struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
1671 struct gelic_wl_scan_info *scan_info;
1672 struct gelic_wl_scan_info *best_bss;
1673 int weight, best_weight;
1676 pr_debug("%s: <-\n", __func__);
1681 list_for_each_entry(scan_info, &wl->network_list, list) {
1682 pr_debug("%s: station %p\n", __func__, scan_info);
1684 if (!scan_info->valid) {
1685 pr_debug("%s: station invalid\n", __func__);
1689 /* If bss specified, check it only */
1690 if (test_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat)) {
1691 if (ether_addr_equal(&scan_info->hwinfo->bssid[2],
1693 best_bss = scan_info;
1694 pr_debug("%s: bssid matched\n", __func__);
1697 pr_debug("%s: bssid unmatched\n", __func__);
1705 security = be16_to_cpu(scan_info->hwinfo->security) &
1706 GELIC_EURUS_SCAN_SEC_MASK;
1707 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1708 if (security == GELIC_EURUS_SCAN_SEC_WPA2)
1709 update_best(&best_bss, scan_info,
1710 &best_weight, &weight);
1713 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA) {
1714 if (security == GELIC_EURUS_SCAN_SEC_WPA)
1715 update_best(&best_bss, scan_info,
1716 &best_weight, &weight);
1719 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_NONE &&
1720 wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1721 if (security == GELIC_EURUS_SCAN_SEC_WEP)
1722 update_best(&best_bss, scan_info,
1723 &best_weight, &weight);
1728 /* If ESSID is set, check it */
1729 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
1730 if ((scan_info->essid_len == wl->essid_len) &&
1732 scan_info->hwinfo->essid,
1733 scan_info->essid_len))
1734 update_best(&best_bss, scan_info,
1735 &best_weight, &weight);
1742 pr_debug("%s: -> bss=%p\n", __func__, best_bss);
1744 pr_debug("%s:addr=%pM\n", __func__,
1745 &best_bss->hwinfo->bssid[2]);
1752 * Setup WEP configuration to the chip
1753 * The caller must hold wl->scan_lock,
1754 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1756 static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
1759 struct gelic_eurus_wep_cfg *wep;
1760 struct gelic_eurus_cmd *cmd;
1765 pr_debug("%s: <-\n", __func__);
1766 /* we can assume no one should uses the buffer */
1767 wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
1771 memset(wep, 0, sizeof(*wep));
1773 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1774 pr_debug("%s: WEP mode\n", __func__);
1775 for (i = 0; i < GELIC_WEP_KEYS; i++) {
1776 if (!test_bit(i, &wl->key_enabled))
1779 pr_debug("%s: key#%d enabled\n", __func__, i);
1781 if (wl->key_len[i] == 13)
1783 else if (wl->key_len[i] != 5) {
1784 pr_info("%s: wrong wep key[%d]=%d\n",
1785 __func__, i, wl->key_len[i]);
1789 memcpy(wep->key[i], wl->key[i], wl->key_len[i]);
1793 pr_info("%s: all wep key disabled\n", __func__);
1799 pr_debug("%s: 104bit key\n", __func__);
1800 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT);
1802 pr_debug("%s: 40bit key\n", __func__);
1803 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT);
1806 pr_debug("%s: NO encryption\n", __func__);
1807 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE);
1810 /* issue wep setup */
1811 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WEP_CFG,
1815 else if (cmd->status || cmd->cmd_status)
1820 free_page((unsigned long)wep);
1821 pr_debug("%s: ->\n", __func__);
1826 static const char *wpasecstr(enum gelic_eurus_wpa_security sec)
1829 case GELIC_EURUS_WPA_SEC_NONE:
1831 case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP:
1832 return "WPA_TKIP_TKIP";
1833 case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES:
1834 return "WPA_TKIP_AES";
1835 case GELIC_EURUS_WPA_SEC_WPA_AES_AES:
1836 return "WPA_AES_AES";
1837 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP:
1838 return "WPA2_TKIP_TKIP";
1839 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES:
1840 return "WPA2_TKIP_AES";
1841 case GELIC_EURUS_WPA_SEC_WPA2_AES_AES:
1842 return "WPA2_AES_AES";
1848 static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
1850 struct gelic_eurus_wpa_cfg *wpa;
1851 struct gelic_eurus_cmd *cmd;
1855 pr_debug("%s: <-\n", __func__);
1856 /* we can assume no one should uses the buffer */
1857 wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
1861 memset(wpa, 0, sizeof(*wpa));
1863 if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
1864 pr_info("%s: PSK not configured yet\n", __func__);
1867 memcpy(wpa->psk, wl->psk, wl->psk_len);
1869 /* set security level */
1870 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1871 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1872 security = GELIC_EURUS_WPA_SEC_WPA2_AES_AES;
1874 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1876 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES;
1878 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP;
1881 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1882 security = GELIC_EURUS_WPA_SEC_WPA_AES_AES;
1884 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1886 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_AES;
1888 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP;
1891 wpa->security = cpu_to_be16(security);
1894 wpa->psk_type = cpu_to_be16(wl->psk_type);
1896 pr_debug("%s: sec=%s psktype=%s\n", __func__,
1897 wpasecstr(wpa->security),
1898 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1899 "BIN" : "passphrase");
1902 * don't enable here if you plan to submit
1903 * the debug log because this dumps your precious
1906 pr_debug("%s: psk=%s\n", __func__,
1907 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1911 /* issue wpa setup */
1912 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WPA_CFG,
1916 else if (cmd->status || cmd->cmd_status)
1919 free_page((unsigned long)wpa);
1920 pr_debug("%s: --> %d\n", __func__, ret);
1925 * Start association. caller must hold assoc_stat_lock
1927 static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
1928 struct gelic_wl_scan_info *bss)
1930 struct gelic_eurus_cmd *cmd;
1931 struct gelic_eurus_common_cfg *common;
1935 pr_debug("%s: <-\n", __func__);
1937 /* do common config */
1938 common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
1942 memset(common, 0, sizeof(*common));
1943 common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
1944 common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
1946 common->scan_index = cpu_to_be16(bss->eurus_index);
1947 switch (wl->auth_method) {
1948 case GELIC_EURUS_AUTH_OPEN:
1949 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_OPEN);
1951 case GELIC_EURUS_AUTH_SHARED:
1952 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_SHARED);
1959 pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
1960 be16_to_cpu(common->scan_index),
1961 be16_to_cpu(common->bss_type),
1962 be16_to_cpu(common->auth_method));
1964 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_COMMON_CFG,
1965 common, sizeof(*common));
1966 if (!cmd || cmd->status || cmd->cmd_status) {
1974 switch (wl->wpa_level) {
1975 case GELIC_WL_WPA_LEVEL_NONE:
1976 /* If WEP or no security, setup WEP config */
1977 ret = gelic_wl_do_wep_setup(wl);
1979 case GELIC_WL_WPA_LEVEL_WPA:
1980 case GELIC_WL_WPA_LEVEL_WPA2:
1981 ret = gelic_wl_do_wpa_setup(wl);
1986 pr_debug("%s: WEP/WPA setup failed %d\n", __func__,
1989 gelic_wl_send_iwap_event(wl, NULL);
1993 /* start association */
1994 init_completion(&wl->assoc_done);
1995 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATING;
1996 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_ASSOC,
1998 if (!cmd || cmd->status || cmd->cmd_status) {
1999 pr_debug("%s: assoc request failed\n", __func__);
2000 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2003 gelic_wl_send_iwap_event(wl, NULL);
2008 /* wait for connected event */
2009 rc = wait_for_completion_timeout(&wl->assoc_done, HZ * 4);/*FIXME*/
2012 /* timeouted. Maybe key or cyrpt mode is wrong */
2013 pr_info("%s: connect timeout\n", __func__);
2014 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC,
2017 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2018 gelic_wl_send_iwap_event(wl, NULL);
2021 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATED;
2023 memcpy(wl->active_bssid, &bss->hwinfo->bssid[2], ETH_ALEN);
2025 /* send connect event */
2026 gelic_wl_send_iwap_event(wl, wl->active_bssid);
2027 pr_info("%s: connected\n", __func__);
2030 free_page((unsigned long)common);
2031 pr_debug("%s: ->\n", __func__);
2038 static void gelic_wl_connected_event(struct gelic_wl_info *wl,
2041 u64 desired_event = 0;
2043 switch (wl->wpa_level) {
2044 case GELIC_WL_WPA_LEVEL_NONE:
2045 desired_event = GELIC_LV1_WL_EVENT_CONNECTED;
2047 case GELIC_WL_WPA_LEVEL_WPA:
2048 case GELIC_WL_WPA_LEVEL_WPA2:
2049 desired_event = GELIC_LV1_WL_EVENT_WPA_CONNECTED;
2053 if (desired_event == event) {
2054 pr_debug("%s: completed\n", __func__);
2055 complete(&wl->assoc_done);
2056 netif_carrier_on(port_to_netdev(wl_port(wl)));
2058 pr_debug("%s: event %#llx under wpa\n",
2065 static void gelic_wl_disconnect_event(struct gelic_wl_info *wl,
2068 struct gelic_eurus_cmd *cmd;
2072 * If we fall here in the middle of association,
2073 * associate_bss() should be waiting for complation of
2075 * As it waits with timeout, just leave assoc_done
2076 * uncompleted, then it terminates with timeout
2078 if (!mutex_trylock(&wl->assoc_stat_lock)) {
2079 pr_debug("%s: already locked\n", __func__);
2082 pr_debug("%s: obtain lock\n", __func__);
2086 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2089 /* send disconnected event to the supplicant */
2090 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2091 gelic_wl_send_iwap_event(wl, NULL);
2093 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2094 netif_carrier_off(port_to_netdev(wl_port(wl)));
2097 mutex_unlock(&wl->assoc_stat_lock);
2103 static const char *eventstr(enum gelic_lv1_wl_event event)
2105 static char buf[32];
2107 if (event & GELIC_LV1_WL_EVENT_DEVICE_READY)
2108 ret = "EURUS_READY";
2109 else if (event & GELIC_LV1_WL_EVENT_SCAN_COMPLETED)
2110 ret = "SCAN_COMPLETED";
2111 else if (event & GELIC_LV1_WL_EVENT_DEAUTH)
2113 else if (event & GELIC_LV1_WL_EVENT_BEACON_LOST)
2114 ret = "BEACON_LOST";
2115 else if (event & GELIC_LV1_WL_EVENT_CONNECTED)
2117 else if (event & GELIC_LV1_WL_EVENT_WPA_CONNECTED)
2118 ret = "WPA_CONNECTED";
2119 else if (event & GELIC_LV1_WL_EVENT_WPA_ERROR)
2122 sprintf(buf, "Unknown(%#x)", event);
2128 static const char *eventstr(enum gelic_lv1_wl_event event)
2133 static void gelic_wl_event_worker(struct work_struct *work)
2135 struct gelic_wl_info *wl;
2136 struct gelic_port *port;
2140 pr_debug("%s:start\n", __func__);
2141 wl = container_of(work, struct gelic_wl_info, event_work.work);
2144 status = lv1_net_control(bus_id(port->card), dev_id(port->card),
2145 GELIC_LV1_GET_WLAN_EVENT, 0, 0, 0,
2148 if (status != LV1_NO_ENTRY)
2149 pr_debug("%s:wlan event failed %d\n",
2151 /* got all events */
2152 pr_debug("%s:end\n", __func__);
2155 pr_debug("%s: event=%s\n", __func__, eventstr(event));
2157 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
2158 gelic_wl_scan_complete_event(wl);
2160 case GELIC_LV1_WL_EVENT_BEACON_LOST:
2161 case GELIC_LV1_WL_EVENT_DEAUTH:
2162 gelic_wl_disconnect_event(wl, event);
2164 case GELIC_LV1_WL_EVENT_CONNECTED:
2165 case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
2166 gelic_wl_connected_event(wl, event);
2174 * association worker
2176 static void gelic_wl_assoc_worker(struct work_struct *work)
2178 struct gelic_wl_info *wl;
2180 struct gelic_wl_scan_info *best_bss;
2182 unsigned long irqflag;
2186 wl = container_of(work, struct gelic_wl_info, assoc_work.work);
2188 mutex_lock(&wl->assoc_stat_lock);
2190 if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
2193 spin_lock_irqsave(&wl->lock, irqflag);
2194 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
2195 pr_debug("%s: assoc ESSID configured %s\n", __func__,
2198 essid_len = wl->essid_len;
2203 spin_unlock_irqrestore(&wl->lock, irqflag);
2205 ret = gelic_wl_start_scan(wl, 0, essid, essid_len);
2206 if (ret == -ERESTARTSYS) {
2207 pr_debug("%s: scan start failed association\n", __func__);
2208 schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
2211 pr_info("%s: scan prerequisite failed\n", __func__);
2216 * Wait for bss scan completion
2217 * If we have scan list already, gelic_wl_start_scan()
2218 * returns OK and raises the complete. Thus,
2219 * it's ok to wait unconditionally here
2221 wait_for_completion(&wl->scan_done);
2223 pr_debug("%s: scan done\n", __func__);
2224 mutex_lock(&wl->scan_lock);
2225 if (wl->scan_stat != GELIC_WL_SCAN_STAT_GOT_LIST) {
2226 gelic_wl_send_iwap_event(wl, NULL);
2227 pr_info("%s: no scan list. association failed\n", __func__);
2231 /* find best matching bss */
2232 best_bss = gelic_wl_find_best_bss(wl);
2234 gelic_wl_send_iwap_event(wl, NULL);
2235 pr_info("%s: no bss matched. association failed\n", __func__);
2239 /* ok, do association */
2240 ret = gelic_wl_associate_bss(wl, best_bss);
2242 pr_info("%s: association failed %d\n", __func__, ret);
2244 mutex_unlock(&wl->scan_lock);
2246 mutex_unlock(&wl->assoc_stat_lock);
2250 * Called from the ethernet interrupt handler
2251 * Processes wireless specific virtual interrupts only
2253 void gelic_wl_interrupt(struct net_device *netdev, u64 status)
2255 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2257 if (status & GELIC_CARD_WLAN_COMMAND_COMPLETED) {
2258 pr_debug("%s:cmd complete\n", __func__);
2259 complete(&wl->cmd_done_intr);
2262 if (status & GELIC_CARD_WLAN_EVENT_RECEIVED) {
2263 pr_debug("%s:event received\n", __func__);
2264 queue_delayed_work(wl->event_queue, &wl->event_work, 0);
2271 static const iw_handler gelic_wl_wext_handler[] =
2273 IW_HANDLER(SIOCGIWNAME, gelic_wl_get_name),
2274 IW_HANDLER(SIOCGIWRANGE, gelic_wl_get_range),
2275 IW_HANDLER(SIOCSIWSCAN, gelic_wl_set_scan),
2276 IW_HANDLER(SIOCGIWSCAN, gelic_wl_get_scan),
2277 IW_HANDLER(SIOCSIWAUTH, gelic_wl_set_auth),
2278 IW_HANDLER(SIOCGIWAUTH, gelic_wl_get_auth),
2279 IW_HANDLER(SIOCSIWESSID, gelic_wl_set_essid),
2280 IW_HANDLER(SIOCGIWESSID, gelic_wl_get_essid),
2281 IW_HANDLER(SIOCSIWENCODE, gelic_wl_set_encode),
2282 IW_HANDLER(SIOCGIWENCODE, gelic_wl_get_encode),
2283 IW_HANDLER(SIOCSIWAP, gelic_wl_set_ap),
2284 IW_HANDLER(SIOCGIWAP, gelic_wl_get_ap),
2285 IW_HANDLER(SIOCSIWENCODEEXT, gelic_wl_set_encodeext),
2286 IW_HANDLER(SIOCGIWENCODEEXT, gelic_wl_get_encodeext),
2287 IW_HANDLER(SIOCSIWMODE, gelic_wl_set_mode),
2288 IW_HANDLER(SIOCGIWMODE, gelic_wl_get_mode),
2289 IW_HANDLER(SIOCGIWNICKN, gelic_wl_get_nick),
2292 static const struct iw_handler_def gelic_wl_wext_handler_def = {
2293 .num_standard = ARRAY_SIZE(gelic_wl_wext_handler),
2294 .standard = gelic_wl_wext_handler,
2295 .get_wireless_stats = gelic_wl_get_wireless_stats,
2298 static struct net_device *gelic_wl_alloc(struct gelic_card *card)
2300 struct net_device *netdev;
2301 struct gelic_port *port;
2302 struct gelic_wl_info *wl;
2305 pr_debug("%s:start\n", __func__);
2306 netdev = alloc_etherdev(sizeof(struct gelic_port) +
2307 sizeof(struct gelic_wl_info));
2308 pr_debug("%s: netdev =%p card=%p\n", __func__, netdev, card);
2312 strcpy(netdev->name, "wlan%d");
2314 port = netdev_priv(netdev);
2315 port->netdev = netdev;
2317 port->type = GELIC_PORT_WIRELESS;
2320 pr_debug("%s: wl=%p port=%p\n", __func__, wl, port);
2322 /* allocate scan list */
2323 wl->networks = kzalloc(sizeof(struct gelic_wl_scan_info) *
2324 GELIC_WL_BSS_MAX_ENT, GFP_KERNEL);
2329 wl->eurus_cmd_queue = create_singlethread_workqueue("gelic_cmd");
2330 if (!wl->eurus_cmd_queue)
2331 goto fail_cmd_workqueue;
2333 wl->event_queue = create_singlethread_workqueue("gelic_event");
2334 if (!wl->event_queue)
2335 goto fail_event_workqueue;
2337 INIT_LIST_HEAD(&wl->network_free_list);
2338 INIT_LIST_HEAD(&wl->network_list);
2339 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++)
2340 list_add_tail(&wl->networks[i].list,
2341 &wl->network_free_list);
2342 init_completion(&wl->cmd_done_intr);
2344 INIT_DELAYED_WORK(&wl->event_work, gelic_wl_event_worker);
2345 INIT_DELAYED_WORK(&wl->assoc_work, gelic_wl_assoc_worker);
2346 mutex_init(&wl->scan_lock);
2347 mutex_init(&wl->assoc_stat_lock);
2349 init_completion(&wl->scan_done);
2350 /* for the case that no scan request is issued and stop() is called */
2351 complete(&wl->scan_done);
2353 spin_lock_init(&wl->lock);
2355 wl->scan_age = 5*HZ; /* FIXME */
2357 /* buffer for receiving scanned list etc */
2358 BUILD_BUG_ON(PAGE_SIZE <
2359 sizeof(struct gelic_eurus_scan_info) *
2360 GELIC_EURUS_MAX_SCAN);
2361 pr_debug("%s:end\n", __func__);
2364 fail_event_workqueue:
2365 destroy_workqueue(wl->eurus_cmd_queue);
2367 kfree(wl->networks);
2369 free_netdev(netdev);
2370 pr_debug("%s:end error\n", __func__);
2375 static void gelic_wl_free(struct gelic_wl_info *wl)
2377 struct gelic_wl_scan_info *scan_info;
2380 pr_debug("%s: <-\n", __func__);
2382 pr_debug("%s: destroy queues\n", __func__);
2383 destroy_workqueue(wl->eurus_cmd_queue);
2384 destroy_workqueue(wl->event_queue);
2386 scan_info = wl->networks;
2387 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++, scan_info++)
2388 kfree(scan_info->hwinfo);
2389 kfree(wl->networks);
2391 free_netdev(port_to_netdev(wl_port(wl)));
2393 pr_debug("%s: ->\n", __func__);
2396 static int gelic_wl_try_associate(struct net_device *netdev)
2398 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2402 pr_debug("%s: <-\n", __func__);
2404 /* check constraits for start association */
2405 /* for no access restriction AP */
2406 if (wl->group_cipher_method == GELIC_WL_CIPHER_NONE) {
2407 if (test_bit(GELIC_WL_STAT_CONFIGURED,
2411 pr_debug("%s: no wep, not configured\n", __func__);
2416 /* for WEP, one of four keys should be set */
2417 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
2418 /* one of keys set */
2419 for (i = 0; i < GELIC_WEP_KEYS; i++) {
2420 if (test_bit(i, &wl->key_enabled))
2423 pr_debug("%s: WEP, but no key specified\n", __func__);
2427 /* for WPA[2], psk should be set */
2428 if ((wl->group_cipher_method == GELIC_WL_CIPHER_TKIP) ||
2429 (wl->group_cipher_method == GELIC_WL_CIPHER_AES)) {
2430 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET,
2434 pr_debug("%s: AES/TKIP, but PSK not configured\n",
2441 ret = schedule_delayed_work(&wl->assoc_work, 0);
2442 pr_debug("%s: start association work %d\n", __func__, ret);
2449 static int gelic_wl_open(struct net_device *netdev)
2451 struct gelic_card *card = netdev_card(netdev);
2453 pr_debug("%s:->%p\n", __func__, netdev);
2455 gelic_card_up(card);
2457 /* try to associate */
2458 gelic_wl_try_associate(netdev);
2460 netif_start_queue(netdev);
2462 pr_debug("%s:<-\n", __func__);
2467 * reset state machine
2469 static int gelic_wl_reset_state(struct gelic_wl_info *wl)
2471 struct gelic_wl_scan_info *target;
2472 struct gelic_wl_scan_info *tmp;
2474 /* empty scan list */
2475 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
2476 list_move_tail(&target->list, &wl->network_free_list);
2478 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
2480 /* clear configuration */
2481 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
2482 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
2483 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
2484 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
2486 wl->key_enabled = 0;
2487 wl->current_key = 0;
2489 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
2493 memset(wl->essid, 0, sizeof(wl->essid));
2494 memset(wl->bssid, 0, sizeof(wl->bssid));
2495 memset(wl->active_bssid, 0, sizeof(wl->active_bssid));
2497 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2499 memset(&wl->iwstat, 0, sizeof(wl->iwstat));
2500 /* all status bit clear */
2506 * Tell eurus to terminate association
2508 static void gelic_wl_disconnect(struct net_device *netdev)
2510 struct gelic_port *port = netdev_priv(netdev);
2511 struct gelic_wl_info *wl = port_wl(port);
2512 struct gelic_eurus_cmd *cmd;
2515 * If scann process is running on chip,
2516 * further requests will be rejected
2518 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING)
2519 wait_for_completion_timeout(&wl->scan_done, HZ);
2521 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2523 gelic_wl_send_iwap_event(wl, NULL);
2526 static int gelic_wl_stop(struct net_device *netdev)
2528 struct gelic_port *port = netdev_priv(netdev);
2529 struct gelic_wl_info *wl = port_wl(port);
2530 struct gelic_card *card = netdev_card(netdev);
2532 pr_debug("%s:<-\n", __func__);
2535 * Cancel pending association work.
2536 * event work can run after netdev down
2538 cancel_delayed_work(&wl->assoc_work);
2540 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2541 gelic_wl_disconnect(netdev);
2543 /* reset our state machine */
2544 gelic_wl_reset_state(wl);
2546 netif_stop_queue(netdev);
2548 gelic_card_down(card);
2550 pr_debug("%s:->\n", __func__);
2556 static const struct net_device_ops gelic_wl_netdevice_ops = {
2557 .ndo_open = gelic_wl_open,
2558 .ndo_stop = gelic_wl_stop,
2559 .ndo_start_xmit = gelic_net_xmit,
2560 .ndo_set_rx_mode = gelic_net_set_multi,
2561 .ndo_tx_timeout = gelic_net_tx_timeout,
2562 .ndo_set_mac_address = eth_mac_addr,
2563 .ndo_validate_addr = eth_validate_addr,
2564 #ifdef CONFIG_NET_POLL_CONTROLLER
2565 .ndo_poll_controller = gelic_net_poll_controller,
2569 static const struct ethtool_ops gelic_wl_ethtool_ops = {
2570 .get_drvinfo = gelic_net_get_drvinfo,
2571 .get_link = gelic_wl_get_link,
2574 static void gelic_wl_setup_netdev_ops(struct net_device *netdev)
2576 struct gelic_wl_info *wl;
2577 wl = port_wl(netdev_priv(netdev));
2579 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
2581 netdev->ethtool_ops = &gelic_wl_ethtool_ops;
2582 netdev->netdev_ops = &gelic_wl_netdevice_ops;
2583 netdev->wireless_data = &wl->wireless_data;
2584 netdev->wireless_handlers = &gelic_wl_wext_handler_def;
2588 * driver probe/remove
2590 int gelic_wl_driver_probe(struct gelic_card *card)
2593 struct net_device *netdev;
2595 pr_debug("%s:start\n", __func__);
2597 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2599 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2602 /* alloc netdevice for wireless */
2603 netdev = gelic_wl_alloc(card);
2607 /* setup net_device structure */
2608 SET_NETDEV_DEV(netdev, &card->dev->core);
2609 gelic_wl_setup_netdev_ops(netdev);
2611 /* setup some of net_device and register it */
2612 ret = gelic_net_setup_netdev(netdev, card);
2615 card->netdev[GELIC_PORT_WIRELESS] = netdev;
2617 /* add enable wireless interrupt */
2618 card->irq_mask |= GELIC_CARD_WLAN_EVENT_RECEIVED |
2619 GELIC_CARD_WLAN_COMMAND_COMPLETED;
2620 /* to allow wireless commands while both interfaces are down */
2621 gelic_card_set_irq_mask(card, GELIC_CARD_WLAN_EVENT_RECEIVED |
2622 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2623 pr_debug("%s:end\n", __func__);
2627 gelic_wl_free(port_wl(netdev_port(netdev)));
2632 int gelic_wl_driver_remove(struct gelic_card *card)
2634 struct gelic_wl_info *wl;
2635 struct net_device *netdev;
2637 pr_debug("%s:start\n", __func__);
2639 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2641 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2644 netdev = card->netdev[GELIC_PORT_WIRELESS];
2645 wl = port_wl(netdev_priv(netdev));
2647 /* if the interface was not up, but associated */
2648 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2649 gelic_wl_disconnect(netdev);
2651 complete(&wl->cmd_done_intr);
2653 /* cancel all work queue */
2654 cancel_delayed_work(&wl->assoc_work);
2655 cancel_delayed_work(&wl->event_work);
2656 flush_workqueue(wl->eurus_cmd_queue);
2657 flush_workqueue(wl->event_queue);
2659 unregister_netdev(netdev);
2661 /* disable wireless interrupt */
2662 pr_debug("%s: disable intr\n", __func__);
2663 card->irq_mask &= ~(GELIC_CARD_WLAN_EVENT_RECEIVED |
2664 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2665 /* free bss list, netdev*/
2667 pr_debug("%s:end\n", __func__);