aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Thompson <thompsa@FreeBSD.org>2010-01-29 02:44:06 +0000
committerAndrew Thompson <thompsa@FreeBSD.org>2010-01-29 02:44:06 +0000
commite50ac68b3dc725aa4b428d2446bb58fe4f5c288c (patch)
tree2391978b0a29215f8e39ca3810313d7efcd63dca /lib
parent2155c5d81467f646691a8188dd0f0fc3764b2ad2 (diff)
downloadsrc-e50ac68b3dc725aa4b428d2446bb58fe4f5c288c.tar.gz
src-e50ac68b3dc725aa4b428d2446bb58fe4f5c288c.zip
Add a function to check if the usb devices is still connected.
Submitted by: Hans Petter Selasky
Notes
Notes: svn path=/head/; revision=203147
Diffstat (limited to 'lib')
-rw-r--r--lib/libusb/libusb20.311
-rw-r--r--lib/libusb/libusb20.c10
-rw-r--r--lib/libusb/libusb20.h1
-rw-r--r--lib/libusb/libusb20_int.h2
-rw-r--r--lib/libusb/libusb20_ugen20.c20
5 files changed, 44 insertions, 0 deletions
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index 5404013ee999..7896e8f01094 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -143,6 +143,8 @@ USB access library (libusb -lusb)
.Ft int
.Fn libusb20_dev_reset "struct libusb20_device *pdev"
.Ft int
+.Fn libusb20_dev_check_connected "struct libusb20_device *pdev"
+.Ft int
.Fn libusb20_dev_set_power_mode "struct libusb20_device *pdev" "uint8_t power_mode"
.Ft uint8_t
.Fn libusb20_dev_get_power_mode "struct libusb20_device *pdev"
@@ -677,6 +679,15 @@ the last set USB configuration.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
+.
+.Pp
+.
+.Fn libusb20_dev_check_connected
+will check if an opened USB device is still connected.
+.
+This function returns zero if the device is still connected else a LIBUSB20_ERROR value is returned.
+.
+.
.Pp
.
.Fn libusb20_dev_set_power_mode
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index 1c75fc16712c..e181b49d24eb 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -67,6 +67,7 @@ dummy_callback(struct libusb20_transfer *xfer)
#define dummy_set_config_index (void *)dummy_int
#define dummy_set_alt_index (void *)dummy_int
#define dummy_reset_device (void *)dummy_int
+#define dummy_check_connected (void *)dummy_int
#define dummy_set_power_mode (void *)dummy_int
#define dummy_get_power_mode (void *)dummy_int
#define dummy_kernel_driver_active (void *)dummy_int
@@ -673,6 +674,15 @@ libusb20_dev_reset(struct libusb20_device *pdev)
}
int
+libusb20_dev_check_connected(struct libusb20_device *pdev)
+{
+ int error;
+
+ error = pdev->methods->check_connected(pdev);
+ return (error);
+}
+
+int
libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode)
{
int error;
diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h
index bb7d8a4ab3d2..6b253aa559a2 100644
--- a/lib/libusb/libusb20.h
+++ b/lib/libusb/libusb20.h
@@ -250,6 +250,7 @@ int libusb20_dev_request_sync(struct libusb20_device *pdev, struct LIBUSB20_CONT
int libusb20_dev_req_string_sync(struct libusb20_device *pdev, uint8_t index, uint16_t langid, void *ptr, uint16_t len);
int libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev, uint8_t index, void *ptr, uint16_t len);
int libusb20_dev_reset(struct libusb20_device *pdev);
+int libusb20_dev_check_connected(struct libusb20_device *pdev);
int libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode);
uint8_t libusb20_dev_get_power_mode(struct libusb20_device *pdev);
int libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h
index 004b0cf381d7..b0e0e2dd7f65 100644
--- a/lib/libusb/libusb20_int.h
+++ b/lib/libusb/libusb20_int.h
@@ -101,6 +101,7 @@ typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t po
typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode);
typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index);
+typedef int (libusb20_check_connected_t)(struct libusb20_device *pdev);
/* USB transfer specific */
typedef int (libusb20_tr_open_t)(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no);
@@ -117,6 +118,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer);
m(n, kernel_driver_active) \
m(n, process) \
m(n, reset_device) \
+ m(n, check_connected) \
m(n, set_power_mode) \
m(n, get_power_mode) \
m(n, set_alt_index) \
diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c
index efcca63a2095..892ba0eb78aa 100644
--- a/lib/libusb/libusb20_ugen20.c
+++ b/lib/libusb/libusb20_ugen20.c
@@ -67,6 +67,7 @@ static libusb20_get_config_index_t ugen20_get_config_index;
static libusb20_set_config_index_t ugen20_set_config_index;
static libusb20_set_alt_index_t ugen20_set_alt_index;
static libusb20_reset_device_t ugen20_reset_device;
+static libusb20_check_connected_t ugen20_check_connected;
static libusb20_set_power_mode_t ugen20_set_power_mode;
static libusb20_get_power_mode_t ugen20_get_power_mode;
static libusb20_kernel_driver_active_t ugen20_kernel_driver_active;
@@ -553,6 +554,25 @@ ugen20_reset_device(struct libusb20_device *pdev)
}
static int
+ugen20_check_connected(struct libusb20_device *pdev)
+{
+ uint32_t plugtime;
+ int error = 0;
+
+ if (ioctl(pdev->file_ctrl, USB_GET_PLUGTIME, &plugtime)) {
+ error = LIBUSB20_ERROR_NO_DEVICE;
+ goto done;
+ }
+
+ if (pdev->session_data.plugtime != plugtime) {
+ error = LIBUSB20_ERROR_NO_DEVICE;
+ goto done;
+ }
+done:
+ return (error);
+}
+
+static int
ugen20_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode)
{
int temp;