• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "disc_coap_capability.h"
17 
18 #include "anonymizer.h"
19 #include "disc_log.h"
20 #include "disc_nstackx_adapter.h"
21 #include "softbus_errcode.h"
22 
DiscCoapAssembleCapData(uint32_t capability,const char * capabilityData,uint32_t dataLen,char * outData,uint32_t outLen)23 int32_t DiscCoapAssembleCapData(uint32_t capability, const char *capabilityData, uint32_t dataLen, char *outData,
24     uint32_t outLen)
25 {
26     (void)capability;
27     (void)capabilityData;
28     (void)dataLen;
29     (void)outData;
30     (void)outLen;
31     return SOFTBUS_FUNC_NOT_SUPPORT;
32 }
33 
DiscCoapFillServiceData(const PublishOption * option,char * outData,uint32_t outDataLen,uint32_t allCap)34 int32_t DiscCoapFillServiceData(const PublishOption *option, char *outData, uint32_t outDataLen, uint32_t allCap)
35 {
36     (void)option;
37     (void)outData;
38     (void)outDataLen;
39     (void)allCap;
40     return SOFTBUS_OK;
41 }
42 
DiscFillBtype(uint32_t capability,uint32_t allCap,NSTACKX_DiscoverySettings * discSet)43 void DiscFillBtype(uint32_t capability, uint32_t allCap, NSTACKX_DiscoverySettings *discSet)
44 {
45     (void)allCap;
46     DISC_CHECK_AND_RETURN_LOGW(discSet != NULL, DISC_COAP, "discSet is NULL");
47     switch (capability) {
48         case 1 << OSD_CAPABILITY_BITMAP:
49             discSet->businessType = (uint8_t)NSTACKX_BUSINESS_TYPE_NULL;
50             break;
51         case 1 << DDMP_CAPABILITY_BITMAP:
52             discSet->businessType = (uint8_t)NSTACKX_BUSINESS_TYPE_AUTONET;
53             break;
54         case 1 << SHARE_CAPABILITY_BITMAP:
55             discSet->businessType = (uint8_t)NSTACKX_BUSINESS_TYPE_STRATEGY;
56             break;
57         default:
58             DISC_LOGW(DISC_COAP, "use the default bType, capability=%{public}u", capability);
59             discSet->businessType = (uint8_t)NSTACKX_BUSINESS_TYPE_NULL;
60             break;
61     }
62 }
63 
DiscCoapProcessDeviceInfo(const NSTACKX_DeviceInfo * nstackxInfo,DeviceInfo * devInfo,const DiscInnerCallback * discCb)64 int32_t DiscCoapProcessDeviceInfo(const NSTACKX_DeviceInfo *nstackxInfo, DeviceInfo *devInfo,
65     const DiscInnerCallback *discCb)
66 {
67     DISC_CHECK_AND_RETURN_RET_LOGE(nstackxInfo != NULL, SOFTBUS_INVALID_PARAM, DISC_COAP, "nstackx devInfo is NULL");
68     DISC_CHECK_AND_RETURN_RET_LOGE(devInfo != NULL, SOFTBUS_INVALID_PARAM, DISC_COAP, "devInfo is NULL");
69     DISC_CHECK_AND_RETURN_RET_LOGE(discCb != NULL && discCb->OnDeviceFound != NULL,
70         SOFTBUS_INVALID_PARAM, DISC_COAP, "discCb is NULL");
71 
72     InnerDeviceInfoAddtions additions = {
73         .medium = COAP,
74     };
75     char *anonymizedName = NULL;
76     Anonymize(devInfo->devName, &anonymizedName);
77 
78     if (nstackxInfo->discoveryType == NSTACKX_DISCOVERY_TYPE_ACTIVE ||
79         nstackxInfo->mode == PUBLISH_MODE_PROACTIVE) {
80         DISC_LOGI(DISC_COAP, "DiscFound: devName=%{public}s, netIf=%{public}s",
81             AnonymizeWrapper(anonymizedName), nstackxInfo->networkName);
82         AnonymizeFree(anonymizedName);
83         discCb->OnDeviceFound(devInfo, &additions);
84         return SOFTBUS_OK;
85     }
86 
87     uint8_t bType = nstackxInfo->businessType;
88     DISC_LOGI(DISC_COAP, "DiscRecv: broadcast devName=%{public}s, bType=%{public}u",
89         AnonymizeWrapper(anonymizedName), bType);
90     AnonymizeFree(anonymizedName);
91     if (bType != NSTACKX_BUSINESS_TYPE_NULL && DiscCoapSendRsp(devInfo, bType) != SOFTBUS_OK) {
92         DISC_LOGE(DISC_COAP, "send response failed");
93         return SOFTBUS_DISCOVER_COAP_SEND_RSP_FAIL;
94     }
95     return SOFTBUS_OK;
96 }
97 
DiscCoapReportNotification(const NSTACKX_NotificationConfig * notification)98 void DiscCoapReportNotification(const NSTACKX_NotificationConfig *notification)
99 {
100     (void)notification;
101 }
102