1 /*
2  * Copyright (c) 2021 Demant
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 struct ll_conn;
8 
9 typedef void (*ll_iso_stream_released_cb_t)(struct ll_conn *conn);
10 
11 #define CIG_STATE_NO_CIG       0
12 #define CIG_STATE_CONFIGURABLE 1 /* Central only */
13 #define CIG_STATE_INITIATING   2 /* Central only */
14 #define CIG_STATE_ACTIVE       3
15 #define CIG_STATE_INACTIVE     4
16 
17 struct ll_conn_iso_stream {
18 	struct ll_iso_stream_hdr hdr;
19 	struct lll_conn_iso_stream lll;
20 
21 	struct ll_conn_iso_group *group;
22 
23 	uint16_t c_max_sdu:12;    /* Maximum SDU size C_To_P */
24 	uint16_t p_max_sdu:12;    /* Maximum SDU size P_To_C */
25 	uint8_t  framed:1;        /* 0: unframed, 1: framed */
26 	uint16_t established:1;   /* 0 if CIS has not yet been established.
27 				   * 1 if CIS has been established and host
28 				   * notified.
29 				   */
30 	uint16_t trx_performed:1; /* 1 if CIS had a transaction */
31 	uint16_t teardown:1;      /* 1 if CIS teardown has been initiated */
32 
33 	union {
34 		struct {
35 			uint8_t  c_rtn;
36 			uint8_t  p_rtn;
37 			uint16_t instant;
38 		} central;
39 	};
40 
41 	uint32_t offset;          /* Offset of CIS from ACL event in us */
42 	uint32_t sync_delay;
43 
44 	ll_iso_stream_released_cb_t released_cb; /* CIS release callback */
45 
46 	uint16_t event_expire;     /* Supervision & Connect Timeout event
47 				    * counter
48 				    */
49 	uint8_t  terminate_reason;
50 	uint8_t  cis_id;
51 
52 #if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE)
53 	uint64_t pkt_seq_num:39;
54 #endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */
55 };
56 
57 struct ll_conn_iso_group {
58 	struct ull_hdr            ull;
59 	struct lll_conn_iso_group lll;
60 
61 	uint32_t c_sdu_interval;
62 	uint32_t p_sdu_interval;
63 	uint32_t c_latency;	/* Transport_Latency_M_To_S = CIG_Sync_Delay +
64 				 * (FT_M_To_S) × ISO_Interval +
65 				 * SDU_Interval_M_To_S
66 				 */
67 	uint32_t p_latency;	/* Transport_Latency_S_To_M = CIG_Sync_Delay +
68 				 * (FT_S_To_M) × ISO_Interval +
69 				 * SDU_Interval_S_To_M
70 				 */
71 	uint32_t cig_ref_point;	/* CIG reference point timestamp (us) based on
72 				 * controller's clock.
73 				 */
74 	uint32_t sync_delay;
75 
76 	uint16_t iso_interval;
77 	uint8_t  cig_id;
78 
79 	uint8_t  state:3;       /* CIG_STATE_NO_CIG, CIG_STATE_CONFIGURABLE (central only),
80 				 * CIG_STATE_INITIATING (central only), CIG_STATE_ACTIVE or
81 				 * CIG_STATE_INACTIVE.
82 				 */
83 	uint8_t  sca_update:4;  /* (new SCA)+1 to trigger restart of ticker */
84 
85 	union {
86 		struct {
87 			uint8_t sca;
88 			uint8_t packing;
89 			uint8_t framing;
90 			uint8_t test:1; /* HCI_LE_Set_CIG_Parameters_Test */
91 		} central;
92 	};
93 };
94 
95 struct node_rx_conn_iso_req {
96 	uint16_t cis_handle;
97 	uint8_t  cig_id;
98 	uint8_t  cis_id;
99 };
100 
101 struct node_rx_conn_iso_estab {
102 	uint16_t cis_handle;
103 	uint8_t  status;
104 };
105