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