svn commit: r206332 - stable/8/lib/libusb
Andrew Thompson
thompsa at FreeBSD.org
Wed Apr 7 00:34:05 UTC 2010
Author: thompsa
Date: Wed Apr 7 00:34:05 2010
New Revision: 206332
URL: http://svn.freebsd.org/changeset/base/206332
Log:
MFC r203147
Add a function to check if the usb devices is still connected.
Submitted by: Hans Petter Selasky
Modified:
stable/8/lib/libusb/libusb20.3
stable/8/lib/libusb/libusb20.c
stable/8/lib/libusb/libusb20.h
stable/8/lib/libusb/libusb20_int.h
stable/8/lib/libusb/libusb20_ugen20.c
Directory Properties:
stable/8/lib/libusb/ (props changed)
stable/8/lib/libusb/usb.h (props changed)
Modified: stable/8/lib/libusb/libusb20.3
==============================================================================
--- stable/8/lib/libusb/libusb20.3 Wed Apr 7 00:32:59 2010 (r206331)
+++ stable/8/lib/libusb/libusb20.3 Wed Apr 7 00:34:05 2010 (r206332)
@@ -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
Modified: stable/8/lib/libusb/libusb20.c
==============================================================================
--- stable/8/lib/libusb/libusb20.c Wed Apr 7 00:32:59 2010 (r206331)
+++ stable/8/lib/libusb/libusb20.c Wed Apr 7 00:34:05 2010 (r206332)
@@ -67,6 +67,7 @@ dummy_callback(struct libusb20_transfer
#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_devic
}
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;
Modified: stable/8/lib/libusb/libusb20.h
==============================================================================
--- stable/8/lib/libusb/libusb20.h Wed Apr 7 00:32:59 2010 (r206331)
+++ stable/8/lib/libusb/libusb20.h Wed Apr 7 00:34:05 2010 (r206332)
@@ -250,6 +250,7 @@ int libusb20_dev_request_sync(struct lib
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);
Modified: stable/8/lib/libusb/libusb20_int.h
==============================================================================
--- stable/8/lib/libusb/libusb20_int.h Wed Apr 7 00:32:59 2010 (r206331)
+++ stable/8/lib/libusb/libusb20_int.h Wed Apr 7 00:34:05 2010 (r206332)
@@ -101,6 +101,7 @@ typedef int (libusb20_set_power_mode_t)(
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
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) \
Modified: stable/8/lib/libusb/libusb20_ugen20.c
==============================================================================
--- stable/8/lib/libusb/libusb20_ugen20.c Wed Apr 7 00:32:59 2010 (r206331)
+++ stable/8/lib/libusb/libusb20_ugen20.c Wed Apr 7 00:34:05 2010 (r206332)
@@ -67,6 +67,7 @@ static libusb20_get_config_index_t ugen2
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_devi
}
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;
More information about the svn-src-stable-8
mailing list