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 <dlfcn.h>
17 #include "data_service_ext_wrapper.h"
18 #include "telephony_log_wrapper.h"
19 #include "cellular_data_constant.h"
20 #include "parameter.h"
21
22 namespace OHOS {
23 namespace Telephony {
DataServiceExtWrapper()24 DataServiceExtWrapper::DataServiceExtWrapper() {}
~DataServiceExtWrapper()25 DataServiceExtWrapper::~DataServiceExtWrapper()
26 {
27 TELEPHONY_LOGD("DataServiceExtWrapper::~DataServiceExtWrapper() start");
28 dlclose(DataServiceExtWrapperHandle_);
29 DataServiceExtWrapperHandle_ = nullptr;
30 }
31
InitDataServiceExtWrapper()32 void DataServiceExtWrapper::InitDataServiceExtWrapper()
33 {
34 TELEPHONY_LOGD("DataServiceExtWrapper::InitDataServiceExtWrapper() start");
35 char pathName[PATH_PARAMETER_SIZE] = {0};
36 int retLen = GetParameter(CONFIG_DATA_SERVICE_EXT_PATH, "", pathName, PATH_PARAMETER_SIZE);
37 if (retLen == 0) {
38 TELEPHONY_LOGE("Failed to get vendor library path through system properties.");
39 return;
40 }
41 DataServiceExtWrapperHandle_ = dlopen(pathName, RTLD_NOW);
42 if (DataServiceExtWrapperHandle_ == nullptr) {
43 TELEPHONY_LOGE("DATA_SERVICE_EXT_WRAPPER_PATH was not loaded, error: %{public}s", dlerror());
44 return;
45 }
46
47 requestTcpAndDnsPackets_ = (REQUEST_TCP_AND_DNS_PACKETS)dlsym(DataServiceExtWrapperHandle_,
48 "SendTcpPktCollecToKernel");
49 // Check whether all function pointers are empty.
50 if (requestTcpAndDnsPackets_ == nullptr) {
51 TELEPHONY_LOGE("data service ext wrapper symbol failed, error: %{public}s", dlerror());
52 return;
53 }
54 TELEPHONY_LOGI("data service ext wrapper init success");
55 }
56 } // namespace Telephony
57 } // namespace OHOS