source: mainline/uspace/app/usbinfo/list.c@ a787081

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a787081 was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 4.3 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>
[16b64b8]46#include <usb_iface.h>
[1d6dd2a]47#include <str.h>
[8594505]48
[9e279c4]49#include "usbinfo.h"
[8594505]50
[e5165a3]51#define MAX_PATH_LENGTH 1024
[8594505]52
[69b264a9]53static void print_usb_device(devman_handle_t handle)
[5dfee52]54{
[69b264a9]55 char path[MAX_PATH_LENGTH];
[b7fd2a0]56 errno_t rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH);
[69b264a9]57 if (rc != EOK) {
[1433ecda]58 printf(NAME "Failed to get path for device %" PRIun "\n", handle);
[69b264a9]59 return;
60 }
[f3922c2]61 printf("\tDevice %" PRIun ": %s\n", handle, path);
[5dfee52]62}
63
[69b264a9]64static void print_usb_bus(service_id_t svc)
[16b64b8]65{
[69b264a9]66 devman_handle_t hc_handle = 0;
[b7fd2a0]67 errno_t rc = devman_fun_sid_to_handle(svc, &hc_handle);
[69b264a9]68 if (rc != EOK) {
69 printf(NAME ": Error resolving handle of HC with SID %"
70 PRIun ", skipping.\n", svc);
71 return;
72 }
73
74 char path[MAX_PATH_LENGTH];
75 rc = devman_fun_get_path(hc_handle, path, sizeof(path));
76 if (rc != EOK) {
77 printf(NAME ": Error resolving path of HC with SID %"
78 PRIun ", skipping.\n", svc);
79 return;
80 }
81 printf("Bus %" PRIun ": %s\n", svc, path);
82
[7c3fb9b]83 /*
84 * Construct device's path.
85 * That's "hc function path" - ( '/' + "hc function name" )
86 */
[69b264a9]87 // TODO replace this with something sane
88
89 /* Get function name */
90 char name[10];
91 rc = devman_fun_get_name(hc_handle, name, sizeof(name));
92 if (rc != EOK) {
93 printf(NAME ": Error resolving name of HC with SID %"
94 PRIun ", skipping.\n", svc);
95 return;
96 }
97
98 /* Get handle of parent device */
99 devman_handle_t fh;
100 path[str_size(path) - str_size(name) - 1] = '\0';
101 rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
102 if (rc != EOK) {
103 printf(NAME ": Error resolving parent handle of HC with"
104 " SID %" PRIun ", skipping.\n", svc);
105 return;
106 }
107
108 /* Get child handle */
109 devman_handle_t dh;
110 rc = devman_fun_get_child(fh, &dh);
111 if (rc != EOK) {
112 printf(NAME ": Error resolving parent handle of HC with"
113 " SID %" PRIun ", skipping.\n", svc);
114 return;
115 }
[a35b458]116
[69b264a9]117 devman_handle_t *fhs = 0;
118 size_t count;
119 rc = devman_dev_get_functions(dh, &fhs, &count);
120 if (rc != EOK) {
121 printf(NAME ": Error siblings of HC with"
122 " SID %" PRIun ", skipping.\n", svc);
123 return;
124 }
[16b64b8]125
[69b264a9]126 for (size_t i = 0; i < count; ++i) {
127 if (fhs[i] != hc_handle)
128 print_usb_device(fhs[i]);
[16b64b8]129 }
[69b264a9]130 free(fhs);
[16b64b8]131}
132
[9e279c4]133void list(void)
[8594505]134{
[e280857]135 category_id_t usbhc_cat;
136 service_id_t *svcs;
137 size_t count;
[b7fd2a0]138 errno_t rc;
[e280857]139
[1dc4a5e]140 rc = loc_category_get_id(USB_HC_CATEGORY, &usbhc_cat, 0);
[e280857]141 if (rc != EOK) {
142 printf(NAME ": Error resolving category '%s'",
[1dc4a5e]143 USB_HC_CATEGORY);
[9e279c4]144 return;
[e280857]145 }
[8594505]146
[e280857]147 rc = loc_category_get_svcs(usbhc_cat, &svcs, &count);
148 if (rc != EOK) {
149 printf(NAME ": Error getting list of host controllers.\n");
[9e279c4]150 return;
[e280857]151 }
152
[58563585]153 for (unsigned int i = 0; i < count; ++i) {
[69b264a9]154 print_usb_bus(svcs[i]);
[8594505]155 }
156
[e280857]157 free(svcs);
[8594505]158}
159
160/** @}
161 */
Note: See TracBrowser for help on using the repository browser.