Changes for ril.h version 6.

- Changes to support LTE and EHRPD radio technology
- Support IPv6 in addition to IPv4 on the modems
- Detailed GPRS registration denied causes
- Access to multiple apps on UICC card
- Access to ISIM app on UICC
- Deprecate RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE as it can
  causes problems when several PDN contexts are active. Failure reason
  should be returned when setup_data_call returns
- Added RIL_RadioTechnology
- Added RIL_PreferredNetworkType
- Added RIL_CdmaSubscriptionSource
- Added RIL_LTE_SignalStrength
- Added AID to SIM requests as an optional parameter
- Add new error codes for returning disconnect reasons
- RIL_Data_Call_Response_v3/v5
    Added fields to support IPv6 and return status as it will
    now be returned as part of RIL_REQUEST_SETUP_DATA_CALL
- Rename RIL_REQUEST_REGISTRATION_STATE
      to RIL_REQUEST_VOICE_REGISTRATION_STATE
    response[3] return RIL_RadioTechnology for voice calls
    response[13] more error codes
- Rename RIL_REQUEST_GPRS_REGISTRATION_STATE
       to RIL_REQUEST_DATA_REGISTRATION_STATE
    Changed response[3] to be RIL_RadioTechnology for data calls
    Added response[4] error codes for registration being denied
    Added response[5] Max simultaneous data calls
- RIL_REQUEST_SETUP_DATA_CALL
    Changed data[0] to be RIL_RadioTechnology
    Response is now a RIL_Data_Call_Response_v5
- RIL_REQUEST_DATA_CALL_LIST
    Response is now a RIL_Data_Call_Response_v5
- RIL_UNSOL_DATA_CALL_LIST_CHANGED
    Response is now a RIL_Data_Call_Response_v5
- RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE
    Changed data[0] to be RIL_PreferredNetworkType
- RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE
    Changed response[0] to be RIL_PreferredNetworkType
- Rename RIL_REQUEST_SET_CDMA_SUBSCRIPTION
    to RIL_REQUEST_SET_CDMA_SUBSCRIPTION_SOURCE
- Added RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
- Added support for AID to RIL_UNSOL_SIM_REFRESH
- Added RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED
- Added RIL_UNSOL_PRL_CHANGED
- Added RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE
- Rename RIL_UNSOL_RESPONSE_NETWORK_CHANGED
     to RIL_UNSOL_RESPONSE_VOICE_NETWORK_CHANGED

Have refercence-ril and mock-ril use a private copy of
ril.h so the ril may evolve separately from them.

Change-Id: I1b952069f5406f5dc42480d019970d10f0120358
diff --git a/include/telephony/ril.h b/include/telephony/ril.h
index 7ede182..f06089b 100644
--- a/include/telephony/ril.h
+++ b/include/telephony/ril.h
@@ -14,20 +14,6 @@
  * 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
 
@@ -40,7 +26,7 @@
 extern "C" {
 #endif
 
-#define RIL_VERSION 5     /* Current version */
+#define RIL_VERSION 6     /* Current version */
 #define RIL_VERSION_MIN 2 /* Minimum RIL_VERSION supported */
 
 #define CDMA_ALPHA_INFO_BUFFER_LENGTH 64
@@ -116,6 +102,29 @@
     RADIO_TECH_HSPAP = 15 // HSPA+
 } RIL_RadioTechnology;
 
+// Do we want to split Data from Voice and the use
+// RIL_RadioTechnology for get/setPreferredVoice/Data ?
+typedef enum {
+    PREF_NET_TYPE_GSM_WCDMA                = 0, /* GSM/WCDMA (WCDMA preferred) */
+    PREF_NET_TYPE_GSM_ONLY                 = 1, /* GSM only */
+    PREF_NET_TYPE_WCDMA                    = 2, /* WCDMA  */
+    PREF_NET_TYPE_GSM_WCDMA_AUTO           = 3, /* GSM/WCDMA (auto mode, according to PRL) */
+    PREF_NET_TYPE_CDMA_EVDO_AUTO           = 4, /* CDMA and EvDo (auto mode, according to PRL) */
+    PREF_NET_TYPE_CDMA_ONLY                = 5, /* CDMA only */
+    PREF_NET_TYPE_EVDO_ONLY                = 6, /* EvDo only */
+    PREF_NET_TYPE_GSM_WCDMA_CDMA_EVDO_AUTO = 7, /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL) */
+    PREF_NET_TYPE_LTE_CDMA_EVDO            = 8, /* LTE, CDMA and EvDo */
+    PREF_NET_TYPE_LTE_GSM_WCDMA            = 9, /* LTE, GSM/WCDMA */
+    PREF_NET_TYPE_LTE_CMDA_EVDO_GSM_WCDMA  = 10, /* LTE, CDMA, EvDo, GSM/WCDMA */
+    PREF_NET_TYPE_LTE_ONLY                 = 11  /* LTE only */
+} RIL_PreferredNetworkType;
+
+/* Source for cdma subscription */
+typedef enum {
+   CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM = 0,
+   CDMA_SUBSCRIPTION_SOURCE_NV = 1
+} RIL_CdmaSubscriptionSource;
+
 /* User-to-User signaling Info activation types derived from 3GPP 23.087 v8.0 */
 typedef enum {
     RIL_UUS_TYPE1_IMPLICIT = 0,
@@ -174,16 +183,15 @@
     RIL_UUS_Info *  uusInfo;    /* NULL or Pointer to User-User Signaling Information */
 } RIL_Call;
 
