From: Bandan Das <bsd@redhat.com>
To: qemu-devel@nongnu.org
Cc: Bandan Das <bsd@redhat.com>, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 3/3] usb-mtp: add support for basic mtp events
Date: Tue, 3 Nov 2015 19:00:25 -0500 [thread overview]
Message-ID: <1446595225-23608-4-git-send-email-bsd@redhat.com> (raw)
In-Reply-To: <1446595225-23608-1-git-send-email-bsd@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 <bsd@redhat.com>
---
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
next prev parent reply other threads:[~2015-11-04 0:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 0:00 [Qemu-devel] [PATCH 0/3] usb-mtp events support Bandan Das
2015-11-04 0:00 ` [Qemu-devel] [PATCH 1/3] usb-mtp: use a list for keeping track of children Bandan Das
2015-11-05 8:24 ` Gerd Hoffmann
2015-11-05 21:23 ` Bandan Das
2015-11-04 0:00 ` [Qemu-devel] [PATCH 2/3] usb-mtp: Add support for inotify based file monitoring Bandan Das
2015-11-05 8:37 ` Gerd Hoffmann
2015-11-05 21:28 ` Bandan Das
2015-11-05 8:49 ` Gerd Hoffmann
2015-11-09 23:12 ` Bandan Das
2015-11-09 23:28 ` Bandan Das
2015-11-12 8:16 ` Gerd Hoffmann
2015-11-12 22:40 ` Bandan Das
2015-11-13 8:08 ` Gerd Hoffmann
2015-11-05 8:49 ` Gerd Hoffmann
2015-11-09 23:13 ` Bandan Das
2015-11-04 0:00 ` Bandan Das [this message]
2015-11-05 8:41 ` [Qemu-devel] [PATCH 3/3] usb-mtp: add support for basic mtp events Gerd Hoffmann
2015-11-05 21:30 ` Bandan Das
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1446595225-23608-4-git-send-email-bsd@redhat.com \
--to=bsd@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).