diff options
Diffstat (limited to 'samsung-ril.c')
-rw-r--r-- | samsung-ril.c | 253 |
1 files changed, 172 insertions, 81 deletions
diff --git a/samsung-ril.c b/samsung-ril.c index 84e3074..aaeedeb 100644 --- a/samsung-ril.c +++ b/samsung-ril.c @@ -23,8 +23,8 @@ #define LOG_TAG "RIL" #include <utils/Log.h> -#include <telephony/ril.h> +#include <ril-versions-compat.h> #include <samsung-ril.h> #include <utils.h> @@ -121,7 +121,7 @@ struct ipc_dispatch_handler ipc_fmt_dispatch_handlers[] = { .handler = ipc_sec_sim_icc_type, }, { - .command = IPC_SEC_LOCK_INFOMATION, + .command = IPC_SEC_LOCK_INFORMATION, .handler = ipc_sec_lock_infomation, }, /* Network */ @@ -208,8 +208,8 @@ struct ipc_dispatch_handler ipc_fmt_dispatch_handlers[] = { }, }; -unsigned int ipc_fmt_dispatch_handlers_count = sizeof(ipc_fmt_dispatch_handlers) / - sizeof(struct ipc_dispatch_handler); +unsigned int ipc_fmt_dispatch_handlers_count = + sizeof(ipc_fmt_dispatch_handlers) / sizeof(struct ipc_dispatch_handler); struct ipc_dispatch_handler ipc_rfs_dispatch_handlers[] = { { @@ -222,8 +222,8 @@ struct ipc_dispatch_handler ipc_rfs_dispatch_handlers[] = { }, }; -unsigned int ipc_rfs_dispatch_handlers_count = sizeof(ipc_rfs_dispatch_handlers) / - sizeof(struct ipc_dispatch_handler); +unsigned int ipc_rfs_dispatch_handlers_count = + sizeof(ipc_rfs_dispatch_handlers) / sizeof(struct ipc_dispatch_handler); struct srs_dispatch_handler srs_dispatch_handlers[] = { { @@ -520,7 +520,9 @@ list_continue: list = list->next; } - RIL_LOGD("%d RIL request%s in the queue (%d pending, %d handled, %d unhandled)", count, count > 1 ? "s" : "", pending, handled, unhandled); + RIL_LOGD("%d RIL request%s in the queue" + " (%d pending, %d handled, %d unhandled)", + count, count > 1 ? "s" : "", pending, handled, unhandled); count = 0; @@ -532,7 +534,8 @@ list_continue: } if (count > 0) - RIL_LOGD("%d RIL request%s data in the queue", count, count > 1 ? "s" : ""); + RIL_LOGD("%d RIL request%s data in the queue", count, + count > 1 ? "s" : ""); RIL_REQUEST_UNLOCK(); @@ -551,7 +554,8 @@ int ril_request_register(int request, void *data, size_t size, RIL_Token token) RIL_REQUEST_LOCK(); - ril_request = (struct ril_request *) calloc(1, sizeof(struct ril_request)); + ril_request = (struct ril_request *) calloc(1, + sizeof(struct ril_request)); ril_request->request = request; ril_request->data = NULL; ril_request->size = size; @@ -598,7 +602,8 @@ int ril_request_unregister(struct ril_request *request) if (ril_clients[i] == NULL) continue; - ril_client_request_unregister(ril_clients[i], request->request, request->token); + ril_client_request_unregister(ril_clients[i], request->request, + request->token); } list = ril_data->requests; @@ -710,7 +715,8 @@ struct ril_request *ril_request_find_request_status(int request, int status) ril_request = (struct ril_request *) list->data; - if (ril_request->request == request && ril_request->status == status) { + if (ril_request->request == request && + ril_request->status == status) { RIL_REQUEST_UNLOCK(); return ril_request; } @@ -822,7 +828,8 @@ int ril_request_complete(RIL_Token token, RIL_Errno error, void *data, { struct ril_request *request; - if (ril_data == NULL || ril_data->env == NULL || ril_data->env->OnRequestComplete == NULL) + if (ril_data == NULL || ril_data->env == NULL || + ril_data->env->OnRequestComplete == NULL) return -1; if (token == NULL) @@ -846,7 +853,8 @@ complete: int ril_request_unsolicited(int request, void *data, size_t size) { - if (ril_data == NULL || ril_data->env == NULL || ril_data->env->OnUnsolicitedResponse == NULL) + if (ril_data == NULL || ril_data->env == NULL || + ril_data->env->OnUnsolicitedResponse == NULL) return -1; ril_data->env->OnUnsolicitedResponse(request, data, size); @@ -857,7 +865,8 @@ int ril_request_unsolicited(int request, void *data, size_t size) int ril_request_timed_callback(RIL_TimedCallback callback, void *data, const struct timeval *time) { - if (ril_data == NULL || ril_data->env == NULL || ril_data->env->RequestTimedCallback == NULL) + if (ril_data == NULL || ril_data->env == NULL || + ril_data->env->RequestTimedCallback == NULL) return -1; ril_data->env->RequestTimedCallback(callback, data, time); @@ -878,7 +887,8 @@ int ril_request_dispatch(struct ril_request *request) continue; if (ril_request_handlers[i].request == request->request) { - status = ril_request_handlers[i].handler(request->data, request->size, request->token); + status = ril_request_handlers[i].handler( + request->data, request->size, request->token); switch (status) { case RIL_REQUEST_PENDING: case RIL_REQUEST_HANDLED: @@ -888,7 +898,10 @@ int ril_request_dispatch(struct ril_request *request) case RIL_REQUEST_COMPLETED: break; default: - RIL_LOGE("Handling RIL request %d failed", request->request); + RIL_LOGE( + "Handling RIL request %d" + " failed", + request->request); return -1; } @@ -897,7 +910,8 @@ int ril_request_dispatch(struct ril_request *request) } RIL_LOGD("Unhandled RIL request: %d", request->request); - ril_request_complete(request->token, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0); + ril_request_complete(request->token, RIL_E_REQUEST_NOT_SUPPORTED, NULL, + 0); return 0; } @@ -915,14 +929,15 @@ void *ril_request_loop(__attribute__((unused)) void *data) RIL_LOCK(); - rc = ril_radio_state_check(RADIO_STATE_OFF); + rc = ril_radio_has_reached_state(RADIO_STATE_OFF); if (rc < 0) { RIL_UNLOCK(); continue; } do { - request = ril_request_find_status(RIL_REQUEST_UNHANDLED); + request = ril_request_find_status( + RIL_REQUEST_UNHANDLED); if (request == NULL) break; @@ -958,7 +973,8 @@ int ril_request_data_register(int request, void *data, size_t size) if (data == NULL || ril_data == NULL) return -1; - request_data = (struct ril_request_data *) calloc(1, sizeof(struct ril_request_data)); + request_data = (struct ril_request_data *) calloc( + 1, sizeof(struct ril_request_data)); request_data->request = request; request_data->data = data; request_data->size = size; @@ -985,7 +1001,8 @@ int ril_request_data_unregister(struct ril_request_data *request_data) list = ril_data->requests_data; while (list != NULL) { if (list->data == (void *) request_data) { - memset(request_data, 0, sizeof(struct ril_request_data)); + memset(request_data, 0, + sizeof(struct ril_request_data)); free(request_data); if (list == ril_data->requests_data) @@ -1016,10 +1033,12 @@ int ril_request_data_flush(void) if (list->data != NULL) { request_data = (struct ril_request_data *) list->data; - if (request_data->data != NULL && request_data->size > 0) + if (request_data->data != NULL && + request_data->size > 0) free(request_data->data); - memset(request_data, 0, sizeof(struct ril_request_data)); + memset(request_data, 0, + sizeof(struct ril_request_data)); free(request_data); } @@ -1155,7 +1174,8 @@ int ril_radio_state_update(RIL_RadioState radio_state) RIL_LOGD("Updating RIL radio state to %d", radio_state); ril_data->radio_state = radio_state; - ril_request_unsolicited(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, 0); + ril_request_unsolicited(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, NULL, + 0); switch (ril_data->radio_state) { case RADIO_STATE_UNAVAILABLE: @@ -1164,7 +1184,10 @@ int ril_radio_state_update(RIL_RadioState radio_state) if (request == NULL) break; - ril_request_complete(request->token, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); + ril_request_complete(request->token, + RIL_E_RADIO_NOT_AVAILABLE, + NULL, + 0); ril_request_unregister(request); } while (request != NULL); @@ -1183,10 +1206,15 @@ int ril_radio_state_update(RIL_RadioState radio_state) case RADIO_STATE_OFF: ril_data_connection_flush(); - ril_request_unsolicited(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, NULL, 0); - ril_request_unsolicited(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0); - ril_request_unsolicited(RIL_UNSOL_DATA_CALL_LIST_CHANGED, NULL, 0); - ril_request_unsolicited(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0); + ril_request_unsolicited( + RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, NULL, 0); + ril_request_unsolicited( + RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, + NULL, 0); + ril_request_unsolicited( + RIL_UNSOL_DATA_CALL_LIST_CHANGED, NULL, 0); + ril_request_unsolicited( + RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0); break; default: RIL_REQUEST_LOOP_UNLOCK(); @@ -1196,38 +1224,82 @@ int ril_radio_state_update(RIL_RadioState radio_state) return 0; } -int ril_radio_state_check(RIL_RadioState radio_state) +/* + * RIL SIM state + */ + +int ril_sim_state_update(enum sim_state sim_state) +{ + if (ril_data == NULL) + return -1; + + if (ril_data->sim_state == sim_state) + return 0; + + RIL_LOGD("Updating RIL SIM state to %d", sim_state); + + ril_data->sim_state = sim_state; + + ril_request_unsolicited(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0); + + return 0; +} + +/* + * Returns 0 if the RIL has reached the given radio_state + * Returns -1 otherwise + */ +int ril_radio_has_reached_state(RIL_RadioState given_state) { RIL_RadioState radio_states[] = { - RADIO_STATE_UNAVAILABLE, RADIO_STATE_OFF, + RADIO_STATE_UNAVAILABLE, RADIO_STATE_ON, - RADIO_STATE_NV_NOT_READY, - RADIO_STATE_NV_READY, - RADIO_STATE_SIM_NOT_READY, - RADIO_STATE_SIM_LOCKED_OR_ABSENT, - RADIO_STATE_SIM_READY, }; - unsigned int index; - unsigned int count; + + RIL_RadioState curr_state; + + unsigned int curr_state_index; + unsigned int given_state_index; + unsigned int radio_states_count; unsigned int i; if (ril_data == NULL) return -1; - count = sizeof(radio_states) / sizeof(RIL_RadioState); + curr_state = ril_data->radio_state; + radio_states_count = sizeof(radio_states) / sizeof(RIL_RadioState); - for (i = 0; i < count; i++) - if (radio_states[i] == radio_state) + for (i = 0; i < radio_states_count; i++) + if (radio_states[i] == given_state) break; + given_state_index = i; - index = i; - - for (i = 0; i < count; i++) - if (radio_states[i] == ril_data->radio_state) + for (i = 0; i < radio_states_count; i++) + if (radio_states[i] == curr_state) break; + curr_state_index = i; - if (i < index) + if (curr_state_index < given_state_index) + return -1; + + return 0; +} + +/* + * Returns 0 if the RIL has reached the given sim_state + * Returns -1 otherwise + */ +int ril_sim_has_reached_state(enum sim_state given_state) +{ + enum sim_state curr_state; + + if (ril_data == NULL) + return -1; + + curr_state = ril_data->sim_state; + + if (curr_state < given_state) return -1; return 0; @@ -1295,7 +1367,8 @@ void ril_on_request(int request, void *data, size_t size, RIL_Token token) memcpy(buffer, data, size); if (((RIL_Dial *) data)->address != NULL) - ((RIL_Dial *) buffer)->address = strdup(((RIL_Dial *) data)->address); + ((RIL_Dial *) buffer)->address = strdup( + ((RIL_Dial *) data)->address); data = buffer; break; @@ -1309,10 +1382,12 @@ void ril_on_request(int request, void *data, size_t size, RIL_Token token) memcpy(buffer, data, size); if (((RIL_SMS_WriteArgs *) data)->pdu != NULL) - ((RIL_SMS_WriteArgs *) buffer)->pdu = strdup(((RIL_SMS_WriteArgs *) data)->pdu); + ((RIL_SMS_WriteArgs *) buffer)->pdu = strdup( + ((RIL_SMS_WriteArgs *) data)->pdu); if (((RIL_SMS_WriteArgs *) data)->smsc != NULL) - ((RIL_SMS_WriteArgs *) buffer)->smsc = strdup(((RIL_SMS_WriteArgs *) data)->smsc); + ((RIL_SMS_WriteArgs *) buffer)->smsc = strdup( + ((RIL_SMS_WriteArgs *) data)->smsc); data = buffer; break; @@ -1329,38 +1404,28 @@ void ril_on_request(int request, void *data, size_t size, RIL_Token token) strings_count = size / sizeof(char *); break; case RIL_REQUEST_SIM_IO: -#if RIL_VERSION >= 6 - if (data == NULL || size < sizeof(RIL_SIM_IO_v6)) -#else - if (data == NULL || size < sizeof(RIL_SIM_IO)) -#endif + if (data == NULL || size < sizeof(RIL_SIM_IO_compat)) break; buffer = calloc(1, size); memcpy(buffer, data, size); -#if RIL_VERSION >= 6 - if (((RIL_SIM_IO_v6 *) data)->path != NULL) - ((RIL_SIM_IO_v6 *) buffer)->path = strdup(((RIL_SIM_IO_v6 *) data)->path); - - if (((RIL_SIM_IO_v6 *) data)->data != NULL) - ((RIL_SIM_IO_v6 *) buffer)->data = strdup(((RIL_SIM_IO_v6 *) data)->data); + if (((RIL_SIM_IO_compat *) data)->path != NULL) + ((RIL_SIM_IO_compat *) buffer)->path = strdup( + ((RIL_SIM_IO_compat *) data)->path); - if (((RIL_SIM_IO_v6 *) data)->pin2 != NULL) - ((RIL_SIM_IO_v6 *) buffer)->pin2 = strdup(((RIL_SIM_IO_v6 *) data)->pin2); + if (((RIL_SIM_IO_compat *) data)->data != NULL) + ((RIL_SIM_IO_compat *) buffer)->data = strdup( + ((RIL_SIM_IO_compat *) data)->data); - if (((RIL_SIM_IO_v6 *) data)->aidPtr != NULL) - ((RIL_SIM_IO_v6 *) buffer)->aidPtr = strdup(((RIL_SIM_IO_v6 *) data)->aidPtr); -#else - if (((RIL_SIM_IO *) data)->path != NULL) - ((RIL_SIM_IO *) buffer)->path = strdup(((RIL_SIM_IO *) data)->path); - - if (((RIL_SIM_IO *) data)->data != NULL) - ((RIL_SIM_IO *) buffer)->data = strdup(((RIL_SIM_IO *) data)->data); - - if (((RIL_SIM_IO *) data)->pin2 != NULL) - ((RIL_SIM_IO *) buffer)->pin2 = strdup(((RIL_SIM_IO *) data)->pin2); + if (((RIL_SIM_IO_compat *) data)->pin2 != NULL) + ((RIL_SIM_IO_compat *) buffer)->pin2 = strdup( + ((RIL_SIM_IO_compat *) data)->pin2); +#if RIL_VERSION >= 6 + if (((RIL_SIM_IO_compat *) data)->aidPtr != NULL) + ((RIL_SIM_IO_compat *) buffer)->aidPtr = strdup + (((RIL_SIM_IO_compat *) data)->aidPtr); #endif data = buffer; @@ -1379,13 +1444,16 @@ void ril_on_request(int request, void *data, size_t size, RIL_Token token) if (i > 0 && c[i] == '\0') { size = i + 1; - RIL_LOGD("Detected string with a size of %d byte%s", size, size > 0 ? "s" : ""); + RIL_LOGD("Detected string with a size of %d " + "byte%s", + size, size > 0 ? "s" : ""); } break; } - if (strings_count > 0 && data != NULL && size >= strings_count * sizeof(char *)) { + if (strings_count > 0 && data != NULL && + size >= strings_count * sizeof(char *)) { buffer = calloc(1, size); for (i = 0; i < strings_count; i++) { @@ -1477,12 +1545,17 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, unsigned int i; int rc; - if (env == NULL) + RIL_LOGD("libsamsung-ril: Started from %s\n", __func__); + + if (env == NULL) { + RIL_LOGE("%s: Aborting: Invalid RIL_Env (RIL_Env is NULL)", + __func__); return NULL; + } rc = ril_data_create(); if (rc < 0) { - RIL_LOGE("Creating RIL data failed"); + RIL_LOGE("%s: Creating RIL data failed", __func__); return NULL; } @@ -1491,17 +1564,26 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, ril_data->env = env; for (i = 0; i < ril_clients_count; i++) { - if (ril_clients[i] == NULL) + if (ril_clients[i] == NULL) { + RIL_LOGD("%s: Skipping ril_client_create " + "due to Invalid client (client is NULL)", + __func__); continue; + } rc = ril_client_create(ril_clients[i]); if (rc < 0) + /* ril_client_create already prints an error if it fails */ goto error; } for (i = 0; i < ril_clients_count; i++) { - if (ril_clients[i] == NULL) + if (ril_clients[i] == NULL) { + RIL_LOGD("%s: Skipping ril_client_open " + "due to Invalid client (client is NULL)", + __func__); continue; + } failures = 0; @@ -1513,18 +1595,27 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, } } while (rc < 0 && failures < RIL_CLIENT_RETRY_COUNT); - if (rc < 0) + if (rc < 0) { + RIL_LOGD("%s: " + "gave up trying to open the %s client " + "after %d retries", + __func__, + (ril_clients[i])->name, + RIL_CLIENT_RETRY_COUNT); goto error; + } rc = ril_client_loop(ril_clients[i]); if (rc < 0) + /* ril_client_loop already prints an error if it fails */ goto error; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - rc = pthread_create(&ril_data->request_thread, &attr, ril_request_loop, NULL); + rc = pthread_create(&ril_data->request_thread, &attr, ril_request_loop, + NULL); if (rc != 0) { RIL_LOGE("Starting request loop failed"); goto error; |