void CProtocolICMP::Process(RMBufChain &aPacket,CProtocolBase * /*aSourceProtocol*/) { RMBufRecvPacket packet; packet.Assign(aPacket); for (;;) // ONLY FOR NEAT BREAK EXITS -- NOT A LOOP { RMBufRecvInfo *const info = packet.Unpack(); if (info == NULL) break; LOG(Log::Printf(_L("\t%S Process(%d bytes)"), &ProtocolName(), info->iLength)); if (info->iIcmp) { // This packet is actually an ICMP error report to an ICMP sent by // this host. The iOffset points to "inner" ICMP, but tradionally // ICMP applications expect the outer RAW ICMP's, thus, change // the iOffset and other fields accordingly info->iOffset = info->iOffsetIp - 8 /* 8 = ICMP header size*/; info->iProtocol = info->iIcmp; // *NOTE* // The following assumes that outer IP tunnels have been removed // from the packet. Then, it can be assumed that the IP header // related to ICMP error is at the beginning of the packet (offset=0). info->iOffsetIp = 0; const MInterface *const mi = NetworkService()->Interfacer()->Interface(info->iInterfaceIndex); if (mi == NULL) break; TIpHeader *const ip = ((RMBufPacketPeek &)packet).GetIpHeader(); if (ip == NULL) break; TInetAddr &src = TInetAddr::Cast(info->iSrcAddr); TInetAddr &dst = TInetAddr::Cast(info->iDstAddr); if (ip->ip4.Version() == 4) { src.SetV4MappedAddress(ip->ip4.SrcAddr()); dst.SetV4MappedAddress(ip->ip4.DstAddr()); } else { src.SetAddress(ip->ip6.SrcAddr()); dst.SetAddress(ip->ip6.DstAddr()); } const TIp6Addr &src_ip = src.Ip6Address(); const TIp6Addr &dst_ip = dst.Ip6Address(); src.SetScope(mi->Scope((TScopeType)(src_ip.Scope()-1))); dst.SetScope(mi->Scope((TScopeType)(dst_ip.Scope()-1))); } // Check "payload length", and don't even try delivering truncated ICMP packets. if (info->iLength - info->iOffset < TInet6HeaderICMP::MinHeaderLength()) break; Deliver(packet); // *ALWAYS BREAK OUT FROM LOOP* break; } packet.Free(); }
static void DumpInterface(const BUSBInterface* interface) { if (!interface) return; printf(" Class .............. 0x%02x (%s)\n", interface->Class(), ClassName(interface->Class())); printf(" Subclass ........... 0x%02x%s\n", interface->Subclass(), SubclassName(interface->Class(), interface->Subclass())); printf(" Protocol ........... 0x%02x%s\n", interface->Protocol(), ProtocolName(interface->Class(), interface->Subclass(), interface->Protocol())); printf(" Interface String ... \"%s\"\n", interface->InterfaceString()); for (uint32 i = 0; i < interface->CountEndpoints(); i++) { const BUSBEndpoint* endpoint = interface->EndpointAt(i); if (!endpoint) continue; printf(" [Endpoint %" B_PRIu32 "]\n", i); printf(" MaxPacketSize .... %d\n", endpoint->MaxPacketSize()); printf(" Interval ......... %d\n", endpoint->Interval()); if (endpoint->IsControl()) printf(" Type ............. Control\n"); else if (endpoint->IsBulk()) printf(" Type ............. Bulk\n"); else if (endpoint->IsIsochronous()) printf(" Type ............. Isochronous\n"); else if (endpoint->IsInterrupt()) printf(" Type ............. Interrupt\n"); if (endpoint->IsInput()) printf(" Direction ........ Input\n"); else printf(" Direction ........ Output\n"); } char buffer[256]; usb_descriptor* generic = (usb_descriptor*)buffer; for (uint32 i = 0; interface->OtherDescriptorAt(i, generic, 256) == B_OK; i++) { printf(" [Descriptor %" B_PRIu32 "]\n", i); DumpDescriptor(&generic->generic, interface->Class(), interface->Subclass()); } }
void IProtocol::FatalError(const char* const aErrorMsg) const { HandleFatalError(ProtocolName(), aErrorMsg); }
static void DumpInfo(BUSBDevice& device, bool verbose) { const char* vendorName = NULL; const char* deviceName = NULL; usb_get_vendor_info(device.VendorID(), &vendorName); usb_get_device_info(device.VendorID(), device.ProductID(), &deviceName); if (!verbose) { printf("%04x:%04x /dev/bus/usb%s \"%s\" \"%s\" ver. %04x\n", device.VendorID(), device.ProductID(), device.Location(), vendorName ? vendorName : device.ManufacturerString(), deviceName ? deviceName : device.ProductString(), device.Version()); return; } printf("[Device /dev/bus/usb%s]\n", device.Location()); printf(" Class .................. 0x%02x (%s)\n", device.Class(), ClassName(device.Class())); printf(" Subclass ............... 0x%02x%s\n", device.Subclass(), SubclassName(device.Class(), device.Subclass())); printf(" Protocol ............... 0x%02x%s\n", device.Protocol(), ProtocolName(device.Class(), device.Subclass(), device.Protocol())); printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); uint32_t version = device.USBVersion(); printf(" USB Version ............ %d.%d\n", version >> 8, version & 0xFF); printf(" Vendor ID .............. 0x%04x", device.VendorID()); if (vendorName != NULL) printf(" (%s)", vendorName); printf("\n Product ID ............. 0x%04x", device.ProductID()); if (deviceName != NULL) printf(" (%s)", deviceName); printf("\n Product Version ........ 0x%04x\n", device.Version()); printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); printf(" Product String ......... \"%s\"\n", device.ProductString()); printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); for (uint32 i = 0; i < device.CountConfigurations(); i++) { printf(" [Configuration %" B_PRIu32 "]\n", i); DumpConfiguration(device.ConfigurationAt(i)); } if (device.Class() != 0x09) return; usb_hub_descriptor hubDescriptor; size_t size = device.GetDescriptor(USB_DESCRIPTOR_HUB, 0, 0, (void*)&hubDescriptor, sizeof(usb_hub_descriptor)); if (size == sizeof(usb_hub_descriptor)) { printf(" Hub ports count......... %d\n", hubDescriptor.num_ports); printf(" Hub Controller Current.. %dmA\n", hubDescriptor.max_power); for (int index = 1; index <= hubDescriptor.num_ports; index++) { usb_port_status portStatus; size_t actualLength = device.ControlTransfer(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_IN, USB_REQUEST_GET_STATUS, 0, index, sizeof(portStatus), (void*)&portStatus); if (actualLength != sizeof(portStatus)) continue; printf(" Port %d status....... %04x.%04x%s%s%s%s%s%s%s%s%s\n", index, portStatus.status, portStatus.change, portStatus.status & PORT_STATUS_CONNECTION ? " Connect": "", portStatus.status & PORT_STATUS_ENABLE ? " Enable": "", portStatus.status & PORT_STATUS_SUSPEND ? " Suspend": "", portStatus.status & PORT_STATUS_OVER_CURRENT ? " Overcurrent": "", portStatus.status & PORT_STATUS_RESET ? " Reset": "", portStatus.status & PORT_STATUS_POWER ? " Power": "", portStatus.status & PORT_STATUS_CONNECTION ? (portStatus.status & PORT_STATUS_LOW_SPEED ? " Lowspeed" : (portStatus.status & PORT_STATUS_HIGH_SPEED ? " Highspeed" : " Fullspeed")) : "", portStatus.status & PORT_STATUS_TEST ? " Test": "", portStatus.status & PORT_STATUS_INDICATOR ? " Indicator": ""); } } }