diff options
author | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-09-09 00:16:52 +0200 |
---|---|---|
committer | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-09-09 00:56:38 +0200 |
commit | b14ea37486ef1d515b852469f9a0f699c8790c7d (patch) | |
tree | 98a15c777ed4382650532dc3d56957c8ea38d6d1 | |
parent | f7c21b467a1b4661b1ec87c74c5da7483a14158b (diff) | |
download | nrf-softdevice-b14ea37486ef1d515b852469f9a0f699c8790c7d.zip |
Fix UB regarding bindgen unions and dynamically-sized array members.
-rw-r--r-- | nrf-softdevice-gen/src/main.rs | 7 | ||||
-rw-r--r-- | nrf-softdevice-s112/src/bindings.rs | 235 | ||||
-rw-r--r-- | nrf-softdevice-s113/src/bindings.rs | 237 | ||||
-rw-r--r-- | nrf-softdevice-s122/src/bindings.rs | 235 | ||||
-rw-r--r-- | nrf-softdevice-s132/src/bindings.rs | 237 | ||||
-rw-r--r-- | nrf-softdevice-s140/src/bindings.rs | 237 | ||||
-rw-r--r-- | nrf-softdevice-s140/src/test.h | 0 | ||||
-rw-r--r-- | nrf-softdevice/src/ble/gap.rs | 129 | ||||
-rw-r--r-- | nrf-softdevice/src/ble/gatt_client.rs | 79 | ||||
-rw-r--r-- | nrf-softdevice/src/ble/gatt_server.rs | 46 | ||||
-rw-r--r-- | nrf-softdevice/src/ble/l2cap.rs | 35 | ||||
-rw-r--r-- | nrf-softdevice/src/ble/mod.rs | 138 | ||||
-rw-r--r-- | nrf-softdevice/src/util/mod.rs | 46 |
13 files changed, 1104 insertions, 557 deletions
diff --git a/nrf-softdevice-gen/src/main.rs b/nrf-softdevice-gen/src/main.rs index fd30102..4ee2bf0 100644 --- a/nrf-softdevice-gen/src/main.rs +++ b/nrf-softdevice-gen/src/main.rs @@ -85,6 +85,13 @@ fn main() { } gen_bindings(&tmp_dir, &src_dir, &tmp_bindings_path, |data| { + // Change all "dynamically-sized" arrays from length 1 to length 0. + // This avoids UB when creating Rust references to structs when the length is 0. + // + // We can't use a "real" flexible array ([] instead of [0]) because + // they're used inside enums :( + let data = data.replace("[1];", "[0];"); + let re = Regex::new(r"SVCALL\((?P<svc>[A-Za-z0-9_]+),\s*(?P<ret>[A-Za-z0-9_]+),\s*(?P<name>[A-Za-z0-9_]+)\((?P<args>.*)\)\);").unwrap(); re.replace_all(&data, "$ret $name($args);").into() }); diff --git a/nrf-softdevice-s112/src/bindings.rs b/nrf-softdevice-s112/src/bindings.rs index b65d3a6..d1d4371 100644 --- a/nrf-softdevice-s112/src/bindings.rs +++ b/nrf-softdevice-s112/src/bindings.rs @@ -209,6 +209,79 @@ where } } } +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::core::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::core::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::core::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} +impl<T> ::core::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::core::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::core::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::core::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::core::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {} pub const NRF_ERROR_BASE_NUM: u32 = 0; pub const NRF_ERROR_SDM_BASE_NUM: u32 = 4096; pub const NRF_ERROR_SOC_BASE_NUM: u32 = 8192; @@ -9401,19 +9474,19 @@ fn bindgen_test_layout_ble_gattc_attr_info128_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_prim_srvc_disc_rsp_t { #[doc = "< Service count."] pub count: u16, #[doc = "< Service data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub services: [ble_gattc_service_t; 1usize], + pub services: __IncompleteArrayField<ble_gattc_service_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_prim_srvc_disc_rsp_t>(), - 10usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_prim_srvc_disc_rsp_t)) ); assert_eq!( @@ -9453,19 +9526,19 @@ fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_rel_disc_rsp_t { #[doc = "< Include count."] pub count: u16, #[doc = "< Include data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub includes: [ble_gattc_include_t; 1usize], + pub includes: __IncompleteArrayField<ble_gattc_include_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_rel_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_rel_disc_rsp_t)) ); assert_eq!( @@ -9500,19 +9573,19 @@ fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_disc_rsp_t { #[doc = "< Characteristic count."] pub count: u16, #[doc = "< Characteristic data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub chars: [ble_gattc_char_t; 1usize], + pub chars: __IncompleteArrayField<ble_gattc_char_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_disc_rsp_t)) ); assert_eq!( @@ -9547,19 +9620,19 @@ fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_desc_disc_rsp_t { #[doc = "< Descriptor count."] pub count: u16, #[doc = "< Descriptor data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub descs: [ble_gattc_desc_t; 1usize], + pub descs: __IncompleteArrayField<ble_gattc_desc_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_desc_disc_rsp_t>(), - 8usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_desc_disc_rsp_t)) ); assert_eq!( @@ -9594,7 +9667,6 @@ fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_attr_info_disc_rsp_t { #[doc = "< Attribute count."] pub count: u16, @@ -9604,23 +9676,22 @@ pub struct ble_gattc_evt_attr_info_disc_rsp_t { pub info: ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { +pub struct ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { #[doc = "< Attribute information for 16-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info16: [ble_gattc_attr_info16_t; 1usize], + pub attr_info16: __BindgenUnionField<[ble_gattc_attr_info16_t; 0usize]>, #[doc = "< Attribute information for 128-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info128: [ble_gattc_attr_info128_t; 1usize], - _bindgen_union_align: [u16; 9usize], + pub attr_info128: __BindgenUnionField<[ble_gattc_attr_info128_t; 0usize]>, + pub bindgen_union_field: [u16; 0usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1>(), - 18usize, + 0usize, concat!( "Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1) @@ -9665,7 +9736,7 @@ fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t>(), - 22usize, + 4usize, concat!("Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t)) ); assert_eq!( @@ -9764,7 +9835,7 @@ fn bindgen_test_layout_ble_gattc_handle_value_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value Pair Count."] pub count: u16, @@ -9773,13 +9844,13 @@ pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value(s) list. To iterate through the list use @ref sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub handle_value: [u8; 1usize], + pub handle_value: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_val_by_uuid_read_rsp_t>(), - 6usize, + 4usize, concat!( "Size of: ", stringify!(ble_gattc_evt_char_val_by_uuid_read_rsp_t) @@ -9835,7 +9906,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_read_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -9845,13 +9916,13 @@ pub struct ble_gattc_evt_read_rsp_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_read_rsp_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_read_rsp_t)) ); assert_eq!( @@ -9906,19 +9977,19 @@ fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_vals_read_rsp_t { #[doc = "< Concatenated Attribute values length."] pub len: u16, #[doc = "< Attribute values. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub values: [u8; 1usize], + pub values: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_vals_read_rsp_t>(), - 4usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_vals_read_rsp_t)) ); assert_eq!( @@ -9957,7 +10028,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_write_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -9969,13 +10040,13 @@ pub struct ble_gattc_evt_write_rsp_t { pub len: u16, #[doc = "< Data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_write_rsp_t>(), - 10usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_write_rsp_t)) ); assert_eq!( @@ -10042,7 +10113,7 @@ fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_HVX."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_hvx_t { #[doc = "< Handle to which the HVx operation applies."] pub handle: u16, @@ -10052,13 +10123,13 @@ pub struct ble_gattc_evt_hvx_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_hvx_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_hvx_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_hvx_t)) ); assert_eq!( @@ -10214,7 +10285,6 @@ fn bindgen_test_layout_ble_gattc_evt_write_cmd_tx_complete_t() { } #[doc = "@brief GATTC event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_t { #[doc = "< Connection Handle on which event occurred."] pub conn_handle: u16, @@ -10226,41 +10296,40 @@ pub struct ble_gattc_evt_t { pub params: ble_gattc_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_t__bindgen_ty_1 { +pub struct ble_gattc_evt_t__bindgen_ty_1 { #[doc = "< Primary Service Discovery Response Event Parameters."] - pub prim_srvc_disc_rsp: ble_gattc_evt_prim_srvc_disc_rsp_t, + pub prim_srvc_disc_rsp: __BindgenUnionField<ble_gattc_evt_prim_srvc_disc_rsp_t>, #[doc = "< Relationship Discovery Response Event Parameters."] - pub rel_disc_rsp: ble_gattc_evt_rel_disc_rsp_t, + pub rel_disc_rsp: __BindgenUnionField<ble_gattc_evt_rel_disc_rsp_t>, #[doc = "< Characteristic Discovery Response Event Parameters."] - pub char_disc_rsp: ble_gattc_evt_char_disc_rsp_t, + pub char_disc_rsp: __BindgenUnionField<ble_gattc_evt_char_disc_rsp_t>, #[doc = "< Descriptor Discovery Response Event Parameters."] - pub desc_disc_rsp: ble_gattc_evt_desc_disc_rsp_t, + pub desc_disc_rsp: __BindgenUnionField<ble_gattc_evt_desc_disc_rsp_t>, #[doc = "< Characteristic Value Read by UUID Response Event Parameters."] - pub char_val_by_uuid_read_rsp: ble_gattc_evt_char_val_by_uuid_read_rsp_t, + pub char_val_by_uuid_read_rsp: __BindgenUnionField<ble_gattc_evt_char_val_by_uuid_read_rsp_t>, #[doc = "< Read Response Event Parameters."] - pub read_rsp: ble_gattc_evt_read_rsp_t, + pub read_rsp: __BindgenUnionField<ble_gattc_evt_read_rsp_t>, #[doc = "< Characteristic Values Read Response Event Parameters."] - pub char_vals_read_rsp: ble_gattc_evt_char_vals_read_rsp_t, + pub char_vals_read_rsp: __BindgenUnionField<ble_gattc_evt_char_vals_read_rsp_t>, #[doc = "< Write Response Event Parameters."] - pub write_rsp: ble_gattc_evt_write_rsp_t, + pub write_rsp: __BindgenUnionField<ble_gattc_evt_write_rsp_t>, #[doc = "< Handle Value Notification/Indication Event Parameters."] - pub hvx: ble_gattc_evt_hvx_t, + pub hvx: __BindgenUnionField<ble_gattc_evt_hvx_t>, #[doc = "< Exchange MTU Response Event Parameters."] - pub exchange_mtu_rsp: ble_gattc_evt_exchange_mtu_rsp_t, + pub exchange_mtu_rsp: __BindgenUnionField<ble_gattc_evt_exchange_mtu_rsp_t>, #[doc = "< Timeout Event Parameters."] - pub timeout: ble_gattc_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gattc_evt_timeout_t>, #[doc = "< Attribute Information Discovery Event Parameters."] - pub attr_info_disc_rsp: ble_gattc_evt_attr_info_disc_rsp_t, + pub attr_info_disc_rsp: __BindgenUnionField<ble_gattc_evt_attr_info_disc_rsp_t>, #[doc = "< Write without Response transmission complete Event Parameters."] - pub write_cmd_tx_complete: ble_gattc_evt_write_cmd_tx_complete_t, - _bindgen_union_align: [u16; 11usize], + pub write_cmd_tx_complete: __BindgenUnionField<ble_gattc_evt_write_cmd_tx_complete_t>, + pub bindgen_union_field: [u16; 4usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t__bindgen_ty_1>(), - 22usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -10439,7 +10508,7 @@ fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t>(), - 28usize, + 14usize, concat!("Size of: ", stringify!(ble_gattc_evt_t)) ); assert_eq!( @@ -12003,7 +12072,7 @@ fn bindgen_test_layout_ble_gatts_cfg_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_WRITE."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gatts_evt_write_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -12019,13 +12088,13 @@ pub struct ble_gatts_evt_write_t { pub len: u16, #[doc = "< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gatts_evt_write_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_write_t>(), - 14usize, + 12usize, concat!("Size of: ", stringify!(ble_gatts_evt_write_t)) ); assert_eq!( @@ -12162,7 +12231,6 @@ fn bindgen_test_layout_ble_gatts_evt_read_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_rw_authorize_request_t { #[doc = "< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES."] pub type_: u8, @@ -12170,19 +12238,18 @@ pub struct ble_gatts_evt_rw_authorize_request_t { pub request: ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { +pub struct ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { #[doc = "< Attribute Read Parameters."] - pub read: ble_gatts_evt_read_t, + pub read: __BindgenUnionField<ble_gatts_evt_read_t>, #[doc = "< Attribute Write Parameters."] - pub write: ble_gatts_evt_write_t, - _bindgen_union_align: [u16; 7usize], + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, + pub bindgen_union_field: [u16; 6usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1>(), - 14usize, + 12usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1) @@ -12227,7 +12294,7 @@ fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t>(), - 16usize, + 14usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t) @@ -12436,7 +12503,6 @@ fn bindgen_test_layout_ble_gatts_evt_hvn_tx_complete_t() { } #[doc = "@brief GATTS event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_t { #[doc = "< Connection Handle on which the event occurred."] pub conn_handle: u16, @@ -12444,29 +12510,28 @@ pub struct ble_gatts_evt_t { pub params: ble_gatts_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_t__bindgen_ty_1 { +pub struct ble_gatts_evt_t__bindgen_ty_1 { #[doc = "< Write Event Parameters."] - pub write: ble_gatts_evt_write_t, + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, #[doc = "< Read or Write Authorize Request Parameters."] - pub authorize_request: ble_gatts_evt_rw_authorize_request_t, + pub authorize_request: __BindgenUnionField<ble_gatts_evt_rw_authorize_request_t>, #[doc = "< System attributes missing."] - pub sys_attr_missing: ble_gatts_evt_sys_attr_missing_t, + pub sys_attr_missing: __BindgenUnionField<ble_gatts_evt_sys_attr_missing_t>, #[doc = "< Handle Value Confirmation Event Parameters."] - pub hvc: ble_gatts_evt_hvc_t, + pub hvc: __BindgenUnionField<ble_gatts_evt_hvc_t>, #[doc = "< Exchange MTU Request Event Parameters."] - pub exchange_mtu_request: ble_gatts_evt_exchange_mtu_request_t, + pub exchange_mtu_request: __BindgenUnionField<ble_gatts_evt_exchange_mtu_request_t>, #[doc = "< Timeout Event."] - pub timeout: ble_gatts_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gatts_evt_timeout_t>, #[doc = "< Handle Value Notification transmission complete Event Parameters."] - pub hvn_tx_complete: ble_gatts_evt_hvn_tx_complete_t, - _bindgen_union_align: [u16; 8usize], + pub hvn_tx_complete: __BindgenUnionField<ble_gatts_evt_hvn_tx_complete_t>, + pub bindgen_union_field: [u16; 7usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t__bindgen_ty_1>(), - 16usize, + 14usize, concat!("Size of: ", stringify!(ble_gatts_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -12567,7 +12632,7 @@ fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t>(), - 18usize, + 16usize, concat!("Size of: ", stringify!(ble_gatts_evt_t)) ); assert_eq!( @@ -13525,7 +13590,6 @@ fn bindgen_test_layout_ble_evt_hdr_t() { } #[doc = "@brief Common BLE Event type, wrapping the module specific event reports."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_evt_t { #[doc = "< Event header."] pub header: ble_evt_hdr_t, @@ -13533,17 +13597,16 @@ pub struct ble_evt_t { pub evt: ble_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_evt_t__bindgen_ty_1 { +pub struct ble_evt_t__bindgen_ty_1 { #[doc = "< Common Event, evt_id in BLE_EVT_* series."] - pub common_evt: ble_common_evt_t, + pub common_evt: __BindgenUnionField<ble_common_evt_t>, #[doc = "< GAP originated event, evt_id in BLE_GAP_EVT_* series."] - pub gap_evt: ble_gap_evt_t, + pub gap_evt: __BindgenUnionField<ble_gap_evt_t>, #[doc = "< GATT client originated event, evt_id in BLE_GATTC_EVT* series."] - pub gattc_evt: ble_gattc_evt_t, + pub gattc_evt: __BindgenUnionField<ble_gattc_evt_t>, #[doc = "< GATT server originated event, evt_id in BLE_GATTS_EVT* series."] - pub gatts_evt: ble_gatts_evt_t, - _bindgen_union_align: [u32; 10usize], + pub gatts_evt: __BindgenUnionField<ble_gatts_evt_t>, + pub bindgen_union_field: [u32; 10usize], } #[test] fn bindgen_test_layout_ble_evt_t__bindgen_ty_1() { diff --git a/nrf-softdevice-s113/src/bindings.rs b/nrf-softdevice-s113/src/bindings.rs index 289f9ee..111a1dd 100644 --- a/nrf-softdevice-s113/src/bindings.rs +++ b/nrf-softdevice-s113/src/bindings.rs @@ -209,6 +209,79 @@ where } } } +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::core::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::core::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::core::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} +impl<T> ::core::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::core::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::core::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::core::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::core::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {} pub const NRF_ERROR_BASE_NUM: u32 = 0; pub const NRF_ERROR_SDM_BASE_NUM: u32 = 4096; pub const NRF_ERROR_SOC_BASE_NUM: u32 = 8192; @@ -11054,19 +11127,19 @@ fn bindgen_test_layout_ble_gattc_attr_info128_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_prim_srvc_disc_rsp_t { #[doc = "< Service count."] pub count: u16, #[doc = "< Service data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub services: [ble_gattc_service_t; 1usize], + pub services: __IncompleteArrayField<ble_gattc_service_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_prim_srvc_disc_rsp_t>(), - 10usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_prim_srvc_disc_rsp_t)) ); assert_eq!( @@ -11106,19 +11179,19 @@ fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_rel_disc_rsp_t { #[doc = "< Include count."] pub count: u16, #[doc = "< Include data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub includes: [ble_gattc_include_t; 1usize], + pub includes: __IncompleteArrayField<ble_gattc_include_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_rel_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_rel_disc_rsp_t)) ); assert_eq!( @@ -11153,19 +11226,19 @@ fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_disc_rsp_t { #[doc = "< Characteristic count."] pub count: u16, #[doc = "< Characteristic data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub chars: [ble_gattc_char_t; 1usize], + pub chars: __IncompleteArrayField<ble_gattc_char_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_disc_rsp_t)) ); assert_eq!( @@ -11200,19 +11273,19 @@ fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_desc_disc_rsp_t { #[doc = "< Descriptor count."] pub count: u16, #[doc = "< Descriptor data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub descs: [ble_gattc_desc_t; 1usize], + pub descs: __IncompleteArrayField<ble_gattc_desc_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_desc_disc_rsp_t>(), - 8usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_desc_disc_rsp_t)) ); assert_eq!( @@ -11247,7 +11320,6 @@ fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_attr_info_disc_rsp_t { #[doc = "< Attribute count."] pub count: u16, @@ -11257,23 +11329,22 @@ pub struct ble_gattc_evt_attr_info_disc_rsp_t { pub info: ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { +pub struct ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { #[doc = "< Attribute information for 16-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info16: [ble_gattc_attr_info16_t; 1usize], + pub attr_info16: __BindgenUnionField<[ble_gattc_attr_info16_t; 0usize]>, #[doc = "< Attribute information for 128-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info128: [ble_gattc_attr_info128_t; 1usize], - _bindgen_union_align: [u16; 9usize], + pub attr_info128: __BindgenUnionField<[ble_gattc_attr_info128_t; 0usize]>, + pub bindgen_union_field: [u16; 0usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1>(), - 18usize, + 0usize, concat!( "Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1) @@ -11318,7 +11389,7 @@ fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t>(), - 22usize, + 4usize, concat!("Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t)) ); assert_eq!( @@ -11417,7 +11488,7 @@ fn bindgen_test_layout_ble_gattc_handle_value_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value Pair Count."] pub count: u16, @@ -11426,13 +11497,13 @@ pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value(s) list. To iterate through the list use @ref sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub handle_value: [u8; 1usize], + pub handle_value: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_val_by_uuid_read_rsp_t>(), - 6usize, + 4usize, concat!( "Size of: ", stringify!(ble_gattc_evt_char_val_by_uuid_read_rsp_t) @@ -11488,7 +11559,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_read_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -11498,13 +11569,13 @@ pub struct ble_gattc_evt_read_rsp_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_read_rsp_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_read_rsp_t)) ); assert_eq!( @@ -11559,19 +11630,19 @@ fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_vals_read_rsp_t { #[doc = "< Concatenated Attribute values length."] pub len: u16, #[doc = "< Attribute values. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub values: [u8; 1usize], + pub values: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_vals_read_rsp_t>(), - 4usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_vals_read_rsp_t)) ); assert_eq!( @@ -11610,7 +11681,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_write_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -11622,13 +11693,13 @@ pub struct ble_gattc_evt_write_rsp_t { pub len: u16, #[doc = "< Data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_write_rsp_t>(), - 10usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_write_rsp_t)) ); assert_eq!( @@ -11695,7 +11766,7 @@ fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_HVX."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_hvx_t { #[doc = "< Handle to which the HVx operation applies."] pub handle: u16, @@ -11705,13 +11776,13 @@ pub struct ble_gattc_evt_hvx_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_hvx_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_hvx_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_hvx_t)) ); assert_eq!( @@ -11867,7 +11938,6 @@ fn bindgen_test_layout_ble_gattc_evt_write_cmd_tx_complete_t() { } #[doc = "@brief GATTC event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_t { #[doc = "< Connection Handle on which event occurred."] pub conn_handle: u16, @@ -11879,41 +11949,40 @@ pub struct ble_gattc_evt_t { pub params: ble_gattc_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_t__bindgen_ty_1 { +pub struct ble_gattc_evt_t__bindgen_ty_1 { #[doc = "< Primary Service Discovery Response Event Parameters."] - pub prim_srvc_disc_rsp: ble_gattc_evt_prim_srvc_disc_rsp_t, + pub prim_srvc_disc_rsp: __BindgenUnionField<ble_gattc_evt_prim_srvc_disc_rsp_t>, #[doc = "< Relationship Discovery Response Event Parameters."] - pub rel_disc_rsp: ble_gattc_evt_rel_disc_rsp_t, + pub rel_disc_rsp: __BindgenUnionField<ble_gattc_evt_rel_disc_rsp_t>, #[doc = "< Characteristic Discovery Response Event Parameters."] - pub char_disc_rsp: ble_gattc_evt_char_disc_rsp_t, + pub char_disc_rsp: __BindgenUnionField<ble_gattc_evt_char_disc_rsp_t>, #[doc = "< Descriptor Discovery Response Event Parameters."] - pub desc_disc_rsp: ble_gattc_evt_desc_disc_rsp_t, + pub desc_disc_rsp: __BindgenUnionField<ble_gattc_evt_desc_disc_rsp_t>, #[doc = "< Characteristic Value Read by UUID Response Event Parameters."] - pub char_val_by_uuid_read_rsp: ble_gattc_evt_char_val_by_uuid_read_rsp_t, + pub char_val_by_uuid_read_rsp: __BindgenUnionField<ble_gattc_evt_char_val_by_uuid_read_rsp_t>, #[doc = "< Read Response Event Parameters."] - pub read_rsp: ble_gattc_evt_read_rsp_t, + pub read_rsp: __BindgenUnionField<ble_gattc_evt_read_rsp_t>, #[doc = "< Characteristic Values Read Response Event Parameters."] - pub char_vals_read_rsp: ble_gattc_evt_char_vals_read_rsp_t, + pub char_vals_read_rsp: __BindgenUnionField<ble_gattc_evt_char_vals_read_rsp_t>, #[doc = "< Write Response Event Parameters."] - pub write_rsp: ble_gattc_evt_write_rsp_t, + pub write_rsp: __BindgenUnionField<ble_gattc_evt_write_rsp_t>, #[doc = "< Handle Value Notification/Indication Event Parameters."] - pub hvx: ble_gattc_evt_hvx_t, + pub hvx: __BindgenUnionField<ble_gattc_evt_hvx_t>, #[doc = "< Exchange MTU Response Event Parameters."] - pub exchange_mtu_rsp: ble_gattc_evt_exchange_mtu_rsp_t, + pub exchange_mtu_rsp: __BindgenUnionField<ble_gattc_evt_exchange_mtu_rsp_t>, #[doc = "< Timeout Event Parameters."] - pub timeout: ble_gattc_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gattc_evt_timeout_t>, #[doc = "< Attribute Information Discovery Event Parameters."] - pub attr_info_disc_rsp: ble_gattc_evt_attr_info_disc_rsp_t, + pub attr_info_disc_rsp: __BindgenUnionField<ble_gattc_evt_attr_info_disc_rsp_t>, #[doc = "< Write without Response transmission complete Event Parameters."] - pub write_cmd_tx_complete: ble_gattc_evt_write_cmd_tx_complete_t, - _bindgen_union_align: [u16; 11usize], + pub write_cmd_tx_complete: __BindgenUnionField<ble_gattc_evt_write_cmd_tx_complete_t>, + pub bindgen_union_field: [u16; 4usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t__bindgen_ty_1>(), - 22usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -12092,7 +12161,7 @@ fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t>(), - 28usize, + 14usize, concat!("Size of: ", stringify!(ble_gattc_evt_t)) ); assert_eq!( @@ -13656,7 +13725,7 @@ fn bindgen_test_layout_ble_gatts_cfg_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_WRITE."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gatts_evt_write_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -13672,13 +13741,13 @@ pub struct ble_gatts_evt_write_t { pub len: u16, #[doc = "< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gatts_evt_write_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_write_t>(), - 14usize, + 12usize, concat!("Size of: ", stringify!(ble_gatts_evt_write_t)) ); assert_eq!( @@ -13815,7 +13884,6 @@ fn bindgen_test_layout_ble_gatts_evt_read_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_rw_authorize_request_t { #[doc = "< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES."] pub type_: u8, @@ -13823,19 +13891,18 @@ pub struct ble_gatts_evt_rw_authorize_request_t { pub request: ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { +pub struct ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { #[doc = "< Attribute Read Parameters."] - pub read: ble_gatts_evt_read_t, + pub read: __BindgenUnionField<ble_gatts_evt_read_t>, #[doc = "< Attribute Write Parameters."] - pub write: ble_gatts_evt_write_t, - _bindgen_union_align: [u16; 7usize], + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, + pub bindgen_union_field: [u16; 6usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1>(), - 14usize, + 12usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1) @@ -13880,7 +13947,7 @@ fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t>(), - 16usize, + 14usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t) @@ -14089,7 +14156,6 @@ fn bindgen_test_layout_ble_gatts_evt_hvn_tx_complete_t() { } #[doc = "@brief GATTS event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_t { #[doc = "< Connection Handle on which the event occurred."] pub conn_handle: u16, @@ -14097,29 +14163,28 @@ pub struct ble_gatts_evt_t { pub params: ble_gatts_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_t__bindgen_ty_1 { +pub struct ble_gatts_evt_t__bindgen_ty_1 { #[doc = "< Write Event Parameters."] - pub write: ble_gatts_evt_write_t, + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, #[doc = "< Read or Write Authorize Request Parameters."] - pub authorize_request: ble_gatts_evt_rw_authorize_request_t, + pub authorize_request: __BindgenUnionField<ble_gatts_evt_rw_authorize_request_t>, #[doc = "< System attributes missing."] - pub sys_attr_missing: ble_gatts_evt_sys_attr_missing_t, + pub sys_attr_missing: __BindgenUnionField<ble_gatts_evt_sys_attr_missing_t>, #[doc = "< Handle Value Confirmation Event Parameters."] - pub hvc: ble_gatts_evt_hvc_t, + pub hvc: __BindgenUnionField<ble_gatts_evt_hvc_t>, #[doc = "< Exchange MTU Request Event Parameters."] - pub exchange_mtu_request: ble_gatts_evt_exchange_mtu_request_t, + pub exchange_mtu_request: __BindgenUnionField<ble_gatts_evt_exchange_mtu_request_t>, #[doc = "< Timeout Event."] - pub timeout: ble_gatts_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gatts_evt_timeout_t>, #[doc = "< Handle Value Notification transmission complete Event Parameters."] - pub hvn_tx_complete: ble_gatts_evt_hvn_tx_complete_t, - _bindgen_union_align: [u16; 8usize], + pub hvn_tx_complete: __BindgenUnionField<ble_gatts_evt_hvn_tx_complete_t>, + pub bindgen_union_field: [u16; 7usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t__bindgen_ty_1>(), - 16usize, + 14usize, concat!("Size of: ", stringify!(ble_gatts_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -14220,7 +14285,7 @@ fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t>(), - 18usize, + 16usize, concat!("Size of: ", stringify!(ble_gatts_evt_t)) ); assert_eq!( @@ -15180,7 +15245,6 @@ fn bindgen_test_layout_ble_evt_hdr_t() { } #[doc = "@brief Common BLE Event type, wrapping the module specific event reports."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_evt_t { #[doc = "< Event header."] pub header: ble_evt_hdr_t, @@ -15188,19 +15252,18 @@ pub struct ble_evt_t { pub evt: ble_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_evt_t__bindgen_ty_1 { +pub struct ble_evt_t__bindgen_ty_1 { #[doc = "< Common Event, evt_id in BLE_EVT_* series."] - pub common_evt: ble_common_evt_t, + pub common_evt: __BindgenUnionField<ble_common_evt_t>, #[doc = "< GAP originated event, evt_id in BLE_GAP_EVT_* series."] - pub gap_evt: ble_gap_evt_t, + pub gap_evt: __BindgenUnionField<ble_gap_evt_t>, #[doc = "< GATT client originated event, evt_id in BLE_GATTC_EVT* series."] - pub gattc_evt: ble_gattc_evt_t, + pub gattc_evt: __BindgenUnionField<ble_gattc_evt_t>, #[doc = "< GATT server originated event, evt_id in BLE_GATTS_EVT* series."] - pub gatts_evt: ble_gatts_evt_t, + pub gatts_evt: __BindgenUnionField<ble_gatts_evt_t>, #[doc = "< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series."] - pub l2cap_evt: ble_l2cap_evt_t, - _bindgen_union_align: [u32; 10usize], + pub l2cap_evt: __BindgenUnionField<ble_l2cap_evt_t>, + pub bindgen_union_field: [u32; 10usize], } #[test] fn bindgen_test_layout_ble_evt_t__bindgen_ty_1() { diff --git a/nrf-softdevice-s122/src/bindings.rs b/nrf-softdevice-s122/src/bindings.rs index 9c950cf..5217b0f 100644 --- a/nrf-softdevice-s122/src/bindings.rs +++ b/nrf-softdevice-s122/src/bindings.rs @@ -209,6 +209,79 @@ where } } } +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::core::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::core::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::core::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} +impl<T> ::core::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::core::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::core::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::core::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::core::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {} pub const NRF_ERROR_BASE_NUM: u32 = 0; pub const NRF_ERROR_SDM_BASE_NUM: u32 = 4096; pub const NRF_ERROR_SOC_BASE_NUM: u32 = 8192; @@ -9983,19 +10056,19 @@ fn bindgen_test_layout_ble_gattc_attr_info128_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_prim_srvc_disc_rsp_t { #[doc = "< Service count."] pub count: u16, #[doc = "< Service data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub services: [ble_gattc_service_t; 1usize], + pub services: __IncompleteArrayField<ble_gattc_service_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_prim_srvc_disc_rsp_t>(), - 10usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_prim_srvc_disc_rsp_t)) ); assert_eq!( @@ -10035,19 +10108,19 @@ fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_rel_disc_rsp_t { #[doc = "< Include count."] pub count: u16, #[doc = "< Include data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub includes: [ble_gattc_include_t; 1usize], + pub includes: __IncompleteArrayField<ble_gattc_include_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_rel_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_rel_disc_rsp_t)) ); assert_eq!( @@ -10082,19 +10155,19 @@ fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_disc_rsp_t { #[doc = "< Characteristic count."] pub count: u16, #[doc = "< Characteristic data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub chars: [ble_gattc_char_t; 1usize], + pub chars: __IncompleteArrayField<ble_gattc_char_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_disc_rsp_t)) ); assert_eq!( @@ -10129,19 +10202,19 @@ fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_desc_disc_rsp_t { #[doc = "< Descriptor count."] pub count: u16, #[doc = "< Descriptor data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub descs: [ble_gattc_desc_t; 1usize], + pub descs: __IncompleteArrayField<ble_gattc_desc_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_desc_disc_rsp_t>(), - 8usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_desc_disc_rsp_t)) ); assert_eq!( @@ -10176,7 +10249,6 @@ fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_attr_info_disc_rsp_t { #[doc = "< Attribute count."] pub count: u16, @@ -10186,23 +10258,22 @@ pub struct ble_gattc_evt_attr_info_disc_rsp_t { pub info: ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { +pub struct ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { #[doc = "< Attribute information for 16-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info16: [ble_gattc_attr_info16_t; 1usize], + pub attr_info16: __BindgenUnionField<[ble_gattc_attr_info16_t; 0usize]>, #[doc = "< Attribute information for 128-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info128: [ble_gattc_attr_info128_t; 1usize], - _bindgen_union_align: [u16; 9usize], + pub attr_info128: __BindgenUnionField<[ble_gattc_attr_info128_t; 0usize]>, + pub bindgen_union_field: [u16; 0usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1>(), - 18usize, + 0usize, concat!( "Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1) @@ -10247,7 +10318,7 @@ fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t>(), - 22usize, + 4usize, concat!("Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t)) ); assert_eq!( @@ -10346,7 +10417,7 @@ fn bindgen_test_layout_ble_gattc_handle_value_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value Pair Count."] pub count: u16, @@ -10355,13 +10426,13 @@ pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value(s) list. To iterate through the list use @ref sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub handle_value: [u8; 1usize], + pub handle_value: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_val_by_uuid_read_rsp_t>(), - 6usize, + 4usize, concat!( "Size of: ", stringify!(ble_gattc_evt_char_val_by_uuid_read_rsp_t) @@ -10417,7 +10488,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_read_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -10427,13 +10498,13 @@ pub struct ble_gattc_evt_read_rsp_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_read_rsp_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_read_rsp_t)) ); assert_eq!( @@ -10488,19 +10559,19 @@ fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_vals_read_rsp_t { #[doc = "< Concatenated Attribute values length."] pub len: u16, #[doc = "< Attribute values. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub values: [u8; 1usize], + pub values: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_vals_read_rsp_t>(), - 4usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_vals_read_rsp_t)) ); assert_eq!( @@ -10539,7 +10610,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_write_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -10551,13 +10622,13 @@ pub struct ble_gattc_evt_write_rsp_t { pub len: u16, #[doc = "< Data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_write_rsp_t>(), - 10usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_write_rsp_t)) ); assert_eq!( @@ -10624,7 +10695,7 @@ fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_HVX."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_hvx_t { #[doc = "< Handle to which the HVx operation applies."] pub handle: u16, @@ -10634,13 +10705,13 @@ pub struct ble_gattc_evt_hvx_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_hvx_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_hvx_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_hvx_t)) ); assert_eq!( @@ -10796,7 +10867,6 @@ fn bindgen_test_layout_ble_gattc_evt_write_cmd_tx_complete_t() { } #[doc = "@brief GATTC event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_t { #[doc = "< Connection Handle on which event occurred."] pub conn_handle: u16, @@ -10808,41 +10878,40 @@ pub struct ble_gattc_evt_t { pub params: ble_gattc_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_t__bindgen_ty_1 { +pub struct ble_gattc_evt_t__bindgen_ty_1 { #[doc = "< Primary Service Discovery Response Event Parameters."] - pub prim_srvc_disc_rsp: ble_gattc_evt_prim_srvc_disc_rsp_t, + pub prim_srvc_disc_rsp: __BindgenUnionField<ble_gattc_evt_prim_srvc_disc_rsp_t>, #[doc = "< Relationship Discovery Response Event Parameters."] - pub rel_disc_rsp: ble_gattc_evt_rel_disc_rsp_t, + pub rel_disc_rsp: __BindgenUnionField<ble_gattc_evt_rel_disc_rsp_t>, #[doc = "< Characteristic Discovery Response Event Parameters."] - pub char_disc_rsp: ble_gattc_evt_char_disc_rsp_t, + pub char_disc_rsp: __BindgenUnionField<ble_gattc_evt_char_disc_rsp_t>, #[doc = "< Descriptor Discovery Response Event Parameters."] - pub desc_disc_rsp: ble_gattc_evt_desc_disc_rsp_t, + pub desc_disc_rsp: __BindgenUnionField<ble_gattc_evt_desc_disc_rsp_t>, #[doc = "< Characteristic Value Read by UUID Response Event Parameters."] - pub char_val_by_uuid_read_rsp: ble_gattc_evt_char_val_by_uuid_read_rsp_t, + pub char_val_by_uuid_read_rsp: __BindgenUnionField<ble_gattc_evt_char_val_by_uuid_read_rsp_t>, #[doc = "< Read Response Event Parameters."] - pub read_rsp: ble_gattc_evt_read_rsp_t, + pub read_rsp: __BindgenUnionField<ble_gattc_evt_read_rsp_t>, #[doc = "< Characteristic Values Read Response Event Parameters."] - pub char_vals_read_rsp: ble_gattc_evt_char_vals_read_rsp_t, + pub char_vals_read_rsp: __BindgenUnionField<ble_gattc_evt_char_vals_read_rsp_t>, #[doc = "< Write Response Event Parameters."] - pub write_rsp: ble_gattc_evt_write_rsp_t, + pub write_rsp: __BindgenUnionField<ble_gattc_evt_write_rsp_t>, #[doc = "< Handle Value Notification/Indication Event Parameters."] - pub hvx: ble_gattc_evt_hvx_t, + pub hvx: __BindgenUnionField<ble_gattc_evt_hvx_t>, #[doc = "< Exchange MTU Response Event Parameters."] - pub exchange_mtu_rsp: ble_gattc_evt_exchange_mtu_rsp_t, + pub exchange_mtu_rsp: __BindgenUnionField<ble_gattc_evt_exchange_mtu_rsp_t>, #[doc = "< Timeout Event Parameters."] - pub timeout: ble_gattc_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gattc_evt_timeout_t>, #[doc = "< Attribute Information Discovery Event Parameters."] - pub attr_info_disc_rsp: ble_gattc_evt_attr_info_disc_rsp_t, + pub attr_info_disc_rsp: __BindgenUnionField<ble_gattc_evt_attr_info_disc_rsp_t>, #[doc = "< Write without Response transmission complete Event Parameters."] - pub write_cmd_tx_complete: ble_gattc_evt_write_cmd_tx_complete_t, - _bindgen_union_align: [u16; 11usize], + pub write_cmd_tx_complete: __BindgenUnionField<ble_gattc_evt_write_cmd_tx_complete_t>, + pub bindgen_union_field: [u16; 4usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t__bindgen_ty_1>(), - 22usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -11021,7 +11090,7 @@ fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t>(), - 28usize, + 14usize, concat!("Size of: ", stringify!(ble_gattc_evt_t)) ); assert_eq!( @@ -12585,7 +12654,7 @@ fn bindgen_test_layout_ble_gatts_cfg_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_WRITE."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gatts_evt_write_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -12601,13 +12670,13 @@ pub struct ble_gatts_evt_write_t { pub len: u16, #[doc = "< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gatts_evt_write_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_write_t>(), - 14usize, + 12usize, concat!("Size of: ", stringify!(ble_gatts_evt_write_t)) ); assert_eq!( @@ -12744,7 +12813,6 @@ fn bindgen_test_layout_ble_gatts_evt_read_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_rw_authorize_request_t { #[doc = "< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES."] pub type_: u8, @@ -12752,19 +12820,18 @@ pub struct ble_gatts_evt_rw_authorize_request_t { pub request: ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { +pub struct ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { #[doc = "< Attribute Read Parameters."] - pub read: ble_gatts_evt_read_t, + pub read: __BindgenUnionField<ble_gatts_evt_read_t>, #[doc = "< Attribute Write Parameters."] - pub write: ble_gatts_evt_write_t, - _bindgen_union_align: [u16; 7usize], + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, + pub bindgen_union_field: [u16; 6usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1>(), - 14usize, + 12usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1) @@ -12809,7 +12876,7 @@ fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t>(), - 16usize, + 14usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t) @@ -13018,7 +13085,6 @@ fn bindgen_test_layout_ble_gatts_evt_hvn_tx_complete_t() { } #[doc = "@brief GATTS event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_t { #[doc = "< Connection Handle on which the event occurred."] pub conn_handle: u16, @@ -13026,29 +13092,28 @@ pub struct ble_gatts_evt_t { pub params: ble_gatts_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_t__bindgen_ty_1 { +pub struct ble_gatts_evt_t__bindgen_ty_1 { #[doc = "< Write Event Parameters."] - pub write: ble_gatts_evt_write_t, + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, #[doc = "< Read or Write Authorize Request Parameters."] - pub authorize_request: ble_gatts_evt_rw_authorize_request_t, + pub authorize_request: __BindgenUnionField<ble_gatts_evt_rw_authorize_request_t>, #[doc = "< System attributes missing."] - pub sys_attr_missing: ble_gatts_evt_sys_attr_missing_t, + pub sys_attr_missing: __BindgenUnionField<ble_gatts_evt_sys_attr_missing_t>, #[doc = "< Handle Value Confirmation Event Parameters."] - pub hvc: ble_gatts_evt_hvc_t, + pub hvc: __BindgenUnionField<ble_gatts_evt_hvc_t>, #[doc = "< Exchange MTU Request Event Parameters."] - pub exchange_mtu_request: ble_gatts_evt_exchange_mtu_request_t, + pub exchange_mtu_request: __BindgenUnionField<ble_gatts_evt_exchange_mtu_request_t>, #[doc = "< Timeout Event."] - pub timeout: ble_gatts_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gatts_evt_timeout_t>, #[doc = "< Handle Value Notification transmission complete Event Parameters."] - pub hvn_tx_complete: ble_gatts_evt_hvn_tx_complete_t, - _bindgen_union_align: [u16; 8usize], + pub hvn_tx_complete: __BindgenUnionField<ble_gatts_evt_hvn_tx_complete_t>, + pub bindgen_union_field: [u16; 7usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t__bindgen_ty_1>(), - 16usize, + 14usize, concat!("Size of: ", stringify!(ble_gatts_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -13149,7 +13214,7 @@ fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t>(), - 18usize, + 16usize, concat!("Size of: ", stringify!(ble_gatts_evt_t)) ); assert_eq!( @@ -14108,7 +14173,6 @@ fn bindgen_test_layout_ble_evt_hdr_t() { } #[doc = "@brief Common BLE Event type, wrapping the module specific event reports."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_evt_t { #[doc = "< Event header."] pub header: ble_evt_hdr_t, @@ -14116,17 +14180,16 @@ pub struct ble_evt_t { pub evt: ble_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_evt_t__bindgen_ty_1 { +pub struct ble_evt_t__bindgen_ty_1 { #[doc = "< Common Event, evt_id in BLE_EVT_* series."] - pub common_evt: ble_common_evt_t, + pub common_evt: __BindgenUnionField<ble_common_evt_t>, #[doc = "< GAP originated event, evt_id in BLE_GAP_EVT_* series."] - pub gap_evt: ble_gap_evt_t, + pub gap_evt: __BindgenUnionField<ble_gap_evt_t>, #[doc = "< GATT client originated event, evt_id in BLE_GATTC_EVT* series."] - pub gattc_evt: ble_gattc_evt_t, + pub gattc_evt: __BindgenUnionField<ble_gattc_evt_t>, #[doc = "< GATT server originated event, evt_id in BLE_GATTS_EVT* series."] - pub gatts_evt: ble_gatts_evt_t, - _bindgen_union_align: [u32; 11usize], + pub gatts_evt: __BindgenUnionField<ble_gatts_evt_t>, + pub bindgen_union_field: [u32; 11usize], } #[test] fn bindgen_test_layout_ble_evt_t__bindgen_ty_1() { diff --git a/nrf-softdevice-s132/src/bindings.rs b/nrf-softdevice-s132/src/bindings.rs index 511e79e..0537d4c 100644 --- a/nrf-softdevice-s132/src/bindings.rs +++ b/nrf-softdevice-s132/src/bindings.rs @@ -209,6 +209,79 @@ where } } } +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::core::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::core::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::core::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} +impl<T> ::core::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::core::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::core::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::core::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::core::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {} pub const NRF_ERROR_BASE_NUM: u32 = 0; pub const NRF_ERROR_SDM_BASE_NUM: u32 = 4096; pub const NRF_ERROR_SOC_BASE_NUM: u32 = 8192; @@ -12260,19 +12333,19 @@ fn bindgen_test_layout_ble_gattc_attr_info128_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_prim_srvc_disc_rsp_t { #[doc = "< Service count."] pub count: u16, #[doc = "< Service data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub services: [ble_gattc_service_t; 1usize], + pub services: __IncompleteArrayField<ble_gattc_service_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_prim_srvc_disc_rsp_t>(), - 10usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_prim_srvc_disc_rsp_t)) ); assert_eq!( @@ -12312,19 +12385,19 @@ fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_rel_disc_rsp_t { #[doc = "< Include count."] pub count: u16, #[doc = "< Include data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub includes: [ble_gattc_include_t; 1usize], + pub includes: __IncompleteArrayField<ble_gattc_include_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_rel_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_rel_disc_rsp_t)) ); assert_eq!( @@ -12359,19 +12432,19 @@ fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_disc_rsp_t { #[doc = "< Characteristic count."] pub count: u16, #[doc = "< Characteristic data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub chars: [ble_gattc_char_t; 1usize], + pub chars: __IncompleteArrayField<ble_gattc_char_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_disc_rsp_t)) ); assert_eq!( @@ -12406,19 +12479,19 @@ fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_desc_disc_rsp_t { #[doc = "< Descriptor count."] pub count: u16, #[doc = "< Descriptor data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub descs: [ble_gattc_desc_t; 1usize], + pub descs: __IncompleteArrayField<ble_gattc_desc_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_desc_disc_rsp_t>(), - 8usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_desc_disc_rsp_t)) ); assert_eq!( @@ -12453,7 +12526,6 @@ fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_attr_info_disc_rsp_t { #[doc = "< Attribute count."] pub count: u16, @@ -12463,23 +12535,22 @@ pub struct ble_gattc_evt_attr_info_disc_rsp_t { pub info: ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { +pub struct ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { #[doc = "< Attribute information for 16-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info16: [ble_gattc_attr_info16_t; 1usize], + pub attr_info16: __BindgenUnionField<[ble_gattc_attr_info16_t; 0usize]>, #[doc = "< Attribute information for 128-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info128: [ble_gattc_attr_info128_t; 1usize], - _bindgen_union_align: [u16; 9usize], + pub attr_info128: __BindgenUnionField<[ble_gattc_attr_info128_t; 0usize]>, + pub bindgen_union_field: [u16; 0usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1>(), - 18usize, + 0usize, concat!( "Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1) @@ -12524,7 +12595,7 @@ fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t>(), - 22usize, + 4usize, concat!("Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t)) ); assert_eq!( @@ -12623,7 +12694,7 @@ fn bindgen_test_layout_ble_gattc_handle_value_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value Pair Count."] pub count: u16, @@ -12632,13 +12703,13 @@ pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value(s) list. To iterate through the list use @ref sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub handle_value: [u8; 1usize], + pub handle_value: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_val_by_uuid_read_rsp_t>(), - 6usize, + 4usize, concat!( "Size of: ", stringify!(ble_gattc_evt_char_val_by_uuid_read_rsp_t) @@ -12694,7 +12765,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_read_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -12704,13 +12775,13 @@ pub struct ble_gattc_evt_read_rsp_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_read_rsp_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_read_rsp_t)) ); assert_eq!( @@ -12765,19 +12836,19 @@ fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_vals_read_rsp_t { #[doc = "< Concatenated Attribute values length."] pub len: u16, #[doc = "< Attribute values. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub values: [u8; 1usize], + pub values: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_vals_read_rsp_t>(), - 4usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_vals_read_rsp_t)) ); assert_eq!( @@ -12816,7 +12887,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_write_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -12828,13 +12899,13 @@ pub struct ble_gattc_evt_write_rsp_t { pub len: u16, #[doc = "< Data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_write_rsp_t>(), - 10usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_write_rsp_t)) ); assert_eq!( @@ -12901,7 +12972,7 @@ fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_HVX."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_hvx_t { #[doc = "< Handle to which the HVx operation applies."] pub handle: u16, @@ -12911,13 +12982,13 @@ pub struct ble_gattc_evt_hvx_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_hvx_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_hvx_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_hvx_t)) ); assert_eq!( @@ -13073,7 +13144,6 @@ fn bindgen_test_layout_ble_gattc_evt_write_cmd_tx_complete_t() { } #[doc = "@brief GATTC event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_t { #[doc = "< Connection Handle on which event occurred."] pub conn_handle: u16, @@ -13085,41 +13155,40 @@ pub struct ble_gattc_evt_t { pub params: ble_gattc_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_t__bindgen_ty_1 { +pub struct ble_gattc_evt_t__bindgen_ty_1 { #[doc = "< Primary Service Discovery Response Event Parameters."] - pub prim_srvc_disc_rsp: ble_gattc_evt_prim_srvc_disc_rsp_t, + pub prim_srvc_disc_rsp: __BindgenUnionField<ble_gattc_evt_prim_srvc_disc_rsp_t>, #[doc = "< Relationship Discovery Response Event Parameters."] - pub rel_disc_rsp: ble_gattc_evt_rel_disc_rsp_t, + pub rel_disc_rsp: __BindgenUnionField<ble_gattc_evt_rel_disc_rsp_t>, #[doc = "< Characteristic Discovery Response Event Parameters."] - pub char_disc_rsp: ble_gattc_evt_char_disc_rsp_t, + pub char_disc_rsp: __BindgenUnionField<ble_gattc_evt_char_disc_rsp_t>, #[doc = "< Descriptor Discovery Response Event Parameters."] - pub desc_disc_rsp: ble_gattc_evt_desc_disc_rsp_t, + pub desc_disc_rsp: __BindgenUnionField<ble_gattc_evt_desc_disc_rsp_t>, #[doc = "< Characteristic Value Read by UUID Response Event Parameters."] - pub char_val_by_uuid_read_rsp: ble_gattc_evt_char_val_by_uuid_read_rsp_t, + pub char_val_by_uuid_read_rsp: __BindgenUnionField<ble_gattc_evt_char_val_by_uuid_read_rsp_t>, #[doc = "< Read Response Event Parameters."] - pub read_rsp: ble_gattc_evt_read_rsp_t, + pub read_rsp: __BindgenUnionField<ble_gattc_evt_read_rsp_t>, #[doc = "< Characteristic Values Read Response Event Parameters."] - pub char_vals_read_rsp: ble_gattc_evt_char_vals_read_rsp_t, + pub char_vals_read_rsp: __BindgenUnionField<ble_gattc_evt_char_vals_read_rsp_t>, #[doc = "< Write Response Event Parameters."] - pub write_rsp: ble_gattc_evt_write_rsp_t, + pub write_rsp: __BindgenUnionField<ble_gattc_evt_write_rsp_t>, #[doc = "< Handle Value Notification/Indication Event Parameters."] - pub hvx: ble_gattc_evt_hvx_t, + pub hvx: __BindgenUnionField<ble_gattc_evt_hvx_t>, #[doc = "< Exchange MTU Response Event Parameters."] - pub exchange_mtu_rsp: ble_gattc_evt_exchange_mtu_rsp_t, + pub exchange_mtu_rsp: __BindgenUnionField<ble_gattc_evt_exchange_mtu_rsp_t>, #[doc = "< Timeout Event Parameters."] - pub timeout: ble_gattc_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gattc_evt_timeout_t>, #[doc = "< Attribute Information Discovery Event Parameters."] - pub attr_info_disc_rsp: ble_gattc_evt_attr_info_disc_rsp_t, + pub attr_info_disc_rsp: __BindgenUnionField<ble_gattc_evt_attr_info_disc_rsp_t>, #[doc = "< Write without Response transmission complete Event Parameters."] - pub write_cmd_tx_complete: ble_gattc_evt_write_cmd_tx_complete_t, - _bindgen_union_align: [u16; 11usize], + pub write_cmd_tx_complete: __BindgenUnionField<ble_gattc_evt_write_cmd_tx_complete_t>, + pub bindgen_union_field: [u16; 4usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t__bindgen_ty_1>(), - 22usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -13298,7 +13367,7 @@ fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t>(), - 28usize, + 14usize, concat!("Size of: ", stringify!(ble_gattc_evt_t)) ); assert_eq!( @@ -14862,7 +14931,7 @@ fn bindgen_test_layout_ble_gatts_cfg_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_WRITE."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gatts_evt_write_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -14878,13 +14947,13 @@ pub struct ble_gatts_evt_write_t { pub len: u16, #[doc = "< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gatts_evt_write_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_write_t>(), - 14usize, + 12usize, concat!("Size of: ", stringify!(ble_gatts_evt_write_t)) ); assert_eq!( @@ -15021,7 +15090,6 @@ fn bindgen_test_layout_ble_gatts_evt_read_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_rw_authorize_request_t { #[doc = "< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES."] pub type_: u8, @@ -15029,19 +15097,18 @@ pub struct ble_gatts_evt_rw_authorize_request_t { pub request: ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { +pub struct ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { #[doc = "< Attribute Read Parameters."] - pub read: ble_gatts_evt_read_t, + pub read: __BindgenUnionField<ble_gatts_evt_read_t>, #[doc = "< Attribute Write Parameters."] - pub write: ble_gatts_evt_write_t, - _bindgen_union_align: [u16; 7usize], + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, + pub bindgen_union_field: [u16; 6usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1>(), - 14usize, + 12usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1) @@ -15086,7 +15153,7 @@ fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t>(), - 16usize, + 14usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t) @@ -15295,7 +15362,6 @@ fn bindgen_test_layout_ble_gatts_evt_hvn_tx_complete_t() { } #[doc = "@brief GATTS event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_t { #[doc = "< Connection Handle on which the event occurred."] pub conn_handle: u16, @@ -15303,29 +15369,28 @@ pub struct ble_gatts_evt_t { pub params: ble_gatts_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_t__bindgen_ty_1 { +pub struct ble_gatts_evt_t__bindgen_ty_1 { #[doc = "< Write Event Parameters."] - pub write: ble_gatts_evt_write_t, + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, #[doc = "< Read or Write Authorize Request Parameters."] - pub authorize_request: ble_gatts_evt_rw_authorize_request_t, + pub authorize_request: __BindgenUnionField<ble_gatts_evt_rw_authorize_request_t>, #[doc = "< System attributes missing."] - pub sys_attr_missing: ble_gatts_evt_sys_attr_missing_t, + pub sys_attr_missing: __BindgenUnionField<ble_gatts_evt_sys_attr_missing_t>, #[doc = "< Handle Value Confirmation Event Parameters."] - pub hvc: ble_gatts_evt_hvc_t, + pub hvc: __BindgenUnionField<ble_gatts_evt_hvc_t>, #[doc = "< Exchange MTU Request Event Parameters."] - pub exchange_mtu_request: ble_gatts_evt_exchange_mtu_request_t, + pub exchange_mtu_request: __BindgenUnionField<ble_gatts_evt_exchange_mtu_request_t>, #[doc = "< Timeout Event."] - pub timeout: ble_gatts_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gatts_evt_timeout_t>, #[doc = "< Handle Value Notification transmission complete Event Parameters."] - pub hvn_tx_complete: ble_gatts_evt_hvn_tx_complete_t, - _bindgen_union_align: [u16; 8usize], + pub hvn_tx_complete: __BindgenUnionField<ble_gatts_evt_hvn_tx_complete_t>, + pub bindgen_union_field: [u16; 7usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t__bindgen_ty_1>(), - 16usize, + 14usize, concat!("Size of: ", stringify!(ble_gatts_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -15426,7 +15491,7 @@ fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t>(), - 18usize, + 16usize, concat!("Size of: ", stringify!(ble_gatts_evt_t)) ); assert_eq!( @@ -16386,7 +16451,6 @@ fn bindgen_test_layout_ble_evt_hdr_t() { } #[doc = "@brief Common BLE Event type, wrapping the module specific event reports."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_evt_t { #[doc = "< Event header."] pub header: ble_evt_hdr_t, @@ -16394,19 +16458,18 @@ pub struct ble_evt_t { pub evt: ble_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_evt_t__bindgen_ty_1 { +pub struct ble_evt_t__bindgen_ty_1 { #[doc = "< Common Event, evt_id in BLE_EVT_* series."] - pub common_evt: ble_common_evt_t, + pub common_evt: __BindgenUnionField<ble_common_evt_t>, #[doc = "< GAP originated event, evt_id in BLE_GAP_EVT_* series."] - pub gap_evt: ble_gap_evt_t, + pub gap_evt: __BindgenUnionField<ble_gap_evt_t>, #[doc = "< GATT client originated event, evt_id in BLE_GATTC_EVT* series."] - pub gattc_evt: ble_gattc_evt_t, + pub gattc_evt: __BindgenUnionField<ble_gattc_evt_t>, #[doc = "< GATT server originated event, evt_id in BLE_GATTS_EVT* series."] - pub gatts_evt: ble_gatts_evt_t, + pub gatts_evt: __BindgenUnionField<ble_gatts_evt_t>, #[doc = "< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series."] - pub l2cap_evt: ble_l2cap_evt_t, - _bindgen_union_align: [u32; 11usize], + pub l2cap_evt: __BindgenUnionField<ble_l2cap_evt_t>, + pub bindgen_union_field: [u32; 11usize], } #[test] fn bindgen_test_layout_ble_evt_t__bindgen_ty_1() { diff --git a/nrf-softdevice-s140/src/bindings.rs b/nrf-softdevice-s140/src/bindings.rs index 20056cb..8b727a6 100644 --- a/nrf-softdevice-s140/src/bindings.rs +++ b/nrf-softdevice-s140/src/bindings.rs @@ -209,6 +209,79 @@ where } } } +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::core::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::core::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::core::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} +impl<T> ::core::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::core::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::core::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::core::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::core::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {} pub const NRF_ERROR_BASE_NUM: u32 = 0; pub const NRF_ERROR_SDM_BASE_NUM: u32 = 4096; pub const NRF_ERROR_SOC_BASE_NUM: u32 = 8192; @@ -12431,19 +12504,19 @@ fn bindgen_test_layout_ble_gattc_attr_info128_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_prim_srvc_disc_rsp_t { #[doc = "< Service count."] pub count: u16, #[doc = "< Service data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub services: [ble_gattc_service_t; 1usize], + pub services: __IncompleteArrayField<ble_gattc_service_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_prim_srvc_disc_rsp_t>(), - 10usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_prim_srvc_disc_rsp_t)) ); assert_eq!( @@ -12483,19 +12556,19 @@ fn bindgen_test_layout_ble_gattc_evt_prim_srvc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_rel_disc_rsp_t { #[doc = "< Include count."] pub count: u16, #[doc = "< Include data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub includes: [ble_gattc_include_t; 1usize], + pub includes: __IncompleteArrayField<ble_gattc_include_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_rel_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_rel_disc_rsp_t)) ); assert_eq!( @@ -12530,19 +12603,19 @@ fn bindgen_test_layout_ble_gattc_evt_rel_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_disc_rsp_t { #[doc = "< Characteristic count."] pub count: u16, #[doc = "< Characteristic data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub chars: [ble_gattc_char_t; 1usize], + pub chars: __IncompleteArrayField<ble_gattc_char_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_disc_rsp_t>(), - 12usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_disc_rsp_t)) ); assert_eq!( @@ -12577,19 +12650,19 @@ fn bindgen_test_layout_ble_gattc_evt_char_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_desc_disc_rsp_t { #[doc = "< Descriptor count."] pub count: u16, #[doc = "< Descriptor data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub descs: [ble_gattc_desc_t; 1usize], + pub descs: __IncompleteArrayField<ble_gattc_desc_t>, } #[test] fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_desc_disc_rsp_t>(), - 8usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_desc_disc_rsp_t)) ); assert_eq!( @@ -12624,7 +12697,6 @@ fn bindgen_test_layout_ble_gattc_evt_desc_disc_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_attr_info_disc_rsp_t { #[doc = "< Attribute count."] pub count: u16, @@ -12634,23 +12706,22 @@ pub struct ble_gattc_evt_attr_info_disc_rsp_t { pub info: ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { +pub struct ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1 { #[doc = "< Attribute information for 16-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info16: [ble_gattc_attr_info16_t; 1usize], + pub attr_info16: __BindgenUnionField<[ble_gattc_attr_info16_t; 0usize]>, #[doc = "< Attribute information for 128-bit Attribute UUID."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub attr_info128: [ble_gattc_attr_info128_t; 1usize], - _bindgen_union_align: [u16; 9usize], + pub attr_info128: __BindgenUnionField<[ble_gattc_attr_info128_t; 0usize]>, + pub bindgen_union_field: [u16; 0usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1>(), - 18usize, + 0usize, concat!( "Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1) @@ -12695,7 +12766,7 @@ fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_attr_info_disc_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_attr_info_disc_rsp_t>(), - 22usize, + 4usize, concat!("Size of: ", stringify!(ble_gattc_evt_attr_info_disc_rsp_t)) ); assert_eq!( @@ -12794,7 +12865,7 @@ fn bindgen_test_layout_ble_gattc_handle_value_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value Pair Count."] pub count: u16, @@ -12803,13 +12874,13 @@ pub struct ble_gattc_evt_char_val_by_uuid_read_rsp_t { #[doc = "< Handle-Value(s) list. To iterate through the list use @ref sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter."] #[doc = "@note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub handle_value: [u8; 1usize], + pub handle_value: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_val_by_uuid_read_rsp_t>(), - 6usize, + 4usize, concat!( "Size of: ", stringify!(ble_gattc_evt_char_val_by_uuid_read_rsp_t) @@ -12865,7 +12936,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_val_by_uuid_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_read_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -12875,13 +12946,13 @@ pub struct ble_gattc_evt_read_rsp_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_read_rsp_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_read_rsp_t)) ); assert_eq!( @@ -12936,19 +13007,19 @@ fn bindgen_test_layout_ble_gattc_evt_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_char_vals_read_rsp_t { #[doc = "< Concatenated Attribute values length."] pub len: u16, #[doc = "< Attribute values. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub values: [u8; 1usize], + pub values: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_char_vals_read_rsp_t>(), - 4usize, + 2usize, concat!("Size of: ", stringify!(ble_gattc_evt_char_vals_read_rsp_t)) ); assert_eq!( @@ -12987,7 +13058,7 @@ fn bindgen_test_layout_ble_gattc_evt_char_vals_read_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_write_rsp_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -12999,13 +13070,13 @@ pub struct ble_gattc_evt_write_rsp_t { pub len: u16, #[doc = "< Data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_write_rsp_t>(), - 10usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_write_rsp_t)) ); assert_eq!( @@ -13072,7 +13143,7 @@ fn bindgen_test_layout_ble_gattc_evt_write_rsp_t() { } #[doc = "@brief Event structure for @ref BLE_GATTC_EVT_HVX."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gattc_evt_hvx_t { #[doc = "< Handle to which the HVx operation applies."] pub handle: u16, @@ -13082,13 +13153,13 @@ pub struct ble_gattc_evt_hvx_t { pub len: u16, #[doc = "< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gattc_evt_hvx_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_hvx_t>(), - 8usize, + 6usize, concat!("Size of: ", stringify!(ble_gattc_evt_hvx_t)) ); assert_eq!( @@ -13244,7 +13315,6 @@ fn bindgen_test_layout_ble_gattc_evt_write_cmd_tx_complete_t() { } #[doc = "@brief GATTC event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gattc_evt_t { #[doc = "< Connection Handle on which event occurred."] pub conn_handle: u16, @@ -13256,41 +13326,40 @@ pub struct ble_gattc_evt_t { pub params: ble_gattc_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gattc_evt_t__bindgen_ty_1 { +pub struct ble_gattc_evt_t__bindgen_ty_1 { #[doc = "< Primary Service Discovery Response Event Parameters."] - pub prim_srvc_disc_rsp: ble_gattc_evt_prim_srvc_disc_rsp_t, + pub prim_srvc_disc_rsp: __BindgenUnionField<ble_gattc_evt_prim_srvc_disc_rsp_t>, #[doc = "< Relationship Discovery Response Event Parameters."] - pub rel_disc_rsp: ble_gattc_evt_rel_disc_rsp_t, + pub rel_disc_rsp: __BindgenUnionField<ble_gattc_evt_rel_disc_rsp_t>, #[doc = "< Characteristic Discovery Response Event Parameters."] - pub char_disc_rsp: ble_gattc_evt_char_disc_rsp_t, + pub char_disc_rsp: __BindgenUnionField<ble_gattc_evt_char_disc_rsp_t>, #[doc = "< Descriptor Discovery Response Event Parameters."] - pub desc_disc_rsp: ble_gattc_evt_desc_disc_rsp_t, + pub desc_disc_rsp: __BindgenUnionField<ble_gattc_evt_desc_disc_rsp_t>, #[doc = "< Characteristic Value Read by UUID Response Event Parameters."] - pub char_val_by_uuid_read_rsp: ble_gattc_evt_char_val_by_uuid_read_rsp_t, + pub char_val_by_uuid_read_rsp: __BindgenUnionField<ble_gattc_evt_char_val_by_uuid_read_rsp_t>, #[doc = "< Read Response Event Parameters."] - pub read_rsp: ble_gattc_evt_read_rsp_t, + pub read_rsp: __BindgenUnionField<ble_gattc_evt_read_rsp_t>, #[doc = "< Characteristic Values Read Response Event Parameters."] - pub char_vals_read_rsp: ble_gattc_evt_char_vals_read_rsp_t, + pub char_vals_read_rsp: __BindgenUnionField<ble_gattc_evt_char_vals_read_rsp_t>, #[doc = "< Write Response Event Parameters."] - pub write_rsp: ble_gattc_evt_write_rsp_t, + pub write_rsp: __BindgenUnionField<ble_gattc_evt_write_rsp_t>, #[doc = "< Handle Value Notification/Indication Event Parameters."] - pub hvx: ble_gattc_evt_hvx_t, + pub hvx: __BindgenUnionField<ble_gattc_evt_hvx_t>, #[doc = "< Exchange MTU Response Event Parameters."] - pub exchange_mtu_rsp: ble_gattc_evt_exchange_mtu_rsp_t, + pub exchange_mtu_rsp: __BindgenUnionField<ble_gattc_evt_exchange_mtu_rsp_t>, #[doc = "< Timeout Event Parameters."] - pub timeout: ble_gattc_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gattc_evt_timeout_t>, #[doc = "< Attribute Information Discovery Event Parameters."] - pub attr_info_disc_rsp: ble_gattc_evt_attr_info_disc_rsp_t, + pub attr_info_disc_rsp: __BindgenUnionField<ble_gattc_evt_attr_info_disc_rsp_t>, #[doc = "< Write without Response transmission complete Event Parameters."] - pub write_cmd_tx_complete: ble_gattc_evt_write_cmd_tx_complete_t, - _bindgen_union_align: [u16; 11usize], + pub write_cmd_tx_complete: __BindgenUnionField<ble_gattc_evt_write_cmd_tx_complete_t>, + pub bindgen_union_field: [u16; 4usize], } #[test] fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t__bindgen_ty_1>(), - 22usize, + 8usize, concat!("Size of: ", stringify!(ble_gattc_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -13469,7 +13538,7 @@ fn bindgen_test_layout_ble_gattc_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gattc_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gattc_evt_t>(), - 28usize, + 14usize, concat!("Size of: ", stringify!(ble_gattc_evt_t)) ); assert_eq!( @@ -15033,7 +15102,7 @@ fn bindgen_test_layout_ble_gatts_cfg_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_WRITE."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct ble_gatts_evt_write_t { #[doc = "< Attribute Handle."] pub handle: u16, @@ -15049,13 +15118,13 @@ pub struct ble_gatts_evt_write_t { pub len: u16, #[doc = "< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation."] #[doc = "See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members."] - pub data: [u8; 1usize], + pub data: __IncompleteArrayField<u8>, } #[test] fn bindgen_test_layout_ble_gatts_evt_write_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_write_t>(), - 14usize, + 12usize, concat!("Size of: ", stringify!(ble_gatts_evt_write_t)) ); assert_eq!( @@ -15192,7 +15261,6 @@ fn bindgen_test_layout_ble_gatts_evt_read_t() { } #[doc = "@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_rw_authorize_request_t { #[doc = "< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES."] pub type_: u8, @@ -15200,19 +15268,18 @@ pub struct ble_gatts_evt_rw_authorize_request_t { pub request: ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { +pub struct ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1 { #[doc = "< Attribute Read Parameters."] - pub read: ble_gatts_evt_read_t, + pub read: __BindgenUnionField<ble_gatts_evt_read_t>, #[doc = "< Attribute Write Parameters."] - pub write: ble_gatts_evt_write_t, - _bindgen_union_align: [u16; 7usize], + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, + pub bindgen_union_field: [u16; 6usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1>(), - 14usize, + 12usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1) @@ -15257,7 +15324,7 @@ fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_rw_authorize_request_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_rw_authorize_request_t>(), - 16usize, + 14usize, concat!( "Size of: ", stringify!(ble_gatts_evt_rw_authorize_request_t) @@ -15466,7 +15533,6 @@ fn bindgen_test_layout_ble_gatts_evt_hvn_tx_complete_t() { } #[doc = "@brief GATTS event structure."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_gatts_evt_t { #[doc = "< Connection Handle on which the event occurred."] pub conn_handle: u16, @@ -15474,29 +15540,28 @@ pub struct ble_gatts_evt_t { pub params: ble_gatts_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_gatts_evt_t__bindgen_ty_1 { +pub struct ble_gatts_evt_t__bindgen_ty_1 { #[doc = "< Write Event Parameters."] - pub write: ble_gatts_evt_write_t, + pub write: __BindgenUnionField<ble_gatts_evt_write_t>, #[doc = "< Read or Write Authorize Request Parameters."] - pub authorize_request: ble_gatts_evt_rw_authorize_request_t, + pub authorize_request: __BindgenUnionField<ble_gatts_evt_rw_authorize_request_t>, #[doc = "< System attributes missing."] - pub sys_attr_missing: ble_gatts_evt_sys_attr_missing_t, + pub sys_attr_missing: __BindgenUnionField<ble_gatts_evt_sys_attr_missing_t>, #[doc = "< Handle Value Confirmation Event Parameters."] - pub hvc: ble_gatts_evt_hvc_t, + pub hvc: __BindgenUnionField<ble_gatts_evt_hvc_t>, #[doc = "< Exchange MTU Request Event Parameters."] - pub exchange_mtu_request: ble_gatts_evt_exchange_mtu_request_t, + pub exchange_mtu_request: __BindgenUnionField<ble_gatts_evt_exchange_mtu_request_t>, #[doc = "< Timeout Event."] - pub timeout: ble_gatts_evt_timeout_t, + pub timeout: __BindgenUnionField<ble_gatts_evt_timeout_t>, #[doc = "< Handle Value Notification transmission complete Event Parameters."] - pub hvn_tx_complete: ble_gatts_evt_hvn_tx_complete_t, - _bindgen_union_align: [u16; 8usize], + pub hvn_tx_complete: __BindgenUnionField<ble_gatts_evt_hvn_tx_complete_t>, + pub bindgen_union_field: [u16; 7usize], } #[test] fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t__bindgen_ty_1>(), - 16usize, + 14usize, concat!("Size of: ", stringify!(ble_gatts_evt_t__bindgen_ty_1)) ); assert_eq!( @@ -15597,7 +15662,7 @@ fn bindgen_test_layout_ble_gatts_evt_t__bindgen_ty_1() { fn bindgen_test_layout_ble_gatts_evt_t() { assert_eq!( ::core::mem::size_of::<ble_gatts_evt_t>(), - 18usize, + 16usize, concat!("Size of: ", stringify!(ble_gatts_evt_t)) ); assert_eq!( @@ -16557,7 +16622,6 @@ fn bindgen_test_layout_ble_evt_hdr_t() { } #[doc = "@brief Common BLE Event type, wrapping the module specific event reports."] #[repr(C)] -#[derive(Copy, Clone)] pub struct ble_evt_t { #[doc = "< Event header."] pub header: ble_evt_hdr_t, @@ -16565,19 +16629,18 @@ pub struct ble_evt_t { pub evt: ble_evt_t__bindgen_ty_1, } #[repr(C)] -#[derive(Copy, Clone)] -pub union ble_evt_t__bindgen_ty_1 { +pub struct ble_evt_t__bindgen_ty_1 { #[doc = "< Common Event, evt_id in BLE_EVT_* series."] - pub common_evt: ble_common_evt_t, + pub common_evt: __BindgenUnionField<ble_common_evt_t>, #[doc = "< GAP originated event, evt_id in BLE_GAP_EVT_* series."] - pub gap_evt: ble_gap_evt_t, + pub gap_evt: __BindgenUnionField<ble_gap_evt_t>, #[doc = "< GATT client originated event, evt_id in BLE_GATTC_EVT* series."] - pub gattc_evt: ble_gattc_evt_t, + pub gattc_evt: __BindgenUnionField<ble_gattc_evt_t>, #[doc = "< GATT server originated event, evt_id in BLE_GATTS_EVT* series."] - pub gatts_evt: ble_gatts_evt_t, + pub gatts_evt: __BindgenUnionField<ble_gatts_evt_t>, #[doc = "< L2CAP originated event, evt_id in BLE_L2CAP_EVT* series."] - pub l2cap_evt: ble_l2cap_evt_t, - _bindgen_union_align: [u32; 11usize], + pub l2cap_evt: __BindgenUnionField<ble_l2cap_evt_t>, + pub bindgen_union_field: [u32; 11usize], } #[test] fn bindgen_test_layout_ble_evt_t__bindgen_ty_1() { diff --git a/nrf-softdevice-s140/src/test.h b/nrf-softdevice-s140/src/test.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/nrf-softdevice-s140/src/test.h diff --git a/nrf-softdevice/src/ble/gap.rs b/nrf-softdevice/src/ble/gap.rs index 93371c4..538cd0e 100644 --- a/nrf-softdevice/src/ble/gap.rs +++ b/nrf-softdevice/src/ble/gap.rs @@ -6,9 +6,9 @@ use crate::sd; use crate::util::*; use crate::uuid::Uuid; -pub(crate) unsafe fn on_connected(evt: &sd::ble_gap_evt_t) { - let params = &evt.params.connected; - let conn_handle = evt.conn_handle; +pub(crate) unsafe fn on_connected(_ble_evt: *const sd::ble_evt_t, gap_evt: &sd::ble_gap_evt_t) { + let params = &gap_evt.params.connected; + let conn_handle = gap_evt.conn_handle; if params.role == sd::BLE_GAP_ROLE_PERIPH as u8 { ADV_SIGNAL.signal(Ok(Connection { conn_handle })) @@ -17,34 +17,111 @@ pub(crate) unsafe fn on_connected(evt: &sd::ble_gap_evt_t) { } } -pub(crate) unsafe fn on_disconnected(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_conn_param_update(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_sec_params_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_sec_info_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_passkey_display(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_key_pressed(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_auth_key_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_lesc_dhkey_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_auth_status(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_conn_sec_update(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_timeout(evt: &sd::ble_gap_evt_t) { - let params = &evt.params.timeout; +pub(crate) unsafe fn on_disconnected(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) { +} + +pub(crate) unsafe fn on_conn_param_update( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_sec_params_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_sec_info_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_passkey_display( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_key_pressed(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) {} +pub(crate) unsafe fn on_auth_key_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_lesc_dhkey_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_auth_status(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) {} + +pub(crate) unsafe fn on_conn_sec_update( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_timeout(_ble_evt: *const sd::ble_evt_t, gap_evt: &sd::ble_gap_evt_t) { + let params = &gap_evt.params.timeout; match params.src as u32 { sd::BLE_GAP_TIMEOUT_SRC_CONN => CONNECT_SIGNAL.signal(Err(ConnectError::Stopped)), x => warn!("unknown timeout src {:u32}", x), } } -pub(crate) unsafe fn on_rssi_changed(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_adv_report(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_sec_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_conn_param_update_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_scan_req_report(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_phy_update_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_phy_update(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_data_length_update_request(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_data_length_update(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_qos_channel_survey_report(_evt: &sd::ble_gap_evt_t) {} -pub(crate) unsafe fn on_adv_set_terminated(_evt: &sd::ble_gap_evt_t) { + +pub(crate) unsafe fn on_rssi_changed(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) { +} + +pub(crate) unsafe fn on_adv_report(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) {} + +pub(crate) unsafe fn on_sec_request(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) {} + +pub(crate) unsafe fn on_conn_param_update_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_scan_req_report( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_phy_update_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_phy_update(_ble_evt: *const sd::ble_evt_t, _gap_evt: &sd::ble_gap_evt_t) {} + +pub(crate) unsafe fn on_data_length_update_request( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_data_length_update( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_qos_channel_survey_report( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { +} + +pub(crate) unsafe fn on_adv_set_terminated( + _ble_evt: *const sd::ble_evt_t, + _gap_evt: &sd::ble_gap_evt_t, +) { ADV_SIGNAL.signal(Err(AdvertiseError::Stopped)) } diff --git a/nrf-softdevice/src/ble/gatt_client.rs b/nrf-softdevice/src/ble/gatt_client.rs index 86f2410..a4d2406 100644 --- a/nrf-softdevice/src/ble/gatt_client.rs +++ b/nrf-softdevice/src/ble/gatt_client.rs @@ -1,15 +1,68 @@ use crate::sd; -pub(crate) unsafe fn on_prim_srvc_disc_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_rel_disc_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_char_disc_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_desc_disc_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_attr_info_disc_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_char_val_by_uuid_read_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_read_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_char_vals_read_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_write_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_hvx(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_exchange_mtu_rsp(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_timeout(_evt: &sd::ble_gattc_evt_t) {} -pub(crate) unsafe fn on_write_cmd_tx_complete(_evt: &sd::ble_gattc_evt_t) {} +pub(crate) unsafe fn on_prim_srvc_disc_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_rel_disc_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_char_disc_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_desc_disc_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_attr_info_disc_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_char_val_by_uuid_read_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_read_rsp(_ble_evt: *const sd::ble_evt_t, _gattc_evt: &sd::ble_gattc_evt_t) { +} + +pub(crate) unsafe fn on_char_vals_read_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_write_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_hvx(_ble_evt: *const sd::ble_evt_t, _gattc_evt: &sd::ble_gattc_evt_t) {} + +pub(crate) unsafe fn on_exchange_mtu_rsp( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} + +pub(crate) unsafe fn on_timeout(_ble_evt: *const sd::ble_evt_t, _gattc_evt: &sd::ble_gattc_evt_t) {} + +pub(crate) unsafe fn on_write_cmd_tx_complete( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gattc_evt_t, +) { +} diff --git a/nrf-softdevice/src/ble/gatt_server.rs b/nrf-softdevice/src/ble/gatt_server.rs index a848a34..4f8822a 100644 --- a/nrf-softdevice/src/ble/gatt_server.rs +++ b/nrf-softdevice/src/ble/gatt_server.rs @@ -2,13 +2,39 @@ use core::ptr; use crate::sd; -pub(crate) unsafe fn on_write(_evt: &sd::ble_gatts_evt_t) {} -pub(crate) unsafe fn on_rw_authorize_request(_evt: &sd::ble_gatts_evt_t) {} -pub(crate) unsafe fn on_sys_attr_missing(evt: &sd::ble_gatts_evt_t) { - sd::sd_ble_gatts_sys_attr_set(evt.conn_handle, ptr::null(), 0, 0); -} -pub(crate) unsafe fn on_hvc(_evt: &sd::ble_gatts_evt_t) {} -pub(crate) unsafe fn on_sc_confirm(_evt: &sd::ble_gatts_evt_t) {} -pub(crate) unsafe fn on_exchange_mtu_request(_evt: &sd::ble_gatts_evt_t) {} -pub(crate) unsafe fn on_timeout(_evt: &sd::ble_gatts_evt_t) {} -pub(crate) unsafe fn on_hvn_tx_complete(_evt: &sd::ble_gatts_evt_t) {} +pub(crate) unsafe fn on_write(_ble_evt: *const sd::ble_evt_t, _gattc_evt: &sd::ble_gatts_evt_t) {} + +pub(crate) unsafe fn on_rw_authorize_request( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gatts_evt_t, +) { +} + +pub(crate) unsafe fn on_sys_attr_missing( + _ble_evt: *const sd::ble_evt_t, + gattc_evt: &sd::ble_gatts_evt_t, +) { + sd::sd_ble_gatts_sys_attr_set(gattc_evt.conn_handle, ptr::null(), 0, 0); +} + +pub(crate) unsafe fn on_hvc(_ble_evt: *const sd::ble_evt_t, _gattc_evt: &sd::ble_gatts_evt_t) {} + +pub(crate) unsafe fn on_sc_confirm( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gatts_evt_t, +) { +} + +pub(crate) unsafe fn on_exchange_mtu_request( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gatts_evt_t, +) { +} + +pub(crate) unsafe fn on_timeout(_ble_evt: *const sd::ble_evt_t, _gattc_evt: &sd::ble_gatts_evt_t) {} + +pub(crate) unsafe fn on_hvn_tx_complete( + _ble_evt: *const sd::ble_evt_t, + _gattc_evt: &sd::ble_gatts_evt_t, +) { +} diff --git a/nrf-softdevice/src/ble/l2cap.rs b/nrf-softdevice/src/ble/l2cap.rs index cebd59e..24b7da4 100644 --- a/nrf-softdevice/src/ble/l2cap.rs +++ b/nrf-softdevice/src/ble/l2cap.rs @@ -1,10 +1,29 @@ use crate::sd; -pub(crate) fn on_ch_setup_request(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_setup_refused(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_setup(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_released(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_sdu_buf_released(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_credit(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_rx(_evt: &sd::ble_l2cap_evt_t) {} -pub(crate) fn on_ch_tx(_evt: &sd::ble_l2cap_evt_t) {} +pub(crate) fn on_ch_setup_request( + _ble_evt: *const sd::ble_evt_t, + _l2cap_evt: &sd::ble_l2cap_evt_t, +) { +} + +pub(crate) fn on_ch_setup_refused( + _ble_evt: *const sd::ble_evt_t, + _l2cap_evt: &sd::ble_l2cap_evt_t, +) { +} + +pub(crate) fn on_ch_setup(_ble_evt: *const sd::ble_evt_t, _l2cap_evt: &sd::ble_l2cap_evt_t) {} + +pub(crate) fn on_ch_released(_ble_evt: *const sd::ble_evt_t, _l2cap_evt: &sd::ble_l2cap_evt_t) {} + +pub(crate) fn on_ch_sdu_buf_released( + _ble_evt: *const sd::ble_evt_t, + _l2cap_evt: &sd::ble_l2cap_evt_t, +) { +} + +pub(crate) fn on_ch_credit(_ble_evt: *const sd::ble_evt_t, _l2cap_evt: &sd::ble_l2cap_evt_t) {} + +pub(crate) fn on_ch_rx(_ble_evt: *const sd::ble_evt_t, _l2cap_evt: &sd::ble_l2cap_evt_t) {} + +pub(crate) fn on_ch_tx(_ble_evt: *const sd::ble_evt_t, _l2cap_evt: &sd::ble_l2cap_evt_t) {} diff --git a/nrf-softdevice/src/ble/mod.rs b/nrf-softdevice/src/ble/mod.rs index c8e03c5..43ccde2 100644 --- a/nrf-softdevice/src/ble/mod.rs +++ b/nrf-softdevice/src/ble/mod.rs @@ -1,4 +1,5 @@ use crate::sd; +use crate::util::*; pub mod gap; pub mod gatt_client; @@ -6,78 +7,81 @@ pub mod gatt_server; pub mod l2cap; pub mod uuid; -fn on_user_mem_request(_evt: &sd::ble_common_evt_t) {} -fn on_user_mem_release(_evt: &sd::ble_common_evt_t) {} +fn on_user_mem_request(_ble_evt: *const sd::ble_evt_t, _common_evt: &sd::ble_common_evt_t) {} +fn on_user_mem_release(_ble_evt: *const sd::ble_evt_t, _common_evt: &sd::ble_common_evt_t) {} -#[rustfmt::skip] -pub(crate) unsafe fn on_evt(evt: &sd::ble_evt_t) { - defmt::trace!("ble evt {:istr}", evt_str(evt.header.evt_id as u32)); - - match evt.header.evt_id as u32 { - sd::BLE_COMMON_EVTS_BLE_EVT_USER_MEM_REQUEST => on_user_mem_request(&evt.evt.common_evt), - sd::BLE_COMMON_EVTS_BLE_EVT_USER_MEM_RELEASE => on_user_mem_release(&evt.evt.common_evt), - - sd::BLE_GAP_EVTS_BLE_GAP_EVT_CONNECTED => gap::on_connected(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => gap::on_disconnected(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_CONN_PARAM_UPDATE => gap::on_conn_param_update(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_SEC_PARAMS_REQUEST => gap::on_sec_params_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_SEC_INFO_REQUEST => gap::on_sec_info_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_PASSKEY_DISPLAY => gap::on_passkey_display(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_KEY_PRESSED => gap::on_key_pressed(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_AUTH_KEY_REQUEST => gap::on_auth_key_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_LESC_DHKEY_REQUEST => gap::on_lesc_dhkey_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_AUTH_STATUS => gap::on_auth_status(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_CONN_SEC_UPDATE => gap::on_conn_sec_update(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_TIMEOUT => gap::on_timeout(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_RSSI_CHANGED => gap::on_rssi_changed(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_ADV_REPORT => gap::on_adv_report(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_SEC_REQUEST => gap::on_sec_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST => gap::on_conn_param_update_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_SCAN_REQ_REPORT => gap::on_scan_req_report(&evt.evt.gap_evt) , - sd::BLE_GAP_EVTS_BLE_GAP_EVT_PHY_UPDATE_REQUEST => gap::on_phy_update_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_PHY_UPDATE => gap::on_phy_update(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST => gap::on_data_length_update_request(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_DATA_LENGTH_UPDATE => gap::on_data_length_update(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT => gap::on_qos_channel_survey_report(&evt.evt.gap_evt), - sd::BLE_GAP_EVTS_BLE_GAP_EVT_ADV_SET_TERMINATED => gap::on_adv_set_terminated(&evt.evt.gap_evt) , - - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP_REQUEST => l2cap::on_ch_setup_request(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP_REFUSED => l2cap::on_ch_setup_refused(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP => l2cap::on_ch_setup(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RELEASED => l2cap::on_ch_released(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED => l2cap::on_ch_sdu_buf_released(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_CREDIT => l2cap::on_ch_credit(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RX => l2cap::on_ch_rx(&evt.evt.l2cap_evt), - sd::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_TX => l2cap::on_ch_tx(&evt.evt.l2cap_evt), - - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP => gatt_client::on_prim_srvc_disc_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_REL_DISC_RSP => gatt_client::on_rel_disc_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_DISC_RSP => gatt_client::on_char_disc_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_DESC_DISC_RSP => gatt_client::on_desc_disc_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_ATTR_INFO_DISC_RSP => gatt_client::on_attr_info_disc_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP => gatt_client::on_char_val_by_uuid_read_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_READ_RSP => gatt_client::on_read_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_VALS_READ_RSP => gatt_client::on_char_vals_read_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_WRITE_RSP => gatt_client::on_write_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_HVX => gatt_client::on_hvx(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_EXCHANGE_MTU_RSP => gatt_client::on_exchange_mtu_rsp(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_TIMEOUT => gatt_client::on_timeout(&evt.evt.gattc_evt), - sd::BLE_GATTC_EVTS_BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE => gatt_client::on_write_cmd_tx_complete(&evt.evt.gattc_evt), - - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_WRITE => gatt_server::on_write(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST => gatt_server::on_rw_authorize_request(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_SYS_ATTR_MISSING => gatt_server::on_sys_attr_missing(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_HVC => gatt_server::on_hvc(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_SC_CONFIRM => gatt_server::on_sc_confirm(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST => gatt_server::on_exchange_mtu_request(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_TIMEOUT => gatt_server::on_timeout(&evt.evt.gatts_evt), - sd::BLE_GATTS_EVTS_BLE_GATTS_EVT_HVN_TX_COMPLETE => gatt_server::on_hvn_tx_complete(&evt.evt.gatts_evt), - - x => depanic!("Unknown ble evt {:u32}", x), +macro_rules! match_event { + ($evt_ptr:ident, $($id:ident => $func:path[$field:ident]),* $(,)? ) => { + let evt = &*$evt_ptr; + defmt::trace!("ble evt {:istr}", evt_str(evt.header.evt_id as u32)); + match evt.header.evt_id as u32 { + $(sd::$id => $func($evt_ptr, get_union_field($evt_ptr, &evt.evt.$field)) ),* , + x => depanic!("Unknown ble evt {:u32}", x), + } }; } #[rustfmt::skip] +pub(crate) unsafe fn on_evt(evt_ptr: *const sd::ble_evt_t) { + match_event!(evt_ptr, + BLE_COMMON_EVTS_BLE_EVT_USER_MEM_REQUEST => on_user_mem_request[common_evt], + BLE_COMMON_EVTS_BLE_EVT_USER_MEM_RELEASE => on_user_mem_release[common_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_CONNECTED => gap::on_connected[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => gap::on_disconnected[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_CONN_PARAM_UPDATE => gap::on_conn_param_update[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_SEC_PARAMS_REQUEST => gap::on_sec_params_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_SEC_INFO_REQUEST => gap::on_sec_info_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_PASSKEY_DISPLAY => gap::on_passkey_display[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_KEY_PRESSED => gap::on_key_pressed[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_AUTH_KEY_REQUEST => gap::on_auth_key_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_LESC_DHKEY_REQUEST => gap::on_lesc_dhkey_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_AUTH_STATUS => gap::on_auth_status[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_CONN_SEC_UPDATE => gap::on_conn_sec_update[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_TIMEOUT => gap::on_timeout[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_RSSI_CHANGED => gap::on_rssi_changed[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_ADV_REPORT => gap::on_adv_report[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_SEC_REQUEST => gap::on_sec_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST => gap::on_conn_param_update_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_SCAN_REQ_REPORT => gap::on_scan_req_report[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_PHY_UPDATE_REQUEST => gap::on_phy_update_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_PHY_UPDATE => gap::on_phy_update[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST => gap::on_data_length_update_request[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_DATA_LENGTH_UPDATE => gap::on_data_length_update[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT => gap::on_qos_channel_survey_report[gap_evt], + BLE_GAP_EVTS_BLE_GAP_EVT_ADV_SET_TERMINATED => gap::on_adv_set_terminated[gap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP_REQUEST => l2cap::on_ch_setup_request[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP_REFUSED => l2cap::on_ch_setup_refused[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP => l2cap::on_ch_setup[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RELEASED => l2cap::on_ch_released[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED => l2cap::on_ch_sdu_buf_released[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_CREDIT => l2cap::on_ch_credit[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RX => l2cap::on_ch_rx[l2cap_evt], + BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_TX => l2cap::on_ch_tx[l2cap_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP => gatt_client::on_prim_srvc_disc_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_REL_DISC_RSP => gatt_client::on_rel_disc_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_DISC_RSP => gatt_client::on_char_disc_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_DESC_DISC_RSP => gatt_client::on_desc_disc_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_ATTR_INFO_DISC_RSP => gatt_client::on_attr_info_disc_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP => gatt_client::on_char_val_by_uuid_read_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_READ_RSP => gatt_client::on_read_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_VALS_READ_RSP => gatt_client::on_char_vals_read_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_WRITE_RSP => gatt_client::on_write_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_HVX => gatt_client::on_hvx[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_EXCHANGE_MTU_RSP => gatt_client::on_exchange_mtu_rsp[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_TIMEOUT => gatt_client::on_timeout[gattc_evt], + BLE_GATTC_EVTS_BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE => gatt_client::on_write_cmd_tx_complete[gattc_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_WRITE => gatt_server::on_write[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST => gatt_server::on_rw_authorize_request[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_SYS_ATTR_MISSING => gatt_server::on_sys_attr_missing[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_HVC => gatt_server::on_hvc[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_SC_CONFIRM => gatt_server::on_sc_confirm[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST => gatt_server::on_exchange_mtu_request[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_TIMEOUT => gatt_server::on_timeout[gatts_evt], + BLE_GATTS_EVTS_BLE_GATTS_EVT_HVN_TX_COMPLETE => gatt_server::on_hvn_tx_complete[gatts_evt], + ); +} + +#[rustfmt::skip] fn evt_str(evt: u32) -> defmt::Str { match evt { sd::BLE_COMMON_EVTS_BLE_EVT_USER_MEM_REQUEST => defmt::intern!("USER_MEM_REQUEST"), diff --git a/nrf-softdevice/src/util/mod.rs b/nrf-softdevice/src/util/mod.rs index 72f77c4..f447e1f 100644 --- a/nrf-softdevice/src/util/mod.rs +++ b/nrf-softdevice/src/util/mod.rs @@ -10,3 +10,49 @@ mod drop_bomb; pub use drop_bomb::*; pub(crate) use defmt::{debug, error, info, trace, warn}; + +use crate::sd; + +/// Create a slice from a variable-length array in a BLE event. +/// +/// This function is a workaround for UB in __IncompleteArrayField +/// see https://github.com/rust-lang/rust-bindgen/issues/1892 +/// see https://github.com/rust-lang/unsafe-code-guidelines/issues/134 +pub(crate) unsafe fn get_flexarray<T>( + orig_ptr: *const sd::ble_evt_t, + array: &sd::__IncompleteArrayField<T>, + count: usize, +) -> &[T] { + let offs = array.as_ptr() as usize - orig_ptr as usize; + let sanitized_ptr = (orig_ptr as *const u8).add(offs) as *const T; + core::slice::from_raw_parts(sanitized_ptr, count) +} + +/// Create a slice from a variable-length array in a BLE event. +/// +/// This function is a workaround for UB in __IncompleteArrayField +/// see https://github.com/rust-lang/rust-bindgen/issues/1892 +/// see https://github.com/rust-lang/unsafe-code-guidelines/issues/134 +pub(crate) unsafe fn get_flexarray2<T>( + orig_ptr: *const sd::ble_evt_t, + array: &[T; 0], + count: usize, +) -> &[T] { + let offs = array.as_ptr() as usize - orig_ptr as usize; + let sanitized_ptr = (orig_ptr as *const u8).add(offs) as *const T; + core::slice::from_raw_parts(sanitized_ptr, count) +} + +/// Get a &T from a __BindgenUnionField<T> in a BLE event. +/// +/// This function is a workaround for UB in __BindgenUnionField +/// see https://github.com/rust-lang/rust-bindgen/issues/1892 +/// see https://github.com/rust-lang/unsafe-code-guidelines/issues/134 +pub(crate) unsafe fn get_union_field<T>( + orig_ptr: *const sd::ble_evt_t, + member: &sd::__BindgenUnionField<T>, +) -> &T { + let offs = member as *const _ as usize - orig_ptr as usize; + let sanitized_ptr = (orig_ptr as *const u8).add(offs) as *const T; + &*sanitized_ptr +} |