pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
argyllcms: sync to pkgsrc/graphics/argyllcms
Module Name: pkgsrc-wip
Committed By: Jonathan A. Kollasch <jakllsch%kollasch.net@localhost>
Pushed By: jakllsch
Date: Fri Nov 24 14:27:02 2023 -0600
Changeset: 616680ce2bd15daa189aa1808a3eacd52c37cbcb
Modified Files:
argyllcms/DESCR
argyllcms/Makefile
argyllcms/PLIST
argyllcms/distinfo
argyllcms/patches/patch-Jamtop
argyllcms/patches/patch-spectro_hidio.c
argyllcms/patches/patch-spectro_usbio.c
Added Files:
argyllcms/patches/patch-spectro_Jamfile
argyllcms/patches/patch-spectro_hidio.h
argyllcms/patches/patch-spectro_usbio__bsd.c
Removed Files:
argyllcms/wip-patch-spectro_usbio__bsd.c
Log Message:
argyllcms: sync to pkgsrc/graphics/argyllcms
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=616680ce2bd15daa189aa1808a3eacd52c37cbcb
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
argyllcms/DESCR | 2 +-
argyllcms/Makefile | 7 +-
argyllcms/PLIST | 16 +
argyllcms/distinfo | 15 +-
argyllcms/patches/patch-Jamtop | 16 +-
argyllcms/patches/patch-spectro_Jamfile | 15 +
argyllcms/patches/patch-spectro_hidio.c | 168 +++++++-
argyllcms/patches/patch-spectro_hidio.h | 22 ++
argyllcms/patches/patch-spectro_usbio.c | 20 +-
argyllcms/patches/patch-spectro_usbio__bsd.c | 515 ++++++++++++++++++++++++
argyllcms/wip-patch-spectro_usbio__bsd.c | 570 ---------------------------
11 files changed, 759 insertions(+), 607 deletions(-)
diffs:
diff --git a/argyllcms/DESCR b/argyllcms/DESCR
index 14975c6a85..43baf54f77 100644
--- a/argyllcms/DESCR
+++ b/argyllcms/DESCR
@@ -3,7 +3,7 @@ as Open Source. It supports accurate ICC profile creation for
scanners, cameras and film recorders, and calibration and profiling
of displays and RGB & CMYK printers. Device Link can be created
with a wide variety of advanced options, including specialized
-Video calibration standards and 3dLuts. Spectral sample data is
+Video calibration standards and 3dLuts. Spectral sample data is
supported, allowing a selection of illuminants observer types, and
paper fluorescent whitener additive compensation. Profiles can also
incorporate source specific gamut mappings for perceptual and
diff --git a/argyllcms/Makefile b/argyllcms/Makefile
index 9213aee479..314c60746d 100644
--- a/argyllcms/Makefile
+++ b/argyllcms/Makefile
@@ -1,6 +1,6 @@
# $NetBSD$
-DISTNAME= Argyll_V2.0.1_src
+DISTNAME= Argyll_V3.0.2_src
PKGNAME= ${DISTNAME:S/_V/cms-/:S/_src$//:tl}
CATEGORIES= graphics
MASTER_SITES= http://www.argyllcms.com/
@@ -22,7 +22,7 @@ PKGCONFIG_OVERRIDE+= zlib/zlib.pc.in
BUILDLINK_TRANSFORM+= rm:-ldl
-TOOL_DEPENDS+= jam>=2.5.2:../../devel/jam
+BUILD_DEPENDS+= jam>=2.5.2:../../devel/jam
do-build:
cd ${WRKSRC} && ${SETENV} DESTDIR=${DESTDIR} PREFIX=${PREFIX} \
@@ -36,9 +36,6 @@ do-install:
${MV} ${DESTDIR}${PREFIX}/bin/License.txt \
${DESTDIR}${PREFIX}/share/argyll/
-#post-install:
-# ${STRIP} ${DESTDIR}${PREFIX}/bin/*
-
.include "../../x11/libXinerama/buildlink3.mk"
.include "../../x11/libXrandr/buildlink3.mk"
.include "../../x11/xorgproto/buildlink3.mk"
diff --git a/argyllcms/PLIST b/argyllcms/PLIST
index 7a7532bf2a..d48ca466cf 100644
--- a/argyllcms/PLIST
+++ b/argyllcms/PLIST
@@ -8,6 +8,7 @@ bin/chartread
bin/collink
bin/colprof
bin/colverify
+bin/cxf2ti3
bin/dispcal
bin/dispread
bin/dispwin
@@ -19,6 +20,7 @@ bin/greytiff
bin/iccdump
bin/iccgamut
bin/icclu
+bin/iccvcgt
bin/illumread
bin/invprofcheck
bin/kodak2ti3
@@ -47,20 +49,28 @@ bin/viewgam
bin/xicclu
share/argyll/License.txt
share/argyll/ref/3dap5k.sp
+share/argyll/ref/ACES_P3.icm
share/argyll/ref/CIE_C.sp
share/argyll/ref/CMP_DT_003.cht
+share/argyll/ref/CMP_DT_mini.cht
+share/argyll/ref/CMP_Digital_Target-2019.cht
share/argyll/ref/CMP_Digital_Target-4.cht
share/argyll/ref/CMP_Digital_Target-4.cie
share/argyll/ref/CMP_Digital_Target-4.ti2
share/argyll/ref/CMP_Digital_Target-7.cht
+share/argyll/ref/CMP_Digital_Target_Studio.cht
share/argyll/ref/ClayRGB1998.icm
share/argyll/ref/ColorChecker.cht
share/argyll/ref/ColorChecker.cie
share/argyll/ref/ColorChecker.ti2
share/argyll/ref/ColorCheckerDC.cht
share/argyll/ref/ColorCheckerDC.ti2
+share/argyll/ref/ColorCheckerHalfPassport.cht
+share/argyll/ref/ColorCheckerHalfPassport.cie
+share/argyll/ref/ColorCheckerHalfPassport.ti2
share/argyll/ref/ColorCheckerPassport.cht
share/argyll/ref/ColorCheckerPassport.cie
+share/argyll/ref/ColorCheckerPassport.ti2
share/argyll/ref/ColorCheckerSG.cht
share/argyll/ref/ColorCheckerSG.ti2
share/argyll/ref/D50_0.0.sp
@@ -75,6 +85,7 @@ share/argyll/ref/D50_1.7.sp
share/argyll/ref/D50_2.0.sp
share/argyll/ref/D50_2.5.sp
share/argyll/ref/D50_3.0.sp
+share/argyll/ref/DisplayP3.icm
share/argyll/ref/EBU3213_PAL.icm
share/argyll/ref/ECI2002.ti2
share/argyll/ref/ECI2002R.ti2
@@ -87,6 +98,10 @@ share/argyll/ref/FograStrip3.ti1
share/argyll/ref/FograStrip3_3.ti2
share/argyll/ref/GTIPlus.sp
share/argyll/ref/Hutchcolor.cht
+share/argyll/ref/ISO12641_2_1.cht
+share/argyll/ref/ISO12641_2_3_1.cht
+share/argyll/ref/ISO12641_2_3_2.cht
+share/argyll/ref/ISO12641_2_3_3.cht
share/argyll/ref/LaserSoftDCPro.cht
share/argyll/ref/Office.sp
share/argyll/ref/ProPhoto.icm
@@ -113,6 +128,7 @@ share/argyll/ref/example121.sp
share/argyll/ref/i1_RGB_Scan_1.4.cht
share/argyll/ref/i1_RGB_Scan_1.4.ti2
share/argyll/ref/it8.cht
+share/argyll/ref/it8Wolf.cht
share/argyll/ref/lab2lab.icm
share/argyll/ref/linear.cal
share/argyll/ref/sRGB.icm
diff --git a/argyllcms/distinfo b/argyllcms/distinfo
index 77eb29ae2b..badfb56a21 100644
--- a/argyllcms/distinfo
+++ b/argyllcms/distinfo
@@ -1,9 +1,12 @@
$NetBSD$
-RMD160 (Argyll_V2.0.1_src.zip) = c6fd956ae9e5171b88e1cb5c8576b1deb42c60aa
-SHA512 (Argyll_V2.0.1_src.zip) = d0755d1837fa000278f390d9d101c1e9de3f2e294583c8b67b37f74f0ca6190917bfddd5ce50a39a274aefeeca304aaebdfd11db391521e222da2368a2881c0e
-Size (Argyll_V2.0.1_src.zip) = 13606682 bytes
-SHA1 (patch-Jamtop) = 397fb2370b444a4c28d2d617519d626eb7eee1a5
-SHA1 (patch-spectro_hidio.c) = b0190685bc8a7a4b0f2025562f143eb1887971dd
+BLAKE2s (Argyll_V3.0.2_src.zip) = 6b5ae8db701693424e0bb4b5670089e866984cef20cb86e49316748bc153d9bf
+SHA512 (Argyll_V3.0.2_src.zip) = befd9f3a1b06b8a403deaed38dd01cf93ae511bf200a37cae4516455050f0178fe51c6fa705579093795f2043ca19e7f79facd165f9e888cf80a3684fb586745
+Size (Argyll_V3.0.2_src.zip) = 14202724 bytes
+SHA1 (patch-Jamtop) = 2d68e70172ea3f5c651a9d6367489ada08f258ea
+SHA1 (patch-spectro_Jamfile) = 1e40d46df292dc73b55163c66e7bb4c7f89acf19
+SHA1 (patch-spectro_hidio.c) = cf9bae6bf2032ce5184c0760991aa3fe8f206fed
+SHA1 (patch-spectro_hidio.h) = cdf6600dd0c346fcc1e6b2d514e8a488dc3c771f
SHA1 (patch-spectro_icoms__ux.c) = 729883ffb5c7060a9b87b23f8eb79fd6458e13f4
-SHA1 (patch-spectro_usbio.c) = 84570916fa25b14f27c607cba188d3836b5505e3
+SHA1 (patch-spectro_usbio.c) = decbe4f2e4d359e10678dbf6ad46d79bf9e16a21
+SHA1 (patch-spectro_usbio__bsd.c) = afe1ec7565bb2226dd525e65e14353e98c75c1ed
diff --git a/argyllcms/patches/patch-Jamtop b/argyllcms/patches/patch-Jamtop
index 6e2f5eed1d..0b72b89aea 100644
--- a/argyllcms/patches/patch-Jamtop
+++ b/argyllcms/patches/patch-Jamtop
@@ -4,11 +4,11 @@ Search and use pkgsrc ${X11BASE} and ${PREFIX} paths.
Recognize pkgsrc libpng16.so (somewhat haphazardly).
Recognize NetBSD.
---- Jamtop.orig 2018-07-09 02:56:56.000000000 +0000
+--- Jamtop.orig 2023-10-23 00:55:56.000000000 +0000
+++ Jamtop
-@@ -82,7 +82,11 @@ if $(UNIX) {
- LINKFLAGS += -framework AppKit ;
+@@ -83,7 +83,11 @@ if $(UNIX) {
+ # Hmm. Would be nice to use pkg-config here, if system has it.
} else {
- if [ GLOB /usr/X11R6/include/X11 : X.h ] {
+ if [ GLOB $(X11BASE)/include/X11 : X.h ] {
@@ -19,7 +19,7 @@ Recognize NetBSD.
LibWinH = /usr/X11R6/include ;
} else if [ GLOB /usr/include/X11 : X.h ] {
LibWinH = /usr/include ;
-@@ -93,7 +97,11 @@ if $(UNIX) {
+@@ -94,7 +98,11 @@ if $(UNIX) {
}
if $(HOST64) {
@@ -32,7 +32,7 @@ Recognize NetBSD.
LibWinD = /usr/X11R6/lib ;
} else if [ GLOB /usr/lib/x86_64-linux-gnu : libX11.so libX11.a ] {
LibWinD = /usr/lib/x86_64-linux-gnu ;
-@@ -107,7 +115,11 @@ if $(UNIX) {
+@@ -108,7 +116,11 @@ if $(UNIX) {
ECHO Unable to locate the 64 bit X11 library files ;
}
} else {
@@ -45,17 +45,17 @@ Recognize NetBSD.
LibWinD = /usr/X11R6/lib ;
} else if [ GLOB /usr/lib/i386-linux-gnu : libX11.so libX11.a ] {
LibWinD = /usr/lib/i386-linux-gnu ;
-@@ -122,6 +134,9 @@ if $(UNIX) {
+@@ -123,6 +135,9 @@ if $(UNIX) {
if $(OS) = FREEBSD {
LINKFLAGS += -g -lrt -lusb ;
GUILINKFLAGS += -L$(LibWinD) -g -lX11 -lXext -lXxf86vm -lXinerama -lXrandr -lXau -lXdmcp -lXss ;
+ } else if $(OS) = NETBSD {
-+ LINKFLAGS += -L$(PREFIX)/lib ${COMPILER_RPATH_FLAG}$(PREFIX)/lib -g -lrt ;
++ LINKFLAGS += -L$(PREFIX)/lib ${COMPILER_RPATH_FLAG}$(PREFIX)/lib -g -lrt -lusbhid ;
+ GUILINKFLAGS += -L$(LibWinD) ${COMPILER_RPATH_FLAG}$(LibWinD) -g -lX11 -lXext -lXxf86vm -lXinerama -lXrandr -lXau -lXdmcp -lXss ;
} else if $(OS) = OPENBSD {
LINKFLAGS += ;
GUILINKFLAGS += -L$(LibWinD) -g -lX11 -lXext -lXxf86vm -lXinerama -lXrandr -lXau -lXdmcp -lXss -L/usr/local/lib ;
-@@ -152,11 +167,14 @@ rule CheckForLibrary {
+@@ -153,11 +168,14 @@ rule CheckForLibrary {
}
if ! $(BUILTIN_$(UCASE)) && $(UNIX) {
diff --git a/argyllcms/patches/patch-spectro_Jamfile b/argyllcms/patches/patch-spectro_Jamfile
new file mode 100644
index 0000000000..dcd33c06c4
--- /dev/null
+++ b/argyllcms/patches/patch-spectro_Jamfile
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Try to make linking work on NetBSD 9.3
+
+--- spectro/Jamfile.orig 2023-10-23 00:56:14.000000000 +0000
++++ spectro/Jamfile
+@@ -166,7 +166,7 @@ LINKLIBS = libinst libinstapp
+ ../ccast/libccast $(SSLLIB) ../yajl/libyajl
+ $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIB)
+ ../numlib/libui libconv ../numlib/libnum
+- $(CMMLIBS) ;
++ $(CMMLIBS) libconv ;
+
+ if $(LIBUSB_IS_DLL) = true {
+ LINKSHLIBS = $(LIBUSBDIR)/$(LIBUSB) ;
diff --git a/argyllcms/patches/patch-spectro_hidio.c b/argyllcms/patches/patch-spectro_hidio.c
index 5dd4fedb81..be03c22941 100644
--- a/argyllcms/patches/patch-spectro_hidio.c
+++ b/argyllcms/patches/patch-spectro_hidio.c
@@ -2,14 +2,168 @@ $NetBSD$
Recognize NetBSD.
---- spectro/hidio.c.orig 2018-07-09 02:57:13.000000000 +0000
+--- spectro/hidio.c.orig 2023-10-23 00:56:17.000000000 +0000
+++ spectro/hidio.c
-@@ -89,7 +89,7 @@
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
--#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
-+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+@@ -92,6 +92,10 @@
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
#include <sys/types.h>
#include <usbhid.h>
++#elif defined(__NetBSD__)
++#include <glob.h>
++#include <dev/usb/usb.h>
++#include <usbhid.h>
#else /* assume Linux */
+ # include <asm/types.h>
+ # include <linux/hiddev.h>
+@@ -432,11 +436,54 @@ int hid_get_paths(icompaths *p) {
+ #endif /* UNIX_APPLE */
+
+ #if defined(UNIX_X11)
++#if defined(__NetBSD__)
++ {
++ int i;
++ int fd;
++ glob_t g;
++ const char *uhid_glob = "/dev/uhid[0-9]*";
++ struct usb_device_info udi;
++ devType itype;
++
++ if (glob(uhid_glob, GLOB_NOSORT, NULL, &g) != 0) {
++ return ICOM_SYS;
++ }
++
++ for (i = 0; i < g.gl_pathc; i++) {
++ struct hid_idevice *hidd;
++ if ((fd = open(g.gl_pathv[i], O_RDONLY)) < 0)
++ continue;
++
++ if (ioctl(fd, USB_GET_DEVICEINFO, &udi) < 0) {
++ a1logd(p->log, 6, "hid_get_paths: USB_GET_DEVICEINFO failed\n");
++ close(fd);
++ continue;
++ }
++ close(fd);
+
++ /* Do a preliminary match */
++ if ((itype = inst_usb_match(udi.udi_vendorNo, udi.udi_productNo, 0)) == instUnknown) {
++ a1logd(p->log, 6, "hid_get_paths: instrument not reconized\n");
++ continue;
++ }
++ if ((hidd = (struct hid_idevice *) calloc(sizeof(struct hid_idevice), 1)) == NULL) {
++ a1loge(p->log, 6, "hid_get_paths() calloc failed!\n");
++ return ICOM_SYS;
++ }
++ if ((hidd->dpath = strdup(g.gl_pathv[i])) == NULL) {
++ a1loge(p->log, 6, "hid_get_paths() strdup failed!\n");
++ return ICOM_SYS;
++ }
++ p->add_hid(p, hidd->dpath, udi.udi_vendorNo, udi.udi_productNo, 0, hidd, itype);
++ }
++
++ globfree(&g);
++ }
++#elif defined NEVER
+ /* This is how we'd go about adding HID support for Linux, IF it */
+ /* was actually capable of communicating application composed reports - */
+ /* which it is not, so HID seems pretty busted on Linux.. */
+-#ifdef NEVER
++
+ /* We need to scan for /dev/hiddev* or /dev/usb/hiddev* device names, */
+ /* and then read their vid & pid */
+ {
+@@ -652,6 +699,24 @@ char **pnames /* List of process names
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif /* UNIX_APPLE */
+
++#if defined(UNIX_X11) && defined(__NetBSD__)
++ static int hid_inited;
++ if (!hid_inited) {
++ hid_init(NULL);
++ hid_inited = 1;
++ }
++ p->hidd->fd = open(p->hidd->dpath, O_RDWR);
++ if (p->hidd->fd < 0)
++ return ICOM_SYS;
++ report_desc_t rd = hid_get_report_desc(p->hidd->fd);
++ p->hidd->rchunk = hid_report_size(rd, hid_input, 0);
++ p->hidd->wchunk = hid_report_size(rd, hid_output, 0);
++ hid_dispose_report_desc(rd);
++
++ if (p->hidd->rchunk <= 0 || p->hidd->wchunk <= 0)
++ return ICOM_SYS;
++#endif
++
+ p->is_open = 1;
+ a1logd(p->log, 8, "hid_open_port: HID port is now open\n");
+ }
+@@ -709,6 +774,10 @@ void hid_close_port(icoms *p) {
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif /* UNIX_APPLE */
+
++#if defined(UNIX_X11) && defined(__NetBSD__)
++ close(p->hidd->fd);
++#endif
++
+ p->is_open = 0;
+ a1logd(p->log, 8, "hid_close_port: has been released and closed\n");
+ }
+@@ -907,6 +976,19 @@ printf("~1 IOHIDDeviceGet returned 0x%x\
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif /* UNIX_APPLE */
+
++#if defined(UNIX_X11) && defined(__NetBSD__)
++ if (bsize % p->hidd->rchunk != 0)
++ return ICOM_SYS; /* XXX right error code? */
++ for (size_t i = 0; i < bsize; i += p->hidd->rchunk) {
++ ssize_t ret;
++ ret = read(p->hidd->fd, &rbuf[i], p->hidd->rchunk);
++ if (ret < 0)
++ return ICOM_SYS; /* XXX right error code? */
++ else
++ bread += ret;
++ }
++#endif
++
+ if (breadp != NULL)
+ *breadp = bread;
+
+@@ -1047,6 +1129,19 @@ printf("~1 IOHIDDeviceSetReportWithCallb
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif /* UNIX_APPLE */
+
++#if defined(UNIX_X11) && defined(__NetBSD__)
++ if (bsize % p->hidd->wchunk != 0)
++ return ICOM_SYS; /* XXX right error code? */
++ for (size_t i = 0; i < bsize; i += p->hidd->wchunk) {
++ ssize_t ret;
++ ret = write(p->hidd->fd, &wbuf[i], p->hidd->wchunk);
++ if (ret < 0)
++ return ICOM_SYS; /* XXX right error code? */
++ else
++ bwritten + ret;
++ }
++#endif
++
+ if (bwrittenp != NULL)
+ *bwrittenp = bwritten;
+
+@@ -1117,6 +1212,10 @@ int hid_copy_hid_idevice(icoms *d, icomp
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif /* UNIX_APPLE */
+ #if defined (UNIX_X11)
++ if ((d->hidd->dpath = strdup(s->hidd->dpath)) == NULL) {
++ a1loge(d->log, ICOM_SYS, "hid_copy_hid_idevice: malloc\n");
++ return ICOM_SYS;
++ }
+ #endif
+ return ICOM_OK;
+ }
+@@ -1140,6 +1239,8 @@ void hid_del_hid_idevice(struct hid_idev
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif /* UNIX_APPLE */
+ #if defined (UNIX_X11)
++ if (hidd->dpath != NULL)
++ free(hidd->dpath);
+ #endif
+ free(hidd);
+ }
diff --git a/argyllcms/patches/patch-spectro_hidio.h b/argyllcms/patches/patch-spectro_hidio.h
new file mode 100644
index 0000000000..76a5b6806b
--- /dev/null
+++ b/argyllcms/patches/patch-spectro_hidio.h
@@ -0,0 +1,22 @@
+$NetBSD$
+
+Attempt to add NetBSD support to spectro/hidio
+
+--- spectro/hidio.h.orig 2023-10-23 00:56:17.000000000 +0000
++++ spectro/hidio.h
+@@ -80,6 +80,15 @@ struct hid_idevice {
+ int bread; /* Bytes read by callback */
+ #endif /* __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
+ #endif
++#if defined(UNIX_X11)
++#if defined(__NetBSD__)
++ char *dpath; /* Device path */
++ /* Stuff setup when device is open: */
++ int fd; /* file descriptor */
++ int rchunk;
++ int wchunk;
++#endif
++#endif
+ };
+
+ /* Cleanup and then free an hidd entry */
diff --git a/argyllcms/patches/patch-spectro_usbio.c b/argyllcms/patches/patch-spectro_usbio.c
index b7adc6f5ae..7c37201db4 100644
--- a/argyllcms/patches/patch-spectro_usbio.c
+++ b/argyllcms/patches/patch-spectro_usbio.c
@@ -1,15 +1,15 @@
$NetBSD$
-Recognize NetBSD.
+Attempt to add NetBSD support to spectro/usbio
---- spectro/usbio.c.orig 2018-07-09 02:57:13.000000000 +0000
+--- spectro/usbio.c.orig 2023-10-23 00:56:17.000000000 +0000
+++ spectro/usbio.c
-@@ -95,7 +95,7 @@ static int icoms_usb_wait_io(
- # include "usbio_ox.c"
- # endif
- # if defined(UNIX_X11)
--# if defined(__FreeBSD__) || defined(__OpenBSD__)
+@@ -96,7 +96,7 @@ static int icoms_usb_wait_io(
+ # include "usbio_ox.c"
+ #endif
+ #if defined(UNIX_X11)
+-# if defined(__FreeBSD__) || defined(__OpenBSD__)
+# if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__)
- # include "usbio_bsd.c"
- # else
- # include "usbio_lx.c"
+ # include "usbio_bsd.c"
+ # else
+ # include "usbio_lx.c"
diff --git a/argyllcms/patches/patch-spectro_usbio__bsd.c b/argyllcms/patches/patch-spectro_usbio__bsd.c
new file mode 100644
index 0000000000..29a330d35c
--- /dev/null
+++ b/argyllcms/patches/patch-spectro_usbio__bsd.c
@@ -0,0 +1,515 @@
+$NetBSD$
+
+Attempt to make actually function with NetBSD ugen(4).
+
+--- spectro/usbio_bsd.c.orig 2023-10-23 00:56:17.000000000 +0000
++++ spectro/usbio_bsd.c
+@@ -67,13 +67,15 @@ icompaths *p
+ #if defined(__FreeBSD__)
+ "/dev/usb/[0-9]*.*.0", /* FreeBSD >= 8 */
+ "/dev/ugen[0-9]*", /* FreeBSD < 8, but no .E */
++#elif defined(__NetBSD__)
++ "/dev/ugen[0-9]*.00", /* NetBSD */
+ #else
+- "/dev/ugen/[0-9]*.00", /* NetBSD, OpenBSD */
++ "/dev/ugen/[0-9]*.00", /* OpenBSD */
+ #endif
+ NULL
+ };
+ int vid, pid;
+- int nconfig = 0, nep = 0;
++ unsigned int configix, nconfig, nep;
+ char *dpath;
+ devType itype;
+ struct usb_idevice *usbd = NULL;
+@@ -85,6 +87,9 @@ icompaths *p
+ glob_t g;
+ int fd;
+ struct usb_device_info di;
++ usb_device_descriptor_t udd;
++ struct usb_interface_desc uid;
++ struct usb_config_desc ucd;
+ int rv, found = 0;
+
+ if (paths[j] == NULL)
+@@ -121,12 +126,8 @@ icompaths *p
+ continue;
+ }
+
+- // ~~99 need to check number of end points ~~~
+- // ~~99 and number of configs
+- nconfig = 1;
+-
+-//USB_GET_DEVICEINFO struct usb_device_info
+-//USB_GET_DEVICE_DESC struct usb_device_descriptor
++ if (ioctl(fd, USB_GET_DEVICE_DESC, &udd) < 0)
++ continue;
+
+ /* Allocate an idevice so that we can fill in the end point information */
+ if ((usbd = (struct usb_idevice *) calloc(sizeof(struct usb_idevice), 1)) == NULL) {
+@@ -136,8 +137,56 @@ icompaths *p
+ return ICOM_SYS;
+ }
+
+- usbd->nconfig = nconfig;
++ usbd->nconfig = nconfig = udd.bNumConfigurations;
+
++ /* Read the configuration descriptors looking for the first configuration, first interface, */
++ /* and extract the number of end points for each configuration */
++ for (configix = 0; configix < nconfig; configix++) {
++ ucd.ucd_config_index = configix;
++ if (ioctl(fd, USB_GET_CONFIG_DESC, &ucd) < 0) {
++ free(usbd);
++ close(fd);
++ break;
++ }
++ usbd->nifce = ucd.ucd_desc.bNumInterface;
++ usbd->config = ucd.ucd_desc.bConfigurationValue;
++
++ if (ucd.ucd_desc.bConfigurationValue != 1)
++ continue;
++
++ uid.uid_config_index = USB_CURRENT_CONFIG_INDEX;
++ uid.uid_interface_index = 0;
++ uid.uid_alt_index = USB_CURRENT_ALT_INDEX;
++
++ if (ioctl(fd, USB_GET_INTERFACE_DESC, &uid) < 0) {
++ break;
++ }
++
++ nep = uid.uid_desc.bNumEndpoints;
++
++ unsigned int epix;
++ struct usb_endpoint_desc ued;
++ for (epix = 0; epix < nep; epix++) {
++ ued.ued_config_index = USB_CURRENT_CONFIG_INDEX;
++ ued.ued_interface_index = 0;
++ ued.ued_alt_index = USB_CURRENT_ALT_INDEX;
++ ued.ued_endpoint_index = epix;
++ if (ioctl(fd, USB_GET_ENDPOINT_DESC, &ued) < 0) {
++ break;
++ }
++
++ const unsigned int ad = ued.ued_desc.bEndpointAddress;
++ usbd->EPINFO(ad).valid = 1;
++ usbd->EPINFO(ad).addr = ad;
++ usbd->EPINFO(ad).packetsize = UGETW(ued.ued_desc.wMaxPacketSize);
++ usbd->EPINFO(ad).type = ued.ued_desc.bmAttributes & IUSB_ENDPOINT_TYPE_MASK;
++ usbd->EPINFO(ad).interface = uid.uid_desc.bInterfaceNumber;
++ usbd->EPINFO(ad).fd = -1;
++
++ a1logd(p->log, 6, "set ep ad 0x%x packetsize %d type %d\n",ad,usbd->EPINFO(ad).packetsize,usbd->EPINFO(ad).type);
++ }
++ }
++
+ /* Found a known instrument ? */
+ if ((itype = inst_usb_match(vid, pid, nep)) != instUnknown) {
+ char pname[400], *cp;
+@@ -310,7 +359,6 @@ char **pnames /* List of process names
+ if (p->is_open)
+ p->close_port(p);
+
+-#ifdef NEVER // ~~99
+ /* Make sure the port is open */
+ if (!p->is_open) {
+ int rv, i, iface;
+@@ -345,12 +393,16 @@ char **pnames /* List of process names
+ p->cconfig = 1;
+
+ if (p->cconfig != config) {
++#if 0
+ if ((rv = ioctl(p->usbd->fd, USBDEVFS_SETCONFIGURATION, &config)) != 0) {
+ a1logd(p->log, 1, "icoms_usb_setconfig failed with %d\n",rv);
+ return ICOM_SYS;
+ }
+ p->cconfig = config;
+ a1logd(p->log, 6, "usb_open_port: set config %d OK\n",config);
++#else
++ a1logd(p->log, 6, "usb_open_port: set config %d unimplemented\n",config);
++#endif
+ }
+
+ /* We're done */
+@@ -363,6 +415,7 @@ char **pnames /* List of process names
+ /* Claim all the interfaces */
+ for (iface = 0; iface < p->nifce; iface++) {
+
++#if 0
+ if ((rv = ioctl(p->usbd->fd, USBDEVFS_CLAIMINTERFACE, &iface)) < 0) {
+ struct usbdevfs_getdriver getd;
+ getd.interface = iface;
+@@ -387,6 +440,30 @@ char **pnames /* List of process names
+ return ICOM_SYS;
+ }
+ }
++#endif
++ }
++
++ char epdpath[33];
++ snprintf(epdpath, sizeof(epdpath), "%s.%02d", p->usbd->dpath, 0);
++ int fd;
++ fd = open(epdpath, O_RDWR);
++ p->ep[0].fd = fd;
++
++ for (int i = 1; i < 16; i++) {
++ int flg;
++ if (p->ep[i].valid && p->ep[i+16].valid)
++ flg = O_RDWR;
++ else if (p->ep[i].valid)
++ flg = O_WRONLY;
++ else if (p->ep[i+16].valid)
++ flg = O_RDONLY;
++ else
++ continue;
++
++ snprintf(epdpath, sizeof(epdpath), "%s.%02d", p->usbd->dpath, i);
++ int fd = open(epdpath, flg);
++
++ p->ep[i].fd = p->ep[i+16].fd = fd;
+ }
+
+ /* Clear any errors. */
+@@ -408,25 +485,10 @@ char **pnames /* List of process names
+ p->rd_qa = 8;
+ a1logd(p->log, 8, "usb_open_port: 'serial' read quanta = packet size = %d\n",p->rd_qa);
+
+- /* Start the reaper thread to handle URB completions */
+- if ((rv = pipe(p->usbd->sd_pipe)) < 0) {
+- a1loge(p->log, ICOM_SYS, "usb_open_port: creat pipe failed with %d\n",rv);
+- return ICOM_SYS;
+- }
+- pthread_mutex_init(&p->usbd->lock, NULL);
+-
+- p->usbd->running = 1;
+- if ((rv = pthread_create(&p->usbd->thread, NULL, urb_reaper, (void*)p)) < 0) {
+- p->usbd->running = 0;
+- a1loge(p->log, ICOM_SYS, "usb_open_port: creating urb reaper thread failed with %s\n",rv);
+- return ICOM_SYS;
+- }
+-
+ p->is_open = 1;
+ a1logd(p->log, 8, "usb_open_port: USB port is now open\n");
+ }
+
+-#endif // ~~99
+ /* Install the cleanup signal handlers, and add to our cleanup list */
+ usb_install_signal_handlers(p);
+
+@@ -445,88 +507,23 @@ static int icoms_usb_transaction(
+ int length,
+ unsigned int timeout /* In msec */
+ ) {
+- int type;
+ int remlen;
+ unsigned char *bp;
+- int xlength = 0;
++ ssize_t xlength = 0;
+ int i;
+ int reqrv = ICOM_OK;
+
+-#ifdef NEVER // ~~99
+ in_usb_rw++;
+ a1logd(p->log, 8, "icoms_usb_transaction: req type 0x%x ep 0x%x size %d\n",ttype,endpoint,length);
+
+- if (!p->usbd->running) {
+- in_usb_rw--;
+- a1logv(p->log, 1, "icoms_usb_transaction: reaper thread is not running\n");
+- return ICOM_SYS;
+- }
++ /* XXX USB_SET_TIMEOUT */
+
+- /* Translate icoms transfer type of Linux */
+- switch (ttype) {
+- case icom_usb_trantype_command:
+- type = USBDEVFS_URB_TYPE_CONTROL;
+- break;
+- case icom_usb_trantype_interrutpt:
+- type = USBDEVFS_URB_TYPE_INTERRUPT;
+- break;
+- case icom_usb_trantype_bulk:
+- type = USBDEVFS_URB_TYPE_BULK;
+- break;
+- }
++ if ((endpoint & IUSB_ENDPOINT_DIR_MASK) == IUSB_ENDPOINT_OUT)
++ xlength = write(p->ep[endpoint&0xf].fd, buffer, length);
++ else
++ xlength = read(p->ep[endpoint&0xf].fd, buffer, length);
+
+- /* Setup the icom req and urbs */
+- req.urbs = NULL;
+- pthread_mutex_init(&req.lock, NULL);
+- pthread_cond_init(&req.cond, NULL);
+-
+- /* Linux historically only copes with 16384 length urbs, */
+- /* so break up longer requests into multiple urbs */
+-
+- req.cancelled = 0;
+- req.nourbs = req.nurbs = (length + (1 << 14)-1) >> 14;
+- if ((req.urbs = (usbio_urb *)calloc(sizeof(usbio_urb), req.nourbs)) == NULL) {
+- in_usb_rw--;
+- a1loge(p->log, ICOM_SYS, "icoms_usb_transaction: control transfer too big! (%d)\n",length);
+- return ICOM_SYS;
+- }
+-
+- bp = buffer;
+- remlen = length;
+- for (i = 0; i < req.nurbs; i++) {
+- req.urbs[i].req = &req;
+- req.urbs[i].urbno = i;
+- /* Setup Linux URB */
+- req.urbs[i].urb.usercontext = &req.urbs[i];
+- req.urbs[i].urb.type = type;
+- if (type != USBDEVFS_URB_TYPE_CONTROL)
+- req.urbs[i].urb.endpoint = endpoint;
+- if (remlen > 16384)
+- req.urbs[i].urb.buffer_length = 16384;
+- else
+- req.urbs[i].urb.buffer_length = remlen;
+- req.urbs[i].urb.buffer = (void *)bp;
+- remlen -= req.urbs[i].urb.buffer_length;
+- bp += req.urbs[i].urb.buffer_length;
+- req.urbs[i].urb.status = -EINPROGRESS;
+- }
+-a1logd(p->log, 8, "icoms_usb_transaction: reset req %p nourbs to %d\n",&req,req.nourbs);
+-
+- /* Add our request to the req list so that it can be cancelled on reap failure */
+- pthread_mutex_lock(&p->usbd->lock);
+- req.next = p->usbd->reqs;
+- p->usbd->reqs = &req;
+- pthread_mutex_unlock(&p->usbd->lock);
+-
+- /* submit the URBs */
+- for (i = 0; i < req.nurbs; i++) {
+- if ((rv = ioctl(p->usbd->fd, USBDEVFS_SUBMITURB, &req.urbs[i].urb)) < 0) {
+- a1logd(p->log, 1, "coms_usb_transaction: Submitting urb to fd %d failed with %d\n",p->usbd->fd, rv);
+- req.urbs[i].urb.status = ICOM_SYS; /* Mark it as failed to submit */
+- req.nourbs--;
+- }
+- }
+-
++#if 0
+ if (cancelt != NULL) {
+ amutex_lock(cancelt->cmtx);
+ cancelt->hcancel = (void *)&req;
+@@ -534,85 +531,7 @@ a1logd(p->log, 8, "icoms_usb_transaction
+ amutex_unlock(cancelt->cond); /* Signal any thread waiting for IO start */
+ amutex_unlock(cancelt->cmtx);
+ }
+-
+- /* Wait for the reaper to wake us, or for a timeout, */
+- /* or for the reaper to die. */
+- pthread_mutex_lock(&req.lock);
+- if (req.nourbs > 0) {
+- struct timeval tv;
+- struct timespec ts;
+-
+- // this is unduly complicated...
+- gettimeofday(&tv, NULL);
+- ts.tv_sec = tv.tv_sec + timeout/1000;
+- ts.tv_nsec = (tv.tv_usec + (timeout % 1000) * 1000) * 1000L;
+- if (ts.tv_nsec > 1000000000L) {
+- ts.tv_nsec -= 1000000000L;
+- ts.tv_sec++;
+- }
+-
+- for(;;) { /* Ignore spurious wakeups */
+- if ((rv = pthread_cond_timedwait(&req.cond, &req.lock, &ts)) != 0) {
+- if (rv != ETIMEDOUT) {
+- pthread_mutex_unlock(&req.lock);
+- a1logd(p->log, 1, "coms_usb_transaction: pthread_cond_timedwait failed with %d\n",rv);
+- rv = ICOM_SYS;
+- goto done;
+- }
+-
+- /* Timed out - cancel the remaining URB's */
+- a1logd(p->log, 8, "coms_usb_transaction: time out - cancel remaining URB's\n");
+- reqrv = ICOM_TO;
+- if (!req.cancelled && (rv = cancel_req(p, &req, -1)) != ICOM_OK) {
+- pthread_mutex_unlock(&req.lock);
+- reqrv = ICOM_SYS;
+- /* Since cancelling failed, we can't wait for them to be reaped */
+- goto done;
+- }
+-
+- /* Wait for the cancelled URB's to be reaped */
+- for (;req.nourbs > 0;) { /* Ignore spurious wakeups */
+- if ((rv = pthread_cond_wait(&req.cond, &req.lock)) != 0) {
+- pthread_mutex_unlock(&req.lock);
+- a1logd(p->log, 1, "coms_usb_transaction: pthread_cond_wait failed with %d\n",rv);
+- reqrv = ICOM_SYS;
+- /* Waiting for reap failed, so give up */
+- goto done;
+- }
+- }
+- } else {
+- a1logd(p->log, 8, "coms_usb_transaction: reap - %d left\n",req.nourbs);
+- }
+- if (req.nourbs <= 0)
+- break; /* All urbs's are done */
+- }
+- }
+- pthread_mutex_unlock(&req.lock);
+-
+- /* Compute the overall result by going through the urbs. */
+- for (i = 0; i < req.nurbs; i++) {
+- int stat = req.urbs[i].urb.status;
+- xlength += req.urbs[i].urb.actual_length;
+-
+- if (stat == ICOM_SYS) { /* Submit or cancel failed */
+- reqrv = ICOM_SYS;
+- } else if (reqrv == ICOM_OK && stat < 0 && stat != -ECONNRESET) { /* Error result */
+- if ((endpoint & IUSB_ENDPOINT_DIR_MASK) == IUSB_ENDPOINT_OUT)
+- reqrv = ICOM_USBW;
+- else
+- reqrv = ICOM_USBR;
+- } else if (reqrv == ICOM_OK && stat == -ECONNRESET) { /* Cancelled */
+- reqrv = ICOM_CANC;
+- } else if (reqrv == ICOM_OK
+- && req.urbs[i].urb.actual_length < req.urbs[i].urb.buffer_length) {
+- /* Disregard any following urb's status - they are probably cancelled */
+- break;
+- }
+- /* reqrv == ICOM_TO will ignore urb status */
+- }
+-
+- if (ttype == icom_usb_trantype_command)
+- xlength += IUSB_REQ_HEADER_SIZE; /* Account for header - linux doesn't */
++#endif
+
+ /* requested size wasn't transferred ? */
+ if (reqrv == ICOM_OK && xlength != length)
+@@ -621,6 +540,7 @@ a1logd(p->log, 8, "icoms_usb_transaction
+ if (transferred != NULL)
+ *transferred = xlength;
+
++#if 0
+ done:;
+ if (cancelt != NULL) {
+ amutex_lock(cancelt->cmtx);
+@@ -630,20 +550,7 @@ done:;
+ cancelt->state = 2;
+ amutex_unlock(cancelt->cmtx);
+ }
+-
+- /* Remove our request from the list */
+- pthread_mutex_lock(&p->usbd->lock);
+- preq = &p->usbd->reqs;
+- while (*preq != &req && *preq != NULL) /* Find it */
+- preq = &((*preq)->next);
+- if (*preq != NULL)
+- *preq = (*preq)->next;
+- pthread_mutex_unlock(&p->usbd->lock);
+-
+- if (req.urbs != NULL)
+- free(req.urbs);
+- pthread_cond_destroy(&req.cond);
+- pthread_mutex_destroy(&req.lock);
++#endif
+
+ if (in_usb_rw < 0)
+ exit(0);
+@@ -651,7 +558,6 @@ done:;
+ in_usb_rw--;
+
+ a1logd(p->log, 8, "coms_usb_transaction: returning err 0x%x and %d bytes\n",reqrv, xlength);
+-#endif // ~~99
+
+ return reqrv;
+ }
+@@ -666,51 +572,34 @@ int value, int index, unsigned char *byt
+ int timeout) {
+ int reqrv = ICOM_OK;
+ int dirw = (requesttype & IUSB_REQ_DIR_MASK) == IUSB_REQ_HOST_TO_DEV ? 1 : 0;
+- unsigned char *buf;
++ struct usb_ctl_request ucr;
+
+ a1logd(p->log, 8, "icoms_usb_control_msg: type 0x%x req 0x%x size %d\n",requesttype,request,size);
+
+-#ifdef NEVER // ~~99
+- /* Allocate a buffer for the ctrl header + payload */
+- if ((buf = calloc(1, IUSB_REQ_HEADER_SIZE + size)) == NULL) {
+- a1loge(p->log, ICOM_SYS, "icoms_usb_control_msg: calloc failed\n");
+- return ICOM_SYS;
+- }
+-
++ ucr.ucr_addr = 0;
+ /* Setup the control header */
+- buf[0] = requesttype;
+- buf[1] = request;
+- short2buf(buf + 2, value);
+- short2buf(buf + 4, index);
+- short2buf(buf + 6, size);
+-
+- /* If it's a write, copy the write data into the buffer */
+- if (dirw)
+- memcpy(buf + IUSB_REQ_HEADER_SIZE, bytes, size);
+-
+- reqrv = icoms_usb_transaction(p, NULL, transferred, icom_usb_trantype_command,
+- dirw ? 0x80 : 0x00, buf, IUSB_REQ_HEADER_SIZE + size, timeout);
+-
+- /* If read, copy the data back */
+- if (!dirw)
+- memcpy(bytes, buf + IUSB_REQ_HEADER_SIZE, size);
++ ucr.ucr_request.bmRequestType = requesttype;
++ ucr.ucr_request.bRequest = request;
++ USETW(ucr.ucr_request.wValue, value);
++ USETW(ucr.ucr_request.wIndex, index);
++ USETW(ucr.ucr_request.wLength, size);
++ ucr.ucr_data = bytes;
++ ucr.ucr_flags = USBD_SHORT_XFER_OK;
++ ucr.ucr_actlen = 0;
+
+- if (transferred != NULL) /* Adjust for header size requested */
+- *transferred -= IUSB_REQ_HEADER_SIZE;
++ /* XXX USB_SET_TIMEOUT */
+
+- free(buf);
++ if (ioctl(p->ep[0].fd, USB_DO_REQUEST, &ucr) < 0)
++ return ICOM_SYS; /* XXX */
++
++ if (transferred != NULL)
++ *transferred = ucr.ucr_actlen;
+
+-#endif // ~~99
+ a1logd(p->log, 8, "icoms_usb_control_msg: returning err 0x%x and %d bytes\n",reqrv, *transferred);
+ return reqrv;
+ }
+
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+-/* Time out error return value */
+-
+-#define USBIO_ERROR_TIMEOUT -ETIMEDOUT
+-
+-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+ /* Cancel i/o in another thread */
+ int icoms_usb_cancel_io(
+@@ -718,8 +607,9 @@ int icoms_usb_cancel_io(
+ usb_cancelt *cancelt
+ ) {
+ int rv = ICOM_OK;
+-#ifdef NEVER // ~~99
++
+ a1logd(p->log, 8, "icoms_usb_cancel_io called\n");
++#ifdef NEVER // ~~99
+ usb_lock_cancel(cancelt);
+ if (cancelt->hcancel != NULL)
+ rv = cancel_req(p, (usbio_req *)cancelt->hcancel, -1);
+@@ -740,6 +630,8 @@ int icoms_usb_resetep(
+ ) {
+ int rv = ICOM_OK;
+
++ a1logd(p->log, 1, "icoms_usb_resetep unimplemented with %d\n",rv);
++
+ #ifdef NEVER // ~~99
+ if ((rv = ioctl(p->usbd->fd, USBDEVFS_RESETEP, &ep)) != 0) {
+ a1logd(p->log, 1, "icoms_usb_resetep failed with %d\n",rv);
+@@ -757,6 +649,8 @@ int icoms_usb_clearhalt(
+ ) {
+ int rv = ICOM_OK;
+
++ a1logd(p->log, 1, "icoms_usb_clearhalt unimplemented with %d\n",rv);
++
+ #ifdef NEVER // ~~99
+ if ((rv = ioctl(p->usbd->fd, USBDEVFS_CLEAR_HALT, &ep)) != 0) {
+ a1logd(p->log, 1, "icoms_usb_clearhalt failed with %d\n",rv);
diff --git a/argyllcms/wip-patch-spectro_usbio__bsd.c b/argyllcms/wip-patch-spectro_usbio__bsd.c
deleted file mode 100644
index fcb2130e72..0000000000
--- a/argyllcms/wip-patch-spectro_usbio__bsd.c
+++ /dev/null
@@ -1,570 +0,0 @@
-$NetBSD$
-
-Attempt to make actually function with NetBSD ugen(4).
-
---- spectro/usbio_bsd.c.orig 2018-07-09 02:57:13.000000000 +0000
-+++ spectro/usbio_bsd.c
-@@ -67,13 +67,15 @@ icompaths *p
- #if defined(__FreeBSD__)
- "/dev/usb/[0-9]*.*.0", /* FreeBSD >= 8 */
- "/dev/ugen[0-9]*", /* FreeBSD < 8, but no .E */
-+#elif defined(__NetBSD__)
-+ "/dev/ugen[0-9]*.00", /* NetBSD */
- #else
-- "/dev/ugen/[0-9]*.00", /* NetBSD, OpenBSD */
-+ "/dev/ugen/[0-9]*.00", /* OpenBSD */
- #endif
- NULL
- };
- int vid, pid;
-- int nconfig = 0, nep = 0;
-+ unsigned int configix, nconfig, nep;
- char *dpath;
- devType itype;
- struct usb_idevice *usbd = NULL;
-@@ -85,6 +87,9 @@ icompaths *p
- glob_t g;
- int fd;
- struct usb_device_info di;
-+ usb_device_descriptor_t udd;
-+ struct usb_interface_desc uid;
-+ struct usb_config_desc ucd;
- int rv, found = 0;
-
- if (paths[j] == NULL)
-@@ -121,12 +126,8 @@ icompaths *p
- continue;
- }
-
-- // ~~99 need to check number of end points ~~~
-- // ~~99 and number of configs
-- nconfig = 1;
--
--//USB_GET_DEVICEINFO struct usb_device_info
--//USB_GET_DEVICE_DESC struct usb_device_descriptor
-+ if (ioctl(fd, USB_GET_DEVICE_DESC, &udd) < 0)
-+ continue;
-
- /* Allocate an idevice so that we can fill in the end point information */
- if ((usbd = (struct usb_idevice *) calloc(sizeof(struct usb_idevice), 1)) == NULL) {
-@@ -136,8 +137,56 @@ icompaths *p
- return ICOM_SYS;
- }
-
-- usbd->nconfig = nconfig;
-+ usbd->nconfig = nconfig = udd.bNumConfigurations;
-
-+ /* Read the configuration descriptors looking for the first configuration, first interface, */
-+ /* and extract the number of end points for each configuration */
-+ for (configix = 0; configix < nconfig; configix++) {
-+ ucd.ucd_config_index = configix;
-+ if (ioctl(fd, USB_GET_CONFIG_DESC, &ucd) < 0) {
-+ free(usbd);
-+ close(fd);
-+ break;
-+ }
-+ usbd->nifce = ucd.ucd_desc.bNumInterface;
-+ usbd->config = ucd.ucd_desc.bConfigurationValue;
-+
-+ if (ucd.ucd_desc.bConfigurationValue != 1)
-+ continue;
-+
-+ uid.uid_config_index = USB_CURRENT_CONFIG_INDEX;
-+ uid.uid_interface_index = 0;
-+ uid.uid_alt_index = USB_CURRENT_ALT_INDEX;
-+
-+ if (ioctl(fd, USB_GET_INTERFACE_DESC, &uid) < 0) {
-+ break;
-+ }
-+
-+ nep = uid.uid_desc.bNumEndpoints;
-+
-+ unsigned int epix;
-+ struct usb_endpoint_desc ued;
-+ for (epix = 0; epix < nep; epix++) {
-+ ued.ued_config_index = USB_CURRENT_CONFIG_INDEX;
-+ ued.ued_interface_index = 0;
-+ ued.ued_alt_index = USB_CURRENT_ALT_INDEX;
-+ ued.ued_endpoint_index = epix;
-+ if (ioctl(fd, USB_GET_ENDPOINT_DESC, &ued) < 0) {
-+ break;
-+ }
-+
-+ const unsigned int ad = ued.ued_desc.bEndpointAddress;
-+ usbd->EPINFO(ad).valid = 1;
-+ usbd->EPINFO(ad).addr = ad;
-+ usbd->EPINFO(ad).packetsize = UGETW(ued.ued_desc.wMaxPacketSize);
-+ usbd->EPINFO(ad).type = ued.ued_desc.bmAttributes & IUSB_ENDPOINT_TYPE_MASK;
-+ usbd->EPINFO(ad).interface = uid.uid_desc.bInterfaceNumber;
-+ usbd->EPINFO(ad).fd = -1;
-+
-+ a1logd(p->log, 6, "set ep ad 0x%x packetsize %d type %d\n",ad,usbd->EPINFO(ad).packetsize,usbd->EPINFO(ad).type);
-+ }
-+ }
-+
- /* Found a known instrument ? */
- if ((itype = inst_usb_match(vid, pid, nep)) != instUnknown) {
- char pname[400], *cp;
-@@ -245,52 +294,18 @@ void usb_close_port(icoms *p) {
-
- a1logd(p->log, 6, "usb_close_port: called\n");
-
--#ifdef NEVER // ~~99
- if (p->is_open && p->usbd != NULL) {
-- struct usbdevfs_urb urb;
-- unsigned char buf[8+IUSB_DESC_TYPE_DEVICE_SIZE];
-- int iface, rv;
--
-- /* Release all the interfaces */
-- for (iface = 0; iface < p->nifce; iface++)
-- ioctl(p->usbd->fd, USBDEVFS_RELEASEINTERFACE, &iface);
--
-- /* Workaround for some bugs - reset device on close */
-- if (p->uflags & icomuf_reset_before_close) {
-- if ((rv = ioctl(p->usbd->fd, USBDEVFS_RESET, NULL)) != 0) {
-- a1logd(p->log, 1, "usb_close_port: reset returned %d\n",rv);
-- }
-- }
--
-- if (p->usbd->running) { /* If reaper is still running */
-- unsigned char buf[1] = { 0 };
--
-- a1logd(p->log, 6, "usb_close_port: waking reaper thread to trigger exit\n");
-- p->usbd->shutdown = 1;
--
-- if (write(p->usbd->sd_pipe[1], buf, 1) < 1) {
-- a1logd(p->log, 1, "usb_close_port: writing to sd_pipe failed with '%s'\n", strerror(errno));
-- /* Hmm. We could be in trouble ? */
-- }
-+ for (int i = 15; i >= 0; i--) {
-+ close(p->ep[i].fd);
- }
-- a1logd(p->log, 6, "usb_close_port: waiting for reaper thread\n");
-- pthread_join(p->usbd->thread, NULL); /* Wait for urb reaper thread to exit */
-- close(p->usbd->fd);
-- pthread_mutex_destroy(&p->usbd->lock);
-- close(p->usbd->sd_pipe[0]);
-- close(p->usbd->sd_pipe[1]);
--
- a1logd(p->log, 6, "usb_close_port: usb port has been released and closed\n");
- }
- p->is_open = 0;
--#endif // ~~99
-
- /* Find it and delete it from our static cleanup list */
- usb_delete_from_cleanup_list(p);
- }
-
--static void *urb_reaper(void *context); /* Declare */
--
- /* Open a USB port for all our uses. */
- /* This always re-opens the port */
- /* return icom error */
-@@ -309,7 +324,6 @@ char **pnames /* List of process names
- if (p->is_open)
- p->close_port(p);
-
--#ifdef NEVER // ~~99
- /* Make sure the port is open */
- if (!p->is_open) {
- int rv, i, iface;
-@@ -344,12 +358,16 @@ char **pnames /* List of process names
- p->cconfig = 1;
-
- if (p->cconfig != config) {
-+#if 0
- if ((rv = ioctl(p->usbd->fd, USBDEVFS_SETCONFIGURATION, &config)) != 0) {
- a1logd(p->log, 1, "icoms_usb_setconfig failed with %d\n",rv);
- return ICOM_SYS;
- }
- p->cconfig = config;
- a1logd(p->log, 6, "usb_open_port: set config %d OK\n",config);
-+#else
-+ a1logd(p->log, 6, "usb_open_port: set config %d unimplemented\n",config);
-+#endif
- }
-
- /* We're done */
-@@ -362,6 +380,7 @@ char **pnames /* List of process names
- /* Claim all the interfaces */
- for (iface = 0; iface < p->nifce; iface++) {
-
-+#if 0
- if ((rv = ioctl(p->usbd->fd, USBDEVFS_CLAIMINTERFACE, &iface)) < 0) {
- struct usbdevfs_getdriver getd;
- getd.interface = iface;
-@@ -386,6 +405,30 @@ char **pnames /* List of process names
- return ICOM_SYS;
- }
- }
-+#endif
-+ }
-+
-+ char epdpath[33];
-+ snprintf(epdpath, sizeof(epdpath), "%s.%02d", p->usbd->dpath, 0);
-+ int fd;
-+ fd = open(epdpath, O_RDWR);
-+ p->ep[0].fd = fd;
-+
-+ for (int i = 1; i < 16; i++) {
-+ int flg;
-+ if (p->ep[i].valid && p->ep[i+16].valid)
-+ flg = O_RDWR;
-+ else if (p->ep[i].valid)
-+ flg = O_WRONLY;
-+ else if (p->ep[i+16].valid)
-+ flg = O_RDONLY;
-+ else
-+ continue;
-+
-+ snprintf(epdpath, sizeof(epdpath), "%s.%02d", p->usbd->dpath, i);
-+ int fd = open(epdpath, flg);
-+
-+ p->ep[i].fd = p->ep[i+16].fd = fd;
- }
-
- /* Clear any errors. */
-@@ -407,25 +450,10 @@ char **pnames /* List of process names
- p->rd_qa = 8;
- a1logd(p->log, 8, "usb_open_port: 'serial' read quanta = packet size = %d\n",p->rd_qa);
-
-- /* Start the reaper thread to handle URB completions */
-- if ((rv = pipe(p->usbd->sd_pipe)) < 0) {
-- a1loge(p->log, ICOM_SYS, "usb_open_port: creat pipe failed with %d\n",rv);
-- return ICOM_SYS;
-- }
-- pthread_mutex_init(&p->usbd->lock, NULL);
--
-- p->usbd->running = 1;
-- if ((rv = pthread_create(&p->usbd->thread, NULL, urb_reaper, (void*)p)) < 0) {
-- p->usbd->running = 0;
-- a1loge(p->log, ICOM_SYS, "usb_open_port: creating urb reaper thread failed with %s\n",rv);
-- return ICOM_SYS;
-- }
--
- p->is_open = 1;
- a1logd(p->log, 8, "usb_open_port: USB port is now open\n");
- }
-
--#endif // ~~99
- /* Install the cleanup signal handlers, and add to our cleanup list */
- usb_install_signal_handlers(p);
-
-@@ -444,88 +472,23 @@ static int icoms_usb_transaction(
- int length,
- unsigned int timeout /* In msec */
- ) {
-- int type;
- int remlen;
- unsigned char *bp;
-- int xlength = 0;
-+ ssize_t xlength = 0;
- int i;
- int reqrv = ICOM_OK;
-
--#ifdef NEVER // ~~99
- in_usb_rw++;
- a1logd(p->log, 8, "icoms_usb_transaction: req type 0x%x ep 0x%x size %d\n",ttype,endpoint,length);
-
-- if (!p->usbd->running) {
-- in_usb_rw--;
-- a1logv(p->log, 1, "icoms_usb_transaction: reaper thread is not running\n");
-- return ICOM_SYS;
-- }
-+ /* XXX USB_SET_TIMEOUT */
-
-- /* Translate icoms transfer type of Linux */
-- switch (ttype) {
-- case icom_usb_trantype_command:
-- type = USBDEVFS_URB_TYPE_CONTROL;
-- break;
-- case icom_usb_trantype_interrutpt:
-- type = USBDEVFS_URB_TYPE_INTERRUPT;
-- break;
-- case icom_usb_trantype_bulk:
-- type = USBDEVFS_URB_TYPE_BULK;
-- break;
-- }
--
-- /* Setup the icom req and urbs */
-- req.urbs = NULL;
-- pthread_mutex_init(&req.lock, NULL);
-- pthread_cond_init(&req.cond, NULL);
--
-- /* Linux historically only copes with 16384 length urbs, */
-- /* so break up longer requests into multiple urbs */
--
-- req.cancelled = 0;
-- req.nourbs = req.nurbs = (length + (1 << 14)-1) >> 14;
-- if ((req.urbs = (usbio_urb *)calloc(sizeof(usbio_urb), req.nourbs)) == NULL) {
-- in_usb_rw--;
-- a1loge(p->log, ICOM_SYS, "icoms_usb_transaction: control transfer too big! (%d)\n",length);
-- return ICOM_SYS;
-- }
-+ if ((endpoint & IUSB_ENDPOINT_DIR_MASK) == IUSB_ENDPOINT_OUT)
-+ xlength = write(p->ep[endpoint&0xf].fd, buffer, length);
-+ else
-+ xlength = read(p->ep[endpoint&0xf].fd, buffer, length);
-
-- bp = buffer;
-- remlen = length;
-- for (i = 0; i < req.nurbs; i++) {
-- req.urbs[i].req = &req;
-- req.urbs[i].urbno = i;
-- /* Setup Linux URB */
-- req.urbs[i].urb.usercontext = &req.urbs[i];
-- req.urbs[i].urb.type = type;
-- if (type != USBDEVFS_URB_TYPE_CONTROL)
-- req.urbs[i].urb.endpoint = endpoint;
-- if (remlen > 16384)
-- req.urbs[i].urb.buffer_length = 16384;
-- else
-- req.urbs[i].urb.buffer_length = remlen;
-- req.urbs[i].urb.buffer = (void *)bp;
-- remlen -= req.urbs[i].urb.buffer_length;
-- bp += req.urbs[i].urb.buffer_length;
-- req.urbs[i].urb.status = -EINPROGRESS;
-- }
--a1logd(p->log, 8, "icoms_usb_transaction: reset req %p nourbs to %d\n",&req,req.nourbs);
--
-- /* Add our request to the req list so that it can be cancelled on reap failure */
-- pthread_mutex_lock(&p->usbd->lock);
-- req.next = p->usbd->reqs;
-- p->usbd->reqs = &req;
-- pthread_mutex_unlock(&p->usbd->lock);
--
-- /* submit the URBs */
-- for (i = 0; i < req.nurbs; i++) {
-- if ((rv = ioctl(p->usbd->fd, USBDEVFS_SUBMITURB, &req.urbs[i].urb)) < 0) {
-- a1logd(p->log, 1, "coms_usb_transaction: Submitting urb to fd %d failed with %d\n",p->usbd->fd, rv);
-- req.urbs[i].urb.status = ICOM_SYS; /* Mark it as failed to submit */
-- req.nourbs--;
-- }
-- }
--
-+#if 0
- if (cancelt != NULL) {
- amutex_lock(cancelt->cmtx);
- cancelt->hcancel = (void *)&req;
-@@ -533,85 +496,7 @@ a1logd(p->log, 8, "icoms_usb_transaction
- amutex_unlock(cancelt->cond); /* Signal any thread waiting for IO start */
- amutex_unlock(cancelt->cmtx);
- }
--
-- /* Wait for the reaper to wake us, or for a timeout, */
-- /* or for the reaper to die. */
-- pthread_mutex_lock(&req.lock);
-- if (req.nourbs > 0) {
-- struct timeval tv;
-- struct timespec ts;
--
-- // this is unduly complicated...
-- gettimeofday(&tv, NULL);
-- ts.tv_sec = tv.tv_sec + timeout/1000;
-- ts.tv_nsec = (tv.tv_usec + (timeout % 1000) * 1000) * 1000L;
-- if (ts.tv_nsec > 1000000000L) {
-- ts.tv_nsec -= 1000000000L;
-- ts.tv_sec++;
-- }
--
-- for(;;) { /* Ignore spurious wakeups */
-- if ((rv = pthread_cond_timedwait(&req.cond, &req.lock, &ts)) != 0) {
-- if (rv != ETIMEDOUT) {
-- pthread_mutex_unlock(&req.lock);
-- a1logd(p->log, 1, "coms_usb_transaction: pthread_cond_timedwait failed with %d\n",rv);
-- rv = ICOM_SYS;
-- goto done;
-- }
--
-- /* Timed out - cancel the remaining URB's */
-- a1logd(p->log, 8, "coms_usb_transaction: time out - cancel remaining URB's\n");
-- reqrv = ICOM_TO;
-- if (!req.cancelled && (rv = cancel_req(p, &req, -1)) != ICOM_OK) {
-- pthread_mutex_unlock(&req.lock);
-- reqrv = ICOM_SYS;
-- /* Since cancelling failed, we can't wait for them to be reaped */
-- goto done;
-- }
--
-- /* Wait for the cancelled URB's to be reaped */
-- for (;req.nourbs > 0;) { /* Ignore spurious wakeups */
-- if ((rv = pthread_cond_wait(&req.cond, &req.lock)) != 0) {
-- pthread_mutex_unlock(&req.lock);
-- a1logd(p->log, 1, "coms_usb_transaction: pthread_cond_wait failed with %d\n",rv);
-- reqrv = ICOM_SYS;
-- /* Waiting for reap failed, so give up */
-- goto done;
-- }
-- }
-- } else {
-- a1logd(p->log, 8, "coms_usb_transaction: reap - %d left\n",req.nourbs);
-- }
-- if (req.nourbs <= 0)
-- break; /* All urbs's are done */
-- }
-- }
-- pthread_mutex_unlock(&req.lock);
--
-- /* Compute the overall result by going through the urbs. */
-- for (i = 0; i < req.nurbs; i++) {
-- int stat = req.urbs[i].urb.status;
-- xlength += req.urbs[i].urb.actual_length;
--
-- if (stat == ICOM_SYS) { /* Submit or cancel failed */
-- reqrv = ICOM_SYS;
-- } else if (reqrv == ICOM_OK && stat < 0 && stat != -ECONNRESET) { /* Error result */
-- if ((endpoint & IUSB_ENDPOINT_DIR_MASK) == IUSB_ENDPOINT_OUT)
-- reqrv = ICOM_USBW;
-- else
-- reqrv = ICOM_USBR;
-- } else if (reqrv == ICOM_OK && stat == -ECONNRESET) { /* Cancelled */
-- reqrv = ICOM_CANC;
-- } else if (reqrv == ICOM_OK
-- && req.urbs[i].urb.actual_length < req.urbs[i].urb.buffer_length) {
-- /* Disregard any following urb's status - they are probably cancelled */
-- break;
-- }
-- /* reqrv == ICOM_TO will ignore urb status */
-- }
--
-- if (ttype == icom_usb_trantype_command)
-- xlength += IUSB_REQ_HEADER_SIZE; /* Account for header - linux doesn't */
-+#endif
-
- /* requested size wasn't transferred ? */
- if (reqrv == ICOM_OK && xlength != length)
-@@ -620,6 +505,7 @@ a1logd(p->log, 8, "icoms_usb_transaction
- if (transferred != NULL)
- *transferred = xlength;
-
-+#if 0
- done:;
- if (cancelt != NULL) {
- amutex_lock(cancelt->cmtx);
-@@ -629,20 +515,7 @@ done:;
- cancelt->state = 2;
- amutex_unlock(cancelt->cmtx);
- }
--
-- /* Remove our request from the list */
-- pthread_mutex_lock(&p->usbd->lock);
-- preq = &p->usbd->reqs;
-- while (*preq != &req && *preq != NULL) /* Find it */
-- preq = &((*preq)->next);
-- if (*preq != NULL)
-- *preq = (*preq)->next;
-- pthread_mutex_unlock(&p->usbd->lock);
--
-- if (req.urbs != NULL)
-- free(req.urbs);
-- pthread_cond_destroy(&req.cond);
-- pthread_mutex_destroy(&req.lock);
-+#endif
-
- if (in_usb_rw < 0)
- exit(0);
-@@ -650,7 +523,6 @@ done:;
- in_usb_rw--;
-
- a1logd(p->log, 8, "coms_usb_transaction: returning err 0x%x and %d bytes\n",reqrv, xlength);
--#endif // ~~99
-
- return reqrv;
- }
-@@ -665,51 +537,34 @@ int value, int index, unsigned char *byt
- int timeout) {
- int reqrv = ICOM_OK;
- int dirw = (requesttype & IUSB_REQ_DIR_MASK) == IUSB_REQ_HOST_TO_DEV ? 1 : 0;
-- unsigned char *buf;
-+ struct usb_ctl_request ucr;
-
- a1logd(p->log, 8, "icoms_usb_control_msg: type 0x%x req 0x%x size %d\n",requesttype,request,size);
-
--#ifdef NEVER // ~~99
-- /* Allocate a buffer for the ctrl header + payload */
-- if ((buf = calloc(1, IUSB_REQ_HEADER_SIZE + size)) == NULL) {
-- a1loge(p->log, ICOM_SYS, "icoms_usb_control_msg: calloc failed\n");
-- return ICOM_SYS;
-- }
--
-+ ucr.ucr_addr = 0;
- /* Setup the control header */
-- buf[0] = requesttype;
-- buf[1] = request;
-- short2buf(buf + 2, value);
-- short2buf(buf + 4, index);
-- short2buf(buf + 6, size);
--
-- /* If it's a write, copy the write data into the buffer */
-- if (dirw)
-- memcpy(buf + IUSB_REQ_HEADER_SIZE, bytes, size);
--
-- reqrv = icoms_usb_transaction(p, NULL, transferred, icom_usb_trantype_command,
-- dirw ? 0x80 : 0x00, buf, IUSB_REQ_HEADER_SIZE + size, timeout);
--
-- /* If read, copy the data back */
-- if (!dirw)
-- memcpy(bytes, buf + IUSB_REQ_HEADER_SIZE, size);
-+ ucr.ucr_request.bmRequestType = requesttype;
-+ ucr.ucr_request.bRequest = request;
-+ USETW(ucr.ucr_request.wValue, value);
-+ USETW(ucr.ucr_request.wIndex, index);
-+ USETW(ucr.ucr_request.wLength, size);
-+ ucr.ucr_data = bytes;
-+ ucr.ucr_flags = USBD_SHORT_XFER_OK;
-+ ucr.ucr_actlen = 0;
-
-- if (transferred != NULL) /* Adjust for header size requested */
-- *transferred -= IUSB_REQ_HEADER_SIZE;
-+ /* XXX USB_SET_TIMEOUT */
-
-- free(buf);
-+ if (ioctl(p->ep[0].fd, USB_DO_REQUEST, &ucr) < 0)
-+ return ICOM_SYS; /* XXX */
-+
-+ if (transferred != NULL)
-+ *transferred = ucr.ucr_actlen;
-
--#endif // ~~99
- a1logd(p->log, 8, "icoms_usb_control_msg: returning err 0x%x and %d bytes\n",reqrv, *transferred);
- return reqrv;
- }
-
- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
--/* Time out error return value */
--
--#define USBIO_ERROR_TIMEOUT -ETIMEDOUT
--
--/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-
- /* Cancel i/o in another thread */
- int icoms_usb_cancel_io(
-@@ -717,8 +572,9 @@ int icoms_usb_cancel_io(
- usb_cancelt *cancelt
- ) {
- int rv = ICOM_OK;
--#ifdef NEVER // ~~99
-+
- a1logd(p->log, 8, "icoms_usb_cancel_io called\n");
-+#ifdef NEVER // ~~99
- usb_lock_cancel(cancelt);
- if (cancelt->hcancel != NULL)
- rv = cancel_req(p, (usbio_req *)cancelt->hcancel, -1);
-@@ -739,6 +595,8 @@ int icoms_usb_resetep(
- ) {
- int rv = ICOM_OK;
-
-+ a1logd(p->log, 1, "icoms_usb_resetep unimplemented with %d\n",rv);
-+
- #ifdef NEVER // ~~99
- if ((rv = ioctl(p->usbd->fd, USBDEVFS_RESETEP, &ep)) != 0) {
- a1logd(p->log, 1, "icoms_usb_resetep failed with %d\n",rv);
-@@ -756,6 +614,8 @@ int icoms_usb_clearhalt(
- ) {
- int rv = ICOM_OK;
-
-+ a1logd(p->log, 1, "icoms_usb_clearhalt unimplemented with %d\n",rv);
-+
- #ifdef NEVER // ~~99
- if ((rv = ioctl(p->usbd->fd, USBDEVFS_CLEAR_HALT, &ep)) != 0) {
- a1logd(p->log, 1, "icoms_usb_clearhalt failed with %d\n",rv);
Home |
Main Index |
Thread Index |
Old Index