From 184d775afd0dd5a11267a8572fabd0e477102e94 Mon Sep 17 00:00:00 2001 From: Dongchul Lim Date: Mon, 7 Apr 2014 19:54:39 +0900 Subject: [PATCH] Initial refactoring merge Change-Id: I640c70af01dec228c3c160ad3f0c28c8481768ee --- CMakeLists.txt | 16 +- include/config.h | 38 ++++ include/vdpram.h | 19 +- include/vdpram_dump.h | 12 +- packaging/tel-plugin-vmodem.spec | 14 +- src/config.c | 303 +++++++++++++++++++++++++ src/desc-vmodem.c | 464 +++++++++++++++++---------------------- src/vdpram.c | 370 +++++++++++++++---------------- src/vdpram_dump.c | 61 ++--- 9 files changed, 759 insertions(+), 538 deletions(-) create mode 100644 include/config.h create mode 100644 src/config.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c08119..d621c71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,16 +21,19 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align") -ADD_DEFINITIONS("-DFEATURE_DLOG_DEBUG") -ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"TEL_PLUGIN_VMODEM\"") + +ADD_DEFINITIONS("-DFEATURE_TLOG_DEBUG") +ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"VMODEM\"") +ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))") MESSAGE(${CMAKE_C_FLAGS}) MESSAGE(${CMAKE_EXE_LINKER_FLAGS}) SET(SRCS - src/desc-vmodem.c - src/vdpram.c - src/vdpram_dump.c + src/desc-vmodem.c + src/vdpram.c + src/config.c + src/vdpram_dump.c ) @@ -42,6 +45,5 @@ SET_TARGET_PROPERTIES(vmodem-plugin PROPERTIES PREFIX "" OUTPUT_NAME vmodem-plug # install -INSTALL(TARGETS vmodem-plugin - LIBRARY DESTINATION ${LIB_INSTALL_DIR}/telephony/plugins) +INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR}/telephony/plugins) INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME tel-plugin-vmodem) diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..d7d27f0 --- /dev/null +++ b/include/config.h @@ -0,0 +1,38 @@ +/* + * tel-plugin-vmodem + * + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + gint vdpram_fd; + gint vdpram_watch_id; +} CustomData; + +void vmodem_config_check_cp_power(TcoreHal *hal); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __CONFIG_H__ */ diff --git a/include/vdpram.h b/include/vdpram.h index 02d11af..3e8de04 100644 --- a/include/vdpram.h +++ b/include/vdpram.h @@ -1,9 +1,7 @@ /* * tel-plugin-vmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Junhwan An + * 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. @@ -21,12 +19,13 @@ #ifndef __VDPRAM_H__ #define __VDPRAM_H__ -int vdpram_close(int fd); -int vdpram_open (void); -gboolean vdpram_poweron(int fd); -gboolean vdpram_poweroff(int fd); +gint vdpram_open (void); +gboolean vdpram_close(gint fd); + +gboolean vdpram_poweron(gint fd); +gboolean vdpram_poweroff(gint fd); -int vdpram_tty_read(int nFd, void* buf, size_t nbytes); -int vdpram_tty_write(int nFd, void* buf, size_t nbytes); +gint vdpram_tty_read(gint fd, void *buf, size_t buf_len); +gint vdpram_tty_write(gint fd, void *buf, size_t buf_len); -#endif +#endif /* __VDPRAM_H__ */ diff --git a/include/vdpram_dump.h b/include/vdpram_dump.h index 222d862..b75c261 100644 --- a/include/vdpram_dump.h +++ b/include/vdpram_dump.h @@ -1,9 +1,7 @@ /* * tel-plugin-vmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Junhwan An + * 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. @@ -21,10 +19,6 @@ #ifndef __VDPRAM_DUMP_H__ #define __VDPRAM_DUMP_H__ -#define TX 0 -#define RX 1 - -void vdpram_hex_dump(int dir, unsigned short data_len, void *data); - -#endif +void vdpram_hex_dump(gboolean tx, gushort data_len, void *data); +#endif /* __VDPRAM_DUMP_H__ */ diff --git a/packaging/tel-plugin-vmodem.spec b/packaging/tel-plugin-vmodem.spec index 5b3e8da..b8bf4d5 100644 --- a/packaging/tel-plugin-vmodem.spec +++ b/packaging/tel-plugin-vmodem.spec @@ -1,9 +1,13 @@ +%define major 3 +%define minor 0 +%define patchlevel 1 + Name: tel-plugin-vmodem -Summary: Telephony AT Virtual Modem library -Version: 0.1.8 -Release: 1 -Group: System/Libraries -License: Apache-2.0 +Version: %{major}.%{minor}.%{patchlevel} +Release: 1 +License: Apache-2.0 +Summary: Telephony Plug-in for AT communication with AT Virtual Modem (emulator) +Group: System/Libraries Source0: tel-plugin-vmodem-%{version}.tar.gz Source1001: tel-plugin-vmodem.manifest Requires(post): /sbin/ldconfig diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..7774474 --- /dev/null +++ b/src/config.c @@ -0,0 +1,303 @@ +/* + * tel-plugin-vmodem + * + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" + +#define AT_MODEM_PLUGIN_NAME "atmodem-plugin.so" + +/* Maximum Core objects per Logical HAL (indirectly per Channel) */ +#define MAX_CO_PER_CHANNEL 2 + +/* CP States */ +#define AT_CPAS_RESULT_READY 0 +#define AT_CPAS_RESULT_UNAVAIL 1 +#define AT_CPAS_RESULT_UNKNOWN 2 +#define AT_CPAS_RESULT_RINGING 3 +#define AT_CPAS_RESULT_CALL_PROGRESS 4 +#define AT_CPAS_RESULT_ASLEEP 5 + +typedef struct { + guint type; + gchar *name; +} VmodemSupportedCo; + +/* + * List of supported Core Object types + */ +static VmodemSupportedCo supported_modules[] = { + {CORE_OBJECT_TYPE_MODEM, "Modem"}, + {CORE_OBJECT_TYPE_NETWORK, "Network"}, + {CORE_OBJECT_TYPE_CALL, "Call"}, + {CORE_OBJECT_TYPE_SIM, "Sim"}, + {CORE_OBJECT_TYPE_SMS, "Sms"}, + {CORE_OBJECT_TYPE_SS, "SS"}, + {CORE_OBJECT_TYPE_PS, "PS"}, + {0, ""}, +}; + +static gboolean __check_cp_poweron(TcoreHal *hal); + +static void __assign_objects_to_hal(TcoreHal *hal) +{ + TcorePlugin *plugin; + gboolean ret; + guint i = 0; + + plugin = tcore_hal_ref_plugin(hal); + + while (supported_modules[i].type != 0) { + /* Add Core Object type for specific 'hal' */ + ret = tcore_server_add_cp_mapping_tbl_entry(plugin, + supported_modules[i].type, hal); + if (ret == TRUE) { + dbg("Core Object Type: [0x%x] - Success", + supported_modules[i].name); + } else { + err("Core Object Type: [0x%x] - Fail", + supported_modules[i].name); + } + + i++; + }; +} + +static void __deassign_objects_from_hal(TcoreHal *hal) +{ + TcorePlugin *plugin; + + plugin = tcore_hal_ref_plugin(hal); + + /* Remove mapping table entry */ + tcore_server_remove_cp_mapping_tbl_entry(plugin, hal); +} + +static gboolean __load_modem_plugin(gpointer data) +{ + TcoreHal *hal = (TcoreHal *)data; + TcorePlugin *plugin; + + dbg("Entry"); + + if (hal == NULL) { + err("hal is NULL"); + return FALSE; + } + + plugin = tcore_hal_ref_plugin(hal); + + /* Load Modem Plug-in */ + if (tcore_server_load_modem_plugin(tcore_plugin_ref_server(plugin), + plugin, AT_MODEM_PLUGIN_NAME) != TEL_RETURN_SUCCESS) { + err("Load Modem Plug-in - [FAIL]"); + + /* Clean-up */ + __deassign_objects_from_hal(hal); + + goto EXIT; + } else { + dbg("Load Modem Plug-in - [SUCCESS]"); + } + + return TRUE; + +EXIT: + /* TODO: Handle Deregister */ + + return FALSE; +} + +static void __on_confirmation_send_message(TcorePending *p, + TelReturn send_status, void *user_data) +{ + dbg("Message send confirmation - [%s]", + ((send_status != TEL_RETURN_SUCCESS) ? "FAIL" : "OK")); +} + +static void __on_timeout_check_cp_poweron(TcorePending *p, void *user_data) +{ + TcoreHal *hal = user_data; + guint data_len = 0; + char *data = "AT+CPAS"; + + data_len = sizeof(data); + + dbg("Resending Command: [%s] Command Length: [%d]", data, data_len); + + /* + * Retransmit 1st AT command (AT+CPAS) directly via HAL without disturbing + * pending queue. + * HAL was passed as user_data, re-using it + */ + tcore_hal_send_data(hal, data_len, (void *)data); +} + +static void __on_response_check_cp_poweron(TcorePending *pending, + guint data_len, const void *data, void *user_data) +{ + const TcoreAtResponse *resp = data; + TcoreHal *hal = user_data; + + GSList *tokens = NULL; + const char *line; + gboolean bpoweron = FALSE; + int response = 0; + + if (resp && resp->success) { + dbg("Check CP POWER - [OK]"); + + /* Parse AT Response */ + if (resp->lines) { + dbg("Check CP POWER - [OK]"); + line = (const char *) resp->lines->data; + dbg("line: %s", line); + tokens = tcore_at_tok_new(line); + dbg("tokens: %p", tokens); + if (g_slist_length(tokens) != 1) { + err("Invalid message"); + goto ERROR; + } + + dbg("Check CP POWER - [OK]"); + + response = atoi(g_slist_nth_data(tokens, 0)); + dbg("CPAS State: [%d]", response); + + switch (response) { + case AT_CPAS_RESULT_READY: + case AT_CPAS_RESULT_RINGING: + case AT_CPAS_RESULT_CALL_PROGRESS: + case AT_CPAS_RESULT_ASLEEP: + dbg("CP Power ON!!!"); + bpoweron = TRUE; + break; + + case AT_CPAS_RESULT_UNAVAIL: + case AT_CPAS_RESULT_UNKNOWN: + default: + err("Value is Unvailable/Unknown - but CP responded - proceed with Power ON!!!"); + bpoweron = TRUE; + break; + } + } + else { + err("Check CP POWER - [NOK] - lines NULL"); + } + } else { + err("Check CP POWER - [NOK]"); + } + +ERROR: + /* Free tokens */ + tcore_at_tok_free(tokens); + + if (bpoweron == TRUE) { + dbg("CP Power ON received"); + + /* Load Modem Plug-in */ + if(__load_modem_plugin(hal) == FALSE) { + /* TODO: Handle Deregistration */ + } + else { + dbg("Modem Plug-in loaded successfully"); + } + } else { + err("CP is not ready, send CPAS again"); + __check_cp_poweron(hal); + } +} + +static gboolean __check_cp_poweron(TcoreHal *hal) +{ + 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_COMMAND_TYPE_SINGLELINE); + + dbg("AT-Command: [%s] Prefix(if any): [%s] Command length: [%d]", + at_req->cmd, at_req->prefix, strlen(at_req->cmd)); + + tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT); + + /* Set timeout value and timeout callback */ + tcore_pending_set_timeout(pending, 10); + tcore_pending_set_timeout_callback(pending, + __on_timeout_check_cp_poweron, hal); + + /* Set request data and register Response and Send callbacks */ + tcore_pending_set_request_data(pending, 0, at_req); + tcore_pending_set_response_callback(pending, + __on_response_check_cp_poweron, hal); + tcore_pending_set_send_callback(pending, + __on_confirmation_send_message, NULL); + + /* Send command to CP */ + if (tcore_hal_send_request(hal, pending) != TEL_RETURN_SUCCESS) { + err("Failed to send CPAS"); + + /* Free resource */ + tcore_at_request_free(at_req); + tcore_pending_free(pending); + + return FALSE; + } + + dbg("Successfully sent CPAS"); + return TRUE; +} + +void vmodem_config_check_cp_power(TcoreHal *hal) +{ + gboolean ret; + dbg("Entry"); + + tcore_check_return(hal != NULL); + + ret = __check_cp_poweron(hal); + if (ret == TRUE) { + dbg("Successfully sent check CP Power ON command"); + + /* Add Core Objects list to HAL */ + __assign_objects_to_hal(hal); + } else { + err("Failed to send check CP Power ON command"); + /* TODO: Handle Deregister */ + } +} diff --git a/src/desc-vmodem.c b/src/desc-vmodem.c index 168a9ef..35a2c96 100644 --- a/src/desc-vmodem.c +++ b/src/desc-vmodem.c @@ -1,9 +1,7 @@ /* * tel-plugin-vmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Junhwan An + * 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. @@ -19,95 +17,39 @@ */ #include +#include #include #include #include -#include #include #include #include #include -#include #include -#include +#include #include -#include +#include "config.h" #include "vdpram.h" +#include "vdpram_dump.h" -#define SERVER_INIT_WAIT_TIMEOUT 500 +#define VMODEM_HAL_NAME "vmodem" -#define DEVICE_NAME_LEN_MAX 16 -#define DEVICE_NAME_PREFIX "pdp" +#define DEVICE_NAME_LEN_MAX 16 +#define DEVICE_NAME_PREFIX "pdp" -#define BUF_LEN_MAX 512 +#define BUF_LEN_MAX 512 -#define CORE_OBJECT_NAME_MAX 16 - -#define MODEM_PLUGIN_NAME "atmodem-plugin.so" - -struct custom_data { - int vdpram_fd; - guint watch_id_vdpram; -}; - -struct v_modules { - unsigned int co_type; - char co_name[CORE_OBJECT_NAME_MAX]; -}; +#define AT_CP_POWER_ON_TIMEOUT 500 -/* Supported Modules */ -static struct v_modules supported_modules[] = { - {CORE_OBJECT_TYPE_MODEM, "Modem"}, - {CORE_OBJECT_TYPE_CALL, "Call"}, - {CORE_OBJECT_TYPE_SS, "SS"}, - {CORE_OBJECT_TYPE_NETWORK, "Network"}, - {CORE_OBJECT_TYPE_PS, "PS"}, - {CORE_OBJECT_TYPE_SIM, "SIM"}, - {CORE_OBJECT_TYPE_SMS, "SMS"}, - {0, ""} -}; - -static void _assign_objects_to_hal(TcoreHal *hal) -{ - TcorePlugin *plugin; - int i; - gboolean ret; - - plugin = tcore_hal_ref_plugin(hal); - - /* Add Core Object type for specific 'hal' */ - for (i = 0 ; supported_modules[i].co_type != 0 ; i++) { - ret = tcore_server_add_cp_mapping_tbl_entry(plugin, - supported_modules[i].co_type, hal); - if (ret == TRUE) { - dbg("[VMODEM] Core Object: [%s] - [Success]", - supported_modules[i].co_name); - } else { - err("[VMODEM] Core Object: [%s] - [Fail]", - supported_modules[i].co_name); - } - } -} - -static void _deassign_objects_from_hal(TcoreHal *hal) -{ - TcorePlugin *plugin; - - plugin = tcore_hal_ref_plugin(hal); - - /* Remove mapping table entry */ - tcore_server_remove_cp_mapping_tbl_entry(plugin, hal); -} - -static guint _register_gio_watch(TcoreHal *h, int fd, void *callback) +static guint __register_gio_watch(TcoreHal *h, int fd, void *callback) { GIOChannel *channel = NULL; guint source; - dbg("[VMODEM] Register to Watch list - fd: [%d]", fd); + dbg("Register to Watch list - fd: [%d]", fd); if ((fd < 0) || (callback == NULL)) return 0; @@ -120,104 +62,69 @@ static guint _register_gio_watch(TcoreHal *h, int fd, void *callback) return source; } -static void _deregister_gio_watch(guint watch_id) +static void __deregister_gio_watch(guint watch_id) { - dbg("[VMODEM] Deregister Watch ID: [%d]", watch_id); + dbg("Deregister Watch ID: [%d]", watch_id); /* Remove source */ g_source_remove(watch_id); } -static gboolean _load_modem_plugin(gpointer data) +static TcoreHookReturn __on_hal_send(TcoreHal *hal, + guint data_len, void *data, void *user_data) { - TcoreHal *hal; - TcorePlugin *plugin; - struct custom_data *user_data; - - dbg("[VMMODEM] Entry"); - - if (data == NULL) { - err("[VMMODEM] data is NULL"); - return FALSE; - } - - hal = data; - plugin = tcore_hal_ref_plugin(hal); - - /* Load Modem Plug-in */ - if (tcore_server_load_modem_plugin(tcore_plugin_ref_server(plugin), - plugin, MODEM_PLUGIN_NAME) == TCORE_RETURN_FAILURE) { - err("[VMMODEM] Load Modem Plug-in - [FAIL]"); - - /* Clean-up */ - _deassign_objects_from_hal(hal); - - goto EXIT; - } else { - dbg("[VMMODEM] Load Modem Plug-in - [SUCCESS]"); - } - - /* To stop the cycle need to return FALSE */ - return FALSE; + /* Dumping Send (Write) data */ + vdpram_hex_dump(TRUE, data_len, data); -EXIT: - user_data = tcore_hal_ref_user_data(hal); - if (user_data == NULL) - return FALSE; - - /* Deregister from Watch list */ - _deregister_gio_watch(user_data->watch_id_vdpram); - - /* Free HAL */ - tcore_hal_free(hal); - - /* Close VDPRAM device */ - vdpram_close(user_data->vdpram_fd); - - /* Free custom data */ - g_free(user_data); + return TCORE_HOOK_RETURN_CONTINUE; +} - return FALSE; +static void __on_hal_recv(TcoreHal *hal, + guint data_len, const void *data, void *user_data) +{ + /* Dumping Receive (Read) data */ + vdpram_hex_dump(FALSE, data_len, (void *)data); } -static TReturn _modem_power(TcoreHal *hal, gboolean enable) +static gboolean __modem_power(TcoreHal *hal, gboolean enable) { - struct custom_data *user_data; + CustomData *user_data; user_data = tcore_hal_ref_user_data(hal); if (user_data == NULL) { - err("[VMODEM] User data is NULL"); - return TCORE_RETURN_FAILURE; + err("User data is NULL"); + return FALSE; } - if (enable == TRUE) { /* POWER ON */ + if (enable == TRUE) { /* POWER ON */ if (FALSE == vdpram_poweron(user_data->vdpram_fd)) { - err("[VMODEM] Power ON - [FAIL]"); - return TCORE_RETURN_FAILURE; + err("Power ON - [FAIL]"); + return FALSE; } /* Set Power State - ON */ tcore_hal_set_power_state(hal, TRUE); - } else { /* POWER OFF */ + } else { /* POWER OFF */ if (vdpram_poweroff(user_data->vdpram_fd) == FALSE) { - err("[VMODEM] Power OFF - [FAIL]"); - return TCORE_RETURN_FAILURE; + err("Power OFF - [FAIL]"); + return FALSE; } /* Set Power state - OFF */ tcore_hal_set_power_state(hal, FALSE); } - return TCORE_RETURN_SUCCESS; + return TRUE; } -static gboolean on_recv_vdpram_message(GIOChannel *channel, - GIOCondition condition, gpointer data) +static gboolean __on_recv_vdpram_message(GIOChannel *channel, + GIOCondition condition, gpointer data) { TcoreHal *hal = data; - struct custom_data *custom; - char buf[BUF_LEN_MAX]; + CustomData *custom; + char buf[BUF_LEN_MAX] = {0, }; int n = 0; + TelReturn ret; custom = tcore_hal_ref_user_data(hal); memset(buf, 0x0, BUF_LEN_MAX); @@ -225,53 +132,117 @@ static gboolean on_recv_vdpram_message(GIOChannel *channel, /* Read from Device */ n = vdpram_tty_read(custom->vdpram_fd, buf, BUF_LEN_MAX); if (n < 0) { - err("[VMODEM] Read error - Data received: [%d]", n); + err("Read error - Data received: [%d]", n); return TRUE; } - dbg("[VMODEM] DPRAM Receive - Data length: [%d]", n); + dbg("DPRAM Receive - Data length: [%d]", n); /* Emit receive callback */ + + + msg("\n---------- [RECV] Length of received data: [%d] ----------\n", n); + + /* Emit response callback */ tcore_hal_emit_recv_callback(hal, n, buf); + /* Dispatch received data to response handler */ + ret = tcore_hal_dispatch_response_data(hal, 0, n, buf); + msg("\n---------- [RECV FINISH] Receive processing: [%d] ----------\n", ret); + return TRUE; } -static TReturn hal_power(TcoreHal *hal, gboolean flag) +static gboolean __power_on(gpointer data) { - return _modem_power(hal, flag); + CustomData *user_data; + TcoreHal *hal = (TcoreHal*)data; + + dbg("Entry"); + + user_data = tcore_hal_ref_user_data(hal); + tcore_check_return_value_assert(user_data != NULL, TRUE); + + /* + * Open DPRAM device: Create and Open interface to CP + */ + user_data->vdpram_fd = vdpram_open(); + if (user_data->vdpram_fd < 1) { + TcorePlugin *plugin = tcore_hal_ref_plugin(hal); + Server *server = tcore_plugin_ref_server(plugin); + + err("Failed to Create/Open CP interface"); + + /* Notify server a modem error occured */ + tcore_server_send_server_notification(server, + TCORE_SERVER_NOTIFICATION_MODEM_ERR, 0, NULL); + + goto EXIT; + } + dbg("Created AP-CP interface"); + + /* Register to Watch llist */ + user_data->vdpram_watch_id = __register_gio_watch(hal, + user_data->vdpram_fd, __on_recv_vdpram_message); + dbg("fd: [%d] Watch ID: [%d]", user_data->vdpram_fd, user_data->vdpram_watch_id); + + /* Power ON VDPRAM device */ + if (__modem_power(hal, TRUE)) { + dbg("Power ON - [SUCCESS]"); + } else { + err("Power ON - [FAIL]"); + goto EXIT; + } + + /* CP is ONLINE, send AT+CPAS */ + vmodem_config_check_cp_power(hal); + + /* To stop the cycle need to return FALSE */ + return FALSE; + +EXIT: + /* TODO: Handle Deregister */ + + /* To stop the cycle need to return FALSE */ + return FALSE; } -static TReturn hal_send(TcoreHal *hal, unsigned int data_len, void *data) +/* HAL Operations */ +static TelReturn _hal_power(TcoreHal *hal, gboolean flag) { - int ret; - struct custom_data *user_data; + return __modem_power(hal, flag); +} + +static TelReturn _hal_send(TcoreHal *hal, + guint data_len, void *data) +{ + CustomData *user_data; + gint ret; if (tcore_hal_get_power_state(hal) == FALSE) { - err("[VMODEM] HAL Power state - OFF"); - return TCORE_RETURN_FAILURE; + err("HAL Power state - OFF"); + return TEL_RETURN_FAILURE; } user_data = tcore_hal_ref_user_data(hal); if (user_data == NULL) { - err("[VMODEM] User data is NULL"); - return TCORE_RETURN_FAILURE; + err("User data is NULL"); + return TEL_RETURN_FAILURE; } ret = vdpram_tty_write(user_data->vdpram_fd, data, data_len); - if(ret < 0) { - err("[VMODEM] Write failed"); - return TCORE_RETURN_FAILURE; - } - else { - dbg("vdpram_tty_write success ret=%d (fd=%d, len=%d)", ret, user_data->vdpram_fd, data_len); - return TCORE_RETURN_SUCCESS; + if(ret < 0) { + err("Write failed"); + return TEL_RETURN_FAILURE; } + dbg("vdpram_tty_write success ret=%d (fd=%d, len=%d)", + ret, user_data->vdpram_fd, data_len); + + 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) { char ifname[DEVICE_NAME_LEN_MAX]; int size = 0; @@ -280,27 +251,27 @@ static TReturn hal_setup_netif(CoreObject *co, char *control = NULL; if (cid > 3) { - err("[VMODEM] Context ID: [%d]", cid); - return TCORE_RETURN_EINVAL; + err("Context ID: [%d]", cid); + return TEL_RETURN_INVALID_PARAMETER; } if (enable == TRUE) { - dbg("[VMODEM] ACTIVATE - Context ID: [%d]", cid); + dbg("ACTIVATE - Context ID: [%d]", cid); control = "/sys/class/net/svnet0/pdp/activate"; } else { - dbg("[VMODEM] DEACTIVATE - Context ID: [%d]", cid); + dbg("DEACTIVATE - Context ID: [%d]", cid); control = "/sys/class/net/svnet0/pdp/deactivate"; } fd = open(control, O_WRONLY); if (fd < 0) { - err("[VMODEM] Failed to Open interface: [%s]", control); + err("Failed to Open interface: [%s]", control); /* Invoke callback function */ if (func) func(co, -1, NULL, user_data); - return TCORE_RETURN_FAILURE; + return TEL_RETURN_FAILURE; } /* Context ID needs to be written to the Device */ @@ -312,25 +283,25 @@ static TReturn hal_setup_netif(CoreObject *co, /* Device name */ snprintf(ifname, DEVICE_NAME_LEN_MAX, "%s%d", DEVICE_NAME_PREFIX, (cid - 1)); - dbg("[VMODEM] Interface Name: [%s]", ifname); + dbg("Interface Name: [%s]", ifname); /* Invoke callback function */ if (func) func(co, 0, ifname, user_data); - return TCORE_RETURN_SUCCESS; + return TEL_RETURN_SUCCESS; } /* HAL Operations */ -static struct tcore_hal_operations hal_ops = { - .power = hal_power, - .send = hal_send, - .setup_netif = hal_setup_netif, +static TcoreHalOperations hal_ops = { + .power = _hal_power, + .send = _hal_send, + .setup_netif = _hal_setup_netif, }; static gboolean on_load() { - dbg("[VMODEM] Load!!!"); + dbg("Load!!!"); return TRUE; } @@ -338,148 +309,105 @@ static gboolean on_load() static gboolean on_init(TcorePlugin *plugin) { TcoreHal *hal; - struct custom_data *data; + CustomData *data; + dbg("Init!!!"); - dbg("[VMODEM] Init!!!"); + tcore_check_return_value_assert(plugin != NULL, FALSE); - if (plugin == NULL) { - err("[VMODEM] PLug-in is NULL"); - return FALSE; - } - - /* Register Modem Interface Plug-in */ - if (tcore_server_register_modem(tcore_plugin_ref_server(plugin), plugin) - == FALSE) { - err("[VMODEM] Registration Failed"); - return FALSE; - } - dbg("[VMODEM] Registered from Server"); - - data = g_try_new0(struct custom_data, 1); - if (data == NULL) { - err("[VMODEM] Failed to allocate memory for Custom data"); - - /* Unregister from Server */ - tcore_server_unregister_modem(tcore_plugin_ref_server(plugin), plugin); - return FALSE; - } + /* Custom data for Modem Interface Plug-in */ + data = tcore_malloc0(sizeof(CustomData)); + dbg("Created custom data memory"); - /* - * Open DPRAM device - */ - data->vdpram_fd = vdpram_open(); - - /* - * Create and initialize HAL - */ - hal = tcore_hal_new(plugin, "vmodem", &hal_ops, TCORE_HAL_MODE_CUSTOM); + /* Create Physical HAL */ + hal = tcore_hal_new(plugin, VMODEM_HAL_NAME, + &hal_ops, TCORE_HAL_MODE_AT); if (hal == NULL) { - /* Close VDPRAM device */ - vdpram_close(data->vdpram_fd); - - /* Fre custom data */ - g_free(data); - - /* Unregister from Server */ - tcore_server_unregister_modem(tcore_plugin_ref_server(plugin), plugin); - + err("Failed to Create Physical HAL"); + tcore_free(data); return FALSE; } + dbg("HAL [0x%x] created", hal); /* Set HAL as Modem Interface Plug-in's User data */ tcore_plugin_link_user_data(plugin, hal); - /* Link custom data to HAL user data */ + /* Link Custom data to HAL's 'user_data' */ tcore_hal_link_user_data(hal, data); - /* Register to Watch llist */ - data->watch_id_vdpram = _register_gio_watch(hal, - data->vdpram_fd, on_recv_vdpram_message); - dbg("[VMODEM] fd: [%d] Watch ID: [%d]", - data->vdpram_fd, data->watch_id_vdpram); + /* Add callbacks for Send/Receive Hooks */ + tcore_hal_add_send_hook(hal, __on_hal_send, NULL); + tcore_hal_add_recv_callback(hal, __on_hal_recv, NULL); + dbg("Added Send hook and Receive callback"); - /* Power ON VDPRAM device */ - if (_modem_power(hal, TRUE) == TCORE_RETURN_SUCCESS) { - dbg("[VMODEM] Power ON - [SUCCESS]"); - } else { - err("[VMODEM] Power ON - [FAIL]"); - goto EXIT; - } + /* Set HAL state to Power OFF (FALSE) */ + (void)tcore_hal_set_power_state(hal, FALSE); + dbg("HAL Power State: Power OFF"); - /* Add Core Objects list to HAL */ - _assign_objects_to_hal(hal); + /* Resgister to Server */ + if (tcore_server_register_modem(tcore_plugin_ref_server(plugin), + plugin) == FALSE) { + err("Registration Failed"); + + tcore_hal_free(hal); + tcore_free(data); + return FALSE; + } + dbg("Registered from Server"); /* Check CP Power ON */ - g_timeout_add_full(G_PRIORITY_HIGH, SERVER_INIT_WAIT_TIMEOUT, _load_modem_plugin, hal, 0); + g_timeout_add_full(G_PRIORITY_HIGH, + AT_CP_POWER_ON_TIMEOUT, __power_on, hal, NULL); - dbg("[VMMODEM] Exit"); return TRUE; - -EXIT: - /* Deregister from Watch list */ - _deregister_gio_watch(data->watch_id_vdpram); - - /* Free HAL */ - tcore_hal_free(hal); - - /* Close VDPRAM device */ - vdpram_close(data->vdpram_fd); - - /* Free custom data */ - g_free(data); - - /* Unregister from Server */ - tcore_server_unregister_modem(tcore_plugin_ref_server(plugin), plugin); - - return FALSE; } static void on_unload(TcorePlugin *plugin) { TcoreHal *hal; - struct custom_data *user_data; + CustomData *user_data; + dbg("Unload!!!"); - dbg("[VMODEM] Unload!!!"); + tcore_check_return_assert(plugin != NULL); - if (plugin == NULL) - return; + /* Unload Modem Plug-in */ + tcore_server_unload_modem_plugin(tcore_plugin_ref_server(plugin), plugin); + + /* Unregister Modem Interface Plug-in from Server */ + tcore_server_unregister_modem(tcore_plugin_ref_server(plugin), plugin); + dbg("Unregistered from Server"); + /* HAL cleanup */ hal = tcore_plugin_ref_user_data(plugin); - if (hal == NULL) + if (hal == NULL) { + err("HAL is NULL"); return; + } - /* Unload Modem Plug-in */ -#if 0 /* TODO - Open the code below */ - tcore_server_unload_modem_plugin(tcore_plugin_ref_server(plugin), plugin); -#endif user_data = tcore_hal_ref_user_data(hal); if (user_data == NULL) return; /* Deregister from Watch list */ - _deregister_gio_watch(user_data->watch_id_vdpram); - dbg("[VMODEM] Deregistered Watch ID"); - - /* Free HAL */ - tcore_hal_free(hal); - dbg("[VMODEM] Freed HAL"); + __deregister_gio_watch(user_data->vdpram_watch_id); + dbg("Deregistered Watch ID"); /* Close VDPRAM device */ - vdpram_close(user_data->vdpram_fd); - dbg("[VMODEM] Closed VDPRAM device"); + (void)vdpram_close(user_data->vdpram_fd); + dbg("Closed VDPRAM device"); /* Free custom data */ g_free(user_data); - tcore_server_unregister_modem(tcore_plugin_ref_server(plugin), plugin); - dbg("[VMODEM] Unregistered from Server"); + /* Free HAL */ + tcore_hal_free(hal); + dbg("Freed HAL"); - dbg("[VMODEM] Unloaded MODEM"); + dbg("Unloaded MODEM Interface Plug-in"); } -/* VMODEM Descriptor Structure */ -struct tcore_plugin_define_desc plugin_define_desc = { - .name = "VMODEM", +/* VMODEM (Modem Interface Plug-in) descriptor */ +EXPORT_API struct tcore_plugin_define_desc plugin_define_desc = { + .name = "vmodem", .priority = TCORE_PLUGIN_PRIORITY_HIGH, .version = 1, .load = on_load, diff --git a/src/vdpram.c b/src/vdpram.c index 078e914..07eca2a 100644 --- a/src/vdpram.c +++ b/src/vdpram.c @@ -1,9 +1,7 @@ /* * tel-plugin-vmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Junhwan An + * 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. @@ -32,9 +30,8 @@ #include #include -#include "legacy/TelUtility.h" + #include "vdpram.h" -#include "vdpram_dump.h" #ifndef TIOCMODG # ifdef TIOCMGET @@ -56,35 +53,37 @@ # endif #endif +#define VDPRAM_OPEN_PATH "/dev/vdpram0" + +/* DPRAM ioctls for DPRAM tty devices */ +#define IOC_MZ_MAGIC ('h') +#define HN_DPRAM_PHONE_ON _IO (IOC_MZ_MAGIC, 0xd0) +#define HN_DPRAM_PHONE_OFF _IO (IOC_MZ_MAGIC, 0xd1) +#define HN_DPRAM_PHONE_GETSTATUS _IOR(IOC_MZ_MAGIC, 0xd2, guint) + /* Retry parameters */ #define SLEEP_TIME_IN_SEC 0 #define SLEEP_TIME_IN_MSEC 50 -#define MAX_RETRY_COUNT 10 +#define MAX_RETRY_COUNT 10 -typedef struct _tty_old_setting_t { - int fd; - struct termios termiosVal; - struct _tty_old_setting_t *next; - struct _tty_old_setting_t *prev; -} tty_old_setting_t; - -#define VDPRAM_OPEN_PATH "/dev/vdpram0" +typedef struct tty_old_setting TtyOldSetting; -/* DPRAM ioctls for DPRAM tty devices */ -#define IOC_MZ_MAGIC ('h') -#define HN_DPRAM_PHONE_ON _IO (IOC_MZ_MAGIC, 0xd0) -#define HN_DPRAM_PHONE_OFF _IO (IOC_MZ_MAGIC, 0xd1) -#define HN_DPRAM_PHONE_GETSTATUS _IOR(IOC_MZ_MAGIC, 0xd2, unsigned int) +struct tty_old_setting { + gint fd; + struct termios termiosVal; + TtyOldSetting *next; + TtyOldSetting *prev; +}; -static tty_old_setting_t *ttyold_head = NULL; +static TtyOldSetting *ttyold_head = NULL; /* - * Insert TTY old settings. + * Insert TTY old settings */ -static void __insert_tty_oldsetting(tty_old_setting_t *me) +static void __insert_tty_oldsetting(TtyOldSetting *me) { - dbg("Function Entrance"); + dbg("Enter"); if (me == NULL) return; @@ -98,42 +97,31 @@ static void __insert_tty_oldsetting(tty_old_setting_t *me) } /* - * Search TTY old settings. + * Search TTY old settings */ -static tty_old_setting_t *__search_tty_oldsetting(int fd) +static TtyOldSetting *__search_tty_oldsetting(gint fd) { - tty_old_setting_t *tty = NULL; - - dbg("Function Entrance"); - - if (ttyold_head == NULL) - return NULL; + TtyOldSetting *tty = ttyold_head; - tty = ttyold_head; + dbg("Enter"); - do { + while (tty) { if (tty->fd == fd) { - dbg("oldsetting for inputted fd [%d] is found", fd); + dbg("tty for fd [%d] found!!!", fd); break; - } else { - if (tty->next == NULL) { - err("No oldsetting found!!!"); - tty = NULL; - break; - } - tty = tty->next; } - } while (1); + tty = tty->next; + }; return tty; } /* - * Remove TTY old settings. + * Remove TTY old settings */ -static void __remove_tty_oldsetting(tty_old_setting_t *me) +static void __remove_tty_oldsetting(TtyOldSetting *me) { - dbg( "Function Enterence."); + dbg("Enter"); if (me == NULL) return; @@ -148,18 +136,18 @@ static void __remove_tty_oldsetting(tty_old_setting_t *me) } /* - * Set hardware flow control. + * Set hardware flow control */ -static void __tty_sethwf(int fd, int on) +static void __tty_sethwf(gint fd, gint on) { struct termios tty; - dbg("Function Entrance"); + dbg("Enter"); if (tcgetattr(fd, &tty)) err("__tty_sethwf: tcgetattr:"); - if (on) + if (on == 1) tty.c_cflag |= CRTSCTS; else tty.c_cflag &= ~CRTSCTS; @@ -169,13 +157,13 @@ static void __tty_sethwf(int fd, int on) } /* - * Set RTS line. Sometimes dropped. Linux specific? + * Set RTS line. Sometimes dropped. Linux specific? */ -static int __tty_setrts(int fd) +static gint __tty_setrts(gint fd) { - int mcs; + gint mcs; - dbg("Function Entrance"); + dbg("Enter"); if (-1 == ioctl(fd, TIOCMODG, &mcs)) err("icotl: TIOCMODG"); @@ -189,35 +177,36 @@ static int __tty_setrts(int fd) } /* - * Set baudrate, parity and number of bits. + * Set baudrate, parity and number of bits */ -static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop, int hwf, int swf) +static gboolean __tty_setparms(gint fd, + gchar *baudr, gchar *par, gchar *bits, gchar *stop, gint hwf, gint swf) { - int spd = -1; - int newbaud; - int bit = bits[0]; - int stop_bit = stop[0]; + gint spd = -1; + gint newbaud; + gint bit = bits[0]; + gint stop_bit = stop[0]; struct termios tty; - tty_old_setting_t *old_setting = NULL; + TtyOldSetting *old_setting = NULL; - dbg("Function Entrance"); + dbg("Enter"); - old_setting = g_try_new0(tty_old_setting_t, 1); + old_setting = g_try_new0(TtyOldSetting, 1); if (old_setting == NULL) - return TAPI_API_SYSTEM_OUT_OF_MEM; + return FALSE; old_setting->fd = fd; if (tcgetattr(fd, &tty) < 0) { g_free(old_setting); - return TAPI_API_TRANSPORT_LAYER_FAILURE; + return FALSE; } if (tcgetattr(fd, &old_setting->termiosVal) < 0) { g_free(old_setting); - return TAPI_API_TRANSPORT_LAYER_FAILURE; + return FALSE; } __insert_tty_oldsetting(old_setting); @@ -232,54 +221,54 @@ static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop if ((newbaud = (atol(baudr) / 100)) == 0 && baudr[0] != '0') newbaud = -1; - switch(newbaud) { - case 0: - spd = 0; - break; + switch (newbaud) { + case 0: + spd = 0; + break; - case 3: - spd = B300; - break; + case 3: + spd = B300; + break; - case 6: - spd = B600; - break; + case 6: + spd = B600; + break; - case 12: - spd = B1200; - break; + case 12: + spd = B1200; + break; - case 24: - spd = B2400; - break; + case 24: + spd = B2400; + break; - case 48: - spd = B4800; - break; + case 48: + spd = B4800; + break; - case 96: - spd = B9600; - break; + case 96: + spd = B9600; + break; - case 192: - spd = B19200; - break; + case 192: + spd = B19200; + break; - case 384: - spd = B38400; - break; + case 384: + spd = B38400; + break; - case 576: - spd = B57600; - break; + case 576: + spd = B57600; + break; - case 1152: - spd = B115200; - break; + case 1152: + spd = B115200; + break; - default: - err("invaid baud rate"); - break; + default: + err("invaid baud rate"); + break; } if (spd != -1) { @@ -287,34 +276,34 @@ static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop cfsetispeed(&tty, (speed_t) spd); } - switch(bit) { - case '5': - tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; - break; + switch (bit) { + case '5': + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; + break; - case '6': - tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; - break; + case '6': + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; + break; - case '7': - tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; - break; + case '7': + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; + break; - case '8': - default: - tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; - break; + case '8': + default: + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; + break; } - switch(stop_bit) { - case '1': - tty.c_cflag &= ~CSTOPB; - break; + switch (stop_bit) { + case '1': + tty.c_cflag &= ~CSTOPB; + break; - case '2': - default: - tty.c_cflag |= CSTOPB; - break; + case '2': + default: + tty.c_cflag |= CSTOPB; + break; } /* Set into raw, no echo mode */ @@ -339,34 +328,34 @@ static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop if (tcsetattr(fd, TCSANOW, &tty) < 0) { g_free(old_setting); - return TAPI_API_TRANSPORT_LAYER_FAILURE; + return FALSE; } __tty_setrts(fd); __tty_sethwf(fd, hwf); - return TAPI_API_SUCCESS; + return TRUE; } /* - * Close TTY Device. + * Close TTY Device */ -static int __tty_close(int fd) +static gboolean __tty_close(gint fd) { - tty_old_setting_t *old_setting = NULL; + TtyOldSetting *old_setting = NULL; - dbg("Function Entrance"); + dbg("Enter"); /* Get previous settings */ old_setting = __search_tty_oldsetting(fd); if (old_setting == NULL) { - dbg("[VDPRAM] No previous settings found!!!"); - return TAPI_API_SUCCESS; + dbg("No previous settings found!!!"); + return TRUE; } if (tcsetattr(fd, TCSAFLUSH, &old_setting->termiosVal) < 0) { - err("[VDPRAM] Close failed"); - return TAPI_API_TRANSPORT_LAYER_FAILURE; + err("Close failed"); + return FALSE; } /* Remove the previous setting configured */ @@ -378,30 +367,30 @@ static int __tty_close(int fd) /* Close fd */ close(fd); - return TAPI_API_SUCCESS; + return TRUE; } /* - * Wait on select. + * Wait on select */ -static void __sleep(int sec, int msec) +static void __sleep(gint sec, gint msec) { - struct timeval tv; + struct timeval tv; - tv.tv_sec = sec; - tv.tv_usec = msec; + tv.tv_sec = sec; + tv.tv_usec = msec; - select(0, NULL, NULL, NULL, &tv); + select(0, NULL, NULL, NULL, &tv); } /* * Close the VDPRAM device */ -int vdpram_close(int fd) +gboolean vdpram_close(gint fd) { - int ret = TAPI_API_SUCCESS; + gint ret; - dbg("Function Entrance"); + dbg("Enter"); /* Close VDPRAM Device */ ret = __tty_close(fd); @@ -412,125 +401,120 @@ int vdpram_close(int fd) /* * Open the VDPRAM device */ -int vdpram_open (void) +gint vdpram_open (void) { - int rv = -1; - int fd = -1; - int val = 0; - unsigned int cmd =0; + gint rv = -1; + gint fd = -1; + gint val = 0; + guint cmd =0; - dbg("Function Enterence."); + dbg("Enter"); /* Open DPRAM device */ fd = open(VDPRAM_OPEN_PATH, O_RDWR); if (fd < 0) { - err("[VDPRAM] Open VDPRAM file - [FAIL] Error: [%s]", strerror(errno)); + err("Open VDPRAM file - [FAIL] Error: [%s]", strerror(errno)); return rv; } else { - dbg("[VDPRAM] Open VDPRAM file - [SUCCESS] fd: [%d] path: [%s]", - fd, VDPRAM_OPEN_PATH); + dbg("Open VDPRAM file - [SUCCESS] fd: [%d] path: [%s]", + fd, VDPRAM_OPEN_PATH); } /* Set device parameters */ - if (__tty_setparms(fd, "115200", "N", "8", "1", 0, 0) != TAPI_API_SUCCESS) { - err("[VDPRAM] Set TTY device parameters - [FAIL]"); + if (__tty_setparms(fd, "115200", "N", "8", "1", 0, 0) != TRUE) { + err("Set TTY device parameters - [FAIL]"); /* Close VDPRAM Device */ - vdpram_close(fd); + (void)vdpram_close(fd); return rv; } else { - dbg("[VDPRAM] Set TTY device parameters - [SUCCESS]"); + dbg("Set TTY device parameters - [SUCCESS]"); } /* TODO: No need to check Status. Delete */ cmd = HN_DPRAM_PHONE_GETSTATUS; if (ioctl(fd, cmd, &val) < 0) { - err("[VDPRAM] Get Phone status - [FAIL] fd: [d] cmd: [%d] val: [%d]", - fd, cmd, val); + err("Get Phone status - [FAIL] fd: [d] cmd: [%d] val: [%d]", + fd, cmd, val); /* Close Device */ - vdpram_close(fd); + (void)vdpram_close(fd); return rv; } else { - dbg("[VDPRAM] Get Phone status - [SUCCESS]"); + dbg("Get Phone status - [SUCCESS]"); } return fd; } /* - * Power ON the Phone. + * Power ON the Phone */ -gboolean vdpram_poweron(int fd) +gboolean vdpram_poweron(gint fd) { if (ioctl(fd, HN_DPRAM_PHONE_ON, NULL) < 0) { - err("[VDPRAM] Phone Power ON [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno)); + err("Phone Power ON [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno)); return FALSE; } else { - dbg("[VDPRAM] Phone Power ON [SUCCESS] - fd: [%d]", fd); + dbg("Phone Power ON [SUCCESS] - fd: [%d]", fd); return TRUE; } } /* - * Power OFF the Phone. + * Power OFF the Phone */ -gboolean vdpram_poweroff(int fd) +gboolean vdpram_poweroff(gint fd) { if (ioctl(fd, HN_DPRAM_PHONE_OFF, NULL) < 0) { - err("[VDPRAM] Phone Power OFF [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno)); + err("Phone Power OFF [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno)); return FALSE; } else { - dbg("[VDPRAM] Phone Power OFF [SUCCESS] - fd: [%d]", fd); + dbg("Phone Power OFF [SUCCESS] - fd: [%d]", fd); return TRUE; } } /* - * Read data from VDPRAM. + * Read data from VDPRAM */ -int vdpram_tty_read(int nFd, void* buf, size_t nbytes) +gint vdpram_tty_read(gint fd, void *buf, size_t buf_len) { - int actual = 0; + gint actual = 0; - if ((actual = read(nFd, buf, nbytes)) < 0) { - err("[VDPRAM] Read [FAIL] - fd: [%d] Error: [%s]", nFd, strerror(errno)); + if ((actual = read(fd, buf, buf_len)) < 0) { + err("Read [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno)); } - /* Dumping Read data */ - vdpram_hex_dump(RX, actual, buf); - return actual; } /* - * Write data to VDPRAM. + * Write data to VDPRAM */ -int vdpram_tty_write(int nFd, void* buf, size_t nbytes) +gint vdpram_tty_write(gint fd, void *buf, size_t buf_len) { - int ret; size_t actual = 0; - int retry = 0; - - do { - vdpram_hex_dump(TX, nbytes, buf); + guint retry = 0; + gint ret; + while(actual < buf_len) { /* Write to Device */ - ret = write(nFd, (unsigned char* )buf, nbytes - actual); + ret = write(fd, (guchar *)buf, buf_len - actual); if (ret < 0) { - err("[VDPRAM] Write [FAIL] - fd: [%d] Error: [%s]", - nFd, strerror(errno)); + err("Write [FAIL] - fd: [%d] Error: [%s]", + fd, strerror(errno)); if ((errno == EAGAIN) || (errno == EBUSY)) { /* Sleep for 50 msecs */ __sleep(SLEEP_TIME_IN_SEC, SLEEP_TIME_IN_MSEC); if (retry == MAX_RETRY_COUNT) { - err("[VDPRAM] Maximum retries completed!!!"); + err("Maximum retries completed!!!"); return 0; } @@ -538,17 +522,17 @@ int vdpram_tty_write(int nFd, void* buf, size_t nbytes) continue; } - if (actual != nbytes) - err("[VDPRAM] Write [FAIL] - fd: [%d]", nFd); + if (actual != buf_len) + err("Write [FAIL] - fd: [%d]", fd); - err("[VDPRAM] Write [FAIL] - Error: [%s]", strerror(errno)); + err("Write [FAIL] - Error: [%s]", strerror(errno)); return actual; } actual += ret; buf += ret; - dbg("[VDPRAM] Write Actual bytes: [%d] Written bytes: [%d]", actual, ret); - } while(actual < nbytes); + dbg("Write Actual bytes: [%d] Written bytes: [%d]", actual, ret); + }; return actual; } diff --git a/src/vdpram_dump.c b/src/vdpram_dump.c index 7befabd..d44836e 100644 --- a/src/vdpram_dump.c +++ b/src/vdpram_dump.c @@ -1,9 +1,7 @@ /* * tel-plugin-vmodem * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Junhwan An + * 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. @@ -21,60 +19,31 @@ #include #include #include -#include - -#include "vdpram_dump.h" - -static void hex_dump(char *pad, int size, const void *data) -{ - char buf[255] = {0, }; - char hex[4] = {0, }; - int i; - unsigned char *p; - - if (size <= 0) { - msg("%sno data", pad); - return; - } - - p = (unsigned char *)data; - snprintf(buf, 255, "%s%04X: ", pad, 0); - for (i = 0; i - if ((i + 1) % 8 == 0) { - if ((i + 1) % 16 == 0) { - msg("%s", buf); - memset(buf, 0, 255); - snprintf(buf, 255, "%s%04X: ", pad, i + 1); - } - else { - strcat(buf, " "); - } - } - } +#include +#include +#include - msg("%s", buf); -} +#include "vdpram_dump.h" -void vdpram_hex_dump(int dir, unsigned short data_len, void *data) +void vdpram_hex_dump(gboolean tx, gushort data_len, void *data) { char *d; if(!data) return; - if (dir == RX) - d = "[RX]"; - else + if (tx == TRUE) d = "[TX]"; + else + d = "[RX]"; - msg(""); - msg(" %s\tlen=%d\t%s", d, data_len, (char *)data); - hex_dump(" ", data_len, data); + msg("\n====== Data DUMP ======\n"); - msg(""); -} + msg(" %s\tData length: [%d] -", d, data_len); + tcore_util_hex_dump(" ", (gint)data_len, data); + msg("\n====== Data DUMP ======\n"); +} -- 2.7.4