summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulK <contact@paulk.fr>2012-02-24 17:11:50 +0100
committerPaulK <contact@paulk.fr>2012-02-24 17:11:50 +0100
commitcb1efeba2b0cffb4fcfaa17e21a2994db42d9319 (patch)
treee382983f63f0bb0c8b51e2f1703557b68870a072
parentb5194a9496d7bd12ca96a97fee8470651e9bbc3b (diff)
downloadhardware_ril_samsung-ril-cb1efeba2b0cffb4fcfaa17e21a2994db42d9319.zip
hardware_ril_samsung-ril-cb1efeba2b0cffb4fcfaa17e21a2994db42d9319.tar.gz
hardware_ril_samsung-ril-cb1efeba2b0cffb4fcfaa17e21a2994db42d9319.tar.bz2
Massive rework of SIM handling, with new features SIM PIN-related.
-rw-r--r--Android.mk2
-rw-r--r--samsung-ril.c25
-rw-r--r--samsung-ril.h17
-rw-r--r--sec.c (renamed from sim.c)549
4 files changed, 397 insertions, 196 deletions
diff --git a/Android.mk b/Android.mk
index 89da396..2b2cfbd 100644
--- a/Android.mk
+++ b/Android.mk
@@ -32,7 +32,7 @@ LOCAL_SRC_FILES := \
misc.c \
sat.c \
ss.c \
- sim.c \
+ sec.c \
net.c \
sms.c \
call.c \
diff --git a/samsung-ril.c b/samsung-ril.c
index e988b06..5d08529 100644
--- a/samsung-ril.c
+++ b/samsung-ril.c
@@ -140,17 +140,21 @@ void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t resp
void ril_tokens_check(void)
{
+ RIL_Token t;
+
if(ril_state.tokens.baseband_version != 0) {
if(ril_state.radio_state != RADIO_STATE_OFF) {
+ t = ril_state.tokens.baseband_version;
ril_state.tokens.baseband_version = 0;
- ril_request_baseband_version(ril_state.tokens.baseband_version);
+ ril_request_baseband_version(t);
}
}
if(ril_state.tokens.get_imei != 0 && ril_state.tokens.get_imeisv != 0) {
if(ril_state.radio_state != RADIO_STATE_OFF) {
+ t = ril_state.tokens.get_imei;
ril_state.tokens.get_imei = 0;
- ril_request_get_imei(ril_state.tokens.get_imei);
+ ril_request_get_imei(t);
}
}
}
@@ -204,7 +208,7 @@ void ipc_fmt_dispatch(struct ipc_message_info *info)
case IPC_SS_USSD:
ipc_ss_ussd(info);
break;
- /* SIM */
+ /* SEC */
case IPC_SEC_PIN_STATUS:
ipc_sec_pin_status(info);
break;
@@ -366,9 +370,9 @@ void onRequest(int request, void *data, size_t datalen, RIL_Token t)
break;
case RIL_REQUEST_CANCEL_USSD:
ril_request_cancel_ussd(t, data, datalen);
- /* SIM */
+ /* SEC */
case RIL_REQUEST_GET_SIM_STATUS:
- ril_request_sim_status(t);
+ ril_request_get_sim_status(t);
break;
case RIL_REQUEST_SIM_IO:
ril_request_sim_io(t, data, datalen);
@@ -376,6 +380,12 @@ void onRequest(int request, void *data, size_t datalen, RIL_Token t)
case RIL_REQUEST_ENTER_SIM_PIN:
ril_request_enter_sim_pin(t, data, datalen);
break;
+ case RIL_REQUEST_CHANGE_SIM_PIN:
+ ril_request_change_sim_pin(t, data, datalen);
+ break;
+ case RIL_REQUEST_ENTER_SIM_PUK:
+ ril_request_enter_sim_puk(t, data, datalen);
+ break;
case RIL_REQUEST_QUERY_FACILITY_LOCK:
ril_request_query_facility_lock(t, data, datalen);
break;
@@ -472,6 +482,7 @@ void onRequest(int request, void *data, size_t datalen, RIL_Token t)
RIL_RadioState currentState()
{
+ LOGD("currentState()");
return ril_state.radio_state;
}
@@ -553,7 +564,7 @@ ipc_fmt:
LOGD("IPC FMT client ready");
-ipc_rfs:
+ipc_rfs:/*
LOGD("Creating IPC RFS client");
ipc_rfs_client = ril_client_new(&ipc_rfs_client_funcs);
@@ -572,7 +583,7 @@ ipc_rfs:
}
LOGD("IPC RFS client ready");
-
+*/
srs:
LOGD("Creating SRS client");
diff --git a/samsung-ril.h b/samsung-ril.h
index c6bfb4a..c328df4 100644
--- a/samsung-ril.h
+++ b/samsung-ril.h
@@ -129,6 +129,7 @@ void RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t resp
struct ril_tokens {
RIL_Token radio_power;
+ RIL_Token pin_status;
RIL_Token get_imei;
RIL_Token get_imeisv;
RIL_Token baseband_version;
@@ -165,12 +166,15 @@ typedef enum {
struct ril_state {
RIL_RadioState radio_state;
- RIL_CardState card_state;
+// RIL_CardStatus card_status;
SIM_Status sim_status;
Modem_PowerMode power_mode;
struct ril_tokens tokens;
+ struct ipc_sec_pin_status_response sim_pin_status;
+ struct ipc_sec_sim_icc_type sim_type;
+
struct ipc_net_regist netinfo;
struct ipc_net_regist gprs_netinfo;
struct ipc_net_current_plmn plmndata;
@@ -241,16 +245,19 @@ void ril_request_send_ussd(RIL_Token t, void *data, size_t datalen);
void ril_request_cancel_ussd(RIL_Token t, void *data, size_t datalen);
void ipc_ss_ussd(struct ipc_message_info *info);
-/* SIM */
+/* SEC */
+void ril_state_update(SIM_Status status);
void ipc_sec_pin_status(struct ipc_message_info *info);
-void ril_request_sim_status(RIL_Token t);
+void ril_request_get_sim_status(RIL_Token t);
void ril_request_sim_io(RIL_Token t, void *data, size_t datalen);
void ipc_sec_rsim_access(struct ipc_message_info *info);
-void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t datalen);
void ipc_sec_pin_status_complete(struct ipc_message_info *info);
void ipc_sec_lock_info(struct ipc_message_info *info);
+void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t datalen);
+void ril_request_change_sim_pin(RIL_Token t, void *data, size_t datalen);
+void ril_request_enter_sim_puk(RIL_Token t, void *data, size_t datalen);
void ril_request_query_facility_lock(RIL_Token t, void *data, size_t datalen);
-void ipc_sec_phone_lock(struct ipc_message_info *info);
+void ipc_sec_phone_lock_complete(struct ipc_message_info *info);
void ril_request_set_facility_lock(RIL_Token t, void *data, size_t datalen);
/* NET */
diff --git a/sim.c b/sec.c
index ef1d5b4..0606944 100644
--- a/sim.c
+++ b/sec.c
@@ -2,7 +2,7 @@
* This file is part of samsung-ril.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
- * Copyright (C) 2011 Paul Kocialkowski <contact@oaulk.fr>
+ * Copyright (C) 2011-2012 Paul Kocialkowski <contact@oaulk.fr>
*
* samsung-ril is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,12 +19,131 @@
*
*/
-#define LOG_TAG "RIL-SIM"
+#define LOG_TAG "RIL-SEC"
#include <utils/Log.h>
#include "samsung-ril.h"
#include "util.h"
+#define RIL_TOKEN_SEC_DATA_WAITING (RIL_Token) 0xff
+
+SIM_Status ipc2ril_sim_status(struct ipc_sec_pin_status_response *pin_status)
+{
+ switch(pin_status->type) {
+ case IPC_SEC_PIN_SIM_INITIALIZING:
+ return SIM_NOT_READY;
+ case IPC_SEC_PIN_SIM_LOCK_SC:
+ switch(pin_status->key) {
+ case IPC_SEC_PIN_SIM_LOCK_SC_PIN1_REQ:
+ return SIM_PIN;
+ case IPC_SEC_PIN_SIM_LOCK_SC_PUK_REQ:
+ return SIM_PUK;
+ case IPC_SEC_PIN_SIM_LOCK_SC_CARD_BLOCKED:
+ return SIM_BLOCKED;
+ default:
+ LOGE("%s: unknown SC substate %d --> setting SIM_ABSENT", __FUNCTION__, pin_status->key);
+ return SIM_ABSENT;
+ }
+ break;
+ case IPC_SEC_PIN_SIM_LOCK_FD:
+ LOGE("%s: FD lock present (unhandled state --> setting SIM_ABSENT)", __FUNCTION__);
+ return SIM_ABSENT;
+ case IPC_SEC_PIN_SIM_LOCK_PN:
+ return SIM_NETWORK_PERSO;
+ case IPC_SEC_PIN_SIM_LOCK_PU:
+ return SIM_NETWORK_SUBSET_PERSO;
+ case IPC_SEC_PIN_SIM_LOCK_PP:
+ return SIM_SERVICE_PROVIDER_PERSO;
+ case IPC_SEC_PIN_SIM_LOCK_PC:
+ return SIM_CORPORATE_PERSO;
+ case IPC_SEC_PIN_SIM_INIT_COMPLETE:
+ return SIM_READY;
+ case IPC_SEC_PIN_SIM_PB_INIT_COMPLETE:
+ /* Ignore phone book init complete */
+ return ril_state.sim_status;
+ case IPC_SEC_PIN_SIM_SIM_LOCK_REQUIRED:
+ case IPC_SEC_PIN_SIM_INSIDE_PF_ERROR:
+ case IPC_SEC_PIN_SIM_CARD_NOT_PRESENT:
+ case IPC_SEC_PIN_SIM_CARD_ERROR:
+ default:
+ /* Catchall for locked, card error and unknown states */
+ return SIM_ABSENT;
+ }
+}
+
+void ipc2ril_card_status(struct ipc_sec_pin_status_response *pin_status, RIL_CardStatus *card_status)
+{
+ SIM_Status sim_status;
+ int app_status_array_length;
+ int app_index;
+ int i;
+
+ static RIL_AppStatus app_status_array[] = {
+ /* SIM_ABSENT = 0 */
+ { RIL_APPTYPE_UNKNOWN, RIL_APPSTATE_UNKNOWN, RIL_PERSOSUBSTATE_UNKNOWN,
+ NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN },
+ /* SIM_NOT_READY = 1 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_DETECTED, RIL_PERSOSUBSTATE_UNKNOWN,
+ NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN },
+ /* SIM_READY = 2 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_READY, RIL_PERSOSUBSTATE_READY,
+ NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN },
+ /* SIM_PIN = 3 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_PIN, RIL_PERSOSUBSTATE_UNKNOWN,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
+ /* SIM_PUK = 4 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_PUK, RIL_PERSOSUBSTATE_UNKNOWN,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_BLOCKED, RIL_PINSTATE_UNKNOWN },
+ /* SIM_BLOCKED = 4 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_PUK, RIL_PERSOSUBSTATE_UNKNOWN,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_PERM_BLOCKED, RIL_PINSTATE_UNKNOWN },
+ /* SIM_NETWORK_PERSO = 6 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_NETWORK,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
+ /* SIM_NETWORK_SUBSET_PERSO = 7 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
+ /* SIM_CORPORATE_PERSO = 8 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_CORPORATE,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
+ /* SIM_SERVICE_PROVIDER_PERSO = 9 */
+ { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
+ NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
+ };
+
+ app_status_array_length = sizeof(app_status_array) / sizeof(RIL_AppStatus);
+
+ if(app_status_array_length > RIL_CARD_MAX_APPS)
+ app_status_array_length = RIL_CARD_MAX_APPS;
+
+ sim_status = ipc2ril_sim_status(pin_status);
+
+ /* Card is assumed to be present if not explicitly absent */
+ if(sim_status == SIM_ABSENT) {
+ card_status->card_state = RIL_CARDSTATE_ABSENT;
+ } else {
+ card_status->card_state = RIL_CARDSTATE_PRESENT;
+ }
+
+ // FIXME: How do we know that?
+ card_status->universal_pin_state = RIL_PINSTATE_UNKNOWN;
+
+ // Initialize the apps
+ for (i = 0 ; i < app_status_array_length ; i++) {
+ memcpy((void *) &(card_status->applications[i]), (void *) &(app_status_array[i]), sizeof(RIL_AppStatus));
+ }
+ for(i = app_status_array_length ; i < RIL_CARD_MAX_APPS ; i++) {
+ memset((void *) &(card_status->applications[i]), 0, sizeof(RIL_AppStatus));
+ }
+
+ // sim_status corresponds to the app index on the table
+ card_status->gsm_umts_subscription_app_index = (int) sim_status;
+ card_status->cdma_subscription_app_index = (int) sim_status;
+ card_status->num_applications = app_status_array_length;
+
+ LOGD("Selection application #%d on %d", (int) sim_status, app_status_array_length);
+}
+
/**
* Update the radio state based on SIM status
*
@@ -38,6 +157,8 @@ void ril_state_update(SIM_Status status)
if(ril_state.power_mode < POWER_MODE_NORMAL)
return;
+ ril_state.sim_status = status;
+
switch(status) {
case SIM_READY:
ril_state.radio_state = RADIO_STATE_SIM_READY;
@@ -64,6 +185,12 @@ void ril_state_update(SIM_Status status)
RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0);
}
+void ril_tokens_pin_status_dump(void)
+{
+ LOGD("ril_tokens_pin_status_dump:\n\
+ \tril_state.tokens.pin_status = 0x%x\n", ril_state.tokens.pin_status);
+}
+
/**
* In: IPC_SEC_PIN_STATUS
* Provides SIM initialization/lock status
@@ -78,150 +205,115 @@ void ril_state_update(SIM_Status status)
*/
void ipc_sec_pin_status(struct ipc_message_info *info)
{
- struct ipc_sec_pin_status_noti *pin_status = (struct ipc_sec_pin_status_noti *) info->data;
-
- /* Don't consider this if modem isn't in normal power mode. */
- if(ril_state.power_mode < POWER_MODE_NORMAL)
- return;
+ RIL_Token t = reqGetToken(info->aseq);
+ struct ipc_sec_pin_status_response *pin_status = (struct ipc_sec_pin_status_response *) info->data;
+ RIL_CardStatus card_status;
+ SIM_Status sim_status;
- if(ril_state.power_mode == POWER_MODE_NORMAL && ril_state.tokens.radio_power != 0) {
+ if(ril_state.power_mode == POWER_MODE_NORMAL && ril_state.tokens.radio_power != (RIL_Token) 0x00) {
RIL_onRequestComplete(ril_state.tokens.radio_power, RIL_E_SUCCESS, NULL, 0);
- ril_state.tokens.radio_power = 0;
+ ril_state.tokens.radio_power = (RIL_Token) 0x00;
}
- /* Determine SIM status */
- switch(pin_status->type) {
- case IPC_SEC_PIN_SIM_INITIALIZING:
- ril_state.sim_status = SIM_NOT_READY;
- break;
- case IPC_SEC_PIN_SIM_LOCK_SC:
- switch(pin_status->key) {
- case IPC_SEC_PIN_SIM_LOCK_SC_PIN1_REQ:
- ril_state.sim_status = SIM_PIN;
- break;
- case IPC_SEC_PIN_SIM_LOCK_SC_PUK_REQ:
- ril_state.sim_status = SIM_PUK;
- break;
- case IPC_SEC_PIN_SIM_LOCK_SC_CARD_BLOCKED:
- ril_state.sim_status = SIM_BLOCKED;
- break;
- default:
- ril_state.sim_status = SIM_ABSENT;
- LOGE("%s: unknown SC substate %d --> setting SIM_ABSENT", __FUNCTION__, pin_status->key);
- break;
+ switch(info->type) {
+ case IPC_TYPE_NOTI:
+ // Don't consider this if modem isn't in normal power mode
+ if(ril_state.power_mode < POWER_MODE_NORMAL)
+ return;
+
+ LOGD("Got UNSOL PIN status message");
+
+ if(ril_state.tokens.pin_status != (RIL_Token) 0x00 && ril_state.tokens.pin_status != RIL_TOKEN_SEC_DATA_WAITING) {
+ LOGE("Another PIN status Req is in progress, skipping");
+ return;
+ }
+
+ sim_status = ipc2ril_sim_status(pin_status);
+ ril_state_update(sim_status);
+
+ memcpy(&(ril_state.sim_pin_status), pin_status, sizeof(struct ipc_sec_pin_status_response));
+
+ // Apparently, these aren't interesting RILJ
+ if(sim_status == SIM_ABSENT || sim_status == SIM_READY || sim_status == SIM_NOT_READY)
+ return;
+
+ // We already told RILJ to get the new data but it wasn't done yet
+ if(ril_state.tokens.pin_status == RIL_TOKEN_SEC_DATA_WAITING) {
+ LOGD("Updating PIN status data in background");
+ } else {
+ ril_state.tokens.pin_status = RIL_TOKEN_SEC_DATA_WAITING;
+ RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
}
break;
- case IPC_SEC_PIN_SIM_LOCK_FD:
- ril_state.sim_status = SIM_ABSENT;
- LOGE("%s: FD lock present (unhandled state --> setting SIM_ABSENT)", __FUNCTION__);
- break;
- case IPC_SEC_PIN_SIM_LOCK_PN:
- ril_state.sim_status = SIM_NETWORK_PERSO;
- break;
- case IPC_SEC_PIN_SIM_LOCK_PU:
- ril_state.sim_status = SIM_NETWORK_SUBSET_PERSO;
- break;
- case IPC_SEC_PIN_SIM_LOCK_PP:
- ril_state.sim_status = SIM_SERVICE_PROVIDER_PERSO;
- break;
- case IPC_SEC_PIN_SIM_LOCK_PC:
- ril_state.sim_status = SIM_CORPORATE_PERSO;
- break;
- case IPC_SEC_PIN_SIM_INIT_COMPLETE:
- ril_state.sim_status = SIM_READY;
+ case IPC_TYPE_RESP:
+ LOGD("Got SOL PIN status message");
+
+ if(ril_state.tokens.pin_status != t)
+ LOGE("PIN status tokens mismatch");
+
+ sim_status = ipc2ril_sim_status(pin_status);
+ ril_state_update(sim_status);
+
+ // Better keeping this up to date
+ memcpy(&(ril_state.sim_pin_status), pin_status, sizeof(struct ipc_sec_pin_status_response));
+
+ ipc2ril_card_status(pin_status, &card_status);
+ RIL_onRequestComplete(t, RIL_E_SUCCESS, &card_status, sizeof(RIL_CardStatus));
+
+ if(ril_state.tokens.pin_status != RIL_TOKEN_SEC_DATA_WAITING)
+ ril_state.tokens.pin_status = (RIL_Token) 0x00;
break;
- case IPC_SEC_PIN_SIM_PB_INIT_COMPLETE:
- /* Ignore phone book init complete */
- return;
- case IPC_SEC_PIN_SIM_SIM_LOCK_REQUIRED:
- case IPC_SEC_PIN_SIM_INSIDE_PF_ERROR:
- case IPC_SEC_PIN_SIM_CARD_NOT_PRESENT:
- case IPC_SEC_PIN_SIM_CARD_ERROR:
default:
- /* Catchall for locked, card error and unknown states */
- ril_state.sim_status = SIM_ABSENT;
- break;
+ LOGE("%s: unhandled ipc method: %d", __FUNCTION__, info->type);
+ break;
}
- /* Update radio state based on SIM state */
- ril_state_update(ril_state.sim_status);
-
- RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
+ ril_tokens_pin_status_dump();
}
/**
* In: RIL_REQUEST_GET_SIM_STATUS
* Requests status of the SIM interface and the SIM card
*/
-void ril_request_sim_status(RIL_Token t)
+void ril_request_get_sim_status(RIL_Token t)
{
- static RIL_AppStatus app_status_array[] = {
- /* SIM_ABSENT = 0 */
- { RIL_APPTYPE_UNKNOWN, RIL_APPSTATE_UNKNOWN, RIL_PERSOSUBSTATE_UNKNOWN,
- NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN },
- /* SIM_NOT_READY = 1 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_DETECTED, RIL_PERSOSUBSTATE_UNKNOWN,
- NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN },
- /* SIM_READY = 2 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_READY, RIL_PERSOSUBSTATE_READY,
- NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN },
- /* SIM_PIN = 3 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_PIN, RIL_PERSOSUBSTATE_UNKNOWN,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
- /* SIM_PUK = 4 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_PUK, RIL_PERSOSUBSTATE_UNKNOWN,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_BLOCKED, RIL_PINSTATE_UNKNOWN },
- /* SIM_BLOCKED = 4 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_PUK, RIL_PERSOSUBSTATE_UNKNOWN,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_PERM_BLOCKED, RIL_PINSTATE_UNKNOWN },
- /* SIM_NETWORK_PERSO = 6 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_NETWORK,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
- /* SIM_NETWORK_SUBSET_PERSO = 7 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_NETWORK_SUBSET,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
- /* SIM_CORPORATE_PERSO = 8 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_CORPORATE,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
- /* SIM_SERVICE_PROVIDER_PERSO = 9 */
- { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
- NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN },
- };
-
- int i, num_applications;
- RIL_CardState card_state;
+ struct ipc_sec_pin_status_response *pin_status;
RIL_CardStatus card_status;
+ SIM_Status sim_status;
- /* Card is assumed to be present if not explicitly absent */
- if(ril_state.sim_status == SIM_ABSENT) {
- card_state = RIL_CARDSTATE_ABSENT;
- } else {
- card_state = RIL_CARDSTATE_PRESENT;
- }
+ if(ril_state.tokens.pin_status == RIL_TOKEN_SEC_DATA_WAITING) {
+ LOGD("Got RILJ request for UNSOL data");
+ hex_dump(&(ril_state.sim_pin_status), sizeof(struct ipc_sec_pin_status_response));
+ pin_status = &(ril_state.sim_pin_status);
+/*
+ sim_status = ipc2ril_sim_status(pin_status);
+ ril_state_update(sim_status);
+*/
+ ipc2ril_card_status(pin_status, &card_status);
- /* Fill in struct */
- card_status.card_state = card_state;
- card_status.universal_pin_state = RIL_PINSTATE_UNKNOWN;
- card_status.gsm_umts_subscription_app_index = RIL_CARD_MAX_APPS;
- card_status.cdma_subscription_app_index = RIL_CARD_MAX_APPS;
- card_status.num_applications = 0;
+ RIL_onRequestComplete(t, RIL_E_SUCCESS, &card_status, sizeof(RIL_CardStatus));
- /* Initialize apps */
- for (i = 0; i < RIL_CARD_MAX_APPS; i++) {
- card_status.applications[i] = app_status_array[0];
- }
+ ril_state.tokens.pin_status = (RIL_Token) 0x00;
+ } else if(ril_state.tokens.pin_status == (RIL_Token) 0x00) {
+ LOGD("Got RILJ request for SOL data");
- /* If a card is present, add the gsm/umts application */
- if(card_status.card_state == RIL_CARDSTATE_PRESENT) {
- card_status.gsm_umts_subscription_app_index = 0;
- card_status.num_applications = 1;
- card_status.applications[0] = app_status_array[ril_state.sim_status];
+ /* Request data to the modem */
+ ril_state.tokens.pin_status = t;
- /* FIXME: if USIM, set apptype */
- //card_status.applications[0] = RIL_APPTYPE_USIM
+ ipc_fmt_send_get(IPC_SEC_PIN_STATUS, reqGetId(t));
+ } else {
+ LOGE("Another request is going on, returning UNSOL data");
+
+ pin_status = &(ril_state.sim_pin_status);
+/*
+ sim_status = ipc2ril_sim_status(pin_status);
+ ril_state_update(sim_status);
+*/
+ ipc2ril_card_status(pin_status, &card_status);
+ RIL_onRequestComplete(t, RIL_E_SUCCESS, &card_status, sizeof(card_status));
}
- RIL_onRequestComplete(t, RIL_E_SUCCESS, &card_status, sizeof(card_status));
+ ril_tokens_pin_status_dump();
}
/**
@@ -302,6 +394,63 @@ void ipc_sec_rsim_access(struct ipc_message_info *info)
}
/**
+ * In: IPC_GEN_PHONE_RES
+ * Provides result of IPC_SEC_PIN_STATUS SET
+ *
+ * Out: RIL_REQUEST_ENTER_SIM_PIN
+ * Returns PIN SIM unlock result
+ */
+void ipc_sec_pin_status_complete(struct ipc_message_info *info)
+{
+ struct ipc_gen_phone_res *phone_res = (struct ipc_gen_phone_res *) info->data;
+ int rc;
+
+ int attempts = -1;
+
+ rc = ipc_gen_phone_res_check(phone_res);
+ if(rc < 0) {
+ if((phone_res->code & 0x00ff) == 0x10) {
+ LOGE("Wrong password!");
+ RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_PASSWORD_INCORRECT, &attempts, sizeof(attempts));
+ } else if((phone_res->code & 0x00ff) == 0x0c) {
+ LOGE("Wrong password and no attempts left!");
+
+ attempts = 0;
+ RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_PASSWORD_INCORRECT, &attempts, sizeof(attempts));
+
+ RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
+ } else {
+ LOGE("There was an error during pin status complete!");
+ RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_GENERIC_FAILURE, NULL, 0);
+ }
+ return;
+ }
+
+ RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_SUCCESS, &attempts, sizeof(attempts));
+}
+
+/**
+ * In: IPC_SEC_LOCK_INFO
+ * Provides number of retries left for a lock type
+ */
+void ipc_sec_lock_info(struct ipc_message_info *info)
+{
+ /*
+ * FIXME: solid way of handling lockinfo and sim unlock response together
+ * so we can return the number of attempts left in respondSecPinStatus
+ */
+ int attempts;
+ struct ipc_sec_lock_info_response *lock_info = (struct ipc_sec_lock_info_response *) info->data;
+
+ if(lock_info->type == IPC_SEC_PIN_TYPE_PIN1) {
+ attempts = lock_info->attempts;
+ LOGD("%s: PIN1 %d attempts left", __FUNCTION__, attempts);
+ } else {
+ LOGE("%s: unhandled lock type %d", __FUNCTION__, lock_info->type);
+ }
+}
+
+/**
* In: RIL_REQUEST_ENTER_SIM_PIN
* Supplies SIM PIN. Only called if RIL_CardStatus has RIL_APPSTATE_PIN state
*
@@ -325,12 +474,13 @@ void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t datalen)
ipc_sec_pin_status_set_setup(&pin_status, IPC_SEC_PIN_TYPE_PIN1, pin, NULL);
- ipc_fmt_send_set(IPC_SEC_PIN_STATUS, reqGetId(t), (unsigned char *) &pin_status, sizeof(pin_status));
-
ipc_gen_phone_res_expect_to_func(reqGetId(t), IPC_SEC_PIN_STATUS,
ipc_sec_pin_status_complete);
+ ipc_fmt_send_set(IPC_SEC_PIN_STATUS, reqGetId(t), (unsigned char *) &pin_status, sizeof(pin_status));
+
/* 2. Get lock status */
+ // FIXME: This is not clean at all
memset(buf, 0, sizeof(buf));
buf[0] = 1;
buf[1] = IPC_SEC_PIN_TYPE_PIN1;
@@ -338,49 +488,62 @@ void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t datalen)
ipc_fmt_send(IPC_SEC_LOCK_INFO, IPC_TYPE_GET, buf, sizeof(buf), reqGetId(t));
}
+void ril_request_change_sim_pin(RIL_Token t, void *data, size_t datalen)
+{
+ char *password_old = ((char **) data)[0];
+ char *password_new = ((char **) data)[1];
+ struct ipc_sec_change_locking_pw locking_pw;
-/**
- * In: IPC_GEN_PHONE_RES
- * Provides result of IPC_SEC_PIN_STATUS SET
- *
- * Out: RIL_REQUEST_ENTER_SIM_PIN
- * Returns PIN SIM unlock result
- */
-// FIXME: here, we're going to do that:
-// do the pin status req, enqueue the token to gen phone res and use this custom function (dd possibility to use custom functions on return, not only return bare requests complete with dumb RIL_E_)
-void ipc_sec_pin_status_complete(struct ipc_message_info *info)
+ memset(&locking_pw, 0, sizeof(locking_pw));
+
+ locking_pw.type = IPC_SEC_PIN_SIM_LOCK_SC;
+
+ locking_pw.length_new = strlen(password_new) > sizeof(locking_pw.password_new)
+ ? sizeof(locking_pw.password_new)
+ : strlen(password_new);
+
+ memcpy(locking_pw.password_new, password_new, locking_pw.length_new);
+
+ locking_pw.length_old = strlen(password_old) > sizeof(locking_pw.password_old)
+ ? sizeof(locking_pw.password_old)
+ : strlen(password_old);
+
+ memcpy(locking_pw.password_old, password_old, locking_pw.length_old);
+
+ ipc_gen_phone_res_expect_to_func(reqGetId(t), IPC_SEC_CHANGE_LOCKING_PW,
+ ipc_sec_pin_status_complete);
+
+ ipc_fmt_send_set(IPC_SEC_CHANGE_LOCKING_PW, reqGetId(t), (unsigned char *) &locking_pw, sizeof(locking_pw));
+}
+
+void ril_request_enter_sim_puk(RIL_Token t, void *data, size_t datalen)
{
- struct ipc_gen_phone_res *gen_res = (struct ipc_gen_phone_res *) info->data;
- int attempts = -1;
+ struct ipc_sec_pin_status_set pin_status;
+ char *puk = ((char **) data)[0];
+ char *pin = ((char **) data)[1];
- if(gen_res->code == 0x0010) {
- RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_PASSWORD_INCORRECT, &attempts, sizeof(int*));
- } else if(gen_res->code == 0x8000) {
- RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_SUCCESS, &attempts, sizeof(int*));
- } else {
- LOGE("%s: unhandled code %04x", __FUNCTION__, gen_res->code);
- }
+ ipc_sec_pin_status_set_setup(&pin_status, IPC_SEC_PIN_TYPE_PIN1, pin, puk);
+
+ ipc_gen_phone_res_expect_to_func(reqGetId(t), IPC_SEC_PIN_STATUS,
+ ipc_sec_pin_status_complete);
+
+ ipc_fmt_send_set(IPC_SEC_PIN_STATUS, reqGetId(t), (unsigned char *) &pin_status, sizeof(pin_status));
}
/**
- * In: IPC_SEC_LOCK_INFO
- * Provides number of retries left for a lock type
+ * In: IPC_SEC_PHONE_LOCK
+ *
+ * Out: RIL_REQUEST_QUERY_FACILITY_LOCK
+ * Query the status of a facility lock state
*/
-void ipc_sec_lock_info(struct ipc_message_info *info)
+void ipc_sec_phone_lock(struct ipc_message_info *info)
{
- /*
- * FIXME: solid way of handling lockinfo and sim unlock response together
- * so we can return the number of attempts left in respondSecPinStatus
- */
- int attempts;
- struct ipc_sec_lock_info_response *lock_info = (struct ipc_sec_lock_info_response *) info->data;
+ int status;
+ struct ipc_sec_phone_lock_response *lock = (struct ipc_sec_phone_lock_response *) info->data;
+
+ status = lock->status;
- if(lock_info->type == IPC_SEC_PIN_TYPE_PIN1) {
- attempts = lock_info->attempts;
- LOGD("%s: PIN1 %d attempts left", __FUNCTION__, attempts);
- } else {
- LOGE("%s: unhandled lock type %d", __FUNCTION__, lock_info->type);
- }
+ RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_SUCCESS, &status, sizeof(status));
}
/**
@@ -391,36 +554,32 @@ void ipc_sec_lock_info(struct ipc_message_info *info)
*/
void ril_request_query_facility_lock(RIL_Token t, void *data, size_t datalen)
{
- unsigned char lock_type;
- char *facility = ((char**)data)[0];
+ unsigned char lock_request;
+
+ char *facility = ((char **) data)[0];
if(!strcmp(facility, "SC")) {
- lock_type = IPC_SEC_PIN_SIM_LOCK_SC;
+ lock_request = IPC_SEC_PIN_SIM_LOCK_SC;
} else if(!strcmp(facility, "FD")) {
- lock_type = IPC_SEC_PIN_SIM_LOCK_FD;
+ lock_request = IPC_SEC_PIN_SIM_LOCK_FD;
+ } else if(!strcmp(facility, "PN")) {
+ lock_request = IPC_SEC_PIN_SIM_LOCK_PN;
+ } else if(!strcmp(facility, "PU")) {
+ lock_request = IPC_SEC_PIN_SIM_LOCK_PU;
+ } else if(!strcmp(facility, "PP")) {
+ lock_request = IPC_SEC_PIN_SIM_LOCK_PP;
+ } else if(!strcmp(facility, "PC")) {
+ lock_request = IPC_SEC_PIN_SIM_LOCK_PC;
} else {
LOGE("%s: unsupported facility: %s", __FUNCTION__, facility);
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
-
- ipc_fmt_send(IPC_SEC_PHONE_LOCK, IPC_TYPE_GET, &lock_type, sizeof(lock_type), reqGetId(t));
+ ipc_fmt_send(IPC_SEC_PHONE_LOCK, IPC_TYPE_GET, &lock_request, sizeof(lock_request), reqGetId(t));
}
-/**
- * In: IPC_SEC_PHONE_LOCK
- *
- * Out: RIL_REQUEST_QUERY_FACILITY_LOCK
- * Query the status of a facility lock state
- */
-void ipc_sec_phone_lock(struct ipc_message_info *info)
-{
- int status;
- struct ipc_sec_phone_lock_response *lock = (struct ipc_sec_phone_lock_response *) info->data;
-
- status = lock->status;
-
- RIL_onRequestComplete(reqGetToken(info->aseq), RIL_E_SUCCESS, &status, sizeof(int*));
-}
+// Both functions were the same
+#define ipc_sec_phone_lock_complete \
+ ipc_sec_pin_status_complete
/**
* In: RIL_REQUEST_SET_FACILITY_LOCK
@@ -430,17 +589,41 @@ void ipc_sec_phone_lock(struct ipc_message_info *info)
*/
void ril_request_set_facility_lock(RIL_Token t, void *data, size_t datalen)
{
- unsigned char lock_type;
- char *facility = ((char**)data)[0];
+ struct ipc_sec_phone_lock_request lock_request;
+
+ char *facility = ((char **) data)[0];
+ char *lock = ((char **) data)[1];
+ char *password = ((char **) data)[2];
+ char *class = ((char **) data)[3];
+
+ memset(&lock_request, 0, sizeof(lock_request));
if(!strcmp(facility, "SC")) {
- lock_type = IPC_SEC_PIN_SIM_LOCK_SC;
+ lock_request.type = IPC_SEC_PIN_SIM_LOCK_SC;
} else if(!strcmp(facility, "FD")) {
- lock_type = IPC_SEC_PIN_SIM_LOCK_FD;
+ lock_request.type = IPC_SEC_PIN_SIM_LOCK_FD;
+ } else if(!strcmp(facility, "PN")) {
+ lock_request.type = IPC_SEC_PIN_SIM_LOCK_PN;
+ } else if(!strcmp(facility, "PU")) {
+ lock_request.type = IPC_SEC_PIN_SIM_LOCK_PU;
+ } else if(!strcmp(facility, "PP")) {
+ lock_request.type = IPC_SEC_PIN_SIM_LOCK_PP;
+ } else if(!strcmp(facility, "PC")) {
+ lock_request.type = IPC_SEC_PIN_SIM_LOCK_PC;
} else {
LOGE("%s: unsupported facility: %s", __FUNCTION__, facility);
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
- ipc_fmt_send(IPC_SEC_PHONE_LOCK, IPC_TYPE_GET, &lock_type, sizeof(lock_type), reqGetId(t));
+ lock_request.lock = lock[0] == '1' ? 1 : 0;
+ lock_request.length = strlen(password) > sizeof(lock_request.password)
+ ? sizeof(lock_request.password)
+ : strlen(password);
+
+ memcpy(lock_request.password, password, lock_request.length);
+
+ ipc_gen_phone_res_expect_to_func(reqGetId(t), IPC_SEC_PHONE_LOCK,
+ ipc_sec_phone_lock_complete);
+
+ ipc_fmt_send(IPC_SEC_PHONE_LOCK, IPC_TYPE_SET, &lock_request, sizeof(lock_request), reqGetId(t));
}