From c1f957396d148f9f20f2828067b6c9e97b584247 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Tue, 31 Jul 2012 00:30:29 +0200 Subject: [PATCH] SIM: Added SIM IO support Signed-off-by: Paul Kocialkowski --- sim.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/sim.c b/sim.c index 2d39a78..a7ef1c1 100644 --- a/sim.c +++ b/sim.c @@ -274,3 +274,79 @@ void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t length) at_send_expect_to_func("AT+CPIN", pin, NULL, t, at_cpin_unlock_expect); } + +int at_crsm_expect(struct at_response *response, void *data, RIL_Token t) +{ + RIL_SIM_IO_Response sim_io_response; + struct at_response_data **response_data = NULL; + int response_data_count = 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+CRSM response!"); + return AT_RESPONSE_HANDLED_ERROR; + } + + LOGE("Caught valid +CRSM response!"); + + response_data_count = at_response_data_process(&response_data, response->data[0], strlen(response->data[0])); + if(response_data_count < 3) + goto error_data; + + memset(&sim_io_response, 0, sizeof(RIL_SIM_IO_Response)); + + if(response_data[0]->type != AT_RESPONSE_DATA_NUMERIC) + goto error_data; + sim_io_response.sw1 = response_data[0]->value.n; + + if(response_data[1]->type != AT_RESPONSE_DATA_NUMERIC) + goto error_data; + sim_io_response.sw2 = response_data[1]->value.n; + + if(response_data[2]->type != AT_RESPONSE_DATA_STRING) + goto error_data; + sim_io_response.simResponse = response_data[2]->value.s; + + RIL_onRequestComplete(t, RIL_E_SUCCESS, &sim_io_response, sizeof(RIL_SIM_IO_Response)); + + at_response_data_free(response_data, response_data_count); + + return AT_RESPONSE_HANDLED_OK; + +error_data: + LOGE("No valid data fiven to AT+CRSM response!"); + + at_response_data_free(response_data, response_data_count); + return AT_RESPONSE_HANDLED_ERROR; +} + +void ril_request_sim_io(RIL_Token t, void *data, size_t length) +{ + RIL_SIM_IO *sim_io_request = NULL; + char *sim_io_data; + + if(data == NULL || length <= 0) { + RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); + return; + } + + sim_io_request = (RIL_SIM_IO *) data; + + // TODO: add delay if SIM is slow (from device flags) + + if(sim_io_request->data == NULL) { + asprintf(&sim_io_data, "%d,%d,%d,%d,%d", + sim_io_request->command, sim_io_request->fileid, + sim_io_request->p1, sim_io_request->p2, sim_io_request->p3); + } else { + asprintf(&sim_io_data, "%d,%d,%d,%d,%d,%s", + sim_io_request->command, sim_io_request->fileid, + sim_io_request->p1, sim_io_request->p2, sim_io_request->p3, sim_io_request->data); + } + + at_send_expect_to_func("AT+CRSM", sim_io_data, NULL, t, at_crsm_expect); + + free(sim_io_data); +} -- 2.11.0