static int run_group_find(MManager *mm, struct menu_data *menu);
static int run_devices_find(MManager *mm, struct menu_data *menu);
-#define CASE_TO_STR(x) case x: return #x;
static const char* __device_type_to_string(companion_device_type_e type)
{
switch (type) {
/* CHECK: List all enum values here */
- CASE_TO_STR(COMPANION_DEVICE_TYPE_LOCAL)
- CASE_TO_STR(COMPANION_DEVICE_TYPE_REMOTE)
+ case COMPANION_DEVICE_TYPE_LOCAL:
+ return "Local";
+ case COMPANION_DEVICE_TYPE_REMOTE:
+ return "Remote";
default :
- return "COMPANION_DEVICE_TYPE_ERROR";
+ return "Unknown";
}
}
if (is_exist == FALSE) {
found_device_list = g_list_append(found_device_list, device);
- msgp("\r[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+ msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
__device_type_to_string(device_type));
}
companion_device_information_get_ip(device, &ip);
companion_device_information_get_device_type(device, &device_type);
- msgb("\n[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+ msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
__device_type_to_string(device_type));
if (device_id)
companion_device_information_get_ip(device, &ip);
companion_device_information_get_device_type(device, &device_type);
- msgp("\r[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+ msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip,
__device_type_to_string(device_type));
if (device_id)
companion_device_information_get_ip(devices[i], &ip);
companion_device_information_get_device_type(devices[i], &device_type);
- msgb("\n[ID] %s [IP] %s [TYPE] %s", device_id, ip,
+ msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip,
__device_type_to_string(device_type));
if (device_id)
* @brief Clones the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a dst should be released using companion_group_information_destroy().
*
* @brief Destroys the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @param[in] group Group handle
*
* @brief Gets group type of the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @param[in] group Group handle
* @param[out] type Group type
* @brief Gets resource type of the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a resource_type should be released using free().
*
* @brief Gets URI path of the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a uri_path should be released using free().
*
* @brief Gets name of the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a name should be released using free().
*
* @brief Gets host address of the group handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a host_addr should be released using free().
*
* @brief Clones the device handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a target should be released using companion_device_information_destroy().
*
* @brief Destroys the device handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @param[in] device Device handle
*
* @brief Gets device ID of the device handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a device_id should be released using free().
*
* @brief Gets IP of the device handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a ip should be released using free().
*
* @brief Gets device type of the device handle.
*
* @since_tizen 5.0
+ * @privlevel public
*
* @remarks The @a device_type should be released using free().
*
deviceid = (char *)g_variant_get_string(key_value, NULL);
else if (g_strcmp0(key, "Address") == 0)
addr = (char *)g_variant_get_string(key_value, NULL);
-/*
- else if (g_strcmp0(key, "SecVer") == 0)
- ver = (char *)g_variant_get_string(key_value, NULL);
-*/
+ else if (g_strcmp0(key, "DeviceType") == 0)
+ device_type = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "Port") == 0)
port = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "SecurePort") == 0)
deviceid = (char *)g_variant_get_string(key_value, NULL);
else if (g_strcmp0(key, "Address") == 0)
addr = (char *)g_variant_get_string(key_value, NULL);
-/*
- else if (g_strcmp0(key, "SecVer") == 0)
- ver = (char *)g_variant_get_string(key_value, NULL);
-*/
+ else if (g_strcmp0(key, "DeviceType") == 0)
+ device_type = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "Port") == 0)
port = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "SecurePort") == 0)
deviceid = (char *)g_variant_get_string(key_value, NULL);
else if (g_strcmp0(key, "Address") == 0)
addr = (char *)g_variant_get_string(key_value, NULL);
-/*
- else if (g_strcmp0(key, "SecVer") == 0)
- ver = (char *)g_variant_get_string(key_value, NULL);
-*/
+ else if (g_strcmp0(key, "DeviceType") == 0)
+ device_type = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "Port") == 0)
port = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "SecurePort") == 0)
companion_group_s * src = (companion_group_s *)source;
companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
+ ret = companion_group_information_create(&target);
+ if (COMP_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ _ERR("companion_group_information_create() Failed(%d)", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
if (src->uri_path)
dst->uri_path = g_strdup(src->uri_path);
companion_device_s * src = (companion_device_s *)source;
companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
+ ret = companion_device_information_create(&target);
+ if (COMP_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ _ERR("companion_device_information_create() Failed(%d)", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
if (src->device_id)
dst->device_id = g_strdup(src->device_id);
if (src->ip)
device_id = (char *)g_variant_get_string(key_value, NULL);
else if (g_strcmp0(key, "Address") == 0)
ip = (char *)g_variant_get_string(key_value, NULL);
-/*
- else if (g_strcmp0(key, "SecVer") == 0)
- device_type = (char *)g_variant_get_string(key_value, NULL);
-*/
+ else if (g_strcmp0(key, "DeviceType") == 0)
+ device_type = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "Port") == 0)
port = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "SecurePort") == 0)
device_id = (char *)g_variant_get_string(key_value, NULL);
else if (g_strcmp0(key, "Address") == 0)
ip = (char *)g_variant_get_string(key_value, NULL);
-/*
- else if (g_strcmp0(key, "SecVer") == 0)
- device_type = (char *)g_variant_get_string(key_value, NULL);
-*/
+ else if (g_strcmp0(key, "DeviceType") == 0)
+ device_type = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "Port") == 0)
port = g_variant_get_uint16(key_value);
else if (g_strcmp0(key, "SecurePort") == 0)
}
g_variant_iter_free(iter_row);
- device = create_device_handle(device_id, ip, device_type, port,
- sec_port);
+ device = create_device_handle(device_id, ip, device_type, port, sec_port);
if (handle->mowned_device_found_cb.found_cb)
handle->mowned_device_found_cb.found_cb(device,
handle->mowned_device_found_cb.user_data);
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __COMP_UTIL_H__
+#define __COMP_UTIL_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define LOCAL_IP 1 /**< Local IP */
+#define REMOTE_IP 2 /**< Remote IP */
+
+void comp_remove_ip_info(void);
+int comp_make_ip_info(void);
+int comp_compare_ip_and_ifname(char *ipdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __COMP_UTIL_H__ */
#include <comp_mot_agent.h>
#include <comp_gdbus_group.h>
#include <comp_db.h>
+#include <comp_util.h>
GList *found_group_list;
GList *mot_enb_dev_list = NULL;
return is_exist;
}
+
GVariant *comp_group_get_remote_mot_enabled_devices()
{
GVariantBuilder builder;
GVariant *group_data;
GList *iter = NULL;
+ comp_remove_ip_info();
+ comp_make_ip_info();
+
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
iter = mot_enb_dev_list;
g_variant_new_uint16(device->port));
g_variant_builder_add(&builder, "{sv}", "Address",
g_variant_new_string(device->addr));
+ g_variant_builder_add(&builder, "{sv}", "DeviceType",
+ g_variant_new_uint16(comp_compare_ip_and_ifname(device->addr)));
g_variant_builder_add(&builder, "{sv}", "Ifindex",
g_variant_new_int32(device->ifindex));
g_variant_builder_add(&builder, "{sv}", "RouteData",
GVariant *group_data;
GList *iter = NULL;
+ comp_remove_ip_info();
+ comp_make_ip_info();
+
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
iter = mowned_dev_list;
g_variant_new_uint16(device->port));
g_variant_builder_add(&builder, "{sv}", "Address",
g_variant_new_string(device->addr));
+ g_variant_builder_add(&builder, "{sv}", "DeviceType",
+ g_variant_new_uint16(comp_compare_ip_and_ifname(device->addr)));
g_variant_builder_add(&builder, "{sv}", "Ifindex",
g_variant_new_int32(device->ifindex));
g_variant_builder_add(&builder, "{sv}", "RouteData",
g_variant_new_uint16(my_device->port));
g_variant_builder_add(&builder, "{sv}", "Address",
g_variant_new_string(my_device->addr));
+ g_variant_builder_add(&builder, "{sv}", "DeviceType",
+ g_variant_new_uint16(comp_compare_ip_and_ifname(my_device->addr)));
g_variant_builder_add(&builder, "{sv}", "Ifindex",
g_variant_new_int32(my_device->ifindex));
g_variant_builder_add(&builder, "{sv}", "RouteData",
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <dirent.h>
+#include <glib.h>
+
+#include <comp_log.h>
+#include <comp_util.h>
+
+#define IPV6_ADDR_GLOBAL 0x0000U
+#define IPV6_ADDR_LOOPBACK 0x0010U
+#define IPV6_ADDR_LINKLOCAL 0x0020U
+#define IPV6_ADDR_SITELOCAL 0x0040U
+#define IPV6_ADDR_COMPATv4 0x0080U
+
+typedef struct _ipv4_info_s {
+ char *ifname; /**< Network interface name */
+ char *mac; /**< MAC address */
+ bool active; /**< interface active or not */
+ int mtu; /**< MTU size */
+ char *ip; /**< IPv4 address */
+ char *broadcast; /**< Broadcast address */
+ char *mask; /**< Net-mask */
+} ipv4_info_s;
+
+typedef struct _ipv6_info_s {
+ char *ifname; /**< Network interface name */
+ char *ip; /**< IPv6 address */
+ int prefix; /**< Prefix length */
+ char *scope; /**< Scope */
+} ipv6_info_s;
+
+typedef struct _ip_info_s {
+ GList *ipv4_list; /**< IPv4 address list */
+ GList *ipv6_list; /**< IPv6 address list */
+} ip_info_s;
+
+ip_info_s g_ip_info; /**< Local IP address list */
+
+static void __free_ipv4_info(gpointer data)
+{
+ ipv4_info_s *ipv4info = (ipv4_info_s *)data;
+ if (NULL == data)
+ return;
+
+ if (ipv4info->ifname) {
+ free(ipv4info->ifname);
+ ipv4info->ifname = NULL;
+ }
+ if (ipv4info->mac) {
+ free(ipv4info->mac);
+ ipv4info->mac = NULL;
+ }
+ if (ipv4info->ip) {
+ free(ipv4info->ip);
+ ipv4info->ip = NULL;
+ }
+ if (ipv4info->broadcast) {
+ free(ipv4info->broadcast);
+ ipv4info->broadcast = NULL;
+ }
+ if (ipv4info->mask) {
+ free(ipv4info->mask);
+ ipv4info->mask = NULL;
+ }
+ free(ipv4info);
+ ipv4info = NULL;
+}
+
+static void __free_ipv6_info(gpointer data)
+{
+ ipv6_info_s *ipv6info = (ipv6_info_s *)data;
+ if (NULL == data)
+ return;
+
+ if (ipv6info->ifname) {
+ free(ipv6info->ifname);
+ ipv6info->ifname = NULL;
+ }
+ if (ipv6info->ip) {
+ free(ipv6info->ip);
+ ipv6info->ip = NULL;
+ }
+ if (ipv6info->scope) {
+ free(ipv6info->scope);
+ ipv6info->scope= NULL;
+ }
+ free(ipv6info);
+ ipv6info = NULL;
+}
+
+void comp_remove_ip_info(void)
+{
+ if (g_ip_info.ipv4_list) {
+ g_list_free_full(g_ip_info.ipv4_list, __free_ipv4_info);
+ g_ip_info.ipv4_list = NULL;
+ }
+ if (g_ip_info.ipv6_list) {
+ g_list_free_full(g_ip_info.ipv6_list, __free_ipv6_info);
+ g_ip_info.ipv6_list = NULL;
+ }
+}
+
+static void _parse_inet6(const char *ifname) {
+ FILE *f;
+ int scope, prefix;
+ unsigned char ipv6[16];
+ char dname[IFNAMSIZ];
+ char address[INET6_ADDRSTRLEN];
+ char *scopestr;
+
+ f = fopen("/proc/net/if_inet6", "r");
+ if (f == NULL) {
+ LOGE("Failed to access /proc/net/if_inet6");
+ return;
+ }
+
+ while (19 == fscanf(f," %2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" \
+ "%2hhx%2hhx%2hhx%2hhx%2hhx %*x %x %x %*x %s",
+ &ipv6[0], &ipv6[1], &ipv6[2], &ipv6[3], &ipv6[4], &ipv6[5], &ipv6[6], &ipv6[7],
+ &ipv6[8], &ipv6[9], &ipv6[10], &ipv6[11], &ipv6[12], &ipv6[13], &ipv6[14],
+ &ipv6[15], &prefix, &scope, dname)) {
+
+ if (strcmp(ifname, dname) != 0)
+ continue;
+
+ if (inet_ntop(AF_INET6, ipv6, address, sizeof(address)) == NULL)
+ continue;
+
+ ipv6_info_s *_ipv6 = calloc(1, sizeof(ipv6_info_s));
+ if (NULL == _ipv6) {
+ LOGE("Memory allocation failed");
+ goto FINISH_READING_IPV6;
+ }
+ _ipv6->ifname = g_strdup(ifname);
+
+ switch (scope) {
+ case IPV6_ADDR_GLOBAL:
+ scopestr = "Global";
+ break;
+ case IPV6_ADDR_LINKLOCAL:
+ scopestr = "Link";
+ break;
+ case IPV6_ADDR_SITELOCAL:
+ scopestr = "Site";
+ break;
+ case IPV6_ADDR_COMPATv4:
+ scopestr = "Compat";
+ break;
+ case IPV6_ADDR_LOOPBACK:
+ scopestr = "Host";
+ break;
+ default:
+ scopestr = "Unknown";
+ }
+ _ipv6->ip = g_strdup(address); /* ex) fe80::212:34ff:fe5a:ec0e */
+ _ipv6->prefix = prefix; /* ex) 64 */
+ _ipv6->scope = g_strdup(scopestr); /* Link */
+
+ g_ip_info.ipv6_list = g_list_append(g_ip_info.ipv6_list, _ipv6);
+ }
+FINISH_READING_IPV6:
+ fclose(f);
+}
+
+static void _parse_ioctl(const char *ifname)
+{
+ int sock;
+ struct ifreq ifr;
+ struct sockaddr_in *ipaddr;
+ char address[INET_ADDRSTRLEN];
+ size_t ifnamelen;
+
+ /* copy ifname to ifr object */
+ ifnamelen = strlen(ifname);
+ if (ifnamelen >= sizeof(ifr.ifr_name)) {
+ return ;
+ }
+ memcpy(ifr.ifr_name, ifname, ifnamelen);
+ ifr.ifr_name[ifnamelen] = '\0';
+
+ /* open socket */
+ sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+ if (sock < 0) {
+ LOGE("socket creation faild");
+ return;
+ }
+
+ ipv4_info_s *_ipv4 = calloc(1, sizeof(ipv4_info_s));
+ if (NULL == _ipv4) {
+ LOGE("Memory allocation failed");
+ goto FINISH_READING_IPV4;
+ }
+ _ipv4->ifname = g_strdup(ifname); /* ex) wlan0 */
+
+ /* process mac */
+ if (ioctl(sock, SIOCGIFHWADDR, &ifr) != -1) {
+ char buf[64] = {0,};
+ snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
+ ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1],
+ ifr.ifr_hwaddr.sa_data[2], ifr.ifr_hwaddr.sa_data[3],
+ ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
+ _ipv4->mac = g_strdup(buf); /* ex) 00:12:34:5a:ec:0e */
+ }
+
+ /* process mtu */
+ if (ioctl(sock, SIOCGIFMTU, &ifr) != -1) {
+ _ipv4->mtu = ifr.ifr_mtu; /* ex) 1492 */
+ }
+
+ /* die if cannot get address */
+ if (ioctl(sock, SIOCGIFADDR, &ifr) == -1) {
+ _ipv4->active = false;
+ goto FINISH_READING_IPV4;
+ }
+
+ /* process ip */
+ ipaddr = (struct sockaddr_in *)&ifr.ifr_addr;
+ if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+ _ipv4->ip = g_strdup(address); /* ex) 192.168.86.111 */
+ }
+
+ /* try to get broadcast */
+ if (ioctl(sock, SIOCGIFBRDADDR, &ifr) != -1) {
+ ipaddr = (struct sockaddr_in *)&ifr.ifr_broadaddr;
+ if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+ _ipv4->broadcast = g_strdup(address); /* ex) 192.168.86.255 */
+ }
+ }
+
+ /* try to get mask */
+ if (ioctl(sock, SIOCGIFNETMASK, &ifr) != -1) {
+ ipaddr = (struct sockaddr_in *)&ifr.ifr_netmask;
+ if (inet_ntop(AF_INET, &ipaddr->sin_addr, address, sizeof(address)) != NULL) {
+ _ipv4->mask = g_strdup(address); /* ex) 255.255.255.0 */
+ }
+ }
+FINISH_READING_IPV4:
+ close(sock);
+ g_ip_info.ipv4_list = g_list_append(g_ip_info.ipv4_list, _ipv4);
+}
+
+
+int comp_make_ip_info(void)
+{
+ DIR *d;
+ struct dirent *de;
+
+ d = opendir("/sys/class/net/");
+ if (d == NULL) {
+ LOGE("Failed to access /sys/class/net/");
+ return -1;
+ }
+
+ while (NULL != (de = readdir(d))) {
+ if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
+ continue;
+
+ _parse_ioctl(de->d_name);
+ _parse_inet6(de->d_name);
+ }
+ closedir(d);
+
+ return 0;
+}
+
+int comp_compare_ip_and_ifname(char *ipdata)
+{
+ char *ip = NULL;
+ char *ifname = NULL;
+ GList *iter = NULL;
+
+ ip = strtok_r(ipdata, "%", &ipdata);
+ ifname = strtok_r(ipdata, "%", &ipdata);
+
+ /* In case IPv4 ip = 192.168.86.90, ifname = (null) */
+ if (NULL == ifname) {
+ ipv4_info_s *ipv4info = NULL;
+ iter = g_list_first(g_ip_info.ipv4_list);
+ while (NULL != iter) {
+ ipv4info = iter->data;
+ if (ipv4info && ipv4info->ip && !strncmp(ipv4info->ip, ip, INET_ADDRSTRLEN)) {
+ return LOCAL_IP;
+ }
+ iter = g_list_next(iter);
+ }
+ } else {
+ /* In case IPv4 ip = fe80::7edd:90ff:feb1:1b57, ifname = wlan0 */
+ ipv6_info_s *ipv6info = NULL;
+ iter = g_list_first(g_ip_info.ipv4_list);
+ while (NULL != iter) {
+ ipv6info = iter->data;
+ if (ipv6info && ipv6info->ip && !strncmp(ipv6info->ip, ip, INET6_ADDRSTRLEN)) {
+ return LOCAL_IP;
+ }
+ iter = g_list_next(iter);
+ }
+ }
+
+ return REMOTE_IP;
+}
+