@@ -21,100 +21,109 @@ static QmiClientUim *uimClient = NULL;
2121
2222static int apdu_interface_connect (struct euicc_ctx * ctx )
2323{
24- g_autoptr (GError ) error = NULL ;
24+ g_autoptr (GError ) error = NULL ;
2525 QrtrNode * node = NULL ;
2626 QmiDevice * device = NULL ;
2727 QmiClient * client = NULL ;
2828 bool found = false;
2929
30- context = g_main_context_new ();
30+ context = g_main_context_new ();
3131
32- bus = qrtr_bus_new_sync (context , & error );
33- if (bus == NULL ) {
34- fprintf (stderr , "error: connect to QRTR bus failed: %s\n" , error -> message );
32+ bus = qrtr_bus_new_sync (context , & error );
33+ if (bus == NULL )
34+ {
35+ fprintf (stderr , "error: connect to QRTR bus failed: %s\n" , error -> message );
3536 return -1 ;
3637 }
3738
3839 /* Find QRTR node for UIM service */
39- for (GList * l = qrtr_bus_peek_nodes (bus ); l != NULL ; l = l -> next ) {
40+ for (GList * l = qrtr_bus_peek_nodes (bus ); l != NULL ; l = l -> next )
41+ {
4042 node = l -> data ;
4143
42- if (node && qrtr_node_lookup_port (node , QMI_SERVICE_UIM ) >= 0 ) {
44+ if (node && qrtr_node_lookup_port (node , QMI_SERVICE_UIM ) >= 0 )
45+ {
4346 found = true;
4447 break ;
4548 }
4649 }
4750
48- if (!found ) {
49- fprintf (stderr , "error: find QRTR node with UIM service failed\n" );
51+ if (!found )
52+ {
53+ fprintf (stderr , "error: find QRTR node with UIM service failed\n" );
5054 return -1 ;
5155 }
5256
53- device = qmi_device_new_from_node_sync (node , context , & error );
54- if (!device ) {
55- fprintf (stderr , "error: create QMI device from QRTR node failed: %s\n" , error -> message );
57+ device = qmi_device_new_from_node_sync (node , context , & error );
58+ if (!device )
59+ {
60+ fprintf (stderr , "error: create QMI device from QRTR node failed: %s\n" , error -> message );
5661 return -1 ;
5762 }
5863
59- qmi_device_open_sync (device , context , & error );
60- if (error ) {
61- fprintf (stderr , "error: open QMI device failed: %s\n" , error -> message );
64+ qmi_device_open_sync (device , context , & error );
65+ if (error )
66+ {
67+ fprintf (stderr , "error: open QMI device failed: %s\n" , error -> message );
6268 return -1 ;
6369 }
6470
65- client = qmi_device_allocate_client_sync (device , context , & error );
66- if (!client ) {
67- fprintf (stderr , "error: allocate QMI client failed: %s\n" , error -> message );
71+ client = qmi_device_allocate_client_sync (device , context , & error );
72+ if (!client )
73+ {
74+ fprintf (stderr , "error: allocate QMI client failed: %s\n" , error -> message );
6875 return -1 ;
6976 }
7077
71- uimClient = QMI_CLIENT_UIM (client );
78+ uimClient = QMI_CLIENT_UIM (client );
7279
7380 return 0 ;
7481}
7582
7683static void apdu_interface_disconnect (struct euicc_ctx * ctx )
7784{
78- g_autoptr (GError ) error = NULL ;
79- QmiClient * client = QMI_CLIENT (uimClient );
80- QmiDevice * device = QMI_DEVICE (qmi_client_get_device (client ));
85+ g_autoptr (GError ) error = NULL ;
86+ QmiClient * client = QMI_CLIENT (uimClient );
87+ QmiDevice * device = QMI_DEVICE (qmi_client_get_device (client ));
8188
82- qmi_device_release_client_sync (device , client , context , & error );
89+ qmi_device_release_client_sync (device , client , context , & error );
8390 uimClient = NULL ;
8491
85- g_main_context_unref (context );
92+ g_main_context_unref (context );
8693 context = NULL ;
8794}
8895
8996static int apdu_interface_transmit (struct euicc_ctx * ctx , uint8_t * * rx , uint32_t * rx_len , const uint8_t * tx , uint32_t tx_len )
9097{
91- g_autoptr (GError ) error = NULL ;
92- g_autoptr (GArray ) apdu_data = NULL ;
98+ g_autoptr (GError ) error = NULL ;
99+ g_autoptr (GArray ) apdu_data = NULL ;
93100
94101 /* Convert tx into request GArray */
95- apdu_data = g_array_new (FALSE, FALSE, sizeof (guint8 ));
102+ apdu_data = g_array_new (FALSE, FALSE, sizeof (guint8 ));
96103 for (uint32_t i = 0 ; i < tx_len ; i ++ )
97- g_array_append_val (apdu_data , tx [i ]);
104+ g_array_append_val (apdu_data , tx [i ]);
98105
99106 QmiMessageUimSendApduInput * input ;
100- input = qmi_message_uim_send_apdu_input_new ();
101- qmi_message_uim_send_apdu_input_set_slot (input , uimSlot , NULL );
102- qmi_message_uim_send_apdu_input_set_channel_id (input , lastChannelId , NULL );
103- qmi_message_uim_send_apdu_input_set_apdu (input , apdu_data , NULL );
107+ input = qmi_message_uim_send_apdu_input_new ();
108+ qmi_message_uim_send_apdu_input_set_slot (input , uimSlot , NULL );
109+ qmi_message_uim_send_apdu_input_set_channel_id (input , lastChannelId , NULL );
110+ qmi_message_uim_send_apdu_input_set_apdu (input , apdu_data , NULL );
104111
105112 QmiMessageUimSendApduOutput * output ;
106- output = qmi_client_uim_send_apdu_sync (uimClient , input , context , & error );
113+ output = qmi_client_uim_send_apdu_sync (uimClient , input , context , & error );
107114
108- qmi_message_uim_send_apdu_input_unref (input );
115+ qmi_message_uim_send_apdu_input_unref (input );
109116
110- if (!qmi_message_uim_send_apdu_output_get_result (output , & error )) {
111- fprintf (stderr , "error: send apdu operation failed: %s\n" , error -> message );
117+ if (!qmi_message_uim_send_apdu_output_get_result (output , & error ))
118+ {
119+ fprintf (stderr , "error: send apdu operation failed: %s\n" , error -> message );
112120 return -1 ;
113121 }
114122
115123 GArray * apdu_res = NULL ;
116- if (!qmi_message_uim_send_apdu_output_get_apdu_response (output , & apdu_res , & error )) {
117- fprintf (stderr , "error: get apdu response operation failed: %s\n" , error -> message );
124+ if (!qmi_message_uim_send_apdu_output_get_apdu_response (output , & apdu_res , & error ))
125+ {
126+ fprintf (stderr , "error: get apdu response operation failed: %s\n" , error -> message );
118127 return -1 ;
119128 }
120129
@@ -126,92 +135,98 @@ static int apdu_interface_transmit(struct euicc_ctx *ctx, uint8_t **rx, uint32_t
126135 for (guint i = 0 ; i < apdu_res -> len ; i ++ )
127136 (* rx )[i ] = apdu_res -> data [i ];
128137
129- qmi_message_uim_send_apdu_output_unref (output );
138+ qmi_message_uim_send_apdu_output_unref (output );
130139
131140 return 0 ;
132141}
133142
134143static int apdu_interface_logic_channel_open (struct euicc_ctx * ctx , const uint8_t * aid , uint8_t aid_len )
135144{
136- g_autoptr (GError ) error = NULL ;
145+ g_autoptr (GError ) error = NULL ;
137146 guint8 channel_id ;
138147
139- GArray * aid_data = g_array_new (FALSE, FALSE, sizeof (guint8 ));
148+ GArray * aid_data = g_array_new (FALSE, FALSE, sizeof (guint8 ));
140149 for (int i = 0 ; i < aid_len ; i ++ )
141- g_array_append_val (aid_data , aid [i ]);
150+ g_array_append_val (aid_data , aid [i ]);
142151
143152 QmiMessageUimOpenLogicalChannelInput * input ;
144- input = qmi_message_uim_open_logical_channel_input_new ();
145- qmi_message_uim_open_logical_channel_input_set_slot (input , uimSlot , NULL );
146- qmi_message_uim_open_logical_channel_input_set_aid (input , aid_data , NULL );
153+ input = qmi_message_uim_open_logical_channel_input_new ();
154+ qmi_message_uim_open_logical_channel_input_set_slot (input , uimSlot , NULL );
155+ qmi_message_uim_open_logical_channel_input_set_aid (input , aid_data , NULL );
147156
148157 QmiMessageUimOpenLogicalChannelOutput * output ;
149- output = qmi_client_uim_open_logical_channel_sync (uimClient , input , context , & error );
158+ output = qmi_client_uim_open_logical_channel_sync (uimClient , input , context , & error );
150159
151- qmi_message_uim_open_logical_channel_input_unref (input );
152- g_array_unref (aid_data );
160+ qmi_message_uim_open_logical_channel_input_unref (input );
161+ g_array_unref (aid_data );
153162
154- if (!output ) {
155- fprintf (stderr , "error: send Open Logical Channel command failed: %s\n" , error -> message );
163+ if (!output )
164+ {
165+ fprintf (stderr , "error: send Open Logical Channel command failed: %s\n" , error -> message );
156166 return -1 ;
157167 }
158168
159- if (!qmi_message_uim_open_logical_channel_output_get_result (output , & error )) {
160- fprintf (stderr , "error: open logical channel operation failed: %s\n" , error -> message );
169+ if (!qmi_message_uim_open_logical_channel_output_get_result (output , & error ))
170+ {
171+ fprintf (stderr , "error: open logical channel operation failed: %s\n" , error -> message );
161172 return -1 ;
162173 }
163174
164- if (!qmi_message_uim_open_logical_channel_output_get_channel_id (output , & channel_id , & error )) {
165- fprintf (stderr , "error: get channel id operation failed: %s\n" , error -> message );
175+ if (!qmi_message_uim_open_logical_channel_output_get_channel_id (output , & channel_id , & error ))
176+ {
177+ fprintf (stderr , "error: get channel id operation failed: %s\n" , error -> message );
166178 return -1 ;
167179 }
168180 lastChannelId = channel_id ;
169181
170- g_debug ("Opened logical channel with id %d" , channel_id );
182+ g_debug ("Opened logical channel with id %d" , channel_id );
171183
172- qmi_message_uim_open_logical_channel_output_unref (output );
184+ qmi_message_uim_open_logical_channel_output_unref (output );
173185
174186 return channel_id ;
175187}
176188
177189static void apdu_interface_logic_channel_close (struct euicc_ctx * ctx , uint8_t channel )
178190{
179- g_autoptr (GError ) error = NULL ;
191+ g_autoptr (GError ) error = NULL ;
180192
181193 QmiMessageUimLogicalChannelInput * input ;
182- input = qmi_message_uim_logical_channel_input_new ();
183- qmi_message_uim_logical_channel_input_set_slot (input , uimSlot , NULL );
184- qmi_message_uim_logical_channel_input_set_channel_id (input , channel , NULL );
194+ input = qmi_message_uim_logical_channel_input_new ();
195+ qmi_message_uim_logical_channel_input_set_slot (input , uimSlot , NULL );
196+ qmi_message_uim_logical_channel_input_set_channel_id (input , channel , NULL );
185197
186198 QmiMessageUimLogicalChannelOutput * output ;
187- output = qmi_client_uim_logical_channel_sync (uimClient , input , context , & error );
199+ output = qmi_client_uim_logical_channel_sync (uimClient , input , context , & error );
188200
189- qmi_message_uim_logical_channel_input_unref (input );
201+ qmi_message_uim_logical_channel_input_unref (input );
190202
191- if (error ) {
192- fprintf (stderr , "error: send Close Logical Channel command failed: %s\n" , error -> message );
203+ if (error )
204+ {
205+ fprintf (stderr , "error: send Close Logical Channel command failed: %s\n" , error -> message );
193206 return ;
194207 }
195208
196- if (!qmi_message_uim_logical_channel_output_get_result (output , & error )) {
197- fprintf (stderr , "error: logical channel operation failed: %s\n" , error -> message );
209+ if (!qmi_message_uim_logical_channel_output_get_result (output , & error ))
210+ {
211+ fprintf (stderr , "error: logical channel operation failed: %s\n" , error -> message );
198212 return ;
199213 }
200214
201215 /* Mark channel as having been cleaned up */
202216 if (channel == lastChannelId )
203217 lastChannelId = -1 ;
204218
205- g_debug ("Closed logical channel with id %d" , channel );
219+ g_debug ("Closed logical channel with id %d" , channel );
206220
207- qmi_message_uim_logical_channel_output_unref (output );
221+ qmi_message_uim_logical_channel_output_unref (output );
208222}
209223
210224static void cleanup (void )
211225{
212- if (lastChannelId != -1 ) {
213- fprintf (stderr , "Cleaning up leaked APDU channel %d\n" , lastChannelId );
214- apdu_interface_logic_channel_close (NULL , lastChannelId );
226+ if (lastChannelId != -1 )
227+ {
228+ fprintf (stderr , "Cleaning up leaked APDU channel %d\n" , lastChannelId );
229+ apdu_interface_logic_channel_close (NULL , lastChannelId );
215230 lastChannelId = -1 ;
216231 }
217232}
@@ -240,9 +255,12 @@ static int libapduinterface_init(struct euicc_apdu_interface *ifstruct)
240255 * Allow the user to select the SIM card slot via environment variable.
241256 * Use the primary SIM slot if not set.
242257 */
243- if (getenv ("UIM_SLOT" )) {
258+ if (getenv ("UIM_SLOT" ))
259+ {
244260 uimSlot = atoi (getenv ("UIM_SLOT" ));
245- } else {
261+ }
262+ else
263+ {
246264 uimSlot = 1 ;
247265 }
248266
0 commit comments