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 <coap3/coap.h> 20 21 #include "nstackx_epoll.h" 22 #include "nstackx_inet.h" 23 #include "nstackx_list.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 #define MAX_COAP_SOCKET_NUM 64 33 34 typedef struct { 35 List node; 36 coap_context_t *ctx; 37 EpollTask taskList[MAX_COAP_SOCKET_NUM]; 38 uint32_t socketNum; 39 uint8_t socketErrFlag; 40 uint8_t freeCtxLater; 41 void *iface; 42 } CoapCtxType; 43 44 List *GetCoapContextList(void); 45 bool IsCoapContextReady(void); 46 CoapCtxType *CoapGetCoapCtxType(const coap_context_t *ctx); 47 48 CoapCtxType *CoapServerInit(uint8_t af, const union InetAddr *ip, void *iface); 49 void CoapServerDestroy(CoapCtxType *ctx, bool moduleDeinit); 50 51 uint32_t RegisterCoAPEpollTask(EpollDesc epollfd); 52 void DeRegisterCoAPEpollTask(void); 53 void ResetCoapSocketTaskCount(uint8_t isBusy); 54 #ifdef _WIN32 55 int32_t CoapThreadInit(void); 56 void CoapThreadDestroy(void); 57 #endif 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif /* COAP_APP_H */ 64