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