2 * Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
4 * Copyright (C) 2006-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/spinlock.h> /* spinlock_t */
22 #include <linux/sched.h> /* wait_queue_head_t */
23 #include <linux/types.h> /* pid_t */
24 #include <linux/netdevice.h> /* struct net_device_stats, struct sk_buff */
25 #include <linux/etherdevice.h>
26 #include <linux/wireless.h>
27 #include <linux/atomic.h> /* struct atomic_t */
28 #include <linux/timer.h> /* struct timer_list */
29 #include <linux/string.h>
30 #include <linux/completion.h> /* struct completion */
31 #include <linux/workqueue.h>
35 #include "ks7010_sdio.h"
38 #define DPRINTK(n, fmt, args...) \
39 if (KS_WLAN_DEBUG>(n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args)
41 #define DPRINTK(n, fmt, args...)
44 struct ks_wlan_parameter
{
45 u8 operation_mode
; /* Operation Mode */
46 u8 channel
; /* Channel */
47 u8 tx_rate
; /* Transmit Rate */
52 u8 bssid
[ETH_ALEN
]; /* BSSID */
57 u8 preamble
; /* Preamble */
58 u8 powermgt
; /* PowerManagementMode */
59 u32 scan_type
; /* AP List Scan Type */
60 #define BEACON_LOST_COUNT_MIN 0
61 #define BEACON_LOST_COUNT_MAX 65535
62 u32 beacon_lost_count
; /* Beacon Lost Count */
63 u32 rts
; /* RTS Threashold */
64 u32 fragment
; /* Fragmentation Threashold */
71 u16 authenticate_type
;
72 u16 phy_type
; /* 11b/11g/11bg mode type */
73 u16 cts_mode
; /* for 11g/11bg mode cts mode */
74 u16 phy_info_timer
; /* phy information timer */
78 DEVICE_STATE_OFF
= 0, /* this means hw_unavailable is != 0 */
79 DEVICE_STATE_PREBOOT
, /* we are in a pre-boot state (empty RAM) */
80 DEVICE_STATE_BOOT
, /* boot state (fw upload, run fw) */
81 DEVICE_STATE_PREINIT
, /* pre-init state */
82 DEVICE_STATE_INIT
, /* init state (restore MIB backup to device) */
83 DEVICE_STATE_READY
, /* driver&device are in operational state */
84 DEVICE_STATE_SLEEP
/* device in sleep mode */
88 #define SME_MODE_SET (1<<0)
89 #define SME_RTS (1<<1)
90 #define SME_FRAG (1<<2)
91 #define SME_WEP_FLAG (1<<3)
92 #define SME_WEP_INDEX (1<<4)
93 #define SME_WEP_VAL1 (1<<5)
94 #define SME_WEP_VAL2 (1<<6)
95 #define SME_WEP_VAL3 (1<<7)
96 #define SME_WEP_VAL4 (1<<8)
97 #define SME_WEP_VAL_MASK (SME_WEP_VAL1|SME_WEP_VAL2|SME_WEP_VAL3|SME_WEP_VAL4)
98 #define SME_RSN (1<<9)
99 #define SME_RSN_MULTICAST (1<<10)
100 #define SME_RSN_UNICAST (1<<11)
101 #define SME_RSN_AUTH (1<<12)
103 #define SME_AP_SCAN (1<<13)
104 #define SME_MULTICAST (1<<14)
110 SME_MULTICAST_REQUEST
,
111 SME_MACADDRESS_SET_REQUEST
,
112 SME_BSS_SCAN_REQUEST
,
124 SME_POW_MNGMT_REQUEST
,
125 SME_PHY_INFO_REQUEST
,
126 SME_MIC_FAILURE_REQUEST
,
128 SME_GET_PRODUCT_VERSION
,
130 SME_RTS_THRESHOLD_REQUEST
,
131 SME_FRAGMENTATION_THRESHOLD_REQUEST
,
132 SME_WEP_INDEX_REQUEST
,
133 SME_WEP_KEY1_REQUEST
,
134 SME_WEP_KEY2_REQUEST
,
135 SME_WEP_KEY3_REQUEST
,
136 SME_WEP_KEY4_REQUEST
,
137 SME_WEP_FLAG_REQUEST
,
138 SME_RSN_UCAST_REQUEST
,
139 SME_RSN_MCAST_REQUEST
,
140 SME_RSN_AUTH_REQUEST
,
141 SME_RSN_ENABLED_REQUEST
,
142 SME_RSN_MODE_REQUEST
,
144 SME_WPS_ENABLE_REQUEST
,
145 SME_WPS_PROBE_REQUEST
,
151 SME_MODE_SET_REQUEST
,
153 SME_GET_EEPROM_CKSUM
,
155 SME_MIC_FAILURE_CONFIRM
,
158 SME_MULTICAST_CONFIRM
,
159 SME_BSS_SCAN_CONFIRM
,
161 SME_POW_MNGMT_CONFIRM
,
162 SME_PHY_INFO_CONFIRM
,
164 SME_RTS_THRESHOLD_CONFIRM
,
165 SME_FRAGMENTATION_THRESHOLD_CONFIRM
,
166 SME_WEP_INDEX_CONFIRM
,
167 SME_WEP_KEY1_CONFIRM
,
168 SME_WEP_KEY2_CONFIRM
,
169 SME_WEP_KEY3_CONFIRM
,
170 SME_WEP_KEY4_CONFIRM
,
171 SME_WEP_FLAG_CONFIRM
,
172 SME_RSN_UCAST_CONFIRM
,
173 SME_RSN_MCAST_CONFIRM
,
174 SME_RSN_AUTH_CONFIRM
,
175 SME_RSN_ENABLED_CONFIRM
,
176 SME_RSN_MODE_CONFIRM
,
177 SME_MODE_SET_CONFIRM
,
184 SME_EVENT_SIZE
/* end */
195 #define SME_EVENT_BUFF_SIZE 128
199 int event_buff
[SME_EVENT_BUFF_SIZE
];
204 unsigned int max_event_count
;
207 unsigned long sme_flag
;
211 int buff
[SME_EVENT_BUFF_SIZE
];
216 #define RSN_IE_BODY_MAX 64
218 u8 id
; /* 0xdd = WPA or 0x30 = RSN */
219 u8 size
; /* max ? 255 ? */
220 u8 body
[RSN_IE_BODY_MAX
];
224 #define WPS_IE_BODY_MAX 255
226 u8 id
; /* 221 'dd <len> 00 50 F2 04' */
227 u8 size
; /* max ? 255 ? */
228 u8 body
[WPS_IE_BODY_MAX
];
249 struct rsn_ie_t wpa_ie
;
250 struct rsn_ie_t rsn_ie
;
252 struct wps_ie_t wps_ie
;
256 #define LOCAL_APLIST_MAX 31
257 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
258 struct local_aplist_t
{
260 struct local_ap_t ap
[LOCAL_APLIST_MAX
+ 1];
263 struct local_gain_t
{
270 struct local_eeprom_sum_t
{
277 EEPROM_CHECKSUM_NONE
,
278 EEPROM_FW_NOT_SUPPORT
,
282 /* Power Save Status */
292 struct power_save_status_t
{
293 atomic_t status
; /* initialvalue 0 */
294 struct completion wakeup_wait
;
295 atomic_t confirm_wait
;
296 atomic_t snooze_guard
;
299 struct sleep_status_t
{
300 atomic_t status
; /* initialvalue 0 */
301 atomic_t doze_request
;
302 atomic_t wakeup_request
;
308 char ssid
[IW_ESSID_MAX_SIZE
+ 1];
319 #define CIPHER_ID_WPA_NONE "\x00\x50\xf2\x00"
320 #define CIPHER_ID_WPA_WEP40 "\x00\x50\xf2\x01"
321 #define CIPHER_ID_WPA_TKIP "\x00\x50\xf2\x02"
322 #define CIPHER_ID_WPA_CCMP "\x00\x50\xf2\x04"
323 #define CIPHER_ID_WPA_WEP104 "\x00\x50\xf2\x05"
325 #define CIPHER_ID_WPA2_NONE "\x00\x0f\xac\x00"
326 #define CIPHER_ID_WPA2_WEP40 "\x00\x0f\xac\x01"
327 #define CIPHER_ID_WPA2_TKIP "\x00\x0f\xac\x02"
328 #define CIPHER_ID_WPA2_CCMP "\x00\x0f\xac\x04"
329 #define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
331 #define CIPHER_ID_LEN 4
339 #define KEY_MGMT_ID_WPA_NONE "\x00\x50\xf2\x00"
340 #define KEY_MGMT_ID_WPA_1X "\x00\x50\xf2\x01"
341 #define KEY_MGMT_ID_WPA_PSK "\x00\x50\xf2\x02"
342 #define KEY_MGMT_ID_WPA_WPANONE "\x00\x50\xf2\xff"
344 #define KEY_MGMT_ID_WPA2_NONE "\x00\x0f\xac\x00"
345 #define KEY_MGMT_ID_WPA2_1X "\x00\x0f\xac\x01"
346 #define KEY_MGMT_ID_WPA2_PSK "\x00\x0f\xac\x02"
347 #define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
349 #define KEY_MGMT_ID_LEN 4
351 #define MIC_KEY_SIZE 8
354 u32 ext_flags
; /* IW_ENCODE_EXT_xxx */
355 u8 tx_seq
[IW_ENCODE_SEQ_MAX_SIZE
]; /* LSB first */
356 u8 rx_seq
[IW_ENCODE_SEQ_MAX_SIZE
]; /* LSB first */
357 struct sockaddr addr
; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
358 * (group) keys or unicast address for
361 u16 key_len
; /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
362 u8 key_val
[IW_ENCODING_TOKEN_MAX
];
363 u8 tx_mic_key
[MIC_KEY_SIZE
];
364 u8 rx_mic_key
[MIC_KEY_SIZE
];
366 #define WPA_KEY_INDEX_MAX 4
367 #define WPA_RX_SEQ_LEN 6
369 struct mic_failure_t
{
370 u16 failure
; /* MIC Failure counter 0 or 1 or 2 */
371 u16 counter
; /* 1sec counter 0-60 */
372 u32 last_failure_time
;
373 int stop
; /* stop flag */
376 struct wpa_status_t
{
378 unsigned int rsn_enabled
;
380 int pairwise_suite
; /* unicast cipher */
381 int group_suite
; /* multicast cipher */
382 int key_mgmt_suite
; /* authentication key management suite */
385 struct wpa_key_t key
[WPA_KEY_INDEX_MAX
];
386 struct scan_ext_t scan_ext
;
387 struct mic_failure_t mic_failure
;
390 #include <linux/list.h>
391 #define PMK_LIST_MAX 8
394 struct list_head head
;
396 struct list_head list
;
398 u8 pmkid
[IW_PMKID_LEN
];
403 struct wps_status_t
{
410 struct ks_wlan_private
{
412 struct hw_info_t ks_wlan_hw
; /* hardware information */
414 struct net_device
*net_dev
;
415 int reg_net
; /* register_netdev */
416 struct net_device_stats nstats
;
417 struct iw_statistics wstats
;
419 struct completion confirm_wait
;
421 /* trx device & sme */
422 struct tx_device tx_dev
;
423 struct rx_device rx_dev
;
424 struct sme_info sme_i
;
426 unsigned int rx_size
;
427 struct tasklet_struct sme_task
;
428 struct work_struct ks_wlan_wakeup_task
;
431 unsigned char eth_addr
[ETH_ALEN
];
433 struct local_aplist_t aplist
;
434 struct local_ap_t current_ap
;
435 struct power_save_status_t psstatus
;
436 struct sleep_status_t sleepstatus
;
437 struct wpa_status_t wpa
;
438 struct pmk_list_t pmklist
;
439 /* wireless parameter */
440 struct ks_wlan_parameter reg
;
443 char nick
[IW_ESSID_MAX_SIZE
+ 1];
445 spinlock_t multicast_spin
;
447 spinlock_t dev_read_lock
;
448 wait_queue_head_t devread_wait
;
450 unsigned int need_commit
; /* for ioctl */
452 /* DeviceIoControl */
453 int device_open_status
;
454 atomic_t event_count
;
457 #define DEVICE_STOCK_COUNT 20
458 unsigned char *dev_data
[DEVICE_STOCK_COUNT
];
459 int dev_size
[DEVICE_STOCK_COUNT
];
461 /* ioctl : IOCTL_FIRMWARE_VERSION */
462 unsigned char firmware_version
[128 + 1];
465 int mac_address_valid
; /* Mac Address Status */
470 unsigned int cur_rx
; /* Index into the Rx buffer of next Rx pkt. */
471 /* spinlock_t lock; */
472 #define FORCE_DISCONNECT 0x80000000
473 #define CONNECT_STATUS_MASK 0x7FFFFFFF
474 u32 connect_status
; /* connect status */
475 int infra_status
; /* Infractructure status */
477 u8 data_buff
[0x1000];
480 u8 scan_ssid
[IW_ESSID_MAX_SIZE
+ 1];
481 struct local_gain_t gain
;
483 struct net_device
*l2_dev
;
485 struct wps_status_t wps
;
490 struct local_eeprom_sum_t eeprom_sum
;
493 struct hostt_t hostt
;
495 unsigned long last_doze
;
496 unsigned long last_wakeup
;
498 uint wakeup_count
; /* for detect wakeup loop */
501 int ks_wlan_net_start(struct net_device
*dev
);
502 int ks_wlan_net_stop(struct net_device
*dev
);
504 #endif /* _KS_WLAN_H */