From d983ae1e8407fc6a9a1bf4a2b4baf193f2593aca Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 1 Jun 2024 17:35:00 +0200 Subject: [PATCH] let's try to wrap this up --- clib/bindings.rs | 2423 +++++++++++++++++---------------- clib/cfg/csp/autoconfig.h | 2 +- clib/wrapper.h | 4 +- examples/autoconfig.h | 2 +- examples/autoconfig.rs | 2 +- examples/src/main.rs | 6 +- libcsp-cargo-build/src/lib.rs | 47 +- libcsp-sys/src/lib.rs | 794 +++++++++-- libcsp/README.md | 18 +- libcsp/src/lib.rs | 159 ++- 10 files changed, 2084 insertions(+), 1373 deletions(-) diff --git a/clib/bindings.rs b/clib/bindings.rs index 264b4d6..7d0ff16 100644 --- a/clib/bindings.rs +++ b/clib/bindings.rs @@ -388,11 +388,16 @@ pub const _STRINGS_H: u32 = 1; pub const CSP_MAX_TIMEOUT: u32 = 4294967295; pub const CSP_MAX_DELAY: u32 = 4294967295; pub const CSP_INFINITY: u32 = 4294967295; -pub const CSP_IF_LOOPBACK_NAME: &[u8; 5] = b"LOOP\0"; -pub const _PTHREAD_H: u32 = 1; -pub const _SCHED_H: u32 = 1; +pub const CSP_SEMAPHORE_OK: u32 = 0; +pub const CSP_SEMAPHORE_ERROR: i32 = -1; +pub const _SEMAPHORE_H: u32 = 1; +pub const _SYS_TYPES_H: u32 = 1; +pub const __clock_t_defined: u32 = 1; +pub const __clockid_t_defined: u32 = 1; pub const __time_t_defined: u32 = 1; -pub const _STRUCT_TIMESPEC: u32 = 1; +pub const __timer_t_defined: u32 = 1; +pub const __BIT_TYPES_DEFINED__: u32 = 1; +pub const _ENDIAN_H: u32 = 1; pub const _BITS_ENDIAN_H: u32 = 1; pub const __LITTLE_ENDIAN: u32 = 1234; pub const __BIG_ENDIAN: u32 = 4321; @@ -400,6 +405,40 @@ pub const __PDP_ENDIAN: u32 = 3412; pub const _BITS_ENDIANNESS_H: u32 = 1; pub const __BYTE_ORDER: u32 = 1234; pub const __FLOAT_WORD_ORDER: u32 = 1234; +pub const LITTLE_ENDIAN: u32 = 1234; +pub const BIG_ENDIAN: u32 = 4321; +pub const PDP_ENDIAN: u32 = 3412; +pub const BYTE_ORDER: u32 = 1234; +pub const _BITS_BYTESWAP_H: u32 = 1; +pub const _BITS_UINTN_IDENTITY_H: u32 = 1; +pub const _SYS_SELECT_H: u32 = 1; +pub const __sigset_t_defined: u32 = 1; +pub const __timeval_defined: u32 = 1; +pub const _STRUCT_TIMESPEC: u32 = 1; +pub const FD_SETSIZE: u32 = 1024; +pub const _BITS_PTHREADTYPES_COMMON_H: u32 = 1; +pub const _THREAD_SHARED_TYPES_H: u32 = 1; +pub const _BITS_PTHREADTYPES_ARCH_H: u32 = 1; +pub const __SIZEOF_PTHREAD_MUTEX_T: u32 = 40; +pub const __SIZEOF_PTHREAD_ATTR_T: u32 = 56; +pub const __SIZEOF_PTHREAD_RWLOCK_T: u32 = 56; +pub const __SIZEOF_PTHREAD_BARRIER_T: u32 = 32; +pub const __SIZEOF_PTHREAD_MUTEXATTR_T: u32 = 4; +pub const __SIZEOF_PTHREAD_COND_T: u32 = 48; +pub const __SIZEOF_PTHREAD_CONDATTR_T: u32 = 4; +pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: u32 = 8; +pub const __SIZEOF_PTHREAD_BARRIERATTR_T: u32 = 4; +pub const _THREAD_MUTEX_INTERNAL_H: u32 = 1; +pub const __PTHREAD_MUTEX_HAVE_PREV: u32 = 1; +pub const __have_pthread_attr_t: u32 = 1; +pub const __SIZEOF_SEM_T: u32 = 32; +pub const CSP_RDP_CLOSED_BY_USERSPACE: u32 = 1; +pub const CSP_RDP_CLOSED_BY_PROTOCOL: u32 = 2; +pub const CSP_RDP_CLOSED_BY_TIMEOUT: u32 = 4; +pub const CSP_RDP_CLOSED_BY_ALL: u32 = 7; +pub const CSP_IF_LOOPBACK_NAME: &[u8; 5] = b"LOOP\0"; +pub const _PTHREAD_H: u32 = 1; +pub const _SCHED_H: u32 = 1; pub const _BITS_SCHED_H: u32 = 1; pub const SCHED_OTHER: u32 = 0; pub const SCHED_FIFO: u32 = 1; @@ -421,27 +460,9 @@ pub const CLOCK_REALTIME_ALARM: u32 = 8; pub const CLOCK_BOOTTIME_ALARM: u32 = 9; pub const CLOCK_TAI: u32 = 11; pub const TIMER_ABSTIME: u32 = 1; -pub const __clock_t_defined: u32 = 1; pub const __struct_tm_defined: u32 = 1; -pub const __clockid_t_defined: u32 = 1; -pub const __timer_t_defined: u32 = 1; pub const __itimerspec_defined: u32 = 1; pub const TIME_UTC: u32 = 1; -pub const _BITS_PTHREADTYPES_COMMON_H: u32 = 1; -pub const _THREAD_SHARED_TYPES_H: u32 = 1; -pub const _BITS_PTHREADTYPES_ARCH_H: u32 = 1; -pub const __SIZEOF_PTHREAD_MUTEX_T: u32 = 40; -pub const __SIZEOF_PTHREAD_ATTR_T: u32 = 56; -pub const __SIZEOF_PTHREAD_RWLOCK_T: u32 = 56; -pub const __SIZEOF_PTHREAD_BARRIER_T: u32 = 32; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: u32 = 4; -pub const __SIZEOF_PTHREAD_COND_T: u32 = 48; -pub const __SIZEOF_PTHREAD_CONDATTR_T: u32 = 4; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: u32 = 8; -pub const __SIZEOF_PTHREAD_BARRIERATTR_T: u32 = 4; -pub const _THREAD_MUTEX_INTERNAL_H: u32 = 1; -pub const __PTHREAD_MUTEX_HAVE_PREV: u32 = 1; -pub const __have_pthread_attr_t: u32 = 1; pub const _BITS_SETJMP_H: u32 = 1; pub const __jmp_buf_tag_defined: u32 = 1; pub const PTHREAD_STACK_MIN: u32 = 16384; @@ -450,19 +471,6 @@ pub const PTHREAD_BARRIER_SERIAL_THREAD: i32 = -1; pub const _NETINET_IN_H: u32 = 1; pub const _SYS_SOCKET_H: u32 = 1; pub const __iovec_defined: u32 = 1; -pub const _SYS_TYPES_H: u32 = 1; -pub const __BIT_TYPES_DEFINED__: u32 = 1; -pub const _ENDIAN_H: u32 = 1; -pub const LITTLE_ENDIAN: u32 = 1234; -pub const BIG_ENDIAN: u32 = 4321; -pub const PDP_ENDIAN: u32 = 3412; -pub const BYTE_ORDER: u32 = 1234; -pub const _BITS_BYTESWAP_H: u32 = 1; -pub const _BITS_UINTN_IDENTITY_H: u32 = 1; -pub const _SYS_SELECT_H: u32 = 1; -pub const __sigset_t_defined: u32 = 1; -pub const __timeval_defined: u32 = 1; -pub const FD_SETSIZE: u32 = 1024; pub const PF_UNSPEC: u32 = 0; pub const PF_LOCAL: u32 = 1; pub const PF_UNIX: u32 = 1; @@ -827,14 +835,6 @@ pub const IN_CLASSC_HOST: u32 = 255; pub const IN_LOOPBACKNET: u32 = 127; pub const INET_ADDRSTRLEN: u32 = 16; pub const INET6_ADDRSTRLEN: u32 = 46; -pub const CSP_SEMAPHORE_OK: u32 = 0; -pub const CSP_SEMAPHORE_ERROR: i32 = -1; -pub const _SEMAPHORE_H: u32 = 1; -pub const __SIZEOF_SEM_T: u32 = 32; -pub const CSP_RDP_CLOSED_BY_USERSPACE: u32 = 1; -pub const CSP_RDP_CLOSED_BY_PROTOCOL: u32 = 2; -pub const CSP_RDP_CLOSED_BY_TIMEOUT: u32 = 4; -pub const CSP_RDP_CLOSED_BY_ALL: u32 = 7; pub type __u_char = ::core::ffi::c_uchar; pub type __u_short = ::core::ffi::c_ushort; pub type __u_int = ::core::ffi::c_uint; @@ -2880,10 +2880,246 @@ extern "C" { ) -> ::core::ffi::c_int; } extern "C" { - #[doc = " Loopback interface."] - pub static mut csp_if_lo: csp_iface_t; + pub fn csp_output_hook( + idout: *mut csp_id_t, + packet: *mut csp_packet_t, + iface: *mut csp_iface_t, + via: u16, + from_me: ::core::ffi::c_int, + ); } +extern "C" { + pub fn csp_input_hook(iface: *mut csp_iface_t, packet: *mut csp_packet_t); +} +extern "C" { + pub fn csp_reboot_hook(); +} +extern "C" { + pub fn csp_shutdown_hook(); +} +extern "C" { + pub fn csp_memfree_hook() -> u32; +} +extern "C" { + pub fn csp_ps_hook(packet: *mut csp_packet_t) -> ::core::ffi::c_uint; +} +extern "C" { + #[doc = " Implement these, if you use csp_if_tun"] + pub fn csp_crypto_decrypt( + ciphertext_in: *mut u8, + ciphertext_len: u8, + msg_out: *mut u8, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_crypto_encrypt( + msg_begin: *mut u8, + msg_len: u8, + ciphertext_out: *mut u8, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_clock_get_time(time: *mut csp_timestamp_t); +} +extern "C" { + pub fn csp_clock_set_time(time: *const csp_timestamp_t) -> ::core::ffi::c_int; +} +pub const memory_order_memory_order_relaxed: memory_order = 0; +pub const memory_order_memory_order_consume: memory_order = 1; +pub const memory_order_memory_order_acquire: memory_order = 2; +pub const memory_order_memory_order_release: memory_order = 3; +pub const memory_order_memory_order_acq_rel: memory_order = 4; +pub const memory_order_memory_order_seq_cst: memory_order = 5; +pub type memory_order = ::core::ffi::c_uint; +extern "C" { + pub fn atomic_thread_fence(arg1: memory_order); +} +extern "C" { + pub fn atomic_signal_fence(arg1: memory_order); +} +pub type atomic_bool = u8; +pub type atomic_char = u8; +pub type atomic_schar = u8; +pub type atomic_uchar = u8; +pub type atomic_short = u16; +pub type atomic_ushort = u16; +pub type atomic_int = u32; +pub type atomic_uint = u32; +pub type atomic_long = u64; +pub type atomic_ulong = u64; +pub type atomic_llong = u64; +pub type atomic_ullong = u64; +pub type atomic_char16_t = u16; +pub type atomic_char32_t = u32; +pub type atomic_wchar_t = u32; +pub type atomic_int_least8_t = u8; +pub type atomic_uint_least8_t = u8; +pub type atomic_int_least16_t = u16; +pub type atomic_uint_least16_t = u16; +pub type atomic_int_least32_t = u32; +pub type atomic_uint_least32_t = u32; +pub type atomic_int_least64_t = u64; +pub type atomic_uint_least64_t = u64; +pub type atomic_int_fast8_t = u8; +pub type atomic_uint_fast8_t = u8; +pub type atomic_int_fast16_t = u64; +pub type atomic_uint_fast16_t = u64; +pub type atomic_int_fast32_t = u64; +pub type atomic_uint_fast32_t = u64; +pub type atomic_int_fast64_t = u64; +pub type atomic_uint_fast64_t = u64; +pub type atomic_intptr_t = u64; +pub type atomic_uintptr_t = u64; +pub type atomic_size_t = u64; +pub type atomic_ptrdiff_t = u64; +pub type atomic_intmax_t = u64; +pub type atomic_uintmax_t = u64; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct atomic_flag { + pub _Value: atomic_bool, +} +#[test] +fn bindgen_test_layout_atomic_flag() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(atomic_flag)) + ); + assert_eq!( + ::core::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(atomic_flag)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr)._Value) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(atomic_flag), + "::", + stringify!(_Value) + ) + ); +} +extern "C" { + pub fn atomic_flag_test_and_set(arg1: *mut atomic_flag) -> bool; +} +extern "C" { + pub fn atomic_flag_test_and_set_explicit(arg1: *mut atomic_flag, arg2: memory_order) -> bool; +} +extern "C" { + pub fn atomic_flag_clear(arg1: *mut atomic_flag); +} +extern "C" { + pub fn atomic_flag_clear_explicit(arg1: *mut atomic_flag, arg2: memory_order); +} +pub type u_char = __u_char; +pub type u_short = __u_short; +pub type u_int = __u_int; +pub type u_long = __u_long; +pub type quad_t = __quad_t; +pub type u_quad_t = __u_quad_t; +pub type fsid_t = __fsid_t; +pub type loff_t = __loff_t; +pub type ino_t = __ino_t; +pub type dev_t = __dev_t; +pub type gid_t = __gid_t; +pub type mode_t = __mode_t; +pub type nlink_t = __nlink_t; +pub type uid_t = __uid_t; +pub type off_t = __off_t; +pub type pid_t = __pid_t; +pub type id_t = __id_t; +pub type daddr_t = __daddr_t; +pub type caddr_t = __caddr_t; +pub type key_t = __key_t; +pub type clock_t = __clock_t; +pub type clockid_t = __clockid_t; pub type time_t = __time_t; +pub type timer_t = __timer_t; +pub type ulong = ::core::ffi::c_ulong; +pub type ushort = ::core::ffi::c_ushort; +pub type uint = ::core::ffi::c_uint; +pub type u_int8_t = __uint8_t; +pub type u_int16_t = __uint16_t; +pub type u_int32_t = __uint32_t; +pub type u_int64_t = __uint64_t; +pub type register_t = ::core::ffi::c_long; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __sigset_t { + pub __val: [::core::ffi::c_ulong; 16usize], +} +#[test] +fn bindgen_test_layout___sigset_t() { + const UNINIT: ::core::mem::MaybeUninit<__sigset_t> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__sigset_t>(), + 128usize, + concat!("Size of: ", stringify!(__sigset_t)) + ); + assert_eq!( + ::core::mem::align_of::<__sigset_t>(), + 8usize, + concat!("Alignment of ", stringify!(__sigset_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__sigset_t), + "::", + stringify!(__val) + ) + ); +} +pub type sigset_t = __sigset_t; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct timeval { + pub tv_sec: __time_t, + pub tv_usec: __suseconds_t, +} +#[test] +fn bindgen_test_layout_timeval() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timeval)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timeval)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_usec) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_usec) + ) + ); +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct timespec { @@ -2925,433 +3161,62 @@ fn bindgen_test_layout_timespec() { ) ); } -pub type pid_t = __pid_t; +pub type suseconds_t = __suseconds_t; +pub type __fd_mask = ::core::ffi::c_long; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct sched_param { - pub sched_priority: ::core::ffi::c_int, +pub struct fd_set { + pub __fds_bits: [__fd_mask; 16usize], } #[test] -fn bindgen_test_layout_sched_param() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_fd_set() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(sched_param)) - ); - assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(sched_param)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).sched_priority) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sched_param), - "::", - stringify!(sched_priority) - ) - ); -} -pub type __cpu_mask = ::core::ffi::c_ulong; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct cpu_set_t { - pub __bits: [__cpu_mask; 16usize], -} -#[test] -fn bindgen_test_layout_cpu_set_t() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(cpu_set_t)) + concat!("Size of: ", stringify!(fd_set)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(cpu_set_t)) + concat!("Alignment of ", stringify!(fd_set)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).__bits) as usize - ptr as usize }, + unsafe { ::core::ptr::addr_of!((*ptr).__fds_bits) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(cpu_set_t), + stringify!(fd_set), "::", - stringify!(__bits) + stringify!(__fds_bits) ) ); } +pub type fd_mask = __fd_mask; extern "C" { - pub fn __sched_cpucount(__setsize: usize, __setp: *const cpu_set_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn __sched_cpualloc(__count: usize) -> *mut cpu_set_t; -} -extern "C" { - pub fn __sched_cpufree(__set: *mut cpu_set_t); -} -extern "C" { - pub fn sched_setparam(__pid: __pid_t, __param: *const sched_param) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sched_getparam(__pid: __pid_t, __param: *mut sched_param) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sched_setscheduler( - __pid: __pid_t, - __policy: ::core::ffi::c_int, - __param: *const sched_param, + pub fn select( + __nfds: ::core::ffi::c_int, + __readfds: *mut fd_set, + __writefds: *mut fd_set, + __exceptfds: *mut fd_set, + __timeout: *mut timeval, ) -> ::core::ffi::c_int; } extern "C" { - pub fn sched_getscheduler(__pid: __pid_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sched_yield() -> ::core::ffi::c_int; -} -extern "C" { - pub fn sched_get_priority_max(__algorithm: ::core::ffi::c_int) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sched_get_priority_min(__algorithm: ::core::ffi::c_int) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sched_rr_get_interval(__pid: __pid_t, __t: *mut timespec) -> ::core::ffi::c_int; -} -pub type clock_t = __clock_t; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct tm { - pub tm_sec: ::core::ffi::c_int, - pub tm_min: ::core::ffi::c_int, - pub tm_hour: ::core::ffi::c_int, - pub tm_mday: ::core::ffi::c_int, - pub tm_mon: ::core::ffi::c_int, - pub tm_year: ::core::ffi::c_int, - pub tm_wday: ::core::ffi::c_int, - pub tm_yday: ::core::ffi::c_int, - pub tm_isdst: ::core::ffi::c_int, - pub tm_gmtoff: ::core::ffi::c_long, - pub tm_zone: *const ::core::ffi::c_char, -} -#[test] -fn bindgen_test_layout_tm() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 56usize, - concat!("Size of: ", stringify!(tm)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(tm)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_sec) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_sec) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_min) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_min) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_hour) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_hour) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_mday) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_mday) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_mon) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_mon) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_year) as usize - ptr as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_year) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_wday) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_wday) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_yday) as usize - ptr as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_yday) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_isdst) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_isdst) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_gmtoff) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_gmtoff) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tm_zone) as usize - ptr as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(tm), - "::", - stringify!(tm_zone) - ) - ); -} -pub type clockid_t = __clockid_t; -pub type timer_t = __timer_t; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct itimerspec { - pub it_interval: timespec, - pub it_value: timespec, -} -#[test] -fn bindgen_test_layout_itimerspec() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(itimerspec)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(itimerspec)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).it_interval) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(itimerspec), - "::", - stringify!(it_interval) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).it_value) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(itimerspec), - "::", - stringify!(it_value) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct sigevent { - _unused: [u8; 0], -} -extern "C" { - pub fn clock() -> clock_t; -} -extern "C" { - pub fn time(__timer: *mut time_t) -> time_t; -} -extern "C" { - pub fn difftime(__time1: time_t, __time0: time_t) -> f64; -} -extern "C" { - pub fn mktime(__tp: *mut tm) -> time_t; -} -extern "C" { - pub fn strftime( - __s: *mut ::core::ffi::c_char, - __maxsize: usize, - __format: *const ::core::ffi::c_char, - __tp: *const tm, - ) -> usize; -} -extern "C" { - pub fn strftime_l( - __s: *mut ::core::ffi::c_char, - __maxsize: usize, - __format: *const ::core::ffi::c_char, - __tp: *const tm, - __loc: locale_t, - ) -> usize; -} -extern "C" { - pub fn gmtime(__timer: *const time_t) -> *mut tm; -} -extern "C" { - pub fn localtime(__timer: *const time_t) -> *mut tm; -} -extern "C" { - pub fn gmtime_r(__timer: *const time_t, __tp: *mut tm) -> *mut tm; -} -extern "C" { - pub fn localtime_r(__timer: *const time_t, __tp: *mut tm) -> *mut tm; -} -extern "C" { - pub fn asctime(__tp: *const tm) -> *mut ::core::ffi::c_char; -} -extern "C" { - pub fn ctime(__timer: *const time_t) -> *mut ::core::ffi::c_char; -} -extern "C" { - pub fn asctime_r(__tp: *const tm, __buf: *mut ::core::ffi::c_char) -> *mut ::core::ffi::c_char; -} -extern "C" { - pub fn ctime_r( - __timer: *const time_t, - __buf: *mut ::core::ffi::c_char, - ) -> *mut ::core::ffi::c_char; -} -extern "C" { - pub static mut __tzname: [*mut ::core::ffi::c_char; 2usize]; -} -extern "C" { - pub static mut __daylight: ::core::ffi::c_int; -} -extern "C" { - pub static mut __timezone: ::core::ffi::c_long; -} -extern "C" { - pub static mut tzname: [*mut ::core::ffi::c_char; 2usize]; -} -extern "C" { - pub fn tzset(); -} -extern "C" { - pub static mut daylight: ::core::ffi::c_int; -} -extern "C" { - pub static mut timezone: ::core::ffi::c_long; -} -extern "C" { - pub fn timegm(__tp: *mut tm) -> time_t; -} -extern "C" { - pub fn timelocal(__tp: *mut tm) -> time_t; -} -extern "C" { - pub fn dysize(__year: ::core::ffi::c_int) -> ::core::ffi::c_int; -} -extern "C" { - pub fn nanosleep( - __requested_time: *const timespec, - __remaining: *mut timespec, + pub fn pselect( + __nfds: ::core::ffi::c_int, + __readfds: *mut fd_set, + __writefds: *mut fd_set, + __exceptfds: *mut fd_set, + __timeout: *const timespec, + __sigmask: *const __sigset_t, ) -> ::core::ffi::c_int; } -extern "C" { - pub fn clock_getres(__clock_id: clockid_t, __res: *mut timespec) -> ::core::ffi::c_int; -} -extern "C" { - pub fn clock_gettime(__clock_id: clockid_t, __tp: *mut timespec) -> ::core::ffi::c_int; -} -extern "C" { - pub fn clock_settime(__clock_id: clockid_t, __tp: *const timespec) -> ::core::ffi::c_int; -} -extern "C" { - pub fn clock_nanosleep( - __clock_id: clockid_t, - __flags: ::core::ffi::c_int, - __req: *const timespec, - __rem: *mut timespec, - ) -> ::core::ffi::c_int; -} -extern "C" { - pub fn clock_getcpuclockid(__pid: pid_t, __clock_id: *mut clockid_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn timer_create( - __clock_id: clockid_t, - __evp: *mut sigevent, - __timerid: *mut timer_t, - ) -> ::core::ffi::c_int; -} -extern "C" { - pub fn timer_delete(__timerid: timer_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn timer_settime( - __timerid: timer_t, - __flags: ::core::ffi::c_int, - __value: *const itimerspec, - __ovalue: *mut itimerspec, - ) -> ::core::ffi::c_int; -} -extern "C" { - pub fn timer_gettime(__timerid: timer_t, __value: *mut itimerspec) -> ::core::ffi::c_int; -} -extern "C" { - pub fn timer_getoverrun(__timerid: timer_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn timespec_get(__ts: *mut timespec, __base: ::core::ffi::c_int) -> ::core::ffi::c_int; -} +pub type blksize_t = __blksize_t; +pub type blkcnt_t = __blkcnt_t; +pub type fsblkcnt_t = __fsblkcnt_t; +pub type fsfilcnt_t = __fsfilcnt_t; #[repr(C)] #[derive(Copy, Clone)] pub union __atomic_wide_counter { @@ -4310,37 +4175,945 @@ fn bindgen_test_layout_pthread_barrierattr_t() { ) ); } -pub type __jmp_buf = [::core::ffi::c_long; 8usize]; #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __sigset_t { - pub __val: [::core::ffi::c_ulong; 16usize], +#[derive(Copy, Clone)] +pub union sem_t { + pub __size: [::core::ffi::c_char; 32usize], + pub __align: ::core::ffi::c_long, } #[test] -fn bindgen_test_layout___sigset_t() { - const UNINIT: ::core::mem::MaybeUninit<__sigset_t> = ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_sem_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::<__sigset_t>(), - 128usize, - concat!("Size of: ", stringify!(__sigset_t)) + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(sem_t)) ); assert_eq!( - ::core::mem::align_of::<__sigset_t>(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(__sigset_t)) + concat!("Alignment of ", stringify!(sem_t)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(__sigset_t), + stringify!(sem_t), "::", - stringify!(__val) + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sem_t), + "::", + stringify!(__align) ) ); } +extern "C" { + pub fn sem_init( + __sem: *mut sem_t, + __pshared: ::core::ffi::c_int, + __value: ::core::ffi::c_uint, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_destroy(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_open( + __name: *const ::core::ffi::c_char, + __oflag: ::core::ffi::c_int, + ... + ) -> *mut sem_t; +} +extern "C" { + pub fn sem_close(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_unlink(__name: *const ::core::ffi::c_char) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_wait(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_timedwait(__sem: *mut sem_t, __abstime: *const timespec) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_trywait(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_post(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_getvalue(__sem: *mut sem_t, __sval: *mut ::core::ffi::c_int) -> ::core::ffi::c_int; +} +pub type csp_bin_sem_t = sem_t; +extern "C" { + #[doc = " initialize a binary semaphore with static storage\n The semaphore is created in state \\a unlocked (value 1).\n On platforms supporting max values, the semaphore is created with a max value of 1, hence the naming \\a binary."] + pub fn csp_bin_sem_init(sem: *mut csp_bin_sem_t); +} +extern "C" { + #[doc = " Wait/lock semaphore\n @param[in] timeout timeout in mS. Use #CSP_MAX_TIMEOUT for no timeout, e.g. wait forever until locked.\n @return #CSP_SEMAPHORE_OK on success, otherwise #CSP_SEMAPHORE_ERROR"] + pub fn csp_bin_sem_wait( + sem: *mut csp_bin_sem_t, + timeout: ::core::ffi::c_uint, + ) -> ::core::ffi::c_int; +} +extern "C" { + #[doc = " Signal/unlock semaphore\n @return #CSP_SEMAPHORE_OK on success, otherwise #CSP_SEMAPHORE_ERROR"] + pub fn csp_bin_sem_post(sem: *mut csp_bin_sem_t) -> ::core::ffi::c_int; +} +pub const csp_conn_state_t_CONN_CLOSED: csp_conn_state_t = 0; +pub const csp_conn_state_t_CONN_OPEN: csp_conn_state_t = 1; +#[doc = " Connection states"] +pub type csp_conn_state_t = ::core::ffi::c_uint; +pub const csp_conn_type_t_CONN_CLIENT: csp_conn_type_t = 0; +pub const csp_conn_type_t_CONN_SERVER: csp_conn_type_t = 1; +#[doc = " Connection types"] +pub type csp_conn_type_t = ::core::ffi::c_uint; +pub const csp_rdp_state_t_RDP_CLOSED: csp_rdp_state_t = 0; +pub const csp_rdp_state_t_RDP_SYN_SENT: csp_rdp_state_t = 1; +pub const csp_rdp_state_t_RDP_SYN_RCVD: csp_rdp_state_t = 2; +pub const csp_rdp_state_t_RDP_OPEN: csp_rdp_state_t = 3; +pub const csp_rdp_state_t_RDP_CLOSE_WAIT: csp_rdp_state_t = 4; +#[doc = " RDP Connection states"] +pub type csp_rdp_state_t = ::core::ffi::c_uint; +#[doc = " RDP Connection"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct csp_rdp_t { + #[doc = "< Connection state"] + pub state: csp_rdp_state_t, + #[doc = "< Tracks 'who' have closed the RDP connection"] + pub closed_by: u8, + #[doc = "< The sequence number of the next segment that is to be sent"] + pub snd_nxt: u16, + #[doc = "< The sequence number of the oldest unacknowledged segment"] + pub snd_una: u16, + #[doc = "< The initial send sequence number"] + pub snd_iss: u16, + #[doc = "< The sequence number of the last segment received correctly and in sequence"] + pub rcv_cur: u16, + #[doc = "< The initial receive sequence number"] + pub rcv_irs: u16, + #[doc = "< The last sequence number acknowledged by the receiver"] + pub rcv_lsa: u16, + pub window_size: u32, + pub conn_timeout: u32, + pub packet_timeout: u32, + pub delayed_acks: u32, + pub ack_timeout: u32, + pub ack_delay_count: u32, + pub ack_timestamp: u32, + pub tx_wait: csp_bin_sem_t, +} +#[test] +fn bindgen_test_layout_csp_rdp_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 80usize, + concat!("Size of: ", stringify!(csp_rdp_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_rdp_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(state) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).closed_by) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(closed_by) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).snd_nxt) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(snd_nxt) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).snd_una) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(snd_una) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).snd_iss) as usize - ptr as usize }, + 10usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(snd_iss) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rcv_cur) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(rcv_cur) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rcv_irs) as usize - ptr as usize }, + 14usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(rcv_irs) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rcv_lsa) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(rcv_lsa) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).window_size) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(window_size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).conn_timeout) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(conn_timeout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).packet_timeout) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(packet_timeout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).delayed_acks) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(delayed_acks) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ack_timeout) as usize - ptr as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(ack_timeout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ack_delay_count) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(ack_delay_count) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ack_timestamp) as usize - ptr as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(ack_timestamp) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tx_wait) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(tx_wait) + ) + ); +} +#[doc = " @brief Connection struct"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct csp_conn_s { + pub type_: atomic_int, + pub state: atomic_int, + pub idin: csp_id_t, + pub idout: csp_id_t, + pub sport_outgoing: u8, + pub rx_queue: csp_queue_handle_t, + pub rx_queue_static: csp_static_queue_t, + pub rx_queue_static_data: [::core::ffi::c_char; 128usize], + pub callback: ::core::option::Option, + pub dest_socket: *mut csp_socket_t, + pub timestamp: u32, + pub opts: u32, + pub rdp: csp_rdp_t, +} +#[test] +fn bindgen_test_layout_csp_conn_s() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 280usize, + concat!("Size of: ", stringify!(csp_conn_s)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_conn_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(state) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idin) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idin) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idout) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sport_outgoing) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(sport_outgoing) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static_data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, + 176usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(callback) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).dest_socket) as usize - ptr as usize }, + 184usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(dest_socket) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).timestamp) as usize - ptr as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(timestamp) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).opts) as usize - ptr as usize }, + 196usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(opts) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, + 200usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rdp) + ) + ); +} +extern "C" { + pub fn csp_conn_enqueue_packet( + conn: *mut csp_conn_t, + packet: *mut csp_packet_t, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_conn_init(); +} +extern "C" { + pub fn csp_conn_allocate(type_: csp_conn_type_t) -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_find_existing(id: *mut csp_id_t) -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_find_dport(dport: ::core::ffi::c_uint) -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_new(idin: csp_id_t, idout: csp_id_t, type_: csp_conn_type_t) + -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_check_timeouts(); +} +extern "C" { + pub fn csp_conn_get_rxq(prio: ::core::ffi::c_int) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_conn_close(conn: *mut csp_conn_t, closed_by: u8) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_conn_get_array(size: *mut usize) -> *const csp_conn_t; +} +extern "C" { + #[doc = " Loopback interface."] + pub static mut csp_if_lo: csp_iface_t; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sched_param { + pub sched_priority: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_sched_param() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(sched_param)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(sched_param)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sched_priority) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sched_param), + "::", + stringify!(sched_priority) + ) + ); +} +pub type __cpu_mask = ::core::ffi::c_ulong; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct cpu_set_t { + pub __bits: [__cpu_mask; 16usize], +} +#[test] +fn bindgen_test_layout_cpu_set_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(cpu_set_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(cpu_set_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__bits) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cpu_set_t), + "::", + stringify!(__bits) + ) + ); +} +extern "C" { + pub fn __sched_cpucount(__setsize: usize, __setp: *const cpu_set_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn __sched_cpualloc(__count: usize) -> *mut cpu_set_t; +} +extern "C" { + pub fn __sched_cpufree(__set: *mut cpu_set_t); +} +extern "C" { + pub fn sched_setparam(__pid: __pid_t, __param: *const sched_param) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_getparam(__pid: __pid_t, __param: *mut sched_param) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_setscheduler( + __pid: __pid_t, + __policy: ::core::ffi::c_int, + __param: *const sched_param, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_getscheduler(__pid: __pid_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_yield() -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_get_priority_max(__algorithm: ::core::ffi::c_int) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_get_priority_min(__algorithm: ::core::ffi::c_int) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sched_rr_get_interval(__pid: __pid_t, __t: *mut timespec) -> ::core::ffi::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct tm { + pub tm_sec: ::core::ffi::c_int, + pub tm_min: ::core::ffi::c_int, + pub tm_hour: ::core::ffi::c_int, + pub tm_mday: ::core::ffi::c_int, + pub tm_mon: ::core::ffi::c_int, + pub tm_year: ::core::ffi::c_int, + pub tm_wday: ::core::ffi::c_int, + pub tm_yday: ::core::ffi::c_int, + pub tm_isdst: ::core::ffi::c_int, + pub tm_gmtoff: ::core::ffi::c_long, + pub tm_zone: *const ::core::ffi::c_char, +} +#[test] +fn bindgen_test_layout_tm() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(tm)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(tm)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_sec) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_min) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_min) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_hour) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_hour) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_mday) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_mday) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_mon) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_mon) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_year) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_year) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_wday) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_wday) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_yday) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_yday) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_isdst) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_isdst) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_gmtoff) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_gmtoff) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tm_zone) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(tm), + "::", + stringify!(tm_zone) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct itimerspec { + pub it_interval: timespec, + pub it_value: timespec, +} +#[test] +fn bindgen_test_layout_itimerspec() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(itimerspec)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(itimerspec)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).it_interval) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(itimerspec), + "::", + stringify!(it_interval) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).it_value) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(itimerspec), + "::", + stringify!(it_value) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sigevent { + _unused: [u8; 0], +} +extern "C" { + pub fn clock() -> clock_t; +} +extern "C" { + pub fn time(__timer: *mut time_t) -> time_t; +} +extern "C" { + pub fn difftime(__time1: time_t, __time0: time_t) -> f64; +} +extern "C" { + pub fn mktime(__tp: *mut tm) -> time_t; +} +extern "C" { + pub fn strftime( + __s: *mut ::core::ffi::c_char, + __maxsize: usize, + __format: *const ::core::ffi::c_char, + __tp: *const tm, + ) -> usize; +} +extern "C" { + pub fn strftime_l( + __s: *mut ::core::ffi::c_char, + __maxsize: usize, + __format: *const ::core::ffi::c_char, + __tp: *const tm, + __loc: locale_t, + ) -> usize; +} +extern "C" { + pub fn gmtime(__timer: *const time_t) -> *mut tm; +} +extern "C" { + pub fn localtime(__timer: *const time_t) -> *mut tm; +} +extern "C" { + pub fn gmtime_r(__timer: *const time_t, __tp: *mut tm) -> *mut tm; +} +extern "C" { + pub fn localtime_r(__timer: *const time_t, __tp: *mut tm) -> *mut tm; +} +extern "C" { + pub fn asctime(__tp: *const tm) -> *mut ::core::ffi::c_char; +} +extern "C" { + pub fn ctime(__timer: *const time_t) -> *mut ::core::ffi::c_char; +} +extern "C" { + pub fn asctime_r(__tp: *const tm, __buf: *mut ::core::ffi::c_char) -> *mut ::core::ffi::c_char; +} +extern "C" { + pub fn ctime_r( + __timer: *const time_t, + __buf: *mut ::core::ffi::c_char, + ) -> *mut ::core::ffi::c_char; +} +extern "C" { + pub static mut __tzname: [*mut ::core::ffi::c_char; 2usize]; +} +extern "C" { + pub static mut __daylight: ::core::ffi::c_int; +} +extern "C" { + pub static mut __timezone: ::core::ffi::c_long; +} +extern "C" { + pub static mut tzname: [*mut ::core::ffi::c_char; 2usize]; +} +extern "C" { + pub fn tzset(); +} +extern "C" { + pub static mut daylight: ::core::ffi::c_int; +} +extern "C" { + pub static mut timezone: ::core::ffi::c_long; +} +extern "C" { + pub fn timegm(__tp: *mut tm) -> time_t; +} +extern "C" { + pub fn timelocal(__tp: *mut tm) -> time_t; +} +extern "C" { + pub fn dysize(__year: ::core::ffi::c_int) -> ::core::ffi::c_int; +} +extern "C" { + pub fn nanosleep( + __requested_time: *const timespec, + __remaining: *mut timespec, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn clock_getres(__clock_id: clockid_t, __res: *mut timespec) -> ::core::ffi::c_int; +} +extern "C" { + pub fn clock_gettime(__clock_id: clockid_t, __tp: *mut timespec) -> ::core::ffi::c_int; +} +extern "C" { + pub fn clock_settime(__clock_id: clockid_t, __tp: *const timespec) -> ::core::ffi::c_int; +} +extern "C" { + pub fn clock_nanosleep( + __clock_id: clockid_t, + __flags: ::core::ffi::c_int, + __req: *const timespec, + __rem: *mut timespec, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn clock_getcpuclockid(__pid: pid_t, __clock_id: *mut clockid_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn timer_create( + __clock_id: clockid_t, + __evp: *mut sigevent, + __timerid: *mut timer_t, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn timer_delete(__timerid: timer_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn timer_settime( + __timerid: timer_t, + __flags: ::core::ffi::c_int, + __value: *const itimerspec, + __ovalue: *mut itimerspec, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn timer_gettime(__timerid: timer_t, __value: *mut itimerspec) -> ::core::ffi::c_int; +} +extern "C" { + pub fn timer_getoverrun(__timerid: timer_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn timespec_get(__ts: *mut timespec, __base: ::core::ffi::c_int) -> ::core::ffi::c_int; +} +pub type __jmp_buf = [::core::ffi::c_long; 8usize]; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct __jmp_buf_tag { @@ -5203,131 +5976,6 @@ fn bindgen_test_layout_iovec() { ) ); } -pub type u_char = __u_char; -pub type u_short = __u_short; -pub type u_int = __u_int; -pub type u_long = __u_long; -pub type quad_t = __quad_t; -pub type u_quad_t = __u_quad_t; -pub type fsid_t = __fsid_t; -pub type loff_t = __loff_t; -pub type ino_t = __ino_t; -pub type dev_t = __dev_t; -pub type gid_t = __gid_t; -pub type mode_t = __mode_t; -pub type nlink_t = __nlink_t; -pub type uid_t = __uid_t; -pub type off_t = __off_t; -pub type id_t = __id_t; -pub type daddr_t = __daddr_t; -pub type caddr_t = __caddr_t; -pub type key_t = __key_t; -pub type ulong = ::core::ffi::c_ulong; -pub type ushort = ::core::ffi::c_ushort; -pub type uint = ::core::ffi::c_uint; -pub type u_int8_t = __uint8_t; -pub type u_int16_t = __uint16_t; -pub type u_int32_t = __uint32_t; -pub type u_int64_t = __uint64_t; -pub type register_t = ::core::ffi::c_long; -pub type sigset_t = __sigset_t; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct timeval { - pub tv_sec: __time_t, - pub tv_usec: __suseconds_t, -} -#[test] -fn bindgen_test_layout_timeval() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(timeval)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(timeval)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timeval), - "::", - stringify!(tv_sec) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tv_usec) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(timeval), - "::", - stringify!(tv_usec) - ) - ); -} -pub type suseconds_t = __suseconds_t; -pub type __fd_mask = ::core::ffi::c_long; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct fd_set { - pub __fds_bits: [__fd_mask; 16usize], -} -#[test] -fn bindgen_test_layout_fd_set() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(fd_set)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(fd_set)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).__fds_bits) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(fd_set), - "::", - stringify!(__fds_bits) - ) - ); -} -pub type fd_mask = __fd_mask; -extern "C" { - pub fn select( - __nfds: ::core::ffi::c_int, - __readfds: *mut fd_set, - __writefds: *mut fd_set, - __exceptfds: *mut fd_set, - __timeout: *mut timeval, - ) -> ::core::ffi::c_int; -} -extern "C" { - pub fn pselect( - __nfds: ::core::ffi::c_int, - __readfds: *mut fd_set, - __writefds: *mut fd_set, - __exceptfds: *mut fd_set, - __timeout: *const timespec, - __sigmask: *const __sigset_t, - ) -> ::core::ffi::c_int; -} -pub type blksize_t = __blksize_t; -pub type blkcnt_t = __blkcnt_t; -pub type fsblkcnt_t = __fsblkcnt_t; -pub type fsfilcnt_t = __fsfilcnt_t; pub type socklen_t = __socklen_t; pub const __socket_type_SOCK_STREAM: __socket_type = 1; pub const __socket_type_SOCK_DGRAM: __socket_type = 2; @@ -6883,609 +7531,6 @@ extern "C" { #[doc = " Setup UDP peer\n\n RX task:\n A server task will attempt at binding to ip 0.0.0.0 port 9600\n If this fails, it is because another udp server is already running.\n The server task will continue attemting the bind and will not exit before the application is closed.\n\n TX peer:\n Outgoing CSP packets will be transferred to the peer specified by the host argument"] pub fn csp_if_udp_init(iface: *mut csp_iface_t, ifconf: *mut csp_if_udp_conf_t); } -pub const memory_order_memory_order_relaxed: memory_order = 0; -pub const memory_order_memory_order_consume: memory_order = 1; -pub const memory_order_memory_order_acquire: memory_order = 2; -pub const memory_order_memory_order_release: memory_order = 3; -pub const memory_order_memory_order_acq_rel: memory_order = 4; -pub const memory_order_memory_order_seq_cst: memory_order = 5; -pub type memory_order = ::core::ffi::c_uint; -extern "C" { - pub fn atomic_thread_fence(arg1: memory_order); -} -extern "C" { - pub fn atomic_signal_fence(arg1: memory_order); -} -pub type atomic_bool = u8; -pub type atomic_char = u8; -pub type atomic_schar = u8; -pub type atomic_uchar = u8; -pub type atomic_short = u16; -pub type atomic_ushort = u16; -pub type atomic_int = u32; -pub type atomic_uint = u32; -pub type atomic_long = u64; -pub type atomic_ulong = u64; -pub type atomic_llong = u64; -pub type atomic_ullong = u64; -pub type atomic_char16_t = u16; -pub type atomic_char32_t = u32; -pub type atomic_wchar_t = u32; -pub type atomic_int_least8_t = u8; -pub type atomic_uint_least8_t = u8; -pub type atomic_int_least16_t = u16; -pub type atomic_uint_least16_t = u16; -pub type atomic_int_least32_t = u32; -pub type atomic_uint_least32_t = u32; -pub type atomic_int_least64_t = u64; -pub type atomic_uint_least64_t = u64; -pub type atomic_int_fast8_t = u8; -pub type atomic_uint_fast8_t = u8; -pub type atomic_int_fast16_t = u64; -pub type atomic_uint_fast16_t = u64; -pub type atomic_int_fast32_t = u64; -pub type atomic_uint_fast32_t = u64; -pub type atomic_int_fast64_t = u64; -pub type atomic_uint_fast64_t = u64; -pub type atomic_intptr_t = u64; -pub type atomic_uintptr_t = u64; -pub type atomic_size_t = u64; -pub type atomic_ptrdiff_t = u64; -pub type atomic_intmax_t = u64; -pub type atomic_uintmax_t = u64; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct atomic_flag { - pub _Value: atomic_bool, -} -#[test] -fn bindgen_test_layout_atomic_flag() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(atomic_flag)) - ); - assert_eq!( - ::core::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(atomic_flag)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr)._Value) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(atomic_flag), - "::", - stringify!(_Value) - ) - ); -} -extern "C" { - pub fn atomic_flag_test_and_set(arg1: *mut atomic_flag) -> bool; -} -extern "C" { - pub fn atomic_flag_test_and_set_explicit(arg1: *mut atomic_flag, arg2: memory_order) -> bool; -} -extern "C" { - pub fn atomic_flag_clear(arg1: *mut atomic_flag); -} -extern "C" { - pub fn atomic_flag_clear_explicit(arg1: *mut atomic_flag, arg2: memory_order); -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union sem_t { - pub __size: [::core::ffi::c_char; 32usize], - pub __align: ::core::ffi::c_long, -} -#[test] -fn bindgen_test_layout_sem_t() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(sem_t)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(sem_t)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sem_t), - "::", - stringify!(__size) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sem_t), - "::", - stringify!(__align) - ) - ); -} -extern "C" { - pub fn sem_init( - __sem: *mut sem_t, - __pshared: ::core::ffi::c_int, - __value: ::core::ffi::c_uint, - ) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_destroy(__sem: *mut sem_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_open( - __name: *const ::core::ffi::c_char, - __oflag: ::core::ffi::c_int, - ... - ) -> *mut sem_t; -} -extern "C" { - pub fn sem_close(__sem: *mut sem_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_unlink(__name: *const ::core::ffi::c_char) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_wait(__sem: *mut sem_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_timedwait(__sem: *mut sem_t, __abstime: *const timespec) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_trywait(__sem: *mut sem_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_post(__sem: *mut sem_t) -> ::core::ffi::c_int; -} -extern "C" { - pub fn sem_getvalue(__sem: *mut sem_t, __sval: *mut ::core::ffi::c_int) -> ::core::ffi::c_int; -} -pub type csp_bin_sem_t = sem_t; -extern "C" { - #[doc = " initialize a binary semaphore with static storage\n The semaphore is created in state \\a unlocked (value 1).\n On platforms supporting max values, the semaphore is created with a max value of 1, hence the naming \\a binary."] - pub fn csp_bin_sem_init(sem: *mut csp_bin_sem_t); -} -extern "C" { - #[doc = " Wait/lock semaphore\n @param[in] timeout timeout in mS. Use #CSP_MAX_TIMEOUT for no timeout, e.g. wait forever until locked.\n @return #CSP_SEMAPHORE_OK on success, otherwise #CSP_SEMAPHORE_ERROR"] - pub fn csp_bin_sem_wait( - sem: *mut csp_bin_sem_t, - timeout: ::core::ffi::c_uint, - ) -> ::core::ffi::c_int; -} -extern "C" { - #[doc = " Signal/unlock semaphore\n @return #CSP_SEMAPHORE_OK on success, otherwise #CSP_SEMAPHORE_ERROR"] - pub fn csp_bin_sem_post(sem: *mut csp_bin_sem_t) -> ::core::ffi::c_int; -} -pub const csp_conn_state_t_CONN_CLOSED: csp_conn_state_t = 0; -pub const csp_conn_state_t_CONN_OPEN: csp_conn_state_t = 1; -#[doc = " Connection states"] -pub type csp_conn_state_t = ::core::ffi::c_uint; -pub const csp_conn_type_t_CONN_CLIENT: csp_conn_type_t = 0; -pub const csp_conn_type_t_CONN_SERVER: csp_conn_type_t = 1; -#[doc = " Connection types"] -pub type csp_conn_type_t = ::core::ffi::c_uint; -pub const csp_rdp_state_t_RDP_CLOSED: csp_rdp_state_t = 0; -pub const csp_rdp_state_t_RDP_SYN_SENT: csp_rdp_state_t = 1; -pub const csp_rdp_state_t_RDP_SYN_RCVD: csp_rdp_state_t = 2; -pub const csp_rdp_state_t_RDP_OPEN: csp_rdp_state_t = 3; -pub const csp_rdp_state_t_RDP_CLOSE_WAIT: csp_rdp_state_t = 4; -#[doc = " RDP Connection states"] -pub type csp_rdp_state_t = ::core::ffi::c_uint; -#[doc = " RDP Connection"] -#[repr(C)] -#[derive(Copy, Clone)] -pub struct csp_rdp_t { - #[doc = "< Connection state"] - pub state: csp_rdp_state_t, - #[doc = "< Tracks 'who' have closed the RDP connection"] - pub closed_by: u8, - #[doc = "< The sequence number of the next segment that is to be sent"] - pub snd_nxt: u16, - #[doc = "< The sequence number of the oldest unacknowledged segment"] - pub snd_una: u16, - #[doc = "< The initial send sequence number"] - pub snd_iss: u16, - #[doc = "< The sequence number of the last segment received correctly and in sequence"] - pub rcv_cur: u16, - #[doc = "< The initial receive sequence number"] - pub rcv_irs: u16, - #[doc = "< The last sequence number acknowledged by the receiver"] - pub rcv_lsa: u16, - pub window_size: u32, - pub conn_timeout: u32, - pub packet_timeout: u32, - pub delayed_acks: u32, - pub ack_timeout: u32, - pub ack_delay_count: u32, - pub ack_timestamp: u32, - pub tx_wait: csp_bin_sem_t, -} -#[test] -fn bindgen_test_layout_csp_rdp_t() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 80usize, - concat!("Size of: ", stringify!(csp_rdp_t)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(csp_rdp_t)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(state) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).closed_by) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(closed_by) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).snd_nxt) as usize - ptr as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(snd_nxt) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).snd_una) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(snd_una) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).snd_iss) as usize - ptr as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(snd_iss) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rcv_cur) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(rcv_cur) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rcv_irs) as usize - ptr as usize }, - 14usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(rcv_irs) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rcv_lsa) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(rcv_lsa) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).window_size) as usize - ptr as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(window_size) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).conn_timeout) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(conn_timeout) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).packet_timeout) as usize - ptr as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(packet_timeout) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).delayed_acks) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(delayed_acks) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).ack_timeout) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(ack_timeout) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).ack_delay_count) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(ack_delay_count) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).ack_timestamp) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(ack_timestamp) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).tx_wait) as usize - ptr as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(csp_rdp_t), - "::", - stringify!(tx_wait) - ) - ); -} -#[doc = " @brief Connection struct"] -#[repr(C)] -#[derive(Copy, Clone)] -pub struct csp_conn_s { - pub type_: atomic_int, - pub state: atomic_int, - pub idin: csp_id_t, - pub idout: csp_id_t, - pub sport_outgoing: u8, - pub rx_queue: csp_queue_handle_t, - pub rx_queue_static: csp_static_queue_t, - pub rx_queue_static_data: [::core::ffi::c_char; 128usize], - pub callback: ::core::option::Option, - pub dest_socket: *mut csp_socket_t, - pub timestamp: u32, - pub opts: u32, - pub rdp: csp_rdp_t, -} -#[test] -fn bindgen_test_layout_csp_conn_s() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 280usize, - concat!("Size of: ", stringify!(csp_conn_s)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(csp_conn_s)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(state) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).idin) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(idin) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).idout) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(idout) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).sport_outgoing) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(sport_outgoing) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rx_queue) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rx_queue_static) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rx_queue_static_data) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, - 176usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(callback) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).dest_socket) as usize - ptr as usize }, - 184usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(dest_socket) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).timestamp) as usize - ptr as usize }, - 192usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(timestamp) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).opts) as usize - ptr as usize }, - 196usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(opts) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, - 200usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rdp) - ) - ); -} -extern "C" { - pub fn csp_conn_enqueue_packet( - conn: *mut csp_conn_t, - packet: *mut csp_packet_t, - ) -> ::core::ffi::c_int; -} -extern "C" { - pub fn csp_conn_init(); -} -extern "C" { - pub fn csp_conn_allocate(type_: csp_conn_type_t) -> *mut csp_conn_t; -} -extern "C" { - pub fn csp_conn_find_existing(id: *mut csp_id_t) -> *mut csp_conn_t; -} -extern "C" { - pub fn csp_conn_find_dport(dport: ::core::ffi::c_uint) -> *mut csp_conn_t; -} -extern "C" { - pub fn csp_conn_new(idin: csp_id_t, idout: csp_id_t, type_: csp_conn_type_t) - -> *mut csp_conn_t; -} -extern "C" { - pub fn csp_conn_check_timeouts(); -} -extern "C" { - pub fn csp_conn_get_rxq(prio: ::core::ffi::c_int) -> ::core::ffi::c_int; -} -extern "C" { - pub fn csp_conn_close(conn: *mut csp_conn_t, closed_by: u8) -> ::core::ffi::c_int; -} -extern "C" { - pub fn csp_conn_get_array(size: *mut usize) -> *const csp_conn_t; -} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct __locale_data { diff --git a/clib/cfg/csp/autoconfig.h b/clib/cfg/csp/autoconfig.h index 823f616..2eadec9 100644 --- a/clib/cfg/csp/autoconfig.h +++ b/clib/cfg/csp/autoconfig.h @@ -1,4 +1,4 @@ -// This file was auto-generated by the libcsp-cargo-build library +// This file was auto-generated by libcsp-cargo-build v0.1.0 #define CSP_POSIX 1 #define CSP_ZEPHYR 0 diff --git a/clib/wrapper.h b/clib/wrapper.h index 6bdb874..727cc32 100644 --- a/clib/wrapper.h +++ b/clib/wrapper.h @@ -1,4 +1,6 @@ #include "csp/csp.h" +#include "csp/csp_hooks.h" +#include "csp_conn.h" + #include "csp/interfaces/csp_if_lo.h" #include "csp/interfaces/csp_if_udp.h" -#include "csp_conn.h" diff --git a/examples/autoconfig.h b/examples/autoconfig.h index 823f616..2eadec9 100644 --- a/examples/autoconfig.h +++ b/examples/autoconfig.h @@ -1,4 +1,4 @@ -// This file was auto-generated by the libcsp-cargo-build library +// This file was auto-generated by libcsp-cargo-build v0.1.0 #define CSP_POSIX 1 #define CSP_ZEPHYR 0 diff --git a/examples/autoconfig.rs b/examples/autoconfig.rs index f343643..0477874 100644 --- a/examples/autoconfig.rs +++ b/examples/autoconfig.rs @@ -1,4 +1,4 @@ -// This file was auto-generated by the libcsp-cargo-build library +// This file was auto-generated by libcsp-cargo-build v0.1.0 pub const CSP_CONN_RXQUEUE_LEN: usize = 16; pub const CSP_QFIFO_LEN: usize = 16; pub const CSP_PORT_MAX_BIND: usize = 16; diff --git a/examples/src/main.rs b/examples/src/main.rs index cf783b7..1d5828c 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -10,9 +10,9 @@ use std::{ use libcsp::{ csp_accept_guarded, csp_bind, csp_buffer_get, csp_conn_dport, csp_conn_print_table, - csp_connect_guarded, csp_iflist_print, csp_init, csp_listen, csp_ping, csp_read_guarded, - csp_reboot, csp_route_work, csp_send, csp_service_handler, ConnectOpts, CspError, CspSocket, - MsgPriority, SocketFlags, CSP_ANY, CSP_LOOPBACK, + csp_connect_guarded, csp_init, csp_listen, csp_ping, csp_read_guarded, csp_reboot, + csp_route_work, csp_send, csp_service_handler, iflist::csp_iflist_print, ConnectOpts, CspError, + CspSocket, MsgPriority, SocketFlags, CSP_ANY, CSP_LOOPBACK, }; const MY_SERVER_PORT: i32 = 10; diff --git a/libcsp-cargo-build/src/lib.rs b/libcsp-cargo-build/src/lib.rs index 5aeccb8..ecd2e2f 100644 --- a/libcsp-cargo-build/src/lib.rs +++ b/libcsp-cargo-build/src/lib.rs @@ -1,3 +1,6 @@ +//! This crate provides a library to allow building the [`libcsp`](https://github.com/libcsp/libcsp) +//! C library with cargo. You can find some more high-level information and examples in the +//! [main repository](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust). use std::{ io::{self, Write}, path::{Path, PathBuf}, @@ -109,6 +112,17 @@ impl Default for Config { } } +/// Primary builder structure used to compile the `libcsp` C library. +/// +/// The [Self::cfg] field can be used to configure the library build. The will also take care +/// of generating the autoconfig.h file required for the library configuration automatically based +/// on the build [Config]. An API is also provided to generate the autoconfig.rs file required +/// for compiling the [`libcsp-sys`](https://crates.io/crates/libcp-sys) Rust FFI bindings crate. +/// +/// ## Example +/// +/// The [example buildscript](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust/src/branch/main/examples/build.rs) +/// uses this builder structure to compile the library. pub struct Builder { generate_autoconf_file: bool, libcsp_path: PathBuf, @@ -120,6 +134,7 @@ pub struct Builder { } impl Builder { + /// Create a new builder instance. pub fn new(libcsp_path: PathBuf, out_dir: PathBuf) -> Self { let mut libcsp_src_path_base = libcsp_path.clone(); libcsp_src_path_base.push("src"); @@ -134,7 +149,13 @@ impl Builder { } } - pub fn cc(&mut self) -> &mut cc::Build { + /// Access to the underlying [cc::Build] builder object. + pub fn cc(&mut self) -> &cc::Build { + &self.build + } + + /// Mutable access to the underlying [cc::Build] builder object. + pub fn cc_mut(&mut self) -> &mut cc::Build { &mut self.build } @@ -187,6 +208,8 @@ impl Builder { self.build.cargo_warnings(self.compiler_warnings); self.build.compile("csp"); + // TODO: We could generate some sort of information file which contains the + // compilation information and the version of hte library. Ok(()) } @@ -216,13 +239,21 @@ impl Builder { } } +/// Generate the autoconfig.h file which is required to build the C library. This file contains +/// important configuration defines. pub fn generate_autoconf_header_file(out_dir: impl AsRef, cfg: &Config) -> io::Result<()> { let out_dir = out_dir.as_ref(); let mut autoconf_file_string = String::new(); - autoconf_file_string - .push_str("// This file was auto-generated by the libcsp-cargo-build library\n"); + let version = env!("CARGO_PKG_VERSION"); + let name = env!("CARGO_PKG_NAME"); + autoconf_file_string.push_str(&format!( + "// This file was auto-generated by {} v{}\n", + name, version + )); #[cfg(unix)] autoconf_file_string.push_str("#define CSP_POSIX 1\n"); + #[cfg(not(unix))] + autoconf_file_string.push_str("#define CSP_POSIX 0\n"); autoconf_file_string.push_str("#define CSP_ZEPHYR 0\n"); autoconf_file_string.push('\n'); autoconf_file_string.push_str(&format!( @@ -320,11 +351,17 @@ pub fn generate_autoconf_header_file(out_dir: impl AsRef, cfg: &Config) -> Ok(()) } +/// Generate the autoconfig.rs file which is required by the +/// [`libcsp-sys`](https://crates.io/crates/libcsp-sys) Rust bindings crate. pub fn generate_autoconf_rust_file(out_dir: impl AsRef, cfg: &Config) -> io::Result<()> { let out_dir = out_dir.as_ref(); let mut autoconf_file_string = String::new(); - autoconf_file_string - .push_str("// This file was auto-generated by the libcsp-cargo-build library\n"); + let version = env!("CARGO_PKG_VERSION"); + let name = env!("CARGO_PKG_NAME"); + autoconf_file_string.push_str(&format!( + "// This file was auto-generated by {} v{}\n", + name, version + )); autoconf_file_string.push_str(&format!( "pub const {}: usize = {};\n", cfg_keys::CONN_RXQUEUE_LEN, diff --git a/libcsp-sys/src/lib.rs b/libcsp-sys/src/lib.rs index 8147c23..9dc8ed0 100644 --- a/libcsp-sys/src/lib.rs +++ b/libcsp-sys/src/lib.rs @@ -1,3 +1,19 @@ +//! This crate provides FFI bindings for the [`libcsp` library](https://github.com/libcsp/libcsp). + +//! Generally, you probably do not want to use this library directly and instead use the +//! [`libcsp`](https://crates.io/crates/libcsp) Rust crate which provides a safe and ergonomic Rust +//! API. +//! +//! You can find some more high-level information and examples in the +//! [main repository](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust). +//! +//! ## Compile-time configuration +//! +//! This library requires some compile-time configuration file to be included to work +//! properly. You can see an example version of the file for the workspace +//! [here](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust/src/branch/main/examples/autoconfig.rs). +//! The user has to provide the path to a directory containing this `autoconfig.rs` file using the +//! `CSP_CONFIG_DIR` environmental variable. #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] @@ -214,6 +230,116 @@ pub struct csp_conn_s { pub rdp: csp_rdp_t, } +#[doc = " Interface Tx function.\n\n @return #CSP_ERR_NONE on success, otherwise an error code."] +pub type nexthop_t = ::core::option::Option< + unsafe extern "C" fn( + iface: *mut csp_iface_t, + via: u16, + packet: *mut csp_packet_t, + from_me: ::core::ffi::c_int, + ) -> ::core::ffi::c_int, +>; + +#[doc = " This struct is referenced in documentation.\n Update doc when you change this."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct csp_iface_s { + #[doc = "< Host address on this subnet"] + pub addr: u16, + #[doc = "< Subnet mask"] + pub netmask: u16, + #[doc = "< Name, max compare length is #CSP_IFLIST_NAME_MAX"] + pub name: *const ::core::ffi::c_char, + #[doc = "< Interface data, only known/used by the interface layer, e.g. state information."] + pub interface_data: *mut ::core::ffi::c_void, + #[doc = "< Driver data, only known/used by the driver layer, e.g. device/channel references."] + pub driver_data: *mut ::core::ffi::c_void, + #[doc = "< Next hop (Tx) function"] + pub nexthop: nexthop_t, + #[doc = "< Set default IF flag (CSP supports multiple defaults)"] + pub is_default: u8, + #[doc = "< Successfully transmitted packets"] + pub tx: u32, + #[doc = "< Successfully received packets"] + pub rx: u32, + #[doc = "< Transmit errors (packets)"] + pub tx_error: u32, + #[doc = "< Receive errors, e.g. too large message"] + pub rx_error: u32, + #[doc = "< Dropped packets"] + pub drop: u32, + #[doc = "< Authentication errors (packets)"] + pub autherr: u32, + #[doc = "< Frame format errors (packets)"] + pub frame: u32, + #[doc = "< Transmitted bytes"] + pub txbytes: u32, + #[doc = "< Received bytes"] + pub rxbytes: u32, + #[doc = "< Interrupts"] + pub irq: u32, + pub next: *mut csp_iface_s, +} + +impl Default for csp_iface_s { + fn default() -> Self { + Self { + addr: Default::default(), + netmask: Default::default(), + name: core::ptr::null(), + interface_data: core::ptr::null_mut(), + driver_data: core::ptr::null_mut(), + nexthop: None, + is_default: Default::default(), + tx: Default::default(), + rx: Default::default(), + tx_error: Default::default(), + rx_error: Default::default(), + drop: Default::default(), + autherr: Default::default(), + frame: Default::default(), + txbytes: Default::default(), + rxbytes: Default::default(), + irq: Default::default(), + next: core::ptr::null_mut(), + } + } +} + +#[doc = " Forward declaration of CSP interface, see #csp_iface_s for details."] +pub type csp_iface_t = csp_iface_s; + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct csp_if_udp_conf_t { + pub host: *mut ::core::ffi::c_char, + pub lport: ::core::ffi::c_int, + pub rport: ::core::ffi::c_int, + pub server_handle: libc::pthread_t, + pub peer_addr: libc::sockaddr_in, + pub sockfd: ::core::ffi::c_int, +} + +impl Default for csp_if_udp_conf_t { + fn default() -> Self { + Self { + host: core::ptr::null_mut(), + lport: Default::default(), + rport: Default::default(), + server_handle: Default::default(), + peer_addr: libc::sockaddr_in { + sin_family: Default::default(), + sin_port: Default::default(), + sin_addr: libc::in_addr { + s_addr: Default::default(), + }, + sin_zero: Default::default(), + }, + sockfd: Default::default(), + } + } +} + extern "C" { #[doc = " Error counters"] pub static mut csp_dbg_buffer_out: u8; @@ -286,6 +412,36 @@ extern "C" { opts: u8, ) -> ::core::ffi::c_int; + #[doc = " Send a single ping/echo packet without waiting for reply.\n Payload is 1 byte.\n\n @param[in] node address of subsystem."] + pub fn csp_ping_noreply(node: u16); + + #[doc = " Request process list.\n\n .. note:: This is currently only supported on FreeRTOS systems.\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for replies. The function will not return until the timeout occurrs."] + pub fn csp_ps(node: u16, timeout: u32); + + #[doc = " Request free memory.\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for reply.\n @param[out] size free memory on subsystem.\n @return #CSP_ERR_NONE on success, otherwise an error code."] + pub fn csp_get_memfree(node: u16, timeout: u32, size: *mut u32) -> ::core::ffi::c_int; + + #[doc = " Request free memory and print to stdout.\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for reply."] + pub fn csp_memfree(node: u16, timeout: u32); + + #[doc = " Request free buffers.\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for reply.\n @param[out] size free buffers.\n @return #CSP_ERR_NONE on success, otherwise an error code."] + pub fn csp_get_buf_free(node: u16, timeout: u32, size: *mut u32) -> ::core::ffi::c_int; + + #[doc = " Request free buffers and print to stdout.\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for reply."] + pub fn csp_buf_free(node: u16, timeout: u32); + + #[doc = " Reboot subsystem.\n If handled by the standard CSP service handler, the reboot handler set by csp_sys_set_reboot() on the subsystem, will be invoked.\n\n @param[in] node address of subsystem.\n"] + pub fn csp_reboot(node: u16); + + #[doc = " Shutdown subsystem.\n If handled by the standard CSP service handler, the shutdown handler set by csp_sys_set_shutdown() on the subsystem, will be invoked.\n\n @param[in] node address of subsystem.\n"] + pub fn csp_shutdown(node: u16); + + #[doc = " Request uptime and print to stdout.\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for reply.\n"] + pub fn csp_uptime(node: u16, timeout: u32); + + #[doc = " Request uptime\n\n @param[in] node address of subsystem.\n @param[in] timeout timeout in mS to wait for reply.\n @param[out] uptime uptime in seconds.\n @return #CSP_ERR_NONE on success, otherwise an error code."] + pub fn csp_get_uptime(node: u16, timeout: u32, uptime: *mut u32) -> ::core::ffi::c_int; + #[doc = " Perform an entire request & reply transaction on an existing connection.\n Send \\a outbuf, wait for reply and copy reply to \\a inbuf.\n\n @param[in] conn connection\n @param[in] timeout timeout in mS to wait for a reply\n @param[in] outbuf outgoing data (request)\n @param[in] outlen length of data in \\a outbuf (request)\n @param[out] inbuf user provided buffer for receiving data (reply)\n @param[in] inlen length of expected reply, -1 for unknown size (inbuf MUST be large enough), 0 for no reply.\n @return 1 or reply size on success, 0 on failure (error, incoming length does not match, timeout)"] pub fn csp_transaction_persistent( conn: *mut csp_conn_t, @@ -296,9 +452,6 @@ extern "C" { inlen: ::core::ffi::c_int, ) -> ::core::ffi::c_int; - #[doc = " Reboot subsystem.\n If handled by the standard CSP service handler, the reboot handler set by csp_sys_set_reboot() on the subsystem, will be invoked.\n\n @param[in] node address of subsystem.\n"] - pub fn csp_reboot(node: u16); - #[doc = " Establish outgoing connection.\n The call will return immediately, unless it is a RDP connection (#CSP_O_RDP) in which case it will wait until the other\n end acknowleges the connection (timeout is determined by the current connection timeout set by csp_rdp_set_opt()).\n\n @param[in] prio priority, see #csp_prio_t\n @param[in] dst Destination address\n @param[in] dst_port Destination port\n @param[in] timeout unused.\n @param[in] opts connection options, see @ref CSP_CONNECTION_OPTIONS.\n @return Established connection or NULL on failure (no free connections, timeout)."] pub fn csp_connect( prio: u8, @@ -308,8 +461,19 @@ extern "C" { opts: u32, ) -> *mut csp_conn_t; + #[doc = " Close a socket, freeing it's RX queue and unbinding it from the associated\n port.\n\n @param[in] sock Socket\n @return #CSP_ERR_NONE on success, otherwise an error code."] + pub fn csp_socket_close(sock: *mut csp_socket_t) -> ::core::ffi::c_int; + #[doc = " Return destination port of connection.\n\n @param[in] conn connection\n @return destination port of an incoming connection"] pub fn csp_conn_dport(conn: *const csp_conn_t) -> ::core::ffi::c_int; + #[doc = " Return source port of connection.\n\n @param[in] conn connection\n @return source port of an incoming connection"] + pub fn csp_conn_sport(conn: *const csp_conn_t) -> ::core::ffi::c_int; + #[doc = " Return destination address of connection.\n\n @param[in] conn connection\n @return destination address of an incoming connection"] + pub fn csp_conn_dst(conn: *const csp_conn_t) -> ::core::ffi::c_int; + #[doc = " Return source address of connection.\n\n @param[in] conn connection\n @return source address of an incoming connection"] + pub fn csp_conn_src(conn: *const csp_conn_t) -> ::core::ffi::c_int; + #[doc = " Return flags of connection.\n\n @param[in] conn connection\n @return flags of an incoming connection, see @ref CSP_HEADER_FLAGS"] + pub fn csp_conn_flags(conn: *const csp_conn_t) -> ::core::ffi::c_int; #[doc = " Get free buffer from task context.\n\n @param[in] unused OBSOLETE ignored field, csp packets have a fixed size now\n @return Buffer pointer to #csp_packet_t or NULL if no buffers available"] pub fn csp_buffer_get(unused: usize) -> *mut csp_packet_t; @@ -319,154 +483,65 @@ extern "C" { #[doc = " Print connection table to stdout."] pub fn csp_conn_print_table(); - - pub fn csp_iflist_print(); - } -#[test] -fn bindgen_test_layout_csp_conn_s() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 280usize, - concat!("Size of: ", stringify!(csp_conn_s)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(csp_conn_s)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(state) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).idin) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(idin) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).idout) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(idout) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).sport_outgoing) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(sport_outgoing) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rx_queue) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rx_queue_static) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rx_queue_static_data) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, - 176usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(callback) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).dest_socket) as usize - ptr as usize }, - 184usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(dest_socket) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).timestamp) as usize - ptr as usize }, - 192usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(timestamp) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).opts) as usize - ptr as usize }, - 196usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(opts) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, - 200usize, - concat!( - "Offset of field: ", - stringify!(csp_conn_s), - "::", - stringify!(rdp) - ) - ); + +pub mod iflist { + use super::*; + + extern "C" { + #[doc = " Add interface to the list.\n\n @param[in] iface The interface must remain valid as long as the application is running.\n @return #CSP_ERR_NONE on success, otherwise an error code."] + pub fn csp_iflist_add(iface: *mut csp_iface_t) -> ::core::ffi::c_int; + + pub fn csp_iflist_print(); + + } +} + +pub mod udp { + use super::*; + + extern "C" { + + #[doc = " Setup UDP peer\n\n RX task:\n A server task will attempt at binding to ip 0.0.0.0 port 9600\n If this fails, it is because another udp server is already running.\n The server task will continue attemting the bind and will not exit before the application is closed.\n\n TX peer:\n Outgoing CSP packets will be transferred to the peer specified by the host argument"] + pub fn csp_if_udp_init(iface: *mut csp_iface_t, ifconf: *mut csp_if_udp_conf_t); + + } +} + +/// Hook module for CSP. +/// +/// You can override these methods by providing them with an implementation block in your +/// application for library with the function signature specified in this module. +pub mod hooks { + use super::*; + + extern "C" { + pub fn csp_output_hook( + idout: *mut csp_id_t, + packet: *mut csp_packet_t, + iface: *mut csp_iface_t, + via: u16, + from_me: ::core::ffi::c_int, + ); + pub fn csp_input_hook(iface: *mut csp_iface_t, packet: *mut csp_packet_t); + pub fn csp_reboot_hook(); + pub fn csp_shutdown_hook(); + pub fn csp_memfree_hook() -> u32; + pub fn csp_ps_hook(packet: *mut csp_packet_t) -> ::core::ffi::c_uint; + #[doc = " Implement these, if you use csp_if_tun"] + pub fn csp_crypto_decrypt( + ciphertext_in: *mut u8, + ciphertext_len: u8, + msg_out: *mut u8, + ) -> ::core::ffi::c_int; + pub fn csp_crypto_encrypt( + msg_begin: *mut u8, + msg_len: u8, + ciphertext_out: *mut u8, + ) -> ::core::ffi::c_int; + pub fn csp_clock_get_time(time: *mut csp_timestamp_t); + pub fn csp_clock_set_time(time: *const csp_timestamp_t) -> ::core::ffi::c_int; + } } #[cfg(test)] @@ -900,4 +975,423 @@ mod tests { ) ); } + + #[test] + fn bindgen_test_layout_csp_if_udp_conf_t() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(csp_if_udp_conf_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_if_udp_conf_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).host) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_if_udp_conf_t), + "::", + stringify!(host) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).lport) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_if_udp_conf_t), + "::", + stringify!(lport) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rport) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(csp_if_udp_conf_t), + "::", + stringify!(rport) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).server_handle) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_if_udp_conf_t), + "::", + stringify!(server_handle) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).peer_addr) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_if_udp_conf_t), + "::", + stringify!(peer_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sockfd) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_if_udp_conf_t), + "::", + stringify!(sockfd) + ) + ); + } + + #[test] + fn bindgen_test_layout_csp_conn_s() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 280usize, + concat!("Size of: ", stringify!(csp_conn_s)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_conn_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(state) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idin) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idin) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idout) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sport_outgoing) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(sport_outgoing) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static_data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, + 176usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(callback) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).dest_socket) as usize - ptr as usize }, + 184usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(dest_socket) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).timestamp) as usize - ptr as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(timestamp) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).opts) as usize - ptr as usize }, + 196usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(opts) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, + 200usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rdp) + ) + ); + } + + #[test] + fn bindgen_test_layout_csp_iface_s() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 96usize, + concat!("Size of: ", stringify!(csp_iface_s)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_iface_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).netmask) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(netmask) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(name) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).interface_data) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(interface_data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).driver_data) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(driver_data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).nexthop) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(nexthop) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).is_default) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(is_default) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tx) as usize - ptr as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(tx) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(rx) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tx_error) as usize - ptr as usize }, + 52usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(tx_error) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_error) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(rx_error) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).drop) as usize - ptr as usize }, + 60usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(drop) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).autherr) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(autherr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).frame) as usize - ptr as usize }, + 68usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(frame) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).txbytes) as usize - ptr as usize }, + 72usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(txbytes) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rxbytes) as usize - ptr as usize }, + 76usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(rxbytes) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).irq) as usize - ptr as usize }, + 80usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(irq) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, + 88usize, + concat!( + "Offset of field: ", + stringify!(csp_iface_s), + "::", + stringify!(next) + ) + ); + } } diff --git a/libcsp/README.md b/libcsp/README.md index dc71e2c..feaa517 100644 --- a/libcsp/README.md +++ b/libcsp/README.md @@ -2,20 +2,10 @@ libcsp-rust ======== This crate provides a (mostly) safe and ergonomic Rust API for the -[`libcsp` library](https://github.com/libcsp/libcsp) on top of the `libcsp-sys` -crate. You can find some more high-level information and examples in the +[`libcsp` library](https://github.com/libcsp/libcsp) on top of the +[`libcsp-sys`](https://crates.io/crates/libcsp-sys) crate. + +You can find some more high-level information and examples in the [main repository](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust). The API documentation should provide all additional information required to use this library. - -## Compile-time configuration of the `libcsp-rust` library - -The `libcsp-rust` library requires some compile-time configuration file to be included to work -properly. You can see an example version of the file for the workspace -[here](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust/src/branch/main/examples/autoconfig.rs). -The user has to provide the path to a directory containing this `autoconfig.rs` file using the -`CSP_CONFIG_DIR` environmental variable. - -It is recommended to read the [main workspace README](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust) -for more information to make the generation and specification of this auto-configuration file -as conveniently and easy as possible. diff --git a/libcsp/src/lib.rs b/libcsp/src/lib.rs index dd4dd81..1399aa0 100644 --- a/libcsp/src/lib.rs +++ b/libcsp/src/lib.rs @@ -1,5 +1,10 @@ +//! This crate provides a (mostly) safe and ergonomic Rust API for the +//! [`libcsp` C library](https://github.com/libcsp/libcsp) on top of the +//! [`libcsp-sys`](https://crates.io/crates/libcsp-sys) crate. +//! +//! You can find some more high-level information and examples in the +//! [main repository](https://egit.irs.uni-stuttgart.de/rust/libcsp-rust). #![no_std] - #[cfg(feature = "alloc")] extern crate alloc; #[cfg(any(feature = "std", test))] @@ -11,7 +16,7 @@ use num_enum::{IntoPrimitive, TryFromPrimitive}; use bitflags::bitflags; use ffi::{csp_conn_s, csp_packet_s, csp_socket_s}; -use libcsp_sys as ffi; +pub use libcsp_sys as ffi; #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum ReservedPort { @@ -291,6 +296,18 @@ pub fn csp_route_work() -> Result<(), CspError> { #[derive(Debug, Copy, Clone)] pub struct CspConnRef(*mut csp_conn_s); +impl CspConnRef { + pub fn inner(&mut self) -> Option<&csp_conn_s> { + // SAFETY: Raw pointer access, we return [None] if the pointers is NULL. + unsafe { self.0.as_ref() } + } + + pub fn inner_mut(&mut self) -> Option<&mut csp_conn_s> { + // SAFETY: Raw pointer access, we return [None] if the pointers is NULL. + unsafe { self.0.as_mut() } + } +} + pub struct CspConnGuard(pub CspConnRef); impl Drop for CspConnGuard { @@ -311,6 +328,57 @@ impl AsMut for CspConnGuard { } } +#[derive(Default)] +pub struct CspInterface(pub ffi::csp_iface_t); + +impl CspInterface { + pub fn new(host_addr: u16, is_default: bool) -> Self { + Self(ffi::csp_iface_t { + addr: host_addr, + netmask: Default::default(), + name: core::ptr::null(), + interface_data: core::ptr::null_mut(), + driver_data: core::ptr::null_mut(), + nexthop: None, + is_default: is_default as u8, + tx: Default::default(), + rx: Default::default(), + tx_error: Default::default(), + rx_error: Default::default(), + drop: Default::default(), + autherr: Default::default(), + frame: Default::default(), + txbytes: Default::default(), + rxbytes: Default::default(), + irq: Default::default(), + next: core::ptr::null_mut(), + }) + } +} + +#[derive(Default)] +pub struct CspUdpConf(pub ffi::csp_if_udp_conf_t); + +impl CspUdpConf { + pub fn new(addr: &'static str, lport: u16, rport: u16) -> Self { + Self(ffi::csp_if_udp_conf_t { + host: addr.as_ptr() as *mut i8, + lport: lport.into(), + rport: rport.into(), + server_handle: Default::default(), + peer_addr: libc::sockaddr_in { + sin_family: Default::default(), + sin_port: Default::default(), + sin_addr: libc::in_addr { + s_addr: Default::default(), + }, + sin_zero: Default::default(), + }, + sockfd: Default::default(), + }) + } +} + pub fn csp_accept_guarded(socket: &mut CspSocket, timeout: Duration) -> Option { Some(CspConnGuard(csp_accept(socket, timeout)?)) } @@ -371,6 +439,41 @@ pub fn csp_conn_dport(conn: &CspConnRef) -> i32 { unsafe { ffi::csp_conn_dport(conn.0) } } +/// Rust wrapper for [ffi::csp_conn_sport]. +pub fn csp_conn_sport(conn: &CspConnRef) -> i32 { + // SAFETY: FFI call. + unsafe { ffi::csp_conn_sport(conn.0) } +} + +/// Rust wrapper for [ffi::csp_conn_dst]. +pub fn csp_conn_dst(conn: &CspConnRef) -> i32 { + // SAFETY: FFI call. + unsafe { ffi::csp_conn_dst(conn.0) } +} + +/// Rust wrapper for [ffi::csp_conn_src]. +pub fn csp_conn_src(conn: &CspConnRef) -> i32 { + // SAFETY: FFI call. + unsafe { ffi::csp_conn_src(conn.0) } +} + +/// Rust wrapper for [ffi::csp_conn_src]. +pub fn csp_conn_flags(conn: &CspConnRef) -> i32 { + // SAFETY: FFI call. + unsafe { ffi::csp_conn_flags(conn.0) } +} + +/// Rust wrapper for [ffi::csp_conn_src] which also tries to convert the options to +/// a [ConnectOpts] bitfield. +pub fn csp_conn_flags_typed(conn: &CspConnRef) -> Option { + let flags_raw = csp_conn_flags(conn); + if flags_raw < 0 { + return None; + } + // SAFETY: FFI call. + ConnectOpts::from_bits(flags_raw as u32) +} + pub fn csp_service_handler(packet: CspPacketRef) { // SAFETY: FFI call. unsafe { ffi::csp_service_handler(&mut *packet.0) } @@ -482,12 +585,6 @@ pub fn csp_conn_print_table() { unsafe { ffi::csp_conn_print_table() } } -/// Rust wrapper for [ffi::csp_iflist_print]. -pub fn csp_iflist_print() { - // SAFETY: FFI call. - unsafe { ffi::csp_iflist_print() } -} - /// Rust wrapper for [ffi::csp_buffer_free]. pub fn csp_buffer_free(packet: impl Into) { // SAFETY: FFI call and the Rust type system actually ensure the correct type @@ -557,3 +654,49 @@ pub fn csp_transaction_w_opts( ) } } + +/// Calls [csp_transaction_w_opts] with [ConnectOpts::NONE]. +pub fn csp_transaction( + prio: MsgPriority, + dst: u16, + dst_port: u8, + timeout: Duration, + out_data: &[u8], + in_data: &mut [u8], + in_len: Option, +) -> i32 { + csp_transaction_w_opts( + prio, + dst, + dst_port, + timeout, + out_data, + in_data, + in_len, + ConnectOpts::NONE, + ) +} + +pub mod udp { + use super::*; + + /// Rust wrapper for [ffi::udp::csp_if_udp_init]. + pub fn csp_if_udp_init(iface: &mut CspInterface, ifconf: &mut CspUdpConf) { + unsafe { ffi::udp::csp_if_udp_init(&mut iface.0, &mut ifconf.0) } + } +} + +pub mod iflist { + use super::*; + + /// Rust wrapper for [ffi::iflist::csp_iflist_print]. + pub fn csp_iflist_print() { + // SAFETY: FFI call. + unsafe { ffi::iflist::csp_iflist_print() } + } + + /// Rust wrapper for [ffi::iflist::csp_iflist_add]. + pub fn csp_iflist_add(iface: &mut CspInterface) -> i32 { + unsafe { ffi::iflist::csp_iflist_add(&mut iface.0) } + } +}