rendered paste bodystatic HalDevice *
net_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
{
HalDevice *d;
const gchar *ifname;
guint media_type;
gint flags;
d = NULL;
if (parent_dev == NULL)
goto error;
d = hal_device_new ();
hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
hal_device_property_set_string (d, "info.category", "net");
hal_device_add_capability (d, "net");
hal_device_property_set_string (d, "net.originating_device", hal_device_get_udi (parent_dev));
hal_device_property_set_string (d, "net.physical_device", hal_device_get_udi (parent_dev));
ifname = hal_util_get_last_element (sysfs_path);
hal_device_property_set_string (d, "net.interface", ifname);
if (!hal_util_set_string_from_file (d, "net.address", sysfs_path, "address")) {
hal_device_property_set_string (d, "net.address", "00:00:00:00:00:00");
}
if (!hal_util_set_int_from_file (d, "net.linux.ifindex", sysfs_path, "ifindex", 10))
goto error;
if (!hal_util_set_int_from_file (d, "net.arp_proto_hw_id", sysfs_path, "type", 10))
goto error;
if (!hal_util_get_int_from_file (sysfs_path, "flags", &flags, 16))
goto error;
media_type = hal_device_property_get_int (d, "net.arp_proto_hw_id");
if (media_type == ARPHRD_ETHER) {
const char *addr;
const char *parent_subsys;
char wireless_path[HAL_PATH_MAX];
char wiphy_path[HAL_PATH_MAX];
struct stat s;
dbus_uint64_t mac_address = 0;
addr = hal_device_property_get_string (d, "net.address");
if (addr != NULL) {
unsigned int a5, a4, a3, a2, a1, a0;
if (sscanf (addr, "%x:%x:%x:%x:%x:%x",
&a5, &a4, &a3, &a2, &a1, &a0) == 6) {
mac_address =
((dbus_uint64_t)a5<<40) |
((dbus_uint64_t)a4<<32) |
((dbus_uint64_t)a3<<24) |
((dbus_uint64_t)a2<<16) |
((dbus_uint64_t)a1<< 8) |
((dbus_uint64_t)a0<< 0);
}
}
snprintf (wireless_path, HAL_PATH_MAX, "%s/wireless", sysfs_path);
/* wireless dscape stack e.g. from rt2500pci driver*/
snprintf (wiphy_path, HAL_PATH_MAX, "%s/wiphy", sysfs_path);
parent_subsys = hal_device_property_get_string (parent_dev, "linux.subsystem");
if (parent_subsys && strcmp(parent_subsys, "bluetooth") == 0) {
hal_device_property_set_string (d, "info.product", "Bluetooth Interface");
hal_device_property_set_string (d, "info.category", "net.bluetooth");
hal_device_add_capability (d, "net.bluetooth");
hal_device_property_set_uint64 (d, "net.bluetooth.mac_address", mac_address);
/* Leave those properties empty so helper may fill it up */
hal_device_property_set_string (d, "net.bluetooth.name", "");
hal_device_property_set_string (d, "net.bluetooth.uuid", "");
} else if ((stat (wireless_path, &s) == 0 && (s.st_mode & S_IFDIR)) ||
(stat (wiphy_path, &s) == 0 && (s.st_mode & S_IFDIR))) {
hal_device_property_set_string (d, "info.product", "WLAN Interface");
hal_device_property_set_string (d, "info.category", "net.80211");
hal_device_add_capability (d, "net.80211");
hal_device_property_set_uint64 (d, "net.80211.mac_address", mac_address);
} else {
hal_device_property_set_string (d, "info.product", "Networking Interface");
hal_device_property_set_string (d, "info.category", "net.80203");
hal_device_add_capability (d, "net.80203");
hal_device_property_set_uint64 (d, "net.80203.mac_address", mac_address);
}
} else if (media_type == ARPHRD_IRDA) {
hal_device_property_set_string (d, "info.product", "Networking Interface");
hal_device_property_set_string (d, "info.category", "net.irda");
hal_device_add_capability (d, "net.irda");
}
#if defined(ARPHRD_IEEE80211_RADIOTAP) && defined(ARPHRD_IEEE80211_PRISM)
else if (media_type == ARPHRD_IEEE80211 || media_type == ARPHRD_IEEE80211_PRISM ||
media_type == ARPHRD_IEEE80211_RADIOTAP) {
hal_device_property_set_string (d, "info.product", "Networking Wireless Control Interface");
hal_device_property_set_string (d, "info.category", "net.80211control");
hal_device_add_capability (d, "net.80211control");
}
#else
#warning ARPHRD_IEEE80211_RADIOTAP and/or ARPHRD_IEEE80211_PRISM not defined!
#endif
return d;
error:
if (d != NULL) {
hal_device_store_remove (hald_get_tdl (), d);
g_object_unref (d);
d = NULL;
}
return d;
}