/* generate hotplug event for each device in this branch */ void devinfo_remove_branch (gchar *devfs_path, HalDevice *d) { GSList *i; GSList *children; HalDevice *child; char *child_devfs_path; if (d == NULL) { d = hal_device_store_match_key_value_string (hald_get_gdl (), "solaris.devfs_path", devfs_path); if (d == NULL) return; } HAL_INFO (("remove_branch: %s %s\n", devfs_path, hal_device_get_udi (d))); /* first remove children */ children = hal_device_store_match_multiple_key_value_string (hald_get_gdl(), "info.parent", hal_device_get_udi (d)); for (i = children; i != NULL; i = g_slist_next (i)) { child = HAL_DEVICE (i->data); HAL_INFO (("remove_branch: child %s\n", hal_device_get_udi (child))); devinfo_remove_branch ((gchar *)hal_device_property_get_string (child, "solaris.devfs_path"), child); } g_slist_free (children); HAL_INFO (("remove_branch: done with children")); /* then remove self */ HAL_INFO (("remove_branch: queueing %s", devfs_path)); devinfo_remove_enqueue (devfs_path, NULL); }
void hal_device_store_add (HalDeviceStore *store, HalDevice *device) { const char buf[] = "/org/freedesktop/Hal/devices/"; if (strncmp(hal_device_get_udi (device), buf, sizeof (buf) - 1) != 0) { HAL_ERROR(("Can't add HalDevice with incorrect UDI. Valid " "UDI must start with '/org/freedesktop/Hal/devices/'")); goto out; } store->devices = g_slist_prepend (store->devices, g_object_ref (device)); g_signal_connect (device, "property_changed", G_CALLBACK (emit_device_property_changed), store); g_signal_connect (device, "pre_property_changed", G_CALLBACK (device_pre_property_changed), store); g_signal_connect (device, "capability_added", G_CALLBACK (emit_device_capability_added), store); g_signal_connect (device, "lock_acquired", G_CALLBACK (emit_device_lock_acquired), store); g_signal_connect (device, "lock_released", G_CALLBACK (emit_device_lock_released), store); property_index_check_all (store, device, TRUE); g_signal_emit (store, signals[STORE_CHANGED], 0, device, TRUE); out: ; }
void hald_runner_kill_device(HalDevice *device) { DBusMessage *msg, *reply; DBusError err; DBusMessageIter iter; const char *udi; running_processes_remove_device (device); msg = dbus_message_new_method_call("org.freedesktop.HalRunner", "/org/freedesktop/HalRunner", "org.freedesktop.HalRunner", "Kill"); if (msg == NULL) DIE(("No memory")); dbus_message_iter_init_append(msg, &iter); udi = hal_device_get_udi(device); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &udi); /* Wait for the reply, should be almost instantanious */ dbus_error_init(&err); reply = dbus_connection_send_with_reply_and_block(runner_connection, msg, -1, &err); if (reply) { dbus_message_unref(reply); } dbus_message_unref(msg); }
/* This is the beginning of hotplug even handling */ void hotplug_event_begin_add_devinfo (HalDevice *d, HalDevice *parent, DevinfoDevHandler *handler, void *end_token) { HotplugEvent *hotplug_event = (HotplugEvent *)end_token; HAL_INFO(("Preprobing udi=%s", hal_device_get_udi (d))); if (parent == NULL && (strcmp(hotplug_event->un.devfs.devfs_path, "/") != 0)) { HAL_ERROR (("Parent is NULL, devfs_path=%s", hotplug_event->un.devfs.devfs_path)); goto skip; } if (parent != NULL && hal_device_property_get_bool (parent, "info.ignore")) { HAL_INFO (("Ignoring device since parent has info.ignore==TRUE")); goto skip; } if (hal_device_store_find (hald_get_tdl (), hal_device_get_udi (d)) == NULL) { /* add to TDL so preprobing callouts and prober can access it */ hal_device_store_add (hald_get_tdl (), d); } /* Process preprobe fdi files */ di_search_and_merge (d, DEVICE_INFO_TYPE_PREPROBE); /* Run preprobe callouts */ hal_util_callout_device_preprobe (d, devinfo_callouts_preprobing_done, end_token, handler); return; skip: if (hal_device_store_find (hald_get_tdl (), hal_device_get_udi (d))) hal_device_store_remove (hald_get_tdl (), d); g_object_unref (d); hotplug_event_end (end_token); return; }
static void hotplug_event_begin_devfs_remove (HotplugEvent *hotplug_event, HalDevice *d) { if (d == NULL) { HAL_ERROR (("devpath %s not present in store, ignore event", hotplug_event->un.devfs.devfs_path)); hotplug_event_end ((void *) hotplug_event); return; } HAL_INFO (("hotplug_event_begin_devfs_remove %s", hal_device_get_udi (d))); hotplug_event_begin_remove_devinfo(d, hotplug_event->un.devfs.devfs_path, (void *) hotplug_event); }
HalDevice * hal_device_store_find (HalDeviceStore *store, const char *udi) { GSList *iter; for (iter = store->devices; iter != NULL; iter = iter->next) { HalDevice *d = iter->data; if (strcmp (hal_device_get_udi (d), udi) == 0) return d; } return NULL; }
void devinfo_callouts_remove_done (HalDevice *d, gpointer userdata1, gpointer userdata2) { void *end_token = (void *) userdata1; HAL_INFO (("Remove callouts completed udi=%s", hal_device_get_udi (d))); if (!hal_device_store_remove (hald_get_gdl (), d)) { HAL_WARNING (("Error removing device")); } g_object_unref (d); hotplug_event_end (end_token); }
void devinfo_callouts_preprobing_done (HalDevice *d, gpointer userdata1, gpointer userdata2) { void *end_token = (void *) userdata1; DevinfoDevHandler *handler = (DevinfoDevHandler *) userdata2; void (*probing_done) (HalDevice *, guint32, gint, char **, gpointer, gpointer); const gchar *prober; int prober_timeout; if (hal_device_property_get_bool (d, "info.ignore")) { HAL_INFO (("Preprobing merged info.ignore==TRUE")); /* Leave device with info.ignore==TRUE so we won't pick up children */ hal_device_property_remove (d, "info.category"); hal_device_property_remove (d, "info.capabilities"); hal_device_store_remove (hald_get_tdl (), d); hal_device_store_add (hald_get_gdl (), d); hotplug_event_end (end_token); return; } if (handler != NULL && handler->get_prober != NULL) { prober = handler->get_prober (d, &prober_timeout); } else { prober = NULL; } if (handler->probing_done != NULL) { probing_done = handler->probing_done; } else { probing_done = devinfo_callouts_probing_done; } if (prober != NULL) { /* probe the device */ HAL_INFO(("Probing udi=%s", hal_device_get_udi (d))); hald_runner_run (d, prober, NULL, prober_timeout, probing_done, (gpointer) end_token, (gpointer) handler); } else { probing_done (d, 0, 0, NULL, userdata1, userdata2); } }
void devinfo_set_default_properties (HalDevice *d, HalDevice *parent, di_node_t node, char *devfs_path) { char *driver_name, *s; const char *s1; char udi[HAL_PATH_MAX]; if (parent != NULL) { hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent)); } else { hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/local"); } hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "/org/freedesktop/Hal/devices%s_%d", devfs_path, di_instance (node)); hal_device_set_udi (d, udi); hal_device_property_set_string (d, "info.udi", udi); if (di_prop_lookup_strings (DDI_DEV_T_ANY, node, "model", &s) > 0) { hal_device_property_set_string (d, "info.product", s); } else { hal_device_property_set_string (d, "info.product", di_node_name (node)); } hal_device_property_set_string (d, "solaris.devfs_path", devfs_path); if ((driver_name = di_driver_name (node)) != NULL) { hal_device_property_set_string (d, "info.solaris.driver", driver_name); } /* inherit parent's claim attributes */ if (hal_device_property_get_bool (parent, "info.claimed")) { s1 = hal_device_property_get_string (parent, "info.claimed.service"); if (s1 != NULL) { hal_device_property_set_bool (d, "info.claimed", TRUE); hal_device_property_set_string (d, "info.claimed.service", s1); } } }
void devinfo_callouts_probing_done (HalDevice *d, guint32 exit_type, gint return_code, char **error, gpointer userdata1, gpointer userdata2) { void *end_token = (void *) userdata1; /* Discard device if probing reports failure */ if (exit_type != HALD_RUN_SUCCESS || (return_code != 0)) { HAL_INFO (("Probing for %s failed %d", hal_device_get_udi (d), return_code)); hal_device_store_remove (hald_get_tdl (), d); g_object_unref (d); hotplug_event_end (end_token); return; } /* Merge properties from .fdi files */ di_search_and_merge (d, DEVICE_INFO_TYPE_INFORMATION); di_search_and_merge (d, DEVICE_INFO_TYPE_POLICY); hal_util_callout_device_add (d, devinfo_callouts_add_done, end_token, NULL); }
static gboolean add_first_part(DBusMessageIter *iter, HalDevice *device, const gchar *command_line, char **extra_env) { DBusMessageIter array_iter; const char *udi; udi = hal_device_get_udi(device); dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &udi); dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter); hal_device_property_foreach (device, add_property_to_msg, &array_iter); add_basic_env(&array_iter, udi); add_extra_env(&array_iter, extra_env); dbus_message_iter_close_container(iter, &array_iter); if (!add_command(iter, command_line)) { return FALSE; } return TRUE; }
static void drvctl_lofi_add(gchar *devfs_path, gchar *name) { di_node_t node; const char *parent_udi; HalDevice *d, *parent; HAL_INFO (("lofi_add: %s %s", name, devfs_path)); if ((d = hal_device_store_match_key_value_string (hald_get_gdl (), "solaris.devfs_path", devfs_path)) == NULL) { HAL_INFO (("device not found in GDL %s", devfs_path)); return; } parent_udi = hal_device_property_get_string (d, "info.parent"); if ((parent_udi == NULL) || (strlen(parent_udi) == 0)) { HAL_INFO (("parent not found in GDL %s", parent_udi)); return; } if ((parent = hal_device_store_match_key_value_string (hald_get_gdl (), "info.udi", parent_udi)) == NULL) { HAL_INFO (("parent not found in GDL %s", parent_udi)); return; } if ((node = di_init (devfs_path, DINFOCPYALL)) == DI_NODE_NIL) { HAL_INFO (("device not found in devinfo %s", devfs_path)); return; } HAL_INFO (("device %s parent %s", hal_device_get_udi (d), parent_udi)); devinfo_lofi_add_major (parent, node, devfs_path, NULL, TRUE, d); di_fini (node); hotplug_event_process_queue (); }
HalDevice * devinfo_add_node(HalDevice *parent, di_node_t node) { HalDevice *d = NULL; char *devfs_path; char *device_type = NULL; DevinfoDevHandler *handler; int i; devfs_path = di_devfs_path (node); (void) di_prop_lookup_strings (DDI_DEV_T_ANY, node, "device_type", &device_type); for (i = 0; (d == NULL) && (devinfo_handlers[i] != NULL); i++) { handler = devinfo_handlers[i]; d = handler->add (parent, node, devfs_path, device_type); } di_devfs_path_free(devfs_path); HAL_INFO (("add_node: %s", d ? hal_device_get_udi (d) : "none")); return (d); }
static HalDevice * hf_net_device_new (const char *interface, HalDevice *parent, GError **err) { char *output; char **lines; int i; int ifindex; GError *tmp_err = NULL; const char *mac = NULL; const char *media = NULL; gboolean is_ethernet = FALSE; gboolean is_wireless = FALSE; gboolean is_tokenring = FALSE; HalDevice *device = NULL; g_return_val_if_fail(interface != NULL, NULL); g_return_val_if_fail(HAL_IS_DEVICE(parent), NULL); output = hf_run(&tmp_err, "/sbin/ifconfig %s", interface); if (! output) { g_set_error(err, 0, 0, "ifconfig failure: %s", tmp_err->message); g_error_free(tmp_err); return NULL; } lines = g_strsplit(output, "\n", 0); g_free(output); for (i = 0; lines[i]; i++) { if (g_str_has_prefix(lines[i], "\tether ")) mac = lines[i] + 7; if (g_str_has_prefix(lines[i], "\tmedia: ")) media = lines[i] + 8; if (g_str_has_prefix(lines[i], "\tmedia: Ethernet")) is_ethernet = TRUE; else if (g_str_has_prefix(lines[i], "\tmedia: IEEE 802.11 Wireless Ethernet")) { is_ethernet = TRUE; is_wireless = TRUE; } else if (g_str_has_prefix(lines[i], "\tmedia: Token ring")) is_tokenring = TRUE; } device = hf_device_new(parent); hf_device_set_udi(device, "net_%s", mac ? mac : hal_util_get_last_element(hal_device_get_udi(parent))); hal_device_property_set_string(device, "info.product", "Networking Interface"); hal_device_add_capability(device, "net"); hal_device_property_set_string(device, "net.address", mac ? mac : "00:00:00:00:00:00"); hal_device_property_set_string(device, "net.interface", interface); hal_device_property_set_string(device, "net.originating_device", hal_device_get_udi(parent)); hal_device_property_set_string(device, "net.media", media); if (hf_devtree_is_driver(interface, "fwe")) hal_device_property_set_int(device, "net.arp_proto_hw_id", ARPHRD_IEEE1394); else if (is_ethernet) hal_device_property_set_int(device, "net.arp_proto_hw_id", ARPHRD_ETHER); else if (is_tokenring) hal_device_property_set_int(device, "net.arp_proto_hw_id", ARPHRD_IEEE802); /* FIXME Add additional net.arp_proto_hw_id support */ ifindex = if_nametoindex(interface); hal_device_property_set_int(device, "net.freebsd.ifindex", ifindex); if (is_ethernet) { dbus_uint64_t numeric_mac = 0; unsigned int a5, a4, a3, a2, a1, a0; if (mac && sscanf(mac, "%x:%x:%x:%x:%x:%x", &a5, &a4, &a3, &a2, &a1, &a0) == 6) numeric_mac = ((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); if (is_wireless) { hal_device_property_set_string(device, "info.product", "WLAN Networking Interface"); hal_device_add_capability(device, "net.80211"); hal_device_property_set_string(device, "info.category", "net.80211"); hal_device_property_set_uint64(device, "net.80211.mac_address", numeric_mac); } else { hal_device_add_capability(device, "net.80203"); hal_device_property_set_string(device, "info.category", "net.80203"); hal_device_property_set_uint64(device, "net.80203.mac_address", numeric_mac); hal_device_property_set_uint64(device, "net.80203.rate", hf_net_get_rate(ifindex)); } } else hal_device_property_set_string(device, "info.category", "net"); g_strfreev(lines); hf_net_device_set_link_up(device, hf_net_get_link_up(interface)); return device; }