Code Sync up from tizen_2.4
[platform/core/telephony/tel-plugin-vmodem.git] / src / vdpram.c
index 07eca2a..f585850 100644 (file)
-/*\r
- * tel-plugin-vmodem\r
- *\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
- * 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
-\r
-#include "vdpram.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
-#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
-
-typedef struct tty_old_setting TtyOldSetting;\r
-\r
-struct tty_old_setting {
-       gint fd;\r
-       struct termios termiosVal;\r
-       TtyOldSetting *next;\r
-       TtyOldSetting *prev;\r
-};\r
-\r
-static TtyOldSetting *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(TtyOldSetting *me)\r
-{\r
-       dbg("Enter");
-\r
-       if (me == NULL)\r
-               return;\r
-\r
-       if (ttyold_head)\r
-               ttyold_head->prev = me;
-\r
-       me->next = ttyold_head;\r
-       me->prev = 0;\r
-       ttyold_head = me;\r
-}\r
-\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;
+
+       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) {
+                       dbg("oldsetting for inputted fd is found");
+                       break;
+               }
+               else {
+                       if (tty->next == NULL) {
+                               dbg("No oldsetting is found");
+                               tty = NULL;
+                               break;
+                       }
+                       tty = tty->next;
+               }
+       }while(1);
+
+       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
+           ttyold_head = me->next;
+
+       if (me->next)
+           me->next->prev = me->prev;
+}
+
+/* Set hardware flow control.
+*/
+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
+           tty.c_cflag &= ~CRTSCTS;
+
+       if (tcsetattr(fd, TCSANOW, &tty))
+               err("__tty_sethwf: tcsetattr:");
+}
+
 /*
- * Search TTY old settings
- */
-static TtyOldSetting *__search_tty_oldsetting(gint fd)\r
-{\r
-       TtyOldSetting *tty = ttyold_head;\r
-\r
-       dbg("Enter");
-\r
-       while (tty) {\r
-               if (tty->fd == fd) {\r
-                       dbg("tty for fd [%d] found!!!", fd);
-                       break;\r
-               }\r
-               tty = tty->next;\r
-       };\r
-\r
-       return tty;\r
-}\r
-\r
+* Set RTS line. Sometimes dropped. Linux specific?
+*/
+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;
+}
+
 /*
- * Remove TTY old settings
+ * Set baudrate, parity and number of bits.
  */
