Skip to content

Commit

Permalink
Fixes for Microsoft OS 1.0 descriptor request handler.
Browse files Browse the repository at this point in the history
- Handler must only claim requests with its specified request code.
- Recipient must be device for index 4, and interface for index 5.
- Don't generate stalls - that's handled by not claiming requests.
  • Loading branch information
martinling committed May 18, 2024
1 parent 1c2eece commit ba8634f
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions luna/gateware/usb/request/windows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def elaborate(self, platform):
#
with m.If(
(setup.type == USBRequestType.VENDOR) &
(setup.recipient == USBRequestRecipient.DEVICE) &
((setup.index == 4) | (setup.index == 5))
(setup.request == self._request_code) & (
((setup.recipient == USBRequestRecipient.DEVICE) & (setup.index == 4)) |
((setup.recipient == USBRequestRecipient.INTERFACE) & (setup.index == 5)))
):
m.d.comb += interface.claim.eq(1)

Expand All @@ -75,13 +76,7 @@ def elaborate(self, platform):

# If we've received a new setup packet, handle it.
with m.If(setup.received):

with m.Switch(setup.request):

with m.Case(self._request_code):
m.next = 'GET_MS_DESCRIPTOR'
with m.Default():
m.next = 'UNHANDLED'
m.next = 'GET_MS_DESCRIPTOR'


# GET_MS_DESCRIPTOR -- The host is trying to request a OS Feature descriptor set
Expand Down Expand Up @@ -125,14 +120,4 @@ def elaborate(self, platform):
m.d.usb += expecting_ack.eq(0)
m.next = 'IDLE'


# UNHANDLED -- we've received a request we're not prepared to handle
with m.State('UNHANDLED'):

# When we next have an opportunity to stall, do so,
# and then return to idle.
with m.If(interface.data_requested | interface.status_requested):
m.d.comb += handshake_generator.stall.eq(1)
m.next = 'IDLE'

return m

0 comments on commit ba8634f

Please sign in to comment.