Initial refactoring merge 99/19099/1 accepted/tizen_3.0.2014.q3_common accepted/tizen_3.0.m14.3_ivi accepted/tizen_generic accepted/tizen_ivi_panda tizen_3.0.2014.q3_common tizen_3.0.2014.q4_common tizen_3.0.2015.q1_common tizen_3.0.m14.2_ivi tizen_3.0.m14.3_ivi tizen_3.0_ivi accepted/tizen/generic/20140408.094928 accepted/tizen/ivi/20140410.192404 accepted/tizen/ivi/panda/20140408.203145 accepted/tizen/mobile/20140409.082552 submit/tizen/20140408.080659 submit/tizen_mobile/20141120.000000 tizen_3.0.2014.q3_common_release tizen_3.0.m14.2_ivi_release tizen_3.0.m14.3_ivi_release tizen_3.0_ivi_release
authorDongchul Lim <dc7.lim@samsung.com>
Mon, 7 Apr 2014 10:54:39 +0000 (19:54 +0900)
committerDongchul Lim <dc7.lim@samsung.com>
Mon, 7 Apr 2014 10:55:00 +0000 (19:55 +0900)
Change-Id: I640c70af01dec228c3c160ad3f0c28c8481768ee

CMakeLists.txt
include/config.h [new file with mode: 0644]
include/vdpram.h
include/vdpram_dump.h
packaging/tel-plugin-vmodem.spec
src/config.c [new file with mode: 0644]
src/desc-vmodem.c
src/vdpram.c
src/vdpram_dump.c

index 0c08119..d621c71 100644 (file)
@@ -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 (file)
index 0000000..d7d27f0
--- /dev/null
@@ -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__ */
index 02d11af..3e8de04 100644 (file)
@@ -1,9 +1,7 @@
 /*\r
  * tel-plugin-vmodem\r
  *\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: Junhwan An <jh48.an@samsung.com>\r
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 #ifndef __VDPRAM_H__\r
 #define __VDPRAM_H__\r
 \r
-int vdpram_close(int fd);\r
-int vdpram_open (void);\r
-gboolean vdpram_poweron(int fd);
-gboolean vdpram_poweroff(int fd);
+gint vdpram_open (void);\r
+gboolean vdpram_close(gint fd);\r
+\r
+gboolean vdpram_poweron(gint fd);
+gboolean vdpram_poweroff(gint fd);
 \r
-int vdpram_tty_read(int nFd, void* buf, size_t nbytes);\r
-int vdpram_tty_write(int nFd, void* buf, size_t nbytes);\r
+gint vdpram_tty_read(gint fd, void *buf, size_t buf_len);\r
+gint vdpram_tty_write(gint fd, void *buf, size_t buf_len);\r
 \r
-#endif\r
+#endif /* __VDPRAM_H__ */\r
index 222d862..b75c261 100644 (file)
@@ -1,9 +1,7 @@
 /*\r
  * tel-plugin-vmodem\r
  *\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: Junhwan An <jh48.an@samsung.com>\r
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 #ifndef __VDPRAM_DUMP_H__\r
 #define __VDPRAM_DUMP_H__\r
 \r
-#define TX                             0
-#define RX                             1
-\r
-void vdpram_hex_dump(int dir, unsigned short data_len, void *data);\r
-\r
-#endif\r
+void vdpram_hex_dump(gboolean tx, gushort data_len, void *data);\r
 \r
+#endif /* __VDPRAM_DUMP_H__ */\r
index 5b3e8da..b8bf4d5 100644 (file)
@@ -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 (file)
index 0000000..7774474
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <glib.h>
+
+#include <tcore.h>
+#include <server.h>
+#include <plugin.h>
+#include <storage.h>
+#include <core_object.h>
+#include <hal.h>
+#include <at.h>
+
+#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 */
+       }
+}
index 168a9ef..35a2c96 100644 (file)
@@ -1,9 +1,7 @@
 /*
  * tel-plugin-vmodem
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Junhwan An <jh48.an@samsung.com>
+ * 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.
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
 #include <unistd.h>
-#include <stdlib.h>
 #include <time.h>
 #include <fcntl.h>
 
 #include <glib.h>
 
 #include <tcore.h>
-#include <plugin.h>
 #include <server.h>
-#include <user_request.h>
+#include <plugin.h>
 #include <hal.h>
-#include <core_object.h>
 
+#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,
index 078e914..07eca2a 100644 (file)
@@ -1,9 +1,7 @@
 /*\r
  * tel-plugin-vmodem\r
  *\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: Junhwan An <jh48.an@samsung.com>\r
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -32,9 +30,8 @@
 #include <glib.h>
 
 #include <log.h>\r
-#include "legacy/TelUtility.h"\r
+\r
 #include "vdpram.h"\r
-#include "vdpram_dump.h"\r
 \r
 #ifndef TIOCMODG\r
 #  ifdef TIOCMGET\r
 #  endif\r
 #endif\r
 \r
+#define VDPRAM_OPEN_PATH               "/dev/vdpram0"\r
+\r
+/* DPRAM ioctls for DPRAM tty devices */\r
+#define IOC_MZ_MAGIC                   ('h')\r
+#define HN_DPRAM_PHONE_ON              _IO (IOC_MZ_MAGIC, 0xd0)\r
+#define HN_DPRAM_PHONE_OFF             _IO (IOC_MZ_MAGIC, 0xd1)\r
+#define HN_DPRAM_PHONE_GETSTATUS       _IOR(IOC_MZ_MAGIC, 0xd2, guint)\r
+\r
 /* 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;\r
-       struct  termios  termiosVal;\r
-       struct  _tty_old_setting_t *next;\r
-       struct  _tty_old_setting_t *prev;\r
-} tty_old_setting_t;\r
-\r
-#define VDPRAM_OPEN_PATH               "/dev/vdpram0"\r
+typedef struct tty_old_setting TtyOldSetting;\r
 \r
-/* DPRAM ioctls for DPRAM tty devices */\r
-#define IOC_MZ_MAGIC           ('h')\r
-#define HN_DPRAM_PHONE_ON                      _IO (IOC_MZ_MAGIC, 0xd0)\r
-#define HN_DPRAM_PHONE_OFF                     _IO (IOC_MZ_MAGIC, 0xd1)\r
-#define HN_DPRAM_PHONE_GETSTATUS       _IOR(IOC_MZ_MAGIC, 0xd2, unsigned int)\r
+struct tty_old_setting {
+       gint fd;\r
+       struct termios termiosVal;\r
+       TtyOldSetting *next;\r
+       TtyOldSetting *prev;\r
+};\r
 \r
