summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyush Jain <ayushjain@google.com>2023-08-16 22:07:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-08-16 22:07:01 +0000
commit2b4d27ad3bd190676b6ed17d324356d2448fe131 (patch)
tree569d413c6305b1a364048c8290633b719c1fe6fa
parentf82ef04017e027de05619d990f341d77b81c4ed2 (diff)
parent3af08566625af94a29741469a7b5397b551e44bc (diff)
downloaduwb-2b4d27ad3bd190676b6ed17d324356d2448fe131.tar.gz
Merge "Send CORE_GET_DEVICE_INFO CMD response in OpenHal." into main
-rw-r--r--src/rust/uwb_core/src/params/uci_packets.rs2
-rw-r--r--src/rust/uwb_core/src/service/uwb_service.rs25
-rw-r--r--src/rust/uwb_core/src/session/session_manager.rs13
-rw-r--r--src/rust/uwb_core/src/uci/mock_uci_manager.rs17
-rw-r--r--src/rust/uwb_core/src/uci/response.rs7
-rw-r--r--src/rust/uwb_core/src/uci/uci_manager.rs51
-rw-r--r--src/rust/uwb_core/src/uci/uci_manager_sync.rs20
7 files changed, 89 insertions, 46 deletions
diff --git a/src/rust/uwb_core/src/params/uci_packets.rs b/src/rust/uwb_core/src/params/uci_packets.rs
index 23597ce..d9da70b 100644
--- a/src/rust/uwb_core/src/params/uci_packets.rs
+++ b/src/rust/uwb_core/src/params/uci_packets.rs
@@ -204,6 +204,8 @@ impl From<UpdateTime> for [u8; 8] {
/// The response of the UciManager::core_get_device_info() method.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GetDeviceInfoResponse {
+ /// Status
+ pub status: StatusCode,
/// The UCI version.
pub uci_version: u16,
/// The MAC version.
diff --git a/src/rust/uwb_core/src/service/uwb_service.rs b/src/rust/uwb_core/src/service/uwb_service.rs
index ce00f95..012fbda 100644
--- a/src/rust/uwb_core/src/service/uwb_service.rs
+++ b/src/rust/uwb_core/src/service/uwb_service.rs
@@ -576,6 +576,7 @@ mod tests {
use tokio::runtime::Runtime;
use crate::params::uci_packets::{SessionState, SetAppConfigResponse, StatusCode};
+ use crate::params::GetDeviceInfoResponse;
use crate::service::mock_uwb_service_callback::MockUwbServiceCallback;
use crate::service::uwb_service_builder::default_runtime;
use crate::service::uwb_service_callback_builder::UwbServiceCallbackSendBuilder;
@@ -584,6 +585,16 @@ mod tests {
};
use crate::uci::mock_uci_manager::MockUciManager;
use crate::uci::notification::UciNotification;
+ use uwb_uci_packets::StatusCode::UciStatusOk;
+
+ const GET_DEVICE_INFO_RSP: GetDeviceInfoResponse = GetDeviceInfoResponse {
+ status: UciStatusOk,
+ uci_version: 0,
+ mac_version: 0,
+ phy_version: 0,
+ uci_test_version: 0,
+ vendor_spec_info: vec![],
+ };
fn setup_uwb_service(
uci_manager: MockUciManager,
@@ -599,7 +610,7 @@ mod tests {
#[test]
fn test_open_close_uci() {
let mut uci_manager = MockUciManager::new();
- uci_manager.expect_open_hal(vec![], Ok(()));
+ uci_manager.expect_open_hal(vec![], Ok(GET_DEVICE_INFO_RSP));
uci_manager.expect_close_hal(false, Ok(()));
let (service, _, _runtime) = setup_uwb_service(uci_manager);
@@ -618,7 +629,7 @@ mod tests {
let range_data = session_range_data(session_id);
let mut uci_manager = MockUciManager::new();
- uci_manager.expect_open_hal(vec![], Ok(()));
+ uci_manager.expect_open_hal(vec![], Ok(GET_DEVICE_INFO_RSP));
uci_manager.expect_session_init(
session_id,
session_type,
@@ -788,7 +799,7 @@ mod tests {
let mut uci_manager = MockUciManager::new();
uci_manager.expect_open_hal(
vec![UciNotification::Vendor(RawUciMessage { gid, oid, payload: payload.clone() })],
- Ok(()),
+ Ok(GET_DEVICE_INFO_RSP),
);
let (service, mut callback, _runtime) = setup_uwb_service(uci_manager);
@@ -804,7 +815,7 @@ mod tests {
let mut uci_manager = MockUciManager::new();
uci_manager.expect_open_hal(
vec![UciNotification::Core(CoreNotification::DeviceStatus(state))],
- Ok(()),
+ Ok(GET_DEVICE_INFO_RSP),
);
let (service, mut callback, _runtime) = setup_uwb_service(uci_manager);
callback.expect_on_uci_device_status_changed(state);
@@ -819,7 +830,7 @@ mod tests {
uci_manager.expect_open_hal(vec![], Err(Error::Timeout));
// Then UwbService should close_hal() and open_hal() to reset the HAL.
uci_manager.expect_close_hal(true, Ok(()));
- uci_manager.expect_open_hal(vec![], Ok(()));
+ uci_manager.expect_open_hal(vec![], Ok(GET_DEVICE_INFO_RSP));
let (service, mut callback, _runtime) = setup_uwb_service(uci_manager.clone());
callback.expect_on_service_reset(true);
@@ -838,11 +849,11 @@ mod tests {
vec![UciNotification::Core(CoreNotification::DeviceStatus(
DeviceState::DeviceStateError,
))],
- Ok(()),
+ Ok(GET_DEVICE_INFO_RSP),
);
// Then UwbService should close_hal() and open_hal() to reset the HAL.
uci_manager.expect_close_hal(true, Ok(()));
- uci_manager.expect_open_hal(vec![], Ok(()));
+ uci_manager.expect_open_hal(vec![], Ok(GET_DEVICE_INFO_RSP));
let (service, mut callback, _runtime) = setup_uwb_service(uci_manager.clone());
callback.expect_on_service_reset(true);
diff --git a/src/rust/uwb_core/src/session/session_manager.rs b/src/rust/uwb_core/src/session/session_manager.rs
index e49dd9c..449d50d 100644
--- a/src/rust/uwb_core/src/session/session_manager.rs
+++ b/src/rust/uwb_core/src/session/session_manager.rs
@@ -443,9 +443,20 @@ pub(crate) mod test_utils {
use crate::params::uci_packets::{
RangingMeasurementType, ReasonCode, ShortAddressTwoWayRangingMeasurement, StatusCode,
};
+ use crate::params::GetDeviceInfoResponse;
use crate::uci::mock_uci_manager::MockUciManager;
use crate::uci::notification::{RangingMeasurements, UciNotification};
use crate::utils::init_test_logging;
+ use uwb_uci_packets::StatusCode::UciStatusOk;
+
+ const GET_DEVICE_INFO_RSP: GetDeviceInfoResponse = GetDeviceInfoResponse {
+ status: UciStatusOk,
+ uci_version: 0,
+ mac_version: 0,
+ phy_version: 0,
+ uci_test_version: 0,
+ vendor_spec_info: vec![],
+ };
pub(crate) fn generate_params() -> AppConfigParams {
FiraAppConfigParamsBuilder::new()
@@ -533,7 +544,7 @@ pub(crate) mod test_utils {
let (uci_notf_sender, uci_notf_receiver) = mpsc::unbounded_channel();
let (session_notf_sender, session_notf_receiver) = mpsc::unbounded_channel();
let mut uci_manager = MockUciManager::new();
- uci_manager.expect_open_hal(vec![], Ok(()));
+ uci_manager.expect_open_hal(vec![], Ok(GET_DEVICE_INFO_RSP));
setup_uci_manager_fn(&mut uci_manager);
uci_manager.set_session_notification_sender(uci_notf_sender).await;
let _ = uci_manager.open_hal().await;
diff --git a/src/rust/uwb_core/src/uci/mock_uci_manager.rs b/src/rust/uwb_core/src/uci/mock_uci_manager.rs
index d7f944a..9dcc4e6 100644
--- a/src/rust/uwb_core/src/uci/mock_uci_manager.rs
+++ b/src/rust/uwb_core/src/uci/mock_uci_manager.rs
@@ -28,9 +28,10 @@ use tokio::time::timeout;
use crate::error::{Error, Result};
use crate::params::uci_packets::{
app_config_tlvs_eq, device_config_tlvs_eq, AppConfigTlv, AppConfigTlvType, CapTlv, Controlees,
- CoreSetConfigResponse, CountryCode, DeviceConfigId, DeviceConfigTlv, GetDeviceInfoResponse, PhaseList,
- PowerStats, RawUciMessage, ResetConfig, SessionId, SessionState, SessionToken, SessionType,
- SessionUpdateDtTagRangingRoundsResponse, SetAppConfigResponse, UpdateMulticastListAction, UpdateTime,
+ CoreSetConfigResponse, CountryCode, DeviceConfigId, DeviceConfigTlv, GetDeviceInfoResponse,
+ PhaseList, PowerStats, RawUciMessage, ResetConfig, SessionId, SessionState, SessionToken,
+ SessionType, SessionUpdateDtTagRangingRoundsResponse, SetAppConfigResponse,
+ UpdateMulticastListAction, UpdateTime,
};
use crate::uci::notification::{
CoreNotification, DataRcvNotification, SessionNotification, UciNotification,
@@ -79,7 +80,11 @@ impl MockUciManager {
/// Prepare Mock to expect for open_hal.
///
/// MockUciManager expects call, returns out as response, followed by notfs sent.
- pub fn expect_open_hal(&mut self, notfs: Vec<UciNotification>, out: Result<()>) {
+ pub fn expect_open_hal(
+ &mut self,
+ notfs: Vec<UciNotification>,
+ out: Result<GetDeviceInfoResponse>,
+ ) {
self.expected_calls.lock().unwrap().push_back(ExpectedCall::OpenHal { notfs, out });
}
@@ -482,7 +487,7 @@ impl UciManager for MockUciManager {
self.data_rcv_notf_sender = data_rcv_notf_sender;
}
- async fn open_hal(&self) -> Result<()> {
+ async fn open_hal(&self) -> Result<GetDeviceInfoResponse> {
let mut expected_calls = self.expected_calls.lock().unwrap();
match expected_calls.pop_front() {
Some(ExpectedCall::OpenHal { notfs, out }) => {
@@ -999,7 +1004,7 @@ impl UciManager for MockUciManager {
enum ExpectedCall {
OpenHal {
notfs: Vec<UciNotification>,
- out: Result<()>,
+ out: Result<GetDeviceInfoResponse>,
},
CloseHal {
expected_force: bool,
diff --git a/src/rust/uwb_core/src/uci/response.rs b/src/rust/uwb_core/src/uci/response.rs
index 23279c9..634bd44 100644
--- a/src/rust/uwb_core/src/uci/response.rs
+++ b/src/rust/uwb_core/src/uci/response.rs
@@ -122,6 +122,7 @@ impl TryFrom<uwb_uci_packets::CoreResponse> for UciResponse {
match evt.specialize() {
CoreResponseChild::GetDeviceInfoRsp(evt) => Ok(UciResponse::CoreGetDeviceInfo(
status_code_to_result(evt.get_status()).map(|_| GetDeviceInfoResponse {
+ status: evt.get_status(),
uci_version: evt.get_uci_version(),
mac_version: evt.get_mac_version(),
phy_version: evt.get_phy_version(),
@@ -208,9 +209,9 @@ impl TryFrom<uwb_uci_packets::SessionConfigResponse> for UciResponse {
SessionConfigResponseChild::SessionQueryMaxDataSizeRsp(evt) => {
Ok(UciResponse::SessionQueryMaxDataSize(Ok(evt.get_max_data_size())))
}
- SessionConfigResponseChild::SessionSetHybridConfigRsp(evt) => Ok(
- UciResponse::SessionSetHybridConfig(status_code_to_result(evt.get_status())),
- ),
+ SessionConfigResponseChild::SessionSetHybridConfigRsp(evt) => {
+ Ok(UciResponse::SessionSetHybridConfig(status_code_to_result(evt.get_status())))
+ }
_ => Err(Error::Unknown),
}
}
diff --git a/src/rust/uwb_core/src/uci/uci_manager.rs b/src/rust/uwb_core/src/uci/uci_manager.rs
index 9c40f19..01cdfa0 100644
--- a/src/rust/uwb_core/src/uci/uci_manager.rs
+++ b/src/rust/uwb_core/src/uci/uci_manager.rs
@@ -71,7 +71,7 @@ pub trait UciManager: 'static + Send + Sync + Clone {
// Open the UCI HAL.
// All the UCI commands should be called after the open_hal() completes successfully.
- async fn open_hal(&self) -> Result<()>;
+ async fn open_hal(&self) -> Result<GetDeviceInfoResponse>;
// Close the UCI HAL.
async fn close_hal(&self, force: bool) -> Result<()>;
@@ -255,16 +255,21 @@ impl UciManager for UciManagerImpl {
.await;
}
- async fn open_hal(&self) -> Result<()> {
+ async fn open_hal(&self) -> Result<GetDeviceInfoResponse> {
match self.send_cmd(UciManagerCmd::OpenHal).await {
Ok(UciResponse::OpenHal) => {
// According to the UCI spec: "The Host shall send CORE_GET_DEVICE_INFO_CMD to
// retrieve the device information.", we call get_device_info() after successfully
// opening the HAL.
- let device_info = self.core_get_device_info().await;
+ let device_info = match self.core_get_device_info().await {
+ Ok(resp) => resp,
+ Err(e) => {
+ return Err(e);
+ }
+ };
debug!("UCI device info: {:?}", device_info);
- Ok(())
+ Ok(device_info)
}
Ok(_) => Err(Error::Unknown),
Err(e) => Err(e),
@@ -1306,24 +1311,27 @@ impl<T: UciHal, U: UciLogger> UciManagerActor<T, U> {
async fn handle_data_rcv(&mut self, packet: UciDataPacket) {
match packet.try_into() {
- Ok(DataRcvNotification { session_token, status, uci_sequence_num,
- source_address, payload }) => {
- match self.get_session_id(&session_token).await {
- Ok(session_id) => {
- let data_recv = DataRcvNotification {
- session_token: session_id,
- status,
- uci_sequence_num,
- source_address,
- payload,
- };
- let _ = self.data_rcv_notf_sender.send(data_recv);
- }
- Err(e) => {
- error!("Unable to find session Id, error {:?}", e);
- }
+ Ok(DataRcvNotification {
+ session_token,
+ status,
+ uci_sequence_num,
+ source_address,
+ payload,
+ }) => match self.get_session_id(&session_token).await {
+ Ok(session_id) => {
+ let data_recv = DataRcvNotification {
+ session_token: session_id,
+ status,
+ uci_sequence_num,
+ source_address,
+ payload,
+ };
+ let _ = self.data_rcv_notf_sender.send(data_recv);
}
- }
+ Err(e) => {
+ error!("Unable to find session Id, error {:?}", e);
+ }
+ },
Err(e) => {
error!("Unable to parse incoming Data packet, error {:?}", e);
}
@@ -1626,6 +1634,7 @@ mod tests {
.await;
let expected_result = GetDeviceInfoResponse {
+ status,
uci_version,
mac_version,
phy_version,
diff --git a/src/rust/uwb_core/src/uci/uci_manager_sync.rs b/src/rust/uwb_core/src/uci/uci_manager_sync.rs
index 688f1e9..57800e6 100644
--- a/src/rust/uwb_core/src/uci/uci_manager_sync.rs
+++ b/src/rust/uwb_core/src/uci/uci_manager_sync.rs
@@ -1,4 +1,4 @@
- // Copyright 2022, The Android Open Source Project
+// Copyright 2022, The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -204,7 +204,7 @@ impl<U: UciManager> UciManagerSync<U> {
self.runtime_handle.block_on(self.uci_manager.set_logger_mode(logger_mode))
}
/// Start UCI HAL and blocking until UCI commands can be sent.
- pub fn open_hal(&self) -> Result<()> {
+ pub fn open_hal(&self) -> Result<GetDeviceInfoResponse> {
self.runtime_handle.block_on(self.uci_manager.open_hal())
}
@@ -449,6 +449,7 @@ mod tests {
use crate::params::uci_packets::GetDeviceInfoResponse;
use crate::uci::mock_uci_manager::MockUciManager;
use crate::uci::{CoreNotification, UciNotification};
+ use uwb_uci_packets::StatusCode::UciStatusOk;
/// Mock NotificationManager forwarding notifications received.
/// The nonsend_counter is deliberately !send to check UciManagerSync::redirect_notification.
@@ -516,17 +517,20 @@ mod tests {
let test_rt = Builder::new_multi_thread().enable_all().build().unwrap();
let (notf_sender, mut notf_receiver) = mpsc::unbounded_channel::<UciNotification>();
let mut uci_manager_impl = MockUciManager::new();
- uci_manager_impl.expect_open_hal(
- vec![UciNotification::Core(CoreNotification::DeviceStatus(DeviceStateReady))],
- Ok(()),
- );
- uci_manager_impl.expect_core_get_device_info(Ok(GetDeviceInfoResponse {
+ let get_device_info_rsp = GetDeviceInfoResponse {
+ status: UciStatusOk,
uci_version: 0,
mac_version: 0,
phy_version: 0,
uci_test_version: 0,
vendor_spec_info: vec![],
- }));
+ };
+
+ uci_manager_impl.expect_open_hal(
+ vec![UciNotification::Core(CoreNotification::DeviceStatus(DeviceStateReady))],
+ Ok(get_device_info_rsp.clone()),
+ );
+ uci_manager_impl.expect_core_get_device_info(Ok(get_device_info_rsp));
let uci_manager_sync = UciManagerSync::new_mock(
uci_manager_impl,
test_rt.handle().to_owned(),