Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint/Interface specific Requests were not handled by correct handler function #44

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions facedancer/future/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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.
Expand Down Expand Up @@ -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)



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


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