22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
27 #include <linux/ethtool.h>
28 #include <linux/if_vlan.h>
32 #include <linux/tcp.h>
33 #include <linux/wireless.h>
35 #include <linux/if_arp.h>
36 #include <linux/ctype.h>
37 #include <linux/string.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);
59 static const int channel_freq[] = {
60 2412, 2417, 2422, 2427, 2432,
61 2437, 2442, 2447, 2452, 2457,
62 2462, 2467, 2472, 2484
64 #define NUM_CHANNELS ARRAY_SIZE(channel_freq)
67 static const int bitrate_list[] = {
81 #define NUM_BITRATES ARRAY_SIZE(bitrate_list)
86 static inline int wpa2_capable(
void)
91 static inline int precise_ie(
void)
128 return "SET_COMMON_CFG";
130 return "GET_COMMON_CFG";
132 return "SET_WEP_CFG";
134 return "GET_WEP_CFG";
136 return "SET_WPA_CFG";
138 return "GET_WPA_CFG";
180 cmd->
status = lv1_net_control(bus_id(card),
dev_id(card),
182 cmd->
cmd, arg1, arg2,
186 pr_info(
"%s: cmd issue failed\n", __func__);
200 cmd->
status = lv1_net_control(bus_id(card),
dev_id(card),
202 cmd->
tag, arg1, arg2,
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",
217 unsigned int eurus_cmd,
229 cmd->
cmd = eurus_cmd;
234 init_completion(&cmd->
done);
291 status = lv1_net_control(bus_id(card),
dev_id(card),
298 pr_info(
"%s: available ch unknown\n", __func__);
302 wl->
ch_info = ch_info_raw >> 48;
307 static int gelic_wl_get_range(
struct net_device *netdev,
324 gelic_wl_get_ch_info(wl);
329 range->
freq[chs].i = i + 1;
330 range->
freq[chs].m = channel_freq[
i];
331 range->
freq[chs].e = 6;
341 range->
bitrate[i] = bitrate_list[i];
377 static int gelic_wl_set_scan(
struct net_device *netdev,
391 pr_debug(
"%s: ESSID scan =%s\n", __func__, essid);
393 return gelic_wl_start_scan(wl, 1, essid, essid_len);
397 static const u8 rsn_oui[
OUI_LEN] = { 0x00, 0x0f, 0xac };
398 static const u8 wpa_oui[
OUI_LEN] = { 0x00, 0x50, 0xf2 };
405 static size_t gelic_wl_synthesize_ie(
u8 *
buf,
409 const u8 *oui_header;
437 pr_info(
"%s: no cipher info. defaulted to CCMP\n",
441 pr_info(
"%s: no cipher info. defaulted to TKIP\n",
447 oui_header = rsn_oui;
449 oui_header = wpa_oui;
506 start[1] = (buf - start - 2);
522 static void gelic_wl_parse_ie(
u8 *
data,
size_t len,
525 size_t data_left =
len;
530 pr_debug(
"%s: data=%p len=%ld\n", __func__,
532 memset(ie_info, 0,
sizeof(
struct ie_info));
534 while (2 <= data_left) {
539 if (data_left < item_len)
544 if ((
OUI_LEN + 1 <= item_len) &&
547 ie_info->
wpa.data = pos - 2;
548 ie_info->
wpa.len = item_len + 2;
552 ie_info->
rsn.data = pos - 2;
554 ie_info->
rsn.len = item_len + 2;
557 pr_debug(
"%s: ignore %#x,%d\n", __func__,
562 data_left -= item_len;
564 pr_debug(
"%s: wpa=%p,%d wpa2=%p,%d\n", __func__,
565 ie_info->
wpa.data, ie_info->
wpa.len,
566 ie_info->
rsn.data, ie_info->
rsn.len);
574 static char *gelic_wl_translate_scan(
struct net_device *netdev,
584 unsigned int i,
j, len;
597 iwe.u.data.flags = 1;
599 ev = iwe_stream_add_point(info, ev, stop, &iwe, scan->
essid);
610 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
612 tmp = ev + iwe_stream_lcp_len(info);
616 pr_debug(
"%s: rates=%d rate=%d\n", __func__,
618 while (i < network->rate_len) {
619 if (j < network->rate_ext_len &&
623 rate = scan->
rate[i++] & 0x7f;
624 iwe.u.bitrate.value = rate * 500000;
625 tmp = iwe_stream_add_value(info, ev, tmp, stop, &iwe,
628 while (j < network->rate_ext_len) {
629 iwe.u.bitrate.value = (scan->
ext_rate[j++] & 0x7f) * 500000;
630 tmp = iwe_stream_add_value(info, ev, tmp, stop, &iwe,
634 if (iwe_stream_lcp_len(info) < (tmp - ev))
643 iwe.u.data.length = 0;
644 ev = iwe_stream_add_point(info, ev, stop, &iwe, scan->
essid);
663 iwe.u.qual.noise = 0;
667 memset(&iwe, 0,
sizeof(iwe));
670 len = gelic_wl_synthesize_ie(buf, scan);
673 iwe.u.data.length = len;
674 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
678 struct ie_info ie_info;
683 gelic_wl_parse_ie(scan->
elements, data_len, &ie_info);
685 if (ie_info.
wpa.len && (ie_info.
wpa.len <=
sizeof(buf))) {
688 iwe.u.data.length = ie_info.
wpa.len;
689 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
692 if (ie_info.
rsn.len && (ie_info.
rsn.len <=
sizeof(buf))) {
693 memset(&iwe, 0,
sizeof(iwe));
696 iwe.u.data.length = ie_info.
rsn.len;
697 ev = iwe_stream_add_point(info, ev, stop, &iwe, buf);
706 static int gelic_wl_get_scan(
struct net_device *netdev,
713 char *stop = ev + wrqu->
data.length;
715 unsigned long this_time =
jiffies;
742 ev = gelic_wl_translate_scan(netdev, info,
746 pr_debug(
"%s:entry too old\n", __func__);
755 wrqu->
data.flags = 0;
758 pr_debug(
"%s: -> %d %d\n", __func__, ret, wrqu->
data.length);
770 pr_debug(
"%s: item %d\n", __func__, i++);
771 pr_debug(
"valid=%d eurusindex=%d last=%lx\n",
774 pr_debug(
"r_len=%d r_ext_len=%d essid_len=%d\n",
784 static int gelic_wl_set_auth(
struct net_device *netdev,
790 unsigned long irqflag;
798 pr_debug(
"%s: NO WPA selected\n", __func__);
804 pr_debug(
"%s: WPA version 1 selected\n", __func__);
821 pr_info(
"%s: WPA2 may not work\n", __func__);
822 if (wpa2_capable()) {
836 pr_debug(
"%s: WEP selected\n", __func__);
840 pr_debug(
"%s: TKIP selected\n", __func__);
844 pr_debug(
"%s: CCMP selected\n", __func__);
848 pr_debug(
"%s: no auth selected\n", __func__);
855 pr_debug(
"%s: WEP selected\n", __func__);
859 pr_debug(
"%s: TKIP selected\n", __func__);
863 pr_debug(
"%s: CCMP selected\n", __func__);
867 pr_debug(
"%s: no auth selected\n", __func__);
873 pr_debug(
"%s: shared key specified\n", __func__);
876 pr_debug(
"%s: open system specified\n", __func__);
884 pr_debug(
"%s: WPA enabled\n", __func__);
887 pr_debug(
"%s: WPA disabled\n", __func__);
904 spin_unlock_irqrestore(&wl->
lock, irqflag);
905 pr_debug(
"%s: -> %d\n", __func__, ret);
909 static int gelic_wl_get_auth(
struct net_device *netdev,
915 unsigned long irqflag;
956 spin_unlock_irqrestore(&wl->
lock, irqflag);
957 pr_debug(
"%s: -> %d\n", __func__, ret);
962 static int gelic_wl_set_essid(
struct net_device *netdev,
967 unsigned long irqflag;
969 pr_debug(
"%s: <- l=%d f=%d\n", __func__,
971 if (IW_ESSID_MAX_SIZE < data->essid.length)
975 if (data->
essid.flags) {
978 pr_debug(
"%s: essid = '%s'\n", __func__, extra);
981 pr_debug(
"%s: ESSID any\n", __func__);
985 spin_unlock_irqrestore(&wl->
lock, irqflag);
988 gelic_wl_try_associate(netdev);
993 static int gelic_wl_get_essid(
struct net_device *netdev,
998 unsigned long irqflag;
1007 data->
essid.flags = 1;
1009 data->
essid.flags = 0;
1012 spin_unlock_irqrestore(&wl->
lock, irqflag);
1019 static int gelic_wl_set_encode(
struct net_device *netdev,
1026 unsigned long irqflag;
1034 pr_debug(
"%s: key_index = %d\n", __func__, key_index);
1043 index_specified = 1;
1046 index_specified = 0;
1052 if (!flags && index_specified) {
1058 if (!index_specified) {
1072 pr_info(
"%s: shared key mode enabled\n", __func__);
1076 if (IW_ENCODING_TOKEN_MAX < enc->
length) {
1088 spin_unlock_irqrestore(&wl->
lock, irqflag);
1093 static int gelic_wl_get_encode(
struct net_device *netdev,
1099 unsigned long irqflag;
1100 unsigned int key_index, index_specified;
1105 pr_debug(
"%s: flag=%#x point=%p len=%d extra=%p\n", __func__,
1112 index_specified = 1;
1115 index_specified = 0;
1142 enc->
flags |= key_index + 1;
1143 pr_debug(
"%s: -> flag=%x len=%d\n", __func__,
1147 spin_unlock_irqrestore(&wl->
lock, irqflag);
1152 static int gelic_wl_set_ap(
struct net_device *netdev,
1157 unsigned long irqflag;
1164 if (is_valid_ether_addr(data->
ap_addr.sa_data)) {
1171 pr_debug(
"%s: clear bssid\n", __func__);
1175 spin_unlock_irqrestore(&wl->
lock, irqflag);
1180 static int gelic_wl_get_ap(
struct net_device *netdev,
1185 unsigned long irqflag;
1197 spin_unlock_irqrestore(&wl->
lock, irqflag);
1204 static int gelic_wl_set_encodeext(
struct net_device *netdev,
1213 unsigned long irqflag;
1222 pr_debug(
"%s: key_index = %d\n", __func__, key_index);
1239 pr_debug(
"%s: request to change default key to %d\n",
1240 __func__, key_index);
1246 pr_debug(
"%s: alg disabled\n", __func__);
1252 pr_debug(
"%s: WEP requested\n", __func__);
1253 if (flags & IW_ENCODE_OPEN) {
1254 pr_debug(
"%s: open key mode\n", __func__);
1258 pr_debug(
"%s: shared key mode\n", __func__);
1261 if (IW_ENCODING_TOKEN_MAX < ext->
key_len) {
1262 pr_info(
"%s: key is too long %d\n", __func__,
1276 pr_err(
"%s: PSK length wrong %d\n", __func__,
1289 spin_unlock_irqrestore(&wl->
lock, irqflag);
1294 static int gelic_wl_get_encodeext(
struct net_device *netdev,
1301 unsigned long irqflag;
1309 if (max_key_len < 0)
1313 pr_debug(
"%s: key_index = %d\n", __func__, key_index);
1347 if (!(enc->
flags & IW_ENCODE_NOKEY)) {
1348 if (max_key_len < wl->
key_len[key_index]) {
1356 pr_debug(
"%s: disabled key requested ix=%d\n",
1357 __func__, key_index);
1360 spin_unlock_irqrestore(&wl->
lock, irqflag);
1365 static int gelic_wl_set_mode(
struct net_device *netdev,
1377 pr_debug(
"%s: -> %d\n", __func__, ret);
1381 static int gelic_wl_get_mode(
struct net_device *netdev,
1393 static int gelic_wl_get_nick(
struct net_device *net_dev,
1397 strcpy(extra,
"gelic_wl");
1399 data->
data.flags = 1;
1423 memset(is, 0,
sizeof(*is));
1425 buf,
sizeof(*rssi));
1444 static int gelic_wl_start_scan(
struct gelic_wl_info *wl,
int always_scan,
1445 u8 *essid,
size_t essid_len)
1452 pr_debug(
"%s: <- always=%d\n", __func__, always_scan);
1460 pr_debug(
"%s: scanning now\n", __func__);
1469 if ((!essid_len && !always_scan)
1471 pr_debug(
"%s: already has the list\n", __func__);
1477 if (essid_len && essid) {
1485 memcpy(buf, essid, essid_len);
1486 pr_debug(
"%s: essid scan='%s'\n", __func__, (
char *)buf);
1514 static void gelic_wl_scan_complete_event(
struct gelic_wl_info *wl)
1520 unsigned int scan_info_size;
1522 unsigned long this_time =
jiffies;
1531 pr_info(
"%s: scan buffer alloc failed\n", __func__);
1539 pr_debug(
"%s: scan complete when stat != scanning(%d)\n",
1548 pr_info(
"%s:cmd failed\n", __func__);
1552 data_len = cmd->
size;
1553 pr_debug(
"%s: data_len = %d\n", __func__, data_len);
1572 for (i = 0, scan_info_size = 0, scan_info = buf;
1576 pr_debug(
"%s:size=%d bssid=%pM scan_info=%p\n", __func__,
1578 &scan_info->
bssid[2], scan_info);
1586 pr_debug(
"%s: invalid scan info\n", __func__);
1593 if (ether_addr_equal(&target->
hwinfo->bssid[2],
1594 &scan_info->
bssid[2])) {
1596 pr_debug(
"%s: same BBS found scanned list\n",
1630 sizeof(scan_info->
essid));
1632 for (r = 0; r < 12; r++)
1633 if (scan_info->
rate[r])
1636 pr_info(
"%s: AP returns %d rates\n", __func__,
1639 for (r = 0; r < 16; r++)
1644 memset(&data, 0,
sizeof(data));
1665 if (*best_weight < ++(*weight)) {
1685 pr_debug(
"%s: station %p\n", __func__, scan_info);
1687 if (!scan_info->
valid) {
1688 pr_debug(
"%s: station invalid\n", __func__);
1694 if (ether_addr_equal(&scan_info->
hwinfo->bssid[2],
1696 best_bss = scan_info;
1697 pr_debug(
"%s: bssid matched\n", __func__);
1700 pr_debug(
"%s: bssid unmached\n", __func__);
1712 update_best(&best_bss, scan_info,
1713 &best_weight, &weight);
1718 update_best(&best_bss, scan_info,
1719 &best_weight, &weight);
1725 update_best(&best_bss, scan_info,
1726 &best_weight, &weight);
1735 scan_info->
hwinfo->essid,
1737 update_best(&best_bss, scan_info,
1738 &best_weight, &weight);
1745 pr_debug(
"%s: -> bss=%p\n", __func__, best_bss);
1747 pr_debug(
"%s:addr=%pM\n", __func__,
1748 &best_bss->
hwinfo->bssid[2]);
1774 memset(wep, 0,
sizeof(*wep));
1777 pr_debug(
"%s: WEP mode\n", __func__);
1782 pr_debug(
"%s: key#%d enabled\n", __func__, i);
1786 else if (wl->
key_len[i] != 5) {
1787 pr_info(
"%s: wrong wep key[%d]=%d\n",
1796 pr_info(
"%s: all wep key disabled\n", __func__);
1802 pr_debug(
"%s: 104bit key\n", __func__);
1805 pr_debug(
"%s: 40bit key\n", __func__);
1809 pr_debug(
"%s: NO encryption\n", __func__);
1836 return "WPA_TKIP_TKIP";
1839 return "WPA_TKIP_AES";
1842 return "WPA_AES_AES";
1845 return "WPA2_TKIP_TKIP";
1848 return "WPA2_TKIP_AES";
1851 return "WPA2_AES_AES";
1871 memset(wpa, 0,
sizeof(*wpa));
1874 pr_info(
"%s: PSK not configured yet\n", __func__);
1906 pr_debug(
"%s: sec=%s psktype=%s\n", __func__,
1909 "BIN" :
"passphrase");
1930 pr_debug(
"%s: --> %d\n", __func__, ret);
1952 memset(common, 0,
sizeof(*common));
1969 pr_debug(
"%s: common cfg index=%d bsstype=%d auth=%d\n", __func__,
1975 common,
sizeof(*common));
1987 ret = gelic_wl_do_wep_setup(wl);
1991 ret = gelic_wl_do_wpa_setup(wl);
1996 pr_debug(
"%s: WEP/WPA setup failed %d\n", __func__,
1999 gelic_wl_send_iwap_event(wl,
NULL);
2009 pr_debug(
"%s: assoc request failed\n", __func__);
2013 gelic_wl_send_iwap_event(wl,
NULL);
2023 pr_info(
"%s: connect timeout\n", __func__);
2028 gelic_wl_send_iwap_event(wl,
NULL);
2037 pr_info(
"%s: connected\n", __func__);
2048 static void gelic_wl_connected_event(
struct gelic_wl_info *wl,
2051 u64 desired_event = 0;
2063 if (desired_event == event) {
2064 pr_debug(
"%s: completed\n", __func__);
2068 pr_debug(
"%s: event %#llx under wpa\n",
2075 static void gelic_wl_disconnect_event(
struct gelic_wl_info *wl,
2089 pr_debug(
"%s: already locked\n", __func__);
2092 pr_debug(
"%s: obtain lock\n", __func__);
2101 gelic_wl_send_iwap_event(wl,
NULL);
2115 static char buf[32];
2118 ret =
"EURUS_READY";
2120 ret =
"SCAN_COMPLETED";
2124 ret =
"BEACON_LOST";
2128 ret =
"WPA_CONNECTED";
2132 sprintf(buf,
"Unknown(%#x)", event);
2143 static void gelic_wl_event_worker(
struct work_struct *work)
2159 pr_debug(
"%s:wlan event failed %d\n",
2165 pr_debug(
"%s: event=%s\n", __func__, eventstr(event));
2167 case GELIC_LV1_WL_EVENT_SCAN_COMPLETED:
2168 gelic_wl_scan_complete_event(wl);
2170 case GELIC_LV1_WL_EVENT_BEACON_LOST:
2171 case GELIC_LV1_WL_EVENT_DEAUTH:
2172 gelic_wl_disconnect_event(wl, event);
2174 case GELIC_LV1_WL_EVENT_CONNECTED:
2175 case GELIC_LV1_WL_EVENT_WPA_CONNECTED:
2176 gelic_wl_connected_event(wl, event);
2186 static void gelic_wl_assoc_worker(
struct work_struct *work)
2192 unsigned long irqflag;
2205 pr_debug(
"%s: assoc ESSID configured %s\n", __func__,
2213 spin_unlock_irqrestore(&wl->
lock, irqflag);
2215 ret = gelic_wl_start_scan(wl, 0, essid, essid_len);
2217 pr_debug(
"%s: scan start failed association\n", __func__);
2221 pr_info(
"%s: scan prerequisite failed\n", __func__);
2233 pr_debug(
"%s: scan done\n", __func__);
2236 gelic_wl_send_iwap_event(wl,
NULL);
2237 pr_info(
"%s: no scan list. association failed\n", __func__);
2242 best_bss = gelic_wl_find_best_bss(wl);
2244 gelic_wl_send_iwap_event(wl,
NULL);
2245 pr_info(
"%s: no bss matched. association failed\n", __func__);
2250 ret = gelic_wl_associate_bss(wl, best_bss);
2252 pr_info(
"%s: association failed %d\n", __func__, ret);
2268 pr_debug(
"%s:cmd complete\n", __func__);
2273 pr_debug(
"%s:event received\n", __func__);
2281 static const iw_handler gelic_wl_wext_handler[] =
2303 .num_standard =
ARRAY_SIZE(gelic_wl_wext_handler),
2304 .standard = gelic_wl_wext_handler,
2305 .get_wireless_stats = gelic_wl_get_wireless_stats,
2316 netdev = alloc_etherdev(
sizeof(
struct gelic_port) +
2318 pr_debug(
"%s: netdev =%p card=%p\n", __func__, netdev, card);
2324 port = netdev_priv(netdev);
2330 pr_debug(
"%s: wl=%p port=%p\n", __func__, wl, port);
2341 goto fail_cmd_workqueue;
2345 goto fail_event_workqueue;
2374 fail_event_workqueue:
2380 pr_debug(
"%s:end error\n", __func__);
2392 pr_debug(
"%s: destroy queues\n", __func__);
2406 static int gelic_wl_try_associate(
struct net_device *netdev)
2421 pr_debug(
"%s: no wep, not configured\n", __func__);
2433 pr_debug(
"%s: WEP, but no key specified\n", __func__);
2444 pr_debug(
"%s: AES/TKIP, but PSK not configured\n",
2452 pr_debug(
"%s: start association work %d\n", __func__, ret);
2459 static int gelic_wl_open(
struct net_device *netdev)
2461 struct gelic_card *card = netdev_card(netdev);
2463 pr_debug(
"%s:->%p\n", __func__, netdev);
2468 gelic_wl_try_associate(netdev);
2470 netif_start_queue(netdev);
2518 static void gelic_wl_disconnect(
struct net_device *netdev)
2520 struct gelic_port *port = netdev_priv(netdev);
2533 gelic_wl_send_iwap_event(wl,
NULL);
2536 static int gelic_wl_stop(
struct net_device *netdev)
2538 struct gelic_port *port = netdev_priv(netdev);
2540 struct gelic_card *card = netdev_card(netdev);
2551 gelic_wl_disconnect(netdev);
2554 gelic_wl_reset_state(wl);
2556 netif_stop_queue(netdev);
2567 .ndo_open = gelic_wl_open,
2568 .ndo_stop = gelic_wl_stop,
2575 #ifdef CONFIG_NET_POLL_CONTROLLER
2580 static const struct ethtool_ops gelic_wl_ethtool_ops = {
2582 .get_link = gelic_wl_get_link,
2588 wl = port_wl(netdev_priv(netdev));
2593 netdev->
netdev_ops = &gelic_wl_netdevice_ops;
2595 netdev->wireless_handlers = &gelic_wl_wext_handler_def;
2614 netdev = gelic_wl_alloc(card);
2620 gelic_wl_setup_netdev_ops(netdev);
2638 gelic_wl_free(port_wl(netdev_port(netdev)));
2656 wl = port_wl(netdev_priv(netdev));
2660 gelic_wl_disconnect(netdev);
2673 pr_debug(
"%s: disable intr\n", __func__);