Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *   Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
0004  *
0005  *   Copyright (C) 2006-2008 KeyStream Corp.
0006  *   Copyright (C) 2009 Renesas Technology Corp.
0007  */
0008 
0009 #ifndef _KS_WLAN_H
0010 #define _KS_WLAN_H
0011 
0012 #include <linux/atomic.h>
0013 #include <linux/circ_buf.h>
0014 #include <linux/completion.h>
0015 #include <linux/netdevice.h>
0016 #include <linux/sched.h>
0017 #include <linux/spinlock.h>
0018 #include <linux/wireless.h>
0019 
0020 struct ks_wlan_parameter {
0021     u8 operation_mode;
0022     u8 channel;
0023     u8 tx_rate;
0024     struct {
0025         u8 size;
0026         u8 body[16];
0027     } rate_set;
0028     u8 bssid[ETH_ALEN];
0029     struct {
0030         u8 size;
0031         u8 body[32 + 1];
0032     } ssid;
0033     u8 preamble;
0034     u8 power_mgmt;
0035     u32 scan_type;
0036 #define BEACON_LOST_COUNT_MAX 65535
0037     u32 beacon_lost_count;
0038     u32 rts;
0039     u32 fragment;
0040     u32 privacy_invoked;
0041     u32 wep_index;
0042     struct {
0043         u8 size;
0044         u8 val[13 * 2 + 1];
0045     } wep_key[4];
0046     u16 authenticate_type;
0047     u16 phy_type;
0048     u16 cts_mode;
0049     u16 phy_info_timer;
0050 };
0051 
0052 enum {
0053     DEVICE_STATE_OFF = 0,   /* this means hw_unavailable is != 0 */
0054     DEVICE_STATE_PREBOOT,   /* we are in a pre-boot state (empty RAM) */
0055     DEVICE_STATE_BOOT,  /* boot state (fw upload, run fw) */
0056     DEVICE_STATE_PREINIT,   /* pre-init state */
0057     DEVICE_STATE_INIT,  /* init state (restore MIB backup to device) */
0058     DEVICE_STATE_READY, /* driver&device are in operational state */
0059     DEVICE_STATE_SLEEP  /* device in sleep mode */
0060 };
0061 
0062 /* SME flag */
0063 #define SME_MODE_SET        BIT(0)
0064 #define SME_RTS             BIT(1)
0065 #define SME_FRAG            BIT(2)
0066 #define SME_WEP_FLAG        BIT(3)
0067 #define SME_WEP_INDEX       BIT(4)
0068 #define SME_WEP_VAL1        BIT(5)
0069 #define SME_WEP_VAL2        BIT(6)
0070 #define SME_WEP_VAL3        BIT(7)
0071 #define SME_WEP_VAL4        BIT(8)
0072 #define SME_WEP_VAL_MASK    GENMASK(8, 5)
0073 #define SME_RSN             BIT(9)
0074 #define SME_RSN_MULTICAST   BIT(10)
0075 #define SME_RSN_UNICAST     BIT(11)
0076 #define SME_RSN_AUTH        BIT(12)
0077 
0078 #define SME_AP_SCAN         BIT(13)
0079 #define SME_MULTICAST       BIT(14)
0080 
0081 /* SME Event */
0082 enum {
0083     SME_START,
0084 
0085     SME_MULTICAST_REQUEST,
0086     SME_MACADDRESS_SET_REQUEST,
0087     SME_BSS_SCAN_REQUEST,
0088     SME_SET_FLAG,
0089     SME_SET_TXKEY,
0090     SME_SET_KEY1,
0091     SME_SET_KEY2,
0092     SME_SET_KEY3,
0093     SME_SET_KEY4,
0094     SME_SET_PMK_TSC,
0095     SME_SET_GMK1_TSC,
0096     SME_SET_GMK2_TSC,
0097     SME_SET_GMK3_TSC,
0098     SME_SET_PMKSA,
0099     SME_POW_MNGMT_REQUEST,
0100     SME_PHY_INFO_REQUEST,
0101     SME_MIC_FAILURE_REQUEST,
0102     SME_GET_MAC_ADDRESS,
0103     SME_GET_PRODUCT_VERSION,
0104     SME_STOP_REQUEST,
0105     SME_RTS_THRESHOLD_REQUEST,
0106     SME_FRAGMENTATION_THRESHOLD_REQUEST,
0107     SME_WEP_INDEX_REQUEST,
0108     SME_WEP_KEY1_REQUEST,
0109     SME_WEP_KEY2_REQUEST,
0110     SME_WEP_KEY3_REQUEST,
0111     SME_WEP_KEY4_REQUEST,
0112     SME_WEP_FLAG_REQUEST,
0113     SME_RSN_UCAST_REQUEST,
0114     SME_RSN_MCAST_REQUEST,
0115     SME_RSN_AUTH_REQUEST,
0116     SME_RSN_ENABLED_REQUEST,
0117     SME_RSN_MODE_REQUEST,
0118     SME_WPS_ENABLE_REQUEST,
0119     SME_WPS_PROBE_REQUEST,
0120     SME_SET_GAIN,
0121     SME_GET_GAIN,
0122     SME_SLEEP_REQUEST,
0123     SME_SET_REGION,
0124     SME_MODE_SET_REQUEST,
0125     SME_START_REQUEST,
0126     SME_GET_EEPROM_CKSUM,
0127 
0128     SME_MIC_FAILURE_CONFIRM,
0129     SME_START_CONFIRM,
0130 
0131     SME_MULTICAST_CONFIRM,
0132     SME_BSS_SCAN_CONFIRM,
0133     SME_GET_CURRENT_AP,
0134     SME_POW_MNGMT_CONFIRM,
0135     SME_PHY_INFO_CONFIRM,
0136     SME_STOP_CONFIRM,
0137     SME_RTS_THRESHOLD_CONFIRM,
0138     SME_FRAGMENTATION_THRESHOLD_CONFIRM,
0139     SME_WEP_INDEX_CONFIRM,
0140     SME_WEP_KEY1_CONFIRM,
0141     SME_WEP_KEY2_CONFIRM,
0142     SME_WEP_KEY3_CONFIRM,
0143     SME_WEP_KEY4_CONFIRM,
0144     SME_WEP_FLAG_CONFIRM,
0145     SME_RSN_UCAST_CONFIRM,
0146     SME_RSN_MCAST_CONFIRM,
0147     SME_RSN_AUTH_CONFIRM,
0148     SME_RSN_ENABLED_CONFIRM,
0149     SME_RSN_MODE_CONFIRM,
0150     SME_MODE_SET_CONFIRM,
0151     SME_SLEEP_CONFIRM,
0152 
0153     SME_RSN_SET_CONFIRM,
0154     SME_WEP_SET_CONFIRM,
0155     SME_TERMINATE,
0156 
0157     SME_EVENT_SIZE
0158 };
0159 
0160 /* SME Status */
0161 enum {
0162     SME_IDLE,
0163     SME_SETUP,
0164     SME_DISCONNECT,
0165     SME_CONNECT
0166 };
0167 
0168 #define SME_EVENT_BUFF_SIZE 128
0169 
0170 struct sme_info {
0171     int sme_status;
0172     int event_buff[SME_EVENT_BUFF_SIZE];
0173     unsigned int qhead;
0174     unsigned int qtail;
0175     spinlock_t sme_spin;
0176     unsigned long sme_flag;
0177 };
0178 
0179 struct hostt {
0180     int buff[SME_EVENT_BUFF_SIZE];
0181     unsigned int qhead;
0182     unsigned int qtail;
0183 };
0184 
0185 #define RSN_IE_BODY_MAX 64
0186 struct rsn_ie {
0187     u8 id;  /* 0xdd = WPA or 0x30 = RSN */
0188     u8 size;    /* max ? 255 ? */
0189     u8 body[RSN_IE_BODY_MAX];
0190 } __packed;
0191 
0192 #define WPA_INFO_ELEM_ID 0xdd
0193 #define RSN_INFO_ELEM_ID 0x30
0194 
0195 #define WPS_IE_BODY_MAX 255
0196 struct wps_ie {
0197     u8 id;  /* 221 'dd <len> 00 50 F2 04' */
0198     u8 size;    /* max ? 255 ? */
0199     u8 body[WPS_IE_BODY_MAX];
0200 } __packed;
0201 
0202 struct local_ap {
0203     u8 bssid[6];
0204     u8 rssi;
0205     u8 sq;
0206     struct {
0207         u8 size;
0208         u8 body[32];
0209         u8 ssid_pad;
0210     } ssid;
0211     struct {
0212         u8 size;
0213         u8 body[16];
0214         u8 rate_pad;
0215     } rate_set;
0216     u16 capability;
0217     u8 channel;
0218     u8 noise;
0219     struct rsn_ie wpa_ie;
0220     struct rsn_ie rsn_ie;
0221     struct wps_ie wps_ie;
0222 };
0223 
0224 #define LOCAL_APLIST_MAX 31
0225 #define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
0226 struct local_aplist {
0227     int size;
0228     struct local_ap ap[LOCAL_APLIST_MAX + 1];
0229 };
0230 
0231 struct local_gain {
0232     u8 tx_mode;
0233     u8 rx_mode;
0234     u8 tx_gain;
0235     u8 rx_gain;
0236 };
0237 
0238 struct local_eeprom_sum {
0239     u8 type;
0240     u8 result;
0241 };
0242 
0243 enum {
0244     EEPROM_OK,
0245     EEPROM_CHECKSUM_NONE,
0246     EEPROM_FW_NOT_SUPPORT,
0247     EEPROM_NG,
0248 };
0249 
0250 /* Power Save Status */
0251 enum {
0252     PS_NONE,
0253     PS_ACTIVE_SET,
0254     PS_SAVE_SET,
0255     PS_CONF_WAIT,
0256     PS_SNOOZE,
0257     PS_WAKEUP
0258 };
0259 
0260 struct power_save_status {
0261     atomic_t status;    /* initialvalue 0 */
0262     struct completion wakeup_wait;
0263     atomic_t confirm_wait;
0264     atomic_t snooze_guard;
0265 };
0266 
0267 struct sleep_status {
0268     atomic_t status;    /* initialvalue 0 */
0269     atomic_t doze_request;
0270     atomic_t wakeup_request;
0271 };
0272 
0273 /* WPA */
0274 struct scan_ext {
0275     unsigned int flag;
0276     char ssid[IW_ESSID_MAX_SIZE + 1];
0277 };
0278 
0279 #define CIPHER_ID_WPA_NONE    "\x00\x50\xf2\x00"
0280 #define CIPHER_ID_WPA_WEP40   "\x00\x50\xf2\x01"
0281 #define CIPHER_ID_WPA_TKIP    "\x00\x50\xf2\x02"
0282 #define CIPHER_ID_WPA_CCMP    "\x00\x50\xf2\x04"
0283 #define CIPHER_ID_WPA_WEP104  "\x00\x50\xf2\x05"
0284 
0285 #define CIPHER_ID_WPA2_NONE   "\x00\x0f\xac\x00"
0286 #define CIPHER_ID_WPA2_WEP40  "\x00\x0f\xac\x01"
0287 #define CIPHER_ID_WPA2_TKIP   "\x00\x0f\xac\x02"
0288 #define CIPHER_ID_WPA2_CCMP   "\x00\x0f\xac\x04"
0289 #define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
0290 
0291 #define CIPHER_ID_LEN    4
0292 
0293 enum {
0294     KEY_MGMT_802_1X,
0295     KEY_MGMT_PSK,
0296     KEY_MGMT_WPANONE,
0297 };
0298 
0299 #define KEY_MGMT_ID_WPA_NONE     "\x00\x50\xf2\x00"
0300 #define KEY_MGMT_ID_WPA_1X       "\x00\x50\xf2\x01"
0301 #define KEY_MGMT_ID_WPA_PSK      "\x00\x50\xf2\x02"
0302 #define KEY_MGMT_ID_WPA_WPANONE  "\x00\x50\xf2\xff"
0303 
0304 #define KEY_MGMT_ID_WPA2_NONE    "\x00\x0f\xac\x00"
0305 #define KEY_MGMT_ID_WPA2_1X      "\x00\x0f\xac\x01"
0306 #define KEY_MGMT_ID_WPA2_PSK     "\x00\x0f\xac\x02"
0307 #define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
0308 
0309 #define KEY_MGMT_ID_LEN  4
0310 
0311 #define MIC_KEY_SIZE 8
0312 
0313 struct wpa_key {
0314     u32 ext_flags;  /* IW_ENCODE_EXT_xxx */
0315     u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE];  /* LSB first */
0316     u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE];  /* LSB first */
0317     struct sockaddr addr;   /* ff:ff:ff:ff:ff:ff for broadcast/multicast
0318                  * (group) keys or unicast address for
0319                  * individual keys
0320                  */
0321     u16 alg;
0322     u16 key_len;    /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
0323     u8 key_val[IW_ENCODING_TOKEN_MAX];
0324     u8 tx_mic_key[MIC_KEY_SIZE];
0325     u8 rx_mic_key[MIC_KEY_SIZE];
0326 };
0327 
0328 #define WPA_KEY_INDEX_MAX 4
0329 #define WPA_RX_SEQ_LEN 6
0330 
0331 struct mic_failure {
0332     u16 failure;    /* MIC Failure counter 0 or 1 or 2 */
0333     u16 counter;    /* 1sec counter 0-60 */
0334     u32 last_failure_time;
0335     int stop;
0336 };
0337 
0338 struct wpa_status {
0339     int wpa_enabled;
0340     bool rsn_enabled;
0341     int version;
0342     int pairwise_suite; /* unicast cipher */
0343     int group_suite;    /* multicast cipher */
0344     int key_mgmt_suite;
0345     int auth_alg;
0346     int txkey;
0347     struct wpa_key key[WPA_KEY_INDEX_MAX];
0348     struct scan_ext scan_ext;
0349     struct mic_failure mic_failure;
0350 };
0351 
0352 #include <linux/list.h>
0353 #define PMK_LIST_MAX 8
0354 struct pmk_list {
0355     u16 size;
0356     struct list_head head;
0357     struct pmk {
0358         struct list_head list;
0359         u8 bssid[ETH_ALEN];
0360         u8 pmkid[IW_PMKID_LEN];
0361     } pmk[PMK_LIST_MAX];
0362 };
0363 
0364 struct wps_status {
0365     int wps_enabled;
0366     int ielen;
0367     u8 ie[255];
0368 };
0369 
0370 /* Tx Device struct */
0371 #define TX_DEVICE_BUFF_SIZE 1024
0372 
0373 struct ks_wlan_private;
0374 
0375 /**
0376  * struct tx_device_buffer - Queue item for the tx queue.
0377  * @sendp: Pointer to the send request data.
0378  * @size: Size of @sendp data.
0379  * @complete_handler: Function called once data write to device is complete.
0380  * @arg1: First argument to @complete_handler.
0381  * @arg2: Second argument to @complete_handler.
0382  */
0383 struct tx_device_buffer {
0384     unsigned char *sendp;
0385     unsigned int size;
0386     void (*complete_handler)(struct ks_wlan_private *priv,
0387                  struct sk_buff *skb);
0388     struct sk_buff *skb;
0389 };
0390 
0391 /**
0392  * struct tx_device - Tx buffer queue.
0393  * @tx_device_buffer: Queue buffer.
0394  * @qhead: Head of tx queue.
0395  * @qtail: Tail of tx queue.
0396  * @tx_dev_lock: Queue lock.
0397  */
0398 struct tx_device {
0399     struct tx_device_buffer tx_dev_buff[TX_DEVICE_BUFF_SIZE];
0400     unsigned int qhead;
0401     unsigned int qtail;
0402     spinlock_t tx_dev_lock; /* protect access to the queue */
0403 };
0404 
0405 /* Rx Device struct */
0406 #define RX_DATA_SIZE    (2 + 2 + 2347 + 1)
0407 #define RX_DEVICE_BUFF_SIZE 32
0408 
0409 /**
0410  * struct rx_device_buffer - Queue item for the rx queue.
0411  * @data: rx data.
0412  * @size: Size of @data.
0413  */
0414 struct rx_device_buffer {
0415     unsigned char data[RX_DATA_SIZE];
0416     unsigned int size;
0417 };
0418 
0419 /**
0420  * struct rx_device - Rx buffer queue.
0421  * @rx_device_buffer: Queue buffer.
0422  * @qhead: Head of rx queue.
0423  * @qtail: Tail of rx queue.
0424  * @rx_dev_lock: Queue lock.
0425  */
0426 struct rx_device {
0427     struct rx_device_buffer rx_dev_buff[RX_DEVICE_BUFF_SIZE];
0428     unsigned int qhead;
0429     unsigned int qtail;
0430     spinlock_t rx_dev_lock; /* protect access to the queue */
0431 };
0432 
0433 struct ks_wlan_private {
0434     /* hardware information */
0435     void *if_hw;
0436     struct workqueue_struct *wq;
0437     struct delayed_work rw_dwork;
0438     struct tasklet_struct rx_bh_task;
0439 
0440     struct net_device *net_dev;
0441     struct net_device_stats nstats;
0442     struct iw_statistics wstats;
0443 
0444     struct completion confirm_wait;
0445 
0446     /* trx device & sme */
0447     struct tx_device tx_dev;
0448     struct rx_device rx_dev;
0449     struct sme_info sme_i;
0450     u8 *rxp;
0451     unsigned int rx_size;
0452     struct work_struct sme_work;
0453     struct work_struct wakeup_work;
0454     int scan_ind_count;
0455 
0456     unsigned char eth_addr[ETH_ALEN];
0457 
0458     struct local_aplist aplist;
0459     struct local_ap current_ap;
0460     struct power_save_status psstatus;
0461     struct sleep_status sleepstatus;
0462     struct wpa_status wpa;
0463     struct pmk_list pmklist;
0464     /* wireless parameter */
0465     struct ks_wlan_parameter reg;
0466     u8 current_rate;
0467 
0468     char nick[IW_ESSID_MAX_SIZE + 1];
0469 
0470     spinlock_t multicast_spin;
0471 
0472     spinlock_t dev_read_lock;
0473     wait_queue_head_t devread_wait;
0474 
0475     unsigned int need_commit;   /* for ioctl */
0476 
0477     /* DeviceIoControl */
0478     bool is_device_open;
0479     atomic_t event_count;
0480     atomic_t rec_count;
0481     int dev_count;
0482 #define DEVICE_STOCK_COUNT 20
0483     unsigned char *dev_data[DEVICE_STOCK_COUNT];
0484     int dev_size[DEVICE_STOCK_COUNT];
0485 
0486     /* ioctl : IOCTL_FIRMWARE_VERSION */
0487     unsigned char firmware_version[128 + 1];
0488     int version_size;
0489 
0490     bool mac_address_valid;
0491 
0492     int dev_state;
0493 
0494     struct sk_buff *skb;
0495     unsigned int cur_rx;    /* Index into the Rx buffer of next Rx pkt. */
0496 #define FORCE_DISCONNECT    0x80000000
0497 #define CONNECT_STATUS_MASK 0x7FFFFFFF
0498     u32 connect_status;
0499     int infra_status;
0500     u8 scan_ssid_len;
0501     u8 scan_ssid[IW_ESSID_MAX_SIZE + 1];
0502     struct local_gain gain;
0503     struct wps_status wps;
0504     u8 sleep_mode;
0505 
0506     u8 region;
0507     struct local_eeprom_sum eeprom_sum;
0508     u8 eeprom_checksum;
0509 
0510     struct hostt hostt;
0511 
0512     unsigned long last_doze;
0513     unsigned long last_wakeup;
0514 
0515     unsigned int wakeup_count;  /* for detect wakeup loop */
0516 };
0517 
0518 static inline void inc_txqhead(struct ks_wlan_private *priv)
0519 {
0520     priv->tx_dev.qhead = (priv->tx_dev.qhead + 1) % TX_DEVICE_BUFF_SIZE;
0521 }
0522 
0523 static inline void inc_txqtail(struct ks_wlan_private *priv)
0524 {
0525     priv->tx_dev.qtail = (priv->tx_dev.qtail + 1) % TX_DEVICE_BUFF_SIZE;
0526 }
0527 
0528 static inline bool txq_has_space(struct ks_wlan_private *priv)
0529 {
0530     return (CIRC_SPACE(priv->tx_dev.qhead, priv->tx_dev.qtail,
0531                TX_DEVICE_BUFF_SIZE) > 0);
0532 }
0533 
0534 static inline void inc_rxqhead(struct ks_wlan_private *priv)
0535 {
0536     priv->rx_dev.qhead = (priv->rx_dev.qhead + 1) % RX_DEVICE_BUFF_SIZE;
0537 }
0538 
0539 static inline void inc_rxqtail(struct ks_wlan_private *priv)
0540 {
0541     priv->rx_dev.qtail = (priv->rx_dev.qtail + 1) % RX_DEVICE_BUFF_SIZE;
0542 }
0543 
0544 static inline bool rxq_has_space(struct ks_wlan_private *priv)
0545 {
0546     return (CIRC_SPACE(priv->rx_dev.qhead, priv->rx_dev.qtail,
0547                RX_DEVICE_BUFF_SIZE) > 0);
0548 }
0549 
0550 static inline unsigned int txq_count(struct ks_wlan_private *priv)
0551 {
0552     return CIRC_CNT_TO_END(priv->tx_dev.qhead, priv->tx_dev.qtail,
0553                    TX_DEVICE_BUFF_SIZE);
0554 }
0555 
0556 static inline unsigned int rxq_count(struct ks_wlan_private *priv)
0557 {
0558     return CIRC_CNT_TO_END(priv->rx_dev.qhead, priv->rx_dev.qtail,
0559                    RX_DEVICE_BUFF_SIZE);
0560 }
0561 
0562 int ks_wlan_net_start(struct net_device *dev);
0563 int ks_wlan_net_stop(struct net_device *dev);
0564 bool is_connect_status(u32 status);
0565 bool is_disconnect_status(u32 status);
0566 
0567 #endif /* _KS_WLAN_H */