CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
usb_msc_bounds.h
Go to the documentation of this file.
1// Pure bounds/alignment validation for a USB MSC block access.
2//
3// Kept dependency-free (stdint/stdbool only) so it is shared by the firmware
4// block layer and host unit tests.
5
6#pragma once
7
8#include <stdint.h>
9#include <stdbool.h>
10
26static inline bool usb_msc_range_ok(uint64_t total_bytes, uint16_t block_size,
27 uint32_t lba, uint32_t offset, uint32_t len,
28 bool is_write) {
29 if (block_size == 0) return false;
30 if (is_write && (offset != 0 || (len % block_size) != 0)) return false;
31 uint64_t addr = (uint64_t)lba * block_size + offset;
32 if (addr + len > total_bytes) return false;
33 return true;
34}
35
45static inline bool usb_msc_should_remount(bool prev, bool cur) {
46 return prev && !cur;
47}
static bool usb_msc_should_remount(bool prev, bool cur)
Whether a host-active transition should trigger a badge remount.
static bool usb_msc_range_ok(uint64_t total_bytes, uint16_t block_size, uint32_t lba, uint32_t offset, uint32_t len, bool is_write)
Validates an MSC block access against the volume geometry.