Cleanup: report_uci_message()

No logics changes.
Creates report_uci_message() function, which calls UciMessage callback.

Bug: 375952239
Test: stress test
Change-Id: I681945e7961bdcaad17bbbb9636eae1d18c43198
Merged-In: I681945e7961bdcaad17bbbb9636eae1d18c43198
diff --git a/aidl/uwb_chip.h b/aidl/uwb_chip.h
index 2ccc579..a963bc3 100644
--- a/aidl/uwb_chip.h
+++ b/aidl/uwb_chip.h
@@ -55,7 +55,7 @@
       }
     }
   }
-  static void dataCallback(uint16_t data_len, uint8_t* p_data) {
+  static void dataCallback(uint16_t data_len, const uint8_t* p_data) {
       std::vector<uint8_t> data;
       data.assign(p_data, p_data + data_len);
       if (mClientCallback != nullptr) {
diff --git a/halimpl/hal/phNxpUciHal.cc b/halimpl/hal/phNxpUciHal.cc
index a9160df..63438f9 100644
--- a/halimpl/hal/phNxpUciHal.cc
+++ b/halimpl/hal/phNxpUciHal.cc
@@ -447,6 +447,13 @@
   p_cb_data->post(pInfo->wStatus);
 }
 
+void report_uci_message(const uint8_t* buffer, size_t len)
+{
+  if ((nxpucihal_ctrl.p_uwb_stack_data_cback != NULL) && (len <= UCI_MAX_PAYLOAD_LEN)) {
+    (*nxpucihal_ctrl.p_uwb_stack_data_cback)(len, buffer);
+  }
+}
+
 static void handle_rx_packet(uint8_t *buffer, size_t length)
 {
   phNxpUciHal_print_packet(NXP_TML_UCI_RSP_NTF_UWBS_2_AP, buffer, length);
@@ -526,9 +533,7 @@
 
   if (!isSkipPacket) {
     /* Read successful, send the event to higher layer */
-    if ((nxpucihal_ctrl.p_uwb_stack_data_cback != NULL) && (length <= UCI_MAX_PAYLOAD_LEN)) {
-      (*nxpucihal_ctrl.p_uwb_stack_data_cback)(length, buffer);
-    }
+    report_uci_message(buffer, length);
   }
 
   /* Disable junk data check for each UCI packet*/
@@ -971,10 +976,8 @@
   // report to upper-layer
   phTmlUwb_DeferredCall(std::make_shared<phLibUwb_Message>(UCI_HAL_INIT_CPLT_MSG));
 
-  if (nxpucihal_ctrl.p_uwb_stack_data_cback != NULL) {
-    uint8_t dev_ready_ntf[] = {0x60, 0x01, 0x00, 0x01, 0x01};
-    (*nxpucihal_ctrl.p_uwb_stack_data_cback)((sizeof(dev_ready_ntf)/sizeof(uint8_t)), dev_ready_ntf);
-  }
+  constexpr uint8_t dev_ready_ntf[] = {0x60, 0x01, 0x00, 0x01, 0x01};
+  report_uci_message(dev_ready_ntf, sizeof(dev_ready_ntf));
 
   return UWBSTATUS_SUCCESS;
 }
@@ -1098,7 +1101,7 @@
  ******************************************* ***********************************/
 void phNxpUciHal_send_dev_error_status_ntf()
 {
- NXPLOG_UCIHAL_D("phNxpUciHal_send_dev_error_status_ntf ");
- static uint8_t rsp_data[5] = {0x60, 0x01, 0x00, 0x01, 0xFF};
- (*nxpucihal_ctrl.p_uwb_stack_data_cback)(sizeof(rsp_data), rsp_data);
+  NXPLOG_UCIHAL_D("phNxpUciHal_send_dev_error_status_ntf ");
+  constexpr uint8_t rsp_data[5] = {0x60, 0x01, 0x00, 0x01, 0xFF};
+  report_uci_message(rsp_data, sizeof(rsp_data));
 }
diff --git a/halimpl/hal/phNxpUciHal.h b/halimpl/hal/phNxpUciHal.h
index d268eb4..e7c0f7b 100644
--- a/halimpl/hal/phNxpUciHal.h
+++ b/halimpl/hal/phNxpUciHal.h
@@ -299,6 +299,10 @@
 tHAL_UWB_STATUS phNxpUciHal_init_hw();
 tHAL_UWB_STATUS phNxpUciHal_write_unlocked(size_t cmd_len, const uint8_t* p_cmd);
 void phNxpUciHal_read_complete(void* pContext, phTmlUwb_ReadTransactInfo* pInfo);
+
+// Report UCI packet to upper layer
+void report_uci_message(const uint8_t* buffer, size_t len);
+
 tHAL_UWB_STATUS phNxpUciHal_uwb_reset();
 tHAL_UWB_STATUS phNxpUciHal_applyVendorConfig();
 tHAL_UWB_STATUS phNxpUciHal_process_ext_cmd_rsp(size_t cmd_len, const uint8_t *p_cmd);
diff --git a/halimpl/hal/phNxpUciHal_ext.cc b/halimpl/hal/phNxpUciHal_ext.cc
index 9a8c2fc..87b694e 100644
--- a/halimpl/hal/phNxpUciHal_ext.cc
+++ b/halimpl/hal/phNxpUciHal_ext.cc
@@ -800,13 +800,15 @@
   }
 
   // send country code response to upper layer
-  static uint8_t rsp_data[5] = { 0x4c, 0x01, 0x00, 0x01 };
   if (rt_set->uwb_enable) {
-    rsp_data[4] = UWBSTATUS_SUCCESS;
+    constexpr uint8_t rsp_data[5] = {
+      0x4c, 0x01, 0x00, 0x01, UWBSTATUS_SUCCESS };
+    report_uci_message(rsp_data, sizeof(rsp_data));
   } else {
-    rsp_data[4] = UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF;
+    constexpr uint8_t rsp_data[5] = {
+      0x4c, 0x01, 0x00, 0x01, UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF };
+    report_uci_message(rsp_data, sizeof(rsp_data));
   }
-  (*nxpucihal_ctrl.p_uwb_stack_data_cback)(sizeof(rsp_data), rsp_data);
 }
 
 // TODO: support fragmented packets
