MFC r203147

Add a function to check if the usb devices is still connected.

Submitted by:	Hans Petter Selasky
This commit is contained in:
Andrew Thompson 2010-04-07 00:34:05 +00:00
parent 464b64f6c8
commit 6836afc4c6
5 changed files with 44 additions and 0 deletions

View File

@ -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

View File

@ -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
@ -672,6 +673,15 @@ libusb20_dev_reset(struct libusb20_device *pdev)
return (error);
}
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)
{

View File

@ -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);

View File

@ -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) \

View File

@ -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;
@ -552,6 +553,25 @@ ugen20_reset_device(struct libusb20_device *pdev)
return (ugen20_tr_renew(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)
{