GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / ks7010 / ks_wlan.h
1 /*
2  *   Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
3  *
4  *   Copyright (C) 2006-2008 KeyStream Corp.
5  *   Copyright (C) 2009 Renesas Technology Corp.
6  *
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.
10  */
11
12 #ifndef _KS_WLAN_H
13 #define _KS_WLAN_H
14
15 #define WPS
16
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20
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>
32
33 #include <linux/io.h>
34
35 #include "ks7010_sdio.h"
36
37 #ifdef KS_WLAN_DEBUG
38 #define DPRINTK(n, fmt, args...) \
39         do { \
40                 if (KS_WLAN_DEBUG > (n)) \
41                         pr_notice("%s: "fmt, __func__, ## args); \
42         } while (0)
43 #else
44 #define DPRINTK(n, fmt, args...)
45 #endif
46
47 struct ks_wlan_parameter {
48         u8 operation_mode;      /* Operation Mode */
49         u8 channel;     /*  Channel */
50         u8 tx_rate;     /*  Transmit Rate */
51         struct {
52                 u8 size;
53                 u8 body[16];
54         } rate_set;
55         u8 bssid[ETH_ALEN];     /* BSSID */
56         struct {
57                 u8 size;
58                 u8 body[32 + 1];
59         } ssid; /*  SSID */
60         u8 preamble;    /*  Preamble */
61         u8 power_mgmt;
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 */
68         u32 privacy_invoked;
69         u32 wep_index;
70         struct {
71                 u8 size;
72                 u8 val[13 * 2 + 1];
73         } wep_key[4];
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 */
78 };
79
80 enum {
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 */
88 };
89
90 /* SME flag */
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)
105
106 #define SME_AP_SCAN         BIT(13)
107 #define SME_MULTICAST       BIT(14)
108
109 /* SME Event */
110 enum {
111         SME_START,
112
113         SME_MULTICAST_REQUEST,
114         SME_MACADDRESS_SET_REQUEST,
115         SME_BSS_SCAN_REQUEST,
116         SME_SET_FLAG,
117         SME_SET_TXKEY,
118         SME_SET_KEY1,
119         SME_SET_KEY2,
120         SME_SET_KEY3,
121         SME_SET_KEY4,
122         SME_SET_PMK_TSC,
123         SME_SET_GMK1_TSC,
124         SME_SET_GMK2_TSC,
125         SME_SET_GMK3_TSC,
126         SME_SET_PMKSA,
127         SME_POW_MNGMT_REQUEST,
128         SME_PHY_INFO_REQUEST,
129         SME_MIC_FAILURE_REQUEST,
130         SME_GET_MAC_ADDRESS,
131         SME_GET_PRODUCT_VERSION,
132         SME_STOP_REQUEST,
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,
146 #ifdef WPS
147         SME_WPS_ENABLE_REQUEST,
148         SME_WPS_PROBE_REQUEST,
149 #endif
150         SME_SET_GAIN,
151         SME_GET_GAIN,
152         SME_SLEEP_REQUEST,
153         SME_SET_REGION,
154         SME_MODE_SET_REQUEST,
155         SME_START_REQUEST,
156         SME_GET_EEPROM_CKSUM,
157
158         SME_MIC_FAILURE_CONFIRM,
159         SME_START_CONFIRM,
160
161         SME_MULTICAST_CONFIRM,
162         SME_BSS_SCAN_CONFIRM,
163         SME_GET_CURRENT_AP,
164         SME_POW_MNGMT_CONFIRM,
165         SME_PHY_INFO_CONFIRM,
166         SME_STOP_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,
181         SME_SLEEP_CONFIRM,
182
183         SME_RSN_SET_CONFIRM,
184         SME_WEP_SET_CONFIRM,
185         SME_TERMINATE,
186
187         SME_EVENT_SIZE  /* end */
188 };
189
190 /* SME Status */
191 enum {
192         SME_IDLE,
193         SME_SETUP,
194         SME_DISCONNECT,
195         SME_CONNECT
196 };
197
198 #define SME_EVENT_BUFF_SIZE     128
199
200 struct sme_info {
201         int sme_status;
202         int event_buff[SME_EVENT_BUFF_SIZE];
203         unsigned int qhead;
204         unsigned int qtail;
205 #ifdef KS_WLAN_DEBUG
206         /* for debug */
207         unsigned int max_event_count;
208 #endif
209         spinlock_t sme_spin;
210         unsigned long sme_flag;
211 };
212
213 struct hostt_t {
214         int buff[SME_EVENT_BUFF_SIZE];
215         unsigned int qhead;
216         unsigned int qtail;
217 };
218
219 #define RSN_IE_BODY_MAX 64
220 struct rsn_ie_t {
221         u8 id;  /* 0xdd = WPA or 0x30 = RSN */
222         u8 size;        /* max ? 255 ? */
223         u8 body[RSN_IE_BODY_MAX];
224 } __packed;
225
226 #ifdef WPS
227 #define WPS_IE_BODY_MAX 255
228 struct wps_ie_t {
229         u8 id;  /* 221 'dd <len> 00 50 F2 04' */
230         u8 size;        /* max ? 255 ? */
231         u8 body[WPS_IE_BODY_MAX];
232 } __packed;
233 #endif /* WPS */
234
235 struct local_ap_t {
236         u8 bssid[6];
237         u8 rssi;
238         u8 sq;
239         struct {
240                 u8 size;
241                 u8 body[32];
242                 u8 ssid_pad;
243         } ssid;
244         struct {
245                 u8 size;
246                 u8 body[16];
247                 u8 rate_pad;
248         } rate_set;
249         u16 capability;
250         u8 channel;
251         u8 noise;
252         struct rsn_ie_t wpa_ie;
253         struct rsn_ie_t rsn_ie;
254 #ifdef WPS
255         struct wps_ie_t wps_ie;
256 #endif /* WPS */
257 };
258
259 #define LOCAL_APLIST_MAX 31
260 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
261 struct local_aplist_t {
262         int size;
263         struct local_ap_t ap[LOCAL_APLIST_MAX + 1];
264 };
265
266 struct local_gain_t {
267         u8 tx_mode;
268         u8 rx_mode;
269         u8 tx_gain;
270         u8 rx_gain;
271 };
272
273 struct local_eeprom_sum_t {
274         u8 type;
275         u8 result;
276 };
277
278 enum {
279         EEPROM_OK,
280         EEPROM_CHECKSUM_NONE,
281         EEPROM_FW_NOT_SUPPORT,
282         EEPROM_NG,
283 };
284
285 /* Power Save Status */
286 enum {
287         PS_NONE,
288         PS_ACTIVE_SET,
289         PS_SAVE_SET,
290         PS_CONF_WAIT,
291         PS_SNOOZE,
292         PS_WAKEUP
293 };
294
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;
300 };
301
302 struct sleep_status_t {
303         atomic_t status;        /* initialvalue 0 */
304         atomic_t doze_request;
305         atomic_t wakeup_request;
306 };
307
308 /* WPA */
309 struct scan_ext_t {
310         unsigned int flag;
311         char ssid[IW_ESSID_MAX_SIZE + 1];
312 };
313
314 enum {
315         CIPHER_NONE,
316         CIPHER_WEP40,
317         CIPHER_TKIP,
318         CIPHER_CCMP,
319         CIPHER_WEP104
320 };
321
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"
327
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"
333
334 #define CIPHER_ID_LEN    4
335
336 enum {
337         KEY_MGMT_802_1X,
338         KEY_MGMT_PSK,
339         KEY_MGMT_WPANONE,
340 };
341
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"
346
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"
351
352 #define KEY_MGMT_ID_LEN  4
353
354 #define MIC_KEY_SIZE 8
355
356 struct wpa_key_t {
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
362                                  * individual keys
363                                  */
364         u16 alg;
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];
369 };
370
371 #define WPA_KEY_INDEX_MAX 4
372 #define WPA_RX_SEQ_LEN 6
373
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 */
379 };
380
381 struct wpa_status_t {
382         int wpa_enabled;
383         unsigned int rsn_enabled;
384         int version;
385         int pairwise_suite;     /* unicast cipher */
386         int group_suite;        /* multicast cipher */
387         int key_mgmt_suite;     /* authentication key management suite */
388         int auth_alg;
389         int txkey;
390         struct wpa_key_t key[WPA_KEY_INDEX_MAX];
391         struct scan_ext_t scan_ext;
392         struct mic_failure_t mic_failure;
393 };
394
395 #include <linux/list.h>
396 #define PMK_LIST_MAX 8
397 struct pmk_list_t {
398         u16 size;
399         struct list_head head;
400         struct pmk_t {
401                 struct list_head list;
402                 u8 bssid[ETH_ALEN];
403                 u8 pmkid[IW_PMKID_LEN];
404         } pmk[PMK_LIST_MAX];
405 };
406
407 #ifdef WPS
408 struct wps_status_t {
409         int wps_enabled;
410         int ielen;
411         u8 ie[255];
412 };
413 #endif /* WPS */
414
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;
421
422         struct net_device *net_dev;
423         int reg_net;    /* register_netdev */
424         struct net_device_stats nstats;
425         struct iw_statistics wstats;
426
427         struct completion confirm_wait;
428
429         /* trx device & sme */
430         struct tx_device tx_dev;
431         struct rx_device rx_dev;
432         struct sme_info sme_i;
433         u8 *rxp;
434         unsigned int rx_size;
435         struct tasklet_struct sme_task;
436         struct work_struct wakeup_work;
437         int scan_ind_count;
438
439         unsigned char eth_addr[ETH_ALEN];
440
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;
449         u8 current_rate;
450
451         char nick[IW_ESSID_MAX_SIZE + 1];
452
453         spinlock_t multicast_spin;
454
455         spinlock_t dev_read_lock;
456         wait_queue_head_t devread_wait;
457
458         unsigned int need_commit;       /* for ioctl */
459
460         /* DeviceIoControl */
461         int device_open_status;
462         atomic_t event_count;
463         atomic_t rec_count;
464         int dev_count;
465 #define DEVICE_STOCK_COUNT 20
466         unsigned char *dev_data[DEVICE_STOCK_COUNT];
467         int dev_size[DEVICE_STOCK_COUNT];
468
469         /* ioctl : IOCTL_FIRMWARE_VERSION */
470         unsigned char firmware_version[128 + 1];
471         int version_size;
472
473         int mac_address_valid;  /* Mac Address Status */
474
475         int dev_state;
476
477         struct sk_buff *skb;
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 */
484
485         u8 data_buff[0x1000];
486
487         u8 scan_ssid_len;
488         u8 scan_ssid[IW_ESSID_MAX_SIZE + 1];
489         struct local_gain_t gain;
490 #ifdef WPS
491         struct net_device *l2_dev;
492         int l2_fd;
493         struct wps_status_t wps;
494 #endif /* WPS */
495         u8 sleep_mode;
496
497         u8 region;
498         struct local_eeprom_sum_t eeprom_sum;
499         u8 eeprom_checksum;
500
501         struct hostt_t hostt;
502
503         unsigned long last_doze;
504         unsigned long last_wakeup;
505
506         uint wakeup_count;      /* for detect wakeup loop */
507 };
508
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);
513
514 #endif /* _KS_WLAN_H */