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 COAP_DISCOVER_H 17 #define COAP_DISCOVER_H 18 #include <coap3/coap.h> 19 #include "nstackx_common.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define COAP_MODULE_NAME_TYPE 0x01 26 #define COAP_DEVICE_ID_TYPE 0x02 27 #define COAP_MSG_TYPE 0x03 28 29 #define SERVER_TYPE_WLANORETH 0 30 #define SERVER_TYPE_P2P 1 31 #define SERVER_TYPE_USB 2 32 33 #define INVALID_TYPE 255 34 #pragma pack(1) 35 typedef struct { 36 uint8_t type; 37 uint16_t len; /* must be a positive integer */ 38 uint8_t value[0]; 39 } CoapMsgUnit; 40 #pragma pack() 41 struct coap_session_t; 42 43 typedef struct { 44 const char *deviceId; 45 const char *moduleName; 46 const uint8_t *data; 47 uint32_t len; 48 uint8_t type; 49 int32_t err; 50 sem_t wait; 51 } MsgCtx; 52 53 typedef struct CoapRequest { 54 uint8_t type; 55 uint8_t code; 56 const char *remoteUrl; 57 uint8_t *token; 58 size_t tokenLength; 59 char *data; 60 size_t dataLength; 61 } CoapRequest; 62 63 typedef enum { 64 COAP_BROADCAST_TYPE_DEFAULT = 0, 65 COAP_BROADCAST_TYPE_USER = 1, 66 COAP_BROADCAST_TYPE_USER_DEFINE_INTERVAL = 2 67 } CoapBroadcastType; 68 69 #ifdef DFINDER_SUPPORT_SET_SCREEN_STATUS 70 void SetScreenStatus(bool isScreenOn); 71 #endif 72 73 void CoapServiceDiscoverInner(uint8_t userRequest); 74 void CoapServiceDiscoverInnerAn(uint8_t userRequest); 75 void CoapServiceDiscoverInnerConfigurable(uint8_t userRequest); 76 void CoapServiceDiscoverStopInner(void); 77 uint8_t CoapDiscoverRequestOngoing(void); 78 79 void CoapServiceNotification(void); 80 81 int32_t CoapInitResources(coap_context_t *ctx); 82 83 int32_t CoapDiscoverInit(EpollDesc epollfd); 84 void CoapDiscoverDeinit(void); 85 86 int32_t CoapSendServiceMsg(MsgCtx *msgCtx, const char *remoteIpStr, const struct in_addr *remoteIp); 87 void CoapSubscribeModuleInner(uint8_t isSubscribe); 88 void CoapUnsubscribeModuleInner(uint8_t isUnsubscribe); 89 void CoapInitSubscribeModuleInner(void); 90 void ResetCoapDiscoverTaskCount(uint8_t isBusy); 91 void SetCoapDiscoverType(CoapBroadcastType type); 92 void SetCoapUserDiscoverInfo(uint32_t advCount, uint32_t advDuration); 93 int32_t SetCoapDiscConfig(const DFinderDiscConfig *discConfig); 94 void SendDiscoveryRsp(const NSTACKX_ResponseSettings *responseSettings); 95 int32_t LocalizeNotificationInterval(const uint16_t *intervals, const uint8_t intervalLen); 96 void CoapServiceNotificationStop(void); 97 98 #ifdef __cplusplus 99 } 100 #endif 101 102 #endif /* #ifndef COAP_DISCOVER_H */ 103