|
34 | 34 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
35 | 35 | #endif |
36 | 36 |
|
37 | | -#define ble_iso_big_conn_handles_init(_big, _handles, _num_handles) \ |
38 | | - do { \ |
39 | | - struct ble_iso_conn *conn = SLIST_FIRST(&ble_iso_conns); \ |
40 | | - \ |
41 | | - for (uint8_t i = 0; i < (_num_handles); i++) { \ |
42 | | - while (conn != NULL) { \ |
43 | | - if (conn->type == BLE_ISO_CONN_BIS) { \ |
44 | | - struct ble_iso_bis *bis; \ |
45 | | - \ |
46 | | - bis = CONTAINER_OF(conn, struct ble_iso_bis, conn); \ |
47 | | - if (bis->big == (_big)) { \ |
48 | | - conn->handle = le16toh((_handles)[i]); \ |
49 | | - conn = SLIST_NEXT(conn, next); \ |
50 | | - break; \ |
51 | | - } \ |
52 | | - } \ |
53 | | - \ |
54 | | - conn = SLIST_NEXT(conn, next); \ |
55 | | - } \ |
56 | | - } \ |
57 | | - } while (0); |
58 | | - |
59 | 37 | enum ble_iso_conn_type { |
60 | 38 | BLE_ISO_CONN_BIS, |
61 | 39 | }; |
@@ -96,6 +74,43 @@ static struct os_mempool ble_iso_bis_pool; |
96 | 74 | static os_membuf_t ble_iso_bis_mem[ |
97 | 75 | OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ISO_MAX_BISES), sizeof (struct ble_iso_bis))]; |
98 | 76 |
|
| 77 | +static int |
| 78 | +ble_iso_big_conn_handles_set(struct ble_iso_big *big, const uint8_t *handles, |
| 79 | + uint8_t num_handles) |
| 80 | +{ |
| 81 | + struct ble_iso_conn *conn; |
| 82 | + uint8_t assigned = 0; |
| 83 | + |
| 84 | + assert(big != NULL); |
| 85 | + assert(handles != NULL); |
| 86 | + assert(num_handles > 0); |
| 87 | + |
| 88 | + SLIST_FOREACH(conn, &ble_iso_conns, next) { |
| 89 | + struct ble_iso_bis *bis; |
| 90 | + |
| 91 | + if (assigned == num_handles) { |
| 92 | + break; |
| 93 | + } |
| 94 | + |
| 95 | + if (conn->type != BLE_ISO_CONN_BIS) { |
| 96 | + continue; |
| 97 | + } |
| 98 | + |
| 99 | + bis = CONTAINER_OF(conn, struct ble_iso_bis, conn); |
| 100 | + if (bis->big != big) { |
| 101 | + continue; |
| 102 | + } |
| 103 | + |
| 104 | + assert(conn->handle == BLE_HS_CONN_HANDLE_NONE); |
| 105 | + conn->handle = get_le16(&handles[assigned * sizeof(uint16_t)]); |
| 106 | + assigned++; |
| 107 | + } |
| 108 | + |
| 109 | + assert(assigned == num_handles); |
| 110 | + |
| 111 | + return 0; |
| 112 | +} |
| 113 | + |
99 | 114 | static void |
100 | 115 | ble_iso_conn_append(struct ble_iso_conn *conn) |
101 | 116 | { |
@@ -360,7 +375,7 @@ ble_iso_rx_create_big_complete(const struct ble_hci_ev_le_subev_create_big_compl |
360 | 375 | /* XXX: Should we destroy the group? */ |
361 | 376 | } |
362 | 377 |
|
363 | | - ble_iso_big_conn_handles_init(big, ev->conn_handle, ev->num_bis); |
| 378 | + ble_iso_big_conn_handles_set(big, (const uint8_t *)ev->conn_handle, ev->num_bis); |
364 | 379 |
|
365 | 380 | big->max_pdu = ev->max_pdu; |
366 | 381 |
|
@@ -643,7 +658,7 @@ ble_iso_rx_big_sync_established(const struct ble_hci_ev_le_subev_big_sync_establ |
643 | 658 | /* XXX: Should we destroy the group? */ |
644 | 659 | } |
645 | 660 |
|
646 | | - ble_iso_big_conn_handles_init(big, ev->conn_handle, ev->num_bis); |
| 661 | + ble_iso_big_conn_handles_set(big, (const uint8_t *)ev->conn_handle, ev->num_bis); |
647 | 662 |
|
648 | 663 | event.big_sync_established.desc.big_handle = ev->big_handle; |
649 | 664 | event.big_sync_established.desc.transport_latency_big = |
|
0 commit comments