15 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/netdevice.h>
20 #include <linux/wireless.h>
23 #include <linux/string.h>
24 #include <linux/if_arp.h>
29 {USB_DEVICE(0x0586, 0x3400)},
30 {USB_DEVICE(0x0ace, 0x1201)},
31 {USB_DEVICE(0x050d, 0x6051)},
32 {USB_DEVICE(0x0db0, 0x6823)},
33 {USB_DEVICE(0x1044, 0x8004)},
34 {USB_DEVICE(0x1044, 0x8005)},
40 #define ZD1201_VERSION "0.15"
51 static int zd1201_fw_upload(
struct usb_device *
dev,
int apfw)
62 fwfile =
"zd1201-ap.fw";
68 dev_err(&dev->dev,
"Failed to load %s firmware file!\n", fwfile);
69 dev_err(&dev->dev,
"Make sure the hotplug firmware loader is installed.\n");
70 dev_err(&dev->dev,
"Goto http://linux-lc100020.sourceforge.net for more info.\n");
74 data = fw_entry->
data;
82 int translen = (len > 1024) ? 1024 : len;
83 memcpy(buf, data, translen);
120 static void zd1201_usbfree(
struct urb *
urb)
122 struct zd1201 *zd = urb->context;
124 switch(urb->status) {
133 zd->
dev->name, urb->status);
136 kfree(urb->transfer_buffer);
150 static int zd1201_docmd(
struct zd1201 *zd,
int cmd,
int parm0,
151 int parm1,
int parm2)
172 usb_fill_bulk_urb(urb, zd->
usb, usb_sndbulkpipe(zd->
usb, zd->
endp_out2),
173 command, 16, zd1201_usbfree, zd);
184 static void zd1201_usbtx(
struct urb *urb)
186 struct zd1201 *zd = urb->context;
187 netif_wake_queue(zd->
dev);
191 static void zd1201_usbrx(
struct urb *urb)
193 struct zd1201 *zd = urb->context;
195 unsigned char *data = urb->transfer_buffer;
202 switch(urb->status) {
211 zd->
dev->name, urb->status);
216 if (urb->status != 0 || urb->actual_length == 0)
222 zd->
rxlen = urb->actual_length;
229 unsigned short infotype, framelen, copylen;
293 while (i < urb->actual_length) {
299 zd->
rxlen += copylen;
302 if (i >= urb->actual_length) {
310 int datalen = urb->actual_length-1;
311 unsigned short len,
fc,
seq;
323 if (!(skb = dev_alloc_skb(datalen+24)))
334 zd->
dev->stats.rx_packets++;
335 zd->
dev->stats.rx_bytes += skb->
len;
347 if ((seq & IEEE80211_SCTL_FRAG) == 0) {
366 if (frag->seq == (seq&IEEE80211_SCTL_SEQ))
374 if (fc & IEEE80211_FCTL_MOREFRAGS)
376 hlist_del_init(&frag->
fnode);
381 skb = dev_alloc_skb(len + 14 + 2);
390 zd->
dev->stats.rx_packets++;
391 zd->
dev->stats.rx_bytes += skb->len;
407 kfree(urb->transfer_buffer);
411 static int zd1201_getconfig(
struct zd1201 *zd,
int rid,
void *riddata,
412 unsigned int riddatalen)
419 unsigned char *
pdata;
433 if (length > zd->
rxlen)
434 length = zd->
rxlen-6;
441 if (riddatalen != (length - 4)) {
442 dev_dbg(&zd->
usb->dev,
"riddatalen mismatches, expected=%u, (packet=%u) length=%u, rid=0x%04X, rid_fid=0x%04X\n",
443 riddatalen, zd->
rxlen, length, rid, rid_fid);
459 dev_dbg(&zd->
usb->dev,
"Packet type mismatch: 0x%x not 0x3\n",
471 actual_length = (length > 64) ? 64 : length;
473 if (pdata[0] != 0x3) {
474 dev_dbg(&zd->
usb->dev,
"Rx Resource packet type error: %02X\n",
479 if (actual_length != 64) {
493 memcpy(riddata, pdata, actual_length);
494 riddata += actual_length;
495 pdata += actual_length;
498 }
while (length > 0);
511 static int zd1201_setconfig(
struct zd1201 *zd,
int rid,
void *buf,
int len,
int wait)
524 for (seq=0; len > 0; seq++) {
525 request =
kmalloc(16, gfp_mask);
534 reqlen = len>12 ? 12 : len;
539 if (request[1] == 0) {
543 memcpy(request+8, buf, reqlen-4);
546 memcpy(request+4, buf, reqlen);
552 usb_fill_bulk_urb(urb, zd->
usb, usb_sndbulkpipe(zd->
usb,
553 zd->
endp_out2), request, 16, zd1201_usbfree, zd);
559 request =
kmalloc(16, gfp_mask);
573 usb_fill_bulk_urb(urb, zd->
usb, usb_sndbulkpipe(zd->
usb, zd->
endp_out2),
574 request, 16, zd1201_usbfree, zd);
582 dev_dbg(&zd->
usb->dev,
"wrong or no RID received\n");
593 static inline int zd1201_getconfig16(
struct zd1201 *zd,
int rid,
short *
val)
598 err = zd1201_getconfig(zd, rid, &zdval,
sizeof(
__le16));
605 static inline int zd1201_setconfig16(
struct zd1201 *zd,
int rid,
short val)
608 return (zd1201_setconfig(zd, rid, &zdval,
sizeof(
__le16), 1));
611 static int zd1201_drvr_start(
struct zd1201 *zd)
640 for (i=0; i<
max; i++) {
661 static int zd1201_enable(
struct zd1201 *zd)
678 static int zd1201_disable(
struct zd1201 *zd)
696 static int zd1201_mac_reset(
struct zd1201 *zd)
701 return zd1201_enable(zd);
704 static int zd1201_join(
struct zd1201 *zd,
char *essid,
int essidlen)
709 err = zd1201_disable(zd);
720 memcpy(buf+2, essid, essidlen);
734 zd->
dev->dev_addr, zd->
dev->addr_len, 1);
738 err = zd1201_enable(zd);
746 static int zd1201_net_open(
struct net_device *dev)
748 struct zd1201 *zd = netdev_priv(dev);
753 netif_start_queue(dev);
758 static int zd1201_net_stop(
struct net_device *dev)
760 netif_stop_queue(dev);
787 struct zd1201 *zd = netdev_priv(dev);
788 unsigned char *txbuf = zd->
txdata;
789 int txbuflen,
pad = 0,
err;
790 struct urb *urb = zd->
tx_urb;
793 dev->
stats.tx_dropped++;
797 netif_stop_queue(dev);
799 txbuflen = skb->
len + 8 + 1;
800 if (txbuflen%64 == 0) {
811 skb_copy_from_linear_data_offset(skb, 12, txbuf + 6, skb->
len - 12);
813 txbuf[skb->
len-12+6]=0;
814 skb_copy_from_linear_data(skb, txbuf + skb->
len - 12 + 6 + pad, 12);
816 txbuf[txbuflen-1] = 0;
818 usb_fill_bulk_urb(urb, zd->
usb, usb_sndbulkpipe(zd->
usb, zd->
endp_out),
819 txbuf, txbuflen, zd1201_usbtx, zd);
823 dev->
stats.tx_errors++;
824 netif_start_queue(dev);
826 dev->
stats.tx_packets++;
834 static void zd1201_tx_timeout(
struct net_device *dev)
836 struct zd1201 *zd = netdev_priv(dev);
840 dev_warn(&zd->
usb->dev,
"%s: TX timeout, shooting down urb\n",
843 dev->
stats.tx_errors++;
848 static int zd1201_set_mac_address(
struct net_device *dev,
void *
p)
851 struct zd1201 *zd = netdev_priv(dev);
863 return zd1201_mac_reset(zd);
868 struct zd1201 *zd = netdev_priv(dev);
873 static void zd1201_set_multicast(
struct net_device *dev)
875 struct zd1201 *zd = netdev_priv(dev);
893 struct zd1201 *zd = netdev_priv(dev);
895 return zd1201_mac_reset(zd);
898 static int zd1201_get_name(
struct net_device *dev,
901 strcpy(name,
"IEEE 802.11b");
905 static int zd1201_set_freq(
struct net_device *dev,
908 struct zd1201 *zd = netdev_priv(dev);
915 channel = ieee80211_freq_to_dsss_chan(freq->
m);
924 zd1201_mac_reset(zd);
929 static int zd1201_get_freq(
struct net_device *dev,
932 struct zd1201 *zd = netdev_priv(dev);
945 static int zd1201_set_mode(
struct net_device *dev,
948 struct zd1201 *zd = netdev_priv(dev);
971 zd1201_join(zd,
"\0-*#\0", 5);
1002 zd1201_mac_reset(zd);
1007 static int zd1201_get_mode(
struct net_device *dev,
1010 struct zd1201 *zd = netdev_priv(dev);
1034 dev_dbg(&zd->
usb->dev,
"Unknown porttype: %d\n",
1044 static int zd1201_get_range(
struct net_device *dev,
1083 static int zd1201_get_wap(
struct net_device *dev,
1086 struct zd1201 *zd = netdev_priv(dev);
1087 unsigned char buffer[6];
1104 static int zd1201_set_scan(
struct net_device *dev,
1111 static int zd1201_get_scan(
struct net_device *dev,
1114 struct zd1201 *zd = netdev_priv(dev);
1115 int err,
i,
j, enabled_save;
1141 for(i=8; i<zd->
rxlen; i+=62) {
1145 cev = iwe_stream_add_event(info, cev, end_buf,
1149 iwe.u.data.length = zd->
rxdata[i+16];
1150 iwe.u.data.flags = 1;
1151 cev = iwe_stream_add_point(info, cev, end_buf,
1155 if (zd->
rxdata[i+14]&0x01)
1159 cev = iwe_stream_add_event(info, cev, end_buf,
1163 iwe.u.freq.m = zd->
rxdata[i+0];
1165 cev = iwe_stream_add_event(info, cev, end_buf,
1169 iwe.u.bitrate.fixed = 0;
1170 iwe.u.bitrate.disabled = 0;
1171 for (j=0; j<10; j++)
if (zd->
rxdata[i+50+j]) {
1172 iwe.u.bitrate.value = (zd->
rxdata[i+50+
j]&0x7f)*500000;
1173 cev = iwe_stream_add_event(info, cev, end_buf,
1178 iwe.u.data.length = 0;
1179 if (zd->
rxdata[i+14]&0x10)
1183 cev = iwe_stream_add_point(info, cev, end_buf, &iwe,
NULL);
1186 iwe.u.qual.qual = zd->
rxdata[i+4];
1187 iwe.u.qual.noise= zd->
rxdata[i+2]/10-100;
1188 iwe.u.qual.level = (256+zd->
rxdata[i+4]*100)/255-100;
1189 iwe.u.qual.updated = 7;
1190 cev = iwe_stream_add_event(info, cev, end_buf,
1203 static int zd1201_set_essid(
struct net_device *dev,
1206 struct zd1201 *zd = netdev_priv(dev);
1218 static int zd1201_get_essid(
struct net_device *dev,
1221 struct zd1201 *zd = netdev_priv(dev);
1239 static int zd1201_set_rate(
struct net_device *dev,
1242 struct zd1201 *zd = netdev_priv(dev);
1246 switch (rrq->
value) {
1269 return zd1201_mac_reset(zd);
1272 static int zd1201_get_rate(
struct net_device *dev,
1275 struct zd1201 *zd = netdev_priv(dev);
1285 rrq->
value = 1000000;
1288 rrq->
value = 2000000;
1291 rrq->
value = 5500000;
1294 rrq->
value = 11000000;
1308 struct zd1201 *zd = netdev_priv(dev);
1310 short val = rts->
value;
1322 return zd1201_mac_reset(zd);
1328 struct zd1201 *zd = netdev_priv(dev);
1343 struct iw_param *frag,
char *extra)
1345 struct zd1201 *zd = netdev_priv(dev);
1347 short val = frag->
value;
1360 return zd1201_mac_reset(zd);
1364 struct iw_param *frag,
char *extra)
1366 struct zd1201 *zd = netdev_priv(dev);
1373 frag->
value = fragt;
1380 static int zd1201_set_retry(
struct net_device *dev,
1386 static int zd1201_get_retry(
struct net_device *dev,
1392 static int zd1201_set_encode(
struct net_device *dev,
1395 struct zd1201 *zd = netdev_priv(dev);
1417 err = zd1201_setconfig(zd, rid, key, erq->
length, 1);
1446 return zd1201_mac_reset(zd);
1449 static int zd1201_get_encode(
struct net_device *dev,
1452 struct zd1201 *zd = netdev_priv(dev);
1482 static int zd1201_set_power(
struct net_device *dev,
1485 struct zd1201 *zd = netdev_priv(dev);
1492 duration = vwrq->
value;
1493 err = zd1201_setconfig16(zd,
1500 err = zd1201_getconfig16(zd,
1521 static int zd1201_get_power(
struct net_device *dev,
1524 struct zd1201 *zd = netdev_priv(dev);
1543 vwrq->
value = duration * level / 4;
1548 if (enabled && level)
1558 static const iw_handler zd1201_iw_handler[] =
1611 struct zd1201 *zd = netdev_priv(dev);
1619 static int zd1201_get_hostauth(
struct net_device *dev,
1622 struct zd1201 *zd = netdev_priv(dev);
1632 rrq->
value = hostauth;
1638 static int zd1201_auth_sta(
struct net_device *dev,
1641 struct zd1201 *zd = netdev_priv(dev);
1642 unsigned char buffer[10];
1648 *(
short*)(buffer+6) = 0;
1649 *(
short*)(buffer+8) = 0;
1654 static int zd1201_set_maxassoc(
struct net_device *dev,
1657 struct zd1201 *zd = netdev_priv(dev);
1669 static int zd1201_get_maxassoc(
struct net_device *dev,
1672 struct zd1201 *zd = netdev_priv(dev);
1682 rrq->
value = maxassoc;
1688 static const iw_handler zd1201_private_handler[] = {
1711 .num_standard =
ARRAY_SIZE(zd1201_iw_handler),
1712 .num_private =
ARRAY_SIZE(zd1201_private_handler),
1713 .num_private_args =
ARRAY_SIZE(zd1201_private_args),
1715 .
private = (
iw_handler *)zd1201_private_handler,
1716 .private_args = (
struct iw_priv_args *) zd1201_private_args,
1721 .ndo_open = zd1201_net_open,
1722 .ndo_stop = zd1201_net_stop,
1723 .ndo_start_xmit = zd1201_hard_start_xmit,
1724 .ndo_tx_timeout = zd1201_tx_timeout,
1725 .ndo_set_rx_mode = zd1201_set_multicast,
1726 .ndo_set_mac_address = zd1201_set_mac_address,
1736 struct usb_device *
usb;
1741 usb = interface_to_usbdev(interface);
1743 dev = alloc_etherdev(
sizeof(*zd));
1746 zd = netdev_priv(dev);
1755 err = zd1201_fw_upload(usb, zd->
ap);
1757 dev_err(&usb->dev,
"zd1201 firmware upload failed: %d\n", err);
1770 err = zd1201_drvr_start(zd);
1784 dev->wireless_handlers = &zd1201_iw_handlers;
1813 dev_info(&usb->dev,
"%s: ZD1201 USB Wireless interface\n",
1816 usb_set_intfdata(interface, zd);
1831 static void zd1201_disconnect(
struct usb_interface *interface)
1833 struct zd1201 *zd = usb_get_intfdata(interface);
1839 usb_set_intfdata(interface, NULL);
1842 hlist_del_init(&frag->
fnode);
1867 struct zd1201 *zd = usb_get_intfdata(interface);
1874 return zd1201_disable(zd);
1881 struct zd1201 *zd = usb_get_intfdata(interface);
1883 if (!zd || !zd->
dev)
1889 return zd1201_enable(zd);
1896 #define zd1201_suspend NULL
1897 #define zd1201_resume NULL
1901 static struct usb_driver zd1201_usb = {
1903 .probe = zd1201_probe,
1904 .disconnect = zd1201_disconnect,
1905 .id_table = zd1201_table,
1908 .disable_hub_initiated_lpm = 1,