From: Dongchul Lim Date: Mon, 7 Apr 2014 10:50:44 +0000 (+0900) Subject: Initial refactoring merge X-Git-Tag: submit/tizen/20140408.080458^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_generic;p=platform%2Fcore%2Ftelephony%2Ftel-plugin-imcmodem.git Initial refactoring merge Change-Id: I77780f57597ed0c8d68f468cf8a38b0a2a788a35 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e3ff6c8..cc44a9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wextra -Wno-unused-paramete ADD_DEFINITIONS("-DFEATURE_DLOG_DEBUG") ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"IMCMODEM\"") +ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))") MESSAGE(${CMAKE_C_FLAGS}) MESSAGE(${CMAKE_EXE_LINKER_FLAGS}) diff --git a/include/config.h b/include/config.h index fb0c534..f3d60f0 100644 --- a/include/config.h +++ b/include/config.h @@ -1,9 +1,7 @@ /* * tel-plugin-imcmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Kyoungyoup Park + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +16,8 @@ * limitations under the License. */ -#ifndef _CONFIG_H_ -#define _CONFIG_H_ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ #ifdef __cplusplus extern "C" { @@ -32,4 +30,4 @@ void config_check_cp_power(TcoreHal *hal); } #endif /* __cplusplus */ -#endif /* _CONFIG_H_ */ +#endif /* __CONFIG_H__ */ diff --git a/include/vnet.h b/include/vnet.h index 5c81e6c..d6a3af4 100644 --- a/include/vnet.h +++ b/include/vnet.h @@ -1,9 +1,7 @@ /* * tel-plugin-imcmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Kyoungyoup Park + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +16,15 @@ * limitations under the License. */ -#ifndef _VNET_H_ -#define _VNET_H_ +#ifndef __VNET_H__ +#define __VNET_H__ #ifdef __cplusplus extern "C" { #endif /* CP states */ -enum vnet_cp_state { +typedef enum { VNET_CP_STATE_UNKNOWN = -1, VNET_CP_STATE_OFFLINE = 0, VNET_CP_STATE_CRASH_RESET, @@ -35,19 +33,19 @@ enum vnet_cp_state { VNET_CP_STATE_ONLINE, VNET_CP_STATE_NV_REBUILDING, VNET_CP_STATE_LOADER_DONE, -}; +} VnetCpState; -void vnet_start_cp_ramdump( void ); -void vnet_start_cp_reset( void ); +void vnet_start_cp_ramdump(void); +void vnet_start_cp_reset(void); -enum vnet_cp_state vnet_get_cp_state( int fd ); +VnetCpState vnet_get_cp_state(int fd); -int vnet_rfs0_open( void ); -int vnet_ipc0_open( void ); +int vnet_rfs0_open(void); +int vnet_ipc0_open(void); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* _VNET_H_ */ +#endif /* __VNET_H__ */ diff --git a/packaging/tel-plugin-imcmodem.spec b/packaging/tel-plugin-imcmodem.spec index ee0ecac..5aeeb91 100644 --- a/packaging/tel-plugin-imcmodem.spec +++ b/packaging/tel-plugin-imcmodem.spec @@ -1,17 +1,21 @@ +%define major 3 +%define minor 0 +%define patchlevel 1 + Name: tel-plugin-imcmodem -Summary: telephony plugin library for AT communication with IMC modem -Version: 0.1.4 +Version: %{major}.%{minor}.%{patchlevel} Release: 1 -Group: System/Libraries License: Apache-2.0 +Summary: Telephony Plug-in for AT communication with IMC modem (Modem Interface Plug-in) +Group: System/Libraries Source0: tel-plugin-imcmodem-%{version}.tar.gz Source1001: tel-plugin-imcmodem.manifest -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(tcore) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig %description imcmodem plugin for telephony diff --git a/src/config.c b/src/config.c index db2e8c2..7fdc971 100644 --- a/src/config.c +++ b/src/config.c @@ -1,9 +1,7 @@ /* * tel-plugin-imcmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Kyoungyoup Park + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -39,21 +36,21 @@ #include "config.h" -#define IMC_MODEM_PLUGIN_NAME "imc-plugin.so" +#define IMC_MODEM_PLUGIN_NAME "imc-plugin.so" -#define IMC_CMUX_MAX_CHANNELS 7 -#define IMC_CMUX_MAX_BUFFER_SIZE 2048 +#define IMC_CMUX_MAX_CHANNELS 7 +#define IMC_CMUX_MAX_BUFFER_SIZE 2048 /* CP States */ -#define IMC_AT_CPAS_RESULT_READY 0 -#define IMC_AT_CPAS_RESULT_UNAVAIL 1 -#define IMC_AT_CPAS_RESULT_UNKNOWN 2 -#define IMC_AT_CPAS_RESULT_RINGING 3 +#define IMC_AT_CPAS_RESULT_READY 0 +#define IMC_AT_CPAS_RESULT_UNAVAIL 1 +#define IMC_AT_CPAS_RESULT_UNKNOWN 2 +#define IMC_AT_CPAS_RESULT_RINGING 3 #define IMC_AT_CPAS_RESULT_CALL_PROGRESS 4 -#define IMC_AT_CPAS_RESULT_ASLEEP 5 +#define IMC_AT_CPAS_RESULT_ASLEEP 5 /* Maximum Core objects per Logical HAL (indirectly per Channel) */ -#define MAX_CORE_OBJECTS_PER_CHANNEL 3 +#define MAX_CO_PER_CHANNEL 3 /* * List of supported Core Object types @@ -68,8 +65,7 @@ * Channel 6 - NETWORK & GPS * Channel 7 - MODEM & PS */ -unsigned int - supported_modules[IMC_CMUX_MAX_CHANNELS+1][MAX_CORE_OBJECTS_PER_CHANNEL] = +guint supported_modules[IMC_CMUX_MAX_CHANNELS+1][MAX_CO_PER_CHANNEL] = { /* * Channel 0 - CMUX Control Channel @@ -95,26 +91,22 @@ unsigned int static gboolean _check_cp_poweron(TcoreHal *hal); static void _send_enable_logging_command(TcoreHal *hal); -static void _on_confirmation_send_message(TcorePending *pending, - gboolean result, void *user_data) +static void _on_confirmation_send_message(TcorePending *p, + TelReturn send_status, void *user_data) { - dbg("Message send confirmation"); - - if (result == FALSE) { /* Fail */ - dbg("SEND FAIL"); - } else { - dbg("SEND OK"); - } + dbg("Message send confirmation - [%s]", + ((send_status != TEL_RETURN_SUCCESS) ? "FAIL" : "OK")); } -static void _assign_objects_to_hal(int channel_id, TcoreHal *hal) + +static void _assign_objects_to_hal(guint channel_id, TcoreHal *hal) { TcorePlugin *plugin; gboolean ret; - int i; + guint i; plugin = tcore_hal_ref_plugin(hal); - for (i = 0 ; i < MAX_CORE_OBJECTS_PER_CHANNEL ; i++) { + for (i = 0 ; i < MAX_CO_PER_CHANNEL ; i++) { if (supported_modules[channel_id][i] == 0) continue; @@ -122,9 +114,11 @@ static void _assign_objects_to_hal(int channel_id, TcoreHal *hal) ret = tcore_server_add_cp_mapping_tbl_entry(plugin, supported_modules[channel_id][i], hal); if (ret == TRUE) { - dbg("Core Object Type: [0x%x] - Success"); + dbg("Core Object Type: [0x%x] - Success", + supported_modules[channel_id][i]); } else { - err("Core Object Type: [0x%x] - Fail"); + err("Core Object Type: [0x%x] - Fail", + supported_modules[channel_id][i]); } } } @@ -135,8 +129,7 @@ static void _on_cmux_setup_complete(gpointer user_data) TcorePlugin *plugin; dbg("MUX Setup - COMPLETE"); - if (user_data == NULL) - return; + tcore_check_return(user_data != NULL); plugin = tcore_hal_ref_plugin(hal); @@ -145,19 +138,18 @@ static void _on_cmux_setup_complete(gpointer user_data) /* Load Modem Plug-in */ tcore_server_load_modem_plugin(tcore_plugin_ref_server(plugin), - plugin, IMC_MODEM_PLUGIN_NAME); + plugin, IMC_MODEM_PLUGIN_NAME); } -static void _on_cmux_channel_setup(int channel_id, TcoreHal *hal, - gpointer user_data) +static void _on_cmux_channel_setup(guint channel_id, + TcoreHal *hal, gpointer user_data) { TcorePlugin *plugin; TcoreHal *phy_hal; if ((hal == NULL) || (user_data == NULL)) return; - if ((channel_id == 0) - || (channel_id > IMC_CMUX_MAX_CHANNELS)) { + if ((channel_id == 0) || (channel_id > IMC_CMUX_MAX_CHANNELS)) { err("Control Channel"); return; } @@ -175,37 +167,33 @@ static void _on_cmux_channel_setup(int channel_id, TcoreHal *hal, dbg("HAL Power State: Power ON"); } -static void _on_response_cmux_init(TcorePending *p, int data_len, - const void *data, void *user_data) +static void _on_response_cmux_init(TcorePending *p, + guint data_len, const void *data, void *user_data) { - const TcoreATResponse *resp = data; + const TcoreAtResponse *resp = data; TcoreHal *hal = user_data; - TReturn ret; + TelReturn ret; - if ((resp != NULL) - && resp->success) { + if (resp && resp->success) { dbg("Initialize CMUX - [OK]"); /* Setup Internal CMUX */ ret = tcore_cmux_setup_internal_mux(CMUX_MODE_BASIC, - IMC_CMUX_MAX_CHANNELS, - IMC_CMUX_MAX_BUFFER_SIZE, hal, - _on_cmux_channel_setup, hal, - _on_cmux_setup_complete, hal); + IMC_CMUX_MAX_CHANNELS, IMC_CMUX_MAX_BUFFER_SIZE, hal, + _on_cmux_channel_setup, hal, _on_cmux_setup_complete, hal); } else { err("Initialize CMUX - [NOK]"); } } static void _on_response_enable_logging(TcorePending *p, - int data_len, const void *data, void *user_data) + guint data_len, const void *data, void *user_data) { - const TcoreATResponse *resp = data; + const TcoreAtResponse *resp = data; TcoreHal *hal = user_data; - TReturn ret; + TelReturn ret; - if ((resp != NULL) - && resp->success) { + if (resp && resp->success) { dbg("Enable CP logging - [OK]"); } else { err("Enable CP logging - [NOK]"); @@ -213,7 +201,7 @@ static void _on_response_enable_logging(TcorePending *p, /* Initialize Internal MUX (CMUX) */ ret = tcore_cmux_init(hal, 0, _on_response_cmux_init, hal); - if (ret != TCORE_RETURN_SUCCESS) { + if (ret != TEL_RETURN_SUCCESS) { err("Failed to initialize CMUX - Error: [0x%x]", ret); } else { dbg("Successfully sent CMUX init to CP"); @@ -223,7 +211,7 @@ static void _on_response_enable_logging(TcorePending *p, static void _on_timeout_check_cp_poweron(TcorePending *p, void *user_data) { TcoreHal *hal = user_data; - unsigned int data_len = 0; + guint data_len = 0; char *data = "AT+CPAS"; data_len = sizeof(data); @@ -239,9 +227,9 @@ static void _on_timeout_check_cp_poweron(TcorePending *p, void *user_data) } static void _on_response_check_cp_poweron(TcorePending *pending, - int data_len, const void *data, void *user_data) + guint data_len, const void *data, void *user_data) { - const TcoreATResponse *resp = data; + const TcoreAtResponse *resp = data; TcoreHal *hal = user_data; GSList *tokens = NULL; @@ -249,8 +237,7 @@ static void _on_response_check_cp_poweron(TcorePending *pending, gboolean bpoweron = FALSE; int response = 0; - if ((resp != NULL) - && resp->success) { + if (resp && resp->success) { dbg("Check CP POWER - [OK]"); /* Parse AT Response */ @@ -304,7 +291,7 @@ ERROR: static void _send_enable_logging_command(TcoreHal *hal) { - TcoreATRequest *at_req = NULL; + TcoreAtRequest *at_req = NULL; TcorePending *pending = NULL; dbg("Sending Trace enabling command for CP logging"); @@ -314,7 +301,7 @@ static void _send_enable_logging_command(TcoreHal *hal) /* Create AT Request */ at_req = tcore_at_request_new("at+xsystrace=1,\"digrf=1;bb_sw=1;3g_sw=1\",\"digrf=0x84\",\"oct=4\";+xsystrace=11;+trace=1", - NULL, TCORE_AT_NO_RESULT); + NULL, TCORE_AT_COMMAND_TYPE_NO_RESULT); dbg("AT-Command: [%s] Prefix(if any): [%s] Command length: [%d]", @@ -326,7 +313,7 @@ static void _send_enable_logging_command(TcoreHal *hal) tcore_pending_set_send_callback(pending, _on_confirmation_send_message, NULL); /* Send command to CP */ - if (tcore_hal_send_request(hal, pending) != TCORE_RETURN_SUCCESS) { + if (tcore_hal_send_request(hal, pending) != TEL_RETURN_SUCCESS) { err("Failed to send Trace logging command"); } else { dbg("Successfully sent Trace logging command"); @@ -335,17 +322,18 @@ static void _send_enable_logging_command(TcoreHal *hal) static gboolean _check_cp_poweron(TcoreHal *hal) { - TcoreATRequest *at_req; + TcoreAtRequest *at_req; TcorePending *pending = NULL; /* Create Pending request */ pending = tcore_pending_new(NULL, 0); /* Create AT Request */ - at_req = tcore_at_request_new("AT+CPAS", "+CPAS:", TCORE_AT_SINGLELINE); + at_req = tcore_at_request_new("AT+CPAS", + "+CPAS:", TCORE_AT_COMMAND_TYPE_SINGLELINE); dbg("AT-Command: [%s] Prefix(if any): [%s] Command length: [%d]", - at_req->cmd, at_req->prefix, strlen(at_req->cmd)); + at_req->cmd, at_req->prefix, strlen(at_req->cmd)); tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT); @@ -359,7 +347,7 @@ static gboolean _check_cp_poweron(TcoreHal *hal) tcore_pending_set_send_callback(pending, _on_confirmation_send_message, NULL); /* Send command to CP */ - if (tcore_hal_send_request(hal, pending) != TCORE_RETURN_SUCCESS) { + if (tcore_hal_send_request(hal, pending) != TEL_RETURN_SUCCESS) { err("Failed to send CPAS"); return FALSE; } else { @@ -373,8 +361,7 @@ void config_check_cp_power(TcoreHal *hal) gboolean ret; dbg("Entry"); - if (hal == NULL) - return; + tcore_check_return(hal != NULL); ret = _check_cp_poweron(hal); if (ret == TRUE) { diff --git a/src/desc-imcmodem.c b/src/desc-imcmodem.c index 3640603..cdaddee 100644 --- a/src/desc-imcmodem.c +++ b/src/desc-imcmodem.c @@ -1,9 +1,7 @@ /* * tel-plugin-imcmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Kyoungyoup Park + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,37 +28,38 @@ #include #include +#include #include #include #include -#include #include +#include #include "vnet.h" #include "config.h" -#define IMC_HAL_NAME "imcmodem" -#define IMC_BUFFER_LEN_MAX 4096 +#define IMC_HAL_NAME "imcmodem" +#define IMC_BUFFER_LEN_MAX 4096 -#define IMC_CP_POWER_ON_TIMEOUT 500 +#define IMC_CP_POWER_ON_TIMEOUT 500 -#define IMC_MAX_CP_POWER_ON_RETRIES 20 +#define IMC_MAX_CP_POWER_ON_RETRIES 20 -#define IMC_DEVICE_NAME_LEN_MAX 16 -#define IMC_DEVICE_NAME_PREFIX "pdp" +#define IMC_DEVICE_NAME_LEN_MAX 16 +#define IMC_DEVICE_NAME_PREFIX "pdp" -#define VNET_CH_PATH_BOOT0 "/dev/umts_boot0" -#define IOCTL_CG_DATA_SEND _IO('o', 0x37) +#define VNET_CH_PATH_BOOT0 "/dev/umts_boot0" +#define IOCTL_CG_DATA_SEND _IO('o', 0x37) -struct vnet_channel { +typedef struct { int fd; guint watch_id; gboolean on; -}; +} VnetChannel; -struct custom_data { - struct vnet_channel ipc0; -}; +typedef struct { + VnetChannel ipc0; +} CustomData; typedef gboolean(*cb_func)(GIOChannel *channel, GIOCondition condition, gpointer data); @@ -69,41 +68,6 @@ static gboolean _on_recv_ipc_message(GIOChannel *channel, GIOCondition condition static guint _register_gio_watch(TcoreHal *plugin, int fd, void *callback); static void _deregister_gio_watch(guint watch_id); - -/* Utility function to dump the Input/Output bytes (TX/RX Data) */ -static void _util_hex_dump(char *pad, int size, const void *data) -{ - char buffer[255] = {0, }; - char hex[4] = {0, }; - int i; - unsigned char *ptr; - - if (size <= 0) { - msg("[%s] NO data", pad); - return; - } - - ptr = (unsigned char *)data; - - snprintf(buffer, 255, "%s%04X: ", pad, 0); - for (i = 0; i < size; i++) { - snprintf(hex, 4, "%02X ", ptr[i]); - strcat(buffer, hex); - - if ((i + 1) % 8 == 0) { - if ((i + 1) % 16 == 0) { - msg("%s", buffer); - memset(buffer, 0, 255); - snprintf(buffer, 255, "%s%04X: ", pad, i + 1); - } else { - strcat(buffer, " "); - } - } - } - - msg("%s", buffer); -} - static guint _register_gio_watch(TcoreHal *hal, int fd, void *callback) { GIOChannel *channel = NULL; @@ -116,7 +80,10 @@ static guint _register_gio_watch(TcoreHal *hal, int fd, void *callback) channel = g_io_channel_unix_new(fd); /* Add to Watch list for IO and HUP events */ - source = g_io_add_watch(channel, G_IO_IN | G_IO_HUP, (GIOFunc) callback, hal); + source = g_io_add_watch(channel, + G_IO_IN | G_IO_HUP, + (GIOFunc) callback, hal); + g_io_channel_unref(channel); channel = NULL; @@ -131,7 +98,7 @@ static void _deregister_gio_watch(guint watch_id) g_source_remove(watch_id); } -static gboolean _ipc0_init(TcoreHal *hal, struct vnet_channel *ch, cb_func recv_message) +static gboolean _ipc0_init(TcoreHal *hal, VnetChannel *ch, cb_func recv_message) { dbg("Entry"); @@ -152,33 +119,37 @@ static gboolean _ipc0_init(TcoreHal *hal, struct vnet_channel *ch, cb_func recv_ /* Register Channel for IO */ ch->watch_id = _register_gio_watch(hal, ch->fd, recv_message); + /* Channel is ON */ ch->on = TRUE; return ch->on; } -static void _ipc0_deinit(struct vnet_channel *ch) +static void _ipc0_deinit(VnetChannel *ch) { - /* Remove and close the Watch ID and 'fd' */ - dbg("Watch ID: [%d]", ch->watch_id); - if (ch->watch_id > 0) - _deregister_gio_watch(ch->watch_id); + if (ch->on) { + dbg("Deinitializing the Channel - Watch ID: [%d] " + "fd: [%d]", ch->watch_id, ch->fd); - dbg("fd: [%d]", ch->fd); - if (ch->fd > 0) - close(ch->fd); + /* Remove and close the Watch ID and 'fd' */ + if (ch->watch_id > 0) + _deregister_gio_watch(ch->watch_id); + + if (ch->fd > 0) + close(ch->fd); - ch->watch_id = 0; - ch->fd = 0; + ch->watch_id = 0; + ch->fd = 0; - ch->on = FALSE; + ch->on = FALSE; + } } static gboolean _silent_reset(TcoreHal *hal) { dbg("[ERROR] Silent Reset"); - /* Set HAL Poer State to OFF (FALSE) */ + /* Set HAL Power State to OFF (FALSE) */ tcore_hal_set_power_state(hal, FALSE); /* TODO: Need to handle Silent Reset */ @@ -188,8 +159,8 @@ static gboolean _silent_reset(TcoreHal *hal) static gboolean _do_exception_operation(TcoreHal *hal, int fd, GIOCondition cond) { - enum vnet_cp_state state = VNET_CP_STATE_UNKNOWN; - struct custom_data *user_data = tcore_hal_ref_user_data(hal); + VnetCpState state = VNET_CP_STATE_UNKNOWN; + CustomData *user_data = tcore_hal_ref_user_data(hal); dbg("Entry"); switch (cond) { @@ -201,8 +172,7 @@ static gboolean _do_exception_operation(TcoreHal *hal, int fd, GIOCondition cond } switch (state) { - case VNET_CP_STATE_CRASH_EXIT: - { + case VNET_CP_STATE_CRASH_EXIT: { err("CP Crash: Start ramdump"); _ipc0_deinit(&user_data->ipc0); @@ -212,8 +182,7 @@ static gboolean _do_exception_operation(TcoreHal *hal, int fd, GIOCondition cond } break; - case VNET_CP_STATE_CRASH_RESET: - { + case VNET_CP_STATE_CRASH_RESET: { err("CP Crash Reset"); _ipc0_deinit(&user_data->ipc0); @@ -228,7 +197,8 @@ static gboolean _do_exception_operation(TcoreHal *hal, int fd, GIOCondition cond } /* - * if current hal power state is FALSE, 'cp_reset' mean normal power off + * if current hal power state is FALSE, + * 'cp_reset' mean normal power off * (it's because of kernel concept) */ state = VNET_CP_STATE_OFFLINE; @@ -259,7 +229,7 @@ static gboolean _do_exception_operation(TcoreHal *hal, int fd, GIOCondition cond static gboolean _power_on(gpointer data) { - struct custom_data *user_data; + CustomData *user_data; TcoreHal *hal; gboolean ret; @@ -289,9 +259,8 @@ static gboolean _power_on(gpointer data) err("Maximum timeout reached: [%d]", count); /* Notify server a modem error occured */ - tcore_server_send_notification(server, NULL, - TNOTI_SERVER_MODEM_ERR, - 0, NULL); + tcore_server_send_server_notification(server, + TCORE_SERVER_NOTIFICATION_MODEM_ERR, 0, NULL); tcore_hal_free(hal); g_free(user_data); @@ -329,32 +298,32 @@ static void _on_cmux_channel_close(TcoreHal *hal, gpointer user_data) tcore_server_remove_cp_mapping_tbl_entry(plugin, hal); } -static enum tcore_hook_return _on_hal_send(TcoreHal *hal, - unsigned int data_len, void *data, void *user_data) +static TcoreHookReturn _on_hal_send(TcoreHal *hal, + guint data_len, void *data, void *user_data) { msg("\n====== TX data DUMP ======\n"); - _util_hex_dump(" ", data_len, data); + tcore_util_hex_dump(" ", data_len, data); msg("\n====== TX data DUMP ======\n"); return TCORE_HOOK_RETURN_CONTINUE; } static void _on_hal_recv(TcoreHal *hal, - unsigned int data_len, const void *data, void *user_data) + guint data_len, const void *data, void *user_data) { msg("\n====== RX data DUMP ======\n"); - _util_hex_dump(" ", data_len, data); + tcore_util_hex_dump(" ", data_len, data); msg("\n====== RX data DUMP ======\n"); } static gboolean _on_recv_ipc_message(GIOChannel *channel, - GIOCondition condition, gpointer data) + GIOCondition condition, gpointer data) { TcoreHal *hal = data; - struct custom_data *custom; + CustomData *custom; char recv_buffer[IMC_BUFFER_LEN_MAX]; int recv_len = 0; - TReturn ret; + TelReturn ret; custom = tcore_hal_ref_user_data(hal); @@ -385,31 +354,30 @@ static gboolean _on_recv_ipc_message(GIOChannel *channel, return TRUE; } -static TReturn _hal_send(TcoreHal *hal, unsigned int data_len, void *data) +static TelReturn _hal_send(TcoreHal *hal, guint data_len, void *data) { int ret; - struct custom_data *user_data; + CustomData *user_data; if (tcore_hal_get_power_state(hal) == FALSE) - return TCORE_RETURN_FAILURE; + return TEL_RETURN_FAILURE; user_data = tcore_hal_ref_user_data(hal); if (!user_data) - return TCORE_RETURN_FAILURE; + return TEL_RETURN_FAILURE; dbg("write (fd=%d, len=%d)", user_data->ipc0.fd, data_len); ret = write(user_data->ipc0.fd, (guchar *) data, data_len); if (ret < 0) - return TCORE_RETURN_FAILURE; + return TEL_RETURN_FAILURE; - return TCORE_RETURN_SUCCESS;; + return TEL_RETURN_SUCCESS;; } -static TReturn _hal_setup_netif(CoreObject *co, - TcoreHalSetupNetifCallback func, - void *user_data, unsigned int cid, - gboolean enable) +static TelReturn _hal_setup_netif(CoreObject *co, + TcoreHalSetupNetifCallback func, void *user_data, + guint cid, gboolean enable) { if (enable == TRUE) { int fd; @@ -421,8 +389,9 @@ static TReturn _hal_setup_netif(CoreObject *co, /* Open device to send IOCTL command */ fd = open(VNET_CH_PATH_BOOT0, O_RDWR); if (fd < 0) { - err("Failed to Open [%s] Error: [%s]", VNET_CH_PATH_BOOT0, strerror(errno)); - return TCORE_RETURN_FAILURE; + err("Failed to Open [%s] Error: [%s]", + VNET_CH_PATH_BOOT0, strerror(errno)); + return TEL_RETURN_FAILURE; } /* @@ -431,23 +400,21 @@ static TReturn _hal_setup_netif(CoreObject *co, * Presently only 2 Contexts are suported */ switch (cid) { - case 1: - { + case 1: { dbg("Send IOCTL: arg 0x05 (0101) HSIC1, cid: [%d]", cid); ret = ioctl(fd, IOCTL_CG_DATA_SEND, 0x05); } break; - case 2: - { + case 2: { dbg("Send IOCTL: arg 0x0A (1010) HSIC2, cid: [%d]", cid); ret = ioctl(fd, IOCTL_CG_DATA_SEND, 0xA); } break; - default: - { - err("More than 2 Contexts are not supported right now!!! cid: [%d]", cid); + default: { + err("More than 2 Contexts are not supported " + "right now!!! cid: [%d]", cid); } } @@ -456,34 +423,37 @@ static TReturn _hal_setup_netif(CoreObject *co, /* TODO - Need to handle Failure case */ if (ret < 0) { - err("[ERROR] IOCTL_CG_DATA_SEND - FAIL [0x%x]", IOCTL_CG_DATA_SEND); + err("[ERROR] IOCTL_CG_DATA_SEND - FAIL [0x%x]", + IOCTL_CG_DATA_SEND); /* Invoke callback function */ if (func) func(co, ret, NULL, user_data); - return TCORE_RETURN_FAILURE; + return TEL_RETURN_FAILURE; } else { - dbg("[OK] IOCTL_CG_DATA_SEND - PASS [0x%x]", IOCTL_CG_DATA_SEND); + dbg("[OK] IOCTL_CG_DATA_SEND - PASS [0x%x]", + IOCTL_CG_DATA_SEND); /* Device name */ - snprintf(ifname, IMC_DEVICE_NAME_LEN_MAX, "%s%d", IMC_DEVICE_NAME_PREFIX, (cid - 1)); + snprintf(ifname, IMC_DEVICE_NAME_LEN_MAX, "%s%d", + IMC_DEVICE_NAME_PREFIX, (cid - 1)); dbg("Interface Name: [%s]", ifname); /* Invoke callback function */ if (func) func(co, ret, ifname, user_data); - return TCORE_RETURN_SUCCESS; + return TEL_RETURN_SUCCESS; } } else { dbg("DEACTIVATE"); - return TCORE_RETURN_SUCCESS; + return TEL_RETURN_SUCCESS; } } /* HAL Operations */ -static struct tcore_hal_operations hal_ops = { +static TcoreHalOperations hal_ops = { .power = NULL, .send = _hal_send, .setup_netif = _hal_setup_netif, @@ -499,42 +469,24 @@ static gboolean on_load() static gboolean on_init(TcorePlugin *plugin) { TcoreHal *hal; - struct custom_data *data; + CustomData *data; dbg("Init!!!"); - if (plugin == NULL) { - err("'plugin' is NULL"); - return FALSE; - } - -#if 1 /* TODO - Need to remove this */ - /* - * CP is NOT coming to ONLINE state, - * but when it is forceffuly reset using the command - - * xmm6262-boot - * it comes back to ONLINE state. - * - * We need to look into this aspect - */ - dbg("====== TRIGGERING CP RESET ======"); - vnet_start_cp_reset(); - dbg("====== CP RESET TRIGGERED ======"); - sleep(2); -#endif /* TODO - Need to remove this */ + tcore_check_return_value_assert(plugin != NULL, FALSE); /* Custom data for Modem Interface Plug-in */ - data = g_try_new0(struct custom_data, 1); - if (data == NULL) { - err("Failed to allocate memory for Custom data"); - return FALSE; - } + data = tcore_malloc0(sizeof(CustomData)); dbg("Created custom data memory"); + /* Intialize for fd to -1 */ + data->ipc0.fd = -1; + /* Create Physical HAL */ - hal = tcore_hal_new(plugin, IMC_HAL_NAME, &hal_ops, TCORE_HAL_MODE_AT); + hal = tcore_hal_new(plugin, IMC_HAL_NAME, + &hal_ops, TCORE_HAL_MODE_AT); if (hal == NULL) { err("Failed to Create Physical HAL"); - g_free(data); + tcore_free(data); return FALSE; } dbg("HAL [0x%x] created", hal); @@ -558,7 +510,8 @@ static gboolean on_init(TcorePlugin *plugin) tcore_server_register_modem(tcore_plugin_ref_server(plugin), plugin); /* Check CP Power ON */ - g_timeout_add_full(G_PRIORITY_HIGH, IMC_CP_POWER_ON_TIMEOUT, _power_on, hal, 0); + g_timeout_add_full(G_PRIORITY_HIGH, + IMC_CP_POWER_ON_TIMEOUT, _power_on, hal, NULL); return TRUE; } @@ -566,14 +519,10 @@ static gboolean on_init(TcorePlugin *plugin) static void on_unload(TcorePlugin *plugin) { TcoreHal *hal; - struct custom_data *user_data; - + CustomData *user_data; dbg("Unload!!!"); - if (plugin == NULL) { - err("Modem Interface Plug-in is NULL"); - return; - } + tcore_check_return_assert(plugin != NULL); /* Unload Modem Plug-in */ tcore_server_unload_modem_plugin(tcore_plugin_ref_server(plugin), plugin); @@ -594,25 +543,22 @@ static void on_unload(TcorePlugin *plugin) dbg("CMUX is closed"); user_data = tcore_hal_ref_user_data(hal); - if (user_data == NULL) - return; - - /* Free HAL */ - tcore_hal_free(hal); - dbg("Freed HAL"); /* Deinitialize the Physical Channel */ _ipc0_deinit(&user_data->ipc0); - dbg("Deinitialized the Channel"); /* Free custom data */ - g_free(user_data); + tcore_free(user_data); + + /* Free HAL */ + tcore_hal_free(hal); + dbg("Freed HAL"); dbg("Unloaded MODEM Interface Plug-in"); } /* Modem Interface Plug-in descriptor */ -struct tcore_plugin_define_desc plugin_define_desc = { +EXPORT_API struct tcore_plugin_define_desc plugin_define_desc = { .name = "imcmodem", .priority = TCORE_PLUGIN_PRIORITY_HIGH, .version = 1, diff --git a/src/vnet.c b/src/vnet.c index c798525..0ffe3a1 100644 --- a/src/vnet.c +++ b/src/vnet.c @@ -1,9 +1,7 @@ /* * tel-plugin-imcmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Kyoungyoup Park + * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,24 +45,28 @@ #define __USE_GNU #endif -#define MODEM_IMAGE_PATH "/boot/modem.bin" -#define NV_DIR_PATH "/csa/nv" -#define NV_FILE_PATH NV_DIR_PATH"/nvdata.bin" +/* Modem image */ +#define MODEM_IMAGE_PATH "/boot/modem.bin" + +/* NV Data */ +#define NV_DIR_PATH "/csa/nv" +#define NV_FILE_PATH NV_DIR_PATH"/nvdata.bin" /* * AP-CP comunication devices */ /* To track CP bootup */ -#define VNET_CH_PATH_BOOT0 "/dev/umts_boot0" +#define VNET_CH_PATH_BOOT0 "/dev/umts_boot0" /* Control communication channel */ -#define VNET_CH_PATH_IPC0 "/dev/umts_ipc0" +#define VNET_CH_PATH_IPC0 "/dev/umts_ipc0" -#define IOCTL_MODEM_STATUS _IO('o', 0x27) +#define IOCTL_MODEM_STATUS _IO('o', 0x27) void vnet_start_cp_ramdump() { int ret; + ret = system("/usr/bin/xmm6262-boot -o u &"); dbg("system(/usr/bin/xmm6262-boot -o u &) ret[%d]", ret); } @@ -72,51 +74,51 @@ void vnet_start_cp_ramdump() void vnet_start_cp_reset() { int ret; + ret = system("/usr/bin/xmm6262-boot &"); dbg("system(/usr/bin/xmm6262-boot &) ret[%d]", ret); } -enum vnet_cp_state vnet_get_cp_state(int fd) +VnetCpState vnet_get_cp_state(int fd) { - enum vnet_cp_state state = VNET_CP_STATE_UNKNOWN; + VnetCpState state = VNET_CP_STATE_UNKNOWN; dbg("Entry"); /* Get CP state */ state = ioctl(fd, IOCTL_MODEM_STATUS); - switch (state) { case VNET_CP_STATE_OFFLINE: dbg("CP State: OFFLINE"); - break; + break; case VNET_CP_STATE_CRASH_RESET: dbg("CP State: CRASH RESET"); - break; + break; case VNET_CP_STATE_CRASH_EXIT: dbg("CP State: CRASH EXIT"); - break; + break; case VNET_CP_STATE_BOOTING: dbg("CP State: BOOT"); - break; + break; case VNET_CP_STATE_ONLINE: dbg("CP State: ONLINE"); - break; + break; case VNET_CP_STATE_NV_REBUILDING: dbg("CP State: NV REBUILD"); - break; + break; case VNET_CP_STATE_LOADER_DONE: dbg("CP State: LOADER DONE"); - break; + break; case VNET_CP_STATE_UNKNOWN: default: dbg("CP State: UNKNOWN State - [%d]", state); - break; + break; } return state; @@ -124,14 +126,15 @@ enum vnet_cp_state vnet_get_cp_state(int fd) int vnet_ipc0_open() { - enum vnet_cp_state state; + VnetCpState state; int fd; dbg("Entry"); /* Opening device to track CP state */ fd = open(VNET_CH_PATH_BOOT0, O_RDWR); if (fd < 0) { - err("Failed to Open [%s] Error: [%s]", VNET_CH_PATH_BOOT0, strerror(errno)); + err("Failed to Open [%s] Error: [%s]", + VNET_CH_PATH_BOOT0, strerror(errno)); return -1; } @@ -145,7 +148,8 @@ int vnet_ipc0_open() /* Opening AP-CP Control communication device */ fd = open(VNET_CH_PATH_IPC0, O_RDWR); if (fd < 0) { - err("Failed to Open [%s] Error: [%s]", VNET_CH_PATH_IPC0, strerror(errno)); + err("Failed to Open [%s] Error: [%s]", + VNET_CH_PATH_IPC0, strerror(errno)); return -1; } }