Define and use RIL_TOKEN_NULL
[samsung-ril.git] / sms.c
1 /*
2  * This file is part of Samsung-RIL.
3  *
4  * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
5  * Copyright (C) 2011-2012 Paul Kocialkowski <contact@paulk.fr>
6  *
7  * Samsung-RIL is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Samsung-RIL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Samsung-RIL.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #define LOG_TAG "RIL-SMS"
23 #include <utils/Log.h>
24
25 #include "samsung-ril.h"
26 #include "util.h"
27
28 unsigned short ril2ipc_sms_ack_error(int success, int failcause)
29 {
30         if (success) {
31                 return IPC_SMS_ACK_NO_ERROR;
32         } else {
33                 switch(failcause) {
34                         case 0xD3:
35                                 return IPC_SMS_ACK_PDA_FULL_ERROR;
36                         default:
37                                 return IPC_SMS_ACK_UNSPEC_ERROR;
38                 }
39         }
40 }
41
42 RIL_Errno ipc2ril_sms_ack_error(unsigned short error, int *error_code)
43 {
44         // error_code is defined in See 3GPP 27.005, 3.2.5 for GSM/UMTS
45
46         if (error_code == NULL)
47                 return RIL_E_GENERIC_FAILURE;
48
49         switch(error) {
50                 case IPC_SMS_ACK_NO_ERROR:
51                         *error_code = -1;
52                         return RIL_E_SUCCESS;
53                 default:
54                         // unknown error
55                         *error_code = 500;
56                         return RIL_E_GENERIC_FAILURE;
57         }
58 }
59
60 /*
61  * Outgoing SMS functions
62  */
63
64 int ril_request_send_sms_register(char *pdu, int pdu_length, unsigned char *smsc, int smsc_length, RIL_Token t)
65 {
66         struct ril_request_send_sms_info *send_sms;
67         struct list_head *list_end;
68         struct list_head *list;
69
70         send_sms = calloc(1, sizeof(struct ril_request_send_sms_info));
71         if (send_sms == NULL)
72                 return -1;
73
74         send_sms->pdu = pdu;
75         send_sms->pdu_length = pdu_length;
76         send_sms->smsc = smsc;
77         send_sms->smsc_length = smsc_length;
78         send_sms->token = t;
79
80         list_end = ril_data.outgoing_sms;
81         while (list_end != NULL && list_end->next != NULL)
82                 list_end = list_end->next;
83
84         list = list_head_alloc((void *) send_sms, list_end, NULL);
85
86         if (ril_data.outgoing_sms == NULL)
87                 ril_data.outgoing_sms = list;
88
89         return 0;
90 }
91
92 void ril_request_send_sms_unregister(struct ril_request_send_sms_info *send_sms)
93 {
94         struct list_head *list;
95
96         if (send_sms == NULL)
97                 return;
98
99         list = ril_data.outgoing_sms;
100         while (list != NULL) {
101                 if (list->data == (void *) send_sms) {
102                         memset(send_sms, 0, sizeof(struct ril_request_send_sms_info));
103                         free(send_sms);
104
105                         if (list == ril_data.outgoing_sms)
106                                 ril_data.outgoing_sms = list->next;
107
108                         list_head_free(list);
109
110                         break;
111                 }
112 list_continue:
113                 list = list->next;
114         }
115 }
116
117 struct ril_request_send_sms_info *ril_request_send_sms_info_find(void)
118 {
119         struct ril_request_send_sms_info *send_sms;
120         struct list_head *list;
121
122         list = ril_data.outgoing_sms;
123         while (list != NULL) {
124                 send_sms = (struct ril_request_send_sms_info *) list->data;
125                 if (send_sms == NULL)
126                         goto list_continue;
127
128                 return send_sms;
129
130 list_continue:
131                 list = list->next;
132         }
133
134         return NULL;
135 }
136
137 struct ril_request_send_sms_info *ril_request_send_sms_info_find_token(RIL_Token t)
138 {
139         struct ril_request_send_sms_info *send_sms;
140         struct list_head *list;
141
142         list = ril_data.outgoing_sms;
143         while (list != NULL) {
144                 send_sms = (struct ril_request_send_sms_info *) list->data;
145                 if (send_sms == NULL)
146                         goto list_continue;
147
148                 if (send_sms->token == t)
149                         return send_sms;
150
151 list_continue:
152                 list = list->next;
153         }
154
155         return NULL;
156 }
157
158 void ril_request_send_sms_info_clear(struct ril_request_send_sms_info *send_sms)
159 {
160         if (send_sms == NULL)
161                 return;
162
163         if (send_sms->pdu != NULL)
164                 free(send_sms->pdu);
165
166         if (send_sms->smsc != NULL)
167                 free(send_sms->smsc);
168 }
169
170 void ril_request_send_sms_next(void)
171 {
172         struct ril_request_send_sms_info *send_sms;
173         RIL_Token t;
174         char *pdu;
175         int pdu_length;
176         unsigned char *smsc;
177         int smsc_length;
178         int rc;
179
180         ril_data.tokens.outgoing_sms = RIL_TOKEN_NULL;
181
182         send_sms = ril_request_send_sms_info_find();
183         if (send_sms == NULL)
184                 return;
185
186         t = send_sms->token;
187         pdu = send_sms->pdu;
188         pdu_length = send_sms->pdu_length;
189         smsc = send_sms->smsc;
190         smsc_length = send_sms->smsc_length;
191
192         ril_request_send_sms_unregister(send_sms);
193
194         if (pdu == NULL) {
195                 LOGE("SMS send request has no valid PDU");
196                 if (smsc != NULL)
197                         free(smsc);
198                 return;
199         }
200
201         ril_data.tokens.outgoing_sms = t;
202         if (smsc == NULL) {
203                 // We first need to get SMS SVC before sending the message
204                 LOGD("We have no SMSC, let's ask one");
205
206                 rc = ril_request_send_sms_register(pdu, pdu_length, NULL, 0, t);
207                 if (rc < 0) {
208                         LOGE("Unable to add the request to the list");
209
210                         ril_request_complete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
211                         if (pdu != NULL)
212                                 free(pdu);
213                         // Send the next SMS in the list
214                         ril_request_send_sms_next();
215                 }
216
217                 ipc_fmt_send_get(IPC_SMS_SVC_CENTER_ADDR, ril_request_get_id(t));
218         } else {
219                 ril_request_send_sms_complete(t, pdu, pdu_length, smsc, smsc_length);
220                 if (pdu != NULL)
221                         free(pdu);
222                 if (smsc != NULL)
223                         free(smsc);
224         }
225 }
226
227 void ril_request_send_sms_complete(RIL_Token t, char *pdu, int pdu_length, unsigned char *smsc, int smsc_length)
228 {
229         struct ipc_sms_send_msg_request send_msg;
230         unsigned char send_msg_type;
231
232         unsigned char *pdu_hex;
233         int pdu_hex_length;
234
235         void *data;
236         int length;
237
238         unsigned char *p;
239
240         if (pdu == NULL || pdu_length <= 0 || smsc == NULL || smsc_length <= 0)
241                 goto error;
242
243         if ((pdu_length / 2 + smsc_length) > 0xfe) {
244                 LOGE("PDU or SMSC too large, aborting");
245                 goto error;
246         }
247
248         pdu_hex_length = pdu_length % 2 == 0 ? pdu_length / 2 :
249                 (pdu_length ^ 1) / 2;
250
251         // Length of the final message
252         length = sizeof(send_msg) + pdu_hex_length + smsc_length;
253
254         LOGD("Sending SMS message (length: 0x%x)!", length);
255
256         pdu_hex = calloc(1, pdu_hex_length);
257         hex2bin(pdu, pdu_length, pdu_hex);
258         send_msg_type = IPC_SMS_MSG_SINGLE;
259
260         /* PDU operations */
261         int pdu_tp_da_index = 2;
262         unsigned char pdu_tp_da_len = pdu_hex[pdu_tp_da_index];
263
264         if (pdu_tp_da_len > 0xff / 2) {
265                 LOGE("PDU TP-DA Len failed (0x%x)\n", pdu_tp_da_len);
266                 goto pdu_end;
267         }
268
269         LOGD("PDU TP-DA Len is 0x%x\n", pdu_tp_da_len);
270
271         int pdu_tp_udh_index = pdu_tp_da_index + pdu_tp_da_len;
272         unsigned char pdu_tp_udh_len = pdu_hex[pdu_tp_udh_index];
273
274         if (pdu_tp_udh_len > 0xff / 2 || pdu_tp_udh_len < 5) {
275                 LOGE("PDU TP-UDH Len failed (0x%x)\n", pdu_tp_udh_len);
276                 goto pdu_end;
277         }
278
279         LOGD("PDU TP-UDH Len is 0x%x\n", pdu_tp_udh_len);
280
281         int pdu_tp_udh_num_index = pdu_tp_udh_index + 4;
282         unsigned char pdu_tp_udh_num = pdu_hex[pdu_tp_udh_num_index];
283
284         if (pdu_tp_udh_num > 0xf) {
285                 LOGE("PDU TP-UDH Num failed (0x%x)\n", pdu_tp_udh_num);
286                 goto pdu_end;
287         }
288
289         int pdu_tp_udh_seq_index = pdu_tp_udh_index + 5;
290         unsigned char pdu_tp_udh_seq = pdu_hex[pdu_tp_udh_seq_index];
291
292         if (pdu_tp_udh_seq > 0xf || pdu_tp_udh_seq > pdu_tp_udh_num) {
293                 LOGE("PDU TP-UDH Seq failed (0x%x)\n", pdu_tp_udh_seq);
294                 goto pdu_end;
295         }
296
297         LOGD("We are sending message %d on %d\n", pdu_tp_udh_seq, pdu_tp_udh_num);
298
299         if (pdu_tp_udh_num > 1) {
300                 LOGD("We are sending a multi-part message!");
301                 send_msg_type = IPC_SMS_MSG_MULTIPLE;
302         }
303
304 pdu_end:
305         // Alloc memory for the final message
306         data = calloc(1, length);
307
308         // Clear and fill the IPC structure part of the message
309         memset(&send_msg, 0, sizeof(struct ipc_sms_send_msg_request));
310         send_msg.type = IPC_SMS_TYPE_OUTGOING;
311         send_msg.msg_type = send_msg_type;
312         send_msg.length = (unsigned char) (pdu_hex_length + smsc_length + 1);
313         send_msg.smsc_len = smsc_length;
314
315         // Copy the parts of the message
316         p = data;
317         memcpy(p, &send_msg, sizeof(send_msg));
318         p += sizeof(send_msg);
319         memcpy(p, smsc, smsc_length);
320         p += smsc_length;
321         memcpy(p, pdu_hex, pdu_hex_length);
322
323         ipc_gen_phone_res_expect_to_func(ril_request_get_id(t), IPC_SMS_SEND_MSG, ipc_sms_send_msg_complete);
324
325         ipc_fmt_send(IPC_SMS_SEND_MSG, IPC_TYPE_EXEC, data, length, ril_request_get_id(t));
326
327         free(pdu_hex);
328         free(data);
329
330         return;
331
332 error:
333         ril_request_complete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
334         // Send the next SMS in the list
335         ril_request_send_sms_next();
336 }
337
338 void ril_request_send_sms(RIL_Token t, void *data, size_t length)
339 {
340         char *pdu = NULL;
341         int pdu_length;
342         unsigned char *smsc = NULL;
343         int smsc_length;
344         int rc;
345
346         if (data == NULL || length < (int) (2 * sizeof(char *)))
347                 goto error;
348
349         pdu = ((char **) data)[1];
350         smsc = ((unsigned char **) data)[0];
351         pdu_length = 0;
352         smsc_length = 0;
353
354         if (pdu != NULL) {
355                 pdu_length = strlen(pdu) + 1;
356                 pdu = strdup(pdu);
357         }
358         if (smsc != NULL) {
359                 smsc_length = strlen((char *) smsc);
360                 smsc = (unsigned char *) strdup((char *) smsc);
361         }
362
363         if (ril_data.tokens.outgoing_sms != RIL_TOKEN_NULL) {
364                 LOGD("Another outgoing SMS is being processed, adding to the list");
365
366                 rc = ril_request_send_sms_register(pdu, pdu_length, smsc, smsc_length, t);
367                 if (rc < 0) {
368                         LOGE("Unable to add the request to the list");
369                         goto error;
370                 }
371
372                 return;
373         }
374
375         ril_data.tokens.outgoing_sms = t;
376         if (smsc == NULL) {
377                 // We first need to get SMS SVC before sending the message
378                 LOGD("We have no SMSC, let's ask one");
379
380                 rc = ril_request_send_sms_register(pdu, pdu_length, NULL, 0, t);
381                 if (rc < 0) {
382                         LOGE("Unable to add the request to the list");
383                         goto error;
384                 }
385
386                 ipc_fmt_send_get(IPC_SMS_SVC_CENTER_ADDR, ril_request_get_id(t));
387         } else {
388                 ril_request_send_sms_complete(t, pdu, pdu_length, smsc, smsc_length);
389                 if (pdu != NULL)
390                         free(pdu);
391                 if (smsc != NULL)
392                         free(smsc);
393         }
394
395         return;
396
397 error:
398         ril_request_complete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
399
400         if (pdu != NULL)
401                 free(pdu);
402         if (smsc != NULL)
403                 free(smsc);
404         // Send the next SMS in the list
405         ril_request_send_sms_next();
406 }
407
408 void ril_request_send_sms_expect_more(RIL_Token t, void *data, size_t length)
409 {
410         // No particular treatment here, we already have a queue
411         ril_request_send_sms(t, data, length);
412 }
413
414 void ipc_sms_svc_center_addr(struct ipc_message_info *info)
415 {
416         struct ril_request_send_sms_info *send_sms;
417         RIL_Token t;
418         char *pdu;
419         int pdu_length;
420         unsigned char *smsc;
421         int smsc_length;
422         int rc;
423
424         if (info == NULL || info->data == NULL || info->length < sizeof(unsigned char))
425                 goto error;
426
427         send_sms = ril_request_send_sms_info_find_token(ril_request_get_token(info->aseq));
428         if (send_sms == NULL || send_sms->pdu == NULL || send_sms->pdu_length <= 0) {
429                 LOGE("The request wasn't queued, reporting generic error!");
430
431                 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
432                 ril_request_send_sms_info_clear(send_sms);
433                 ril_request_send_sms_unregister(send_sms);
434                 // Send the next SMS in the list
435                 ril_request_send_sms_next();
436
437                 return;
438         }
439
440         t = send_sms->token;
441         pdu = send_sms->pdu;
442         pdu_length = send_sms->pdu_length;
443         smsc = (unsigned char *) info->data + sizeof(unsigned char);
444         smsc_length = (int) ((unsigned char *) info->data)[0];
445
446         LOGD("Got SMSC, completing the request");
447         ril_request_send_sms_unregister(send_sms);
448         ril_request_send_sms_complete(t, pdu, pdu_length, smsc, smsc_length);
449         if (pdu != NULL)
450                 free(pdu);
451
452         return;
453
454 error:
455         if (info != NULL)
456                 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
457 }
458
459 void ipc_sms_send_msg_complete(struct ipc_message_info *info)
460 {
461         struct ril_request_send_sms_info *send_sms;
462         struct ipc_gen_phone_res *phone_res;
463
464         phone_res = (struct ipc_gen_phone_res *) info->data;
465         if (ipc_gen_phone_res_check(phone_res) < 0) {
466                 LOGE("IPC_GEN_PHONE_RES indicates error, abort request to RILJ");
467
468                 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
469                 // Send the next SMS in the list
470                 ril_request_send_sms_next();
471         }
472 }
473
474 void ipc_sms_send_msg(struct ipc_message_info *info)
475 {
476         struct ipc_sms_send_msg_response *report_msg;
477         RIL_SMS_Response response;
478         RIL_Errno e;
479
480         if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_sms_send_msg_response))
481                 goto error;
482
483         report_msg = (struct ipc_sms_send_msg_response *) info->data;
484
485         LOGD("Got ACK for msg_tpid #%d\n", report_msg->msg_tpid);
486
487         memset(&response, 0, sizeof(response));
488         response.messageRef = report_msg->msg_tpid;
489         response.ackPDU = NULL;
490
491         e = ipc2ril_sms_ack_error(report_msg->error, &response.errorCode);
492
493         ril_request_complete(ril_request_get_token(info->aseq), e, (void *) &response, sizeof(response));
494
495         // Send the next SMS in the list
496         ril_request_send_sms_next();
497
498         return;
499
500 error:
501         if (info != NULL)
502                 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
503 }
504
505 /*
506  * Incoming SMS functions
507  */
508
509 int ipc_sms_incoming_msg_register(char *pdu, int length, unsigned char type, unsigned char tpid)
510 {
511         struct ipc_sms_incoming_msg_info *incoming_msg;
512         struct list_head *list_end;
513         struct list_head *list;
514
515         incoming_msg = calloc(1, sizeof(struct ipc_sms_incoming_msg_info));
516         if (incoming_msg == NULL)
517                 return -1;
518
519         incoming_msg->pdu = pdu;
520         incoming_msg->length = length;
521         incoming_msg->type = type;
522         incoming_msg->tpid = tpid;
523
524         list_end = ril_data.incoming_sms;
525         while (list_end != NULL && list_end->next != NULL)
526                 list_end = list_end->next;
527
528         list = list_head_alloc((void *) incoming_msg, list_end, NULL);
529
530         if (ril_data.incoming_sms == NULL)
531                 ril_data.incoming_sms = list;
532
533         return 0;
534 }
535
536 void ipc_sms_incoming_msg_unregister(struct ipc_sms_incoming_msg_info *incoming_msg)
537 {
538         struct list_head *list;
539
540         if (incoming_msg == NULL)
541                 return;
542
543         list = ril_data.incoming_sms;
544         while (list != NULL) {
545                 if (list->data == (void *) incoming_msg) {
546                         memset(incoming_msg, 0, sizeof(struct ipc_sms_incoming_msg_info));
547                         free(incoming_msg);
548
549                         if (list == ril_data.incoming_sms)
550                                 ril_data.incoming_sms = list->next;
551
552                         list_head_free(list);
553
554                         break;
555                 }
556 list_continue:
557                 list = list->next;
558         }
559 }
560
561 struct ipc_sms_incoming_msg_info *ipc_sms_incoming_msg_info_find(void)
562 {
563         struct ipc_sms_incoming_msg_info *incoming_msg;
564         struct list_head *list;
565
566         list = ril_data.incoming_sms;
567         while (list != NULL) {
568                 incoming_msg = (struct ipc_sms_incoming_msg_info *) list->data;
569                 if (incoming_msg == NULL)
570                         goto list_continue;
571
572                 return incoming_msg;
573
574 list_continue:
575                 list = list->next;
576         }
577
578         return NULL;
579 }
580
581 void ipc_sms_incoming_msg_next(void)
582 {
583         struct ipc_sms_incoming_msg_info *incoming_msg;
584
585         ril_data.state.sms_incoming_msg_tpid = 0;
586
587         incoming_msg = ipc_sms_incoming_msg_info_find();
588         if (incoming_msg == NULL)
589                 return;
590
591         ipc_sms_incoming_msg_complete(incoming_msg->pdu, incoming_msg->length, incoming_msg->type, incoming_msg->tpid);
592         ipc_sms_incoming_msg_unregister(incoming_msg);
593 }
594
595 void ipc_sms_incoming_msg_complete(char *pdu, int length, unsigned char type, unsigned char tpid)
596 {
597         if (pdu == NULL || length <= 0)
598                 return;
599
600         ril_data.state.sms_incoming_msg_tpid = tpid;
601
602         if (type == IPC_SMS_TYPE_POINT_TO_POINT) {
603                 ril_request_unsolicited(RIL_UNSOL_RESPONSE_NEW_SMS, pdu, length);
604         } else if (type == IPC_SMS_TYPE_STATUS_REPORT) {
605                 ril_request_unsolicited(RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT, pdu, length);
606         } else {
607                 LOGE("Unhandled message type: %x", type);
608         }
609
610         free(pdu);
611 }
612
613 void ipc_sms_incoming_msg(struct ipc_message_info *info)
614 {
615         struct ipc_sms_incoming_msg *msg;
616         unsigned char *pdu_hex;
617         char *pdu;
618         int length;
619         int rc;
620
621         if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_sms_incoming_msg))
622                 goto error;
623
624         msg = (struct ipc_sms_incoming_msg *) info->data;
625         pdu_hex = ((unsigned char *) info->data + sizeof(struct ipc_sms_incoming_msg));
626
627         length = msg->length * 2 + 1;
628         pdu = (char *) calloc(1, length);
629
630         bin2hex(pdu_hex, msg->length, pdu);
631
632         if (ril_data.state.sms_incoming_msg_tpid != 0) {
633                 LOGD("Another message is waiting ACK, queuing");
634                 rc = ipc_sms_incoming_msg_register(pdu, length, msg->type, msg->msg_tpid);
635                 if (rc < 0)
636                         LOGE("Unable to register incoming msg");
637
638                 return;
639         }
640
641         ipc_sms_incoming_msg_complete(pdu, length, msg->type, msg->msg_tpid);
642
643         return;
644
645 error:
646         if (info != NULL)
647                 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
648 }
649
650 void ril_request_sms_acknowledge(RIL_Token t, void *data, size_t length)
651 {
652         struct ipc_sms_deliver_report_request report_msg;
653         int success, fail_cause;
654
655         if (data == NULL || length < 2 * sizeof(int))
656                 goto error;
657
658         success = ((int *) data)[0];
659         fail_cause = ((int *) data)[1];
660
661         if (ril_data.state.sms_incoming_msg_tpid == 0) {
662                 LOGE("There is no SMS message to ACK!");
663                 goto error;
664         }
665
666         report_msg.type = IPC_SMS_TYPE_STATUS_REPORT;
667         report_msg.error = ril2ipc_sms_ack_error(success, fail_cause);
668         report_msg.msg_tpid = ril_data.state.sms_incoming_msg_tpid;
669         report_msg.unk = 0;
670
671         ipc_gen_phone_res_expect_to_abort(ril_request_get_id(t), IPC_SMS_DELIVER_REPORT);
672
673         ipc_fmt_send(IPC_SMS_DELIVER_REPORT, IPC_TYPE_EXEC, (void *) &report_msg, sizeof(report_msg), ril_request_get_id(t));
674
675         ipc_sms_incoming_msg_next();
676
677         return;
678
679 error:
680         ril_request_complete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
681
682         ipc_sms_incoming_msg_next();
683 }
684
685 void ipc_sms_deliver_report(struct ipc_message_info *info)
686 {
687         struct ipc_sms_deliver_report_response *report_msg;
688         RIL_Errno e;
689         int error_code;
690
691         if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_sms_deliver_report_response))
692                 goto error;
693
694         report_msg = (struct ipc_sms_deliver_report_response *) info->data;
695         e = ipc2ril_sms_ack_error(report_msg->error, &error_code);
696
697         ril_request_complete(ril_request_get_token(info->aseq), e, NULL, 0);
698
699         return;
700
701 error:
702         if (info != NULL)
703                 ril_request_complete(ril_request_get_token(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
704 }
705
706 /*
707  * Apparently non-SMS-messages-related function
708  */
709
710 void ipc_sms_device_ready(struct ipc_message_info *info)
711 {
712 #if RIL_VERSION >= 7
713         if (ril_data.state.radio_state == RADIO_STATE_ON) {
714 #else
715         if (ril_data.state.radio_state == RADIO_STATE_SIM_READY) {
716 #endif
717                 ipc_fmt_send(IPC_SMS_DEVICE_READY, IPC_TYPE_SET, NULL, 0, info->aseq);
718         }
719
720         ril_tokens_check();
721 }