1 /*
2  * Copyright (c) 2015-2016 Quantenna Communications, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16 
17 #ifndef _QTN_QLINK_H_
18 #define _QTN_QLINK_H_
19 
20 #include <linux/ieee80211.h>
21 
22 #define QLINK_PROTO_VER		6
23 
24 #define QLINK_MACID_RSVD		0xFF
25 #define QLINK_VIFID_RSVD		0xFF
26 
27 /* Common QLINK protocol messages definitions.
28  */
29 
30 /**
31  * enum qlink_msg_type - QLINK message types
32  *
33  * Used to distinguish between message types of QLINK protocol.
34  *
35  * @QLINK_MSG_TYPE_CMD: Message is carrying data of a command sent from
36  *	driver to wireless hardware.
37  * @QLINK_MSG_TYPE_CMDRSP: Message is carrying data of a response to a command.
38  *	Sent from wireless HW to driver in reply to previously issued command.
39  * @QLINK_MSG_TYPE_EVENT: Data for an event originated in wireless hardware and
40  *	sent asynchronously to driver.
41  */
42 enum qlink_msg_type {
43 	QLINK_MSG_TYPE_CMD	= 1,
44 	QLINK_MSG_TYPE_CMDRSP	= 2,
45 	QLINK_MSG_TYPE_EVENT	= 3
46 };
47 
48 /**
49  * struct qlink_msg_header - common QLINK protocol message header
50  *
51  * Portion of QLINK protocol header common for all message types.
52  *
53  * @type: Message type, one of &enum qlink_msg_type.
54  * @len: Total length of message including all headers.
55  */
56 struct qlink_msg_header {
57 	__le16 type;
58 	__le16 len;
59 } __packed;
60 
61 /* Generic definitions of data and information carried in QLINK messages
62  */
63 
64 /**
65  * enum qlink_hw_capab - device capabilities.
66  *
67  * @QLINK_HW_CAPAB_REG_UPDATE: device can update it's regulatory region.
68  * @QLINK_HW_CAPAB_STA_INACT_TIMEOUT: device implements a logic to kick-out
69  *	associated STAs due to inactivity. Inactivity timeout period is taken
70  *	from QLINK_CMD_START_AP parameters.
71  */
72 enum qlink_hw_capab {
73 	QLINK_HW_CAPAB_REG_UPDATE = BIT(0),
74 	QLINK_HW_CAPAB_STA_INACT_TIMEOUT = BIT(1),
75 };
76 
77 enum qlink_iface_type {
78 	QLINK_IFTYPE_AP		= 1,
79 	QLINK_IFTYPE_STATION	= 2,
80 	QLINK_IFTYPE_ADHOC	= 3,
81 	QLINK_IFTYPE_MONITOR	= 4,
82 	QLINK_IFTYPE_WDS	= 5,
83 	QLINK_IFTYPE_AP_VLAN	= 6,
84 };
85 
86 /**
87  * struct qlink_intf_info - information on virtual interface.
88  *
89  * Data describing a single virtual interface.
90  *
91  * @if_type: Mode of interface operation, one of &enum qlink_iface_type
92  * @vlanid: VLAN ID for AP_VLAN interface type
93  * @mac_addr: MAC address of virtual interface.
94  */
95 struct qlink_intf_info {
96 	__le16 if_type;
97 	__le16 vlanid;
98 	u8 mac_addr[ETH_ALEN];
99 	u8 rsvd[2];
100 } __packed;
101 
102 enum qlink_sta_flags {
103 	QLINK_STA_FLAG_INVALID		= 0,
104 	QLINK_STA_FLAG_AUTHORIZED		= BIT(0),
105 	QLINK_STA_FLAG_SHORT_PREAMBLE	= BIT(1),
106 	QLINK_STA_FLAG_WME			= BIT(2),
107 	QLINK_STA_FLAG_MFP			= BIT(3),
108 	QLINK_STA_FLAG_AUTHENTICATED		= BIT(4),
109 	QLINK_STA_FLAG_TDLS_PEER		= BIT(5),
110 	QLINK_STA_FLAG_ASSOCIATED		= BIT(6),
111 };
112 
113 enum qlink_channel_width {
114 	QLINK_CHAN_WIDTH_5 = 0,
115 	QLINK_CHAN_WIDTH_10,
116 	QLINK_CHAN_WIDTH_20_NOHT,
117 	QLINK_CHAN_WIDTH_20,
118 	QLINK_CHAN_WIDTH_40,
119 	QLINK_CHAN_WIDTH_80,
120 	QLINK_CHAN_WIDTH_80P80,
121 	QLINK_CHAN_WIDTH_160,
122 };
123 
124 /**
125  * struct qlink_chandef - qlink channel definition
126  *
127  * @center_freq1: center frequency of first segment
128  * @center_freq2: center frequency of second segment (80+80 only)
129  * @width: channel width, one of @enum qlink_channel_width
130  */
131 struct qlink_chandef {
132 	__le16 center_freq1;
133 	__le16 center_freq2;
134 	u8 width;
135 	u8 rsvd[3];
136 } __packed;
137 
138 #define QLINK_MAX_NR_CIPHER_SUITES            5
139 #define QLINK_MAX_NR_AKM_SUITES               2
140 
141 struct qlink_auth_encr {
142 	__le32 wpa_versions;
143 	__le32 cipher_group;
144 	__le32 n_ciphers_pairwise;
145 	__le32 ciphers_pairwise[QLINK_MAX_NR_CIPHER_SUITES];
146 	__le32 n_akm_suites;
147 	__le32 akm_suites[QLINK_MAX_NR_AKM_SUITES];
148 	__le16 control_port_ethertype;
149 	u8 auth_type;
150 	u8 privacy;
151 	u8 control_port;
152 	u8 control_port_no_encrypt;
153 	u8 rsvd[2];
154 } __packed;
155 
156 /* QLINK Command messages related definitions
157  */
158 
159 /**
160  * enum qlink_cmd_type - list of supported commands
161  *
162  * Commands are QLINK messages of type @QLINK_MSG_TYPE_CMD, sent by driver to
163  * wireless network device for processing. Device is expected to send back a
164  * reply message of type &QLINK_MSG_TYPE_CMDRSP, containing at least command
165  * execution status (one of &enum qlink_cmd_result). Reply message
166  * may also contain data payload specific to the command type.
167  *
168  * @QLINK_CMD_BAND_INFO_GET: for the specified MAC and specified band, get
169  *	the band's description including number of operational channels and
170  *	info on each channel, HT/VHT capabilities, supported rates etc.
171  *	This command is generic to a specified MAC, interface index must be set
172  *	to QLINK_VIFID_RSVD in command header.
173  * @QLINK_CMD_REG_NOTIFY: notify device about regulatory domain change. This
174  *	command is supported only if device reports QLINK_HW_SUPPORTS_REG_UPDATE
175  *	capability.
176  */
177 enum qlink_cmd_type {
178 	QLINK_CMD_FW_INIT		= 0x0001,
179 	QLINK_CMD_FW_DEINIT		= 0x0002,
180 	QLINK_CMD_REGISTER_MGMT		= 0x0003,
181 	QLINK_CMD_SEND_MGMT_FRAME	= 0x0004,
182 	QLINK_CMD_MGMT_SET_APPIE	= 0x0005,
183 	QLINK_CMD_PHY_PARAMS_GET	= 0x0011,
184 	QLINK_CMD_PHY_PARAMS_SET	= 0x0012,
185 	QLINK_CMD_GET_HW_INFO		= 0x0013,
186 	QLINK_CMD_MAC_INFO		= 0x0014,
187 	QLINK_CMD_ADD_INTF		= 0x0015,
188 	QLINK_CMD_DEL_INTF		= 0x0016,
189 	QLINK_CMD_CHANGE_INTF		= 0x0017,
190 	QLINK_CMD_UPDOWN_INTF		= 0x0018,
191 	QLINK_CMD_REG_NOTIFY		= 0x0019,
192 	QLINK_CMD_BAND_INFO_GET		= 0x001A,
193 	QLINK_CMD_CHAN_SWITCH		= 0x001B,
194 	QLINK_CMD_CHAN_GET		= 0x001C,
195 	QLINK_CMD_START_AP		= 0x0021,
196 	QLINK_CMD_STOP_AP		= 0x0022,
197 	QLINK_CMD_GET_STA_INFO		= 0x0030,
198 	QLINK_CMD_ADD_KEY		= 0x0040,
199 	QLINK_CMD_DEL_KEY		= 0x0041,
200 	QLINK_CMD_SET_DEFAULT_KEY	= 0x0042,
201 	QLINK_CMD_SET_DEFAULT_MGMT_KEY	= 0x0043,
202 	QLINK_CMD_CHANGE_STA		= 0x0051,
203 	QLINK_CMD_DEL_STA		= 0x0052,
204 	QLINK_CMD_SCAN			= 0x0053,
205 	QLINK_CMD_CHAN_STATS		= 0x0054,
206 	QLINK_CMD_CONNECT		= 0x0060,
207 	QLINK_CMD_DISCONNECT		= 0x0061,
208 };
209 
210 /**
211  * struct qlink_cmd - QLINK command message header
212  *
213  * Header used for QLINK messages of QLINK_MSG_TYPE_CMD type.
214  *
215  * @mhdr: Common QLINK message header.
216  * @cmd_id: command id, one of &enum qlink_cmd_type.
217  * @seq_num: sequence number of command message, used for matching with
218  *	response message.
219  * @macid: index of physical radio device the command is destined to or
220  *	QLINK_MACID_RSVD if not applicable.
221  * @vifid: index of virtual wireless interface on specified @macid the command
222  *	is destined to or QLINK_VIFID_RSVD if not applicable.
223  */
224 struct qlink_cmd {
225 	struct qlink_msg_header mhdr;
226 	__le16 cmd_id;
227 	__le16 seq_num;
228 	u8 rsvd[2];
229 	u8 macid;
230 	u8 vifid;
231 } __packed;
232 
233 /**
234  * struct qlink_cmd_manage_intf - interface management command
235  *
236  * Data for interface management commands QLINK_CMD_ADD_INTF, QLINK_CMD_DEL_INTF
237  * and QLINK_CMD_CHANGE_INTF.
238  *
239  * @intf_info: interface description.
240  */
241 struct qlink_cmd_manage_intf {
242 	struct qlink_cmd chdr;
243 	struct qlink_intf_info intf_info;
244 } __packed;
245 
246 enum qlink_mgmt_frame_type {
247 	QLINK_MGMT_FRAME_ASSOC_REQ	= 0x00,
248 	QLINK_MGMT_FRAME_ASSOC_RESP	= 0x01,
249 	QLINK_MGMT_FRAME_REASSOC_REQ	= 0x02,
250 	QLINK_MGMT_FRAME_REASSOC_RESP	= 0x03,
251 	QLINK_MGMT_FRAME_PROBE_REQ	= 0x04,
252 	QLINK_MGMT_FRAME_PROBE_RESP	= 0x05,
253 	QLINK_MGMT_FRAME_BEACON		= 0x06,
254 	QLINK_MGMT_FRAME_ATIM		= 0x07,
255 	QLINK_MGMT_FRAME_DISASSOC	= 0x08,
256 	QLINK_MGMT_FRAME_AUTH		= 0x09,
257 	QLINK_MGMT_FRAME_DEAUTH		= 0x0A,
258 	QLINK_MGMT_FRAME_ACTION		= 0x0B,
259 
260 	QLINK_MGMT_FRAME_TYPE_COUNT
261 };
262 
263 /**
264  * struct qlink_cmd_mgmt_frame_register - data for QLINK_CMD_REGISTER_MGMT
265  *
266  * @frame_type: MGMT frame type the registration request describes, one of
267  *	&enum qlink_mgmt_frame_type.
268  * @do_register: 0 - unregister, otherwise register for reception of specified
269  *	MGMT frame type.
270  */
271 struct qlink_cmd_mgmt_frame_register {
272 	struct qlink_cmd chdr;
273 	__le16 frame_type;
274 	u8 do_register;
275 } __packed;
276 
277 enum qlink_mgmt_frame_tx_flags {
278 	QLINK_MGMT_FRAME_TX_FLAG_NONE		= 0,
279 	QLINK_MGMT_FRAME_TX_FLAG_OFFCHAN	= BIT(0),
280 	QLINK_MGMT_FRAME_TX_FLAG_NO_CCK		= BIT(1),
281 	QLINK_MGMT_FRAME_TX_FLAG_ACK_NOWAIT	= BIT(2),
282 };
283 
284 /**
285  * struct qlink_cmd_mgmt_frame_tx - data for QLINK_CMD_SEND_MGMT_FRAME command
286  *
287  * @cookie: opaque request identifier.
288  * @freq: Frequency to use for frame transmission.
289  * @flags: Transmission flags, one of &enum qlink_mgmt_frame_tx_flags.
290  * @frame_data: frame to transmit.
291  */
292 struct qlink_cmd_mgmt_frame_tx {
293 	struct qlink_cmd chdr;
294 	__le32 cookie;
295 	__le16 freq;
296 	__le16 flags;
297 	u8 frame_data[0];
298 } __packed;
299 
300 /**
301  * struct qlink_cmd_get_sta_info - data for QLINK_CMD_GET_STA_INFO command
302  *
303  * @sta_addr: MAC address of the STA statistics is requested for.
304  */
305 struct qlink_cmd_get_sta_info {
306 	struct qlink_cmd chdr;
307 	u8 sta_addr[ETH_ALEN];
308 } __packed;
309 
310 /**
311  * struct qlink_cmd_add_key - data for QLINK_CMD_ADD_KEY command.
312  *
313  * @key_index: index of the key being installed.
314  * @pairwise: whether to use pairwise key.
315  * @addr: MAC address of a STA key is being installed to.
316  * @cipher: cipher suite.
317  * @vlanid: VLAN ID for AP_VLAN interface type
318  * @key_data: key data itself.
319  */
320 struct qlink_cmd_add_key {
321 	struct qlink_cmd chdr;
322 	u8 key_index;
323 	u8 pairwise;
324 	u8 addr[ETH_ALEN];
325 	__le32 cipher;
326 	__le16 vlanid;
327 	u8 key_data[0];
328 } __packed;
329 
330 /**
331  * struct qlink_cmd_del_key_req - data for QLINK_CMD_DEL_KEY command
332  *
333  * @key_index: index of the key being removed.
334  * @pairwise: whether to use pairwise key.
335  * @addr: MAC address of a STA for which a key is removed.
336  */
337 struct qlink_cmd_del_key {
338 	struct qlink_cmd chdr;
339 	u8 key_index;
340 	u8 pairwise;
341 	u8 addr[ETH_ALEN];
342 } __packed;
343 
344 /**
345  * struct qlink_cmd_set_def_key - data for QLINK_CMD_SET_DEFAULT_KEY command
346  *
347  * @key_index: index of the key to be set as default one.
348  * @unicast: key is unicast.
349  * @multicast: key is multicast.
350  */
351 struct qlink_cmd_set_def_key {
352 	struct qlink_cmd chdr;
353 	u8 key_index;
354 	u8 unicast;
355 	u8 multicast;
356 } __packed;
357 
358 /**
359  * struct qlink_cmd_set_def_mgmt_key - data for QLINK_CMD_SET_DEFAULT_MGMT_KEY
360  *
361  * @key_index: index of the key to be set as default MGMT key.
362  */
363 struct qlink_cmd_set_def_mgmt_key {
364 	struct qlink_cmd chdr;
365 	u8 key_index;
366 } __packed;
367 
368 /**
369  * struct qlink_cmd_change_sta - data for QLINK_CMD_CHANGE_STA command
370  *
371  * @sta_flags_mask: STA flags mask, bitmap of &enum qlink_sta_flags
372  * @sta_flags_set: STA flags values, bitmap of &enum qlink_sta_flags
373  * @if_type: Mode of interface operation, one of &enum qlink_iface_type
374  * @vlanid: VLAN ID to assign to specific STA
375  * @sta_addr: address of the STA for which parameters are set.
376  */
377 struct qlink_cmd_change_sta {
378 	struct qlink_cmd chdr;
379 	__le32 sta_flags_mask;
380 	__le32 sta_flags_set;
381 	__le16 if_type;
382 	__le16 vlanid;
383 	u8 sta_addr[ETH_ALEN];
384 } __packed;
385 
386 /**
387  * struct qlink_cmd_del_sta - data for QLINK_CMD_DEL_STA command.
388  *
389  * See &struct station_del_parameters
390  */
391 struct qlink_cmd_del_sta {
392 	struct qlink_cmd chdr;
393 	__le16 reason_code;
394 	u8 subtype;
395 	u8 sta_addr[ETH_ALEN];
396 } __packed;
397 
398 enum qlink_sta_connect_flags {
399 	QLINK_STA_CONNECT_DISABLE_HT	= BIT(0),
400 	QLINK_STA_CONNECT_DISABLE_VHT	= BIT(1),
401 	QLINK_STA_CONNECT_USE_RRM	= BIT(2),
402 };
403 
404 /**
405  * struct qlink_cmd_connect - data for QLINK_CMD_CONNECT command
406  *
407  * @bssid: BSSID of the BSS to connect to.
408  * @bssid_hint: recommended AP BSSID for initial connection to the BSS or
409  *	00:00:00:00:00:00 if not specified.
410  * @prev_bssid: previous BSSID, if specified (not 00:00:00:00:00:00) indicates
411  *	a request to reassociate.
412  * @bg_scan_period: period of background scan.
413  * @flags: one of &enum qlink_sta_connect_flags.
414  * @ht_capa: HT Capabilities overrides.
415  * @ht_capa_mask: The bits of ht_capa which are to be used.
416  * @vht_capa: VHT Capability overrides
417  * @vht_capa_mask: The bits of vht_capa which are to be used.
418  * @aen: authentication information.
419  * @mfp: whether to use management frame protection.
420  * @payload: variable portion of connection request.
421  */
422 struct qlink_cmd_connect {
423 	struct qlink_cmd chdr;
424 	u8 bssid[ETH_ALEN];
425 	u8 bssid_hint[ETH_ALEN];
426 	u8 prev_bssid[ETH_ALEN];
427 	__le16 bg_scan_period;
428 	__le32 flags;
429 	struct ieee80211_ht_cap ht_capa;
430 	struct ieee80211_ht_cap ht_capa_mask;
431 	struct ieee80211_vht_cap vht_capa;
432 	struct ieee80211_vht_cap vht_capa_mask;
433 	struct qlink_auth_encr aen;
434 	u8 mfp;
435 	u8 pbss;
436 	u8 rsvd[2];
437 	u8 payload[0];
438 } __packed;
439 
440 /**
441  * struct qlink_cmd_disconnect - data for QLINK_CMD_DISCONNECT command
442  *
443  * @reason: code of the reason of disconnect, see &enum ieee80211_reasoncode.
444  */
445 struct qlink_cmd_disconnect {
446 	struct qlink_cmd chdr;
447 	__le16 reason;
448 } __packed;
449 
450 /**
451  * struct qlink_cmd_updown - data for QLINK_CMD_UPDOWN_INTF command
452  *
453  * @if_up: bring specified interface DOWN (if_up==0) or UP (otherwise).
454  *	Interface is specified in common command header @chdr.
455  */
456 struct qlink_cmd_updown {
457 	struct qlink_cmd chdr;
458 	u8 if_up;
459 } __packed;
460 
461 /**
462  * enum qlink_band - a list of frequency bands
463  *
464  * @QLINK_BAND_2GHZ: 2.4GHz band
465  * @QLINK_BAND_5GHZ: 5GHz band
466  * @QLINK_BAND_60GHZ: 60GHz band
467  */
468 enum qlink_band {
469 	QLINK_BAND_2GHZ = BIT(0),
470 	QLINK_BAND_5GHZ = BIT(1),
471 	QLINK_BAND_60GHZ = BIT(2),
472 };
473 
474 /**
475  * struct qlink_cmd_band_info_get - data for QLINK_CMD_BAND_INFO_GET command
476  *
477  * @band: a PHY band for which information is queried, one of @enum qlink_band
478  */
479 struct qlink_cmd_band_info_get {
480 	struct qlink_cmd chdr;
481 	u8 band;
482 } __packed;
483 
484 /**
485  * struct qlink_cmd_get_chan_stats - data for QLINK_CMD_CHAN_STATS command
486  *
487  * @channel: channel number according to 802.11 17.3.8.3.2 and Annex J
488  */
489 struct qlink_cmd_get_chan_stats {
490 	struct qlink_cmd chdr;
491 	__le16 channel;
492 } __packed;
493 
494 /**
495  * enum qlink_reg_initiator - Indicates the initiator of a reg domain request
496  *
497  * See &enum nl80211_reg_initiator for more info.
498  */
499 enum qlink_reg_initiator {
500 	QLINK_REGDOM_SET_BY_CORE,
501 	QLINK_REGDOM_SET_BY_USER,
502 	QLINK_REGDOM_SET_BY_DRIVER,
503 	QLINK_REGDOM_SET_BY_COUNTRY_IE,
504 };
505 
506 /**
507  * enum qlink_user_reg_hint_type - type of user regulatory hint
508  *
509  * See &enum nl80211_user_reg_hint_type for more info.
510  */
511 enum qlink_user_reg_hint_type {
512 	QLINK_USER_REG_HINT_USER	= 0,
513 	QLINK_USER_REG_HINT_CELL_BASE	= 1,
514 	QLINK_USER_REG_HINT_INDOOR	= 2,
515 };
516 
517 /**
518  * struct qlink_cmd_reg_notify - data for QLINK_CMD_REG_NOTIFY command
519  *
520  * @alpha2: the ISO / IEC 3166 alpha2 country code.
521  * @initiator: which entity sent the request, one of &enum qlink_reg_initiator.
522  * @user_reg_hint_type: type of hint for QLINK_REGDOM_SET_BY_USER request, one
523  *	of &enum qlink_user_reg_hint_type.
524  */
525 struct qlink_cmd_reg_notify {
526 	struct qlink_cmd chdr;
527 	u8 alpha2[2];
528 	u8 initiator;
529 	u8 user_reg_hint_type;
530 } __packed;
531 
532 /**
533  * struct qlink_cmd_chan_switch - data for QLINK_CMD_CHAN_SWITCH command
534  *
535  * @channel: channel number according to 802.11 17.3.8.3.2 and Annex J
536  * @radar_required: whether radar detection is required on the new channel
537  * @block_tx: whether transmissions should be blocked while changing
538  * @beacon_count: number of beacons until switch
539  */
540 struct qlink_cmd_chan_switch {
541 	struct qlink_cmd chdr;
542 	__le16 channel;
543 	u8 radar_required;
544 	u8 block_tx;
545 	u8 beacon_count;
546 } __packed;
547 
548 /**
549  * enum qlink_hidden_ssid - values for %NL80211_ATTR_HIDDEN_SSID
550  *
551  * Refer to &enum nl80211_hidden_ssid
552  */
553 enum qlink_hidden_ssid {
554 	QLINK_HIDDEN_SSID_NOT_IN_USE,
555 	QLINK_HIDDEN_SSID_ZERO_LEN,
556 	QLINK_HIDDEN_SSID_ZERO_CONTENTS
557 };
558 
559 /**
560  * struct qlink_cmd_start_ap - data for QLINK_CMD_START_AP command
561  *
562  * @beacon_interval: beacon interval
563  * @inactivity_timeout: station's inactivity period in seconds
564  * @dtim_period: DTIM period
565  * @hidden_ssid: whether to hide the SSID, one of &enum qlink_hidden_ssid
566  * @smps_mode: SMPS mode
567  * @ht_required: stations must support HT
568  * @vht_required: stations must support VHT
569  * @aen: encryption info
570  * @info: variable configurations
571  */
572 struct qlink_cmd_start_ap {
573 	struct qlink_cmd chdr;
574 	__le16 beacon_interval;
575 	__le16 inactivity_timeout;
576 	u8 dtim_period;
577 	u8 hidden_ssid;
578 	u8 smps_mode;
579 	u8 p2p_ctwindow;
580 	u8 p2p_opp_ps;
581 	u8 pbss;
582 	u8 ht_required;
583 	u8 vht_required;
584 	struct qlink_auth_encr aen;
585 	u8 info[0];
586 } __packed;
587 
588 /* QLINK Command Responses messages related definitions
589  */
590 
591 enum qlink_cmd_result {
592 	QLINK_CMD_RESULT_OK = 0,
593 	QLINK_CMD_RESULT_INVALID,
594 	QLINK_CMD_RESULT_ENOTSUPP,
595 	QLINK_CMD_RESULT_ENOTFOUND,
596 	QLINK_CMD_RESULT_EALREADY,
597 };
598 
599 /**
600  * struct qlink_resp - QLINK command response message header
601  *
602  * Header used for QLINK messages of QLINK_MSG_TYPE_CMDRSP type.
603  *
604  * @mhdr: see &struct qlink_msg_header.
605  * @cmd_id: command ID the response corresponds to, one of &enum qlink_cmd_type.
606  * @seq_num: sequence number of command message, used for matching with
607  *	response message.
608  * @result: result of the command execution, one of &enum qlink_cmd_result.
609  * @macid: index of physical radio device the response is sent from or
610  *	QLINK_MACID_RSVD if not applicable.
611  * @vifid: index of virtual wireless interface on specified @macid the response
612  *	is sent from or QLINK_VIFID_RSVD if not applicable.
613  */
614 struct qlink_resp {
615 	struct qlink_msg_header mhdr;
616 	__le16 cmd_id;
617 	__le16 seq_num;
618 	__le16 result;
619 	u8 macid;
620 	u8 vifid;
621 } __packed;
622 
623 /**
624  * struct qlink_resp_get_mac_info - response for QLINK_CMD_MAC_INFO command
625  *
626  * Data describing specific physical device providing wireless MAC
627  * functionality.
628  *
629  * @dev_mac: MAC address of physical WMAC device (used for first BSS on
630  *	specified WMAC).
631  * @num_tx_chain: Number of transmit chains used by WMAC.
632  * @num_rx_chain: Number of receive chains used by WMAC.
633  * @vht_cap_mod_mask: mask specifying which VHT capabilities can be altered.
634  * @ht_cap_mod_mask: mask specifying which HT capabilities can be altered.
635  * @bands_cap: wireless bands WMAC can operate in, bitmap of &enum qlink_band.
636  * @max_ap_assoc_sta: Maximum number of associations supported by WMAC.
637  * @radar_detect_widths: bitmask of channels BW for which WMAC can detect radar.
638  * @var_info: variable-length WMAC info data.
639  */
640 struct qlink_resp_get_mac_info {
641 	struct qlink_resp rhdr;
642 	u8 dev_mac[ETH_ALEN];
643 	u8 num_tx_chain;
644 	u8 num_rx_chain;
645 	struct ieee80211_vht_cap vht_cap_mod_mask;
646 	struct ieee80211_ht_cap ht_cap_mod_mask;
647 	__le16 max_ap_assoc_sta;
648 	__le16 radar_detect_widths;
649 	u8 bands_cap;
650 	u8 rsvd[1];
651 	u8 var_info[0];
652 } __packed;
653 
654 /**
655  * enum qlink_dfs_regions - regulatory DFS regions
656  *
657  * Corresponds to &enum nl80211_dfs_regions.
658  */
659 enum qlink_dfs_regions {
660 	QLINK_DFS_UNSET	= 0,
661 	QLINK_DFS_FCC	= 1,
662 	QLINK_DFS_ETSI	= 2,
663 	QLINK_DFS_JP	= 3,
664 };
665 
666 /**
667  * struct qlink_resp_get_hw_info - response for QLINK_CMD_GET_HW_INFO command
668  *
669  * Description of wireless hardware capabilities and features.
670  *
671  * @fw_ver: wireless hardware firmware version.
672  * @hw_capab: Bitmap of capabilities supported by firmware.
673  * @ql_proto_ver: Version of QLINK protocol used by firmware.
674  * @num_mac: Number of separate physical radio devices provided by hardware.
675  * @mac_bitmap: Bitmap of MAC IDs that are active and can be used in firmware.
676  * @total_tx_chains: total number of transmit chains used by device.
677  * @total_rx_chains: total number of receive chains.
678  * @alpha2: country code ID firmware is configured to.
679  * @n_reg_rules: number of regulatory rules TLVs in variable portion of the
680  *	message.
681  * @dfs_region: regulatory DFS region, one of @enum qlink_dfs_region.
682  * @info: variable-length HW info, can contain QTN_TLV_ID_REG_RULE.
683  */
684 struct qlink_resp_get_hw_info {
685 	struct qlink_resp rhdr;
686 	__le32 fw_ver;
687 	__le32 hw_capab;
688 	__le16 ql_proto_ver;
689 	u8 num_mac;
690 	u8 mac_bitmap;
691 	u8 total_tx_chain;
692 	u8 total_rx_chain;
693 	u8 alpha2[2];
694 	u8 n_reg_rules;
695 	u8 dfs_region;
696 	u8 info[0];
697 } __packed;
698 
699 /**
700  * struct qlink_resp_manage_intf - response for interface management commands
701  *
702  * Response data for QLINK_CMD_ADD_INTF and QLINK_CMD_CHANGE_INTF commands.
703  *
704  * @rhdr: Common Command Response message header.
705  * @intf_info: interface description.
706  */
707 struct qlink_resp_manage_intf {
708 	struct qlink_resp rhdr;
709 	struct qlink_intf_info intf_info;
710 } __packed;
711 
712 /**
713  * struct qlink_resp_get_sta_info - response for QLINK_CMD_GET_STA_INFO command
714  *
715  * Response data containing statistics for specified STA.
716  *
717  * @sta_addr: MAC address of STA the response carries statistic for.
718  * @info: statistics for specified STA.
719  */
720 struct qlink_resp_get_sta_info {
721 	struct qlink_resp rhdr;
722 	u8 sta_addr[ETH_ALEN];
723 	u8 info[0];
724 } __packed;
725 
726 /**
727  * struct qlink_resp_band_info_get - response for QLINK_CMD_BAND_INFO_GET cmd
728  *
729  * @band: frequency band that the response describes, one of @enum qlink_band.
730  * @num_chans: total number of channels info TLVs contained in reply.
731  * @num_bitrates: total number of bitrate TLVs contained in reply.
732  * @info: variable-length info portion.
733  */
734 struct qlink_resp_band_info_get {
735 	struct qlink_resp rhdr;
736 	u8 band;
737 	u8 num_chans;
738 	u8 num_bitrates;
739 	u8 rsvd[1];
740 	u8 info[0];
741 } __packed;
742 
743 /**
744  * struct qlink_resp_phy_params - response for QLINK_CMD_PHY_PARAMS_GET command
745  *
746  * @info: variable-length array of PHY params.
747  */
748 struct qlink_resp_phy_params {
749 	struct qlink_resp rhdr;
750 	u8 info[0];
751 } __packed;
752 
753 /**
754  * struct qlink_resp_get_chan_stats - response for QLINK_CMD_CHAN_STATS cmd
755  *
756  * @info: variable-length channel info.
757  */
758 struct qlink_resp_get_chan_stats {
759 	struct qlink_cmd rhdr;
760 	u8 info[0];
761 } __packed;
762 
763 /**
764  * struct qlink_resp_channel_get - response for QLINK_CMD_CHAN_GET command
765  *
766  * @chan: definition of current operating channel.
767  */
768 struct qlink_resp_channel_get {
769 	struct qlink_resp rhdr;
770 	struct qlink_chandef chan;
771 } __packed;
772 
773 /* QLINK Events messages related definitions
774  */
775 
776 enum qlink_event_type {
777 	QLINK_EVENT_STA_ASSOCIATED	= 0x0021,
778 	QLINK_EVENT_STA_DEAUTH		= 0x0022,
779 	QLINK_EVENT_MGMT_RECEIVED	= 0x0023,
780 	QLINK_EVENT_SCAN_RESULTS	= 0x0024,
781 	QLINK_EVENT_SCAN_COMPLETE	= 0x0025,
782 	QLINK_EVENT_BSS_JOIN		= 0x0026,
783 	QLINK_EVENT_BSS_LEAVE		= 0x0027,
784 	QLINK_EVENT_FREQ_CHANGE		= 0x0028,
785 };
786 
787 /**
788  * struct qlink_event - QLINK event message header
789  *
790  * Header used for QLINK messages of QLINK_MSG_TYPE_EVENT type.
791  *
792  * @mhdr: Common QLINK message header.
793  * @event_id: Specifies specific event ID, one of &enum qlink_event_type.
794  * @macid: index of physical radio device the event was generated on or
795  *	QLINK_MACID_RSVD if not applicable.
796  * @vifid: index of virtual wireless interface on specified @macid the event
797  *	was generated on or QLINK_VIFID_RSVD if not applicable.
798  */
799 struct qlink_event {
800 	struct qlink_msg_header mhdr;
801 	__le16 event_id;
802 	u8 macid;
803 	u8 vifid;
804 } __packed;
805 
806 /**
807  * struct qlink_event_sta_assoc - data for QLINK_EVENT_STA_ASSOCIATED event
808  *
809  * @sta_addr: Address of a STA for which new association event was generated
810  * @frame_control: control bits from 802.11 ASSOC_REQUEST header.
811  * @payload: IEs from association request.
812  */
813 struct qlink_event_sta_assoc {
814 	struct qlink_event ehdr;
815 	u8 sta_addr[ETH_ALEN];
816 	__le16 frame_control;
817 	u8 ies[0];
818 } __packed;
819 
820 /**
821  * struct qlink_event_sta_deauth - data for QLINK_EVENT_STA_DEAUTH event
822  *
823  * @sta_addr: Address of a deauthenticated STA.
824  * @reason: reason for deauthentication.
825  */
826 struct qlink_event_sta_deauth {
827 	struct qlink_event ehdr;
828 	u8 sta_addr[ETH_ALEN];
829 	__le16 reason;
830 } __packed;
831 
832 /**
833  * struct qlink_event_bss_join - data for QLINK_EVENT_BSS_JOIN event
834  *
835  * @bssid: BSSID of a BSS which interface tried to joined.
836  * @status: status of joining attempt, see &enum ieee80211_statuscode.
837  */
838 struct qlink_event_bss_join {
839 	struct qlink_event ehdr;
840 	u8 bssid[ETH_ALEN];
841 	__le16 status;
842 } __packed;
843 
844 /**
845  * struct qlink_event_bss_leave - data for QLINK_EVENT_BSS_LEAVE event
846  *
847  * @reason: reason of disconnecting from BSS.
848  */
849 struct qlink_event_bss_leave {
850 	struct qlink_event ehdr;
851 	__le16 reason;
852 } __packed;
853 
854 /**
855  * struct qlink_event_freq_change - data for QLINK_EVENT_FREQ_CHANGE event
856  *
857  * @chan: new operating channel definition
858  */
859 struct qlink_event_freq_change {
860 	struct qlink_event ehdr;
861 	struct qlink_chandef chan;
862 } __packed;
863 
864 enum qlink_rxmgmt_flags {
865 	QLINK_RXMGMT_FLAG_ANSWERED = 1 << 0,
866 };
867 
868 /**
869  * struct qlink_event_rxmgmt - data for QLINK_EVENT_MGMT_RECEIVED event
870  *
871  * @freq: Frequency on which the frame was received in MHz.
872  * @sig_dbm: signal strength in dBm.
873  * @flags: bitmap of &enum qlink_rxmgmt_flags.
874  * @frame_data: data of Rx'd frame itself.
875  */
876 struct qlink_event_rxmgmt {
877 	struct qlink_event ehdr;
878 	__le32 freq;
879 	__le32 sig_dbm;
880 	__le32 flags;
881 	u8 frame_data[0];
882 } __packed;
883 
884 /**
885  * struct qlink_event_scan_result - data for QLINK_EVENT_SCAN_RESULTS event
886  *
887  * @tsf: TSF timestamp indicating when scan results were generated.
888  * @freq: Center frequency of the channel where BSS for which the scan result
889  *	event was generated was discovered.
890  * @capab: capabilities field.
891  * @bintval: beacon interval announced by discovered BSS.
892  * @signal: signal strength.
893  * @bssid: BSSID announced by discovered BSS.
894  * @ssid_len: length of SSID announced by BSS.
895  * @ssid: SSID announced by discovered BSS.
896  * @payload: IEs that are announced by discovered BSS in its MGMt frames.
897  */
898 struct qlink_event_scan_result {
899 	struct qlink_event ehdr;
900 	__le64 tsf;
901 	__le16 freq;
902 	__le16 capab;
903 	__le16 bintval;
904 	s8 signal;
905 	u8 ssid_len;
906 	u8 ssid[IEEE80211_MAX_SSID_LEN];
907 	u8 bssid[ETH_ALEN];
908 	u8 rsvd[2];
909 	u8 payload[0];
910 } __packed;
911 
912 /**
913  * enum qlink_scan_complete_flags - indicates result of scan request.
914  *
915  * @QLINK_SCAN_NONE: Scan request was processed.
916  * @QLINK_SCAN_ABORTED: Scan was aborted.
917  */
918 enum qlink_scan_complete_flags {
919 	QLINK_SCAN_NONE		= 0,
920 	QLINK_SCAN_ABORTED	= BIT(0),
921 };
922 
923 /**
924  * struct qlink_event_scan_complete - data for QLINK_EVENT_SCAN_COMPLETE event
925  *
926  * @flags: flags indicating the status of pending scan request,
927  *	see &enum qlink_scan_complete_flags.
928  */
929 struct qlink_event_scan_complete {
930 	struct qlink_event ehdr;
931 	__le32 flags;
932 } __packed;
933 
934 /* QLINK TLVs (Type-Length Values) definitions
935  */
936 
937 enum qlink_tlv_id {
938 	QTN_TLV_ID_FRAG_THRESH		= 0x0201,
939 	QTN_TLV_ID_RTS_THRESH		= 0x0202,
940 	QTN_TLV_ID_SRETRY_LIMIT		= 0x0203,
941 	QTN_TLV_ID_LRETRY_LIMIT		= 0x0204,
942 	QTN_TLV_ID_REG_RULE		= 0x0207,
943 	QTN_TLV_ID_CHANNEL		= 0x020F,
944 	QTN_TLV_ID_CHANDEF		= 0x0210,
945 	QTN_TLV_ID_COVERAGE_CLASS	= 0x0213,
946 	QTN_TLV_ID_IFACE_LIMIT		= 0x0214,
947 	QTN_TLV_ID_NUM_IFACE_COMB	= 0x0215,
948 	QTN_TLV_ID_CHANNEL_STATS	= 0x0216,
949 	QTN_TLV_ID_STA_BASIC_COUNTERS	= 0x0300,
950 	QTN_TLV_ID_STA_GENERIC_INFO	= 0x0301,
951 	QTN_TLV_ID_KEY			= 0x0302,
952 	QTN_TLV_ID_SEQ			= 0x0303,
953 	QTN_TLV_ID_IE_SET		= 0x0305,
954 };
955 
956 struct qlink_tlv_hdr {
957 	__le16 type;
958 	__le16 len;
959 	u8 val[0];
960 } __packed;
961 
962 struct qlink_iface_limit {
963 	__le16 max_num;
964 	__le16 type;
965 } __packed;
966 
967 struct qlink_iface_comb_num {
968 	__le16 iface_comb_num;
969 } __packed;
970 
971 struct qlink_sta_stat_basic_counters {
972 	__le64 rx_bytes;
973 	__le64 tx_bytes;
974 	__le64 rx_beacons;
975 	__le32 rx_packets;
976 	__le32 tx_packets;
977 	__le32 rx_dropped;
978 	__le32 tx_failed;
979 } __packed;
980 
981 enum qlink_sta_info_rate_flags {
982 	QLINK_STA_INFO_RATE_FLAG_INVALID	= 0,
983 	QLINK_STA_INFO_RATE_FLAG_HT_MCS		= BIT(0),
984 	QLINK_STA_INFO_RATE_FLAG_VHT_MCS	= BIT(1),
985 	QLINK_STA_INFO_RATE_FLAG_SHORT_GI	= BIT(2),
986 	QLINK_STA_INFO_RATE_FLAG_60G		= BIT(3),
987 };
988 
989 enum qlink_sta_info_rate_bw {
990 	QLINK_STA_INFO_RATE_BW_5		= 0,
991 	QLINK_STA_INFO_RATE_BW_10		= 1,
992 	QLINK_STA_INFO_RATE_BW_20		= 2,
993 	QLINK_STA_INFO_RATE_BW_40		= 3,
994 	QLINK_STA_INFO_RATE_BW_80		= 4,
995 	QLINK_STA_INFO_RATE_BW_160		= 5,
996 };
997 
998 /**
999  * struct qlink_sta_info_rate - STA rate statistics
1000  *
1001  * @rate: data rate in Mbps.
1002  * @flags: bitmap of &enum qlink_sta_flags.
1003  * @mcs: 802.11-defined MCS index.
1004  * nss: Number of Spatial Streams.
1005  * @bw: bandwidth, one of &enum qlink_sta_info_rate_bw.
1006  */
1007 struct qlink_sta_info_rate {
1008 	__le16 rate;
1009 	u8 flags;
1010 	u8 mcs;
1011 	u8 nss;
1012 	u8 bw;
1013 } __packed;
1014 
1015 struct qlink_sta_info_state {
1016 	__le32 mask;
1017 	__le32 value;
1018 } __packed;
1019 
1020 #define QLINK_RSSI_OFFSET	120
1021 
1022 struct qlink_sta_info_generic {
1023 	struct qlink_sta_info_state state;
1024 	__le32 connected_time;
1025 	__le32 inactive_time;
1026 	struct qlink_sta_info_rate rx_rate;
1027 	struct qlink_sta_info_rate tx_rate;
1028 	u8 rssi;
1029 	u8 rssi_avg;
1030 } __packed;
1031 
1032 struct qlink_tlv_frag_rts_thr {
1033 	struct qlink_tlv_hdr hdr;
1034 	__le16 thr;
1035 } __packed;
1036 
1037 struct qlink_tlv_rlimit {
1038 	struct qlink_tlv_hdr hdr;
1039 	u8 rlimit;
1040 } __packed;
1041 
1042 struct qlink_tlv_cclass {
1043 	struct qlink_tlv_hdr hdr;
1044 	u8 cclass;
1045 } __packed;
1046 
1047 /**
1048  * enum qlink_reg_rule_flags - regulatory rule flags
1049  *
1050  * See description of &enum nl80211_reg_rule_flags
1051  */
1052 enum qlink_reg_rule_flags {
1053 	QLINK_RRF_NO_OFDM	= BIT(0),
1054 	QLINK_RRF_NO_CCK	= BIT(1),
1055 	QLINK_RRF_NO_INDOOR	= BIT(2),
1056 	QLINK_RRF_NO_OUTDOOR	= BIT(3),
1057 	QLINK_RRF_DFS		= BIT(4),
1058 	QLINK_RRF_PTP_ONLY	= BIT(5),
1059 	QLINK_RRF_PTMP_ONLY	= BIT(6),
1060 	QLINK_RRF_NO_IR		= BIT(7),
1061 	QLINK_RRF_AUTO_BW	= BIT(8),
1062 	QLINK_RRF_IR_CONCURRENT	= BIT(9),
1063 	QLINK_RRF_NO_HT40MINUS	= BIT(10),
1064 	QLINK_RRF_NO_HT40PLUS	= BIT(11),
1065 	QLINK_RRF_NO_80MHZ	= BIT(12),
1066 	QLINK_RRF_NO_160MHZ	= BIT(13),
1067 };
1068 
1069 /**
1070  * struct qlink_tlv_reg_rule - data for QTN_TLV_ID_REG_RULE TLV
1071  *
1072  * Regulatory rule description.
1073  *
1074  * @start_freq_khz: start frequency of the range the rule is attributed to.
1075  * @end_freq_khz: end frequency of the range the rule is attributed to.
1076  * @max_bandwidth_khz: max bandwidth that channels in specified range can be
1077  *	configured to.
1078  * @max_antenna_gain: max antenna gain that can be used in the specified
1079  *	frequency range, dBi.
1080  * @max_eirp: maximum EIRP.
1081  * @flags: regulatory rule flags in &enum qlink_reg_rule_flags.
1082  * @dfs_cac_ms: DFS CAC period.
1083  */
1084 struct qlink_tlv_reg_rule {
1085 	struct qlink_tlv_hdr hdr;
1086 	__le32 start_freq_khz;
1087 	__le32 end_freq_khz;
1088 	__le32 max_bandwidth_khz;
1089 	__le32 max_antenna_gain;
1090 	__le32 max_eirp;
1091 	__le32 flags;
1092 	__le32 dfs_cac_ms;
1093 } __packed;
1094 
1095 enum qlink_channel_flags {
1096 	QLINK_CHAN_DISABLED		= BIT(0),
1097 	QLINK_CHAN_NO_IR		= BIT(1),
1098 	QLINK_CHAN_RADAR		= BIT(3),
1099 	QLINK_CHAN_NO_HT40PLUS		= BIT(4),
1100 	QLINK_CHAN_NO_HT40MINUS		= BIT(5),
1101 	QLINK_CHAN_NO_OFDM		= BIT(6),
1102 	QLINK_CHAN_NO_80MHZ		= BIT(7),
1103 	QLINK_CHAN_NO_160MHZ		= BIT(8),
1104 	QLINK_CHAN_INDOOR_ONLY		= BIT(9),
1105 	QLINK_CHAN_IR_CONCURRENT	= BIT(10),
1106 	QLINK_CHAN_NO_20MHZ		= BIT(11),
1107 	QLINK_CHAN_NO_10MHZ		= BIT(12),
1108 };
1109 
1110 enum qlink_dfs_state {
1111 	QLINK_DFS_USABLE,
1112 	QLINK_DFS_UNAVAILABLE,
1113 	QLINK_DFS_AVAILABLE,
1114 };
1115 
1116 struct qlink_tlv_channel {
1117 	struct qlink_tlv_hdr hdr;
1118 	__le16 hw_value;
1119 	__le16 center_freq;
1120 	__le32 flags;
1121 	u8 band;
1122 	u8 max_antenna_gain;
1123 	u8 max_power;
1124 	u8 max_reg_power;
1125 	__le32 dfs_cac_ms;
1126 	u8 dfs_state;
1127 	u8 beacon_found;
1128 	u8 rsvd[2];
1129 } __packed;
1130 
1131 /**
1132  * struct qlink_tlv_chandef - data for QTN_TLV_ID_CHANDEF TLV
1133  *
1134  * Channel definition.
1135  *
1136  * @chan: channel definition data.
1137  */
1138 struct qlink_tlv_chandef {
1139 	struct qlink_tlv_hdr hdr;
1140 	struct qlink_chandef chan;
1141 } __packed;
1142 
1143 enum qlink_ie_set_type {
1144 	QLINK_IE_SET_UNKNOWN,
1145 	QLINK_IE_SET_ASSOC_REQ,
1146 	QLINK_IE_SET_ASSOC_RESP,
1147 	QLINK_IE_SET_PROBE_REQ,
1148 	QLINK_IE_SET_SCAN,
1149 	QLINK_IE_SET_BEACON_HEAD,
1150 	QLINK_IE_SET_BEACON_TAIL,
1151 	QLINK_IE_SET_BEACON_IES,
1152 	QLINK_IE_SET_PROBE_RESP,
1153 	QLINK_IE_SET_PROBE_RESP_IES,
1154 };
1155 
1156 /**
1157  * struct qlink_tlv_ie_set - data for QTN_TLV_ID_IE_SET
1158  *
1159  * @type: type of MGMT frame IEs belong to, one of &enum qlink_ie_set_type.
1160  * @flags: for future use.
1161  * @ie_data: IEs data.
1162  */
1163 struct qlink_tlv_ie_set {
1164 	struct qlink_tlv_hdr hdr;
1165 	u8 type;
1166 	u8 flags;
1167 	u8 ie_data[0];
1168 } __packed;
1169 
1170 struct qlink_chan_stats {
1171 	__le32 chan_num;
1172 	__le32 cca_tx;
1173 	__le32 cca_rx;
1174 	__le32 cca_busy;
1175 	__le32 cca_try;
1176 	s8 chan_noise;
1177 } __packed;
1178 
1179 #endif /* _QTN_QLINK_H_ */
1180