2 * PS3 gelic network driver.
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/etherdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/if_vlan.h>
31 #include <linux/tcp.h>
32 #include <linux/wireless.h>
33 #include <linux/ctype.h>
34 #include <linux/string.h>
35 #include <net/iw_handler.h>
36 #include <net/ieee80211.h>
38 #include <linux/dma-mapping.h>
39 #include <net/checksum.h>
40 #include <asm/firmware.h>
42 #include <asm/lv1call.h>
44 #include "ps3_gelic_net.h"
45 #include "ps3_gelic_wireless.h"
48 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan);
49 static int gelic_wl_try_associate(struct net_device *netdev);
55 /* 802.11b/g channel to freq in MHz */
56 static const int channel_freq[] = {
57 2412, 2417, 2422, 2427, 2432,
58 2437, 2442, 2447, 2452, 2457,
59 2462, 2467, 2472, 2484
61 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
64 static const int bitrate_list[] = {
78 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
81 * wpa2 support requires the hypervisor version 2.0 or later
83 static inline int wpa2_capable(void)
85 return (0 <= ps3_compare_firmware_version(2, 0, 0));
88 static inline int precise_ie(void)
90 return (0 <= ps3_compare_firmware_version(2, 2, 0));
93 * post_eurus_cmd helpers
95 struct eurus_cmd_arg_info {
96 int pre_arg; /* command requres arg1, arg2 at POST COMMAND */
97 int post_arg; /* command requires arg1, arg2 at GET_RESULT */
100 static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
101 [GELIC_EURUS_CMD_SET_COMMON_CFG] = { .pre_arg = 1},
102 [GELIC_EURUS_CMD_SET_WEP_CFG] = { .pre_arg = 1},
103 [GELIC_EURUS_CMD_SET_WPA_CFG] = { .pre_arg = 1},
104 [GELIC_EURUS_CMD_GET_COMMON_CFG] = { .post_arg = 1},
105 [GELIC_EURUS_CMD_GET_WEP_CFG] = { .post_arg = 1},
106 [GELIC_EURUS_CMD_GET_WPA_CFG] = { .post_arg = 1},
107 [GELIC_EURUS_CMD_GET_RSSI_CFG] = { .post_arg = 1},
108 [GELIC_EURUS_CMD_GET_SCAN] = { .post_arg = 1},
112 static const char *cmdstr(enum gelic_eurus_command ix)
115 case GELIC_EURUS_CMD_ASSOC:
117 case GELIC_EURUS_CMD_DISASSOC:
119 case GELIC_EURUS_CMD_START_SCAN:
121 case GELIC_EURUS_CMD_GET_SCAN:
123 case GELIC_EURUS_CMD_SET_COMMON_CFG:
124 return "SET_COMMON_CFG";
125 case GELIC_EURUS_CMD_GET_COMMON_CFG:
126 return "GET_COMMON_CFG";
127 case GELIC_EURUS_CMD_SET_WEP_CFG:
128 return "SET_WEP_CFG";
129 case GELIC_EURUS_CMD_GET_WEP_CFG:
130 return "GET_WEP_CFG";
131 case GELIC_EURUS_CMD_SET_WPA_CFG:
132 return "SET_WPA_CFG";
133 case GELIC_EURUS_CMD_GET_WPA_CFG:
134 return "GET_WPA_CFG";
135 case GELIC_EURUS_CMD_GET_RSSI_CFG:
143 static inline const char *cmdstr(enum gelic_eurus_command ix)
149 /* synchronously do eurus commands */
150 static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
152 struct gelic_eurus_cmd *cmd;
153 struct gelic_card *card;
154 struct gelic_wl_info *wl;
158 pr_debug("%s: <-\n", __func__);
159 cmd = container_of(work, struct gelic_eurus_cmd, work);
160 BUG_ON(cmd_info[cmd->cmd].pre_arg &&
161 cmd_info[cmd->cmd].post_arg);
163 card = port_to_card(wl_port(wl));
165 if (cmd_info[cmd->cmd].pre_arg) {
166 arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
167 arg2 = cmd->buf_size;
172 init_completion(&wl->cmd_done_intr);
173 pr_debug("%s: cmd='%s' start\n", __func__, cmdstr(cmd->cmd));
174 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
175 GELIC_LV1_POST_WLAN_CMD,
176 cmd->cmd, arg1, arg2,
177 &cmd->tag, &cmd->size);
179 complete(&cmd->done);
180 pr_info("%s: cmd issue failed\n", __func__);
184 wait_for_completion(&wl->cmd_done_intr);
186 if (cmd_info[cmd->cmd].post_arg) {
187 arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
188 arg2 = cmd->buf_size;
194 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
195 GELIC_LV1_GET_WLAN_CMD_RESULT,
196 cmd->tag, arg1, arg2,
197 &cmd->cmd_status, &cmd->size);
199 if (cmd->status || cmd->cmd_status) {
200 pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__,
201 cmd->tag, arg1, arg2);
202 pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
203 __func__, cmd->status, cmd->cmd_status, cmd->size);
206 complete(&cmd->done);
207 pr_debug("%s: cmd='%s' done\n", __func__, cmdstr(cmd->cmd));
210 static struct gelic_eurus_cmd *gelic_eurus_sync_cmd(struct gelic_wl_info *wl,
211 unsigned int eurus_cmd,
213 unsigned int buf_size)
215 struct gelic_eurus_cmd *cmd;
218 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
222 /* initialize members */
223 cmd->cmd = eurus_cmd;
224 cmd->buffer = buffer;
225 cmd->buf_size = buf_size;
227 INIT_WORK(&cmd->work, gelic_eurus_sync_cmd_worker);
228 init_completion(&cmd->done);
229 queue_work(wl->eurus_cmd_queue, &cmd->work);
231 /* wait for command completion */
232 wait_for_completion(&cmd->done);
237 static u32 gelic_wl_get_link(struct net_device *netdev)
239 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
242 pr_debug("%s: <-\n", __func__);
243 mutex_lock(&wl->assoc_stat_lock);
244 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
248 mutex_unlock(&wl->assoc_stat_lock);
249 pr_debug("%s: ->\n", __func__);
253 static void gelic_wl_send_iwap_event(struct gelic_wl_info *wl, u8 *bssid)
255 union iwreq_data data;
257 memset(&data, 0, sizeof(data));
259 memcpy(data.ap_addr.sa_data, bssid, ETH_ALEN);
260 data.ap_addr.sa_family = ARPHRD_ETHER;
261 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWAP,
266 * wireless extension handlers and helpers
270 static int gelic_wl_get_name(struct net_device *dev,
271 struct iw_request_info *info,
272 union iwreq_data *iwreq, char *extra)
274 strcpy(iwreq->name, "IEEE 802.11bg");
278 static void gelic_wl_get_ch_info(struct gelic_wl_info *wl)
280 struct gelic_card *card = port_to_card(wl_port(wl));
281 u64 ch_info_raw, tmp;
284 if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO, &wl->stat)) {
285 status = lv1_net_control(bus_id(card), dev_id(card),
286 GELIC_LV1_GET_CHANNEL, 0, 0, 0,
289 /* some fw versions may return error */
291 if (status != LV1_NO_ENTRY)
292 pr_info("%s: available ch unknown\n", __func__);
293 wl->ch_info = 0x07ff;/* 11 ch */
295 /* 16 bits of MSB has available channels */
296 wl->ch_info = ch_info_raw >> 48;
302 static int gelic_wl_get_range(struct net_device *netdev,
303 struct iw_request_info *info,
304 union iwreq_data *iwreq, char *extra)
306 struct iw_point *point = &iwreq->data;
307 struct iw_range *range = (struct iw_range *)extra;
308 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
311 pr_debug("%s: <-\n", __func__);
312 point->length = sizeof(struct iw_range);
313 memset(range, 0, sizeof(struct iw_range));
315 range->we_version_compiled = WIRELESS_EXT;
316 range->we_version_source = 22;
318 /* available channels and frequencies */
319 gelic_wl_get_ch_info(wl);
322 i < NUM_CHANNELS && chs < IW_MAX_FREQUENCIES; i++)
323 if (wl->ch_info & (1 << i)) {
324 range->freq[chs].i = i + 1;
325 range->freq[chs].m = channel_freq[i];
326 range->freq[chs].e = 6;
329 range->num_frequency = chs;
330 range->old_num_frequency = chs;
331 range->num_channels = chs;
332 range->old_num_channels = chs;
335 for (i = 0; i < NUM_BITRATES; i++)
336 range->bitrate[i] = bitrate_list[i];
337 range->num_bitrates = i;
340 range->max_qual.qual = 100; /* relative value */
341 range->max_qual.level = 100;
342 range->avg_qual.qual = 50;
343 range->avg_qual.level = 50;
344 range->sensitivity = 0;
346 /* Event capability */
347 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
348 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
349 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
351 /* encryption capability */
352 range->enc_capa = IW_ENC_CAPA_WPA |
353 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP |
354 IW_ENC_CAPA_4WAY_HANDSHAKE;
356 range->enc_capa |= IW_ENC_CAPA_WPA2;
357 range->encoding_size[0] = 5; /* 40bit WEP */
358 range->encoding_size[1] = 13; /* 104bit WEP */
359 range->encoding_size[2] = 32; /* WPA-PSK */
360 range->num_encoding_sizes = 3;
361 range->max_encoding_tokens = GELIC_WEP_KEYS;
363 pr_debug("%s: ->\n", __func__);
368 /* SIOC{G,S}IWSCAN */
369 static int gelic_wl_set_scan(struct net_device *netdev,
370 struct iw_request_info *info,
371 union iwreq_data *wrqu, char *extra)
373 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
375 return gelic_wl_start_scan(wl, 1);
379 static const u8 rsn_oui[OUI_LEN] = { 0x00, 0x0f, 0xac };
380 static const u8 wpa_oui[OUI_LEN] = { 0x00, 0x50, 0xf2 };
383 * synthesize WPA/RSN IE data
384 * See WiFi WPA specification and IEEE 802.11-2007 7.3.2.25
387 static size_t gelic_wl_synthesize_ie(u8 *buf,
388 struct gelic_eurus_scan_info *scan)
391 const u8 *oui_header;
396 pr_debug("%s: <- sec=%16x\n", __func__, scan->security);
397 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_MASK) {
398 case GELIC_EURUS_SCAN_SEC_WPA:
401 case GELIC_EURUS_SCAN_SEC_WPA2:
405 /* WEP or none. No IE returned */
409 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_WPA_MASK) {
410 case GELIC_EURUS_SCAN_SEC_WPA_TKIP:
413 case GELIC_EURUS_SCAN_SEC_WPA_AES:
419 pr_info("%s: no cipher info. defaulted to CCMP\n",
423 pr_info("%s: no cipher info. defaulted to TKIP\n",
429 oui_header = rsn_oui;
431 oui_header = wpa_oui;
435 *buf++ = MFIE_TYPE_RSN;
437 *buf++ = MFIE_TYPE_GENERIC;
439 /* length filed; set later */
442 /* wpa special header */
444 memcpy(buf, wpa_oui, OUI_LEN);
450 *buf++ = 0x01; /* version 1.0 */
454 memcpy(buf, oui_header, OUI_LEN);
458 *buf++ = 0x04; /* CCMP */
460 *buf++ = 0x02; /* TKIP */
462 /* pairwise key count always 1 */
466 /* pairwise key suit */
467 memcpy(buf, oui_header, OUI_LEN);
470 *buf++ = 0x04; /* CCMP */
472 *buf++ = 0x02; /* TKIP */
478 /* AKM suite is assumed as PSK*/
479 memcpy(buf, oui_header, OUI_LEN);
481 *buf++ = 0x02; /* PSK */
483 /* RSN capabilities is 0 */
487 /* set length field */
488 start[1] = (buf - start - 2);
490 pr_debug("%s: ->\n", __func__);
491 return (buf - start);
504 static void gelic_wl_parse_ie(u8 *data, size_t len,
505 struct ie_info *ie_info)
507 size_t data_left = len;
512 pr_debug("%s: data=%p len=%ld \n", __func__,
514 memset(ie_info, 0, sizeof(struct ie_info));
516 while (2 <= data_left) {
521 if (data_left < item_len)
525 case MFIE_TYPE_GENERIC:
526 if ((OUI_LEN + 1 <= item_len) &&
527 !memcmp(pos, wpa_oui, OUI_LEN) &&
528 pos[OUI_LEN] == 0x01) {
529 ie_info->wpa.data = pos - 2;
530 ie_info->wpa.len = item_len + 2;
534 ie_info->rsn.data = pos - 2;
535 /* length includes the header */
536 ie_info->rsn.len = item_len + 2;
539 pr_debug("%s: ignore %#x,%d\n", __func__,
544 data_left -= item_len;
546 pr_debug("%s: wpa=%p,%d wpa2=%p,%d\n", __func__,
547 ie_info->wpa.data, ie_info->wpa.len,
548 ie_info->rsn.data, ie_info->rsn.len);
553 * translate the scan informations from hypervisor to a
556 static char *gelic_wl_translate_scan(struct net_device *netdev,
559 struct gelic_wl_scan_info *network)
562 struct gelic_eurus_scan_info *scan = network->hwinfo;
565 unsigned int i, j, len;
566 u8 buf[MAX_WPA_IE_LEN];
568 pr_debug("%s: <-\n", __func__);
570 /* first entry should be AP's mac address */
572 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
573 memcpy(iwe.u.ap_addr.sa_data, &scan->bssid[2], ETH_ALEN);
574 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_ADDR_LEN);
577 iwe.cmd = SIOCGIWESSID;
578 iwe.u.data.flags = 1;
579 iwe.u.data.length = strnlen(scan->essid, 32);
580 ev = iwe_stream_add_point(ev, stop, &iwe, scan->essid);
583 iwe.cmd = SIOCGIWFREQ;
584 iwe.u.freq.m = be16_to_cpu(scan->channel);
585 iwe.u.freq.e = 0; /* table value in MHz */
587 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_FREQ_LEN);
590 iwe.cmd = SIOCGIWRATE;
591 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
592 /* to stuff multiple values in one event */
593 tmp = ev + IW_EV_LCP_LEN;
594 /* put them in ascendant order (older is first) */
597 pr_debug("%s: rates=%d rate=%d\n", __func__,
598 network->rate_len, network->rate_ext_len);
599 while (i < network->rate_len) {
600 if (j < network->rate_ext_len &&
601 ((scan->ext_rate[j] & 0x7f) < (scan->rate[i] & 0x7f)))
602 rate = scan->ext_rate[j++] & 0x7f;
604 rate = scan->rate[i++] & 0x7f;
605 iwe.u.bitrate.value = rate * 500000; /* 500kbps unit */
606 tmp = iwe_stream_add_value(ev, tmp, stop, &iwe,
609 while (j < network->rate_ext_len) {
610 iwe.u.bitrate.value = (scan->ext_rate[j++] & 0x7f) * 500000;
611 tmp = iwe_stream_add_value(ev, tmp, stop, &iwe,
614 /* Check if we added any rate */
615 if (IW_EV_LCP_LEN < (tmp - ev))
619 iwe.cmd = SIOCGIWENCODE;
620 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_PRIVACY)
621 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
623 iwe.u.data.flags = IW_ENCODE_DISABLED;
624 iwe.u.data.length = 0;
625 ev = iwe_stream_add_point(ev, stop, &iwe, scan->essid);
628 iwe.cmd = SIOCGIWMODE;
629 if (be16_to_cpu(scan->capability) &
630 (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
631 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_ESS)
632 iwe.u.mode = IW_MODE_MASTER;
634 iwe.u.mode = IW_MODE_ADHOC;
635 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_UINT_LEN);
640 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED |
641 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
642 iwe.u.qual.level = be16_to_cpu(scan->rssi);
643 iwe.u.qual.qual = be16_to_cpu(scan->rssi);
644 iwe.u.qual.noise = 0;
645 ev = iwe_stream_add_event(ev, stop, &iwe, IW_EV_QUAL_LEN);
648 memset(&iwe, 0, sizeof(iwe));
649 if (be16_to_cpu(scan->size) <= sizeof(*scan)) {
650 /* If wpa[2] capable station, synthesize IE and put it */
651 len = gelic_wl_synthesize_ie(buf, scan);
654 iwe.u.data.length = len;
655 ev = iwe_stream_add_point(ev, stop, &iwe, buf);
658 /* this scan info has IE data */
659 struct ie_info ie_info;
662 data_len = be16_to_cpu(scan->size) - sizeof(*scan);
664 gelic_wl_parse_ie(scan->elements, data_len, &ie_info);
666 if (ie_info.wpa.len && (ie_info.wpa.len <= sizeof(buf))) {
667 memcpy(buf, ie_info.wpa.data, ie_info.wpa.len);
669 iwe.u.data.length = ie_info.wpa.len;
670 ev = iwe_stream_add_point(ev, stop, &iwe, buf);
673 if (ie_info.rsn.len && (ie_info.rsn.len <= sizeof(buf))) {
674 memset(&iwe, 0, sizeof(iwe));
675 memcpy(buf, ie_info.rsn.data, ie_info.rsn.len);
677 iwe.u.data.length = ie_info.rsn.len;
678 ev = iwe_stream_add_point(ev, stop, &iwe, buf);
682 pr_debug("%s: ->\n", __func__);
687 static int gelic_wl_get_scan(struct net_device *netdev,
688 struct iw_request_info *info,
689 union iwreq_data *wrqu, char *extra)
691 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
692 struct gelic_wl_scan_info *scan_info;
694 char *stop = ev + wrqu->data.length;
696 unsigned long this_time = jiffies;
698 pr_debug("%s: <-\n", __func__);
699 if (mutex_lock_interruptible(&wl->scan_lock))
702 switch (wl->scan_stat) {
703 case GELIC_WL_SCAN_STAT_SCANNING:
704 /* If a scan in progress, caller should call me again */
709 case GELIC_WL_SCAN_STAT_INIT:
710 /* last scan request failed or never issued */
714 case GELIC_WL_SCAN_STAT_GOT_LIST:
715 /* ok, use current list */
719 list_for_each_entry(scan_info, &wl->network_list, list) {
720 if (wl->scan_age == 0 ||
721 time_after(scan_info->last_scanned + wl->scan_age,
723 ev = gelic_wl_translate_scan(netdev, ev, stop,
726 pr_debug("%s:entry too old\n", __func__);
728 if (stop - ev <= IW_EV_ADDR_LEN) {
734 wrqu->data.length = ev - extra;
735 wrqu->data.flags = 0;
737 mutex_unlock(&wl->scan_lock);
738 pr_debug("%s: -> %d %d\n", __func__, ret, wrqu->data.length);
743 static void scan_list_dump(struct gelic_wl_info *wl)
745 struct gelic_wl_scan_info *scan_info;
747 DECLARE_MAC_BUF(mac);
750 list_for_each_entry(scan_info, &wl->network_list, list) {
751 pr_debug("%s: item %d\n", __func__, i++);
752 pr_debug("valid=%d eurusindex=%d last=%lx\n",
753 scan_info->valid, scan_info->eurus_index,
754 scan_info->last_scanned);
755 pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
756 scan_info->rate_len, scan_info->rate_ext_len,
757 scan_info->essid_len);
759 pr_debug("bssid=%s\n",
760 print_mac(mac, &scan_info->hwinfo->bssid[2]));
761 pr_debug("essid=%s\n", scan_info->hwinfo->essid);
766 static int gelic_wl_set_auth(struct net_device *netdev,
767 struct iw_request_info *info,
768 union iwreq_data *data, char *extra)
770 struct iw_param *param = &data->param;
771 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
772 unsigned long irqflag;
775 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
776 spin_lock_irqsave(&wl->lock, irqflag);
777 switch (param->flags & IW_AUTH_INDEX) {
778 case IW_AUTH_WPA_VERSION:
779 if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
780 pr_debug("%s: NO WPA selected\n", __func__);
781 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
782 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
783 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
785 if (param->value & IW_AUTH_WPA_VERSION_WPA) {
786 pr_debug("%s: WPA version 1 selected\n", __func__);
787 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
788 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
789 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
790 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
792 if (param->value & IW_AUTH_WPA_VERSION_WPA2) {
794 * As the hypervisor may not tell the cipher
795 * information of the AP if it is WPA2,
796 * you will not decide suitable cipher from
798 * You should have knowledge about the AP's
799 * cipher infomation in other method prior to
803 pr_info("%s: WPA2 may not work\n", __func__);
804 if (wpa2_capable()) {
805 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
806 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
807 wl->pairwise_cipher_method =
809 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
815 case IW_AUTH_CIPHER_PAIRWISE:
817 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
818 pr_debug("%s: WEP selected\n", __func__);
819 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
821 if (param->value & IW_AUTH_CIPHER_TKIP) {
822 pr_debug("%s: TKIP selected\n", __func__);
823 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
825 if (param->value & IW_AUTH_CIPHER_CCMP) {
826 pr_debug("%s: CCMP selected\n", __func__);
827 wl->pairwise_cipher_method = GELIC_WL_CIPHER_AES;
829 if (param->value & IW_AUTH_CIPHER_NONE) {
830 pr_debug("%s: no auth selected\n", __func__);
831 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
834 case IW_AUTH_CIPHER_GROUP:
836 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
837 pr_debug("%s: WEP selected\n", __func__);
838 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
840 if (param->value & IW_AUTH_CIPHER_TKIP) {
841 pr_debug("%s: TKIP selected\n", __func__);
842 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
844 if (param->value & IW_AUTH_CIPHER_CCMP) {
845 pr_debug("%s: CCMP selected\n", __func__);
846 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
848 if (param->value & IW_AUTH_CIPHER_NONE) {
849 pr_debug("%s: no auth selected\n", __func__);
850 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
853 case IW_AUTH_80211_AUTH_ALG:
854 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
855 pr_debug("%s: shared key specified\n", __func__);
856 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
857 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
858 pr_debug("%s: open system specified\n", __func__);
859 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
864 case IW_AUTH_WPA_ENABLED:
866 pr_debug("%s: WPA enabled\n", __func__);
867 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
869 pr_debug("%s: WPA disabled\n", __func__);
870 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
874 case IW_AUTH_KEY_MGMT:
875 if (param->value & IW_AUTH_KEY_MGMT_PSK)
877 /* intentionally fall through */
884 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
886 spin_unlock_irqrestore(&wl->lock, irqflag);
887 pr_debug("%s: -> %d\n", __func__, ret);
891 static int gelic_wl_get_auth(struct net_device *netdev,
892 struct iw_request_info *info,
893 union iwreq_data *iwreq, char *extra)
895 struct iw_param *param = &iwreq->param;
896 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
897 unsigned long irqflag;
900 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
901 spin_lock_irqsave(&wl->lock, irqflag);
902 switch (param->flags & IW_AUTH_INDEX) {
903 case IW_AUTH_WPA_VERSION:
904 switch (wl->wpa_level) {
905 case GELIC_WL_WPA_LEVEL_WPA:
906 param->value |= IW_AUTH_WPA_VERSION_WPA;
908 case GELIC_WL_WPA_LEVEL_WPA2:
909 param->value |= IW_AUTH_WPA_VERSION_WPA2;
912 param->value |= IW_AUTH_WPA_VERSION_DISABLED;
916 case IW_AUTH_80211_AUTH_ALG:
917 if (wl->auth_method == GELIC_EURUS_AUTH_SHARED)
918 param->value = IW_AUTH_ALG_SHARED_KEY;
919 else if (wl->auth_method == GELIC_EURUS_AUTH_OPEN)
920 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
923 case IW_AUTH_WPA_ENABLED:
924 switch (wl->wpa_level) {
925 case GELIC_WL_WPA_LEVEL_WPA:
926 case GELIC_WL_WPA_LEVEL_WPA2:
938 spin_unlock_irqrestore(&wl->lock, irqflag);
939 pr_debug("%s: -> %d\n", __func__, ret);
943 /* SIOC{S,G}IWESSID */
944 static int gelic_wl_set_essid(struct net_device *netdev,
945 struct iw_request_info *info,
946 union iwreq_data *data, char *extra)
948 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
949 unsigned long irqflag;
951 pr_debug("%s: <- l=%d f=%d\n", __func__,
952 data->essid.length, data->essid.flags);
953 if (IW_ESSID_MAX_SIZE < data->essid.length)
956 spin_lock_irqsave(&wl->lock, irqflag);
957 if (data->essid.flags) {
958 wl->essid_len = data->essid.length;
959 memcpy(wl->essid, extra, wl->essid_len);
960 pr_debug("%s: essid = '%s'\n", __func__, extra);
961 set_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
963 pr_debug("%s: ESSID any \n", __func__);
964 clear_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
966 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
967 spin_unlock_irqrestore(&wl->lock, irqflag);
970 gelic_wl_try_associate(netdev); /* FIXME */
971 pr_debug("%s: -> \n", __func__);
975 static int gelic_wl_get_essid(struct net_device *netdev,
976 struct iw_request_info *info,
977 union iwreq_data *data, char *extra)
979 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
980 unsigned long irqflag;
982 pr_debug("%s: <- \n", __func__);
983 mutex_lock(&wl->assoc_stat_lock);
984 spin_lock_irqsave(&wl->lock, irqflag);
985 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat) ||
986 wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
987 memcpy(extra, wl->essid, wl->essid_len);
988 data->essid.length = wl->essid_len;
989 data->essid.flags = 1;
991 data->essid.flags = 0;
993 mutex_unlock(&wl->assoc_stat_lock);
994 spin_unlock_irqrestore(&wl->lock, irqflag);
995 pr_debug("%s: -> len=%d \n", __func__, data->essid.length);
1000 /* SIO{S,G}IWENCODE */
1001 static int gelic_wl_set_encode(struct net_device *netdev,
1002 struct iw_request_info *info,
1003 union iwreq_data *data, char *extra)
1005 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1006 struct iw_point *enc = &data->encoding;
1008 unsigned int irqflag;
1009 int key_index, index_specified;
1012 pr_debug("%s: <- \n", __func__);
1013 flags = enc->flags & IW_ENCODE_FLAGS;
1014 key_index = enc->flags & IW_ENCODE_INDEX;
1016 pr_debug("%s: key_index = %d\n", __func__, key_index);
1017 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1018 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1020 if (GELIC_WEP_KEYS < key_index)
1023 spin_lock_irqsave(&wl->lock, irqflag);
1025 index_specified = 1;
1028 index_specified = 0;
1029 key_index = wl->current_key;
1032 if (flags & IW_ENCODE_NOKEY) {
1033 /* if just IW_ENCODE_NOKEY, change current key index */
1034 if (!flags && index_specified) {
1035 wl->current_key = key_index;
1039 if (flags & IW_ENCODE_DISABLED) {
1040 if (!index_specified) {
1041 /* disable encryption */
1042 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1043 wl->pairwise_cipher_method =
1044 GELIC_WL_CIPHER_NONE;
1045 /* invalidate all key */
1046 wl->key_enabled = 0;
1048 clear_bit(key_index, &wl->key_enabled);
1051 if (flags & IW_ENCODE_OPEN)
1052 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1053 if (flags & IW_ENCODE_RESTRICTED) {
1054 pr_info("%s: shared key mode enabled\n", __func__);
1055 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1058 if (IW_ENCODING_TOKEN_MAX < enc->length) {
1062 wl->key_len[key_index] = enc->length;
1063 memcpy(wl->key[key_index], extra, enc->length);
1064 set_bit(key_index, &wl->key_enabled);
1065 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
1066 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
1068 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1070 spin_unlock_irqrestore(&wl->lock, irqflag);
1071 pr_debug("%s: -> \n", __func__);
1075 static int gelic_wl_get_encode(struct net_device *netdev,
1076 struct iw_request_info *info,
1077 union iwreq_data *data, char *extra)
1079 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1080 struct iw_point *enc = &data->encoding;
1081 unsigned int irqflag;
1082 unsigned int key_index, index_specified;
1085 pr_debug("%s: <- \n", __func__);
1086 key_index = enc->flags & IW_ENCODE_INDEX;
1087 pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
1088 enc->flags, enc->pointer, enc->length, extra);
1089 if (GELIC_WEP_KEYS < key_index)
1092 spin_lock_irqsave(&wl->lock, irqflag);
1094 index_specified = 1;
1097 index_specified = 0;
1098 key_index = wl->current_key;
1101 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1102 switch (wl->auth_method) {
1103 case GELIC_EURUS_AUTH_OPEN:
1104 enc->flags = IW_ENCODE_OPEN;
1106 case GELIC_EURUS_AUTH_SHARED:
1107 enc->flags = IW_ENCODE_RESTRICTED;
1111 enc->flags = IW_ENCODE_DISABLED;
1113 if (test_bit(key_index, &wl->key_enabled)) {
1114 if (enc->length < wl->key_len[key_index]) {
1118 enc->length = wl->key_len[key_index];
1119 memcpy(extra, wl->key[key_index], wl->key_len[key_index]);
1122 enc->flags |= IW_ENCODE_NOKEY;
1124 enc->flags |= key_index + 1;
1125 pr_debug("%s: -> flag=%x len=%d\n", __func__,
1126 enc->flags, enc->length);
1129 spin_unlock_irqrestore(&wl->lock, irqflag);
1134 static int gelic_wl_set_ap(struct net_device *netdev,
1135 struct iw_request_info *info,
1136 union iwreq_data *data, char *extra)
1138 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1139 unsigned long irqflag;
1141 pr_debug("%s: <-\n", __func__);
1142 if (data->ap_addr.sa_family != ARPHRD_ETHER)
1145 spin_lock_irqsave(&wl->lock, irqflag);
1146 if (is_valid_ether_addr(data->ap_addr.sa_data)) {
1147 memcpy(wl->bssid, data->ap_addr.sa_data,
1149 set_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1150 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1151 pr_debug("%s: bss=%02x:%02x:%02x:%02x:%02x:%02x\n",
1153 wl->bssid[0], wl->bssid[1],
1154 wl->bssid[2], wl->bssid[3],
1155 wl->bssid[4], wl->bssid[5]);
1157 pr_debug("%s: clear bssid\n", __func__);
1158 clear_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1159 memset(wl->bssid, 0, ETH_ALEN);
1161 spin_unlock_irqrestore(&wl->lock, irqflag);
1162 pr_debug("%s: ->\n", __func__);
1166 static int gelic_wl_get_ap(struct net_device *netdev,
1167 struct iw_request_info *info,
1168 union iwreq_data *data, char *extra)
1170 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1171 unsigned long irqflag;
1173 pr_debug("%s: <-\n", __func__);
1174 mutex_lock(&wl->assoc_stat_lock);
1175 spin_lock_irqsave(&wl->lock, irqflag);
1176 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1177 data->ap_addr.sa_family = ARPHRD_ETHER;
1178 memcpy(data->ap_addr.sa_data, wl->active_bssid,
1181 memset(data->ap_addr.sa_data, 0, ETH_ALEN);
1183 spin_unlock_irqrestore(&wl->lock, irqflag);
1184 mutex_unlock(&wl->assoc_stat_lock);
1185 pr_debug("%s: ->\n", __func__);
1189 /* SIOC{S,G}IWENCODEEXT */
1190 static int gelic_wl_set_encodeext(struct net_device *netdev,
1191 struct iw_request_info *info,
1192 union iwreq_data *data, char *extra)
1194 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1195 struct iw_point *enc = &data->encoding;
1196 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1199 unsigned int irqflag;
1203 pr_debug("%s: <- \n", __func__);
1204 flags = enc->flags & IW_ENCODE_FLAGS;
1206 key_index = enc->flags & IW_ENCODE_INDEX;
1208 pr_debug("%s: key_index = %d\n", __func__, key_index);
1209 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1210 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1211 pr_debug("%s: ext_flag=%x\n", __func__, ext->ext_flags);
1212 pr_debug("%s: ext_key_len=%x\n", __func__, ext->key_len);
1214 if (GELIC_WEP_KEYS < key_index)
1217 spin_lock_irqsave(&wl->lock, irqflag);
1221 key_index = wl->current_key;
1223 if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
1224 /* reques to change default key index */
1225 pr_debug("%s: request to change default key to %d\n",
1226 __func__, key_index);
1227 wl->current_key = key_index;
1231 if (alg == IW_ENCODE_ALG_NONE || (flags & IW_ENCODE_DISABLED)) {
1232 pr_debug("%s: alg disabled\n", __func__);
1233 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
1234 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1235 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
1236 wl->auth_method = GELIC_EURUS_AUTH_OPEN; /* should be open */
1237 } else if (alg == IW_ENCODE_ALG_WEP) {
1238 pr_debug("%s: WEP requested\n", __func__);
1239 if (flags & IW_ENCODE_OPEN) {
1240 pr_debug("%s: open key mode\n", __func__);
1241 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1243 if (flags & IW_ENCODE_RESTRICTED) {
1244 pr_debug("%s: shared key mode\n", __func__);
1245 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1247 if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
1248 pr_info("%s: key is too long %d\n", __func__,
1253 /* OK, update the key */
1254 wl->key_len[key_index] = ext->key_len;
1255 memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
1256 memcpy(wl->key[key_index], ext->key, ext->key_len);
1257 set_bit(key_index, &wl->key_enabled);
1258 /* remember wep info changed */
1259 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1260 } else if (alg == IW_ENCODE_ALG_PMK) {
1261 if (ext->key_len != WPA_PSK_LEN) {
1262 pr_err("%s: PSK length wrong %d\n", __func__,
1267 memset(wl->psk, 0, sizeof(wl->psk));
1268 memcpy(wl->psk, ext->key, ext->key_len);
1269 wl->psk_len = ext->key_len;
1270 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1271 /* remember PSK configured */
1272 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1275 spin_unlock_irqrestore(&wl->lock, irqflag);
1276 pr_debug("%s: -> \n", __func__);
1280 static int gelic_wl_get_encodeext(struct net_device *netdev,
1281 struct iw_request_info *info,
1282 union iwreq_data *data, char *extra)
1284 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1285 struct iw_point *enc = &data->encoding;
1286 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1287 unsigned int irqflag;
1292 pr_debug("%s: <- \n", __func__);
1294 max_key_len = enc->length - sizeof(struct iw_encode_ext);
1295 if (max_key_len < 0)
1297 key_index = enc->flags & IW_ENCODE_INDEX;
1299 pr_debug("%s: key_index = %d\n", __func__, key_index);
1300 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1301 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1303 if (GELIC_WEP_KEYS < key_index)
1306 spin_lock_irqsave(&wl->lock, irqflag);
1310 key_index = wl->current_key;
1312 memset(ext, 0, sizeof(struct iw_encode_ext));
1313 switch (wl->group_cipher_method) {
1314 case GELIC_WL_CIPHER_WEP:
1315 ext->alg = IW_ENCODE_ALG_WEP;
1316 enc->flags |= IW_ENCODE_ENABLED;
1318 case GELIC_WL_CIPHER_TKIP:
1319 ext->alg = IW_ENCODE_ALG_TKIP;
1320 enc->flags |= IW_ENCODE_ENABLED;
1322 case GELIC_WL_CIPHER_AES:
1323 ext->alg = IW_ENCODE_ALG_CCMP;
1324 enc->flags |= IW_ENCODE_ENABLED;
1326 case GELIC_WL_CIPHER_NONE:
1328 ext->alg = IW_ENCODE_ALG_NONE;
1329 enc->flags |= IW_ENCODE_NOKEY;
1333 if (!(enc->flags & IW_ENCODE_NOKEY)) {
1334 if (max_key_len < wl->key_len[key_index]) {
1338 if (test_bit(key_index, &wl->key_enabled))
1339 memcpy(ext->key, wl->key[key_index],
1340 wl->key_len[key_index]);
1342 pr_debug("%s: disabled key requested ix=%d\n",
1343 __func__, key_index);
1346 spin_unlock_irqrestore(&wl->lock, irqflag);
1347 pr_debug("%s: -> \n", __func__);
1350 /* SIOC{S,G}IWMODE */
1351 static int gelic_wl_set_mode(struct net_device *netdev,
1352 struct iw_request_info *info,
1353 union iwreq_data *data, char *extra)
1355 __u32 mode = data->mode;
1358 pr_debug("%s: <- \n", __func__);
1359 if (mode == IW_MODE_INFRA)
1363 pr_debug("%s: -> %d\n", __func__, ret);
1367 static int gelic_wl_get_mode(struct net_device *netdev,
1368 struct iw_request_info *info,
1369 union iwreq_data *data, char *extra)
1371 __u32 *mode = &data->mode;
1372 pr_debug("%s: <- \n", __func__);
1373 *mode = IW_MODE_INFRA;
1374 pr_debug("%s: ->\n", __func__);
1378 /* SIOCIWFIRSTPRIV */
1379 static int hex2bin(u8 *str, u8 *bin, unsigned int len)
1382 static unsigned char *hex = "0123456789ABCDEF";
1383 unsigned char *p, *q;
1386 if (len != WPA_PSK_LEN * 2)
1389 for (i = 0; i < WPA_PSK_LEN * 2; i += 2) {
1390 p = strchr(hex, toupper(str[i]));
1391 q = strchr(hex, toupper(str[i + 1]));
1393 pr_info("%s: unconvertible PSK digit=%d\n",
1397 tmp = ((p - hex) << 4) + (q - hex);
1403 static int gelic_wl_priv_set_psk(struct net_device *net_dev,
1404 struct iw_request_info *info,
1405 union iwreq_data *data, char *extra)
1407 struct gelic_wl_info *wl = port_wl(netdev_priv(net_dev));
1409 unsigned int irqflag;
1412 pr_debug("%s:<- len=%d\n", __func__, data->data.length);
1413 len = data->data.length - 1;
1417 spin_lock_irqsave(&wl->lock, irqflag);
1418 if (extra[0] == '"' && extra[len - 1] == '"') {
1419 pr_debug("%s: passphrase mode\n", __func__);
1421 if (GELIC_WL_EURUS_PSK_MAX_LEN < (len - 2)) {
1422 pr_info("%s: passphrase too long\n", __func__);
1426 memset(wl->psk, 0, sizeof(wl->psk));
1427 wl->psk_len = len - 2;
1428 memcpy(wl->psk, &(extra[1]), wl->psk_len);
1429 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
1431 ret = hex2bin(extra, wl->psk, len);
1434 wl->psk_len = WPA_PSK_LEN;
1435 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1437 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1439 spin_unlock_irqrestore(&wl->lock, irqflag);
1440 pr_debug("%s:->\n", __func__);
1444 static int gelic_wl_priv_get_psk(struct net_device *net_dev,
1445 struct iw_request_info *info,
1446 union iwreq_data *data, char *extra)
1448 struct gelic_wl_info *wl = port_wl(netdev_priv(net_dev));
1450 unsigned int irqflag;
1453 pr_debug("%s:<-\n", __func__);
1454 if (!capable(CAP_NET_ADMIN))
1457 spin_lock_irqsave(&wl->lock, irqflag);
1459 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat)) {
1460 if (wl->psk_type == GELIC_EURUS_WPA_PSK_BIN) {
1461 for (i = 0; i < wl->psk_len; i++) {
1462 sprintf(p, "%02xu", wl->psk[i]);
1466 data->data.length = wl->psk_len * 2;
1469 memcpy(p, wl->psk, wl->psk_len);
1473 data->data.length = wl->psk_len + 2;
1477 data->data.length = 0;
1478 spin_unlock_irqrestore(&wl->lock, irqflag);
1479 pr_debug("%s:-> %d\n", __func__, data->data.length);
1484 static int gelic_wl_get_nick(struct net_device *net_dev,
1485 struct iw_request_info *info,
1486 union iwreq_data *data, char *extra)
1488 strcpy(extra, "gelic_wl");
1489 data->data.length = strlen(extra);
1490 data->data.flags = 1;
1497 static struct iw_statistics *gelic_wl_get_wireless_stats(
1498 struct net_device *netdev)
1501 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1502 struct gelic_eurus_cmd *cmd;
1503 struct iw_statistics *is;
1504 struct gelic_eurus_rssi_info *rssi;
1507 pr_debug("%s: <-\n", __func__);
1509 buf = (void *)__get_free_page(GFP_KERNEL);
1514 memset(is, 0, sizeof(*is));
1515 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
1516 buf, sizeof(*rssi));
1517 if (cmd && !cmd->status && !cmd->cmd_status) {
1519 is->qual.level = be16_to_cpu(rssi->rssi);
1520 is->qual.updated = IW_QUAL_LEVEL_UPDATED |
1521 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
1523 /* not associated */
1524 is->qual.updated = IW_QUAL_ALL_INVALID;
1527 free_page((unsigned long)buf);
1528 pr_debug("%s: ->\n", __func__);
1535 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan)
1537 struct gelic_eurus_cmd *cmd;
1540 pr_debug("%s: <- always=%d\n", __func__, always_scan);
1541 if (mutex_lock_interruptible(&wl->scan_lock))
1542 return -ERESTARTSYS;
1545 * If already a scan in progress, do not trigger more
1547 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING) {
1548 pr_debug("%s: scanning now\n", __func__);
1552 init_completion(&wl->scan_done);
1554 * If we have already a bss list, don't try to get new
1556 if (!always_scan && wl->scan_stat == GELIC_WL_SCAN_STAT_GOT_LIST) {
1557 pr_debug("%s: already has the list\n", __func__);
1558 complete(&wl->scan_done);
1562 * issue start scan request
1564 wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
1565 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
1567 if (!cmd || cmd->status || cmd->cmd_status) {
1568 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1569 complete(&wl->scan_done);
1575 mutex_unlock(&wl->scan_lock);
1576 pr_debug("%s: ->\n", __func__);
1581 * retrieve scan result from the chip (hypervisor)
1582 * this function is invoked by schedule work.
1584 static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
1586 struct gelic_eurus_cmd *cmd = NULL;
1587 struct gelic_wl_scan_info *target, *tmp;
1588 struct gelic_wl_scan_info *oldest = NULL;
1589 struct gelic_eurus_scan_info *scan_info;
1590 unsigned int scan_info_size;
1591 union iwreq_data data;
1592 unsigned long this_time = jiffies;
1593 unsigned int data_len, i, found, r;
1595 DECLARE_MAC_BUF(mac);
1597 pr_debug("%s:start\n", __func__);
1598 mutex_lock(&wl->scan_lock);
1600 buf = (void *)__get_free_page(GFP_KERNEL);
1602 pr_info("%s: scan buffer alloc failed\n", __func__);
1606 if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
1608 * stop() may be called while scanning, ignore result
1610 pr_debug("%s: scan complete when stat != scanning(%d)\n",
1611 __func__, wl->scan_stat);
1615 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
1617 if (!cmd || cmd->status || cmd->cmd_status) {
1618 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1619 pr_info("%s:cmd failed\n", __func__);
1623 data_len = cmd->size;
1624 pr_debug("%s: data_len = %d\n", __func__, data_len);
1627 /* OK, bss list retrieved */
1628 wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST;
1630 /* mark all entries are old */
1631 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
1633 /* expire too old entries */
1634 if (time_before(target->last_scanned + wl->scan_age,
1636 kfree(target->hwinfo);
1637 target->hwinfo = NULL;
1638 list_move_tail(&target->list, &wl->network_free_list);
1642 /* put them in the newtork_list */
1643 for (i = 0, scan_info_size = 0, scan_info = buf;
1644 scan_info_size < data_len;
1645 i++, scan_info_size += be16_to_cpu(scan_info->size),
1646 scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
1647 pr_debug("%s:size=%d bssid=%s scan_info=%p\n", __func__,
1648 be16_to_cpu(scan_info->size),
1649 print_mac(mac, &scan_info->bssid[2]), scan_info);
1652 * The wireless firmware may return invalid channel 0 and/or
1653 * invalid rate if the AP emits zero length SSID ie. As this
1654 * scan information is useless, ignore it
1656 if (!be16_to_cpu(scan_info->channel) || !scan_info->rate[0]) {
1657 pr_debug("%s: invalid scan info\n", __func__);
1663 list_for_each_entry(target, &wl->network_list, list) {
1664 if (!compare_ether_addr(&target->hwinfo->bssid[2],
1665 &scan_info->bssid[2])) {
1667 pr_debug("%s: same BBS found scanned list\n",
1672 (target->last_scanned < oldest->last_scanned))
1677 /* not found in the list */
1678 if (list_empty(&wl->network_free_list)) {
1682 target = list_entry(wl->network_free_list.next,
1683 struct gelic_wl_scan_info,
1688 /* update the item */
1689 target->last_scanned = this_time;
1691 target->eurus_index = i;
1692 kfree(target->hwinfo);
1693 target->hwinfo = kzalloc(be16_to_cpu(scan_info->size),
1695 if (!target->hwinfo) {
1696 pr_info("%s: kzalloc failed\n", __func__);
1699 /* copy hw scan info */
1700 memcpy(target->hwinfo, scan_info, scan_info->size);
1701 target->essid_len = strnlen(scan_info->essid,
1702 sizeof(scan_info->essid));
1703 target->rate_len = 0;
1704 for (r = 0; r < MAX_RATES_LENGTH; r++)
1705 if (scan_info->rate[r])
1707 if (8 < target->rate_len)
1708 pr_info("%s: AP returns %d rates\n", __func__,
1710 target->rate_ext_len = 0;
1711 for (r = 0; r < MAX_RATES_EX_LENGTH; r++)
1712 if (scan_info->ext_rate[r])
1713 target->rate_ext_len++;
1714 list_move_tail(&target->list, &wl->network_list);
1716 memset(&data, 0, sizeof(data));
1717 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
1720 free_page((unsigned long)buf);
1721 complete(&wl->scan_done);
1722 mutex_unlock(&wl->scan_lock);
1723 pr_debug("%s:end\n", __func__);
1727 * Select an appropriate bss from current scan list regarding
1728 * current settings from userspace.
1729 * The caller must hold wl->scan_lock,
1730 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1732 static void update_best(struct gelic_wl_scan_info **best,
1733 struct gelic_wl_scan_info *candid,
1737 if (*best_weight < ++(*weight)) {
1738 *best_weight = *weight;
1744 struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
1746 struct gelic_wl_scan_info *scan_info;
1747 struct gelic_wl_scan_info *best_bss;
1748 int weight, best_weight;
1750 DECLARE_MAC_BUF(mac);
1752 pr_debug("%s: <-\n", __func__);
1757 list_for_each_entry(scan_info, &wl->network_list, list) {
1758 pr_debug("%s: station %p\n", __func__, scan_info);
1760 if (!scan_info->valid) {
1761 pr_debug("%s: station invalid\n", __func__);
1765 /* If bss specified, check it only */
1766 if (test_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat)) {
1767 if (!compare_ether_addr(&scan_info->hwinfo->bssid[2],
1769 best_bss = scan_info;
1770 pr_debug("%s: bssid matched\n", __func__);
1773 pr_debug("%s: bssid unmached\n", __func__);
1781 security = be16_to_cpu(scan_info->hwinfo->security) &
1782 GELIC_EURUS_SCAN_SEC_MASK;
1783 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1784 if (security == GELIC_EURUS_SCAN_SEC_WPA2)
1785 update_best(&best_bss, scan_info,
1786 &best_weight, &weight);
1789 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA) {
1790 if (security == GELIC_EURUS_SCAN_SEC_WPA)
1791 update_best(&best_bss, scan_info,
1792 &best_weight, &weight);
1795 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_NONE &&
1796 wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1797 if (security == GELIC_EURUS_SCAN_SEC_WEP)
1798 update_best(&best_bss, scan_info,
1799 &best_weight, &weight);
1804 /* If ESSID is set, check it */
1805 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
1806 if ((scan_info->essid_len == wl->essid_len) &&
1808 scan_info->hwinfo->essid,
1809 scan_info->essid_len))
1810 update_best(&best_bss, scan_info,
1811 &best_weight, &weight);
1818 pr_debug("%s: -> bss=%p\n", __func__, best_bss);
1820 pr_debug("%s:addr=%s\n", __func__,
1821 print_mac(mac, &best_bss->hwinfo->bssid[2]));
1828 * Setup WEP configuration to the chip
1829 * The caller must hold wl->scan_lock,
1830 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1832 static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
1835 struct gelic_eurus_wep_cfg *wep;
1836 struct gelic_eurus_cmd *cmd;
1841 pr_debug("%s: <-\n", __func__);
1842 /* we can assume no one should uses the buffer */
1843 wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
1847 memset(wep, 0, sizeof(*wep));
1849 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1850 pr_debug("%s: WEP mode\n", __func__);
1851 for (i = 0; i < GELIC_WEP_KEYS; i++) {
1852 if (!test_bit(i, &wl->key_enabled))
1855 pr_debug("%s: key#%d enabled\n", __func__, i);
1857 if (wl->key_len[i] == 13)
1859 else if (wl->key_len[i] != 5) {
1860 pr_info("%s: wrong wep key[%d]=%d\n",
1861 __func__, i, wl->key_len[i]);
1865 memcpy(wep->key[i], wl->key[i], wl->key_len[i]);
1869 pr_info("%s: all wep key disabled\n", __func__);
1875 pr_debug("%s: 104bit key\n", __func__);
1876 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT);
1878 pr_debug("%s: 40bit key\n", __func__);
1879 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT);
1882 pr_debug("%s: NO encryption\n", __func__);
1883 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE);
1886 /* issue wep setup */
1887 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WEP_CFG,
1891 else if (cmd->status || cmd->cmd_status)
1896 free_page((unsigned long)wep);
1897 pr_debug("%s: ->\n", __func__);
1902 static const char *wpasecstr(enum gelic_eurus_wpa_security sec)
1905 case GELIC_EURUS_WPA_SEC_NONE:
1908 case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP:
1909 return "WPA_TKIP_TKIP";
1911 case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES:
1912 return "WPA_TKIP_AES";
1914 case GELIC_EURUS_WPA_SEC_WPA_AES_AES:
1915 return "WPA_AES_AES";
1917 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP:
1918 return "WPA2_TKIP_TKIP";
1920 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES:
1921 return "WPA2_TKIP_AES";
1923 case GELIC_EURUS_WPA_SEC_WPA2_AES_AES:
1924 return "WPA2_AES_AES";
1931 static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
1933 struct gelic_eurus_wpa_cfg *wpa;
1934 struct gelic_eurus_cmd *cmd;
1938 pr_debug("%s: <-\n", __func__);
1939 /* we can assume no one should uses the buffer */
1940 wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
1944 memset(wpa, 0, sizeof(*wpa));
1946 if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
1947 pr_info("%s: PSK not configured yet\n", __func__);
1950 memcpy(wpa->psk, wl->psk, wl->psk_len);
1952 /* set security level */
1953 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1954 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1955 security = GELIC_EURUS_WPA_SEC_WPA2_AES_AES;
1957 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1959 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES;
1961 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP;
1964 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1965 security = GELIC_EURUS_WPA_SEC_WPA_AES_AES;
1967 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1969 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_AES;
1971 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP;
1974 wpa->security = cpu_to_be16(security);
1977 wpa->psk_type = cpu_to_be16(wl->psk_type);
1979 pr_debug("%s: sec=%s psktype=%s\nn", __func__,
1980 wpasecstr(wpa->security),
1981 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1982 "BIN" : "passphrase");
1985 * don't enable here if you plan to submit
1986 * the debug log because this dumps your precious
1989 pr_debug("%s: psk=%s\n",
1990 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1991 (char *)"N/A" : (char *)wpa->psk);
1994 /* issue wpa setup */
1995 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WPA_CFG,
1999 else if (cmd->status || cmd->cmd_status)
2002 free_page((unsigned long)wpa);
2003 pr_debug("%s: --> %d\n", __func__, ret);
2008 * Start association. caller must hold assoc_stat_lock
2010 static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
2011 struct gelic_wl_scan_info *bss)
2013 struct gelic_eurus_cmd *cmd;
2014 struct gelic_eurus_common_cfg *common;
2018 pr_debug("%s: <-\n", __func__);
2020 /* do common config */
2021 common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
2025 memset(common, 0, sizeof(*common));
2026 common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
2027 common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
2029 common->scan_index = cpu_to_be16(bss->eurus_index);
2030 switch (wl->auth_method) {
2031 case GELIC_EURUS_AUTH_OPEN:
2032 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_OPEN);
2034 case GELIC_EURUS_AUTH_SHARED:
2035 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_SHARED);
2042 pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
2043 be16_to_cpu(common->scan_index),
2044 be16_to_cpu(common->bss_type),
2045 be16_to_cpu(common->auth_method));
2047 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_COMMON_CFG,
2048 common, sizeof(*common));
2049 if (!cmd || cmd->status || cmd->cmd_status) {
2057 switch (wl->wpa_level) {
2058 case GELIC_WL_WPA_LEVEL_NONE:
2059 /* If WEP or no security, setup WEP config */
2060 ret = gelic_wl_do_wep_setup(wl);
2062 case GELIC_WL_WPA_LEVEL_WPA:
2063 case GELIC_WL_WPA_LEVEL_WPA2:
2064 ret = gelic_wl_do_wpa_setup(wl);
2069 pr_debug("%s: WEP/WPA setup failed %d\n", __func__,
2073 /* start association */
2074 init_completion(&wl->assoc_done);
2075 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATING;
2076 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_ASSOC,
2078 if (!cmd || cmd->status || cmd->cmd_status) {
2079 pr_debug("%s: assoc request failed\n", __func__);
2080 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2083 gelic_wl_send_iwap_event(wl, NULL);
2088 /* wait for connected event */
2089 rc = wait_for_completion_timeout(&wl->assoc_done, HZ * 4);/*FIXME*/
2092 /* timeouted. Maybe key or cyrpt mode is wrong */
2093 pr_info("%s: connect timeout \n", __func__);
2094 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC,
2097 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2098 gelic_wl_send_iwap_event(wl, NULL);
2101 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATED;
2103 memcpy(wl->active_bssid, &bss->hwinfo->bssid[2], ETH_ALEN);
2105 /* send connect event */
2106 gelic_wl_send_iwap_event(wl, wl->active_bssid);
2107 pr_info("%s: connected\n", __func__);
2110 free_page((unsigned long)common);
2111 pr_debug("%s: ->\n", __func__);
2118 static void gelic_wl_connected_event(struct gelic_wl_info *wl,
2121 u64 desired_event = 0;
2123 switch (wl->wpa_level) {
2124 case GELIC_WL_WPA_LEVEL_NONE:
2125 desired_event = GELIC_LV1_WL_EVENT_CONNECTED;
2127 case GELIC_WL_WPA_LEVEL_WPA:
2128 case GELIC_WL_WPA_LEVEL_WPA2:
2129 desired_event = GELIC_LV1_WL_EVENT_WPA_CONNECTED;
2133 if (desired_event == event) {
2134 pr_debug("%s: completed \n", __func__);
2135 complete(&wl->assoc_done);
2136 netif_carrier_on(port_to_netdev(wl_port(wl)));
2138 pr_debug("%s: event %#lx under wpa\n",
2145 static void gelic_wl_disconnect_event(struct gelic_wl_info *wl,
2148 struct gelic_eurus_cmd *cmd;
2152 * If we fall here in the middle of association,
2153 * associate_bss() should be waiting for complation of
2155 * As it waits with timeout, just leave assoc_done
2156 * uncompleted, then it terminates with timeout
2158 if (!mutex_trylock(&wl->assoc_stat_lock)) {
2159 pr_debug("%s: already locked\n", __func__);
2162 pr_debug("%s: obtain lock\n", __func__);
2166 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2169 /* send disconnected event to the supplicant */
2170 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2171 gelic_wl_send_iwap_event(wl, NULL);
2173 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2174 netif_carrier_off(port_to_netdev(wl_port(wl)));
2177 mutex_unlock(&wl->assoc_stat_lock);
2183 static const char *eventstr(enum gelic_lv1_wl_event event)
2185 static char buf[32];
2187 if (event & GELIC_LV1_WL_EVENT_DEVICE_READY)
2188 ret = "EURUS_READY";
2189 else if (event & GELIC_LV1_WL_EVENT_SCAN_COMPLETED)
2190 ret = "SCAN_COMPLETED";
2191 else if (event & GELIC_LV1_WL_EVENT_DEAUTH)
2193 else if (event & GELIC_LV1_WL_EVENT_BEACON_LOST)
2194 ret = "BEACON_LOST";
2195 else if (event & GELIC_LV1_WL_EVENT_CONNECTED)
2197 else if (event & GELIC_LV1_WL_EVENT_WPA_CONNECTED)
2198 ret = "WPA_CONNECTED";
2199 else if (event & GELIC_LV1_WL_EVENT_WPA_ERROR)
2202 sprintf(buf, "Unknown(%#x)", event);
2208 static const char *eventstr(enum gelic_lv1_wl_event event)
2213 static void gelic_wl_event_worker(struct work_struct *work)
2215 struct gelic_wl_info *wl;
2216 struct gelic_port *port;
2220 pr_debug("%s:start\n", __func__);
2221 wl = container_of(work, struct gelic_wl_info, event_work.work);
2224 status = lv1_net_control(bus_id(port->card), dev_id(port->card),
2225 GELIC_LV1_GET_WLAN_EVENT, 0, 0, 0,
2228 if (status != LV1_NO_ENTRY)
2229 pr_debug("%s:wlan event failed %d\n",
2231 /* got all events */
2232 pr_debug("%s:end\n", __func__);
2235 pr_debug("%s: event=%s\n", __func__, eventstr(event));
2237 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
2238 gelic_wl_scan_complete_event(wl);
2240 case GELIC_LV1_WL_EVENT_BEACON_LOST:
2241 case GELIC_LV1_WL_EVENT_DEAUTH:
2242 gelic_wl_disconnect_event(wl, event);
2244 case GELIC_LV1_WL_EVENT_CONNECTED:
2245 case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
2246 gelic_wl_connected_event(wl, event);
2254 * association worker
2256 static void gelic_wl_assoc_worker(struct work_struct *work)
2258 struct gelic_wl_info *wl;
2260 struct gelic_wl_scan_info *best_bss;
2263 wl = container_of(work, struct gelic_wl_info, assoc_work.work);
2265 mutex_lock(&wl->assoc_stat_lock);
2267 if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
2270 ret = gelic_wl_start_scan(wl, 0);
2271 if (ret == -ERESTARTSYS) {
2272 pr_debug("%s: scan start failed association\n", __func__);
2273 schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
2276 pr_info("%s: scan prerequisite failed\n", __func__);
2281 * Wait for bss scan completion
2282 * If we have scan list already, gelic_wl_start_scan()
2283 * returns OK and raises the complete. Thus,
2284 * it's ok to wait unconditionally here
2286 wait_for_completion(&wl->scan_done);
2288 pr_debug("%s: scan done\n", __func__);
2289 mutex_lock(&wl->scan_lock);
2290 if (wl->scan_stat != GELIC_WL_SCAN_STAT_GOT_LIST) {
2291 gelic_wl_send_iwap_event(wl, NULL);
2292 pr_info("%s: no scan list. association failed\n", __func__);
2296 /* find best matching bss */
2297 best_bss = gelic_wl_find_best_bss(wl);
2299 gelic_wl_send_iwap_event(wl, NULL);
2300 pr_info("%s: no bss matched. association failed\n", __func__);
2304 /* ok, do association */
2305 ret = gelic_wl_associate_bss(wl, best_bss);
2307 pr_info("%s: association failed %d\n", __func__, ret);
2309 mutex_unlock(&wl->scan_lock);
2311 mutex_unlock(&wl->assoc_stat_lock);
2315 * Called from the ethernet interrupt handler
2316 * Processes wireless specific virtual interrupts only
2318 void gelic_wl_interrupt(struct net_device *netdev, u64 status)
2320 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2322 if (status & GELIC_CARD_WLAN_COMMAND_COMPLETED) {
2323 pr_debug("%s:cmd complete\n", __func__);
2324 complete(&wl->cmd_done_intr);
2327 if (status & GELIC_CARD_WLAN_EVENT_RECEIVED) {
2328 pr_debug("%s:event received\n", __func__);
2329 queue_delayed_work(wl->event_queue, &wl->event_work, 0);
2336 #define IW_IOCTL(n) [(n) - SIOCSIWCOMMIT]
2337 static const iw_handler gelic_wl_wext_handler[] =
2339 IW_IOCTL(SIOCGIWNAME) = gelic_wl_get_name,
2340 IW_IOCTL(SIOCGIWRANGE) = gelic_wl_get_range,
2341 IW_IOCTL(SIOCSIWSCAN) = gelic_wl_set_scan,
2342 IW_IOCTL(SIOCGIWSCAN) = gelic_wl_get_scan,
2343 IW_IOCTL(SIOCSIWAUTH) = gelic_wl_set_auth,
2344 IW_IOCTL(SIOCGIWAUTH) = gelic_wl_get_auth,
2345 IW_IOCTL(SIOCSIWESSID) = gelic_wl_set_essid,
2346 IW_IOCTL(SIOCGIWESSID) = gelic_wl_get_essid,
2347 IW_IOCTL(SIOCSIWENCODE) = gelic_wl_set_encode,
2348 IW_IOCTL(SIOCGIWENCODE) = gelic_wl_get_encode,
2349 IW_IOCTL(SIOCSIWAP) = gelic_wl_set_ap,
2350 IW_IOCTL(SIOCGIWAP) = gelic_wl_get_ap,
2351 IW_IOCTL(SIOCSIWENCODEEXT) = gelic_wl_set_encodeext,
2352 IW_IOCTL(SIOCGIWENCODEEXT) = gelic_wl_get_encodeext,
2353 IW_IOCTL(SIOCSIWMODE) = gelic_wl_set_mode,
2354 IW_IOCTL(SIOCGIWMODE) = gelic_wl_get_mode,
2355 IW_IOCTL(SIOCGIWNICKN) = gelic_wl_get_nick,
2358 static struct iw_priv_args gelic_wl_private_args[] =
2361 .cmd = GELIC_WL_PRIV_SET_PSK,
2362 .set_args = IW_PRIV_TYPE_CHAR |
2363 (GELIC_WL_EURUS_PSK_MAX_LEN + 2),
2367 .cmd = GELIC_WL_PRIV_GET_PSK,
2368 .get_args = IW_PRIV_TYPE_CHAR |
2369 (GELIC_WL_EURUS_PSK_MAX_LEN + 2),
2374 static const iw_handler gelic_wl_private_handler[] =
2376 gelic_wl_priv_set_psk,
2377 gelic_wl_priv_get_psk,
2380 static const struct iw_handler_def gelic_wl_wext_handler_def = {
2381 .num_standard = ARRAY_SIZE(gelic_wl_wext_handler),
2382 .standard = gelic_wl_wext_handler,
2383 .get_wireless_stats = gelic_wl_get_wireless_stats,
2384 .num_private = ARRAY_SIZE(gelic_wl_private_handler),
2385 .num_private_args = ARRAY_SIZE(gelic_wl_private_args),
2386 .private = gelic_wl_private_handler,
2387 .private_args = gelic_wl_private_args,
2390 static struct net_device *gelic_wl_alloc(struct gelic_card *card)
2392 struct net_device *netdev;
2393 struct gelic_port *port;
2394 struct gelic_wl_info *wl;
2397 pr_debug("%s:start\n", __func__);
2398 netdev = alloc_etherdev(sizeof(struct gelic_port) +
2399 sizeof(struct gelic_wl_info));
2400 pr_debug("%s: netdev =%p card=%p \np", __func__, netdev, card);
2404 strcpy(netdev->name, "wlan%d");
2406 port = netdev_priv(netdev);
2407 port->netdev = netdev;
2409 port->type = GELIC_PORT_WIRELESS;
2412 pr_debug("%s: wl=%p port=%p\n", __func__, wl, port);
2414 /* allocate scan list */
2415 wl->networks = kzalloc(sizeof(struct gelic_wl_scan_info) *
2416 GELIC_WL_BSS_MAX_ENT, GFP_KERNEL);
2421 wl->eurus_cmd_queue = create_singlethread_workqueue("gelic_cmd");
2422 if (!wl->eurus_cmd_queue)
2423 goto fail_cmd_workqueue;
2425 wl->event_queue = create_singlethread_workqueue("gelic_event");
2426 if (!wl->event_queue)
2427 goto fail_event_workqueue;
2429 INIT_LIST_HEAD(&wl->network_free_list);
2430 INIT_LIST_HEAD(&wl->network_list);
2431 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++)
2432 list_add_tail(&wl->networks[i].list,
2433 &wl->network_free_list);
2434 init_completion(&wl->cmd_done_intr);
2436 INIT_DELAYED_WORK(&wl->event_work, gelic_wl_event_worker);
2437 INIT_DELAYED_WORK(&wl->assoc_work, gelic_wl_assoc_worker);
2438 mutex_init(&wl->scan_lock);
2439 mutex_init(&wl->assoc_stat_lock);
2441 init_completion(&wl->scan_done);
2442 /* for the case that no scan request is issued and stop() is called */
2443 complete(&wl->scan_done);
2445 spin_lock_init(&wl->lock);
2447 wl->scan_age = 5*HZ; /* FIXME */
2449 /* buffer for receiving scanned list etc */
2450 BUILD_BUG_ON(PAGE_SIZE <
2451 sizeof(struct gelic_eurus_scan_info) *
2452 GELIC_EURUS_MAX_SCAN);
2453 pr_debug("%s:end\n", __func__);
2456 fail_event_workqueue:
2457 destroy_workqueue(wl->eurus_cmd_queue);
2459 kfree(wl->networks);
2461 free_netdev(netdev);
2462 pr_debug("%s:end error\n", __func__);
2467 static void gelic_wl_free(struct gelic_wl_info *wl)
2469 struct gelic_wl_scan_info *scan_info;
2472 pr_debug("%s: <-\n", __func__);
2474 pr_debug("%s: destroy queues\n", __func__);
2475 destroy_workqueue(wl->eurus_cmd_queue);
2476 destroy_workqueue(wl->event_queue);
2478 scan_info = wl->networks;
2479 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++, scan_info++)
2480 kfree(scan_info->hwinfo);
2481 kfree(wl->networks);
2483 free_netdev(port_to_netdev(wl_port(wl)));
2485 pr_debug("%s: ->\n", __func__);
2488 static int gelic_wl_try_associate(struct net_device *netdev)
2490 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2494 pr_debug("%s: <-\n", __func__);
2496 /* check constraits for start association */
2497 /* for no access restriction AP */
2498 if (wl->group_cipher_method == GELIC_WL_CIPHER_NONE) {
2499 if (test_bit(GELIC_WL_STAT_CONFIGURED,
2503 pr_debug("%s: no wep, not configured\n", __func__);
2508 /* for WEP, one of four keys should be set */
2509 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
2510 /* one of keys set */
2511 for (i = 0; i < GELIC_WEP_KEYS; i++) {
2512 if (test_bit(i, &wl->key_enabled))
2515 pr_debug("%s: WEP, but no key specified\n", __func__);
2519 /* for WPA[2], psk should be set */
2520 if ((wl->group_cipher_method == GELIC_WL_CIPHER_TKIP) ||
2521 (wl->group_cipher_method == GELIC_WL_CIPHER_AES)) {
2522 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET,
2526 pr_debug("%s: AES/TKIP, but PSK not configured\n",
2533 ret = schedule_delayed_work(&wl->assoc_work, 0);
2534 pr_debug("%s: start association work %d\n", __func__, ret);
2541 static int gelic_wl_open(struct net_device *netdev)
2543 struct gelic_card *card = netdev_card(netdev);
2545 pr_debug("%s:->%p\n", __func__, netdev);
2547 gelic_card_up(card);
2549 /* try to associate */
2550 gelic_wl_try_associate(netdev);
2552 netif_start_queue(netdev);
2554 pr_debug("%s:<-\n", __func__);
2559 * reset state machine
2561 static int gelic_wl_reset_state(struct gelic_wl_info *wl)
2563 struct gelic_wl_scan_info *target;
2564 struct gelic_wl_scan_info *tmp;
2566 /* empty scan list */
2567 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
2568 list_move_tail(&target->list, &wl->network_free_list);
2570 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
2572 /* clear configuration */
2573 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
2574 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
2575 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
2576 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
2578 wl->key_enabled = 0;
2579 wl->current_key = 0;
2581 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
2585 memset(wl->essid, 0, sizeof(wl->essid));
2586 memset(wl->bssid, 0, sizeof(wl->bssid));
2587 memset(wl->active_bssid, 0, sizeof(wl->active_bssid));
2589 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2591 memset(&wl->iwstat, 0, sizeof(wl->iwstat));
2592 /* all status bit clear */
2598 * Tell eurus to terminate association
2600 static void gelic_wl_disconnect(struct net_device *netdev)
2602 struct gelic_port *port = netdev_priv(netdev);
2603 struct gelic_wl_info *wl = port_wl(port);
2604 struct gelic_eurus_cmd *cmd;
2607 * If scann process is running on chip,
2608 * further requests will be rejected
2610 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING)
2611 wait_for_completion_timeout(&wl->scan_done, HZ);
2613 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2615 gelic_wl_send_iwap_event(wl, NULL);
2618 static int gelic_wl_stop(struct net_device *netdev)
2620 struct gelic_port *port = netdev_priv(netdev);
2621 struct gelic_wl_info *wl = port_wl(port);
2622 struct gelic_card *card = netdev_card(netdev);
2624 pr_debug("%s:<-\n", __func__);
2627 * Cancel pending association work.
2628 * event work can run after netdev down
2630 cancel_delayed_work(&wl->assoc_work);
2632 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2633 gelic_wl_disconnect(netdev);
2635 /* reset our state machine */
2636 gelic_wl_reset_state(wl);
2638 netif_stop_queue(netdev);
2640 gelic_card_down(card);
2642 pr_debug("%s:->\n", __func__);
2648 static struct ethtool_ops gelic_wl_ethtool_ops = {
2649 .get_drvinfo = gelic_net_get_drvinfo,
2650 .get_link = gelic_wl_get_link,
2651 .get_tx_csum = ethtool_op_get_tx_csum,
2652 .set_tx_csum = ethtool_op_set_tx_csum,
2653 .get_rx_csum = gelic_net_get_rx_csum,
2654 .set_rx_csum = gelic_net_set_rx_csum,
2657 static void gelic_wl_setup_netdev_ops(struct net_device *netdev)
2659 struct gelic_wl_info *wl;
2660 wl = port_wl(netdev_priv(netdev));
2662 netdev->open = &gelic_wl_open;
2663 netdev->stop = &gelic_wl_stop;
2664 netdev->hard_start_xmit = &gelic_net_xmit;
2665 netdev->set_multicast_list = &gelic_net_set_multi;
2666 netdev->change_mtu = &gelic_net_change_mtu;
2667 netdev->wireless_data = &wl->wireless_data;
2668 netdev->wireless_handlers = &gelic_wl_wext_handler_def;
2670 netdev->tx_timeout = &gelic_net_tx_timeout;
2671 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
2673 netdev->ethtool_ops = &gelic_wl_ethtool_ops;
2674 #ifdef CONFIG_NET_POLL_CONTROLLER
2675 netdev->poll_controller = gelic_net_poll_controller;
2680 * driver probe/remove
2682 int gelic_wl_driver_probe(struct gelic_card *card)
2685 struct net_device *netdev;
2687 pr_debug("%s:start\n", __func__);
2689 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2691 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2694 /* alloc netdevice for wireless */
2695 netdev = gelic_wl_alloc(card);
2699 /* setup net_device structure */
2700 SET_NETDEV_DEV(netdev, &card->dev->core);
2701 gelic_wl_setup_netdev_ops(netdev);
2703 /* setup some of net_device and register it */
2704 ret = gelic_net_setup_netdev(netdev, card);
2707 card->netdev[GELIC_PORT_WIRELESS] = netdev;
2709 /* add enable wireless interrupt */
2710 card->irq_mask |= GELIC_CARD_WLAN_EVENT_RECEIVED |
2711 GELIC_CARD_WLAN_COMMAND_COMPLETED;
2712 /* to allow wireless commands while both interfaces are down */
2713 gelic_card_set_irq_mask(card, GELIC_CARD_WLAN_EVENT_RECEIVED |
2714 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2715 pr_debug("%s:end\n", __func__);
2719 gelic_wl_free(port_wl(netdev_port(netdev)));
2724 int gelic_wl_driver_remove(struct gelic_card *card)
2726 struct gelic_wl_info *wl;
2727 struct net_device *netdev;
2729 pr_debug("%s:start\n", __func__);
2731 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2733 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2736 netdev = card->netdev[GELIC_PORT_WIRELESS];
2737 wl = port_wl(netdev_priv(netdev));
2739 /* if the interface was not up, but associated */
2740 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2741 gelic_wl_disconnect(netdev);
2743 complete(&wl->cmd_done_intr);
2745 /* cancel all work queue */
2746 cancel_delayed_work(&wl->assoc_work);
2747 cancel_delayed_work(&wl->event_work);
2748 flush_workqueue(wl->eurus_cmd_queue);
2749 flush_workqueue(wl->event_queue);
2751 unregister_netdev(netdev);
2753 /* disable wireless interrupt */
2754 pr_debug("%s: disable intr\n", __func__);
2755 card->irq_mask &= ~(GELIC_CARD_WLAN_EVENT_RECEIVED |
2756 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2757 /* free bss list, netdev*/
2759 pr_debug("%s:end\n", __func__);