C Linux USB Driver | Best way to print URB buffer contents -
i'm new linux usb driver development, , absolutely love far! i'm creating driver xbox 1 controller, , have question guys. in below code, see fill interrupt in urb in open function, , print contents of urb buffer in xb1_int_in_callback() function. best way this? @ moment, i'm using printk(kern_info "int_in_buffer: %s", dev->int_in_buffer), don't see entire urb buffer contents printed, , weird string printed dmesg.
sorry if simple question, i'm new programming , c, i'm still learning go, absolutely love far!
code:
static void xb1_int_in_callback(struct urb *int_in_urb) { struct xb1_controller *dev = int_in_urb->context; printk(kern_info "xb1_int_in_callback called"); printk(kern_info "int_in_buffer: %s", dev->int_in_buffer); } 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 locate interface in open function"); retval = -enodev; goto exit; } dev = usb_get_intfdata(interface); if(!dev) { printk(kern_info "unable 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 submit int_in_urb in open function"); dev->int_in_running = 0; goto exit; } file->private_data = dev; exit: return retval; } static int xb1_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct xb1_controller *dev = null; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; int i; int retval = -enodev; if(!udev) { printk(kern_info "udev null in probe function"); xb1_abort(dev); return retval; } dev = kzalloc(sizeof(struct xb1_controller), gfp_kernel); if(!dev) { printk(kern_info "unable allocate memory dev in probe function"); xb1_abort(dev); return retval; } dev->udev = udev; dev->interface = interface; iface_desc = interface->cur_altsetting; for(i=0; i<iface_desc->desc.bnumendpoints; i++) { endpoint = &iface_desc->endpoint[i].desc; if(((endpoint->bendpointaddress & usb_endpoint_dir_mask) == usb_dir_in) && ((endpoint->bmattributes & usb_endpoint_xfertype_mask) == usb_endpoint_xfer_int)) { dev->int_in_endpoint = endpoint; } } if(!dev->int_in_endpoint) { printk(kern_info "unable locate interrupt in endpoint interface in probe function"); xb1_abort(dev); return retval; } else { printk(kern_info "interrupt in endpoint found!"); }
for printing small buffers (up 64 bytes long) use printk format:
raw buffer hex string:
%*ph 00 01 02 ... 3f %*phc 00:01:02: ... :3f %*phd 00-01-02- ... -3f %*phn 000102 ... 3f
for larger buffers use print_hex_dump()
. reference here.
Comments
Post a Comment