00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <usb/classes/classes.h>
00036 #include <usbvirt/device.h>
00037 #include <errno.h>
00038 #include <str_error.h>
00039 #include <stdlib.h>
00040 #include <ddf/driver.h>
00041 #include <devman.h>
00042 #include <usb/dev/hub.h>
00043 #include <usb/dev/recognise.h>
00044
00045 #include "hub.h"
00046
00047 #include "vhcd.h"
00048 #include "conn.h"
00049
00050 usbvirt_device_t virtual_hub_device = {
00051 .name = "root hub",
00052 .ops = &hub_ops,
00053 .address = 0
00054 };
00055
00056 static ddf_dev_ops_t rh_ops = {
00057 .interfaces[USB_DEV_IFACE] = &rh_usb_iface,
00058 };
00059
00060 static int hub_register_in_devman_fibril(void *arg);
00061
00062 void virtual_hub_device_init(ddf_fun_t *hc_dev)
00063 {
00064 virthub_init(&virtual_hub_device);
00065
00066
00067
00068
00069
00070
00071
00072 fid_t root_hub_registration
00073 = fibril_create(hub_register_in_devman_fibril, hc_dev);
00074 if (root_hub_registration == 0) {
00075 usb_log_fatal("Failed to create hub registration fibril.\n");
00076 return;
00077 }
00078
00079 fibril_add_ready(root_hub_registration);
00080 }
00081
00082 static int pretend_port_rest(int unused, void *unused2)
00083 {
00084 return EOK;
00085 }
00086
00092 int hub_register_in_devman_fibril(void *arg)
00093 {
00094 ddf_fun_t *hc_dev = (ddf_fun_t *) arg;
00095
00096
00097
00098
00099 int phone;
00100 do {
00101 phone = devman_device_connect(hc_dev->handle, 0);
00102 } while (phone < 0);
00103 async_hangup(phone);
00104
00105 int rc;
00106
00107 usb_hc_connection_t hc_conn;
00108 rc = usb_hc_connection_initialize(&hc_conn, hc_dev->handle);
00109 assert(rc == EOK);
00110
00111 rc = usb_hc_connection_open(&hc_conn);
00112 assert(rc == EOK);
00113
00114 ddf_fun_t *hub_dev;
00115 rc = usb_hc_new_device_wrapper(hc_dev->dev, &hc_conn,
00116 USB_SPEED_FULL,
00117 pretend_port_rest, 0, NULL,
00118 NULL, NULL, &rh_ops, hc_dev, &hub_dev);
00119 if (rc != EOK) {
00120 usb_log_fatal("Failed to create root hub: %s.\n",
00121 str_error(rc));
00122 }
00123
00124 usb_hc_connection_close(&hc_conn);
00125
00126 usb_log_info("Created root hub function (handle %zu).\n",
00127 (size_t) hub_dev->handle);
00128
00129 return 0;
00130 }
00131
00132