From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtlWQ-0000qi-Jd for qemu-devel@nongnu.org; Tue, 03 Nov 2015 19:01:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtlWM-0003Z8-Ay for qemu-devel@nongnu.org; Tue, 03 Nov 2015 19:01:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53588) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtlWM-0003Z2-4E for qemu-devel@nongnu.org; Tue, 03 Nov 2015 19:01:46 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id BD9EAA84 for ; Wed, 4 Nov 2015 00:01:45 +0000 (UTC) From: Bandan Das Date: Tue, 3 Nov 2015 19:00:25 -0500 Message-Id: <1446595225-23608-4-git-send-email-bsd@redhat.com> In-Reply-To: <1446595225-23608-1-git-send-email-bsd@redhat.com> References: <1446595225-23608-1-git-send-email-bsd@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] usb-mtp: add support for basic mtp events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Bandan Das , kraxel@redhat.com When the host polls for events, we check our events qlist and send one event at a time. Also, note that the event packet needs to be sent in one go, so I increased the max packet size to 64. Tested with a linux guest. Signed-off-by: Bandan Das --- hw/usb/dev-mtp.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 79d4ab0..ad33ee8 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -64,6 +64,11 @@ enum mtp_code { /* format codes */ FMT_UNDEFINED_OBJECT = 0x3000, FMT_ASSOCIATION = 0x3001, + + /* event codes */ + EVT_OBJ_ADDED = 0x4002, + EVT_OBJ_REMOVED = 0x4003, + EVT_OBJ_INFO_CHANGED = 0x4007, }; typedef struct { @@ -94,12 +99,6 @@ struct MTPMonEntry { QTAILQ_ENTRY(MTPMonEntry) next; }; -enum inotify_event_type { - CREATE = 1, - DELETE = 2, - MODIFY = 3, -}; - struct MTPControl { uint16_t code; uint32_t trans; @@ -205,7 +204,7 @@ static const USBDescIface desc_iface_full = { },{ .bEndpointAddress = USB_DIR_IN | EP_EVENT, .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = 8, + .wMaxPacketSize = 64, .bInterval = 0x0a, }, } @@ -247,7 +246,7 @@ static const USBDescIface desc_iface_high = { },{ .bEndpointAddress = USB_DIR_IN | EP_EVENT, .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = 8, + .wMaxPacketSize = 64, .bInterval = 0x0a, }, } @@ -526,7 +525,7 @@ static void inotify_watchfn(void *arg) entry = g_new0(MTPMonEntry, 1); entry->handle = s->next_handle; - entry->event = CREATE; + entry->event = EVT_OBJ_ADDED; o = usb_mtp_add_child(s, parent, event->name); if (!o) { error = 1; @@ -551,7 +550,7 @@ static void inotify_watchfn(void *arg) } entry = g_new0(MTPMonEntry, 1); entry->handle = o->handle; - entry->event = DELETE; + entry->event = EVT_OBJ_REMOVED; usb_mtp_object_free(s, o); trace_usb_mtp_inotify_event(s->dev.addr, o->path, event->mask, "Obj Deleted"); @@ -565,7 +564,7 @@ static void inotify_watchfn(void *arg) } entry = g_new0(MTPMonEntry, 1); entry->handle = o->handle; - entry->event = MODIFY; + entry->event = EVT_OBJ_INFO_CHANGED; trace_usb_mtp_inotify_event(s->dev.addr, o->path, event->mask, "Obj Modified"); break; @@ -1313,6 +1312,29 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) } break; case EP_EVENT: + if (!QTAILQ_EMPTY(&s->events)) { + struct MTPMonEntry *e = QTAILQ_LAST(&s->events, events); + uint32_t handle; + int len = sizeof(container) + sizeof(uint32_t); + + if (p->iov.size < len) { + trace_usb_mtp_stall(s->dev.addr, + "packet too small to send event"); + p->status = USB_RET_STALL; + return; + } + + QTAILQ_REMOVE(&s->events, e, next); + container.length = cpu_to_le32(len); + container.type = cpu_to_le32(TYPE_EVENT); + container.code = cpu_to_le16(e->event); + container.trans = 0; /* no trans specific events */ + handle = cpu_to_le32(e->handle); + usb_packet_copy(p, &container, sizeof(container)); + usb_packet_copy(p, &handle, sizeof(uint32_t)); + g_free(e); + return; + } p->status = USB_RET_NAK; return; default: -- 2.4.3