• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file softbus_broadcast_type.h
18  * @brief Declare constants for the softbus broadcast.
19  *
20  * @since 4.1
21  * @version 1.0
22  */
23 
24 #ifndef SOFTBUS_BROADCAST_TYPE_STRUCT_H
25 #define SOFTBUS_BROADCAST_TYPE_STRUCT_H
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 #ifdef __cplusplus
30 extern "C"{
31 #endif
32 
33 /**
34  * @brief Defines mac address length.
35  *
36  * @since 4.1
37  * @version 1.0
38  */
39 #define BC_ADDR_MAC_LEN                          6
40 
41 // Bluetooth scan duty cycle, unit: ms
42 #define SOFTBUS_BC_SCAN_INTERVAL_P2              3000
43 #define SOFTBUS_BC_SCAN_INTERVAL_P2_FAST         1500
44 #define SOFTBUS_BC_SCAN_INTERVAL_P10             300
45 #define SOFTBUS_BC_SCAN_INTERVAL_P10_LONG_RANGE  400
46 #define SOFTBUS_BC_SCAN_INTERVAL_P25             240
47 #define SOFTBUS_BC_SCAN_INTERVAL_P50             60
48 #define SOFTBUS_BC_SCAN_INTERVAL_P75             40
49 #define SOFTBUS_BC_SCAN_INTERVAL_P100_LONG_RANGE 30
50 #define SOFTBUS_BC_SCAN_INTERVAL_P100            1000
51 #define SOFTBUS_BC_SCAN_WINDOW_P2                60
52 #define SOFTBUS_BC_SCAN_WINDOW_P2_FAST           30
53 #define SOFTBUS_BC_SCAN_WINDOW_P10               30
54 #define SOFTBUS_BC_SCAN_WINDOW_P10_LONG_RANGE    40
55 #define SOFTBUS_BC_SCAN_WINDOW_P25               60
56 #define SOFTBUS_BC_SCAN_WINDOW_P50               30
57 #define SOFTBUS_BC_SCAN_WINDOW_P75               30
58 #define SOFTBUS_BC_SCAN_WINDOW_P100              1000
59 #define SOFTBUS_BC_SCAN_WINDOW_P100_LONG_RANGE   30
60 
61 /**
62  * @brief Defines the maxium lenght of irk information.
63  *
64  * @since 4.1
65  * @version 1.0
66  */
67 #define BC_IRK_LEN                               16
68 
69 /**
70  * @brief Defines the maxium lenght of udid hash information.
71  *
72  * @since 4.1
73  * @version 1.0
74  */
75 #define BC_UDID_HASH_LEN                         32
76 
77 /**
78  * @brief Defines the length of local name, the maximum length of complete local name is 30 bytes.
79  *
80  * @since 4.1
81  * @version 1.0
82  */
83 #define BC_LOCAL_NAME_LEN_MAX                    30
84 
85 /**
86  * @brief Defines the broadcast protocol.
87  *
88  * @since 6.0
89  * @version 1.0
90  */
91 typedef enum {
92     BROADCAST_PROTOCOL_BLE,
93     BROADCAST_PROTOCOL_SLE,
94     BROADCAST_PROTOCOL_BUTT,
95 } BroadcastProtocol;
96 
97 /**
98  * @brief Defines the broadcast service type.
99  *
100  * @since 4.1
101  * @version 1.0
102  */
103 typedef enum {
104     SRV_TYPE_HB, // The service type is heart beat.
105     SRV_TYPE_CONN, // The service type is connection.
106     SRV_TYPE_TRANS_MSG, // The service type is transmission message.
107     SRV_TYPE_DIS, // The service type is distributed discovery.
108     SRV_TYPE_SHARE, // The service type is share discovery.
109     SRV_TYPE_APPROACH, // The service type is approach discovery.
110     SRV_TYPE_LP_BURST, // The service type is burst for lowpower.
111     SRV_TYPE_LP_HB, // The service type is heartbeat for lowpower.
112     SRV_TYPE_FAST_OFFLINE, // The service type is fast offline.
113     SRV_TYPE_VLINK, // The service type is virtual link discovery.
114     SRV_TYPE_TOUCH, // The service type is touch discovery.
115     SRV_TYPE_OOP, // The service type is oop discovery.
116     SRV_TYPE_AUTH_CONN, // The service type is auth connection.
117     SRV_TYPE_OH_APPROACH, // The service type is oh approach discovery.
118     SRV_TYPE_D2D_PAGING, // The service type is D2D 1v1 communication.
119     SRV_TYPE_D2D_GROUP_TALKIE, // The service type is D2D group talkie.
120     SRV_TYPE_BUTT,
121 } BaseServiceType;
122 
123 /**
124  * @brief Defines the mapping between supported service types and their names.
125  *
126  * @since 4.1
127  * @version 1.0
128  */
129 typedef struct {
130     /** Service types. For details, see {@link BaseServiceType}. */
131     BaseServiceType srvType;
132     /** Service names. For details, see {@link g_srvTypeMap}. */
133     char *service;
134 } SrvTypeMap;
135 
136 /**
137  * @brief Defines the mapping between supported service types and their names.
138  *
139  * Subsequent extensions need to be added in sequence.
140  *
141  * @since 4.1
142  * @version 1.0
143  */
144 static const SrvTypeMap g_srvTypeMap[] = {
145     {SRV_TYPE_HB, (char *)"heart beat"},
146     {SRV_TYPE_CONN, (char *)"connection"},
147     {SRV_TYPE_TRANS_MSG, (char *)"trans msg"},
148     {SRV_TYPE_DIS, (char *)"distributed"},
149     {SRV_TYPE_SHARE, (char *)"share"},
150     {SRV_TYPE_APPROACH, (char *)"approach"},
151     {SRV_TYPE_LP_BURST, (char *)"lp burst"},
152     {SRV_TYPE_LP_HB, (char *)"lp heartbeat"},
153     {SRV_TYPE_FAST_OFFLINE, (char *)"fast offline"},
154     {SRV_TYPE_VLINK, (char *)"virtual link"},
155     {SRV_TYPE_TOUCH, (char *)"touch"},
156     {SRV_TYPE_OOP, (char *)"oop"},
157     {SRV_TYPE_AUTH_CONN, (char *)"authConn"},
158     {SRV_TYPE_OH_APPROACH, (char *)"oh_approach"},
159     {SRV_TYPE_D2D_PAGING, (char *)"d2d paging"},
160     {SRV_TYPE_D2D_GROUP_TALKIE, (char *)"d2d group talkie"},
161 };
162 
163 /**
164  * @brief Defines the broadcast type to lp.
165  *
166  * @since 5.0
167  * @version 1.0
168  */
169 typedef enum {
170     SOFTBUS_HEARTBEAT_TYPE = 0,
171     SOFTBUS_BURST_TYPE,
172     SOFTBUS_UNKNOW_TYPE,
173 } LpServerType;
174 
175 /**
176  * @brief Defines the broadcast status type.
177  *
178  * @since 4.1
179  * @version 1.0
180  */
181 typedef enum {
182     SOFTBUS_BC_STATUS_SUCCESS = 0x00,
183     SOFTBUS_BC_STATUS_FAIL,
184     SOFTBUS_BC_STATUS_NOT_READY,
185     SOFTBUS_BC_STATUS_NOMEM,
186     SOFTBUS_BC_STATUS_BUSY,
187     SOFTBUS_BC_STATUS_DONE,
188     SOFTBUS_BC_STATUS_UNSUPPORTED,
189     SOFTBUS_BC_STATUS_PARM_INVALID,
190     SOFTBUS_BC_STATUS_UNHANDLED,
191     SOFTBUS_BC_STATUS_AUTH_FAILURE,
192     SOFTBUS_BC_STATUS_RMT_DEV_DOWN,
193     SOFTBUS_BC_STATUS_AUTH_REJECTED,
194     SOFTBUS_BC_STATUS_DUPLICATED_ADDR
195 } SoftBusBcStatus;
196 
197 /**
198  * @brief Defines the broadcast event type.
199  *
200  * @since 4.1
201  * @version 1.0
202  */
203 typedef enum {
204     SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00,
205     SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
206     SOFTBUS_BC_EVT_CONNECTABLE = 0x01,
207     SOFTBUS_BC_EVT_CONNECTABLE_DIRECTED = 0x05,
208     SOFTBUS_BC_EVT_SCANNABLE = 0x02,
209     SOFTBUS_BC_EVT_SCANNABLE_DIRECTED = 0x06,
210     SOFTBUS_BC_EVT_LEGACY_NON_CONNECTABLE = 0x10,
211     SOFTBUS_BC_EVT_LEGACY_SCANNABLE = 0x12,
212     SOFTBUS_BC_EVT_LEGACY_CONNECTABLE = 0x13,
213     SOFTBUS_BC_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15,
214     SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A,
215     SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B
216 } SoftBusBcScanResultEvtType;
217 
218 /**
219  * @brief Defines the broadcast mac type.
220  *
221  * @since 4.1
222  * @version 1.0
223  */
224 typedef enum {
225     SOFTBUS_BC_PUBLIC_DEVICE_ADDRESS = 0x00,
226     SOFTBUS_BC_RANDOM_DEVICE_ADDRESS = 0x01,
227     SOFTBUS_BC_PUBLIC_IDENTITY_ADDRESS = 0x02,
228     SOFTBUS_BC_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03,
229     SOFTBUS_BC_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE,
230     SOFTBUS_BC_NO_ADDRESS = 0xFF,
231 } SoftBusBcScanResultAddrType;
232 
233 /**
234  * @brief Defines the scan type.
235  *
236  * @since 4.1
237  * @version 1.0
238  */
239 typedef enum {
240     SOFTBUS_BC_SCAN_TYPE_PASSIVE = 0x00,
241     SOFTBUS_BC_SCAN_TYPE_ACTIVE,
242 } SoftBusBcScanType;
243 
244 /**
245  * @brief Defines the scan physics type.
246  *
247  * @since 4.1
248  * @version 1.0
249  */
250 typedef enum {
251     SOFTBUS_BC_SCAN_PHY_NO_PACKET = 0x00,
252     SOFTBUS_BC_SCAN_PHY_1M = 0x01,
253     SOFTBUS_BC_SCAN_PHY_2M = 0x02,
254     SOFTBUS_BC_SCAN_PHY_CODED = 0x03
255 } SoftBusBcScanResultPhyType;
256 
257 /**
258  * @brief Defines the scan filter policy type.
259  *
260  * @since 4.1
261  * @version 1.0
262  */
263 typedef enum {
264     SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00,
265     SOFTBUS_BC_SCAN_FILTER_POLICY_ONLY_WHITE_LIST,
266     SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA,
267     SOFTBUS_BC_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA
268 } SoftBusBcScanFilterPolicy;
269 
270 /**
271  * @brief Defines the broadcast adv type.
272  *
273  * @since 4.1
274  * @version 1.0
275  */
276 typedef enum {
277     SOFTBUS_BC_ADV_IND = 0x00,
278     SOFTBUS_BC_ADV_DIRECT_IND_HIGH = 0x01,
279     SOFTBUS_BC_ADV_SCAN_IND = 0x02,
280     SOFTBUS_BC_ADV_NONCONN_IND = 0x03,
281     SOFTBUS_BC_ADV_DIRECT_IND_LOW  = 0x04,
282 } SoftBusBcAdvType;
283 
284 /**
285  * @brief Defines the broadcast adv filter and allow scan type.
286  *
287  * @since 4.1
288  * @version 1.0
289  */
290 typedef enum {
291     SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
292     SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01,
293     SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02,
294     SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03,
295 } SoftBusBcAdvFilter;
296 
297 /**
298  * @brief Defines the broadcast data status.
299  *
300  * @since 4.1
301  * @version 1.0
302  */
303 typedef enum {
304     SOFTBUS_BC_DATA_COMPLETE = 0x00,
305     SOFTBUS_BC_DATA_INCOMPLETE_MORE_TO_COME = 0x01,
306     SOFTBUS_BC_DATA_INCOMPLETE_TRUNCATED = 0x02,
307 } SoftBusBcScanResultDataStatus;
308 
309 /**
310  * @brief Defines the switch status of the ble and br.
311  *
312  * @since 4.1
313  * @version 1.0
314  */
315 typedef enum {
316     SOFTBUS_BC_BT_STATE_TURNING_ON = 0x0,
317     SOFTBUS_BC_BT_STATE_TURN_ON,
318     SOFTBUS_BC_BT_STATE_TURNING_OFF,
319     SOFTBUS_BC_BT_STATE_TURN_OFF,
320     SOFTBUS_BC_BR_STATE_TURNING_ON,
321     SOFTBUS_BC_BR_STATE_TURN_ON,
322     SOFTBUS_BC_BR_STATE_TURNING_OFF,
323     SOFTBUS_BC_BR_STATE_TURN_OFF
324 } SoftBusBcStackState;
325 
326 /**
327  * @brief Defines the broadcast service type.
328  *
329  * @since 4.1
330  * @version 1.0
331  */
332 typedef enum {
333     BC_DATA_TYPE_SERVICE, // The broadcast data type is service data.
334     BC_DATA_TYPE_MANUFACTURER, // The broadcast data type is manufacturer data.
335     BC_DATA_TYPE_BUTT,
336 } BroadcastDataType;
337 
338 /**
339  * @brief Defines the broadcast data information.
340  *
341  * @since 4.1
342  * @version 1.0
343  */
344 typedef struct {
345     uint16_t id; // broadcast data id, uuid or company id.
346     uint16_t payloadLen;
347     BroadcastDataType type; // broadcast data type {@link BroadcastDataType}.
348     uint8_t *payload; // if pointer defines rsp payload, pointer may be null
349 } BroadcastPayload;
350 
351 /**
352  * @brief Defines the broadcast packet.
353  *
354  * @since 4.1
355  * @version 1.0
356  */
357 typedef struct {
358     // By default, the flag behavior is supported. If the flag behavior is not supported, the value must be set to false
359     bool isSupportFlag;
360     uint8_t flag;
361     BroadcastPayload bcData;
362     BroadcastPayload rspData;
363 } BroadcastPacket;
364 
365 /**
366  * @brief Defines mac address information
367  *
368  * @since 4.1
369  * @version 1.0
370  */
371 typedef struct {
372     uint8_t addr[BC_ADDR_MAC_LEN];
373 } BcMacAddr;
374 
375 /**
376  * @brief Defines uuid information
377  *
378  * @since 4.1
379  * @version 1.0
380  */
381 typedef struct {
382     uint8_t uuidLen;
383     int8_t *uuid;
384 } BroadcastUuid;
385 
386 /**
387  * @brief Defines the device information returned by <b>SoftbusBroadcastCallback</b>.
388  *
389  * @since 4.1
390  * @version 1.0
391  */
392 typedef struct {
393     uint8_t eventType;
394     uint8_t dataStatus;
395     uint8_t primaryPhy;
396     uint8_t secondaryPhy;
397     uint8_t advSid;
398     int8_t txPower;
399     int8_t rssi;
400     uint8_t addrType;
401     uint8_t localName[BC_LOCAL_NAME_LEN_MAX];
402     BcMacAddr addr;
403     int8_t *deviceName;
404     BroadcastPacket packet;
405 } BroadcastReportInfo;
406 
407 /**
408  * @brief Defines the broadcast parameters
409  *
410  * @since 4.1
411  * @version 1.0
412  */
413 typedef struct {
414     uint8_t advType;
415     uint8_t advFilterPolicy;
416     uint8_t ownAddrType;
417     uint8_t peerAddrType;
418     int8_t txPower;
419     bool isSupportRpa;
420     uint8_t ownIrk[BC_IRK_LEN];
421     uint8_t ownUdidHash[BC_UDID_HASH_LEN];
422     BcMacAddr peerAddr;
423     BcMacAddr localAddr;
424     int32_t channelMap;
425     int32_t duration;
426     int32_t minInterval;
427     int32_t maxInterval;
428     uint8_t linkRole;
429     uint8_t frameType;
430 } BroadcastParam;
431 
432 /**
433  * @brief Defines broadcast scan filters
434  *
435  * @since 4.1
436  * @version 1.0
437  */
438 typedef struct {
439     bool advIndReport;
440     uint16_t serviceUuid;
441     uint32_t serviceDataLength;
442     uint16_t manufactureId;
443     uint32_t manufactureDataLength;
444     int8_t *address;
445     int8_t *deviceName;
446     uint8_t *serviceData;
447     uint8_t *serviceDataMask;
448     uint8_t *manufactureData;
449     uint8_t *manufactureDataMask;
450     uint8_t filterIndex;
451 } BcScanFilter;
452 
453 /**
454  * @brief Defines broadcast scan parameters
455  *
456  * @since 4.1
457  * @version 1.0
458  */
459 typedef struct {
460     uint8_t scanType;
461     uint8_t scanPhy;
462     uint8_t scanFilterPolicy;
463     uint8_t frameType;
464     uint16_t scanInterval;
465     uint16_t scanWindow;
466 } BcScanParams;
467 
468 /**
469  * @brief Defines broadcast parameters of the low power chip.
470  *
471  * @since 4.1
472  * @version 1.0
473  */
474 typedef struct {
475     int32_t bcHandle;
476     BroadcastPacket packet;
477     BroadcastParam bcParam;
478 } LpBroadcastParam;
479 
480 /**
481  * @brief Defines scan parameters of the low power chip.
482  *
483  * @since 4.1
484  * @version 1.0
485  */
486 typedef struct {
487     BcScanParams scanParam;
488     int32_t listenerId;
489 } LpScanParam;
490 
491 #ifdef __cplusplus
492 }
493 #endif
494 
495 #endif /* SOFTBUS_BROADCAST_TYPE_STRUCT_H */
496