Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9ff27a3 authored by Azhar Shaikh's avatar Azhar Shaikh
Browse files

usb: gadget: f_mtp: Change the icon to camera for PTP composition



The existing code shows the phone icon in 'My Computer' of windows host,
for PTP composition.
Create a new Extended Configuration Descriptor for PTP composition and
update the compatibleID to display a camera icon for PTP composition.

Change-Id: If286c5b80874a95be0b5ecc533d0e5c7a14f39d3
Signed-off-by: default avatarAzhar Shaikh <azhars@codeaurora.org>
parent 77813844
Loading
Loading
Loading
Loading
+36 −5
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ struct mtp_dev {
	} perf[MAX_ITERATION];
	unsigned dbg_read_index;
	unsigned dbg_write_index;
	bool is_ptp;
};

static struct usb_interface_descriptor mtp_interface_desc = {
@@ -340,10 +341,12 @@ struct mtp_ext_config_desc_function {
};

/* MTP Extended Configuration Descriptor */
struct {
struct ext_mtp_desc {
	struct mtp_ext_config_desc_header	header;
	struct mtp_ext_config_desc_function    function;
} mtp_ext_config_desc = {
};

struct ext_mtp_desc  mtp_ext_config_desc = {
	.header = {
		.dwLength = __constant_cpu_to_le32(sizeof(mtp_ext_config_desc)),
		.bcdVersion = __constant_cpu_to_le16(0x0100),
@@ -357,6 +360,20 @@ struct {
	},
};

struct ext_mtp_desc ptp_ext_config_desc = {
	.header = {
		.dwLength = cpu_to_le32(sizeof(mtp_ext_config_desc)),
		.bcdVersion = cpu_to_le16(0x0100),
		.wIndex = cpu_to_le16(4),
		.bCount = cpu_to_le16(1),
	},
	.function = {
		.bFirstInterfaceNumber = 0,
		.bInterfaceCount = 1,
		.compatibleID = { 'P', 'T', 'P' },
	},
};

struct mtp_device_status {
	__le16	wLength;
	__le16	wCode;
@@ -1275,9 +1292,21 @@ static int mtp_ctrlrequest(struct usb_composite_dev *cdev,
		if (ctrl->bRequest == 1
				&& (ctrl->bRequestType & USB_DIR_IN)
				&& (w_index == 4 || w_index == 5)) {
			value = (w_length < sizeof(mtp_ext_config_desc) ?
					w_length : sizeof(mtp_ext_config_desc));
			memcpy(cdev->req->buf, &mtp_ext_config_desc, value);
			if (!dev->is_ptp) {
				value = (w_length <
						sizeof(mtp_ext_config_desc) ?
						w_length :
						sizeof(mtp_ext_config_desc));
				memcpy(cdev->req->buf, &mtp_ext_config_desc,
									value);
			} else {
				value = (w_length <
						sizeof(ptp_ext_config_desc) ?
						w_length :
						sizeof(ptp_ext_config_desc));
				memcpy(cdev->req->buf, &ptp_ext_config_desc,
									value);
			}
		}
	} else if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS) {
		DBG(cdev, "class request: %d index: %d value: %d length: %d\n",
@@ -1401,6 +1430,7 @@ mtp_function_unbind(struct usb_configuration *c, struct usb_function *f)
	while ((req = mtp_req_get(dev, &dev->intr_idle)))
		mtp_request_free(req, dev->ep_intr);
	dev->state = STATE_OFFLINE;
	dev->is_ptp = false;
}

static int mtp_function_set_alt(struct usb_function *f,
@@ -1507,6 +1537,7 @@ static int mtp_bind_config(struct usb_configuration *c, bool ptp_config)
	dev->function.set_alt = mtp_function_set_alt;
	dev->function.disable = mtp_function_disable;

	dev->is_ptp = ptp_config;
	return usb_add_function(c, &dev->function);
}