• 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  * @addtogroup SoftBus
18  * @{
19  *
20  * @brief Provides high-speed, secure communication between devices.
21  *
22  * This module implements unified distributed communication capability management between nearby devices, and provides
23  * link-independent device discovery and transmission interfaces to support service publishing and data transmission.
24  *
25  * @since 6.0
26  * @version 1.0
27  */
28 /** @} */
29 
30 /**
31  * @file softbus_service_type.h
32  *
33  * @brief Declares structs and constants for service discovery.
34  *
35  * @since 6.0
36  * @version 1.0
37  */
38 
39 #ifndef SOFTBUS_SERVICE_DISCOVERY_TYPE_H
40 #define SOFTBUS_SERVICE_DISCOVERY_TYPE_H
41 
42 #include <stdbool.h>
43 #include <stdint.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Indicate the maximum length of service type string.
51  *
52  * @since 6.0
53  * @version 1.0
54  */
55 #define DISC_SERVICE_TYPE_MAX_LEN 16
56 
57 /**
58  * @brief Indicate the maximum length of service name string.
59  *
60  * @since 6.0
61  * @version 1.0
62  */
63 #define DISC_SERVICE_NAME_MAX_LEN 64
64 
65 /**
66  * @brief Indicate the maximum length of service display name string.
67  *
68  * @since 6.0
69  * @version 1.0
70  */
71 #define DISC_SERVICE_DISPLAYNAME_MAX_LEN 128
72 
73 /**
74  * @brief Indicates the maximum length of the customData data string in <b>ServiceInfo</b>.
75  *
76  * @since 6.0
77  * @version 1.0
78  */
79 #define DISC_SERVICE_CUSTOMDATA_MAX_LEN 512
80 
81 /**
82  * @brief Indicates the maximum length of the customData data string in <b>DiscoveryInfo</b>.
83  *
84  * @since 6.0
85  * @version 1.0
86  */
87 #define DISC_SERVICE_REQUEST_CUSTOMDATA_MAX_LEN 10
88 
89 /**
90  * @brief Enumerates different media used for publishing services.
91  *
92  * @since 6.0
93  * @version 1.0
94  */
95 typedef enum {
96     SERVICE_MEDIUM_TYPE_AUTO,        // All supported media will be called automatically
97     SERVICE_MEDIUM_TYPE_BLE,         // Bluetooth
98     SERVICE_MEDIUM_TYPE_BLE_TRIGGER, // Bluetooth triggered
99     SERVICE_MEDIUM_TYPE_MDNS,        // mDNS
100     SERVICE_MEDIUM_TYPE_BUTT,
101 } ServiceMediumType;
102 
103 /**
104  * @brief Enumerates the modes in which services are published and discovered.
105  *
106  * @since 6.0
107  * @version 1.0
108  */
109 typedef enum  {
110     /* Passive */
111     SERVICE_DISCOVER_MODE_PASSIVE = 0x15,
112     /* Active */
113     SERVICE_DISCOVER_MODE_ACTIVE = 0x25
114 } ServiceDiscoverMode;
115 
116 /**
117  * @brief Enumerates frequencies for Bluetooth Scanner.
118  *
119  * @since 6.0
120  * @version 1.0
121  */
122 typedef enum {
123     FREQ_LOW,                   // Scan duty cycle is 2%
124     FREQ_MID,                   // Scan duty cycle is 10%
125     FREQ_HIGH,                  // Scan duty cycle is 25%
126     FREQ_SUPER_HIGH,            // Scan duty cycle is 50%
127     FREQ_ALMOST_EXTREMELY_HIGH, // Scan duty cycle is 75%
128     FREQ_EXTREMELY_HIGH,        // Scan duty cycle is 100%
129     FREQ_VALUE_BUTT
130 } EnableFreq;
131 
132 /**
133  * @brief Defines the service information returned by <b>IServiceDiscoveryCb</b>.
134  *
135  * @since 6.0
136  * @version 1.0
137  */
138 typedef struct {
139     /* Service ID */
140     int64_t serviceId;
141     /* Service type: must be c-string format, end with '\0', 1-15 characters in length.*/
142     char serviceType[DISC_SERVICE_TYPE_MAX_LEN];
143     /* Service name to be registered: must be c-string format, end with '\0', 0-64 characters in length */
144     char serviceName[DISC_SERVICE_NAME_MAX_LEN];
145     /* Service name to be displayed: must be c-string format, end with '\0', 7-128 bytes in length */
146     char serviceDisplayName[DISC_SERVICE_DISPLAYNAME_MAX_LEN];
147     /* Custom data for service: must be c-string format, end with '\0', 0-512 bytes in length */
148     unsigned char customData[DISC_SERVICE_CUSTOMDATA_MAX_LEN];
149     /* Length of custom data */
150     unsigned int dataLen;
151 } ServiceInfo;
152 
153 /**
154  * @brief Defines the service publishing and discovery parameters.
155  *
156  * @since 6.0
157  * @version 1.0
158  */
159 typedef struct {
160     /* The media on which to register the service */
161     ServiceMediumType media;
162     /* The publishing and discovery mode */
163     ServiceDiscoverMode mode;
164     /* The publishing frequency */
165     EnableFreq freq;
166 } ServiceDiscoveryParam;
167 
168 /**
169  * @brief Defines the service discovery information.
170  *
171  * @since 6.0
172  * @version 1.0
173  */
174 typedef struct {
175     /* Local service ID generated by device manager */
176     int64_t localServiceId;
177     /* The service type must be a short text string, 1-15 characters in length */
178     char serviceType[DISC_SERVICE_TYPE_MAX_LEN];
179     /* Request Custom data for service discovery, 0-9 bytes in length */
180     unsigned char reqCustomData[DISC_SERVICE_REQUEST_CUSTOMDATA_MAX_LEN];
181     /* Length of request custom data */
182     unsigned int dataLen;
183 } DiscoveryInfo;
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif
190