-/* Deprecated, use RIL_Data_Call_Response_v5 */
+/* Deprecated, use RIL_Data_Call_Response_v6 */
 typedef struct {
     int             cid;        /* Context ID, uniquely identifies this call */
     int             active;     /* 0=inactive, 1=active/physical link down, 2=active/physical link up */
     char *          type;       /* One of the PDP_type values in TS 27.007 section 10.1.1.
                                    For example, "IP", "IPV6", "IPV4V6", or "PPP". */
     char *          apn;        /* ignored */
-    char *          address;    /* A space-delimited list of addresses, e.g., "192.0.1.3" or
-                                   "192.0.1.11 2001:db8::1". */
-} RIL_Data_Call_Response_v3;
+    char *          address;    /* An address, e.g., "192.0.1.3" or "2001:db8::1". */
+} RIL_Data_Call_Response_v4;
 
 /*
  * Returned by RIL_REQUEST_SETUP_DATA_CALL, RIL_REQUEST_DATA_CALL_LIST
@@ -198,14 +206,20 @@
                                    PDP_FAIL_ONLY_SINGLE_BEARER_ALLOWED this is the type supported
                                    such as "IP" or "IPV6" */
     char *          ifname;     /* The network interface name */
-    char *          addresses;  /* A space-delimited list of addresses,
-                                   e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1".
+    char *          addresses;  /* A space-delimited list of addresses with optional "/" prefix length,
+                                   e.g., "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64".
                                    May not be empty, typically 1 IPv4 or 1 IPv6 or
-                                   one of each. */
+                                   one of each. If the prefix length is absent the addresses
+                                   are assumed to be point to point with IPv4 having a prefix
+                                   length of 32 and IPv6 128. */
     char *          dnses;      /* A space-delimited list of DNS server addresses,
                                    e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1".
                                    May be empty. */
-} RIL_Data_Call_Response_v5;
+    char *          gateways;   /* A space-delimited list of default gateway addresses,
+                                   e.g., "192.0.1.3" or "192.0.1.11 2001:db8::1".
+                                   May be empty in which case the addresses represent point
+                                   to point connections. */
+} RIL_Data_Call_Response_v6;
 
 typedef struct {
     int messageRef;   /* TP-Message-Reference for GSM,
@@ -254,7 +268,22 @@
     int p3;
     char *data;     /* May be NULL*/
     char *pin2;     /* May be NULL*/
-} RIL_SIM_IO;
+} RIL_SIM_IO_v5;
+
+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"
+                       Path must always be provided.
+                     */
+    int p1;
+    int p2;
+    int p3;
+    char *data;     /* May be NULL*/
+    char *pin2;     /* May be NULL*/
+    char *aidPtr;   /* AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value. */
+} RIL_SIM_IO_v6;
 
 typedef struct {
     int sw1;
@@ -353,11 +382,11 @@
     PDP_FAIL_PROTOCOL_ERRORS   = 0x6F,             /* no retry */
 
     /* Not mentioned in the specification */
-    PDP_FAIL_REGISTRATION_FAIL = -1,
-    PDP_FAIL_GPRS_REGISTRATION_FAIL = -2,
+    PDP_FAIL_VOICE_REGISTRATION_FAIL = -1,
+    PDP_FAIL_DATA_REGISTRATION_FAIL = -2,
 
    /* reasons for data call drop - network/modem disconnect */
-    PDP_FAIL_SIGNAL_LOST = -3,            /* should  retry */
+    PDP_FAIL_SIGNAL_LOST = -3,            /* no retry */
     PDP_FAIL_PREF_RADIO_TECH_CHANGED = -4,/* preferred technology has changed, should retry
                                              with parameters appropriate for new technology */
     PDP_FAIL_RADIO_POWER_OFF = -5,        /* data call was disconnected because radio was resetting,
@@ -453,7 +482,8 @@
   RIL_APPTYPE_SIM     = 1,
   RIL_APPTYPE_USIM    = 2,
   RIL_APPTYPE_RUIM    = 3,
-  RIL_APPTYPE_CSIM    = 4
+  RIL_APPTYPE_CSIM    = 4,
+  RIL_APPTYPE_ISIM    = 5
 } RIL_AppType;
 
 typedef struct
@@ -465,37 +495,61 @@
   char             *aid_ptr;        /* null terminated string, e.g., from 0xA0, 0x00 -> 0x41,
                                        0x30, 0x30, 0x30 */
   char             *app_label_ptr;  /* null terminated string */
-  int              pin1_replaced;   /* applicable to USIM and CSIM */
+  int              pin1_replaced;   /* applicable to USIM, CSIM & ISIM */
   RIL_PinState     pin1;
   RIL_PinState     pin2;
 } RIL_AppStatus;
 
+/* Deprecated, use RIL_CardStatus_v6 */
+typedef struct
+{
+  RIL_CardState card_state;
+  RIL_PinState  universal_pin_state;             /* applicable to USIM and CSIM: RIL_PINSTATE_xxx */
+  int           gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */
+  int           cdma_subscription_app_index;     /* value < RIL_CARD_MAX_APPS, -1 if none */
+  int           num_applications;                /* value <= RIL_CARD_MAX_APPS */
+  RIL_AppStatus applications[RIL_CARD_MAX_APPS];
+} RIL_CardStatus_v5;
+
 typedef struct
 {
   RIL_CardState card_state;
   RIL_PinState  universal_pin_state;             /* applicable to USIM and CSIM: RIL_PINSTATE_xxx */
-  int           gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS */
-  int           cdma_subscription_app_index;     /* value < RIL_CARD_MAX_APPS */
+  int           gsm_umts_subscription_app_index; /* value < RIL_CARD_MAX_APPS, -1 if none */
+  int           cdma_subscription_app_index;     /* value < RIL_CARD_MAX_APPS, -1 if none */
+  int           ims_subscription_app_index;      /* value < RIL_CARD_MAX_APPS, -1 if none */
   int           num_applications;                /* value <= RIL_CARD_MAX_APPS */
   RIL_AppStatus applications[RIL_CARD_MAX_APPS];
-} RIL_CardStatus;
+} RIL_CardStatus_v6;
 
 /* 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 initialized.  All files should be re-read. data[1] contains AID that caused REFRESH */
     SIM_INIT = 1,
     /* SIM reset.  SIM power required, SIM may be locked and all files should be re-read. */
     SIM_RESET = 2
 } RIL_SimRefreshResult;
 
+/* Deprecated, use RIL_CDMA_CallWaiting_v6 */
+typedef struct {
+    char *          number;             /* Remote party number */
+    int             numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown */
+    char *          name;               /* Remote party name */
+    RIL_CDMA_SignalInfoRecord signalInfoRecord;
+} RIL_CDMA_CallWaiting_v5;
+
 typedef struct {
     char *          number;             /* Remote party number */
     int             numberPresentation; /* 0=Allowed, 1=Restricted, 2=Not Specified/Unknown */
     char *          name;               /* Remote party name */
     RIL_CDMA_SignalInfoRecord signalInfoRecord;
-} RIL_CDMA_CallWaiting;
+    /* Number type/Number plan required to support International Call Waiting */
+    int             number_type;        /* 0=Unknown, 1=International, 2=National,
+                                           3=Network specific, 4=subscriber */
+    int             number_plan;        /* 0=Unknown, 1=ISDN, 3=Data, 4=Telex, 8=Nat'l, 9=Private */
+} RIL_CDMA_CallWaiting_v6;
 
 /**
  * Which types of Cell Broadcast Message (CBM) are to be received by the ME
@@ -581,12 +635,29 @@
     int signalNoiseRatio; /* Valid values are 0-8.  8 is the highest signal to noise ratio. */
 } RIL_EVDO_SignalStrength;
 
