xref: /wlan-dirver/qca-wifi-host-cmn/umac/wifi_pos/inc/wifi_pos_api.h (revision 45a38684b07295822dc8eba39e293408f203eec8)
1 /*
2  * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: wifi_pos_api.h
21  * This file declares public APIs of wifi positioning component
22  */
23 #ifndef _WIFI_POS_API_H_
24 #define _WIFI_POS_API_H_
25 
26 /* Include files */
27 #include "wifi_pos_utils_pub.h"
28 #include "../src/wifi_pos_utils_i.h"
29 
30 /* forward reference */
31 struct wlan_objmgr_psoc;
32 struct wifi_pos_driver_caps;
33 
34 /**
35  * enum RTT_FIELD_ID - identifies which field is being specified
36  * @META_DATA_SUB_TYPE: oem data req sub type
37  * @META_DATA_CHANNEL_MHZ: channel mhz info
38  * @META_DATA_PDEV: pdev info
39  */
40 enum RTT_FIELD_ID {
41 	META_DATA_SUB_TYPE,
42 	META_DATA_CHANNEL_MHZ,
43 	META_DATA_PDEV,
44 };
45 
46 /**
47  * struct wifi_pos_field - wifi positioning field element
48  * @id: RTT field id
49  * @offset: data offset in field info buffer
50  * @length: length of related data in field info buffer
51  */
52 struct wifi_pos_field {
53 	uint32_t id;
54 	uint32_t offset;
55 	uint32_t length;
56 };
57 
58 /**
59  * struct wifi_pos_field_info - wifi positioning field info buffer
60  * @count: number of @wifi_pos_field elements
61  * @fields: buffer to hold @wifi_pos_field elements
62  */
63 struct wifi_pos_field_info {
64 	uint32_t count;
65 	struct wifi_pos_field fields[1];
66 };
67 
68 /* Length of interface name */
69 #define INTERFACE_LEN 16
70 /**
71  * struct wifi_pos_interface - wifi positioning interface structure
72  * @length: interface length
73  * @dev_name: device name
74  */
75 struct wifi_pos_interface {
76 	uint8_t length;
77 	char dev_name[INTERFACE_LEN];
78 };
79 
80 #ifdef WIFI_POS_CONVERGED
81 /**
82  * enum oem_err_msg - err msg returned to user space
83  * @OEM_ERR_NULL_CONTEXT: NULL context
84  * @OEM_ERR_APP_NOT_REGISTERED: OEM App is not registered
85  * @OEM_ERR_INVALID_SIGNATURE: Invalid signature
86  * @OEM_ERR_NULL_MESSAGE_HEADER: Invalid message header
87  * @OEM_ERR_INVALID_MESSAGE_TYPE: Invalid message type
88  * @OEM_ERR_INVALID_MESSAGE_LENGTH: Invalid length in message body
89  */
90 enum oem_err_msg {
91 	OEM_ERR_NULL_CONTEXT = 1,
92 	OEM_ERR_APP_NOT_REGISTERED,
93 	OEM_ERR_INVALID_SIGNATURE,
94 	OEM_ERR_NULL_MESSAGE_HEADER,
95 	OEM_ERR_INVALID_MESSAGE_TYPE,
96 	OEM_ERR_INVALID_MESSAGE_LENGTH
97 };
98 
99 /* this struct is needed since MLME is not converged yet */
100 struct wifi_pos_ch_info {
101 	uint8_t chan_id;
102 	uint32_t mhz;
103 	uint32_t band_center_freq1;
104 	uint32_t band_center_freq2;
105 	uint32_t info;
106 	uint32_t reg_info_1;
107 	uint32_t reg_info_2;
108 	uint8_t nss;
109 	uint32_t rate_flags;
110 	uint8_t sec_ch_offset;
111 	uint32_t ch_width;
112 };
113 
114 /**
115  * typedef wifi_pos_ch_info_rsp - Channel information
116  * @chan_id: channel id
117  * @reserved0: reserved for padding and future use
118  * @mhz: primary 20 MHz channel frequency in mhz
119  * @band_center_freq1: Center frequency 1 in MHz
120  * @band_center_freq2: Center frequency 2 in MHz, valid only for 11ac
121  *      VHT 80+80 mode
122  * @info: channel info
123  * @reg_info_1: regulatory information field 1 which contains min power,
124  *      max power, reg power and reg class id
125  * @reg_info_2: regulatory information field 2 which contains antennamax
126  */
127 struct qdf_packed wifi_pos_ch_info_rsp {
128 	uint32_t chan_id;
129 	uint32_t reserved0;
130 	uint32_t mhz;
131 	uint32_t band_center_freq1;
132 	uint32_t band_center_freq2;
133 	uint32_t info;
134 	uint32_t reg_info_1;
135 	uint32_t reg_info_2;
136 };
137 
138 /**
139  * struct wifi_pos_peer_status_info - Status information for a given peer
140  * @peer_mac_addr: peer mac address
141  * @peer_status: peer status: 1: CONNECTED, 2: DISCONNECTED
142  * @vdev_id: vdev_id for the peer mac
143  * @peer_capability: peer capability: 0: RTT/RTT2, 1: RTT3. Default is 0
144  * @reserved0: reserved0
145  * @peer_chan_info: channel info on which peer is connected
146  */
147 struct qdf_packed wifi_pos_peer_status_info {
148 	uint8_t peer_mac_addr[ETH_ALEN];
149 	uint8_t peer_status;
150 	uint8_t vdev_id;
151 	uint32_t peer_capability;
152 	uint32_t reserved0;
153 	struct wifi_pos_ch_info_rsp peer_chan_info;
154 };
155 
156 /**
157  * struct wifi_pos_req_msg - wifi pos request struct
158  * @msg_type: message type
159  * @pid: process id
160  * @buf: request buffer
161  * @buf_len: request buffer length
162  * @field_info_buf: buffer containing field info
163  * @field_info_buf_len: length of field info buffer
164  * @rsp_version: nl type or ani type
165  * @interface: contains interface name and length
166  */
167 struct wifi_pos_req_msg {
168 	enum wifi_pos_cmd_ids msg_type;
169 	uint32_t pid;
170 	uint8_t *buf;
171 	uint32_t buf_len;
172 	struct wifi_pos_field_info *field_info_buf;
173 	uint32_t field_info_buf_len;
174 	uint32_t rsp_version;
175 	struct wifi_pos_interface interface;
176 };
177 
178 /**
179  * ucfg_wifi_pos_process_req: ucfg API to be called from HDD/OS_IF to process a
180  * wifi_pos request from userspace
181  * @psoc: pointer to psoc object
182  * @req: wifi_pos request msg
183  * @send_rsp_cb: callback pointer required to send msg to userspace
184  *
185  * Return: status of operation
186  */
187 QDF_STATUS ucfg_wifi_pos_process_req(struct wlan_objmgr_psoc *psoc,
188 				     struct wifi_pos_req_msg *req,
189 				     wifi_pos_send_rsp_handler send_rsp_cb);
190 
191 /**
192  * wifi_pos_init: initializes WIFI POS component, called by dispatcher init
193  *
194  * Return: status of operation
195  */
196 QDF_STATUS wifi_pos_init(void);
197 
198 /**
199  * wifi_pos_deinit: de-initializes WIFI POS component, called by dispatcher init
200  *
201  * Return: status of operation
202  */
203 QDF_STATUS wifi_pos_deinit(void);
204 
205 /**
206  * wifi_pos_psoc_enable: psoc enable API for wifi positioning component
207  * @psoc: pointer to PSOC
208  *
209  * Return: status of operation
210  */
211 QDF_STATUS wifi_pos_psoc_enable(struct wlan_objmgr_psoc *psoc);
212 
213 /**
214  * wifi_pos_psoc_disable: psoc disable API for wifi positioning component
215  * @psoc: pointer to PSOC
216  *
217  * Return: status of operation
218  */
219 QDF_STATUS wifi_pos_psoc_disable(struct wlan_objmgr_psoc *psoc);
220 
221 /**
222  * wifi_pos_set_oem_target_type: public API to set param in wifi_pos private
223  * object
224  * @psoc: pointer to PSOC
225  * @val: value to set
226  *
227  * Return: None
228  */
229 void wifi_pos_set_oem_target_type(struct wlan_objmgr_psoc *psoc, uint32_t val);
230 
231 /**
232  * wifi_pos_set_oem_fw_version: public API to set param in wifi_pos private
233  * object
234  * @psoc: pointer to PSOC
235  * @val: value to set
236  *
237  * Return: None
238  */
239 void wifi_pos_set_oem_fw_version(struct wlan_objmgr_psoc *psoc, uint32_t val);
240 
241 /**
242  * wifi_pos_set_drv_ver_major: public API to set param in wifi_pos private
243  * object
244  * @psoc: pointer to PSOC
245  * @val: value to set
246  *
247  * Return: None
248  */
249 void wifi_pos_set_drv_ver_major(struct wlan_objmgr_psoc *psoc, uint8_t val);
250 
251 /**
252  * wifi_pos_set_drv_ver_minor: public API to set param in wifi_pos private
253  * object
254  * @psoc: pointer to PSOC
255  * @val: value to set
256  *
257  * Return: None
258  */
259 void wifi_pos_set_drv_ver_minor(struct wlan_objmgr_psoc *psoc, uint8_t val);
260 
261 /**
262  * wifi_pos_set_drv_ver_patch: public API to set param in wifi_pos private
263  * object
264  * @psoc: pointer to PSOC
265  * @val: value to set
266  *
267  * Return: None
268  */
269 void wifi_pos_set_drv_ver_patch(struct wlan_objmgr_psoc *psoc, uint8_t val);
270 
271 /**
272  * wifi_pos_set_drv_ver_build: public API to set param in wifi_pos private
273  * object
274  * @psoc: pointer to PSOC
275  * @val: value to set
276  *
277  * Return: None
278  */
279 void wifi_pos_set_drv_ver_build(struct wlan_objmgr_psoc *psoc, uint8_t val);
280 
281 /**
282  * wifi_pos_set_dwell_time_min: public API to set param in wifi_pos private
283  * object
284  * @psoc: pointer to PSOC
285  * @val: value to set
286  *
287  * Return: None
288  */
289 void wifi_pos_set_dwell_time_min(struct wlan_objmgr_psoc *psoc, uint16_t val);
290 
291 /**
292  * wifi_pos_set_dwell_time_max: public API to set param in wifi_pos private
293  * object
294  * @psoc: pointer to PSOC
295  * @val: value to set
296  *
297  * Return: None
298  */
299 void wifi_pos_set_dwell_time_max(struct wlan_objmgr_psoc *psoc, uint16_t val);
300 
301 /**
302  * wifi_pos_set_current_dwell_time_min: public API to set param in wifi_pos
303  * private object
304  * @psoc: pointer to PSOC
305  * @val: value to set
306  *
307  * Return: None
308  */
309 void wifi_pos_set_current_dwell_time_min(struct wlan_objmgr_psoc *psoc,
310 					 uint16_t val);
311 
312 /**
313  * wifi_pos_set_current_dwell_time_max: public API to set param in wifi_pos
314  * private object
315  * @psoc: pointer to PSOC
316  * @val: value to set
317  *
318  * Return: None
319  */
320 void wifi_pos_set_current_dwell_time_max(struct wlan_objmgr_psoc *psoc,
321 					 uint16_t val);
322 
323 /**
324  * wifi_pos_populate_caps() - populate oem capabilities
325  * @psoc: psoc object
326  * @caps: pointer to populate the capabilities
327  *
328  * Return: error code
329  */
330 QDF_STATUS wifi_pos_populate_caps(struct wlan_objmgr_psoc *psoc,
331 			   struct wifi_pos_driver_caps *caps);
332 
333 struct wlan_lmac_if_rx_ops;
334 /**
335  * wifi_pos_register_rx_ops: function to register with lmac rx ops
336  * @rx_ops: lmac rx ops struct object
337  *
338  * Return: None
339  */
340 void wifi_pos_register_rx_ops(struct wlan_lmac_if_rx_ops *rx_ops);
341 
342 /**
343  * ucfg_wifi_pos_get_ftm_cap: API to get fine timing measurement caps
344  * @psoc: psoc object
345  *
346  * Return: FTM value
347  */
348 uint32_t ucfg_wifi_pos_get_ftm_cap(struct wlan_objmgr_psoc *psoc);
349 
350 /**
351  * ucfg_wifi_pos_set_ftm_cap: API to set fine timing measurement caps
352  * @psoc: psoc object
353  * @val: value to set
354  *
355  * Return: None
356  */
357 void ucfg_wifi_pos_set_ftm_cap(struct wlan_objmgr_psoc *psoc, uint32_t val);
358 
359 /**
360  * ucfg_wifi_pos_set_oem_6g_supported: API to set oem target 6g enabled/disabled
361  * @psoc: psoc object
362  * @val: value to set
363  *
364  * Return: None
365  */
366 void ucfg_wifi_pos_set_oem_6g_supported(struct wlan_objmgr_psoc *psoc,
367 					bool val);
368 
369 /**
370  * ucfg_wifi_pos_is_nl_rsp: API to check if response is nl or ani type
371  * @psoc: psoc object
372  *
373  * Return: true if response is nl type
374  */
375 bool ucfg_wifi_pos_is_nl_rsp(struct wlan_objmgr_psoc *psoc);
376 
377 /**
378  * wifi_pos_get_app_pid: returns oem app pid.
379  * @psoc: pointer to psoc object
380  *
381  * Return: oem app pid
382  */
383 uint32_t wifi_pos_get_app_pid(struct wlan_objmgr_psoc *psoc);
384 
385 /**
386  * wifi_pos_is_app_registered: indicates if oem app is registered.
387  * @psoc: pointer to psoc object
388  *
389  * Return: true if app is registered, false otherwise
390  */
391 bool wifi_pos_is_app_registered(struct wlan_objmgr_psoc *psoc);
392 
393 /**
394  * wifi_pos_get_psoc: API to get global PSOC object
395  *
396  * Since request from userspace is not associated with any vdev/pdev/psoc, this
397  * API is used to get global psoc object.
398  * Return: global psoc object.
399  */
400 struct wlan_objmgr_psoc *wifi_pos_get_psoc(void);
401 
402 #else
403 static inline QDF_STATUS wifi_pos_init(void)
404 {
405 	return QDF_STATUS_SUCCESS;
406 }
407 
408 static inline QDF_STATUS wifi_pos_deinit(void)
409 {
410 	return QDF_STATUS_SUCCESS;
411 }
412 
413 static inline QDF_STATUS wifi_pos_psoc_enable(struct wlan_objmgr_psoc *psoc)
414 {
415 	return QDF_STATUS_SUCCESS;
416 }
417 
418 static inline QDF_STATUS wifi_pos_psoc_disable(struct wlan_objmgr_psoc *psoc)
419 {
420 	return QDF_STATUS_SUCCESS;
421 }
422 #endif
423 
424 #if defined(WLAN_FEATURE_CIF_CFR) && defined(WIFI_POS_CONVERGED)
425 /**
426  * wifi_pos_init_cir_cfr_rings: API to set DMA ring cap in wifi pos psoc private
427  * object
428  * @psoc: pointer to psoc object
429  * @hal_soc: hal soc pointer
430  * @num_mac: number of macs
431  * @buf: buffer containing dma ring cap
432  *
433  * Return: status of operation.
434  */
435 QDF_STATUS wifi_pos_init_cir_cfr_rings(struct wlan_objmgr_psoc *psoc,
436 				   void *hal_soc, uint8_t num_mac, void *buf);
437 #else
438 static inline QDF_STATUS wifi_pos_init_cir_cfr_rings(
439 				struct wlan_objmgr_psoc *psoc,
440 				void *hal_soc, uint8_t num_mac, void *buf)
441 {
442 	return QDF_STATUS_SUCCESS;
443 }
444 #endif
445 
446 /**
447  * wifi_pos_register_get_fw_phy_mode_for_freq_cb: API to register callback
448  * to get current PHY mode
449  * @psoc: pointer to psoc object
450  * @handler: callback to be registered
451  *
452  * Return: QDF_STATUS_SUCCESS in case of success, error codes in
453  * case of failure
454  */
455 QDF_STATUS wifi_pos_register_get_fw_phy_mode_for_freq_cb(
456 			struct wlan_objmgr_psoc *psoc,
457 			void (*handler)(uint32_t, uint32_t, uint32_t *));
458 
459 /**
460  * wifi_pos_register_get_phy_mode_cb: API to register callback to get
461  * current PHY mode
462  * @psoc: pointer to psoc object
463  * @handler: callback to be registered
464  *
465  * Return: QDF_STATUS_SUCCESS in case of success, error codes in
466  * case of failure
467  */
468 QDF_STATUS wifi_pos_register_get_phy_mode_cb(
469 			struct wlan_objmgr_psoc *psoc,
470 			void (*handler)(uint8_t, uint32_t, uint32_t *));
471 
472 /**
473  * wifi_pos_register_send_action: API to register callback to send
474  * action frames
475  * @psoc: pointer to psoc object
476  * @handler: callback to be registered
477  *
478  * Return: QDF_STATUS_SUCCESS in case of success, error codes in
479  * case of failure
480  */
481 QDF_STATUS wifi_pos_register_send_action(
482 				struct wlan_objmgr_psoc *psoc,
483 				void (*handler)(struct wlan_objmgr_psoc *psoc,
484 						uint32_t sub_type,
485 						uint8_t *buf,
486 						uint32_t buf_len));
487 
488 #ifndef CNSS_GENL
489 /**
490  * ucfg_wifi_psoc_get_pdev_id_by_dev_name: ucfg API to get pdev_id and psoc from
491  *                                         devname.
492  * @dev_name: dev name received from LOWI application
493  * @pdev_id: get pdev_id from dev_name
494  * @psoc: get psoc corresponding psoc from dev_name
495  */
496 QDF_STATUS ucfg_wifi_psoc_get_pdev_id_by_dev_name(
497 		char *dev_name, uint8_t *pdev_id,
498 		struct wlan_objmgr_psoc **psoc);
499 
500 /**
501  * wifi_pos_register_get_pdev_id_by_dev_name: API to register callback to get
502  * pdev_id from dev name
503  * @psoc: pointer to global psoc object
504  * @handler: callback to be registered
505  *
506  * Return: QDF_STATUS_SUCCESS in case of success, error codes in
507  * case of failure
508  */
509 QDF_STATUS wifi_pos_register_get_pdev_id_by_dev_name(
510 		struct wlan_objmgr_psoc *psoc,
511 		QDF_STATUS (*handler)(char *dev_name, uint8_t *pdev_id,
512 				      struct wlan_objmgr_psoc **psoc));
513 #endif
514 
515 /**
516  * wifi_pos_send_report_resp: Send report to osif
517  * @psoc: pointer to psoc object
518  * @req_id: Request id
519  * @dest_mac: destination mac address
520  * @err_code: Error code to be sent
521  *
522  * Return: QDF_STATUS_SUCCESS in case of success, error codes in
523  * case of failure
524  */
525 QDF_STATUS wifi_pos_send_report_resp(struct wlan_objmgr_psoc *psoc,
526 				     int req_id, uint8_t *dest_mac,
527 				     int err_code);
528 
529 /**
530  * wifi_pos_convert_host_pdev_id_to_target: convert host pdev_id to target
531  * pdev_id
532  * @psoc: pointer to psoc object
533  * @host_pdev_id: host pdev id
534  * @target_pdev_id: target pdev id
535  *
536  * Return: QDF_STATUS_SUCCESS in case of success, error codes in
537  * case of failure
538  */
539 QDF_STATUS wifi_pos_convert_host_pdev_id_to_target(
540 	struct wlan_objmgr_psoc *psoc, uint32_t host_pdev_id,
541 	uint32_t *target_pdev_id);
542 #endif
543