RIL: Added libril handlers and first power functions
authorPaul Kocialkowski <contact@paulk.fr>
Thu, 26 Jul 2012 21:26:13 +0000 (23:26 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Thu, 26 Jul 2012 21:26:13 +0000 (23:26 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Android.mk
hayes-ril.c
hayes-ril.h
power.c [new file with mode: 0644]

index bea75ee..951107d 100644 (file)
@@ -21,7 +21,8 @@ hayes_ril_files := \
        hayes-ril.c \
        at.c \
        device.c \
-       utils.c
+       utils.c \
+       power.c
 
 ifeq ($(TARGET_DEVICE),gta04)
        hayes_ril_device_files := device/gta04/gta04.c
index 262fa28..aad75cc 100644 (file)
@@ -29,17 +29,47 @@ struct ril_globals ril_globals;
 
 struct ril_dispatch_unsol ril_dispatch_unsol[] = {};
 
+void ril_on_request(int request, void *data, size_t length, RIL_Token t)
+{
+       switch(request) {
+               // Power
+               case RIL_REQUEST_RADIO_POWER:
+                       ril_request_radio_power(t, data, length);
+                       break;
+               default:
+                       LOGE("Request not implemented: %d\n", request);
+                       RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
+                       break;
+       }
+}
+
 const char *ril_get_version(void)
 {
        return RIL_VERSION_STRING;
 }
 
+RIL_RadioState ril_on_state_request(void)
+{
+       LOGD("State request");
+       return ril_globals.radio_state;
+}
+
+int ril_on_supports(int requestCode)
+{
+       return 1;
+}
+
+void ril_on_cancel(RIL_Token t)
+{
+       return;
+}
+
 static const RIL_RadioFunctions ril_ops = {
        RIL_VERSION,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
+       ril_on_request,
+       ril_on_state_request,
+       ril_on_supports,
+       ril_on_cancel,
        ril_get_version
 };
 
@@ -109,6 +139,8 @@ void ril_globals_init(void)
 
        LOGE("Registered %d unsol requests handlers", ril_globals.dispatch_unsol_count);
 
+       ril_globals.radio_state = RADIO_STATE_OFF;
+
        at_responses_handling_init();
 }
 
index b4fbd3d..7220d15 100644 (file)
@@ -105,6 +105,9 @@ struct ril_globals {
 
        // Log
        pthread_mutex_t log_mutex;
+
+       // Power
+       RIL_RadioState radio_state;
 };
 
 /*
diff --git a/power.c b/power.c
new file mode 100644 (file)
index 0000000..465310e
--- /dev/null
+++ b/power.c
@@ -0,0 +1,111 @@
+/*
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * 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-PWR"
+#include <utils/Log.h>
+#include <telephony/ril.h>
+
+#include <hayes-ril.h>
+
+int at_cfun_enable(struct at_response *response, void *data, RIL_Token t)
+{
+       if(response->status == AT_STATUS_UNDEF)
+               return AT_RESPONSE_UNHANDELD_REASON_STATUS;
+
+       LOGD("Updating radio state from AT+CFUN response");
+
+       switch(response->status) {
+               case AT_STATUS_OK:
+                       ril_globals.radio_state = RADIO_STATE_SIM_NOT_READY;
+                       RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
+                       break;
+       }
+
+       return AT_RESPONSE_HANDLED_OK;
+}
+
+int at_cfun_disable(struct at_response *response, void *data, RIL_Token t)
+{
+       if(response->status == AT_STATUS_UNDEF)
+               return AT_RESPONSE_UNHANDELD_REASON_STATUS;
+
+       LOGD("Updating radio state from AT+CFUN response");
+
+       switch(response->status) {
+               case AT_STATUS_OK:
+                       ril_globals.radio_state = RADIO_STATE_OFF;
+                       RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
+                       break;
+       }
+
+       return AT_RESPONSE_HANDLED_OK;
+}
+
+void ril_power_on(void)
+{
+       int status;
+
+       LOGD("Powering on");
+
+       // Echo enabled, send results, verbose enabled
+       at_send_expect_status("ATE1Q0V1", NULL);
+
+       // Extended errors
+       at_send_expect_status("AT+CMEE=1", NULL);
+
+       // Detailed rings, service reporting
+       at_send_expect_status("AT+CRC=1;+CR=1", NULL);
+
+       // SMS PDU mode
+       at_send_expect_status("AT+CMGF=0", NULL);
+
+       // SMS PDU mode
+       at_send_expect_status("AT+CMGF=0", NULL);
+
+       // Network registration notifications
+       status = at_send_expect_status("AT+CREG=2", NULL);
+       if(at_status_error(status)) {
+               LOGD("Modem doesn't support AT+CREG=2");
+               at_send_expect_status("AT+CREG=1", NULL);
+       }
+
+       at_send_expect_to_func("AT+CFUN=1", NULL, NULL, 0x0000, at_cfun_enable);
+}
+
+void ril_power_off(void)
+{
+       at_send_expect_to_func("AT+CFUN=0", NULL, NULL, 0x0000, at_cfun_disable);
+}
+
+void ril_request_radio_power(RIL_Token t, void *data, size_t length)
+{
+       int power_state = *((int *)data);
+       int rc;
+
+       if(power_state > 0) {
+               ril_power_on();
+       } else {
+               ril_power_off();
+       }
+
+       RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
+}