+typedef struct {
+    int signalStrength;  /* Valid values are (0-31, 99) as defined in TS 27.007 8.5 */
+    int rsrp;            /* The current Reference Signal Receive Power in dBm
+                          * multipled by -1. Range: 44 to 140 dBm, TODO: doc reference */
+    int rsrq;            /* The current Reference Signal Receive Quality in dB
+                          * multiplied by -1. Range: 20 to 3 dB. TODO: doc reference */
+    int rssnr;           /* TODO: Need documentation and doc reference */
+    int cqi;             /* TODO: Need documentation and doc reference */
+} RIL_LTE_SignalStrength;
+
+/* Deprecated, use RIL_SignalStrength_v6 */
+typedef struct {
+    RIL_GW_SignalStrength   GW_SignalStrength;
+    RIL_CDMA_SignalStrength CDMA_SignalStrength;
+    RIL_EVDO_SignalStrength EVDO_SignalStrength;
+} RIL_SignalStrength_v5;
 
 typedef struct {
     RIL_GW_SignalStrength   GW_SignalStrength;
     RIL_CDMA_SignalStrength CDMA_SignalStrength;
     RIL_EVDO_SignalStrength EVDO_SignalStrength;
-} RIL_SignalStrength;
+    RIL_LTE_SignalStrength  LTE_SignalStrength;
+} RIL_SignalStrength_v6;
 
 /* Names of the CDMA info records (C.S0005 section 3.7.5) */
 typedef enum {
@@ -709,7 +780,7 @@
  *
  * "data" is NULL
  *
- * "response" is const RIL_CardStatus *
+ * "response" is const RIL_CardStatus_v5 *
  *
  * Valid errors:
  *  Must never fail
@@ -723,6 +794,7 @@
  *
  * "data" is const char **
  * ((const char **)data)[0] is PIN value
+ * ((const char **)data)[1] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -746,6 +818,7 @@
  * "data" is const char **
  * ((const char **)data)[0] is PUK value
  * ((const char **)data)[1] is new PIN value
+ * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -769,6 +842,7 @@
  *
  * "data" is const char **
  * ((const char **)data)[0] is PIN2 value
+ * ((const char **)data)[1] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -791,6 +865,7 @@
  * "data" is const char **
  * ((const char **)data)[0] is PUK2 value
  * ((const char **)data)[1] is new PIN2 value
+ * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -814,6 +889,7 @@
  * "data" is const char **
  * ((const char **)data)[0] is old PIN value
  * ((const char **)data)[1] is new PIN value
+ * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -839,6 +915,7 @@
  * "data" is const char **
  * ((const char **)data)[0] is old PIN2 value
  * ((const char **)data)[1] is new PIN2 value
+ * ((const char **)data)[2] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -921,7 +998,8 @@
  *
  * Only valid when radio state is "RADIO_STATE_SIM_READY"
  *
- * "data" is NULL
+ * "data" is const char **
+ * ((const char **)data)[0] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  * "response" is a const char * containing the IMSI
  *
  * Valid errors:
@@ -1098,7 +1176,7 @@
 #define RIL_REQUEST_SIGNAL_STRENGTH 19
 
 /**
- * RIL_REQUEST_REGISTRATION_STATE
+ * RIL_REQUEST_VOICE_REGISTRATION_STATE
  *
  * Request current registration state
  *
@@ -1182,6 +1260,29 @@
  *                                 8 - No Suitable Cells in this Location Area
  *                                 9 - Network failure
  *                                10 - Persistent location update reject
+ *                                11 - PLMN not allowed
+ *                                12 - Location area not allowed
+ *                                13 - Roaming not allowed in this Location Area
+ *                                15 - No Suitable Cells in this Location Area
+ *                                17 - Network Failure
+ *                                20 - MAC Failure
+ *                                21 - Sync Failure
+ *                                22 - Congestion
+ *                                23 - GSM Authentication unacceptable
+ *                                25 - Not Authorized for this CSG
+ *                                32 - Service option not supported
+ *                                33 - Requested service option not subscribed
+ *                                34 - Service option temporarily out of order
+ *                                38 - Call cannot be identified
+ *                                48-63 - Retry upon entry into a new cell
+ *                                95 - Semantically incorrect message
+ *                                96 - Invalid mandatory information
+ *                                97 - Message type non-existent or not implemented
+ *                                98 - Message not compatible with protocol state
+ *                                99 - Information element non-existent or not implemented
+ *                               100 - Conditional IE error
+ *                               101 - Message not compatible with protocol state
+ *                               111 - Protocol error, unspecified
  * ((const char **)response)[14] is the Primary Scrambling Code of the current
  *                               cell as described in TS 25.331, in hexadecimal
  *                               format, or NULL if unknown or not registered
@@ -1199,12 +1300,12 @@
  *  RADIO_NOT_AVAILABLE
  *  GENERIC_FAILURE
  */
-#define RIL_REQUEST_REGISTRATION_STATE 20
+#define RIL_REQUEST_VOICE_REGISTRATION_STATE 20
 
 /**
- * RIL_REQUEST_GPRS_REGISTRATION_STATE
+ * RIL_REQUEST_DATA_REGISTRATION_STATE
  *
- * Request current GPRS registration state
+ * Request current DATA registration state
  *
  * "data" is NULL
  * "response" is a "char **"
@@ -1213,6 +1314,19 @@
  * ((const char **)response)[2] is CID if registered or NULL if not
  * ((const char **)response)[3] indicates the available data radio technology,
  *                              valid values as defined by RIL_RadioTechnology.
+ * ((const char **)response)[4] if registration state is 3 (Registration
+ *                               denied) this is an enumerated reason why
+ *                               registration was denied.  See 3GPP TS 24.008,
+ *                               Annex G.6 "Additonal cause codes for GMM".
+ *      7 == GPRS services not allowed
+ *      8 == GPRS services and non-GPRS services not allowed
+ *      9 == MS identity cannot be derived by the network
+ *      10 == Implicitly detached
+ *      14 == GPRS services not allowed in this PLMN
+ *      16 == MSC temporarily not reachable
+ *      40 == No PDP context activated
+ * ((const char **)response)[5] The maximum number of simultaneous Data Calls that can be
+ *                              established using RIL_REQUEST_SETUP_DATA_CALL.
  *
  * LAC and CID are in hexadecimal format.
  * valid LAC are 0x0000 - 0xffff
@@ -1226,7 +1340,7 @@
  *  RADIO_NOT_AVAILABLE
  *  GENERIC_FAILURE
  */
-#define RIL_REQUEST_GPRS_REGISTRATION_STATE 21
+#define RIL_REQUEST_DATA_REGISTRATION_STATE 21
 
 /**
  * RIL_REQUEST_OPERATOR
@@ -1368,12 +1482,12 @@
  *    is capable of sending and receiving packets. The prefix length
  *    of the addresses must be /32 for IPv4 and /128 for IPv6.
  *  - Must NOT change the linux routing table.
- *  - Support up to RIL_REQUEST_GPRS_REGISTRATION_STATE response[5]
+ *  - Support up to RIL_REQUEST_DATA_REGISTRATION_STATE response[5]
  *    number of simultaneous data call contexts.
  *
  * "data" is a const char **
- * ((const char **)data)[0] indicates whether to setup connection on radio technology CDMA
- *                              or GSM/UMTS, 0-1. 0 - CDMA, 1-GSM/UMTS
+ * ((const char **)data)[0] Radio technology to use: 0-CDMA, 1-GSM/UMTS, 2...
+ *                          for values above 2 this is RIL_RadioTechnology + 2.
  * ((const char **)data)[1] is a RIL_DataProfile (support is optional)
  * ((const char **)data)[2] is the APN to connect to if radio technology is GSM/UMTS. This APN will
  *                          override the one in the profile. NULL indicates no APN overrride.
@@ -1384,18 +1498,19 @@
  *                          1 => PAP may be performed; CHAP is never performed.
  *                          2 => CHAP may be performed; PAP is never performed.
  *                          3 => PAP / CHAP may be performed - baseband dependent.
- * ((const char **)data)[6] is the PDP type to request if the radio technology is GSM/UMTS.
- *                          Must be one of the PDP_type values in TS 27.007 section 10.1.1.
+ * ((const char **)data)[6] is the connection type to request must be one of the
+ *                          PDP_type values in TS 27.007 section 10.1.1.
  *                          For example, "IP", "IPV6", "IPV4V6", or "PPP".
+ * ((const char **)data)[7] Optional connection property parameters, format to be defined.
  *
- * "response" is a RIL_Data_Call_Response_v5
+ * "response" is a RIL_Data_Call_Response_v6
  *
  * FIXME may need way to configure QoS settings
  *
  * Valid errors:
  *  SUCCESS should be returned on both success and failure of setup with
- *  the RIL_Data_Call_Response_v5.status containing the actual status.
- *  For all other errors the RIL_Data_Call_Resonse_v5 is ignored.
+ *  the RIL_Data_Call_Response_v6.status containing the actual status.
+ *  For all other errors the RIL_Data_Call_Resonse_v6 is ignored.
  *
  *  Other errors could include:
  *    RADIO_NOT_AVAILABLE, GENERIC_FAILURE, OP_NOT_ALLOWED_BEFORE_REG_TO_NW,
@@ -1414,7 +1529,7 @@
  * where it assumes all of the EF selection will be done by the
  * callee.
  *
- * "data" is a const RIL_SIM_IO *
+ * "data" is a const RIL_SIM_IO_v5 *
  * 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)
@@ -1713,6 +1828,7 @@
  * ((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
+ * ((const char **)data)[3] is AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is an int *
  * ((const int *)response) 0 is the TS 27.007 service class bit vector of
@@ -1742,6 +1858,7 @@
  * ((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"
+ * ((const char **)data)[4] = AID value, See ETSI 102.221 8.1 and 101.220 4, NULL if no value.
  *
  * "response" is int *
  * ((int *)response)[0] is the number of retries remaining, or -1 if unknown
@@ -2018,7 +2135,8 @@
 #define RIL_REQUEST_QUERY_CLIP 55
 
 /**
- * RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE
+ * RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE - Deprecated use the status
+ * field in RIL_Data_Call_Response_v6.
  *
  * Requests the failure cause code for the most recently failed PDP
  * context or CDMA data connection active
@@ -2042,7 +2160,8 @@
  *  GENERIC_FAILURE
  *
  * See also: RIL_REQUEST_LAST_CALL_FAIL_CAUSE
- * TODO: Deprecate when v5 is completed.
+ *
+ * Deprecated use the status field in RIL_Data_Call_Response_v6.
  */
 
 #define RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE 56
@@ -2056,7 +2175,7 @@
  * replaces RIL_REQUEST_PDP_CONTEXT_LIST
  *
  * "data" is NULL
- * "response" is an array of RIL_Data_Call_Response_v5
+ * "response" is an array of RIL_Data_Call_Response_v6
  *
  * Valid errors:
  *  SUCCESS
@@ -2412,16 +2531,7 @@
  * 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 GSM/WCDMA (WCDMA preferred)
- * ((int *)data)[0] is == 1 for GSM only
- * ((int *)data)[0] is == 2 for WCDMA only
- * ((int *)data)[0] is == 3 for GSM/WCDMA (auto mode, according to PRL)
- * ((int *)data)[0] is == 4 for CDMA and EvDo (auto mode, according to PRL)
- * ((int *)data)[0] is == 5 for CDMA only
- * ((int *)data)[0] is == 6 for EvDo only
- * ((int *)data)[0] is == 7 for GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL)
+ * "data" is int * which is RIL_PreferredNetworkType
  *
  * "response" is NULL
  *
