diff options
author | Bhautik Ardeshana <bhautik.ardeshana@nxp.com> | 2024-03-26 12:12:39 +0530 |
---|---|---|
committer | Bhautik Ardeshana <bhautik.ardeshana@nxp.com> | 2024-03-27 10:35:09 +0530 |
commit | 52b4d90ef6ac4f17cb6a6fed4cfc2f6c391df6bd (patch) | |
tree | bb9969c757841594ef69000d64d719e923fa2b28 | |
parent | d1d0a6616d4aa982891c958011de5a317a5a2d7a (diff) | |
download | uwb-52b4d90ef6ac4f17cb6a6fed4cfc2f6c391df6bd.tar.gz |
Race condition while processing session status notification.
pass sessionToken as parameter to SessionStatusNotification
Bug: 329386934
Test: atest libuwb_core_tests
Change-Id: Id23649c13e27edbeaa8d62fc12e75febb041242c
-rw-r--r-- | src/rust/uwb_core/src/session/session_manager.rs | 4 | ||||
-rw-r--r-- | src/rust/uwb_core/src/uci/notification.rs | 7 | ||||
-rw-r--r-- | src/rust/uwb_core/src/uci/uci_manager.rs | 11 |
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 08af530..6f7cc8c 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 4104dc2..a29b1a7 100644 --- a/src/rust/uwb_core/src/uci/uci_manager.rs +++ b/src/rust/uwb_core/src/uci/uci_manager.rs @@ -1362,7 +1362,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, @@ -1374,6 +1374,7 @@ impl<T: UciHal, U: UciLogger> UciManagerActor<T, U> { }; match orig_session_notf { SessionNotification::Status { + session_id:_, session_token, session_state, reason_code: _, @@ -1428,14 +1429,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, }) |