Bluetooth: Controller: Add Periodic Advertising ADI support

Add implementation to add ADI in Periodic Advertising PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig
index 4a75113..0683097 100644
--- a/subsys/bluetooth/controller/Kconfig
+++ b/subsys/bluetooth/controller/Kconfig
@@ -503,6 +503,13 @@
 	bool "LE Periodic Advertising in Advertising State [EXPERIMENTAL]" if BT_LL_SW_SPLIT
 	select EXPERIMENTAL if BT_LL_SW_SPLIT
 
+config BT_CTLR_ADV_PERIODIC_ADI_SUPPORT
+	bool "Periodic Advertising ADI support"
+	depends on BT_CTLR_ADV_PERIODIC
+	default y
+	help
+	  Enable support for adding AdvDataInfo in Periodic Advertising PDUs.
+
 config BT_CTLR_SYNC_PERIODIC
 	bool "LE Periodic Advertising in Synchronization State" if !BT_LL_SW_SPLIT
 	depends on BT_OBSERVER && BT_CTLR_SYNC_PERIODIC_SUPPORT
diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c
index 7128ee0..29174a5 100644
--- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c
+++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c
@@ -1089,7 +1089,13 @@
 	}
 #endif /* CONFIG_BT_CTLR_DF_ADV_CTE_TX */
 
-	/* No ADI in AUX_SYNC_IND */
+	if (IS_ENABLED(CONFIG_BT_CTLR_ADV_PERIODIC_ADI_SUPPORT)) {
+		if (ter_hdr_prev.adi) {
+			ter_dptr_prev += sizeof(struct pdu_adv_adi);
+		}
+		ter_hdr.adi = 1U;
+		ter_dptr += sizeof(struct pdu_adv_adi);
+	}
 
 	/* AuxPtr - will be added if AUX_CHAIN_IND is required */
 	if ((hdr_add_fields & ULL_ADV_PDU_HDR_FIELD_AUX_PTR) ||
@@ -1233,7 +1239,27 @@
 		}
 	}
 
-	/* No ADI in AUX_SYNC_IND*/
+	if (IS_ENABLED(CONFIG_BT_CTLR_ADV_PERIODIC_ADI_SUPPORT)) {
+		struct pdu_adv_adi *adi;
+		struct ll_adv_set *adv;
+		uint16_t did;
+
+		if (ter_hdr_prev.adi) {
+			ter_dptr_prev -= sizeof(struct pdu_adv_adi);
+		}
+
+		ter_dptr -= sizeof(struct pdu_adv_adi);
+		adi = (void *)ter_dptr;
+
+		adv = HDR_LLL2ULL(lll_sync->adv);
+
+		adi->sid = adv->sid;
+
+		/* The DID for a specific SID shall be unique.
+		 */
+		did = ull_adv_aux_did_next_unique_get(adv->sid);
+		adi->did = sys_cpu_to_le16(did);
+	}
 
 #if defined(CONFIG_BT_CTLR_DF_ADV_CTE_TX)
 	if (ter_hdr.cte_info) {