@@ -2442,14 +2552,7 @@
  * "data" is NULL
  *
  * "response" is int *
- * ((int *)response)[0] is == 0 for GSM/WCDMA (WCDMA preferred)
- * ((int *)response)[0] is == 1 for GSM only
- * ((int *)response)[0] is == 2 for WCDMA only
- * ((int *)response)[0] is == 3 for GSM/WCDMA (auto mode, according to PRL)
- * ((int *)response)[0] is == 4 for CDMA and EvDo (auto mode, according to PRL)
- * ((int *)response)[0] is == 5 for CDMA only
- * ((int *)response)[0] is == 6 for EvDo only
- * ((int *)response)[0] is == 7 for GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL)
+ * ((int *)reponse)[0] is == RIL_PreferredNetworkType
  *
  * Valid errors:
  *  SUCCESS
@@ -2501,14 +2604,13 @@
 #define RIL_REQUEST_SET_LOCATION_UPDATES 76
 
 /**
- * RIL_REQUEST_CDMA_SET_SUBSCRIPTION
+ * RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE
  *
  * Request to set the location where the CDMA subscription shall
  * be retrieved
  *
  * "data" is int *
- * ((int *)data)[0] is == 0 from RUIM/SIM (default)
- * ((int *)data)[0] is == 1 from NV
+ * ((int *)data)[0] is == RIL_CdmaSubscriptionSource
  *
  * "response" is NULL
  *
@@ -2518,8 +2620,10 @@
  *  GENERIC_FAILURE
  *  SIM_ABSENT
  *  SUBSCRIPTION_NOT_AVAILABLE
+ *
+ * See also: RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE
  */
-#define RIL_REQUEST_CDMA_SET_SUBSCRIPTION 77
+#define RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE 77
 
 /**
  * RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE
@@ -3041,6 +3145,27 @@
  */
 #define RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING 103
 
+/**
+ * RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE
+ *
+ * Request to query the location where the CDMA subscription shall
+ * be retrieved
+ *
+ * "data" is NULL
+ *
+ * "response" is int *
+ * ((int *)data)[0] is == RIL_CdmaSubscriptionSource
+ *
+ * Valid errors:
+ *  SUCCESS
+ *  RADIO_NOT_AVAILABLE
+ *  GENERIC_FAILURE
+ *  SUBSCRIPTION_NOT_AVAILABLE
+ *
+ * See also: RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE
+ */
+#define RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE 104
+
 /***********************************************************************/
 
 
@@ -3078,15 +3203,13 @@
 
 
 /**
- * RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED
+ * RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED
  *
- * Called when network state, operator name, or GPRS state has changed
- * Basically on, +CREG and +CGREG
+ * Called when the voice network state changed
  *
  * Callee will invoke the following requests on main thread:
  *
- * RIL_REQUEST_REGISTRATION_STATE
- * RIL_REQUEST_GPRS_REGISTRATION_STATE
+ * RIL_REQUEST_VOICE_REGISTRATION_STATE
  * RIL_REQUEST_OPERATOR
  *
  * "data" is NULL
@@ -3094,7 +3217,7 @@
  * FIXME should this happen when SIM records are loaded? (eg, for
  * EONS)
  */
-#define RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED 1002
+#define RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 1002
 
 /**
  * RIL_UNSOL_RESPONSE_NEW_SMS
@@ -3207,7 +3330,7 @@
  * has been activated or deactivated
  * replaces RIL_UNSOL_PDP_CONTEXT_LIST_CHANGED
  *
- * "data" is an array of RIL_Data_Call_Response_v5 identical to that
+ * "data" is an array of RIL_Data_Call_Response_v6 identical to that
  * returned by RIL_REQUEST_DATA_CALL_LIST
  *
  * See also: RIL_REQUEST_DATA_CALL_LIST
@@ -3292,7 +3415,8 @@
  * "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.
+ * SIM_FILE_UPDATE, AID(application ID) of the card application
+ * triggering the REFRESH if the result is SIM_INIT, 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
@@ -3461,6 +3585,40 @@
  * "data" is null
  */
 #define RIL_UNSOL_RESEND_INCALL_MUTE 1030
+
+/**
+ * RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED
+ *
+ * Called when CDMA subscription source changed.
+ *
+ * "data" is int *
+ * ((int *)data)[0] is == RIL_CdmaSubscriptionSource
+ */
+#define RIL_UNSOL_CDMA_SUBSCRIPTION_CHANGED 1031
+
+/**
+ * RIL_UNSOL_CDMA_PRL_CHANGED
+ *
+ * Called when PRL (preferred roaming list) changes.
+ *
+ * "data" is int *
+ * ((int *)data)[0] is PRL_VERSION as would be returned by RIL_REQUEST_CDMA_SUBSCRIPTION
+ */
+#define RIL_UNSOL_CDMA_PRL_CHANGED 1032
+
+/**
+ * RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE
+ *
+ * Called when Emergency Callback Mode Ends
+ *
+ * Indicates that the radio system selection module has
+ * proactively exited emergency callback mode.
+ *
+ * "data" is NULL
+ *
+ */
+#define RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE 1033
+
 /***********************************************************************/
 
 
diff --git a/libril/ril.cpp b/libril/ril.cpp
index 714ffa7..25f09ca 100644
--- a/libril/ril.cpp
+++ b/libril/ril.cpp
@@ -669,11 +669,17 @@
  *   int32_t p1, p2, p3
  *   String data
  *   String pin2
+ *   String aidPtr
  */
 static void
 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
-    RIL_SIM_IO simIO;
+    union RIL_SIM_IO {
+        RIL_SIM_IO_v6 v6;
+        RIL_SIM_IO_v5 v5;
+    } simIO;
+
     int32_t t;
+    int size;
     status_t status;
 
     memset (&simIO, 0, sizeof(simIO));
@@ -681,30 +687,31 @@
     // note we only check status at the end
 
     status = p.readInt32(&t);
-    simIO.command = (int)t;
+    simIO.v6.command = (int)t;
 
     status = p.readInt32(&t);
-    simIO.fileid = (int)t;
+    simIO.v6.fileid = (int)t;
 
-    simIO.path = strdupReadString(p);
+    simIO.v6.path = strdupReadString(p);
 
     status = p.readInt32(&t);
-    simIO.p1 = (int)t;
+    simIO.v6.p1 = (int)t;
 
     status = p.readInt32(&t);
-    simIO.p2 = (int)t;
+    simIO.v6.p2 = (int)t;
 
     status = p.readInt32(&t);
-    simIO.p3 = (int)t;
+    simIO.v6.p3 = (int)t;
 
-    simIO.data = strdupReadString(p);
-    simIO.pin2 = strdupReadString(p);
+    simIO.v6.data = strdupReadString(p);
+    simIO.v6.pin2 = strdupReadString(p);
+    simIO.v6.aidPtr = 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);
+    appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
+        simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
+        simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
+        (char*)simIO.v6.data,  (char*)simIO.v6.pin2, simIO.v6.aidPtr);
     closeRequest;
     printRequest(pRI->token, pRI->pCI->requestNumber);
 
@@ -712,17 +719,20 @@
         goto invalid;
     }
 
-       s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, sizeof(simIO), pRI);
+    size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
+    s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
 
 #ifdef MEMSET_FREED
-    memsetString (simIO.path);
-    memsetString (simIO.data);
-    memsetString (simIO.pin2);
+    memsetString (simIO.v6.path);
+    memsetString (simIO.v6.data);
+    memsetString (simIO.v6.pin2);
+    memsetString (simIO.v6.aidPtr);
 #endif
 
-    free (simIO.path);
-    free (simIO.data);
-    free (simIO.pin2);
+    free (simIO.v6.path);
+    free (simIO.v6.data);
+    free (simIO.v6.pin2);
+    free (simIO.v6.aidPtr);
 
 #ifdef MEMSET_FREED
     memset(&simIO, 0, sizeof(simIO));
@@ -1473,36 +1483,35 @@
     return 0;
 }
 
-static int responseDataCallListV3(Parcel &p, void *response, size_t responselen)
+static int responseDataCallListV4(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_Data_Call_Response_v3) != 0) {
+    if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
         LOGE("invalid response length %d expected multiple of %d",
-                (int)responselen, (int)sizeof(RIL_Data_Call_Response_v3));
+                (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
         return RIL_ERRNO_INVALID_RESPONSE;
     }
 
-    int num = responselen / sizeof(RIL_Data_Call_Response_v3);
+    int num = responselen / sizeof(RIL_Data_Call_Response_v4);
     p.writeInt32(num);
 
-    RIL_Data_Call_Response_v3 *p_cur = (RIL_Data_Call_Response_v3 *) response;
+    RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) 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);
+        // apn is not used, so don't send.
         writeStringToParcel(p, p_cur[i].address);
