Merge "Race condition while processing session status notification." into main
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 @@
 
     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 @@
         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 @@
     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 SessionNotification {
     /// SessionStatusNtf equivalent.
     Status {
+        /// SessionId : u32
+        session_id: SessionId,
         /// SessionToken : u32
         session_token: SessionToken,
         /// uwb_uci_packets::SessionState.
@@ -383,6 +385,8 @@
         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 @@
         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 @@
             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 @@
                 };
                 match orig_session_notf {
                     SessionNotification::Status {
+                        session_id:_,
                         session_token,
                         session_state,
                         reason_code: _,
@@ -1415,14 +1416,16 @@
     // 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,
                 })