1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifdef MODVERSIONS
28#include <linux/modversions.h>
29#endif
30
31#include <linux/module.h>
32#include <linux/usb.h>
33
34#include "usbdrv.h"
35#include "zdusb.h"
36
37int zfLnxAllocAllUrbs(struct usbdrv_private *macp);
38void zfLnxFreeAllUrbs(struct usbdrv_private *macp);
39void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp);
40
41MODULE_AUTHOR("Atheros Communications");
42MODULE_DESCRIPTION("Atheros 802.11n Wireless LAN adapter");
43MODULE_LICENSE("Dual BSD/GPL");
44
45static const char driver_name[] = "Otus";
46
47
48static struct usb_device_id zd1221_ids [] = {
49 { USB_DEVICE(VENDOR_ATHR, PRODUCT_AR9170) },
50 { USB_DEVICE(VENDOR_DLINK, PRODUCT_DWA160A) },
51 { USB_DEVICE(VENDOR_NETGEAR, PRODUCT_WNDA3100) },
52 { USB_DEVICE(VENDOR_NETGEAR, PRODUCT_WN111v2) },
53 { }
54};
55
56MODULE_DEVICE_TABLE(usb, zd1221_ids);
57
58extern u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp);
59extern int usbdrv_close(struct net_device *dev);
60extern u8_t zfLnxClearStructs(struct net_device *dev);
61extern int zfWdsClose(struct net_device *dev);
62extern int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
63extern int zfLnxVapClose(struct net_device *dev);
64extern int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId);
65
66
67extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
68
69
70extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
71
72static int zfLnxProbe(struct usb_interface *interface,
73 const struct usb_device_id *id)
74{
75 struct usb_device *dev = interface_to_usbdev(interface);
76
77 struct net_device *net = NULL;
78 struct usbdrv_private *macp = NULL;
79 int vendor_id, product_id;
80 int result = 0;
81
82 usb_get_dev(dev);
83
84 vendor_id = dev->descriptor.idVendor;
85 product_id = dev->descriptor.idProduct;
86
87#ifdef HMAC_DEBUG
88 printk(KERN_NOTICE "vendor_id = %04x\n", vendor_id);
89 printk(KERN_NOTICE "product_id = %04x\n", product_id);
90
91 if (dev->speed == USB_SPEED_HIGH)
92 printk(KERN_NOTICE "USB 2.0 Host\n");
93 else
94 printk(KERN_NOTICE "USB 1.1 Host\n");
95#endif
96
97 if (!(macp = kmalloc(sizeof(struct usbdrv_private), GFP_KERNEL)))
98 {
99 printk(KERN_ERR "out of memory allocating device structure\n");
100 result = -ENOMEM;
101 goto fail;
102 }
103
104
105 memset(macp, 0, sizeof(struct usbdrv_private));
106
107 net = alloc_etherdev(0);
108
109 if (net == NULL)
110 {
111 printk(KERN_ERR "zfLnxProbe: Not able to alloc etherdev struct\n");
112 result = -ENOMEM;
113 goto fail1;
114 }
115
116 strcpy(net->name, "ath%d");
117
118 net->ml_priv = macp;
119 macp->udev = dev;
120 macp->device = net;
121
122
123
124 macp->interface = interface;
125
126
127
128
129
130 if (!zfLnxAllocAllUrbs(macp))
131 {
132 result = -ENOMEM;
133 goto fail2;
134 }
135
136 if (!zfLnxInitSetup(net, macp))
137 {
138 result = -EIO;
139 goto fail3;
140 }
141 else
142 {
143 usb_set_intfdata(interface, macp);
144 SET_NETDEV_DEV(net, &interface->dev);
145
146 if (register_netdev(net) != 0)
147 {
148 usb_set_intfdata(interface, NULL);
149 goto fail3;
150 }
151 }
152
153 netif_carrier_off(net);
154 goto done;
155
156fail3:
157 zfLnxFreeAllUrbs(macp);
158fail2:
159 free_netdev(net);
160fail1:
161 kfree(macp);
162
163fail:
164 usb_put_dev(dev);
165 macp = NULL;
166
167done:
168 return result;
169}
170
171static void zfLnxDisconnect(struct usb_interface *interface)
172{
173 struct usbdrv_private *macp = (struct usbdrv_private *) usb_get_intfdata(interface);
174
175 printk(KERN_DEBUG "zfLnxDisconnect\n");
176
177 if (!macp)
178 {
179 printk(KERN_ERR "unregistering non-existant device\n");
180 return;
181 }
182
183 if (macp->driver_isolated)
184 {
185 if (macp->device->flags & IFF_UP)
186 usbdrv_close(macp->device);
187 }
188
189#if 0
190
191
192
193
194
195
196 zfLnxVapClose(vap[0].dev);
197
198 zfLnxUnregisterVapDev(macp->device, 0);
199#endif
200
201 zfLnxClearStructs(macp->device);
202
203 unregister_netdev(macp->device);
204
205 usb_put_dev(interface_to_usbdev(interface));
206
207
208
209
210
211 free_netdev(macp->device);
212
213 zfLnxFreeAllUrbs(macp);
214
215 kfree(macp);
216 macp = NULL;
217
218 usb_set_intfdata(interface, NULL);
219}
220
221static struct usb_driver zd1221_driver = {
222 .name = driver_name,
223 .probe = zfLnxProbe,
224 .disconnect = zfLnxDisconnect,
225 .id_table = zd1221_ids,
226};
227
228int __init zfLnxIinit(void)
229{
230 printk(KERN_NOTICE "%s - version %s\n", DRIVER_NAME, VERSIONID);
231 return usb_register(&zd1221_driver);
232}
233
234void __exit zfLnxExit(void)
235{
236 usb_deregister(&zd1221_driver);
237}
238
239module_init(zfLnxIinit);
240module_exit(zfLnxExit);
241