-        appendPrintBuf("%s[cid=%d,%s,%s,%s,%s],", printBuf,
+        appendPrintBuf("%s[cid=%d,%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;
@@ -1517,23 +1526,23 @@
     p.writeInt32(s_callbacks.version);
 
     if (s_callbacks.version < 5) {
-        return responseDataCallListV3(p, response, responselen);
+        return responseDataCallListV4(p, response, responselen);
     } else {
         if (response == NULL && responselen != 0) {
             LOGE("invalid response: NULL");
             return RIL_ERRNO_INVALID_RESPONSE;
         }
 
-        if (responselen % sizeof(RIL_Data_Call_Response_v5) != 0) {
+        if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
             LOGE("invalid response length %d expected multiple of %d",
-                    (int)responselen, (int)sizeof(RIL_Data_Call_Response_v5));
+                    (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
             return RIL_ERRNO_INVALID_RESPONSE;
         }
 
-        int num = responselen / sizeof(RIL_Data_Call_Response_v5);
+        int num = responselen / sizeof(RIL_Data_Call_Response_v6);
         p.writeInt32(num);
 
-        RIL_Data_Call_Response_v5 *p_cur = (RIL_Data_Call_Response_v5 *) response;
+        RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
         startResponse;
         int i;
         for (i = 0; i < num; i++) {
@@ -1544,13 +1553,15 @@
             writeStringToParcel(p, p_cur[i].ifname);
             writeStringToParcel(p, p_cur[i].addresses);
             writeStringToParcel(p, p_cur[i].dnses);
+            writeStringToParcel(p, p_cur[i].gateways);
             appendPrintBuf("%s[status=%d,cid=%d,%s,%d,%s,%s,%s],", printBuf,
                 p_cur[i].status,
                 p_cur[i].cid,
                 (p_cur[i].active==0)?"down":"up",
                 (char*)p_cur[i].ifname,
                 (char*)p_cur[i].addresses,
-                (char*)p_cur[i].dnses);
+                (char*)p_cur[i].dnses,
+                (char*)p_cur[i].gateways);
         }
         removeLastChar;
         closeResponse;
@@ -1890,9 +1901,8 @@
         return RIL_ERRNO_INVALID_RESPONSE;
     }
 
-    if (responselen == sizeof (RIL_SignalStrength)) {
-        // New RIL
-        RIL_SignalStrength *p_cur = ((RIL_SignalStrength *) response);
+    if (responselen >= sizeof (RIL_SignalStrength_v5)) {
+        RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
 
         p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
         p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
@@ -1901,12 +1911,23 @@
         p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
         p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
         p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
+        if (responselen >= sizeof (RIL_SignalStrength_v6)) {
+            p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
+            p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
+            p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
+            p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
+            p.writeInt32(p_cur->LTE_SignalStrength.cqi);
+        } else {
+            memset(&p_cur->LTE_SignalStrength, sizeof (RIL_LTE_SignalStrength), 0);
+        }
 
         startResponse;
         appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
-                CDMA_SignalStrength.dbm=%d,CDMA_SignalStrength.ecio=%d,\
-                EVDO_SignalStrength.dbm =%d,EVDO_SignalStrength.ecio=%d,\
-                EVDO_SignalStrength.signalNoiseRatio=%d]",
+                CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
+                EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
+                EVDO_SS.signalNoiseRatio=%d,\
+                LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
+                LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
                 printBuf,
                 p_cur->GW_SignalStrength.signalStrength,
                 p_cur->GW_SignalStrength.bitErrorRate,
@@ -1914,34 +1935,14 @@
                 p_cur->CDMA_SignalStrength.ecio,
                 p_cur->EVDO_SignalStrength.dbm,
                 p_cur->EVDO_SignalStrength.ecio,
-                p_cur->EVDO_SignalStrength.signalNoiseRatio);
-
+                p_cur->EVDO_SignalStrength.signalNoiseRatio,
+                p_cur->LTE_SignalStrength.signalStrength,
+                p_cur->LTE_SignalStrength.rsrp,
+                p_cur->LTE_SignalStrength.rsrq,
+                p_cur->LTE_SignalStrength.rssnr,
+                p_cur->LTE_SignalStrength.cqi);
         closeResponse;
 
-    } else if (responselen % sizeof (int) == 0) {
-        // Old RIL deprecated
-        int *p_cur = (int *) response;
-
-        startResponse;
-
-        // With the Old RIL we see one or 2 integers.
-        size_t num = responselen / sizeof (int); // Number of integers from ril
-        size_t totalIntegers = 7; // Number of integers in RIL_SignalStrength
-        size_t i;
-
-        appendPrintBuf("%s[", printBuf);
-        for (i = 0; i < num; i++) {
-            appendPrintBuf("%s %d", printBuf, *p_cur);
-            p.writeInt32(*p_cur++);
-        }
-        appendPrintBuf("%s]", printBuf);
-
-        // Fill the remainder with zero's.
-        for (; i < totalIntegers; i++) {
-            p.writeInt32(0);
-        }
-
-        closeResponse;
     } else {
         LOGE("invalid response length");
         return RIL_ERRNO_INVALID_RESPONSE;
@@ -1994,23 +1995,29 @@
         return RIL_ERRNO_INVALID_RESPONSE;
     }
 
-    if (responselen != sizeof(RIL_CDMA_CallWaiting)) {
-        LOGE("invalid response length %d expected %d\n",
-            (int)responselen, (int)sizeof(RIL_CDMA_CallWaiting));
-        return RIL_ERRNO_INVALID_RESPONSE;
+    if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
+        LOGW("Upgrade to ril version %d\n", RIL_VERSION);
+    }
+
+    RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
+
+    writeStringToParcel(p, p_cur->number);
+    p.writeInt32(p_cur->numberPresentation);
+    writeStringToParcel(p, p_cur->name);
+    marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
+
+    if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
+        p.writeInt32(p_cur->number_type);
+        p.writeInt32(p_cur->number_plan);
+    } else {
+        p.writeInt32(0);
+        p.writeInt32(0);
     }
 
     startResponse;
-    RIL_CDMA_CallWaiting *p_cur = ((RIL_CDMA_CallWaiting *) response);
-
-    writeStringToParcel (p, p_cur->number);
-    p.writeInt32(p_cur->numberPresentation);
-    writeStringToParcel (p, p_cur->name);
-    marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
-
     appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
             signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
-            signal=%d]",
+            signal=%d,number_type=%d,number_plan=%d]",
             printBuf,
             p_cur->number,
             p_cur->numberPresentation,
@@ -2018,8 +2025,9 @@
             p_cur->signalInfoRecord.isPresent,
             p_cur->signalInfoRecord.signalType,
             p_cur->signalInfoRecord.alertPitch,
-            p_cur->signalInfoRecord.signal);
-
+            p_cur->signalInfoRecord.signal,
+            p_cur->number_type,
+            p_cur->number_plan);
     closeResponse;
 
     return 0;
