2 * Media Transfer Protocol implementation, backed by host filesystem.
4 * Copyright Red Hat, Inc 2014
7 * Gerd Hoffmann <kraxel@redhat.com>
9 * This code is licensed under the GPL v2 or later.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
17 #include <sys/statvfs.h>
18 #ifdef CONFIG_INOTIFY1
19 #include <sys/inotify.h>
20 #include "qemu/main-loop.h"
23 #include "qemu-common.h"
27 #include "hw/usb/desc.h"
29 /* ----------------------------------------------------------------------- */
31 enum mtp_container_type
{
40 CMD_GET_DEVICE_INFO
= 0x1001,
41 CMD_OPEN_SESSION
= 0x1002,
42 CMD_CLOSE_SESSION
= 0x1003,
43 CMD_GET_STORAGE_IDS
= 0x1004,
44 CMD_GET_STORAGE_INFO
= 0x1005,
45 CMD_GET_NUM_OBJECTS
= 0x1006,
46 CMD_GET_OBJECT_HANDLES
= 0x1007,
47 CMD_GET_OBJECT_INFO
= 0x1008,
48 CMD_GET_OBJECT
= 0x1009,
49 CMD_GET_PARTIAL_OBJECT
= 0x101b,
50 CMD_GET_OBJECT_PROPS_SUPPORTED
= 0x9801,
51 CMD_GET_OBJECT_PROP_DESC
= 0x9802,
52 CMD_GET_OBJECT_PROP_VALUE
= 0x9803,
56 RES_GENERAL_ERROR
= 0x2002,
57 RES_SESSION_NOT_OPEN
= 0x2003,
58 RES_INVALID_TRANSACTION_ID
= 0x2004,
59 RES_OPERATION_NOT_SUPPORTED
= 0x2005,
60 RES_PARAMETER_NOT_SUPPORTED
= 0x2006,
61 RES_INCOMPLETE_TRANSFER
= 0x2007,
62 RES_INVALID_STORAGE_ID
= 0x2008,
63 RES_INVALID_OBJECT_HANDLE
= 0x2009,
64 RES_INVALID_OBJECT_FORMAT_CODE
= 0x200b,
65 RES_SPEC_BY_FORMAT_UNSUPPORTED
= 0x2014,
66 RES_INVALID_PARENT_OBJECT
= 0x201a,
67 RES_INVALID_PARAMETER
= 0x201d,
68 RES_SESSION_ALREADY_OPEN
= 0x201e,
69 RES_INVALID_OBJECT_PROP_CODE
= 0xA801,
72 FMT_UNDEFINED_OBJECT
= 0x3000,
73 FMT_ASSOCIATION
= 0x3001,
76 EVT_OBJ_ADDED
= 0x4002,
77 EVT_OBJ_REMOVED
= 0x4003,
78 EVT_OBJ_INFO_CHANGED
= 0x4007,
80 /* object properties */
81 PROP_STORAGE_ID
= 0xDC01,
82 PROP_OBJECT_FORMAT
= 0xDC02,
83 PROP_OBJECT_COMPRESSED_SIZE
= 0xDC04,
84 PROP_PARENT_OBJECT
= 0xDC0B,
85 PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
= 0xDC41,
90 DATA_TYPE_UINT16
= 0x0004,
91 DATA_TYPE_UINT32
= 0x0006,
92 DATA_TYPE_UINT64
= 0x0008,
93 DATA_TYPE_UINT128
= 0x000a,
94 DATA_TYPE_STRING
= 0xffff,
102 } QEMU_PACKED mtp_container
;
104 /* ----------------------------------------------------------------------- */
106 typedef struct MTPState MTPState
;
107 typedef struct MTPControl MTPControl
;
108 typedef struct MTPData MTPData
;
109 typedef struct MTPObject MTPObject
;
117 #ifdef CONFIG_INOTIFY1
118 typedef struct MTPMonEntry MTPMonEntry
;
124 QTAILQ_ENTRY(MTPMonEntry
) next
;
152 #ifdef CONFIG_INOTIFY1
153 /* inotify watch cookie */
158 QLIST_HEAD(, MTPObject
) children
;
159 QLIST_ENTRY(MTPObject
) list
;
161 QTAILQ_ENTRY(MTPObject
) next
;
174 uint32_t next_handle
;
176 QTAILQ_HEAD(, MTPObject
) objects
;
177 #ifdef CONFIG_INOTIFY1
178 /* inotify descriptor */
180 QTAILQ_HEAD(events
, MTPMonEntry
) events
;
184 #define TYPE_USB_MTP "usb-mtp"
185 #define USB_MTP(obj) OBJECT_CHECK(MTPState, (obj), TYPE_USB_MTP)
187 #define QEMU_STORAGE_ID 0x00010001
189 #define MTP_FLAG_WRITABLE 0
191 #define FLAG_SET(_mtp, _flag) ((_mtp)->flags & (1 << (_flag)))
193 /* ----------------------------------------------------------------------- */
195 #define MTP_MANUFACTURER "QEMU"
196 #define MTP_PRODUCT "QEMU filesharing"
199 STR_MANUFACTURER
= 1,
208 static const USBDescStrings desc_strings
= {
209 [STR_MANUFACTURER
] = MTP_MANUFACTURER
,
210 [STR_PRODUCT
] = MTP_PRODUCT
,
211 [STR_SERIALNUMBER
] = "34617",
213 [STR_CONFIG_FULL
] = "Full speed config (usb 1.1)",
214 [STR_CONFIG_HIGH
] = "High speed config (usb 2.0)",
215 [STR_CONFIG_SUPER
] = "Super speed config (usb 3.0)",
218 static const USBDescIface desc_iface_full
= {
219 .bInterfaceNumber
= 0,
221 .bInterfaceClass
= USB_CLASS_STILL_IMAGE
,
222 .bInterfaceSubClass
= 0x01,
223 .bInterfaceProtocol
= 0x01,
224 .iInterface
= STR_MTP
,
225 .eps
= (USBDescEndpoint
[]) {
227 .bEndpointAddress
= USB_DIR_IN
| EP_DATA_IN
,
228 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
229 .wMaxPacketSize
= 64,
231 .bEndpointAddress
= USB_DIR_OUT
| EP_DATA_OUT
,
232 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
233 .wMaxPacketSize
= 64,
235 .bEndpointAddress
= USB_DIR_IN
| EP_EVENT
,
236 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
237 .wMaxPacketSize
= 64,
243 static const USBDescDevice desc_device_full
= {
245 .bMaxPacketSize0
= 8,
246 .bNumConfigurations
= 1,
247 .confs
= (USBDescConfig
[]) {
250 .bConfigurationValue
= 1,
251 .iConfiguration
= STR_CONFIG_FULL
,
252 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
255 .ifs
= &desc_iface_full
,
260 static const USBDescIface desc_iface_high
= {
261 .bInterfaceNumber
= 0,
263 .bInterfaceClass
= USB_CLASS_STILL_IMAGE
,
264 .bInterfaceSubClass
= 0x01,
265 .bInterfaceProtocol
= 0x01,
266 .iInterface
= STR_MTP
,
267 .eps
= (USBDescEndpoint
[]) {
269 .bEndpointAddress
= USB_DIR_IN
| EP_DATA_IN
,
270 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
271 .wMaxPacketSize
= 512,
273 .bEndpointAddress
= USB_DIR_OUT
| EP_DATA_OUT
,
274 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
275 .wMaxPacketSize
= 512,
277 .bEndpointAddress
= USB_DIR_IN
| EP_EVENT
,
278 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
279 .wMaxPacketSize
= 64,
285 static const USBDescDevice desc_device_high
= {
287 .bMaxPacketSize0
= 64,
288 .bNumConfigurations
= 1,
289 .confs
= (USBDescConfig
[]) {
292 .bConfigurationValue
= 1,
293 .iConfiguration
= STR_CONFIG_HIGH
,
294 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
297 .ifs
= &desc_iface_high
,
302 static const USBDescMSOS desc_msos
= {
303 .CompatibleID
= "MTP",
304 .SelectiveSuspendEnabled
= true,
307 static const USBDesc desc
= {
309 .idVendor
= 0x46f4, /* CRC16() of "QEMU" */
312 .iManufacturer
= STR_MANUFACTURER
,
313 .iProduct
= STR_PRODUCT
,
314 .iSerialNumber
= STR_SERIALNUMBER
,
316 .full
= &desc_device_full
,
317 .high
= &desc_device_high
,
322 /* ----------------------------------------------------------------------- */
324 static MTPObject
*usb_mtp_object_alloc(MTPState
*s
, uint32_t handle
,
325 MTPObject
*parent
, char *name
)
327 MTPObject
*o
= g_new0(MTPObject
, 1);
329 if (name
[0] == '.') {
335 o
->name
= g_strdup(name
);
336 if (parent
== NULL
) {
337 o
->path
= g_strdup(name
);
339 o
->path
= g_strdup_printf("%s/%s", parent
->path
, name
);
342 if (lstat(o
->path
, &o
->stat
) != 0) {
345 if (S_ISREG(o
->stat
.st_mode
)) {
346 o
->format
= FMT_UNDEFINED_OBJECT
;
347 } else if (S_ISDIR(o
->stat
.st_mode
)) {
348 o
->format
= FMT_ASSOCIATION
;
353 if (access(o
->path
, R_OK
) != 0) {
357 trace_usb_mtp_object_alloc(s
->dev
.addr
, o
->handle
, o
->path
);
359 QTAILQ_INSERT_TAIL(&s
->objects
, o
, next
);
369 static void usb_mtp_object_free(MTPState
*s
, MTPObject
*o
)
377 trace_usb_mtp_object_free(s
->dev
.addr
, o
->handle
, o
->path
);
379 QTAILQ_REMOVE(&s
->objects
, o
, next
);
381 QLIST_REMOVE(o
, list
);
382 o
->parent
->nchildren
--;
385 while (!QLIST_EMPTY(&o
->children
)) {
386 iter
= QLIST_FIRST(&o
->children
);
387 usb_mtp_object_free(s
, iter
);
394 static MTPObject
*usb_mtp_object_lookup(MTPState
*s
, uint32_t handle
)
398 QTAILQ_FOREACH(o
, &s
->objects
, next
) {
399 if (o
->handle
== handle
) {
406 static MTPObject
*usb_mtp_add_child(MTPState
*s
, MTPObject
*o
,
410 usb_mtp_object_alloc(s
, s
->next_handle
++, o
, name
);
413 trace_usb_mtp_add_child(s
->dev
.addr
, child
->handle
, child
->path
);
414 QLIST_INSERT_HEAD(&o
->children
, child
, list
);
417 if (child
->format
== FMT_ASSOCIATION
) {
418 QLIST_INIT(&child
->children
);
425 #ifdef CONFIG_INOTIFY1
426 static MTPObject
*usb_mtp_object_lookup_name(MTPObject
*parent
,
431 QLIST_FOREACH(iter
, &parent
->children
, list
) {
432 if (strncmp(iter
->name
, name
, len
) == 0) {
440 static MTPObject
*usb_mtp_object_lookup_wd(MTPState
*s
, int wd
)
444 QTAILQ_FOREACH(iter
, &s
->objects
, next
) {
445 if (iter
->watchfd
== wd
) {
453 static void inotify_watchfn(void *arg
)
457 /* From the man page: atleast one event can be read */
459 char buf
[sizeof(struct inotify_event
) + NAME_MAX
+ 1];
462 bytes
= read(s
->inotifyfd
, buf
, sizeof(buf
));
466 /* Better luck next time */
471 * TODO: Ignore initiator initiated events.
472 * For now we are good because the store is RO
476 struct inotify_event
*event
= (struct inotify_event
*)p
;
478 uint32_t mask
= event
->mask
& (IN_CREATE
| IN_DELETE
|
479 IN_MODIFY
| IN_IGNORED
);
480 MTPObject
*parent
= usb_mtp_object_lookup_wd(s
, event
->wd
);
481 MTPMonEntry
*entry
= NULL
;
484 pos
= pos
+ sizeof(struct inotify_event
) + event
->len
;
493 if (usb_mtp_object_lookup_name
494 (parent
, event
->name
, event
->len
)) {
495 /* Duplicate create event */
498 entry
= g_new0(MTPMonEntry
, 1);
499 entry
->handle
= s
->next_handle
;
500 entry
->event
= EVT_OBJ_ADDED
;
501 o
= usb_mtp_add_child(s
, parent
, event
->name
);
506 o
->watchfd
= watchfd
;
507 trace_usb_mtp_inotify_event(s
->dev
.addr
, event
->name
,
508 event
->mask
, "Obj Added");
513 * The kernel issues a IN_IGNORED event
514 * when a dir containing a watchpoint is
515 * deleted, so we don't have to delete the
518 o
= usb_mtp_object_lookup_name(parent
, event
->name
, event
->len
);
522 entry
= g_new0(MTPMonEntry
, 1);
523 entry
->handle
= o
->handle
;
524 entry
->event
= EVT_OBJ_REMOVED
;
525 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
526 event
->mask
, "Obj Deleted");
527 usb_mtp_object_free(s
, o
);
531 o
= usb_mtp_object_lookup_name(parent
, event
->name
, event
->len
);
535 entry
= g_new0(MTPMonEntry
, 1);
536 entry
->handle
= o
->handle
;
537 entry
->event
= EVT_OBJ_INFO_CHANGED
;
538 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
539 event
->mask
, "Obj Modified");
543 o
= usb_mtp_object_lookup_name(parent
, event
->name
, event
->len
);
544 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
545 event
->mask
, "Obj ignored");
549 fprintf(stderr
, "usb-mtp: failed to parse inotify event\n");
554 QTAILQ_INSERT_HEAD(&s
->events
, entry
, next
);
560 static int usb_mtp_inotify_init(MTPState
*s
)
564 fd
= inotify_init1(IN_NONBLOCK
);
569 QTAILQ_INIT(&s
->events
);
572 qemu_set_fd_handler(fd
, inotify_watchfn
, NULL
, s
);
577 static void usb_mtp_inotify_cleanup(MTPState
*s
)
585 qemu_set_fd_handler(s
->inotifyfd
, NULL
, NULL
, s
);
588 QTAILQ_FOREACH_SAFE(e
, &s
->events
, next
, p
) {
589 QTAILQ_REMOVE(&s
->events
, e
, next
);
594 static int usb_mtp_add_watch(int inotifyfd
, char *path
)
596 uint32_t mask
= IN_CREATE
| IN_DELETE
| IN_MODIFY
|
599 return inotify_add_watch(inotifyfd
, path
, mask
);
603 static void usb_mtp_object_readdir(MTPState
*s
, MTPObject
*o
)
605 struct dirent
*entry
;
608 if (o
->have_children
) {
611 o
->have_children
= true;
613 dir
= opendir(o
->path
);
617 #ifdef CONFIG_INOTIFY1
618 int watchfd
= usb_mtp_add_watch(s
->inotifyfd
, o
->path
);
620 fprintf(stderr
, "usb-mtp: failed to add watch for %s\n", o
->path
);
622 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
624 o
->watchfd
= watchfd
;
627 while ((entry
= readdir(dir
)) != NULL
) {
628 usb_mtp_add_child(s
, o
, entry
->d_name
);
633 /* ----------------------------------------------------------------------- */
635 static MTPData
*usb_mtp_data_alloc(MTPControl
*c
)
637 MTPData
*data
= g_new0(MTPData
, 1);
639 data
->code
= c
->code
;
640 data
->trans
= c
->trans
;
646 static void usb_mtp_data_free(MTPData
*data
)
651 if (data
->fd
!= -1) {
658 static void usb_mtp_realloc(MTPData
*data
, uint32_t bytes
)
660 if (data
->length
+ bytes
<= data
->alloc
) {
663 data
->alloc
= (data
->length
+ bytes
+ 0xff) & ~0xff;
664 data
->data
= g_realloc(data
->data
, data
->alloc
);
667 static void usb_mtp_add_u8(MTPData
*data
, uint8_t val
)
669 usb_mtp_realloc(data
, 1);
670 data
->data
[data
->length
++] = val
;
673 static void usb_mtp_add_u16(MTPData
*data
, uint16_t val
)
675 usb_mtp_realloc(data
, 2);
676 data
->data
[data
->length
++] = (val
>> 0) & 0xff;
677 data
->data
[data
->length
++] = (val
>> 8) & 0xff;
680 static void usb_mtp_add_u32(MTPData
*data
, uint32_t val
)
682 usb_mtp_realloc(data
, 4);
683 data
->data
[data
->length
++] = (val
>> 0) & 0xff;
684 data
->data
[data
->length
++] = (val
>> 8) & 0xff;
685 data
->data
[data
->length
++] = (val
>> 16) & 0xff;
686 data
->data
[data
->length
++] = (val
>> 24) & 0xff;
689 static void usb_mtp_add_u64(MTPData
*data
, uint64_t val
)
691 usb_mtp_realloc(data
, 8);
692 data
->data
[data
->length
++] = (val
>> 0) & 0xff;
693 data
->data
[data
->length
++] = (val
>> 8) & 0xff;
694 data
->data
[data
->length
++] = (val
>> 16) & 0xff;
695 data
->data
[data
->length
++] = (val
>> 24) & 0xff;
696 data
->data
[data
->length
++] = (val
>> 32) & 0xff;
697 data
->data
[data
->length
++] = (val
>> 40) & 0xff;
698 data
->data
[data
->length
++] = (val
>> 48) & 0xff;
699 data
->data
[data
->length
++] = (val
>> 56) & 0xff;
702 static void usb_mtp_add_u16_array(MTPData
*data
, uint32_t len
,
703 const uint16_t *vals
)
707 usb_mtp_add_u32(data
, len
);
708 for (i
= 0; i
< len
; i
++) {
709 usb_mtp_add_u16(data
, vals
[i
]);
713 static void usb_mtp_add_u32_array(MTPData
*data
, uint32_t len
,
714 const uint32_t *vals
)
718 usb_mtp_add_u32(data
, len
);
719 for (i
= 0; i
< len
; i
++) {
720 usb_mtp_add_u32(data
, vals
[i
]);
724 static void usb_mtp_add_wstr(MTPData
*data
, const wchar_t *str
)
726 uint32_t len
= wcslen(str
);
730 len
++; /* include terminating L'\0' */
733 usb_mtp_add_u8(data
, len
);
734 for (i
= 0; i
< len
; i
++) {
735 usb_mtp_add_u16(data
, str
[i
]);
739 static void usb_mtp_add_str(MTPData
*data
, const char *str
)
741 uint32_t len
= strlen(str
)+1;
742 wchar_t *wstr
= g_new(wchar_t, len
);
745 ret
= mbstowcs(wstr
, str
, len
);
747 usb_mtp_add_wstr(data
, L
"Oops");
749 usb_mtp_add_wstr(data
, wstr
);
755 static void usb_mtp_add_time(MTPData
*data
, time_t time
)
760 gmtime_r(&time
, &tm
);
761 strftime(buf
, sizeof(buf
), "%Y%m%dT%H%M%S", &tm
);
762 usb_mtp_add_str(data
, buf
);
765 /* ----------------------------------------------------------------------- */
767 static void usb_mtp_queue_result(MTPState
*s
, uint16_t code
, uint32_t trans
,
768 int argc
, uint32_t arg0
, uint32_t arg1
)
770 MTPControl
*c
= g_new0(MTPControl
, 1);
782 assert(s
->result
== NULL
);
786 /* ----------------------------------------------------------------------- */
788 static MTPData
*usb_mtp_get_device_info(MTPState
*s
, MTPControl
*c
)
790 static const uint16_t ops
[] = {
795 CMD_GET_STORAGE_INFO
,
797 CMD_GET_OBJECT_HANDLES
,
800 CMD_GET_PARTIAL_OBJECT
,
801 CMD_GET_OBJECT_PROPS_SUPPORTED
,
802 CMD_GET_OBJECT_PROP_DESC
,
803 CMD_GET_OBJECT_PROP_VALUE
,
805 static const uint16_t fmt
[] = {
806 FMT_UNDEFINED_OBJECT
,
809 MTPData
*d
= usb_mtp_data_alloc(c
);
811 trace_usb_mtp_op_get_device_info(s
->dev
.addr
);
813 usb_mtp_add_u16(d
, 100);
814 usb_mtp_add_u32(d
, 0x00000006);
815 usb_mtp_add_u16(d
, 0x0064);
816 usb_mtp_add_wstr(d
, L
"");
817 usb_mtp_add_u16(d
, 0x0000);
819 usb_mtp_add_u16_array(d
, ARRAY_SIZE(ops
), ops
);
820 usb_mtp_add_u16_array(d
, 0, NULL
);
821 usb_mtp_add_u16_array(d
, 0, NULL
);
822 usb_mtp_add_u16_array(d
, 0, NULL
);
823 usb_mtp_add_u16_array(d
, ARRAY_SIZE(fmt
), fmt
);
825 usb_mtp_add_wstr(d
, L
"" MTP_MANUFACTURER
);
826 usb_mtp_add_wstr(d
, L
"" MTP_PRODUCT
);
827 usb_mtp_add_wstr(d
, L
"0.1");
828 usb_mtp_add_wstr(d
, L
"0123456789abcdef0123456789abcdef");
833 static MTPData
*usb_mtp_get_storage_ids(MTPState
*s
, MTPControl
*c
)
835 static const uint32_t ids
[] = {
838 MTPData
*d
= usb_mtp_data_alloc(c
);
840 trace_usb_mtp_op_get_storage_ids(s
->dev
.addr
);
842 usb_mtp_add_u32_array(d
, ARRAY_SIZE(ids
), ids
);
847 static MTPData
*usb_mtp_get_storage_info(MTPState
*s
, MTPControl
*c
)
849 MTPData
*d
= usb_mtp_data_alloc(c
);
853 trace_usb_mtp_op_get_storage_info(s
->dev
.addr
);
855 if (FLAG_SET(s
, MTP_FLAG_WRITABLE
)) {
856 usb_mtp_add_u16(d
, 0x0003);
857 usb_mtp_add_u16(d
, 0x0002);
858 usb_mtp_add_u16(d
, 0x0000);
860 usb_mtp_add_u16(d
, 0x0001);
861 usb_mtp_add_u16(d
, 0x0002);
862 usb_mtp_add_u16(d
, 0x0001);
865 rc
= statvfs(s
->root
, &buf
);
867 usb_mtp_add_u64(d
, (uint64_t)buf
.f_frsize
* buf
.f_blocks
);
868 usb_mtp_add_u64(d
, (uint64_t)buf
.f_bavail
* buf
.f_blocks
);
869 usb_mtp_add_u32(d
, buf
.f_ffree
);
871 usb_mtp_add_u64(d
, 0xffffffff);
872 usb_mtp_add_u64(d
, 0xffffffff);
873 usb_mtp_add_u32(d
, 0xffffffff);
876 usb_mtp_add_str(d
, s
->desc
);
877 usb_mtp_add_wstr(d
, L
"123456789abcdef");
881 static MTPData
*usb_mtp_get_object_handles(MTPState
*s
, MTPControl
*c
,
884 MTPData
*d
= usb_mtp_data_alloc(c
);
885 uint32_t i
= 0, handles
[o
->nchildren
];
888 trace_usb_mtp_op_get_object_handles(s
->dev
.addr
, o
->handle
, o
->path
);
890 QLIST_FOREACH(iter
, &o
->children
, list
) {
891 handles
[i
++] = iter
->handle
;
893 assert(i
== o
->nchildren
);
894 usb_mtp_add_u32_array(d
, o
->nchildren
, handles
);
899 static MTPData
*usb_mtp_get_object_info(MTPState
*s
, MTPControl
*c
,
902 MTPData
*d
= usb_mtp_data_alloc(c
);
904 trace_usb_mtp_op_get_object_info(s
->dev
.addr
, o
->handle
, o
->path
);
906 usb_mtp_add_u32(d
, QEMU_STORAGE_ID
);
907 usb_mtp_add_u16(d
, o
->format
);
908 usb_mtp_add_u16(d
, 0);
910 if (o
->stat
.st_size
> 0xFFFFFFFF) {
911 usb_mtp_add_u32(d
, 0xFFFFFFFF);
913 usb_mtp_add_u32(d
, o
->stat
.st_size
);
916 usb_mtp_add_u16(d
, 0);
917 usb_mtp_add_u32(d
, 0);
918 usb_mtp_add_u32(d
, 0);
919 usb_mtp_add_u32(d
, 0);
920 usb_mtp_add_u32(d
, 0);
921 usb_mtp_add_u32(d
, 0);
922 usb_mtp_add_u32(d
, 0);
925 usb_mtp_add_u32(d
, o
->parent
->handle
);
927 usb_mtp_add_u32(d
, 0);
929 if (o
->format
== FMT_ASSOCIATION
) {
930 usb_mtp_add_u16(d
, 0x0001);
931 usb_mtp_add_u32(d
, 0x00000001);
932 usb_mtp_add_u32(d
, 0);
934 usb_mtp_add_u16(d
, 0);
935 usb_mtp_add_u32(d
, 0);
936 usb_mtp_add_u32(d
, 0);
939 usb_mtp_add_str(d
, o
->name
);
940 usb_mtp_add_time(d
, o
->stat
.st_ctime
);
941 usb_mtp_add_time(d
, o
->stat
.st_mtime
);
942 usb_mtp_add_wstr(d
, L
"");
947 static MTPData
*usb_mtp_get_object(MTPState
*s
, MTPControl
*c
,
950 MTPData
*d
= usb_mtp_data_alloc(c
);
952 trace_usb_mtp_op_get_object(s
->dev
.addr
, o
->handle
, o
->path
);
954 d
->fd
= open(o
->path
, O_RDONLY
);
956 usb_mtp_data_free(d
);
959 d
->length
= o
->stat
.st_size
;
961 d
->data
= g_malloc(d
->alloc
);
965 static MTPData
*usb_mtp_get_partial_object(MTPState
*s
, MTPControl
*c
,
968 MTPData
*d
= usb_mtp_data_alloc(c
);
971 trace_usb_mtp_op_get_partial_object(s
->dev
.addr
, o
->handle
, o
->path
,
972 c
->argv
[1], c
->argv
[2]);
974 d
->fd
= open(o
->path
, O_RDONLY
);
976 usb_mtp_data_free(d
);
981 if (offset
> o
->stat
.st_size
) {
982 offset
= o
->stat
.st_size
;
984 if (lseek(d
->fd
, offset
, SEEK_SET
) < 0) {
985 usb_mtp_data_free(d
);
989 d
->length
= c
->argv
[2];
990 if (d
->length
> o
->stat
.st_size
- offset
) {
991 d
->length
= o
->stat
.st_size
- offset
;
997 static MTPData
*usb_mtp_get_object_props_supported(MTPState
*s
, MTPControl
*c
)
999 static const uint16_t props
[] = {
1002 PROP_OBJECT_COMPRESSED_SIZE
,
1004 PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
,
1007 MTPData
*d
= usb_mtp_data_alloc(c
);
1008 usb_mtp_add_u16_array(d
, ARRAY_SIZE(props
), props
);
1013 static MTPData
*usb_mtp_get_object_prop_desc(MTPState
*s
, MTPControl
*c
)
1015 MTPData
*d
= usb_mtp_data_alloc(c
);
1016 switch (c
->argv
[0]) {
1017 case PROP_STORAGE_ID
:
1018 usb_mtp_add_u16(d
, PROP_STORAGE_ID
);
1019 usb_mtp_add_u16(d
, DATA_TYPE_UINT32
);
1020 usb_mtp_add_u8(d
, 0x00);
1021 usb_mtp_add_u32(d
, 0x00000000);
1022 usb_mtp_add_u32(d
, 0x00000000);
1023 usb_mtp_add_u8(d
, 0x00);
1025 case PROP_OBJECT_FORMAT
:
1026 usb_mtp_add_u16(d
, PROP_OBJECT_FORMAT
);
1027 usb_mtp_add_u16(d
, DATA_TYPE_UINT16
);
1028 usb_mtp_add_u8(d
, 0x00);
1029 usb_mtp_add_u16(d
, 0x0000);
1030 usb_mtp_add_u32(d
, 0x00000000);
1031 usb_mtp_add_u8(d
, 0x00);
1033 case PROP_OBJECT_COMPRESSED_SIZE
:
1034 usb_mtp_add_u16(d
, PROP_OBJECT_COMPRESSED_SIZE
);
1035 usb_mtp_add_u16(d
, DATA_TYPE_UINT64
);
1036 usb_mtp_add_u8(d
, 0x00);
1037 usb_mtp_add_u64(d
, 0x0000000000000000);
1038 usb_mtp_add_u32(d
, 0x00000000);
1039 usb_mtp_add_u8(d
, 0x00);
1041 case PROP_PARENT_OBJECT
:
1042 usb_mtp_add_u16(d
, PROP_PARENT_OBJECT
);
1043 usb_mtp_add_u16(d
, DATA_TYPE_UINT32
);
1044 usb_mtp_add_u8(d
, 0x00);
1045 usb_mtp_add_u32(d
, 0x00000000);
1046 usb_mtp_add_u32(d
, 0x00000000);
1047 usb_mtp_add_u8(d
, 0x00);
1049 case PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
:
1050 usb_mtp_add_u16(d
, PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
);
1051 usb_mtp_add_u16(d
, DATA_TYPE_UINT128
);
1052 usb_mtp_add_u8(d
, 0x00);
1053 usb_mtp_add_u64(d
, 0x0000000000000000);
1054 usb_mtp_add_u64(d
, 0x0000000000000000);
1055 usb_mtp_add_u32(d
, 0x00000000);
1056 usb_mtp_add_u8(d
, 0x00);
1059 usb_mtp_add_u16(d
, PROP_NAME
);
1060 usb_mtp_add_u16(d
, DATA_TYPE_STRING
);
1061 usb_mtp_add_u8(d
, 0x00);
1062 usb_mtp_add_u8(d
, 0x00);
1063 usb_mtp_add_u32(d
, 0x00000000);
1064 usb_mtp_add_u8(d
, 0x00);
1067 usb_mtp_data_free(d
);
1074 static MTPData
*usb_mtp_get_object_prop_value(MTPState
*s
, MTPControl
*c
,
1077 MTPData
*d
= usb_mtp_data_alloc(c
);
1078 switch (c
->argv
[1]) {
1079 case PROP_STORAGE_ID
:
1080 usb_mtp_add_u32(d
, QEMU_STORAGE_ID
);
1082 case PROP_OBJECT_FORMAT
:
1083 usb_mtp_add_u16(d
, o
->format
);
1085 case PROP_OBJECT_COMPRESSED_SIZE
:
1086 usb_mtp_add_u64(d
, o
->stat
.st_size
);
1088 case PROP_PARENT_OBJECT
:
1089 if (o
->parent
== NULL
) {
1090 usb_mtp_add_u32(d
, 0x00000000);
1092 usb_mtp_add_u32(d
, o
->parent
->handle
);
1095 case PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
:
1096 /* Should be persistent between sessions,
1097 * but using our objedt ID is "good enough"
1099 usb_mtp_add_u64(d
, 0x0000000000000000);
1100 usb_mtp_add_u64(d
, o
->handle
);
1103 usb_mtp_add_str(d
, o
->name
);
1106 usb_mtp_data_free(d
);
1113 static void usb_mtp_command(MTPState
*s
, MTPControl
*c
)
1115 MTPData
*data_in
= NULL
;
1117 uint32_t nres
= 0, res0
= 0;
1120 if (c
->code
>= CMD_CLOSE_SESSION
&& s
->session
== 0) {
1121 usb_mtp_queue_result(s
, RES_SESSION_NOT_OPEN
,
1126 /* process commands */
1128 case CMD_GET_DEVICE_INFO
:
1129 data_in
= usb_mtp_get_device_info(s
, c
);
1131 case CMD_OPEN_SESSION
:
1133 usb_mtp_queue_result(s
, RES_SESSION_ALREADY_OPEN
,
1134 c
->trans
, 1, s
->session
, 0);
1137 if (c
->argv
[0] == 0) {
1138 usb_mtp_queue_result(s
, RES_INVALID_PARAMETER
,
1142 trace_usb_mtp_op_open_session(s
->dev
.addr
);
1143 s
->session
= c
->argv
[0];
1144 usb_mtp_object_alloc(s
, s
->next_handle
++, NULL
, s
->root
);
1145 #ifdef CONFIG_INOTIFY1
1146 if (usb_mtp_inotify_init(s
)) {
1147 fprintf(stderr
, "usb-mtp: file monitoring init failed\n");
1151 case CMD_CLOSE_SESSION
:
1152 trace_usb_mtp_op_close_session(s
->dev
.addr
);
1155 #ifdef CONFIG_INOTIFY1
1156 usb_mtp_inotify_cleanup(s
);
1158 usb_mtp_object_free(s
, QTAILQ_FIRST(&s
->objects
));
1159 assert(QTAILQ_EMPTY(&s
->objects
));
1161 case CMD_GET_STORAGE_IDS
:
1162 data_in
= usb_mtp_get_storage_ids(s
, c
);
1164 case CMD_GET_STORAGE_INFO
:
1165 if (c
->argv
[0] != QEMU_STORAGE_ID
&&
1166 c
->argv
[0] != 0xffffffff) {
1167 usb_mtp_queue_result(s
, RES_INVALID_STORAGE_ID
,
1171 data_in
= usb_mtp_get_storage_info(s
, c
);
1173 case CMD_GET_NUM_OBJECTS
:
1174 case CMD_GET_OBJECT_HANDLES
:
1175 if (c
->argv
[0] != QEMU_STORAGE_ID
&&
1176 c
->argv
[0] != 0xffffffff) {
1177 usb_mtp_queue_result(s
, RES_INVALID_STORAGE_ID
,
1181 if (c
->argv
[1] != 0x00000000) {
1182 usb_mtp_queue_result(s
, RES_SPEC_BY_FORMAT_UNSUPPORTED
,
1186 if (c
->argv
[2] == 0x00000000 ||
1187 c
->argv
[2] == 0xffffffff) {
1188 o
= QTAILQ_FIRST(&s
->objects
);
1190 o
= usb_mtp_object_lookup(s
, c
->argv
[2]);
1193 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1197 if (o
->format
!= FMT_ASSOCIATION
) {
1198 usb_mtp_queue_result(s
, RES_INVALID_PARENT_OBJECT
,
1202 usb_mtp_object_readdir(s
, o
);
1203 if (c
->code
== CMD_GET_NUM_OBJECTS
) {
1204 trace_usb_mtp_op_get_num_objects(s
->dev
.addr
, o
->handle
, o
->path
);
1206 res0
= o
->nchildren
;
1208 data_in
= usb_mtp_get_object_handles(s
, c
, o
);
1211 case CMD_GET_OBJECT_INFO
:
1212 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1214 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1218 data_in
= usb_mtp_get_object_info(s
, c
, o
);
1220 case CMD_GET_OBJECT
:
1221 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1223 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1227 if (o
->format
== FMT_ASSOCIATION
) {
1228 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1232 data_in
= usb_mtp_get_object(s
, c
, o
);
1233 if (data_in
== NULL
) {
1234 usb_mtp_queue_result(s
, RES_GENERAL_ERROR
,
1239 case CMD_GET_PARTIAL_OBJECT
:
1240 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1242 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1246 if (o
->format
== FMT_ASSOCIATION
) {
1247 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1251 data_in
= usb_mtp_get_partial_object(s
, c
, o
);
1252 if (data_in
== NULL
) {
1253 usb_mtp_queue_result(s
, RES_GENERAL_ERROR
,
1258 res0
= data_in
->length
;
1260 case CMD_GET_OBJECT_PROPS_SUPPORTED
:
1261 if (c
->argv
[0] != FMT_UNDEFINED_OBJECT
&&
1262 c
->argv
[0] != FMT_ASSOCIATION
) {
1263 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_FORMAT_CODE
,
1267 data_in
= usb_mtp_get_object_props_supported(s
, c
);
1269 case CMD_GET_OBJECT_PROP_DESC
:
1270 if (c
->argv
[1] != FMT_UNDEFINED_OBJECT
&&
1271 c
->argv
[1] != FMT_ASSOCIATION
) {
1272 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_FORMAT_CODE
,
1276 data_in
= usb_mtp_get_object_prop_desc(s
, c
);
1277 if (data_in
== NULL
) {
1278 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_PROP_CODE
,
1283 case CMD_GET_OBJECT_PROP_VALUE
:
1284 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1286 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1290 data_in
= usb_mtp_get_object_prop_value(s
, c
, o
);
1291 if (data_in
== NULL
) {
1292 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_PROP_CODE
,
1298 trace_usb_mtp_op_unknown(s
->dev
.addr
, c
->code
);
1299 usb_mtp_queue_result(s
, RES_OPERATION_NOT_SUPPORTED
,
1304 /* return results on success */
1306 assert(s
->data_in
== NULL
);
1307 s
->data_in
= data_in
;
1309 usb_mtp_queue_result(s
, RES_OK
, c
->trans
, nres
, res0
, 0);
1312 /* ----------------------------------------------------------------------- */
1314 static void usb_mtp_handle_reset(USBDevice
*dev
)
1316 MTPState
*s
= USB_MTP(dev
);
1318 trace_usb_mtp_reset(s
->dev
.addr
);
1320 #ifdef CONFIG_INOTIFY1
1321 usb_mtp_inotify_cleanup(s
);
1323 usb_mtp_object_free(s
, QTAILQ_FIRST(&s
->objects
));
1325 usb_mtp_data_free(s
->data_in
);
1327 usb_mtp_data_free(s
->data_out
);
1333 static void usb_mtp_handle_control(USBDevice
*dev
, USBPacket
*p
,
1334 int request
, int value
, int index
,
1335 int length
, uint8_t *data
)
1339 ret
= usb_desc_handle_control(dev
, p
, request
, value
, index
, length
, data
);
1344 trace_usb_mtp_stall(dev
->addr
, "unknown control request");
1345 p
->status
= USB_RET_STALL
;
1348 static void usb_mtp_cancel_packet(USBDevice
*dev
, USBPacket
*p
)
1350 /* we don't use async packets, so this should never be called */
1351 fprintf(stderr
, "%s\n", __func__
);
1354 static void usb_mtp_handle_data(USBDevice
*dev
, USBPacket
*p
)
1356 MTPState
*s
= USB_MTP(dev
);
1358 mtp_container container
;
1362 switch (p
->ep
->nr
) {
1364 if (s
->data_out
!= NULL
) {
1366 trace_usb_mtp_stall(s
->dev
.addr
, "awaiting data-out");
1367 p
->status
= USB_RET_STALL
;
1370 if (p
->iov
.size
< sizeof(container
)) {
1371 trace_usb_mtp_stall(s
->dev
.addr
, "packet too small");
1372 p
->status
= USB_RET_STALL
;
1375 if (s
->data_in
!= NULL
) {
1376 MTPData
*d
= s
->data_in
;
1377 uint64_t dlen
= d
->length
- d
->offset
;
1379 trace_usb_mtp_data_in(s
->dev
.addr
, d
->trans
, d
->length
);
1380 if (d
->length
+ sizeof(container
) > 0xFFFFFFFF) {
1381 container
.length
= cpu_to_le32(0xFFFFFFFF);
1384 cpu_to_le32(d
->length
+ sizeof(container
));
1386 container
.type
= cpu_to_le16(TYPE_DATA
);
1387 container
.code
= cpu_to_le16(d
->code
);
1388 container
.trans
= cpu_to_le32(d
->trans
);
1389 usb_packet_copy(p
, &container
, sizeof(container
));
1391 if (dlen
> p
->iov
.size
- sizeof(container
)) {
1392 dlen
= p
->iov
.size
- sizeof(container
);
1395 if (dlen
> p
->iov
.size
) {
1400 usb_packet_copy(p
, d
->data
+ d
->offset
, dlen
);
1402 if (d
->alloc
< p
->iov
.size
) {
1403 d
->alloc
= p
->iov
.size
;
1404 d
->data
= g_realloc(d
->data
, d
->alloc
);
1406 rc
= read(d
->fd
, d
->data
, dlen
);
1408 memset(d
->data
, 0, dlen
);
1409 s
->result
->code
= RES_INCOMPLETE_TRANSFER
;
1411 usb_packet_copy(p
, d
->data
, dlen
);
1414 if (d
->offset
== d
->length
) {
1415 usb_mtp_data_free(s
->data_in
);
1418 } else if (s
->result
!= NULL
) {
1419 MTPControl
*r
= s
->result
;
1420 int length
= sizeof(container
) + r
->argc
* sizeof(uint32_t);
1421 if (r
->code
== RES_OK
) {
1422 trace_usb_mtp_success(s
->dev
.addr
, r
->trans
,
1423 (r
->argc
> 0) ? r
->argv
[0] : 0,
1424 (r
->argc
> 1) ? r
->argv
[1] : 0);
1426 trace_usb_mtp_error(s
->dev
.addr
, r
->code
, r
->trans
,
1427 (r
->argc
> 0) ? r
->argv
[0] : 0,
1428 (r
->argc
> 1) ? r
->argv
[1] : 0);
1430 container
.length
= cpu_to_le32(length
);
1431 container
.type
= cpu_to_le16(TYPE_RESPONSE
);
1432 container
.code
= cpu_to_le16(r
->code
);
1433 container
.trans
= cpu_to_le32(r
->trans
);
1434 for (i
= 0; i
< r
->argc
; i
++) {
1435 params
[i
] = cpu_to_le32(r
->argv
[i
]);
1437 usb_packet_copy(p
, &container
, sizeof(container
));
1438 usb_packet_copy(p
, ¶ms
, length
- sizeof(container
));
1444 if (p
->iov
.size
< sizeof(container
)) {
1445 trace_usb_mtp_stall(s
->dev
.addr
, "packet too small");
1446 p
->status
= USB_RET_STALL
;
1449 usb_packet_copy(p
, &container
, sizeof(container
));
1450 switch (le16_to_cpu(container
.type
)) {
1452 if (s
->data_in
|| s
->data_out
|| s
->result
) {
1453 trace_usb_mtp_stall(s
->dev
.addr
, "transaction inflight");
1454 p
->status
= USB_RET_STALL
;
1457 cmd
.code
= le16_to_cpu(container
.code
);
1458 cmd
.argc
= (le32_to_cpu(container
.length
) - sizeof(container
))
1460 cmd
.trans
= le32_to_cpu(container
.trans
);
1461 if (cmd
.argc
> ARRAY_SIZE(cmd
.argv
)) {
1462 cmd
.argc
= ARRAY_SIZE(cmd
.argv
);
1464 if (p
->iov
.size
< sizeof(container
) + cmd
.argc
* sizeof(uint32_t)) {
1465 trace_usb_mtp_stall(s
->dev
.addr
, "packet too small");
1466 p
->status
= USB_RET_STALL
;
1469 usb_packet_copy(p
, ¶ms
, cmd
.argc
* sizeof(uint32_t));
1470 for (i
= 0; i
< cmd
.argc
; i
++) {
1471 cmd
.argv
[i
] = le32_to_cpu(params
[i
]);
1473 trace_usb_mtp_command(s
->dev
.addr
, cmd
.code
, cmd
.trans
,
1474 (cmd
.argc
> 0) ? cmd
.argv
[0] : 0,
1475 (cmd
.argc
> 1) ? cmd
.argv
[1] : 0,
1476 (cmd
.argc
> 2) ? cmd
.argv
[2] : 0,
1477 (cmd
.argc
> 3) ? cmd
.argv
[3] : 0,
1478 (cmd
.argc
> 4) ? cmd
.argv
[4] : 0);
1479 usb_mtp_command(s
, &cmd
);
1482 /* not needed as long as the mtp device is read-only */
1483 p
->status
= USB_RET_STALL
;
1488 #ifdef CONFIG_INOTIFY1
1489 if (!QTAILQ_EMPTY(&s
->events
)) {
1490 struct MTPMonEntry
*e
= QTAILQ_LAST(&s
->events
, events
);
1492 int len
= sizeof(container
) + sizeof(uint32_t);
1494 if (p
->iov
.size
< len
) {
1495 trace_usb_mtp_stall(s
->dev
.addr
,
1496 "packet too small to send event");
1497 p
->status
= USB_RET_STALL
;
1501 QTAILQ_REMOVE(&s
->events
, e
, next
);
1502 container
.length
= cpu_to_le32(len
);
1503 container
.type
= cpu_to_le32(TYPE_EVENT
);
1504 container
.code
= cpu_to_le16(e
->event
);
1505 container
.trans
= 0; /* no trans specific events */
1506 handle
= cpu_to_le32(e
->handle
);
1507 usb_packet_copy(p
, &container
, sizeof(container
));
1508 usb_packet_copy(p
, &handle
, sizeof(uint32_t));
1513 p
->status
= USB_RET_NAK
;
1516 trace_usb_mtp_stall(s
->dev
.addr
, "invalid endpoint");
1517 p
->status
= USB_RET_STALL
;
1521 if (p
->actual_length
== 0) {
1522 trace_usb_mtp_nak(s
->dev
.addr
, p
->ep
->nr
);
1523 p
->status
= USB_RET_NAK
;
1526 trace_usb_mtp_xfer(s
->dev
.addr
, p
->ep
->nr
, p
->actual_length
,
1532 static void usb_mtp_realize(USBDevice
*dev
, Error
**errp
)
1534 MTPState
*s
= USB_MTP(dev
);
1536 usb_desc_create_serial(dev
);
1538 QTAILQ_INIT(&s
->objects
);
1539 if (s
->desc
== NULL
) {
1540 if (s
->root
== NULL
) {
1541 error_setg(errp
, "usb-mtp: x-root property must be configured");
1544 s
->desc
= strrchr(s
->root
, '/');
1545 if (s
->desc
&& s
->desc
[0]) {
1546 s
->desc
= g_strdup(s
->desc
+ 1);
1548 s
->desc
= g_strdup("none");
1553 static const VMStateDescription vmstate_usb_mtp
= {
1557 .minimum_version_id
= 1,
1558 .fields
= (VMStateField
[]) {
1559 VMSTATE_USB_DEVICE(dev
, MTPState
),
1560 VMSTATE_END_OF_LIST()
1564 static Property mtp_properties
[] = {
1565 DEFINE_PROP_STRING("x-root", MTPState
, root
),
1566 DEFINE_PROP_STRING("desc", MTPState
, desc
),
1567 DEFINE_PROP_END_OF_LIST(),
1570 static void usb_mtp_class_initfn(ObjectClass
*klass
, void *data
)
1572 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1573 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
1575 uc
->realize
= usb_mtp_realize
;
1576 uc
->product_desc
= "QEMU USB MTP";
1577 uc
->usb_desc
= &desc
;
1578 uc
->cancel_packet
= usb_mtp_cancel_packet
;
1579 uc
->handle_attach
= usb_desc_attach
;
1580 uc
->handle_reset
= usb_mtp_handle_reset
;
1581 uc
->handle_control
= usb_mtp_handle_control
;
1582 uc
->handle_data
= usb_mtp_handle_data
;
1583 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1584 dc
->desc
= "USB Media Transfer Protocol device";
1585 dc
->fw_name
= "mtp";
1586 dc
->vmsd
= &vmstate_usb_mtp
;
1587 dc
->props
= mtp_properties
;
1590 static TypeInfo mtp_info
= {
1591 .name
= TYPE_USB_MTP
,
1592 .parent
= TYPE_USB_DEVICE
,
1593 .instance_size
= sizeof(MTPState
),
1594 .class_init
= usb_mtp_class_initfn
,
1597 static void usb_mtp_register_types(void)
1599 type_register_static(&mtp_info
);
1602 type_init(usb_mtp_register_types
)