-static tty_old_setting_t *ttyold_head = NULL;\r
+static TtyOldSetting *ttyold_head = NULL;\r
 \r
 /*
- *     Insert TTY old settings.
+ * Insert TTY old settings
  */
-static void __insert_tty_oldsetting(tty_old_setting_t *me)\r
+static void __insert_tty_oldsetting(TtyOldSetting *me)\r
 {\r
-       dbg("Function Entrance");
+       dbg("Enter");
 \r
        if (me == NULL)\r
                return;\r
@@ -98,42 +97,31 @@ static void __insert_tty_oldsetting(tty_old_setting_t *me)
 }\r
 \r
 /*
- *     Search TTY old settings.
+ * Search TTY old settings
  */
-static tty_old_setting_t *__search_tty_oldsetting(int fd)\r
+static TtyOldSetting *__search_tty_oldsetting(gint fd)\r
 {\r
-       tty_old_setting_t *tty = NULL;\r
-\r
-       dbg("Function Entrance");
-\r
-       if (ttyold_head == NULL)\r
-               return NULL;\r
+       TtyOldSetting *tty = ttyold_head;\r
 \r
-       tty = ttyold_head;\r
+       dbg("Enter");
 \r
-       do {
+       while (tty) {\r
                if (tty->fd == fd) {\r
-                       dbg("oldsetting for inputted fd [%d] is found", fd);
+                       dbg("tty for fd [%d] found!!!", fd);
                        break;\r
-               } else {
-                       if (tty->next == NULL) {\r
-                               err("No oldsetting found!!!");
-                               tty = NULL;\r
-                               break;\r
-                       }\r
-                       tty = tty->next;\r
                }\r
-       } while (1);
+               tty = tty->next;\r
+       };\r
 \r
        return tty;\r
 }\r
 \r
 /*
- *     Remove TTY old settings.
+ * Remove TTY old settings
  */