-static void __remove_tty_oldsetting(TtyOldSetting *me)\r
-{\r
-       dbg("Enter");\r
-\r
-       if (me == NULL)\r
-               return;\r
-\r
-       if (me->prev)\r
-               me->prev->next = me->next;
-       else\r
-               ttyold_head = me->next;
-\r
-       if (me->next)\r
-               me->next->prev = me->prev;
-}\r
-\r
+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);
+       }
+
+       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
+           tty.c_iflag &= ~(IXON | IXOFF | IXANY);
+
+       tty.c_cflag &= ~(PARENB | PARODD);
+
+       if (par[0] == 'E')
+           tty.c_cflag |= PARENB;
+       else if (par[0] == 'O')
+           tty.c_cflag |= (PARENB | PARODD);
+
+       if (tcsetattr(fd, TCSANOW, &tty) < 0) {
+               free(old_setting);
+           return TAPI_API_TRANSPORT_LAYER_FAILURE;
+       }
+
+       __tty_setrts(fd);
+       __tty_sethwf(fd, hwf);
+
+       return TAPI_API_SUCCESS;
+
+}
+
+static int __tty_close(int fd)
+{
+       tty_old_setting_t *old_setting = NULL;
+
+       dbg("Function Enterence.");
+
+       old_setting = __search_tty_oldsetting(fd);
+       if (old_setting == NULL)
+               return TAPI_API_SUCCESS;
+
+       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;
+}
+
 /*
- * Set hardware flow control
- */
-static void __tty_sethwf(gint fd, gint on)\r
-{\r
-       struct termios tty;\r
-\r
-       dbg("Enter");
-\r
-       if (tcgetattr(fd, &tty))\r
-               err("__tty_sethwf: tcgetattr:");\r
-\r
-       if (on == 1)\r
-               tty.c_cflag |= CRTSCTS;
-       else\r
-               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?
- */
-static gint __tty_setrts(gint fd)\r
-{\r
-       gint mcs;\r
-\r
-       dbg("Enter");
-\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 gboolean __tty_setparms(gint fd,\r
-       gchar *baudr, gchar *par, gchar *bits, gchar *stop, gint hwf, gint swf)\r
-{\r
-       gint spd = -1;\r
-       gint newbaud;\r
-       gint bit = bits[0];\r
-       gint stop_bit = stop[0];\r
-\r
-       struct termios tty;\r
-       TtyOldSetting *old_setting = NULL;\r
-\r
-       dbg("Enter");
-\r
-       old_setting = g_try_new0(TtyOldSetting, 1);
-\r
-       if (old_setting == NULL)\r
-               return FALSE;\r
-\r
-       old_setting->fd = fd;\r
-\r
-       if (tcgetattr(fd, &tty) < 0) {\r
-               g_free(old_setting);
-               return FALSE;\r
-       }\r
-\r
-       if (tcgetattr(fd, &old_setting->termiosVal) < 0) {\r
-               g_free(old_setting);
-               return FALSE;\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
-               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
-               tty.c_iflag |= IXON | IXOFF;
-       else\r
-               tty.c_iflag &= ~(IXON | IXOFF | IXANY);
-\r
-       tty.c_cflag &= ~(PARENB | PARODD);\r
-\r
-       if (par[0] == 'E')\r
-               tty.c_cflag |= PARENB;
-       else if (par[0] == 'O')\r
-               tty.c_cflag |= (PARENB | PARODD);
-\r
-       if (tcsetattr(fd, TCSANOW, &tty) < 0) {\r
-               g_free(old_setting);
-               return FALSE;
-       }\r
-\r
-       __tty_setrts(fd);\r
-       __tty_sethwf(fd, hwf);\r
-\r
-       return TRUE;\r
-}\r
-\r
+* restore the old settings before close.
+*/
+int vdpram_close(int fd)
+{
+       int ret = TAPI_API_SUCCESS;
+
+       dbg("Function Enterence.");
+
+       ret = __tty_close(fd);
+
+       return ret;
+}
+
 /*
- * Close TTY Device
- */
-static gboolean __tty_close(gint fd)\r
-{\r
-       TtyOldSetting *old_setting = NULL;\r
-\r
-       dbg("Enter");
-\r
-       /* Get previous settings */
-       old_setting = __search_tty_oldsetting(fd);\r
-       if (old_setting == NULL) {
-               dbg("No previous settings found!!!");
-               return TRUE;\r
-       }
-\r
-       if (tcsetattr(fd, TCSAFLUSH, &old_setting->termiosVal) < 0)     {\r
-               err("Close failed");
-               return FALSE;\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 TRUE;\r
-}\r
-\r
-/*\r
- * Wait on select
- */
-static void __sleep(gint sec, gint msec)
+*      Open the vdpram fd.
+*/
+int vdpram_open (void)
 {
-       struct timeval tv;
+       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("#### 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) {
+               vdpram_close(fd);
+               return rv;
+       }
+       else
+               dbg("#### Success set tty vdpram params. fd:%d", fd);
+
+       /*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("#### ioctl Success fd:%d, cmd:%lu, val:%d", fd,cmd,val);
 
-       tv.tv_sec = sec;
-       tv.tv_usec = msec;
+       return fd;
 
-       select(0, NULL, NULL, NULL, &tv);
 }
 
 /*
- * Close the VDPRAM device
- */
-gboolean vdpram_close(gint fd)\r
-{\r
-       gint ret;\r
-\r
-       dbg("Enter");
-\r
-       /* Close VDPRAM Device */
-       ret = __tty_close(fd);\r
-\r
-       return ret;\r
-}\r
-\r
-/*\r
- * Open the VDPRAM device
- */
-gint vdpram_open (void)\r
-{\r
-       gint rv = -1;\r
-       gint fd = -1;\r
-       gint val = 0;\r
-       guint cmd =0;\r
-\r
-       dbg("Enter");
-
-       /* Open DPRAM device */
-       fd = open(VDPRAM_OPEN_PATH, O_RDWR);\r
-       if (fd < 0) {\r
-               err("Open VDPRAM file - [FAIL] Error: [%s]", strerror(errno));
-               return rv;\r
-       } else {
-               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) != TRUE) {
-               err("Set TTY device parameters - [FAIL]");
-\r
-               /* Close VDPRAM Device */
-               (void)vdpram_close(fd);\r
-               return rv;\r
-       }\r
+*      power on the phone.
+*/
+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("Set TTY device parameters - [SUCCESS]");
+               dbg("Phone Power On success (fd:%d)", fd);
+               rv = 1;
        }
-\r
-       /* TODO: No need to check Status. Delete */
-       cmd = HN_DPRAM_PHONE_GETSTATUS;\r
-       if (ioctl(fd, cmd, &val) < 0) {
-               err("Get Phone status - [FAIL] fd: [d] cmd: [%d] val: [%d]",
-                       fd, cmd, val);
-\r
-               /* Close Device */
-               (void)vdpram_close(fd);\r
-
-               return rv;\r
-       } else {
-               dbg("Get Phone status - [SUCCESS]");
-       }\r
-\r
-       return fd;\r
-}\r
-\r
-/*\r
- * Power ON the Phone
+       return rv;
+}
+
+ /*
+ *     Power Off the Phone.
  */
-gboolean vdpram_poweron(gint fd)
-{\r
-       if (ioctl(fd, HN_DPRAM_PHONE_ON, NULL) < 0) {\r
-               err("Phone Power ON [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno));
-               return FALSE;
-       }\r
-       else {\r
-               dbg("Phone Power ON [SUCCESS] - fd: [%d]", fd);
-               return TRUE;
-       }\r
-}\r
-\r
+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(gint fd)
-{\r
-       if (ioctl(fd, HN_DPRAM_PHONE_OFF, NULL) < 0) {\r
-               err("Phone Power OFF [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno));
-               return FALSE;
-       }\r
-       else {\r
-               dbg("Phone Power OFF [SUCCESS] - fd: [%d]", fd);
-               return TRUE;
-       }\r
-}\r
-\r
-/*\r
- * Read data from VDPRAM
- */
-gint vdpram_tty_read(gint fd, void *buf, size_t buf_len)\r
-{\r
-       gint actual = 0;\r
-\r
-       if ((actual = read(fd, buf, buf_len)) < 0) {\r
-               err("Read [FAIL] - fd: [%d] Error: [%s]", fd, strerror(errno));
-       }\r
-
-       return actual;\r
-}\r
-\r
-/*\r
- * Write data to VDPRAM
- */
-gint vdpram_tty_write(gint fd, void *buf, size_t buf_len)\r
-{\r
-       size_t actual = 0;\r
-       guint retry = 0;\r
-       gint ret;\r
-
-       while(actual < buf_len) {\r
-               /* Write to Device */
-               ret = write(fd, (guchar *)buf, buf_len - actual);\r
+*      Read data from 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);
+    return;
+}
+
+/*
+*      Write data to vdpram.
+*/
+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("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("Maximum retries completed!!!");
-                                       return 0;
-                               }
-\r
-                               retry = retry + 1;
-                               continue;
-                       }
-\r
-                       if (actual != buf_len)
-                               err("Write [FAIL] - fd: [%d]", fd);
-\r
-                       err("Write [FAIL] - Error: [%s]", strerror(errno));
-                       return actual;\r
-               }\r
-\r
-               actual  += ret;\r
-               buf     += ret;\r
-               dbg("Write Actual bytes: [%d] Written bytes: [%d]", actual, ret);
-       };\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     */