sfc: Create multiple TX queues
[linux/fpc-iii.git] / drivers / net / ps3_gelic_wireless.c
blobd4ff627c6f7ac2ab513ef1f027c993539aab1b2b
1 /*
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.
20 #undef DEBUG
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
26 #include <linux/etherdevice.h>
27 #include <linux/ethtool.h>
28 #include <linux/if_vlan.h>
30 #include <linux/in.h>
31 #include <linux/ip.h>
32 #include <linux/tcp.h>
33 #include <linux/wireless.h>
34 #include <linux/ieee80211.h>
35 #include <linux/if_arp.h>
36 #include <linux/ctype.h>
37 #include <linux/string.h>
38 #include <net/iw_handler.h>
40 #include <linux/dma-mapping.h>
41 #include <net/checksum.h>
42 #include <asm/firmware.h>
43 #include <asm/ps3.h>
44 #include <asm/lv1call.h>
46 #include "ps3_gelic_net.h"
47 #include "ps3_gelic_wireless.h"
50 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
51 u8 *essid, size_t essid_len);
52 static int gelic_wl_try_associate(struct net_device *netdev);
55 * tables
58 /* 802.11b/g channel to freq in MHz */
59 static const int channel_freq[] = {
60 2412, 2417, 2422, 2427, 2432,
61 2437, 2442, 2447, 2452, 2457,
62 2462, 2467, 2472, 2484
64 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
66 /* in bps */
67 static const int bitrate_list[] = {
68 1000000,
69 2000000,
70 5500000,
71 11000000,
72 6000000,
73 9000000,
74 12000000,
75 18000000,
76 24000000,
77 36000000,
78 48000000,
79 54000000
81 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
84 * wpa2 support requires the hypervisor version 2.0 or later
86 static inline int wpa2_capable(void)
88 return (0 <= ps3_compare_firmware_version(2, 0, 0));
91 static inline int precise_ie(void)
93 return (0 <= ps3_compare_firmware_version(2, 2, 0));
96 * post_eurus_cmd helpers
98 struct eurus_cmd_arg_info {
99 int pre_arg; /* command requres arg1, arg2 at POST COMMAND */
100 int post_arg; /* command requires arg1, arg2 at GET_RESULT */
103 static const struct eurus_cmd_arg_info cmd_info[GELIC_EURUS_CMD_MAX_INDEX] = {
104 [GELIC_EURUS_CMD_SET_COMMON_CFG] = { .pre_arg = 1},
105 [GELIC_EURUS_CMD_SET_WEP_CFG] = { .pre_arg = 1},
106 [GELIC_EURUS_CMD_SET_WPA_CFG] = { .pre_arg = 1},
107 [GELIC_EURUS_CMD_GET_COMMON_CFG] = { .post_arg = 1},
108 [GELIC_EURUS_CMD_GET_WEP_CFG] = { .post_arg = 1},
109 [GELIC_EURUS_CMD_GET_WPA_CFG] = { .post_arg = 1},
110 [GELIC_EURUS_CMD_GET_RSSI_CFG] = { .post_arg = 1},
111 [GELIC_EURUS_CMD_START_SCAN] = { .pre_arg = 1},
112 [GELIC_EURUS_CMD_GET_SCAN] = { .post_arg = 1},
115 #ifdef DEBUG
116 static const char *cmdstr(enum gelic_eurus_command ix)
118 switch (ix) {
119 case GELIC_EURUS_CMD_ASSOC:
120 return "ASSOC";
121 case GELIC_EURUS_CMD_DISASSOC:
122 return "DISASSOC";
123 case GELIC_EURUS_CMD_START_SCAN:
124 return "SCAN";
125 case GELIC_EURUS_CMD_GET_SCAN:
126 return "GET SCAN";
127 case GELIC_EURUS_CMD_SET_COMMON_CFG:
128 return "SET_COMMON_CFG";
129 case GELIC_EURUS_CMD_GET_COMMON_CFG:
130 return "GET_COMMON_CFG";
131 case GELIC_EURUS_CMD_SET_WEP_CFG:
132 return "SET_WEP_CFG";
133 case GELIC_EURUS_CMD_GET_WEP_CFG:
134 return "GET_WEP_CFG";
135 case GELIC_EURUS_CMD_SET_WPA_CFG:
136 return "SET_WPA_CFG";
137 case GELIC_EURUS_CMD_GET_WPA_CFG:
138 return "GET_WPA_CFG";
139 case GELIC_EURUS_CMD_GET_RSSI_CFG:
140 return "GET_RSSI";
141 default:
142 break;
144 return "";
146 #else
147 static inline const char *cmdstr(enum gelic_eurus_command ix)
149 return "";
151 #endif
153 /* synchronously do eurus commands */
154 static void gelic_eurus_sync_cmd_worker(struct work_struct *work)
156 struct gelic_eurus_cmd *cmd;
157 struct gelic_card *card;
158 struct gelic_wl_info *wl;
160 u64 arg1, arg2;
162 pr_debug("%s: <-\n", __func__);
163 cmd = container_of(work, struct gelic_eurus_cmd, work);
164 BUG_ON(cmd_info[cmd->cmd].pre_arg &&
165 cmd_info[cmd->cmd].post_arg);
166 wl = cmd->wl;
167 card = port_to_card(wl_port(wl));
169 if (cmd_info[cmd->cmd].pre_arg) {
170 arg1 = (cmd->buffer) ?
171 ps3_mm_phys_to_lpar(__pa(cmd->buffer)) :
173 arg2 = cmd->buf_size;
174 } else {
175 arg1 = 0;
176 arg2 = 0;
178 init_completion(&wl->cmd_done_intr);
179 pr_debug("%s: cmd='%s' start\n", __func__, cmdstr(cmd->cmd));
180 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
181 GELIC_LV1_POST_WLAN_CMD,
182 cmd->cmd, arg1, arg2,
183 &cmd->tag, &cmd->size);
184 if (cmd->status) {
185 complete(&cmd->done);
186 pr_info("%s: cmd issue failed\n", __func__);
187 return;
190 wait_for_completion(&wl->cmd_done_intr);
192 if (cmd_info[cmd->cmd].post_arg) {
193 arg1 = ps3_mm_phys_to_lpar(__pa(cmd->buffer));
194 arg2 = cmd->buf_size;
195 } else {
196 arg1 = 0;
197 arg2 = 0;
200 cmd->status = lv1_net_control(bus_id(card), dev_id(card),
201 GELIC_LV1_GET_WLAN_CMD_RESULT,
202 cmd->tag, arg1, arg2,
203 &cmd->cmd_status, &cmd->size);
204 #ifdef DEBUG
205 if (cmd->status || cmd->cmd_status) {
206 pr_debug("%s: cmd done tag=%#lx arg1=%#lx, arg2=%#lx\n", __func__,
207 cmd->tag, arg1, arg2);
208 pr_debug("%s: cmd done status=%#x cmd_status=%#lx size=%#lx\n",
209 __func__, cmd->status, cmd->cmd_status, cmd->size);
211 #endif
212 complete(&cmd->done);
213 pr_debug("%s: cmd='%s' done\n", __func__, cmdstr(cmd->cmd));
216 static struct gelic_eurus_cmd *gelic_eurus_sync_cmd(struct gelic_wl_info *wl,
217 unsigned int eurus_cmd,
218 void *buffer,
219 unsigned int buf_size)
221 struct gelic_eurus_cmd *cmd;
223 /* allocate cmd */
224 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
225 if (!cmd)
226 return NULL;
228 /* initialize members */
229 cmd->cmd = eurus_cmd;
230 cmd->buffer = buffer;
231 cmd->buf_size = buf_size;
232 cmd->wl = wl;
233 INIT_WORK(&cmd->work, gelic_eurus_sync_cmd_worker);
234 init_completion(&cmd->done);
235 queue_work(wl->eurus_cmd_queue, &cmd->work);
237 /* wait for command completion */
238 wait_for_completion(&cmd->done);
240 return cmd;
243 static u32 gelic_wl_get_link(struct net_device *netdev)
245 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
246 u32 ret;
248 pr_debug("%s: <-\n", __func__);
249 mutex_lock(&wl->assoc_stat_lock);
250 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
251 ret = 1;
252 else
253 ret = 0;
254 mutex_unlock(&wl->assoc_stat_lock);
255 pr_debug("%s: ->\n", __func__);
256 return ret;
259 static void gelic_wl_send_iwap_event(struct gelic_wl_info *wl, u8 *bssid)
261 union iwreq_data data;
263 memset(&data, 0, sizeof(data));
264 if (bssid)
265 memcpy(data.ap_addr.sa_data, bssid, ETH_ALEN);
266 data.ap_addr.sa_family = ARPHRD_ETHER;
267 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWAP,
268 &data, NULL);
272 * wireless extension handlers and helpers
275 /* SIOGIWNAME */
276 static int gelic_wl_get_name(struct net_device *dev,
277 struct iw_request_info *info,
278 union iwreq_data *iwreq, char *extra)
280 strcpy(iwreq->name, "IEEE 802.11bg");
281 return 0;
284 static void gelic_wl_get_ch_info(struct gelic_wl_info *wl)
286 struct gelic_card *card = port_to_card(wl_port(wl));
287 u64 ch_info_raw, tmp;
288 int status;
290 if (!test_and_set_bit(GELIC_WL_STAT_CH_INFO, &wl->stat)) {
291 status = lv1_net_control(bus_id(card), dev_id(card),
292 GELIC_LV1_GET_CHANNEL, 0, 0, 0,
293 &ch_info_raw,
294 &tmp);
295 /* some fw versions may return error */
296 if (status) {
297 if (status != LV1_NO_ENTRY)
298 pr_info("%s: available ch unknown\n", __func__);
299 wl->ch_info = 0x07ff;/* 11 ch */
300 } else
301 /* 16 bits of MSB has available channels */
302 wl->ch_info = ch_info_raw >> 48;
304 return;
307 /* SIOGIWRANGE */
308 static int gelic_wl_get_range(struct net_device *netdev,
309 struct iw_request_info *info,
310 union iwreq_data *iwreq, char *extra)
312 struct iw_point *point = &iwreq->data;
313 struct iw_range *range = (struct iw_range *)extra;
314 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
315 unsigned int i, chs;
317 pr_debug("%s: <-\n", __func__);
318 point->length = sizeof(struct iw_range);
319 memset(range, 0, sizeof(struct iw_range));
321 range->we_version_compiled = WIRELESS_EXT;
322 range->we_version_source = 22;
324 /* available channels and frequencies */
325 gelic_wl_get_ch_info(wl);
327 for (i = 0, chs = 0;
328 i < NUM_CHANNELS && chs < IW_MAX_FREQUENCIES; i++)
329 if (wl->ch_info & (1 << i)) {
330 range->freq[chs].i = i + 1;
331 range->freq[chs].m = channel_freq[i];
332 range->freq[chs].e = 6;
333 chs++;
335 range->num_frequency = chs;
336 range->old_num_frequency = chs;
337 range->num_channels = chs;
338 range->old_num_channels = chs;
340 /* bitrates */
341 for (i = 0; i < NUM_BITRATES; i++)
342 range->bitrate[i] = bitrate_list[i];
343 range->num_bitrates = i;
345 /* signal levels */
346 range->max_qual.qual = 100; /* relative value */
347 range->max_qual.level = 100;
348 range->avg_qual.qual = 50;
349 range->avg_qual.level = 50;
350 range->sensitivity = 0;
352 /* Event capability */
353 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
354 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
355 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
357 /* encryption capability */
358 range->enc_capa = IW_ENC_CAPA_WPA |
359 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP |
360 IW_ENC_CAPA_4WAY_HANDSHAKE;
361 if (wpa2_capable())
362 range->enc_capa |= IW_ENC_CAPA_WPA2;
363 range->encoding_size[0] = 5; /* 40bit WEP */
364 range->encoding_size[1] = 13; /* 104bit WEP */
365 range->encoding_size[2] = 32; /* WPA-PSK */
366 range->num_encoding_sizes = 3;
367 range->max_encoding_tokens = GELIC_WEP_KEYS;
369 /* scan capability */
370 range->scan_capa = IW_SCAN_CAPA_ESSID;
372 pr_debug("%s: ->\n", __func__);
373 return 0;
377 /* SIOC{G,S}IWSCAN */
378 static int gelic_wl_set_scan(struct net_device *netdev,
379 struct iw_request_info *info,
380 union iwreq_data *wrqu, char *extra)
382 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
383 struct iw_scan_req *req;
384 u8 *essid = NULL;
385 size_t essid_len = 0;
387 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
388 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
389 req = (struct iw_scan_req*)extra;
390 essid = req->essid;
391 essid_len = req->essid_len;
392 pr_debug("%s: ESSID scan =%s\n", __func__, essid);
394 return gelic_wl_start_scan(wl, 1, essid, essid_len);
397 #define OUI_LEN 3
398 static const u8 rsn_oui[OUI_LEN] = { 0x00, 0x0f, 0xac };
399 static const u8 wpa_oui[OUI_LEN] = { 0x00, 0x50, 0xf2 };
402 * synthesize WPA/RSN IE data
403 * See WiFi WPA specification and IEEE 802.11-2007 7.3.2.25
404 * for the format
406 static size_t gelic_wl_synthesize_ie(u8 *buf,
407 struct gelic_eurus_scan_info *scan)
410 const u8 *oui_header;
411 u8 *start = buf;
412 int rsn;
413 int ccmp;
415 pr_debug("%s: <- sec=%16x\n", __func__, scan->security);
416 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_MASK) {
417 case GELIC_EURUS_SCAN_SEC_WPA:
418 rsn = 0;
419 break;
420 case GELIC_EURUS_SCAN_SEC_WPA2:
421 rsn = 1;
422 break;
423 default:
424 /* WEP or none. No IE returned */
425 return 0;
428 switch (be16_to_cpu(scan->security) & GELIC_EURUS_SCAN_SEC_WPA_MASK) {
429 case GELIC_EURUS_SCAN_SEC_WPA_TKIP:
430 ccmp = 0;
431 break;
432 case GELIC_EURUS_SCAN_SEC_WPA_AES:
433 ccmp = 1;
434 break;
435 default:
436 if (rsn) {
437 ccmp = 1;
438 pr_info("%s: no cipher info. defaulted to CCMP\n",
439 __func__);
440 } else {
441 ccmp = 0;
442 pr_info("%s: no cipher info. defaulted to TKIP\n",
443 __func__);
447 if (rsn)
448 oui_header = rsn_oui;
449 else
450 oui_header = wpa_oui;
452 /* element id */
453 if (rsn)
454 *buf++ = WLAN_EID_RSN;
455 else
456 *buf++ = WLAN_EID_GENERIC;
458 /* length filed; set later */
459 buf++;
461 /* wpa special header */
462 if (!rsn) {
463 memcpy(buf, wpa_oui, OUI_LEN);
464 buf += OUI_LEN;
465 *buf++ = 0x01;
468 /* version */
469 *buf++ = 0x01; /* version 1.0 */
470 *buf++ = 0x00;
472 /* group cipher */
473 memcpy(buf, oui_header, OUI_LEN);
474 buf += OUI_LEN;
476 if (ccmp)
477 *buf++ = 0x04; /* CCMP */
478 else
479 *buf++ = 0x02; /* TKIP */
481 /* pairwise key count always 1 */
482 *buf++ = 0x01;
483 *buf++ = 0x00;
485 /* pairwise key suit */
486 memcpy(buf, oui_header, OUI_LEN);
487 buf += OUI_LEN;
488 if (ccmp)
489 *buf++ = 0x04; /* CCMP */
490 else
491 *buf++ = 0x02; /* TKIP */
493 /* AKM count is 1 */
494 *buf++ = 0x01;
495 *buf++ = 0x00;
497 /* AKM suite is assumed as PSK*/
498 memcpy(buf, oui_header, OUI_LEN);
499 buf += OUI_LEN;
500 *buf++ = 0x02; /* PSK */
502 /* RSN capabilities is 0 */
503 *buf++ = 0x00;
504 *buf++ = 0x00;
506 /* set length field */
507 start[1] = (buf - start - 2);
509 pr_debug("%s: ->\n", __func__);
510 return (buf - start);
513 struct ie_item {
514 u8 *data;
515 u8 len;
518 struct ie_info {
519 struct ie_item wpa;
520 struct ie_item rsn;
523 static void gelic_wl_parse_ie(u8 *data, size_t len,
524 struct ie_info *ie_info)
526 size_t data_left = len;
527 u8 *pos = data;
528 u8 item_len;
529 u8 item_id;
531 pr_debug("%s: data=%p len=%ld\n", __func__,
532 data, len);
533 memset(ie_info, 0, sizeof(struct ie_info));
535 while (2 <= data_left) {
536 item_id = *pos++;
537 item_len = *pos++;
538 data_left -= 2;
540 if (data_left < item_len)
541 break;
543 switch (item_id) {
544 case WLAN_EID_GENERIC:
545 if ((OUI_LEN + 1 <= item_len) &&
546 !memcmp(pos, wpa_oui, OUI_LEN) &&
547 pos[OUI_LEN] == 0x01) {
548 ie_info->wpa.data = pos - 2;
549 ie_info->wpa.len = item_len + 2;
551 break;
552 case WLAN_EID_RSN:
553 ie_info->rsn.data = pos - 2;
554 /* length includes the header */
555 ie_info->rsn.len = item_len + 2;
556 break;
557 default:
558 pr_debug("%s: ignore %#x,%d\n", __func__,
559 item_id, item_len);
560 break;
562 pos += item_len;
563 data_left -= item_len;
565 pr_debug("%s: wpa=%p,%d wpa2=%p,%d\n", __func__,
566 ie_info->wpa.data, ie_info->wpa.len,
567 ie_info->rsn.data, ie_info->rsn.len);
572 * translate the scan informations from hypervisor to a
573 * independent format
575 static char *gelic_wl_translate_scan(struct net_device *netdev,
576 struct iw_request_info *info,
577 char *ev,
578 char *stop,
579 struct gelic_wl_scan_info *network)
581 struct iw_event iwe;
582 struct gelic_eurus_scan_info *scan = network->hwinfo;
583 char *tmp;
584 u8 rate;
585 unsigned int i, j, len;
586 u8 buf[64]; /* arbitrary size large enough */
588 pr_debug("%s: <-\n", __func__);
590 /* first entry should be AP's mac address */
591 iwe.cmd = SIOCGIWAP;
592 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
593 memcpy(iwe.u.ap_addr.sa_data, &scan->bssid[2], ETH_ALEN);
594 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_ADDR_LEN);
596 /* ESSID */
597 iwe.cmd = SIOCGIWESSID;
598 iwe.u.data.flags = 1;
599 iwe.u.data.length = strnlen(scan->essid, 32);
600 ev = iwe_stream_add_point(info, ev, stop, &iwe, scan->essid);
602 /* FREQUENCY */
603 iwe.cmd = SIOCGIWFREQ;
604 iwe.u.freq.m = be16_to_cpu(scan->channel);
605 iwe.u.freq.e = 0; /* table value in MHz */
606 iwe.u.freq.i = 0;
607 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_FREQ_LEN);
609 /* RATES */
610 iwe.cmd = SIOCGIWRATE;
611 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
612 /* to stuff multiple values in one event */
613 tmp = ev + iwe_stream_lcp_len(info);
614 /* put them in ascendant order (older is first) */
615 i = 0;
616 j = 0;
617 pr_debug("%s: rates=%d rate=%d\n", __func__,
618 network->rate_len, network->rate_ext_len);
619 while (i < network->rate_len) {
620 if (j < network->rate_ext_len &&
621 ((scan->ext_rate[j] & 0x7f) < (scan->rate[i] & 0x7f)))
622 rate = scan->ext_rate[j++] & 0x7f;
623 else
624 rate = scan->rate[i++] & 0x7f;
625 iwe.u.bitrate.value = rate * 500000; /* 500kbps unit */
626 tmp = iwe_stream_add_value(info, ev, tmp, stop, &iwe,
627 IW_EV_PARAM_LEN);
629 while (j < network->rate_ext_len) {
630 iwe.u.bitrate.value = (scan->ext_rate[j++] & 0x7f) * 500000;
631 tmp = iwe_stream_add_value(info, ev, tmp, stop, &iwe,
632 IW_EV_PARAM_LEN);
634 /* Check if we added any rate */
635 if (iwe_stream_lcp_len(info) < (tmp - ev))
636 ev = tmp;
638 /* ENCODE */
639 iwe.cmd = SIOCGIWENCODE;
640 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_PRIVACY)
641 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
642 else
643 iwe.u.data.flags = IW_ENCODE_DISABLED;
644 iwe.u.data.length = 0;
645 ev = iwe_stream_add_point(info, ev, stop, &iwe, scan->essid);
647 /* MODE */
648 iwe.cmd = SIOCGIWMODE;
649 if (be16_to_cpu(scan->capability) &
650 (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
651 if (be16_to_cpu(scan->capability) & WLAN_CAPABILITY_ESS)
652 iwe.u.mode = IW_MODE_MASTER;
653 else
654 iwe.u.mode = IW_MODE_ADHOC;
655 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_UINT_LEN);
658 /* QUAL */
659 iwe.cmd = IWEVQUAL;
660 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED |
661 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
662 iwe.u.qual.level = be16_to_cpu(scan->rssi);
663 iwe.u.qual.qual = be16_to_cpu(scan->rssi);
664 iwe.u.qual.noise = 0;
665 ev = iwe_stream_add_event(info, ev, stop, &iwe, IW_EV_QUAL_LEN);
667 /* RSN */
668 memset(&iwe, 0, sizeof(iwe));
669 if (be16_to_cpu(scan->size) <= sizeof(*scan)) {
670 /* If wpa[2] capable station, synthesize IE and put it */
671 len = gelic_wl_synthesize_ie(buf, scan);
672 if (len) {
673 iwe.cmd = IWEVGENIE;
674 iwe.u.data.length = len;
675 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
677 } else {
678 /* this scan info has IE data */
679 struct ie_info ie_info;
680 size_t data_len;
682 data_len = be16_to_cpu(scan->size) - sizeof(*scan);
684 gelic_wl_parse_ie(scan->elements, data_len, &ie_info);
686 if (ie_info.wpa.len && (ie_info.wpa.len <= sizeof(buf))) {
687 memcpy(buf, ie_info.wpa.data, ie_info.wpa.len);
688 iwe.cmd = IWEVGENIE;
689 iwe.u.data.length = ie_info.wpa.len;
690 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
693 if (ie_info.rsn.len && (ie_info.rsn.len <= sizeof(buf))) {
694 memset(&iwe, 0, sizeof(iwe));
695 memcpy(buf, ie_info.rsn.data, ie_info.rsn.len);
696 iwe.cmd = IWEVGENIE;
697 iwe.u.data.length = ie_info.rsn.len;
698 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
702 pr_debug("%s: ->\n", __func__);
703 return ev;
707 static int gelic_wl_get_scan(struct net_device *netdev,
708 struct iw_request_info *info,
709 union iwreq_data *wrqu, char *extra)
711 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
712 struct gelic_wl_scan_info *scan_info;
713 char *ev = extra;
714 char *stop = ev + wrqu->data.length;
715 int ret = 0;
716 unsigned long this_time = jiffies;
718 pr_debug("%s: <-\n", __func__);
719 if (mutex_lock_interruptible(&wl->scan_lock))
720 return -EAGAIN;
722 switch (wl->scan_stat) {
723 case GELIC_WL_SCAN_STAT_SCANNING:
724 /* If a scan in progress, caller should call me again */
725 ret = -EAGAIN;
726 goto out;
727 break;
729 case GELIC_WL_SCAN_STAT_INIT:
730 /* last scan request failed or never issued */
731 ret = -ENODEV;
732 goto out;
733 break;
734 case GELIC_WL_SCAN_STAT_GOT_LIST:
735 /* ok, use current list */
736 break;
739 list_for_each_entry(scan_info, &wl->network_list, list) {
740 if (wl->scan_age == 0 ||
741 time_after(scan_info->last_scanned + wl->scan_age,
742 this_time))
743 ev = gelic_wl_translate_scan(netdev, info,
744 ev, stop,
745 scan_info);
746 else
747 pr_debug("%s:entry too old\n", __func__);
749 if (stop - ev <= IW_EV_ADDR_LEN) {
750 ret = -E2BIG;
751 goto out;
755 wrqu->data.length = ev - extra;
756 wrqu->data.flags = 0;
757 out:
758 mutex_unlock(&wl->scan_lock);
759 pr_debug("%s: -> %d %d\n", __func__, ret, wrqu->data.length);
760 return ret;
763 #ifdef DEBUG
764 static void scan_list_dump(struct gelic_wl_info *wl)
766 struct gelic_wl_scan_info *scan_info;
767 int i;
769 i = 0;
770 list_for_each_entry(scan_info, &wl->network_list, list) {
771 pr_debug("%s: item %d\n", __func__, i++);
772 pr_debug("valid=%d eurusindex=%d last=%lx\n",
773 scan_info->valid, scan_info->eurus_index,
774 scan_info->last_scanned);
775 pr_debug("r_len=%d r_ext_len=%d essid_len=%d\n",
776 scan_info->rate_len, scan_info->rate_ext_len,
777 scan_info->essid_len);
778 /* -- */
779 pr_debug("bssid=%pM\n", &scan_info->hwinfo->bssid[2]);
780 pr_debug("essid=%s\n", scan_info->hwinfo->essid);
783 #endif
785 static int gelic_wl_set_auth(struct net_device *netdev,
786 struct iw_request_info *info,
787 union iwreq_data *data, char *extra)
789 struct iw_param *param = &data->param;
790 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
791 unsigned long irqflag;
792 int ret = 0;
794 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
795 spin_lock_irqsave(&wl->lock, irqflag);
796 switch (param->flags & IW_AUTH_INDEX) {
797 case IW_AUTH_WPA_VERSION:
798 if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
799 pr_debug("%s: NO WPA selected\n", __func__);
800 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
801 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
802 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
804 if (param->value & IW_AUTH_WPA_VERSION_WPA) {
805 pr_debug("%s: WPA version 1 selected\n", __func__);
806 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
807 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
808 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
809 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
811 if (param->value & IW_AUTH_WPA_VERSION_WPA2) {
813 * As the hypervisor may not tell the cipher
814 * information of the AP if it is WPA2,
815 * you will not decide suitable cipher from
816 * its beacon.
817 * You should have knowledge about the AP's
818 * cipher infomation in other method prior to
819 * the association.
821 if (!precise_ie())
822 pr_info("%s: WPA2 may not work\n", __func__);
823 if (wpa2_capable()) {
824 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA2;
825 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
826 wl->pairwise_cipher_method =
827 GELIC_WL_CIPHER_AES;
828 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
829 } else
830 ret = -EINVAL;
832 break;
834 case IW_AUTH_CIPHER_PAIRWISE:
835 if (param->value &
836 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
837 pr_debug("%s: WEP selected\n", __func__);
838 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
840 if (param->value & IW_AUTH_CIPHER_TKIP) {
841 pr_debug("%s: TKIP selected\n", __func__);
842 wl->pairwise_cipher_method = GELIC_WL_CIPHER_TKIP;
844 if (param->value & IW_AUTH_CIPHER_CCMP) {
845 pr_debug("%s: CCMP selected\n", __func__);
846 wl->pairwise_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->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
852 break;
853 case IW_AUTH_CIPHER_GROUP:
854 if (param->value &
855 (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
856 pr_debug("%s: WEP selected\n", __func__);
857 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
859 if (param->value & IW_AUTH_CIPHER_TKIP) {
860 pr_debug("%s: TKIP selected\n", __func__);
861 wl->group_cipher_method = GELIC_WL_CIPHER_TKIP;
863 if (param->value & IW_AUTH_CIPHER_CCMP) {
864 pr_debug("%s: CCMP selected\n", __func__);
865 wl->group_cipher_method = GELIC_WL_CIPHER_AES;
867 if (param->value & IW_AUTH_CIPHER_NONE) {
868 pr_debug("%s: no auth selected\n", __func__);
869 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
871 break;
872 case IW_AUTH_80211_AUTH_ALG:
873 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
874 pr_debug("%s: shared key specified\n", __func__);
875 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
876 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
877 pr_debug("%s: open system specified\n", __func__);
878 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
879 } else
880 ret = -EINVAL;
881 break;
883 case IW_AUTH_WPA_ENABLED:
884 if (param->value) {
885 pr_debug("%s: WPA enabled\n", __func__);
886 wl->wpa_level = GELIC_WL_WPA_LEVEL_WPA;
887 } else {
888 pr_debug("%s: WPA disabled\n", __func__);
889 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
891 break;
893 case IW_AUTH_KEY_MGMT:
894 if (param->value & IW_AUTH_KEY_MGMT_PSK)
895 break;
896 /* intentionally fall through */
897 default:
898 ret = -EOPNOTSUPP;
899 break;
902 if (!ret)
903 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
905 spin_unlock_irqrestore(&wl->lock, irqflag);
906 pr_debug("%s: -> %d\n", __func__, ret);
907 return ret;
910 static int gelic_wl_get_auth(struct net_device *netdev,
911 struct iw_request_info *info,
912 union iwreq_data *iwreq, char *extra)
914 struct iw_param *param = &iwreq->param;
915 struct gelic_wl_info *wl = port_wl(netdev_port(netdev));
916 unsigned long irqflag;
917 int ret = 0;
919 pr_debug("%s: <- %d\n", __func__, param->flags & IW_AUTH_INDEX);
920 spin_lock_irqsave(&wl->lock, irqflag);
921 switch (param->flags & IW_AUTH_INDEX) {
922 case IW_AUTH_WPA_VERSION:
923 switch (wl->wpa_level) {
924 case GELIC_WL_WPA_LEVEL_WPA:
925 param->value |= IW_AUTH_WPA_VERSION_WPA;
926 break;
927 case GELIC_WL_WPA_LEVEL_WPA2:
928 param->value |= IW_AUTH_WPA_VERSION_WPA2;
929 break;
930 default:
931 param->value |= IW_AUTH_WPA_VERSION_DISABLED;
933 break;
935 case IW_AUTH_80211_AUTH_ALG:
936 if (wl->auth_method == GELIC_EURUS_AUTH_SHARED)
937 param->value = IW_AUTH_ALG_SHARED_KEY;
938 else if (wl->auth_method == GELIC_EURUS_AUTH_OPEN)
939 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
940 break;
942 case IW_AUTH_WPA_ENABLED:
943 switch (wl->wpa_level) {
944 case GELIC_WL_WPA_LEVEL_WPA:
945 case GELIC_WL_WPA_LEVEL_WPA2:
946 param->value = 1;
947 break;
948 default:
949 param->value = 0;
950 break;
952 break;
953 default:
954 ret = -EOPNOTSUPP;
957 spin_unlock_irqrestore(&wl->lock, irqflag);
958 pr_debug("%s: -> %d\n", __func__, ret);
959 return ret;
962 /* SIOC{S,G}IWESSID */
963 static int gelic_wl_set_essid(struct net_device *netdev,
964 struct iw_request_info *info,
965 union iwreq_data *data, char *extra)
967 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
968 unsigned long irqflag;
970 pr_debug("%s: <- l=%d f=%d\n", __func__,
971 data->essid.length, data->essid.flags);
972 if (IW_ESSID_MAX_SIZE < data->essid.length)
973 return -EINVAL;
975 spin_lock_irqsave(&wl->lock, irqflag);
976 if (data->essid.flags) {
977 wl->essid_len = data->essid.length;
978 memcpy(wl->essid, extra, wl->essid_len);
979 pr_debug("%s: essid = '%s'\n", __func__, extra);
980 set_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
981 } else {
982 pr_debug("%s: ESSID any\n", __func__);
983 clear_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat);
985 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
986 spin_unlock_irqrestore(&wl->lock, irqflag);
989 gelic_wl_try_associate(netdev); /* FIXME */
990 pr_debug("%s: ->\n", __func__);
991 return 0;
994 static int gelic_wl_get_essid(struct net_device *netdev,
995 struct iw_request_info *info,
996 union iwreq_data *data, char *extra)
998 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
999 unsigned long irqflag;
1001 pr_debug("%s: <-\n", __func__);
1002 mutex_lock(&wl->assoc_stat_lock);
1003 spin_lock_irqsave(&wl->lock, irqflag);
1004 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat) ||
1005 wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1006 memcpy(extra, wl->essid, wl->essid_len);
1007 data->essid.length = wl->essid_len;
1008 data->essid.flags = 1;
1009 } else
1010 data->essid.flags = 0;
1012 mutex_unlock(&wl->assoc_stat_lock);
1013 spin_unlock_irqrestore(&wl->lock, irqflag);
1014 pr_debug("%s: -> len=%d\n", __func__, data->essid.length);
1016 return 0;
1019 /* SIO{S,G}IWENCODE */
1020 static int gelic_wl_set_encode(struct net_device *netdev,
1021 struct iw_request_info *info,
1022 union iwreq_data *data, char *extra)
1024 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1025 struct iw_point *enc = &data->encoding;
1026 __u16 flags;
1027 unsigned long irqflag;
1028 int key_index, index_specified;
1029 int ret = 0;
1031 pr_debug("%s: <-\n", __func__);
1032 flags = enc->flags & IW_ENCODE_FLAGS;
1033 key_index = enc->flags & IW_ENCODE_INDEX;
1035 pr_debug("%s: key_index = %d\n", __func__, key_index);
1036 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1037 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1039 if (GELIC_WEP_KEYS < key_index)
1040 return -EINVAL;
1042 spin_lock_irqsave(&wl->lock, irqflag);
1043 if (key_index) {
1044 index_specified = 1;
1045 key_index--;
1046 } else {
1047 index_specified = 0;
1048 key_index = wl->current_key;
1051 if (flags & IW_ENCODE_NOKEY) {
1052 /* if just IW_ENCODE_NOKEY, change current key index */
1053 if (!flags && index_specified) {
1054 wl->current_key = key_index;
1055 goto done;
1058 if (flags & IW_ENCODE_DISABLED) {
1059 if (!index_specified) {
1060 /* disable encryption */
1061 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1062 wl->pairwise_cipher_method =
1063 GELIC_WL_CIPHER_NONE;
1064 /* invalidate all key */
1065 wl->key_enabled = 0;
1066 } else
1067 clear_bit(key_index, &wl->key_enabled);
1070 if (flags & IW_ENCODE_OPEN)
1071 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1072 if (flags & IW_ENCODE_RESTRICTED) {
1073 pr_info("%s: shared key mode enabled\n", __func__);
1074 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1076 } else {
1077 if (IW_ENCODING_TOKEN_MAX < enc->length) {
1078 ret = -EINVAL;
1079 goto done;
1081 wl->key_len[key_index] = enc->length;
1082 memcpy(wl->key[key_index], extra, enc->length);
1083 set_bit(key_index, &wl->key_enabled);
1084 wl->pairwise_cipher_method = GELIC_WL_CIPHER_WEP;
1085 wl->group_cipher_method = GELIC_WL_CIPHER_WEP;
1087 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1088 done:
1089 spin_unlock_irqrestore(&wl->lock, irqflag);
1090 pr_debug("%s: ->\n", __func__);
1091 return ret;
1094 static int gelic_wl_get_encode(struct net_device *netdev,
1095 struct iw_request_info *info,
1096 union iwreq_data *data, char *extra)
1098 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1099 struct iw_point *enc = &data->encoding;
1100 unsigned long irqflag;
1101 unsigned int key_index, index_specified;
1102 int ret = 0;
1104 pr_debug("%s: <-\n", __func__);
1105 key_index = enc->flags & IW_ENCODE_INDEX;
1106 pr_debug("%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
1107 enc->flags, enc->pointer, enc->length, extra);
1108 if (GELIC_WEP_KEYS < key_index)
1109 return -EINVAL;
1111 spin_lock_irqsave(&wl->lock, irqflag);
1112 if (key_index) {
1113 index_specified = 1;
1114 key_index--;
1115 } else {
1116 index_specified = 0;
1117 key_index = wl->current_key;
1120 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1121 switch (wl->auth_method) {
1122 case GELIC_EURUS_AUTH_OPEN:
1123 enc->flags = IW_ENCODE_OPEN;
1124 break;
1125 case GELIC_EURUS_AUTH_SHARED:
1126 enc->flags = IW_ENCODE_RESTRICTED;
1127 break;
1129 } else
1130 enc->flags = IW_ENCODE_DISABLED;
1132 if (test_bit(key_index, &wl->key_enabled)) {
1133 if (enc->length < wl->key_len[key_index]) {
1134 ret = -EINVAL;
1135 goto done;
1137 enc->length = wl->key_len[key_index];
1138 memcpy(extra, wl->key[key_index], wl->key_len[key_index]);
1139 } else {
1140 enc->length = 0;
1141 enc->flags |= IW_ENCODE_NOKEY;
1143 enc->flags |= key_index + 1;
1144 pr_debug("%s: -> flag=%x len=%d\n", __func__,
1145 enc->flags, enc->length);
1147 done:
1148 spin_unlock_irqrestore(&wl->lock, irqflag);
1149 return ret;
1152 /* SIOC{S,G}IWAP */
1153 static int gelic_wl_set_ap(struct net_device *netdev,
1154 struct iw_request_info *info,
1155 union iwreq_data *data, char *extra)
1157 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1158 unsigned long irqflag;
1160 pr_debug("%s: <-\n", __func__);
1161 if (data->ap_addr.sa_family != ARPHRD_ETHER)
1162 return -EINVAL;
1164 spin_lock_irqsave(&wl->lock, irqflag);
1165 if (is_valid_ether_addr(data->ap_addr.sa_data)) {
1166 memcpy(wl->bssid, data->ap_addr.sa_data,
1167 ETH_ALEN);
1168 set_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1169 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1170 pr_debug("%s: bss=%pM\n", __func__, wl->bssid);
1171 } else {
1172 pr_debug("%s: clear bssid\n", __func__);
1173 clear_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat);
1174 memset(wl->bssid, 0, ETH_ALEN);
1176 spin_unlock_irqrestore(&wl->lock, irqflag);
1177 pr_debug("%s: ->\n", __func__);
1178 return 0;
1181 static int gelic_wl_get_ap(struct net_device *netdev,
1182 struct iw_request_info *info,
1183 union iwreq_data *data, char *extra)
1185 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1186 unsigned long irqflag;
1188 pr_debug("%s: <-\n", __func__);
1189 mutex_lock(&wl->assoc_stat_lock);
1190 spin_lock_irqsave(&wl->lock, irqflag);
1191 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED) {
1192 data->ap_addr.sa_family = ARPHRD_ETHER;
1193 memcpy(data->ap_addr.sa_data, wl->active_bssid,
1194 ETH_ALEN);
1195 } else
1196 memset(data->ap_addr.sa_data, 0, ETH_ALEN);
1198 spin_unlock_irqrestore(&wl->lock, irqflag);
1199 mutex_unlock(&wl->assoc_stat_lock);
1200 pr_debug("%s: ->\n", __func__);
1201 return 0;
1204 /* SIOC{S,G}IWENCODEEXT */
1205 static int gelic_wl_set_encodeext(struct net_device *netdev,
1206 struct iw_request_info *info,
1207 union iwreq_data *data, char *extra)
1209 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1210 struct iw_point *enc = &data->encoding;
1211 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1212 __u16 alg;
1213 __u16 flags;
1214 unsigned long irqflag;
1215 int key_index;
1216 int ret = 0;
1218 pr_debug("%s: <-\n", __func__);
1219 flags = enc->flags & IW_ENCODE_FLAGS;
1220 alg = ext->alg;
1221 key_index = enc->flags & IW_ENCODE_INDEX;
1223 pr_debug("%s: key_index = %d\n", __func__, key_index);
1224 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1225 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1226 pr_debug("%s: ext_flag=%x\n", __func__, ext->ext_flags);
1227 pr_debug("%s: ext_key_len=%x\n", __func__, ext->key_len);
1229 if (GELIC_WEP_KEYS < key_index)
1230 return -EINVAL;
1232 spin_lock_irqsave(&wl->lock, irqflag);
1233 if (key_index)
1234 key_index--;
1235 else
1236 key_index = wl->current_key;
1238 if (!enc->length && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
1239 /* reques to change default key index */
1240 pr_debug("%s: request to change default key to %d\n",
1241 __func__, key_index);
1242 wl->current_key = key_index;
1243 goto done;
1246 if (alg == IW_ENCODE_ALG_NONE || (flags & IW_ENCODE_DISABLED)) {
1247 pr_debug("%s: alg disabled\n", __func__);
1248 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
1249 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
1250 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
1251 wl->auth_method = GELIC_EURUS_AUTH_OPEN; /* should be open */
1252 } else if (alg == IW_ENCODE_ALG_WEP) {
1253 pr_debug("%s: WEP requested\n", __func__);
1254 if (flags & IW_ENCODE_OPEN) {
1255 pr_debug("%s: open key mode\n", __func__);
1256 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
1258 if (flags & IW_ENCODE_RESTRICTED) {
1259 pr_debug("%s: shared key mode\n", __func__);
1260 wl->auth_method = GELIC_EURUS_AUTH_SHARED;
1262 if (IW_ENCODING_TOKEN_MAX < ext->key_len) {
1263 pr_info("%s: key is too long %d\n", __func__,
1264 ext->key_len);
1265 ret = -EINVAL;
1266 goto done;
1268 /* OK, update the key */
1269 wl->key_len[key_index] = ext->key_len;
1270 memset(wl->key[key_index], 0, IW_ENCODING_TOKEN_MAX);
1271 memcpy(wl->key[key_index], ext->key, ext->key_len);
1272 set_bit(key_index, &wl->key_enabled);
1273 /* remember wep info changed */
1274 set_bit(GELIC_WL_STAT_CONFIGURED, &wl->stat);
1275 } else if (alg == IW_ENCODE_ALG_PMK) {
1276 if (ext->key_len != WPA_PSK_LEN) {
1277 pr_err("%s: PSK length wrong %d\n", __func__,
1278 ext->key_len);
1279 ret = -EINVAL;
1280 goto done;
1282 memset(wl->psk, 0, sizeof(wl->psk));
1283 memcpy(wl->psk, ext->key, ext->key_len);
1284 wl->psk_len = ext->key_len;
1285 wl->psk_type = GELIC_EURUS_WPA_PSK_BIN;
1286 /* remember PSK configured */
1287 set_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat);
1289 done:
1290 spin_unlock_irqrestore(&wl->lock, irqflag);
1291 pr_debug("%s: ->\n", __func__);
1292 return ret;
1295 static int gelic_wl_get_encodeext(struct net_device *netdev,
1296 struct iw_request_info *info,
1297 union iwreq_data *data, char *extra)
1299 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1300 struct iw_point *enc = &data->encoding;
1301 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1302 unsigned long irqflag;
1303 int key_index;
1304 int ret = 0;
1305 int max_key_len;
1307 pr_debug("%s: <-\n", __func__);
1309 max_key_len = enc->length - sizeof(struct iw_encode_ext);
1310 if (max_key_len < 0)
1311 return -EINVAL;
1312 key_index = enc->flags & IW_ENCODE_INDEX;
1314 pr_debug("%s: key_index = %d\n", __func__, key_index);
1315 pr_debug("%s: key_len = %d\n", __func__, enc->length);
1316 pr_debug("%s: flag=%x\n", __func__, enc->flags & IW_ENCODE_FLAGS);
1318 if (GELIC_WEP_KEYS < key_index)
1319 return -EINVAL;
1321 spin_lock_irqsave(&wl->lock, irqflag);
1322 if (key_index)
1323 key_index--;
1324 else
1325 key_index = wl->current_key;
1327 memset(ext, 0, sizeof(struct iw_encode_ext));
1328 switch (wl->group_cipher_method) {
1329 case GELIC_WL_CIPHER_WEP:
1330 ext->alg = IW_ENCODE_ALG_WEP;
1331 enc->flags |= IW_ENCODE_ENABLED;
1332 break;
1333 case GELIC_WL_CIPHER_TKIP:
1334 ext->alg = IW_ENCODE_ALG_TKIP;
1335 enc->flags |= IW_ENCODE_ENABLED;
1336 break;
1337 case GELIC_WL_CIPHER_AES:
1338 ext->alg = IW_ENCODE_ALG_CCMP;
1339 enc->flags |= IW_ENCODE_ENABLED;
1340 break;
1341 case GELIC_WL_CIPHER_NONE:
1342 default:
1343 ext->alg = IW_ENCODE_ALG_NONE;
1344 enc->flags |= IW_ENCODE_NOKEY;
1345 break;
1348 if (!(enc->flags & IW_ENCODE_NOKEY)) {
1349 if (max_key_len < wl->key_len[key_index]) {
1350 ret = -E2BIG;
1351 goto out;
1353 if (test_bit(key_index, &wl->key_enabled))
1354 memcpy(ext->key, wl->key[key_index],
1355 wl->key_len[key_index]);
1356 else
1357 pr_debug("%s: disabled key requested ix=%d\n",
1358 __func__, key_index);
1360 out:
1361 spin_unlock_irqrestore(&wl->lock, irqflag);
1362 pr_debug("%s: ->\n", __func__);
1363 return ret;
1365 /* SIOC{S,G}IWMODE */
1366 static int gelic_wl_set_mode(struct net_device *netdev,
1367 struct iw_request_info *info,
1368 union iwreq_data *data, char *extra)
1370 __u32 mode = data->mode;
1371 int ret;
1373 pr_debug("%s: <-\n", __func__);
1374 if (mode == IW_MODE_INFRA)
1375 ret = 0;
1376 else
1377 ret = -EOPNOTSUPP;
1378 pr_debug("%s: -> %d\n", __func__, ret);
1379 return ret;
1382 static int gelic_wl_get_mode(struct net_device *netdev,
1383 struct iw_request_info *info,
1384 union iwreq_data *data, char *extra)
1386 __u32 *mode = &data->mode;
1387 pr_debug("%s: <-\n", __func__);
1388 *mode = IW_MODE_INFRA;
1389 pr_debug("%s: ->\n", __func__);
1390 return 0;
1393 /* SIOCGIWNICKN */
1394 static int gelic_wl_get_nick(struct net_device *net_dev,
1395 struct iw_request_info *info,
1396 union iwreq_data *data, char *extra)
1398 strcpy(extra, "gelic_wl");
1399 data->data.length = strlen(extra);
1400 data->data.flags = 1;
1401 return 0;
1405 /* --- */
1407 static struct iw_statistics *gelic_wl_get_wireless_stats(
1408 struct net_device *netdev)
1411 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
1412 struct gelic_eurus_cmd *cmd;
1413 struct iw_statistics *is;
1414 struct gelic_eurus_rssi_info *rssi;
1415 void *buf;
1417 pr_debug("%s: <-\n", __func__);
1419 buf = (void *)__get_free_page(GFP_KERNEL);
1420 if (!buf)
1421 return NULL;
1423 is = &wl->iwstat;
1424 memset(is, 0, sizeof(*is));
1425 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_RSSI_CFG,
1426 buf, sizeof(*rssi));
1427 if (cmd && !cmd->status && !cmd->cmd_status) {
1428 rssi = buf;
1429 is->qual.level = be16_to_cpu(rssi->rssi);
1430 is->qual.updated = IW_QUAL_LEVEL_UPDATED |
1431 IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID;
1432 } else
1433 /* not associated */
1434 is->qual.updated = IW_QUAL_ALL_INVALID;
1436 kfree(cmd);
1437 free_page((unsigned long)buf);
1438 pr_debug("%s: ->\n", __func__);
1439 return is;
1443 * scanning helpers
1445 static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan,
1446 u8 *essid, size_t essid_len)
1448 struct gelic_eurus_cmd *cmd;
1449 int ret = 0;
1450 void *buf = NULL;
1451 size_t len;
1453 pr_debug("%s: <- always=%d\n", __func__, always_scan);
1454 if (mutex_lock_interruptible(&wl->scan_lock))
1455 return -ERESTARTSYS;
1458 * If already a scan in progress, do not trigger more
1460 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING) {
1461 pr_debug("%s: scanning now\n", __func__);
1462 goto out;
1465 init_completion(&wl->scan_done);
1467 * If we have already a bss list, don't try to get new
1468 * unless we are doing an ESSID scan
1470 if ((!essid_len && !always_scan)
1471 && wl->scan_stat == GELIC_WL_SCAN_STAT_GOT_LIST) {
1472 pr_debug("%s: already has the list\n", __func__);
1473 complete(&wl->scan_done);
1474 goto out;
1477 /* ESSID scan ? */
1478 if (essid_len && essid) {
1479 buf = (void *)__get_free_page(GFP_KERNEL);
1480 if (!buf) {
1481 ret = -ENOMEM;
1482 goto out;
1484 len = IW_ESSID_MAX_SIZE; /* hypervisor always requires 32 */
1485 memset(buf, 0, len);
1486 memcpy(buf, essid, essid_len);
1487 pr_debug("%s: essid scan='%s'\n", __func__, (char *)buf);
1488 } else
1489 len = 0;
1492 * issue start scan request
1494 wl->scan_stat = GELIC_WL_SCAN_STAT_SCANNING;
1495 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_START_SCAN,
1496 buf, len);
1497 if (!cmd || cmd->status || cmd->cmd_status) {
1498 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1499 complete(&wl->scan_done);
1500 ret = -ENOMEM;
1501 goto out;
1503 kfree(cmd);
1504 out:
1505 free_page((unsigned long)buf);
1506 mutex_unlock(&wl->scan_lock);
1507 pr_debug("%s: ->\n", __func__);
1508 return ret;
1512 * retrieve scan result from the chip (hypervisor)
1513 * this function is invoked by schedule work.
1515 static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl)
1517 struct gelic_eurus_cmd *cmd = NULL;
1518 struct gelic_wl_scan_info *target, *tmp;
1519 struct gelic_wl_scan_info *oldest = NULL;
1520 struct gelic_eurus_scan_info *scan_info;
1521 unsigned int scan_info_size;
1522 union iwreq_data data;
1523 unsigned long this_time = jiffies;
1524 unsigned int data_len, i, found, r;
1525 void *buf;
1527 pr_debug("%s:start\n", __func__);
1528 mutex_lock(&wl->scan_lock);
1530 buf = (void *)__get_free_page(GFP_KERNEL);
1531 if (!buf) {
1532 pr_info("%s: scan buffer alloc failed\n", __func__);
1533 goto out;
1536 if (wl->scan_stat != GELIC_WL_SCAN_STAT_SCANNING) {
1538 * stop() may be called while scanning, ignore result
1540 pr_debug("%s: scan complete when stat != scanning(%d)\n",
1541 __func__, wl->scan_stat);
1542 goto out;
1545 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_GET_SCAN,
1546 buf, PAGE_SIZE);
1547 if (!cmd || cmd->status || cmd->cmd_status) {
1548 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
1549 pr_info("%s:cmd failed\n", __func__);
1550 kfree(cmd);
1551 goto out;
1553 data_len = cmd->size;
1554 pr_debug("%s: data_len = %d\n", __func__, data_len);
1555 kfree(cmd);
1557 /* OK, bss list retrieved */
1558 wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST;
1560 /* mark all entries are old */
1561 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
1562 target->valid = 0;
1563 /* expire too old entries */
1564 if (time_before(target->last_scanned + wl->scan_age,
1565 this_time)) {
1566 kfree(target->hwinfo);
1567 target->hwinfo = NULL;
1568 list_move_tail(&target->list, &wl->network_free_list);
1572 /* put them in the network_list */
1573 for (i = 0, scan_info_size = 0, scan_info = buf;
1574 scan_info_size < data_len;
1575 i++, scan_info_size += be16_to_cpu(scan_info->size),
1576 scan_info = (void *)scan_info + be16_to_cpu(scan_info->size)) {
1577 pr_debug("%s:size=%d bssid=%pM scan_info=%p\n", __func__,
1578 be16_to_cpu(scan_info->size),
1579 &scan_info->bssid[2], scan_info);
1582 * The wireless firmware may return invalid channel 0 and/or
1583 * invalid rate if the AP emits zero length SSID ie. As this
1584 * scan information is useless, ignore it
1586 if (!be16_to_cpu(scan_info->channel) || !scan_info->rate[0]) {
1587 pr_debug("%s: invalid scan info\n", __func__);
1588 continue;
1591 found = 0;
1592 oldest = NULL;
1593 list_for_each_entry(target, &wl->network_list, list) {
1594 if (!compare_ether_addr(&target->hwinfo->bssid[2],
1595 &scan_info->bssid[2])) {
1596 found = 1;
1597 pr_debug("%s: same BBS found scanned list\n",
1598 __func__);
1599 break;
1601 if (!oldest ||
1602 (target->last_scanned < oldest->last_scanned))
1603 oldest = target;
1606 if (!found) {
1607 /* not found in the list */
1608 if (list_empty(&wl->network_free_list)) {
1609 /* expire oldest */
1610 target = oldest;
1611 } else {
1612 target = list_entry(wl->network_free_list.next,
1613 struct gelic_wl_scan_info,
1614 list);
1618 /* update the item */
1619 target->last_scanned = this_time;
1620 target->valid = 1;
1621 target->eurus_index = i;
1622 kfree(target->hwinfo);
1623 target->hwinfo = kzalloc(be16_to_cpu(scan_info->size),
1624 GFP_KERNEL);
1625 if (!target->hwinfo) {
1626 pr_info("%s: kzalloc failed\n", __func__);
1627 continue;
1629 /* copy hw scan info */
1630 memcpy(target->hwinfo, scan_info, scan_info->size);
1631 target->essid_len = strnlen(scan_info->essid,
1632 sizeof(scan_info->essid));
1633 target->rate_len = 0;
1634 for (r = 0; r < 12; r++)
1635 if (scan_info->rate[r])
1636 target->rate_len++;
1637 if (8 < target->rate_len)
1638 pr_info("%s: AP returns %d rates\n", __func__,
1639 target->rate_len);
1640 target->rate_ext_len = 0;
1641 for (r = 0; r < 16; r++)
1642 if (scan_info->ext_rate[r])
1643 target->rate_ext_len++;
1644 list_move_tail(&target->list, &wl->network_list);
1646 memset(&data, 0, sizeof(data));
1647 wireless_send_event(port_to_netdev(wl_port(wl)), SIOCGIWSCAN, &data,
1648 NULL);
1649 out:
1650 free_page((unsigned long)buf);
1651 complete(&wl->scan_done);
1652 mutex_unlock(&wl->scan_lock);
1653 pr_debug("%s:end\n", __func__);
1657 * Select an appropriate bss from current scan list regarding
1658 * current settings from userspace.
1659 * The caller must hold wl->scan_lock,
1660 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1662 static void update_best(struct gelic_wl_scan_info **best,
1663 struct gelic_wl_scan_info *candid,
1664 int *best_weight,
1665 int *weight)
1667 if (*best_weight < ++(*weight)) {
1668 *best_weight = *weight;
1669 *best = candid;
1673 static
1674 struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
1676 struct gelic_wl_scan_info *scan_info;
1677 struct gelic_wl_scan_info *best_bss;
1678 int weight, best_weight;
1679 u16 security;
1681 pr_debug("%s: <-\n", __func__);
1683 best_bss = NULL;
1684 best_weight = 0;
1686 list_for_each_entry(scan_info, &wl->network_list, list) {
1687 pr_debug("%s: station %p\n", __func__, scan_info);
1689 if (!scan_info->valid) {
1690 pr_debug("%s: station invalid\n", __func__);
1691 continue;
1694 /* If bss specified, check it only */
1695 if (test_bit(GELIC_WL_STAT_BSSID_SET, &wl->stat)) {
1696 if (!compare_ether_addr(&scan_info->hwinfo->bssid[2],
1697 wl->bssid)) {
1698 best_bss = scan_info;
1699 pr_debug("%s: bssid matched\n", __func__);
1700 break;
1701 } else {
1702 pr_debug("%s: bssid unmached\n", __func__);
1703 continue;
1707 weight = 0;
1709 /* security */
1710 security = be16_to_cpu(scan_info->hwinfo->security) &
1711 GELIC_EURUS_SCAN_SEC_MASK;
1712 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1713 if (security == GELIC_EURUS_SCAN_SEC_WPA2)
1714 update_best(&best_bss, scan_info,
1715 &best_weight, &weight);
1716 else
1717 continue;
1718 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA) {
1719 if (security == GELIC_EURUS_SCAN_SEC_WPA)
1720 update_best(&best_bss, scan_info,
1721 &best_weight, &weight);
1722 else
1723 continue;
1724 } else if (wl->wpa_level == GELIC_WL_WPA_LEVEL_NONE &&
1725 wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1726 if (security == GELIC_EURUS_SCAN_SEC_WEP)
1727 update_best(&best_bss, scan_info,
1728 &best_weight, &weight);
1729 else
1730 continue;
1733 /* If ESSID is set, check it */
1734 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
1735 if ((scan_info->essid_len == wl->essid_len) &&
1736 !strncmp(wl->essid,
1737 scan_info->hwinfo->essid,
1738 scan_info->essid_len))
1739 update_best(&best_bss, scan_info,
1740 &best_weight, &weight);
1741 else
1742 continue;
1746 #ifdef DEBUG
1747 pr_debug("%s: -> bss=%p\n", __func__, best_bss);
1748 if (best_bss) {
1749 pr_debug("%s:addr=%pM\n", __func__,
1750 &best_bss->hwinfo->bssid[2]);
1752 #endif
1753 return best_bss;
1757 * Setup WEP configuration to the chip
1758 * The caller must hold wl->scan_lock,
1759 * and on the state of wl->scan_state == GELIC_WL_SCAN_GOT_LIST
1761 static int gelic_wl_do_wep_setup(struct gelic_wl_info *wl)
1763 unsigned int i;
1764 struct gelic_eurus_wep_cfg *wep;
1765 struct gelic_eurus_cmd *cmd;
1766 int wep104 = 0;
1767 int have_key = 0;
1768 int ret = 0;
1770 pr_debug("%s: <-\n", __func__);
1771 /* we can assume no one should uses the buffer */
1772 wep = (struct gelic_eurus_wep_cfg *)__get_free_page(GFP_KERNEL);
1773 if (!wep)
1774 return -ENOMEM;
1776 memset(wep, 0, sizeof(*wep));
1778 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
1779 pr_debug("%s: WEP mode\n", __func__);
1780 for (i = 0; i < GELIC_WEP_KEYS; i++) {
1781 if (!test_bit(i, &wl->key_enabled))
1782 continue;
1784 pr_debug("%s: key#%d enabled\n", __func__, i);
1785 have_key = 1;
1786 if (wl->key_len[i] == 13)
1787 wep104 = 1;
1788 else if (wl->key_len[i] != 5) {
1789 pr_info("%s: wrong wep key[%d]=%d\n",
1790 __func__, i, wl->key_len[i]);
1791 ret = -EINVAL;
1792 goto out;
1794 memcpy(wep->key[i], wl->key[i], wl->key_len[i]);
1797 if (!have_key) {
1798 pr_info("%s: all wep key disabled\n", __func__);
1799 ret = -EINVAL;
1800 goto out;
1803 if (wep104) {
1804 pr_debug("%s: 104bit key\n", __func__);
1805 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_104BIT);
1806 } else {
1807 pr_debug("%s: 40bit key\n", __func__);
1808 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_40BIT);
1810 } else {
1811 pr_debug("%s: NO encryption\n", __func__);
1812 wep->security = cpu_to_be16(GELIC_EURUS_WEP_SEC_NONE);
1815 /* issue wep setup */
1816 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WEP_CFG,
1817 wep, sizeof(*wep));
1818 if (!cmd)
1819 ret = -ENOMEM;
1820 else if (cmd->status || cmd->cmd_status)
1821 ret = -ENXIO;
1823 kfree(cmd);
1824 out:
1825 free_page((unsigned long)wep);
1826 pr_debug("%s: ->\n", __func__);
1827 return ret;
1830 #ifdef DEBUG
1831 static const char *wpasecstr(enum gelic_eurus_wpa_security sec)
1833 switch (sec) {
1834 case GELIC_EURUS_WPA_SEC_NONE:
1835 return "NONE";
1836 break;
1837 case GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP:
1838 return "WPA_TKIP_TKIP";
1839 break;
1840 case GELIC_EURUS_WPA_SEC_WPA_TKIP_AES:
1841 return "WPA_TKIP_AES";
1842 break;
1843 case GELIC_EURUS_WPA_SEC_WPA_AES_AES:
1844 return "WPA_AES_AES";
1845 break;
1846 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP:
1847 return "WPA2_TKIP_TKIP";
1848 break;
1849 case GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES:
1850 return "WPA2_TKIP_AES";
1851 break;
1852 case GELIC_EURUS_WPA_SEC_WPA2_AES_AES:
1853 return "WPA2_AES_AES";
1854 break;
1856 return "";
1858 #endif
1860 static int gelic_wl_do_wpa_setup(struct gelic_wl_info *wl)
1862 struct gelic_eurus_wpa_cfg *wpa;
1863 struct gelic_eurus_cmd *cmd;
1864 u16 security;
1865 int ret = 0;
1867 pr_debug("%s: <-\n", __func__);
1868 /* we can assume no one should uses the buffer */
1869 wpa = (struct gelic_eurus_wpa_cfg *)__get_free_page(GFP_KERNEL);
1870 if (!wpa)
1871 return -ENOMEM;
1873 memset(wpa, 0, sizeof(*wpa));
1875 if (!test_bit(GELIC_WL_STAT_WPA_PSK_SET, &wl->stat))
1876 pr_info("%s: PSK not configured yet\n", __func__);
1878 /* copy key */
1879 memcpy(wpa->psk, wl->psk, wl->psk_len);
1881 /* set security level */
1882 if (wl->wpa_level == GELIC_WL_WPA_LEVEL_WPA2) {
1883 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1884 security = GELIC_EURUS_WPA_SEC_WPA2_AES_AES;
1885 } else {
1886 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1887 precise_ie())
1888 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_AES;
1889 else
1890 security = GELIC_EURUS_WPA_SEC_WPA2_TKIP_TKIP;
1892 } else {
1893 if (wl->group_cipher_method == GELIC_WL_CIPHER_AES) {
1894 security = GELIC_EURUS_WPA_SEC_WPA_AES_AES;
1895 } else {
1896 if (wl->pairwise_cipher_method == GELIC_WL_CIPHER_AES &&
1897 precise_ie())
1898 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_AES;
1899 else
1900 security = GELIC_EURUS_WPA_SEC_WPA_TKIP_TKIP;
1903 wpa->security = cpu_to_be16(security);
1905 /* PSK type */
1906 wpa->psk_type = cpu_to_be16(wl->psk_type);
1907 #ifdef DEBUG
1908 pr_debug("%s: sec=%s psktype=%s\n", __func__,
1909 wpasecstr(wpa->security),
1910 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1911 "BIN" : "passphrase");
1912 #if 0
1914 * don't enable here if you plan to submit
1915 * the debug log because this dumps your precious
1916 * passphrase/key.
1918 pr_debug("%s: psk=%s\n", __func__,
1919 (wpa->psk_type == GELIC_EURUS_WPA_PSK_BIN) ?
1920 "N/A" : wpa->psk);
1921 #endif
1922 #endif
1923 /* issue wpa setup */
1924 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_WPA_CFG,
1925 wpa, sizeof(*wpa));
1926 if (!cmd)
1927 ret = -ENOMEM;
1928 else if (cmd->status || cmd->cmd_status)
1929 ret = -ENXIO;
1930 kfree(cmd);
1931 free_page((unsigned long)wpa);
1932 pr_debug("%s: --> %d\n", __func__, ret);
1933 return ret;
1937 * Start association. caller must hold assoc_stat_lock
1939 static int gelic_wl_associate_bss(struct gelic_wl_info *wl,
1940 struct gelic_wl_scan_info *bss)
1942 struct gelic_eurus_cmd *cmd;
1943 struct gelic_eurus_common_cfg *common;
1944 int ret = 0;
1945 unsigned long rc;
1947 pr_debug("%s: <-\n", __func__);
1949 /* do common config */
1950 common = (struct gelic_eurus_common_cfg *)__get_free_page(GFP_KERNEL);
1951 if (!common)
1952 return -ENOMEM;
1954 memset(common, 0, sizeof(*common));
1955 common->bss_type = cpu_to_be16(GELIC_EURUS_BSS_INFRA);
1956 common->op_mode = cpu_to_be16(GELIC_EURUS_OPMODE_11BG);
1958 common->scan_index = cpu_to_be16(bss->eurus_index);
1959 switch (wl->auth_method) {
1960 case GELIC_EURUS_AUTH_OPEN:
1961 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_OPEN);
1962 break;
1963 case GELIC_EURUS_AUTH_SHARED:
1964 common->auth_method = cpu_to_be16(GELIC_EURUS_AUTH_SHARED);
1965 break;
1968 #ifdef DEBUG
1969 scan_list_dump(wl);
1970 #endif
1971 pr_debug("%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
1972 be16_to_cpu(common->scan_index),
1973 be16_to_cpu(common->bss_type),
1974 be16_to_cpu(common->auth_method));
1976 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_SET_COMMON_CFG,
1977 common, sizeof(*common));
1978 if (!cmd || cmd->status || cmd->cmd_status) {
1979 ret = -ENOMEM;
1980 kfree(cmd);
1981 goto out;
1983 kfree(cmd);
1985 /* WEP/WPA */
1986 switch (wl->wpa_level) {
1987 case GELIC_WL_WPA_LEVEL_NONE:
1988 /* If WEP or no security, setup WEP config */
1989 ret = gelic_wl_do_wep_setup(wl);
1990 break;
1991 case GELIC_WL_WPA_LEVEL_WPA:
1992 case GELIC_WL_WPA_LEVEL_WPA2:
1993 ret = gelic_wl_do_wpa_setup(wl);
1994 break;
1997 if (ret) {
1998 pr_debug("%s: WEP/WPA setup failed %d\n", __func__,
1999 ret);
2000 ret = -EPERM;
2001 gelic_wl_send_iwap_event(wl, NULL);
2002 goto out;
2005 /* start association */
2006 init_completion(&wl->assoc_done);
2007 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATING;
2008 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_ASSOC,
2009 NULL, 0);
2010 if (!cmd || cmd->status || cmd->cmd_status) {
2011 pr_debug("%s: assoc request failed\n", __func__);
2012 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2013 kfree(cmd);
2014 ret = -ENOMEM;
2015 gelic_wl_send_iwap_event(wl, NULL);
2016 goto out;
2018 kfree(cmd);
2020 /* wait for connected event */
2021 rc = wait_for_completion_timeout(&wl->assoc_done, HZ * 4);/*FIXME*/
2023 if (!rc) {
2024 /* timeouted. Maybe key or cyrpt mode is wrong */
2025 pr_info("%s: connect timeout\n", __func__);
2026 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC,
2027 NULL, 0);
2028 kfree(cmd);
2029 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2030 gelic_wl_send_iwap_event(wl, NULL);
2031 ret = -ENXIO;
2032 } else {
2033 wl->assoc_stat = GELIC_WL_ASSOC_STAT_ASSOCIATED;
2034 /* copy bssid */
2035 memcpy(wl->active_bssid, &bss->hwinfo->bssid[2], ETH_ALEN);
2037 /* send connect event */
2038 gelic_wl_send_iwap_event(wl, wl->active_bssid);
2039 pr_info("%s: connected\n", __func__);
2041 out:
2042 free_page((unsigned long)common);
2043 pr_debug("%s: ->\n", __func__);
2044 return ret;
2048 * connected event
2050 static void gelic_wl_connected_event(struct gelic_wl_info *wl,
2051 u64 event)
2053 u64 desired_event = 0;
2055 switch (wl->wpa_level) {
2056 case GELIC_WL_WPA_LEVEL_NONE:
2057 desired_event = GELIC_LV1_WL_EVENT_CONNECTED;
2058 break;
2059 case GELIC_WL_WPA_LEVEL_WPA:
2060 case GELIC_WL_WPA_LEVEL_WPA2:
2061 desired_event = GELIC_LV1_WL_EVENT_WPA_CONNECTED;
2062 break;
2065 if (desired_event == event) {
2066 pr_debug("%s: completed\n", __func__);
2067 complete(&wl->assoc_done);
2068 netif_carrier_on(port_to_netdev(wl_port(wl)));
2069 } else
2070 pr_debug("%s: event %#llx under wpa\n",
2071 __func__, event);
2075 * disconnect event
2077 static void gelic_wl_disconnect_event(struct gelic_wl_info *wl,
2078 u64 event)
2080 struct gelic_eurus_cmd *cmd;
2081 int lock;
2084 * If we fall here in the middle of association,
2085 * associate_bss() should be waiting for complation of
2086 * wl->assoc_done.
2087 * As it waits with timeout, just leave assoc_done
2088 * uncompleted, then it terminates with timeout
2090 if (!mutex_trylock(&wl->assoc_stat_lock)) {
2091 pr_debug("%s: already locked\n", __func__);
2092 lock = 0;
2093 } else {
2094 pr_debug("%s: obtain lock\n", __func__);
2095 lock = 1;
2098 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2099 kfree(cmd);
2101 /* send disconnected event to the supplicant */
2102 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2103 gelic_wl_send_iwap_event(wl, NULL);
2105 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2106 netif_carrier_off(port_to_netdev(wl_port(wl)));
2108 if (lock)
2109 mutex_unlock(&wl->assoc_stat_lock);
2112 * event worker
2114 #ifdef DEBUG
2115 static const char *eventstr(enum gelic_lv1_wl_event event)
2117 static char buf[32];
2118 char *ret;
2119 if (event & GELIC_LV1_WL_EVENT_DEVICE_READY)
2120 ret = "EURUS_READY";
2121 else if (event & GELIC_LV1_WL_EVENT_SCAN_COMPLETED)
2122 ret = "SCAN_COMPLETED";
2123 else if (event & GELIC_LV1_WL_EVENT_DEAUTH)
2124 ret = "DEAUTH";
2125 else if (event & GELIC_LV1_WL_EVENT_BEACON_LOST)
2126 ret = "BEACON_LOST";
2127 else if (event & GELIC_LV1_WL_EVENT_CONNECTED)
2128 ret = "CONNECTED";
2129 else if (event & GELIC_LV1_WL_EVENT_WPA_CONNECTED)
2130 ret = "WPA_CONNECTED";
2131 else if (event & GELIC_LV1_WL_EVENT_WPA_ERROR)
2132 ret = "WPA_ERROR";
2133 else {
2134 sprintf(buf, "Unknown(%#x)", event);
2135 ret = buf;
2137 return ret;
2139 #else
2140 static const char *eventstr(enum gelic_lv1_wl_event event)
2142 return NULL;
2144 #endif
2145 static void gelic_wl_event_worker(struct work_struct *work)
2147 struct gelic_wl_info *wl;
2148 struct gelic_port *port;
2149 u64 event, tmp;
2150 int status;
2152 pr_debug("%s:start\n", __func__);
2153 wl = container_of(work, struct gelic_wl_info, event_work.work);
2154 port = wl_port(wl);
2155 while (1) {
2156 status = lv1_net_control(bus_id(port->card), dev_id(port->card),
2157 GELIC_LV1_GET_WLAN_EVENT, 0, 0, 0,
2158 &event, &tmp);
2159 if (status) {
2160 if (status != LV1_NO_ENTRY)
2161 pr_debug("%s:wlan event failed %d\n",
2162 __func__, status);
2163 /* got all events */
2164 pr_debug("%s:end\n", __func__);
2165 return;
2167 pr_debug("%s: event=%s\n", __func__, eventstr(event));
2168 switch (event) {
2169 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
2170 gelic_wl_scan_complete_event(wl);
2171 break;
2172 case GELIC_LV1_WL_EVENT_BEACON_LOST:
2173 case GELIC_LV1_WL_EVENT_DEAUTH:
2174 gelic_wl_disconnect_event(wl, event);
2175 break;
2176 case GELIC_LV1_WL_EVENT_CONNECTED:
2177 case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
2178 gelic_wl_connected_event(wl, event);
2179 break;
2180 default:
2181 break;
2183 } /* while */
2186 * association worker
2188 static void gelic_wl_assoc_worker(struct work_struct *work)
2190 struct gelic_wl_info *wl;
2192 struct gelic_wl_scan_info *best_bss;
2193 int ret;
2194 unsigned long irqflag;
2195 u8 *essid;
2196 size_t essid_len;
2198 wl = container_of(work, struct gelic_wl_info, assoc_work.work);
2200 mutex_lock(&wl->assoc_stat_lock);
2202 if (wl->assoc_stat != GELIC_WL_ASSOC_STAT_DISCONN)
2203 goto out;
2205 spin_lock_irqsave(&wl->lock, irqflag);
2206 if (test_bit(GELIC_WL_STAT_ESSID_SET, &wl->stat)) {
2207 pr_debug("%s: assoc ESSID configured %s\n", __func__,
2208 wl->essid);
2209 essid = wl->essid;
2210 essid_len = wl->essid_len;
2211 } else {
2212 essid = NULL;
2213 essid_len = 0;
2215 spin_unlock_irqrestore(&wl->lock, irqflag);
2217 ret = gelic_wl_start_scan(wl, 0, essid, essid_len);
2218 if (ret == -ERESTARTSYS) {
2219 pr_debug("%s: scan start failed association\n", __func__);
2220 schedule_delayed_work(&wl->assoc_work, HZ/10); /*FIXME*/
2221 goto out;
2222 } else if (ret) {
2223 pr_info("%s: scan prerequisite failed\n", __func__);
2224 goto out;
2228 * Wait for bss scan completion
2229 * If we have scan list already, gelic_wl_start_scan()
2230 * returns OK and raises the complete. Thus,
2231 * it's ok to wait unconditionally here
2233 wait_for_completion(&wl->scan_done);
2235 pr_debug("%s: scan done\n", __func__);
2236 mutex_lock(&wl->scan_lock);
2237 if (wl->scan_stat != GELIC_WL_SCAN_STAT_GOT_LIST) {
2238 gelic_wl_send_iwap_event(wl, NULL);
2239 pr_info("%s: no scan list. association failed\n", __func__);
2240 goto scan_lock_out;
2243 /* find best matching bss */
2244 best_bss = gelic_wl_find_best_bss(wl);
2245 if (!best_bss) {
2246 gelic_wl_send_iwap_event(wl, NULL);
2247 pr_info("%s: no bss matched. association failed\n", __func__);
2248 goto scan_lock_out;
2251 /* ok, do association */
2252 ret = gelic_wl_associate_bss(wl, best_bss);
2253 if (ret)
2254 pr_info("%s: association failed %d\n", __func__, ret);
2255 scan_lock_out:
2256 mutex_unlock(&wl->scan_lock);
2257 out:
2258 mutex_unlock(&wl->assoc_stat_lock);
2261 * Interrupt handler
2262 * Called from the ethernet interrupt handler
2263 * Processes wireless specific virtual interrupts only
2265 void gelic_wl_interrupt(struct net_device *netdev, u64 status)
2267 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2269 if (status & GELIC_CARD_WLAN_COMMAND_COMPLETED) {
2270 pr_debug("%s:cmd complete\n", __func__);
2271 complete(&wl->cmd_done_intr);
2274 if (status & GELIC_CARD_WLAN_EVENT_RECEIVED) {
2275 pr_debug("%s:event received\n", __func__);
2276 queue_delayed_work(wl->event_queue, &wl->event_work, 0);
2281 * driver helpers
2283 static const iw_handler gelic_wl_wext_handler[] =
2285 IW_HANDLER(SIOCGIWNAME, gelic_wl_get_name),
2286 IW_HANDLER(SIOCGIWRANGE, gelic_wl_get_range),
2287 IW_HANDLER(SIOCSIWSCAN, gelic_wl_set_scan),
2288 IW_HANDLER(SIOCGIWSCAN, gelic_wl_get_scan),
2289 IW_HANDLER(SIOCSIWAUTH, gelic_wl_set_auth),
2290 IW_HANDLER(SIOCGIWAUTH, gelic_wl_get_auth),
2291 IW_HANDLER(SIOCSIWESSID, gelic_wl_set_essid),
2292 IW_HANDLER(SIOCGIWESSID, gelic_wl_get_essid),
2293 IW_HANDLER(SIOCSIWENCODE, gelic_wl_set_encode),
2294 IW_HANDLER(SIOCGIWENCODE, gelic_wl_get_encode),
2295 IW_HANDLER(SIOCSIWAP, gelic_wl_set_ap),
2296 IW_HANDLER(SIOCGIWAP, gelic_wl_get_ap),
2297 IW_HANDLER(SIOCSIWENCODEEXT, gelic_wl_set_encodeext),
2298 IW_HANDLER(SIOCGIWENCODEEXT, gelic_wl_get_encodeext),
2299 IW_HANDLER(SIOCSIWMODE, gelic_wl_set_mode),
2300 IW_HANDLER(SIOCGIWMODE, gelic_wl_get_mode),
2301 IW_HANDLER(SIOCGIWNICKN, gelic_wl_get_nick),
2304 static const struct iw_handler_def gelic_wl_wext_handler_def = {
2305 .num_standard = ARRAY_SIZE(gelic_wl_wext_handler),
2306 .standard = gelic_wl_wext_handler,
2307 .get_wireless_stats = gelic_wl_get_wireless_stats,
2310 static struct net_device * __devinit gelic_wl_alloc(struct gelic_card *card)
2312 struct net_device *netdev;
2313 struct gelic_port *port;
2314 struct gelic_wl_info *wl;
2315 unsigned int i;
2317 pr_debug("%s:start\n", __func__);
2318 netdev = alloc_etherdev(sizeof(struct gelic_port) +
2319 sizeof(struct gelic_wl_info));
2320 pr_debug("%s: netdev =%p card=%p\n", __func__, netdev, card);
2321 if (!netdev)
2322 return NULL;
2324 strcpy(netdev->name, "wlan%d");
2326 port = netdev_priv(netdev);
2327 port->netdev = netdev;
2328 port->card = card;
2329 port->type = GELIC_PORT_WIRELESS;
2331 wl = port_wl(port);
2332 pr_debug("%s: wl=%p port=%p\n", __func__, wl, port);
2334 /* allocate scan list */
2335 wl->networks = kzalloc(sizeof(struct gelic_wl_scan_info) *
2336 GELIC_WL_BSS_MAX_ENT, GFP_KERNEL);
2338 if (!wl->networks)
2339 goto fail_bss;
2341 wl->eurus_cmd_queue = create_singlethread_workqueue("gelic_cmd");
2342 if (!wl->eurus_cmd_queue)
2343 goto fail_cmd_workqueue;
2345 wl->event_queue = create_singlethread_workqueue("gelic_event");
2346 if (!wl->event_queue)
2347 goto fail_event_workqueue;
2349 INIT_LIST_HEAD(&wl->network_free_list);
2350 INIT_LIST_HEAD(&wl->network_list);
2351 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++)
2352 list_add_tail(&wl->networks[i].list,
2353 &wl->network_free_list);
2354 init_completion(&wl->cmd_done_intr);
2356 INIT_DELAYED_WORK(&wl->event_work, gelic_wl_event_worker);
2357 INIT_DELAYED_WORK(&wl->assoc_work, gelic_wl_assoc_worker);
2358 mutex_init(&wl->scan_lock);
2359 mutex_init(&wl->assoc_stat_lock);
2361 init_completion(&wl->scan_done);
2362 /* for the case that no scan request is issued and stop() is called */
2363 complete(&wl->scan_done);
2365 spin_lock_init(&wl->lock);
2367 wl->scan_age = 5*HZ; /* FIXME */
2369 /* buffer for receiving scanned list etc */
2370 BUILD_BUG_ON(PAGE_SIZE <
2371 sizeof(struct gelic_eurus_scan_info) *
2372 GELIC_EURUS_MAX_SCAN);
2373 pr_debug("%s:end\n", __func__);
2374 return netdev;
2376 fail_event_workqueue:
2377 destroy_workqueue(wl->eurus_cmd_queue);
2378 fail_cmd_workqueue:
2379 kfree(wl->networks);
2380 fail_bss:
2381 free_netdev(netdev);
2382 pr_debug("%s:end error\n", __func__);
2383 return NULL;
2387 static void gelic_wl_free(struct gelic_wl_info *wl)
2389 struct gelic_wl_scan_info *scan_info;
2390 unsigned int i;
2392 pr_debug("%s: <-\n", __func__);
2394 pr_debug("%s: destroy queues\n", __func__);
2395 destroy_workqueue(wl->eurus_cmd_queue);
2396 destroy_workqueue(wl->event_queue);
2398 scan_info = wl->networks;
2399 for (i = 0; i < GELIC_WL_BSS_MAX_ENT; i++, scan_info++)
2400 kfree(scan_info->hwinfo);
2401 kfree(wl->networks);
2403 free_netdev(port_to_netdev(wl_port(wl)));
2405 pr_debug("%s: ->\n", __func__);
2408 static int gelic_wl_try_associate(struct net_device *netdev)
2410 struct gelic_wl_info *wl = port_wl(netdev_priv(netdev));
2411 int ret = -1;
2412 unsigned int i;
2414 pr_debug("%s: <-\n", __func__);
2416 /* check constraits for start association */
2417 /* for no access restriction AP */
2418 if (wl->group_cipher_method == GELIC_WL_CIPHER_NONE) {
2419 if (test_bit(GELIC_WL_STAT_CONFIGURED,
2420 &wl->stat))
2421 goto do_associate;
2422 else {
2423 pr_debug("%s: no wep, not configured\n", __func__);
2424 return ret;
2428 /* for WEP, one of four keys should be set */
2429 if (wl->group_cipher_method == GELIC_WL_CIPHER_WEP) {
2430 /* one of keys set */
2431 for (i = 0; i < GELIC_WEP_KEYS; i++) {
2432 if (test_bit(i, &wl->key_enabled))
2433 goto do_associate;
2435 pr_debug("%s: WEP, but no key specified\n", __func__);
2436 return ret;
2439 /* for WPA[2], psk should be set */
2440 if ((wl->group_cipher_method == GELIC_WL_CIPHER_TKIP) ||
2441 (wl->group_cipher_method == GELIC_WL_CIPHER_AES)) {
2442 if (test_bit(GELIC_WL_STAT_WPA_PSK_SET,
2443 &wl->stat))
2444 goto do_associate;
2445 else {
2446 pr_debug("%s: AES/TKIP, but PSK not configured\n",
2447 __func__);
2448 return ret;
2452 do_associate:
2453 ret = schedule_delayed_work(&wl->assoc_work, 0);
2454 pr_debug("%s: start association work %d\n", __func__, ret);
2455 return ret;
2459 * netdev handlers
2461 static int gelic_wl_open(struct net_device *netdev)
2463 struct gelic_card *card = netdev_card(netdev);
2465 pr_debug("%s:->%p\n", __func__, netdev);
2467 gelic_card_up(card);
2469 /* try to associate */
2470 gelic_wl_try_associate(netdev);
2472 netif_start_queue(netdev);
2474 pr_debug("%s:<-\n", __func__);
2475 return 0;
2479 * reset state machine
2481 static int gelic_wl_reset_state(struct gelic_wl_info *wl)
2483 struct gelic_wl_scan_info *target;
2484 struct gelic_wl_scan_info *tmp;
2486 /* empty scan list */
2487 list_for_each_entry_safe(target, tmp, &wl->network_list, list) {
2488 list_move_tail(&target->list, &wl->network_free_list);
2490 wl->scan_stat = GELIC_WL_SCAN_STAT_INIT;
2492 /* clear configuration */
2493 wl->auth_method = GELIC_EURUS_AUTH_OPEN;
2494 wl->group_cipher_method = GELIC_WL_CIPHER_NONE;
2495 wl->pairwise_cipher_method = GELIC_WL_CIPHER_NONE;
2496 wl->wpa_level = GELIC_WL_WPA_LEVEL_NONE;
2498 wl->key_enabled = 0;
2499 wl->current_key = 0;
2501 wl->psk_type = GELIC_EURUS_WPA_PSK_PASSPHRASE;
2502 wl->psk_len = 0;
2504 wl->essid_len = 0;
2505 memset(wl->essid, 0, sizeof(wl->essid));
2506 memset(wl->bssid, 0, sizeof(wl->bssid));
2507 memset(wl->active_bssid, 0, sizeof(wl->active_bssid));
2509 wl->assoc_stat = GELIC_WL_ASSOC_STAT_DISCONN;
2511 memset(&wl->iwstat, 0, sizeof(wl->iwstat));
2512 /* all status bit clear */
2513 wl->stat = 0;
2514 return 0;
2518 * Tell eurus to terminate association
2520 static void gelic_wl_disconnect(struct net_device *netdev)
2522 struct gelic_port *port = netdev_priv(netdev);
2523 struct gelic_wl_info *wl = port_wl(port);
2524 struct gelic_eurus_cmd *cmd;
2527 * If scann process is running on chip,
2528 * further requests will be rejected
2530 if (wl->scan_stat == GELIC_WL_SCAN_STAT_SCANNING)
2531 wait_for_completion_timeout(&wl->scan_done, HZ);
2533 cmd = gelic_eurus_sync_cmd(wl, GELIC_EURUS_CMD_DISASSOC, NULL, 0);
2534 kfree(cmd);
2535 gelic_wl_send_iwap_event(wl, NULL);
2538 static int gelic_wl_stop(struct net_device *netdev)
2540 struct gelic_port *port = netdev_priv(netdev);
2541 struct gelic_wl_info *wl = port_wl(port);
2542 struct gelic_card *card = netdev_card(netdev);
2544 pr_debug("%s:<-\n", __func__);
2547 * Cancel pending association work.
2548 * event work can run after netdev down
2550 cancel_delayed_work(&wl->assoc_work);
2552 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2553 gelic_wl_disconnect(netdev);
2555 /* reset our state machine */
2556 gelic_wl_reset_state(wl);
2558 netif_stop_queue(netdev);
2560 gelic_card_down(card);
2562 pr_debug("%s:->\n", __func__);
2563 return 0;
2566 /* -- */
2568 static const struct net_device_ops gelic_wl_netdevice_ops = {
2569 .ndo_open = gelic_wl_open,
2570 .ndo_stop = gelic_wl_stop,
2571 .ndo_start_xmit = gelic_net_xmit,
2572 .ndo_set_multicast_list = gelic_net_set_multi,
2573 .ndo_change_mtu = gelic_net_change_mtu,
2574 .ndo_tx_timeout = gelic_net_tx_timeout,
2575 .ndo_set_mac_address = eth_mac_addr,
2576 .ndo_validate_addr = eth_validate_addr,
2577 #ifdef CONFIG_NET_POLL_CONTROLLER
2578 .ndo_poll_controller = gelic_net_poll_controller,
2579 #endif
2582 static const struct ethtool_ops gelic_wl_ethtool_ops = {
2583 .get_drvinfo = gelic_net_get_drvinfo,
2584 .get_link = gelic_wl_get_link,
2585 .get_tx_csum = ethtool_op_get_tx_csum,
2586 .set_tx_csum = ethtool_op_set_tx_csum,
2587 .get_rx_csum = gelic_net_get_rx_csum,
2588 .set_rx_csum = gelic_net_set_rx_csum,
2591 static void __devinit gelic_wl_setup_netdev_ops(struct net_device *netdev)
2593 struct gelic_wl_info *wl;
2594 wl = port_wl(netdev_priv(netdev));
2595 BUG_ON(!wl);
2596 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
2598 netdev->ethtool_ops = &gelic_wl_ethtool_ops;
2599 netdev->netdev_ops = &gelic_wl_netdevice_ops;
2600 netdev->wireless_data = &wl->wireless_data;
2601 netdev->wireless_handlers = &gelic_wl_wext_handler_def;
2605 * driver probe/remove
2607 int __devinit gelic_wl_driver_probe(struct gelic_card *card)
2609 int ret;
2610 struct net_device *netdev;
2612 pr_debug("%s:start\n", __func__);
2614 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2615 return 0;
2616 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2617 return 0;
2619 /* alloc netdevice for wireless */
2620 netdev = gelic_wl_alloc(card);
2621 if (!netdev)
2622 return -ENOMEM;
2624 /* setup net_device structure */
2625 SET_NETDEV_DEV(netdev, &card->dev->core);
2626 gelic_wl_setup_netdev_ops(netdev);
2628 /* setup some of net_device and register it */
2629 ret = gelic_net_setup_netdev(netdev, card);
2630 if (ret)
2631 goto fail_setup;
2632 card->netdev[GELIC_PORT_WIRELESS] = netdev;
2634 /* add enable wireless interrupt */
2635 card->irq_mask |= GELIC_CARD_WLAN_EVENT_RECEIVED |
2636 GELIC_CARD_WLAN_COMMAND_COMPLETED;
2637 /* to allow wireless commands while both interfaces are down */
2638 gelic_card_set_irq_mask(card, GELIC_CARD_WLAN_EVENT_RECEIVED |
2639 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2640 pr_debug("%s:end\n", __func__);
2641 return 0;
2643 fail_setup:
2644 gelic_wl_free(port_wl(netdev_port(netdev)));
2646 return ret;
2649 int gelic_wl_driver_remove(struct gelic_card *card)
2651 struct gelic_wl_info *wl;
2652 struct net_device *netdev;
2654 pr_debug("%s:start\n", __func__);
2656 if (ps3_compare_firmware_version(1, 6, 0) < 0)
2657 return 0;
2658 if (!card->vlan[GELIC_PORT_WIRELESS].tx)
2659 return 0;
2661 netdev = card->netdev[GELIC_PORT_WIRELESS];
2662 wl = port_wl(netdev_priv(netdev));
2664 /* if the interface was not up, but associated */
2665 if (wl->assoc_stat == GELIC_WL_ASSOC_STAT_ASSOCIATED)
2666 gelic_wl_disconnect(netdev);
2668 complete(&wl->cmd_done_intr);
2670 /* cancel all work queue */
2671 cancel_delayed_work(&wl->assoc_work);
2672 cancel_delayed_work(&wl->event_work);
2673 flush_workqueue(wl->eurus_cmd_queue);
2674 flush_workqueue(wl->event_queue);
2676 unregister_netdev(netdev);
2678 /* disable wireless interrupt */
2679 pr_debug("%s: disable intr\n", __func__);
2680 card->irq_mask &= ~(GELIC_CARD_WLAN_EVENT_RECEIVED |
2681 GELIC_CARD_WLAN_COMMAND_COMPLETED);
2682 /* free bss list, netdev*/
2683 gelic_wl_free(wl);
2684 pr_debug("%s:end\n", __func__);
2685 return 0;