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/version.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
22 #include <linux/spinlock.h> /* spinlock_t */
23 #include <linux/sched.h> /* wait_queue_head_t */
24 #include <linux/types.h> /* pid_t */
25 #include <linux/netdevice.h> /* struct net_device_stats, struct sk_buff */
26 #include <linux/etherdevice.h>
27 #include <linux/wireless.h>
28 #include <asm/atomic.h> /* struct atmic_t */
29 #include <linux/timer.h> /* struct timer_list */
30 #include <linux/string.h>
31 #include <linux/completion.h> /* struct completion */
32 #include <linux/workqueue.h>
36 #include "ks7010_sdio.h"
39 #define DPRINTK(n, fmt, args...) \
40 if (KS_WLAN_DEBUG>(n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args)
42 #define DPRINTK(n, fmt, args...)
45 struct ks_wlan_parameter {
46 uint8_t operation_mode; /* Operation Mode */
47 uint8_t channel; /* Channel */
48 uint8_t tx_rate; /* Transmit Rate */
53 uint8_t bssid[ETH_ALEN]; /* BSSID */
58 uint8_t preamble; /* Preamble */
59 uint8_t powermgt; /* PowerManagementMode */
60 uint32_t scan_type; /* AP List Scan Type */
61 #define BEACON_LOST_COUNT_MIN 0
62 #define BEACON_LOST_COUNT_MAX 65535
63 uint32_t beacon_lost_count; /* Beacon Lost Count */
64 uint32_t rts; /* RTS Threashold */
65 uint32_t fragment; /* Fragmentation Threashold */
66 uint32_t privacy_invoked;
70 uint8_t val[13 * 2 + 1];
72 uint16_t authenticate_type;
73 uint16_t phy_type; /* 11b/11g/11bg mode type */
74 uint16_t cts_mode; /* for 11g/11bg mode cts mode */
75 uint16_t phy_info_timer; /* phy information timer */
79 DEVICE_STATE_OFF = 0, /* this means hw_unavailable is != 0 */
80 DEVICE_STATE_PREBOOT, /* we are in a pre-boot state (empty RAM) */
81 DEVICE_STATE_BOOT, /* boot state (fw upload, run fw) */
82 DEVICE_STATE_PREINIT, /* pre-init state */
83 DEVICE_STATE_INIT, /* init state (restore MIB backup to device) */
84 DEVICE_STATE_READY, /* driver&device are in operational state */
85 DEVICE_STATE_SLEEP /* device in sleep mode */
89 #define SME_MODE_SET (1<<0)
90 #define SME_RTS (1<<1)
91 #define SME_FRAG (1<<2)
92 #define SME_WEP_FLAG (1<<3)
93 #define SME_WEP_INDEX (1<<4)
94 #define SME_WEP_VAL1 (1<<5)
95 #define SME_WEP_VAL2 (1<<6)
96 #define SME_WEP_VAL3 (1<<7)
97 #define SME_WEP_VAL4 (1<<8)
98 #define SME_WEP_VAL_MASK (SME_WEP_VAL1|SME_WEP_VAL2|SME_WEP_VAL3|SME_WEP_VAL4)
99 #define SME_RSN (1<<9)
100 #define SME_RSN_MULTICAST (1<<10)
101 #define SME_RSN_UNICAST (1<<11)
102 #define SME_RSN_AUTH (1<<12)
104 #define SME_AP_SCAN (1<<13)
105 #define SME_MULTICAST (1<<14)
111 SME_MULTICAST_REQUEST,
112 SME_MACADDRESS_SET_REQUEST,
113 SME_BSS_SCAN_REQUEST,
125 SME_POW_MNGMT_REQUEST,
126 SME_PHY_INFO_REQUEST,
127 SME_MIC_FAILURE_REQUEST,
129 SME_GET_PRODUCT_VERSION,
131 SME_RTS_THRESHOLD_REQUEST,
132 SME_FRAGMENTATION_THRESHOLD_REQUEST,
133 SME_WEP_INDEX_REQUEST,
134 SME_WEP_KEY1_REQUEST,
135 SME_WEP_KEY2_REQUEST,
136 SME_WEP_KEY3_REQUEST,
137 SME_WEP_KEY4_REQUEST,
138 SME_WEP_FLAG_REQUEST,
139 SME_RSN_UCAST_REQUEST,
140 SME_RSN_MCAST_REQUEST,
141 SME_RSN_AUTH_REQUEST,
142 SME_RSN_ENABLED_REQUEST,
143 SME_RSN_MODE_REQUEST,
145 SME_WPS_ENABLE_REQUEST,
146 SME_WPS_PROBE_REQUEST,
152 SME_MODE_SET_REQUEST,
154 SME_GET_EEPROM_CKSUM,
156 SME_MIC_FAILURE_CONFIRM,
159 SME_MULTICAST_CONFIRM,
160 SME_BSS_SCAN_CONFIRM,
162 SME_POW_MNGMT_CONFIRM,
163 SME_PHY_INFO_CONFIRM,
165 SME_RTS_THRESHOLD_CONFIRM,
166 SME_FRAGMENTATION_THRESHOLD_CONFIRM,
167 SME_WEP_INDEX_CONFIRM,
168 SME_WEP_KEY1_CONFIRM,
169 SME_WEP_KEY2_CONFIRM,
170 SME_WEP_KEY3_CONFIRM,
171 SME_WEP_KEY4_CONFIRM,
172 SME_WEP_FLAG_CONFIRM,
173 SME_RSN_UCAST_CONFIRM,
174 SME_RSN_MCAST_CONFIRM,
175 SME_RSN_AUTH_CONFIRM,
176 SME_RSN_ENABLED_CONFIRM,
177 SME_RSN_MODE_CONFIRM,
178 SME_MODE_SET_CONFIRM,
185 SME_EVENT_SIZE /* end */
196 #define SME_EVENT_BUFF_SIZE 128
200 int event_buff[SME_EVENT_BUFF_SIZE];
205 unsigned int max_event_count;
208 unsigned long sme_flag;
212 int buff[SME_EVENT_BUFF_SIZE];
217 #define RSN_IE_BODY_MAX 64
219 uint8_t id; /* 0xdd = WPA or 0x30 = RSN */
220 uint8_t size; /* max ? 255 ? */
221 uint8_t body[RSN_IE_BODY_MAX];
225 #define WPS_IE_BODY_MAX 255
227 uint8_t id; /* 221 'dd <len> 00 50 F2 04' */
228 uint8_t size; /* max ? 255 ? */
229 uint8_t body[WPS_IE_BODY_MAX];
250 struct rsn_ie_t wpa_ie;
251 struct rsn_ie_t rsn_ie;
253 struct wps_ie_t wps_ie;
257 #define LOCAL_APLIST_MAX 31
258 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
259 struct local_aplist_t {
261 struct local_ap_t ap[LOCAL_APLIST_MAX + 1];
264 struct local_gain_t {
271 struct local_eeprom_sum_t {
278 EEPROM_CHECKSUM_NONE,
279 EEPROM_FW_NOT_SUPPORT,
283 /* Power Save Status */
293 struct power_save_status_t {
294 atomic_t status; /* initialvalue 0 */
295 struct completion wakeup_wait;
296 atomic_t confirm_wait;
297 atomic_t snooze_guard;
300 struct sleep_status_t {
301 atomic_t status; /* initialvalue 0 */
302 atomic_t doze_request;
303 atomic_t wakeup_request;
309 char ssid[IW_ESSID_MAX_SIZE + 1];
320 #define CIPHER_ID_WPA_NONE "\x00\x50\xf2\x00"
321 #define CIPHER_ID_WPA_WEP40 "\x00\x50\xf2\x01"
322 #define CIPHER_ID_WPA_TKIP "\x00\x50\xf2\x02"
323 #define CIPHER_ID_WPA_CCMP "\x00\x50\xf2\x04"
324 #define CIPHER_ID_WPA_WEP104 "\x00\x50\xf2\x05"
326 #define CIPHER_ID_WPA2_NONE "\x00\x0f\xac\x00"
327 #define CIPHER_ID_WPA2_WEP40 "\x00\x0f\xac\x01"
328 #define CIPHER_ID_WPA2_TKIP "\x00\x0f\xac\x02"
329 #define CIPHER_ID_WPA2_CCMP "\x00\x0f\xac\x04"
330 #define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
332 #define CIPHER_ID_LEN 4
340 #define KEY_MGMT_ID_WPA_NONE "\x00\x50\xf2\x00"
341 #define KEY_MGMT_ID_WPA_1X "\x00\x50\xf2\x01"
342 #define KEY_MGMT_ID_WPA_PSK "\x00\x50\xf2\x02"
343 #define KEY_MGMT_ID_WPA_WPANONE "\x00\x50\xf2\xff"
345 #define KEY_MGMT_ID_WPA2_NONE "\x00\x0f\xac\x00"
346 #define KEY_MGMT_ID_WPA2_1X "\x00\x0f\xac\x01"
347 #define KEY_MGMT_ID_WPA2_PSK "\x00\x0f\xac\x02"
348 #define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
350 #define KEY_MGMT_ID_LEN 4
352 #define MIC_KEY_SIZE 8
355 uint32_t ext_flags; /* IW_ENCODE_EXT_xxx */
356 uint8_t tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
357 uint8_t rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
358 struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
359 * (group) keys or unicast address for
362 uint16_t key_len; /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
363 uint8_t key_val[IW_ENCODING_TOKEN_MAX];
364 uint8_t tx_mic_key[MIC_KEY_SIZE];
365 uint8_t rx_mic_key[MIC_KEY_SIZE];
367 #define WPA_KEY_INDEX_MAX 4
368 #define WPA_RX_SEQ_LEN 6
370 struct mic_failure_t {
371 uint16_t failure; /* MIC Failure counter 0 or 1 or 2 */
372 uint16_t counter; /* 1sec counter 0-60 */
373 uint32_t last_failure_time;
374 int stop; /* stop flag */
377 struct wpa_status_t {
379 unsigned int rsn_enabled;
381 int pairwise_suite; /* unicast cipher */
382 int group_suite; /* multicast cipher */
383 int key_mgmt_suite; /* authentication key management suite */
386 struct wpa_key_t key[WPA_KEY_INDEX_MAX];
387 struct scan_ext_t scan_ext;
388 struct mic_failure_t mic_failure;
391 #include <linux/list.h>
392 #define PMK_LIST_MAX 8
395 struct list_head head;
397 struct list_head list;
398 uint8_t bssid[ETH_ALEN];
399 uint8_t pmkid[IW_PMKID_LEN];
404 struct wps_status_t {
411 struct ks_wlan_private {
413 struct hw_info_t ks_wlan_hw; /* hardware information */
415 struct net_device *net_dev;
416 int reg_net; /* register_netdev */
417 struct net_device_stats nstats;
418 struct iw_statistics wstats;
420 struct completion confirm_wait;
422 /* trx device & sme */
423 struct tx_device tx_dev;
424 struct rx_device rx_dev;
425 struct sme_info sme_i;
427 unsigned int rx_size;
428 struct tasklet_struct sme_task;
429 struct work_struct ks_wlan_wakeup_task;
432 unsigned char eth_addr[ETH_ALEN];
434 struct local_aplist_t aplist;
435 struct local_ap_t current_ap;
436 struct power_save_status_t psstatus;
437 struct sleep_status_t sleepstatus;
438 struct wpa_status_t wpa;
439 struct pmk_list_t pmklist;
440 /* wireless parameter */
441 struct ks_wlan_parameter reg;
442 uint8_t current_rate;
444 char nick[IW_ESSID_MAX_SIZE + 1];
446 spinlock_t multicast_spin;
448 spinlock_t dev_read_lock;
449 wait_queue_head_t devread_wait;
451 unsigned int need_commit; /* for ioctl */
453 /* DeviceIoControl */
454 int device_open_status;
455 atomic_t event_count;
458 #define DEVICE_STOCK_COUNT 20
459 unsigned char *dev_data[DEVICE_STOCK_COUNT];
460 int dev_size[DEVICE_STOCK_COUNT];
462 /* ioctl : IOCTL_FIRMWARE_VERSION */
463 unsigned char firmware_version[128 + 1];
466 int mac_address_valid; /* Mac Address Status */
471 unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */
472 /* spinlock_t lock; */
473 #define FORCE_DISCONNECT 0x80000000
474 #define CONNECT_STATUS_MASK 0x7FFFFFFF
475 uint32_t connect_status; /* connect status */
476 int infra_status; /* Infractructure status */
478 uint8_t data_buff[0x1000];
480 uint8_t scan_ssid_len;
481 uint8_t scan_ssid[IW_ESSID_MAX_SIZE + 1];
482 struct local_gain_t gain;
484 struct net_device *l2_dev;
486 struct wps_status_t wps;
491 struct local_eeprom_sum_t eeprom_sum;
492 uint8_t eeprom_checksum;
494 struct hostt_t hostt;
496 unsigned long last_doze;
497 unsigned long last_wakeup;
499 uint wakeup_count; /* for detect wakeup loop */
502 int ks_wlan_net_start(struct net_device *dev);
503 int ks_wlan_net_stop(struct net_device *dev);
505 #endif /* _KS_WLAN_H */