source: mainline/uspace/app/lsusb/main.c@ e5165a3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e5165a3 was e5165a3, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

lsusb prints path to host controller

  • Property mode set to 100644
File size: 2.7 KB
Line 
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>
42#include <bool.h>
43#include <getopt.h>
44#include <devman.h>
45#include <devmap.h>
46
47#define NAME "lsusb"
48
49#define MAX_FAILED_ATTEMPTS 4
50#define MAX_PATH_LENGTH 1024
51
52static int get_hc_handle(size_t class_index, devman_handle_t *hc_handle)
53{
54 char *class_index_str;
55 devman_handle_t hc_handle_tmp;
56 int rc;
57
58 rc = asprintf(&class_index_str, "%zu", class_index);
59 if (rc < 0) {
60 return ENOMEM;
61 }
62 rc = devman_device_get_handle_by_class("usbhc", class_index_str,
63 &hc_handle_tmp, 0);
64 free(class_index_str);
65 if (rc != EOK) {
66 return rc;
67 }
68
69 if (hc_handle != NULL) {
70 *hc_handle = hc_handle_tmp;
71 }
72
73 return EOK;
74}
75
76int main(int argc, char *argv[])
77{
78 size_t class_index = 0;
79 size_t failed_attempts = 0;
80
81 while (failed_attempts < MAX_FAILED_ATTEMPTS) {
82 class_index++;
83 devman_handle_t hc_handle = 0;
84 int rc = get_hc_handle(class_index, &hc_handle);
85 if (rc != EOK) {
86 failed_attempts++;
87 continue;
88 }
89 char path[MAX_PATH_LENGTH];
90 rc = devman_get_device_path(hc_handle, path, MAX_PATH_LENGTH);
91 if (rc != EOK) {
92 continue;
93 }
94 printf(NAME ": host controller %zu is `%s'.\n",
95 class_index, path);
96 }
97
98 return 0;
99}
100
101
102/** @}
103 */
Note: See TracBrowser for help on using the repository browser.