Skip to content

Conversation

@cvinayak
Copy link
Contributor

Add Extended Advertising Type validation when associated
Periodic Advertising is enable, and Extended Advertising
set is re-configured to other advertising types.

Signed-off-by: Vinayak Kariappa Chettimada [email protected]

kruithofa
kruithofa previously approved these changes May 18, 2022
Comment on lines 284 to 296
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* high duty cycle directed */
if (evt_prop & BT_HCI_LE_ADV_PROP_HI_DC_CONN) {
adv_type = 0x01; /* PDU_ADV_TYPE_DIRECT_IND */
} else {
adv_type = leg_adv_type[evt_prop & 0x03];
}
/* high duty cycle directed */
if (evt_prop & BT_HCI_LE_ADV_PROP_HI_DC_CONN) {
adv_type = 0x01; /* Index of PDU_ADV_TYPE_DIRECT_IND in pdu_adv_type[] */
} else {
/* We take advantage of the fact that 2 LS bits of evt_prop can map to legacy advertising PDU types by using a look up */
adv_type = leg_adv_type[evt_prop & BIT_MASK(sizeof(leg_adv_type)];
}

0x03 is BIT_MASK(sizeof(leg_adv_type)) which is to restrict the index to the size of the lookup table.

Is the about comments and code suggestion acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that is actually making it more confusing to me. So adv_type is not an adv_type, but rather an index of a value in a local array that is unordered:

			uint8_t const leg_adv_type[] = {
				0x03, /* PDU_ADV_TYPE_NONCONN_IND */
				0x04, /* PDU_ADV_TYPE_DIRECT_IND */
				0x02, /* PDU_ADV_TYPE_SCAN_IND */
				0x00  /* PDU_ADV_TYPE_ADV_IND */
};

but only when evt_prop & BT_HCI_LE_ADV_PROP_HI_DC_CONN else it is a value in the array?

I think using the same variable as an index and as a value is hard to follow in terms of readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adv_type is an index into pdu_adv_type[]. leg_adv_type[] is second level of lookup from evt_prop value that gives an index into pdu_adv_type[]. Do suggest changes that can make it clearer to understand the level of lookup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is:

			uint8_t const leg_adv_type[] = {
				0x03, /* index of PDU_ADV_TYPE_NONCONN_IND in pdu_adv_type[] */
				0x04, /* index of PDU_ADV_TYPE_DIRECT_IND in pdu_adv_type[] */
				0x02, /* index of PDU_ADV_TYPE_SCAN_IND in pdu_adv_type[] */
				0x00  /* index of PDU_ADV_TYPE_ADV_IND in pdu_adv_type[] */
			};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That explains it. Would possibly also suggest to change adv_type to pdu_adv_type_index to make it very explicit that the variable is a index to the pdu_adv_type array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adv_type is the Advertising Type parameter name in HCI LE Set Advertising Parameters command that is used in the lookup pdu_adv_type[], will keep the name as-is.

Updated the PR will additional comments in code.

Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor request to make the array name explicit and a suggestion (can be postponed) to move the entire conversion to a separate function

Comment on lines 260 to 263
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
0x03, /* index of PDU_ADV_TYPE_NONCONN_IND */
0x04, /* index of PDU_ADV_TYPE_DIRECT_IND */
0x02, /* index of PDU_ADV_TYPE_SCAN_IND */
0x00 /* index of PDU_ADV_TYPE_ADV_IND */
0x03, /* index of PDU_ADV_TYPE_NONCONN_IND in pdu_adv_type[] */
0x04, /* index of PDU_ADV_TYPE_DIRECT_IND in pdu_adv_type[] */
0x02, /* index of PDU_ADV_TYPE_SCAN_IND in pdu_adv_type[] */
0x00 /* index of PDU_ADV_TYPE_ADV_IND in pdu_adv_type[] */

Comment on lines 285 to 295
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire lookup/conversion from evt_prop to adv type could also be moved into a separate function which could possibly also improve readability and understandability.

I guess since leg_adv_type is only used for adv_type = leg_adv_type[evt_prop & 0x03]; the entire array could be moved into the else { clause.

@cvinayak cvinayak force-pushed the github_ext_adv_type_check branch 2 times, most recently from 5273d5e to c025f28 Compare May 18, 2022 16:48
@cvinayak cvinayak requested a review from Thalley May 18, 2022 16:51
@cvinayak cvinayak force-pushed the github_ext_adv_type_check branch from c025f28 to e14ca6b Compare May 18, 2022 17:31
Add Extended Advertising Type validation when associated
Periodic Advertising is enable, and Extended Advertising
set is re-configured to other advertising types.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
@cvinayak cvinayak force-pushed the github_ext_adv_type_check branch from e14ca6b to 416789c Compare May 18, 2022 17:35
Copy link
Contributor

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still unclear why we are using the index of the pdu_adv_type array instead of the adv_type from the array itself, but I guess this is as good as it gets with the current way :)

@cvinayak
Copy link
Contributor Author

It is still unclear why we are using the index of the pdu_adv_type array instead of the adv_type from the array itself, but I guess this is as good as it gets with the current way :)

adv_type is the HCI parameter value and is not the advertising type value in PDUs hence the pdu_adv_type array lookup. This lookup is used in multiple places to check if advertising type of a set is being changed. Without the use of adv_type index, multiple places need to have conditional compile and runtime checks comparing extended vs legacy advertising.

@cvinayak cvinayak added this to the v3.1.0 milestone May 19, 2022
@cvinayak cvinayak changed the title Bluetooth: Controller: Add Extended Advertising Type Validations Bluetooth: Controller: Fix missing Extended Advertising Type Validations May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants