auto import from //depot/cupcake/@135843
diff --git a/include/telephony/ril.h b/include/telephony/ril.h
deleted file mode 100644
index 57f842f..0000000
--- a/include/telephony/ril.h
+++ /dev/null
@@ -1,2327 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * ISSUES:
- * - SMS retransmit (specifying TP-Message-ID)
- *
- */
-
-/**
- * TODO
- *
- * Supp Service Notification (+CSSN)
- * GPRS PDP context deactivate notification
- *  
- */
-
-
-#ifndef ANDROID_RIL_H 
-#define ANDROID_RIL_H 1
-
-#include <stdlib.h>
-#include <sys/time.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define RIL_VERSION 2
-
-typedef void * RIL_Token;
-
-typedef enum {
-    RIL_E_SUCCESS = 0,
-    RIL_E_RADIO_NOT_AVAILABLE = 1,     /* If radio did not start or is resetting */
-    RIL_E_GENERIC_FAILURE = 2,
-    RIL_E_PASSWORD_INCORRECT = 3,      /* for PIN/PIN2 methods only! */
-    RIL_E_SIM_PIN2 = 4,                /* Operation requires SIM PIN2 to be entered */
-    RIL_E_SIM_PUK2 = 5,                /* Operation requires SIM PIN2 to be entered */
-    RIL_E_REQUEST_NOT_SUPPORTED = 6,
-    RIL_E_CANCELLED = 7,
-    RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL = 8, /* data ops are not allowed during voice
-                                                   call on a Class C GPRS device */
-    RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW = 9,  /* data ops are not allowed before device
-                                                   registers in network */
-    RIL_E_SMS_SEND_FAIL_RETRY = 10		/* fail to send sms and need retry */	
-} RIL_Errno;
-
-typedef enum {
-    RIL_CALL_ACTIVE = 0,
-    RIL_CALL_HOLDING = 1,
-    RIL_CALL_DIALING = 2,    /* MO call only */
-    RIL_CALL_ALERTING = 3,   /* MO call only */
-    RIL_CALL_INCOMING = 4,   /* MT call only */
-    RIL_CALL_WAITING = 5     /* MT call only */
-} RIL_CallState;
-
-typedef enum {
-    RADIO_STATE_OFF = 0,          /* Radio explictly powered off (eg CFUN=0) */
-    RADIO_STATE_UNAVAILABLE = 1,  /* Radio unavailable (eg, resetting or not booted) */
-    RADIO_STATE_SIM_NOT_READY = 2,      /* Radio is on, but the SIM interface is not ready */
-    RADIO_STATE_SIM_LOCKED_OR_ABSENT = 3, /* SIM PIN locked, PUK required, network 
-                               personalization locked, or SIM absent */
-    RADIO_STATE_SIM_READY = 4           /* Radio is on and SIM interface is available */
-} RIL_RadioState;
-
-typedef struct {
-    RIL_CallState   state;
-    int             index;      /* GSM Index for use with, eg, AT+CHLD */
-    int             toa;        /* type of address, eg 145 = intl */
-    char            isMpty;     /* nonzero if is mpty call */
-    char            isMT;       /* nonzero if call is mobile terminated */
-    char            als;        /* ALS line indicator if available 
-                                   (0 = line 1) */
-    char            isVoice;    /* nonzero if this is is a voice call */
-
-    char *          number;     /* phone number */
-} RIL_Call;
-
-typedef struct {
-    int             cid;        /* Context ID */
-    int             active;     /* nonzero if context is active */
-    char *          type;       /* X.25, IP, IPV6, etc. */
-    char *          apn;
-    char *          address;
-} RIL_PDP_Context_Response;
-
-typedef struct {
-    int messageRef;   /*TP-Message-Reference*/
-    char *ackPDU;     /* or NULL if n/a */
-} RIL_SMS_Response;
-
-/** Used by RIL_REQUEST_WRITE_SMS_TO_SIM */
-typedef struct {
-    int status;     /* Status of message.  See TS 27.005 3.1, "<stat>": */
-                    /*      0 = "REC UNREAD"    */
-                    /*      1 = "REC READ"      */
-                    /*      2 = "STO UNSENT"    */
-                    /*      3 = "STO SENT"      */
-    char * pdu;     /* PDU of message to write, as a hex string. */
-    char * smsc;    /* SMSC address in GSM BCD format prefixed by a length byte
-                       (as expected by TS 27.005) or NULL for default SMSC */
-} RIL_SMS_WriteArgs;
-
-/** Used by RIL_REQUEST_DIAL */
-typedef struct {
-    char * address;
-    int clir;
-            /* (same as 'n' paremeter in TS 27.007 7.7 "+CLIR"
-             * clir == 0 on "use subscription default value"
-             * clir == 1 on "CLIR invocation" (restrict CLI presentation)
-             * clir == 2 on "CLIR suppression" (allow CLI presentation)
-             */
-
-} RIL_Dial;
-
-typedef struct {
-    int command;    /* one of the commands listed for TS 27.007 +CRSM*/
-    int fileid;     /* EF id */
-    char *path;     /* "pathid" from TS 27.007 +CRSM command.
-                       Path is in hex asciii format eg "7f205f70"
-                     */
-    int p1;
-    int p2;
-    int p3;
-    char *data;     /* May be NULL*/
-    char *pin2;     /* May be NULL*/
-} RIL_SIM_IO;
-
-typedef struct {
-    int sw1;
-    int sw2;
-    char *simResponse;  /* In hex string format ([a-fA-F0-9]*). */
-} RIL_SIM_IO_Response;
-
-/* See also com.android.internal.telephony.gsm.CallForwardInfo */
-
-typedef struct {
-    int             status;     /*
-                                 * For RIL_REQUEST_QUERY_CALL_FORWARD_STATUS
-                                 * status 1 = active, 0 = not active
-                                 *
-                                 * For RIL_REQUEST_SET_CALL_FORWARD:
-                                 * status is:
-                                 * 0 = disable
-                                 * 1 = enable
-                                 * 2 = interrogate
-                                 * 3 = registeration
-                                 * 4 = erasure
-                                 */
-
-    int             reason;     /* from TS 27.007 7.11 "reason" */
-    int             serviceClass;/* From 27.007 +CCFC/+CLCK "class"
-                                    See table for Android mapping from
-                                    MMI service code 
-				    0 means user doesn't input class */
-    int             toa;        /* "type" from TS 27.007 7.11 */
-    char *          number;     /* "number" from TS 27.007 7.11. May be NULL */
-    int             timeSeconds; /* for CF no reply only */
-}RIL_CallForwardInfo;
-
-typedef struct {
-   char * cid;         /* Cell Id (as described in TS 27.005) in 16 bits in GSM
-                        * Primary Scrambling Code (as described in TS 25.331)
-                        *         in 9 bits in UMTS 
-                        * Valid values are hexadecimal 0x0000 - 0xffff.
-                        */
-   int    rssi;        /* Received RSSI in 2G,
-                        * Level index of CPICH Received Signal Code Power in 3G
-                        */
-} RIL_NeighboringCell;
-
-/* See RIL_REQUEST_LAST_CALL_FAIL_CAUSE */
-typedef enum {
-    CALL_FAIL_NORMAL = 16,
-    CALL_FAIL_BUSY = 17,
-    CALL_FAIL_CONGESTION = 34,
-    CALL_FAIL_ACM_LIMIT_EXCEEDED = 68,
-    CALL_FAIL_CALL_BARRED = 240,
-    CALL_FAIL_FDN_BLOCKED = 241,
-    CALL_FAIL_ERROR_UNSPECIFIED = 0xffff
-} RIL_LastCallFailCause;
-
-/* See RIL_REQUEST_LAST_PDP_FAIL_CAUSE */
-typedef enum {
-    PDP_FAIL_BARRED = 8,         /* no retry; prompt user */
-    PDP_FAIL_BAD_APN = 27,       /* no retry; prompt user */
-    PDP_FAIL_USER_AUTHENTICATION = 29, /* no retry; prompt user */
-    PDP_FAIL_SERVICE_OPTION_NOT_SUPPORTED = 32,  /*no retry; prompt user */
-    PDP_FAIL_SERVICE_OPTION_NOT_SUBSCRIBED = 33, /*no retry; prompt user */
-    PDP_FAIL_ERROR_UNSPECIFIED = 0xffff  /* This and all other cases: retry silently */
-} RIL_LastPDPActivateFailCause;
-
-/* Used by RIL_UNSOL_SUPP_SVC_NOTIFICATION */
-typedef struct {
-    int     notificationType;   /*
-                                 * 0 = MO intermediate result code
-                                 * 1 = MT unsolicited result code
-                                 */
-    int     code;               /* See 27.007 7.17
-                                   "code1" for MO
-                                   "code2" for MT. */
-    int     index;              /* CUG index. See 27.007 7.17. */
-    int     type;               /* "type" from 27.007 7.17 (MT only). */
-    char *  number;             /* "number" from 27.007 7.17
-                                   (MT only, may be NULL). */
-} RIL_SuppSvcNotification;
-
-/* see RIL_REQUEST_GET_SIM_STATUS */
-#define RIL_SIM_ABSENT      		0
-#define RIL_SIM_NOT_READY   		1
-/* RIL_SIM_READY means that the radio state is RADIO_STATE_SIM_READY. 
- * This is more
- * than "+CPIN: READY". It also means the radio is ready for SIM I/O
- */
-#define RIL_SIM_READY       		2
-#define RIL_SIM_PIN         		3
-#define RIL_SIM_PUK         		4
-#define RIL_SIM_NETWORK_PERSONALIZATION 5
-
-/* The result of a SIM refresh, returned in data[0] of RIL_UNSOL_SIM_REFRESH */
-typedef enum {
-    /* A file on SIM has been updated.  data[1] contains the EFID. */
-    SIM_FILE_UPDATE = 0,
-    /* SIM initialized.  All files should be re-read. */
-    SIM_INIT = 1,
-    /* SIM reset.  SIM power required, SIM may be locked and all files should be re-read. */
-    SIM_RESET = 2
-} RIL_SimRefreshResult;
-
-/** 
- * RIL_REQUEST_GET_SIM_STATUS
- *
- * Requests status of the SIM interface and the SIM card
- * 
- * "data" is NULL
- *
- * "response" must be an int * pointing to RIL_SIM_* constant 
- * This should always succeed (RIL_SUCCESS)
- *
- * If the radio is off or unavailable, return RIL_SIM_NOT_READY 
- *
- * Please note: RIL_SIM_READY means that the radio state 
- * is RADIO_STATE_SIM_READY.   This is more than "+CPIN: READY". 
- * It also means the radio is ready for SIM I/O
- *
- * Valid errors:
- *  Must never fail
- */
-#define RIL_REQUEST_GET_SIM_STATUS 1
-
-/**
- * RIL_REQUEST_ENTER_SIM_PIN
- *
- * Supplies SIM PIN. Only called if SIM status is RIL_SIM_PIN
- *
- * "data" is const char **
- * ((const char **)data)[0] is PIN value
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- * SUCCESS 
- * RADIO_NOT_AVAILABLE (radio resetting)
- * GENERIC_FAILURE
- * PASSWORD_INCORRECT
- */
-
-#define RIL_REQUEST_ENTER_SIM_PIN 2
-
-
-/**
- * RIL_REQUEST_ENTER_SIM_PUK
- *
- * Supplies SIM PUK and new PIN. 
- *
- * "data" is const char **
- * ((const char **)data)[0] is PUK value
- * ((const char **)data)[1] is new PIN value
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *  PASSWORD_INCORRECT
- *     (PUK is invalid)
- */
-
-#define RIL_REQUEST_ENTER_SIM_PUK 3
-
-/**
- * RIL_REQUEST_ENTER_SIM_PIN2
- *
- * Supplies SIM PIN2. Only called following operation where SIM_PIN2 was
- * returned as a a failure from a previous operation.
- *
- * "data" is const char **
- * ((const char **)data)[0] is PIN2 value
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *  PASSWORD_INCORRECT
- */
-
-#define RIL_REQUEST_ENTER_SIM_PIN2 4
-
-/**
- * RIL_REQUEST_ENTER_SIM_PUK2
- *
- * Supplies SIM PUK2 and new PIN2. 
- *
- * "data" is const char **
- * ((const char **)data)[0] is PUK2 value
- * ((const char **)data)[1] is new PIN2 value
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *  PASSWORD_INCORRECT
- *     (PUK2 is invalid)
- */
-
-#define RIL_REQUEST_ENTER_SIM_PUK2 5
-
-/**
- * RIL_REQUEST_CHANGE_SIM_PIN
- *
- * Supplies old SIM PIN and new PIN. 
- *
- * "data" is const char **
- * ((const char **)data)[0] is old PIN value
- * ((const char **)data)[1] is new PIN value
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *  PASSWORD_INCORRECT
- *     (old PIN is invalid)
- *      
- */
-
-#define RIL_REQUEST_CHANGE_SIM_PIN 6
-
-
-/**
- * RIL_REQUEST_CHANGE_SIM_PIN2
- *
- * Supplies old SIM PIN2 and new PIN2. 
- *
- * "data" is const char **
- * ((const char **)data)[0] is old PIN2 value
- * ((const char **)data)[1] is new PIN2 value
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *  PASSWORD_INCORRECT
- *     (old PIN2 is invalid)
- *      
- */
-
-#define RIL_REQUEST_CHANGE_SIM_PIN2 7
-
-/**
- * RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION
- *
- * Requests that network personlization be deactivated
- *
- * "data" is const char **
- * ((const char **)(data))[0]] is network depersonlization code
- *
- * "response" must be NULL
- *
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *  PASSWORD_INCORRECT
- *     (code is invalid)
- */
-
-#define RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION 8
-
-/**
- * RIL_REQUEST_GET_CURRENT_CALLS 
- *
- * Requests current call list
- *
- * "data" is NULL
- *
- * "response" must be a "const RIL_Call **"
- * 
- * Valid errors:
- *  
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- *      (request will be made again in a few hundred msec)
- */
-
-#define RIL_REQUEST_GET_CURRENT_CALLS 9
-
-
-/** 
- * RIL_REQUEST_DIAL
- *
- * Initiate voice call
- *
- * "data" is const RIL_Dial *
- * "response" is NULL
- *  
- * This method is never used for supplementary service codes
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_DIAL 10
-
-/**
- * RIL_REQUEST_GET_IMSI
- *
- * Get the SIM IMSI
- *
- * Only valid when radio state is "RADIO_STATE_SIM_READY"
- *
- * "data" is NULL
- * "response" is a const char * containing the IMSI
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_GET_IMSI 11
-
-/**
- * RIL_REQUEST_HANGUP
- *
- * Hang up a specific line (like AT+CHLD=1x)
- *
- * "data" is an int * 
- * (int *)data)[0] contains GSM call index (value of 'x' in CHLD above)
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_HANGUP 12
-
-/**
- * RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND
- *
- * Hang up waiting or held (like AT+CHLD=0)
- *
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND 13
-
-/**
- * RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
- *
- * Hang up waiting or held (like AT+CHLD=1)
- *
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND 14
-
-/**
- * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE
- *
- * Switch waiting or holding call and active call (like AT+CHLD=2)
- *
- * State transitions should be is follows:
- *
- * If call 1 is waiting and call 2 is active, then if this re
- *
- *   BEFORE                               AFTER
- * Call 1   Call 2                 Call 1       Call 2
- * ACTIVE   HOLDING                HOLDING     ACTIVE
- * ACTIVE   WAITING                HOLDING     ACTIVE
- * HOLDING  WAITING                HOLDING     ACTIVE
- * ACTIVE   IDLE                   HOLDING     IDLE
- * IDLE     IDLE                   IDLE        IDLE
- *
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE 15
-#define RIL_REQUEST_SWITCH_HOLDING_AND_ACTIVE 15
-
-/**
- * RIL_REQUEST_CONFERENCE
- *
- * Conference holding and active (like AT+CHLD=3)
-
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_CONFERENCE 16
-
-/**
- * RIL_REQUEST_UDUB
- *
- * Send UDUB (user determined used busy) to ringing or 
- * waiting call answer)(RIL_BasicRequest r);
- *
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_UDUB 17
-
-/**
- * RIL_REQUEST_LAST_CALL_FAIL_CAUSE
- *
- * Requests the failure cause code for the most recently terminated call
- *
- * "data" is NULL
- * "response" is a "int *"
- * ((int *)response)[0] is an integer cause code defined in TS 24.008
- *   Annex H or close approximation
- *
- * If the implementation does not have access to the exact cause codes,
- * then it should return one of the values listed in RIL_LastCallFailCause,
- * as the UI layer needs to distinguish these cases for tone generation or
- * error notification.
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_LAST_PDP_FAIL_CAUSE
- */
-#define RIL_REQUEST_LAST_CALL_FAIL_CAUSE 18
-
-/**
- * RIL_REQUEST_SIGNAL_STRENGTH
- *
- * Requests current signal strength and bit error rate
- *
- * Must succeed if radio is on.
- *
- * "data" is NULL
- * "response" is an "int *"
- * ((int *)response)[0] is received signal strength (0-31, 99)
- * ((int *)response)[1] is bit error rate (0-7, 99)
- *  as defined in TS 27.007 8.5
- *  Other values (eg -1) are not legal
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- */
-
-#define RIL_REQUEST_SIGNAL_STRENGTH 19
-/**
- * RIL_REQUEST_REGISTRATION_STATE
- *
- * Request current registration state
- *
- * "data" is NULL
- * "response" is a "char **"
- * ((const char **)response)[0] is registration state 0-5 from TS 27.007 7.2
- * ((const char **)response)[1] is LAC if registered or NULL if not
- * ((const char **)response)[2] is CID if registered or NULL if not
- *
- * LAC and CID are in hexadecimal format.
- * valid LAC are 0x0000 - 0xffff
- * valid CID are 0x00000000 - 0x0fffffff
- *     In GSM, CID is Cell ID (as described in TS 27.007) in 16 bits
- *     In UMTS, CID is UMTS Cell Identity (as described in TS 25.331) in 28 bits
- * 
- * Please note that registration state 4 ("unknown") is treated 
- * as "out of service" in the Android telephony system
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_REGISTRATION_STATE 20
-
-/**
- * RIL_REQUEST_GPRS_REGISTRATION_STATE
- *
- * Request current GPRS registration state
- *
- * "data" is NULL
- * "response" is a "char **"
- * ((const char **)response)[0] is registration state 0-5 from TS 27.007 7.2
- * ((const char **)response)[1] is LAC if registered or NULL if not
- * ((const char **)response)[2] is CID if registered or NULL if not
- * ((const char **)response)[3] indicates the available radio technology, where:
- *      0 == unknown
- *      1 == GPRS only
- *      2 == EDGE
- *      3 == UMTS
- *
- * LAC and CID are in hexadecimal format.
- * valid LAC are 0x0000 - 0xffff
- * valid CID are 0x00000000 - 0x0fffffff
- * 
- * Please note that registration state 4 ("unknown") is treated 
- * as "out of service" in the Android telephony system
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_GPRS_REGISTRATION_STATE 21
-
-/**
- * RIL_REQUEST_OPERATOR
- *
- * Request current operator ONS or EONS
- *
- * "data" is NULL
- * "response" is a "const char **"
- * ((const char **)response)[0] is long alpha ONS or EONS 
- *                                  or NULL if unregistered
- *
- * ((const char **)response)[1] is short alpha ONS or EONS 
- *                                  or NULL if unregistered
- * ((const char **)response)[2] is 5 or 6 digit numeric code (MCC + MNC)
- *                                  or NULL if unregistered
- *                                  
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_OPERATOR 22
-
-/**
- * RIL_REQUEST_RADIO_POWER
- *
- * Toggle radio on and off (for "airplane" mode)
- * "data" is int *
- * ((int *)data)[0] is > 0 for "Radio On"
- * ((int *)data)[0] is == 0 for "Radio Off"
- *
- * "response" is NULL
- *
- * Turn radio on if "on" > 0
- * Turn radio off if "on" == 0
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_RADIO_POWER 23
-
-/**
- * RIL_REQUEST_DTMF
- *
- * Send a DTMF tone
- *
- * If the implementation is currently playing a tone requested via
- * RIL_REQUEST_DTMF_START, that tone should be cancelled and the new tone
- * should be played instead
- *
- * "data" is a char *
- * ((char *)data)[0] is a single character with one of 12 values: 0-9,*,#
- * ((char *)data)[1] is a single character with one of 3 values:
- *    'S' -- tone should be played for a short time
- *    'L' -- tone should be played for a long time
- * "response" is NULL
- * 
- * FIXME should this block/mute microphone?
- * How does this interact with local DTMF feedback?
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_DTMF_STOP, RIL_REQUEST_DTMF_START
- *
- */
-#define RIL_REQUEST_DTMF 24
-
-/**
- * RIL_REQUEST_SEND_SMS
- * 
- * Send an SMS message
- *
- * "data" is const char **
- * ((const char **)data)[0] is SMSC address in GSM BCD format prefixed
- *      by a length byte (as expected by TS 27.005) or NULL for default SMSC
- * ((const char **)data)[1] is SMS in PDU format as an ASCII hex string
- *      less the SMSC address
- *      TP-Layer-Length is be "strlen(((const char **)data)[1])/2"
- *
- * "response" is a const RIL_SMS_Response *
- *
- * Based on the return error, caller decides to resend if sending sms
- * fails. SMS_SEND_FAIL_RETRY means retry (i.e. error cause is 332) 
- * and GENERIC_FAILURE means no retry (i.e. error cause is 500)
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  SMS_SEND_FAIL_RETRY
- *  GENERIC_FAILURE
- *
- * FIXME how do we specify TP-Message-Reference if we need to resend?
- */
-#define RIL_REQUEST_SEND_SMS 25
-
-
-/**
- * RIL_REQUEST_SEND_SMS_EXPECT_MORE
- * 
- * Send an SMS message. Identical to RIL_REQUEST_SEND_SMS,
- * except that more messages are expected to be sent soon. If possible,
- * keep SMS relay protocol link open (eg TS 27.005 AT+CMMS command)
- *
- * "data" is const char **
- * ((const char **)data)[0] is SMSC address in GSM BCD format prefixed
- *      by a length byte (as expected by TS 27.005) or NULL for default SMSC
- * ((const char **)data)[1] is SMS in PDU format as an ASCII hex string
- *      less the SMSC address
- *      TP-Layer-Length is be "strlen(((const char **)data)[1])/2"
- *
- * "response" is a const RIL_SMS_Response *
- *
- * Based on the return error, caller decides to resend if sending sms
- * fails. SMS_SEND_FAIL_RETRY means retry (i.e. error cause is 332) 
- * and GENERIC_FAILURE means no retry (i.e. error cause is 500)
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  SMS_SEND_FAIL_RETRY
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_SEND_SMS_EXPECT_MORE 26
-
-
-/**
- * RIL_REQUEST_SETUP_DEFAULT_PDP
- *
- * Configure and activate PDP context (CID 1) for default IP connection 
- *
- * Android Telephony layer will start up pppd process on specified
- * tty when this request responded to.
- *
- * "data" is a const char **
- * ((const char **)data)[0] is the APN to connect to
- * ((const char **)data)[1] is the username, or NULL
- * ((const char **)data)[2] is the password, or NULL
- *
- * "response" is a char **
- * ((char **)response)[0] indicating PDP CID, which is generated by RIL
- * ((char **)response)[1] indicating the network interface name
- * ((char **)response)[2] indicating the IP address for this interface
- *
- * FIXME may need way to configure QoS settings
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_DEACTIVATE_DEFAULT_PDP
- */
-
-#define RIL_REQUEST_SETUP_DEFAULT_PDP 27
-
-
-
-/**
- * RIL_REQUEST_SIM_IO
- *
- * Request SIM I/O operation.
- * This is similar to the TS 27.007 "restricted SIM" operation
- * where it assumes all of the EF selection will be done by the
- * callee.
- *
- * "data" is a const RIL_SIM_IO *
- * Please note that RIL_SIM_IO has a "PIN2" field which may be NULL,
- * or may specify a PIN2 for operations that require a PIN2 (eg
- * updating FDN records)
- *
- * "response" is a const RIL_SIM_IO_Response *
- *
- * Arguments and responses that are unused for certain
- * values of "command" should be ignored or set to NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *  SIM_PIN2
- *  SIM_PUK2
- */
-#define RIL_REQUEST_SIM_IO 28
-
-/**
- * RIL_REQUEST_SEND_USSD
- *
- * Send a USSD message
- *
- * If a USSD session already exists, the message should be sent in the
- * context of that session. Otherwise, a new session should be created.
- *
- * The network reply should be reported via RIL_UNSOL_ON_USSD
- *
- * Only one USSD session may exist at a time, and the session is assumed
- * to exist until:
- *   a) The android system invokes RIL_REQUEST_CANCEL_USSD
- *   b) The implementation sends a RIL_UNSOL_ON_USSD with a type code
- *      of "0" (USSD-Notify/no further action) or "2" (session terminated)
- *
- * "data" is a const char * containing the USSD request in UTF-8 format
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_CANCEL_USSD, RIL_UNSOL_ON_USSD
- */
-
-#define RIL_REQUEST_SEND_USSD 29
-
-/**
- * RIL_REQUEST_CANCEL_USSD
- * 
- * Cancel the current USSD session if one exists
- *
- * "data" is null
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE 
- */
-
-#define RIL_REQUEST_CANCEL_USSD 30
-
-/**  
- * RIL_REQUEST_GET_CLIR
- *
- * Gets current CLIR status
- * "data" is NULL
- * "response" is int *
- * ((int *)data)[0] is "n" parameter from TS 27.007 7.7
- * ((int *)data)[1] is "m" parameter from TS 27.007 7.7
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_GET_CLIR 31
-
-/**
- * RIL_REQUEST_SET_CLIR
- *
- * "data" is int *
- * ((int *)data)[0] is "n" parameter from TS 27.007 7.7
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SET_CLIR 32
-
-/**
- * RIL_REQUEST_QUERY_CALL_FORWARD_STATUS
- *
- * "data" is const RIL_CallForwardInfo *
- *
- * "response" is const RIL_CallForwardInfo **
- * "response" points to an array of RIL_CallForwardInfo *'s, one for
- * each distinct registered phone number.
- *
- * For example, if data is forwarded to +18005551212 and voice is forwarded
- * to +18005559999, then two separate RIL_CallForwardInfo's should be returned
- * 
- * If, however, both data and voice are forwarded to +18005551212, then
- * a single RIL_CallForwardInfo can be returned with the service class
- * set to "data + voice = 3")
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_QUERY_CALL_FORWARD_STATUS 33
-
-
-/**
- * RIL_REQUEST_SET_CALL_FORWARD
- *
- * Configure call forward rule
- *
- * "data" is const RIL_CallForwardInfo *
- * "response" is NULL
- *  
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SET_CALL_FORWARD 34
-
-
-/**
- * RIL_REQUEST_QUERY_CALL_WAITING
- *
- * Query current call waiting state
- *
- * "data" is const int *
- * ((const int *)data)[0] is the TS 27.007 service class to query.
- * "response" is a const int *
- * ((const int *)response)[0] is 0 for "disabled" and 1 for "enabled"
- *
- * If ((const int *)response)[0] is = 1, then ((const int *)response)[1]
- * must follow, with the TS 27.007 service class bit vector of services
- * for which call waiting is enabled.
- *
- * For example, if ((const int *)response)[0]  is 1 and 
- * ((const int *)response)[1] is 3, then call waiting is enabled for data
- * and voice and disabled for everything else
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_QUERY_CALL_WAITING 35
-
-
-/**
- * RIL_REQUEST_SET_CALL_WAITING
- *
- * Configure current call waiting state
- *
- * "data" is const int *
- * ((const int *)data)[0] is 0 for "disabled" and 1 for "enabled"
- * ((const int *)data)[1] is the TS 27.007 service class bit vector of
- *                           services to modify
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SET_CALL_WAITING 36
-
-/**
- * RIL_REQUEST_SMS_ACKNOWLEDGE
- *
- * Acknowledge successful or failed receipt of SMS previously indicated
- * via RIL_UNSOL_RESPONSE_NEW_SMS 
- *
- * "data" is int *
- * ((int *)data)[0] is "1" on successful receipt 
- *                  (basically, AT+CNMA=1 from TS 27.005
- * ((int *)data)[0] is "0" on failed receipt 
- *                  (basically, AT+CNMA=2 from TS 27.005)
- *
- * "response" is NULL
- *
- * FIXME would like request that specified RP-ACK/RP-ERROR PDU
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SMS_ACKNOWLEDGE  37
-
-/**
- * RIL_REQUEST_GET_IMEI
- *
- * Get the device IMEI, including check digit
- *
- * Valid when RadioState is not RADIO_STATE_UNAVAILABLE
- *
- * "data" is NULL
- * "response" is a const char * containing the IMEI
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_GET_IMEI 38
-
-/**
- * RIL_REQUEST_GET_IMEISV
- *
- * Get the device IMEISV, which should be two decimal digits
- *
- * Valid when RadioState is not RADIO_STATE_UNAVAILABLE
- *
- * "data" is NULL
- * "response" is a const char * containing the IMEISV
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_GET_IMEISV 39
-
-
-/**
- * RIL_REQUEST_ANSWER
- *
- * Answer incoming call
- *
- * Will not be called for WAITING calls.
- * RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE will be used in this case
- * instead
- *
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_ANSWER 40
-
-/**
- * RIL_REQUEST_DEACTIVATE_DEFAULT_PDP
- *
- * Deactivate PDP context created by RIL_REQUEST_SETUP_DEFAULT_PDP
- *
- * "data" is const char **
- * ((char**)data)[0] indicating PDP CID
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_SETUP_DEFAULT_PDP
- */
-
-#define RIL_REQUEST_DEACTIVATE_DEFAULT_PDP 41
-
-/**
- * RIL_REQUEST_QUERY_FACILITY_LOCK
- *
- * Query the status of a facility lock state
- *
- * "data" is const char **
- * ((const char **)data)[0] is the facility string code from TS 27.007 7.4  
- *                      (eg "AO" for BAOC, "SC" for SIM lock)
- * ((const char **)data)[1] is the password, or "" if not required
- * ((const char **)data)[2] is the TS 27.007 service class bit vector of
- *                           services to query
- *
- * "response" is an int *
- * ((const int *)response) 0 is the TS 27.007 service class bit vector of
- *                           services for which the specified barring facility 
- *                           is active. "0" means "disabled for all"
- * 
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_QUERY_FACILITY_LOCK 42
-
-/**
- * RIL_REQUEST_SET_FACILITY_LOCK
- *
- * Enable/disable one facility lock
- *
- * "data" is const char **
- *
- * ((const char **)data)[0] = facility string code from TS 27.007 7.4
- * (eg "AO" for BAOC)
- * ((const char **)data)[1] = "0" for "unlock" and "1" for "lock"
- * ((const char **)data)[2] = password
- * ((const char **)data)[3] = string representation of decimal TS 27.007
- *                            service class bit vector. Eg, the string
- *                            "1" means "set this facility for voice services"
- *
- * "response" is NULL 
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_SET_FACILITY_LOCK 43
-
-/**
- * RIL_REQUEST_CHANGE_BARRING_PASSWORD
- *
- * Change call barring facility password
- *
- * "data" is const char **
- *
- * ((const char **)data)[0] = facility string code from TS 27.007 7.4
- * (eg "AO" for BAOC)
- * ((const char **)data)[1] = old password
- * ((const char **)data)[2] = new password
- *
- * "response" is NULL 
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_CHANGE_BARRING_PASSWORD 44
-
-/**
- * RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE
- *
- * Query current network selectin mode
- *
- * "data" is NULL
- *
- * "response" is int *
- * ((const int *)response)[0] is
- *     0 for automatic selection
- *     1 for manual selection
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE 45
-
-/**
- * RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC
- *
- * Specify that the network should be selected automatically
- *
- * "data" is NULL
- * "response" is NULL
- *
- * This request must not respond until the new operator is selected 
- * and registered
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC 46
-
-/**
- * RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL
- *
- * Manually select a specified network.
- *
- * The radio baseband/RIL implementation is expected to fall back to 
- * automatic selection mode if the manually selected network should go
- * out of range in the future.
- *
- * "data" is const char * specifying MCCMNC of network to select (eg "310170")
- * "response" is NULL
- *
- * This request must not respond until the new operator is selected 
- * and registered
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL 47
-
-/**
- * RIL_REQUEST_QUERY_AVAILABLE_NETWORKS
- *
- * Scans for available networks
- *
- * "data" is NULL
- * "response" is const char ** that should be an array of n*4 strings, where
- *    n is the number of available networks
- * For each available network:
- *
- * ((const char **)response)[n+0] is long alpha ONS or EONS 
- * ((const char **)response)[n+1] is short alpha ONS or EONS 
- * ((const char **)response)[n+2] is 5 or 6 digit numeric code (MCC + MNC)
- * ((const char **)response)[n+3] is a string value of the status:
- *           "unknown"
- *           "available"
- *           "current"
- *           "forbidden"
- *
- * This request must not respond until the new operator is selected 
- * and registered
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 48
-
-/**
- * RIL_REQUEST_DTMF_START
- *
- * Start playing a DTMF tone. Continue playing DTMF tone until 
- * RIL_REQUEST_DTMF_STOP is received 
- *
- * If a RIL_REQUEST_DTMF_START is received while a tone is currently playing,
- * it should cancel the previous tone and play the new one.
- * 
- * "data" is a char *
- * ((char *)data)[0] is a single character with one of 12 values: 0-9,*,#
- * "response" is NULL
- * 
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_DTMF, RIL_REQUEST_DTMF_STOP
- */
-#define RIL_REQUEST_DTMF_START 49
-
-/**
- * RIL_REQUEST_DTMF_STOP
- *
- * Stop playing a currently playing DTMF tone.
- * 
- * "data" is NULL
- * "response" is NULL
- * 
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_DTMF, RIL_REQUEST_DTMF_START
- */
-#define RIL_REQUEST_DTMF_STOP 50
-
-/**
- * RIL_REQUEST_BASEBAND_VERSION
- *
- * Return string value indicating baseband version, eg
- * response from AT+CGMR
- * 
- * "data" is NULL
- * "response" is const char * containing version string for log reporting
- * 
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_BASEBAND_VERSION 51
-
-/**
- * RIL_REQUEST_SEPARATE_CONNECTION
- *
- * Separate a party from a multiparty call placing the multiparty call
- * (less the specified party) on hold and leaving the specified party 
- * as the only other member of the current (active) call
- *
- * Like AT+CHLD=2x
- *
- * See TS 22.084 1.3.8.2 (iii)
- * TS 22.030 6.5.5 "Entering "2X followed by send"
- * TS 27.007 "AT+CHLD=2x"
- * 
- * "data" is an int * 
- * (int *)data)[0] contains GSM call index (value of 'x' in CHLD above)
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SEPARATE_CONNECTION 52
-
-
-/**
- * RIL_REQUEST_SET_MUTE
- *
- * Turn on or off uplink (microphone) mute.
- *
- * Will only be sent while voice call is active.
- * Will always be reset to "disable mute" when a new voice call is initiated
- *
- * "data" is an int *
- * (int *)data)[0] is 1 for "enable mute" and 0 for "disable mute"
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_SET_MUTE 53
-
-/**
- * RIL_REQUEST_GET_MUTE
- *
- * Queries the current state of the uplink mute setting
- *
- * "data" is NULL
- * "response" is an int *
- * (int *)response)[0] is 1 for "mute enabled" and 0 for "mute disabled"
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_GET_MUTE 54
-
-/**
- * RIL_REQUEST_QUERY_CLIP
- *
- * Queries the status of the CLIP supplementary service
- *
- * (for MMI code "*#30#")
- *
- * "data" is NULL
- * "response" is an int *
- * (int *)response)[0] is 1 for "CLIP provisioned" 
- *                           and 0 for "CLIP not provisioned"
- *                           and 2 for "unknown, e.g. no network etc" 
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_QUERY_CLIP 55
-
-/**
- * RIL_REQUEST_LAST_PDP_FAIL_CAUSE
- * 
- * Requests the failure cause code for the most recently failed PDP 
- * context activate
- *
- * "data" is NULL
- *
- * "response" is a "int *"
- * ((int *)response)[0] is an integer cause code defined in TS 24.008
- *   section 6.1.3.1.3 or close approximation
- *
- * If the implementation does not have access to the exact cause codes,
- * then it should return one of the values listed in 
- * RIL_LastPDPActivateFailCause, as the UI layer needs to distinguish these 
- * cases for error notification
- * and potential retries.
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_LAST_CALL_FAIL_CAUSE
- *  
- */ 
-
-#define RIL_REQUEST_LAST_PDP_FAIL_CAUSE 56
-
-/**
- * RIL_REQUEST_PDP_CONTEXT_LIST
- *
- * Queries the status of PDP contexts, returning for each
- * its CID, whether or not it is active, and its PDP type,
- * APN, and PDP adddress.
- *
- * "data" is NULL
- * "response" is an array of RIL_PDP_Context_Response
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_PDP_CONTEXT_LIST 57
-
-/**
- * RIL_REQUEST_RESET_RADIO
- *
- * Request a radio reset. The RIL implementation may postpone
- * the reset until after this request is responded to if the baseband
- * is presently busy.
- *
- * "data" is NULL
- * "response" is NULL
- *
- * The reset action could be delayed for a while
- * in case baseband modem is just busy.
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-
-#define RIL_REQUEST_RESET_RADIO 58
-
-/**
- * RIL_REQUEST_OEM_HOOK_RAW
- *
- * This request reserved for OEM-specific uses. It passes raw byte arrays
- * back and forth.
- *
- * It can be invoked on the Java side from 
- * com.android.internal.telephony.Phone.invokeOemRilRequestRaw()
- *
- * "data" is a char * of bytes copied from the byte[] data argument in java
- * "response" is a char * of bytes that will returned via the
- * caller's "response" Message here: 
- * (byte[])(((AsyncResult)response.obj).result)
- *
- * An error response here will result in 
- * (((AsyncResult)response.obj).result) == null and 
- * (((AsyncResult)response.obj).exception) being an instance of
- * com.android.internal.telephony.gsm.CommandException
- *
- * Valid errors:
- *  All
- */
-
-#define RIL_REQUEST_OEM_HOOK_RAW 59
-
-/**
- * RIL_REQUEST_OEM_HOOK_STRINGS
- *
- * This request reserved for OEM-specific uses. It passes strings
- * back and forth.
- *
- * It can be invoked on the Java side from 
- * com.android.internal.telephony.Phone.invokeOemRilRequestStrings()
- *
- * "data" is a const char **, representing an array of null-terminated UTF-8
- * strings copied from the "String[] strings" argument to
- * invokeOemRilRequestStrings()
- *
- * "response" is a const char **, representing an array of null-terminated UTF-8
- * stings that will be returned via the caller's response message here:
- *
- * (String[])(((AsyncResult)response.obj).result)
- *
- * An error response here will result in 
- * (((AsyncResult)response.obj).result) == null and 
- * (((AsyncResult)response.obj).exception) being an instance of
- * com.android.internal.telephony.gsm.CommandException
- *
- * Valid errors:
- *  All
- */
-
-#define RIL_REQUEST_OEM_HOOK_STRINGS 60
-
-/**
- * RIL_REQUEST_SCREEN_STATE
- *
- * Indicates the current state of the screen.  When the screen is off, the
- * RIL should notify the baseband to suppress certain notifications (eg,
- * signal strength and changes in LAC or CID) in an effort to conserve power.
- * These notifications should resume when the screen is on.
- *
- * "data" is int *
- * ((int *)data)[0] is == 1 for "Screen On"
- * ((int *)data)[0] is == 0 for "Screen Off"
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SCREEN_STATE 61
-
-
-/**
- * RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION
- *
- * Enables/disables supplementary service related notifications
- * from the network.
- *
- * Notifications are reported via RIL_UNSOL_SUPP_SVC_NOTIFICATION.
- *
- * "data" is int *
- * ((int *)data)[0] is == 1 for notifications enabled
- * ((int *)data)[0] is == 0 for notifications disabled
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_UNSOL_SUPP_SVC_NOTIFICATION.
- */
-#define RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION 62
-
-/**
- * RIL_REQUEST_WRITE_SMS_TO_SIM
- *
- * Stores a SMS message to SIM memory.
- *
- * "data" is RIL_SMS_WriteArgs *
- *
- * "response" is int *
- * ((const int *)response)[0] is the record index where the message is stored.
- *
- * Valid errors:
- *  SUCCESS
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_WRITE_SMS_TO_SIM 63
-
-/**
- * RIL_REQUEST_DELETE_SMS_ON_SIM
- *
- * Deletes a SMS message from SIM memory.
- *
- * "data" is int  *
- * ((int *)data)[0] is the record index of the message to delete.
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  GENERIC_FAILURE
- *
- */
-#define RIL_REQUEST_DELETE_SMS_ON_SIM 64
-
-/**
- * RIL_REQUEST_SET_BAND_MODE
- *
- * Assign a specified band for RF configuration.
- *
- * "data" is int *
- * ((int *)data)[0] is == 0 for "unspecified" (selected by baseband automatically)
- * ((int *)data)[0] is == 1 for "EURO band" (GSM-900 / DCS-1800 / WCDMA-IMT-2000)
- * ((int *)data)[0] is == 2 for "US band" (GSM-850 / PCS-1900 / WCDMA-850 / WCDMA-PCS-1900)
- * ((int *)data)[0] is == 3 for "JPN band" (WCDMA-800 / WCDMA-IMT-2000)
- * ((int *)data)[0] is == 4 for "AUS band" (GSM-900 / DCS-1800 / WCDMA-850 / WCDMA-IMT-2000)
- * ((int *)data)[0] is == 5 for "AUS band 2" (GSM-900 / DCS-1800 / WCDMA-850)
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_SET_BAND_MODE 65
-
-/**
- * RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE
- *
- * Query the list of band mode supported by RF.
- *
- * "data" is NULL
- *
- * "response" is int *
- * "response" points to an array of int's, the int[0] is the size of array, reset is one for
- * each available band mode.
- *
- *  0 for "unspecified" (selected by baseband automatically)
- *  1 for "EURO band" (GSM-900 / DCS-1800 / WCDMA-IMT-2000)
- *  2 for "US band" (GSM-850 / PCS-1900 / WCDMA-850 / WCDMA-PCS-1900)
- *  3 for "JPN band" (WCDMA-800 / WCDMA-IMT-2000)
- *  4 for "AUS band" (GSM-900 / DCS-1800 / WCDMA-850 / WCDMA-IMT-2000)
- *  5 for "AUS band 2" (GSM-900 / DCS-1800 / WCDMA-850)
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_SET_BAND_MODE
- */
-#define RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE 66
-
-/**
- * RIL_REQUEST_STK_GET_PROFILE
- *
- * Requests the profile of SIM tool kit.
- * The profile indicates the SAT/USAT features supported by ME.
- * The SAT/USAT features refer to 3GPP TS 11.14 and 3GPP TS 31.111
- *
- * "data" is NULL
- *
- * "response" is a const char * containing SAT/USAT profile
- * in hexadecimal format string starting with first byte of terminal profile
- *
- * Valid errors:
- *  RIL_E_SUCCESS
- *  RIL_E_RADIO_NOT_AVAILABLE (radio resetting)
- *  RIL_E_GENERIC_FAILURE
- */
-#define RIL_REQUEST_STK_GET_PROFILE 67
-
-/**
- * RIL_REQUEST_STK_SET_PROFILE
- *
- * Download the STK terminal profile as part of SIM initialization
- * procedure
- *
- * "data" is a const char * containing SAT/USAT profile
- * in hexadecimal format string starting with first byte of terminal profile
- *
- * "response" is NULL
- *
- * Valid errors:
- *  RIL_E_SUCCESS
- *  RIL_E_RADIO_NOT_AVAILABLE (radio resetting)
- *  RIL_E_GENERIC_FAILURE
- */
-#define RIL_REQUEST_STK_SET_PROFILE 68
-
-/**
- * RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND
- *
- * Requests to send a SAT/USAT envelope command to SIM.
- * The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111
- *
- * "data" is a const char * containing SAT/USAT command
- * in hexadecimal format string starting with command tag
- *
- * "response" is a const char * containing SAT/USAT response
- * in hexadecimal format string starting with first byte of response
- * (May be NULL)
- *
- * Valid errors:
- *  RIL_E_SUCCESS
- *  RIL_E_RADIO_NOT_AVAILABLE (radio resetting)
- *  RIL_E_GENERIC_FAILURE
- */
-#define RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND 69
-
-/**
- * RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE
- *
- * Requests to send a terminal response to SIM for a received
- * proactive command
- *
- * "data" is a const char * containing SAT/USAT response
- * in hexadecimal format string starting with first byte of response data
- *
- * "response" is NULL
- *
- * Valid errors:
- *  RIL_E_SUCCESS
- *  RIL_E_RADIO_NOT_AVAILABLE (radio resetting)
- *  RIL_E_GENERIC_FAILURE
- */
-#define RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE 70
-
-/**
- * RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM
- *
- * When STK application gets RIL_UNSOL_STK_CALL_SETUP, the call actually has
- * been initialized by ME already. (We could see the call has been in the 'call
- * list') So, STK application needs to accept/reject the call according as user
- * operations.
- *
- * "data" is int *
- * ((int *)data)[0] is > 0 for "accept" the call setup
- * ((int *)data)[0] is == 0 for "reject" the call setup
- *
- * "response" is NULL
- *
- * Valid errors:
- *  RIL_E_SUCCESS
- *  RIL_E_RADIO_NOT_AVAILABLE (radio resetting)
- *  RIL_E_GENERIC_FAILURE
- */
-#define RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM 71
-
-/**
- * RIL_REQUEST_EXPLICIT_CALL_TRANSFER
- *
- * Connects the two calls and disconnects the subscriber from both calls.
- * 
- * "data" is NULL
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS 
- *  RADIO_NOT_AVAILABLE (radio resetting)
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_EXPLICIT_CALL_TRANSFER 72
-
-/**
- * RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE
- *
- * Requests to set the preferred network type for searching and registering
- * (CS/PS domain, RAT, and operation mode)
- *
- * "data" is int *
- * ((int *)data)[0] is == 0 for WCDMA preferred (auto mode)
- * ((int *)data)[0] is == 1 for GSM only
- * ((int *)data)[0] is == 2 for WCDMA only
- *
- * "response" is NULL
- *
- * Valid errors:
- *  RIL_E_SUCCESS
- *  RIL_E_RADIO_NOT_AVAILABLE (radio resetting)
- *  RIL_E_GENERIC_FAILURE
- */
-#define RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE 73
-
-/**
- * RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE
- *
- * Query the preferred network type (CS/PS domain, RAT, and operation mode)
- * for searching and registering
- *
- * "data" is NULL
- *
- * "response" is int *
- * ((int *)response)[0] is == 0 for WCDMA preferred (auto mode)
- * ((int *)response)[0] is == 1 for GSM only
- * ((int *)response)[0] is == 2 for WCDMA only
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE
- */
-#define RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE 74
-
-/**
- * RIL_REQUEST_NEIGHBORING_CELL_IDS
- *
- * Request neighboring cell id in GSM network
- *
- * "data" is NULL
- * "response" must be a " const RIL_NeighboringCell** "
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- */
-#define RIL_REQUEST_GET_NEIGHBORING_CELL_IDS 75
-
-/**
- * RIL_REQUEST_SET_LOCATION_UPDATES
- *
- * Enables/disables network state change notifications due to changes in
- * LAC and/or CID (basically, +CREG=2 vs. +CREG=1).  
- *
- * Note:  The RIL implementation should default to "updates enabled"
- * when the screen is on and "updates disabled" when the screen is off.
- *
- * "data" is int *
- * ((int *)data)[0] is == 1 for updates enabled (+CREG=2)
- * ((int *)data)[0] is == 0 for updates disabled (+CREG=1)
- *
- * "response" is NULL
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  GENERIC_FAILURE
- *
- * See also: RIL_REQUEST_SCREEN_STATE, RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED
- */
-#define RIL_REQUEST_SET_LOCATION_UPDATES 76
-
-/***********************************************************************/
-
-#define RIL_UNSOL_RESPONSE_BASE 1000
-
-/**
- * RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED
- *
- * Indicate when value of RIL_RadioState has changed.
- *
- * Callee will invoke RIL_RadioStateRequest method on main thread
- *
- * "data" is NULL
- */
-
-#define RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED 1000
-
-
-/**
- * RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
- *
- * Indicate when call state has changed
- *
- * Callee will invoke RIL_REQUEST_GET_CURRENT_CALLS on main thread
- *
- * "data" is NULL
- *
- * Response should be invoked on, for example, 
- * "RING", "BUSY", "NO CARRIER", and also call state
- * transitions (DIALING->ALERTING ALERTING->ACTIVE)
- *
- * Redundent or extraneous invocations are tolerated
- */
-#define RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 1001
-
-
-/**
- * RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED 
- *
- * Called when network state, operator name, or GPRS state has changed
- * Basically on, +CREG and +CGREG
- *
- * Callee will invoke the following requests on main thread:
- *
- * RIL_REQUEST_REGISTRATION_STATE
- * RIL_REQUEST_GPRS_REGISTRATION_STATE
- * RIL_REQUEST_OPERATOR
- *
- * "data" is NULL
- *
- * FIXME should this happen when SIM records are loaded? (eg, for
- * EONS)
- */
-#define RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED 1002
-
-/**
- * RIL_UNSOL_RESPONSE_NEW_SMS
- *
- * Called when new SMS is received.
- * 
- * "data" is const char *
- * This is a pointer to a string containing the PDU of an SMS-DELIVER
- * as an ascii string of hex digits. The PDU starts with the SMSC address
- * per TS 27.005 (+CMT:)
- *
- * Callee will subsequently confirm the receipt of thei SMS with a
- * RIL_REQUEST_SMS_ACKNOWLEDGE
- *
- * No new RIL_UNSOL_RESPONSE_NEW_SMS 
- * or RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT messages should be sent until a
- * RIL_REQUEST_SMS_ACKNOWLEDGE has been received
- */
-
-#define RIL_UNSOL_RESPONSE_NEW_SMS 1003
-
-/**
- * RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT
- *
- * Called when new SMS Status Report is received.
- * 
- * "data" is const char *
- * This is a pointer to a string containing the PDU of an SMS-STATUS-REPORT
- * as an ascii string of hex digits. The PDU starts with the SMSC address
- * per TS 27.005 (+CDS:).
- *
- * Callee will subsequently confirm the receipt of the SMS with a
- * RIL_REQUEST_SMS_ACKNOWLEDGE
- *
- * No new RIL_UNSOL_RESPONSE_NEW_SMS 
- * or RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT messages should be sent until a
- * RIL_REQUEST_SMS_ACKNOWLEDGE has been received
- */
-
-#define RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT 1004
-
-/**
- * RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM
- *
- * Called when new SMS has been stored on SIM card
- * 
- * "data" is const int *
- * ((const int *)data)[0] contains the slot index on the SIM that contains
- * the new message
- */
-
-#define RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM 1005
-
-/**
- * RIL_UNSOL_ON_USSD
- *
- * Called when a new USSD message is received.
- *
- * "data" is const char **
- * ((const char **)data)[0] points to a type code, which is 
- *  one of these string values:
- *      "0"   USSD-Notify -- text in ((const char **)data)[1]
- *      "1"   USSD-Request -- text in ((const char **)data)[1]
- *      "2"   Session terminated by network
- *      "3"   other local client (eg, SIM Toolkit) has responded
- *      "4"   Operation not supported
- *      "5"   Network timeout
- *
- * The USSD session is assumed to persist if the type code is "1", otherwise
- * the current session (if any) is assumed to have terminated.
- *
- * ((const char **)data)[1] points to a message string if applicable, which
- * should always be in UTF-8.
- */
-#define RIL_UNSOL_ON_USSD 1006
-/* Previously #define RIL_UNSOL_ON_USSD_NOTIFY 1006   */
-
-/**
- * RIL_UNSOL_ON_USSD_REQUEST
- *
- * Obsolete. Send via RIL_UNSOL_ON_USSD
- */
-#define RIL_UNSOL_ON_USSD_REQUEST 1007 
-
-
-/**
- * RIL_UNSOL_NITZ_TIME_RECEIVED
- *
- * Called when radio has received a NITZ time message
- *
- * "data" is const char * pointing to NITZ time string
- * in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt"
- */
-#define RIL_UNSOL_NITZ_TIME_RECEIVED  1008
-
-/**
- * RIL_UNSOL_SIGNAL_STRENGTH
- *
- * Radio may report signal strength rather han have it polled.
- *
- * "data" is an "int *"
- * ((int *)response)[0] is received signal strength (0-31, 99)
- * ((int *)response)[1] is bit error rate (0-7, 99)
- *  as defined in TS 27.007 8.5
- *  Other values (eg -1) are not legal
- */
-#define RIL_UNSOL_SIGNAL_STRENGTH  1009
-
-
-/**
- * RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED
- *
- * Indicate a PDP context state has changed, or a new context
- * has been activated or deactivated
- *
- * "data" is an array of RIL_PDP_Context_Response identical to that
- * returned by RIL_REQUEST_PDP_CONTEXT_LIST
- *
- * See also: RIL_REQUEST_PDP_CONTEXT_LIST
- */
-
-#define RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED 1010
-
-/**
- * RIL_UNSOL_SUPP_SVC_NOTIFICATION
- *
- * Reports supplementary service related notification from the network.
- *
- * "data" is a const RIL_SuppSvcNotification *
- *
- */
-
-#define RIL_UNSOL_SUPP_SVC_NOTIFICATION 1011
-
-/**
- * RIL_UNSOL_STK_SESSION_END
- *
- * Indicate when STK session is terminated by SIM.
- *
- * "data" is NULL
- */
-#define RIL_UNSOL_STK_SESSION_END 1012
-
-/**
- * RIL_UNSOL_STK_PROACTIVE_COMMAND
- *
- * Indicate when SIM issue a STK proactive command to applications
- *
- * "data" is a const char * containing SAT/USAT proactive command
- * in hexadecimal format string starting with command tag
- *
- */
-#define RIL_UNSOL_STK_PROACTIVE_COMMAND 1013
-
-/**
- * RIL_UNSOL_STK_EVENT_NOTIFY
- *
- * Indicate when SIM notifies applcations some event happens.
- * Generally, application does not need to have any feedback to
- * SIM but shall be able to indicate appropriate messages to users.
- *
- * "data" is a const char * containing SAT/USAT commands or responses
- * sent by ME to SIM or commands handled by ME, in hexadecimal format string
- * starting with first byte of response data or command tag
- *
- */
-#define RIL_UNSOL_STK_EVENT_NOTIFY 1014
-
-/**
- * RIL_UNSOL_STK_CALL_SETUP
- *
- * Indicate when SIM wants application to setup a voice call.
- *
- * "data" is const int *
- * ((const int *)data)[0] contains timeout value (in milliseconds)
- */
-#define RIL_UNSOL_STK_CALL_SETUP 1015
-
-/**
- * RIL_UNSOL_SIM_SMS_STORAGE_FULL
- *
- * Indicates that SMS storage on the SIM is full.  Sent when the network
- * attempts to deliver a new SMS message.  Messages cannot be saved on the
- * SIM until space is freed.  In particular, incoming Class 2 messages
- * cannot be stored.
- *
- * "data" is null
- *
- */
-#define RIL_UNSOL_SIM_SMS_STORAGE_FULL 1016
-
-/**
- * RIL_UNSOL_SIM_REFRESH
- *
- * Indicates that file(s) on the SIM have been updated, or the SIM
- * has been reinitialized.
- *
- * "data" is an int *
- * ((int *)data)[0] is a RIL_SimRefreshResult.
- * ((int *)data)[1] is the EFID of the updated file if the result is
- * SIM_FILE_UPDATE or NULL for any other result.
- *
- * Note: If the radio state changes as a result of the SIM refresh (eg,
- * SIM_READY -> SIM_LOCKED_OR_ABSENT), RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED
- * should be sent.
- */
-#define RIL_UNSOL_SIM_REFRESH 1017
-
-/**
- * RIL_UNSOL_CALL_RING
- *
- * Ring indication for an incoming call (eg, RING or CRING event).
- *
- * "data" is null
- */
-#define RIL_UNSOL_CALL_RING 1018
-
-/***********************************************************************/
-
-
-/**
- * RIL_Request Function pointer
- *
- * @param request is one of RIL_REQUEST_*
- * @param data is pointer to data defined for that RIL_REQUEST_*
- *        data is owned by caller, and should not be modified or freed by callee
- * @param t should be used in subsequent call to RIL_onResponse
- * @param datalen the length of data
- *
- */
-typedef void (*RIL_RequestFunc) (int request, void *data, 
-                                    size_t datalen, RIL_Token t);
-
-/**
- * This function should return the current radio state synchronously
- */
-typedef RIL_RadioState (*RIL_RadioStateRequest)();
-
-/**
- * This function returns "1" if the specified RIL_REQUEST code is
- * supported and 0 if it is not
- *
- * @param requestCode is one of RIL_REQUEST codes
- */
-
-typedef int (*RIL_Supports)(int requestCode);
-
-/**
- * This function is called from a separate thread--not the 
- * thread that calls RIL_RequestFunc--and indicates that a pending
- * request should be cancelled.
- * 
- * On cancel, the callee should do its best to abandon the request and
- * call RIL_onRequestComplete with RIL_Errno CANCELLED at some later point.
- *
- * Subsequent calls to  RIL_onRequestComplete for this request with
- * other results will be tolerated but ignored. (That is, it is valid
- * to ignore the cancellation request)
- *
- * RIL_Cancel calls should return immediately, and not wait for cancellation
- *
- * Please see ITU v.250 5.6.1 for how one might implement this on a TS 27.007 
- * interface
- *
- * @param t token wants to be canceled
- */
-
-typedef void (*RIL_Cancel)(RIL_Token t);
-
-typedef void (*RIL_TimedCallback) (void *param);
-
-/**
- * Return a version string for your RIL implementation
- */
-typedef const char * (*RIL_GetVersion) (void);
-
-typedef struct {
-    int version;        /* set to RIL_VERSION */
-    RIL_RequestFunc onRequest;
-    RIL_RadioStateRequest onStateRequest;
-    RIL_Supports supports;
-    RIL_Cancel onCancel;
-    RIL_GetVersion getVersion;
-} RIL_RadioFunctions;
-
-#ifdef RIL_SHLIB
-struct RIL_Env {
-    /**
-     * "t" is parameter passed in on previous call to RIL_Notification
-     * routine.
-     *
-     * If "e" != SUCCESS, then response can be null/is ignored
-     *
-     * "response" is owned by caller, and should not be modified or 
-     * freed by callee
-     *
-     * RIL_onRequestComplete will return as soon as possible
-     */
-    void (*OnRequestComplete)(RIL_Token t, RIL_Errno e, 
-                           void *response, size_t responselen);
-
-    /**
-     * "unsolResponse" is one of RIL_UNSOL_RESPONSE_*
-     * "data" is pointer to data defined for that RIL_UNSOL_RESPONSE_*
-     *
-     * "data" is owned by caller, and should not be modified or freed by callee
-     */
-
-    void (*OnUnsolicitedResponse)(int unsolResponse, const void *data, 
-                                    size_t datalen);
-
-    /**
-     * Call user-specifed "callback" function on on the same thread that 
-     * RIL_RequestFunc is called. If "relativeTime" is specified, then it specifies
-     * a relative time value at which the callback is invoked. If relativeTime is
-     * NULL or points to a 0-filled structure, the callback will be invoked as
-     * soon as possible
-     */
-
-    void (*RequestTimedCallback) (RIL_TimedCallback callback, 
-                                   void *param, const struct timeval *relativeTime);   
-};
-
-
-/** 
- *  RIL implementations must defined RIL_Init 
- *  argc and argv will be command line arguments intended for the RIL implementation
- *  Return NULL on error
- *
- * @param env is environment point defined as RIL_Env
- * @param argc number of arguments
- * @param argv list fo arguments
- *
- */
-const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv);
-
-#else /* RIL_SHLIB */
-
-/**
- * Call this once at startup to register notification routine
- *
- * @param callbacks user-specifed callback function
- */
-void RIL_register (const RIL_RadioFunctions *callbacks);
-
-
-/**
- *
- * RIL_onRequestComplete will return as soon as possible
- *
- * @param t is parameter passed in on previous call to RIL_Notification
- *          routine.
- * @param e error code
- *          if "e" != SUCCESS, then response can be null/is ignored
- * @param response is owned by caller, and should not be modified or
- *                 freed by callee
- * @param responselen the length of response in byte
- */
-void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, 
-                           void *response, size_t responselen);
-
-/**
- * @param unsolResponse is one of RIL_UNSOL_RESPONSE_*
- * @param data is pointer to data defined for that RIL_UNSOL_RESPONSE_*
- *     "data" is owned by caller, and should not be modified or freed by callee
- * @param datalen the length of data in byte
- */
-
-void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, 
-                                size_t datalen);
-
-
-/**
- * Call user-specifed "callback" function on on the same thread that 
- * RIL_RequestFunc is called. If "relativeTime" is specified, then it specifies
- * a relative time value at which the callback is invoked. If relativeTime is
- * NULL or points to a 0-filled structure, the callback will be invoked as
- * soon as possible
- *
- * @param callback user-specifed callback function
- * @param param parameter list
- * @param relativeTime a relative time value at which the callback is invoked
- */
-
-void RIL_requestTimedCallback (RIL_TimedCallback callback, 
-                               void *param, const struct timeval *relativeTime);
-
-
-#endif /* RIL_SHLIB */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*ANDROID_RIL_H*/
-
diff --git a/libril/Android.mk b/libril/Android.mk
deleted file mode 100644
index 9416f24..0000000
--- a/libril/Android.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright 2006 The Android Open Source Project
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    ril.cpp \
-    ril_event.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-    libutils \
-    libcutils \
-    libhardware_legacy
-
-LOCAL_CFLAGS := 
-
-LOCAL_MODULE:= libril
-
-LOCAL_LDLIBS += -lpthread
-
-include $(BUILD_SHARED_LIBRARY)
-
-
-# For RdoServD which needs a static library
-# =========================================
-ifneq ($(ANDROID_BIONIC_TRANSITION),)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    ril.cpp
-
-LOCAL_STATIC_LIBRARIES := \
-    libutils_static \
-    libcutils
-
-LOCAL_CFLAGS := 
-
-LOCAL_MODULE:= libril_static
-
-LOCAL_LDLIBS += -lpthread
-
-include $(BUILD_STATIC_LIBRARY)
-endif # ANDROID_BIONIC_TRANSITION
diff --git a/libril/MODULE_LICENSE_APACHE2 b/libril/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/libril/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/libril/NOTICE b/libril/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/libril/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
-   Copyright (c) 2005-2008, The Android Open Source Project
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
diff --git a/libril/ril.cpp b/libril/ril.cpp
deleted file mode 100644
index 3476232..0000000
--- a/libril/ril.cpp
+++ /dev/null
@@ -1,2202 +0,0 @@
-/* //device/libs/telephony/ril.cpp
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-#define LOG_TAG "RILC"
-
-#include <hardware_legacy/power.h>
-
-#include <telephony/ril.h>
-#include <cutils/sockets.h>
-#include <cutils/jstring.h>
-#include <cutils/record_stream.h>
-#include <utils/Log.h>
-#include <utils/SystemClock.h>
-#include <pthread.h>
-#include <utils/Parcel.h>
-#include <cutils/jstring.h>
-
-#include <sys/types.h>
-#include <pwd.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <errno.h>
-#include <assert.h>
-#include <ctype.h>
-#include <alloca.h>
-#include <sys/un.h>
-#include <assert.h>
-#include <netinet/in.h>
-#include <cutils/properties.h>
-
-#include <ril_event.h>
-
-namespace android {
-
-#define PHONE_PROCESS "radio"
-
-#define SOCKET_NAME_RIL "rild"
-#define SOCKET_NAME_RIL_DEBUG "rild-debug"
-
-#define ANDROID_WAKE_LOCK_NAME "radio-interface"
-
-
-#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
-
-// match with constant in RIL.java
-#define MAX_COMMAND_BYTES (8 * 1024)
-
-// Basically: memset buffers that the client library
-// shouldn't be using anymore in an attempt to find
-// memory usage issues sooner.
-#define MEMSET_FREED 1
-
-#define NUM_ELEMS(a)     (sizeof (a) / sizeof (a)[0])
-
-/* Constants for response types */
-#define RESPONSE_SOLICITED 0
-#define RESPONSE_UNSOLICITED 1
-
-/* Negative values for private RIL errno's */
-#define RIL_ERRNO_INVALID_RESPONSE -1
-
-// request, response, and unsolicited msg print macro
-#define PRINTBUF_SIZE 8096
-
-// Enable RILC log
-#define RILC_LOG 0
-
-#if RILC_LOG
-    #define startRequest           sprintf(printBuf, "(")
-    #define closeRequest           sprintf(printBuf, "%s)", printBuf)
-    #define printRequest(token, req)           \
-            LOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
-
-    #define startResponse           sprintf(printBuf, "%s {", printBuf)
-    #define closeResponse           sprintf(printBuf, "%s}", printBuf)
-    #define printResponse           LOGD("%s", printBuf)
-
-    #define clearPrintBuf           printBuf[0] = 0
-    #define removeLastChar          printBuf[strlen(printBuf)-1] = 0
-    #define appendPrintBuf(x...)    sprintf(printBuf, x)
-#else
-    #define startRequest
-    #define closeRequest
-    #define printRequest(token, req)
-    #define startResponse
-    #define closeResponse
-    #define printResponse
-    #define clearPrintBuf
-    #define removeLastChar
-    #define appendPrintBuf(x...)
-#endif
-
-enum WakeType {DONT_WAKE, WAKE_PARTIAL};
-
-typedef struct {
-    int requestNumber;
-    void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
-    int(*responseFunction) (Parcel &p, void *response, size_t responselen);
-} CommandInfo;
-
-typedef struct {
-    int requestNumber;
-    int (*responseFunction) (Parcel &p, void *response, size_t responselen);
-    WakeType wakeType;
-} UnsolResponseInfo;
-
-typedef struct RequestInfo {
-    int32_t token;      //this is not RIL_Token 
-    CommandInfo *pCI;
-    struct RequestInfo *p_next;
-    char cancelled;
-    char local;         // responses to local commands do not go back to command process
-} RequestInfo;
-
-typedef struct UserCallbackInfo{
-    RIL_TimedCallback p_callback;
-    void *userParam;
-    struct ril_event event;
-    struct UserCallbackInfo *p_next;
-} UserCallbackInfo;
-
-
-/*******************************************************************/
-
-RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
-static int s_registerCalled = 0;
-
-static pthread_t s_tid_dispatch;
-static pthread_t s_tid_reader;
-static int s_started = 0;
-
-static int s_fdListen = -1;
-static int s_fdCommand = -1;
-static int s_fdDebug = -1;
-
-static int s_fdWakeupRead;
-static int s_fdWakeupWrite;
-
-static struct ril_event s_commands_event;
-static struct ril_event s_wakeupfd_event;
-static struct ril_event s_listen_event;
-static struct ril_event s_wake_timeout_event;
-static struct ril_event s_debug_event;
-
-
-static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
-
-static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
-
-static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
-
-static RequestInfo *s_pendingRequests = NULL;
-
-static RequestInfo *s_toDispatchHead = NULL;
-static RequestInfo *s_toDispatchTail = NULL;
-
-static UserCallbackInfo *s_last_wake_timeout_info = NULL;
-
-static void *s_lastNITZTimeData = NULL;
-static size_t s_lastNITZTimeDataSize;
-
-#if RILC_LOG
-    static char printBuf[PRINTBUF_SIZE];
-#endif
-
-/*******************************************************************/
-
-static void dispatchVoid (Parcel& p, RequestInfo *pRI);
-static void dispatchString (Parcel& p, RequestInfo *pRI);
-static void dispatchStrings (Parcel& p, RequestInfo *pRI);
-static void dispatchInts (Parcel& p, RequestInfo *pRI);
-static void dispatchDial (Parcel& p, RequestInfo *pRI);
-static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
-static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
-static void dispatchRaw(Parcel& p, RequestInfo *pRI);
-static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
-
-static int responseInts(Parcel &p, void *response, size_t responselen);
-static int responseStrings(Parcel &p, void *response, size_t responselen);
-static int responseString(Parcel &p, void *response, size_t responselen);
-static int responseVoid(Parcel &p, void *response, size_t responselen);
-static int responseCallList(Parcel &p, void *response, size_t responselen);
-static int responseSMS(Parcel &p, void *response, size_t responselen);
-static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
-static int responseCallForwards(Parcel &p, void *response, size_t responselen);
-static int responseContexts(Parcel &p, void *response, size_t responselen);
-static int responseRaw(Parcel &p, void *response, size_t responselen);
-static int responseSsn(Parcel &p, void *response, size_t responselen);
-static int responseCellList(Parcel &p, void *response, size_t responselen);
-
-extern "C" const char * requestToString(int request);
-extern "C" const char * failCauseToString(RIL_Errno);
-extern "C" const char * callStateToString(RIL_CallState);
-extern "C" const char * radioStateToString(RIL_RadioState);
-
-#ifdef RIL_SHLIB
-extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data, 
-                                size_t datalen);
-#endif
-
-static UserCallbackInfo * internalRequestTimedCallback 
-    (RIL_TimedCallback callback, void *param, 
-        const struct timeval *relativeTime);
-
-/** Index == requestNumber */
-static CommandInfo s_commands[] = {
-#include "ril_commands.h"
-};
-
-static UnsolResponseInfo s_unsolResponses[] = {
-#include "ril_unsol_commands.h"
-};
-
-
-static char *
-strdupReadString(Parcel &p)
-{
-    size_t stringlen;
-    const char16_t *s16;
-            
-    s16 = p.readString16Inplace(&stringlen);
-    
-    return strndup16to8(s16, stringlen);
-}
-
-static void writeStringToParcel(Parcel &p, const char *s)
-{
-    char16_t *s16;
-    size_t s16_len;
-    s16 = strdup8to16(s, &s16_len);
-    p.writeString16(s16, s16_len);
-    free(s16);
-}
-
-
-static void
-memsetString (char *s)
-{
-    if (s != NULL) {
-        memset (s, 0, strlen(s));
-    }
-}
-
-void   nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
-                                    const size_t* objects, size_t objectsSize,
-                                        void* cookie)
-{
-    // do nothing -- the data reference lives longer than the Parcel object
-}
-
-/** 
- * To be called from dispatch thread
- * Issue a single local request, ensuring that the response
- * is not sent back up to the command process 
- */
-static void
-issueLocalRequest(int request, void *data, int len)
-{
-    RequestInfo *pRI;
-    int ret;
-
-    pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
-
-    pRI->local = 1;
-    pRI->token = 0xffffffff;        // token is not used in this context
-    pRI->pCI = &(s_commands[request]);
-
-    ret = pthread_mutex_lock(&s_pendingRequestsMutex);
-    assert (ret == 0);
-
-    pRI->p_next = s_pendingRequests;
-    s_pendingRequests = pRI;
-
-    ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
-    assert (ret == 0);
-
-    LOGD("C[locl]> %s", requestToString(request));
-
-    s_callbacks.onRequest(request, data, len, pRI);
-}
-
-
-
-static int
-processCommandBuffer(void *buffer, size_t buflen)
-{
-    Parcel p;
-    status_t status;
-    int32_t request;
-    int32_t token;
-    RequestInfo *pRI;
-    int ret;
-
-    p.setData((uint8_t *) buffer, buflen);
-
-    // status checked at end
-    status = p.readInt32(&request);
-    status = p.readInt32 (&token);
-
-    if (status != NO_ERROR) {
-        LOGE("invalid request block");
-        return 0;
-    }
-
-    if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
-        LOGE("unsupported request code %d token %d", request, token);
-        // FIXME this should perhaps return a response
-        return 0;
-    }
-
-
-    pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
-
-    pRI->token = token;
-    pRI->pCI = &(s_commands[request]);
-
-    ret = pthread_mutex_lock(&s_pendingRequestsMutex);
-    assert (ret == 0);
-
-    pRI->p_next = s_pendingRequests;
-    s_pendingRequests = pRI;
-
-    ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
-    assert (ret == 0);
-
-/*    sLastDispatchedToken = token; */
-
-    pRI->pCI->dispatchFunction(p, pRI);    
-
-    return 0;
-}
-
-static void
-invalidCommandBlock (RequestInfo *pRI)
-{
-    LOGE("invalid command block for token %d request %s", 
-                pRI->token, requestToString(pRI->pCI->requestNumber));
-}
-
-/** Callee expects NULL */
-static void 
-dispatchVoid (Parcel& p, RequestInfo *pRI)
-{
-    clearPrintBuf;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-    s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
-}
-
-/** Callee expects const char * */
-static void
-dispatchString (Parcel& p, RequestInfo *pRI)
-{
-    status_t status;
-    size_t datalen;
-    size_t stringlen;
-    char *string8 = NULL;
-
-    string8 = strdupReadString(p);
-
-    startRequest;
-    appendPrintBuf("%s%s", printBuf, string8);
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-
-    s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
-                       sizeof(char *), pRI);
-
-#ifdef MEMSET_FREED
-    memsetString(string8);
-#endif
-
-    free(string8);
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-/** Callee expects const char ** */
-static void
-dispatchStrings (Parcel &p, RequestInfo *pRI)
-{
-    int32_t countStrings;
-    status_t status;
-    size_t datalen;
-    char **pStrings;
-
-    status = p.readInt32 (&countStrings);
-
-    if (status != NO_ERROR) {
-        goto invalid;
-    }
-
-    startRequest;
-    if (countStrings == 0) {
-        // just some non-null pointer
-        pStrings = (char **)alloca(sizeof(char *));
-        datalen = 0;
-    } else if (((int)countStrings) == -1) {
-        pStrings = NULL;
-        datalen = 0;
-    } else {
-        datalen = sizeof(char *) * countStrings;
-    
-        pStrings = (char **)alloca(datalen);
-
-        for (int i = 0 ; i < countStrings ; i++) {
-            pStrings[i] = strdupReadString(p);
-            appendPrintBuf("%s%s,", printBuf, pStrings[i]);
-        }
-    }
-    removeLastChar;
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-
-    s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
-
-    if (pStrings != NULL) {
-        for (int i = 0 ; i < countStrings ; i++) {
-#ifdef MEMSET_FREED
-            memsetString (pStrings[i]);
-#endif
-            free(pStrings[i]);
-        }
-
-#ifdef MEMSET_FREED
-        memset(pStrings, 0, datalen);
-#endif
-    }
-    
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-/** Callee expects const int * */
-static void
-dispatchInts (Parcel &p, RequestInfo *pRI)
-{
-    int32_t count;
-    status_t status;
-    size_t datalen;
-    int *pInts;
-
-    status = p.readInt32 (&count);
-
-    if (status != NO_ERROR || count == 0) {
-        goto invalid;
-    }
-
-    datalen = sizeof(int) * count;
-    pInts = (int *)alloca(datalen);
-
-    startRequest;
-    for (int i = 0 ; i < count ; i++) {
-        int32_t t;
-
-        status = p.readInt32(&t);
-        pInts[i] = (int)t;
-        appendPrintBuf("%s%d,", printBuf, t);
-
-        if (status != NO_ERROR) {
-            goto invalid;
-        }
-   }
-   removeLastChar;
-   closeRequest;
-   printRequest(pRI->token, pRI->pCI->requestNumber);
-
-   s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts), 
-                       datalen, pRI);
-
-#ifdef MEMSET_FREED
-    memset(pInts, 0, datalen);
-#endif
-
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-
-/** 
- * Callee expects const RIL_SMS_WriteArgs * 
- * Payload is:
- *   int32_t status
- *   String pdu
- */
-static void
-dispatchSmsWrite (Parcel &p, RequestInfo *pRI)
-{
-    RIL_SMS_WriteArgs args;
-    int32_t t;
-    status_t status;
-
-    memset (&args, 0, sizeof(args));
-
-    status = p.readInt32(&t);
-    args.status = (int)t;
-
-    args.pdu = strdupReadString(p);
-
-    if (status != NO_ERROR || args.pdu == NULL) {
-        goto invalid;
-    }
-
-    args.smsc = strdupReadString(p);
-
-    startRequest;
-    appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
-        (char*)args.pdu,  (char*)args.smsc);
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-    
-    s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
-
-#ifdef MEMSET_FREED
-    memsetString (args.pdu);
-#endif
-
-    free (args.pdu);
-    
-#ifdef MEMSET_FREED
-    memset(&args, 0, sizeof(args));
-#endif
-
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-/** 
- * Callee expects const RIL_Dial * 
- * Payload is:
- *   String address
- *   int32_t clir
- */
-static void
-dispatchDial (Parcel &p, RequestInfo *pRI)
-{
-    RIL_Dial dial;
-    int32_t t;
-    status_t status;
-
-    memset (&dial, 0, sizeof(dial));
-
-    dial.address = strdupReadString(p);
-
-    status = p.readInt32(&t);
-    dial.clir = (int)t;
-
-    if (status != NO_ERROR || dial.address == NULL) {
-        goto invalid;
-    }
-
-    startRequest;
-    appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-
-    s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeof(dial), pRI);
-
-#ifdef MEMSET_FREED
-    memsetString (dial.address);
-#endif
-
-    free (dial.address);
-    
-#ifdef MEMSET_FREED
-    memset(&dial, 0, sizeof(dial));
-#endif
-
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-/** 
- * Callee expects const RIL_SIM_IO * 
- * Payload is:
- *   int32_t command
- *   int32_t fileid
- *   String path
- *   int32_t p1, p2, p3
- *   String data 
- *   String pin2 
- */
-static void
-dispatchSIM_IO (Parcel &p, RequestInfo *pRI)
-{
-    RIL_SIM_IO simIO;
-    int32_t t;
-    status_t status;
-
-    memset (&simIO, 0, sizeof(simIO));
-
-    // note we only check status at the end 
-    
-    status = p.readInt32(&t);
-    simIO.command = (int)t;
-
-    status = p.readInt32(&t);
-    simIO.fileid = (int)t;
-
-    simIO.path = strdupReadString(p);
-
-    status = p.readInt32(&t);
-    simIO.p1 = (int)t;
-
-    status = p.readInt32(&t);
-    simIO.p2 = (int)t;
-
-    status = p.readInt32(&t);
-    simIO.p3 = (int)t;
-
-    simIO.data = strdupReadString(p);
-    simIO.pin2 = strdupReadString(p);
-
-    startRequest;
-    appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s", printBuf,
-        simIO.command, simIO.fileid, (char*)simIO.path,
-        simIO.p1, simIO.p2, simIO.p3,
-        (char*)simIO.data,  (char*)simIO.pin2);
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-    
-    if (status != NO_ERROR) {
-        goto invalid;
-    }
-
-       s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, sizeof(simIO), pRI);
-
-#ifdef MEMSET_FREED
-    memsetString (simIO.path);
-    memsetString (simIO.data);
-    memsetString (simIO.pin2);
-#endif
-
-    free (simIO.path);
-    free (simIO.data);
-    free (simIO.pin2);
-    
-#ifdef MEMSET_FREED
-    memset(&simIO, 0, sizeof(simIO));
-#endif
-
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-/**
- * Callee expects const RIL_CallForwardInfo *
- * Payload is:
- *  int32_t status/action
- *  int32_t reason
- *  int32_t serviceCode
- *  int32_t toa
- *  String number  (0 length -> null)
- *  int32_t timeSeconds
- */
-static void 
-dispatchCallForward(Parcel &p, RequestInfo *pRI)
-{
-    RIL_CallForwardInfo cff;
-    int32_t t;
-    status_t status;
-
-    memset (&cff, 0, sizeof(cff));
-
-    // note we only check status at the end 
-
-    status = p.readInt32(&t);
-    cff.status = (int)t;
-    
-    status = p.readInt32(&t);
-    cff.reason = (int)t;
-
-    status = p.readInt32(&t);
-    cff.serviceClass = (int)t;
-
-    status = p.readInt32(&t);
-    cff.toa = (int)t;
-
-    cff.number = strdupReadString(p);
-
-    status = p.readInt32(&t);
-    cff.timeSeconds = (int)t;
-
-    if (status != NO_ERROR) {
-        goto invalid;
-    }
-
-    // special case: number 0-length fields is null
-
-    if (cff.number != NULL && strlen (cff.number) == 0) {
-        cff.number = NULL;
-    }
-
-    startRequest;
-    appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
-        cff.status, cff.reason, cff.serviceClass, cff.toa,
-        (char*)cff.number, cff.timeSeconds);
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-
-    s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
-
-#ifdef MEMSET_FREED
-    memsetString(cff.number);
-#endif
-
-    free (cff.number);
-
-#ifdef MEMSET_FREED
-    memset(&cff, 0, sizeof(cff));
-#endif
-
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-
-static void 
-dispatchRaw(Parcel &p, RequestInfo *pRI)
-{
-    int32_t len;
-    status_t status;
-    const void *data;
-
-    status = p.readInt32(&len);
-
-    if (status != NO_ERROR) {
-        goto invalid;
-    }
-
-    // The java code writes -1 for null arrays
-    if (((int)len) == -1) {
-        data = NULL;
-        len = 0;
-    } 
-
-    data = p.readInplace(len);
-
-    startRequest;
-    appendPrintBuf("%sraw_size=%d", printBuf, len);
-    closeRequest;
-    printRequest(pRI->token, pRI->pCI->requestNumber);
-
-    s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
-
-    return;
-invalid:
-    invalidCommandBlock(pRI);
-    return;
-}
-
-static int
-blockingWrite(int fd, const void *buffer, size_t len)
-{
-    size_t writeOffset = 0; 
-    const uint8_t *toWrite;
-
-    toWrite = (const uint8_t *)buffer;
-
-    while (writeOffset < len) {
-        ssize_t written;
-        do {
-            written = write (fd, toWrite + writeOffset,
-                                len - writeOffset);
-        } while (written < 0 && errno == EINTR);
-
-        if (written >= 0) {
-            writeOffset += written;
-        } else {   // written < 0
-            LOGE ("RIL Response: unexpected error on write errno:%d", errno);
-            close(fd);
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
-static int
-sendResponseRaw (const void *data, size_t dataSize)
-{
-    int fd = s_fdCommand;
-    int ret;
-    uint32_t header;
-
-    if (s_fdCommand < 0) {
-        return -1;
-    }
-
-    if (dataSize > MAX_COMMAND_BYTES) {
-        LOGE("RIL: packet larger than %u (%u)",
-                MAX_COMMAND_BYTES, (unsigned int )dataSize);
-
-        return -1;
-    }
-    
-
-    // FIXME is blocking here ok? issue #550970
-
-    pthread_mutex_lock(&s_writeMutex);
-
-    header = htonl(dataSize);
-
-    ret = blockingWrite(fd, (void *)&header, sizeof(header));
-
-    if (ret < 0) {
-        return ret;
-    }
-
-    blockingWrite(fd, data, dataSize);
-
-    if (ret < 0) {
-        return ret;
-    }
-
-    pthread_mutex_unlock(&s_writeMutex);
-
-    return 0;
-}
-
-static int
-sendResponse (Parcel &p)
-{
-    printResponse;
-    return sendResponseRaw(p.data(), p.dataSize());
-}
-
-/** response is an int* pointing to an array of ints*/
- 
-static int 
-responseInts(Parcel &p, void *response, size_t responselen)
-{
-    int numInts;
-
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-    if (responselen % sizeof(int) != 0) {
-        LOGE("invalid response length %d expected multiple of %d\n", 
-            (int)responselen, (int)sizeof(int));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    int *p_int = (int *) response;
-
-    numInts = responselen / sizeof(int *);
-    p.writeInt32 (numInts);
-
-    /* each int*/
-    startResponse;
-    for (int i = 0 ; i < numInts ; i++) {
-        appendPrintBuf("%s%d,", printBuf, p_int[i]);
-        p.writeInt32(p_int[i]);
-    }
-    removeLastChar;
-    closeResponse;
-
-    return 0;
-}
-
-/** response is a char **, pointing to an array of char *'s */
-static int responseStrings(Parcel &p, void *response, size_t responselen)
-{
-    int numStrings;
-    
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-    if (responselen % sizeof(char *) != 0) {
-        LOGE("invalid response length %d expected multiple of %d\n", 
-            (int)responselen, (int)sizeof(char *));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (response == NULL) {
-        p.writeInt32 (0);
-    } else {
-        char **p_cur = (char **) response;
-
-        numStrings = responselen / sizeof(char *);
-        p.writeInt32 (numStrings);
-
-        /* each string*/
-        startResponse;
-        for (int i = 0 ; i < numStrings ; i++) {
-            appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
-            writeStringToParcel (p, p_cur[i]);
-        }
-        removeLastChar;
-        closeResponse;
-    }
-    return 0;
-}
-
-
-/**
- * NULL strings are accepted 
- * FIXME currently ignores responselen
- */
-static int responseString(Parcel &p, void *response, size_t responselen)
-{
-    /* one string only */
-    startResponse;
-    appendPrintBuf("%s%s", printBuf, (char*)response);
-    closeResponse;
-
-    writeStringToParcel(p, (const char *)response);
-
-    return 0;
-}
-
-static int responseVoid(Parcel &p, void *response, size_t responselen)
-{
-    startResponse;
-    removeLastChar;
-    return 0;
-}
-
-static int responseCallList(Parcel &p, void *response, size_t responselen)
-{    
-    int num;
-
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen % sizeof (RIL_Call *) != 0) {
-        LOGE("invalid response length %d expected multiple of %d\n", 
-            (int)responselen, (int)sizeof (RIL_Call *));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    startResponse;
-    /* number of call info's */
-    num = responselen / sizeof(RIL_Call *);
-    p.writeInt32(num);
-
-    for (int i = 0 ; i < num ; i++) {
-        RIL_Call *p_cur = ((RIL_Call **) response)[i];
-        /* each call info */
-        p.writeInt32(p_cur->state);
-        p.writeInt32(p_cur->index);
-        p.writeInt32(p_cur->toa);
-        p.writeInt32(p_cur->isMpty);
-        p.writeInt32(p_cur->isMT);
-        p.writeInt32(p_cur->als);
-        p.writeInt32(p_cur->isVoice);
-        writeStringToParcel (p, p_cur->number);
-        appendPrintBuf("%s[%s,id=%d,toa=%d,%s,%s,als=%d,%s,%s],", printBuf,
-            callStateToString(p_cur->state),
-            p_cur->index, p_cur->toa,
-            (p_cur->isMpty)?"mpty":"norm",
-            (p_cur->isMT)?"mt":"mo",
-            p_cur->als,
-            (p_cur->isVoice)?"voc":"nonvoc",
-            (char*)p_cur->number);
-    }
-    removeLastChar;
-    closeResponse;
-
-    return 0;
-}
-
-static int responseSMS(Parcel &p, void *response, size_t responselen)
-{
-    if (response == NULL) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen != sizeof (RIL_SMS_Response) ) {
-        LOGE("invalid response length %d expected %d", 
-                (int)responselen, (int)sizeof (RIL_SMS_Response));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
-
-    p.writeInt32(p_cur->messageRef);
-    writeStringToParcel(p, p_cur->ackPDU);
-
-    startResponse;
-    appendPrintBuf("%s%d,%s", printBuf, p_cur->messageRef,
-        (char*)p_cur->ackPDU);
-    closeResponse;
-
-    return 0;
-}
-
-static int responseContexts(Parcel &p, void *response, size_t responselen)
-{
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen % sizeof(RIL_PDP_Context_Response) != 0) {
-        LOGE("invalid response length %d expected multiple of %d", 
-                (int)responselen, (int)sizeof(RIL_PDP_Context_Response));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    int num = responselen / sizeof(RIL_PDP_Context_Response);
-    p.writeInt32(num);
-
-    RIL_PDP_Context_Response *p_cur = (RIL_PDP_Context_Response *) response;
-    startResponse;
-    int i;
-    for (i = 0; i < num; i++) {
-        p.writeInt32(p_cur[i].cid);
-        p.writeInt32(p_cur[i].active);
-        writeStringToParcel(p, p_cur[i].type);
-        writeStringToParcel(p, p_cur[i].apn);
-        writeStringToParcel(p, p_cur[i].address);
-        appendPrintBuf("%s[cid=%d,%s,%s,%s,%s],", printBuf,
-            p_cur[i].cid,
-            (p_cur[i].active==0)?"down":"up",
-            (char*)p_cur[i].type,
-            (char*)p_cur[i].apn,
-            (char*)p_cur[i].address);
-    }
-    removeLastChar;
-    closeResponse;
-
-    return 0;
-}
-
-static int responseRaw(Parcel &p, void *response, size_t responselen)
-{
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL with responselen != 0");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    // The java code reads -1 size as null byte array
-    if (response == NULL) {
-        p.writeInt32(-1);       
-    } else {
-        p.writeInt32(responselen);
-        p.write(response, responselen);
-    }
-
-    return 0;
-}
-
-
-static int responseSIM_IO(Parcel &p, void *response, size_t responselen)
-{
-    if (response == NULL) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen != sizeof (RIL_SIM_IO_Response) ) {
-        LOGE("invalid response length was %d expected %d",
-                (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
-    p.writeInt32(p_cur->sw1);
-    p.writeInt32(p_cur->sw2);
-    writeStringToParcel(p, p_cur->simResponse);
-
-    startResponse;
-    appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
-        (char*)p_cur->simResponse);
-    closeResponse;
-
-
-    return 0;
-}
-
-static int responseCallForwards(Parcel &p, void *response, size_t responselen)
-{
-    int num;
-    
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
-        LOGE("invalid response length %d expected multiple of %d", 
-                (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    /* number of call info's */
-    num = responselen / sizeof(RIL_CallForwardInfo *);
-    p.writeInt32(num);
-
-    startResponse;
-    for (int i = 0 ; i < num ; i++) {
-        RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
-
-        p.writeInt32(p_cur->status);
-        p.writeInt32(p_cur->reason);
-        p.writeInt32(p_cur->serviceClass);
-        p.writeInt32(p_cur->toa);
-        writeStringToParcel(p, p_cur->number);
-        p.writeInt32(p_cur->timeSeconds);
-        appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
-            (p_cur->status==1)?"enable":"disable",
-            p_cur->reason, p_cur->serviceClass, p_cur->toa,
-            (char*)p_cur->number,
-            p_cur->timeSeconds);
-    }
-    removeLastChar;
-    closeResponse;
-    
-    return 0;
-}
-
-static int responseSsn(Parcel &p, void *response, size_t responselen)
-{
-    if (response == NULL) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen != sizeof(RIL_SuppSvcNotification)) {
-        LOGE("invalid response length was %d expected %d",
-                (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
-    p.writeInt32(p_cur->notificationType);
-    p.writeInt32(p_cur->code);
-    p.writeInt32(p_cur->index);
-    p.writeInt32(p_cur->type);
-    writeStringToParcel(p, p_cur->number);
-
-    startResponse;
-    appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
-        (p_cur->notificationType==0)?"mo":"mt",
-         p_cur->code, p_cur->index, p_cur->type,
-        (char*)p_cur->number);
-    closeResponse;
-
-    return 0;
-}
-
-static int responseCellList(Parcel &p, void *response, size_t responselen)
-{
-    int num;
-
-    if (response == NULL && responselen != 0) {
-        LOGE("invalid response: NULL");
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
-        LOGE("invalid response length %d expected multiple of %d\n",
-            (int)responselen, (int)sizeof (RIL_NeighboringCell *));
-        return RIL_ERRNO_INVALID_RESPONSE;
-    }
-
-    startResponse;
-    /* number of cell info's */
-    num = responselen / sizeof(RIL_NeighboringCell *);
-    p.writeInt32(num);
-
-    for (int i = 0 ; i < num ; i++) {
-        RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
-
-        /* each cell info */
-        p.writeInt32(p_cur->rssi);
-        writeStringToParcel (p, p_cur->cid);
-
-        appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
-            p_cur->cid, p_cur->rssi);
-    }
-    removeLastChar;
-    closeResponse;
-
-    return 0;
-}
-
-static void triggerEvLoop()
-{
-    int ret;
-    if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
-        /* trigger event loop to wakeup. No reason to do this,
-         * if we're in the event loop thread */
-         do {
-            ret = write (s_fdWakeupWrite, " ", 1);
-         } while (ret < 0 && errno == EINTR);
-    }
-}
-
-static void rilEventAddWakeup(struct ril_event *ev)
-{
-    ril_event_add(ev);
-    triggerEvLoop();
-}
-
-/**
- * A write on the wakeup fd is done just to pop us out of select()
- * We empty the buffer here and then ril_event will reset the timers on the
- * way back down
- */
-static void processWakeupCallback(int fd, short flags, void *param)
-{
-    char buff[16];
-    int ret;
-
-    LOGV("processWakeupCallback");
-
-    /* empty our wakeup socket out */
-    do {
-        ret = read(s_fdWakeupRead, &buff, sizeof(buff));
-    } while (ret > 0 || (ret < 0 && errno == EINTR)); 
-}
-
-static void onCommandsSocketClosed()
-{
-    int ret;
-    RequestInfo *p_cur;
-
-    /* mark pending requests as "cancelled" so we dont report responses */
-
-    ret = pthread_mutex_lock(&s_pendingRequestsMutex);
-    assert (ret == 0);
-
-    p_cur = s_pendingRequests;
-
-    for (p_cur = s_pendingRequests 
-            ; p_cur != NULL
-            ; p_cur  = p_cur->p_next
-    ) {
-        p_cur->cancelled = 1;
-    }
-
-    ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
-    assert (ret == 0);
-}
-
-static void processCommandsCallback(int fd, short flags, void *param)
-{
-    RecordStream *p_rs;
-    void *p_record;
-    size_t recordlen;
-    int ret;
-
-    assert(fd == s_fdCommand);
-
-    p_rs = (RecordStream *)param;
-
-    for (;;) {
-        /* loop until EAGAIN/EINTR, end of stream, or other error */
-        ret = record_stream_get_next(p_rs, &p_record, &recordlen);
-
-        if (ret == 0 && p_record == NULL) {
-            /* end-of-stream */
-            break;
-        } else if (ret < 0) {
-            break;
-        } else if (ret == 0) { /* && p_record != NULL */
-            processCommandBuffer(p_record, recordlen);
-        }
-    }
-
-    if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
-        /* fatal error or end-of-stream */
-        if (ret != 0) {
-            LOGE("error on reading command socket errno:%d\n", errno);
-        } else {
-            LOGW("EOS.  Closing command socket.");
-        }
-        
-        close(s_fdCommand);
-        s_fdCommand = -1;
-
-        ril_event_del(&s_commands_event);
-
-        record_stream_free(p_rs);
-
-        /* start listening for new connections again */
-        rilEventAddWakeup(&s_listen_event);
-
-        onCommandsSocketClosed();
-    }
-}
-
-
-static void onNewCommandConnect()
-{
-    // implicit radio state changed
-    RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
-                                    NULL, 0);
-
-    // Send last NITZ time data, in case it was missed
-    if (s_lastNITZTimeData != NULL) {
-        sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
-
-        free(s_lastNITZTimeData);
-        s_lastNITZTimeData = NULL;
-    }
-
-    // Get version string
-    if (s_callbacks.getVersion != NULL) {
-        const char *version;
-        version = s_callbacks.getVersion();
-        LOGI("RIL Daemon version: %s\n", version);
-        
-        property_set(PROPERTY_RIL_IMPL, version);
-    } else {
-        LOGI("RIL Daemon version: unavailable\n");
-        property_set(PROPERTY_RIL_IMPL, "unavailable");
-    }
-
-}
-
-static void listenCallback (int fd, short flags, void *param)
-{
-    int ret;
-    int err;
-    int is_phone_socket;
-    RecordStream *p_rs;
-
-    struct sockaddr_un peeraddr;
-    socklen_t socklen = sizeof (peeraddr);
-
-    struct ucred creds;
-    socklen_t szCreds = sizeof(creds);
-
-    struct passwd *pwd = NULL;
-
-    assert (s_fdCommand < 0);
-    assert (fd == s_fdListen);
-    
-    s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
-
-    if (s_fdCommand < 0 ) {
-        LOGE("Error on accept() errno:%d", errno);
-        /* start listening for new connections again */
-        rilEventAddWakeup(&s_listen_event);
-	return;
-    }
-
-    /* check the credential of the other side and only accept socket from
-     * phone process
-     */ 
-    errno = 0;
-    is_phone_socket = 0;
-    
-    err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
-    
-    if (err == 0 && szCreds > 0) {
-      errno = 0;
-      pwd = getpwuid(creds.uid);
-      if (pwd != NULL) {
-	if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
-	  is_phone_socket = 1;
-	} else {
-	  LOGE("RILD can't accept socket from process %s", pwd->pw_name);
-	}
-      } else {
-	LOGE("Error on getpwuid() errno: %d", errno);
-      }
-    } else {
-      LOGD("Error on getsockopt() errno: %d", errno);
-    }
-
-    if ( !is_phone_socket ) {
-      LOGE("RILD must accept socket from %s", PHONE_PROCESS);
-        
-      close(s_fdCommand);
-      s_fdCommand = -1;
-
-      onCommandsSocketClosed();
-
-      /* start listening for new connections again */
-      rilEventAddWakeup(&s_listen_event);
-
-      return;
-    }
-
-    ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
-
-    if (ret < 0) {
-        LOGE ("Error setting O_NONBLOCK errno:%d", errno);
-    }
-
-    LOGI("libril: new connection");
-
-    p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
-
-    ril_event_set (&s_commands_event, s_fdCommand, 1, 
-        processCommandsCallback, p_rs);
-
-    rilEventAddWakeup (&s_commands_event);
-
-    onNewCommandConnect();
-}
-
-static void freeDebugCallbackArgs(int number, char **args) {
-    for (int i = 0; i < number; i++) {
-        if (args[i] != NULL) {
-            free(args[i]);
-        }
-    }
-    free(args);
-}
-
-static void debugCallback (int fd, short flags, void *param)
-{
-    int acceptFD, option;
-    struct sockaddr_un peeraddr;
-    socklen_t socklen = sizeof (peeraddr);
-    int data;
-    unsigned int qxdm_data[6];
-    const char *deactData[1] = {"1"};
-    char *actData[1];
-    RIL_Dial dialData;
-    int hangupData[1] = {1};
-    int number;
-    char **args;
-
-    acceptFD = accept (fd,  (sockaddr *) &peeraddr, &socklen);
-
-    if (acceptFD < 0) {
-        LOGE ("error accepting on debug port: %d\n", errno);
-        return;
-    }
-
-    if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
-        LOGE ("error reading on socket: number of Args: \n");
-        return;
-    }
-    args = (char **) malloc(sizeof(char*) * number);
-
-    for (int i = 0; i < number; i++) {
-        int len;
-        if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
-            LOGE ("error reading on socket: Len of Args: \n");
-            freeDebugCallbackArgs(i, args);
-            return;
-        }
-        // +1 for null-term
-        args[i] = (char *) malloc((sizeof(char) * len) + 1);
-        if (recv(acceptFD, args[i], sizeof(char) * len, 0) 
-            != sizeof(char) * len) {
-            LOGE ("error reading on socket: Args[%d] \n", i);
-            freeDebugCallbackArgs(i, args);
-            return;
-        }
-        char * buf = args[i];
-        buf[len] = 0;
-    }
-
-    switch (atoi(args[0])) {
-        case 0:
-            LOGI ("Connection on debug port: issuing reset.");
-            issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
-            break;
-        case 1:
-            LOGI ("Connection on debug port: issuing radio power off.");
-            data = 0;
-            issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
-            // Close the socket
-            close(s_fdCommand);
-            s_fdCommand = -1;
-            break;
-        case 2:
-            LOGI ("Debug port: issuing unsolicited network change.");
-            RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED,
-                                      NULL, 0);
-            break;
-        case 3:
-            LOGI ("Debug port: QXDM log enable.");
-            qxdm_data[0] = 65536;
-            qxdm_data[1] = 16;
-            qxdm_data[2] = 1;
-            qxdm_data[3] = 32;
-            qxdm_data[4] = 0;
-            qxdm_data[4] = 8;
-            issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data, 
-                              6 * sizeof(int));
-            break;
-        case 4:
-            LOGI ("Debug port: QXDM log disable.");
-            qxdm_data[0] = 65536;
-            qxdm_data[1] = 16;
-            qxdm_data[2] = 0;
-            qxdm_data[3] = 32;
-            qxdm_data[4] = 0;
-            qxdm_data[4] = 8;
-            issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
-                              6 * sizeof(int));
-            break;
-        case 5:
-            LOGI("Debug port: Radio On");
-            data = 1;
-            issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
-            sleep(2);
-            // Set network selection automatic.
-            issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
-            break;
-        case 6:
-            LOGI("Debug port: Setup PDP, Apn :%s\n", args[1]);
-            actData[0] = args[1];
-            issueLocalRequest(RIL_REQUEST_SETUP_DEFAULT_PDP, &actData, 
-                              sizeof(actData));
-            break;
-        case 7:
-            LOGI("Debug port: Deactivate PDP");
-            issueLocalRequest(RIL_REQUEST_DEACTIVATE_DEFAULT_PDP, &deactData, 
-                              sizeof(deactData));
-            break;
-        case 8:
-            LOGI("Debug port: Dial Call");
-            dialData.clir = 0;
-            dialData.address = args[1];
-            issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
-            break;
-        case 9:
-            LOGI("Debug port: Answer Call");
-            issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
-            break;
-        case 10:
-            LOGI("Debug port: End Call");
-            issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData, 
-                              sizeof(hangupData));
-            break;
-        default:
-            LOGE ("Invalid request");
-            break;
-    }
-    freeDebugCallbackArgs(number, args);
-    close(acceptFD);
-}
-
-
-static void userTimerCallback (int fd, short flags, void *param)
-{
-    UserCallbackInfo *p_info;
-
-    p_info = (UserCallbackInfo *)param;
-
-    p_info->p_callback(p_info->userParam);
-
-
-    // FIXME generalize this...there should be a cancel mechanism
-    if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
-        s_last_wake_timeout_info = NULL;
-    }
-
-    free(p_info);
-}
-
-
-static void *
-eventLoop(void *param)
-{
-    int ret;
-    int filedes[2];
-
-    ril_event_init();
-
-    pthread_mutex_lock(&s_startupMutex);
-
-    s_started = 1;
-    pthread_cond_broadcast(&s_startupCond);
-
-    pthread_mutex_unlock(&s_startupMutex);
-
-    ret = pipe(filedes);
-
-    if (ret < 0) {
-        LOGE("Error in pipe() errno:%d", errno);
-        return NULL;
-    }
-
-    s_fdWakeupRead = filedes[0];
-    s_fdWakeupWrite = filedes[1];
-
-    fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
-
-    ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
-                processWakeupCallback, NULL);
-
-    rilEventAddWakeup (&s_wakeupfd_event);
-
-    // Only returns on error
-    ril_event_loop();
-    LOGE ("error in event_loop_base errno:%d", errno);
-
-    return NULL;
-}
-
-extern "C" void 
-RIL_startEventLoop(void)
-{
-    int ret;
-    pthread_attr_t attr;
-    
-    /* spin up eventLoop thread and wait for it to get started */
-    s_started = 0;
-    pthread_mutex_lock(&s_startupMutex);
-
-    pthread_attr_init (&attr);
-    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);    
-    ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
-
-    while (s_started == 0) {
-        pthread_cond_wait(&s_startupCond, &s_startupMutex);
-    }
-
-    pthread_mutex_unlock(&s_startupMutex);
-
-    if (ret < 0) {
-        LOGE("Failed to create dispatch thread errno:%d", errno);
-        return;
-    }
-}
-
-// Used for testing purpose only.
-extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
-    memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
-}
-
-extern "C" void 
-RIL_register (const RIL_RadioFunctions *callbacks)
-{
-    int ret;
-    int flags;
-
-    if (callbacks == NULL 
-        || ! (callbacks->version == RIL_VERSION || callbacks->version == 1)
-    ) {
-        LOGE(
-            "RIL_register: RIL_RadioFunctions * null or invalid version"
-            " (expected %d)", RIL_VERSION);
-        return;
-    }
-
-    if (s_registerCalled > 0) {
-        LOGE("RIL_register has been called more than once. "
-                "Subsequent call ignored");
-        return;
-    }
-
-    memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
-
-    s_registerCalled = 1;
-
-    // Little self-check
-
-    for (int i = 0; i < (int)NUM_ELEMS(s_commands) ; i++) {
-        assert(i == s_commands[i].requestNumber);
-    }
-
-    for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses) ; i++) {
-        assert(i + RIL_UNSOL_RESPONSE_BASE 
-                == s_unsolResponses[i].requestNumber);
-    }
-
-    // New rild impl calls RIL_startEventLoop() first
-    // old standalone impl wants it here.
-
-    if (s_started == 0) {
-        RIL_startEventLoop();
-    }
-
-    // start listen socket
-
-#if 0
-    ret = socket_local_server (SOCKET_NAME_RIL, 
-            ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
-
-    if (ret < 0) {
-        LOGE("Unable to bind socket errno:%d", errno);
-        exit (-1);
-    }
-    s_fdListen = ret;
-
-#else
-    s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
-    if (s_fdListen < 0) {
-        LOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
-        exit(-1);
-    }
-
-    ret = listen(s_fdListen, 4);
-
-    if (ret < 0) {
-        LOGE("Failed to listen on control socket '%d': %s",
-             s_fdListen, strerror(errno));
-        exit(-1);
-    }
-#endif
-
-
-    /* note: non-persistent so we can accept only one connection at a time */
-    ril_event_set (&s_listen_event, s_fdListen, false, 
-                listenCallback, NULL);
-
-    rilEventAddWakeup (&s_listen_event);
-
-#if 1
-    // start debug interface socket
-
-    s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
-    if (s_fdDebug < 0) {
-        LOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
-        exit(-1);
-    }
-
-    ret = listen(s_fdDebug, 4);
-
-    if (ret < 0) {
-        LOGE("Failed to listen on ril debug socket '%d': %s",
-             s_fdDebug, strerror(errno));
-        exit(-1);
-    }
-
-    ril_event_set (&s_debug_event, s_fdDebug, true,
-                debugCallback, NULL);
-
-    rilEventAddWakeup (&s_debug_event);
-#endif
-
-}
-
-static int
-checkAndDequeueRequestInfo(struct RequestInfo *pRI)
-{
-    int ret = 0;
-    
-    if (pRI == NULL) {
-        return 0;
-    }
-
-    pthread_mutex_lock(&s_pendingRequestsMutex);
-
-    for(RequestInfo **ppCur = &s_pendingRequests 
-        ; *ppCur != NULL 
-        ; ppCur = &((*ppCur)->p_next)
-    ) {
-        if (pRI == *ppCur) {
-            ret = 1;
-
-            *ppCur = (*ppCur)->p_next;
-            break;
-        }
-    }
-
-    pthread_mutex_unlock(&s_pendingRequestsMutex);
-
-    return ret;
-}
-
-
-extern "C" void
-RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen)
-{
-    RequestInfo *pRI;
-    int ret;
-    size_t errorOffset;
-
-    pRI = (RequestInfo *)t;
-
-    if (!checkAndDequeueRequestInfo(pRI)) {
-        LOGE ("RIL_onRequestComplete: invalid RIL_Token");
-        return;
-    }
-
-    if (pRI->local > 0) {
-        // Locally issued command...void only!
-        // response does not go back up the command socket
-        LOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
-
-        goto done;
-    }
-
-    appendPrintBuf("[%04d]< %s",
-        pRI->token, requestToString(pRI->pCI->requestNumber));
-
-    if (pRI->cancelled == 0) {
-        Parcel p;
-
-        p.writeInt32 (RESPONSE_SOLICITED);
-        p.writeInt32 (pRI->token);
-        errorOffset = p.dataPosition();
-
-        p.writeInt32 (e);
-
-        if (e == RIL_E_SUCCESS) {
-            /* process response on success */
-            ret = pRI->pCI->responseFunction(p, response, responselen);
-
-            /* if an error occurred, rewind and mark it */
-            if (ret != 0) {
-                p.setDataPosition(errorOffset);
-                p.writeInt32 (ret);
-            }
-        } else {
-            appendPrintBuf("%s returns %s", printBuf, failCauseToString(e));
-        }
-
-        if (s_fdCommand < 0) {
-            LOGD ("RIL onRequestComplete: Command channel closed");
-        }
-        sendResponse(p);
-    }
-
-done:
-    free(pRI);
-}
-
-
-static void
-grabPartialWakeLock()
-{
-    acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
-}
-
-static void
-releaseWakeLock()
-{
-    release_wake_lock(ANDROID_WAKE_LOCK_NAME);
-}
-
-/**
- * Timer callback to put us back to sleep before the default timeout
- */
-static void
-wakeTimeoutCallback (void *param)
-{
-    // We're using "param != NULL" as a cancellation mechanism
-    if (param == NULL) {
-        //LOGD("wakeTimeout: releasing wake lock");
-
-        releaseWakeLock();
-    } else {
-        //LOGD("wakeTimeout: releasing wake lock CANCELLED");
-    }
-}
-
-extern "C"
-void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
-                                size_t datalen)
-{
-    int unsolResponseIndex;
-    int ret;
-    int64_t timeReceived = 0;
-    bool shouldScheduleTimeout = false;
-
-    if (s_registerCalled == 0) {
-        // Ignore RIL_onUnsolicitedResponse before RIL_register
-        LOGW("RIL_onUnsolicitedResponse called before RIL_register");
-        return;
-    }
-
-    unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
-
-    if ((unsolResponseIndex < 0)
-        || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
-        LOGE("unsupported unsolicited response code %d", unsolResponse);
-        return;
-    }
-
-    // Grab a wake lock if needed for this reponse,
-    // as we exit we'll either release it immediately
-    // or set a timer to release it later.
-    switch (s_unsolResponses[unsolResponseIndex].wakeType) {
-        case WAKE_PARTIAL:
-            grabPartialWakeLock();
-            shouldScheduleTimeout = true;
-        break;
-
-        case DONT_WAKE:
-        default:
-            // No wake lock is grabed so don't set timeout
-            shouldScheduleTimeout = false;
-            break;
-    }
-
-    // Mark the time this was received, doing this
-    // after grabing the wakelock incase getting
-    // the elapsedRealTime might cause us to goto
-    // sleep.
-    if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
-        timeReceived = elapsedRealtime();
-    }
-
-    appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
-
-    Parcel p;
-
-    p.writeInt32 (RESPONSE_UNSOLICITED);
-    p.writeInt32 (unsolResponse);
-
-    ret = s_unsolResponses[unsolResponseIndex]
-                .responseFunction(p, data, datalen);
-    if (ret != 0) {
-        // Problem with the response. Don't continue;
-        goto error_exit;
-    }
-
-    // some things get more payload
-    switch(unsolResponse) {
-        case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
-            p.writeInt32(s_callbacks.onStateRequest());
-            appendPrintBuf("%s {%s}", printBuf,
-                radioStateToString(s_callbacks.onStateRequest()));
-        break;
-
-
-        case RIL_UNSOL_NITZ_TIME_RECEIVED:
-            // Store the time that this was received so the
-            // handler of this message can account for
-            // the time it takes to arrive and process. In
-            // particular the system has been known to sleep
-            // before this message can be processed.
-            p.writeInt64(timeReceived);
-        break;
-    }
-
-    ret = sendResponse(p);
-    if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
-
-        // Unfortunately, NITZ time is not poll/update like everything
-        // else in the system. So, if the upstream client isn't connected,
-        // keep a copy of the last NITZ response (with receive time noted
-        // above) around so we can deliver it when it is connected
-
-        if (s_lastNITZTimeData != NULL) {
-            free (s_lastNITZTimeData);
-            s_lastNITZTimeData = NULL;
-        }
-
-        s_lastNITZTimeData = malloc(p.dataSize());
-        s_lastNITZTimeDataSize = p.dataSize();
-        memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
-    }
-
-    // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
-    // FIXME The java code should handshake here to release wake lock
-
-    if (shouldScheduleTimeout) {
-        // Cancel the previous request
-        if (s_last_wake_timeout_info != NULL) {
-            s_last_wake_timeout_info->userParam = (void *)1;
-        }
-
-        s_last_wake_timeout_info
-            = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
-                                            &TIMEVAL_WAKE_TIMEOUT);
-    }
-
-    // Normal exit
-    return;
-
-error_exit:
-    // There was an error and we've got the wake lock so release it.
-    if (shouldScheduleTimeout) {
-        releaseWakeLock();
-    }
-}
-
-/** FIXME generalize this if you track UserCAllbackInfo, clear it  
-    when the callback occurs 
-*/
-static UserCallbackInfo *
-internalRequestTimedCallback (RIL_TimedCallback callback, void *param, 
-                                const struct timeval *relativeTime)
-
-{
-    struct timeval myRelativeTime;
-    UserCallbackInfo *p_info;
-
-    p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
-
-    p_info->p_callback = callback; 
-    p_info->userParam = param;
-
-    if (relativeTime == NULL) {
-        /* treat null parameter as a 0 relative time */
-        memset (&myRelativeTime, 0, sizeof(myRelativeTime));
-    } else {
-        /* FIXME I think event_add's tv param is really const anyway */
-        memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
-    }
-
-    ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
-
-    ril_timer_add(&(p_info->event), &myRelativeTime);
-
-    triggerEvLoop();
-    return p_info;
-}
-
-
-extern "C" void
-RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, 
-                                const struct timeval *relativeTime)
-{
-    internalRequestTimedCallback (callback, param, relativeTime);
-}
-
-const char *
-failCauseToString(RIL_Errno e)
-{
-    switch(e) {
-        case RIL_E_SUCCESS: return "E_SUCCESS";
-        case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";
-        case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
-        case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
-        case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
-        case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
-        case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
-        case RIL_E_CANCELLED: return "E_CANCELLED";
-        case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
-        case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
-        case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
-        default: return "<unknown error>";
-    }
-}
-
-const char *
-radioStateToString(RIL_RadioState s)
-{
-    switch(s) {
-        case RADIO_STATE_OFF: return "RADIO_OFF";
-        case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
-        case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
-        case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
-        case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
-        default: return "<unknown state>";
-    }
-}
-
-const char *
-callStateToString(RIL_CallState s)
-{
-    switch(s) {
-        case RIL_CALL_ACTIVE : return "ACTIVE";
-        case RIL_CALL_HOLDING: return "HOLDING";
-        case RIL_CALL_DIALING: return "DIALING";
-        case RIL_CALL_ALERTING: return "ALERTING";
-        case RIL_CALL_INCOMING: return "INCOMING";
-        case RIL_CALL_WAITING: return "WAITING";
-        default: return "<unknown state>";
-    }
-}
-
-const char *
-requestToString(int request) 
-{
-/*
- cat libs/telephony/ril_commands.h \
- | egrep "^ *{RIL_" \
- | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
-
-
- cat libs/telephony/ril_unsol_commands.h \
- | egrep "^ *{RIL_" \
- | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
-
-*/
-    switch(request) {
-        case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
-        case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
-        case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
-        case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
-        case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
-        case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
-        case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
-        case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
-        case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
-        case RIL_REQUEST_DIAL: return "DIAL";
-        case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
-        case RIL_REQUEST_HANGUP: return "HANGUP";
-        case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
-        case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
-        case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
-        case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
-        case RIL_REQUEST_UDUB: return "UDUB";
-        case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
-        case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
-        case RIL_REQUEST_REGISTRATION_STATE: return "REGISTRATION_STATE";
-        case RIL_REQUEST_GPRS_REGISTRATION_STATE: return "GPRS_REGISTRATION_STATE";
-        case RIL_REQUEST_OPERATOR: return "OPERATOR";
-        case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
-        case RIL_REQUEST_DTMF: return "DTMF";
-        case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
-        case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
-        case RIL_REQUEST_SETUP_DEFAULT_PDP: return "SETUP_DEFAULT_PDP";
-        case RIL_REQUEST_SIM_IO: return "SIM_IO";
-        case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
-        case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
-        case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
-        case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
-        case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
-        case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
-        case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
-        case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
-        case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
-        case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
-        case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
-        case RIL_REQUEST_ANSWER: return "ANSWER";
-        case RIL_REQUEST_DEACTIVATE_DEFAULT_PDP: return "DEACTIVATE_DEFAULT_PDP";
-        case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
-        case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
-        case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
-        case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
-        case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
-        case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
-        case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
-        case RIL_REQUEST_DTMF_START: return "DTMF_START";
-        case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
-        case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
-        case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
-        case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
-        case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
-        case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
-        case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
-        case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
-        case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
-        case RIL_REQUEST_LAST_PDP_FAIL_CAUSE: return "LAST_PDP_FAIL_CAUSE";
-        case RIL_REQUEST_PDP_CONTEXT_LIST: return "PDP_CONTEXT_LIST";
-        case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
-        case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
-        case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
-	    case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
-	    case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
-        case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
-        case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
-        case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
-        case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
-        case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
-        case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
-        case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
-        case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
-
-        case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
-        case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
-        case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_NETWORK_STATE_CHANGED";
-        case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
-        case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
-        case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
-        case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
-        case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
-        case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
-        case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
-        case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
-        case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
-        case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
-        case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
-        case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
-        case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
-        case RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED: return "UNSOL_PDP_CONTEXT_LIST_CHANGED";
-        case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
-        default: return "<unknown request>";
-    }
-}
-
-} /* namespace android */
diff --git a/libril/ril_commands.h b/libril/ril_commands.h
deleted file mode 100644
index a097da0..0000000
--- a/libril/ril_commands.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* //device/libs/telephony/ril_commands.h
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-    {0, NULL, NULL},                   //none
-    {RIL_REQUEST_GET_SIM_STATUS,dispatchVoid, responseInts},
-    {RIL_REQUEST_ENTER_SIM_PIN, dispatchStrings, responseVoid},
-    {RIL_REQUEST_ENTER_SIM_PUK, dispatchStrings, responseVoid},
-    {RIL_REQUEST_ENTER_SIM_PIN2, dispatchStrings, responseVoid},
-    {RIL_REQUEST_ENTER_SIM_PUK2, dispatchStrings, responseVoid},
-    {RIL_REQUEST_CHANGE_SIM_PIN, dispatchStrings, responseVoid},
-    {RIL_REQUEST_CHANGE_SIM_PIN2, dispatchStrings, responseVoid},
-    {RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, dispatchStrings, responseVoid},
-    {RIL_REQUEST_GET_CURRENT_CALLS, dispatchVoid, responseCallList},
-    {RIL_REQUEST_DIAL, dispatchDial, responseVoid},   
-    {RIL_REQUEST_GET_IMSI, dispatchVoid, responseString},
-    {RIL_REQUEST_HANGUP, dispatchInts, responseVoid},
-    {RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, dispatchVoid, responseVoid},
-    {RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, dispatchVoid, responseVoid},
-    {RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, dispatchVoid, responseVoid},
-    {RIL_REQUEST_CONFERENCE, dispatchVoid, responseVoid},
-    {RIL_REQUEST_UDUB, dispatchVoid, responseVoid},
-    {RIL_REQUEST_LAST_CALL_FAIL_CAUSE, dispatchVoid, responseInts},
-    {RIL_REQUEST_SIGNAL_STRENGTH, dispatchVoid, responseInts},
-    {RIL_REQUEST_REGISTRATION_STATE, dispatchVoid, responseStrings},
-    {RIL_REQUEST_GPRS_REGISTRATION_STATE, dispatchVoid, responseStrings},
-    {RIL_REQUEST_OPERATOR, dispatchVoid, responseStrings},
-    {RIL_REQUEST_RADIO_POWER, dispatchInts, responseVoid},
-    {RIL_REQUEST_DTMF, dispatchString, responseVoid},
-    {RIL_REQUEST_SEND_SMS, dispatchStrings, responseSMS},
-    {RIL_REQUEST_SEND_SMS_EXPECT_MORE, dispatchStrings, responseSMS},
-    {RIL_REQUEST_SETUP_DEFAULT_PDP, dispatchStrings, responseStrings},
-    {RIL_REQUEST_SIM_IO, dispatchSIM_IO, responseSIM_IO},
-    {RIL_REQUEST_SEND_USSD, dispatchString, responseVoid},
-    {RIL_REQUEST_CANCEL_USSD, dispatchVoid, responseVoid},
-    {RIL_REQUEST_GET_CLIR, dispatchVoid, responseInts},
-    {RIL_REQUEST_SET_CLIR, dispatchInts, responseVoid},
-    {RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, dispatchCallForward, responseCallForwards},
-    {RIL_REQUEST_SET_CALL_FORWARD, dispatchCallForward, responseVoid},
-    {RIL_REQUEST_QUERY_CALL_WAITING, dispatchInts, responseInts},
-    {RIL_REQUEST_SET_CALL_WAITING, dispatchInts, responseVoid},
-    {RIL_REQUEST_SMS_ACKNOWLEDGE, dispatchInts, responseVoid},
-    {RIL_REQUEST_GET_IMEI, dispatchVoid, responseString},
-    {RIL_REQUEST_GET_IMEISV, dispatchVoid, responseString},
-    {RIL_REQUEST_ANSWER,dispatchVoid, responseVoid},
-    {RIL_REQUEST_DEACTIVATE_DEFAULT_PDP, dispatchStrings, responseVoid},
-    {RIL_REQUEST_QUERY_FACILITY_LOCK, dispatchStrings, responseInts},    
-    {RIL_REQUEST_SET_FACILITY_LOCK, dispatchStrings, responseVoid},
-    {RIL_REQUEST_CHANGE_BARRING_PASSWORD, dispatchStrings, responseVoid},
-    {RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, dispatchVoid, responseInts},
-    {RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, dispatchVoid, responseVoid},
-    {RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, dispatchString, responseVoid},
-    {RIL_REQUEST_QUERY_AVAILABLE_NETWORKS , dispatchVoid, responseStrings},
-    {RIL_REQUEST_DTMF_START, dispatchString, responseVoid},
-    {RIL_REQUEST_DTMF_STOP, dispatchVoid, responseVoid},
-    {RIL_REQUEST_BASEBAND_VERSION, dispatchVoid, responseString},
-    {RIL_REQUEST_SEPARATE_CONNECTION, dispatchInts, responseVoid},
-    {RIL_REQUEST_SET_MUTE, dispatchInts, responseVoid},
-    {RIL_REQUEST_GET_MUTE, dispatchVoid, responseInts},
-    {RIL_REQUEST_QUERY_CLIP, dispatchVoid, responseInts},
-    {RIL_REQUEST_LAST_PDP_FAIL_CAUSE, dispatchVoid, responseInts},
-    {RIL_REQUEST_PDP_CONTEXT_LIST, dispatchVoid, responseContexts},
-    {RIL_REQUEST_RESET_RADIO, dispatchVoid, responseVoid},
-    {RIL_REQUEST_OEM_HOOK_RAW, dispatchRaw, responseRaw},
-    {RIL_REQUEST_OEM_HOOK_STRINGS, dispatchStrings, responseStrings},
-    {RIL_REQUEST_SCREEN_STATE, dispatchInts, responseVoid},
-    {RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, dispatchInts, responseVoid},
-    {RIL_REQUEST_WRITE_SMS_TO_SIM, dispatchSmsWrite, responseInts},
-    {RIL_REQUEST_DELETE_SMS_ON_SIM, dispatchInts, responseVoid},
-    {RIL_REQUEST_SET_BAND_MODE, dispatchInts, responseVoid},
-    {RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, dispatchVoid, responseInts},
-    {RIL_REQUEST_STK_GET_PROFILE, dispatchVoid, responseString},
-    {RIL_REQUEST_STK_SET_PROFILE, dispatchString, responseVoid},
-    {RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, dispatchString, responseString},
-    {RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, dispatchString, responseVoid},
-    {RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM, dispatchInts, responseVoid},
-    {RIL_REQUEST_EXPLICIT_CALL_TRANSFER, dispatchVoid, responseVoid},
-    {RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, dispatchInts, responseVoid},
-    {RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, dispatchVoid, responseInts},
-    {RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, dispatchVoid, responseCellList},
-    {RIL_REQUEST_SET_LOCATION_UPDATES, dispatchInts, responseVoid}
diff --git a/libril/ril_event.cpp b/libril/ril_event.cpp
deleted file mode 100644
index 46e2cc9..0000000
--- a/libril/ril_event.cpp
+++ /dev/null
@@ -1,368 +0,0 @@
-/* //device/libs/telephony/ril_event.cpp
-**
-** Copyright 2008, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-#define LOG_TAG "RILC"
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <utils/Log.h>
-#include <ril_event.h>
-#include <string.h>
-#include <sys/time.h>
-#include <time.h>
-
-#include <pthread.h>
-static pthread_mutex_t listMutex;
-#define MUTEX_ACQUIRE() pthread_mutex_lock(&listMutex)
-#define MUTEX_RELEASE() pthread_mutex_unlock(&listMutex)
-#define MUTEX_INIT() pthread_mutex_init(&listMutex, NULL)
-#define MUTEX_DESTROY() pthread_mutex_destroy(&listMutex)
-
-#ifndef timeradd
-#define timeradd(tvp, uvp, vvp)						\
-	do {								\
-		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
-		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
-		if ((vvp)->tv_usec >= 1000000) {			\
-			(vvp)->tv_sec++;				\
-			(vvp)->tv_usec -= 1000000;			\
-		}							\
-	} while (0)
-#endif
-
-#ifndef timercmp
-#define timercmp(a, b, op)               \
-        ((a)->tv_sec == (b)->tv_sec      \
-        ? (a)->tv_usec op (b)->tv_usec   \
-        : (a)->tv_sec op (b)->tv_sec)
-#endif
-
-#ifndef timersub
-#define timersub(a, b, res)                           \
-    do {                                              \
-        (res)->tv_sec = (a)->tv_sec - (b)->tv_sec;    \
-        (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
-        if ((res)->tv_usec < 0) {                     \
-            (res)->tv_usec += 1000000;                \
-            (res)->tv_sec -= 1;                       \
-        }                                             \
-    } while(0);
-#endif
-
-static fd_set readFds;
-static int nfds = 0;
-
-static struct ril_event * watch_table[MAX_FD_EVENTS];
-static struct ril_event timer_list;
-static struct ril_event pending_list;
-
-#define DEBUG 0
-
-#if DEBUG
-#define dlog(x...) LOGD( x )
-static void dump_event(struct ril_event * ev)
-{
-    dlog("~~~~ Event %x ~~~~", (unsigned int)ev);
-    dlog("     next    = %x", (unsigned int)ev->next);
-    dlog("     prev    = %x", (unsigned int)ev->prev);
-    dlog("     fd      = %d", ev->fd);
-    dlog("     pers    = %d", ev->persist);
-    dlog("     timeout = %ds + %dus", (int)ev->timeout.tv_sec, (int)ev->timeout.tv_usec);
-    dlog("     func    = %x", (unsigned int)ev->func);
-    dlog("     param   = %x", (unsigned int)ev->param);
-    dlog("~~~~~~~~~~~~~~~~~~");
-}
-#else
-#define dlog(x...)
-#define dump_event(x)
-#endif
-
-static void getNow(struct timeval * tv)
-{
-#ifdef HAVE_POSIX_CLOCKS
-    struct timespec ts;
-    clock_gettime(CLOCK_MONOTONIC, &ts);
-    tv->tv_sec = ts.tv_sec;
-    tv->tv_usec = ts.tv_nsec/1000;
-#else
-    gettimeofday(tv, NULL);
-#endif
-}
-
-static void init_list(struct ril_event * list)
-{
-    memset(list, 0, sizeof(struct ril_event));
-    list->next = list;
-    list->prev = list;
-    list->fd = -1;
-}
-
-static void addToList(struct ril_event * ev, struct ril_event * list)
-{
-    ev->next = list;
-    ev->prev = list->prev;
-    ev->prev->next = ev;
-    list->prev = ev;
-    dump_event(ev);
-}
-
-static void removeFromList(struct ril_event * ev)
-{
-    dlog("~~~~ Removing event ~~~~");
-    dump_event(ev);
-
-    ev->next->prev = ev->prev;
-    ev->prev->next = ev->next;
-    ev->next = NULL;
-    ev->prev = NULL;
-}
-
-
-static void removeWatch(struct ril_event * ev, int index)
-{
-    watch_table[index] = NULL;
-    ev->index = -1;
-
-    FD_CLR(ev->fd, &readFds);
-
-    if (ev->fd+1 == nfds) {
-        int n = 0;
-
-        for (int i = 0; i < MAX_FD_EVENTS; i++) {
-            struct ril_event * rev = watch_table[i];
-
-            if ((rev != NULL) && (rev->fd > n)) {
-                n = rev->fd;
-            }
-        }
-        nfds = n + 1; 
-        dlog("~~~~ nfds = %d ~~~~", nfds);
-    }
-}
-
-static void processTimeouts()
-{
-    dlog("~~~~ +processTimeouts ~~~~");
-    MUTEX_ACQUIRE();
-    struct timeval now;
-    struct ril_event * tev = timer_list.next;
-    struct ril_event * next;
-
-    getNow(&now);
-    // walk list, see if now >= ev->timeout for any events
-
-    dlog("~~~~ Looking for timers <= %ds + %dus ~~~~", (int)now.tv_sec, (int)now.tv_usec);
-    while ((tev != &timer_list) && (timercmp(&now, &tev->timeout, >))) {
-        // Timer expired
-        dlog("~~~~ firing timer ~~~~");
-        next = tev->next;
-        removeFromList(tev);
-        addToList(tev, &pending_list);
-        tev = next;
-    }
-    MUTEX_RELEASE();
-    dlog("~~~~ -processTimeouts ~~~~");
-}
-
-static void processReadReadies(fd_set * rfds, int n)
-{
-    dlog("~~~~ +processReadReadies (%d) ~~~~", n);
-    MUTEX_ACQUIRE();
-
-    for (int i = 0; (i < MAX_FD_EVENTS) && (n > 0); i++) {
-        struct ril_event * rev = watch_table[i];
-        if (rev != NULL && FD_ISSET(rev->fd, rfds)) {
-            addToList(rev, &pending_list);
-            if (rev->persist == false) {
-                removeWatch(rev, i);
-            }
-            n--;
-        }
-    }
-
-    MUTEX_RELEASE();
-    dlog("~~~~ -processReadReadies (%d) ~~~~", n);
-}
-
-static void firePending()
-{
-    dlog("~~~~ +firePending ~~~~");
-    struct ril_event * ev = pending_list.next;
-    while (ev != &pending_list) {
-        struct ril_event * next = ev->next;
-        removeFromList(ev);
-        ev->func(ev->fd, 0, ev->param); 
-        ev = next;
-    }
-    dlog("~~~~ -firePending ~~~~");
-}
-
-static int calcNextTimeout(struct timeval * tv)
-{
-    struct ril_event * tev = timer_list.next;
-    struct timeval now;
-
-    getNow(&now);
-
-    // Sorted list, so calc based on first node
-    if (tev == &timer_list) {
-        // no pending timers
-        return -1;
-    }
-
-    dlog("~~~~ now = %ds + %dus ~~~~", (int)now.tv_sec, (int)now.tv_usec);
-    dlog("~~~~ next = %ds + %dus ~~~~",
-            (int)tev->timeout.tv_sec, (int)tev->timeout.tv_usec);
-    if (timercmp(&tev->timeout, &now, >)) {
-        timersub(&tev->timeout, &now, tv);
-    } else {
-        // timer already expired.
-        tv->tv_sec = tv->tv_usec = 0;
-    }
-    return 0;
-}
-
-// Initialize internal data structs
-void ril_event_init()
-{
-    MUTEX_INIT();
-
-    FD_ZERO(&readFds);
-    init_list(&timer_list);
-    init_list(&pending_list);
-    memset(watch_table, 0, sizeof(watch_table));
-}
-
-// Initialize an event
-void ril_event_set(struct ril_event * ev, int fd, bool persist, ril_event_cb func, void * param)
-{
-    dlog("~~~~ ril_event_set %x ~~~~", (unsigned int)ev);
-    memset(ev, 0, sizeof(struct ril_event));
-    ev->fd = fd;
-    ev->index = -1;
-    ev->persist = persist;
-    ev->func = func;
-    ev->param = param;
-    fcntl(fd, F_SETFL, O_NONBLOCK);
-}
-
-// Add event to watch list
-void ril_event_add(struct ril_event * ev)
-{
-    dlog("~~~~ +ril_event_add ~~~~");
-    MUTEX_ACQUIRE();
-    for (int i = 0; i < MAX_FD_EVENTS; i++) {
-        if (watch_table[i] == NULL) {
-            watch_table[i] = ev;
-            ev->index = i;
-            dlog("~~~~ added at %d ~~~~", i);
-            dump_event(ev);
-            FD_SET(ev->fd, &readFds);
-            if (ev->fd >= nfds) nfds = ev->fd+1;
-            dlog("~~~~ nfds = %d ~~~~", nfds);
-            break;
-        } 
-    }
-    MUTEX_RELEASE();
-    dlog("~~~~ -ril_event_add ~~~~");
-}
-
-// Add timer event
-void ril_timer_add(struct ril_event * ev, struct timeval * tv)
-{
-    dlog("~~~~ +ril_timer_add ~~~~");
-    MUTEX_ACQUIRE();
-
-    struct ril_event * list;
-    if (tv != NULL) {
-        // add to timer list
-        list = timer_list.next;
-        ev->fd = -1; // make sure fd is invalid
-
-        struct timeval now;
-        getNow(&now);
-        timeradd(&now, tv, &ev->timeout);
-
-        // keep list sorted
-        while (timercmp(&list->timeout, &ev->timeout, < )
-                && (list != &timer_list)) {
-            list = list->next;
-        }
-        // list now points to the first event older than ev
-        addToList(ev, list);
-    } 
-
-    MUTEX_RELEASE();
-    dlog("~~~~ -ril_timer_add ~~~~");
-}
-
-// Remove event from watch or timer list
-void ril_event_del(struct ril_event * ev)
-{
-    dlog("~~~~ +ril_event_del ~~~~");
-    MUTEX_ACQUIRE();
-
-    if (ev->index < 0 || ev->index >= MAX_FD_EVENTS) {
-        return;
-    }
-
-    removeWatch(ev, ev->index);
-
-    MUTEX_RELEASE();
-    dlog("~~~~ -ril_event_del ~~~~");
-}
-
-void ril_event_loop()
-{
-    int n;
-    fd_set rfds;
-    struct timeval tv;
-    struct timeval * ptv;
-
-
-    for (;;) {
-
-        // make local copy of read fd_set
-        memcpy(&rfds, &readFds, sizeof(fd_set));
-        if (-1 == calcNextTimeout(&tv)) {
-            // no pending timers; block indefinitely
-            dlog("~~~~ no timers; blocking indefinitely ~~~~");
-            ptv = NULL;
-        } else {
-            dlog("~~~~ blocking for %ds + %dus ~~~~", (int)tv.tv_sec, (int)tv.tv_usec);
-            ptv = &tv;
-        }
-        n = select(nfds, &rfds, NULL, NULL, ptv);
-        dlog("~~~~ %d events fired ~~~~", n);
-        if (n < 0) {
-            if (errno == EINTR) continue;
-
-            LOGE("ril_event: select error (%d)", errno);
-            // bail?
-            return;
-        }
-
-        // Check for timeouts
-        processTimeouts();
-        // Check for read-ready
-        processReadReadies(&rfds, n);
-        // Fire away
-        firePending();
-    }
-}
diff --git a/libril/ril_event.h b/libril/ril_event.h
deleted file mode 100644
index 420dbc0..0000000
--- a/libril/ril_event.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* //device/libs/telephony/ril_event.h
-**
-** Copyright 2008, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-// Max number of fd's we watch at any one time.  Increase if necessary.
-#define MAX_FD_EVENTS 8
-
-typedef void (*ril_event_cb)(int fd, short events, void *userdata);
-
-struct ril_event {
-    struct ril_event *next;
-    struct ril_event *prev;
-
-    int fd;
-    int index;
-    bool persist;
-    struct timeval timeout;
-    ril_event_cb func;
-    void *param;
-};
-
-// Initialize internal data structs
-void ril_event_init();
-
-// Initialize an event
-void ril_event_set(struct ril_event * ev, int fd, bool persist, ril_event_cb func, void * param);
-
-// Add event to watch list
-void ril_event_add(struct ril_event * ev);
-
-// Add timer event
-void ril_timer_add(struct ril_event * ev, struct timeval * tv);
-
-// Remove event from watch list
-void ril_event_del(struct ril_event * ev);
-
-// Event loop
-void ril_event_loop();
-
diff --git a/libril/ril_unsol_commands.h b/libril/ril_unsol_commands.h
deleted file mode 100644
index 40f76d1..0000000
--- a/libril/ril_unsol_commands.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* //device/libs/telephony/ril_unsol_commands.h
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-    {RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
-    {RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
-    {RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
-    {RIL_UNSOL_RESPONSE_NEW_SMS, responseString, WAKE_PARTIAL},
-    {RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT, responseString, WAKE_PARTIAL},
-    {RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM, responseInts, WAKE_PARTIAL},
-    {RIL_UNSOL_ON_USSD, responseStrings, WAKE_PARTIAL},
-    {RIL_UNSOL_ON_USSD_REQUEST, responseVoid, DONT_WAKE},
-    {RIL_UNSOL_NITZ_TIME_RECEIVED, responseString, WAKE_PARTIAL},
-    {RIL_UNSOL_SIGNAL_STRENGTH, responseInts, DONT_WAKE},
-    {RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED, responseContexts, WAKE_PARTIAL},
-    {RIL_UNSOL_SUPP_SVC_NOTIFICATION, responseSsn, WAKE_PARTIAL},
-    {RIL_UNSOL_STK_SESSION_END, responseVoid, WAKE_PARTIAL},
-    {RIL_UNSOL_STK_PROACTIVE_COMMAND, responseString, WAKE_PARTIAL},
-    {RIL_UNSOL_STK_EVENT_NOTIFY, responseString, WAKE_PARTIAL},
-    {RIL_UNSOL_STK_CALL_SETUP, responseInts, WAKE_PARTIAL},
-    {RIL_UNSOL_SIM_SMS_STORAGE_FULL, responseVoid, WAKE_PARTIAL},
-    {RIL_UNSOL_SIM_REFRESH, responseInts, WAKE_PARTIAL},
-    {RIL_UNSOL_CALL_RING, responseVoid, WAKE_PARTIAL}
diff --git a/reference-ril/Android.mk b/reference-ril/Android.mk
deleted file mode 100644
index 7ec1f97..0000000
--- a/reference-ril/Android.mk
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright 2006 The Android Open Source Project
-
-# XXX using libutils for simulator build only...
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    reference-ril.c \
-    atchannel.c \
-    misc.c \
-    at_tok.c
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils libutils libril
-
-	# for asprinf
-LOCAL_CFLAGS := -D_GNU_SOURCE
-
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
-
-ifeq ($(TARGET_DEVICE),sooner)
-  LOCAL_CFLAGS += -DOMAP_CSMI_POWER_CONTROL -DUSE_TI_COMMANDS 
-endif
-
-ifeq ($(TARGET_DEVICE),surf)
-  LOCAL_CFLAGS += -DPOLL_CALL_STATE -DUSE_QMI
-endif
-
-ifeq ($(TARGET_DEVICE),dream)
-  LOCAL_CFLAGS += -DPOLL_CALL_STATE -DUSE_QMI
-endif
-
-ifeq (foo,foo)
-  #build shared library
-  LOCAL_SHARED_LIBRARIES += \
-	libcutils libutils
-  LOCAL_LDLIBS += -lpthread
-  LOCAL_CFLAGS += -DRIL_SHLIB
-  LOCAL_MODULE:= libreference-ril
-  include $(BUILD_SHARED_LIBRARY)
-else
-  #build executable
-  LOCAL_SHARED_LIBRARIES += \
-	libril
-  LOCAL_MODULE:= reference-ril
-  include $(BUILD_EXECUTABLE)
-endif
diff --git a/reference-ril/MODULE_LICENSE_APACHE2 b/reference-ril/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/reference-ril/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/reference-ril/NOTICE b/reference-ril/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/reference-ril/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
-   Copyright (c) 2005-2008, The Android Open Source Project
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
diff --git a/reference-ril/at_tok.c b/reference-ril/at_tok.c
deleted file mode 100644
index 11e0cba..0000000
--- a/reference-ril/at_tok.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/* //device/system/reference-ril/at_tok.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-#include "at_tok.h"
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-
-/**
- * Starts tokenizing an AT response string
- * returns -1 if this is not a valid response string, 0 on success.
- * updates *p_cur with current position
- */
-int at_tok_start(char **p_cur)
-{
-    if (*p_cur == NULL) {
-        return -1;
-    }
-
-    // skip prefix
-    // consume "^[^:]:"
-
-    *p_cur = strchr(*p_cur, ':');
-
-    if (*p_cur == NULL) {
-        return -1;
-    }
-
-    (*p_cur)++;
-
-    return 0;
-}
-
-static void skipWhiteSpace(char **p_cur)
-{
-    if (*p_cur == NULL) return;
-
-    while (**p_cur != '\0' && isspace(**p_cur)) {
-        (*p_cur)++;
-    }
-}
-
-static void skipNextComma(char **p_cur)
-{
-    if (*p_cur == NULL) return;
-
-    while (**p_cur != '\0' && **p_cur != ',') {
-        (*p_cur)++;
-    }
-
-    if (**p_cur == ',') {
-        (*p_cur)++;
-    }    
-}
-
-static char * nextTok(char **p_cur)
-{
-    char *ret = NULL;
-
-    skipWhiteSpace(p_cur);
-
-    if (*p_cur == NULL) {
-        ret = NULL;
-    } else if (**p_cur == '"') {
-        (*p_cur)++;
-        ret = strsep(p_cur, "\"");
-        skipNextComma(p_cur);
-    } else {
-        ret = strsep(p_cur, ",");
-    }
-
-    return ret;
-}
-
-
-/**
- * Parses the next integer in the AT response line and places it in *p_out
- * returns 0 on success and -1 on fail
- * updates *p_cur
- * "base" is the same as the base param in strtol
- */
-
-static int at_tok_nextint_base(char **p_cur, int *p_out, int base, int  uns)
-{
-    char *ret;
-    
-    if (*p_cur == NULL) {
-        return -1;
-    }
-
-    ret = nextTok(p_cur);
-
-    if (ret == NULL) {
-        return -1;
-    } else {
-        long l;
-        char *end;
-
-        if (uns)
-            l = strtoul(ret, &end, base);
-        else
-            l = strtol(ret, &end, base);
-
-        *p_out = (int)l;
-
-        if (end == ret) {
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
-/**
- * Parses the next base 10 integer in the AT response line 
- * and places it in *p_out
- * returns 0 on success and -1 on fail
- * updates *p_cur
- */
-int at_tok_nextint(char **p_cur, int *p_out)
-{
-    return at_tok_nextint_base(p_cur, p_out, 10, 0);
-}
-
-/**
- * Parses the next base 16 integer in the AT response line 
- * and places it in *p_out
- * returns 0 on success and -1 on fail
- * updates *p_cur
- */
-int at_tok_nexthexint(char **p_cur, int *p_out)
-{
-    return at_tok_nextint_base(p_cur, p_out, 16, 1);
-}
-
-int at_tok_nextbool(char **p_cur, char *p_out)
-{
-    int ret;
-    int result;
-
-    ret = at_tok_nextint(p_cur, &result);
-
-    if (ret < 0) {
-        return -1;
-    }
-
-    // booleans should be 0 or 1
-    if (!(result == 0 || result == 1)) {
-        return -1;
-    }
-
-    if (p_out != NULL) {
-        *p_out = (char)result;
-    }
-
-    return ret;
-}
-
-int at_tok_nextstr(char **p_cur, char **p_out)
-{
-    if (*p_cur == NULL) {
-        return -1;
-    }
-
-    *p_out = nextTok(p_cur);
-
-    return 0;
-}
-
-/** returns 1 on "has more tokens" and 0 if no */
-int at_tok_hasmore(char **p_cur)
-{
-    return ! (*p_cur == NULL || **p_cur == '\0');
-}
-
-
diff --git a/reference-ril/at_tok.h b/reference-ril/at_tok.h
deleted file mode 100644
index 42bb4c9..0000000
--- a/reference-ril/at_tok.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* //device/system/reference-ril/at_tok.h
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-#ifndef AT_TOK_H
-#define AT_TOK_H 1
-
-int at_tok_start(char **p_cur);
-int at_tok_nextint(char **p_cur, int *p_out);
-int at_tok_nexthexint(char **p_cur, int *p_out);
-
-int at_tok_nextbool(char **p_cur, char *p_out);
-int at_tok_nextstr(char **p_cur, char **out);
-
-int at_tok_hasmore(char **p_cur);
-
-#endif /*AT_TOK_H */
diff --git a/reference-ril/atchannel.c b/reference-ril/atchannel.c
deleted file mode 100644
index f878b35..0000000
--- a/reference-ril/atchannel.c
+++ /dev/null
@@ -1,1018 +0,0 @@
-/* //device/system/reference-ril/atchannel.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include "atchannel.h"
-#include "at_tok.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <time.h>
-#include <unistd.h>
-
-#define LOG_NDEBUG 0
-#define LOG_TAG "AT"
-#include <utils/Log.h>
-
-#ifdef HAVE_ANDROID_OS
-/* for IOCTL's */
-#include <linux/omap_csmi.h>
-#endif /*HAVE_ANDROID_OS*/
-
-#include "misc.h"
-
-#ifdef HAVE_ANDROID_OS
-#define USE_NP 1
-#endif /* HAVE_ANDROID_OS */
-
-
-#define NUM_ELEMS(x) (sizeof(x)/sizeof(x[0]))
-
-#define MAX_AT_RESPONSE (8 * 1024)
-#define HANDSHAKE_RETRY_COUNT 8
-#define HANDSHAKE_TIMEOUT_MSEC 250
-
-static pthread_t s_tid_reader;
-static int s_fd = -1;    /* fd of the AT channel */
-static ATUnsolHandler s_unsolHandler;
-
-/* for input buffering */
-
-static char s_ATBuffer[MAX_AT_RESPONSE+1];
-static char *s_ATBufferCur = s_ATBuffer;
-
-static int s_ackPowerIoctl; /* true if TTY has android byte-count
-                                handshake for low power*/
-static int s_readCount = 0;
-
-#if AT_DEBUG
-void  AT_DUMP(const char*  prefix, const char*  buff, int  len)
-{
-    if (len < 0)
-        len = strlen(buff);
-    LOGD("%.*s", len, buff);
-}
-#endif
-
-/*
- * for current pending command
- * these are protected by s_commandmutex
- */
-
-static pthread_mutex_t s_commandmutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t s_commandcond = PTHREAD_COND_INITIALIZER;
-
-static ATCommandType s_type;
-static const char *s_responsePrefix = NULL;
-static const char *s_smsPDU = NULL;
-static ATResponse *sp_response = NULL;
-
-static void (*s_onTimeout)(void) = NULL;
-static void (*s_onReaderClosed)(void) = NULL;
-static int s_readerClosed;
-
-static void onReaderClosed();
-static int writeCtrlZ (const char *s);
-static int writeline (const char *s);
-
-#ifndef USE_NP
-static void setTimespecRelative(struct timespec *p_ts, long long msec)
-{
-    struct timeval tv;
-
-    gettimeofday(&tv, (struct timezone *) NULL);
-
-    /* what's really funny about this is that I know
-       pthread_cond_timedwait just turns around and makes this
-       a relative time again */
-    p_ts->tv_sec = tv.tv_sec + (msec / 1000);
-    p_ts->tv_nsec = (tv.tv_usec + (msec % 1000) * 1000L ) * 1000L;
-}
-#endif /*USE_NP*/
-
-static void sleepMsec(long long msec)
-{
-    struct timespec ts;
-    int err;
-
-    ts.tv_sec = (msec / 1000);
-    ts.tv_nsec = (msec % 1000) * 1000 * 1000;
-
-    do {
-        err = nanosleep (&ts, &ts);
-    } while (err < 0 && errno == EINTR);
-}
-
-
-
-/** add an intermediate response to sp_response*/
-static void addIntermediate(const char *line)
-{
-    ATLine *p_new;
-
-    p_new = (ATLine  *) malloc(sizeof(ATLine));
-
-    p_new->line = strdup(line);
-
-    /* note: this adds to the head of the list, so the list
-       will be in reverse order of lines received. the order is flipped
-       again before passing on to the command issuer */
-    p_new->p_next = sp_response->p_intermediates;
-    sp_response->p_intermediates = p_new;
-}
-
-
-/**
- * returns 1 if line is a final response indicating error
- * See 27.007 annex B
- * WARNING: NO CARRIER and others are sometimes unsolicited
- */
-static const char * s_finalResponsesError[] = {
-    "ERROR",
-    "+CMS ERROR:",
-    "+CME ERROR:",
-    "NO CARRIER", /* sometimes! */
-    "NO ANSWER",
-    "NO DIALTONE",
-};
-static int isFinalResponseError(const char *line)
-{
-    size_t i;
-
-    for (i = 0 ; i < NUM_ELEMS(s_finalResponsesError) ; i++) {
-        if (strStartsWith(line, s_finalResponsesError[i])) {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-/**
- * returns 1 if line is a final response indicating success
- * See 27.007 annex B
- * WARNING: NO CARRIER and others are sometimes unsolicited
- */
-static const char * s_finalResponsesSuccess[] = {
-    "OK",
-    "CONNECT"       /* some stacks start up data on another channel */
-};
-static int isFinalResponseSuccess(const char *line)
-{
-    size_t i;
-
-    for (i = 0 ; i < NUM_ELEMS(s_finalResponsesSuccess) ; i++) {
-        if (strStartsWith(line, s_finalResponsesSuccess[i])) {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-/**
- * returns 1 if line is a final response, either  error or success
- * See 27.007 annex B
- * WARNING: NO CARRIER and others are sometimes unsolicited
- */
-static int isFinalResponse(const char *line)
-{
-    return isFinalResponseSuccess(line) || isFinalResponseError(line);
-}
-
-
-/**
- * returns 1 if line is the first line in (what will be) a two-line
- * SMS unsolicited response
- */
-static const char * s_smsUnsoliciteds[] = {
-    "+CMT:",
-    "+CDS:",
-    "+CBM:"
-};
-static int isSMSUnsolicited(const char *line)
-{
-    size_t i;
-
-    for (i = 0 ; i < NUM_ELEMS(s_smsUnsoliciteds) ; i++) {
-        if (strStartsWith(line, s_smsUnsoliciteds[i])) {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-
-/** assumes s_commandmutex is held */
-static void handleFinalResponse(const char *line)
-{
-    sp_response->finalResponse = strdup(line);
-
-    pthread_cond_signal(&s_commandcond);
-}
-
-static void handleUnsolicited(const char *line)
-{
-    if (s_unsolHandler != NULL) {
-        s_unsolHandler(line, NULL);
-    }
-}
-
-static void processLine(const char *line)
-{
-    pthread_mutex_lock(&s_commandmutex);
-
-    if (sp_response == NULL) {
-        /* no command pending */
-        handleUnsolicited(line);
-    } else if (isFinalResponseSuccess(line)) {
-        sp_response->success = 1;
-        handleFinalResponse(line);
-    } else if (isFinalResponseError(line)) {
-        sp_response->success = 0;
-        handleFinalResponse(line);
-    } else if (s_smsPDU != NULL && 0 == strcmp(line, "> ")) {
-        // See eg. TS 27.005 4.3
-        // Commands like AT+CMGS have a "> " prompt
-        writeCtrlZ(s_smsPDU);
-        s_smsPDU = NULL;
-    } else switch (s_type) {
-        case NO_RESULT:
-            handleUnsolicited(line);
-            break;
-        case NUMERIC:
-            if (sp_response->p_intermediates == NULL
-                && isdigit(line[0])
-            ) {
-                addIntermediate(line);
-            } else {
-                /* either we already have an intermediate response or
-                   the line doesn't begin with a digit */
-                handleUnsolicited(line);
-            }
-            break;
-        case SINGLELINE:
-            if (sp_response->p_intermediates == NULL
-                && strStartsWith (line, s_responsePrefix)
-            ) {
-                addIntermediate(line);
-            } else {
-                /* we already have an intermediate response */
-                handleUnsolicited(line);
-            }
-            break;
-        case MULTILINE:
-            if (strStartsWith (line, s_responsePrefix)) {
-                addIntermediate(line);
-            } else {
-                handleUnsolicited(line);
-            }
-        break;
-
-        default: /* this should never be reached */
-            LOGE("Unsupported AT command type %d\n", s_type);
-            handleUnsolicited(line);
-        break;
-    }
-
-    pthread_mutex_unlock(&s_commandmutex);
-}
-
-
-/**
- * Returns a pointer to the end of the next line
- * special-cases the "> " SMS prompt
- *
- * returns NULL if there is no complete line
- */
-static char * findNextEOL(char *cur)
-{
-    if (cur[0] == '>' && cur[1] == ' ' && cur[2] == '\0') {
-        /* SMS prompt character...not \r terminated */
-        return cur+2;
-    }
-
-    // Find next newline
-    while (*cur != '\0' && *cur != '\r' && *cur != '\n') cur++;
-
-    return *cur == '\0' ? NULL : cur;
-}
-
-
-/**
- * Reads a line from the AT channel, returns NULL on timeout.
- * Assumes it has exclusive read access to the FD
- *
- * This line is valid only until the next call to readline
- *
- * This function exists because as of writing, android libc does not
- * have buffered stdio.
- */
-
-static const char *readline()
-{
-    ssize_t count;
-
-    char *p_read = NULL;
-    char *p_eol = NULL;
-    char *ret;
-
-    /* this is a little odd. I use *s_ATBufferCur == 0 to
-     * mean "buffer consumed completely". If it points to a character, than
-     * the buffer continues until a \0
-     */
-    if (*s_ATBufferCur == '\0') {
-        /* empty buffer */
-        s_ATBufferCur = s_ATBuffer;
-        *s_ATBufferCur = '\0';
-        p_read = s_ATBuffer;
-    } else {   /* *s_ATBufferCur != '\0' */
-        /* there's data in the buffer from the last read */
-
-        // skip over leading newlines
-        while (*s_ATBufferCur == '\r' || *s_ATBufferCur == '\n')
-            s_ATBufferCur++;
-
-        p_eol = findNextEOL(s_ATBufferCur);
-
-        if (p_eol == NULL) {
-            /* a partial line. move it up and prepare to read more */
-            size_t len;
-
-            len = strlen(s_ATBufferCur);
-
-            memmove(s_ATBuffer, s_ATBufferCur, len + 1);
-            p_read = s_ATBuffer + len;
-            s_ATBufferCur = s_ATBuffer;
-        }
-        /* Otherwise, (p_eol !- NULL) there is a complete line  */
-        /* that will be returned the while () loop below        */
-    }
-
-    while (p_eol == NULL) {
-        if (0 == MAX_AT_RESPONSE - (p_read - s_ATBuffer)) {
-            LOGE("ERROR: Input line exceeded buffer\n");
-            /* ditch buffer and start over again */
-            s_ATBufferCur = s_ATBuffer;
-            *s_ATBufferCur = '\0';
-            p_read = s_ATBuffer;
-        }
-
-        do {
-            count = read(s_fd, p_read,
-                            MAX_AT_RESPONSE - (p_read - s_ATBuffer));
-        } while (count < 0 && errno == EINTR);
-
-        if (count > 0) {
-            AT_DUMP( "<< ", p_read, count );
-            s_readCount += count;
-
-            p_read[count] = '\0';
-
-            // skip over leading newlines
-            while (*s_ATBufferCur == '\r' || *s_ATBufferCur == '\n')
-                s_ATBufferCur++;
-
-            p_eol = findNextEOL(s_ATBufferCur);
-            p_read += count;
-        } else if (count <= 0) {
-            /* read error encountered or EOF reached */
-            if(count == 0) {
-                LOGD("atchannel: EOF reached");
-            } else {
-                LOGD("atchannel: read error %s", strerror(errno));
-            }
-            return NULL;
-        }
-    }
-
-    /* a full line in the buffer. Place a \0 over the \r and return */
-
-    ret = s_ATBufferCur;
-    *p_eol = '\0';
-    s_ATBufferCur = p_eol + 1; /* this will always be <= p_read,    */
-                              /* and there will be a \0 at *p_read */
-
-    LOGD("AT< %s\n", ret);
-    return ret;
-}
-
-
-static void onReaderClosed()
-{
-    if (s_onReaderClosed != NULL && s_readerClosed == 0) {
-
-        pthread_mutex_lock(&s_commandmutex);
-
-        s_readerClosed = 1;
-
-        pthread_cond_signal(&s_commandcond);
-
-        pthread_mutex_unlock(&s_commandmutex);
-
-        s_onReaderClosed();
-    }
-}
-
-
-static void *readerLoop(void *arg)
-{
-    for (;;) {
-        const char * line;
-
-        line = readline();
-
-        if (line == NULL) {
-            break;
-        }
-
-        if(isSMSUnsolicited(line)) {
-            char *line1;
-            const char *line2;
-
-            // The scope of string returned by 'readline()' is valid only
-            // till next call to 'readline()' hence making a copy of line
-            // before calling readline again.
-            line1 = strdup(line);
-            line2 = readline();
-
-            if (line2 == NULL) {
-                break;
-            }
-
-            if (s_unsolHandler != NULL) {
-                s_unsolHandler (line1, line2);
-            }
-            free(line1);
-        } else {
-            processLine(line);
-        }
-
-#ifdef HAVE_ANDROID_OS
-        if (s_ackPowerIoctl > 0) {
-            /* acknowledge that bytes have been read and processed */
-            ioctl(s_fd, OMAP_CSMI_TTY_ACK, &s_readCount);
-            s_readCount = 0;
-        }
-#endif /*HAVE_ANDROID_OS*/
-    }
-
-    onReaderClosed();
-
-    return NULL;
-}
-
-/**
- * Sends string s to the radio with a \r appended.
- * Returns AT_ERROR_* on error, 0 on success
- *
- * This function exists because as of writing, android libc does not
- * have buffered stdio.
- */
-static int writeline (const char *s)
-{
-    size_t cur = 0;
-    size_t len = strlen(s);
-    ssize_t written;
-
-    if (s_fd < 0 || s_readerClosed > 0) {
-        return AT_ERROR_CHANNEL_CLOSED;
-    }
-
-    LOGD("AT> %s\n", s);
-
-    AT_DUMP( ">> ", s, strlen(s) );
-
-    /* the main string */
-    while (cur < len) {
-        do {
-            written = write (s_fd, s + cur, len - cur);
-        } while (written < 0 && errno == EINTR);
-
-        if (written < 0) {
-            return AT_ERROR_GENERIC;
-        }
-
-        cur += written;
-    }
-
-    /* the \r  */
-
-    do {
-        written = write (s_fd, "\r" , 1);
-    } while ((written < 0 && errno == EINTR) || (written == 0));
-
-    if (written < 0) {
-        return AT_ERROR_GENERIC;
-    }
-
-    return 0;
-}
-static int writeCtrlZ (const char *s)
-{
-    size_t cur = 0;
-    size_t len = strlen(s);
-    ssize_t written;
-
-    if (s_fd < 0 || s_readerClosed > 0) {
-        return AT_ERROR_CHANNEL_CLOSED;
-    }
-
-    LOGD("AT> %s^Z\n", s);
-
-    AT_DUMP( ">* ", s, strlen(s) );
-
-    /* the main string */
-    while (cur < len) {
-        do {
-            written = write (s_fd, s + cur, len - cur);
-        } while (written < 0 && errno == EINTR);
-
-        if (written < 0) {
-            return AT_ERROR_GENERIC;
-        }
-
-        cur += written;
-    }
-
-    /* the ^Z  */
-
-    do {
-        written = write (s_fd, "\032" , 1);
-    } while ((written < 0 && errno == EINTR) || (written == 0));
-
-    if (written < 0) {
-        return AT_ERROR_GENERIC;
-    }
-
-    return 0;
-}
-
-static void clearPendingCommand()
-{
-    if (sp_response != NULL) {
-        at_response_free(sp_response);
-    }
-
-    sp_response = NULL;
-    s_responsePrefix = NULL;
-    s_smsPDU = NULL;
-}
-
-
-/**
- * Starts AT handler on stream "fd'
- * returns 0 on success, -1 on error
- */
-int at_open(int fd, ATUnsolHandler h)
-{
-    int ret;
-    pthread_t tid;
-    pthread_attr_t attr;
-
-    s_fd = fd;
-    s_unsolHandler = h;
-    s_readerClosed = 0;
-
-    s_responsePrefix = NULL;
-    s_smsPDU = NULL;
-    sp_response = NULL;
-
-    /* Android power control ioctl */
-#ifdef HAVE_ANDROID_OS
-#ifdef OMAP_CSMI_POWER_CONTROL
-    ret = ioctl(fd, OMAP_CSMI_TTY_ENABLE_ACK);
-    if(ret == 0) {
-        int ack_count;
-		int read_count;
-        int old_flags;
-        char sync_buf[256];
-        old_flags = fcntl(fd, F_GETFL, 0);
-        fcntl(fd, F_SETFL, old_flags | O_NONBLOCK);
-        do {
-            ioctl(fd, OMAP_CSMI_TTY_READ_UNACKED, &ack_count);
-			read_count = 0;
-            do {
-                ret = read(fd, sync_buf, sizeof(sync_buf));
-				if(ret > 0)
-					read_count += ret;
-            } while(ret > 0 || (ret < 0 && errno == EINTR));
-            ioctl(fd, OMAP_CSMI_TTY_ACK, &ack_count);
-         } while(ack_count > 0 || read_count > 0);
-        fcntl(fd, F_SETFL, old_flags);
-        s_readCount = 0;
-        s_ackPowerIoctl = 1;
-    }
-    else
-        s_ackPowerIoctl = 0;
-
-#else // OMAP_CSMI_POWER_CONTROL
-    s_ackPowerIoctl = 0;
-
-#endif // OMAP_CSMI_POWER_CONTROL
-#endif /*HAVE_ANDROID_OS*/
-
-    pthread_attr_init (&attr);
-    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
-    ret = pthread_create(&s_tid_reader, &attr, readerLoop, &attr);
-
-    if (ret < 0) {
-        perror ("pthread_create");
-        return -1;
-    }
-
-
-    return 0;
-}
-
-/* FIXME is it ok to call this from the reader and the command thread? */
-void at_close()
-{
-    if (s_fd >= 0) {
-        close(s_fd);
-    }
-    s_fd = -1;
-
-    pthread_mutex_lock(&s_commandmutex);
-
-    s_readerClosed = 1;
-
-    pthread_cond_signal(&s_commandcond);
-
-    pthread_mutex_unlock(&s_commandmutex);
-
-    /* the reader thread should eventually die */
-}
-
-static ATResponse * at_response_new()
-{
-    return (ATResponse *) calloc(1, sizeof(ATResponse));
-}
-
-void at_response_free(ATResponse *p_response)
-{
-    ATLine *p_line;
-
-    if (p_response == NULL) return;
-
-    p_line = p_response->p_intermediates;
-
-    while (p_line != NULL) {
-        ATLine *p_toFree;
-
-        p_toFree = p_line;
-        p_line = p_line->p_next;
-
-        free(p_toFree->line);
-        free(p_toFree);
-    }
-
-    free (p_response->finalResponse);
-    free (p_response);
-}
-
-/**
- * The line reader places the intermediate responses in reverse order
- * here we flip them back
- */
-static void reverseIntermediates(ATResponse *p_response)
-{
-    ATLine *pcur,*pnext;
-
-    pcur = p_response->p_intermediates;
-    p_response->p_intermediates = NULL;
-
-    while (pcur != NULL) {
-        pnext = pcur->p_next;
-        pcur->p_next = p_response->p_intermediates;
-        p_response->p_intermediates = pcur;
-        pcur = pnext;
-    }
-}
-
-/**
- * Internal send_command implementation
- * Doesn't lock or call the timeout callback
- *
- * timeoutMsec == 0 means infinite timeout
- */
-
-static int at_send_command_full_nolock (const char *command, ATCommandType type,
-                    const char *responsePrefix, const char *smspdu,
-                    long long timeoutMsec, ATResponse **pp_outResponse)
-{
-    int err = 0;
-#ifndef USE_NP
-    struct timespec ts;
-#endif /*USE_NP*/
-
-    if(sp_response != NULL) {
-        err = AT_ERROR_COMMAND_PENDING;
-        goto error;
-    }
-
-    err = writeline (command);
-
-    if (err < 0) {
-        goto error;
-    }
-
-    s_type = type;
-    s_responsePrefix = responsePrefix;
-    s_smsPDU = smspdu;
-    sp_response = at_response_new();
-
-#ifndef USE_NP
-    if (timeoutMsec != 0) {
-        setTimespecRelative(&ts, timeoutMsec);
-    }
-#endif /*USE_NP*/
-
-    while (sp_response->finalResponse == NULL && s_readerClosed == 0) {
-        if (timeoutMsec != 0) {
-#ifdef USE_NP
-            err = pthread_cond_timeout_np(&s_commandcond, &s_commandmutex, timeoutMsec);
-#else
-            err = pthread_cond_timedwait(&s_commandcond, &s_commandmutex, &ts);
-#endif /*USE_NP*/
-        } else {
-            err = pthread_cond_wait(&s_commandcond, &s_commandmutex);
-        }
-
-        if (err == ETIMEDOUT) {
-            err = AT_ERROR_TIMEOUT;
-            goto error;
-        }
-    }
-
-    if (pp_outResponse == NULL) {
-        at_response_free(sp_response);
-    } else {
-        /* line reader stores intermediate responses in reverse order */
-        reverseIntermediates(sp_response);
-        *pp_outResponse = sp_response;
-    }
-
-    sp_response = NULL;
-
-    if(s_readerClosed > 0) {
-        err = AT_ERROR_CHANNEL_CLOSED;
-        goto error;
-    }
-
-    err = 0;
-error:
-    clearPendingCommand();
-
-    return err;
-}
-
-/**
- * Internal send_command implementation
- *
- * timeoutMsec == 0 means infinite timeout
- */
-static int at_send_command_full (const char *command, ATCommandType type,
-                    const char *responsePrefix, const char *smspdu,
-                    long long timeoutMsec, ATResponse **pp_outResponse)
-{
-    int err;
-
-    if (0 != pthread_equal(s_tid_reader, pthread_self())) {
-        /* cannot be called from reader thread */
-        return AT_ERROR_INVALID_THREAD;
-    }
-
-    pthread_mutex_lock(&s_commandmutex);
-
-    err = at_send_command_full_nolock(command, type,
-                    responsePrefix, smspdu,
-                    timeoutMsec, pp_outResponse);
-
-    pthread_mutex_unlock(&s_commandmutex);
-
-    if (err == AT_ERROR_TIMEOUT && s_onTimeout != NULL) {
-        s_onTimeout();
-    }
-
-    return err;
-}
-
-
-/**
- * Issue a single normal AT command with no intermediate response expected
- *
- * "command" should not include \r
- * pp_outResponse can be NULL
- *
- * if non-NULL, the resulting ATResponse * must be eventually freed with
- * at_response_free
- */
-int at_send_command (const char *command, ATResponse **pp_outResponse)
-{
-    int err;
-
-    err = at_send_command_full (command, NO_RESULT, NULL,
-                                    NULL, 0, pp_outResponse);
-
-    return err;
-}
-
-
-int at_send_command_singleline (const char *command,
-                                const char *responsePrefix,
-                                 ATResponse **pp_outResponse)
-{
-    int err;
-
-    err = at_send_command_full (command, SINGLELINE, responsePrefix,
-                                    NULL, 0, pp_outResponse);
-
-    if (err == 0 && pp_outResponse != NULL
-        && (*pp_outResponse)->success > 0
-        && (*pp_outResponse)->p_intermediates == NULL
-    ) {
-        /* successful command must have an intermediate response */
-        at_response_free(*pp_outResponse);
-        *pp_outResponse = NULL;
-        return AT_ERROR_INVALID_RESPONSE;
-    }
-
-    return err;
-}
-
-
-int at_send_command_numeric (const char *command,
-                                 ATResponse **pp_outResponse)
-{
-    int err;
-
-    err = at_send_command_full (command, NUMERIC, NULL,
-                                    NULL, 0, pp_outResponse);
-
-    if (err == 0 && pp_outResponse != NULL
-        && (*pp_outResponse)->success > 0
-        && (*pp_outResponse)->p_intermediates == NULL
-    ) {
-        /* successful command must have an intermediate response */
-        at_response_free(*pp_outResponse);
-        *pp_outResponse = NULL;
-        return AT_ERROR_INVALID_RESPONSE;
-    }
-
-    return err;
-}
-
-
-int at_send_command_sms (const char *command,
-                                const char *pdu,
-                                const char *responsePrefix,
-                                 ATResponse **pp_outResponse)
-{
-    int err;
-
-    err = at_send_command_full (command, SINGLELINE, responsePrefix,
-                                    pdu, 0, pp_outResponse);
-
-    if (err == 0 && pp_outResponse != NULL
-        && (*pp_outResponse)->success > 0
-        && (*pp_outResponse)->p_intermediates == NULL
-    ) {
-        /* successful command must have an intermediate response */
-        at_response_free(*pp_outResponse);
-        *pp_outResponse = NULL;
-        return AT_ERROR_INVALID_RESPONSE;
-    }
-
-    return err;
-}
-
-
-int at_send_command_multiline (const char *command,
-                                const char *responsePrefix,
-                                 ATResponse **pp_outResponse)
-{
-    int err;
-
-    err = at_send_command_full (command, MULTILINE, responsePrefix,
-                                    NULL, 0, pp_outResponse);
-
-    return err;
-}
-
-
-/** This callback is invoked on the command thread */
-void at_set_on_timeout(void (*onTimeout)(void))
-{
-    s_onTimeout = onTimeout;
-}
-
-/**
- *  This callback is invoked on the reader thread (like ATUnsolHandler)
- *  when the input stream closes before you call at_close
- *  (not when you call at_close())
- *  You should still call at_close()
- */
-
-void at_set_on_reader_closed(void (*onClose)(void))
-{
-    s_onReaderClosed = onClose;
-}
-
-
-/**
- * Periodically issue an AT command and wait for a response.
- * Used to ensure channel has start up and is active
- */
-
-int at_handshake()
-{
-    int i;
-    int err = 0;
-
-    if (0 != pthread_equal(s_tid_reader, pthread_self())) {
-        /* cannot be called from reader thread */
-        return AT_ERROR_INVALID_THREAD;
-    }
-
-    pthread_mutex_lock(&s_commandmutex);
-
-    for (i = 0 ; i < HANDSHAKE_RETRY_COUNT ; i++) {
-        /* some stacks start with verbose off */
-        err = at_send_command_full_nolock ("ATE0Q0V1", NO_RESULT,
-                    NULL, NULL, HANDSHAKE_TIMEOUT_MSEC, NULL);
-
-        if (err == 0) {
-            break;
-        }
-    }
-
-    if (err == 0) {
-        /* pause for a bit to let the input buffer drain any unmatched OK's
-           (they will appear as extraneous unsolicited responses) */
-
-        sleepMsec(HANDSHAKE_TIMEOUT_MSEC);
-    }
-
-    pthread_mutex_unlock(&s_commandmutex);
-
-    return err;
-}
-
-/**
- * Returns error code from response
- * Assumes AT+CMEE=1 (numeric) mode
- */
-AT_CME_Error at_get_cme_error(const ATResponse *p_response)
-{
-    int ret;
-    int err;
-    char *p_cur;
-
-    if (p_response->success > 0) {
-        return CME_SUCCESS;
-    }
-
-    if (p_response->finalResponse == NULL
-        || !strStartsWith(p_response->finalResponse, "+CME ERROR:")
-    ) {
-        return CME_ERROR_NON_CME;
-    }
-
-    p_cur = p_response->finalResponse;
-    err = at_tok_start(&p_cur);
-
-    if (err < 0) {
-        return CME_ERROR_NON_CME;
-    }
-
-    err = at_tok_nextint(&p_cur, &ret);
-
-    if (err < 0) {
-        return CME_ERROR_NON_CME;
-    }
-
-    return (AT_CME_Error) ret;
-}
-
diff --git a/reference-ril/atchannel.h b/reference-ril/atchannel.h
deleted file mode 100644
index cfd49d5..0000000
--- a/reference-ril/atchannel.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/* //device/system/reference-ril/atchannel.h
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#ifndef ATCHANNEL_H
-#define ATCHANNEL_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* define AT_DEBUG to send AT traffic to /tmp/radio-at.log" */
-#define AT_DEBUG  0
-
-#if AT_DEBUG
-extern void  AT_DUMP(const char* prefix, const char*  buff, int  len);
-#else
-#define  AT_DUMP(prefix,buff,len)  do{}while(0)
-#endif
-
-#define AT_ERROR_GENERIC -1
-#define AT_ERROR_COMMAND_PENDING -2
-#define AT_ERROR_CHANNEL_CLOSED -3
-#define AT_ERROR_TIMEOUT -4
-#define AT_ERROR_INVALID_THREAD -5 /* AT commands may not be issued from
-                                       reader thread (or unsolicited response
-                                       callback */
-#define AT_ERROR_INVALID_RESPONSE -6 /* eg an at_send_command_singleline that
-                                        did not get back an intermediate
-                                        response */
-
-
-typedef enum {
-    NO_RESULT,   /* no intermediate response expected */
-    NUMERIC,     /* a single intermediate response starting with a 0-9 */
-    SINGLELINE,  /* a single intermediate response starting with a prefix */
-    MULTILINE    /* multiple line intermediate response
-                    starting with a prefix */
-} ATCommandType;
-
-/** a singly-lined list of intermediate responses */
-typedef struct ATLine  {
-    struct ATLine *p_next;
-    char *line;
-} ATLine;
-
-/** Free this with at_response_free() */
-typedef struct {
-    int success;              /* true if final response indicates
-                                    success (eg "OK") */
-    char *finalResponse;      /* eg OK, ERROR */
-    ATLine  *p_intermediates; /* any intermediate responses */
-} ATResponse;
-
-/**
- * a user-provided unsolicited response handler function
- * this will be called from the reader thread, so do not block
- * "s" is the line, and "sms_pdu" is either NULL or the PDU response
- * for multi-line TS 27.005 SMS PDU responses (eg +CMT:)
- */
-typedef void (*ATUnsolHandler)(const char *s, const char *sms_pdu);
-
-int at_open(int fd, ATUnsolHandler h);
-void at_close();
-
-/* This callback is invoked on the command thread.
-   You should reset or handshake here to avoid getting out of sync */
-void at_set_on_timeout(void (*onTimeout)(void));
-/* This callback is invoked on the reader thread (like ATUnsolHandler)
-   when the input stream closes before you call at_close
-   (not when you call at_close())
-   You should still call at_close()
-   It may also be invoked immediately from the current thread if the read
-   channel is already closed */
-void at_set_on_reader_closed(void (*onClose)(void));
-
-int at_send_command_singleline (const char *command,
-                                const char *responsePrefix,
-                                 ATResponse **pp_outResponse);
-
-int at_send_command_numeric (const char *command,
-                                 ATResponse **pp_outResponse);
-
-int at_send_command_multiline (const char *command,
-                                const char *responsePrefix,
-                                 ATResponse **pp_outResponse);
-
-
-int at_handshake();
-
-int at_send_command (const char *command, ATResponse **pp_outResponse);
-
-int at_send_command_sms (const char *command, const char *pdu,
-                            const char *responsePrefix,
-                            ATResponse **pp_outResponse);
-
-void at_response_free(ATResponse *p_response);
-
-typedef enum {
-    CME_ERROR_NON_CME = -1,
-    CME_SUCCESS = 0,
-    CME_SIM_NOT_INSERTED = 10
-} AT_CME_Error;
-
-AT_CME_Error at_get_cme_error(const ATResponse *p_response);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*ATCHANNEL_H*/
diff --git a/reference-ril/misc.c b/reference-ril/misc.c
deleted file mode 100644
index 7945e75..0000000
--- a/reference-ril/misc.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* //device/system/reference-ril/misc.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-/** returns 1 if line starts with prefix, 0 if it does not */
-int strStartsWith(const char *line, const char *prefix)
-{
-    for ( ; *line != '\0' && *prefix != '\0' ; line++, prefix++) {
-        if (*line != *prefix) {
-            return 0;
-        }
-    }
-
-    return *prefix == '\0';
-}
-
diff --git a/reference-ril/misc.h b/reference-ril/misc.h
deleted file mode 100644
index bafe7df..0000000
--- a/reference-ril/misc.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* //device/system/reference-ril/misc.h
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-/** returns 1 if line starts with prefix, 0 if it does not */
-int strStartsWith(const char *line, const char *prefix);
diff --git a/reference-ril/reference-ril.c b/reference-ril/reference-ril.c
deleted file mode 100644
index ccb5b62..0000000
--- a/reference-ril/reference-ril.c
+++ /dev/null
@@ -1,2052 +0,0 @@
-/* //device/system/reference-ril/reference-ril.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include <telephony/ril.h>
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <pthread.h>
-#include <alloca.h>
-#include "atchannel.h"
-#include "at_tok.h"
-#include "misc.h"
-#include <getopt.h>
-#include <sys/socket.h>
-#include <cutils/sockets.h>
-#include <termios.h>
-
-#define LOG_TAG "RIL"
-#include <utils/Log.h>
-
-#define MAX_AT_RESPONSE 0x1000
-
-/* pathname returned from RIL_REQUEST_SETUP_DEFAULT_PDP */
-#define PPP_TTY_PATH "/dev/omap_csmi_tty1"
-
-#ifdef USE_TI_COMMANDS
-
-// Enable a workaround
-// 1) Make incoming call, do not answer
-// 2) Hangup remote end
-// Expected: call should disappear from CLCC line
-// Actual: Call shows as "ACTIVE" before disappearing
-#define WORKAROUND_ERRONEOUS_ANSWER 1
-
-// Some varients of the TI stack do not support the +CGEV unsolicited
-// response. However, they seem to send an unsolicited +CME ERROR: 150
-#define WORKAROUND_FAKE_CGEV 1
-#endif
-
-static void onRequest (int request, void *data, size_t datalen, RIL_Token t);
-static RIL_RadioState currentState();
-static int onSupports (int requestCode);
-static void onCancel (RIL_Token t);
-static const char *getVersion();
-static int isRadioOn();
-static int getSIMStatus();
-static void onPDPContextListChanged(void *param);
-
-extern const char * requestToString(int request);
-
-/*** Static Variables ***/
-static const RIL_RadioFunctions s_callbacks = {
-    RIL_VERSION,
-    onRequest,
-    currentState,
-    onSupports,
-    onCancel,
-    getVersion
-};
-
-#ifdef RIL_SHLIB
-static const struct RIL_Env *s_rilenv;
-
-#define RIL_onRequestComplete(t, e, response, responselen) s_rilenv->OnRequestComplete(t,e, response, responselen)
-#define RIL_onUnsolicitedResponse(a,b,c) s_rilenv->OnUnsolicitedResponse(a,b,c)
-#define RIL_requestTimedCallback(a,b,c) s_rilenv->RequestTimedCallback(a,b,c)
-#endif
-
-static RIL_RadioState sState = RADIO_STATE_UNAVAILABLE;
-
-static pthread_mutex_t s_state_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t s_state_cond = PTHREAD_COND_INITIALIZER;
-
-static int s_port = -1;
-static const char * s_device_path = NULL;
-static int          s_device_socket = 0;
-
-/* trigger change to this with s_state_cond */
-static int s_closed = 0;
-
-static int sFD;     /* file desc of AT channel */
-static char sATBuffer[MAX_AT_RESPONSE+1];
-static char *sATBufferCur = NULL;
-
-static const struct timeval TIMEVAL_SIMPOLL = {1,0};
-static const struct timeval TIMEVAL_CALLSTATEPOLL = {0,500000};
-static const struct timeval TIMEVAL_0 = {0,0};
-
-#ifdef WORKAROUND_ERRONEOUS_ANSWER
-// Max number of times we'll try to repoll when we think
-// we have a AT+CLCC race condition
-#define REPOLL_CALLS_COUNT_MAX 4
-
-// Line index that was incoming or waiting at last poll, or -1 for none
-static int s_incomingOrWaitingLine = -1;
-// Number of times we've asked for a repoll of AT+CLCC
-static int s_repollCallsCount = 0;
-// Should we expect a call to be answered in the next CLCC?
-static int s_expectAnswer = 0;
-#endif /* WORKAROUND_ERRONEOUS_ANSWER */
-
-static void pollSIMState (void *param);
-static void setRadioState(RIL_RadioState newState);
-
-static int clccStateToRILState(int state, RIL_CallState *p_state)
-
-{
-    switch(state) {
-        case 0: *p_state = RIL_CALL_ACTIVE;   return 0;
-        case 1: *p_state = RIL_CALL_HOLDING;  return 0;
-        case 2: *p_state = RIL_CALL_DIALING;  return 0;
-        case 3: *p_state = RIL_CALL_ALERTING; return 0;
-        case 4: *p_state = RIL_CALL_INCOMING; return 0;
-        case 5: *p_state = RIL_CALL_WAITING;  return 0;
-        default: return -1;
-    }
-}
-
-/**
- * Note: directly modified line and has *p_call point directly into
- * modified line
- */
-static int callFromCLCCLine(char *line, RIL_Call *p_call)
-{
-        //+CLCC: 1,0,2,0,0,\"+18005551212\",145
-        //     index,isMT,state,mode,isMpty(,number,TOA)?
-
-    int err;
-    int state;
-    int mode;
-
-    err = at_tok_start(&line);
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &(p_call->index));
-    if (err < 0) goto error;
-
-    err = at_tok_nextbool(&line, &(p_call->isMT));
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &state);
-    if (err < 0) goto error;
-
-    err = clccStateToRILState(state, &(p_call->state));
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &mode);
-    if (err < 0) goto error;
-
-    p_call->isVoice = (mode == 0);
-
-    err = at_tok_nextbool(&line, &(p_call->isMpty));
-    if (err < 0) goto error;
-
-    if (at_tok_hasmore(&line)) {
-        err = at_tok_nextstr(&line, &(p_call->number));
-
-        /* tolerate null here */
-        if (err < 0) return 0;
-
-        // Some lame implementations return strings
-        // like "NOT AVAILABLE" in the CLCC line
-        if (p_call->number != NULL
-            && 0 == strspn(p_call->number, "+0123456789")
-        ) {
-            p_call->number = NULL;
-        }
-
-        err = at_tok_nextint(&line, &p_call->toa);
-        if (err < 0) goto error;
-    }
-
-    return 0;
-
-error:
-    LOGE("invalid CLCC line\n");
-    return -1;
-}
-
-
-/** do post-AT+CFUN=1 initialization */
-static void onRadioPowerOn()
-{
-#ifdef USE_TI_COMMANDS
-    /*  Must be after CFUN=1 */
-    /*  TI specific -- notifications for CPHS things such */
-    /*  as CPHS message waiting indicator */
-
-    at_send_command("AT%CPHS=1", NULL);
-
-    /*  TI specific -- enable NITZ unsol notifs */
-    at_send_command("AT%CTZV=1", NULL);
-#endif
-
-    pollSIMState(NULL);
-}
-
-/** do post- SIM ready initialization */
-static void onSIMReady()
-{
-    at_send_command_singleline("AT+CSMS=1", "+CSMS:", NULL);
-    /*
-     * Always send SMS messages directly to the TE
-     *
-     * mode = 1 // discard when link is reserved (link should never be
-     *             reserved)
-     * mt = 2   // most messages routed to TE
-     * bm = 2   // new cell BM's routed to TE
-     * ds = 1   // Status reports routed to TE
-     * bfr = 1  // flush buffer
-     */
-    at_send_command("AT+CNMI=1,2,2,1,1", NULL);
-}
-
-static void requestRadioPower(void *data, size_t datalen, RIL_Token t)
-{
-    int onOff;
-
-    int err;
-    ATResponse *p_response = NULL;
-
-    assert (datalen >= sizeof(int *));
-    onOff = ((int *)data)[0];
-
-    if (onOff == 0 && sState != RADIO_STATE_OFF) {
-        err = at_send_command("AT+CFUN=0", &p_response);
-       if (err < 0 || p_response->success == 0) goto error;
-        setRadioState(RADIO_STATE_OFF);
-    } else if (onOff > 0 && sState == RADIO_STATE_OFF) {
-        err = at_send_command("AT+CFUN=1", &p_response);
-        if (err < 0|| p_response->success == 0) {
-            // Some stacks return an error when there is no SIM,
-            // but they really turn the RF portion on
-            // So, if we get an error, let's check to see if it
-            // turned on anyway
-
-            if (isRadioOn() != 1) {
-                goto error;
-            }
-        }
-        setRadioState(RADIO_STATE_SIM_NOT_READY);
-    }
-
-    at_response_free(p_response);
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-    return;
-error:
-    at_response_free(p_response);
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-}
-
-static void requestOrSendPDPContextList(RIL_Token *t);
-
-static void onPDPContextListChanged(void *param)
-{
-    requestOrSendPDPContextList(NULL);
-}
-
-static void requestPDPContextList(void *data, size_t datalen, RIL_Token t)
-{
-    requestOrSendPDPContextList(&t);
-}
-
-static void requestOrSendPDPContextList(RIL_Token *t)
-{
-    ATResponse *p_response;
-    ATLine *p_cur;
-    int err;
-    int n = 0;
-    char *out;
-
-    err = at_send_command_multiline ("AT+CGACT?", "+CGACT:", &p_response);
-    if (err != 0 || p_response->success == 0) {
-        if (t != NULL)
-            RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0);
-        else
-            RIL_onUnsolicitedResponse(RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED,
-                                      NULL, 0);
-        return;
-    }
-
-    for (p_cur = p_response->p_intermediates; p_cur != NULL;
-         p_cur = p_cur->p_next)
-        n++;
-
-    RIL_PDP_Context_Response *responses =
-        alloca(n * sizeof(RIL_PDP_Context_Response));
-
-    int i;
-    for (i = 0; i < n; i++) {
-        responses[i].cid = -1;
-        responses[i].active = -1;
-        responses[i].type = "";
-        responses[i].apn = "";
-        responses[i].address = "";
-    }
-
-    RIL_PDP_Context_Response *response = responses;
-    for (p_cur = p_response->p_intermediates; p_cur != NULL;
-         p_cur = p_cur->p_next) {
-        char *line = p_cur->line;
-
-        err = at_tok_start(&line);
-        if (err < 0)
-            goto error;
-
-        err = at_tok_nextint(&line, &response->cid);
-        if (err < 0)
-            goto error;
-
-        err = at_tok_nextint(&line, &response->active);
-        if (err < 0)
-            goto error;
-
-        response++;
-    }
-
-    at_response_free(p_response);
-
-    err = at_send_command_multiline ("AT+CGDCONT?", "+CGDCONT:", &p_response);
-    if (err != 0 || p_response->success == 0) {
-        if (t != NULL)
-            RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0);
-        else
-            RIL_onUnsolicitedResponse(RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED,
-                                      NULL, 0);
-        return;
-    }
-
-    for (p_cur = p_response->p_intermediates; p_cur != NULL;
-         p_cur = p_cur->p_next) {
-        char *line = p_cur->line;
-        int cid;
-        char *type;
-        char *apn;
-        char *address;
-
-
-        err = at_tok_start(&line);
-        if (err < 0)
-            goto error;
-
-        err = at_tok_nextint(&line, &cid);
-        if (err < 0)
-            goto error;
-
-        for (i = 0; i < n; i++) {
-            if (responses[i].cid == cid)
-                break;
-        }
-
-        if (i >= n) {
-            /* details for a context we didn't hear about in the last request */
-            continue;
-        }
-
-        err = at_tok_nextstr(&line, &out);
-        if (err < 0)
-            goto error;
-
-        responses[i].type = alloca(strlen(out) + 1);
-        strcpy(responses[i].type, out);
-
-        err = at_tok_nextstr(&line, &out);
-        if (err < 0)
-            goto error;
-
-        responses[i].apn = alloca(strlen(out) + 1);
-        strcpy(responses[i].apn, out);
-
-        err = at_tok_nextstr(&line, &out);
-        if (err < 0)
-            goto error;
-
-        responses[i].address = alloca(strlen(out) + 1);
-        strcpy(responses[i].address, out);
-    }
-
-    at_response_free(p_response);
-
-    if (t != NULL)
-        RIL_onRequestComplete(*t, RIL_E_SUCCESS, responses,
-                              n * sizeof(RIL_PDP_Context_Response));
-    else
-        RIL_onUnsolicitedResponse(RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED,
-                                  responses,
-                                  n * sizeof(RIL_PDP_Context_Response));
-
-    return;
-
-error:
-    if (t != NULL)
-        RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    else
-        RIL_onUnsolicitedResponse(RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED,
-                                  NULL, 0);
-
-    at_response_free(p_response);
-}
-
-static void requestQueryNetworkSelectionMode(
-                void *data, size_t datalen, RIL_Token t)
-{
-    int err;
-    ATResponse *p_response = NULL;
-    int response = 0;
-    char *line;
-
-    err = at_send_command_singleline("AT+COPS?", "+COPS:", &p_response);
-
-    if (err < 0 || p_response->success == 0) {
-        goto error;
-    }
-
-    line = p_response->p_intermediates->line;
-
-    err = at_tok_start(&line);
-
-    if (err < 0) {
-        goto error;
-    }
-
-    err = at_tok_nextint(&line, &response);
-
-    if (err < 0) {
-        goto error;
-    }
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));
-    at_response_free(p_response);
-    return;
-error:
-    at_response_free(p_response);
-    LOGE("requestQueryNetworkSelectionMode must never return error when radio is on");
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-}
-
-static void sendCallStateChanged(void *param)
-{
-    RIL_onUnsolicitedResponse (
-        RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,
-        NULL, 0);
-}
-
-static void requestGetCurrentCalls(void *data, size_t datalen, RIL_Token t)
-{
-    int err;
-    ATResponse *p_response;
-    ATLine *p_cur;
-    int countCalls;
-    int countValidCalls;
-    RIL_Call *p_calls;
-    RIL_Call **pp_calls;
-    int i;
-    int needRepoll = 0;
-
-#ifdef WORKAROUND_ERRONEOUS_ANSWER
-    int prevIncomingOrWaitingLine;
-
-    prevIncomingOrWaitingLine = s_incomingOrWaitingLine;
-    s_incomingOrWaitingLine = -1;
-#endif /*WORKAROUND_ERRONEOUS_ANSWER*/
-
-    err = at_send_command_multiline ("AT+CLCC", "+CLCC:", &p_response);
-
-    if (err != 0 || p_response->success == 0) {
-        RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-        return;
-    }
-
-    /* count the calls */
-    for (countCalls = 0, p_cur = p_response->p_intermediates
-            ; p_cur != NULL
-            ; p_cur = p_cur->p_next
-    ) {
-        countCalls++;
-    }
-
-    /* yes, there's an array of pointers and then an array of structures */
-
-    pp_calls = (RIL_Call **)alloca(countCalls * sizeof(RIL_Call *));
-    p_calls = (RIL_Call *)alloca(countCalls * sizeof(RIL_Call));
-    memset (p_calls, 0, countCalls * sizeof(RIL_Call));
-
-    /* init the pointer array */
-    for(i = 0; i < countCalls ; i++) {
-        pp_calls[i] = &(p_calls[i]);
-    }
-
-    for (countValidCalls = 0, p_cur = p_response->p_intermediates
-            ; p_cur != NULL
-            ; p_cur = p_cur->p_next
-    ) {
-        err = callFromCLCCLine(p_cur->line, p_calls + countValidCalls);
-
-        if (err != 0) {
-            continue;
-        }
-
-#ifdef WORKAROUND_ERRONEOUS_ANSWER
-        if (p_calls[countValidCalls].state == RIL_CALL_INCOMING
-            || p_calls[countValidCalls].state == RIL_CALL_WAITING
-        ) {
-            s_incomingOrWaitingLine = p_calls[countValidCalls].index;
-        }
-#endif /*WORKAROUND_ERRONEOUS_ANSWER*/
-
-        if (p_calls[countValidCalls].state != RIL_CALL_ACTIVE
-            && p_calls[countValidCalls].state != RIL_CALL_HOLDING
-        ) {
-            needRepoll = 1;
-        }
-
-        countValidCalls++;
-    }
-
-#ifdef WORKAROUND_ERRONEOUS_ANSWER
-    // Basically:
-    // A call was incoming or waiting
-    // Now it's marked as active
-    // But we never answered it
-    //
-    // This is probably a bug, and the call will probably
-    // disappear from the call list in the next poll
-    if (prevIncomingOrWaitingLine >= 0
-            && s_incomingOrWaitingLine < 0
-            && s_expectAnswer == 0
-    ) {
-        for (i = 0; i < countValidCalls ; i++) {
-
-            if (p_calls[i].index == prevIncomingOrWaitingLine
-                    && p_calls[i].state == RIL_CALL_ACTIVE
-                    && s_repollCallsCount < REPOLL_CALLS_COUNT_MAX
-            ) {
-                LOGI(
-                    "Hit WORKAROUND_ERRONOUS_ANSWER case."
-                    " Repoll count: %d\n", s_repollCallsCount);
-                s_repollCallsCount++;
-                goto error;
-            }
-        }
-    }
-
-    s_expectAnswer = 0;
-    s_repollCallsCount = 0;
-#endif /*WORKAROUND_ERRONEOUS_ANSWER*/
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, pp_calls,
-            countValidCalls * sizeof (RIL_Call *));
-
-    at_response_free(p_response);
-
-#ifdef POLL_CALL_STATE
-    if (countValidCalls) {  // We don't seem to get a "NO CARRIER" message from
-                            // smd, so we're forced to poll until the call ends.
-#else
-    if (needRepoll) {
-#endif
-        RIL_requestTimedCallback (sendCallStateChanged, NULL, &TIMEVAL_CALLSTATEPOLL);
-    }
-
-    return;
-error:
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-}
-
-static void requestDial(void *data, size_t datalen, RIL_Token t)
-{
-    RIL_Dial *p_dial;
-    char *cmd;
-    const char *clir;
-    int ret;
-
-    p_dial = (RIL_Dial *)data;
-
-    switch (p_dial->clir) {
-        case 1: clir = "I"; break;  /*invocation*/
-        case 2: clir = "i"; break;  /*suppression*/
-        default:
-        case 0: clir = ""; break;   /*subscription default*/
-    }
-
-    asprintf(&cmd, "ATD%s%s;", p_dial->address, clir);
-
-    ret = at_send_command(cmd, NULL);
-
-    free(cmd);
-
-    /* success or failure is ignored by the upper layer here.
-       it will call GET_CURRENT_CALLS and determine success that way */
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-}
-
-static void requestWriteSmsToSim(void *data, size_t datalen, RIL_Token t)
-{
-    RIL_SMS_WriteArgs *p_args;
-    char *cmd;
-    int length;
-    int err;
-    ATResponse *p_response = NULL;
-
-    p_args = (RIL_SMS_WriteArgs *)data;
-
-    length = strlen(p_args->pdu)/2;
-    asprintf(&cmd, "AT+CMGW=%d,%d", length, p_args->status);
-
-    err = at_send_command_sms(cmd, p_args->pdu, "+CMGW:", &p_response);
-
-    if (err != 0 || p_response->success == 0) goto error;
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-    at_response_free(p_response);
-
-    return;
-error:
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-}
-
-static void requestHangup(void *data, size_t datalen, RIL_Token t)
-{
-    int *p_line;
-
-    int ret;
-    char *cmd;
-
-    p_line = (int *)data;
-
-    // 3GPP 22.030 6.5.5
-    // "Releases a specific active call X"
-    asprintf(&cmd, "AT+CHLD=1%d", p_line[0]);
-
-    ret = at_send_command(cmd, NULL);
-
-    free(cmd);
-
-    /* success or failure is ignored by the upper layer here.
-       it will call GET_CURRENT_CALLS and determine success that way */
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-}
-
-static void requestSignalStrength(void *data, size_t datalen, RIL_Token t)
-{
-    ATResponse *p_response = NULL;
-    int err;
-    int response[2];
-    char *line;
-
-    err = at_send_command_singleline("AT+CSQ", "+CSQ:", &p_response);
-
-    if (err < 0 || p_response->success == 0) {
-        RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-        goto error;
-    }
-
-    line = p_response->p_intermediates->line;
-
-    err = at_tok_start(&line);
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &(response[0]));
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &(response[1]));
-    if (err < 0) goto error;
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
-
-    at_response_free(p_response);
-    return;
-
-error:
-    LOGE("requestSignalStrength must never return an error when radio is on");
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-}
-
-static void requestRegistrationState(int request, void *data,
-                                        size_t datalen, RIL_Token t)
-{
-    int err;
-    int response[4];
-    char * responseStr[4];
-    ATResponse *p_response = NULL;
-    const char *cmd;
-    const char *prefix;
-    char *line, *p;
-    int commas;
-    int skip;
-    int count = 3;
-
-
-    if (request == RIL_REQUEST_REGISTRATION_STATE) {
-        cmd = "AT+CREG?";
-        prefix = "+CREG:";
-    } else if (request == RIL_REQUEST_GPRS_REGISTRATION_STATE) {
-        cmd = "AT+CGREG?";
-        prefix = "+CGREG:";
-    } else {
-        assert(0);
-        goto error;
-    }
-
-    err = at_send_command_singleline(cmd, prefix, &p_response);
-
-    if (err != 0) goto error;
-
-    line = p_response->p_intermediates->line;
-
-    err = at_tok_start(&line);
-    if (err < 0) goto error;
-
-    /* Ok you have to be careful here
-     * The solicited version of the CREG response is
-     * +CREG: n, stat, [lac, cid]
-     * and the unsolicited version is
-     * +CREG: stat, [lac, cid]
-     * The <n> parameter is basically "is unsolicited creg on?"
-     * which it should always be
-     *
-     * Now we should normally get the solicited version here,
-     * but the unsolicited version could have snuck in
-     * so we have to handle both
-     *
-     * Also since the LAC and CID are only reported when registered,
-     * we can have 1, 2, 3, or 4 arguments here
-     *
-     * finally, a +CGREG: answer may have a fifth value that corresponds
-     * to the network type, as in;
-     *
-     *   +CGREG: n, stat [,lac, cid [,networkType]]
-     */
-
-    /* count number of commas */
-    commas = 0;
-    for (p = line ; *p != '\0' ;p++) {
-        if (*p == ',') commas++;
-    }
-
-    switch (commas) {
-        case 0: /* +CREG: <stat> */
-            err = at_tok_nextint(&line, &response[0]);
-            if (err < 0) goto error;
-            response[1] = -1;
-            response[2] = -1;
-        break;
-
-        case 1: /* +CREG: <n>, <stat> */
-            err = at_tok_nextint(&line, &skip);
-            if (err < 0) goto error;
-            err = at_tok_nextint(&line, &response[0]);
-            if (err < 0) goto error;
-            response[1] = -1;
-            response[2] = -1;
-            if (err < 0) goto error;
-        break;
-
-        case 2: /* +CREG: <stat>, <lac>, <cid> */
-            err = at_tok_nextint(&line, &response[0]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[1]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[2]);
-            if (err < 0) goto error;
-        break;
-        case 3: /* +CREG: <n>, <stat>, <lac>, <cid> */
-            err = at_tok_nextint(&line, &skip);
-            if (err < 0) goto error;
-            err = at_tok_nextint(&line, &response[0]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[1]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[2]);
-            if (err < 0) goto error;
-        break;
-        /* special case for CGREG, there is a fourth parameter
-         * that is the network type (unknown/gprs/edge/umts)
-         */
-        case 4: /* +CGREG: <n>, <stat>, <lac>, <cid>, <networkType> */
-            err = at_tok_nextint(&line, &skip);
-            if (err < 0) goto error;
-            err = at_tok_nextint(&line, &response[0]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[1]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[2]);
-            if (err < 0) goto error;
-            err = at_tok_nexthexint(&line, &response[3]);
-            if (err < 0) goto error;
-            count = 4;
-        break;
-        default:
-            goto error;
-    }
-
-    asprintf(&responseStr[0], "%d", response[0]);
-    asprintf(&responseStr[1], "%d", response[1]);
-    asprintf(&responseStr[2], "%d", response[2]);
-
-    if (count > 3)
-        asprintf(&responseStr[3], "%d", response[3]);
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, count*sizeof(char*));
-    at_response_free(p_response);
-
-    return;
-error:
-    LOGE("requestRegistrationState must never return an error when radio is on");
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-}
-
-static void requestOperator(void *data, size_t datalen, RIL_Token t)
-{
-    int err;
-    int i;
-    int skip;
-    ATLine *p_cur;
-    char *response[3];
-
-    memset(response, 0, sizeof(response));
-
-    ATResponse *p_response = NULL;
-
-    err = at_send_command_multiline(
-        "AT+COPS=3,0;+COPS?;+COPS=3,1;+COPS?;+COPS=3,2;+COPS?",
-        "+COPS:", &p_response);
-
-    /* we expect 3 lines here:
-     * +COPS: 0,0,"T - Mobile"
-     * +COPS: 0,1,"TMO"
-     * +COPS: 0,2,"310170"
-     */
-
-    if (err != 0) goto error;
-
-    for (i = 0, p_cur = p_response->p_intermediates
-            ; p_cur != NULL
-            ; p_cur = p_cur->p_next, i++
-    ) {
-        char *line = p_cur->line;
-
-        err = at_tok_start(&line);
-        if (err < 0) goto error;
-
-        err = at_tok_nextint(&line, &skip);
-        if (err < 0) goto error;
-
-        // If we're unregistered, we may just get
-        // a "+COPS: 0" response
-        if (!at_tok_hasmore(&line)) {
-            response[i] = NULL;
-            continue;
-        }
-
-        err = at_tok_nextint(&line, &skip);
-        if (err < 0) goto error;
-
-        // a "+COPS: 0, n" response is also possible
-        if (!at_tok_hasmore(&line)) {
-            response[i] = NULL;
-            continue;
-        }
-
-        err = at_tok_nextstr(&line, &(response[i]));
-        if (err < 0) goto error;
-    }
-
-    if (i != 3) {
-        /* expect 3 lines exactly */
-        goto error;
-    }
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
-    at_response_free(p_response);
-
-    return;
-error:
-    LOGE("requestOperator must not return error when radio is on");
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-}
-
-static void requestSendSMS(void *data, size_t datalen, RIL_Token t)
-{
-    int err;
-    const char *smsc;
-    const char *pdu;
-    int tpLayerLength;
-    char *cmd1, *cmd2;
-    RIL_SMS_Response response;
-    ATResponse *p_response = NULL;
-
-    smsc = ((const char **)data)[0];
-    pdu = ((const char **)data)[1];
-
-    tpLayerLength = strlen(pdu)/2;
-
-    // "NULL for default SMSC"
-    if (smsc == NULL) {
-        smsc= "00";
-    }
-
-    asprintf(&cmd1, "AT+CMGS=%d", tpLayerLength);
-    asprintf(&cmd2, "%s%s", smsc, pdu);
-
-    err = at_send_command_sms(cmd1, cmd2, "+CMGS:", &p_response);
-
-    if (err != 0 || p_response->success == 0) goto error;
-
-    memset(&response, 0, sizeof(response));
-
-    /* FIXME fill in messageRef and ackPDU */
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response));
-    at_response_free(p_response);
-
-    return;
-error:
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-}
-
-static void requestSetupDefaultPDP(void *data, size_t datalen, RIL_Token t)
-{
-    const char *apn;
-    char *cmd;
-    int err;
-    ATResponse *p_response = NULL;
-    char *response[2] = { "1", PPP_TTY_PATH };
-
-    apn = ((const char **)data)[0];
-
-#ifdef USE_TI_COMMANDS
-    // Config for multislot class 10 (probably default anyway eh?)
-    err = at_send_command("AT%CPRIM=\"GMM\",\"CONFIG MULTISLOT_CLASS=<10>\"",
-                        NULL);
-
-    err = at_send_command("AT%DATA=2,\"UART\",1,,\"SER\",\"UART\",0", NULL);
-#endif /* USE_TI_COMMANDS */
-
-    int fd, qmistatus;
-    size_t cur = 0;
-    size_t len;
-    ssize_t written, rlen;
-    char status[32] = {0};
-    int retry = 10;
-
-    LOGD("requesting data connection to APN '%s'", apn);
-
-    fd = open ("/dev/qmi", O_RDWR);
-    if (fd >= 0) { /* the device doesn't exist on the emulator */
-
-	    LOGD("opened the qmi device\n");
-	    asprintf(&cmd, "up:%s", apn);
-	    len = strlen(cmd);
-
-	    while (cur < len) {
-		    do {
-	            written = write (fd, cmd + cur, len - cur);
-	        } while (written < 0 && errno == EINTR);
-
-	        if (written < 0) {
-                LOGE("### ERROR writing to /dev/qmi");
-                close(fd);
-                goto error;
-            }
-
-            cur += written;
-        }
-
-        // wait for interface to come online
-
-        do {
-            sleep(1);
-            do {
-                rlen = read(fd, status, 31);
-            } while (rlen < 0 && errno == EINTR);
-
-            if (rlen < 0) {
-                LOGE("### ERROR reading from /dev/qmi");
-                close(fd);
-                goto error;
-            } else {
-                status[rlen] = '\0';
-                LOGD("### status: %s", status);
-            }
-        } while (strncmp(status, "STATE=up", 8) && strcmp(status, "online") && --retry);
-
-        close(fd);
-
-        if (retry == 0) {
-            LOGE("### Failed to get data connection up\n");
-	        goto error;
-		}
-
-        qmistatus = system("netcfg rmnet0 dhcp");
-
-        LOGD("netcfg rmnet0 dhcp: status %d\n", qmistatus);
-
-	    if (qmistatus < 0) goto error;
-
-	} else {
-
-        asprintf(&cmd, "AT+CGDCONT=1,\"IP\",\"%s\",,0,0", apn);
-	    //FIXME check for error here
-	    err = at_send_command(cmd, NULL);
-	    free(cmd);
-
-	    // Set required QoS params to default
-	    err = at_send_command("AT+CGQREQ=1", NULL);
-
-	    // Set minimum QoS params to default
-	    err = at_send_command("AT+CGQMIN=1", NULL);
-
-	    // packet-domain event reporting
-	    err = at_send_command("AT+CGEREP=1,0", NULL);
-
-	    // Hangup anything that's happening there now
-	    err = at_send_command("AT+CGACT=1,0", NULL);
-
-	    // Start data on PDP context 1
-	    err = at_send_command("ATD*99***1#", &p_response);
-
-	    if (err < 0 || p_response->success == 0) {
-	        goto error;
-	    }
-    }
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
-    at_response_free(p_response);
-
-    return;
-error:
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-
-}
-
-static void requestSMSAcknowledge(void *data, size_t datalen, RIL_Token t)
-{
-    int ackSuccess;
-    int err;
-
-    ackSuccess = ((int *)data)[0];
-
-    if (ackSuccess == 1) {
-        err = at_send_command("AT+CNMA=1", NULL);
-    } else if (ackSuccess == 0)  {
-        err = at_send_command("AT+CNMA=2", NULL);
-    } else {
-        LOGE("unsupported arg to RIL_REQUEST_SMS_ACKNOWLEDGE\n");
-        goto error;
-    }
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-error:
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-
-}
-
-static void  requestSIM_IO(void *data, size_t datalen, RIL_Token t)
-{
-    ATResponse *p_response = NULL;
-    RIL_SIM_IO_Response sr;
-    int err;
-    char *cmd = NULL;
-    RIL_SIM_IO *p_args;
-    char *line;
-
-    memset(&sr, 0, sizeof(sr));
-
-    p_args = (RIL_SIM_IO *)data;
-
-    /* FIXME handle pin2 */
-
-    if (p_args->data == NULL) {
-        asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d",
-                    p_args->command, p_args->fileid,
-                    p_args->p1, p_args->p2, p_args->p3);
-    } else {
-        asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d,%s",
-                    p_args->command, p_args->fileid,
-                    p_args->p1, p_args->p2, p_args->p3, p_args->data);
-    }
-
-    err = at_send_command_singleline(cmd, "+CRSM:", &p_response);
-
-    if (err < 0 || p_response->success == 0) {
-        goto error;
-    }
-
-    line = p_response->p_intermediates->line;
-
-    err = at_tok_start(&line);
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &(sr.sw1));
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &(sr.sw2));
-    if (err < 0) goto error;
-
-    if (at_tok_hasmore(&line)) {
-        err = at_tok_nextstr(&line, &(sr.simResponse));
-        if (err < 0) goto error;
-    }
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, &sr, sizeof(sr));
-    at_response_free(p_response);
-    free(cmd);
-
-    return;
-error:
-    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-    at_response_free(p_response);
-    free(cmd);
-
-}
-
-static void  requestEnterSimPin(void*  data, size_t  datalen, RIL_Token  t)
-{
-    ATResponse   *p_response = NULL;
-    int           err;
-    char*         cmd = NULL;
-    const char**  strings = (const char**)data;;
-
-    if ( datalen == sizeof(char*) ) {
-        asprintf(&cmd, "AT+CPIN=%s", strings[0]);
-    } else if ( datalen == 2*sizeof(char*) ) {
-        asprintf(&cmd, "AT+CPIN=%s,%s", strings[0], strings[1]);
-    } else
-        goto error;
-
-    err = at_send_command_singleline(cmd, "+CPIN:", &p_response);
-    free(cmd);
-
-    if (err < 0 || p_response->success == 0) {
-error:
-        RIL_onRequestComplete(t, RIL_E_PASSWORD_INCORRECT, NULL, 0);
-    } else {
-        RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-    }
-    at_response_free(p_response);
-}
-
-
-static void  requestSendUSSD(void *data, size_t datalen, RIL_Token t)
-{
-    const char *ussdRequest;
-
-    ussdRequest = (char *)(data);
-
-
-    RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
-
-// @@@ TODO
-
-}
-
-
-/*** Callback methods from the RIL library to us ***/
-
-/**
- * Call from RIL to us to make a RIL_REQUEST
- *
- * Must be completed with a call to RIL_onRequestComplete()
- *
- * RIL_onRequestComplete() may be called from any thread, before or after
- * this function returns.
- *
- * Will always be called from the same thread, so returning here implies
- * that the radio is ready to process another command (whether or not
- * the previous command has completed).
- */
-static void
-onRequest (int request, void *data, size_t datalen, RIL_Token t)
-{
-    ATResponse *p_response;
-    int err;
-
-    LOGD("onRequest: %s", requestToString(request));
-
-    /* Ignore all requests except RIL_REQUEST_GET_SIM_STATUS
-     * when RADIO_STATE_UNAVAILABLE.
-     */
-    if (sState == RADIO_STATE_UNAVAILABLE
-        && request != RIL_REQUEST_GET_SIM_STATUS
-    ) {
-        RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
-        return;
-    }
-
-    /* Ignore all non-power requests when RADIO_STATE_OFF
-     * (except RIL_REQUEST_GET_SIM_STATUS)
-     */
-    if (sState == RADIO_STATE_OFF
-        && !(request == RIL_REQUEST_RADIO_POWER
-            || request == RIL_REQUEST_GET_SIM_STATUS)
-    ) {
-        RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
-        return;
-    }
-
-    switch (request) {
-        case RIL_REQUEST_GET_SIM_STATUS: {
-            int simStatus;
-
-            simStatus = getSIMStatus();
-
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, &simStatus, sizeof(simStatus));
-            break;
-        }
-        case RIL_REQUEST_GET_CURRENT_CALLS:
-            requestGetCurrentCalls(data, datalen, t);
-            break;
-        case RIL_REQUEST_DIAL:
-            requestDial(data, datalen, t);
-            break;
-        case RIL_REQUEST_HANGUP:
-            requestHangup(data, datalen, t);
-            break;
-        case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND:
-            // 3GPP 22.030 6.5.5
-            // "Releases all held calls or sets User Determined User Busy
-            //  (UDUB) for a waiting call."
-            at_send_command("AT+CHLD=0", NULL);
-
-            /* success or failure is ignored by the upper layer here.
-               it will call GET_CURRENT_CALLS and determine success that way */
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-        case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND:
-            // 3GPP 22.030 6.5.5
-            // "Releases all active calls (if any exist) and accepts
-            //  the other (held or waiting) call."
-            at_send_command("AT+CHLD=1", NULL);
-
-            /* success or failure is ignored by the upper layer here.
-               it will call GET_CURRENT_CALLS and determine success that way */
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-        case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE:
-            // 3GPP 22.030 6.5.5
-            // "Places all active calls (if any exist) on hold and accepts
-            //  the other (held or waiting) call."
-            at_send_command("AT+CHLD=2", NULL);
-
-#ifdef WORKAROUND_ERRONEOUS_ANSWER
-            s_expectAnswer = 1;
-#endif /* WORKAROUND_ERRONEOUS_ANSWER */
-
-            /* success or failure is ignored by the upper layer here.
-               it will call GET_CURRENT_CALLS and determine success that way */
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-        case RIL_REQUEST_ANSWER:
-            at_send_command("ATA", NULL);
-
-#ifdef WORKAROUND_ERRONEOUS_ANSWER
-            s_expectAnswer = 1;
-#endif /* WORKAROUND_ERRONEOUS_ANSWER */
-
-            /* success or failure is ignored by the upper layer here.
-               it will call GET_CURRENT_CALLS and determine success that way */
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-        case RIL_REQUEST_CONFERENCE:
-            // 3GPP 22.030 6.5.5
-            // "Adds a held call to the conversation"
-            at_send_command("AT+CHLD=3", NULL);
-
-            /* success or failure is ignored by the upper layer here.
-               it will call GET_CURRENT_CALLS and determine success that way */
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-        case RIL_REQUEST_UDUB:
-            /* user determined user busy */
-            /* sometimes used: ATH */
-            at_send_command("ATH", NULL);
-
-            /* success or failure is ignored by the upper layer here.
-               it will call GET_CURRENT_CALLS and determine success that way */
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-
-        case RIL_REQUEST_SEPARATE_CONNECTION:
-            {
-                char  cmd[12];
-                int   party = ((int*)data)[0];
-
-                // Make sure that party is in a valid range.
-                // (Note: The Telephony middle layer imposes a range of 1 to 7.
-                // It's sufficient for us to just make sure it's single digit.)
-                if (party > 0 && party < 10) {
-                    sprintf(cmd, "AT+CHLD=2%d", party);
-                    at_send_command(cmd, NULL);
-                    RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-                } else {
-                    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-                }
-            }
-            break;
-
-        case RIL_REQUEST_SIGNAL_STRENGTH:
-            requestSignalStrength(data, datalen, t);
-            break;
-        case RIL_REQUEST_REGISTRATION_STATE:
-        case RIL_REQUEST_GPRS_REGISTRATION_STATE:
-            requestRegistrationState(request, data, datalen, t);
-            break;
-        case RIL_REQUEST_OPERATOR:
-            requestOperator(data, datalen, t);
-            break;
-        case RIL_REQUEST_RADIO_POWER:
-            requestRadioPower(data, datalen, t);
-            break;
-        case RIL_REQUEST_DTMF: {
-            char c = ((char *)data)[0];
-            char *cmd;
-            asprintf(&cmd, "AT+VTS=%c", (int)c);
-            at_send_command(cmd, NULL);
-            free(cmd);
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            break;
-        }
-        case RIL_REQUEST_SEND_SMS:
-            requestSendSMS(data, datalen, t);
-            break;
-        case RIL_REQUEST_SETUP_DEFAULT_PDP:
-            requestSetupDefaultPDP(data, datalen, t);
-            break;
-        case RIL_REQUEST_SMS_ACKNOWLEDGE:
-            requestSMSAcknowledge(data, datalen, t);
-            break;
-
-        case RIL_REQUEST_GET_IMSI:
-            p_response = NULL;
-            err = at_send_command_numeric("AT+CIMI", &p_response);
-
-            if (err < 0 || p_response->success == 0) {
-                RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-            } else {
-                RIL_onRequestComplete(t, RIL_E_SUCCESS,
-                    p_response->p_intermediates->line, sizeof(char *));
-            }
-            at_response_free(p_response);
-            break;
-
-        case RIL_REQUEST_GET_IMEI:
-            p_response = NULL;
-            err = at_send_command_numeric("AT+CGSN", &p_response);
-
-            if (err < 0 || p_response->success == 0) {
-                RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-            } else {
-                RIL_onRequestComplete(t, RIL_E_SUCCESS,
-                    p_response->p_intermediates->line, sizeof(char *));
-            }
-            at_response_free(p_response);
-            break;
-
-        case RIL_REQUEST_SIM_IO:
-            requestSIM_IO(data,datalen,t);
-            break;
-
-        case RIL_REQUEST_SEND_USSD:
-            requestSendUSSD(data, datalen, t);
-            break;
-
-        case RIL_REQUEST_CANCEL_USSD:
-            p_response = NULL;
-            err = at_send_command_numeric("AT+CUSD=2", &p_response);
-
-            if (err < 0 || p_response->success == 0) {
-                RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-            } else {
-                RIL_onRequestComplete(t, RIL_E_SUCCESS,
-                    p_response->p_intermediates->line, sizeof(char *));
-            }
-            at_response_free(p_response);
-            break;
-
-        case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC:
-            at_send_command("AT+COPS=0", NULL);
-            break;
-
-        case RIL_REQUEST_PDP_CONTEXT_LIST:
-            requestPDPContextList(data, datalen, t);
-            break;
-
-        case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE:
-            requestQueryNetworkSelectionMode(data, datalen, t);
-            break;
-
-        case RIL_REQUEST_OEM_HOOK_RAW:
-            // echo back data
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, data, datalen);
-            break;
-
-
-        case RIL_REQUEST_OEM_HOOK_STRINGS: {
-            int i;
-            const char ** cur;
-
-            LOGD("got OEM_HOOK_STRINGS: 0x%8p %lu", data, (long)datalen);
-
-
-            for (i = (datalen / sizeof (char *)), cur = (const char **)data ;
-                    i > 0 ; cur++, i --) {
-                LOGD("> '%s'", *cur);
-            }
-
-            // echo back strings
-            RIL_onRequestComplete(t, RIL_E_SUCCESS, data, datalen);
-            break;
-        }
-
-        case RIL_REQUEST_WRITE_SMS_TO_SIM:
-            requestWriteSmsToSim(data, datalen, t);
-            break;
-
-        case RIL_REQUEST_DELETE_SMS_ON_SIM: {
-            char * cmd;
-            p_response = NULL;
-            asprintf(&cmd, "AT+CMGD=%d", ((int *)data)[0]);
-            err = at_send_command(cmd, &p_response);
-            free(cmd);
-            if (err < 0 || p_response->success == 0) {
-                RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
-            } else {
-                RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-            }
-            at_response_free(p_response);
-            break;
-        }
-
-        case RIL_REQUEST_ENTER_SIM_PIN:
-        case RIL_REQUEST_ENTER_SIM_PUK:
-        case RIL_REQUEST_ENTER_SIM_PIN2:
-        case RIL_REQUEST_ENTER_SIM_PUK2:
-        case RIL_REQUEST_CHANGE_SIM_PIN:
-        case RIL_REQUEST_CHANGE_SIM_PIN2:
-            requestEnterSimPin(data, datalen, t);
-            break;
-
-        default:
-            RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
-            break;
-    }
-}
-
-/**
- * Synchronous call from the RIL to us to return current radio state.
- * RADIO_STATE_UNAVAILABLE should be the initial state.
- */
-static RIL_RadioState
-currentState()
-{
-    return sState;
-}
-/**
- * Call from RIL to us to find out whether a specific request code
- * is supported by this implementation.
- *
- * Return 1 for "supported" and 0 for "unsupported"
- */
-
-static int
-onSupports (int requestCode)
-{
-    //@@@ todo
-
-    return 1;
-}
-
-static void onCancel (RIL_Token t)
-{
-    //@@@todo
-
-}
-
-static const char * getVersion(void)
-{
-    return "android reference-ril 1.0";
-}
-
-static void
-setRadioState(RIL_RadioState newState)
-{
-    RIL_RadioState oldState;
-
-    pthread_mutex_lock(&s_state_mutex);
-
-    oldState = sState;
-
-    if (s_closed > 0) {
-        // If we're closed, the only reasonable state is
-        // RADIO_STATE_UNAVAILABLE
-        // This is here because things on the main thread
-        // may attempt to change the radio state after the closed
-        // event happened in another thread
-        newState = RADIO_STATE_UNAVAILABLE;
-    }
-
-    if (sState != newState || s_closed > 0) {
-        sState = newState;
-
-        pthread_cond_broadcast (&s_state_cond);
-    }
-
-    pthread_mutex_unlock(&s_state_mutex);
-
-
-    /* do these outside of the mutex */
-    if (sState != oldState) {
-        RIL_onUnsolicitedResponse (RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
-                                    NULL, 0);
-
-        /* FIXME onSimReady() and onRadioPowerOn() cannot be called
-         * from the AT reader thread
-         * Currently, this doesn't happen, but if that changes then these
-         * will need to be dispatched on the request thread
-         */
-        if (sState == RADIO_STATE_SIM_READY) {
-            onSIMReady();
-        } else if (sState == RADIO_STATE_SIM_NOT_READY) {
-            onRadioPowerOn();
-        }
-    }
-}
-
-/** returns one of RIM_SIM_*. Returns RIL_SIM_NOT_READY on error */
-static int
-getSIMStatus()
-{
-    ATResponse *p_response = NULL;
-    int err;
-    int ret;
-    char *cpinLine;
-    char *cpinResult;
-
-    if (sState == RADIO_STATE_OFF || sState == RADIO_STATE_UNAVAILABLE) {
-        ret = RIL_SIM_NOT_READY;
-        goto done;
-    }
-
-    err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &p_response);
-
-    if (err != 0) {
-        ret = RIL_SIM_NOT_READY;
-        goto done;
-    }
-
-    switch (at_get_cme_error(p_response)) {
-        case CME_SUCCESS:
-            break;
-
-        case CME_SIM_NOT_INSERTED:
-            ret = RIL_SIM_ABSENT;
-            goto done;
-
-        default:
-            ret = RIL_SIM_NOT_READY;
-            goto done;
-    }
-
-    /* CPIN? has succeeded, now look at the result */
-
-    cpinLine = p_response->p_intermediates->line;
-    err = at_tok_start (&cpinLine);
-
-    if (err < 0) {
-        ret = RIL_SIM_NOT_READY;
-        goto done;
-    }
-
-    err = at_tok_nextstr(&cpinLine, &cpinResult);
-
-    if (err < 0) {
-        ret = RIL_SIM_NOT_READY;
-        goto done;
-    }
-
-    if (0 == strcmp (cpinResult, "SIM PIN")) {
-        ret = RIL_SIM_PIN;
-        goto done;
-    } else if (0 == strcmp (cpinResult, "SIM PUK")) {
-        ret = RIL_SIM_PUK;
-        goto done;
-    } else if (0 == strcmp (cpinResult, "PH-NET PIN")) {
-        return RIL_SIM_NETWORK_PERSONALIZATION;
-    } else if (0 != strcmp (cpinResult, "READY"))  {
-        /* we're treating unsupported lock types as "sim absent" */
-        ret = RIL_SIM_ABSENT;
-        goto done;
-    }
-
-    at_response_free(p_response);
-    p_response = NULL;
-    cpinResult = NULL;
-
-    ret = RIL_SIM_READY;
-
-done:
-    at_response_free(p_response);
-    return ret;
-}
-
-
-/**
- * SIM ready means any commands that access the SIM will work, including:
- *  AT+CPIN, AT+CSMS, AT+CNMI, AT+CRSM
- *  (all SMS-related commands)
- */
-
-static void pollSIMState (void *param)
-{
-    ATResponse *p_response;
-    int ret;
-
-    if (sState != RADIO_STATE_SIM_NOT_READY) {
-        // no longer valid to poll
-        return;
-    }
-
-    switch(getSIMStatus()) {
-        case RIL_SIM_ABSENT:
-        case RIL_SIM_PIN:
-        case RIL_SIM_PUK:
-        case RIL_SIM_NETWORK_PERSONALIZATION:
-        default:
-            setRadioState(RADIO_STATE_SIM_LOCKED_OR_ABSENT);
-        return;
-
-        case RIL_SIM_NOT_READY:
-            RIL_requestTimedCallback (pollSIMState, NULL, &TIMEVAL_SIMPOLL);
-        return;
-
-        case RIL_SIM_READY:
-            setRadioState(RADIO_STATE_SIM_READY);
-        return;
-    }
-}
-
-/** returns 1 if on, 0 if off, and -1 on error */
-static int isRadioOn()
-{
-    ATResponse *p_response = NULL;
-    int err;
-    char *line;
-    char ret;
-
-    err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &p_response);
-
-    if (err < 0 || p_response->success == 0) {
-        // assume radio is off
-        goto error;
-    }
-
-    line = p_response->p_intermediates->line;
-
-    err = at_tok_start(&line);
-    if (err < 0) goto error;
-
-    err = at_tok_nextbool(&line, &ret);
-    if (err < 0) goto error;
-
-    at_response_free(p_response);
-
-    return (int)ret;
-
-error:
-
-    at_response_free(p_response);
-    return -1;
-}
-
-/**
- * Initialize everything that can be configured while we're still in
- * AT+CFUN=0
- */
-static void initializeCallback(void *param)
-{
-    ATResponse *p_response = NULL;
-    int err;
-
-    setRadioState (RADIO_STATE_OFF);
-
-    at_handshake();
-
-    /* note: we don't check errors here. Everything important will
-       be handled in onATTimeout and onATReaderClosed */
-
-    /*  atchannel is tolerant of echo but it must */
-    /*  have verbose result codes */
-    at_send_command("ATE0Q0V1", NULL);
-
-    /*  No auto-answer */
-    at_send_command("ATS0=0", NULL);
-
-    /*  Extended errors */
-    at_send_command("AT+CMEE=1", NULL);
-
-    /*  Network registration events */
-    err = at_send_command("AT+CREG=2", &p_response);
-
-    /* some handsets -- in tethered mode -- don't support CREG=2 */
-    if (err < 0 || p_response->success == 0) {
-        at_send_command("AT+CREG=1", NULL);
-    }
-
-    at_response_free(p_response);
-
-    /*  GPRS registration events */
-    at_send_command("AT+CGREG=1", NULL);
-
-    /*  Call Waiting notifications */
-    at_send_command("AT+CCWA=1", NULL);
-
-    /*  Alternating voice/data off */
-    at_send_command("AT+CMOD=0", NULL);
-
-    /*  Not muted */
-    at_send_command("AT+CMUT=0", NULL);
-
-    /*  +CSSU unsolicited supp service notifications */
-    at_send_command("AT+CSSN=0,1", NULL);
-
-    /*  no connected line identification */
-    at_send_command("AT+COLP=0", NULL);
-
-    /*  HEX character set */
-    at_send_command("AT+CSCS=\"HEX\"", NULL);
-
-    /*  USSD unsolicited */
-    at_send_command("AT+CUSD=1", NULL);
-
-    /*  Enable +CGEV GPRS event notifications, but don't buffer */
-    at_send_command("AT+CGEREP=1,0", NULL);
-
-    /*  SMS PDU mode */
-    at_send_command("AT+CMGF=0", NULL);
-
-#ifdef USE_TI_COMMANDS
-
-    at_send_command("AT%CPI=3", NULL);
-
-    /*  TI specific -- notifications when SMS is ready (currently ignored) */
-    at_send_command("AT%CSTAT=1", NULL);
-
-#endif /* USE_TI_COMMANDS */
-
-
-    /* assume radio is off on error */
-    if (isRadioOn() > 0) {
-        setRadioState (RADIO_STATE_SIM_NOT_READY);
-    }
-}
-
-static void waitForClose()
-{
-    pthread_mutex_lock(&s_state_mutex);
-
-    while (s_closed == 0) {
-        pthread_cond_wait(&s_state_cond, &s_state_mutex);
-    }
-
-    pthread_mutex_unlock(&s_state_mutex);
-}
-
-/**
- * Called by atchannel when an unsolicited line appears
- * This is called on atchannel's reader thread. AT commands may
- * not be issued here
- */
-static void onUnsolicited (const char *s, const char *sms_pdu)
-{
-    char *line = NULL;
-    int err;
-
-    /* Ignore unsolicited responses until we're initialized.
-     * This is OK because the RIL library will poll for initial state
-     */
-    if (sState == RADIO_STATE_UNAVAILABLE) {
-        return;
-    }
-
-    if (strStartsWith(s, "%CTZV:")) {
-        /* TI specific -- NITZ time */
-        char *response;
-
-        line = strdup(s);
-        at_tok_start(&line);
-
-        err = at_tok_nextstr(&line, &response);
-
-        if (err != 0) {
-            LOGE("invalid NITZ line %s\n", s);
-        } else {
-            RIL_onUnsolicitedResponse (
-                RIL_UNSOL_NITZ_TIME_RECEIVED,
-                response, strlen(response));
-        }
-    } else if (strStartsWith(s,"+CRING:")
-                || strStartsWith(s,"RING")
-                || strStartsWith(s,"NO CARRIER")
-                || strStartsWith(s,"+CCWA")
-    ) {
-        RIL_onUnsolicitedResponse (
-            RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,
-            NULL, 0);
-#ifdef WORKAROUND_FAKE_CGEV
-        RIL_requestTimedCallback (onPDPContextListChanged, NULL, NULL);
-#endif /* WORKAROUND_FAKE_CGEV */
-    } else if (strStartsWith(s,"+CREG:")
-                || strStartsWith(s,"+CGREG:")
-    ) {
-        RIL_onUnsolicitedResponse (
-            RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED,
-            NULL, 0);
-#ifdef WORKAROUND_FAKE_CGEV
-        RIL_requestTimedCallback (onPDPContextListChanged, NULL, NULL);
-#endif /* WORKAROUND_FAKE_CGEV */
-    } else if (strStartsWith(s, "+CMT:")) {
-        RIL_onUnsolicitedResponse (
-            RIL_UNSOL_RESPONSE_NEW_SMS,
-            sms_pdu, strlen(sms_pdu));
-    } else if (strStartsWith(s, "+CDS:")) {
-        RIL_onUnsolicitedResponse (
-            RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT,
-            sms_pdu, strlen(sms_pdu));
-    } else if (strStartsWith(s, "+CGEV:")) {
-        /* Really, we can ignore NW CLASS and ME CLASS events here,
-         * but right now we don't since extranous
-         * RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED calls are tolerated
-         */
-        /* can't issue AT commands here -- call on main thread */
-        RIL_requestTimedCallback (onPDPContextListChanged, NULL, NULL);
-#ifdef WORKAROUND_FAKE_CGEV
-    } else if (strStartsWith(s, "+CME ERROR: 150")) {
-        RIL_requestTimedCallback (onPDPContextListChanged, NULL, NULL);
-#endif /* WORKAROUND_FAKE_CGEV */
-    }
-}
-
-/* Called on command or reader thread */
-static void onATReaderClosed()
-{
-    LOGI("AT channel closed\n");
-    at_close();
-    s_closed = 1;
-
-    setRadioState (RADIO_STATE_UNAVAILABLE);
-}
-
-/* Called on command thread */
-static void onATTimeout()
-{
-    LOGI("AT channel timeout; closing\n");
-    at_close();
-
-    s_closed = 1;
-
-    /* FIXME cause a radio reset here */
-
-    setRadioState (RADIO_STATE_UNAVAILABLE);
-}
-
-static void usage(char *s)
-{
-#ifdef RIL_SHLIB
-    fprintf(stderr, "reference-ril requires: -p <tcp port> or -d /dev/tty_device\n");
-#else
-    fprintf(stderr, "usage: %s [-p <tcp port>] [-d /dev/tty_device]\n", s);
-    exit(-1);
-#endif
-}
-
-static void *
-mainLoop(void *param)
-{
-    int fd;
-    int ret;
-
-    AT_DUMP("== ", "entering mainLoop()", -1 );
-    at_set_on_reader_closed(onATReaderClosed);
-    at_set_on_timeout(onATTimeout);
-
-    for (;;) {
-        fd = -1;
-        while  (fd < 0) {
-            if (s_port > 0) {
-                fd = socket_loopback_client(s_port, SOCK_STREAM);
-            } else if (s_device_socket) {
-                fd = socket_local_client( s_device_path,
-                                          ANDROID_SOCKET_NAMESPACE_FILESYSTEM,
-                                          SOCK_STREAM );
-            } else if (s_device_path != NULL) {
-                fd = open (s_device_path, O_RDWR);
-                if ( fd >= 0 && !memcmp( s_device_path, "/dev/ttyS", 9 ) ) {
-                    /* disable echo on serial ports */
-                    struct termios  ios;
-                    tcgetattr( fd, &ios );
-                    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
-                    tcsetattr( fd, TCSANOW, &ios );
-                }
-            }
-
-            if (fd < 0) {
-                perror ("opening AT interface. retrying...");
-                sleep(10);
-                /* never returns */
-            }
-        }
-
-        s_closed = 0;
-        ret = at_open(fd, onUnsolicited);
-
-        if (ret < 0) {
-            LOGE ("AT error %d on at_open\n", ret);
-            return 0;
-        }
-
-        RIL_requestTimedCallback(initializeCallback, NULL, &TIMEVAL_0);
-
-        // Give initializeCallback a chance to dispatched, since
-        // we don't presently have a cancellation mechanism
-        sleep(1);
-
-        waitForClose();
-        LOGI("Re-opening after close");
-    }
-}
-
-#ifdef RIL_SHLIB
-
-pthread_t s_tid_mainloop;
-
-const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv)
-{
-    int ret;
-    int fd = -1;
-    int opt;
-    pthread_attr_t attr;
-
-    s_rilenv = env;
-
-    while ( -1 != (opt = getopt(argc, argv, "p:d:s:"))) {
-        switch (opt) {
-            case 'p':
-                s_port = atoi(optarg);
-                if (s_port == 0) {
-                    usage(argv[0]);
-                    return NULL;
-                }
-                LOGI("Opening loopback port %d\n", s_port);
-            break;
-
-            case 'd':
-                s_device_path = optarg;
-                LOGI("Opening tty device %s\n", s_device_path);
-            break;
-
-            case 's':
-                s_device_path   = optarg;
-                s_device_socket = 1;
-                LOGI("Opening socket %s\n", s_device_path);
-            break;
-
-            default:
-                usage(argv[0]);
-                return NULL;
-        }
-    }
-
-    if (s_port < 0 && s_device_path == NULL) {
-        usage(argv[0]);
-        return NULL;
-    }
-
-    pthread_attr_init (&attr);
-    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-    ret = pthread_create(&s_tid_mainloop, &attr, mainLoop, NULL);
-
-    return &s_callbacks;
-}
-#else /* RIL_SHLIB */
-int main (int argc, char **argv)
-{
-    int ret;
-    int fd = -1;
-    int opt;
-
-    while ( -1 != (opt = getopt(argc, argv, "p:d:"))) {
-        switch (opt) {
-            case 'p':
-                s_port = atoi(optarg);
-                if (s_port == 0) {
-                    usage(argv[0]);
-                }
-                LOGI("Opening loopback port %d\n", s_port);
-            break;
-
-            case 'd':
-                s_device_path = optarg;
-                LOGI("Opening tty device %s\n", s_device_path);
-            break;
-
-            case 's':
-                s_device_path   = optarg;
-                s_device_socket = 1;
-                LOGI("Opening socket %s\n", s_device_path);
-            break;
-
-            default:
-                usage(argv[0]);
-        }
-    }
-
-    if (s_port < 0 && s_device_path == NULL) {
-        usage(argv[0]);
-    }
-
-    RIL_register(&s_callbacks);
-
-    mainLoop(NULL);
-
-    return 0;
-}
-
-#endif /* RIL_SHLIB */
diff --git a/rild/Android.mk b/rild/Android.mk
deleted file mode 100644
index a54e5b7..0000000
--- a/rild/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2006 The Android Open Source Project
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	rild.c
-
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libril
-
-LOCAL_CFLAGS := -DRIL_SHLIB
-
-LOCAL_MODULE:= rild
-
-include $(BUILD_EXECUTABLE)
-
-# For radiooptions binary
-# =======================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	radiooptions.c
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-
-LOCAL_CFLAGS := \
-
-LOCAL_MODULE:= radiooptions
-
-include $(BUILD_EXECUTABLE)
diff --git a/rild/MODULE_LICENSE_APACHE2 b/rild/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/rild/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/rild/NOTICE b/rild/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/rild/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
-   Copyright (c) 2005-2008, The Android Open Source Project
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
diff --git a/rild/radiooptions.c b/rild/radiooptions.c
deleted file mode 100644
index ec32f40..0000000
--- a/rild/radiooptions.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/* //device/system/toolbox/resetradio.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License"); 
-** you may not use this file except in compliance with the License. 
-** You may obtain a copy of the License at 
-**
-**     http://www.apache.org/licenses/LICENSE-2.0 
-**
-** Unless required by applicable law or agreed to in writing, software 
-** distributed under the License is distributed on an "AS IS" BASIS, 
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-** See the License for the specific language governing permissions and 
-** limitations under the License.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <cutils/sockets.h>
-
-#define SOCKET_NAME_RIL_DEBUG	"rild-debug"	/* from ril.cpp */
-
-enum options {
-    RADIO_RESET,
-    RADIO_OFF,
-    UNSOL_NETWORK_STATE_CHANGE,
-    QXDM_ENABLE,
-    QXDM_DISABLE,
-    RADIO_ON,
-    SETUP_PDP,
-    DEACTIVATE_PDP,
-    DIAL_CALL,
-    ANSWER_CALL,
-    END_CALL,
-};
-
-
-static void print_usage() {
-    perror("Usage: radiooptions [option] [extra_socket_args]\n\
-           0 - RADIO_RESET, \n\
-           1 - RADIO_OFF, \n\
-           2 - UNSOL_NETWORK_STATE_CHANGE, \n\
-           3 - QXDM_ENABLE, \n\
-           4 - QXDM_DISABLE, \n\
-           5 - RADIO_ON, \n\
-           6 apn- SETUP_PDP apn, \n\
-           7 - DEACTIVE_PDP, \n\
-           8 number - DIAL_CALL number, \n\
-           9 - ANSWER_CALL, \n\
-           10 - END_CALL \n");
-}
-
-static int error_check(int argc, char * argv[]) {
-    if (argc < 2) {
-        return -1;
-    }
-    const int option = atoi(argv[1]);
-    if (option < 0 || option > 10) {
-        return 0;
-    } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 3) {
-        return 0;
-    } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 2) {
-        return 0;
-    }
-    return -1;
-}
-
-static int get_number_args(char *argv[]) {
-    const int option = atoi(argv[1]);
-    if (option != DIAL_CALL && option != SETUP_PDP) {
-        return 1;
-    } else {
-        return 2;
-    }
-}
-
-int main(int argc, char *argv[])
-{
-    int fd;
-    int num_socket_args = 0;
-    int i  = 0;
-    if(error_check(argc, argv)) {
-        print_usage();
-        exit(-1);
-    }
-
-    fd = socket_local_client(SOCKET_NAME_RIL_DEBUG,
-                             ANDROID_SOCKET_NAMESPACE_RESERVED,
-                             SOCK_STREAM);
-    if (fd < 0) {
-        perror ("opening radio debug socket");
-        exit(-1);
-    }
-
-    num_socket_args = get_number_args(argv);
-    int ret = send(fd, (const void *)&num_socket_args, sizeof(int), 0);
-    if(ret != sizeof(int)) {
-        perror ("Socket write error when sending num args");
-        close(fd);
-        exit(-1);
-    }
-
-    for (i = 0; i < num_socket_args; i++) {
-        // Send length of the arg, followed by the arg.
-        int len = strlen(argv[1 + i]);
-        ret = send(fd, &len, sizeof(int), 0);
-        if (ret != sizeof(int)) {
-            perror("Socket write Error: when sending arg length");
-            close(fd);
-            exit(-1);
-        }
-        ret = send(fd, argv[1 + i], sizeof(char) * len, 0);
-        if (ret != len * sizeof(char)) {
-            perror ("Socket write Error: When sending arg");
-            close(fd);
-            exit(-1);
-        }
-    }
-
-    close(fd);
-    return 0;
-}
diff --git a/rild/rild.c b/rild/rild.c
deleted file mode 100644
index 5b62501..0000000
--- a/rild/rild.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/* //device/system/rild/rild.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <dlfcn.h>
-#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <telephony/ril.h>
-#define LOG_TAG "RILD"
-#include <utils/Log.h>
-#include <cutils/properties.h>
-#include <cutils/sockets.h>
-#include <linux/capability.h>
-#include <linux/prctl.h>
-
-#include <private/android_filesystem_config.h>
-
-#define LIB_PATH_PROPERTY   "rild.libpath"
-#define LIB_ARGS_PROPERTY   "rild.libargs"
-#define MAX_LIB_ARGS        16
-
-static void usage(const char *argv0)
-{
-    fprintf(stderr, "Usage: %s -l <ril impl library> [-- <args for impl library>]\n", argv0);
-    exit(-1);
-}
-
-extern void RIL_register (const RIL_RadioFunctions *callbacks);
-
-extern void RIL_onRequestComplete(RIL_Token t, RIL_Errno e,
-                           void *response, size_t responselen);
-
-extern void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
-                                size_t datalen);
-
-extern void RIL_requestTimedCallback (RIL_TimedCallback callback,
-                               void *param, const struct timeval *relativeTime);
-
-
-static struct RIL_Env s_rilEnv = {
-    RIL_onRequestComplete,
-    RIL_onUnsolicitedResponse,
-    RIL_requestTimedCallback
-};
-
-extern void RIL_startEventLoop();
-
-static int make_argv(char * args, char ** argv)
-{
-    // Note: reserve argv[0]
-    int count = 1;
-    char * tok;
-    char * s = args;
-
-    while ((tok = strtok(s, " \0"))) {
-        argv[count] = tok;
-        s = NULL;
-        count++;
-    }
-    return count;
-}
-
-/*
- * switchUser - Switches UID to radio, preserving CAP_NET_ADMIN capabilities.
- * Our group, cache, was set by init.
- */
-void switchUser() {
-    prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
-    setuid(AID_RADIO);
-
-    struct __user_cap_header_struct header;
-    struct __user_cap_data_struct cap;
-    header.version = _LINUX_CAPABILITY_VERSION;
-    header.pid = 0;
-    cap.effective = cap.permitted = 1 << CAP_NET_ADMIN;
-    cap.inheritable = 0;
-    capset(&header, &cap);
-}
-
-int main(int argc, char **argv)
-{
-    const char * rilLibPath = NULL;
-    char **rilArgv;
-    void *dlHandle;
-    const RIL_RadioFunctions *(*rilInit)(const struct RIL_Env *, int, char **);
-    const RIL_RadioFunctions *funcs;
-    char libPath[PROPERTY_VALUE_MAX];
-    unsigned char hasLibArgs = 0;
-
-    int i;
-
-    for (i = 1; i < argc ;) {
-        if (0 == strcmp(argv[i], "-l") && (argc - i > 1)) {
-            rilLibPath = argv[i + 1];
-            i += 2;
-        } else if (0 == strcmp(argv[i], "--")) {
-            i++;
-            hasLibArgs = 1;
-            break;
-        } else {
-            usage(argv[0]);
-        }
-    }
-
-    if (rilLibPath == NULL) {
-        if ( 0 == property_get(LIB_PATH_PROPERTY, libPath, NULL)) {
-            // No lib sepcified on the command line, and nothing set in props.
-            // Assume "no-ril" case.
-            goto done;
-        } else {
-            rilLibPath = libPath;
-        }
-    }
-
-    /* special override when in the emulator */
-#if 1
-    {
-        static char*  arg_overrides[3];
-        static char   arg_device[32];
-        int           done = 0;
-
-#define  REFERENCE_RIL_PATH  "/system/lib/libreference-ril.so"
-
-        /* first, read /proc/cmdline into memory */
-        char          buffer[1024], *p, *q;
-        int           len;
-        int           fd = open("/proc/cmdline",O_RDONLY);
-
-        if (fd < 0) {
-            LOGD("could not open /proc/cmdline:%s", strerror(errno));
-            goto OpenLib;
-        }
-
-        do {
-            len = read(fd,buffer,sizeof(buffer)); }
-        while (len == -1 && errno == EINTR);
-
-        if (len < 0) {
-            LOGD("could not read /proc/cmdline:%s", strerror(errno));
-            close(fd);
-            goto OpenLib;
-        }
-        close(fd);
-
-        if (strstr(buffer, "android.qemud=") != NULL)
-        {
-            /* the qemud daemon is launched after rild, so
-            * give it some time to create its GSM socket
-            */
-            int  tries = 5;
-#define  QEMUD_SOCKET_NAME    "qemud_gsm"
-
-            while (1) {
-                int  fd;
-
-                sleep(1);
-
-                fd = socket_local_client(
-                            QEMUD_SOCKET_NAME,
-                            ANDROID_SOCKET_NAMESPACE_RESERVED,
-                            SOCK_STREAM );
-
-                if (fd >= 0) {
-                    close(fd);
-                    snprintf( arg_device, sizeof(arg_device), "%s/%s",
-                                ANDROID_SOCKET_DIR, QEMUD_SOCKET_NAME );
-
-                    arg_overrides[1] = "-s";
-                    arg_overrides[2] = arg_device;
-                    done = 1;
-                    break;
-                }
-                LOGD("could not connect to %s socket: %s",
-                    QEMUD_SOCKET_NAME, strerror(errno));
-                if (--tries == 0)
-                    break;
-            }
-            if (!done) {
-                LOGE("could not connect to %s socket (giving up): %s",
-                    QEMUD_SOCKET_NAME, strerror(errno));
-                while(1)
-                    sleep(0x00ffffff);
-            }
-        }
-
-        /* otherwise, try to see if we passed a device name from the kernel */
-        if (!done) do {
-#define  KERNEL_OPTION  "android.ril="
-#define  DEV_PREFIX     "/dev/"
-
-            p = strstr( buffer, KERNEL_OPTION );
-            if (p == NULL)
-                break;
-
-            p += sizeof(KERNEL_OPTION)-1;
-            q  = strpbrk( p, " \t\n\r" );
-            if (q != NULL)
-                *q = 0;
-
-            snprintf( arg_device, sizeof(arg_device), DEV_PREFIX "%s", p );
-            arg_device[sizeof(arg_device)-1] = 0;
-            arg_overrides[1] = "-d";
-            arg_overrides[2] = arg_device;
-            done = 1;
-
-        } while (0);
-
-        if (done) {
-            argv = arg_overrides;
-            argc = 3;
-            i    = 1;
-            hasLibArgs = 1;
-            rilLibPath = REFERENCE_RIL_PATH;
-
-            LOGD("overriding with %s %s", arg_overrides[1], arg_overrides[2]);
-        }
-    }
-OpenLib:
-#endif
-    switchUser();
-
-    dlHandle = dlopen(rilLibPath, RTLD_NOW);
-
-    if (dlHandle == NULL) {
-        fprintf(stderr, "dlopen failed: %s\n", dlerror());
-        exit(-1);
-    }
-
-    RIL_startEventLoop();
-
-    rilInit = (const RIL_RadioFunctions *(*)(const struct RIL_Env *, int, char **))dlsym(dlHandle, "RIL_Init");
-
-    if (rilInit == NULL) {
-        fprintf(stderr, "RIL_Init not defined or exported in %s\n", rilLibPath);
-        exit(-1);
-    }
-
-    if (hasLibArgs) {
-        rilArgv = argv + i - 1;
-        argc = argc -i + 1;
-    } else {
-        static char * newArgv[MAX_LIB_ARGS];
-        static char args[PROPERTY_VALUE_MAX];
-        rilArgv = newArgv;
-        property_get(LIB_ARGS_PROPERTY, args, "");
-        argc = make_argv(args, rilArgv);
-    }
-
-    // Make sure there's a reasonable argv[0]
-    rilArgv[0] = argv[0];
-
-    funcs = rilInit(&s_rilEnv, argc, rilArgv);
-
-    RIL_register(funcs);
-
-done:
-
-    while(1) {
-        // sleep(UINT32_MAX) seems to return immediately on bionic
-        sleep(0x00ffffff);
-    }
-}
-