📄 usbmon.c
字号:
/* usbmon.c - Nereid USB Monitor / main * 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 <string.h>#include <sys/dos.h>#include <sys/iocs.h>#include <sys/xstart.h>#include "include/nereid_usb.h"#include "usbmon.h"#include "cmd_nereid.h"#include "cmd_sl811hst.h"#include "cmd_usb.h"#include "cmd_usbio.h"#include "cmd_usbreq.h"#include "usbinfo.h"#include "config.h"#include "version.h"/* Variables */int verbose_level = 0;/* usbmon 僐儅儞僪 */int usbmon_sys_info (int argc, char* argv[]);int usbmon_setq (int argc, char* argv[]);int usbmon_help (int argc, char* argv[]);int usbmon_quit (int argc, char* argv[]);/* 僿儖僾 */extern const char helpmes[];__asm (".data\n" "_helpmes:\n" "\t.insert help.txt\n" "\t.dc.b 0\n" "\t.text\n");/* 僐儅儞僪楍 */static const CmdList cmd_list[] = { /* cmd_nereid.c */ { nereid_reset_on, "nereid reset on" }, { nereid_reset_off, "nereid reset off" }, { nereid_power_on, "nereid power on" }, { nereid_power_off, "nereid power off" }, { nereid_int_on, "nereid int on" }, { nereid_int_off, "nereid int off" }, /* alias */ { nereid_enable, "enable" }, { nereid_disable, "disable" }, /* cmd_sl811hst.c */ { sl811hst_reg, "sl811hst reg" }, { sl811hst_dump, "sl811hst dump" }, { sl811hst_read, "sl811hst read" }, { sl811hst_write, "sl811hst write" }, { sl811hst_fill, "sl811hst fill" }, /* cmd_usb.c */ { usb_reset, "usb reset" }, { usb_detect_speed, "usb detect speed" }, { usb_setup, "usb setup" }, /* cmd_usbio.c */ { usb_input, "input" }, { usb_output, "output" }, /* cmd_usbreq.c */ { req_std_get_status, "request get status" }, { req_std_get_status, "request standard get status" }, { req_cls_get_status, "request class get status" }, { req_vdr_get_status, "request vendor get status" }, { req_std_clr_feature, "request clear feature" }, { req_std_clr_feature, "request standard clear feature" }, { req_cls_clr_feature, "request class clear feature" }, { req_vdr_clr_feature, "request vendor clear feature" }, { req_std_get_state, "request get state" }, { req_std_get_state, "request standard get state" }, { req_cls_get_state, "request class get state" }, { req_vdr_get_state, "request vendor get state" }, { req_std_set_feature, "request set feature" }, { req_std_set_feature, "request standard set feature" }, { req_cls_set_feature, "request class set feature" }, { req_vdr_set_feature, "request vendor set feature" }, { req_std_set_address, "request set address" }, { req_std_set_address, "request standard set address" }, { req_cls_set_address, "request class set address" }, { req_vdr_set_address, "request vendor set address" }, { req_std_get_desc, "request get descriptor" }, { req_std_get_desc, "request standard get descriptor" }, { req_cls_get_desc, "request class get descriptor" }, { req_vdr_get_desc, "request vendor get descriptor" }, { req_std_set_desc, "request set descriptor" }, { req_std_set_desc, "request standard set descriptor" }, { req_cls_set_desc, "request class set descriptor" }, { req_vdr_set_desc, "request vendor set descriptor" }, { req_std_get_conf, "request get configuration" }, { req_std_get_conf, "request standard get configuration" }, { req_cls_get_conf, "request class get configuration" }, { req_vdr_get_conf, "request vendor get configuration" }, { req_std_set_conf, "request set configuration" }, { req_std_set_conf, "request standard set configuration" }, { req_cls_set_conf, "request class set configuration" }, { req_vdr_set_conf, "request vendor set configuration" }, { req_std_get_intf, "request get interface" }, { req_std_get_intf, "request standard get interface" }, { req_cls_get_intf, "request class get interface" }, { req_vdr_get_intf, "request vendor get interface" }, { req_std_set_intf, "request set interface" }, { req_std_set_intf, "request standard set interface" }, { req_cls_set_intf, "request class set interface" }, { req_vdr_set_intf, "request vendor set interface" }, { req_std_synch_frame, "request synch frame" }, { req_std_synch_frame, "request standard synch frame" }, { req_cls_synch_frame, "request class synch frame" }, { req_vdr_synch_frame, "request vendor synch frame" }, /* Hub Class */ { req_cls_clr_tt_buf, "request clear tt buffer" }, { req_cls_clr_tt_buf, "request class clear tt buffer" }, { req_cls_reset_tt, "request reset tt" }, { req_cls_reset_tt, "request class reset tt" }, { req_cls_get_tt_stat, "request get tt stat" }, { req_cls_get_tt_stat, "request class get tt stat" }, { req_cls_stop_tt, "request stop tt" }, { req_cls_stop_tt, "request class stop tt" }, /* usbmon.c */ { usbmon_sys_info, "system info" }, { usbmon_setq, "setq" }, { usbmon_quit, "quit" }, { usbmon_quit, "exit" }, { usbmon_help, "help" }, { usbmon_help, "?" },};#define CMD_NUM (sizeof (cmd_list) / sizeof (CmdList))/* Command: 僔僗僥儉忣曬昞帵 */intusbmon_sys_info (int argc, char* argv[]){ /* MPU丄ROM 僶乕僕儑儞 */ printf ("MPU 680%d0, IOCS ROM 0x%08x\n", *(unsigned char*)0xcbc, _iocs_romver ()); /* 妱傝崬傒傾僪儗僗 */ { int vec_fa = *(int*)(0xfa * 4); int vec_fb = *(int*)(0xfb * 4); int iocs_f4 = *(int*)(0x400 + 0xf4 * 4); printf ("Vector 0xfb(#0) = 0x%08x, Vector 0xfa(#1) = 0x%08x, IOCS 0xf4 = 0x%08x\n", vec_fb, vec_fa, iocs_f4); } /* Nereid 惂屼儗僕僗僞 */ printf ("Nereid CONTROL = 0x%02x\n", *NEREID_CTRL); /* 惓忢廔椆 */ return RET_SUCCESS;}/* Command: 愝掕抣曄峏 */intusbmon_setq (int argc, char* argv[]){ int i; if (argc == 0) { printf ("<name>\t\t曄悢柤傪巜掕偟傑偡." " 仸尰嵼偼 verbose 偺傒巜掕壜擻偱偡.\n" "<val> = 0乣1\t愝掕偡傞抣傪巜掕偟傑偡.\n"); /* 惓忢廔椆 */ return RET_SUCCESS; } for (i = 0; i < argc; i += 2) { char* name; int val; if (argc < i + 2) { printf ("set: 堷悢偑懌傝傑偣傫.\n"); return RET_FAILURE; } name = argv[i + 0]; if (sscanf (argv[i + 1], "%i", &val) != 1) { printf ("set: 堷悢偑惓偟偔偁傝傑偣傫.\n"); return RET_FAILURE; } if (strcmp (name, "verbose") == 0) verbose_level = val; else { printf ("set: 巜掕壜擻側曄悢偼 verbose 偱偡.\n"); return RET_FAILURE; } } /* 惓忢廔椆 */ return RET_SUCCESS;}/* Command: 僿儖僾 昞帵 */intusbmon_help (int argc, char* argv[]){ printf (helpmes); /* 惓忢廔椆 */ return RET_SUCCESS;}/* Command: 儌僯僞廔椆 */intusbmon_quit (int argc, char* argv[]){ /* 廔椆僐乕僪傪曉偡 */ return RET_QUIT;}static intget_cmdnum (const char* cmd){ int cmdnum; for (cmdnum = 1; ; ++cmdnum) { cmd = strchr (cmd, ' '); if (cmd == NULL) break; ++cmd; } return cmdnum;}/* Function: 僐儅儞僪専嶕 */static CmdFuncsearch_command (int* argc_ptr, char*** argv_ptr){ int i; int argc = *argc_ptr; char** argv = *argv_ptr; if (argc == 0) return NULL; for (i = 0; i < CMD_NUM; ++i) { const char* cmd = cmd_list[i].cmdline; int cmdnum, flag, j; cmdnum = get_cmdnum (cmd); if (cmdnum > argc) continue; for (flag = 0, j = 0; j < cmdnum; ++j) { int cmdlen = (strchr (cmd, ' ') ? : (cmd + strlen (cmd))) - cmd; int arglen = strlen (argv[j]); flag = 0; if (arglen > cmdlen) break; /* 晄堦抳妋掕 */ if (strnicmp (argv[j], cmd, arglen) != 0) break; /* 晄堦抳 */ flag = 1; cmd += cmdlen + 1; } if (flag == 1) { *argc_ptr -= cmdnum; *argv_ptr += cmdnum; return cmd_list[i].func; } } /* 僐儅儞僪偑尒偮偐傜側偐偭偨 */ return NULL;}static int call_func (CmdFunc func, int argc, char** argv);/* Function: USB 儌僯僞偺儊僀儞儖乕僾 */static voidusbmon (int nereid_id){ init_all_usbinfo (); for (;;) { char buf[1024]; CmdFunc func; int argc, rc; char** argv; char** argv_top; /* 僐儅儞僪擖椡 */ printf ("#%d>", nereid_id); fflush (stdout); if (fgets (buf, sizeof buf - 1, stdin) == NULL) { /* EOF */ printf ("\n"); break; } /* 枛旜偺 LF 傪嶍彍偡傞 */ { int l = strlen (buf) - 1; if (*buf && buf[l] == '\n') buf[l] = '\0'; } if (buf[0] == '\0') {#ifdef DEFAULT_COMMAND /* 夵峴偩偗側傜巜掕僐儅儞僪屇傃弌偟 */ strcpy (buf, DEFAULT_COMMAND);#else continue;#endif } /* 僐儅儞僪儔僀儞暘妱 */ { int i; char* p; argc = _dehupair (buf, buf); if (argc == 0) continue; argv_top = malloc ((argc + 1) * sizeof (char*)); if (argv_top == NULL) { perror ("usbmon"); continue; } p = buf; argv = argv_top; for (i = 0; i < argc; ++i) { *argv++ = p; p += strlen (p) + 1; } *argv = NULL; } /* 僐儅儞僪専嶕 */ argv = argv_top; func = search_command (&argc, &argv); if (func == NULL) { printf ("僐儅儞僪偑惓偟偔偁傝傑偣傫.\n"); free (argv); continue; } /* 僗乕僷乕僶僀僓儌乕僪偱僐儅儞僪屇傃弌偟 */ rc = call_func (func, argc, argv); free (argv_top); /* 曉抣偑 -1 側傜廔椆 */ if (rc == -1) break; } return;}static intcall_func (CmdFunc func, int argc, char** argv){ int ssp = _dos_super (0); int rc = func (argc, argv); _dos_super (ssp); return rc;}/* Function: Nereid 憰拝専嵏 */static intis_exist_nereid (int nereid_id){ unsigned short buf; unsigned short* ne_ctrl = (unsigned short*) ((nereid_id == 0) ? 0xece3f0 : 0xece8f0); if (_dos_bus_err ((void*) 0xecc000, &buf, 2) == 0) return 0; /* Xellent30(#3)桳傝 */ if (_dos_bus_err (ne_ctrl, &buf, 2) == 0) return 1; /* Nereid 桳傝 */ return 0; }/* Function: main */intmain (void){ int nereid_id = 0; /* 尰嵼偺偲偙傠偼 #0 屌掕 */ /* Nereid 憰拝僠僃僢僋 */ if (!is_exist_nereid (nereid_id)) { printf ("usbmon: Nereid 偑憰拝偝傟偰偄傑偣傫.\n"); return 1; } printf ("Nereid USB Monitor version " VERSION); printf (" / Nereid ID=#%d\n", nereid_id); usbmon (nereid_id); return 0;}/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -