Code sync from tizen_2.4
[platform/core/telephony/tel-plugin-vmodem.git] / src / vdpram.c
index 078e914..ec81ee8 100644 (file)
-/*\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
- *\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
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <termios.h>\r
-#include <errno.h>\r
-#include <sys/time.h>\r
-#include <sys/mman.h>\r
-#include <unistd.h>\r
-#include <fcntl.h>\r
-#include <sys/ioctl.h>\r
-\r
-#include <glib.h>
-
-#include <log.h>\r
-#include "legacy/TelUtility.h"\r
-#include "vdpram.h"\r
-#include "vdpram_dump.h"\r
-\r
-#ifndef TIOCMODG\r
-#  ifdef TIOCMGET\r
-#    define TIOCMODG TIOCMGET\r
-#  else\r
-#    ifdef MCGETA\r
-#      define TIOCMODG MCGETA\r
-#    endif\r
-#  endif\r
-#endif\r
-\r
-#ifndef TIOCMODS\r
-#  ifdef TIOCMSET\r
-#    define TIOCMODS TIOCMSET\r
-#  else\r
-#    ifdef MCSETA\r
-#      define TIOCMODS MCSETA\r
-#    endif\r
-#  endif\r
-#endif\r
-\r
-/* Retry parameters */
-#define SLEEP_TIME_IN_SEC              0
-#define SLEEP_TIME_IN_MSEC             50
-
-#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
-\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
-\r
-static tty_old_setting_t *ttyold_head = NULL;\r
-\r
 /*
- *     Insert TTY old settings.
+ * tel-plugin-vmodem
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Junhwan An <jh48.an@samsung.com>
+ *
+ * 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.
  */
-static void __insert_tty_oldsetting(tty_old_setting_t *me)\r
-{\r
-       dbg("Function Entrance");
-\r
-       if (me == NULL)\r
-               return;\r
-\r
-       if (ttyold_head)\r
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <termios.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include <log.h>
+#include "legacy/TelUtility.h"
+#include "vdpram.h"
+#include "vdpram_dump.h"
+
+#ifndef TIOCMODG
+#  ifdef TIOCMGET
+#    define TIOCMODG TIOCMGET
+#  else
+#    ifdef MCGETA
+#      define TIOCMODG MCGETA
+#    endif
+#  endif
+#endif
+
+#ifndef TIOCMODS
+#  ifdef TIOCMSET
+#    define TIOCMODS TIOCMSET
+#  else
+#    ifdef MCSETA
+#      define TIOCMODS MCSETA
+#    endif
+#  endif
+#endif
+
+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"
+
+/* 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)
+
+static tty_old_setting_t *ttyold_head = NULL;
+
+/* static functions */
+static void __insert_tty_oldsetting(tty_old_setting_t *me)
+{
+       dbg("Function Enterence.");
+
+       if (me == NULL)
+               return;
+
+       if (ttyold_head)
                ttyold_head->prev = me;
-\r
-       me->next = ttyold_head;\r
-       me->prev = 0;\r
-       ttyold_head = me;\r
-}\r
-\r
-/*
- *     Search TTY old settings.
- */
-static tty_old_setting_t *__search_tty_oldsetting(int fd)\r
-{\r
-       tty_old_setting_t *tty = NULL;\r
-\r
-       dbg("Function Entrance");
-\r
-       if (ttyold_head == NULL)\r
-               return NULL;\r
-\r
-       tty = ttyold_head;\r
-\r
+
+       me->next = ttyold_head;
+       me->prev = 0;
+       ttyold_head = me;
+}
+
+static tty_old_setting_t *__search_tty_oldsetting(int fd)
+{
+       tty_old_setting_t *tty = NULL;
+
+       dbg("Function Enterence.");
+
+       if (ttyold_head == NULL)
+               return NULL;
+
+       tty = ttyold_head;
+
        do {
-               if (tty->fd == fd) {\r
-                       dbg("oldsetting for inputted fd [%d] is found", fd);
-                       break;\r
+               if (tty->fd == fd) {
+                       dbg("oldsetting for inputted fd is found");
+                       break;
                } else {
-                       if (tty->next == NULL) {\r
-                               err("No oldsetting found!!!");
-                               tty = NULL;\r
-                               break;\r
-                       }\r
-                       tty = tty->next;\r
-               }\r
+                       if (tty->next == NULL) {
+                               dbg("No oldsetting is found");
+                               tty = NULL;
+                               break;
+                       }
+                       tty = tty->next;
+               }
        } while (1);
-\r
-       return tty;\r
-}\r
-\r
-/*
- *     Remove TTY old settings.
- */
-static void __remove_tty_oldsetting(tty_old_setting_t *me)\r
-{\r
-       dbg( "Function Enterence.");\r
-\r
-       if (me == NULL)\r
-               return;\r
-\r
-       if (me->prev)\r
+
+       return tty;
+}
+
+static void __remove_tty_oldsetting(tty_old_setting_t *me)
+{
+       dbg("Function Enterence.");
+
+       if (me == NULL)
+               return;
+
+       if (me->prev)
                me->prev->next = me->next;
-       else\r
+       else
                ttyold_head = me->next;
-\r
-       if (me->next)\r
+
+       if (me->next)
                me->next->prev = me->prev;
-}\r
-\r
+}
+
 /*
- *     Set hardware flow control.
+ * Set hardware flow control.
  */
