Linus Walleij | 6d3c222 | 2010-11-30 23:42:32 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file mtp-hotplug.c |
Linus Walleij | 4f4082b | 2010-12-01 23:00:00 +0000 | [diff] [blame] | 3 | * Program to create hotplug scripts. |
Linus Walleij | 543badf | 2007-02-05 19:07:38 +0000 | [diff] [blame] | 4 | * |
Linus Walleij | 1ff1a64 | 2012-01-28 10:54:37 +0100 | [diff] [blame] | 5 | * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> |
Linus Walleij | 161fcce | 2008-03-12 22:02:59 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2008 Marcus Meissner <marcus@jet.franken.de> |
Linus Walleij | 543badf | 2007-02-05 19:07:38 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the |
| 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | * Boston, MA 02111-1307, USA. |
| 22 | */ |
Linus Walleij | 6d3c222 | 2010-11-30 23:42:32 +0000 | [diff] [blame] | 23 | #include <libmtp.h> |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | |
| 29 | static void usage(void) |
| 30 | { |
Denis Dupeyron | 83e79a2 | 2011-02-07 22:40:45 -0700 | [diff] [blame] | 31 | fprintf(stderr, "usage: hotplug [-u -H -i -a\"ACTION\"] -p\"DIR\" -g\"GROUP\" -m\"MODE\"\n"); |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 32 | fprintf(stderr, " -w: use hwdb syntax\n"); |
Linus Walleij | 2d069e2 | 2006-08-23 19:05:18 +0000 | [diff] [blame] | 33 | fprintf(stderr, " -u: use udev syntax\n"); |
Linus Walleij | e527254 | 2010-11-30 23:26:11 +0000 | [diff] [blame] | 34 | fprintf(stderr, " -o: use old udev syntax\n"); |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 35 | fprintf(stderr, " -H: use hal syntax\n"); |
Linus Walleij | 99466e3 | 2007-05-11 21:42:53 +0000 | [diff] [blame] | 36 | fprintf(stderr, " -i: use usb.ids simple list syntax\n"); |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 37 | fprintf(stderr, " -a\"ACTION\": perform udev action ACTION on attachment\n"); |
Denis Dupeyron | b9eed54 | 2011-01-26 22:31:16 -0700 | [diff] [blame] | 38 | fprintf(stderr, " -p\"DIR\": directory where mtp-probe will be installed\n"); |
Denis Dupeyron | 83e79a2 | 2011-02-07 22:40:45 -0700 | [diff] [blame] | 39 | fprintf(stderr, " -g\"GROUP\": file group for device nodes\n"); |
| 40 | fprintf(stderr, " -m\"MODE\": file mode for device nodes\n"); |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 41 | exit(1); |
| 42 | } |
| 43 | |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 44 | enum style { |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 45 | style_usbmap, |
| 46 | style_udev, |
Linus Walleij | e527254 | 2010-11-30 23:26:11 +0000 | [diff] [blame] | 47 | style_udev_old, |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 48 | style_hal, |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 49 | style_usbids, |
| 50 | style_hwdb |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 53 | int main (int argc, char **argv) |
| 54 | { |
| 55 | LIBMTP_device_entry_t *entries; |
| 56 | int numentries; |
| 57 | int i; |
| 58 | int ret; |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 59 | enum style style = style_usbmap; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 60 | int opt; |
| 61 | extern int optind; |
| 62 | extern char *optarg; |
| 63 | char *udev_action = NULL; |
Linus Walleij | c4cd50b | 2011-01-08 22:50:07 +0000 | [diff] [blame] | 64 | /* |
| 65 | * You could tag on MODE="0666" here to enfore writeable |
| 66 | * device nodes, use the command line argument for that. |
| 67 | * Current udev default rules will make any device tagged |
| 68 | * with ENV{ID_MEDIA_PLAYER}=1 writable for the console |
| 69 | * user. |
| 70 | */ |
| 71 | char default_udev_action[] = "SYMLINK+=\"libmtp-%k\", ENV{ID_MTP_DEVICE}=\"1\", ENV{ID_MEDIA_PLAYER}=\"1\""; |
Linus Walleij | 71b8c0f | 2007-09-06 09:09:14 +0000 | [diff] [blame] | 72 | char *action; // To hold the action actually used. |
Linus Walleij | cbfe177 | 2010-11-28 21:20:51 +0000 | [diff] [blame] | 73 | uint16_t last_vendor = 0x0000U; |
Linus Walleij | 59d69ab | 2011-02-09 21:44:37 +0100 | [diff] [blame] | 74 | char mtp_probe_dir[256]; |
Denis Dupeyron | 83e79a2 | 2011-02-07 22:40:45 -0700 | [diff] [blame] | 75 | char *udev_group= NULL; |
| 76 | char *udev_mode = NULL; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 77 | |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 78 | while ( (opt = getopt(argc, argv, "wuoiHa:p:g:m:")) != -1 ) { |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 79 | switch (opt) { |
| 80 | case 'a': |
| 81 | udev_action = strdup(optarg); |
Denis Dupeyron | b9eed54 | 2011-01-26 22:31:16 -0700 | [diff] [blame] | 82 | break; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 83 | case 'u': |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 84 | style = style_udev; |
| 85 | break; |
Linus Walleij | e527254 | 2010-11-30 23:26:11 +0000 | [diff] [blame] | 86 | case 'o': |
| 87 | style = style_udev_old; |
| 88 | break; |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 89 | case 'H': |
| 90 | style = style_hal; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 91 | break; |
Linus Walleij | 99466e3 | 2007-05-11 21:42:53 +0000 | [diff] [blame] | 92 | case 'i': |
| 93 | style = style_usbids; |
| 94 | break; |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 95 | case 'w': |
| 96 | style = style_hwdb; |
| 97 | break; |
Denis Dupeyron | b9eed54 | 2011-01-26 22:31:16 -0700 | [diff] [blame] | 98 | case 'p': |
Linus Walleij | 59d69ab | 2011-02-09 21:44:37 +0100 | [diff] [blame] | 99 | strncpy(mtp_probe_dir,optarg,sizeof(mtp_probe_dir)); |
| 100 | mtp_probe_dir[sizeof(mtp_probe_dir)-1] = '\0'; |
| 101 | if (strlen(mtp_probe_dir) <= 1) { |
| 102 | printf("Supply some sane mtp-probe dir\n"); |
| 103 | exit(1); |
| 104 | } |
| 105 | /* Make sure the dir ends with '/' */ |
| 106 | if (mtp_probe_dir[strlen(mtp_probe_dir)-1] != '/') { |
| 107 | int index = strlen(mtp_probe_dir); |
| 108 | if (index >= (sizeof(mtp_probe_dir)-1)) { |
| 109 | exit(1); |
| 110 | } |
| 111 | mtp_probe_dir[index] = '/'; |
| 112 | mtp_probe_dir[index+1] = '\0'; |
| 113 | } |
Linus Walleij | df3ef0f | 2011-02-09 22:05:52 +0100 | [diff] [blame] | 114 | /* Don't add the standard udev path... */ |
| 115 | if (!strcmp(mtp_probe_dir, "/lib/udev/")) { |
| 116 | mtp_probe_dir[0] = '\0'; |
| 117 | } |
Denis Dupeyron | b9eed54 | 2011-01-26 22:31:16 -0700 | [diff] [blame] | 118 | break; |
Denis Dupeyron | 83e79a2 | 2011-02-07 22:40:45 -0700 | [diff] [blame] | 119 | case 'g': |
| 120 | udev_group = strdup(optarg); |
| 121 | break; |
| 122 | case 'm': |
| 123 | udev_mode = strdup(optarg); |
| 124 | break; |
| 125 | default: |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 126 | usage(); |
| 127 | } |
| 128 | } |
| 129 | |
Linus Walleij | 71b8c0f | 2007-09-06 09:09:14 +0000 | [diff] [blame] | 130 | if (udev_action != NULL) { |
| 131 | action = udev_action; |
| 132 | } else { |
| 133 | action = default_udev_action; |
| 134 | } |
| 135 | |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 136 | LIBMTP_Init(); |
| 137 | ret = LIBMTP_Get_Supported_Devices_List(&entries, &numentries); |
| 138 | if (ret == 0) { |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 139 | switch (style) { |
| 140 | case style_udev: |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 141 | printf("# UDEV-style hotplug map for libmtp\n"); |
| 142 | printf("# Put this file in /etc/udev/rules.d\n\n"); |
Linus Walleij | 50d47a5 | 2007-09-05 07:59:40 +0000 | [diff] [blame] | 143 | printf("ACTION!=\"add\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | 1d82965 | 2009-06-02 19:53:01 +0000 | [diff] [blame] | 144 | printf("ENV{MAJOR}!=\"?*\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | 71b8c0f | 2007-09-06 09:09:14 +0000 | [diff] [blame] | 145 | printf("SUBSYSTEM==\"usb\", GOTO=\"libmtp_usb_rules\"\n" |
Linus Walleij | 8632a4d | 2007-07-30 14:51:41 +0000 | [diff] [blame] | 146 | "GOTO=\"libmtp_rules_end\"\n\n" |
Linus Walleij | 71b8c0f | 2007-09-06 09:09:14 +0000 | [diff] [blame] | 147 | "LABEL=\"libmtp_usb_rules\"\n\n"); |
Linus Walleij | 1ff1a64 | 2012-01-28 10:54:37 +0100 | [diff] [blame] | 148 | printf("# Some sensitive devices we surely don\'t wanna probe\n"); |
| 149 | printf("# Color instruments\n"); |
Linus Walleij | c65bc90 | 2011-10-22 21:16:22 +0200 | [diff] [blame] | 150 | printf("ATTR{idVendor}==\"0670\", GOTO=\"libmtp_rules_end\"\n"); |
| 151 | printf("ATTR{idVendor}==\"0765\", GOTO=\"libmtp_rules_end\"\n"); |
| 152 | printf("ATTR{idVendor}==\"085c\", GOTO=\"libmtp_rules_end\"\n"); |
| 153 | printf("ATTR{idVendor}==\"0971\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | 1ff1a64 | 2012-01-28 10:54:37 +0100 | [diff] [blame] | 154 | printf("# Canon scanners that look like MTP devices (PID 0x22nn)\n"); |
| 155 | printf("ATTR{idVendor}==\"04a9\", ATTR{idProduct}==\"22*\", GOTO=\"libmtp_rules_end\"\n"); |
Alessio Treglia | 35e6d20 | 2012-09-11 22:00:22 +0200 | [diff] [blame] | 156 | printf("# Canon digital camera (EOS 3D) that looks like MTP device (PID 0x3113)\n"); |
| 157 | printf("ATTR{idVendor}==\"04a9\", ATTR{idProduct}==\"3113\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | f7ff08a | 2012-03-22 23:10:33 +0100 | [diff] [blame] | 158 | printf("# Sensitive Atheros devices that look like MTP devices\n"); |
| 159 | printf("ATTR{idVendor}==\"0cf3\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | 25e40ec | 2012-06-27 22:21:22 +0200 | [diff] [blame] | 160 | printf("# Sensitive Atmel JTAG programmers\n"); |
| 161 | printf("ATTR{idVendor}==\"03eb\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | 0132421 | 2012-10-20 21:40:03 +0200 | [diff] [blame] | 162 | printf("# Sensitive Philips device\n"); |
| 163 | printf("ATTR{idVendor}==\"0471\", ATTR{idProduct}==\"083f\", GOTO=\"libmtp_rules_end\"\n"); |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 164 | break; |
Linus Walleij | e527254 | 2010-11-30 23:26:11 +0000 | [diff] [blame] | 165 | case style_udev_old: |
| 166 | printf("# UDEV-style hotplug map for libmtp\n"); |
| 167 | printf("# Put this file in /etc/udev/rules.d\n\n"); |
| 168 | printf("ACTION!=\"add\", GOTO=\"libmtp_rules_end\"\n"); |
| 169 | printf("ENV{MAJOR}!=\"?*\", GOTO=\"libmtp_rules_end\"\n"); |
| 170 | printf("SUBSYSTEM==\"usb_device\", GOTO=\"libmtp_usb_device_rules\"\n" |
| 171 | "GOTO=\"libmtp_rules_end\"\n\n" |
| 172 | "LABEL=\"libmtp_usb_device_rules\"\n\n"); |
| 173 | break; |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 174 | case style_usbmap: |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 175 | printf("# This usermap will call the script \"libmtp.sh\" whenever a known MTP device is attached.\n\n"); |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 176 | break; |
| 177 | case style_hal: |
| 178 | printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- -*- SGML -*- -->\n"); |
| 179 | printf("<!-- This file was generated by %s - - fdi -->\n", argv[0]); |
| 180 | printf("<deviceinfo version=\"0.2\">\n"); |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 181 | printf(" <device>\n"); |
Linus Walleij | 161fcce | 2008-03-12 22:02:59 +0000 | [diff] [blame] | 182 | printf(" <match key=\"info.subsystem\" string=\"usb\">\n"); |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 183 | break; |
Linus Walleij | 99466e3 | 2007-05-11 21:42:53 +0000 | [diff] [blame] | 184 | case style_usbids: |
| 185 | printf("# usb.ids style device list from libmtp\n"); |
| 186 | printf("# Compare: http://www.linux-usb.org/usb.ids\n"); |
| 187 | break; |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 188 | case style_hwdb: |
| 189 | printf("# hardware database file for libmtp supported devices\n"); |
| 190 | break; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | for (i = 0; i < numentries; i++) { |
| 194 | LIBMTP_device_entry_t * entry = &entries[i]; |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 195 | |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 196 | switch (style) { |
Linus Walleij | e527254 | 2010-11-30 23:26:11 +0000 | [diff] [blame] | 197 | case style_udev: |
| 198 | case style_udev_old: |
| 199 | printf("# %s %s\n", entry->vendor, entry->product); |
Denis Dupeyron | 83e79a2 | 2011-02-07 22:40:45 -0700 | [diff] [blame] | 200 | printf("ATTR{idVendor}==\"%04x\", ATTR{idProduct}==\"%04x\", %s", entry->vendor_id, entry->product_id, action); |
| 201 | if (udev_group != NULL) printf(", GROUP=\"%s\"", udev_group); |
| 202 | if (udev_mode != NULL) printf(", MODE=\"%s\"", udev_mode); |
| 203 | printf("\n"); |
Linus Walleij | e527254 | 2010-11-30 23:26:11 +0000 | [diff] [blame] | 204 | break; |
Linus Walleij | 50d47a5 | 2007-09-05 07:59:40 +0000 | [diff] [blame] | 205 | case style_usbmap: |
jefferai | da9687e | 2007-10-16 16:44:15 +0000 | [diff] [blame] | 206 | printf("# %s %s\n", entry->vendor, entry->product); |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 207 | printf("libmtp.sh 0x0003 0x%04x 0x%04x 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000\n", entry->vendor_id, entry->product_id); |
| 208 | break; |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 209 | case style_hal: |
jefferai | da9687e | 2007-10-16 16:44:15 +0000 | [diff] [blame] | 210 | printf(" <!-- %s %s -->\n", entry->vendor, entry->product); |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 211 | printf(" <match key=\"usb.vendor_id\" int=\"0x%04x\">\n", entry->vendor_id); |
| 212 | printf(" <match key=\"usb.product_id\" int=\"0x%04x\">\n", entry->product_id); |
Linus Walleij | 3e13dda | 2007-07-09 22:42:17 +0000 | [diff] [blame] | 213 | /* FIXME: If hal >=0.5.10 can be depended upon, the matches below with contains_not can instead use addset */ |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 214 | printf(" <match key=\"info.capabilities\" contains_not=\"portable_audio_player\">\n"); |
| 215 | printf(" <append key=\"info.capabilities\" type=\"strlist\">portable_audio_player</append>\n"); |
| 216 | printf(" </match>\n"); |
jefferai | 0bfe3ab | 2007-10-09 22:23:48 +0000 | [diff] [blame] | 217 | printf(" <merge key=\"info.vendor\" type=\"string\">%s</merge>\n", entry->vendor); |
| 218 | printf(" <merge key=\"info.product\" type=\"string\">%s</merge>\n", entry->product); |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 219 | printf(" <merge key=\"info.category\" type=\"string\">portable_audio_player</merge>\n"); |
| 220 | printf(" <merge key=\"portable_audio_player.access_method\" type=\"string\">user</merge>\n"); |
| 221 | printf(" <match key=\"portable_audio_player.access_method.protocols\" contains_not=\"mtp\">\n"); |
| 222 | printf(" <append key=\"portable_audio_player.access_method.protocols\" type=\"strlist\">mtp</append>\n"); |
| 223 | printf(" </match>\n"); |
| 224 | printf(" <append key=\"portable_audio_player.access_method.drivers\" type=\"strlist\">libmtp</append>\n"); |
Linus Walleij | 3e13dda | 2007-07-09 22:42:17 +0000 | [diff] [blame] | 225 | /* FIXME: needs true list of formats ... But all of them can do MP3 and WMA */ |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 226 | printf(" <match key=\"portable_audio_player.output_formats\" contains_not=\"audio/mpeg\">\n"); |
| 227 | printf(" <append key=\"portable_audio_player.output_formats\" type=\"strlist\">audio/mpeg</append>\n"); |
| 228 | printf(" </match>\n"); |
| 229 | printf(" <match key=\"portable_audio_player.output_formats\" contains_not=\"audio/x-ms-wma\">\n"); |
| 230 | printf(" <append key=\"portable_audio_player.output_formats\" type=\"strlist\">audio/x-ms-wma</append>\n"); |
| 231 | printf(" </match>\n"); |
Linus Walleij | 3e13dda | 2007-07-09 22:42:17 +0000 | [diff] [blame] | 232 | /* Special hack to support the OGG format - irivers, TrekStor and NormSoft (Palm) can always play these files! */ |
| 233 | if (entry->vendor_id == 0x4102 || // iriver |
| 234 | entry->vendor_id == 0x066f || // TrekStor |
| 235 | entry->vendor_id == 0x1703) { // NormSoft, Inc. |
| 236 | printf(" <match key=\"portable_audio_player.output_formats\" contains_not=\"application/ogg\">\n"); |
| 237 | printf(" <append key=\"portable_audio_player.output_formats\" type=\"strlist\">application/ogg</append>\n"); |
| 238 | printf(" </match>\n"); |
| 239 | } |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 240 | printf(" <merge key=\"portable_audio_player.libmtp.protocol\" type=\"string\">mtp</merge>\n"); |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 241 | printf(" </match>\n"); |
| 242 | printf(" </match>\n"); |
| 243 | break; |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 244 | case style_usbids: |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 245 | if (last_vendor != entry->vendor_id) { |
| 246 | printf("%04x\n", entry->vendor_id); |
| 247 | } |
jefferai | da9687e | 2007-10-16 16:44:15 +0000 | [diff] [blame] | 248 | printf("\t%04x %s %s\n", entry->product_id, entry->vendor, entry->product); |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 249 | break; |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 250 | case style_hwdb: |
| 251 | printf("# %s %s\n", entry->vendor, entry->product); |
| 252 | printf("usb:v%04xp%04x*\n", entry->vendor_id, entry->product_id); |
| 253 | printf(" ID_MEDIA_PLAYER=1\n"); |
| 254 | printf(" ID_MTP_DEVICE=1\n"); |
| 255 | printf("\n"); |
| 256 | break; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 257 | } |
Linus Walleij | 99466e3 | 2007-05-11 21:42:53 +0000 | [diff] [blame] | 258 | last_vendor = entry->vendor_id; |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 259 | } |
| 260 | } else { |
| 261 | printf("Error.\n"); |
| 262 | exit(1); |
| 263 | } |
| 264 | |
Linus Walleij | 71b8c0f | 2007-09-06 09:09:14 +0000 | [diff] [blame] | 265 | // Then the footer. |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 266 | switch (style) { |
| 267 | case style_usbmap: |
Marcus Meissner | 4b1b2c7 | 2015-03-22 18:37:30 +0100 | [diff] [blame] | 268 | case style_hwdb: |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 269 | break; |
| 270 | case style_udev: |
Linus Walleij | 6d3c222 | 2010-11-30 23:42:32 +0000 | [diff] [blame] | 271 | case style_udev_old: |
Linus Walleij | 549f49a | 2010-12-05 14:00:34 +0000 | [diff] [blame] | 272 | /* |
| 273 | * This is code that invokes the mtp-probe program on |
| 274 | * every USB device that is either PTP or vendor specific |
| 275 | */ |
Linus Walleij | 9438183 | 2011-01-19 17:47:39 +0100 | [diff] [blame] | 276 | printf("\n# Autoprobe vendor-specific, communication and PTP devices\n"); |
Linus Walleij | d5ab76b | 2011-10-22 15:04:02 +0200 | [diff] [blame] | 277 | printf("ENV{ID_MTP_DEVICE}!=\"1\", ENV{MTP_NO_PROBE}!=\"1\", ENV{COLOR_MEASUREMENT_DEVICE}!=\"1\", ENV{libsane_matched}!=\"yes\", ATTR{bDeviceClass}==\"00|02|06|ef|ff\", PROGRAM=\"%smtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum}\", RESULT==\"1\", %s", mtp_probe_dir, action); |
Denis Dupeyron | 83e79a2 | 2011-02-07 22:40:45 -0700 | [diff] [blame] | 278 | if (udev_group != NULL) printf(", GROUP=\"%s\"", udev_group); |
| 279 | if (udev_mode != NULL) printf(", MODE=\"%s\"", udev_mode); |
| 280 | printf("\n"); |
| 281 | printf("\nLABEL=\"libmtp_rules_end\"\n"); |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 282 | break; |
| 283 | case style_hal: |
jefferai | f28f2a1 | 2007-05-24 23:07:41 +0000 | [diff] [blame] | 284 | printf(" </match>\n"); |
| 285 | printf(" </device>\n"); |
Linus Walleij | f73de15 | 2006-11-25 21:44:44 +0000 | [diff] [blame] | 286 | printf("</deviceinfo>\n"); |
| 287 | break; |
Linus Walleij | 99466e3 | 2007-05-11 21:42:53 +0000 | [diff] [blame] | 288 | case style_usbids: |
| 289 | printf("\n"); |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | exit (0); |
| 293 | } |