ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS);
}
+#if 0
static void send_tethering_port_ecp(void)
{
type_length length;
g_free(msg);
}
}
+#endif
+
+static void send_tethering_connection_info(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[64];
+
+ msg = g_malloc(MSG_BUF_SIZE);
+ if (!msg) {
+ LOG_SEVERE("failed to allocate memory\n");
+ return;
+ }
+
+ LOG_INFO(">> send port_num: %d\n", tethering_port);
+ {
+ const char *ip = get_tethering_connected_ipaddr();
+ int port = get_tethering_connected_port();
+
+ if (!ip) {
+ LOG_SEVERE("invalid connected ip\n");
+ return;
+ }
+
+ if (!port) {
+ LOG_SEVERE("invalid connected port\n");
+ return;
+ }
+ g_snprintf(data, sizeof(data) - 1, "%s:%d", ip, port);
+ length = strlen(data);
+ data[length] = '\0';
+ }
+
+ 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_INFO(">> send connection msg to ecp. "
+ "action=%d, group=%d, data=%s length=%d\n",
+ action, group, data, length);
+
+ send_tethering_ntf((const char *)msg);
+
+ g_free(msg);
+}
static void send_tethering_status_ntf(type_group group, type_action action)
{
case ECS_TETHERING_MSG_ACTION_CONNECTION_STATUS:
status = get_tethering_connection_status();
if (status == CONNECTED) {
- send_tethering_port_ecp();
+ send_tethering_connection_info();
}
break;
case ECS_TETHERING_MSG_ACTION_SENSOR_STATUS:
gchar cmd[10] = {0};
gchar **server_addr = NULL;
- LOG_INFO("enter %s\n", __func__);
+ LOG_TRACE("enter %s\n", __func__);
g_strlcpy(cmd, msg->category, sizeof(cmd));
type_length length = (type_length) msg->length;
} else {
LOG_SEVERE("failed to parse port number\n");
}
-
LOG_INFO("len = %zd, data\" %s\"", strlen(data), data);
connect_tethering_app(ip_address, port);
break;
}
- LOG_INFO("leave %s\n", __func__);
+ LOG_TRACE("leave %s\n", __func__);
return true;
}
* - S-Core Co., Ltd
*
*/
+
#ifndef __WIN32
#include <sys/ioctl.h>
#else
#endif
#define SEND_BUF_MAX_SIZE 4096
-static const char *loopback="127.0.0.1";
+static const char *loopback = "127.0.0.1";
+
+enum connection_type {
+ NONE = 0,
+ USB,
+ WIFI,
+};
typedef struct tethering_recv_buf {
uint32_t len;
// connection state
int status;
+ int type;
// receiver handling thread
QemuThread thread;
} TetheringState;
-static TetheringState *tethering_client;
+static TetheringState *tethering_client = NULL;
static tethering_recv_buf recv_buf;
-// static bool app_state = false;
static void end_tethering_socket(int sockfd);
static void set_tethering_connection_status(int status);
#if 0
+static bool app_state = false;
+
static void set_tethering_app_state(bool state);
static bool get_tethering_app_state(void);
#endif
// message handlers
static void msgproc_tethering_handshake_ans(Tethering__HandShakeAns *msg)
{
- // FIXME: handle handshake answer
- // ans = msg->result;
+ // handle handshake answer
}
static void msgproc_app_state_msg(Tethering__AppState *msg)
set_tethering_touch_status(status);
disconnect_tethering_app();
- } else {
- // does nothing
}
}
static int start_tethering_socket(const char *ipaddress, int port)
{
struct sockaddr_in addr;
- int sock = -1;
- int ret = 0;
+ int sock = -1, ret = 0;
addr.sin_family = AF_INET;
addr.sin_port = htons(port); // i.e. 1234
LOG_INFO("server ip address: %s, port: %d\n", ipaddress, port);
ret = inet_aton(ipaddress, &addr.sin_addr);
-
if (ret == 0) {
- LOG_SEVERE("inet_aton failure\n");
+ perror("inet_aton failure\n");
return -1;
}
int status = 0;
if (!tethering_client) {
- return -1;
+ LOG_INFO("tethering_client is null\n");
+ LOG_INFO("tetherging connection status: %d\n", status);
+ return DISCONNECTED;
}
qemu_mutex_lock(&tethering_client->mutex);
status = tethering_client->status;
qemu_mutex_unlock(&tethering_client->mutex);
+ LOG_INFO("tetherging connection status: %d\n", status);
+
return status;
}
+int get_tethering_connected_port(void)
+{
+ if (!tethering_client) {
+ LOG_SEVERE("tethering_client is null\n");
+ return 0;
+ }
+
+ LOG_TRACE("connected port: %d\n", tethering_client->port);
+ return tethering_client->port;
+}
+
+const char *get_tethering_connected_ipaddr(void)
+{
+ if (!tethering_client) {
+ LOG_SEVERE("tethering client is null\n");
+ return NULL;
+ }
+
+ LOG_TRACE("connected ip address: %s\n", tethering_client->ipaddress);
+ return tethering_client->ipaddress;
+}
+
static void set_tethering_connection_status(int status)
{
if (!tethering_client) {
if (ipaddress) {
ipaddr_len = strlen(ipaddress);
+ client->type = WIFI;
} else {
- // ipaddr_len = strlen(LOOPBACK);
ipaddr_len = strlen(loopback);
ipaddress = loopback;
+ client->type = USB;
}
client->ipaddress = g_malloc0(ipaddr_len + 1);
if (!client->ipaddress) {
+ LOG_SEVERE("failed to allocate ipaddress buffer\n");
g_free(client);
return -1;
}
+
g_strlcpy(client->ipaddress, ipaddress, ipaddr_len + 1);
+ LOG_INFO("connection info. ip %s, port %d type %d\n",
+ client->ipaddress, client->port, client->type);
tethering_client = client;
- qemu_mutex_init(&tethering_client->mutex);
+ qemu_mutex_init(&tethering_client->mutex);
qemu_thread_create(&tethering_client->thread, "tethering-io-thread",
initialize_tethering_socket, client,
QEMU_THREAD_DETACHED);
sock = tethering_client->fd;
if (sock < 0) {
- LOG_SEVERE("tethering socket is terminated or not ready\n");
+ LOG_SEVERE("tethering socket is already terminated or not ready\n");
return -1;
} else {
send_emul_state_msg();