ril-caf: Allow using RIL version 10

 * RIL version 11 adds a field that must be supported by the modem and
   is not compatible with RIL version 10. Add a flag to support v10.
 * Define USE_RIL_VERSION_10 to enable this.

Change-Id: I2d2dcbc149a46f9a56b5c852d5dbc9296b214180
diff --git a/include/telephony/ril.h b/include/telephony/ril.h
index 72190e3..99d932c 100644
--- a/include/telephony/ril.h
+++ b/include/telephony/ril.h
@@ -50,7 +50,11 @@
 #define SIM_COUNT 1
 #endif
 
+#ifdef USE_RIL_VERSION_10
+#define RIL_VERSION 10
+#else
 #define RIL_VERSION 11     /* Current version */
+#endif
 #define RIL_VERSION_MIN 6 /* Minimum RIL_VERSION supported */
 
 #define CDMA_ALPHA_INFO_BUFFER_LENGTH 64
@@ -386,6 +390,7 @@
                                  via PCO(Protocol Configuration Option) for IMS client. */
 } RIL_Data_Call_Response_v9;
 
+#if (RIL_VERSION == 11)
 typedef struct {
     int             status;     /* A RIL_DataCallFailCause, 0 which is PDP_FAIL_NONE if no error */
     int             suggestedRetryTime; /* If status != 0, this fields indicates the suggested retry
@@ -421,6 +426,7 @@
                                    Value <= 0 means network has either not sent a value or
                                    sent an invalid value */
 } RIL_Data_Call_Response_v11;
+#endif
 
 typedef enum {
     RADIO_TECH_3GPP = 1, /* 3GPP Technologies - GSM, WCDMA */
diff --git a/libril/ril.cpp b/libril/ril.cpp
index cc39525..d87efb7 100755
--- a/libril/ril.cpp
+++ b/libril/ril.cpp
@@ -2419,6 +2419,7 @@
     return 0;
 }
 
+#if (RIL_VERSION == 11)
 static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
 {
     if (response == NULL && responselen != 0) {
@@ -2469,23 +2470,46 @@
 
     return 0;
 }
-
+#endif
 
 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
 {
     if (s_callbacks.version < 5) {
         RLOGD("responseDataCallList: v4");
         return responseDataCallListV4(p, response, responselen);
+#if (RIL_VERSION == 11)
     } else if (s_callbacks.version < 10) {
         return responseDataCallListV6(p, response, responselen);
     } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
         return responseDataCallListV9(p, response, responselen);
+#endif
     } else {
         if (response == NULL && responselen != 0) {
             RLOGE("invalid response: NULL");
             return RIL_ERRNO_INVALID_RESPONSE;
         }
 
+#if (RIL_VERSION == 10)
+        // Support v6 or v9 with new rils
+        if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
+            RLOGD("responseDataCallList: v6");
+            return responseDataCallListV6(p, response, responselen);
+        }
+
+        if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
+            RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
+                    (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
+            return RIL_ERRNO_INVALID_RESPONSE;
+        }
+
+        // Write version
+        p.writeInt32(10);
+
+        int num = responselen / sizeof(RIL_Data_Call_Response_v9);
+        p.writeInt32(num);
+
+        RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
+#else
         if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
             RLOGE("invalid response length %d expected multiple of %d",
                     (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
@@ -2499,6 +2523,7 @@
         p.writeInt32(num);
 
         RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
+#endif
         startResponse;
         int i;
         for (i = 0; i < num; i++) {
@@ -2512,6 +2537,19 @@
             writeStringToParcel(p, p_cur[i].dnses);
             writeStringToParcel(p, p_cur[i].gateways);
             writeStringToParcel(p, p_cur[i].pcscf);
+#if (RIL_VERSION == 10)
+            appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
+                p_cur[i].status,
+                p_cur[i].suggestedRetryTime,
+                p_cur[i].cid,
+                (p_cur[i].active==0)?"down":"up",
+                (char*)p_cur[i].type,
+                (char*)p_cur[i].ifname,
+                (char*)p_cur[i].addresses,
+                (char*)p_cur[i].dnses,
+                (char*)p_cur[i].gateways,
+                (char*)p_cur[i].pcscf);
+#else
             p.writeInt32(p_cur[i].mtu);
             appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
                 p_cur[i].status,
@@ -2525,6 +2563,7 @@
                 (char*)p_cur[i].gateways,
                 (char*)p_cur[i].pcscf,
                 p_cur[i].mtu);
+#endif
         }
         removeLastChar;
         closeResponse;
diff --git a/reference-ril/reference-ril.c b/reference-ril/reference-ril.c
index 24aeac4..39de740 100644
--- a/reference-ril/reference-ril.c
+++ b/reference-ril/reference-ril.c
@@ -452,8 +452,13 @@
          p_cur = p_cur->p_next)
         n++;
 
+#if (RIL_VERSION == 10)
+    RIL_Data_Call_Response_v9 *responses =
+        alloca(n * sizeof(RIL_Data_Call_Response_v9));
+#else
     RIL_Data_Call_Response_v11 *responses =
         alloca(n * sizeof(RIL_Data_Call_Response_v11));
+#endif
 
     int i;
     for (i = 0; i < n; i++) {
@@ -467,10 +472,16 @@
         responses[i].dnses = "";
         responses[i].gateways = "";
         responses[i].pcscf = "";
+#if (RIL_VERSION == 11)
         responses[i].mtu = 0;
+#endif
     }
 
+#if (RIL_VERSION == 10)
+    RIL_Data_Call_Response_v9 *response = responses;
+#else
     RIL_Data_Call_Response_v11 *response = responses;
+#endif
     for (p_cur = p_response->p_intermediates; p_cur != NULL;
          p_cur = p_cur->p_next) {
         char *line = p_cur->line;
@@ -587,7 +598,9 @@
 
                 /* There is only on gateway in the emulator */
                 responses[i].gateways = "10.0.2.2";
+#if (RIL_VERSION == 11)
                 responses[i].mtu = DEFAULT_MTU;
+#endif
             }
             else {
                 /* I don't know where we are, so use the public Google DNS
@@ -601,6 +614,15 @@
 
     at_response_free(p_response);
 
+#if (RIL_VERSION == 10)
+    if (t != NULL)
+         RIL_onRequestComplete(*t, RIL_E_SUCCESS, responses,
+                              n * sizeof(RIL_Data_Call_Response_v9));
+    else
+         RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED,
+                                   responses,
+                                   n * sizeof(RIL_Data_Call_Response_v9));
+#else
     if (t != NULL)
         RIL_onRequestComplete(*t, RIL_E_SUCCESS, responses,
                               n * sizeof(RIL_Data_Call_Response_v11));
@@ -608,7 +630,7 @@
         RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED,
                                   responses,
                                   n * sizeof(RIL_Data_Call_Response_v11));
-
+#endif
     return;
 
 error: