1 /*
2 * Copyright (c) 2024 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 "sysvpn_config.h"
17 #include "ipsecvpn_config.h"
18 #include "l2tpvpn_config.h"
19 #include "netmgr_ext_log_wrapper.h"
20
21 namespace OHOS {
22 namespace NetManagerStandard {
23
Marshalling(Parcel & parcel) const24 bool SysVpnConfig::Marshalling(Parcel &parcel) const
25 {
26 // add vpnType first
27 parcel.WriteInt32(vpnType_);
28
29 bool allOK = VpnConfig::Marshalling(parcel) &&
30 parcel.WriteString(vpnId_) &&
31 parcel.WriteString(vpnName_) &&
32 parcel.WriteInt32(vpnType_) &&
33 parcel.WriteString(userName_) &&
34 parcel.WriteString(password_) &&
35 parcel.WriteBool(saveLogin_) &&
36 parcel.WriteInt32(userId_) &&
37 parcel.WriteString(forwardingRoutes_);
38 if (!allOK) {
39 NETMGR_EXT_LOG_I("sysvpn SysVpnConfig Marshalling failed");
40 }
41 return allOK;
42 }
43
Unmarshalling(Parcel & parcel)44 sptr<SysVpnConfig> SysVpnConfig::Unmarshalling(Parcel &parcel)
45 {
46 // get vpnType first
47 int32_t type = -1;
48 parcel.ReadInt32(type);
49
50 switch (type) {
51 case static_cast<int32_t>(VpnType::IKEV2_IPSEC_MSCHAPv2):
52 case static_cast<int32_t>(VpnType::IKEV2_IPSEC_PSK):
53 case static_cast<int32_t>(VpnType::IKEV2_IPSEC_RSA):
54 case static_cast<int32_t>(VpnType::IPSEC_XAUTH_PSK):
55 case static_cast<int32_t>(VpnType::IPSEC_XAUTH_RSA):
56 case static_cast<int32_t>(VpnType::IPSEC_HYBRID_RSA):
57 return IpsecVpnConfig::Unmarshalling(parcel);
58 case static_cast<int32_t>(VpnType::L2TP_IPSEC_PSK):
59 case static_cast<int32_t>(VpnType::L2TP_IPSEC_RSA):
60 return L2tpVpnConfig::Unmarshalling(parcel);
61 default:
62 NETMGR_EXT_LOG_E("sysvpn SysVpnConfig Unmarshalling failed, type=%{public}d", type);
63 return nullptr;
64 }
65 }
66
Unmarshalling(Parcel & parcel,sptr<SysVpnConfig> ptr)67 bool SysVpnConfig::Unmarshalling(Parcel &parcel, sptr<SysVpnConfig> ptr)
68 {
69 bool allOK = VpnConfig::UnmarshallingVpnConfig(parcel, ptr) &&
70 parcel.ReadString(ptr->vpnId_) &&
71 parcel.ReadString(ptr->vpnName_) &&
72 parcel.ReadInt32(ptr->vpnType_) &&
73 parcel.ReadString(ptr->userName_) &&
74 parcel.ReadString(ptr->password_) &&
75 parcel.ReadBool(ptr->saveLogin_) &&
76 parcel.ReadInt32(ptr->userId_) &&
77 parcel.ReadString(ptr->forwardingRoutes_);
78 if (!allOK) {
79 NETMGR_EXT_LOG_I("sysvpn SysVpnConfig Unmarshalling failed");
80 }
81 return allOK;
82 }
83 } // namespace NetManagerStandard
84 } // namespace OHOS