-static void __remove_tty_oldsetting(tty_old_setting_t *me)\r
+static void __remove_tty_oldsetting(TtyOldSetting *me)\r
 {\r
-       dbg( "Function Enterence.");\r
+       dbg("Enter");\r
 \r
        if (me == NULL)\r
                return;\r
@@ -148,18 +136,18 @@ static void __remove_tty_oldsetting(tty_old_setting_t *me)
 }\r
 \r
 /*
- *     Set hardware flow control.
+ * Set hardware flow control
  */
-static void __tty_sethwf(int fd, int on)\r
+static void __tty_sethwf(gint fd, gint on)\r
 {\r
        struct termios tty;\r
 \r
-       dbg("Function Entrance");
+       dbg("Enter");
 \r
        if (tcgetattr(fd, &tty))\r
                err("__tty_sethwf: tcgetattr:");\r
 \r
-       if (on)\r
+       if (on == 1)\r
                tty.c_cflag |= CRTSCTS;
        else\r
                tty.c_cflag &= ~CRTSCTS;
@@ -169,13 +157,13 @@ static void __tty_sethwf(int fd, int on)
 }\r
 \r
 /*\r
- *     Set RTS line. Sometimes dropped. Linux specific?
+ * Set RTS line. Sometimes dropped. Linux specific?
  */
-static int __tty_setrts(int fd)\r
+static gint __tty_setrts(gint fd)\r
 {\r
-       int mcs;\r
+       gint mcs;\r
 \r
-       dbg("Function Entrance");
+       dbg("Enter");
 \r
        if (-1 ==  ioctl(fd, TIOCMODG, &mcs))\r
                err("icotl: TIOCMODG");\r
@@ -189,35 +177,36 @@ static int __tty_setrts(int fd)
 }\r
 \r
 /*\r
- *     Set baudrate, parity and number of bits.
+ * Set baudrate, parity and number of bits
  */\r
