2f9d06e3dd2428fec995cb7b7a16f6f003b8344f
[safe/jmp/linux-2.6] / drivers / staging / otus / usbdrv.c
1 /*
2  * Copyright (c) 2007-2008 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 /*  Module Name : usbdrv.c                                              */
17 /*                                                                      */
18 /*  Abstract                                                            */
19 /*     This module contains network interface up/down related functions.*/
20 /*                                                                      */
21 /*  NOTES                                                               */
22 /*     Platform dependent.                                              */
23 /*                                                                      */
24 /************************************************************************/
25
26 /* src/usbdrv.c */
27
28 #define ZM_PIBSS_MODE   0
29 #define ZM_AP_MODE      0
30 #define ZM_CHANNEL      11
31 #define ZM_WEP_MOME     0
32 #define ZM_SHARE_AUTH   0
33 #define ZM_DISABLE_XMIT 0
34
35 #include "usbdrv.h"
36 #include "oal_dt.h"
37 #include "80211core/pub_zfi.h"
38
39 #include "linux/netlink.h"
40 #include "linux/rtnetlink.h"
41
42 #if WIRELESS_EXT > 12
43 #include <net/iw_handler.h>
44 #endif
45
46 #ifdef ZM_HOSTAPD_SUPPORT
47 #include "athr_common.h"
48 #endif
49
50 extern void zfDumpDescriptor(zdev_t* dev, u16_t type);
51 //extern void zfiWlanQueryMacAddress(zdev_t* dev, u8_t* addr);
52
53 // ISR handler
54 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
55 irqreturn_t usbdrv_intr(int, void *, struct pt_regs *);
56 #else
57 void usbdrv_intr(int, void *, struct pt_regs *);
58 #endif
59
60 // Network Device interface related function
61 int usbdrv_open(struct net_device *);
62 int usbdrv_close(struct net_device *);
63 int usbdrv_change_mtu(struct net_device *, int);
64 int usbdrv_set_mac(struct net_device *, void *);
65 int usbdrv_xmit_frame(struct sk_buff *, struct net_device *);
66 void usbdrv_set_multi(struct net_device *);
67 struct net_device_stats *usbdrv_get_stats(struct net_device *);
68
69 //wireless extension helper functions
70 int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
71 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq);
72 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
73 /* Wireless Extension Handler functions */
74 int usbdrvwext_giwmode(struct net_device *dev, struct iw_request_info* info,
75         __u32 *mode, char *extra);
76 int zfLnxPrivateIoctl(struct usbdrv_private *macp, struct zdap_ioctl *zdreq);
77
78 void zfLnx10msTimer(struct net_device* dev);
79 int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
80 int zfRegisterWdsDev(struct net_device* parentDev, u16_t wdsId);
81 int zfWdsOpen(struct net_device *dev);
82 int zfWdsClose(struct net_device *dev);
83 int zfLnxVapOpen(struct net_device *dev);
84 int zfLnxVapClose(struct net_device *dev);
85 int zfLnxVapXmitFrame(struct sk_buff *skb, struct net_device *dev);
86 int zfLnxRegisterVapDev(struct net_device* parentDev, u16_t vapId);
87 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm);
88 extern u16_t zfLnxGetVapId(zdev_t* dev);
89 extern u16_t zfLnxCheckTxBufferCnt(zdev_t *dev);
90 extern UsbTxQ_t *zfLnxGetUsbTxBuffer(zdev_t *dev);
91
92 extern u16_t zfLnxAuthNotify(zdev_t* dev, u16_t* macAddr);
93 extern u16_t zfLnxAsocNotify(zdev_t* dev, u16_t* macAddr, u8_t* body, u16_t bodySize, u16_t port);
94 extern u16_t zfLnxDisAsocNotify(zdev_t* dev, u8_t* macAddr, u16_t port);
95 extern u16_t zfLnxApConnectNotify(zdev_t* dev, u8_t* macAddr, u16_t port);
96 extern void zfLnxConnectNotify(zdev_t* dev, u16_t status, u16_t* bssid);
97 extern void zfLnxScanNotify(zdev_t* dev, struct zsScanResult* result);
98 extern void zfLnxStatisticsNotify(zdev_t* dev, struct zsStastics* result);
99 extern void zfLnxMicFailureNotify(zdev_t* dev, u16_t* addr, u16_t status);
100 extern void zfLnxApMicFailureNotify(zdev_t* dev, u8_t* addr, zbuf_t* buf);
101 extern void zfLnxIbssPartnerNotify(zdev_t* dev, u16_t status, struct zsPartnerNotifyEvent *event);
102 extern void zfLnxMacAddressNotify(zdev_t* dev, u8_t* addr);
103 extern void zfLnxSendCompleteIndication(zdev_t* dev, zbuf_t* buf);
104 extern void zfLnxRecvEth(zdev_t* dev, zbuf_t* buf, u16_t port);
105 extern void zfLnxRestoreBufData(zdev_t* dev, zbuf_t* buf);
106 #ifdef ZM_ENABLE_CENC
107 extern u16_t zfLnxCencAsocNotify(zdev_t* dev, u16_t* macAddr, u8_t* body, u16_t bodySize, u16_t port);
108 #endif //ZM_ENABLE_CENC
109 extern void zfLnxWatchDogNotify(zdev_t* dev);
110 extern void zfLnxRecv80211(zdev_t* dev, zbuf_t* buf, struct zsAdditionInfo* addInfo);
111 extern u8_t zfLnxCreateThread(zdev_t *dev);
112
113 /******************************************************************************
114 *                        P U B L I C   D A T A
115 *******************************************************************************
116 */
117
118 /* Definition of Wireless Extension */
119
120 #if WIRELESS_EXT > 12
121 #include <net/iw_handler.h>
122 #endif
123 //wireless extension helper functions
124 extern int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
125 extern int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
126 /* Wireless Extension Handler functions */
127 extern int usbdrvwext_giwname(struct net_device *dev, struct iw_request_info *info,
128         union iwreq_data *wrq, char *extra);
129 extern int usbdrvwext_siwfreq(struct net_device *dev, struct iw_request_info *info,
130         struct iw_freq *freq, char *extra);
131 extern int usbdrvwext_giwfreq(struct net_device *dev, struct iw_request_info *info,
132         struct iw_freq *freq, char *extra);
133 extern int usbdrvwext_siwmode(struct net_device *dev, struct iw_request_info *info,
134         union iwreq_data *wrq, char *extra);
135 extern int usbdrvwext_giwmode(struct net_device *dev, struct iw_request_info *info,
136         __u32 *mode, char *extra);
137 extern int usbdrvwext_siwsens(struct net_device *dev, struct iw_request_info *info,
138                 struct iw_param *sens, char *extra);
139 extern int usbdrvwext_giwsens(struct net_device *dev, struct iw_request_info *info,
140                 struct iw_param *sens, char *extra);
141 extern int usbdrvwext_giwrange(struct net_device *dev, struct iw_request_info *info,
142         struct iw_point *data, char *extra);
143 extern int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
144         struct sockaddr *MacAddr, char *extra);
145 extern int usbdrvwext_giwap(struct net_device *dev, struct iw_request_info *info,
146         struct sockaddr *MacAddr, char *extra);
147 extern int usbdrvwext_iwaplist(struct net_device *dev, struct iw_request_info *info,
148                 struct iw_point *data, char *extra);
149 extern int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
150         struct iw_point *data, char *extra);
151 extern int usbdrvwext_giwscan(struct net_device *dev, struct iw_request_info *info,
152         struct iw_point *data, char *extra);
153 extern int usbdrvwext_siwessid(struct net_device *dev, struct iw_request_info *info,
154         struct iw_point *essid, char *extra);
155 extern int usbdrvwext_giwessid(struct net_device *dev, struct iw_request_info *info,
156         struct iw_point *essid, char *extra);
157 extern int usbdrvwext_siwnickn(struct net_device *dev, struct iw_request_info *info,
158             struct iw_point *data, char *nickname);
159 extern int usbdrvwext_giwnickn(struct net_device *dev, struct iw_request_info *info,
160             struct iw_point *data, char *nickname);
161 extern int usbdrvwext_siwrate(struct net_device *dev, struct iw_request_info *info,
162         struct iw_param *frq, char *extra);
163 extern int usbdrvwext_giwrate(struct net_device *dev, struct iw_request_info *info,
164         struct iw_param *frq, char *extra);
165 extern int usbdrvwext_siwrts(struct net_device *dev, struct iw_request_info *info,
166         struct iw_param *rts, char *extra);
167 extern int usbdrvwext_giwrts(struct net_device *dev, struct iw_request_info *info,
168         struct iw_param *rts, char *extra);
169 extern int usbdrvwext_siwfrag(struct net_device *dev, struct iw_request_info *info,
170         struct iw_param *frag, char *extra);
171 extern int usbdrvwext_giwfrag(struct net_device *dev, struct iw_request_info *info,
172         struct iw_param *frag, char *extra);
173 extern int usbdrvwext_siwtxpow(struct net_device *dev, struct iw_request_info *info,
174                 struct iw_param *rrq, char *extra);
175 extern int usbdrvwext_giwtxpow(struct net_device *dev, struct iw_request_info *info,
176                 struct iw_param *rrq, char *extra);
177 extern int usbdrvwext_siwretry(struct net_device *dev, struct iw_request_info *info,
178             struct iw_param *rrq, char *extra);
179 extern int usbdrvwext_giwretry(struct net_device *dev, struct iw_request_info *info,
180             struct iw_param *rrq, char *extra);
181 extern int usbdrvwext_siwencode(struct net_device *dev, struct iw_request_info *info,
182         struct iw_point *erq, char *key);
183 extern int usbdrvwext_giwencode(struct net_device *dev, struct iw_request_info *info,
184         struct iw_point *erq, char *key);
185 extern int usbdrvwext_siwpower(struct net_device *dev, struct iw_request_info *info,
186         struct iw_param *frq, char *extra);
187 extern int usbdrvwext_giwpower(struct net_device *dev, struct iw_request_info *info,
188         struct iw_param *frq, char *extra);
189 extern int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
190 /*
191  * Structures to export the Wireless Handlers
192  */
193
194 struct iw_priv_args usbdrv_private_args[] = {
195 //    { SIOCIWFIRSTPRIV + 0x0, 0, 0, "list_bss" },
196 //    { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
197     { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_auth" },  /* 0 - open, 1 - shared key */
198     { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_CHAR | 12, "get_auth" },
199 //    { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble" },  /* 0 - long, 1 - short */
200 //    { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_CHAR | 6, "get_preamble" },
201 //    { SIOCIWFIRSTPRIV + 0x6, 0, 0, "cnt" },
202 //    { SIOCIWFIRSTPRIV + 0x7, 0, 0, "regs" },
203 //    { SIOCIWFIRSTPRIV + 0x8, 0, 0, "probe" },
204 //    { SIOCIWFIRSTPRIV + 0x9, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dbg_flag" },
205 //    { SIOCIWFIRSTPRIV + 0xA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "connect" },
206 //    { SIOCIWFIRSTPRIV + 0xB, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_mac_mode" },
207 //    { SIOCIWFIRSTPRIV + 0xC, 0, IW_PRIV_TYPE_CHAR | 12, "get_mac_mode" },
208 };
209
210 #if WIRELESS_EXT > 12
211 static iw_handler usbdrvwext_handler[] = {
212     (iw_handler) NULL,                              /* SIOCSIWCOMMIT */
213     (iw_handler) usbdrvwext_giwname,                /* SIOCGIWNAME */
214     (iw_handler) NULL,                              /* SIOCSIWNWID */
215     (iw_handler) NULL,                              /* SIOCGIWNWID */
216     (iw_handler) usbdrvwext_siwfreq,                /* SIOCSIWFREQ */
217     (iw_handler) usbdrvwext_giwfreq,                /* SIOCGIWFREQ */
218     (iw_handler) usbdrvwext_siwmode,                /* SIOCSIWMODE */
219     (iw_handler) usbdrvwext_giwmode,                /* SIOCGIWMODE */
220     (iw_handler) usbdrvwext_siwsens,                /* SIOCSIWSENS */
221     (iw_handler) usbdrvwext_giwsens,                /* SIOCGIWSENS */
222     (iw_handler) NULL, /* not used */               /* SIOCSIWRANGE */
223     (iw_handler) usbdrvwext_giwrange,               /* SIOCGIWRANGE */
224     (iw_handler) NULL, /* not used */               /* SIOCSIWPRIV */
225     (iw_handler) NULL, /* kernel code */            /* SIOCGIWPRIV */
226     (iw_handler) NULL, /* not used */               /* SIOCSIWSTATS */
227     (iw_handler) NULL, /* kernel code */            /* SIOCGIWSTATS */
228     (iw_handler) NULL,                              /* SIOCSIWSPY */
229     (iw_handler) NULL,                              /* SIOCGIWSPY */
230     (iw_handler) NULL,                              /* -- hole -- */
231     (iw_handler) NULL,                              /* -- hole -- */
232     (iw_handler) usbdrvwext_siwap,                  /* SIOCSIWAP */
233     (iw_handler) usbdrvwext_giwap,                  /* SIOCGIWAP */
234     (iw_handler) NULL,              /* -- hole -- */
235     (iw_handler) usbdrvwext_iwaplist,               /* SIOCGIWAPLIST */
236 #if WIRELESS_EXT > 13
237     (iw_handler) usbdrvwext_siwscan,                /* SIOCSIWSCAN */
238     (iw_handler) usbdrvwext_giwscan,                /* SIOCGIWSCAN */
239 #else /* WIRELESS_EXT > 13 */
240     (iw_handler) NULL, /* null */                   /* SIOCSIWSCAN */
241     (iw_handler) NULL, /* null */                   /* SIOCGIWSCAN */
242 #endif /* WIRELESS_EXT > 13 */
243     (iw_handler) usbdrvwext_siwessid,               /* SIOCSIWESSID */
244     (iw_handler) usbdrvwext_giwessid,               /* SIOCGIWESSID */
245
246     (iw_handler) usbdrvwext_siwnickn,               /* SIOCSIWNICKN */
247     (iw_handler) usbdrvwext_giwnickn,               /* SIOCGIWNICKN */
248     (iw_handler) NULL,                              /* -- hole -- */
249     (iw_handler) NULL,                              /* -- hole -- */
250     (iw_handler) usbdrvwext_siwrate,                /* SIOCSIWRATE */
251     (iw_handler) usbdrvwext_giwrate,                /* SIOCGIWRATE */
252     (iw_handler) usbdrvwext_siwrts,                 /* SIOCSIWRTS */
253     (iw_handler) usbdrvwext_giwrts,                 /* SIOCGIWRTS */
254     (iw_handler) usbdrvwext_siwfrag,                /* SIOCSIWFRAG */
255     (iw_handler) usbdrvwext_giwfrag,                /* SIOCGIWFRAG */
256     (iw_handler) usbdrvwext_siwtxpow,               /* SIOCSIWTXPOW */
257     (iw_handler) usbdrvwext_giwtxpow,               /* SIOCGIWTXPOW */
258     (iw_handler) usbdrvwext_siwretry,               /* SIOCSIWRETRY */
259     (iw_handler) usbdrvwext_giwretry,               /* SIOCGIWRETRY */
260     (iw_handler) usbdrvwext_siwencode,              /* SIOCSIWENCODE */
261     (iw_handler) usbdrvwext_giwencode,              /* SIOCGIWENCODE */
262     (iw_handler) usbdrvwext_siwpower,               /* SIOCSIWPOWER */
263     (iw_handler) usbdrvwext_giwpower,               /* SIOCGIWPOWER */
264 };
265
266 static const iw_handler usbdrv_private_handler[] =
267 {
268         //(iw_handler) usbdrvwext_setparam,             /* SIOCWFIRSTPRIV+0 */
269         //(iw_handler) usbdrvwext_getparam,             /* SIOCWFIRSTPRIV+1 */
270         //(iw_handler) usbdrvwext_setkey,                   /* SIOCWFIRSTPRIV+2 */
271         //(iw_handler) usbdrvwext_setwmmparams, /* SIOCWFIRSTPRIV+3 */
272         //(iw_handler) usbdrvwext_delkey,                   /* SIOCWFIRSTPRIV+4 */
273         //(iw_handler) usbdrvwext_getwmmparams, /* SIOCWFIRSTPRIV+5 */
274         //(iw_handler) usbdrvwext_setmlme,              /* SIOCWFIRSTPRIV+6 */
275         //(iw_handler) usbdrvwext_getchaninfo,  /* SIOCWFIRSTPRIV+7 */
276         //(iw_handler) usbdrvwext_setoptie,             /* SIOCWFIRSTPRIV+8 */
277         //(iw_handler) usbdrvwext_getoptie,             /* SIOCWFIRSTPRIV+9 */
278         //(iw_handler) usbdrvwext_addmac,                   /* SIOCWFIRSTPRIV+10 */
279         //(iw_handler) usbdrvwext_getscanresults,       /* SIOCWFIRSTPRIV+11 */
280         //(iw_handler) usbdrvwext_delmac,                   /* SIOCWFIRSTPRIV+12 */
281         //(iw_handler) usbdrvwext_getchanlist,  /* SIOCWFIRSTPRIV+13 */
282         //(iw_handler) usbdrvwext_setchanlist,  /* SIOCWFIRSTPRIV+14 */
283         //(iw_handler) NULL,                                    /* SIOCWFIRSTPRIV+15 */
284         //(iw_handler) usbdrvwext_chanswitch,       /* SIOCWFIRSTPRIV+16 */
285         //(iw_handler) usbdrvwext_setmode,              /* SIOCWFIRSTPRIV+17 */
286         //(iw_handler) usbdrvwext_getmode,              /* SIOCWFIRSTPRIV+18 */
287     NULL,               /* SIOCIWFIRSTPRIV */
288 };
289
290 static struct iw_handler_def p80211wext_handler_def = {
291     .num_standard = sizeof(usbdrvwext_handler) / sizeof(iw_handler),
292     .num_private = sizeof(usbdrv_private_handler)/sizeof(iw_handler),
293     .num_private_args = sizeof(usbdrv_private_args)/sizeof(struct iw_priv_args),
294     .standard = usbdrvwext_handler,
295     .private = (iw_handler *) usbdrv_private_handler,
296     .private_args = (struct iw_priv_args *) usbdrv_private_args
297 };
298 #endif
299
300 /* WDS */
301 //struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
302 //void zfInitWdsStruct(void);
303
304 /* VAP */
305 struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
306 void zfLnxInitVapStruct(void);
307
308
309 /**
310  * usbdrv_intr - interrupt handler
311  * @irq: the IRQ number
312  * @dev_inst: the net_device struct
313  * @regs: registers (unused)
314  *
315  * This routine is the ISR for the usbdrv board. It services
316  * the RX & TX queues & starts the RU if it has stopped due
317  * to no resources.
318  */
319 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
320 irqreturn_t usbdrv_intr(int irq, void *dev_inst, struct pt_regs *regs)
321 #else
322 void usbdrv_intr(int irq, void *dev_inst, struct pt_regs *regs)
323 #endif
324 {
325     struct net_device *dev;
326     struct usbdrv_private *macp;
327
328     dev = dev_inst;
329     macp = dev->ml_priv;
330
331
332     /* Read register error, card may be unpluged */
333     if (0)//(intr_status == -1)
334 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
335         return IRQ_NONE;
336 #else
337         return;
338 #endif
339
340     /* the device is closed, don't continue or else bad things may happen. */
341     if (!netif_running(dev)) {
342 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
343         return IRQ_NONE;
344 #else
345         return;
346 #endif
347     }
348
349     if (macp->driver_isolated) {
350 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
351         return IRQ_NONE;
352 #else
353         return;
354 #endif
355     }
356
357 #if (WLAN_HOSTIF == WLAN_PCI)
358     //zfiIsrPci(dev);
359 #endif
360
361 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
362     return IRQ_HANDLED;
363 #else
364     return;
365 #endif
366 }
367
368 int usbdrv_open(struct net_device *dev)
369 {
370     struct usbdrv_private *macp = dev->ml_priv;
371     int rc = 0;
372     u16_t size;
373     void* mem;
374     //unsigned char addr[6];
375     struct zsCbFuncTbl cbFuncTbl;
376
377     printk("Enter open()\n");
378
379 //#ifndef CONFIG_SMP
380 //    read_lock(&(macp->isolate_lock));
381 //#endif
382     if (macp->driver_isolated) {
383         rc = -EBUSY;
384         goto exit;
385     }
386
387     size = zfiGlobalDataSize(dev);
388     if ((mem = kmalloc(size, GFP_KERNEL)) == NULL)
389     {
390         rc = -EBUSY;
391         goto exit;
392     }
393     macp->wd = mem;
394
395     memset(&cbFuncTbl, 0, sizeof(struct zsCbFuncTbl));
396     cbFuncTbl.zfcbAuthNotify = zfLnxAuthNotify;
397     cbFuncTbl.zfcbAuthNotify = zfLnxAuthNotify;
398     cbFuncTbl.zfcbAsocNotify = zfLnxAsocNotify;
399     cbFuncTbl.zfcbDisAsocNotify = zfLnxDisAsocNotify;
400     cbFuncTbl.zfcbApConnectNotify = zfLnxApConnectNotify;
401     cbFuncTbl.zfcbConnectNotify = zfLnxConnectNotify;
402     cbFuncTbl.zfcbScanNotify = zfLnxScanNotify;
403     cbFuncTbl.zfcbMicFailureNotify = zfLnxMicFailureNotify;
404     cbFuncTbl.zfcbApMicFailureNotify = zfLnxApMicFailureNotify;
405     cbFuncTbl.zfcbIbssPartnerNotify = zfLnxIbssPartnerNotify;
406     cbFuncTbl.zfcbMacAddressNotify = zfLnxMacAddressNotify;
407     cbFuncTbl.zfcbSendCompleteIndication = zfLnxSendCompleteIndication;
408     cbFuncTbl.zfcbRecvEth = zfLnxRecvEth;
409     cbFuncTbl.zfcbRecv80211 = zfLnxRecv80211;
410     cbFuncTbl.zfcbRestoreBufData = zfLnxRestoreBufData;
411 #ifdef ZM_ENABLE_CENC
412     cbFuncTbl.zfcbCencAsocNotify = zfLnxCencAsocNotify;
413 #endif //ZM_ENABLE_CENC
414     cbFuncTbl.zfcbHwWatchDogNotify = zfLnxWatchDogNotify;
415     zfiWlanOpen(dev, &cbFuncTbl);
416
417 #if 0
418     {
419         //u16_t mac[3] = {0x1300, 0xb6d4, 0x5aaf};
420         u16_t mac[3] = {0x8000, 0x00ab, 0x0000};
421         //zfiWlanSetMacAddress(dev, mac);
422     }
423     /* MAC address */
424     zfiWlanQueryMacAddress(dev, addr);
425     dev->dev_addr[0] = addr[0];
426     dev->dev_addr[1] = addr[1];
427     dev->dev_addr[2] = addr[2];
428     dev->dev_addr[3] = addr[3];
429     dev->dev_addr[4] = addr[4];
430     dev->dev_addr[5] = addr[5];
431 #endif
432     //zfwMacAddressNotify() will be called to setup dev->dev_addr[]
433
434     zfLnxCreateThread(dev);
435
436     mod_timer(&(macp->hbTimer10ms), jiffies + (1*HZ)/100);   //10 ms
437
438     netif_carrier_on(dev);
439
440     netif_start_queue(dev);
441
442 #if ZM_AP_MODE == 1
443     zfiWlanSetWlanMode(dev, ZM_MODE_AP);
444     zfiWlanSetBasicRate(dev, 0xf, 0, 0);
445     zfiWlanSetSSID(dev, "OTUS_CWY", 8);
446     zfiWlanSetDtimCount(dev, 3);
447
448   #if ZM_WEP_MOME == 1
449     {
450         u8_t key[16] = {0x12, 0x34, 0x56, 0x78, 0x90};
451         struct zsKeyInfo keyInfo;
452
453         keyInfo.keyLength = 5;
454         keyInfo.keyIndex = 0;
455         keyInfo.flag = 0;
456         keyInfo.key = key;
457         zfiWlanSetKey(dev, keyInfo);
458
459         zfiWlanSetEncryMode(dev, ZM_WEP64);
460     }
461
462     #if ZM_SHARE_AUTH == 1
463     zfiWlanSetAuthenticationMode(dev, 1);
464     #endif //#if ZM_SHARE_AUTH == 1
465   #endif //#if ZM_WEP_MOME == 1
466
467 #elif ZM_PIBSS_MODE == 1
468     zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
469 #else
470     zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
471 #endif
472     //zfiWlanSetChannel(dev, ZM_CHANNEL, FALSE);
473     zfiWlanSetFrequency(dev, 2462000, FALSE);
474     zfiWlanSetRtsThreshold(dev, 32767);
475     zfiWlanSetFragThreshold(dev, 0);
476
477     zfiWlanEnable(dev);
478
479 #ifdef ZM_ENABLE_CENC
480 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
481     macp->netlink_sk = netlink_kernel_create(NETLINK_USERSOCK, NULL);
482 #else
483     macp->netlink_sk = netlink_kernel_create(NETLINK_USERSOCK, 1, NULL, THIS_MODULE);
484 #endif
485
486     if (macp->netlink_sk == NULL)
487     {
488         printk(KERN_ERR "Can't create NETLINK socket\n");
489     }
490 #endif
491
492     macp->DeviceOpened = 1;
493 exit:
494 //#ifndef CONFIG_SMP
495 //    read_unlock(&(macp->isolate_lock));
496 //#endif
497     //zfRegisterWdsDev(dev, 0);
498     //zfLnxRegisterVapDev(dev, 0);
499
500     return rc;
501 }
502
503
504
505
506 /**
507  * usbdrv_get_stats - get driver statistics
508  * @dev: adapter's net_device struct
509  *
510  * This routine is called when the OS wants the adapter's stats returned.
511  * It returns the address of the net_device_stats stucture for the device.
512  * If the statistics are currently being updated, then they might be incorrect
513  * for a short while. However, since this cannot actually cause damage, no
514  * locking is used.
515  */
516
517 struct net_device_stats * usbdrv_get_stats(struct net_device *dev)
518 {
519     struct usbdrv_private *macp = dev->ml_priv;
520
521     macp->drv_stats.net_stats.tx_errors =
522         macp->drv_stats.net_stats.tx_carrier_errors +
523         macp->drv_stats.net_stats.tx_aborted_errors;
524
525     macp->drv_stats.net_stats.rx_errors =
526         macp->drv_stats.net_stats.rx_crc_errors +
527         macp->drv_stats.net_stats.rx_frame_errors +
528         macp->drv_stats.net_stats.rx_length_errors;
529
530
531     return &(macp->drv_stats.net_stats);
532 }
533
534
535 /**
536  * usbdrv_set_mac - set the MAC address
537  * @dev: adapter's net_device struct
538  * @addr: the new address
539  *
540  * This routine sets the ethernet address of the board
541  * Returns:
542  * 0  - if successful
543  * -1 - otherwise
544  */
545
546 int usbdrv_set_mac(struct net_device *dev, void *addr)
547 {
548     struct usbdrv_private *macp;
549     int rc = -1;
550
551     macp = dev->ml_priv;
552     read_lock(&(macp->isolate_lock));
553
554     if (macp->driver_isolated) {
555         goto exit;
556     }
557
558     rc = 0;
559
560
561 exit:
562     read_unlock(&(macp->isolate_lock));
563     return rc;
564 }
565
566
567
568 void
569 usbdrv_isolate_driver(struct usbdrv_private *macp)
570 {
571 #ifndef CONFIG_SMP
572     write_lock_irq(&(macp->isolate_lock));
573 #endif
574     macp->driver_isolated = TRUE;
575 #ifndef CONFIG_SMP
576     write_unlock_irq(&(macp->isolate_lock));
577 #endif
578
579     if (netif_running(macp->device))
580     {
581         netif_carrier_off(macp->device);
582         netif_stop_queue(macp->device);
583     }
584 }
585
586 #define VLAN_SIZE       4
587 int usbdrv_change_mtu(struct net_device *dev, int new_mtu)
588 {
589     if ((new_mtu < 68) || (new_mtu > (ETH_DATA_LEN + VLAN_SIZE)))
590         return -EINVAL;
591
592     dev->mtu = new_mtu;
593     return 0;
594 }
595
596 void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp);
597
598 int usbdrv_close(struct net_device *dev)
599 {
600 extern void zfHpLedCtrl(struct net_device *dev, u16_t ledId, u8_t mode);
601
602     struct usbdrv_private *macp = dev->ml_priv;
603
604     printk(KERN_DEBUG "usbdrv_close\n");
605
606     netif_carrier_off(macp->device);
607
608     del_timer_sync(&macp->hbTimer10ms);
609
610     printk(KERN_DEBUG "usbdrv_netif_carrier_off\n");
611
612     usbdrv_isolate_driver(macp);
613
614     printk(KERN_DEBUG "usbdrv_isolate_driver\n");
615
616     netif_carrier_off(macp->device);
617 #ifdef ZM_ENABLE_CENC
618     /* CENC */
619     if (macp->netlink_sk != NULL)
620     {
621     //    sock_release(macp->netlink_sk);
622         printk(KERN_ERR "usbdrv close netlink socket\n");
623     }
624 #endif //ZM_ENABLE_CENC
625 #if (WLAN_HOSTIF == WLAN_PCI)
626     //free_irq(dev->irq, dev);
627 #endif
628
629     /* Turn off LED */
630     zfHpLedCtrl(dev, 0, 0);
631     zfHpLedCtrl(dev, 1, 0);
632
633     /* Delay for a while */
634     mdelay(10);
635
636     /* clear WPA/RSN IE */
637     macp->supIe[1] = 0;
638
639     /* set the isolate flag to false, so usbdrv_open can be called */
640     macp->driver_isolated = FALSE;
641
642     zfiWlanClose(dev);
643     kfree(macp->wd);
644
645     zfLnxUnlinkAllUrbs(macp);
646
647     return 0;
648 }
649
650
651
652
653 int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev)
654 {
655     int notify_stop = FALSE;
656     struct usbdrv_private *macp = dev->ml_priv;
657
658 #if 0
659     /* Test code */
660     {
661         struct sk_buff* s;
662
663         s = skb_copy_expand(skb, 8, 0, GFP_ATOMIC);
664         skb_push(s, 8);
665         s->data[0] = 'z';
666         s->data[1] = 'y';
667         s->data[2] = 'd';
668         s->data[3] = 'a';
669         s->data[4] = 's';
670         printk("len1=%d, len2=%d", skb->len, s->len);
671         netlink_broadcast(rtnl, s, 0, RTMGRP_LINK, GFP_ATOMIC);
672     }
673 #endif
674
675 #if ZM_DISABLE_XMIT
676     dev_kfree_skb_irq(skb);
677 #else
678     zfiTxSendEth(dev, skb, 0);
679 #endif
680     macp->drv_stats.net_stats.tx_bytes += skb->len;
681     macp->drv_stats.net_stats.tx_packets++;
682
683     //dev_kfree_skb_irq(skb);
684
685     if (notify_stop) {
686         netif_carrier_off(dev);
687         netif_stop_queue(dev);
688     }
689
690     return 0;
691 }
692
693
694
695
696 void usbdrv_set_multi(struct net_device *dev)
697 {
698
699
700     if (!(dev->flags & IFF_UP))
701         return;
702
703         return;
704
705 }
706
707
708
709 /**
710  * usbdrv_clear_structs - free resources
711
712  * @dev: adapter's net_device struct
713  *
714  * Free all device specific structs, unmap i/o address, etc.
715  */
716 void usbdrv_clear_structs(struct net_device *dev)
717 {
718     struct usbdrv_private *macp = dev->ml_priv;
719
720
721 #if (WLAN_HOSTIF == WLAN_PCI)
722     iounmap(macp->regp);
723
724     pci_release_regions(macp->pdev);
725     pci_disable_device(macp->pdev);
726     pci_set_drvdata(macp->pdev, NULL);
727 #endif
728
729     kfree(macp);
730
731     kfree(dev);
732
733 }
734
735 void usbdrv_remove1(struct pci_dev *pcid)
736 {
737     struct net_device *dev;
738     struct usbdrv_private *macp;
739
740     if (!(dev = (struct net_device *) pci_get_drvdata(pcid)))
741         return;
742
743     macp = dev->ml_priv;
744     unregister_netdev(dev);
745
746     usbdrv_clear_structs(dev);
747 }
748
749
750 void zfLnx10msTimer(struct net_device* dev)
751 {
752     struct usbdrv_private *macp = dev->ml_priv;
753
754     mod_timer(&(macp->hbTimer10ms), jiffies + (1*HZ)/100);   //10 ms
755     zfiHeartBeat(dev);
756     return;
757 }
758
759 void zfLnxInitVapStruct(void)
760 {
761     u16_t i;
762
763     for (i=0; i<ZM_VAP_PORT_NUMBER; i++)
764     {
765         vap[i].dev = NULL;
766         vap[i].openFlag = 0;
767     }
768 }
769
770 int zfLnxVapOpen(struct net_device *dev)
771 {
772     u16_t vapId;
773
774     vapId = zfLnxGetVapId(dev);
775
776     if (vap[vapId].openFlag == 0)
777     {
778         vap[vapId].openFlag = 1;
779         printk("zfLnxVapOpen : device name=%s, vap ID=%d\n", dev->name, vapId);
780         zfiWlanSetSSID(dev, "vap1", 4);
781         zfiWlanEnable(dev);
782         netif_start_queue(dev);
783     }
784     else
785     {
786         printk("VAP opened error : vap ID=%d\n", vapId);
787     }
788         return 0;
789 }
790
791 int zfLnxVapClose(struct net_device *dev)
792 {
793     u16_t vapId;
794
795     vapId = zfLnxGetVapId(dev);
796
797     if (vapId != 0xffff)
798     {
799         if (vap[vapId].openFlag == 1)
800         {
801             printk("zfLnxVapClose: device name=%s, vap ID=%d\n", dev->name, vapId);
802
803             netif_stop_queue(dev);
804             vap[vapId].openFlag = 0;
805         }
806         else
807         {
808             printk("VAP port was not opened : vap ID=%d\n", vapId);
809         }
810     }
811         return 0;
812 }
813
814 int zfLnxVapXmitFrame(struct sk_buff *skb, struct net_device *dev)
815 {
816     int notify_stop = FALSE;
817     struct usbdrv_private *macp = dev->ml_priv;
818     u16_t vapId;
819
820     vapId = zfLnxGetVapId(dev);
821     //printk("zfLnxVapXmitFrame: vap ID=%d\n", vapId);
822     //printk("zfLnxVapXmitFrame(), skb=%lxh\n", (u32_t)skb);
823
824     if (vapId >= ZM_VAP_PORT_NUMBER)
825     {
826         dev_kfree_skb_irq(skb);
827         return 0;
828     }
829 #if 1
830     if (vap[vapId].openFlag == 0)
831     {
832         dev_kfree_skb_irq(skb);
833         return 0;
834     }
835 #endif
836
837
838     zfiTxSendEth(dev, skb, 0x1);
839
840     macp->drv_stats.net_stats.tx_bytes += skb->len;
841     macp->drv_stats.net_stats.tx_packets++;
842
843     //dev_kfree_skb_irq(skb);
844
845     if (notify_stop) {
846         netif_carrier_off(dev);
847         netif_stop_queue(dev);
848     }
849
850     return 0;
851 }
852
853 int zfLnxRegisterVapDev(struct net_device* parentDev, u16_t vapId)
854 {
855     /* Allocate net device structure */
856     vap[vapId].dev = alloc_etherdev(0);
857     printk("Register vap dev=%x\n", (u32_t)vap[vapId].dev);
858
859     if(vap[vapId].dev == NULL) {
860         printk("alloc_etherdev fail\n");
861         return -ENOMEM;
862     }
863
864     /* Setup the default settings */
865     ether_setup(vap[vapId].dev);
866
867     /* MAC address */
868     memcpy(vap[vapId].dev->dev_addr, parentDev->dev_addr, ETH_ALEN);
869
870     vap[vapId].dev->irq = parentDev->irq;
871     vap[vapId].dev->base_addr = parentDev->base_addr;
872     vap[vapId].dev->mem_start = parentDev->mem_start;
873     vap[vapId].dev->mem_end = parentDev->mem_end;
874     vap[vapId].dev->ml_priv = parentDev->ml_priv;
875
876     //dev->hard_start_xmit = &zd1212_wds_xmit_frame;
877     vap[vapId].dev->hard_start_xmit = &zfLnxVapXmitFrame;
878     vap[vapId].dev->open = &zfLnxVapOpen;
879     vap[vapId].dev->stop = &zfLnxVapClose;
880     vap[vapId].dev->get_stats = &usbdrv_get_stats;
881     vap[vapId].dev->change_mtu = &usbdrv_change_mtu;
882 #ifdef ZM_HOSTAPD_SUPPORT
883     vap[vapId].dev->do_ioctl = usbdrv_ioctl;
884 #else
885     vap[vapId].dev->do_ioctl = NULL;
886 #endif
887 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
888     vap[vapId].dev->destructor = free_netdev;
889 #else
890     vap[vapId].dev->features |= NETIF_F_DYNALLOC;
891 #endif
892
893     vap[vapId].dev->tx_queue_len = 0;
894
895     vap[vapId].dev->dev_addr[0] = parentDev->dev_addr[0];
896     vap[vapId].dev->dev_addr[1] = parentDev->dev_addr[1];
897     vap[vapId].dev->dev_addr[2] = parentDev->dev_addr[2];
898     vap[vapId].dev->dev_addr[3] = parentDev->dev_addr[3];
899     vap[vapId].dev->dev_addr[4] = parentDev->dev_addr[4];
900     vap[vapId].dev->dev_addr[5] = parentDev->dev_addr[5] + (vapId+1);
901
902     /* Stop the network queue first */
903     netif_stop_queue(vap[vapId].dev);
904
905     sprintf(vap[vapId].dev->name, "vap%d", vapId);
906     printk("Register VAP dev success : %s\n", vap[vapId].dev->name);
907
908     if(register_netdevice(vap[vapId].dev) != 0) {
909         printk("register VAP device fail\n");
910         vap[vapId].dev = NULL;
911         return -EINVAL;
912     }
913
914     return 0;
915 }
916
917 int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId)
918 {
919     int ret = 0;
920
921     printk("Unregister VAP dev : %s\n", vap[vapId].dev->name);
922
923     if(vap[vapId].dev != NULL) {
924         printk("Unregister vap dev=%x\n", (u32_t)vap[vapId].dev);
925         //
926         //unregister_netdevice(wds[wdsId].dev);
927         unregister_netdev(vap[vapId].dev);
928
929         printk("VAP unregister_netdevice\n");
930         vap[vapId].dev = NULL;
931     }
932     else {
933         printk("unregister VAP device: %d fail\n", vapId);
934         ret = -EINVAL;
935     }
936
937     return ret;
938 }
939
940
941
942 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* tune me! */
943 #  define SUBMIT_URB(u,f)       usb_submit_urb(u,f)
944 #  define USB_ALLOC_URB(u,f)    usb_alloc_urb(u,f)
945 #else
946 #  define SUBMIT_URB(u,f)       usb_submit_urb(u)
947 #  define USB_ALLOC_URB(u,f)    usb_alloc_urb(u)
948 #endif
949
950 //extern void zfiWlanQueryMacAddress(zdev_t* dev, u8_t* addr);
951
952 extern int usbdrv_open(struct net_device *dev);
953 extern int usbdrv_close(struct net_device *dev);
954 extern int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev);
955 extern int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev);
956 extern int usbdrv_change_mtu(struct net_device *dev, int new_mtu);
957 extern void usbdrv_set_multi(struct net_device *dev);
958 extern int usbdrv_set_mac(struct net_device *dev, void *addr);
959 extern struct net_device_stats * usbdrv_get_stats(struct net_device *dev);
960 extern int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
961 extern UsbTxQ_t *zfLnxGetUsbTxBuffer(struct net_device *dev);
962
963 int zfLnxAllocAllUrbs(struct usbdrv_private *macp)
964 {
965     struct usb_interface *interface = macp->interface;
966 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
967     struct usb_interface_descriptor *iface_desc = &interface->altsetting[0];
968 #else
969     struct usb_host_interface *iface_desc = &interface->altsetting[0];
970 #endif
971
972     struct usb_endpoint_descriptor *endpoint;
973     int i;
974
975     /* descriptor matches, let's find the endpoints needed */
976     /* check out the endpoints */
977 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
978     for (i = 0; i < iface_desc->bNumEndpoints; ++i)
979     {
980         endpoint = &iface_desc->endpoint[i];
981 #else
982     for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
983     {
984         endpoint = &iface_desc->endpoint[i].desc;
985 #endif
986         if ((endpoint->bEndpointAddress & 0x80) &&
987             ((endpoint->bmAttributes & 3) == 0x02))
988         {
989             /* we found a bulk in endpoint */
990             printk(KERN_ERR "bulk in: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
991         }
992
993         if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
994             ((endpoint->bmAttributes & 3) == 0x02))
995         {
996             /* we found a bulk out endpoint */
997             printk(KERN_ERR "bulk out: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
998         }
999
1000         if ((endpoint->bEndpointAddress & 0x80) &&
1001             ((endpoint->bmAttributes & 3) == 0x03))
1002         {
1003             /* we found a interrupt in endpoint */
1004             printk(KERN_ERR "interrupt in: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
1005             printk(KERN_ERR "interrupt in: int_interval = %d\n", endpoint->bInterval);
1006         }
1007
1008         if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
1009             ((endpoint->bmAttributes & 3) == 0x03))
1010         {
1011             /* we found a interrupt out endpoint */
1012             printk(KERN_ERR "interrupt out: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
1013             printk(KERN_ERR "interrupt out: int_interval = %d\n", endpoint->bInterval);
1014         }
1015     }
1016
1017     /* Allocate all Tx URBs */
1018     for (i = 0; i < ZM_MAX_TX_URB_NUM; i++)
1019     {
1020         macp->WlanTxDataUrb[i] = USB_ALLOC_URB(0, GFP_KERNEL);
1021
1022         if (macp->WlanTxDataUrb[i] == 0)
1023         {
1024             int j;
1025
1026             /* Free all urbs */
1027             for (j = 0; j < i; j++)
1028             {
1029                 usb_free_urb(macp->WlanTxDataUrb[j]);
1030             }
1031
1032             return 0;
1033         }
1034     }
1035
1036     /* Allocate all Rx URBs */
1037     for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
1038     {
1039         macp->WlanRxDataUrb[i] = USB_ALLOC_URB(0, GFP_KERNEL);
1040
1041         if (macp->WlanRxDataUrb[i] == 0)
1042         {
1043             int j;
1044
1045             /* Free all urbs */
1046             for (j = 0; j < i; j++)
1047             {
1048                 usb_free_urb(macp->WlanRxDataUrb[j]);
1049             }
1050
1051             for (j = 0; j < ZM_MAX_TX_URB_NUM; j++)
1052             {
1053                 usb_free_urb(macp->WlanTxDataUrb[j]);
1054             }
1055
1056             return 0;
1057         }
1058     }
1059
1060     /* Allocate Register Read/Write USB */
1061     macp->RegOutUrb = USB_ALLOC_URB(0, GFP_KERNEL);
1062     macp->RegInUrb = USB_ALLOC_URB(0, GFP_KERNEL);
1063
1064     return 1;
1065 }
1066
1067 void zfLnxFreeAllUrbs(struct usbdrv_private *macp)
1068 {
1069     int i;
1070
1071     /* Free all Tx URBs */
1072     for (i = 0; i < ZM_MAX_TX_URB_NUM; i++)
1073     {
1074         if (macp->WlanTxDataUrb[i] != NULL)
1075         {
1076             usb_free_urb(macp->WlanTxDataUrb[i]);
1077         }
1078     }
1079
1080     /* Free all Rx URBs */
1081     for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
1082     {
1083         if (macp->WlanRxDataUrb[i] != NULL)
1084         {
1085             usb_free_urb(macp->WlanRxDataUrb[i]);
1086         }
1087     }
1088
1089     /* Free USB Register Read/Write URB */
1090     usb_free_urb(macp->RegOutUrb);
1091     usb_free_urb(macp->RegInUrb);
1092 }
1093
1094 void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp)
1095 {
1096     int i;
1097
1098     /* Unlink all Tx URBs */
1099     for (i = 0; i < ZM_MAX_TX_URB_NUM; i++)
1100     {
1101         if (macp->WlanTxDataUrb[i] != NULL)
1102         {
1103 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1104             macp->WlanTxDataUrb[i]->transfer_flags &= ~URB_ASYNC_UNLINK;
1105 #endif
1106             usb_unlink_urb(macp->WlanTxDataUrb[i]);
1107         }
1108     }
1109
1110     /* Unlink all Rx URBs */
1111     for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
1112     {
1113         if (macp->WlanRxDataUrb[i] != NULL)
1114         {
1115 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1116             macp->WlanRxDataUrb[i]->transfer_flags &= ~URB_ASYNC_UNLINK;
1117 #endif
1118             usb_unlink_urb(macp->WlanRxDataUrb[i]);
1119         }
1120     }
1121
1122     /* Unlink USB Register Read/Write URB */
1123 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1124     macp->RegOutUrb->transfer_flags &= ~URB_ASYNC_UNLINK;
1125 #endif
1126     usb_unlink_urb(macp->RegOutUrb);
1127
1128 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1129     macp->RegInUrb->transfer_flags &= ~URB_ASYNC_UNLINK;
1130 #endif
1131     usb_unlink_urb(macp->RegInUrb);
1132 }
1133
1134 u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp)
1135 {
1136     //unsigned char addr[6];
1137
1138     //init_MUTEX(&macp->ps_sem);
1139     //init_MUTEX(&macp->reg_sem);
1140     //init_MUTEX(&macp->bcn_sem);
1141     //init_MUTEX(&macp->config_sem);
1142
1143     spin_lock_init(&(macp->cs_lock));
1144 #if 0
1145     /* MAC address */
1146     zfiWlanQueryMacAddress(dev, addr);
1147     dev->dev_addr[0] = addr[0];
1148     dev->dev_addr[1] = addr[1];
1149     dev->dev_addr[2] = addr[2];
1150     dev->dev_addr[3] = addr[3];
1151     dev->dev_addr[4] = addr[4];
1152     dev->dev_addr[5] = addr[5];
1153 #endif
1154 #if WIRELESS_EXT > 12
1155     dev->wireless_handlers = (struct iw_handler_def *)&p80211wext_handler_def;
1156 #endif
1157
1158     dev->open = usbdrv_open;
1159     dev->hard_start_xmit = usbdrv_xmit_frame;
1160     dev->stop = usbdrv_close;
1161     dev->change_mtu = &usbdrv_change_mtu;
1162     dev->get_stats = usbdrv_get_stats;
1163     dev->set_multicast_list = usbdrv_set_multi;
1164     dev->set_mac_address = usbdrv_set_mac;
1165     dev->do_ioctl = usbdrv_ioctl;
1166
1167     dev->flags |= IFF_MULTICAST;
1168
1169 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1170     dev->dev_addr[0] = 0x00;
1171     dev->dev_addr[1] = 0x03;
1172     dev->dev_addr[2] = 0x7f;
1173     dev->dev_addr[3] = 0x11;
1174     dev->dev_addr[4] = 0x22;
1175     dev->dev_addr[5] = 0x33;
1176 #endif
1177
1178     /* Initialize Heart Beat timer */
1179     init_timer(&macp->hbTimer10ms);
1180     macp->hbTimer10ms.data = (unsigned long)dev;
1181     macp->hbTimer10ms.function = (void *)&zfLnx10msTimer;
1182
1183     /* Initialize WDS and VAP data structure */
1184     //zfInitWdsStruct();
1185     zfLnxInitVapStruct();
1186
1187     return 1;
1188 }
1189
1190 u8_t zfLnxClearStructs(struct net_device *dev)
1191 {
1192     u16_t ii;
1193     u16_t TxQCnt;
1194
1195     TxQCnt = zfLnxCheckTxBufferCnt(dev);
1196
1197     printk(KERN_ERR "TxQCnt: %d\n", TxQCnt);
1198
1199     for(ii = 0; ii < TxQCnt; ii++)
1200     {
1201         UsbTxQ_t *TxQ = zfLnxGetUsbTxBuffer(dev);
1202
1203         printk(KERN_ERR "dev_kfree_skb_any\n");
1204         /* Free buffer */
1205         dev_kfree_skb_any(TxQ->buf);
1206     }
1207
1208     return 0;
1209 }