diff options
author | Linus Walleij <triad@df.lth.se> | 2010-12-05 14:00:34 +0000 |
---|---|---|
committer | Linus Walleij <triad@df.lth.se> | 2010-12-05 14:00:34 +0000 |
commit | 549f49a7966b55adde29133d8b97ab9a10a9ab25 (patch) | |
tree | e7e25696c888c32e4fdf0bafa0f5fdceef388347 | |
parent | 4f4082b6fac5d3ac61b1cc626759615b9b2813cc (diff) | |
download | libmtp-549f49a7966b55adde29133d8b97ab9a10a9ab25.tar.gz |
Improbe the hotplug capability
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/libmtp.h.in | 1 | ||||
-rw-r--r-- | src/libmtp.sym | 1 | ||||
-rw-r--r-- | src/libusb-glue.c | 28 | ||||
-rw-r--r-- | src/libusb-glue.h | 2 | ||||
-rw-r--r-- | util/mtp-hotplug.c | 8 | ||||
-rw-r--r-- | util/mtp-probe.c | 53 |
7 files changed, 88 insertions, 12 deletions
@@ -1,3 +1,10 @@ +2010-12-05 Linus Walleij <triad@df.lth.se> + + * utils/mtp-probe.c: enhanced to use libmtp intrinsics + and e.g. OS descriptor to probe new devices from + udev. + * utils/mtp-hotplug.c: utilize mtp-probe. + 2010-12-01 Linus Walleij <triad@df.lth.se> * examples/hotplug.c: drop old udev style somewhat. diff --git a/src/libmtp.h.in b/src/libmtp.h.in index 0dcf078..06be565 100644 --- a/src/libmtp.h.in +++ b/src/libmtp.h.in @@ -783,6 +783,7 @@ int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const, int * cons * @{ */ LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t **, int *); +int LIBMTP_Check_Specific_Device(int busno, int devno); LIBMTP_mtpdevice_t *LIBMTP_Open_Raw_Device(LIBMTP_raw_device_t *); /* Begin old, legacy interface */ LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void); diff --git a/src/libmtp.sym b/src/libmtp.sym index 63981d2..98264db 100644 --- a/src/libmtp.sym +++ b/src/libmtp.sym @@ -2,6 +2,7 @@ LIBMTP_Set_Debug LIBMTP_Init LIBMTP_Get_Supported_Devices_List LIBMTP_Detect_Raw_Devices +LIBMTP_Check_Specific_Device LIBMTP_Open_Raw_Device LIBMTP_Get_First_Device LIBMTP_Get_Connected_Devices diff --git a/src/libusb-glue.c b/src/libusb-glue.c index 501fe61..ea22384 100644 --- a/src/libusb-glue.c +++ b/src/libusb-glue.c @@ -498,6 +498,34 @@ static LIBMTP_error_number_t get_mtp_usb_device_list(mtpdevice_list_t ** mtp_dev } /** + * Checks if a specific device with a certain bus and device + * number has an MTP type device descriptor. + * + * @param busno the bus number of the device to check + * @param deviceno the device number of the device to check + * @return 1 if the device is MTP else 0 + */ +int LIBMTP_Check_Specific_Device(int busno, int devno) +{ + struct usb_bus *bus = init_usb(); + for (; bus != NULL; bus = bus->next) { + struct usb_device *dev = bus->devices; + if (bus->location != busno) + continue; + + for (; dev != NULL; dev = dev->next) { + + if (dev->devnum != devno) + continue; + + if (probe_device_descriptor(dev, NULL)) + return 1; + } + } + return 0; +} + +/** * Detect the raw MTP device descriptors and return a list of * of the devices found. * diff --git a/src/libusb-glue.h b/src/libusb-glue.h index db41d83..fc9ca13 100644 --- a/src/libusb-glue.h +++ b/src/libusb-glue.h @@ -87,7 +87,7 @@ int open_device (int busn, int devn, short force, PTP_USB *ptp_usb, PTPParams *p void dump_usbinfo(PTP_USB *ptp_usb); const char *get_playlist_extension(PTP_USB *ptp_usb); void close_device(PTP_USB *ptp_usb, PTPParams *params); -LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, +LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, PTPParams *params, void **usbinfo); void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout); diff --git a/util/mtp-hotplug.c b/util/mtp-hotplug.c index 1266ebf..c403a05 100644 --- a/util/mtp-hotplug.c +++ b/util/mtp-hotplug.c @@ -193,6 +193,14 @@ int main (int argc, char **argv) break; case style_udev: case style_udev_old: + /* + * This is code that invokes the mtp-probe program on + * every USB device that is either PTP or vendor specific + */ + printf("\n# Autoprobe PTP devices\n"); + printf("ENV{ID_MTP_DEVICE}!=\"1\", ATTR{bDeviceClass}==\"06\", PROGRAM=\"/lib/udev/mtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum}\", RESULT==\"1\", %s\n", action); + printf("\n# Autoprobe vendor-specific devices\n"); + printf("ENV{ID_MTP_DEVICE}!=\"1\", ATTR{bDeviceClass}==\"ff\", PROGRAM=\"/lib/udev/mtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum}\", RESULT==\"1\", %s\n\n", action); printf("LABEL=\"libmtp_rules_end\"\n"); break; case style_hal: diff --git a/util/mtp-probe.c b/util/mtp-probe.c index 7de15f8..a05820e 100644 --- a/util/mtp-probe.c +++ b/util/mtp-probe.c @@ -4,12 +4,20 @@ * userspace to determine if they are MTP devices, used for * udev rules. * - * Invoke the program on a sysfs device entry to check it - * for MTP signatures, e.g. - * mtp-probe /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-8 + * Invoke the program from udev to check it for MTP signatures, + * e.g. + * ATTR{bDeviceClass}=="ff", + * PROGRAM="<path>/mtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum}", + * RESULT=="1", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1", + * SYMLINK+="libmtp-%k", MODE="666" * - * Exits with status code 0 if the device is an MTP device, - * else exits with 1. + * Is you issue this before testing your /var/log/messages + * will be more verbose: + * + * udevadm control --log-priority=debug + * + * Exits with status code 1 if the device is an MTP device, + * else exits with 0. * * Copyright (C) 2010 Linus Walleij <triad@df.lth.se> * @@ -28,21 +36,44 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include <libmtp.h> +#ifndef __linux__ +#error "This program should only be compiled for Linux!" +#endif + #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <syslog.h> +#include <libmtp.h> int main (int argc, char **argv) { char *fname; + int busno; + int devno; + int ret; - if (argc < 2) { - printf("No device file to check\n"); - exit(1); + if (argc < 4) { + syslog(LOG_INFO, "need device path, busnumber, device number as argument\n"); + printf("0"); + exit(0); } + fname = argv[1]; - printf("Checking: \"%s\"...\n", fname); - exit (1); + busno = atoi(argv[2]); + devno = atoi(argv[3]); + + syslog(LOG_INFO, "checking bus %d, device %d: \"%s\"\n", busno, devno, fname); + + ret = LIBMTP_Check_Specific_Device(busno, devno); + if (ret) { + syslog(LOG_INFO, "bus: %d, device: %d was an MTP device\n", busno, devno); + printf("1"); + } else { + syslog(LOG_INFO, "bus: %d, device: %d was not an MTP device\n", busno, devno); + printf("0"); + } + + exit(0); } |