Early return for CORE_GET_CAPS_INFO_RSP
Without using global variable,
phNxpUciHal_handle_get_caps_info() returns true if the packet is
handled internally and already reported to upper layer.
And change the prototype to use (size_t, const uint8_t*).
Bug: 375952239
Test: stress test
Change-Id: I37d24e5c51dbdb6167b23fc5c4f9bbe2132ec4ed
Merged-In: I37d24e5c51dbdb6167b23fc5c4f9bbe2132ec4ed
diff --git a/halimpl/hal/phNxpUciHal.cc b/halimpl/hal/phNxpUciHal.cc
index 1ff9472..b05dbde 100644
--- a/halimpl/hal/phNxpUciHal.cc
+++ b/halimpl/hal/phNxpUciHal.cc
@@ -459,7 +459,9 @@
// mapping device caps according to Fira 2.0
if (mt == UCI_MT_RSP && gid == UCI_GID_CORE && oid == UCI_MSG_CORE_GET_CAPS_INFO) {
- phNxpUciHal_handle_get_caps_info(length, buffer);
+ if (phNxpUciHal_handle_get_caps_info(length, buffer)) {
+ return;
+ }
}
/* DBG packets not yet supported, just ignore them silently */
diff --git a/halimpl/hal/phNxpUciHal_ext.cc b/halimpl/hal/phNxpUciHal_ext.cc
index b64bea8..8d4477a 100644
--- a/halimpl/hal/phNxpUciHal_ext.cc
+++ b/halimpl/hal/phNxpUciHal_ext.cc
@@ -925,15 +925,15 @@
return false;
}
-void phNxpUciHal_handle_get_caps_info(uint16_t data_len, uint8_t *p_data)
+bool phNxpUciHal_handle_get_caps_info(size_t data_len, const uint8_t *p_data)
{
if (data_len < UCI_MSG_CORE_GET_CAPS_INFO_NR_OFFSET)
- return;
+ return false;
uint8_t status = p_data[UCI_RESPONSE_STATUS_OFFSET];
uint8_t nr = p_data[UCI_MSG_CORE_GET_CAPS_INFO_NR_OFFSET];
if (status != UWBSTATUS_SUCCESS || nr < 1)
- return;
+ return false;
auto tlvs = decodeTlvBytes({0xe0, 0xe1, 0xe2, 0xe3}, &p_data[UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET], data_len - UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET);
if (tlvs.size() != nr) {
@@ -1011,6 +1011,7 @@
auto tlv_bytes = encodeTlvBytes(tlvs);
if ((tlv_bytes.size() + UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET) > sizeof(packet)) {
NXPLOG_UCIHAL_E("DevCaps overflow!");
+ return false;
} else {
uint8_t packet_len = UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET + tlv_bytes.size();
packet[UCI_PAYLOAD_LENGTH_OFFSET] = packet_len - UCI_MSG_HDR_SIZE;
@@ -1022,6 +1023,6 @@
(*nxpucihal_ctrl.p_uwb_stack_data_cback)(packet_len, packet);
// skip the incoming packet as we have send the modified response
// already
- nxpucihal_ctrl.isSkipPacket = 1;
+ return true;
}
}
diff --git a/halimpl/hal/phNxpUciHal_ext.h b/halimpl/hal/phNxpUciHal_ext.h
index 147847a..d2c69e1 100644
--- a/halimpl/hal/phNxpUciHal_ext.h
+++ b/halimpl/hal/phNxpUciHal_ext.h
@@ -65,6 +65,10 @@
void phNxpUciHal_process_response();
void phNxpUciHal_handle_set_country_code(const char country_code[2]);
bool phNxpUciHal_handle_set_app_config(uint16_t *data_len, uint8_t *p_data);
-void phNxpUciHal_handle_get_caps_info(uint16_t data_len, uint8_t *p_data);
+
+// Handles CORE_GET_CAPS_INFO_RSP
+// Returns true if the packet is patched / reported to upper layer.
+bool phNxpUciHal_handle_get_caps_info(size_t data_len, const uint8_t *p_data);
+
void apply_per_country_calibrations(void);
#endif /* _PHNXPNICHAL_EXT_H_ */