Skip to content

Commit

Permalink
Merge branch 'mrh1997-getdescreq-fix' into antoinevg/facedancer-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed Jan 22, 2024
2 parents d6ef75e + f92d86b commit 8ec720d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
11 changes: 7 additions & 4 deletions facedancer/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
Expand Down Expand Up @@ -715,8 +716,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}")
Expand All @@ -726,7 +729,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.
Expand Down Expand Up @@ -813,7 +816,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)



Expand Down
2 changes: 1 addition & 1 deletion facedancer/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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


Expand Down
5 changes: 2 additions & 3 deletions facedancer/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,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)
Expand Down
2 changes: 1 addition & 1 deletion facedancer/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down

0 comments on commit 8ec720d

Please sign in to comment.