HelenOS sources
This source file includes following definitions.
- device_add
- device_cleanup
- device_remove
- device_gone
- function_online
- function_offline
- main
#include <errno.h>
#include <usb/debug.h>
#include <usb/classes/classes.h>
#include <usb/dev/driver.h>
#include <usbdiag_iface.h>
#include <str_error.h>
#include "device.h"
#define NAME "usbdiag"
static const usb_endpoint_description_t *diag_endpoints[];
static errno_t device_add(usb_device_t *dev)
{
errno_t rc;
usb_log_info("Adding device '%s'", usb_device_get_name(dev));
usbdiag_dev_t *diag_dev;
if ((rc = usbdiag_dev_create(dev, &diag_dev, diag_endpoints))) {
usb_log_error("Failed create device: %s.", str_error(rc));
goto err;
}
if ((rc = ddf_fun_bind(diag_dev->fun))) {
usb_log_error("Failed to bind DDF function: %s.", str_error(rc));
goto err_create;
}
if ((rc = ddf_fun_add_to_category(diag_dev->fun, USBDIAG_CATEGORY))) {
usb_log_error("Failed add DDF to category '"
USBDIAG_CATEGORY "': %s.\n", str_error(rc));
goto err_bind;
}
return EOK;
err_bind:
ddf_fun_unbind(diag_dev->fun);
err_create:
usbdiag_dev_destroy(diag_dev);
err:
return rc;
}
static errno_t device_cleanup(usbdiag_dev_t *diag_dev)
{
usbdiag_dev_destroy(diag_dev);
return EOK;
}
static errno_t device_remove(usb_device_t *dev)
{
errno_t rc;
usb_log_info("Removing device '%s'", usb_device_get_name(dev));
usbdiag_dev_t *diag_dev = usb_device_to_usbdiag_dev(dev);
if ((rc = ddf_fun_unbind(diag_dev->fun))) {
usb_log_error("Failed to unbind DDF function: %s", str_error(rc));
goto err;
}
usb_log_info("Device '%s' removed.", usb_device_get_name(dev));
return device_cleanup(diag_dev);
err:
return rc;
}
static errno_t device_gone(usb_device_t *dev)
{
errno_t rc;
usb_log_info("Device '%s' gone.", usb_device_get_name(dev));
usbdiag_dev_t *diag_dev = usb_device_to_usbdiag_dev(dev);
if ((rc = ddf_fun_unbind(diag_dev->fun))) {
usb_log_error("Failed to unbind DDF function: %s", str_error(rc));
goto err;
}
return device_cleanup(diag_dev);
err:
return rc;
}
static errno_t function_online(ddf_fun_t *fun)
{
return ddf_fun_online(fun);
}
static errno_t function_offline(ddf_fun_t *fun)
{
return ddf_fun_offline(fun);
}
static const usb_endpoint_description_t burst_intr_in_ep = {
.transfer_type = USB_TRANSFER_INTERRUPT,
.direction = USB_DIRECTION_IN,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t burst_intr_out_ep = {
.transfer_type = USB_TRANSFER_INTERRUPT,
.direction = USB_DIRECTION_OUT,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t burst_bulk_in_ep = {
.transfer_type = USB_TRANSFER_BULK,
.direction = USB_DIRECTION_IN,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t burst_bulk_out_ep = {
.transfer_type = USB_TRANSFER_BULK,
.direction = USB_DIRECTION_OUT,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t burst_isoch_in_ep = {
.transfer_type = USB_TRANSFER_ISOCHRONOUS,
.direction = USB_DIRECTION_IN,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t burst_isoch_out_ep = {
.transfer_type = USB_TRANSFER_ISOCHRONOUS,
.direction = USB_DIRECTION_OUT,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t data_intr_in_ep = {
.transfer_type = USB_TRANSFER_INTERRUPT,
.direction = USB_DIRECTION_IN,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t data_intr_out_ep = {
.transfer_type = USB_TRANSFER_INTERRUPT,
.direction = USB_DIRECTION_OUT,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t data_bulk_in_ep = {
.transfer_type = USB_TRANSFER_BULK,
.direction = USB_DIRECTION_IN,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t data_bulk_out_ep = {
.transfer_type = USB_TRANSFER_BULK,
.direction = USB_DIRECTION_OUT,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t data_isoch_in_ep = {
.transfer_type = USB_TRANSFER_ISOCHRONOUS,
.direction = USB_DIRECTION_IN,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t data_isoch_out_ep = {
.transfer_type = USB_TRANSFER_ISOCHRONOUS,
.direction = USB_DIRECTION_OUT,
.interface_class = USB_CLASS_DIAGNOSTIC,
.interface_subclass = 0x00,
.interface_protocol = 0x01,
.flags = 0
};
static const usb_endpoint_description_t *diag_endpoints[] = {
[USBDIAG_EP_BURST_INTR_IN] = &burst_intr_in_ep,
[USBDIAG_EP_BURST_INTR_OUT] = &burst_intr_out_ep,
[USBDIAG_EP_BURST_BULK_IN] = &burst_bulk_in_ep,
[USBDIAG_EP_BURST_BULK_OUT] = &burst_bulk_out_ep,
[USBDIAG_EP_BURST_ISOCH_IN] = &burst_isoch_in_ep,
[USBDIAG_EP_BURST_ISOCH_OUT] = &burst_isoch_out_ep,
[USBDIAG_EP_DATA_INTR_IN] = &data_intr_in_ep,
[USBDIAG_EP_DATA_INTR_OUT] = &data_intr_out_ep,
[USBDIAG_EP_DATA_BULK_IN] = &data_bulk_in_ep,
[USBDIAG_EP_DATA_BULK_OUT] = &data_bulk_out_ep,
[USBDIAG_EP_DATA_ISOCH_IN] = &data_isoch_in_ep,
[USBDIAG_EP_DATA_ISOCH_OUT] = &data_isoch_out_ep,
NULL
};
static const usb_driver_ops_t diag_driver_ops = {
.device_add = device_add,
.device_remove = device_remove,
.device_gone = device_gone,
.function_online = function_online,
.function_offline = function_offline
};
static const usb_driver_t diag_driver = {
.name = NAME,
.ops = &diag_driver_ops,
.endpoints = &diag_endpoints[1]
};
int main(int argc, char *argv[])
{
printf(NAME ": USB diagnostic device driver.\n");
log_init(NAME);
return usb_driver_main(&diag_driver);
}
HelenOS homepage, sources at GitHub