diff --git a/facedancer/future/device.py b/facedancer/future/device.py index 8f7744bd..773a7904 100644 --- a/facedancer/future/device.py +++ b/facedancer/future/device.py @@ -21,6 +21,7 @@ from .descriptor import USBDescribable, USBDescriptor, StringDescriptorManager from .configuration import USBConfiguration +from .interface import USBInterface from .endpoint import USBEndpoint from .request import USBControlRequest, USBRequestHandler from .request import standard_request_handler, to_device, get_request_handler_methods @@ -665,8 +666,10 @@ def get_string_descriptor(self, index:int) -> bytes: else: return self.strings[index] - - def handle_generic_get_descriptor_request(self, request: USBControlRequest): + @staticmethod + def handle_generic_get_descriptor_request( + descriptor_container:Union['USBDevice', USBInterface], + request: USBControlRequest): """ Handle GET_DESCRIPTOR requests; per USB2 [9.4.3] """ logging.debug(f"received GET_DESCRIPTOR request {request}") @@ -676,7 +679,7 @@ def handle_generic_get_descriptor_request(self, request: USBControlRequest): descriptor_index = request.value_low # Try to find the descriptor associate with the request. - response = self.descriptors.get(descriptor_type, None) + response = descriptor_container.descriptors.get(descriptor_type, None) # If we have a callable, we need to evaluate it to figure # out what the actual descriptor should be. @@ -763,7 +766,7 @@ def handle_get_descriptor_request(self, request): """ Handle GET_DESCRIPTOR requests; per USB2 [9.4.3] """ # Defer to our generic get_descriptor handler. - self.handle_generic_get_descriptor_request(request) + self.handle_generic_get_descriptor_request(self, request) diff --git a/facedancer/future/endpoint.py b/facedancer/future/endpoint.py index ec64a4a3..96ff64ce 100644 --- a/facedancer/future/endpoint.py +++ b/facedancer/future/endpoint.py @@ -157,7 +157,7 @@ def get_identifier(self) -> int: def matches_identifier(self, other:int) -> bool: # Use only the MSB and the lower nibble; per the USB specification. - masked_other = 0b10001111 + masked_other = other & 0b10001111 return self.get_identifier() == masked_other diff --git a/facedancer/future/interface.py b/facedancer/future/interface.py index 38bad641..a7a4c944 100644 --- a/facedancer/future/interface.py +++ b/facedancer/future/interface.py @@ -181,9 +181,8 @@ def handle_get_descriptor_request(self, request): """ Handle GET_DESCRIPTOR requests; per USB2 [9.4.3] """ logging.debug("Handling GET_DESCRIPTOR on endpoint.") - # This is the same as the USBDevice get descriptor request; - # delegate to its unbound method to avoid duplication. - device.USBDevice.handle_generic_get_descriptor_request(self, request) + # This is the same as the USBDevice get descriptor request => avoid duplication. + self.get_device().handle_generic_get_descriptor_request(self, request) # Table 9-12 of USB 2.0 spec (pdf page 296) diff --git a/facedancer/future/request.py b/facedancer/future/request.py index 2d51b154..c6ddcfec 100644 --- a/facedancer/future/request.py +++ b/facedancer/future/request.py @@ -170,7 +170,7 @@ def to_any_endpoint(func): def to_this_interface(func): """ Decorator; refines a handler so it's only called on requests targeting this interface. """ - return _wrap_with_field_matcher(func, 'recipient', USBRequestRecipient.INTERFACE) + return _wrap_with_field_matcher(func, 'recipient', USBRequestRecipient.INTERFACE, match_index=True) def to_any_interface(func): """ Decorator; refines a handler so it's only called on requests with an interface recipient. """