2 * Emulator Control Server - Device Tethering Handler
4 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
7 * KiTae Kim <kt920.kim@samsung.com>
8 * JiHye Kim <jihye1128.kim@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include "ui/console.h"
33 #include "ecs_tethering.h"
34 #include "../tethering/app_tethering.h"
35 #include "../hw/maru_virtio_touchscreen.h"
36 #include "../debug_ch.h"
38 MULTI_DEBUG_CHANNEL(tizen, ecs_tethering);
40 #define MSG_BUF_SIZE 255
41 #define MSG_LEN_SIZE 4
44 // ecs <-> ecp messages
45 #define ECS_TETHERING_MSG_CATEGORY "tethering"
47 #define ECS_TETHERING_MSG_GROUP_ECP 1
48 // #define TETHERING_MSG_GROUP_USB
49 // #define TETHERING_MSG_GROUP_WIFI
51 #define ECS_TETHERING_MSG_ACTION_CONNECT 1
52 #define ECS_TETHERING_MSG_ACTION_DISCONNECT 2
53 #define ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS 3
54 #define ECS_TETHERING_MSG_ACTION_SENSOR_STATUS 4
55 #define ECS_TETHERING_MSG_ACTION_TOUCH_STATUS 5
58 // static bool send_tethering_ntf(const char *data, const int len);
59 static bool send_tethering_ntf(const char *data);
60 static void send_tethering_status_ntf(type_group group, type_action action);
62 static int tethering_port = 0;
64 void send_tethering_sensor_status_ecp(void)
66 INFO(">> send tethering_event_status to ecp\n");
67 send_tethering_status_ntf(ECS_TETHERING_MSG_GROUP_ECP,
68 ECS_TETHERING_MSG_ACTION_SENSOR_STATUS);
71 void send_tethering_touch_status_ecp(void)
73 send_tethering_status_ntf(ECS_TETHERING_MSG_GROUP_ECP,
74 ECS_TETHERING_MSG_ACTION_TOUCH_STATUS);
77 void send_tethering_connection_status_ecp(void)
79 INFO(">> send tethering_connection_status to ecp\n");
80 send_tethering_status_ntf(ECS_TETHERING_MSG_GROUP_ECP,
81 ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS);
84 static void send_tethering_port_ecp(void)
87 type_group group = ECS_TETHERING_MSG_GROUP_ECP;
88 type_action action = ECS_TETHERING_MSG_ACTION_CONNECT;
92 msg = g_malloc(MSG_BUF_SIZE);
97 TRACE(">> send port_num: %d\n", tethering_port);
99 g_snprintf(data, sizeof(data) - 1, "%d", tethering_port);
100 length = strlen(data);
102 memcpy(msg, ECS_TETHERING_MSG_CATEGORY, 10);
103 memcpy(msg + 10, &length, sizeof(unsigned short));
104 memcpy(msg + 12, &group, sizeof(unsigned char));
105 memcpy(msg + 13, &action, sizeof(unsigned char));
106 memcpy(msg + 14, data, length);
108 TRACE(">> send tethering_ntf to ecp. action=%d, group=%d, data=%s\n",
109 action, group, data);
111 // send_tethering_ntf((const char *)msg, MSG_BUF_SIZE);
112 send_tethering_ntf((const char *)msg);
119 static void send_tethering_status_ntf(type_group group, type_action action)
121 type_length length = 1;
127 case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS:
128 status = get_tethering_connection_status();
129 if (status == CONNECTED) {
130 send_tethering_port_ecp();
133 case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS:
134 status = get_tethering_sensor_status();
136 case ECS_TETHERING_MSG_ACTION_TOUCH_STATUS:
137 status = get_tethering_multitouch_status();
143 msg = g_malloc(MSG_BUF_SIZE);
148 g_snprintf(data, sizeof(data), "%d", status);
150 memcpy(msg, ECS_TETHERING_MSG_CATEGORY, 10);
151 memcpy(msg + 10, &length, sizeof(unsigned short));
152 memcpy(msg + 12, &group, sizeof(unsigned char));
153 memcpy(msg + 13, &action, sizeof(unsigned char));
154 memcpy(msg + 14, data, 1);
156 TRACE(">> send tethering_ntf to ecp. action=%d, group=%d, data=%s\n",
157 action, group, data);
159 // send_tethering_ntf((const char *)msg, MSG_BUF_SIZE);
160 send_tethering_ntf((const char *)msg);
167 // static bool send_tethering_ntf(const char *data, const int len)
168 static bool send_tethering_ntf(const char *data)
170 type_length length = 0;
171 type_group group = 0;
172 type_action action = 0;
174 const int catsize = 10;
175 char cat[catsize + 1];
176 memset(cat, 0, catsize + 1);
178 read_val_str(data, cat, catsize);
179 read_val_short(data + catsize, &length);
180 read_val_char(data + catsize + 2, &group);
181 read_val_char(data + catsize + 2 + 1, &action);
183 const char* ijdata = (data + catsize + 2 + 1 + 1);
185 TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group);
187 ECS__Master master = ECS__MASTER__INIT;
188 ECS__TetheringNtf ntf = ECS__TETHERING_NTF__INIT;
190 ntf.category = (char*) g_malloc(catsize + 1);
191 strncpy(ntf.category, cat, 10);
200 ntf.data.data = g_malloc(length);
201 ntf.data.len = length;
202 memcpy(ntf.data.data, ijdata, length);
204 TRACE("data = %s, length = %hu\n", ijdata, length);
207 master.type = ECS__MASTER__TYPE__TETHERING_NTF;
208 master.tethering_ntf = &ntf;
210 send_to_ecp(&master);
212 if (ntf.data.data && ntf.data.len > 0) {
213 g_free(ntf.data.data);
217 g_free(ntf.category);
223 void send_tethering_sensor_data(const char *data, int len)
225 set_injector_data(data);
228 void send_tethering_touch_data(int x, int y, int index, int status)
230 virtio_touchscreen_event(x, y, index, status);
233 // handle tethering_req message
234 bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg)
238 g_strlcpy(cmd, msg->category, sizeof(cmd));
239 type_length length = (type_length) msg->length;
240 type_group group = (type_group) (msg->group & 0xff);
241 type_action action = (type_action) (msg->action & 0xff);
243 TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d\n",
244 cmd, length, action, group);
246 if (group == ECS_TETHERING_MSG_GROUP_ECP) {
248 case ECS_TETHERING_MSG_ACTION_CONNECT:
250 if (msg->data.data && msg->data.len > 0) {
251 const gchar *data = (const gchar *)msg->data.data;
254 port = g_ascii_strtoull(data, NULL, 10);
256 TRACE(">> MSG_ACTION_CONNECT\n");
257 TRACE(">> len = %zd, data\" %s\"\n", strlen(data), data);
259 connect_tethering_app(port);
260 tethering_port = port;
262 TRACE(">> port_num: %d, %d\n", port, tethering_port);
266 case ECS_TETHERING_MSG_ACTION_DISCONNECT:
267 INFO(">> MSG_ACTION_DISCONNECT\n");
268 disconnect_tethering_app();
271 case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS:
272 case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS:
273 case ECS_TETHERING_MSG_ACTION_TOUCH_STATUS:
274 TRACE(">> get_status_action\n");
275 send_tethering_status_ntf(group, action);