Czytaj / pisz na pendrive'ie używając libusb: libusb_bulk_transfer ()

Próbuję wykonać operacje odczytu i zapisu na apendrive.

Szczegóły: ID dostawcy: 8564 i ID produktu: 1000. Jest toPrzekroczyć Urządzenie pamięci masowej JetFlash.

Chciałbym wiedzieć, czy możliwe jest uzyskanie odczytu / zapisu na pendrive. Jeśli tak, to czy tak się stanie w przypadku kodu podanego poniżej.

Nauczyłem się metod uzyskiwania identyfikatora urządzenia, identyfikatora produktu i adresów punktów końcowych. To właśnie wdrożyłem.

Tutaj urządzenie jest potwierdzane i otwierane. I nawet interfejs twierdzi, że jest udany.

Ale funkcje przesyłania masowego zwracają -1.

Jakie jest wyjaśnienie?

#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include </usr/include/libusb-1.0/libusb.h>

#define BULK_EP_OUT     0x82
#define BULK_EP_IN      0x02

int main(void)
{
    int r = 0, e = 0;
    struct libusb_device_handle *handle = NULL;
    struct libusb_device **devs;
    struct libusb_device *dev;
    struct libusb_device_descriptor desc;
    char str1[256], str2[256];

    /* Init libusb */
    r = libusb_init(NULL);
    if (r < 0)
    {
        printf("\nfailed to initialise libusb\n");
        return 1;
    }

    handle = libusb_open_device_with_vid_pid(NULL, 0x8564, 0x1000);
    if(handle == NULL)
    {
        printf("\nError in device opening!");
    }
    else
        printf("\nDevice Opened");

    // Tell libusb to use the CONFIGNUM configuration of the device

    libusb_set_configuration(handle, 1);
    if(libusb_kernel_driver_active(handle, 0) == 1)
    {
        printf("\nKernel Driver Active");
        if(libusb_detach_kernel_driver(handle, 0) == 0)
            printf("\nKernel Driver Detached!");
    }

    e = libusb_claim_interface(handle, 0);
    if(e < 0)
    {
        printf("\nCannot Claim Interface");
    }
    else
        printf("\nClaimed Interface");

      /* Communicate */

    int bytes_read;
    int nbytes = 256;
    unsigned char *my_string, *my_string1;
    int transferred = 0;
    my_string = (unsigned char *) malloc (nbytes + 1);
    my_string1 = (unsigned char *) malloc (nbytes + 1);

    strcpy(my_string, "divesd");
    printf("\nTo be sent : %s", my_string);

    e = libusb_bulk_transfer(handle, BULK_EP_OUT, my_string, bytes_read, &transferred, 5000);
    printf("\nXfer returned with %d", e);
    printf("\nSent %d bytes with string: %s\n", transferred, my_string);

    libusb_bulk_transfer(handle, BULK_EP_IN, my_string1, 256, &transferred, 5000);
    printf("\nXfer returned with %d", e);     //It returns -1... This is an error, I guess.
    printf("\nReceived %d bytes with string: %s\n", transferred, my_string1);

    e = libusb_release_interface(handle, 0);
    libusb_close(handle);
    libusb_exit(NULL);
    return 0;
}

questionAnswers(1)

yourAnswerToTheQuestion