-
Notifications
You must be signed in to change notification settings - Fork 142
Proxy fixes and logging clarity improvements #162
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
Open
akvadrako
wants to merge
1
commit into
greatscottgadgets:main
Choose a base branch
from
akvadrako:proxy-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ class USBProxySetupFilters(USBProxyFilter): | |
|
|
||
| MAX_PACKET_SIZE_EP0 = 64 | ||
|
|
||
| configurations: dict[int, USBDescriptor] | ||
|
|
||
| def __init__(self, device, verbose=0): | ||
| self.device = device | ||
| self.configurations = {} | ||
|
|
@@ -48,18 +50,20 @@ def filter_control_in(self, req, data, stalled): | |
| if descriptor_type == self.DESCRIPTOR_CONFIGURATION and req.length >= 32: | ||
| configuration = USBDescribable.from_binary_descriptor(data) | ||
| self.configurations[configuration.number] = configuration | ||
| if self.verbose > 0: | ||
| if self.verbose > 2: | ||
| log.info("-- Storing configuration {} --".format(configuration)) | ||
|
|
||
|
|
||
| if descriptor_type == self.DESCRIPTOR_DEVICE and req.length >= 7: | ||
| # Patch our data to overwrite the maximum packet size on EP0. | ||
| # See USBProxy.connect for a rationale on this. | ||
| device = USBDescribable.from_binary_descriptor(data) | ||
| device.max_packet_size_ep0 = 64 | ||
| data = bytearray(device.get_descriptor())[:len(data)] | ||
| if self.verbose > 0: | ||
| log.info("-- Patched device descriptor. --") | ||
| old = device.max_packet_size_ep0 | ||
| if old != 64: | ||
| device.max_packet_size_ep0 = 64 | ||
| data = bytearray(device.get_descriptor())[:len(data)] | ||
| if self.verbose > 0: | ||
| log.info(f"-- Patched device descriptor. max_packet_size_ep0 {old} to 64 --") | ||
|
|
||
| return req, data, stalled | ||
|
|
||
|
|
@@ -69,13 +73,14 @@ def filter_control_out(self, req, data): | |
| # handle it ourself, and absorb it. | ||
| if req.get_recipient() == self.RECIPIENT_DEVICE and \ | ||
| req.request == self.SET_ADDRESS_REQUEST: | ||
| log.info(f"setup: out - handle set_address {req}") | ||
| req.acknowledge(blocking=True) | ||
| self.device.set_address(req.value) | ||
| return None, None | ||
|
|
||
| # Special case: if this is a SET_CONFIGURATION_REQUEST, | ||
| # pass it through, but also set up the Facedancer hardware | ||
| # in response. | ||
| # Special case: SET_CONFIGURATION_REQUEST | ||
| # libusb1 recommends always calling setConfiguration() instead | ||
| # of sending the control packet manually | ||
| if req.get_recipient() == self.RECIPIENT_DEVICE and \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. This should have been changed when we moved USB Proxy from |
||
| req.request == self.SET_CONFIGURATION_REQUEST: | ||
| configuration_index = req.value | ||
|
|
@@ -84,8 +89,10 @@ def filter_control_out(self, req, data): | |
| if configuration_index in self.configurations: | ||
| configuration = self.configurations[configuration_index] | ||
|
|
||
| if self.verbose > 0: | ||
| if self.verbose > 2: | ||
| log.info("-- Applying configuration {} --".format(configuration)) | ||
| elif self.verbose > 0: | ||
| log.info(f"-- Applying configuration {configuration.get_identifier()} --") | ||
|
|
||
| self.device.configured(configuration) | ||
|
|
||
|
|
@@ -94,13 +101,17 @@ def filter_control_out(self, req, data): | |
| else: | ||
| log.warning("-- WARNING: Applying configuration {}, but we've never read that configuration's descriptor! --".format(configuration_index)) | ||
|
|
||
| # Special case: if this is a SET_INTERFACE_REQUEST, | ||
| # pass it through, but also tell the device so it can update | ||
| # its current configuration. | ||
| return None, None | ||
|
|
||
| # Special case: SET_INTERFACE_REQUEST | ||
| # libusb1 recommends calling setInterfaceAlternative() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| if req.get_recipient() == self.RECIPIENT_INTERFACE and \ | ||
| req.request == self.SET_INTERFACE_REQUEST: | ||
| interface_number = req.index | ||
| alternate = req.value | ||
| log.info(f"setup: out - handle SET_INTERFACE_REQUEST {req}") | ||
| self.device.interface_changed(interface_number, alternate) | ||
|
|
||
| return None, None | ||
|
|
||
| return req, data | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type annotations! We love more type annotations in the codebase! Thank you!