• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "get_mac_plugin.h"
17 
18 #include "edm_constants.h"
19 #include "edm_ipc_interface_code.h"
20 #include "ethernet_client.h"
21 #include "interface_type.h"
22 #include "string_serializer.h"
23 #include "iplugin_manager.h"
24 
25 namespace OHOS {
26 namespace EDM {
27 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetMacPlugin::GetPlugin());
28 
InitPlugin(std::shared_ptr<IPluginTemplate<GetMacPlugin,std::string>> ptr)29 void GetMacPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<GetMacPlugin, std::string>> ptr)
30 {
31     EDMLOGI("GetMacPlugin InitPlugin...");
32     std::map<std::string, std::map<IPlugin::PermissionType, std::string>> tagPermissions;
33     std::map<IPlugin::PermissionType, std::string> typePermissionsForTag11;
34     std::map<IPlugin::PermissionType, std::string> typePermissionsForTag12;
35     typePermissionsForTag11.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
36         EdmPermission::PERMISSION_ENTERPRISE_GET_NETWORK_INFO);
37     typePermissionsForTag12.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
38         EdmPermission::PERMISSION_ENTERPRISE_MANAGE_NETWORK);
39     tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_11, typePermissionsForTag11);
40     tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_12, typePermissionsForTag12);
41 
42     IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(tagPermissions, IPlugin::ApiType::PUBLIC);
43     ptr->InitAttribute(EdmInterfaceCode::GET_MAC, PolicyName::POLICY_GET_MAC, config, false);
44     ptr->SetSerializer(StringSerializer::GetInstance());
45 }
46 
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)47 ErrCode GetMacPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId)
48 {
49     EDMLOGI("GetMacPlugin OnGetPolicy.");
50     nmd::InterfaceConfigurationParcel config;
51     std::string networkInterface;
52     data.ReadString(networkInterface);
53     DelayedSingleton<NetManagerStandard::EthernetClient>::GetInstance()->GetInterfaceConfig(networkInterface, config);
54     reply.WriteInt32(ERR_OK);
55     reply.WriteString(config.hwAddr);
56     return ERR_OK;
57 }
58 } // namespace EDM
59 } // namespace OHOS
60