Commit graph

249 commits

Author SHA1 Message Date
bunnie
2aebf6819a clear out collapsed view in prep to clone hw struct 2022-08-10 14:59:09 +08:00
bunnie
69a7c101a8 split hosted/hw into separate main files
cleans out a bunch of #[cfg] directives that were getting
ridiculous

this version runs clean but needs a lot of work for the next
stage.
2022-08-10 14:54:50 +08:00
bunnie
af1013a1f3 rework SoC semver reporting to use xous-semver 2022-07-11 15:39:42 +08:00
bunnie
2bea23687e fix hosted mode emulation stubs 2022-06-28 03:36:40 +08:00
bunnie
f571e3069a fix regressions on USB suspend/resume
the core now enumerates after a suspend/resume cycle, although
sometimes it takes two tries for the enumeration to go all the way
through. not sure why, yet.
2022-06-28 03:25:33 +08:00
bunnie
a7ce3e6204 make keyboard tick() blocks non-fatal
at the moment if for some reason the USB stack can't send a tick
there's a panic. it's not actually a life-ending event if that happens.
2022-06-27 02:18:55 +08:00
bunnie
0e5fb14894 add a compatibility gate on USB HID interface
If the SoC isn't compatible, don't try starting the U2F server.
2022-06-27 02:00:22 +08:00
bunnie
c1c0729f39 add some indicator if keyboard LEDs were set by host 2022-06-24 18:58:27 +08:00
bunnie
e6e44d3dfb add an ensure usb connection
ensure connection will not reset the core if it's already connected,
unlike the switch version which always resets the core even if it is
connected.
2022-06-23 02:26:12 +08:00
bunnie
ed51bbc23e update USB PID, resolving issue #182 2022-06-15 01:56:27 +08:00
bunnie
0cdd9d9920 fix regression in usb-device 2022-06-14 17:09:09 +08:00
bunnie
fc8e5df2b1 Merge remote-tracking branch 'origin/dither2' into dp2-merge 2022-06-14 16:45:38 +08:00
bunnie
cce617366f move to the release version of usbd-human-interface-device
thanks @dlkj!
2022-06-13 00:20:14 +08:00
bunnie
9ab3f71f23 modify naming of FidoInterface to RawFidoInterface
per maintainer request of usbd-human-interface-device for PR
2022-06-12 23:05:20 +08:00
bunnie
5497b1d264 add a delay to de-chatter switching between cores 2022-06-11 22:46:37 +08:00
bunnie
e32ea4d3f5 fix #174 2022-06-10 21:36:53 +08:00
bunnie
cae1c3267e add sentinels for test automation 2022-06-10 21:16:59 +08:00
bunnie
fd9fb1cbcc fix hosted mode 2022-06-09 00:28:48 +08:00
bunnie
a4d0cdba80 pass unplug events down to the FIDO stack
this is necessary because unplugs actually force some
cryptographic state to rekey
2022-06-08 23:47:44 +08:00
bunnie
6c94e61ab6 make hosted mode "happy" when running with HID calls 2022-06-06 19:00:19 +08:00
bunnie
ffd8e3607d add a check that the write() has completed before initiating a new one 2022-06-06 03:46:30 +08:00
bunnie
f4f6106b48 fix CI issues in github actions due to namespace collision of feature & package 2022-06-04 14:20:45 +08:00
bunnie
272abfd157 cleanup pass on spew and warnings 2022-06-04 00:56:47 +08:00
bunnie
6397aafb21 quiet down debug spew 2022-06-04 00:35:28 +08:00
bunnie
3ad70c711d add mjolnir; fix EP allocation bug
Spent the last couple days tracing down a dastardly bug, which was
slew only upon the creation of mjolnir.

The SpinalHDL USB core is unique in that it has a hardware
implementation of a linked list for its descriptors. This can
be very high performance because you can receive packets much
faster than software can keep up with it in short bursts --
assuming the stack can deal with it.

Unfortunately the poor Rust stack that we adopted from
the STM32 land only assumes single descriptors. Alas, we cannot
unlock the full power of linked list descriptors, and instead
we use "single entry lists" with static allocations, to match
the paradigm of the STM32.

Anyways. Early on, when creating the linked list allocator,
I contemplated doing it the Rusty way, and the C way. The Rusty
way would create a structure that mapped the descriptor headers
plus the variable-sized data chunk into some magical structure
that got us bounds checking and had proper accessors etc.
The C way would just be raw pointer manipulation using unsafes.

Unfortunately, my Rust-fu was no match for the linked list.
The problem is that the descriptors could be of any data size,
and they had to be mapped to a very specific piece of memory.
So I had to create a `repr (C)` struct that matched Rust's
alignment requirements and also somehow could deal with
a variable length array *but could not be a slice* because
the hardware implementation does not have the flexibility
to accommodate a fat pointer. I couldn't figure out how
to get const generics to work, and the size of the array
could be anything from 0 bytes to a couple kilobytes. So,
I ditched the safety of Rust and went with a C-style unsafe
pointer implementation.

Sure enough, it came to haunt me. When I wrote the allocator,
I forgot to allocate space for the descriptor headers. This
worked fine for the keyboard, because the keyboard asks for
32-byte descriptors but only ever does a 25-byte report. That's
just enough to fit the descriptor headers, ironically.

