summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorgrehan <grehan@FreeBSD.org>2011-06-30 17:37:42 +0000
committergrehan <grehan@FreeBSD.org>2011-06-30 17:37:42 +0000
commitcebb6ff778bc230fa6cd369286b316ad6f9414b5 (patch)
treef90e6332e59ffb9573a64f8a2475203ee54f3816 /lib
parent2c6741be0f59191f2283eb268e4f7690399d578a (diff)
parent2b9b009195e403f0f2fc9bf0d9eeefc2297d94b8 (diff)
downloadFreeBSD-src-cebb6ff778bc230fa6cd369286b316ad6f9414b5.zip
FreeBSD-src-cebb6ff778bc230fa6cd369286b316ad6f9414b5.tar.gz
IFC @ r223696 to pick up dfr's userboot
Diffstat (limited to 'lib')
-rw-r--r--lib/csu/powerpc64/Makefile14
-rw-r--r--lib/libc/gen/getutxent.34
-rw-r--r--lib/libc/gen/posix_spawn.32
-rw-r--r--lib/libc/gen/posix_spawn.c4
-rw-r--r--lib/libc/gen/pututxline.c4
-rw-r--r--lib/libc/stdlib/malloc.c2
-rw-r--r--lib/libc/stdlib/ptsname.c2
-rw-r--r--lib/libmd/sha256.32
-rw-r--r--lib/libmd/sha512.32
-rw-r--r--lib/libprocstat/Makefile2
-rw-r--r--lib/libstand/tftp.c183
-rw-r--r--lib/libusb/Makefile4
-rw-r--r--lib/libusb/libusb01.c (renamed from lib/libusb/libusb20_compat01.c)0
-rw-r--r--lib/libusb/libusb10.c2
-rw-r--r--lib/libusb/libusb20.323
-rw-r--r--lib/libusb/libusb20.c12
-rw-r--r--lib/libusb/libusb20.h2
-rw-r--r--lib/libusb/libusb20_int.h2
-rw-r--r--lib/libusb/libusb20_ugen20.c5
19 files changed, 203 insertions, 68 deletions
diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile
index 04926ad..095a9ad 100644
--- a/lib/csu/powerpc64/Makefile
+++ b/lib/csu/powerpc64/Makefile
@@ -4,15 +4,14 @@
SRCS= crt1.c crti.S crtn.S
OBJS= ${SRCS:N*.h:R:S/$/.o/g}
-OBJS+= gcrt1.o
-CFLAGS+= -Wall -Wno-unused \
- -I${.CURDIR}/../common \
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
-I${.CURDIR}/../../libc/include
all: ${OBJS}
CLEANFILES= ${OBJS}
-CLEANFILES+= crt1.s gcrt1.s
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
# directly compiled to .o files.
@@ -31,6 +30,13 @@ gcrt1.s: crt1.c
gcrt1.o: gcrt1.s
${CC} ${CFLAGS} -c -o ${.TARGET} gcrt1.s
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1.s
+
realinstall:
${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${OBJS} ${DESTDIR}${LIBDIR}
diff --git a/lib/libc/gen/getutxent.3 b/lib/libc/gen/getutxent.3
index 5c8b793..1920555 100644
--- a/lib/libc/gen/getutxent.3
+++ b/lib/libc/gen/getutxent.3
@@ -175,7 +175,7 @@ prefix, corresponding with the device used to facilitate the user login
session.
If no TTY character device is used, this field is left blank.
This field is only applicable to entries of type
-.Dv USER_PROCESS
+.Dv USER_PROCESS
and
.Dv LOGIN_PROCESS .
.It Fa ut_host
@@ -473,7 +473,7 @@ are extensions.
.Sh HISTORY
These functions appeared in
.Fx 9.0 .
-They replaced the
+They replaced the
.In utmp.h
interface.
.Sh AUTHORS
diff --git a/lib/libc/gen/posix_spawn.3 b/lib/libc/gen/posix_spawn.3
index 3d902bf..73359b4 100644
--- a/lib/libc/gen/posix_spawn.3
+++ b/lib/libc/gen/posix_spawn.3
@@ -167,7 +167,7 @@ group IDs for the child process are changed as specified in the
attributes object referenced by
.Fa attrp .
.It
-The file actions specified by the spawn file actions object are
+The file actions specified by the spawn file actions object are
performed in the order in which they were added to the spawn file
actions object.
.It
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
index 58044b3..e4ceb20 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -182,7 +182,7 @@ process_file_actions(const posix_spawn_file_actions_t fa)
if (error)
return (error);
}
- return (0);
+ return (0);
}
static int
@@ -193,7 +193,7 @@ do_posix_spawn(pid_t *pid, const char *path,
{
pid_t p;
volatile int error = 0;
-
+
p = vfork();
switch (p) {
case -1:
diff --git a/lib/libc/gen/pututxline.c b/lib/libc/gen/pututxline.c
index 4caa00c..0cc7a01 100644
--- a/lib/libc/gen/pututxline.c
+++ b/lib/libc/gen/pututxline.c
@@ -57,7 +57,7 @@ futx_open(const char *file)
errno = EFTYPE;
return (NULL);
}
-
+
fp = fdopen(fd, "r+");
if (fp == NULL) {
_close(fd);
@@ -103,7 +103,7 @@ utx_active_add(const struct futx *fu)
/* Allow us to overwrite unused records. */
if (partial == -1) {
partial = ftello(fp);
- /*
+ /*
* Distinguish errors from valid values so we
* don't overwrite good data by accident.
*/
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 48d9c14..5290512 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -234,7 +234,7 @@ __FBSDID("$FreeBSD$");
#ifdef __sparc64__
# define LG_QUANTUM 4
# define LG_SIZEOF_PTR 3
-# define TLS_MODEL /* default */
+# define TLS_MODEL __attribute__((tls_model("initial-exec")))
#endif
#ifdef __amd64__
# define LG_QUANTUM 4
diff --git a/lib/libc/stdlib/ptsname.c b/lib/libc/stdlib/ptsname.c
index fc3b719..40b140d 100644
--- a/lib/libc/stdlib/ptsname.c
+++ b/lib/libc/stdlib/ptsname.c
@@ -82,7 +82,7 @@ ptsname(int fildes)
/* Make sure fildes points to a master device. */
if (__isptmaster(fildes) != 0)
goto done;
-
+
if (fdevname_r(fildes, pt_slave + (sizeof _PATH_DEV - 1),
sizeof pt_slave - (sizeof _PATH_DEV - 1)) != NULL)
ret = pt_slave;
diff --git a/lib/libmd/sha256.3 b/lib/libmd/sha256.3
index fb96100..f40e6df 100644
--- a/lib/libmd/sha256.3
+++ b/lib/libmd/sha256.3
@@ -127,7 +127,7 @@ argument is non-null it must point to at least 65 characters of buffer space.
.Xr sha 3
.Sh HISTORY
These functions appeared in
-.Fx 4.0 .
+.Fx 6.0 .
.Sh AUTHORS
The core hash routines were implemented by Colin Percival based on
the published
diff --git a/lib/libmd/sha512.3 b/lib/libmd/sha512.3
index 45a4096..953ee25 100644
--- a/lib/libmd/sha512.3
+++ b/lib/libmd/sha512.3
@@ -127,7 +127,7 @@ argument is non-null it must point to at least 65 characters of buffer space.
.Xr sha 3
.Sh HISTORY
These functions appeared in
-.Fx 4.0 .
+.Fx 9.0 .
.Sh AUTHORS
The core hash routines were implemented by Colin Percival based on
the published
diff --git a/lib/libprocstat/Makefile b/lib/libprocstat/Makefile
index e509169..05a64e7 100644
--- a/lib/libprocstat/Makefile
+++ b/lib/libprocstat/Makefile
@@ -19,6 +19,8 @@ INCS= libprocstat.h
CFLAGS+= -I. -I${.CURDIR} -D_KVM_VNODE
SHLIB_MAJOR= 1
WITHOUT_MAN= yes
+DPADD= ${LIBKVM} ${LIBUTIL}
+LDADD= -lkvm -lutil
.if ${MK_NCP} != "no"
CFLAGS+= -DLIBPROCSTAT_NWFS
diff --git a/lib/libstand/tftp.c b/lib/libstand/tftp.c
index 54e184c..bf92c04 100644
--- a/lib/libstand/tftp.c
+++ b/lib/libstand/tftp.c
@@ -64,13 +64,13 @@ struct tftp_handle;
static int tftp_open(const char *path, struct open_file *f);
static int tftp_close(struct open_file *f);
-static void tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len);
+static int tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len);
static int tftp_read(struct open_file *f, void *buf, size_t size, size_t *resid);
static int tftp_write(struct open_file *f, void *buf, size_t size, size_t *resid);
static off_t tftp_seek(struct open_file *f, off_t offset, int where);
static int tftp_set_blksize(struct tftp_handle *h, const char *str);
static int tftp_stat(struct open_file *f, struct stat *sb);
-static ssize_t sendrecv_tftp(struct tftp_handle *h,
+static ssize_t sendrecv_tftp(struct tftp_handle *h,
ssize_t (*sproc)(struct iodesc *, void *, size_t),
void *sbuf, size_t ssize,
ssize_t (*rproc)(struct tftp_handle *h, void *, ssize_t, time_t, unsigned short *),
@@ -93,7 +93,7 @@ static int tftpport = 2000;
static int is_open = 0;
/*
- * The legacy TFTP_BLKSIZE value was 512.
+ * The legacy TFTP_BLKSIZE value was SEGSIZE(512).
* TFTP_REQUESTED_BLKSIZE of 1428 is (Ethernet MTU, less the TFTP, UDP and
* IP header lengths).
*/
@@ -102,7 +102,7 @@ static int is_open = 0;
/*
* Choose a blksize big enough so we can test with Ethernet
* Jumbo frames in the future.
- */
+ */
#define TFTP_MAX_BLKSIZE 9008
struct tftp_handle {
@@ -113,7 +113,7 @@ struct tftp_handle {
int off;
char *path; /* saved for re-requests */
unsigned int tftp_blksize;
- unsigned long tftp_tsize;
+ unsigned long tftp_tsize;
struct {
u_char header[HEADER_SIZE];
struct tftphdr t;
@@ -121,7 +121,8 @@ struct tftp_handle {
} __packed __aligned(4) lastdata;
};
-static const int tftperrors[8] = {
+#define TFTP_MAX_ERRCODE EOPTNEG
+static const int tftperrors[TFTP_MAX_ERRCODE + 1] = {
0, /* ??? */
ENOENT,
EPERM,
@@ -129,10 +130,57 @@ static const int tftperrors[8] = {
EINVAL, /* ??? */
EINVAL, /* ??? */
EEXIST,
- EINVAL /* ??? */
+ EINVAL, /* ??? */
+ EINVAL, /* Option negotiation failed. */
};
-static ssize_t
+static int tftp_getnextblock(struct tftp_handle *h);
+
+/* send error message back. */
+static void
+tftp_senderr(struct tftp_handle *h, u_short errcode, const char *msg)
+{
+ struct {
+ u_char header[HEADER_SIZE];
+ struct tftphdr t;
+ u_char space[63]; /* +1 from t */
+ } __packed __aligned(4) wbuf;
+ char *wtail;
+ int len;
+
+ len = strlen(msg);
+ if (len > sizeof(wbuf.space))
+ len = sizeof(wbuf.space);
+
+ wbuf.t.th_opcode = htons((u_short) ERROR);
+ wbuf.t.th_code = htons(errcode);
+
+ wtail = wbuf.t.th_msg;
+ bcopy(msg, wtail, len);
+ wtail[len] = '\0';
+ wtail += len + 1;
+
+ sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t);
+}
+
+static void
+tftp_sendack(struct tftp_handle *h)
+{
+ struct {
+ u_char header[HEADER_SIZE];
+ struct tftphdr t;
+ } __packed __aligned(4) wbuf;
+ char *wtail;
+
+ wbuf.t.th_opcode = htons((u_short) ACK);
+ wtail = (char *) &wbuf.t.th_block;
+ wbuf.t.th_block = htons((u_short) h->currblock);
+ wtail += 2;
+
+ sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t);
+}
+
+static ssize_t
recvtftp(struct tftp_handle *h, void *pkt, ssize_t len, time_t tleft,
unsigned short *rtype)
{
@@ -170,7 +218,7 @@ recvtftp(struct tftp_handle *h, void *pkt, ssize_t len, time_t tleft,
return got;
}
case ERROR:
- if ((unsigned) ntohs(t->th_code) >= 8) {
+ if ((unsigned) ntohs(t->th_code) > TFTP_MAX_ERRCODE) {
printf("illegal tftp error %d\n", ntohs(t->th_code));
errno = EIO;
} else {
@@ -182,14 +230,30 @@ recvtftp(struct tftp_handle *h, void *pkt, ssize_t len, time_t tleft,
return (-1);
case OACK: {
struct udphdr *uh;
- int tftp_oack_len = len - sizeof(t->th_opcode);
- tftp_parse_oack(h, t->th_u.tu_stuff, tftp_oack_len);
+ int tftp_oack_len;
+
+ /*
+ * Unexpected OACK. TFTP transfer already in progress.
+ * Drop the pkt.
+ */
+ if (d->xid != 1) {
+ return (-1);
+ }
+
/*
- * Remember which port this OACK came from,
- * because we need to send the ACK back to it.
+ * Remember which port this OACK came from, because we need
+ * to send the ACK or errors back to it.
*/
uh = (struct udphdr *) pkt - 1;
d->destport = uh->uh_sport;
+
+ /* Parse options ACK-ed by the server. */
+ tftp_oack_len = len - sizeof(t->th_opcode);
+ if (tftp_parse_oack(h, t->th_u.tu_stuff, tftp_oack_len) != 0) {
+ tftp_senderr(h, EOPTNEG, "Malformed OACK");
+ errno = EIO;
+ return (-1);
+ }
return (0);
}
default:
@@ -201,7 +265,7 @@ recvtftp(struct tftp_handle *h, void *pkt, ssize_t len, time_t tleft,
}
/* send request, expect first block (or error) */
-static int
+static int
tftp_makereq(struct tftp_handle *h)
{
struct {
@@ -250,26 +314,28 @@ tftp_makereq(struct tftp_handle *h)
h->iodesc->destport = htons(IPPORT_TFTP);
h->iodesc->xid = 1; /* expected block */
+ h->currblock = 0;
+ h->islastblock = 0;
+ h->validsize = 0;
+
res = sendrecv_tftp(h, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
&recvtftp, t, sizeof(*t) + h->tftp_blksize, &rtype);
- if (rtype == OACK) {
- wbuf.t.th_opcode = htons((u_short)ACK);
- wtail = (char *) &wbuf.t.th_block;
- wbuf.t.th_block = htons(0);
- wtail += 2;
- rtype = 0;
- res = sendrecv_tftp(h, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
- &recvtftp, t, sizeof(*t) + h->tftp_blksize, &rtype);
- }
+ if (rtype == OACK)
+ return (tftp_getnextblock(h));
+
+ /* Server ignored our blksize request, revert to TFTP default. */
+ h->tftp_blksize = SEGSIZE;
switch (rtype) {
case DATA: {
h->currblock = 1;
h->validsize = res;
h->islastblock = 0;
- if (res < h->tftp_blksize)
+ if (res < h->tftp_blksize) {
h->islastblock = 1; /* very short file */
+ tftp_sendack(h);
+ }
return (0);
}
case ERROR:
@@ -320,7 +386,7 @@ tftp_getnextblock(struct tftp_handle *h)
return (0);
}
-static int
+static int
tftp_open(const char *path, struct open_file *f)
{
struct tftp_handle *tftpfile;
@@ -365,7 +431,7 @@ tftp_open(const char *path, struct open_file *f)
return (0);
}
-static int
+static int
tftp_read(struct open_file *f, void *addr, size_t size,
size_t *resid /* out */)
{
@@ -381,9 +447,11 @@ tftp_read(struct open_file *f, void *addr, size_t size,
needblock = tftpfile->off / tftpfile->tftp_blksize + 1;
- if (tftpfile->currblock > needblock) /* seek backwards */
+ if (tftpfile->currblock > needblock) { /* seek backwards */
+ tftp_senderr(tftpfile, 0, "No error: read aborted");
tftp_makereq(tftpfile); /* no error check, it worked
* for open */
+ }
while (tftpfile->currblock < needblock) {
int res;
@@ -452,7 +520,7 @@ tftp_close(struct open_file *f)
return (0);
}
-static int
+static int
tftp_write(struct open_file *f __unused, void *start __unused, size_t size __unused,
size_t *resid __unused /* out */)
{
@@ -473,7 +541,7 @@ tftp_stat(struct open_file *f, struct stat *sb)
return (0);
}
-static off_t
+static off_t
tftp_seek(struct open_file *f, off_t offset, int where)
{
struct tftp_handle *tftpfile;
@@ -494,7 +562,7 @@ tftp_seek(struct open_file *f, off_t offset, int where)
}
static ssize_t
-sendrecv_tftp(struct tftp_handle *h,
+sendrecv_tftp(struct tftp_handle *h,
ssize_t (*sproc)(struct iodesc *, void *, size_t),
void *sbuf, size_t ssize,
ssize_t (*rproc)(struct tftp_handle *, void *, ssize_t, time_t, unsigned short *),
@@ -562,9 +630,9 @@ tftp_set_blksize(struct tftp_handle *h, const char *str)
/*
* Only accept blksize value if it is numeric.
- * RFC2348 specifies that acceptable valuesare 8-65464
- * 8-65464 . Let's choose a limit less than MAXRSPACE
- */
+ * RFC2348 specifies that acceptable values are 8-65464.
+ * Let's choose a limit less than MAXRSPACE.
+ */
if (*endptr == '\0' && new_blksize >= 8
&& new_blksize <= TFTP_MAX_BLKSIZE) {
h->tftp_blksize = new_blksize;
@@ -597,13 +665,12 @@ tftp_set_blksize(struct tftp_handle *h, const char *str)
* optN, valueN
* The final option/value acknowledgment pair.
*/
-static void
+static int
tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len)
{
/*
* We parse the OACK strings into an array
* of name-value pairs.
- *
*/
char *tftp_options[128] = { 0 };
char *val = buf;
@@ -612,18 +679,22 @@ tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len)
int blksize_is_set = 0;
int tsize = 0;
-
- while ( option_idx < 128 && i < len ) {
- if (buf[i] == '\0') {
- if (&buf[i] > val) {
- tftp_options[option_idx] = val;
- val = &buf[i] + 1;
- ++option_idx;
- }
- }
- ++i;
+ unsigned int orig_blksize;
+
+ while (option_idx < 128 && i < len) {
+ if (buf[i] == '\0') {
+ if (&buf[i] > val) {
+ tftp_options[option_idx] = val;
+ val = &buf[i] + 1;
+ ++option_idx;
+ }
+ }
+ ++i;
}
+ /* Save the block size we requested for sanity check later. */
+ orig_blksize = h->tftp_blksize;
+
/*
* Parse individual TFTP options.
* * "blksize" is specified in RFC2348.
@@ -631,27 +702,37 @@ tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len)
*/
for (i = 0; i < option_idx; i += 2) {
if (strcasecmp(tftp_options[i], "blksize") == 0) {
- if (i + 1 < option_idx) {
+ if (i + 1 < option_idx)
blksize_is_set =
tftp_set_blksize(h, tftp_options[i + 1]);
- }
} else if (strcasecmp(tftp_options[i], "tsize") == 0) {
- if (i + 1 < option_idx) {
+ if (i + 1 < option_idx)
tsize = strtol(tftp_options[i + 1], (char **)NULL, 10);
- }
+ } else {
+ /* Do not allow any options we did not expect to be ACKed. */
+ printf("unexpected tftp option '%s'\n", tftp_options[i]);
+ return (-1);
}
}
if (!blksize_is_set) {
/*
* If TFTP blksize was not set, try defaulting
- * to the legacy TFTP blksize of 512
+ * to the legacy TFTP blksize of SEGSIZE(512)
*/
- h->tftp_blksize = 512;
+ h->tftp_blksize = SEGSIZE;
+ } else if (h->tftp_blksize > orig_blksize) {
+ /*
+ * Server should not be proposing block sizes that
+ * exceed what we said we can handle.
+ */
+ printf("unexpected blksize %u\n", h->tftp_blksize);
+ return (-1);
}
#ifdef TFTP_DEBUG
printf("tftp_blksize: %u\n", h->tftp_blksize);
printf("tftp_tsize: %lu\n", h->tftp_tsize);
#endif
+ return 0;
}
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index debbfa2..f438cff 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -22,7 +22,7 @@ MLINKS+= libusb.3 usb.3
# libusb 0.1 compat
INCS+= usb.h
-SRCS+= libusb20_compat01.c
+SRCS+= libusb01.c
# libusb 1.0 compat
INCS+= libusb.h
@@ -184,6 +184,8 @@ MLINKS += libusb20.3 libusb20_dev_get_device_desc.3
MLINKS += libusb20.3 libusb20_dev_alloc_config.3
MLINKS += libusb20.3 libusb20_dev_alloc.3
MLINKS += libusb20.3 libusb20_dev_get_address.3
+MLINKS += libusb20.3 libusb20_dev_get_parent_address.3
+MLINKS += libusb20.3 libusb20_dev_get_parent_port.3
MLINKS += libusb20.3 libusb20_dev_get_bus_number.3
MLINKS += libusb20.3 libusb20_dev_get_mode.3
MLINKS += libusb20.3 libusb20_dev_get_speed.3
diff --git a/lib/libusb/libusb20_compat01.c b/lib/libusb/libusb01.c
index 4124ef6..4124ef6 100644
--- a/lib/libusb/libusb20_compat01.c
+++ b/lib/libusb/libusb01.c
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index fa50ea7..737e610 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -636,7 +636,7 @@ libusb_clear_halt(struct libusb20_device *pdev, uint8_t endpoint)
return (LIBUSB_ERROR_INVALID_PARAM);
CTX_LOCK(dev->ctx);
- err = libusb20_tr_open(xfer, 0, 0, endpoint);
+ err = libusb20_tr_open(xfer, 0, 1, endpoint);
CTX_UNLOCK(dev->ctx);
if (err != 0 && err != LIBUSB20_ERROR_BUSY)
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index 93dfe18..042f885 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -159,6 +159,10 @@ USB access library (libusb -lusb)
.Ft uint8_t
.Fn libusb20_dev_get_address "struct libusb20_device *pdev"
.Ft uint8_t
+.Fn libusb20_dev_get_parent_address "struct libusb20_device *pdev"
+.Ft uint8_t
+.Fn libusb20_dev_get_parent_port "struct libusb20_device *pdev"
+.Ft uint8_t
.Fn libusb20_dev_get_bus_number "struct libusb20_device *pdev"
.Ft uint8_t
.Fn libusb20_dev_get_mode "struct libusb20_device *pdev"
@@ -756,12 +760,31 @@ is an internal function to allocate a new USB device.
.Fn libusb20_dev_get_address
returns the internal and not necessarily the real
hardware address of the given USB device.
+Valid addresses start at one.
+.
+.Pp
+.
+.Fn libusb20_dev_get_parent_address
+returns the internal and not necessarily the real hardware address of
+the given parent USB HUB device.
+This value is zero for the root HUB which usually has a device address
+equal to one.
+Valid addresses start at one.
+.
+.Pp
+.
+.Fn libusb20_dev_get_parent_port
+returns the port number on the parent USB HUB device.
+This value is zero for the root HUB which usually has a device address
+equal to one.
+Valid port numbers start at one.
.
.Pp
.
.Fn libusb20_dev_get_bus_number
returns the internal bus number which the given USB
device belongs to.
+Valid bus numbers start at zero.
.
.Pp
.
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index bcaa1e4..716f540 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -1057,6 +1057,18 @@ libusb20_dev_get_address(struct libusb20_device *pdev)
}
uint8_t
+libusb20_dev_get_parent_address(struct libusb20_device *pdev)
+{
+ return (pdev->parent_address);
+}
+
+uint8_t
+libusb20_dev_get_parent_port(struct libusb20_device *pdev)
+{
+ return (pdev->parent_port);
+}
+
+uint8_t
libusb20_dev_get_bus_number(struct libusb20_device *pdev)
{
return (pdev->bus_number);
diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h
index 958a379..22a2899 100644
--- a/lib/libusb/libusb20.h
+++ b/lib/libusb/libusb20.h
@@ -262,6 +262,8 @@ struct LIBUSB20_DEVICE_DESC_DECODED *libusb20_dev_get_device_desc(struct libusb2
struct libusb20_config *libusb20_dev_alloc_config(struct libusb20_device *pdev, uint8_t config_index);
struct libusb20_device *libusb20_dev_alloc(void);
uint8_t libusb20_dev_get_address(struct libusb20_device *pdev);
+uint8_t libusb20_dev_get_parent_address(struct libusb20_device *pdev);
+uint8_t libusb20_dev_get_parent_port(struct libusb20_device *pdev);
uint8_t libusb20_dev_get_bus_number(struct libusb20_device *pdev);
uint8_t libusb20_dev_get_mode(struct libusb20_device *pdev);
uint8_t libusb20_dev_get_speed(struct libusb20_device *pdev);
diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h
index 2ecfb47..bef4d02 100644
--- a/lib/libusb/libusb20_int.h
+++ b/lib/libusb/libusb20_int.h
@@ -226,6 +226,8 @@ struct libusb20_device {
uint8_t usb_mode;
uint8_t usb_speed;
uint8_t is_opened;
+ uint8_t parent_address;
+ uint8_t parent_port;
char usb_desc[96];
};
diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c
index 933d728..307ed96 100644
--- a/lib/libusb/libusb20_ugen20.c
+++ b/lib/libusb/libusb20_ugen20.c
@@ -195,6 +195,11 @@ ugen20_enumerate(struct libusb20_device *pdev, const char *id)
break;
}
+ /* get parent HUB index and port */
+
+ pdev->parent_address = devinfo.udi_hubindex;
+ pdev->parent_port = devinfo.udi_hubport;
+
/* generate a nice description for printout */
snprintf(pdev->usb_desc, sizeof(pdev->usb_desc),
OpenPOWER on IntegriCloud