X-Git-Url: http://git.rot13.org//?p=goodfet;a=blobdiff_plain;f=client%2FUSBDevice.py;fp=client%2FUSBDevice.py;h=e25fea88dcf0f91ad4c1762dbd3f727d0f066f46;hp=84e8b1ff3a3e84f958af2206308b834843bcfdf3;hb=85180b93353582dd0cb8c344b6170192c858f86d;hpb=f89ac90c389c244a33e7b5dd20090bf588763291 diff --git a/client/USBDevice.py b/client/USBDevice.py index 84e8b1f..e25fea8 100644 --- a/client/USBDevice.py +++ b/client/USBDevice.py @@ -133,7 +133,11 @@ class USBDevice: elif req.get_recipient() == USB.request_recipient_interface: recipient = self.configuration.interfaces[req.index] elif req.get_recipient() == USB.request_recipient_endpoint: - recipient = self.configuration.endpoints[req.index] + try: + recipient = self.endpoints[req.index] + except KeyError: + self.maxusb_app.stall_ep0() + return # and then the type if req.get_type() == USB.request_type_standard: @@ -148,12 +152,12 @@ class USBDevice: self.maxusb_app.stall_ep0() def handle_data_available(self, ep_num, data): - if self.ready and ep_num in self.endpoints: + if self.state == USB.state_configured and ep_num in self.endpoints: endpoint = self.endpoints[ep_num] endpoint.handler(data) def handle_buffer_available(self, ep_num): - if self.ready and ep_num in self.endpoints: + if self.state == USB.state_configured and ep_num in self.endpoints: endpoint = self.endpoints[ep_num] endpoint.handler() @@ -230,6 +234,11 @@ class USBDevice: else: # string descriptors start at 1 s = self.strings[num-1].encode('utf-16') + + # Linux doesn't like the leading 2-byte Byte Order Mark (BOM); + # FreeBSD is okay without it + s = s[2:] + d = bytearray([ len(s) + 2, # length of descriptor in bytes 3 # descriptor type 3 == string