25
deal_with_hplip_firmware(GUdevDevice *device)
27
const gchar *id_vendor, *id_product, *id_model;
31
id_vendor = g_udev_device_get_sysfs_attr (device, "idVendor");
32
id_product = g_udev_device_get_sysfs_attr (device, "idProduct");
33
id_model = g_udev_device_get_property (device, "ID_MODEL");
34
g_debug_uevent ("uevent.c id_vendor=%s, id_product=%s", id_vendor, id_product);
36
// only idVendor=03f0, idProduct="??{17,2a}" requires firmware
37
if (g_strcmp0 (id_vendor, "03f0") != 0 ||
39
g_utf8_strlen(id_product, -1) != 4)
41
if (! ( ((id_product[2] == '1') && (id_product[3] == '7')) ||
42
((id_product[2] == '2') && (tolower(id_product[3]) == 'a')) ))
45
// firmware is only required if "hp-mkuri -c" returns 2 or 5
46
const gchar *cmd = "/usr/bin/hp-mkuri -c";
47
g_setenv("hp_model", id_model, TRUE);
48
if (!g_spawn_command_line_sync (cmd, NULL, NULL, &ret, &error))
50
g_warning("error calling hp-mkuri");
54
// check return codes, 2 & 5 indicate that it has the firmware already
55
if (WEXITSTATUS(ret) != 2 && WEXITSTATUS(ret) != 5)
57
g_debug_uevent ("hp-mkuri indicates no firmware needed");
61
if (!g_spawn_async("/", hplip_helper, NULL, 0, NULL, NULL, NULL, NULL))
63
g_warning("error calling hplip_helper");
70
24
static gboolean scp_checked = FALSE;
126
79
if (g_strcmp0 (action, "add") != 0 && g_strcmp0 (action, "change") != 0)
129
/* handle firmware */
130
if (deal_with_hplip_firmware(device))
134
82
if (deal_with_scp(device))
142
const gchar* subsytems[] = {"firmware", "usb", NULL};
89
const gchar* subsystems[] = {"firmware", "usb", NULL};
144
/* build firmware search path */
146
92
if (uname (&u) != 0) {
147
g_warning("uname() failed, not monitoring firmware");
93
g_warning("uname() failed, not monitoring devices");
151
GUdevClient* gudev = g_udev_client_new (subsytems);
97
GUdevClient* gudev = g_udev_client_new (subsystems);
152
98
g_signal_connect (gudev, "uevent", G_CALLBACK (on_uevent), NULL);
154
/* cold plug HPLIP firmware */
100
/* cold plug HPLIP devices */
155
101
GList *usb_devices, *elem;
156
102
usb_devices = g_udev_client_query_by_subsystem (gudev, "usb");
157
103
for (elem = usb_devices; elem != NULL; elem = g_list_next(elem)) {
158
deal_with_hplip_firmware(elem->data);
160
104
deal_with_scp(elem->data);
162
105
g_object_unref(elem->data);
164
107
g_list_free(usb_devices);