Paul,
Here are my patches. I haven't tried Fuse yet - I want to revel in the fact
that this is working for owhttpd/owftpd/owserver!
I put the usb_clear_halt fix into the DS9490 code, since I really don't know
when the libusb port might get updated. This could probably use some smart
checking in configure for such things... It's ugly, but hopefully only
temporary.
Any idea why <sys/types> needs to be included twice (lines 77 and 85 of ow.h)?
Rob.
--- /home/robert/build/owfs-2.4p3/module/owlib/src/include/ow.h Fri Jun 23
17:50:23 2006
+++ /home/robert/build/owfs-2.4p3.rob/module/owlib/src/include/ow.h Sun Jul
23 13:34:36 2006
@@ -76,6 +76,11 @@
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> /* for stat */
#endif
+#ifdef __FreeBSD__ // Fix to compile under FreeBSD
+ #define major(x) ((int)(((unsigned int)(x) >> 8)&0xff)) /* major
number */
+ #define minor(x) ((int)((x)&0xffff00ff)) /* minor number */
+ #define IPPORT_RESERVED 1024
+#endif
#include <ctype.h>
#include <sys/types.h>
#include <stdlib.h>
@@ -99,7 +104,10 @@
#include <termios.h>
#include <errno.h>
#include <syslog.h>
-#include <sys/file.h> /* for flock */
+// #include <sys/file.h> /* for flock */
+#ifdef __FreeBSD__
+ #include <sys/select.h>
+#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h> /* for long options */
#endif
@@ -209,6 +217,28 @@
#endif /* OW_MT */
#if OW_USB
+ #ifdef __FreeBSD__
+ // Add a few definitions we need
+ #undef HAVE_USB_INTERRUPT_READ // This call in libusb is unneeded for
FreeBSD (and it's broken)
+ #define u_long unsigned long
+ #define u_char unsigned char
+ #define u_int unsigned int
+// #include <sys/ioctl.h>
+ // The include, structure definition, and define are only needed until
FreeBSD has a usb_clear_halt function
+ #include <dev/usb/usb.h>
+ struct usb_dev_handle {
+ int fd;
+ struct usb_bus *bus;
+ struct usb_device *device;
+ int config;
+ int interface;
+ int altsetting;
+ void *impl_info;
+ };
+ #define USB_CLEAR_HALT BSD_usb_clear_halt
+ #else
+ #define USB_CLEAR_HALT usb_clear_halt
+ #endif
#include <usb.h>
#endif /* OW_USB */
--- /home/robert/build/owfs-2.4p3/module/owlib/src/c/ow_ds9490.c Fri Jun
23 17:50:23 2006
+++ /home/robert/build/owfs-2.4p3.rob/module/owlib/src/c/ow_ds9490.c Sun Jul
23 13:23:42 2006
@@ -209,6 +209,28 @@
char badUSBname[] = "-1/-1" ;
+#ifdef __FreeBSD__
+// This is in here until the libusb on FreeBSD supports the usb_clear_halt
function
+int BSD_usb_clear_halt(usb_dev_handle *dev, unsigned int ep)
+{
+ int ret;
+ struct usb_ctl_request ctl_req;
+
+ ctl_req.ucr_addr = 0; // Not used for this type of request
+ ctl_req.ucr_request.bmRequestType = UT_WRITE_ENDPOINT;
+ ctl_req.ucr_request.bRequest = UR_CLEAR_FEATURE;
+ USETW(ctl_req.ucr_request.wValue, UF_ENDPOINT_HALT);
+ USETW(ctl_req.ucr_request.wIndex, ep);
+ USETW(ctl_req.ucr_request.wLength, 0);
+ ctl_req.ucr_flags = 0;
+
+ if ((ret = ioctl(dev->fd, USB_DO_REQUEST, &ctl_req)) < 0)
+ LEVEL_DATA("DS9490_clear_halt: failed for %d", ep);
+
+ return ret;
+}
+#endif /* __FreeBSD__ */
+
int DS9490_enumerate( void ) {
struct usb_list ul ;
int ret = 0 ;
@@ -384,10 +406,10 @@
// clear endpoints
if ( (ret =
- usb_clear_halt(usb, DS2490_EP3) ||
- usb_clear_halt(usb, DS2490_EP2) ||
- usb_clear_halt(usb, DS2490_EP1) ) ) {
- LEVEL_DEFAULT("DS9490_open: usb_clear_halt failed
ret=%d\n", ret);
+ USB_CLEAR_HALT(usb, DS2490_EP3) ||
+ USB_CLEAR_HALT(usb, DS2490_EP2) ||
+ USB_CLEAR_HALT(usb, DS2490_EP1) ) ) {
+ LEVEL_DEFAULT("DS9490_open: USB_CLEAR_HALT failed
ret=%d\n", ret);
} else if ( DS9490_setup_adapter(pn) ||
DS9490_overdrive(ONEWIREBUSSPEED_REGULAR, pn) ||
DS9490_level(MODE_NORMAL, pn) ) {
@@ -584,8 +606,22 @@
int ret , loops = 0 ;
int i ;
usb_dev_handle * usb = pn->in->connin.usb.usb ;
+#ifdef OW_DEBUG
+ char s[97], t[4] ; // For my fancy display in the log
+#endif
memset(buffer, 0, 32) ; // should not be needed
+
+ LEVEL_DETAIL("DS9490_getstatus: readlen=%d\n", readlen);
+
+#ifdef __FreeBSD__ // Clear the Interrupt read buffer before trying to get
status
+ char junk[1500] ;
+ if ( (ret=usb_bulk_read(usb,DS2490_EP1,(ASCII
*)junk,(size_t)1500,TIMEOUT_USB)) < 0 ) {
+ STAT_ADD1_BUS(BUS_status_errors,pn->in);
+ LEVEL_DATA("DS9490_getstatus: error reading ret=%d\n", ret);
+ return -EIO ;
+ }
+#endif // __FreeBSD__
do {
#ifdef HAVE_USB_INTERRUPT_READ
// Fix from Wim Heirman -- kernel 2.6 is fussier about endpoint type
@@ -597,7 +633,24 @@
LEVEL_DATA("DS9490_getstatus: error reading ret=%d\n", ret);
return -EIO ;
}
+#ifdef OW_DEBUG
+ if (error_level>4) { // LEVEL_DETAIL
+ s[0] = '\0';
+ for (i = 0; i < ret; i++) {
+ sprintf(t,"-%02x",buffer[i]);
+ strcat(s,t);
+ }
+ LEVEL_DETAIL("DS9490_getstatus: Bytes%s\n", s);
+ }
+#endif
if(ret > 16) {
+ if (ret == 32) { // FreeBSD buffers the input, so this could just
be two readings
+ if (!memcmp(buffer, &buffer[16], 6)) {
+ memmove(buffer, &buffer[16],16);
+ ret = 16;
+ LEVEL_DATA("DS9490_getstatus: Corrected buffer 32 byte
read\n", s);
+ }
+ }
for(i=16; i<ret; i++) {
BYTE val = buffer[i];
if(val != ONEWIREDEVICEDETECT) {
@@ -810,7 +863,7 @@
//printf("DS9490_read\n");
if ((ret=usb_bulk_read(usb,DS2490_EP3,(ASCII*)buf,(int)size,TIMEOUT_USB ))
> 0) return ret ;
LEVEL_DATA("DS9490_read: failed ret=%d\n", ret);
- usb_clear_halt(usb,DS2490_EP3) ;
+ USB_CLEAR_HALT(usb,DS2490_EP3) ;
STAT_ADD1_BUS(BUS_read_errors,pn->in) ;
return ret ;
}
@@ -821,7 +874,7 @@
//printf("DS9490_write\n");
if ((ret=usb_bulk_write(usb,DS2490_EP2,(const ASCII *)buf,(const
int)size,TIMEOUT_USB )) > 0) return ret ;
LEVEL_DATA("DS9490_write: failed ret=%d\n", ret);
- usb_clear_halt(usb,DS2490_EP2) ;
+ USB_CLEAR_HALT(usb,DS2490_EP2) ;
STAT_ADD1_BUS(BUS_write_errors,pn->in) ;
return ret ;
}
--- /home/robert/build/owfs-2.4p3/module/owlib/src/c/ow_net.c Tue Jun 6
19:07:00 2006
+++ /home/robert/build/owfs-2.4p3.rob/module/owlib/src/c/ow_net.c Sun Jul
23 11:23:41 2006
@@ -109,8 +109,11 @@
memset( &hint, 0, sizeof(struct addrinfo) ) ;
hint.ai_flags = AI_PASSIVE ;
hint.ai_socktype = SOCK_STREAM ;
+#ifdef __FreeBSD__
+ hint.ai_family = AF_INET; // Until the code is fixed to bind to more than
one protocol
+#else
hint.ai_family = AF_UNSPEC ;
-
+#endif
//printf("ServerAddr: [%s] [%s]\n", out->host, out->service);
if ( (ret=getaddrinfo( out->host, out->service, &hint, &out->ai )) ) {
--- /home/robert/build/owfs-2.4p3/module/owlib/src/c/ow_tree.c Sun May 21
19:57:42 2006
+++ /home/robert/build/owfs-2.4p3.rob/module/owlib/src/c/ow_tree.c Sun Jul
23 11:13:34 2006
@@ -33,8 +33,19 @@
static void Device2Tree( const struct device * d, enum pn_type type ) {
- tsearch( d, &Tree[type], device_compare ) ;
- if (d->ft) qsort( d->ft,(size_t) d->nft,sizeof(struct
filetype),file_compare ) ;
+ struct device *d_copy;
+
+ /* In order for DeviceDestroy to work on FreeBSD we must copy the keys.
+ Otherwise, tdestroy will attempt to free implicitly allocated
structures.
+ */
+
+ if ( (d_copy = (struct device *)malloc(sizeof(struct device))) ) {
+ memmove(d_copy, d, sizeof(struct device));
+ tsearch( d_copy, &Tree[type], device_compare ) ;
+ if (d_copy->ft) qsort( d_copy->ft,(size_t) d_copy->nft,sizeof(struct
filetype),file_compare ) ;
+ } else {
+ LEVEL_DATA("Device2Tree: Could not allocate memory for device
%s\n",d->name);
+ }
/*
{
int i ;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers