dump.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 <errno.h>
00037 #include <str_error.h>
00038 #include <stdlib.h>
00039 #include <usb/dev/pipes.h>
00040 #include <usb/dev/dp.h>
00041 #include <usb/classes/classes.h>
00042 #include "usbmid.h"
00043 
00049 static void dump_tree_descriptor(uint8_t *data, size_t depth)
00050 {
00051         if (data == NULL) {
00052                 return;
00053         }
00054         int type = (int) *(data + 1);
00055         if (type == USB_DESCTYPE_INTERFACE) {
00056                 usb_standard_interface_descriptor_t *descriptor
00057                     = (usb_standard_interface_descriptor_t *) data;
00058                 usb_log_info("Found interface: %s (0x%02x/0x%02x/0x%02x).\n",
00059                     usb_str_class(descriptor->interface_class),
00060                     (int) descriptor->interface_class,
00061                     (int) descriptor->interface_subclass,
00062                     (int) descriptor->interface_protocol);
00063         }
00064 }
00065 
00073 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
00074     uint8_t *root, size_t depth)
00075 {
00076         if (root == NULL) {
00077                 return;
00078         }
00079         dump_tree_descriptor(root, depth);
00080         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
00081         do {
00082                 dump_tree_internal(parser, data, child, depth + 1);
00083                 child = usb_dp_get_sibling_descriptor(parser, data, root, child);
00084         } while (child != NULL);
00085 }
00086 
00092 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data)
00093 {
00094         uint8_t *ptr = data->data;
00095         dump_tree_internal(parser, data, ptr, 0);
00096 }
00097 
00103 void usbmid_dump_descriptors(uint8_t *descriptors, size_t length)
00104 {
00105         usb_dp_parser_data_t data = {
00106                 .data = descriptors,
00107                 .size = length,
00108                 .arg = NULL
00109         };
00110 
00111         usb_dp_parser_t parser = {
00112                 .nesting = usb_dp_standard_descriptor_nesting
00113         };
00114 
00115         dump_tree(&parser, &data);
00116 }
00117 

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