-static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop, int hwf, int swf)\r
+static gboolean __tty_setparms(gint fd,\r
+       gchar *baudr, gchar *par, gchar *bits, gchar *stop, gint hwf, gint swf)\r
 {\r
-       int spd = -1;\r
-       int newbaud;\r
-       int bit = bits[0];\r
-       int stop_bit = stop[0];\r
+       gint spd = -1;\r
+       gint newbaud;\r
+       gint bit = bits[0];\r
+       gint stop_bit = stop[0];\r
 \r
        struct termios tty;\r
-       tty_old_setting_t *old_setting = NULL;\r
+       TtyOldSetting *old_setting = NULL;\r
 \r
-       dbg("Function Entrance");
+       dbg("Enter");
 \r
-       old_setting = g_try_new0(tty_old_setting_t, 1);
+       old_setting = g_try_new0(TtyOldSetting, 1);
 \r
        if (old_setting == NULL)\r
-               return TAPI_API_SYSTEM_OUT_OF_MEM;\r
+               return FALSE;\r
 \r
        old_setting->fd = fd;\r
 \r
        if (tcgetattr(fd, &tty) < 0) {\r
                g_free(old_setting);
-               return TAPI_API_TRANSPORT_LAYER_FAILURE;\r
+               return FALSE;\r
        }\r
 \r
        if (tcgetattr(fd, &old_setting->termiosVal) < 0) {\r
                g_free(old_setting);
-               return TAPI_API_TRANSPORT_LAYER_FAILURE;\r
+               return FALSE;\r
        }\r
 \r
        __insert_tty_oldsetting(old_setting);\r
@@ -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')\r
                newbaud = -1;\r
 \r
-       switch(newbaud) {
-               case 0:\r
-                       spd = 0;\r
-               break;
+       switch (newbaud) {
+       case 0:\r
+               spd = 0;\r
+       break;
 \r
-               case 3:\r
-                       spd = B300;\r
-               break;
+       case 3:\r
+               spd = B300;\r
+       break;
 \r
-               case 6:\r
-                       spd = B600;\r
-               break;
+       case 6:\r
+               spd = B600;\r
+       break;
 \r
-               case 12:\r
-                       spd = B1200;\r
-               break;
+       case 12:\r
+               spd = B1200;\r
+       break;
 \r
-               case 24:\r
-                       spd = B2400;\r
-               break;
+       case 24:\r
+               spd = B2400;\r
+       break;
 \r
-               case 48:\r
-                       spd = B4800;\r
-               break;
+       case 48:\r
+               spd = B4800;\r
+       break;
 \r
-               case 96:\r
-                       spd = B9600;\r
-               break;
+       case 96:\r
+               spd = B9600;\r
+       break;
 \r
-               case 192:\r
-                       spd = B19200;\r
-               break;
+       case 192:\r
+               spd = B19200;\r
+       break;
 \r
-               case 384:\r
-                       spd = B38400;\r
-               break;
+       case 384:\r
+               spd = B38400;\r
+       break;
 \r
-               case 576:\r
-                       spd = B57600;\r
-               break;
+       case 576:\r
+               spd = B57600;\r
+       break;
 \r
-               case 1152:\r
-                       spd = B115200;\r
-               break;
+       case 1152:\r
+               spd = B115200;\r
+       break;
 \r
-               default:\r
-                       err("invaid baud rate");\r
-               break;
+       default:\r
+               err("invaid baud rate");\r
+       break;
        }\r
 \r
        if (spd != -1) {\r
@@ -287,34 +276,34 @@ static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop
                cfsetispeed(&tty, (speed_t) spd);
        }\r
 \r
-       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;
 \r
-               case '6':
-                       tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6;
-               break;
+       case '6':
+               tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6;
+       break;
 \r
-               case '7':
-                       tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7;
-               break;
+       case '7':
+               tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7;
+       break;
 \r
-               case '8':
-               default:
-                       tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
-               break;
+       case '8':
+       default:
+               tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
+       break;
        }\r
 \r
-       switch(stop_bit) {
-               case '1':
-                       tty.c_cflag &= ~CSTOPB;
-               break;
+       switch (stop_bit) {
+       case '1':
+               tty.c_cflag &= ~CSTOPB;
+       break;
 \r
-               case '2':
-               default:
-                       tty.c_cflag |= CSTOPB;
-               break;
+       case '2':
+       default:
+               tty.c_cflag |= CSTOPB;
+       break;
        }\r
 \r
        /* Set into raw, no echo mode */\r
@@ -339,34 +328,34 @@ static int __tty_setparms(int fd, char* baudr, char* par, char* bits, char* stop
 \r
        if (tcsetattr(fd, TCSANOW, &tty) < 0) {\r
                g_free(old_setting);
-               return TAPI_API_TRANSPORT_LAYER_FAILURE;
+               return FALSE;
        }\r
 \r
        __tty_setrts(fd);\r
        __tty_sethwf(fd, hwf);\r
 \r
-       return TAPI_API_SUCCESS;\r
+       return TRUE;\r
 }\r
 \r
 /*
- *     Close TTY Device.
+ * Close TTY Device
  */
-static int __tty_close(int fd)\r
+static gboolean __tty_close(gint fd)\r
 {\r
-       tty_old_setting_t *old_setting = NULL;\r
+       TtyOldSetting *old_setting = NULL;\r
 \r
-       dbg("Function Entrance");
+       dbg("Enter");
 \r
        /* Get previous settings */
        old_setting = __search_tty_oldsetting(fd);\r
        if (old_setting == NULL) {
-               dbg("[VDPRAM] No previous settings found!!!");
-               return TAPI_API_SUCCESS;\r
+               dbg("No previous settings found!!!");
+               return TRUE;\r
        }
 \r
        if (tcsetattr(fd, TCSAFLUSH, &old_setting->termiosVal) < 0)     {\r
-               err("[VDPRAM] Close failed");
-               return TAPI_API_TRANSPORT_LAYER_FAILURE;\r
+               err("Close failed");
+               return FALSE;\r
        }\r
 \r
        /* Remove the previous setting configured */
@@ -378,30 +367,30 @@ static int __tty_close(int fd)
        /* Close fd */
        close(fd);\r
 \r
-       return TAPI_API_SUCCESS;\r
+       return TRUE;\r
 }\r
 \r
 /*\r
- *     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)\r
+gboolean vdpram_close(gint fd)\r
 {\r
-       int ret = TAPI_API_SUCCESS;\r
+       gint ret;\r
 \r
-       dbg("Function Entrance");
+       dbg("Enter");
 \r
        /* Close VDPRAM Device */
        ret = __tty_close(fd);\r
@@ -412,125 +401,120 @@ int vdpram_close(int fd)
 /*\r
  * Open the VDPRAM device
  */
-int vdpram_open (void)\r
+gint vdpram_open (void)\r
 {\r
-       int rv = -1;\r
-       int fd = -1;\r
-       int val = 0;\r
-       unsigned int cmd =0;\r
+       gint rv = -1;\r
+       gint fd = -1;\r
+       gint val = 0;\r
+       guint cmd =0;\r
 \r
-       dbg("Function Enterence.");
+       dbg("Enter");
 
        /* Open DPRAM device */
        fd = open(VDPRAM_OPEN_PATH, O_RDWR);\r
        if (fd < 0) {\r
-               err("[VDPRAM] Open VDPRAM file - [FAIL] Error: [%s]", strerror(errno));
+               err("Open VDPRAM file - [FAIL] Error: [%s]", strerror(errno));
                return rv;\r
        } 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);
        }\r
 \r
        /* 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]");
 \r
                /* Close VDPRAM Device */
-               vdpram_close(fd);\r
+               (void)vdpram_close(fd);\r
                return rv;\r
        }\r
        else {
-               dbg("[VDPRAM] Set TTY device parameters - [SUCCESS]");
+               dbg("Set TTY device parameters - [SUCCESS]");
        }
 \r
        /* TODO: No need to check Status. Delete */
        cmd = HN_DPRAM_PHONE_GETSTATUS;\r
        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);
 \r
                /* Close Device */
