📄 usrusbtool.c
字号:
return; } if (pDevDescr->manufacturerIndex != 0 || pDevDescr->productIndex != 0) fprintf (fout, " = "); if (pDevDescr->manufacturerIndex != 0) { showUsbString (clientHandle, nodeId, fout, pDevDescr->manufacturerIndex, MAX_MFG_STR_LEN); fprintf (fout, "/"); } if (pDevDescr->productIndex != 0) { showUsbString (clientHandle, nodeId, fout, pDevDescr->productIndex, MAX_PROD_STR_LEN); } }/***************************************************************************** HubEnumerate - Enumerate all ports on the specified hub* * This routine enumerates all devices from the specified HubId down.* <clientHandle> must be a valid USBD_CLIENT_HANDLE. <hubId> specifies* the Node Id of the first USB hub to be enumerated.** RETURNS: OK, or ERROR if USBD returns an error.*/LOCAL UINT16 HubEnumerate ( USBD_CLIENT_HANDLE clientHandle, /* Caller抯 USBD client handle */ USBD_NODE_ID hubId, /* Node Id for hub to enumerate */ FILE *fout, UINT16 indent ) { UINT16 portCount; /* Number of ports on this hub */ UINT16 portIndex; /* current port index */ UINT16 nodeType; /* type of node being enumerated */ USBD_NODE_ID nodeId; /* id of node being enumerated */ UINT16 s; /* Retrieve the number of ports for this hub. */ fprintf (fout, "%*shub 0x%x", indent, "", (UINT32) hubId); showMfgModel (clientHandle, hubId, fout); fprintf (fout, "\n"); if ((s = usbdHubPortCountGet (clientHandle, hubId, &portCount)) != OK) { fprintf (fout, "usbdHubPortCountGet() returned %d\n", s); return ERROR; } fprintf (fout, "%*sport count = %d\n", indent+INDENT, "", portCount); /* See if a device is attached to each of the hub抯 ports. */ for (portIndex = 0; portIndex < portCount; portIndex++) { if ((s = usbdNodeIdGet (clientHandle, hubId, portIndex, &nodeType, &nodeId)) != OK) { fprintf (fout, "%*susbdNodeIdGet() returned %d\n", indent+INDENT, "", s); return ERROR; } switch (nodeType) { case USB_NODETYPE_NONE: /* No device attached. */ fprintf (fout, "%*sport %d not connected\n", indent+INDENT, "", portIndex); break; case USB_NODETYPE_HUB: /* Another hub found. */ fprintf (fout, "%*sport %d is hub 0x%x\n", indent+INDENT, "", portIndex, (UINT32) nodeId); if (HubEnumerate (clientHandle, nodeId, fout, indent+INDENT) != OK) return ERROR; break; case USB_NODETYPE_DEVICE: /* Device attached to port. */ fprintf (fout, "%*sport %d is device 0x%x", indent+INDENT, "", portIndex, (UINT32) nodeId); showMfgModel (clientHandle, nodeId, fout); fprintf (fout, "\n"); break; default: /* Unknown node type code */ fprintf (fout, "%*snode type not recognized for node 0x%x\n", indent+INDENT, "", (UINT32) nodeId); break; } } return OK; }/***************************************************************************** USBEnumerate - Enumerate all USB host controllers in the system.* * This routine enumerates all USB host controllers, hubs, and devices* currently connected to the system. The caller must register with the* USBD prior to calling this function and supply its USBD_CLIENT_HANDLE* in <clientHandle>.** RETURNS: OK, or ERROR if USBD returns an error.*/LOCAL UINT16 USBEnumerate ( USBD_CLIENT_HANDLE clientHandle, /* Caller抯 USBD client handle */ FILE *fout ) { UINT16 busCount; /* Number of USB host controllers */ UINT16 busIndex; /* current bus index */ USBD_NODE_ID rootId; /* Root hub id for current bus */ UINT16 s; /* Retrieve the number of USB host controllers in the system. */ if ((s = usbdBusCountGet (clientHandle, &busCount)) != OK) { fprintf (fout, "usbdBusCountGet() returned %d\n", s); return ERROR; } fprintf (fout, "bus count = %d\n", busCount); /* Retrieve the root hub id for each host controller and enumerate it. */ for (busIndex = 0; busIndex < busCount; busIndex++) { if ((s = usbdRootNodeIdGet (clientHandle, busIndex, &rootId)) != OK) { fprintf (fout, "usbdRootNodeIdGet() returned %d\n", s); return ERROR; } fprintf (fout, "enumerating bus %d\n", busIndex); if (HubEnumerate (clientHandle, rootId, fout, INDENT) != OK) return ERROR; } return OK; }/*************************************************************************** cmdUsbEnum - Enumerate USBs attached to system** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdUsbEnum ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { USBEnumerate (usbdClientHandle, fout); return RET_CONTINUE; }/*************************************************************************** cmdUsbStats - Show bus statistics** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdUsbStats ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; USBD_STATS stats; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); /* Validate parameters */ if (nodeId == -1) { fprintf (fout, "Must specify a node id.\n"); return RET_CONTINUE; } /* Execute function. */ if ((s = usbdStatisticsGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, &stats, sizeof (stats))) != OK) fprintf (fout, "usbdStatisticsGet() returned %d\n", s); else { fprintf (fout, "totalTransfersIn = %ld\n", (long) stats.totalTransfersIn); fprintf (fout, "totalTransfersout = %ld\n", (long) stats.totalTransfersOut); fprintf (fout, "totalReceiveErrors = %ld\n", (long) stats.totalReceiveErrors); fprintf (fout, "totalTransmitErrors = %ld\n", (long) stats.totalTransmitErrors); } return RET_CONTINUE; }/*************************************************************************** cmdGetConfig - get current configuration value for a device** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdGetConfig ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; UINT16 * pConfiguration; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); /* Validate parameters */ if (nodeId == -1) { fprintf (fout, "Must specify a node id.\n"); return RET_CONTINUE; } if ((pConfiguration = OSS_MALLOC (sizeof (UINT16))) == NULL) return RET_CONTINUE; /* Execute function. */ if ((s = usbdConfigurationGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, pConfiguration)) != OK) fprintf (fout, "usbdConfigurationGet() returned %d\n", s); else fprintf (fout, "current configuration = 0x%x\n", *pConfiguration); OSS_FREE (pConfiguration); return RET_CONTINUE; }/*************************************************************************** cmdSetConfig - set current configuration value for a device** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdSetConfig ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; long configuration; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); *ppCmd = GetHexToken (*ppCmd, &configuration, -1); /* Validate parameters */ if (nodeId == -1 || configuration == -1) { fprintf (fout, "Must specify a node id and configuration value.\n"); return RET_CONTINUE; } /* Execute function. */ s = usbdConfigurationSet (usbdClientHandle, (GENERIC_HANDLE) nodeId, (UINT16) configuration, 0); fprintf (fout, "usbdConfigurationSet() returned %d\n", s); return RET_CONTINUE; }/*************************************************************************** cmdGetInterface - get alt. setting for an interface** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdGetInterface ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; long index; UINT16 * pAltSetting; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); *ppCmd = GetHexToken (*ppCmd, &index, -1); /* Validate parameters */ if (nodeId == -1 || index == -1) { fprintf (fout, "Must specify a node id and interface number.\n"); return RET_CONTINUE; } if ((pAltSetting = OSS_MALLOC (sizeof (UINT16))) == NULL) return RET_CONTINUE; /* Execute function. */ if ((s = usbdInterfaceGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, index, pAltSetting)) != OK) fprintf (fout, "usbdInterfaceGet() returned %d\n", s); else fprintf (fout, "alternate setting = 0x%x\n", *pAltSetting); OSS_FREE (pAltSetting); return RET_CONTINUE; }/*************************************************************************** cmdSetInterface - set alt. setting for an interface** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdSetInterface ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; long index; long altSetting; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); *ppCmd = GetHexToken (*ppCmd, &index, -1); *ppCmd = GetHexToken (*ppCmd, &altSetting, -1); /* Validate parameters */ if (nodeId == -1 || index == -1 || altSetting == -1) { fprintf (fout, "Must specify a node id, interface number, and alt. setting.\n"); return RET_CONTINUE; } /* Execute function. */ s = usbdInterfaceSet (usbdClientHandle, (GENERIC_HANDLE) nodeId, index, altSetting); fprintf (fout, "usbdInterfaceSet() returned %d\n", s); return RET_CONTINUE; }#endif /* INCLUDE_USB from way above*//*************************************************************************** displayMem - dumps memory to display** RETURNS: N/A*/LOCAL VOID displayMem ( UINT16 bfrLen, pUINT8 pBfr, FILE *fout ) { int i,j; for (i = 0; i < bfrLen; i += 16) { for (j = i; j < bfrLen && j < i+16; j++) { fprintf (fout, "%2.2x ", pBfr [j]); if (j % 16 == 7) fprintf (fout, " "); } fprintf (fout, " "); for (j = i; j < bfrLen && j < i+16; j++) { fprintf (fout, "%c", (pBfr [j] >= 32 && pBfr [j] <= 127) ? pBfr [j] : '.'); } fprintf (fout, "\n"); } }#ifdef INCLUDE_USB/*************************************************************************** cmdGetStatus - get status for a device/interface/endpoint** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdGetStatus ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; long statusType; long index; long length; UINT8 * pStatusBfr; UINT16 actLen; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); *ppCmd = GetHexToken (*ppCmd, &statusType, -1); *ppCmd = GetHexToken (*ppCmd, &index, -1); *ppCmd = GetHexToken (*ppCmd, &length, -1); /* Validate parameters */ if (nodeId == -1 || statusType == -1 || index == -1 || length == -1) { fprintf (fout, "Must specify a node id, status type, and index.\n"); return RET_CONTINUE; } if (length > GENERIC_USB_BFR) { fprintf (fout, "length must be 0x%x or less.\n", (unsigned int) GENERIC_USB_BFR); return RET_CONTINUE; } if ((pStatusBfr = OSS_MALLOC (GENERIC_USB_BFR)) == NULL) return RET_CONTINUE; /* Execute function. */ if ((s = usbdStatusGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, statusType, index, length, pStatusBfr, &actLen)) != OK) fprintf (fout, "usbdStatusGet() returned %d\n", s); else { fprintf (fout, "actLen = 0x%x (%d) bytes\n", actLen, actLen); displayMem (actLen, pStatusBfr, fout); } OSS_FREE (pStatusBfr); return RET_CONTINUE; }/*************************************************************************** cmdGetAddress - get USB address for a node** RETURNS: RET_CONTINUE;*/LOCAL UINT16 cmdGetAddress ( pVOID Param, /* Generic parameter passed down */ char **ppCmd, /* Ptr to remainder of cmd line */ FILE *fin, /* stream for input (if any) */ FILE *fout /* stream for output (if any) */ ) { long nodeId; UINT16 address; UINT16 s; /* Extract parameters. */ *ppCmd = GetHexToken (*ppCmd, &nodeId, -1); /* Validate parameters */ if (nodeId == -1) { fprintf (fout, "Must specify a node id.\n"); return RET_CONTINUE; } /* Execute function. */ if ((s = usbdAddressGet (usbdClientHandle, (GENERIC_HANDLE) nodeId, &address)) != OK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -