• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "nstackx_inet.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define COAP_SRV_DEFAULT_PORT 5684
31 #define COAP_SRV_DEFAULT_ADDR "0.0.0.0"
32 
33 typedef enum {
34     SOCKET_READ_EVENT = 0,
35     SOCKET_WRITE_EVENT,
36     SOCKET_ERROR_EVENT,
37     SOCKET_END_EVENT
38 } SocketEventType;
39 
40 typedef struct {
41     bool inited;
42     uint8_t socketErrFlag;
43     int32_t listenFd;
44     EpollTask task;
45     uint64_t socketEventNum[SOCKET_END_EVENT];
46     void *iface;
47 } CoapCtxType;
48 
49 bool IsCoapContextReady(void);
50 
51 const char *CoapGetLocalIfaceName(void);
52 CoapCtxType *CoapGetCoapCtxType(void);
53 
54 CoapCtxType *CoapServerInit(uint8_t af, const union InetAddr *addr, void *iface);
55 void CoapServerDestroy(CoapCtxType *ctx, bool moduleDeinit);
56 
57 void ResetCoapSocketTaskCount(uint8_t isBusy);
58 int32_t CoapSendMessage(const CoapBuildParam *param, uint8_t isBroadcast, uint8_t businessType, bool isAckMsg);
59 
60 #ifdef __cplusplus
61 }
62 #endif
63 
64 #endif /* COAP_APP_H */
65