From c9d531ee1a82c2aa157f1839c5f01dc4266c61a4 Mon Sep 17 00:00:00 2001 From: Szymon Czapracki Date: Thu, 8 Aug 2024 15:34:08 +0200 Subject: [PATCH] nimble/audio: Modify BASS control point write access Modify BASS control point write access in a way that it would use flattened mbuf to pass data to handler. Previous solution was prone to errors due to chained mbufs. Fix handler check from simple bool comparison to ensuring that it's not NULL. Add opcode variable to hold proper operation id in write access. This is helpful during debugging operations. --- .../audio/services/bass/src/ble_audio_svc_bass.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c b/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c index 1c4ff639e..b71f27d82 100644 --- a/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c +++ b/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c @@ -617,13 +617,16 @@ ble_svc_audio_bass_find_handler(uint8_t opcode) static int ble_svc_audio_bass_ctrl_point_write_access(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle) { + uint8_t opcode; + struct os_mbuf *om; + uint16_t mbuf_len = OS_MBUF_PKTLEN(ctxt->om); struct ble_svc_audio_bass_ctrl_point_handler *handler; - uint8_t opcode = ctxt->om->om_data[0]; + opcode = ctxt->om->om_data[0]; handler = ble_svc_audio_bass_find_handler(opcode); - if (!handler) { + if (handler == NULL) { return BLE_SVC_AUDIO_BASS_ERR_OPCODE_NOT_SUPPORTED; } @@ -633,7 +636,12 @@ ble_svc_audio_bass_ctrl_point_write_access(struct ble_gatt_access_ctxt *ctxt, ui return BLE_ATT_ERR_WRITE_REQ_REJECTED; } - return handler->handler_cb(&ctxt->om->om_data[1], ctxt->om->om_len - 1, conn_handle); + om = os_mbuf_pullup(ctxt->om, mbuf_len); + if (!om) { + return BLE_ATT_ERR_UNLIKELY; + } + + return handler->handler_cb(&om->om_data[1], mbuf_len - 1, conn_handle); } static int