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 "[email protected]"
20 #include <android/hardware/secure_element/1.0/ISecureElement.h>
21 #include <dlfcn.h>
22 #include <hidl/LegacySupport.h>
23 #include <log/log.h>
24
25 #include "SecureElement.h"
26 typedef int (*STEsePreProcess)(void);
27
28 // Generated HIDL files
29 using android::OK;
30 using android::sp;
31 using android::status_t;
32 using android::hardware::configureRpcThreadpool;
33 using android::hardware::joinRpcThreadpool;
34 using android::hardware::secure_element::V1_0::ISecureElement;
35 using android::hardware::secure_element::V1_0::implementation::SecureElement;
36
main()37 int main() {
38 ALOGD("Secure Element HAL Service 1.0 is starting.");
39
40 // Ignore this dlopen it doesn't needed.
41 #if defined(ST_LIB_32)
42 void* stdll = dlopen("/vendor/lib/libstpreprocess.so", RTLD_NOW);
43 #else
44 void* stdll = dlopen("/vendor/lib64/libstpreprocess.so", RTLD_NOW);
45 #endif
46 if (stdll) {
47 STEsePreProcess fn = (STEsePreProcess)dlsym(stdll, "pre_process");
48 if (fn) {
49 ALOGD("Result=%d", fn());
50 }
51 }
52 sp<ISecureElement> se_service = new SecureElement();
53 configureRpcThreadpool(1, true /*callerWillJoin*/);
54 status_t status = se_service->registerAsService("eSE1");
55 if (status != OK) {
56 LOG_ALWAYS_FATAL(
57 "Could not register service for Secure Element HAL Iface (%d).",
58 status);
59 return -1;
60 }
61
62 ALOGD("Secure Element Service is ready");
63 joinRpcThreadpool();
64 return 1;
65 }
66