Workaround for LTE RSRP -ve values in Signal

Ril version 6 and below sends negative values
for lte rsrp in signalstrength.
Workaround to maintain backward compatibility
and convert this to positive
values in compliance with ril.h

Support for processing all fields in
SignalStrength in reference-ril

Change-Id: I4d480aa2f607cd617b18681f722de246a7894348
diff --git a/libril/ril.cpp b/libril/ril.cpp
index b8aba01..e3f7e41 100644
--- a/libril/ril.cpp
+++ b/libril/ril.cpp
@@ -1995,6 +1995,15 @@
         p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
         if (responselen >= sizeof (RIL_SignalStrength_v6)) {
             p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
+
+            /*
+             * ril version <=6 receives negative values for rsrp
+             * workaround for backward compatibility
+             */
+            p_cur->LTE_SignalStrength.rsrp =
+                    ((s_callbacks.version <= 6) && (p_cur->LTE_SignalStrength.rsrp < 0 )) ?
+                        -(p_cur->LTE_SignalStrength.rsrp) : p_cur->LTE_SignalStrength.rsrp;
+
             p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
             p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
             p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
diff --git a/reference-ril/reference-ril.c b/reference-ril/reference-ril.c
index 37c87b2..578ff63 100644
--- a/reference-ril/reference-ril.c
+++ b/reference-ril/reference-ril.c
@@ -728,10 +728,12 @@
 
 static void requestSignalStrength(void *data, size_t datalen, RIL_Token t)
 {
-    RIL_SignalStrength_v6 response;
     ATResponse *p_response = NULL;
     int err;
     char *line;
+    int count =0;
+    int numofElements=sizeof(RIL_SignalStrength_v6)/sizeof(int);
+    int response[numofElements];
 
     err = at_send_command_singleline("AT+CSQ", "+CSQ:", &p_response);
 
@@ -745,15 +747,12 @@
     err = at_tok_start(&line);
     if (err < 0) goto error;
 
-    memset(&response, 0, sizeof(RIL_SignalStrength_v6));
+    for (count =0; count < numofElements; count ++) {
+        err = at_tok_nextint(&line, &(response[count]));
+        if (err < 0) goto error;
+    }
 
-    err = at_tok_nextint(&line, &response.GW_SignalStrength.signalStrength);
-    if (err < 0) goto error;
-
-    err = at_tok_nextint(&line, &response.GW_SignalStrength.bitErrorRate);
-    if (err < 0) goto error;
-
-    RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response));
+    RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
 
     at_response_free(p_response);
     return;