diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..4947287
--- /dev/null
+++ b/LICENSE
@@ -0,0 +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.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.en.md b/README.en.md
old mode 100644
new mode 100755
index 0471c0c..efe9ea6
--- a/README.en.md
+++ b/README.en.md
@@ -1,4 +1,4 @@
-# communication_netmanager_standard
+# communication_netmanager_base
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 1165ef4..6a43c1c
--- a/README.md
+++ b/README.md
@@ -1,39 +1,95 @@
-# communication_netmanager_standard
+# Net Manager
-#### 介绍
-{**以下是 Gitee 平台说明,您可以替换此简介**
-Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
-无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
-
-#### 软件架构
-软件架构说明
+- [简介](#section112mcpsimp)
+- [目录](#section125mcpsimp)
+- [约束](#section133mcpsimp)
+- [相关仓](#section155mcpsimp)
-#### 安装教程
-1. xxxx
-2. xxxx
-3. xxxx
+## 简介
-#### 使用说明
+网络管理介绍:
-1. xxxx
-2. xxxx
-3. xxxx
+ 网络管理模块作为电话子系统可裁剪部件,依赖于蜂窝数据管理,主要分为连接管理、策略管理、流量管理、网络共享、VPN管理五大模块;如图1:网络管理架构图;
-#### 参与贡献
+**图 1** 网络管理架构图
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
+
+连接管理介绍:
-#### 特技
+ 负责与蜂窝数据交互,请求到IP后,再与Netd交互并将路由参数设置到内核,使得蜂窝数据连接且可用,最终实现上网,如图2:网络连接架构图;
+
+**图 2** 网络连接架构图
+
+
+
+**图 3** 网络策略架构图
+
+
+
+## 目录
+
+```
+/foundation/communication/netmanager_standard/netmanager_standard/
+├── frameworks # 框架代码
+│ ├── innerkitsimpl # 内部接口实现
+│ │ └── netconnmanager
+│ │ │ └── src
+│ │ └── netpolicymanager
+│ │ └── src
+│ └── js # JS接口实现
+│ └── napi
+│ ├── http
+│ ├── socket
+│ └── websocket
+├── interfaces # 接口代码
+│ ├── innerkits # 内部接口
+│ │ └── native
+│ │ └── netconnmanager
+│ │ │ └── include
+│ │ └── netpolicymanager
+│ │ └── include
+│ └── kits # 外部接口
+│ └── js
+├── sa_profile # 服务配置文件
+├── services # 核心服务代码目录
+│ ├── common # 网络管理公共组件
+│ ├── etc # 网络管理进程配置脚本
+│ │ └── init
+│ ├── netconnmanager # 网络连接管理代码
+│ │ ├── include # 头文件
+│ │ │ ├── ipc # IPC通信头文件
+│ │ │ ├── net_controller # 网络控制
+│ │ ├── src # 源文件目录
+│ │ │ ├── ipc # IPC通信源文件
+│ │ │ ├── net_controller # 网络控制实现
+│ │ └── test # 单元测试代码
+│ ├── netpolicymanager # 网络策略管理代码
+│ │ ├── include # 头文件
+│ │ │ └── ipc # IPC通信头文件
+│ │ ├── src # 源文件目录
+│ │ │ └── ipc # IPC通信源文件
+│ │ └── test # 单元测试代码
+│ ├── netmanagernative # Netd代码
+│ └── prebuild # 预编译库文件
+└── utils # 公共功能实现
+| └── log # 日志实现
+└── ohos.build # 编译文件
+```
+
+## 约束
+
+- 开发语言:C++
+- 软件层,需要以下子系统和服务配合使用:蜂窝数据、安全子系统、软总线子系统、USB子系统、电源管理子系统等;
+- 硬件层,需要搭载的设备支持以下硬件:可以进行独立蜂窝通信的Modem以及SIM卡;
+
+## 相关仓
+
+[netmanager_standard](https://gitee.com/openharmony/communication_netmanager_standard/blob/master/README.md)
+
+[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E7%94%B5%E8%AF%9D%E6%9C%8D%E5%8A%A1%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
+
+[ telephony_cellular_data](https://gitee.com/openharmony/telephony_cellular_data/blob/master/README.md)
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/figures/net_conn_manager_arch_zh.png b/figures/net_conn_manager_arch_zh.png
new file mode 100755
index 0000000..bef52c5
Binary files /dev/null and b/figures/net_conn_manager_arch_zh.png differ
diff --git a/figures/net_manager_arch_zh.png b/figures/net_manager_arch_zh.png
new file mode 100755
index 0000000..5c247ab
Binary files /dev/null and b/figures/net_manager_arch_zh.png differ
diff --git a/figures/net_policy_manager_arch_zh.png b/figures/net_policy_manager_arch_zh.png
new file mode 100755
index 0000000..bc88209
Binary files /dev/null and b/figures/net_policy_manager_arch_zh.png differ
diff --git a/figures/net_stats_manager_arch_zh.png b/figures/net_stats_manager_arch_zh.png
new file mode 100755
index 0000000..b1ed2be
Binary files /dev/null and b/figures/net_stats_manager_arch_zh.png differ
diff --git a/frameworks/innerkitsimpl/dnsresolvermanager/src/dns_addr_info.cpp b/frameworks/innerkitsimpl/dnsresolvermanager/src/dns_addr_info.cpp
new file mode 100755
index 0000000..70fadb2
--- /dev/null
+++ b/frameworks/innerkitsimpl/dnsresolvermanager/src/dns_addr_info.cpp
@@ -0,0 +1,67 @@
+/*
+ * 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 "dns_addr_info.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool DnsAddrInfo::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteInt32(flags_)) {
+ return false;
+ }
+ if (!parcel.WriteInt32(family_)) {
+ return false;
+ }
+ if (!parcel.WriteInt32(sockType_)) {
+ return false;
+ }
+ if (!parcel.WriteInt32(protocol_)) {
+ return false;
+ }
+ if (!parcel.WriteString(addr_)) {
+ return false;
+ }
+ return true;
+}
+
+sptr DnsAddrInfo::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ NETMGR_LOGE("create DnsAddrInfo failed");
+ return nullptr;
+ }
+ if (!parcel.ReadInt32(ptr->flags_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadInt32(ptr->family_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadInt32(ptr->sockType_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadInt32(ptr->protocol_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->addr_)) {
+ return nullptr;
+ }
+ return ptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/dnsresolvermanager/src/dns_resolver_client.cpp b/frameworks/innerkitsimpl/dnsresolvermanager/src/dns_resolver_client.cpp
new file mode 100755
index 0000000..ab9edfd
--- /dev/null
+++ b/frameworks/innerkitsimpl/dnsresolvermanager/src/dns_resolver_client.cpp
@@ -0,0 +1,154 @@
+/*
+ * 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 "dns_resolver_client.h"
+
+#include "iservice_registry.h"
+#include "system_ability_definition.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+DnsResolverClient::DnsResolverClient() : dnsResolverService_(nullptr), deathRecipient_(nullptr) {}
+
+DnsResolverClient::~DnsResolverClient() {}
+
+int32_t DnsResolverClient::GetAddressesByName(const std::string &hostName, std::vector &addrInfo)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->GetAddressesByName(hostName, addrInfo);
+}
+
+int32_t DnsResolverClient::GetAddrInfo(const std::string &hostName, const std::string &server,
+ const sptr &hints, std::vector> &dnsAddrInfo)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->GetAddrInfo(hostName, server, hints, dnsAddrInfo);
+}
+
+int32_t DnsResolverClient::CreateNetworkCache(uint16_t netId)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->CreateNetworkCache(netId);
+}
+
+int32_t DnsResolverClient::DestoryNetworkCache(uint16_t netId)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->DestoryNetworkCache(netId);
+}
+
+int32_t DnsResolverClient::FlushNetworkCache(uint16_t netId)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->FlushNetworkCache(netId);
+}
+
+int32_t DnsResolverClient::SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
+ const std::vector &servers, const std::vector &domains)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->SetResolverConfig(netId, baseTimeoutMsec, retryCount, servers, domains);
+}
+
+int32_t DnsResolverClient::GetResolverInfo(uint16_t netId, std::vector &servers,
+ std::vector &domains, uint16_t &baseTimeoutMsec, uint8_t &retryCount)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->GetResolverInfo(netId, servers, domains, baseTimeoutMsec, retryCount);
+}
+
+sptr DnsResolverClient::GetProxy()
+{
+ std::lock_guard lock(mutex_);
+ if (dnsResolverService_) {
+ NETMGR_LOGI("get proxy is ok");
+ return dnsResolverService_;
+ }
+ NETMGR_LOGI("execute GetSystemAbilityManager");
+ sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ if (sam == nullptr) {
+ NETMGR_LOGE("GetProxy, get SystemAbilityManager failed");
+ return nullptr;
+ }
+ sptr remote = sam->CheckSystemAbility(COMM_DNS_MANAGER_SYS_ABILITY_ID);
+ if (remote == nullptr) {
+ NETMGR_LOGE("get Remote service failed");
+ return nullptr;
+ }
+ deathRecipient_ = (std::make_unique(*this)).release();
+ if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
+ NETMGR_LOGE("add death recipient failed");
+ return nullptr;
+ }
+ dnsResolverService_ = iface_cast(remote);
+ if (dnsResolverService_ == nullptr) {
+ NETMGR_LOGE("get Remote service proxy failed");
+ return nullptr;
+ }
+ return dnsResolverService_;
+}
+
+void DnsResolverClient::OnRemoteDied(const wptr &remote)
+{
+ NETMGR_LOGI("on remote died");
+ if (remote == nullptr) {
+ NETMGR_LOGE("remote object is nullptr");
+ return;
+ }
+ std::lock_guard lock(mutex_);
+ if (dnsResolverService_ == nullptr) {
+ NETMGR_LOGE("dnsResolverService_ is nullptr");
+ return;
+ }
+ sptr local = dnsResolverService_->AsObject();
+ if (local != remote.promote()) {
+ NETMGR_LOGE("proxy and stub is not same remote object");
+ return;
+ }
+ local->RemoveDeathRecipient(deathRecipient_);
+ dnsResolverService_ = nullptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/ethernetmanager/src/ethernet_client.cpp b/frameworks/innerkitsimpl/ethernetmanager/src/ethernet_client.cpp
new file mode 100755
index 0000000..0395477
--- /dev/null
+++ b/frameworks/innerkitsimpl/ethernetmanager/src/ethernet_client.cpp
@@ -0,0 +1,120 @@
+/*
+ * 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 "ethernet_client.h"
+
+#include "iservice_registry.h"
+#include "system_ability_definition.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+EthernetClient::EthernetClient() : ethernetService_(nullptr), deathRecipient_(nullptr) {}
+
+EthernetClient::~EthernetClient() {}
+
+int32_t EthernetClient::SetIfaceConfig(const std::string &iface, sptr &ic)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->SetIfaceConfig(iface, ic);
+}
+
+sptr EthernetClient::GetIfaceConfig(const std::string &iface)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return nullptr;
+ }
+ return proxy->GetIfaceConfig(iface);
+}
+int32_t EthernetClient::IsActivate(const std::string &iface)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->IsActivate(iface);
+}
+
+std::vector EthernetClient::GetActivateInterfaces()
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return {};
+ }
+ return proxy->GetActivateInterfaces();
+}
+
+sptr EthernetClient::GetProxy()
+{
+ std::lock_guard lock(mutex_);
+ if (ethernetService_) {
+ NETMGR_LOGI("get proxy is ok");
+ return ethernetService_;
+ }
+ NETMGR_LOGI("execute GetSystemAbilityManager");
+ sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ if (sam == nullptr) {
+ NETMGR_LOGE("GetProxy, get SystemAbilityManager failed");
+ return nullptr;
+ }
+ sptr remote = sam->CheckSystemAbility(COMM_ETHERNET_MANAGER_SYS_ABILITY_ID);
+ if (remote == nullptr) {
+ NETMGR_LOGE("get Remote service failed");
+ return nullptr;
+ }
+ deathRecipient_ = (std::make_unique(*this)).release();
+ if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
+ NETMGR_LOGE("add death recipient failed");
+ return nullptr;
+ }
+ ethernetService_ = iface_cast(remote);
+ if (ethernetService_ == nullptr) {
+ NETMGR_LOGE("get Remote service proxy failed");
+ return nullptr;
+ }
+ return ethernetService_;
+}
+
+void EthernetClient::OnRemoteDied(const wptr &remote)
+{
+ NETMGR_LOGI("on remote died");
+ if (remote == nullptr) {
+ NETMGR_LOGE("remote object is nullptr");
+ return;
+ }
+ std::lock_guard lock(mutex_);
+ if (ethernetService_ == nullptr) {
+ NETMGR_LOGE("ethernetService_ is nullptr");
+ return;
+ }
+ sptr local = ethernetService_->AsObject();
+ if (local != remote.promote()) {
+ NETMGR_LOGE("proxy and stub is not same remote object");
+ return;
+ }
+ local->RemoveDeathRecipient(deathRecipient_);
+ ethernetService_ = nullptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/ethernetmanager/src/interface_configuration.cpp b/frameworks/innerkitsimpl/ethernetmanager/src/interface_configuration.cpp
new file mode 100755
index 0000000..b744bc9
--- /dev/null
+++ b/frameworks/innerkitsimpl/ethernetmanager/src/interface_configuration.cpp
@@ -0,0 +1,53 @@
+/*
+ * 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 "interface_configuration.h"
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool InterfaceConfiguration::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteInt32(static_cast(mode_))) {
+ return false;
+ }
+ if (!ipStatic_.Marshalling(parcel)) {
+ NETMGR_LOGE("write ipStatic_ to parcel failed");
+ return false;
+ }
+ return true;
+}
+
+sptr InterfaceConfiguration::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ return nullptr;
+ }
+ int32_t mode = 0;
+ if (!parcel.ReadInt32(mode)) {
+ return nullptr;
+ }
+ ptr->mode_ = static_cast(mode);
+ sptr sc = StaticConfiguration::Unmarshalling(parcel);
+ if (sc == nullptr) {
+ NETMGR_LOGE("sc is null");
+ return nullptr;
+ }
+ ptr->ipStatic_ = *sc;
+ return ptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/ethernetmanager/src/static_configuration.cpp b/frameworks/innerkitsimpl/ethernetmanager/src/static_configuration.cpp
new file mode 100755
index 0000000..cce72d0
--- /dev/null
+++ b/frameworks/innerkitsimpl/ethernetmanager/src/static_configuration.cpp
@@ -0,0 +1,105 @@
+/*
+ * 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 "static_configuration.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool StaticConfiguration::Marshalling(Parcel &parcel) const
+{
+ if (!ipAddr_.Marshalling(parcel)) {
+ NETMGR_LOGE("write ipAddr_ to parcel failed");
+ return false;
+ }
+ if (!route_.Marshalling(parcel)) {
+ NETMGR_LOGE("write route_ to parcel failed");
+ return false;
+ }
+ if (!gate_.Marshalling(parcel)) {
+ NETMGR_LOGE("write gate_ to parcel failed");
+ return false;
+ }
+ if (!netMask_.Marshalling(parcel)) {
+ NETMGR_LOGE("write netMask_ to parcel failed");
+ return false;
+ }
+ if (!parcel.WriteUint32(dnsServers_.size())) {
+ NETMGR_LOGE("write dnsServers_ size to parcel failed");
+ return false;
+ }
+ for (auto it = dnsServers_.begin(); it != dnsServers_.end(); ++it) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write dnsServers_ to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteString(domain_)) {
+ NETMGR_LOGE("write domain_ to parcel failed");
+ return false;
+ }
+ return true;
+}
+
+sptr StaticConfiguration::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ return nullptr;
+ }
+ sptr ipAddr = INetAddr::Unmarshalling(parcel);
+ if (ipAddr == nullptr) {
+ NETMGR_LOGE("ipAddr_ is null");
+ return nullptr;
+ }
+ ptr->ipAddr_ = *ipAddr;
+ sptr route = INetAddr::Unmarshalling(parcel);
+ if (route == nullptr) {
+ NETMGR_LOGE("route_ is null");
+ return nullptr;
+ }
+ ptr->route_ = *route;
+ sptr gate = INetAddr::Unmarshalling(parcel);
+ if (gate == nullptr) {
+ NETMGR_LOGE("gate_ is null");
+ return nullptr;
+ }
+ ptr->gate_ = *gate;
+ sptr netMask = INetAddr::Unmarshalling(parcel);
+ if (netMask == nullptr) {
+ NETMGR_LOGE("netMask_ is null");
+ return nullptr;
+ }
+ ptr->netMask_ = *netMask;
+ uint32_t size = 0;
+ if (!parcel.ReadUint32(size)) {
+ return nullptr;
+ }
+ for (uint32_t i = 0; i < size; i++) {
+ sptr netAddr = INetAddr::Unmarshalling(parcel);
+ if (netAddr == nullptr) {
+ NETMGR_LOGE("netAddr is null");
+ return nullptr;
+ }
+ ptr->dnsServers_.push_back(*netAddr);
+ }
+ if (!parcel.ReadString(ptr->domain_)) {
+ return nullptr;
+ }
+ return ptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/inet_addr.cpp b/frameworks/innerkitsimpl/netconnmanager/src/inet_addr.cpp
new file mode 100755
index 0000000..ea08d61
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/inet_addr.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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 "inet_addr.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool INetAddr::operator==(const INetAddr &obj) const
+{
+ bool out = true;
+ out = out && (type_ == obj.type_);
+ out = out && (family_ == obj.family_);
+ out = out && (prefixlen_ == obj.prefixlen_);
+ out = out && (address_ == obj.address_);
+ out = out && (netMask_ == obj.netMask_);
+ out = out && (hostName_ == obj.hostName_);
+ return out;
+}
+
+bool INetAddr::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteUint8(type_)) {
+ return false;
+ }
+ if (!parcel.WriteUint8(family_)) {
+ return false;
+ }
+ if (!parcel.WriteUint8(prefixlen_)) {
+ return false;
+ }
+ if (!parcel.WriteString(address_)) {
+ return false;
+ }
+ if (!parcel.WriteString(netMask_)) {
+ return false;
+ }
+ if (!parcel.WriteString(hostName_)) {
+ return false;
+ }
+ return true;
+}
+
+sptr INetAddr::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ NETMGR_LOGE("create INetAddr failed");
+ return nullptr;
+ }
+ if (!parcel.ReadUint8(ptr->type_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadUint8(ptr->family_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadUint8(ptr->prefixlen_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->address_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->netMask_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->hostName_)) {
+ return nullptr;
+ }
+ return ptr;
+}
+
+bool INetAddr::Marshalling(Parcel &parcel, const sptr &object)
+{
+ if (object == nullptr) {
+ NETMGR_LOGE("INetAddr object ptr is nullptr");
+ return false;
+ }
+ if (!parcel.WriteUint8(object->type_)) {
+ return false;
+ }
+ if (!parcel.WriteUint8(object->family_)) {
+ return false;
+ }
+ if (!parcel.WriteUint8(object->prefixlen_)) {
+ return false;
+ }
+ if (!parcel.WriteString(object->address_)) {
+ return false;
+ }
+ if (!parcel.WriteString(object->netMask_)) {
+ return false;
+ }
+ if (!parcel.WriteString(object->hostName_)) {
+ return false;
+ }
+ return true;
+}
+
+std::string INetAddr::ToString(const std::string tab) const
+{
+ std::string familyStr = std::to_string(family_);
+ std::string prefixlenStr = std::to_string(prefixlen_);
+ std::string jsonStr = "{";
+ jsonStr += "\"family_\"";
+ jsonStr += ":";
+ jsonStr += "\"" + familyStr + "\",";
+
+ jsonStr += "\"prefixlen_\"";
+ jsonStr += ":";
+ jsonStr += "\"" + prefixlenStr + "\",";
+
+ jsonStr += "\"address_\"";
+ jsonStr += ":";
+ jsonStr += "\"" + address_ + "\",";
+
+ jsonStr += "\"netMask_\"";
+ jsonStr += ":";
+ jsonStr += "\"" + netMask_ + "\"";
+ jsonStr += "}";
+ return jsonStr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/ipc/net_conn_callback_stub.cpp b/frameworks/innerkitsimpl/netconnmanager/src/ipc/net_conn_callback_stub.cpp
new file mode 100755
index 0000000..644ee7c
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/ipc/net_conn_callback_stub.cpp
@@ -0,0 +1,67 @@
+/*
+ * 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 "net_conn_callback_stub.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+NetConnCallbackStub::NetConnCallbackStub()
+{
+ memberFuncMap_[NET_CONN_STATE_CHANGED] = &NetConnCallbackStub::OnNetConnStateChanged;
+}
+
+NetConnCallbackStub::~NetConnCallbackStub() {}
+
+int32_t NetConnCallbackStub::OnRemoteRequest(
+ uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
+{
+ NETMGR_LOGI("Stub call start, code:[%{public}d]", code);
+ std::u16string myDescripter = NetConnCallbackStub::GetDescriptor();
+ std::u16string remoteDescripter = data.ReadInterfaceToken();
+ if (myDescripter != remoteDescripter) {
+ NETMGR_LOGE("Descriptor checked failed");
+ return ERR_FLATTEN_OBJECT;
+ }
+
+ auto itFunc = memberFuncMap_.find(code);
+ if (itFunc != memberFuncMap_.end()) {
+ auto requestFunc = itFunc->second;
+ if (requestFunc != nullptr) {
+ return (this->*requestFunc)(data, reply);
+ }
+ }
+
+ NETMGR_LOGI("Stub default case, need check");
+ return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+}
+
+int32_t NetConnCallbackStub::OnNetConnStateChanged(MessageParcel &data, MessageParcel &reply)
+{
+ if (!data.ContainFileDescriptors()) {
+ NETMGR_LOGE("Execute ContainFileDescriptors failed");
+ }
+
+ sptr info = NetConnCallbackInfo::Unmarshalling(data);
+ int32_t result = NetConnStateChanged(info);
+ if (!reply.WriteInt32(result)) {
+ NETMGR_LOGE("Write parcel failed");
+ return result;
+ }
+
+ return ERR_NONE;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/net_conn_callback_info.cpp b/frameworks/innerkitsimpl/netconnmanager/src/net_conn_callback_info.cpp
new file mode 100755
index 0000000..d50771a
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/net_conn_callback_info.cpp
@@ -0,0 +1,91 @@
+/*
+ * 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 "net_conn_callback_info.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool NetConnCallbackInfo::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteInt32(netState_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(netType_)) {
+ return false;
+ }
+
+ return true;
+}
+
+sptr NetConnCallbackInfo::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ NETMGR_LOGE("The parameter of ptr is nullptr");
+ return nullptr;
+ }
+
+ if (!parcel.ReadInt32(ptr->netState_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadUint32(ptr->netType_)) {
+ return nullptr;
+ }
+
+ return ptr;
+}
+
+bool NetConnCallbackInfo::Marshalling(Parcel &parcel, const sptr &object)
+{
+ if (object == nullptr) {
+ NETMGR_LOGE("NetConnCallbackInfo object is nullptr");
+ return false;
+ }
+
+ if (!parcel.WriteInt32(object->netState_)) {
+ NETMGR_LOGE("Write netState_ failed");
+ return false;
+ }
+ if (!parcel.WriteUint32(object->netType_)) {
+ NETMGR_LOGE("Write netType_ failed");
+ return false;
+ }
+
+ return true;
+}
+
+std::string NetConnCallbackInfo::ToString(const std::string &tab) const
+{
+ std::string str;
+ str.append("\n");
+ str.append(tab);
+ str.append("[NetConnCallbackInfo]");
+
+ str.append("\n");
+ str.append(tab);
+ str.append("netState_ = ");
+ str.append(std::to_string(netState_));
+
+ str.append("\n");
+ str.append(tab);
+ str.append("netType_ = ");
+ str.append(std::to_string(netType_));
+
+ return str;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/net_conn_client.cpp b/frameworks/innerkitsimpl/netconnmanager/src/net_conn_client.cpp
new file mode 100755
index 0000000..5d7f67e
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/net_conn_client.cpp
@@ -0,0 +1,183 @@
+/*
+ * 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 "net_conn_client.h"
+
+#include "iservice_registry.h"
+#include "system_ability_definition.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+NetConnClient::NetConnClient() : NetConnService_(nullptr), deathRecipient_(nullptr) {}
+
+NetConnClient::~NetConnClient() {}
+
+int32_t NetConnClient::SystemReady()
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->SystemReady();
+}
+
+int32_t NetConnClient::RegisterNetSupplier(uint32_t netType, const std::string &ident, uint64_t netCapabilities)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->RegisterNetSupplier(netType, ident, netCapabilities);
+}
+
+int32_t NetConnClient::UnregisterNetSupplier(uint32_t supplierId)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->UnregisterNetSupplier(supplierId);
+}
+
+int32_t NetConnClient::RegisterNetConnCallback(const sptr &callback)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("The parameter of proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->RegisterNetConnCallback(callback);
+}
+
+int32_t NetConnClient::RegisterNetConnCallback(const sptr &netSpecifier,
+ const sptr &callback)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("The parameter of proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->RegisterNetConnCallback(netSpecifier, callback);
+}
+
+int32_t NetConnClient::UnregisterNetConnCallback(const sptr &callback)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->UnregisterNetConnCallback(callback);
+}
+
+int32_t NetConnClient::UnregisterNetConnCallback(const sptr &netSpecifier,
+ const sptr &callback)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->UnregisterNetConnCallback(netSpecifier, callback);
+}
+
+int32_t NetConnClient::UpdateNetSupplierInfo(uint32_t supplierId, const sptr &netSupplierInfo)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->UpdateNetSupplierInfo(supplierId, netSupplierInfo);
+}
+
+int32_t NetConnClient::UpdateNetCapabilities(uint32_t supplierId, uint64_t netCapabilities)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->UpdateNetCapabilities(supplierId, netCapabilities);
+}
+
+int32_t NetConnClient::UpdateNetLinkInfo(uint32_t supplierId, const sptr &netLinkInfo)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return IPC_PROXY_ERR;
+ }
+ return proxy->UpdateNetLinkInfo(supplierId, netLinkInfo);
+}
+
+sptr NetConnClient::GetProxy()
+{
+ std::lock_guard lock(mutex_);
+ if (NetConnService_) {
+ NETMGR_LOGI("get proxy is ok");
+ return NetConnService_;
+ }
+ NETMGR_LOGI("execute GetSystemAbilityManager");
+ sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ if (sam == nullptr) {
+ NETMGR_LOGE("GetProxy, get SystemAbilityManager failed");
+ return nullptr;
+ }
+ sptr remote = sam->CheckSystemAbility(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID);
+ if (remote == nullptr) {
+ NETMGR_LOGE("get Remote service failed");
+ return nullptr;
+ }
+ deathRecipient_ = (std::make_unique(*this)).release();
+ if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
+ NETMGR_LOGE("add death recipient failed");
+ return nullptr;
+ }
+ NetConnService_ = iface_cast(remote);
+ if (NetConnService_ == nullptr) {
+ NETMGR_LOGE("get Remote service proxy failed");
+ return nullptr;
+ }
+ return NetConnService_;
+}
+
+void NetConnClient::OnRemoteDied(const wptr &remote)
+{
+ NETMGR_LOGI("on remote died");
+ if (remote == nullptr) {
+ NETMGR_LOGE("remote object is nullptr");
+ return;
+ }
+ std::lock_guard lock(mutex_);
+ if (NetConnService_ == nullptr) {
+ NETMGR_LOGE("OnRemoteDied NetConnService_ is nullptr");
+ return;
+ }
+ sptr local = NetConnService_->AsObject();
+ if (local != remote.promote()) {
+ NETMGR_LOGE("OnRemoteDied proxy and stub is not same remote object");
+ return;
+ }
+ local->RemoveDeathRecipient(deathRecipient_);
+ NetConnService_ = nullptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/net_link_info.cpp b/frameworks/innerkitsimpl/netconnmanager/src/net_link_info.cpp
new file mode 100755
index 0000000..c3f874a
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/net_link_info.cpp
@@ -0,0 +1,207 @@
+/*
+ * 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 "net_link_info.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool NetLinkInfo::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteString(ifaceName_)) {
+ return false;
+ }
+ if (!parcel.WriteString(domain_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(netAddrList_.size())) {
+ return false;
+ }
+ for (auto it = netAddrList_.begin(); it != netAddrList_.end(); it++) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write net address to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteUint32(dnsList_.size())) {
+ return false;
+ }
+ for (auto it = dnsList_.begin(); it != dnsList_.end(); it++) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write dns to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteUint32(routeList_.size())) {
+ return false;
+ }
+ for (auto it = routeList_.begin(); it != routeList_.end(); it++) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write route to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteUint16(mtu_)) {
+ return false;
+ }
+ return true;
+}
+
+sptr NetLinkInfo::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->ifaceName_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->domain_)) {
+ return nullptr;
+ }
+ uint32_t size = 0;
+ if (!parcel.ReadUint32(size)) {
+ return nullptr;
+ }
+ sptr netAddr;
+ for (uint32_t i = 0; i < size; i++) {
+ netAddr = INetAddr::Unmarshalling(parcel);
+ if (netAddr == nullptr) {
+ NETMGR_LOGE("INetAddr::Unmarshalling(parcel) is null");
+ return nullptr;
+ }
+ ptr->netAddrList_.push_back(*netAddr);
+ }
+ if (!parcel.ReadUint32(size)) {
+ return nullptr;
+ }
+ for (uint32_t i = 0; i < size; i++) {
+ netAddr = INetAddr::Unmarshalling(parcel);
+ if (netAddr == nullptr) {
+ NETMGR_LOGE("INetAddr::Unmarshalling(parcel) is null");
+ return nullptr;
+ }
+ ptr->dnsList_.push_back(*netAddr);
+ }
+ if (!parcel.ReadUint32(size)) {
+ return nullptr;
+ }
+ sptr route;
+ for (uint32_t i = 0; i < size; i++) {
+ route = Route::Unmarshalling(parcel);
+ if (route == nullptr) {
+ NETMGR_LOGE("Route::Unmarshalling(parcel) is null");
+ return nullptr;
+ }
+ ptr->routeList_.push_back(*route);
+ }
+ if (!parcel.ReadUint16(ptr->mtu_)) {
+ return nullptr;
+ }
+ return ptr;
+}
+
+bool NetLinkInfo::Marshalling(Parcel &parcel, const sptr &object)
+{
+ if (object == nullptr) {
+ NETMGR_LOGE("NetLinkInfo object ptr is nullptr");
+ return false;
+ }
+ if (!parcel.WriteString(object->ifaceName_)) {
+ return false;
+ }
+ if (!parcel.WriteString(object->domain_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(object->netAddrList_.size())) {
+ return false;
+ }
+ for (auto it = object->netAddrList_.begin(); it != object->netAddrList_.end(); it++) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write objects net address to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteUint32(object->dnsList_.size())) {
+ return false;
+ }
+ for (auto it = object->dnsList_.begin(); it != object->dnsList_.end(); it++) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write objects dns to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteUint32(object->routeList_.size())) {
+ return false;
+ }
+ for (auto it = object->routeList_.begin(); it != object->routeList_.end(); it++) {
+ if (!it->Marshalling(parcel)) {
+ NETMGR_LOGE("write objects route to parcel failed");
+ return false;
+ }
+ }
+ if (!parcel.WriteUint16(object->mtu_)) {
+ return false;
+ }
+ return true;
+}
+
+std::string NetLinkInfo::ToString(const std::string &tab) const
+{
+ std::string str;
+ str.append("\n");
+ str.append(tab);
+ str.append("[NetLinkInfo]");
+
+ str.append("\n");
+ str.append(tab);
+ str.append("ifaceName_ = ");
+ str.append(ifaceName_);
+
+ str.append("\n");
+ str.append(tab);
+ str.append("domain_ = ");
+ str.append(domain_);
+
+ str.append("\n");
+ str.append(tab);
+ str.append("netAddrList_ = ");
+ for (auto it = netAddrList_.begin(); it != netAddrList_.end(); it++) {
+ str.append(it->ToString(tab + " "));
+ }
+
+ str.append("\n");
+ str.append(tab);
+ str.append("dnsList_ = ");
+ for (auto it = dnsList_.begin(); it != dnsList_.end(); it++) {
+ str.append(it->ToString(tab + " "));
+ }
+
+ str.append("\n");
+ str.append(tab);
+ str.append("routeList_ = ");
+ for (auto it = routeList_.begin(); it != routeList_.end(); it++) {
+ str.append(it->ToString(tab + " "));
+ }
+
+ str.append("\n");
+ str.append(tab);
+ str.append("mtu_ = ");
+ str.append(std::to_string(mtu_));
+ return str;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/net_specifier.cpp b/frameworks/innerkitsimpl/netconnmanager/src/net_specifier.cpp
new file mode 100755
index 0000000..ae3f326
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/net_specifier.cpp
@@ -0,0 +1,98 @@
+/*
+ * 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 "net_specifier.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool NetSpecifier::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteString(ident_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(netType_)) {
+ return false;
+ }
+ if (!parcel.WriteUint64(netCapabilities_)) {
+ return false;
+ }
+ return true;
+}
+
+sptr NetSpecifier::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ NETMGR_LOGE("make_unique() failed");
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->ident_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadUint32(ptr->netType_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadUint64(ptr->netCapabilities_)) {
+ return nullptr;
+ }
+ return ptr;
+}
+
+bool NetSpecifier::Marshalling(Parcel &parcel, const sptr &object)
+{
+ if (object == nullptr) {
+ NETMGR_LOGE("NetSpecifier object ptr is nullptr");
+ return false;
+ }
+ if (!parcel.WriteString(object->ident_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(object->netType_)) {
+ return false;
+ }
+ if (!parcel.WriteUint64(object->netCapabilities_)) {
+ return false;
+ }
+ return true;
+}
+
+std::string NetSpecifier::ToString(const std::string &tab) const
+{
+ std::string str;
+ str.append("\n");
+ str.append(tab);
+ str.append("[NetSpecifier]");
+
+ str.append("\n");
+ str.append(tab);
+ str.append("ident_ = ");
+ str.append(ident_);
+
+ str.append("\n");
+ str.append(tab);
+ str.append("netType_ = ");
+ str.append(std::to_string(netType_));
+
+ str.append("\n");
+ str.append(tab);
+ str.append("netCapabilities_ = ");
+ str.append(std::to_string(netCapabilities_));
+
+ return str;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/net_supplier_info.cpp b/frameworks/innerkitsimpl/netconnmanager/src/net_supplier_info.cpp
new file mode 100755
index 0000000..0bfa3f1
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/net_supplier_info.cpp
@@ -0,0 +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.
+ */
+
+#include "net_supplier_info.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool NetSupplierInfo::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteBool(isAvailable_)) {
+ return false;
+ }
+ if (!parcel.WriteBool(isRoaming_)) {
+ return false;
+ }
+ if (!parcel.WriteUint8(strength_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(frequency_)) {
+ return false;
+ }
+ return true;
+}
+
+sptr NetSupplierInfo::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ NETMGR_LOGE("make_unique() failed");
+ return nullptr;
+ }
+ if (!parcel.ReadBool(ptr->isAvailable_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadBool(ptr->isRoaming_)) {
+ return nullptr;
+ }
+ if (!parcel.ReadUint8(ptr->strength_)) {
+ NETMGR_LOGE("read strength_ from parcel failed");
+ return nullptr;
+ }
+ if (!parcel.ReadUint32(ptr->frequency_)) {
+ return nullptr;
+ }
+ return ptr;
+}
+
+bool NetSupplierInfo::Marshalling(Parcel &parcel, const sptr &object)
+{
+ if (object == nullptr) {
+ NETMGR_LOGE("NetSupplierInfo object ptr is nullptr");
+ return false;
+ }
+ if (!parcel.WriteBool(object->isAvailable_)) {
+ return false;
+ }
+ if (!parcel.WriteBool(object->isRoaming_)) {
+ return false;
+ }
+ if (!parcel.WriteUint8(object->strength_)) {
+ return false;
+ }
+ if (!parcel.WriteUint32(object->frequency_)) {
+ return false;
+ }
+ return true;
+}
+
+std::string NetSupplierInfo::ToString(const std::string &tab) const
+{
+ std::string str;
+ str.append("\n");
+ str.append(tab);
+ str.append("[NetSupplierInfo]");
+
+ str.append("\n");
+ str.append(tab);
+ str.append("isAvailable_ = ");
+ str.append(std::to_string(isAvailable_));
+
+ str.append("\n");
+ str.append(tab);
+ str.append("isRoaming_ = ");
+ str.append(std::to_string(isRoaming_));
+
+ str.append("\n");
+ str.append(tab);
+ str.append("strength_ = ");
+ str.append(std::to_string(strength_));
+
+ str.append("\n");
+ str.append(tab);
+ str.append("frequency_ = ");
+ str.append(std::to_string(frequency_));
+
+ return str;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/netconnmanager/src/route.cpp b/frameworks/innerkitsimpl/netconnmanager/src/route.cpp
new file mode 100755
index 0000000..9287b95
--- /dev/null
+++ b/frameworks/innerkitsimpl/netconnmanager/src/route.cpp
@@ -0,0 +1,117 @@
+/*
+ * 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 "route.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+bool Route::operator==(const Route &obj) const
+{
+ bool out = true;
+ out = out && (iface_ == obj.iface_);
+ out = out && (destination_ == obj.destination_);
+ out = out && (gateway_ == obj.gateway_);
+ return out;
+}
+
+bool Route::Marshalling(Parcel &parcel) const
+{
+ if (!parcel.WriteString(iface_)) {
+ return false;
+ }
+ if (!destination_.Marshalling(parcel)) {
+ NETMGR_LOGE("write destination_ to parcel failed");
+ return false;
+ }
+ if (!gateway_.Marshalling(parcel)) {
+ NETMGR_LOGE("write gateway_ to parcel failed");
+ return false;
+ }
+ return true;
+}
+
+sptr Route::Unmarshalling(Parcel &parcel)
+{
+ sptr ptr = (std::make_unique()).release();
+ if (ptr == nullptr) {
+ NETMGR_LOGE("make_unique() failed");
+ return nullptr;
+ }
+ if (!parcel.ReadString(ptr->iface_)) {
+ return nullptr;
+ }
+ sptr destination = INetAddr::Unmarshalling(parcel);
+ if (destination == nullptr) {
+ NETMGR_LOGE("read destination from parcel failed");
+ return nullptr;
+ }
+ ptr->destination_ = *destination;
+ sptr gateway = INetAddr::Unmarshalling(parcel);
+ if (gateway == nullptr) {
+ NETMGR_LOGE("read gateway from parcel failed");
+ return nullptr;
+ }
+ ptr->gateway_ = *gateway;
+ return ptr;
+}
+
+bool Route::Marshalling(Parcel &parcel, const sptr &object)
+{
+ if (object == nullptr) {
+ NETMGR_LOGE("Route object ptr is nullptr");
+ return false;
+ }
+ if (!parcel.WriteString(object->iface_)) {
+ return false;
+ }
+ if (!object->destination_.Marshalling(parcel)) {
+ NETMGR_LOGE("write object->destination_ to parcel failed");
+ return false;
+ }
+ if (!object->gateway_.Marshalling(parcel)) {
+ NETMGR_LOGE("write object->gateway_ to parcel failed");
+ return false;
+ }
+ return true;
+}
+
+std::string Route::ToString(const std::string &tab) const
+{
+ std::string str;
+ str.append("\n");
+ str.append(tab);
+ str.append("[Route]");
+
+ str.append("\n");
+ str.append(tab);
+ str.append("iface_ = ");
+ str.append(iface_);
+
+ str.append("\n");
+ str.append(tab);
+ str.append("destination_ = ");
+ str.append(destination_.ToString(tab + " "));
+
+ str.append("\n");
+ str.append(tab);
+ str.append("gateway_ = ");
+ str.append(gateway_.ToString(tab + " "));
+
+ return str;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/netpolicymanager/src/net_policy_client.cpp b/frameworks/innerkitsimpl/netpolicymanager/src/net_policy_client.cpp
new file mode 100755
index 0000000..834e4ce
--- /dev/null
+++ b/frameworks/innerkitsimpl/netpolicymanager/src/net_policy_client.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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 "net_policy_client.h"
+
+#include "iservice_registry.h"
+#include "system_ability_definition.h"
+
+#include "net_mgr_log_wrapper.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+NetPolicyClient::NetPolicyClient() : netPolicyService_(nullptr), deathRecipient_(nullptr) {}
+
+NetPolicyClient::~NetPolicyClient() {}
+
+NetPolicyResultCode NetPolicyClient::SetUidPolicy(uint32_t uid, NetUidPolicy policy)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return NetPolicyResultCode::ERR_INTERNAL_ERROR;
+ }
+ return proxy->SetUidPolicy(uid, policy);
+}
+
+NetUidPolicy NetPolicyClient::GetUidPolicy(uint32_t uid)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return NetUidPolicy::NET_POLICY_NONE;
+ }
+ return proxy->GetUidPolicy(uid);
+}
+
+std::vector NetPolicyClient::GetUids(NetUidPolicy policy)
+{
+ std::vector uids;
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return uids;
+ }
+ uids = proxy->GetUids(policy);
+ return uids;
+}
+
+bool NetPolicyClient::IsUidNetAccess(uint32_t uid, bool metered)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return false;
+ }
+ return proxy->IsUidNetAccess(uid, metered);
+}
+
+bool NetPolicyClient::IsUidNetAccess(uint32_t uid, const std::string &ifaceName)
+{
+ sptr proxy = GetProxy();
+ if (proxy == nullptr) {
+ NETMGR_LOGE("proxy is nullptr");
+ return false;
+ }
+ return proxy->IsUidNetAccess(uid, ifaceName);
+}
+
+sptr NetPolicyClient::GetProxy()
+{
+ std::lock_guard lock(mutex_);
+ if (netPolicyService_ != nullptr) {
+ return netPolicyService_;
+ }
+
+ sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ if (sam == nullptr) {
+ NETMGR_LOGE("GetProxy, get SystemAbilityManager failed");
+ return nullptr;
+ }
+
+ sptr remote = sam->CheckSystemAbility(COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID);
+ if (remote == nullptr) {
+ NETMGR_LOGE("get Remote service failed");
+ return nullptr;
+ }
+
+ deathRecipient_ = (std::make_unique(*this)).release();
+ if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
+ NETMGR_LOGE("add death recipient failed");
+ return nullptr;
+ }
+
+ netPolicyService_ = iface_cast(remote);
+ if (netPolicyService_ == nullptr) {
+ NETMGR_LOGE("get Remote service proxy failed");
+ return nullptr;
+ }
+ return netPolicyService_;
+}
+
+void NetPolicyClient::OnRemoteDied(const wptr &remote)
+{
+ NETMGR_LOGI("on remote died");
+ if (remote == nullptr) {
+ NETMGR_LOGE("remote object is nullptr");
+ return;
+ }
+
+ std::lock_guard lock(mutex_);
+ if (netPolicyService_ == nullptr) {
+ NETMGR_LOGE("netPolicyService_ is nullptr");
+ return;
+ }
+
+ sptr local = netPolicyService_->AsObject();
+ if (local != remote.promote()) {
+ NETMGR_LOGE("proxy and stub is not same remote object");
+ return;
+ }
+ local->RemoveDeathRecipient(deathRecipient_);
+ netPolicyService_ = nullptr;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/js/common/napi_common.cpp b/frameworks/js/common/napi_common.cpp
new file mode 100755
index 0000000..b2aecb2
--- /dev/null
+++ b/frameworks/js/common/napi_common.cpp
@@ -0,0 +1,72 @@
+/*
+ * 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 "napi_common.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+napi_value NpiCommon::CreateCodeMessage(napi_env env, const std::string &msg, int32_t code)
+{
+ napi_value messageCodeInfo = nullptr;
+ napi_value messageInfo = nullptr;
+ napi_value codeInfo = nullptr;
+ NAPI_CALL(env, napi_create_string_utf8(env, msg.c_str(), msg.length(), &messageInfo));
+ NAPI_CALL(env, napi_create_string_utf8(
+ env, std::to_string(code).c_str(), std::to_string(code).length(), &codeInfo));
+ NAPI_CALL(env, napi_create_error(env, codeInfo, messageInfo, &messageCodeInfo));
+ return messageCodeInfo;
+}
+
+void NpiCommon::SetPropertyInt32(napi_env env, napi_value object, const std::string &propertyName, int32_t property)
+{
+ napi_value propertyDest = nullptr;
+ NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, property, &propertyDest));
+ NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, object, propertyName.c_str(), propertyDest));
+}
+
+void NpiCommon::SetPropertyString(
+ napi_env env, napi_value object, const std::string &propertyName, const std::string &property)
+{
+ napi_value propertyDest = nullptr;
+ NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, property.c_str(), property.length(), &propertyDest));
+ NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, object, propertyName.c_str(), propertyDest));
+}
+
+void NpiCommon::GetPropertyString(
+ napi_env env, napi_value object, const std::string &propertyName, std::string &property)
+{
+ napi_value value = nullptr;
+ char propertyBuffer[PROPERTY_MAX_BYTE] = {0};
+ size_t realByte= 0;
+ NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, object, propertyName.c_str(), &value));
+ NAPI_CALL_RETURN_VOID(env, napi_get_value_string_utf8(env, value, propertyBuffer, PROPERTY_MAX_BYTE, &realByte));
+ property = propertyBuffer;
+}
+
+void NpiCommon::GetPropertyInt32(napi_env env, napi_value object, const std::string &propertyName, int32_t &property)
+{
+ napi_value value = nullptr;
+ NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, object, propertyName.c_str(), &value));
+ NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, value, &property));
+}
+
+napi_value NpiCommon::NapiValueByInt32(napi_env env, int32_t property)
+{
+ napi_value value = nullptr;
+ NAPI_CALL(env, napi_create_int32(env, property, &value));
+ return value;
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/js/common/napi_common.h b/frameworks/js/common/napi_common.h
new file mode 100755
index 0000000..bce9aea
--- /dev/null
+++ b/frameworks/js/common/napi_common.h
@@ -0,0 +1,70 @@
+/*
+ * 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 NAPI_COMMON_H
+#define NAPI_COMMON_H
+
+#include
+#include
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+// define callback ref count
+constexpr uint32_t CALLBACK_REF_CNT = 1;
+// define property max bytes
+constexpr uint32_t PROPERTY_MAX_BYTE = 128;
+// define constant of 64 bytes
+constexpr uint32_t BUFFER_BYTE = 64;
+
+enum JS_CALLBACK_ARGV {
+ CALLBACK_ARGV_INDEX_0 = 0,
+ CALLBACK_ARGV_INDEX_1,
+ CALLBACK_ARGV_CNT,
+};
+
+enum JS_ARGV_NUM {
+ ARGV_NUM_0 = 0,
+ ARGV_NUM_1,
+ ARGV_NUM_2,
+ ARGV_NUM_3,
+ ARGV_NUM_4,
+ ARGV_NUM_5,
+};
+
+enum JS_ARGV_INDEX {
+ ARGV_INDEX_0 = 0,
+ ARGV_INDEX_1,
+ ARGV_INDEX_2,
+ ARGV_INDEX_3,
+ ARGV_INDEX_4,
+};
+
+class NpiCommon {
+public:
+ static napi_value CreateCodeMessage(napi_env env, const std::string &msg, int32_t code);
+ static napi_value NapiValueByInt32(napi_env env, int32_t property);
+ static void SetPropertyInt32(napi_env env, napi_value object, const std::string &propertyName, int32_t property);
+ static void SetPropertyString(napi_env env, napi_value object, const std::string &propertyName,
+ const std::string &property);
+ static void GetPropertyString(napi_env env, napi_value object, const std::string &propertyName,
+ std::string &property);
+ static void GetPropertyInt32(napi_env env, napi_value object, const std::string &propertyName, int32_t &property);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // NAPI_COMMON_H
+
diff --git a/frameworks/js/dnsresolver/BUILD.gn b/frameworks/js/dnsresolver/BUILD.gn
new file mode 100755
index 0000000..5cd5ca5
--- /dev/null
+++ b/frameworks/js/dnsresolver/BUILD.gn
@@ -0,0 +1,57 @@
+# 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.
+
+import("//build/ohos.gni")
+import(
+ "//foundation/communication/netmanager_standard/netmanager_base_config.gni")
+
+SUBSYSTEM_DIR = "//foundation/communication"
+NETMANAGER_NAPI_ROOT = "$SUBSYSTEM_DIR/netmanager_standard/frameworks/js/"
+
+ohos_shared_library("dnsresolver") {
+ include_dirs = [
+ "//third_party/node/src",
+ "$NETMANAGER_NAPI_ROOT/dnsresolver/include",
+ "$NETMANAGER_NAPI_ROOT/common",
+ "$NETMANAGER_BASE_ROOT/utils/log/include",
+ "$DNSRESOLVERMANAGER_SOURCE_DIR/include",
+ "$DNSRESOLVERMANAGER_SOURCE_DIR/include/ipc",
+ "$INNERKITS_ROOT/native/netconnmanager/include",
+ ]
+
+ sources = [
+ "$NETMANAGER_NAPI_ROOT/common/napi_common.cpp",
+ "$NETMANAGER_NAPI_ROOT/dnsresolver/src/napi_dns_resolver.cpp",
+ ]
+
+ defines = [ "NETMGR_DEBUG" ]
+
+ deps = [
+ "$INNERKITS_ROOT/native/dnsresolvermanager:dns_resolver_manager_if",
+ "$INNERKITS_ROOT/native/netconnmanager:net_conn_manager_if",
+ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
+ "//foundation/ace/napi/:ace_napi",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ relative_install_dir = "module"
+ part_name = "netmanager_standard"
+ subsystem_name = "communication"
+}
diff --git a/frameworks/js/dnsresolver/include/napi_dns_resolver.h b/frameworks/js/dnsresolver/include/napi_dns_resolver.h
new file mode 100755
index 0000000..0f3a2d4
--- /dev/null
+++ b/frameworks/js/dnsresolver/include/napi_dns_resolver.h
@@ -0,0 +1,52 @@
+/*
+ * 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 NAPI_DNS_RESOLVER_H
+#define NAPI_DNS_RESOLVER_H
+
+#include
+#include
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+constexpr int32_t HOST_MAX_BYTES = 256;
+
+// dns resolver async context
+struct DnsResolverAsyncContext {
+ napi_async_work work = nullptr;
+ napi_deferred deferred = nullptr;
+ napi_ref callbackRef = nullptr;
+ // Data context
+ char host[HOST_MAX_BYTES] = {0};
+ size_t hostRealBytes = 0;
+ std::vector hostAddress;
+};
+
+class NapiDnsResolver {
+public:
+ NapiDnsResolver();
+ ~NapiDnsResolver() = default;
+ static napi_value DeclareNapiDnsResolverInterface(napi_env env, napi_value exports);
+ static napi_value RegisterDnsResolverInterface(napi_env env, napi_value exports);
+ static void ExecDnsResolverCallback(napi_env env, void *data);
+ static void CompleteDnsResolverCallback(napi_env env, napi_status status, void *data);
+ // declare napi interface for JS
+ static napi_value GetAddressesByName(napi_env env, napi_callback_info info);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // NAPI_DNS_RESOLVER_H
diff --git a/frameworks/js/dnsresolver/src/napi_dns_resolver.cpp b/frameworks/js/dnsresolver/src/napi_dns_resolver.cpp
new file mode 100755
index 0000000..8b4271d
--- /dev/null
+++ b/frameworks/js/dnsresolver/src/napi_dns_resolver.cpp
@@ -0,0 +1,158 @@
+/*
+ * 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 "napi_dns_resolver.h"
+#include "system_ability_definition.h"
+#include "iservice_registry.h"
+#include "net_mgr_log_wrapper.h"
+#include "i_dns_resolver_service.h"
+#include "dns_resolver_client.h"
+#include "napi_common.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+NapiDnsResolver::NapiDnsResolver() {}
+
+void NapiDnsResolver::ExecDnsResolverCallback(napi_env env, void *data)
+{
+ DnsResolverAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ std::string hostName = context->host;
+ std::vector addrInfo;
+ NETMGR_LOGI("ExecDnsResolverCallback [%{public}s]", hostName.c_str());
+ DelayedSingleton::GetInstance()->GetAddressesByName(hostName, addrInfo);
+ NETMGR_LOGI("ExecDnsResolverCallback, addrInfo.size = [%{public}d]", static_cast(addrInfo.size()));
+ std::string tap;
+ for (auto it = addrInfo.begin(); it != addrInfo.end(); ++it) {
+ context->hostAddress.push_back(it->ToString(tap));
+ }
+}
+
+void NapiDnsResolver::CompleteDnsResolverCallback(napi_env env, napi_status status, void *data)
+{
+ NETMGR_LOGI("CompleteDnsResolverCallback");
+ DnsResolverAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ // creat function return
+ napi_value infoAttay = nullptr;
+ napi_value info = nullptr;
+ napi_create_string_utf8(env, "fail", NAPI_AUTO_LENGTH, &info);
+ napi_create_array_with_length(env, context->hostAddress.size(), &infoAttay);
+ for (size_t index = 0; index < context->hostAddress.size(); index++) {
+ napi_create_string_utf8(env, context->hostAddress[index].c_str(), NAPI_AUTO_LENGTH, &info);
+ napi_set_element(env, infoAttay, index, info);
+ }
+ if (context->callbackRef == nullptr) {
+ // promiss return
+ if (context->hostAddress.size() > 0) {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, infoAttay));
+ } else {
+ NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context->deferred, info));
+ }
+ } else {
+ // call back return
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ if (context->hostAddress.size() > 0) {
+ callbackValues[CALLBACK_ARGV_INDEX_1] = infoAttay;
+ } else {
+ callbackValues[CALLBACK_ARGV_INDEX_0] = info;
+ }
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+napi_value NapiDnsResolver::GetAddressesByName(napi_env env, napi_callback_info info)
+{
+ NETMGR_LOGI("NapiDnsResolver GetAddressesByName");
+ size_t argc = ARGV_NUM_2;
+ napi_value argv[] = {nullptr, nullptr} ;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ DnsResolverAsyncContext* context = std::make_unique().release();
+ NAPI_CALL(env, napi_get_value_string_utf8(
+ env, argv[ARGV_INDEX_0], context->host, HOST_MAX_BYTES, &(context->hostRealBytes)));
+ NETMGR_LOGI("GetAddressesByName = [%{public}s]", context->host);
+ NETMGR_LOGI("GetAddressesByName argc = [%{public}d]", static_cast(argc));
+ napi_value result = nullptr;
+ if (argc == ARGV_NUM_1) {
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_NUM_2) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_1], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("GetAddressesByName exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "GetAddressesByName", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecDnsResolverCallback,
+ CompleteDnsResolverCallback,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiDnsResolver::DeclareNapiDnsResolverInterface(napi_env env, napi_value exports)
+{
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_FUNCTION("getAddressesByName", GetAddressesByName),
+ };
+ NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+ return exports;
+}
+
+napi_value NapiDnsResolver::RegisterDnsResolverInterface(napi_env env, napi_value exports)
+{
+ DeclareNapiDnsResolverInterface(env, exports);
+ return nullptr;
+}
+
+static napi_module _dnsResolverModule = {
+ .nm_version = 1,
+ .nm_flags = 0,
+ .nm_filename = nullptr,
+ .nm_register_func = NapiDnsResolver::RegisterDnsResolverInterface,
+ .nm_modname = "netmanager.dnsresolver",
+ .nm_priv = ((void *)0),
+ .reserved = {0},
+};
+
+extern "C" __attribute__((constructor)) void RegisterDnsResolverModule(void)
+{
+ napi_module_register(&_dnsResolverModule);
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/js/ethernet/BUILD.gn b/frameworks/js/ethernet/BUILD.gn
new file mode 100755
index 0000000..e0f098b
--- /dev/null
+++ b/frameworks/js/ethernet/BUILD.gn
@@ -0,0 +1,62 @@
+# 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.
+
+import("//build/ohos.gni")
+import(
+ "//foundation/communication/netmanager_standard/netmanager_base_config.gni")
+
+SUBSYSTEM_DIR = "//foundation/communication"
+NETMANAGER_NAPI_ROOT = "$SUBSYSTEM_DIR/netmanager_standard/frameworks/js/"
+
+ohos_shared_library("ethernet") {
+ include_dirs = [
+ "//third_party/node/src",
+ "$NETMANAGER_NAPI_ROOT/ethernet/include",
+ "$NETMANAGER_NAPI_ROOT/common",
+ "$NETMANAGER_BASE_ROOT/utils/log/include",
+ "$ETHERNETMANAGER_SOURCE_DIR/include",
+ "$ETHERNETMANAGER_SOURCE_DIR/include/ipc",
+ "$INNERKITS_ROOT/native/ethernetmanager/include",
+ "//foundation/communication/netmanager_standard/interfaces/innerkits/native/ethernetmanager/include",
+ "//foundation/communication/wifi/services/wifi_standard/wifi_framework/dhcp_manage/mgr_service/include",
+ "//foundation/communication/wifi/services/wifi_standard/wifi_framework/dhcp_manage/mgr_service/interfaces",
+ ]
+
+ sources = [
+ "$NETMANAGER_NAPI_ROOT/common/napi_common.cpp",
+ "$NETMANAGER_NAPI_ROOT/ethernet/src/napi_ethernet.cpp",
+ ]
+
+ defines = [ "NETMGR_DEBUG" ]
+
+ deps = [
+ "$INNERKITS_ROOT/native/ethernetmanager:ethernet_manager_if",
+ "$INNERKITS_ROOT/native/netconnmanager:net_conn_manager_if",
+ "$NETMANAGER_PREBUILTS_DIR/librarys/netd:libnet_manager_native",
+ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
+ "//foundation/ace/napi/:ace_napi",
+ "//foundation/communication/wifi/services/wifi_standard/wifi_framework/dhcp_manage/mgr_service:dhcp_manager_service",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ relative_install_dir = "module"
+ part_name = "netmanager_standard"
+ subsystem_name = "communication"
+}
diff --git a/frameworks/js/ethernet/include/napi_ethernet.h b/frameworks/js/ethernet/include/napi_ethernet.h
new file mode 100755
index 0000000..19f35c8
--- /dev/null
+++ b/frameworks/js/ethernet/include/napi_ethernet.h
@@ -0,0 +1,86 @@
+/*
+ * 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 NAPI_ETHERNET_H
+#define NAPI_ETHERNET_H
+
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+#include
+#include
+
+namespace OHOS {
+namespace NetManagerStandard {
+// ethernet name max bytes
+constexpr int32_t ETHERNET_NAME_MAX_BYTE = 32;
+// ip address max bytes
+constexpr int32_t IP_ADDR_MAX_BYTE = 128;
+// ip address type [static]
+const std::string STATIC_IP = "static";
+// ip address type [dynamic]
+const std::string DYNAMIC_IP = "dynamic";
+
+struct EthernetAsyncContext {
+ napi_async_work work = nullptr;
+ napi_deferred deferred = nullptr;
+ napi_ref callbackRef = nullptr;
+ // Data context
+ char ethernetName[ETHERNET_NAME_MAX_BYTE] = {0};
+ size_t ethernetNameRealBytes = 0;
+ int32_t ifActivate = 0;
+ // get all ethernetName
+ std::vector ethernetNameList;
+ // [0] static, [1] dhcp
+ int32_t ipMode = 0;
+ // ip address info
+ std::string ipAddrInfo;
+ // route address info
+ std::string routeAddrInfo;
+ // gate address info
+ std::string gateAddrInfo;
+ // mask address info
+ std::string maskAddrInfo;
+ // dns0 address info
+ std::string dns0AddrInfo;
+ // dns1 address info
+ std::string dns1AddrInfo;
+ int32_t result = 0;
+};
+
+class NapiEthernet {
+public:
+ NapiEthernet();
+ ~NapiEthernet() = default;
+ static napi_value RegisterEthernetInterface(napi_env env, napi_value exports);
+ static napi_value DeclareEthernetInterface(napi_env env, napi_value exports);
+ static napi_value DeclareEthernetData(napi_env env, napi_value exports);
+
+ static void ExecSetIfaceConfig(napi_env env, void *data);
+ static void CompleteSetIfaceConfig(napi_env env, napi_status status, void *data);
+ static void ExecGetIfaceConfig(napi_env env, void *data);
+ static void CompleteGetIfaceConfig(napi_env env, napi_status status, void *data);
+ static void ExecIsActivate(napi_env env, void *data);
+ static void CompleteIsActivate(napi_env env, napi_status status, void *data);
+ static void ExecGetActivateInterfaces(napi_env env, void *data);
+ static void CompleteGetActivateInterfaces(napi_env env, napi_status status, void *data);
+ // define napi interface for JS
+ static napi_value SetIfaceConfig(napi_env env, napi_callback_info info);
+ static napi_value GetIfaceConfig(napi_env env, napi_callback_info info);
+ static napi_value IsActivate(napi_env env, napi_callback_info info);
+ static napi_value GetActivateInterfaces(napi_env env, napi_callback_info info);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // NAPI_ETHERNET_H
diff --git a/frameworks/js/ethernet/src/napi_ethernet.cpp b/frameworks/js/ethernet/src/napi_ethernet.cpp
new file mode 100755
index 0000000..847ea02
--- /dev/null
+++ b/frameworks/js/ethernet/src/napi_ethernet.cpp
@@ -0,0 +1,470 @@
+/*
+ * 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 "napi_ethernet.h"
+#include
+#include "system_ability_definition.h"
+#include "iservice_registry.h"
+#include "net_mgr_log_wrapper.h"
+#include "i_ethernet_service.h"
+#include "ethernet_client.h"
+#include "napi_common.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+NapiEthernet::NapiEthernet() {}
+
+void NapiEthernet::ExecSetIfaceConfig(napi_env env, void *data)
+{
+ NETMGR_LOGI("ExecSetIfaceConfig");
+ EthernetAsyncContext *context = (EthernetAsyncContext *)data;
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ INetAddr addr0, addr1;
+ sptr config = std::make_unique().release();
+ if (config == nullptr) {
+ NETMGR_LOGE("config == nullptr");
+ return;
+ }
+ addr0.address_ = context->dns0AddrInfo;
+ addr1.address_ = context->dns1AddrInfo;
+ config->mode_ = static_cast(context->ipMode);
+ config->ipStatic_.ipAddr_.address_ = context->ipAddrInfo;
+ config->ipStatic_.route_.address_ = context->routeAddrInfo;
+ config->ipStatic_.gate_.address_ = context->gateAddrInfo;
+ config->ipStatic_.netMask_.address_ = context->maskAddrInfo;
+ config->ipStatic_.dnsServers_.push_back(addr0);
+ config->ipStatic_.dnsServers_.push_back(addr1);
+ context->result = DelayedSingleton::GetInstance()->SetIfaceConfig(
+ context->ethernetName, config);
+ NETMGR_LOGI("ExecSetIfaceConfig result =[%{public}d]", context->result);
+}
+
+void NapiEthernet::CompleteSetIfaceConfig(napi_env env, napi_status status, void *data)
+{
+ NETMGR_LOGI("CompleteSetIfaceConfig");
+ EthernetAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ napi_create_int32(env, context->result, &info);
+ if (context->callbackRef == nullptr) {
+ // promiss return
+ if (context->result != ERR_NONE) {
+ NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context->deferred, info));
+ } else {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ }
+ } else {
+ // call back return
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ if (context->result != ERR_NONE) {
+ callbackValues[CALLBACK_ARGV_INDEX_0] = info;
+ } else {
+ callbackValues[CALLBACK_ARGV_INDEX_1] = info;
+ }
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+void NapiEthernet::ExecGetIfaceConfig(napi_env env, void *data)
+{
+ NETMGR_LOGI("ExecGetIfaceConfig");
+ EthernetAsyncContext *context = (EthernetAsyncContext *)data;
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ sptr config =
+ DelayedSingleton::GetInstance()->GetIfaceConfig(context->ethernetName);
+ if (config != nullptr) {
+ context->ifActivate = 1;
+ std::string tap;
+ context->ipMode = config->mode_;
+ NETMGR_LOGI("config->mode_ = [%{public}d]", config->mode_);
+ context->ipAddrInfo = config->ipStatic_.ipAddr_.ToString(tap);
+ NETMGR_LOGI("config->ipAddr_ = [%{public}s]", config->ipStatic_.ipAddr_.ToString(tap).c_str());
+ context->routeAddrInfo = config->ipStatic_.route_.ToString(tap);
+ NETMGR_LOGI("config->route_ = [%{public}s]", config->ipStatic_.route_.ToString(tap).c_str());
+ context->gateAddrInfo = config->ipStatic_.gate_.ToString(tap);
+ NETMGR_LOGI("config->gate_ = [%{public}s]", config->ipStatic_.gate_.ToString(tap).c_str());
+ context->maskAddrInfo = config->ipStatic_.netMask_.ToString(tap);
+ NETMGR_LOGI("config->netMask_ = [%{public}s]", config->ipStatic_.netMask_.ToString(tap).c_str());
+ for (auto it = config->ipStatic_.dnsServers_.begin(); it != config->ipStatic_.dnsServers_.end(); ++it) {
+ context->dns0AddrInfo = it->ToString(tap);
+ context->dns1AddrInfo = it->ToString(tap);
+ NETMGR_LOGI("config->dnsServers_ = [%{public}s]", it->ToString(tap).c_str());
+ }
+ } else {
+ context->ifActivate = -1;
+ }
+}
+
+void NapiEthernet::CompleteGetIfaceConfig(napi_env env, napi_status status, void *data)
+{
+ NETMGR_LOGI("CompleteGetIfaceConfig");
+ EthernetAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ napi_value infoFail = nullptr;
+ napi_create_object(env, &info);
+ napi_create_string_utf8(env, "fail", NAPI_AUTO_LENGTH, &infoFail);
+ NpiCommon::SetPropertyInt32(env, info, "mode", context->ipMode);
+ NpiCommon::SetPropertyString(env, info, "ipAddr", context->ipAddrInfo);
+ NpiCommon::SetPropertyString(env, info, "routeAddr", context->routeAddrInfo);
+ NpiCommon::SetPropertyString(env, info, "gateAddr", context->gateAddrInfo);
+ NpiCommon::SetPropertyString(env, info, "maskAddr", context->maskAddrInfo);
+ NpiCommon::SetPropertyString(env, info, "dns0Addr", context->dns0AddrInfo);
+ NpiCommon::SetPropertyString(env, info, "dns1Addr", context->dns1AddrInfo);
+ if (context->callbackRef == nullptr) {
+ if (context->ifActivate == -1) {
+ NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context->deferred, infoFail));
+ } else {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ }
+ } else {
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ if (context->ifActivate == 0) {
+ callbackValues[ARGV_INDEX_0] = infoFail;
+ } else {
+ callbackValues[ARGV_INDEX_1] = info;
+ }
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+void NapiEthernet::ExecIsActivate(napi_env env, void *data)
+{
+ NETMGR_LOGI("ExecIsActivate");
+ EthernetAsyncContext *context = (EthernetAsyncContext *)data;
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ context->ifActivate = DelayedSingleton::GetInstance()->IsActivate(context->ethernetName);
+ NETMGR_LOGI("ifActivate == [%{public}d]", context->ifActivate);
+}
+
+void NapiEthernet::CompleteIsActivate(napi_env env, napi_status status, void *data)
+{
+ NETMGR_LOGI("CompleteIsActivate");
+ EthernetAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ napi_create_int32(env, context->ifActivate, &info);
+ if (context->callbackRef == nullptr) {
+ if (context->ifActivate == -1) {
+ NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context->deferred, info));
+ } else {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ }
+ } else {
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ if (context->ifActivate == -1) {
+ callbackValues[ARGV_INDEX_0] = info;
+ } else {
+ callbackValues[ARGV_INDEX_1] = info;
+ }
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+void NapiEthernet::ExecGetActivateInterfaces(napi_env env, void *data)
+{
+ NETMGR_LOGI("ExecGetActivateInterfaces");
+ EthernetAsyncContext *context = (EthernetAsyncContext *)data;
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ context->ethernetNameList = DelayedSingleton::GetInstance()->GetActivateInterfaces();
+}
+
+void NapiEthernet::CompleteGetActivateInterfaces(napi_env env, napi_status status, void *data)
+{
+ NETMGR_LOGI("CompleteGetActivateInterfaces");
+ EthernetAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ // creat function return
+ napi_value infoAttay = nullptr;
+ napi_value info = nullptr;
+ napi_create_array_with_length(env, context->ethernetNameList.size(), &infoAttay);
+ for (size_t index = 0; index < context->ethernetNameList.size(); index++) {
+ napi_create_string_utf8(env, context->ethernetNameList[index].c_str(), NAPI_AUTO_LENGTH, &info);
+ napi_set_element(env, infoAttay, index, info);
+ }
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, infoAttay));
+ } else {
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ callbackValues[CALLBACK_ARGV_INDEX_1] = infoAttay;
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+napi_value NapiEthernet::SetIfaceConfig(napi_env env, napi_callback_info info)
+{
+ NETMGR_LOGI("SetIfaceConfig");
+ size_t argc = ARGV_NUM_4;
+ napi_value argv[] = {nullptr, nullptr, nullptr, nullptr} ;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NETMGR_LOGI("SetIfaceConfig agvc = [%{public}d]", static_cast(argc));
+ EthernetAsyncContext* context = std::make_unique().release();
+ // Parse Js argv
+ NAPI_CALL(env, napi_get_value_string_utf8(env, argv[ARGV_INDEX_0],
+ context->ethernetName, ETHERNET_NAME_MAX_BYTE, &(context->ethernetNameRealBytes)));
+ NETMGR_LOGI("SetIfaceConfig ethernetName = [%{public}s]", context->ethernetName);
+ // Parse Js object [ip]
+ NAPI_CALL(env, napi_get_value_int32(env, argv[ARGV_INDEX_1], &context->ipMode));
+ NETMGR_LOGI("SetIfaceConfig mode = [%{public}d]", context->ipMode);
+ if (context->ipMode == IPSetMode::STATIC) {
+ NpiCommon::GetPropertyString(env, argv[ARGV_INDEX_2], "ipAddr", context->ipAddrInfo);
+ NpiCommon::GetPropertyString(env, argv[ARGV_INDEX_2], "routeAddr", context->routeAddrInfo);
+ NpiCommon::GetPropertyString(env, argv[ARGV_INDEX_2], "gateAddr", context->gateAddrInfo);
+ NpiCommon::GetPropertyString(env, argv[ARGV_INDEX_2], "maskAddr", context->maskAddrInfo);
+ NpiCommon::GetPropertyString(env, argv[ARGV_INDEX_2], "dnsAddr0", context->dns0AddrInfo);
+ NpiCommon::GetPropertyString(env, argv[ARGV_INDEX_2], "dnsAddr1", context->dns1AddrInfo);
+ }
+ napi_value result = nullptr;
+ if ((argc == ARGV_NUM_2) || (argc == ARGV_NUM_3 && context->ipMode == IPSetMode::STATIC)) {
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if ((argc == ARGV_NUM_4) || (argc == ARGV_NUM_3 && context->ipMode == IPSetMode::DHCP)) {
+ NAPI_CALL(env, napi_create_reference(env, argv[argc - 1], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("SetIfaceConfig exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "SetIfaceConfig", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecSetIfaceConfig,
+ CompleteSetIfaceConfig,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiEthernet::GetIfaceConfig(napi_env env, napi_callback_info info)
+{
+ NETMGR_LOGI("GetIfaceConfig");
+ size_t argc = ARGV_NUM_2;
+ napi_value argv[] = {nullptr, nullptr} ;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NETMGR_LOGI("GetIfaceConfig agvc = [%{public}d]", static_cast(argc));
+ EthernetAsyncContext* context = std::make_unique().release();
+ // Parse Js argv
+ NAPI_CALL(env, napi_get_value_string_utf8(env, argv[ARGV_INDEX_0],
+ context->ethernetName, ETHERNET_NAME_MAX_BYTE, &(context->ethernetNameRealBytes)));
+ NETMGR_LOGI("GetIfaceConfig [%{public}s]", context->ethernetName);
+ napi_value result = nullptr;
+ if (argc == ARGV_NUM_1) {
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_NUM_2) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_1], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("GetIfaceConfig exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "GetIfaceConfig", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecGetIfaceConfig,
+ CompleteGetIfaceConfig,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiEthernet::IsActivate(napi_env env, napi_callback_info info)
+{
+ NETMGR_LOGI("IsActivate");
+ size_t argc = ARGV_NUM_2;
+ napi_value argv[] = {nullptr, nullptr} ;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NETMGR_LOGI("IsActivate agvc = [%{public}d]", static_cast(argc));
+ EthernetAsyncContext* context = std::make_unique().release();
+ // Parse Js argv
+ NAPI_CALL(env, napi_get_value_string_utf8(env, argv[ARGV_INDEX_0],
+ context->ethernetName, ETHERNET_NAME_MAX_BYTE, &(context->ethernetNameRealBytes)));
+ NETMGR_LOGI("IsActivate [%{public}s]", context->ethernetName);
+ napi_value result = nullptr;
+ if (argc == ARGV_NUM_1) {
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_NUM_2) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_1], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("IsActivate exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "IsActivate", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecIsActivate,
+ CompleteIsActivate,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiEthernet::GetActivateInterfaces(napi_env env, napi_callback_info info)
+{
+ size_t argc = ARGV_NUM_1;
+ napi_value argv[] = {nullptr} ;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NETMGR_LOGI("GetActivateInterfaces agvc = [%{public}d]", static_cast(argc));
+ EthernetAsyncContext* context = std::make_unique().release();
+ napi_value result = nullptr;
+ if (argc == ARGV_NUM_0) {
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_NUM_1) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_0], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("GetActivateInterfaces exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "GetActivateInterfaces", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecGetActivateInterfaces,
+ CompleteGetActivateInterfaces,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiEthernet::DeclareEthernetData(napi_env env, napi_value exports)
+{
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_STATIC_PROPERTY("STATIC",
+ NpiCommon::NapiValueByInt32(env, static_cast(IPSetMode::STATIC))),
+ DECLARE_NAPI_STATIC_PROPERTY("DHCP",
+ NpiCommon::NapiValueByInt32(env, static_cast(IPSetMode::DHCP))),
+ };
+ NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+ return exports;
+}
+
+napi_value NapiEthernet::DeclareEthernetInterface(napi_env env, napi_value exports)
+{
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_FUNCTION("setIfaceConfig", SetIfaceConfig),
+ DECLARE_NAPI_FUNCTION("getIfaceConfig", GetIfaceConfig),
+ DECLARE_NAPI_FUNCTION("isActivate", IsActivate),
+ DECLARE_NAPI_FUNCTION("getActivateInterfaces", GetActivateInterfaces),
+ };
+ NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+ return exports;
+}
+
+napi_value NapiEthernet::RegisterEthernetInterface(napi_env env, napi_value exports)
+{
+ DeclareEthernetInterface(env, exports);
+ DeclareEthernetData(env, exports);
+ return nullptr;
+}
+
+static napi_module _ethernetModule = {
+ .nm_version = 1,
+ .nm_flags = 0,
+ .nm_filename = nullptr,
+ .nm_register_func = NapiEthernet::RegisterEthernetInterface,
+ .nm_modname = "netmanager.ethernet",
+ .nm_priv = ((void *)0),
+ .reserved = {0},
+};
+
+extern "C" __attribute__((constructor)) void RegisterEthernetModule(void)
+{
+ napi_module_register(&_ethernetModule);
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/frameworks/js/netpolicy/BUILD.gn b/frameworks/js/netpolicy/BUILD.gn
new file mode 100755
index 0000000..d504eed
--- /dev/null
+++ b/frameworks/js/netpolicy/BUILD.gn
@@ -0,0 +1,55 @@
+# 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.
+
+import("//build/ohos.gni")
+import(
+ "//foundation/communication/netmanager_standard/netmanager_base_config.gni")
+
+NETMANAGER_NAPI_ROOT = "$SUBSYSTEM_DIR/netmanager_standard/frameworks/js/"
+
+ohos_shared_library("netpolicy") {
+ include_dirs = [
+ "//third_party/node/src",
+ "$NETMANAGER_NAPI_ROOT/netpolicy/include",
+ "$NETMANAGER_NAPI_ROOT/common",
+ "$NETMANAGER_BASE_ROOT/utils/log/include",
+ "$NETPOLICYMANAGER_SOURCE_DIR/include",
+ "$NETPOLICYMANAGER_SOURCE_DIR/include/ipc",
+ ]
+
+ sources = [
+ "$NETMANAGER_NAPI_ROOT/common/napi_common.cpp",
+ "$NETMANAGER_NAPI_ROOT/netpolicy/src/napi_net_policy.cpp",
+ ]
+
+ defines = [ "NETMGR_DEBUG" ]
+
+ deps = [
+ "$INNERKITS_ROOT/native/netconnmanager:net_conn_manager_if",
+ "$INNERKITS_ROOT/native/netpolicymanager:net_policy_manager_if",
+ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
+ "//foundation/ace/napi/:ace_napi",
+ "//utils/native/base:utils",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ relative_install_dir = "module"
+ part_name = "netmanager_standard"
+ subsystem_name = "communication"
+}
diff --git a/frameworks/js/netpolicy/include/napi_net_policy.h b/frameworks/js/netpolicy/include/napi_net_policy.h
new file mode 100755
index 0000000..fc33b51
--- /dev/null
+++ b/frameworks/js/netpolicy/include/napi_net_policy.h
@@ -0,0 +1,73 @@
+/*
+ * 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 NAPI_NET_POLICY_H
+#define NAPI_NET_POLICY_H
+
+#include
+#include
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+#include "net_policy_constants.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+// net policy async context
+struct NetPolicyAsyncContext {
+ napi_async_work work = nullptr;
+ napi_deferred deferred = nullptr;
+ napi_ref callbackRef = nullptr;
+ // uid
+ uint32_t uid = 0;
+ // policy
+ uint32_t policy = 0;
+ // result of policy napi
+ int32_t policyResult = 0;
+ // vector of uid
+ std::vector uidTogether;
+ // result of bool type
+ bool result = false;
+ // metered
+ bool metered = false;
+ // interface name
+ std::string interfaceName;
+};
+
+class NapiNetPolicy {
+public:
+ NapiNetPolicy();
+ ~NapiNetPolicy() = default;
+ static napi_value RegisterNetPolicyInterface(napi_env env, napi_value exports);
+ static napi_value DeclareNapiNetPolicyInterface(napi_env env, napi_value exports);
+ static napi_value DeclareNapiNetPolicyData(napi_env env, napi_value exports);
+ static napi_value DeclareNapiNetPolicyResultData(napi_env env, napi_value exports);
+
+ static void ExecSetUidPolicy(napi_env env, void *data);
+ static void ExecGetUids(napi_env env, void *data);
+ static void ExecGetUidPolicy(napi_env env, void *data);
+ static void ExecIsUidNetAccess(napi_env env, void *data);
+ static void CompleteSetUidPolicy(napi_env env, napi_status status, void *data);
+ static void CompleteGetUids(napi_env env, napi_status status, void *data);
+ static void CompleteGetUidPolicy(napi_env env, napi_status status, void *data);
+ static void CompleteIsUidNetAccess(napi_env env, napi_status status, void *data);
+ // Declare napi interfaces for JS
+ static napi_value SetUidPolicy(napi_env env, napi_callback_info info);
+ static napi_value GetUidPolicy(napi_env env, napi_callback_info info);
+ static napi_value GetUids(napi_env env, napi_callback_info info);
+ static napi_value IsUidNetAccess(napi_env env, napi_callback_info info);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // NAPI_NET_POLICY_H
diff --git a/frameworks/js/netpolicy/src/napi_net_policy.cpp b/frameworks/js/netpolicy/src/napi_net_policy.cpp
new file mode 100755
index 0000000..e7831cb
--- /dev/null
+++ b/frameworks/js/netpolicy/src/napi_net_policy.cpp
@@ -0,0 +1,442 @@
+/*
+ * 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 "napi_net_policy.h"
+#include
+#include "system_ability_definition.h"
+#include "iservice_registry.h"
+#include "net_mgr_log_wrapper.h"
+#include "i_net_policy_service.h"
+#include "net_conn_constants.h"
+#include "net_policy_client.h"
+#include "napi_common.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+void NapiNetPolicy::ExecSetUidPolicy(napi_env env, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ NetUidPolicy policy = static_cast(context->policy);
+ context->policyResult =
+ static_cast(DelayedSingleton::GetInstance()->SetUidPolicy(context->uid, policy));
+ NETMGR_LOGI("ExecSetUidPolicy, policy = [%{public}d], policyResult = [%{public}d]",
+ context->policy, context->policyResult);
+}
+
+void NapiNetPolicy::ExecGetUids(napi_env env, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ NetUidPolicy policy = static_cast(context->policy);
+ context->uidTogether = DelayedSingleton::GetInstance()->GetUids(policy);
+ NETMGR_LOGI("ExecGetUids, policy = [%{public}d], res.length = [%{public}d]",
+ context->policy, static_cast(context->uidTogether.size()));
+}
+
+void NapiNetPolicy::ExecGetUidPolicy(napi_env env, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ context->policyResult =
+ static_cast(DelayedSingleton::GetInstance()->GetUidPolicy(context->uid));
+ NETMGR_LOGI("ExecGetUidPolicy, uid = [%{public}d], policyResult = [%{public}d]",
+ context->uid, context->policyResult);
+}
+
+void NapiNetPolicy::ExecIsUidNetAccess(napi_env env, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ if (context->interfaceName.length() > 0) {
+ context->result =
+ DelayedSingleton::GetInstance()->IsUidNetAccess(context->uid, context->interfaceName);
+ } else {
+ context->result =
+ DelayedSingleton::GetInstance()->IsUidNetAccess(context->uid, context->metered);
+ }
+}
+void NapiNetPolicy::CompleteSetUidPolicy(napi_env env, napi_status status, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ napi_create_int32(env, context->policyResult, &info);
+ if (context->callbackRef == nullptr) {
+ // promiss return
+ if (context->policyResult != static_cast(NetPolicyResultCode::ERR_NONE)) {
+ NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context->deferred, info));
+ } else {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ }
+ } else {
+ // call back
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ if (context->policyResult != static_cast(NetPolicyResultCode::ERR_NONE)) {
+ callbackValues[CALLBACK_ARGV_INDEX_0] = info;
+ } else {
+ callbackValues[CALLBACK_ARGV_INDEX_1] = info;
+ }
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+void NapiNetPolicy::CompleteGetUids(napi_env env, napi_status status, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ std::vector& res = context->uidTogether;
+ napi_create_array(env, &info);
+ for (unsigned int i = 0; i < res.size(); i++) {
+ napi_value num;
+ napi_create_uint32(env, res[i], &num);
+ napi_set_element(env, info, i, num);
+ }
+ if (!context->callbackRef) {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ } else {
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ callbackValues[CALLBACK_ARGV_INDEX_1] = info;
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+void NapiNetPolicy::CompleteGetUidPolicy(napi_env env, napi_status status, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ napi_create_int32(env, context->policyResult, &info);
+ if (!context->callbackRef) {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ } else {
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ callbackValues[CALLBACK_ARGV_INDEX_1] = info;
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+void NapiNetPolicy::CompleteIsUidNetAccess(napi_env env, napi_status status, void *data)
+{
+ NetPolicyAsyncContext* context = static_cast(data);
+ if (context == nullptr) {
+ NETMGR_LOGE("context == nullptr");
+ return;
+ }
+ napi_value info = nullptr;
+ napi_create_int32(env, context->result, &info);
+ if (!context->callbackRef) {
+ if (context->result == 0) {
+ NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context->deferred, info));
+ } else {
+ NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context->deferred, info));
+ }
+ } else {
+ napi_value callbackValues[CALLBACK_ARGV_CNT] = {nullptr, nullptr};
+ napi_value recv = nullptr;
+ napi_value result = nullptr;
+ napi_value callbackFunc = nullptr;
+ napi_get_undefined(env, &recv);
+ napi_get_reference_value(env, context->callbackRef, &callbackFunc);
+ if (context->result == 0) {
+ callbackValues[CALLBACK_ARGV_INDEX_0] = info;
+ } else {
+ callbackValues[CALLBACK_ARGV_INDEX_1] = info;
+ }
+ napi_call_function(env, recv, callbackFunc, std::size(callbackValues), callbackValues, &result);
+ napi_delete_reference(env, context->callbackRef);
+ }
+ napi_delete_async_work(env, context->work);
+ delete context;
+ context = nullptr;
+}
+
+napi_value NapiNetPolicy::DeclareNapiNetPolicyData(napi_env env, napi_value exports)
+{
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_STATIC_PROPERTY("NET_POLICY_NONE",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetUidPolicy::NET_POLICY_NONE))),
+ DECLARE_NAPI_STATIC_PROPERTY("NET_POLICY_ALLOW_METERED_BACKGROUND",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetUidPolicy::NET_POLICY_ALLOW_METERED_BACKGROUND))),
+ DECLARE_NAPI_STATIC_PROPERTY("NET_POLICY_TEMPORARY_ALLOW_METERED",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetUidPolicy::NET_POLICY_TEMPORARY_ALLOW_METERED))),
+ DECLARE_NAPI_STATIC_PROPERTY("NET_POLICY_REJECT_METERED_BACKGROUND",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetUidPolicy::NET_POLICY_REJECT_METERED_BACKGROUND))),
+ DECLARE_NAPI_STATIC_PROPERTY("NET_POLICY_ALLOW_ALL",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetUidPolicy::NET_POLICY_ALLOW_ALL))),
+ DECLARE_NAPI_STATIC_PROPERTY("NET_POLICY_REJECT_ALL",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetUidPolicy::NET_POLICY_REJECT_ALL))),
+ };
+ NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+ return exports;
+}
+
+napi_value NapiNetPolicy::DeclareNapiNetPolicyResultData(napi_env env, napi_value exports)
+{
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_STATIC_PROPERTY("ERR_NONE",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetPolicyResultCode::ERR_NONE))),
+ DECLARE_NAPI_STATIC_PROPERTY("ERR_INTERNAL_ERROR",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetPolicyResultCode::ERR_INTERNAL_ERROR))),
+ DECLARE_NAPI_STATIC_PROPERTY("ERR_INVALID_UID",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetPolicyResultCode::ERR_INVALID_UID))),
+ DECLARE_NAPI_STATIC_PROPERTY("ERR_INVALID_POLICY",
+ NpiCommon::NapiValueByInt32(env, static_cast(NetPolicyResultCode::ERR_INVALID_POLICY))),
+ };
+ NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+ return exports;
+}
+
+napi_value NapiNetPolicy::DeclareNapiNetPolicyInterface(napi_env env, napi_value exports)
+{
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_FUNCTION("setUidPolicy", SetUidPolicy),
+ DECLARE_NAPI_FUNCTION("getUidPolicy", GetUidPolicy),
+ DECLARE_NAPI_FUNCTION("getUids", GetUids),
+ DECLARE_NAPI_FUNCTION("isUidNetAccess", IsUidNetAccess),
+ };
+ NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+ return exports;
+}
+
+napi_value NapiNetPolicy::SetUidPolicy(napi_env env, napi_callback_info info)
+{
+ size_t argc = ARGV_NUM_3;
+ napi_value argv[] = {nullptr, nullptr, nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NetPolicyAsyncContext* context = std::make_unique().release();
+ NAPI_CALL(env, napi_get_value_uint32(env, argv[ARGV_INDEX_0], &context->uid));
+ NAPI_CALL(env, napi_get_value_uint32(env, argv[ARGV_INDEX_1], &context->policy));
+ NETMGR_LOGI("JS agvc count = [%{public}d], argv[ARGV_INDEX_0] = [%{public}d], argv[ARGV_INDEX_1] = [%{public}d]",
+ static_cast(argc), context->uid, context->policy);
+ napi_value result = nullptr;
+ if (argc == ARGV_INDEX_2) {
+ if (context->callbackRef == nullptr) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_INDEX_3) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_2], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("SetUidPolicy exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "SetUidPolicy", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecSetUidPolicy,
+ CompleteSetUidPolicy,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiNetPolicy::GetUidPolicy(napi_env env, napi_callback_info info)
+{
+ size_t argc = ARGV_INDEX_2;
+ napi_value argv[] = {nullptr, nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NetPolicyAsyncContext* context = std::make_unique().release();
+ NAPI_CALL(env, napi_get_value_uint32(env, argv[ARGV_INDEX_0], &context->uid));
+ NETMGR_LOGE("JS agvc count = [%{public}d], argv[0] = [%{public}d]",
+ static_cast(argc), context->uid);
+ // Get and verify parameter[js]
+ napi_value result = nullptr;
+ if (argc == ARGV_INDEX_1) {
+ if (!context->callbackRef) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_INDEX_2) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_1], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("GetUidPolicy exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "getUids", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecGetUidPolicy,
+ CompleteGetUidPolicy,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiNetPolicy::GetUids(napi_env env, napi_callback_info info)
+{
+ size_t argc = ARGV_INDEX_2;
+ napi_value argv[] = {nullptr, nullptr} ;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NetPolicyAsyncContext* context = std::make_unique().release();
+ NAPI_CALL(env, napi_get_value_uint32(env, argv[ARGV_INDEX_0], &context->policy));
+ NETMGR_LOGE("JS agvc count = [%{public}d], argv[0] = [%{public}d]",
+ static_cast(argc), context->policy);
+ // Get and verify parameter[js]
+ napi_value result = nullptr;
+ if (argc == ARGV_INDEX_1) {
+ if (!context->callbackRef) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_INDEX_2) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_INDEX_1], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("GetUids exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "getUids", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecGetUids,
+ CompleteGetUids,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiNetPolicy::IsUidNetAccess(napi_env env, napi_callback_info info)
+{
+ napi_valuetype valueType = napi_undefined;
+ size_t argc = ARGV_NUM_3;
+ napi_value argv[] = {nullptr, nullptr, nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ NetPolicyAsyncContext* context = std::make_unique().release();
+ NAPI_CALL(env, napi_get_value_uint32(env, argv[ARGV_NUM_0], &context->uid));
+ napi_typeof(env, argv[ARGV_NUM_1], &valueType);
+ if (napi_valuetype::napi_boolean == valueType) {
+ NAPI_CALL(env, napi_get_value_bool(env, argv[ARGV_NUM_1], &context->metered));
+ }
+ if (napi_valuetype::napi_string == valueType) {
+ char buf[BUFFER_BYTE] = {0};
+ size_t typeLen = 0;
+ napi_get_value_string_utf8(env, argv[ARGV_NUM_1], buf, sizeof(buf), &typeLen);
+ context->interfaceName = buf;
+ NETMGR_LOGE("interfaceName = [%{public}s].\n", context->interfaceName.c_str());
+ }
+ NETMGR_LOGI("JS agvc count = [%{public}d], argv[0] = [%{public}d], argv[1] = [%{public}d]",
+ static_cast(argc), context->uid, context->metered);
+ napi_value result = nullptr;
+ if (argc == ARGV_NUM_2) {
+ if (!context->callbackRef) {
+ NAPI_CALL(env, napi_create_promise(env, &context->deferred, &result));
+ } else {
+ NAPI_CALL(env, napi_get_undefined(env, &result));
+ }
+ } else if (argc == ARGV_NUM_3) {
+ NAPI_CALL(env, napi_create_reference(env, argv[ARGV_NUM_2], CALLBACK_REF_CNT, &context->callbackRef));
+ } else {
+ NETMGR_LOGE("IsUidNetAccess exception");
+ }
+ // creat async work
+ napi_value resource = nullptr;
+ napi_value resourceName = nullptr;
+ NAPI_CALL(env, napi_get_undefined(env, &resource));
+ NAPI_CALL(env, napi_create_string_utf8(env, "IsUidNetAccess", NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, resource, resourceName,
+ ExecIsUidNetAccess,
+ CompleteIsUidNetAccess,
+ (void *)context,
+ &context->work));
+ NAPI_CALL(env, napi_queue_async_work(env, context->work));
+ return result;
+}
+
+napi_value NapiNetPolicy::RegisterNetPolicyInterface(napi_env env, napi_value exports)
+{
+ NETMGR_LOGI("RegisterNetPolicyInterface");
+ DeclareNapiNetPolicyInterface(env, exports);
+ DeclareNapiNetPolicyData(env, exports);
+ DeclareNapiNetPolicyResultData(env, exports);
+ return nullptr;
+}
+
+static napi_module _netPolicyModule = {
+ .nm_version = 1,
+ .nm_flags = 0,
+ .nm_filename = nullptr,
+ .nm_register_func = NapiNetPolicy::RegisterNetPolicyInterface,
+ .nm_modname = "netmanager.netpolicy",
+ .nm_priv = ((void *)0),
+ .reserved = {0},
+};
+
+extern "C" __attribute__((constructor)) void RegisterNetPolicyModule(void)
+{
+ napi_module_register(&_netPolicyModule);
+}
+} // namespace NetManagerStandard
+} // namespace OHOS
diff --git a/interfaces/innerkits/native/dnsresolvermanager/BUILD.gn b/interfaces/innerkits/native/dnsresolvermanager/BUILD.gn
new file mode 100755
index 0000000..874b156
--- /dev/null
+++ b/interfaces/innerkits/native/dnsresolvermanager/BUILD.gn
@@ -0,0 +1,77 @@
+# 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.
+
+import("//build/ohos.gni")
+import(
+ "//foundation/communication/netmanager_standard/netmanager_base_config.gni")
+
+config("net_conn_manager_if_config") {
+ # header file path
+ include_dirs = [
+ "$DNSRESOLVERMANAGER_SOURCE_DIR/include/ipc/",
+ "$INNERKITS_ROOT/native/dnsresolvermanager/include",
+ "$INNERKITS_ROOT/native/netconnmanager/include",
+ "$INNERKITS_ROOT/native/include",
+ ]
+
+ cflags = []
+ if (is_double_framework) {
+ cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ]
+ }
+ if (target_cpu == "arm") {
+ cflags += [ "-DBINDER_IPC_32BIT" ]
+ }
+ if (is_standard_system) {
+ cflags += [ "-DCONFIG_STANDARD_SYSTEM" ]
+ }
+ if (defined(build_public_version) && build_public_version) {
+ cflags += [ "-DBUILD_PUBLIC_VERSION" ]
+ }
+}
+
+ohos_shared_library("dns_resolver_manager_if") {
+ sources = [
+ "$DNSRESOLVERMANAGER_INNERKITS_SOURCE_DIR/src/dns_addr_info.cpp",
+ "$DNSRESOLVERMANAGER_INNERKITS_SOURCE_DIR/src/dns_resolver_client.cpp",
+ "$DNSRESOLVERMANAGER_SOURCE_DIR/src/ipc/dns_resolver_service_proxy.cpp",
+ ]
+
+ include_dirs = [ "$DNSRESOLVERMANAGER_SOURCE_DIR/include/" ]
+
+ public_configs = [ ":net_conn_manager_if_config" ]
+
+ deps = [
+ "$INNERKITS_ROOT/native/netconnmanager:net_conn_manager_if",
+ "$NETMANAGER_BASE_ROOT/utils:net_manager_common",
+ ]
+
+ external_deps = [
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "NETMGR_LOG_TAG = \"DnsResolverManager\"",
+ "LOG_DOMAIN = 0xD0015B0",
+ ]
+
+ if (is_standard_system) {
+ external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps += [ "hilog:libhilog" ]
+ }
+
+ part_name = "netmanager_standard"
+ subsystem_name = "communication"
+}
diff --git a/interfaces/innerkits/native/dnsresolvermanager/include/dns_addr_info.h b/interfaces/innerkits/native/dnsresolvermanager/include/dns_addr_info.h
new file mode 100755
index 0000000..b955b00
--- /dev/null
+++ b/interfaces/innerkits/native/dnsresolvermanager/include/dns_addr_info.h
@@ -0,0 +1,39 @@
+/*
+ * 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 DNS_ADDR_INFO_H
+#define DNS_ADDR_INFO_H
+
+#include
+#include
+
+#include "parcel.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+struct DnsAddrInfo : public Parcelable {
+ int32_t flags_ = 0;
+ int32_t family_ = 0;
+ int32_t sockType_ = 0;
+ int32_t protocol_ = 0;
+ std::string addr_;
+ std::string canonName_;
+
+ bool Marshalling(Parcel &parcel) const override;
+ static sptr Unmarshalling(Parcel &parcel);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/native/dnsresolvermanager/include/dns_resolver_client.h b/interfaces/innerkits/native/dnsresolvermanager/include/dns_resolver_client.h
new file mode 100755
index 0000000..e461d60
--- /dev/null
+++ b/interfaces/innerkits/native/dnsresolvermanager/include/dns_resolver_client.h
@@ -0,0 +1,123 @@
+/*
+ * 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 DNS_RESOLVER_MANAGER_H
+#define DNS_RESOLVER_MANAGER_H
+
+#include
+
+#include "parcel.h"
+#include "singleton.h"
+
+#include "i_dns_resolver_service.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+class DnsResolverClient {
+ DECLARE_DELAYED_SINGLETON(DnsResolverClient)
+
+public:
+ /**
+ * @brief Get Addresses By domain Name
+ *
+ * @param The domain name
+ * @param The address information is parsed successfully
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t GetAddressesByName(const std::string &hostName, std::vector &addrInfo);
+ /**
+ * @brief Get Addresses By domain Name
+ *
+ * @param DNS server address
+ * @param DNS server address
+ * @param Address information structure
+ * @param The address information is parsed successfully
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t GetAddrInfo(const std::string &hostName, const std::string &server,
+ const sptr &hints, std::vector> &dnsAddrInfo);
+ /**
+ * @brief Create a network cache and netId mapping
+ *
+ * @param netId
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t CreateNetworkCache(uint16_t netId);
+ /**
+ * @brief Delete the network cache and remove the mapping with netId
+ *
+ * @param netId
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t DestoryNetworkCache(uint16_t netId);
+ /**
+ * @brief Clear the network cache information
+ *
+ * @param netId
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t FlushNetworkCache(uint16_t netId);
+ /**
+ * @brief Bind the DNS server address to netId
+ *
+ * @param netId
+ * @param Timeout of domain name request
+ * @param Number of Domain name Requests
+ * @param DNS server address information
+ * @param The domain name
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
+ const std::vector &servers, const std::vector &domains);
+ /**
+ * @brief Obtain domain name resolution configuration information
+ *
+ * @param netId
+ * @param DNS server address information
+ * @param The domain name
+ * @param Timeout of domain name request
+ * @param Number of Domain name Requests
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t GetResolverInfo(uint16_t netId, std::vector &servers,
+ std::vector &domains, uint16_t &baseTimeoutMsec, uint8_t &retryCount);
+
+private:
+ class DnsResolverDeathRecipient : public IRemoteObject::DeathRecipient {
+ public:
+ explicit DnsResolverDeathRecipient(DnsResolverClient &client) : client_(client) {}
+ ~DnsResolverDeathRecipient() override = default;
+ void OnRemoteDied(const wptr &remote) override
+ {
+ client_.OnRemoteDied(remote);
+ }
+
+ private:
+ DnsResolverClient &client_;
+ };
+
+private:
+ sptr GetProxy();
+ void OnRemoteDied(const wptr &remote);
+
+private:
+ std::mutex mutex_;
+ sptr dnsResolverService_;
+ sptr deathRecipient_;
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+
+#endif // DNS_RESOLVER_MANAGER_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/dnsresolvermanager/include/dns_resolver_constants.h b/interfaces/innerkits/native/dnsresolvermanager/include/dns_resolver_constants.h
new file mode 100755
index 0000000..31fed08
--- /dev/null
+++ b/interfaces/innerkits/native/dnsresolvermanager/include/dns_resolver_constants.h
@@ -0,0 +1,27 @@
+/*
+ * 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 DNS_RESOLVER_CONSTANTS_H
+#define DNS_RESOLVER_CONSTANTS_H
+
+#include "netmanager_constants.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+constexpr int DNS_ERROR = -1;
+constexpr int DNS_SUCCESS = 0;
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // DNS_RESOLVER_CONSTANTS_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/ethernetmanager/BUILD.gn b/interfaces/innerkits/native/ethernetmanager/BUILD.gn
new file mode 100755
index 0000000..5265e86
--- /dev/null
+++ b/interfaces/innerkits/native/ethernetmanager/BUILD.gn
@@ -0,0 +1,80 @@
+# 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.
+import("//build/ohos.gni")
+import(
+ "//foundation/communication/netmanager_standard/netmanager_base_config.gni")
+config("net_conn_manager_if_config") {
+ # header file path
+ include_dirs = [
+ "$ETHERNETMANAGER_SOURCE_DIR/include/ipc/",
+ "$INNERKITS_ROOT/native/ethernetmanager/include",
+ "$INNERKITS_ROOT/native/netconnmanager/include",
+ "$INNERKITS_ROOT/native/include",
+ ]
+
+ cflags = []
+ if (is_double_framework) {
+ cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ]
+ }
+ if (target_cpu == "arm") {
+ cflags += [ "-DBINDER_IPC_32BIT" ]
+ }
+ if (is_standard_system) {
+ cflags += [ "-DCONFIG_STANDARD_SYSTEM" ]
+ }
+ if (defined(build_public_version) && build_public_version) {
+ cflags += [ "-DBUILD_PUBLIC_VERSION" ]
+ }
+}
+
+ohos_shared_library("ethernet_manager_if") {
+ sources = [
+ "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/ethernet_client.cpp",
+ "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/interface_configuration.cpp",
+ "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/static_configuration.cpp",
+ "$ETHERNETMANAGER_SOURCE_DIR/src/ipc/ethernet_service_proxy.cpp",
+ ]
+
+ include_dirs = [ "$ETHERNETMANAGER_SOURCE_DIR/include/" ]
+
+ public_configs = [ ":net_conn_manager_if_config" ]
+
+ deps = [
+ "$INNERKITS_ROOT/native/netconnmanager:net_conn_manager_if",
+ "$NETMANAGER_BASE_ROOT/utils:net_manager_common",
+ ]
+
+ external_deps = [
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "NETMGR_LOG_TAG = \"EthernetManager\"",
+ "LOG_DOMAIN = 0xD0015B0",
+ ]
+
+ if (enable_netmgr_debug) {
+ defines += [ "NETMGR_DEBUG" ]
+ }
+
+ if (is_standard_system) {
+ external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps += [ "hilog:libhilog" ]
+ }
+
+ part_name = "netmanager_standard"
+ subsystem_name = "communication"
+}
diff --git a/interfaces/innerkits/native/ethernetmanager/include/ethernet_client.h b/interfaces/innerkits/native/ethernetmanager/include/ethernet_client.h
new file mode 100755
index 0000000..db6729c
--- /dev/null
+++ b/interfaces/innerkits/native/ethernetmanager/include/ethernet_client.h
@@ -0,0 +1,86 @@
+/*
+ * 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 ETHERNET_MANAGER_H
+#define ETHERNET_MANAGER_H
+
+#include
+
+#include "parcel.h"
+#include "singleton.h"
+
+#include "i_ethernet_service.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+class EthernetClient {
+ DECLARE_DELAYED_SINGLETON(EthernetClient)
+
+public:
+ /**
+ * @brief Set the network interface configuration
+ *
+ * @param Network interface name
+ * @param Network interface parameters
+ * @return Returns 0 as success, other values as failure
+ */
+ int32_t SetIfaceConfig(const std::string &iface, sptr &ic);
+ /**
+ * @brief Gets the network interface configuration parameters
+ *
+ * @param Network interface name
+ * @return Parameter is returned on success, null on failure
+ */
+ sptr GetIfaceConfig(const std::string &iface);
+ /**
+ * @brief Gets the network interface configuration parameters
+ *
+ * @param Network interface name
+ * @return Returns 1 for device open (active), 0 for device closed (inactive), and -1 for failure
+ */
+ int32_t IsActivate(const std::string &iface);
+ /**
+ * @brief Gets the list of active devices
+ *
+ * @return Return to device List
+ */
+ std::vector GetActivateInterfaces();
+
+private:
+ class EthernetDeathRecipient : public IRemoteObject::DeathRecipient {
+ public:
+ explicit EthernetDeathRecipient(EthernetClient &client) : client_(client) {}
+ ~EthernetDeathRecipient() override = default;
+ void OnRemoteDied(const wptr &remote) override
+ {
+ client_.OnRemoteDied(remote);
+ }
+
+ private:
+ EthernetClient &client_;
+ };
+
+private:
+ sptr GetProxy();
+ void OnRemoteDied(const wptr &remote);
+
+private:
+ std::mutex mutex_;
+ sptr ethernetService_;
+ sptr deathRecipient_;
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // ETHERNET_MANAGER_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/ethernetmanager/include/ethernet_constants.h b/interfaces/innerkits/native/ethernetmanager/include/ethernet_constants.h
new file mode 100755
index 0000000..3c42533
--- /dev/null
+++ b/interfaces/innerkits/native/ethernetmanager/include/ethernet_constants.h
@@ -0,0 +1,27 @@
+/*
+ * 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 ETHERNET_CONSTANTS_H
+#define ETHERNET_CONSTANTS_H
+
+#include "netmanager_constants.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+constexpr int ETHERNET_ERROR = -1;
+constexpr int ETHERNET_SUCCESS = 0;
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // ETHERNET_ERRORS_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/ethernetmanager/include/interface_configuration.h b/interfaces/innerkits/native/ethernetmanager/include/interface_configuration.h
new file mode 100755
index 0000000..7445f41
--- /dev/null
+++ b/interfaces/innerkits/native/ethernetmanager/include/interface_configuration.h
@@ -0,0 +1,36 @@
+/*
+ * 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 INTERFACE_CONFIGURATION_H
+#define INTERFACE_CONFIGURATION_H
+
+#include "static_configuration.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+typedef enum {
+ STATIC,
+ DHCP,
+} IPSetMode;
+struct InterfaceConfiguration : public Parcelable {
+ IPSetMode mode_;
+ StaticConfiguration ipStatic_;
+
+ virtual bool Marshalling(Parcel &parcel) const override;
+ static sptr Unmarshalling(Parcel &parcel);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/native/ethernetmanager/include/static_configuration.h b/interfaces/innerkits/native/ethernetmanager/include/static_configuration.h
new file mode 100755
index 0000000..b269f65
--- /dev/null
+++ b/interfaces/innerkits/native/ethernetmanager/include/static_configuration.h
@@ -0,0 +1,40 @@
+/*
+ * 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 STATIC_CONFIGURATION_H
+#define STATIC_CONFIGURATION_H
+
+#include
+#include
+
+#include "parcel.h"
+#include "inet_addr.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+struct StaticConfiguration : public Parcelable {
+ INetAddr ipAddr_;
+ INetAddr route_;
+ INetAddr gate_;
+ INetAddr netMask_;
+ std::vector dnsServers_;
+ std::string domain_;
+
+ virtual bool Marshalling(Parcel &parcel) const override;
+ static sptr Unmarshalling(Parcel &parcel);
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/native/include/netmanager_constants.h b/interfaces/innerkits/native/include/netmanager_constants.h
new file mode 100755
index 0000000..5dfc674
--- /dev/null
+++ b/interfaces/innerkits/native/include/netmanager_constants.h
@@ -0,0 +1,67 @@
+/*
+ * 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 NETMANAGER_CONSTANTS_H
+#define NETMANAGER_CONSTANTS_H
+
+#include
+
+namespace OHOS {
+namespace NetManagerStandard {
+constexpr int NETMANAGER_ERROR = -1;
+constexpr int NETMANAGER_SUCCESS = 0;
+
+enum {
+ NETMANAGER_COMMON = 0x00,
+ NETMANAGER_DNS_RESOLVER_MANAGER = 0x01,
+ NETMANAGER_ETHERNET_MANAGER = 0x02,
+ NETMANAGER_NET_CONN_MANAGER = 0x03,
+ NETMANAGER_NET_POLICY_MANAGER = 0x04,
+};
+
+// Error code for common
+constexpr ErrCode COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMUNICATION, NETMANAGER_COMMON);
+
+enum {
+ NETMANAGER_ERR_FAIL = COMMON_ERR_OFFSET,
+ NETMANAGER_ERR_MEMCPY_FAIL,
+ NETMANAGER_ERR_MEMSET_FAIL,
+ NETMANAGER_ERR_STRCPY_FAIL,
+ NETMANAGER_ERR_STRING_EMPTY,
+ NETMANAGER_ERR_LOCAL_PTR_NULL,
+ NETMANAGER_ERR_PERMISSION_ERR,
+ NETMANAGER_ERR_DESCRIPTOR_MISMATCH,
+ NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL,
+ NETMANAGER_ERR_WRITE_DATA_FAIL,
+ NETMANAGER_ERR_WRITE_REPLY_FAIL,
+ NETMANAGER_ERR_READ_DATA_FAIL,
+ NETMANAGER_ERR_READ_REPLY_FAIL,
+ NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL,
+ NETMANAGER_ERR_ADD_DEATH_RECIPIENT_FAIL,
+ NETMANAGER_ERR_REGISTER_CALLBACK_FAIL,
+ NETMANAGER_ERR_UNINIT,
+};
+
+// Error code for netmanager dns resolver
+constexpr ErrCode DNS_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMUNICATION, NETMANAGER_DNS_RESOLVER_MANAGER);
+// Error code for netmanager ethernet
+constexpr ErrCode ETHERNET_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMUNICATION, NETMANAGER_ETHERNET_MANAGER);
+// Error code for netmanager conn manager
+constexpr ErrCode CONN_MANAGER_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMUNICATION, NETMANAGER_NET_CONN_MANAGER);
+// Error code for netmanager policy manager
+constexpr ErrCode POLICY_MANAGER_ERR_OFFSET = ErrCodeOffset(SUBSYS_COMMUNICATION, NETMANAGER_NET_POLICY_MANAGER);
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // NETMANAGER_CONSTANTS_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/netconnmanager/BUILD.gn b/interfaces/innerkits/native/netconnmanager/BUILD.gn
new file mode 100755
index 0000000..6ed54b2
--- /dev/null
+++ b/interfaces/innerkits/native/netconnmanager/BUILD.gn
@@ -0,0 +1,83 @@
+# 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.
+
+import("//build/ohos.gni")
+import(
+ "//foundation/communication/netmanager_standard/netmanager_base_config.gni")
+
+config("net_conn_manager_if_config") {
+ # header file path
+ include_dirs = [
+ "$NETCONNMANAGER_SOURCE_DIR/include/ipc",
+ "$INNERKITS_ROOT/native/netconnmanager/include",
+ "$INNERKITS_ROOT/native/netconnmanager/include/ipc",
+ ]
+
+ cflags = []
+ if (is_double_framework) {
+ cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ]
+ }
+ if (target_cpu == "arm") {
+ cflags += [ "-DBINDER_IPC_32BIT" ]
+ }
+ if (is_standard_system) {
+ cflags += [ "-DCONFIG_STANDARD_SYSTEM" ]
+ }
+ if (defined(build_public_version) && build_public_version) {
+ cflags += [ "-DBUILD_PUBLIC_VERSION" ]
+ }
+}
+
+ohos_shared_library("net_conn_manager_if") {
+ sources = [
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/inet_addr.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/ipc/net_conn_callback_stub.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/net_conn_callback_info.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/net_conn_client.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/net_link_info.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/net_specifier.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/net_supplier_info.cpp",
+ "$NETCONNMANAGER_INNERKITS_SOURCE_DIR/src/route.cpp",
+ "$NETCONNMANAGER_SOURCE_DIR/src/ipc/net_conn_service_proxy.cpp",
+ ]
+
+ include_dirs = [ "$NETCONNMANAGER_SOURCE_DIR/include/" ]
+
+ public_configs = [ ":net_conn_manager_if_config" ]
+
+ deps = [ "$NETMANAGER_BASE_ROOT/utils:net_manager_common" ]
+
+ external_deps = [
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ defines = [
+ "NETMGR_LOG_TAG = \"NetConnManager\"",
+ "LOG_DOMAIN = 0xD0015B0",
+ ]
+
+ if (enable_netmgr_debug) {
+ defines += [ "NETMGR_DEBUG" ]
+ }
+
+ if (is_standard_system) {
+ external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps += [ "hilog:libhilog" ]
+ }
+
+ part_name = "netmanager_standard"
+ subsystem_name = "communication"
+}
diff --git a/interfaces/innerkits/native/netconnmanager/include/inet_addr.h b/interfaces/innerkits/native/netconnmanager/include/inet_addr.h
new file mode 100755
index 0000000..65615d5
--- /dev/null
+++ b/interfaces/innerkits/native/netconnmanager/include/inet_addr.h
@@ -0,0 +1,48 @@
+/*
+ * 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 INET_ADDR_H
+#define INET_ADDR_H
+
+#include
+
+#include "parcel.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+struct INetAddr : public Parcelable {
+ typedef enum {
+ UNKNOWN = 0x00,
+ IPV4 = 0x01,
+ IPV6 = 0x02,
+ } IpType;
+
+ uint8_t type_ = UNKNOWN;
+ uint8_t family_ = 0x00;
+ uint8_t prefixlen_ = 0;
+ std::string address_;
+ std::string netMask_;
+ std::string hostName_;
+
+ bool operator==(const INetAddr& obj) const;
+
+ virtual bool Marshalling(Parcel &parcel) const override;
+ static sptr Unmarshalling(Parcel &parcel);
+ static bool Marshalling(Parcel &parcel, const sptr &object);
+ std::string ToString(const std::string tab = "") const;
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/native/netconnmanager/include/ipc/i_net_conn_callback.h b/interfaces/innerkits/native/netconnmanager/include/ipc/i_net_conn_callback.h
new file mode 100755
index 0000000..c7fd30a
--- /dev/null
+++ b/interfaces/innerkits/native/netconnmanager/include/ipc/i_net_conn_callback.h
@@ -0,0 +1,41 @@
+/*
+ * 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 I_NET_CONN_CALLBACK_H
+#define I_NET_CONN_CALLBACK_H
+
+#include
+
+#include "iremote_broker.h"
+
+#include "net_conn_callback_info.h"
+
+namespace OHOS {
+namespace NetManagerStandard {
+class INetConnCallback : public IRemoteBroker {
+public:
+ virtual ~INetConnCallback() = default;
+public:
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NetManagerStandard.INetConnCallback");
+ enum {
+ NET_CONN_STATE_CHANGED = 0,
+ };
+
+public:
+ virtual int32_t NetConnStateChanged(const sptr &info) = 0;
+};
+} // namespace NetManagerStandard
+} // namespace OHOS
+#endif // I_NET_CONN_CALLBACK_H
diff --git a/interfaces/innerkits/native/netconnmanager/include/ipc/net_conn_callback_stub.h b/interfaces/innerkits/native/netconnmanager/include/ipc/net_conn_callback_stub.h
new file mode 100755
index 0000000..5eefd7e
--- /dev/null
+++ b/interfaces/innerkits/native/netconnmanager/include/ipc/net_conn_callback_stub.h
@@ -0,0 +1,46 @@
+/*
+ * 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 NET_CONN_CALLBACK_STUB_H
+#define NET_CONN_CALLBACK_STUB_H
+
+#include