Skip to main content

sapphire_emboss/
lib.rs

1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5pub use pw_bluetooth_att_emb as att;
6pub use pw_bluetooth_hci_commands_emb as hci_commands;
7pub use pw_bluetooth_hci_common_emb as hci_common;
8pub use pw_bluetooth_hci_data_emb as hci_data;
9pub use pw_bluetooth_hci_h4_emb as hci_h4;
10pub use pw_bluetooth_l2cap_frames_emb as l2cap_frames;
11
12pub use emboss_runtime::{
13    CheckComplete, CheckOk, CompleteState, Error, InfallibleRead, InfallibleWrite, IsComplete,
14    IsOk, MutStorage, OkState, State, Storage, TryFromRaw, UncheckedState,
15};
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20    use att::{AttErrorRsp, AttErrorRspWriter, AttOpcode, ErrorCode};
21    use hci_commands::ResetCommand;
22    use hci_common::OpCode;
23
24    #[test]
25    fn test_reset_command() {
26        let buffer = [0x03u8, 0x0cu8, 0x00u8];
27        let view = ResetCommand::new(&buffer[..]);
28        assert_eq!(view.header().opcode().try_read().unwrap(), OpCode::RESET);
29        assert_eq!(view.header().parameter_total_size().try_read().unwrap(), 0);
30    }
31
32    #[test]
33    fn test_error_rsp() {
34        let mut buffer = [0u8; 5];
35        let _ = AttErrorRspWriter::new(&mut buffer[..])
36            .check_complete()
37            .unwrap()
38            .write_attribute_opcode(AttOpcode::ATT_ERROR_RSP)
39            .write_request_opcode_in_error_uint(u8::from(AttOpcode::ATT_READ_REQ))
40            .write_attribute_handle(0x1234)
41            .write_error_code(ErrorCode::READ_NOT_PERMITTED);
42
43        let read_view = AttErrorRsp::new(&buffer[..]).check_ok().unwrap();
44        assert_eq!(read_view.attribute_opcode().read(), Ok(AttOpcode::ATT_ERROR_RSP));
45        assert_eq!(
46            read_view.request_opcode_in_error_uint().read(),
47            u8::from(AttOpcode::ATT_READ_REQ)
48        );
49        assert_eq!(read_view.attribute_handle().read(), 0x1234);
50        assert_eq!(read_view.error_code().read(), Ok(ErrorCode::READ_NOT_PERMITTED));
51    }
52}