From: Marcel Holtmann Date: Fri, 4 Jan 2008 01:37:34 +0000 (+0100) Subject: Add interface properties for device details X-Git-Tag: 0.1~448 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0979df838ec942c23d8a5bad23a1e7f87d666ec;p=platform%2Fupstream%2Fconnman.git Add interface properties for device details --- diff --git a/include/iface.h b/include/iface.h index cc79a4d..a916cd1 100644 --- a/include/iface.h +++ b/include/iface.h @@ -75,6 +75,12 @@ struct connman_iface { struct connman_iface_driver *driver; void *driver_data; + + struct { + char *driver; + char *vendor; + char *product; + } device; }; struct connman_iface_driver { @@ -92,6 +98,8 @@ struct connman_iface_driver { int (*connect) (struct connman_iface *iface, struct connman_network *network); + const char * (*get_address) (struct connman_iface *iface); + void (*set_network) (struct connman_iface *iface, const char *network); void (*set_passphrase) (struct connman_iface *iface, diff --git a/plugins/80211.c b/plugins/80211.c index 5a74de5..5aebe96 100644 --- a/plugins/80211.c +++ b/plugins/80211.c @@ -58,6 +58,7 @@ struct station_data { struct iface_data { char ifname[IFNAMSIZ]; + char ifaddr[18]; GSList *stations; gchar *network; @@ -163,6 +164,7 @@ static int iface_probe(struct connman_iface *iface) { struct iface_data *data; struct ifreq ifr; + struct ether_addr *eth; int sk, err; sk = socket(PF_INET, SOCK_DGRAM, 0); @@ -174,6 +176,9 @@ static int iface_probe(struct connman_iface *iface) err = ioctl(sk, SIOCGIFNAME, &ifr); + if (err == 0) + err = ioctl(sk, SIOCGIFHWADDR, &ifr); + close(sk); if (err < 0) @@ -189,6 +194,15 @@ static int iface_probe(struct connman_iface *iface) memcpy(data->ifname, ifr.ifr_name, IFNAMSIZ); + eth = (void *) &ifr.ifr_hwaddr.sa_data; + sprintf(data->ifaddr, "%02X:%02X:%02X:%02X:%02X:%02X", + eth->ether_addr_octet[0], + eth->ether_addr_octet[1], + eth->ether_addr_octet[2], + eth->ether_addr_octet[3], + eth->ether_addr_octet[4], + eth->ether_addr_octet[5]); + iface->type = CONNMAN_IFACE_TYPE_80211; iface->flags = CONNMAN_IFACE_FLAG_RTNL | @@ -276,6 +290,15 @@ static int iface_connect(struct connman_iface *iface, return 0; } +static const char *iface_get_address(struct connman_iface *iface) +{ + struct iface_data *data = connman_iface_get_data(iface); + + printf("[802.11] get address %s\n", data->ifname); + + return data->ifaddr; +} + static void iface_set_network(struct connman_iface *iface, const char *network) { @@ -512,6 +535,7 @@ static struct connman_iface_driver iface_driver = { .activate = iface_activate, .scan = iface_scan, .connect = iface_connect, + .get_address = iface_get_address, .set_network = iface_set_network, .set_passphrase = iface_set_passphrase, .rtnl_carrier = iface_carrier, diff --git a/src/iface.c b/src/iface.c index 82fbdda..b08fdb8 100644 --- a/src/iface.c +++ b/src/iface.c @@ -417,8 +417,80 @@ static dbus_bool_t get_type(DBusConnection *conn, return TRUE; } +static dbus_bool_t get_address(DBusConnection *conn, + DBusMessageIter *iter, void *data) +{ + struct connman_iface *iface = data; + const char *address; + + DBG("iface %p", iface); + + if (!iface->driver->get_address) + return FALSE; + + address = iface->driver->get_address(iface); + if (address == NULL) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &address); + + return TRUE; +} + +static dbus_bool_t get_driver(DBusConnection *conn, + DBusMessageIter *iter, void *data) +{ + struct connman_iface *iface = data; + + DBG("iface %p", iface); + + if (iface->device.driver == NULL) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, + &iface->device.driver); + + return TRUE; +} + +static dbus_bool_t get_vendor(DBusConnection *conn, + DBusMessageIter *iter, void *data) +{ + struct connman_iface *iface = data; + + DBG("iface %p", iface); + + if (iface->device.vendor == NULL) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, + &iface->device.vendor); + + return TRUE; +} + +static dbus_bool_t get_product(DBusConnection *conn, + DBusMessageIter *iter, void *data) +{ + struct connman_iface *iface = data; + + DBG("iface %p", iface); + + if (iface->device.product == NULL) + return FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, + &iface->device.product); + + return TRUE; +} + static GDBusPropertyTable iface_properties[] = { - { "Type", "s", get_type }, + { "Type", "s", get_type }, + { "Address", "s", get_address }, + { "Driver", "s", get_driver }, + { "Vendor", "s", get_vendor }, + { "Product", "s", get_product }, { }, }; @@ -436,9 +508,44 @@ static void device_free(void *data) g_free(iface->path); g_free(iface->udi); g_free(iface->sysfs); + g_free(iface->device.driver); + g_free(iface->device.vendor); + g_free(iface->device.product); g_free(iface); } +static void detect_device_info(LibHalContext *ctx, struct connman_iface *iface) +{ + char *parent, *subsys, *value; + + parent = libhal_device_get_property_string(ctx, iface->udi, + "info.parent", NULL); + + subsys = libhal_device_get_property_string(ctx, iface->udi, + "linux.subsystem", NULL); + + value = libhal_device_get_property_string(ctx, iface->udi, + "info.linux.driver", NULL); + if (value == NULL) { + value = libhal_device_get_property_string(ctx, parent, + "info.linux.driver", NULL); + if (value != NULL) + iface->device.driver = g_strdup(value); + } + + if (strcmp(subsys, "net") == 0) { + value = libhal_device_get_property_string(ctx, parent, + "info.vendor", NULL); + if (value != NULL) + iface->device.vendor = g_strdup(value); + + value = libhal_device_get_property_string(ctx, parent, + "info.product", NULL); + if (value != NULL) + iface->device.product = g_strdup(value); + } +} + static int probe_device(LibHalContext *ctx, struct connman_iface_driver *driver, const char *udi) { @@ -469,6 +576,8 @@ static int probe_device(LibHalContext *ctx, if (sysfs != NULL) iface->sysfs = g_strdup(sysfs); + detect_device_info(ctx, iface); + iface->index = -1; if (g_str_has_prefix(driver->capability, "net") == TRUE)