When implementing FIDO/U2F, it asks for 64-byte descriptors
and uses exactly 64-byte messages for everything. This caused
a bug where I could receive one incoming packet, but when
responding with an outgoing packet we'd overwrite the descriptors
of the receiving packet, zeroing it out, causing the the descriptor
to fail in the hardware state machine. Of course I never saw
this because I would print the descriptors of the individual
endpoints upon creating them, but the pointer-overflow problem
only occurs later.

Thus mjolnir was created, it is basically a tool that gives me
a raw hex dump of the endpoint and descriptor banks, which I
can then analyze and diff. It's very powerful, but also very
unweildy -- if invoked indiscriminantly, the overhead of
all the prints would cause other failures due to timing problems.
Thus mjolnir exists as a feature that introduces special
locks around the USB endpoints so that they NAK while mjolnir
does its analysis, disallowing concurrent mutation of the
memory state.

Upon deploying mjolnir, the problem became obvious, and it is
now fixed.

Thus, while on the one hand, it's a great story of how maybe
we should avoid unsafe Rust, it's also a story of how hardware
structures like a hardware linked list may be fundamentally
incompatible with Rust. I think if the hardware USB descriptor
linked list was modified to allow for a fat pointer to track
a data slice, the implementation would almost be trivial. But,
rewriting HDL to fit Rust also has its hazards, as the exact
layout of a fat pointer in RAM is not guaranteed and it would
probably foolhardy to commit to something not guaranteed in
hardware.
2022-06-03 23:53:37 +08:00
bunnie
4dca789d22 make keyboard composite device optional
just to make debugging a bit easier
2022-06-03 18:17:39 +08:00
bunnie
6ff5924cea fix issue with in_progress being set on init for writes
also try to wait for transactions in progress on write before
re-initiating
2022-06-03 16:49:36 +08:00
bunnie
8914dad705 remove redundant nack overhead, and the mystery delay
looks like after solving the redundant interrupt problem,
the mystery delay is no longer needed.
2022-06-03 03:11:35 +08:00
bunnie
f7a01693fe fix interrupts for USB; fix issue #170
this fixes two things:

1. writes no longer generate a spurious interrupt on completion
that also triggers a "non-read".

2. writes are not automatically set to send on allocation. this
solves issue #170. they are only set to send after a write.
2022-06-03 02:26:08 +08:00
bunnie
48f3b36875 stuck at getting FIDO stack to respond to second OUT packet. 2022-06-03 01:08:25 +08:00
bunnie
52e6071265 update FidoMsg api and fix opcode bug 2022-06-02 00:58:13 +08:00
bunnie
59550978f4 fix warnings that have cropped up for transition to 2021 edition 2022-06-01 11:54:24 +10:00
Sean Cross
d342d7a885 apps/services: remove xous::xous_main macro usage
This macro will be removed, since it is no longer necessary. Remove this
macro across the project and replace it with a standard `main()`
function.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-06-01 11:54:24 +10:00
bunnie
7e0831c756 initialize the keyboard interface with a clean report on boot 2022-06-01 11:54:24 +10:00
bunnie
b20514e87d cleanup hosted mode warnings 2022-05-31 14:48:09 +08:00
bunnie
376d7a713b Merge branch 'main' into u2f 2022-05-31 14:39:08 +08:00
bunnie
98289b1405 fix warnings that have cropped up for transition to 2021 edition 2022-05-31 14:38:41 +08:00
Sean Cross
3ae9d8abf0 apps/services: remove xous::xous_main macro usage
This macro will be removed, since it is no longer necessary. Remove this
macro across the project and replace it with a standard `main()`
function.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-31 13:33:30 +08:00
bunnie
647a3a26dd port to composite format 2022-05-30 18:52:03 +08:00
bunnie
372c2cb680 Merge branch 'main' into u2f 2022-05-30 17:41:27 +08:00
bunnie
c046e0bb16 initialize the keyboard interface with a clean report on boot 2022-05-30 17:39:09 +08:00
bunnie
05f705a931 prove that we've restored ditherpunk functionality to hosted mode
this basically brings us back to the point of the original PR,
but with the code being optional.
2022-05-27 18:05:36 +08:00
bunnie
634f3b0e93 fix composite device description - we now have HID & U2F simultaneously! 2022-05-27 00:34:06 +08:00
bunnie
a8f761722a start to lay in u2f messaging infrastructure 2022-05-26 17:58:22 +08:00
bunnie
3b6bc6aeeb suppress hosted mode warnings in usb dev crate 2022-05-24 17:08:27 +08:00
bunnie
3bfdc238a0 add support for keymaps in HID
remaps keys based on the assumed keymap based on the user's
preference for the keyboard layout on the device.

So far, only dvorak and QWERTY are supported.
2022-05-17 16:41:08 +08:00
bunnie
b69fbfdd01 adjust keyboard emulation delays for better compatibility 2022-05-17 03:08:08 +08:00
bunnie
ec53be0ac7 add USB device checkup functions and fix hosted mode 2022-05-17 02:26:28 +08:00
bunnie
346caad315 Add the usb-device-xous driver to the default hardware config
Also includes the USB test commands in shellchat.

This is different from the usb-test crate, in that it's fully
integrated into Xous. usb-test is just for quick-testing the USB
driver, in the absence of most of the rest of Xous.
2022-05-17 00:46:52 +08:00