-static void __tty_sethwf(int fd, int on)\r
-{\r
-       struct termios tty;\r
-\r
-       dbg("Function Entrance");
-\r
-       if (tcgetattr(fd, &tty))\r
-               err("__tty_sethwf: tcgetattr:");\r
-\r
-       if (on)\r
+static void __tty_sethwf(int fd, int on)
+{
+       struct termios tty;
+
+       dbg("Function Enterence.");
+
+       if (tcgetattr(fd, &tty))
+               err("__tty_sethwf: tcgetattr:");
+
+       if (on)
                tty.c_cflag |= CRTSCTS;
-       else\r
+       else
                tty.c_cflag &= ~CRTSCTS;
-\r
-       if (tcsetattr(fd, TCSANOW, &tty))\r
-               err("__tty_sethwf: tcsetattr:");\r
-}\r
-\r
-/*\r
- *     Set RTS line. Sometimes dropped. Linux specific?
+
+       if (tcsetattr(fd, TCSANOW, &tty))
+               err("__tty_sethwf: tcsetattr:");
+}
+
+/*
+ * Set RTS line. Sometimes dropped. Linux specific?
  */
-static int __tty_setrts(int fd)\r
-{\r
-       int mcs;\r
-\r
-       dbg("Function Entrance");
-\r
-       if (-1 ==  ioctl(fd, TIOCMODG, &mcs))\r
-               err("icotl: TIOCMODG");\r
-\r
-       mcs |= TIOCM_RTS;\r
-\r
-       if (-1 == ioctl(fd, TIOCMODS, &mcs))\r
-               err("icotl: TIOCMODS");\r
-\r
-       return 0;\r
-}\r
-\r
-/*\r
- *     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
-{\r
-       int spd = -1;\r
-       int newbaud;\r
-       int bit = bits[0];\r
-       int stop_bit = stop[0];\r
-\r
-       struct termios tty;\r
-       tty_old_setting_t *old_setting = NULL;\r
-\r
-       dbg("Function Entrance");
-\r
-       old_setting = g_try_new0(tty_old_setting_t, 1);
-\r
-       if (old_setting == NULL)\r
-               return TAPI_API_SYSTEM_OUT_OF_MEM;\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
-       }\r
-\r
-       if (tcgetattr(fd, &old_setting->termiosVal) < 0) {\r
-               g_free(old_setting);
-               return TAPI_API_TRANSPORT_LAYER_FAILURE;\r
-       }\r
-\r
-       __insert_tty_oldsetting(old_setting);\r
-\r
-       fflush(stdout);\r
-\r
-       /* We generate mark and space parity ourself. */\r
-       if (bit == '7' && (par[0] == 'M' || par[0] == 'S'))\r
-               bit = '8';\r
-\r
-       /* Check if 'baudr' is really a number */\r
-       if ((newbaud = (atol(baudr) / 100)) == 0 && baudr[0] != '0')\r
-               newbaud = -1;\r
-\r
-       switch(newbaud) {
-               case 0:\r
-                       spd = 0;\r
-               break;
-\r
-               case 3:\r
-                       spd = B300;\r
-               break;
-\r
-               case 6:\r
-                       spd = B600;\r
-               break;
-\r
-               case 12:\r
-                       spd = B1200;\r
-               break;
-\r
-               case 24:\r
-                       spd = B2400;\r
-               break;
-\r
-               case 48:\r
-                       spd = B4800;\r
-               break;
-\r
-               case 96:\r
-                       spd = B9600;\r
-               break;
-\r
-               case 192:\r
-                       spd = B19200;\r
-               break;
-\r
-               case 384:\r
-                       spd = B38400;\r
-               break;
-\r
-               case 576:\r
-                       spd = B57600;\r
-               break;
-\r
-               case 1152:\r
-                       spd = B115200;\r
-               break;
-\r
-               default:\r
-                       err("invaid baud rate");\r
-               break;
-       }\r
-\r
-       if (spd != -1) {\r
+static int __tty_setrts(int fd)
+{
+       int mcs;
+
+       dbg("Function Enterence.");
+
+       if (-1 ==  ioctl(fd, TIOCMODG, &mcs))
+               err("icotl: TIOCMODG");
+
+       mcs |= TIOCM_RTS;
+
+       if (-1 == ioctl(fd, TIOCMODS, &mcs))
+               err("icotl: TIOCMODS");
+
+       return 0;
+}
+
+/*
+ * Set baudrate, parity and number of bits.
+ */
+static int __tty_setparms(int fd,
+       const char *baudr, const char *par,
+       const char *bits, const char *stop,
+       int hwf, int swf)
+{
+       int spd = -1;
+       int newbaud;
+       int bit = bits[0];
+       int stop_bit = stop[0];
+
+       struct termios tty;
+       tty_old_setting_t *old_setting = NULL;
+
+       dbg("Function Enterence.");
+
+       old_setting = calloc(sizeof(tty_old_setting_t), 1);
+       if (old_setting == NULL)
+               return TAPI_API_SYSTEM_OUT_OF_MEM;
+
+       old_setting->fd = fd;
+
+       if (tcgetattr(fd, &tty) < 0) {
+               free(old_setting);
+               return TAPI_API_TRANSPORT_LAYER_FAILURE;
+       }
+
+       if (tcgetattr(fd, &old_setting->termiosVal) < 0) {
+               free(old_setting);
+               return TAPI_API_TRANSPORT_LAYER_FAILURE;
+       }
+
+       __insert_tty_oldsetting(old_setting);
+
+       fflush(stdout);
+
+       /* We generate mark and space parity ourself. */
+       if (bit == '7' && (par[0] == 'M' || par[0] == 'S'))
+               bit = '8';
+
+       /* Check if 'baudr' is really a number */
+       if ((newbaud = (atol(baudr) / 100)) == 0 && baudr[0] != '0')
+               newbaud = -1;
+
+       switch (newbaud) {
+       case 0:
+               spd = 0;
+       break;
+
+       case 3:
+               spd = B300;
+       break;
+
+       case 6:
+               spd = B600;
+       break;
+
+       case 12:
+               spd = B1200;
+       break;
+
+       case 24:
+               spd = B2400;
+       break;
+
+       case 48:
+               spd = B4800;
+       break;
+
+       case 96:
+               spd = B9600;
+       break;
+
+       case 192:
+               spd = B19200;
+       break;
+
+       case 384:
+               spd = B38400;
+       break;
+
+       case 576:
+               spd = B57600;
+       break;
+
+       case 1152:
+               spd = B115200;
+       break;
+
+       default:
+               err("invaid baud rate");
+       break;
+       }
+
+       if (spd != -1) {
                cfsetospeed(&tty, (speed_t) spd);
                cfsetispeed(&tty, (speed_t) spd);
-       }\r
-\r
-       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;
-\r
-               case '7':
-                       tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7;
-               break;
-\r
-               case '8':
-               default:
-                       tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
-               break;
-       }\r
-\r
-       switch(stop_bit) {
-               case '1':
-                       tty.c_cflag &= ~CSTOPB;
-               break;
-\r
-               case '2':
-               default:
-                       tty.c_cflag |= CSTOPB;
-               break;
-       }\r
-\r
-       /* Set into raw, no echo mode */\r
-       tty.c_iflag = IGNBRK;\r
-       tty.c_lflag = 0;\r
-       tty.c_oflag = 0;\r
-       tty.c_cflag |= CLOCAL | CREAD;\r
-       tty.c_cc[VMIN] = 1;\r
-       tty.c_cc[VTIME] = 1;\r
-\r
-       if (swf)\r
+       }
+
+       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 '7':
+               tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7;
+       break;
+
+       case '8':
+       default:
+               tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
+       break;
+       }
+
+       switch (stop_bit) {
+       case '1':
+               tty.c_cflag &= ~CSTOPB;
+       break;
+
+       case '2':
+       default:
+               tty.c_cflag |= CSTOPB;
+       break;
+       }
+
+       /* Set into raw, no echo mode */
+       tty.c_iflag = IGNBRK;
+       tty.c_lflag = 0;
+       tty.c_oflag = 0;
+       tty.c_cflag |= CLOCAL | CREAD;
+       tty.c_cc[VMIN] = 1;
+       tty.c_cc[VTIME] = 1;
+
+       if (swf)
                tty.c_iflag |= IXON | IXOFF;
-       else\r
+       else
                tty.c_iflag &= ~(IXON | IXOFF | IXANY);
-\r
-       tty.c_cflag &= ~(PARENB | PARODD);\r
-\r
-       if (par[0] == 'E')\r
+
+       tty.c_cflag &= ~(PARENB | PARODD);
+
+       if (par[0] == 'E')
                tty.c_cflag |= PARENB;
-       else if (par[0] == 'O')\r
+       else if (par[0] == 'O')
                tty.c_cflag |= (PARENB | PARODD);
-\r
-       if (tcsetattr(fd, TCSANOW, &tty) < 0) {\r
-               g_free(old_setting);
+
+       if (tcsetattr(fd, TCSANOW, &tty) < 0) {
+               free(old_setting);
                return TAPI_API_TRANSPORT_LAYER_FAILURE;
-       }\r
-\r
-       __tty_setrts(fd);\r
-       __tty_sethwf(fd, hwf);\r
-\r
-       return TAPI_API_SUCCESS;\r
-}\r
-\r
-/*
- *     Close TTY Device.
- */
-static int __tty_close(int fd)\r
-{\r
-       tty_old_setting_t *old_setting = NULL;\r
-\r
-       dbg("Function Entrance");
-\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
        }
-\r
-       if (tcsetattr(fd, TCSAFLUSH, &old_setting->termiosVal) < 0)     {\r
-               err("[VDPRAM] Close failed");
-               return TAPI_API_TRANSPORT_LAYER_FAILURE;\r
-       }\r
-\r
-       /* Remove the previous setting configured */
-       __remove_tty_oldsetting(old_setting);\r
-\r
-       /* Free memory */
-       g_free(old_setting);
-\r
-       /* Close fd */
-       close(fd);\r
-\r
-       return TAPI_API_SUCCESS;\r
-}\r
-\r
-/*\r
- *     Wait on select.
- */
-static void __sleep(int sec, int msec)
+
+       __tty_setrts(fd);
+       __tty_sethwf(fd, hwf);
+
+       return TAPI_API_SUCCESS;
+}
+
+static int __tty_close(int fd)
 {
-    struct timeval tv;
+       tty_old_setting_t *old_setting = NULL;
+
+       dbg("Function Enterence.");
 
-    tv.tv_sec = sec;
-    tv.tv_usec = msec;
+       old_setting = __search_tty_oldsetting(fd);
+       if (old_setting == NULL)
+               return TAPI_API_SUCCESS;
 
-    select(0, NULL, NULL, NULL, &tv);
+       if (tcsetattr(fd, TCSAFLUSH, &old_setting->termiosVal) < 0) {
+               err("close failed");
+               return TAPI_API_TRANSPORT_LAYER_FAILURE;
+       }
+
+       __remove_tty_oldsetting(old_setting);
+
+       free(old_setting);
+
+       close(fd);
+
+       return TAPI_API_SUCCESS;
 }
 
 /*
- * Close the VDPRAM device
+ * Restore the old settings before close.
  */
-int vdpram_close(int fd)\r
-{\r
-       int ret = TAPI_API_SUCCESS;\r
-\r
-       dbg("Function Entrance");
-\r
-       /* Close VDPRAM Device */
-       ret = __tty_close(fd);\r
-\r
-       return ret;\r
-}\r
-\r
-/*\r
- * Open the VDPRAM device
- */
-int vdpram_open (void)\r
-{\r
-       int rv = -1;\r
-       int fd = -1;\r
-       int val = 0;\r
-       unsigned int cmd =0;\r
-\r
+int vdpram_close(int fd)
+{
+       int ret = TAPI_API_SUCCESS;
+
        dbg("Function Enterence.");
 
-       /* 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));
-               return rv;\r
+       ret = __tty_close(fd);
+
+       return ret;
+}
+
+/*
+ * Open the vdpram fd.
+ */
+int vdpram_open(void)
+{
+       int rv = -1;
+       int fd = -1;
+       int val = 0;
+       unsigned int cmd = 0;
+
+       fd = open(VDPRAM_OPEN_PATH, O_RDWR);
+
+       if (fd < 0) {
+               err("#### Failed to open vdpram file: error no hex %x", errno);
+               return rv;
        } else {
-               dbg("[VDPRAM] Open VDPRAM file - [SUCCESS] fd: [%d] path: [%s]",
-                                                                               fd, VDPRAM_OPEN_PATH);
-       }\r
-\r
-       /* Set device parameters */
+               dbg("#### Success to open vdpram file. fd:%d, path:%s", fd, VDPRAM_OPEN_PATH);
+       }
+
+
        if (__tty_setparms(fd, "115200", "N", "8", "1", 0, 0) != TAPI_API_SUCCESS) {
-               err("[VDPRAM] Set TTY device parameters - [FAIL]");
-\r
-               /* Close VDPRAM Device */
-               vdpram_close(fd);\r
-               return rv;\r
-       }\r
-       else {
-               dbg("[VDPRAM] Set TTY device parameters - [SUCCESS]");
+               vdpram_close(fd);
+               return rv;
+       } else {
+               dbg("#### Success set tty vdpram params. fd:%d", fd);
        }
-\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);
-\r
-               /* Close Device */
-               vdpram_close(fd);\r
 
-               return rv;\r
+       /*TODO: No need to check Status. Delete*/
+       cmd = HN_DPRAM_PHONE_GETSTATUS;
+
+       if (ioctl(fd, cmd, &val) < 0) {
+               err("#### ioctl failed fd:%d, cmd:%lu, val:%d", fd, cmd, val);
+               vdpram_close(fd);
+               return rv;
        } else {
-               dbg("[VDPRAM] Get Phone status - [SUCCESS]");
-       }\r
-\r
-       return fd;\r
-}\r
-\r
-/*\r
- *     Power ON the Phone.
+               dbg("#### ioctl Success fd:%d, cmd:%lu, val:%d", fd, cmd, val);
+       }
+
+       return fd;
+
+}
+
+/*
+ * power on the phone.
  */
-gboolean vdpram_poweron(int 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));
-               return FALSE;
-       }\r
-       else {\r
-               dbg("[VDPRAM] Phone Power ON [SUCCESS] - fd: [%d]", fd);
-               return TRUE;
-       }\r
-}\r
-\r
+int vdpram_poweron(int fd)
+{
+       int rv = -1;
+
+       if (ioctl(fd, HN_DPRAM_PHONE_ON, NULL) < 0) {
+               err("Phone Power On failed (fd:%d)", fd);
+               rv = 0;
+       } else {
+               dbg("Phone Power On success (fd:%d)", fd);
+               rv = 1;
+       }
+       return rv;
+}
+
+ /*
+  * Power Off the Phone.
+  */
+int vdpram_poweroff(int fd)
+{
+       int rv;
+
+       if (ioctl(fd, HN_DPRAM_PHONE_OFF, NULL) < 0) {
+               err("Phone Power Off failed.");
+               rv = -1;
+       } else {
+               dbg("Phone Power Off success.");
+               rv = 1;
+       }
+
+       return rv;
+}
+
 /*
- *     Power OFF the Phone.
- */\r
-gboolean vdpram_poweroff(int 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));
-               return FALSE;
-       }\r
-       else {\r
-               dbg("[VDPRAM] 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
-{\r
-       int     actual = 0;\r
-\r
-       if ((actual = read(nFd, buf, nbytes)) < 0) {\r
-               err("[VDPRAM] Read [FAIL] - fd: [%d] Error: [%s]", nFd, strerror(errno));
-       }\r
-
-       /* Dumping Read data */
-       vdpram_hex_dump(RX, actual, buf);
-\r
-       return actual;\r
-}\r
-\r
-/*\r
- *     Write data to VDPRAM.
+int vdpram_tty_read(int nFd, void *buf, size_t nbytes)
+{
+       int     actual = 0;
+
+       if ((actual = read(nFd, buf, nbytes)) < 0)
+               dbg("[TRANSPORT DPRAM]read failed.");
+
+       vdpram_hex_dump(IPC_RX, actual, buf);
+
+       return actual;
+}
+
+static void __selectsleep(int sec, int msec)
+{
+       struct timeval tv;
+
+       tv.tv_sec = sec;
+       tv.tv_usec = msec;
+       select(0, NULL, NULL, NULL, &tv);
+}
+
+/*
+ * Write data to vdpram.
  */
-int vdpram_tty_write(int nFd, void* buf, size_t nbytes)\r
-{\r
-       int ret;\r
-       size_t actual = 0;\r
-       int     retry = 0;\r
-\r
-       do {\r
-               vdpram_hex_dump(TX, nbytes, buf);
-
-               /* Write to Device */
-               ret = write(nFd, (unsigned char* )buf, nbytes - actual);\r
+int vdpram_tty_write(int nFd, void *buf, size_t nbytes)
+{
+       int ret;
+       size_t actual = 0;
+       int     retry = 0;
+
+       do {
+               vdpram_hex_dump(IPC_TX, nbytes, buf);
+               ret = write(nFd, (unsigned char *)buf, nbytes - actual);
+
+               if ((ret < 0 && errno == EAGAIN) || (ret < 0 && errno == EBUSY)) {
+                       err("write failed. retry.. ret[%d] with errno[%d] ", ret, errno);
+                       __selectsleep(0, 50);
+
+                       if (retry == 10)
+                               return 0;
+
+                       retry = retry + 1;
+                       continue;
+               }
+
                if (ret < 0) {
-                       err("[VDPRAM] Write [FAIL] - fd: [%d] Error: [%s]",
-                                                                                               nFd, 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!!!");
-                                       return 0;
-                               }
-\r
-                               retry = retry + 1;
-                               continue;
-                       }
-\r
-                       if (actual != nbytes)
-                               err("[VDPRAM] Write [FAIL] - fd: [%d]", nFd);
-\r
-                       err("[VDPRAM] 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
-\r
-       return actual;\r
-}\r
+                   if (actual != nbytes)
+                               err("write failed.ret[%d]", ret);
+
+                       err("errno [%d]", errno);
+                       return actual;
+               }
+
+               actual += ret;
+               buf += ret;
+
+       } while (actual < nbytes);
+
+       return actual;
+}
+/*     EOF     */