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/ieee80211.h>
34 #include <linux/if_arp.h>
35 #include <linux/ctype.h>
36 #include <linux/string.h>
37 #include <net/iw_handler.h>
39 #include <linux/dma-mapping.h>
40 #include <net/checksum.h>
41 #include <asm/firmware.h>
43 #include <asm/lv1call.h>
45 #include "ps3_gelic_net.h"
46 #include "ps3_gelic_wireless.h"
49 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
50 u8 *essid, size_t essid_len);
51 static int gelic_wl_try_associate(struct net_device *netdev);
57 /* 802.11b/g channel to freq in MHz */
58 static const int channel_freq[] = {
59 2412, 2417, 2422, 2427, 2432,
60 2437, 2442, 2447, 2452, 2457,
61 2462, 2467, 2472, 2484
63 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
66 static const int bitrate_list[] = {
80 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
83 * wpa2 support requires the hypervisor version 2.0 or later
85 static inline int wpa2_capable(void)
87 return (0 <= ps3_compare_firmware_version(2, 0, 0));
90 static inline int precise_ie(void)
92 return (0 <= ps3_compare_firmware_version(2, 2, 0));
95 * post_eurus_cmd helpers
97 struct eurus_cmd_arg_info {
98 int pre_arg; /* command requres arg1, arg2 at POST COMMAND */
99 int post_arg; /* command requires arg1, arg2 at GET_RESULT */
102 static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
103 [GELIC_EURUS_CMD_SET_COMMON_CFG] = { .pre_arg = 1},
104 [GELIC_EURUS_CMD_SET_WEP_CFG] = { .pre_arg = 1},
105 [GELIC_EURUS_CMD_SET_WPA_CFG] = { .pre_arg = 1},
106 [GELIC_EURUS_CMD_GET_COMMON_CFG] = { .post_arg = 1},
107 [GELIC_EURUS_CMD_GET_WEP_CFG] = { .post_arg = 1},
108 [GELIC_EURUS_CMD_GET_WPA_CFG] = { .post_arg = 1},
109 [GELIC_EURUS_CMD_GET_RSSI_CFG] = { .post_arg = 1},
110 [GELIC_EURUS_CMD_START_SCAN] = { .pre_arg = 1},
111 [GELIC_EURUS_CMD_GET_SCAN] = { .post_arg = 1},
115 static const char *cmdstr(enum gelic_eurus_command ix)
118 case GELIC_EURUS_CMD_ASSOC:
120 case GELIC_EURUS_CMD_DISASSOC:
122 case GELIC_EURUS_CMD_START_SCAN:
124 case GELIC_EURUS_CMD_GET_SCAN:
126 case GELIC_EURUS_CMD_SET_COMMON_CFG:
127 return "SET_COMMON_CFG";
128 case GELIC_EURUS_CMD_GET_COMMON_CFG:
129 return "GET_COMMON_CFG";
130 case GELIC_EURUS_CMD_SET_WEP_CFG:
131 return "SET_WEP_CFG";
132 case GELIC_EURUS_CMD_GET_WEP_CFG:
133 return "GET_WEP_CFG";
134 case GELIC_EURUS_CMD_SET_WPA_CFG:
135 return "SET_WPA_CFG";
136 case GELIC_EURUS_CMD_GET_WPA_CFG:
137 return "GET_WPA_CFG";
138 case GELIC_EURUS_CMD_GET_RSSI_CFG:
146 static inline const char *cmdstr(enum gelic_eurus_command ix)
152 /* synchronously do eurus commands */
153 static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
155 struct gelic_eurus_cmd *cmd;
156 struct gelic_card *card;
157 struct gelic_wl_info *wl;
161 pr_debug("%s: <-\n", __func__);
162 cmd = container_of(work, struct gelic_eurus_cmd, work);
163 BUG_ON(cmd_info[cmd->cmd].pre_arg &&
164 cmd_info[cmd->cmd].post_arg);
166 card = port_to_card(wl_port(wl));
168 if (cmd_info[cmd->cmd].pre_arg) {
169 arg1 = (cmd->buffer) ?
170 ps3_mm_phys_to_lpar(__pa(cmd->buffer)) :
172 arg2 = cmd->buf_size;
177 init_completion(&wl->cmd_done_intr);
178 pr_debug("%s: cmd='%s' start\n", __func__, cmdstr(cmd->cmd));
179 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
180 GELIC_LV1_POST_WLAN_CMD,
181 cmd->cmd, arg1, arg2,
182 &cmd->tag, &cmd->size);
184 complete(&cmd->done);
185 pr_info("%s: cmd issue failed\n", __func__);
189 wait_for_completion(&wl->cmd_done_intr);
191 if (cmd_info[cmd->cmd].post_arg) {
192 arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
193 arg2 = cmd->buf_size;
199 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
200 GELIC_LV1_GET_WLAN_CMD_RESULT,
201 cmd->tag, arg1, arg2,
202 &cmd->cmd_status, &cmd->size);
204 if (cmd->status || cmd->cmd_status) {
205 pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__,
206 cmd->tag, arg1, arg2);
207 pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
208 __func__, cmd->status, cmd->cmd_status, cmd->size);
211 complete(&cmd->done);
212 pr_debug("%s: cmd='%s' done\n", __func__, cmdstr(cmd->cmd));
215 static struct gelic_eurus_cmd *gelic_eurus_sync_cmd(struct gelic_wl_info *wl,
216 unsigned int eurus_cmd,
218 unsigned int buf_size)
220 struct gelic_eurus_cmd *cmd;
223 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
227 /* initialize members */
228 cmd->cmd = eurus_cmd;
229 cmd->buffer = buffer;
230 cmd->buf_size = buf_size;
232 INIT_WORK(&cmd->work, gelic_eurus_sync_cmd_worker);
233 init_completion(&cmd->done);
234 queue_work(wl->eurus_cmd_queue, &cmd->work);
236 /* wait for command completion */
237 wait_for_completion(&cmd->done);
242 static u32 gelic_wl_get_link(struct net_device *netdev)
244 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
247 pr_debug("%s: <-\n", __func__);
248 mutex_lock(&wl->assoc_stat_lock);
249 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
253 mutex_unlock(&wl->assoc_stat_lock);
254 pr_debug("%s: ->\n", __func__);
258 static void gelic_wl_send_iwap_event(struct gelic_wl_info *wl, u8 *bssid)
260 union iwreq_data data;
262 memset(&data, 0, sizeof(data));
264 memcpy(data.ap_addr.sa_data, bssid, ETH_ALEN);
265 data.ap_addr.sa_family = ARPHRD_ETHER;
266 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWAP,
271 * wireless extension handlers and helpers
275 static int gelic_wl_get_name(struct net_device *dev,
276 struct iw_request_info *info,
277 union iwreq_data *iwreq, char *extra)
279 strcpy(iwreq->name, "IEEE 802.11bg");
283 static void gelic_wl_get_ch_info(struct gelic_wl_info *wl)
285 struct gelic_card *card = port_to_card(wl_port(wl));
286 u64 ch_info_raw, tmp;
289 if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO, &wl->stat)) {
290 status = lv1_net_control(bus_id(card), dev_id(card),
291 GELIC_LV1_GET_CHANNEL, 0, 0, 0,
294 /* some fw versions may return error */
296 if (status != LV1_NO_ENTRY)
297 pr_info("%s: available ch unknown\n", __func__);
298 wl->ch_info = 0x07ff;/* 11 ch */
300 /* 16 bits of MSB has available channels */
301 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_GENERIC;
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__);
509 return (buf - start);
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_GENERIC:
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 */
728 case GELIC_WL_SCAN_STAT_INIT:
729 /* last scan request failed or never issued */
733 case GELIC_WL_SCAN_STAT_GOT_LIST:
734 /* ok, use current list */
738 list_for_each_entry(scan_info, &wl->network_list, list) {
739 if (wl->scan_age == 0 ||
740 time_after(scan_info->last_scanned + wl->scan_age,
742 ev = gelic_wl_translate_scan(netdev, info,
746 pr_debug("%s:entry too old\n", __func__);
748 if (stop - ev <= IW_EV_ADDR_LEN) {
754 wrqu->data.length = ev - extra;
755 wrqu->data.flags = 0;
757 mutex_unlock(&wl->scan_lock);
758 pr_debug("%s: -> %d %d\n", __func__, ret, wrqu->data.length);
763 static void scan_list_dump(struct gelic_wl_info *wl)
765 struct gelic_wl_scan_info *scan_info;
769 list_for_each_entry(scan_info, &wl->network_list, list) {
770 pr_debug("%s: item %d\n", __func__, i++);
771 pr_debug("valid=%d eurusindex=%d last=%lx\n",
772 scan_info->valid, scan_info->eurus_index,
773 scan_info->last_scanned);
774 pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
775 scan_info->rate_len, scan_info->rate_ext_len,
776 scan_info->essid_len);
778 pr_debug("bssid=%pM\n", &scan_info->hwinfo->bssid[2]);
779 pr_debug("essid=%s\n", scan_info->hwinfo->essid);
784 static int gelic_wl_set_auth(struct net_device *netdev,
785 struct iw_request_info *info,
786 union iwreq_data *data, char *extra)
788 struct iw_param *param = &data->param;
789 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
790 unsigned long irqflag;
793 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
794 spin_lock_irqsave(&wl->lock, irqflag);
795 switch (param->flags & IW_AUTH_INDEX) {
796 case IW_AUTH_WPA_VERSION:
797 if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
798 pr_debug("%s: NO WPA selected\n", __func__);
799 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
800 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
801 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
803 if (param->value & IW_AUTH_WPA_VERSION_WPA) {
804 pr_debug("%s: WPA version 1 selected\n", __func__);
805 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
806 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
807 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
808 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
810 if (param->value & IW_AUTH_WPA_VERSION_WPA2) {
812 * As the hypervisor may not tell the cipher
813 * information of the AP if it is WPA2,
814 * you will not decide suitable cipher from
816 * You should have knowledge about the AP's
817 * cipher infomation in other method prior to
821 pr_info("%s: WPA2 may not work\n", __func__);
822 if (wpa2_capable()) {
823 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
824 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
825 wl->pairwise_cipher_method =
827 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
833 case IW_AUTH_CIPHER_PAIRWISE:
835 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
836 pr_debug("%s: WEP selected\n", __func__);
837 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
839 if (param->value & IW_AUTH_CIPHER_TKIP) {
840 pr_debug("%s: TKIP selected\n", __func__);
841 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
843 if (param->value & IW_AUTH_CIPHER_CCMP) {
844 pr_debug("%s: CCMP selected\n", __func__);
845 wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
847 if (param->value & IW_AUTH_CIPHER_NONE) {
848 pr_debug("%s: no auth selected\n", __func__);
849 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
852 case IW_AUTH_CIPHER_GROUP:
854 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
855 pr_debug("%s: WEP selected\n", __func__);
856 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
858 if (param->value & IW_AUTH_CIPHER_TKIP) {
859 pr_debug("%s: TKIP selected\n", __func__);
860 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
862 if (param->value & IW_AUTH_CIPHER_CCMP) {
863 pr_debug("%s: CCMP selected\n", __func__);
864 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
866 if (param->value & IW_AUTH_CIPHER_NONE) {
867 pr_debug("%s: no auth selected\n", __func__);
868 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
871 case IW_AUTH_80211_AUTH_ALG:
872 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
873 pr_debug("%s: shared key specified\n", __func__);
874 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
875 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
876 pr_debug("%s: open system specified\n", __func__);
877 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
882 case IW_AUTH_WPA_ENABLED:
884 pr_debug("%s: WPA enabled\n", __func__);
885 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
887 pr_debug("%s: WPA disabled\n", __func__);
888 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
892 case IW_AUTH_KEY_MGMT:
893 if (param->value & IW_AUTH_KEY_MGMT_PSK)
895 /* intentionally fall through */
902 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
904 spin_unlock_irqrestore(&wl->lock, irqflag);
905 pr_debug("%s: -> %d\n", __func__, ret);
909 static int gelic_wl_get_auth(struct net_device *netdev,
910 struct iw_request_info *info,
911 union iwreq_data *iwreq, char *extra)
913 struct iw_param *param = &iwreq->param;
914 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
915 unsigned long irqflag;
918 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
919 spin_lock_irqsave(&wl->lock, irqflag);
920 switch (param->flags & IW_AUTH_INDEX) {
921 case IW_AUTH_WPA_VERSION:
922 switch (wl->wpa_level) {
923 case GELIC_WL_WPA_LEVEL_WPA:
924 param->value |= IW_AUTH_WPA_VERSION_WPA;
926 case GELIC_WL_WPA_LEVEL_WPA2:
927 param->value |= IW_AUTH_WPA_VERSION_WPA2;
930 param->value |= IW_AUTH_WPA_VERSION_DISABLED;
934 case IW_AUTH_80211_AUTH_ALG:
935 if (wl->auth_method == GELIC_EURUS_AUTH_SHARED)
936 param->value = IW_AUTH_ALG_SHARED_KEY;
937 else if (wl->auth_method == GELIC_EURUS_AUTH_OPEN)
938 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
941 case IW_AUTH_WPA_ENABLED:
942 switch (wl->wpa_level) {
943 case GELIC_WL_WPA_LEVEL_WPA:
944 case GELIC_WL_WPA_LEVEL_WPA2:
956 spin_unlock_irqrestore(&wl->lock, irqflag);
957 pr_debug("%s: -> %d\n", __func__, ret);
961 /* SIOC{S,G}IWESSID */
962 static int gelic_wl_set_essid(struct net_device *netdev,
963 struct iw_request_info *info,
964 union iwreq_data *data, char *extra)
966 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
967 unsigned long irqflag;
969 pr_debug("%s: <- l=%d f=%d\n", __func__,
970 data->essid.length, data->essid.flags);
971 if (IW_ESSID_MAX_SIZE < data->essid.length)
974 spin_lock_irqsave(&wl->lock, irqflag);
975 if (data->essid.flags) {
976 wl->essid_len = data->essid.length;
977 memcpy(wl->essid, extra, wl->essid_len);
978 pr_debug("%s: essid = '%s'\n", __func__, extra);
979 set_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
981 pr_debug("%s: ESSID any \n", __func__);
982 clear_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
984 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
985 spin_unlock_irqrestore(&wl->lock, irqflag);
988 gelic_wl_try_associate(netdev); /* FIXME */
989 pr_debug("%s: -> \n", __func__);
993 static int gelic_wl_get_essid(struct net_device *netdev,
994 struct iw_request_info *info,
995 union iwreq_data *data, char *extra)
997 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
998 unsigned long irqflag;
1000 pr_debug("%s: <- \n", __func__);
1001 mutex_lock(&wl->assoc_stat_lock);
1002 spin_lock_irqsave(&wl->lock, irqflag);
1003 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat) ||
1004 wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1005 memcpy(extra, wl->essid, wl->essid_len);
1006 data->essid.length = wl->essid_len;
1007 data->essid.flags = 1;
1009 data->essid.flags = 0;
1011 mutex_unlock(&wl->assoc_stat_lock);
1012 spin_unlock_irqrestore(&wl->lock, irqflag);
1013 pr_debug("%s: -> len=%d \n", __func__, data->essid.length);
1018 /* SIO{S,G}IWENCODE */
1019 static int gelic_wl_set_encode(struct net_device *netdev,
1020 struct iw_request_info *info,
1021 union iwreq_data *data, char *extra)
1023 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1024 struct iw_point *enc = &data->encoding;
1026 unsigned long irqflag;
1027 int key_index, index_specified;
1030 pr_debug("%s: <- \n", __func__);
1031 flags = enc->flags & IW_ENCODE_FLAGS;
1032 key_index = enc->flags & IW_ENCODE_INDEX;
1034 pr_debug("%s: key_index = %d\n", __func__, key_index);
1035 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1036 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1038 if (GELIC_WEP_KEYS < key_index)
1041 spin_lock_irqsave(&wl->lock, irqflag);
1043 index_specified = 1;
1046 index_specified = 0;
1047 key_index = wl->current_key;
1050 if (flags & IW_ENCODE_NOKEY) {
1051 /* if just IW_ENCODE_NOKEY, change current key index */
1052 if (!flags && index_specified) {
1053 wl->current_key = key_index;
1057 if (flags & IW_ENCODE_DISABLED) {
1058 if (!index_specified) {
1059 /* disable encryption */
1060 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1061 wl->pairwise_cipher_method =
1062 GELIC_WL_CIPHER_NONE;
1063 /* invalidate all key */
1064 wl->key_enabled = 0;
1066 clear_bit(key_index, &wl->key_enabled);
1069 if (flags & IW_ENCODE_OPEN)
1070 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1071 if (flags & IW_ENCODE_RESTRICTED) {
1072 pr_info("%s: shared key mode enabled\n", __func__);
1073 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1076 if (IW_ENCODING_TOKEN_MAX < enc->length) {
1080 wl->key_len[key_index] = enc->length;
1081 memcpy(wl->key[key_index], extra, enc->length);
1082 set_bit(key_index, &wl->key_enabled);
1083 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
1084 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
1086 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1088 spin_unlock_irqrestore(&wl->lock, irqflag);
1089 pr_debug("%s: -> \n", __func__);
1093 static int gelic_wl_get_encode(struct net_device *netdev,
1094 struct iw_request_info *info,
1095 union iwreq_data *data, char *extra)
1097 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1098 struct iw_point *enc = &data->encoding;
1099 unsigned long irqflag;
1100 unsigned int key_index, index_specified;
1103 pr_debug("%s: <- \n", __func__);
1104 key_index = enc->flags & IW_ENCODE_INDEX;
1105 pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
1106 enc->flags, enc->pointer, enc->length, extra);
1107 if (GELIC_WEP_KEYS < key_index)
1110 spin_lock_irqsave(&wl->lock, irqflag);
1112 index_specified = 1;
1115 index_specified = 0;
1116 key_index = wl->current_key;
1119 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1120 switch (wl->auth_method) {
1121 case GELIC_EURUS_AUTH_OPEN:
1122 enc->flags = IW_ENCODE_OPEN;
1124 case GELIC_EURUS_AUTH_SHARED:
1125 enc->flags = IW_ENCODE_RESTRICTED;
1129 enc->flags = IW_ENCODE_DISABLED;
1131 if (test_bit(key_index, &wl->key_enabled)) {
1132 if (enc->length < wl->key_len[key_index]) {
1136 enc->length = wl->key_len[key_index];
1137 memcpy(extra, wl->key[key_index], wl->key_len[key_index]);
1140 enc->flags |= IW_ENCODE_NOKEY;
1142 enc->flags |= key_index + 1;
1143 pr_debug("%s: -> flag=%x len=%d\n", __func__,
1144 enc->flags, enc->length);
1147 spin_unlock_irqrestore(&wl->lock, irqflag);
1152 static int gelic_wl_set_ap(struct net_device *netdev,
1153 struct iw_request_info *info,
1154 union iwreq_data *data, char *extra)
1156 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1157 unsigned long irqflag;
1159 pr_debug("%s: <-\n", __func__);
1160 if (data->ap_addr.sa_family != ARPHRD_ETHER)
1163 spin_lock_irqsave(&wl->lock, irqflag);
1164 if (is_valid_ether_addr(data->ap_addr.sa_data)) {
1165 memcpy(wl->bssid, data->ap_addr.sa_data,
1167 set_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1168 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1169 pr_debug("%s: bss=%pM\n", __func__, wl->bssid);
1171 pr_debug("%s: clear bssid\n", __func__);
1172 clear_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1173 memset(wl->bssid, 0, ETH_ALEN);
1175 spin_unlock_irqrestore(&wl->lock, irqflag);
1176 pr_debug("%s: ->\n", __func__);
1180 static int gelic_wl_get_ap(struct net_device *netdev,
1181 struct iw_request_info *info,
1182 union iwreq_data *data, char *extra)
1184 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1185 unsigned long irqflag;
1187 pr_debug("%s: <-\n", __func__);
1188 mutex_lock(&wl->assoc_stat_lock);
1189 spin_lock_irqsave(&wl->lock, irqflag);
1190 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1191 data->ap_addr.sa_family = ARPHRD_ETHER;
1192 memcpy(data->ap_addr.sa_data, wl->active_bssid,
1195 memset(data->ap_addr.sa_data, 0, ETH_ALEN);
1197 spin_unlock_irqrestore(&wl->lock, irqflag);
1198 mutex_unlock(&wl->assoc_stat_lock);
1199 pr_debug("%s: ->\n", __func__);
1203 /* SIOC{S,G}IWENCODEEXT */
1204 static int gelic_wl_set_encodeext(struct net_device *netdev,
1205 struct iw_request_info *info,
1206 union iwreq_data *data, char *extra)
1208 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1209 struct iw_point *enc = &data->encoding;
1210 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1213 unsigned long irqflag;
1217 pr_debug("%s: <- \n", __func__);
1218 flags = enc->flags & IW_ENCODE_FLAGS;
1220 key_index = enc->flags & IW_ENCODE_INDEX;
1222 pr_debug("%s: key_index = %d\n", __func__, key_index);
1223 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1224 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1225 pr_debug("%s: ext_flag=%x\n", __func__, ext->ext_flags);
1226 pr_debug("%s: ext_key_len=%x\n", __func__, ext->key_len);
1228 if (GELIC_WEP_KEYS < key_index)
1231 spin_lock_irqsave(&wl->lock, irqflag);
1235 key_index = wl->current_key;
1237 if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
1238 /* reques to change default key index */
1239 pr_debug("%s: request to change default key to %d\n",
1240 __func__, key_index);
1241 wl->current_key = key_index;
1245 if (alg == IW_ENCODE_ALG_NONE || (flags & IW_ENCODE_DISABLED)) {
1246 pr_debug("%s: alg disabled\n", __func__);
1247 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
1248 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1249 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
1250 wl->auth_method = GELIC_EURUS_AUTH_OPEN; /* should be open */
1251 } else if (alg == IW_ENCODE_ALG_WEP) {
1252 pr_debug("%s: WEP requested\n", __func__);
1253 if (flags & IW_ENCODE_OPEN) {
1254 pr_debug("%s: open key mode\n", __func__);
1255 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1257 if (flags & IW_ENCODE_RESTRICTED) {
1258 pr_debug("%s: shared key mode\n", __func__);
1259 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1261 if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
1262 pr_info("%s: key is too long %d\n", __func__,
1267 /* OK, update the key */
1268 wl->key_len[key_index] = ext->key_len;
1269 memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
1270 memcpy(wl->key[key_index], ext->key, ext->key_len);
1271 set_bit(key_index, &wl->key_enabled);
1272 /* remember wep info changed */
1273 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1274 } else if (alg == IW_ENCODE_ALG_PMK) {
1275 if (ext->key_len != WPA_PSK_LEN) {
1276 pr_err("%s: PSK length wrong %d\n", __func__,
1281 memset(wl->psk, 0, sizeof(wl->psk));
1282 memcpy(wl->psk, ext->key, ext->key_len);
1283 wl->psk_len = ext->key_len;
1284 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1285 /* remember PSK configured */
1286 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1289 spin_unlock_irqrestore(&wl->lock, irqflag);
1290 pr_debug("%s: -> \n", __func__);
1294 static int gelic_wl_get_encodeext(struct net_device *netdev,
1295 struct iw_request_info *info,
1296 union iwreq_data *data, char *extra)
1298 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1299 struct iw_point *enc = &data->encoding;
1300 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1301 unsigned long irqflag;
1306 pr_debug("%s: <- \n", __func__);
1308 max_key_len = enc->length - sizeof(struct iw_encode_ext);
1309 if (max_key_len < 0)
1311 key_index = enc->flags & IW_ENCODE_INDEX;
1313 pr_debug("%s: key_index = %d\n", __func__, key_index);
1314 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1315 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1317 if (GELIC_WEP_KEYS < key_index)
1320 spin_lock_irqsave(&wl->lock, irqflag);
1324 key_index = wl->current_key;
1326 memset(ext, 0, sizeof(struct iw_encode_ext));
1327 switch (wl->group_cipher_method) {
1328 case GELIC_WL_CIPHER_WEP:
1329 ext->alg = IW_ENCODE_ALG_WEP;
1330 enc->flags |= IW_ENCODE_ENABLED;
1332 case GELIC_WL_CIPHER_TKIP:
1333 ext->alg = IW_ENCODE_ALG_TKIP;
1334 enc->flags |= IW_ENCODE_ENABLED;
1336 case GELIC_WL_CIPHER_AES:
1337 ext->alg = IW_ENCODE_ALG_CCMP;
1338 enc->flags |= IW_ENCODE_ENABLED;
1340 case GELIC_WL_CIPHER_NONE:
1342 ext->alg = IW_ENCODE_ALG_NONE;
1343 enc->flags |= IW_ENCODE_NOKEY;
1347 if (!(enc->flags & IW_ENCODE_NOKEY)) {
1348 if (max_key_len < wl->key_len[key_index]) {
1352 if (test_bit(key_index, &wl->key_enabled))
1353 memcpy(ext->key, wl->key[key_index],
1354 wl->key_len[key_index]);
1356 pr_debug("%s: disabled key requested ix=%d\n",
1357 __func__, key_index);
1360 spin_unlock_irqrestore(&wl->lock, irqflag);
1361 pr_debug("%s: -> \n", __func__);
1364 /* SIOC{S,G}IWMODE */
1365 static int gelic_wl_set_mode(struct net_device *netdev,
1366 struct iw_request_info *info,
1367 union iwreq_data *data, char *extra)
1369 __u32 mode = data->mode;
1372 pr_debug("%s: <- \n", __func__);
1373 if (mode == IW_MODE_INFRA)
1377 pr_debug("%s: -> %d\n", __func__, ret);
1381 static int gelic_wl_get_mode(struct net_device *netdev,
1382 struct iw_request_info *info,
1383 union iwreq_data *data, char *extra)
1385 __u32 *mode = &data->mode;
1386 pr_debug("%s: <- \n", __func__);
1387 *mode = IW_MODE_INFRA;
1388 pr_debug("%s: ->\n", __func__);
1393 static int gelic_wl_get_nick(struct net_device *net_dev,
1394 struct iw_request_info *info,
1395 union iwreq_data *data, char *extra)
1397 strcpy(extra, "gelic_wl");
1398 data->data.length = strlen(extra);
1399 data->data.flags = 1;
1406 static struct iw_statistics *gelic_wl_get_wireless_stats(
1407 struct net_device *netdev)
1410 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1411 struct gelic_eurus_cmd *cmd;
1412 struct iw_statistics *is;
1413 struct gelic_eurus_rssi_info *rssi;
1416 pr_debug("%s: <-\n", __func__);
1418 buf = (void *)__get_free_page(GFP_KERNEL);
1423 memset(is, 0, sizeof(*is));
1424 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
1425 buf, sizeof(*rssi));
1426 if (cmd && !cmd->status && !cmd->cmd_status) {
1428 is->qual.level = be16_to_cpu(rssi->rssi);
1429 is->qual.updated = IW_QUAL_LEVEL_UPDATED |
1430 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
1432 /* not associated */
1433 is->qual.updated = IW_QUAL_ALL_INVALID;
1436 free_page((unsigned long)buf);
1437 pr_debug("%s: ->\n", __func__);
1444 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
1445 u8 *essid, size_t essid_len)
1447 struct gelic_eurus_cmd *cmd;
1452 pr_debug("%s: <- always=%d\n", __func__, always_scan);
1453 if (mutex_lock_interruptible(&wl->scan_lock))
1454 return -ERESTARTSYS;
1457 * If already a scan in progress, do not trigger more
1459 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING) {
1460 pr_debug("%s: scanning now\n", __func__);
1464 init_completion(&wl->scan_done);
1466 * If we have already a bss list, don't try to get new
1468 if (!always_scan && wl->scan_stat == GELIC_WL_SCAN_STAT_GOT_LIST) {
1469 pr_debug("%s: already has the list\n", __func__);
1470 complete(&wl->scan_done);
1475 if (essid_len && essid) {
1476 buf = (void *)__get_free_page(GFP_KERNEL);
1481 len = IW_ESSID_MAX_SIZE; /* hypervisor always requires 32 */
1482 memset(buf, 0, len);
1483 memcpy(buf, essid, essid_len);
1484 pr_debug("%s: essid scan='%s'\n", __func__, (char *)buf);
1489 * issue start scan request
1491 wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
1492 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
1494 if (!cmd || cmd->status || cmd->cmd_status) {
1495 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1496 complete(&wl->scan_done);
1502 free_page((unsigned long)buf);
1503 mutex_unlock(&wl->scan_lock);
1504 pr_debug("%s: ->\n", __func__);
1509 * retrieve scan result from the chip (hypervisor)
1510 * this function is invoked by schedule work.
1512 static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
1514 struct gelic_eurus_cmd *cmd = NULL;
1515 struct gelic_wl_scan_info *target, *tmp;
1516 struct gelic_wl_scan_info *oldest = NULL;
1517 struct gelic_eurus_scan_info *scan_info;
1518 unsigned int scan_info_size;
1519 union iwreq_data data;
1520 unsigned long this_time = jiffies;
1521 unsigned int data_len, i, found, r;
1524 pr_debug("%s:start\n", __func__);
1525 mutex_lock(&wl->scan_lock);
1527 buf = (void *)__get_free_page(GFP_KERNEL);
1529 pr_info("%s: scan buffer alloc failed\n", __func__);
1533 if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
1535 * stop() may be called while scanning, ignore result
1537 pr_debug("%s: scan complete when stat != scanning(%d)\n",
1538 __func__, wl->scan_stat);
1542 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
1544 if (!cmd || cmd->status || cmd->cmd_status) {
1545 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1546 pr_info("%s:cmd failed\n", __func__);
1550 data_len = cmd->size;
1551 pr_debug("%s: data_len = %d\n", __func__, data_len);
1554 /* OK, bss list retrieved */
1555 wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST;
1557 /* mark all entries are old */
1558 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
1560 /* expire too old entries */
1561 if (time_before(target->last_scanned + wl->scan_age,
1563 kfree(target->hwinfo);
1564 target->hwinfo = NULL;
1565 list_move_tail(&target->list, &wl->network_free_list);
1569 /* put them in the newtork_list */
1570 for (i = 0, scan_info_size = 0, scan_info = buf;
1571 scan_info_size < data_len;
1572 i++, scan_info_size += be16_to_cpu(scan_info->size),
1573 scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
1574 pr_debug("%s:size=%d bssid=%pM scan_info=%p\n", __func__,
1575 be16_to_cpu(scan_info->size),
1576 &scan_info->bssid[2], scan_info);
1579 * The wireless firmware may return invalid channel 0 and/or
1580 * invalid rate if the AP emits zero length SSID ie. As this
1581 * scan information is useless, ignore it
1583 if (!be16_to_cpu(scan_info->channel) || !scan_info->rate[0]) {
1584 pr_debug("%s: invalid scan info\n", __func__);
1590 list_for_each_entry(target, &wl->network_list, list) {
1591 if (!compare_ether_addr(&target->hwinfo->bssid[2],
1592 &scan_info->bssid[2])) {
1594 pr_debug("%s: same BBS found scanned list\n",
1599 (target->last_scanned < oldest->last_scanned))
1604 /* not found in the list */
1605 if (list_empty(&wl->network_free_list)) {
1609 target = list_entry(wl->network_free_list.next,
1610 struct gelic_wl_scan_info,
1615 /* update the item */
1616 target->last_scanned = this_time;
1618 target->eurus_index = i;
1619 kfree(target->hwinfo);
1620 target->hwinfo = kzalloc(be16_to_cpu(scan_info->size),
1622 if (!target->hwinfo) {
1623 pr_info("%s: kzalloc failed\n", __func__);
1626 /* copy hw scan info */
1627 memcpy(target->hwinfo, scan_info, scan_info->size);
1628 target->essid_len = strnlen(scan_info->essid,
1629 sizeof(scan_info->essid));
1630 target->rate_len = 0;
1631 for (r = 0; r < 12; r++)
1632 if (scan_info->rate[r])
1634 if (8 < target->rate_len)
1635 pr_info("%s: AP returns %d rates\n", __func__,
1637 target->rate_ext_len = 0;
1638 for (r = 0; r < 16; r++)
1639 if (scan_info->ext_rate[r])
1640 target->rate_ext_len++;
1641 list_move_tail(&target->list, &wl->network_list);
1643 memset(&data, 0, sizeof(data));
1644 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
1647 free_page((unsigned long)buf);
1648 complete(&wl->scan_done);
1649 mutex_unlock(&wl->scan_lock);
1650 pr_debug("%s:end\n", __func__);
1654 * Select an appropriate bss from current scan list regarding
1655 * current settings from userspace.
1656 * The caller must hold wl->scan_lock,
1657 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1659 static void update_best(struct gelic_wl_scan_info **best,
1660 struct gelic_wl_scan_info *candid,
1664 if (*best_weight < ++(*weight)) {
1665 *best_weight = *weight;
1671 struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
1673 struct gelic_wl_scan_info *scan_info;
1674 struct gelic_wl_scan_info *best_bss;
1675 int weight, best_weight;
1678 pr_debug("%s: <-\n", __func__);
1683 list_for_each_entry(scan_info, &wl->network_list, list) {
1684 pr_debug("%s: station %p\n", __func__, scan_info);
1686 if (!scan_info->valid) {
1687 pr_debug("%s: station invalid\n", __func__);
1691 /* If bss specified, check it only */
1692 if (test_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat)) {
1693 if (!compare_ether_addr(&scan_info->hwinfo->bssid[2],
1695 best_bss = scan_info;
1696 pr_debug("%s: bssid matched\n", __func__);
1699 pr_debug("%s: bssid unmached\n", __func__);
1707 security = be16_to_cpu(scan_info->hwinfo->security) &
1708 GELIC_EURUS_SCAN_SEC_MASK;
1709 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1710 if (security == GELIC_EURUS_SCAN_SEC_WPA2)
1711 update_best(&best_bss, scan_info,
1712 &best_weight, &weight);
1715 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA) {
1716 if (security == GELIC_EURUS_SCAN_SEC_WPA)
1717 update_best(&best_bss, scan_info,
1718 &best_weight, &weight);
1721 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_NONE &&
1722 wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1723 if (security == GELIC_EURUS_SCAN_SEC_WEP)
1724 update_best(&best_bss, scan_info,
1725 &best_weight, &weight);
1730 /* If ESSID is set, check it */
1731 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
1732 if ((scan_info->essid_len == wl->essid_len) &&
1734 scan_info->hwinfo->essid,
1735 scan_info->essid_len))
1736 update_best(&best_bss, scan_info,
1737 &best_weight, &weight);
1744 pr_debug("%s: -> bss=%p\n", __func__, best_bss);
1746 pr_debug("%s:addr=%pM\n", __func__,
1747 &best_bss->hwinfo->bssid[2]);
1754 * Setup WEP configuration to the chip
1755 * The caller must hold wl->scan_lock,
1756 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1758 static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
1761 struct gelic_eurus_wep_cfg *wep;
1762 struct gelic_eurus_cmd *cmd;
1767 pr_debug("%s: <-\n", __func__);
1768 /* we can assume no one should uses the buffer */
1769 wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
1773 memset(wep, 0, sizeof(*wep));
1775 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1776 pr_debug("%s: WEP mode\n", __func__);
1777 for (i = 0; i < GELIC_WEP_KEYS; i++) {
1778 if (!test_bit(i, &wl->key_enabled))
1781 pr_debug("%s: key#%d enabled\n", __func__, i);
1783 if (wl->key_len[i] == 13)
1785 else if (wl->key_len[i] != 5) {
1786 pr_info("%s: wrong wep key[%d]=%d\n",
1787 __func__, i, wl->key_len[i]);
1791 memcpy(wep->key[i], wl->key[i], wl->key_len[i]);
1795 pr_info("%s: all wep key disabled\n", __func__);
1801 pr_debug("%s: 104bit key\n", __func__);
1802 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT);
1804 pr_debug("%s: 40bit key\n", __func__);
1805 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT);
1808 pr_debug("%s: NO encryption\n", __func__);
1809 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE);
1812 /* issue wep setup */
1813 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WEP_CFG,
1817 else if (cmd->status || cmd->cmd_status)
1822 free_page((unsigned long)wep);
1823 pr_debug("%s: ->\n", __func__);
1828 static const char *wpasecstr(enum gelic_eurus_wpa_security sec)
1831 case GELIC_EURUS_WPA_SEC_NONE:
1834 case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP:
1835 return "WPA_TKIP_TKIP";
1837 case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES:
1838 return "WPA_TKIP_AES";
1840 case GELIC_EURUS_WPA_SEC_WPA_AES_AES:
1841 return "WPA_AES_AES";
1843 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP:
1844 return "WPA2_TKIP_TKIP";
1846 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES:
1847 return "WPA2_TKIP_AES";
1849 case GELIC_EURUS_WPA_SEC_WPA2_AES_AES:
1850 return "WPA2_AES_AES";
1857 static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
1859 struct gelic_eurus_wpa_cfg *wpa;
1860 struct gelic_eurus_cmd *cmd;
1864 pr_debug("%s: <-\n", __func__);
1865 /* we can assume no one should uses the buffer */
1866 wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
1870 memset(wpa, 0, sizeof(*wpa));
1872 if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
1873 pr_info("%s: PSK not configured yet\n", __func__);
1876 memcpy(wpa->psk, wl->psk, wl->psk_len);
1878 /* set security level */
1879 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1880 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1881 security = GELIC_EURUS_WPA_SEC_WPA2_AES_AES;
1883 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1885 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES;
1887 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP;
1890 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1891 security = GELIC_EURUS_WPA_SEC_WPA_AES_AES;
1893 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1895 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_AES;
1897 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP;
1900 wpa->security = cpu_to_be16(security);
1903 wpa->psk_type = cpu_to_be16(wl->psk_type);
1905 pr_debug("%s: sec=%s psktype=%s\nn", __func__,
1906 wpasecstr(wpa->security),
1907 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1908 "BIN" : "passphrase");
1911 * don't enable here if you plan to submit
1912 * the debug log because this dumps your precious
1915 pr_debug("%s: psk=%s\n",
1916 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1917 (char *)"N/A" : (char *)wpa->psk);
1920 /* issue wpa setup */
1921 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WPA_CFG,
1925 else if (cmd->status || cmd->cmd_status)
1928 free_page((unsigned long)wpa);
1929 pr_debug("%s: --> %d\n", __func__, ret);
1934 * Start association. caller must hold assoc_stat_lock
1936 static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
1937 struct gelic_wl_scan_info *bss)
1939 struct gelic_eurus_cmd *cmd;
1940 struct gelic_eurus_common_cfg *common;
1944 pr_debug("%s: <-\n", __func__);
1946 /* do common config */
1947 common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
1951 memset(common, 0, sizeof(*common));
1952 common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
1953 common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
1955 common->scan_index = cpu_to_be16(bss->eurus_index);
1956 switch (wl->auth_method) {
1957 case GELIC_EURUS_AUTH_OPEN:
1958 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_OPEN);
1960 case GELIC_EURUS_AUTH_SHARED:
1961 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_SHARED);
1968 pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
1969 be16_to_cpu(common->scan_index),
1970 be16_to_cpu(common->bss_type),
1971 be16_to_cpu(common->auth_method));
1973 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_COMMON_CFG,
1974 common, sizeof(*common));
1975 if (!cmd || cmd->status || cmd->cmd_status) {
1983 switch (wl->wpa_level) {
1984 case GELIC_WL_WPA_LEVEL_NONE:
1985 /* If WEP or no security, setup WEP config */
1986 ret = gelic_wl_do_wep_setup(wl);
1988 case GELIC_WL_WPA_LEVEL_WPA:
1989 case GELIC_WL_WPA_LEVEL_WPA2:
1990 ret = gelic_wl_do_wpa_setup(wl);
1995 pr_debug("%s: WEP/WPA setup failed %d\n", __func__,
1998 gelic_wl_send_iwap_event(wl, NULL);
2002 /* start association */
2003 init_completion(&wl->assoc_done);
2004 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATING;
2005 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_ASSOC,
2007 if (!cmd || cmd->status || cmd->cmd_status) {
2008 pr_debug("%s: assoc request failed\n", __func__);
2009 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2012 gelic_wl_send_iwap_event(wl, NULL);
2017 /* wait for connected event */
2018 rc = wait_for_completion_timeout(&wl->assoc_done, HZ * 4);/*FIXME*/
2021 /* timeouted. Maybe key or cyrpt mode is wrong */
2022 pr_info("%s: connect timeout \n", __func__);
2023 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC,
2026 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2027 gelic_wl_send_iwap_event(wl, NULL);
2030 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATED;
2032 memcpy(wl->active_bssid, &bss->hwinfo->bssid[2], ETH_ALEN);
2034 /* send connect event */
2035 gelic_wl_send_iwap_event(wl, wl->active_bssid);
2036 pr_info("%s: connected\n", __func__);
2039 free_page((unsigned long)common);
2040 pr_debug("%s: ->\n", __func__);
2047 static void gelic_wl_connected_event(struct gelic_wl_info *wl,
2050 u64 desired_event = 0;
2052 switch (wl->wpa_level) {
2053 case GELIC_WL_WPA_LEVEL_NONE:
2054 desired_event = GELIC_LV1_WL_EVENT_CONNECTED;
2056 case GELIC_WL_WPA_LEVEL_WPA:
2057 case GELIC_WL_WPA_LEVEL_WPA2:
2058 desired_event = GELIC_LV1_WL_EVENT_WPA_CONNECTED;
2062 if (desired_event == event) {
2063 pr_debug("%s: completed \n", __func__);
2064 complete(&wl->assoc_done);
2065 netif_carrier_on(port_to_netdev(wl_port(wl)));
2067 pr_debug("%s: event %#llx under wpa\n",
2074 static void gelic_wl_disconnect_event(struct gelic_wl_info *wl,
2077 struct gelic_eurus_cmd *cmd;
2081 * If we fall here in the middle of association,
2082 * associate_bss() should be waiting for complation of
2084 * As it waits with timeout, just leave assoc_done
2085 * uncompleted, then it terminates with timeout
2087 if (!mutex_trylock(&wl->assoc_stat_lock)) {
2088 pr_debug("%s: already locked\n", __func__);
2091 pr_debug("%s: obtain lock\n", __func__);
2095 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2098 /* send disconnected event to the supplicant */
2099 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2100 gelic_wl_send_iwap_event(wl, NULL);
2102 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2103 netif_carrier_off(port_to_netdev(wl_port(wl)));
2106 mutex_unlock(&wl->assoc_stat_lock);
2112 static const char *eventstr(enum gelic_lv1_wl_event event)
2114 static char buf[32];
2116 if (event & GELIC_LV1_WL_EVENT_DEVICE_READY)
2117 ret = "EURUS_READY";
2118 else if (event & GELIC_LV1_WL_EVENT_SCAN_COMPLETED)
2119 ret = "SCAN_COMPLETED";
2120 else if (event & GELIC_LV1_WL_EVENT_DEAUTH)
2122 else if (event & GELIC_LV1_WL_EVENT_BEACON_LOST)
2123 ret = "BEACON_LOST";
2124 else if (event & GELIC_LV1_WL_EVENT_CONNECTED)
2126 else if (event & GELIC_LV1_WL_EVENT_WPA_CONNECTED)
2127 ret = "WPA_CONNECTED";
2128 else if (event & GELIC_LV1_WL_EVENT_WPA_ERROR)
2131 sprintf(buf, "Unknown(%#x)", event);
2137 static const char *eventstr(enum gelic_lv1_wl_event event)
2142 static void gelic_wl_event_worker(struct work_struct *work)
2144 struct gelic_wl_info *wl;
2145 struct gelic_port *port;
2149 pr_debug("%s:start\n", __func__);
2150 wl = container_of(work, struct gelic_wl_info, event_work.work);
2153 status = lv1_net_control(bus_id(port->card), dev_id(port->card),
2154 GELIC_LV1_GET_WLAN_EVENT, 0, 0, 0,
2157 if (status != LV1_NO_ENTRY)
2158 pr_debug("%s:wlan event failed %d\n",
2160 /* got all events */
2161 pr_debug("%s:end\n", __func__);
2164 pr_debug("%s: event=%s\n", __func__, eventstr(event));
2166 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
2167 gelic_wl_scan_complete_event(wl);
2169 case GELIC_LV1_WL_EVENT_BEACON_LOST:
2170 case GELIC_LV1_WL_EVENT_DEAUTH:
2171 gelic_wl_disconnect_event(wl, event);
2173 case GELIC_LV1_WL_EVENT_CONNECTED:
2174 case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
2175 gelic_wl_connected_event(wl, event);
2183 * association worker
2185 static void gelic_wl_assoc_worker(struct work_struct *work)
2187 struct gelic_wl_info *wl;
2189 struct gelic_wl_scan_info *best_bss;
2191 unsigned long irqflag;
2195 wl = container_of(work, struct gelic_wl_info, assoc_work.work);
2197 mutex_lock(&wl->assoc_stat_lock);
2199 if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
2202 spin_lock_irqsave(&wl->lock, irqflag);
2203 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
2204 pr_debug("%s: assoc ESSID configured %s\n", __func__,
2207 essid_len = wl->essid_len;
2212 spin_unlock_irqrestore(&wl->lock, irqflag);
2214 ret = gelic_wl_start_scan(wl, 0, essid, essid_len);
2215 if (ret == -ERESTARTSYS) {
2216 pr_debug("%s: scan start failed association\n", __func__);
2217 schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
2220 pr_info("%s: scan prerequisite failed\n", __func__);
2225 * Wait for bss scan completion
2226 * If we have scan list already, gelic_wl_start_scan()
2227 * returns OK and raises the complete. Thus,
2228 * it's ok to wait unconditionally here
2230 wait_for_completion(&wl->scan_done);
2232 pr_debug("%s: scan done\n", __func__);
2233 mutex_lock(&wl->scan_lock);
2234 if (wl->scan_stat != GELIC_WL_SCAN_STAT_GOT_LIST) {
2235 gelic_wl_send_iwap_event(wl, NULL);
2236 pr_info("%s: no scan list. association failed\n", __func__);
2240 /* find best matching bss */
2241 best_bss = gelic_wl_find_best_bss(wl);
2243 gelic_wl_send_iwap_event(wl, NULL);
2244 pr_info("%s: no bss matched. association failed\n", __func__);
2248 /* ok, do association */
2249 ret = gelic_wl_associate_bss(wl, best_bss);
2251 pr_info("%s: association failed %d\n", __func__, ret);
2253 mutex_unlock(&wl->scan_lock);
2255 mutex_unlock(&wl->assoc_stat_lock);
2259 * Called from the ethernet interrupt handler
2260 * Processes wireless specific virtual interrupts only
2262 void gelic_wl_interrupt(struct net_device *netdev, u64 status)
2264 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2266 if (status & GELIC_CARD_WLAN_COMMAND_COMPLETED) {
2267 pr_debug("%s:cmd complete\n", __func__);
2268 complete(&wl->cmd_done_intr);
2271 if (status & GELIC_CARD_WLAN_EVENT_RECEIVED) {
2272 pr_debug("%s:event received\n", __func__);
2273 queue_delayed_work(wl->event_queue, &wl->event_work, 0);
2280 #define IW_IOCTL(n) [(n) - SIOCSIWCOMMIT]
2281 static const iw_handler gelic_wl_wext_handler[] =
2283 IW_IOCTL(SIOCGIWNAME) = gelic_wl_get_name,
2284 IW_IOCTL(SIOCGIWRANGE) = gelic_wl_get_range,
2285 IW_IOCTL(SIOCSIWSCAN) = gelic_wl_set_scan,
2286 IW_IOCTL(SIOCGIWSCAN) = gelic_wl_get_scan,
2287 IW_IOCTL(SIOCSIWAUTH) = gelic_wl_set_auth,
2288 IW_IOCTL(SIOCGIWAUTH) = gelic_wl_get_auth,
2289 IW_IOCTL(SIOCSIWESSID) = gelic_wl_set_essid,
2290 IW_IOCTL(SIOCGIWESSID) = gelic_wl_get_essid,
2291 IW_IOCTL(SIOCSIWENCODE) = gelic_wl_set_encode,
2292 IW_IOCTL(SIOCGIWENCODE) = gelic_wl_get_encode,
2293 IW_IOCTL(SIOCSIWAP) = gelic_wl_set_ap,
2294 IW_IOCTL(SIOCGIWAP) = gelic_wl_get_ap,
2295 IW_IOCTL(SIOCSIWENCODEEXT) = gelic_wl_set_encodeext,
2296 IW_IOCTL(SIOCGIWENCODEEXT) = gelic_wl_get_encodeext,
2297 IW_IOCTL(SIOCSIWMODE) = gelic_wl_set_mode,
2298 IW_IOCTL(SIOCGIWMODE) = gelic_wl_get_mode,
2299 IW_IOCTL(SIOCGIWNICKN) = gelic_wl_get_nick,
2302 static const struct iw_handler_def gelic_wl_wext_handler_def = {
2303 .num_standard = ARRAY_SIZE(gelic_wl_wext_handler),
2304 .standard = gelic_wl_wext_handler,
2305 .get_wireless_stats = gelic_wl_get_wireless_stats,
2308 static struct net_device * __devinit gelic_wl_alloc(struct gelic_card *card)
2310 struct net_device *netdev;
2311 struct gelic_port *port;
2312 struct gelic_wl_info *wl;
2315 pr_debug("%s:start\n", __func__);
2316 netdev = alloc_etherdev(sizeof(struct gelic_port) +
2317 sizeof(struct gelic_wl_info));
2318 pr_debug("%s: netdev =%p card=%p \np", __func__, netdev, card);
2322 strcpy(netdev->name, "wlan%d");
2324 port = netdev_priv(netdev);
2325 port->netdev = netdev;
2327 port->type = GELIC_PORT_WIRELESS;
2330 pr_debug("%s: wl=%p port=%p\n", __func__, wl, port);
2332 /* allocate scan list */
2333 wl->networks = kzalloc(sizeof(struct gelic_wl_scan_info) *
2334 GELIC_WL_BSS_MAX_ENT, GFP_KERNEL);
2339 wl->eurus_cmd_queue = create_singlethread_workqueue("gelic_cmd");
2340 if (!wl->eurus_cmd_queue)
2341 goto fail_cmd_workqueue;
2343 wl->event_queue = create_singlethread_workqueue("gelic_event");
2344 if (!wl->event_queue)
2345 goto fail_event_workqueue;
2347 INIT_LIST_HEAD(&wl->network_free_list);
2348 INIT_LIST_HEAD(&wl->network_list);
2349 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++)
2350 list_add_tail(&wl->networks[i].list,
2351 &wl->network_free_list);
2352 init_completion(&wl->cmd_done_intr);
2354 INIT_DELAYED_WORK(&wl->event_work, gelic_wl_event_worker);
2355 INIT_DELAYED_WORK(&wl->assoc_work, gelic_wl_assoc_worker);
2356 mutex_init(&wl->scan_lock);
2357 mutex_init(&wl->assoc_stat_lock);
2359 init_completion(&wl->scan_done);
2360 /* for the case that no scan request is issued and stop() is called */
2361 complete(&wl->scan_done);
2363 spin_lock_init(&wl->lock);
2365 wl->scan_age = 5*HZ; /* FIXME */
2367 /* buffer for receiving scanned list etc */
2368 BUILD_BUG_ON(PAGE_SIZE <
2369 sizeof(struct gelic_eurus_scan_info) *
2370 GELIC_EURUS_MAX_SCAN);
2371 pr_debug("%s:end\n", __func__);
2374 fail_event_workqueue:
2375 destroy_workqueue(wl->eurus_cmd_queue);
2377 kfree(wl->networks);
2379 free_netdev(netdev);
2380 pr_debug("%s:end error\n", __func__);
2385 static void gelic_wl_free(struct gelic_wl_info *wl)
2387 struct gelic_wl_scan_info *scan_info;
2390 pr_debug("%s: <-\n", __func__);
2392 pr_debug("%s: destroy queues\n", __func__);
2393 destroy_workqueue(wl->eurus_cmd_queue);
2394 destroy_workqueue(wl->event_queue);
2396 scan_info = wl->networks;
2397 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++, scan_info++)
2398 kfree(scan_info->hwinfo);
2399 kfree(wl->networks);
2401 free_netdev(port_to_netdev(wl_port(wl)));
2403 pr_debug("%s: ->\n", __func__);
2406 static int gelic_wl_try_associate(struct net_device *netdev)
2408 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2412 pr_debug("%s: <-\n", __func__);
2414 /* check constraits for start association */
2415 /* for no access restriction AP */
2416 if (wl->group_cipher_method == GELIC_WL_CIPHER_NONE) {
2417 if (test_bit(GELIC_WL_STAT_CONFIGURED,
2421 pr_debug("%s: no wep, not configured\n", __func__);
2426 /* for WEP, one of four keys should be set */
2427 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
2428 /* one of keys set */
2429 for (i = 0; i < GELIC_WEP_KEYS; i++) {
2430 if (test_bit(i, &wl->key_enabled))
2433 pr_debug("%s: WEP, but no key specified\n", __func__);
2437 /* for WPA[2], psk should be set */
2438 if ((wl->group_cipher_method == GELIC_WL_CIPHER_TKIP) ||
2439 (wl->group_cipher_method == GELIC_WL_CIPHER_AES)) {
2440 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET,
2444 pr_debug("%s: AES/TKIP, but PSK not configured\n",
2451 ret = schedule_delayed_work(&wl->assoc_work, 0);
2452 pr_debug("%s: start association work %d\n", __func__, ret);
2459 static int gelic_wl_open(struct net_device *netdev)
2461 struct gelic_card *card = netdev_card(netdev);
2463 pr_debug("%s:->%p\n", __func__, netdev);
2465 gelic_card_up(card);
2467 /* try to associate */
2468 gelic_wl_try_associate(netdev);
2470 netif_start_queue(netdev);
2472 pr_debug("%s:<-\n", __func__);
2477 * reset state machine
2479 static int gelic_wl_reset_state(struct gelic_wl_info *wl)
2481 struct gelic_wl_scan_info *target;
2482 struct gelic_wl_scan_info *tmp;
2484 /* empty scan list */
2485 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
2486 list_move_tail(&target->list, &wl->network_free_list);
2488 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
2490 /* clear configuration */
2491 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
2492 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
2493 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
2494 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
2496 wl->key_enabled = 0;
2497 wl->current_key = 0;
2499 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
2503 memset(wl->essid, 0, sizeof(wl->essid));
2504 memset(wl->bssid, 0, sizeof(wl->bssid));
2505 memset(wl->active_bssid, 0, sizeof(wl->active_bssid));
2507 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2509 memset(&wl->iwstat, 0, sizeof(wl->iwstat));
2510 /* all status bit clear */
2516 * Tell eurus to terminate association
2518 static void gelic_wl_disconnect(struct net_device *netdev)
2520 struct gelic_port *port = netdev_priv(netdev);
2521 struct gelic_wl_info *wl = port_wl(port);
2522 struct gelic_eurus_cmd *cmd;
2525 * If scann process is running on chip,
2526 * further requests will be rejected
2528 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING)
2529 wait_for_completion_timeout(&wl->scan_done, HZ);
2531 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2533 gelic_wl_send_iwap_event(wl, NULL);
2536 static int gelic_wl_stop(struct net_device *netdev)
2538 struct gelic_port *port = netdev_priv(netdev);
2539 struct gelic_wl_info *wl = port_wl(port);
2540 struct gelic_card *card = netdev_card(netdev);
2542 pr_debug("%s:<-\n", __func__);
2545 * Cancel pending association work.
2546 * event work can run after netdev down
2548 cancel_delayed_work(&wl->assoc_work);
2550 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2551 gelic_wl_disconnect(netdev);
2553 /* reset our state machine */
2554 gelic_wl_reset_state(wl);
2556 netif_stop_queue(netdev);
2558 gelic_card_down(card);
2560 pr_debug("%s:->\n", __func__);
2566 static const struct net_device_ops gelic_wl_netdevice_ops = {
2567 .ndo_open = gelic_wl_open,
2568 .ndo_stop = gelic_wl_stop,
2569 .ndo_start_xmit = gelic_net_xmit,
2570 .ndo_set_multicast_list = gelic_net_set_multi,
2571 .ndo_change_mtu = gelic_net_change_mtu,
2572 .ndo_tx_timeout = gelic_net_tx_timeout,
2573 .ndo_set_mac_address = eth_mac_addr,
2574 .ndo_validate_addr = eth_validate_addr,
2575 #ifdef CONFIG_NET_POLL_CONTROLLER
2576 .ndo_poll_controller = gelic_net_poll_controller,
2580 static const struct ethtool_ops gelic_wl_ethtool_ops = {
2581 .get_drvinfo = gelic_net_get_drvinfo,
2582 .get_link = gelic_wl_get_link,
2583 .get_tx_csum = ethtool_op_get_tx_csum,
2584 .set_tx_csum = ethtool_op_set_tx_csum,
2585 .get_rx_csum = gelic_net_get_rx_csum,
2586 .set_rx_csum = gelic_net_set_rx_csum,
2589 static void __devinit gelic_wl_setup_netdev_ops(struct net_device *netdev)
2591 struct gelic_wl_info *wl;
2592 wl = port_wl(netdev_priv(netdev));
2594 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
2596 netdev->ethtool_ops = &gelic_wl_ethtool_ops;
2597 netdev->netdev_ops = &gelic_wl_netdevice_ops;
2598 netdev->wireless_data = &wl->wireless_data;
2599 netdev->wireless_handlers = &gelic_wl_wext_handler_def;
2603 * driver probe/remove
2605 int __devinit gelic_wl_driver_probe(struct gelic_card *card)
2608 struct net_device *netdev;
2610 pr_debug("%s:start\n", __func__);
2612 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2614 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2617 /* alloc netdevice for wireless */
2618 netdev = gelic_wl_alloc(card);
2622 /* setup net_device structure */
2623 SET_NETDEV_DEV(netdev, &card->dev->core);
2624 gelic_wl_setup_netdev_ops(netdev);
2626 /* setup some of net_device and register it */
2627 ret = gelic_net_setup_netdev(netdev, card);
2630 card->netdev[GELIC_PORT_WIRELESS] = netdev;
2632 /* add enable wireless interrupt */
2633 card->irq_mask |= GELIC_CARD_WLAN_EVENT_RECEIVED |
2634 GELIC_CARD_WLAN_COMMAND_COMPLETED;
2635 /* to allow wireless commands while both interfaces are down */
2636 gelic_card_set_irq_mask(card, GELIC_CARD_WLAN_EVENT_RECEIVED |
2637 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2638 pr_debug("%s:end\n", __func__);
2642 gelic_wl_free(port_wl(netdev_port(netdev)));
2647 int gelic_wl_driver_remove(struct gelic_card *card)
2649 struct gelic_wl_info *wl;
2650 struct net_device *netdev;
2652 pr_debug("%s:start\n", __func__);
2654 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2656 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2659 netdev = card->netdev[GELIC_PORT_WIRELESS];
2660 wl = port_wl(netdev_priv(netdev));
2662 /* if the interface was not up, but associated */
2663 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2664 gelic_wl_disconnect(netdev);
2666 complete(&wl->cmd_done_intr);
2668 /* cancel all work queue */
2669 cancel_delayed_work(&wl->assoc_work);
2670 cancel_delayed_work(&wl->event_work);
2671 flush_workqueue(wl->eurus_cmd_queue);
2672 flush_workqueue(wl->event_queue);
2674 unregister_netdev(netdev);
2676 /* disable wireless interrupt */
2677 pr_debug("%s: disable intr\n", __func__);
2678 card->irq_mask &= ~(GELIC_CARD_WLAN_EVENT_RECEIVED |
2679 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2680 /* free bss list, netdev*/
2682 pr_debug("%s:end\n", __func__);