Re: usbtmc: vendor specific i/o

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 02, 2016 at 06:58:11AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Aug 01, 2016 at 08:40:02PM +0200, Ladislav Michl wrote:
> > Hi,
> > 
> > I need to ask usbtmc device for vendor specific data. What about adding ioctl
> > which switches MsgIDs to be vendor specific? Or are there other, better,
> > options? Patch bellow ilustrates changes to allow reading and writing vendor
> > specific messages.
> 
> I don't understand exactly what you are changing here, it seems like you
> are just changing the messages being sent to the device?  Doesn't that
> break existing users?

Sorry for being too brief. For sure I not want to break any existing user.
Normally MsgID=DEV_DEP_MSG_OUT is used for command message,
REQUEST_DEV_DEP_MSG_IN to request response message and DEV_DEP_MSG_IN
is MsgID of response message (values are 1 and 2 respectively).
However usbtmc class defines also vendor specific messages, which uses
the same scheme with values 126, resp. 127. Currently there's no way
to send vendor specific messages.
My question is whenever it is okay to add ioctl which will alter between
normal and vendor specific messages or if there's another prefered way,
something like this pseudo-patch (showing only one way switch):

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 917a55c..4c90e50 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -549,7 +549,7 @@ static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t t
 	/* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message
 	 * Refer to class specs for details
 	 */
-	buffer[0] = 2;
+	buffer[0] = data->msgid_in;
 	buffer[1] = data->bTag;
 	buffer[2] = ~data->bTag;
 	buffer[3] = 0; /* Reserved */
@@ -677,8 +677,8 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
 				goto exit;
 			}
 
-			if (buffer[0] != 2) {
-				dev_err(dev, "Device sent reply with wrong MsgID: %u != 2\n", buffer[0]);
+			if (buffer[0] != data->msgid_in) {
+				dev_err(dev, "Device sent reply with wrong MsgID: %u != %u\n", buffer[0], data->msgid_out);
 				if (data->auto_abort)
 					usbtmc_ioctl_abort_bulk_in(data);
 				goto exit;
@@ -807,7 +807,7 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
 		}
 
 		/* Setup IO buffer for DEV_DEP_MSG_OUT message */
-		buffer[0] = 1;
+		buffer[0] = data->msgid_out;
 		buffer[1] = data->bTag;
 		buffer[2] = ~data->bTag;
 		buffer[3] = 0; /* Reserved */
@@ -1227,6 +1227,12 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		retval = usbtmc_ioctl_abort_bulk_in(data);
 		break;
 
+	case USBTMC_IOCTL_VENDOR_SPECIFIC:
+		data->msgid_out = 126;
+		data->msgid_in = 127;
+		retval = 0;
+		break;
+
 	case USBTMC488_IOCTL_GET_CAPS:
 		retval = copy_to_user((void __user *)arg,
 				&data->usb488_caps,
@@ -1414,6 +1420,8 @@ static int usbtmc_probe(struct usb_interface *intf,
 	data->TermChar = '\n';
 	/*  2 <= bTag <= 127   USBTMC-USB488 subclass specification 4.3.1 */
 	data->iin_bTag = 2;
+	data->msgid_out = 1;
+	data->msgid_in = 2;
 
 	/* USBTMC devices have only one setting, so use that */
 	iface_desc = data->intf->cur_altsetting;
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux