1f9f848faSopenharmony_ci/* 2f9f848faSopenharmony_ci * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. 3f9f848faSopenharmony_ci * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. 4f9f848faSopenharmony_ci * 5f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 6f9f848faSopenharmony_ci * are permitted provided that the following conditions are met: 7f9f848faSopenharmony_ci * 8f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 9f9f848faSopenharmony_ci * conditions and the following disclaimer. 10f9f848faSopenharmony_ci * 11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12f9f848faSopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 13f9f848faSopenharmony_ci * provided with the distribution. 14f9f848faSopenharmony_ci * 15f9f848faSopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16f9f848faSopenharmony_ci * to endorse or promote products derived from this software without specific prior written 17f9f848faSopenharmony_ci * permission. 18f9f848faSopenharmony_ci * 19f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20f9f848faSopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21f9f848faSopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22f9f848faSopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23f9f848faSopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24f9f848faSopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25f9f848faSopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26f9f848faSopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27f9f848faSopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28f9f848faSopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29f9f848faSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30f9f848faSopenharmony_ci */ 31f9f848faSopenharmony_ci 32f9f848faSopenharmony_ci#ifndef __USB_BTREE_H__ 33f9f848faSopenharmony_ci#define __USB_BTREE_H__ 34f9f848faSopenharmony_ci 35f9f848faSopenharmony_ci#include <los_typedef.h> 36f9f848faSopenharmony_ci#include <securec.h> 37f9f848faSopenharmony_ci 38f9f848faSopenharmony_ci#ifdef __cplusplus 39f9f848faSopenharmony_ci#if __cplusplus 40f9f848faSopenharmony_ciextern "C" { 41f9f848faSopenharmony_ci#endif /* __cplusplus */ 42f9f848faSopenharmony_ci#endif /* __cplusplus */ 43f9f848faSopenharmony_ci 44f9f848faSopenharmony_cistruct node_info { 45f9f848faSopenharmony_ci uint8_t port_no; 46f9f848faSopenharmony_ci const char *nameunit; /* Save dev_nameunit address. */ 47f9f848faSopenharmony_ci}; 48f9f848faSopenharmony_ci 49f9f848faSopenharmony_citypedef struct usbd_bt_node { 50f9f848faSopenharmony_ci struct node_info info; 51f9f848faSopenharmony_ci struct usbd_bt_node *lbt_node; 52f9f848faSopenharmony_ci struct usbd_bt_node *rbt_node; 53f9f848faSopenharmony_ci}usbd_bt_node,*usbd_bt_tree; 54f9f848faSopenharmony_ci 55f9f848faSopenharmony_ci/* External API interface */ 56f9f848faSopenharmony_cistruct usbd_bt_node *usbd_create_bt_node(struct node_info *info); 57f9f848faSopenharmony_civoid usbd_free_bt_node(usbd_bt_node *node); 58f9f848faSopenharmony_ciint usbd_insert_bt_node(usbd_bt_node *node, usbd_bt_tree tree, struct node_info *parent_info); 59f9f848faSopenharmony_ciint usbd_remove_bt_node(usbd_bt_tree tree, struct node_info *p_info, struct node_info *rm_info); 60f9f848faSopenharmony_ciint usbd_get_hub_quantity(void); 61f9f848faSopenharmony_cistruct usbd_bt_node *usbd_per_order_probe(usbd_bt_tree tree, char *devname, uint8_t *port_num); 62f9f848faSopenharmony_ci 63f9f848faSopenharmony_ciinline int usbd_atoi(const char *name) 64f9f848faSopenharmony_ci{ 65f9f848faSopenharmony_ci int num = 0; 66f9f848faSopenharmony_ci if (name == NULL) { 67f9f848faSopenharmony_ci return -1; 68f9f848faSopenharmony_ci } 69f9f848faSopenharmony_ci 70f9f848faSopenharmony_ci while(*name) { 71f9f848faSopenharmony_ci num *= 10; 72f9f848faSopenharmony_ci num += *name++ - '0'; 73f9f848faSopenharmony_ci } 74f9f848faSopenharmony_ci return num; 75f9f848faSopenharmony_ci} 76f9f848faSopenharmony_ci 77f9f848faSopenharmony_ci 78f9f848faSopenharmony_ci#ifdef __cplusplus 79f9f848faSopenharmony_ci#if __cplusplus 80f9f848faSopenharmony_ci} 81f9f848faSopenharmony_ci#endif /* __cplusplus */ 82f9f848faSopenharmony_ci#endif /* __cplusplus */ 83f9f848faSopenharmony_ci 84f9f848faSopenharmony_ci#endif /* __USB_BTREE_H__ */ 85f9f848faSopenharmony_ci 86