def handleEvent(self, event): if not event.isDataTransaction(): return header = Struct.Group(None, Struct.UInt16("handle"), Struct.UInt16("dataTotalLength"), ) params = header.decode(event.data) if header.handle is None: return boundaryFlag = (header.handle >> 12) & 3 broadcastFlag = (header.handle >> 14) & 3 handle = header.handle & 0x0FFF event.pushDecoded("BT ACL: handle=0x%04x len=0x%04x (%s%s)" % (handle, header.dataTotalLength, self.packetBoundaryNames[boundaryFlag], self.broadcastFlagNames[broadcastFlag]))
def decode_HCICommand(self, setup): header = Struct.Group(None, Struct.UInt16("opcode"), Struct.UInt8("numParameters"), ) params = header.decode(setup.event.data[8:]) if header.opcode is None: ocf = ogf = None else: ocf = header.opcode & 0x03FF ogf = header.opcode >> 10 ogfName = self.hciOpcodes.get(ogf, (ogf, {}))[0] ocfName = self.hciOpcodes.get(ogf, (ogf, {}))[1].get(ocf, ocf) setup.event.pushDecoded("BT Command: %s [%s]" % (ocfName, ogfName))
class DescriptorGroup(Struct.Group): """Parses out USB descriptors into a Struct.Group tree. This class handles any standard descriptor, but subclasses can add class-specific descriptors as needed. """ descriptorTypes = Struct.EnumDict({ 0x01: "device", 0x02: "config", 0x03: "string", 0x04: "interface", 0x05: "endpoint", }) headerStruct = lambda self: ( Struct.UInt8("bLength"), Struct.UInt8("bDescriptorType"), ) struct_device = lambda self: ( Struct.UInt16Hex("bcdUSB"), Struct.UInt8Hex("bDeviceClass"), Struct.UInt8Hex("bDeviceSubClass"), Struct.UInt8Hex("bDeviceProtocol"), Struct.UInt8("bMaxPacketSize0"), Struct.UInt16Hex("idVendor"), Struct.UInt16Hex("idProduct"), Struct.UInt16Hex("bcdDevice"), Struct.UInt8("iManufacturer"), Struct.UInt8("iProduct"), Struct.UInt8("iSerialNumber"), Struct.UInt8("bNumConfigurations"), ) struct_config = lambda self: ( Struct.UInt16("wTotalLength"), Struct.UInt8("bNumInterfaces"), Struct.UInt8("bConfigurationValue"), Struct.UInt8("iConfiguration"), Struct.UInt8Hex("bmAttributes"), Struct.UInt8("MaxPower"), ) struct_string = lambda self: (Struct.Utf16String("string"), ) struct_interface = lambda self: ( Struct.UInt8("bInterfaceNumber"), Struct.UInt8("bAlternateSetting"), Struct.UInt8("bNumEndpoints"), Struct.UInt8Hex("bInterfaceClass"), Struct.UInt8Hex("bInterfaceSubClass"), Struct.UInt8Hex("bInterfaceProtocol"), Struct.UInt8("iInterface"), ) struct_endpoint = lambda self: ( Struct.UInt8Hex("bEndpointAddress"), Struct.UInt8Hex("bmAttributes"), Struct.UInt16("wMaxPacketSize"), Struct.UInt8("bInterval"), ) def __init__(self): Struct.Group.__init__(self, "descriptors") def decode(self, buffer): # Common descriptor header buffer = Struct.Group.decode(self, buffer, self.headerStruct()) # Decode descriptor type self.type = self.descriptorTypes[self.bDescriptorType] # Make sure that we eat exactly the right number of bytes, # according to the descriptor header descriptor = buffer[:self.bLength - 2] buffer = buffer[self.bLength - 2:] # The rest of the decoding is done by a hander, in the form of a child item list. Struct.Group.decode( self, descriptor, getattr(self, "struct_%s" % self.type, lambda: None)()) return buffer