xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/phl_scan.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 - 2020 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef __PHL_SCAN_H__
16 #define __PHL_SCAN_H__
17 
18 /* Header file for application to invoke scan service */
19 #define PHL_SSID_LEN 32
20 struct rtw_phl_ssid {
21 	u32 ssid_len;
22 	u8 ssid[PHL_SSID_LEN];
23 };
24 
25 enum phl_scan_mode {
26 	NULL_MODE,  /* End of Scanning */
27 	NORMAL_SCAN_MODE, /* OFF CHANNEL : non-operation channel*/
28 	BACKOP_MODE,
29 	P2P_SCAN_MODE,
30 	P2P_LISTEN_MODE,
31 	MAX_MODE,
32 };
33 
34 /* Scan type including active and passive scan. */
35 enum rtw_phl_scan_type {
36 	RTW_PHL_SCAN_PASSIVE,
37 	RTW_PHL_SCAN_ACTIVE,
38 	RTW_PHL_SCAN_MIX,
39 };
40 
41 enum phl_ext_act_scan_state {
42 	EXT_ACT_SCAN_DISABLE,
43 	EXT_ACT_SCAN_ENABLE,
44 	EXT_ACT_SCAN_TRIGGER,
45 	EXT_ACT_SCAN_DONE,
46 };
47 
48 struct phl_scan_channel {
49 	_os_list list;
50 
51 	enum band_type band;
52 	u16 channel; /* channel number */
53 	u16 duration; /* 0: use default, otherwise: channel scan time */
54 	enum channel_width bw; /* 0: use default 20Mhz */
55 	enum chan_offset offset;
56 	enum rtw_phl_scan_type type; /* active scan: 1, passive scan: 0 */
57 	u8 scan_mode; /* according to phl_scan_mode */
58 	u8 ext_act_scan; /* according to phl_ext_act_scan_state */
59 };
60 
61 enum scan_result {
62 	SCAN_REQ_ABORT, /* abort a non-started(queued) scan */
63 	SCAN_REQ_CANCEL, /* cancel a started scan */
64 	SCAN_REQ_COMPLETE /* scan complete */
65 };
66 
67 enum scan_bkop_mode {
68 	SCAN_BKOP_NONE,
69 	SCAN_BKOP_CNT,
70 	SCAN_BKOP_TIMER
71 };
72 
73 #define SCAN_SSID_AMOUNT 9 /* for WEXT_CSCAN_AMOUNT 9 */
74 #define SCAN_CH_AMOUNT (14+37)
75 struct rtw_phl_scan_param {
76 	u32 max_scan_time;
77 	#ifdef CONFIG_PHL_CMD_SCAN_BKOP_TIME
78 	u32 max_listen_time;
79 	#endif
80 	struct rtw_phl_ssid ssid[SCAN_SSID_AMOUNT];
81 	u8 ssid_num;
82 	u8 repeat; /* 255 means scan forever until cancel */
83 
84 	u8 ch_num;
85 	struct phl_scan_channel *ch;
86 	u32 ch_sz;
87 	int ch_idx; /* current scaned cahnnel index, init vaule = (-1) */
88 
89 	/* back op param */
90 	enum scan_bkop_mode back_op_mode;
91 	u8 back_op_ch_cnt; /* every back_op_ch_cnt go back to op ch */
92 
93 	/* every 'back_op_off_ch_dur_ms' go back to op ch
94 	 * back_op_off_ch_dur_ms have to large than ch->duration
95 	 * 0 : not specify
96 	*/
97 	u16 back_op_ch_dur_ms; /* op ch stay time; 0 : use default value */
98 	u16 back_op_off_ch_dur_ms;
99 	u16 back_op_off_ch_ext_dur_ms; /* extend when off_ch_tx (MGNT_TX) */
100 
101 	struct rtw_phl_scan_ops *ops;
102 	void *priv; /* ops private */
103 
104 	struct rtw_wifi_role_t *wifi_role;
105 	/* scan fsm internal use
106 	 * represent current scanning channel
107 	 */
108 	struct phl_scan_channel *scan_ch;
109 
110 #ifdef CONFIG_PHL_CMD_SCAN
111 	struct phl_queue chlist;
112 	struct phl_scan_channel back_op_ch[MAX_WIFI_ROLE_NUMBER];
113 
114 	_os_timer scan_timer; /* handle in phl_cmd_scan */
115 	u8 fltr_mode; /* backup filter mode before off channel */
116 	u8 state;
117 #endif
118 	/* create for computing scan time */
119 	u32 enqueue_time;
120 	u32 start_time;
121 	u32 end_time;
122 	u32 total_scan_time;
123 
124 	u32 token; /* unique id, generated by rtw_phl_scan_request() */
125 	const char *name;
126 	enum scan_result result;
127 	u32 ext_act_scan_period;
128 };
129 
130 enum PRECEDE {
131 	TO_TAIL, /* normal case */
132 	TO_HEAD, /* insert to head */
133 	IMMEDIATE /* cancel previous scan and run immediately */
134 };
135 
136 struct rtw_phl_scan_ops {
137 	int (*scan_issue_pbreq)(void *priv, struct rtw_phl_scan_param *param);
138 	u8 (*scan_issue_null_data)(void *priv, u8 ridx, bool ps);
139 	int (*scan_start)(void *priv, struct rtw_phl_scan_param *param);
140 	int (*scan_ch_ready)(void *priv, struct rtw_phl_scan_param *param);
141 	int (*scan_off_ch_tx)(void *priv,
142 		struct rtw_phl_scan_param *param, void *data);
143 	int (*scan_complete)(void *priv, struct rtw_phl_scan_param *param);
144 };
145 
146 enum rtw_phl_status rtw_phl_scan_cancel(void *phl);
147 enum rtw_phl_status rtw_phl_scan_request(void *phl,
148 	struct rtw_phl_scan_param *pbuf, enum PRECEDE order);
149 enum rtw_phl_status rtw_phl_scan_del_request(void *phl,
150 	u32 token);
151 enum rtw_phl_status rtw_phl_scan_pause(void *phl);
152 enum rtw_phl_status rtw_phl_scan_resume(void *phl);
153 enum rtw_phl_status rtw_phl_scan_force_active_scan(void *phl,
154 	u16 channel, u16 duration);
155 int rtw_phl_scan_inprogress_req_num(void *phl);
156 enum rtw_phl_status rtw_phl_scan_running_req(void *phl,
157 	struct rtw_phl_scan_param **param);
158 bool rtw_phl_scan_scanning_req(void *phl, u32 token, u32 *token_running);
159 enum rtw_phl_status rtw_phl_scan_off_ch_tx(void *phl, void *data, int len);
160 
161 /* CMD_DISP SCAN*/
162 enum rtw_phl_status rtw_phl_cmd_scan_request(void *phl,
163 	struct rtw_phl_scan_param *param, enum PRECEDE order);
164 enum rtw_phl_status rtw_phl_cmd_scan_cancel(void *phl,
165 				struct rtw_phl_scan_param *param);
166 int rtw_phl_cmd_scan_inprogress(void *phl, u8 band_idx);
167 
168 #endif /* __PHL_SCAN_H__ */
169 
170