Network: Added Signal Strength, SIM: Added missing SIM IO header and call
authorPaul Kocialkowski <contact@paulk.fr>
Tue, 31 Jul 2012 10:26:51 +0000 (12:26 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Tue, 31 Jul 2012 10:27:33 +0000 (12:27 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Android.mk
hayes-ril.c
hayes-ril.h
network.c [new file with mode: 0644]

index ccd1927..ad5da7e 100644 (file)
@@ -24,7 +24,8 @@ hayes_ril_files := \
        utils.c \
        call.c \
        power.c \
-       sim.c
+       sim.c \
+       network.c
 
 ifeq ($(TARGET_DEVICE),gta04)
        hayes_ril_device_files := device/gta04/gta04.c
index 4617cda..fac4877 100644 (file)
@@ -43,6 +43,13 @@ void ril_on_request(int request, void *data, size_t length, RIL_Token t)
                case RIL_REQUEST_ENTER_SIM_PIN:
                        ril_request_enter_sim_pin(t, data, length);
                        break;
+               case RIL_REQUEST_SIM_IO:
+                       ril_request_sim_io(t, data, length);
+                       break;
+               // Network
+               case RIL_REQUEST_SIGNAL_STRENGTH:
+                       ril_request_signal_strength(t, data, length);
+                       break;
                // Call
                case RIL_REQUEST_GET_CURRENT_CALLS:
                        ril_request_get_current_calls(t, data, length);
index 13efa0e..f162d9a 100644 (file)
@@ -148,5 +148,9 @@ void ril_request_radio_power(RIL_Token t, void *data, size_t length);
 int at_cpin_expect(struct at_response *response, void *data, RIL_Token t);
 void ril_request_get_sim_status(RIL_Token t, void *data, size_t length);
 void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t length);
+void ril_request_sim_io(RIL_Token t, void *data, size_t length);
+
+// Network
+void ril_request_signal_strength(RIL_Token t, void *data, size_t length);
 
 #endif
diff --git a/network.c b/network.c
new file mode 100644 (file)
index 0000000..d47545e
--- /dev/null
+++ b/network.c
@@ -0,0 +1,98 @@
+/*
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * Parts of this code are based on htcgeneric-ril, reference-ril:
+ * Copyright 2006-2011, htcgeneric-ril contributors
+ * 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 "RIL-NET"
+#include <utils/Log.h>
+#include <telephony/ril.h>
+
+#include <hayes-ril.h>
+
+void at2ril_signal_strength(RIL_SignalStrength *ss, int *values)
+{
+       const int dbm_table[8] = {135,125,115,105,95,85,75,70};
+       const int edbm_table[8] = {120,110,100,90,80,75,70,65};
+       const int ecio_table[8] = {200,150,130,120,110,100,90,80};
+
+       memset(ss, 0, sizeof(RIL_SignalStrength));
+
+       if(ril_device->type == DEV_GSM) {
+               ss->GW_SignalStrength.signalStrength = values[0];
+               ss->GW_SignalStrength.bitErrorRate = values[1];
+       } else {
+               /* 1st # is CDMA, 2nd is EVDO */
+               ss->CDMA_SignalStrength.dbm = dbm_table[values[0]];
+               ss->CDMA_SignalStrength.ecio = ecio_table[values[0]];
+               ss->EVDO_SignalStrength.dbm = edbm_table[values[1]];
+               ss->EVDO_SignalStrength.ecio = ecio_table[values[1]];
+               ss->EVDO_SignalStrength.signalNoiseRatio = values[1];
+       }
+}
+
+int at_csq_expect(struct at_response *response, void *data, RIL_Token t)
+{
+       struct at_response_data **response_data = NULL;
+       int response_data_count = 0;
+
+       RIL_SignalStrength ss;
+       int values[2] = { 0 };
+
+       if(response->status == AT_STATUS_UNDEF)
+               return AT_RESPONSE_UNHANDELD_REASON_STATUS;
+
+       if(response->data == NULL || response->data_count <= 0) {
+               LOGE("No data given to AT+CSQ response!");
+               return AT_RESPONSE_HANDLED_ERROR;
+       }
+
+       LOGE("Caught valid AT+CSQ response!");
+
+       response_data_count = at_response_data_process(&response_data, response->data[0], strlen(response->data[0]));
+       if(response_data_count < 2)
+               goto error_data;
+
+       if(response_data[0]->type != AT_RESPONSE_DATA_NUMERIC)
+               goto error_data;
+       values[0] = response_data[0]->value.n;
+
+       if(response_data[1]->type != AT_RESPONSE_DATA_NUMERIC)
+               goto error_data;
+       values[1] = response_data[1]->value.n;
+
+       at2ril_signal_strength(&ss, values);
+
+       RIL_onRequestComplete(t, RIL_E_SUCCESS, &ss, sizeof(RIL_SignalStrength));
+
+       at_response_data_free(response_data, response_data_count);
+
+       return AT_RESPONSE_HANDLED_OK;
+
+error_data:
+       LOGE("No valid data fiven to AT+CSQ response!");
+
+       at_response_data_free(response_data, response_data_count);
+       return AT_RESPONSE_HANDLED_ERROR;
+}
+
+void ril_request_signal_strength(RIL_Token t, void *data, size_t length)
+{
+       at_send_expect_to_func("AT+CSQ", NULL, NULL, t, at_csq_expect);
+}