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
|
/**
* This file is part of samsung-ril.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
* Copyright (C) 2011-2012 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-CALL"
#include <utils/Log.h>
#include "samsung-ril.h"
/**
* Format conversion utils
*/
unsigned char ipc2ril_call_list_entry_state(unsigned char call_state)
{
switch(call_state) {
case IPC_CALL_LIST_ENTRY_STATE_ACTIVE:
return RIL_CALL_ACTIVE;
case IPC_CALL_LIST_ENTRY_STATE_HOLDING:
return RIL_CALL_HOLDING;
case IPC_CALL_LIST_ENTRY_STATE_DIALING:
return RIL_CALL_DIALING;
case IPC_CALL_LIST_ENTRY_STATE_ALERTING:
return RIL_CALL_ALERTING;
case IPC_CALL_LIST_ENTRY_STATE_INCOMING:
return RIL_CALL_INCOMING;
case IPC_CALL_LIST_ENTRY_STATE_WAITING:
return RIL_CALL_WAITING;
default:
LOGE("Unknown IPC_CALL_LIST_ENTRY_STATE!");
return -1;
}
}
RIL_LastCallFailCause ipc2ril_call_fail_cause(unsigned char end_cause)
{
switch(end_cause) {
case IPC_CALL_END_CAUSE_NORMAL:
case IPC_CALL_END_CAUSE_REJECTED:
return CALL_FAIL_NORMAL;
case IPC_CALL_END_CAUSE_UNSPECIFIED:
default:
return CALL_FAIL_ERROR_UNSPECIFIED;
}
}
/**
* In: RIL_UNSOL_CALL_RING
* Ring indication for an incoming call (eg, RING or CRING event).
*/
void ipc_call_incoming(struct ipc_message_info *info)
{
ril_request_unsolicited(RIL_UNSOL_CALL_RING, NULL, 0);
/* FIXME: Do we really need to send this? */
ril_request_unsolicited(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, NULL, 0);
}
/**
* In: IPC_CALL_STATUS
* Indicates that a call's status has changed
*
* RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
* Indicate when call state has changed
*/
void ipc_call_status(struct ipc_message_info *info)
{
struct ipc_call_status *call_status =
(struct ipc_call_status *) info->data;
memcpy(&(ril_data.state.call_status), call_status, sizeof(struct ipc_call_status));
LOGD("Updating Call Status data");
ril_request_unsolicited(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, NULL, 0);
}
/**
* In: RIL_REQUEST_DIAL
* Initiate voice call
*
* Out: IPC_CALL_OUTGOING
*/
void ril_request_dial(RIL_Token t, void *data, size_t datalen)
{
const RIL_Dial *dial = (const RIL_Dial*)data;
struct ipc_call_outgoing call;
int clir;
if (strlen(dial->address) > sizeof(call.number)) {
printf("Outgoing call number too long\n");
return;
}
/* FIXME: separate method? */
switch(dial->clir) {
case 0:
clir = IPC_CALL_IDENTITY_DEFAULT;
break;
case 1:
clir = IPC_CALL_IDENTITY_SHOW;
break;
case 2:
clir = IPC_CALL_IDENTITY_HIDE;
break;
default:
clir = IPC_CALL_IDENTITY_DEFAULT;
break;
}
memset(&call, 0x00, sizeof(call));
call.type = IPC_CALL_TYPE_VOICE;
call.identity = clir;
call.prefix = dial->address[0] == '+' ? IPC_CALL_PREFIX_INTL : IPC_CALL_PREFIX_NONE;
call.length = strlen(dial->address);
memcpy(call.number, dial->address, strlen(dial->address));
ipc_fmt_send(IPC_CALL_OUTGOING, IPC_TYPE_EXEC, (unsigned char *) &call, sizeof(call), ril_request_get_id(t));
/* FIXME: This should actually be sent based on the response from baseband */
ril_request_complete(t, RIL_E_SUCCESS, NULL, 0);
}
/**
* In: RIL_REQUEST_GET_CURRENT_CALLS
* Requests current call list
*
* Out: IPC_CALL_LIST GET
* Requests a list of active calls
*/
void ril_request_get_current_calls(RIL_Token t)
{
ipc_fmt_send_get(IPC_CALL_LIST, ril_request_get_id(t));
}
/**
* In: IPC_CALL_LIST GET
* Provides a list of active calls
*
* Out: RIL_REQUEST_GET_CURRENT_CALLS
* Requests current call list
*/
void ipc_call_list(struct ipc_message_info *info)
{
struct ipc_call_list_entry *entry;
unsigned char num_entries;
char *number, *number_ril;
int i;
num_entries = *((unsigned char *) info->data);
if (num_entries == 0) {
// Don't bother with mem alloc
ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, NULL, 0);
return;
}
entry = (struct ipc_call_list_entry *) ((char *) info->data + 1);
RIL_Call **calls = (RIL_Call **) malloc(num_entries * sizeof(RIL_Call *));
for (i = 0; i < num_entries; i++) {
RIL_Call *call = (RIL_Call *) malloc(sizeof(RIL_Call));
/* Number is located after call list entry */
number = ((char *) entry) + sizeof(*entry);
number_ril = (char *) malloc(entry->number_len + 1);
memset(number_ril, 0, (entry->number_len + 1));
memcpy(number_ril, number, entry->number_len);
call->state = ipc2ril_call_list_entry_state(entry->state);
call->index = (entry->idx+1);
call->toa = (entry->number_len > 0 && number[0] == '+') ? 145 : 129;
call->isMpty = entry->mpty;
call->isMT = (entry->term == IPC_CALL_TERM_MT);
call->als = 0;
call->isVoice = (entry->type == IPC_CALL_TYPE_VOICE);
call->isVoicePrivacy = 0;
call->number = number_ril;
call->numberPresentation = (entry->number_len > 0) ? 0 : 2;
call->name = NULL;
call->namePresentation = 2;
call->uusInfo = NULL;
calls[i] = call;
/* Next entry after current number */
entry = (struct ipc_call_list_entry *) (number + entry->number_len);
}
ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, calls, (num_entries * sizeof(RIL_Call *)));
for (i = 0; i < num_entries; i++) {
free(calls[i]);
}
free(calls);
}
/**
* In: RIL_REQUEST_HANGUP
* Hang up a specific line (like AT+CHLD=1x)
*
* Out: IPC_CALL_RELEASE EXEC
*/
void ril_request_hangup(RIL_Token t)
{
ipc_fmt_send_exec(IPC_CALL_RELEASE, ril_request_get_id(t));
/* FIXME: This should actually be sent based on the response from baseband */
ril_request_complete(t, RIL_E_SUCCESS, NULL, 0);
/* FIXME: Do we really need to send this? */
ril_request_unsolicited(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, NULL, 0);
}
/**
* In: RIL_REQUEST_ANSWER
* Answer incoming call
*
* Out: IPC_CALL_ANSWER
*/
void ril_request_answer(RIL_Token t)
{
ipc_fmt_send_exec(IPC_CALL_ANSWER, ril_request_get_id(t));
/* FIXME: This should actually be sent based on the response from baseband */
ril_request_complete(t, RIL_E_SUCCESS, NULL, 0);
/* FIXME: Do we really need to send this? */
ril_request_unsolicited(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, NULL, 0);
}
/**
* In: RIL_REQUEST_LAST_CALL_FAIL_CAUSE
* Reason why last call was terminated
*/
void ril_request_last_call_fail_cause(RIL_Token t)
{
RIL_LastCallFailCause fail_cause;
struct ipc_call_status *call_status =
&(ril_data.state.call_status);
fail_cause = ipc2ril_call_fail_cause(call_status->end_cause);
// Empty global call_status
memset(call_status, 0, sizeof(struct ipc_call_status));
ril_request_complete(t, RIL_E_SUCCESS, &fail_cause, sizeof(RIL_LastCallFailCause));
}
/**
* In: IPC_CALL_BURST_DTMF
* Send DTMF burst. RILJ only sends 1 DTMF tone to send at a time.
*
* Out: IPC_CALL_BURST_DTMF
* It should be possible to send multiple DTMF tones at once in this message.
* First byte should be DTMF tones count.
*/
void ril_request_dtmf(RIL_Token t, void *data, int length)
{
struct ipc_call_cont_dtmf cont_dtmf;
unsigned char *burst;
int burst_len;
unsigned char dtmf_count = 1;
int i;
if (ril_data.state.dtmf_tone != 0) {
LOGD("Another tone wasn't stopped, stopping that one before anything");
cont_dtmf.state = IPC_CALL_DTMF_STATE_STOP;
cont_dtmf.tone = 0;
ipc_fmt_send(IPC_CALL_CONT_DTMF, IPC_TYPE_SET, (void *) &cont_dtmf, sizeof(cont_dtmf), ril_request_get_id(t));
usleep(300);
}
burst_len = sizeof(struct ipc_call_cont_dtmf) * dtmf_count + 1;
burst = malloc(burst_len);
memset(burst, 0, burst_len);
burst[0] = dtmf_count;
for (i=0 ; i < dtmf_count ; i++) {
// Apparently, it's possible to set multiple DTMF tones on this message
cont_dtmf.state = IPC_CALL_DTMF_STATE_START;
cont_dtmf.tone = ((char *) data)[0];
memcpy(burst + 1 + sizeof(struct ipc_call_cont_dtmf) * i, &cont_dtmf, sizeof(cont_dtmf));
}
ipc_gen_phone_res_expect_to_abort(ril_request_get_id(t), IPC_CALL_BURST_DTMF);
ipc_fmt_send(IPC_CALL_BURST_DTMF, IPC_TYPE_EXEC, (void *) burst, burst_len, ril_request_get_id(t));
free(burst);
}
void ipc_call_burst_dtmf(struct ipc_message_info *info)
{
unsigned char ret = *((unsigned char *) info->data);
// This apparently should return 1, or perhaps that is the DTMF tones count
if (ret == 0) {
LOGD("Apparently, something went wrong with DTMF burst");
ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
}
ril_request_complete(ril_request_get_token(info->aseq), RIL_E_SUCCESS, NULL, 0);
}
void ril_request_dtmf_start(RIL_Token t, void *data, int length)
{
struct ipc_call_cont_dtmf cont_dtmf;
if (ril_data.state.dtmf_tone != 0) {
LOGD("Another tone wasn't stopped, stopping that one before anything");
cont_dtmf.state = IPC_CALL_DTMF_STATE_STOP;
cont_dtmf.tone = 0;
ipc_fmt_send(IPC_CALL_CONT_DTMF, IPC_TYPE_SET, (void *) &cont_dtmf, sizeof(cont_dtmf), ril_request_get_id(t));
usleep(300);
}
cont_dtmf.state = IPC_CALL_DTMF_STATE_START;
cont_dtmf.tone = ((unsigned char *)data)[0];
ril_data.state.dtmf_tone = cont_dtmf.tone;
ipc_gen_phone_res_expect_to_complete(ril_request_get_id(t), IPC_CALL_CONT_DTMF);
ipc_fmt_send(IPC_CALL_CONT_DTMF, IPC_TYPE_SET, (void *) &cont_dtmf, sizeof(cont_dtmf), ril_request_get_id(t));
}
void ril_request_dtmf_stop(RIL_Token t)
{
struct ipc_call_cont_dtmf cont_dtmf;
cont_dtmf.state = IPC_CALL_DTMF_STATE_STOP;
cont_dtmf.tone = 0;
ril_data.state.dtmf_tone = 0;
ipc_gen_phone_res_expect_to_complete(ril_request_get_id(t), IPC_CALL_CONT_DTMF);
ipc_fmt_send(IPC_CALL_CONT_DTMF, IPC_TYPE_SET, (void *) &cont_dtmf, sizeof(cont_dtmf), ril_request_get_id(t));
}
|