AT: Better failure handling and removed wrong unlock
[hayes-ril.git] / power.c
diff --git a/power.c b/power.c
index 465310e..50ab7a9 100644 (file)
--- a/power.c
+++ b/power.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
  *
- * Based on htcgeneric-ril, reference-ril:
+ * Parts of this code are based on htcgeneric-ril, reference-ril:
  * Copyright 2006-2011, htcgeneric-ril contributors
  * Copyright 2006, The Android Open Source Project
  *
@@ -26,7 +26,7 @@
 
 #include <hayes-ril.h>
 
-int at_cfun_enable(struct at_response *response, void *data, RIL_Token t)
+int at_cfun_enable_expect(struct at_response *response, void *data, RIL_Token t)
 {
        if(response->status == AT_STATUS_UNDEF)
                return AT_RESPONSE_UNHANDELD_REASON_STATUS;
@@ -43,7 +43,7 @@ int at_cfun_enable(struct at_response *response, void *data, RIL_Token t)
        return AT_RESPONSE_HANDLED_OK;
 }
 
-int at_cfun_disable(struct at_response *response, void *data, RIL_Token t)
+int at_cfun_disable_expect(struct at_response *response, void *data, RIL_Token t)
 {
        if(response->status == AT_STATUS_UNDEF)
                return AT_RESPONSE_UNHANDELD_REASON_STATUS;
@@ -62,38 +62,20 @@ int at_cfun_disable(struct at_response *response, void *data, RIL_Token t)
 
 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);
+       at_send_expect_to_func("AT+CFUN=1", NULL, NULL, 0x0000, at_cfun_enable_expect);
 
-       // 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);
+       ril_device_at_power_on(ril_device);
 }
 
 void ril_power_off(void)
 {
-       at_send_expect_to_func("AT+CFUN=0", NULL, NULL, 0x0000, at_cfun_disable);
+       LOGD("Powering off");
+
+       ril_device_at_power_off(ril_device);
+
+       at_send_expect_to_func("AT+CFUN=0", NULL, NULL, 0x0000, at_cfun_disable_expect);
 }
 
 void ril_request_radio_power(RIL_Token t, void *data, size_t length)
@@ -103,6 +85,9 @@ void ril_request_radio_power(RIL_Token t, void *data, size_t length)
 
        if(power_state > 0) {
                ril_power_on();
+
+               // Ask for PIN status
+               at_send_expect_to_func("AT+CPIN?", NULL, NULL, 0x0000, at_cpin_expect);
        } else {
                ril_power_off();
        }