• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2023 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 #ifndef NSTACKX_H
17 #define NSTACKX_H
18 
19 #include <stdbool.h>
20 #include <stddef.h>
21 #include <stdint.h>
22 #include "nstackx_struct.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Register local device information */
29 DFINDER_EXPORT int32_t NSTACKX_RegisterDevice(const NSTACKX_LocalDeviceInfo *localDeviceInfo);
30 
31 /* Register local device name */
32 DFINDER_EXPORT int32_t NSTACKX_RegisterDeviceName(const char *devName);
33 
34 /* Register local device information with deviceHash */
35 DFINDER_EXPORT int32_t NSTACKX_RegisterDeviceAn(const NSTACKX_LocalDeviceInfo *localDeviceInfo, uint64_t deviceHash);
36 
37 /* New interface to register local device with multiple interfaces */
38 DFINDER_EXPORT int32_t NSTACKX_RegisterDeviceV2(const NSTACKX_LocalDeviceInfoV2 *localDeviceInfo);
39 
40 DFINDER_EXPORT int NSTACKX_DFinderSetEventFunc(void *softobj, DFinderEventFunc func);
41 
42 DFINDER_EXPORT int NSTACKX_DFinderDump(const char **argv, uint32_t argc, void *softObj, DFinderDumpFunc dump);
43 
44 /*
45  * NSTACKX Initialization
46  * return 0 on success, negative value on failure
47  */
48 DFINDER_EXPORT int32_t NSTACKX_Init(const NSTACKX_Parameter *parameter);
49 
50 /*
51  * NSTACKX Initialization V2
52  * support notify device info one by one
53  * return 0 on success, negative value on failure
54  */
55 DFINDER_EXPORT int32_t NSTACKX_InitV2(const NSTACKX_Parameter *parameter, bool isNotifyPerDevice);
56 
57 /* NSTACKX Destruction */
58 DFINDER_EXPORT void NSTACKX_Deinit(void);
59 
60 /*
61  * NSTACKX thread Initialization
62  * return 0 on success, negative value on failure
63  */
64 DFINDER_EXPORT int32_t NSTACKX_ThreadInit(void);
65 
66 /* NSTACKX thread Destruction */
67 DFINDER_EXPORT void NSTACKX_ThreadDeinit(void);
68 
69 /*
70  * Start device discovery
71  * return 0 on success, negative value on failure
72  */
73 DFINDER_EXPORT int32_t NSTACKX_StartDeviceFind(void);
74 
75 /*
76  * Start device discovery by mode
77  * return 0 on success, negative value on failure
78  */
79 DFINDER_EXPORT int32_t NSTACKX_StartDeviceFindAn(uint8_t mode);
80 
81 /*
82  * Stop device discovery
83  * return 0 on success, negative value on failure
84  */
85 DFINDER_EXPORT int32_t NSTACKX_StopDeviceFind(void);
86 
87 /*
88  * subscribe module
89  * return 0 on success, negative value on failure
90  */
91 DFINDER_EXPORT int32_t NSTACKX_SubscribeModule(void);
92 
93 /*
94  * unsubscribe module
95  * return 0 on success, negative value on failure
96  */
97 DFINDER_EXPORT int32_t NSTACKX_UnsubscribeModule(void);
98 
99 /*
100  * Register the device hash of local device.
101  * return 0 on success, negative value on failure
102  */
103 DFINDER_EXPORT int32_t NSTACKX_RegisterDeviceHash(uint64_t deviceHash);
104 
105 /*
106  * Register the serviceData of local device.
107  * return 0 on success, negative value on failure
108  */
109 DFINDER_EXPORT int32_t NSTACKX_RegisterServiceDataV2(const struct NSTACKX_ServiceData *param, uint32_t cnt);
110 
111 /*
112  * Register the capability of local device.
113  * return 0 on success, negative value on failure
114  */
115 DFINDER_EXPORT int32_t NSTACKX_RegisterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]);
116 
117 /*
118  * Set the capability to filter remote devices.
119  * return 0 on success, negative value on failure
120  */
121 DFINDER_EXPORT int32_t NSTACKX_SetFilterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]);
122 
123 /*
124  * Set the agingTime of the device list.
125  * The unit of agingTime is seconds, and the range is 1 to 10 seconds.
126  */
127 DFINDER_EXPORT int32_t NSTACKX_SetDeviceListAgingTime(uint32_t agingTime);
128 
129 /*
130  * Set the size of the device list.
131  * The range is 20 to 400.
132  */
133 DFINDER_EXPORT int32_t NSTACKX_SetMaxDeviceNum(uint32_t maxDeviceNum);
134 
135 /*
136  * dfinder set screen status
137  * param: isScreenOn, screen status
138  * return: always return 0 on success
139  */
140 DFINDER_EXPORT int32_t NSTACKX_ScreenStatusChange(bool isScreenOn);
141 
142 /*
143  * Register the serviceData of local device.
144  * return 0 on success, negative value on failure
145  */
146 DFINDER_EXPORT int32_t NSTACKX_RegisterServiceData(const char *serviceData);
147 
148 /**
149  * @brief register business data to local device, the data will be used as bData filed in json format in coap payload
150  *
151  * @param [in] (const char *) businessData: specific data which need to be put into the coap payload
152  *
153  * @return (int32_t)
154  *      0                operation success
155  *      negative value   a number indicating the rough cause of this failure
156  *
157  * @note 1. the length of businessData should be less than NSTACKX_MAX_BUSINESS_DATA_LEN
158  *       2. the registered business data will only be used in unicast which is confusing
159  *       3. this interface will be DEPRECATED soon, in some special case, you can replace it with:
160  *          NSTACKX_StartDeviceDiscovery && NSTACKX_SendDiscoveryRsp
161  *
162  * @exception
163  */
164 DFINDER_EXPORT int32_t NSTACKX_RegisterBusinessData(const char *businessData);
165 
166 /*
167  * Register the extendServiceData of local device.
168  * return 0 on success, negative value on failure
169  */
170 DFINDER_EXPORT int32_t NSTACKX_RegisterExtendServiceData(const char *extendServiceData);
171 
172 /*
173  * Send Msg to remote peer
174  * return 0 on success, negative value on failure
175  */
176 DFINDER_EXPORT int32_t NSTACKX_SendMsg(const char *moduleName, const char *deviceId, const uint8_t *data,
177                                        uint32_t len);
178 
179 /*
180  * Send Msg to remote peer
181  * return 0 on success, negative value on failure
182  */
183 DFINDER_EXPORT int32_t NSTACKX_SendMsgDirect(const char *moduleName, const char *deviceId, const uint8_t *data,
184     uint32_t len, const char *ipaddr, uint8_t sendType);
185 
186 /*
187  * Get device list from cache
188  * param: deviceList - Device list return from NSTACKX, user should prepare sufficient buffer to store
189  *                     device list.
190  * param: deviceCountPtr - In/Out parameter. It indicates buffer size (number of elements) in deviceList
191  *                         When returns, it indicates numbers of valid device in deviceList.
192  * return 0 on success, negative value on failure
193  */
194 DFINDER_EXPORT int32_t NSTACKX_GetDeviceList(NSTACKX_DeviceInfo *deviceList, uint32_t *deviceCountPtr);
195 
196 /*
197  * NSTACKX Initialization, only used for restart.
198  * return 0 on success, negative value on failure
199  */
200 DFINDER_EXPORT int32_t NSTACKX_InitRestart(const NSTACKX_Parameter *parameter);
201 
202 /*
203  * NSTACKX Initialization, only used for restart.
204  * return 0 on success, negative value on failure
205  */
206 DFINDER_EXPORT void NSTACKX_StartDeviceFindRestart(void);
207 
208 /**
209  * @brief start device find with configurable parameters
210  *
211  * @param [in] (const NSTACKX_DiscoverySettings *) discoverySettings: configurable discovery properties
212  *
213  * @return (int32_t)
214  *      0                operation success
215  *      negative value   a number indicating the rough cause of this failure
216  *
217  * @note 1. if the discovery is already running, calling this interface will stop the previous one and start a new one
218  *       2. if both advertiseCount and advertiseDuration in discoverySettings are zero, the discovery interval will
219  *          fallback to 5 sec 12 times(100 ms, 200, 200, 300...)
220  *       3. if advertiseCount is not zero, the broadcast interval equals advertiseDuration / advertiseCount
221  *
222  * @exception
223  */
224 DFINDER_EXPORT int32_t NSTACKX_StartDeviceDiscovery(const NSTACKX_DiscoverySettings *discoverySettings);
225 
226 /*
227  * Start device discovery with configured broadcast interval and other settings
228  * return 0 on success, negative value on failure
229  */
230 DFINDER_EXPORT int32_t NSTACKX_StartDeviceDiscoveryWithConfig(const DFinderDiscConfig *discConfig);
231 
232 /**
233  * @brief reply unicast to remote device specified by remoteIp, using local nic specified by localNetworkName
234  *
235  * @param [in] (const NSTACKX_ResponseSettings *) responseSettings: configurable unicast reply properties
236  *
237  * @return (int32_t)
238  *      0                operation success
239  *      negative value   a number indicating the rough cause of this failure
240  *
241  * @note only one unicast reply will be sent each time this interface is called
242  *
243  * @exception
244  */
245 DFINDER_EXPORT int32_t NSTACKX_SendDiscoveryRsp(const NSTACKX_ResponseSettings *responseSettings);
246 
247 /**
248  * @brief start sending broadcast notifications
249  *
250  * @param [in] config: configurable properties to send notification, see struct NSTACKX_NotificationConfig
251  *
252  * @return (int32_t)
253  *      0                operation success
254  *      negative value   a number indicating the rough cause of this failure
255  *
256  * @note 1. if the sending is already running, calling this interface will stop the previous one and start a new one,
257  *          caller can update its notification msg through this way
258  *       2. caller should ensure the consistency of associated data
259  * @exception
260  */
261 DFINDER_EXPORT int32_t NSTACKX_SendNotification(const NSTACKX_NotificationConfig *config);
262 
263 /**
264  * @brief stop sending broadcast notifications
265  *
266  * @param [in] businessType: service identify, notification of which business we should stop
267  *
268  * @return (int32_t)
269  *      0                operation success
270  *      negative value   a number indicating the rough cause of this failure
271  *
272  * @note 1. calling this interface will stop the sending timer
273  *       2. if not business sensitive, should use NSTACKX_BUSINESS_TYPE_NULL, see struct NSTACKX_BusinessType
274  *
275  * @exception
276  */
277 DFINDER_EXPORT int32_t NSTACKX_StopSendNotification(uint8_t businessType);
278 
279 #ifdef ENABLE_USER_LOG
280 
281 /*
282  * Set the DFinder log implementation
283  */
284 DFINDER_EXPORT int32_t NSTACKX_DFinderRegisterLog(DFinderLogCallback userLogCallback);
285 #endif
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif /* NSTACKX_H */
292