From 1e92a3f211337188e1c33711a6e1c437ffe401be Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Mon, 11 Nov 2013 18:06:46 +0900 Subject: [PATCH] tethering: modified connection error routine. Added routine to handle connection refused case. In addition to this, port number needs to be sent to ecp when ecp is launched again after being connected. Change-Id: Ia5a4104452024f7558febf1410b366e94ed3d8a1 Signed-off-by: Kitae Kim --- tizen/src/ecs/ecs_tethering.c | 56 +++++++++++++++++++++++++++++++++---- tizen/src/tethering/app_tethering.c | 51 +++++++++++++++------------------ tizen/src/tethering/app_tethering.h | 17 +++++++++++ 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/tizen/src/ecs/ecs_tethering.c b/tizen/src/ecs/ecs_tethering.c index 066459b..f5c64af 100644 --- a/tizen/src/ecs/ecs_tethering.c +++ b/tizen/src/ecs/ecs_tethering.c @@ -55,10 +55,12 @@ MULTI_DEBUG_CHANNEL(tizen, ecs_tethering); #define ECS_TETHERING_MSG_ACTION_TOUCH_STATUS 5 #endif -// ecs <-> ecp -static bool send_tethering_ntf(const char *data, const int len); +// static bool send_tethering_ntf(const char *data, const int len); +static bool send_tethering_ntf(const char *data); static void send_tethering_status_ntf(type_group group, type_action action); +static int tethering_port = 0; + void send_tethering_sensor_status_ecp(void) { LOG(">> send tethering_event_status to ecp"); @@ -79,6 +81,41 @@ void send_tethering_connection_status_ecp(void) ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS); } +static void send_tethering_port_ecp(void) +{ + type_length length; + type_group group = ECS_TETHERING_MSG_GROUP_ECP; + type_action action = ECS_TETHERING_MSG_ACTION_CONNECT; + uint8_t *msg = NULL; + gchar data[12]; + + msg = g_malloc(MSG_BUF_SIZE); + if (!msg) { + return; + } + + LOG(">> send port_num: %d", tethering_port); + + g_snprintf(data, sizeof(data) - 1, "%d", tethering_port); + length = strlen(data); + + memcpy(msg, ECS_TETHERING_MSG_CATEGORY, 10); + memcpy(msg + 10, &length, sizeof(unsigned short)); + memcpy(msg + 12, &group, sizeof(unsigned char)); + memcpy(msg + 13, &action, sizeof(unsigned char)); + memcpy(msg + 14, data, length); + + LOG(">> send tethering_ntf to ecp. action=%d, group=%d, data=%s", + action, group, data); + +// send_tethering_ntf((const char *)msg, MSG_BUF_SIZE); + send_tethering_ntf((const char *)msg); + + if (msg) { + g_free(msg); + } +} + static void send_tethering_status_ntf(type_group group, type_action action) { type_length length = 1; @@ -89,6 +126,9 @@ static void send_tethering_status_ntf(type_group group, type_action action) switch (action) { case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS: status = get_tethering_connection_status(); + if (status == CONNECTED) { + send_tethering_port_ecp(); + } break; case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS: status = get_tethering_sensor_status(); @@ -116,14 +156,16 @@ static void send_tethering_status_ntf(type_group group, type_action action) LOG(">> send tethering_ntf to ecp. action=%d, group=%d, data=%s", action, group, data); - send_tethering_ntf((const char *)msg, MSG_BUF_SIZE); +// send_tethering_ntf((const char *)msg, MSG_BUF_SIZE); + send_tethering_ntf((const char *)msg); if (msg) { g_free(msg); } } -static bool send_tethering_ntf(const char *data, const int len) +// static bool send_tethering_ntf(const char *data, const int len) +static bool send_tethering_ntf(const char *data) { type_length length = 0; type_group group = 0; @@ -212,17 +254,19 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) port = g_ascii_strtoull(data, NULL, 10); LOG(">> MSG_ACTION_CONNECT"); - LOG(">> port_num: %d", port); LOG(">> len = %zd, data\" %s\"", strlen(data), data); connect_tethering_app(port); + tethering_port = port; + + LOG(">> port_num: %d, %d", port, tethering_port); } } break; case ECS_TETHERING_MSG_ACTION_DISCONNECT: LOG(">> MSG_ACTION_DISCONNECT"); - // end_tethering_socket(tethering_sock); disconnect_tethering_app(); + tethering_port = 0; break; case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS: case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS: diff --git a/tizen/src/tethering/app_tethering.c b/tizen/src/tethering/app_tethering.c index d0ff763..fb2e656 100644 --- a/tizen/src/tethering/app_tethering.c +++ b/tizen/src/tethering/app_tethering.c @@ -62,10 +62,12 @@ typedef struct _TetheringState { tethering_recv_buf recv_buf; } TetheringState; +#if 0 enum connection_status { CONNECTED = 1, DISCONNECTED, CONNECTING, + CONNREFUSED, }; enum device_status { @@ -73,6 +75,12 @@ enum device_status { DISABLED, }; +enum touch_status { + RELEASED = 0, + PRESSED, +}; +#endif + enum sensor_level { level_accel = 1, level_proxi = 2, @@ -83,14 +91,9 @@ enum sensor_level { level_magnetic = 13 }; -enum touch_status { - RELEASED = 0, - PRESSED, -}; - #ifndef DEBUG -const char *connection_status_str[3] = {"CONNECTED", "DISCONNECTED", - "CONNECTING"}; +const char *connection_status_str[4] = {"CONNECTED", "DISCONNECTED", + "CONNECTING", "CONNREFUSED"}; #endif static tethering_recv_buf recv_buf; @@ -501,8 +504,8 @@ static bool send_set_multitouch_resolution(void) TRACE("enter: %s\n", __func__); - resolution.width = get_emul_lcd_width(); - resolution.height = get_emul_lcd_height(); + resolution.width = get_emul_resolution_width(); + resolution.height = get_emul_resolution_height(); mt.type = INJECTOR__MULTI_TOUCH_MSG__TYPE__RESOLUTION; mt.resolution = &resolution; @@ -862,7 +865,7 @@ static int start_tethering_socket(int port) { struct sockaddr_in addr; - int sock = -1, opt = 0; + int sock = -1; int ret = 0; addr.sin_family = AF_INET; @@ -871,22 +874,12 @@ static int start_tethering_socket(int port) sock = qemu_socket(PF_INET, SOCK_STREAM, 0); if (sock < 0) { - // handle error, print message - set_tethering_connection_status(DISCONNECTED); +// set_tethering_connection_status(DISCONNECTED); + ERR("tethering socket creation is failed\n", sock); return -1; } INFO("tethering socket is created: %d\n", sock); - ret = - qemu_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - if (ret < 0) { - // handle error, - ERR("setsockopt failure\n"); - end_tethering_socket(sock); - return -1; - } - - // set nonblock mode qemu_set_nonblock(sock); set_tethering_connection_status(CONNECTING); @@ -900,14 +893,15 @@ static int start_tethering_socket(int port) // set_tethering_app_state(true); break; } - INFO("ret: %d\n", ret); -// } while (ret == -EINTR); + TRACE("ret: %d\n", ret); } while (ret == -EINPROGRESS); - if (ret < 0) { - end_tethering_socket(sock); + if (ret < 0 && ret != -EISCONN) { + if (ret == -ECONNREFUSED) { + set_tethering_connection_status(CONNREFUSED); + } + closesocket(sock); sock = -1; - INFO("tethering_sock: %d\n", sock); } return sock; @@ -974,7 +968,7 @@ int get_tethering_multitouch_status(void) static void set_tethering_multitouch_status(int status) { mt_device_status = status; - send_tethering_multitouch_status_ecp(); + send_tethering_touch_status_ecp(); } int connect_tethering_app(int port) @@ -990,6 +984,7 @@ int connect_tethering_app(int port) return -1; } + INFO("tethering_sock: %d\n", sock); tethering_sock = sock; reset_tethering_recv_buf(&recv_buf); diff --git a/tizen/src/tethering/app_tethering.h b/tizen/src/tethering/app_tethering.h index 35850dc..9441d75 100644 --- a/tizen/src/tethering/app_tethering.h +++ b/tizen/src/tethering/app_tethering.h @@ -28,6 +28,23 @@ * */ +enum connection_status { + CONNECTED = 1, + DISCONNECTED, + CONNECTING, + CONNREFUSED, +}; + +enum device_status { + ENABLED = 1, + DISABLED, +}; + +enum touch_status { + RELEASED = 0, + PRESSED, +}; + int connect_tethering_app(int port); int disconnect_tethering_app(void); -- 2.7.4