QEMU AS A USB MTP RESPONDER Bandan Das <bsd@redhat.com> KVM - - PowerPoint PPT Presentation

qemu as a usb mtp responder
SMART_READER_LITE
LIVE PREVIEW

QEMU AS A USB MTP RESPONDER Bandan Das <bsd@redhat.com> KVM - - PowerPoint PPT Presentation

QEMU AS A USB MTP RESPONDER Bandan Das <bsd@redhat.com> KVM Forum 2016 1 . 1 MULTIPLE WAYS TO SHARE FOLDERS, SUCH AS: Network based - NFS/Samba/SSHFS Device based Virtio - 9pfs, virtio-serial usb-mtp 2 . 1 ADVANTAGES/DISADVANTAGES


slide-1
SLIDE 1

1 . 1

QEMU AS A USB MTP RESPONDER

Bandan Das <bsd@redhat.com> KVM Forum 2016

slide-2
SLIDE 2

2 . 1

MULTIPLE WAYS TO SHARE FOLDERS, SUCH AS:

Network based - NFS/Samba/SSHFS Device based Virtio - 9pfs, virtio-serial usb-mtp

slide-3
SLIDE 3

2 . 2

ADVANTAGES/DISADVANTAGES

Conguration Is there a rewall ? Availability of services and support Does guest support this device ? Present usb-mtp as another option More options = good ?

slide-4
SLIDE 4

3 . 1

MEDIA TRANSFER PROTOCOL

Introduced by Microsoft as an extension to Picture Transfer Protocol (PTP) What is PTP ? Protocol for transferring digital images from cameras Application layer protocol New names : Initiator (Client), Responder (Server) Atomic operations, controlled by the server One operation at a time

slide-5
SLIDE 5

4 . 1

MEDIA TRANSFER PROTOCOL

Limited le operations support Supports many transport layers (TCP/IP, Firewire) although USB is common USB device class Supports DRM Good adoption - Android, Windows, Linux Plug and Play in most cases!

slide-6
SLIDE 6

5 . 1

MTP VS USB MASS STORAGE

Storage still in control of the device File corruption is minimized Interesting tidbit: Default in Android Let's Android not having to use VFAT Prevents OEM from providing users with little application space

slide-7
SLIDE 7

6 . 1

MTP HIGH LEVEL WORKFLOW

Device connected Transport layer discovery Device information/OpenSession Device capability, name etc List contents Object handles Object properties such as le size Send object metadata Object Exchange Request Response

slide-8
SLIDE 8

7 . 1

QEMU AND MTP

Exposed to the guest as a USB device Example usage: One le operation at a time Supports notication of le changes to the guest Supports > 4G les No write support yet (Copy to device)

... -usb -device usb-mtp,x-root=usbdrive,desc=mtp-share

slide-9
SLIDE 9

8 . 1

THE TRANSPORT LAYER

MTP runs on top of USB USB communication is through endpoints Each endpoint is a data pipe One control endpoint IN endpoints (device -> host, or responder to initiator) OUT endpoints (host-> device, or initiator to responder) Types of endpoints Control Bulk (Storage data) Isochronous (Streaming data) Interrupts (IN endpoint, host polls this endpoint)

slide-10
SLIDE 10

9 . 1

A LOOK AT THE DATA STRUCTURES

/* Device structure corresponding to OpenSession */ struct MTPState { USBDevice dev; ... MTPData *data_in; MTPData *data_out; MTPControl *result; ... #ifdef CONFIG_INOTIFY1 /* inotify descriptor */ int inotifyfd; QTAILQ_HEAD(events, MTPMonEntry) events; #endif } ... /* Response Dataset from Responder to Initiator */ struct MTPData { uint16_t code; uint32_t trans; ... }

slide-11
SLIDE 11

10 . 1

A LOOK AT THE DATA STRUCTURES

/* * Request Dataset from Initiator to Responder * Formatted by usb-mtp */ struct MTPControl { uint16_t code; uint32_t trans; int argc; uint32_t argv[5]; } ... /* Struct that defines contents */ struct MTPObject { uint32_t handle; uint16_t format; char *name; ... }

slide-12
SLIDE 12

11 . 1

USB AND MTP INTERACTION

static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) { ... /* Responses from device, including data transfers, error propagation */ case EP_DATA_IN: /* Requests from host */ case EP_DATA_OUT: /* Events such as file change notifications */ case EP_EVENT:

slide-13
SLIDE 13

12 . 1

MTP IMPLEMENTATION INTERNALS

Object Enumeration Notication changes Data transfer File Operations - Write/Copy/Delete etc.

slide-14
SLIDE 14

13 . 1

OBJECT ENUMERATION

Initiator sets up a "MTPControl" packet with argv[ 2 ] = 0 or 0xffffffff Initiator sends CMD_GET_OBJECT_HANDLES Responder does sanity checks on MTPControl packet Responder does readdir() on root folder and lls MTPObject structs recursively Responder sends a MTPData packet with the MTPObject uint32_t handles array

slide-15
SLIDE 15

14 . 1

DATA TRANSFER

Initiator sends CMD_GET_OBJECT_INFO (Optional) Responder replies with a MTPData packet with object details such as name, size Initiator sends CMD_GET_OBJECT with MTPControl argv[ 0 ] set to the handle Responder does sanity checks on object handle and looks up the entry Responder reads le and lls up a MTPData packet Responder keeps track of offset if size > usb payload

slide-16
SLIDE 16

15 . 1

NOTIFICATION CHANGES (EP_EVENT)

Convention: device interrupts the host when it needs attention With USB, host polls for events Events are propagated when the host polls the interrupt endpoint Uses inotify (only works with Linux hosts) Register inotify handlers to all les in the folders Call object enumeration when new le is added Store inotify events When host (Initiator) polls this EP, deliver one event at a time

slide-17
SLIDE 17

16 . 1

MTP WRITE

MTP does not support edit/write directly Host(Initiator) can copy le, edit and copy it back Or create a new le Support for SendObjectInfo that sends a ObjectInfo dataset (I->R) ObjectInfo sanity checks detremine if device can accept the object Support for SendObject that follows the above

slide-18
SLIDE 18

17 . 1

OUTREACHY INTERNSHIP PROJECT

Isaac Lozano, adding features and xing bugs Adding support for > 4G le transfers Support for Device properties Microsoft specic data elds Not mentioned in spec - conventional values Adding write support

slide-19
SLIDE 19

18 . 1

TODO ITEMS

Adding asynchronous operations Support for multiple sessions Performance audit, synchronous operations eats up CPU Support all MTP le operations - Write/Move/Delete/Copy etc. Testing with different guest congurations

slide-20
SLIDE 20

19 . 1

THANK YOU

Questions ?