#ifndef _DR_IPC_H
-#define _DR_IPC_H
+#define _DR_IPC_H
#include <glib.h>
-/**
- * @def USB_BUFFER_SIZE
- * Defines the maximum buffer size for the USB
- */
+/**
+ * @def USB_BUFFER_SIZE
+ * Defines the maximum buffer size for the USB
+ */
#define USB_BUFFER_SIZE 1500
#define ERRMSG_SIZE 100
int _get_at_cmd_type(char *buf);
-#endif
+#endif //_DR_PARSER_H_
#ifndef _DR_USB_H
-#define _DR_USB_H
+#define _DR_USB_H
/*
/** @internal
- * This function initialises the USB interface
- *
- * @return This function returns 0 if the USB has been initialised successfully or it returns -1 on failure
- *
- */
+ * This function initialises the USB interface
+ *
+ * @return This function returns 0 if the USB has been initialised successfully or it returns -1 on failure
+ *
+ */
int _init_usb(void);
/** @internal
- * This function deinitialises the USB interface
- */
+ * This function deinitialises the USB interface
+ */
void _deinit_usb(void);
/** @internal
- * This function is used to write data to the USB interface
- *
- * @param [in] buf data to be written to USB
- * @param [in] buf_len no of bytes of data to be written to USB
- * @return This function returns the no of bytes written to the USB.
- */
+ * This function is used to write data to the USB interface
+ *
+ * @param [in] buf data to be written to USB
+ * @param [in] buf_len no of bytes of data to be written to USB
+ * @return This function returns the no of bytes written to the USB.
+ */
int _write_to_usb(char *buf, int buf_len);
/** @internal
- * This function is used to send modem line state to Host PC
- *
- * @param [in] ctrl status of control lines
- * @return This function returns zero if successful else returns -EIO
- *
- */
+ * This function is used to send modem line state to Host PC
+ *
+ * @param [in] ctrl status of control lines
+ * @return This function returns zero if successful else returns -EIO
+ *
+ */
int _send_usb_line_state(int ctrl);
int _system_cmd(const char *command);
int _system_cmd_ext(const char *cmd, char *const arg_list[]);
-#endif
+#endif //_DR_UTIL_H_
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib-bindings.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
typedef enum {
SERIAL_SESSION_DISCONNECTED,
SERIAL_SESSION_CONNECTED
-}dr_session_state_t;
+} dr_session_state_t;
typedef struct {
int server_socket;
int g_watch_id_client;
GIOChannel *g_io;
unsigned char state;
-}dr_socket_info_t;
+} dr_socket_info_t;
dr_socket_info_t serial_session = {0, };
static DBusHandlerResult __dbus_event_filter(DBusConnection *sys_conn,
- DBusMessage *msg, void *data)
+ DBusMessage *msg, void *data)
{
const char *path = dbus_message_get_path(msg);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
if (dbus_message_is_signal(msg, NETWORK_SERIAL_INTERFACE,
- "ready_for_serial")) {
+ "ready_for_serial")) {
char *res = NULL;
dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &res,
- DBUS_TYPE_INVALID);
+ DBUS_TYPE_STRING, &res,
+ DBUS_TYPE_INVALID);
if (g_strcmp0(res, "OK") == 0)
_send_serial_status_signal(SERIAL_OPENED);
DBusError dbus_error;
conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
- if(!conn) {
+ if (!conn) {
ERR(" DBUS get failed\n");
g_error_free(err);
return FALSE;
dbus_error_init(&dbus_error);
dbus_connection_add_filter(dbus_connection, __dbus_event_filter, NULL, NULL);
dbus_bus_add_match(dbus_connection,
- "type=signal,interface=" NETWORK_SERIAL_INTERFACE
- ",member=ready_for_serial", &dbus_error);
+ "type=signal,interface=" NETWORK_SERIAL_INTERFACE
+ ",member=ready_for_serial", &dbus_error);
if (dbus_error_is_set(&dbus_error)) {
ERR("Fail to add dbus filter signal\n");
dbus_error_free(&dbus_error);
void _send_serial_status_signal(int event)
{
DBusMessage *msg = NULL;
- if(dbus_connection == NULL) return;
+ if (dbus_connection == NULL) return;
msg = dbus_message_new_signal("/DataRouter",
- "User.Data.Router.Introspectable",
- "serial_status");
+ "User.Data.Router.Introspectable",
+ "serial_status");
if (!msg) {
ERR("Unable to allocate D-Bus signal\n");
return;
}
if (!dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &event,
- DBUS_TYPE_INVALID)) {
+ DBUS_TYPE_INT32, &event,
+ DBUS_TYPE_INVALID)) {
ERR("Event sending failed\n");
dbus_message_unref(msg);
return;
}
- DBG("Send dbus signal : %s\n", event ? "SERIAL_OPENED":"SERIAL_CLOSED");
+ DBG("Send dbus signal : %s\n", event ? "SERIAL_OPENED" : "SERIAL_CLOSED");
dbus_connection_send(dbus_connection, msg, NULL);
dbus_message_unref(msg);
return;
int ret;
DBG("Closing socket\n");
ret = close(serial_session.client_socket);
- if (ret == -1) {
+ if (ret == -1)
perror("close error: ");
- }
+
serial_session.state = SERIAL_SESSION_DISCONNECTED;
return;
}
socklen_t addrlen;
addrlen = sizeof(client_addr);
- if ( cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR) ) {
+ if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
DBG("GIOCondition %d \n", cond);
- if(serial_session.server_socket >= 0) {
+ if (serial_session.server_socket >= 0) {
close(serial_session.server_socket);
serial_session.server_socket = 0;
}
return FALSE;
}
- if(serial_session.state == SERIAL_SESSION_CONNECTED) {
+ if (serial_session.state == SERIAL_SESSION_CONNECTED) {
DBG("Connection already exists.....\n");
return FALSE;
}
io = g_io_channel_unix_new(clientfd);
g_io_channel_set_close_on_unref(io, TRUE);
serial_session.g_watch_id_client = g_io_add_watch(io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
- __g_io_server_handler, NULL);
+ __g_io_server_handler, NULL);
g_io_channel_unref(io);
- serial_session.client_socket= clientfd;
+ serial_session.client_socket = clientfd;
serial_session.state = SERIAL_SESSION_CONNECTED;
} else {
ERR("Accept failed\n");
serial_session.g_io = g_io_channel_unix_new(server_socket);
g_io_channel_set_close_on_unref(serial_session.g_io, TRUE);
serial_session.g_watch_id_server = g_io_add_watch(serial_session.g_io,
- G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
- __g_io_accept_handler, NULL);
+ G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ __g_io_accept_handler, NULL);
g_io_channel_unref(serial_session.g_io);
return;
gboolean _is_exist_serial_session(void)
{
- return (serial_session.state == SERIAL_SESSION_CONNECTED) ? TRUE: FALSE;
+ return (serial_session.state == SERIAL_SESSION_CONNECTED) ? TRUE : FALSE;
}
gboolean _wait_serial_session(void)
/**************** USB ******************/
if (_get_usb_state(&usb_state) != -1) {
- if (usb_state != VCONFKEY_SYSMAN_USB_DISCONNECTED ) {
+ if (usb_state != VCONFKEY_SYSMAN_USB_DISCONNECTED)
_init_usb();
- }
}
DBG("-\n");
{
DBG("+\n");
-#if !GLIB_CHECK_VERSION (2, 35, 0)
+#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init();
#endif
_init_dbus_signal();
static gboolean acm_enabled(int mode)
{
- switch(mode) {
+ switch (mode) {
case SET_USB_DEFAULT:
case SET_USB_SDB:
case SET_USB_SDB_DIAG:
{
int ret;
- ret =
- vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS, (vconf_callback_fn) __usb_status_noti_handler, NULL);
- if (ret < 0) {
+ ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
+ (vconf_callback_fn)__usb_status_noti_handler, NULL);
+ if (ret < 0)
ERR("Error !!! VCONFKEY reg noti : %s\n", VCONFKEY_SYSMAN_USB_STATUS);
- }
- ret =
- vconf_notify_key_changed(VCONFKEY_USB_CUR_MODE,
- (vconf_callback_fn) __usb_mode_noti_handler, NULL);
- if (ret < 0) {
+ ret = vconf_notify_key_changed(VCONFKEY_USB_CUR_MODE,
+ (vconf_callback_fn) __usb_mode_noti_handler, NULL);
+ if (ret < 0)
ERR("Error !!! VCONFKEY reg noti : %s\n", VCONFKEY_USB_CUR_MODE);
- }
return TRUE;
}
void _unregister_vconf_notification(void)
{
- vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, (vconf_callback_fn) __usb_status_noti_handler);
- vconf_ignore_key_changed(VCONFKEY_USB_CUR_MODE, (vconf_callback_fn) __usb_mode_noti_handler);
+ vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
+ (vconf_callback_fn) __usb_status_noti_handler);
+ vconf_ignore_key_changed(VCONFKEY_USB_CUR_MODE,
+ (vconf_callback_fn) __usb_mode_noti_handler);
return;
}
int _get_at_cmd_type(char *buf)
{
- if (buf == NULL) {
+ if (buf == NULL)
return TOKEN_ERROR;
- }
int idx;
for (idx = 0; dr_at_cmds[idx].at_cmd[0] != '\0'; idx++) {
if (!g_ascii_strncasecmp
- ((const gchar *)buf, (const gchar *)dr_at_cmds[idx].at_cmd,
- strlen(dr_at_cmds[idx].at_cmd))) {
+ ((const gchar *)buf, (const gchar *)dr_at_cmds[idx].at_cmd,
+ strlen(dr_at_cmds[idx].at_cmd))) {
DBG("Found %s\n", dr_at_cmds[idx].at_cmd);
buf = buf + strlen(dr_at_cmds[idx].at_cmd);
return dr_at_cmds[idx].token_type;
return 0;
failed:
- if(usb_fd >= 0) {
+ if (usb_fd >= 0)
close(usb_fd);
- }
- if(ctl_fd >= 0) {
+
+ if (ctl_fd >= 0)
close(ctl_fd);
- }
+
return -1;
}
{
DBG("+\n");
int status;
- if(dr_info.usb.thread_id <= 0) {
+ if (dr_info.usb.thread_id <= 0) {
ERR("Invalid USB interface !!! \n");
return;
}
static void __process_at_cmd(char *buffer, int nread)
{
- if(buffer == NULL || nread == 0)
+ if (buffer == NULL || nread == 0)
return;
int type;
int check_cnt = 0;
char *info = NULL;
- DBG("Received: %s [%d byte]\n",buffer, nread);
- if(TRUE == _is_exist_serial_session()) {
+ DBG("Received: %s [%d byte]\n", buffer, nread);
+ if (TRUE == _is_exist_serial_session()) {
_write_to_serial_client(buffer, nread);
return;
}
sizeof(dr_info.usb.data_buffer)-1);
if (nread < 0) {
ERR("read length is less then zero\n");
- if (errno == EINTR) {
+ if (errno == EINTR)
continue;
- }
+
perror("Read USB failed");
__close_usb_node();
pthread_exit(NULL);
&line_state, sizeof(unsigned int));
if (ret < 0) {
ERR("read length is less then zero\n");
- if (errno == EINTR) {
+ if (errno == EINTR)
continue;
- }
+
__close_usb_node();
pthread_exit(NULL);
}
if ((line_state & ACM_CTRL_DTR) &&
(dr_info.line.input_line_state.bits.dtr == FALSE)) {
DBG("ACM_CTRL_DTR+ received\n");
- if(dr_info.line.output_line_state.bits.dsr == FALSE) {
- /*
- * When USB initialized, DTR On is set to CP.
- * If DR set DTR ON twice, Modem will be reponse as DSR Off
- */
+ if (dr_info.line.output_line_state.bits.dsr == FALSE) {
+ /*
+ * When USB initialized, DTR On is set to CP.
+ * If DR set DTR ON twice, Modem will be reponse as DSR Off
+ */
_send_dtr_ctrl_signal(DTR_ON);
}
dr_info.line.input_line_state.bits.dtr = TRUE;
__close_usb_node();
pthread_exit(NULL);
}
- }
- else if (poll_state == 0)
+ } else if (poll_state == 0) {
ERR("poll timeout\n");
- else if (poll_state < 0)
+ } else if (poll_state < 0) {
ERR("poll error\n");
+ }
}
return NULL;
}
case 0:
pid2 = fork();
- if(pid2 == 0) {
+ if (pid2 == 0) {
execv(cmd, arg_list);
exit(256);
} else