diff options
author | 2024-06-14 11:31:29 -0700 | |
---|---|---|
committer | 2024-06-14 11:53:56 -0700 | |
commit | 0d0ce8597e1cd19affd50fa8d88843e3f62383ec (patch) | |
tree | a9323a40c29403260bc0ba5d6be8c1ac35008903 | |
parent | 5978a92641d8e3b1cb9d84b9a6327127fdbe1b39 (diff) |
system/rust: Update GATT packet definition to use 8[] for ATT values
Bug: 331817295
Test: m com.android.btservices
Test: atest --host libbluetooth_core_rs_test
Flag: EXEMPT, mechanical refactor
Change-Id: Ia8b5fbf470df7ed3d20fced5339beb136e3aa9ba
-rw-r--r-- | system/rust/src/gatt/ffi.rs | 4 | ||||
-rw-r--r-- | system/rust/src/gatt/server/att_server_bearer.rs | 104 | ||||
-rw-r--r-- | system/rust/src/gatt/server/command_handler.rs | 11 | ||||
-rw-r--r-- | system/rust/src/gatt/server/gatt_database.rs | 69 | ||||
-rw-r--r-- | system/rust/src/gatt/server/indication_handler.rs | 48 | ||||
-rw-r--r-- | system/rust/src/gatt/server/request_handler.rs | 11 | ||||
-rw-r--r-- | system/rust/src/gatt/server/services/gatt.rs | 18 | ||||
-rw-r--r-- | system/rust/src/gatt/server/transactions/find_by_type_value.rs | 18 | ||||
-rw-r--r-- | system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs | 26 | ||||
-rw-r--r-- | system/rust/src/gatt/server/transactions/read_by_group_type_request.rs | 18 | ||||
-rw-r--r-- | system/rust/src/gatt/server/transactions/read_by_type_request.rs | 16 | ||||
-rw-r--r-- | system/rust/src/gatt/server/transactions/read_request.rs | 18 | ||||
-rw-r--r-- | system/rust/src/gatt/server/transactions/write_request.rs | 14 | ||||
-rw-r--r-- | system/rust/src/packets.pdl | 22 | ||||
-rw-r--r-- | system/rust/src/utils/packet.rs | 8 | ||||
-rw-r--r-- | system/rust/tests/gatt_server_test.rs | 69 |
16 files changed, 183 insertions, 291 deletions
diff --git a/system/rust/src/gatt/ffi.rs b/system/rust/src/gatt/ffi.rs index d5a9ec7a2d..965383edef 100644 --- a/system/rust/src/gatt/ffi.rs +++ b/system/rust/src/gatt/ffi.rs @@ -12,7 +12,7 @@ use tokio::task::spawn_local; use crate::{ do_in_rust_thread, - packets::{AttAttributeDataChild, AttBuilder, AttErrorCode, Serializable, SerializeError}, + packets::{AttBuilder, AttErrorCode, Serializable, SerializeError}, }; use super::{ @@ -438,7 +438,7 @@ fn send_response(_server_id: u8, conn_id: u16, trans_id: u32, status: u8, value: fn send_indication(_server_id: u8, handle: u16, conn_id: u16, value: &[u8]) { let handle = AttHandle(handle); let conn_id = ConnectionId(conn_id); - let value = AttAttributeDataChild::RawData(value.into()); + let value = value.into(); trace!("send_indication {handle:?}, {conn_id:?}"); diff --git a/system/rust/src/gatt/server/att_server_bearer.rs b/system/rust/src/gatt/server/att_server_bearer.rs index d2d732fc7a..b6ba9c5ebb 100644 --- a/system/rust/src/gatt/server/att_server_bearer.rs +++ b/system/rust/src/gatt/server/att_server_bearer.rs @@ -19,8 +19,8 @@ use crate::{ opcode_types::{classify_opcode, OperationType}, }, packets::{ - AttAttributeDataChild, AttBuilder, AttChild, AttErrorCode, AttErrorResponseBuilder, - AttView, Packet, SerializeError, + AttBuilder, AttChild, AttErrorCode, AttErrorResponseBuilder, AttView, Packet, + SerializeError, }, utils::{owned_handle::OwnedHandle, packet::HACK_child_to_opcode}, }; @@ -118,7 +118,7 @@ impl<T: AttDatabase + Clone + 'static> WeakBoxRef<'_, AttServerBearer<T>> { pub fn send_indication( &self, handle: AttHandle, - data: AttAttributeDataChild, + data: Vec<u8>, ) -> impl Future<Output = Result<(), IndicationError>> { trace!("sending indication for handle {handle:?}"); @@ -143,7 +143,7 @@ impl<T: AttDatabase + Clone + 'static> WeakBoxRef<'_, AttServerBearer<T>> { IndicationError::SendError(SendError::ConnectionDropped) })?; // finally, send, and wait for a response - indication_handler.send(handle, data, mtu, |packet| this.try_send_packet(packet)).await + indication_handler.send(handle, &data, mtu, |packet| this.try_send_packet(packet)).await } } @@ -238,8 +238,8 @@ mod test { }, }, packets::{ - AttAttributeDataBuilder, AttAttributeDataChild, AttHandleValueConfirmationBuilder, - AttOpcode, AttReadRequestBuilder, AttReadResponseBuilder, + AttHandleValueConfirmationBuilder, AttOpcode, AttReadRequestBuilder, + AttReadResponseBuilder, }, utils::{ packet::build_att_view_or_crash, @@ -389,14 +389,7 @@ mod test { resp, AttBuilder { opcode: AttOpcode::READ_RESPONSE, - _child_: AttReadResponseBuilder { - value: AttAttributeDataBuilder { - _child_: AttAttributeDataChild::RawData( - data.to_vec().into_boxed_slice() - ) - }, - } - .into() + _child_: AttReadResponseBuilder { value: data.into() }.into() } ); // assert no other replies were made @@ -414,10 +407,7 @@ mod test { // act: send an indication let pending_send = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); assert_eq!(rx.recv().await.unwrap().opcode, AttOpcode::HANDLE_VALUE_INDICATION); assert_eq!(rx.try_recv(), Err(TryRecvError::Empty)); // and the confirmation @@ -438,10 +428,7 @@ mod test { // act: send the first indication let pending_send1 = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); // wait for/capture the outgoing packet let sent1 = rx.recv().await.unwrap(); // send the response @@ -450,10 +437,7 @@ mod test { ); // send the second indication let pending_send2 = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); // wait for/capture the outgoing packet let sent2 = rx.recv().await.unwrap(); // and the response @@ -479,14 +463,9 @@ mod test { // act: send two indications simultaneously let pending_send1 = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); - let pending_send2 = spawn_local(conn.as_ref().send_indication( - ANOTHER_VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); + let pending_send2 = + spawn_local(conn.as_ref().send_indication(ANOTHER_VALID_HANDLE, vec![1, 2, 3])); // assert: only one was initially sent assert_eq!(rx.recv().await.unwrap().opcode, AttOpcode::HANDLE_VALUE_INDICATION); assert_eq!(rx.try_recv(), Err(TryRecvError::Empty)); @@ -504,14 +483,9 @@ mod test { // act: send two indications simultaneously let pending_send1 = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); - let pending_send2 = spawn_local(conn.as_ref().send_indication( - ANOTHER_VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); + let pending_send2 = + spawn_local(conn.as_ref().send_indication(ANOTHER_VALID_HANDLE, vec![1, 2, 3])); // wait for/capture the outgoing packet let sent1 = rx.recv().await.unwrap(); // send response for the first one @@ -540,14 +514,9 @@ mod test { // act: send two indications simultaneously let pending_send1 = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); - let pending_send2 = spawn_local(conn.as_ref().send_indication( - ANOTHER_VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); + let pending_send2 = + spawn_local(conn.as_ref().send_indication(ANOTHER_VALID_HANDLE, vec![1, 2, 3])); // wait for/capture the outgoing packet let sent1 = rx.recv().await.unwrap(); // send response for the first one @@ -577,10 +546,7 @@ mod test { // arrange: a pending indication let (conn, mut rx) = open_connection(); let pending_send = - spawn_local(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )); + spawn_local(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])); // act: drop the connection after the indication is sent rx.recv().await.unwrap(); @@ -602,12 +568,7 @@ mod test { conn.as_ref().handle_mtu_event(MtuEvent::OutgoingRequest).unwrap(); // act: try to send an indication with a large payload size - let _ = - try_await(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData((1..50).collect()), - )) - .await; + let _ = try_await(conn.as_ref().send_indication(VALID_HANDLE, (1..50).collect())).await; // then resolve the MTU negotiation with a large MTU conn.as_ref().handle_mtu_event(MtuEvent::IncomingResponse(100)).unwrap(); @@ -625,12 +586,9 @@ mod test { // act: try to send an indication with a large payload size let pending_mtu = - try_await(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData((1..50).collect()), - )) - .await - .unwrap_err(); + try_await(conn.as_ref().send_indication(VALID_HANDLE, (1..50).collect())) + .await + .unwrap_err(); // then resolve the MTU negotiation with a small MTU conn.as_ref().handle_mtu_event(MtuEvent::IncomingResponse(32)).unwrap(); @@ -664,21 +622,11 @@ mod test { block_on_locally(async { // arrange: an outstanding indication let (conn, mut rx) = open_connection(); - let _ = - try_await(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - )) - .await; + let _ = try_await(conn.as_ref().send_indication(VALID_HANDLE, vec![1, 2, 3])).await; rx.recv().await.unwrap(); // flush rx_queue // act: enqueue an indication with a large payload - let _ = - try_await(conn.as_ref().send_indication( - VALID_HANDLE, - AttAttributeDataChild::RawData((1..50).collect()), - )) - .await; + let _ = try_await(conn.as_ref().send_indication(VALID_HANDLE, (1..50).collect())).await; // then perform MTU negotiation to upgrade to a large MTU conn.as_ref().handle_mtu_event(MtuEvent::OutgoingRequest).unwrap(); conn.as_ref().handle_mtu_event(MtuEvent::IncomingResponse(512)).unwrap(); diff --git a/system/rust/src/gatt/server/command_handler.rs b/system/rust/src/gatt/server/command_handler.rs index a147584da9..763c68f7d0 100644 --- a/system/rust/src/gatt/server/command_handler.rs +++ b/system/rust/src/gatt/server/command_handler.rs @@ -24,7 +24,7 @@ impl<Db: AttDatabase> AttCommandHandler<Db> { }; snapshotted_db.write_no_response_attribute( packet.get_handle().into(), - &packet.get_value().get_raw_payload().collect::<Vec<_>>(), + &packet.get_value_iter().collect::<Vec<_>>(), ); } _ => { @@ -47,10 +47,7 @@ mod test { test::test_att_db::TestAttDatabase, }, }, - packets::{ - AttAttributeDataBuilder, AttAttributeDataChild, AttErrorCode, AttErrorResponseBuilder, - AttOpcode, AttWriteCommandBuilder, - }, + packets::{AttErrorCode, AttErrorResponseBuilder, AttOpcode, AttWriteCommandBuilder}, utils::{packet::build_att_view_or_crash, task::block_on_locally}, }; @@ -71,9 +68,7 @@ mod test { // act: send write command let att_view = build_att_view_or_crash(AttWriteCommandBuilder { handle: AttHandle(3).into(), - value: AttAttributeDataBuilder { - _child_: AttAttributeDataChild::RawData(data.to_vec().into_boxed_slice()), - }, + value: data.into(), }); handler.process_packet(att_view.view()); diff --git a/system/rust/src/gatt/server/gatt_database.rs b/system/rust/src/gatt/server/gatt_database.rs index baffd17773..b1c688f0a7 100644 --- a/system/rust/src/gatt/server/gatt_database.rs +++ b/system/rust/src/gatt/server/gatt_database.rs @@ -521,7 +521,6 @@ mod test { mock_datastore::{MockDatastore, MockDatastoreEvents}, mock_raw_datastore::{MockRawDatastore, MockRawDatastoreEvents}, }, - packets::AttAttributeDataChild, utils::task::block_on_locally, }; @@ -578,11 +577,9 @@ mod test { ); assert_eq!( service_value, - AttAttributeDataChild::GattServiceDeclarationValue( - GattServiceDeclarationValueBuilder { uuid: SERVICE_TYPE.into() } - ) - .to_vec() - .map_err(|_| AttErrorCode::UNLIKELY_ERROR) + GattServiceDeclarationValueBuilder { uuid: SERVICE_TYPE.into() } + .to_vec() + .map_err(|_| AttErrorCode::UNLIKELY_ERROR) ); } @@ -717,22 +714,20 @@ mod test { assert_eq!( characteristic_decl, - AttAttributeDataChild::GattCharacteristicDeclarationValue( - GattCharacteristicDeclarationValueBuilder { - properties: GattCharacteristicPropertiesBuilder { - read: 1, - broadcast: 0, - write_without_response: 0, - write: 1, - notify: 0, - indicate: 1, - authenticated_signed_writes: 0, - extended_properties: 0, - }, - handle: CHARACTERISTIC_VALUE_HANDLE.into(), - uuid: CHARACTERISTIC_TYPE.into() - } - ) + GattCharacteristicDeclarationValueBuilder { + properties: GattCharacteristicPropertiesBuilder { + read: 1, + broadcast: 0, + write_without_response: 0, + write: 1, + notify: 0, + indicate: 1, + authenticated_signed_writes: 0, + extended_properties: 0, + }, + handle: CHARACTERISTIC_VALUE_HANDLE.into(), + uuid: CHARACTERISTIC_TYPE.into() + } .to_vec() .map_err(|_| AttErrorCode::UNLIKELY_ERROR) ); @@ -767,22 +762,20 @@ mod test { tokio_test::block_on(att_db.read_attribute(CHARACTERISTIC_DECLARATION_HANDLE)); assert_eq!( characteristic_decl, - AttAttributeDataChild::GattCharacteristicDeclarationValue( - GattCharacteristicDeclarationValueBuilder { - properties: GattCharacteristicPropertiesBuilder { - read: 1, - broadcast: 0, - write_without_response: 1, - write: 1, - notify: 0, - indicate: 1, - authenticated_signed_writes: 0, - extended_properties: 0, - }, - handle: CHARACTERISTIC_VALUE_HANDLE.into(), - uuid: CHARACTERISTIC_TYPE.into() - } - ) + GattCharacteristicDeclarationValueBuilder { + properties: GattCharacteristicPropertiesBuilder { + read: 1, + broadcast: 0, + write_without_response: 1, + write: 1, + notify: 0, + indicate: 1, + authenticated_signed_writes: 0, + extended_properties: 0, + }, + handle: CHARACTERISTIC_VALUE_HANDLE.into(), + uuid: CHARACTERISTIC_TYPE.into() + } .to_vec() .map_err(|_| AttErrorCode::UNLIKELY_ERROR) ); diff --git a/system/rust/src/gatt/server/indication_handler.rs b/system/rust/src/gatt/server/indication_handler.rs index c69a68f91c..0a06003a7b 100644 --- a/system/rust/src/gatt/server/indication_handler.rs +++ b/system/rust/src/gatt/server/indication_handler.rs @@ -8,8 +8,7 @@ use tokio::{ use crate::{ gatt::ids::AttHandle, - packets::{AttAttributeDataChild, AttChild, AttHandleValueIndicationBuilder, Serializable}, - utils::packet::build_att_data, + packets::{AttChild, AttHandleValueIndicationBuilder}, }; use super::{ @@ -52,17 +51,14 @@ impl<T: AttDatabase> IndicationHandler<T> { pub async fn send( &mut self, handle: AttHandle, - data: AttAttributeDataChild, + data: &[u8], mtu: usize, send_packet: impl FnOnce(AttChild) -> Result<(), SendError>, ) -> Result<(), IndicationError> { - let data_size = data - .size_in_bits() - .map_err(SendError::SerializeError) - .map_err(IndicationError::SendError)?; + let data_size = data.len(); // As per Core Spec 5.3 Vol 3F 3.4.7.2, the indicated value must be at most // ATT_MTU-3 - if data_size > (mtu - 3) * 8 { + if data_size > (mtu - 3) { return Err(IndicationError::DataExceedsMtu { mtu: mtu - 3 }); } @@ -82,8 +78,7 @@ impl<T: AttDatabase> IndicationHandler<T> { let _ = self.pending_confirmation.try_recv(); send_packet( - AttHandleValueIndicationBuilder { handle: handle.into(), value: build_att_data(data) } - .into(), + AttHandleValueIndicationBuilder { handle: handle.into(), value: data.into() }.into(), ) .map_err(IndicationError::SendError)?; @@ -138,10 +133,7 @@ mod test { const NONEXISTENT_HANDLE: AttHandle = AttHandle(2); const NON_INDICATE_HANDLE: AttHandle = AttHandle(3); const MTU: usize = 32; - - fn get_data() -> AttAttributeDataChild { - AttAttributeDataChild::RawData([1, 2, 3].into()) - } + const DATA: [u8; 3] = [1, 2, 3]; fn get_att_database() -> TestAttDatabase { TestAttDatabase::new(vec![ @@ -175,7 +167,7 @@ mod test { // act: send an indication spawn_local(async move { indication_handler - .send(HANDLE, get_data(), MTU, move |packet| { + .send(HANDLE, &DATA, MTU, move |packet| { tx.send(packet).unwrap(); Ok(()) }) @@ -188,10 +180,7 @@ mod test { }; assert_eq!( indication, - AttHandleValueIndicationBuilder { - handle: HANDLE.into(), - value: build_att_data(get_data()), - } + AttHandleValueIndicationBuilder { handle: HANDLE.into(), value: DATA.into() } ); }); } @@ -205,7 +194,7 @@ mod test { // act: send an indication on a nonexistent handle let ret = indication_handler - .send(NONEXISTENT_HANDLE, get_data(), MTU, move |_| unreachable!()) + .send(NONEXISTENT_HANDLE, &DATA, MTU, move |_| unreachable!()) .await; // assert: that we failed with IndicationError::AttributeNotFound @@ -222,7 +211,7 @@ mod test { // act: send an indication on an attribute that does not support indications let ret = indication_handler - .send(NON_INDICATE_HANDLE, get_data(), MTU, move |_| unreachable!()) + .send(NON_INDICATE_HANDLE, &DATA, MTU, move |_| unreachable!()) .await; // assert: that we failed with IndicationError::IndicationsNotSupported @@ -241,7 +230,7 @@ mod test { // act: send an indication let pending_result = spawn_local(async move { indication_handler - .send(HANDLE, get_data(), MTU, move |packet| { + .send(HANDLE, &DATA, MTU, move |packet| { tx.send(packet).unwrap(); Ok(()) }) @@ -267,7 +256,7 @@ mod test { // act: send an indication let pending_result = spawn_local(async move { indication_handler - .send(HANDLE, get_data(), MTU, move |packet| { + .send(HANDLE, &DATA, MTU, move |packet| { tx.send(packet).unwrap(); Ok(()) }) @@ -299,7 +288,7 @@ mod test { // act: send an indication let pending_result = spawn_local(async move { indication_handler - .send(HANDLE, get_data(), MTU, move |packet| { + .send(HANDLE, &DATA, MTU, move |packet| { tx.send(packet).unwrap(); Ok(()) }) @@ -334,7 +323,7 @@ mod test { let time_sent = Instant::now(); let pending_result = spawn_local(async move { indication_handler - .send(HANDLE, get_data(), MTU, move |packet| { + .send(HANDLE, &DATA, MTU, move |packet| { tx.send(packet).unwrap(); Ok(()) }) @@ -365,14 +354,7 @@ mod test { IndicationHandler::new(get_att_database()); // act: send an indication with an ATT_MTU of 4 and data length of 3 - let res = indication_handler - .send( - HANDLE, - AttAttributeDataChild::RawData([1, 2, 3].into()), - 4, - move |_| unreachable!(), - ) - .await; + let res = indication_handler.send(HANDLE, &[1, 2, 3], 4, move |_| unreachable!()).await; // assert: that we got the expected error, indicating the max data size (not the // ATT_MTU, but ATT_MTU-3) diff --git a/system/rust/src/gatt/server/request_handler.rs b/system/rust/src/gatt/server/request_handler.rs index e6890803d0..74cbb7f3e0 100644 --- a/system/rust/src/gatt/server/request_handler.rs +++ b/system/rust/src/gatt/server/request_handler.rs @@ -110,11 +110,8 @@ mod test { request_handler::AttRequestHandler, test::test_att_db::TestAttDatabase, }, - packets::{ - AttAttributeDataChild, AttReadRequestBuilder, AttReadResponseBuilder, - AttWriteResponseBuilder, - }, - utils::packet::{build_att_data, build_att_view_or_crash}, + packets::{AttReadRequestBuilder, AttReadResponseBuilder, AttWriteResponseBuilder}, + utils::packet::build_att_view_or_crash, }; #[test] @@ -139,9 +136,7 @@ mod test { // assert assert_eq!( response, - AttChild::AttReadResponse(AttReadResponseBuilder { - value: build_att_data(AttAttributeDataChild::RawData([1, 2, 3].into())) - }) + AttChild::AttReadResponse(AttReadResponseBuilder { value: [1, 2, 3].into() }) ); } diff --git a/system/rust/src/gatt/server/services/gatt.rs b/system/rust/src/gatt/server/services/gatt.rs index 5bb6ce5f89..6ba8e90238 100644 --- a/system/rust/src/gatt/server/services/gatt.rs +++ b/system/rust/src/gatt/server/services/gatt.rs @@ -135,7 +135,8 @@ impl GattDatabaseCallbacks for GattService { start_handle: (*range.start()).into(), end_handle: (*range.end()).into(), } - .into(), + .to_vec() + .unwrap(), ), ); } @@ -190,7 +191,7 @@ mod test { }, }, }, - packets::{AttAttributeDataChild, AttBuilder, AttChild}, + packets::{AttBuilder, AttChild}, utils::task::{block_on_locally, try_await}, }; @@ -369,11 +370,14 @@ mod test { let AttChild::AttHandleValueIndication(resp) = resp._child_ else { unreachable!(); }; - let AttAttributeDataChild::GattServiceChanged(resp) = resp.value._child_ else { - unreachable!(); - }; - assert_eq!(resp.start_handle.handle, 15); - assert_eq!(resp.end_handle.handle, 17); + assert_eq!( + Ok(resp.value.into()), + GattServiceChangedBuilder { + start_handle: AttHandle(15).into(), + end_handle: AttHandle(17).into(), + } + .to_vec() + ); }); } diff --git a/system/rust/src/gatt/server/transactions/find_by_type_value.rs b/system/rust/src/gatt/server/transactions/find_by_type_value.rs index 5a7cbb280a..d3a463084a 100644 --- a/system/rust/src/gatt/server/transactions/find_by_type_value.rs +++ b/system/rust/src/gatt/server/transactions/find_by_type_value.rs @@ -43,7 +43,7 @@ pub async fn handle_find_by_type_value_request( continue; } if let Ok(value) = db.read_attribute(handle).await { - if value == request.get_attribute_value().get_raw_payload().collect::<Vec<_>>() { + if value == request.get_attribute_value_iter().collect::<Vec<_>>() { // match found if !matches.push(AttributeHandleRangeBuilder { found_attribute_handle: handle.into(), @@ -84,8 +84,8 @@ mod test { test::test_att_db::TestAttDatabase, }, }, - packets::{AttAttributeDataChild, AttFindByTypeValueRequestBuilder}, - utils::packet::{build_att_data, build_view_or_crash}, + packets::AttFindByTypeValueRequestBuilder, + utils::packet::build_view_or_crash, }; use super::*; @@ -131,7 +131,7 @@ mod test { starting_handle: AttHandle(3).into(), ending_handle: AttHandle(5).into(), attribute_type: UUID.try_into().unwrap(), - attribute_value: build_att_data(AttAttributeDataChild::RawData(VALUE.into())), + attribute_value: VALUE.into(), }); let response = tokio_test::block_on(handle_find_by_type_value_request(att_view.view(), 128, &db)); @@ -193,7 +193,7 @@ mod test { starting_handle: AttHandle(3).into(), ending_handle: AttHandle(5).into(), attribute_type: UUID.try_into().unwrap(), - attribute_value: build_att_data(AttAttributeDataChild::RawData(VALUE.into())), + attribute_value: VALUE.into(), }); let response = tokio_test::block_on(handle_find_by_type_value_request(att_view.view(), 128, &db)); @@ -230,7 +230,7 @@ mod test { starting_handle: AttHandle(3).into(), ending_handle: AttHandle(1).into(), attribute_type: UUID.try_into().unwrap(), - attribute_value: build_att_data(AttAttributeDataChild::RawData(VALUE.into())), + attribute_value: VALUE.into(), }); let response = tokio_test::block_on(handle_find_by_type_value_request(att_view.view(), 128, &db)); @@ -264,7 +264,7 @@ mod test { starting_handle: AttHandle(4).into(), ending_handle: AttHandle(5).into(), attribute_type: UUID.try_into().unwrap(), - attribute_value: build_att_data(AttAttributeDataChild::RawData(VALUE.into())), + attribute_value: VALUE.into(), }); let response = tokio_test::block_on(handle_find_by_type_value_request(att_view.view(), 128, &db)); @@ -316,7 +316,7 @@ mod test { starting_handle: AttHandle(3).into(), ending_handle: AttHandle(4).into(), attribute_type: CHARACTERISTIC_UUID.try_into().unwrap(), - attribute_value: build_att_data(AttAttributeDataChild::RawData(VALUE.into())), + attribute_value: VALUE.into(), }); let response = tokio_test::block_on(handle_find_by_type_value_request(att_view.view(), 128, &db)); @@ -364,7 +364,7 @@ mod test { starting_handle: AttHandle(3).into(), ending_handle: AttHandle(4).into(), attribute_type: UUID.try_into().unwrap(), - attribute_value: build_att_data(AttAttributeDataChild::RawData(VALUE.into())), + attribute_value: VALUE.into(), }); let response = tokio_test::block_on(handle_find_by_type_value_request(att_view.view(), 5, &db)); diff --git a/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs b/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs index 52abe8c5c2..ac93459bcf 100644 --- a/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs +++ b/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs @@ -4,7 +4,7 @@ use crate::{ core::uuid::Uuid, gatt::server::att_database::{AttAttribute, StableAttDatabase}, - packets::{AttAttributeDataChild, AttErrorCode}, + packets::AttErrorCode, }; /// An attribute and the value @@ -12,7 +12,7 @@ use crate::{ pub struct AttributeWithValue { /// The attribute pub attr: AttAttribute, - pub value: AttAttributeDataChild, + pub value: Vec<u8>, } /// Takes a StableAttDatabase, a range of handles, a target type, and a @@ -49,10 +49,7 @@ pub async fn filter_read_attributes_by_size_type( curr_elem_size = Some(value_size) } - out.push(AttributeWithValue { - attr, - value: AttAttributeDataChild::RawData(value.into_boxed_slice()), - }); + out.push(AttributeWithValue { attr, value }); } Err(err) => { if out.is_empty() { @@ -80,7 +77,6 @@ mod test { test::test_att_db::TestAttDatabase, }, }, - packets::AttAttributeDataChild, }; const UUID: Uuid = Uuid::new(1234); @@ -112,7 +108,7 @@ mod test { response.collect::<Vec<_>>(), vec![AttributeWithValue { attr: db.find_attribute(AttHandle(3)).unwrap(), - value: AttAttributeDataChild::RawData([4, 5].into()) + value: vec![4, 5] }] ) } @@ -162,11 +158,11 @@ mod test { vec![ AttributeWithValue { attr: db.find_attribute(AttHandle(3)).unwrap(), - value: AttAttributeDataChild::RawData([4, 5].into()) + value: vec![4, 5], }, AttributeWithValue { attr: db.find_attribute(AttHandle(6)).unwrap(), - value: AttAttributeDataChild::RawData([6, 7].into()) + value: vec![6, 7], } ] ); @@ -216,7 +212,7 @@ mod test { response.collect::<Vec<_>>(), vec![AttributeWithValue { attr: db.find_attribute(AttHandle(3)).unwrap(), - value: AttAttributeDataChild::RawData([4, 5].into()) + value: vec![4, 5], },] ); } @@ -247,7 +243,7 @@ mod test { response.collect::<Vec<_>>(), vec![AttributeWithValue { attr: db.find_attribute(AttHandle(3)).unwrap(), - value: AttAttributeDataChild::RawData([4, 5].into()) + value: vec![4, 5], },] ); } @@ -340,7 +336,7 @@ mod test { response.collect::<Vec<_>>(), vec![AttributeWithValue { attr: db.find_attribute(AttHandle(3)).unwrap(), - value: AttAttributeDataChild::RawData([4, 5, 6].into()) + value: vec![4, 5, 6], },] ); } @@ -391,11 +387,11 @@ mod test { vec![ AttributeWithValue { attr: db.find_attribute(AttHandle(3)).unwrap(), - value: AttAttributeDataChild::RawData([4, 5, 6].into()) + value: vec![4, 5, 6], }, AttributeWithValue { attr: db.find_attribute(AttHandle(5)).unwrap(), - value: AttAttributeDataChild::RawData([6, 7, 8].into()) + value: vec![6, 7, 8], } ] ); diff --git a/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs b/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs index 5e53222022..762b8ce196 100644 --- a/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs +++ b/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs @@ -8,7 +8,7 @@ use crate::{ }, }, packets::{ - AttAttributeDataBuilder, AttChild, AttErrorCode, AttErrorResponseBuilder, AttOpcode, + AttChild, AttErrorCode, AttErrorResponseBuilder, AttOpcode, AttReadByGroupTypeDataElementBuilder, AttReadByGroupTypeRequestView, AttReadByGroupTypeResponseBuilder, ParseError, }, @@ -74,7 +74,7 @@ pub async fn handle_read_by_group_type_request( .expect("should never be None, since grouping UUID was validated earlier") .handle .into(), - value: AttAttributeDataBuilder { _child_: value }, + value: value.into(), }) { break; } @@ -104,8 +104,8 @@ mod test { test::test_att_db::TestAttDatabase, }, }, - packets::{AttAttributeDataChild, AttReadByGroupTypeRequestBuilder}, - utils::packet::{build_att_data, build_view_or_crash}, + packets::AttReadByGroupTypeRequestBuilder, + utils::packet::build_view_or_crash, }; use super::*; @@ -161,12 +161,12 @@ mod test { AttReadByGroupTypeDataElementBuilder { handle: AttHandle(3).into(), end_group_handle: AttHandle(4).into(), - value: build_att_data(AttAttributeDataChild::RawData([4, 5].into())), + value: [4, 5].into(), }, AttReadByGroupTypeDataElementBuilder { handle: AttHandle(5).into(), end_group_handle: AttHandle(5).into(), - value: build_att_data(AttAttributeDataChild::RawData([6, 7].into())), + value: [6, 7].into(), }, ] .into() @@ -261,7 +261,7 @@ mod test { data: [AttReadByGroupTypeDataElementBuilder { handle: AttHandle(3).into(), end_group_handle: AttHandle(3).into(), - value: build_att_data(AttAttributeDataChild::RawData([1].into())), + value: [1].into(), },] .into() } @@ -310,7 +310,7 @@ mod test { data: [AttReadByGroupTypeDataElementBuilder { handle: AttHandle(3).into(), end_group_handle: AttHandle(3).into(), - value: build_att_data(AttAttributeDataChild::RawData([4, 5, 6].into())) + value: [4, 5, 6].into() },] .into() } @@ -360,7 +360,7 @@ mod test { data: [AttReadByGroupTypeDataElementBuilder { handle: AttHandle(3).into(), end_group_handle: AttHandle(4).into(), - value: build_att_data(AttAttributeDataChild::RawData([4, 5].into())), + value: [4, 5].into(), },] .into() } diff --git a/system/rust/src/gatt/server/transactions/read_by_type_request.rs b/system/rust/src/gatt/server/transactions/read_by_type_request.rs index 6d663b2536..83a1b0862a 100644 --- a/system/rust/src/gatt/server/transactions/read_by_type_request.rs +++ b/system/rust/src/gatt/server/transactions/read_by_type_request.rs @@ -2,7 +2,7 @@ use crate::{ core::uuid::Uuid, gatt::{ids::AttHandle, server::att_database::StableAttDatabase}, packets::{ - AttAttributeDataBuilder, AttChild, AttErrorCode, AttErrorResponseBuilder, AttOpcode, + AttChild, AttErrorCode, AttErrorResponseBuilder, AttOpcode, AttReadByTypeDataElementBuilder, AttReadByTypeRequestView, AttReadByTypeResponseBuilder, ParseError, }, @@ -54,7 +54,7 @@ pub async fn handle_read_by_type_request( for AttributeWithValue { attr, value } in attrs { if !out.push(AttReadByTypeDataElementBuilder { handle: attr.handle.into(), - value: AttAttributeDataBuilder { _child_: value }, + value: value.into_boxed_slice(), }) { break; } @@ -86,8 +86,8 @@ mod test { test::test_att_db::TestAttDatabase, }, }, - packets::{AttAttributeDataChild, AttReadByTypeRequestBuilder}, - utils::packet::{build_att_data, build_view_or_crash}, + packets::AttReadByTypeRequestBuilder, + utils::packet::build_view_or_crash, }; const UUID: Uuid = Uuid::new(1234); @@ -123,7 +123,7 @@ mod test { AttReadByTypeResponseBuilder { data: [AttReadByTypeDataElementBuilder { handle: AttHandle(3).into(), - value: build_att_data(AttAttributeDataChild::RawData([4, 5].into())) + value: [4, 5].into() }] .into() } @@ -180,11 +180,11 @@ mod test { data: [ AttReadByTypeDataElementBuilder { handle: AttHandle(3).into(), - value: build_att_data(AttAttributeDataChild::RawData([4, 5].into())) + value: [4, 5].into() }, AttReadByTypeDataElementBuilder { handle: AttHandle(6).into(), - value: build_att_data(AttAttributeDataChild::RawData([6, 7].into())) + value: [6, 7].into() } ] .into() @@ -232,7 +232,7 @@ mod test { AttReadByTypeResponseBuilder { data: [AttReadByTypeDataElementBuilder { handle: AttHandle(3).into(), - value: build_att_data(AttAttributeDataChild::RawData([4, 5, 6].into())) + value: [4, 5, 6].into() },] .into() } diff --git a/system/rust/src/gatt/server/transactions/read_request.rs b/system/rust/src/gatt/server/transactions/read_request.rs index fb33074c6d..ba4ea3a3fe 100644 --- a/system/rust/src/gatt/server/transactions/read_request.rs +++ b/system/rust/src/gatt/server/transactions/read_request.rs @@ -1,8 +1,7 @@ use crate::{ gatt::server::att_database::AttDatabase, packets::{ - AttAttributeDataBuilder, AttAttributeDataChild, AttChild, AttErrorResponseBuilder, - AttOpcode, AttReadRequestView, AttReadResponseBuilder, + AttChild, AttErrorResponseBuilder, AttOpcode, AttReadRequestView, AttReadResponseBuilder, }, }; @@ -17,12 +16,7 @@ pub async fn handle_read_request<T: AttDatabase>( Ok(mut data) => { // as per 5.3 3F 3.4.4.4 ATT_READ_RSP, we truncate to MTU - 1 data.truncate(mtu - 1); - AttReadResponseBuilder { - value: AttAttributeDataBuilder { - _child_: AttAttributeDataChild::RawData(data.into_boxed_slice()), - }, - } - .into() + AttReadResponseBuilder { value: data.into_boxed_slice() }.into() } Err(error_code) => AttErrorResponseBuilder { opcode_in_error: AttOpcode::READ_REQUEST, @@ -46,8 +40,8 @@ mod test { test::test_att_db::TestAttDatabase, }, }, - packets::{AttAttributeDataChild, AttErrorCode, AttReadRequestBuilder, Serializable}, - utils::packet::{build_att_data, build_view_or_crash}, + packets::{AttErrorCode, AttReadRequestBuilder, Serializable}, + utils::packet::build_view_or_crash, }; fn make_db_with_handle_and_value(handle: u16, value: Vec<u8>) -> TestAttDatabase { @@ -81,9 +75,7 @@ mod test { response.to_vec().unwrap(); // check it serializes assert_eq!( response, - AttChild::AttReadResponse(AttReadResponseBuilder { - value: build_att_data(AttAttributeDataChild::RawData([4, 5].into())) - }) + AttChild::AttReadResponse(AttReadResponseBuilder { value: [4, 5].into() }) ) } diff --git a/system/rust/src/gatt/server/transactions/write_request.rs b/system/rust/src/gatt/server/transactions/write_request.rs index 23a11d9d56..b777c3fd82 100644 --- a/system/rust/src/gatt/server/transactions/write_request.rs +++ b/system/rust/src/gatt/server/transactions/write_request.rs @@ -10,7 +10,7 @@ pub async fn handle_write_request<T: AttDatabase>( db: &T, ) -> AttChild { let handle = request.get_handle().into(); - let value = request.get_value().get_raw_payload().collect::<Vec<_>>(); + let value = request.get_value_iter().collect::<Vec<_>>(); match db.write_attribute(handle, &value).await { Ok(()) => AttWriteResponseBuilder {}.into(), Err(error_code) => AttErrorResponseBuilder { @@ -39,10 +39,10 @@ mod test { }, }, packets::{ - AttAttributeDataBuilder, AttAttributeDataChild, AttChild, AttErrorCode, - AttErrorResponseBuilder, AttWriteRequestBuilder, AttWriteResponseBuilder, + AttChild, AttErrorCode, AttErrorResponseBuilder, AttWriteRequestBuilder, + AttWriteResponseBuilder, }, - utils::packet::{build_att_data, build_view_or_crash}, + utils::packet::build_view_or_crash, }; #[test] @@ -61,9 +61,7 @@ mod test { // act: write to the attribute let att_view = build_view_or_crash(AttWriteRequestBuilder { handle: AttHandle(1).into(), - value: AttAttributeDataBuilder { - _child_: AttAttributeDataChild::RawData(data.clone().into_boxed_slice()), - }, + value: data.clone().into_boxed_slice(), }); let resp = block_on(handle_write_request(att_view.view(), &db)); @@ -86,7 +84,7 @@ mod test { // act: write to the attribute let att_view = build_view_or_crash(AttWriteRequestBuilder { handle: AttHandle(1).into(), - value: build_att_data(AttAttributeDataChild::RawData([1, 2].into())), + value: [1, 2].into(), }); let resp = block_on(handle_write_request(att_view.view(), &db)); diff --git a/system/rust/src/packets.pdl b/system/rust/src/packets.pdl index c8079bec42..77fc970322 100644 --- a/system/rust/src/packets.pdl +++ b/system/rust/src/packets.pdl @@ -133,6 +133,10 @@ struct GattCharacteristicProperties { extended_properties: 1, } +struct AttAttributeData { + _payload_ +} + struct GattCharacteristicDeclarationValue : AttAttributeData { properties: GattCharacteristicProperties, handle: AttHandle, @@ -158,15 +162,11 @@ struct UuidAsAttData : AttAttributeData { uuid: Uuid, } -struct AttAttributeData { - _payload_ -} - packet AttFindByTypeValueRequest : Att(opcode = FIND_BY_TYPE_VALUE_REQUEST) { starting_handle : AttHandle, ending_handle : AttHandle, attribute_type : Uuid16, - attribute_value : AttAttributeData, + attribute_value : 8[], } struct AttributeHandleRange { @@ -187,7 +187,7 @@ packet AttReadByGroupTypeRequest : Att(opcode = READ_BY_GROUP_TYPE_REQUEST) { struct AttReadByGroupTypeDataElement { handle : AttHandle, end_group_handle : AttHandle, - value : AttAttributeData, + value : 8[], } packet AttReadByGroupTypeResponse : Att(opcode = READ_BY_GROUP_TYPE_RESPONSE) { @@ -203,7 +203,7 @@ packet AttReadByTypeRequest : Att(opcode = READ_BY_TYPE_REQUEST) { struct AttReadByTypeDataElement { handle : AttHandle, - value : AttAttributeData, + value : 8[], } packet AttReadByTypeResponse : Att(opcode = READ_BY_TYPE_RESPONSE) { @@ -216,12 +216,12 @@ packet AttReadRequest : Att(opcode = READ_REQUEST) { } packet AttReadResponse : Att(opcode = READ_RESPONSE) { - value: AttAttributeData, + value: 8[], } packet AttWriteRequest : Att(opcode = WRITE_REQUEST) { handle : AttHandle, - value : AttAttributeData, + value : 8[], } packet AttWriteResponse : Att(opcode = WRITE_RESPONSE) {} @@ -234,7 +234,7 @@ packet AttErrorResponse : Att(opcode = ERROR_RESPONSE) { packet AttHandleValueIndication : Att(opcode = HANDLE_VALUE_INDICATION) { handle: AttHandle, - value: AttAttributeData, + value: 8[], } packet AttHandleValueConfirmation : Att(opcode = HANDLE_VALUE_CONFIRMATION) {} @@ -249,5 +249,5 @@ packet AttExchangeMtuResponse : Att(opcode = EXCHANGE_MTU_RESPONSE) { packet AttWriteCommand : Att(opcode = WRITE_COMMAND) { handle : AttHandle, - value : AttAttributeData, + value : 8[], } diff --git a/system/rust/src/utils/packet.rs b/system/rust/src/utils/packet.rs index 790be2026b..86039636b8 100644 --- a/system/rust/src/utils/packet.rs +++ b/system/rust/src/utils/packet.rs @@ -1,8 +1,7 @@ //! Utility for packet manipulation on top of the codegen from PDL use crate::packets::{ - AttAttributeDataBuilder, AttAttributeDataChild, AttBuilder, AttChild, AttOpcode, Builder, - OwnedAttView, OwnedPacket, Serializable, + AttBuilder, AttChild, AttOpcode, Builder, OwnedAttView, OwnedPacket, Serializable, }; /// Convert an ATT builder child into an owned AttView, for use in test @@ -45,8 +44,3 @@ pub fn HACK_child_to_opcode(child: &AttChild) -> AttOpcode { AttChild::AttWriteCommand(_) => AttOpcode::WRITE_COMMAND, } } - -/// Utility to simplify assembly of AttData by reducing boilerplate -pub fn build_att_data(child: impl Into<AttAttributeDataChild>) -> AttAttributeDataBuilder { - AttAttributeDataBuilder { _child_: child.into() } -} diff --git a/system/rust/tests/gatt_server_test.rs b/system/rust/tests/gatt_server_test.rs index 2b31db764c..9cccd51bc3 100644 --- a/system/rust/tests/gatt_server_test.rs +++ b/system/rust/tests/gatt_server_test.rs @@ -30,7 +30,7 @@ use bluetooth_core::{ }, }, packets::{ - AttAttributeDataChild, AttBuilder, AttChild, AttErrorCode, AttErrorResponseBuilder, + AttBuilder, AttChild, AttErrorCode, AttErrorResponseBuilder, AttFindByTypeValueRequestBuilder, AttFindInformationRequestBuilder, AttFindInformationResponseChild, AttHandleValueConfirmationBuilder, AttHandleValueIndicationBuilder, AttOpcode, AttReadByTypeRequestBuilder, @@ -39,7 +39,7 @@ use bluetooth_core::{ GattClientCharacteristicConfigurationBuilder, GattServiceChangedBuilder, GattServiceDeclarationValueBuilder, Packet, Serializable, UuidAsAttDataBuilder, }, - utils::packet::{build_att_data, build_att_view_or_crash}, + utils::packet::build_att_view_or_crash, }; use tokio::{ @@ -133,9 +133,10 @@ fn test_service_read() { AttBuilder { opcode: AttOpcode::READ_RESPONSE, _child_: AttReadResponseBuilder { - value: build_att_data(GattServiceDeclarationValueBuilder { - uuid: SERVICE_TYPE.into() - }) + value: GattServiceDeclarationValueBuilder { uuid: SERVICE_TYPE.into() } + .to_vec() + .unwrap() + .into(), } .into() } @@ -182,9 +183,6 @@ fn test_characteristic_read() { start_test(async move { // arrange let (mut gatt, mut transport_rx) = start_gatt_module(); - - let data = AttAttributeDataChild::RawData(DATA.into()); - let mut data_rx = create_server_and_open_connection(&mut gatt); // act @@ -214,7 +212,7 @@ fn test_characteristic_read() { resp, AttBuilder { opcode: AttOpcode::READ_RESPONSE, - _child_: AttReadResponseBuilder { value: build_att_data(data) }.into() + _child_: AttReadResponseBuilder { value: DATA.into() }.into() } ); }) @@ -225,16 +223,13 @@ fn test_characteristic_write() { start_test(async move { // arrange let (mut gatt, mut transport_rx) = start_gatt_module(); - - let data = AttAttributeDataChild::RawData(DATA.into()); - let mut data_rx = create_server_and_open_connection(&mut gatt); // act gatt.get_bearer(TCB_IDX).unwrap().handle_packet( build_att_view_or_crash(AttWriteRequestBuilder { handle: CHARACTERISTIC_HANDLE.into(), - value: build_att_data(data.clone()), + value: DATA.into(), }) .view(), ); @@ -262,7 +257,7 @@ fn test_characteristic_write() { _child_: AttWriteResponseBuilder {}.into() } ); - assert_eq!(data.to_vec().unwrap(), written_data) + assert_eq!(&DATA, written_data.as_slice()); }) } @@ -271,14 +266,11 @@ fn test_send_indication() { start_test(async move { // arrange let (mut gatt, mut transport_rx) = start_gatt_module(); - - let data = AttAttributeDataChild::RawData(DATA.into()); - create_server_and_open_connection(&mut gatt); // act let pending_indication = spawn_local( - gatt.get_bearer(TCB_IDX).unwrap().send_indication(CHARACTERISTIC_HANDLE, data.clone()), + gatt.get_bearer(TCB_IDX).unwrap().send_indication(CHARACTERISTIC_HANDLE, DATA.into()), ); let (tcb_idx, resp) = transport_rx.recv().await.unwrap(); @@ -296,7 +288,7 @@ fn test_send_indication() { opcode: AttOpcode::HANDLE_VALUE_INDICATION, _child_: AttHandleValueIndicationBuilder { handle: CHARACTERISTIC_HANDLE.into(), - value: build_att_data(data), + value: DATA.into(), } .into() } @@ -313,10 +305,11 @@ fn test_send_indication_and_disconnect() { create_server_and_open_connection(&mut gatt); // act: send an indication, then disconnect - let pending_indication = spawn_local(gatt.get_bearer(TCB_IDX).unwrap().send_indication( - CHARACTERISTIC_HANDLE, - AttAttributeDataChild::RawData([1, 2, 3, 4].into()), - )); + let pending_indication = spawn_local( + gatt.get_bearer(TCB_IDX) + .unwrap() + .send_indication(CHARACTERISTIC_HANDLE, vec![1, 2, 3, 4]), + ); transport_rx.recv().await.unwrap(); gatt.on_le_disconnect(TCB_IDX).unwrap(); @@ -333,16 +326,13 @@ fn test_write_to_descriptor() { start_test(async move { // arrange let (mut gatt, mut transport_rx) = start_gatt_module(); - - let data = AttAttributeDataChild::RawData(DATA.into()); - let mut data_rx = create_server_and_open_connection(&mut gatt); // act gatt.get_bearer(TCB_IDX).unwrap().handle_packet( build_att_view_or_crash(AttWriteRequestBuilder { handle: DESCRIPTOR_HANDLE.into(), - value: build_att_data(data.clone()), + value: DATA.into(), }) .view(), ); @@ -370,7 +360,7 @@ fn test_write_to_descriptor() { _child_: AttWriteResponseBuilder {}.into() } ); - assert_eq!(data.to_vec().unwrap(), written_data) + assert_eq!(&DATA, written_data.as_slice()); }) } @@ -505,9 +495,10 @@ fn test_service_change_indication() { starting_handle: AttHandle::MIN.into(), ending_handle: AttHandle::MAX.into(), attribute_type: PRIMARY_SERVICE_DECLARATION_UUID.try_into().unwrap(), - attribute_value: build_att_data(UuidAsAttDataBuilder { - uuid: GATT_SERVICE_UUID.into(), - }), + attribute_value: UuidAsAttDataBuilder { uuid: GATT_SERVICE_UUID.into() } + .to_vec() + .unwrap() + .into(), }) .view(), ); @@ -538,7 +529,7 @@ fn test_service_change_indication() { .into_vec() .into_iter() .find_map(|characteristic| { - let value = characteristic.value.to_vec().unwrap(); + let value = characteristic.value.to_vec(); let decl = GattCharacteristicDeclarationValueView::try_parse_from_buffer(value.as_slice()) .unwrap(); @@ -583,10 +574,13 @@ fn test_service_change_indication() { gatt.get_bearer(TCB_IDX).unwrap().handle_packet( build_att_view_or_crash(AttWriteRequestBuilder { handle: service_change_descriptor_handle, - value: build_att_data(GattClientCharacteristicConfigurationBuilder { + value: GattClientCharacteristicConfigurationBuilder { notification: 0, indication: 1, - }), + } + .to_vec() + .unwrap() + .into(), }) .view(), ); @@ -614,11 +608,12 @@ fn test_service_change_indication() { }; assert_eq!(indication.handle, service_change_char_handle.into()); assert_eq!( - indication.value, - build_att_data(GattServiceChangedBuilder { + Ok(indication.value.into()), + GattServiceChangedBuilder { start_handle: AttHandle(30).into(), end_handle: AttHandle(30).into(), - }) + } + .to_vec() ); }); } |