Added minimal SIM support, updated copyright, renamed expect funcs, CME errors
authorPaul Kocialkowski <contact@paulk.fr>
Fri, 27 Jul 2012 18:07:51 +0000 (20:07 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Fri, 27 Jul 2012 18:07:51 +0000 (20:07 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Android.mk
at.h
hayes-ril.c
hayes-ril.h
power.c
sim.c [new file with mode: 0644]

index 951107d..ccd1927 100644 (file)
@@ -22,7 +22,9 @@ hayes_ril_files := \
        at.c \
        device.c \
        utils.c \
-       power.c
+       call.c \
+       power.c \
+       sim.c
 
 ifeq ($(TARGET_DEVICE),gta04)
        hayes_ril_device_files := device/gta04/gta04.c
diff --git a/at.h b/at.h
index 869b100..9b04057 100644 (file)
--- a/at.h
+++ b/at.h
@@ -3,6 +3,10 @@
  *
  * 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
@@ -69,6 +73,69 @@ enum {
 };
 
 enum {
+       AT_CME_ERROR_PHONE_FAILURE = 0,
+       AT_CME_ERROR_PHONE_NO_CONNECTION,
+       AT_CME_ERROR_PHONE_LINK_RESERVED,
+       AT_CME_ERROR_OPERATION_NOT_ALLOWED,
+       AT_CME_ERROR_OPERATION_NOT_SUPPORTED,
+       AT_CME_ERROR_PH_SIM_PIN_REQD,
+       AT_CME_ERROR_PH_FSIM_PIN_REQD,
+       AT_CME_ERROR_PH_FSIM_PUK_REQD,
+       AT_CME_ERROR_SIM_NOT_INSERTED=10,
+       AT_CME_ERROR_SIM_PIN_REQD,
+       AT_CME_ERROR_SIM_PUK_REQD,
+       AT_CME_ERROR_SIM_FAILURE,
+       AT_CME_ERROR_SIM_BUSY,
+       AT_CME_ERROR_SIM_WRONG,
+       AT_CME_ERROR_INCORRECT_PASSWORD,
+       AT_CME_ERROR_SIM_PIN2_REQD,
+       AT_CME_ERROR_SIM_PUK2_REQD,
+       AT_CME_ERROR_MEMORY_FULL=20,
+       AT_CME_ERROR_INVALID_INDEX,
+       AT_CME_ERROR_NOT_FOUND,
+       AT_CME_ERROR_MEMORY_FAILURE,
+       AT_CME_ERROR_TEXT_STRING_TOO_LONG,
+       AT_CME_ERROR_INVALID_CHARS_IN_TEXT,
+       AT_CME_ERROR_DIAL_STRING_TOO_LONG,
+       AT_CME_ERROR_INVALID_CHARS_IN_DIAL,
+       AT_CME_ERROR_NO_NETWORK_SERVICE=30,
+       AT_CME_ERROR_NETWORK_TIMEOUT,
+       AT_CME_ERROR_NETWORK_NOT_ALLOWED,
+       AT_CME_ERROR_NETWORK_PERS_PIN_REQD=40,
+       AT_CME_ERROR_NETWORK_PERS_PUK_REQD,
+       AT_CME_ERROR_NETWORK_SUBSET_PERS_PIN_REQD,
+       AT_CME_ERROR_NETWORK_SUBSET_PERS_PUK_REQD,
+       AT_CME_ERROR_PROVIDER_PERS_PIN_REQD,
+       AT_CME_ERROR_PROVIDER_PERS_PUK_REQD,
+       AT_CME_ERROR_CORP_PERS_PIN_REQD,
+       AT_CME_ERROR_CORP_PERS_PUK_REQD,
+       AT_CME_ERROR_PH_SIM_PUK_REQD,
+       AT_CME_ERROR_UNKNOWN_ERROR=100,
+       AT_CME_ERROR_ILLEGAL_MS=103,
+       AT_CME_ERROR_ILLEGAL_ME=106,
+       AT_CME_ERROR_GPRS_NOT_ALLOWED,
+       AT_CME_ERROR_PLMN_NOT_ALLOWED=111,
+       AT_CME_ERROR_LOCATION_NOT_ALLOWED,
+       AT_CME_ERROR_ROAMING_NOT_ALLOWED,
+       AT_CME_ERROR_TEMPORARY_NOT_ALLOWED=126,
+       AT_CME_ERROR_SERVICE_OPTION_NOT_SUPPORTED=132,
+       AT_CME_ERROR_SERVICE_OPTION_NOT_SUBSCRIBED,
+       AT_CME_ERROR_SERVICE_OPTION_OUT_OF_ORDER,
+       AT_CME_ERROR_UNSPECIFIED_GPRS_ERROR=148,
+       AT_CME_ERROR_PDP_AUTHENTICATION_FAILED,
+       AT_CME_ERROR_INVALID_MOBILE_CLASS,
+       AT_CME_ERROR_OPERATION_TEMP_NOT_ALLOWED=256,
+       AT_CME_ERROR_CALL_BARRED,
+       AT_CME_ERROR_PHONE_BUSY,
+       AT_CME_ERROR_USER_ABORT,
+       AT_CME_ERROR_INVALID_DIAL_STRING,
+       AT_CME_ERROR_SS_NOT_EXECUTED,
+       AT_CME_ERROR_SIM_BLOCKED,
+       AT_CME_ERROR_INVALID_BLOCK,
+       AT_CME_ERROR_SIM_POWERED_DOWN=772
+};
+
+enum {
        AT_RESPONSE_WAITING,
        AT_RESPONSE_UNHANDELD_REASON_DATA,
        AT_RESPONSE_UNHANDELD_REASON_STATUS,
index aad75cc..e049664 100644 (file)
@@ -27,7 +27,9 @@
 struct ril_device *ril_device;
 struct ril_globals ril_globals;
 
-struct ril_dispatch_unsol ril_dispatch_unsol[] = {};
+struct ril_dispatch_unsol ril_dispatch_unsol[] = {
+       { "AT+CPIN",    at_cpin }
+};
 
 void ril_on_request(int request, void *data, size_t length, RIL_Token t)
 {
@@ -36,6 +38,10 @@ void ril_on_request(int request, void *data, size_t length, RIL_Token t)
                case RIL_REQUEST_RADIO_POWER:
                        ril_request_radio_power(t, data, length);
                        break;
+               // Call
+               case RIL_REQUEST_GET_CURRENT_CALLS:
+                       ril_request_get_current_calls(t, data, length);
+                       break;
                default:
                        LOGE("Request not implemented: %d\n", request);
                        RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
index 7220d15..e6f92d8 100644 (file)
@@ -138,4 +138,13 @@ void ril_recv_log(struct at_response *response);
 void ril_send_log(struct at_request *request);
 void ril_data_log(char *data, int length);
 
+// Call
+void ril_request_get_current_calls(RIL_Token t, void *data, size_t length);
+
+// Power
+void ril_request_radio_power(RIL_Token t, void *data, size_t length);
+
+// SIM
+void at_cpin(struct at_response *response);
+
 #endif
diff --git a/power.c b/power.c
index 465310e..62a8d80 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;
@@ -88,12 +88,12 @@ void ril_power_on(void)
                at_send_expect_status("AT+CREG=1", NULL);
        }
 
-       at_send_expect_to_func("AT+CFUN=1", NULL, NULL, 0x0000, at_cfun_enable);
+       at_send_expect_to_func("AT+CFUN=1", NULL, NULL, 0x0000, at_cfun_enable_expect);
 }
 
 void ril_power_off(void)
 {
-       at_send_expect_to_func("AT+CFUN=0", NULL, NULL, 0x0000, at_cfun_disable);
+       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)
@@ -107,5 +107,8 @@ void ril_request_radio_power(RIL_Token t, void *data, size_t length)
                ril_power_off();
        }
 
+       // Send AT+CPIN, response will fall unsol and update status
+       at_send_command("AT+CPIN?");
+
        RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
 }
