1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Copyright 2021 NXP. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * You may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef UWB_INT_H_ 20 #define UWB_INT_H_ 21 22 #include "uci_defs.h" 23 #include "uwb_api.h" 24 #include "uwb_gki.h" 25 #include "uwb_target.h" 26 27 /**************************************************************************** 28 ** UWB_TASK definitions 29 ****************************************************************************/ 30 31 /* UWB_TASK event masks */ 32 #define UWB_TASK_EVT_TRANSPORT_READY EVENT_MASK(APPL_EVT_0) 33 34 /* UWB Timer events */ 35 #define UWB_TTYPE_UCI_WAIT_RSP 0x00 36 #define UWB_WAIT_RSP_RAW_CMD 0x01 37 38 #define UWB_SAVED_HDR_SIZE 2 39 40 /* UWB Task event messages */ 41 enum { 42 UWB_STATE_NONE, /* not start up yet */ 43 UWB_STATE_W4_HAL_OPEN, /* waiting for HAL_UWB_OPEN_CPLT_EVT */ 44 UWB_STATE_IDLE, /* normal operation( device is in idle state) */ 45 UWB_STATE_ACTIVE, /* UWB device is in active */ 46 UWB_STATE_W4_HAL_CLOSE, /* waiting for HAL_UWB_CLOSE_CPLT_EVT */ 47 UWB_STATE_CLOSING 48 }; 49 typedef uint8_t tUWB_STATE; 50 51 /* This data type is for UWB task to send a UCI VS command to UCIT task */ 52 typedef struct { 53 UWB_HDR bt_hdr; /* the UCI command */ 54 tUWB_RAW_CBACK* p_cback; /* the callback function to receive RSP */ 55 } tUWB_UCI_RAW_MSG; 56 57 /* This data type is for HAL event */ 58 typedef struct { 59 UWB_HDR hdr; 60 uint8_t hal_evt; /* HAL event code */ 61 uint8_t status; /* tHAL_UWB_STATUS */ 62 } tUWB_HAL_EVT_MSG; 63 64 /* callback function pointer(8; use 8 to be safe + UWB_SAVED_CMD_SIZE(2) */ 65 #define UWB_RECEIVE_MSGS_OFFSET (10) 66 67 /* UWB control blocks */ 68 typedef struct { 69 tUWB_RESPONSE_CBACK* p_resp_cback; 70 tUWB_TEST_RESPONSE_CBACK* p_test_resp_cback; 71 72 /* UWB_TASK timer management */ 73 TIMER_LIST_Q timer_queue; /* 1-sec timer event queue */ 74 TIMER_LIST_Q quick_timer_queue; 75 76 tUWB_STATE uwb_state; 77 78 uint8_t trace_level; 79 uint8_t last_hdr[UWB_SAVED_HDR_SIZE]; /* part of last UCI command header */ 80 uint8_t last_cmd[UWB_SAVED_HDR_SIZE]; /* part of last UCI command payload */ 81 82 void* p_raw_cmd_cback; /* the callback function for last raw command */ 83 BUFFER_Q uci_cmd_xmit_q; /* UCI command queue */ 84 85 TIMER_LIST_ENT 86 uci_wait_rsp_timer; /* Timer for waiting for uci command response */ 87 uint16_t uci_wait_rsp_tout; /* UCI command timeout (in ms) */ 88 uint16_t retry_rsp_timeout; /* UCI command timeout during retry */ 89 90 uint8_t uci_cmd_window; /* Number of commands the controller can accecpt 91 without waiting for response */ 92 bool is_resp_pending; /* response is pending from UWBS */ 93 bool is_recovery_in_progress; /* recovery in progresss */ 94 95 tHAL_UWB_ENTRY* p_hal; 96 uint8_t rawCmdCbflag; 97 uint8_t device_state; 98 99 uint16_t cmd_retry_count; 100 UWB_HDR* pLast_cmd_buf; 101 102 bool IsConformaceTestEnabled; /* MCTT mode indicator */ 103 } tUWB_CB; 104 105 /***************************************************************************** 106 ** EXTERNAL FUNCTION DECLARATIONS 107 *****************************************************************************/ 108 109 /* Global UWB data */ 110 extern tUWB_CB uwb_cb; 111 112 /**************************************************************************** 113 ** Internal uwb functions 114 ****************************************************************************/ 115 116 extern void uwb_init(void); 117 118 extern bool uwb_ucif_process_event(UWB_HDR* p_msg); 119 extern void uwb_ucif_check_cmd_queue(UWB_HDR* p_buf); 120 extern void uwb_ucif_retransmit_cmd(UWB_HDR* p_buf); 121 extern void uwb_ucif_send_cmd(UWB_HDR* p_buf); 122 extern void uwb_ucif_update_cmd_window(void); 123 extern void uwb_ucif_cmd_timeout(void); 124 extern void uwb_ucif_event_status(tUWB_RESPONSE_EVT event, uint8_t status); 125 extern void uwb_ucif_error_status(uint8_t conn_id, uint8_t status); 126 extern void uwb_ucif_uwb_recovery(void); 127 128 extern bool uwb_proc_core_rsp(uint8_t op_code, uint8_t* p_buf, uint16_t len); 129 extern void uwb_ucif_proc_get_device_info_rsp(uint8_t* p_buf, uint16_t len); 130 extern void uwb_ucif_proc_get_device_capability_rsp(uint8_t* p_buf, 131 uint16_t len); 132 extern void uwb_ucif_proc_core_set_config_status(uint8_t* p_buf, uint16_t len); 133 extern void uwb_ucif_proc_core_get_config_rsp(uint8_t* p_buf, uint16_t len); 134 extern void uwb_ucif_proc_core_device_reset_rsp_status(uint8_t* p_buf, 135 uint16_t len); 136 extern void uwb_ucif_proc_core_device_status(uint8_t* p_buf, uint16_t len); 137 extern void uwb_ucif_proc_core_generic_error_ntf(uint8_t* p_buf, uint16_t len); 138 extern void uwb_ucif_proc_conformance_ntf(uint8_t* p_buf, uint16_t len); 139 extern void uwb_ucif_proc_app_get_config_status(uint8_t* p_buf, uint16_t len); 140 extern void uwb_ucif_proc_app_set_config_status(uint8_t* p_buf, uint16_t len); 141 extern void uwb_ucif_proc_ranging_data(uint8_t* p_buf, uint16_t len); 142 extern void uwb_ucif_proc_send_blink_data_ntf(uint8_t* p_buf, uint16_t len); 143 extern void uwb_ucif_range_management_status(tUWB_RESPONSE_EVT event, 144 uint8_t* p_buf, uint16_t len); 145 extern void uwb_ucif_get_range_count_status(tUWB_RESPONSE_EVT event, 146 uint8_t* p_buf, uint16_t len); 147 extern void uwb_ucif_session_management_status(tUWB_RESPONSE_EVT event, 148 uint8_t* p_buf, uint16_t len); 149 extern void uwb_ucif_proc_session_status(uint8_t* p_buf, uint16_t len); 150 extern void uwb_ucif_proc_multicast_list_update_ntf(uint8_t* p_buf, 151 uint16_t len); 152 void uwb_ucif_proc_android_set_country_code_status(uint8_t* p_buf, 153 uint16_t len); 154 155 /* APIs for handling UWB RF test command responses and notifications */ 156 extern void uwb_ucif_test_management_status(tUWB_RESPONSE_EVT event, 157 uint8_t* p_buf, uint16_t len); 158 extern void uwb_ucif_proc_test_get_config_status(uint8_t* p_buf, uint16_t len); 159 extern void uwb_ucif_proc_test_set_config_status(uint8_t* p_buf, uint16_t len); 160 extern void uwb_ucif_proc_rf_test_data(tUWB_RESPONSE_EVT event, uint8_t* p_buf, 161 uint16_t len); 162 163 /* From uwb_task.c */ 164 extern uint32_t uwb_task(uint32_t param); 165 void uwb_task_shutdown_uwbc(void); 166 167 /* From uwb_main.c */ 168 void uwb_enabled(tUWB_STATUS uwb_status, UWB_HDR* p_init_rsp_msg); 169 void uwb_set_state(tUWB_STATE uwb_state); 170 void uwb_main_flush_cmd_queue(void); 171 void uwb_main_handle_hal_evt(tUWB_HAL_EVT_MSG* p_msg); 172 void uwb_gen_cleanup(void); 173 174 /* Timer functions */ 175 void uwb_start_timer(TIMER_LIST_ENT* p_tle, uint16_t type, uint32_t timeout); 176 uint32_t uwb_remaining_time(TIMER_LIST_ENT* p_tle); 177 void uwb_stop_timer(TIMER_LIST_ENT* p_tle); 178 179 void uwb_start_quick_timer(TIMER_LIST_ENT* p_tle, uint16_t type, 180 uint32_t timeout); 181 void uwb_stop_quick_timer(TIMER_LIST_ENT* p_tle); 182 void uwb_process_quick_timer_evt(void); 183 184 #endif /* UWB_INT_H_ */ 185