I'm new to Linux driver development, and I love it so far! However, I've come across an issue, and I cannot resolve it. I'm trying to send a GET_STATUS RequestType control message to my device, and read the response back in the data variable, then print it out, but when I add the usb_control_msg code to my probe function, my Ubuntu VM freezes. When I add the usb_control_msg code to my open function below, I get an error ("Message too long") when I open the device file. I just want to get the status of my device, but the open function appears to be the only place I can insert the usb_control_msg code, without my Ubuntu VM freezing. Have I misunderstood how the usb_control_msg function works?
Thanks so much for your help!
Code:
static int xb1_open(struct inode *inode, struct file *file) {
printk(KERN_INFO "open function called..");
struct xb1_controller *dev;
struct usb_interface *interface;
int subminor;
int retval = 0;
subminor = iminor(inode);
interface = usb_find_interface(&xb1_driver, subminor);
if(!interface) {
printk(KERN_INFO "Unable to locate interface in open
function");
retval = -ENODEV;
goto exit;
}
dev = usb_get_intfdata(interface);
if(!dev) {
printk(KERN_INFO "Unable to locate dev structure in open
function");
retval = -ENODEV;
goto exit;
}
usb_fill_int_urb(dev->int_in_urb, dev->udev, usb_rcvintpipe(dev-
>udev, dev->int_in_endpoint->bEndpointAddress),
dev->int_in_buffer, dev->int_in_endpoint-
>wMaxPacketSize, xb1_int_in_callback,
dev, dev->int_in_endpoint->bInterval);
dev->int_in_running = 1;
retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL);
if(retval) {
printk(KERN_INFO "Unable to submit int_in_urb in open
function");
dev->int_in_running = 0;
goto exit;
}
file->private_data = dev;
u8 data[8];
retval = usb_control_msg(dev, usb_rcvctrlpipe(dev->udev, 0), 0x00,
0xa3, 0x0000, 0x0, &data, sizeof(data),
5);
if(retval < 0) {
printk(KERN_INFO "usb_control_msg failed | Retval = %d",
retval);
}
else {
printk(KERN_INFO "data: %phC", data);
}
exit:
return retval;
}
You are using both usb_submit_urb and usb_control_msg, which is wrong. You need to use any one, depending on the context.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.