• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 UWA_DM_INT_H
20 #define UWA_DM_INT_H
21 
22 #include <string.h>
23 
24 #include "uwa_api.h"
25 #include "uwa_sys.h"
26 #include "uwb_api.h"
27 
28 /*****************************************************************************
29 **  Constants and data types
30 *****************************************************************************/
31 
32 /* UWA_DM flags */
33 /* DM is enabled                                                        */
34 #define UWA_DM_FLAGS_DM_IS_ACTIVE 0x00000001
35 #define UWA_DM_FLAGS_ENABLE_EVT_PEND 0x00000002
36 
37 /* DM events */
38 enum {
39   /* device manager local device API events */
40   UWA_DM_API_ENABLE_EVT = UWA_SYS_EVT_START(UWA_ID_DM),
41   UWA_DM_API_DISABLE_EVT,
42   UWA_DM_API_GET_DEVICE_INFO_EVT,
43   UWA_DM_API_SET_CORE_CONFIG_EVT,
44   UWA_DM_API_GET_CORE_CONFIG_EVT,
45   UWA_DM_API_DEVICE_RESET_EVT,
46   UWA_DM_API_SESSION_INIT_EVT,
47   UWA_DM_API_SESSION_DEINIT_EVT,
48   UWA_DM_API_SESSION_GET_COUNT_EVT,
49   UWA_DM_API_SET_APP_CONFIG_EVT,
50   UWA_DM_API_GET_APP_CONFIG_EVT,
51   UWA_DM_API_START_RANGE_EVT,
52   UWA_DM_API_STOP_RANGE_EVT,
53   UWA_DM_API_SEND_RAW_EVT,
54   UWA_DM_API_GET_RANGE_COUNT_EVT,
55   UWA_DM_API_GET_SESSION_STATUS_EVT,
56   UWA_DM_API_CORE_GET_DEVICE_CAPABILITY_EVT,
57   UWA_DM_API_SESSION_UPDATE_MULTICAST_LIST_EVT,
58   UWA_DM_API_SET_COUNTRY_CODE_EVT,
59   UWA_DM_API_SEND_BLINK_DATA_EVT,
60   /*    UWB RF Test API events   */
61   UWA_DM_API_TEST_SET_CONFIG_EVT,
62   UWA_DM_API_TEST_GET_CONFIG_EVT,
63   UWA_DM_API_TEST_PERIODIC_TX_EVT,
64   UWA_DM_API_TEST_PER_RX_EVT,
65   UWA_DM_API_TEST_UWB_LOOPBACK_EVT,
66   UWA_DM_API_TEST_RX_EVT,
67   UWA_DM_API_TEST_STOP_SESSION_EVT,
68   /* UWB Data packet events */
69   UWA_DM_MAX_EVT
70 };
71 
72 /* data type for UWA_DM_API_ENABLE_EVT */
73 typedef struct {
74   UWB_HDR hdr;
75   tUWA_DM_CBACK* p_dm_cback;
76   tUWA_DM_TEST_CBACK* p_dm_test_cback;
77 } tUWA_DM_API_ENABLE;
78 
79 /* data type for UWA_DM_API_DISABLE_EVT */
80 typedef struct {
81   UWB_HDR hdr;
82   bool graceful;
83 } tUWA_DM_API_DISABLE;
84 
85 /* data type for UWA_DM_API_SET_CORE_CONFIG_EVT */
86 typedef struct {
87   UWB_HDR hdr;
88   tUWA_PMID param_id;
89   uint8_t length;
90   uint8_t* p_data;
91 } tUWA_DM_API_CORE_SET_CONFIG;
92 
93 /* data type for UWA_DM_API_SET_APP_CONFIG_EVT */
94 typedef struct {
95   UWB_HDR hdr;
96   uint32_t session_id;
97   uint8_t num_ids;
98   uint8_t length;
99   uint8_t* p_data;
100 } tUWA_DM_API_SET_APP_CONFIG;
101 
102 /* data type for UWA_DM_API_GET_CORE_CONFIG_EVT */
103 typedef struct {
104   UWB_HDR hdr;
105   uint8_t num_ids;
106   tUWA_PMID* p_pmids;
107 } tUWA_DM_API_CORE_GET_CONFIG;
108 
109 /* data type for UWA_DM_API_GET_APP_CONFIG_EVT */
110 typedef struct {
111   UWB_HDR hdr;
112   uint32_t session_id;
113   uint8_t num_ids;
114   uint8_t length;
115   uint8_t* p_pmids;
116 } tUWA_DM_API_GET_APP_CONFIG;
117 
118 /* data type for UWA_DM_API_DEVICE_RESET_EVT */
119 typedef struct {
120   UWB_HDR hdr;
121   uint8_t resetConfig; /* Vendor Specific Reset Config*/
122 } tUWA_DM_API_DEVICE_RESET;
123 
124 /* data type for UWA_DM_API_SEND_RAW_EVT */
125 typedef struct {
126   UWB_HDR hdr;
127   tUWA_RAW_CMD_CBACK* p_cback;
128   uint8_t oid;
129   uint16_t cmd_params_len;
130   uint8_t* p_cmd_params;
131 } tUWA_DM_API_SEND_RAW;
132 
133 /* data type for UWA_DM_API_START_RANGE_EVT */
134 typedef struct {
135   UWB_HDR hdr;
136   uint32_t session_id; /* Session ID for which ranging shall start */
137 } tUWA_DM_API_RANGING_START;
138 
139 /* data type for UWA_DM_API_STOP_RANGE_EVT */
140 typedef struct {
141   UWB_HDR hdr;
142   uint32_t session_id; /* Session ID for which ranging shall stop */
143 } tUWA_DM_API_RANGING_STOP;
144 
145 /* data type for UWA_DM_API_SESSION_GET_COUNT_EVT */
146 typedef struct {
147   UWB_HDR hdr;
148 } tUWA_DM_API_GET_SESSION_COUNT;
149 
150 /* data type for UWA_DM_API_SESSION_GET_COUNT_EVT */
151 typedef struct {
152   UWB_HDR hdr;
153   uint32_t session_id;
154 } tUWA_DM_API_GET_RANGING_COUNT;
155 
156 /* data type for UWA_DM_API_SESSION_GET_STATUS_EVT */
157 typedef struct {
158   UWB_HDR hdr;
159   uint32_t session_id;
160 } tUWA_DM_API_GET_SESSION_STATUS;
161 
162 /* data type for UWA_DM_API_SESSION_INIT_EVT */
163 typedef struct {
164   UWB_HDR hdr;
165   uint32_t session_id; /* session_id for Particular Activity */
166   uint8_t sessionType; /* session type for Particular Activity */
167 } tUWA_DM_API_SESSION_INIT;
168 
169 /* data type for UWA_DM_API_SESSION_DEINIT_EVT */
170 typedef struct {
171   UWB_HDR hdr;
172   uint32_t session_id; /* session_id for Particular activity */
173 } tUWA_DM_API_SESSION_DEINIT;
174 
175 /* data type for UWA_DM_API_GET_DEVICE_INFO_EVT */
176 typedef struct {
177   UWB_HDR hdr;
178 } tUWA_DM_API_GET_DEVICE_INFO;
179 
180 /* data type for UWA_DM_API_CORE_GET_DEVICE_CAPABILITY_EVT */
181 typedef struct {
182   UWB_HDR hdr;
183 } tUWA_DM_API_CORE_GET_DEVICE_CAPABILITY;
184 
185 /* data type for UWA_DM_API_SESSION_UPDATE_MULTICAST_LIST_EVT */
186 typedef struct {
187   UWB_HDR hdr;
188   uint32_t session_id;
189   uint8_t action;
190   uint8_t no_of_controlee;
191   uint16_t short_address_list[MAX_NUM_CONTROLLEES];
192   uint32_t subsession_id_list[MAX_NUM_CONTROLLEES];
193 } tUWA_DM_API_SESSION_UPDATE_MULTICAST_LIST;
194 
195 /* data type for UWA_DM_API_SESSION_UPDATE_MULTICAST_LIST_EVT */
196 typedef struct {
197   UWB_HDR hdr;
198   uint8_t country_code[COUNTRY_CODE_ARRAY_LEN];
199 } tUWA_DM_API_SET_COUNTRY_CODE;
200 
201 /* data type for UWA_DM_API_DM_API_SEND_BLINK_DATA_EVT */
202 typedef struct {
203   UWB_HDR hdr;
204   uint32_t session_id;
205   uint8_t repetition_count;
206   uint8_t app_data_len;
207   uint8_t app_data[UCI_MAX_PAYLOAD_SIZE];
208 } tUWA_DM_API_SEND_BLINK_DATA;
209 
210 /* data type for UWA_DM_API_TEST_SET_CONFIG_EVT */
211 typedef struct {
212   UWB_HDR hdr;
213   uint32_t session_id;
214   uint8_t num_ids;
215   uint8_t length;
216   uint8_t* p_data;
217 } tUWA_DM_API_TEST_SET_CONFIG;
218 
219 /* data type for UWA_DM_API_TEST_GET_CONFIG_EVT */
220 typedef struct {
221   UWB_HDR hdr;
222   uint32_t session_id;
223   uint8_t num_ids;
224   uint8_t length;
225   uint8_t* p_pmids;
226 } tUWA_DM_API_TEST_GET_CONFIG;
227 
228 /* data type for UWA_DM_API_TEST_PERIODIC_TX_EVT */
229 typedef struct {
230   UWB_HDR hdr;
231   uint16_t length;
232   uint8_t* p_data;
233 } tUWA_DM_API_TEST_PERIODIC_TX;
234 
235 /* data type for UWA_DM_API_TEST_PER_RX_EVT */
236 typedef struct {
237   UWB_HDR hdr;
238   uint16_t length;
239   uint8_t* p_data;
240 } tUWA_DM_API_TEST_PER_RX;
241 
242 /* data type for UWA_DM_API_TEST_UWB_LOOPBACK_EVT */
243 typedef struct {
244   UWB_HDR hdr;
245   uint16_t length;
246   uint8_t* p_data;
247 } tUWA_DM_API_TEST_UWB_LOOPBACK;
248 
249 /* data type for UWA_DM_API_TEST_RX_EVT */
250 typedef struct {
251   UWB_HDR hdr;
252 } tUWA_DM_API_TEST_RX;
253 
254 /* data type for UWA_DM_API_TEST_STOP_SESSION_EVT */
255 typedef struct {
256   UWB_HDR hdr;
257 } tUWA_DM_API_TEST_STOP_SESSION;
258 
259 /* union of all data types */
260 typedef union {
261   /* GKI event buffer header */
262   UWB_HDR hdr;
263   tUWA_DM_API_ENABLE enable;   /* UWA_DM_API_ENABLE_EVT           */
264   tUWA_DM_API_DISABLE disable; /* UWA_DM_API_DISABLE_EVT          */
265   tUWA_DM_API_GET_DEVICE_INFO
266       sGet_device_info;                   /* UWA_DM_API_GET_DEVICE_INFO      */
267   tUWA_DM_API_DEVICE_RESET sDevice_reset; /* UWA_DM_API_DEVICE_RESET_EVT */
268   tUWA_DM_API_CORE_SET_CONFIG setconfig;  /* UWA_DM_API_SET_CORE_CONFIG_EVT  */
269   tUWA_DM_API_CORE_GET_CONFIG getconfig;  /* UWA_DM_API_GET_CORE_CONFIG_EVT  */
270   tUWA_DM_API_SESSION_INIT sessionInit;   /* UWA_DM_API_SESSION_INIT         */
271   tUWA_DM_API_SESSION_DEINIT sessionDeInit; /* UWA_DM_API_SESSION_DEINIT */
272   tUWA_DM_API_GET_SESSION_COUNT
273       sGet_session_cnt; /* UWA_DM_API_SESSION_GET_COUNT_EVT*/
274   tUWA_DM_API_GET_APP_CONFIG
275       sApp_get_config; /* UWA_DM_API_GET_CORE_CONFIG_EVT       */
276   tUWA_DM_API_SET_APP_CONFIG
277       sApp_set_config; /* UWA_DM_API_SET_CORE_CONFIG_EVT       */
278   tUWA_DM_API_RANGING_START rang_start; /* UWA_DM_API_START_RANGE_EVT        */
279   tUWA_DM_API_RANGING_STOP rang_stop;   /* UWA_DM_API_STOP_RANGE_EVT         */
280   tUWA_DM_API_SEND_RAW send_raw;        /* UWA_DM_API_SEND_RAW_EVT         */
281   tUWA_DM_API_GET_RANGING_COUNT
282       sGet_rang_count; /* UWA_DM_API_GET_RANGE_COUNT_EVT         */
283   tUWA_DM_API_GET_SESSION_STATUS
284       sGet_session_status; /* UWA_DM_API_GET_SESSION_STATUS_EVT         */
285   tUWA_DM_API_CORE_GET_DEVICE_CAPABILITY
286       get_device_capability; /* UWA_DM_API_CORE_GET_DEVICE_CAPABILITY_EVT  */
287   tUWA_DM_API_TEST_UWB_LOOPBACK
288       sUwb_loopback; /* UWA_DM_API_TEST_UWB_LOOPBACK_EVT  */
289   tUWA_DM_API_SESSION_UPDATE_MULTICAST_LIST
290       sMulticast_list; /* UWA_DM_API_SESSION_UPDATE_MULTICAST_LIST_EVT */
291   tUWA_DM_API_SET_COUNTRY_CODE
292       sCountryCode; /* UWA_DM_API_SET_COUNTRY_CODE_EVT */
293   tUWA_DM_API_SEND_BLINK_DATA
294       sSend_blink_data; /* UWA_DM_API_SEND_BLINK_DATA_EVT */
295                         /*  data types for all UWB RF TEST events */
296   tUWA_DM_API_TEST_GET_CONFIG
297       sTest_get_config; /* UWA_DM_API_TEST_GET_CONFIG_EVT       */
298   tUWA_DM_API_TEST_SET_CONFIG
299       sTest_set_config; /* UWA_DM_API_TEST_SET_CONFIG_EVT       */
300   tUWA_DM_API_TEST_PERIODIC_TX
301       sPeriodic_tx; /* UWA_DM_API_TEST_PERIODIC_TX_EVT            */
302   tUWA_DM_API_TEST_PER_RX sPer_rx; /* UWA_DM_API_TEST_PER_RX_EVT            */
303   tUWA_DM_API_TEST_RX sTest_rx;    /*UWA_DM_API_TEST_RX_EVT*/
304   tUWA_DM_API_TEST_STOP_SESSION
305       sTest_stop_session; /* UWA_DM_API_TEST_STOP_SESSION_EVT     */
306 } tUWA_DM_MSG;
307 
308 typedef struct {
309   uint32_t flags; /* UWA_DM flags (see definitions for UWA_DM_FLAGS_*)    */
310   tUWA_DM_CBACK* p_dm_cback;           /* UWA DM callback */
311   tUWA_DM_TEST_CBACK* p_dm_test_cback; /* UWA DM callback for RF test events */
312   TIMER_LIST_ENT tle;
313 } tUWA_DM_CB;
314 
315 tUWA_STATUS uwa_rw_send_raw_frame(UWB_HDR* p_data);
316 void uwa_dm_disable_complete(void);
317 
318 /* UWA device manager control block */
319 extern tUWA_DM_CB uwa_dm_cb;
320 
321 void uwa_dm_init(void);
322 
323 /* Action function prototypes */
324 bool uwa_dm_enable(tUWA_DM_MSG* p_data);
325 bool uwa_dm_disable(tUWA_DM_MSG* p_data);
326 bool uwa_dm_act_get_device_info(tUWA_DM_MSG* p_data);
327 bool uwa_dm_act_device_reset(tUWA_DM_MSG* p_data);
328 bool uwa_dm_set_core_config(tUWA_DM_MSG* p_data);
329 bool uwa_dm_get_core_config(tUWA_DM_MSG* p_data);
330 bool uwa_dm_act_send_session_init(tUWA_DM_MSG* p_data);
331 bool uwa_dm_act_send_session_deinit(tUWA_DM_MSG* p_data);
332 bool uwa_dm_act_get_session_count(tUWA_DM_MSG* p_data);
333 bool uwa_dm_act_app_set_config(tUWA_DM_MSG* p_data);
334 bool uwa_dm_act_app_get_config(tUWA_DM_MSG* p_data);
335 bool uwa_dm_act_start_range_session(tUWA_DM_MSG* p_data);
336 bool uwa_dm_act_stop_range_session(tUWA_DM_MSG* p_data);
337 bool uwa_dm_act_send_raw_cmd(tUWA_DM_MSG* p_data);
338 bool uwa_dm_act_get_range_count(tUWA_DM_MSG* p_data);
339 bool uwa_dm_act_get_session_status(tUWA_DM_MSG* p_data);
340 bool uwa_dm_act_get_device_capability(tUWA_DM_MSG* p_data);
341 bool uwa_dm_act_multicast_list_update(tUWA_DM_MSG* p_data);
342 bool uwa_dm_act_set_country_code(tUWA_DM_MSG* p_data);
343 bool uwa_dm_act_send_blink_data(tUWA_DM_MSG* p_data);
344 
345 /* Action function prototypes for all RF test functionality */
346 bool uwa_dm_act_test_set_config(tUWA_DM_MSG* p_data);
347 bool uwa_dm_act_test_get_config(tUWA_DM_MSG* p_data);
348 bool uwa_dm_act_test_periodic_tx(tUWA_DM_MSG* p_data);
349 bool uwa_dm_act_test_per_rx(tUWA_DM_MSG* p_data);
350 bool uwa_dm_act_test_uwb_loopback(tUWA_DM_MSG* p_data);
351 bool uwa_dm_act_test_rx(tUWA_DM_MSG* p_data);
352 bool uwa_dm_act_test_stop_session(tUWA_DM_MSG* p_data);
353 
354 /* Main function prototypes */
355 bool uwa_dm_evt_hdlr(UWB_HDR* p_msg);
356 void uwa_dm_sys_enable(void);
357 void uwa_dm_sys_disable(void);
358 
359 std::string uwa_dm_uwb_revt_2_str(tUWB_RESPONSE_EVT event);
360 std::string uwa_test_dm_uwb_revt_2_str(tUWB_RESPONSE_EVT event);
361 
362 #endif /* UWA_DM_INT_H */
363