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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/*
* This file is part of Samsung-RIL.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
* Copyright (C) 2011-2013 Paul Kocialkowski <contact@paulk.fr>
*
* Samsung-RIL is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Samsung-RIL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Samsung-RIL. If not, see <http://www.gnu.org/licenses/>.
*/
#define LOG_TAG "RIL-IPC"
#include <utils/Log.h>
#include "samsung-ril.h"
/*
* IPC shared
*/
void ipc_log_handler(void *log_data, const char *message)
{
LOGD("ipc: %s", message);
}
/*
* IPC FMT
*/
void ipc_fmt_send(const unsigned short command, const char type, unsigned char *data, const int length, unsigned char mseq)
{
struct ipc_client *ipc_client;
if (ril_data.ipc_fmt_client == NULL || ril_data.ipc_fmt_client->data == NULL)
return;
ipc_client = (struct ipc_client *) ril_data.ipc_fmt_client->data;
RIL_CLIENT_LOCK(ril_data.ipc_fmt_client);
ipc_client_send(ipc_client, command, type, data, length, mseq);
RIL_CLIENT_UNLOCK(ril_data.ipc_fmt_client);
}
int ipc_fmt_read_loop(struct ril_client *client)
{
struct ipc_client *ipc_client;
struct ipc_message_info info;
int rc;
if (client == NULL || client->data == NULL)
return -EINVAL;
ipc_client = (struct ipc_client *) client->data;
while (1) {
rc = ipc_client_poll(ipc_client, NULL);
if (rc < 0) {
LOGE("IPC FMT client poll failed, aborting");
return -1;
}
memset(&info, 0, sizeof(info));
RIL_CLIENT_LOCK(client);
if (ipc_client_recv(ipc_client, &info) < 0) {
RIL_CLIENT_UNLOCK(client);
LOGE("IPC FMT recv failed, aborting");
return -1;
}
RIL_CLIENT_UNLOCK(client);
ipc_fmt_dispatch(&info);
ipc_client_response_free(ipc_client, &info);
}
return 0;
}
int ipc_fmt_create(struct ril_client *client)
{
struct ipc_client *ipc_client;
int rc;
if (client == NULL)
return -EINVAL;
LOGD("Creating new FMT client");
ipc_client = ipc_client_create(IPC_CLIENT_TYPE_FMT);
if (ipc_client == NULL) {
LOGE("FMT client creation failed");
goto error_client_create;
}
client->data = (void *) ipc_client;
LOGD("Setting log handler");
rc = ipc_client_set_log_callback(ipc_client, ipc_log_handler, NULL);
if (rc < 0) {
LOGE("Setting log handler failed");
goto error_log_callback;
}
LOGD("Creating data");
rc = ipc_client_data_create(ipc_client);
if (rc < 0) {
LOGE("Creating data failed");
goto error_data_create;
}
LOGD("Starting bootstrap");
rc = ipc_client_bootstrap(ipc_client);
if (rc < 0) {
LOGE("Modem bootstrap failed");
goto error_bootstrap;
}
LOGD("Client power on...");
rc = ipc_client_power_on(ipc_client);
if (rc < 0) {
LOGE("%s: failed to power on ipc client", __func__);
goto error_power_on;
}
LOGD("Client open...");
rc = ipc_client_open(ipc_client);
if (rc < 0) {
LOGE("%s: failed to open ipc client", __func__);
goto error_open;
}
LOGD("IPC FMT client done");
return 0;
error:
ipc_client_power_off(ipc_client);
error_power_on:
error_get_fd:
ipc_client_close(ipc_client);
error_open:
error_bootstrap:
ipc_client_data_destroy(ipc_client);
error_data_create:
error_log_callback:
ipc_client_destroy(ipc_client);
error_client_create:
client->data = NULL;
return -1;
}
int ipc_fmt_destroy(struct ril_client *client)
{
struct ipc_client *ipc_client;
int rc;
if (client == NULL || client->data == NULL) {
LOGE("Client was already destroyed");
return 0;
}
ipc_client = (struct ipc_client *) client->data;
LOGD("Destroying ipc fmt client");
if (ipc_client != NULL) {
ipc_client_power_off(ipc_client);
ipc_client_close(ipc_client);
ipc_client_data_destroy(ipc_client);
ipc_client_destroy(ipc_client);
}
client->data = NULL;
return 0;
}
/*
* IPC RFS
*/
void ipc_rfs_send(const unsigned short command, unsigned char *data, const int length, unsigned char mseq)
{
struct ipc_client *ipc_client;
if (ril_data.ipc_rfs_client == NULL || ril_data.ipc_rfs_client->data == NULL)
return;
ipc_client = (struct ipc_client *) ril_data.ipc_rfs_client->data;
RIL_CLIENT_LOCK(ril_data.ipc_rfs_client);
ipc_client_send(ipc_client, command, 0, data, length, mseq);
RIL_CLIENT_UNLOCK(ril_data.ipc_rfs_client);
}
int ipc_rfs_read_loop(struct ril_client *client)
{
struct ipc_client *ipc_client;
struct ipc_message_info info;
int rc;
if (client == NULL || client->data == NULL)
return -EINVAL;
ipc_client = (struct ipc_client *) client->data;
while (1) {
rc = ipc_client_poll(ipc_client, NULL);
if (rc < 0) {
LOGE("IPC RFS client poll failed, aborting");
return -1;
}
memset(&info, 0, sizeof(info));
RIL_CLIENT_LOCK(client);
if (ipc_client_recv(ipc_client, &info) < 0) {
RIL_CLIENT_UNLOCK(client);
LOGE("IPC RFS recv failed, aborting");
return -1;
}
RIL_CLIENT_UNLOCK(client);
ipc_rfs_dispatch(&info);
ipc_client_response_free(ipc_client, &info);
}
return 0;
}
int ipc_rfs_create(struct ril_client *client)
{
struct ipc_client *ipc_client;
int rc;
if (client == NULL)
return -EINVAL;
LOGD("Creating new RFS client");
ipc_client = ipc_client_create(IPC_CLIENT_TYPE_RFS);
if (ipc_client == NULL) {
LOGE("RFS client creation failed");
goto error_client_create;
}
client->data = (void *) ipc_client;
LOGD("Setting log handler");
rc = ipc_client_set_log_callback(ipc_client, ipc_log_handler, NULL);
if (rc < 0) {
LOGE("Setting log handler failed");
goto error_log_callback;
}
LOGD("Creating data");
rc = ipc_client_data_create(ipc_client);
if (rc < 0) {
LOGE("Creating data failed");
goto error_data_create;
}
LOGD("Client open...");
rc = ipc_client_open(ipc_client);
if (rc < 0) {
LOGE("%s: failed to open ipc client", __func__);
goto error_open;
}
LOGD("IPC RFS client done");
return 0;
error:
error_get_fd:
ipc_client_close(ipc_client);
error_open:
ipc_client_data_destroy(ipc_client);
error_data_create:
error_log_callback:
ipc_client_destroy(ipc_client);
error_client_create:
client->data = NULL;
return -1;
}
int ipc_rfs_destroy(struct ril_client *client)
{
struct ipc_client *ipc_client;
int rc;
if (client == NULL || client->data == NULL) {
LOGE("Client was already destroyed");
return 0;
}
ipc_client = (struct ipc_client *) client->data;
LOGD("Destroying ipc rfs client");
if (ipc_client != NULL) {
ipc_client_close(ipc_client);
ipc_client_data_destroy(ipc_client);
ipc_client_destroy(ipc_client);
}
client->data = NULL;
return 0;
}
/*
* IPC clients structures
*/
struct ril_client_funcs ipc_fmt_client_funcs = {
.create = ipc_fmt_create,
.destroy = ipc_fmt_destroy,
.read_loop = ipc_fmt_read_loop,
};
struct ril_client_funcs ipc_rfs_client_funcs = {
.create = ipc_rfs_create,
.destroy = ipc_rfs_destroy,
.read_loop = ipc_rfs_read_loop,
};
|