@@ -881,10 +883,10 @@
         NXPLOG_UCIHAL_D("Country code blocked channel %u", ch);
 
         // send setAppConfig response with UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF response
-        static uint8_t rsp_data[] = { 0x41, 0x03, 0x04, 0x04,
+        const uint8_t rsp_data[] = { 0x41, 0x03, 0x04, 0x04,
           UCI_STATUS_FAILED, 0x01, tlv_tag, UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF
         };
-        (*nxpucihal_ctrl.p_uwb_stack_data_cback)(sizeof(rsp_data), rsp_data);
+        report_uci_message(rsp_data, sizeof(rsp_data));
         return true;
       }
     }
@@ -1024,8 +1026,7 @@
 
     phNxpUciHal_print_packet(NXP_TML_UCI_RSP_NTF_UWBS_2_AP, packet, packet_len);
 
-    // send GET CAPS INFO response to the Upper Layer
-    (*nxpucihal_ctrl.p_uwb_stack_data_cback)(packet_len, packet);
+    report_uci_message(packet, packet_len);
     // skip the incoming packet as we have send the modified response
     // already
     return true;
diff --git a/halimpl/inc/phNxpUciHal_Adaptation.h b/halimpl/inc/phNxpUciHal_Adaptation.h
index 7d5f5b5..94eff2c 100644
--- a/halimpl/inc/phNxpUciHal_Adaptation.h
+++ b/halimpl/inc/phNxpUciHal_Adaptation.h
@@ -34,7 +34,7 @@
  * The callback passed in from the UWB stack that the HAL
  * can use to pass incomming data to the stack.
  */
-typedef void(uwb_stack_data_callback_t)(uint16_t data_len, uint8_t* p_data);
+typedef void(uwb_stack_data_callback_t)(uint16_t data_len, const uint8_t* p_data);
 
 /* NXP HAL functions */
 uint16_t phNxpUciHal_open(uwb_stack_callback_t* p_cback,