1
2
3
4
5
6
7 #ifndef WILC_WFI_NETDEVICE
8 #define WILC_WFI_NETDEVICE
9
10 #include <linux/tcp.h>
11 #include <linux/ieee80211.h>
12 #include <net/cfg80211.h>
13 #include <net/ieee80211_radiotap.h>
14 #include <linux/if_arp.h>
15 #include <linux/gpio/consumer.h>
16
17 #include "wilc_hif.h"
18 #include "wilc_wlan.h"
19 #include "wilc_wlan_cfg.h"
20
21 #define FLOW_CONTROL_LOWER_THRESHOLD 128
22 #define FLOW_CONTROL_UPPER_THRESHOLD 256
23
24 #define WILC_MAX_NUM_PMKIDS 16
25 #define PMKID_FOUND 1
26 #define NUM_STA_ASSOCIATED 8
27
28 #define NUM_REG_FRAME 2
29
30 #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
31 #define DEFAULT_LINK_SPEED 72
32
33 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
34
35 struct wilc_wfi_stats {
36 unsigned long rx_packets;
37 unsigned long tx_packets;
38 unsigned long rx_bytes;
39 unsigned long tx_bytes;
40 u64 rx_time;
41 u64 tx_time;
42
43 };
44
45 struct wilc_wfi_key {
46 u8 *key;
47 u8 *seq;
48 int key_len;
49 int seq_len;
50 u32 cipher;
51 };
52
53 struct wilc_wfi_wep_key {
54 u8 *key;
55 u8 key_len;
56 u8 key_idx;
57 };
58
59 struct sta_info {
60 u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
61 };
62
63
64 struct wilc_wfi_p2p_listen_params {
65 struct ieee80211_channel *listen_ch;
66 u32 listen_duration;
67 u64 listen_cookie;
68 };
69
70 struct wilc_p2p_var {
71 u8 local_random;
72 u8 recv_random;
73 bool is_wilc_ie;
74 };
75
76 static const u32 wilc_cipher_suites[] = {
77 WLAN_CIPHER_SUITE_WEP40,
78 WLAN_CIPHER_SUITE_WEP104,
79 WLAN_CIPHER_SUITE_TKIP,
80 WLAN_CIPHER_SUITE_CCMP,
81 WLAN_CIPHER_SUITE_AES_CMAC
82 };
83
84 #define CHAN2G(_channel, _freq, _flags) { \
85 .band = NL80211_BAND_2GHZ, \
86 .center_freq = (_freq), \
87 .hw_value = (_channel), \
88 .flags = (_flags), \
89 .max_antenna_gain = 0, \
90 .max_power = 30, \
91 }
92
93 static const struct ieee80211_channel wilc_2ghz_channels[] = {
94 CHAN2G(1, 2412, 0),
95 CHAN2G(2, 2417, 0),
96 CHAN2G(3, 2422, 0),
97 CHAN2G(4, 2427, 0),
98 CHAN2G(5, 2432, 0),
99 CHAN2G(6, 2437, 0),
100 CHAN2G(7, 2442, 0),
101 CHAN2G(8, 2447, 0),
102 CHAN2G(9, 2452, 0),
103 CHAN2G(10, 2457, 0),
104 CHAN2G(11, 2462, 0),
105 CHAN2G(12, 2467, 0),
106 CHAN2G(13, 2472, 0),
107 CHAN2G(14, 2484, 0)
108 };
109
110 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
111 .bitrate = (_rate), \
112 .hw_value = (_hw_value), \
113 .flags = (_flags), \
114 }
115
116 static struct ieee80211_rate wilc_bitrates[] = {
117 RATETAB_ENT(10, 0, 0),
118 RATETAB_ENT(20, 1, 0),
119 RATETAB_ENT(55, 2, 0),
120 RATETAB_ENT(110, 3, 0),
121 RATETAB_ENT(60, 9, 0),
122 RATETAB_ENT(90, 6, 0),
123 RATETAB_ENT(120, 7, 0),
124 RATETAB_ENT(180, 8, 0),
125 RATETAB_ENT(240, 9, 0),
126 RATETAB_ENT(360, 10, 0),
127 RATETAB_ENT(480, 11, 0),
128 RATETAB_ENT(540, 12, 0)
129 };
130
131 struct wilc_priv {
132 struct wireless_dev wdev;
133 struct cfg80211_scan_request *scan_req;
134
135 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
136 u64 tx_cookie;
137
138 bool cfg_scanning;
139
140 u8 associated_bss[ETH_ALEN];
141 struct sta_info assoc_stainfo;
142 struct sk_buff *skb;
143 struct net_device *dev;
144 struct host_if_drv *hif_drv;
145 struct wilc_pmkid_attr pmkid_list;
146 u8 wep_key[4][WLAN_KEY_LEN_WEP104];
147 u8 wep_key_len[4];
148
149 struct net_device *real_ndev;
150 struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
151 struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
152 u8 wilc_groupkey;
153
154 struct mutex scan_req_lock;
155 bool p2p_listen_state;
156 int scanned_cnt;
157 struct wilc_p2p_var p2p;
158
159 u64 inc_roc_cookie;
160 };
161
162 struct frame_reg {
163 u16 type;
164 bool reg;
165 };
166
167 #define MAX_TCP_SESSION 25
168 #define MAX_PENDING_ACKS 256
169
170 struct ack_session_info {
171 u32 seq_num;
172 u32 bigger_ack_num;
173 u16 src_port;
174 u16 dst_port;
175 u16 status;
176 };
177
178 struct pending_acks {
179 u32 ack_num;
180 u32 session_index;
181 struct txq_entry_t *txqe;
182 };
183
184 struct tcp_ack_filter {
185 struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
186 struct pending_acks pending_acks[MAX_PENDING_ACKS];
187 u32 pending_base;
188 u32 tcp_session;
189 u32 pending_acks_idx;
190 bool enabled;
191 };
192
193 struct wilc_vif {
194 u8 idx;
195 u8 iftype;
196 int monitor_flag;
197 int mac_opened;
198 struct frame_reg frame_reg[NUM_REG_FRAME];
199 struct net_device_stats netstats;
200 struct wilc *wilc;
201 u8 bssid[ETH_ALEN];
202 struct host_if_drv *hif_drv;
203 struct net_device *ndev;
204 u8 mode;
205 struct timer_list during_ip_timer;
206 struct timer_list periodic_rssi;
207 struct rf_info periodic_stat;
208 struct tcp_ack_filter ack_filter;
209 bool connecting;
210 struct wilc_priv priv;
211 };
212
213 struct wilc {
214 struct wiphy *wiphy;
215 const struct wilc_hif_func *hif_func;
216 int io_type;
217 s8 mac_status;
218 struct gpio_desc *gpio_irq;
219 struct clk *rtc_clk;
220 bool initialized;
221 int dev_irq_num;
222 int close;
223 u8 vif_num;
224 struct wilc_vif *vif[WILC_NUM_CONCURRENT_IFC];
225
226 struct mutex vif_mutex;
227 u8 open_ifcs;
228
229 struct mutex txq_add_to_head_cs;
230
231 spinlock_t txq_spinlock;
232
233 struct mutex rxq_cs;
234
235 struct mutex hif_cs;
236
237 struct completion cfg_event;
238 struct completion sync_event;
239 struct completion txq_event;
240 struct completion txq_thread_started;
241
242 struct task_struct *txq_thread;
243
244 int quit;
245
246 struct mutex cfg_cmd_lock;
247 struct wilc_cfg_frame cfg_frame;
248 u32 cfg_frame_offset;
249 u8 cfg_seq_no;
250
251 u8 *rx_buffer;
252 u32 rx_buffer_offset;
253 u8 *tx_buffer;
254
255 struct txq_entry_t txq_head;
256 int txq_entries;
257
258 struct rxq_entry_t rxq_head;
259
260 const struct firmware *firmware;
261
262 struct device *dev;
263 bool suspend_event;
264
265 int clients_count;
266 struct workqueue_struct *hif_workqueue;
267 enum chip_ps_states chip_ps_state;
268 struct wilc_cfg cfg;
269 void *bus_data;
270 struct net_device *monitor_dev;
271
272 struct mutex deinit_lock;
273 u8 sta_ch;
274 u8 op_ch;
275 struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
276 struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
277 struct ieee80211_supported_band band;
278 u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
279 };
280
281 struct wilc_wfi_mon_priv {
282 struct net_device *real_ndev;
283 };
284
285 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
286 void wilc_mac_indicate(struct wilc *wilc);
287 void wilc_netdev_cleanup(struct wilc *wilc);
288 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
289 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
290 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
291 int vif_type, enum nl80211_iftype type,
292 bool rtnl_locked);
293 #endif