Skip to content

Commit e13edf6

Browse files
kevin-whisperNahal Farhi
authored andcommitted
[MFI] Add ability to pass MFI audio through HCI (zephyrproject-rtos#27)
MFI audio packets now pass through HCI with the packet boundary flag set to '11' as suggested by the MFI spec
1 parent af741c4 commit e13edf6

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,11 @@ struct bt_conn *bt_conn_create_br(const bt_addr_t *peer,
14921492
*/
14931493
struct bt_conn *bt_conn_create_sco(const bt_addr_t *peer);
14941494

1495+
// *** Whisper added for MFI. Register a callback for when audio packets are
1496+
// received so the BLE stack knows where to pass them
1497+
typedef void (*hci_mfi_audio_recv_cb_fn)(const uint8_t *data, uint8_t data_len);
1498+
void bt_conn_mfi_audio_register_cb(hci_mfi_audio_recv_cb_fn mfi_audio_cb);
1499+
14951500
#ifdef __cplusplus
14961501
}
14971502
#endif

subsys/bluetooth/controller/hci/hci.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7946,9 +7946,14 @@ void hci_acl_encode(struct node_rx_pdu *node_rx, struct net_buf *buf)
79467946
switch (pdu_data->ll_id) {
79477947
case PDU_DATA_LLID_DATA_CONTINUE:
79487948
case PDU_DATA_LLID_DATA_START:
7949+
case PDU_DATA_LLID_RESV:
79497950
acl = (void *)net_buf_add(buf, sizeof(*acl));
79507951
if (pdu_data->ll_id == PDU_DATA_LLID_DATA_START) {
79517952
handle_flags = bt_acl_handle_pack(handle, BT_ACL_START);
7953+
} else if (pdu_data->ll_id == PDU_DATA_LLID_RESV) {
7954+
// MFI audio packets get sent over HCI with the packet boundary
7955+
// flag set to '11' which is normally unused
7956+
handle_flags = bt_acl_handle_pack(handle, BT_ACL_COMPLETE);
79527957
} else {
79537958
handle_flags = bt_acl_handle_pack(handle, BT_ACL_CONT);
79547959
}

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,15 @@ static inline int isr_rx_pdu(struct lll_conn *lll, struct pdu_data *pdu_data_rx,
10601060

10611061
// if this is an audio packet and the primary transmit slot, deassert the sync signal
10621062
// for the ezairo
1063-
if((pdu_data_rx->ll_id == PDU_DATA_LLID_RESV) &&
1064-
(pdu_data_rx->sn == 0) &&
1065-
lll_mfi_audio_sync_deassert_cb) {
1066-
lll_mfi_audio_sync_deassert_cb();
1063+
if(pdu_data_rx->ll_id == PDU_DATA_LLID_RESV) {
1064+
// at the end of the packet, append the transmit slot type
1065+
pdu_data_rx->lldata[pdu_data_rx->len] = pdu_data_rx->sn;
1066+
pdu_data_rx->len = pdu_data_rx->len + 1;
1067+
1068+
// if this is the primary transmit slot, de-assert the sync signal for the ezairo
1069+
if((pdu_data_rx->sn == 0) && lll_mfi_audio_sync_deassert_cb) {
1070+
lll_mfi_audio_sync_deassert_cb();
1071+
}
10671072
}
10681073
}
10691074

subsys/bluetooth/controller/ll_sw/ull_conn.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "ull_conn_types.h"
4343
#include "ull_conn_iso_types.h"
4444
#include "ull_internal.h"
45-
#include "ull_mfi_audio_internal.h"
4645
#include "ull_sched_internal.h"
4746
#include "ull_chan_internal.h"
4847
#include "ull_conn_internal.h"
@@ -998,12 +997,6 @@ void ull_conn_setup(memq_link_t *rx_link, struct node_rx_hdr *rx)
998997
}
999998
}
1000999

1001-
// *** Whisper added for MFI
1002-
static mfi_audio_recv_cb_fn ull_mfi_audio_cb = NULL;
1003-
void ull_mfi_audio_register_cb(mfi_audio_recv_cb_fn mfi_audio_cb) {
1004-
ull_mfi_audio_cb = mfi_audio_cb;
1005-
}
1006-
10071000
int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx)
10081001
{
10091002
struct pdu_data *pdu_rx;
@@ -1057,19 +1050,9 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx)
10571050
break;
10581051

10591052
case PDU_DATA_LLID_RESV:
1060-
// *** Whisper added for MFI. MFI audio packets come in with the reserved
1061-
// LLID. When we see these packets, pass the payload on to the mfi audio callback
1062-
// if the callback exists
1063-
if (ull_mfi_audio_cb) {
1064-
mfi_audio_slot_type_t slot_type;
1065-
if(pdu_rx->sn == 0) {
1066-
slot_type = MFI_AUDIO_SLOT_TYPE_PRIMARY;
1067-
} else {
1068-
slot_type = MFI_AUDIO_SLOT_TYPE_RETRANSMIT;
1069-
}
1070-
ull_mfi_audio_cb(pdu_rx->lldata, pdu_rx->len, slot_type);
1071-
}
1072-
// fallthrough (this existed before whisper modification)
1053+
// *** Whisper added for MFI. Previously this would fallthrough and mark
1054+
// the node for release but now we added a break so the packet isn't discarded
1055+
break;
10731056
default:
10741057
#if defined(CONFIG_BT_CTLR_LE_ENC)
10751058
#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY)

subsys/bluetooth/controller/ll_sw/ull_mfi_audio_internal.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

subsys/bluetooth/host/conn.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ void bt_conn_reset_rx_state(struct bt_conn *conn)
236236
conn->rx = NULL;
237237
}
238238

239+
// *** Whisper added for MFI
240+
static hci_mfi_audio_recv_cb_fn bt_conn_mfi_audio_cb = NULL;
241+
void bt_conn_mfi_audio_register_cb(hci_mfi_audio_recv_cb_fn mfi_audio_cb) {
242+
bt_conn_mfi_audio_cb = mfi_audio_cb;
243+
}
244+
239245
static void bt_acl_recv(struct bt_conn *conn, struct net_buf *buf,
240246
uint8_t flags)
241247
{
@@ -285,6 +291,17 @@ static void bt_acl_recv(struct bt_conn *conn, struct net_buf *buf,
285291
net_buf_add_mem(conn->rx, buf->data, buf->len);
286292
net_buf_unref(buf);
287293
break;
294+
// *** Whisper added for MFI. BT_ACL_COMPLETE is a packet boundary flag of '11' which
295+
// is how apple recommends transferring audio data over HCI. this packet boundary flag
296+
// is normally unused here
297+
case BT_ACL_COMPLETE:
298+
if(bt_conn_mfi_audio_cb) {
299+
bt_conn_mfi_audio_cb(buf->data, buf->len);
300+
}
301+
bt_conn_reset_rx_state(conn);
302+
net_buf_unref(buf);
303+
return;
304+
288305
default:
289306
/* BT_ACL_START_NO_FLUSH and BT_ACL_COMPLETE are not allowed on
290307
* LE-U from Controller to Host.

0 commit comments

Comments
 (0)