From bfe02011b79d2a97b77212cf72bfecc1684cf2b8 Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Wed, 23 Apr 2014 13:22:14 +0900 Subject: [PATCH] tethering: support wifi connection Make a connection no matter which type of connection is used. Change-Id: Iaf29392531ee5b0ca21d606cf3d2e927fef35a84 Signed-off-by: Kitae Kim --- tizen/src/ecs/ecs_tethering.c | 54 +++++++++++++++++++++---------------- tizen/src/ecs/ecs_tethering.h | 18 ++++++++++++- tizen/src/tethering/app_tethering.c | 27 ++++++++++++++----- tizen/src/tethering/app_tethering.h | 2 +- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/tizen/src/ecs/ecs_tethering.c b/tizen/src/ecs/ecs_tethering.c index a703435..f87a21b 100644 --- a/tizen/src/ecs/ecs_tethering.c +++ b/tizen/src/ecs/ecs_tethering.c @@ -40,21 +40,6 @@ MULTI_DEBUG_CHANNEL(tizen, ecs_tethering); #define MSG_BUF_SIZE 255 #define MSG_LEN_SIZE 4 -#if 0 -// ecs <-> ecp messages -#define ECS_TETHERING_MSG_CATEGORY "tethering" - -#define ECS_TETHERING_MSG_GROUP_ECP 1 -// #define TETHERING_MSG_GROUP_USB -// #define TETHERING_MSG_GROUP_WIFI - -#define ECS_TETHERING_MSG_ACTION_CONNECT 1 -#define ECS_TETHERING_MSG_ACTION_DISCONNECT 2 -#define ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS 3 -#define ECS_TETHERING_MSG_ACTION_SENSOR_STATUS 4 -#define ECS_TETHERING_MSG_ACTION_TOUCH_STATUS 5 -#endif - // 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); @@ -234,6 +219,7 @@ void send_tethering_touch_data(int x, int y, int index, int status) bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) { gchar cmd[10] = {0}; + gchar **server_addr = NULL; g_strlcpy(cmd, msg->category, sizeof(cmd)); type_length length = (type_length) msg->length; @@ -247,19 +233,41 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg) switch(action) { case ECS_TETHERING_MSG_ACTION_CONNECT: { + // get ip address and port if (msg->data.data && msg->data.len > 0) { const gchar *data = (const gchar *)msg->data.data; - gint port = 0; - - port = g_ascii_strtoull(data, NULL, 10); - - TRACE(">> MSG_ACTION_CONNECT\n"); - TRACE(">> len = %zd, data\" %s\"\n", strlen(data), data); - - connect_tethering_app(port); + // gchar **server_addr = NULL; + gchar *ip_address = NULL; + guint64 port = 0; + + server_addr = g_strsplit(data, ":", 0); + if (server_addr && server_addr[0]) { + int len = strlen(server_addr[0]); + + if (len) { + ip_address = g_malloc(len + 1); + g_strlcpy(ip_address, server_addr[0], len + 1); + } + INFO("IP address: %s, length: %d\n", ip_address, len); + } + + if (server_addr && server_addr[1]) { + port = g_ascii_strtoull(server_addr[1], NULL, 10); + INFO("port number: %d\n", port); + } else { + ERR("failed to parse port number\n"); + } + + TRACE("MSG_ACTION_CONNECT"); + TRACE("len = %zd, data\" %s\"", strlen(data), data); + + connect_tethering_app(ip_address, port); tethering_port = port; TRACE(">> port_num: %d, %d\n", port, tethering_port); + g_free(ip_address); + + g_strfreev(server_addr); } } break; diff --git a/tizen/src/ecs/ecs_tethering.h b/tizen/src/ecs/ecs_tethering.h index 0df460f..1acf078 100644 --- a/tizen/src/ecs/ecs_tethering.h +++ b/tizen/src/ecs/ecs_tethering.h @@ -28,21 +28,37 @@ * */ -// ecs <-> ecp messages +/* + * define tethering messages between ecs and ecp + */ #define ECS_TETHERING_MSG_CATEGORY "tethering" #define ECS_TETHERING_MSG_GROUP_ECP 1 // #define TETHERING_MSG_GROUP_USB // #define TETHERING_MSG_GROUP_WIFI +#if 0 #define ECS_TETHERING_MSG_ACTION_CONNECT 1 #define ECS_TETHERING_MSG_ACTION_DISCONNECT 2 #define ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS 3 #define ECS_TETHERING_MSG_ACTION_SENSOR_STATUS 4 #define ECS_TETHERING_MSG_ACTION_TOUCH_STATUS 5 +#endif + +enum ECS_TETHERING_MSG_ACTION { + ECS_TETHERING_MSG_ACTION_CONNECT = 1, + ECS_TETHERING_MSG_ACTION_DISCONNECT, + ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS, + ECS_TETHERING_MSG_ACTION_SENSOR_STATUS, + ECS_TETHERING_MSG_ACTION_TOUCH_STATUS, +}; void send_tethering_sensor_status_ecp(void); + void send_tethering_touch_status_ecp(void); + void send_tethering_connection_status_ecp(void); + void send_tethering_sensor_data(const char *data, int len); + void send_tethering_touch_data(int x, int y, int index, int status); diff --git a/tizen/src/tethering/app_tethering.c b/tizen/src/tethering/app_tethering.c index 8d28b11..e637de6 100644 --- a/tizen/src/tethering/app_tethering.c +++ b/tizen/src/tethering/app_tethering.c @@ -865,16 +865,28 @@ static int destroy_tethering_io_handler(int fd) return ret; } -static int start_tethering_socket(int port) +static int start_tethering_socket(const char *ipaddress, int port) { struct sockaddr_in addr; + gchar serveraddr[32] = { 0, }; int sock = -1; int ret = 0; + addr.sin_family = AF_INET; addr.sin_port = htons(port); // i.e. 1234 - ret = inet_aton("127.0.0.1", &addr.sin_addr); + + if (ipaddress == NULL) { + g_strlcpy(serveraddr, "127.0.0.1", sizeof(serveraddr)); + } else { + g_strlcpy(serveraddr, ipaddress, sizeof(serveraddr)); + } + + INFO("server ip address: %s, port: %d\n", serveraddr, port); + + ret = inet_aton(serveraddr, &addr.sin_addr); + if (ret == 0) { ERR("inet_aton failure\n"); return -1; @@ -893,6 +905,7 @@ static int start_tethering_socket(int port) set_tethering_connection_status(CONNECTING); do { if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + perror("connect failure"); INFO("tethering socket is connecting.\n"); ret = -socket_error(); } else { @@ -901,14 +914,16 @@ static int start_tethering_socket(int port) // set_tethering_app_state(true); break; } - TRACE("ret: %d\n", ret); + INFO("ret: %d\n", ret); } while (ret == -EINPROGRESS); if (ret < 0 && ret != -EISCONN) { if (ret == -ECONNREFUSED) { + INFO("socket connection is refused\n"); set_tethering_connection_status(CONNREFUSED); } - closesocket(sock); + INFO("close socket\n"); + end_tethering_socket(sock); sock = -1; } @@ -979,13 +994,13 @@ static void set_tethering_multitouch_status(int status) send_tethering_touch_status_ecp(); } -int connect_tethering_app(int port) +int connect_tethering_app(const char *ipaddress, int port) { int sock = 0, ret = 0; TRACE("connect ecp to app\n"); - sock = start_tethering_socket(port); + sock = start_tethering_socket(ipaddress, port); if (sock < 0) { ERR("failed to start tethering_socket\n"); tethering_sock = -1; diff --git a/tizen/src/tethering/app_tethering.h b/tizen/src/tethering/app_tethering.h index 9441d75..c2ba1d2 100644 --- a/tizen/src/tethering/app_tethering.h +++ b/tizen/src/tethering/app_tethering.h @@ -45,7 +45,7 @@ enum touch_status { PRESSED, }; -int connect_tethering_app(int port); +int connect_tethering_app(const char *ipaddress, int port); int disconnect_tethering_app(void); -- 2.7.4