1 /*
2 * Copyright (c) 2025-2026 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 <arpa/inet.h>
17 #include <sys/socket.h>
18
19 #include "errors.h"
20 #include "hilog/log.h"
21 #include "ipc_object_stub.h"
22 #include "ipc_types.h"
23 #include "message_parcel.h"
24 #include "netmgr_ext_log_wrapper.h"
25 #include "networkslice_ipc_interface_code.h"
26 #include "networkslice_service.h"
27 #include "net_manager_constants.h"
28 #include "networkslice_stub.h"
29
30 namespace OHOS {
31 namespace NetManagerStandard {
32
NetworkSliceStub()33 NetworkSliceStub::NetworkSliceStub()
34 {
35 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::SET_NETWORKSLICE_UEPOLICY)] =
36 &NetworkSliceStub::OnSetNetworkSlicePolicy;
37 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::NETWORKSLICE_INIT_UEPOLICY)] =
38 &NetworkSliceStub::OnNetworkSliceInitUePolicy;
39 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::NETWORKSLICE_ALLOWEDNSSAI_RPT)] =
40 &NetworkSliceStub::OnNetworkSliceAllowedNssaiRpt;
41 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::NETWORKSLICE_EHPLMN_RPT)] =
42 &NetworkSliceStub::OnNetworkSliceEhplmnRpt;
43 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::NETWORKSLICE_GETRSDBYDNN)] =
44 &NetworkSliceStub::OnGetRouteSelectionDescriptorByDNN;
45 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::NETWORKSLICE_GETRSDBYNETCAP)] =
46 &NetworkSliceStub::OnGetRSDByNetCap;
47 memberFuncMap_[static_cast<uint32_t>(NetworkSliceInterfaceCode::NETWORKSLICE_SETSASTATE)] =
48 &NetworkSliceStub::OnSetSaState;
49 }
50
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51 int32_t NetworkSliceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
52 MessageOption &option)
53 {
54 std::u16string myDescripter = NetworkSliceStub::GetDescriptor();
55 std::u16string remoteDescripter = data.ReadInterfaceToken();
56 if (myDescripter != remoteDescripter) {
57 NETMGR_EXT_LOG_E("descriptor checked fail");
58 return NETMANAGER_EXT_ERR_DESCRIPTOR_MISMATCH;
59 }
60 auto itFunc = memberFuncMap_.find(code);
61 if (itFunc != memberFuncMap_.end()) {
62 auto requestFunc = itFunc->second;
63 if (requestFunc != nullptr) {
64 return (this->*requestFunc)(data, reply);
65 }
66 }
67 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
68 }
69
OnSetNetworkSlicePolicy(MessageParcel & data,MessageParcel & reply)70 int32_t NetworkSliceStub::OnSetNetworkSlicePolicy(MessageParcel &data, MessageParcel &reply)
71 {
72 NETMGR_EXT_LOG_I("NetworkSliceStub::OnSetNetworkSlicePolicy");
73 int32_t buffersize = data.ReadInt32();
74 std::vector<uint8_t> buffer;
75 for (int32_t i = 0; i < buffersize; ++i) {
76 buffer.push_back(data.ReadUint8());
77 }
78 int32_t ret = NetworkSliceService::GetInstance().SetNetworkSliceUePolicy(buffer);
79 return NETMANAGER_EXT_SUCCESS;
80 }
81
OnNetworkSliceAllowedNssaiRpt(MessageParcel & data,MessageParcel & reply)82 int32_t NetworkSliceStub::OnNetworkSliceAllowedNssaiRpt(MessageParcel &data, MessageParcel &reply)
83 {
84 NETMGR_EXT_LOG_I("NetworkSliceStub::OnNetworkSliceAllowedNssaiRpt");
85 int32_t buffersize = data.ReadInt32();
86 std::vector<uint8_t> buffer;
87 for (int i = 0; i < buffersize; ++i) {
88 buffer.push_back(data.ReadUint8());
89 }
90 int32_t ret = NetworkSliceService::GetInstance().NetworkSliceAllowedNssaiRpt(buffer);
91 return NETMANAGER_EXT_SUCCESS;
92 }
93
OnNetworkSliceEhplmnRpt(MessageParcel & data,MessageParcel & reply)94 int32_t NetworkSliceStub::OnNetworkSliceEhplmnRpt(MessageParcel &data, MessageParcel &reply)
95 {
96 NETMGR_EXT_LOG_I("NetworkSliceStub::OnNetworkSliceEhplmnRpt");
97 int32_t buffersize = data.ReadInt32();
98 std::vector<uint8_t> buffer;
99 for (int i = 0; i < buffersize; ++i) {
100 buffer.push_back(data.ReadUint8());
101 }
102 int32_t ret = NetworkSliceService::GetInstance().NetworkSliceEhplmnRpt(buffer);
103 return NETMANAGER_EXT_SUCCESS;
104 }
105
OnNetworkSliceInitUePolicy(MessageParcel & data,MessageParcel & reply)106 int32_t NetworkSliceStub::OnNetworkSliceInitUePolicy(MessageParcel &data, MessageParcel &reply)
107 {
108 NETMGR_EXT_LOG_I("NetworkSliceStub::OnNetworkSliceInitUePolicy");
109 int32_t ret = NetworkSliceService::GetInstance().NetworkSliceInitUePolicy();
110 return NETMANAGER_EXT_SUCCESS;
111 }
112
OnGetRouteSelectionDescriptorByDNN(MessageParcel & data,MessageParcel & reply)113 int32_t NetworkSliceStub::OnGetRouteSelectionDescriptorByDNN(MessageParcel &data, MessageParcel &reply)
114 {
115 NETMGR_EXT_LOG_I("NetworkSliceStub::OnGetRouteSelectionDescriptorByDNN");
116 std::string dnn = data.ReadString();
117 std::string snssai;
118 uint8_t sscmode;
119 int32_t ret = NetworkSliceService::GetInstance().GetRouteSelectionDescriptorByDNN(dnn, snssai, sscmode);
120 reply.WriteString(snssai);
121 reply.WriteUint8(sscmode);
122 return NETMANAGER_EXT_SUCCESS;
123 }
124
OnGetRSDByNetCap(MessageParcel & data,MessageParcel & reply)125 int32_t NetworkSliceStub::OnGetRSDByNetCap(MessageParcel &data, MessageParcel &reply)
126 {
127 NETMGR_EXT_LOG_I("NetworkSliceStub::OnGetRSDByNetCap");
128 int32_t netcap = data.ReadInt32();
129 std::map<std::string, std::string> networkSliceParas;
130 int32_t ret = NetworkSliceService::GetInstance().GetRSDByNetCap(netcap, networkSliceParas);
131 if (networkSliceParas.find("dnn") != networkSliceParas.end() && !networkSliceParas["dnn"].empty()) {
132 reply.WriteString(networkSliceParas["dnn"]);
133 } else {
134 reply.WriteString("Invalid");
135 }
136 if (networkSliceParas.find("snssai") != networkSliceParas.end() && !networkSliceParas["snssai"].empty()) {
137 reply.WriteString(networkSliceParas["snssai"]);
138 } else {
139 reply.WriteString("Invalid");
140 }
141 if (networkSliceParas.find("sscmode") != networkSliceParas.end() && !networkSliceParas["sscmode"].empty()) {
142 reply.WriteString(networkSliceParas["sscmode"]);
143 } else {
144 reply.WriteString("0");
145 }
146 if (networkSliceParas.find("pdusessiontype") != networkSliceParas.end() &&
147 !networkSliceParas["pdusessiontype"].empty()) {
148 reply.WriteString(networkSliceParas["pdusessiontype"]);
149 } else {
150 reply.WriteString("0");
151 }
152 if (networkSliceParas.find("routebitmap") != networkSliceParas.end() && !networkSliceParas["routebitmap"].empty()) {
153 reply.WriteString(networkSliceParas["routebitmap"]);
154 } else {
155 reply.WriteString("0");
156 }
157 return ret;
158 }
159
OnSetSaState(MessageParcel & data,MessageParcel & reply)160 int32_t NetworkSliceStub::OnSetSaState(MessageParcel &data, MessageParcel &reply)
161 {
162 NETMGR_EXT_LOG_I("NetworkSliceStub::OnSetSaState");
163 bool isSaState = data.ReadBool();
164 int32_t ret = NetworkSliceService::GetInstance().SetSaState(isSaState);
165 return NETMANAGER_EXT_SUCCESS;
166 }
167 } // namespace NetManagerStandard
168 } // namespace OHOS
169