-               vdpram_close(fd);\r
+               (void)vdpram_close(fd);\r
 
                return rv;\r
        } else {
-               dbg("[VDPRAM] Get Phone status - [SUCCESS]");
+               dbg("Get Phone status - [SUCCESS]");
        }\r
 \r
        return fd;\r
 }\r
 \r
 /*\r
- *     Power ON the Phone.
+ * Power ON the Phone
  */
-gboolean vdpram_poweron(int fd)
+gboolean vdpram_poweron(gint fd)
 {\r
        if (ioctl(fd, HN_DPRAM_PHONE_ON, NULL) < 0) {\r
-               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;
        }\r
        else {\r
-               dbg("[VDPRAM] Phone Power ON [SUCCESS] - fd: [%d]", fd);
+               dbg("Phone Power ON [SUCCESS] - fd: [%d]", fd);
                return TRUE;
        }\r
 }\r
 \r
 /*
- *     Power OFF the Phone.
+ * Power OFF the Phone
  */\r
-gboolean vdpram_poweroff(int fd)
+gboolean vdpram_poweroff(gint fd)
 {\r
        if (ioctl(fd, HN_DPRAM_PHONE_OFF, NULL) < 0) {\r
-               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;
        }\r
        else {\r
-               dbg("[VDPRAM] Phone Power OFF [SUCCESS] - fd: [%d]", fd);
+               dbg("Phone Power OFF [SUCCESS] - fd: [%d]", fd);
                return TRUE;
        }\r
 }\r
 \r
 /*\r
- *     Read data from VDPRAM.
+ * Read data from VDPRAM
  */
