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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
/**
* This file is part of samsung-ril.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
* Copyright (C) 2011 Paul Kocialkowski <contact@oaulk.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/>.
*
*/
#include <time.h>
#include <pthread.h>
#define LOG_TAG "RIL"
#include <utils/Log.h>
#include <telephony/ril.h>
#include "samsung-ril.h"
#include "util.h"
#define RIL_VERSION_STRING "Samsung RIL"
/**
* Samsung-RIL TODO:
*
* General:
* - SIM SMS I/O
* - Review code with requests that produce GEN_PHONE_RES messages to use the GEN_PHONE_RES engine
*
* Data-related:
* - find a reliable way to configure data iface
* - GPRS: IPC_GPRS_CALL_STATUS, LAST_DATA_CALL_FAIL_CAUSE
* - check data with orange non-free ril: no gprs_ip_config
* - data: use IPC_GPRS_CALL_STATUS with global token for possible fail or return anyway and store ip config global?
* - update global fail cause in global after gprs_call_status, generic error on stored token
*/
/**
* RIL global vars
*/
struct ril_client *ipc_fmt_client;
struct ril_client *ipc_rfs_client;
struct ril_client *srs_client;
const struct RIL_Env *ril_env;
struct ril_state ril_state;
/**
* RIL request token
*/
struct ril_request_token ril_requests_tokens[0x100];
int ril_request_id = 0;
void ril_requests_tokens_init(void)
{
memset(ril_requests_tokens, 0, sizeof(struct ril_request_token) * 0x100);
}
int ril_request_id_new(void)
{
ril_request_id++;
ril_request_id %= 0x100;
return ril_request_id;
}
int ril_request_reg_id(RIL_Token token)
{
int id = ril_request_id_new();
ril_requests_tokens[id].token = token;
ril_requests_tokens[id].canceled = 0;
return id;
}
int ril_request_get_id(RIL_Token token)
{
int i;
for(i=0 ; i < 0x100 ; i++)
if(ril_requests_tokens[i].token == token)
return i;
// If the token isn't registered yet, register it
return ril_request_reg_id(token);
}
RIL_Token ril_request_get_token(int id)
{
return ril_requests_tokens[id].token;
}
int ril_request_get_canceled(RIL_Token token)
{
int id;
id = ril_request_get_id(token);
if(ril_requests_tokens[id].canceled > 0)
return 1;
else
return 0;
}
void ril_request_set_canceled(RIL_Token token, int canceled)
{
int id;
id = ril_request_get_id(token);
ril_requests_tokens[id].canceled = canceled;
}
void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen)
{
if(!ril_request_get_canceled(t))
RIL_onRequestCompleteReal(t, e, response, responselen);
else
RIL_onRequestCompleteReal(t, RIL_E_CANCELLED, response, responselen);
}
/**
* RIL tokens
*/
void ril_tokens_check(void)
{
RIL_Token t;
if(ril_state.tokens.baseband_version != 0) {
if(ril_state.radio_state != RADIO_STATE_OFF) {
t = ril_state.tokens.baseband_version;
ril_state.tokens.baseband_version = 0;
ril_request_baseband_version(t);
}
}
if(ril_state.tokens.get_imei != 0 && ril_state.tokens.get_imeisv != 0) {
if(ril_state.radio_state != RADIO_STATE_OFF) {
t = ril_state.tokens.get_imei;
ril_state.tokens.get_imei = 0;
ril_request_get_imei(t);
}
}
}
/**
* Clients dispatch functions
*/
void ipc_fmt_dispatch(struct ipc_message_info *info)
{
switch(IPC_COMMAND(info)) {
/* GEN */
case IPC_GEN_PHONE_RES:
ipc_gen_phone_res(info);
break;
/* PWR */
case IPC_PWR_PHONE_PWR_UP:
ipc_pwr_phone_pwr_up();
break;
case IPC_PWR_PHONE_STATE:
ipc_pwr_phone_state(info);
break;
/* DISP */
case IPC_DISP_ICON_INFO:
ipc_disp_icon_info(info);
break;
case IPC_DISP_RSSI_INFO:
ipc_disp_rssi_info(info);
break;
/* MISC */
case IPC_MISC_ME_SN:
ipc_misc_me_sn(info);
break;
case IPC_MISC_ME_VERSION:
ipc_misc_me_version(info);
break;
case IPC_MISC_ME_IMSI:
ipc_misc_me_imsi(info);
break;
case IPC_MISC_TIME_INFO:
ipc_misc_time_info(info);
break;
/* SAT */
case IPC_SAT_PROACTIVE_CMD:
respondSatProactiveCmd(info);
break;
case IPC_SAT_ENVELOPE_CMD:
respondSatEnvelopeCmd(info);
break;
/* SS */
case IPC_SS_USSD:
ipc_ss_ussd(info);
break;
/* SEC */
case IPC_SEC_PIN_STATUS:
ipc_sec_pin_status(info);
break;
case IPC_SEC_LOCK_INFO:
ipc_sec_lock_info(info);
break;
case IPC_SEC_RSIM_ACCESS:
ipc_sec_rsim_access(info);
break;
case IPC_SEC_PHONE_LOCK:
ipc_sec_phone_lock(info);
break;
/* NET */
case IPC_NET_CURRENT_PLMN:
ipc_net_current_plmn(info);
break;
case IPC_NET_REGIST:
ipc_net_regist(info);
break;
case IPC_NET_PLMN_LIST:
ipc_net_plmn_list(info);
break;
case IPC_NET_PLMN_SEL:
ipc_net_plmn_sel(info);
break;
case IPC_NET_MODE_SEL:
ipc_net_mode_sel(info);
break;
/* SMS */
case IPC_SMS_INCOMING_MSG:
ipc_sms_incoming_msg(info);
break;
case IPC_SMS_DELIVER_REPORT:
ipc_sms_deliver_report(info);
break;
case IPC_SMS_SVC_CENTER_ADDR:
ipc_sms_svc_center_addr(info);
break;
case IPC_SMS_SEND_MSG:
ipc_sms_send_msg(info);
break;
case IPC_SMS_DEVICE_READY:
ipc_sms_device_ready(info);
break;
/* CALL */
case IPC_CALL_INCOMING:
ipc_call_incoming(info);
break;
case IPC_CALL_LIST:
ipc_call_list(info);
break;
case IPC_CALL_STATUS:
ipc_call_status(info);
break;
case IPC_CALL_BURST_DTMF:
ipc_call_burst_dtmf(info);
break;
/* GPRS */
case IPC_GPRS_IP_CONFIGURATION:
ipc_gprs_ip_configuration(info);
break;
default:
LOGD("Unhandled command: %s (%04x)", ipc_command_to_str(IPC_COMMAND(info)), IPC_COMMAND(info));
break;
}
}
void ipc_rfs_dispatch(struct ipc_message_info *info)
{
switch(IPC_COMMAND(info)) {
case IPC_RFS_NV_READ_ITEM:
ipc_rfs_nv_read_item(info);
break;
case IPC_RFS_NV_WRITE_ITEM:
ipc_rfs_nv_write_item(info);
break;
default:
LOGD("Unhandled command: %s (%04x)", ipc_command_to_str(IPC_COMMAND(info)), IPC_COMMAND(info));
break;
}
}
void srs_dispatch(struct srs_message *message)
{
switch(message->command) {
case SRS_CONTROL_PING:
srs_control_ping(message);
break;
case SRS_SND_SET_CALL_CLOCK_SYNC:
srs_snd_set_call_clock_sync(message);
break;
case SRS_SND_SET_CALL_VOLUME:
srs_snd_set_call_volume(message);
break;
case SRS_SND_SET_CALL_AUDIO_PATH:
srs_snd_set_call_audio_path(message);
break;
default:
LOGD("Unhandled command: (%04x)", message->command);
break;
}
}
/*
* RIL main dispatch function
*/
int ril_modem_check(void)
{
if(ipc_fmt_client == NULL)
return -1;
if(ipc_fmt_client->state != RIL_CLIENT_READY)
return -1;
return 0;
}
void onRequest(int request, void *data, size_t datalen, RIL_Token t)
{
if(ril_modem_check() < 0)
RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
switch(request) {
/* PWR */
case RIL_REQUEST_RADIO_POWER:
ril_request_radio_power(t, data, datalen);
break;
case RIL_REQUEST_BASEBAND_VERSION:
ril_request_baseband_version(t);
break;
/* DISP */
case RIL_REQUEST_SIGNAL_STRENGTH:
ril_request_signal_strength(t);
break;
/* MISC */
case RIL_REQUEST_GET_IMEI:
ril_request_get_imei(t);
break;
case RIL_REQUEST_GET_IMEISV:
ril_request_get_imeisv(t);
break;
case RIL_REQUEST_GET_IMSI:
ril_request_get_imsi(t);
break;
/* SAT */
case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE:
requestSatSendTerminalResponse(t, data, datalen);
break;
case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND:
requestSatSendEnvelopeCommand(t, data, datalen);
break;
case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM:
RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
break;
/* SS */
case RIL_REQUEST_SEND_USSD:
ril_request_send_ussd(t, data, datalen);
break;
case RIL_REQUEST_CANCEL_USSD:
ril_request_cancel_ussd(t, data, datalen);
/* SEC */
case RIL_REQUEST_GET_SIM_STATUS:
ril_request_get_sim_status(t);
break;
case RIL_REQUEST_SIM_IO:
ril_request_sim_io(t, data, datalen);
break;
case RIL_REQUEST_ENTER_SIM_PIN:
ril_request_enter_sim_pin(t, data, datalen);
break;
case RIL_REQUEST_CHANGE_SIM_PIN:
ril_request_change_sim_pin(t, data, datalen);
break;
case RIL_REQUEST_ENTER_SIM_PUK:
ril_request_enter_sim_puk(t, data, datalen);
break;
case RIL_REQUEST_QUERY_FACILITY_LOCK:
ril_request_query_facility_lock(t, data, datalen);
break;
case RIL_REQUEST_SET_FACILITY_LOCK:
ril_request_set_facility_lock(t, data, datalen);
break;
/* NET */
case RIL_REQUEST_OPERATOR:
ril_request_operator(t);
break;
case RIL_REQUEST_REGISTRATION_STATE:
ril_request_registration_state(t);
break;
case RIL_REQUEST_GPRS_REGISTRATION_STATE:
ril_request_gprs_registration_state(t);
break;
case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS:
ril_request_query_available_networks(t);
break;
case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
ril_request_get_preferred_network_type(t);
break;
case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE:
ril_request_set_preferred_network_type(t, data, datalen);
break;
case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE:
ril_request_query_network_selection_mode(t);
break;
case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC:
ril_request_set_network_selection_automatic(t);
break;
case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL:
ril_request_set_network_selection_manual(t, data, datalen);
break;
/* SMS */
case RIL_REQUEST_SEND_SMS:
ril_request_send_sms(t, data, datalen);
break;
case RIL_REQUEST_SEND_SMS_EXPECT_MORE:
ril_request_send_sms_expect_more(t, data, datalen);
break;
case RIL_REQUEST_SMS_ACKNOWLEDGE:
ril_request_sms_acknowledge(t, data, datalen);
break;
/* CALL */
case RIL_REQUEST_DIAL:
ril_request_dial(t, data, datalen);
break;
case RIL_REQUEST_GET_CURRENT_CALLS:
ril_request_get_current_calls(t);
break;
case RIL_REQUEST_HANGUP:
case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND:
case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND:
ril_request_hangup(t);
break;
case RIL_REQUEST_ANSWER:
ril_request_answer(t);
break;
case RIL_REQUEST_DTMF:
ril_request_dtmf(t, data, datalen);
break;
case RIL_REQUEST_DTMF_START:
ril_request_dtmf_start(t, data, datalen);
break;
case RIL_REQUEST_DTMF_STOP:
ril_request_dtmf_stop(t);
break;
/* GPRS */
case RIL_REQUEST_SETUP_DATA_CALL:
ril_request_setup_data_call(t, data, datalen);
break;
case RIL_REQUEST_DEACTIVATE_DATA_CALL:
ril_request_deactivate_data_call(t, data, datalen);
break;
/* SND */
case RIL_REQUEST_SET_MUTE:
ril_request_set_mute(t, data, datalen);
/* OTHER */
case RIL_REQUEST_SCREEN_STATE:
/* This doesn't affect anything */
RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
break;
default:
LOGE("Request not implemented: %d\n", request);
RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
break;
}
}
/**
* RILJ related functions
*/
RIL_RadioState currentState()
{
LOGD("currentState()");
return ril_state.radio_state;
}
int onSupports(int requestCode)
{
switch(requestCode) {
default:
return 1;
}
}
void onCancel(RIL_Token t)
{
ril_request_set_canceled(t, 1);
}
const char *getVersion(void)
{
return RIL_VERSION_STRING;
}
/**
* RIL init function
*/
void ril_globals_init(void)
{
memset(&ril_state, 0, sizeof(ril_state));
memset(&(ril_state.tokens), 0, sizeof(struct ril_tokens));
ril_requests_tokens_init();
ipc_gen_phone_res_expects_init();
ril_request_sms_init();
ipc_sms_tpid_queue_init();
}
void ril_state_lpm(void)
{
ril_state.radio_state = RADIO_STATE_OFF;
ril_state.power_mode = POWER_MODE_LPM;
}
static const RIL_RadioFunctions ril_ops = {
6, //RIL_VERSION
onRequest,
currentState,
onSupports,
onCancel,
getVersion
};
const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv)
{
int rc;
ril_env = env;
ril_globals_init();
ril_state_lpm();
ipc_fmt:
LOGD("Creating IPC FMT client");
ipc_fmt_client = ril_client_new(&ipc_fmt_client_funcs);
rc = ril_client_create(ipc_fmt_client);
if(rc < 0) {
LOGE("IPC FMT client creation failed.");
goto ipc_rfs;
}
rc = ril_client_thread_start(ipc_fmt_client);
if(rc < 0) {
LOGE("IPC FMT thread creation failed.");
goto ipc_rfs;
}
LOGD("IPC FMT client ready");
ipc_rfs:
LOGD("Creating IPC RFS client");
ipc_rfs_client = ril_client_new(&ipc_rfs_client_funcs);
rc = ril_client_create(ipc_rfs_client);
if(rc < 0) {
LOGE("IPC RFS client creation failed.");
goto srs;
}
rc = ril_client_thread_start(ipc_rfs_client);
if(rc < 0) {
LOGE("IPC RFS thread creation failed.");
goto srs;
}
LOGD("IPC RFS client ready");
srs:
LOGD("Creating SRS client");
srs_client = ril_client_new(&srs_client_funcs);
rc = ril_client_create(srs_client);
if(rc < 0) {
LOGE("SRS client creation failed.");
goto end;
}
rc = ril_client_thread_start(srs_client);
if(rc < 0) {
LOGE("SRS thread creation failed.");
goto end;
}
LOGD("SRS client ready");
end:
return &ril_ops;
}
int main(int argc, char *argv[])
{
return 0;
}
|