📄 usbinfo.c
字号:
/* usbinfo.c - Nereid USB Monitor / USB Device Information * Copyright (C) 2003 Tachibana Eriko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <stdio.h>#include <stdlib.h>#include "include/usbdef.h"#include "usbinfo.h"/* Variables */UsbInfo usbinfo[1 + DEVADR_MAX];#define USBINFO_NUM (sizeof (usbinfo) / sizeof (usbinfo[0]))/* Functions */static void init_usbinfo_sub (UsbInfo* p, int flag);/* 巜掕偟偨僨僶僀僗傾僪儗僗偺僨僶僀僗忣曬僥乕僽儖傪曉偡 */UsbInfo*get_usbinfo (int devadr){ if (0 <= devadr && devadr < USBINFO_NUM) return &usbinfo[devadr]; printf ("get_usbinfo: 晄惓側僨僶僀僗傾僪儗僗偱偡.\n"); return NULL;}/* 僨僶僀僗傾僪儗僗 0 梡偺僥乕僽儖傪曉偡 */UsbInfo*alloc_usbinfo0 (void){ UsbInfo* p = &usbinfo[0]; init_usbinfo (p); return p;}/* 嬻偒僥乕僽儖(亖僨僶僀僗傾僪儗僗)傪曉偡 */UsbInfo*alloc_usbinfo (void){ int i; for (i = 1; i < USBINFO_NUM; ++i) { if (usbinfo[i].phase == PHASE_UNPLUGGED) return &usbinfo[i]; } printf ("alloc_usbinfo: 僨僶僀僗忣曬僥乕僽儖偑堦攖偱偡.\n"); return NULL;}/* 僨僶僀僗忣曬僥乕僽儖傪夝曻偡傞 */voidfree_usbinfo (UsbInfo* p){ if (p != NULL) init_usbinfo (p);}/* 僨僶僀僗忣曬僥乕僽儖傪慡偰弶婜壔偡傞 */voidinit_all_usbinfo (void){ static int init_flag = 0; int i; for (i = 0; i < USBINFO_NUM; ++i) init_usbinfo_sub (&usbinfo[i], init_flag); init_flag = 1;}/* 僨僶僀僗忣曬僥乕僽儖傪弶婜壔偡傞 */voidinit_usbinfo (UsbInfo* p){ init_usbinfo_sub (p, 1);}static voidinit_usbinfo_sub (UsbInfo* p, int flag){ int devadr = p - usbinfo; /* 攋夡僠僃僢僋丄僶僢僼傽夝曻 */ if (flag == 1) { if (p->devadr != devadr) printf ("init_usbinfo: 僨僶僀僗傾僪儗僗偑攋夡偝傟偰偄傑偡(%d).\n", devadr); free (p->confdescp); } p->devadr = devadr; p->bMaxPacketSize0 = 0; p->confno = 0; p->hubadr = 0; p->hubport = 0; p->phase = PHASE_UNPLUGGED; p->speed = SPEED_UNKNOWN; p->confdescp = NULL; p->total_confdesc = 0;}/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -