mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 00:39:52 +00:00
fix:Modify the file format
Signed-off-by: leimingqiang <leimingqiang7@huawei.com>
This commit is contained in:
parent
c5fe4dbc7f
commit
76aea5a27e
352
LICENSE
352
LICENSE
@ -1,177 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
@ -1,58 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_hisysevent.h"
|
||||
|
||||
int32_t SoftbusWriteHisEvt(SoftBusEvtReportMsg* reportMsg)
|
||||
{
|
||||
(void)reportMsg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SoftbusFreeEvtReporMsg(SoftBusEvtReportMsg* msg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg->paramArray != NULL) {
|
||||
SoftBusFree(msg->paramArray);
|
||||
msg->paramArray = NULL;
|
||||
}
|
||||
SoftBusFree(msg);
|
||||
}
|
||||
|
||||
SoftBusEvtReportMsg* SoftbusCreateEvtReportMsg(int32_t paramNum)
|
||||
{
|
||||
if (paramNum <= SOFTBUS_EVT_PARAM_ZERO || paramNum >= SOFTBUS_EVT_PARAM_BUTT) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "param is invalid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SoftBusEvtReportMsg *msg = (SoftBusEvtReportMsg*)SoftBusMalloc(sizeof(SoftBusEvtReportMsg));
|
||||
if (msg == NULL) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "report msg is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msg->paramArray = (SoftBusEvtParam*)SoftBusMalloc(sizeof(SoftBusEvtParam) * paramNum);
|
||||
if (msg->paramArray == NULL) {
|
||||
SoftbusFreeEvtReporMsg(msg);
|
||||
return NULL;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_hisysevent.h"
|
||||
|
||||
int32_t SoftbusWriteHisEvt(SoftBusEvtReportMsg* reportMsg)
|
||||
{
|
||||
(void)reportMsg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SoftbusFreeEvtReporMsg(SoftBusEvtReportMsg* msg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg->paramArray != NULL) {
|
||||
SoftBusFree(msg->paramArray);
|
||||
msg->paramArray = NULL;
|
||||
}
|
||||
SoftBusFree(msg);
|
||||
}
|
||||
|
||||
SoftBusEvtReportMsg* SoftbusCreateEvtReportMsg(int32_t paramNum)
|
||||
{
|
||||
if (paramNum <= SOFTBUS_EVT_PARAM_ZERO || paramNum >= SOFTBUS_EVT_PARAM_BUTT) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "param is invalid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SoftBusEvtReportMsg *msg = (SoftBusEvtReportMsg*)SoftBusMalloc(sizeof(SoftBusEvtReportMsg));
|
||||
if (msg == NULL) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "report msg is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msg->paramArray = (SoftBusEvtParam*)SoftBusMalloc(sizeof(SoftBusEvtParam) * paramNum);
|
||||
if (msg->paramArray == NULL) {
|
||||
SoftbusFreeEvtReporMsg(msg);
|
||||
return NULL;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LNN_IP_UTILS_ADAPTER_H
|
||||
#define LNN_IP_UTILS_ADAPTER_H
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <securec.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // LNN_IP_UTILS_ADAPTER_H
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LNN_IP_UTILS_ADAPTER_H
|
||||
#define LNN_IP_UTILS_ADAPTER_H
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <securec.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // LNN_IP_UTILS_ADAPTER_H
|
||||
|
@ -1,90 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_ADAPTER_CRYPTO_H
|
||||
#define SOFTBUS_ADAPTER_CRYPTO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "softbus_def.h"
|
||||
|
||||
#ifndef AES_GCM_H
|
||||
#define AES_GCM_H
|
||||
|
||||
#define HUKS_AES_GCM_KEY_LEN 256
|
||||
#define GCM_IV_LEN 12
|
||||
#define AAD_LEN 16
|
||||
|
||||
#define TAG_LEN 16
|
||||
#define OVERHEAD_LEN (GCM_IV_LEN + TAG_LEN)
|
||||
|
||||
#define GCM_KEY_BITS_LEN_128 128
|
||||
#define GCM_KEY_BITS_LEN_256 256
|
||||
#define KEY_BITS_UNIT 8
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
typedef struct {
|
||||
unsigned char *aad;
|
||||
uint32_t aadLen;
|
||||
const unsigned char *input;
|
||||
uint32_t inputLen;
|
||||
unsigned char **output;
|
||||
uint32_t *outputLen;
|
||||
} GcmInputParams;
|
||||
|
||||
typedef struct {
|
||||
uint32_t keyLen;
|
||||
unsigned char key[SESSION_KEY_LENGTH];
|
||||
unsigned char iv[GCM_IV_LEN];
|
||||
} AesGcmCipherKey;
|
||||
|
||||
int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen);
|
||||
|
||||
int32_t SoftBusBase64Decode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen);
|
||||
|
||||
int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash);
|
||||
|
||||
int32_t SoftBusGenerateSessionKey(char* key, uint32_t len);
|
||||
|
||||
int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len);
|
||||
|
||||
int32_t SoftBusEncryptData(AesGcmCipherKey *key, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen);
|
||||
|
||||
int32_t SoftBusEncryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen, int32_t seqNum);
|
||||
|
||||
int32_t SoftBusDecryptData(AesGcmCipherKey *key, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *decryptData, uint32_t *decryptLen);
|
||||
|
||||
int32_t SoftBusDecryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen, int32_t seqNum);
|
||||
|
||||
uint32_t SoftBusCryptoRand(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* SOFTBUS_ADAPTER_CRYPTO_H */
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_ADAPTER_CRYPTO_H
|
||||
#define SOFTBUS_ADAPTER_CRYPTO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "softbus_def.h"
|
||||
|
||||
#ifndef AES_GCM_H
|
||||
#define AES_GCM_H
|
||||
|
||||
#define HUKS_AES_GCM_KEY_LEN 256
|
||||
#define GCM_IV_LEN 12
|
||||
#define AAD_LEN 16
|
||||
|
||||
#define TAG_LEN 16
|
||||
#define OVERHEAD_LEN (GCM_IV_LEN + TAG_LEN)
|
||||
|
||||
#define GCM_KEY_BITS_LEN_128 128
|
||||
#define GCM_KEY_BITS_LEN_256 256
|
||||
#define KEY_BITS_UNIT 8
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
typedef struct {
|
||||
unsigned char *aad;
|
||||
uint32_t aadLen;
|
||||
const unsigned char *input;
|
||||
uint32_t inputLen;
|
||||
unsigned char **output;
|
||||
uint32_t *outputLen;
|
||||
} GcmInputParams;
|
||||
|
||||
typedef struct {
|
||||
uint32_t keyLen;
|
||||
unsigned char key[SESSION_KEY_LENGTH];
|
||||
unsigned char iv[GCM_IV_LEN];
|
||||
} AesGcmCipherKey;
|
||||
|
||||
int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen);
|
||||
|
||||
int32_t SoftBusBase64Decode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen);
|
||||
|
||||
int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash);
|
||||
|
||||
int32_t SoftBusGenerateSessionKey(char* key, uint32_t len);
|
||||
|
||||
int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len);
|
||||
|
||||
int32_t SoftBusEncryptData(AesGcmCipherKey *key, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen);
|
||||
|
||||
int32_t SoftBusEncryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen, int32_t seqNum);
|
||||
|
||||
int32_t SoftBusDecryptData(AesGcmCipherKey *key, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *decryptData, uint32_t *decryptLen);
|
||||
|
||||
int32_t SoftBusDecryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen, int32_t seqNum);
|
||||
|
||||
uint32_t SoftBusCryptoRand(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* SOFTBUS_ADAPTER_CRYPTO_H */
|
||||
|
@ -1,113 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_ADAPTER_LOG_H
|
||||
#define SOFTBUS_ADAPTER_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef SOFTBUS_DEBUG
|
||||
#if defined(__LITEOS_M__)
|
||||
#define SOFTBUS_PRINTF
|
||||
#include "log.h"
|
||||
#else
|
||||
#include "hilog/log.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SOFTBUS_DEBUG
|
||||
#if defined(__LITEOS_M__)
|
||||
|
||||
#define LOG_DBG(fmt, ...) HILOG_DEBUG(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_INFO(fmt, ...) HILOG_INFO(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_WARN(fmt, ...) HILOG_WARN(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_ERR(fmt, ...) HILOG_ERROR(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#else
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#undef LOG_TAG
|
||||
#define LOG_DOMAIN 0xD0015C0
|
||||
#define LOG_TAG "dsoftbus"
|
||||
|
||||
#define LOG_DBG(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_INFO(fmt, ...) HILOG_INFO(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_WARN(fmt, ...) HILOG_WARN(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_ERR(fmt, ...) HILOG_ERROR(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#endif
|
||||
#else
|
||||
enum {
|
||||
SOFTBUS_LOG_LEVEL_DEBUG = 0,
|
||||
SOFTBUS_LOG_LEVEL_INFO,
|
||||
SOFTBUS_LOG_LEVEL_WARNING,
|
||||
SOFTBUS_LOG_LEVEL_ERROR
|
||||
};
|
||||
|
||||
#define SOFTBUS_LOG_LEVEL SOFTBUS_LOG_LEVEL_INFO
|
||||
|
||||
#define LOG_DBG(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_DEBUG >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("DEBUG:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOG_INFO(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_INFO >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("INFO:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOG_WARN(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_WARNING >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("WARN:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOG_ERR(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_ERROR >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("ERROR:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#if defined(__LITEOS_M__)
|
||||
#define SOFTBUS_HILOG_ID HILOG_MODULE_SOFTBUS
|
||||
#else
|
||||
#define SOFTBUS_HILOG_ID LOG_CORE
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_LOG_DBG,
|
||||
SOFTBUS_LOG_INFO,
|
||||
SOFTBUS_LOG_WARN,
|
||||
SOFTBUS_LOG_ERROR,
|
||||
SOFTBUS_LOG_LEVEL_MAX,
|
||||
} SoftBusLogLevel;
|
||||
|
||||
void SoftBusOutPrint(const char *buf, SoftBusLogLevel level);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_ADAPTER_LOG_H
|
||||
#define SOFTBUS_ADAPTER_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef SOFTBUS_DEBUG
|
||||
#if defined(__LITEOS_M__)
|
||||
#define SOFTBUS_PRINTF
|
||||
#include "log.h"
|
||||
#else
|
||||
#include "hilog/log.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SOFTBUS_DEBUG
|
||||
#if defined(__LITEOS_M__)
|
||||
|
||||
#define LOG_DBG(fmt, ...) HILOG_DEBUG(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_INFO(fmt, ...) HILOG_INFO(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_WARN(fmt, ...) HILOG_WARN(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_ERR(fmt, ...) HILOG_ERROR(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
|
||||
#else
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#undef LOG_TAG
|
||||
#define LOG_DOMAIN 0xD0015C0
|
||||
#define LOG_TAG "dsoftbus"
|
||||
|
||||
#define LOG_DBG(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_INFO(fmt, ...) HILOG_INFO(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_WARN(fmt, ...) HILOG_WARN(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#define LOG_ERR(fmt, ...) HILOG_ERROR(LOG_CORE, fmt"\n", ##__VA_ARGS__);
|
||||
#endif
|
||||
#else
|
||||
enum {
|
||||
SOFTBUS_LOG_LEVEL_DEBUG = 0,
|
||||
SOFTBUS_LOG_LEVEL_INFO,
|
||||
SOFTBUS_LOG_LEVEL_WARNING,
|
||||
SOFTBUS_LOG_LEVEL_ERROR
|
||||
};
|
||||
|
||||
#define SOFTBUS_LOG_LEVEL SOFTBUS_LOG_LEVEL_INFO
|
||||
|
||||
#define LOG_DBG(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_DEBUG >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("DEBUG:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOG_INFO(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_INFO >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("INFO:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOG_WARN(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_WARNING >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("WARN:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOG_ERR(fmt, ...) do { \
|
||||
if (SOFTBUS_LOG_LEVEL_ERROR >= SOFTBUS_LOG_LEVEL) { \
|
||||
printf("ERROR:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#if defined(__LITEOS_M__)
|
||||
#define SOFTBUS_HILOG_ID HILOG_MODULE_SOFTBUS
|
||||
#else
|
||||
#define SOFTBUS_HILOG_ID LOG_CORE
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_LOG_DBG,
|
||||
SOFTBUS_LOG_INFO,
|
||||
SOFTBUS_LOG_WARN,
|
||||
SOFTBUS_LOG_ERROR,
|
||||
SOFTBUS_LOG_LEVEL_MAX,
|
||||
} SoftBusLogLevel;
|
||||
|
||||
void SoftBusOutPrint(const char *buf, SoftBusLogLevel level);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
@ -1,58 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_ip_utils_adapter.h"
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
|
||||
int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len)
|
||||
{
|
||||
if (ifName == NULL || ip == NULL) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "ifName or ip buffer is NULL!");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct netif *netif = NULL;
|
||||
char *ipStr = NULL;
|
||||
char *netMaskStr = NULL;
|
||||
ip4_addr_t *ipAddr = NULL;
|
||||
ip4_addr_t *netMask = NULL;
|
||||
|
||||
netif = netif_find(ifName);
|
||||
if (netif == NULL) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "netif is NULL!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
#ifdef HISPARK_PEGASUS_USE_NETIF_GET_ADDR
|
||||
netifapi_netif_get_addr(netif, ipAddr, netMask, NULL);
|
||||
#else
|
||||
ipAddr = (ip4_addr_t *)netif_ip4_addr(netif);
|
||||
netMask = (ip4_addr_t *)netif_ip4_netmask(netif);
|
||||
#endif
|
||||
ipStr = ip4addr_ntoa(ipAddr);
|
||||
if (strncpy_s(ip, len, ipStr, strlen(ipStr)) != EOK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy ip failed!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (netmask != NULL) {
|
||||
netMaskStr = ip4addr_ntoa(netMask);
|
||||
if (strncpy_s(netmask, len, netMaskStr, strlen(netMaskStr)) != EOK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy netmask failed!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_ip_utils_adapter.h"
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
|
||||
int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len)
|
||||
{
|
||||
if (ifName == NULL || ip == NULL) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "ifName or ip buffer is NULL!");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct netif *netif = NULL;
|
||||
char *ipStr = NULL;
|
||||
char *netMaskStr = NULL;
|
||||
ip4_addr_t *ipAddr = NULL;
|
||||
ip4_addr_t *netMask = NULL;
|
||||
|
||||
netif = netif_find(ifName);
|
||||
if (netif == NULL) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "netif is NULL!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
#ifdef HISPARK_PEGASUS_USE_NETIF_GET_ADDR
|
||||
netifapi_netif_get_addr(netif, ipAddr, netMask, NULL);
|
||||
#else
|
||||
ipAddr = (ip4_addr_t *)netif_ip4_addr(netif);
|
||||
netMask = (ip4_addr_t *)netif_ip4_netmask(netif);
|
||||
#endif
|
||||
ipStr = ip4addr_ntoa(ipAddr);
|
||||
if (strncpy_s(ip, len, ipStr, strlen(ipStr)) != EOK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy ip failed!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (netmask != NULL) {
|
||||
netMaskStr = ip4addr_ntoa(netMask);
|
||||
if (strncpy_s(netmask, len, netMaskStr, strlen(netMaskStr)) != EOK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy netmask failed!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
@ -1,302 +1,302 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_crypto.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/platform.h"
|
||||
#include "softbus_adapter_file.h"
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#ifndef MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_MD_C
|
||||
#define MBEDTLS_MD_C
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#endif
|
||||
|
||||
static pthread_mutex_t g_randomLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int32_t MbedAesGcmEncrypt(const AesGcmCipherKey *cipherkey, const unsigned char *plainText,
|
||||
uint32_t plainTextSize, unsigned char *cipherText, uint32_t cipherTextLen)
|
||||
{
|
||||
if ((cipherkey == NULL) || (plainText == NULL) || (plainTextSize == 0) || cipherText == NULL ||
|
||||
(cipherTextLen < plainTextSize + OVERHEAD_LEN)) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "Encrypt invalid para\n");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int32_t ret;
|
||||
unsigned char tagBuf[TAG_LEN] = {0};
|
||||
mbedtls_gcm_context aesContext;
|
||||
mbedtls_gcm_init(&aesContext);
|
||||
|
||||
ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, cipherkey->key, cipherkey->keyLen * KEY_BITS_UNIT);
|
||||
if (ret != 0) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_crypt_and_tag(&aesContext, MBEDTLS_GCM_ENCRYPT, plainTextSize, cipherkey->iv,
|
||||
GCM_IV_LEN, NULL, 0, plainText, cipherText + GCM_IV_LEN, TAG_LEN, tagBuf);
|
||||
if (ret != 0) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(cipherText, cipherTextLen, cipherkey->iv, GCM_IV_LEN) != EOK) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(cipherText + GCM_IV_LEN + plainTextSize, cipherTextLen - GCM_IV_LEN - plainTextSize,
|
||||
tagBuf, TAG_LEN) != 0) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return (plainTextSize + OVERHEAD_LEN);
|
||||
}
|
||||
|
||||
static int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigned char *cipherText,
|
||||
uint32_t cipherTextSize, unsigned char *plain, uint32_t plainLen)
|
||||
{
|
||||
if ((cipherkey == NULL) || (cipherText == NULL) || (cipherTextSize <= OVERHEAD_LEN) || plain == NULL ||
|
||||
(plainLen < cipherTextSize - OVERHEAD_LEN)) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt invalid para\n");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
mbedtls_gcm_context aesContext;
|
||||
mbedtls_gcm_init(&aesContext);
|
||||
int32_t ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, cipherkey->key,
|
||||
cipherkey->keyLen * KEY_BITS_UNIT);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt mbedtls_gcm_setkey fail\n");
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_DECRYPT_ERR;
|
||||
}
|
||||
|
||||
int32_t actualPlainLen = (int32_t)(cipherTextSize - OVERHEAD_LEN);
|
||||
ret = mbedtls_gcm_auth_decrypt(&aesContext, cipherTextSize - OVERHEAD_LEN, cipherkey->iv,
|
||||
GCM_IV_LEN, NULL, 0, cipherText + actualPlainLen + GCM_IV_LEN, TAG_LEN, cipherText + GCM_IV_LEN, plain);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] Decrypt mbedtls_gcm_auth_decrypt fail.[%d]\n", ret);
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_DECRYPT_ERR;
|
||||
}
|
||||
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return actualPlainLen;
|
||||
}
|
||||
|
||||
int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen)
|
||||
{
|
||||
if (dst == NULL || dlen == 0 || olen == NULL || src == NULL || slen == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return mbedtls_base64_encode(dst, dlen, olen, src, slen);
|
||||
}
|
||||
|
||||
int32_t SoftBusBase64Decode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen)
|
||||
{
|
||||
if (dst == NULL || dlen == 0 || olen == NULL || src == NULL || slen == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return mbedtls_base64_decode(dst, dlen, olen, src, slen);
|
||||
}
|
||||
|
||||
int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash)
|
||||
{
|
||||
if (str == NULL || hash == NULL || len == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
mbedtls_md_context_t ctx;
|
||||
const mbedtls_md_info_t *info = NULL;
|
||||
mbedtls_md_init(&ctx);
|
||||
|
||||
info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
|
||||
if (mbedtls_md_setup(&ctx, info, 0) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (mbedtls_md_starts(&ctx) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (mbedtls_md_update(&ctx, str, len) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (mbedtls_md_finish(&ctx, hash) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
|
||||
{
|
||||
if (randStr == NULL || len == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
static mbedtls_entropy_context entropy;
|
||||
static mbedtls_ctr_drbg_context ctrDrbg;
|
||||
static bool initFlag = false;
|
||||
int32_t ret;
|
||||
|
||||
if (pthread_mutex_lock(&g_randomLock) != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "lock mutex failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (initFlag == false) {
|
||||
mbedtls_ctr_drbg_init(&ctrDrbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
ret = mbedtls_ctr_drbg_seed(&ctrDrbg, mbedtls_entropy_func, &entropy, NULL, 0);
|
||||
if (ret != 0) {
|
||||
pthread_mutex_unlock(&g_randomLock);
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random seed error, ret[%d]", ret);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
initFlag = true;
|
||||
}
|
||||
|
||||
ret = mbedtls_ctr_drbg_random(&ctrDrbg, randStr, len);
|
||||
pthread_mutex_unlock(&g_randomLock);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random error, ret[%d]", ret);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGenerateSessionKey(char *key, uint32_t len)
|
||||
{
|
||||
if (SoftBusGenerateRandomArray((unsigned char*)key, len) != SOFTBUS_OK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate sessionKey error.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusEncryptData(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen)
|
||||
{
|
||||
if (cipherKey == NULL || input == NULL || inLen == 0 || encryptData == NULL || encryptLen == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
uint32_t outLen = inLen + OVERHEAD_LEN;
|
||||
int32_t result = MbedAesGcmEncrypt(cipherKey, input, inLen, encryptData, outLen);
|
||||
if (result <= 0) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
*encryptLen = result;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusEncryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen, int32_t seqNum)
|
||||
{
|
||||
if (cipherKey == NULL || input == NULL || inLen == 0 || encryptData == NULL || encryptLen == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (memcpy_s(cipherKey->iv, sizeof(int32_t), &seqNum, sizeof(int32_t)) != EOK) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
uint32_t outLen = inLen + OVERHEAD_LEN;
|
||||
int32_t result = MbedAesGcmEncrypt(cipherKey, input, inLen, encryptData, outLen);
|
||||
if (result <= 0) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
*encryptLen = result;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *decryptData, uint32_t *decryptLen)
|
||||
{
|
||||
if (cipherKey == NULL || input == NULL || inLen < GCM_IV_LEN || decryptData == NULL || decryptLen == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (memcpy_s(cipherKey->iv, sizeof(cipherKey->iv), input, GCM_IV_LEN) != EOK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy iv failed.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
uint32_t outLen = inLen - OVERHEAD_LEN;
|
||||
int32_t result = MbedAesGcmDecrypt(cipherKey, input, inLen, decryptData, outLen);
|
||||
if (result <= 0) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
*decryptLen = (uint32_t)result;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDecryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *decryptData, uint32_t *decryptLen, int32_t seqNum)
|
||||
{
|
||||
(void)seqNum;
|
||||
return SoftBusDecryptData(cipherKey, input, inLen, decryptData, decryptLen);
|
||||
}
|
||||
|
||||
uint32_t SoftBusCryptoRand(void)
|
||||
{
|
||||
int32_t fd = SoftBusOpenFile("/dev/urandom", SOFTBUS_O_RDONLY);
|
||||
if (fd < 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand open file fail");
|
||||
return 0;
|
||||
}
|
||||
uint32_t value = 0;
|
||||
int32_t len = SoftBusReadFile(fd, &value, sizeof(uint32_t));
|
||||
if (len < 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand read file fail");
|
||||
return 0;
|
||||
}
|
||||
SoftBusCloseFile(fd);
|
||||
return value;
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_crypto.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/platform.h"
|
||||
#include "softbus_adapter_file.h"
|
||||
#include "softbus_adapter_log.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#ifndef MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_MD_C
|
||||
#define MBEDTLS_MD_C
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#endif
|
||||
|
||||
static pthread_mutex_t g_randomLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int32_t MbedAesGcmEncrypt(const AesGcmCipherKey *cipherkey, const unsigned char *plainText,
|
||||
uint32_t plainTextSize, unsigned char *cipherText, uint32_t cipherTextLen)
|
||||
{
|
||||
if ((cipherkey == NULL) || (plainText == NULL) || (plainTextSize == 0) || cipherText == NULL ||
|
||||
(cipherTextLen < plainTextSize + OVERHEAD_LEN)) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "Encrypt invalid para\n");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int32_t ret;
|
||||
unsigned char tagBuf[TAG_LEN] = {0};
|
||||
mbedtls_gcm_context aesContext;
|
||||
mbedtls_gcm_init(&aesContext);
|
||||
|
||||
ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, cipherkey->key, cipherkey->keyLen * KEY_BITS_UNIT);
|
||||
if (ret != 0) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
ret = mbedtls_gcm_crypt_and_tag(&aesContext, MBEDTLS_GCM_ENCRYPT, plainTextSize, cipherkey->iv,
|
||||
GCM_IV_LEN, NULL, 0, plainText, cipherText + GCM_IV_LEN, TAG_LEN, tagBuf);
|
||||
if (ret != 0) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(cipherText, cipherTextLen, cipherkey->iv, GCM_IV_LEN) != EOK) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(cipherText + GCM_IV_LEN + plainTextSize, cipherTextLen - GCM_IV_LEN - plainTextSize,
|
||||
tagBuf, TAG_LEN) != 0) {
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return (plainTextSize + OVERHEAD_LEN);
|
||||
}
|
||||
|
||||
static int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigned char *cipherText,
|
||||
uint32_t cipherTextSize, unsigned char *plain, uint32_t plainLen)
|
||||
{
|
||||
if ((cipherkey == NULL) || (cipherText == NULL) || (cipherTextSize <= OVERHEAD_LEN) || plain == NULL ||
|
||||
(plainLen < cipherTextSize - OVERHEAD_LEN)) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt invalid para\n");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
mbedtls_gcm_context aesContext;
|
||||
mbedtls_gcm_init(&aesContext);
|
||||
int32_t ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, cipherkey->key,
|
||||
cipherkey->keyLen * KEY_BITS_UNIT);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt mbedtls_gcm_setkey fail\n");
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_DECRYPT_ERR;
|
||||
}
|
||||
|
||||
int32_t actualPlainLen = (int32_t)(cipherTextSize - OVERHEAD_LEN);
|
||||
ret = mbedtls_gcm_auth_decrypt(&aesContext, cipherTextSize - OVERHEAD_LEN, cipherkey->iv,
|
||||
GCM_IV_LEN, NULL, 0, cipherText + actualPlainLen + GCM_IV_LEN, TAG_LEN, cipherText + GCM_IV_LEN, plain);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] Decrypt mbedtls_gcm_auth_decrypt fail.[%d]\n", ret);
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return SOFTBUS_DECRYPT_ERR;
|
||||
}
|
||||
|
||||
mbedtls_gcm_free(&aesContext);
|
||||
return actualPlainLen;
|
||||
}
|
||||
|
||||
int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen)
|
||||
{
|
||||
if (dst == NULL || dlen == 0 || olen == NULL || src == NULL || slen == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return mbedtls_base64_encode(dst, dlen, olen, src, slen);
|
||||
}
|
||||
|
||||
int32_t SoftBusBase64Decode(unsigned char *dst, size_t dlen,
|
||||
size_t *olen, const unsigned char *src, size_t slen)
|
||||
{
|
||||
if (dst == NULL || dlen == 0 || olen == NULL || src == NULL || slen == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
return mbedtls_base64_decode(dst, dlen, olen, src, slen);
|
||||
}
|
||||
|
||||
int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash)
|
||||
{
|
||||
if (str == NULL || hash == NULL || len == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
mbedtls_md_context_t ctx;
|
||||
const mbedtls_md_info_t *info = NULL;
|
||||
mbedtls_md_init(&ctx);
|
||||
|
||||
info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
|
||||
if (mbedtls_md_setup(&ctx, info, 0) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (mbedtls_md_starts(&ctx) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (mbedtls_md_update(&ctx, str, len) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (mbedtls_md_finish(&ctx, hash) != 0) {
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
|
||||
mbedtls_md_free(&ctx);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
|
||||
{
|
||||
if (randStr == NULL || len == 0) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
static mbedtls_entropy_context entropy;
|
||||
static mbedtls_ctr_drbg_context ctrDrbg;
|
||||
static bool initFlag = false;
|
||||
int32_t ret;
|
||||
|
||||
if (pthread_mutex_lock(&g_randomLock) != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "lock mutex failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (initFlag == false) {
|
||||
mbedtls_ctr_drbg_init(&ctrDrbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
ret = mbedtls_ctr_drbg_seed(&ctrDrbg, mbedtls_entropy_func, &entropy, NULL, 0);
|
||||
if (ret != 0) {
|
||||
pthread_mutex_unlock(&g_randomLock);
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random seed error, ret[%d]", ret);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
initFlag = true;
|
||||
}
|
||||
|
||||
ret = mbedtls_ctr_drbg_random(&ctrDrbg, randStr, len);
|
||||
pthread_mutex_unlock(&g_randomLock);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random error, ret[%d]", ret);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGenerateSessionKey(char *key, uint32_t len)
|
||||
{
|
||||
if (SoftBusGenerateRandomArray((unsigned char*)key, len) != SOFTBUS_OK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate sessionKey error.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusEncryptData(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen)
|
||||
{
|
||||
if (cipherKey == NULL || input == NULL || inLen == 0 || encryptData == NULL || encryptLen == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
uint32_t outLen = inLen + OVERHEAD_LEN;
|
||||
int32_t result = MbedAesGcmEncrypt(cipherKey, input, inLen, encryptData, outLen);
|
||||
if (result <= 0) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
*encryptLen = result;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusEncryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *encryptData, uint32_t *encryptLen, int32_t seqNum)
|
||||
{
|
||||
if (cipherKey == NULL || input == NULL || inLen == 0 || encryptData == NULL || encryptLen == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
if (memcpy_s(cipherKey->iv, sizeof(int32_t), &seqNum, sizeof(int32_t)) != EOK) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
uint32_t outLen = inLen + OVERHEAD_LEN;
|
||||
int32_t result = MbedAesGcmEncrypt(cipherKey, input, inLen, encryptData, outLen);
|
||||
if (result <= 0) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
*encryptLen = result;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *decryptData, uint32_t *decryptLen)
|
||||
{
|
||||
if (cipherKey == NULL || input == NULL || inLen < GCM_IV_LEN || decryptData == NULL || decryptLen == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (memcpy_s(cipherKey->iv, sizeof(cipherKey->iv), input, GCM_IV_LEN) != EOK) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy iv failed.");
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
uint32_t outLen = inLen - OVERHEAD_LEN;
|
||||
int32_t result = MbedAesGcmDecrypt(cipherKey, input, inLen, decryptData, outLen);
|
||||
if (result <= 0) {
|
||||
return SOFTBUS_ENCRYPT_ERR;
|
||||
}
|
||||
*decryptLen = (uint32_t)result;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDecryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen,
|
||||
unsigned char *decryptData, uint32_t *decryptLen, int32_t seqNum)
|
||||
{
|
||||
(void)seqNum;
|
||||
return SoftBusDecryptData(cipherKey, input, inLen, decryptData, decryptLen);
|
||||
}
|
||||
|
||||
uint32_t SoftBusCryptoRand(void)
|
||||
{
|
||||
int32_t fd = SoftBusOpenFile("/dev/urandom", SOFTBUS_O_RDONLY);
|
||||
if (fd < 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand open file fail");
|
||||
return 0;
|
||||
}
|
||||
uint32_t value = 0;
|
||||
int32_t len = SoftBusReadFile(fd, &value, sizeof(uint32_t));
|
||||
if (len < 0) {
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand read file fail");
|
||||
return 0;
|
||||
}
|
||||
SoftBusCloseFile(fd);
|
||||
return value;
|
||||
}
|
||||
|
@ -1,327 +1,327 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "bus_center_server_proxy.h"
|
||||
#include "bus_center_server_proxy_standard.h"
|
||||
|
||||
#include <mutex>
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_ipc_def.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
using namespace OHOS;
|
||||
|
||||
namespace {
|
||||
sptr<BusCenterServerProxy> g_serverProxy = nullptr;
|
||||
uint32_t g_getSystemAbilityId = 2;
|
||||
const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
|
||||
std::mutex g_mutex;
|
||||
}
|
||||
|
||||
static sptr<IRemoteObject> GetSystemAbility()
|
||||
{
|
||||
MessageParcel data;
|
||||
|
||||
if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
data.WriteInt32(SOFTBUS_SERVER_SA_ID_INNER);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> samgr = IPCSkeleton::GetContextObject();
|
||||
int32_t err = samgr->SendRequest(g_getSystemAbilityId, data, reply, option);
|
||||
if (err != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Get GetSystemAbility failed!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return reply.ReadRemoteObject();
|
||||
}
|
||||
|
||||
int32_t BusCenterServerProxyInit(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
sptr<IRemoteObject> object = GetSystemAbility();
|
||||
if (object == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Get remote softbus object failed!\n");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_serverProxy = new (std::nothrow) BusCenterServerProxy(object);
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Create bus center server proxy failed!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void BusCenterServerProxyDeInit(void)
|
||||
{
|
||||
delete g_serverProxy;
|
||||
g_serverProxy = nullptr;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int32_t *infoNum)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllOnlineNodeInfo g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetAllOnlineNodeInfo(pkgName, info, infoTypeLen, infoNum);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllOnlineNodeInfo get all online info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetLocalDeviceInfo g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetLocalDeviceInfo(pkgName, info, infoTypeLen);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetLocalDeviceInfo get local device info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf, uint32_t len)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetNodeKeyInfo g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetNodeKeyInfo(pkgName, networkId, key, buf, len);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetNodeKeyInfo get node key info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcSetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcSetNodeDataChangeFlag g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->SetNodeDataChangeFlag(pkgName, networkId, dataChangeFlag);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcSetNodeDataChangeFlag get node key info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcJoinLNN(const char *pkgName, void *addr, unsigned int addrTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinLNN g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->JoinLNN(pkgName, addr, addrTypeLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinLNN failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcJoinMetaNode(const char *pkgName, void *addr, CustomData *customData, unsigned int addrTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinMetaNode g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->JoinMetaNode(pkgName, addr, customData, addrTypeLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinMetaNode failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcLeaveLNN(const char *pkgName, const char *networkId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveLNN g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->LeaveLNN(pkgName, networkId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveLNN failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcLeaveMetaNode(const char *pkgName, const char *networkId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveMetaNode g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->LeaveMetaNode(pkgName, networkId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveMetaNode failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy, int32_t period)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStartTimeSync g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StartTimeSync(pkgName, targetNetworkId, accuracy, period);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStartTimeSync failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopTimeSync g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StopTimeSync(pkgName, targetNetworkId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopTimeSync failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcPublishLNN(const char *pkgName, const void *info, uint32_t infoLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcPublishLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->PublishLNN(pkgName, info, infoLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcPublishLNN failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStopPublishLNN(const char *pkgName, int32_t publishId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StopPublishLNN(pkgName, publishId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcRefreshLNN(const char *pkgName, const void *info, uint32_t infoTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcRefreshLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->RefreshLNN(pkgName, info, infoTypeLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcRefreshLNN failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStopRefreshLNN(const char *pkgName, int32_t refreshId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StopRefreshLNN(pkgName, refreshId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId)
|
||||
{
|
||||
(void)pkgName;
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->ActiveMetaNode(info, metaNodeId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcDeactiveMetaNode(const char *pkgName, const char *metaNodeId)
|
||||
{
|
||||
(void)pkgName;
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->DeactiveMetaNode(metaNodeId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum)
|
||||
{
|
||||
(void)pkgName;
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetAllMetaNodeInfo(infos, infoNum);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId,
|
||||
const GearMode *mode)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcShiftLNNGear g_serverProxy is nullptr!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int ret = g_serverProxy->ShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcShiftLNNGear failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "bus_center_server_proxy.h"
|
||||
#include "bus_center_server_proxy_standard.h"
|
||||
|
||||
#include <mutex>
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_ipc_def.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
using namespace OHOS;
|
||||
|
||||
namespace {
|
||||
sptr<BusCenterServerProxy> g_serverProxy = nullptr;
|
||||
uint32_t g_getSystemAbilityId = 2;
|
||||
const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
|
||||
std::mutex g_mutex;
|
||||
}
|
||||
|
||||
static sptr<IRemoteObject> GetSystemAbility()
|
||||
{
|
||||
MessageParcel data;
|
||||
|
||||
if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
data.WriteInt32(SOFTBUS_SERVER_SA_ID_INNER);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> samgr = IPCSkeleton::GetContextObject();
|
||||
int32_t err = samgr->SendRequest(g_getSystemAbilityId, data, reply, option);
|
||||
if (err != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Get GetSystemAbility failed!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return reply.ReadRemoteObject();
|
||||
}
|
||||
|
||||
int32_t BusCenterServerProxyInit(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
sptr<IRemoteObject> object = GetSystemAbility();
|
||||
if (object == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Get remote softbus object failed!\n");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_serverProxy = new (std::nothrow) BusCenterServerProxy(object);
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Create bus center server proxy failed!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void BusCenterServerProxyDeInit(void)
|
||||
{
|
||||
delete g_serverProxy;
|
||||
g_serverProxy = nullptr;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int32_t *infoNum)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllOnlineNodeInfo g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetAllOnlineNodeInfo(pkgName, info, infoTypeLen, infoNum);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllOnlineNodeInfo get all online info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetLocalDeviceInfo g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetLocalDeviceInfo(pkgName, info, infoTypeLen);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetLocalDeviceInfo get local device info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf, uint32_t len)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetNodeKeyInfo g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetNodeKeyInfo(pkgName, networkId, key, buf, len);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetNodeKeyInfo get node key info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcSetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcSetNodeDataChangeFlag g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->SetNodeDataChangeFlag(pkgName, networkId, dataChangeFlag);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcSetNodeDataChangeFlag get node key info failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcJoinLNN(const char *pkgName, void *addr, unsigned int addrTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinLNN g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->JoinLNN(pkgName, addr, addrTypeLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinLNN failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcJoinMetaNode(const char *pkgName, void *addr, CustomData *customData, unsigned int addrTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinMetaNode g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->JoinMetaNode(pkgName, addr, customData, addrTypeLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinMetaNode failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcLeaveLNN(const char *pkgName, const char *networkId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveLNN g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->LeaveLNN(pkgName, networkId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveLNN failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcLeaveMetaNode(const char *pkgName, const char *networkId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveMetaNode g_serverProxy is nullptr!\n");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->LeaveMetaNode(pkgName, networkId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveMetaNode failed!\n");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy, int32_t period)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStartTimeSync g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StartTimeSync(pkgName, targetNetworkId, accuracy, period);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStartTimeSync failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopTimeSync g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StopTimeSync(pkgName, targetNetworkId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopTimeSync failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcPublishLNN(const char *pkgName, const void *info, uint32_t infoLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcPublishLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->PublishLNN(pkgName, info, infoLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcPublishLNN failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStopPublishLNN(const char *pkgName, int32_t publishId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StopPublishLNN(pkgName, publishId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN failed!");
|
||||
return ret;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t ServerIpcRefreshLNN(const char *pkgName, const void *info, uint32_t infoTypeLen)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcRefreshLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->RefreshLNN(pkgName, info, infoTypeLen);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcRefreshLNN failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcStopRefreshLNN(const char *pkgName, int32_t refreshId)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->StopRefreshLNN(pkgName, refreshId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId)
|
||||
{
|
||||
(void)pkgName;
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->ActiveMetaNode(info, metaNodeId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcDeactiveMetaNode(const char *pkgName, const char *metaNodeId)
|
||||
{
|
||||
(void)pkgName;
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->DeactiveMetaNode(metaNodeId);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcGetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum)
|
||||
{
|
||||
(void)pkgName;
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo g_serverProxy is nullptr!");
|
||||
return SOFTBUS_SERVER_NOT_INIT;
|
||||
}
|
||||
int ret = g_serverProxy->GetAllMetaNodeInfo(infos, infoNum);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ServerIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId,
|
||||
const GearMode *mode)
|
||||
{
|
||||
if (g_serverProxy == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcShiftLNNGear g_serverProxy is nullptr!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int ret = g_serverProxy->ShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
|
||||
if (ret != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcShiftLNNGear failed!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user