1ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood/*
2ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * Gadget Function Driver for MTP
3ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood *
4ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * Copyright (C) 2010 Google, Inc.
5ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * Author: Mike Lockwood <lockwood@android.com>
6ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood *
7ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * This software is licensed under the terms of the GNU General Public
8ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * License version 2, as published by the Free Software Foundation, and
9ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * may be copied, distributed, and modified under those terms.
10ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood *
11ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * This program is distributed in the hope that it will be useful,
12ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * but WITHOUT ANY WARRANTY; without even the implied warranty of
13ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * GNU General Public License for more details.
15ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood *
16ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood */
17ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
18ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood#ifndef __LINUX_USB_F_MTP_H
19ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood#define __LINUX_USB_F_MTP_H
20ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
21f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood#ifdef __KERNEL__
22ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
23f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwoodstruct mtp_data_header {
24f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	/* length of packet, including this header */
25f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	uint32_t	length;
26f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	/* container type (2 for data packet) */
27f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	uint16_t	type;
28f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	/* MTP command code */
29f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	uint16_t    command;
30f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	/* MTP transaction ID */
31f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	uint32_t	transaction_id;
32f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood};
33f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood
34f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood#endif /* __KERNEL__ */
35ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
36ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwoodstruct mtp_file_range {
37ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	/* file descriptor for file to transfer */
38ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	int			fd;
39ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	/* offset in file for start of transfer */
40ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	loff_t  	offset;
41ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	/* number of bytes to transfer */
420dc7b51382fdf0fd9baaf2708324a7fd69dd8ef4Mike Lockwood	int64_t		length;
43f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	/* MTP command ID for data header,
44f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	 * used only for MTP_SEND_FILE_WITH_HEADER
45f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	 */
46f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	uint16_t	command;
47f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	/* MTP transaction ID for data header,
48f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	 * used only for MTP_SEND_FILE_WITH_HEADER
49f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	 */
50f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood	uint32_t	transaction_id;
51ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood};
52ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
53ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwoodstruct mtp_event {
54ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	/* size of the event */
55ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	size_t		length;
56ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	/* event data to send */
57ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood	void  		*data;
58ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood};
59ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
60ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood/* Sends the specified file range to the host */
61ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood#define MTP_SEND_FILE              _IOW('M', 0, struct mtp_file_range)
62ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood/* Receives data from the host and writes it to a file.
63ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood * The file is created if it does not exist.
64ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood */
65ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood#define MTP_RECEIVE_FILE           _IOW('M', 1, struct mtp_file_range)
66ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood/* Sends an event to the host via the interrupt endpoint */
67ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood#define MTP_SEND_EVENT             _IOW('M', 3, struct mtp_event)
68f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood/* Sends the specified file range to the host,
69f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood * with a 12 byte MTP data packet header at the beginning.
70f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood */
71f9686350bd4ed98998f0a0e6184e5d292d42704eMike Lockwood#define MTP_SEND_FILE_WITH_HEADER  _IOW('M', 4, struct mtp_file_range)
72ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood
73ef379ffdaf931ffc4884b84703ce4906a987b559Mike Lockwood#endif /* __LINUX_USB_F_MTP_H */
74