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 "qapi/error.h"
21 #include "qemu/main-loop.h"
24 #include "qemu-common.h"
28 #include "hw/usb/desc.h"
30 /* ----------------------------------------------------------------------- */
32 enum mtp_container_type
{
41 CMD_GET_DEVICE_INFO
= 0x1001,
42 CMD_OPEN_SESSION
= 0x1002,
43 CMD_CLOSE_SESSION
= 0x1003,
44 CMD_GET_STORAGE_IDS
= 0x1004,
45 CMD_GET_STORAGE_INFO
= 0x1005,
46 CMD_GET_NUM_OBJECTS
= 0x1006,
47 CMD_GET_OBJECT_HANDLES
= 0x1007,
48 CMD_GET_OBJECT_INFO
= 0x1008,
49 CMD_GET_OBJECT
= 0x1009,
50 CMD_GET_PARTIAL_OBJECT
= 0x101b,
51 CMD_GET_OBJECT_PROPS_SUPPORTED
= 0x9801,
52 CMD_GET_OBJECT_PROP_DESC
= 0x9802,
53 CMD_GET_OBJECT_PROP_VALUE
= 0x9803,
57 RES_GENERAL_ERROR
= 0x2002,
58 RES_SESSION_NOT_OPEN
= 0x2003,
59 RES_INVALID_TRANSACTION_ID
= 0x2004,
60 RES_OPERATION_NOT_SUPPORTED
= 0x2005,
61 RES_PARAMETER_NOT_SUPPORTED
= 0x2006,
62 RES_INCOMPLETE_TRANSFER
= 0x2007,
63 RES_INVALID_STORAGE_ID
= 0x2008,
64 RES_INVALID_OBJECT_HANDLE
= 0x2009,
65 RES_INVALID_OBJECT_FORMAT_CODE
= 0x200b,
66 RES_SPEC_BY_FORMAT_UNSUPPORTED
= 0x2014,
67 RES_INVALID_PARENT_OBJECT
= 0x201a,
68 RES_INVALID_PARAMETER
= 0x201d,
69 RES_SESSION_ALREADY_OPEN
= 0x201e,
70 RES_INVALID_OBJECT_PROP_CODE
= 0xA801,
73 FMT_UNDEFINED_OBJECT
= 0x3000,
74 FMT_ASSOCIATION
= 0x3001,
77 EVT_OBJ_ADDED
= 0x4002,
78 EVT_OBJ_REMOVED
= 0x4003,
79 EVT_OBJ_INFO_CHANGED
= 0x4007,
81 /* object properties */
82 PROP_STORAGE_ID
= 0xDC01,
83 PROP_OBJECT_FORMAT
= 0xDC02,
84 PROP_OBJECT_COMPRESSED_SIZE
= 0xDC04,
85 PROP_PARENT_OBJECT
= 0xDC0B,
86 PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
= 0xDC41,
91 DATA_TYPE_UINT16
= 0x0004,
92 DATA_TYPE_UINT32
= 0x0006,
93 DATA_TYPE_UINT64
= 0x0008,
94 DATA_TYPE_UINT128
= 0x000a,
95 DATA_TYPE_STRING
= 0xffff,
103 } QEMU_PACKED mtp_container
;
105 /* ----------------------------------------------------------------------- */
107 typedef struct MTPState MTPState
;
108 typedef struct MTPControl MTPControl
;
109 typedef struct MTPData MTPData
;
110 typedef struct MTPObject MTPObject
;
118 #ifdef CONFIG_INOTIFY1
119 typedef struct MTPMonEntry MTPMonEntry
;
125 QTAILQ_ENTRY(MTPMonEntry
) next
;
153 #ifdef CONFIG_INOTIFY1
154 /* inotify watch cookie */
159 QLIST_HEAD(, MTPObject
) children
;
160 QLIST_ENTRY(MTPObject
) list
;
162 QTAILQ_ENTRY(MTPObject
) next
;
175 uint32_t next_handle
;
177 QTAILQ_HEAD(, MTPObject
) objects
;
178 #ifdef CONFIG_INOTIFY1
179 /* inotify descriptor */
181 QTAILQ_HEAD(events
, MTPMonEntry
) events
;
185 #define TYPE_USB_MTP "usb-mtp"
186 #define USB_MTP(obj) OBJECT_CHECK(MTPState, (obj), TYPE_USB_MTP)
188 #define QEMU_STORAGE_ID 0x00010001
190 #define MTP_FLAG_WRITABLE 0
192 #define FLAG_SET(_mtp, _flag) ((_mtp)->flags & (1 << (_flag)))
194 /* ----------------------------------------------------------------------- */
196 #define MTP_MANUFACTURER "QEMU"
197 #define MTP_PRODUCT "QEMU filesharing"
200 STR_MANUFACTURER
= 1,
209 static const USBDescStrings desc_strings
= {
210 [STR_MANUFACTURER
] = MTP_MANUFACTURER
,
211 [STR_PRODUCT
] = MTP_PRODUCT
,
212 [STR_SERIALNUMBER
] = "34617",
214 [STR_CONFIG_FULL
] = "Full speed config (usb 1.1)",
215 [STR_CONFIG_HIGH
] = "High speed config (usb 2.0)",
216 [STR_CONFIG_SUPER
] = "Super speed config (usb 3.0)",
219 static const USBDescIface desc_iface_full
= {
220 .bInterfaceNumber
= 0,
222 .bInterfaceClass
= USB_CLASS_STILL_IMAGE
,
223 .bInterfaceSubClass
= 0x01,
224 .bInterfaceProtocol
= 0x01,
225 .iInterface
= STR_MTP
,
226 .eps
= (USBDescEndpoint
[]) {
228 .bEndpointAddress
= USB_DIR_IN
| EP_DATA_IN
,
229 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
230 .wMaxPacketSize
= 64,
232 .bEndpointAddress
= USB_DIR_OUT
| EP_DATA_OUT
,
233 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
234 .wMaxPacketSize
= 64,
236 .bEndpointAddress
= USB_DIR_IN
| EP_EVENT
,
237 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
238 .wMaxPacketSize
= 64,
244 static const USBDescDevice desc_device_full
= {
246 .bMaxPacketSize0
= 8,
247 .bNumConfigurations
= 1,
248 .confs
= (USBDescConfig
[]) {
251 .bConfigurationValue
= 1,
252 .iConfiguration
= STR_CONFIG_FULL
,
253 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
256 .ifs
= &desc_iface_full
,
261 static const USBDescIface desc_iface_high
= {
262 .bInterfaceNumber
= 0,
264 .bInterfaceClass
= USB_CLASS_STILL_IMAGE
,
265 .bInterfaceSubClass
= 0x01,
266 .bInterfaceProtocol
= 0x01,
267 .iInterface
= STR_MTP
,
268 .eps
= (USBDescEndpoint
[]) {
270 .bEndpointAddress
= USB_DIR_IN
| EP_DATA_IN
,
271 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
272 .wMaxPacketSize
= 512,
274 .bEndpointAddress
= USB_DIR_OUT
| EP_DATA_OUT
,
275 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
276 .wMaxPacketSize
= 512,
278 .bEndpointAddress
= USB_DIR_IN
| EP_EVENT
,
279 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
280 .wMaxPacketSize
= 64,
286 static const USBDescDevice desc_device_high
= {
288 .bMaxPacketSize0
= 64,
289 .bNumConfigurations
= 1,
290 .confs
= (USBDescConfig
[]) {
293 .bConfigurationValue
= 1,
294 .iConfiguration
= STR_CONFIG_HIGH
,
295 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
298 .ifs
= &desc_iface_high
,
303 static const USBDescMSOS desc_msos
= {
304 .CompatibleID
= "MTP",
305 .SelectiveSuspendEnabled
= true,
308 static const USBDesc desc
= {
310 .idVendor
= 0x46f4, /* CRC16() of "QEMU" */
313 .iManufacturer
= STR_MANUFACTURER
,
314 .iProduct
= STR_PRODUCT
,
315 .iSerialNumber
= STR_SERIALNUMBER
,
317 .full
= &desc_device_full
,
318 .high
= &desc_device_high
,
323 /* ----------------------------------------------------------------------- */
325 static MTPObject
*usb_mtp_object_alloc(MTPState
*s
, uint32_t handle
,
326 MTPObject
*parent
, char *name
)
328 MTPObject
*o
= g_new0(MTPObject
, 1);
330 if (name
[0] == '.') {
336 o
->name
= g_strdup(name
);
337 if (parent
== NULL
) {
338 o
->path
= g_strdup(name
);
340 o
->path
= g_strdup_printf("%s/%s", parent
->path
, name
);
343 if (lstat(o
->path
, &o
->stat
) != 0) {
346 if (S_ISREG(o
->stat
.st_mode
)) {
347 o
->format
= FMT_UNDEFINED_OBJECT
;
348 } else if (S_ISDIR(o
->stat
.st_mode
)) {
349 o
->format
= FMT_ASSOCIATION
;
354 if (access(o
->path
, R_OK
) != 0) {
358 trace_usb_mtp_object_alloc(s
->dev
.addr
, o
->handle
, o
->path
);
360 QTAILQ_INSERT_TAIL(&s
->objects
, o
, next
);
370 static void usb_mtp_object_free(MTPState
*s
, MTPObject
*o
)
378 trace_usb_mtp_object_free(s
->dev
.addr
, o
->handle
, o
->path
);
380 QTAILQ_REMOVE(&s
->objects
, o
, next
);
382 QLIST_REMOVE(o
, list
);
383 o
->parent
->nchildren
--;
386 while (!QLIST_EMPTY(&o
->children
)) {
387 iter
= QLIST_FIRST(&o
->children
);
388 usb_mtp_object_free(s
, iter
);
395 static MTPObject
*usb_mtp_object_lookup(MTPState
*s
, uint32_t handle
)
399 QTAILQ_FOREACH(o
, &s
->objects
, next
) {
400 if (o
->handle
== handle
) {
407 static MTPObject
*usb_mtp_add_child(MTPState
*s
, MTPObject
*o
,
411 usb_mtp_object_alloc(s
, s
->next_handle
++, o
, name
);
414 trace_usb_mtp_add_child(s
->dev
.addr
, child
->handle
, child
->path
);
415 QLIST_INSERT_HEAD(&o
->children
, child
, list
);
418 if (child
->format
== FMT_ASSOCIATION
) {
419 QLIST_INIT(&child
->children
);
426 #ifdef CONFIG_INOTIFY1
427 static MTPObject
*usb_mtp_object_lookup_name(MTPObject
*parent
,
432 QLIST_FOREACH(iter
, &parent
->children
, list
) {
433 if (strncmp(iter
->name
, name
, len
) == 0) {
441 static MTPObject
*usb_mtp_object_lookup_wd(MTPState
*s
, int wd
)
445 QTAILQ_FOREACH(iter
, &s
->objects
, next
) {
446 if (iter
->watchfd
== wd
) {
454 static void inotify_watchfn(void *arg
)
458 /* From the man page: atleast one event can be read */
460 char buf
[sizeof(struct inotify_event
) + NAME_MAX
+ 1];
463 bytes
= read(s
->inotifyfd
, buf
, sizeof(buf
));
467 /* Better luck next time */
472 * TODO: Ignore initiator initiated events.
473 * For now we are good because the store is RO
477 struct inotify_event
*event
= (struct inotify_event
*)p
;
479 uint32_t mask
= event
->mask
& (IN_CREATE
| IN_DELETE
|
480 IN_MODIFY
| IN_IGNORED
);
481 MTPObject
*parent
= usb_mtp_object_lookup_wd(s
, event
->wd
);
482 MTPMonEntry
*entry
= NULL
;
485 pos
= pos
+ sizeof(struct inotify_event
) + event
->len
;
494 if (usb_mtp_object_lookup_name
495 (parent
, event
->name
, event
->len
)) {
496 /* Duplicate create event */
499 entry
= g_new0(MTPMonEntry
, 1);
500 entry
->handle
= s
->next_handle
;
501 entry
->event
= EVT_OBJ_ADDED
;
502 o
= usb_mtp_add_child(s
, parent
, event
->name
);
507 o
->watchfd
= watchfd
;
508 trace_usb_mtp_inotify_event(s
->dev
.addr
, event
->name
,
509 event
->mask
, "Obj Added");
514 * The kernel issues a IN_IGNORED event
515 * when a dir containing a watchpoint is
516 * deleted, so we don't have to delete the
519 o
= usb_mtp_object_lookup_name(parent
, event
->name
, event
->len
);
523 entry
= g_new0(MTPMonEntry
, 1);
524 entry
->handle
= o
->handle
;
525 entry
->event
= EVT_OBJ_REMOVED
;
526 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
527 event
->mask
, "Obj Deleted");
528 usb_mtp_object_free(s
, o
);
532 o
= usb_mtp_object_lookup_name(parent
, event
->name
, event
->len
);
536 entry
= g_new0(MTPMonEntry
, 1);
537 entry
->handle
= o
->handle
;
538 entry
->event
= EVT_OBJ_INFO_CHANGED
;
539 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
540 event
->mask
, "Obj Modified");
544 o
= usb_mtp_object_lookup_name(parent
, event
->name
, event
->len
);
545 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
546 event
->mask
, "Obj ignored");
550 fprintf(stderr
, "usb-mtp: failed to parse inotify event\n");
555 QTAILQ_INSERT_HEAD(&s
->events
, entry
, next
);
561 static int usb_mtp_inotify_init(MTPState
*s
)
565 fd
= inotify_init1(IN_NONBLOCK
);
570 QTAILQ_INIT(&s
->events
);
573 qemu_set_fd_handler(fd
, inotify_watchfn
, NULL
, s
);
578 static void usb_mtp_inotify_cleanup(MTPState
*s
)
586 qemu_set_fd_handler(s
->inotifyfd
, NULL
, NULL
, s
);
589 QTAILQ_FOREACH_SAFE(e
, &s
->events
, next
, p
) {
590 QTAILQ_REMOVE(&s
->events
, e
, next
);
595 static int usb_mtp_add_watch(int inotifyfd
, char *path
)
597 uint32_t mask
= IN_CREATE
| IN_DELETE
| IN_MODIFY
|
600 return inotify_add_watch(inotifyfd
, path
, mask
);
604 static void usb_mtp_object_readdir(MTPState
*s
, MTPObject
*o
)
606 struct dirent
*entry
;
609 if (o
->have_children
) {
612 o
->have_children
= true;
614 dir
= opendir(o
->path
);
618 #ifdef CONFIG_INOTIFY1
619 int watchfd
= usb_mtp_add_watch(s
->inotifyfd
, o
->path
);
621 fprintf(stderr
, "usb-mtp: failed to add watch for %s\n", o
->path
);
623 trace_usb_mtp_inotify_event(s
->dev
.addr
, o
->path
,
625 o
->watchfd
= watchfd
;
628 while ((entry
= readdir(dir
)) != NULL
) {
629 usb_mtp_add_child(s
, o
, entry
->d_name
);
634 /* ----------------------------------------------------------------------- */
636 static MTPData
*usb_mtp_data_alloc(MTPControl
*c
)
638 MTPData
*data
= g_new0(MTPData
, 1);
640 data
->code
= c
->code
;
641 data
->trans
= c
->trans
;
647 static void usb_mtp_data_free(MTPData
*data
)
652 if (data
->fd
!= -1) {
659 static void usb_mtp_realloc(MTPData
*data
, uint32_t bytes
)
661 if (data
->length
+ bytes
<= data
->alloc
) {
664 data
->alloc
= (data
->length
+ bytes
+ 0xff) & ~0xff;
665 data
->data
= g_realloc(data
->data
, data
->alloc
);
668 static void usb_mtp_add_u8(MTPData
*data
, uint8_t val
)
670 usb_mtp_realloc(data
, 1);
671 data
->data
[data
->length
++] = val
;
674 static void usb_mtp_add_u16(MTPData
*data
, uint16_t val
)
676 usb_mtp_realloc(data
, 2);
677 data
->data
[data
->length
++] = (val
>> 0) & 0xff;
678 data
->data
[data
->length
++] = (val
>> 8) & 0xff;
681 static void usb_mtp_add_u32(MTPData
*data
, uint32_t val
)
683 usb_mtp_realloc(data
, 4);
684 data
->data
[data
->length
++] = (val
>> 0) & 0xff;
685 data
->data
[data
->length
++] = (val
>> 8) & 0xff;
686 data
->data
[data
->length
++] = (val
>> 16) & 0xff;
687 data
->data
[data
->length
++] = (val
>> 24) & 0xff;
690 static void usb_mtp_add_u64(MTPData
*data
, uint64_t val
)
692 usb_mtp_realloc(data
, 8);
693 data
->data
[data
->length
++] = (val
>> 0) & 0xff;
694 data
->data
[data
->length
++] = (val
>> 8) & 0xff;
695 data
->data
[data
->length
++] = (val
>> 16) & 0xff;
696 data
->data
[data
->length
++] = (val
>> 24) & 0xff;
697 data
->data
[data
->length
++] = (val
>> 32) & 0xff;
698 data
->data
[data
->length
++] = (val
>> 40) & 0xff;
699 data
->data
[data
->length
++] = (val
>> 48) & 0xff;
700 data
->data
[data
->length
++] = (val
>> 56) & 0xff;
703 static void usb_mtp_add_u16_array(MTPData
*data
, uint32_t len
,
704 const uint16_t *vals
)
708 usb_mtp_add_u32(data
, len
);
709 for (i
= 0; i
< len
; i
++) {
710 usb_mtp_add_u16(data
, vals
[i
]);
714 static void usb_mtp_add_u32_array(MTPData
*data
, uint32_t len
,
715 const uint32_t *vals
)
719 usb_mtp_add_u32(data
, len
);
720 for (i
= 0; i
< len
; i
++) {
721 usb_mtp_add_u32(data
, vals
[i
]);
725 static void usb_mtp_add_wstr(MTPData
*data
, const wchar_t *str
)
727 uint32_t len
= wcslen(str
);
731 len
++; /* include terminating L'\0' */
734 usb_mtp_add_u8(data
, len
);
735 for (i
= 0; i
< len
; i
++) {
736 usb_mtp_add_u16(data
, str
[i
]);
740 static void usb_mtp_add_str(MTPData
*data
, const char *str
)
742 uint32_t len
= strlen(str
)+1;
743 wchar_t *wstr
= g_new(wchar_t, len
);
746 ret
= mbstowcs(wstr
, str
, len
);
748 usb_mtp_add_wstr(data
, L
"Oops");
750 usb_mtp_add_wstr(data
, wstr
);
756 static void usb_mtp_add_time(MTPData
*data
, time_t time
)
761 gmtime_r(&time
, &tm
);
762 strftime(buf
, sizeof(buf
), "%Y%m%dT%H%M%S", &tm
);
763 usb_mtp_add_str(data
, buf
);
766 /* ----------------------------------------------------------------------- */
768 static void usb_mtp_queue_result(MTPState
*s
, uint16_t code
, uint32_t trans
,
769 int argc
, uint32_t arg0
, uint32_t arg1
)
771 MTPControl
*c
= g_new0(MTPControl
, 1);
783 assert(s
->result
== NULL
);
787 /* ----------------------------------------------------------------------- */
789 static MTPData
*usb_mtp_get_device_info(MTPState
*s
, MTPControl
*c
)
791 static const uint16_t ops
[] = {
796 CMD_GET_STORAGE_INFO
,
798 CMD_GET_OBJECT_HANDLES
,
801 CMD_GET_PARTIAL_OBJECT
,
802 CMD_GET_OBJECT_PROPS_SUPPORTED
,
803 CMD_GET_OBJECT_PROP_DESC
,
804 CMD_GET_OBJECT_PROP_VALUE
,
806 static const uint16_t fmt
[] = {
807 FMT_UNDEFINED_OBJECT
,
810 MTPData
*d
= usb_mtp_data_alloc(c
);
812 trace_usb_mtp_op_get_device_info(s
->dev
.addr
);
814 usb_mtp_add_u16(d
, 100);
815 usb_mtp_add_u32(d
, 0x00000006);
816 usb_mtp_add_u16(d
, 0x0064);
817 usb_mtp_add_wstr(d
, L
"");
818 usb_mtp_add_u16(d
, 0x0000);
820 usb_mtp_add_u16_array(d
, ARRAY_SIZE(ops
), ops
);
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
, 0, NULL
);
824 usb_mtp_add_u16_array(d
, ARRAY_SIZE(fmt
), fmt
);
826 usb_mtp_add_wstr(d
, L
"" MTP_MANUFACTURER
);
827 usb_mtp_add_wstr(d
, L
"" MTP_PRODUCT
);
828 usb_mtp_add_wstr(d
, L
"0.1");
829 usb_mtp_add_wstr(d
, L
"0123456789abcdef0123456789abcdef");
834 static MTPData
*usb_mtp_get_storage_ids(MTPState
*s
, MTPControl
*c
)
836 static const uint32_t ids
[] = {
839 MTPData
*d
= usb_mtp_data_alloc(c
);
841 trace_usb_mtp_op_get_storage_ids(s
->dev
.addr
);
843 usb_mtp_add_u32_array(d
, ARRAY_SIZE(ids
), ids
);
848 static MTPData
*usb_mtp_get_storage_info(MTPState
*s
, MTPControl
*c
)
850 MTPData
*d
= usb_mtp_data_alloc(c
);
854 trace_usb_mtp_op_get_storage_info(s
->dev
.addr
);
856 if (FLAG_SET(s
, MTP_FLAG_WRITABLE
)) {
857 usb_mtp_add_u16(d
, 0x0003);
858 usb_mtp_add_u16(d
, 0x0002);
859 usb_mtp_add_u16(d
, 0x0000);
861 usb_mtp_add_u16(d
, 0x0001);
862 usb_mtp_add_u16(d
, 0x0002);
863 usb_mtp_add_u16(d
, 0x0001);
866 rc
= statvfs(s
->root
, &buf
);
868 usb_mtp_add_u64(d
, (uint64_t)buf
.f_frsize
* buf
.f_blocks
);
869 usb_mtp_add_u64(d
, (uint64_t)buf
.f_bavail
* buf
.f_blocks
);
870 usb_mtp_add_u32(d
, buf
.f_ffree
);
872 usb_mtp_add_u64(d
, 0xffffffff);
873 usb_mtp_add_u64(d
, 0xffffffff);
874 usb_mtp_add_u32(d
, 0xffffffff);
877 usb_mtp_add_str(d
, s
->desc
);
878 usb_mtp_add_wstr(d
, L
"123456789abcdef");
882 static MTPData
*usb_mtp_get_object_handles(MTPState
*s
, MTPControl
*c
,
885 MTPData
*d
= usb_mtp_data_alloc(c
);
886 uint32_t i
= 0, handles
[o
->nchildren
];
889 trace_usb_mtp_op_get_object_handles(s
->dev
.addr
, o
->handle
, o
->path
);
891 QLIST_FOREACH(iter
, &o
->children
, list
) {
892 handles
[i
++] = iter
->handle
;
894 assert(i
== o
->nchildren
);
895 usb_mtp_add_u32_array(d
, o
->nchildren
, handles
);
900 static MTPData
*usb_mtp_get_object_info(MTPState
*s
, MTPControl
*c
,
903 MTPData
*d
= usb_mtp_data_alloc(c
);
905 trace_usb_mtp_op_get_object_info(s
->dev
.addr
, o
->handle
, o
->path
);
907 usb_mtp_add_u32(d
, QEMU_STORAGE_ID
);
908 usb_mtp_add_u16(d
, o
->format
);
909 usb_mtp_add_u16(d
, 0);
911 if (o
->stat
.st_size
> 0xFFFFFFFF) {
912 usb_mtp_add_u32(d
, 0xFFFFFFFF);
914 usb_mtp_add_u32(d
, o
->stat
.st_size
);
917 usb_mtp_add_u16(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);
923 usb_mtp_add_u32(d
, 0);
926 usb_mtp_add_u32(d
, o
->parent
->handle
);
928 usb_mtp_add_u32(d
, 0);
930 if (o
->format
== FMT_ASSOCIATION
) {
931 usb_mtp_add_u16(d
, 0x0001);
932 usb_mtp_add_u32(d
, 0x00000001);
933 usb_mtp_add_u32(d
, 0);
935 usb_mtp_add_u16(d
, 0);
936 usb_mtp_add_u32(d
, 0);
937 usb_mtp_add_u32(d
, 0);
940 usb_mtp_add_str(d
, o
->name
);
941 usb_mtp_add_time(d
, o
->stat
.st_ctime
);
942 usb_mtp_add_time(d
, o
->stat
.st_mtime
);
943 usb_mtp_add_wstr(d
, L
"");
948 static MTPData
*usb_mtp_get_object(MTPState
*s
, MTPControl
*c
,
951 MTPData
*d
= usb_mtp_data_alloc(c
);
953 trace_usb_mtp_op_get_object(s
->dev
.addr
, o
->handle
, o
->path
);
955 d
->fd
= open(o
->path
, O_RDONLY
);
957 usb_mtp_data_free(d
);
960 d
->length
= o
->stat
.st_size
;
962 d
->data
= g_malloc(d
->alloc
);
966 static MTPData
*usb_mtp_get_partial_object(MTPState
*s
, MTPControl
*c
,
969 MTPData
*d
= usb_mtp_data_alloc(c
);
972 trace_usb_mtp_op_get_partial_object(s
->dev
.addr
, o
->handle
, o
->path
,
973 c
->argv
[1], c
->argv
[2]);
975 d
->fd
= open(o
->path
, O_RDONLY
);
977 usb_mtp_data_free(d
);
982 if (offset
> o
->stat
.st_size
) {
983 offset
= o
->stat
.st_size
;
985 if (lseek(d
->fd
, offset
, SEEK_SET
) < 0) {
986 usb_mtp_data_free(d
);
990 d
->length
= c
->argv
[2];
991 if (d
->length
> o
->stat
.st_size
- offset
) {
992 d
->length
= o
->stat
.st_size
- offset
;
998 static MTPData
*usb_mtp_get_object_props_supported(MTPState
*s
, MTPControl
*c
)
1000 static const uint16_t props
[] = {
1003 PROP_OBJECT_COMPRESSED_SIZE
,
1005 PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
,
1008 MTPData
*d
= usb_mtp_data_alloc(c
);
1009 usb_mtp_add_u16_array(d
, ARRAY_SIZE(props
), props
);
1014 static MTPData
*usb_mtp_get_object_prop_desc(MTPState
*s
, MTPControl
*c
)
1016 MTPData
*d
= usb_mtp_data_alloc(c
);
1017 switch (c
->argv
[0]) {
1018 case PROP_STORAGE_ID
:
1019 usb_mtp_add_u16(d
, PROP_STORAGE_ID
);
1020 usb_mtp_add_u16(d
, DATA_TYPE_UINT32
);
1021 usb_mtp_add_u8(d
, 0x00);
1022 usb_mtp_add_u32(d
, 0x00000000);
1023 usb_mtp_add_u32(d
, 0x00000000);
1024 usb_mtp_add_u8(d
, 0x00);
1026 case PROP_OBJECT_FORMAT
:
1027 usb_mtp_add_u16(d
, PROP_OBJECT_FORMAT
);
1028 usb_mtp_add_u16(d
, DATA_TYPE_UINT16
);
1029 usb_mtp_add_u8(d
, 0x00);
1030 usb_mtp_add_u16(d
, 0x0000);
1031 usb_mtp_add_u32(d
, 0x00000000);
1032 usb_mtp_add_u8(d
, 0x00);
1034 case PROP_OBJECT_COMPRESSED_SIZE
:
1035 usb_mtp_add_u16(d
, PROP_OBJECT_COMPRESSED_SIZE
);
1036 usb_mtp_add_u16(d
, DATA_TYPE_UINT64
);
1037 usb_mtp_add_u8(d
, 0x00);
1038 usb_mtp_add_u64(d
, 0x0000000000000000);
1039 usb_mtp_add_u32(d
, 0x00000000);
1040 usb_mtp_add_u8(d
, 0x00);
1042 case PROP_PARENT_OBJECT
:
1043 usb_mtp_add_u16(d
, PROP_PARENT_OBJECT
);
1044 usb_mtp_add_u16(d
, DATA_TYPE_UINT32
);
1045 usb_mtp_add_u8(d
, 0x00);
1046 usb_mtp_add_u32(d
, 0x00000000);
1047 usb_mtp_add_u32(d
, 0x00000000);
1048 usb_mtp_add_u8(d
, 0x00);
1050 case PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
:
1051 usb_mtp_add_u16(d
, PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
);
1052 usb_mtp_add_u16(d
, DATA_TYPE_UINT128
);
1053 usb_mtp_add_u8(d
, 0x00);
1054 usb_mtp_add_u64(d
, 0x0000000000000000);
1055 usb_mtp_add_u64(d
, 0x0000000000000000);
1056 usb_mtp_add_u32(d
, 0x00000000);
1057 usb_mtp_add_u8(d
, 0x00);
1060 usb_mtp_add_u16(d
, PROP_NAME
);
1061 usb_mtp_add_u16(d
, DATA_TYPE_STRING
);
1062 usb_mtp_add_u8(d
, 0x00);
1063 usb_mtp_add_u8(d
, 0x00);
1064 usb_mtp_add_u32(d
, 0x00000000);
1065 usb_mtp_add_u8(d
, 0x00);
1068 usb_mtp_data_free(d
);
1075 static MTPData
*usb_mtp_get_object_prop_value(MTPState
*s
, MTPControl
*c
,
1078 MTPData
*d
= usb_mtp_data_alloc(c
);
1079 switch (c
->argv
[1]) {
1080 case PROP_STORAGE_ID
:
1081 usb_mtp_add_u32(d
, QEMU_STORAGE_ID
);
1083 case PROP_OBJECT_FORMAT
:
1084 usb_mtp_add_u16(d
, o
->format
);
1086 case PROP_OBJECT_COMPRESSED_SIZE
:
1087 usb_mtp_add_u64(d
, o
->stat
.st_size
);
1089 case PROP_PARENT_OBJECT
:
1090 if (o
->parent
== NULL
) {
1091 usb_mtp_add_u32(d
, 0x00000000);
1093 usb_mtp_add_u32(d
, o
->parent
->handle
);
1096 case PROP_PERSISTENT_UNIQUE_OBJECT_IDENTIFIER
:
1097 /* Should be persistant between sessions,
1098 * but using our objedt ID is "good enough"
1100 usb_mtp_add_u64(d
, 0x0000000000000000);
1101 usb_mtp_add_u64(d
, o
->handle
);
1104 usb_mtp_add_str(d
, o
->name
);
1107 usb_mtp_data_free(d
);
1114 static void usb_mtp_command(MTPState
*s
, MTPControl
*c
)
1116 MTPData
*data_in
= NULL
;
1118 uint32_t nres
= 0, res0
= 0;
1121 if (c
->code
>= CMD_CLOSE_SESSION
&& s
->session
== 0) {
1122 usb_mtp_queue_result(s
, RES_SESSION_NOT_OPEN
,
1127 /* process commands */
1129 case CMD_GET_DEVICE_INFO
:
1130 data_in
= usb_mtp_get_device_info(s
, c
);
1132 case CMD_OPEN_SESSION
:
1134 usb_mtp_queue_result(s
, RES_SESSION_ALREADY_OPEN
,
1135 c
->trans
, 1, s
->session
, 0);
1138 if (c
->argv
[0] == 0) {
1139 usb_mtp_queue_result(s
, RES_INVALID_PARAMETER
,
1143 trace_usb_mtp_op_open_session(s
->dev
.addr
);
1144 s
->session
= c
->argv
[0];
1145 usb_mtp_object_alloc(s
, s
->next_handle
++, NULL
, s
->root
);
1146 #ifdef CONFIG_INOTIFY1
1147 if (usb_mtp_inotify_init(s
)) {
1148 fprintf(stderr
, "usb-mtp: file monitoring init failed\n");
1152 case CMD_CLOSE_SESSION
:
1153 trace_usb_mtp_op_close_session(s
->dev
.addr
);
1156 #ifdef CONFIG_INOTIFY1
1157 usb_mtp_inotify_cleanup(s
);
1159 usb_mtp_object_free(s
, QTAILQ_FIRST(&s
->objects
));
1160 assert(QTAILQ_EMPTY(&s
->objects
));
1162 case CMD_GET_STORAGE_IDS
:
1163 data_in
= usb_mtp_get_storage_ids(s
, c
);
1165 case CMD_GET_STORAGE_INFO
:
1166 if (c
->argv
[0] != QEMU_STORAGE_ID
&&
1167 c
->argv
[0] != 0xffffffff) {
1168 usb_mtp_queue_result(s
, RES_INVALID_STORAGE_ID
,
1172 data_in
= usb_mtp_get_storage_info(s
, c
);
1174 case CMD_GET_NUM_OBJECTS
:
1175 case CMD_GET_OBJECT_HANDLES
:
1176 if (c
->argv
[0] != QEMU_STORAGE_ID
&&
1177 c
->argv
[0] != 0xffffffff) {
1178 usb_mtp_queue_result(s
, RES_INVALID_STORAGE_ID
,
1182 if (c
->argv
[1] != 0x00000000) {
1183 usb_mtp_queue_result(s
, RES_SPEC_BY_FORMAT_UNSUPPORTED
,
1187 if (c
->argv
[2] == 0x00000000 ||
1188 c
->argv
[2] == 0xffffffff) {
1189 o
= QTAILQ_FIRST(&s
->objects
);
1191 o
= usb_mtp_object_lookup(s
, c
->argv
[2]);
1194 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1198 if (o
->format
!= FMT_ASSOCIATION
) {
1199 usb_mtp_queue_result(s
, RES_INVALID_PARENT_OBJECT
,
1203 usb_mtp_object_readdir(s
, o
);
1204 if (c
->code
== CMD_GET_NUM_OBJECTS
) {
1205 trace_usb_mtp_op_get_num_objects(s
->dev
.addr
, o
->handle
, o
->path
);
1207 res0
= o
->nchildren
;
1209 data_in
= usb_mtp_get_object_handles(s
, c
, o
);
1212 case CMD_GET_OBJECT_INFO
:
1213 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1215 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1219 data_in
= usb_mtp_get_object_info(s
, c
, o
);
1221 case CMD_GET_OBJECT
:
1222 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1224 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1228 if (o
->format
== FMT_ASSOCIATION
) {
1229 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1233 data_in
= usb_mtp_get_object(s
, c
, o
);
1234 if (data_in
== NULL
) {
1235 usb_mtp_queue_result(s
, RES_GENERAL_ERROR
,
1240 case CMD_GET_PARTIAL_OBJECT
:
1241 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1243 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1247 if (o
->format
== FMT_ASSOCIATION
) {
1248 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1252 data_in
= usb_mtp_get_partial_object(s
, c
, o
);
1253 if (data_in
== NULL
) {
1254 usb_mtp_queue_result(s
, RES_GENERAL_ERROR
,
1259 res0
= data_in
->length
;
1261 case CMD_GET_OBJECT_PROPS_SUPPORTED
:
1262 if (c
->argv
[0] != FMT_UNDEFINED_OBJECT
&&
1263 c
->argv
[0] != FMT_ASSOCIATION
) {
1264 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_FORMAT_CODE
,
1268 data_in
= usb_mtp_get_object_props_supported(s
, c
);
1270 case CMD_GET_OBJECT_PROP_DESC
:
1271 if (c
->argv
[1] != FMT_UNDEFINED_OBJECT
&&
1272 c
->argv
[1] != FMT_ASSOCIATION
) {
1273 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_FORMAT_CODE
,
1277 data_in
= usb_mtp_get_object_prop_desc(s
, c
);
1278 if (data_in
== NULL
) {
1279 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_PROP_CODE
,
1284 case CMD_GET_OBJECT_PROP_VALUE
:
1285 o
= usb_mtp_object_lookup(s
, c
->argv
[0]);
1287 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_HANDLE
,
1291 data_in
= usb_mtp_get_object_prop_value(s
, c
, o
);
1292 if (data_in
== NULL
) {
1293 usb_mtp_queue_result(s
, RES_INVALID_OBJECT_PROP_CODE
,
1299 trace_usb_mtp_op_unknown(s
->dev
.addr
, c
->code
);
1300 usb_mtp_queue_result(s
, RES_OPERATION_NOT_SUPPORTED
,
1305 /* return results on success */
1307 assert(s
->data_in
== NULL
);
1308 s
->data_in
= data_in
;
1310 usb_mtp_queue_result(s
, RES_OK
, c
->trans
, nres
, res0
, 0);
1313 /* ----------------------------------------------------------------------- */
1315 static void usb_mtp_handle_reset(USBDevice
*dev
)
1317 MTPState
*s
= USB_MTP(dev
);
1319 trace_usb_mtp_reset(s
->dev
.addr
);
1321 #ifdef CONFIG_INOTIFY1
1322 usb_mtp_inotify_cleanup(s
);
1324 usb_mtp_object_free(s
, QTAILQ_FIRST(&s
->objects
));
1326 usb_mtp_data_free(s
->data_in
);
1328 usb_mtp_data_free(s
->data_out
);
1334 static void usb_mtp_handle_control(USBDevice
*dev
, USBPacket
*p
,
1335 int request
, int value
, int index
,
1336 int length
, uint8_t *data
)
1340 ret
= usb_desc_handle_control(dev
, p
, request
, value
, index
, length
, data
);
1345 trace_usb_mtp_stall(dev
->addr
, "unknown control request");
1346 p
->status
= USB_RET_STALL
;
1349 static void usb_mtp_cancel_packet(USBDevice
*dev
, USBPacket
*p
)
1351 /* we don't use async packets, so this should never be called */
1352 fprintf(stderr
, "%s\n", __func__
);
1355 static void usb_mtp_handle_data(USBDevice
*dev
, USBPacket
*p
)
1357 MTPState
*s
= USB_MTP(dev
);
1359 mtp_container container
;
1363 switch (p
->ep
->nr
) {
1365 if (s
->data_out
!= NULL
) {
1367 trace_usb_mtp_stall(s
->dev
.addr
, "awaiting data-out");
1368 p
->status
= USB_RET_STALL
;
1371 if (p
->iov
.size
< sizeof(container
)) {
1372 trace_usb_mtp_stall(s
->dev
.addr
, "packet too small");
1373 p
->status
= USB_RET_STALL
;
1376 if (s
->data_in
!= NULL
) {
1377 MTPData
*d
= s
->data_in
;
1378 uint64_t dlen
= d
->length
- d
->offset
;
1380 trace_usb_mtp_data_in(s
->dev
.addr
, d
->trans
, d
->length
);
1381 if (d
->length
+ sizeof(container
) > 0xFFFFFFFF) {
1382 container
.length
= cpu_to_le32(0xFFFFFFFF);
1385 cpu_to_le32(d
->length
+ sizeof(container
));
1387 container
.type
= cpu_to_le16(TYPE_DATA
);
1388 container
.code
= cpu_to_le16(d
->code
);
1389 container
.trans
= cpu_to_le32(d
->trans
);
1390 usb_packet_copy(p
, &container
, sizeof(container
));
1392 if (dlen
> p
->iov
.size
- sizeof(container
)) {
1393 dlen
= p
->iov
.size
- sizeof(container
);
1396 if (dlen
> p
->iov
.size
) {
1401 usb_packet_copy(p
, d
->data
+ d
->offset
, dlen
);
1403 if (d
->alloc
< p
->iov
.size
) {
1404 d
->alloc
= p
->iov
.size
;
1405 d
->data
= g_realloc(d
->data
, d
->alloc
);
1407 rc
= read(d
->fd
, d
->data
, dlen
);
1409 memset(d
->data
, 0, dlen
);
1410 s
->result
->code
= RES_INCOMPLETE_TRANSFER
;
1412 usb_packet_copy(p
, d
->data
, dlen
);
1415 if (d
->offset
== d
->length
) {
1416 usb_mtp_data_free(s
->data_in
);
1419 } else if (s
->result
!= NULL
) {
1420 MTPControl
*r
= s
->result
;
1421 int length
= sizeof(container
) + r
->argc
* sizeof(uint32_t);
1422 if (r
->code
== RES_OK
) {
1423 trace_usb_mtp_success(s
->dev
.addr
, r
->trans
,
1424 (r
->argc
> 0) ? r
->argv
[0] : 0,
1425 (r
->argc
> 1) ? r
->argv
[1] : 0);
1427 trace_usb_mtp_error(s
->dev
.addr
, r
->code
, r
->trans
,
1428 (r
->argc
> 0) ? r
->argv
[0] : 0,
1429 (r
->argc
> 1) ? r
->argv
[1] : 0);
1431 container
.length
= cpu_to_le32(length
);
1432 container
.type
= cpu_to_le16(TYPE_RESPONSE
);
1433 container
.code
= cpu_to_le16(r
->code
);
1434 container
.trans
= cpu_to_le32(r
->trans
);
1435 for (i
= 0; i
< r
->argc
; i
++) {
1436 params
[i
] = cpu_to_le32(r
->argv
[i
]);
1438 usb_packet_copy(p
, &container
, sizeof(container
));
1439 usb_packet_copy(p
, ¶ms
, length
- sizeof(container
));
1445 if (p
->iov
.size
< sizeof(container
)) {
1446 trace_usb_mtp_stall(s
->dev
.addr
, "packet too small");
1447 p
->status
= USB_RET_STALL
;
1450 usb_packet_copy(p
, &container
, sizeof(container
));
1451 switch (le16_to_cpu(container
.type
)) {
1453 if (s
->data_in
|| s
->data_out
|| s
->result
) {
1454 trace_usb_mtp_stall(s
->dev
.addr
, "transaction inflight");
1455 p
->status
= USB_RET_STALL
;
1458 cmd
.code
= le16_to_cpu(container
.code
);
1459 cmd
.argc
= (le32_to_cpu(container
.length
) - sizeof(container
))
1461 cmd
.trans
= le32_to_cpu(container
.trans
);
1462 if (cmd
.argc
> ARRAY_SIZE(cmd
.argv
)) {
1463 cmd
.argc
= ARRAY_SIZE(cmd
.argv
);
1465 if (p
->iov
.size
< sizeof(container
) + cmd
.argc
* sizeof(uint32_t)) {
1466 trace_usb_mtp_stall(s
->dev
.addr
, "packet too small");
1467 p
->status
= USB_RET_STALL
;
1470 usb_packet_copy(p
, ¶ms
, cmd
.argc
* sizeof(uint32_t));
1471 for (i
= 0; i
< cmd
.argc
; i
++) {
1472 cmd
.argv
[i
] = le32_to_cpu(params
[i
]);
1474 trace_usb_mtp_command(s
->dev
.addr
, cmd
.code
, cmd
.trans
,
1475 (cmd
.argc
> 0) ? cmd
.argv
[0] : 0,
1476 (cmd
.argc
> 1) ? cmd
.argv
[1] : 0,
1477 (cmd
.argc
> 2) ? cmd
.argv
[2] : 0,
1478 (cmd
.argc
> 3) ? cmd
.argv
[3] : 0,
1479 (cmd
.argc
> 4) ? cmd
.argv
[4] : 0);
1480 usb_mtp_command(s
, &cmd
);
1483 /* not needed as long as the mtp device is read-only */
1484 p
->status
= USB_RET_STALL
;
1489 #ifdef CONFIG_INOTIFY1
1490 if (!QTAILQ_EMPTY(&s
->events
)) {
1491 struct MTPMonEntry
*e
= QTAILQ_LAST(&s
->events
, events
);
1493 int len
= sizeof(container
) + sizeof(uint32_t);
1495 if (p
->iov
.size
< len
) {
1496 trace_usb_mtp_stall(s
->dev
.addr
,
1497 "packet too small to send event");
1498 p
->status
= USB_RET_STALL
;
1502 QTAILQ_REMOVE(&s
->events
, e
, next
);
1503 container
.length
= cpu_to_le32(len
);
1504 container
.type
= cpu_to_le32(TYPE_EVENT
);
1505 container
.code
= cpu_to_le16(e
->event
);
1506 container
.trans
= 0; /* no trans specific events */
1507 handle
= cpu_to_le32(e
->handle
);
1508 usb_packet_copy(p
, &container
, sizeof(container
));
1509 usb_packet_copy(p
, &handle
, sizeof(uint32_t));
1514 p
->status
= USB_RET_NAK
;
1517 trace_usb_mtp_stall(s
->dev
.addr
, "invalid endpoint");
1518 p
->status
= USB_RET_STALL
;
1522 if (p
->actual_length
== 0) {
1523 trace_usb_mtp_nak(s
->dev
.addr
, p
->ep
->nr
);
1524 p
->status
= USB_RET_NAK
;
1527 trace_usb_mtp_xfer(s
->dev
.addr
, p
->ep
->nr
, p
->actual_length
,
1533 static void usb_mtp_realize(USBDevice
*dev
, Error
**errp
)
1535 MTPState
*s
= USB_MTP(dev
);
1537 usb_desc_create_serial(dev
);
1539 QTAILQ_INIT(&s
->objects
);
1540 if (s
->desc
== NULL
) {
1541 if (s
->root
== NULL
) {
1542 error_setg(errp
, "usb-mtp: x-root property must be configured");
1545 s
->desc
= strrchr(s
->root
, '/');
1546 if (s
->desc
&& s
->desc
[0]) {
1547 s
->desc
= g_strdup(s
->desc
+ 1);
1549 s
->desc
= g_strdup("none");
1554 static const VMStateDescription vmstate_usb_mtp
= {
1558 .minimum_version_id
= 1,
1559 .fields
= (VMStateField
[]) {
1560 VMSTATE_USB_DEVICE(dev
, MTPState
),
1561 VMSTATE_END_OF_LIST()
1565 static Property mtp_properties
[] = {
1566 DEFINE_PROP_STRING("x-root", MTPState
, root
),
1567 DEFINE_PROP_STRING("desc", MTPState
, desc
),
1568 DEFINE_PROP_END_OF_LIST(),
1571 static void usb_mtp_class_initfn(ObjectClass
*klass
, void *data
)
1573 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1574 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
1576 uc
->realize
= usb_mtp_realize
;
1577 uc
->product_desc
= "QEMU USB MTP";
1578 uc
->usb_desc
= &desc
;
1579 uc
->cancel_packet
= usb_mtp_cancel_packet
;
1580 uc
->handle_attach
= usb_desc_attach
;
1581 uc
->handle_reset
= usb_mtp_handle_reset
;
1582 uc
->handle_control
= usb_mtp_handle_control
;
1583 uc
->handle_data
= usb_mtp_handle_data
;
1584 dc
->fw_name
= "mtp";
1585 dc
->vmsd
= &vmstate_usb_mtp
;
1586 dc
->props
= mtp_properties
;
1589 static TypeInfo mtp_info
= {
1590 .name
= TYPE_USB_MTP
,
1591 .parent
= TYPE_USB_DEVICE
,
1592 .instance_size
= sizeof(MTPState
),
1593 .class_init
= usb_mtp_class_initfn
,
1596 static void usb_mtp_register_types(void)
1598 type_register_static(&mtp_info
);
1601 type_init(usb_mtp_register_types
)