Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Add support for framed ISO PDU #1941

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions nimble/controller/include/controller/ble_ll_isoal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ struct ble_ll_isoal_mux {

/* Max PDU length */
uint8_t max_pdu;
/* Number of expected SDUs per ISO interval */
uint8_t sdu_per_interval;
/* Number of expected PDUs per SDU */
uint8_t pdu_per_sdu;
/* Number of SDUs required to fill complete BIG/CIG event (i.e. with pt) */
uint8_t sdu_per_event;
/* Number of SDUs available for current event */
uint8_t sdu_in_event;

struct {
/* Number of expected SDUs per ISO interval */
uint8_t sdu_per_interval;
/* Number of expected PDUs per SDU */
uint8_t pdu_per_sdu;
/* Number of SDUs required to fill complete BIG/CIG event (i.e. with pt) */
uint8_t sdu_per_event;
/* Number of SDUs available for current event */
uint8_t sdu_in_event;
};

STAILQ_HEAD(, os_mbuf_pkthdr) sdu_q;
uint16_t sdu_q_len;
Expand All @@ -52,21 +55,22 @@ struct ble_ll_isoal_mux {
uint32_t event_tx_timestamp;
uint32_t last_tx_timestamp;
uint16_t last_tx_packet_seq_num;

uint8_t framed : 1;
};

void
ble_ll_isoal_mux_init(struct ble_ll_isoal_mux *mux, uint8_t max_pdu,
uint32_t iso_interval_us, uint32_t sdu_interval_us,
uint8_t bn, uint8_t pte);
uint8_t bn, uint8_t pte, uint8_t framed);
void ble_ll_isoal_mux_free(struct ble_ll_isoal_mux *mux);

int ble_ll_isoal_mux_event_start(struct ble_ll_isoal_mux *mux,
uint32_t timestamp);
int ble_ll_isoal_mux_event_done(struct ble_ll_isoal_mux *mux);

int
ble_ll_isoal_mux_unframed_get(struct ble_ll_isoal_mux *mux, uint8_t idx,
uint8_t *llid, void *dptr);
int ble_ll_isoal_mux_pdu_get(struct ble_ll_isoal_mux *mux, uint8_t idx,
uint8_t *llid, void *dptr);

/* HCI command handlers */
int ble_ll_isoal_hci_setup_iso_data_path(const uint8_t *cmdbuf, uint8_t cmdlen,
Expand Down
66 changes: 45 additions & 21 deletions nimble/controller/src/ble_ll_iso_big.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ struct ble_ll_iso_bis {
uint16_t prn_sub_lu;
uint16_t remap_idx;

uint8_t subevent_num;
uint8_t n;
uint8_t g;
uint8_t subevent_num; /* 1-NSE, current subevent number */
uint8_t n; /* 1-BN, current burst number */
uint8_t g; /* 0-(NSE/BN), group number. Each group consists of BN subevents */
} tx;

struct ble_ll_isoal_mux mux;
Expand Down Expand Up @@ -111,7 +111,6 @@ struct ble_ll_iso_big {
uint8_t irc; /* 1-15 */
uint8_t nse; /* 1-31 */
uint8_t interleaved : 1;
uint8_t framed : 1;
uint8_t encrypted : 1;
uint8_t giv[8];
uint8_t gskd[16];
Expand Down Expand Up @@ -707,8 +706,10 @@ ble_ll_iso_big_subevent_pdu_cb(uint8_t *dptr, void *arg, uint8_t *hdr_byte)

/* Core 5.3, Vol 6, Part B, 4.4.6.6 */
if (bis->tx.g < big->irc) {
/* Group carry the data associated with the current BIS event */
idx = bis->tx.n;
} else {
/* Group carry the data associated with the future BIS event specified by PTO */
idx = big->bn * big->pto * (bis->tx.g - big->irc + 1) + bis->tx.n;
}

Expand All @@ -718,26 +719,54 @@ ble_ll_iso_big_subevent_pdu_cb(uint8_t *dptr, void *arg, uint8_t *hdr_byte)
ble_phy_encrypt_counter_set(big->bis_counter + idx, 1);
}

#if 1
pdu_len = ble_ll_isoal_mux_unframed_get(&bis->mux, idx, &llid, dptr);
#if 0
pdu_len = ble_ll_isoal_mux_pdu_get(&bis->mux, idx, &llid, dptr);
#else
llid = 0;
pdu_len = big->max_pdu;
/* XXX dummy data for testing */
memset(dptr, bis->num | (bis->num << 4), pdu_len);
if (bis->mux.framed) {
llid = 2;
/* Segmentation Header */
union {
uint16_t u16;
struct {
uint8_t sc: 1;
uint8_t cmplt: 1;
uint8_t length;
};
} seg_hdr = {
.sc = 0,
.cmplt = 1,
.length = pdu_len - 2,
};
put_le16(dptr, seg_hdr.u16);
dptr += 2;
/* TimeOffset */
put_le24(dptr, 1000);
dptr += 3;
} else {
llid = 0;
}
put_be32(dptr, big->big_counter);
put_be32(&dptr[4], big->bis_counter + idx);
dptr[8] = bis->tx.subevent_num;
dptr[9] = bis->tx.g;
dptr[10] = bis->tx.n;
dptr += 4;
put_be32(dptr, big->bis_counter + idx);
dptr += 4;
*dptr = bis->tx.subevent_num;
dptr++;
*dptr = bis->tx.g;
dptr++;
*dptr = bis->tx.n;
dptr++;
if (bis->tx.g == 0) {
dptr[11] = 'B';
*dptr = 'B'; /* (B)urst */
} else if (bis->tx.g < big->irc) {
dptr[11] = 'R';
*dptr = 'R'; /* (R)epetition */
} else {
dptr[11] = 'P';
*dptr = 'P'; /* (P)retransmission */
}
dptr[12] = 0xff;
dptr++;
*dptr = 0xff;
#endif

*hdr_byte = llid | (big->cssn << 2) | (big->cstf << 5);
Expand Down Expand Up @@ -856,8 +885,6 @@ ble_ll_iso_big_event_sched_cb(struct ble_ll_sched_item *sch)

ble_ll_tx_power_set(g_ble_ll_tx_power);

BLE_LL_ASSERT(!big->framed);

/* XXX calculate this in advance at the end of previous event? */
big->tx.subevents_rem = big->num_bis * big->nse;
STAILQ_FOREACH(bis, &big->bis_q, bis_q_next) {
Expand Down Expand Up @@ -1038,10 +1065,8 @@ ble_ll_iso_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis,
bis->num = big->num_bis;
bis->crc_init = (big->crc_init << 8) | (big->num_bis);

BLE_LL_ASSERT(!big->framed);

ble_ll_isoal_mux_init(&bis->mux, bp->max_pdu, bp->iso_interval * 1250,
bp->sdu_interval, bp->bn, pte);
bp->sdu_interval, bp->bn, pte, bp->framed);
}

big_pool_free--;
Expand Down Expand Up @@ -1077,7 +1102,6 @@ ble_ll_iso_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis,
big->irc = bp->irc;
big->nse = bp->nse;
big->interleaved = bp->interleaved;
big->framed = bp->framed;
big->encrypted = bp->encrypted;
big->sdu_interval = bp->sdu_interval;
big->iso_interval = bp->iso_interval;
Expand Down
24 changes: 23 additions & 1 deletion nimble/controller/src/ble_ll_isoal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static struct ble_ll_iso_tx_q ll_isoal_tx_q;
void
ble_ll_isoal_mux_init(struct ble_ll_isoal_mux *mux, uint8_t max_pdu,
uint32_t iso_interval_us, uint32_t sdu_interval_us,
uint8_t bn, uint8_t pte)
uint8_t bn, uint8_t pte, uint8_t framed)
{
memset(mux, 0, sizeof(*mux));

Expand All @@ -47,6 +47,8 @@ ble_ll_isoal_mux_init(struct ble_ll_isoal_mux *mux, uint8_t max_pdu,

STAILQ_INIT(&mux->sdu_q);
mux->sdu_q_len = 0;

mux->framed = framed;
}

void
Expand Down Expand Up @@ -254,6 +256,26 @@ ble_ll_isoal_mux_unframed_get(struct ble_ll_isoal_mux *mux, uint8_t idx,
return pdu_len;
}

static int
ble_ll_isoal_mux_framed_get(struct ble_ll_isoal_mux *mux, uint8_t idx,
uint8_t *llid, void *dptr)
{


return 0;
}

int
ble_ll_isoal_mux_pdu_get(struct ble_ll_isoal_mux *mux, uint8_t idx,
uint8_t *llid, void *dptr)
{
if (mux->framed) {
return ble_ll_isoal_mux_framed_get(mux, idx, llid, dptr);
} else {
return ble_ll_isoal_mux_unframed_get(mux, idx, llid, dptr);
}
}

static void
ble_ll_isoal_tx_pkt_in(struct ble_npl_event *ev)
{
Expand Down
Loading