1 /* 2 * Copyright (C) 2021 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 <stdint.h> 20 21 #ifdef __cplusplus 22 extern "C"{ 23 #endif 24 25 #define NSTACKX_MAX_DEVICE_NAME_LEN 64 26 #define NSTACKX_MAX_MODULE_NAME_LEN 64 27 #define NSTACKX_MAX_DEVICE_ID_LEN 96 28 #define NSTACKX_MAX_SENDMSG_DATA_LEN 512 29 #define NSTACKX_MAX_MAC_STRING_LEN 18 30 #define NSTACKX_MAX_IP_STRING_LEN 16 31 #define NSTACKX_MAX_CAPABILITY_NUM 2 32 #define NSTACKX_MAX_DEVICE_NUM 20 33 #define NSTACKX_MAX_INTERFACE_NAME_LEN 16 34 #define NSTACKX_MAX_HICOM_VERSION 16 35 #define NSTACKX_MAX_SERVICE_DATA_LEN 64 36 37 #define NSTACKX_MAX_RESERVED_INFO_LEN 219 // expand from 131 to 219 (+88) bytes to hold service data 38 #define DEVICE_HASH_LEN 21 39 #define DEFAULT_MODE 0 40 #define DISCOVER_MODE 1 41 #define PUBLISH_MODE_UPLINE 2 42 #define PUBLISH_MODE_OFFLINE 3 43 #define PUBLISH_MODE_PROACTIVE 10 44 #define PUBLISH_DEVICE_NUM 1 45 #define INNER_DISCOVERY 1 46 #define PUBLISH_NUM 1 47 48 /* Remote device information */ 49 typedef struct NSTACKX_DeviceInfo { 50 char deviceId[NSTACKX_MAX_DEVICE_ID_LEN]; 51 char deviceName[NSTACKX_MAX_DEVICE_NAME_LEN]; 52 uint32_t capabilityBitmapNum; 53 uint32_t capabilityBitmap[NSTACKX_MAX_CAPABILITY_NUM]; 54 uint8_t deviceType; 55 uint8_t mode; 56 uint8_t update : 1; 57 uint8_t reserved : 7; 58 char version[NSTACKX_MAX_HICOM_VERSION]; 59 char reservedInfo[NSTACKX_MAX_RESERVED_INFO_LEN]; 60 } NSTACKX_DeviceInfo; 61 62 /* Local device information */ 63 typedef struct { 64 char name[NSTACKX_MAX_DEVICE_NAME_LEN]; 65 char deviceId[NSTACKX_MAX_DEVICE_ID_LEN]; 66 char btMacAddr[NSTACKX_MAX_MAC_STRING_LEN]; 67 char wifiMacAddr[NSTACKX_MAX_MAC_STRING_LEN]; 68 char networkIpAddr[NSTACKX_MAX_IP_STRING_LEN]; 69 char networkName[NSTACKX_MAX_INTERFACE_NAME_LEN]; 70 uint8_t is5GHzBandSupported; 71 uint8_t deviceType; 72 char version[NSTACKX_MAX_HICOM_VERSION]; 73 } NSTACKX_LocalDeviceInfo; 74 75 /* Register local device information */ 76 int32_t NSTACKX_RegisterDevice(const NSTACKX_LocalDeviceInfo *localDeviceInfo); 77 78 /* Register local device information with deviceHash */ 79 int32_t NSTACKX_RegisterDeviceAn(const NSTACKX_LocalDeviceInfo *localDeviceInfo, uint64_t deviceHash); 80 81 /* Device list change callback type */ 82 typedef void (*NSTACKX_OnDeviceListChanged)(const NSTACKX_DeviceInfo *deviceList, uint32_t deviceCount); 83 84 /* Data receive callback type */ 85 typedef void (*NSTACKX_OnMsgReceived)(const char *moduleName, const char *deviceId, 86 const uint8_t *data, uint32_t len); 87 88 /* DFinder message type list. */ 89 typedef enum { 90 DFINDER_ON_TOO_BUSY = 1, 91 DFINDER_ON_INNER_ERROR, 92 } DFinderMsgType; 93 94 /* Data receive callback type */ 95 typedef void (*NSTACKX_OnDFinderMsgReceived)(DFinderMsgType msgType); 96 97 /* NSTACKX parameter, which contains callback list */ 98 typedef struct { 99 NSTACKX_OnDeviceListChanged onDeviceListChanged; 100 NSTACKX_OnDeviceListChanged onDeviceFound; 101 NSTACKX_OnMsgReceived onMsgReceived; 102 NSTACKX_OnDFinderMsgReceived onDFinderMsgReceived; 103 } NSTACKX_Parameter; 104 105 /* 106 * NSTACKX Initialization 107 * return 0 on success, negative value on failure 108 */ 109 int32_t NSTACKX_Init(const NSTACKX_Parameter *parameter); 110 111 /* NSTACKX Destruction */ 112 void NSTACKX_Deinit(void); 113 114 /* 115 * Start device discovery 116 * return 0 on success, negative value on failure 117 */ 118 int32_t NSTACKX_StartDeviceFind(void); 119 120 /* 121 * Start device discovery by mode 122 * return 0 on success, negative value on failure 123 */ 124 int32_t NSTACKX_StartDeviceFindAn(uint8_t mode); 125 126 /* 127 * Stop device discovery 128 * return 0 on success, negative value on failure 129 */ 130 int32_t NSTACKX_StopDeviceFind(void); 131 132 /* 133 * Register the capability of local device. 134 * return 0 on success, negative value on failure 135 */ 136 int32_t NSTACKX_RegisterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]); 137 138 /* 139 * Set the capability to filter remote devices. 140 * return 0 on success, negative value on failure 141 */ 142 int32_t NSTACKX_SetFilterCapability(uint32_t capabilityBitmapNum, uint32_t capabilityBitmap[]); 143 144 /* 145 * Register the serviceData of local device. 146 * return 0 on success, negative value on failure 147 */ 148 int32_t NSTACKX_RegisterServiceData(const char *serviceData); 149 150 #ifdef __cplusplus 151 } 152 #endif 153 154 #endif /* NSTACKX_H */ 155