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 22, 2024
1 parent f8994e1 commit e43b04a
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions nimble/host/audio/services/bass/src/ble_audio_svc_bass.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ ble_svc_audio_bass_receive_state_free(struct ble_svc_audio_bass_rcv_state_entry
}

static int
ble_svc_audio_bass_remote_scan_stopped(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
ble_svc_audio_bass_remote_scan_stopped(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle)
{
struct ble_audio_event ev = {
.type = BLE_AUDIO_EVENT_BASS_REMOTE_SCAN_STOPPED
Expand All @@ -262,7 +262,7 @@ ble_svc_audio_bass_remote_scan_stopped(uint8_t *data, uint16_t data_len, uint16_
}

static int
ble_svc_audio_bass_remote_scan_started(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
ble_svc_audio_bass_remote_scan_started(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle)
{
struct ble_audio_event ev = {
.type = BLE_AUDIO_EVENT_BASS_REMOTE_SCAN_STARTED
Expand All @@ -275,7 +275,7 @@ ble_svc_audio_bass_remote_scan_started(uint8_t *data, uint16_t data_len, uint16_
}

static int
ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
ble_svc_audio_bass_add_source(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle)
{
struct ble_audio_event ev = {
.type = BLE_AUDIO_EVENT_BASS_OPERATION_STATUS,
Expand All @@ -290,9 +290,16 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha
uint8_t *metadata_ptr;
uint8_t source_id_new;
uint8_t source_id_to_remove = BLE_SVC_AUDIO_BASS_RECEIVE_STATE_SRC_ID_NONE;
uint16_t om_len;
int rc = 0;
int i;

om_len = OS_MBUF_PKTLEN(ctxt->om);
rc = ble_hs_mbuf_to_flat(ctxt->om, data, om_len, NULL);
if (rc) {
return BLE_ATT_ERR_UNLIKELY;
}

memset(&operation, 0, sizeof(operation));

operation.op = BLE_SVC_AUDIO_BASS_OPERATION_ADD_SOURCE;
Expand Down Expand Up @@ -438,7 +445,7 @@ check_bis_sync(uint16_t num_subgroups, const uint32_t *bis_sync_list)
}

static int
ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
ble_svc_audio_bass_modify_source(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle)
{
struct ble_svc_audio_bass_operation operation;
struct ble_svc_audio_bass_rcv_state_entry *rcv_state = NULL;
Expand All @@ -450,9 +457,16 @@ ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn
}
};
uint8_t offset = 0;
uint16_t om_len;
int rc = 0;
int i;

om_len = OS_MBUF_PKTLEN(ctxt->om);
rc = ble_hs_mbuf_to_flat(ctxt->om, data, om_len, NULL);
if (rc) {
return BLE_ATT_ERR_UNLIKELY;
}

memset(&operation, 0, sizeof(operation));

operation.op = BLE_SVC_AUDIO_BASS_OPERATION_MODIFY_SOURCE;
Expand Down Expand Up @@ -523,13 +537,19 @@ ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn
}

static int
ble_svc_audio_bass_set_broadcast_code(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
ble_svc_audio_bass_set_broadcast_code(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle)
{
struct ble_svc_audio_bass_rcv_state_entry *rcv_state = NULL;
struct ble_audio_event ev = {
.type = BLE_AUDIO_EVENT_BASS_BROADCAST_CODE_SET,
};

om_len = OS_MBUF_PKTLEN(ctxt->om);
rc = ble_hs_mbuf_to_flat(ctxt->om, data, om_len, NULL);
if (rc) {
return BLE_ATT_ERR_UNLIKELY;
}

ev.bass_set_broadcast_code.source_id = data[0];

ble_svc_audio_bass_receive_state_find_by_source_id(&rcv_state,
Expand All @@ -546,7 +566,7 @@ ble_svc_audio_bass_set_broadcast_code(uint8_t *data, uint16_t data_len, uint16_t
}

static int
ble_svc_audio_bass_remove_source(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
ble_svc_audio_bass_remove_source(struct ble_gatt_access_ctxt *ctxt, uint16_t conn_handle)
{
struct ble_audio_event ev = {
.type = BLE_AUDIO_EVENT_BASS_BROADCAST_CODE_SET,
Expand Down Expand Up @@ -617,13 +637,15 @@ 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)
{
struct os_mbuf *om;
uint8_t opcode;
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;
}

Expand All @@ -633,7 +655,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
Expand Down

0 comments on commit e43b04a

Please sign in to comment.