1 /*
2 * Copyright 2024 NXP
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "phNxpNciHal_WiredSeIface.h"
18
19 #include <dlfcn.h>
20 #include <phNxpNciHal.h>
21
22 #define TERMINAL_TYPE_ESE 0x01
23 #define TERMINAL_TYPE_EUICC 0x05
24 #define TERMINAL_TYPE_EUICC2 0x06
25
26 /*******************************************************************************
27 **
28 ** Function phNxpNciHal_WiredSeStart()
29 **
30 ** Description Starts wired-se HAL. This is the first Api to be invoked.
31 ** Once it is started it will run throughout the process
32 *lifecycle.
33 ** It is recommended to call from main() of service.
34 **
35 ** Parameters outHandle - Handle to the Wired SE subsystem.
36 ** Returns NFCSTATUS_SUCCESS if WiredSe HAL is started.
37 ** NFCSTATUS_FAILURE otherwise
38 *******************************************************************************/
39
phNxpNciHal_WiredSeStart(WiredSeHandle * outHandle)40 NFCSTATUS phNxpNciHal_WiredSeStart(WiredSeHandle* outHandle) {
41 if (outHandle == NULL) {
42 return NFCSTATUS_FAILED;
43 }
44 // Open WiredSe shared library
45 NXPLOG_NCIHAL_D("Opening (/vendor/lib64/WiredSe.so)");
46 outHandle->dlHandle = dlopen("/vendor/lib64/WiredSe.so", RTLD_NOW);
47 if (outHandle->dlHandle == NULL) {
48 NXPLOG_NCIHAL_E("Error : opening (/vendor/lib64/WiredSe.so) %s!!",
49 dlerror());
50 return NFCSTATUS_FAILED;
51 }
52 outHandle->start =
53 (WiredSeStartFunc_t)dlsym(outHandle->dlHandle, "WiredSeService_Start");
54 if (outHandle->start == NULL) {
55 NXPLOG_NCIHAL_E("Error : Failed to find symbol WiredSeService_Start %s!!",
56 dlerror());
57 return NFCSTATUS_FAILED;
58 }
59 outHandle->dispatchEvent = (WiredSeDispatchEventFunc_t)dlsym(
60 outHandle->dlHandle, "WiredSeService_DispatchEvent");
61 if (outHandle->dispatchEvent == NULL) {
62 NXPLOG_NCIHAL_E(
63 "Error : Failed to find symbol WiredSeService_DispatchEvent "
64 "%s!!",
65 dlerror());
66 return NFCSTATUS_FAILED;
67 }
68 NXPLOG_NCIHAL_D("Opened (/vendor/lib64/WiredSe.so)");
69 return outHandle->start(&outHandle->pWiredSeService);
70 }
71
72 /*******************************************************************************
73 **
74 ** Function phNxpNciHal_WiredSeDispatchEvent()
75 **
76 ** Description Dispatch events to wired-se subsystem.
77 **
78 ** Parameters outHandle - WiredSe Handle
79 ** Returns NFCSTATUS_SUCCESS if success.
80 ** NFCSTATUS_FAILURE otherwise
81 *******************************************************************************/
phNxpNciHal_WiredSeDispatchEvent(WiredSeHandle * inHandle,WiredSeEvtType evtType,WiredSeEvtData evtData)82 NFCSTATUS phNxpNciHal_WiredSeDispatchEvent(WiredSeHandle* inHandle,
83 WiredSeEvtType evtType,
84 WiredSeEvtData evtData) {
85 if (inHandle == NULL || inHandle->dispatchEvent == NULL ||
86 inHandle->pWiredSeService == NULL) {
87 return NFCSTATUS_FAILED;
88 }
89 WiredSeEvt event;
90 event.eventData = evtData;
91 event.event = evtType;
92 return inHandle->dispatchEvent(inHandle->pWiredSeService, event);
93 }
94