main.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00036 #include <usb/dev/driver.h>
00037 #include <usb/debug.h>
00038 #include <errno.h>
00039 #include <str_error.h>
00040 
00041 #define NAME "usbflbk"
00042 
00048 static int usbfallback_add_device(usb_device_t *dev)
00049 {
00050         int rc;
00051         const char *fun_name = "ctl";
00052 
00053         ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed,
00054             fun_name);
00055         if (ctl_fun == NULL) {
00056                 usb_log_error("Failed to create control function.\n");
00057                 return ENOMEM;
00058         }
00059         rc = ddf_fun_bind(ctl_fun);
00060         if (rc != EOK) {
00061                 usb_log_error("Failed to bind control function: %s.\n",
00062                     str_error(rc));
00063                 return rc;
00064         }
00065 
00066         usb_log_info("Pretending to control %s `%s'" \
00067             " (node `%s', handle %" PRIun ").\n",
00068             dev->interface_no < 0 ? "device" : "interface",
00069             dev->ddf_dev->name, fun_name, dev->ddf_dev->handle);
00070 
00071         return EOK;
00072 }
00073 
00075 static usb_driver_ops_t usbfallback_driver_ops = {
00076         .add_device = usbfallback_add_device,
00077 };
00078 
00080 static usb_driver_t usbfallback_driver = {
00081         .name = NAME,
00082         .ops = &usbfallback_driver_ops,
00083         .endpoints = NULL
00084 };
00085 
00086 int main(int argc, char *argv[])
00087 {
00088         usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
00089 
00090         return usb_driver_main(&usbfallback_driver);
00091 }
00092 

Generated on Thu Jun 2 07:45:41 2011 for HelenOS/USB by  doxygen 1.4.7