diff options
| author | Wei Mao <[email protected]> | 2017-03-15 12:58:20 -0700 |
|---|---|---|
| committer | Wei Mao <[email protected]> | 2017-03-15 12:58:20 -0700 |
| commit | 80cc22cbdea1de8d21eb406bf351a916ca2c4b43 (patch) | |
| tree | 6ea96c638c1b8041f12aab4dc7d19d5d952a2e73 /usb/usbview/xmlhelper.cpp | |
| parent | 6b8cbe40b82f442860902752ff2df18ac1daf229 (diff) | |
[usb] Fix Code Analysis Warnings
Diffstat (limited to 'usb/usbview/xmlhelper.cpp')
| -rw-r--r-- | usb/usbview/xmlhelper.cpp | 147 |
1 files changed, 79 insertions, 68 deletions
diff --git a/usb/usbview/xmlhelper.cpp b/usb/usbview/xmlhelper.cpp index fc58840e..f67c9587 100644 --- a/usb/usbview/xmlhelper.cpp +++ b/usb/usbview/xmlhelper.cpp @@ -27,7 +27,7 @@ Revision History: #include "h264.h" #include "xmlhelper.h" -// usbschema.hpp is autogenerated from schema during build PASS0 +// usbschema.hpp is autogenerated from schema during build PASS0 #include "usbschema.hpp" // Include code analysis suppressions @@ -56,7 +56,7 @@ Revision History: #define USB_GENERIC "USB GENERIC (UNKNOWN)" /***************************************************************************** - N A M E S P A C E S + N A M E S P A C E S *****************************************************************************/ using namespace System; @@ -148,7 +148,7 @@ void XmlAddPipeInformation( ULONG numPipes, UCHAR connectionSpeed); void XmlAddUsbDeviceDescriptor( - UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, + UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, PUSB_DEVICE_DESCRIPTOR usbDeviceDescriptor); void XmlAddConfigurationDescriptor( UsbConfigurationDescriptorType ^ confXmlDesc, @@ -176,7 +176,7 @@ bool XmlAddDeviceClassDetails( PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfo, PUSBDEVICEINFO deviceInfo); void XmlAddConnectionInfo( - NodeConnectionInfoExType ^xmlConnectionInfo, + NodeConnectionInfoExType ^xmlConnectionInfo, PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfo, PUSBDEVICEINFO deviceInfo, PSTRING_DESCRIPTOR_NODE stringDesc, @@ -223,13 +223,13 @@ UsbBillboardCapabilityDescriptorType ^ XmlGetBillboardCapabilityDescriptor( ); /***************************************************************************** - D E F I N I T I O N S + D E F I N I T I O N S *****************************************************************************/ /***************************************************************************** XmlNotifyEndOfNodeList - This function is called back by WalkTreeTopDown() function to notify us + This function is called back by WalkTreeTopDown() function to notify us that there are no more children to add for the current parent *****************************************************************************/ @@ -302,7 +302,7 @@ HRESULT XmlAddHostController(PSTR hcName, PUSBHOSTCONTROLLERINFO hcInfo) else { // Create a new array every time as Array.Resize does not seem to work in our case (CLI) - // We do this using ArrayList. + // We do this using ArrayList. ArrayList ^hcList = gcnew ArrayList; hcList->AddRange(gXmlView->UsbTree); hc = gcnew HostControllerType(); @@ -325,20 +325,31 @@ HRESULT XmlAddHostController(PSTR hcName, PUSBHOSTCONTROLLERINFO hcInfo) hc->DeviceName = PACHAR_TO_STRING(hcInfo->UsbDeviceProperties->DeviceDesc); hc->DeviceClass = PACHAR_TO_STRING(hcInfo->UsbDeviceProperties->DeviceClass); - if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_OHCI) == 0) + bool foundUsbProtocol = false; + if (hcInfo->UsbDeviceProperties->Service != NULL) { - hc->UsbProtocol = gcnew String(USB_1_1); - } - else if(_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_EHCI) == 0 || - _stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_UHCI) == 0) - { - hc->UsbProtocol = gcnew String(USB_2_0); - } - else if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_XHCI) == 0) - { - hc->UsbProtocol = gcnew String(USB_3_0); + foundUsbProtocol = true; + + if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_OHCI) == 0) + { + hc->UsbProtocol = gcnew String(USB_1_1); + } + else if(_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_EHCI) == 0 || + _stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_UHCI) == 0) + { + hc->UsbProtocol = gcnew String(USB_2_0); + } + else if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_XHCI) == 0) + { + hc->UsbProtocol = gcnew String(USB_3_0); + } + else + { + foundUsbProtocol = false; + } } - else + + if (!foundUsbProtocol) { // If protocol lookup failed based on service name, try Controller flavor if(NULL != hcInfo->ControllerInfo) @@ -488,10 +499,10 @@ void XmlAddConnectionInfoV2(NodeConnectionInfoExV2Type ^ connectionXmlInfo, PUSB connectionXmlInfo->Usb200Supported = connectionInfo->SupportedUsbProtocols.Usb200? true:false; connectionXmlInfo->Usb300Supported = connectionInfo->SupportedUsbProtocols.Usb300? true:false; - connectionXmlInfo->DeviceIsOperatingAtSuperSpeedOrHigher = + connectionXmlInfo->DeviceIsOperatingAtSuperSpeedOrHigher = connectionInfo->Flags.DeviceIsOperatingAtSuperSpeedOrHigher; - connectionXmlInfo->DeviceIsSuperSpeedCapableOrHigher = + connectionXmlInfo->DeviceIsSuperSpeedCapableOrHigher = connectionInfo->Flags.DeviceIsSuperSpeedCapableOrHigher; connectionXmlInfo->DeviceIsOperatingAtSuperSpeedPlusOrHigher = @@ -499,7 +510,7 @@ void XmlAddConnectionInfoV2(NodeConnectionInfoExV2Type ^ connectionXmlInfo, PUSB connectionXmlInfo->DeviceIsSuperSpeedPlusCapableOrHigher = connectionInfo->Flags.DeviceIsSuperSpeedPlusCapableOrHigher; - + } return; } @@ -655,7 +666,7 @@ ExternalHubType ^ AddExternalHub(Object ^parent) boolean arrayCreated = false; // An external hub can be connected to a Root Hub or another External Hub - // We need to determine the type of the object. + // We need to determine the type of the object. // Try root hub first @@ -736,7 +747,7 @@ NoDeviceType ^ AddDisconnectedPort(Object ^parent) boolean arrayCreated = false; // An external hub can be connected to a Root Hub or another External Hub - // We need to determine the type of the object. + // We need to determine the type of the object. // Try RH first @@ -818,7 +829,7 @@ UsbDeviceType ^ AddUsbDevice(Object ^parent) boolean arrayCreated = false; // An external hub can be connected to a Root Hub or another External Hub - // We need to determine the type of the object. + // We need to determine the type of the object. // Try RH first @@ -937,9 +948,9 @@ void XmlAddIADDescriptor( iadDesc->bFunctionProtocol); // Protocol check - if (iadDesc->bFunctionClass == USB_DEVICE_CLASS_VIDEO) + if (iadDesc->bFunctionClass == USB_DEVICE_CLASS_VIDEO) { - if (iadDesc->bFunctionProtocol != PC_PROTOCOL_UNDEFINED) + if (iadDesc->bFunctionProtocol != PC_PROTOCOL_UNDEFINED) { iadXmlDesc->Protocol= gcnew String("WARNING: Protocol must be set to PC_PROTOCOL_UNDEFINED"); iadXmlDesc->Protocol+= " for this class but is set to: "; @@ -949,7 +960,7 @@ void XmlAddIADDescriptor( { iadXmlDesc->Protocol = gcnew String("PC_PROTOCOL_UNDEFINED protocol"); } - } + } if (iadDesc->iFunction) { @@ -1084,7 +1095,7 @@ UsbDeviceUnknownDescriptorType ^ XmlGetUnknownDescriptor( void XmlAddEndpointDescriptor( EndpointDescriptorType ^usbXmlEndpointDescriptor, PUSB_ENDPOINT_DESCRIPTOR endPointDescriptor, - UCHAR connectionSpeed + UCHAR connectionSpeed ) { EndpointDescriptorType ^ue = usbXmlEndpointDescriptor; @@ -1172,10 +1183,10 @@ void XmlAddEndpointDescriptor( } // Add validation - if (endPointDescriptor->wMaxPacketSize & 0xE000) + if (endPointDescriptor->wMaxPacketSize & 0xE000) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: wMaxPacketSize bits 15-13 should be 0"); - } else if (connectionSpeed==UsbHighSpeed) + } else if (connectionSpeed==UsbHighSpeed) { USHORT hsMux; @@ -1187,26 +1198,26 @@ void XmlAddEndpointDescriptor( case USB_ENDPOINT_TYPE_INTERRUPT: switch (hsMux) { case 0: - if ((maxBytes < 1) || (maxBytes > 1024)) + if ((maxBytes < 1) || (maxBytes > 1024)) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: Invalid maximum packet size, should be between 1 and 1024"); } break; case 1: - if ((maxBytes < 513) || (maxBytes > 1024)) + if ((maxBytes < 513) || (maxBytes > 1024)) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: Invalid maximum packet size, should be between 513 and 1024"); } break; case 2: - if ((maxBytes < 683) || (maxBytes > 1024)) + if ((maxBytes < 683) || (maxBytes > 1024)) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: Invalid maximum packet size, should be between 683 and 1024"); } break; - + case 3: ue->EndpointPacketSizeValidation = gcnew String("ERROR: Bits 12-11 set to reserved value\r\n"); break; @@ -1264,7 +1275,7 @@ void XmlAddPipeInformation( This routine adds usb device descriptor *****************************************************************************/ void XmlAddUsbDeviceDescriptor( - UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, + UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, PUSB_DEVICE_DESCRIPTOR usbDeviceDescriptor) { UsbDeviceDescriptorType ^ud = usbXmlDeviceDescriptor; @@ -1310,7 +1321,7 @@ void XmlAddConfigurationDescriptor( return; } - if(deviceInfo->ConnectionInfoV2 && + if(deviceInfo->ConnectionInfoV2 && (deviceInfo->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedOrHigher || deviceInfo->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedPlusOrHigher)) { @@ -1328,9 +1339,9 @@ void XmlAddConfigurationDescriptor( uCount = GetConfigurationSize(deviceInfo); - if (uCount != configDesc->wTotalLength) + if (uCount != configDesc->wTotalLength) { - confXmlDesc->ConfigDescError = gcnew String("ERROR: Invalid total configuration size " + + confXmlDesc->ConfigDescError = gcnew String("ERROR: Invalid total configuration size " + configDesc->wTotalLength + ", should be " + uCount); } @@ -1432,7 +1443,7 @@ UsbDeviceClassType ^ XmlGetDeviceClass(UCHAR bInterfaceClass, UCHAR bInterfaceSu case USB_DEVICE_CLASS_VENDOR_SPECIFIC: deviceClass = gcnew String("Vendor Specific Device"); break; - + case USB_DEVICE_CLASS_HUMAN_INTERFACE: deviceClass = gcnew String("HID Interface"); @@ -1547,7 +1558,7 @@ UsbDeviceClassType ^ XmlGetDeviceClass(UCHAR bInterfaceClass, UCHAR bInterfaceSu default: deviceClass = gcnew String("Interface Class unknown : "); - deviceClass += bInterfaceClass; + deviceClass += bInterfaceClass; break; } @@ -1588,15 +1599,15 @@ void XmlAddDeviceInterfaceDescriptor( // Update class and sub class ifXmlDesc->InterfaceDetails = XmlGetDeviceClass( - ifDesc->bInterfaceClass, + ifDesc->bInterfaceClass, ifDesc->bInterfaceSubClass, ifDesc->bInterfaceProtocol); //This is basically the check for PC_PROTOCOL_UNDEFINED - if ((ifDesc->bInterfaceClass == USB_DEVICE_CLASS_VIDEO) || - (ifDesc->bInterfaceClass == USB_DEVICE_CLASS_AUDIO)) + if ((ifDesc->bInterfaceClass == USB_DEVICE_CLASS_VIDEO) || + (ifDesc->bInterfaceClass == USB_DEVICE_CLASS_AUDIO)) { - if (ifDesc->bInterfaceProtocol != PC_PROTOCOL_UNDEFINED) + if (ifDesc->bInterfaceProtocol != PC_PROTOCOL_UNDEFINED) { ifXmlDesc->ProtocolError = gcnew String("WARNING: Protocol must be set to PC_PROTOCOL_UNDEFINED"); ifXmlDesc->ProtocolError += " for this class but is set to: "; @@ -2087,9 +2098,9 @@ String ^ XmlGetStringDescriptor(UCHAR index, PSTRING_DESCRIPTOR_NODE stringDesc, if ((foundDescriptor == false) && (foundNonEnglishDescriptor == false)) { // If no descriptor was found, return error message in field - desc = gcnew String("ERROR: No String descriptor for index " + + desc = gcnew String("ERROR: No String descriptor for index " + index); - } + } else if ((foundDescriptor == false) && (foundNonEnglishDescriptor == true) && (enOnly)) { desc = gcnew String("ERROR: The index " + index + " does not support English(US)"); @@ -2196,9 +2207,9 @@ bool XmlAddDeviceClassDetails( { deviceDetails->DeviceProtocol = gcnew String("Interface Association Descriptor protocol"); } - else + else { - deviceDetails->DeviceProtocolError = gcnew String("ERROR: device Protocol should be USB IAD Protocol " + + deviceDetails->DeviceProtocolError = gcnew String("ERROR: device Protocol should be USB IAD Protocol " + USB_IAD_PROTOCOL + " when IAD descriptor is used"); } @@ -2208,7 +2219,7 @@ bool XmlAddDeviceClassDetails( { deviceDetails->DeviceType = XmlGetDeviceClassString(connectionInfo->DeviceDescriptor.bDeviceClass); - if (connectionInfo->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_BILLBOARD && + if (connectionInfo->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_BILLBOARD && (connectionInfo->DeviceDescriptor.bDeviceSubClass != 0x0 || connectionInfo->DeviceDescriptor.bDeviceProtocol != 0x0)) { @@ -2233,7 +2244,7 @@ bool XmlAddDeviceClassDetails( } // Not an IAD device, so all subclass values are invalid - if (connectionInfo->DeviceDescriptor.bDeviceSubClass > 0x00 && + if (connectionInfo->DeviceDescriptor.bDeviceSubClass > 0x00 && connectionInfo->DeviceDescriptor.bDeviceSubClass < 0xFF) { deviceDetails->SubclassTypeError = gcnew String("ERROR: bDeviceSubClass is invalid - " + @@ -2241,7 +2252,7 @@ bool XmlAddDeviceClassDetails( } // Not an IAD device, so all subclass values are invalid, check protocol - if (connectionInfo->DeviceDescriptor.bDeviceProtocol > 0x00 && + if (connectionInfo->DeviceDescriptor.bDeviceProtocol > 0x00 && connectionInfo->DeviceDescriptor.bDeviceProtocol < 0xFF && tog==1) { deviceDetails->DeviceProtocolError = gcnew String("ERROR: bDeviceProtocol is invalid - " + @@ -2259,7 +2270,7 @@ bool XmlAddDeviceClassDetails( This routine adds connection information for the device *****************************************************************************/ void XmlAddConnectionInfo( - NodeConnectionInfoExType ^xmlConnectionInfo, + NodeConnectionInfoExType ^xmlConnectionInfo, PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfo, PUSBDEVICEINFO deviceInfo, PSTRING_DESCRIPTOR_NODE stringDesc, @@ -2281,7 +2292,7 @@ void XmlAddConnectionInfo( if (connectionInfo->DeviceDescriptor.iProduct) { - // Add EN version of string descriptor + // Add EN version of string descriptor nc->IProductStringDescEn = XmlGetStringDescriptor( connectionInfo->DeviceDescriptor.iProduct, @@ -2298,7 +2309,7 @@ void XmlAddConnectionInfo( // Check device descriptor length if (connectionInfo->DeviceDescriptor.bLength != DEVICE_DESCRIPTOR_LENGTH) { - nc->LengthError = gcnew String("ERROR: bLength " + + nc->LengthError = gcnew String("ERROR: bLength " + connectionInfo->DeviceDescriptor.bLength + " incorrect, should be " + DEVICE_DESCRIPTOR_LENGTH @@ -2306,7 +2317,7 @@ void XmlAddConnectionInfo( } // Check for device error - if ((connectionInfo->ConnectionStatus == DeviceFailedEnumeration) || + if ((connectionInfo->ConnectionStatus == DeviceFailedEnumeration) || (connectionInfo->ConnectionStatus == DeviceGeneralFailure)) { nc->DeviceError = gcnew String("ERROR: Device enumeration failure"); @@ -2447,7 +2458,7 @@ HRESULT XmlAddExternalHub(PSTR ehName, PUSBEXTERNALHUBINFO ehInfo) exHub->PortConnector = gcnew PortConnectorType(); XmlAddPortConnectorProps( - exHub->PortConnector, + exHub->PortConnector, ehInfo->PortConnectorProps ); } @@ -2518,16 +2529,16 @@ UsbBosDescriptorType ^ XmlGetBosDescriptor( commonDesc = (PUSB_COMMON_DESCRIPTOR) bosDesc; - while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR) bosDesc, - bosDesc->wTotalLength, - commonDesc, + while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR) bosDesc, + bosDesc->wTotalLength, + commonDesc, -1)) != NULL) { switch (commonDesc->bDescriptorType) { case USB_DEVICE_CAPABILITY_DESCRIPTOR_TYPE: capDesc = (PUSB_DEVICE_CAPABILITY_DESCRIPTOR)commonDesc; - switch (capDesc->bDevCapabilityType) + switch (capDesc->bDevCapabilityType) { case USB_DEVICE_CAPABILITY_USB20_EXTENSION: usb20CapExtDescList->Add( @@ -2591,7 +2602,7 @@ UsbBosDescriptorType ^ XmlGetBosDescriptor( ); return bosXmlDesc; -} +} /***************************************************************************** @@ -2980,7 +2991,7 @@ HRESULT XmlAddUsbDevice(PSTR devName, PUSBDEVICEINFO deviceInfo) deviceInfo->DeviceInfoNode ); - // Add port connector + // Add port connector if (NULL != deviceInfo->PortConnectorProps) { usbDevice->PortConnector = gcnew PortConnectorType(); @@ -3049,7 +3060,7 @@ HRESULT XmlAddRootHub(PSTR rhName, PUSBROOTHUBINFO rhInfo) if (hcParent != nullptr) { RootHubType ^ rh = nullptr; - hcParent = (HostControllerType ^) parent; + hcParent = (HostControllerType ^) parent; hcParent->RootHub = gcnew RootHubType(); rh = hcParent->RootHub; @@ -3116,7 +3127,7 @@ VOID XmlSetVersion( InitXmlHelper() - Initialize XML helper + Initialize XML helper *****************************************************************************/ HRESULT InitXmlHelper() { @@ -3132,9 +3143,9 @@ HRESULT InitXmlHelper() (XmlGlobal::Instance())->ViewAll->UvcView->UsbTree = nullptr; XmlSetVersion( - UVC_SPEC_MAJOR_VERSION, - UVC_SPEC_MINOR_VERSION, - USBVIEW_MAJOR_VERSION, + UVC_SPEC_MAJOR_VERSION, + UVC_SPEC_MINOR_VERSION, + USBVIEW_MAJOR_VERSION, USBVIEW_MINOR_VERSION ); |
