source: mainline/uspace/app/usbinfo/list.c@ 03362fbd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 03362fbd was 3e6a98c5, checked in by Jiri Svoboda <jiri@…>, 13 years ago

Standards-compliant boolean type.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[8594505]1/*
2 * Copyright (c) 2010-2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup lsusb
30 * @{
31 */
32/**
33 * @file
34 * Listing of USB host controllers.
35 */
36
37#include <inttypes.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <errno.h>
41#include <str_error.h>
[3e6a98c5]42#include <stdbool.h>
[8594505]43#include <getopt.h>
44#include <devman.h>
[15f3c3f]45#include <loc.h>
[7d521e24]46#include <usb/dev/hub.h>
[0edf7c7]47#include <usb/hc.h>
[8594505]48
[9e279c4]49#include "usbinfo.h"
[8594505]50
[2720b51a]51#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
[e5165a3]52#define MAX_PATH_LENGTH 1024
[8594505]53
[e280857]54static void print_found_hc(service_id_t sid, const char *path)
[5dfee52]55{
[e280857]56 printf("Bus %" PRIun ": %s\n", sid, path);
[5dfee52]57}
58static void print_found_dev(usb_address_t addr, const char *path)
59{
60 printf(" Device %02d: %s\n", addr, path);
61}
62
63static void print_hc_devices(devman_handle_t hc_handle)
64{
65 int rc;
66 usb_hc_connection_t conn;
67
68 usb_hc_connection_initialize(&conn, hc_handle);
69 rc = usb_hc_connection_open(&conn);
70 if (rc != EOK) {
71 printf(NAME ": failed to connect to HC: %s.\n",
72 str_error(rc));
73 return;
74 }
75 usb_address_t addr;
[2720b51a]76 for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
[5dfee52]77 devman_handle_t dev_handle;
78 rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
79 if (rc != EOK) {
80 continue;
81 }
82 char path[MAX_PATH_LENGTH];
[7beb220]83 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
[5dfee52]84 if (rc != EOK) {
85 continue;
86 }
87 print_found_dev(addr, path);
88 }
89 usb_hc_connection_close(&conn);
90}
91
[9e279c4]92void list(void)
[8594505]93{
[e280857]94 category_id_t usbhc_cat;
95 service_id_t *svcs;
96 size_t count;
97 size_t i;
98 int rc;
99
[1dc4a5e]100 rc = loc_category_get_id(USB_HC_CATEGORY, &usbhc_cat, 0);
[e280857]101 if (rc != EOK) {
102 printf(NAME ": Error resolving category '%s'",
[1dc4a5e]103 USB_HC_CATEGORY);
[9e279c4]104 return;
[e280857]105 }
[8594505]106
[e280857]107 rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
108 if (rc != EOK) {
109 printf(NAME ": Error getting list of host controllers.\n");
[9e279c4]110 return;
[e280857]111 }
112
113 for (i = 0; i < count; i++) {
[8594505]114 devman_handle_t hc_handle = 0;
[e280857]115 int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
[8594505]116 if (rc != EOK) {
[e280857]117 printf(NAME ": Error resolving handle of HC with SID %"
118 PRIun ", skipping.\n", svcs[i]);
[8594505]119 continue;
120 }
[e5165a3]121 char path[MAX_PATH_LENGTH];
[7beb220]122 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
[e5165a3]123 if (rc != EOK) {
[e280857]124 printf(NAME ": Error resolving path of HC with SID %"
125 PRIun ", skipping.\n", svcs[i]);
[e5165a3]126 continue;
127 }
[e280857]128 print_found_hc(svcs[i], path);
[5dfee52]129 print_hc_devices(hc_handle);
[8594505]130 }
131
[e280857]132 free(svcs);
[8594505]133}
134
135
136/** @}
137 */
Note: See TracBrowser for help on using the repository browser.