blob: 8ba69ee67c070a830eb52699163d269c3d196407 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001/*!
2 * @file wilc_wfi_netdevice.h
3 * @brief Definitions for the network module
4 * @author mdaftedar
5 * @date 01 MAR 2012
6 * @version 1.0
7 */
8#ifndef WILC_WFI_NETDEVICE
9#define WILC_WFI_NETDEVICE
10
Johnny Kimc5c77ba2015-05-11 14:30:56 +090011#define WILC_WFI_RX_INTR 0x0001
12#define WILC_WFI_TX_INTR 0x0002
13
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090014#define WILC_WFI_TIMEOUT 5
Johnny Kimc5c77ba2015-05-11 14:30:56 +090015#define WILC_MAX_NUM_PMKIDS 16
16#define PMKID_LEN 16
17#define PMKID_FOUND 1
18 #define NUM_STA_ASSOCIATED 8
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/moduleparam.h>
23#include <linux/sched.h>
24#include <linux/kernel.h>
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090025#include <linux/slab.h>
26#include <linux/errno.h>
27#include <linux/types.h>
28#include <linux/interrupt.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090029#include <linux/time.h>
30#include <linux/in.h>
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090031#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/ip.h>
34#include <linux/tcp.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090035#include <linux/skbuff.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090036#include <linux/ieee80211.h>
37#include <net/cfg80211.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090038#include <linux/ieee80211.h>
39#include <net/cfg80211.h>
40#include <net/ieee80211_radiotap.h>
41#include <linux/if_arp.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090042#include <linux/in6.h>
43#include <asm/checksum.h>
44#include "host_interface.h"
45#include "wilc_wlan.h"
Chaehyun Lim30b2ba092015-10-02 16:41:15 +090046#include <linux/wireless.h>
Johnny Kimc5c77ba2015-05-11 14:30:56 +090047
48#define FLOW_CONTROL_LOWER_THRESHOLD 128
49#define FLOW_CONTROL_UPPER_THRESHOLD 256
50
Johnny Kimc5c77ba2015-05-11 14:30:56 +090051enum stats_flags {
Anish Bhattffda2032015-09-29 12:15:49 -070052 WILC_WFI_RX_PKT = BIT(0),
53 WILC_WFI_TX_PKT = BIT(1),
Johnny Kimc5c77ba2015-05-11 14:30:56 +090054};
55
56struct WILC_WFI_stats {
Johnny Kimc5c77ba2015-05-11 14:30:56 +090057 unsigned long rx_packets;
58 unsigned long tx_packets;
59 unsigned long rx_bytes;
60 unsigned long tx_bytes;
61 u64 rx_time;
62 u64 tx_time;
63
64};
65
66/*
67 * This structure is private to each device. It is used to pass
68 * packets in and out, so there is place for a packet
69 */
70
Johnny Kimc5c77ba2015-05-11 14:30:56 +090071#define num_reg_frame 2
Johnny Kimc5c77ba2015-05-11 14:30:56 +090072
73struct wilc_wfi_key {
74 u8 *key;
75 u8 *seq;
76 int key_len;
77 int seq_len;
78 u32 cipher;
79};
Sunghoon Cho36901b62015-06-26 15:48:15 +090080
Johnny Kimc5c77ba2015-05-11 14:30:56 +090081struct wilc_wfi_wep_key {
82 u8 *key;
83 u8 key_len;
84 u8 key_idx;
85};
86
87struct sta_info {
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090088 u8 au8Sta_AssociatedBss[MAX_NUM_STA][ETH_ALEN];
Johnny Kimc5c77ba2015-05-11 14:30:56 +090089};
90
Johnny Kimc5c77ba2015-05-11 14:30:56 +090091/*Parameters needed for host interface for remaining on channel*/
92struct wilc_wfi_p2pListenParams {
93 struct ieee80211_channel *pstrListenChan;
94 enum nl80211_channel_type tenuChannelType;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090095 u32 u32ListenDuration;
Chaehyun Lim57b298f2015-06-11 14:35:56 +090096 u64 u64ListenCookie;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090097 u32 u32ListenSessionID;
Johnny Kimc5c77ba2015-05-11 14:30:56 +090098};
99
Chaehyun Lim27268872015-09-15 14:06:13 +0900100struct wilc_priv {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101 struct wireless_dev *wdev;
102 struct cfg80211_scan_request *pstrScanReq;
103
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900104 struct wilc_wfi_p2pListenParams strRemainOnChanParams;
Chaehyun Lim57b298f2015-06-11 14:35:56 +0900105 u64 u64tx_cookie;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900106
Dean Lee72ed4dc2015-06-12 14:11:44 +0900107 bool bCfgScanning;
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900108 u32 u32RcvdChCount;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900109
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900110 u8 au8AssociatedBss[ETH_ALEN];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900111 struct sta_info assoc_stainfo;
112 struct net_device_stats stats;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900113 u8 monitor_flag;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900114 int status;
115 struct WILC_WFI_packet *ppool;
116 struct WILC_WFI_packet *rx_queue; /* List of incoming packets */
117 int rx_int_enabled;
118 int tx_packetlen;
119 u8 *tx_packetdata;
120 struct sk_buff *skb;
121 spinlock_t lock;
122 struct net_device *dev;
123 struct napi_struct napi;
Leo Kim441dc602015-10-12 16:55:35 +0900124 struct host_if_drv *hWILCWFIDrv;
Leo Kima949f902015-10-05 15:25:44 +0900125 struct host_if_pmkid_attr pmkid_list;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900126 struct WILC_WFI_stats netstats;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900127 u8 WILC_WFI_wep_default;
128 u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104];
129 u8 WILC_WFI_wep_key_len[4];
Sunghoon Cho70e59d92015-06-26 15:48:16 +0900130 /* The real interface that the monitor is on */
131 struct net_device *real_ndev;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900132 struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA];
133 struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA];
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900134 u8 wilc_groupkey;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900135 /* semaphores */
Arnd Bergmann83383ea2015-06-01 21:06:43 +0200136 struct semaphore SemHandleUpdateStats;
137 struct semaphore hSemScanReq;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900138 /* */
Dean Lee72ed4dc2015-06-12 14:11:44 +0900139 bool gbAutoRateAdjusted;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900140
Dean Lee72ed4dc2015-06-12 14:11:44 +0900141 bool bInP2PlistenState;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900142
143};
144
145typedef struct {
Chaehyun Limd85f5322015-06-11 14:35:54 +0900146 u16 frame_type;
Dean Lee72ed4dc2015-06-12 14:11:44 +0900147 bool reg;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900148
149} struct_frame_reg;
150
Tony Cho1a08bc42015-10-14 20:46:32 +0900151struct wilc_vif {
Tony Cho7e7fa472015-10-20 14:26:48 +0900152 u8 src_addr[ETH_ALEN];
Tony Cho7201cd22015-10-20 14:26:49 +0900153 u8 bssid[ETH_ALEN];
Tony Cho3134a572015-10-20 14:26:50 +0900154 struct host_if_drv *hif_drv;
Tony Cho817f3fb2015-10-20 14:26:51 +0900155 struct net_device *ndev;
Tony Cho1a08bc42015-10-14 20:46:32 +0900156};
Tony Chof61c5af2015-10-14 20:46:30 +0900157
158struct wilc {
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900159 int mac_status;
Tony Cho080f11b2015-10-20 14:26:45 +0900160 bool initialized;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900161 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
162 unsigned short dev_irq_num;
163 #endif
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900164 int close;
Tony Choc1b30f62015-10-20 14:26:46 +0900165 u8 vif_num;
Tony Cho8259a532015-10-20 14:26:47 +0900166 struct wilc_vif vif[NUM_CONCURRENT_IFC];
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900167 u8 open_ifcs;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900168
Greg Kroah-Hartman642768e2015-09-03 19:56:21 -0700169 struct semaphore txq_add_to_head_cs;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900170 spinlock_t txq_spinlock;
171
172 struct mutex rxq_cs;
173 struct mutex hif_cs;
174
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900175 struct semaphore cfg_event;
176 struct semaphore sync_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900177 struct semaphore txq_event;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900178
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900179 struct semaphore txq_thread_started;
180
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900181 struct task_struct *txq_thread;
182
183 unsigned char eth_src_address[NUM_CONCURRENT_IFC][6];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900184
Tony Cho8b8ad7b2015-10-20 14:26:53 +0900185 const struct firmware *firmware;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900186
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900187#ifdef WILC_SDIO
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900188 struct sdio_func *wilc_sdio_func;
189#else
190 struct spi_device *wilc_spidev;
191#endif
Tony Chof61c5af2015-10-14 20:46:30 +0900192};
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900193
194typedef struct {
Chaehyun Lim51e825f2015-09-15 14:06:14 +0900195 u8 u8IfIdx;
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +0900196 u8 iftype;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900197 int monitor_flag;
198 int mac_opened;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900199 struct_frame_reg g_struct_frame_reg[num_reg_frame];
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900200 struct net_device *wilc_netdev;
201 struct net_device_stats netstats;
Glen Lee38b3001d2015-10-20 17:13:51 +0900202 struct wilc *wilc;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900203} perInterface_wlan_t;
204
205struct WILC_WFI_mon_priv {
206 struct net_device *real_ndev;
207};
Sunghoon Cho1d1c5b22015-06-17 14:42:36 +0900208
Tony Chof61c5af2015-10-14 20:46:30 +0900209extern struct wilc *g_linux_wlan;
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900210extern struct net_device *WILC_WFI_devs[];
Glen Lee63611672015-09-24 18:14:52 +0900211void frmw_to_linux(u8 *buff, u32 size, u32 pkt_offset);
Glen Lee64f2b712015-10-27 18:27:43 +0900212void linux_wlan_mac_indicate(struct wilc *wilc, int flag);
Glen Leec0cadaa2015-09-24 18:14:54 +0900213void linux_wlan_rx_complete(void);
Glen Leeef2b7842015-09-24 18:14:55 +0900214void linux_wlan_dbg(u8 *buff);
Glen Leeb002e202015-09-24 18:15:05 +0900215int linux_wlan_lock_timeout(void *vp, u32 timeout);
Tony Cho4875c492015-10-20 14:26:52 +0900216void wl_wlan_cleanup(void);
Tony Cho12ba5412015-10-20 14:26:56 +0900217int wilc_netdev_init(struct wilc **wilc);
Glen Lee53dc0cf2015-10-20 17:13:57 +0900218void wilc1000_wlan_deinit(struct net_device *dev);
Glen Lee11f4b2e2015-10-27 18:27:51 +0900219void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900220#endif