• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 COAP_DISCOVER_H
17 #define COAP_DISCOVER_H
18 #include <coap3/coap.h>
19 #include "nstackx_common.h"
20 
21 #define COAP_MODULE_NAME_TYPE 0x01
22 #define COAP_DEVICE_ID_TYPE 0x02
23 #define COAP_MSG_TYPE 0x03
24 
25 #define SERVER_TYPE_WLANORETH 0
26 #define SERVER_TYPE_P2P 1
27 #define SERVER_TYPE_USB 2
28 
29 #define INVALID_TYPE 255
30 #pragma pack(1)
31 typedef struct {
32     uint8_t type;
33     uint16_t len; /* must be a positive integer */
34     uint8_t value[0];
35 } CoapMsgUnit;
36 #pragma pack()
37 struct coap_session_t;
38 struct DeviceInfo;
39 typedef struct {
40     char deviceId[NSTACKX_MAX_DEVICE_ID_LEN];
41     char moduleName[NSTACKX_MAX_MODULE_NAME_LEN];
42     char p2pAddr[NSTACKX_MAX_IP_STRING_LEN];
43     uint8_t *data;
44     uint32_t len;
45     uint8_t type;
46     int32_t err;
47     sem_t wait;
48 } MsgCtx;
49 
50 typedef struct CoapRequest {
51     uint8_t type;
52     uint8_t code;
53     const char *remoteUrl;
54     uint8_t *token;
55     size_t tokenLength;
56     char *data;
57     size_t dataLength;
58 } CoapRequest;
59 
60 typedef enum {
61     COAP_BROADCAST_TYPE_DEFAULT = 0,
62     COAP_BROADCAST_TYPE_USER = 1
63 } CoapBroadcastType;
64 
65 void CoapServiceDiscoverInner(uint8_t userRequest);
66 void CoapServiceDiscoverInnerAn(uint8_t userRequest);
67 void CoapServiceDiscoverInnerConfigurable(uint8_t userRequest);
68 void CoapServiceDiscoverStopInner(void);
69 uint8_t CoapDiscoverRequestOngoing(void);
70 
71 #ifndef DFINDER_SUPPORT_MULTI_NIF
72 void CoapInitResources(coap_context_t *ctx, uint8_t serverType);
73 #endif
74 
75 int32_t CoapDiscoverInit(EpollDesc epollfd);
76 void CoapDiscoverDeinit(void);
77 
78 #ifdef DFINDER_SUPPORT_MULTI_NIF
79 void CoapInitResourcesWithIdx(coap_context_t *ctx, uint32_t idx, const char *networkName);
80 void CoapDestroyCtxWithIdx(uint32_t ctxIdx);
81 #else
82 void CoapDestroyCtx(uint8_t serverType);
83 #endif
84 
85 int32_t CoapSendServiceMsg(MsgCtx *msgCtx, struct DeviceInfo *deviceInfo);
86 int32_t CoapSendServiceMsgWithDefiniteTargetIp(MsgCtx *msgCtx, struct DeviceInfo *deviceInfo);
87 coap_context_t *GetContext(uint8_t serverType);
88 void CoapSubscribeModuleInner(uint8_t isSubscribe);
89 void CoapUnsubscribeModuleInner(uint8_t isUnsubscribe);
90 void CoapInitSubscribeModuleInner(void);
91 void ResetCoapDiscoverTaskCount(uint8_t isBusy);
92 uint8_t GetActualType(const uint8_t type, const char *dstIp);
93 void SetCoapDiscoverType(CoapBroadcastType type);
94 void SetCoapUserDiscoverInfo(uint32_t advCount, uint32_t advDuration);
95 void SendDiscoveryRsp(const NSTACKX_ResponseSettings *responseSettings);
96 #endif /* #ifndef COAP_DISCOVER_H */
97