diff --git a/sim.c b/sim.c
new file mode 100644 (file)
index 0000000..ae9c6e7
--- /dev/null
+++ b/sim.c
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#include <ctype.h>
+
+#define LOG_TAG "RIL-SIM"
+#include <utils/Log.h>
+#include <telephony/ril.h>
+
+#include <hayes-ril.h>
+
+RIL_RadioState at2ril_cme_pin_status(int code)
+{
+       switch(code) {
+               case AT_CME_ERROR_PH_SIM_PIN_REQD:
+               case AT_CME_ERROR_PH_SIM_PUK_REQD:
+               case AT_CME_ERROR_PH_FSIM_PIN_REQD:
+               case AT_CME_ERROR_PH_FSIM_PUK_REQD:
+               case AT_CME_ERROR_SIM_NOT_INSERTED:
+               case AT_CME_ERROR_SIM_PIN_REQD:
+               case AT_CME_ERROR_SIM_PUK_REQD:
+               case AT_CME_ERROR_SIM_PIN2_REQD:
+               case AT_CME_ERROR_SIM_PUK2_REQD:
+               case AT_CME_ERROR_SIM_BLOCKED:
+                       return RADIO_STATE_SIM_LOCKED_OR_ABSENT;
+               case AT_CME_ERROR_SIM_FAILURE:
+               case AT_CME_ERROR_SIM_BUSY:
+               case AT_CME_ERROR_SIM_WRONG:
+               case AT_CME_ERROR_SIM_POWERED_DOWN:
+               default:
+                       return RADIO_STATE_SIM_NOT_READY;
+       }
+}
+
+void at_cpin(struct at_response *response)
+{
+       int code = 0;
+
+       if(response->status == AT_STATUS_UNDEF)
+               return;
+
+       if(response->status == AT_STATUS_CME_ERROR && response->error != NULL) {
+               code = atoi(response->error);
+               if(code != 0) {
+                       LOGD("Updating radio state!");
+                       ril_globals.radio_state = at2ril_cme_pin_status(code);
+                       RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
+               }
+
+               // TODO: gather more infos for ril_globals
+       } else if(response->status == AT_STATUS_OK) {
+               ril_globals.radio_state = RADIO_STATE_SIM_READY;
+               RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
+               // TODO: gather more infos for ril_globals
+       } else {
+               // Various error codes, not helping here
+               return;
+       }
+
+       // TODO: Store the data we have in ril_globals (pointer alloc here?), then call UNSOL
+
+       LOGD("Handled AT+CPIN response");
+}