diff -ur libusb-beos/beos.c libusb-davidson/beos.c --- libusb-beos/beos.c Sun Jan 20 16:04:30 2008 +++ libusb-davidson/beos.c Fri Dec 26 23:33:04 2008 @@ -20,10 +20,10 @@ static char usb_path[PATH_MAX + 1] = ""; -#if 0 +/*#if 0*/ static int myioctl(int fd, int cmd, void *p, size_t sz) { - int ret; + int ret = 0; //char c; printf("ioctl(%d, %x, %p, %ld)\n", fd, cmd, p, sz); fflush(stdout); @@ -34,7 +34,52 @@ } #define ioctl myioctl -#endif +/*#endif*/ + +void PrintHex(const unsigned char* buf, size_t size) { + uint16 i = 0; + uint16 j = 0; + int breakpoint = 0; + + for(;i < size; i++) { + fprintf(stdout, "%02x ", (unsigned char)buf[i]); + breakpoint++; + + if(!((i + 1)%16) && i) { + fprintf(stdout, "\t\t"); + for(j = ((i+1) - 16); j < ((i+1)/16) * 16; j++) { + if ((buf[j] < 0x21) || (buf[j] > 0x7d)) { + fprintf(stdout, "."); + } else { + fprintf(stdout, "%c", (unsigned char)buf[j]); + }; + } + fprintf(stdout, "\n"); + breakpoint = 0; + } + } + + if(breakpoint == 16) { + fprintf(stdout, "\n"); + return; + } + + for(; breakpoint < 16; breakpoint++) { + fprintf(stdout, " "); + } + + fprintf(stdout, "\t\t"); + + for(j = size - (size%16); j < size; j++) { + if(buf[j] < 30) { + fprintf(stdout, "."); + } else { + fprintf(stdout, "%c", (unsigned char)buf[j]); + }; + } + + fprintf(stdout, "\n"); +} static int device_open(struct usb_device *dev) { @@ -77,7 +122,7 @@ int usb_set_configuration(usb_dev_handle *dev, int configuration) { - int ret; + int ret = -1; raw_command command; command.config.config_index = configuration; @@ -124,7 +169,7 @@ if (ret < 0) USB_ERROR_STR(errno, "could not release intf %d: %s", interface, strerror(errno)); - +x dev->interface = -1; #endif return 0; @@ -133,6 +178,21 @@ // XXX int usb_set_altinterface(usb_dev_handle *dev, int alternate) { + int ret; + raw_command command; + command.alternate.config_index = alternate; + + ret = ioctl(dev->fd, RAW_COMMAND_SET_CONFIGURATION, &command, sizeof(command)); + if (command.config.status != RAW_STATUS_SUCCESS) { + if (ret < 0) { + USB_ERROR_STR(errno, "could not set alt interface %d: %s", alternate, strerror(errno)); + }; + } else { + dev->altsetting = alternate; + } + + return 0; + #if 0 int ret; struct usb_setinterface setintf; @@ -165,6 +225,12 @@ command.control.length = size; command.control.data = bytes; + fprintf(stderr, "usb_control_msg([%p], %i, %i, %i, %i, ..., %i, %i)\n", dev, requesttype, request, + value, index, size, timeout); + + PrintHex((uchar *)bytes, size); + +/*return -1;*/ ret = ioctl(dev->fd, RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command)); if (command.control.status != RAW_STATUS_SUCCESS) { if (ret < 0) { @@ -174,6 +240,8 @@ ret = command.control.length; } + fprintf(stderr, "\tReturned: %i\n", ret); + return ret; } @@ -295,157 +363,200 @@ int usb_os_find_devices(struct usb_bus *bus, struct usb_device **devices) { - struct usb_device *fdev = NULL; - DIR *dir; - struct dirent *entry; - char dirpath[PATH_MAX + 1]; - - snprintf(dirpath, PATH_MAX, "%s/%s", usb_path, bus->dirname); - - dir = opendir(dirpath); - if (!dir) - USB_ERROR_STR(errno, "couldn't opendir(%s): %s", dirpath, - strerror(errno)); - - while ((entry = readdir(dir)) != NULL) { - //unsigned char device_desc[DEVICE_DESC_LENGTH]; - char filename[PATH_MAX + 1]; - struct usb_device *dev; - int i, fd, ret; - usb_device_descriptor desc; - raw_command command; - command.device.descriptor = &desc; - - /* Skip anything starting with a . */ - if (entry->d_name[0] == '.') - continue; - - dev = malloc(sizeof(*dev)); - if (!dev) - USB_ERROR(ENOMEM); - - memset((void *)dev, 0, sizeof(*dev)); - - dev->bus = bus; - - strncpy(dev->filename, entry->d_name, sizeof(dev->filename) - 1); - dev->filename[sizeof(dev->filename) - 1] = 0; - - snprintf(filename, sizeof(filename) - 1, "%s/%s", dirpath, entry->d_name); - fd = open(filename, O_RDWR); - if (fd < 0) { - fd = open(filename, O_RDONLY); - if (fd < 0) { - if (usb_debug >= 2) { - fprintf(stderr, "usb_os_find_devices: Couldn't open %s\n", - filename); - } - - free(dev); - continue; - } - } - - ret = ioctl(fd, RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command, sizeof(command)); - if (ret < 0) { - if (usb_debug) { - fprintf(stderr, "usb_os_find_devices: Couldn't read descriptor\n"); - }; - - free(dev); - goto err; - }; - - //usb_parse_descriptor(device_desc, "bbwbbbbwwwbbbb", &dev->descriptor); - memcpy(&dev->descriptor, &desc, sizeof(desc)); //XXX check endianness - - LIST_ADD(fdev, dev); - - if (usb_debug >= 2) - fprintf(stderr, "usb_os_find_devices: Found %s on %s\n", - dev->filename, bus->dirname); - - /* Now try to fetch the rest of the descriptors */ - if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG) - /* Silent since we'll try again later */ - goto err; - - if (dev->descriptor.bNumConfigurations < 1) - /* Silent since we'll try again later */ - goto err; - - dev->config = (struct usb_config_descriptor *)malloc(dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor)); - if (!dev->config) - /* Silent since we'll try again later */ - goto err; - - memset(dev->config, 0, dev->descriptor.bNumConfigurations * - sizeof(struct usb_config_descriptor)); - - for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { - unsigned char /*buffer[8],*/ *bigbuffer; - usb_configuration_descriptor config; - command.config.descriptor = &config; - command.config.config_index = i; - - /* Get the first 8 bytes so we can figure out what the total length is */ - //ret = read(fd, (void *)buffer, 8); - ret = ioctl(fd, RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command, sizeof(command)); - if (ret < 0) { - if (usb_debug >= 1) - fprintf(stderr, "Unable to get descriptor (%d)\n", ret); - goto err; - } - - //usb_parse_descriptor(buffer, "bbw", &config); - bigbuffer = malloc(sizeof(config)); - //bigbuffer = malloc(config.wTotalLength); - if (!bigbuffer) { - if (usb_debug >= 1) - fprintf(stderr, "Unable to allocate memory for descriptors\n"); - goto err; - } - - config.total_length = sizeof(config); - memcpy(bigbuffer, &config, sizeof(config)); -#if 0 - /* Read the rest of the config descriptor */ - memcpy(bigbuffer, buffer, 8); - - ret = read(fd, (void *)(bigbuffer + 8), config.wTotalLength - 8); - if (ret < config.wTotalLength - 8) { - if (usb_debug >= 1) { - if (ret < 0) - fprintf(stderr, "Unable to get descriptor (%d)\n", ret); - else - fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", config.wTotalLength, ret); - } - - free(bigbuffer); - goto err; - } -#endif - - ret = usb_parse_configuration(&dev->config[i], bigbuffer); - if (usb_debug >= 2) { - if (ret > 0) - fprintf(stderr, "Descriptor data still left\n"); - else if (ret < 0) - fprintf(stderr, "Unable to parse descriptors\n"); - } - - free(bigbuffer); - } - + struct usb_device *fdev = NULL; + DIR *dir; + struct dirent *entry; + char dirpath[PATH_MAX + 1]; + + snprintf(dirpath, PATH_MAX, "%s/%s", usb_path, bus->dirname); + + fprintf(stderr, "usb_os_find_devices(): Iterating %s\n", dirpath); + + dir = opendir(dirpath); + if (!dir) { + USB_ERROR_STR(errno, "couldn't opendir(%s): %s", dirpath, strerror(errno)); + }; + + while ((entry = readdir(dir)) != NULL) { + //unsigned char device_desc[DEVICE_DESC_LENGTH]; + char filename[PATH_MAX + 1]; + struct usb_device *dev; + int i = 0; + int fd = 0; + int ret = 0; + usb_device_descriptor desc; + raw_command command; + command.device.descriptor = &desc; + + /* Skip anything starting with a . */ + if (entry->d_name[0] == '.') continue; + if (strcmp(entry->d_name, "hub") == 0) continue; + + dev = malloc(sizeof(*dev)); + if (!dev) USB_ERROR(ENOMEM); + + memset((void *)dev, 0, sizeof(*dev)); + + dev->bus = bus; + + strncpy(dev->filename, entry->d_name, sizeof(dev->filename) - 1); + dev->filename[sizeof(dev->filename) - 1] = 0; + + snprintf(filename, sizeof(filename) - 1, "%s/%s", dirpath, entry->d_name); + fd = open(filename, O_RDWR); + if (fd < 0) { + fd = open(filename, O_RDONLY); + if (fd < 0) { + if (usb_debug >= 2) { + fprintf(stderr, "usb_os_find_devices: Couldn't open %s\n", filename); + } + + free(dev); + continue; + } + } + + ret = ioctl(fd, RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command, sizeof(command)); + if (ret < 0) { + if (usb_debug) { + fprintf(stderr, "usb_os_find_devices: Couldn't read descriptor\n"); + }; + + free(dev); + goto err; + }; + + memcpy(&dev->descriptor, &desc, sizeof(desc)); //XXX check endianness + + LIST_ADD(fdev, dev); + + if (usb_debug >= 2) { + fprintf(stderr, "usb_os_find_devices: Found %s on %s\n", dev->filename, bus->dirname); + } + + /* Now try to fetch the rest of the descriptors */ + if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG) { + /* Silent since we'll try again later */ + goto err; + } + + if (dev->descriptor.bNumConfigurations < 1) { + /* Silent since we'll try again later */ + goto err; + } + + dev->config = (struct usb_config_descriptor *)malloc(dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor)); + if (!dev->config) { + /* Silent since we'll try again later */ + goto err; + } + + memset(dev->config, 0, dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor)); + + for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { + int j = 0; + unsigned char *bigbuffer = NULL; + usb_configuration_descriptor config; + command.config.descriptor = &config; + command.config.config_index = i; + + /* Get the first 8 bytes so we can figure out what the total length is */ + ret = ioctl(fd, RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command, sizeof(command)); + if (ret < 0) { + if (usb_debug >= 1) { + fprintf(stderr, "Unable to get descriptor (%d)\n", ret); + }; + goto err; + } + + bigbuffer = malloc(sizeof(config)); + if (!bigbuffer) { + if (usb_debug >= 1) { + fprintf(stderr, "Unable to allocate memory for descriptors\n"); + } + goto err; + } + + config.total_length = sizeof(config); + memcpy(bigbuffer, &config, sizeof(config)); + + ret = usb_parse_configuration(&dev->config[i], bigbuffer); + if (usb_debug >= 2) { + if (ret > 0) { + fprintf(stderr, "Descriptor data still left\n"); + } else if (ret < 0) { + fprintf(stderr, "Unable to parse descriptors\n"); + } + } + + for (j = 0; j < dev->config[i].bNumInterfaces; j++) { + raw_command cmdInterface; + raw_command cmdAltCount; + usb_interface_descriptor descAlt; + usb_interface_descriptor desc; + uint32 altCount; + int k = 0; + + cmdInterface.interface.descriptor = &desc; + cmdInterface.interface.config_index = i; + cmdInterface.interface.interface_index = j; + + ret = ioctl(fd, RAW_COMMAND_GET_INTERFACE_DESCRIPTOR, &cmdInterface, sizeof(cmdInterface)); + + if (ret < 0) { + if (usb_debug >= 1) { + fprintf(stderr, "Unable to get interface descriptor (%d)\n", ret); + }; + goto err; + } + + cmdAltCount.alternate.config_index = i; + cmdAltCount.alternate.interface_index = j; + cmdAltCount.alternate.descriptor = &descAlt; + cmdAltCount.alternate.alternate_count = &altCount; + + ret = ioctl(fd, RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &cmdAltCount, sizeof(cmdAltCount)); + if (ret < 0) { + if (usb_debug >= 1) fprintf(stderr, "Unable to get alt interface count (%d)\n", ret); + goto err; + } + + dev->config[i].interface[j].num_altsetting = altCount; + dev->config[i].interface[j].altsetting = (struct usb_interface_descriptor *)malloc(altCount * sizeof(struct usb_interface_descriptor)); + + if (dev->config[i].interface[j].altsetting == NULL) { + if (usb_debug >= 1) fprintf(stderr, "Unable to allocate memory for alternate settings\n"); + goto err; + } + + for (k = 0; k < altCount; k++) { + raw_command cmdAltDesc; + usb_interface_descriptor descAltDetail; + uint32 altCountValue; + + cmdAltDesc.alternate.config_index = i; + cmdAltDesc.alternate.interface_index = j; + cmdAltDesc.alternate.alternate_index = k; + cmdAltDesc.alternate.descriptor = &descAltDetail; + cmdAltDesc.alternate.alternate_count = &altCountValue; + + ret = ioctl(fd, RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, &cmdAltDesc, sizeof(cmdAltDesc)); + if (ret < 0) { + if (usb_debug >= 1) fprintf(stderr, "Unable to get alternate interface %i (%d)\n", k, ret); + goto err; + }; + }; + }; + free(bigbuffer); + } err: - close(fd); - } - - closedir(dir); - - *devices = fdev; - - return 0; + close(fd); + } + closedir(dir); + + *devices = fdev; + + return 0; } // XXX diff -ur libusb-beos/beos.h libusb-davidson/beos.h --- libusb-beos/beos.h Sun Jan 20 13:15:42 2008 +++ libusb-davidson/beos.h Sun Apr 20 11:08:38 2008 @@ -11,8 +11,6 @@ #include -//#include - typedef enum { RAW_COMMAND_GET_VERSION = 0x1000, @@ -23,12 +21,15 @@ RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR, RAW_COMMAND_GET_STRING_DESCRIPTOR, RAW_COMMAND_GET_GENERIC_DESCRIPTOR, + RAW_COMMAND_GET_ALT_INTERFACE_COUNT, + RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, RAW_COMMAND_SET_CONFIGURATION = 0x3000, RAW_COMMAND_SET_FEATURE, RAW_COMMAND_CLEAR_FEATURE, RAW_COMMAND_GET_STATUS, RAW_COMMAND_GET_DESCRIPTOR, + RAW_COMMAND_SET_ALT_INTERFACE, RAW_COMMAND_CONTROL_TRANSFER = 0x4000, RAW_COMMAND_INTERRUPT_TRANSFER, @@ -76,6 +77,15 @@ uint32 config_index; uint32 interface_index; } interface; + + struct { + status_t status; + uint32 *alternate_count; + usb_interface_descriptor *descriptor; + uint32 config_index; + uint32 interface_index; + uint32 alternate_index; + } alternate; struct { status_t status; Only in libusb-davidson/: beos.mmu_man.c diff -ur libusb-beos/configure libusb-davidson/configure --- libusb-beos/configure Sat Jul 14 00:34:42 2007 +++ libusb-davidson/configure Mon Jan 21 19:46:20 2008 @@ -19317,7 +19317,7 @@ { echo "$as_me:$LINENO: result: BeOS or Haiku" >&5 echo "${ECHO_T}BeOS or Haiku" >&6; } #OSLIBS="-Wl,--whole-archive -lUSBKit.a" - OSLIBS="-lUSBKit.a" +# OSLIBS="-lUSBKit.a" ;; *) { echo "$as_me:$LINENO: result: unknown operating system" >&5 diff -ur libusb-beos/libusb-config libusb-davidson/libusb-config --- libusb-beos/libusb-config Sun Jan 20 14:39:39 2008 +++ libusb-davidson/libusb-config Fri Feb 29 21:34:29 2008 @@ -75,5 +75,5 @@ echo $includes fi if test "$echo_libs" = "yes"; then - echo -L${exec_prefix}/lib -lusb -lUSBKit.a + echo -L${exec_prefix}/lib -lusb fi diff -ur libusb-beos/tests/hub_strings.cpp libusb-davidson/tests/hub_strings.cpp --- libusb-beos/tests/hub_strings.cpp Sun Jan 20 14:15:22 2008 +++ libusb-davidson/tests/hub_strings.cpp Mon Jan 21 20:11:15 2008 @@ -16,6 +16,8 @@ using namespace std; +#include + int main(void) { USB::Busses buslist; @@ -39,9 +41,12 @@ << hex << setw(2) << setfill('0') << int(device->devProtocol()) << endl; retval = device->string(manufString, 3); +cout << "About to do stuff " << endl; + if ( 0 < retval ) { cout << "3: " << manufString << endl; } else { +printf("Retval: %i (0x%04x)\n", retval, retval); if (RETERR(EPIPE) != retval) { // we ignore EPIPE, because some hubs don't have strings cout << "fetching string 3 failed: " << usb_strerror() << endl; return EXIT_FAILURE; diff -ur libusb-beos/usbpp.cpp libusb-davidson/usbpp.cpp --- libusb-beos/usbpp.cpp Sun Jan 20 13:23:33 2008 +++ libusb-davidson/usbpp.cpp Mon Jan 21 20:16:04 2008 @@ -180,14 +180,18 @@ return m_fileName; } +#include + int Device::string(std::string &buf, int index, u_int16_t langID) { + printf("Device::String(%i, %i)\n", index, langID); int retval; char tmpBuff[256]; if (0 == langID) { /* we want the first lang ID available, so find out what it is */ retval = usb_get_string(m_handle, 0, 0, tmpBuff, sizeof(tmpBuff)); + printf("usb_get_string: %i\n",retval); if (retval < 0) return retval; @@ -198,12 +202,14 @@ } retval = usb_get_string(m_handle, index, langID, tmpBuff, sizeof(tmpBuff)); - +printf("\tusb_get_string: %i vs %i\n", retval, USB_DT_STRING); if (retval < 0) return retval; if (tmpBuff[1] != USB_DT_STRING) return RETERR(EIO); + +printf(" Compared to: %i\n", tmpBuff[0]); if (tmpBuff[0] > retval) return RETERR(EFBIG);