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