summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2024-04-04 20:39:37 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-04 20:39:37 +0000
commitfe73631a4b3e4d13d9f344ee6548cf73b1ad0851 (patch)
treee7837d1acc5b2e6a53436d4eb1d8fbb77c891d8f
parent794e34a03355a3dcf79cdf9f6f757b7ed2400a31 (diff)
parent52b4d90ef6ac4f17cb6a6fed4cfc2f6c391df6bd (diff)
downloaduwb-fe73631a4b3e4d13d9f344ee6548cf73b1ad0851.tar.gz
Merge "Race condition while processing session status notification." into main
-rw-r--r--src/rust/uwb_core/src/session/session_manager.rs4
-rw-r--r--src/rust/uwb_core/src/uci/notification.rs7
-rw-r--r--src/rust/uwb_core/src/uci/uci_manager.rs11
3 files changed, 16 insertions, 6 deletions
diff --git a/src/rust/uwb_core/src/session/session_manager.rs b/src/rust/uwb_core/src/session/session_manager.rs
index 38a9887..40801fa 100644
--- a/src/rust/uwb_core/src/session/session_manager.rs
+++ b/src/rust/uwb_core/src/session/session_manager.rs
@@ -294,7 +294,8 @@ impl<T: UciManager> SessionManagerActor<T> {
fn handle_uci_notification(&mut self, notf: UciSessionNotification) {
match notf {
- UciSessionNotification::Status { session_token, session_state, reason_code } => {
+ UciSessionNotification::Status {
+ session_id:_, session_token, session_state, reason_code } => {
let reason_code = match ReasonCode::try_from(reason_code) {
Ok(r) => r,
Err(_) => {
@@ -542,6 +543,7 @@ pub(crate) mod test_utils {
session_state: SessionState,
) -> UciNotification {
UciNotification::Session(UciSessionNotification::Status {
+ session_id: 0x0,
session_token: session_id,
session_state,
reason_code: ReasonCode::StateChangeWithSessionManagementCommands.into(),
diff --git a/src/rust/uwb_core/src/uci/notification.rs b/src/rust/uwb_core/src/uci/notification.rs
index cab87f7..06cc909 100644
--- a/src/rust/uwb_core/src/uci/notification.rs
+++ b/src/rust/uwb_core/src/uci/notification.rs
@@ -29,7 +29,7 @@ use crate::params::uci_packets::{
DataTransferNtfStatusCode, DataTransferPhaseConfigUpdateStatusCode, DeviceState,
ExtendedAddressDlTdoaRangingMeasurement, ExtendedAddressOwrAoaRangingMeasurement,
ExtendedAddressTwoWayRangingMeasurement, RadarDataType, RangingMeasurementType, RawUciMessage,
- SessionState, SessionToken, ShortAddressDlTdoaRangingMeasurement,
+ SessionId, SessionState, SessionToken, ShortAddressDlTdoaRangingMeasurement,
ShortAddressOwrAoaRangingMeasurement, ShortAddressTwoWayRangingMeasurement, StatusCode,
};
@@ -58,6 +58,8 @@ pub enum CoreNotification {
pub enum SessionNotification {
/// SessionStatusNtf equivalent.
Status {
+ /// SessionId : u32
+ session_id: SessionId,
/// SessionToken : u32
session_token: SessionToken,
/// uwb_uci_packets::SessionState.
@@ -383,6 +385,8 @@ impl TryFrom<uwb_uci_packets::SessionConfigNotification> for SessionNotification
use uwb_uci_packets::SessionConfigNotificationChild;
match evt.specialize() {
SessionConfigNotificationChild::SessionStatusNtf(evt) => Ok(Self::Status {
+ //no sessionId recieved, assign from sessionIdToToken map in uci_manager
+ session_id: 0,
session_token: evt.get_session_token(),
session_state: evt.get_session_state(),
reason_code: evt.get_reason_code(),
@@ -892,6 +896,7 @@ mod tests {
assert_eq!(
uci_notification_from_session_status_ntf,
UciNotification::Session(SessionNotification::Status {
+ session_id: 0x0,
session_token: 0x20,
session_state: uwb_uci_packets::SessionState::SessionStateActive,
reason_code: uwb_uci_packets::ReasonCode::StateChangeWithSessionManagementCommands
diff --git a/src/rust/uwb_core/src/uci/uci_manager.rs b/src/rust/uwb_core/src/uci/uci_manager.rs
index c068609..8fd1acc 100644
--- a/src/rust/uwb_core/src/uci/uci_manager.rs
+++ b/src/rust/uwb_core/src/uci/uci_manager.rs
@@ -1349,7 +1349,7 @@ impl<T: UciHal, U: UciLogger> UciManagerActor<T, U> {
UciNotification::Session(orig_session_notf) => {
let mod_session_notf = {
match self
- .replace_session_token_with_session_id(orig_session_notf.clone())
+ .add_session_id_to_session_status_ntf(orig_session_notf.clone())
.await
{
Ok(session_notf) => session_notf,
@@ -1361,6 +1361,7 @@ impl<T: UciHal, U: UciLogger> UciManagerActor<T, U> {
};
match orig_session_notf {
SessionNotification::Status {
+ session_id:_,
session_token,
session_state,
reason_code: _,
@@ -1415,14 +1416,16 @@ impl<T: UciHal, U: UciLogger> UciManagerActor<T, U> {
// TODO: Sharing of structs across UCI (PDL) & JNI layer like this makes this ugly. Ideally
// the struct sent to JNI layer should only contain |session_id| and at uci layer
// it could be |session_id| or |session_handle|.
- async fn replace_session_token_with_session_id(
+ async fn add_session_id_to_session_status_ntf(
&self,
session_notification: SessionNotification,
) -> Result<SessionNotification> {
match session_notification {
- SessionNotification::Status { session_token, session_state, reason_code } => {
+ SessionNotification::Status {
+ session_id:_, session_token, session_state, reason_code } => {
Ok(SessionNotification::Status {
- session_token: self.get_session_id(&session_token).await?,
+ session_id: self.get_session_id(&session_token).await?,
+ session_token,
session_state,
reason_code,
})