blob: d112e1baa207cce9f3cef38b1cc9153d2d8bfd53 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
22#include <telephony/ril.h>
23#include <cutils/sockets.h>
24#include <cutils/jstring.h>
25#include <cutils/record_stream.h>
26#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
29#include <utils/Parcel.h>
30#include <cutils/jstring.h>
31
32#include <sys/types.h>
33#include <pwd.h>
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38#include <string.h>
39#include <unistd.h>
40#include <fcntl.h>
41#include <time.h>
42#include <errno.h>
43#include <assert.h>
44#include <ctype.h>
45#include <alloca.h>
46#include <sys/un.h>
47#include <assert.h>
48#include <netinet/in.h>
49#include <cutils/properties.h>
50
51#include <ril_event.h>
52
53namespace android {
54
55#define PHONE_PROCESS "radio"
56
57#define SOCKET_NAME_RIL "rild"
58#define SOCKET_NAME_RIL_DEBUG "rild-debug"
59
60#define ANDROID_WAKE_LOCK_NAME "radio-interface"
61
62
63#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
64
65// match with constant in RIL.java
66#define MAX_COMMAND_BYTES (8 * 1024)
67
68// Basically: memset buffers that the client library
69// shouldn't be using anymore in an attempt to find
70// memory usage issues sooner.
71#define MEMSET_FREED 1
72
73#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
74
75/* Constants for response types */
76#define RESPONSE_SOLICITED 0
77#define RESPONSE_UNSOLICITED 1
78
79/* Negative values for private RIL errno's */
80#define RIL_ERRNO_INVALID_RESPONSE -1
81
82// request, response, and unsolicited msg print macro
83#define PRINTBUF_SIZE 8096
84
85// Enable RILC log
86#define RILC_LOG 0
87
88#if RILC_LOG
89 #define startRequest sprintf(printBuf, "(")
90 #define closeRequest sprintf(printBuf, "%s)", printBuf)
91 #define printRequest(token, req) \
92 LOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
93
94 #define startResponse sprintf(printBuf, "%s {", printBuf)
95 #define closeResponse sprintf(printBuf, "%s}", printBuf)
96 #define printResponse LOGD("%s", printBuf)
97
98 #define clearPrintBuf printBuf[0] = 0
99 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
100 #define appendPrintBuf(x...) sprintf(printBuf, x)
101#else
102 #define startRequest
103 #define closeRequest
104 #define printRequest(token, req)
105 #define startResponse
106 #define closeResponse
107 #define printResponse
108 #define clearPrintBuf
109 #define removeLastChar
110 #define appendPrintBuf(x...)
111#endif
112
113enum WakeType {DONT_WAKE, WAKE_PARTIAL};
114
115typedef struct {
116 int requestNumber;
117 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
118 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
119} CommandInfo;
120
121typedef struct {
122 int requestNumber;
123 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
124 WakeType wakeType;
125} UnsolResponseInfo;
126
127typedef struct RequestInfo {
128 int32_t token; //this is not RIL_Token
129 CommandInfo *pCI;
130 struct RequestInfo *p_next;
131 char cancelled;
132 char local; // responses to local commands do not go back to command process
133} RequestInfo;
134
135typedef struct UserCallbackInfo{
136 RIL_TimedCallback p_callback;
137 void *userParam;
138 struct ril_event event;
139 struct UserCallbackInfo *p_next;
140} UserCallbackInfo;
141
142
143/*******************************************************************/
144
145RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
146static int s_registerCalled = 0;
147
148static pthread_t s_tid_dispatch;
149static pthread_t s_tid_reader;
150static int s_started = 0;
151
152static int s_fdListen = -1;
153static int s_fdCommand = -1;
154static int s_fdDebug = -1;
155
156static int s_fdWakeupRead;
157static int s_fdWakeupWrite;
158
159static struct ril_event s_commands_event;
160static struct ril_event s_wakeupfd_event;
161static struct ril_event s_listen_event;
162static struct ril_event s_wake_timeout_event;
163static struct ril_event s_debug_event;
164
165
166static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
167
168static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
169static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
170static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
171static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
172
173static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
174static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
175
176static RequestInfo *s_pendingRequests = NULL;
177
178static RequestInfo *s_toDispatchHead = NULL;
179static RequestInfo *s_toDispatchTail = NULL;
180
181static UserCallbackInfo *s_last_wake_timeout_info = NULL;
182
183static void *s_lastNITZTimeData = NULL;
184static size_t s_lastNITZTimeDataSize;
185
186#if RILC_LOG
187 static char printBuf[PRINTBUF_SIZE];
188#endif
189
190/*******************************************************************/
191
192static void dispatchVoid (Parcel& p, RequestInfo *pRI);
193static void dispatchString (Parcel& p, RequestInfo *pRI);
194static void dispatchStrings (Parcel& p, RequestInfo *pRI);
195static void dispatchInts (Parcel& p, RequestInfo *pRI);
196static void dispatchDial (Parcel& p, RequestInfo *pRI);
197static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
198static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
199static void dispatchRaw(Parcel& p, RequestInfo *pRI);
200static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
201
202static int responseInts(Parcel &p, void *response, size_t responselen);
203static int responseStrings(Parcel &p, void *response, size_t responselen);
204static int responseString(Parcel &p, void *response, size_t responselen);
205static int responseVoid(Parcel &p, void *response, size_t responselen);
206static int responseCallList(Parcel &p, void *response, size_t responselen);
207static int responseSMS(Parcel &p, void *response, size_t responselen);
208static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
209static int responseCallForwards(Parcel &p, void *response, size_t responselen);
210static int responseContexts(Parcel &p, void *response, size_t responselen);
211static int responseRaw(Parcel &p, void *response, size_t responselen);
212static int responseSsn(Parcel &p, void *response, size_t responselen);
213static int responseCellList(Parcel &p, void *response, size_t responselen);
214
215extern "C" const char * requestToString(int request);
216extern "C" const char * failCauseToString(RIL_Errno);
217extern "C" const char * callStateToString(RIL_CallState);
218extern "C" const char * radioStateToString(RIL_RadioState);
219
220#ifdef RIL_SHLIB
221extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
222 size_t datalen);
223#endif
224
225static UserCallbackInfo * internalRequestTimedCallback
226 (RIL_TimedCallback callback, void *param,
227 const struct timeval *relativeTime);
228
229/** Index == requestNumber */
230static CommandInfo s_commands[] = {
231#include "ril_commands.h"
232};
233
234static UnsolResponseInfo s_unsolResponses[] = {
235#include "ril_unsol_commands.h"
236};
237
238
239static char *
240strdupReadString(Parcel &p)
241{
242 size_t stringlen;
243 const char16_t *s16;
244
245 s16 = p.readString16Inplace(&stringlen);
246
247 return strndup16to8(s16, stringlen);
248}
249
250static void writeStringToParcel(Parcel &p, const char *s)
251{
252 char16_t *s16;
253 size_t s16_len;
254 s16 = strdup8to16(s, &s16_len);
255 p.writeString16(s16, s16_len);
256 free(s16);
257}
258
259
260static void
261memsetString (char *s)
262{
263 if (s != NULL) {
264 memset (s, 0, strlen(s));
265 }
266}
267
268void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
269 const size_t* objects, size_t objectsSize,
270 void* cookie)
271{
272 // do nothing -- the data reference lives longer than the Parcel object
273}
274
275/**
276 * To be called from dispatch thread
277 * Issue a single local request, ensuring that the response
278 * is not sent back up to the command process
279 */
280static void
281issueLocalRequest(int request, void *data, int len)
282{
283 RequestInfo *pRI;
284 int ret;
285
286 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
287
288 pRI->local = 1;
289 pRI->token = 0xffffffff; // token is not used in this context
290 pRI->pCI = &(s_commands[request]);
291
292 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
293 assert (ret == 0);
294
295 pRI->p_next = s_pendingRequests;
296 s_pendingRequests = pRI;
297
298 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
299 assert (ret == 0);
300
301 LOGD("C[locl]> %s", requestToString(request));
302
303 s_callbacks.onRequest(request, data, len, pRI);
304}
305
306
307
308static int
309processCommandBuffer(void *buffer, size_t buflen)
310{
311 Parcel p;
312 status_t status;
313 int32_t request;
314 int32_t token;
315 RequestInfo *pRI;
316 int ret;
317
318 p.setData((uint8_t *) buffer, buflen);
319
320 // status checked at end
321 status = p.readInt32(&request);
322 status = p.readInt32 (&token);
323
324 if (status != NO_ERROR) {
325 LOGE("invalid request block");
326 return 0;
327 }
328
329 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
330 LOGE("unsupported request code %d token %d", request, token);
331 // FIXME this should perhaps return a response
332 return 0;
333 }
334
335
336 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
337
338 pRI->token = token;
339 pRI->pCI = &(s_commands[request]);
340
341 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
342 assert (ret == 0);
343
344 pRI->p_next = s_pendingRequests;
345 s_pendingRequests = pRI;
346
347 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
348 assert (ret == 0);
349
350/* sLastDispatchedToken = token; */
351
352 pRI->pCI->dispatchFunction(p, pRI);
353
354 return 0;
355}
356
357static void
358invalidCommandBlock (RequestInfo *pRI)
359{
360 LOGE("invalid command block for token %d request %s",
361 pRI->token, requestToString(pRI->pCI->requestNumber));
362}
363
364/** Callee expects NULL */
365static void
366dispatchVoid (Parcel& p, RequestInfo *pRI)
367{
368 clearPrintBuf;
369 printRequest(pRI->token, pRI->pCI->requestNumber);
370 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
371}
372
373/** Callee expects const char * */
374static void
375dispatchString (Parcel& p, RequestInfo *pRI)
376{
377 status_t status;
378 size_t datalen;
379 size_t stringlen;
380 char *string8 = NULL;
381
382 string8 = strdupReadString(p);
383
384 startRequest;
385 appendPrintBuf("%s%s", printBuf, string8);
386 closeRequest;
387 printRequest(pRI->token, pRI->pCI->requestNumber);
388
389 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
390 sizeof(char *), pRI);
391
392#ifdef MEMSET_FREED
393 memsetString(string8);
394#endif
395
396 free(string8);
397 return;
398invalid:
399 invalidCommandBlock(pRI);
400 return;
401}
402
403/** Callee expects const char ** */
404static void
405dispatchStrings (Parcel &p, RequestInfo *pRI)
406{
407 int32_t countStrings;
408 status_t status;
409 size_t datalen;
410 char **pStrings;
411
412 status = p.readInt32 (&countStrings);
413
414 if (status != NO_ERROR) {
415 goto invalid;
416 }
417
418 startRequest;
419 if (countStrings == 0) {
420 // just some non-null pointer
421 pStrings = (char **)alloca(sizeof(char *));
422 datalen = 0;
423 } else if (((int)countStrings) == -1) {
424 pStrings = NULL;
425 datalen = 0;
426 } else {
427 datalen = sizeof(char *) * countStrings;
428
429 pStrings = (char **)alloca(datalen);
430
431 for (int i = 0 ; i < countStrings ; i++) {
432 pStrings[i] = strdupReadString(p);
433 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
434 }
435 }
436 removeLastChar;
437 closeRequest;
438 printRequest(pRI->token, pRI->pCI->requestNumber);
439
440 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
441
442 if (pStrings != NULL) {
443 for (int i = 0 ; i < countStrings ; i++) {
444#ifdef MEMSET_FREED
445 memsetString (pStrings[i]);
446#endif
447 free(pStrings[i]);
448 }
449
450#ifdef MEMSET_FREED
451 memset(pStrings, 0, datalen);
452#endif
453 }
454
455 return;
456invalid:
457 invalidCommandBlock(pRI);
458 return;
459}
460
461/** Callee expects const int * */
462static void
463dispatchInts (Parcel &p, RequestInfo *pRI)
464{
465 int32_t count;
466 status_t status;
467 size_t datalen;
468 int *pInts;
469
470 status = p.readInt32 (&count);
471
472 if (status != NO_ERROR || count == 0) {
473 goto invalid;
474 }
475
476 datalen = sizeof(int) * count;
477 pInts = (int *)alloca(datalen);
478
479 startRequest;
480 for (int i = 0 ; i < count ; i++) {
481 int32_t t;
482
483 status = p.readInt32(&t);
484 pInts[i] = (int)t;
485 appendPrintBuf("%s%d,", printBuf, t);
486
487 if (status != NO_ERROR) {
488 goto invalid;
489 }
490 }
491 removeLastChar;
492 closeRequest;
493 printRequest(pRI->token, pRI->pCI->requestNumber);
494
495 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
496 datalen, pRI);
497
498#ifdef MEMSET_FREED
499 memset(pInts, 0, datalen);
500#endif
501
502 return;
503invalid:
504 invalidCommandBlock(pRI);
505 return;
506}
507
508
509/**
510 * Callee expects const RIL_SMS_WriteArgs *
511 * Payload is:
512 * int32_t status
513 * String pdu
514 */
515static void
516dispatchSmsWrite (Parcel &p, RequestInfo *pRI)
517{
518 RIL_SMS_WriteArgs args;
519 int32_t t;
520 status_t status;
521
522 memset (&args, 0, sizeof(args));
523
524 status = p.readInt32(&t);
525 args.status = (int)t;
526
527 args.pdu = strdupReadString(p);
528
529 if (status != NO_ERROR || args.pdu == NULL) {
530 goto invalid;
531 }
532
533 args.smsc = strdupReadString(p);
534
535 startRequest;
536 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
537 (char*)args.pdu, (char*)args.smsc);
538 closeRequest;
539 printRequest(pRI->token, pRI->pCI->requestNumber);
540
541 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
542
543#ifdef MEMSET_FREED
544 memsetString (args.pdu);
545#endif
546
547 free (args.pdu);
548
549#ifdef MEMSET_FREED
550 memset(&args, 0, sizeof(args));
551#endif
552
553 return;
554invalid:
555 invalidCommandBlock(pRI);
556 return;
557}
558
559/**
560 * Callee expects const RIL_Dial *
561 * Payload is:
562 * String address
563 * int32_t clir
564 */
565static void
566dispatchDial (Parcel &p, RequestInfo *pRI)
567{
568 RIL_Dial dial;
569 int32_t t;
570 status_t status;
571
572 memset (&dial, 0, sizeof(dial));
573
574 dial.address = strdupReadString(p);
575
576 status = p.readInt32(&t);
577 dial.clir = (int)t;
578
579 if (status != NO_ERROR || dial.address == NULL) {
580 goto invalid;
581 }
582
583 startRequest;
584 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
585 closeRequest;
586 printRequest(pRI->token, pRI->pCI->requestNumber);
587
588 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeof(dial), pRI);
589
590#ifdef MEMSET_FREED
591 memsetString (dial.address);
592#endif
593
594 free (dial.address);
595
596#ifdef MEMSET_FREED
597 memset(&dial, 0, sizeof(dial));
598#endif
599
600 return;
601invalid:
602 invalidCommandBlock(pRI);
603 return;
604}
605
606/**
607 * Callee expects const RIL_SIM_IO *
608 * Payload is:
609 * int32_t command
610 * int32_t fileid
611 * String path
612 * int32_t p1, p2, p3
613 * String data
614 * String pin2
615 */
616static void
617dispatchSIM_IO (Parcel &p, RequestInfo *pRI)
618{
619 RIL_SIM_IO simIO;
620 int32_t t;
621 status_t status;
622
623 memset (&simIO, 0, sizeof(simIO));
624
625 // note we only check status at the end
626
627 status = p.readInt32(&t);
628 simIO.command = (int)t;
629
630 status = p.readInt32(&t);
631 simIO.fileid = (int)t;
632
633 simIO.path = strdupReadString(p);
634
635 status = p.readInt32(&t);
636 simIO.p1 = (int)t;
637
638 status = p.readInt32(&t);
639 simIO.p2 = (int)t;
640
641 status = p.readInt32(&t);
642 simIO.p3 = (int)t;
643
644 simIO.data = strdupReadString(p);
645 simIO.pin2 = strdupReadString(p);
646
647 startRequest;
648 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s", printBuf,
649 simIO.command, simIO.fileid, (char*)simIO.path,
650 simIO.p1, simIO.p2, simIO.p3,
651 (char*)simIO.data, (char*)simIO.pin2);
652 closeRequest;
653 printRequest(pRI->token, pRI->pCI->requestNumber);
654
655 if (status != NO_ERROR) {
656 goto invalid;
657 }
658
659 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, sizeof(simIO), pRI);
660
661#ifdef MEMSET_FREED
662 memsetString (simIO.path);
663 memsetString (simIO.data);
664 memsetString (simIO.pin2);
665#endif
666
667 free (simIO.path);
668 free (simIO.data);
669 free (simIO.pin2);
670
671#ifdef MEMSET_FREED
672 memset(&simIO, 0, sizeof(simIO));
673#endif
674
675 return;
676invalid:
677 invalidCommandBlock(pRI);
678 return;
679}
680
681/**
682 * Callee expects const RIL_CallForwardInfo *
683 * Payload is:
684 * int32_t status/action
685 * int32_t reason
686 * int32_t serviceCode
687 * int32_t toa
688 * String number (0 length -> null)
689 * int32_t timeSeconds
690 */
691static void
692dispatchCallForward(Parcel &p, RequestInfo *pRI)
693{
694 RIL_CallForwardInfo cff;
695 int32_t t;
696 status_t status;
697
698 memset (&cff, 0, sizeof(cff));
699
700 // note we only check status at the end
701
702 status = p.readInt32(&t);
703 cff.status = (int)t;
704
705 status = p.readInt32(&t);
706 cff.reason = (int)t;
707
708 status = p.readInt32(&t);
709 cff.serviceClass = (int)t;
710
711 status = p.readInt32(&t);
712 cff.toa = (int)t;
713
714 cff.number = strdupReadString(p);
715
716 status = p.readInt32(&t);
717 cff.timeSeconds = (int)t;
718
719 if (status != NO_ERROR) {
720 goto invalid;
721 }
722
723 // special case: number 0-length fields is null
724
725 if (cff.number != NULL && strlen (cff.number) == 0) {
726 cff.number = NULL;
727 }
728
729 startRequest;
730 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
731 cff.status, cff.reason, cff.serviceClass, cff.toa,
732 (char*)cff.number, cff.timeSeconds);
733 closeRequest;
734 printRequest(pRI->token, pRI->pCI->requestNumber);
735
736 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
737
738#ifdef MEMSET_FREED
739 memsetString(cff.number);
740#endif
741
742 free (cff.number);
743
744#ifdef MEMSET_FREED
745 memset(&cff, 0, sizeof(cff));
746#endif
747
748 return;
749invalid:
750 invalidCommandBlock(pRI);
751 return;
752}
753
754
755static void
756dispatchRaw(Parcel &p, RequestInfo *pRI)
757{
758 int32_t len;
759 status_t status;
760 const void *data;
761
762 status = p.readInt32(&len);
763
764 if (status != NO_ERROR) {
765 goto invalid;
766 }
767
768 // The java code writes -1 for null arrays
769 if (((int)len) == -1) {
770 data = NULL;
771 len = 0;
772 }
773
774 data = p.readInplace(len);
775
776 startRequest;
777 appendPrintBuf("%sraw_size=%d", printBuf, len);
778 closeRequest;
779 printRequest(pRI->token, pRI->pCI->requestNumber);
780
781 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
782
783 return;
784invalid:
785 invalidCommandBlock(pRI);
786 return;
787}
788
789static int
790blockingWrite(int fd, const void *buffer, size_t len)
791{
792 size_t writeOffset = 0;
793 const uint8_t *toWrite;
794
795 toWrite = (const uint8_t *)buffer;
796
797 while (writeOffset < len) {
798 ssize_t written;
799 do {
800 written = write (fd, toWrite + writeOffset,
801 len - writeOffset);
802 } while (written < 0 && errno == EINTR);
803
804 if (written >= 0) {
805 writeOffset += written;
806 } else { // written < 0
807 LOGE ("RIL Response: unexpected error on write errno:%d", errno);
808 close(fd);
809 return -1;
810 }
811 }
812
813 return 0;
814}
815
816static int
817sendResponseRaw (const void *data, size_t dataSize)
818{
819 int fd = s_fdCommand;
820 int ret;
821 uint32_t header;
822
823 if (s_fdCommand < 0) {
824 return -1;
825 }
826
827 if (dataSize > MAX_COMMAND_BYTES) {
828 LOGE("RIL: packet larger than %u (%u)",
829 MAX_COMMAND_BYTES, (unsigned int )dataSize);
830
831 return -1;
832 }
833
834
835 // FIXME is blocking here ok? issue #550970
836
837 pthread_mutex_lock(&s_writeMutex);
838
839 header = htonl(dataSize);
840
841 ret = blockingWrite(fd, (void *)&header, sizeof(header));
842
843 if (ret < 0) {
844 return ret;
845 }
846
847 blockingWrite(fd, data, dataSize);
848
849 if (ret < 0) {
850 return ret;
851 }
852
853 pthread_mutex_unlock(&s_writeMutex);
854
855 return 0;
856}
857
858static int
859sendResponse (Parcel &p)
860{
861 printResponse;
862 return sendResponseRaw(p.data(), p.dataSize());
863}
864
865/** response is an int* pointing to an array of ints*/
866
867static int
868responseInts(Parcel &p, void *response, size_t responselen)
869{
870 int numInts;
871
872 if (response == NULL && responselen != 0) {
873 LOGE("invalid response: NULL");
874 return RIL_ERRNO_INVALID_RESPONSE;
875 }
876 if (responselen % sizeof(int) != 0) {
877 LOGE("invalid response length %d expected multiple of %d\n",
878 (int)responselen, (int)sizeof(int));
879 return RIL_ERRNO_INVALID_RESPONSE;
880 }
881
882 int *p_int = (int *) response;
883
884 numInts = responselen / sizeof(int *);
885 p.writeInt32 (numInts);
886
887 /* each int*/
888 startResponse;
889 for (int i = 0 ; i < numInts ; i++) {
890 appendPrintBuf("%s%d,", printBuf, p_int[i]);
891 p.writeInt32(p_int[i]);
892 }
893 removeLastChar;
894 closeResponse;
895
896 return 0;
897}
898
899/** response is a char **, pointing to an array of char *'s */
900static int responseStrings(Parcel &p, void *response, size_t responselen)
901{
902 int numStrings;
903
904 if (response == NULL && responselen != 0) {
905 LOGE("invalid response: NULL");
906 return RIL_ERRNO_INVALID_RESPONSE;
907 }
908 if (responselen % sizeof(char *) != 0) {
909 LOGE("invalid response length %d expected multiple of %d\n",
910 (int)responselen, (int)sizeof(char *));
911 return RIL_ERRNO_INVALID_RESPONSE;
912 }
913
914 if (response == NULL) {
915 p.writeInt32 (0);
916 } else {
917 char **p_cur = (char **) response;
918
919 numStrings = responselen / sizeof(char *);
920 p.writeInt32 (numStrings);
921
922 /* each string*/
923 startResponse;
924 for (int i = 0 ; i < numStrings ; i++) {
925 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
926 writeStringToParcel (p, p_cur[i]);
927 }
928 removeLastChar;
929 closeResponse;
930 }
931 return 0;
932}
933
934
935/**
936 * NULL strings are accepted
937 * FIXME currently ignores responselen
938 */
939static int responseString(Parcel &p, void *response, size_t responselen)
940{
941 /* one string only */
942 startResponse;
943 appendPrintBuf("%s%s", printBuf, (char*)response);
944 closeResponse;
945
946 writeStringToParcel(p, (const char *)response);
947
948 return 0;
949}
950
951static int responseVoid(Parcel &p, void *response, size_t responselen)
952{
953 startResponse;
954 removeLastChar;
955 return 0;
956}
957
958static int responseCallList(Parcel &p, void *response, size_t responselen)
959{
960 int num;
961
962 if (response == NULL && responselen != 0) {
963 LOGE("invalid response: NULL");
964 return RIL_ERRNO_INVALID_RESPONSE;
965 }
966
967 if (responselen % sizeof (RIL_Call *) != 0) {
968 LOGE("invalid response length %d expected multiple of %d\n",
969 (int)responselen, (int)sizeof (RIL_Call *));
970 return RIL_ERRNO_INVALID_RESPONSE;
971 }
972
973 startResponse;
974 /* number of call info's */
975 num = responselen / sizeof(RIL_Call *);
976 p.writeInt32(num);
977
978 for (int i = 0 ; i < num ; i++) {
979 RIL_Call *p_cur = ((RIL_Call **) response)[i];
980 /* each call info */
981 p.writeInt32(p_cur->state);
982 p.writeInt32(p_cur->index);
983 p.writeInt32(p_cur->toa);
984 p.writeInt32(p_cur->isMpty);
985 p.writeInt32(p_cur->isMT);
986 p.writeInt32(p_cur->als);
987 p.writeInt32(p_cur->isVoice);
988 writeStringToParcel (p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -0700989 p.writeInt32(p_cur->numberPresentation);
990 appendPrintBuf("%s[%s,id=%d,toa=%d,%s,%s,als=%d,%s,%s,cli=%d],",
991 printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800992 callStateToString(p_cur->state),
993 p_cur->index, p_cur->toa,
994 (p_cur->isMpty)?"mpty":"norm",
995 (p_cur->isMT)?"mt":"mo",
996 p_cur->als,
997 (p_cur->isVoice)?"voc":"nonvoc",
John Wangff368742009-03-24 17:56:29 -0700998 (char*)p_cur->number,
999 p_cur->numberPresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001000 }
1001 removeLastChar;
1002 closeResponse;
1003
1004 return 0;
1005}
1006
1007static int responseSMS(Parcel &p, void *response, size_t responselen)
1008{
1009 if (response == NULL) {
1010 LOGE("invalid response: NULL");
1011 return RIL_ERRNO_INVALID_RESPONSE;
1012 }
1013
1014 if (responselen != sizeof (RIL_SMS_Response) ) {
1015 LOGE("invalid response length %d expected %d",
1016 (int)responselen, (int)sizeof (RIL_SMS_Response));
1017 return RIL_ERRNO_INVALID_RESPONSE;
1018 }
1019
1020 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1021
1022 p.writeInt32(p_cur->messageRef);
1023 writeStringToParcel(p, p_cur->ackPDU);
1024
1025 startResponse;
1026 appendPrintBuf("%s%d,%s", printBuf, p_cur->messageRef,
1027 (char*)p_cur->ackPDU);
1028 closeResponse;
1029
1030 return 0;
1031}
1032
1033static int responseContexts(Parcel &p, void *response, size_t responselen)
1034{
1035 if (response == NULL && responselen != 0) {
1036 LOGE("invalid response: NULL");
1037 return RIL_ERRNO_INVALID_RESPONSE;
1038 }
1039
1040 if (responselen % sizeof(RIL_PDP_Context_Response) != 0) {
1041 LOGE("invalid response length %d expected multiple of %d",
1042 (int)responselen, (int)sizeof(RIL_PDP_Context_Response));
1043 return RIL_ERRNO_INVALID_RESPONSE;
1044 }
1045
1046 int num = responselen / sizeof(RIL_PDP_Context_Response);
1047 p.writeInt32(num);
1048
1049 RIL_PDP_Context_Response *p_cur = (RIL_PDP_Context_Response *) response;
1050 startResponse;
1051 int i;
1052 for (i = 0; i < num; i++) {
1053 p.writeInt32(p_cur[i].cid);
1054 p.writeInt32(p_cur[i].active);
1055 writeStringToParcel(p, p_cur[i].type);
1056 writeStringToParcel(p, p_cur[i].apn);
1057 writeStringToParcel(p, p_cur[i].address);
1058 appendPrintBuf("%s[cid=%d,%s,%s,%s,%s],", printBuf,
1059 p_cur[i].cid,
1060 (p_cur[i].active==0)?"down":"up",
1061 (char*)p_cur[i].type,
1062 (char*)p_cur[i].apn,
1063 (char*)p_cur[i].address);
1064 }
1065 removeLastChar;
1066 closeResponse;
1067
1068 return 0;
1069}
1070
1071static int responseRaw(Parcel &p, void *response, size_t responselen)
1072{
1073 if (response == NULL && responselen != 0) {
1074 LOGE("invalid response: NULL with responselen != 0");
1075 return RIL_ERRNO_INVALID_RESPONSE;
1076 }
1077
1078 // The java code reads -1 size as null byte array
1079 if (response == NULL) {
1080 p.writeInt32(-1);
1081 } else {
1082 p.writeInt32(responselen);
1083 p.write(response, responselen);
1084 }
1085
1086 return 0;
1087}
1088
1089
1090static int responseSIM_IO(Parcel &p, void *response, size_t responselen)
1091{
1092 if (response == NULL) {
1093 LOGE("invalid response: NULL");
1094 return RIL_ERRNO_INVALID_RESPONSE;
1095 }
1096
1097 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
1098 LOGE("invalid response length was %d expected %d",
1099 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1100 return RIL_ERRNO_INVALID_RESPONSE;
1101 }
1102
1103 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1104 p.writeInt32(p_cur->sw1);
1105 p.writeInt32(p_cur->sw2);
1106 writeStringToParcel(p, p_cur->simResponse);
1107
1108 startResponse;
1109 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1110 (char*)p_cur->simResponse);
1111 closeResponse;
1112
1113
1114 return 0;
1115}
1116
1117static int responseCallForwards(Parcel &p, void *response, size_t responselen)
1118{
1119 int num;
1120
1121 if (response == NULL && responselen != 0) {
1122 LOGE("invalid response: NULL");
1123 return RIL_ERRNO_INVALID_RESPONSE;
1124 }
1125
1126 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
1127 LOGE("invalid response length %d expected multiple of %d",
1128 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1129 return RIL_ERRNO_INVALID_RESPONSE;
1130 }
1131
1132 /* number of call info's */
1133 num = responselen / sizeof(RIL_CallForwardInfo *);
1134 p.writeInt32(num);
1135
1136 startResponse;
1137 for (int i = 0 ; i < num ; i++) {
1138 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1139
1140 p.writeInt32(p_cur->status);
1141 p.writeInt32(p_cur->reason);
1142 p.writeInt32(p_cur->serviceClass);
1143 p.writeInt32(p_cur->toa);
1144 writeStringToParcel(p, p_cur->number);
1145 p.writeInt32(p_cur->timeSeconds);
1146 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1147 (p_cur->status==1)?"enable":"disable",
1148 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1149 (char*)p_cur->number,
1150 p_cur->timeSeconds);
1151 }
1152 removeLastChar;
1153 closeResponse;
1154
1155 return 0;
1156}
1157
1158static int responseSsn(Parcel &p, void *response, size_t responselen)
1159{
1160 if (response == NULL) {
1161 LOGE("invalid response: NULL");
1162 return RIL_ERRNO_INVALID_RESPONSE;
1163 }
1164
1165 if (responselen != sizeof(RIL_SuppSvcNotification)) {
1166 LOGE("invalid response length was %d expected %d",
1167 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1168 return RIL_ERRNO_INVALID_RESPONSE;
1169 }
1170
1171 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1172 p.writeInt32(p_cur->notificationType);
1173 p.writeInt32(p_cur->code);
1174 p.writeInt32(p_cur->index);
1175 p.writeInt32(p_cur->type);
1176 writeStringToParcel(p, p_cur->number);
1177
1178 startResponse;
1179 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1180 (p_cur->notificationType==0)?"mo":"mt",
1181 p_cur->code, p_cur->index, p_cur->type,
1182 (char*)p_cur->number);
1183 closeResponse;
1184
1185 return 0;
1186}
1187
1188static int responseCellList(Parcel &p, void *response, size_t responselen)
1189{
1190 int num;
1191
1192 if (response == NULL && responselen != 0) {
1193 LOGE("invalid response: NULL");
1194 return RIL_ERRNO_INVALID_RESPONSE;
1195 }
1196
1197 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
1198 LOGE("invalid response length %d expected multiple of %d\n",
1199 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
1200 return RIL_ERRNO_INVALID_RESPONSE;
1201 }
1202
1203 startResponse;
1204 /* number of cell info's */
1205 num = responselen / sizeof(RIL_NeighboringCell *);
1206 p.writeInt32(num);
1207
1208 for (int i = 0 ; i < num ; i++) {
1209 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
1210
1211 /* each cell info */
1212 p.writeInt32(p_cur->rssi);
1213 writeStringToParcel (p, p_cur->cid);
1214
1215 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
1216 p_cur->cid, p_cur->rssi);
1217 }
1218 removeLastChar;
1219 closeResponse;
1220
1221 return 0;
1222}
1223
1224static void triggerEvLoop()
1225{
1226 int ret;
1227 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
1228 /* trigger event loop to wakeup. No reason to do this,
1229 * if we're in the event loop thread */
1230 do {
1231 ret = write (s_fdWakeupWrite, " ", 1);
1232 } while (ret < 0 && errno == EINTR);
1233 }
1234}
1235
1236static void rilEventAddWakeup(struct ril_event *ev)
1237{
1238 ril_event_add(ev);
1239 triggerEvLoop();
1240}
1241
1242/**
1243 * A write on the wakeup fd is done just to pop us out of select()
1244 * We empty the buffer here and then ril_event will reset the timers on the
1245 * way back down
1246 */
1247static void processWakeupCallback(int fd, short flags, void *param)
1248{
1249 char buff[16];
1250 int ret;
1251
1252 LOGV("processWakeupCallback");
1253
1254 /* empty our wakeup socket out */
1255 do {
1256 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
1257 } while (ret > 0 || (ret < 0 && errno == EINTR));
1258}
1259
1260static void onCommandsSocketClosed()
1261{
1262 int ret;
1263 RequestInfo *p_cur;
1264
1265 /* mark pending requests as "cancelled" so we dont report responses */
1266
1267 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
1268 assert (ret == 0);
1269
1270 p_cur = s_pendingRequests;
1271
1272 for (p_cur = s_pendingRequests
1273 ; p_cur != NULL
1274 ; p_cur = p_cur->p_next
1275 ) {
1276 p_cur->cancelled = 1;
1277 }
1278
1279 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
1280 assert (ret == 0);
1281}
1282
1283static void processCommandsCallback(int fd, short flags, void *param)
1284{
1285 RecordStream *p_rs;
1286 void *p_record;
1287 size_t recordlen;
1288 int ret;
1289
1290 assert(fd == s_fdCommand);
1291
1292 p_rs = (RecordStream *)param;
1293
1294 for (;;) {
1295 /* loop until EAGAIN/EINTR, end of stream, or other error */
1296 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
1297
1298 if (ret == 0 && p_record == NULL) {
1299 /* end-of-stream */
1300 break;
1301 } else if (ret < 0) {
1302 break;
1303 } else if (ret == 0) { /* && p_record != NULL */
1304 processCommandBuffer(p_record, recordlen);
1305 }
1306 }
1307
1308 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
1309 /* fatal error or end-of-stream */
1310 if (ret != 0) {
1311 LOGE("error on reading command socket errno:%d\n", errno);
1312 } else {
1313 LOGW("EOS. Closing command socket.");
1314 }
1315
1316 close(s_fdCommand);
1317 s_fdCommand = -1;
1318
1319 ril_event_del(&s_commands_event);
1320
1321 record_stream_free(p_rs);
1322
1323 /* start listening for new connections again */
1324 rilEventAddWakeup(&s_listen_event);
1325
1326 onCommandsSocketClosed();
1327 }
1328}
1329
1330
1331static void onNewCommandConnect()
1332{
1333 // implicit radio state changed
1334 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
1335 NULL, 0);
1336
1337 // Send last NITZ time data, in case it was missed
1338 if (s_lastNITZTimeData != NULL) {
1339 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
1340
1341 free(s_lastNITZTimeData);
1342 s_lastNITZTimeData = NULL;
1343 }
1344
1345 // Get version string
1346 if (s_callbacks.getVersion != NULL) {
1347 const char *version;
1348 version = s_callbacks.getVersion();
1349 LOGI("RIL Daemon version: %s\n", version);
1350
1351 property_set(PROPERTY_RIL_IMPL, version);
1352 } else {
1353 LOGI("RIL Daemon version: unavailable\n");
1354 property_set(PROPERTY_RIL_IMPL, "unavailable");
1355 }
1356
1357}
1358
1359static void listenCallback (int fd, short flags, void *param)
1360{
1361 int ret;
1362 int err;
1363 int is_phone_socket;
1364 RecordStream *p_rs;
1365
1366 struct sockaddr_un peeraddr;
1367 socklen_t socklen = sizeof (peeraddr);
1368
1369 struct ucred creds;
1370 socklen_t szCreds = sizeof(creds);
1371
1372 struct passwd *pwd = NULL;
1373
1374 assert (s_fdCommand < 0);
1375 assert (fd == s_fdListen);
1376
1377 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
1378
1379 if (s_fdCommand < 0 ) {
1380 LOGE("Error on accept() errno:%d", errno);
1381 /* start listening for new connections again */
1382 rilEventAddWakeup(&s_listen_event);
1383 return;
1384 }
1385
1386 /* check the credential of the other side and only accept socket from
1387 * phone process
1388 */
1389 errno = 0;
1390 is_phone_socket = 0;
1391
1392 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
1393
1394 if (err == 0 && szCreds > 0) {
1395 errno = 0;
1396 pwd = getpwuid(creds.uid);
1397 if (pwd != NULL) {
1398 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
1399 is_phone_socket = 1;
1400 } else {
1401 LOGE("RILD can't accept socket from process %s", pwd->pw_name);
1402 }
1403 } else {
1404 LOGE("Error on getpwuid() errno: %d", errno);
1405 }
1406 } else {
1407 LOGD("Error on getsockopt() errno: %d", errno);
1408 }
1409
1410 if ( !is_phone_socket ) {
1411 LOGE("RILD must accept socket from %s", PHONE_PROCESS);
1412
1413 close(s_fdCommand);
1414 s_fdCommand = -1;
1415
1416 onCommandsSocketClosed();
1417
1418 /* start listening for new connections again */
1419 rilEventAddWakeup(&s_listen_event);
1420
1421 return;
1422 }
1423
1424 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
1425
1426 if (ret < 0) {
1427 LOGE ("Error setting O_NONBLOCK errno:%d", errno);
1428 }
1429
1430 LOGI("libril: new connection");
1431
1432 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
1433
1434 ril_event_set (&s_commands_event, s_fdCommand, 1,
1435 processCommandsCallback, p_rs);
1436
1437 rilEventAddWakeup (&s_commands_event);
1438
1439 onNewCommandConnect();
1440}
1441
1442static void freeDebugCallbackArgs(int number, char **args) {
1443 for (int i = 0; i < number; i++) {
1444 if (args[i] != NULL) {
1445 free(args[i]);
1446 }
1447 }
1448 free(args);
1449}
1450
1451static void debugCallback (int fd, short flags, void *param)
1452{
1453 int acceptFD, option;
1454 struct sockaddr_un peeraddr;
1455 socklen_t socklen = sizeof (peeraddr);
1456 int data;
1457 unsigned int qxdm_data[6];
1458 const char *deactData[1] = {"1"};
1459 char *actData[1];
1460 RIL_Dial dialData;
1461 int hangupData[1] = {1};
1462 int number;
1463 char **args;
1464
1465 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
1466
1467 if (acceptFD < 0) {
1468 LOGE ("error accepting on debug port: %d\n", errno);
1469 return;
1470 }
1471
1472 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
1473 LOGE ("error reading on socket: number of Args: \n");
1474 return;
1475 }
1476 args = (char **) malloc(sizeof(char*) * number);
1477
1478 for (int i = 0; i < number; i++) {
1479 int len;
1480 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
1481 LOGE ("error reading on socket: Len of Args: \n");
1482 freeDebugCallbackArgs(i, args);
1483 return;
1484 }
1485 // +1 for null-term
1486 args[i] = (char *) malloc((sizeof(char) * len) + 1);
1487 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
1488 != sizeof(char) * len) {
1489 LOGE ("error reading on socket: Args[%d] \n", i);
1490 freeDebugCallbackArgs(i, args);
1491 return;
1492 }
1493 char * buf = args[i];
1494 buf[len] = 0;
1495 }
1496
1497 switch (atoi(args[0])) {
1498 case 0:
1499 LOGI ("Connection on debug port: issuing reset.");
1500 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
1501 break;
1502 case 1:
1503 LOGI ("Connection on debug port: issuing radio power off.");
1504 data = 0;
1505 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
1506 // Close the socket
1507 close(s_fdCommand);
1508 s_fdCommand = -1;
1509 break;
1510 case 2:
1511 LOGI ("Debug port: issuing unsolicited network change.");
1512 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED,
1513 NULL, 0);
1514 break;
1515 case 3:
1516 LOGI ("Debug port: QXDM log enable.");
1517 qxdm_data[0] = 65536;
1518 qxdm_data[1] = 16;
1519 qxdm_data[2] = 1;
1520 qxdm_data[3] = 32;
1521 qxdm_data[4] = 0;
1522 qxdm_data[4] = 8;
1523 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
1524 6 * sizeof(int));
1525 break;
1526 case 4:
1527 LOGI ("Debug port: QXDM log disable.");
1528 qxdm_data[0] = 65536;
1529 qxdm_data[1] = 16;
1530 qxdm_data[2] = 0;
1531 qxdm_data[3] = 32;
1532 qxdm_data[4] = 0;
1533 qxdm_data[4] = 8;
1534 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
1535 6 * sizeof(int));
1536 break;
1537 case 5:
1538 LOGI("Debug port: Radio On");
1539 data = 1;
1540 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
1541 sleep(2);
1542 // Set network selection automatic.
1543 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
1544 break;
1545 case 6:
1546 LOGI("Debug port: Setup PDP, Apn :%s\n", args[1]);
1547 actData[0] = args[1];
1548 issueLocalRequest(RIL_REQUEST_SETUP_DEFAULT_PDP, &actData,
1549 sizeof(actData));
1550 break;
1551 case 7:
1552 LOGI("Debug port: Deactivate PDP");
1553 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DEFAULT_PDP, &deactData,
1554 sizeof(deactData));
1555 break;
1556 case 8:
1557 LOGI("Debug port: Dial Call");
1558 dialData.clir = 0;
1559 dialData.address = args[1];
1560 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
1561 break;
1562 case 9:
1563 LOGI("Debug port: Answer Call");
1564 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
1565 break;
1566 case 10:
1567 LOGI("Debug port: End Call");
1568 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
1569 sizeof(hangupData));
1570 break;
1571 default:
1572 LOGE ("Invalid request");
1573 break;
1574 }
1575 freeDebugCallbackArgs(number, args);
1576 close(acceptFD);
1577}
1578
1579
1580static void userTimerCallback (int fd, short flags, void *param)
1581{
1582 UserCallbackInfo *p_info;
1583
1584 p_info = (UserCallbackInfo *)param;
1585
1586 p_info->p_callback(p_info->userParam);
1587
1588
1589 // FIXME generalize this...there should be a cancel mechanism
1590 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
1591 s_last_wake_timeout_info = NULL;
1592 }
1593
1594 free(p_info);
1595}
1596
1597
1598static void *
1599eventLoop(void *param)
1600{
1601 int ret;
1602 int filedes[2];
1603
1604 ril_event_init();
1605
1606 pthread_mutex_lock(&s_startupMutex);
1607
1608 s_started = 1;
1609 pthread_cond_broadcast(&s_startupCond);
1610
1611 pthread_mutex_unlock(&s_startupMutex);
1612
1613 ret = pipe(filedes);
1614
1615 if (ret < 0) {
1616 LOGE("Error in pipe() errno:%d", errno);
1617 return NULL;
1618 }
1619
1620 s_fdWakeupRead = filedes[0];
1621 s_fdWakeupWrite = filedes[1];
1622
1623 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
1624
1625 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
1626 processWakeupCallback, NULL);
1627
1628 rilEventAddWakeup (&s_wakeupfd_event);
1629
1630 // Only returns on error
1631 ril_event_loop();
1632 LOGE ("error in event_loop_base errno:%d", errno);
1633
1634 return NULL;
1635}
1636
1637extern "C" void
1638RIL_startEventLoop(void)
1639{
1640 int ret;
1641 pthread_attr_t attr;
1642
1643 /* spin up eventLoop thread and wait for it to get started */
1644 s_started = 0;
1645 pthread_mutex_lock(&s_startupMutex);
1646
1647 pthread_attr_init (&attr);
1648 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1649 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
1650
1651 while (s_started == 0) {
1652 pthread_cond_wait(&s_startupCond, &s_startupMutex);
1653 }
1654
1655 pthread_mutex_unlock(&s_startupMutex);
1656
1657 if (ret < 0) {
1658 LOGE("Failed to create dispatch thread errno:%d", errno);
1659 return;
1660 }
1661}
1662
1663// Used for testing purpose only.
1664extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
1665 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
1666}
1667
1668extern "C" void
1669RIL_register (const RIL_RadioFunctions *callbacks)
1670{
1671 int ret;
1672 int flags;
1673
1674 if (callbacks == NULL
1675 || ! (callbacks->version == RIL_VERSION || callbacks->version == 1)
1676 ) {
1677 LOGE(
1678 "RIL_register: RIL_RadioFunctions * null or invalid version"
1679 " (expected %d)", RIL_VERSION);
1680 return;
1681 }
1682
1683 if (s_registerCalled > 0) {
1684 LOGE("RIL_register has been called more than once. "
1685 "Subsequent call ignored");
1686 return;
1687 }
1688
1689 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
1690
1691 s_registerCalled = 1;
1692
1693 // Little self-check
1694
1695 for (int i = 0; i < (int)NUM_ELEMS(s_commands) ; i++) {
1696 assert(i == s_commands[i].requestNumber);
1697 }
1698
1699 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses) ; i++) {
1700 assert(i + RIL_UNSOL_RESPONSE_BASE
1701 == s_unsolResponses[i].requestNumber);
1702 }
1703
1704 // New rild impl calls RIL_startEventLoop() first
1705 // old standalone impl wants it here.
1706
1707 if (s_started == 0) {
1708 RIL_startEventLoop();
1709 }
1710
1711 // start listen socket
1712
1713#if 0
1714 ret = socket_local_server (SOCKET_NAME_RIL,
1715 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
1716
1717 if (ret < 0) {
1718 LOGE("Unable to bind socket errno:%d", errno);
1719 exit (-1);
1720 }
1721 s_fdListen = ret;
1722
1723#else
1724 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
1725 if (s_fdListen < 0) {
1726 LOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
1727 exit(-1);
1728 }
1729
1730 ret = listen(s_fdListen, 4);
1731
1732 if (ret < 0) {
1733 LOGE("Failed to listen on control socket '%d': %s",
1734 s_fdListen, strerror(errno));
1735 exit(-1);
1736 }
1737#endif
1738
1739
1740 /* note: non-persistent so we can accept only one connection at a time */
1741 ril_event_set (&s_listen_event, s_fdListen, false,
1742 listenCallback, NULL);
1743
1744 rilEventAddWakeup (&s_listen_event);
1745
1746#if 1
1747 // start debug interface socket
1748
1749 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
1750 if (s_fdDebug < 0) {
1751 LOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
1752 exit(-1);
1753 }
1754
1755 ret = listen(s_fdDebug, 4);
1756
1757 if (ret < 0) {
1758 LOGE("Failed to listen on ril debug socket '%d': %s",
1759 s_fdDebug, strerror(errno));
1760 exit(-1);
1761 }
1762
1763 ril_event_set (&s_debug_event, s_fdDebug, true,
1764 debugCallback, NULL);
1765
1766 rilEventAddWakeup (&s_debug_event);
1767#endif
1768
1769}
1770
1771static int
1772checkAndDequeueRequestInfo(struct RequestInfo *pRI)
1773{
1774 int ret = 0;
1775
1776 if (pRI == NULL) {
1777 return 0;
1778 }
1779
1780 pthread_mutex_lock(&s_pendingRequestsMutex);
1781
1782 for(RequestInfo **ppCur = &s_pendingRequests
1783 ; *ppCur != NULL
1784 ; ppCur = &((*ppCur)->p_next)
1785 ) {
1786 if (pRI == *ppCur) {
1787 ret = 1;
1788
1789 *ppCur = (*ppCur)->p_next;
1790 break;
1791 }
1792 }
1793
1794 pthread_mutex_unlock(&s_pendingRequestsMutex);
1795
1796 return ret;
1797}
1798
1799
1800extern "C" void
1801RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen)
1802{
1803 RequestInfo *pRI;
1804 int ret;
1805 size_t errorOffset;
1806
1807 pRI = (RequestInfo *)t;
1808
1809 if (!checkAndDequeueRequestInfo(pRI)) {
1810 LOGE ("RIL_onRequestComplete: invalid RIL_Token");
1811 return;
1812 }
1813
1814 if (pRI->local > 0) {
1815 // Locally issued command...void only!
1816 // response does not go back up the command socket
1817 LOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
1818
1819 goto done;
1820 }
1821
1822 appendPrintBuf("[%04d]< %s",
1823 pRI->token, requestToString(pRI->pCI->requestNumber));
1824
1825 if (pRI->cancelled == 0) {
1826 Parcel p;
1827
1828 p.writeInt32 (RESPONSE_SOLICITED);
1829 p.writeInt32 (pRI->token);
1830 errorOffset = p.dataPosition();
1831
1832 p.writeInt32 (e);
1833
1834 if (e == RIL_E_SUCCESS) {
1835 /* process response on success */
1836 ret = pRI->pCI->responseFunction(p, response, responselen);
1837
1838 /* if an error occurred, rewind and mark it */
1839 if (ret != 0) {
1840 p.setDataPosition(errorOffset);
1841 p.writeInt32 (ret);
1842 }
1843 } else {
1844 appendPrintBuf("%s returns %s", printBuf, failCauseToString(e));
1845 }
1846
1847 if (s_fdCommand < 0) {
1848 LOGD ("RIL onRequestComplete: Command channel closed");
1849 }
1850 sendResponse(p);
1851 }
1852
1853done:
1854 free(pRI);
1855}
1856
1857
1858static void
1859grabPartialWakeLock()
1860{
1861 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
1862}
1863
1864static void
1865releaseWakeLock()
1866{
1867 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
1868}
1869
1870/**
1871 * Timer callback to put us back to sleep before the default timeout
1872 */
1873static void
1874wakeTimeoutCallback (void *param)
1875{
1876 // We're using "param != NULL" as a cancellation mechanism
1877 if (param == NULL) {
1878 //LOGD("wakeTimeout: releasing wake lock");
1879
1880 releaseWakeLock();
1881 } else {
1882 //LOGD("wakeTimeout: releasing wake lock CANCELLED");
1883 }
1884}
1885
1886extern "C"
1887void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
1888 size_t datalen)
1889{
1890 int unsolResponseIndex;
1891 int ret;
1892 int64_t timeReceived = 0;
1893 bool shouldScheduleTimeout = false;
1894
1895 if (s_registerCalled == 0) {
1896 // Ignore RIL_onUnsolicitedResponse before RIL_register
1897 LOGW("RIL_onUnsolicitedResponse called before RIL_register");
1898 return;
1899 }
The Android Open Source Project34a51082009-03-05 14:34:37 -08001900
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001901 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
1902
1903 if ((unsolResponseIndex < 0)
1904 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
1905 LOGE("unsupported unsolicited response code %d", unsolResponse);
1906 return;
1907 }
1908
1909 // Grab a wake lock if needed for this reponse,
1910 // as we exit we'll either release it immediately
1911 // or set a timer to release it later.
1912 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
1913 case WAKE_PARTIAL:
1914 grabPartialWakeLock();
1915 shouldScheduleTimeout = true;
1916 break;
1917
1918 case DONT_WAKE:
1919 default:
1920 // No wake lock is grabed so don't set timeout
1921 shouldScheduleTimeout = false;
1922 break;
1923 }
1924
1925 // Mark the time this was received, doing this
1926 // after grabing the wakelock incase getting
1927 // the elapsedRealTime might cause us to goto
1928 // sleep.
1929 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
1930 timeReceived = elapsedRealtime();
1931 }
1932
1933 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
1934
1935 Parcel p;
1936
1937 p.writeInt32 (RESPONSE_UNSOLICITED);
1938 p.writeInt32 (unsolResponse);
1939
1940 ret = s_unsolResponses[unsolResponseIndex]
1941 .responseFunction(p, data, datalen);
1942 if (ret != 0) {
1943 // Problem with the response. Don't continue;
1944 goto error_exit;
1945 }
1946
1947 // some things get more payload
1948 switch(unsolResponse) {
1949 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
1950 p.writeInt32(s_callbacks.onStateRequest());
1951 appendPrintBuf("%s {%s}", printBuf,
1952 radioStateToString(s_callbacks.onStateRequest()));
1953 break;
1954
1955
1956 case RIL_UNSOL_NITZ_TIME_RECEIVED:
1957 // Store the time that this was received so the
1958 // handler of this message can account for
1959 // the time it takes to arrive and process. In
1960 // particular the system has been known to sleep
1961 // before this message can be processed.
1962 p.writeInt64(timeReceived);
1963 break;
1964 }
1965
1966 ret = sendResponse(p);
1967 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
1968
1969 // Unfortunately, NITZ time is not poll/update like everything
1970 // else in the system. So, if the upstream client isn't connected,
1971 // keep a copy of the last NITZ response (with receive time noted
1972 // above) around so we can deliver it when it is connected
1973
1974 if (s_lastNITZTimeData != NULL) {
1975 free (s_lastNITZTimeData);
1976 s_lastNITZTimeData = NULL;
1977 }
1978
1979 s_lastNITZTimeData = malloc(p.dataSize());
1980 s_lastNITZTimeDataSize = p.dataSize();
1981 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
1982 }
1983
1984 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
1985 // FIXME The java code should handshake here to release wake lock
1986
1987 if (shouldScheduleTimeout) {
1988 // Cancel the previous request
1989 if (s_last_wake_timeout_info != NULL) {
1990 s_last_wake_timeout_info->userParam = (void *)1;
1991 }
1992
1993 s_last_wake_timeout_info
1994 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
1995 &TIMEVAL_WAKE_TIMEOUT);
1996 }
1997
1998 // Normal exit
1999 return;
2000
2001error_exit:
2002 // There was an error and we've got the wake lock so release it.
2003 if (shouldScheduleTimeout) {
2004 releaseWakeLock();
2005 }
2006}
2007
2008/** FIXME generalize this if you track UserCAllbackInfo, clear it
2009 when the callback occurs
2010*/
2011static UserCallbackInfo *
2012internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
2013 const struct timeval *relativeTime)
2014
2015{
2016 struct timeval myRelativeTime;
2017 UserCallbackInfo *p_info;
2018
2019 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
2020
2021 p_info->p_callback = callback;
2022 p_info->userParam = param;
2023
2024 if (relativeTime == NULL) {
2025 /* treat null parameter as a 0 relative time */
2026 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
2027 } else {
2028 /* FIXME I think event_add's tv param is really const anyway */
2029 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
2030 }
2031
2032 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
2033
2034 ril_timer_add(&(p_info->event), &myRelativeTime);
2035
2036 triggerEvLoop();
2037 return p_info;
2038}
2039
2040
2041extern "C" void
2042RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
2043 const struct timeval *relativeTime)
2044{
2045 internalRequestTimedCallback (callback, param, relativeTime);
2046}
2047
2048const char *
2049failCauseToString(RIL_Errno e)
2050{
2051 switch(e) {
2052 case RIL_E_SUCCESS: return "E_SUCCESS";
2053 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";
2054 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
2055 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
2056 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
2057 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
2058 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
2059 case RIL_E_CANCELLED: return "E_CANCELLED";
2060 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
2061 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
2062 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
2063 default: return "<unknown error>";
2064 }
2065}
2066
2067const char *
2068radioStateToString(RIL_RadioState s)
2069{
2070 switch(s) {
2071 case RADIO_STATE_OFF: return "RADIO_OFF";
2072 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
2073 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
2074 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
2075 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
2076 default: return "<unknown state>";
2077 }
2078}
2079
2080const char *
2081callStateToString(RIL_CallState s)
2082{
2083 switch(s) {
2084 case RIL_CALL_ACTIVE : return "ACTIVE";
2085 case RIL_CALL_HOLDING: return "HOLDING";
2086 case RIL_CALL_DIALING: return "DIALING";
2087 case RIL_CALL_ALERTING: return "ALERTING";
2088 case RIL_CALL_INCOMING: return "INCOMING";
2089 case RIL_CALL_WAITING: return "WAITING";
2090 default: return "<unknown state>";
2091 }
2092}
2093
2094const char *
2095requestToString(int request)
2096{
2097/*
2098 cat libs/telephony/ril_commands.h \
2099 | egrep "^ *{RIL_" \
2100 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
2101
2102
2103 cat libs/telephony/ril_unsol_commands.h \
2104 | egrep "^ *{RIL_" \
2105 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
2106
2107*/
2108 switch(request) {
2109 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
2110 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
2111 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
2112 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
2113 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
2114 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
2115 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
2116 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
2117 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
2118 case RIL_REQUEST_DIAL: return "DIAL";
2119 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
2120 case RIL_REQUEST_HANGUP: return "HANGUP";
2121 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
2122 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
2123 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
2124 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
2125 case RIL_REQUEST_UDUB: return "UDUB";
2126 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
2127 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
2128 case RIL_REQUEST_REGISTRATION_STATE: return "REGISTRATION_STATE";
2129 case RIL_REQUEST_GPRS_REGISTRATION_STATE: return "GPRS_REGISTRATION_STATE";
2130 case RIL_REQUEST_OPERATOR: return "OPERATOR";
2131 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
2132 case RIL_REQUEST_DTMF: return "DTMF";
2133 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
2134 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
2135 case RIL_REQUEST_SETUP_DEFAULT_PDP: return "SETUP_DEFAULT_PDP";
2136 case RIL_REQUEST_SIM_IO: return "SIM_IO";
2137 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
2138 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
2139 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
2140 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
2141 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
2142 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
2143 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
2144 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
2145 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
2146 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
2147 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
2148 case RIL_REQUEST_ANSWER: return "ANSWER";
2149 case RIL_REQUEST_DEACTIVATE_DEFAULT_PDP: return "DEACTIVATE_DEFAULT_PDP";
2150 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
2151 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
2152 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
2153 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
2154 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
2155 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
2156 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
2157 case RIL_REQUEST_DTMF_START: return "DTMF_START";
2158 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
2159 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
2160 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
2161 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
2162 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
2163 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
2164 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
2165 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
2166 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
2167 case RIL_REQUEST_LAST_PDP_FAIL_CAUSE: return "LAST_PDP_FAIL_CAUSE";
2168 case RIL_REQUEST_PDP_CONTEXT_LIST: return "PDP_CONTEXT_LIST";
2169 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
2170 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
2171 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
2172 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
2173 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
2174 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
2175 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
2176 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
2177 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
2178 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
2179 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
2180 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
2181 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
2182
2183 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
2184 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
2185 case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_NETWORK_STATE_CHANGED";
2186 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
2187 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
2188 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
2189 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
2190 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
2191 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
2192 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
2193 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
2194 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
2195 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
2196 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
2197 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
2198 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
2199 case RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED: return "UNSOL_PDP_CONTEXT_LIST_CHANGED";
2200 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
The Android Open Source Project34a51082009-03-05 14:34:37 -08002201 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002202 default: return "<unknown request>";
2203 }
2204}
2205
2206} /* namespace android */