1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
5 * Copyright (C) 2006-2008 KeyStream Corp.
6 * Copyright (C) 2009 Renesas Technology Corp.
12 #include <linux/atomic.h>
13 #include <linux/circ_buf.h>
14 #include <linux/completion.h>
15 #include <linux/netdevice.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/wireless.h>
20 struct ks_wlan_parameter {
36 #define BEACON_LOST_COUNT_MAX 65535
37 u32 beacon_lost_count;
46 u16 authenticate_type;
53 DEVICE_STATE_OFF = 0, /* this means hw_unavailable is != 0 */
54 DEVICE_STATE_PREBOOT, /* we are in a pre-boot state (empty RAM) */
55 DEVICE_STATE_BOOT, /* boot state (fw upload, run fw) */
56 DEVICE_STATE_PREINIT, /* pre-init state */
57 DEVICE_STATE_INIT, /* init state (restore MIB backup to device) */
58 DEVICE_STATE_READY, /* driver&device are in operational state */
59 DEVICE_STATE_SLEEP /* device in sleep mode */
63 #define SME_MODE_SET BIT(0)
64 #define SME_RTS BIT(1)
65 #define SME_FRAG BIT(2)
66 #define SME_WEP_FLAG BIT(3)
67 #define SME_WEP_INDEX BIT(4)
68 #define SME_WEP_VAL1 BIT(5)
69 #define SME_WEP_VAL2 BIT(6)
70 #define SME_WEP_VAL3 BIT(7)
71 #define SME_WEP_VAL4 BIT(8)
72 #define SME_WEP_VAL_MASK GENMASK(8, 5)
73 #define SME_RSN BIT(9)
74 #define SME_RSN_MULTICAST BIT(10)
75 #define SME_RSN_UNICAST BIT(11)
76 #define SME_RSN_AUTH BIT(12)
78 #define SME_AP_SCAN BIT(13)
79 #define SME_MULTICAST BIT(14)
85 SME_MULTICAST_REQUEST,
86 SME_MACADDRESS_SET_REQUEST,
99 SME_POW_MNGMT_REQUEST,
100 SME_PHY_INFO_REQUEST,
101 SME_MIC_FAILURE_REQUEST,
103 SME_GET_PRODUCT_VERSION,
105 SME_RTS_THRESHOLD_REQUEST,
106 SME_FRAGMENTATION_THRESHOLD_REQUEST,
107 SME_WEP_INDEX_REQUEST,
108 SME_WEP_KEY1_REQUEST,
109 SME_WEP_KEY2_REQUEST,
110 SME_WEP_KEY3_REQUEST,
111 SME_WEP_KEY4_REQUEST,
112 SME_WEP_FLAG_REQUEST,
113 SME_RSN_UCAST_REQUEST,
114 SME_RSN_MCAST_REQUEST,
115 SME_RSN_AUTH_REQUEST,
116 SME_RSN_ENABLED_REQUEST,
117 SME_RSN_MODE_REQUEST,
118 SME_WPS_ENABLE_REQUEST,
119 SME_WPS_PROBE_REQUEST,
124 SME_MODE_SET_REQUEST,
126 SME_GET_EEPROM_CKSUM,
128 SME_MIC_FAILURE_CONFIRM,
131 SME_MULTICAST_CONFIRM,
132 SME_BSS_SCAN_CONFIRM,
134 SME_POW_MNGMT_CONFIRM,
135 SME_PHY_INFO_CONFIRM,
137 SME_RTS_THRESHOLD_CONFIRM,
138 SME_FRAGMENTATION_THRESHOLD_CONFIRM,
139 SME_WEP_INDEX_CONFIRM,
140 SME_WEP_KEY1_CONFIRM,
141 SME_WEP_KEY2_CONFIRM,
142 SME_WEP_KEY3_CONFIRM,
143 SME_WEP_KEY4_CONFIRM,
144 SME_WEP_FLAG_CONFIRM,
145 SME_RSN_UCAST_CONFIRM,
146 SME_RSN_MCAST_CONFIRM,
147 SME_RSN_AUTH_CONFIRM,
148 SME_RSN_ENABLED_CONFIRM,
149 SME_RSN_MODE_CONFIRM,
150 SME_MODE_SET_CONFIRM,
168 #define SME_EVENT_BUFF_SIZE 128
172 int event_buff[SME_EVENT_BUFF_SIZE];
176 unsigned long sme_flag;
180 int buff[SME_EVENT_BUFF_SIZE];
185 #define RSN_IE_BODY_MAX 64
187 u8 id; /* 0xdd = WPA or 0x30 = RSN */
188 u8 size; /* max ? 255 ? */
189 u8 body[RSN_IE_BODY_MAX];
192 #define WPA_INFO_ELEM_ID 0xdd
193 #define RSN_INFO_ELEM_ID 0x30
195 #define WPS_IE_BODY_MAX 255
197 u8 id; /* 221 'dd <len> 00 50 F2 04' */
198 u8 size; /* max ? 255 ? */
199 u8 body[WPS_IE_BODY_MAX];
219 struct rsn_ie wpa_ie;
220 struct rsn_ie rsn_ie;
221 struct wps_ie wps_ie;
224 #define LOCAL_APLIST_MAX 31
225 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
226 struct local_aplist {
228 struct local_ap ap[LOCAL_APLIST_MAX + 1];
238 struct local_eeprom_sum {
245 EEPROM_CHECKSUM_NONE,
246 EEPROM_FW_NOT_SUPPORT,
250 /* Power Save Status */
260 struct power_save_status {
261 atomic_t status; /* initialvalue 0 */
262 struct completion wakeup_wait;
263 atomic_t confirm_wait;
264 atomic_t snooze_guard;
267 struct sleep_status {
268 atomic_t status; /* initialvalue 0 */
269 atomic_t doze_request;
270 atomic_t wakeup_request;
276 char ssid[IW_ESSID_MAX_SIZE + 1];
279 #define CIPHER_ID_WPA_NONE "\x00\x50\xf2\x00"
280 #define CIPHER_ID_WPA_WEP40 "\x00\x50\xf2\x01"
281 #define CIPHER_ID_WPA_TKIP "\x00\x50\xf2\x02"
282 #define CIPHER_ID_WPA_CCMP "\x00\x50\xf2\x04"
283 #define CIPHER_ID_WPA_WEP104 "\x00\x50\xf2\x05"
285 #define CIPHER_ID_WPA2_NONE "\x00\x0f\xac\x00"
286 #define CIPHER_ID_WPA2_WEP40 "\x00\x0f\xac\x01"
287 #define CIPHER_ID_WPA2_TKIP "\x00\x0f\xac\x02"
288 #define CIPHER_ID_WPA2_CCMP "\x00\x0f\xac\x04"
289 #define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
291 #define CIPHER_ID_LEN 4
299 #define KEY_MGMT_ID_WPA_NONE "\x00\x50\xf2\x00"
300 #define KEY_MGMT_ID_WPA_1X "\x00\x50\xf2\x01"
301 #define KEY_MGMT_ID_WPA_PSK "\x00\x50\xf2\x02"
302 #define KEY_MGMT_ID_WPA_WPANONE "\x00\x50\xf2\xff"
304 #define KEY_MGMT_ID_WPA2_NONE "\x00\x0f\xac\x00"
305 #define KEY_MGMT_ID_WPA2_1X "\x00\x0f\xac\x01"
306 #define KEY_MGMT_ID_WPA2_PSK "\x00\x0f\xac\x02"
307 #define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
309 #define KEY_MGMT_ID_LEN 4
311 #define MIC_KEY_SIZE 8
314 u32 ext_flags; /* IW_ENCODE_EXT_xxx */
315 u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
316 u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
317 struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
318 * (group) keys or unicast address for
322 u16 key_len; /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
323 u8 key_val[IW_ENCODING_TOKEN_MAX];
324 u8 tx_mic_key[MIC_KEY_SIZE];
325 u8 rx_mic_key[MIC_KEY_SIZE];
328 #define WPA_KEY_INDEX_MAX 4
329 #define WPA_RX_SEQ_LEN 6
332 u16 failure; /* MIC Failure counter 0 or 1 or 2 */
333 u16 counter; /* 1sec counter 0-60 */
334 u32 last_failure_time;
342 int pairwise_suite; /* unicast cipher */
343 int group_suite; /* multicast cipher */
347 struct wpa_key key[WPA_KEY_INDEX_MAX];
348 struct scan_ext scan_ext;
349 struct mic_failure mic_failure;
352 #include <linux/list.h>
353 #define PMK_LIST_MAX 8
356 struct list_head head;
358 struct list_head list;
360 u8 pmkid[IW_PMKID_LEN];
370 /* Tx Device struct */
371 #define TX_DEVICE_BUFF_SIZE 1024
373 struct ks_wlan_private;
376 * struct tx_device_buffer - Queue item for the tx queue.
377 * @sendp: Pointer to the send request data.
378 * @size: Size of @sendp data.
379 * @complete_handler: Function called once data write to device is complete.
380 * @arg1: First argument to @complete_handler.
381 * @arg2: Second argument to @complete_handler.
383 struct tx_device_buffer {
384 unsigned char *sendp;
386 void (*complete_handler)(struct ks_wlan_private *priv,
387 struct sk_buff *skb);
392 * struct tx_device - Tx buffer queue.
393 * @tx_device_buffer: Queue buffer.
394 * @qhead: Head of tx queue.
395 * @qtail: Tail of tx queue.
396 * @tx_dev_lock: Queue lock.
399 struct tx_device_buffer tx_dev_buff[TX_DEVICE_BUFF_SIZE];
402 spinlock_t tx_dev_lock; /* protect access to the queue */
405 /* Rx Device struct */
406 #define RX_DATA_SIZE (2 + 2 + 2347 + 1)
407 #define RX_DEVICE_BUFF_SIZE 32
410 * struct rx_device_buffer - Queue item for the rx queue.
412 * @size: Size of @data.
414 struct rx_device_buffer {
415 unsigned char data[RX_DATA_SIZE];
420 * struct rx_device - Rx buffer queue.
421 * @rx_device_buffer: Queue buffer.
422 * @qhead: Head of rx queue.
423 * @qtail: Tail of rx queue.
424 * @rx_dev_lock: Queue lock.
427 struct rx_device_buffer rx_dev_buff[RX_DEVICE_BUFF_SIZE];
430 spinlock_t rx_dev_lock; /* protect access to the queue */
433 struct ks_wlan_private {
434 /* hardware information */
436 struct workqueue_struct *wq;
437 struct delayed_work rw_dwork;
438 struct tasklet_struct rx_bh_task;
440 struct net_device *net_dev;
441 struct net_device_stats nstats;
442 struct iw_statistics wstats;
444 struct completion confirm_wait;
446 /* trx device & sme */
447 struct tx_device tx_dev;
448 struct rx_device rx_dev;
449 struct sme_info sme_i;
451 unsigned int rx_size;
452 struct tasklet_struct sme_task;
453 struct work_struct wakeup_work;
456 unsigned char eth_addr[ETH_ALEN];
458 struct local_aplist aplist;
459 struct local_ap current_ap;
460 struct power_save_status psstatus;
461 struct sleep_status sleepstatus;
462 struct wpa_status wpa;
463 struct pmk_list pmklist;
464 /* wireless parameter */
465 struct ks_wlan_parameter reg;
468 char nick[IW_ESSID_MAX_SIZE + 1];
470 spinlock_t multicast_spin;
472 spinlock_t dev_read_lock;
473 wait_queue_head_t devread_wait;
475 unsigned int need_commit; /* for ioctl */
477 /* DeviceIoControl */
479 atomic_t event_count;
482 #define DEVICE_STOCK_COUNT 20
483 unsigned char *dev_data[DEVICE_STOCK_COUNT];
484 int dev_size[DEVICE_STOCK_COUNT];
486 /* ioctl : IOCTL_FIRMWARE_VERSION */
487 unsigned char firmware_version[128 + 1];
490 bool mac_address_valid;
495 unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */
496 #define FORCE_DISCONNECT 0x80000000
497 #define CONNECT_STATUS_MASK 0x7FFFFFFF
501 u8 scan_ssid[IW_ESSID_MAX_SIZE + 1];
502 struct local_gain gain;
503 struct wps_status wps;
507 struct local_eeprom_sum eeprom_sum;
512 unsigned long last_doze;
513 unsigned long last_wakeup;
515 unsigned int wakeup_count; /* for detect wakeup loop */
518 static inline void inc_txqhead(struct ks_wlan_private *priv)
520 priv->tx_dev.qhead = (priv->tx_dev.qhead + 1) % TX_DEVICE_BUFF_SIZE;
523 static inline void inc_txqtail(struct ks_wlan_private *priv)
525 priv->tx_dev.qtail = (priv->tx_dev.qtail + 1) % TX_DEVICE_BUFF_SIZE;
528 static inline bool txq_has_space(struct ks_wlan_private *priv)
530 return (CIRC_SPACE(priv->tx_dev.qhead, priv->tx_dev.qtail,
531 TX_DEVICE_BUFF_SIZE) > 0);
534 static inline void inc_rxqhead(struct ks_wlan_private *priv)
536 priv->rx_dev.qhead = (priv->rx_dev.qhead + 1) % RX_DEVICE_BUFF_SIZE;
539 static inline void inc_rxqtail(struct ks_wlan_private *priv)
541 priv->rx_dev.qtail = (priv->rx_dev.qtail + 1) % RX_DEVICE_BUFF_SIZE;
544 static inline bool rxq_has_space(struct ks_wlan_private *priv)
546 return (CIRC_SPACE(priv->rx_dev.qhead, priv->rx_dev.qtail,
547 RX_DEVICE_BUFF_SIZE) > 0);
550 static inline unsigned int txq_count(struct ks_wlan_private *priv)
552 return CIRC_CNT_TO_END(priv->tx_dev.qhead, priv->tx_dev.qtail,
553 TX_DEVICE_BUFF_SIZE);
556 static inline unsigned int rxq_count(struct ks_wlan_private *priv)
558 return CIRC_CNT_TO_END(priv->rx_dev.qhead, priv->rx_dev.qtail,
559 RX_DEVICE_BUFF_SIZE);
562 int ks_wlan_net_start(struct net_device *dev);
563 int ks_wlan_net_stop(struct net_device *dev);
564 bool is_connect_status(u32 status);
565 bool is_disconnect_status(u32 status);
567 #endif /* _KS_WLAN_H */