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