10 Commits

Author SHA1 Message Date
cecio
41360fc26b Update README.md 2023-04-22 22:38:48 +02:00
cecio
50178b2272 renamed STL files 2023-04-22 22:33:49 +02:00
cecio
41ba557583 Merge branch 'main' of https://github.com/cecio/USBvalve 2023-04-22 22:32:53 +02:00
cecio
b91effbbba new release 0.8.x 2023-04-22 22:32:08 +02:00
WM
ac51d0884a Updated STL files (#3)
* Create .gitkeep

* STL files

STL files for a box and a cover for the 128x32 screen

* Delete .gitkeep

* Updated STL files

Updated STL files for the lid with more grip
2023-04-13 22:35:04 +02:00
cecio
c02516a815 Merge branch 'main' of https://github.com/cecio/USBvalve 2023-04-13 13:17:04 +02:00
WM
181bf1ba0d Add STL files (#2)
* Create .gitkeep

* STL files

STL files for a box and a cover for the 128x32 screen

* Delete .gitkeep
2023-04-13 13:15:05 +02:00
cecio
121742fb6f bump to release 0.8.0 2023-04-04 00:13:04 +02:00
cecio
3d890ff1ac Gerber file renamed 2023-04-03 22:54:24 +02:00
cecio
4318641722 first version with HID detector working 2023-03-30 23:28:12 +02:00
13 changed files with 177 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -14,6 +14,13 @@ With **USBvalve** you can have an immediate feedback about what happen to the dr
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/readme.png" alt="Readme" width="15%" height="15%" />
</p>
and from version `0.8.0` you can also use it as USB Host to detect *BADUSB* devices:
<p float="left">
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/hid.png" alt="HID" width="15%" height="15%" />
</p>
## Repository Structure
`docs`: documentation about the project, with a presentation where you can have a look to all the features
@@ -41,24 +48,31 @@ If you want to build your own, you need:
### Building instructions
Almost all the job is done directly on the board by the software, so you just need to arrange the connection with the OLED for output
Almost all the job is done directly on the board by the software, so you just need to arrange the connection with the OLED for output.
Starting from version 0.8.0 of the firmware, **USBvalve** can detect HID devices (used to detect *BADUSB*). This require an additional USB port behaving as Host. If you are not interested in this, you can use the old instructions [in docs folder](https://github.com/cecio/USBvalve/blob/main/docs/BUILDING-1.1.md) and use PCB version `1.1`. Otherwise go ahead with PCB version `1.2` (we have version for USB-A or USB-B, see folder).
#### With USBvalve PCB
<p float="left">
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/USB_valve_front.png" width="25%" height="25%" />
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/USB_valve_back.png" width="25%" height="25%" />
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/USB_valve_1-2_front.png" width="25%" height="25%" />
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/USB_valve_1-2_back.png" width="24%" height="24%" />
</p>
- place the Raspberry Pi Pico on the silk screen on the front
- you don't need to solder all the PINs. Just the following:
- D4 and D5 (left side)
- GND (right side)
- D14 and D15 (left side)
- GND (right side, third pin from the top)
- GND (right side, third pin from the bottom)
- 3v3_OUT (right side)
- VBUS (right side)
- the 3 DEBUG pin on the bottom: SWCLK, GND and SWDIO
- place the 3D printer spacer or a piece of tape on the parts of the OLED that my touch the Raspberry
- solder the OLED (with a header) on the 4 PIN space
- solder a USB female port in `USBH` area. This is for version `A`, but there is a version for USB `Micro-B` as well if you prefer
Some of the OLEDs have the GND and VCC PINs swapped, so I built the PCB to be compatible with both versions:
@@ -78,14 +92,18 @@ Otherwise you should the opposite and place the solder on the other PADs:
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/pico-pinout.svg" alt="Pico Pi" width="85%" height="85%" />
If you are using a breadboard or just wiring, all you have to do is to ensure to connect the proper PINs at the OLED screen.
If you are using a breadboard or just wiring, all you have to do is to ensure to connect the proper PINs at the OLED screen and to the Host USB port.
The mapping is the following:
- PIN6 of Pi --> OLED SDA
- PIN7 of Pi --> OLED SCL
- PIN19 of Pi --> D+ of USB Host
- PIN20 of Pi --> D- of USB Host
- PIN23 (GND) of Pi --> GND of USB Host
- PIN38 (GND) of Pi --> OLED GND
- PIN36 (3V3OUT) of Pi --> OLED VCC
- PIN40 (VBUS) of Pi --> VCC of USB Host
If you want to use the DEBUG functions, you can also place a header on the 3 SWD PINs at the bottom of the board.
@@ -105,10 +123,10 @@ It's done!
Obviously you can also build your own firmware. To build the *standard* one I used:
- Arduino IDE 2.0.4
- Arduino IDE 2.1.0
- ~~as board I used `Raspberry Pi Pico - Arduino MBED OS RP2040` version `4.0.2`~~
- ~~`Adafruit TinyUSB Library` version `1.14.4`. Newer versions are not working because the RPI SDK of the board is stick to an older version. May be migrate the entire project directly on Raspberry Pi Pico SDK is the solution here.~~
- from version `0.7.0` I used `Adafruit TinyUSB Library` version `2.0.1` and Board `Raspberry Pi RP2040 (2.7.0)`
- from version `0.7.0` I used `Adafruit TinyUSB Library` version `2.1.0` and Board `Raspberry Pi RP2040 (2.7.0)`
- `ssd1306` OLED library version `1.8.3`
If you want to re-create a new fake filesystem, you may want to have a look to the `utils` folder, where I placed some utilities to build a new one.

BIN
STL/Box_USBvalve_1.1.stl Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -16,9 +16,29 @@
any redistribution
*********************************************************************/
#include <pio_usb.h>
#include "Adafruit_TinyUSB.h"
#include "SSD1306AsciiWire.h"
//
// BADUSB detector section
//
/*
* Requirements:
* - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
* - 2 consecutive GPIOs: D+ is defined by HOST_PIN_DP (gpio2), D- = D+ +1 (gpio3)
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
*/
#define HOST_PIN_DP 14 // Pin used as D+ for host, D- = D+ + 1
#define LANGUAGE_ID 0x0409 // English
// USB Host object
Adafruit_USBH_Host USBHost;
// END of BADUSB detector section
// Define vars for OLED screen
#define I2C_ADDRESS 0x3C // 0X3C+SA0 - 0x3C or 0x3D
#define RST_PIN -1 // Define proper RST_PIN if required.
@@ -54,7 +74,7 @@ bool activeState = false;
//
// USBvalve globals
//
#define VERSION "USBvalve - 0.7.0"
#define VERSION "USBvalve - 0.8.1"
boolean readme = false;
boolean autorun = false;
boolean written = false;
@@ -65,7 +85,7 @@ int x = 2;
#define BLOCK_README 100 // Block where README.txt file is saved
#define MAX_DUMP_BYTES 16 // Used by the dump of the debug facility: do not increase this too much
#define BYTES_TO_HASH 512 * 2 // Number of bytes of the RAM disk used to check consistency
#define BYTES_TO_HASH_OFFSET 7 // Starting sector to check for consistency (FAT_DIRECTORY is 7)
#define BYTES_TO_HASH_OFFSET 7 // Starting sector to check for consistency (FAT_DIRECTORY is 7)
// Burned hash to check consistency
u8 valid_hash[WIDTH] = {
@@ -79,7 +99,7 @@ u8 valid_hash[WIDTH] = {
u8 computed_hash[WIDTH] = { 0x00 };
// Core 0 Setup
// Core 0 Setup: will be used for the USB mass device functions
void setup() {
// Check consistency of RAM FS
quark(computed_hash, msc_disk[BYTES_TO_HASH_OFFSET], BYTES_TO_HASH);
@@ -141,7 +161,21 @@ void setup() {
}
}
// Main Core0 loop, managing display
// Core 1 Setup: will be used for the USB host functions for BADUSB detector
void setup1() {
//while ( !Serial ) delay(10); // wait for native usb
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
pio_cfg.pin_dp = HOST_PIN_DP;
USBHost.configure_pio_usb(1, &pio_cfg);
// run host stack on controller (rhport) 1
// Note: For rp2040 pico-pio-usb, calling USBHost.begin() on core1 will have most of the
// host bit-banging processing works done in core1
USBHost.begin(1);
}
// Main Core0 loop: managing display
void loop() {
if (readme == true) {
@@ -167,6 +201,11 @@ void loop() {
}
}
// Main Core1 loop: managing USB Host
void loop1() {
USBHost.task();
}
// Callback invoked when received READ10 command.
// Copy disk's data to buffer (up to bufsize) and
// return number of copied bytes (must be multiple of block size).
@@ -289,4 +328,54 @@ void hexDump(unsigned char* data, size_t size) {
}
}
SerialTinyUSB.println();
}
}
//
// BADUSB detector section
//
// Invoked when device with hid interface is mounted
// Report descriptor is also available for use.
// tuh_hid_parse_report_descriptor() can be used to parse common/simple enough
// descriptor. Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE,
// it will be skipped therefore report_desc = NULL, desc_len = 0
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
(void)desc_report;
(void)desc_len;
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
if (x == OLED_LINES) cls();
oled.println("[++] HID Device");
x++;
SerialTinyUSB.printf("HID device address = %d, instance = %d mounted\r\n", dev_addr, instance);
SerialTinyUSB.printf("VID = %04x, PID = %04x\r\n", vid, pid);
if (!tuh_hid_receive_report(dev_addr, instance)) {
SerialTinyUSB.printf("Error: cannot request to receive report\r\n");
}
}
// Invoked when device with hid interface is un-mounted
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
SerialTinyUSB.printf("HID device address = %d, instance = %d unmounted\r\n", dev_addr, instance);
}
// Invoked when received report from device via interrupt endpoint
void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {
if (x == OLED_LINES) cls();
oled.println("[!!] HID Sending data");
x++;
SerialTinyUSB.printf("HIDreport : ");
for (uint16_t i = 0; i < len; i++) {
SerialTinyUSB.printf("0x%02X ", report[i]);
}
SerialTinyUSB.println();
// continue to request to receive report
if (!tuh_hid_receive_report(dev_addr, instance)) {
SerialTinyUSB.printf("Error: cannot request to receive report\r\n");
}
}
// END of BADUSB detector section

58
docs/BUILDING-1.1.md Normal file
View File

@@ -0,0 +1,58 @@
#### With USBvalve PCB
<p float="left">
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/USB_valve_front.png" width="25%" height="25%" />
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/USB_valve_back.png" width="25%" height="25%" />
</p>
- place the Raspberry Pi Pico on the silk screen on the front
- you don't need to solder all the PINs. Just the following:
- D4 and D5 (left side)
- GND (right side)
- 3v3_OUT (right side)
- the 3 DEBUG pin on the bottom: SWCLK, GND and SWDIO
- place the 3D printer spacer or a piece of tape on the parts of the OLED that my touch the Raspberry
- solder the OLED (with a header) on the 4 PIN space
Some of the OLEDs have the GND and VCC PINs swapped, so I built the PCB to be compatible with both versions:
For example if your OLED has GND on PIN1 and VCC on PIN2 like this:
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/usb_valve_oled.png" width="35%" height="35%" />
You have to place a blob of solder on these two pads on the back of the PCB:
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/usb_valve_pads.png" width="15%" height="15%" />
Otherwise you should the opposite and place the solder on the other PADs:
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/usb_valve_pads_2.png" width="15%" height="15%" />
#### Without USBvalve PCB
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/pico-pinout.svg" alt="Pico Pi" width="85%" height="85%" />
If you are using a breadboard or just wiring, all you have to do is to ensure to connect the proper PINs at the OLED screen.
The mapping is the following:
- PIN6 of Pi --> OLED SDA
- PIN7 of Pi --> OLED SCL
- PIN38 (GND) of Pi --> OLED GND
- PIN36 (3V3OUT) of Pi --> OLED VCC
If you want to use the DEBUG functions, you can also place a header on the 3 SWD PINs at the bottom of the board.
### Flash Firmware
To flash the firmware, follow these steps:
- Connect the Raspberry Pi Pico with the USB cable, by keeping the *BOOTSEL* button pressed (the big white button on the board)
- release the button
- you will see a new drive on the system, named `RPI-RP2` (in Linux envs you may have to manually mount it)
- copy the proper firmware file (with extension `uf2`) in the folder, depending on the OLED you used
- wait few seconds until the mounted folder disappear
It's done!

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
pictures/hid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB