MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zd1205.c
blob477ac64107b8bbfaaa6a8cc2e4c66400f6c067e9
1 /* src/zd1205.c
3 *
5 * Copyright (C) 2004 ZyDAS Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
8 *
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>
39 #include <linux/fs.h>
40 #include <linux/stat.h>
42 #include "zd1205.h"
43 #include "zdinlinef.h"
44 #include "zddebug.h"
45 #include "zddebug2.h"
46 #include "menu_drv_macro.h"
47 #include "zdhw.h"
48 #include "zdsorts.h"
49 #include "zdglobal.h"
50 #include "zdutils.h"
51 #include "zdmisc.h"
52 #include "zdhci.h"
53 #ifdef HOST_IF_USB
54 #include "zd1211.h"
55 #endif
58 #if WIRELESS_EXT > 12
59 #include <net/iw_handler.h>
60 #endif
62 #if ZDCONF_LP_SUPPORT == 1
63 #include "zdlpmgt.h"
64 #include "zdturbo_burst.h"
65 #endif
66 #if ZDPRODUCTIOCTL
67 #include "zdreq.h"
68 #endif
69 extern U16 mTmRetryConnect;
70 extern BOOLEAN mProbeWithSsid;
71 extern u8 mMacMode;
72 extern U8 mBssType;
73 extern Element mSsid;
74 extern Element dot11DesiredSsid;
75 int errno;
76 extern u8 mCurrConnUser;
77 extern U8 mNumBOnlySta;
79 extern u8 mBssNum;
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
83 extern U8 mWepKeyLen;
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 /******************************************************************************
93 * C O N S T A N T S
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))
130 #ifndef HOST_IF_USB
131 #define nowT() (zd_readl(TSF_LowPart)) //us unit
132 #else
133 #define nowT() (jiffies) //tick (10ms) unit
134 #endif
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 *);
142 #else
143 #define zd1205_create_proc_subdir(X) 0
144 #define zd1205_remove_proc_subdir(X) do {} while(0)
145 #endif
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);
170 #ifndef HOST_IF_USB
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);
177 #else
178 struct rx_list_elem *zd1205_start_ru(struct zd1205_private *);
179 #endif
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);
199 //for 1211
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);
250 #endif
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();
269 //void zd_ScanEnd();
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);
286 //prince add begin
287 int zd1205_moxa_repeat( struct zd1205_private *macp);
288 int zd1205_dis_update_setting( struct zd1205_private *macp);
289 //prince add end
291 /******************************************************************************
293 * P U B L I C D A T A
294 *******************************************************************************
296 /* Global Data structures and variables */
297 #ifndef HOST_IF_USB
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";
302 #endif
304 #if 0 // mask by Victor Yu. 04-04-2007, we don't use it.
305 const char config_filename[] = "/etc/zd1211.conf";
306 #endif
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;
315 u8 *mTxOFDMType;
316 zd_80211Obj_t dot11Obj = {0};
317 #if ZDCONF_LP_SUPPORT == 1
318 fragInfo_t PollFragInfo;
319 #endif
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;
352 } ZD_REGION;
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" },
373 #endif
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
461 #endif
463 #endif
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)); \
469 __upper = __high; \
470 if (__high) { \
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)); \
476 __mod; \
478 #endif
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);
486 else
487 mdelay(ms);
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 */
496 #endif
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);
503 #if defined(OFDM)
504 u8 OfdmRateTbl[12] = {
505 0x00, //1M
506 0x01, //2M
507 0x02, //5.5M
508 0x03, //11M
509 0x1b, //6M
510 0x1f, //9M
511 0x1a, //12M
512 0x1e, //18M
513 0x19, //24M
514 0x1d, //36M
515 0x18, //48M
516 0x1c //54M
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]= {
521 0x00, //Useless
522 0x01, //Useless
523 0x02, //Useless
524 0x03, //Useless
525 0x3b, //6M
526 0x3f, //9M
527 0x3a, //12M
528 0x3e, //18M
529 0x39, //24M
530 0x3d, //36M
531 0x38, //48M
532 0x3c //54M
535 #endif
536 //The Order is meaningful, Do not Change
537 static u8 a_ChannelMap[] = {
538 184,196,16,
539 36,36,
540 40,48,
541 52,64,
542 100,112,
543 128,140,
544 149,165};
546 typedef struct _a_InterpolationStruc {
548 u8 a_Channel;
549 u8 Left_Most_Channel;
550 u8 Right_Most_Channel;
551 u8 TotalDivisionNum;
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},
559 { 8, 16, 16, 3, 3},
560 { 12, 16, 16, 3, 3},
561 { 34, 36, 36, 3, 3},
562 { 38, 36, 36, 3, 3},
563 { 42, 40, 48, 4, 1},
564 { 44, 40, 48, 4, 2},
565 { 46, 40, 48, 4, 3},
566 { 56, 52, 64, 3, 1},
567 { 60, 52, 64, 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];
587 // [0][]:CH,
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)
596 u32 tmpvalue;
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)));
602 else{
603 printk("Error in a_get_cal_int_val\n");
604 return FALSE;
608 u8 a_get_cal_36M_setpoint_val( u8 index)
610 u32 tmpvalue;
612 if (index < 16){
613 tmpvalue=zd_readl(ZD_E2P_A36M_CAL_VALUE+((index>>2)<<2));
614 return ((u8)(tmpvalue >> (index%4*8)));
616 else{
617 printk("Error in a_get_cal_36M_setpoint_val\n");
618 return FALSE;
622 u8 a_get_cal_48M_54M_setpoint_val( u8 index)
624 u32 tmpvalue;
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)));
630 else{
631 printk("Error in a_get_cal_54M_setpoint_val\n");
632 return FALSE;
635 u8 a_find_index_in_a_Calibration_Data( u8 ch)
637 u8 i;
638 for (i=0;i<a_CALIBRATED_CH_NUM;i++){
639 if (ch == a_Calibration_Data[0][i]){
640 return i;
643 return (u8)0xff;
645 u8 a_find_index_in_a_Interpolation_Data( u8 ch)
647 u8 i;
648 for (i=0;i<a_INTERPOLATION_CH_NUM;i++){
649 if (ch == a_Interpolation_Data[0][i]){
650 return i;
653 return (u8)0xff;
656 BOOLEAN a_get_interpolation_value(
657 u8 index,
658 u8 *pIntVal,
659 u8 *pSetPoint_36M,
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");
668 return FALSE;
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");
674 return FALSE;
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);
688 return TRUE;
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) {
693 u8 idx;
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);
697 if(0xff != idx) {
698 *intValue = a_Interpolation_Data[1][idx];
699 if(rate <= RATE_36M)
700 *calValue = a_Interpolation_Data[2][idx];
701 else //rate >=48
702 *calValue = a_Interpolation_Data[3][idx];
704 else
705 return 0xff;
707 else {//Channel is in Calibration Data
708 *intValue = a_Calibration_Data[1][idx];
709 if(rate <= RATE_36M)
710 *calValue = a_Calibration_Data[2][idx];
711 else //rate >=48
712 *calValue = a_Calibration_Data[3][idx];
715 return 0;
719 //prince add for get Region String
720 static char* get_curregion_str( struct zd1205_private *macp )
722 char *retStr;
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");
738 return retStr;
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 )
749 retChannel = 40;
750 #if 0 // mask by Victor Yu. 04-04-2007
751 else
752 retChannel = setChannel;
753 #endif
754 } else {
755 if ( macp->RegionCode == ZD_REGION_USA ) {
756 if ( setChannel < 1 || setChannel > 11 || setChannel == 0 )
757 retChannel = 1;
758 #if 0 // mask by Victor Yu. 04-04-2007
759 else
760 retChannel = setChannel;
761 #endif
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;
766 else
767 retChannel = setChannel;
768 #endif
769 } else if ( macp->RegionCode == ZD_REGION_France ) {
770 if ( setChannel < 10 || setChannel > 13 || setChannel == 0 )
771 retChannel = 10;
772 #if 0 // mask by Victor Yu. 04-04-2007
773 else
774 retChannel = setChannel;
775 #endif
776 } else if ( macp->RegionCode == ZD_REGION_Japan ) {
777 if ( setChannel < 1 || setChannel > 14 || setChannel == 0 )
778 retChannel = 1;
779 #if 0 // mask by Victor Yu. 04-04-2007
780 else
781 retChannel = setChannel;
782 #endif
783 } else if ( macp->RegionCode == ZD_REGION_Israel ) {
784 if ( setChannel < 3 || setChannel > 9 || setChannel == 0 )
785 retChannel = 3;
786 #if 0 // mask by Victor Yu. 04-04-2007
787 else
788 retChannel = setChannel;
789 #endif
790 } else if ( macp->RegionCode == ZD_REGION_Mexico ) {
791 if ( setChannel < 10 || setChannel > 11 || setChannel == 0 )
792 retChannel = 10;
793 #if 0 // mask by Victor Yu. 04-04-2007
794 else
795 retChannel = setChannel;
796 #endif
800 return (U8)retChannel;
804 //prince add for disassoc
805 static void zd1205_disassoc(struct zd1205_private *macp)
807 if(macp->bAssoc)
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);
815 else
816 zdcb_status_notify(STA_DISASSOCIATED, &macp->BSSID[0]);
819 return;
823 #ifdef HOST_IF_USB
824 #define fDISABLE_LED 0
825 void iLED_ON(struct zd1205_private *macp, u32 LEDn)
827 #if !fDISABLE_LED
829 u32 tmpvalue;
831 tmpvalue = zd_readl(rLED_CTRL);
832 tmpvalue |= LEDn;
833 zd_writel(tmpvalue, rLED_CTRL);
835 #ifdef ROBIN_KAO
836 tmpvalue = zd_readl(FW_LINK_STATUS);
837 tmpvalue |= 0x1;
838 zd_writel(tmpvalue, FW_LINK_STATUS);
839 #endif
841 #endif
845 void iLED_OFF(struct zd1205_private *macp, u32 LEDn)
847 #if !fDISABLE_LED
849 u32 tmpvalue;
852 tmpvalue = zd_readl(rLED_CTRL);
853 tmpvalue &= ~LEDn;
854 zd_writel(tmpvalue, rLED_CTRL);
857 #ifdef ROBIN_KAO
858 zd_writel(0x0, FW_LINK_STATUS);
859 #endif
861 #endif
865 void iLED_SWITCH(struct zd1205_private *macp, u32 LEDn)
867 #if !fDISABLE_LED
868 u32 tmpvalue;
870 tmpvalue = zd_readl(rLED_CTRL);
871 tmpvalue ^= LEDn;
872 zd_writel(tmpvalue, rLED_CTRL);
873 #endif
876 #else
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)
894 u32 tmpvalue;
896 tmpvalue = zd_readl(LEDn);
897 tmpvalue ^= 0x1;
898 zd_writel(tmpvalue, LEDn);
901 #endif
904 void zd_writel(u32 value, u32 offset)
906 struct zd1205_private *macp = g_dev->priv;
907 void *regp = macp->regp;
908 u32 RegWait = 0;
911 #ifdef HOST_IF_USB
912 #if fPROG_FLASH
913 if (!macp->bAllowAccessRegister)
914 return;
915 #endif
917 zd1211_writel(offset, value, true);
918 return;
919 #endif
922 atomic_inc(&macp->DoNotSleep);
923 if (dot11Obj.bDeviceInSleep){
924 while((readl(regp+ZD_MAC_PS_STATE) & 0x7) != MAC_OPERATION){
925 udelay(1000);
926 RegWait++;
927 if ((RegWait > REG_MAX_WAIT) || macp->bSurpriseRemoved){
928 dot11Obj.bDeviceInSleep = 0;
929 ZD1211DEBUG(0, "zd_writel Sleep to die!!!");
930 break;
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;
945 u32 value;
946 u32 RegWait = 0;
948 #ifdef HOST_IF_USB
949 #if fPROG_FLASH
950 if (!macp->bAllowAccessRegister)
951 return 0xffffffff;
952 #endif
953 //value = zd1211_readl(offset, true);
954 value = zd1211_readl(offset, true);
956 return value;
957 #endif
959 atomic_inc(&macp->DoNotSleep);
960 if (dot11Obj.bDeviceInSleep){
961 while((readl(regp+ZD_MAC_PS_STATE) & 0x7) != MAC_OPERATION){
962 udelay(1000);
963 RegWait++;
964 if ((RegWait > REG_MAX_WAIT) || macp->bSurpriseRemoved){
966 dot11Obj.bDeviceInSleep = 0;
967 ZD1211DEBUG(0, "zd_readl Sleep to die!!!");
968 break;
973 value = readl(regp+offset);
974 atomic_dec(&macp->DoNotSleep);
976 return value;
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)
1000 #ifdef HOST_IF_USB
1001 return;
1002 #endif
1004 if (!dot11Obj.bDeviceInSleep)
1005 zd_writel(phyAddr, ZD_PCI_TxAddr_p1);
1009 void zd1205_start_upload(u32 phyAddr)
1011 #ifdef HOST_IF_USB
1013 return;
1014 #endif
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)
1030 u32 tmpvalue;
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;
1041 return 1;
1047 return 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)
1060 zd_CleanupAwakeQ();
1064 static void zd1205_tx_action(unsigned long parm)
1066 zd_CleanupTxQ();
1070 #ifndef HOST_IF_USB
1071 u8 zd1205_RateAdaption(u16 aid, u8 CurrentRate, u8 gear)
1074 u8 NewRate;
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);
1090 else{
1091 NewRate = CurrentRate;
1093 return (NewRate);
1096 return 0;
1098 #endif
1100 void zd1205_ClearTupleCache(struct zd1205_private *macp)
1102 int i;
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)
1114 int k;
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))
1121 return 1;
1124 return 0;
1128 void zd1205_UpdateTupleCache(struct zd1205_private *macp, u8 *pAddr, u16 seq ,u8 frag)
1130 int k;
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;
1139 return;
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;
1150 pCache->freeTpi++;
1155 void zd1205_ArReset(struct zd1205_private *macp)
1157 u8 i;
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)
1167 u8 i;
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");
1174 macp->ArAgedCnt++;
1179 dot11Obj.ReleaseBuffer(pArray->mpdu[i].buf);
1180 pArray->mpdu[i].inUse = 0;
1189 int zd1205_ArFree(struct zd1205_private *macp)
1191 u8 i;
1192 defrag_Array_t *pArray = &macp->defragArray;
1194 for (i=0; i<MAX_DEFRAG_NUM; i++){
1195 if (!pArray->mpdu[i].inUse)
1197 return i;
1200 macp->ArFreeFailCnt++;
1201 return -1;
1205 int zd1205_ArSearch(struct zd1205_private *macp, u8 *pAddr, u16 seq, u8 frag)
1207 u8 i;
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)){
1218 return i;
1220 else {
1221 dot11Obj.ReleaseBuffer(pDeMpdu->buf);
1222 pDeMpdu->inUse = 0;
1223 return -1;
1229 return -1;
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)
1250 u8 *pTxGain;
1252 #if fTX_GAIN_OFDM
1253 if (TxPwrType != cTX_OFDM)
1254 pTxGain = &(dot11Obj.TxGainSetting);
1256 else
1257 pTxGain = &(dot11Obj.TxGainSetting2);
1258 #else
1259 pTxGain = &(dot11Obj.TxGainSetting);
1260 #endif
1262 switch(macp->RF_Mode){
1263 case MAXIM_NEW_RF:
1264 if (*pTxGain < MAXIM2_MAX_TX_PWR_SET)
1266 (*pTxGain)++;
1267 break;
1269 case RFMD_RF:
1270 if (*pTxGain < RFMD_MAX_TX_PWR_SET)
1271 (*pTxGain) ++;
1272 break;
1274 case AL2230_RF:
1275 case AL2230S_RF:
1276 case AL7230B_RF:
1277 if (*pTxGain < AL2230_MAX_TX_PWR_SET)
1278 (*pTxGain) += 2;
1279 break;
1281 default:
1282 break;
1285 HW_Write_TxGain2(&dot11Obj, TxPwrType);
1289 void zd1205_DecreaseTxPower(struct zd1205_private *macp, u8 TxPwrType)
1291 u8 *pTxGain;
1293 #if fTX_GAIN_OFDM
1294 if (TxPwrType != cTX_OFDM)
1295 pTxGain = &(dot11Obj.TxGainSetting);
1296 else
1297 pTxGain = &(dot11Obj.TxGainSetting2);
1298 #else
1300 pTxGain = &(dot11Obj.TxGainSetting);
1302 #endif
1305 switch(macp->RF_Mode){
1306 case MAXIM_NEW_RF:
1307 if (*pTxGain > MAXIM2_MIN_TX_PWR_SET)
1309 (*pTxGain)--;
1310 break;
1312 case RFMD_RF:
1313 if (*pTxGain > RFMD_MIN_TX_PWR_SET)
1315 (*pTxGain) --;
1317 break;
1319 case AL2230_RF:
1320 case AL2230S_RF:
1321 case AL7230B_RF:
1322 if (*pTxGain > AL2230_MIN_TX_PWR_SET)
1323 (*pTxGain) -= 2;
1324 break;
1326 default:
1327 break;
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);
1348 return 1;
1350 if(!in_irq())spin_unlock_irqrestore(&macp->q_lock, flags);
1353 if ((dot11Obj.QueueFlag & MGT_QUEUE_SET) || (dot11Obj.QueueFlag & TX_QUEUE_SET))
1354 return 1;
1356 if (macp->bAnyActivity)
1357 return 1;
1359 // No any activity.
1360 return 0;
1364 void zd1205_connect_mon(struct zd1205_private *macp)
1366 static u16 IdleLoop_Under_Seq1 = 0;
1368 zd_ConnectMon();
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.
1380 else{
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;
1397 #ifdef HOST_IF_USB
1399 defer_kevent(macp, KEVENT_MGT_MON_TIMEOUT);
1400 mod_timer(&(macp->tm_mgt_id), jiffies+ (1*HZ)/50); //20ms
1403 #else
1404 zd1205_connect_mon(macp);
1405 mod_timer(&(macp->tm_mgt_id), jiffies+ (1*HZ)/50); //20ms
1406 #endif
1411 void zd1205_SwAntennaDiv(struct zd1205_private *macp)
1413 #if fANT_DIVERSITY
1414 static u32 loop = 0;
1415 loop++;
1417 // Software Antenna Diversity Mechanism
1418 if (macp->bEnableSwAntennaDiv){
1419 switch(AccState){
1420 case ACC_1:
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;
1424 else {
1425 Avg1_SQ_OFDM = 0;
1427 if (macp->Acc_Num)
1428 Avg1_SQ = macp->Acc_SQ / macp->Acc_Num;
1429 else
1430 Avg1_SQ = 0;
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);
1439 AccState = ACC_2;
1442 macp->Acc_SQ = 0;
1445 macp->Acc_Num = 0;
1447 macp->Acc_SQ_OFDM = 0;
1448 macp->Acc_Num_OFDM = 0;
1450 break;
1452 case ACC_2:
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;
1458 else {
1459 Avg2_SQ_OFDM = 0;
1460 if (macp->Acc_Num)
1461 Avg2_SQ = macp->Acc_SQ / macp->Acc_Num;
1462 else
1463 Avg2_SQ = 0;
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);
1478 AccState = ACC_1;
1479 macp->Acc_SQ = 0;
1480 macp->Acc_Num = 0;
1481 macp->Acc_SQ_OFDM = 0;
1482 macp->Acc_Num_OFDM = 0;
1485 break;
1487 default:
1488 break;
1491 #endif
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);
1512 #define TOLERANCE 2
1514 int zd1205_IbssPsCheck(struct zd1205_private *macp)
1516 u32 ul_BcnItvl, ul_atimwnd;
1517 u64 TSFTimer;
1518 u32 tmpvalue;
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));
1536 /*==prince delete
1537 if ((do_div(TSFTimer, ul_BcnItvl)) > (ul_atimwnd + TOLERANCE)){
1538 ===============*/
1539 //prince add begin
1540 do_div(TSFTimer, ul_BcnItvl);
1541 if ( (u32)TSFTimer > (ul_atimwnd + TOLERANCE) ) {
1542 //prince add end
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);
1550 return 1;
1555 return 0;
1560 void zd1205_InfraPsCheck(struct zd1205_private *macp)
1562 u32 tmpvalue;
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);
1575 up(&macp->bcn_sem);
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);
1588 up(&macp->bcn_sem);
1590 macp->PwrState = PS_CAM;
1591 zd_EventNotify(EVENT_PS_CHANGE, (U8)macp->PwrState, 0, 0);
1592 ZD1211DEBUG(0, "=====PSM --> CAM\n");
1595 return;
1598 //Normally, house keeping routine is run every 100ms.
1599 void zd1205_house_keeping(struct zd1205_private *macp)
1602 //u32 tmpvalue;
1603 static u32 loop = 0;
1604 card_Setting_t *pSetting = &macp->cardSetting;
1605 u8 BssType = pSetting->BssType;
1606 u8 bAssoc = macp->bAssoc;
1608 #if 0
1609 if (dot11Obj.QueueFlag & TX_QUEUE_SET){
1610 macp->txQueSetCnt++;
1611 //tasklet_schedule(&macp->zd1205_tx_tasklet);
1612 zd_CleanupTxQ();
1614 #endif
1615 loop++;
1617 #ifndef HOST_IF_USB
1618 while (dot11Obj.bDeviceInSleep){
1619 // If device is in sleep, do not access device register often to
1620 // prevent host from slowing down.
1621 wait_ms(10);
1623 #else
1624 if (dot11Obj.bDeviceInSleep)
1625 return;
1626 #endif
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))
1637 return;
1641 #if 1
1642 // Infrasture AP mode beacon generation
1643 if (BssType == AP_BSS) {
1644 down(&macp->bcn_sem);
1645 zd_EventNotify(EVENT_TBCN, 0, 0, 0);
1646 up(&macp->bcn_sem);
1648 if (macp->dtimCount == 0)
1649 macp->dtimCount = macp->cardSetting.DtimPeriod;
1650 macp->dtimCount--;
1652 #endif
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
1661 //Collect HW Tally
1662 //zd1205_CollectHwTally(macp); //This will make us lose CfgNextBcn interrupt
1664 #ifdef HOST_IF_USB
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);
1670 #endif
1672 // Infrastructure Power-State momitor
1674 if ((!dot11Obj.bChScanning) && (BssType == INFRASTRUCTURE_BSS) && (bAssoc) && (macp->bPSMSupported)){
1675 zd1205_InfraPsCheck(macp);
1679 #ifdef HOST_IF_USB
1680 #ifndef ZD1211B
1681 zd1211_TxCalibration(macp);
1682 #endif
1683 //if(dot11Obj.rfMode == UW2453_RF)
1684 // PHY_UWTxPower(&dot11Obj, mRfChannel);
1685 zd1211_CheckWithIPC(macp);
1686 #endif
1690 void HKeepingCB(struct net_device *dev)
1692 struct zd1205_private *macp = dev->priv;
1693 static U32 loop = 0;
1694 loop++;
1696 #ifdef HOST_IF_USB
1697 defer_kevent(macp, KEVENT_HOUSE_KEEPING);
1698 mod_timer(&(macp->tm_hking_id), jiffies+ (1*HZ)/10);
1699 #else
1700 zd1205_house_keeping(macp);
1701 mod_timer(&(macp->tm_hking_id), jiffies+ (1*HZ)/10);
1702 #endif
1704 if (!macp->bFixedRate && (loop & BIT_0))
1706 zd_RateAdaption();
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");
1719 return;
1722 if(!dot11Obj.LP_MODE)
1723 return;
1724 PollFragInfo.msgID = 254;
1725 dot11Obj.SetupNextSend(&PollFragInfo);
1726 mod_timer(&(macp->tm_lp_poll_id), jiffies+(1*HZ)/20);
1727 // 1ms
1729 #endif
1732 void zd1205_CollectBssInfo(struct zd1205_private *macp, plcp_wla_Header_t *pWlanHdr, u8 *pMacBody, u32 bodyLen)
1734 u8 bssidmatched = 0;
1735 u8 i, j;
1736 u8 *pBssid;
1737 u8 *pByte;
1738 u32 currPos = 0;
1739 u8 elemId, elemLen;
1740 U16 loopCheck = 0;
1742 if ((*(pMacBody+CAP_OFFSET)) & BIT_1) //IBSS
1743 pBssid = pWlanHdr->Address3;
1744 else
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]){
1750 break;
1754 if (j==6){
1755 bssidmatched = 1;
1756 break;
1760 if (bssidmatched)
1761 return;
1763 //get bssid
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));
1773 //get capability
1774 pByte = pMacBody+CAP_OFFSET;
1775 macp->BSSInfo[macp->bss_index].cap = ((*pByte) + ((u16)(*(pByte+1))<<8) );
1777 //get element
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__);
1786 break;
1788 elemId = *pByte;
1789 elemLen = *(pByte+1);
1791 switch(elemId){
1792 case ELEID_SSID: //ssid
1793 for (i=0; i<elemLen+2; i++){
1794 macp->BSSInfo[macp->bss_index].ssid[i] = *pByte;
1795 pByte++;
1797 break;
1799 case ELEID_SUPRATES: //supported rateS
1801 for (i=0; i<elemLen+2; i++){
1802 macp->BSSInfo[macp->bss_index].supRates[i] = *pByte;
1803 pByte++;
1805 break;
1808 case ELEID_DSPARMS: //ds parameter
1809 macp->BSSInfo[macp->bss_index].channel = *(pByte+2);
1810 pByte += (elemLen+2);
1811 break;
1813 case ELEID_EXT_RATES:
1815 pByte += (elemLen+2);
1816 break;
1818 default:
1820 pByte += (elemLen+2);
1821 break;
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)){
1831 macp->bss_index ++;
1834 return;
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;
1844 int i = 0;
1846 list_for_each(entry_ptr, &(macp->active_rx_list)){
1848 rx_struct = list_entry(entry_ptr, struct rx_list_elem, list_elem);
1849 if (!rx_struct)
1850 return;
1851 #ifndef HOST_IF_USB
1852 pci_dma_sync_single(macp->pdev, rx_struct->dma_addr,
1853 macp->rfd_size, PCI_DMA_FROMDEVICE);
1854 #endif
1855 skb = rx_struct->skb;
1856 rfd = RFD_POINTER(skb, macp); /* locate RFD within skb */
1857 #if 0
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));
1869 #endif
1871 zd1205_dump_data("rfd", (u8 *)rfd, 24);
1872 i++;
1878 void zd1205_dump_data(char *info, u8 *data, u32 data_len)
1880 int i;
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));
1915 return rx_struct;
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;
1935 ZENTER(4);
1937 new_skb = (struct sk_buff *) dev_alloc_skb(skb_size);
1938 if (new_skb) {
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)
1946 goto err;
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
1954 #ifndef HOST_IF_USB
1955 rx_struct->dma_addr = pci_map_single(macp->pdev, new_skb->data, sizeof (zd1205_RFD_t), PCI_DMA_FROMDEVICE);
1957 #endif
1959 ZD1211DEBUG(4, "zd1211: rx_struct->dma_addr = %x\n", (u32)rx_struct->dma_addr);
1961 #ifndef HOST_IF_USB
1962 if (!rx_struct->dma_addr)
1963 goto err;
1964 #endif
1967 skb_reserve(new_skb, macp->rfd_size); //now skb->data point to RxBuffer
1969 #ifdef HOST_IF_USB
1970 rx_struct->dma_addr = (u32)new_skb->data;
1971 rx_struct->UnFinishFrmLen = 0;
1972 #endif
1974 ZEXIT(4);
1975 return rx_struct;
1976 } else {
1977 macp->AllocSkbFailCnt++;
1978 printk(KERN_DEBUG "zd1205: dev_alloc_skb fail\n");
1979 return NULL;
1982 err:
1983 printk(KERN_DEBUG "zd1205: ****** err\n");
1984 dev_kfree_skb_any(new_skb);
1986 return NULL;
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.
2001 void
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;
2009 ZENTER(4);
2012 (rx_struct->skb)->dev = macp->device;
2013 rfdn = RFD_POINTER(rx_struct->skb, macp);
2015 rfdn->CbCommand = RFD_EL_BIT;
2016 wmb();
2017 rfdn->CbStatus = 0xffffffff;
2019 rfdn->ActualCount = 0;
2020 rfdn->MaxSize = MAX_WLAN_SIZE;
2022 rfdn->NextCbPhyAddrHighPart = 0;
2024 rfdn->NextCbPhyAddrLowPart = 0;
2027 #ifndef HOST_IF_USB
2028 wmb();
2030 pci_dma_sync_single(macp->pdev, rx_struct->dma_addr, macp->rfd_size,
2031 PCI_DMA_TODEVICE);
2032 #endif
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);
2043 #ifndef HOST_IF_USB
2044 pci_dma_sync_single(macp->pdev, rx_struct_last->dma_addr,
2046 4, PCI_DMA_FROMDEVICE);
2047 #endif
2049 put_unaligned(rx_struct->dma_addr,
2050 ((u32 *) (&(rfd->NextCbPhyAddrLowPart))));
2051 #ifndef HOST_IF_USB
2052 wmb();
2053 pci_dma_sync_single(macp->pdev, rx_struct_last->dma_addr,
2054 8, PCI_DMA_TODEVICE);
2056 #endif
2058 rfd->CbCommand = 0;
2061 #ifndef HOST_IF_USB
2062 wmb();
2063 pci_dma_sync_single(macp->pdev, rx_struct_last->dma_addr,
2064 4, PCI_DMA_TODEVICE);
2066 #endif
2069 list_add_tail(&(rx_struct->list_elem), &(macp->active_rx_list)); //add elem to active_rx_list
2070 ZEXIT(4);
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");
2081 return;
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;
2092 u32 tbd_cnt;
2093 zd1205_TBD_t *tbd_arr = sw_tcb->pFirstTbd;
2095 ZENTER(2);
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);
2103 #ifndef HOST_IF_USB
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),
2109 PCI_DMA_TODEVICE);
2111 #endif
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
2127 ZEXIT(2);
2128 return;
2131 void zd1205_tx_isr(struct zd1205_private *macp)
2133 #if ZDCONF_LP_SUPPORT == 1
2134 int i;
2135 #endif
2136 zd1205_SwTcb_t *sw_tcb = NULL;
2138 #ifndef HOST_IF_USB
2139 zd1250_SwTcb_t *next_sw_tcb;
2140 #endif
2141 u16 aid;
2143 #ifdef HOST_IF_USB
2144 int bRunOnce = false;
2145 #endif
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);
2152 return;
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
2158 completed list */
2159 while (macp->activeTxQ->count){
2160 sw_tcb = macp->activeTxQ->first;
2162 #ifdef HOST_IF_USB
2163 // in USB modem, only run once
2164 if (bRunOnce)
2165 break;
2166 bRunOnce = true;
2167 #endif
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));
2175 #ifndef HOST_IF_USB
2176 rmb();
2178 if ((u16)le32_to_cpu(sw_tcb->pTcb->CbStatus) != CB_STATUS_COMPLETE){
2179 next_sw_tcb = sw_tcb;
2181 while(1){
2182 next_sw_tcb = next_sw_tcb->next;
2183 if (!next_sw_tcb)
2184 break;
2186 if ((u16)le32_to_cpu(next_sw_tcb->pTcb->CbStatus) == CB_STATUS_COMPLETE)
2187 break;
2190 if (!next_sw_tcb)
2191 break;
2193 #endif
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);
2202 aid = sw_tcb->aid;
2203 zd1205_transmit_cleanup(macp, sw_tcb);
2204 macp->txCmpCnt++;
2206 if (!sw_tcb->LastFrag)
2207 continue;
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;
2218 lp->pktCnt = 0;
2219 lp->sending = 0;
2220 lp->createTime = 0;
2221 lp->pktSize = 0;
2222 lp_recycle_tx_bucket(lp);
2224 else
2225 #endif
2227 zd_EventNotify(EVENT_TX_COMPLETE, ZD_TX_CONFIRM, (U32)sw_tcb->MsgID, (U32)aid);
2230 macp->SequenceNum++;
2231 macp->bDataTrafficLight = 1;
2234 #ifdef HOST_IF_USB
2235 if(sw_tcb->CalMIC[MIC_LNG] == TRUE)
2236 zd1211_submit_tx_urb(macp,TRUE);
2237 else
2238 zd1211_submit_tx_urb(macp,FALSE);
2239 #endif
2241 ZD1211DEBUG(2, "***** zd1205_tx_isr exit *****\n");
2242 return;
2246 #ifndef HOST_IF_USB
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;
2256 u8 ShortPreambleFg;
2257 u16 Len;
2258 u16 NextLen;
2259 u16 LenInUs;
2260 u16 NextLenInUs;
2261 u8 Service;
2262 u16 aid;
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);
2270 return;
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;
2292 aid = sw_tcb->aid;
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
2316 // LenInUs, Service
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;
2324 // NextLenInUs
2325 #if defined(OFDM)
2326 NextLen = (ctrl_set->CtrlSetting[25+1] + ((u16)ctrl_set->CtrlSetting[25+2] << 8));
2327 #else
2328 NextLen = (ctrl_set->CtrlSetting[18] + ((u16)ctrl_set->CtrlSetting[19] << 8));
2329 #endif
2335 Cal_Us_Service(NewRate, NextLen, &NextLenInUs, &Service);
2336 ctrl_set->CtrlSetting[23] = (u8)NextLenInUs;
2337 ctrl_set->CtrlSetting[24] = (u8)(NextLenInUs >> 8);
2339 #if defined(OFDM)
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
2349 #endif
2350 // Re-Start Tx-Bus master with a lower Rate
2352 zd1205_start_download(sw_tcb->TcbPhys | BIT_0);
2353 return;
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
2362 completed list */
2364 no_rate_adaption:
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)
2378 continue;
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));
2388 }else{
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);
2395 break;
2398 macp->bIBSS_Wakeup_Dest = 1;
2402 ZD1211DEBUG(2, "+++++ zd1205_retry_failed exit +++++\n");
2404 return;
2406 #endif
2409 static void zd1205_config(struct zd1205_private *macp)
2411 u32 tmpValue;
2412 int i, jj;
2414 ZENTER(1);
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);
2436 else {
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;
2445 else
2446 macp->dtim_notify_en = 0;
2449 if (macp->intrMask & CFG_NEXT_BCN_EN)
2451 macp->config_next_bcn_en = 1;
2452 else
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;
2479 #ifdef HOST_IF_USB
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;
2509 macp->DataLED = 0;
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)
2515 macp->DataLED = 1;
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
2522 macp->IPCFlag = 4;
2525 macp->RF_Mode &= 0x0f;
2527 tmpValue = zd_readl(FW_USB_SPEED);
2528 dot11Obj.IsUSB2_0 = (u8) tmpValue;
2529 #else
2530 dot11Obj.bIsNormalSize = 1;
2531 dot11Obj.IsUSB2_0 = 1;
2532 #endif
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];
2573 else{
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);
2588 else{
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
2608 else{
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)
2618 #if fTX_PWR_CTRL
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);
2625 if (i != 3){
2626 macp->SetPointOFDM[jj][i*4+2] = (u8) (tmpValue >> 16);
2627 macp->SetPointOFDM[jj][i*4+3] = (u8) (tmpValue >> 24);
2631 #endif
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;
2679 macp->iv16 = 0;
2680 macp->iv32 = 0;
2681 macp->EnableTxPwrCtrl = 1;
2682 macp->PSThreshhold = 10000;
2684 #if fANT_DIVERSITY
2685 // macp->NiceSQThr_OFDM = 12 * 4; // 12 dB --> 48 %
2686 macp->NiceSQThr_OFDM = 48; // 48 %
2687 macp->bEnableSwAntennaDiv = 1;
2688 #endif
2690 #if fWRITE_WORD_REG
2691 macp->FlashType = 0xFF;
2693 #endif
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
2708 ZEXIT(0);
2712 int zd1205_dis_connect(struct zd1205_private *macp)
2714 u32 tmpvalue;
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.
2722 macp->bAssoc = 0;
2723 macp->PwrState = PS_CAM;
2725 // PwrMgt = 0
2726 down(&macp->bcn_sem);
2727 tmpvalue = zd_readl(ZD_BCNInterval);
2728 tmpvalue &= ~POWER_MNT;
2729 zd_writel(tmpvalue, ZD_BCNInterval);
2730 up(&macp->bcn_sem);
2733 #ifndef HOST_IF_USB
2734 while (dot11Obj.bDeviceInSleep){
2735 wait_ms(1);
2736 //if (macp->Notification & RQ_TERMINATION){
2737 // break;
2740 #else
2743 if (dot11Obj.bDeviceInSleep){
2744 ZD1211DEBUG(1, "Device in sleep\n");
2746 return 1;
2749 #endif
2751 // After all pending packets are served, then notify NDIS with
2752 // DISCONNECT.
2753 // Otherwise, it might cause IP Address = 0.0.0.0
2755 #ifndef HOST_IF_USB
2756 while (macp->activeTxQ->count){
2757 // After this step, we can make sure that no ATIM pended.
2758 wait_ms(1);
2759 //if (macp->Notification & RQ_TERMINATION){
2760 // break;
2763 #else
2764 //if (macp->activeTxQ->count){
2765 // ZD1211DEBUG(1, "activeTxQ not empty\n");
2767 // return 1;
2768 //}
2770 #endif
2772 // Notice PS_Change
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);
2780 up(&macp->bcn_sem);
2781 zd1205_notify_disjoin_event(macp);
2784 // We may need issue disassociate frame.
2785 // Issue notification
2787 return 0;
2792 #ifndef HOST_IF_USB
2794 static void zd1205_dtim_notify(
2795 struct zd1205_private *macp
2800 zd1205_SwTcb_t *sw_tcb;
2801 u32 tmp_value;
2803 zd_EventNotify(EVENT_DTIM_NOTIFY, 0, 0, 0);
2804 if (!macp->activeTxQ->count)
2805 sw_tcb = macp->freeTxQ->first;
2806 else
2807 sw_tcb = macp->activeTxQ->first;
2810 tmp_value = zd_readl(DeviceState);
2811 tmp_value &= 0xf;
2812 zd1205_start_download(sw_tcb->TcbPhys | BIT_0);
2815 #endif
2817 void zd1205_config_wep_keys(struct zd1205_private *macp)
2819 card_Setting_t *pSetting = &macp->cardSetting;
2821 u8 encryMode = pSetting->EncryMode;
2822 u8 i, j;
2823 u8 DynKeyMode = pSetting->DynKeyMode;
2824 u8 keyLength;
2826 if ((encryMode == 0) || (DynKeyMode != 0)){
2827 HW_CAM_Write(&dot11Obj, DEFAULT_ENCRY_TYPE, NO_WEP);
2828 return;
2831 if (pSetting->OperationMode != CAM_AP_VAP){
2832 HW_CAM_ResetRollTbl(&dot11Obj); //force CAM to use default encry type
2834 switch(encryMode){
2835 case WEP64:
2836 ZD1211DEBUG(0, "WEP64 Mode\n");
2837 keyLength = 5;
2838 break;
2840 case WEP128:
2841 ZD1211DEBUG(0, "WEP128 Mode\n");
2842 keyLength = 13;
2843 break;
2845 case WEP256:
2846 ZD1211DEBUG(0, "WEP256 Mode\n");
2847 keyLength = 29;
2848 break;
2850 default:
2851 ZD1211DEBUG(0, "Not supported Mode\n");
2852 ZD1211DEBUG(0, "encryMode = %d\n", encryMode);
2854 return;
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);
2863 return;
2865 #if 0
2866 void zd1205_config_dyn_key(u8 DynKeyMode, u8 *pkey, int idx)
2868 u8 keyLength;
2869 u8 encryMode;
2870 u32 offset;
2872 HW_CAM_ResetRollTbl(&dot11Obj); //force CAM to use default encry type
2874 switch(DynKeyMode){
2875 case DYN_KEY_TKIP:
2876 WPADEBUG("Dynamic key TKIP mode\n");
2877 keyLength = 32;
2878 encryMode = TKIP;
2879 break;
2881 case DYN_KEY_AES:
2882 WPADEBUG("Dynamic key AES mode\n");
2883 keyLength = 16;
2884 encryMode = AES;
2885 break;
2887 default:
2888 WPADEBUG("Do not support the Dynamic key mode = %d\n", DynKeyMode);
2889 return;
2892 /* The size for each key is 256 bits (32 bytes) */
2893 offset = idx * 8;
2895 HW_CAM_Write(&dot11Obj, DEFAULT_ENCRY_TYPE, encryMode);
2896 HW_ConfigStatKey(&dot11Obj, pkey, keyLength, STA_KEY_START_ADDR+offset);
2898 return;
2900 #endif
2903 #if defined CONFIG_ARCH_W341 || defined CONFIG_ARCH_W321 || defined CONFIG_ARCH_W311
2904 #define WLAN_LED 4
2905 #define ST1_LED 8
2906 #define ST2_LED 9
2907 #define ST3_LED 20
2908 #define ST4_LED 21
2909 #define ST5_LED 28
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
2917 #define WLAN_LED 0
2918 #define STR1_LED 1
2919 #define STR2_LED 2
2920 #define STR3_LED 3
2921 #define STR4_LED 4
2922 #define STR5_LED 5
2923 #define PIO(x) (1<<x)
2925 #endif
2926 static int zd1205_validate_frame(struct zd1205_private *macp, zd1205_RFD_t *rfd)
2928 plcp_wla_Header_t *wla_hdr;
2929 u32 min_length;
2930 u32 frame_len;
2932 u32 len, tot_len;
2933 u8 bOfdmFrm = 0;
2934 u8 PlcpRate;
2935 //u8 rx_offset = macp->rxOffset;
2937 u8 FrameEndInd;
2938 #if ZDCONF_WE_STAT_SUPPORT == 1
2939 U32 Tmp=0;
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};
2942 static U32 Qidx=0;
2943 #elif !defined(ZDCONF_WE_STAT_SUPPORT)
2944 #error "Undefine ZDCONF_WE_STAT_SUPPORT"
2945 #endif
2946 u32 idx;
2949 // Extension Info
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++;
2969 return false;
2972 //pSwRfd->pRfd->RxBuffer[frameLen+rxOffset-1]
2973 //bit7: error frame
2974 //bit6: crc16 error
2975 //bit5: address not match
2976 //bit4: crc32 error
2977 //bit3: decrypt error
2979 //bit2: overrun
2981 //bit1: Rx Timeout
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++;
2988 return FALSE;
2991 if (bWepBit(wla_hdr)){
2992 //if (macp->cardSetting.EncryMode == ENCRY_TKIP)
2993 // min_length = 48;
2994 //else
2995 min_length = 44;
2996 if (frame_len < min_length){
2997 //printk(KERN_DEBUG "frame_len = %x\n", frame_len);
2998 macp->ErrShortFrmCnt++;
2999 return false;
3002 else{
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++;
3007 return false;
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++;
3019 return false;
3022 // Check if the SwRfd->frame_len matched the length derived from PLCP.
3023 bOfdmFrm = (FrameEndInd & BIT_0);
3025 if (bOfdmFrm){
3026 // it's OFDM
3027 macp->rxOFDMDataFrame++;
3028 #ifdef HOST_IF_USB
3029 macp->PHYFreOFDMframe = 1;
3030 #endif
3031 switch(PlcpRate & 0xF){
3032 case 0x0B: //6M
3034 macp->rxInfo.rate = RATE_6M;
3035 break;
3037 case 0x0F: //9M
3038 macp->rxInfo.rate = RATE_9M;
3039 break;
3042 case 0x0A: //12M
3043 macp->rxInfo.rate = RATE_12M;
3045 break;
3047 case 0x0E: //18M
3048 macp->rxInfo.rate = RATE_18M;
3049 break;
3052 case 0x09: //24M
3053 macp->rxInfo.rate = RATE_24M;
3054 break;
3056 case 0x0D: //36M
3057 macp->rxInfo.rate = RATE_36M;
3058 break;
3060 case 0x08: //48M
3061 macp->rxInfo.rate = RATE_48M;
3062 break;
3064 case 0x0C: //54M
3065 macp->rxInfo.rate = RATE_54M;
3066 break;
3068 default:
3069 break;
3073 else{
3074 // it's CCK
3075 macp->rx11bDataFrame++;
3076 // the value from PHY is in scale from Max is 0 and Min is 0xb5
3077 switch(PlcpRate){
3078 case 0x0A:
3080 macp->rxInfo.rate = RATE_1M;
3081 break;
3083 case 0x14:
3084 macp->rxInfo.rate = RATE_2M;
3085 break;
3087 case 0x37:
3088 macp->rxInfo.rate = RATE_5M;
3089 break;
3091 case 0x6E:
3092 macp->rxInfo.rate = RATE_11M;
3093 break;
3095 default:
3096 break;
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
3108 #ifdef HOST_IF_USB
3109 macp->rxSignalQuality = CalculateQuality(macp, rfd, &macp->rxSignalQualityIndB);
3110 macp->rxSignalStrength = CalculateStrength(macp, rfd);
3111 #endif
3112 #if ZDCONF_WE_STAT_SUPPORT == 1
3113 Qual[Qidx++ % 10] = macp->rxSignalQuality;
3114 Str[Qidx % 10] = macp->rxSignalStrength;
3116 if(Qidx % 100 == 0) {
3117 Tmp = 0;
3118 for(idx=0;idx<10;idx++)
3119 Tmp += Qual[idx];
3120 macp->iwstats.qual.qual=Tmp/10;
3122 Tmp = 0;
3123 for(idx=0;idx<10;idx++)
3124 Tmp += Str[idx];
3125 Tmp/=10;
3127 Tmp = -(100 - Tmp);
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"
3143 #endif
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);
3158 #else
3159 mcpu_gpio_inout(LED_GPIO,MCPU_GPIO_OUTPUT);
3160 #endif
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);
3183 #else
3184 u32 pio=1<<WLAN_LED;;
3185 u8 strength=macp->rxSignalStrength;
3186 if(strength>=0)
3187 pio |= (1<<ST1_LED);
3188 if(strength>=20)
3189 pio |= (1<<ST2_LED);
3190 if(strength>=40)
3191 pio |= (1<<ST3_LED);
3192 if(strength>=60)
3193 pio |= (1<<ST4_LED);
3194 if(strength>=70)
3195 pio |= (1<<ST5_LED);
3196 mcpu_gpio_set(LED_GPIO, MCPU_GPIO_HIGH);
3197 mcpu_gpio_set(pio, MCPU_GPIO_LOW);
3198 #endif
3199 macp->led_cnt = 0 ;
3201 else
3202 macp->led_cnt++ ;
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);
3227 #else
3228 unsigned char pio=PIO(WLAN_LED);
3229 u8 strength=macp->rxSignalStrength;
3230 if(strength>=0)
3231 pio |= PIO(STR1_LED);
3232 if(strength>=20)
3233 pio |= PIO(STR2_LED);
3234 if(strength>=40)
3235 pio |= PIO(STR3_LED);
3236 if(strength>=60)
3237 pio |= PIO(STR4_LED);
3238 if(strength>=70)
3239 pio |= PIO(STR5_LED);
3240 *(volatile unsigned char *)WLAN_LED_REG = LED_PIO;
3241 *(volatile unsigned char *)WLAN_LED_REG = ~pio;
3242 #endif
3244 macp->led_cnt = 0 ;
3246 else
3247 macp->led_cnt++ ;
3248 #endif
3249 //prince add for led end
3252 return true;
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.
3261 * Returns:
3262 * 0: if allocation has failed.
3263 * 1: Otherwise.
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));
3277 #ifndef HOST_IF_USB
3278 if (!(macp->txUnCached = pci_alloc_consistent(macp->pdev,
3279 macp->txUnCachedSize, &(macp->txUnCachedPhys)))) {
3280 return 0;
3282 #else
3283 macp->txUnCached = kmalloc(macp->txUnCachedSize, GFP_ATOMIC);
3284 if (!macp->txUnCached){
3285 printk(KERN_ERR "zd1205: kmalloc txCached failed\n");
3286 return 0;
3288 #endif
3290 memset(macp->txUnCached, 0x00, macp->txUnCachedSize);
3291 return 1;
3294 void
3295 zd1205_free_tcb_pool(struct zd1205_private *macp)
3297 #ifndef HOST_IF_USB
3299 pci_free_consistent(macp->pdev, macp->txUnCachedSize,
3301 macp->txUnCached, macp->txUnCachedPhys);
3302 #else
3303 if (macp->txUnCached)
3304 kfree(macp->txUnCached);
3305 #endif
3307 macp->txUnCachedPhys = 0;
3313 static void
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));
3324 #ifndef HOST_IF_USB
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);
3329 #else
3330 if(rx_struct->skb)dev_kfree_skb_any/**/(rx_struct->skb);
3331 #endif
3333 kfree(rx_struct);
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));
3341 kfree(rx_struct);
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
3359 static int
3360 zd1205_alloc_rfd_pool(struct zd1205_private *macp)
3362 struct rx_list_elem *rx_struct;
3363 int i;
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));
3382 void
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
3403 * next ISR.
3405 #ifndef HOST_IF_USB
3406 void zd1205_start_ru(struct zd1205_private *macp)
3407 #else
3408 struct rx_list_elem *zd1205_start_ru(struct zd1205_private *macp)
3409 #endif
3411 #ifndef HOST_IF_USB
3412 u32 tmp_value;
3413 u32 loopCnt = 0;
3414 #endif
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;
3422 ZENTER(4);
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);
3429 if (!rx_struct)
3430 #ifndef HOST_IF_USB
3431 return;
3432 #else
3433 return NULL;
3434 #endif
3436 #ifndef HOST_IF_USB
3437 pci_dma_sync_single(macp->pdev, rx_struct->dma_addr,
3439 macp->rfd_size, PCI_DMA_FROMDEVICE);
3440 #endif
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) {
3446 buffer_found = 1;
3447 break;
3452 /* No available buffers */
3453 if (!buffer_found) {
3454 printk(KERN_ERR "zd1205: No available buffers\n");
3455 #ifndef HOST_IF_USB
3456 return;
3457 #else
3458 return NULL;
3459 #endif
3462 #ifndef HOST_IF_USB
3463 while(1){
3464 tmp_value = zd_readl(DeviceState);
3465 tmp_value &= 0xf0;
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. */
3469 loopCnt++;
3470 if (loopCnt > 10000000)
3471 break;
3473 udelay(1);
3474 continue;
3476 else{
3477 break;
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);
3496 ZEXIT(4);
3498 return;
3499 #else
3501 return rx_struct;
3503 #endif
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;
3512 ZENTER(4);
3514 list_for_each(entry_ptr, &(macp->active_rx_list)){
3515 rx_struct = list_entry(entry_ptr, struct rx_list_elem, list_elem);
3516 if (!rx_struct)
3517 return;
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)
3529 u8 *pBssid;
3530 u8 *pByte;
3531 u32 currPos = 0;
3532 u8 elemId, elemLen;
3533 u8 Zd1202Detected = 0;
3534 u8 BitmapCtrl;
3535 u16 N1;
3536 u16 N2;
3537 u16 quotient;
3538 u16 remainder;
3539 u8 BssType = macp->cardSetting.BssType;
3540 u8 erp;
3541 u16 cap;
3542 u8 preamble = 0;
3543 u16 basicRateMap = 0;
3544 u16 supRateMap = 0;
3545 u8 bErpSta = 0;
3546 int i;
3547 u8 tmpMaxRate = 0x02;
3548 u8 rate;
3549 U16 loopCheck = 0;
3550 U16 flagAdhoc = 0; // Bit 0=1, means SSID same, but BSSID mismatch.
3551 U8 chid;
3552 U8 networkType; // 1: IBSS, 0: ESS
3553 U32 SrcAddrOfBcn;
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];
3563 networkType = 1;
3564 pBssid = pWlanHdr->Address3;
3566 else
3568 networkType = 0;
3569 pBssid = pWlanHdr->Address2;
3570 if (BssType == INDEPENDENT_BSS)
3571 return;
3573 //sequence_number = (*(u16*)(&pWlanHdr->SeqCtrl[0])) >> 4;
3575 if (cap & BIT_5)
3576 preamble = 1;
3577 else
3578 preamble = 0;
3580 //get element
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__);
3590 break;
3592 elemId = *pByte;
3593 elemLen = *(pByte+1);
3595 switch (elemId){
3596 case ELEID_DSPARMS:
3597 chid = *(pByte+2);
3598 if (BssType==INFRASTRUCTURE_BSS && macp->bAssoc && dot11Obj.Channel != *(pByte+2))
3600 macp->bAssoc=0;
3601 printk("Channel changed:%u to %u\n",dot11Obj.Channel,*(pByte+2));
3602 zd_CmdProcess(CMD_ROAMING,0,0);
3604 pByte += (elemLen+2);
3605 break;
3606 case ELEID_SSID:
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");
3616 else
3618 macp->bAssoc=0;
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)
3630 flagAdhoc |= BIT_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);
3641 //else
3643 // macp->bAssoc=0;
3644 // printk("SSID Changed\n");
3645 // zd_CmdProcess(CMD_ROAMING,0,0);
3648 pByte += (elemLen+2);
3649 break;
3653 case 0xfe: //ZyDAS Extended Supported Rate (16.5M)
3654 case 0xff: //ZyDAS Extended Supported Rate (27.5M)
3655 Zd1202Detected = 1;
3657 if (elemLen != 0){ //For possible future compatibility issue,
3658 //we adopt "length = 0", which will not
3659 //disturb others.
3661 pByte += (elemLen+2);
3662 break;
3664 case ELEID_TIM:
3665 if ((BssType == INFRASTRUCTURE_BSS) && (macp->bAssoc)){
3666 if (elemLen >= 3){
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);
3676 break;
3679 if ((*(pByte+5+quotient-N1) >> remainder) & BIT_0 ){
3680 if(macp->bAssoc)
3682 //zd_EventNotify(EVENT_MORE_DATA, 0, 0, 0);
3683 dot11Obj.bMoreData = 1;
3684 zd_PsPoll();
3685 macp->bAnyActivity = 1;
3688 else{
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);
3700 break;
3703 case ELEID_ERP_INFO:
3704 if (macp->bAssoc){
3705 erp = *(pByte+2);
3707 if (erp & USE_PROTECTION_BIT){
3708 if (!(dot11Obj.ConfigFlag & ENABLE_PROTECTION_SET))
3709 defer_kevent(macp, KEVENT_EN_PROTECTION);
3711 else {
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);
3721 else {
3722 if (dot11Obj.ConfigFlag & BARKER_PREAMBLE_SET)
3723 defer_kevent(macp, KEVENT_DIS_BARKER);
3726 // check B-STA
3727 if (erp & NON_ERP_PRESENT_BIT){
3728 if (dot11Obj.ConfigFlag & SHORT_SLOT_TIME_SET){
3729 defer_kevent(macp, KEVENT_DIS_SHORT_SLOT);
3732 else {
3733 if (!(dot11Obj.ConfigFlag & SHORT_SLOT_TIME_SET)){
3734 defer_kevent(macp, KEVENT_EN_SHORT_SLOT);
3739 pByte += (elemLen+2);
3740 break;
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);
3752 break;
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);
3766 break;
3768 default:
3769 pByte += (elemLen+2);
3770 break;
3774 currPos += (elemLen+2);
3778 if (Zd1202Detected){
3779 macp->BSS_Members |= MEMBER_ZD1202;
3781 else{
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
3806 bErpSta = 1;
3807 else
3808 bErpSta = 1;
3810 else
3811 bErpSta = 0;
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)){
3816 #ifdef HOST_IF_USB
3817 defer_kevent(macp, KEVENT_EN_PROTECTION);
3818 ZD1211DEBUG(2, "KEVENT_EN_PROTECTION\n");
3819 #else
3820 zd_EventNotify(EVENT_ENABLE_PROTECTION, 1, 0, 0);
3821 #endif
3826 macp->Bcn_Acc_Num++;
3827 macp->Bcn_Acc_SQ += macp->rxInfo.signalQuality;
3828 return;
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 */
3852 int i;
3853 u32 rfd_status;
3854 struct sk_buff *skb;
3855 struct net_device *dev;
3856 u32 data_sz;
3857 struct rx_list_elem *rx_struct;
3858 u32 rfd_cnt = 0;
3859 plcp_wla_Header_t *wla_hdr;
3860 u8 *pHdr;
3861 u8 *pIv;
3862 u8 *pBody = NULL;
3863 u32 bodyLen = 0;
3864 u32 hdrLen = WLAN_HEADER;
3865 u16 seq = 0;
3866 u8 frag = 0;
3867 u8 *pTa = NULL;
3868 defrag_Array_t *pDefArray = &macp->defragArray;
3869 u8 EthHdr[12];
3870 card_Setting_t *pSetting = &macp->cardSetting;
3871 u8 bDataFrm = 0;
3872 u8 BaseFrmType = 0;
3873 int SaIndex = 0;
3874 u8 BssType=pSetting->BssType;
3875 u8 bSwCheckMIC=0;
3876 BOOLEAN LP_Mode;
3878 u8 rxDecryType = 0;
3880 #ifdef HOST_IF_USB
3881 #if fMERGE_RX_FRAME
3882 int rx_cnt;
3883 struct rx_list_elem **rx_struct_array = macp->rx_struct_array;
3884 int total_rx_cnt = macp->total_rx_cnt;
3885 #else
3886 u8 RunOnce = 0;
3887 #endif
3888 #endif
3890 ZENTER(4);
3891 dev = macp->device;
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++){
3907 #else //PCI
3908 for (i=0; i<macp->numRfd; i++) {
3909 #endif
3911 #if fMERGE_RX_FRAME
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 */
3918 break;
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");
3926 break;
3929 rmb();
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
3939 #ifndef HOST_IF_USB
3940 pci_dma_sync_single(macp->pdev, rx_struct->dma_addr,
3941 macp->rfd_size+PLCP_HEADER+WLAN_HEADER, PCI_DMA_FROMDEVICE);
3942 #endif
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 */
3947 break;
3949 #ifdef HOST_IF_USB
3950 if (RunOnce)
3951 break;
3952 RunOnce = 1;
3953 #endif
3954 macp->DriverRxFrmCnt ++;
3955 /* to allow manipulation with current skb we need to unlink it */
3956 list_del(&(rx_struct->list_elem));
3958 #ifdef HOST_IF_USB
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");
3966 #endif
3968 #endif //end of !fMERGE_RX_FRAME
3969 bSwCheckMIC=0;
3971 data_sz = (u16)(rfd->ActualCount & 0x3fff);
3972 data_sz -= macp->rxOffset;
3973 ZD1211DEBUG(4, "zd1211: data_sz = %x\n", data_sz);
3974 #if 0
3975 //for debug only
3976 if (macp->bPSMSupported)
3977 zd1205_dump_data("RxBuffer", (u8 *)rfd->RxBuffer, data_sz);
3979 //zd1205_add_skb_to_end(macp, rx_struct);
3980 //continue;
3981 #endif
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 */
4004 #ifndef HOST_IF_USB
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);
4008 #endif
4009 if (zd1205_validate_frame(macp, rfd) == false){
4010 //int i;
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: ");
4016 //for(i=0;i<6;i++)
4017 // printk("%02x ", wla_hdr->Address1[i]);
4018 //printk("\nAddr2: ");
4019 //for(i=0;i<6;i++)
4020 // printk("%02x ", wla_hdr->Address2[i]);
4021 //printk("\nAddr3: ");
4022 //for(i=0;i<6;i++)
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);
4031 continue;
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);
4041 continue;
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);
4051 macp->rxDupCnt ++;
4052 continue;
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){
4060 int tmpvalue = -1;
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);
4066 if (tmpvalue == 0)
4067 break;
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");
4079 continue;
4083 if (BaseFrameType(wla_hdr) == DATA){
4084 if (BssType == INFRASTRUCTURE_BSS){
4085 if (memcmp(&macp->BSSID[0], &wla_hdr->Address2[0], 6) != 0){
4086 //BSSID filter
4087 zd1205_add_skb_to_end(macp, rx_struct);
4088 continue;
4090 } else if ((BssType == INDEPENDENT_BSS) || (BssType == PSEUDO_IBSS)){
4091 if (memcmp(&macp->BSSID[0], &wla_hdr->Address3[0], 6) != 0){
4092 //BSSID filter
4093 zd1205_add_skb_to_end(macp, rx_struct);
4094 continue;
4096 } else {
4097 zd1205_add_skb_to_end(macp, rx_struct);
4098 continue;
4101 else {
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;
4110 //frame with WEP
4111 if (bWepBit(wla_hdr)) {
4112 u16 RxIv16 = 0;
4113 u32 RxIv32 = 0;
4114 ZD1211DEBUG(4, "zd1205: wep frame\n");
4116 pIv = pHdr + hdrLen;
4117 pBody += IV_SIZE;
4118 bodyLen = bodyLen - IV_SIZE - ICV_SIZE;
4119 hdrLen += IV_SIZE;
4120 rxDecryType = (macp->rxDecryType & 0x0f);
4122 switch(rxDecryType)
4124 case WEP64:
4125 case WEP128:
4126 case WEP256:
4127 break;
4129 case TKIP:
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)
4139 {//For hostapd
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.
4147 #endif
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
4151 break;
4153 case AES:
4154 //ZD1211DEBUG(0, "Got AES frame !!!\n");
4155 bodyLen -= (MIC_LENGTH);
4156 pBody += EXTEND_IV_LEN;
4157 hdrLen += EXTEND_IV_LEN;
4158 break;
4159 default:
4160 break;
4162 }//end of wep bit
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);
4175 continue;
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)){
4186 bDataFrm = 1;
4188 if (isWDS(wla_hdr)){
4189 //ZD1211DEBUG(3, "***** WDS or group\n");
4190 zd1205_add_skb_to_end(macp, rx_struct);
4191 continue;
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>
4205 goto defrag_ind;
4207 else{ //First fragment
4208 DFDEBUG("***** First Frag");
4209 macp->rxNeedFragCnt++;
4210 i = zd1205_ArFree(macp); //Get a free one
4212 if (i < 0){
4213 zd1205_ArAge(macp, nowT());
4214 i = zd1205_ArFree(macp);
4215 if (i < 0){
4216 DFDEBUG("***** ArFree fail");
4217 macp->DropFirstFragCnt++;
4218 zd1205_add_skb_to_end(macp, rx_struct);
4219 continue;
4223 zd1205_ArUpdate(macp, pTa, seq, frag, i);
4224 pDefArray->mpdu[i].dataStart = pBody;
4225 skb->len = bodyLen;
4226 pDefArray->mpdu[i].buf = (void *)skb; //save skb
4228 #ifndef HOST_IF_USB
4229 pci_unmap_single(macp->pdev, rx_struct->dma_addr,
4230 sizeof (zd1205_RFD_t), PCI_DMA_FROMDEVICE);
4231 #endif
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);
4236 #ifndef HOST_IF_USB
4237 zd1205_alloc_skbs(macp); /* and get them */
4238 #else
4239 tasklet_schedule(&macp->rx_buff_tasklet);
4240 #endif
4241 rfd_cnt++;
4242 zd1205_ArAge(macp, nowT());
4243 continue;
4245 }//end of farg == 0
4246 else{ //more frag
4247 struct sk_buff *defrag_skb;
4248 u8 *pStart;
4250 i = zd1205_ArSearch(macp, pTa, seq, frag); //Get exist one
4251 if (i < 0){
4252 DFDEBUG("***** ArSearch fail");
4253 macp->ArSearchFailCnt++;
4254 zd1205_ArAge(macp, nowT());
4255 zd1205_add_skb_to_end(macp, rx_struct); //discard this one
4256 continue;
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;
4270 skb = defrag_skb;
4271 skb->data = (u8 *)pDefArray->mpdu[i].dataStart; //point mac body
4272 pBody = skb->data;
4273 bodyLen = skb->len;
4274 macp->rxCompFragCnt++;
4275 //if (rxDecryType == TKIP)
4276 // bSwCheckMIC = 1;
4278 //goto defrag_ind; //bug
4279 goto defrag_comp;
4281 else{
4282 DFDEBUG("***** More Frag");
4283 zd1205_ArAge(macp, nowT());
4284 zd1205_add_skb_to_end(macp, rx_struct);
4285 continue;
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);
4299 #if defined(OFDM)
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
4307 macp->bOLBC++;
4308 if (!(dot11Obj.ConfigFlag & ENABLE_PROTECTION_SET) && (macp->bOLBC >= 3))
4310 #ifdef HOST_IF_USB
4311 defer_kevent(macp, KEVENT_EN_PROTECTION);
4312 #else
4313 zd_EventNotify(EVENT_ENABLE_PROTECTION, 1, 0, 0);
4314 #endif
4319 #endif
4320 zd1205_add_skb_to_end(macp, rx_struct);
4321 continue;
4323 else { //STA mode
4324 if (dot11Obj.ConfigFlag & ACTIVE_CHANNEL_SCAN_SET) //path through
4325 goto defrag_ind;
4326 else {
4327 if (BssType == INDEPENDENT_BSS || memcmp(&macp->BSSID[0], &wla_hdr->Address3[0], 6) == 0){ //BSSID filter
4328 macp->bcnCnt++;
4329 zd1205_CheckBeaconInfo(macp, wla_hdr, pBody, bodyLen);
4330 if (macp->bPSMSupported)
4332 //ZD1211DEBUG(0, "AP is alive due to Bcn Rcvd\n");
4334 macp->bAPAlive = 1;
4336 #if 0
4337 else {
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
4342 #ifdef HOST_IF_USB
4344 defer_kevent(macp, KEVENT_EN_PROTECTION);
4345 #else
4346 zd_EventNotify(EVENT_ENABLE_PROTECTION, 1, 0, 0);
4347 #endif
4353 #endif
4354 //discard Beacon
4355 zd1205_add_skb_to_end(macp, rx_struct); /* discard Beacon frames */
4356 continue;
4360 else{
4361 if (bGroup(wla_hdr)){
4362 if ((BssType != AP_BSS) || (BssType != INDEPENDENT_BSS)){
4363 zd1205_add_skb_to_end(macp, rx_struct);
4364 continue;
4369 goto defrag_ind;
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);
4377 continue;
4379 else {
4380 zd1205_add_skb_to_end(macp, rx_struct);
4381 continue;
4383 }//end of sniffer_on
4386 defrag_ind:
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;
4396 else
4398 macp->rxUnicastFrm++;
4399 macp->rxUnicastOctets += hdrLen + bodyLen;
4403 macp->rxCnt++;
4404 #ifndef HOST_IF_USB
4405 pci_unmap_single(macp->pdev, rx_struct->dma_addr,
4406 sizeof (zd1205_RFD_t), PCI_DMA_FROMDEVICE);
4408 #endif
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);
4415 #ifndef HOST_IF_USB
4416 zd1205_alloc_skbs(macp); /* and get them */
4417 #else
4418 tasklet_schedule(&macp->rx_buff_tasklet);
4419 #endif
4421 defrag_comp:
4422 macp->rxInfo.bSwCheckMIC = bSwCheckMIC;
4424 rfd_cnt++;
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){
4435 macp->bAPAlive = 1;
4437 if ((macp->bPSMSupported) && (macp->PwrState) && (!dot11Obj.bDeviceInSleep)){
4438 if (bMoreData(wla_hdr) && macp->bAssoc){
4439 // More date in AP
4440 //zd_EventNotify(EVENT_MORE_DATA, 0, 0, 0);
4441 //if((jiffies / HZ) & 5 == 5)
4442 dot11Obj.bMoreData = 1;
4443 zd_PsPoll();
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)
4453 LP_Mode = TRUE;
4455 #endif
4457 zd_ReceivePkt(pHdr, hdrLen, pBody, bodyLen, (void *)skb, EthHdr, &macp->rxInfo, LP_Mode);
4458 macp->bDataTrafficLight = 1;
4460 else{
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);
4466 skb->dev = dev;
4467 skb->ip_summed = CHECKSUM_NONE;
4468 netif_rx(skb);
4470 }/* end of rfd loop */
4472 //if(macp->skb_req)zd1205_alloc_skbs(macp);//add by johnson
4474 #ifdef HOST_IF_USB
4475 #if !fMERGE_RX_FRAME
4476 if (!RunOnce)
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");
4486 #endif
4487 if (dot11Obj.QueueFlag & TX_QUEUE_SET){
4488 macp->txQueSetCnt++;
4489 //tasklet_schedule(&macp->zd1205_tx_tasklet);
4490 zd_CleanupTxQ();
4493 #else
4494 /* restart the RU if it has stopped */
4495 zd1205_start_ru(macp);
4496 #endif
4497 ZEXIT(4);
4498 return rfd_cnt;
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
4509 * to no resources.
4512 #ifndef HOST_IF_USB
4513 void
4514 zd1205_intr(int irq, void *dev_inst, struct pt_regs *regs)
4516 struct net_device *dev;
4517 struct zd1205_private *macp;
4518 void *regp;
4519 u32 intr_status;
4520 dev = dev_inst;
4521 macp = dev->priv;
4522 regp = macp->regp;
4524 intr_status = zd_readl(InterruptCtrl);
4526 if (!intr_status)
4528 return;
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();
4539 return;
4543 if (macp->driver_isolated) {
4544 goto exit;
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){
4576 macp->bcnCnt++;
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;
4585 macp->dtimCount--;
4592 if (intr_status & DTIM_NOTIFY){
4593 zd_writel((intr_status | DTIM_NOTIFY), InterruptCtrl);
4595 if (macp->dtim_notify_en){
4596 macp->dtimCnt++;
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
4620 // ^ ^ ^ ^ ^ ^
4621 // | | | | | |
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);
4651 exit:
4654 zd1205_enable_int();
4656 #endif
4659 zd1205_open(struct net_device *dev)
4661 struct zd1205_private *macp = dev->priv;
4662 card_Setting_t *pSetting = &macp->cardSetting;
4663 int rc = 0;
4665 ZENTER(0);
4666 #if ZDCONF_LP_SUPPORT == 1
4667 initLP();
4668 #endif
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) {
4677 rc = -EBUSY;
4678 goto exit;
4681 //macp->bUSBDeveiceAttached = 1;
4683 if ((rc = zd1205_alloc_space(macp)) != 0) {
4684 rc = -ENOMEM;
4685 goto exit;
4688 /* setup the tcb pool */
4689 if (!zd1205_alloc_tcb_pool(macp)) {
4690 printk(KERN_ERR "zd1205: failed to zd1205_alloc_tcb_pool\n");
4691 rc = -ENOMEM;
4692 goto err_exit;
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");
4699 rc = -ENOMEM;
4700 goto err_exit;
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);
4710 #endif
4713 #ifndef HOST_IF_USB
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);
4722 #endif
4724 goto err_exit;
4727 zd1205_start_ru(macp);
4728 #endif
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");
4748 goto err_exit;
4752 if(CustomMACSet) {
4753 zd_writel(cpu_to_le32(*(u32 *)macp->macAdr), MACAddr_P1);
4754 zd_writel(cpu_to_le32(*(u32 *)(macp->macAdr+4)), MACAddr_P2);
4757 goto exit;
4759 err_exit:
4760 zd1205_clear_pools(macp);
4762 exit:
4763 //read_unlock(&(macp->isolate_lock));
4764 ZEXIT(0);
4766 return rc;
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);
4773 Q->first = NULL;
4774 Q->last = NULL;
4778 Q->count = 0;
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){
4792 Q->first = signal;
4793 Q->last = signal;
4795 else{
4796 Q->last->next = signal;
4800 Q->last = signal;
4803 Q->count++;
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){
4820 Q->count--;
4821 p = Q->first;
4822 Q->first = (Q->first)->next;
4823 if (Q->first == NULL)
4824 Q->last = NULL;
4830 if(!in_irq())spin_unlock_irqrestore(&macp->q_lock, flags);
4832 return p;
4837 static void
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 */
4846 u32 TcbCount;
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;
4852 u32 HwCtrlPhys;
4853 zd1205_Header_t *pHwHeaderPtr;
4854 u32 HwHeaderPhys;
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);
4861 #if 0
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);
4872 #endif
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;
4881 #ifndef HOST_IF_USB
4882 HwTcbPhys = macp->txUnCachedPhys;
4883 #else
4884 HwTcbPhys = (u32)macp->txUnCached;
4885 #endif
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;
4916 sw_tcb->skb = 0;
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;
4924 #if 0
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;
4944 #endif
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 */
4960 #ifndef HOST_IF_USB
4961 hw_tcb->NextCbPhyAddrLowPart = cpu_to_le32(macp->txUnCachedPhys);
4962 #else
4965 hw_tcb->NextCbPhyAddrLowPart = (U32)macp->txUnCached;
4966 #endif
4967 hw_tcb->NextCbPhyAddrHighPart = 0;
4970 else{
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);
4981 return;
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
4996 * locking is used.
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
5031 * Returns:
5032 * 0 - if successful
5033 * -1 - otherwise
5037 zd1205_set_mac(struct net_device *dev, void *addr)
5039 struct zd1205_private *macp;
5041 int i;
5042 int rc = -1;
5043 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
5046 macp = dev->priv;
5047 read_lock(&(macp->isolate_lock));
5049 if (macp->driver_isolated) {
5050 goto exit;
5054 if(!(p_sockaddr->sa_data[0] & BIT_0))
5055 memcpy(&(dev->dev_addr[0]), p_sockaddr->sa_data, ETH_ALEN);
5056 else
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 ");
5064 for(i=0;i<6;i++)
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);
5082 else {
5083 zd_writel(STA_RX_FILTER, ZD_Rx_Filter);
5085 CustomMACSet = TRUE;
5087 rc = 0;
5090 exit:
5091 read_unlock(&(macp->isolate_lock));
5092 return rc;
5098 void
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);
5111 #endif
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)))
5128 return -EINVAL;
5130 dev->mtu = new_mtu;
5132 return 0;
5137 zd1205_close(struct net_device *dev)
5140 struct zd1205_private *macp = dev->priv;
5142 ZENTER(0);
5144 netif_carrier_off(macp->device);
5147 #if 0
5148 while (dot11Obj.bDeviceInSleep){
5149 wait_ms(10);
5151 #endif
5153 zd1205_isolate_driver(macp);
5156 macp->intrMask = 0;
5157 macp->bAssoc = 0;
5158 mCounterMeasureState = 0;
5159 macp->bGkInstalled = 0;
5160 mGkInstalled=0;
5161 macp->cardSetting.DynKeyMode=0;
5162 mPrivacyInvoked=0;
5163 dot11Obj.MIC_CNT=FALSE;
5166 //zd_writel(0x01, Pre_TBTT);
5170 zd_writel(0x0, BCNInterval);
5172 #ifndef HOST_IF_USB
5173 zd_writel(0x0, LED1);
5174 zd_writel(0x0, LED2);
5175 free_irq(dev->irq, dev);
5176 zd1205_device_reset(macp);
5177 #else
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);
5194 #endif
5198 zd1205_clear_pools(macp);
5200 macp->bPSMSupported = 0;
5201 dot11Obj.bDeviceInSleep = 0;
5205 //set FdescBuf unused
5206 re_initFdescBuf();
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;
5216 ZEXIT(0);
5218 return 0;
5224 u8 CalNumOfFrag(struct zd1205_private *macp, u32 length)
5228 u8 FragNum = 1;
5229 u32 pdusize;
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;
5239 if (FragNum == 0)
5240 FragNum = 1;
5243 return FragNum;
5246 int zd1205_xmit_frame(struct sk_buff *skb, struct net_device *dev)
5248 int rc = 0;
5249 int notify_stop = false;
5250 struct zd1205_private *macp = dev->priv;
5251 #if AAAA03_FIX == 1
5252 struct skb_buff *new_skb = NULL;
5253 #endif
5254 u16 TypeLen;
5255 u8 *pHdr = skb->data;
5256 u32 bodyLen;
5257 u32 TotalLen;
5258 u8 *pBody;
5259 u8 NumOfFrag = 1;
5260 u8 EtherHdr[14];
5261 u8 bEapol = 0;
5262 u8 *pMac = NULL;
5263 Hash_t *pHash = NULL;
5264 u8 bGroupAddr = 0;
5265 card_Setting_t *pSetting = &macp->cardSetting;
5266 u8 bEthType2 = 0;
5267 u8 *pSkbData = skb->data;
5268 u32 SkbLength = skb->len;
5269 BOOLEAN bHashSearchResult;
5271 ZENTER(2);
5273 if(!skb)return 0;
5274 #if AAAA03_FIX == 1
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");
5278 #endif
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++;
5283 return 0;
5285 #endif
5286 //skb = new_skb;
5287 pHdr = skb->data;
5288 pSkbData = skb->data;
5289 SkbLength = skb->len;
5290 #endif
5292 //zd1205_dump_data("tx packet", (u8 *)skb->data, skb->len);
5293 if (pHdr[0] & BIT_0)
5294 bGroupAddr = 1;
5296 read_lock(&(macp->isolate_lock));
5297 if (macp->driver_isolated) {
5298 rc = -EBUSY;
5299 //#if AAAA03_FIX == 1
5300 //dev_kfree_skb/*_irq*/(skb);
5301 //#endif
5302 goto exit2;
5305 if (!spin_trylock(&macp->bd_non_tx_lock)){
5306 notify_stop = true;
5307 rc = 1;
5308 //#if AAAA03_FIX == 1
5309 //dev_kfree_skb/*_irq*/(skb);
5310 //#endif
5311 goto exit2;
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
5318 notify_stop = true;
5319 rc = 1;
5320 //#if AAAA03_FIX == 1
5321 //dev_kfree_skb/*_irq*/(skb);
5322 //#endif
5323 goto exit1;
5326 if (pSetting->BssType == INFRASTRUCTURE_BSS)
5327 pMac = macp->BSSID;
5328 else if (pSetting->BssType == INDEPENDENT_BSS)
5329 pMac = pHdr;
5331 bHashSearchResult = zd_QueryStaTable(pMac, (void**)&pHash);
5332 if ((!macp->bAssoc) || ((!bHashSearchResult) && (!bGroupAddr))){
5333 //dev_kfree_skb/*_irq*/(skb);
5334 rc = 0;
5335 goto exit1;
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);
5343 rc=0;
5344 goto exit1;
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);
5353 rc = 0;
5354 goto exit1;
5357 else {
5358 if (mCurrConnUser==0 || ((pSetting->DynKeyMode) && (mGkInstalled == 0))) {
5359 //dev_kfree_skb/*_irq*/(skb);
5360 rc = 0;
5361 goto exit1;
5366 if (TypeLen > 1500){ /* Ethernet 2 frame */
5367 bEthType2 = 1;
5368 bodyLen = skb->len - 6;
5369 } else {
5370 bEthType2 = 0;
5371 bodyLen = TypeLen;
5374 TotalLen = bodyLen + WLAN_HEADER; //Mac Header(24)
5375 NumOfFrag = CalNumOfFrag(macp, TotalLen);
5377 if (macp->freeTxQ->count < (NumOfFrag+1)){
5378 macp->txQueToUpCnt++;
5379 notify_stop = true;
5380 rc = 1;
5381 //#if AAAA03_FIX == 1
5382 //dev_kfree_skb/*_irq*/(skb);
5383 //#endif
5384 goto exit1;
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));
5399 else
5400 memcpy(pHdr+6, (void *)ZD_SNAP_HEADER, sizeof(ZD_SNAP_HEADER));
5402 if (TypeLen == EAPOL ) {
5403 WPADEBUG("Transmit EAPOL packet\n");
5404 bEapol = 1;
5407 skb->len -= 6; /* Minus DA, SA; Plus 802.2LLC Header */
5408 bodyLen = skb->len;
5409 skb->data += 6;
5411 else{ /* 802.3 frame */
5412 /* DA(6) SA(6) Len(2) 802.2_LLC(3) 802.2_SNAP(3+2) Data.... */
5413 skb->len -= 14;
5414 bodyLen = TypeLen;
5415 skb->data += 14;
5418 pBody = skb->data;
5420 #if 0
5421 //force release for debug only
5422 dev_kfree_skb_irq(skb);
5423 rc = 0;
5424 goto exit1;
5425 #endif
5426 if (!zd_SendPkt(EtherHdr, pBody, bodyLen, (void *)skb, bEapol, pHash)){
5427 notify_stop = true;
5428 rc = 1;
5429 //restore skb data structure
5430 skb->data = pSkbData;
5431 skb->len = SkbLength;
5432 goto exit1;
5435 macp->drv_stats.net_stats.tx_bytes += skb->len;
5436 macp->drv_stats.net_stats.tx_packets++;
5438 exit1:
5439 spin_unlock(&macp->bd_non_tx_lock);
5441 exit2:
5442 read_unlock(&(macp->isolate_lock));
5444 if (notify_stop) {
5445 //netif_carrier_off(dev);
5446 netif_stop_queue(dev);
5449 ZEXIT(2);
5450 #if 0 // mask by Victor Yu. 04-04-2007
5451 #if AAAA03_FIX == 1
5452 rc = 0;
5453 #endif
5454 #endif
5456 return rc;
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)
5467 do_div(n, base);
5468 return (u32)n;
5470 #endif
5473 void zd1205_sleep_reset(struct zd1205_private *macp)
5475 u32 tmpvalue;
5476 u32 ul_pretbtt;
5477 u32 ul_BcnItvl;
5478 u64 TSFTimer;
5479 u32 ul_Rem;
5480 U16 loopCheck = 0;
5483 #ifndef HOST_IF_USB
5484 unsigned long flags;
5485 #endif
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);
5494 #if 1
5495 ul_BcnItvl = zd_readl(ZD_BCNInterval) & 0xFFFF;
5496 HW_UpdatePreTBTT(&dot11Obj, ul_BcnItvl-BEFORE_BEACON);
5497 ul_pretbtt = zd_readl(ZD_Pre_TBTT);
5498 #else
5499 ul_BcnItvl = dot11Obj.BeaconInterval;
5500 if (ul_BcnItvl < (BEFORE_BEACON))
5501 ul_BcnItvl=100;
5502 ul_pretbtt = ul_BcnItvl-BEFORE_BEACON;//Adjust Pre-TBTT occur before TBTT */
5503 #endif
5504 //ZD1211DEBUG(1, "Pre_TBTT = %u\n", ul_pretbtt);
5507 while(1){
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);
5526 #else
5527 ul_Rem = victor_do_div(TSFTimer, ul_BcnItvl);
5528 #endif
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
5538 #if 0
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);
5541 #else
5542 zd_writel(BIT_28 | BIT_0, ZD_PS_Ctrl); // Keep Power on of 44MHz Osc while in sleep.
5543 #endif
5544 dot11Obj.bDeviceInSleep = 1;
5545 up(&macp->ps_sem);
5546 macp->sleepCnt++;
5547 break;
5550 mdelay(1);
5553 macp->TxStartTime = 0;
5558 void update_beacon_interval(struct zd1205_private *macp, int val)
5560 int BcnInterval;
5561 int ul_PreTBTT;
5562 int tmpvalue;
5564 BcnInterval = val;
5567 /* One thing must be sure that BcnInterval > Pre_TBTT > ATIMWnd >= 0 */
5568 if(BcnInterval < 5) {
5569 BcnInterval = 5;
5573 ul_PreTBTT = zd_readl(Pre_TBTT);
5575 if(ul_PreTBTT < 4) {
5576 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)
5596 u32 tmp_value;
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 */
5607 wait_ms(5);
5613 void zd1205_recycle_tx(struct zd1205_private *macp)
5616 zd1205_SwTcb_t *sw_tcb;
5619 #if 1
5620 while (macp->activeTxQ->count){
5621 sw_tcb = zd1205_first_txq(macp, macp->activeTxQ);
5622 zd1205_transmit_cleanup(macp, sw_tcb);
5623 macp->txCmpCnt++;
5624 if (!sw_tcb->LastFrag)
5625 continue;
5627 zd_EventNotify(EVENT_TX_COMPLETE, ZD_RETRY_FAILED, (U32)sw_tcb->MsgID, sw_tcb->aid);
5629 #else
5630 if (macp->activeTxQ->count){
5631 sw_tcb = macp->activeTxQ->first;
5632 zd1205_start_download(sw_tcb->TcbPhys);
5634 #endif
5637 void zd1205_process_wakeup(struct zd1205_private *macp)
5639 card_Setting_t *pSetting = &macp->cardSetting;
5641 #ifndef HOST_IF_USB
5642 u32 tmpvalue;
5643 u64 TSFTimer;
5644 #endif
5646 ZENTER(1);
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);
5652 #if 0
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
5660 #endif
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);
5665 #ifndef HOST_IF_USB
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.
5684 #endif
5687 dot11Obj.bDeviceInSleep = 0;
5689 // Solve Sequence number duplication problem after wakeup.
5690 macp->SequenceNum = 0;
5692 #ifndef HOST_IF_USB
5693 zd1205_recycle_tx(macp);
5694 #endif
5696 #ifndef HOST_IF_USB
5697 zd1205_start_ru(macp);
5698 #else
5699 //zd1205_recycle_rx(macp);
5700 #endif
5702 macp->wakeupCnt++;
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.
5746 * Returns :
5747 * true: if S/W was successfully initialized
5749 * false: otherwise
5753 static unsigned char zd1205_sw_init(struct zd1205_private *macp)
5755 //ZENTER(0);
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);
5759 #endif
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);
5774 #ifdef HOST_IF_USB
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);
5780 #endif
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;
5787 #endif
5789 //ZEXIT(0);
5790 return 1;
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.
5809 * Returns:
5810 * true - If the adapter was initialized
5811 * false - If the adapter failed initialization
5813 unsigned char
5814 zd1205_hw_init(struct zd1205_private *macp)
5818 //ZENTER(0);
5819 HW_ResetPhy(&dot11Obj);
5820 HW_InitHMAC(&dot11Obj);
5821 zd1205_config(macp);
5823 //ZEXIT(0);
5824 return true;
5829 void zd1211_set_multicast(struct zd1205_private *macp)
5831 struct net_device *dev = macp->device;
5832 struct dev_mc_list *mc_list;
5833 unsigned int i;
5835 u8 *pKey;
5836 u32 tmpValue;
5837 u8 mcBuffer[192];
5838 u16 mcLen;
5841 if (!(dev->flags & IFF_UP))
5842 return;
5844 if (macp->cardSetting.BssType == AP_BSS)
5845 return;
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);
5869 pKey = mcBuffer;
5871 for (i=0; i<mcLen; i++){
5872 if ((i%6) == 5){
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);
5882 else {
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);
5912 //for debug only
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;
5923 #ifdef HOST_IF_USB
5924 defer_kevent(macp, KEVENT_SET_MULTICAST);
5925 #else
5926 zd1211_set_multicast(macp);
5927 #endif
5932 #ifdef HOST_IF_USB
5933 #define TX_TIMEOUT (4*100) //4sec
5934 #else
5935 #define TX_TIMEOUT (4*1000*1000) //4sec
5936 #endif
5939 * zd1205_watchdog
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.
5946 void
5947 zd1205_watchdog(struct zd1205_private *macp)
5951 card_Setting_t *pSetting = &macp->cardSetting;
5952 u32 TxBytes, RxBytes;
5954 #ifndef HOST_IF_USB
5955 u32 diffTime;
5956 u32 tmpvalue;
5957 #endif
5959 //read_lock(&(macp->isolate_lock));
5961 if (macp->driver_isolated) {
5962 //goto pexit;
5963 return;
5966 if (!netif_running(macp->device)) {
5968 //goto pexit;
5969 return;
5972 rmb();
5974 macp->CheckForHangLoop++;
5975 #if ZDCONF_LP_SUPPORT == 1
5976 if(Turbo_getBurst_Status() && !Turbo_BurstSTA_Check())
5978 Turbo_BurstOff();
5980 else if(!Turbo_getBurst_Status() && Turbo_BurstSTA_Check())
5981 Turbo_BurstOn();
5983 #endif
5985 zd_PerSecTimer();
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)
5994 if(macp->bAssoc)
5995 { // We thought the Station is still associated with AP.
5996 // dump dot11DesiredSsid
5997 //U8 cbTemp;
5998 //U8 ssidLenToDump=dot11DesiredSsid.buf[1];
5999 //for (cbTemp=0; cbTemp<ssidLenToDump; cbTemp++)
6000 // printk("%c", dot11DesiredSsid.buf[2+cbTemp]);
6001 //printk("\n");
6002 mTmRetryConnect=0;
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);
6019 else
6021 zdcb_status_notify(STA_DISASSOCIATED, &macp->BSSID[0]);
6024 macp->NoBcnDetectedCnt = 0;
6025 //defer_kevent(macp, KEVENT_DIS_CONNECT);
6028 else
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.
6035 else
6036 { // macp->bAssoc ==0, we are in disconnected state.
6038 //printk(KERN_ERR "***** We are disconnected\n");
6039 mTmRetryConnect++;
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))
6046 mTmRetryConnect=0;
6049 else
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;
6075 else
6076 {// OLBC condition exist.
6077 macp->nOLBC_CounterInSec=0;
6080 macp->bOLBC=0;
6082 }// End of AP_BSS condition
6083 /*===prince add begin
6084 else if( pSetting->BssType == INDEPENDENT_BSS )
6086 if ( mMacMode == PURE_A_MODE )
6088 U32 myrand ;
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 );
6099 prince add end==*/
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;
6109 else
6110 macp->SuggestionMode = PS_CAM;
6113 macp->TotalTxDataFrmBytes = 0;
6114 macp->TotalRxDataFrmBytes = 0;
6120 void
6121 zd1205_watchdog_cb(struct net_device *dev)
6123 struct zd1205_private *macp = dev->priv;
6125 #ifdef HOST_IF_USB
6126 defer_kevent(macp, KEVENT_WATCH_DOG);
6127 mod_timer(&(macp->watchdog_timer), jiffies+(1*HZ));
6128 #else
6129 zd1205_watchdog(macp);
6130 mod_timer(&(macp->watchdog_timer), jiffies+(1*HZ));
6131 #endif
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.
6147 * Returns:
6149 * true: if successfull
6150 * false: otherwise
6152 #ifndef HOST_IF_USB
6153 static unsigned char
6154 zd1205_pci_setup(struct pci_dev *pcid, struct zd1205_private *macp)
6157 struct net_device *dev = macp->device;
6160 int rc = 0;
6162 ZENTER(0);
6163 if ((rc = pci_enable_device(pcid)) != 0) {
6164 goto err;
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");
6177 else{
6180 printk(KERN_ERR "zd1205: No suitable DMA available.\n");
6181 goto err;
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) {
6196 goto err_disable;
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);
6210 if (!macp->regp) {
6211 printk(KERN_ERR "zd1205: %s: Failed to map PCI address 0x%lX\n",
6212 dev->name, pci_resource_start(pcid, 0));
6213 rc = -ENOMEM;
6214 goto err_region;
6216 else
6217 printk(KERN_DEBUG "zd1205: mapping base addr = %x\n", (u32)macp->regp);
6219 ZEXIT(0);
6220 return 0;
6222 err_region:
6223 pci_release_regions(pcid);
6226 err_disable:
6227 pci_disable_device(pcid);
6229 err:
6231 return rc;
6233 #endif
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.
6246 * Returns:
6247 * 0: if the operation was successful
6248 * %-ENOMEM: if memory allocation failed
6254 unsigned char
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");
6263 return 1;
6268 else{
6269 memset(macp->txCached, 0, macp->txCachedSize);
6270 return 0;
6277 static void
6278 zd1205_dealloc_space(struct zd1205_private *macp)
6280 if (macp->txCached)
6281 kfree(macp->txCached);
6287 /* Read the permanent ethernet address from the eprom. */
6288 void
6289 zd1205_rd_eaddr(struct zd1205_private *macp)
6291 #if defined FLASH_MAC
6293 #include <linux/mtd/mtd.h>
6294 struct mtd_info *mtd;
6295 int len;
6296 mtd = get_mtd_device(NULL, 0);
6297 if ( mtd != NULL )
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 );
6305 #else
6308 u32 tmpValue;
6311 //ZENTER(0);
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];
6343 //ZEXIT(0);
6344 #endif
6347 void
6348 zd1205_lock(struct zd1205_private *macp)
6350 #ifndef HOST_IF_USB
6351 spin_lock_bh(&macp->conf_lock);
6352 #else
6353 spin_lock(&macp->conf_lock);
6354 #endif
6357 void
6358 zd1205_unlock(struct zd1205_private *macp)
6360 #ifndef HOST_IF_USB
6361 spin_unlock_bh(&macp->conf_lock);
6362 #else
6363 spin_unlock(&macp->conf_lock);
6364 #endif
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
6376 36,5180,
6377 40,5200,
6378 44,5220,
6379 48,5240,
6380 52,5260,
6381 56,5280,
6382 60,5300,
6383 64,5320,
6384 100,5500,
6385 104,5520,
6386 108,5540,
6387 112,5560,
6388 116,5580,
6389 120,5600,
6390 124,5620,
6391 128,5640,
6392 132,5660,
6393 136,5680,
6394 140,5700,
6396 184,4920,
6397 188,4940,
6398 192,4960,
6399 196,4980,
6400 8,5040,
6401 12,5060,
6402 16,5080,
6403 34,5170,
6404 38,5190,
6405 42,5210,
6406 46,5230,
6408 149,5745,
6409 153,5765,
6410 157,5785,
6411 161,5805,
6412 165,5825
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){
6425 u32 i;
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");
6433 return 0;
6435 #if 0
6436 static u32 Freq_11A_to_channel(const u32 freq) {
6437 u32 i;
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");
6445 return 0;
6448 #endif
6449 #define MIN_KEY_SIZE 5
6451 static int
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)
6467 return -EINVAL;
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;
6477 else {
6478 // if (erq->length > 0){
6479 pSetting->WepKeyLen = MIN_KEY_SIZE;
6480 pSetting->EncryMode = WEP64;
6481 // }
6482 // else {
6483 // pSetting->WepKeyLen = 0; /* Disable the key */
6484 // pSetting->EncryMode = NO_WEP;
6485 // }
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);
6496 else
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;
6507 } */
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;
6515 else
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);
6534 return -EINVAL;
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;
6555 else
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");
6560 return 0;
6562 printk(KERN_DEBUG "Update CardSetting\n");
6565 #ifdef HOST_IF_USB
6566 defer_kevent(macp, KEVENT_UPDATE_SETTING);
6567 #else
6568 zd_UpdateCardSetting(pSetting);
6569 #endif
6570 return 0;
6575 static int
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;
6587 zd1205_lock(macp);
6588 if (pSetting->EncryOnOff){
6589 erq->flags = IW_ENCODE_OPEN;
6592 else {
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;
6598 memset(key, 0, 16);
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) {
6611 erq->length = 0;
6615 zd1205_unlock(macp);
6618 return 0;
6621 static int
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));
6631 if (erq->flags) {
6632 if (erq->length > (IW_ESSID_MAX_SIZE+1))
6633 return -E2BIG;
6635 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
6636 return -EFAULT;
6639 zd1205_lock(macp);
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);
6649 return 0;
6651 static int
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));
6657 return 0;
6661 static int
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];
6666 u8 len;
6668 zd1205_lock(macp);
6670 if (macp->bAssoc){
6671 len = dot11Obj.CurrSsid[1];
6672 memcpy(essidbuf, &dot11Obj.CurrSsid[2], len);
6674 else {
6675 len = macp->cardSetting.Info_SSID[1];
6676 memcpy(essidbuf, &macp->cardSetting.Info_SSID[2], len);
6679 essidbuf[len] = 0;
6680 zd1205_unlock(macp);
6682 erq->flags = 1;
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);
6690 if (erq->pointer)
6691 if ( copy_to_user(erq->pointer, essidbuf, erq->length) )
6692 return -EFAULT;
6693 return 0;
6696 static int
6697 zd1205_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
6699 struct zd1205_private *macp = dev->priv;
6700 int chan = -1;
6701 int fflag=0; //Found Flag
6702 //prince add begin
6703 U16 checkChan;
6704 char *RegionStr;
6705 //prince add end
6707 /*===prince delete
6708 if (macp->cardSetting.BssType == INFRASTRUCTURE_BSS )
6709 return -EINVAL;
6710 =================*/
6712 //prince add begin
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 ) )
6716 return -EINVAL;
6717 //prince add end
6722 if ( (frq->e == 0) && (frq->m <= 1000) ) {
6723 /* Setting by channel number */
6724 chan = frq->m;
6725 fflag=1;
6726 } else {
6727 /* Setting by frequency - search the table */
6728 int mult = 1;
6729 int i;
6731 for (i = 0; i < (6 - frq->e); i++)
6732 mult *= 10;
6734 if(PURE_A_MODE != mMacMode ) {
6735 for (i = 0; i < NUM_CHANNELS; i++)
6736 if (frq->m == (channel_frequency[i] * mult)) {
6737 chan = i+1;
6738 fflag=1;
6739 break;
6742 else {
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];
6747 fflag=1;
6748 break;
6753 //prince delete
6754 // if(PURE_A_MODE != mMacMode) {
6755 if(macp->cardSetting.MacMode != PURE_A_MODE ) {
6756 /*prince delete
6757 if ( (chan < 1) || (14 > chan) ) {
6759 printk("We Can't Found Required Channel in ioctl_setfreq(2.4G)\n");
6760 return -EINVAL;
6763 //prince1 add begin
6765 if ( (chan < 1) || ( 14 < chan) ) {
6766 printk("We Can't Found Required Channel in ioctl_setfreq(2.4G)\n");
6767 return -EINVAL;
6769 else
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);
6777 kfree( RegionStr );
6778 return -EINVAL;
6782 //prince add end
6786 else {
6788 if ( (chan < 1) || (0 == fflag) )
6790 printk("We Can't Found Required Channel in ioctl_setfreq(5G)\n");
6791 return -EINVAL;
6794 if( 0 == channel_11A_to_Freq(chan) )
6796 printk("The channel isn't exist(%d)\n",chan);
6797 return -EINVAL;
6802 zd1205_lock(macp);
6803 /*==prince delete
6804 macp->cardSetting.Channel = chan;
6805 =========*/
6806 //prince add begin
6807 macp->ModeChChannel = chan;
6808 //prince add end
6809 macp->IBSS_DesiredChannel = chan;
6810 zd1205_unlock(macp);
6812 return 0;
6818 static int
6819 zd1205_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
6821 struct zd1205_private *macp = dev->priv;
6822 int val = rrq->value;
6824 if (rrq->disabled)
6825 val = 2347;
6827 if ( (val < 0) || (val > 2347) )
6828 return -EINVAL;
6830 zd1205_lock(macp);
6832 macp->cardSetting.RTSThreshold = val;
6833 if (rrq->disabled)
6834 macp->cardSetting.RTSThreshold = 9999;
6836 zd1205_unlock(macp);
6838 return 0;
6842 static int
6843 zd1205_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
6845 struct zd1205_private *macp = dev->priv;
6847 int err = 0;
6849 zd1205_lock(macp);
6851 if (frq->disabled)
6853 macp->cardSetting.FragThreshold = 9999;
6855 else
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");
6862 err = -EINVAL;
6864 else
6865 #endif
6867 if ( (frq->value < 256) || (frq->value > 2346) )
6869 err = -EINVAL;
6871 else
6873 /* must be even */
6874 macp->cardSetting.FragThreshold= frq->value & ~0x1;
6879 zd1205_unlock(macp);
6880 return err;
6883 static int
6884 zd1205_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
6886 struct zd1205_private *macp = dev->priv;
6888 u16 val;
6890 zd1205_lock(macp);
6891 val = macp->cardSetting.FragThreshold;
6892 frq->value = val;
6893 frq->disabled = (val >= 2346);
6894 frq->fixed = 1;
6895 zd1205_unlock(macp);
6897 return 0;
6900 static int
6901 zd1205_ioctl_setrate(struct net_device *dev, struct iw_param *frq)
6903 return 0;
6906 static int
6907 zd1205_ioctl_getrate(struct net_device *dev, struct iw_param *frq)
6909 struct zd1205_private *macp = dev->priv;
6912 frq->fixed = 0;
6913 frq->disabled = 0;
6914 frq->value = 0;
6916 switch(macp->cardSetting.CurrTxRate)
6918 case RATE_1M:
6919 frq->value = 1000000;
6920 break;
6922 case RATE_2M:
6924 frq->value = 2000000;
6925 break;
6927 case RATE_5M:
6928 frq->value = 5500000;
6929 break;
6931 case RATE_11M:
6932 frq->value = 11000000;
6933 break;
6935 case RATE_6M:
6936 frq->value = 6000000;
6937 break;
6939 case RATE_9M:
6940 frq->value = 9000000;
6941 break;
6943 case RATE_12M:
6944 frq->value = 12000000;
6945 break;
6947 case RATE_18M:
6948 frq->value = 18000000;
6949 break;
6951 case RATE_24M:
6952 frq->value = 24000000;
6953 break;
6955 case RATE_36M:
6956 frq->value = 36000000;
6957 break;
6959 case RATE_48M:
6960 frq->value = 48000000;
6961 break;
6963 case RATE_54M:
6964 frq->value = 54000000;
6965 break;
6967 default:
6968 return -EINVAL;
6971 return 0;
6973 #if 1
6974 static int
6975 zd1205_ioctl_settxpower(struct net_device *dev, struct iw_param *prq)
6977 struct zd1205_private *macp = dev->priv;
6978 int ret = 0;
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;
6986 else
6987 ret = -EINVAL;
6989 return ret;
6992 static int
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
7002 prq->flags = 0;
7003 prq->disabled = 0;
7004 prq->fixed = 0;
7006 switch(macp->cardSetting.TxPowerLevel)
7008 case TX_17dbm:
7009 prq->value = 17;
7010 break;
7012 case TX_14dbm:
7013 prq->value = 14;
7014 break;
7016 case TX_11dbm:
7017 prq->value = 11;
7018 break;
7020 default:
7021 return -EINVAL;
7024 return 0;
7026 #endif
7027 static int
7028 zd1205_ioctl_setpower(struct net_device *dev, struct iw_param *frq)
7030 struct zd1205_private *macp = dev->priv;
7032 int err = 0;
7034 zd1205_lock(macp);
7036 if (frq->disabled){
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);
7043 else{
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");
7051 err = -EINVAL;
7053 if(!err)
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);
7065 if(!err)
7066 HW_UpdatePreTBTT(&dot11Obj, dot11Obj.BeaconInterval-BEFORE_BEACON);
7068 return err;
7071 static int
7072 zd1205_ioctl_getpower(struct net_device *dev, struct iw_param *frq)
7074 struct zd1205_private *macp = dev->priv;
7076 zd1205_lock(macp);
7077 if (macp->bPSMSupported)
7078 frq->disabled = 0;
7079 else
7080 frq->disabled = 1;
7081 zd1205_unlock(macp);
7083 return 0;
7086 static long
7087 zd1205_hw_get_freq(struct zd1205_private *macp)
7089 u32 freq;
7090 zd1205_lock(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);
7098 return freq;
7102 static int zd1205_ioctl_setmode(struct net_device *dev, __u32 *mode)
7104 //prince add begin
7105 struct zd1205_private *macp = dev->priv;
7107 switch(*mode) {
7108 case IW_MODE_ADHOC:
7109 ZD1211DEBUG(0, "Switch to Ad-Hoc mode\n");
7110 macp->ModeChBssType = INDEPENDENT_BSS;
7111 break;
7113 case IW_MODE_INFRA:
7114 ZD1211DEBUG(0, "Switch to Infra mode\n");
7115 macp->ModeChBssType = INFRASTRUCTURE_BSS;
7116 break;
7119 case IW_MODE_MASTER:
7120 ZD1211DEBUG(0, "Switch to AP mode\n");
7121 macp->ModeChBssType = AP_BSS;
7122 break;
7123 default:
7124 ZD1211DEBUG(0, "Switch to PSEUDO_IBSS mode\n");
7125 macp->ModeChBssType = PSEUDO_IBSS;
7126 break;
7129 //prince add end
7131 /*prince delete
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");
7140 return 0;
7142 switch(*mode) {
7143 case IW_MODE_ADHOC:
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);
7151 break;
7153 case IW_MODE_INFRA:
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);
7164 break;
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);
7186 break;
7188 default:
7189 ZD1211DEBUG(0, "Switch to PSEUDO_IBSS mode\n");
7190 macp->cardSetting.BssType = PSEUDO_IBSS;
7191 zd_writel(STA_RX_FILTER, Rx_Filter);
7192 break;
7196 macp->bAssoc = 0;
7197 if (macp->usb->speed != USB_SPEED_HIGH)
7198 macp->cardSetting.MacMode = PURE_B_MODE;
7199 else {
7200 #if 0
7201 if (macp->cardSetting.BssType == INDEPENDENT_BSS)
7202 macp->cardSetting.MacMode = PURE_B_MODE;
7203 else
7204 macp->cardSetting.MacMode = MIXED_MODE;
7205 #endif
7208 zd1205_SetRatesInfo(macp);
7210 //zd1205_unlock(macp);
7211 clear_bit(0, &setmodeLock);
7212 =================*/
7213 return 0;
7217 /////////////////////////
7219 static int
7220 zd1205_ioctl_getretry(struct net_device *dev, struct iw_param *prq)
7222 return 0;
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))
7230 return -EINVAL;
7232 macp = dev->priv;
7233 freq->m = zd1205_hw_get_freq(macp);
7234 freq->e = 1;
7235 return 0;
7238 static int zd1205wext_siwmode(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra)
7240 int err;
7241 err = zd1205_ioctl_setmode(dev, mode);
7242 return err;
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))
7252 return -EINVAL;
7254 zd1205_lock(macp);
7256 switch(BssType){
7257 case AP_BSS:
7258 *mode = IW_MODE_MASTER;
7259 break;
7261 case INFRASTRUCTURE_BSS:
7262 *mode = IW_MODE_INFRA;
7263 break;
7265 case INDEPENDENT_BSS:
7266 *mode = IW_MODE_ADHOC;
7267 break;
7269 default:
7270 *mode = IW_MODE_ADHOC;
7271 break;
7274 zd1205_unlock(macp);
7275 return 0;
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))
7281 return -EINVAL;
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;
7289 macp = dev->priv;
7291 if(!netif_running(dev))
7292 return -EINVAL;
7294 rts->value = macp->cardSetting.RTSThreshold;
7295 rts->disabled = (rts->value == 2347);
7296 rts->fixed = 1;
7298 return 0;
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))
7304 return -EINVAL;
7306 return zd1205_ioctl_getfrag(dev, frag);
7308 #if 1
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))
7312 return -EINVAL;
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);
7321 #endif
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;
7325 int i, val;
7326 if(!netif_running(dev))
7327 return -EINVAL;
7330 #if WIRELESS_EXT > 9
7331 range->txpower_capa = IW_TXPOW_DBM;
7332 // XXX what about min/max_pmp, min/max_pmt, etc.
7333 #endif
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 */
7348 val = 0;
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;
7354 val++;
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;
7362 val++;
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;
7396 return 0;
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)
7402 // u8 i;
7403 // u8 oldMacMode;
7404 //u32 ul_mac_ps_state;
7405 //u16 channel;
7406 //BOOLEAN ProbeWithSsid_bak;
7407 struct zd1205_private *macp = g_dev->priv;
7408 u32 wait_cnt = 0;
7410 if(!netif_running(dev))
7411 return -EINVAL;
7413 goto scanning_done;
7414 #if 0
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)
7420 int cnt=0;
7421 cnt++;
7422 if(cnt>500) {
7423 printk("Locked in waitting bChScanning for 5s. Exit!\n");
7424 dot11Obj.bChScanning=FALSE;
7425 CurrScanCH=1;
7426 return 0;
7428 wait_ms(10);
7430 goto scanning_done;
7432 else
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.
7438 wait_ms(1);
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.
7447 zd_ScanBegin();
7448 for (channel=1; channel <= 14; channel++)
7450 zd_CmdScanReq(channel);//Set RF channel then send ProbeRequest
7451 wait_ms(100);
7453 zd_ScanEnd();
7454 dot11Obj.bChScanning=0;
7455 mProbeWithSsid=ProbeWithSsid_bak;
7457 #endif
7458 scanning_done:
7459 if(!dot11Obj.bChScanning) {
7460 if(1 || mAssoc) {
7461 dot11Obj.ConfigFlag |= JUST_CHANNEL_SCAN;
7462 zd_CmdProbeReq(0);
7463 //prince add begin
7464 macp->IBSS_DesiredMacMode = macp->cardSetting.MacMode;
7465 macp->IBSS_DesiredChannel = macp->cardSetting.Channel;
7466 //prince add end
7468 else
7469 ;// This mean there is one just done scanning.
7471 while(dot11Obj.bChScanning) {
7472 if(wait_cnt++ > 200) {
7473 int i;
7474 for(i=0;i<10;i++)
7475 printk(KERN_ERR "UnStoppable Scanning\n");
7476 dot11Obj.bChScanning=0;
7477 break;
7479 wait_ms(50);
7482 zd1205_notify_scan_done(macp);
7483 set_bit(CTX_FLAG_ESSID_WAS_SET, (void *)&macp->flags);
7486 return 0;
7490 #if WIRELESS_EXT > 14
7492 * Encode a WPA or RSN information element as a custom
7493 * element using the hostap format.
7495 static u_int
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)
7500 u8 *p;
7501 int i;
7503 if (bufsize < leader_len)
7504 return 0;
7505 p = buf;
7506 memcpy(p, leader, leader_len);
7507 bufsize -= leader_len;
7508 p += 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,
7521 char *current_ev,
7522 char *end_buf,
7523 bss_info_t *list)
7525 struct iw_event iwe; /* Temporary buffer */
7526 u16 capabilities;
7528 #if WIRELESS_EXT > 14
7529 char buf[64*2 + 30];
7530 #endif
7532 char *current_val; /* For rates */
7533 U32 Tmp;
7534 int i;
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 */
7544 /* Add the ESSID */
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]);
7552 /* Add mode */
7553 iwe.cmd = SIOCGIWMODE;
7554 capabilities = list->cap;
7555 if(capabilities & (0x01 | 0x02)) {
7556 if(capabilities & 0x01)
7557 iwe.u.mode = IW_MODE_MASTER;
7559 else
7560 iwe.u.mode = IW_MODE_ADHOC;
7561 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
7564 /* Add frequency */
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;
7569 else {
7570 iwe.u.freq.m = channel_11A_to_Freq(iwe.u.freq.m) * 100000;
7572 iwe.u.freq.e = 1;
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 */
7577 iwe.cmd = IWEVQUAL;
7579 #if WIRELESS_EXT > 18
7580 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
7581 |IW_QUAL_NOISE_UPDATED;
7582 #endif
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);
7591 #else
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);
7603 #endif
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");
7615 break;
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);
7623 #endif
7625 /* Add encryption capability */
7627 iwe.cmd = SIOCGIWENCODE;
7628 if(capabilities & 0x10)
7629 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
7630 else
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
7636 * more of magic */
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);
7686 else
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,
7692 &iwe, 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 */
7713 return current_ev;
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;
7721 int i;
7722 static int loop = 0;
7724 if(!netif_running(dev))
7725 return -EINVAL;
7728 //ZENTER(0);
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 */
7734 loop++;
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.
7740 if(loop & BIT_0)
7742 current_ev = zd1205_translate_scan(dev, current_ev,
7743 extra + IW_SCAN_MAX_DATA,
7744 &macp->BSSInfo[i]);
7746 else
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)
7759 while(i--)
7760 printk("Scanning result over the maximum abort\n");
7761 break;
7766 /* Length of data */
7767 data->length = (current_ev - extra);
7768 data->flags = 0; /* todo */
7770 if(!dot11Obj.bChScanning) {
7771 if(1 || mAssoc) {
7772 //prince add begin
7773 macp->cardSetting.MacMode = macp->IBSS_DesiredMacMode;
7774 macp->cardSetting.Channel = macp->IBSS_DesiredChannel;
7775 //prince add end
7780 return 0;
7783 #endif
7784 #ifdef ZDCONF_APDBG
7785 void zd1205_dumpEEPROM(struct zd1205_private *macp) {
7786 int i,ret;
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);
7796 if( 0xff == ret ) {
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]);
7818 #endif
7820 void zd1205_list_bss(struct zd1205_private *macp)
7822 int i, j;
7823 u16 cap;
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];
7833 printk("\n");
7834 printk("%2d ",i+1);
7835 for (j=0; j<pBssInfo->ssid[1]; j++)
7837 printk("%c", pBssInfo->ssid[2+j]);
7839 printk("\n");
7840 printk(" ");
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);
7848 printk(" ");
7850 cap = pBssInfo->cap;
7851 cap &= (0x10 | 0x02 | 0x01);
7853 switch(cap)
7855 case 0x01:
7856 printk(" I");
7857 break;
7859 case 0x02:
7860 printk(" A");
7861 break;
7863 case 0x11:
7864 printk("Iw");
7865 break;
7867 case 0x12:
7868 printk("Aw");
7869 break;
7871 default :
7872 break;
7875 printk(" ");
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)
7882 printk(",");
7885 printk(" ");
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)
7890 printk(",");
7894 if (pBssInfo->apMode == PURE_B_AP)
7895 printk(" B-AP");
7896 else if (pBssInfo->apMode == PURE_G_AP)
7897 printk(" G-AP");
7898 else if (pBssInfo->apMode == MIXED_AP)
7899 printk(" M-AP");
7900 else if (pBssInfo->apMode == PURE_A_AP)
7901 printk(" A-AP");
7902 else
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);
7914 else
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);
7928 else
7929 printk(" AMSDU_Off");
7932 #endif
7933 #if ZDCONF_SES_SUPPORT == 1
7934 if(pBssInfo->SES_Element_Valid)
7936 printk(" SES(%d)", pBssInfo->SES_Element.buf[1]);
7938 #endif
7940 printk("\n");
7945 /////////////////////////////////////////
7947 zd1205_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7949 struct zd1205_private *macp;
7950 void *regp;
7951 struct zdap_ioctl zdreq;
7952 struct iwreq *wrq = (struct iwreq *)ifr;
7953 int err = 0;
7954 int changed = 0;
7956 macp = dev->priv;
7957 regp = macp->regp;
7959 if(!netif_running(dev))
7960 return -EINVAL;
7961 down(&macp->ioctl_sem);
7963 switch (cmd) {
7964 case SIOCGIWNAME:
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");
7968 break;
7970 case SIOCGIWAP:
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);
7976 else {
7977 if(macp->bAssoc)
7978 memcpy(wrq->u.ap_addr.sa_data, macp->BSSID, 6);
7979 else
7980 memset(wrq->u.ap_addr.sa_data, 0, 6);
7982 break;
7984 case SIOCGIWRANGE:
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)))
7992 err = -EFAULT;
7994 break;
7996 case SIOCSIWMODE:
7997 ZD1211DEBUG(1, "%s: SIOCSIWMODE\n", dev->name);
7998 err = zd1205wext_siwmode(dev, NULL, &wrq->u.mode, NULL);
7999 /*==prince delete
8000 if (!err)
8001 changed = 1;
8002 break;
8003 ====*/
8004 //prince add begin
8005 if ( !err )
8006 changed = 1;
8007 if ((!err) && changed) {
8008 #ifdef HOST_IF_USB
8009 defer_kevent(macp, KEVENT_DIS_UPDATE_SETTING );
8010 #else
8011 zd1205_dis_update_setting( macp);
8013 #endif
8016 up(&macp->ioctl_sem);
8017 return err;
8018 //prince add end
8020 case SIOCGIWMODE:
8021 ZD1211DEBUG(1, "%s: SIOCGIWMODE\n", dev->name);
8022 err = zd1205wext_giwmode(dev, NULL, &wrq->u.mode, NULL);
8023 break;
8025 case SIOCSIWENCODE:
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){
8032 err = -E2BIG;
8033 break;
8036 if (copy_from_user(keybuf, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
8037 err = -EFAULT;
8038 break;
8042 zd1205_dump_data("keybuf", keybuf, wrq->u.encoding.length);
8043 err = zd1205_ioctl_setiwencode(dev, &wrq->u.encoding, keybuf);
8045 if (!err)
8046 changed = 0;
8048 break;
8050 case SIOCGIWENCODE:
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))
8059 err = -EFAULT;
8062 break;
8064 case SIOCSIWESSID:
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)
8068 changed = 1;
8069 /*===prince delete
8070 break;
8071 ===*/
8072 //prince add begin
8073 if ((!err) && changed) {
8074 #ifdef HOST_IF_USB
8075 defer_kevent(macp, KEVENT_DIS_UPDATE_SETTING );
8076 #else
8077 zd1205_dis_update_setting( macp );
8078 #endif
8081 up(&macp->ioctl_sem);
8082 return 0;
8083 //prince add end
8084 case SIOCSIWAP:
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);
8090 changed = 1;
8093 break;
8095 case SIOCGIWESSID:
8096 ZD1211DEBUG(1, "%s: SIOCGIWESSID\n", dev->name);
8097 err = zd1205_ioctl_getessid(dev, &wrq->u.essid);
8098 break;
8100 case SIOCGIWFREQ:
8101 ZD1211DEBUG(1, "%s: SIOCGIWFREQ\n", dev->name);
8102 wrq->u.freq.m = zd1205_hw_get_freq(macp);
8103 wrq->u.freq.e = 1;
8104 break;
8106 case SIOCSIWFREQ:
8107 ZD1211DEBUG(1, "%s: SIOCSIWFREQ\n", dev->name);
8109 err = zd1205_ioctl_setfreq(dev, &wrq->u.freq);
8110 if ( err == 0 )
8111 changed = 1;
8112 //===prince add begin
8113 if ( changed )
8115 #ifdef HOST_IF_USB
8116 defer_kevent(macp, KEVENT_DIS_UPDATE_SETTING);
8117 #else
8118 zd1205_dis_update_setting(macp);
8119 #endif
8122 up(&macp->ioctl_sem);
8123 return 0;
8124 //prince add end
8125 /*==prince delete
8126 break;
8127 =====*/
8128 case SIOCGIWRTS:
8129 ZD1211DEBUG(1, "%s: SIOCGIWRTS\n", dev->name);
8130 zd1205wext_giwrts(dev, NULL, &wrq->u.rts, NULL);
8131 break;
8133 case SIOCSIWRTS:
8134 ZD1211DEBUG(1, "%s: SIOCSIWRTS\n", dev->name);
8137 err = zd1205_ioctl_setrts(dev, &wrq->u.rts);
8138 if (! err)
8139 changed = 1;
8140 break;
8142 case SIOCSIWFRAG:
8143 ZD1211DEBUG(1, "%s: SIOCSIWFRAG\n", dev->name);
8145 err = zd1205_ioctl_setfrag(dev, &wrq->u.frag);
8146 if (! err)
8147 changed = 1;
8148 break;
8150 case SIOCGIWFRAG:
8151 ZD1211DEBUG(1, "%s: SIOCGIWFRAG\n", dev->name);
8152 err = zd1205_ioctl_getfrag(dev, &wrq->u.frag);
8153 break;
8155 case SIOCSIWRATE:
8156 ZD1211DEBUG(1, "%s: SIOCSIWRATE\n", dev->name);
8158 err = zd1205_ioctl_setrate(dev, &wrq->u.bitrate);
8159 if (! err)
8160 changed = 1;
8162 break;
8164 case SIOCGIWRATE:
8165 ZD1211DEBUG(1, "%s: SIOCGIWRATE\n", dev->name);
8166 err = zd1205_ioctl_getrate(dev, &wrq->u.bitrate);
8167 break;
8169 case SIOCSIWPOWER:
8170 ZD1211DEBUG(1, "%s: SIOCSIWPOWER\n", dev->name);
8172 err = zd1205_ioctl_setpower(dev, &wrq->u.power);
8173 if (!err)
8174 changed = 0;
8175 break;
8178 case SIOCGIWPOWER:
8179 ZD1211DEBUG(1, "%s: SIOCGIWPOWER\n", dev->name);
8180 err = zd1205_ioctl_getpower(dev, &wrq->u.power);
8181 break;
8183 #if WIRELESS_EXT > 10
8184 case SIOCSIWRETRY:
8185 ZD1211DEBUG(1, "%s: SIOCSIWRETRY\n", dev->name);
8186 err = -EOPNOTSUPP;
8187 break;
8190 case SIOCGIWRETRY:
8191 ZD1211DEBUG(1, "%s: SIOCGIWRETRY\n", dev->name);
8192 err = zd1205_ioctl_getretry(dev, &wrq->u.retry);
8193 break;
8194 #endif /* WIRELESS_EXT > 10 */
8195 case SIOCGIWPRIV:
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" },
8210 /*====prince dlete
8211 { SIOCIWFIRSTPRIV + 0xF , IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "lp_mode" },
8212 ================*/
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));
8222 if (err)
8223 break;
8225 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
8226 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
8227 err = -EFAULT;
8229 break;
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);
8235 break;
8237 case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
8238 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x1 (card_reset)\n", dev->name);
8239 if (! capable(CAP_NET_ADMIN)) {
8240 err = -EPERM;
8241 break;
8244 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
8245 zd1205_lock(macp);
8246 zd1205_device_reset(macp);
8247 zd1205_unlock(macp);
8248 err = 0;
8249 break;
8251 case SIOCIWFIRSTPRIV + 0x2: /* set_auth */
8252 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x2 (set_auth)\n", dev->name);
8253 if (! capable(CAP_NET_ADMIN)) {
8254 err = -EPERM;
8255 break;
8258 int val = *( (int *) wrq->u.name );
8259 if ((val < 0) || (val > 1)){
8260 err = -EINVAL;
8261 break;
8263 else {
8264 zd1205_lock(macp);
8265 macp->cardSetting.AuthMode = val;
8266 zd1205_unlock(macp);
8267 err = 0;
8268 changed = 1;
8271 break;
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)){
8283 return -EFAULT;
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)){
8290 return -EFAULT;
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)){
8297 return -EFAULT;
8300 else {
8301 return -EFAULT;
8304 break;
8306 case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
8307 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x4 (set_preamble)\n", dev->name);
8309 if (! capable(CAP_NET_ADMIN)) {
8310 err = -EPERM;
8311 break;
8314 int val = *( (int *) wrq->u.name );
8316 if ((val < 0) || (val > 1)){
8317 err = -EINVAL;
8318 break;
8320 else {
8321 zd1205_lock(macp);
8323 if (val)
8324 macp->cardSetting.PreambleType = 1;
8325 else
8326 macp->cardSetting.PreambleType = 0;
8328 zd1205_unlock(macp);
8329 err = 0;
8330 changed = 1;
8333 break;
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)){
8346 return -EFAULT;
8349 else {
8350 wrq->u.data.length = 5;
8352 if (copy_to_user(wrq->u.data.pointer, "long", 5)){
8353 return -EFAULT;
8357 break;
8358 case SIOCIWFIRSTPRIV + 0x6: // dump_cnt
8359 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x6 (dump_cnt)\n", dev->name);
8360 zd1205_dump_cnters(macp);
8361 break;
8362 case SIOCIWFIRSTPRIV + 0x7: /* dump_reg */
8363 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x7 (dump_reg)\n", dev->name);
8364 zd1205_dump_regs(macp);
8365 break;
8367 case SIOCIWFIRSTPRIV + 0x8: /* probe */
8368 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x8 (probe)\n", dev->name);
8369 zd_CmdProcess(CMD_PROBE_REQ, 0, 0);
8370 break;
8372 // case SIOCIWFIRSTPRIV + 0x9: /* set_dbgflag */
8373 // ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x9 (set_dbgflag)\n", dev->name);
8375 // if (! capable(CAP_NET_ADMIN)) {
8376 // err = -EPERM;
8377 // break;
8378 // }
8379 // {
8380 // int val = *( (int *) wrq->u.name );
8382 // if ((val < 0) || (val > 5)){
8383 // err = -EINVAL;
8384 // break;
8385 // }
8386 // else {
8387 // zd1205_lock(macp);
8388 // macp->dbg_flag = val;
8389 // zd1205_unlock(macp);
8390 // err = 0;
8391 // }
8392 // }
8393 // break;
8396 case SIOCIWFIRSTPRIV + 0xA: // connect
8397 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0xA (connect)\n", dev->name);
8399 if (! capable(CAP_NET_ADMIN)) {
8400 err = -EPERM;
8401 break;
8404 int val = *( (int *) wrq->u.name );
8406 if ((val < 1) || (val >macp->bss_index)){
8407 err = -EINVAL;
8408 break;
8410 else
8412 U8 bssTypeToConnect;
8413 U16 capabilities;
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);
8433 err = 0;
8434 zd_UpdateCardSetting(&macp->cardSetting);
8436 if (capabilities & (CAP_IBSS | CAP_ESS)) {
8437 zd1205_lock(macp);
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;
8447 else {
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);
8456 err = 0;
8459 break;
8461 #if ZDCONF_LP_SUPPORT == 1
8462 case SIOCIWFIRSTPRIV + 0xF: //LP_MODE
8464 int val = *((int *)wrq->u.name);
8465 if( val == 5) {
8466 dot11Obj.BURST_MODE = 0;
8467 printk("Burst is set 0\n");
8469 else if(val == 4) {
8470 dot11Obj.BURST_MODE = 1;
8471 printk("Burst is set 1\n");
8474 else if(val == 3) {
8475 LP_CNT_SHOW();
8477 else if (val == 2) {
8478 printk("Current LP Mode = %d\n", dot11Obj.LP_MODE);
8480 else if(val == 1) {
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");
8485 return -EINVAL;
8487 zd1205_lock(macp);
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");
8494 else if(val == 0) {
8495 dot11Obj.LP_MODE = 0;
8496 del_timer_sync(&macp->tm_lp_poll_id);
8497 printk("LP_MODE set 0\n");
8499 else
8500 return -EFAULT;
8502 break;
8503 #endif
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)) {
8509 err = -EPERM;
8510 break;
8513 int val = *( (int *) wrq->u.name );
8514 int mac_mode_limit;
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)
8521 mac_mode_limit = 3;
8522 else {
8523 printk("Unknown RF Module. You are not allowed to set mac mode\n");
8524 mac_mode_limit = 0;
8527 if ((val < 1) || (val > mac_mode_limit)){
8528 printk("Max MacMode is 4 !\n");
8529 break;
8530 /*==prince add begin
8531 goto set_mac_mode_err;
8532 ==============*/
8535 else
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);
8554 err = 0;
8555 changed = 1;
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;
8579 err = 0;
8580 changed = 1;
8581 if ((!err) && changed) {
8582 #ifdef HOST_IF_USB
8583 defer_kevent(macp, KEVENT_DIS_UPDATE_SETTING );
8584 #else
8585 zd1205_dis_update_setting(macp);
8586 #endif
8589 up(&macp->ioctl_sem);
8590 return err;
8591 //prince add end
8596 /*=prince delete begin
8597 break;
8598 prince delete end==*/
8600 //===prince add begin
8601 set_mac_mode_err:
8602 up(&macp->ioctl_sem);
8603 return 0;
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;
8616 /*===prince delete
8617 if (copy_to_user(wrq->u.data.pointer, "Mixed Mode", 11)){
8618 return -EFAULT;
8620 ==================*/
8621 //prince add begin
8622 memcpy(wrq->u.data.pointer, "Mixed Mode", 11);
8623 //prince add end
8626 else if (macp->cardSetting.MacMode == PURE_G_MODE){
8627 wrq->u.data.length = 12;
8628 /*====prince delete
8629 if (copy_to_user(wrq->u.data.pointer, "Pure G Mode", 12)){
8630 return -EFAULT;
8632 ===================*/
8633 //prince add begin
8634 memcpy(wrq->u.data.pointer, "Pure G Mode", 12);
8635 //prince add end
8638 else if (macp->cardSetting.MacMode == PURE_B_MODE){
8639 wrq->u.data.length = 12;
8640 /*===prince delete
8641 if (copy_to_user(wrq->u.data.pointer, "Pure B Mode", 12)){
8642 return -EFAULT;
8644 =================*/
8645 //prince add begin
8646 memcpy(wrq->u.data.pointer, "Pure B Mode", 12);
8648 //prince add end
8650 else if (macp->cardSetting.MacMode == PURE_A_MODE) {
8651 wrq->u.data.length = 12;
8652 /*===prince delete
8653 if (copy_to_user(wrq->u.data.pointer, "Pure A Mode", 12)){
8654 return -EFAULT;
8656 =================*/
8657 //prince add begin
8658 memcpy(wrq->u.data.pointer, "Pure A Mode", 12);
8659 //prince add end
8662 else
8663 return -EFAULT;
8665 break;
8667 case SIOCIWFIRSTPRIV + 0xD: // save_conf
8668 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0xD (save_conf)\n", dev->name);
8669 zd1205_save_card_setting(macp);
8670 break;
8671 case SIOCIWFIRSTPRIV + 0x06: // load_conf
8672 ZD1211DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x06 (load_conf)\n", dev->name);
8673 zd1205_load_card_setting(macp, 0);
8674 break;
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))
8685 // return -EFAULT;
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))
8692 // return -EFAULT;
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))
8699 // return -EFAULT;
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))
8706 // return -EFAULT;
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))
8712 // return -EFAULT;
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))
8719 // return -EFAULT;
8720 memcpy(wrq->u.data.pointer, "Mexico", 7);
8723 else
8724 return -EFAULT;
8727 break;
8728 case SIOCIWFIRSTPRIV + 0x9 : //set_Region
8730 int val = *( (int *) wrq->u.name );
8731 U16 checkChan;
8733 if ((val < 1) || (val > 6)){
8734 err = -EINVAL;
8735 break;
8737 else {
8738 switch(val) {
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;
8749 switch(val) {
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
8758 //prince add begin
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);
8765 err = 0;
8766 changed = 1;
8769 //prince add end
8771 break;
8774 //prince add for moxa repeat begin
8776 case SIOCIWFIRSTPRIV + 0xD: //set_moxa_repeat
8777 ZD1211DEBUG(0, "Switch to MOXA REPEAT MODE\n");
8778 err = 0;
8779 if ( !err )
8780 changed = 1;
8781 if ((!err) && changed) {
8782 #ifdef HOST_IF_USB
8783 defer_kevent(macp, KEVENT_MOXA_REPEAT );
8784 #else
8785 zd1205_moxa_repeat( macp );
8787 #endif
8790 up(&macp->ioctl_sem);
8791 return err;
8792 //prince add for repeat function end
8793 ////////////////////////////
8794 #ifdef ZDCONF_MENUDBG
8795 case ZD_MENU_DBG:
8797 u32 in=0,ret=0;
8798 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))){
8799 return -EFAULT;
8801 zd1205_lock(macp);
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);
8806 err = 0;
8808 break;
8809 #endif
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");
8814 return -EFAULT;
8817 //printk(KERN_DEBUG "zd1211: cmd = %2x, reg = 0x%04x, value = 0x%08x\n", zdreq.cmd, zdreq.addr, zdreq.value);
8819 zd1205_lock(macp);
8821 #ifdef HOST_IF_USB
8822 if ( zdreq.cmd == ZD_IOCTL_REG_READ )
8823 zd1205_zd_dbg_ioctl(macp, &zdreq);
8824 else
8826 memcpy(&macp->zdreq, &zdreq, sizeof(zdreq));
8827 defer_kevent(macp, KEVENT_ZD_IOCTL);
8829 #else
8831 zd1205_zd_dbg_ioctl(macp, &zdreq);
8832 #endif
8833 zd1205_unlock(macp);
8834 err = 0;
8836 if ( zdreq.cmd == ZD_IOCTL_REG_READ )
8838 if (copy_to_user(ifr->ifr_data, &zdreq, sizeof (zdreq)))
8839 return -EFAULT;
8842 break;
8843 #ifdef PRODUCTION
8844 case ZDPRODUCTIOCTL:
8845 zd1205_lock(macp);
8846 zdproduction_ioctl(macp, (struct zd_point *)&wrq->u.data);
8847 zd1205_unlock(macp);
8848 err = 0;
8849 break;
8850 #endif
8851 case ZD_IOCTL_WPA:
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");
8854 return -EFAULT;
8857 zd1205_lock(macp);
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
8861 #ifdef SMP
8862 defer_kevent(macp, KEVENT_ZD_WPA_IOCTL);
8863 #else
8864 zd1205_wpa_ioctl(macp, &macp->zd_wpa_req);
8865 #endif
8866 zd1205_unlock(macp);
8867 err = 0;
8868 break;
8870 case ZD_IOCTL_PARAM:
8872 int *p;
8873 int op;
8874 int arg;
8876 /* Point to the name field and retrieve the
8877 * op and arg elements. */
8878 p = (int *)wrq->u.name;
8879 op = *p++;
8880 arg = *p;
8882 if(op == ZD_PARAM_COUNTERMEASURES) {
8883 if(arg) {
8884 if(dot11Obj.MIC_CNT)
8885 mCounterMeasureState = 1;
8886 WPADEBUG("CounterMeasure Enable\n");
8888 else {
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 */
8901 if(arg) {
8902 mCap |= CAP_PRIVACY;
8903 macp->cardSetting.EncryOnOff = 1;
8904 WPADEBUG("enable\n");
8906 else {
8907 mCap &= ~CAP_PRIVACY;
8908 macp->cardSetting.EncryOnOff = 0;
8909 WPADEBUG("disable\n");
8912 if(op == ZD_PARAM_WPA) {
8913 WPADEBUG("ZD_PARAM_WPA: ");
8915 if(arg) {
8916 WPADEBUG("enable\n");
8917 macp->cardSetting.WPASupport = 1;
8919 else {
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
8925 * field to zero. */
8926 macp->cardSetting.WPAIe[1] = 0;
8929 if(op == ZD_PARAM_COUNTERMEASURES) {
8930 WPADEBUG("ZD_PARAM_COUNTERMEASURES: ");
8932 if(arg) {
8933 WPADEBUG("enable\n");
8935 else {
8936 WPADEBUG("disable\n");
8939 if(op == ZD_PARAM_DROPUNENCRYPTED) {
8940 WPADEBUG("ZD_PARAM_DROPUNENCRYPTED: ");
8942 if(arg) {
8943 WPADEBUG("enable\n");
8945 else {
8946 WPADEBUG("disable\n");
8949 if(op == ZD_PARAM_AUTH_ALGS) {
8950 WPADEBUG("ZD_PARAM_AUTH_ALGS: ");
8952 if(arg == 0) {
8953 WPADEBUG("OPEN_SYSTEM\n");
8955 else {
8956 WPADEBUG("SHARED_KEY\n");
8960 err = 0;
8961 break;
8962 default:
8963 //ZD1211DEBUG(0, "zd1205: unknown cmd = %2x\n", cmd);
8964 err = -EOPNOTSUPP;
8965 break;
8970 if ((!err) && changed) {
8971 #ifdef HOST_IF_USB
8972 defer_kevent(macp, KEVENT_UPDATE_SETTING);
8973 #else
8974 zd_UpdateCardSetting(&macp->cardSetting);
8975 #endif
8979 up(&macp->ioctl_sem);
8980 return err;
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
8994 * system resources.
8996 * Returns:
8999 * true: if successful
9000 * false: otherwise
9003 unsigned char
9004 zd1205_init(struct zd1205_private *macp)
9006 int i;
9007 u32 tmpValue;
9009 //ZENTER(0);
9010 #if fPROG_FLASH
9011 macp->bAllowAccessRegister = 1;
9012 #endif
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);
9027 #endif
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;
9057 else
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;
9081 for(i=0;i<14;i++)
9083 if((1 << i) & dot11Obj.UW2453SelectAntennaAUX)
9084 dot11Obj.UW2453ChannelSelectAntennaAUX[i] = TRUE;
9085 else
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");
9095 else
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();
9106 ZEXIT(0);
9107 return true;
9112 void zd1205_init_card_setting(struct zd1205_private *macp)
9114 card_Setting_t *pSetting = &macp->cardSetting;
9115 //prince add begin
9116 macp->ModeChBssType = 0x10;
9117 macp->ModeChChannel = 0x00;
9118 macp->ModeChMacMode = 0x00;
9119 //prince add end
9121 #ifndef CFCC
9122 pSetting->BssType = INFRASTRUCTURE_BSS;
9123 #else
9124 pSetting->BssType = INDEPENDENT_BSS;
9125 #endif
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;
9202 else
9203 pSetting->Rate275 = 0;
9204 #else
9205 if (macp->usb->speed != USB_SPEED_HIGH)
9206 pSetting->MacMode = PURE_B_MODE;
9207 else {
9209 //if (pSetting->BssType == INDEPENDENT_BSS)
9210 //pSetting->MacMode = PURE_B_MODE;
9211 //else
9212 pSetting->MacMode = MIXED_MODE;
9214 zd1205_SetRatesInfo(macp);
9215 //pCardSetting->UartEnable = 1;
9216 //pCardSetting->BaudRate = BAUD_RATE_115200;
9219 #endif
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)
9242 int ifp;
9243 int bcount = 0;
9244 mm_segment_t fs;
9245 unsigned int file_length;
9246 u8 *buffer, *old_buffer;
9247 int i, parse_id, count = 0;
9248 char *token;
9249 card_Setting_t *pSetting = &macp->cardSetting;
9250 u8 ssidLen;
9251 u16 frag;
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
9259 fs = get_fs();
9260 set_fs(KERNEL_DS);
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");
9265 set_fs(fs);
9266 return;
9269 /* Get information about the file. */
9270 //fstat (ifp, &file_info);
9271 //sys_fstat(ifp, &file_info);
9272 //file_length = file_info.st_size;
9274 file_length = 512;
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);
9282 // close the file
9283 close(ifp);
9285 // switch back the segment setting
9286 set_fs(fs);
9288 parse_id = 0;
9291 while ((token=strsep((char **)&buffer, "=\n"))){
9292 count++;
9294 if (count % 2){
9295 if (!strcmp(token, "mode"))
9296 parse_id = 1;
9297 else if (!strcmp(token, "essid"))
9298 parse_id = 2;
9299 else if (!strcmp(token, "channel"))
9300 parse_id = 3;
9301 else if (!strcmp(token, "rts"))
9302 parse_id = 4;
9303 else if (!strcmp(token, "frag"))
9304 parse_id = 5;
9305 else
9306 parse_id = 0;
9308 else {
9309 switch (parse_id){
9310 case 1:
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;
9317 break;
9319 case 2:
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];
9326 break;
9328 case 3:
9329 pSetting->Channel = (u8)simple_strtoul(token, &token, 0);
9330 break;
9332 case 4:
9333 pSetting->RTSThreshold = (u16)simple_strtoul(token, &token, 0);
9334 break;
9336 case 5:
9337 frag = (u16)simple_strtoul(token, &token, 0);
9339 if (frag < 256)
9340 frag = 256;
9341 pSetting->FragThreshold = frag;
9342 break;
9344 default:
9345 break;
9349 if (count > 9)
9350 break;
9353 kfree(old_buffer);
9354 if (!bInit)
9355 zd_UpdateCardSetting(pSetting);
9357 //zd1205_show_card_setting(macp);
9358 return;
9361 void zd1205_save_card_setting(struct zd1205_private *macp)
9363 int ifp;
9364 int bcount = 0;
9365 mm_segment_t fs;
9366 unsigned int file_length;
9367 u8 *buffer, *old_buffer;
9368 u8 ssidLen;
9369 char ssid[33];
9370 int write_byte = 0;
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
9379 fs = get_fs();
9380 set_fs(KERNEL_DS);
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");
9386 set_fs(fs);
9387 return;
9390 /* Get information about the file. */
9391 //fstat (ifp, &file_info);
9392 //sys_fstat(ifp, &file_info);
9393 //file_length = file_info.st_size;
9395 file_length = 512;
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;
9413 buffer += bcount;
9415 bcount = snprintf(buffer, file_length, "essid=%s\n", ssid);
9416 ZD1211DEBUG(1, "essid bcount=%d\n", bcount);
9417 write_byte += bcount;
9418 buffer += bcount;
9420 bcount = snprintf(buffer, file_length, "channel=%d\n", pSetting->Channel);
9421 ZD1211DEBUG(1, "channel bcount=%d\n", bcount);
9422 write_byte += bcount;
9423 buffer += bcount;
9425 bcount = snprintf(buffer, file_length, "rts=%d\n", pSetting->RTSThreshold);
9426 ZD1211DEBUG(1, "rts bcount=%d\n", bcount);
9427 write_byte += bcount;
9428 buffer += 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);
9439 // close the file
9440 close(ifp);
9442 // switch back the segment setting
9443 set_fs(fs);
9445 kfree(old_buffer);
9446 return;
9448 #endif
9450 #ifndef HOST_IF_USB
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;
9458 int rc = 0;
9461 ZENTER(0);
9463 dev = alloc_etherdev(sizeof (struct zd1205_private));
9466 if (dev == NULL) {
9467 printk(KERN_ERR "zd1205: Not able to alloc etherdev struct\n");
9468 rc = -ENODEV;
9469 goto out;
9475 g_dev = dev; //save this for CBs use
9476 SET_MODULE_OWNER(dev);
9478 if (first_time) {
9479 first_time = false;
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");
9488 macp = dev->priv;
9489 macp->pdev = pcid;
9490 macp->device = dev;
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;
9499 macp->regp = 0;
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) {
9520 goto err_dev;
9525 if (!zd1205_init(macp)) {
9526 printk(KERN_ERR "zd1025: Failed to initialize, instance \n");
9528 rc = -ENODEV;
9530 goto err_pci;
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) {
9549 goto err_pci;
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";
9562 else
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");
9573 goto out;
9575 err_pci:
9577 iounmap(macp->regp);
9578 pci_release_regions(pcid);
9579 pci_disable_device(pcid);
9582 err_dev:
9584 pci_set_drvdata(pcid, NULL);
9587 kfree(dev);
9589 out:
9590 ZEXIT(0);
9591 return rc;
9593 #endif
9598 * zd1205_clear_structs - free resources
9599 * @dev: adapter's net_device struct
9602 * Free all device specific structs, unmap i/o address, etc.
9605 void
9607 zd1205_clear_structs(struct net_device *dev)
9609 #ifndef HOST_IF_USB
9610 struct zd1205_private *macp = dev->priv;
9611 #endif
9613 zd1205_sw_release();
9614 #ifndef HOST_IF_USB
9615 iounmap(macp->regp);
9616 pci_release_regions(macp->pdev);
9617 pci_disable_device(macp->pdev);
9618 pci_set_drvdata(macp->pdev, NULL);
9619 #endif
9621 //kfree(dev);
9622 free_netdev(dev); //kernel 2,6
9625 #ifndef HOST_IF_USB
9626 void
9627 zd1205_remove1(struct pci_dev *pcid)
9629 struct net_device *dev;
9630 struct zd1205_private *macp;
9633 ZENTER(0);
9635 if (!(dev = (struct net_device *) pci_get_drvdata(pcid)))
9637 return;
9639 macp = dev->priv;
9640 unregister_netdev(dev);
9641 zd1205_remove_proc_subdir(macp);
9642 zd1205_clear_structs(dev);
9645 ZEXIT(0);
9647 #endif
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},
9659 {0,}
9664 MODULE_DEVICE_TABLE(pci, zd1205_id_table);
9668 static struct pci_driver zd1205_driver = {
9669 .name = "zd1205",
9670 .id_table = zd1205_id_table,
9671 .probe = zd1205_found1,
9673 .remove = __devexit_p(zd1205_remove1),
9677 static int __init
9678 zd1205_init_module(void)
9681 int ret;
9683 ret = pci_module_init(&zd1205_driver);
9684 return ret;
9688 static void __exit
9689 zd1205_cleanup_module(void)
9691 pci_unregister_driver(&zd1205_driver);
9694 module_init(zd1205_init_module);
9696 module_exit(zd1205_cleanup_module);
9697 #endif
9699 /*************************************************************************/
9700 BOOLEAN zdcb_setup_next_send(fragInfo_t *frag_info_origin)
9702 int tbdidx;
9703 fragInfo_t *frag_info = frag_info_origin;
9704 #if ZDCONF_LP_SUPPORT == 1
9705 struct lp_desc *lp_bucket = NULL;
9706 U32 xxx;
9707 #endif
9708 U32 PrvFragLen = 0;
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;
9719 zd1205_TBD_t *pTbd;
9720 U8 *hdr, *pBody;
9721 U32 bodyLen, length;
9722 U32 tcb_tbd_num = 0;
9723 int i;
9724 U16 pdu_size = 0;
9726 void *addr;
9727 wla_Header_t *wla_hdr;
9728 U32 CurrFragLen;
9729 U32 NextFragLen;
9731 skb_frag_t *frag = NULL;
9732 ctrl_Set_parm_t ctrl_setting_parms;
9733 U32 TotalLength = 0;
9736 #ifndef HOST_IF_USB
9737 zd1205_SwTcb_t *next_sw_tcb;
9738 U32 tmp_value, tmp_value3;
9739 unsigned long lock_flag;
9740 U32 loopCnt = 0;
9741 #endif
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;
9747 U8 tmpBuf[64];
9749 U32 bodyLength = 0;
9750 U32 cfgLength;
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;
9767 else
9768 LP_Over_Threshold = FALSE;
9769 LP_Threshold_StartTime = jiffies;
9772 #endif
9774 memset(&ctrl_setting_parms,0, sizeof(ctrl_Set_parm_t));
9777 #ifdef HOST_IF_USB
9779 if (!test_bit(ZD1211_RUNNING, &macp->flags))
9780 return FALSE;
9781 #endif
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);
9789 #ifndef HOST_IF_USB
9790 spin_lock_irqsave(&macp->bd_non_tx_lock, lock_flag);
9791 #endif
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;
9802 if (numOfFrag == 0)
9803 numOfFrag = 1;
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);
9813 #ifndef HOST_IF_USB
9814 spin_unlock_irqrestore(&macp->bd_non_tx_lock, lock_flag);
9815 #endif
9816 return FALSE;
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");
9826 return FALSE;
9828 lp_bucket = popPkt(FALSE, 0, nowT());
9829 if(lp_bucket == NULL) {
9830 LP_CNT_PERIOD_POP_FAIL++;
9831 return FALSE;
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;
9839 else if(
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;
9850 int tmpDataTime;
9851 //tmpDataTime = LastData;
9852 //LastData = nowT();
9853 if(pushPkt(frag_info, sstByAid[frag_info->aid]->Turbo_AMSDU_LEN,nowT()) != 0) {
9855 LP_CNT_PUSH_FAIL++;
9856 return FALSE;
9858 LP_CNT_PUSH_SUCC++;
9859 TX_LOOP:
9860 if(macp->freeTxQ->count - 1 < 1) {
9861 printk(KERN_ERR "FreeTxQ[0] is empty to popPkt,N\n");
9862 return TRUE;
9864 lp_bucket = popPkt(FALSE, sstByAid[frag_info->aid]->Turbo_AMSDU_LEN,nowT());
9866 if(lp_bucket == NULL) {
9867 //printk("popPkt NULL\n");
9868 LP_CNT_POP_FAIL++;
9869 return TRUE;
9871 LP_CNT_POP_SUCC++;
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);
9894 else
9895 printk("ADHOC or WDS don't support A-MSDU now\n");
9897 #endif
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;
9932 #endif
9934 #ifdef HOST_IF_USB
9935 //sw_tcb->bHasCompleteBeforeSend = 0;
9936 //sw_tcb->bHasBeenDelayedBefore = 0;
9937 #endif
9938 hdr = frag_info->macHdr[i];
9940 if (macp->dbg_flag > 4)
9941 zd1205_dump_data("header part", (U8 *)hdr, 24);
9944 if (skb){
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;
9953 else
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");
9958 pBody = skb->data;
9959 bodyLen = skb->len;
9961 if (i == (numOfFrag - 1)){
9962 CurrFragLen = bodyLen - i*pdu_size;
9963 NextFragLen = 0;
9964 sw_tcb->LastFrag = 1;
9966 else{
9967 CurrFragLen = pdu_size;
9968 sw_tcb->LastFrag = 0;
9970 if (i == (numOfFrag-2))
9971 NextFragLen = bodyLen - (i+1)*pdu_size;
9972 else
9973 NextFragLen = pdu_size;
9978 else{ //mgt frame
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;
9991 tcb_tbd_num = 0;
9992 hw_tcb->TxCbTbdNumber = 0;
9994 sw_tcb->FrameType = hdr[0];
9995 sw_tcb->MsgID = MsgID;
9996 sw_tcb->aid = aid;
9997 sw_tcb->skb = skb;
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));
10024 #endif
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;
10042 pTbd++;
10043 tcb_tbd_num++;
10044 #if ZDCONF_LP_SUPPORT == 1
10045 cfgLength = length;
10046 #endif
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;
10055 /* MAC Header */
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??
10061 length = hdrLen;
10062 pTbd->TbdBufferAddrLowPart = (u32)hdr;
10066 TotalLength += length;
10067 pTbd->TbdCount = length;
10068 pTbd++;
10069 tcb_tbd_num++;
10071 #if defined(AMAC)
10072 #if ZDCONF_LP_SUPPORT == 1
10073 if(!lp_bucket || !dot11Obj.LP_MODE)
10074 #endif
10075 TotalLength += CurrFragLen;
10076 #ifdef ZD1211
10077 sw_tcb->pHwCtrlPtr->CtrlSetting[18] = (u8)TotalLength;
10078 sw_tcb->pHwCtrlPtr->CtrlSetting[19] = (u8)(TotalLength >> 8);
10079 #endif
10080 #endif
10082 /* Frame Body */
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)
10090 #endif
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);
10097 #else
10098 body_dma = (u32)pBody;
10099 #endif
10101 ZD1211DEBUG(2, "zd1211: body_dma = %x\n", (u32)body_dma);
10103 pTbd->TbdBufferAddrLowPart = body_dma;
10104 pTbd->TbdCount = CurrFragLen;
10105 pBody += CurrFragLen;
10107 #ifdef HOST_IF_USB
10108 pTbd->PrvFragLen = PrvFragLen;
10109 PrvFragLen += CurrFragLen;
10110 #endif
10112 pTbd++;
10113 tcb_tbd_num++;
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++) {
10121 //SLOW DOWN
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;
10126 xxx =
10127 be16_to_cpu(*(U16 *)(lp_bucket->pkt[tbdidx].EthHdr+12)) > 3500;
10128 if(xxx > 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];
10132 bodyLen = 14;
10133 body_dma = (u32)pBody;
10135 if(!body_dma)
10136 printk("!!!!!!!!! body_dma is NULL\n");
10137 pTbd->TbdBufferAddrLowPart = body_dma;
10138 pTbd->TbdCount = bodyLen;
10140 pTbd++;
10141 tcb_tbd_num++;
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;
10149 if(!body_dma)
10150 printk("!!!!!!!!!!!!! body_dma is NULL\n");
10151 pTbd->TbdBufferAddrLowPart = body_dma;
10152 pTbd->TbdCount = bodyLen;
10154 pTbd++;
10155 tcb_tbd_num++;
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;
10169 pTbd++;
10170 tcb_tbd_num++;
10171 TotalLength += bodyLen;
10172 bodyLength += bodyLen;
10178 #endif
10179 else {
10180 while(CurrFragLen ){
10181 u32 body_dma;
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);
10190 #else
10191 body_dma = (u32)addr;
10192 #endif
10193 pTbd->TbdBufferAddrLowPart = body_dma;
10194 pTbd->TbdCount = frag->size;
10195 tcb_tbd_num++;
10196 #ifdef HOST_IF_USB
10197 pTbd->PrvFragLen = PrvFragLen;
10198 PrvFragLen += CurrFragLen;
10199 #endif
10200 CurrFragLen -= frag->size;
10201 frag++;
10203 else{
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));
10209 #else
10210 body_dma = (u32)addr;
10211 #endif
10212 pTbd->TbdBufferAddrLowPart = body_dma;
10213 frag->page_offset += CurrFragLen;
10214 frag->size -= CurrFragLen;
10215 #ifdef HOST_IF_USB
10216 pTbd->PrvFragLen = PrvFragLen;
10217 PrvFragLen += CurrFragLen;
10218 #endif
10219 CurrFragLen = 0;
10222 printk(KERN_DEBUG "zd1205: page_address = %x\n", (u32)addr);
10223 printk(KERN_DEBUG "zd1205: body_dma = %x\n", (u32)body_dma);
10224 pTbd++;
10225 tcb_tbd_num++;
10229 hw_tcb->TxCbTbdNumber = tcb_tbd_num;
10230 macp->txCnt++;
10232 #ifndef HOST_IF_USB
10233 hw_tcb->CbCommand = 0; /* set this TCB belong to bus master */
10234 wmb();
10236 while(1){
10237 tmp_value = zd_readl(DeviceState);
10238 tmp_value &= 0xf;
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. */
10243 loopCnt++;
10245 if (loopCnt > 1000000)
10246 break;
10248 udelay(1);
10249 continue;
10251 else
10252 break;
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 */
10261 macp->txIdleCnt++;
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));
10283 #endif
10285 zd1205_qlast_txq(macp, macp->activeTxQ, sw_tcb);
10287 #ifdef HOST_IF_USB
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;
10297 sw_tcb->MIC_Len=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];
10303 else {
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];
10314 else {
10315 sw_tcb->MIC_Start=0;
10316 sw_tcb->MIC_Len=0;
10318 zd1211_submit_tx_urb(macp,TRUE);
10320 else
10321 zd1211_submit_tx_urb(macp,FALSE);
10322 //zd1205_tx_isr(macp); //for debug only
10323 #endif
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);
10331 #endif
10333 ZD1211DEBUG(2, "===== zdcb_setup_next_send exit =====\n");
10334 return TRUE;
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;
10350 U8 totalValid = 0;
10351 U8 wCnt;
10352 U16 loopCheck = 0;
10354 ZENTER(3);
10355 skb = skb1;
10356 #if ZDCONF_LP_SUPPORT == 1
10357 if(LP_MAP) {
10358 //for(i=0;i<be16_to_cpu(*(U16 *)pData);i++) {
10359 length-=2; //Ignore QoS Ctrl
10360 pData+=2;
10361 wCnt = 0;
10362 while(1)
10364 // Not used for general Driver
10365 if(loopCheck++ > 100)
10367 printk("infinite loop occurs in %s\n", __FUNCTION__);
10368 loopCheck = 0;
10369 break;
10372 wCnt++;
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) ) )
10376 totalValid++;
10377 dataOff+=pktLen;
10378 if(dataOff >= length) break;
10379 dataOff += (4-(dataOff % 4))%4;
10382 if(totalValid == 0)
10384 if(skb)dev_kfree_skb_any/*irq*/(skb);
10385 return;
10387 dataOff = 0;
10388 while(1)
10390 // Not used for General Driver
10391 if(loopCheck++ > 100)
10393 printk("infinite loop occurs in %s\n", __FUNCTION__);
10394 loopCheck = 0;
10395 break;
10398 j++;
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) ) ))
10403 dataOff+=pktLen;
10404 if(dataOff >= length) break;
10405 dataOff += (4-(dataOff % 4))%4;
10406 continue;
10409 if(dataOff + pktLen != length) {
10410 skb = skb_clone(skb1,GFP_ATOMIC);
10411 if(skb == NULL) printk(KERN_ERR "### skb NULL ##\n");
10413 else
10414 skb = skb1;
10415 totalValid--;
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));
10423 printk("\n");
10425 printk("%ldth,Wrong !! dataOff+pktLen > length\n,%ld,%ld",j,dataOff+pktLen,length);
10426 return;
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))
10438 case NET_RX_BAD:
10439 case NET_RX_DROP:
10440 case NET_RX_CN_MOD:
10441 case NET_RX_CN_HIGH:
10442 break;
10443 default:
10444 macp->drv_stats.net_stats.rx_packets++;
10445 macp->drv_stats.net_stats.rx_bytes += skb->len;
10446 break;
10448 dataOff+=pktLen;
10449 if(dataOff >= length) break;
10450 dataOff += (4-(dataOff % 4))%4;
10451 if(totalValid == 0) return;
10453 return;
10455 #endif
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);
10462 if (skb){
10463 skb->dev = g_dev;
10464 skb_reserve(skb, 2);
10465 eth_copy_and_sum(skb, pData, length, 0);
10467 skb_put(skb, length);
10470 else{
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)){
10485 case NET_RX_BAD:
10486 case NET_RX_DROP:
10487 case NET_RX_CN_MOD:
10488 case NET_RX_CN_HIGH:
10489 break;
10491 default:
10492 macp->drv_stats.net_stats.rx_packets++;
10493 macp->drv_stats.net_stats.rx_bytes += skb->len;
10494 break;
10496 ZEXIT(3);
10499 U16 zdcb_status_notify(U16 status, U8 *StaAddr)
10501 struct zd1205_private *macp = g_dev->priv;
10502 U16 result = 0;
10503 int newassoc = 0;
10505 switch (status){
10506 case STA_AUTH_REQ:
10507 break;
10509 case STA_ASOC_REQ:
10510 break;
10512 case STA_REASOC_REQ:
10513 break;
10515 case STA_ASSOCIATED:
10516 case STA_REASSOCIATED:
10517 macp->bAssoc = 1;
10518 mTmRetryConnect=0;
10519 iLED_ON(macp, macp->LinkLEDn);
10520 #ifdef HOST_IF_USB
10521 macp-> LinkTimer = 0;
10523 if (macp->DataLED == 0){
10524 #ifdef ROBIN_KAO
10525 zd_writel(0x03, FW_LINK_STATUS);
10526 #else
10527 zd_writel(0x01, FW_LINK_STATUS);
10528 #endif
10530 else
10531 zd_writel(0x00, FW_LINK_STATUS);
10532 #endif
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));
10545 newassoc = 1;
10547 else
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);
10557 break;
10559 case STA_DISASSOCIATED:
10560 case STA_DEAUTHED:
10561 #ifndef HOST_IF_USB
10562 iLED_OFF(macp, LED1);
10563 #else
10564 zd_writel(0x0, FW_LINK_STATUS);
10565 #endif
10566 macp->bAssoc = 0;
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));
10581 else
10582 ZD1211DEBUG(0, "STA_DEAUTHED:" MACSTR "\n",MAC2STR(StaAddr));
10584 break;
10586 default:
10587 break;
10590 return result;
10594 void zdcb_tx_completed(void)
10599 void chal_tout_cb(unsigned long ptr)
10601 #ifdef HOST_IF_USB
10602 struct zd1205_private *macp = g_dev->priv;
10603 defer_kevent(macp, KEVENT_TCHAL_TIMEOUT);
10604 #else
10605 zd_EventNotify(EVENT_TCHAL_TIMEOUT, 0, 0, 0);
10606 #endif
10609 void scan_tout_cb(unsigned long ptr)
10611 #ifdef HOST_IF_USB
10612 struct zd1205_private *macp = g_dev->priv;
10613 defer_kevent(macp, KEVENT_SCAN_TIMEOUT);
10614 #else
10615 zd_EventNotify(EVENT_SCAN_TIMEOUT, 0, 0, 0);
10616 #endif
10619 void asoc_tout_cb(unsigned long ptr)
10621 #ifdef HOST_IF_USB
10622 struct zd1205_private *macp = g_dev->priv;
10623 defer_kevent(macp, KEVENT_AUTH_TIMEOUT);
10624 #else
10625 zd_EventNotify(EVENT_ASOC_TIMEOUT, 0, 0, 0);
10626 #endif
10629 void auth_tout_cb(unsigned long ptr)
10631 #ifdef HOST_IF_USB
10632 struct zd1205_private *macp = g_dev->priv;
10633 defer_kevent(macp, KEVENT_AUTH_TIMEOUT);
10634 #else
10635 zd_EventNotify(EVENT_AUTH_TIMEOUT, 0, 0, 0);
10636 #endif
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)
10644 return;
10645 timeout_in_jiffies= (timeout*HZ)/1000; // Conver ms to jiffies
10647 switch (event){
10648 case DO_CHAL:
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);
10654 break;
10656 case DO_SCAN:
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);
10662 break;
10665 case DO_AUTH:
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);
10671 break;
10673 case DO_ASOC:
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;
10684 break;
10686 default:
10687 break;
10692 void zdcb_stop_timer(U32 TimerId)
10694 struct zd1205_private *macp = g_dev->priv;
10696 switch (TimerId){
10697 case DO_CHAL:
10698 del_timer(&macp->tm_chal_id);
10699 break;
10701 case DO_AUTH:
10702 if(macp->tm_auth_id.magic == TIMER_MAGIC )
10703 del_timer(&macp->tm_auth_id);
10704 break;
10707 case DO_ASOC:
10708 del_timer(&macp->tm_asoc_id);
10709 AsocTimerStat = FALSE;
10710 break;
10712 default:
10713 break;
10719 zdcb_dis_intr(void)
10721 struct zd1205_private *macp = g_dev->priv;
10722 U32 flags = 0;
10724 #if 1//ndef HOST_IF_USB
10725 if(!in_irq())spin_lock_irqsave(&macp->cs_lock, flags);
10726 #else
10727 spin_lock(&macp->cs_lock);
10728 #endif
10729 return flags;
10732 void
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);
10739 #else
10740 spin_unlock(&macp->cs_lock);
10741 #endif
10744 U32 zdcb_vir_to_phy_addr(U32 virtAddr) //TBD
10746 return virtAddr;
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);
10759 BOOLEAN
10760 zdcb_check_tcb_avail(U8 num_of_frag)
10762 struct zd1205_private *macp = g_dev->priv;
10763 BOOLEAN ret;
10765 U32 flags;
10767 if(!in_irq())spin_lock_irqsave(&macp->q_lock, flags);
10768 if (macp->freeTxQ->count < (num_of_frag+1))
10769 ret = FALSE;
10770 else
10771 ret = TRUE;
10773 if(!in_irq())spin_unlock_irqrestore(&macp->q_lock, flags);
10774 return ret;
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);
10788 #else
10789 interruptible_sleep_on_timeout(&macp->msdelay, delay_jiffies);
10790 #endif
10792 //udelay(ustime);
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);
10800 if (new_skb){
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;
10813 if (first){
10814 next = seed;
10815 first = 0;
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)
10841 Hash_t *pHash;
10843 if (mCounterMeasureState)
10845 #ifdef WPA_DEBUG
10846 printk(KERN_DEBUG "---------In CounterMeasure state, fail AssocReqest\n");
10847 #endif
10848 return 1;
10850 pHash = HashSearch((MacAddr_t *)addr);
10852 /* Can't search the MAC address in the hash table. */
10853 if (pHash == NULL)
10854 return 1;
10855 else {
10856 memcpy(&pHash->WPAIE, WPAIE, sizeof(pHash->WPAIE));
10858 return 0;
10861 void zdcb_MicFailure(unsigned char *addr)
10863 union iwreq_data wrqu;
10864 char buf[128];
10866 /* TODO: needed parameters: count, keyid, key type, src address, TSC */
10867 #ifdef WPA_DEBUG
10868 printk(KERN_ERR "MLME-MICHAELMICFAILURE.indication addr=" MACSTR "\n", MAC2STR(addr));
10869 #endif
10870 memset(&wrqu, 0, sizeof(wrqu));
10871 wrqu.data.length = strlen(buf);
10872 wireless_send_event(g_dev, IWEVCUSTOM, &wrqu, buf);
10875 #endif
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;
10904 // wpa support
10905 #ifdef HOSTAPD_SUPPORT
10906 pObj->MicFailure = zdcb_MicFailure;
10907 pObj->AssocRequest = zdcb_AssocRequest;
10908 pObj->WpaIe = NULL;
10909 #else
10910 // wpa support
10911 pObj->MicFailure = NULL;
10912 pObj->AssocRequest = NULL;
10913 pObj->WpaIe = NULL;
10914 #endif
10918 void zd1205_SetRatesInfo(struct zd1205_private *macp)
10921 u8 bRatesSet = 1;
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
10931 bRatesSet = 1;
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
10938 bRatesSet = 2;
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
10945 bRatesSet = 4;
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
10953 bRatesSet = 3;
10955 else
10956 VerAssert("NULL");
10958 if (bRatesSet == 1){ //wi-fi set1
10959 // supported rates
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
10981 // supported rates
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
11004 // supported rates
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;
11024 /*===prince delete
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];
11063 else
11064 return 225;
11069 u32 X_Constant[] = {
11070 715, 655, 585, 540, 470, 410, 360, 315,
11071 270, 235, 205, 175, 150, 125, 105, 85,
11072 65, 50, 40, 25, 15
11077 u8 X_To_dB(u32 X, u8 rate)
11079 u8 ret = 0;
11080 int i;
11082 int SizeOfX_Con = sizeof(X_Constant);
11084 switch (rate)
11086 case 0x0B: // 6M
11087 case 0x0A: // 12M
11088 case 0x09: // 24M
11089 X /= 2;
11090 break;
11091 case 0x0F: // 9M
11092 case 0x0E: // 18M
11093 case 0x0D: // 36M
11094 case 0x0C: // 54M
11095 X *= 3;
11096 X /= 4;
11097 break;
11098 case 0x08: // 48M
11099 X *= 2;
11100 X /= 3;
11101 break;
11102 default:
11103 break;
11105 for (i=0; i<SizeOfX_Con; i++){
11106 if (X > X_Constant[i])
11107 break;
11110 switch (rate)
11112 case 0x0B: // 6M
11113 case 0x0F: // 9M
11114 ret = i + 3;
11115 break;
11116 case 0x0A: // 12M
11117 case 0x0E: // 18M
11118 ret = i + 5;
11119 break;
11120 case 0x09: // 24M
11121 case 0x0D: // 36M
11122 ret = i + 9;
11123 break;
11124 case 0x08: // 48M
11125 case 0x0C: // 54M
11126 ret = i + 15;
11127 break;
11128 default:
11129 break;
11131 return ret;
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;
11140 u32 X;
11141 u16 tmpf;
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){
11152 // it's OFDM
11153 macp->rxOFDMDataFrame++;
11155 X = 10000 * SignalQuality2 / (frame_len - macp->rxOffset);
11156 CorrectQuality = X_To_dB(X, wla_hdr->PlcpHdr[0] & 0xF);
11158 if (pQualityIndB)
11159 *pQualityIndB = CorrectQuality;
11161 CorrectQuality = (CorrectQuality +0)* 4;
11162 if (CorrectQuality > 100)
11163 CorrectQuality = 100;
11165 else{
11166 // it's CCK
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]){
11171 case 0x0A: //1M
11172 case 0x14: //2M
11173 case 0x37: //5.5M
11174 case 0x6E: //11M
11175 tmpf = 0;
11177 if (macp->rxSignalQuality1 > 0)
11178 tmpf = (u16)(ZDLog10multiply100(macp->rxSignalQuality1) * 20 /100);
11179 CorrectQuality = 45 - (u8)(tmpf);
11181 if (pQualityIndB)
11182 *pQualityIndB = CorrectQuality;
11184 CorrectQuality = (CorrectQuality+5) * 4;
11186 if (CorrectQuality > 100)
11187 CorrectQuality = 100;
11188 break;
11190 default:
11191 break;
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 ?
11204 u32 frame_len;
11205 u32 tot_len;
11206 u8 i, rssi, tmp;
11207 u32 tmpvalue = 2;
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)) &&
11221 (macp->bAssoc) ){
11222 for(i=0; i<macp->PHYTestIndex-1; i++)
11223 tmpvalue *= 2;
11225 //if ( (dot11Obj.CR122Flag == 1)||(dot11Obj.CR203Flag == 1) )
11226 // rssi += 22;
11227 tmp = macp->PHYTestRssi;
11228 macp->PHYTestTotal = macp->PHYTestTotal
11229 - (macp->PHYTestTotal/tmpvalue)
11230 + rssi;
11231 macp->PHYTestRssi = (u8) (macp->PHYTestTotal/tmpvalue);
11234 return rssi;
11237 void zd1205_initCAM(struct zd1205_private *macp)
11239 int i;
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)
11251 u8 *pByte;
11252 u32 currPos = 0;
11253 u8 elemId, elemLen;
11254 u8 gAP = 0;
11255 u8 ErpInfo = 0;
11256 U16 loopCheck = 0;
11258 //get element
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__);
11268 loopCheck = 0;
11269 break;
11272 elemId = *pByte;
11273 elemLen = *(pByte+1);
11275 switch(elemId){
11276 case ELEID_ERP_INFO: //ERP info
11277 gAP = 1;
11278 ErpInfo = *(pByte+2);
11279 pByte += (elemLen+2);
11280 break;
11282 default:
11283 pByte += (elemLen+2);
11284 break;
11288 currPos += elemLen+2;
11291 if (gAP){
11292 if (ErpInfo & NON_ERP_PRESENT_BIT){ //with B sta associated
11293 return 1;
11295 else
11296 return 0;
11298 else // B AP exist, enable protection mode
11299 return 1;
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;
11308 else
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));
11330 /* int ii;
11332 WPADEBUG("zd1205_notfiy_join_event: MAC= ");
11333 for(ii = 0; ii < 6; ii++)
11334 WPADEBUG("%02x ", macp->BSSID[ii] & 0xff);
11335 WPADEBUG("\n");*/
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);
11345 #endif
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");
11356 int ii;
11358 WPADEBUG("zd1205_notfiy_join_event: MAC= ");
11359 for(ii = 0; ii < 6; ii++)
11360 WPADEBUG("%02x ", macp->BSSID[ii] & 0xff);
11361 WPADEBUG("\n");
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);
11372 #endif*/
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,
11384 int keyidx)
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;
11394 else
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,
11406 int keyidx)
11408 union iwreq_data wrqu;
11409 char buf[128];
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,
11425 int keyidx)
11428 #endif /* WIRELESS_EXT >= 15 */
11429 BssInfo_t *zd1212_bssid_to_BssInfo(U8 *bssid)
11431 int i;
11432 for(i=0;i<mBssNum;i++)
11434 if(memcmp(&mBssInfo[i].bssid, bssid, ETH_ALEN) == 0)
11435 return &mBssInfo[i];
11437 return NULL;
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;
11445 else
11447 LongPrint("NULL macp in ChnageMacMode\n",1);
11448 return;
11451 zd1205_lock(macp);
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;
11458 #else
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;
11475 else
11478 if ( Channel > 14 )
11479 macp->cardSetting.Channel = 1;
11483 dot11Obj.Channel = macp->cardSetting.Channel;
11484 macp->bDefaultIbssMacMode=1;
11486 #endif
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
11505 + macp->rxDupCnt;
11507 return &macp->iwstats;
11511 //prince add for dis_update_setting
11512 int zd1205_dis_update_setting( struct zd1205_private *macp)
11514 int retOK = 0;
11515 static size_t dis_update_setting_Lock = 0;
11518 if ( macp->CurrScanCH != 1 && macp->cardSetting.BssType != AP_BSS )
11520 //prince debug
11521 printk(KERN_DEBUG "macp->CurrScanCH:%d pdot11Obj->bChScanning:%d\n",macp->CurrScanCH,pdot11Obj->bChScanning);
11522 if ( macp->LastCurrScanCH == macp->CurrScanCH )
11523 goto update_data;
11524 macp->LastCurrScanCH = macp->CurrScanCH;
11525 return retOK;
11528 update_data:
11530 if(test_and_set_bit(0, (void *)&dis_update_setting_Lock))
11532 printk("change dis_update_setting at the same time\n");
11533 return retOK;
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);
11599 macp->bAssoc = 0;
11601 if (macp->usb->speed != USB_SPEED_HIGH)
11602 macp->cardSetting.MacMode = PURE_B_MODE;
11603 else {
11604 #if 0
11605 if (macp->cardSetting.BssType == INDEPENDENT_BSS)
11606 macp->cardSetting.MacMode = PURE_B_MODE;
11607 else
11608 macp->cardSetting.MacMode = MIXED_MODE;
11609 #endif
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;
11647 retOK = 1;
11648 return retOK;
11655 //prince add for moxa_repeat
11656 int zd1205_moxa_repeat( struct zd1205_private *macp)
11658 int retOK = 0;
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 )
11669 goto update_data;
11670 macp->LastCurrScanCH = macp->CurrScanCH;
11672 return retOK;
11675 update_data:
11677 if(test_and_set_bit(0, (void *)&moxa_repeat_Lock))
11679 printk("change mode at the same time\n");
11680 return retOK;
11684 zd1205_disassoc(macp);
11686 zd1205_lock(macp);
11688 //set Rating
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);
11717 macp->bAssoc = 0;
11719 if (macp->usb->speed != USB_SPEED_HIGH)
11720 macp->cardSetting.MacMode = PURE_B_MODE;
11721 else {
11722 #if 0
11723 if (macp->cardSetting.BssType == INDEPENDENT_BSS)
11724 macp->cardSetting.MacMode = PURE_B_MODE;
11725 else
11726 macp->cardSetting.MacMode = MIXED_MODE;
11727 #endif
11731 clear_bit(0, (void *)&moxa_repeat_Lock);
11733 zd_UpdateCardSetting(&(macp->cardSetting));
11735 retOK = 1;
11736 return retOK;
11741 #elif !defined(ZDCONF_WE_STAT_SUPPORT)
11742 #error "Undefine ZDCONF_WE_STAT_SUPPORT"
11743 #endif