5 * Copyright (C) 2004 ZyDAS Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * -------------------------------------------------------------------- */
32 #define __KERNEL_SYSCALLS__
34 #include <linux/config.h>
35 #include <net/checksum.h>
36 #include <linux/tcp.h>
37 #include <linux/udp.h>
40 #include <linux/stat.h>
43 #include "zdinlinef.h"
46 #include "menu_drv_macro.h"
59 #include <net/iw_handler.h>
62 #if ZDCONF_LP_SUPPORT == 1
64 #include "zdturbo_burst.h"
69 extern U16 mTmRetryConnect
;
70 extern BOOLEAN mProbeWithSsid
;
74 extern Element dot11DesiredSsid
;
76 extern u8 mCurrConnUser
;
77 extern U8 mNumBOnlySta
;
80 extern U8 mKeyFormat
; //Init value: WEP64_USED(1)
81 extern BOOLEAN mPrivacyInvoked
; // Init value: FALSE
82 extern U8 mKeyVector
[4][16]; // Store WEP key
84 extern U8 mKeyId
; // Init value: 0
85 extern U16 mCap
; // Init value: CAP_ESS(1);
86 extern u16 CurrScanCH
;
87 extern MacAddr_t dot11MacAddress
;
89 extern BOOLEAN
zd_CmdProbeReq(U8 bWithSSID
);
90 extern Hash_t
*HashSearch(MacAddr_t
*pMac
);
91 extern void re_initFdescBuf(void);
92 /******************************************************************************
94 *******************************************************************************
98 static u8 ZD_SNAP_HEADER
[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
99 static u8 ZD_SNAP_BRIDGE_TUNNEL
[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
100 static u8 zd_Snap_Apple_Type
[] = {0xAA,0xAA,0x03,0x08,0x00,0x07,0x80,0x9b};
101 //Slow Pairwise key install issue is casued by a too fast response 1/2
102 //group key update before PTK is installed. The gorup update is discarded
103 //caused key update fails.
104 //<Slow Pairwise Key Install Fix>
105 static u8 ZD_SNAP_EAPOL
[] = {0xAA,0xAA,0xAA,0x03, 0x00,0x00,0x00, 0x88,0x8E};
106 //</Slow Pairwise Key Install Fix>
108 static u16 IPX
=0x8137;
109 //static u16 NOVELL=0xe0e0;
110 static u16 APPLE_TALK
=0x80f3;
111 static u16 EAPOL
=0x888e;
115 #define MAX_MULTICAST_ADDRS 32
116 #define NUM_WEPKEYS 4
118 #define bGroup(pWlanHdr) (pWlanHdr->Address1[0] & BIT_0)
119 #define getSeq(pWlanHdr) (((u16)pWlanHdr->SeqCtrl[1] << 4) + (u16)((pWlanHdr->SeqCtrl[0] & 0xF0) >> 4))
120 #define getFrag(pWlanHdr) (pWlanHdr->SeqCtrl[0] & 0x0F)
121 #define getTA(pWlanHdr) (&pWlanHdr->Address2[0])
122 #define isWDS(pWlanHdr) (((pWlanHdr->FrameCtrl[1] & TO_DS_FROM_DS) == TO_DS_FROM_DS) ? 1 : 0)
123 #define bRetryBit(pWlanHdr) (pWlanHdr->FrameCtrl[1] & RETRY_BIT)
124 #define bWepBit(pWlanHdr) (pWlanHdr->FrameCtrl[1] & ENCRY_BIT)
125 #define bMoreFrag(pWlanHdr) (pWlanHdr->FrameCtrl[1] & MORE_FRAG)
126 #define bMoreData(pWlanHdr) (pWlanHdr->FrameCtrl[1] & MORE_DATA)
127 #define BaseFrameType(pWlanHdr) (pWlanHdr->FrameCtrl[0] & 0x0C)
128 #define SubFrameType(pWlanHdr) (pWlanHdr->FrameCtrl[0])
129 #define bDataMgtFrame(pWlanHdr) (((pWlanHdr->FrameCtrl[0] & 0x04) == 0))
131 #define nowT() (zd_readl(TSF_LowPart)) //us unit
133 #define nowT() (jiffies) //tick (10ms) unit
135 /******************************************************************************
136 * F U N C T I O N D E C L A R A T I O N S
137 *******************************************************************************
139 #ifdef CONFIG_PROC_FS
140 extern int zd1205_create_proc_subdir(struct zd1205_private
*);
141 extern void zd1205_remove_proc_subdir(struct zd1205_private
*);
143 #define zd1205_create_proc_subdir(X) 0
144 #define zd1205_remove_proc_subdir(X) do {} while(0)
146 static u32
channel_11A_to_Freq(const u32 channel
);
147 //static u32 Freq_11A_to_channel(const u32 freq);
150 static unsigned char zd1205_alloc_space(struct zd1205_private
*);
151 unsigned char zd1205_init(struct zd1205_private
*);
152 static void zd1205_setup_tcb_pool(struct zd1205_private
*macp
);
153 static void zd1205_config(struct zd1205_private
*macp
);
154 static void zd1205_rd_eaddr(struct zd1205_private
*);
155 int zd1205_open(struct net_device
*);
156 int zd1205_close(struct net_device
*);
157 int zd1205_change_mtu(struct net_device
*, int);
158 int zd1205_set_mac(struct net_device
*, void *);
159 void zd1205_set_multi(struct net_device
*);
160 struct net_device_stats
*zd1205_get_stats(struct net_device
*);
161 static int zd1205_alloc_tcb_pool(struct zd1205_private
*);
162 static void zd1205_free_tcb_pool(struct zd1205_private
*);
163 static int zd1205_alloc_rfd_pool(struct zd1205_private
*);
164 static void zd1205_free_rfd_pool(struct zd1205_private
*);
165 static void zd1205_clear_pools(struct zd1205_private
*macp
);
166 zd1205_SwTcb_t
* zd1205_first_txq(struct zd1205_private
*macp
, zd1205_SwTcbQ_t
*Q
);
167 void zd1205_qlast_txq(struct zd1205_private
*macp
, zd1205_SwTcbQ_t
*Q
, zd1205_SwTcb_t
*signal
);
168 static void zd1205_init_txq(struct zd1205_private
*macp
, zd1205_SwTcbQ_t
*Q
);
171 static u8
zd1205_pci_setup(struct pci_dev
*, struct zd1205_private
*);
172 static void zd1205_intr(int, void *, struct pt_regs
*);
173 static void zd1205_retry_failed(struct zd1205_private
*);
174 static void zd1205_dtim_notify(struct zd1205_private
*);
175 void zd1205_start_ru(struct zd1205_private
*);
176 u8
zd1205_RateAdaption(u16 aid
, u8 CurrentRate
, u8 gear
);
178 struct rx_list_elem
*zd1205_start_ru(struct zd1205_private
*);
181 u32
zd1205_rx_isr(struct zd1205_private
*macp
);
182 void zd1205_tx_isr(struct zd1205_private
*);
183 static void zd1205_transmit_cleanup(struct zd1205_private
*, zd1205_SwTcb_t
*sw_tcb
);
184 static int zd1205_validate_frame(struct zd1205_private
*macp
, zd1205_RFD_t
*rfd
);
185 int zd1205_xmit_frame(struct sk_buff
*, struct net_device
*);
186 static void zd1205_dealloc_space(struct zd1205_private
*macp
);
187 void zd1205_disable_int(void);
188 void zd1205_enable_int(void);
189 void zd1205_config_wep_keys(struct zd1205_private
*macp
);
190 void HKeepingCB(struct net_device
*dev
);
191 void zd1205_mgt_mon_cb(struct net_device
*dev
);
192 void zd1205_lp_poll_cb(struct net_device
*dev
);
193 void zd1205_process_wakeup(struct zd1205_private
*macp
);
194 void zd1205_device_reset(struct zd1205_private
*macp
);
195 int zd1205_DestPowerSave(struct zd1205_private
*macp
, u8
*pDestAddr
);
197 void zd1205_recycle_rx(struct zd1205_private
*macp
);
200 u8
CalculateStrength(struct zd1205_private
*macp
, zd1205_RFD_t
*rfd
);
201 u8
CalculateQuality(struct zd1205_private
*macp
, zd1205_RFD_t
*rfd
, u8
*pQualityIndB
);
202 void zd1205_initCAM(struct zd1205_private
*macp
);
203 int zd1205_CheckOverlapBss(struct zd1205_private
*macp
, plcp_wla_Header_t
*pWlanHdr
, u8
*pMacBody
, u32 bodyLen
);
204 void zd1205_HandleQosRequest(struct zd1205_private
*macp
);
205 void zd1205_SetRatesInfo(struct zd1205_private
*macp
);
207 u8
X_To_dB(u32 X
, u8 rate
);
208 u16
ZDLog10multiply100(int data
);
209 void zd1205_connect_mon(struct zd1205_private
*macp
);
211 //wireless extension helper functions
212 void zd1205_lock(struct zd1205_private
*macp
);
213 void zd1205_unlock(struct zd1205_private
*macp
);
214 static int zd1205_ioctl_setiwencode(struct net_device
*dev
, struct iw_point
*erq
, char* key
);
215 static int zd1205_ioctl_getiwencode(struct net_device
*dev
, struct iw_point
*erq
, char* key
);
216 static int zd1205_ioctl_setessid(struct net_device
*dev
, struct iw_point
*erq
);
217 static int zd1205_ioctl_setbssid(struct net_device
*dev
, struct iwreq
*wrq
);
219 static int zd1205_ioctl_getessid(struct net_device
*dev
, struct iw_point
*erq
);
220 static int zd1205_ioctl_setfreq(struct net_device
*dev
, struct iw_freq
*frq
);
221 //static int zd1205_ioctl_setsens(struct net_device *dev, struct iw_param *srq);
222 static int zd1205_ioctl_setrts(struct net_device
*dev
, struct iw_param
*rrq
);
223 static int zd1205_ioctl_setfrag(struct net_device
*dev
, struct iw_param
*frq
);
225 static int zd1205_ioctl_getfrag(struct net_device
*dev
, struct iw_param
*frq
);
226 static int zd1205_ioctl_setrate(struct net_device
*dev
, struct iw_param
*frq
);
227 static int zd1205_ioctl_getrate(struct net_device
*dev
, struct iw_param
*frq
);
228 static int zd1205_ioctl_settxpower(struct net_device
*dev
, struct iw_param
*prq
);
229 static int zd1205_ioctl_gettxpower(struct net_device
*dev
, struct iw_param
*prq
);
230 static int zd1205_ioctl_setpower(struct net_device
*dev
, struct iw_param
*prq
);
231 static int zd1205_ioctl_getpower(struct net_device
*dev
, struct iw_param
*prq
);
232 static int zd1205_ioctl_setmode(struct net_device
*dev
, __u32
*mode
);
234 /* Wireless Extension Handler functions */
235 static int zd1205wext_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_freq
*freq
, char *extra
);
236 static int zd1205wext_siwmode(struct net_device
*dev
, struct iw_request_info
*info
, __u32
*mode
, char *extra
);
237 static int zd1205wext_giwmode(struct net_device
*dev
, struct iw_request_info
*info
, __u32
*mode
, char *extra
);
238 static int zd1205wext_giwrate(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rrq
, char *extra
);
239 static int zd1205wext_giwrts(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rts
, char *extra
);
240 static int zd1205wext_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*frag
, char *extra
);
241 static int zd1205wext_giwtxpow(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rrq
, char *extra
);
242 static int zd1205wext_siwtxpow(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rrq
, char *extra
);
243 static int zd1205wext_giwrange(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_point
*data
, char *extra
);
247 #if WIRELESS_EXT > 13
248 static int zd1205wext_siwscan(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_point
*data
, char *extra
);
249 static int zd1205wext_giwscan(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_point
*data
, char *extra
);
252 /* functions to support 802.11 protocol stack */
253 void zdcb_rx_ind(U8
*pData
, U32 length
, void *buf
, U32 LP_MAP
);
254 void zdcb_release_buffer(void *buf
);
255 void zdcb_tx_completed(void);
256 void zdcb_start_timer(U32 timeout
, U32 event
);
257 void zdcb_stop_timer(U32 TimerId
);
258 void zd1205_set_zd_cbs(zd_80211Obj_t
*pObj
);
259 void zdcb_set_reg(void *reg
, U32 offset
, U32 value
);
260 void chal_tout_cb(unsigned long ptr
);
261 U32
zdcb_dis_intr(void);
262 void zdcb_set_intr_mask(U32 flags
);
263 BOOLEAN
zdcb_check_tcb_avail(U8 num_of_frag
);
264 BOOLEAN
zdcb_setup_next_send(fragInfo_t
*frag_info
);
267 //void zd_CmdScanReq(u16 channel);
268 //void zd_ScanBegin();
271 U16
zdcb_status_notify(U16 status
, U8
*StaAddr
);
272 U32
zdcb_vir_to_phy_addr(U32 virtAddr
);
273 U32
zdcb_get_reg(void *reg
, U32 offset
);
274 void zdcb_delay_us(U32 ustime
);
275 int zdcb_Rand(U32 seed
);
277 /* For WPA supported functions */
278 void zd1205_notify_join_event(struct zd1205_private
*macp
);
279 void zd1205_notify_disjoin_event(struct zd1205_private
*macp
);
280 void zd1205_notify_scan_done(struct zd1205_private
*macp
);
281 BOOLEAN
zd_CmdProbeReq(U8 ProbeWithSsid
);
283 BssInfo_t
*zd1212_bssid_to_BssInfo(U8
*bssid
);
284 void zd_RateAdaption(void);
287 int zd1205_moxa_repeat( struct zd1205_private
*macp
);
288 int zd1205_dis_update_setting( struct zd1205_private
*macp
);
291 /******************************************************************************
293 * P U B L I C D A T A
294 *******************************************************************************
296 /* Global Data structures and variables */
298 char zd1205_copyright
[] __devinitdata
= "Copyright (c) 2002 Zydas Corporation";
299 char zd1205_driver_version
[]="0.0.1";
300 const char *zd1205_full_driver_name
= "Zydas ZD1205 Network Driver";
301 char zd1205_short_driver_name
[] = "zd1205";
304 #if 0 // mask by Victor Yu. 04-04-2007, we don't use it.
305 const char config_filename
[] = "/etc/zd1211.conf";
307 static BOOLEAN CustomMACSet
= FALSE
;
308 static u8 CustomMAC
[ETH_ALEN
];
309 static BOOLEAN AsocTimerStat
= FALSE
; //If the Asoc Timer is enabled
310 extern Hash_t
*sstByAid
[MAX_RECORD
];
313 zd1205_SwTcbQ_t free_txq_buf
, active_txq_buf
;
314 struct net_device
*g_dev
;
316 zd_80211Obj_t dot11Obj
= {0};
317 #if ZDCONF_LP_SUPPORT == 1
318 fragInfo_t PollFragInfo
;
321 #define RX_COPY_BREAK 0//1518 //we do bridge, don't care IP header alignment
322 #define BEFORE_BEACON 25
323 /* Definition of Wireless Extension */
326 * Structures to export the Wireless Handlers
329 typedef enum _ZD_REGION
331 ZD_REGION_Default
= 0x00,//All channel
332 ZD_REGION_USA
= 0x10,//G channel->ch1-11;
333 ZD_REGION_Canada
= 0x20,//G channel->ch1-11;
334 ZD_REGION_Argentina
= 0x21,//G channel->ch1-11;
335 ZD_REGION_Brazil
= 0x22,//G channel->ch1-11;
336 ZD_REGION_Europe
= 0x30,//G channel->ETSI ch1-13;
337 ZD_REGION_Spain
= 0x31,//G channel->ETSI ch1-13;
338 ZD_REGION_France
= 0x32,//G channel->ch10-13;
339 ZD_REGION_Ukraine
= 0x33,//G channel->ch1-11;
340 ZD_REGION_AustriaBelgium
= 0x34,//Austria and Belgium G channel->ch1-13;;
341 ZD_REGION_Switzerland
= 0x35,//G channel->ch1-13;
342 ZD_REGION_Japan
= 0x40,//G channel->ch1-14;
343 ZD_REGION_Australia
= 0x42,//G channel->ch1-13;
344 ZD_REGION_China
= 0x43,//G channel->ch1-11;
345 ZD_REGION_HongKong
= 0x44,//G channel->ch1-11;
346 ZD_REGION_Korea
= 0x45,//G channel->ch1-11;
347 ZD_REGION_NewZealand
= 0x46,//G channel->ch1-11;
348 ZD_REGION_Singapore
= 0x47,//G channel->ch10-13;
349 ZD_REGION_Taiwan
= 0x48,//G channel->ch1-13;
350 ZD_REGION_Israel
= 0x50,//G channel->ch3-9;
351 ZD_REGION_Mexico
= 0x51 //G channel->ch10,11;
354 //Here update fot iwpriv 20060914 prince
355 struct iw_priv_args zd1205_private_args
[] = {
356 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "list_bss" },
357 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
358 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_auth" }, /* 0 - open, 1 - shared key */
359 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_CHAR
| 12, "get_auth" },
360 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_preamble" }, /* 0 - long, 1 - short */
361 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_CHAR
| 6, "get_preamble" },
362 { SIOCIWFIRSTPRIV
+ 0x6, 0, 0, "cnt" },
363 { SIOCIWFIRSTPRIV
+ 0x7, 0, 0, "regs" },
364 { SIOCIWFIRSTPRIV
+ 0x8, 0, 0, "probe" },
365 { SIOCIWFIRSTPRIV
+ 0x9,IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_Region" },
366 { SIOCIWFIRSTPRIV
+ 0xA, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "connect" },
367 { SIOCIWFIRSTPRIV
+ 0xB, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_mac_mode" },
368 { SIOCIWFIRSTPRIV
+ 0xC, 0, IW_PRIV_TYPE_CHAR
| 12, "get_mac_mode" },
369 { SIOCIWFIRSTPRIV
+ 0xD, 0, 0, "set_moxa_repeat" },
370 { SIOCIWFIRSTPRIV
+ 0xE, 0, IW_PRIV_TYPE_CHAR
| 14, "get_Region" },
371 #if ZDCONF_LP_SUPPORT == 1
372 { SIOCIWFIRSTPRIV
+ 0xF , IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "lp_mode" },
375 // { SIOCIWFIRSTPRIV + 0x9, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dbg_flag" },
376 // { SIOCIWFIRSTPRIV + 0xD, 0, 0, "save_conf" },
377 // { SIOCIWFIRSTPRIV + 0xE, 0, 0, "load_conf" },
383 #if WIRELESS_EXT > 12
384 static iw_handler zd1205wext_handler
[] = {
385 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
387 (iw_handler
) NULL
, /* SIOCGIWNAME */
388 (iw_handler
) NULL
, /* SIOCSIWNWID */
389 (iw_handler
) NULL
, /* SIOCGIWNWID */
390 (iw_handler
) NULL
, /* SIOCSIWFREQ */
391 (iw_handler
) zd1205wext_giwfreq
, /* SIOCGIWFREQ */
394 (iw_handler
) NULL
, /* SIOCSIWMODE */
395 (iw_handler
) zd1205wext_giwmode
, /* SIOCGIWMODE */
397 (iw_handler
) NULL
, /* SIOCSIWSENS */
398 (iw_handler
) NULL
, /* SIOCGIWSENS */
399 (iw_handler
) NULL
, /* not used */ /* SIOCSIWRANGE */
400 (iw_handler
) zd1205wext_giwrange
, /* SIOCGIWRANGE */
401 (iw_handler
) NULL
, /* not used */ /* SIOCSIWPRIV */
402 (iw_handler
) NULL
, /* kernel code */ /* SIOCGIWPRIV */
403 (iw_handler
) NULL
, /* not used */ /* SIOCSIWSTATS */
404 (iw_handler
) NULL
, /* kernel code */ /* SIOCGIWSTATS */
406 (iw_handler
) NULL
, /* SIOCSIWSPY */
407 (iw_handler
) NULL
, /* SIOCGIWSPY */
408 (iw_handler
) NULL
, /* -- hole -- */
409 (iw_handler
) NULL
, /* -- hole -- */
410 (iw_handler
) NULL
, /* SIOCSIWAP */
411 (iw_handler
) NULL
, /* SIOCGIWAP */
412 (iw_handler
) NULL
, /* -- hole -- */
413 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
414 #if WIRELESS_EXT > 13
415 (iw_handler
) zd1205wext_siwscan
, /* SIOCSIWSCAN */
416 (iw_handler
) zd1205wext_giwscan
, /* SIOCGIWSCAN */
417 #else /* WIRELESS_EXT > 13 */
418 (iw_handler
) NULL
, /* null */ /* SIOCSIWSCAN */
419 (iw_handler
) NULL
, /* null */ /* SIOCGIWSCAN */
420 #endif /* WIRELESS_EXT > 13 */
421 (iw_handler
) NULL
, /* SIOCSIWESSID */
422 (iw_handler
) NULL
, /* SIOCGIWESSID */
423 (iw_handler
) NULL
, /* SIOCSIWNICKN */
424 (iw_handler
) NULL
, /* SIOCGIWNICKN */
425 (iw_handler
) NULL
, /* -- hole -- */
426 (iw_handler
) NULL
, /* -- hole -- */
427 (iw_handler
) NULL
, /* SIOCSIWRATE */
428 (iw_handler
) zd1205wext_giwrate
, /* SIOCGIWRATE */
429 (iw_handler
) NULL
, /* SIOCSIWRTS */
431 (iw_handler
) zd1205wext_giwrts
, /* SIOCGIWRTS */
432 (iw_handler
) NULL
, /* SIOCSIWFRAG */
433 (iw_handler
) zd1205wext_giwfrag
, /* SIOCGIWFRAG */
434 /* Jimmy_chen@moxa.com.tw : iwconfig ethX txpower N need */
435 (iw_handler
) zd1205wext_siwtxpow
, /* SIOCSIWTXPOW */
436 (iw_handler
) zd1205wext_giwtxpow
, /* SIOCGIWTXPOW */
437 (iw_handler
) NULL
, /* SIOCSIWRETRY */
438 (iw_handler
) NULL
, /* SIOCGIWRETRY */
439 (iw_handler
) NULL
, /* SIOCSIWENCODE */
440 (iw_handler
) NULL
, /* SIOCGIWENCODE */
441 (iw_handler
) NULL
, /* SIOCSIWPOWER */
442 (iw_handler
) NULL
, /* SIOCGIWPOWER */
445 static const iw_handler zd1205_private_handler
[] =
447 NULL
, /* SIOCIWFIRSTPRIV */
451 struct iw_handler_def p80211wext_handler_def
= {
452 num_standard
: sizeof(zd1205wext_handler
) / sizeof(iw_handler
),
453 num_private
: sizeof(zd1205_private_handler
)/sizeof(iw_handler
),
455 num_private_args
: sizeof(zd1205_private_args
)/sizeof(struct iw_priv_args
),
456 standard
: zd1205wext_handler
,
457 private: (iw_handler
*) zd1205_private_handler
,
458 private_args
: (struct iw_priv_args
*) zd1205_private_args
,
459 #if WIRELESS_EXT > 18
460 get_wireless_stats
: (struct iw_statistics
* )zd1205_iw_getstats
465 #if 0//(LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
466 #define do_div(n,base) ({ \
467 unsigned long __upper, __low, __high, __mod; \
468 asm("":"=a" (__low), "=d" (__high):"A" (n)); \
471 __upper = __high % (base); \
472 __high = __high / (base); \
474 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (base), "0" (__low), "1" (__upper)); \
475 asm("":"=A" (n):"a" (__low),"d" (__high)); \
479 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,6))
480 static void wait_ms(unsigned int ms
)
482 if(!in_interrupt()) {
483 current
->state
= TASK_UNINTERRUPTIBLE
;
484 schedule_timeout(1 + ms
* HZ
/ 1000);
490 #ifndef CONFIG_ARCH_MOXART
491 asmlinkage
_syscall3(int,write
,int,fd
,const char *,buf
,off_t
,count
)
492 asmlinkage
_syscall3(int,read
,int,fd
,char *,buf
,off_t
,count
)
493 asmlinkage
_syscall3(int,open
,const char *,file
,int,flag
,int,mode
)
494 asmlinkage
_syscall1(int,close
,int,fd
)
495 #endif /* CONFIG_ARCH_MOXART */
497 const U16 dot11A_Channel
[]={36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,184,188,192,196,8,12,16,34,38,42,46,149,153,157,161,165};
498 const U16 dot11A_Channel_Amount
=sizeof(dot11A_Channel
)/sizeof(U16
);
504 u8 OfdmRateTbl
[12] = {
518 //Rate > 6M, the bit Long/Short preamble is 1 for 802.11a
519 //While it's 0 for 802.11g
520 u8 OfdmRateTbl_11A
[12]= {
536 //The Order is meaningful, Do not Change
537 static u8 a_ChannelMap
[] = {
546 typedef struct _a_InterpolationStruc
{
549 u8 Left_Most_Channel
;
550 u8 Right_Most_Channel
;
552 u8 Position
; // starting from left.
553 } a_InterpolationStruc
;
555 static a_InterpolationStruc a_InterpolationTbl
[] = {
556 //a_Channel, Left_Most_Channel, Right_Most_Channel,TotalDivisionNum,Position
557 {188, 184, 196, 3, 1},
558 {192, 184, 196, 3, 2},
568 {104, 100, 112, 3, 1},
569 {108, 100, 112, 3, 2},
570 {116, 112, 128, 4, 1},
571 {120, 112, 128, 4, 2},
572 {124, 112, 128, 4, 3},
573 {132, 128, 140, 3, 1},
574 {136, 128, 140, 3, 2},
575 {153, 149, 165, 4, 1},
576 {157, 149, 165, 4, 2},
577 {161, 149, 165, 4, 3}
580 #define a_CALIBRATED_CH_NUM sizeof(a_ChannelMap)
581 #define a_INTERPOLATION_CH_NUM (sizeof(a_InterpolationTbl) / sizeof(a_InterpolationStruc))
582 #define a_MAX_CALIBRATION_CH_NUM 16
583 #define a_MAX_INTERPOLATION_CH_NUM 32
584 #define cPWR_INT_VALUE_GUARD 8
585 u8 a_Calibration_Data
[4][a_MAX_CALIBRATION_CH_NUM
];
586 u8 a_Interpolation_Data
[4][a_MAX_INTERPOLATION_CH_NUM
];
588 // [1][]:Integration Value
589 // [2][]:SetPoint_36M
590 // [3][]:SetPoint_48M_54M
593 //Find the array index of certain Channel
594 u8
a_get_cal_int_val( u8 index
)
598 if (index
< a_CALIBRATED_CH_NUM
){
599 tmpvalue
=zd_readl(ZD_E2P_11A_INT_VALUE1
+((index
>>2)<<2));
600 return ((u8
)(tmpvalue
>> (index
%4*8)));
603 printk("Error in a_get_cal_int_val\n");
608 u8
a_get_cal_36M_setpoint_val( u8 index
)
613 tmpvalue
=zd_readl(ZD_E2P_A36M_CAL_VALUE
+((index
>>2)<<2));
614 return ((u8
)(tmpvalue
>> (index
%4*8)));
617 printk("Error in a_get_cal_36M_setpoint_val\n");
622 u8
a_get_cal_48M_54M_setpoint_val( u8 index
)
626 if (index
< a_CALIBRATED_CH_NUM
){
627 tmpvalue
=zd_readl(ZD_E2P_A54M_CAL_VALUE
+((index
>>2)<<2));
628 return ((u8
)(tmpvalue
>> (index
%4*8)));
631 printk("Error in a_get_cal_54M_setpoint_val\n");
635 u8
a_find_index_in_a_Calibration_Data( u8 ch
)
638 for (i
=0;i
<a_CALIBRATED_CH_NUM
;i
++){
639 if (ch
== a_Calibration_Data
[0][i
]){
645 u8
a_find_index_in_a_Interpolation_Data( u8 ch
)
648 for (i
=0;i
<a_INTERPOLATION_CH_NUM
;i
++){
649 if (ch
== a_Interpolation_Data
[0][i
]){
656 BOOLEAN
a_get_interpolation_value(
660 u8
*pSetPoint_48M_54M
)
662 u8 lm_index
; //Left Most Index
663 u8 rm_index
; //Right Most Index
664 // Find Left-Most CH in a_ChannelMap
665 lm_index
= a_find_index_in_a_Calibration_Data( a_InterpolationTbl
[index
].Left_Most_Channel
);
666 if (lm_index
== 0xff){
667 printk("Get lm_index error in a_get_inter..\n");
670 // Find Right-Most CH in a_ChannelMap
671 rm_index
= a_find_index_in_a_Calibration_Data( a_InterpolationTbl
[index
].Right_Most_Channel
);
672 if (rm_index
== 0xff){
673 printk("Get rm_index error in a_get_inter..\n");
677 *pIntVal
= (u8
)(a_Calibration_Data
[1][lm_index
] +
678 (u32
)ABS(a_Calibration_Data
[1][rm_index
],a_Calibration_Data
[1][lm_index
])*
679 a_InterpolationTbl
[index
].Position
/ a_InterpolationTbl
[index
].TotalDivisionNum
);
681 *pSetPoint_36M
= (u8
)(a_Calibration_Data
[2][lm_index
] +
682 (u32
)ABS(a_Calibration_Data
[2][rm_index
],a_Calibration_Data
[2][lm_index
])*
683 a_InterpolationTbl
[index
].Position
/ a_InterpolationTbl
[index
].TotalDivisionNum
);
684 *pSetPoint_48M_54M
= (u8
)(a_Calibration_Data
[3][lm_index
] +
685 (u32
)ABS(a_Calibration_Data
[3][rm_index
],a_Calibration_Data
[3][lm_index
])*
686 a_InterpolationTbl
[index
].Position
/ a_InterpolationTbl
[index
].TotalDivisionNum
);
690 //Channel A, One Stop Call to get cal & int
691 u8
a_OSC_get_cal_int( u8 ch
, u32 rate
, u8
*intValue
, u8
*calValue
) {
694 idx
= a_find_index_in_a_Calibration_Data(ch
);
695 if(0xff == idx
) {//Error code, we can't found the channel in calibration data
696 idx
= a_find_index_in_a_Interpolation_Data(ch
);
698 *intValue
= a_Interpolation_Data
[1][idx
];
700 *calValue
= a_Interpolation_Data
[2][idx
];
702 *calValue
= a_Interpolation_Data
[3][idx
];
707 else {//Channel is in Calibration Data
708 *intValue
= a_Calibration_Data
[1][idx
];
710 *calValue
= a_Calibration_Data
[2][idx
];
712 *calValue
= a_Calibration_Data
[3][idx
];
719 //prince add for get Region String
720 static char* get_curregion_str( struct zd1205_private
*macp
)
724 retStr
= kmalloc(sizeof(char)*30,GFP_KERNEL
);
726 if ( macp
->RegionCode
== ZD_REGION_USA
)
727 sprintf(retStr
,"%s","USA");
728 else if ( macp
->RegionCode
== ZD_REGION_Europe
)
729 sprintf(retStr
,"%s","Taiwan/Europe");
730 else if ( macp
->RegionCode
== ZD_REGION_France
)
731 sprintf(retStr
,"%s","France");
732 else if ( macp
->RegionCode
== ZD_REGION_Japan
)
733 sprintf(retStr
,"%s","Japan");
734 else if ( macp
->RegionCode
== ZD_REGION_Israel
)
735 sprintf(retStr
,"%s","Israel");
736 else if ( macp
->RegionCode
== ZD_REGION_Mexico
)
737 sprintf(retStr
,"%s","Mexico");
741 //prince add for pass region and channel return correct channel
742 //if setChannel == 0 default channel
743 static U8
pass_channel_for_region(struct zd1205_private
*macp
,U16 setChannel
)
745 U16 retChannel
=setChannel
;
747 if ( macp
->cardSetting
.MacMode
== PURE_A_MODE
) {
748 if ( setChannel
< 36 || setChannel
== 0 )
750 #if 0 // mask by Victor Yu. 04-04-2007
752 retChannel
= setChannel
;
755 if ( macp
->RegionCode
== ZD_REGION_USA
) {
756 if ( setChannel
< 1 || setChannel
> 11 || setChannel
== 0 )
758 #if 0 // mask by Victor Yu. 04-04-2007
760 retChannel
= setChannel
;
762 } else if ( macp
->RegionCode
== ZD_REGION_Europe
) {
763 #if 0 // mask by Victor Yu. 04-04-2007
764 if ( setChannel
< 1 || setChannel
> 13 || setChannel
== 0 )
765 retChannel
= setChannel
;
767 retChannel
= setChannel
;
769 } else if ( macp
->RegionCode
== ZD_REGION_France
) {
770 if ( setChannel
< 10 || setChannel
> 13 || setChannel
== 0 )
772 #if 0 // mask by Victor Yu. 04-04-2007
774 retChannel
= setChannel
;
776 } else if ( macp
->RegionCode
== ZD_REGION_Japan
) {
777 if ( setChannel
< 1 || setChannel
> 14 || setChannel
== 0 )
779 #if 0 // mask by Victor Yu. 04-04-2007
781 retChannel
= setChannel
;
783 } else if ( macp
->RegionCode
== ZD_REGION_Israel
) {
784 if ( setChannel
< 3 || setChannel
> 9 || setChannel
== 0 )
786 #if 0 // mask by Victor Yu. 04-04-2007
788 retChannel
= setChannel
;
790 } else if ( macp
->RegionCode
== ZD_REGION_Mexico
) {
791 if ( setChannel
< 10 || setChannel
> 11 || setChannel
== 0 )
793 #if 0 // mask by Victor Yu. 04-04-2007
795 retChannel
= setChannel
;
800 return (U8
)retChannel
;
804 //prince add for disassoc
805 static void zd1205_disassoc(struct zd1205_private
*macp
)
809 if ( !( macp
->cardSetting
.BssType
== INDEPENDENT_BSS
&& macp
->ModeChBssType
== AP_BSS
) )
811 zd1205_dis_connect(macp
);
812 //zd_CmdProcess(CMD_DIS_CONNECT, 0, 0);
813 if (macp
->cardSetting
.ap_scan
!= 1)
814 zd_CmdProcess(CMD_ROAMING
, 0, 0);
816 zdcb_status_notify(STA_DISASSOCIATED
, &macp
->BSSID
[0]);
824 #define fDISABLE_LED 0
825 void iLED_ON(struct zd1205_private
*macp
, u32 LEDn
)
831 tmpvalue
= zd_readl(rLED_CTRL
);
833 zd_writel(tmpvalue
, rLED_CTRL
);
836 tmpvalue
= zd_readl(FW_LINK_STATUS
);
838 zd_writel(tmpvalue
, FW_LINK_STATUS
);
845 void iLED_OFF(struct zd1205_private
*macp
, u32 LEDn
)
852 tmpvalue
= zd_readl(rLED_CTRL
);
854 zd_writel(tmpvalue
, rLED_CTRL
);
858 zd_writel(0x0, FW_LINK_STATUS
);
865 void iLED_SWITCH(struct zd1205_private
*macp
, u32 LEDn
)
870 tmpvalue
= zd_readl(rLED_CTRL
);
872 zd_writel(tmpvalue
, rLED_CTRL
);
877 void iLED_ON(struct zd1205_private
*macp
, u32 LEDn
)
879 zd_writel(0x1, LEDn
);
886 void iLED_OFF(struct zd1205_private
*macp
, u32 LEDn
)
888 zd_writel(0x0, LEDn
);
892 void iLED_SWITCH(struct zd1205_private
*macp
, u32 LEDn
)
896 tmpvalue
= zd_readl(LEDn
);
898 zd_writel(tmpvalue
, LEDn
);
904 void zd_writel(u32 value
, u32 offset
)
906 struct zd1205_private
*macp
= g_dev
->priv
;
907 void *regp
= macp
->regp
;
913 if (!macp
->bAllowAccessRegister
)
917 zd1211_writel(offset
, value
, true);
922 atomic_inc(&macp
->DoNotSleep
);
923 if (dot11Obj
.bDeviceInSleep
){
924 while((readl(regp
+ZD_MAC_PS_STATE
) & 0x7) != MAC_OPERATION
){
927 if ((RegWait
> REG_MAX_WAIT
) || macp
->bSurpriseRemoved
){
928 dot11Obj
.bDeviceInSleep
= 0;
929 ZD1211DEBUG(0, "zd_writel Sleep to die!!!");
936 writel(value
, regp
+offset
);
937 atomic_dec(&macp
->DoNotSleep
);
941 u32
zd_readl(u32 offset
)
943 struct zd1205_private
*macp
= g_dev
->priv
;
944 void *regp
= macp
->regp
;
950 if (!macp
->bAllowAccessRegister
)
953 //value = zd1211_readl(offset, true);
954 value
= zd1211_readl(offset
, true);
959 atomic_inc(&macp
->DoNotSleep
);
960 if (dot11Obj
.bDeviceInSleep
){
961 while((readl(regp
+ZD_MAC_PS_STATE
) & 0x7) != MAC_OPERATION
){
964 if ((RegWait
> REG_MAX_WAIT
) || macp
->bSurpriseRemoved
){
966 dot11Obj
.bDeviceInSleep
= 0;
967 ZD1211DEBUG(0, "zd_readl Sleep to die!!!");
973 value
= readl(regp
+offset
);
974 atomic_dec(&macp
->DoNotSleep
);
980 void zd1205_disable_int(void)
983 /* Disable interrupts on our PCI board by setting the mask bit */
984 zd_writel(0, InterruptCtrl
);
990 void zd1205_enable_int(void)
992 struct zd1205_private
*macp
= g_dev
->priv
;
994 zd_writel(macp
->intrMask
, InterruptCtrl
);
998 void zd1205_start_download(u32 phyAddr
)
1004 if (!dot11Obj
.bDeviceInSleep
)
1005 zd_writel(phyAddr
, ZD_PCI_TxAddr_p1
);
1009 void zd1205_start_upload(u32 phyAddr
)
1017 if (!dot11Obj
.bDeviceInSleep
){
1018 zd_writel(phyAddr
, ZD_PCI_RxAddr_p1
);
1021 zd_writel(0, ZD_PCI_RxAddr_p2
);
1027 int zd1205_DestPowerSave(struct zd1205_private
*macp
, u8
*pDestAddr
)
1032 if ((macp
->cardSetting
.ATIMWindow
!= 0) && (macp
->bAssoc
)){
1033 // We must make sure that Device has been in IBSS mode and PwrMgt mode.
1034 tmpvalue
= zd_readl(ZD_BCNInterval
);
1035 if ((tmpvalue
& IBSS_MODE
) && (tmpvalue
& POWER_MNT
)){
1038 // ATIM could be sent only when BCNController is active.
1039 if ((*(pDestAddr
) & BIT_0
) || (macp
->bIBSS_Wakeup_Dest
)){ // We should issue ATIM for multicast frame.
1040 macp
->bIBSS_Wakeup_Dest
= 0;
1052 static void zd1205_action(unsigned long parm
)
1054 zd_SigProcess(); //process management frame queue in mgtQ
1058 static void zd1205_ps_action(unsigned long parm
)
1064 static void zd1205_tx_action(unsigned long parm
)
1071 u8
zd1205_RateAdaption(u16 aid
, u8 CurrentRate
, u8 gear
)
1077 RATEDEBUG("***** zd1205_RateAdaption");
1078 RATEDEBUG_V("aid", aid
);
1081 RATEDEBUG_V("CurrentRate", CurrentRate
);
1083 if (gear
== FALL_RATE
){
1086 if (CurrentRate
>= RATE_2M
){
1087 NewRate
= CurrentRate
- 1;
1088 zd_EventNotify(EVENT_UPDATE_TX_RATE
, (U32
)NewRate
, (U32
)aid
, 0);
1091 NewRate
= CurrentRate
;
1100 void zd1205_ClearTupleCache(struct zd1205_private
*macp
)
1103 tuple_Cache_t
*pCache
= &macp
->cache
;
1105 pCache
->freeTpi
= 0;
1106 for (i
=0; i
<TUPLE_CACHE_SIZE
; i
++){
1107 pCache
->cache
[i
].full
= 0;
1112 u8
zd1205_SearchTupleCache(struct zd1205_private
*macp
, u8
*pAddr
, u16 seq
, u8 frag
)
1115 tuple_Cache_t
*pCache
= &macp
->cache
;
1117 for (k
=0; k
<TUPLE_CACHE_SIZE
; k
++){
1118 if ((memcmp((char *)&pCache
->cache
[k
].ta
[0], (char *)pAddr
, 6) == 0)
1119 && (pCache
->cache
[k
].sn
== seq
) && (pCache
->cache
[k
].fn
== frag
)
1120 && (pCache
->cache
[k
].full
))
1128 void zd1205_UpdateTupleCache(struct zd1205_private
*macp
, u8
*pAddr
, u16 seq
,u8 frag
)
1131 tuple_Cache_t
*pCache
= &macp
->cache
;
1133 for (k
=0; k
<TUPLE_CACHE_SIZE
; k
++){
1134 if (pCache
->cache
[k
].full
){
1135 if ((memcmp((char *)&pCache
->cache
[k
].ta
[0], (char *)pAddr
, 6) == 0)
1136 && (pCache
->cache
[k
].sn
== seq
) ){
1137 pCache
->cache
[k
].fn
= frag
;
1144 pCache
->freeTpi
&= (TUPLE_CACHE_SIZE
-1);
1145 memcpy(&pCache
->cache
[pCache
->freeTpi
].ta
[0], (char *)pAddr
, 6);
1146 pCache
->cache
[pCache
->freeTpi
].sn
= seq
;
1147 pCache
->cache
[pCache
->freeTpi
].fn
= frag
;
1148 pCache
->cache
[pCache
->freeTpi
].full
= 1;
1155 void zd1205_ArReset(struct zd1205_private
*macp
)
1158 defrag_Array_t
*pArray
= &macp
->defragArray
;
1160 for (i
=0; i
<MAX_DEFRAG_NUM
; i
++)
1161 pArray
->mpdu
[i
].inUse
= 0;
1165 void zd1205_ArAge(struct zd1205_private
*macp
, u32 age
)
1168 defrag_Array_t
*pArray
= &macp
->defragArray
;
1170 for (i
=0; i
<MAX_DEFRAG_NUM
; i
++){
1171 if (pArray
->mpdu
[i
].inUse
){
1172 if ((age
- pArray
->mpdu
[i
].eol
) > MAX_RX_TIMEOUT
){
1173 DFDEBUG("***** zd1205_ArAged");
1179 dot11Obj
.ReleaseBuffer(pArray
->mpdu
[i
].buf
);
1180 pArray
->mpdu
[i
].inUse
= 0;
1189 int zd1205_ArFree(struct zd1205_private
*macp
)
1192 defrag_Array_t
*pArray
= &macp
->defragArray
;
1194 for (i
=0; i
<MAX_DEFRAG_NUM
; i
++){
1195 if (!pArray
->mpdu
[i
].inUse
)
1200 macp
->ArFreeFailCnt
++;
1205 int zd1205_ArSearch(struct zd1205_private
*macp
, u8
*pAddr
, u16 seq
, u8 frag
)
1208 defrag_Array_t
*pArray
= &macp
->defragArray
;
1209 defrag_Mpdu_t
*pDeMpdu
;
1212 for (i
=0; i
<MAX_DEFRAG_NUM
; i
++){
1213 pDeMpdu
= &pArray
->mpdu
[i
];
1214 if (pDeMpdu
->inUse
){
1215 if ((memcmp((char *)&pDeMpdu
->ta
[0], pAddr
, 6) == 0)
1216 && (pDeMpdu
->sn
== seq
)){
1217 if (pDeMpdu
->fn
== (frag
-1)){
1221 dot11Obj
.ReleaseBuffer(pDeMpdu
->buf
);
1234 void zd1205_ArUpdate(struct zd1205_private
*macp
, u8
*pAddr
, u16 seq
, u8 frag
, int i
)
1237 defrag_Array_t
*pArray
= &macp
->defragArray
;
1240 pArray
->mpdu
[i
].inUse
= 1;
1241 memcpy(&pArray
->mpdu
[i
].ta
[0], (char*)pAddr
, 6);
1242 pArray
->mpdu
[i
].sn
= seq
;
1243 pArray
->mpdu
[i
].fn
= frag
;
1244 pArray
->mpdu
[i
].eol
= nowT();
1248 void zd1205_IncreaseTxPower(struct zd1205_private
*macp
, u8 TxPwrType
)
1253 if (TxPwrType
!= cTX_OFDM
)
1254 pTxGain
= &(dot11Obj
.TxGainSetting
);
1257 pTxGain
= &(dot11Obj
.TxGainSetting2
);
1259 pTxGain
= &(dot11Obj
.TxGainSetting
);
1262 switch(macp
->RF_Mode
){
1264 if (*pTxGain
< MAXIM2_MAX_TX_PWR_SET
)
1270 if (*pTxGain
< RFMD_MAX_TX_PWR_SET
)
1277 if (*pTxGain
< AL2230_MAX_TX_PWR_SET
)
1285 HW_Write_TxGain2(&dot11Obj
, TxPwrType
);
1289 void zd1205_DecreaseTxPower(struct zd1205_private
*macp
, u8 TxPwrType
)
1294 if (TxPwrType
!= cTX_OFDM
)
1295 pTxGain
= &(dot11Obj
.TxGainSetting
);
1297 pTxGain
= &(dot11Obj
.TxGainSetting2
);
1300 pTxGain
= &(dot11Obj
.TxGainSetting
);
1305 switch(macp
->RF_Mode
){
1307 if (*pTxGain
> MAXIM2_MIN_TX_PWR_SET
)
1313 if (*pTxGain
> RFMD_MIN_TX_PWR_SET
)
1322 if (*pTxGain
> AL2230_MIN_TX_PWR_SET
)
1330 HW_Write_TxGain2(&dot11Obj
, TxPwrType
);
1337 zd1205_AnyActivity(struct zd1205_private
*macp
)
1339 unsigned long flags
;
1341 // Any frame wait for transmission.
1342 if(!in_irq())spin_lock_irqsave(&macp
->q_lock
, flags
);
1343 if (macp
->activeTxQ
->count
){
1344 if(!in_irq())spin_unlock_irqrestore(&macp
->q_lock
, flags
);
1350 if(!in_irq())spin_unlock_irqrestore(&macp
->q_lock
, flags
);
1353 if ((dot11Obj
.QueueFlag
& MGT_QUEUE_SET
) || (dot11Obj
.QueueFlag
& TX_QUEUE_SET
))
1356 if (macp
->bAnyActivity
)
1364 void zd1205_connect_mon(struct zd1205_private
*macp
)
1366 static u16 IdleLoop_Under_Seq1
= 0;
1369 // if (dot11Obj.bDeviceInSleep)
1370 // printk(KERN_ERR "mon\n");
1371 if ((macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
) && (macp
->bPSMSupported
)){
1372 if ((!dot11Obj
.bChScanning
) && (macp
->PwrState
) && (!dot11Obj
.bDeviceInSleep
) && (macp
->bAssoc
)){
1373 // Solve Sequence number duplication problem after wakeup.
1374 if (!zd1205_AnyActivity(macp
)){
1375 if ((macp
->SequenceNum
!= 1) || (IdleLoop_Under_Seq1
> 20)){
1376 //zd1205_sleep_reset(macp);
1377 IdleLoop_Under_Seq1
= 0;
1378 // Avoid accessing Registers to save computation power.
1381 IdleLoop_Under_Seq1
++;
1383 //ZD1211DEBUG(2, "IdleLoop_Under_Seq1= %d\n", IdleLoop_Under_Seq1);
1392 void zd1205_mgt_mon_cb(struct net_device
*dev
)
1394 struct zd1205_private
*macp
= dev
->priv
;
1399 defer_kevent(macp
, KEVENT_MGT_MON_TIMEOUT
);
1400 mod_timer(&(macp
->tm_mgt_id
), jiffies
+ (1*HZ
)/50); //20ms
1404 zd1205_connect_mon(macp
);
1405 mod_timer(&(macp
->tm_mgt_id
), jiffies
+ (1*HZ
)/50); //20ms
1411 void zd1205_SwAntennaDiv(struct zd1205_private
*macp
)
1414 static u32 loop
= 0;
1417 // Software Antenna Diversity Mechanism
1418 if (macp
->bEnableSwAntennaDiv
){
1421 if ((loop
% macp
->Ant_MonitorDur1
) == 0){
1422 if (macp
->Acc_Num_OFDM
)
1423 Avg1_SQ_OFDM
= macp
->Acc_SQ_OFDM
/ macp
->Acc_Num_OFDM
;
1428 Avg1_SQ
= macp
->Acc_SQ
/ macp
->Acc_Num
;
1433 // Higher SQ is better
1434 if (((Avg1_SQ_OFDM
< macp
->NiceSQThr_OFDM
) && (Avg1_SQ_OFDM
> 0))
1435 || ((Avg1_SQ_OFDM
== 0)
1436 && ((Avg1_SQ
< macp
->NiceSQThr
) && (Avg1_SQ
> 0)))
1437 || (!macp
->bAssoc
)){ // disconnected
1438 SwitchAntenna(macp
);
1447 macp
->Acc_SQ_OFDM
= 0;
1448 macp
->Acc_Num_OFDM
= 0;
1453 if ((loop
% macp
->Ant_MonitorDur2
) == 0)
1456 if (macp
->Acc_Num_OFDM
)
1457 Avg2_SQ_OFDM
= macp
->Acc_SQ_OFDM
/ macp
->Acc_Num_OFDM
;
1461 Avg2_SQ
= macp
->Acc_SQ
/ macp
->Acc_Num
;
1466 // Higher SQ is better
1467 if ((Avg2_SQ_OFDM
< Avg1_SQ_OFDM
)
1470 || (((Avg2_SQ_OFDM
== 0) && (Avg1_SQ_OFDM
== 0))
1471 && (Avg2_SQ
< Avg1_SQ
))
1472 || (!macp
->bAssoc
)){ // disconnected
1473 SwitchAntenna(macp
);
1481 macp
->Acc_SQ_OFDM
= 0;
1482 macp
->Acc_Num_OFDM
= 0;
1495 void zd1205_CollectHwTally(struct zd1205_private
*macp
)
1497 macp
->hwTotalRxFrm
+= zd_readl(TotalRxFrm
);
1498 macp
->hwCRC32Cnt
+= zd_readl(CRC32Cnt
);
1500 macp
->hwCRC16Cnt
+= zd_readl(CRC16Cnt
);
1501 //macp->hwDecrypErr_UNI += zd_readl(DecrypErr_UNI);
1502 //macp->hwDecrypErr_Mul += zd_readl(DecrypErr_Mul);
1503 macp
->hwRxFIFOOverrun
+= zd_readl(RxFIFOOverrun
);
1504 macp
->hwTotalTxFrm
+= zd_readl(TotalTxFrm
);
1507 macp
->hwUnderrunCnt
+= zd_readl(UnderrunCnt
);
1508 macp
->hwRetryCnt
+= zd_readl(RetryCnt
);
1514 int zd1205_IbssPsCheck(struct zd1205_private
*macp
)
1516 u32 ul_BcnItvl
, ul_atimwnd
;
1521 // Make sure that we have passed (ATIM-Window+TOLERANCE)
1522 ul_BcnItvl
= zd_readl(ZD_BCNInterval
);
1523 ul_BcnItvl
&= 0xffff;
1525 ul_atimwnd
= zd_readl(ZD_ATIMWndPeriod
);
1526 tmpvalue
= zd_readl(ZD_TSF_LowPart
);
1527 TSFTimer
= tmpvalue
;
1529 tmpvalue
= zd_readl(ZD_TSF_HighPart
);
1530 TSFTimer
+= (((u64
)tmpvalue
) << 32);
1531 TSFTimer
= TSFTimer
>> 10; // in unit of TU
1533 //printk("TSF(TU) %d \n", TSFTimer);
1534 //printk("BeaconInterval = %d\n", ul_BcnItvl);
1535 //printk("TSF mod BeaconInterval = %d\n", (TSFTimer % ul_BcnItvl));
1537 if ((do_div(TSFTimer, ul_BcnItvl)) > (ul_atimwnd + TOLERANCE)){
1540 do_div(TSFTimer
, ul_BcnItvl
);
1541 if ( (u32
)TSFTimer
> (ul_atimwnd
+ TOLERANCE
) ) {
1544 // Make sure no traffic before (ATIMWnd+TOLERANCE)
1545 if ((!macp
->bFrmRxed1
) && (macp
->SuggestionMode
== PS_PSM
)){
1546 // Any frame wait for transmission.
1547 if (!macp
->activeTxQ
->count
){
1549 //zd1205_sleep_reset(macp);
1560 void zd1205_InfraPsCheck(struct zd1205_private
*macp
)
1564 // Now, we assure that no any power-save related operation performing.
1565 // That's because all power-save related operations are either
1566 // Mutexed by Adapter->Lock or Notified by Adapter->Notification.
1567 if ((macp
->SuggestionMode
== PS_PSM
) && (macp
->PwrState
== PS_CAM
)){
1568 down(&macp
->bcn_sem
);
1569 tmpvalue
= zd_readl(ZD_BCNInterval
);
1571 tmpvalue
|= POWER_MNT
;
1574 zd_writel(tmpvalue
, ZD_BCNInterval
);
1577 macp
->PwrState
= PS_PSM
;
1578 zd_EventNotify(EVENT_PS_CHANGE
, (U8
)macp
->PwrState
, 0, 0);
1579 ZD1211DEBUG(0, "=====CAM --> PSM\n");
1581 else if ((macp
->SuggestionMode
== PS_CAM
) && (macp
->PwrState
== PS_PSM
) &&
1582 (!dot11Obj
.bDeviceInSleep
)){
1583 down(&macp
->bcn_sem
);
1585 tmpvalue
= zd_readl(ZD_BCNInterval
);
1586 tmpvalue
&= ~POWER_MNT
;
1587 zd_writel(tmpvalue
, ZD_BCNInterval
);
1590 macp
->PwrState
= PS_CAM
;
1591 zd_EventNotify(EVENT_PS_CHANGE
, (U8
)macp
->PwrState
, 0, 0);
1592 ZD1211DEBUG(0, "=====PSM --> CAM\n");
1598 //Normally, house keeping routine is run every 100ms.
1599 void zd1205_house_keeping(struct zd1205_private
*macp
)
1603 static u32 loop
= 0;
1604 card_Setting_t
*pSetting
= &macp
->cardSetting
;
1605 u8 BssType
= pSetting
->BssType
;
1606 u8 bAssoc
= macp
->bAssoc
;
1609 if (dot11Obj
.QueueFlag
& TX_QUEUE_SET
){
1610 macp
->txQueSetCnt
++;
1611 //tasklet_schedule(&macp->zd1205_tx_tasklet);
1618 while (dot11Obj
.bDeviceInSleep
){
1619 // If device is in sleep, do not access device register often to
1620 // prevent host from slowing down.
1624 if (dot11Obj
.bDeviceInSleep
)
1628 // Software Antenna Diversity Mechanism
1629 if (macp
->bEnableSwAntennaDiv
){
1630 zd1205_SwAntennaDiv(macp
);
1633 // IBSS power-save monitor
1634 if ((BssType
== INDEPENDENT_BSS
) && (bAssoc
)){
1635 if ((!dot11Obj
.bChScanning
) && macp
->bPSMSupported
){
1636 if (zd1205_IbssPsCheck(macp
))
1642 // Infrasture AP mode beacon generation
1643 if (BssType
== AP_BSS
) {
1644 down(&macp
->bcn_sem
);
1645 zd_EventNotify(EVENT_TBCN
, 0, 0, 0);
1648 if (macp
->dtimCount
== 0)
1649 macp
->dtimCount
= macp
->cardSetting
.DtimPeriod
;
1655 //++ Recovery mechanism for ZD1202 ASIC Phy-Bus arbitration fault.
1656 // We combined tx-power-tracking/Sw Antenna diversity code here to
1657 // reduce the frequence of
1658 // calling ReleaseCtrOfPhyReg. It's harmful to throughput.
1660 if ((loop
% 1) == 0){ //every 100 ms
1662 //zd1205_CollectHwTally(macp); //This will make us lose CfgNextBcn interrupt
1666 //tmpvalue = zd_readl(0x6e4);
1667 //macp->REG_6e4_Add += tmpvalue;
1668 //printk(KERN_ERR "Detect Strong Signal:%lu\n",jiffies);
1669 zd1211_StrongSignalDect(macp
);
1672 // Infrastructure Power-State momitor
1674 if ((!dot11Obj
.bChScanning
) && (BssType
== INFRASTRUCTURE_BSS
) && (bAssoc
) && (macp
->bPSMSupported
)){
1675 zd1205_InfraPsCheck(macp
);
1681 zd1211_TxCalibration(macp
);
1683 //if(dot11Obj.rfMode == UW2453_RF)
1684 // PHY_UWTxPower(&dot11Obj, mRfChannel);
1685 zd1211_CheckWithIPC(macp
);
1690 void HKeepingCB(struct net_device
*dev
)
1692 struct zd1205_private
*macp
= dev
->priv
;
1693 static U32 loop
= 0;
1697 defer_kevent(macp
, KEVENT_HOUSE_KEEPING
);
1698 mod_timer(&(macp
->tm_hking_id
), jiffies
+ (1*HZ
)/10);
1700 zd1205_house_keeping(macp
);
1701 mod_timer(&(macp
->tm_hking_id
), jiffies
+ (1*HZ
)/10);
1704 if (!macp
->bFixedRate
&& (loop
& BIT_0
))
1710 #if ZDCONF_LP_SUPPORT == 1
1711 void zd1205_lp_poll_cb(struct net_device
*dev
)
1713 struct zd1205_private
*macp
= dev
->priv
;
1716 if (macp->cardStatus == 0x1234)
1718 ZD1211DEBUG(0, "mgt_mon_cb: card was closed\n");
1722 if(!dot11Obj
.LP_MODE
)
1724 PollFragInfo
.msgID
= 254;
1725 dot11Obj
.SetupNextSend(&PollFragInfo
);
1726 mod_timer(&(macp
->tm_lp_poll_id
), jiffies
+(1*HZ
)/20);
1732 void zd1205_CollectBssInfo(struct zd1205_private
*macp
, plcp_wla_Header_t
*pWlanHdr
, u8
*pMacBody
, u32 bodyLen
)
1734 u8 bssidmatched
= 0;
1742 if ((*(pMacBody
+CAP_OFFSET
)) & BIT_1
) //IBSS
1743 pBssid
= pWlanHdr
->Address3
;
1745 pBssid
= pWlanHdr
->Address2
;
1747 for (i
=0; i
<macp
->bss_index
; i
++){
1748 for (j
=0; j
<6; j
++){
1749 if (macp
->BSSInfo
[i
].bssid
[j
] != pBssid
[j
]){
1764 for (i
=0; i
<6; i
++){
1765 macp
->BSSInfo
[macp
->bss_index
].bssid
[i
] = pBssid
[i
];
1769 //get beacon interval
1770 pByte
= pMacBody
+BCN_INTERVAL_OFFSET
;
1771 macp
->BSSInfo
[macp
->bss_index
].beaconInterval
= ((*pByte
) + ((u16
)(*(pByte
+1))<<8));
1774 pByte
= pMacBody
+CAP_OFFSET
;
1775 macp
->BSSInfo
[macp
->bss_index
].cap
= ((*pByte
) + ((u16
)(*(pByte
+1))<<8) );
1778 pByte
= pMacBody
+SSID_OFFSET
;
1779 currPos
= SSID_OFFSET
;
1781 while(currPos
< bodyLen
){
1782 // To prevent incorrect elemId length (ex. 0)
1783 if(loopCheck
++ > 100)
1785 printk("infinite loop occurs in %s\n", __FUNCTION__
);
1789 elemLen
= *(pByte
+1);
1792 case ELEID_SSID
: //ssid
1793 for (i
=0; i
<elemLen
+2; i
++){
1794 macp
->BSSInfo
[macp
->bss_index
].ssid
[i
] = *pByte
;
1799 case ELEID_SUPRATES
: //supported rateS
1801 for (i
=0; i
<elemLen
+2; i
++){
1802 macp
->BSSInfo
[macp
->bss_index
].supRates
[i
] = *pByte
;
1808 case ELEID_DSPARMS
: //ds parameter
1809 macp
->BSSInfo
[macp
->bss_index
].channel
= *(pByte
+2);
1810 pByte
+= (elemLen
+2);
1813 case ELEID_EXT_RATES
:
1815 pByte
+= (elemLen
+2);
1820 pByte
+= (elemLen
+2);
1824 currPos
+= elemLen
+2;
1827 macp
->BSSInfo
[macp
->bss_index
].signalStrength
= macp
->rxSignalStrength
;
1828 macp
->BSSInfo
[macp
->bss_index
].signalQuality
= macp
->rxSignalQuality
;
1830 if (macp
->bss_index
< (BSS_INFO_NUM
-1)){
1837 void zd1205_dump_rfds(struct zd1205_private
*macp
)
1839 struct rx_list_elem
*rx_struct
= NULL
;
1840 struct list_head
*entry_ptr
= NULL
;
1841 zd1205_RFD_t
*rfd
= 0;
1842 struct sk_buff
*skb
;
1846 list_for_each(entry_ptr
, &(macp
->active_rx_list
)){
1848 rx_struct
= list_entry(entry_ptr
, struct rx_list_elem
, list_elem
);
1852 pci_dma_sync_single(macp
->pdev
, rx_struct
->dma_addr
,
1853 macp
->rfd_size
, PCI_DMA_FROMDEVICE
);
1855 skb
= rx_struct
->skb
;
1856 rfd
= RFD_POINTER(skb
, macp
); /* locate RFD within skb */
1858 printk(KERN_DEBUG
"zd1205: i = %x\n", i
);
1859 printk(KERN_DEBUG
"zd1205: rx_struct = %x\n", (u32
)rx_struct
);
1861 printk(KERN_DEBUG
"zd1205: rx_struct->dma_addr = %x\n", (u32
)rx_struct
->dma_addr
);
1862 printk(KERN_DEBUG
"zd1205: rx_struct->skb = %x\n", (u32
)rx_struct
->skb
);
1863 printk(KERN_DEBUG
"zd1205: rfd = %x\n", (u32
)rfd
);
1864 printk(KERN_DEBUG
"zd1205: CbStatus = %x\n", le32_to_cpu(rfd
->CbStatus
));
1866 printk(KERN_DEBUG
"zd1205: CbCommand = %x\n", le32_to_cpu(rfd
->CbCommand
));
1867 printk(KERN_DEBUG
"zd1205: NextCbPhyAddrLowPart = %x\n", le32_to_cpu(rfd
->NextCbPhyAddrLowPart
));
1868 printk(KERN_DEBUG
"zd1205: NextCbPhyAddrHighPart = %x\n", le32_to_cpu(rfd
->NextCbPhyAddrHighPart
));
1871 zd1205_dump_data("rfd", (u8
*)rfd
, 24);
1878 void zd1205_dump_data(char *info
, u8
*data
, u32 data_len
)
1881 printk(KERN_DEBUG
"%s data [%d]: \n", info
, data_len
);
1883 for (i
=0; i
<data_len
; i
++){
1884 printk(KERN_DEBUG
"%02x", data
[i
]);
1885 printk(KERN_DEBUG
" ");
1886 if ((i
>0) && ((i
+1)%16 == 0))
1887 printk(KERN_DEBUG
"\n");
1890 printk(KERN_DEBUG
"\n");
1896 * zd1205_get_rx_struct - retrieve cell to hold skb buff from the pool
1897 * @macp: atapter's private data struct
1900 * Returns the new cell to hold sk_buff or %NULL.
1903 static struct rx_list_elem
*
1904 zd1205_get_rx_struct(struct zd1205_private
*macp
)
1906 struct rx_list_elem
*rx_struct
= NULL
;
1908 if (!list_empty(&(macp
->rx_struct_pool
))) {
1910 rx_struct
= list_entry(macp
->rx_struct_pool
.next
,
1911 struct rx_list_elem
, list_elem
);
1912 list_del(&(rx_struct
->list_elem
));
1920 * zd1205_alloc_skb - allocate an skb for the adapter
1921 * @macp: atapter's private data struct
1923 * Allocates skb with enough room for rfd, and data, and reserve non-data space.
1924 * Returns the new cell with sk_buff or %NULL.
1927 static struct rx_list_elem
*
1928 zd1205_alloc_skb(struct zd1205_private
*macp
)
1930 struct sk_buff
*new_skb
;
1932 u32 skb_size
= sizeof (zd1205_RFD_t
);
1933 struct rx_list_elem
*rx_struct
;
1937 new_skb
= (struct sk_buff
*) dev_alloc_skb(skb_size
);
1939 /* The IP data should be
1940 DWORD aligned. since the ethernet header is 14 bytes long,
1941 we need to reserve 2 extra bytes so that the TCP/IP headers
1943 will be DWORD aligned. */
1944 //skb_reserve(new_skb, 2); //for zd1202, rx dma must be 4-bytes aligmnebt
1945 if ((rx_struct
= zd1205_get_rx_struct(macp
)) == NULL
)
1948 ZD1211DEBUG(4, "zd1211: rx_struct = %x\n", (u32
)rx_struct
);
1951 rx_struct
->skb
= new_skb
;
1953 //Rx DMA address must be 4 bytes alignment
1955 rx_struct
->dma_addr
= pci_map_single(macp
->pdev
, new_skb
->data
, sizeof (zd1205_RFD_t
), PCI_DMA_FROMDEVICE
);
1959 ZD1211DEBUG(4, "zd1211: rx_struct->dma_addr = %x\n", (u32
)rx_struct
->dma_addr
);
1962 if (!rx_struct
->dma_addr
)
1967 skb_reserve(new_skb
, macp
->rfd_size
); //now skb->data point to RxBuffer
1970 rx_struct
->dma_addr
= (u32
)new_skb
->data
;
1971 rx_struct
->UnFinishFrmLen
= 0;
1977 macp
->AllocSkbFailCnt
++;
1978 printk(KERN_DEBUG
"zd1205: dev_alloc_skb fail\n");
1983 printk(KERN_DEBUG
"zd1205: ****** err\n");
1984 dev_kfree_skb_any(new_skb
);
1991 * zd1205_add_skb_to_end - add an skb to the end of our rfd list
1993 * @macp: atapter's private data struct
1994 * @rx_struct: rx_list_elem with the new skb
1996 * Adds a newly allocated skb to the end of our rfd list.
2002 zd1205_add_skb_to_end(struct zd1205_private
*macp
, struct rx_list_elem
*rx_struct
)
2004 zd1205_RFD_t
*rfdn
; /* The new rfd */
2006 zd1205_RFD_t
*rfd
; /* The old rfd */
2007 struct rx_list_elem
*rx_struct_last
;
2012 (rx_struct
->skb
)->dev
= macp
->device
;
2013 rfdn
= RFD_POINTER(rx_struct
->skb
, macp
);
2015 rfdn
->CbCommand
= RFD_EL_BIT
;
2017 rfdn
->CbStatus
= 0xffffffff;
2019 rfdn
->ActualCount
= 0;
2020 rfdn
->MaxSize
= MAX_WLAN_SIZE
;
2022 rfdn
->NextCbPhyAddrHighPart
= 0;
2024 rfdn
->NextCbPhyAddrLowPart
= 0;
2030 pci_dma_sync_single(macp
->pdev
, rx_struct
->dma_addr
, macp
->rfd_size
,
2034 if (!list_empty(&(macp
->active_rx_list
))) {
2035 rx_struct_last
= list_entry(macp
->active_rx_list
.prev
,
2037 struct rx_list_elem
, list_elem
);
2040 rfd
= RFD_POINTER(rx_struct_last
->skb
, macp
);
2041 ZD1211DEBUG(4, "zd1211: rfd = %x\n", (u32
)rfd
);
2044 pci_dma_sync_single(macp
->pdev
, rx_struct_last
->dma_addr
,
2046 4, PCI_DMA_FROMDEVICE
);
2049 put_unaligned(rx_struct
->dma_addr
,
2050 ((u32
*) (&(rfd
->NextCbPhyAddrLowPart
))));
2053 pci_dma_sync_single(macp
->pdev
, rx_struct_last
->dma_addr
,
2054 8, PCI_DMA_TODEVICE
);
2063 pci_dma_sync_single(macp
->pdev
, rx_struct_last
->dma_addr
,
2064 4, PCI_DMA_TODEVICE
);
2069 list_add_tail(&(rx_struct
->list_elem
), &(macp
->active_rx_list
)); //add elem to active_rx_list
2074 void zd1205_alloc_skbs(struct zd1205_private
*macp
)
2076 for (; macp
->skb_req
> 0; macp
->skb_req
--) {
2077 struct rx_list_elem
*rx_struct
;
2079 if ((rx_struct
= zd1205_alloc_skb(macp
)) == NULL
){
2080 printk(KERN_DEBUG
"zd1205: zd1205_alloc_skb fail\n");
2084 zd1205_add_skb_to_end(macp
, rx_struct
);
2089 void zd1205_transmit_cleanup(struct zd1205_private
*macp
, zd1205_SwTcb_t
*sw_tcb
)
2091 zd1205_HwTCB_t
*hw_tcb
;
2093 zd1205_TBD_t
*tbd_arr
= sw_tcb
->pFirstTbd
;
2097 hw_tcb
= sw_tcb
->pTcb
;
2098 tbd_cnt
= hw_tcb
->TxCbTbdNumber
;
2099 tbd_arr
+= 2; //CtrlSetting and MacHeader
2101 ZD1211DEBUG(2, "zd1211: umap tbd cnt = %x\n", tbd_cnt
-2);
2104 for (i
=0; i
<tbd_cnt
-2; i
++, tbd_arr
++) {
2105 ZD1211DEBUG(2, "zd1211: umap body_dma = %x\n", le32_to_cpu(tbd_arr
->TbdBufferAddrLowPart
));
2106 pci_unmap_single(macp
->pdev
,
2107 le32_to_cpu(tbd_arr
->TbdBufferAddrLowPart
),
2108 le32_to_cpu(tbd_arr
->TbdCount
),
2113 ZD1211DEBUG(2, "zd1211: Free TcbPhys = %x\n", (u32
)sw_tcb
->TcbPhys
);
2114 zd1205_qlast_txq(macp
, macp
->freeTxQ
, sw_tcb
);
2115 ZD1211DEBUG(2, "zd1211: Cnt of freeTxQ = %x\n", macp
->freeTxQ
->count
);
2117 //sw_tcb->HangDur = 0;
2118 hw_tcb
->CbStatus
= 0xffffffff;
2119 hw_tcb
->TxCbTbdNumber
= 0xaaaaaaaa; /* for debug */
2120 hw_tcb
->CbCommand
= CB_S_BIT
;
2122 if ((netif_running(macp
->device
)) && (macp
->bAssoc
)){
2123 netif_carrier_on(macp
->device
);
2124 netif_wake_queue(macp
->device
); //resume tx
2131 void zd1205_tx_isr(struct zd1205_private
*macp
)
2133 #if ZDCONF_LP_SUPPORT == 1
2136 zd1205_SwTcb_t
*sw_tcb
= NULL
;
2139 zd1250_SwTcb_t
*next_sw_tcb
;
2144 int bRunOnce
= false;
2147 ZD1211DEBUG(2, "***** zd1205_tx_isr enter *****\n");
2149 if (!macp
->activeTxQ
->count
){
2150 printk(KERN_DEBUG
"No element in activeQ\n");
2151 clear_bit(ZD1211_TX_BUSY
, &macp
->flags
);
2155 /* Look at the TCB at the head of the queue. If it has been completed
2156 then pop it off and place it at the tail of the completed list.
2157 Repeat this process until all the completed TCBs have been moved to the
2159 while (macp
->activeTxQ
->count
){
2160 sw_tcb
= macp
->activeTxQ
->first
;
2163 // in USB modem, only run once
2168 // check to see if the TCB has been DMA'd
2170 // Workaround for hardware problem that seems leap over a TCB
2171 // and then fill completion token in the next TCB.
2172 ZD1211DEBUG(2, "zd1211: hw_tcb = %x\n", (u32
)sw_tcb
->pTcb
);
2173 ZD1211DEBUG(2, "zd1211: CbStatus = %x\n", (u16
)(sw_tcb
->pTcb
->CbStatus
));
2178 if ((u16
)le32_to_cpu(sw_tcb
->pTcb
->CbStatus
) != CB_STATUS_COMPLETE
){
2179 next_sw_tcb
= sw_tcb
;
2182 next_sw_tcb
= next_sw_tcb
->next
;
2186 if ((u16
)le32_to_cpu(next_sw_tcb
->pTcb
->CbStatus
) == CB_STATUS_COMPLETE
)
2195 /* Remove the TCB from the active queue. */
2196 sw_tcb
= zd1205_first_txq(macp
, macp
->activeTxQ
);
2197 //Clear bit should run once only. This depends on the "bRunOnce"
2198 //mechanism. Clear twice may interfer normal tx
2199 clear_bit(ZD1211_TX_BUSY
, &macp
->flags
);
2200 ZD1211DEBUG(2, "zd1211: Cnt of activeQ = %x\n", macp
->activeTxQ
->count
);
2203 zd1205_transmit_cleanup(macp
, sw_tcb
);
2206 if (!sw_tcb
->LastFrag
)
2209 #if ZDCONF_LP_SUPPORT == 1
2210 if(dot11Obj
.LP_MODE
&& sw_tcb
->LP_bucket
) {
2211 //printk("TX_ISR Free LP_bucket\n");
2212 struct lp_desc
*lp
= (struct lp_desc
*)sw_tcb
->LP_bucket
;
2213 for(i
=0;i
<lp
->pktCnt
;i
++) {
2214 //printk("msgID:%d\n", lp->pkt[i].msgID);
2215 zd_EventNotify(EVENT_TX_COMPLETE
, ZD_TX_CONFIRM
, (U32
)lp
->pkt
[i
].msgID
, (U32
)aid
);
2217 sw_tcb
->LP_bucket
= NULL
;
2222 lp_recycle_tx_bucket(lp
);
2227 zd_EventNotify(EVENT_TX_COMPLETE
, ZD_TX_CONFIRM
, (U32
)sw_tcb
->MsgID
, (U32
)aid
);
2230 macp
->SequenceNum
++;
2231 macp
->bDataTrafficLight
= 1;
2235 if(sw_tcb
->CalMIC
[MIC_LNG
] == TRUE
)
2236 zd1211_submit_tx_urb(macp
,TRUE
);
2238 zd1211_submit_tx_urb(macp
,FALSE
);
2241 ZD1211DEBUG(2, "***** zd1205_tx_isr exit *****\n");
2247 static void zd1205_retry_failed(struct zd1205_private
*macp
)
2249 zd1205_SwTcb_t
*sw_tcb
;
2250 zd1205_SwTcb_t
*next_sw_tcb
= NULL
;
2252 zd1205_HwTCB_t
*hw_tcb
;
2253 zd1205_Ctrl_Set_t
*ctrl_set
;
2255 u8 CurrentRate
, NewRate
;
2264 ZD1211DEBUG(2, "+++++ zd1205_retry_failed enter +++++\n");
2266 if (!macp
->activeTxQ
->count
){
2267 ZD1211DEBUG(1, "**********empty activeTxQ, got retry failed");
2268 sw_tcb
= macp
->freeTxQ
->first
;
2269 zd1205_start_download(sw_tcb
->TcbPhys
| BIT_0
);
2274 // Feature: Rate Adaption
2275 // - During the procedure of processing a transmitting frame, we must keep
2276 // the TaRate consistent.
2277 // - When to fall OppositeContext.CurrentTxRate:
2278 // Whenever RetryFail occurs, change OppositeContext.CurrentTxRate by a value
2279 // ((Rate of this TCB) minus a degree) and modify this TCB's control-setting
2280 // with the OppositeContext.CurrentTxRate and then Restart this TCB.
2281 // (Set RetryMAX = 2).
2282 // Once the TxRate is 1M and still RetryFail, abandon this frame.
2283 // - When to rise TxRate:
2284 // If there are 10 frames transmitted successfully
2285 // (OppositeContext.ConsecutiveSuccessFrames >= 10), change
2286 // OppositeContext.CurrentTxRate by a value
2287 // ((Rate of this TCB) plus a degree).
2290 // - Adjust OppositeContext.CurrentTxRate manually. (by application tool)
2291 sw_tcb
= macp
->activeTxQ
->first
;
2293 ctrl_set
= sw_tcb
->pHwCtrlPtr
;
2295 if (ctrl_set
->CtrlSetting
[11] & BIT_3
){ //management frame
2296 goto no_rate_adaption
;
2299 //CurrentRate = (ctrl_set->CtrlSetting[0] & 0x1f);
2301 CurrentRate
= sw_tcb
->Rate
;
2303 ShortPreambleFg
= (ctrl_set
->CtrlSetting
[0] & 0x20);
2305 if (((!ShortPreambleFg
) && (CurrentRate
> RATE_1M
)) ||
2306 ((ShortPreambleFg
) && (CurrentRate
> RATE_2M
))){
2307 // Fall TxRate a degree
2309 NewRate
= zd1205_RateAdaption(aid
, CurrentRate
, FALL_RATE
);
2310 sw_tcb
->Rate
= NewRate
;
2312 // Modify Control-setting
2313 ctrl_set
->CtrlSetting
[0] = (ShortPreambleFg
| NewRate
);
2314 ctrl_set
->CtrlSetting
[11] |= BIT_0
; // Set need backoff
2317 Len
= (ctrl_set
->CtrlSetting
[1] + ((u16
)ctrl_set
->CtrlSetting
[2] << 8));
2318 Cal_Us_Service(NewRate
, Len
, &LenInUs
, &Service
);
2319 ctrl_set
->CtrlSetting
[20] = (u8
)LenInUs
;
2320 ctrl_set
->CtrlSetting
[21] = (u8
)(LenInUs
>> 8);
2321 ctrl_set
->CtrlSetting
[22] = Service
;
2326 NextLen
= (ctrl_set
->CtrlSetting
[25+1] + ((u16
)ctrl_set
->CtrlSetting
[25+2] << 8));
2328 NextLen
= (ctrl_set
->CtrlSetting
[18] + ((u16
)ctrl_set
->CtrlSetting
[19] << 8));
2335 Cal_Us_Service(NewRate
, NextLen
, &NextLenInUs
, &Service
);
2336 ctrl_set
->CtrlSetting
[23] = (u8
)NextLenInUs
;
2337 ctrl_set
->CtrlSetting
[24] = (u8
)(NextLenInUs
>> 8);
2340 if (NewRate
> RATE_11M
){
2341 NewRate
= OfdmRateTbl
[NewRate
];
2344 macp
->retryFailCnt
++;
2346 ctrl_set
->CtrlSetting
[0] = (ShortPreambleFg
| NewRate
);
2347 ctrl_set
->CtrlSetting
[11] |= BIT_0
; // Set need backoff
2350 // Re-Start Tx-Bus master with a lower Rate
2352 zd1205_start_download(sw_tcb
->TcbPhys
| BIT_0
);
2358 /* Look at the TCB at the head of the queue. If it has been completed
2360 then pop it off and place it at the tail of the completed list.
2361 Repeat this process until all the completed TCBs have been moved to the
2365 while (macp
->activeTxQ
->count
){
2366 //ZD1211DEBUG(1, "zd1211: sw_tcb = %x\n", (u32)sw_tcb);
2367 ZD1211DEBUG(2, "zd1211: hw_tcb = %x\n", (u32
)sw_tcb
->pTcb
);
2370 /* Remove the TCB from the active queue. */
2371 sw_tcb
= zd1205_first_txq(macp
, macp
->activeTxQ
);
2373 ZD1211DEBUG(2, "zd1211: Cnt of activeQ = %x\n", macp
->activeTxQ
->count
);
2375 zd1205_transmit_cleanup(macp
, sw_tcb
);
2376 macp
->retryFailCnt
++;
2377 if (!sw_tcb
->LastFrag
)
2381 zd_EventNotify(EVENT_TX_COMPLETE
, ZD_RETRY_FAILED
, (U32
)sw_tcb
->MsgID
, aid
);
2383 if (!macp
->activeTxQ
->count
){
2384 // Re-Start Tx-Bus master with an suspend TCB
2385 hw_tcb
= (zd1205_HwTCB_t
*)sw_tcb
->pTcb
;
2386 // Set BIT_0 to escape from Retry-Fail-Wait State.
2387 zd1205_start_download((cpu_to_le32(hw_tcb
->NextCbPhyAddrLowPart
) | BIT_0
));
2389 next_sw_tcb
= macp
->activeTxQ
->first
;
2390 // Re-Start Tx bus master
2391 // Set BIT_0 to escape from Retry-Fail-Wait state.
2393 zd1205_start_download(next_sw_tcb
->TcbPhys
| BIT_0
);
2398 macp
->bIBSS_Wakeup_Dest
= 1;
2402 ZD1211DEBUG(2, "+++++ zd1205_retry_failed exit +++++\n");
2409 static void zd1205_config(struct zd1205_private
*macp
)
2417 // Retrieve Feature BitMap
2418 zd_writel(macp
->cardSetting
.EncryMode
, EncryptionType
);
2419 macp
->dtimCount
= 0;
2422 /* Setup Physical Address */
2423 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[0]), MACAddr_P1
);
2424 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[4]), MACAddr_P2
);
2425 if (macp
->cardSetting
.BssType
== AP_BSS
){
2426 /* Set bssid = MacAddress */
2427 macp
->BSSID
[0] = macp
->macAdr
[0];
2428 macp
->BSSID
[1] = macp
->macAdr
[1];
2429 macp
->BSSID
[2] = macp
->macAdr
[2];
2430 macp
->BSSID
[3] = macp
->macAdr
[3];
2431 macp
->BSSID
[4] = macp
->macAdr
[4];
2432 macp
->BSSID
[5] = macp
->macAdr
[5];
2433 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[0]), BSSID_P1
);
2434 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[4]), BSSID_P2
);
2437 zd_writel(STA_RX_FILTER
, ZD_Rx_Filter
);
2441 macp
->intrMask
= ZD1205_INT_MASK
;
2443 if (macp
->intrMask
& DTIM_NOTIFY_EN
)
2444 macp
->dtim_notify_en
= 1;
2446 macp
->dtim_notify_en
= 0;
2449 if (macp
->intrMask
& CFG_NEXT_BCN_EN
)
2451 macp
->config_next_bcn_en
= 1;
2453 macp
->config_next_bcn_en
= 0;
2457 zd1205_ClearTupleCache(macp
);
2458 zd1205_ArReset(macp
);
2460 macp
->bTraceSetPoint
= 1;
2461 macp
->bFixedRate
= 0;
2462 dot11Obj
.bDeviceInSleep
= 0;
2464 macp
->bGkInstalled
= 0;
2465 macp
->PwrState
= PS_CAM
;
2467 // Get Allowed Channel and Default Channel
2468 dot11Obj
.AllowedChannel
= zd_readl(ZD_E2P_ALLOWED_CHANNEL
);
2470 dot11Obj
.AllowedChannel
= 0x7FF;
2472 ZD1211DEBUG(0, "AllowedChannel = %08x\n", (u32
)dot11Obj
.AllowedChannel
);
2474 if (!(dot11Obj
.AllowedChannel
& 0xFFFF0000)){
2475 dot11Obj
.AllowedChannel
|= 0x10000;
2480 tmpValue
= zd_readl(E2P_SUBID
);
2481 macp
->RegionCode
= (u16
)(tmpValue
>> 16);
2483 dot11Obj
.RegionCode
= macp
->RegionCode
;
2484 macp
->LinkLEDn
= LED1
;
2485 if (macp
->RF_Mode
& BIT_4
){
2488 macp
->LinkLEDn
= LED2
;
2489 ZD1211DEBUG(0, "LED2\n");
2491 ZD1211DEBUG(0, "LinkLEDn = %x\n", macp
->LinkLEDn
);
2493 if (macp
->RF_Mode
& BIT_8
){
2495 dot11Obj
.bOverWritePhyRegFromE2P
= 1;
2496 ZD1211DEBUG(0, "OverWritePhyRegFromE2P\n");
2502 if (macp
->RF_Mode
& BIT_9
){
2503 dot11Obj
.bIsNormalSize
= 1;
2504 ZD1211DEBUG(0, "NormalSize\n");
2507 macp
->LinkLED_OnDur
= 2;
2508 macp
->LinkLED_OffDur
= 1;
2510 if (macp
->RF_Mode
& BIT_24
){
2512 macp
->LinkLED_OnDur
= ((macp
->RF_Mode
) >> 25) & 0x3;
2513 macp
->LinkLED_OffDur
= ((macp
->RF_Mode
) >> 27) & 0x3;
2514 if (macp
->RF_Mode
& BIT_29
)
2517 ZD1211DEBUG(1, "LinkLED_OnDur = %d\n", macp
->LinkLED_OnDur
);
2519 ZD1211DEBUG(1, "LinkLED_OffDur = %d\n", macp
->LinkLED_OffDur
);
2521 if (!(macp
->RF_Mode
& BIT_10
)){ // The IPC protection: the default is disablesd
2525 macp
->RF_Mode
&= 0x0f;
2527 tmpValue
= zd_readl(FW_USB_SPEED
);
2528 dot11Obj
.IsUSB2_0
= (u8
) tmpValue
;
2530 dot11Obj
.bIsNormalSize
= 1;
2531 dot11Obj
.IsUSB2_0
= 1;
2534 printk("AllowedChannel = %08x\n", (u32
)dot11Obj
.AllowedChannel
);
2535 printk("Region:%u\n",(u32
) dot11Obj
.RegionCode
);
2538 ZD1211DEBUG(1, "IsUSB2_0 = %d\n", dot11Obj
.IsUSB2_0
);
2539 // read Set Point from EEPROM
2541 tmpValue
= zd_readl(ZD_E2P_PWR_INT_VALUE1
);
2542 tmpValue
-= cPWR_INT_VALUE_GUARD
;
2543 dot11Obj
.IntValue
[0] = (u8
)tmpValue
;
2544 dot11Obj
.IntValue
[1] = (u8
)(tmpValue
>> 8);
2546 dot11Obj
.IntValue
[2] = (u8
)(tmpValue
>> 16);
2547 dot11Obj
.IntValue
[3] = (u8
)(tmpValue
>> 24);
2549 tmpValue
= zd_readl(ZD_E2P_PWR_INT_VALUE2
);
2550 tmpValue
-= cPWR_INT_VALUE_GUARD
;
2551 dot11Obj
.IntValue
[4] = (u8
)tmpValue
;
2552 dot11Obj
.IntValue
[5] = (u8
)(tmpValue
>> 8);
2553 dot11Obj
.IntValue
[6] = (u8
)(tmpValue
>> 16);
2554 dot11Obj
.IntValue
[7] = (u8
)(tmpValue
>> 24);
2556 tmpValue
= zd_readl(ZD_E2P_PWR_INT_VALUE3
);
2557 tmpValue
-= cPWR_INT_VALUE_GUARD
;
2558 dot11Obj
.IntValue
[8] = (u8
)tmpValue
;
2559 dot11Obj
.IntValue
[9] = (u8
)(tmpValue
>> 8);
2560 dot11Obj
.IntValue
[10] = (u8
)(tmpValue
>> 16);
2561 dot11Obj
.IntValue
[11] = (u8
)(tmpValue
>> 24);
2563 tmpValue
= zd_readl(ZD_E2P_PWR_INT_VALUE4
);
2564 tmpValue
-= cPWR_INT_VALUE_GUARD
;
2565 dot11Obj
.IntValue
[12] = (u8
)tmpValue
;
2566 dot11Obj
.IntValue
[13] = (u8
)(tmpValue
>> 8);
2568 //Initiate a_Calibration_Data CH field
2569 for (i
=0;i
<a_CALIBRATED_CH_NUM
;i
++){
2570 if((i
== 0) || ((i
!= 0) && (a_ChannelMap
[i
-1] != a_ChannelMap
[i
]))){
2571 a_Calibration_Data
[0][i
] = a_ChannelMap
[i
];
2574 a_Calibration_Data
[0][i
] = 0xff;
2577 //Initiate a_Interpolation_Data CH field
2578 for (i
=0;i
<a_INTERPOLATION_CH_NUM
;i
++)
2579 a_Interpolation_Data
[0][i
] = a_InterpolationTbl
[i
].a_Channel
;
2581 for (i
=0;i
<a_CALIBRATED_CH_NUM
;i
++){
2582 //Adapter->a_Calibration_Data[0][i] = a_ChannelMap[i];
2583 if(a_Calibration_Data
[0][i
] != 0xff){
2584 a_Calibration_Data
[1][i
] = a_get_cal_int_val((u8
)i
) - cPWR_INT_VALUE_GUARD
;
2585 a_Calibration_Data
[2][i
] = a_get_cal_36M_setpoint_val((u8
)i
);
2586 a_Calibration_Data
[3][i
] = a_get_cal_48M_54M_setpoint_val((u8
)i
);
2589 a_Calibration_Data
[1][i
] = 0xff;
2590 a_Calibration_Data
[2][i
] = 0xff;
2591 a_Calibration_Data
[3][i
] = 0xff;
2596 //Calculate Interpolation SetPoints(For 802.11a)
2597 for (i
=0;i
<a_INTERPOLATION_CH_NUM
;i
++){
2598 //Adapter->a_Interpolation_Data[0][i] = a_InterpolationTbl[i].a_Channel;
2599 if(a_InterpolationTbl
[i
].Left_Most_Channel
== a_InterpolationTbl
[i
].Right_Most_Channel
){
2600 for (jj
=0;jj
<a_CALIBRATED_CH_NUM
;jj
++){
2601 if(a_Calibration_Data
[0][jj
] == a_InterpolationTbl
[i
].Left_Most_Channel
){
2602 a_Interpolation_Data
[1][i
] = a_Calibration_Data
[1][jj
];
2603 a_Interpolation_Data
[2][i
] = a_Calibration_Data
[2][jj
];
2604 a_Interpolation_Data
[3][i
] = a_Calibration_Data
[3][jj
];
2605 }//Directly used certain calibrated channel values
2609 if(0xff == a_get_interpolation_value((u8
)i
, &a_Interpolation_Data
[1][i
],
2610 &a_Interpolation_Data
[2][i
], &a_Interpolation_Data
[3][i
]))
2611 printk("Get Int/Cal wrong in Interpolation Tbl(%d)\n",i
);
2614 //End Calculate Interpolation SetPoints(For 802.11a)
2619 for (jj
= 0; jj
< 3; jj
++){
2621 for (i
= 0; i
< 4; i
++){
2622 tmpValue
= zd_readl(E2P_36M_CAL_VALUE
+ jj
*0x20 + i
*4);
2623 macp
->SetPointOFDM
[jj
][i
*4] = (u8
) tmpValue
;
2624 macp
->SetPointOFDM
[jj
][i
*4+1] = (u8
) (tmpValue
>> 8);
2626 macp
->SetPointOFDM
[jj
][i
*4+2] = (u8
) (tmpValue
>> 16);
2627 macp
->SetPointOFDM
[jj
][i
*4+3] = (u8
) (tmpValue
>> 24);
2634 zd_writel(0x00000064,ZD_BCNInterval
);
2635 HW_UpdateBcnInterval(&dot11Obj
, 0x00000064);
2637 // read Set Point from EEPROM
2638 tmpValue
= zd_readl(ZD_E2P_PWR_CAL_VALUE1
);
2639 macp
->EepSetPoint
[0] = (u8
)tmpValue
;
2640 macp
->EepSetPoint
[1] = (u8
)(tmpValue
>> 8);
2641 macp
->EepSetPoint
[2] = (u8
)(tmpValue
>> 16);
2642 macp
->EepSetPoint
[3] = (u8
)(tmpValue
>> 24);
2644 tmpValue
= zd_readl(ZD_E2P_PWR_CAL_VALUE2
);
2646 macp
->EepSetPoint
[4] = (u8
)tmpValue
;
2648 macp
->EepSetPoint
[5] = (u8
)(tmpValue
>> 8);
2649 macp
->EepSetPoint
[6] = (u8
)(tmpValue
>> 16);
2650 macp
->EepSetPoint
[7] = (u8
)(tmpValue
>> 24);
2653 tmpValue
= zd_readl(ZD_E2P_PWR_CAL_VALUE3
);
2654 macp
->EepSetPoint
[8] = (u8
)tmpValue
;
2656 macp
->EepSetPoint
[9] = (u8
)(tmpValue
>> 8);
2657 macp
->EepSetPoint
[10] = (u8
)(tmpValue
>> 16);
2658 macp
->EepSetPoint
[11] = (u8
)(tmpValue
>> 24);
2660 tmpValue
= zd_readl(ZD_E2P_PWR_CAL_VALUE4
);
2661 macp
->EepSetPoint
[12] = (u8
)tmpValue
;
2662 macp
->EepSetPoint
[13] = (u8
)(tmpValue
>> 8);
2664 HW_SetRfChannel(&dot11Obj
, (dot11Obj
.AllowedChannel
>> 16), 0, MIXED_MODE
);
2665 // For Antenna Diversity Parameters
2666 macp
->bEnableSwAntennaDiv
= 0;
2667 macp
->Ant_MonitorDur1
= 10;//100;
2668 macp
->Ant_MonitorDur2
= 1;
2669 macp
->NiceSQThr
= 48;
2671 macp
->rxOffset
= ZD_RX_OFFSET
;
2673 macp
->bPSMSupported
= 0;
2674 macp
->NormalBackoff
= 0x7f047f;
2675 macp
->UrgentBackoff
= 0x7f0407;
2676 macp
->LooseBackoff
= 0x7f107f;
2677 macp
->WorseSQThr
= 0x48;
2678 macp
->MulticastAddr
[0] = 0;
2681 macp
->EnableTxPwrCtrl
= 1;
2682 macp
->PSThreshhold
= 10000;
2685 // macp->NiceSQThr_OFDM = 12 * 4; // 12 dB --> 48 %
2686 macp
->NiceSQThr_OFDM
= 48; // 48 %
2687 macp
->bEnableSwAntennaDiv
= 1;
2691 macp
->FlashType
= 0xFF;
2696 macp
->PHYTestIndex
= 5;
2697 macp
->PHYTestRssiBound
= 0x3a;
2698 macp
->PHYTestTimer
= 30;
2699 macp
->TrafficBound
= 200;
2701 macp
->PHYLowPower
= 3; // Tx/Rx enable
2702 dot11Obj
.CR122Flag
= 2; // initial value
2704 dot11Obj
.CR31Flag
= 2; // initial value
2705 dot11Obj
.CR203Flag
= 2; // initial value
2706 dot11Obj
.PhyTest
= 4;
2707 macp
->AdapterMaxRate
= 0x0B; // initail max rate = 54M
2712 int zd1205_dis_connect(struct zd1205_private
*macp
)
2716 ZD1211DEBUG(0, "zd1205_dis_connect\n");
2718 netif_carrier_off(macp
->device
);
2719 netif_stop_queue(macp
->device
);
2721 // Note: The following sequence is important, do not change it arbitrarily.
2723 macp
->PwrState
= PS_CAM
;
2726 down(&macp
->bcn_sem
);
2727 tmpvalue
= zd_readl(ZD_BCNInterval
);
2728 tmpvalue
&= ~POWER_MNT
;
2729 zd_writel(tmpvalue
, ZD_BCNInterval
);
2734 while (dot11Obj
.bDeviceInSleep
){
2736 //if (macp->Notification & RQ_TERMINATION){
2743 if (dot11Obj
.bDeviceInSleep
){
2744 ZD1211DEBUG(1, "Device in sleep\n");
2751 // After all pending packets are served, then notify NDIS with
2753 // Otherwise, it might cause IP Address = 0.0.0.0
2756 while (macp
->activeTxQ
->count
){
2757 // After this step, we can make sure that no ATIM pended.
2759 //if (macp->Notification & RQ_TERMINATION){
2764 //if (macp->activeTxQ->count){
2765 // ZD1211DEBUG(1, "activeTxQ not empty\n");
2773 zd_EventNotify(EVENT_PS_CHANGE
, (u8
)macp
->PwrState
, 0, 0);
2775 // IBSS = 0, i.e, stop sending beacon.
2776 down(&macp
->bcn_sem
);
2777 tmpvalue
= zd_readl(ZD_BCNInterval
);
2778 tmpvalue
&= ~IBSS_MODE
;
2779 zd_writel(tmpvalue
, ZD_BCNInterval
);
2781 zd1205_notify_disjoin_event(macp
);
2784 // We may need issue disassociate frame.
2785 // Issue notification
2794 static void zd1205_dtim_notify(
2795 struct zd1205_private
*macp
2800 zd1205_SwTcb_t
*sw_tcb
;
2803 zd_EventNotify(EVENT_DTIM_NOTIFY
, 0, 0, 0);
2804 if (!macp
->activeTxQ
->count
)
2805 sw_tcb
= macp
->freeTxQ
->first
;
2807 sw_tcb
= macp
->activeTxQ
->first
;
2810 tmp_value
= zd_readl(DeviceState
);
2812 zd1205_start_download(sw_tcb
->TcbPhys
| BIT_0
);
2817 void zd1205_config_wep_keys(struct zd1205_private
*macp
)
2819 card_Setting_t
*pSetting
= &macp
->cardSetting
;
2821 u8 encryMode
= pSetting
->EncryMode
;
2823 u8 DynKeyMode
= pSetting
->DynKeyMode
;
2826 if ((encryMode
== 0) || (DynKeyMode
!= 0)){
2827 HW_CAM_Write(&dot11Obj
, DEFAULT_ENCRY_TYPE
, NO_WEP
);
2831 if (pSetting
->OperationMode
!= CAM_AP_VAP
){
2832 HW_CAM_ResetRollTbl(&dot11Obj
); //force CAM to use default encry type
2836 ZD1211DEBUG(0, "WEP64 Mode\n");
2841 ZD1211DEBUG(0, "WEP128 Mode\n");
2846 ZD1211DEBUG(0, "WEP256 Mode\n");
2851 ZD1211DEBUG(0, "Not supported Mode\n");
2852 ZD1211DEBUG(0, "encryMode = %d\n", encryMode
);
2857 HW_CAM_Write(&dot11Obj
, DEFAULT_ENCRY_TYPE
, encryMode
);
2859 for (i
=0, j
=0; i
<4; i
++, j
+=8){ //one key occupy 32 bytes space
2860 HW_ConfigStatKey(&dot11Obj
, &pSetting
->keyVector
[i
][0], keyLength
, STA_KEY_START_ADDR
+j
);
2866 void zd1205_config_dyn_key(u8 DynKeyMode
, u8
*pkey
, int idx
)
2872 HW_CAM_ResetRollTbl(&dot11Obj
); //force CAM to use default encry type
2876 WPADEBUG("Dynamic key TKIP mode\n");
2882 WPADEBUG("Dynamic key AES mode\n");
2888 WPADEBUG("Do not support the Dynamic key mode = %d\n", DynKeyMode
);
2892 /* The size for each key is 256 bits (32 bytes) */
2895 HW_CAM_Write(&dot11Obj
, DEFAULT_ENCRY_TYPE
, encryMode
);
2896 HW_ConfigStatKey(&dot11Obj
, pkey
, keyLength
, STA_KEY_START_ADDR
+offset
);
2903 #if defined CONFIG_ARCH_W341 || defined CONFIG_ARCH_W321 || defined CONFIG_ARCH_W311
2910 #define MCPU_GPIO_INPUT 0
2911 #define MCPU_GPIO_OUTPUT 1
2912 #define MCPU_GPIO_HIGH 1
2913 #define MCPU_GPIO_LOW 0
2915 #elif defined CONFIG_ARCH_W311
2916 #define WLAN_LED_REG CPE_WLAN_LED_REG_VA_BASE
2923 #define PIO(x) (1<<x)
2926 static int zd1205_validate_frame(struct zd1205_private
*macp
, zd1205_RFD_t
*rfd
)
2928 plcp_wla_Header_t
*wla_hdr
;
2935 //u8 rx_offset = macp->rxOffset;
2938 #if ZDCONF_WE_STAT_SUPPORT == 1
2940 static U8 Qual
[10]={0,0,0,0,0,0,0,0,0,0};
2941 static U8 Str
[10]={0,0,0,0,0,0,0,0,0,0};
2943 #elif !defined(ZDCONF_WE_STAT_SUPPORT)
2944 #error "Undefine ZDCONF_WE_STAT_SUPPORT"
2950 /*********************************************************************/
2951 /* Signal Quality | Signal Strength | Signal Quality2 | Noise Report */
2952 /*********************************************************************/
2954 /*****************************************************/
2955 /* DA Index | SA Index | Rx Decrypt Type | Rx Status */
2956 /*****************************************************/
2958 // Accept Data/Management frame only.
2959 wla_hdr
= (plcp_wla_Header_t
*)&rfd
->RxBuffer
[macp
->rxOffset
];
2961 tot_len
=(rfd
->ActualCount
) & 0x3fff;
2962 len
= tot_len
- EXTRA_INFO_LEN
;
2963 frame_len
= tot_len
- macp
->rxOffset
;
2965 PlcpRate
= wla_hdr
->PlcpHdr
[0];
2967 if (frame_len
== 0){
2968 macp
->ErrZeroLenFrmCnt
++;
2972 //pSwRfd->pRfd->RxBuffer[frameLen+rxOffset-1]
2975 //bit5: address not match
2977 //bit3: decrypt error
2982 //bit0: OFDM modulation
2984 macp
->rxDecryType
= rfd
->RxBuffer
[tot_len
-2];
2985 FrameEndInd
= rfd
->RxBuffer
[tot_len
-1];
2986 if (FrameEndInd
& BIT_7
){
2987 macp
->ErrToHostFrmCnt
++;
2991 if (bWepBit(wla_hdr
)){
2992 //if (macp->cardSetting.EncryMode == ENCRY_TKIP)
2996 if (frame_len
< min_length
){
2997 //printk(KERN_DEBUG "frame_len = %x\n", frame_len);
2998 macp
->ErrShortFrmCnt
++;
3003 // Minimum Length = PLCP(5)+MACHeader(24)+EXTINFO(5)+CRC(4)
3004 if (frame_len
< 36){
3005 //printk(KERN_DEBUG "frame_len = %x\n", frame_len);
3006 macp
->ErrShortFrmCnt
++;
3011 // Check if frame_len > MAX_WLAN_SIZE.
3012 if (frame_len
> ZD_MAX_WLAN_SIZE
){
3013 // Do not worry about the corruption of HwRfd.
3014 // If the frame_len > 2410, the Rx-Bus-Master skip the bytes that exceed
3015 // 2410 to protect the structure of HwRfd.
3016 // However, the Rx-Bus-Master still reports this frame to host if the frame
3017 // is recognized as good by the FA(Frame Analyzer).
3018 macp
->ErrLongFrmCnt
++;
3022 // Check if the SwRfd->frame_len matched the length derived from PLCP.
3023 bOfdmFrm
= (FrameEndInd
& BIT_0
);
3027 macp
->rxOFDMDataFrame
++;
3029 macp
->PHYFreOFDMframe
= 1;
3031 switch(PlcpRate
& 0xF){
3034 macp
->rxInfo
.rate
= RATE_6M
;
3038 macp
->rxInfo
.rate
= RATE_9M
;
3043 macp
->rxInfo
.rate
= RATE_12M
;
3048 macp
->rxInfo
.rate
= RATE_18M
;
3053 macp
->rxInfo
.rate
= RATE_24M
;
3057 macp
->rxInfo
.rate
= RATE_36M
;
3061 macp
->rxInfo
.rate
= RATE_48M
;
3065 macp
->rxInfo
.rate
= RATE_54M
;
3075 macp
->rx11bDataFrame
++;
3076 // the value from PHY is in scale from Max is 0 and Min is 0xb5
3080 macp
->rxInfo
.rate
= RATE_1M
;
3084 macp
->rxInfo
.rate
= RATE_2M
;
3088 macp
->rxInfo
.rate
= RATE_5M
;
3092 macp
->rxInfo
.rate
= RATE_11M
;
3100 //The Padding Information is Quality1, Strength, Quality2....
3101 //The document is incorrect.
3102 macp
->rxSignalQuality
= rfd
->RxBuffer
[len
];
3103 macp
->rxSignalQuality1
= macp
->rxSignalQuality
;
3104 macp
->rxSignalStrength
= rfd
->RxBuffer
[len
+1];
3105 macp
->rxSignalQuality2
= rfd
->RxBuffer
[len
+2];
3106 //macp->rxNoiseReport = rfd->RxBuffer[len+3]; //3d31
3109 macp
->rxSignalQuality
= CalculateQuality(macp
, rfd
, &macp
->rxSignalQualityIndB
);
3110 macp
->rxSignalStrength
= CalculateStrength(macp
, rfd
);
3112 #if ZDCONF_WE_STAT_SUPPORT == 1
3113 Qual
[Qidx
++ % 10] = macp
->rxSignalQuality
;
3114 Str
[Qidx
% 10] = macp
->rxSignalStrength
;
3116 if(Qidx
% 100 == 0) {
3118 for(idx
=0;idx
<10;idx
++)
3120 macp
->iwstats
.qual
.qual
=Tmp
/10;
3123 for(idx
=0;idx
<10;idx
++)
3128 Tmp
= Tmp
> -40 ? -40: Tmp
;
3129 Tmp
= Tmp
< -105 ? -105: Tmp
;
3130 Tmp
= (Tmp
+ 105)*100/65;
3131 macp
->iwstats
.qual
.level
= Tmp
;
3132 /* Only valid in ZD1212
3133 Tmp = -(100 - rfd->RxBuffer[len+3]);
3134 Tmp = Tmp > -40 ? -40: Tmp;
3135 Tmp = Tmp < -105 ? -105: Tmp;
3136 Tmp = (Tmp + 105)*100/65;
3137 macp->iwstats.qual.noise= Tmp;
3141 #elif !defined(ZDCONF_WE_STAT_SUPPORT)
3142 #error "Undefine ZDCONF_WE_STAT_SUPPORT"
3145 macp
->rxInfo
.signalQuality
= macp
->rxSignalQuality
;
3146 macp
->rxInfo
.signalStrength
= macp
->rxSignalStrength
;
3148 //prince add for led begin
3149 #if defined(CONFIG_ARCH_W341) || defined(CONFIG_ARCH_W321)|| defined(CONFIG_ARCH_W311)
3150 #define LED_GPIO ((1<<WLAN_LED)|(1<<ST1_LED)|(1<<ST2_LED)|(1<<ST3_LED)|(1<<ST4_LED)|(1<<ST5_LED))
3151 #if 0 // mask by Victor Yu. 04-04-2007
3152 mcpu_gpio_inout(1<<WLAN_LED
,MCPU_GPIO_OUTPUT
);
3153 mcpu_gpio_inout(1<<ST1_LED
,MCPU_GPIO_OUTPUT
);
3154 mcpu_gpio_inout(1<<ST2_LED
,MCPU_GPIO_OUTPUT
);
3155 mcpu_gpio_inout(1<<ST3_LED
,MCPU_GPIO_OUTPUT
);
3156 mcpu_gpio_inout(1<<ST4_LED
,MCPU_GPIO_OUTPUT
);
3157 mcpu_gpio_inout(1<<ST5_LED
,MCPU_GPIO_OUTPUT
);
3159 mcpu_gpio_inout(LED_GPIO
,MCPU_GPIO_OUTPUT
);
3161 if(macp
->led_cnt
== 10)
3163 #if 0 // mask by Victor Yu. 04-04-2007
3164 mcpu_gpio_set(1<<ST1_LED
, MCPU_GPIO_HIGH
);
3165 mcpu_gpio_set(1<<ST2_LED
, MCPU_GPIO_HIGH
);
3166 mcpu_gpio_set(1<<ST3_LED
, MCPU_GPIO_HIGH
);
3167 mcpu_gpio_set(1<<ST4_LED
, MCPU_GPIO_HIGH
);
3168 mcpu_gpio_set(1<<ST5_LED
, MCPU_GPIO_HIGH
);
3170 mcpu_gpio_set(1<<WLAN_LED
, MCPU_GPIO_LOW
);
3172 if(macp
->rxSignalStrength
>0)
3173 mcpu_gpio_set(1<<ST1_LED
, MCPU_GPIO_LOW
);
3174 if(macp
->rxSignalStrength
>20)
3175 mcpu_gpio_set(1<<ST2_LED
, MCPU_GPIO_LOW
);
3176 if(macp
->rxSignalStrength
>40)
3177 mcpu_gpio_set(1<<ST3_LED
, MCPU_GPIO_LOW
);
3178 if(macp
->rxSignalStrength
>60)
3179 mcpu_gpio_set(1<<ST4_LED
, MCPU_GPIO_LOW
);
3180 if(macp
->rxSignalStrength
>70)
3181 mcpu_gpio_set(1<<ST5_LED
, MCPU_GPIO_LOW
);
3184 u32 pio
=1<<WLAN_LED
;;
3185 u8 strength
=macp
->rxSignalStrength
;
3187 pio
|= (1<<ST1_LED
);
3189 pio
|= (1<<ST2_LED
);
3191 pio
|= (1<<ST3_LED
);
3193 pio
|= (1<<ST4_LED
);
3195 pio
|= (1<<ST5_LED
);
3196 mcpu_gpio_set(LED_GPIO
, MCPU_GPIO_HIGH
);
3197 mcpu_gpio_set(pio
, MCPU_GPIO_LOW
);
3204 #elif defined(CONFIG_ARCH_W311)
3205 #define LED_PIO (PIO(WLAN_LED)|PIO(STR1_LED)|PIO(STR2_LED)|PIO(STR3_LED)|PIO(STR4_LED)|PIO(STR5_LED))
3206 if(macp
->led_cnt
== 10)
3208 #if 0 // mask by Victor Yu. 04-04-2007
3209 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
| ~PIO(WLAN_LED
) ;
3210 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
& PIO(STR1_LED
);
3211 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
& PIO(STR2_LED
);
3212 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
& PIO(STR3_LED
);
3213 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
& PIO(STR4_LED
);
3214 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
& PIO(STR5_LED
);
3216 if(macp
->rxSignalStrength
>0)
3217 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
| ~PIO(STR1_LED
);
3218 if(macp
->rxSignalStrength
>20)
3219 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
| ~PIO(STR2_LED
);
3220 if(macp
->rxSignalStrength
>40)
3221 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
| ~PIO(STR3_LED
);
3222 if(macp
->rxSignalStrength
>60)
3223 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
| ~PIO(STR4_LED
);
3224 if(macp
->rxSignalStrength
>70)
3225 *(volatile unsigned char *)WLAN_LED_REG
= *(volatile unsigned char *)WLAN_LED_REG
| ~PIO(STR5_LED
);
3228 unsigned char pio
=PIO(WLAN_LED
);
3229 u8 strength
=macp
->rxSignalStrength
;
3231 pio
|= PIO(STR1_LED
);
3233 pio
|= PIO(STR2_LED
);
3235 pio
|= PIO(STR3_LED
);
3237 pio
|= PIO(STR4_LED
);
3239 pio
|= PIO(STR5_LED
);
3240 *(volatile unsigned char *)WLAN_LED_REG
= LED_PIO
;
3241 *(volatile unsigned char *)WLAN_LED_REG
= ~pio
;
3249 //prince add for led end
3256 * zd1205_alloc_tcb_pool - allocate TCB circular list
3257 * @macp: atapter's private data struct
3259 * This routine allocates memory for the circular list of transmit descriptors.
3262 * 0: if allocation has failed.
3267 zd1205_alloc_tcb_pool(struct zd1205_private
*macp
)
3269 /* deal with Tx uncached memory */
3270 /* Allocate memory for the shared transmit resources with enough extra mem
3271 * to paragraph align (4-byte alignment) everything */
3273 macp
->txUnCachedSize
= (macp
->numTcb
*
3274 (sizeof(zd1205_HwTCB_t
)+ sizeof(zd1205_Ctrl_Set_t
)+sizeof(zd1205_Header_t
)))
3275 + (macp
->numTbd
* sizeof(zd1205_TBD_t
));
3278 if (!(macp
->txUnCached
= pci_alloc_consistent(macp
->pdev
,
3279 macp
->txUnCachedSize
, &(macp
->txUnCachedPhys
)))) {
3283 macp
->txUnCached
= kmalloc(macp
->txUnCachedSize
, GFP_ATOMIC
);
3284 if (!macp
->txUnCached
){
3285 printk(KERN_ERR
"zd1205: kmalloc txCached failed\n");
3290 memset(macp
->txUnCached
, 0x00, macp
->txUnCachedSize
);
3295 zd1205_free_tcb_pool(struct zd1205_private
*macp
)
3299 pci_free_consistent(macp
->pdev
, macp
->txUnCachedSize
,
3301 macp
->txUnCached
, macp
->txUnCachedPhys
);
3303 if (macp
->txUnCached
)
3304 kfree(macp
->txUnCached
);
3307 macp
->txUnCachedPhys
= 0;
3314 zd1205_free_rfd_pool(struct zd1205_private
*macp
)
3316 struct rx_list_elem
*rx_struct
;
3318 while (!list_empty(&(macp
->active_rx_list
))) {
3319 rx_struct
= list_entry(macp
->active_rx_list
.next
,
3320 struct rx_list_elem
, list_elem
);
3321 list_del(&(rx_struct
->list_elem
));
3325 pci_unmap_single(macp
->pdev
, rx_struct
->dma_addr
,
3327 sizeof (zd1205_RFD_t
), PCI_DMA_TODEVICE
);
3328 dev_kfree_skb(rx_struct
->skb
);
3330 if(rx_struct
->skb
)dev_kfree_skb_any
/**/(rx_struct
->skb
);
3337 while (!list_empty(&(macp
->rx_struct_pool
))) {
3338 rx_struct
= list_entry(macp
->rx_struct_pool
.next
,
3339 struct rx_list_elem
, list_elem
);
3340 list_del(&(rx_struct
->list_elem
));
3349 * zd1205_alloc_rfd_pool - allocate RFDs
3350 * @macp: atapter's private data struct
3353 * Allocates initial pool of skb which holds both rfd and data,
3354 * and return a pointer to the head of the list
3360 zd1205_alloc_rfd_pool(struct zd1205_private
*macp
)
3362 struct rx_list_elem
*rx_struct
;
3367 INIT_LIST_HEAD(&(macp
->active_rx_list
));
3368 INIT_LIST_HEAD(&(macp
->rx_struct_pool
));
3369 macp
->skb_req
= macp
->numRfd
;
3372 for (i
= 0; i
< macp
->skb_req
; i
++) {
3373 rx_struct
= kmalloc(sizeof (struct rx_list_elem
), GFP_ATOMIC
);
3374 list_add(&(rx_struct
->list_elem
), &(macp
->rx_struct_pool
));
3377 zd1205_alloc_skbs(macp
);
3378 return !list_empty(&(macp
->active_rx_list
));
3384 zd1205_clear_pools(struct zd1205_private
*macp
)
3386 zd1205_dealloc_space(macp
);
3387 zd1205_free_rfd_pool(macp
);
3389 zd1205_free_tcb_pool(macp
);
3394 * zd1205_start_ru - start the RU if needed
3395 * @macp: atapter's private data struct
3397 * This routine checks the status of the receive unit(RU),
3398 * and starts the RU if it was not already active. However,
3399 * before restarting the RU, the driver gives the RU the buffers
3400 * it freed up during the servicing of the ISR. If there are
3401 * no free buffers to give to the RU, (i.e. we have reached a
3402 * no resource condition) the RU will not be started till the
3406 void zd1205_start_ru(struct zd1205_private
*macp
)
3408 struct rx_list_elem
*zd1205_start_ru(struct zd1205_private
*macp
)
3415 struct rx_list_elem
*rx_struct
= NULL
;
3416 struct list_head
*entry_ptr
= NULL
;
3418 zd1205_RFD_t
*rfd
= 0;
3419 int buffer_found
= 0;
3420 struct sk_buff
*skb
;
3424 if (list_empty(&(macp
->active_rx_list
))) return NULL
;
3426 list_for_each(entry_ptr
, &(macp
->active_rx_list
)){
3427 rx_struct
= list_entry(entry_ptr
, struct rx_list_elem
, list_elem
);
3437 pci_dma_sync_single(macp
->pdev
, rx_struct
->dma_addr
,
3439 macp
->rfd_size
, PCI_DMA_FROMDEVICE
);
3442 skb
= rx_struct
->skb
;
3443 rfd
= RFD_POINTER(skb
, macp
); /* locate RFD within skb */
3445 if (SKB_RFD_STATUS(rx_struct
->skb
, macp
) != RFD_STATUS_COMPLETE
) {
3452 /* No available buffers */
3453 if (!buffer_found
) {
3454 printk(KERN_ERR
"zd1205: No available buffers\n");
3464 tmp_value
= zd_readl(DeviceState
);
3466 if ((tmp_value
== RX_READ_RCB
) || (tmp_value
== RX_CHK_RCB
)){
3467 /* Device is now checking suspend or not.
3468 Keep watching until it finished check. */
3470 if (loopCnt
> 10000000)
3484 if (loopCnt
> 10000000)
3485 ZD1211DEBUG(0, "I am in zd1205_start_ru loop\n");
3488 if (tmp_value
== RX_IDLE
){
3489 /* Rx bus master is in idle state. */
3490 if ((u16
)le32_to_cpu(rfd
->CbStatus
) != RFD_STATUS_COMPLETE
){
3491 zd1205_start_upload(rx_struct
->dma_addr
);
3506 void zd1205_recycle_rx(struct zd1205_private
*macp
)
3508 struct rx_list_elem
*rx_struct
= NULL
;
3509 struct list_head
*entry_ptr
= NULL
;
3510 zd1205_RFD_t
*rfd
= 0;
3511 struct sk_buff
*skb
;
3514 list_for_each(entry_ptr
, &(macp
->active_rx_list
)){
3515 rx_struct
= list_entry(entry_ptr
, struct rx_list_elem
, list_elem
);
3519 rx_struct
->UnFinishFrmLen
= 0;
3520 skb
= rx_struct
->skb
;
3521 rfd
= RFD_POINTER(skb
, macp
); /* locate RFD within skb */
3522 rfd
->CbStatus
= 0xffffffff;
3527 void zd1205_CheckBeaconInfo(struct zd1205_private
*macp
, plcp_wla_Header_t
*pWlanHdr
, u8
*pMacBody
, u32 bodyLen
)
3533 u8 Zd1202Detected
= 0;
3539 u8 BssType
= macp
->cardSetting
.BssType
;
3543 u16 basicRateMap
= 0;
3547 u8 tmpMaxRate
= 0x02;
3550 U16 flagAdhoc
= 0; // Bit 0=1, means SSID same, but BSSID mismatch.
3552 U8 networkType
; // 1: IBSS, 0: ESS
3555 //u16 sequence_number;
3557 cap
= (*(pMacBody
+ CAP_OFFSET
)) + ((*(pMacBody
+ CAP_OFFSET
+1)) << 8);
3559 if (cap
& BIT_1
) //IBSS
3561 SrcAddrOfBcn
= pWlanHdr
->Address2
[2] + pWlanHdr
->Address2
[3] +
3562 pWlanHdr
->Address2
[4] + pWlanHdr
->Address2
[5];
3564 pBssid
= pWlanHdr
->Address3
;
3569 pBssid
= pWlanHdr
->Address2
;
3570 if (BssType
== INDEPENDENT_BSS
)
3573 //sequence_number = (*(u16*)(&pWlanHdr->SeqCtrl[0])) >> 4;
3581 pByte
= pMacBody
+ SSID_OFFSET
;
3583 currPos
= SSID_OFFSET
;
3585 while(currPos
< bodyLen
){
3586 //To prevent incorrect elemLen ( ex. 0)
3587 if(loopCheck
++ > 100)
3589 printk("infinite loop occurs in %s\n", __FUNCTION__
);
3593 elemLen
= *(pByte
+1);
3598 if (BssType
==INFRASTRUCTURE_BSS
&& macp
->bAssoc
&& dot11Obj
.Channel
!= *(pByte
+2))
3601 printk("Channel changed:%u to %u\n",dot11Obj
.Channel
,*(pByte
+2));
3602 zd_CmdProcess(CMD_ROAMING
,0,0);
3604 pByte
+= (elemLen
+2);
3607 //printk("Get ssid\n");
3608 if (BssType
== INFRASTRUCTURE_BSS
&& macp
->bAssoc
&&(dot11DesiredSsid
.buf
[1]==0)) // Any ssid
3610 //printk("Rx ssidlen=%d\n",elemLen);
3612 if (memcmp((pByte
+2),&dot11Obj
.CurrSsid
[2],elemLen
)==0 && dot11Obj
.CurrSsid
[1]==elemLen
)
3614 // printk("SSID Same\n");
3619 printk("SSID Changed\n");
3620 zd_CmdProcess(CMD_ROAMING
,0,0);
3623 else if (BssType
== INDEPENDENT_BSS
)
3624 {// The ESSID of IBSS network should NOT be an Any type.
3626 if (memcmp((pByte
+2),&dot11Obj
.CurrSsid
[2],elemLen
)==0 && dot11Obj
.CurrSsid
[1]==elemLen
)
3628 if (memcmp(&macp
->BSSID
[0], pBssid
, 6) != 0)
3631 //printk("Adhoc: SSID Same,But BSSID is diff\n");
3632 //printk("This Beacon:" MACSTR "\n", MAC2STR(pBssid));
3633 //printk("Our BSSID:" MACSTR "\n", MAC2STR(macp->BSSID));
3634 //if (mTimeBeforeAdhocRoaming)
3636 // if (--mTimeBeforeAdhocRoaming == 0)
3637 // zd_CmdProcess(CMD_ROAMING,0,0);
3644 // printk("SSID Changed\n");
3645 // zd_CmdProcess(CMD_ROAMING,0,0);
3648 pByte
+= (elemLen
+2);
3653 case 0xfe: //ZyDAS Extended Supported Rate (16.5M)
3654 case 0xff: //ZyDAS Extended Supported Rate (27.5M)
3657 if (elemLen
!= 0){ //For possible future compatibility issue,
3658 //we adopt "length = 0", which will not
3661 pByte
+= (elemLen
+2);
3665 if ((BssType
== INFRASTRUCTURE_BSS
) && (macp
->bAssoc
)){
3667 BitmapCtrl
= *(pByte
+4);
3668 N1
= (BitmapCtrl
& ~BIT_0
);
3669 N2
= (elemLen
+ N1
- 4);
3670 quotient
= (dot11Obj
.Aid
>> 3);
3671 remainder
= (dot11Obj
.Aid
& 0x7);
3673 if ((quotient
< N1
) || (quotient
> N2
)){
3674 macp
->bAnyActivity
= 0;
3675 pByte
+= (elemLen
+2);
3679 if ((*(pByte
+5+quotient
-N1
) >> remainder
) & BIT_0
){
3682 //zd_EventNotify(EVENT_MORE_DATA, 0, 0, 0);
3683 dot11Obj
.bMoreData
= 1;
3685 macp
->bAnyActivity
= 1;
3689 macp
->bAnyActivity
= 0;
3692 // Multicast frames queued in AP
3693 if (BitmapCtrl
& BIT_0
){
3694 ZD1211DEBUG(1, "Got multicast framed queued information!\n");
3695 macp
->bAnyActivity
= 1;
3699 pByte
+= (elemLen
+2);
3703 case ELEID_ERP_INFO
:
3707 if (erp
& USE_PROTECTION_BIT
){
3708 if (!(dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
))
3709 defer_kevent(macp
, KEVENT_EN_PROTECTION
);
3712 if (dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
)
3713 defer_kevent(macp
, KEVENT_DIS_PROTECTION
);
3716 // check Barker_Preamble_Mode
3717 if (erp
& BARKER_PREAMBLE_BIT
){
3718 if (!(dot11Obj
.ConfigFlag
& BARKER_PREAMBLE_SET
))
3719 defer_kevent(macp
, KEVENT_EN_BARKER
);
3722 if (dot11Obj
.ConfigFlag
& BARKER_PREAMBLE_SET
)
3723 defer_kevent(macp
, KEVENT_DIS_BARKER
);
3727 if (erp
& NON_ERP_PRESENT_BIT
){
3728 if (dot11Obj
.ConfigFlag
& SHORT_SLOT_TIME_SET
){
3729 defer_kevent(macp
, KEVENT_DIS_SHORT_SLOT
);
3733 if (!(dot11Obj
.ConfigFlag
& SHORT_SLOT_TIME_SET
)){
3734 defer_kevent(macp
, KEVENT_EN_SHORT_SLOT
);
3739 pByte
+= (elemLen
+2);
3742 case ELEID_SUPRATES
:
3743 if ((BssType
== INDEPENDENT_BSS
) && (macp
->bAssoc
)){
3744 zd_makeRateInfoMAP(pByte
, &basicRateMap
, &supRateMap
);
3745 for (i
=0; i
<elemLen
; i
++){
3746 rate
= *(pByte
+2+i
);
3747 if ((rate
& 0x7f) > tmpMaxRate
)
3748 tmpMaxRate
= (rate
& 0x7f);
3751 pByte
+= (elemLen
+2);
3754 case ELEID_EXT_RATES
:
3755 if ((BssType
== INDEPENDENT_BSS
) && (macp
->bAssoc
)){
3756 zd_makeRateInfoMAP(pByte
, &basicRateMap
, &supRateMap
);
3758 for (i
=0; i
<elemLen
; i
++){
3759 rate
= *(pByte
+2+i
);
3760 if ((rate
& 0x7f) > tmpMaxRate
)
3761 tmpMaxRate
= (rate
& 0x7f);
3765 pByte
+= (elemLen
+2);
3769 pByte
+= (elemLen
+2);
3774 currPos
+= (elemLen
+2);
3778 if (Zd1202Detected
){
3779 macp
->BSS_Members
|= MEMBER_ZD1202
;
3782 macp
->BSS_Members
|= MEMBER_OTHERS
;
3785 if (flagAdhoc
& BIT_0
)
3787 //printk("macp->bAssoc=%d, ch0:%d, ch:%d, \n",macp->bAssoc, dot11Obj.Channel, chid);
3788 if ((dot11MacAddress
.mac
[2] + dot11MacAddress
.mac
[3] + dot11MacAddress
.mac
[4] + dot11MacAddress
.mac
[5]) < (pWlanHdr
->Address2
[2] + pWlanHdr
->Address2
[3] + pWlanHdr
->Address2
[4] + pWlanHdr
->Address2
[5]))
3790 if (mTimeBeforeAdhocRoaming
)
3792 if (--mTimeBeforeAdhocRoaming
== 0)
3794 zd_CmdProcess(CMD_ROAMING
, 0, 0);
3795 printk(" ReJoin to \n");
3802 if (flagAdhoc
== 0 && (BssType
== INDEPENDENT_BSS
) && (macp
->bAssoc
))
3804 if (supRateMap
> 0x0f){ //support rates include OFDM rates
3805 if (basicRateMap
& ~0xf) // basic rates include OFDM rates
3813 zd_UpdateIbssInfo(pWlanHdr
->Address2
, tmpMaxRate
, preamble
, bErpSta
);
3814 if ((macp
->cardSetting
.MacMode
!= PURE_A_MODE
) &&(macp
->cardSetting
.MacMode
!= PURE_B_MODE
) && (!bErpSta
)){
3815 if (!(dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
)){
3817 defer_kevent(macp
, KEVENT_EN_PROTECTION
);
3818 ZD1211DEBUG(2, "KEVENT_EN_PROTECTION\n");
3820 zd_EventNotify(EVENT_ENABLE_PROTECTION
, 1, 0, 0);
3826 macp
->Bcn_Acc_Num
++;
3827 macp
->Bcn_Acc_SQ
+= macp
->rxInfo
.signalQuality
;
3833 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
3836 * zd1205_rx_isr - service RX queue
3837 * @macp: atapter's private data struct
3838 * @max_number_of_rfds: max number of RFDs to process
3839 * @rx_congestion: flag pointer, to inform the calling function of congestion.
3841 * This routine processes the RX interrupt & services the RX queues.
3842 * For each successful RFD, it allocates a new msg block, links that
3844 * into the RFD list, and sends the old msg upstream.
3845 * The new RFD is then put at the end of the free list of RFD's.
3846 * It returns the number of serviced RFDs.
3849 u32
zd1205_rx_isr(struct zd1205_private
*macp
)
3851 zd1205_RFD_t
*rfd
; /* new rfd, received rfd */
3854 struct sk_buff
*skb
;
3855 struct net_device
*dev
;
3857 struct rx_list_elem
*rx_struct
;
3859 plcp_wla_Header_t
*wla_hdr
;
3864 u32 hdrLen
= WLAN_HEADER
;
3868 defrag_Array_t
*pDefArray
= &macp
->defragArray
;
3870 card_Setting_t
*pSetting
= &macp
->cardSetting
;
3874 u8 BssType
=pSetting
->BssType
;
3883 struct rx_list_elem
**rx_struct_array
= macp
->rx_struct_array
;
3884 int total_rx_cnt
= macp
->total_rx_cnt
;
3892 /* current design of rx is as following:
3893 * 1. socket buffer (skb) used to pass network packet to upper layer
3894 * 2. all HW host memory structures (like RFDs, RBDs and data buffers)
3895 * are placed in a skb's data room
3896 * 3. when rx process is complete, we change skb internal pointers to exclude
3897 * from data area all unrelated things (RFD, RDB) and to leave
3898 * just rx'ed packet netto
3899 * 4. for each skb passed to upper layer, new one is allocated instead.
3900 * 5. if no skb left, in 2 sec another atempt to allocate skbs will be made
3901 * (watchdog trigger SWI intr and isr should allocate new skbs)
3905 #if fMERGE_RX_FRAME //USB
3906 for (rx_cnt
=0; rx_cnt
<total_rx_cnt
; rx_cnt
++){
3908 for (i
=0; i
<macp
->numRfd
; i
++) {
3912 rx_struct
= rx_struct_array
[rx_cnt
];
3913 skb
= rx_struct
->skb
;
3914 rfd
= RFD_POINTER(skb
, macp
);
3915 rfd_status
= SKB_RFD_STATUS(rx_struct
->skb
, macp
);
3917 if (rfd_status
!= RFD_STATUS_COMPLETE
) /* does not contains data yet - exit */
3919 //macp->DriverRxFrmCnt ++;
3920 #else //end of fMERGE_RX_FRAME
3922 if (list_empty(&(macp
->active_rx_list
))) {
3923 //zd1205_add_skb_to_end(macp, rx_struct);
3924 //printk("zd1205: list_empty\n");
3925 printk(KERN_ERR
"zd1205: list_empty\n");
3931 rx_struct
= list_entry(macp
->active_rx_list
.next
,
3932 struct rx_list_elem
, list_elem
);
3934 ZD1211DEBUG(4, "zd1211: rx_struct = %x\n", (u32
)rx_struct
);
3935 skb
= rx_struct
->skb
;
3936 rfd
= RFD_POINTER(skb
, macp
); /* locate RFD within skb */
3938 // sync only the RFD header
3940 pci_dma_sync_single(macp
->pdev
, rx_struct
->dma_addr
,
3941 macp
->rfd_size
+PLCP_HEADER
+WLAN_HEADER
, PCI_DMA_FROMDEVICE
);
3943 rfd_status
= SKB_RFD_STATUS(rx_struct
->skb
, macp
); /* get RFD's status */
3945 ZD1211DEBUG(4, "zd1211: rfd_status = %x\n", rfd_status
);
3946 if (rfd_status
!= RFD_STATUS_COMPLETE
) /* does not contains data yet - exit */
3954 macp
->DriverRxFrmCnt
++;
3955 /* to allow manipulation with current skb we need to unlink it */
3956 list_del(&(rx_struct
->list_elem
));
3959 if(zd1211_submit_rx_urb(macp
))
3961 printk("No available buffer. Reallocate\n");
3962 zd1211_alloc_rx((unsigned long)macp
);
3963 if(zd1211_submit_rx_urb(macp
))
3964 printk("zd1211_submit_rx_urb fails. Abort\n");
3968 #endif //end of !fMERGE_RX_FRAME
3971 data_sz
= (u16
)(rfd
->ActualCount
& 0x3fff);
3972 data_sz
-= macp
->rxOffset
;
3973 ZD1211DEBUG(4, "zd1211: data_sz = %x\n", data_sz
);
3976 if (macp
->bPSMSupported
)
3977 zd1205_dump_data("RxBuffer", (u8
*)rfd
->RxBuffer
, data_sz
);
3979 //zd1205_add_skb_to_end(macp, rx_struct);
3982 wla_hdr
= (plcp_wla_Header_t
*)&rfd
->RxBuffer
[macp
->rxOffset
];
3983 pHdr
= (u8
*)wla_hdr
+ PLCP_HEADER
;
3984 dot11Obj
.bMoreData
= (wla_hdr
->FrameCtrl
[1] & BIT_5
) > 0?1:0;
3987 u8 *mb = hdrLen+ pHdr;
3988 if(mb[0] == 0xf0 && mb[1] == 0xf0)
3989 printk("Get NETBIOS\n");
3992 if (SubFrameType(wla_hdr
) != BEACON
){
3993 macp
->bFrmRxed1
= 1;
3996 if (!macp
->sniffer_on
){
3997 BaseFrmType
= BaseFrameType(wla_hdr
);
3998 macp
->DriverRxFrmCnt
++;
4000 if ((BaseFrmType
== DATA
) || (BaseFrmType
== MANAGEMENT
)){ //Data or Management Frames
4001 /* do not free & unmap badly recieved packet.
4002 * move it to the end of skb list for reuse */
4005 //sync for access correctly
4006 pci_dma_sync_single(macp
->pdev
, rx_struct
->dma_addr
,
4007 data_sz
+ macp
->rfd_size
, PCI_DMA_FROMDEVICE
);
4009 if (zd1205_validate_frame(macp
, rfd
) == false){
4011 //int frame_len=(le32_to_cpu(rfd->ActualCount)&0x3fff)-macp->rxOffset;
4012 ZD1211DEBUG(4, "zd1211: invalid frame\n");
4013 //plcp_wla_Header_t *wla_hdrb;
4014 //printk("zd1211: invalid frame\n");
4015 //printk("\nAddr1: ");
4017 // printk("%02x ", wla_hdr->Address1[i]);
4018 //printk("\nAddr2: ");
4020 // printk("%02x ", wla_hdr->Address2[i]);
4021 //printk("\nAddr3: ");
4023 // printk("%02x ", wla_hdr->Address3[i]);
4024 //printk("\nDuration:%d",*(u16 *)wla_hdr->Duration);
4025 //printk("\nFrmCtl:%d",*(u16 *)wla_hdr->FrameCtrl);
4026 //printk("\nLength:%d\n",frame_len);
4029 macp
->invalid_frame_good_crc
++;
4030 zd1205_add_skb_to_end(macp
, rx_struct
);
4034 seq
= getSeq(wla_hdr
);
4035 frag
= getFrag(wla_hdr
);
4036 pTa
= getTA(wla_hdr
);
4038 if (!bGroup(wla_hdr
)){ //unicast
4039 if (memcmp(&wla_hdr
->Address1
[0], &macp
->macAdr
[0], 6) != 0){
4040 zd1205_add_skb_to_end(macp
, rx_struct
);
4043 else{ //check dupicated frame
4044 //if (BaseFrmType == DATA)
4045 //zd1205_dump_data("RxBuffer", (u8 *)rfd->RxBuffer, data_sz);
4047 if ((bRetryBit(wla_hdr
))
4048 && (zd1205_SearchTupleCache(macp
, pTa
, seq
, frag
))){ //dupicated
4049 zd1205_UpdateTupleCache(macp
, pTa
, seq
, frag
);
4050 zd1205_add_skb_to_end(macp
, rx_struct
);
4054 zd1205_UpdateTupleCache(macp
, pTa
, seq
, frag
);
4057 else { //group address
4058 // check if the address1 of the multicast frame is in the multicast list
4059 if (wla_hdr
->Address1
[0] != 0xff){
4061 //zd1205_dump_data("address1", (u8 *)wla_hdr->Address1, 6);
4063 for(i
=0; i
<macp
->MulticastAddr
[0]; i
++){
4064 tmpvalue
= memcmp(&macp
->MulticastAddr
[6*i
+1], wla_hdr
->Address1
, 6);
4070 //If the address is not registerd multicast addr.
4071 //and not if promisc || All multicast mode.Drop It.
4072 if ((tmpvalue
!= 0) &&
4073 !(dev
->flags
& IFF_PROMISC
) &&
4074 !(dev
->flags
& IFF_ALLMULTI
))
4077 zd1205_add_skb_to_end(macp
, rx_struct
);
4078 ZD1211DEBUG(1, " - address1 is not in the multicast list\n");
4083 if (BaseFrameType(wla_hdr
) == DATA
){
4084 if (BssType
== INFRASTRUCTURE_BSS
){
4085 if (memcmp(&macp
->BSSID
[0], &wla_hdr
->Address2
[0], 6) != 0){
4087 zd1205_add_skb_to_end(macp
, rx_struct
);
4090 } else if ((BssType
== INDEPENDENT_BSS
) || (BssType
== PSEUDO_IBSS
)){
4091 if (memcmp(&macp
->BSSID
[0], &wla_hdr
->Address3
[0], 6) != 0){
4093 zd1205_add_skb_to_end(macp
, rx_struct
);
4097 zd1205_add_skb_to_end(macp
, rx_struct
);
4102 ;//ZD1211DEBUG(3, "Group Mgt Frame\n");
4106 hdrLen
= WLAN_HEADER
;
4107 pBody
= (u8
*)pHdr
+ WLAN_HEADER
;
4108 bodyLen
= data_sz
- PLCP_HEADER
- WLAN_HEADER
- EXTRA_INFO_LEN
- CRC32_LEN
;
4111 if (bWepBit(wla_hdr
)) {
4114 ZD1211DEBUG(4, "zd1205: wep frame\n");
4116 pIv
= pHdr
+ hdrLen
;
4118 bodyLen
= bodyLen
- IV_SIZE
- ICV_SIZE
;
4120 rxDecryType
= (macp
->rxDecryType
& 0x0f);
4130 bSwCheckMIC
=1;// zd1211 always use sw-mic regardless of fragmentation.
4131 bodyLen
-= EXTEND_IV_LEN
;
4132 pBody
+= EXTEND_IV_LEN
;
4133 hdrLen
+= EXTEND_IV_LEN
;
4134 #if 0 // zd1211 does not have hw-mic feature.
4135 if (macp
->rxDecryType
& RX_MIC_ERROR_IND
)
4137 printk("hw mic error!\n");
4138 if (dot11Obj
.MicFailure
)
4140 //dot11Obj.MicFailure(&wla_hdr->Address2[0]);
4142 //SDMichaelFailureDetected((UCHAR*) &wla_hdr->Address2[0]);// For hostapd
4143 // hostap_michael_mic_failure((zd1205_private_t *)g_dev->priv, (struct hostap_ieee80211_hdr *)pHdr, (int)pIv[3] & KEYID_MASK); // For Xsupplicant.
4148 RxIv16
= ((u16
)pIv
[0] << 8) + pIv
[2];
4149 RxIv32
= pIv
[4] + ((u32
)pIv
[5] << 8) + ((u32
)pIv
[6] << 16) + ((u32
)pIv
[7] << 24);
4150 // check iv sequence
4154 //ZD1211DEBUG(0, "Got AES frame !!!\n");
4155 bodyLen
-= (MIC_LENGTH
);
4156 pBody
+= EXTEND_IV_LEN
;
4157 hdrLen
+= EXTEND_IV_LEN
;
4163 if (BssType
== AP_BSS
){
4164 memcpy(EthHdr
, &wla_hdr
->Address3
[0], 6); // copy DA
4165 memcpy(&EthHdr
[6], &wla_hdr
->Address2
[0], 6); // copy SA
4167 else if (BssType
== INFRASTRUCTURE_BSS
){
4168 memcpy(EthHdr
, &wla_hdr
->Address1
[0], 6); // copy DA
4169 memcpy(&EthHdr
[6], &wla_hdr
->Address3
[0], 6); // copy SA
4170 //If we got a broadcast frame with Add3 is ourself. Drop it.
4171 // This kind of packet is from our broadcast reqest to AP . // And AP rebroadcast it .
4172 if( bGroup(wla_hdr
) &&
4173 memcmp(macp
->macAdr
,wla_hdr
->Address3
, 6) == 0) {
4174 zd1205_add_skb_to_end(macp
, rx_struct
);
4180 else if ((BssType
== INDEPENDENT_BSS
) || (BssType
== PSEUDO_IBSS
)){
4181 memcpy(EthHdr
, &wla_hdr
->Address1
[0], 6); // copy DA
4182 memcpy(&EthHdr
[6], &wla_hdr
->Address2
[0], 6); // copy SA
4185 if ((BaseFrmType
== DATA
)){
4188 if (isWDS(wla_hdr
)){
4189 //ZD1211DEBUG(3, "***** WDS or group\n");
4190 zd1205_add_skb_to_end(macp
, rx_struct
);
4193 if (frag
== 0){ //No fragment or first fragment
4194 if (!bMoreFrag(wla_hdr
)){ //No more fragment
4195 //ZD1211DEBUG(2, "***** No Frag\n");
4196 //if (rxDecryType == TKIP)
4197 // bodyLen -= MIC_LENGTH;
4198 //<Slow Pairwise Key Install Fix>
4199 if(macp
->cardSetting
.WPASupport
== 1)
4201 if(memcmp(ZD_SNAP_EAPOL
, pBody
, 8) == 0)
4202 macp
->EncTypeOfLastRxEapolPkt
= rxDecryType
& 7;
4204 //</Slow Pairwise Key Install Fix>
4207 else{ //First fragment
4208 DFDEBUG("***** First Frag");
4209 macp
->rxNeedFragCnt
++;
4210 i
= zd1205_ArFree(macp
); //Get a free one
4213 zd1205_ArAge(macp
, nowT());
4214 i
= zd1205_ArFree(macp
);
4216 DFDEBUG("***** ArFree fail");
4217 macp
->DropFirstFragCnt
++;
4218 zd1205_add_skb_to_end(macp
, rx_struct
);
4223 zd1205_ArUpdate(macp
, pTa
, seq
, frag
, i
);
4224 pDefArray
->mpdu
[i
].dataStart
= pBody
;
4226 pDefArray
->mpdu
[i
].buf
= (void *)skb
; //save skb
4229 pci_unmap_single(macp
->pdev
, rx_struct
->dma_addr
,
4230 sizeof (zd1205_RFD_t
), PCI_DMA_FROMDEVICE
);
4232 list_add(&(rx_struct
->list_elem
), &(macp
->rx_struct_pool
));
4233 macp
->skb_req
++; /* incr number of requested skbs */
4234 // if(macp->skb_req > 10)
4235 // zd1211_alloc_rx((unsigned long)macp);
4237 zd1205_alloc_skbs(macp
); /* and get them */
4239 tasklet_schedule(&macp
->rx_buff_tasklet
);
4242 zd1205_ArAge(macp
, nowT());
4247 struct sk_buff
*defrag_skb
;
4250 i
= zd1205_ArSearch(macp
, pTa
, seq
, frag
); //Get exist one
4252 DFDEBUG("***** ArSearch fail");
4253 macp
->ArSearchFailCnt
++;
4254 zd1205_ArAge(macp
, nowT());
4255 zd1205_add_skb_to_end(macp
, rx_struct
); //discard this one
4259 defrag_skb
= (struct sk_buff
*)pDefArray
->mpdu
[i
].buf
;
4260 pStart
= (u8
*)pDefArray
->mpdu
[i
].dataStart
;
4261 pDefArray
->mpdu
[i
].fn
= frag
;
4263 memcpy((pStart
+defrag_skb
->len
), pBody
, bodyLen
); //copy to reassamble buffer
4264 defrag_skb
->len
+= bodyLen
;
4266 if (!bMoreFrag(wla_hdr
)){ //Last fragment
4267 DFDEBUG("***** Last Frag");
4268 zd1205_add_skb_to_end(macp
, rx_struct
);
4269 pDefArray
->mpdu
[i
].inUse
= 0;
4271 skb
->data
= (u8
*)pDefArray
->mpdu
[i
].dataStart
; //point mac body
4274 macp
->rxCompFragCnt
++;
4275 //if (rxDecryType == TKIP)
4278 //goto defrag_ind; //bug
4282 DFDEBUG("***** More Frag");
4283 zd1205_ArAge(macp
, nowT());
4284 zd1205_add_skb_to_end(macp
, rx_struct
);
4288 }//end of data frame
4289 else if (BaseFrameType(wla_hdr
) == MANAGEMENT
)
4291 if (SubFrameType(wla_hdr
) == BEACON
)
4293 if (BssType
== AP_BSS
)
4295 if (dot11Obj
.ConfigFlag
& PASSIVE_CHANNEL_SCAN_SET
)
4297 zd1205_CollectBssInfo(macp
, wla_hdr
, pBody
, bodyLen
);
4300 if (pSetting
->MacMode
!= PURE_B_MODE
&& pSetting
->MacMode
!= PURE_A_MODE
)
4302 if (!dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
)
4304 if (zd1205_CheckOverlapBss(macp
, wla_hdr
, pBody
, bodyLen
))
4306 // ebable protection mode
4308 if (!(dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
) && (macp
->bOLBC
>= 3))
4311 defer_kevent(macp
, KEVENT_EN_PROTECTION
);
4313 zd_EventNotify(EVENT_ENABLE_PROTECTION
, 1, 0, 0);
4320 zd1205_add_skb_to_end(macp
, rx_struct
);
4324 if (dot11Obj
.ConfigFlag
& ACTIVE_CHANNEL_SCAN_SET
) //path through
4327 if (BssType
== INDEPENDENT_BSS
|| memcmp(&macp
->BSSID
[0], &wla_hdr
->Address3
[0], 6) == 0){ //BSSID filter
4329 zd1205_CheckBeaconInfo(macp
, wla_hdr
, pBody
, bodyLen
);
4330 if (macp
->bPSMSupported
)
4332 //ZD1211DEBUG(0, "AP is alive due to Bcn Rcvd\n");
4338 if ((pSetting
->MacMode
!= PURE_B_MODE
) && (BssType
== INDEPENDENT_BSS
)){
4339 if (!dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
){
4340 if (zd1205_CheckOverlapBss(macp
, wla_hdr
, pBody
, bodyLen
)){
4341 // ebable protection mode
4344 defer_kevent(macp
, KEVENT_EN_PROTECTION
);
4346 zd_EventNotify(EVENT_ENABLE_PROTECTION
, 1, 0, 0);
4355 zd1205_add_skb_to_end(macp
, rx_struct
); /* discard Beacon frames */
4361 if (bGroup(wla_hdr
)){
4362 if ((BssType
!= AP_BSS
) || (BssType
!= INDEPENDENT_BSS
)){
4363 zd1205_add_skb_to_end(macp
, rx_struct
);
4370 } //end of management frame
4372 else if (SubFrameType(wla_hdr
) == PS_POLL
)
4374 if (BssType
==AP_BSS
&& memcmp(&wla_hdr
->Address1
[0], &macp
->macAdr
[0], 6) == 0) //Ps-Poll for me
4375 zd_CmdProcess(CMD_PS_POLL
, (void *)pHdr
, 0);
4376 zd1205_add_skb_to_end(macp
, rx_struct
);
4380 zd1205_add_skb_to_end(macp
, rx_struct
);
4383 }//end of sniffer_on
4387 if (BaseFrmType
== DATA
)
4389 if (bGroup(wla_hdr
))
4391 macp
->rxMulticastFrm
++;
4392 macp
->rxMulticastOctets
+= hdrLen
+ bodyLen
;
4393 macp
->rxBroadcastFrm
++;
4394 macp
->rxBroadcastOctets
+= hdrLen
+ bodyLen
;
4398 macp
->rxUnicastFrm
++;
4399 macp
->rxUnicastOctets
+= hdrLen
+ bodyLen
;
4405 pci_unmap_single(macp
->pdev
, rx_struct
->dma_addr
,
4406 sizeof (zd1205_RFD_t
), PCI_DMA_FROMDEVICE
);
4409 list_add(&(rx_struct
->list_elem
), &(macp
->rx_struct_pool
));
4410 /* end of dma access to rfd */
4411 macp
->skb_req
++; /* incr number of requested skbs */
4412 // if(macp->skb_req > 10)
4413 // zd1211_alloc_rx((unsigned long)macp);
4416 zd1205_alloc_skbs(macp
); /* and get them */
4418 tasklet_schedule(&macp
->rx_buff_tasklet
);
4422 macp
->rxInfo
.bSwCheckMIC
= bSwCheckMIC
;
4425 if (!macp
->sniffer_on
){
4426 if (BaseFrmType
== DATA
)
4427 macp
->TotalRxDataFrmBytes
+= (hdrLen
+bodyLen
);
4429 macp
->rxInfo
.bDataFrm
= BaseFrmType
;
4430 macp
->rxInfo
.SaIndex
= SaIndex
;
4432 if ((BssType
== INFRASTRUCTURE_BSS
) && (macp
->bAssoc
)){
4433 if (memcmp(&macp
->BSSID
[0], &wla_hdr
->Address2
[0], 6) == 0){
4437 if ((macp
->bPSMSupported
) && (macp
->PwrState
) && (!dot11Obj
.bDeviceInSleep
)){
4438 if (bMoreData(wla_hdr
) && macp
->bAssoc
){
4440 //zd_EventNotify(EVENT_MORE_DATA, 0, 0, 0);
4441 //if((jiffies / HZ) & 5 == 5)
4442 dot11Obj
.bMoreData
= 1;
4448 LP_Mode
= 0; //This must be set. This initilization of "LP_Mode = FALSE" fails.
4449 #if ZDCONF_LP_SUPPORT == 1
4450 if(wla_hdr
->FrameCtrl
[0] == 0x88)
4452 if(*(wla_hdr
->SeqCtrl
+2) & BIT_7
)
4457 zd_ReceivePkt(pHdr
, hdrLen
, pBody
, bodyLen
, (void *)skb
, EthHdr
, &macp
->rxInfo
, LP_Mode
);
4458 macp
->bDataTrafficLight
= 1;
4461 skb
->tail
= skb
->data
= pHdr
;
4462 skb_put(skb
, data_sz
- PLCP_HEADER
);
4463 skb
->mac
.raw
= skb
->data
;
4464 skb
->pkt_type
= PACKET_OTHERHOST
;
4465 skb
->protocol
= htons(ETH_P_802_2
);
4467 skb
->ip_summed
= CHECKSUM_NONE
;
4470 }/* end of rfd loop */
4472 //if(macp->skb_req)zd1205_alloc_skbs(macp);//add by johnson
4475 #if !fMERGE_RX_FRAME
4478 if(zd1211_submit_rx_urb(macp
))
4480 printk("No avaialbe Rx buffer. Allocate it immediately\n");
4481 zd1211_alloc_rx((unsigned long)macp
);
4482 if(zd1211_sumbit_rx_urb(macp
))
4483 printk("zd1211_submit_rx_urb fails again. Abort\n");
4487 if (dot11Obj
.QueueFlag
& TX_QUEUE_SET
){
4488 macp
->txQueSetCnt
++;
4489 //tasklet_schedule(&macp->zd1205_tx_tasklet);
4494 /* restart the RU if it has stopped */
4495 zd1205_start_ru(macp
);
4502 * zd1205_intr - interrupt handler
4503 * @irq: the IRQ number
4504 * @dev_inst: the net_device struct
4505 * @regs: registers (unused)
4507 * This routine is the ISR for the zd1205 board. It services
4508 * the RX & TX queues & starts the RU if it has stopped due
4514 zd1205_intr(int irq
, void *dev_inst
, struct pt_regs
*regs
)
4516 struct net_device
*dev
;
4517 struct zd1205_private
*macp
;
4524 intr_status
= zd_readl(InterruptCtrl
);
4531 /* disable intr before we ack & after identifying the intr as ours */
4532 zd1205_disable_int();
4535 /* the device is closed, don't continue or else bad things may happen. */
4537 if (!netif_running(dev
)) {
4538 zd1205_enable_int();
4543 if (macp
->driver_isolated
) {
4551 /* Then, do Rx as soon as possible */
4552 if (intr_status
& RX_COMPLETE
){
4553 zd_writel((intr_status
| RX_COMPLETE
), InterruptCtrl
);
4554 macp
->drv_stats
.rx_intr_pkts
+= zd1205_rx_isr(macp
);
4557 /* Then, recycle Tx chain/descriptors */
4558 if (intr_status
& TX_COMPLETE
){
4559 zd_writel((intr_status
| TX_COMPLETE
), InterruptCtrl
);
4560 zd1205_tx_isr(macp
);
4561 macp
->TxStartTime
= 0;
4565 if (intr_status
& RETRY_FAIL
) {
4566 zd_writel((intr_status
| RETRY_FAIL
), InterruptCtrl
);
4567 zd1205_retry_failed(macp
);
4568 macp
->TxStartTime
= 0;
4572 if (intr_status
& CFG_NEXT_BCN
) {
4573 zd_writel((intr_status
| CFG_NEXT_BCN
), InterruptCtrl
);
4575 if (macp
->config_next_bcn_en
){
4577 zd_EventNotify(EVENT_TBCN
, 0, 0, 0);
4579 if (macp
->cardSetting
.BssType
== INDEPENDENT_BSS
){
4580 macp
->bFrmRxed1
= 0;
4581 } else if (macp
->cardSetting
.BssType
== AP_BSS
){
4582 if (macp
->dtimCount
== 0)
4584 macp
->dtimCount
= macp
->cardSetting
.DtimPeriod
;
4592 if (intr_status
& DTIM_NOTIFY
){
4593 zd_writel((intr_status
| DTIM_NOTIFY
), InterruptCtrl
);
4595 if (macp
->dtim_notify_en
){
4597 zd1205_dtim_notify(macp
);
4602 if (intr_status
& BUS_ABORT
){
4603 if (!dot11Obj
.bDeviceInSleep
)
4604 ZD1211DEBUG(0, "******Bus Abort!!!\n");
4605 zd_writel(0xff, InterruptCtrl
);
4606 //zd1205_sleep_reset(macp);
4610 if (intr_status
& WAKE_UP
){
4611 //ZD1211DEBUG(1, "******WAKE_UP!!!\n");
4612 zd_writel((intr_status
| WAKE_UP
), InterruptCtrl
);
4614 if (dot11Obj
.bDeviceInSleep
){
4615 //++ After wake up, we should ignore all interrupt except for Wakeup Interrupt.
4616 // This is very important!
4617 // If, we do not obey this, the following bug might occurs:
4619 // -------------------------------------------------------------------> time
4622 // Sleep | Process Process GetReturn |
4623 // Wakeup WakeupInt RxComplete Packet RxComplet
4625 // & (ReStart (NotifyNdis (Rfd1) (due to
4626 // RxComplete Rx(Rfd1)) Rfd1) Chain Rfd1 ReStartRx
4627 // at last of in Process
4628 // RfdList WakeupInt)
4629 // This problem cause Rx-master stays in Idle
4630 // state, and we did not restart it again!
4631 zd_writel(0xff, InterruptCtrl
);
4632 zd1205_process_wakeup(macp
);
4638 if (macp
->dtimCount
== macp
->cardSetting
.DtimPeriod
- 1){
4639 if (dot11Obj
.QueueFlag
& AWAKE_QUEUE_SET
)
4640 tasklet_schedule(&macp
->zd1205_ps_tasklet
);
4643 if (dot11Obj
.QueueFlag
& MGT_QUEUE_SET
)
4644 tasklet_schedule(&macp
->zd1205_tasklet
);
4647 if (dot11Obj
.QueueFlag
& TX_QUEUE_SET
)
4649 tasklet_schedule(&macp
->zd1205_tx_tasklet
);
4654 zd1205_enable_int();
4659 zd1205_open(struct net_device
*dev
)
4661 struct zd1205_private
*macp
= dev
->priv
;
4662 card_Setting_t
*pSetting
= &macp
->cardSetting
;
4666 #if ZDCONF_LP_SUPPORT == 1
4669 pSetting
->EncryOnOff
= 0;
4670 pSetting
->EncryMode
= NO_WEP
;
4671 pSetting
->EncryKeyId
= 0;
4673 //This is used before previous up stat only,So we clear it.
4674 clear_bit(CTX_FLAG_ESSID_WAS_SET
, (void*)&macp
->flags
);
4675 //read_lock(&(macp->isolate_lock));
4676 if (macp
->driver_isolated
) {
4681 //macp->bUSBDeveiceAttached = 1;
4683 if ((rc
= zd1205_alloc_space(macp
)) != 0) {
4688 /* setup the tcb pool */
4689 if (!zd1205_alloc_tcb_pool(macp
)) {
4690 printk(KERN_ERR
"zd1205: failed to zd1205_alloc_tcb_pool\n");
4695 zd1205_setup_tcb_pool(macp
);
4697 if (!zd1205_alloc_rfd_pool(macp
)) {
4698 printk(KERN_ERR
"zd1205: failed to zd1205_alloc_rfd_pool\n");
4704 mod_timer(&(macp
->watchdog_timer
), jiffies
+ (1*HZ
)); //1 sec
4705 mod_timer(&(macp
->tm_hking_id
), jiffies
+ (1*HZ
)/10); //100 ms
4706 mod_timer(&(macp
->tm_mgt_id
), jiffies
+ (1*HZ
)/50); //20 ms
4707 #if ZDCONF_LP_SUPPORT == 1
4708 if(dot11Obj
.LP_MODE
)
4709 mod_timer(&(macp
->tm_lp_poll_id
), jiffies
+ (1*HZ
)/100);
4714 if ((rc
= request_irq(dev
->irq
, &zd1205_intr
, SA_SHIRQ
, dev
->name
, dev
)) != 0) {
4715 printk(KERN_ERR
"zd1205: failed to request_irq\n");
4716 del_timer_sync(&macp
->watchdog_timer
);
4717 del_timer_sync(&macp
->tm_hking_id
);
4718 del_timer_sync(&macp
->tm_mgt_id
);
4719 #if ZDCONF_LP_SUPPORT == 1
4720 if(dot11Obj
.LP_MODE
)
4721 del_timer_sync(&macp
->tm_lp_poll_id
);
4727 zd1205_start_ru(macp
);
4730 if (macp
->cardSetting
.BssType
== AP_BSS
){
4731 netif_start_queue(dev
);
4732 zd_writel(0x1, LED1
);
4735 macp
->IBSS_DesiredMacMode
= macp
->cardSetting
.MacMode
;
4736 macp
->IBSS_DesiredChannel
= macp
->cardSetting
.Channel
;
4737 macp
->intrMask
= ZD1205_INT_MASK
;
4738 macp
->bHandleNonRxTxRunning
= 0;
4740 zd_UpdateCardSetting(&macp
->cardSetting
);
4741 zd_CmdProcess(CMD_ENABLE
, &dot11Obj
, 0); //AP start send beacon , STA start scan
4742 zd1205_enable_int();
4744 set_bit(ZD1211_RUNNING
, &macp
->flags
);
4745 if (zd1211_submit_rx_urb(macp
))
4747 printk("Error in submit_rx_urb in zd1205_open\n");
4753 zd_writel(cpu_to_le32(*(u32
*)macp
->macAdr
), MACAddr_P1
);
4754 zd_writel(cpu_to_le32(*(u32
*)(macp
->macAdr
+4)), MACAddr_P2
);
4760 zd1205_clear_pools(macp
);
4763 //read_unlock(&(macp->isolate_lock));
4768 void zd1205_init_txq(struct zd1205_private
*macp
, zd1205_SwTcbQ_t
*Q
)
4770 unsigned long flags
;
4772 if(!in_irq())spin_lock_irqsave(&macp
->q_lock
, flags
);
4779 if(!in_irq())spin_unlock_irqrestore(&macp
->q_lock
, flags
);
4785 void zd1205_qlast_txq(struct zd1205_private
*macp
, zd1205_SwTcbQ_t
*Q
, zd1205_SwTcb_t
*signal
)
4787 unsigned long flags
;
4788 if(!in_irq())spin_lock_irqsave(&macp
->q_lock
, flags
);
4790 signal
->next
= NULL
;
4791 if (Q
->last
== NULL
){
4796 Q
->last
->next
= signal
;
4804 if(!in_irq())spin_unlock_irqrestore(&macp
->q_lock
, flags
);
4811 zd1205_SwTcb_t
* zd1205_first_txq(struct zd1205_private
*macp
, zd1205_SwTcbQ_t
*Q
)
4813 zd1205_SwTcb_t
*p
= NULL
;
4815 unsigned long flags
;
4817 if(!in_irq())spin_lock_irqsave(&macp
->q_lock
, flags
);
4819 if (Q
->first
!= NULL
){
4822 Q
->first
= (Q
->first
)->next
;
4823 if (Q
->first
== NULL
)
4830 if(!in_irq())spin_unlock_irqrestore(&macp
->q_lock
, flags
);
4838 zd1205_setup_tcb_pool(struct zd1205_private
*macp
)
4841 /* TCB local variables */
4842 zd1205_SwTcb_t
*sw_tcb
; /* cached TCB list logical pointers */
4844 zd1205_HwTCB_t
*hw_tcb
; /* uncached TCB list logical pointers */
4845 u32 HwTcbPhys
; /* uncached TCB list physical pointer */
4848 /* TBD local variables */
4849 zd1205_TBD_t
*pHwTbd
; /* uncached TBD list pointers */
4850 u32 HwTbdPhys
; /* uncached TBD list physical pointer */
4851 zd1205_Ctrl_Set_t
*pHwCtrlPtr
;
4853 zd1205_Header_t
*pHwHeaderPtr
;
4856 macp
->freeTxQ
= &free_txq_buf
;
4857 macp
->activeTxQ
= &active_txq_buf
;
4858 zd1205_init_txq(macp
, macp
->freeTxQ
);
4859 zd1205_init_txq(macp
, macp
->activeTxQ
);
4862 /* print some basic sizing debug info */
4863 printk(KERN_DEBUG
"sizeof(SwTcb) = %04x\n", sizeof(zd1205_SwTcb_t
));
4864 printk(KERN_DEBUG
"sizeof(HwTcb) = %04x\n", sizeof(zd1205_HwTCB_t
));
4866 printk(KERN_DEBUG
"sizeof(HwTbd)= %04x\n", sizeof(zd1205_TBD_t
));
4867 printk(KERN_DEBUG
"sizeof(CTRL_STRUC) = %04x\n", sizeof(zd1205_Ctrl_Set_t
));
4868 printk(KERN_DEBUG
"sizeof(HEADER_STRUC) = %04x\n", sizeof(zd1205_Header_t
));
4869 printk(KERN_DEBUG
"macp->numTcb = %04x\n", macp
->numTcb
);
4870 printk(KERN_DEBUG
"macp->numTbdPerTcb = %04x\n", macp
->numTbdPerTcb
);
4871 printk(KERN_DEBUG
"macp->numTbd = %04x\n", macp
->numTbd
);
4875 /* Setup the initial pointers to the HW and SW TCB data space */
4876 sw_tcb
= (zd1205_SwTcb_t
*) macp
->txCached
;
4877 hw_tcb
= (zd1205_HwTCB_t
*) macp
->txUnCached
;
4882 HwTcbPhys
= macp
->txUnCachedPhys
;
4884 HwTcbPhys
= (u32
)macp
->txUnCached
;
4887 /* Setup the initial pointers to the TBD data space.
4888 TBDs are located immediately following the TCBs */
4889 pHwTbd
= (zd1205_TBD_t
*) (macp
->txUnCached
+ (sizeof(zd1205_HwTCB_t
) * macp
->numTcb
));
4890 HwTbdPhys
= HwTcbPhys
+ (sizeof(zd1205_HwTCB_t
) * macp
->numTcb
);
4892 /* Setup yhe initial pointers to the Control Setting space
4893 CTRLs are located immediately following the TBDs */
4894 pHwCtrlPtr
= (zd1205_Ctrl_Set_t
*) ((u32
)pHwTbd
+ (sizeof(zd1205_TBD_t
) * macp
->numTbd
));
4895 HwCtrlPhys
= HwTbdPhys
+ (sizeof(zd1205_TBD_t
) * macp
->numTbd
);
4897 /* Setup the initial pointers to the Mac Header space
4898 MACHEADERs are located immediately following the CTRLs */
4899 pHwHeaderPtr
= (zd1205_Header_t
*) ((u32
)pHwCtrlPtr
+ (sizeof(zd1205_Ctrl_Set_t
) * macp
->numTcb
));
4900 HwHeaderPhys
= HwCtrlPhys
+ (sizeof(zd1205_Ctrl_Set_t
) * macp
->numTcb
);
4904 /* Go through and set up each TCB */
4905 for (TcbCount
= 0; TcbCount
< macp
->numTcb
;
4908 TcbCount
++, sw_tcb
++, hw_tcb
++, HwTcbPhys
+= sizeof(zd1205_HwTCB_t
),
4909 pHwTbd
= (zd1205_TBD_t
*) (((u8
*) pHwTbd
) + ((sizeof(zd1205_TBD_t
) * macp
->numTbdPerTcb
))),
4910 HwTbdPhys
+= (sizeof(zd1205_TBD_t
) * macp
->numTbdPerTcb
),
4911 pHwCtrlPtr
++, HwCtrlPhys
+= sizeof(zd1205_Ctrl_Set_t
),
4912 pHwHeaderPtr
++, HwHeaderPhys
+= sizeof(zd1205_Header_t
)){
4913 /* point the cached TCB to the logical address of the uncached one */
4914 sw_tcb
->TcbCount
= TcbCount
;
4917 sw_tcb
->pTcb
= hw_tcb
;
4918 sw_tcb
->TcbPhys
= HwTcbPhys
;
4919 sw_tcb
->pFirstTbd
= pHwTbd
;
4920 sw_tcb
->FirstTbdPhys
= HwTbdPhys
;
4921 sw_tcb
->pHwCtrlPtr
= pHwCtrlPtr
;
4922 sw_tcb
->HwCtrlPhys
= HwCtrlPhys
;
4926 // Pre-init control setting
4928 zd1205_Ctrl_Set_t
*ctrl_set
= sw_tcb
->pHwCtrlPtr
;
4931 ctrl_set
->CtrlSetting
[3] = (u8
)(sw_tcb
->TcbPhys
);
4933 ctrl_set
->CtrlSetting
[4] = (u8
)(sw_tcb
->TcbPhys
>> 8);
4934 ctrl_set
->CtrlSetting
[5] = (u8
)(sw_tcb
->TcbPhys
>> 16);
4935 ctrl_set
->CtrlSetting
[6] = (u8
)(sw_tcb
->TcbPhys
>> 24);
4936 ctrl_set
->CtrlSetting
[18] = 0; //default for fragment
4937 ctrl_set
->CtrlSetting
[19] = 0;
4938 ctrl_set
->CtrlSetting
[23] = 0; //default for fragment
4940 ctrl_set
->CtrlSetting
[24] = 0;
4941 ctrl_set
->CtrlSetting
[26] = 0;
4942 ctrl_set
->CtrlSetting
[27] = 0;
4946 sw_tcb
->pHwHeaderPtr
= pHwHeaderPtr
;
4947 sw_tcb
->HwHeaderPhys
= HwHeaderPhys
;
4951 /* initialize the uncached TCB contents -- status is zeroed */
4952 hw_tcb
->CbStatus
= 0xffffffff;
4953 hw_tcb
->CbCommand
= CB_S_BIT
;
4954 hw_tcb
->TxCbFirstTbdAddrLowPart
= HwTbdPhys
;
4955 hw_tcb
->TxCbFirstTbdAddrHighPart
= 0;
4956 hw_tcb
->TxCbTbdNumber
= 0;
4957 if (TcbCount
== (macp
->numTcb
-1)){
4958 /* Turn around TBD */
4961 hw_tcb
->NextCbPhyAddrLowPart
= cpu_to_le32(macp
->txUnCachedPhys
);
4965 hw_tcb
->NextCbPhyAddrLowPart
= (U32
)macp
->txUnCached
;
4967 hw_tcb
->NextCbPhyAddrHighPart
= 0;
4971 hw_tcb
->NextCbPhyAddrLowPart
= HwTcbPhys
+ sizeof(zd1205_HwTCB_t
);
4972 hw_tcb
->NextCbPhyAddrHighPart
= 0;
4977 /* add this TCB to the free list */
4978 zd1205_qlast_txq(macp
, macp
->freeTxQ
, sw_tcb
);
4988 * zd1205_get_stats - get driver statistics
4990 * @dev: adapter's net_device struct
4992 * This routine is called when the OS wants the adapter's stats returned.
4993 * It returns the address of the net_device_stats stucture for the device.
4994 * If the statistics are currently being updated, then they might be incorrect
4995 * for a short while. However, since this cannot actually cause damage, no
4999 struct net_device_stats
*
5000 zd1205_get_stats(struct net_device
*dev
)
5002 struct zd1205_private
*macp
= dev
->priv
;
5004 macp
->drv_stats
.net_stats
.tx_errors
=
5005 macp
->drv_stats
.net_stats
.tx_carrier_errors
+
5006 macp
->drv_stats
.net_stats
.tx_aborted_errors
;
5008 macp
->drv_stats
.net_stats
.rx_errors
=
5009 macp
->drv_stats
.net_stats
.rx_crc_errors
+
5010 macp
->drv_stats
.net_stats
.rx_frame_errors
+
5012 macp
->drv_stats
.net_stats
.rx_length_errors
+
5015 macp
->drv_stats
.rcv_cdt_frames
;
5018 return &(macp
->drv_stats
.net_stats
);
5023 * zd1205_set_mac - set the MAC address
5024 * @dev: adapter's net_device struct
5026 * @addr: the new address
5028 * This routine sets the ethernet address of the board
5037 zd1205_set_mac(struct net_device
*dev
, void *addr
)
5039 struct zd1205_private
*macp
;
5043 struct sockaddr
*p_sockaddr
= (struct sockaddr
*) addr
;
5047 read_lock(&(macp
->isolate_lock
));
5049 if (macp
->driver_isolated
) {
5054 if(!(p_sockaddr
->sa_data
[0] & BIT_0
))
5055 memcpy(&(dev
->dev_addr
[0]), p_sockaddr
->sa_data
, ETH_ALEN
);
5058 printk("########## Chaiort Testing Mode for Embedded System Station #########\n");
5059 printk("HW Address BIT_0 is on\n");
5060 printk("Trasparent mode of Embedded system station for\n");
5061 printk("NetIQ Chaiort Testing is activated\n");
5062 p_sockaddr
->sa_data
[0] = 0;
5063 printk("The MAC of EP behind the station is ");
5065 printk("%02x ", p_sockaddr
->sa_data
[i
]);
5066 printk("\n#####################################################################\n");
5069 zd_writel(cpu_to_le32(*(u32
*)p_sockaddr
->sa_data
), MACAddr_P1
);
5070 zd_writel(cpu_to_le32(*(u32
*)(p_sockaddr
->sa_data
+4)), MACAddr_P2
);
5071 memcpy(macp
->macAdr
,p_sockaddr
->sa_data
,ETH_ALEN
);
5072 memcpy(CustomMAC
,p_sockaddr
->sa_data
,ETH_ALEN
);
5073 memcpy(macp
->cardSetting
.MacAddr
,macp
->macAdr
,ETH_ALEN
);
5075 if (macp
->cardSetting
.BssType
== AP_BSS
){
5076 // Set bssid = MacAddress
5077 memcpy(macp
->BSSID
,macp
->macAdr
,ETH_ALEN
);
5079 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[0]), BSSID_P1
);
5080 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[4]), BSSID_P2
);
5083 zd_writel(STA_RX_FILTER
, ZD_Rx_Filter
);
5085 CustomMACSet
= TRUE
;
5091 read_unlock(&(macp
->isolate_lock
));
5099 zd1205_isolate_driver(struct zd1205_private
*macp
)
5101 write_lock_irq(&(macp
->isolate_lock
));
5102 macp
->driver_isolated
= true;
5103 write_unlock_irq(&(macp
->isolate_lock
));
5104 del_timer_sync(&macp
->watchdog_timer
);
5105 del_timer_sync(&macp
->tm_hking_id
);
5106 del_timer_sync(&macp
->tm_mgt_id
);
5107 del_timer_sync(&macp
->tm_scan_id
);
5108 #if ZDCONF_LP_SUPPORT == 1
5109 if(dot11Obj
.LP_MODE
)
5110 del_timer_sync(&macp
->tm_lp_poll_id
);
5115 if (netif_running(macp
->device
))
5117 netif_carrier_off(macp
->device
);
5118 netif_stop_queue(macp
->device
);
5124 zd1205_change_mtu(struct net_device
*dev
, int new_mtu
)
5127 if ((new_mtu
< 68) || (new_mtu
> (ETH_DATA_LEN
+ VLAN_SIZE
)))
5137 zd1205_close(struct net_device
*dev
)
5140 struct zd1205_private
*macp
= dev
->priv
;
5144 netif_carrier_off(macp
->device
);
5148 while (dot11Obj
.bDeviceInSleep
){
5153 zd1205_isolate_driver(macp
);
5158 mCounterMeasureState
= 0;
5159 macp
->bGkInstalled
= 0;
5161 macp
->cardSetting
.DynKeyMode
=0;
5163 dot11Obj
.MIC_CNT
=FALSE
;
5166 //zd_writel(0x01, Pre_TBTT);
5170 zd_writel(0x0, BCNInterval
);
5173 zd_writel(0x0, LED1
);
5174 zd_writel(0x0, LED2
);
5175 free_irq(dev
->irq
, dev
);
5176 zd1205_device_reset(macp
);
5179 if (!test_bit(ZD1211_UNPLUG
, &macp
->flags
)){
5180 iLED_OFF(macp
, macp
->LinkLEDn
);
5181 zd_writel(0x0, FW_LINK_STATUS
);
5182 //zd1211_disable_net_traffic(macp);
5183 //zd1205_device_reset(macp);
5186 clear_bit(ZD1211_RUNNING
, &macp
->flags
);
5188 //tasklet_kill(&macp->zd1211_rx_tasklet);
5189 //tasklet_kill(&macp->zd1211_tx_tasklet);
5190 //tasklet_kill(&macp->rx_buff_tasklet);
5193 zd1211_unlink_all_urbs(macp
);
5198 zd1205_clear_pools(macp
);
5200 macp
->bPSMSupported
= 0;
5201 dot11Obj
.bDeviceInSleep
= 0;
5205 //set FdescBuf unused
5208 // set the isolate flag to false, so zd1205_open can be called
5210 dot11Obj
.bChScanning
= 0;
5212 macp
->driver_isolated
= false;
5213 mIfaceOpened
= FALSE
;
5224 u8
CalNumOfFrag(struct zd1205_private
*macp
, u32 length
)
5233 pdusize
= macp
->cardSetting
.FragThreshold
;
5235 if ((length
+ CRC32_LEN
) > pdusize
){ //Need fragment
5236 pdusize
-= WLAN_HEADER
+ CRC32_LEN
;
5238 FragNum
= ((length
- WLAN_HEADER
)+ (pdusize
-1)) / pdusize
;
5246 int zd1205_xmit_frame(struct sk_buff
*skb
, struct net_device
*dev
)
5249 int notify_stop
= false;
5250 struct zd1205_private
*macp
= dev
->priv
;
5252 struct skb_buff
*new_skb
= NULL
;
5255 u8
*pHdr
= skb
->data
;
5263 Hash_t
*pHash
= NULL
;
5265 card_Setting_t
*pSetting
= &macp
->cardSetting
;
5267 u8
*pSkbData
= skb
->data
;
5268 u32 SkbLength
= skb
->len
;
5269 BOOLEAN bHashSearchResult
;
5275 //new_skb = skb_copy(skb, GFP_ATOMIC);
5276 #if 0 // mask by Victor Yu, 04-04-2007
5277 while(!new_skb
) printk("new skb is NULL\n");
5279 //if(skb)dev_kfree_skb_irq(skb);
5280 #if 0 // add by Victor Yu. 04-04-2007
5281 if ( new_skb
== NULL
) {
5282 macp
->drv_stats
.net_stats
.tx_dropped
++;
5288 pSkbData
= skb
->data
;
5289 SkbLength
= skb
->len
;
5292 //zd1205_dump_data("tx packet", (u8 *)skb->data, skb->len);
5293 if (pHdr
[0] & BIT_0
)
5296 read_lock(&(macp
->isolate_lock
));
5297 if (macp
->driver_isolated
) {
5299 //#if AAAA03_FIX == 1
5300 //dev_kfree_skb/*_irq*/(skb);
5305 if (!spin_trylock(&macp
->bd_non_tx_lock
)){
5308 //#if AAAA03_FIX == 1
5309 //dev_kfree_skb/*_irq*/(skb);
5314 TypeLen
= (((u16
) pHdr
[12]) << 8) + (pHdr
[13]);
5315 if ((pSetting
->BssType
== INFRASTRUCTURE_BSS
) || (pSetting
->BssType
== INDEPENDENT_BSS
)){
5316 if (dot11Obj
.bDeviceInSleep
){
5317 //queue to upper layer
5320 //#if AAAA03_FIX == 1
5321 //dev_kfree_skb/*_irq*/(skb);
5326 if (pSetting
->BssType
== INFRASTRUCTURE_BSS
)
5328 else if (pSetting
->BssType
== INDEPENDENT_BSS
)
5331 bHashSearchResult
= zd_QueryStaTable(pMac
, (void**)&pHash
);
5332 if ((!macp
->bAssoc
) || ((!bHashSearchResult
) && (!bGroupAddr
))){
5333 //dev_kfree_skb/*_irq*/(skb);
5337 if (macp
->cardSetting
.WPASupport
==1 && pSetting
->BssType
==INFRASTRUCTURE_BSS
)
5339 if (TypeLen
!= 0x888e && pHash
->pkInstalled
==0)
5341 printk(KERN_DEBUG
"*** Block Non-EAPol packet before key installed:%04x\n", TypeLen
);
5342 //dev_kfree_skb/*_irq*/(skb);
5349 else if (pSetting
->BssType
== AP_BSS
){
5350 if (!bGroupAddr
) { //da is unicast
5351 if (!zd_QueryStaTable(pHdr
,(void**)&pHash
)){
5352 //dev_kfree_skb/*_irq*/(skb);
5358 if (mCurrConnUser
==0 || ((pSetting
->DynKeyMode
) && (mGkInstalled
== 0))) {
5359 //dev_kfree_skb/*_irq*/(skb);
5366 if (TypeLen
> 1500){ /* Ethernet 2 frame */
5368 bodyLen
= skb
->len
- 6;
5374 TotalLen
= bodyLen
+ WLAN_HEADER
; //Mac Header(24)
5375 NumOfFrag
= CalNumOfFrag(macp
, TotalLen
);
5377 if (macp
->freeTxQ
->count
< (NumOfFrag
+1)){
5378 macp
->txQueToUpCnt
++;
5381 //#if AAAA03_FIX == 1
5382 //dev_kfree_skb/*_irq*/(skb);
5387 memcpy(&EtherHdr
[0], pHdr
, 14); //save ethernet header
5390 if (bEthType2
){ /* Ethernet 2 frame */
5391 /* DA(6) SA(6) Type(2) Data....(reserved array) */
5392 if (TypeLen
== IPX
) {
5393 memcpy(pHdr
+6, ZD_SNAP_BRIDGE_TUNNEL
, sizeof(ZD_SNAP_BRIDGE_TUNNEL
));
5395 else if(TypeLen
== APPLE_TALK
) {
5396 memcpy(pHdr
+6, zd_Snap_Apple_Type
, sizeof(zd_Snap_Apple_Type
));
5400 memcpy(pHdr
+6, (void *)ZD_SNAP_HEADER
, sizeof(ZD_SNAP_HEADER
));
5402 if (TypeLen
== EAPOL
) {
5403 WPADEBUG("Transmit EAPOL packet\n");
5407 skb
->len
-= 6; /* Minus DA, SA; Plus 802.2LLC Header */
5411 else{ /* 802.3 frame */
5412 /* DA(6) SA(6) Len(2) 802.2_LLC(3) 802.2_SNAP(3+2) Data.... */
5421 //force release for debug only
5422 dev_kfree_skb_irq(skb
);
5426 if (!zd_SendPkt(EtherHdr
, pBody
, bodyLen
, (void *)skb
, bEapol
, pHash
)){
5429 //restore skb data structure
5430 skb
->data
= pSkbData
;
5431 skb
->len
= SkbLength
;
5435 macp
->drv_stats
.net_stats
.tx_bytes
+= skb
->len
;
5436 macp
->drv_stats
.net_stats
.tx_packets
++;
5439 spin_unlock(&macp
->bd_non_tx_lock
);
5442 read_unlock(&(macp
->isolate_lock
));
5445 //netif_carrier_off(dev);
5446 netif_stop_queue(dev
);
5450 #if 0 // mask by Victor Yu. 04-04-2007
5459 void zd1205_sw_release(void)
5461 zd_EventNotify(EVENT_BUF_RELEASE
, 0, 0, 0);
5464 #if 1 // add by Victor Yu. 07-11-2006
5465 static u32
victor_do_div(u64 n
, u32 base
)
5473 void zd1205_sleep_reset(struct zd1205_private
*macp
)
5484 unsigned long flags
;
5487 //return; //for debug only, test SW
5489 ZD1211DEBUG(1, "Prepare to enter sleep mode\n");
5490 netif_stop_queue(macp
->device
);
5491 //netif_carrier_off(macp->device);
5492 //HW_RadioOnOff(&dot11Obj, 0);
5495 ul_BcnItvl
= zd_readl(ZD_BCNInterval
) & 0xFFFF;
5496 HW_UpdatePreTBTT(&dot11Obj
, ul_BcnItvl
-BEFORE_BEACON
);
5497 ul_pretbtt
= zd_readl(ZD_Pre_TBTT
);
5499 ul_BcnItvl
= dot11Obj
.BeaconInterval
;
5500 if (ul_BcnItvl
< (BEFORE_BEACON
))
5502 ul_pretbtt
= ul_BcnItvl
-BEFORE_BEACON
;//Adjust Pre-TBTT occur before TBTT */
5504 //ZD1211DEBUG(1, "Pre_TBTT = %u\n", ul_pretbtt);
5508 // Make sure that the time issued sleep-command is not too close to Pre_TBTT.
5509 // Also make sure that sleep-command is out of Beacon-Tx duration.
5510 //For PSM state becomes steady
5511 if(loopCheck
++ > 100)
5513 printk("infinite loop occurs in %s\n", __FUNCTION__
);
5515 tmpvalue
= zd_readl(ZD_TSF_LowPart
);
5516 TSFTimer
= tmpvalue
;
5517 tmpvalue
= zd_readl(ZD_TSF_HighPart
);
5518 TSFTimer
+= (((u64
)tmpvalue
) << 32);
5519 TSFTimer
= TSFTimer
>> 10; // in unit of TU
5520 //printk("TSF(TU) %d \n", TSFTimer);
5521 //printk("BeaconInterval = %d\n", ul_BcnItvl);
5522 //printk("TSF mod BeaconInterval = %d\n", (TSFTimer % ul_BcnItvl));
5524 #if 0 // mask by Victor Yu. 07-11-2006
5525 ul_Rem
= do_div(TSFTimer
, ul_BcnItvl
);
5527 ul_Rem
= victor_do_div(TSFTimer
, ul_BcnItvl
);
5530 if ((ul_pretbtt
> ul_Rem
) || (macp
->bSurpriseRemoved
))
5532 //++ Ensure the following is an atomic operation.
5533 ZD1211DEBUG(1, "Rem=%u\n",ul_Rem
);
5534 if ( (((ul_pretbtt
- ul_Rem
) >= 3) && (ul_Rem
> BEACON_TIME
) && (!atomic_read(&macp
->DoNotSleep
))) || (macp
->bSurpriseRemoved
))
5536 //printk("Start To Sleep\n");
5537 down(&macp
->ps_sem
); // for zd1211
5539 tmpvalue
= zd_readl(ZD_PS_Ctrl
); //Because readout value is always zero in zd1211, no need perform read operation before modifying.
5540 zd_writel((tmpvalue
| BIT_0
), ZD_PS_Ctrl
);
5542 zd_writel(BIT_28
| BIT_0
, ZD_PS_Ctrl
); // Keep Power on of 44MHz Osc while in sleep.
5544 dot11Obj
.bDeviceInSleep
= 1;
5553 macp
->TxStartTime
= 0;
5558 void update_beacon_interval(struct zd1205_private
*macp
, int val
)
5567 /* One thing must be sure that BcnInterval > Pre_TBTT > ATIMWnd >= 0 */
5568 if(BcnInterval
< 5) {
5573 ul_PreTBTT
= zd_readl(Pre_TBTT
);
5575 if(ul_PreTBTT
< 4) {
5580 if(ul_PreTBTT
>= BcnInterval
) {
5581 ul_PreTBTT
= BcnInterval
- 1;
5584 zd_writel(ul_PreTBTT
, Pre_TBTT
);
5586 tmpvalue
= zd_readl(BCNInterval
);
5587 tmpvalue
&= ~0xffffffff;
5588 tmpvalue
|= BcnInterval
;
5589 zd_writel(tmpvalue
, BCNInterval
);
5594 void zd1205_device_reset(struct zd1205_private
*macp
)
5599 /* Update the value of Beacon Interval and Pre TBTT */
5600 update_beacon_interval(macp
, 0x2);
5601 zd_writel(0x01, Pre_TBTT
);
5603 tmp_value
= zd_readl(PS_Ctrl
);
5604 zd_writel(tmp_value
| BIT_0
, PS_Ctrl
);
5605 dot11Obj
.bDeviceInSleep
= 1;
5606 /* Sleep for 5 msec */
5613 void zd1205_recycle_tx(struct zd1205_private
*macp
)
5616 zd1205_SwTcb_t
*sw_tcb
;
5620 while (macp
->activeTxQ
->count
){
5621 sw_tcb
= zd1205_first_txq(macp
, macp
->activeTxQ
);
5622 zd1205_transmit_cleanup(macp
, sw_tcb
);
5624 if (!sw_tcb
->LastFrag
)
5627 zd_EventNotify(EVENT_TX_COMPLETE
, ZD_RETRY_FAILED
, (U32
)sw_tcb
->MsgID
, sw_tcb
->aid
);
5630 if (macp
->activeTxQ
->count
){
5631 sw_tcb
= macp
->activeTxQ
->first
;
5632 zd1205_start_download(sw_tcb
->TcbPhys
);
5637 void zd1205_process_wakeup(struct zd1205_private
*macp
)
5639 card_Setting_t
*pSetting
= &macp
->cardSetting
;
5648 if (pSetting
->BssType
== AP_BSS
){
5649 HW_EnableBeacon(&dot11Obj
, pSetting
->BeaconInterval
, pSetting
->DtimPeriod
, AP_BSS
);
5650 HW_SetRfChannel(&dot11Obj
, pSetting
->Channel
, 0,macp
->cardSetting
.MacMode
);
5653 else if (pSetting
->BssType
== INFRASTRUCTURE_BSS
){
5654 //HW_SetRfChannel(&dot11Obj, dot11Obj.Channel, 0);
5656 if ((netif_running(macp
->device
)) && (macp
->bAssoc
)){
5657 netif_wake_queue(macp
->device
); //resume tx
5661 //printk(KERN_ERR "Bf RF ON: %lu\n",jiffies);
5662 //HW_RadioOnOff(&dot11Obj, 1);
5663 //printk(KERN_ERR "After RF ON: %lu\n", jiffies);
5666 tmpvalue
= zd_readl(ZD_TSF_LowPart
);
5667 TSFTimer
= tmpvalue
;
5668 tmpvalue
= zd_readl(ZD_TSF_HighPart
);
5669 TSFTimer
+= (((u64
)tmpvalue
) << 32);
5670 TSFTimer
= TSFTimer
>> 10; // in unit of TU
5672 //printk("TSF(TU) %d \n", TSFTimer);
5673 //printk("BeaconInterval = %d\n", dot11Obj.BeaconInterval);
5674 //printk("TSF mod BeaconInterval = %d\n", (TSFTimer % dot11Obj.BeaconInterval));
5675 //printk("Now, Device had been waken up\n");
5677 tmpvalue
= zd_readl(ZD_DeviceState
);
5678 //printk("DeviceState == %x\n", tmpvalue);
5680 // In IBSS mode, BCNATIM is now operating, therefore, the Tx-State will not
5681 // stay in idle state. So, we change form 0xffff to 0xff, ie, we just make
5683 // sure that bus-masters, both Tx and Rx, are in idle-state.
5687 dot11Obj
.bDeviceInSleep
= 0;
5689 // Solve Sequence number duplication problem after wakeup.
5690 macp
->SequenceNum
= 0;
5693 zd1205_recycle_tx(macp
);
5697 zd1205_start_ru(macp
);
5699 //zd1205_recycle_rx(macp);
5704 if ((netif_running(macp
->device
)) && (macp
->bAssoc
))
5706 netif_carrier_on(macp
->device
);
5707 netif_wake_queue(macp
->device
);
5716 void zd1205_sw_reset(struct zd1205_private
*macp
)
5718 zd1205_disable_int();
5719 zd1205_tx_isr(macp
);
5720 memset(macp
->txUnCached
, 0x00, macp
->txUnCachedSize
);
5722 zd1205_setup_tcb_pool(macp
);
5723 zd1205_sleep_reset(macp
);
5724 zd1205_start_ru(macp
);
5725 zd_EventNotify(EVENT_SW_RESET
, 0, 0, 0);
5726 zd1205_enable_int();
5728 if(netif_running(macp
->device
))
5730 netif_carrier_on(macp
->device
);
5731 netif_wake_queue(macp
->device
);
5738 * zd1205_sw_init - initialize software structs
5739 * @macp: atapter's private data struct
5741 * This routine initializes all software structures. Sets up the
5742 * circular structures for the RFD's & TCB's. Allocates the per board
5743 * structure for storing adapter information. The CSR is also memory
5744 * mapped in this routine.
5747 * true: if S/W was successfully initialized
5753 static unsigned char zd1205_sw_init(struct zd1205_private
*macp
)
5756 zd1205_init_card_setting(macp
);
5757 #if 0 // mask by Victor Yu. 004-04-2007, we don't use it.
5758 zd1205_load_card_setting(macp
, 1);
5760 zd1205_set_zd_cbs((zd_80211Obj_t
*)&dot11Obj
);
5761 zd_CmdProcess(CMD_RESET_80211
, &dot11Obj
, 0);
5764 /* Initialize our spinlocks */
5765 spin_lock_init(&(macp
->bd_lock
));
5766 spin_lock_init(&(macp
->bd_non_tx_lock
));
5767 //spin_lock_init(&(macp->q_lock));
5768 spin_lock_init(&(macp
->conf_lock
));
5770 tasklet_init(&macp
->zd1205_tasklet
, zd1205_action
, 0);
5771 tasklet_init(&macp
->zd1205_ps_tasklet
, zd1205_ps_action
, 0);
5772 tasklet_init(&macp
->zd1205_tx_tasklet
, zd1205_tx_action
, 0);
5775 //spin_lock_init(&(macp->intr_lock));
5776 spin_lock_init(&(macp
->rx_pool_lock
));
5777 tasklet_init(&macp
->zd1211_rx_tasklet
, zd1211_rx_isr
, (unsigned long)macp
);
5778 tasklet_init(&macp
->zd1211_tx_tasklet
, zd1211_tx_isr
, (unsigned long)macp
);
5779 tasklet_init(&macp
->rx_buff_tasklet
, zd1211_alloc_rx
, (unsigned long)macp
);
5782 macp
->isolate_lock
= RW_LOCK_UNLOCKED
;
5783 macp
->driver_isolated
= false;
5784 #if ZDCONF_LP_SUPPORT == 1
5785 dot11Obj
.LP_MODE
= 0;
5786 dot11Obj
.BURST_MODE
= 0;
5795 * zd1205_hw_init - initialized tthe hardware
5796 * @macp: atapter's private data struct
5799 * @reset_cmd: s/w reset or selective reset
5802 * This routine performs a reset on the adapter, and configures the adapter.
5803 * This includes configuring the 82557 LAN controller, validating and setting
5806 * the node address, detecting and configuring the Phy chip on the adapter,
5807 * and initializing all of the on chip counters.
5810 * true - If the adapter was initialized
5811 * false - If the adapter failed initialization
5814 zd1205_hw_init(struct zd1205_private
*macp
)
5819 HW_ResetPhy(&dot11Obj
);
5820 HW_InitHMAC(&dot11Obj
);
5821 zd1205_config(macp
);
5829 void zd1211_set_multicast(struct zd1205_private
*macp
)
5831 struct net_device
*dev
= macp
->device
;
5832 struct dev_mc_list
*mc_list
;
5841 if (!(dev
->flags
& IFF_UP
))
5844 if (macp
->cardSetting
.BssType
== AP_BSS
)
5848 zd_writel(0, GroupHash_P1
);
5849 zd_writel(0x80000000, GroupHash_P2
);
5850 macp
->MulticastAddr
[0] = dev
->mc_count
;
5851 mcLen
= dev
->mc_count
*ETH_ALEN
;
5854 for (i
= 0, mc_list
= dev
->mc_list
;
5855 (i
< dev
->mc_count
) && (i
< MAX_MULTICAST_ADDRS
);
5857 i
++, mc_list
= mc_list
->next
) {
5860 //zd1205_dump_data("mc addr", (u8 *)&(mc_list->dmi_addr), ETH_ALEN);
5861 memcpy(&macp
->MulticastAddr
[1+i
* ETH_ALEN
], (u8
*) &(mc_list
->dmi_addr
), ETH_ALEN
);
5863 macp
->MulticastAddr
[mcLen
+1] = 0;
5864 //zd1205_dump_data("MulticastAddr", (u8 *)macp->MulticastAddr, mcLen +2);
5866 memcpy(mcBuffer
, &macp
->MulticastAddr
[1], mcLen
);
5868 //zd1205_dump_data("mcBuffer", (u8 *)mcBuffer, mcLen);
5871 for (i
=0; i
<mcLen
; i
++){
5873 *(pKey
+i
) = (*(pKey
+i
)) >> 2;
5874 if (*(pKey
+i
) >= 32){
5875 tmpValue
= zd_readl(GroupHash_P2
);
5877 tmpValue
|= (0x01 << (*(pKey
+i
)-32));
5878 zd_writel(tmpValue
, GroupHash_P2
);
5883 tmpValue
= zd_readl(GroupHash_P1
);
5884 tmpValue
|= (0x01 << (*(pKey
+i
)));
5885 zd_writel(tmpValue
, GroupHash_P1
);
5890 if(dev
->flags
& IFF_PROMISC
)
5891 printk("Promiscuous mode enabled.\n");
5893 if(dev
->flags
& IFF_PROMISC
) {
5894 zd_writel(0xffffffff,GroupHash_P1
);
5895 zd_writel(0xffffffff,GroupHash_P2
);
5897 else if( dev
->flags
& IFF_ALLMULTI
) {
5898 zd_writel(0xffffffff,GroupHash_P1
);
5899 zd_writel(0xffffffff,GroupHash_P2
);
5904 macp
->GroupHashP1
= zd_readl(GroupHash_P1
);
5907 macp
->GroupHashP2
= zd_readl(GroupHash_P2
);
5909 ZD1211DEBUG(1, "GroupHashP1 = %x\n", macp
->GroupHashP1
);
5910 ZD1211DEBUG(1, "GroupHashP2 = %x\n", macp
->GroupHashP2
);
5913 //zd_writel(0xffffffff, GroupHash_P1);
5915 //zd_writel(0xffffffff, GroupHash_P2);
5919 void zd1205_set_multi(struct net_device
*dev
)
5921 struct zd1205_private
*macp
= dev
->priv
;
5924 defer_kevent(macp
, KEVENT_SET_MULTICAST
);
5926 zd1211_set_multicast(macp
);
5933 #define TX_TIMEOUT (4*100) //4sec
5935 #define TX_TIMEOUT (4*1000*1000) //4sec
5941 * @dev: adapter's net_device struct
5943 * This routine runs every 1 seconds and updates our statitics and link state,
5944 * and refreshs txthld value.
5947 zd1205_watchdog(struct zd1205_private
*macp
)
5951 card_Setting_t
*pSetting
= &macp
->cardSetting
;
5952 u32 TxBytes
, RxBytes
;
5959 //read_lock(&(macp->isolate_lock));
5961 if (macp
->driver_isolated
) {
5966 if (!netif_running(macp
->device
)) {
5974 macp
->CheckForHangLoop
++;
5975 #if ZDCONF_LP_SUPPORT == 1
5976 if(Turbo_getBurst_Status() && !Turbo_BurstSTA_Check())
5980 else if(!Turbo_getBurst_Status() && Turbo_BurstSTA_Check())
5987 TxBytes
= macp
->TotalTxDataFrmBytes
;
5988 RxBytes
= macp
->TotalRxDataFrmBytes
;
5990 // Check if AP(Access Point) still alive in the current channel
5992 if (pSetting
->BssType
== INFRASTRUCTURE_BSS
)
5995 { // We thought the Station is still associated with AP.
5996 // dump dot11DesiredSsid
5998 //U8 ssidLenToDump=dot11DesiredSsid.buf[1];
5999 //for (cbTemp=0; cbTemp<ssidLenToDump; cbTemp++)
6000 // printk("%c", dot11DesiredSsid.buf[2+cbTemp]);
6003 if (!macp
->bAPAlive
)
6004 { // The AP-exist flag is not set by any received Mgt or Data frame yet, so we increase the lost-Beacon counter.
6005 macp
->NoBcnDetectedCnt
++;
6006 if (dot11Obj
.bChScanning
)
6007 macp
->NoBcnDetectedCnt
= 0;
6009 if (macp
->activeTxQ
->count
> 12)
6010 macp
->NoBcnDetectedCnt
= 0;
6012 if (macp
->NoBcnDetectedCnt
> 5){
6013 printk(KERN_ERR
"******We Lose AP for 5 seconds\n");
6014 if(!mCounterMeasureState
) {
6015 zd1205_dis_connect(macp
);
6016 //zd_CmdProcess(CMD_DIS_CONNECT, 0, 0);
6017 if (macp
->cardSetting
.ap_scan
!= 1)
6018 zd_CmdProcess(CMD_ROAMING
, 0, 0);
6021 zdcb_status_notify(STA_DISASSOCIATED
, &macp
->BSSID
[0]);
6024 macp
->NoBcnDetectedCnt
= 0;
6025 //defer_kevent(macp, KEVENT_DIS_CONNECT);
6029 { // We have received at least one Mgt or Data frame from AP, so we reset the lost-Beacon counter.
6030 macp
->NoBcnDetectedCnt
= 0;
6033 macp
->bAPAlive
= 0; // Clear AP-exist flag, it will be Set when a Mgt or Data frame is received.
6036 { // macp->bAssoc ==0, we are in disconnected state.
6038 //printk(KERN_ERR "***** We are disconnected\n");
6040 if (mTmRetryConnect
>= 6)
6042 if (macp
->cardSetting
.ap_scan
!= 1)
6043 { //when wpa_supplicant takes care of scanning and AP selection, it is not necessary for driver attempt to reconnect.
6044 if (zd_CmdProcess(CMD_ROAMING
,0,0))
6050 {// ap_scan=1 in wpa_supplicant.conf
6051 ZD1211DEBUG(0, "wpa_supplicant takes care of scanning and AP selection, no need to roam driver itself\n");
6052 mTmRetryConnect
= 0;
6058 else if (pSetting
->BssType
== AP_BSS
)
6060 if((pSetting
->MacMode
==MIXED_MODE
|| pSetting
->MacMode
==PURE_G_MODE
))
6061 {// Try to disable protection mechanism if OLBC not exist any more.
6062 if (dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
)
6064 if (macp
->bOLBC
==0) // The bOLBC will be incremented after checking OLBC by calling zd1205_CheckOverlapBss.
6066 if(++macp
->nOLBC_CounterInSec
> 2)
6068 if (mNumBOnlySta
==0)
6070 zd_EventNotify(EVENT_ENABLE_PROTECTION
, 0,0,0);//Disable protection mode.
6072 macp
->nOLBC_CounterInSec
=0;
6076 {// OLBC condition exist.
6077 macp
->nOLBC_CounterInSec
=0;
6082 }// End of AP_BSS condition
6083 /*===prince add begin
6084 else if( pSetting->BssType == INDEPENDENT_BSS )
6086 if ( mMacMode == PURE_A_MODE )
6089 //update beacon interval
6090 get_random_bytes(&myrand,sizeof(U32)) ;
6091 //pSetting->bcnInterval = jiffies % 21 + 90;
6092 pSetting->BeaconInterval = myrand % 21 + 90;
6093 mBeaconPeriod = pSetting->BeaconInterval; //MZCai
6094 HW_EnableBeacon(&dot11Obj, pSetting->BeaconInterval, 0 ,INDEPENDENT_BSS );
6101 if ((macp
->bPSMSupported
) && (macp
->bAssoc
)){
6103 // Check if we need to enter the PSM (power-save mode), CAM mode or no-change
6105 if ((TxBytes
+ RxBytes
<= macp
->PSThreshhold
))
6107 macp
->SuggestionMode
= PS_PSM
;
6110 macp
->SuggestionMode
= PS_CAM
;
6113 macp
->TotalTxDataFrmBytes
= 0;
6114 macp
->TotalRxDataFrmBytes
= 0;
6121 zd1205_watchdog_cb(struct net_device
*dev
)
6123 struct zd1205_private
*macp
= dev
->priv
;
6126 defer_kevent(macp
, KEVENT_WATCH_DOG
);
6127 mod_timer(&(macp
->watchdog_timer
), jiffies
+(1*HZ
));
6129 zd1205_watchdog(macp
);
6130 mod_timer(&(macp
->watchdog_timer
), jiffies
+(1*HZ
));
6136 * zd1205_pci_setup - setup the adapter's PCI information
6138 * @pcid: adapter's pci_dev struct
6139 * @macp: atapter's private data struct
6142 * This routine sets up all PCI information for the adapter. It enables the bus
6143 * master bit (some BIOS don't do this), requests memory ans I/O regions, and
6144 * calls ioremap() on the adapter's memory region.
6149 * true: if successfull
6153 static unsigned char
6154 zd1205_pci_setup(struct pci_dev
*pcid
, struct zd1205_private
*macp
)
6157 struct net_device
*dev
= macp
->device
;
6163 if ((rc
= pci_enable_device(pcid
)) != 0) {
6167 if (!pci_set_dma_mask(pcid
, 0xffffffffffffffff)){
6168 macp
->using_dac
= 1;
6169 printk(KERN_DEBUG
"zd1205: support 64-bit DMA.\n");
6171 else if (!pci_set_dma_mask(pcid
, 0xffffffff)){
6173 macp
->using_dac
= 0;
6174 printk(KERN_DEBUG
"zd1205: support 32-bit DMA.\n");
6180 printk(KERN_ERR
"zd1205: No suitable DMA available.\n");
6185 /* dev and ven ID have already been checked so it is our device */
6186 pci_read_config_byte(pcid
, PCI_REVISION_ID
, (u8
*) &(macp
->rev_id
));
6188 /* address #0 is a memory region */
6190 dev
->mem_start
= pci_resource_start(pcid
, 0);
6191 dev
->mem_end
= dev
->mem_start
+ ZD1205_REGS_SIZE
;
6193 /* address #1 is a IO region */
6194 dev
->base_addr
= pci_resource_start(pcid
, 1);
6195 if ((rc
= pci_request_regions(pcid
, zd1205_short_driver_name
)) != 0) {
6199 pci_enable_wake(pcid
, 0, 0);
6201 /* if Bus Mastering is off, turn it on! */
6202 pci_set_master(pcid
);
6204 /* address #0 is a memory mapping */
6205 macp
->regp
= (void *)ioremap_nocache(dev
->mem_start
, ZD1205_REGS_SIZE
);
6206 dot11Obj
.reg
= macp
->regp
;
6207 //printk(KERN_DEBUG "zd1205: dot11Obj.reg = %x\n", (u32)dot11Obj.reg);
6211 printk(KERN_ERR
"zd1205: %s: Failed to map PCI address 0x%lX\n",
6212 dev
->name
, pci_resource_start(pcid
, 0));
6217 printk(KERN_DEBUG
"zd1205: mapping base addr = %x\n", (u32
)macp
->regp
);
6223 pci_release_regions(pcid
);
6227 pci_disable_device(pcid
);
6239 * zd1205_alloc_space - allocate private driver data
6240 * @macp: atapter's private data struct
6243 * This routine allocates memory for the driver. Memory allocated is for the
6244 * selftest and statistics structures.
6247 * 0: if the operation was successful
6248 * %-ENOMEM: if memory allocation failed
6255 zd1205_alloc_space(struct zd1205_private
*macp
)
6257 /* deal with Tx cached memory */
6258 macp
->txCachedSize
= (macp
->numTcb
* sizeof(zd1205_SwTcb_t
));
6259 macp
->txCached
= kmalloc(macp
->txCachedSize
, GFP_ATOMIC
);
6261 if (!macp
->txCached
){
6262 printk(KERN_ERR
"zd1205: kmalloc txCached failed\n");
6269 memset(macp
->txCached
, 0, macp
->txCachedSize
);
6278 zd1205_dealloc_space(struct zd1205_private
*macp
)
6281 kfree(macp
->txCached
);
6287 /* Read the permanent ethernet address from the eprom. */
6289 zd1205_rd_eaddr(struct zd1205_private
*macp
)
6291 #if defined FLASH_MAC
6293 #include <linux/mtd/mtd.h>
6294 struct mtd_info
*mtd
;
6296 mtd
= get_mtd_device(NULL
, 0);
6299 mtd
->read(mtd
, 0x90, 6, &len
, macp
->macAdr
);
6300 memcpy( macp
->device
->dev_addr
, macp
->macAdr
,6 );
6301 memcpy( macp
->cardSetting
.MacAddr
, macp
->macAdr
,6 );
6312 //The MAC is set by User. We don't load it from EEPROM.
6314 tmpValue
= zd_readl(E2P_MACADDR_P1
);
6315 ZD1211DEBUG(1, "E2P_MACADDR_P1 = %08x\n", tmpValue
);
6320 macp
->device
->dev_addr
[0] = macp
->macAdr
[0] = (u8
)tmpValue
;//0x00;
6321 macp
->device
->dev_addr
[1] = macp
->macAdr
[1] = (u8
)(tmpValue
>> 8);//0xA0;
6322 macp
->device
->dev_addr
[2] = macp
->macAdr
[2] = (u8
)(tmpValue
>> 16);//0xC5;
6323 macp
->device
->dev_addr
[3] = macp
->macAdr
[3] = (u8
)(tmpValue
>> 24);//0x11;
6324 tmpValue
= zd_readl(E2P_MACADDR_P2
);
6325 ZD1211DEBUG(1, "E2P_MACADDR_P2 = %08x\n", tmpValue
);
6326 macp
->device
->dev_addr
[4] = macp
->macAdr
[4] = (u8
)tmpValue
;//0x22;
6327 macp
->device
->dev_addr
[5] = macp
->macAdr
[5] = (u8
)(tmpValue
>> 8);//0x33;
6329 ZD1211DEBUG(0, "MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n",
6330 macp
->device
->dev_addr
[0], macp
->device
->dev_addr
[1], macp
->device
->dev_addr
[2],
6331 macp
->device
->dev_addr
[3], macp
->device
->dev_addr
[4], macp
->device
->dev_addr
[5]);
6334 macp
->cardSetting
.MacAddr
[0] = macp
->macAdr
[0];
6336 macp
->cardSetting
.MacAddr
[1] = macp
->macAdr
[1];
6338 macp
->cardSetting
.MacAddr
[2] = macp
->macAdr
[2];
6339 macp
->cardSetting
.MacAddr
[3] = macp
->macAdr
[3];
6341 macp
->cardSetting
.MacAddr
[4] = macp
->macAdr
[4];
6342 macp
->cardSetting
.MacAddr
[5] = macp
->macAdr
[5];
6348 zd1205_lock(struct zd1205_private
*macp
)
6351 spin_lock_bh(&macp
->conf_lock
);
6353 spin_lock(&macp
->conf_lock
);
6358 zd1205_unlock(struct zd1205_private
*macp
)
6361 spin_unlock_bh(&macp
->conf_lock
);
6363 spin_unlock(&macp
->conf_lock
);
6367 //wireless extension helper functions
6368 /* taken from orinoco.c ;-) */
6369 const u32 channel_frequency
[] = {
6370 2412, 2417, 2422, 2427, 2432, 2437, 2442,
6371 2447, 2452, 2457, 2462, 2467, 2472, 2484
6374 const u32 channel_frequency_11A
[] = {
6375 //Even element for Channel Number, Odd for Frequency
6419 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
6420 #define NUM_CHANNELS_11A ( (sizeof(channel_frequency_11A)/2) / sizeof(u32))
6422 #define MAX_KEY_SIZE 13
6423 //Find the Channel Frequency in channel_frequency_11A
6424 static u32
channel_11A_to_Freq(const u32 channel
){
6427 for(i
=0;i
<NUM_CHANNELS_11A
;i
++) {
6428 if(channel
== channel_frequency_11A
[i
*2])
6429 return channel_frequency_11A
[i
*2 + 1];
6431 // printk("\n\nWarnning channel_11A_to_Freq fail(CH:%d)\n\n",channel);
6432 // printk("\n\nZero Return\n\n");
6436 static u32
Freq_11A_to_channel(const u32 freq
) {
6439 for(i
=0;i
<NUM_CHANNELS_11A
;i
++) {
6440 if(freq
== channel_frequency_11A
[i
*2 + 1])
6441 return channel_frequency_11A
[i
*2];
6443 printk("\n\nWarnning Freq_11A_to_channel fail(CH:%d)\n\n",freq
);
6444 printk("\n\nZero Return\n\n");
6449 #define MIN_KEY_SIZE 5
6452 zd1205_ioctl_setiwencode(struct net_device
*dev
, struct iw_point
*erq
, char *key
)
6454 //BOOLEAN bReconnect=FALSE;
6455 struct zd1205_private
*macp
= dev
->priv
;
6456 card_Setting_t
*pSetting
= &macp
->cardSetting
;
6458 if (erq
->length
> 0)
6460 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
6461 int current_index
= pSetting
->EncryKeyId
;
6463 // ZD1211DEBUG(1, "index = %d\n", index);
6464 // ZD1211DEBUG(1, "erq->length = %d\n", erq->length);
6466 if (erq
->length
> MAX_KEY_SIZE
)
6469 if ((index
< 0) || (index
>= 4))
6470 index
= current_index
;
6472 /* Set the length */
6473 if (erq
->length
> MIN_KEY_SIZE
){
6474 pSetting
->WepKeyLen
= MAX_KEY_SIZE
;
6475 pSetting
->EncryMode
= WEP128
;
6478 // if (erq->length > 0){
6479 pSetting
->WepKeyLen
= MIN_KEY_SIZE
;
6480 pSetting
->EncryMode
= WEP64
;
6483 // pSetting->WepKeyLen = 0; /* Disable the key */
6484 // pSetting->EncryMode = NO_WEP;
6488 /* Check if the key is not marked as invalid */
6489 if (!(erq
->flags
& IW_ENCODE_NOKEY
))
6490 { // for command: key xxxxxxxxxx [n]
6491 // ZD1211DEBUG(0, "Set contents of key %d\n", index+1);
6492 pSetting
->EncryKeyId
= index
;
6493 memcpy(&pSetting
->keyVector
[index
][0], key
, pSetting
->WepKeyLen
);
6494 zd1205_config_wep_keys(macp
);
6497 { // For command: key on
6498 // ZD1211DEBUG(0, "key %d is enabled\n", index+1);
6501 /* WE specify that if a valid key is set, encryption
6502 * should be enabled (user may turn it off later)
6503 * This is also how "iwconfig ethX key on" works */
6504 /*if ((index == current_index) && (pSetting->WepKeyLen > 0) &&
6505 (pSetting->EncryOnOff == 0)) {
6506 pSetting->EncryOnOff = 1;
6508 pSetting
->EncryOnOff
=1;
6510 else if(erq
->flags
& IW_ENCODE_DISABLED
)
6511 { // for command: key off
6512 // ZD1211DEBUG(0, "Disable Encryption\n");
6513 pSetting
->EncryOnOff
=0;
6517 /* Do we want to just set the transmit key index ? */
6518 // For command: (erq->length==0)
6519 // key on (If no key ever set)
6520 // key [n] , change current active key
6521 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
6522 //ZD1211DEBUG(0, "change key %d as active key\n", index+1);
6523 if ((index
>= 0) && (index
< 4))
6525 // ZD1211DEBUG(0, "Active key id=%d\n", index+1);
6526 pSetting
->EncryKeyId
= index
; // Because pSetting->WepKeyLen has been set, it is not necessary to set it again!
6527 pSetting
->EncryOnOff
= 1;
6529 else /* Don't complain if only change the mode */
6531 if(!(erq
->flags
& IW_ENCODE_MODE
))
6533 // ZD1211DEBUG(0, "change mode for invalid key id:%d\n",index+1);
6538 if(erq
->flags
& IW_ENCODE_RESTRICTED
){
6539 pSetting
->EncryOnOff
= 1;
6542 if(erq
->flags
& IW_ENCODE_OPEN
) {
6543 pSetting
->EncryOnOff
= 1; // Only Wep
6546 // ZD1211DEBUG(0,"pSetting->EncryOnOff: %d\n", pSetting->EncryOnOff);
6547 if (mPrivacyInvoked
== pSetting
->EncryOnOff
)
6548 { // Privacy setting is the same as before one, No need do reconnect, just update some global parameters.
6550 mKeyFormat
= pSetting
->EncryMode
;
6551 mKeyId
= pSetting
->EncryKeyId
;
6552 mPrivacyInvoked
= pSetting
->EncryOnOff
;
6553 if (mPrivacyInvoked
)
6554 mCap
|= CAP_PRIVACY
;
6556 mCap
&= ~CAP_PRIVACY
;
6557 memcpy(&mKeyVector
[0][0], &pSetting
->keyVector
[0][0],sizeof(mKeyVector
));
6558 mWepKeyLen
= pSetting
->WepKeyLen
;
6559 printk(KERN_DEBUG
"Just Update WEP key\n");
6562 printk(KERN_DEBUG
"Update CardSetting\n");
6566 defer_kevent(macp
, KEVENT_UPDATE_SETTING
);
6568 zd_UpdateCardSetting(pSetting
);
6576 zd1205_ioctl_getiwencode(struct net_device
*dev
, struct iw_point
*erq
, char *key
)
6580 struct zd1205_private
*macp
= dev
->priv
;
6581 card_Setting_t
*pSetting
= &macp
->cardSetting
;
6585 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
6588 if (pSetting
->EncryOnOff
){
6589 erq
->flags
= IW_ENCODE_OPEN
;
6593 erq
->flags
= IW_ENCODE_DISABLED
;
6596 /* We can't return the key, so set the proper flag and return zero */
6597 erq
->flags
|= IW_ENCODE_NOKEY
;
6600 /* Which key do we want ? -1 -> tx index */
6602 if((index
< 0) || (index
>= 4))
6603 index
= pSetting
->EncryKeyId
;
6606 erq
->flags
|= index
+ 1;
6607 /* Copy the key to the user buffer */
6609 erq
->length
= pSetting
->WepKeyLen
;
6610 if (erq
->length
> 16) {
6615 zd1205_unlock(macp
);
6622 zd1205_ioctl_setessid(struct net_device
*dev
, struct iw_point
*erq
)
6624 struct zd1205_private
*macp
= dev
->priv
;
6625 char essidbuf
[IW_ESSID_MAX_SIZE
+1];
6628 memset(&essidbuf
, 0, sizeof(essidbuf
));
6632 if (erq
->length
> (IW_ESSID_MAX_SIZE
+1))
6635 if (copy_from_user(&essidbuf
, erq
->pointer
, erq
->length
))
6641 //essidbuf[erq->length] = '\0';
6642 memcpy(&macp
->cardSetting
.Info_SSID
[2], essidbuf
, erq
->length
);
6643 macp
->cardSetting
.Info_SSID
[1] = strlen(essidbuf
);
6645 //memcpy(&macp->cardSetting.Info_SSID[2], essidbuf, erq->length-1);
6646 //macp->cardSetting.Info_SSID[1] = erq->length-1;
6647 zd1205_unlock(macp
);
6652 zd1205_ioctl_setbssid(struct net_device
*dev
, struct iwreq
*wrq
)
6654 //struct zd1205_private *macp = dev->priv;
6655 memcpy(dot11DesiredBssid
, &wrq
->u
.ap_addr
.sa_data
, ETH_ALEN
);
6656 //ZD1211DEBUG(0,"set AP BSSID=" MACSTR "\n",MAC2STR(dot11DesiredBssid));
6662 zd1205_ioctl_getessid(struct net_device
*dev
, struct iw_point
*erq
)
6664 struct zd1205_private
*macp
= dev
->priv
;
6665 char essidbuf
[IW_ESSID_MAX_SIZE
+1];
6671 len
= dot11Obj
.CurrSsid
[1];
6672 memcpy(essidbuf
, &dot11Obj
.CurrSsid
[2], len
);
6675 len
= macp
->cardSetting
.Info_SSID
[1];
6676 memcpy(essidbuf
, &macp
->cardSetting
.Info_SSID
[2], len
);
6680 zd1205_unlock(macp
);
6683 erq
->length
= strlen(essidbuf
);
6685 WPADEBUG("zd1205_ioctl_getessid: %s\n", essidbuf
);
6687 //erq->length = strlen(essidbuf) + 1;
6688 //zd1205_dump_data("essidbuf", (u8 *)essidbuf, erq->length);
6691 if ( copy_to_user(erq
->pointer
, essidbuf
, erq
->length
) )
6697 zd1205_ioctl_setfreq(struct net_device
*dev
, struct iw_freq
*frq
)
6699 struct zd1205_private
*macp
= dev
->priv
;
6701 int fflag
=0; //Found Flag
6708 if (macp->cardSetting.BssType == INFRASTRUCTURE_BSS )
6713 if (macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
||
6714 ( macp
->cardSetting
.BssType
== INDEPENDENT_BSS
&& macp
->cardSetting
.MacMode
== MIXED_MODE
) ||
6715 ( macp
->cardSetting
.BssType
== AP_BSS
&& macp
->cardSetting
.MacMode
== MIXED_MODE
) )
6722 if ( (frq
->e
== 0) && (frq
->m
<= 1000) ) {
6723 /* Setting by channel number */
6727 /* Setting by frequency - search the table */
6731 for (i
= 0; i
< (6 - frq
->e
); i
++)
6734 if(PURE_A_MODE
!= mMacMode
) {
6735 for (i
= 0; i
< NUM_CHANNELS
; i
++)
6736 if (frq
->m
== (channel_frequency
[i
] * mult
)) {
6743 for (i
= 0; i
< NUM_CHANNELS_11A
; i
++)
6744 if (frq
->m
== (channel_frequency_11A
[i
*2+1] * mult
)) {
6746 chan
= channel_frequency_11A
[i
*2];
6754 // if(PURE_A_MODE != mMacMode) {
6755 if(macp
->cardSetting
.MacMode
!= PURE_A_MODE
) {
6757 if ( (chan < 1) || (14 > chan) ) {
6759 printk("We Can't Found Required Channel in ioctl_setfreq(2.4G)\n");
6765 if ( (chan
< 1) || ( 14 < chan
) ) {
6766 printk("We Can't Found Required Channel in ioctl_setfreq(2.4G)\n");
6772 checkChan
= pass_channel_for_region(macp
,(U16
)chan
);
6773 if ( (int)checkChan
!= chan
)
6775 RegionStr
= get_curregion_str( macp
);
6776 printk("%s Region Can't Use %d Channel\n",RegionStr
,chan
);
6788 if ( (chan
< 1) || (0 == fflag
) )
6790 printk("We Can't Found Required Channel in ioctl_setfreq(5G)\n");
6794 if( 0 == channel_11A_to_Freq(chan
) )
6796 printk("The channel isn't exist(%d)\n",chan
);
6804 macp->cardSetting.Channel = chan;
6807 macp
->ModeChChannel
= chan
;
6809 macp
->IBSS_DesiredChannel
= chan
;
6810 zd1205_unlock(macp
);
6819 zd1205_ioctl_setrts(struct net_device
*dev
, struct iw_param
*rrq
)
6821 struct zd1205_private
*macp
= dev
->priv
;
6822 int val
= rrq
->value
;
6827 if ( (val
< 0) || (val
> 2347) )
6832 macp
->cardSetting
.RTSThreshold
= val
;
6834 macp
->cardSetting
.RTSThreshold
= 9999;
6836 zd1205_unlock(macp
);
6843 zd1205_ioctl_setfrag(struct net_device
*dev
, struct iw_param
*frq
)
6845 struct zd1205_private
*macp
= dev
->priv
;
6853 macp
->cardSetting
.FragThreshold
= 9999;
6857 #if ZDCONF_LP_SUPPORT == 1
6858 if(dot11Obj
.LP_MODE
)
6860 printk("You can't turn on fragment when lp_mode is on\n");
6861 printk("issue iwpriv ethX lp_mode 0 to turn it off\n");
6867 if ( (frq
->value
< 256) || (frq
->value
> 2346) )
6874 macp
->cardSetting
.FragThreshold
= frq
->value
& ~0x1;
6879 zd1205_unlock(macp
);
6884 zd1205_ioctl_getfrag(struct net_device
*dev
, struct iw_param
*frq
)
6886 struct zd1205_private
*macp
= dev
->priv
;
6891 val
= macp
->cardSetting
.FragThreshold
;
6893 frq
->disabled
= (val
>= 2346);
6895 zd1205_unlock(macp
);
6901 zd1205_ioctl_setrate(struct net_device
*dev
, struct iw_param
*frq
)
6907 zd1205_ioctl_getrate(struct net_device
*dev
, struct iw_param
*frq
)
6909 struct zd1205_private
*macp
= dev
->priv
;
6916 switch(macp
->cardSetting
.CurrTxRate
)
6919 frq
->value
= 1000000;
6924 frq
->value
= 2000000;
6928 frq
->value
= 5500000;
6932 frq
->value
= 11000000;
6936 frq
->value
= 6000000;
6940 frq
->value
= 9000000;
6944 frq
->value
= 12000000;
6948 frq
->value
= 18000000;
6952 frq
->value
= 24000000;
6956 frq
->value
= 36000000;
6960 frq
->value
= 48000000;
6964 frq
->value
= 54000000;
6975 zd1205_ioctl_settxpower(struct net_device
*dev
, struct iw_param
*prq
)
6977 struct zd1205_private
*macp
= dev
->priv
;
6980 #define TX_17dbm 0x00
6981 #define TX_14dbm 0x01
6982 #define TX_11dbm 0x02
6984 if(prq
->value
>= TX_17dbm
&& prq
->value
<= TX_11dbm
)
6985 macp
->cardSetting
.TxPowerLevel
= prq
->value
;
6993 zd1205_ioctl_gettxpower(struct net_device
*dev
, struct iw_param
*prq
)
6995 struct zd1205_private
*macp
= dev
->priv
;
6998 #define TX_17dbm 0x00
6999 #define TX_14dbm 0x01
7000 #define TX_11dbm 0x02
7006 switch(macp
->cardSetting
.TxPowerLevel
)
7028 zd1205_ioctl_setpower(struct net_device
*dev
, struct iw_param
*frq
)
7030 struct zd1205_private
*macp
= dev
->priv
;
7037 printk(KERN_ERR
"power save disabed\n");
7038 macp
->cardSetting
.ATIMWindow
= 0x0;
7039 macp
->bPSMSupported
= 0;
7040 macp
->PwrState
= PS_CAM
;
7041 zd_EventNotify(EVENT_PS_CHANGE
, (U8
)macp
->PwrState
, 0, 0);
7044 if(frq
->flags
!= IW_POWER_TIMEOUT
)
7046 printk("The PSM command syntax :\n");
7047 printk(" iwconfig ethX power timeout DATA_COUNTu \n");
7048 printk("When the data is less than DATA_COUNT, STA enters PowerSaving, else WakeUP\n");
7049 printk("Exampel : iwconfig eth1 power timeout 500000u\n");
7050 printk(" When traffic is less than 500k/s, Enter Power Saving\n");
7055 printk(KERN_ERR
"power save enabled\n");
7056 printk("The PSM Threshold is %dK %dBytes\n", frq
->value
/1024,frq
->value
%1024);
7057 macp
->PSThreshhold
= frq
->value
;
7058 macp
->cardSetting
.ATIMWindow
= 0x5;
7059 macp
->bPSMSupported
= 1;
7063 zd1205_unlock(macp
);
7064 printk("dot11Obj.BeaconInterval:%d,BEFORE_BEACON:%d\n",dot11Obj
.BeaconInterval
,BEFORE_BEACON
);
7066 HW_UpdatePreTBTT(&dot11Obj
, dot11Obj
.BeaconInterval
-BEFORE_BEACON
);
7072 zd1205_ioctl_getpower(struct net_device
*dev
, struct iw_param
*frq
)
7074 struct zd1205_private
*macp
= dev
->priv
;
7077 if (macp
->bPSMSupported
)
7081 zd1205_unlock(macp
);
7087 zd1205_hw_get_freq(struct zd1205_private
*macp
)
7091 if(PURE_A_MODE
!= mMacMode
)
7092 freq
= channel_frequency
[dot11Obj
.Channel
-1] * 100000;
7093 else if(PURE_A_MODE
== mMacMode
)
7094 //for PURE_A_MODE the Channel Number is not required to sub one.
7095 //Because the channel is get from setting not the order in array
7096 freq
= channel_11A_to_Freq(dot11Obj
.Channel
) * 100000;
7097 zd1205_unlock(macp
);
7102 static int zd1205_ioctl_setmode(struct net_device
*dev
, __u32
*mode
)
7105 struct zd1205_private
*macp
= dev
->priv
;
7109 ZD1211DEBUG(0, "Switch to Ad-Hoc mode\n");
7110 macp
->ModeChBssType
= INDEPENDENT_BSS
;
7114 ZD1211DEBUG(0, "Switch to Infra mode\n");
7115 macp
->ModeChBssType
= INFRASTRUCTURE_BSS
;
7119 case IW_MODE_MASTER
:
7120 ZD1211DEBUG(0, "Switch to AP mode\n");
7121 macp
->ModeChBssType
= AP_BSS
;
7124 ZD1211DEBUG(0, "Switch to PSEUDO_IBSS mode\n");
7125 macp
->ModeChBssType
= PSEUDO_IBSS
;
7132 struct zd1205_private *macp = dev->priv;
7133 static unsigned long setmodeLock = 0;
7135 //zd1205_lock(macp);
7137 if(test_and_set_bit(0, &setmodeLock))
7139 printk("change mode at the same time\n");
7144 ZD1211DEBUG(0, "Switch to Ad-Hoc mode\n");
7145 macp->cardSetting.BssType = INDEPENDENT_BSS;
7147 if (macp->bDefaultIbssMacMode==0)
7148 macp->cardSetting.MacMode=PURE_B_MODE;
7150 zd_writel(STA_RX_FILTER, Rx_Filter);
7154 ZD1211DEBUG(0, "Switch to Infra mode\n");
7155 macp->cardSetting.BssType = INFRASTRUCTURE_BSS;
7156 macp->cardSetting.AuthMode = 0;
7158 if (macp->bDefaultIbssMacMode==0)
7160 macp->cardSetting.MacMode=MIXED_MODE;
7163 zd_writel(STA_RX_FILTER, Rx_Filter);
7167 case IW_MODE_MASTER:
7168 ZD1211DEBUG(0, "Switch to AP mode\n");
7169 macp->cardSetting.BssType = AP_BSS;
7171 // Set bssid = MacAddress
7173 macp->BSSID[0] = macp->macAdr[0];
7174 macp->BSSID[1] = macp->macAdr[1];
7175 macp->BSSID[2] = macp->macAdr[2];
7177 macp->BSSID[3] = macp->macAdr[3];
7178 macp->BSSID[4] = macp->macAdr[4];
7179 macp->BSSID[5] = macp->macAdr[5];
7181 zd_writel(cpu_to_le32(*(u32 *)&macp->macAdr[0]), BSSID_P1);
7182 zd_writel(cpu_to_le32(*(u32 *)&macp->macAdr[4]), BSSID_P2);
7183 macp->cardSetting.AuthMode = 2; //auto auth
7184 zd_writel(AP_RX_FILTER, Rx_Filter);
7185 netif_start_queue(dev);
7189 ZD1211DEBUG(0, "Switch to PSEUDO_IBSS mode\n");
7190 macp->cardSetting.BssType = PSEUDO_IBSS;
7191 zd_writel(STA_RX_FILTER, Rx_Filter);
7197 if (macp->usb->speed != USB_SPEED_HIGH)
7198 macp->cardSetting.MacMode = PURE_B_MODE;
7201 if (macp->cardSetting.BssType == INDEPENDENT_BSS)
7202 macp->cardSetting.MacMode = PURE_B_MODE;
7204 macp->cardSetting.MacMode = MIXED_MODE;
7208 zd1205_SetRatesInfo(macp);
7210 //zd1205_unlock(macp);
7211 clear_bit(0, &setmodeLock);
7217 /////////////////////////
7220 zd1205_ioctl_getretry(struct net_device
*dev
, struct iw_param
*prq
)
7225 /* For WIRELESS_EXT > 12 */
7226 static int zd1205wext_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_freq
*freq
, char *extra
)
7228 struct zd1205_private
*macp
;
7229 if(!netif_running(dev
))
7233 freq
->m
= zd1205_hw_get_freq(macp
);
7238 static int zd1205wext_siwmode(struct net_device
*dev
, struct iw_request_info
*info
, __u32
*mode
, char *extra
)
7241 err
= zd1205_ioctl_setmode(dev
, mode
);
7246 static int zd1205wext_giwmode(struct net_device
*dev
, struct iw_request_info
*info
, __u32
*mode
, char *extra
)
7248 struct zd1205_private
*macp
= dev
->priv
;
7249 u8 BssType
= macp
->cardSetting
.BssType
;
7251 if(!netif_running(dev
))
7258 *mode
= IW_MODE_MASTER
;
7261 case INFRASTRUCTURE_BSS
:
7262 *mode
= IW_MODE_INFRA
;
7265 case INDEPENDENT_BSS
:
7266 *mode
= IW_MODE_ADHOC
;
7270 *mode
= IW_MODE_ADHOC
;
7274 zd1205_unlock(macp
);
7278 static int zd1205wext_giwrate(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rrq
, char *extra
)
7280 if(!netif_running(dev
))
7283 return zd1205_ioctl_getrate(dev
, rrq
);
7286 static int zd1205wext_giwrts(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rts
, char *extra
)
7288 struct zd1205_private
*macp
;
7291 if(!netif_running(dev
))
7294 rts
->value
= macp
->cardSetting
.RTSThreshold
;
7295 rts
->disabled
= (rts
->value
== 2347);
7301 static int zd1205wext_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*frag
, char *extra
)
7303 if(!netif_running(dev
))
7306 return zd1205_ioctl_getfrag(dev
, frag
);
7309 static int zd1205wext_giwtxpow(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rrq
, char *extra
)
7311 if(!netif_running(dev
))
7314 return zd1205_ioctl_gettxpower(dev
, rrq
);
7317 static int zd1205wext_siwtxpow(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_param
*rrq
, char *extra
)
7319 return zd1205_ioctl_settxpower(dev
, rrq
);
7322 static int zd1205wext_giwrange(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_point
*data
, char *extra
)
7324 struct iw_range
*range
= (struct iw_range
*) extra
;
7326 if(!netif_running(dev
))
7330 #if WIRELESS_EXT > 9
7331 range
->txpower_capa
= IW_TXPOW_DBM
;
7332 // XXX what about min/max_pmp, min/max_pmt, etc.
7335 #if WIRELESS_EXT > 10
7336 range
->we_version_compiled
= WIRELESS_EXT
;
7337 range
->we_version_source
= 13;
7338 range
->retry_capa
= IW_RETRY_LIMIT
;
7339 range
->retry_flags
= IW_RETRY_LIMIT
;
7340 range
->min_retry
= 0;
7341 range
->max_retry
= 255;
7343 #endif /* WIRELESS_EXT > 10 */
7347 /* XXX need to filter against the regulatory domain &| active set */
7349 if(PURE_A_MODE
!= mMacMode
) {
7350 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
7351 range
->freq
[val
].i
= i
+ 1;
7352 range
->freq
[val
].m
= channel_frequency
[i
] * 100000;
7353 range
->freq
[val
].e
= 1;
7357 else if(PURE_A_MODE
== mMacMode
) {
7358 for (i
= 0; i
< NUM_CHANNELS_11A
&& i
< 32; i
++) {
7359 range
->freq
[val
].i
= channel_frequency_11A
[i
*2];;
7360 range
->freq
[val
].m
= channel_frequency_11A
[i
*2+1] * 100000;
7361 range
->freq
[val
].e
= 1;
7363 //For 802.11a, there are too more frequency. We can't return them all
7369 range
->num_frequency
= val
;
7371 /* Max of /proc/net/wireless */
7372 range
->max_qual
.qual
= 100;
7373 range
->max_qual
.level
= 100;
7375 range
->max_qual
.noise
= 100;
7376 range
->sensitivity
= 3;
7378 // XXX these need to be nsd-specific!
7379 range
->min_rts
= 256;
7380 range
->max_rts
= 2346;
7382 range
->min_frag
= 256;
7383 range
->max_frag
= 2346;
7384 range
->max_encoding_tokens
= NUM_WEPKEYS
;
7385 range
->num_encoding_sizes
= 2;
7386 range
->encoding_size
[0] = 5;
7387 range
->encoding_size
[1] = 13;
7389 // XXX what about num_bitrates/throughput?
7390 range
->num_bitrates
= 0;
7392 /* estimated max throughput */
7393 // XXX need to cap it if we're running at ~2Mbps..
7394 range
->throughput
= 5500000;
7399 #if WIRELESS_EXT > 13
7400 static int zd1205wext_siwscan(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_point
*data
, char *extra
)
7404 //u32 ul_mac_ps_state;
7406 //BOOLEAN ProbeWithSsid_bak;
7407 struct zd1205_private
*macp
= g_dev
->priv
;
7410 if(!netif_running(dev
))
7415 // If the device is scanning when user issue site survey request, we use the result of it directly.
7416 if (dot11Obj
.bChScanning
)
7417 { // Use the result of driver-driven scan.
7418 while (dot11Obj
.bChScanning
)
7423 printk("Locked in waitting bChScanning for 5s. Exit!\n");
7424 dot11Obj
.bChScanning
=FALSE
;
7434 // Set Scanning flag firstly to prevent device from entering sleeping state again before complete of site survey.
7435 dot11Obj
.bChScanning
=1;
7436 while (dot11Obj
.bDeviceInSleep
)
7437 { // busy wait until the device is awaken.
7442 //***********************************************************************
7443 // Execute site survey request only bChScanning flag is FALSE.
7444 { // Execute user's site survey request.
7445 ProbeWithSsid_bak
=mProbeWithSsid
;
7446 mProbeWithSsid
=0; // Send Probe request with broadcast ssid.
7448 for (channel
=1; channel
<= 14; channel
++)
7450 zd_CmdScanReq(channel
);//Set RF channel then send ProbeRequest
7454 dot11Obj
.bChScanning
=0;
7455 mProbeWithSsid
=ProbeWithSsid_bak
;
7459 if(!dot11Obj
.bChScanning
) {
7461 dot11Obj
.ConfigFlag
|= JUST_CHANNEL_SCAN
;
7464 macp
->IBSS_DesiredMacMode
= macp
->cardSetting
.MacMode
;
7465 macp
->IBSS_DesiredChannel
= macp
->cardSetting
.Channel
;
7469 ;// This mean there is one just done scanning.
7471 while(dot11Obj
.bChScanning
) {
7472 if(wait_cnt
++ > 200) {
7475 printk(KERN_ERR
"UnStoppable Scanning\n");
7476 dot11Obj
.bChScanning
=0;
7482 zd1205_notify_scan_done(macp
);
7483 set_bit(CTX_FLAG_ESSID_WAS_SET
, (void *)&macp
->flags
);
7490 #if WIRELESS_EXT > 14
7492 * Encode a WPA or RSN information element as a custom
7493 * element using the hostap format.
7496 encode_ie(void *buf
, size_t bufsize
,
7497 const u_int8_t
*ie
, size_t ielen
,
7498 const char *leader
, size_t leader_len
)
7503 if (bufsize
< leader_len
)
7506 memcpy(p
, leader
, leader_len
);
7507 bufsize
-= leader_len
;
7509 for (i
= 0; i
< ielen
&& bufsize
> 2; i
++)
7510 p
+= sprintf(p
, "%02x", ie
[i
]);
7511 return (i
== ielen
? p
- (u8
*)buf
: 0);
7513 #endif /* WIRELESS_EXT > 14 */
7515 /*------------------------------------------------------------------*/
7517 * Translate scan data returned from the card to a card independent
7518 * format that the Wireless Tools will understand
7520 static char *zd1205_translate_scan(struct net_device
*dev
,
7525 struct iw_event iwe
; /* Temporary buffer */
7528 #if WIRELESS_EXT > 14
7529 char buf
[64*2 + 30];
7532 char *current_val
; /* For rates */
7536 /* First entry *MUST* be the AP MAC address */
7537 iwe
.cmd
= SIOCGIWAP
;
7538 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
7539 memcpy(iwe
.u
.ap_addr
.sa_data
, list
->bssid
, ETH_ALEN
);
7540 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
7542 /* Other entries will be displayed in the order we give them */
7545 iwe
.u
.data
.length
= list
->ssid
[1];
7546 if(iwe
.u
.data
.length
> 32)
7547 iwe
.u
.data
.length
= 32;
7548 iwe
.cmd
= SIOCGIWESSID
;
7549 iwe
.u
.data
.flags
= 1;
7550 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, &list
->ssid
[2]);
7553 iwe
.cmd
= SIOCGIWMODE
;
7554 capabilities
= list
->cap
;
7555 if(capabilities
& (0x01 | 0x02)) {
7556 if(capabilities
& 0x01)
7557 iwe
.u
.mode
= IW_MODE_MASTER
;
7560 iwe
.u
.mode
= IW_MODE_ADHOC
;
7561 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
7565 iwe
.cmd
= SIOCGIWFREQ
;
7566 iwe
.u
.freq
.m
= list
->channel
;
7567 if(list
->apMode
!= PURE_A_AP
)
7568 iwe
.u
.freq
.m
= channel_frequency
[iwe
.u
.freq
.m
-1] * 100000;
7570 iwe
.u
.freq
.m
= channel_11A_to_Freq(iwe
.u
.freq
.m
) * 100000;
7573 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
7575 #if WIRELESS_EXT < 15
7576 /* Add quality statistics */
7579 #if WIRELESS_EXT > 18
7580 iwe
.u
.qual
.updated
= IW_QUAL_QUAL_UPDATED
| IW_QUAL_LEVEL_UPDATED
7581 |IW_QUAL_NOISE_UPDATED
;
7583 Tmp
= -(100 - list
->signalStrength
);
7584 Tmp
= Tmp
> -40 ? -40: Tmp
;
7585 Tmp
= Tmp
< -105 ? -105: Tmp
;
7586 Tmp
= (Tmp
+ 105)*100/65;
7587 iwe
.u
.qual
.level
= Tmp
;
7588 iwe
.u
.qual
.noise
= 0;
7589 iwe
.u
.qual
.qual
= list
->signalQuality
;
7590 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
7592 // Transform Signal quality from level to percentage
7593 memset(&iwe
, 0, sizeof(iwe
));
7594 iwe
.cmd
= IWEVCUSTOM
;
7595 Tmp
= -(100 - list
->signalStrength
);
7596 Tmp
= Tmp
> -40 ? -40: Tmp
;
7597 Tmp
= Tmp
< -105 ? -105: Tmp
;
7598 Tmp
= (Tmp
+ 105)*100/65;
7600 snprintf(buf
, sizeof(buf
), "SignalStrength=%lu %%,LinkQuality:%u%%", Tmp
,list
->signalQuality
);
7601 iwe
.u
.data
.length
= strlen(buf
);
7602 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, buf
);
7604 #if ZDCONF_SES_SUPPORT == 1
7605 if(list
->SES_Element_Valid
)
7607 memset(&iwe
, 0, sizeof(iwe
));
7608 iwe
.cmd
= IWEVCUSTOM
;
7609 sprintf(buf
, "%s","SES:0x");
7610 for(i
=0;i
<list
->SES_Element
.buf
[1]-3;i
++)
7612 if(6+i
*2+1 > sizeof(buf
)) //SES:0x + Will_Copied + 0x0
7614 printk("Out of Buffer \n");
7617 sprintf(buf
+6+i
*2,"%02x",list
->SES_Element
.buf
[5+i
]);
7619 iwe
.u
.data
.length
= strlen(buf
);
7620 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, buf
);
7625 /* Add encryption capability */
7627 iwe
.cmd
= SIOCGIWENCODE
;
7628 if(capabilities
& 0x10)
7629 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
7631 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
7632 iwe
.u
.data
.length
= 0;
7633 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, list
->ssid
);
7635 /* Rate : stuffing multiple values in a single event require a bit
7637 current_val
= current_ev
+ IW_EV_LCP_LEN
;
7640 iwe
.cmd
= SIOCGIWRATE
;
7643 /* Those two flags are ignored... */
7644 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
7646 for(i
= 0 ; i
< list
->supRates
[1] ; i
++) {
7647 /* Bit rate given in 500 kb/s units (+ 0x80) */
7648 iwe
.u
.bitrate
.value
= ((list
->supRates
[i
+2] & 0x7f) * 500000);
7649 /* Add new value to event */
7650 current_val
= iwe_stream_add_value(current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
7653 if (list
->apMode
!= PURE_B_AP
){
7654 for (i
= 0 ; i
< list
->extRates
[1] ; i
++) {
7655 /* Bit rate given in 500 kb/s units (+ 0x80) */
7656 iwe
.u
.bitrate
.value
= ((list
->extRates
[i
+2] & 0x7f) * 500000);
7657 /* Add new value to event */
7658 current_val
= iwe_stream_add_value(current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
7662 /* Check if we added any event */
7663 if((current_val
- current_ev
) > IW_EV_LCP_LEN
)
7664 current_ev
= current_val
;
7666 #if WIRELESS_EXT > 14
7668 #define IEEE80211_ELEMID_RSN 0x30
7670 memset(&iwe
, 0, sizeof(iwe
));
7671 iwe
.cmd
= IWEVCUSTOM
;
7672 snprintf(buf
, sizeof(buf
), "bcn_int=%d", list
->beaconInterval
);
7673 iwe
.u
.data
.length
= strlen(buf
);
7674 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, buf
);
7676 if (list
->WPAIe
[1] != 0) {
7677 static const char rsn_leader
[] = "rsn_ie=";
7678 static const char wpa_leader
[] = "wpa_ie=";
7680 memset(&iwe
, 0, sizeof(iwe
));
7681 iwe
.cmd
= IWEVCUSTOM
;
7682 if (list
->WPAIe
[0] == IEEE80211_ELEMID_RSN
)
7683 iwe
.u
.data
.length
= encode_ie(buf
, sizeof(buf
),
7684 list
->WPAIe
, list
->WPAIe
[1]+2,
7685 rsn_leader
, sizeof(rsn_leader
)-1);
7687 iwe
.u
.data
.length
= encode_ie(buf
, sizeof(buf
),
7688 list
->WPAIe
, list
->WPAIe
[1]+2,
7689 wpa_leader
, sizeof(wpa_leader
)-1);
7690 if (iwe
.u
.data
.length
!= 0)
7691 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
7694 if (list
->RSNIe
[1] != 0)
7696 static const char rsn_leader
[] = "rsn_ie=";
7697 memset(&iwe
, 0, sizeof(iwe
));
7698 iwe
.cmd
= IWEVCUSTOM
;
7699 if (list
->RSNIe
[0] == IEEE80211_ELEMID_RSN
)
7701 iwe
.u
.data
.length
= encode_ie(buf
, sizeof(buf
),
7702 list
->RSNIe
, list
->RSNIe
[1]+2,
7703 rsn_leader
, sizeof(rsn_leader
)-1);
7704 if (iwe
.u
.data
.length
!= 0)
7705 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, buf
);
7709 #endif /* WIRELESS_EXT > 14 */
7711 /* The other data in the scan result are not really
7712 * interesting, so for now drop it */
7717 static int zd1205wext_giwscan(struct net_device
*dev
, struct iw_request_info
*info
, struct iw_point
*data
, char *extra
)
7719 struct zd1205_private
*macp
= dev
->priv
;
7720 char *current_ev
= extra
;
7722 static int loop
= 0;
7724 if(!netif_running(dev
))
7730 macp
->bss_index
= zd_GetBssList(&macp
->BSSInfo
[0]);
7731 //ZD1211DEBUG(0, "macp->bss_index = %x\n", macp->bss_index);
7733 /* Read and parse all entries */
7735 for (i
=0; i
<macp
->bss_index
; i
++) {
7736 /* Translate to WE format this entry */
7737 //When there exists too many APs. APs in tail of bss info
7738 //array aren't shown. Because the scan result stores only
7739 //4k byte most. So, we show from head/tail alternately.
7742 current_ev
= zd1205_translate_scan(dev
, current_ev
,
7743 extra
+ IW_SCAN_MAX_DATA
,
7748 current_ev
= zd1205_translate_scan(dev
, current_ev
,
7749 extra
+ IW_SCAN_MAX_DATA
,
7750 &macp
->BSSInfo
[macp
->bss_index
-1-i
]);
7752 if(current_ev
- extra
> IW_SCAN_MAX_DATA
* 9 / 10)
7754 printk("Warning! The scanning result almost exceed the maximum\n");
7755 printk(" available.\n");
7757 else if(current_ev
- extra
> IW_SCAN_MAX_DATA
)
7760 printk("Scanning result over the maximum abort\n");
7766 /* Length of data */
7767 data
->length
= (current_ev
- extra
);
7768 data
->flags
= 0; /* todo */
7770 if(!dot11Obj
.bChScanning
) {
7773 macp
->cardSetting
.MacMode
= macp
->IBSS_DesiredMacMode
;
7774 macp
->cardSetting
.Channel
= macp
->IBSS_DesiredChannel
;
7785 void zd1205_dumpEEPROM(struct zd1205_private
*macp
) {
7787 u8 int54
,int36
,cal54
,cal36
;
7789 if(AL7230B_RF
== dot11Obj
.rfMode
) {
7790 printk("802.11a Integration & SetPoint Values:\n");
7791 printk("-----------------------------------------\n");
7794 for(i
=0;i
<dot11A_Channel_Amount
&& AL7230B_RF
== dot11Obj
.rfMode
;i
++) {
7795 ret
= a_OSC_get_cal_int(dot11A_Channel
[i
], RATE_36M
, &int36
, &cal36
);
7797 printk("Channel %d doesn't exist in zd1205_dumpEEPROM\n",i
);
7799 ret
= a_OSC_get_cal_int(dot11A_Channel
[i
], RATE_54M
, &int54
, &cal54
);
7801 printk("Channel:%3d Int:%x Set36:%x Set54:%x\n",
7802 dot11A_Channel
[i
],int36
,cal36
,cal54
);
7805 printk("\n802.11b/g Integration & SetPoint Values:\n");
7806 printk("-----------------------------------------\n");
7808 for(i
=1;i
<=14;i
++) {
7809 printk("Channel:%3d Int:%x Set11:%x Set36:%x Set48:%x Set54:%x\n",
7811 dot11Obj
.IntValue
[i
-1],
7812 macp
->EepSetPoint
[i
-1],
7813 macp
->SetPointOFDM
[0][i
-1],
7814 macp
->SetPointOFDM
[1][i
-1],macp
->SetPointOFDM
[2][i
-1]);
7820 void zd1205_list_bss(struct zd1205_private
*macp
)
7824 bss_info_t
*pBssInfo
;
7826 printk("\nSSID BSSID CH Signal Mode AP-Type Other");
7827 printk("\n-----------------------------------------------------------------");
7829 for (i
=0; i
<macp
->bss_index
; i
++)
7831 pBssInfo
= &macp
->BSSInfo
[i
];
7835 for (j
=0; j
<pBssInfo
->ssid
[1]; j
++)
7837 printk("%c", pBssInfo
->ssid
[2+j
]);
7842 printk("%02x%02x%02x%02x%02x%02x",
7843 pBssInfo
->bssid
[0], pBssInfo
->bssid
[1], pBssInfo
->bssid
[2],
7844 pBssInfo
->bssid
[3], pBssInfo
->bssid
[4], pBssInfo
->bssid
[5]);
7846 printk(" %4d", pBssInfo
->channel
);
7847 printk(" %4d", pBssInfo
->signalStrength
);
7850 cap
= pBssInfo
->cap
;
7851 cap
&= (0x10 | 0x02 | 0x01);
7878 for (j=0; j<pBssInfo->supRates[1]; j++)
7880 printk("%2d", (pBssInfo->supRates[2+j] & 0x7F)*5/10);
7881 if(j != pBssInfo->supRates[1]-1)
7886 for (j=0; j<pBssInfo->extRates[1]; j++)
7888 printk("%2d", (pBssInfo->extRates[2+j] & 0x7F)*5/10);
7889 if(j != pBssInfo->extRates[1]-1)
7894 if (pBssInfo
->apMode
== PURE_B_AP
)
7896 else if (pBssInfo
->apMode
== PURE_G_AP
)
7898 else if (pBssInfo
->apMode
== MIXED_AP
)
7900 else if (pBssInfo
->apMode
== PURE_A_AP
)
7903 {VerAssert("NULL");}
7904 #if ZDCONF_LP_SUPPORT == 1
7905 if(pBssInfo
->zdIE_Info_BURST
[0] == EID_ZYDAS
)
7907 if(pBssInfo
->zdIE_Info_BURST
[2] == (U8
)ZDOUI_BURST
&&
7908 pBssInfo
->zdIE_Info_BURST
[3] == (U8
)(ZDOUI_BURST
>> 8) &&
7909 pBssInfo
->zdIE_Info_BURST
[4] == (U8
)(ZDOUI_BURST
>> 16))
7912 if(pBssInfo
->zdIE_Info_BURST
[8] & BIT_7
)
7913 printk(" BurstOn(0x%02x)", pBssInfo
->zdIE_Info_BURST
[8] & 0x7F);
7915 printk(" BurstOff ");
7919 if(pBssInfo
->zdIE_Info_AMSDU
[0] == EID_ZYDAS
)
7921 if(pBssInfo
->zdIE_Info_AMSDU
[2] == (U8
)ZDOUI_AMSDU
&&
7922 pBssInfo
->zdIE_Info_AMSDU
[3] == (U8
)(ZDOUI_AMSDU
>> 8) &&
7923 pBssInfo
->zdIE_Info_AMSDU
[4] == (U8
)(ZDOUI_AMSDU
>> 16))
7926 if(pBssInfo
->zdIE_Info_AMSDU
[8] & BIT_0
)
7927 printk(" AMSDU_On(%d)", pBssInfo
->zdIE_Info_AMSDU
[8] & BIT_1
);
7929 printk(" AMSDU_Off");
7933 #if ZDCONF_SES_SUPPORT == 1
7934 if(pBssInfo
->SES_Element_Valid
)
7936 printk(" SES(%d)", pBssInfo
->SES_Element
.buf
[1]);
7945 /////////////////////////////////////////
7947 zd1205_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
7949 struct zd1205_private
*macp
;
7951 struct zdap_ioctl zdreq
;
7952 struct iwreq
*wrq
= (struct iwreq
*)ifr
;
7959 if(!netif_running(dev
))
7961 down(&macp
->ioctl_sem
);
7965 ZD1211DEBUG(1, "%s: SIOCGIWNAME\n", dev
->name
);
7966 //strcpy(wrq->u.name, "IEEE 802.11-DS");
7967 strcpy(wrq
->u
.name
, "802.11b/g NIC");
7971 ZD1211DEBUG(1, "%s: SIOCGIWAP\n", dev
->name
);
7972 wrq
->u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
7974 if (macp
->cardSetting
.BssType
== AP_BSS
)
7975 memcpy(wrq
->u
.ap_addr
.sa_data
, macp
->macAdr
, 6);
7978 memcpy(wrq
->u
.ap_addr
.sa_data
, macp
->BSSID
, 6);
7980 memset(wrq
->u
.ap_addr
.sa_data
, 0, 6);
7985 ZD1211DEBUG(1, "%s: SIOCGIWRANGE\n", dev
->name
);
7986 if ( wrq
->u
.data
.pointer
!= NULL
) {
7987 struct iw_range range
;
7988 err
= zd1205wext_giwrange(dev
, NULL
, &wrq
->u
.data
, (char *) &range
);
7990 /* Push that up to the caller */
7991 if (copy_to_user(wrq
->u
.data
.pointer
, &range
, sizeof(range
)))
7997 ZD1211DEBUG(1, "%s: SIOCSIWMODE\n", dev
->name
);
7998 err
= zd1205wext_siwmode(dev
, NULL
, &wrq
->u
.mode
, NULL
);
8007 if ((!err
) && changed
) {
8009 defer_kevent(macp
, KEVENT_DIS_UPDATE_SETTING
);
8011 zd1205_dis_update_setting( macp
);
8016 up(&macp
->ioctl_sem
);
8021 ZD1211DEBUG(1, "%s: SIOCGIWMODE\n", dev
->name
);
8022 err
= zd1205wext_giwmode(dev
, NULL
, &wrq
->u
.mode
, NULL
);
8027 char keybuf
[MAX_KEY_SIZE
];
8028 ZD1211DEBUG(1, "%s: SIOCSIWENCODE\n", dev
->name
);
8030 if (wrq
->u
.encoding
.pointer
){
8031 if (wrq
->u
.encoding
.length
> MAX_KEY_SIZE
){
8036 if (copy_from_user(keybuf
, wrq
->u
.encoding
.pointer
, wrq
->u
.encoding
.length
)) {
8042 zd1205_dump_data("keybuf", keybuf
, wrq
->u
.encoding
.length
);
8043 err
= zd1205_ioctl_setiwencode(dev
, &wrq
->u
.encoding
, keybuf
);
8052 char keybuf
[MAX_KEY_SIZE
];
8054 ZD1211DEBUG(1, "%s: SIOCGIWENCODE\n", dev
->name
);
8055 err
= zd1205_ioctl_getiwencode(dev
, &wrq
->u
.encoding
, keybuf
);
8057 if (wrq
->u
.encoding
.pointer
){
8058 if (copy_to_user(wrq
->u
.encoding
.pointer
, keybuf
, wrq
->u
.encoding
.length
))
8065 ZD1211DEBUG(1, "%s: SIOCSIWESSID\n", dev
->name
);
8066 err
= zd1205_ioctl_setessid(dev
, &wrq
->u
.essid
);
8067 if (!err
&& macp
->cardSetting
.ap_scan
!= 1)
8073 if ((!err
) && changed
) {
8075 defer_kevent(macp
, KEVENT_DIS_UPDATE_SETTING
);
8077 zd1205_dis_update_setting( macp
);
8081 up(&macp
->ioctl_sem
);
8085 ZD1211DEBUG(1, "%s: SIOCSIWAP\n", dev
->name
);
8086 err
= zd1205_ioctl_setbssid(dev
, wrq
);
8087 if (!err
&& macp
->cardSetting
.ap_scan
== 1)
8089 //set_bit(CTX_FLAG_ESSID_WAS_SET,(void*)&macp->flags);
8096 ZD1211DEBUG(1, "%s: SIOCGIWESSID\n", dev
->name
);
8097 err
= zd1205_ioctl_getessid(dev
, &wrq
->u
.essid
);
8101 ZD1211DEBUG(1, "%s: SIOCGIWFREQ\n", dev
->name
);
8102 wrq
->u
.freq
.m
= zd1205_hw_get_freq(macp
);
8107 ZD1211DEBUG(1, "%s: SIOCSIWFREQ\n", dev
->name
);
8109 err
= zd1205_ioctl_setfreq(dev
, &wrq
->u
.freq
);
8112 //===prince add begin
8116 defer_kevent(macp
, KEVENT_DIS_UPDATE_SETTING
);
8118 zd1205_dis_update_setting(macp
);
8122 up(&macp
->ioctl_sem
);
8129 ZD1211DEBUG(1, "%s: SIOCGIWRTS\n", dev
->name
);
8130 zd1205wext_giwrts(dev
, NULL
, &wrq
->u
.rts
, NULL
);
8134 ZD1211DEBUG(1, "%s: SIOCSIWRTS\n", dev
->name
);
8137 err
= zd1205_ioctl_setrts(dev
, &wrq
->u
.rts
);
8143 ZD1211DEBUG(1, "%s: SIOCSIWFRAG\n", dev
->name
);
8145 err
= zd1205_ioctl_setfrag(dev
, &wrq
->u
.frag
);
8151 ZD1211DEBUG(1, "%s: SIOCGIWFRAG\n", dev
->name
);
8152 err
= zd1205_ioctl_getfrag(dev
, &wrq
->u
.frag
);
8156 ZD1211DEBUG(1, "%s: SIOCSIWRATE\n", dev
->name
);
8158 err
= zd1205_ioctl_setrate(dev
, &wrq
->u
.bitrate
);
8165 ZD1211DEBUG(1, "%s: SIOCGIWRATE\n", dev
->name
);
8166 err
= zd1205_ioctl_getrate(dev
, &wrq
->u
.bitrate
);
8170 ZD1211DEBUG(1, "%s: SIOCSIWPOWER\n", dev
->name
);
8172 err
= zd1205_ioctl_setpower(dev
, &wrq
->u
.power
);
8179 ZD1211DEBUG(1, "%s: SIOCGIWPOWER\n", dev
->name
);
8180 err
= zd1205_ioctl_getpower(dev
, &wrq
->u
.power
);
8183 #if WIRELESS_EXT > 10
8185 ZD1211DEBUG(1, "%s: SIOCSIWRETRY\n", dev
->name
);
8191 ZD1211DEBUG(1, "%s: SIOCGIWRETRY\n", dev
->name
);
8192 err
= zd1205_ioctl_getretry(dev
, &wrq
->u
.retry
);
8194 #endif /* WIRELESS_EXT > 10 */
8196 if (wrq
->u
.data
.pointer
) {
8197 //here update for iwpriv prince 2006-09-14
8198 struct iw_priv_args privtab
[] = {
8199 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "list_bss" },
8200 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
8201 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_auth" }, /* 0 - open, 1 - shared key */
8202 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_CHAR
| 12, "get_auth" },
8203 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_preamble" }, /* 0 - long, 1 - short */
8204 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_CHAR
| 6, "get_preamble" },
8205 { SIOCIWFIRSTPRIV
+ 0x6, 0, 0, "cnt" },
8206 { SIOCIWFIRSTPRIV
+ 0x7, 0, 0, "regs" },
8207 { SIOCIWFIRSTPRIV
+ 0x8, 0, 0, "probe" },
8208 { SIOCIWFIRSTPRIV
+ 0x9,IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_Region" },
8209 { SIOCIWFIRSTPRIV
+ 0xA, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "connect" },
8211 { SIOCIWFIRSTPRIV + 0xF , IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "lp_mode" },
8213 { SIOCIWFIRSTPRIV
+ 0xB, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, 0, "set_mac_mode" },
8214 { SIOCIWFIRSTPRIV
+ 0xC, 0, IW_PRIV_TYPE_CHAR
| 12, "get_mac_mode" },
8215 { SIOCIWFIRSTPRIV
+ 0xD, 0, 0, "set_moxa_repeat" },
8216 { SIOCIWFIRSTPRIV
+ 0xE, 0, IW_PRIV_TYPE_CHAR
| 14, "get_Region" },
8217 // { SIOCIWFIRSTPRIV + 0x9, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dbg_flag" },
8218 // { SIOCIWFIRSTPRIV + 0xD, 0, 0, "save_conf" },
8221 err
= access_ok(VERIFY_WRITE
, wrq
->u
.data
.pointer
, sizeof(privtab
));
8225 wrq
->u
.data
.length
= sizeof(privtab
) / sizeof(privtab
[0]);
8226 if (copy_to_user(wrq
->u
.data
.pointer
, privtab
, sizeof(privtab
)))
8231 case SIOCIWFIRSTPRIV
+ 0x0: /* list_bss */
8232 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x0 (list_bss)\n", dev
->name
);
8233 macp
->bss_index
= zd_GetBssList(&macp
->BSSInfo
[0]);
8234 zd1205_list_bss(macp
);
8237 case SIOCIWFIRSTPRIV
+ 0x1: /* card_reset */
8238 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x1 (card_reset)\n", dev
->name
);
8239 if (! capable(CAP_NET_ADMIN
)) {
8244 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
8246 zd1205_device_reset(macp
);
8247 zd1205_unlock(macp
);
8251 case SIOCIWFIRSTPRIV
+ 0x2: /* set_auth */
8252 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x2 (set_auth)\n", dev
->name
);
8253 if (! capable(CAP_NET_ADMIN
)) {
8258 int val
= *( (int *) wrq
->u
.name
);
8259 if ((val
< 0) || (val
> 1)){
8265 macp
->cardSetting
.AuthMode
= val
;
8266 zd1205_unlock(macp
);
8273 case SIOCIWFIRSTPRIV
+ 0x3: /* get_auth */
8274 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x3 (get_auth)\n", dev
->name
);
8276 if (wrq
->u
.data
.pointer
){
8277 wrq
->u
.data
.flags
= 1;
8279 if (macp
->cardSetting
.AuthMode
== 0) {
8280 wrq
->u
.data
.length
= 12;
8282 if (copy_to_user(wrq
->u
.data
.pointer
, "open system", 12)){
8286 else if (macp
->cardSetting
.AuthMode
== 1){
8287 wrq
->u
.data
.length
= 11;
8289 if (copy_to_user(wrq
->u
.data
.pointer
, "shared key", 11)){
8293 else if (macp
->cardSetting
.AuthMode
== 2){
8294 wrq
->u
.data
.length
= 10;
8296 if (copy_to_user(wrq
->u
.data
.pointer
, "auto mode", 10)){
8306 case SIOCIWFIRSTPRIV
+ 0x4: /* set_preamble */
8307 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x4 (set_preamble)\n", dev
->name
);
8309 if (! capable(CAP_NET_ADMIN
)) {
8314 int val
= *( (int *) wrq
->u
.name
);
8316 if ((val
< 0) || (val
> 1)){
8324 macp
->cardSetting
.PreambleType
= 1;
8326 macp
->cardSetting
.PreambleType
= 0;
8328 zd1205_unlock(macp
);
8336 case SIOCIWFIRSTPRIV
+ 0x5: /* get_preamble */
8337 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x5 (get_preamble)\n", dev
->name
);
8339 if (wrq
->u
.data
.pointer
){
8340 wrq
->u
.data
.flags
= 1;
8342 if (macp
->cardSetting
.PreambleType
){
8343 wrq
->u
.data
.length
= 6;
8345 if (copy_to_user(wrq
->u
.data
.pointer
, "short", 6)){
8350 wrq
->u
.data
.length
= 5;
8352 if (copy_to_user(wrq
->u
.data
.pointer
, "long", 5)){
8358 case SIOCIWFIRSTPRIV
+ 0x6: // dump_cnt
8359 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x6 (dump_cnt)\n", dev
->name
);
8360 zd1205_dump_cnters(macp
);
8362 case SIOCIWFIRSTPRIV
+ 0x7: /* dump_reg */
8363 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x7 (dump_reg)\n", dev
->name
);
8364 zd1205_dump_regs(macp
);
8367 case SIOCIWFIRSTPRIV
+ 0x8: /* probe */
8368 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x8 (probe)\n", dev
->name
);
8369 zd_CmdProcess(CMD_PROBE_REQ
, 0, 0);
8372 // case SIOCIWFIRSTPRIV + 0x9: /* set_dbgflag */
8373 // ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x9 (set_dbgflag)\n", dev->name);
8375 // if (! capable(CAP_NET_ADMIN)) {
8380 // int val = *( (int *) wrq->u.name );
8382 // if ((val < 0) || (val > 5)){
8387 // zd1205_lock(macp);
8388 // macp->dbg_flag = val;
8389 // zd1205_unlock(macp);
8396 case SIOCIWFIRSTPRIV
+ 0xA: // connect
8397 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0xA (connect)\n", dev
->name
);
8399 if (! capable(CAP_NET_ADMIN
)) {
8404 int val
= *( (int *) wrq
->u
.name
);
8406 if ((val
< 1) || (val
>macp
->bss_index
)){
8412 U8 bssTypeToConnect
;
8414 u8 ChangeToMacMode
=MIXED_MODE
;
8415 capabilities
= macp
->BSSInfo
[val
-1].cap
;
8416 //If you connect to non-A AP while in 5G Band, or
8417 //you connect to A AP while in 2.4G, you need to
8418 //do mac_mode change first
8419 if((PURE_A_AP
== macp
->BSSInfo
[val
-1].apMode
&&
8420 PURE_A_MODE
!= mMacMode
) ||
8421 (PURE_A_AP
!= macp
->BSSInfo
[val
-1].apMode
&&
8422 PURE_A_MODE
== mMacMode
) )
8424 if(PURE_A_AP
== macp
->BSSInfo
[val
-1].apMode
)
8425 ChangeToMacMode
= PURE_A_MODE
;
8427 printk("Changed macmode in connect\n");
8428 macp
->cardSetting
.Channel
= 8;//Default Channel to 8
8429 macp
->cardSetting
.MacMode
= ChangeToMacMode
;
8430 macp
->bDefaultIbssMacMode
=1;
8431 //set_mac_mode command has been issued by the user.
8432 zd1205_SetRatesInfo(macp
);
8434 zd_UpdateCardSetting(&macp
->cardSetting
);
8436 if (capabilities
& (CAP_IBSS
| CAP_ESS
)) {
8438 memcpy((U8
*)&mSsid
,(U8
*)macp
->BSSInfo
[val
-1].ssid
,34);
8439 memcpy((U8
*)&dot11DesiredSsid
, &mSsid
, 34);
8440 macp
->BSSInfo
[val
-1].ssid
[mSsid
.buf
[1]+2]=0;
8441 mProbeWithSsid
=TRUE
;
8442 if (capabilities
& CAP_IBSS
) {
8443 if (macp
->bDefaultIbssMacMode
==0)
8444 mMacMode
=macp
->cardSetting
.MacMode
=PURE_B_MODE
;
8445 bssTypeToConnect
=INDEPENDENT_BSS
;
8448 if (macp
->bDefaultIbssMacMode
==0)
8449 mMacMode
=macp
->cardSetting
.MacMode
=MIXED_MODE
;
8450 bssTypeToConnect
=INFRASTRUCTURE_BSS
;
8452 mBssType
=macp
->cardSetting
.BssType
=bssTypeToConnect
;
8453 zd_CmdProcess(CMD_CONNECT
, &bssTypeToConnect
, val
);
8454 zd1205_unlock(macp
);
8461 #if ZDCONF_LP_SUPPORT == 1
8462 case SIOCIWFIRSTPRIV
+ 0xF: //LP_MODE
8464 int val
= *((int *)wrq
->u
.name
);
8466 dot11Obj
.BURST_MODE
= 0;
8467 printk("Burst is set 0\n");
8470 dot11Obj
.BURST_MODE
= 1;
8471 printk("Burst is set 1\n");
8477 else if (val
== 2) {
8478 printk("Current LP Mode = %d\n", dot11Obj
.LP_MODE
);
8481 if(macp
->cardSetting
.FragThreshold
< 4000)
8483 printk("You can't turn on LP_Mode when fragment is on\n");
8484 printk("issue iwconfig ethX frag off to turn it off\n");
8488 dot11Obj
.LP_MODE
= 1;
8489 mod_timer(&(macp
->tm_lp_poll_id
), jiffies
+ (1*HZ
)/100);
8490 zd1205_unlock(macp
);
8491 printk("LP_MODE set 1\n");
8495 dot11Obj
.LP_MODE
= 0;
8496 del_timer_sync(&macp
->tm_lp_poll_id
);
8497 printk("LP_MODE set 0\n");
8505 case SIOCIWFIRSTPRIV
+ 0xB: /* set_mac_mode */
8506 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0xB (set_mac_mode)\n", dev
->name
);
8508 if (! capable(CAP_NET_ADMIN
)) {
8513 int val
= *( (int *) wrq
->u
.name
);
8516 if(AL7230B_RF
== dot11Obj
.rfMode
)
8517 mac_mode_limit
= 4; //4 = A,B,G
8518 else if (AL2230_RF
== dot11Obj
.rfMode
)
8519 mac_mode_limit
= 3; //3 = B,G
8520 else if (AL2230S_RF
== dot11Obj
.rfMode
)
8523 printk("Unknown RF Module. You are not allowed to set mac mode\n");
8527 if ((val
< 1) || (val
> mac_mode_limit
)){
8528 printk("Max MacMode is 4 !\n");
8530 /*==prince add begin
8531 goto set_mac_mode_err;
8537 /*====prince delete begin
8538 //If Band changed from 2.4G <-> 5G, we need
8539 //to set default channel
8540 if( (macp->cardSetting.MacMode != PURE_A_MODE &&
8541 val == PURE_A_MODE))
8543 macp->cardSetting.Channel = 36;
8545 else if(macp->cardSetting.MacMode == PURE_A_MODE &&
8546 val != PURE_A_MODE) {
8547 macp->cardSetting.Channel = 1;
8549 macp->IBSS_DesiredMacMode = val;
8550 macp->IBSS_DesiredChannel = macp->cardSetting.Channel;
8551 macp->cardSetting.MacMode = val;
8552 macp->bDefaultIbssMacMode=1;// Indicates that the set_mac_mode command has been issued by the user.
8553 zd1205_SetRatesInfo(macp);
8556 prince delete end===*/
8558 //====prince add begin
8559 if ( macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
)
8561 printk("Managed mode cannot support change macmode!\n");
8562 goto set_mac_mode_err
;
8565 if ( macp
->cardSetting
.BssType
== AP_BSS
||
8566 macp
->cardSetting
.BssType
== INDEPENDENT_BSS
)
8568 if ( val
== MIXED_MODE
)
8570 printk("Master/ad-hoc mode cannot support change to Mixed macmode!\n");
8571 goto set_mac_mode_err
;
8575 //If Band changed from 2.4G <-> 5G, we need
8576 //to set default channel
8577 macp
->ModeChMacMode
= val
;
8581 if ((!err
) && changed
) {
8583 defer_kevent(macp
, KEVENT_DIS_UPDATE_SETTING
);
8585 zd1205_dis_update_setting(macp
);
8589 up(&macp
->ioctl_sem
);
8596 /*=prince delete begin
8598 prince delete end==*/
8600 //===prince add begin
8602 up(&macp
->ioctl_sem
);
8604 //====prince add end
8606 case SIOCIWFIRSTPRIV
+ 0xC: /* get_mac_mode */
8607 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0xC (get_mac_mode)\n", dev
->name
);
8611 if (wrq
->u
.data
.pointer
){
8612 wrq
->u
.data
.flags
= 1;
8614 if (macp
->cardSetting
.MacMode
== MIXED_MODE
){
8615 wrq
->u
.data
.length
= 11;
8617 if (copy_to_user(wrq->u.data.pointer, "Mixed Mode", 11)){
8620 ==================*/
8622 memcpy(wrq
->u
.data
.pointer
, "Mixed Mode", 11);
8626 else if (macp
->cardSetting
.MacMode
== PURE_G_MODE
){
8627 wrq
->u
.data
.length
= 12;
8629 if (copy_to_user(wrq->u.data.pointer, "Pure G Mode", 12)){
8632 ===================*/
8634 memcpy(wrq
->u
.data
.pointer
, "Pure G Mode", 12);
8638 else if (macp
->cardSetting
.MacMode
== PURE_B_MODE
){
8639 wrq
->u
.data
.length
= 12;
8641 if (copy_to_user(wrq->u.data.pointer, "Pure B Mode", 12)){
8646 memcpy(wrq
->u
.data
.pointer
, "Pure B Mode", 12);
8650 else if (macp
->cardSetting
.MacMode
== PURE_A_MODE
) {
8651 wrq
->u
.data
.length
= 12;
8653 if (copy_to_user(wrq->u.data.pointer, "Pure A Mode", 12)){
8658 memcpy(wrq
->u
.data
.pointer
, "Pure A Mode", 12);
8667 case SIOCIWFIRSTPRIV + 0xD: // save_conf
8668 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0xD (save_conf)\n", dev->name);
8669 zd1205_save_card_setting(macp);
8671 case SIOCIWFIRSTPRIV + 0x06: // load_conf
8672 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x06 (load_conf)\n", dev->name);
8673 zd1205_load_card_setting(macp, 0);
8676 //Here update for iwpriv 20060914 prince
8677 case SIOCIWFIRSTPRIV
+ 0xE: //get_Region
8678 //zd1205_dumpEEPROM(macp);
8679 if (wrq
->u
.data
.pointer
){
8680 wrq
->u
.data
.flags
= 1;
8682 if (ZD_REGION_USA
== dot11Obj
.RegionCode
){
8683 wrq
->u
.data
.length
= 3;
8684 // if (copy_to_user(wrq->u.data.pointer, "USA", 4))
8686 memcpy(wrq
->u
.data
.pointer
, "USA", 4);
8689 else if (ZD_REGION_Europe
== dot11Obj
.RegionCode
){
8690 wrq
->u
.data
.length
= 13;
8691 // if (copy_to_user(wrq->u.data.pointer, "Taiwan/Europe", 14))
8693 memcpy(wrq
->u
.data
.pointer
, "Taiwan/Europe", 14);
8696 else if (ZD_REGION_France
== dot11Obj
.RegionCode
){
8697 wrq
->u
.data
.length
= 6;
8698 // if (copy_to_user(wrq->u.data.pointer, "France", 7))
8700 memcpy(wrq
->u
.data
.pointer
, "France", 7);
8703 else if (ZD_REGION_Japan
== dot11Obj
.RegionCode
){
8704 wrq
->u
.data
.length
= 5;
8705 // if (copy_to_user(wrq->u.data.pointer, "Japan", 6))
8707 memcpy(wrq
->u
.data
.pointer
, "Japan", 6);
8709 else if (ZD_REGION_Israel
== dot11Obj
.RegionCode
){
8710 wrq
->u
.data
.length
= 6;
8711 // if (copy_to_user(wrq->u.data.pointer, "Israel", 7))
8713 memcpy(wrq
->u
.data
.pointer
, "Israel", 7);
8716 else if (ZD_REGION_Mexico
== dot11Obj
.RegionCode
){
8717 wrq
->u
.data
.length
= 6;
8718 // if (copy_to_user(wrq->u.data.pointer, "Mexico", 7))
8720 memcpy(wrq
->u
.data
.pointer
, "Mexico", 7);
8728 case SIOCIWFIRSTPRIV
+ 0x9 : //set_Region
8730 int val
= *( (int *) wrq
->u
.name
);
8733 if ((val
< 1) || (val
> 6)){
8739 case 1 : macp
->RegionCode
= ZD_REGION_USA
;break;
8740 case 2 : macp
->RegionCode
= ZD_REGION_Europe
;break;
8741 case 3 : macp
->RegionCode
= ZD_REGION_France
;break;
8742 case 4 : macp
->RegionCode
= ZD_REGION_Japan
;break;
8743 case 5 : macp
->RegionCode
= ZD_REGION_Israel
;break;
8744 case 6 : macp
->RegionCode
= ZD_REGION_Mexico
;break;
8748 dot11Obj
.RegionCode
= macp
->RegionCode
;
8750 case 1 : dot11Obj
.AllowedChannel
= 0x107ff;break;//1-11
8751 case 2 : dot11Obj
.AllowedChannel
= 0x11fff;break;//1-13
8752 case 3 : dot11Obj
.AllowedChannel
= 0xa1e00;break;//10-13
8753 case 4 : dot11Obj
.AllowedChannel
= 0x13fff;break;//1-14
8754 case 5 : dot11Obj
.AllowedChannel
= 0x301fc;break;//3-9
8755 case 6 : dot11Obj
.AllowedChannel
= 0xa0600;break;//10,11
8759 checkChan
= pass_channel_for_region(macp
,macp
->cardSetting
.Channel
);
8760 if ( checkChan
!= macp
->cardSetting
.Channel
)
8762 macp
->cardSetting
.Channel
= checkChan
;
8763 dot11Obj
.Channel
= macp
->cardSetting
.Channel
;
8764 zd1205_SetRatesInfo(macp
);
8774 //prince add for moxa repeat begin
8776 case SIOCIWFIRSTPRIV
+ 0xD: //set_moxa_repeat
8777 ZD1211DEBUG(0, "Switch to MOXA REPEAT MODE\n");
8781 if ((!err
) && changed
) {
8783 defer_kevent(macp
, KEVENT_MOXA_REPEAT
);
8785 zd1205_moxa_repeat( macp
);
8790 up(&macp
->ioctl_sem
);
8792 //prince add for repeat function end
8793 ////////////////////////////
8794 #ifdef ZDCONF_MENUDBG
8798 if (copy_from_user(&zdreq
, ifr
->ifr_data
, sizeof(zdreq
))){
8802 zd1205_zd_dbg2_ioctl(macp
, &zdreq
,&ret
);
8803 copy_from_user(&in
,((struct zdap_ioctl
*)(ifr
->ifr_data
))->data
,4);
8804 copy_to_user(((struct zdap_ioctl
*)(ifr
->ifr_data
))->data
, &ret
, sizeof(ret
));
8805 zd1205_unlock(macp
);
8811 case ZDAPIOCTL
: //ZD1202 debug command
8812 if (copy_from_user(&zdreq
, ifr
->ifr_data
, sizeof (zdreq
))){
8813 printk(KERN_ERR
"ZDAPIOCTL: copy_from_user error\n");
8817 //printk(KERN_DEBUG "zd1211: cmd = %2x, reg = 0x%04x, value = 0x%08x\n", zdreq.cmd, zdreq.addr, zdreq.value);
8822 if ( zdreq
.cmd
== ZD_IOCTL_REG_READ
)
8823 zd1205_zd_dbg_ioctl(macp
, &zdreq
);
8826 memcpy(&macp
->zdreq
, &zdreq
, sizeof(zdreq
));
8827 defer_kevent(macp
, KEVENT_ZD_IOCTL
);
8831 zd1205_zd_dbg_ioctl(macp
, &zdreq
);
8833 zd1205_unlock(macp
);
8836 if ( zdreq
.cmd
== ZD_IOCTL_REG_READ
)
8838 if (copy_to_user(ifr
->ifr_data
, &zdreq
, sizeof (zdreq
)))
8844 case ZDPRODUCTIOCTL
:
8846 zdproduction_ioctl(macp
, (struct zd_point
*)&wrq
->u
.data
);
8847 zd1205_unlock(macp
);
8852 if (copy_from_user(&macp
->zd_wpa_req
, ifr
->ifr_data
, sizeof(struct zydas_wlan_param
))){
8853 WPADEBUG("ZD_IOCTL_WPA: copy_from_user error\n");
8858 //defer_kevent may cause wpa authentication timeout in slow system.
8859 //On SMP, it should not be slow. If we use wpa_ioctl directly on SMP, it has
8860 //race condition. So we need to use defer_kevent
8862 defer_kevent(macp
, KEVENT_ZD_WPA_IOCTL
);
8864 zd1205_wpa_ioctl(macp
, &macp
->zd_wpa_req
);
8866 zd1205_unlock(macp
);
8870 case ZD_IOCTL_PARAM
:
8876 /* Point to the name field and retrieve the
8877 * op and arg elements. */
8878 p
= (int *)wrq
->u
.name
;
8882 if(op
== ZD_PARAM_COUNTERMEASURES
) {
8884 if(dot11Obj
.MIC_CNT
)
8885 mCounterMeasureState
= 1;
8886 WPADEBUG("CounterMeasure Enable\n");
8889 mCounterMeasureState
= 0;
8890 WPADEBUG("CounterMeasure Disable\n");
8893 if(op
== ZD_PARAM_ROAMING
) {
8894 macp
->cardSetting
.ap_scan
=(U8
)arg
;
8895 WPADEBUG("************* ZD_PARAM_ROAMING: %d\n", arg
);
8897 if(op
== ZD_PARAM_PRIVACY
) {
8898 WPADEBUG("ZD_IOCTL_PRIVACY: ");
8900 /* Turn on the privacy invoke flag */
8902 mCap
|= CAP_PRIVACY
;
8903 macp
->cardSetting
.EncryOnOff
= 1;
8904 WPADEBUG("enable\n");
8907 mCap
&= ~CAP_PRIVACY
;
8908 macp
->cardSetting
.EncryOnOff
= 0;
8909 WPADEBUG("disable\n");
8912 if(op
== ZD_PARAM_WPA
) {
8913 WPADEBUG("ZD_PARAM_WPA: ");
8916 WPADEBUG("enable\n");
8917 macp
->cardSetting
.WPASupport
= 1;
8920 /* Reset the WPA related variables */
8921 WPADEBUG("disable\n");
8922 macp
->cardSetting
.WPASupport
= 0;
8924 /* Now we only set the length in the WPA IE
8926 macp
->cardSetting
.WPAIe
[1] = 0;
8929 if(op
== ZD_PARAM_COUNTERMEASURES
) {
8930 WPADEBUG("ZD_PARAM_COUNTERMEASURES: ");
8933 WPADEBUG("enable\n");
8936 WPADEBUG("disable\n");
8939 if(op
== ZD_PARAM_DROPUNENCRYPTED
) {
8940 WPADEBUG("ZD_PARAM_DROPUNENCRYPTED: ");
8943 WPADEBUG("enable\n");
8946 WPADEBUG("disable\n");
8949 if(op
== ZD_PARAM_AUTH_ALGS
) {
8950 WPADEBUG("ZD_PARAM_AUTH_ALGS: ");
8953 WPADEBUG("OPEN_SYSTEM\n");
8956 WPADEBUG("SHARED_KEY\n");
8963 //ZD1211DEBUG(0, "zd1205: unknown cmd = %2x\n", cmd);
8970 if ((!err
) && changed
) {
8972 defer_kevent(macp
, KEVENT_UPDATE_SETTING
);
8974 zd_UpdateCardSetting(&macp
->cardSetting
);
8979 up(&macp
->ioctl_sem
);
8989 * zd1205init - initialize the adapter
8990 * @macp: atapter's private data struct
8992 * This routine is called when this driver is loaded. This is the initialization
8993 * routine which allocates memory, configures the adapter and determines the
8999 * true: if successful
9004 zd1205_init(struct zd1205_private
*macp
)
9011 macp
->bAllowAccessRegister
= 1;
9013 /* read the MAC address from the eprom */
9014 mTxOFDMType
= &(((struct zd1205_private
*)g_dev
->priv
)->TxOFDMType
);
9015 zd1205_rd_eaddr(macp
);
9017 zd_writel(0x01, AfterPNP
);
9019 #if fWRITE_WORD_REG || fREAD_MUL_REG
9021 // Must get this information before any register write
9024 tmpValue
= zd1211_readl(cADDR_ENTRY_TABLE
, false);
9025 macp
->AddrEntryTable
= (u16
) tmpValue
;
9026 ZD1211DEBUG(0, "AddrEntryTable = %04x\n", macp
->AddrEntryTable
);
9029 macp
->RF_Mode
= zd_readl(E2P_POD
);
9032 //prince add for avoid cannont read RF_Mode
9033 macp
->RF_Mode
= 0x400005;
9034 //prince add for avoid cannont read RF_Mode
9037 ZD1211DEBUG(0, "RF_Mode = %08x\n", macp
->RF_Mode
);
9038 macp
->PA_Type
= ((macp
->RF_Mode
) >> 16) & 0xF;//hardware type 2, bit0-3
9039 printk(KERN_ERR
"PA type: %01x\n", macp
->PA_Type
);
9041 dot11Obj
.HWFeature
= macp
->RF_Mode
& 0xfff0;
9042 if((macp
->RF_Mode
>> 16) & BIT_15
)
9044 printk("PHYNEWLayout = 1\n");
9045 dot11Obj
.PHYNEWLayout
= 1;
9047 if((macp
->RF_Mode
>> 16) & BIT_7
)
9049 printk("PHY_Decrease_CR128_state = 1\n");
9050 dot11Obj
.PHY_Decrease_CR128_state
= 1;
9055 if (((macp
->RF_Mode
& 0xf) == AL2230_RF
) && (dot11Obj
.HWFeature
& BIT_7
) )
9056 macp
->RF_Mode
= AL2230S_RF
;
9058 macp
->RF_Mode
&= 0x0f;
9060 dot11Obj
.rfMode
= (macp
->RF_Mode
& 0x0f);
9063 if ((dot11Obj
.rfMode
== 0x04) || (dot11Obj
.rfMode
== 0x07))
9064 printk("AiroHa AL2230RF\n");
9065 else if (dot11Obj
.rfMode
== 0x07)
9066 printk("Airoha AL7230B_RF\n");
9067 else if (dot11Obj
.rfMode
== 0x0a)
9068 printk("Airoha AL2230S_RF\n");
9069 // else if (dot11Obj.rfMode == 0x09)
9070 // printk("GCT RF\n");
9071 else if (dot11Obj
.rfMode
== 0x0d)
9072 printk("RFMD RF\n");
9073 else if (dot11Obj
.rfMode
== 0x05)
9074 printk("AiroHa 7230B_RF\n");
9075 else if (dot11Obj
.rfMode
== UW2453_RF
)
9077 //dot11Obj.UWPowerControlFlag = TRUE;
9078 dot11Obj
.UWPowerControlFlag
= FALSE
;
9079 tmpValue
= zd_readl(E2P_DEVICE_VER
+12);
9080 dot11Obj
.UW2453SelectAntennaAUX
= tmpValue
>> 16;
9083 if((1 << i
) & dot11Obj
.UW2453SelectAntennaAUX
)
9084 dot11Obj
.UW2453ChannelSelectAntennaAUX
[i
] = TRUE
;
9086 dot11Obj
.UW2453ChannelSelectAntennaAUX
[i
] = FALSE
;
9088 if((1 << 14) & dot11Obj
.UW2453SelectAntennaAUX
)
9089 dot11Obj
.UW2453NoTXfollowRX
= TRUE
;
9090 if((1 << 15) & dot11Obj
.UW2453SelectAntennaAUX
)
9091 dot11Obj
.UW2453MiniCard
= TRUE
;
9093 printk("UW2453 RF\n");
9096 printk("RF_Mode = %x\n", (u8
)dot11Obj
.rfMode
);
9100 zd_writel(0x00, GPI_EN
);
9101 zd1205_sw_init(macp
);
9103 zd1205_hw_init(macp
);
9104 zd1205_disable_int();
9112 void zd1205_init_card_setting(struct zd1205_private
*macp
)
9114 card_Setting_t
*pSetting
= &macp
->cardSetting
;
9116 macp
->ModeChBssType
= 0x10;
9117 macp
->ModeChChannel
= 0x00;
9118 macp
->ModeChMacMode
= 0x00;
9122 pSetting
->BssType
= INFRASTRUCTURE_BSS
;
9124 pSetting
->BssType
= INDEPENDENT_BSS
;
9126 //pSetting->BssType = AP_BSS;
9127 //pSetting->BssType = INDEPENDENT_BSS;
9128 //pSetting->BssType = PSEUDO_IBSS;
9129 pSetting
->HiddenSSID
= 0; //disable hidden essid
9130 pSetting
->LimitedUser
= 32;
9131 pSetting
->RadioOn
= 1;
9133 pSetting
->BlockBSS
= 0;
9134 pSetting
->EncryOnOff
= 0;
9135 //pSetting->PreambleType = 0; //long preamble
9136 pSetting
->PreambleType
= 1; //short preamble
9137 pSetting
->Channel
= 6;
9138 pSetting
->EncryMode
= NO_WEP
;
9139 pSetting
->EncryKeyId
= 0;
9140 pSetting
->TxPowerLevel
= -1;
9142 if (pSetting
->BssType
== AP_BSS
) {
9143 pSetting
->AuthMode
= 2; //auto auth
9144 pSetting
->Info_SSID
[0] = 0;
9145 pSetting
->Info_SSID
[1] = 0x08;
9146 pSetting
->Info_SSID
[2] = 'Z';
9147 pSetting
->Info_SSID
[3] = 'D';
9148 pSetting
->Info_SSID
[4] = '1';
9149 pSetting
->Info_SSID
[5] = '2';
9150 pSetting
->Info_SSID
[6] = '1';
9151 pSetting
->Info_SSID
[7] = '1';
9152 pSetting
->Info_SSID
[8] = 'A';
9153 pSetting
->Info_SSID
[9] = 'P';
9155 else if (pSetting
->BssType
== INFRASTRUCTURE_BSS
) {
9156 pSetting
->AuthMode
= 0; //open syatem
9158 pSetting
->Info_SSID
[0] = 0;
9159 //pSetting->Info_SSID[1] = 0x05;
9160 pSetting
->Info_SSID
[1] = 0x00;
9161 pSetting
->Info_SSID
[2] = 'G';
9162 pSetting
->Info_SSID
[3] = '1';
9163 pSetting
->Info_SSID
[4] = '0';
9164 pSetting
->Info_SSID
[5] = '0';
9165 pSetting
->Info_SSID
[6] = '0';
9166 //pSetting->Info_SSID[7] = 'A';
9167 //pSetting->Info_SSID[8] = 'B';
9169 else if (pSetting
->BssType
== INDEPENDENT_BSS
) {
9170 pSetting
->AuthMode
= 0; //open syatem
9171 pSetting
->Info_SSID
[0] = 0;
9172 pSetting
->Info_SSID
[1] = 0x09;
9173 pSetting
->Info_SSID
[2] = '1';
9174 pSetting
->Info_SSID
[3] = '2';
9176 pSetting
->Info_SSID
[4] = '1';
9177 pSetting
->Info_SSID
[5] = '1';
9178 pSetting
->Info_SSID
[6] = 'A';
9179 pSetting
->Info_SSID
[7] = 'd';
9180 pSetting
->Info_SSID
[8] = 'H';
9181 pSetting
->Info_SSID
[9] = 'o';
9182 pSetting
->Info_SSID
[10] = 'c';
9185 #if !(defined(GCCK) && defined(OFDM))
9186 pSetting
->Info_SupportedRates
[0] = 0x01;
9187 pSetting
->Info_SupportedRates
[1] = 0x05;
9188 pSetting
->Info_SupportedRates
[2] = 0x82;
9189 pSetting
->Info_SupportedRates
[3] = 0x84;
9190 pSetting
->Info_SupportedRates
[4] = 0x8B;
9191 pSetting
->Info_SupportedRates
[5] = 0x96;
9192 pSetting
->Info_SupportedRates
[6] = 0x21;
9196 if ((dot11Obj
.rfMode
== AL2210MPVB_RF
) || (dot11Obj
.rfMode
== AL2210_RF
)){
9197 pSetting
->Rate275
= 1;
9198 pSetting
->Info_SupportedRates
[7] = 0x2C;//22
9199 pSetting
->Info_SupportedRates
[8] = 0x37;//27.5
9200 pSetting
->Info_SupportedRates
[1] = 0x07;
9203 pSetting
->Rate275
= 0;
9205 if (macp
->usb
->speed
!= USB_SPEED_HIGH
)
9206 pSetting
->MacMode
= PURE_B_MODE
;
9209 //if (pSetting->BssType == INDEPENDENT_BSS)
9210 //pSetting->MacMode = PURE_B_MODE;
9212 pSetting
->MacMode
= MIXED_MODE
;
9214 zd1205_SetRatesInfo(macp
);
9215 //pCardSetting->UartEnable = 1;
9216 //pCardSetting->BaudRate = BAUD_RATE_115200;
9222 pSetting
->FragThreshold
= 9999;
9223 pSetting
->RTSThreshold
= 9999;
9225 pSetting
->BeaconInterval
= 100;
9226 pSetting
->DtimPeriod
= 3;
9227 pSetting
->SwCipher
= 0;
9230 pSetting
->DynKeyMode
= 0;
9231 pSetting
->WpaBcKeyLen
= 32; // Tmp key(16) + Tx Mic key(8) + Rx Mic key(8)
9234 //dot11Obj.MicFailure = NULL;
9235 //dot11Obj.AssocRequest = NULL;
9236 //dot11Obj.WpaIe = NULL;
9239 #if 0 // 04-04-2007 mask by Victor Yu. We don't use it.
9240 void zd1205_load_card_setting(struct zd1205_private
*macp
, u8 bInit
)
9245 unsigned int file_length
;
9246 u8
*buffer
, *old_buffer
;
9247 int i
, parse_id
, count
= 0;
9249 card_Setting_t
*pSetting
= &macp
->cardSetting
;
9253 //struct stat file_info;
9255 // Open the code file
9256 // for file opening temporarily tell the kernel I am not a user for
9257 // memory management segment access
9261 // open the file with the firmware for uploading
9262 if (ifp
= open(config_filename
, O_RDONLY
, 0 ), ifp
< 0){
9263 // error opening the file
9264 ZD1211DEBUG(0, "File opening did not success\n");
9269 /* Get information about the file. */
9270 //fstat (ifp, &file_info);
9271 //sys_fstat(ifp, &file_info);
9272 //file_length = file_info.st_size;
9275 buffer
= kmalloc(file_length
, GFP_ATOMIC
);
9276 old_buffer
= buffer
;
9278 /* Read the file into the buffer. */
9279 bcount
= read(ifp
, buffer
, file_length
);
9280 ZD1211DEBUG(1, "bcount=%d\n", bcount
);
9285 // switch back the segment setting
9291 while ((token
=strsep((char **)&buffer
, "=\n"))){
9295 if (!strcmp(token
, "mode"))
9297 else if (!strcmp(token
, "essid"))
9299 else if (!strcmp(token
, "channel"))
9301 else if (!strcmp(token
, "rts"))
9303 else if (!strcmp(token
, "frag"))
9311 if (!strcmp(token
, "Managed"))
9312 pSetting
->BssType
= INFRASTRUCTURE_BSS
;
9313 else if (!strcmp(token
, "Ad-Hoc"))
9314 pSetting
->BssType
= INDEPENDENT_BSS
;
9315 else if (!strcmp(token
, "Master"))
9316 pSetting
->BssType
= AP_BSS
;
9320 pSetting
->Info_SSID
[0] = 0;
9321 ssidLen
= strnlen(token
, 32);
9322 pSetting
->Info_SSID
[1] = ssidLen
;
9324 for (i
=0; i
<ssidLen
; i
++)
9325 pSetting
->Info_SSID
[2+i
] = token
[i
];
9329 pSetting
->Channel
= (u8
)simple_strtoul(token
, &token
, 0);
9333 pSetting
->RTSThreshold
= (u16
)simple_strtoul(token
, &token
, 0);
9337 frag
= (u16
)simple_strtoul(token
, &token
, 0);
9341 pSetting
->FragThreshold
= frag
;
9355 zd_UpdateCardSetting(pSetting
);
9357 //zd1205_show_card_setting(macp);
9361 void zd1205_save_card_setting(struct zd1205_private
*macp
)
9366 unsigned int file_length
;
9367 u8
*buffer
, *old_buffer
;
9371 card_Setting_t
*pSetting
= &macp
->cardSetting
;
9373 //struct stat file_info;
9375 // Open the code file
9376 // for file opening temporarily tell the kernel I am not a user for
9377 // memory management segment access
9382 // open the file with the firmware for uploading
9383 if (ifp
= open(config_filename
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0666 ), ifp
< 0){
9384 // error opening the file
9385 ZD1211DEBUG(0, "File opening did not success\n");
9390 /* Get information about the file. */
9391 //fstat (ifp, &file_info);
9392 //sys_fstat(ifp, &file_info);
9393 //file_length = file_info.st_size;
9397 buffer
= kmalloc(file_length
, GFP_ATOMIC
);
9398 old_buffer
= buffer
;
9400 ssidLen
= pSetting
->Info_SSID
[1];
9401 memcpy(ssid
, &pSetting
->Info_SSID
[2], ssidLen
);
9402 ssid
[ssidLen
] = '\0';
9404 if (pSetting
->BssType
== INFRASTRUCTURE_BSS
)
9405 bcount
= snprintf(buffer
, file_length
, "mode=Managed\n");
9406 else if (pSetting
->BssType
== INDEPENDENT_BSS
)
9407 bcount
= snprintf(buffer
, file_length
, "mode=Ad-Hoc\n");
9408 else if (pSetting
->BssType
== AP_BSS
)
9409 bcount
= snprintf(buffer
, file_length
, "mode=Master\n");
9411 ZD1211DEBUG(1, "mode bcount=%d\n", bcount
);
9412 write_byte
= bcount
;
9415 bcount
= snprintf(buffer
, file_length
, "essid=%s\n", ssid
);
9416 ZD1211DEBUG(1, "essid bcount=%d\n", bcount
);
9417 write_byte
+= bcount
;
9420 bcount
= snprintf(buffer
, file_length
, "channel=%d\n", pSetting
->Channel
);
9421 ZD1211DEBUG(1, "channel bcount=%d\n", bcount
);
9422 write_byte
+= bcount
;
9425 bcount
= snprintf(buffer
, file_length
, "rts=%d\n", pSetting
->RTSThreshold
);
9426 ZD1211DEBUG(1, "rts bcount=%d\n", bcount
);
9427 write_byte
+= bcount
;
9430 bcount
= snprintf(buffer
, file_length
, "frag=%d\n", pSetting
->FragThreshold
);
9431 ZD1211DEBUG(1, "frag bcount=%d\n", bcount
);
9432 write_byte
+= bcount
;
9434 /* Write the file into the buffer. */
9435 ZD1211DEBUG(1, "write_byte=%d\n", write_byte
);
9436 bcount
= write(ifp
, old_buffer
, write_byte
);
9437 ZD1211DEBUG(1, "bcount=%d\n", bcount
);
9442 // switch back the segment setting
9452 zd1205_found1(struct pci_dev
*pcid
, const struct pci_device_id
*ent
)
9454 static int first_time
= true;
9455 struct net_device
*dev
= NULL
;
9456 struct zd1205_private
*macp
= NULL
;
9463 dev
= alloc_etherdev(sizeof (struct zd1205_private
));
9467 printk(KERN_ERR
"zd1205: Not able to alloc etherdev struct\n");
9475 g_dev
= dev
; //save this for CBs use
9476 SET_MODULE_OWNER(dev
);
9481 printk(KERN_NOTICE
"%s - version %s\n",
9482 zd1205_full_driver_name
, zd1205_driver_version
);
9484 printk(KERN_NOTICE
"%s\n", zd1205_copyright
);
9485 printk(KERN_NOTICE
"\n");
9492 pci_set_drvdata(pcid
, dev
);
9493 macp
->numTcb
= NUM_TCB
;
9495 macp
->numTbd
= NUM_TBD
;
9496 macp
->numRfd
= NUM_RFD
;
9498 macp
->numTbdPerTcb
= NUM_TBD_PER_TCB
;
9500 macp
->rxOffset
= ZD_RX_OFFSET
;
9501 macp
->rfd_size
= 24; // form CbStatus to NextCbPhyAddrHighPart
9504 init_timer(&macp
->watchdog_timer
);
9507 macp
->watchdog_timer
.data
= (unsigned long) dev
;
9508 macp
->watchdog_timer
.function
= (void *) &zd1205_watchdog_cb
;
9509 init_timer(&macp
->tm_hking_id
);
9510 macp
->tm_hking_id
.data
= (unsigned long) dev
;
9512 macp
->tm_hking_id
.function
= (void *) &HKeepingCB
;
9514 init_timer(&macp
->tm_mgt_id
);
9515 macp
->tm_mgt_id
.data
= (unsigned long) dev
;
9516 macp
->tm_mgt_id
.function
= (void *) &zd1205_mgt_mon_cb
;
9519 if ((rc
= zd1205_pci_setup(pcid
, macp
)) != 0) {
9525 if (!zd1205_init(macp
)) {
9526 printk(KERN_ERR
"zd1025: Failed to initialize, instance \n");
9534 dev
->irq
= pcid
->irq
;
9535 dev
->open
= &zd1205_open
;
9536 dev
->hard_start_xmit
= &zd1205_xmit_frame
;
9538 dev
->stop
= &zd1205_close
;
9539 dev
->change_mtu
= &zd1205_change_mtu
;
9540 dev
->get_stats
= &zd1205_get_stats
;
9541 dev
->set_multicast_list
= &zd1205_set_multi
;
9543 dev
->set_mac_address
= &zd1205_set_mac
;
9545 dev
->do_ioctl
= &zd1205_ioctl
;
9546 dev
->features
|= NETIF_F_SG
| NETIF_F_HW_CSUM
;
9548 if ((rc
= register_netdev(dev
)) != 0) {
9555 memcpy(macp
->ifname
, dev
->name
, IFNAMSIZ
);
9556 macp
->ifname
[IFNAMSIZ
-1] = 0;
9560 if (netif_carrier_ok(macp
->device
))
9561 macp
->cable_status
= "Cable OK";
9563 macp
->cable_status
= "Not Available";
9565 if (zd1205_create_proc_subdir(macp
) < 0) {
9566 printk(KERN_ERR
"zd1205: Failed to create proc dir for %s\n",
9567 macp
->device
->name
);
9572 printk(KERN_NOTICE
"\n");
9577 iounmap(macp
->regp
);
9578 pci_release_regions(pcid
);
9579 pci_disable_device(pcid
);
9584 pci_set_drvdata(pcid
, NULL
);
9598 * zd1205_clear_structs - free resources
9599 * @dev: adapter's net_device struct
9602 * Free all device specific structs, unmap i/o address, etc.
9607 zd1205_clear_structs(struct net_device
*dev
)
9610 struct zd1205_private
*macp
= dev
->priv
;
9613 zd1205_sw_release();
9615 iounmap(macp
->regp
);
9616 pci_release_regions(macp
->pdev
);
9617 pci_disable_device(macp
->pdev
);
9618 pci_set_drvdata(macp
->pdev
, NULL
);
9622 free_netdev(dev
); //kernel 2,6
9627 zd1205_remove1(struct pci_dev
*pcid
)
9629 struct net_device
*dev
;
9630 struct zd1205_private
*macp
;
9635 if (!(dev
= (struct net_device
*) pci_get_drvdata(pcid
)))
9640 unregister_netdev(dev
);
9641 zd1205_remove_proc_subdir(macp
);
9642 zd1205_clear_structs(dev
);
9650 #if 0 //move codes to zdpci_hotplug.c
9651 static struct pci_device_id zd1205_id_table
[] __devinitdata
=
9655 {0x167b, 0x2102, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, ZD_1202
},
9656 {0x167b, 0x2100, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, ZD_1202
},
9657 {0x167b, 0x2105, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, ZD_1205
},
9664 MODULE_DEVICE_TABLE(pci
, zd1205_id_table
);
9668 static struct pci_driver zd1205_driver
= {
9670 .id_table
= zd1205_id_table
,
9671 .probe
= zd1205_found1
,
9673 .remove
= __devexit_p(zd1205_remove1
),
9678 zd1205_init_module(void)
9683 ret
= pci_module_init(&zd1205_driver
);
9689 zd1205_cleanup_module(void)
9691 pci_unregister_driver(&zd1205_driver
);
9694 module_init(zd1205_init_module
);
9696 module_exit(zd1205_cleanup_module
);
9699 /*************************************************************************/
9700 BOOLEAN
zdcb_setup_next_send(fragInfo_t
*frag_info_origin
)
9703 fragInfo_t
*frag_info
= frag_info_origin
;
9704 #if ZDCONF_LP_SUPPORT == 1
9705 struct lp_desc
*lp_bucket
= NULL
;
9709 struct zd1205_private
*macp
= g_dev
->priv
;
9710 struct sk_buff
*skb
= (struct sk_buff
*)frag_info
->buf
;
9711 U8 bIntraBss
= frag_info
->bIntraBss
;
9712 U8 MsgID
= frag_info
->msgID
;
9713 U8 numOfFrag
= frag_info
->totalFrag
;
9715 U16 aid
= frag_info
->aid
;
9716 U8 hdrLen
= frag_info
->hdrLen
;
9717 zd1205_SwTcb_t
*sw_tcb
;
9718 zd1205_HwTCB_t
*hw_tcb
;
9721 U32 bodyLen
, length
;
9722 U32 tcb_tbd_num
= 0;
9727 wla_Header_t
*wla_hdr
;
9731 skb_frag_t
*frag
= NULL
;
9732 ctrl_Set_parm_t ctrl_setting_parms
;
9733 U32 TotalLength
= 0;
9737 zd1205_SwTcb_t
*next_sw_tcb
;
9738 U32 tmp_value
, tmp_value3
;
9739 unsigned long lock_flag
;
9742 #if ZDCONF_LP_SUPPORT == 1
9743 static U32 LP_Threshold_StartTime
=0; //Threshold to trigger LP_MODE
9744 static U32 LP_Threshold_PKT_NUM
=0; //Threshold to trigger LP_MODE
9745 static BOOLEAN LP_Over_Threshold
= FALSE
;
9751 extern U32 LP_CNT_PUSH_SUCC
;
9752 extern U32 LP_CNT_PUSH_FAIL
;
9753 extern U32 LP_CNT_POP_SUCC
;
9754 extern U32 LP_CNT_POP_FAIL
;
9755 extern U32 LP_CNT_PERIOD_POP_SUCC
;
9756 extern U32 LP_CNT_PERIOD_POP_FAIL
;
9757 extern U32 LP_CNT_LAST_LATENCY
;
9759 if(frag_info
->msgID
!= 254 )
9761 LP_Threshold_PKT_NUM
++;
9762 if(LP_Threshold_PKT_NUM
> 100)
9764 LP_Threshold_PKT_NUM
= 0;
9765 if(jiffies
-LP_Threshold_StartTime
<= HZ
)
9766 LP_Over_Threshold
= TRUE
;
9768 LP_Over_Threshold
= FALSE
;
9769 LP_Threshold_StartTime
= jiffies
;
9774 memset(&ctrl_setting_parms
,0, sizeof(ctrl_Set_parm_t
));
9779 if (!test_bit(ZD1211_RUNNING
, &macp
->flags
))
9783 ZD1211DEBUG(2, "===== zdcb_setup_next_send enter =====\n");
9784 ZD1211DEBUG(2, "zd1211: bIntraBss = %x\n", bIntraBss
);
9785 ZD1211DEBUG(2, "zd1211: numOfFrag = %x\n", numOfFrag
);
9786 ZD1211DEBUG(2, "zd1211: skb = %x\n", (u32
)skb
);
9787 ZD1211DEBUG(2, "zd1211: aid = %x\n", aid
);
9790 spin_lock_irqsave(&macp
->bd_non_tx_lock
, lock_flag
);
9794 if ((frag_info
->msgID
!= 254) && (skb
) && (!bIntraBss
)){ //data frame from upper layer
9795 if (skb_shinfo(skb
)->nr_frags
){ //got frag buffer
9796 frag
= &skb_shinfo(skb
)->frags
[0];
9798 if (skb
->len
> macp
->cardSetting
.FragThreshold
){ //need fragment
9799 pdu_size
= macp
->cardSetting
.FragThreshold
- 24 - 4; //mac header and crc32 length
9800 numOfFrag
= (skb
->len
+ (pdu_size
-1) ) / pdu_size
;
9804 ZD1211DEBUG(2, "zd1211: numOfFrag = %x\n", numOfFrag
);
9809 if (macp
->freeTxQ
->count
-1 < numOfFrag
){
9810 printk(KERN_ERR
"zd1205: Not enough freeTxQ\n");
9811 //printk(KERN_ERR "zd1205: Cnt of freeTxQ = %x\n", macp->freeTxQ->count);
9812 zd_EventNotify(EVENT_TX_COMPLETE
, ZD_RETRY_FAILED
, (U32
)MsgID
, aid
);
9814 spin_unlock_irqrestore(&macp
->bd_non_tx_lock
, lock_flag
);
9819 #if ZDCONF_LP_SUPPORT == 1
9820 if(dot11Obj
.LP_MODE
) {
9821 if(frag_info
->msgID
== 254) {
9822 static int loopCnt
= 0;
9823 //if(loopCnt++ % 3 !=0 ) return FALSE;
9824 if(macp
->freeTxQ
->count
- 1 < 1) {
9825 printk(KERN_ERR
"FreeTxQ[0] is empty to popPkt,P\n");
9828 lp_bucket
= popPkt(FALSE
, 0, nowT());
9829 if(lp_bucket
== NULL
) {
9830 LP_CNT_PERIOD_POP_FAIL
++;
9833 LP_CNT_PERIOD_POP_SUCC
++;
9834 //printk("Got frame in Periodid poll\n");
9835 frag_info
= &lp_bucket
->pkt
[0];
9836 frag_info
->macHdr
[0][0]=0x88; //SLOW DOWN
9837 //if(lp_bucket->pktSize >= 1600) frag_info->qid = 0;
9840 (sstByAid
[frag_info
->aid
]->Turbo_AMSDU
) &&
9841 (LP_Over_Threshold
) && //LP works when data arrival rate not low
9842 !(frag_info
->EthHdr
[0] & BIT_0
) &&
9843 ((frag_info
->macHdr
[0][0] & 0x0C) == 0x08) &&
9844 ((((U16
) frag_info
->EthHdr
[12]) << 8) + (frag_info
->EthHdr
[13]) != 0x888e) &&
9845 !(frag_info
->macHdr
[0][4] & BIT_0
) &&
9846 (mBssType
== INFRASTRUCTURE_BSS
|| sstByAid
[frag_info
->aid
]->LP_CAP
)
9849 static U32 LastData
= 0;
9851 //tmpDataTime = LastData;
9852 //LastData = nowT();
9853 if(pushPkt(frag_info
, sstByAid
[frag_info
->aid
]->Turbo_AMSDU_LEN
,nowT()) != 0) {
9860 if(macp
->freeTxQ
->count
- 1 < 1) {
9861 printk(KERN_ERR
"FreeTxQ[0] is empty to popPkt,N\n");
9864 lp_bucket
= popPkt(FALSE
, sstByAid
[frag_info
->aid
]->Turbo_AMSDU_LEN
,nowT());
9866 if(lp_bucket
== NULL
) {
9867 //printk("popPkt NULL\n");
9872 frag_info
= &lp_bucket
->pkt
[0];
9873 memset(&ctrl_setting_parms
,0, sizeof(ctrl_Set_parm_t
));
9874 //if(nowT() - tmpDataTime > 500)
9875 // ctrl_setting_parms.DurationLen = 500;
9876 //printk("Got a Data Frm from lp_bucket\n");
9877 frag_info
->macHdr
[0][0]=0x88; //SLOW DOWN
9878 //if(lp_bucket->pktSize >= 1600) frag_info->qid = 0;
9880 skb
= (struct sk_buff
*)frag_info
->buf
;
9881 bIntraBss
= frag_info
->bIntraBss
;
9882 MsgID
= frag_info
->msgID
;
9883 numOfFrag
= frag_info
->totalFrag
;
9884 aid
= frag_info
->aid
;
9885 hdrLen
= frag_info
->hdrLen
;
9886 //qid = frag_info->qid;
9888 if(frag_info
->macHdr
[0][0] == 0x88)
9890 if(mBssType
== INFRASTRUCTURE_BSS
)
9891 memcpy(frag_info
->macHdr
[0]+4+12, frag_info
->macHdr
[0]+4,6);
9892 else if(mBssType
== AP_BSS
)
9893 memcpy(frag_info
->macHdr
[0]+4+12, frag_info
->macHdr
[0]+4+6,6);
9895 printk("ADHOC or WDS don't support A-MSDU now\n");
9899 ctrl_setting_parms
.Rate
= frag_info
->rate
;
9900 ctrl_setting_parms
.Preamble
= frag_info
->preamble
;
9901 ctrl_setting_parms
.encryType
= frag_info
->encryType
;
9902 //ctrl_setting_parms.vapId = frag_info->vapId;
9904 for (i
=0; i
<numOfFrag
; i
++){
9905 ZD1211DEBUG(2, "zd1211: Cnt of freeTxQ = %x\n", macp
->freeTxQ
->count
);
9906 ZD1211DEBUG(2, "zd1211: Frag Num = %x\n", i
);
9908 sw_tcb
= zd1205_first_txq(macp
, macp
->freeTxQ
);
9909 #if ZDCONF_LP_SUPPORT == 1
9910 if(sw_tcb
== NULL
) {
9911 printk(KERN_ERR
"FreeTxQ is NULL !!! Very Serious\n");
9912 printk(KERN_ERR
"Maybe Cause by LP with Multiple Push");
9913 printk(KERN_ERR
"Check LP vs. FreeTxQ\n");
9915 memcpy(sw_tcb
->Padding
, "abc",3);
9918 if(frag_info
->macHdr
[0][0]==0x88)
9920 memcpy(tmpBuf
, frag_info
->macHdr
[0]+24, frag_info
->hdrLen
-24);
9921 memcpy(frag_info
->macHdr
[0]+26, tmpBuf
, frag_info
->hdrLen
-24);
9922 frag_info
->macHdr
[0][24]=BIT_7
;
9923 frag_info
->macHdr
[0][25]=0;
9924 frag_info
->hdrLen
+=2;
9925 hdrLen
= frag_info
->hdrLen
;
9930 if(dot11Obj
.LP_MODE
)
9931 sw_tcb
->LP_bucket
= lp_bucket
;
9935 //sw_tcb->bHasCompleteBeforeSend = 0;
9936 //sw_tcb->bHasBeenDelayedBefore = 0;
9938 hdr
= frag_info
->macHdr
[i
];
9940 if (macp
->dbg_flag
> 4)
9941 zd1205_dump_data("header part", (U8
*)hdr
, 24);
9945 if ((bIntraBss
) || (!frag
)){ //wireless forwarding or tx data from upper layer and no linux frag
9946 ZD1211DEBUG(2, "zd1211: Wireless forwarding or no linux frag\n");
9947 pBody
= frag_info
->macBody
[i
];
9948 bodyLen
= frag_info
->bodyLen
[i
];
9949 CurrFragLen
= bodyLen
;
9950 NextFragLen
= frag_info
->nextBodyLen
[i
];
9951 if (i
== (numOfFrag
- 1))
9952 sw_tcb
->LastFrag
= 1;
9954 sw_tcb
->LastFrag
= 0;
9956 else{ //tx data from upper layer with linux frag
9957 ZD1211DEBUG(2, "zd1211: tx data from upper layer with linux frag\n");
9961 if (i
== (numOfFrag
- 1)){
9962 CurrFragLen
= bodyLen
- i
*pdu_size
;
9964 sw_tcb
->LastFrag
= 1;
9967 CurrFragLen
= pdu_size
;
9968 sw_tcb
->LastFrag
= 0;
9970 if (i
== (numOfFrag
-2))
9971 NextFragLen
= bodyLen
- (i
+1)*pdu_size
;
9973 NextFragLen
= pdu_size
;
9979 //ZD1211DEBUG(2, "zd1211: mgt frame\n");
9981 pBody
= frag_info
->macBody
[i
];
9982 bodyLen
= frag_info
->bodyLen
[i
];
9983 CurrFragLen
= bodyLen
;
9984 NextFragLen
= frag_info
->nextBodyLen
[i
];
9985 sw_tcb
->LastFrag
= 1;
9988 wla_hdr
= (wla_Header_t
*)hdr
;
9989 hw_tcb
= sw_tcb
->pTcb
;
9990 pTbd
= sw_tcb
->pFirstTbd
;
9992 hw_tcb
->TxCbTbdNumber
= 0;
9994 sw_tcb
->FrameType
= hdr
[0];
9995 sw_tcb
->MsgID
= MsgID
;
9998 sw_tcb
->bIntraBss
= bIntraBss
;
9999 sw_tcb
->Rate
= frag_info
->rate
;
10001 #if ZDCONF_LP_SUPPORT == 1
10002 //ZD1211DEBUG(2, "zd1212: sw_tcb = %x\n", sw_tcb);
10003 ZD1211DEBUG(2, "zd1212: hw_tcb = %lx\n", (U32
)hw_tcb
);
10004 ZD1211DEBUG(2, "zd1212: first tbd = %lx\n", (U32
)pTbd
);
10005 if(dot11Obj
.LP_MODE
&& lp_bucket
) {
10006 for(i
=1;i
<lp_bucket
->pktCnt
;i
++) {
10007 CurrFragLen
+= lp_bucket
->pkt
[i
].bodyLen
[0]+14;
10008 if(i
!= lp_bucket
->pktCnt
- 1)
10009 CurrFragLen
+= (4-((lp_bucket
->pkt
[i
].bodyLen
[0]+14) % 4))%4;
10010 NextFragLen
+= lp_bucket
->pkt
[i
].nextBodyLen
[0]+14;
10012 CurrFragLen
+= 14; //SLOW DOWN
10013 if(lp_bucket
->pktCnt
!= 1)
10014 CurrFragLen
+= (4-((lp_bucket
->pkt
[0].bodyLen
[0]+14) % 4))%4;
10015 CurrFragLen
+= 2; //For QoS Ctrl Field
10016 //CurrFragLen += lp_bucket->pktCnt*2+2;
10017 //printk("Total CurrFragLen : %d\n", CurrFragLen);
10020 if (!macp
->bPSMSupported
)
10021 if (wla_hdr
->Duration
[0] != 0 || wla_hdr
->Duration
[1] != 0)
10022 printk(KERN_ERR
"Dur = %d\n", wla_hdr
->Duration
[0] + ((U16
)wla_hdr
->Duration
[1]<<8));
10027 ctrl_setting_parms
.CurrFragLen
= CurrFragLen
;
10028 ctrl_setting_parms
.NextFragLen
= NextFragLen
;
10030 /* Control Setting */
10031 length
= Cfg_CtrlSetting(macp
, sw_tcb
, wla_hdr
, &ctrl_setting_parms
);
10032 if(wla_hdr
->FrameCtrl
[0] == PS_POLL
)
10034 if((*(U16
*)wla_hdr
->Duration
) == 0)
10035 printk("AAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBB\n");
10037 TotalLength
= length
;
10039 pTbd
->TbdBufferAddrHighPart
= 0;
10040 pTbd
->TbdBufferAddrLowPart
= sw_tcb
->HwCtrlPhys
;
10041 pTbd
->TbdCount
= length
;
10044 #if ZDCONF_LP_SUPPORT == 1
10045 cfgLength
= length
;
10047 //if(*(u16 *)wla_hdr->Duration != 0) { //Possible Alignment Problem
10048 //if(wla_hdr->Duration[0]+wla_hdr->Duration[1] != 0)
10049 if(wla_hdr
->FrameCtrl
[0] != PS_POLL
)
10051 wla_hdr
->Duration
[0] = 0;
10052 wla_hdr
->Duration
[1] = 0;
10056 if (ctrl_setting_parms
.encryType
== TKIP
){
10057 length
= Cfg_MacHeader(macp
, sw_tcb
, wla_hdr
, hdrLen
);
10058 pTbd
->TbdBufferAddrLowPart
= sw_tcb
->HwHeaderPhys
;
10060 else { //WPA will failed, why??
10062 pTbd
->TbdBufferAddrLowPart
= (u32
)hdr
;
10066 TotalLength
+= length
;
10067 pTbd
->TbdCount
= length
;
10072 #if ZDCONF_LP_SUPPORT == 1
10073 if(!lp_bucket
|| !dot11Obj
.LP_MODE
)
10075 TotalLength
+= CurrFragLen
;
10077 sw_tcb
->pHwCtrlPtr
->CtrlSetting
[18] = (u8
)TotalLength
;
10078 sw_tcb
->pHwCtrlPtr
->CtrlSetting
[19] = (u8
)(TotalLength
>> 8);
10083 if ((!skb
) || ((skb
) && (!frag
)) ) {
10084 u32 body_dma
, tbdidx
;
10086 ZD1211DEBUG(2, "zd1211: Management frame body or No linux frag\n");
10087 #if ZDCONF_LP_SUPPORT == 1
10088 if(!dot11Obj
.LP_MODE
|| !lp_bucket
)
10091 if (macp
->dbg_flag
> 4)
10092 zd1205_dump_data("data part", (U8
*)pBody
, 14);
10094 pTbd
->TbdBufferAddrHighPart
= 0;
10095 #ifndef HOST_IF_USB
10096 body_dma
= pci_map_single(macp
->pdev
, pBody
, bodyLen
, PCI_DMA_TODEVICE
);
10098 body_dma
= (u32
)pBody
;
10101 ZD1211DEBUG(2, "zd1211: body_dma = %x\n", (u32
)body_dma
);
10103 pTbd
->TbdBufferAddrLowPart
= body_dma
;
10104 pTbd
->TbdCount
= CurrFragLen
;
10105 pBody
+= CurrFragLen
;
10108 pTbd
->PrvFragLen
= PrvFragLen
;
10109 PrvFragLen
+= CurrFragLen
;
10115 #if ZDCONF_LP_SUPPORT == 1
10116 else if(dot11Obj
.LP_MODE
&& lp_bucket
) //Long Packet
10118 //printk("pktCnt:%d\n", lp_bucket->pktCnt);
10120 for(tbdidx
= 0; tbdidx
< lp_bucket
->pktCnt
;tbdidx
++) {
10123 pTbd
->TbdBufferAddrHighPart
= 0;
10124 lp_bucket
->pkt
[tbdidx
].EthHdr
[13] = (14+lp_bucket
->pkt
[tbdidx
].bodyLen
[0]) & 0xFF;
10125 lp_bucket
->pkt
[tbdidx
].EthHdr
[12] = (14+lp_bucket
->pkt
[tbdidx
].bodyLen
[0]) >> 8;
10127 be16_to_cpu(*(U16
*)(lp_bucket
->pkt
[tbdidx
].EthHdr
+12)) > 3500;
10129 printk("What!? size > 3500 : %ld\n", xxx
);
10130 memcpy(sw_tcb
->HdrInfo
[tbdidx
],lp_bucket
->pkt
[tbdidx
].EthHdr
,14);
10131 pBody
= sw_tcb
->HdrInfo
[tbdidx
];
10133 body_dma
= (u32
)pBody
;
10136 printk("!!!!!!!!! body_dma is NULL\n");
10137 pTbd
->TbdBufferAddrLowPart
= body_dma
;
10138 pTbd
->TbdCount
= bodyLen
;
10142 TotalLength
+= bodyLen
;
10143 bodyLength
+= bodyLen
;
10145 pTbd
->TbdBufferAddrHighPart
= 0;
10146 pBody
= lp_bucket
->pkt
[tbdidx
].macBody
[0]; //SLOW
10147 bodyLen
= lp_bucket
->pkt
[tbdidx
].bodyLen
[0];//SLOW
10148 body_dma
= (u32
)pBody
;
10150 printk("!!!!!!!!!!!!! body_dma is NULL\n");
10151 pTbd
->TbdBufferAddrLowPart
= body_dma
;
10152 pTbd
->TbdCount
= bodyLen
;
10156 TotalLength
+= bodyLen
;
10157 bodyLength
+= bodyLen
;
10159 //For A-MSDU Padding
10160 if(tbdidx
!= lp_bucket
->pktCnt
-1 && ((bodyLen
+14)%4))
10162 pTbd
->TbdBufferAddrHighPart
= 0;
10163 pBody
= sw_tcb
->Padding
; //SLOW
10164 bodyLen
= (4-(bodyLen
+ 14) % 4)%4;
10165 body_dma
= (u32
)pBody
;
10166 pTbd
->TbdBufferAddrLowPart
= body_dma
;
10167 pTbd
->TbdCount
= bodyLen
;
10171 TotalLength
+= bodyLen
;
10172 bodyLength
+= bodyLen
;
10180 while(CurrFragLen
){
10184 if (CurrFragLen
>= frag
->size
){
10185 printk(KERN_DEBUG
"zd1205: linux more frag skb\n");
10186 addr
= ((void *) page_address(frag
->page
) + frag
->page_offset
);
10187 pTbd
->TbdBufferAddrHighPart
= 0;
10188 #ifndef HOST_IF_USB
10189 body_dma
= pci_map_single(macp
->pdev
, addr
, frag
->size
, PCI_DMA_TODEVICE
);
10191 body_dma
= (u32
)addr
;
10193 pTbd
->TbdBufferAddrLowPart
= body_dma
;
10194 pTbd
->TbdCount
= frag
->size
;
10197 pTbd
->PrvFragLen
= PrvFragLen
;
10198 PrvFragLen
+= CurrFragLen
;
10200 CurrFragLen
-= frag
->size
;
10204 printk(KERN_DEBUG
"zd1205: linux last frag skb\n");
10205 addr
= ((void *) page_address(frag
->page
) + frag
->page_offset
);
10206 pTbd
->TbdBufferAddrHighPart
= 0;
10207 #ifndef HOST_IF_USB
10208 body_dma
= cpu_to_le32(pci_map_single(macp
->pdev
, addr
, pdu_size
, PCI_DMA_TODEVICE
));
10210 body_dma
= (u32
)addr
;
10212 pTbd
->TbdBufferAddrLowPart
= body_dma
;
10213 frag
->page_offset
+= CurrFragLen
;
10214 frag
->size
-= CurrFragLen
;
10216 pTbd
->PrvFragLen
= PrvFragLen
;
10217 PrvFragLen
+= CurrFragLen
;
10222 printk(KERN_DEBUG
"zd1205: page_address = %x\n", (u32
)addr
);
10223 printk(KERN_DEBUG
"zd1205: body_dma = %x\n", (u32
)body_dma
);
10229 hw_tcb
->TxCbTbdNumber
= tcb_tbd_num
;
10232 #ifndef HOST_IF_USB
10233 hw_tcb
->CbCommand
= 0; /* set this TCB belong to bus master */
10237 tmp_value
= zd_readl(DeviceState
);
10240 if ((tmp_value
== TX_READ_TCB
) || (tmp_value
== TX_CHK_TCB
)){
10241 /* Device is now checking suspend or not.
10242 Keep watching until it finished check. */
10245 if (loopCnt
> 1000000)
10255 if (loopCnt
> 1000000)
10256 ZD1211DEBUG(0, "I am in zdcb_setup_next_send loop\n") ;
10258 ZD1211DEBUG(1, "zd1211: Device State = %x\n", (u32
)tmp_value
);
10260 if (tmp_value
== TX_IDLE
){ /* bus master get suspended TCB */
10263 /* Tx bus master is in idle state. */
10264 //tmpValue1 = zd_readl(InterruptCtrl);
10265 /* No retry fail happened */
10266 tmp_value3
= zd_readl(ReadTcbAddress
);
10267 next_sw_tcb
= macp
->freeTxQ
->first
;
10269 if (tmp_value3
!= le32_to_cpu(next_sw_tcb
->pTcb
->NextCbPhyAddrLowPart
)){
10270 /* Restart Tx again */
10271 zd1205_start_download(sw_tcb
->TcbPhys
);
10272 ZD1211DEBUG(1, "zd1211: Write PCI_TxAddr_p1 = %x\n", sw_tcb
->TcbPhys
);
10276 else if (tmp_value
== 0xA){ //Dtim Notify Int happened
10277 zd1205_start_download(sw_tcb
->TcbPhys
| BIT_0
);
10280 ZD1211DEBUG(2, "zd1211: NAV_CCA = %x\n", zd_readl(NAV_CCA
));
10281 ZD1211DEBUG(2, "zd1211: NAC_CNT = %x\n", zd_readl(NAV_CNT
));
10285 zd1205_qlast_txq(macp
, macp
->activeTxQ
, sw_tcb
);
10288 if(wla_hdr
->FrameCtrl
[0] == PS_POLL
)
10290 if((*(U16
*)wla_hdr
->Duration
) == 0)
10291 printk("AAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBB\n");
10294 //The following code is to handle cross fragment MIC
10295 memcpy(sw_tcb
->CalMIC
,frag_info
->CalSwMic
, MIC_LNG
+1);
10296 sw_tcb
->MIC_Start
=0;
10298 if(i
==numOfFrag
-1 && sw_tcb
->CalMIC
[MIC_LNG
]==TRUE
) {
10299 if(frag_info
->bodyLen
[i
] < MIC_LNG
) {
10300 sw_tcb
->MIC_Start
=MIC_LNG
-frag_info
->bodyLen
[i
];
10301 sw_tcb
->MIC_Len
=frag_info
->bodyLen
[i
];
10304 sw_tcb
->MIC_Start
=0;
10305 sw_tcb
->MIC_Len
=MIC_LNG
;
10307 zd1211_submit_tx_urb(macp
,TRUE
);
10309 else if(sw_tcb
->CalMIC
[MIC_LNG
] == TRUE
&& (i
== numOfFrag
-2)) {
10310 if(frag_info
->bodyLen
[i
+1] < MIC_LNG
) {
10311 sw_tcb
->MIC_Start
=0;
10312 sw_tcb
->MIC_Len
=MIC_LNG
-frag_info
->bodyLen
[i
+1];
10315 sw_tcb
->MIC_Start
=0;
10318 zd1211_submit_tx_urb(macp
,TRUE
);
10321 zd1211_submit_tx_urb(macp
,FALSE
);
10322 //zd1205_tx_isr(macp); //for debug only
10324 g_dev
->trans_start
= jiffies
;
10325 macp
->TxStartTime
= nowT();
10326 ZD1211DEBUG(2, "zd1211: Cnt of activeQ = %x\n", macp
->activeTxQ
->count
);
10329 #ifndef HOST_IF_USB
10330 spin_unlock_irqrestore(&macp
->bd_non_tx_lock
, lock_flag
);
10333 ZD1211DEBUG(2, "===== zdcb_setup_next_send exit =====\n");
10337 void zdcb_release_buffer(void *buf
)
10339 struct sk_buff
*skb
= (struct sk_buff
*)buf
; if (skb
)
10340 dev_kfree_skb_any(skb
);
10341 //dev_kfree_skb_irq(skb);
10344 void zdcb_rx_ind(U8
*pData
, U32 length
, void *buf
, U32 LP_MAP
)
10346 struct zd1205_private
*macp
= g_dev
->priv
;
10347 struct sk_buff
*skb1
= (struct sk_buff
*)buf
;
10348 struct sk_buff
*skb
= NULL
;
10349 U32 i
,dataOff
=0, pktLen
=0,j
=0;
10356 #if ZDCONF_LP_SUPPORT == 1
10358 //for(i=0;i<be16_to_cpu(*(U16 *)pData);i++) {
10359 length
-=2; //Ignore QoS Ctrl
10364 // Not used for general Driver
10365 if(loopCheck
++ > 100)
10367 printk("infinite loop occurs in %s\n", __FUNCTION__
);
10373 pktLen
= be16_to_cpu(*(U16
*)(pData
+dataOff
+12));
10374 //if(memcmp(pData+dataOff, ZD_DROPIT_TAG,6) != 0)
10375 if(LP_MAP
& ( BIT_0
<<(wCnt
-1) ) )
10378 if(dataOff
>= length
) break;
10379 dataOff
+= (4-(dataOff
% 4))%4;
10382 if(totalValid
== 0)
10384 if(skb
)dev_kfree_skb_any
/*irq*/(skb
);
10390 // Not used for General Driver
10391 if(loopCheck
++ > 100)
10393 printk("infinite loop occurs in %s\n", __FUNCTION__
);
10399 pktLen
= be16_to_cpu(*(U16
*)(pData
+dataOff
+12));
10400 //if(memcmp(pData+dataOff, ZD_DROPIT_TAG,6) == 0)
10401 if(!(LP_MAP
& ( BIT_0
<<(wCnt
-1) ) ))
10404 if(dataOff
>= length
) break;
10405 dataOff
+= (4-(dataOff
% 4))%4;
10409 if(dataOff
+ pktLen
!= length
) {
10410 skb
= skb_clone(skb1
,GFP_ATOMIC
);
10411 if(skb
== NULL
) printk(KERN_ERR
"### skb NULL ##\n");
10416 if(dataOff
+pktLen
> length
) {
10417 printk("** pData+dataOff **\n");
10418 for(i
=-15;i
<20;i
++)
10419 printk("%02x ", *(pData
+dataOff
+i
));
10420 printk("** pData **\n");
10421 for(i
=-15;i
<26;i
++)
10422 printk("%02x ", *(pData
+i
));
10425 printk("%ldth,Wrong !! dataOff+pktLen > length\n,%ld,%ld",j
,dataOff
+pktLen
,length
);
10428 memcpy(pData
+dataOff
+14, pData
+dataOff
+6,6);
10429 memcpy(pData
+dataOff
+8, pData
+dataOff
,6);
10430 skb
->tail
= skb
->data
= pData
+dataOff
+8;
10431 skb_put(skb
, pktLen
-8);
10432 skb
->protocol
= eth_type_trans(skb
, g_dev
);
10433 skb
->ip_summed
= CHECKSUM_NONE
; //TBD
10434 g_dev
->last_rx
= jiffies
;
10436 switch(netif_rx(skb
))
10440 case NET_RX_CN_MOD
:
10441 case NET_RX_CN_HIGH
:
10444 macp
->drv_stats
.net_stats
.rx_packets
++;
10445 macp
->drv_stats
.net_stats
.rx_bytes
+= skb
->len
;
10449 if(dataOff
>= length
) break;
10450 dataOff
+= (4-(dataOff
% 4))%4;
10451 if(totalValid
== 0) return;
10457 //copy packet for IP header is located on 4-bytes alignment
10458 if (length
< RX_COPY_BREAK
){
10459 dev_kfree_skb_any
/*irq*/(skb
);
10460 skb
= dev_alloc_skb(length
+2);
10464 skb_reserve(skb
, 2);
10465 eth_copy_and_sum(skb
, pData
, length
, 0);
10467 skb_put(skb
, length
);
10471 skb
->tail
= skb
->data
= pData
;
10472 skb_put(skb
, length
);
10475 //zd1205_dump_data("rx_ind", (U8 *)skb->data, skb->len);
10477 ZD1211DEBUG(2, "zd1211: rx_ind length = %x\n", (u32
)length
);
10479 /* set the protocol */
10480 skb
->protocol
= eth_type_trans(skb
, g_dev
);
10481 skb
->ip_summed
= CHECKSUM_NONE
; //TBD
10482 g_dev
->last_rx
= jiffies
;
10484 switch(netif_rx(skb
)){
10487 case NET_RX_CN_MOD
:
10488 case NET_RX_CN_HIGH
:
10492 macp
->drv_stats
.net_stats
.rx_packets
++;
10493 macp
->drv_stats
.net_stats
.rx_bytes
+= skb
->len
;
10499 U16
zdcb_status_notify(U16 status
, U8
*StaAddr
)
10501 struct zd1205_private
*macp
= g_dev
->priv
;
10512 case STA_REASOC_REQ
:
10515 case STA_ASSOCIATED
:
10516 case STA_REASSOCIATED
:
10519 iLED_ON(macp
, macp
->LinkLEDn
);
10521 macp
-> LinkTimer
= 0;
10523 if (macp
->DataLED
== 0){
10525 zd_writel(0x03, FW_LINK_STATUS
);
10527 zd_writel(0x01, FW_LINK_STATUS
);
10531 zd_writel(0x00, FW_LINK_STATUS
);
10533 memcpy(&macp
->BSSID
[0], StaAddr
, 6);
10535 //if (macp->cardSetting.BssType == INFRASTRUCTURE_BSS)
10536 if (macp
->cardSetting
.BssType
!= AP_BSS
)
10538 netif_wake_queue(macp
->device
);
10539 netif_carrier_on(macp
->device
);
10542 if (status
== STA_ASSOCIATED
)
10544 ZD1211DEBUG(0, "STA_ASSOCIATED with " MACSTR
"\n", MAC2STR(StaAddr
));
10549 ZD1211DEBUG(0, "STA_REASSOCIATED with " MACSTR
"\n", MAC2STR(StaAddr
));
10551 /* Generate a wireless event to the upper layer */
10552 if(test_and_clear_bit(CTX_FLAG_ESSID_WAS_SET
, (void*)&macp
->flags
))
10554 zd1205_notify_join_event(macp
);
10559 case STA_DISASSOCIATED
:
10561 #ifndef HOST_IF_USB
10562 iLED_OFF(macp
, LED1
);
10564 zd_writel(0x0, FW_LINK_STATUS
);
10568 if (macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
)
10570 union iwreq_data wreq
;
10571 memset(&wreq
, 0, sizeof(wreq
));
10572 wreq
.addr
.sa_family
=ARPHRD_ETHER
;
10573 wireless_send_event(macp
->device
, SIOCGIWAP
,&wreq
, NULL
);
10574 memset(&macp
->BSSID
[0], 0, 6);
10575 netif_stop_queue(macp
->device
);
10576 //zd1205_dis_connect(macp);
10577 netif_carrier_off(macp
->device
);
10579 if (status
== STA_DISASSOCIATED
)
10580 ZD1211DEBUG(0, "STA_DISASSOCIATED:" MACSTR
"\n",MAC2STR(StaAddr
));
10582 ZD1211DEBUG(0, "STA_DEAUTHED:" MACSTR
"\n",MAC2STR(StaAddr
));
10594 void zdcb_tx_completed(void)
10599 void chal_tout_cb(unsigned long ptr
)
10602 struct zd1205_private
*macp
= g_dev
->priv
;
10603 defer_kevent(macp
, KEVENT_TCHAL_TIMEOUT
);
10605 zd_EventNotify(EVENT_TCHAL_TIMEOUT
, 0, 0, 0);
10609 void scan_tout_cb(unsigned long ptr
)
10612 struct zd1205_private
*macp
= g_dev
->priv
;
10613 defer_kevent(macp
, KEVENT_SCAN_TIMEOUT
);
10615 zd_EventNotify(EVENT_SCAN_TIMEOUT
, 0, 0, 0);
10619 void asoc_tout_cb(unsigned long ptr
)
10622 struct zd1205_private
*macp
= g_dev
->priv
;
10623 defer_kevent(macp
, KEVENT_AUTH_TIMEOUT
);
10625 zd_EventNotify(EVENT_ASOC_TIMEOUT
, 0, 0, 0);
10629 void auth_tout_cb(unsigned long ptr
)
10632 struct zd1205_private
*macp
= g_dev
->priv
;
10633 defer_kevent(macp
, KEVENT_AUTH_TIMEOUT
);
10635 zd_EventNotify(EVENT_AUTH_TIMEOUT
, 0, 0, 0);
10639 void zdcb_start_timer(U32 timeout
, U32 event
)
10641 struct zd1205_private
*macp
= g_dev
->priv
;
10642 u32 timeout_in_jiffies
;
10643 if (!macp
->bUSBDeveiceAttached
)
10645 timeout_in_jiffies
= (timeout
*HZ
)/1000; // Conver ms to jiffies
10649 init_timer(&macp
->tm_chal_id
);
10650 macp
->tm_chal_id
.data
= (unsigned long) g_dev
;
10651 macp
->tm_chal_id
.expires
= jiffies
+ timeout_in_jiffies
;
10652 macp
->tm_chal_id
.function
= chal_tout_cb
;
10653 add_timer(&macp
->tm_chal_id
);
10657 init_timer(&macp
->tm_scan_id
);
10658 macp
->tm_scan_id
.data
= (unsigned long) g_dev
;
10659 macp
->tm_scan_id
.expires
= jiffies
+ timeout_in_jiffies
;
10660 macp
->tm_scan_id
.function
= scan_tout_cb
;
10661 add_timer(&macp
->tm_scan_id
);
10666 init_timer(&macp
->tm_auth_id
);
10667 macp
->tm_auth_id
.data
= (unsigned long) g_dev
;
10668 macp
->tm_auth_id
.expires
= jiffies
+ timeout_in_jiffies
;
10669 macp
->tm_auth_id
.function
= auth_tout_cb
;
10670 add_timer(&macp
->tm_auth_id
);
10674 if(AsocTimerStat
) {
10675 del_timer_sync(&macp
->tm_asoc_id
);
10676 AsocTimerStat
= FALSE
;
10678 init_timer(&macp
->tm_asoc_id
);
10679 macp
->tm_asoc_id
.data
= (unsigned long) g_dev
;
10680 macp
->tm_asoc_id
.expires
= jiffies
+ timeout_in_jiffies
;
10681 macp
->tm_asoc_id
.function
= asoc_tout_cb
;
10682 add_timer(&macp
->tm_asoc_id
);
10683 AsocTimerStat
= TRUE
;
10692 void zdcb_stop_timer(U32 TimerId
)
10694 struct zd1205_private
*macp
= g_dev
->priv
;
10698 del_timer(&macp
->tm_chal_id
);
10702 if(macp
->tm_auth_id
.magic
== TIMER_MAGIC
)
10703 del_timer(&macp
->tm_auth_id
);
10708 del_timer(&macp
->tm_asoc_id
);
10709 AsocTimerStat
= FALSE
;
10719 zdcb_dis_intr(void)
10721 struct zd1205_private
*macp
= g_dev
->priv
;
10724 #if 1//ndef HOST_IF_USB
10725 if(!in_irq())spin_lock_irqsave(&macp
->cs_lock
, flags
);
10727 spin_lock(&macp
->cs_lock
);
10733 zdcb_set_intr_mask(U32 flags
)
10735 struct zd1205_private
*macp
= g_dev
->priv
;
10737 #if 1//ndef HOST_IF_USB
10738 if(!in_irq())spin_unlock_irqrestore(&macp
->cs_lock
, flags
);
10740 spin_unlock(&macp
->cs_lock
);
10744 U32
zdcb_vir_to_phy_addr(U32 virtAddr
) //TBD
10749 void zdcb_set_reg(void *reg
, U32 offset
, U32 value
)
10751 zd_writel(value
, offset
);
10754 U32
zdcb_get_reg(void *reg
, U32 offset
)
10756 return zd_readl(offset
);
10760 zdcb_check_tcb_avail(U8 num_of_frag
)
10762 struct zd1205_private
*macp
= g_dev
->priv
;
10767 if(!in_irq())spin_lock_irqsave(&macp
->q_lock
, flags
);
10768 if (macp
->freeTxQ
->count
< (num_of_frag
+1))
10773 if(!in_irq())spin_unlock_irqrestore(&macp
->q_lock
, flags
);
10778 void zdcb_delay_us(U32 ustime
)
10780 struct zd1205_private
*macp
=g_dev
->priv
;
10781 //Convert microseconds to jiffies. 20060809 MZCai
10782 U32 delay_ms
= ustime
/1000;
10783 U32 delay_jiffies
= delay_ms
/ (1000/HZ
);
10784 if(delay_jiffies
== 0) delay_jiffies
= 1;
10786 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
10787 wait_event_interruptible_timeout(macp
->msdelay
, 0, delay_jiffies
);
10789 interruptible_sleep_on_timeout(&macp
->msdelay
, delay_jiffies
);
10795 void * zdcb_AllocBuffer(U16 dataSize
, U8
**pData
)
10797 struct sk_buff
*new_skb
= NULL
;
10799 new_skb
= (struct sk_buff
*) dev_alloc_skb(dataSize
);
10801 *pData
= new_skb
->data
;
10804 return (void *)new_skb
;
10807 unsigned long int next
= 1;
10809 int zdcb_Rand(U32 seed
)
10811 static int first
= 1;
10818 next
= next
* 1103515245 + 12345;
10819 return ((unsigned int)(next
/65535)%32768);
10822 void zdcb_AcquireDoNotSleep(void)
10824 struct zd1205_private
*macp
= g_dev
->priv
;
10825 atomic_inc(&macp
->DoNotSleep
);
10828 void zdcb_ReleaseDoNotSleep(void)
10830 struct zd1205_private
*macp
= g_dev
->priv
;
10831 atomic_dec(&macp
->DoNotSleep
);
10833 #ifdef HOSTAPD_SUPPORT
10835 In this callback function, we just copy the WPA IE into the
10836 field of each STA's hash_t entry. The behavior is for the hostapd.
10839 int zdcb_AssocRequest(U8
*addr
, U8
*WPAIE
, U16 size
)
10843 if (mCounterMeasureState
)
10846 printk(KERN_DEBUG
"---------In CounterMeasure state, fail AssocReqest\n");
10850 pHash
= HashSearch((MacAddr_t
*)addr
);
10852 /* Can't search the MAC address in the hash table. */
10856 memcpy(&pHash
->WPAIE
, WPAIE
, sizeof(pHash
->WPAIE
));
10861 void zdcb_MicFailure(unsigned char *addr
)
10863 union iwreq_data wrqu
;
10866 /* TODO: needed parameters: count, keyid, key type, src address, TSC */
10868 printk(KERN_ERR
"MLME-MICHAELMICFAILURE.indication addr=" MACSTR
"\n", MAC2STR(addr
));
10870 memset(&wrqu
, 0, sizeof(wrqu
));
10871 wrqu
.data
.length
= strlen(buf
);
10872 wireless_send_event(g_dev
, IWEVCUSTOM
, &wrqu
, buf
);
10877 //setup callback functions for protocol stack
10878 void zd1205_set_zd_cbs(zd_80211Obj_t
*pObj
)
10880 pObj
->QueueFlag
= 0;
10881 pObj
->ConfigFlag
= 0;
10882 pObj
->SetReg
= zdcb_set_reg
;
10883 pObj
->GetReg
= zdcb_get_reg
;
10885 pObj
->ReleaseBuffer
= zdcb_release_buffer
;
10886 pObj
->RxInd
= zdcb_rx_ind
;
10887 pObj
->TxCompleted
= zdcb_tx_completed
;
10888 pObj
->StartTimer
= zdcb_start_timer
;
10889 pObj
->StopTimer
= zdcb_stop_timer
;
10890 pObj
->SetupNextSend
= zdcb_setup_next_send
;
10892 pObj
->StatusNotify
= zdcb_status_notify
;
10893 pObj
->ExitCS
= zdcb_set_intr_mask
;
10894 pObj
->EnterCS
= zdcb_dis_intr
;
10895 pObj
->Vir2PhyAddr
= zdcb_vir_to_phy_addr
;
10896 pObj
->CheckTCBAvail
= zdcb_check_tcb_avail
;
10897 pObj
->DelayUs
= zdcb_delay_us
;
10898 pObj
->AllocBuffer
= zdcb_AllocBuffer
;
10899 pObj
->Rand
= zdcb_Rand
;
10900 pObj
->AcquireDoNotSleep
= zdcb_AcquireDoNotSleep
;
10901 pObj
->ReleaseDoNotSleep
= zdcb_ReleaseDoNotSleep
;
10902 pObj
->bChScanning
=0;
10905 #ifdef HOSTAPD_SUPPORT
10906 pObj
->MicFailure
= zdcb_MicFailure
;
10907 pObj
->AssocRequest
= zdcb_AssocRequest
;
10908 pObj
->WpaIe
= NULL
;
10911 pObj
->MicFailure
= NULL
;
10912 pObj
->AssocRequest
= NULL
;
10913 pObj
->WpaIe
= NULL
;
10918 void zd1205_SetRatesInfo(struct zd1205_private
*macp
)
10922 card_Setting_t
*pCardSetting
;
10924 pCardSetting
= &macp
->cardSetting
;
10926 if (pCardSetting
->MacMode
== MIXED_MODE
){
10927 ZD1211DEBUG(0, "Mixed Mode\n");
10928 zd_writel(CW_SHORT_SLOT
, CWmin_CWmax
);
10929 pCardSetting
->ShortSlotTime
= 1;
10930 pCardSetting
->PreambleType
= 1; //short preamble
10933 else if (pCardSetting
->MacMode
== PURE_G_MODE
){
10934 ZD1211DEBUG(0, "Pure G-Mode\n");
10935 zd_writel(CW_SHORT_SLOT
, CWmin_CWmax
);
10936 pCardSetting
->ShortSlotTime
= 1;
10937 pCardSetting
->PreambleType
= 1; //short preamble
10940 else if (pCardSetting
->MacMode
== PURE_A_MODE
) {
10941 ZD1211DEBUG(0, "Pure A-Mode\n");
10942 zd_writel(CW_SHORT_SLOT
, CWmin_CWmax
);
10943 pCardSetting
->ShortSlotTime
= 1;
10944 pCardSetting
->PreambleType
= 1; //short preamble
10948 else if (pCardSetting
->MacMode
== PURE_B_MODE
) { // pure B mode
10949 ZD1211DEBUG(0, "Pure B-Mode\n");
10950 zd_writel(CW_NORMAL_SLOT
, CWmin_CWmax
);
10951 pCardSetting
->ShortSlotTime
= 0;
10952 pCardSetting
->PreambleType
= 1; //short preamble
10958 if (bRatesSet
== 1){ //wi-fi set1
10960 pCardSetting
->Info_SupportedRates
[0] = 0x01;
10961 pCardSetting
->Info_SupportedRates
[1] = 0x04;
10962 pCardSetting
->Info_SupportedRates
[2] = 0x82; //basic rate
10963 pCardSetting
->Info_SupportedRates
[3] = 0x84; //basic rate
10964 pCardSetting
->Info_SupportedRates
[4] = 0x8B; //basic rate
10965 pCardSetting
->Info_SupportedRates
[5] = 0x96; //basic rate
10967 //Extended supported rates
10968 pCardSetting
->Ext_SupportedRates
[0] = 0x32;
10969 pCardSetting
->Ext_SupportedRates
[1] = 0x08;
10970 pCardSetting
->Ext_SupportedRates
[2] = 0x0c;
10971 pCardSetting
->Ext_SupportedRates
[3] = 0x12;
10972 pCardSetting
->Ext_SupportedRates
[4] = 0x18;
10973 pCardSetting
->Ext_SupportedRates
[6] = 0x24;
10974 pCardSetting
->Ext_SupportedRates
[7] = 0x30;
10975 pCardSetting
->Ext_SupportedRates
[8] = 0x48;
10976 pCardSetting
->Ext_SupportedRates
[5] = 0x60;
10977 pCardSetting
->Ext_SupportedRates
[9] = 0x6c;
10978 zd_writel(0x150f, MandatoryRateTbl
); //1,2,5.5,11,6,12,24
10980 else if (bRatesSet
== 2){ //wi-fi set2
10982 pCardSetting
->Info_SupportedRates
[0] = 0x01;
10983 pCardSetting
->Info_SupportedRates
[1] = 0x04;
10984 pCardSetting
->Info_SupportedRates
[2] = 0x82; //basic rate
10985 pCardSetting
->Info_SupportedRates
[3] = 0x84; //basic rate
10986 pCardSetting
->Info_SupportedRates
[4] = 0x8B; //basic rate
10987 pCardSetting
->Info_SupportedRates
[5] = 0x96; //basic rate
10989 //Extended supported rates
10990 pCardSetting
->Ext_SupportedRates
[0] = 0x32;
10991 pCardSetting
->Ext_SupportedRates
[1] = 0x08;
10992 pCardSetting
->Ext_SupportedRates
[2] = 0x8c; //basic rate
10993 pCardSetting
->Ext_SupportedRates
[3] = 0x12;
10994 pCardSetting
->Ext_SupportedRates
[4] = 0x98; //basic rate
10995 pCardSetting
->Ext_SupportedRates
[6] = 0x24;
10996 pCardSetting
->Ext_SupportedRates
[7] = 0xb0; //basic rate
10997 pCardSetting
->Ext_SupportedRates
[8] = 0x48;
10998 pCardSetting
->Ext_SupportedRates
[5] = 0x60;
10999 pCardSetting
->Ext_SupportedRates
[9] = 0x6c;
11001 zd_writel(0x150f, MandatoryRateTbl
); //1,2,5.5,11,6,12,24
11003 else if (bRatesSet
== 3){ //pure b mode
11005 pCardSetting
->Info_SupportedRates
[0] = 0x01;
11006 pCardSetting
->Info_SupportedRates
[1] = 0x04;
11007 pCardSetting
->Info_SupportedRates
[2] = 0x82; //basic rate
11008 pCardSetting
->Info_SupportedRates
[3] = 0x84; //basic rate
11009 pCardSetting
->Info_SupportedRates
[4] = 0x8B; //basic rate
11010 pCardSetting
->Info_SupportedRates
[5] = 0x96; //basic rate
11011 zd_writel(0x0f, MandatoryRateTbl
); //1,2,5.5,11
11013 else if (bRatesSet
== 4) {//Pure A
11014 pCardSetting
->Info_SupportedRates
[0] = 0x01; //Element ID
11015 pCardSetting
->Info_SupportedRates
[1] = 0x08; //Rates Amount
11016 pCardSetting
->Info_SupportedRates
[2] = 0x80+12 ; //RateByte = Mandatory Bit + 500k x 12
11017 pCardSetting
->Info_SupportedRates
[3] = 0x00+18; //Supported Rate
11018 pCardSetting
->Info_SupportedRates
[4] = 0x80+24; //basic rate
11019 pCardSetting
->Info_SupportedRates
[5] = 0x00+36;
11020 pCardSetting
->Info_SupportedRates
[6] = 0x80+48; //basic rate
11021 pCardSetting
->Info_SupportedRates
[7] = 0x00+72;
11022 pCardSetting
->Info_SupportedRates
[8] = 0x00+96;
11023 pCardSetting
->Info_SupportedRates
[9] = 0x00+108;
11025 zd_writel(0x0f, MandatoryRateTbl); //6,9,12,18,24,36,48,54
11026 ==================*/
11027 //prince add for ZYDAS 1211_PRE2
11028 zd_writel(0x1500, MandatoryRateTbl
); //6,9,12,18,24,36,48,54
11036 u16 ZDLOGTEN
[] = {0,
11037 0 , 30 , 47 , 60 , 69 , 77 , 84 , 90 , 95 , 100 ,
11038 104 , 107 , 111 , 114 , 117 , 120 , 123 , 125 , 127 , 130 ,
11039 132 , 134 , 136 , 138 , 139 , 141 , 143 , 144 , 146 , 147 ,
11040 149 , 150 , 151 , 153 , 154 , 155 , 156 , 157 , 159 , 160 ,
11041 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 169 ,
11042 170 , 171 , 172 , 173 , 174 , 174 , 175 , 176 , 177 , 177 ,
11043 178 , 179 , 179 , 180 , 181 , 181 , 182 , 183 , 183 , 184 ,
11044 185 , 185 , 186 , 186 , 187 , 188 , 188 , 189 , 189 , 190 ,
11045 190 , 191 , 191 , 192 , 192 , 193 , 193 , 194 , 194 , 195 ,
11046 195 , 196 , 196 , 197 , 197 , 198 , 198 , 199 , 199 , 200 ,
11047 200 , 200 , 210 , 210 , 220 , 220 , 220 , 230 , 230 , 240 ,
11048 240 , 240 , 250 , 250 , 260 , 260 , 260 , 270 , 270 , 270 ,
11049 280 , 280 , 280 , 290 , 290 , 210 , 210 , 210 , 211 , 211 ,
11050 211 , 212 , 212 , 212 , 213 , 213 , 213 , 213 , 214 , 214 ,
11051 214 , 215 , 215 , 215 , 216 , 216 , 216 , 217 , 217 , 217 ,
11052 217 , 218 , 218 , 218 , 219 , 219 , 219 , 219 , 220 , 220 ,
11053 220 , 220 , 221 , 221 , 221 , 222 , 222 , 222 , 222 , 223 ,
11054 223 , 223 , 223 , 224 , 224 , 224 , 224 , 225 , 225 , 225 ,
11059 ZDLog10multiply100(int data
)
11061 if ((data
>= 0) && (data
<= 0xb5))
11062 return ZDLOGTEN
[data
];
11069 u32 X_Constant
[] = {
11070 715, 655, 585, 540, 470, 410, 360, 315,
11071 270, 235, 205, 175, 150, 125, 105, 85,
11077 u8
X_To_dB(u32 X
, u8 rate
)
11082 int SizeOfX_Con
= sizeof(X_Constant
);
11105 for (i
=0; i
<SizeOfX_Con
; i
++){
11106 if (X
> X_Constant
[i
])
11134 u8
CalculateQuality(struct zd1205_private
*macp
, zd1205_RFD_t
*rfd
, u8
*pQualityIndB
)
11136 u8 CorrectQuality
= 0;
11137 plcp_wla_Header_t
*wla_hdr
;
11138 u32 frame_len
,tot_len
;
11139 u8 SignalQuality2
= macp
->rxSignalQuality2
;
11142 u8 rxOffset
= macp
->rxOffset
;
11144 wla_hdr
= (plcp_wla_Header_t
*)&rfd
->RxBuffer
[macp
->rxOffset
];
11145 tot_len
= rfd
->ActualCount
& 0x3fff;
11146 frame_len
= tot_len
- EXTRA_INFO_LEN
;
11147 SignalQuality2
= rfd
->RxBuffer
[frame_len
+2];
11151 if (rfd
->RxBuffer
[tot_len
-1] & 0x01){
11153 macp
->rxOFDMDataFrame
++;
11155 X
= 10000 * SignalQuality2
/ (frame_len
- macp
->rxOffset
);
11156 CorrectQuality
= X_To_dB(X
, wla_hdr
->PlcpHdr
[0] & 0xF);
11159 *pQualityIndB
= CorrectQuality
;
11161 CorrectQuality
= (CorrectQuality
+0)* 4;
11162 if (CorrectQuality
> 100)
11163 CorrectQuality
= 100;
11167 macp
->rx11bDataFrame
++;
11169 // the value from PHY is in scale from Max is 0 and Min is 0xb5
11170 switch(wla_hdr
->PlcpHdr
[0]){
11177 if (macp
->rxSignalQuality1
> 0)
11178 tmpf
= (u16
)(ZDLog10multiply100(macp
->rxSignalQuality1
) * 20 /100);
11179 CorrectQuality
= 45 - (u8
)(tmpf
);
11182 *pQualityIndB
= CorrectQuality
;
11184 CorrectQuality
= (CorrectQuality
+5) * 4;
11186 if (CorrectQuality
> 100)
11187 CorrectQuality
= 100;
11197 return CorrectQuality
;
11200 u8
CalculateStrength(struct zd1205_private
*macp
, zd1205_RFD_t
*rfd
)
11202 // return in ? , the Value-105 = dB
11203 // the value from PHY is in ?
11208 plcp_wla_Header_t
*wla_hdr
;
11209 //u8 rxOffset = macp->rxOffset;
11211 wla_hdr
= (plcp_wla_Header_t
*)&rfd
->RxBuffer
[macp
->rxOffset
];
11212 tot_len
= rfd
->ActualCount
& 0x3fff;
11213 frame_len
= tot_len
- EXTRA_INFO_LEN
;
11214 rssi
= rfd
->RxBuffer
[frame_len
+1];
11216 if ( (((macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
)&&
11217 (!memcmp(wla_hdr
->Address2
, macp
->BSSID
, 6))) ||
11218 ((macp
->cardSetting
.BssType
== INDEPENDENT_BSS
)&&
11219 (!memcmp(wla_hdr
->Address3
, macp
->BSSID
, 6))) ||
11220 (macp
->cardSetting
.BssType
== PSEUDO_IBSS
)) &&
11222 for(i
=0; i
<macp
->PHYTestIndex
-1; i
++)
11225 //if ( (dot11Obj.CR122Flag == 1)||(dot11Obj.CR203Flag == 1) )
11227 tmp
= macp
->PHYTestRssi
;
11228 macp
->PHYTestTotal
= macp
->PHYTestTotal
11229 - (macp
->PHYTestTotal
/tmpvalue
)
11231 macp
->PHYTestRssi
= (u8
) (macp
->PHYTestTotal
/tmpvalue
);
11237 void zd1205_initCAM(struct zd1205_private
*macp
)
11241 zd_writel(0, CAM_ROLL_TB_LOW
);
11242 zd_writel(0, CAM_ROLL_TB_HIGH
);
11244 for (i
=0; i
<445; i
++){
11245 HW_CAM_Write(&dot11Obj
, i
, 0);
11249 int zd1205_CheckOverlapBss(struct zd1205_private
*macp
, plcp_wla_Header_t
*pWlanHdr
, u8
*pMacBody
, u32 bodyLen
)
11253 u8 elemId
, elemLen
;
11259 pByte
= pMacBody
+SSID_OFFSET
;
11260 currPos
= SSID_OFFSET
;
11262 while(currPos
< bodyLen
)
11264 //To prevent incorrect elemLen (ex. 0)
11265 if(loopCheck
++ > 100)
11267 printk("infinite loop occurs in %s\n", __FUNCTION__
);
11273 elemLen
= *(pByte
+1);
11276 case ELEID_ERP_INFO
: //ERP info
11278 ErpInfo
= *(pByte
+2);
11279 pByte
+= (elemLen
+2);
11283 pByte
+= (elemLen
+2);
11288 currPos
+= elemLen
+2;
11292 if (ErpInfo
& NON_ERP_PRESENT_BIT
){ //with B sta associated
11298 else // B AP exist, enable protection mode
11302 void zd1205_HandleQosRequest(struct zd1205_private
*macp
)
11304 zd1205_SwTcb_t
*sw_tcb
;
11306 if (!macp
->activeTxQ
->count
)
11307 sw_tcb
= macp
->freeTxQ
->first
;
11309 sw_tcb
= macp
->activeTxQ
->first
;
11310 zd1205_start_download(sw_tcb
->TcbPhys
| BIT_0
);
11314 * zd1205_notify_join_event - Notify wireless join event to the upper layer
11315 * @macp: atapter's private data struct
11316 * @newassoc: new associate or not
11320 void zd1205_notify_join_event(struct zd1205_private
*macp
)
11322 union iwreq_data wreq
;
11324 memset(&wreq
, 0, sizeof(wreq
));
11325 memcpy(wreq
.addr
.sa_data
, &macp
->BSSID
[0], 6);
11326 wreq
.addr
.sa_family
= ARPHRD_ETHER
;
11329 ZD1211DEBUG(0, "Notify_join_event:" MACSTR
"\n",MAC2STR(macp
->BSSID
));
11332 WPADEBUG("zd1205_notfiy_join_event: MAC= ");
11333 for(ii = 0; ii < 6; ii++)
11334 WPADEBUG("%02x ", macp->BSSID[ii] & 0xff);
11338 if(macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
) {
11339 wireless_send_event(macp
->device
, SIOCGIWAP
, &wreq
, NULL
);
11341 #if WIRELESS_EXT >= 15
11342 else if(macp
->cardSetting
.BssType
== AP_BSS
) {
11343 wireless_send_event(macp
->device
, IWEVREGISTERED
, &wreq
, NULL
);
11347 void zd1205_notify_disjoin_event(struct zd1205_private
*macp
)
11349 union iwreq_data wreq
;
11351 memset(&wreq
, 0, sizeof(wreq
));
11352 //memcpy(wreq.addr.sa_data, &macp->BSSID[0], 6);
11353 wreq
.addr
.sa_family
= ARPHRD_ETHER
;
11354 printk(KERN_DEBUG
"zd1205_notify_disjoin_event\n");
11358 WPADEBUG("zd1205_notfiy_join_event: MAC= ");
11359 for(ii = 0; ii < 6; ii++)
11360 WPADEBUG("%02x ", macp->BSSID[ii] & 0xff);
11364 if(macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
) {
11365 //wireless_send_event(macp->device, SIOCGIWSCAN, &wreq, NULL);
11366 wireless_send_event(macp
->device
, SIOCGIWAP
, &wreq
, NULL
);
11368 /*#if WIRELESS_EXT >= 15
11369 else if(macp->cardSetting.BssType == AP_BSS) {
11370 wireless_send_event(macp->device, IWEVREGISTERED, &wreq, NULL);
11374 void zd1205_notify_scan_done(struct zd1205_private
*macp
)
11376 union iwreq_data wreq
;
11377 wreq
.data
.length
= 0;
11378 wreq
.data
.flags
= 0;
11379 wireless_send_event(macp
->device
, SIOCGIWSCAN
, &wreq
, NULL
);
11381 #if WIRELESS_EXT >= 18
11382 void hostap_michael_mic_failure(struct zd1205_private
*macp
,
11383 struct hostap_ieee80211_hdr
*hdr
,
11386 union iwreq_data wrqu
;
11387 struct iw_michaelmicfailure ev
;
11389 /* TODO: needed parameters: count, keyid, key type, TSC */
11390 memset(&ev
, 0, sizeof(ev
));
11391 ev
.flags
= keyidx
& IW_MICFAILURE_KEY_ID
;
11392 if (hdr
->addr1
[0] & 0x01)
11393 ev
.flags
|= IW_MICFAILURE_GROUP
;
11395 ev
.flags
|= IW_MICFAILURE_PAIRWISE
;
11396 ev
.src_addr
.sa_family
= ARPHRD_ETHER
;
11397 memcpy(ev
.src_addr
.sa_data
, hdr
->addr2
, ETH_ALEN
);
11398 memset(&wrqu
, 0, sizeof(wrqu
));
11399 wrqu
.data
.length
= sizeof(ev
);
11400 wireless_send_event(g_dev
, IWEVMICHAELMICFAILURE
, &wrqu
, (char *) &ev
);
11402 #elif WIRELESS_EXT >= 15
11403 // For kernel 2.6.5(FC2), WIRELESS_EXT is 16
11404 void hostap_michael_mic_failure(struct zd1205_private
*macp
,
11405 struct hostap_ieee80211_hdr
*hdr
,
11408 union iwreq_data wrqu
;
11411 /* TODO: needed parameters: count, keyid, key type, TSC */
11412 sprintf(buf
, "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr="
11413 MACSTR
")", keyidx
, hdr
->addr1
[0] & 0x01 ? "broad" : "uni",
11414 MAC2STR(hdr
->addr2
));
11415 memset(&wrqu
, 0, sizeof(wrqu
));
11416 wrqu
.data
.length
= strlen(buf
);
11417 printk("MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr="
11418 MACSTR
")", keyidx
, hdr
->addr1
[0] & 0x01 ? "broad" : "uni",
11419 MAC2STR(hdr
->addr2
));
11420 wireless_send_event(g_dev
, IWEVCUSTOM
, &wrqu
, buf
);
11422 #else /* WIRELESS_EXT >= 15 */
11423 void hostap_michael_mic_failure(struct zd1205_private
*macp
,
11424 struct hostap_ieee80211_hdr
*hdr
,
11428 #endif /* WIRELESS_EXT >= 15 */
11429 BssInfo_t
*zd1212_bssid_to_BssInfo(U8
*bssid
)
11432 for(i
=0;i
<mBssNum
;i
++)
11434 if(memcmp(&mBssInfo
[i
].bssid
, bssid
, ETH_ALEN
) == 0)
11435 return &mBssInfo
[i
];
11440 void ChangeMacMode(u8 MAC_Mode
, u8 Channel
) {
11441 struct zd1205_private
*macp
;
11443 if(NULL
!= g_dev
&& NULL
!= g_dev
->priv
)
11444 macp
= (struct zd1205_private
*)g_dev
->priv
;
11447 LongPrint("NULL macp in ChnageMacMode\n",1);
11453 #if 1 //prince retain this for any trouble happened
11454 macp
->cardSetting
.Channel
= Channel
; //Default Channel to 8
11455 dot11Obj
.Channel
= Channel
;
11456 macp
->cardSetting
.MacMode
= MAC_Mode
;
11457 macp
->bDefaultIbssMacMode
=1;
11459 if ( macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
)
11461 macp
->cardSetting
.Channel
= Channel
; //Default Channel to 8
11462 dot11Obj
.Channel
= Channel
;
11463 macp
->cardSetting
.MacMode
= MAC_Mode
;
11464 macp
->bDefaultIbssMacMode
=1;
11466 else if ( macp
->cardSetting
.BssType
== INDEPENDENT_BSS
)
11468 if ( macp
->cardSetting
.MacMode
== PURE_A_MODE
)
11471 if ( Channel
< 36 )
11472 macp
->cardSetting
.Channel
= 36;
11478 if ( Channel
> 14 )
11479 macp
->cardSetting
.Channel
= 1;
11483 dot11Obj
.Channel
= macp
->cardSetting
.Channel
;
11484 macp
->bDefaultIbssMacMode
=1;
11488 zd1205_unlock(macp
);
11490 //set_mac_mode command has been issued by the user.
11491 zd1205_SetRatesInfo(macp
);
11492 //zd_UpdateCardSetting(&(macp->cardSetting));
11494 #if ZDCONF_WE_STAT_SUPPORT == 1
11495 struct iw_statistics
*
11496 zd1205_iw_getstats(struct net_device
*dev
)
11498 struct zd1205_private
*macp
= (struct zd1205_private
*)dev
->priv
;
11500 macp
->iwstats
.discard
.fragment
= macp
->ArAgedCnt
11501 + macp
->ArFreeFailCnt
;
11503 macp
->iwstats
.discard
.retries
= macp
->retryFailCnt
;
11504 macp
->iwstats
.discard
.misc
= macp
->invalid_frame_good_crc
11507 return &macp
->iwstats
;
11511 //prince add for dis_update_setting
11512 int zd1205_dis_update_setting( struct zd1205_private
*macp
)
11515 static size_t dis_update_setting_Lock
= 0;
11518 if ( macp
->CurrScanCH
!= 1 && macp
->cardSetting
.BssType
!= AP_BSS
)
11521 printk(KERN_DEBUG
"macp->CurrScanCH:%d pdot11Obj->bChScanning:%d\n",macp
->CurrScanCH
,pdot11Obj
->bChScanning
);
11522 if ( macp
->LastCurrScanCH
== macp
->CurrScanCH
)
11524 macp
->LastCurrScanCH
= macp
->CurrScanCH
;
11530 if(test_and_set_bit(0, (void *)&dis_update_setting_Lock
))
11532 printk("change dis_update_setting at the same time\n");
11537 zd1205_disassoc(macp
);
11539 if ( macp
->ModeChBssType
!= 0x10 ) //change BssType
11542 //want change BssType
11543 if ( macp
->ModeChBssType
== INFRASTRUCTURE_BSS
)
11545 macp
->cardSetting
.BssType
= INFRASTRUCTURE_BSS
;
11546 macp
->cardSetting
.AuthMode
= 0;
11548 if (macp->bDefaultIbssMacMode==0)
11550 macp->cardSetting.MacMode=MIXED_MODE;
11553 macp
->cardSetting
.MacMode
=MIXED_MODE
;
11554 zd_writel(STA_RX_FILTER
, Rx_Filter
);
11556 else if ( macp
->ModeChBssType
== INDEPENDENT_BSS
)
11558 macp
->cardSetting
.BssType
= INDEPENDENT_BSS
;
11561 if (macp->bDefaultIbssMacMode==0)
11563 macp->cardSetting.MacMode=PURE_B_MODE;
11566 macp
->cardSetting
.MacMode
= PURE_B_MODE
;
11567 macp
->cardSetting
.Channel
= pass_channel_for_region(macp
,0);
11568 macp
->IBSS_DesiredMacMode
= PURE_B_MODE
;
11569 macp
->IBSS_DesiredChannel
= macp
->cardSetting
.Channel
;
11572 // macp->cardSetting.Channel = 6;
11573 zd_writel(STA_RX_FILTER
, Rx_Filter
);
11576 else if ( macp
->ModeChBssType
== AP_BSS
)
11578 macp
->cardSetting
.BssType
= AP_BSS
;
11579 // Set bssid = MacAddress
11580 macp
->BSSID
[0] = macp
->macAdr
[0];
11581 macp
->BSSID
[1] = macp
->macAdr
[1];
11582 macp
->BSSID
[2] = macp
->macAdr
[2];
11583 macp
->BSSID
[3] = macp
->macAdr
[3];
11584 macp
->BSSID
[4] = macp
->macAdr
[4];
11585 macp
->BSSID
[5] = macp
->macAdr
[5];
11587 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[0]), BSSID_P1
);
11588 zd_writel(cpu_to_le32(*(u32
*)&macp
->macAdr
[4]), BSSID_P2
);
11589 macp
->cardSetting
.AuthMode
= 2; //auto auth
11590 macp
->cardSetting
.MacMode
=PURE_G_MODE
;
11591 macp
->cardSetting
.Channel
= pass_channel_for_region(macp
,0);
11592 // macp->cardSetting.Channel = 8;
11594 zd_writel(AP_RX_FILTER
, Rx_Filter
);
11595 netif_start_queue(g_dev
);
11601 if (macp
->usb
->speed
!= USB_SPEED_HIGH
)
11602 macp
->cardSetting
.MacMode
= PURE_B_MODE
;
11605 if (macp
->cardSetting
.BssType
== INDEPENDENT_BSS
)
11606 macp
->cardSetting
.MacMode
= PURE_B_MODE
;
11608 macp
->cardSetting
.MacMode
= MIXED_MODE
;
11611 macp
->bDefaultIbssMacMode
=1;// Indicates that the set_mac_mode command has been issued by the user.
11612 zd1205_SetRatesInfo(macp
);
11615 if ( macp
->ModeChChannel
!= 0x00 ) //change Channel
11617 macp
->cardSetting
.Channel
= macp
->ModeChChannel
;
11618 dot11Obj
.Channel
= macp
->cardSetting
.Channel
;
11621 if ( macp
->ModeChMacMode
!= 0x00 ) //change MacMode
11623 macp
->cardSetting
.MacMode
= macp
->ModeChMacMode
;
11624 macp
->IBSS_DesiredMacMode
= macp
->ModeChMacMode
;
11625 macp
->cardSetting
.Channel
= pass_channel_for_region(macp
,macp
->cardSetting
.Channel
);
11626 macp
->IBSS_DesiredChannel
= macp
->cardSetting
.Channel
;
11627 macp
->bDefaultIbssMacMode
=1;// Indicates that the set_mac_mode command has been issued by the user.
11628 zd1205_SetRatesInfo(macp
);
11633 clear_bit(0, (void *)&dis_update_setting_Lock
);
11635 zd_UpdateCardSetting(&(macp
->cardSetting
));
11638 if ( macp
->ModeChBssType
!= 0x10 )
11639 macp
->ModeChBssType
= 0x10;
11641 if ( macp
->ModeChChannel
!= 0x00 )
11642 macp
->ModeChChannel
= 0x00;
11644 if ( macp
->ModeChMacMode
!= 0x00 )
11645 macp
->ModeChMacMode
= 0x00;
11655 //prince add for moxa_repeat
11656 int zd1205_moxa_repeat( struct zd1205_private
*macp
)
11659 char essidbuf
[IW_ESSID_MAX_SIZE
+1] = "MOXA_R";
11660 char key
[MAX_KEY_SIZE
] = "89190";
11661 static size_t moxa_repeat_Lock
= 0;
11665 if ( macp
->CurrScanCH
!= 1 && macp
->cardSetting
.BssType
!= AP_BSS
)
11668 if ( macp
->LastCurrScanCH
== macp
->CurrScanCH
)
11670 macp
->LastCurrScanCH
= macp
->CurrScanCH
;
11677 if(test_and_set_bit(0, (void *)&moxa_repeat_Lock
))
11679 printk("change mode at the same time\n");
11684 zd1205_disassoc(macp
);
11689 macp
->bDefaultIbssMacMode
=1;
11690 macp
->cardSetting
.MacMode
= PURE_B_MODE
;
11691 macp
->cardSetting
.BssType
= INDEPENDENT_BSS
;
11692 macp
->cardSetting
.Channel
= pass_channel_for_region(macp
,0);
11693 macp
->IBSS_DesiredMacMode
= macp
->cardSetting
.MacMode
;
11694 macp
->IBSS_DesiredChannel
= macp
->cardSetting
.Channel
;
11697 // macp->cardSetting.Channel = 10;
11698 dot11Obj
.Channel
= macp
->cardSetting
.Channel
;
11699 zd_writel(STA_RX_FILTER
, Rx_Filter
);
11700 zd1205_SetRatesInfo(macp
);
11703 //set essid , wep key
11704 memcpy(&macp
->cardSetting
.Info_SSID
[2], essidbuf
, IW_ESSID_MAX_SIZE
+1);
11705 macp
->cardSetting
.Info_SSID
[1] = strlen(essidbuf
);
11707 macp
->cardSetting
.WepKeyLen
= strlen(key
) + 1;
11708 macp
->cardSetting
.EncryMode
= WEP64
;
11709 macp
->cardSetting
.EncryKeyId
= 0;
11710 memcpy(&macp
->cardSetting
.keyVector
[0][0], key
, strlen(key
) + 1);
11711 macp
->cardSetting
.EncryOnOff
=1;
11712 zd1205_config_wep_keys(macp
);
11715 zd1205_unlock(macp
);
11719 if (macp
->usb
->speed
!= USB_SPEED_HIGH
)
11720 macp
->cardSetting
.MacMode
= PURE_B_MODE
;
11723 if (macp
->cardSetting
.BssType
== INDEPENDENT_BSS
)
11724 macp
->cardSetting
.MacMode
= PURE_B_MODE
;
11726 macp
->cardSetting
.MacMode
= MIXED_MODE
;
11731 clear_bit(0, (void *)&moxa_repeat_Lock
);
11733 zd_UpdateCardSetting(&(macp
->cardSetting
));
11741 #elif !defined(ZDCONF_WE_STAT_SUPPORT)
11742 #error "Undefine ZDCONF_WE_STAT_SUPPORT"