1 /******************************************************************************
2 *
3 * Copyright (C) 2018 ST Microelectronics S.A.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *
18 ******************************************************************************/
19 #define LOG_TAG "ese@1.2-service.st"
20 #include <android-base/properties.h>
21 #include <android/hardware/secure_element/1.2/ISecureElement.h>
22 #include <dlfcn.h>
23 #include <hidl/LegacySupport.h>
24 #include <log/log.h>
25
26 #include "SecureElement.h"
27
28 typedef int (*STEsePreProcess)(void);
29
30 // Generated HIDL files
31 using android::OK;
32 using android::sp;
33 using android::status_t;
34 using android::hardware::configureRpcThreadpool;
35 using android::hardware::joinRpcThreadpool;
36 using android::hardware::secure_element::V1_2::ISecureElement;
37 using android::hardware::secure_element::V1_2::implementation::SecureElement;
38
main()39 int main() {
40 ALOGD("Secure Element HAL Service 1.2 is starting.");
41 sp<ISecureElement> se_service = new SecureElement();
42 configureRpcThreadpool(1, true /*callerWillJoin*/);
43
44 // Ignore this dlopen if you don't need it.
45 std::string valueStr =
46 android::base::GetProperty("persist.vendor.se.stpreprocess", "");
47 void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
48 if (stdll) {
49 STEsePreProcess fn = (STEsePreProcess)dlsym(stdll, "pre_process");
50 if (fn) {
51 if (fn() == 0) {
52 ALOGD("%s: init done", __func__);
53 } else {
54 ALOGE("%s: Error init ", __func__);
55 }
56 }
57 }
58
59 status_t status = se_service->registerAsService("eSE1");
60 if (status != OK) {
61 LOG_ALWAYS_FATAL(
62 "Could not register service for Secure Element HAL Iface (%d).",
63 status);
64 return -1;
65 }
66
67 ALOGD("Secure Element Service is ready");
68 joinRpcThreadpool();
69 return 1;
70 }
71