i have tried the driver now on a small application in which i print
what i receive from the gadget so
when the gadget sends "hello" for example, the application just prints
some noise characters.

i thinks that copy_to_user does not work right or its location should
be adjusted?
does copy_to_user arguments are: destination,source,count respectively ?

here is my code till now:

*********************************************************************************
static void skel_read_bulk_callback(struct urb *urb, struct pt_regs *regs)
{
        struct usb_skel *dev;
        struct my_data *mine = (struct my_data *)urb->context;
        complete(&(mine->done));
        dev = mine->dev;
        up(&dev->limit_sem);
}

static ssize_t skel_read(struct file *file, char *user_buffer, size_t
count, loff_t *ppos)

{
//      struct completion done;
//      struct usb_skel *dev;
        int retval = 0;
        struct urb *urb = NULL;
        char *buf = NULL;

        size_t readsize = min(count, (size_t)MAX_TRANSFER);

        mydata1.dev = (struct usb_skel *)file->private_data;

        /* verify that we actually have some data to read */
        if (count == 0)
                goto exit;

        /* limit the number of URBs in flight to stop a user from using up all 
RAM */
        if (      down_interruptible( & (mydata1.dev->limit_sem) )     )
        {
                retval = -ERESTARTSYS;
                goto exit;
        }

        init_completion(& (  mydata1.done) );

        /* create a urb, and a buffer for it, and copy the data to the urb */
        urb = usb_alloc_urb(0, GFP_KERNEL);
        if (!urb) {
                retval = -ENOMEM;
                goto error;
        }

        buf = usb_buffer_alloc(mydata1.dev->udev, readsize, GFP_KERNEL,
&urb->transfer_dma);
        if (!buf) {
                retval = -ENOMEM;
                goto error;
        }

        /* initialize the urb properly */
        usb_fill_bulk_urb(urb, mydata1.dev->udev,
                          usb_rcvbulkpipe(mydata1.dev->udev, 
mydata1.dev->bulk_in_endpointAddr),
                          buf, readsize, skel_read_bulk_callback, &mydata1);
        urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

        /* send the data out the bulk port */
        retval = usb_submit_urb(urb, GFP_KERNEL);
        if (retval) {
                err("%s - failed submitting read urb, error %d", __FUNCTION__, 
retval);
                goto error;
        }

        wait_for_completion(  &(mydata1.done)  );

        if (   copy_to_user( mydata1.dev->bulk_in_buffer,
user_buffer,urb->actual_length) )
                retval = -EFAULT;
        else
                retval = urb->actual_length;

        
        /* free up our allocated buffer */
        usb_buffer_free(urb->dev, urb->transfer_buffer_length,
                        urb->transfer_buffer, urb->transfer_dma);
        /* release our reference to this urb, the USB core will eventually
free it entirely */
        usb_free_urb(urb);

        return retval;

exit:
        return retval;

error:
        usb_buffer_free(mydata1.dev->udev, readsize, buf, urb->transfer_dma);
        usb_free_urb(urb);
        up(  &(mydata1.dev->limit_sem) );
        return retval;
}
****************************************************************************************

so when the gadget sends "hello", i tried to print what the host
receives and the size of data it receives , it prints the size correct
as 5 for "hello" but when i print what it receives i got some noise
characters.so what is still wrong i dont know?

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to