ASoC: Remove duplicate ADC/DAC widgets from wm_hubs.c
[linux/fpc-iii.git] / drivers / staging / otus / usbdrv.c
blob540cbbb826f9a5137cf93f2608fb6c1decd6e415
1 /*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
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.
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.
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 /************************************************************************/
26 /* src/usbdrv.c */
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
35 #include "usbdrv.h"
36 #include "oal_dt.h"
37 #include "80211core/pub_zfi.h"
39 #include "linux/netlink.h"
40 #include "linux/rtnetlink.h"
42 #if WIRELESS_EXT > 12
43 #include <net/iw_handler.h>
44 #endif
46 #ifdef ZM_HOSTAPD_SUPPORT
47 #include "athr_common.h"
48 #endif
50 extern void zfDumpDescriptor(zdev_t* dev, u16_t type);
51 //extern void zfiWlanQueryMacAddress(zdev_t* dev, u8_t* addr);
53 // ISR handler
54 irqreturn_t usbdrv_intr(int, void *, struct pt_regs *);
56 // Network Device interface related function
57 int usbdrv_open(struct net_device *);
58 int usbdrv_close(struct net_device *);
59 int usbdrv_change_mtu(struct net_device *, int);
60 int usbdrv_set_mac(struct net_device *, void *);
61 int usbdrv_xmit_frame(struct sk_buff *, struct net_device *);
62 void usbdrv_set_multi(struct net_device *);
63 struct net_device_stats *usbdrv_get_stats(struct net_device *);
65 //wireless extension helper functions
66 int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
67 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq);
68 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
69 /* Wireless Extension Handler functions */
70 int usbdrvwext_giwmode(struct net_device *dev, struct iw_request_info* info,
71 __u32 *mode, char *extra);
72 int zfLnxPrivateIoctl(struct usbdrv_private *macp, struct zdap_ioctl *zdreq);
74 void zfLnx10msTimer(struct net_device* dev);
75 int zfUnregisterWdsDev(struct net_device* parentDev, u16_t wdsId);
76 int zfRegisterWdsDev(struct net_device* parentDev, u16_t wdsId);
77 int zfWdsOpen(struct net_device *dev);
78 int zfWdsClose(struct net_device *dev);
79 int zfLnxVapOpen(struct net_device *dev);
80 int zfLnxVapClose(struct net_device *dev);
81 int zfLnxVapXmitFrame(struct sk_buff *skb, struct net_device *dev);
82 int zfLnxRegisterVapDev(struct net_device* parentDev, u16_t vapId);
83 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm);
84 extern u16_t zfLnxGetVapId(zdev_t* dev);
85 extern u16_t zfLnxCheckTxBufferCnt(zdev_t *dev);
86 extern UsbTxQ_t *zfLnxGetUsbTxBuffer(zdev_t *dev);
88 extern u16_t zfLnxAuthNotify(zdev_t* dev, u16_t* macAddr);
89 extern u16_t zfLnxAsocNotify(zdev_t* dev, u16_t* macAddr, u8_t* body, u16_t bodySize, u16_t port);
90 extern u16_t zfLnxDisAsocNotify(zdev_t* dev, u8_t* macAddr, u16_t port);
91 extern u16_t zfLnxApConnectNotify(zdev_t* dev, u8_t* macAddr, u16_t port);
92 extern void zfLnxConnectNotify(zdev_t* dev, u16_t status, u16_t* bssid);
93 extern void zfLnxScanNotify(zdev_t* dev, struct zsScanResult* result);
94 extern void zfLnxStatisticsNotify(zdev_t* dev, struct zsStastics* result);
95 extern void zfLnxMicFailureNotify(zdev_t* dev, u16_t* addr, u16_t status);
96 extern void zfLnxApMicFailureNotify(zdev_t* dev, u8_t* addr, zbuf_t* buf);
97 extern void zfLnxIbssPartnerNotify(zdev_t* dev, u16_t status, struct zsPartnerNotifyEvent *event);
98 extern void zfLnxMacAddressNotify(zdev_t* dev, u8_t* addr);
99 extern void zfLnxSendCompleteIndication(zdev_t* dev, zbuf_t* buf);
100 extern void zfLnxRecvEth(zdev_t* dev, zbuf_t* buf, u16_t port);
101 extern void zfLnxRestoreBufData(zdev_t* dev, zbuf_t* buf);
102 #ifdef ZM_ENABLE_CENC
103 extern u16_t zfLnxCencAsocNotify(zdev_t* dev, u16_t* macAddr, u8_t* body, u16_t bodySize, u16_t port);
104 #endif //ZM_ENABLE_CENC
105 extern void zfLnxWatchDogNotify(zdev_t* dev);
106 extern void zfLnxRecv80211(zdev_t* dev, zbuf_t* buf, struct zsAdditionInfo* addInfo);
107 extern u8_t zfLnxCreateThread(zdev_t *dev);
109 /******************************************************************************
110 * P U B L I C D A T A
111 *******************************************************************************
114 /* Definition of Wireless Extension */
116 #if WIRELESS_EXT > 12
117 #include <net/iw_handler.h>
118 #endif
119 //wireless extension helper functions
120 extern int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
121 extern int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
122 /* Wireless Extension Handler functions */
123 extern int usbdrvwext_giwname(struct net_device *dev, struct iw_request_info *info,
124 union iwreq_data *wrq, char *extra);
125 extern int usbdrvwext_siwfreq(struct net_device *dev, struct iw_request_info *info,
126 struct iw_freq *freq, char *extra);
127 extern int usbdrvwext_giwfreq(struct net_device *dev, struct iw_request_info *info,
128 struct iw_freq *freq, char *extra);
129 extern int usbdrvwext_siwmode(struct net_device *dev, struct iw_request_info *info,
130 union iwreq_data *wrq, char *extra);
131 extern int usbdrvwext_giwmode(struct net_device *dev, struct iw_request_info *info,
132 __u32 *mode, char *extra);
133 extern int usbdrvwext_siwsens(struct net_device *dev, struct iw_request_info *info,
134 struct iw_param *sens, char *extra);
135 extern int usbdrvwext_giwsens(struct net_device *dev, struct iw_request_info *info,
136 struct iw_param *sens, char *extra);
137 extern int usbdrvwext_giwrange(struct net_device *dev, struct iw_request_info *info,
138 struct iw_point *data, char *extra);
139 extern int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
140 struct sockaddr *MacAddr, char *extra);
141 extern int usbdrvwext_giwap(struct net_device *dev, struct iw_request_info *info,
142 struct sockaddr *MacAddr, char *extra);
143 extern int usbdrvwext_iwaplist(struct net_device *dev, struct iw_request_info *info,
144 struct iw_point *data, char *extra);
145 extern int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
146 struct iw_point *data, char *extra);
147 extern int usbdrvwext_giwscan(struct net_device *dev, struct iw_request_info *info,
148 struct iw_point *data, char *extra);
149 extern int usbdrvwext_siwessid(struct net_device *dev, struct iw_request_info *info,
150 struct iw_point *essid, char *extra);
151 extern int usbdrvwext_giwessid(struct net_device *dev, struct iw_request_info *info,
152 struct iw_point *essid, char *extra);
153 extern int usbdrvwext_siwnickn(struct net_device *dev, struct iw_request_info *info,
154 struct iw_point *data, char *nickname);
155 extern int usbdrvwext_giwnickn(struct net_device *dev, struct iw_request_info *info,
156 struct iw_point *data, char *nickname);
157 extern int usbdrvwext_siwrate(struct net_device *dev, struct iw_request_info *info,
158 struct iw_param *frq, char *extra);
159 extern int usbdrvwext_giwrate(struct net_device *dev, struct iw_request_info *info,
160 struct iw_param *frq, char *extra);
161 extern int usbdrvwext_siwrts(struct net_device *dev, struct iw_request_info *info,
162 struct iw_param *rts, char *extra);
163 extern int usbdrvwext_giwrts(struct net_device *dev, struct iw_request_info *info,
164 struct iw_param *rts, char *extra);
165 extern int usbdrvwext_siwfrag(struct net_device *dev, struct iw_request_info *info,
166 struct iw_param *frag, char *extra);
167 extern int usbdrvwext_giwfrag(struct net_device *dev, struct iw_request_info *info,
168 struct iw_param *frag, char *extra);
169 extern int usbdrvwext_siwtxpow(struct net_device *dev, struct iw_request_info *info,
170 struct iw_param *rrq, char *extra);
171 extern int usbdrvwext_giwtxpow(struct net_device *dev, struct iw_request_info *info,
172 struct iw_param *rrq, char *extra);
173 extern int usbdrvwext_siwretry(struct net_device *dev, struct iw_request_info *info,
174 struct iw_param *rrq, char *extra);
175 extern int usbdrvwext_giwretry(struct net_device *dev, struct iw_request_info *info,
176 struct iw_param *rrq, char *extra);
177 extern int usbdrvwext_siwencode(struct net_device *dev, struct iw_request_info *info,
178 struct iw_point *erq, char *key);
179 extern int usbdrvwext_giwencode(struct net_device *dev, struct iw_request_info *info,
180 struct iw_point *erq, char *key);
181 extern int usbdrvwext_siwpower(struct net_device *dev, struct iw_request_info *info,
182 struct iw_param *frq, char *extra);
183 extern int usbdrvwext_giwpower(struct net_device *dev, struct iw_request_info *info,
184 struct iw_param *frq, char *extra);
185 extern int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
187 * Structures to export the Wireless Handlers
190 struct iw_priv_args usbdrv_private_args[] = {
191 // { SIOCIWFIRSTPRIV + 0x0, 0, 0, "list_bss" },
192 // { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
193 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_auth" }, /* 0 - open, 1 - shared key */
194 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_CHAR | 12, "get_auth" },
195 // { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble" }, /* 0 - long, 1 - short */
196 // { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_CHAR | 6, "get_preamble" },
197 // { SIOCIWFIRSTPRIV + 0x6, 0, 0, "cnt" },
198 // { SIOCIWFIRSTPRIV + 0x7, 0, 0, "regs" },
199 // { SIOCIWFIRSTPRIV + 0x8, 0, 0, "probe" },
200 // { SIOCIWFIRSTPRIV + 0x9, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dbg_flag" },
201 // { SIOCIWFIRSTPRIV + 0xA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "connect" },
202 // { SIOCIWFIRSTPRIV + 0xB, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_mac_mode" },
203 // { SIOCIWFIRSTPRIV + 0xC, 0, IW_PRIV_TYPE_CHAR | 12, "get_mac_mode" },
206 #if WIRELESS_EXT > 12
207 static iw_handler usbdrvwext_handler[] = {
208 (iw_handler) NULL, /* SIOCSIWCOMMIT */
209 (iw_handler) usbdrvwext_giwname, /* SIOCGIWNAME */
210 (iw_handler) NULL, /* SIOCSIWNWID */
211 (iw_handler) NULL, /* SIOCGIWNWID */
212 (iw_handler) usbdrvwext_siwfreq, /* SIOCSIWFREQ */
213 (iw_handler) usbdrvwext_giwfreq, /* SIOCGIWFREQ */
214 (iw_handler) usbdrvwext_siwmode, /* SIOCSIWMODE */
215 (iw_handler) usbdrvwext_giwmode, /* SIOCGIWMODE */
216 (iw_handler) usbdrvwext_siwsens, /* SIOCSIWSENS */
217 (iw_handler) usbdrvwext_giwsens, /* SIOCGIWSENS */
218 (iw_handler) NULL, /* not used */ /* SIOCSIWRANGE */
219 (iw_handler) usbdrvwext_giwrange, /* SIOCGIWRANGE */
220 (iw_handler) NULL, /* not used */ /* SIOCSIWPRIV */
221 (iw_handler) NULL, /* kernel code */ /* SIOCGIWPRIV */
222 (iw_handler) NULL, /* not used */ /* SIOCSIWSTATS */
223 (iw_handler) NULL, /* kernel code */ /* SIOCGIWSTATS */
224 (iw_handler) NULL, /* SIOCSIWSPY */
225 (iw_handler) NULL, /* SIOCGIWSPY */
226 (iw_handler) NULL, /* -- hole -- */
227 (iw_handler) NULL, /* -- hole -- */
228 (iw_handler) usbdrvwext_siwap, /* SIOCSIWAP */
229 (iw_handler) usbdrvwext_giwap, /* SIOCGIWAP */
230 (iw_handler) NULL, /* -- hole -- */
231 (iw_handler) usbdrvwext_iwaplist, /* SIOCGIWAPLIST */
232 #if WIRELESS_EXT > 13
233 (iw_handler) usbdrvwext_siwscan, /* SIOCSIWSCAN */
234 (iw_handler) usbdrvwext_giwscan, /* SIOCGIWSCAN */
235 #else /* WIRELESS_EXT > 13 */
236 (iw_handler) NULL, /* null */ /* SIOCSIWSCAN */
237 (iw_handler) NULL, /* null */ /* SIOCGIWSCAN */
238 #endif /* WIRELESS_EXT > 13 */
239 (iw_handler) usbdrvwext_siwessid, /* SIOCSIWESSID */
240 (iw_handler) usbdrvwext_giwessid, /* SIOCGIWESSID */
242 (iw_handler) usbdrvwext_siwnickn, /* SIOCSIWNICKN */
243 (iw_handler) usbdrvwext_giwnickn, /* SIOCGIWNICKN */
244 (iw_handler) NULL, /* -- hole -- */
245 (iw_handler) NULL, /* -- hole -- */
246 (iw_handler) usbdrvwext_siwrate, /* SIOCSIWRATE */
247 (iw_handler) usbdrvwext_giwrate, /* SIOCGIWRATE */
248 (iw_handler) usbdrvwext_siwrts, /* SIOCSIWRTS */
249 (iw_handler) usbdrvwext_giwrts, /* SIOCGIWRTS */
250 (iw_handler) usbdrvwext_siwfrag, /* SIOCSIWFRAG */
251 (iw_handler) usbdrvwext_giwfrag, /* SIOCGIWFRAG */
252 (iw_handler) usbdrvwext_siwtxpow, /* SIOCSIWTXPOW */
253 (iw_handler) usbdrvwext_giwtxpow, /* SIOCGIWTXPOW */
254 (iw_handler) usbdrvwext_siwretry, /* SIOCSIWRETRY */
255 (iw_handler) usbdrvwext_giwretry, /* SIOCGIWRETRY */
256 (iw_handler) usbdrvwext_siwencode, /* SIOCSIWENCODE */
257 (iw_handler) usbdrvwext_giwencode, /* SIOCGIWENCODE */
258 (iw_handler) usbdrvwext_siwpower, /* SIOCSIWPOWER */
259 (iw_handler) usbdrvwext_giwpower, /* SIOCGIWPOWER */
262 static const iw_handler usbdrv_private_handler[] =
264 //(iw_handler) usbdrvwext_setparam, /* SIOCWFIRSTPRIV+0 */
265 //(iw_handler) usbdrvwext_getparam, /* SIOCWFIRSTPRIV+1 */
266 //(iw_handler) usbdrvwext_setkey, /* SIOCWFIRSTPRIV+2 */
267 //(iw_handler) usbdrvwext_setwmmparams, /* SIOCWFIRSTPRIV+3 */
268 //(iw_handler) usbdrvwext_delkey, /* SIOCWFIRSTPRIV+4 */
269 //(iw_handler) usbdrvwext_getwmmparams, /* SIOCWFIRSTPRIV+5 */
270 //(iw_handler) usbdrvwext_setmlme, /* SIOCWFIRSTPRIV+6 */
271 //(iw_handler) usbdrvwext_getchaninfo, /* SIOCWFIRSTPRIV+7 */
272 //(iw_handler) usbdrvwext_setoptie, /* SIOCWFIRSTPRIV+8 */
273 //(iw_handler) usbdrvwext_getoptie, /* SIOCWFIRSTPRIV+9 */
274 //(iw_handler) usbdrvwext_addmac, /* SIOCWFIRSTPRIV+10 */
275 //(iw_handler) usbdrvwext_getscanresults, /* SIOCWFIRSTPRIV+11 */
276 //(iw_handler) usbdrvwext_delmac, /* SIOCWFIRSTPRIV+12 */
277 //(iw_handler) usbdrvwext_getchanlist, /* SIOCWFIRSTPRIV+13 */
278 //(iw_handler) usbdrvwext_setchanlist, /* SIOCWFIRSTPRIV+14 */
279 //(iw_handler) NULL, /* SIOCWFIRSTPRIV+15 */
280 //(iw_handler) usbdrvwext_chanswitch, /* SIOCWFIRSTPRIV+16 */
281 //(iw_handler) usbdrvwext_setmode, /* SIOCWFIRSTPRIV+17 */
282 //(iw_handler) usbdrvwext_getmode, /* SIOCWFIRSTPRIV+18 */
283 NULL, /* SIOCIWFIRSTPRIV */
286 static struct iw_handler_def p80211wext_handler_def = {
287 .num_standard = sizeof(usbdrvwext_handler) / sizeof(iw_handler),
288 .num_private = sizeof(usbdrv_private_handler)/sizeof(iw_handler),
289 .num_private_args = sizeof(usbdrv_private_args)/sizeof(struct iw_priv_args),
290 .standard = usbdrvwext_handler,
291 .private = (iw_handler *) usbdrv_private_handler,
292 .private_args = (struct iw_priv_args *) usbdrv_private_args
294 #endif
296 /* WDS */
297 //struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER];
298 //void zfInitWdsStruct(void);
300 /* VAP */
301 struct zsVapStruct vap[ZM_VAP_PORT_NUMBER];
302 void zfLnxInitVapStruct(void);
306 * usbdrv_intr - interrupt handler
307 * @irq: the IRQ number
308 * @dev_inst: the net_device struct
309 * @regs: registers (unused)
311 * This routine is the ISR for the usbdrv board. It services
312 * the RX & TX queues & starts the RU if it has stopped due
313 * to no resources.
315 irqreturn_t usbdrv_intr(int irq, void *dev_inst, struct pt_regs *regs)
317 struct net_device *dev;
318 struct usbdrv_private *macp;
320 dev = dev_inst;
321 macp = dev->ml_priv;
324 /* Read register error, card may be unpluged */
325 if (0)//(intr_status == -1)
326 return IRQ_NONE;
328 /* the device is closed, don't continue or else bad things may happen. */
329 if (!netif_running(dev)) {
330 return IRQ_NONE;
333 if (macp->driver_isolated) {
334 return IRQ_NONE;
337 #if (WLAN_HOSTIF == WLAN_PCI)
338 //zfiIsrPci(dev);
339 #endif
341 return IRQ_HANDLED;
344 int usbdrv_open(struct net_device *dev)
346 struct usbdrv_private *macp = dev->ml_priv;
347 int rc = 0;
348 u16_t size;
349 void* mem;
350 //unsigned char addr[6];
351 struct zsCbFuncTbl cbFuncTbl;
353 printk("Enter open()\n");
355 //#ifndef CONFIG_SMP
356 // read_lock(&(macp->isolate_lock));
357 //#endif
358 if (macp->driver_isolated) {
359 rc = -EBUSY;
360 goto exit;
363 size = zfiGlobalDataSize(dev);
364 if ((mem = kmalloc(size, GFP_KERNEL)) == NULL)
366 rc = -EBUSY;
367 goto exit;
369 macp->wd = mem;
371 memset(&cbFuncTbl, 0, sizeof(struct zsCbFuncTbl));
372 cbFuncTbl.zfcbAuthNotify = zfLnxAuthNotify;
373 cbFuncTbl.zfcbAuthNotify = zfLnxAuthNotify;
374 cbFuncTbl.zfcbAsocNotify = zfLnxAsocNotify;
375 cbFuncTbl.zfcbDisAsocNotify = zfLnxDisAsocNotify;
376 cbFuncTbl.zfcbApConnectNotify = zfLnxApConnectNotify;
377 cbFuncTbl.zfcbConnectNotify = zfLnxConnectNotify;
378 cbFuncTbl.zfcbScanNotify = zfLnxScanNotify;
379 cbFuncTbl.zfcbMicFailureNotify = zfLnxMicFailureNotify;
380 cbFuncTbl.zfcbApMicFailureNotify = zfLnxApMicFailureNotify;
381 cbFuncTbl.zfcbIbssPartnerNotify = zfLnxIbssPartnerNotify;
382 cbFuncTbl.zfcbMacAddressNotify = zfLnxMacAddressNotify;
383 cbFuncTbl.zfcbSendCompleteIndication = zfLnxSendCompleteIndication;
384 cbFuncTbl.zfcbRecvEth = zfLnxRecvEth;
385 cbFuncTbl.zfcbRecv80211 = zfLnxRecv80211;
386 cbFuncTbl.zfcbRestoreBufData = zfLnxRestoreBufData;
387 #ifdef ZM_ENABLE_CENC
388 cbFuncTbl.zfcbCencAsocNotify = zfLnxCencAsocNotify;
389 #endif //ZM_ENABLE_CENC
390 cbFuncTbl.zfcbHwWatchDogNotify = zfLnxWatchDogNotify;
391 zfiWlanOpen(dev, &cbFuncTbl);
393 #if 0
395 //u16_t mac[3] = {0x1300, 0xb6d4, 0x5aaf};
396 u16_t mac[3] = {0x8000, 0x00ab, 0x0000};
397 //zfiWlanSetMacAddress(dev, mac);
399 /* MAC address */
400 zfiWlanQueryMacAddress(dev, addr);
401 dev->dev_addr[0] = addr[0];
402 dev->dev_addr[1] = addr[1];
403 dev->dev_addr[2] = addr[2];
404 dev->dev_addr[3] = addr[3];
405 dev->dev_addr[4] = addr[4];
406 dev->dev_addr[5] = addr[5];
407 #endif
408 //zfwMacAddressNotify() will be called to setup dev->dev_addr[]
410 zfLnxCreateThread(dev);
412 mod_timer(&(macp->hbTimer10ms), jiffies + (1*HZ)/100); //10 ms
414 netif_carrier_on(dev);
416 netif_start_queue(dev);
418 #if ZM_AP_MODE == 1
419 zfiWlanSetWlanMode(dev, ZM_MODE_AP);
420 zfiWlanSetBasicRate(dev, 0xf, 0, 0);
421 zfiWlanSetSSID(dev, "OTUS_CWY", 8);
422 zfiWlanSetDtimCount(dev, 3);
424 #if ZM_WEP_MOME == 1
426 u8_t key[16] = {0x12, 0x34, 0x56, 0x78, 0x90};
427 struct zsKeyInfo keyInfo;
429 keyInfo.keyLength = 5;
430 keyInfo.keyIndex = 0;
431 keyInfo.flag = 0;
432 keyInfo.key = key;
433 zfiWlanSetKey(dev, keyInfo);
435 zfiWlanSetEncryMode(dev, ZM_WEP64);
438 #if ZM_SHARE_AUTH == 1
439 zfiWlanSetAuthenticationMode(dev, 1);
440 #endif //#if ZM_SHARE_AUTH == 1
441 #endif //#if ZM_WEP_MOME == 1
443 #elif ZM_PIBSS_MODE == 1
444 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
445 #else
446 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
447 #endif
448 //zfiWlanSetChannel(dev, ZM_CHANNEL, FALSE);
449 zfiWlanSetFrequency(dev, 2462000, FALSE);
450 zfiWlanSetRtsThreshold(dev, 32767);
451 zfiWlanSetFragThreshold(dev, 0);
453 zfiWlanEnable(dev);
455 #ifdef ZM_ENABLE_CENC
456 macp->netlink_sk = netlink_kernel_create(NETLINK_USERSOCK, 1, NULL, THIS_MODULE);
458 if (macp->netlink_sk == NULL)
460 printk(KERN_ERR "Can't create NETLINK socket\n");
462 #endif
464 macp->DeviceOpened = 1;
465 exit:
466 //#ifndef CONFIG_SMP
467 // read_unlock(&(macp->isolate_lock));
468 //#endif
469 //zfRegisterWdsDev(dev, 0);
470 //zfLnxRegisterVapDev(dev, 0);
472 return rc;
479 * usbdrv_get_stats - get driver statistics
480 * @dev: adapter's net_device struct
482 * This routine is called when the OS wants the adapter's stats returned.
483 * It returns the address of the net_device_stats stucture for the device.
484 * If the statistics are currently being updated, then they might be incorrect
485 * for a short while. However, since this cannot actually cause damage, no
486 * locking is used.
489 struct net_device_stats * usbdrv_get_stats(struct net_device *dev)
491 struct usbdrv_private *macp = dev->ml_priv;
493 macp->drv_stats.net_stats.tx_errors =
494 macp->drv_stats.net_stats.tx_carrier_errors +
495 macp->drv_stats.net_stats.tx_aborted_errors;
497 macp->drv_stats.net_stats.rx_errors =
498 macp->drv_stats.net_stats.rx_crc_errors +
499 macp->drv_stats.net_stats.rx_frame_errors +
500 macp->drv_stats.net_stats.rx_length_errors;
503 return &(macp->drv_stats.net_stats);
508 * usbdrv_set_mac - set the MAC address
509 * @dev: adapter's net_device struct
510 * @addr: the new address
512 * This routine sets the ethernet address of the board
513 * Returns:
514 * 0 - if successful
515 * -1 - otherwise
518 int usbdrv_set_mac(struct net_device *dev, void *addr)
520 struct usbdrv_private *macp;
521 int rc = -1;
523 macp = dev->ml_priv;
524 read_lock(&(macp->isolate_lock));
526 if (macp->driver_isolated) {
527 goto exit;
530 rc = 0;
533 exit:
534 read_unlock(&(macp->isolate_lock));
535 return rc;
540 void
541 usbdrv_isolate_driver(struct usbdrv_private *macp)
543 #ifndef CONFIG_SMP
544 write_lock_irq(&(macp->isolate_lock));
545 #endif
546 macp->driver_isolated = TRUE;
547 #ifndef CONFIG_SMP
548 write_unlock_irq(&(macp->isolate_lock));
549 #endif
551 if (netif_running(macp->device))
553 netif_carrier_off(macp->device);
554 netif_stop_queue(macp->device);
558 #define VLAN_SIZE 4
559 int usbdrv_change_mtu(struct net_device *dev, int new_mtu)
561 if ((new_mtu < 68) || (new_mtu > (ETH_DATA_LEN + VLAN_SIZE)))
562 return -EINVAL;
564 dev->mtu = new_mtu;
565 return 0;
568 void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp);
570 int usbdrv_close(struct net_device *dev)
572 extern void zfHpLedCtrl(struct net_device *dev, u16_t ledId, u8_t mode);
574 struct usbdrv_private *macp = dev->ml_priv;
576 printk(KERN_DEBUG "usbdrv_close\n");
578 netif_carrier_off(macp->device);
580 del_timer_sync(&macp->hbTimer10ms);
582 printk(KERN_DEBUG "usbdrv_netif_carrier_off\n");
584 usbdrv_isolate_driver(macp);
586 printk(KERN_DEBUG "usbdrv_isolate_driver\n");
588 netif_carrier_off(macp->device);
589 #ifdef ZM_ENABLE_CENC
590 /* CENC */
591 if (macp->netlink_sk != NULL)
593 // sock_release(macp->netlink_sk);
594 printk(KERN_ERR "usbdrv close netlink socket\n");
596 #endif //ZM_ENABLE_CENC
597 #if (WLAN_HOSTIF == WLAN_PCI)
598 //free_irq(dev->irq, dev);
599 #endif
601 /* Turn off LED */
602 zfHpLedCtrl(dev, 0, 0);
603 zfHpLedCtrl(dev, 1, 0);
605 /* Delay for a while */
606 mdelay(10);
608 /* clear WPA/RSN IE */
609 macp->supIe[1] = 0;
611 /* set the isolate flag to false, so usbdrv_open can be called */
612 macp->driver_isolated = FALSE;
614 zfiWlanClose(dev);
615 kfree(macp->wd);
617 zfLnxUnlinkAllUrbs(macp);
619 return 0;
625 int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev)
627 int notify_stop = FALSE;
628 struct usbdrv_private *macp = dev->ml_priv;
630 #if 0
631 /* Test code */
633 struct sk_buff* s;
635 s = skb_copy_expand(skb, 8, 0, GFP_ATOMIC);
636 skb_push(s, 8);
637 s->data[0] = 'z';
638 s->data[1] = 'y';
639 s->data[2] = 'd';
640 s->data[3] = 'a';
641 s->data[4] = 's';
642 printk("len1=%d, len2=%d", skb->len, s->len);
643 netlink_broadcast(rtnl, s, 0, RTMGRP_LINK, GFP_ATOMIC);
645 #endif
647 #if ZM_DISABLE_XMIT
648 dev_kfree_skb_irq(skb);
649 #else
650 zfiTxSendEth(dev, skb, 0);
651 #endif
652 macp->drv_stats.net_stats.tx_bytes += skb->len;
653 macp->drv_stats.net_stats.tx_packets++;
655 //dev_kfree_skb_irq(skb);
657 if (notify_stop) {
658 netif_carrier_off(dev);
659 netif_stop_queue(dev);
662 return 0;
668 void usbdrv_set_multi(struct net_device *dev)
672 if (!(dev->flags & IFF_UP))
673 return;
675 return;
682 * usbdrv_clear_structs - free resources
684 * @dev: adapter's net_device struct
686 * Free all device specific structs, unmap i/o address, etc.
688 void usbdrv_clear_structs(struct net_device *dev)
690 struct usbdrv_private *macp = dev->ml_priv;
693 #if (WLAN_HOSTIF == WLAN_PCI)
694 iounmap(macp->regp);
696 pci_release_regions(macp->pdev);
697 pci_disable_device(macp->pdev);
698 pci_set_drvdata(macp->pdev, NULL);
699 #endif
701 kfree(macp);
703 kfree(dev);
707 void usbdrv_remove1(struct pci_dev *pcid)
709 struct net_device *dev;
710 struct usbdrv_private *macp;
712 if (!(dev = (struct net_device *) pci_get_drvdata(pcid)))
713 return;
715 macp = dev->ml_priv;
716 unregister_netdev(dev);
718 usbdrv_clear_structs(dev);
722 void zfLnx10msTimer(struct net_device* dev)
724 struct usbdrv_private *macp = dev->ml_priv;
726 mod_timer(&(macp->hbTimer10ms), jiffies + (1*HZ)/100); //10 ms
727 zfiHeartBeat(dev);
728 return;
731 void zfLnxInitVapStruct(void)
733 u16_t i;
735 for (i=0; i<ZM_VAP_PORT_NUMBER; i++)
737 vap[i].dev = NULL;
738 vap[i].openFlag = 0;
742 int zfLnxVapOpen(struct net_device *dev)
744 u16_t vapId;
746 vapId = zfLnxGetVapId(dev);
748 if (vap[vapId].openFlag == 0)
750 vap[vapId].openFlag = 1;
751 printk("zfLnxVapOpen : device name=%s, vap ID=%d\n", dev->name, vapId);
752 zfiWlanSetSSID(dev, "vap1", 4);
753 zfiWlanEnable(dev);
754 netif_start_queue(dev);
756 else
758 printk("VAP opened error : vap ID=%d\n", vapId);
760 return 0;
763 int zfLnxVapClose(struct net_device *dev)
765 u16_t vapId;
767 vapId = zfLnxGetVapId(dev);
769 if (vapId != 0xffff)
771 if (vap[vapId].openFlag == 1)
773 printk("zfLnxVapClose: device name=%s, vap ID=%d\n", dev->name, vapId);
775 netif_stop_queue(dev);
776 vap[vapId].openFlag = 0;
778 else
780 printk("VAP port was not opened : vap ID=%d\n", vapId);
783 return 0;
786 int zfLnxVapXmitFrame(struct sk_buff *skb, struct net_device *dev)
788 int notify_stop = FALSE;
789 struct usbdrv_private *macp = dev->ml_priv;
790 u16_t vapId;
792 vapId = zfLnxGetVapId(dev);
793 //printk("zfLnxVapXmitFrame: vap ID=%d\n", vapId);
794 //printk("zfLnxVapXmitFrame(), skb=%lxh\n", (u32_t)skb);
796 if (vapId >= ZM_VAP_PORT_NUMBER)
798 dev_kfree_skb_irq(skb);
799 return 0;
801 #if 1
802 if (vap[vapId].openFlag == 0)
804 dev_kfree_skb_irq(skb);
805 return 0;
807 #endif
810 zfiTxSendEth(dev, skb, 0x1);
812 macp->drv_stats.net_stats.tx_bytes += skb->len;
813 macp->drv_stats.net_stats.tx_packets++;
815 //dev_kfree_skb_irq(skb);
817 if (notify_stop) {
818 netif_carrier_off(dev);
819 netif_stop_queue(dev);
822 return 0;
825 static const struct net_device_ops vap_netdev_ops = {
826 .ndo_open = zfLnxVapOpen,
827 .ndo_stop = zfLnxVapClose,
828 .ndo_start_xmit = zfLnxVapXmitFrame,
829 .ndo_get_stats = usbdrv_get_stats,
830 .ndo_change_mtu = usbdrv_change_mtu,
831 .ndo_validate_addr = eth_validate_addr,
832 .ndo_set_mac_address = eth_mac_addr,
833 #ifdef ZM_HOSTAPD_SUPPORT
834 .ndo_do_ioctl = usbdrv_ioctl,
835 #else
836 .ndo_do_ioctl = NULL,
837 #endif
840 int zfLnxRegisterVapDev(struct net_device* parentDev, u16_t vapId)
842 /* Allocate net device structure */
843 vap[vapId].dev = alloc_etherdev(0);
844 printk("Register vap dev=%x\n", (u32_t)vap[vapId].dev);
846 if(vap[vapId].dev == NULL) {
847 printk("alloc_etherdev fail\n");
848 return -ENOMEM;
851 /* Setup the default settings */
852 ether_setup(vap[vapId].dev);
854 /* MAC address */
855 memcpy(vap[vapId].dev->dev_addr, parentDev->dev_addr, ETH_ALEN);
857 vap[vapId].dev->irq = parentDev->irq;
858 vap[vapId].dev->base_addr = parentDev->base_addr;
859 vap[vapId].dev->mem_start = parentDev->mem_start;
860 vap[vapId].dev->mem_end = parentDev->mem_end;
861 vap[vapId].dev->ml_priv = parentDev->ml_priv;
863 //dev->hard_start_xmit = &zd1212_wds_xmit_frame;
864 vap[vapId].dev->netdev_ops = &vap_netdev_ops;
865 vap[vapId].dev->destructor = free_netdev;
867 vap[vapId].dev->tx_queue_len = 0;
869 vap[vapId].dev->dev_addr[0] = parentDev->dev_addr[0];
870 vap[vapId].dev->dev_addr[1] = parentDev->dev_addr[1];
871 vap[vapId].dev->dev_addr[2] = parentDev->dev_addr[2];
872 vap[vapId].dev->dev_addr[3] = parentDev->dev_addr[3];
873 vap[vapId].dev->dev_addr[4] = parentDev->dev_addr[4];
874 vap[vapId].dev->dev_addr[5] = parentDev->dev_addr[5] + (vapId+1);
876 /* Stop the network queue first */
877 netif_stop_queue(vap[vapId].dev);
879 sprintf(vap[vapId].dev->name, "vap%d", vapId);
880 printk("Register VAP dev success : %s\n", vap[vapId].dev->name);
882 if(register_netdevice(vap[vapId].dev) != 0) {
883 printk("register VAP device fail\n");
884 vap[vapId].dev = NULL;
885 return -EINVAL;
888 return 0;
891 int zfLnxUnregisterVapDev(struct net_device* parentDev, u16_t vapId)
893 int ret = 0;
895 printk("Unregister VAP dev : %s\n", vap[vapId].dev->name);
897 if(vap[vapId].dev != NULL) {
898 printk("Unregister vap dev=%x\n", (u32_t)vap[vapId].dev);
900 //unregister_netdevice(wds[wdsId].dev);
901 unregister_netdev(vap[vapId].dev);
903 printk("VAP unregister_netdevice\n");
904 vap[vapId].dev = NULL;
906 else {
907 printk("unregister VAP device: %d fail\n", vapId);
908 ret = -EINVAL;
911 return ret;
916 # define SUBMIT_URB(u,f) usb_submit_urb(u,f)
917 # define USB_ALLOC_URB(u,f) usb_alloc_urb(u,f)
919 //extern void zfiWlanQueryMacAddress(zdev_t* dev, u8_t* addr);
921 extern int usbdrv_open(struct net_device *dev);
922 extern int usbdrv_close(struct net_device *dev);
923 extern int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev);
924 extern int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev);
925 extern int usbdrv_change_mtu(struct net_device *dev, int new_mtu);
926 extern void usbdrv_set_multi(struct net_device *dev);
927 extern int usbdrv_set_mac(struct net_device *dev, void *addr);
928 extern struct net_device_stats * usbdrv_get_stats(struct net_device *dev);
929 extern int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
930 extern UsbTxQ_t *zfLnxGetUsbTxBuffer(struct net_device *dev);
932 int zfLnxAllocAllUrbs(struct usbdrv_private *macp)
934 struct usb_interface *interface = macp->interface;
935 struct usb_host_interface *iface_desc = &interface->altsetting[0];
937 struct usb_endpoint_descriptor *endpoint;
938 int i;
940 /* descriptor matches, let's find the endpoints needed */
941 /* check out the endpoints */
942 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
944 endpoint = &iface_desc->endpoint[i].desc;
945 if (usb_endpoint_is_bulk_in(endpoint))
947 /* we found a bulk in endpoint */
948 printk(KERN_ERR "bulk in: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
951 if (usb_endpoint_is_bulk_out(endpoint))
953 /* we found a bulk out endpoint */
954 printk(KERN_ERR "bulk out: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
957 if (usb_endpoint_is_int_in(endpoint))
959 /* we found a interrupt in endpoint */
960 printk(KERN_ERR "interrupt in: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
961 printk(KERN_ERR "interrupt in: int_interval = %d\n", endpoint->bInterval);
964 if (usb_endpoint_is_int_out(endpoint))
966 /* we found a interrupt out endpoint */
967 printk(KERN_ERR "interrupt out: wMaxPacketSize = %x\n", le16_to_cpu(endpoint->wMaxPacketSize));
968 printk(KERN_ERR "interrupt out: int_interval = %d\n", endpoint->bInterval);
972 /* Allocate all Tx URBs */
973 for (i = 0; i < ZM_MAX_TX_URB_NUM; i++)
975 macp->WlanTxDataUrb[i] = USB_ALLOC_URB(0, GFP_KERNEL);
977 if (macp->WlanTxDataUrb[i] == 0)
979 int j;
981 /* Free all urbs */
982 for (j = 0; j < i; j++)
984 usb_free_urb(macp->WlanTxDataUrb[j]);
987 return 0;
991 /* Allocate all Rx URBs */
992 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
994 macp->WlanRxDataUrb[i] = USB_ALLOC_URB(0, GFP_KERNEL);
996 if (macp->WlanRxDataUrb[i] == 0)
998 int j;
1000 /* Free all urbs */
1001 for (j = 0; j < i; j++)
1003 usb_free_urb(macp->WlanRxDataUrb[j]);
1006 for (j = 0; j < ZM_MAX_TX_URB_NUM; j++)
1008 usb_free_urb(macp->WlanTxDataUrb[j]);
1011 return 0;
1015 /* Allocate Register Read/Write USB */
1016 macp->RegOutUrb = USB_ALLOC_URB(0, GFP_KERNEL);
1017 macp->RegInUrb = USB_ALLOC_URB(0, GFP_KERNEL);
1019 return 1;
1022 void zfLnxFreeAllUrbs(struct usbdrv_private *macp)
1024 int i;
1026 /* Free all Tx URBs */
1027 for (i = 0; i < ZM_MAX_TX_URB_NUM; i++)
1029 if (macp->WlanTxDataUrb[i] != NULL)
1031 usb_free_urb(macp->WlanTxDataUrb[i]);
1035 /* Free all Rx URBs */
1036 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
1038 if (macp->WlanRxDataUrb[i] != NULL)
1040 usb_free_urb(macp->WlanRxDataUrb[i]);
1044 /* Free USB Register Read/Write URB */
1045 usb_free_urb(macp->RegOutUrb);
1046 usb_free_urb(macp->RegInUrb);
1049 void zfLnxUnlinkAllUrbs(struct usbdrv_private *macp)
1051 int i;
1053 /* Unlink all Tx URBs */
1054 for (i = 0; i < ZM_MAX_TX_URB_NUM; i++)
1056 if (macp->WlanTxDataUrb[i] != NULL)
1058 usb_unlink_urb(macp->WlanTxDataUrb[i]);
1062 /* Unlink all Rx URBs */
1063 for (i = 0; i < ZM_MAX_RX_URB_NUM; i++)
1065 if (macp->WlanRxDataUrb[i] != NULL)
1067 usb_unlink_urb(macp->WlanRxDataUrb[i]);
1071 /* Unlink USB Register Read/Write URB */
1072 usb_unlink_urb(macp->RegOutUrb);
1074 usb_unlink_urb(macp->RegInUrb);
1077 static const struct net_device_ops otus_netdev_ops = {
1078 .ndo_open = usbdrv_open,
1079 .ndo_stop = usbdrv_close,
1080 .ndo_start_xmit = usbdrv_xmit_frame,
1081 .ndo_change_mtu = usbdrv_change_mtu,
1082 .ndo_get_stats = usbdrv_get_stats,
1083 .ndo_set_multicast_list = usbdrv_set_multi,
1084 .ndo_set_mac_address = usbdrv_set_mac,
1085 .ndo_do_ioctl = usbdrv_ioctl,
1086 .ndo_validate_addr = eth_validate_addr,
1089 u8_t zfLnxInitSetup(struct net_device *dev, struct usbdrv_private *macp)
1091 //unsigned char addr[6];
1093 //init_MUTEX(&macp->ps_sem);
1094 //init_MUTEX(&macp->reg_sem);
1095 //init_MUTEX(&macp->bcn_sem);
1096 //init_MUTEX(&macp->config_sem);
1098 spin_lock_init(&(macp->cs_lock));
1099 #if 0
1100 /* MAC address */
1101 zfiWlanQueryMacAddress(dev, addr);
1102 dev->dev_addr[0] = addr[0];
1103 dev->dev_addr[1] = addr[1];
1104 dev->dev_addr[2] = addr[2];
1105 dev->dev_addr[3] = addr[3];
1106 dev->dev_addr[4] = addr[4];
1107 dev->dev_addr[5] = addr[5];
1108 #endif
1109 #if WIRELESS_EXT > 12
1110 dev->wireless_handlers = (struct iw_handler_def *)&p80211wext_handler_def;
1111 #endif
1113 dev->netdev_ops = &otus_netdev_ops;
1115 dev->flags |= IFF_MULTICAST;
1117 dev->dev_addr[0] = 0x00;
1118 dev->dev_addr[1] = 0x03;
1119 dev->dev_addr[2] = 0x7f;
1120 dev->dev_addr[3] = 0x11;
1121 dev->dev_addr[4] = 0x22;
1122 dev->dev_addr[5] = 0x33;
1124 /* Initialize Heart Beat timer */
1125 init_timer(&macp->hbTimer10ms);
1126 macp->hbTimer10ms.data = (unsigned long)dev;
1127 macp->hbTimer10ms.function = (void *)&zfLnx10msTimer;
1129 /* Initialize WDS and VAP data structure */
1130 //zfInitWdsStruct();
1131 zfLnxInitVapStruct();
1133 return 1;
1136 u8_t zfLnxClearStructs(struct net_device *dev)
1138 u16_t ii;
1139 u16_t TxQCnt;
1141 TxQCnt = zfLnxCheckTxBufferCnt(dev);
1143 printk(KERN_ERR "TxQCnt: %d\n", TxQCnt);
1145 for(ii = 0; ii < TxQCnt; ii++)
1147 UsbTxQ_t *TxQ = zfLnxGetUsbTxBuffer(dev);
1149 printk(KERN_ERR "dev_kfree_skb_any\n");
1150 /* Free buffer */
1151 dev_kfree_skb_any(TxQ->buf);
1154 return 0;