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   void* stdll = dlopen("/vendor/lib64/libstpreprocess.so", RTLD_NOW);
42   if (stdll) {
43     STEsePreProcess fn = (STEsePreProcess)dlsym(stdll, "pre_process");
44     if (fn) {
45       ALOGD("Result=%d", fn());
46     }
47   }
48   sp<ISecureElement> se_service = new SecureElement();
49   configureRpcThreadpool(1, true /*callerWillJoin*/);
50   status_t status = se_service->registerAsService("eSE1");
51   if (status != OK) {
52     LOG_ALWAYS_FATAL(
53         "Could not register service for Secure Element HAL Iface (%d).",
54         status);
55     return -1;
56   }
57 
58   ALOGD("Secure Element Service is ready");
59   joinRpcThreadpool();
60   return 1;
61 }
62