forked from estkme-group/lpac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.c
128 lines (112 loc) · 2.81 KB
/
driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "driver.h"
#include "driver.private.h"
#include <stdio.h>
#include <string.h>
#ifdef LPAC_WITH_APDU_GBINDER
#include "driver/apdu/gbinder_hidl.h"
#endif
#ifdef LPAC_WITH_APDU_QMI
#include "driver/apdu/qmi.h"
#endif
#ifdef LPAC_WITH_APDU_QMI_QRTR
#include "driver/apdu/qmi_qrtr.h"
#endif
#ifdef LPAC_WITH_APDU_PCSC
#include "driver/apdu/pcsc.h"
#endif
#ifdef LPAC_WITH_APDU_AT
#include "driver/apdu/at.h"
#endif
#ifdef LPAC_WITH_HTTP_CURL
#include "driver/http/curl.h"
#endif
#include "driver/apdu/stdio.h"
#include "driver/http/stdio.h"
static const struct euicc_driver *drivers[] = {
#ifdef LPAC_WITH_APDU_GBINDER
&driver_apdu_gbinder_hidl,
#endif
#ifdef LPAC_WITH_APDU_QMI
&driver_apdu_qmi,
#endif
#ifdef LPAC_WITH_APDU_QMI_QRTR
&driver_apdu_qmi_qrtr,
#endif
#ifdef LPAC_WITH_APDU_PCSC
&driver_apdu_pcsc,
#endif
#ifdef LPAC_WITH_APDU_AT
&driver_apdu_at,
#endif
#ifdef LPAC_WITH_HTTP_CURL
&driver_http_curl,
#endif
&driver_apdu_stdio,
&driver_http_stdio,
NULL,
};
static const struct euicc_driver *_driver_apdu = NULL;
static const struct euicc_driver *_driver_http = NULL;
struct euicc_apdu_interface euicc_driver_interface_apdu;
struct euicc_http_interface euicc_driver_interface_http;
int (*euicc_driver_main_apdu)(int argc, char **argv) = NULL;
int (*euicc_driver_main_http)(int argc, char **argv) = NULL;
static const struct euicc_driver *_find_driver(enum euicc_driver_type type, const char *name)
{
for (int i = 0; drivers[i] != NULL; i++)
{
const struct euicc_driver *d = drivers[i];
if (d->type != type)
{
continue;
}
if (name == NULL)
{
return d;
}
if (strcmp(d->name, name) == 0)
{
return d;
}
}
return NULL;
}
int euicc_driver_init(const char *apdu_driver_name, const char *http_driver_name)
{
_driver_apdu = _find_driver(DRIVER_APDU, apdu_driver_name);
if (_driver_apdu == NULL)
{
fprintf(stderr, "No APDU driver found\n");
return -1;
}
_driver_http = _find_driver(DRIVER_HTTP, http_driver_name);
if (_driver_http == NULL)
{
fprintf(stderr, "No HTTP driver found\n");
return -1;
}
if (_driver_apdu->init(&euicc_driver_interface_apdu))
{
fprintf(stderr, "APDU driver init failed\n");
return -1;
}
if (_driver_http->init(&euicc_driver_interface_http))
{
fprintf(stderr, "HTTP driver init failed\n");
return -1;
}
euicc_driver_main_apdu = _driver_apdu->main;
euicc_driver_main_http = _driver_http->main;
return 0;
}
void euicc_driver_fini()
{
if (_driver_apdu != NULL)
{
_driver_apdu->fini(&euicc_driver_interface_apdu);
}
if (_driver_http != NULL)
{
_driver_http->fini(&euicc_driver_interface_http);
}
}