File
Blob: firmware/crates/esp32-radio/src/platform/ffi.rs
| 1 | //! Hand-written declarations for our small private C ABI, not vendor layouts. |
| 2 | //! Keep signatures in sync with platform/include/radio_bridge.h. |
| 3 | use std::ffi::{c_char, c_void}; |
| 4 | |
| 5 | /// Private C pointer/length pair, borrowed only by one synchronous HMAC call. |
| 6 | #[repr(C)] |
| 7 | #[derive(Clone, Copy)] |
| 8 | pub(super) struct CryptoPart { |
| 9 | pub bytes: *const u8, |
| 10 | pub length: usize, |
| 11 | } |
| 12 | |
| 13 | pub(super) const CRYPTO_HASH_STATE_BYTES: usize = 256; |
| 14 | |
| 15 | unsafe extern "C" { |
| 16 | pub(super) fn radio_crypto_key_info(der: *const u8, length: usize, bits: *mut i32) -> i32; |
| 17 | pub(super) fn radio_crypto_sign( |
| 18 | der: *const u8, |
| 19 | key_length: usize, |
| 20 | data: *const u8, |
| 21 | data_length: usize, |
| 22 | hash_bits: i32, |
| 23 | output: *mut u8, |
| 24 | capacity: usize, |
| 25 | used: *mut usize, |
| 26 | ) -> i32; |
| 27 | pub(super) fn radio_crypto_p256_keygen(secret: *mut u8, public: *mut u8) -> i32; |
| 28 | pub(super) fn radio_crypto_p256_shared( |
| 29 | secret: *const u8, |
| 30 | public: *const u8, |
| 31 | shared: *mut u8, |
| 32 | ) -> i32; |
| 33 | #[cfg(feature = "crypto-profile")] |
| 34 | pub(super) fn radio_crypto_profile_start() -> i32; |
| 35 | #[cfg(feature = "crypto-profile")] |
| 36 | pub(super) fn radio_crypto_profile_finish() -> i32; |
| 37 | pub(super) fn radio_crypto_aes_ctr( |
| 38 | key: *const u8, |
| 39 | key_length: usize, |
| 40 | iv: *const u8, |
| 41 | input: *const u8, |
| 42 | length: usize, |
| 43 | output: *mut u8, |
| 44 | capacity: usize, |
| 45 | ) -> i32; |
| 46 | pub(super) fn radio_crypto_aes_ecb( |
| 47 | key: *const u8, |
| 48 | key_length: usize, |
| 49 | input: *const u8, |
| 50 | output: *mut u8, |
| 51 | ) -> i32; |
| 52 | pub(super) fn radio_crypto_aes_gcm( |
| 53 | decrypt: i32, |
| 54 | key: *const u8, |
| 55 | key_length: usize, |
| 56 | iv: *const u8, |
| 57 | aad: *const u8, |
| 58 | aad_length: usize, |
| 59 | input: *const u8, |
| 60 | length: usize, |
| 61 | output: *mut u8, |
| 62 | capacity: usize, |
| 63 | ) -> i32; |
| 64 | pub(super) fn radio_crypto_sha256(input: *const u8, length: usize, output: *mut u8) -> i32; |
| 65 | pub(super) fn radio_crypto_hmac( |
| 66 | bits: i32, |
| 67 | key: *const u8, |
| 68 | key_length: usize, |
| 69 | parts: *const CryptoPart, |
| 70 | count: usize, |
| 71 | output: *mut u8, |
| 72 | capacity: usize, |
| 73 | ) -> i32; |
| 74 | pub(super) fn radio_crypto_hash_init(state: *mut u8, bits: i32) -> i32; |
| 75 | pub(super) fn radio_crypto_hash_update(state: *mut u8, input: *const u8, length: usize) -> i32; |
| 76 | pub(super) fn radio_crypto_hash_finish( |
| 77 | state: *const u8, |
| 78 | output: *mut u8, |
| 79 | capacity: usize, |
| 80 | ) -> i32; |
| 81 | pub(super) fn radio_crypto_verify_ec( |
| 82 | certificate: *const u8, |
| 83 | certificate_length: usize, |
| 84 | data: *const u8, |
| 85 | data_length: usize, |
| 86 | signature: *const u8, |
| 87 | signature_length: usize, |
| 88 | hash_bits: i32, |
| 89 | ) -> i32; |
| 90 | pub(super) fn radio_board_init() -> i32; |
| 91 | pub(super) fn radio_clock_sync() -> i32; |
| 92 | pub(super) fn radio_now_us() -> u64; |
| 93 | pub(super) fn radio_random() -> u32; |
| 94 | pub(super) fn radio_heap_free() -> u32; |
| 95 | pub(super) fn radio_stack_free() -> u32; |
| 96 | pub(super) fn radio_led(r: u8, g: u8, b: u8) -> i32; |
| 97 | pub(super) fn radio_console_byte() -> i32; |
| 98 | pub(super) fn radio_log(message: *const c_char); |
| 99 | pub(super) fn radio_recovery_attempt(reset: i32) -> u32; |
| 100 | pub(super) fn radio_restart() -> !; |
| 101 | pub(super) fn radio_music_size() -> usize; |
| 102 | pub(super) fn radio_music_read(offset: usize, out: *mut u8, length: usize) -> i32; |
| 103 | pub(super) fn radio_ipv4(octets: *mut u8) -> i32; |
| 104 | pub(super) fn radio_certificate_generate( |
| 105 | cert: *mut u8, |
| 106 | cert_capacity: usize, |
| 107 | cert_length: *mut usize, |
| 108 | key: *mut u8, |
| 109 | key_capacity: usize, |
| 110 | key_length: *mut usize, |
| 111 | ) -> i32; |
| 112 | pub(super) fn radio_http_open() -> *mut c_void; |
| 113 | pub(super) fn radio_http_post( |
| 114 | http: *mut c_void, |
| 115 | path: *const c_char, |
| 116 | body: *const u8, |
| 117 | length: usize, |
| 118 | response: *mut *const u8, |
| 119 | used: *mut usize, |
| 120 | ) -> i32; |
| 121 | pub(super) fn radio_http_free(http: *mut c_void); |
| 122 | pub(super) fn radio_metrics_open() -> *mut c_void; |
| 123 | pub(super) fn radio_metrics_sample( |
| 124 | metrics: *mut c_void, |
| 125 | clocks: *mut u64, |
| 126 | memory: *mut u32, |
| 127 | sensors: *mut i32, |
| 128 | detailed: i32, |
| 129 | ) -> i32; |
| 130 | pub(super) fn radio_metrics_free(metrics: *mut c_void); |
| 131 | pub(super) fn radio_current_core() -> i32; |
| 132 | pub(super) fn radio_dsp_open() -> *mut c_void; |
| 133 | pub(super) fn radio_dsp_free(dsp: *mut c_void); |
| 134 | pub(super) fn radio_dsp_reset(dsp: *mut c_void) -> i32; |
| 135 | pub(super) fn radio_dsp_decode(dsp: *mut c_void, opus: *const u8, length: usize) -> i32; |
| 136 | pub(super) fn radio_dsp_pcm(dsp: *mut c_void) -> *const i16; |
| 137 | pub(super) fn radio_dsp_fft_buffer(dsp: *mut c_void) -> *mut f32; |
| 138 | pub(super) fn radio_dsp_transform(dsp: *mut c_void) -> i32; |
| 139 | pub(super) fn radio_analysis_history_alloc() -> *mut f32; |
| 140 | pub(super) fn radio_analysis_history_free(history: *mut f32); |
| 141 | } |