Linux Audio

Check our new training course

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
 * Copyright (c) 2018-2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#define IS_ACL_HANDLE(_handle) ((_handle) < CONFIG_BT_MAX_CONN)

enum llcp {
	LLCP_NONE,
	LLCP_CONN_UPD,
	LLCP_CHAN_MAP,

	/*
	 * LLCP_TERMINATE,
	 * LLCP_FEATURE_EXCHANGE,
	 * LLCP_VERSION_EXCHANGE,
	 */

#if defined(CONFIG_BT_CTLR_LE_ENC)
	LLCP_ENCRYPTION,
#endif /* CONFIG_BT_CTLR_LE_ENC */

	LLCP_CONNECTION_PARAM_REQ,

#if defined(CONFIG_BT_CTLR_LE_PING)
	LLCP_PING,
#endif /* CONFIG_BT_CTLR_LE_PING */

#if defined(CONFIG_BT_CTLR_PHY)
	LLCP_PHY_UPD,
#endif /* CONFIG_BT_CTLR_PHY */
};

#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY)
struct ll_conn {
	struct ull_hdr  ull;
	struct lll_conn lll;

	uint16_t connect_expire;
	uint16_t supervision_reload;
	uint16_t supervision_expire;
	uint16_t procedure_reload;
	uint16_t procedure_expire;

#if defined(CONFIG_BT_CTLR_LE_PING)
	uint16_t appto_reload;
	uint16_t appto_expire;
	uint16_t apto_reload;
	uint16_t apto_expire;
#endif /* CONFIG_BT_CTLR_LE_PING */

#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
	uint16_t default_tx_octets;

#if defined(CONFIG_BT_CTLR_PHY)
	uint16_t default_tx_time;
#endif /* CONFIG_BT_CTLR_PHY */
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */

#if defined(CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN)
	uint8_t own_id_addr_type:1;
	uint8_t peer_id_addr_type:1;
	uint8_t own_id_addr[BDADDR_SIZE];
	uint8_t peer_id_addr[BDADDR_SIZE];
#endif /* CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN */

	union {
		struct {
			uint8_t fex_valid:1;
			uint8_t txn_lock:1;
#if defined(CONFIG_BT_CTLR_CONN_META)
			uint8_t is_must_expire:1;
#endif /* CONFIG_BT_CTLR_CONN_META */
		} common;

#if defined(CONFIG_BT_PERIPHERAL)
		struct {
			uint8_t  fex_valid:1;
			uint8_t  txn_lock:1;
#if defined(CONFIG_BT_CTLR_CONN_META)
			uint8_t  is_must_expire:1;
#endif /* CONFIG_BT_CTLR_CONN_META */
			uint8_t  latency_cancel:1;
			uint8_t  sca:3;
#if defined(CONFIG_BT_CTLR_LE_ENC)
			uint8_t  llcp_type;
#endif /* CONFIG_BT_CTLR_LE_ENC */
#if defined(CONFIG_BT_CTLR_CONN_RANDOM_FORCE)
			uint32_t force;
#endif /* CONFIG_BT_CTLR_CONN_RANDOM_FORCE */
#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
			uint32_t ticks_to_offset;
#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
		} periph;
#endif /* CONFIG_BT_PERIPHERAL */

#if defined(CONFIG_BT_CENTRAL)
		struct {
			uint8_t fex_valid:1;
			uint8_t txn_lock:1;
#if defined(CONFIG_BT_CTLR_CONN_META)
			uint8_t is_must_expire:1;
#endif /* CONFIG_BT_CTLR_CONN_META */
			uint8_t terminate_ack:1;
		} central;
#endif /* CONFIG_BT_CENTRAL */
	};

	uint8_t llcp_req;
	uint8_t llcp_ack;

	uint8_t llcp_type;

	struct {
		union {
			struct {
				uint16_t instant;
				uint16_t *pdu_win_offset;
				uint32_t ticks_anchor;
			} conn_upd;

			struct {
				uint8_t  initiate:1;
				uint8_t  chm[5];
				uint16_t instant;
			} chan_map;

#if defined(CONFIG_BT_CTLR_PHY)
			struct {
				uint8_t initiate:1;
				uint8_t cmd:1;
				uint8_t tx:3;
				uint8_t rx:3;
				uint16_t instant;
			} phy_upd_ind;
#endif /* CONFIG_BT_CTLR_PHY */
		};

#if defined(CONFIG_BT_CTLR_LE_ENC)
		struct {
			enum {
				LLCP_ENC_STATE_INPROG,
				LLCP_ENC_STATE_INIT,
				LLCP_ENC_STATE_LTK_WAIT,
				LLCP_ENC_STATE_ENC_WAIT,
			} state:2 __packed;
			uint8_t  error_code;
			uint8_t  skd[16];
		} encryption;
#endif /* CONFIG_BT_CTLR_LE_ENC */
	} llcp;

	struct node_rx_pdu *llcp_rx;

#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD)
	struct node_rx_pdu *llcp_rx_hold;
#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */

	struct {
		uint8_t  req;
		uint8_t  ack;
		enum {
			LLCP_CUI_STATE_INPROG,
			LLCP_CUI_STATE_USE,
			LLCP_CUI_STATE_SELECT,
			LLCP_CUI_STATE_OFFS_REQ,
			LLCP_CUI_STATE_OFFS_RDY,
			LLCP_CUI_STATE_REJECT,
		} state:3 __packed;
		uint8_t  cmd:1;
		uint16_t interval;
		uint16_t latency;
		uint16_t timeout;
		uint32_t win_offset_us;
		uint8_t  win_size;
	} llcp_cu;

	struct {
		uint8_t  req;
		uint8_t  ack;
		/* TODO: 8, 16, 32 or 64 based on local supported features */
		uint64_t features_conn;
		uint64_t features_peer;
	} llcp_feature;

	struct {
		uint8_t  req;
		uint8_t  ack;
		uint8_t  tx:1;
		uint8_t  rx:1;
		uint8_t  version_number;
		uint16_t company_id;
		uint16_t sub_version_number;
	} llcp_version;

	struct {
		uint8_t req;
		uint8_t ack;
		uint8_t reason_own;
		uint8_t reason_final;
		/* node rx type with memory aligned storage for terminate
		 * reason.
		 * HCI will reference the value using the pdu member of
		 * struct node_rx_pdu.
		 */
		struct {
			struct node_rx_hdr hdr;
			union {
				uint8_t    pdu[0] __aligned(4);
				uint8_t    reason;
			};
		} node_rx;
	} llcp_terminate;

#if defined(CONFIG_BT_CTLR_LE_ENC)
	struct {
		uint8_t req;
		uint8_t ack;
		uint8_t pause_rx:1;
		uint8_t pause_tx:1;
		uint8_t refresh:1;
		uint8_t ediv[2];
		uint8_t rand[8];
		uint8_t ltk[16];
	} llcp_enc;
#endif /* CONFIG_BT_CTLR_LE_ENC */

#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
	struct {
		uint8_t  req;
		uint8_t  ack;
		enum {
			LLCP_CPR_STATE_REQ,
			LLCP_CPR_STATE_RSP,
			LLCP_CPR_STATE_APP_REQ,
			LLCP_CPR_STATE_APP_WAIT,
			LLCP_CPR_STATE_RSP_WAIT,
			LLCP_CPR_STATE_UPD_WAIT,
			LLCP_CPR_STATE_UPD,
			LLCP_CPR_STATE_OFFS_REQ,
			LLCP_CPR_STATE_OFFS_RDY,
		} state:4 __packed;
		uint8_t  cmd:1;
		uint8_t  disabled:1;
		uint8_t  status;
		uint16_t interval_min;
		uint16_t interval_max;
		uint16_t latency;
		uint16_t timeout;
		uint8_t  preferred_periodicity;
		uint16_t reference_conn_event_count;
		uint16_t offset0;
		uint16_t offset1;
		uint16_t offset2;
		uint16_t offset3;
		uint16_t offset4;
		uint16_t offset5;
		uint16_t *pdu_win_offset0;
		uint32_t ticks_ref;
		uint32_t ticks_to_offset_next;
	} llcp_conn_param;
#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */

#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
	struct {
		uint8_t  req;
		uint8_t  ack;
		uint8_t  state:3;
#define LLCP_LENGTH_STATE_REQ                 0
#define LLCP_LENGTH_STATE_REQ_ACK_WAIT        1
#define LLCP_LENGTH_STATE_RSP_WAIT            2
#define LLCP_LENGTH_STATE_RSP_ACK_WAIT        3
#define LLCP_LENGTH_STATE_RESIZE              4
#define LLCP_LENGTH_STATE_RESIZE_RSP          5
#define LLCP_LENGTH_STATE_RESIZE_RSP_ACK_WAIT 6
		uint8_t  disabled:1;
		uint16_t rx_octets;
		uint16_t tx_octets;
#if defined(CONFIG_BT_CTLR_PHY)
		uint16_t rx_time;
		uint16_t tx_time;
#endif /* CONFIG_BT_CTLR_PHY */
		struct {
			uint16_t tx_octets;
#if defined(CONFIG_BT_CTLR_PHY)
			uint16_t tx_time;
#endif /* CONFIG_BT_CTLR_PHY */
		} cache;
	} llcp_length;
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */

#if defined(CONFIG_BT_CTLR_PHY)
	struct {
		uint8_t req;
		uint8_t ack;
		uint8_t state:2;
#define LLCP_PHY_STATE_REQ      0
#define LLCP_PHY_STATE_ACK_WAIT 1
#define LLCP_PHY_STATE_RSP_WAIT 2
#define LLCP_PHY_STATE_UPD      3
		uint8_t tx:3;
		uint8_t rx:3;
		uint8_t pause_tx:1;
		uint8_t flags:1;
		uint8_t cmd:1;
		uint8_t disabled:1;
	} llcp_phy;

	uint8_t phy_pref_tx:3;
	uint8_t phy_pref_rx:3;
#endif /* CONFIG_BT_CTLR_PHY */

#if defined(CONFIG_BT_CTLR_LLID_DATA_START_EMPTY)
	/* Detect empty L2CAP start frame */
	uint8_t  start_empty:1;
#endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */

	struct node_tx *tx_head;
	struct node_tx *tx_ctrl;
	struct node_tx *tx_ctrl_last;
	struct node_tx *tx_data;
	struct node_tx *tx_data_last;

	uint8_t chm_updated;

#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
	struct {
		uint8_t  req;
		uint8_t  ack;
		enum {
			LLCP_CIS_STATE_REQ,
			LLCP_CIS_STATE_RSP_WAIT,
			LLCP_CIS_STATE_IND_WAIT,
			LLCP_CIS_STATE_INST_WAIT
		} state:8 __packed;
		uint8_t  cig_id;
		uint16_t cis_handle;
		uint8_t  cis_id;
		uint32_t cis_offset_min;
		uint32_t cis_offset_max;
		uint16_t conn_event_count;
	} llcp_cis;
#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */

#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ)
	struct lll_df_conn_rx_params df_rx_params;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
};
#else
/*
 * This is for the refactored LLCP
 *
 * to reduce length and unreadability of the ll_conn struct the
 * structures inside it have been defined first
 */
struct llcp_struct {
	/* Local Request */
	struct {
		sys_slist_t pend_proc_list;
		uint8_t state;
		/* Procedure Response Timeout timer expire value */
		uint16_t prt_expire;
		uint8_t pause;
	} local;

	/* Remote Request */
	struct {
		sys_slist_t pend_proc_list;
		uint8_t state;
		/* Procedure Response Timeout timer expire value */
		uint16_t prt_expire;
		uint8_t pause;
		uint8_t collision;
		uint8_t incompat;
		uint8_t reject_opcode;
#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RSP) || defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ)
		uint8_t paused_cmd;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP || CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
	} remote;

	/* Procedure Response Timeout timer reload value */
	uint16_t prt_reload;

	/* Prepare parameters */
	struct {
		uint32_t ticks_at_expire;
		uint16_t lazy;
	} prep;

	/* Version Exchange Procedure State */
	struct {
		uint8_t sent;
		uint8_t valid;
		struct pdu_data_llctrl_version_ind cached;
	} vex;

	/*
	 * As of today only 36 feature bits are in use,
	 * so some optimisation is possible
	 * we also need to keep track of the features of the
	 * other node, so that we can send a proper
	 * reply over HCI to the host
	 * see BT Core spec 5.2 Vol 6, Part B, sec. 5.1.4
	 */
	struct {
		uint8_t sent;
		uint8_t valid;
		/*
		 * Stores features supported by peer device. The content of the member may be
		 * verified when feature exchange procedure has completed, valid member is set to 1.
		 */
		uint64_t features_peer;
		/*
		 * Stores features common for two connected devices. Before feature exchange
		 * procedure is completed, the member stores information about all features
		 * supported by local device. After completion of the procedure, the feature set
		 * may be limited to features that are common.
		 */
		uint64_t features_used;
	} fex;

	/* Minimum used channels procedure state */
	struct {
		uint8_t phys;
		uint8_t min_used_chans;
	} muc;

	/* TODO: we'll need the next few structs eventually,
	 * Thomas and Szymon please comment on names etc.
	 */
	struct {
		uint16_t *pdu_win_offset;
		uint32_t ticks_anchor;
	} conn_upd;

#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ)
	/* @brief Constant Tone Extension configuration for CTE request control procedure. */
	struct llcp_df_req_cfg {
		/* Procedure may be active periodically, active state must be stored.
		 * If procedure is active, request parameters update may not be issued.
		 */
		volatile uint8_t is_enabled;
		uint8_t cte_type;
		/* Minimum requested CTE length in 8us units */
		uint8_t min_cte_len;
		uint16_t req_interval;
		uint16_t req_expire;
	} cte_req;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */

#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RSP)
	struct llcp_df_rsp_cfg {
		uint8_t is_enabled:1;
		uint8_t is_active:1;
		uint8_t cte_types;
		uint8_t max_cte_len;
		void *disable_param;
		void (*disable_cb)(void *param);
	} cte_rsp;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */

	struct {
		uint8_t terminate_ack;
	} cis;

	uint8_t tx_buffer_alloc;
	uint8_t tx_q_pause_data_mask;
}; /* struct llcp_struct */

struct ll_conn {
	struct ull_hdr  ull;
	struct lll_conn lll;

	struct ull_tx_q tx_q;
	struct llcp_struct llcp;

	struct {
		uint8_t reason_final;
		/* node rx type with memory aligned storage for terminate
		 * reason.
		 * HCI will reference the value using the pdu member of
		 * struct node_rx_pdu.
		 */
		struct {
			struct node_rx_hdr hdr;

			uint8_t reason __aligned(4);
		} node_rx;
	} llcp_terminate;

/*
 * TODO: all the following comes from the legacy LL llcp structure
 * and/or needs to be properly integrated in the control procedures
 */
	union {
		struct {
#if defined(CONFIG_BT_CTLR_CONN_META)
			uint8_t  is_must_expire:1;
#endif /* CONFIG_BT_CTLR_CONN_META */
		} common;
#if defined(CONFIG_BT_PERIPHERAL)
		struct {
#if defined(CONFIG_BT_CTLR_CONN_META)
			uint8_t  is_must_expire:1;
#endif /* CONFIG_BT_CTLR_CONN_META */
			uint8_t  latency_cancel:1;
			uint8_t  sca:3;
			uint32_t force;
			uint32_t ticks_to_offset;
		} periph;
#endif /* CONFIG_BT_PERIPHERAL */

#if defined(CONFIG_BT_CENTRAL)
		struct {
#if defined(CONFIG_BT_CTLR_CONN_META)
			uint8_t  is_must_expire:1;
#endif /* CONFIG_BT_CTLR_CONN_META */
			uint8_t terminate_ack:1;
		} central;
#endif /* CONFIG_BT_CENTRAL */
	};

	/* Cancel the prepare in the instant a Connection Update takes place */
	uint8_t cancel_prepare:1;

#if defined(CONFIG_BT_CTLR_LE_ENC)
	/* Pause Rx data PDU's */
	uint8_t pause_rx_data:1;
#endif /* CONFIG_BT_CTLR_LE_ENC */

#if defined(CONFIG_BT_CTLR_LE_PING)
	uint16_t appto_reload;
	uint16_t appto_expire;
	uint16_t apto_reload;
	uint16_t apto_expire;
#endif /* CONFIG_BT_CTLR_LE_PING */

	uint16_t connect_expire;
	uint16_t supervision_reload;
	uint16_t supervision_expire;
	uint32_t connect_accept_to;

#if defined(CONFIG_BT_CTLR_PHY)
	uint8_t phy_pref_tx:3;
	uint8_t phy_pref_rx:3;
#endif /* CONFIG_BT_CTLR_PHY */
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
	uint16_t default_tx_octets;

#if defined(CONFIG_BT_CTLR_PHY)
	uint16_t default_tx_time;
#endif /* CONFIG_BT_CTLR_PHY */
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */

#if defined(CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN)
	uint8_t own_id_addr_type:1;
	uint8_t peer_id_addr_type:1;
	uint8_t own_id_addr[BDADDR_SIZE];
	uint8_t peer_id_addr[BDADDR_SIZE];
#endif /* CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN */

#if defined(CONFIG_BT_CTLR_LLID_DATA_START_EMPTY)
	/* Detect empty L2CAP start frame */
	uint8_t  start_empty:1;
#endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */
}; /* struct ll_conn */
#endif /* BT_LL_SW_SPLIT_LEGACY */

struct node_rx_cc {
	uint8_t  status;
	uint8_t  role;
	uint8_t  peer_addr_type;
	uint8_t  peer_addr[BDADDR_SIZE];
#if defined(CONFIG_BT_CTLR_PRIVACY)
	uint8_t  peer_rpa[BDADDR_SIZE];
	uint8_t  local_rpa[BDADDR_SIZE];
#endif /* CONFIG_BT_CTLR_PRIVACY */
	uint16_t interval;
	uint16_t latency;
	uint16_t timeout;
	uint8_t  sca;
};

struct node_rx_cu {
	uint8_t  status;
	uint16_t interval;
	uint16_t latency;
	uint16_t timeout;
};

struct node_rx_cs {
	uint8_t csa;
};

struct node_rx_pu {
	uint8_t status;
	uint8_t tx;
	uint8_t rx;
};