mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
usb: gadget: mtp: Add MTP/PTP function
USB gadget function driver used by the Android framework to implement the MTP and PTP protocols. It creates a character device that provides an interface for fast transfer of files and supports transferring files greater than 4GB. Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
parent
1e8ce155ca
commit
f0fbc48125
3 changed files with 1424 additions and 0 deletions
|
@ -45,6 +45,7 @@
|
|||
#include "f_mass_storage.c"
|
||||
#include "u_serial.c"
|
||||
#include "f_acm.c"
|
||||
#include "f_mtp.c"
|
||||
#define USB_ETH_RNDIS y
|
||||
#include "f_rndis.c"
|
||||
#include "rndis.c"
|
||||
|
@ -264,6 +265,69 @@ static struct android_usb_function acm_function = {
|
|||
};
|
||||
|
||||
|
||||
static int
|
||||
mtp_function_init(struct android_usb_function *f,
|
||||
struct usb_composite_dev *cdev)
|
||||
{
|
||||
return mtp_setup();
|
||||
}
|
||||
|
||||
static void mtp_function_cleanup(struct android_usb_function *f)
|
||||
{
|
||||
mtp_cleanup();
|
||||
}
|
||||
|
||||
static int
|
||||
mtp_function_bind_config(struct android_usb_function *f,
|
||||
struct usb_configuration *c)
|
||||
{
|
||||
return mtp_bind_config(c, false);
|
||||
}
|
||||
|
||||
static int
|
||||
ptp_function_init(struct android_usb_function *f,
|
||||
struct usb_composite_dev *cdev)
|
||||
{
|
||||
/* nothing to do - initialization is handled by mtp_function_init */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ptp_function_cleanup(struct android_usb_function *f)
|
||||
{
|
||||
/* nothing to do - cleanup is handled by mtp_function_cleanup */
|
||||
}
|
||||
|
||||
static int
|
||||
ptp_function_bind_config(struct android_usb_function *f,
|
||||
struct usb_configuration *c)
|
||||
{
|
||||
return mtp_bind_config(c, true);
|
||||
}
|
||||
|
||||
static int mtp_function_ctrlrequest(struct android_usb_function *f,
|
||||
struct usb_composite_dev *cdev,
|
||||
const struct usb_ctrlrequest *c)
|
||||
{
|
||||
return mtp_ctrlrequest(cdev, c);
|
||||
}
|
||||
|
||||
static struct android_usb_function mtp_function = {
|
||||
.name = "mtp",
|
||||
.init = mtp_function_init,
|
||||
.cleanup = mtp_function_cleanup,
|
||||
.bind_config = mtp_function_bind_config,
|
||||
.ctrlrequest = mtp_function_ctrlrequest,
|
||||
};
|
||||
|
||||
/* PTP function is same as MTP with slightly different interface descriptor */
|
||||
static struct android_usb_function ptp_function = {
|
||||
.name = "ptp",
|
||||
.init = ptp_function_init,
|
||||
.cleanup = ptp_function_cleanup,
|
||||
.bind_config = ptp_function_bind_config,
|
||||
};
|
||||
|
||||
|
||||
struct rndis_function_config {
|
||||
u8 ethaddr[ETH_ALEN];
|
||||
u32 vendorID;
|
||||
|
@ -543,6 +607,8 @@ static struct android_usb_function mass_storage_function = {
|
|||
|
||||
static struct android_usb_function *supported_functions[] = {
|
||||
&acm_function,
|
||||
&mtp_function,
|
||||
&ptp_function,
|
||||
&rndis_function,
|
||||
&mass_storage_function,
|
||||
NULL
|
||||
|
|
1283
drivers/usb/gadget/f_mtp.c
Normal file
1283
drivers/usb/gadget/f_mtp.c
Normal file
File diff suppressed because it is too large
Load diff
75
include/linux/usb/f_mtp.h
Normal file
75
include/linux/usb/f_mtp.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Gadget Function Driver for MTP
|
||||
*
|
||||
* Copyright (C) 2010 Google, Inc.
|
||||
* Author: Mike Lockwood <lockwood@android.com>
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_USB_F_MTP_H
|
||||
#define __LINUX_USB_F_MTP_H
|
||||
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
struct mtp_data_header {
|
||||
/* length of packet, including this header */
|
||||
uint32_t length;
|
||||
/* container type (2 for data packet) */
|
||||
uint16_t type;
|
||||
/* MTP command code */
|
||||
uint16_t command;
|
||||
/* MTP transaction ID */
|
||||
uint32_t transaction_id;
|
||||
};
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
struct mtp_file_range {
|
||||
/* file descriptor for file to transfer */
|
||||
int fd;
|
||||
/* offset in file for start of transfer */
|
||||
loff_t offset;
|
||||
/* number of bytes to transfer */
|
||||
int64_t length;
|
||||
/* MTP command ID for data header,
|
||||
* used only for MTP_SEND_FILE_WITH_HEADER
|
||||
*/
|
||||
uint16_t command;
|
||||
/* MTP transaction ID for data header,
|
||||
* used only for MTP_SEND_FILE_WITH_HEADER
|
||||
*/
|
||||
uint32_t transaction_id;
|
||||
};
|
||||
|
||||
struct mtp_event {
|
||||
/* size of the event */
|
||||
size_t length;
|
||||
/* event data to send */
|
||||
void *data;
|
||||
};
|
||||
|
||||
/* Sends the specified file range to the host */
|
||||
#define MTP_SEND_FILE _IOW('M', 0, struct mtp_file_range)
|
||||
/* Receives data from the host and writes it to a file.
|
||||
* The file is created if it does not exist.
|
||||
*/
|
||||
#define MTP_RECEIVE_FILE _IOW('M', 1, struct mtp_file_range)
|
||||
/* Sends an event to the host via the interrupt endpoint */
|
||||
#define MTP_SEND_EVENT _IOW('M', 3, struct mtp_event)
|
||||
/* Sends the specified file range to the host,
|
||||
* with a 12 byte MTP data packet header at the beginning.
|
||||
*/
|
||||
#define MTP_SEND_FILE_WITH_HEADER _IOW('M', 4, struct mtp_file_range)
|
||||
|
||||
#endif /* __LINUX_USB_F_MTP_H */
|
Loading…
Reference in a new issue