1 /* 2 * Copyright (c) 2025 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 #include "configuration_parcel_ipc.h" 16 #include "netmgr_ext_log_wrapper.h" 17 18 namespace OHOS { 19 namespace NetManagerStandard { Marshalling(Parcel & parcel) const20bool ConfigurationParcelIpc::Marshalling(Parcel &parcel) const 21 { 22 if (!parcel.WriteString(ifName_)) { 23 return false; 24 } 25 if (!parcel.WriteString(hwAddr_)) { 26 return false; 27 } 28 if (!parcel.WriteString(ipv4Addr_)) { 29 return false; 30 } 31 if (!parcel.WriteInt32(prefixLength_)) { 32 return false; 33 } 34 int32_t flagsSize = static_cast<int32_t>(flags_.size()); 35 if (!parcel.WriteInt32(flagsSize)) { 36 return false; 37 } 38 39 for (auto flag : flags_) { 40 if (!parcel.WriteString(flag)) { 41 return false; 42 } 43 } 44 return true; 45 } 46 Unmarshalling(Parcel & parcel)47ConfigurationParcelIpc* ConfigurationParcelIpc::Unmarshalling(Parcel &parcel) 48 { 49 std::unique_ptr<ConfigurationParcelIpc> ptr = std::make_unique<ConfigurationParcelIpc>(); 50 if (ptr == nullptr) { 51 NETMGR_EXT_LOG_E("ptr is null"); 52 return nullptr; 53 } 54 if (!parcel.ReadString(ptr->ifName_)) { 55 return nullptr; 56 } 57 if (!parcel.ReadString(ptr->hwAddr_)) { 58 return nullptr; 59 } 60 if (!parcel.ReadString(ptr->ipv4Addr_)) { 61 return nullptr; 62 } 63 if (!parcel.ReadInt32(ptr->prefixLength_)) { 64 return nullptr; 65 } 66 int32_t length = 0; 67 if (!parcel.ReadInt32(length)) { 68 return nullptr; 69 } 70 std::string flags; 71 length = (length > MAX_FLAG_NUM) ? MAX_FLAG_NUM : length; 72 for (int32_t idx = 0; idx < length; idx++) { 73 if (!parcel.ReadString(flags)) { 74 return nullptr; 75 } 76 ptr->flags_.push_back(flags); 77 } 78 return ptr.release(); 79 } 80 ConvertEtherConfigParcelToNmd(const ConfigurationParcelIpc & ipc,OHOS::nmd::InterfaceConfigurationParcel & cfg)81void ConfigurationParcelIpc::ConvertEtherConfigParcelToNmd(const ConfigurationParcelIpc &ipc, 82 OHOS::nmd::InterfaceConfigurationParcel &cfg) 83 { 84 cfg.ifName = ipc.ifName_; 85 cfg.hwAddr = ipc.hwAddr_; 86 cfg.ipv4Addr = ipc.ipv4Addr_; 87 cfg.prefixLength = ipc.prefixLength_; 88 cfg.flags = ipc.flags_; 89 } 90 ConvertNmdToEtherConfigParcel(ConfigurationParcelIpc & ipc,const OHOS::nmd::InterfaceConfigurationParcel & cfg)91void ConfigurationParcelIpc::ConvertNmdToEtherConfigParcel(ConfigurationParcelIpc &ipc, 92 const OHOS::nmd::InterfaceConfigurationParcel &cfg) 93 { 94 ipc.ifName_ = cfg.ifName; 95 ipc.hwAddr_ = cfg.hwAddr; 96 ipc.ipv4Addr_ = cfg.ipv4Addr; 97 ipc.prefixLength_ = cfg.prefixLength; 98 ipc.flags_ = cfg.flags; 99 } 100 } 101 } 102