#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");
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;
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();
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;
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:
tethering_recv_buf recv_buf;
} TetheringState;
+#if 0
enum connection_status {
CONNECTED = 1,
DISCONNECTED,
CONNECTING,
+ CONNREFUSED,
};
enum device_status {
DISABLED,
};
+enum touch_status {
+ RELEASED = 0,
+ PRESSED,
+};
+#endif
+
enum sensor_level {
level_accel = 1,
level_proxi = 2,
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;
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;
{
struct sockaddr_in addr;
- int sock = -1, opt = 0;
+ int sock = -1;
int ret = 0;
addr.sin_family = AF_INET;
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);
// 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;
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)
return -1;
}
+ INFO("tethering_sock: %d\n", sock);
tethering_sock = sock;
reset_tethering_recv_buf(&recv_buf);