1060ff233Sopenharmony_ci/* 2060ff233Sopenharmony_ci * Copyright (C) 2021-2023 Huawei Device Co., Ltd. 3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License. 5060ff233Sopenharmony_ci * You may obtain a copy of the License at 6060ff233Sopenharmony_ci * 7060ff233Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8060ff233Sopenharmony_ci * 9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and 13060ff233Sopenharmony_ci * limitations under the License. 14060ff233Sopenharmony_ci */ 15060ff233Sopenharmony_ci 16060ff233Sopenharmony_ci#ifndef NSTACKX_H 17060ff233Sopenharmony_ci#define NSTACKX_H 18060ff233Sopenharmony_ci 19060ff233Sopenharmony_ci#include <stdbool.h> 20060ff233Sopenharmony_ci#include <stddef.h> 21060ff233Sopenharmony_ci#include <stdint.h> 22060ff233Sopenharmony_ci 23060ff233Sopenharmony_ci#ifdef __cplusplus 24060ff233Sopenharmony_ciextern "C" { 25060ff233Sopenharmony_ci#endif 26060ff233Sopenharmony_ci 27060ff233Sopenharmony_ci#define NSTACKX_MAX_DEVICE_NAME_LEN 64 28060ff233Sopenharmony_ci#define NSTACKX_MAX_MODULE_NAME_LEN 64 29060ff233Sopenharmony_ci#define NSTACKX_MAX_DEVICE_ID_LEN 96 30060ff233Sopenharmony_ci#define NSTACKX_MAX_SENDMSG_DATA_LEN 512 31060ff233Sopenharmony_ci#define NSTACKX_MAX_MAC_STRING_LEN 18 32060ff233Sopenharmony_ci#define NSTACKX_MAX_IP_STRING_LEN 16 33060ff233Sopenharmony_ci#define NSTACKX_MAX_CAPABILITY_NUM 2 34060ff233Sopenharmony_ci#define NSTACKX_MAX_INTERFACE_NAME_LEN 16 35060ff233Sopenharmony_ci#define NSTACKX_MAX_SERVICE_DATA_LEN 64 36060ff233Sopenharmony_ci#define NSTACKX_MAX_EXTEND_SERVICE_DATA_LEN 128 37060ff233Sopenharmony_ci#ifndef NSTACKX_EXTEND_BUSINESSDATA 38060ff233Sopenharmony_ci#define NSTACKX_MAX_BUSINESS_DATA_LEN 1 39060ff233Sopenharmony_ci#else 40060ff233Sopenharmony_ci#define NSTACKX_MAX_BUSINESS_DATA_LEN 300 41060ff233Sopenharmony_ci#endif 42060ff233Sopenharmony_ci#define NSTACKX_MAX_NOTIFICATION_DATA_LEN 800 43060ff233Sopenharmony_ci 44060ff233Sopenharmony_ci#ifdef DFINDER_SAVE_DEVICE_LIST 45060ff233Sopenharmony_ci#define NSTACKX_MIN_DEVICE_NUM 1 46060ff233Sopenharmony_ci#define NSTACKX_DEFAULT_DEVICE_NUM 20 47060ff233Sopenharmony_ci#define NSTACKX_MAX_DEVICE_NUM 400 48060ff233Sopenharmony_ci#define NSTACKX_DEFAULT_AGING_TIME 1 49060ff233Sopenharmony_ci#define NSTACKX_MIN_AGING_TIME 1 50060ff233Sopenharmony_ci#define NSTACKX_MAX_AGING_TIME 10 51060ff233Sopenharmony_ci#else 52060ff233Sopenharmony_ci#define NSTACKX_MAX_DEVICE_NUM 1 53060ff233Sopenharmony_ci#endif 54060ff233Sopenharmony_ci 55060ff233Sopenharmony_ci// expand from 131 to 219 (+88) bytes to hold service data 56060ff233Sopenharmony_ci// expand from 219 to 400 (+128 +53) bytes to hold extend service data 57060ff233Sopenharmony_ci// expand from 400 to (420 + NSTACKX_MAX_BUSINESS_DATA_LEN) bytes to hold business data and type 58060ff233Sopenharmony_ci#define NSTACKX_MAX_RESERVED_INFO_LEN (420 + NSTACKX_MAX_BUSINESS_DATA_LEN) 59060ff233Sopenharmony_ci 60060ff233Sopenharmony_ci#define DEVICE_HASH_LEN 21 61060ff233Sopenharmony_cienum { 62060ff233Sopenharmony_ci DEFAULT_MODE = 0, 63060ff233Sopenharmony_ci DISCOVER_MODE = 1, 64060ff233Sopenharmony_ci PUBLISH_MODE_UPLINE = 2, 65060ff233Sopenharmony_ci PUBLISH_MODE_OFFLINE = 3, 66060ff233Sopenharmony_ci PUBLISH_MODE_PROACTIVE = 10 67060ff233Sopenharmony_ci}; // discovery mode 68060ff233Sopenharmony_ci#define PUBLISH_DEVICE_NUM 1 69060ff233Sopenharmony_ci#define INNER_DISCOVERY 1 70060ff233Sopenharmony_ci#define PUBLISH_NUM 1 71060ff233Sopenharmony_ci#define COUNT_INIT 0 72060ff233Sopenharmony_ci 73060ff233Sopenharmony_cienum { 74060ff233Sopenharmony_ci NSTACKX_DISCOVERY_TYPE_PASSIVE = 1, 75060ff233Sopenharmony_ci NSTACKX_DISCOVERY_TYPE_ACTIVE = 2 76060ff233Sopenharmony_ci}; 77060ff233Sopenharmony_ci 78060ff233Sopenharmony_ci#ifndef DFINDER_EXPORT 79060ff233Sopenharmony_ci#ifdef _WIN32 80060ff233Sopenharmony_ci#define DFINDER_EXPORT __declspec(dllexport) 81060ff233Sopenharmony_ci#else 82060ff233Sopenharmony_ci#define DFINDER_EXPORT 83060ff233Sopenharmony_ci#endif 84060ff233Sopenharmony_ci#endif 85060ff233Sopenharmony_ci 86060ff233Sopenharmony_ci/* Remote device information */ 87060ff233Sopenharmony_citypedef struct NSTACKX_DeviceInfo { 88060ff233Sopenharmony_ci char deviceId[NSTACKX_MAX_DEVICE_ID_LEN]; 89060ff233Sopenharmony_ci char deviceName[NSTACKX_MAX_DEVICE_NAME_LEN]; 90060ff233Sopenharmony_ci uint32_t capabilityBitmapNum; 91060ff233Sopenharmony_ci uint32_t capabilityBitmap[NSTACKX_MAX_CAPABILITY_NUM]; 92060ff233Sopenharmony_ci uint32_t deviceType; 93060ff233Sopenharmony_ci uint8_t mode; 94060ff233Sopenharmony_ci uint8_t update : 1; 95060ff233Sopenharmony_ci uint8_t reserved : 7; 96060ff233Sopenharmony_ci char networkName[NSTACKX_MAX_INTERFACE_NAME_LEN]; 97060ff233Sopenharmony_ci uint8_t discoveryType; 98060ff233Sopenharmony_ci uint8_t businessType; 99060ff233Sopenharmony_ci char reservedInfo[NSTACKX_MAX_RESERVED_INFO_LEN]; 100060ff233Sopenharmony_ci} NSTACKX_DeviceInfo; 101060ff233Sopenharmony_ci 102060ff233Sopenharmony_ci#define NSTACKX_MAX_LISTENED_NIF_NUM 2 103060ff233Sopenharmony_ci 104060ff233Sopenharmony_citypedef struct { 105060ff233Sopenharmony_ci char networkName[NSTACKX_MAX_INTERFACE_NAME_LEN]; 106060ff233Sopenharmony_ci char networkIpAddr[NSTACKX_MAX_IP_STRING_LEN]; 107060ff233Sopenharmony_ci} NSTACKX_InterfaceInfo; 108060ff233Sopenharmony_ci 109060ff233Sopenharmony_ci 110060ff233Sopenharmony_ci/* Local device information */ 111060ff233Sopenharmony_citypedef struct { 112060ff233Sopenharmony_ci char name[NSTACKX_MAX_DEVICE_NAME_LEN]; 113060ff233Sopenharmony_ci char deviceId[NSTACKX_MAX_DEVICE_ID_LEN]; 114060ff233Sopenharmony_ci char btMacAddr[NSTACKX_MAX_MAC_STRING_LEN]; 115060ff233Sopenharmony_ci char wifiMacAddr[NSTACKX_MAX_MAC_STRING_LEN]; 116060ff233Sopenharmony_ci 117060ff233Sopenharmony_ci /* Configuration for network interface */ 118060ff233Sopenharmony_ci NSTACKX_InterfaceInfo localIfInfo[NSTACKX_MAX_LISTENED_NIF_NUM]; 119060ff233Sopenharmony_ci uint8_t ifNums; 120060ff233Sopenharmony_ci 121060ff233Sopenharmony_ci /* Obsoleted. Use localIfInfo instead. */ 122060ff233Sopenharmony_ci char networkIpAddr[NSTACKX_MAX_IP_STRING_LEN]; 123060ff233Sopenharmony_ci /* Obsoleted. Use localIfInfo instead. */ 124060ff233Sopenharmony_ci char networkName[NSTACKX_MAX_INTERFACE_NAME_LEN]; 125060ff233Sopenharmony_ci uint8_t is5GHzBandSupported; 126060ff233Sopenharmony_ci uint8_t businessType; 127060ff233Sopenharmony_ci uint32_t deviceType; 128060ff233Sopenharmony_ci} NSTACKX_LocalDeviceInfo; 129060ff233Sopenharmony_ci 130060ff233Sopenharmony_citypedef enum { 131060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_NULL = 0, /* if not set business type, type null will be used as default choice */ 132060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_HICOM = 1, /* designed for hicom, but not used currently */ 133060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_SOFTBUS = 2, /* designed for softbus-mineharmony to implement some customized features */ 134060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_NEARBY = 3, /* designed to handle the interaction between two nearby service */ 135060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_AUTONET = 4, /* designed for softbus-autonet to implement some customized features */ 136060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_STRATEGY = 5, /* designed for softbus-strategy to report disc result in different rounds */ 137060ff233Sopenharmony_ci NSTACKX_BUSINESS_TYPE_MAX /* for parameter legality verification */ 138060ff233Sopenharmony_ci} NSTACKX_BusinessType; 139060ff233Sopenharmony_ci 140060ff233Sopenharmony_ci#define NSTACKX_MIN_ADVERTISE_COUNT 1 141060ff233Sopenharmony_ci#define NSTACKX_MAX_ADVERTISE_COUNT 100 142060ff233Sopenharmony_ci/* The unit is ms. */ 143060ff233Sopenharmony_ci#define NSTACKX_MIN_ADVERTISE_DURATION 5000 144060ff233Sopenharmony_ci#define NSTACKX_MAX_ADVERTISE_DURATION 50000 145060ff233Sopenharmony_ci#define NSTACKX_MIN_ADVERTISE_INTERVAL 10 146060ff233Sopenharmony_ci#define NSTACKX_MAX_ADVERTISE_INTERVAL 10000 147060ff233Sopenharmony_ci 148060ff233Sopenharmony_citypedef struct { 149060ff233Sopenharmony_ci uint8_t businessType; /* service identify */ 150060ff233Sopenharmony_ci uint8_t discoveryMode; /* discovery mode, e.g. PUBLISH_MODE_PROACTIVE */ 151060ff233Sopenharmony_ci uint32_t advertiseCount; /* the number of broadcasts to be sent */ 152060ff233Sopenharmony_ci uint32_t advertiseDuration; /* duration of discovery this time */ 153060ff233Sopenharmony_ci uint32_t length; /* the length of business data, include '\0' */ 154060ff233Sopenharmony_ci char *businessData; /* business data in broadcast: {"bData":"xxx"} */ 155060ff233Sopenharmony_ci} NSTACKX_DiscoverySettings; 156060ff233Sopenharmony_ci 157060ff233Sopenharmony_citypedef struct { 158060ff233Sopenharmony_ci uint8_t businessType; 159060ff233Sopenharmony_ci uint8_t discoveryMode; 160060ff233Sopenharmony_ci uint32_t intervalArrLen; 161060ff233Sopenharmony_ci uint32_t *bcastInterval; 162060ff233Sopenharmony_ci uint32_t businessDataLen; 163060ff233Sopenharmony_ci char *businessData; 164060ff233Sopenharmony_ci} DFinderDiscConfig; 165060ff233Sopenharmony_ci 166060ff233Sopenharmony_citypedef struct { 167060ff233Sopenharmony_ci const char *name; 168060ff233Sopenharmony_ci const char *deviceId; 169060ff233Sopenharmony_ci const NSTACKX_InterfaceInfo *localIfInfo; 170060ff233Sopenharmony_ci uint32_t ifNums; 171060ff233Sopenharmony_ci uint32_t deviceType; 172060ff233Sopenharmony_ci uint64_t deviceHash; 173060ff233Sopenharmony_ci bool hasDeviceHash; 174060ff233Sopenharmony_ci uint8_t businessType; 175060ff233Sopenharmony_ci} NSTACKX_LocalDeviceInfoV2; 176060ff233Sopenharmony_ci 177060ff233Sopenharmony_ci/* Register local device information */ 178060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterDevice(const NSTACKX_LocalDeviceInfo *localDeviceInfo); 179060ff233Sopenharmony_ci 180060ff233Sopenharmony_ci/* Register local device name */ 181060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterDeviceName(const char *devName); 182060ff233Sopenharmony_ci 183060ff233Sopenharmony_ci/* Register local device information with deviceHash */ 184060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterDeviceAn(const NSTACKX_LocalDeviceInfo *localDeviceInfo, uint64_t deviceHash); 185060ff233Sopenharmony_ci 186060ff233Sopenharmony_ci/* New interface to register local device with multiple interfaces */ 187060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterDeviceV2(const NSTACKX_LocalDeviceInfoV2 *localDeviceInfo); 188060ff233Sopenharmony_ci 189060ff233Sopenharmony_ci/* Device list change callback type */ 190060ff233Sopenharmony_citypedef void (*NSTACKX_OnDeviceListChanged)(const NSTACKX_DeviceInfo *deviceList, uint32_t deviceCount); 191060ff233Sopenharmony_ci 192060ff233Sopenharmony_citypedef void (*NSTACKX_OnMsgReceived)(const char *moduleName, const char *deviceId, 193060ff233Sopenharmony_ci const uint8_t *data, uint32_t len, const char *srcIp); /* Data receive callback type */ 194060ff233Sopenharmony_ci 195060ff233Sopenharmony_ci/* DFinder message type list. */ 196060ff233Sopenharmony_citypedef enum { 197060ff233Sopenharmony_ci DFINDER_ON_TOO_BUSY = 1, 198060ff233Sopenharmony_ci DFINDER_ON_INNER_ERROR, 199060ff233Sopenharmony_ci DFINDER_ON_TOO_MANY_DEVICE, 200060ff233Sopenharmony_ci} DFinderMsgType; 201060ff233Sopenharmony_ci 202060ff233Sopenharmony_ci/* store the notification config, used with interface: NSTACKX_SendNotification */ 203060ff233Sopenharmony_citypedef struct { 204060ff233Sopenharmony_ci char *msg; /* notification data in json format */ 205060ff233Sopenharmony_ci size_t msgLen; /* strlen of notification data */ 206060ff233Sopenharmony_ci uint16_t *intervalsMs; /* pointer to intervals to send notification, first element should be 0 */ 207060ff233Sopenharmony_ci uint8_t intervalLen; /* configured number of intervals */ 208060ff233Sopenharmony_ci uint8_t businessType; /* service identify, see enum NSTACKX_BusinessType */ 209060ff233Sopenharmony_ci} NSTACKX_NotificationConfig; 210060ff233Sopenharmony_ci 211060ff233Sopenharmony_ci/* Data receive callback type */ 212060ff233Sopenharmony_citypedef void (*NSTACKX_OnDFinderMsgReceived)(DFinderMsgType msgType); 213060ff233Sopenharmony_ci 214060ff233Sopenharmony_ci/** 215060ff233Sopenharmony_ci * @brief define function pointer type, used to report the notification data received 216060ff233Sopenharmony_ci * 217060ff233Sopenharmony_ci * @param [out] element: notification data to report, see struct NSTACKX_NotificationConfig 218060ff233Sopenharmony_ci */ 219060ff233Sopenharmony_citypedef void (*NSTACKX_OnNotificationReceived)(const NSTACKX_NotificationConfig *notification); 220060ff233Sopenharmony_ci 221060ff233Sopenharmony_ci/* NSTACKX parameter, which contains callback list */ 222060ff233Sopenharmony_citypedef struct { 223060ff233Sopenharmony_ci NSTACKX_OnDeviceListChanged onDeviceListChanged; 224060ff233Sopenharmony_ci NSTACKX_OnDeviceListChanged onDeviceFound; 225060ff233Sopenharmony_ci NSTACKX_OnMsgReceived onMsgReceived; 226060ff233Sopenharmony_ci NSTACKX_OnDFinderMsgReceived onDFinderMsgReceived; 227060ff233Sopenharmony_ci NSTACKX_OnNotificationReceived onNotificationReceived; 228060ff233Sopenharmony_ci uint32_t maxDeviceNum; // the size of the device list configured by the caller 229060ff233Sopenharmony_ci} NSTACKX_Parameter; 230060ff233Sopenharmony_ci 231060ff233Sopenharmony_ci/* DFinder log level */ 232060ff233Sopenharmony_cienum { 233060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_OFF = 0, 234060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_FATAL = 1, 235060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_ERROR = 2, 236060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_WARNING = 3, 237060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_INFO = 4, 238060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_DEBUG = 5, 239060ff233Sopenharmony_ci DFINDER_LOG_LEVEL_END, 240060ff233Sopenharmony_ci}; 241060ff233Sopenharmony_ci 242060ff233Sopenharmony_citypedef enum { 243060ff233Sopenharmony_ci DFINDER_EVENT_TYPE_FAULT, 244060ff233Sopenharmony_ci DFINDER_EVENT_TYPE_STATISTIC, 245060ff233Sopenharmony_ci DFINDER_EVENT_TYPE_SECURITY, 246060ff233Sopenharmony_ci DFINDER_EVENT_TYPE_BEHAVIOR, 247060ff233Sopenharmony_ci} DFinderEventType; 248060ff233Sopenharmony_ci 249060ff233Sopenharmony_citypedef enum { 250060ff233Sopenharmony_ci DFINDER_EVENT_LEVEL_CRITICAL, 251060ff233Sopenharmony_ci DFINDER_EVENT_LEVEL_MINOR, 252060ff233Sopenharmony_ci} DFinderEventLevel; 253060ff233Sopenharmony_ci 254060ff233Sopenharmony_citypedef enum { 255060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_BOOL, 256060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_UINT8, 257060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_UINT16, 258060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_INT32, 259060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_UINT32, 260060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_UINT64, 261060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_FLOAT, 262060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_DOUBLE, 263060ff233Sopenharmony_ci DFINDER_PARAM_TYPE_STRING, 264060ff233Sopenharmony_ci} DFinderEventParamType; 265060ff233Sopenharmony_ci 266060ff233Sopenharmony_ci#define DFINDER_EVENT_NAME_LEN 32 267060ff233Sopenharmony_ci#define DFINDER_EVENT_TAG_LEN 16 268060ff233Sopenharmony_ci 269060ff233Sopenharmony_citypedef struct { 270060ff233Sopenharmony_ci DFinderEventParamType type; 271060ff233Sopenharmony_ci char name[DFINDER_EVENT_NAME_LEN]; 272060ff233Sopenharmony_ci union { 273060ff233Sopenharmony_ci bool b; 274060ff233Sopenharmony_ci uint8_t u8v; 275060ff233Sopenharmony_ci uint16_t u16v; 276060ff233Sopenharmony_ci int32_t i32v; 277060ff233Sopenharmony_ci uint32_t u32v; 278060ff233Sopenharmony_ci uint64_t u64v; 279060ff233Sopenharmony_ci float f; 280060ff233Sopenharmony_ci double d; 281060ff233Sopenharmony_ci char str[DFINDER_EVENT_NAME_LEN]; 282060ff233Sopenharmony_ci } value; 283060ff233Sopenharmony_ci} DFinderEventParam; 284060ff233Sopenharmony_ci 285060ff233Sopenharmony_citypedef struct { 286060ff233Sopenharmony_ci char eventName[DFINDER_EVENT_NAME_LEN]; 287060ff233Sopenharmony_ci DFinderEventType type; 288060ff233Sopenharmony_ci DFinderEventLevel level; 289060ff233Sopenharmony_ci char tag[DFINDER_EVENT_TAG_LEN]; 290060ff233Sopenharmony_ci char desc[DFINDER_EVENT_NAME_LEN]; 291060ff233Sopenharmony_ci DFinderEventParam *params; 292060ff233Sopenharmony_ci uint32_t paramNum; 293060ff233Sopenharmony_ci} DFinderEvent; 294060ff233Sopenharmony_ci 295060ff233Sopenharmony_citypedef void (*DFinderEventFunc)(void *softObj, const DFinderEvent *info); 296060ff233Sopenharmony_ci 297060ff233Sopenharmony_ciDFINDER_EXPORT int NSTACKX_DFinderSetEventFunc(void *softobj, DFinderEventFunc func); 298060ff233Sopenharmony_ci 299060ff233Sopenharmony_citypedef void (*DFinderDumpFunc)(void *softObj, const char *data, uint32_t len); 300060ff233Sopenharmony_ciDFINDER_EXPORT int NSTACKX_DFinderDump(const char **argv, uint32_t argc, void *softObj, DFinderDumpFunc dump); 301060ff233Sopenharmony_ci 302060ff233Sopenharmony_ci/* 303060ff233Sopenharmony_ci * NSTACKX Initialization 304060ff233Sopenharmony_ci * return 0 on success, negative value on failure 305060ff233Sopenharmony_ci */ 306060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_Init(const NSTACKX_Parameter *parameter); 307060ff233Sopenharmony_ci 308060ff233Sopenharmony_ci/* 309060ff233Sopenharmony_ci * NSTACKX Initialization V2 310060ff233Sopenharmony_ci * support notify device info one by one 311060ff233Sopenharmony_ci * return 0 on success, negative value on failure 312060ff233Sopenharmony_ci */ 313060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_InitV2(const NSTACKX_Parameter *parameter, bool isNotifyPerDevice); 314060ff233Sopenharmony_ci 315060ff233Sopenharmony_ci/* NSTACKX Destruction */ 316060ff233Sopenharmony_ciDFINDER_EXPORT void NSTACKX_Deinit(void); 317060ff233Sopenharmony_ci 318060ff233Sopenharmony_ci/* 319060ff233Sopenharmony_ci * Start device discovery 320060ff233Sopenharmony_ci * return 0 on success, negative value on failure 321060ff233Sopenharmony_ci */ 322060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_StartDeviceFind(void); 323060ff233Sopenharmony_ci 324060ff233Sopenharmony_ci/* 325060ff233Sopenharmony_ci * Start device discovery by mode 326060ff233Sopenharmony_ci * return 0 on success, negative value on failure 327060ff233Sopenharmony_ci */ 328060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_StartDeviceFindAn(uint8_t mode); 329060ff233Sopenharmony_ci 330060ff233Sopenharmony_ci/* 331060ff233Sopenharmony_ci * Stop device discovery 332060ff233Sopenharmony_ci * return 0 on success, negative value on failure 333060ff233Sopenharmony_ci */ 334060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_StopDeviceFind(void); 335060ff233Sopenharmony_ci 336060ff233Sopenharmony_ci/* 337060ff233Sopenharmony_ci * subscribe module 338060ff233Sopenharmony_ci * return 0 on success, negative value on failure 339060ff233Sopenharmony_ci */ 340060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SubscribeModule(void); 341060ff233Sopenharmony_ci 342060ff233Sopenharmony_ci/* 343060ff233Sopenharmony_ci * unsubscribe module 344060ff233Sopenharmony_ci * return 0 on success, negative value on failure 345060ff233Sopenharmony_ci */ 346060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_UnsubscribeModule(void); 347060ff233Sopenharmony_ci 348060ff233Sopenharmony_ci/* 349060ff233Sopenharmony_ci * Register the capability of local device. 350060ff233Sopenharmony_ci * return 0 on success, negative value on failure 351060ff233Sopenharmony_ci */ 352060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]); 353060ff233Sopenharmony_ci 354060ff233Sopenharmony_ci/* 355060ff233Sopenharmony_ci * Set the capability to filter remote devices. 356060ff233Sopenharmony_ci * return 0 on success, negative value on failure 357060ff233Sopenharmony_ci */ 358060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SetFilterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]); 359060ff233Sopenharmony_ci 360060ff233Sopenharmony_ci/* 361060ff233Sopenharmony_ci * Set the agingTime of the device list. 362060ff233Sopenharmony_ci * The unit of agingTime is seconds, and the range is 1 to 10 seconds. 363060ff233Sopenharmony_ci */ 364060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SetDeviceListAgingTime(uint32_t agingTime); 365060ff233Sopenharmony_ci 366060ff233Sopenharmony_ci/* 367060ff233Sopenharmony_ci * Set the size of the device list. 368060ff233Sopenharmony_ci * The range is 20 to 400. 369060ff233Sopenharmony_ci */ 370060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SetMaxDeviceNum(uint32_t maxDeviceNum); 371060ff233Sopenharmony_ci 372060ff233Sopenharmony_ci/* 373060ff233Sopenharmony_ci * dfinder set screen status 374060ff233Sopenharmony_ci * param: isScreenOn, screen status 375060ff233Sopenharmony_ci * return: always return 0 on success 376060ff233Sopenharmony_ci */ 377060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_ScreenStatusChange(bool isScreenOn); 378060ff233Sopenharmony_ci 379060ff233Sopenharmony_ci/* 380060ff233Sopenharmony_ci * Register the serviceData of local device. 381060ff233Sopenharmony_ci * return 0 on success, negative value on failure 382060ff233Sopenharmony_ci */ 383060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterServiceData(const char *serviceData); 384060ff233Sopenharmony_ci 385060ff233Sopenharmony_ci/** 386060ff233Sopenharmony_ci * @brief register business data to local device, the data will be used as bData filed in json format in coap payload 387060ff233Sopenharmony_ci * 388060ff233Sopenharmony_ci * @param [in] (const char *) businessData: specific data which need to be put into the coap payload 389060ff233Sopenharmony_ci * 390060ff233Sopenharmony_ci * @return (int32_t) 391060ff233Sopenharmony_ci * 0 operation success 392060ff233Sopenharmony_ci * negative value a number indicating the rough cause of this failure 393060ff233Sopenharmony_ci * 394060ff233Sopenharmony_ci * @note 1. the length of businessData should be less than NSTACKX_MAX_BUSINESS_DATA_LEN 395060ff233Sopenharmony_ci * 2. the registered business data will only be used in unicast which is confusing 396060ff233Sopenharmony_ci * 3. this interface will be DEPRECATED soon, in some special case, you can replace it with: 397060ff233Sopenharmony_ci * NSTACKX_StartDeviceDiscovery && NSTACKX_SendDiscoveryRsp 398060ff233Sopenharmony_ci * 399060ff233Sopenharmony_ci * @exception 400060ff233Sopenharmony_ci */ 401060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterBusinessData(const char *businessData); 402060ff233Sopenharmony_ci 403060ff233Sopenharmony_ci/* 404060ff233Sopenharmony_ci * Register the extendServiceData of local device. 405060ff233Sopenharmony_ci * return 0 on success, negative value on failure 406060ff233Sopenharmony_ci */ 407060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_RegisterExtendServiceData(const char *extendServiceData); 408060ff233Sopenharmony_ci 409060ff233Sopenharmony_ci/* 410060ff233Sopenharmony_ci * Send Msg to remote peer 411060ff233Sopenharmony_ci * return 0 on success, negative value on failure 412060ff233Sopenharmony_ci */ 413060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SendMsg(const char *moduleName, const char *deviceId, const uint8_t *data, 414060ff233Sopenharmony_ci uint32_t len); 415060ff233Sopenharmony_ci 416060ff233Sopenharmony_ci/* 417060ff233Sopenharmony_ci * Send Msg to remote peer 418060ff233Sopenharmony_ci * return 0 on success, negative value on failure 419060ff233Sopenharmony_ci */ 420060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SendMsgDirect(const char *moduleName, const char *deviceId, const uint8_t *data, 421060ff233Sopenharmony_ci uint32_t len, const char *ipaddr, uint8_t sendType); 422060ff233Sopenharmony_ci 423060ff233Sopenharmony_ci/* 424060ff233Sopenharmony_ci * Get device list from cache 425060ff233Sopenharmony_ci * param: deviceList - Device list return from NSTACKX, user should prepare sufficient buffer to store 426060ff233Sopenharmony_ci * device list. 427060ff233Sopenharmony_ci * param: deviceCountPtr - In/Out parameter. It indicates buffer size (number of elements) in deviceList 428060ff233Sopenharmony_ci * When returns, it indicates numbers of valid device in deviceList. 429060ff233Sopenharmony_ci * return 0 on success, negative value on failure 430060ff233Sopenharmony_ci */ 431060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_GetDeviceList(NSTACKX_DeviceInfo *deviceList, uint32_t *deviceCountPtr); 432060ff233Sopenharmony_ci 433060ff233Sopenharmony_ci/* 434060ff233Sopenharmony_ci * NSTACKX Initialization, only used for restart. 435060ff233Sopenharmony_ci * return 0 on success, negative value on failure 436060ff233Sopenharmony_ci */ 437060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_InitRestart(const NSTACKX_Parameter *parameter); 438060ff233Sopenharmony_ci 439060ff233Sopenharmony_ci/* 440060ff233Sopenharmony_ci * NSTACKX Initialization, only used for restart. 441060ff233Sopenharmony_ci * return 0 on success, negative value on failure 442060ff233Sopenharmony_ci */ 443060ff233Sopenharmony_ciDFINDER_EXPORT void NSTACKX_StartDeviceFindRestart(void); 444060ff233Sopenharmony_ci 445060ff233Sopenharmony_ci/** 446060ff233Sopenharmony_ci * @brief start device find with configurable parameters 447060ff233Sopenharmony_ci * 448060ff233Sopenharmony_ci * @param [in] (const NSTACKX_DiscoverySettings *) discoverySettings: configurable discovery properties 449060ff233Sopenharmony_ci * 450060ff233Sopenharmony_ci * @return (int32_t) 451060ff233Sopenharmony_ci * 0 operation success 452060ff233Sopenharmony_ci * negative value a number indicating the rough cause of this failure 453060ff233Sopenharmony_ci * 454060ff233Sopenharmony_ci * @note 1. if the discovery is already running, calling this interface will stop the previous one and start a new one 455060ff233Sopenharmony_ci * 2. if both advertiseCount and advertiseDuration in discoverySettings are zero, the discovery interval will 456060ff233Sopenharmony_ci * fallback to 5 sec 12 times(100 ms, 200, 200, 300...) 457060ff233Sopenharmony_ci * 3. if advertiseCount is not zero, the broadcast interval equals advertiseDuration / advertiseCount 458060ff233Sopenharmony_ci * 459060ff233Sopenharmony_ci * @exception 460060ff233Sopenharmony_ci */ 461060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_StartDeviceDiscovery(const NSTACKX_DiscoverySettings *discoverySettings); 462060ff233Sopenharmony_ci 463060ff233Sopenharmony_ci/* 464060ff233Sopenharmony_ci * Start device discovery with configured broadcast interval and other settings 465060ff233Sopenharmony_ci * return 0 on success, negative value on failure 466060ff233Sopenharmony_ci */ 467060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_StartDeviceDiscoveryWithConfig(const DFinderDiscConfig *discConfig); 468060ff233Sopenharmony_ci 469060ff233Sopenharmony_citypedef struct { 470060ff233Sopenharmony_ci char localNetworkName[NSTACKX_MAX_INTERFACE_NAME_LEN]; /* nic name of local device */ 471060ff233Sopenharmony_ci char remoteIp[NSTACKX_MAX_IP_STRING_LEN]; /* ip of remote device */ 472060ff233Sopenharmony_ci char *businessData; /* business data in unicast: {"bData":"xxx"} */ 473060ff233Sopenharmony_ci uint32_t length; /* the length of business data, include '\0' */ 474060ff233Sopenharmony_ci uint8_t businessType; /* service identify */ 475060ff233Sopenharmony_ci} NSTACKX_ResponseSettings; 476060ff233Sopenharmony_ci 477060ff233Sopenharmony_ci/** 478060ff233Sopenharmony_ci * @brief reply unicast to remote device specified by remoteIp, using local nic specified by localNetworkName 479060ff233Sopenharmony_ci * 480060ff233Sopenharmony_ci * @param [in] (const NSTACKX_ResponseSettings *) responseSettings: configurable unicast reply properties 481060ff233Sopenharmony_ci * 482060ff233Sopenharmony_ci * @return (int32_t) 483060ff233Sopenharmony_ci * 0 operation success 484060ff233Sopenharmony_ci * negative value a number indicating the rough cause of this failure 485060ff233Sopenharmony_ci * 486060ff233Sopenharmony_ci * @note only one unicast reply will be sent each time this interface is called 487060ff233Sopenharmony_ci * 488060ff233Sopenharmony_ci * @exception 489060ff233Sopenharmony_ci */ 490060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SendDiscoveryRsp(const NSTACKX_ResponseSettings *responseSettings); 491060ff233Sopenharmony_ci 492060ff233Sopenharmony_ci/** 493060ff233Sopenharmony_ci * @brief start sending broadcast notifications 494060ff233Sopenharmony_ci * 495060ff233Sopenharmony_ci * @param [in] config: configurable properties to send notification, see struct NSTACKX_NotificationConfig 496060ff233Sopenharmony_ci * 497060ff233Sopenharmony_ci * @return (int32_t) 498060ff233Sopenharmony_ci * 0 operation success 499060ff233Sopenharmony_ci * negative value a number indicating the rough cause of this failure 500060ff233Sopenharmony_ci * 501060ff233Sopenharmony_ci * @note 1. if the sending is already running, calling this interface will stop the previous one and start a new one, 502060ff233Sopenharmony_ci * caller can update its notification msg through this way 503060ff233Sopenharmony_ci * 2. caller should ensure the consistency of associated data 504060ff233Sopenharmony_ci * @exception 505060ff233Sopenharmony_ci */ 506060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_SendNotification(const NSTACKX_NotificationConfig *config); 507060ff233Sopenharmony_ci 508060ff233Sopenharmony_ci/** 509060ff233Sopenharmony_ci * @brief stop sending broadcast notifications 510060ff233Sopenharmony_ci * 511060ff233Sopenharmony_ci * @param [in] businessType: service identify, notification of which business we should stop 512060ff233Sopenharmony_ci * 513060ff233Sopenharmony_ci * @return (int32_t) 514060ff233Sopenharmony_ci * 0 operation success 515060ff233Sopenharmony_ci * negative value a number indicating the rough cause of this failure 516060ff233Sopenharmony_ci * 517060ff233Sopenharmony_ci * @note 1. calling this interface will stop the sending timer 518060ff233Sopenharmony_ci * 2. if not business sensitive, should use NSTACKX_BUSINESS_TYPE_NULL, see struct NSTACKX_BusinessType 519060ff233Sopenharmony_ci * 520060ff233Sopenharmony_ci * @exception 521060ff233Sopenharmony_ci */ 522060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_StopSendNotification(uint8_t businessType); 523060ff233Sopenharmony_ci 524060ff233Sopenharmony_ci#ifdef ENABLE_USER_LOG 525060ff233Sopenharmony_citypedef void (*DFinderLogCallback)(const char *moduleName, uint32_t logLevel, const char *format, ...); 526060ff233Sopenharmony_ci 527060ff233Sopenharmony_ci/* 528060ff233Sopenharmony_ci * Set the DFinder log implementation 529060ff233Sopenharmony_ci */ 530060ff233Sopenharmony_ciDFINDER_EXPORT int32_t NSTACKX_DFinderRegisterLog(DFinderLogCallback userLogCallback); 531060ff233Sopenharmony_ci#endif 532060ff233Sopenharmony_ci 533060ff233Sopenharmony_ci#ifdef __cplusplus 534060ff233Sopenharmony_ci} 535060ff233Sopenharmony_ci#endif 536060ff233Sopenharmony_ci 537060ff233Sopenharmony_ci#endif /* NSTACKX_H */ 538