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...) \
40 if (KS_WLAN_DEBUG > (n)) \
41 pr_notice("%s: "fmt, __func__, ## args); \
44 #define DPRINTK(n, fmt, args...)
47 struct ks_wlan_parameter {
48 u8 operation_mode; /* Operation Mode */
49 u8 channel; /* Channel */
50 u8 tx_rate; /* Transmit Rate */
55 u8 bssid[ETH_ALEN]; /* BSSID */
60 u8 preamble; /* Preamble */
62 u32 scan_type; /* AP List Scan Type */
63 #define BEACON_LOST_COUNT_MIN 0
64 #define BEACON_LOST_COUNT_MAX 65535
65 u32 beacon_lost_count; /* Beacon Lost Count */
66 u32 rts; /* RTS Threashold */
67 u32 fragment; /* Fragmentation Threashold */
74 u16 authenticate_type;
75 u16 phy_type; /* 11b/11g/11bg mode type */
76 u16 cts_mode; /* for 11g/11bg mode cts mode */
77 u16 phy_info_timer; /* phy information timer */
81 DEVICE_STATE_OFF = 0, /* this means hw_unavailable is != 0 */
82 DEVICE_STATE_PREBOOT, /* we are in a pre-boot state (empty RAM) */
83 DEVICE_STATE_BOOT, /* boot state (fw upload, run fw) */
84 DEVICE_STATE_PREINIT, /* pre-init state */
85 DEVICE_STATE_INIT, /* init state (restore MIB backup to device) */
86 DEVICE_STATE_READY, /* driver&device are in operational state */
87 DEVICE_STATE_SLEEP /* device in sleep mode */
91 #define SME_MODE_SET BIT(0)
92 #define SME_RTS BIT(1)
93 #define SME_FRAG BIT(2)
94 #define SME_WEP_FLAG BIT(3)
95 #define SME_WEP_INDEX BIT(4)
96 #define SME_WEP_VAL1 BIT(5)
97 #define SME_WEP_VAL2 BIT(6)
98 #define SME_WEP_VAL3 BIT(7)
99 #define SME_WEP_VAL4 BIT(8)
100 #define SME_WEP_VAL_MASK (SME_WEP_VAL1 | SME_WEP_VAL2 | SME_WEP_VAL3 | SME_WEP_VAL4)
101 #define SME_RSN BIT(9)
102 #define SME_RSN_MULTICAST BIT(10)
103 #define SME_RSN_UNICAST BIT(11)
104 #define SME_RSN_AUTH BIT(12)
106 #define SME_AP_SCAN BIT(13)
107 #define SME_MULTICAST BIT(14)
113 SME_MULTICAST_REQUEST,
114 SME_MACADDRESS_SET_REQUEST,
115 SME_BSS_SCAN_REQUEST,
127 SME_POW_MNGMT_REQUEST,
128 SME_PHY_INFO_REQUEST,
129 SME_MIC_FAILURE_REQUEST,
131 SME_GET_PRODUCT_VERSION,
133 SME_RTS_THRESHOLD_REQUEST,
134 SME_FRAGMENTATION_THRESHOLD_REQUEST,
135 SME_WEP_INDEX_REQUEST,
136 SME_WEP_KEY1_REQUEST,
137 SME_WEP_KEY2_REQUEST,
138 SME_WEP_KEY3_REQUEST,
139 SME_WEP_KEY4_REQUEST,
140 SME_WEP_FLAG_REQUEST,
141 SME_RSN_UCAST_REQUEST,
142 SME_RSN_MCAST_REQUEST,
143 SME_RSN_AUTH_REQUEST,
144 SME_RSN_ENABLED_REQUEST,
145 SME_RSN_MODE_REQUEST,
147 SME_WPS_ENABLE_REQUEST,
148 SME_WPS_PROBE_REQUEST,
154 SME_MODE_SET_REQUEST,
156 SME_GET_EEPROM_CKSUM,
158 SME_MIC_FAILURE_CONFIRM,
161 SME_MULTICAST_CONFIRM,
162 SME_BSS_SCAN_CONFIRM,
164 SME_POW_MNGMT_CONFIRM,
165 SME_PHY_INFO_CONFIRM,
167 SME_RTS_THRESHOLD_CONFIRM,
168 SME_FRAGMENTATION_THRESHOLD_CONFIRM,
169 SME_WEP_INDEX_CONFIRM,
170 SME_WEP_KEY1_CONFIRM,
171 SME_WEP_KEY2_CONFIRM,
172 SME_WEP_KEY3_CONFIRM,
173 SME_WEP_KEY4_CONFIRM,
174 SME_WEP_FLAG_CONFIRM,
175 SME_RSN_UCAST_CONFIRM,
176 SME_RSN_MCAST_CONFIRM,
177 SME_RSN_AUTH_CONFIRM,
178 SME_RSN_ENABLED_CONFIRM,
179 SME_RSN_MODE_CONFIRM,
180 SME_MODE_SET_CONFIRM,
187 SME_EVENT_SIZE /* end */
198 #define SME_EVENT_BUFF_SIZE 128
202 int event_buff[SME_EVENT_BUFF_SIZE];
207 unsigned int max_event_count;
210 unsigned long sme_flag;
214 int buff[SME_EVENT_BUFF_SIZE];
219 #define RSN_IE_BODY_MAX 64
221 u8 id; /* 0xdd = WPA or 0x30 = RSN */
222 u8 size; /* max ? 255 ? */
223 u8 body[RSN_IE_BODY_MAX];
227 #define WPS_IE_BODY_MAX 255
229 u8 id; /* 221 'dd <len> 00 50 F2 04' */
230 u8 size; /* max ? 255 ? */
231 u8 body[WPS_IE_BODY_MAX];
252 struct rsn_ie_t wpa_ie;
253 struct rsn_ie_t rsn_ie;
255 struct wps_ie_t wps_ie;
259 #define LOCAL_APLIST_MAX 31
260 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
261 struct local_aplist_t {
263 struct local_ap_t ap[LOCAL_APLIST_MAX + 1];
266 struct local_gain_t {
273 struct local_eeprom_sum_t {
280 EEPROM_CHECKSUM_NONE,
281 EEPROM_FW_NOT_SUPPORT,
285 /* Power Save Status */
295 struct power_save_status_t {
296 atomic_t status; /* initialvalue 0 */
297 struct completion wakeup_wait;
298 atomic_t confirm_wait;
299 atomic_t snooze_guard;
302 struct sleep_status_t {
303 atomic_t status; /* initialvalue 0 */
304 atomic_t doze_request;
305 atomic_t wakeup_request;
311 char ssid[IW_ESSID_MAX_SIZE + 1];
322 #define CIPHER_ID_WPA_NONE "\x00\x50\xf2\x00"
323 #define CIPHER_ID_WPA_WEP40 "\x00\x50\xf2\x01"
324 #define CIPHER_ID_WPA_TKIP "\x00\x50\xf2\x02"
325 #define CIPHER_ID_WPA_CCMP "\x00\x50\xf2\x04"
326 #define CIPHER_ID_WPA_WEP104 "\x00\x50\xf2\x05"
328 #define CIPHER_ID_WPA2_NONE "\x00\x0f\xac\x00"
329 #define CIPHER_ID_WPA2_WEP40 "\x00\x0f\xac\x01"
330 #define CIPHER_ID_WPA2_TKIP "\x00\x0f\xac\x02"
331 #define CIPHER_ID_WPA2_CCMP "\x00\x0f\xac\x04"
332 #define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
334 #define CIPHER_ID_LEN 4
342 #define KEY_MGMT_ID_WPA_NONE "\x00\x50\xf2\x00"
343 #define KEY_MGMT_ID_WPA_1X "\x00\x50\xf2\x01"
344 #define KEY_MGMT_ID_WPA_PSK "\x00\x50\xf2\x02"
345 #define KEY_MGMT_ID_WPA_WPANONE "\x00\x50\xf2\xff"
347 #define KEY_MGMT_ID_WPA2_NONE "\x00\x0f\xac\x00"
348 #define KEY_MGMT_ID_WPA2_1X "\x00\x0f\xac\x01"
349 #define KEY_MGMT_ID_WPA2_PSK "\x00\x0f\xac\x02"
350 #define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
352 #define KEY_MGMT_ID_LEN 4
354 #define MIC_KEY_SIZE 8
357 u32 ext_flags; /* IW_ENCODE_EXT_xxx */
358 u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
359 u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
360 struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
361 * (group) keys or unicast address for
365 u16 key_len; /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
366 u8 key_val[IW_ENCODING_TOKEN_MAX];
367 u8 tx_mic_key[MIC_KEY_SIZE];
368 u8 rx_mic_key[MIC_KEY_SIZE];
371 #define WPA_KEY_INDEX_MAX 4
372 #define WPA_RX_SEQ_LEN 6
374 struct mic_failure_t {
375 u16 failure; /* MIC Failure counter 0 or 1 or 2 */
376 u16 counter; /* 1sec counter 0-60 */
377 u32 last_failure_time;
378 int stop; /* stop flag */
381 struct wpa_status_t {
383 unsigned int rsn_enabled;
385 int pairwise_suite; /* unicast cipher */
386 int group_suite; /* multicast cipher */
387 int key_mgmt_suite; /* authentication key management suite */
390 struct wpa_key_t key[WPA_KEY_INDEX_MAX];
391 struct scan_ext_t scan_ext;
392 struct mic_failure_t mic_failure;
395 #include <linux/list.h>
396 #define PMK_LIST_MAX 8
399 struct list_head head;
401 struct list_head list;
403 u8 pmkid[IW_PMKID_LEN];
408 struct wps_status_t {
415 struct ks_wlan_private {
416 /* hardware information */
417 struct ks_sdio_card *ks_sdio_card;
418 struct workqueue_struct *wq;
419 struct delayed_work rw_dwork;
420 struct tasklet_struct rx_bh_task;
422 struct net_device *net_dev;
423 int reg_net; /* register_netdev */
424 struct net_device_stats nstats;
425 struct iw_statistics wstats;
427 struct completion confirm_wait;
429 /* trx device & sme */
430 struct tx_device tx_dev;
431 struct rx_device rx_dev;
432 struct sme_info sme_i;
434 unsigned int rx_size;
435 struct tasklet_struct sme_task;
436 struct work_struct wakeup_work;
439 unsigned char eth_addr[ETH_ALEN];
441 struct local_aplist_t aplist;
442 struct local_ap_t current_ap;
443 struct power_save_status_t psstatus;
444 struct sleep_status_t sleepstatus;
445 struct wpa_status_t wpa;
446 struct pmk_list_t pmklist;
447 /* wireless parameter */
448 struct ks_wlan_parameter reg;
451 char nick[IW_ESSID_MAX_SIZE + 1];
453 spinlock_t multicast_spin;
455 spinlock_t dev_read_lock;
456 wait_queue_head_t devread_wait;
458 unsigned int need_commit; /* for ioctl */
460 /* DeviceIoControl */
461 int device_open_status;
462 atomic_t event_count;
465 #define DEVICE_STOCK_COUNT 20
466 unsigned char *dev_data[DEVICE_STOCK_COUNT];
467 int dev_size[DEVICE_STOCK_COUNT];
469 /* ioctl : IOCTL_FIRMWARE_VERSION */
470 unsigned char firmware_version[128 + 1];
473 int mac_address_valid; /* Mac Address Status */
478 unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */
479 /* spinlock_t lock; */
480 #define FORCE_DISCONNECT 0x80000000
481 #define CONNECT_STATUS_MASK 0x7FFFFFFF
482 u32 connect_status; /* connect status */
483 int infra_status; /* Infractructure status */
485 u8 data_buff[0x1000];
488 u8 scan_ssid[IW_ESSID_MAX_SIZE + 1];
489 struct local_gain_t gain;
491 struct net_device *l2_dev;
493 struct wps_status_t wps;
498 struct local_eeprom_sum_t eeprom_sum;
501 struct hostt_t hostt;
503 unsigned long last_doze;
504 unsigned long last_wakeup;
506 uint wakeup_count; /* for detect wakeup loop */
509 int ks_wlan_net_start(struct net_device *dev);
510 int ks_wlan_net_stop(struct net_device *dev);
511 bool is_connect_status(u32 status);
512 bool is_disconnect_status(u32 status);
514 #endif /* _KS_WLAN_H */