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_APP_H 17 #define COAP_APP_H 18 19 #include <arpa/inet.h> 20 21 #include "coap_adapter.h" 22 #include "coap_def.h" 23 #include "nstackx_epoll.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #define COAP_SRV_DEFAULT_PORT 5684 30 #define COAP_SRV_DEFAULT_ADDR "0.0.0.0" 31 32 typedef enum { 33 SOCKET_READ_EVENT = 0, 34 SOCKET_WRITE_EVENT, 35 SOCKET_ERROR_EVENT, 36 SOCKET_END_EVENT 37 } SocketEventType; 38 39 typedef struct { 40 bool inited; 41 uint8_t socketErrFlag; 42 int32_t listenFd; 43 EpollTask task; 44 uint64_t socketEventNum[SOCKET_END_EVENT]; 45 void *iface; 46 } CoapCtxType; 47 48 bool IsCoapContextReady(void); 49 50 const char *CoapGetLocalIfaceName(void); 51 CoapCtxType *CoapGetCoapCtxType(void); 52 53 CoapCtxType *CoapServerInit(const struct in_addr *ip, void *iface); 54 void CoapServerDestroy(CoapCtxType *ctx, bool moduleDeinit); 55 56 void ResetCoapSocketTaskCount(uint8_t isBusy); 57 int32_t CoapSendMessage(const CoapBuildParam *param, uint8_t isBroadcast, uint8_t businessType, bool isAckMsg); 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif /* COAP_APP_H */ 64