Changeset 1051


Ignore:
Timestamp:
05/22/08 13:07:31 (4 years ago)
Author:
alonbl
Message:

Fix OpenBSD issues.

fixes sys-bsd.c to use the correct device
filenames on OpenBSD. An earlier patch already fixed this for the control
endpoint, but this caused the other endpoints to be accessed under
'/dev/ugenX.00.E'. This patch causes the correct filenames to be used
for all endpoints.

Also, Fix BSD support of USB devices.

By David Imhoff and Hasso Tepper.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ifd/sys-bsd.c

    r973 r1051  
    1414#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) 
    1515#include <sys/types.h> 
     16#if defined(__DragonFly__) 
     17#include <bus/usb/usb.h> 
     18#else 
    1619#include <dev/usb/usb.h> 
     20#endif 
    1721#include <sys/stat.h> 
    1822#include <sys/ioctl.h> 
     
    6468        } 
    6569 
    66         sprintf((char *)&filename, "%s.%d", name, endpoint); 
     70#ifdef __OpenBSD__ 
     71        snprintf(filename, sizeof(filename), "%s.%02d", name, endpoint); 
     72#else 
     73        snprintf(filename, sizeof(filename), "%s.%d", name, endpoint); 
     74#endif /* __OpenBSD__ */ 
    6775 
    6876        if ((interfaces[interface][endpoint].ep_fd = open(filename, flags)) < 0) { 
     
    95103        ct_debug("ifd_sysdep_usb_bulk: endpoint=%d direction=%d", endpoint, 
    96104                 direction); 
    97         if (open_ep(dev->name, 0, endpoint, O_RDWR | O_NONBLOCK)) { 
    98                 ct_debug("ifd_sysdep_usb_bulk: opening endpoint failed"); 
    99                 return -1; 
    100         } 
    101105        if (direction) { 
     106                int one = 1; 
     107 
     108                if (open_ep(dev->name, 0, endpoint, O_RDONLY | O_NONBLOCK)) { 
     109                        ct_debug("ifd_sysdep_usb_bulk: opening endpoint failed"); 
     110                        return -1; 
     111                } 
     112 
     113                if (ioctl(interfaces[0][endpoint].ep_fd, USB_SET_SHORT_XFER, 
     114                    &one) < 0) { 
     115                        ifd_debug(6, "ifd_sysdep_usb_bulk: USB_SET_SHORT_XFER" 
     116                                  " failed: %s", strerror(errno)); 
     117                        ct_error("usb_bulk read failed: %s", strerror(errno)); 
     118                } 
    102119                if ((bytes_to_process = 
    103120                     read(interfaces[0][endpoint].ep_fd, buffer, len)) < 0) { 
     
    111128                return bytes_to_process; 
    112129        } else { 
     130                if (open_ep(dev->name, 0, endpoint, O_WRONLY | O_NONBLOCK)) { 
     131                        ct_debug("ifd_sysdep_usb_bulk: opening endpoint failed"); 
     132                        return -1; 
     133                } 
     134 
    113135                bytes_to_process = len; 
    114136                if ((bytes_processed = 
     
    315337int ifd_sysdep_usb_open(const char *device) 
    316338{ 
     339#ifdef __OpenBSD__ 
     340        char path[256]; 
     341 
     342        if (snprintf(&path, sizeof(path), "%s.00", device) < 0) 
     343                return -1; 
     344        return open(path, O_RDWR); 
     345#else 
    317346        return open(device, O_RDWR); 
     347#endif /* __OpenBSD__ */ 
    318348} 
    319349 
     
    385415                        if (!(driver = ifd_driver_for_id(&id))) 
    386416                                continue; 
    387 #ifdef __OpenBSD__ 
    388                         snprintf(typedev, sizeof(typedev), 
    389                                  "usb:/dev/%s.00", device_info.udi_devnames[0]); 
    390 #else 
    391417                        snprintf(typedev, sizeof(typedev), 
    392418                                 "usb:/dev/%s", device_info.udi_devnames[0]); 
    393 #endif                          /* __OpenBSD__ */ 
    394419 
    395420                        ifd_spawn_handler(driver, typedev, -1); 
Note: See TracChangeset for help on using the changeset viewer.