-int vdpram_tty_read(int nFd, void* buf, size_t nbytes)\r
+gint vdpram_tty_read(gint fd, void *buf, size_t buf_len)\r
 {\r
-       int     actual = 0;\r
+       gint actual = 0;\r
 \r
-       if ((actual = read(nFd, buf, nbytes)) < 0) {\r
-               err("[VDPRAM] Read [FAIL] - fd: [%d] Error: [%s]", nFd, strerror(errno));
+       if ((actual = read(fd, buf, buf_len)) < 0) {\r
+               err("Read [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno));
        }\r
 
-       /* Dumping Read data */
-       vdpram_hex_dump(RX, actual, buf);
-\r
        return actual;\r
 }\r
 \r
 /*\r
- *     Write data to VDPRAM.
+ * Write data to VDPRAM
  */
-int vdpram_tty_write(int nFd, void* buf, size_t nbytes)\r
+gint vdpram_tty_write(gint fd, void *buf, size_t buf_len)\r
 {\r
-       int ret;\r
        size_t actual = 0;\r
-       int     retry = 0;\r
-\r
-       do {\r
-               vdpram_hex_dump(TX, nbytes, buf);
+       guint retry = 0;\r
+       gint ret;\r
 
+       while(actual < buf_len) {\r
                /* Write to Device */
-               ret = write(nFd, (unsigned char* )buf, nbytes - actual);\r
+               ret = write(fd, (guchar *)buf, buf_len - actual);\r
                if (ret < 0) {
-                       err("[VDPRAM] Write [FAIL] - fd: [%d] Error: [%s]",
-                                                                                               nFd, strerror(errno));
+                       err("Write [FAIL] - fd: [%d] Error: [%s]",
+                               fd, strerror(errno));
 \r
                        if ((errno == EAGAIN) || (errno == EBUSY)) {
                                /* Sleep for 50 msecs */
                                __sleep(SLEEP_TIME_IN_SEC, SLEEP_TIME_IN_MSEC);
 \r
                                if (retry == MAX_RETRY_COUNT) {
-                                       err("[VDPRAM] Maximum retries completed!!!");
+                                       err("Maximum retries completed!!!");
                                        return 0;
                                }
 \r
@@ -538,17 +522,17 @@ int vdpram_tty_write(int nFd, void* buf, size_t nbytes)
                                continue;
                        }
 \r
-                       if (actual != nbytes)
-                               err("[VDPRAM] Write [FAIL] - fd: [%d]", nFd);
+                       if (actual != buf_len)
+                               err("Write [FAIL] - fd: [%d]", fd);
 \r
-                       err("[VDPRAM] Write [FAIL] - Error: [%s]", strerror(errno));
+                       err("Write [FAIL] - Error: [%s]", strerror(errno));
                        return actual;\r
                }\r
 \r
                actual  += ret;\r
                buf     += ret;\r
-               dbg("[VDPRAM] Write Actual bytes: [%d] Written bytes: [%d]", actual, ret);
-       } while(actual < nbytes);\r
+               dbg("Write Actual bytes: [%d] Written bytes: [%d]", actual, ret);
+       };\r
 \r
        return actual;\r
 }\r
index 7befabd..d44836e 100644 (file)
@@ -1,9 +1,7 @@
 /*\r
  * tel-plugin-vmodem\r
  *\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: Junhwan An <jh48.an@samsung.com>\r
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
-#include <log.h>\r
-\r
-#include "vdpram_dump.h"\r
-\r
-static void hex_dump(char *pad, int size, const void *data)\r
-{\r
-       char buf[255] = {0, };\r
-       char hex[4] = {0, };\r
-       int i;\r
-       unsigned char *p;\r
-\r
-       if (size <= 0) {\r
-               msg("%sno data", pad);\r
-               return;\r
-       }\r
-\r
-       p = (unsigned char *)data;\r
 \r
-       snprintf(buf, 255, "%s%04X: ", pad, 0);\r
-       for (i = 0; i<size; i++) {\r
-               snprintf(hex, 4, "%02X ", p[i]);\r
-               strcat(buf, hex);\r
+#include <glib.h>\r
 \r
-               if ((i + 1) % 8 == 0) {\r
-                       if ((i + 1) % 16 == 0) {\r
-                               msg("%s", buf);\r
-                               memset(buf, 0, 255);\r
-                               snprintf(buf, 255, "%s%04X: ", pad, i + 1);\r
-                       }\r
-                       else {\r
-                               strcat(buf, "  ");\r
-                       }\r
-               }\r
-       }\r
+#include <tcore.h>\r
+#include <util.h>\r
+#include <log.h>\r
 \r
-       msg("%s", buf);\r
-}\r
+#include "vdpram_dump.h"\r
 \r
-void vdpram_hex_dump(int dir, unsigned short data_len, void *data)\r
+void vdpram_hex_dump(gboolean tx, gushort data_len, void *data)\r
 {\r
        char *d;\r
 \r
        if(!data)\r
                return;\r
 \r
-       if (dir == RX)
-               d = "[RX]";\r
-       else\r
+       if (tx == TRUE)
                d = "[TX]";\r
+       else\r
+               d = "[RX]";\r
 \r
-       msg("");\r
-       msg("  %s\tlen=%d\t%s", d, data_len, (char *)data);\r
-       hex_dump("        ", data_len, data);\r
+       msg("\n====== Data DUMP ======\n");\r
 \r
-       msg("");\r
-}\r
+       msg("  %s\tData length: [%d] -", d, data_len);\r
+       tcore_util_hex_dump("        ", (gint)data_len, data);\r
 \r
+       msg("\n====== Data DUMP ======\n");\r
+}\r