desctree.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 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 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <errno.h>
00040 #include <str_error.h>
00041 #include <bool.h>
00042 
00043 #include <usb/usb.h>
00044 #include <usb/descriptor.h>
00045 #include <usb/debug.h>
00046 #include <usb/classes/classes.h>
00047 
00048 #include "usbinfo.h"
00049 #include <usb/dev/dp.h>
00050 
00051 static void browse_descriptor_tree_internal(usb_dp_parser_t *parser,
00052     usb_dp_parser_data_t *data, uint8_t *root, size_t depth,
00053     dump_descriptor_in_tree_t callback, void *arg)
00054 {
00055         if (root == NULL) {
00056                 return;
00057         }
00058         callback(root, depth, arg);
00059         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
00060         do {
00061                 browse_descriptor_tree_internal(parser, data, child, depth + 1,
00062                     callback, arg);
00063                 child = usb_dp_get_sibling_descriptor(parser, data,
00064                     root, child);
00065         } while (child != NULL);
00066 }
00067 
00068 void browse_descriptor_tree(uint8_t *descriptors, size_t descriptors_size,
00069     usb_dp_descriptor_nesting_t *descriptor_nesting,
00070     dump_descriptor_in_tree_t callback, size_t initial_depth, void *arg)
00071 {
00072         usb_dp_parser_data_t data = {
00073                 .data = descriptors,
00074                 .size = descriptors_size,
00075                 .arg = NULL
00076         };
00077 
00078         usb_dp_parser_t parser = {
00079                 .nesting = descriptor_nesting
00080         };
00081 
00082         browse_descriptor_tree_internal(&parser, &data, descriptors,
00083             initial_depth, callback, arg);
00084 }
00085 

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