Skip to content

Commit 3b84e03

Browse files
andrzej-kaczmarekcvinayak
authored andcommitted
Bluetooth: controller: Remove adv_sync_hdr_set_clear
adv_sync_hdr_set_clear was just wrapped by ull_adv_sync_pdu_set_clear so we can merge both into single function. Signed-off-by: Andrzej Kaczmarek <[email protected]>
1 parent 541c79b commit 3b84e03

File tree

1 file changed

+118
-155
lines changed

1 file changed

+118
-155
lines changed

subsys/bluetooth/controller/ll_sw/ull_adv_sync.c

Lines changed: 118 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ static inline uint16_t sync_handle_get(struct ll_adv_sync_set *sync);
5050
static inline uint8_t sync_remove(struct ll_adv_sync_set *sync,
5151
struct ll_adv_set *adv, uint8_t enable);
5252

53-
static uint8_t adv_sync_hdr_set_clear(struct lll_adv_sync *lll_sync,
54-
struct pdu_adv *ter_pdu_prev,
55-
struct pdu_adv *ter_pdu,
56-
uint16_t hdr_add_fields,
57-
uint16_t hdr_rem_fields,
58-
void *data);
59-
6053
static void mfy_sync_offset_get(void *param);
6154
static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu);
6255
static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si,
@@ -829,154 +822,6 @@ uint8_t ull_adv_sync_pdu_set_clear(struct lll_adv_sync *lll_sync,
829822
uint16_t hdr_add_fields,
830823
uint16_t hdr_rem_fields,
831824
struct adv_pdu_field_data *data)
832-
{
833-
int err;
834-
835-
err = adv_sync_hdr_set_clear(lll_sync, ter_pdu_prev, ter_pdu,
836-
hdr_add_fields, hdr_rem_fields,
837-
(data ? data->field_data : NULL));
838-
839-
return err;
840-
}
841-
842-
#if defined(CONFIG_BT_CTLR_DF_ADV_CTE_TX)
843-
/* @brief Set or clear fields in extended advertising header and store
844-
* extra_data if requested.
845-
*
846-
* @param[in] extra_data_prev Pointer to previous content of extra_data.
847-
* @param[in] hdr_add_fields Flag with information which fields add.
848-
* @param[in] hdr_rem_fields Flag with information which fields remove.
849-
* @param[in] data Pointer to data to be stored in extra_data.
850-
* Content depends on the data depends on
851-
* @p hdr_add_fields.
852-
*
853-
* @Note
854-
* @p data depends on the flag provided by @p hdr_add_fields.
855-
* Information about content of value may be found in description of
856-
* @ref ull_adv_sync_pdu_set_clear.
857-
*
858-
* @return Zero in case of success, other value in case of failure.
859-
*/
860-
void ull_adv_sync_extra_data_set_clear(void *extra_data_prev,
861-
void *extra_data_new,
862-
uint16_t hdr_add_fields,
863-
uint16_t hdr_rem_fields,
864-
void *data)
865-
{
866-
/* Currently only CTE enable requires extra_data. Due to that fact
867-
* CTE additional data are just copied to extra_data memory.
868-
*/
869-
if (hdr_add_fields & ULL_ADV_PDU_HDR_FIELD_CTE_INFO) {
870-
memcpy(extra_data_new, data, sizeof(struct lll_df_adv_cfg));
871-
} else if (!(hdr_rem_fields & ULL_ADV_PDU_HDR_FIELD_CTE_INFO) ||
872-
extra_data_prev) {
873-
memmove(extra_data_new, extra_data_prev,
874-
sizeof(struct lll_df_adv_cfg));
875-
}
876-
}
877-
#endif /* CONFIG_BT_CTLR_DF_ADV_CTE_TX */
878-
879-
static int init_reset(void)
880-
{
881-
/* Initialize adv sync pool. */
882-
mem_init(ll_adv_sync_pool, sizeof(struct ll_adv_sync_set),
883-
sizeof(ll_adv_sync_pool) / sizeof(struct ll_adv_sync_set),
884-
&adv_sync_free);
885-
886-
return 0;
887-
}
888-
889-
static inline struct ll_adv_sync_set *sync_acquire(void)
890-
{
891-
return mem_acquire(&adv_sync_free);
892-
}
893-
894-
static inline void sync_release(struct ll_adv_sync_set *sync)
895-
{
896-
mem_release(sync, &adv_sync_free);
897-
}
898-
899-
static inline uint16_t sync_handle_get(struct ll_adv_sync_set *sync)
900-
{
901-
return mem_index_get(sync, ll_adv_sync_pool,
902-
sizeof(struct ll_adv_sync_set));
903-
}
904-
905-
static uint8_t sync_stop(struct ll_adv_sync_set *sync)
906-
{
907-
uint8_t sync_handle;
908-
int err;
909-
910-
sync_handle = sync_handle_get(sync);
911-
912-
err = ull_ticker_stop_with_mark(TICKER_ID_ADV_SYNC_BASE + sync_handle,
913-
sync, &sync->lll);
914-
LL_ASSERT(err == 0 || err == -EALREADY);
915-
if (err) {
916-
return BT_HCI_ERR_CMD_DISALLOWED;
917-
}
918-
919-
return 0;
920-
}
921-
922-
static inline uint8_t sync_remove(struct ll_adv_sync_set *sync,
923-
struct ll_adv_set *adv, uint8_t enable)
924-
{
925-
uint8_t pri_idx;
926-
uint8_t err;
927-
928-
/* Remove sync_info from auxiliary PDU */
929-
err = ull_adv_aux_hdr_set_clear(adv, 0,
930-
ULL_ADV_PDU_HDR_FIELD_SYNC_INFO,
931-
NULL, NULL, &pri_idx);
932-
if (err) {
933-
return err;
934-
}
935-
936-
lll_adv_data_enqueue(&adv->lll, pri_idx);
937-
938-
if (sync->is_started) {
939-
/* TODO: we removed sync info, but if sync_stop() fails, what do
940-
* we do?
941-
*/
942-
err = sync_stop(sync);
943-
if (err) {
944-
return err;
945-
}
946-
947-
sync->is_started = 0U;
948-
}
949-
950-
if (!enable) {
951-
sync->is_enabled = 0U;
952-
}
953-
954-
return 0U;
955-
}
956-
957-
/* @brief Set or clear fields in extended advertising header.
958-
*
959-
* @param[in] adv Advertising set.
960-
* @param[in] hdr_add_fields Flag with information which fields add.
961-
* @param[in] hdr_rem_fields Flag with information which fields remove.
962-
* @param[in] value Pointer to data to be added to header.
963-
* Content depends on the value of
964-
* @p hdr_add_fields.
965-
* @param[out] ter_idx Index of new PDU.
966-
*
967-
* @Note
968-
* @p value depends on the flag provided by @p hdr_add_fields.
969-
* Information about content of value may be found in description of
970-
* @ref ull_adv_sync_pdu_set_clear.
971-
*
972-
* @return Zero in case of success, other value in case of failure.
973-
*/
974-
static uint8_t adv_sync_hdr_set_clear(struct lll_adv_sync *lll_sync,
975-
struct pdu_adv *ter_pdu_prev,
976-
struct pdu_adv *ter_pdu,
977-
uint16_t hdr_add_fields,
978-
uint16_t hdr_rem_fields,
979-
void *value)
980825
{
981826
struct pdu_adv_com_ext_adv *ter_com_hdr, *ter_com_hdr_prev;
982827
struct pdu_adv_ext_hdr *ter_hdr, ter_hdr_prev;
@@ -990,6 +835,9 @@ static uint8_t adv_sync_hdr_set_clear(struct lll_adv_sync *lll_sync,
990835
uint8_t cte_info;
991836
#endif /* CONFIG_BT_CTLR_DF_ADV_CTE_TX */
992837
uint8_t ad_len;
838+
void *value;
839+
840+
value = data ? data->field_data : NULL;
993841

994842
/* Get common pointers from reference to previous tertiary PDU data */
995843
ter_com_hdr_prev = (void *)&ter_pdu_prev->adv_ext_ind;
@@ -1175,6 +1023,121 @@ static uint8_t adv_sync_hdr_set_clear(struct lll_adv_sync *lll_sync,
11751023
return 0;
11761024
}
11771025

1026+
#if defined(CONFIG_BT_CTLR_DF_ADV_CTE_TX)
1027+
/* @brief Set or clear fields in extended advertising header and store
1028+
* extra_data if requested.
1029+
*
1030+
* @param[in] extra_data_prev Pointer to previous content of extra_data.
1031+
* @param[in] hdr_add_fields Flag with information which fields add.
1032+
* @param[in] hdr_rem_fields Flag with information which fields remove.
1033+
* @param[in] data Pointer to data to be stored in extra_data.
1034+
* Content depends on the data depends on
1035+
* @p hdr_add_fields.
1036+
*
1037+
* @Note
1038+
* @p data depends on the flag provided by @p hdr_add_fields.
1039+
* Information about content of value may be found in description of
1040+
* @ref ull_adv_sync_pdu_set_clear.
1041+
*
1042+
* @return Zero in case of success, other value in case of failure.
1043+
*/
1044+
void ull_adv_sync_extra_data_set_clear(void *extra_data_prev,
1045+
void *extra_data_new,
1046+
uint16_t hdr_add_fields,
1047+
uint16_t hdr_rem_fields,
1048+
void *data)
1049+
{
1050+
/* Currently only CTE enable requires extra_data. Due to that fact
1051+
* CTE additional data are just copied to extra_data memory.
1052+
*/
1053+
if (hdr_add_fields & ULL_ADV_PDU_HDR_FIELD_CTE_INFO) {
1054+
memcpy(extra_data_new, data, sizeof(struct lll_df_adv_cfg));
1055+
} else if (!(hdr_rem_fields & ULL_ADV_PDU_HDR_FIELD_CTE_INFO) ||
1056+
extra_data_prev) {
1057+
memmove(extra_data_new, extra_data_prev,
1058+
sizeof(struct lll_df_adv_cfg));
1059+
}
1060+
}
1061+
#endif /* CONFIG_BT_CTLR_DF_ADV_CTE_TX */
1062+
1063+
static int init_reset(void)
1064+
{
1065+
/* Initialize adv sync pool. */
1066+
mem_init(ll_adv_sync_pool, sizeof(struct ll_adv_sync_set),
1067+
sizeof(ll_adv_sync_pool) / sizeof(struct ll_adv_sync_set),
1068+
&adv_sync_free);
1069+
1070+
return 0;
1071+
}
1072+
1073+
static inline struct ll_adv_sync_set *sync_acquire(void)
1074+
{
1075+
return mem_acquire(&adv_sync_free);
1076+
}
1077+
1078+
static inline void sync_release(struct ll_adv_sync_set *sync)
1079+
{
1080+
mem_release(sync, &adv_sync_free);
1081+
}
1082+
1083+
static inline uint16_t sync_handle_get(struct ll_adv_sync_set *sync)
1084+
{
1085+
return mem_index_get(sync, ll_adv_sync_pool,
1086+
sizeof(struct ll_adv_sync_set));
1087+
}
1088+
1089+
static uint8_t sync_stop(struct ll_adv_sync_set *sync)
1090+
{
1091+
uint8_t sync_handle;
1092+
int err;
1093+
1094+
sync_handle = sync_handle_get(sync);
1095+
1096+
err = ull_ticker_stop_with_mark(TICKER_ID_ADV_SYNC_BASE + sync_handle,
1097+
sync, &sync->lll);
1098+
LL_ASSERT(err == 0 || err == -EALREADY);
1099+
if (err) {
1100+
return BT_HCI_ERR_CMD_DISALLOWED;
1101+
}
1102+
1103+
return 0;
1104+
}
1105+
1106+
static inline uint8_t sync_remove(struct ll_adv_sync_set *sync,
1107+
struct ll_adv_set *adv, uint8_t enable)
1108+
{
1109+
uint8_t pri_idx;
1110+
uint8_t err;
1111+
1112+
/* Remove sync_info from auxiliary PDU */
1113+
err = ull_adv_aux_hdr_set_clear(adv, 0,
1114+
ULL_ADV_PDU_HDR_FIELD_SYNC_INFO,
1115+
NULL, NULL, &pri_idx);
1116+
if (err) {
1117+
return err;
1118+
}
1119+
1120+
lll_adv_data_enqueue(&adv->lll, pri_idx);
1121+
1122+
if (sync->is_started) {
1123+
/* TODO: we removed sync info, but if sync_stop() fails, what do
1124+
* we do?
1125+
*/
1126+
err = sync_stop(sync);
1127+
if (err) {
1128+
return err;
1129+
}
1130+
1131+
sync->is_started = 0U;
1132+
}
1133+
1134+
if (!enable) {
1135+
sync->is_enabled = 0U;
1136+
}
1137+
1138+
return 0U;
1139+
}
1140+
11781141
static void mfy_sync_offset_get(void *param)
11791142
{
11801143
struct ll_adv_set *adv = param;

0 commit comments

Comments
 (0)