diff options
author | PaulK <contact@paulk.fr> | 2011-12-21 21:54:03 +0100 |
---|---|---|
committer | PaulK <contact@paulk.fr> | 2011-12-21 21:54:03 +0100 |
commit | 0091ceae5f7cbeeb42e3b43de3dcf8e500fe8752 (patch) | |
tree | dff5b107e7c51dcbb71d636fd6189d3570881a39 /samsung-ril.c | |
parent | cb295e0a15c8bc5087a542f25bc369aecbecde80 (diff) | |
download | hardware_replicant_libsamsung-ril-0091ceae5f7cbeeb42e3b43de3dcf8e500fe8752.tar.gz hardware_replicant_libsamsung-ril-0091ceae5f7cbeeb42e3b43de3dcf8e500fe8752.tar.bz2 hardware_replicant_libsamsung-ril-0091ceae5f7cbeeb42e3b43de3dcf8e500fe8752.zip |
RIL rework: multi-client, more stable, added GPLv3 copyright notice
Diffstat (limited to 'samsung-ril.c')
-rw-r--r-- | samsung-ril.c | 696 |
1 files changed, 321 insertions, 375 deletions
diff --git a/samsung-ril.c b/samsung-ril.c index d2b4df3..a457b45 100644 --- a/samsung-ril.c +++ b/samsung-ril.c @@ -1,486 +1,426 @@ -#include <time.h> - -#include <telephony/ril.h> +/** + * 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> + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * samsung-ril is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with samsung-ril. If not, see <http://www.gnu.org/licenses/>. + * + */ -#include <samsung-ril-socket.h> -#include <radio.h> -#include <util.h> +#include <time.h> +#include <pthread.h> #define LOG_TAG "RIL" #include <utils/Log.h> +#include <telephony/ril.h> -#include "socket.h" #include "samsung-ril.h" #include "util.h" #define RIL_VERSION_STRING "Samsung RIL" -const struct RIL_Env *rilenv; -struct radio_state radio; +/** + * Samsung-RIL TODO: + * - add IPC_NET_SERVING_NETWORK + * - client prefix first: ipc2ril_reg_state + * - all these functions on the top + * - use checked function before returning a token to RILJ + */ -struct ipc_client *ipc_client; -struct srs_server *srs_server; -int client_fmt_fd = -1; +/** + * RIL global vars + */ -/* - * Token-related function +struct ril_client *ipc_fmt_client; +struct ril_client *ipc_rfs_client; +struct ril_client *srs_client; + +const struct RIL_Env *ril_env; +struct ril_state ril_state; + +/** + * RIL request token */ -/* Tokens associated with requests */ -RIL_Token request_ids[256]; -int rid = 0; +struct ril_request_token ril_requests_tokens[0x100]; +int ril_request_id = 0; -void read_loop_thread(); +int ril_request_id_new(void) +{ + ril_request_id++; + ril_request_id %= 0x100; + return ril_request_id; +} -int getRequestId(RIL_Token token) +int ril_request_reg_id(RIL_Token token) { - int id = (rid++ % 0x7E); //fixme - request_ids[id] = token; + int id = ril_request_id_new(); - //LOGD("Assigned request id token=%08X id=%02X\n", token, id); + ril_requests_tokens[id].token = token; + ril_requests_tokens[id].canceled = 0; return id; } -void setToken(int id, RIL_Token token) +int ril_request_get_id(RIL_Token token) +{ + int i; + + for(i=0 ; i < 0x100 ; i++) + if(ril_requests_tokens[i].token == token) + return i; + + // If the token isn't registered yet, register it + return ril_request_reg_id(token); +} + +RIL_Token ril_request_get_token(int id) { - request_ids[id] = token; + return ril_requests_tokens[id].token; } -RIL_Token getToken(int id) +int ril_request_is_valid(RIL_Token token) { - //LOGD("Got token=%08X id=%02X\n", request_ids[id], id); - return request_ids[id]; + int id; + + id = ril_request_get_id(token); + + if(ril_requests_tokens[id].canceled > 0) + return 1; + else + return 0; } -void RadioTokensCheck(void) +/** + * RIL tokens + */ + +void ril_tokens_check(void) { - if(radio.tokens.baseband_version != 0) { - if(radio.radio_state != RADIO_STATE_OFF) { - requestBasebandVersion(radio.tokens.baseband_version); - radio.tokens.baseband_version = 0; + if(ril_state.tokens.baseband_version != 0) { + if(ril_state.radio_state != RADIO_STATE_OFF) { + ril_request_baseband_version(ril_state.tokens.baseband_version); + ril_state.tokens.baseband_version = 0; } } - if(radio.tokens.get_imei != 0) { - if(radio.radio_state != RADIO_STATE_OFF) { - requestIMEI(radio.tokens.get_imei); - radio.tokens.get_imei = 0; + if(ril_state.tokens.get_imei != 0) { + if(ril_state.radio_state != RADIO_STATE_OFF) { + ril_request_get_imei(ril_state.tokens.get_imei); + ril_state.tokens.get_imei = 0; } } } -/* - * RILJ (RIL to modem) related functions +/** + * Clients dispatch functions */ -void onRequest(int request, void *data, size_t datalen, RIL_Token t) +void respondGenPhonRes(struct ipc_message_info *info) { - //LOGD("%s: start %d %08X", __FUNCTION__, request, t); -/* - if(radio.tokens.radio_power != 0) { - RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); - return; + struct ipc_gen_phone_res *gen_res = (struct ipc_gen_phone_res*)info->data; + unsigned short msg_type = ((gen_res->group << 8) | gen_res->type); + + if(msg_type == IPC_SEC_PIN_STATUS) { + ipc_sec_pin_status_res(info); + } else { + LOGD("%s: unhandled generic response for msg %04x", __FUNCTION__, msg_type); } -*/ - switch(request) { - case RIL_REQUEST_RADIO_POWER: - requestPower(t, data, datalen); - break; - case RIL_REQUEST_BASEBAND_VERSION: - requestBasebandVersion(t); - break; - case RIL_REQUEST_GET_IMSI: - requestIMSI(t); +} + +void ipc_fmt_dispatch(struct ipc_message_info *info) +{ + switch(IPC_COMMAND(info)) { + /* PWR */ + case IPC_PWR_PHONE_PWR_UP: + ipc_pwr_phone_pwr_up(); break; - case RIL_REQUEST_GET_IMEI: - requestIMEI(t); + case IPC_PWR_PHONE_STATE: + ipc_pwr_phone_state(info); break; - case RIL_REQUEST_GET_IMEISV: - requestIMEISV(t); + /* DISP */ + case IPC_DISP_ICON_INFO: + ipc_disp_icon_info(info); break; - case RIL_REQUEST_OPERATOR: - requestOperator(t); + case IPC_DISP_RSSI_INFO: + ipc_disp_rssi_info(info); break; - case RIL_REQUEST_REGISTRATION_STATE: - requestRegistrationState(t); + /* MISC */ + case IPC_MISC_ME_SN: + ipc_misc_me_sn(info); break; - case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: - requestGetPreferredNetworkType(t); + case IPC_MISC_ME_VERSION: + ipc_misc_me_version(info); break; - case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: - requestSetPreferredNetworkType(t, data, datalen); + case IPC_MISC_ME_IMSI: + ipc_misc_me_imsi(info); break; - case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: - requestNwSelectionMode(t); + case IPC_MISC_TIME_INFO: + ipc_misc_time_info(info); break; - case RIL_REQUEST_GPRS_REGISTRATION_STATE: - requestGPRSRegistrationState(t); + /* SAT */ + case IPC_SAT_PROACTIVE_CMD: + respondSatProactiveCmd(info); break; - case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: - requestAvailNetworks(t); + case IPC_SAT_ENVELOPE_CMD: + respondSatEnvelopeCmd(info); break; - case RIL_REQUEST_DIAL: - requestDial(t, data, datalen); + /* SIM */ + case IPC_SEC_PIN_STATUS: + ipc_sec_pin_status(info); break; - case RIL_REQUEST_GET_CURRENT_CALLS: - requestGetCurrentCalls(t); + case IPC_SEC_LOCK_INFO: + ipc_sec_lock_info(info); break; - case RIL_REQUEST_HANGUP: - case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: - case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: - requestHangup(t); + case IPC_SEC_RSIM_ACCESS: + ipc_sec_rsim_access(info); break; - case RIL_REQUEST_ANSWER: - requestAnswer(t); + case IPC_SEC_PHONE_LOCK: + ipc_sec_phone_lock(info); break; - case RIL_REQUEST_DTMF_START: - requestDtmfStart(t, data, datalen); - break; - case RIL_REQUEST_DTMF_STOP: - requestDtmfStop(t); - break; - case RIL_REQUEST_SEND_SMS: - requestSendSms(t, data, datalen); + /* NET */ + case IPC_NET_CURRENT_PLMN: + ipc_net_current_plmn(info); break; - case RIL_REQUEST_SEND_SMS_EXPECT_MORE: - requestSendSmsExpectMore(t, data, datalen); + case IPC_NET_REGIST: + ipc_net_regist(info); break; - case RIL_REQUEST_SMS_ACKNOWLEDGE: - requestSmsAcknowledge(t, data, datalen); + case IPC_NET_PLMN_LIST: + ipc_net_plmn_list(info); break; - case RIL_REQUEST_GET_SIM_STATUS: - requestSimStatus(t); + case IPC_NET_MODE_SEL: + ipc_net_mode_sel(info); break; - case RIL_REQUEST_SIM_IO: - requestSimIo(t, data, datalen); + /* SMS */ + case IPC_SMS_INCOMING_MSG: + ipc_sms_incoming_msg(info); break; - case RIL_REQUEST_ENTER_SIM_PIN: - requestEnterSimPin(t, data, datalen); + case IPC_SMS_DELIVER_REPORT: + ipc_sms_deliver_report(info); break; - case RIL_REQUEST_QUERY_FACILITY_LOCK: - requestQueryFacilityLock(t, data, datalen); + case IPC_SMS_SVC_CENTER_ADDR: + ipc_sms_svc_center_addr(info); break; - case RIL_REQUEST_SET_FACILITY_LOCK: - requestSetFacilityLock(t, data, datalen); + case IPC_SMS_SEND_MSG: + ipc_sms_send_msg(info); break; - case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: - requestSatSendTerminalResponse(t, data, datalen); + case IPC_SMS_DEVICE_READY: + ipc_sms_device_ready(info); break; - case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: - requestSatSendEnvelopeCommand(t, data, datalen); + /* CALL */ + case IPC_CALL_INCOMING: + ipc_call_incoming(info); break; - case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: - RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); + case IPC_CALL_LIST: + ipc_call_list(info); break; - case RIL_REQUEST_SCREEN_STATE: - /* This doesn't affect anything */ - RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); + case IPC_CALL_STATUS: + ipc_call_status(info); break; + /* OTHER */ + case IPC_GEN_PHONE_RES: +// respondGenPhonRes(info); + break; default: - LOGE("Request not implemented: %d\n", request); - RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0); + LOGD("Unknown msgtype: %04x", info->type); break; } } -RIL_RadioState currentState() -{ - return radio.radio_state; -} - -int onSupports(int requestCode) +void srs_dispatch(struct srs_message *message) { - switch(requestCode) { - default: - return 1; + switch(message->command) { + case SRS_CONTROL_PING: + srs_control_ping(message); + break; + case SRS_SND_SET_CALL_CLOCK_SYNC: + srs_snd_set_call_clock_sync(message); + break; } } -void onCancel(RIL_Token t) -{ - /* Todo */ -} +/* + * RIL main dispatch function + */ -const char *getVersion(void) +int ril_modem_check(void) { - return RIL_VERSION_STRING; -} + if(ipc_fmt_client == NULL) + return -1; -void respondGenPhonRes(struct ipc_message_info *info) -{ - struct ipc_gen_phone_res *gen_res = (struct ipc_gen_phone_res*)info->data; - unsigned short msg_type = ((gen_res->group << 8) | gen_res->type); + if(ipc_fmt_client->state != RIL_CLIENT_READY) + return -1; - if(msg_type == IPC_SEC_PIN_STATUS) { - respondSecPinStatus(info); - } else { - LOGD("%s: unhandled generic response for msg %04x", __FUNCTION__, msg_type); - } + return 0; } -/** - * libsamsung-ipc (modem to RIL) related functions - */ - -void onReceive(struct ipc_message_info *info) +void onRequest(int request, void *data, size_t datalen, RIL_Token t) { - /* FIXME: This _needs_ to be moved to each individual function. Unsollicited calls do not have a token! */ - RIL_Token t = getToken(info->aseq); - - // TODO: add IPC_NET_SERVING_NETWORK + if(ril_modem_check() < 0) + RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); - switch(IPC_COMMAND(info)) { - case IPC_PWR_PHONE_PWR_UP: - respondPowerUp(); + switch(request) { + /* PWR */ + case RIL_REQUEST_RADIO_POWER: + ril_request_radio_power(t, data, datalen); break; - case IPC_PWR_PHONE_STATE: - respondPowerPhoneState(info); + case RIL_REQUEST_BASEBAND_VERSION: + ril_request_baseband_version(t); break; - case IPC_MISC_ME_VERSION: - respondBasebandVersion(info); + /* MISC */ + case RIL_REQUEST_GET_IMEI: + ril_request_get_imei(t); break; - case IPC_MISC_ME_IMSI: - respondIMSI(info); + case RIL_REQUEST_GET_IMEISV: + ril_request_get_imeisv(t); break; - case IPC_MISC_ME_SN: - respondMeSn(t, info->data, info->length); + case RIL_REQUEST_GET_IMSI: + ril_request_get_imsi(t); break; - case IPC_MISC_TIME_INFO: - respondNitz(info->data, info->length); + /* SAT */ + case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: + requestSatSendTerminalResponse(t, data, datalen); break; - case IPC_NET_CURRENT_PLMN: - respondOperator(info); + case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: + requestSatSendEnvelopeCommand(t, data, datalen); break; - case IPC_NET_PLMN_LIST: - respondAvailNetworks(t, info->data, info->length); + case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: + RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); break; - case IPC_NET_REGIST: - respondNetRegist(info); + /* SIM */ + case RIL_REQUEST_GET_SIM_STATUS: + ril_request_sim_status(t); break; - case IPC_NET_MODE_SEL: - respondModeSel(info); + case RIL_REQUEST_SIM_IO: + ril_request_sim_io(t, data, datalen); break; - case IPC_DISP_ICON_INFO: - respondIconSignalStrength(t, info->data, info->length); + case RIL_REQUEST_ENTER_SIM_PIN: + ril_request_enter_sim_pin(t, data, datalen); break; - case IPC_DISP_RSSI_INFO: - respondSignalStrength(t, info->data, info->length); + case RIL_REQUEST_QUERY_FACILITY_LOCK: + ril_request_query_facility_lock(t, data, datalen); break; - case IPC_CALL_INCOMING: - respondCallIncoming(t, info->data, info->length); + case RIL_REQUEST_SET_FACILITY_LOCK: + ril_request_set_facility_lock(t, data, datalen); break; - case IPC_CALL_LIST: - respondCallList(t, info->data, info->length); + /* NET */ + case RIL_REQUEST_OPERATOR: + ril_request_operator(t); break; - case IPC_CALL_STATUS: - respondCallStatus(t, info->data, info->length); + case RIL_REQUEST_REGISTRATION_STATE: + ril_request_registration_state(t); break; - case IPC_SMS_INCOMING_MSG: - respondSmsIncoming(t, info->data, info->length); + case RIL_REQUEST_GPRS_REGISTRATION_STATE: + ril_request_gprs_registration_state(t); break; - case IPC_SMS_DELIVER_REPORT: - respondSmsDeliverReport(t, info->data, info->length); + case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: + ril_request_query_available_networks(t); break; - case IPC_SMS_SVC_CENTER_ADDR: - respondSmsSvcCenterAddr(t, info->data, info->length); + case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: + ril_request_query_network_selection_mode(t); break; - case IPC_SMS_SEND_MSG: - respondSmsSendMsg(t, info->data, info->length); + case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: + ril_request_get_preferred_network_type(t); break; - case IPC_SEC_PIN_STATUS: - respondSimStatusChanged(t, info->data, info->length); + case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: + ril_request_set_preffered_network_type(t, data, datalen); break; - case IPC_SEC_LOCK_INFO: - respondLockInfo(info); + /* SMS */ + case RIL_REQUEST_SEND_SMS: + ril_request_send_sms(t, data, datalen); break; - case IPC_SEC_RSIM_ACCESS: - respondSecRsimAccess(t, info->data, info->length); + case RIL_REQUEST_SEND_SMS_EXPECT_MORE: + ril_request_send_sms_expect_more(t, data, datalen); break; - case IPC_SEC_PHONE_LOCK: - respondSecPhoneLock(info); + case RIL_REQUEST_SMS_ACKNOWLEDGE: + ril_request_sms_acknowledge(t, data, datalen); break; - case IPC_SAT_PROACTIVE_CMD: - respondSatProactiveCmd(info); + /* CALL */ + case RIL_REQUEST_DIAL: + ril_request_dial(t, data, datalen); break; - case IPC_SAT_ENVELOPE_CMD: - respondSatEnvelopeCmd(info); + case RIL_REQUEST_GET_CURRENT_CALLS: + ril_request_get_current_calls(t); break; - case IPC_GEN_PHONE_RES: - respondGenPhonRes(info); + case RIL_REQUEST_HANGUP: + case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: + case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: + ril_request_hangup(t); break; - case IPC_SMS_DEVICE_READY: - respondSmsDeviceReady(t, info); + case RIL_REQUEST_ANSWER: + ril_request_answer(t); + break; + case RIL_REQUEST_DTMF_START: + ril_request_dtmf_start(t, data, datalen); + break; + case RIL_REQUEST_DTMF_STOP: + ril_request_dtmf_stop(t); + break; + /* OTHER */ + case RIL_REQUEST_SCREEN_STATE: + /* This doesn't affect anything */ + RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); break; default: - //LOGD("Unknown msgtype: %04x", info->type); + LOGE("Request not implemented: %d\n", request); + RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0); break; } } -void ipc_log_handler(const char *message, void *user_data) -{ - LOGD("ipc: %s", message); -} - -void socketRespondGetHelo(struct srs_message *message) -{ - int helo = SRS_CONTROL_HELO; - srs_server_send(srs_server, SRS_CONTROL_GET_HELO, &helo, sizeof(helo), message->msg_id); -} +/** + * RILJ related functions + */ -void socketRespondLinkClose(struct srs_message *message) +RIL_RadioState currentState() { - close(srs_server->client_fd); - srs_server->client_fd = -1; + return ril_state.radio_state; } -void socketRespondSetCallClockSync(struct srs_message *message) +int onSupports(int requestCode) { - unsigned char data = *((unsigned char *) message->data); - LOGE("SetCallClockSync data is 0x%x\n", data); - - ipc_client_send(ipc_client, IPC_SND_CLOCK_CTRL, IPC_TYPE_EXEC, &data, sizeof(data), 0xff); + switch(requestCode) { + default: + return 1; + } } -void onSocketReceive(struct srs_message *message) +void onCancel(RIL_Token t) { - switch(message->command) { - case SRS_CONTROL_GET_HELO: - socketRespondGetHelo(message); - break; - case SRS_CONTROL_LINK_CLOSE: - socketRespondLinkClose(message); - break; - case SRS_SND_SET_CALL_CLOCK_SYNC: - socketRespondSetCallClockSync(message); - break; - } + /* Todo */ } -void *socket_loop() +const char *getVersion(void) { - struct srs_message srs_message; - fd_set fds; - int rc; - - while(1) { - rc = srs_server_accept(srs_server); - - LOGE("SRS server accept!"); - - FD_ZERO(&fds); - FD_SET(srs_server->client_fd, &fds); - - while(1) { - usleep(300); - - if(srs_server->client_fd < 0) - break; - - select(FD_SETSIZE, &fds, NULL, NULL, NULL); - - if(FD_ISSET(srs_server->client_fd, &fds)) { - if(srs_server_recv(srs_server, &srs_message) < 0) { - LOGE("SRS server RECV failure!!!"); - break; - } - - LOGE("SRS OBTAINED DATA DUMP == %d == %d ======", srs_message.command, srs_message.data_len); - ipc_hex_dump(ipc_client, srs_message.data, srs_message.data_len); - - onSocketReceive(&srs_message); - - if(srs_message.data != NULL) //check on datalen - free(srs_message.data); - } - } - - if(srs_server->client_fd > 0) { - close(srs_server->client_fd); - srs_server->client_fd = -1; - } - - LOGE("SRS server client ended!"); - } - - return 0; + return RIL_VERSION_STRING; } /** - * read_loop(): - * This function is the main RIL read loop + * RIL init function */ -void *read_loop() -{ - struct ipc_message_info resp; - fd_set fds; - - FD_ZERO(&fds); - FD_SET(client_fmt_fd, &fds); - while(1) { - usleep(300); - - select(FD_SETSIZE, &fds, NULL, NULL, NULL); - - if(FD_ISSET(client_fmt_fd, &fds)) { - if(ipc_client_recv(ipc_client, &resp)) { - LOGE("IPC RECV failure!!!"); - break; - } - LOGD("RECV aseq=0x%x mseq=0x%x data_length=%d\n", resp.aseq, resp.mseq, resp.length); - - onReceive(&resp); - - if(resp.data != NULL) - free(resp.data); - } - } - - ipc_client_power_off(ipc_client); - ipc_client_close(ipc_client); - ipc_client_free(ipc_client); - - return 0; -} - -void radio_init_tokens(void) +void ril_state_lpm(void) { - memset(&(radio.tokens), 0, sizeof(struct ril_tokens)); + memset(&ril_state, 0, sizeof(ril_state)); + ril_state.radio_state = RADIO_STATE_OFF; + ril_state.power_mode = POWER_MODE_LPM; } -void radio_init_lpm(void) -{ - memset(&radio, 0, sizeof(radio)); - radio.radio_state = RADIO_STATE_OFF; - radio.power_mode = POWER_MODE_LPM; -} -void socket_loop_thread() -{ - pthread_t thread; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create(&thread, &attr, socket_loop, NULL); -} - -void read_loop_thread() -{ - pthread_t thread; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create(&thread, &attr, read_loop, NULL); -} - -/** - * RIL_Init function - */ - -static const RIL_RadioFunctions radio_ops = { +static const RIL_RadioFunctions ril_ops = { RIL_VERSION, onRequest, currentState, @@ -491,48 +431,54 @@ static const RIL_RadioFunctions radio_ops = { const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv) { - radio_init_lpm(); - radio_init_tokens(); + int rc; - rilenv = env; + ril_env = env; - LOGD("Creating new FMT client"); - ipc_client = ipc_client_new(IPC_CLIENT_TYPE_FMT); + ril_state_lpm(); + memset(&(ril_state.tokens), 0, sizeof(struct ril_tokens)); - ipc_client_set_log_handler(ipc_client, ipc_log_handler, NULL); +ipc_fmt: + ipc_fmt_client = ril_client_new(&ipc_fmt_client_funcs); + rc = ril_client_create(ipc_fmt_client); - ipc_client_bootstrap_modem(ipc_client); + if(rc < 0) { + LOGE("IPC FMT client creation failed."); + goto ipc_rfs; + } - LOGD("All handlers data is %p", &client_fmt_fd); - ipc_client_set_all_handlers_data(ipc_client, &client_fmt_fd); + rc = ril_client_thread_start(ipc_fmt_client); - LOGD("Client open..."); - if(ipc_client_open(ipc_client)) { - LOGE("%s: failed to open ipc client", __FUNCTION__); - return 0; + if(rc < 0) { + LOGE("IPC FMT thread creation failed."); + goto ipc_rfs; } - if(client_fmt_fd < 0) { - LOGE("%s: client_fmt_fd is negative, aborting", __FUNCTION__); - return 0; - } + LOGD("IPC FMT client ready"); - LOGD("Client power on..."); - if(ipc_client_power_on(ipc_client)) { - LOGE("%s: failed to power on ipc client", __FUNCTION__); - return 0; +ipc_rfs: + LOGD("Wait for the rest to be working before doing RFS"); + +srs: + srs_client = ril_client_new(&srs_client_funcs); + rc = ril_client_create(srs_client); + + if(rc < 0) { + LOGE("SRS client creation failed."); + goto end; } - srs_server = srs_server_new(); - if(srs_server_open(srs_server) < 0) { - LOGE("%s: samsung-ril-socket server open failed", __FUNCTION__); - return 0; + rc = ril_client_thread_start(srs_client); + + if(rc < 0) { + LOGE("SRS thread creation failed."); + goto end; } - read_loop_thread(); - socket_loop_thread(); + LOGD("SRS client ready"); - return &radio_ops; +end: + return &ril_ops; } int main(int argc, char *argv[]) |