@@ -2049,18 +2057,25 @@
         return RIL_ERRNO_INVALID_RESPONSE;
     }
 
-    if (responselen % sizeof (RIL_CardStatus *) != 0) {
-        LOGE("invalid response length %d expected multiple of %d\n",
-            (int)responselen, (int)sizeof (RIL_CardStatus *));
+    if (responselen != sizeof (RIL_CardStatus_v6 *)) {
+        LOGE("responseSimStatus: Expecting pointer\n");
         return RIL_ERRNO_INVALID_RESPONSE;
     }
 
-    RIL_CardStatus *p_cur = ((RIL_CardStatus *) response);
+    RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
 
     p.writeInt32(p_cur->card_state);
     p.writeInt32(p_cur->universal_pin_state);
     p.writeInt32(p_cur->gsm_umts_subscription_app_index);
     p.writeInt32(p_cur->cdma_subscription_app_index);
+
+    if (s_callbacks.version == 6) {
+        p.writeInt32(p_cur->ims_subscription_app_index);
+    } else {
+        p.writeInt32(-1);
+    }
+   
+    p.writeInt32(p_cur->cdma_subscription_app_index);
     p.writeInt32(p_cur->num_applications);
 
     startResponse;
@@ -2460,8 +2475,8 @@
             s_fdCommand = -1;
             break;
         case 2:
-            LOGI ("Debug port: issuing unsolicited network change.");
-            RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED,
+            LOGI ("Debug port: issuing unsolicited voice network change.");
+            RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
                                       NULL, 0);
             break;
         case 3:
@@ -3081,8 +3096,8 @@
         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_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
+        case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
         case RIL_REQUEST_OPERATOR: return "OPERATOR";
         case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
         case RIL_REQUEST_DTMF: return "DTMF";
@@ -3135,7 +3150,7 @@
         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_REQUEST_CDMA_SET_SUBSCRIPTION:return"CDMA_SET_SUBSCRIPTION";
+        case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
         case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
         case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
         case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
@@ -3161,9 +3176,10 @@
         case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
         case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
         case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
+        case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
         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_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_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";
@@ -3191,6 +3207,9 @@
         case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
         case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
         case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
+        case RIL_UNSOL_CDMA_SUBSCRIPTION_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_CHANGED";
+        case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
+        case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
         default: return "<unknown request>";
     }
 }
diff --git a/libril/ril_commands.h b/libril/ril_commands.h
index a8fb8de..fbd2a69 100644
--- a/libril/ril_commands.h
+++ b/libril/ril_commands.h
@@ -34,8 +34,8 @@
     {RIL_REQUEST_UDUB, dispatchVoid, responseVoid},
     {RIL_REQUEST_LAST_CALL_FAIL_CAUSE, dispatchVoid, responseInts},
     {RIL_REQUEST_SIGNAL_STRENGTH, dispatchVoid, responseRilSignalStrength},
-    {RIL_REQUEST_REGISTRATION_STATE, dispatchVoid, responseStrings},
-    {RIL_REQUEST_GPRS_REGISTRATION_STATE, dispatchVoid, responseStrings},
+    {RIL_REQUEST_VOICE_REGISTRATION_STATE, dispatchVoid, responseStrings},
+    {RIL_REQUEST_DATA_REGISTRATION_STATE, dispatchVoid, responseStrings},
     {RIL_REQUEST_OPERATOR, dispatchVoid, responseStrings},
     {RIL_REQUEST_RADIO_POWER, dispatchInts, responseVoid},
     {RIL_REQUEST_DTMF, dispatchString, responseVoid},
@@ -91,7 +91,7 @@
     {RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, dispatchVoid, responseInts},
     {RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, dispatchVoid, responseCellList},
     {RIL_REQUEST_SET_LOCATION_UPDATES, dispatchInts, responseVoid},
-    {RIL_REQUEST_CDMA_SET_SUBSCRIPTION, dispatchInts, responseVoid},
+    {RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, dispatchInts, responseVoid},
     {RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, dispatchInts, responseVoid},
     {RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, dispatchVoid, responseInts},
     {RIL_REQUEST_SET_TTY_MODE, dispatchInts, responseVoid},
@@ -117,4 +117,5 @@
     {RIL_REQUEST_GET_SMSC_ADDRESS, dispatchVoid, responseString},
     {RIL_REQUEST_SET_SMSC_ADDRESS, dispatchString, responseVoid},
     {RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, dispatchInts, responseVoid},
-    {RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, dispatchVoid, responseVoid}
+    {RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, dispatchVoid, responseVoid},
+    {RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, dispatchVoid, responseInts}
diff --git a/libril/ril_unsol_commands.h b/libril/ril_unsol_commands.h
index 6eddd0f..4e5eac7 100644
--- a/libril/ril_unsol_commands.h
+++ b/libril/ril_unsol_commands.h
@@ -16,7 +16,7 @@
 */
     {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_VOICE_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},
@@ -44,4 +44,8 @@
     {RIL_UNSOL_CDMA_INFO_REC, responseCdmaInformationRecords, WAKE_PARTIAL},
     {RIL_UNSOL_OEM_HOOK_RAW, responseRaw, WAKE_PARTIAL},
     {RIL_UNSOL_RINGBACK_TONE, responseInts, WAKE_PARTIAL},
-    {RIL_UNSOL_RESEND_INCALL_MUTE, responseVoid, WAKE_PARTIAL}
+    {RIL_UNSOL_RESEND_INCALL_MUTE, responseVoid, WAKE_PARTIAL},
+    {RIL_UNSOL_CDMA_SUBSCRIPTION_CHANGED, responseInts, WAKE_PARTIAL},
+    {RIL_UNSOL_CDMA_PRL_CHANGED, responseInts, WAKE_PARTIAL},
+    {RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE, responseVoid, WAKE_PARTIAL}
+