Skip to content

Commit

Permalink
nimble/audio: Modify BASS control point write access
Browse files Browse the repository at this point in the history
Modify BASS control point write access in a way that
it would use proper mbuf for holding incoming data.

Fix handler check from simple bool comparison to ensuring
that it's not NULL.
  • Loading branch information
szymon-czapracki committed Aug 21, 2024
1 parent f8994e1 commit 6d51e7f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions nimble/host/audio/services/bass/src/ble_audio_svc_bass.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha
operation.op = BLE_SVC_AUDIO_BASS_OPERATION_ADD_SOURCE;
operation.conn_handle = conn_handle;

offset++;
operation.add_source.adv_addr.type = data[offset++];
memcpy(operation.add_source.adv_addr.val, &data[offset], 6);
offset += 6;
Expand Down Expand Up @@ -458,6 +459,7 @@ ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn
operation.op = BLE_SVC_AUDIO_BASS_OPERATION_MODIFY_SOURCE;
operation.conn_handle = conn_handle;

offset++;
operation.modify_source.source_id = data[offset++];

ble_svc_audio_bass_receive_state_find_by_source_id(&rcv_state,
Expand Down Expand Up @@ -530,7 +532,7 @@ ble_svc_audio_bass_set_broadcast_code(uint8_t *data, uint16_t data_len, uint16_t
.type = BLE_AUDIO_EVENT_BASS_BROADCAST_CODE_SET,
};

ev.bass_set_broadcast_code.source_id = data[0];
ev.bass_set_broadcast_code.source_id = data[1];

ble_svc_audio_bass_receive_state_find_by_source_id(&rcv_state,
ev.bass_set_broadcast_code.source_id);
Expand Down Expand Up @@ -617,13 +619,17 @@ 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;
uint16_t mbuf_len = OS_MBUF_PKTLEN(ctxt->om);
struct ble_svc_audio_bass_ctrl_point_handler *handler;
uint8_t data[MYNEWT_VAL(BLE_SVC_AUDIO_BASS_METADATA_MAX_SZ)];

uint8_t opcode = ctxt->om->om_data[0];
os_mbuf_copydata(ctxt->om, 0, mbuf_len, data);
opcode = data[0];

handler = ble_svc_audio_bass_find_handler(opcode);

if (!handler) {
if (handler == NULL) {
return BLE_SVC_AUDIO_BASS_ERR_OPCODE_NOT_SUPPORTED;
}

Expand All @@ -633,7 +639,7 @@ 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);
return handler->handler_cb(data, mbuf_len, conn_handle);
}

static int
Expand Down

0 comments on commit 6d51e7f

Please sign in to comment.