bluetooth: ble_scan: add manufacturer data filter support#783
bluetooth: ble_scan: add manufacturer data filter support#783PizzaAllTheWay wants to merge 3 commits intonrfconnect:mainfrom
Conversation
71e578f to
db6182f
Compare
|
You can find the documentation preview for this PR here. |
db6182f to
991a6e7
Compare
| * @p target_data_len bytes match @p target_data. | ||
| * @retval false No match, or the advertising data contains no manufacturer-specific data. | ||
| */ | ||
| bool ble_adv_data_manufacturer_data_find(const uint8_t *data, uint16_t data_len, |
There was a problem hiding this comment.
Let's align with the other _find functions. Use buf, len for encoded advertising data and length. Also align doxygen formatting (one space after variable etc.).
| return false; | ||
| } | ||
|
|
||
| if (target_data_len > parsed_len) { |
There was a problem hiding this comment.
We don't necessarily know the exact length, rather we should be able to tell the size of the buffer we have and return the amount of bytes copied.
There was a problem hiding this comment.
Can you elaborate? I don't quite follow what you're asking for here.
This function is a bool returning find, it doesn't copy anything, it just reports whether a match exists in the advertising data. Is it something about the existing target_data/target_data_len parameters that I'm missing?
| return false; | ||
| } | ||
|
|
||
| return memcmp(&data[data_offset], target_data, target_data_len) == 0; |
There was a problem hiding this comment.
Lets do the memcpy first then return true.
|
|
||
|
|
| TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); | ||
| } | ||
|
|
||
| static void encode_manufacturer_data_test_data(const uint8_t *payload, uint8_t payload_len) |
There was a problem hiding this comment.
encode_manufacturer_test_data is enough
| Maximum size of the short name to search for in the advertisement report. | ||
|
|
||
| config BLE_SCAN_MANUFACTURER_DATA_MAX_LEN | ||
| int "Maximum size for the manufacturer data to search in the advertisement report" |
There was a problem hiding this comment.
Align with Kconfigs above.
| Maximum number of filters for UUIDs. | ||
|
|
||
| config BLE_SCAN_MANUFACTURER_DATA_COUNT | ||
| int "Number of manufacturer data filters" |
There was a problem hiding this comment.
Align with other Kconfigs.
|
|
||
| test_ble_scan_init(); | ||
|
|
||
| nrf_err = ble_scan_filters_enable(&ble_scan, 0x20, true); |
There was a problem hiding this comment.
Put in the same commit as the changes to ble_scan!
|
|
||
| #define UUID 0x2312 | ||
|
|
||
| /* Nordic Semiconductor company identifier (Bluetooth SIG assigned). */ |
There was a problem hiding this comment.
Squash commit adding tests with ble_scan code changes.
| TEST_ASSERT_EQUAL(0, scan_event.filter_match.filter_match.short_name_filter_match); | ||
| TEST_ASSERT_EQUAL(0, scan_event.filter_match.filter_match.appearance_filter_match); | ||
| TEST_ASSERT_EQUAL(1, scan_event.filter_match.filter_match.uuid_filter_match); | ||
| TEST_ASSERT_EQUAL(0, scan_event.filter_match.filter_match.manufacturer_data_filter_match); |
There was a problem hiding this comment.
Add test case for manufacturer_data_filter_match equal to 1
There was a problem hiding this comment.
test_ble_scan_on_ble_evt_adv_report_device_manufacturer_data() already covers that case, it asserts scan_event.filter_match.filter_match.manufacturer_data_filter_match == 1 on a successful match.
Did you mean an additional test, like a combined filter case (similar to test_ble_scan_on_ble_evt_adv_report_device_name_and_appearance()) where manufacturer data matches together with another filter? Could you elaborate?
There was a problem hiding this comment.
Ok, I assume you meant an extra case with multiple manufacturer data filters, so I added test_ble_scan_on_ble_evt_adv_report_device_multiple_manufacturer_data() (two manuf filters registered). Also bumped CONFIG_BLE_SCAN_MANUFACTURER_DATA_COUNT to 2 and updated test_ble_scan_filter_add_manufacturer_data_error_no_mem() accordingly. Let me know if that's what you had in mind.
991a6e7 to
4dcd5d0
Compare
| * Added: | ||
|
|
||
| * The :c:func:`ble_adv_data_manufacturer_data_find` function to locate manufacturer-specific data in an advertising payload and prefix-match it against a target value. |
There was a problem hiding this comment.
| * Added: | |
| * The :c:func:`ble_adv_data_manufacturer_data_find` function to locate manufacturer-specific data in an advertising payload and prefix-match it against a target value. | |
| * Added the :c:func:`ble_adv_data_manufacturer_data_find` function to locate manufacturer-specific data in an advertising payload and prefix-match it against a target value. |
| * Added: | ||
|
|
||
| * The :c:struct:`ble_scan_filter_data` structure as input to the :c:func:`ble_scan_filter_add` function. | ||
| * Support for filtering by manufacturer-specific data via the :c:macro:`BLE_SCAN_MANUFACTURER_DATA_FILTER` filter type. |
There was a problem hiding this comment.
| * Support for filtering by manufacturer-specific data via the :c:macro:`BLE_SCAN_MANUFACTURER_DATA_FILTER` filter type. | |
| * Support for filtering by manufacturer-specific data using the :c:macro:`BLE_SCAN_MANUFACTURER_DATA_FILTER` filter type. |
| * vendor payload. | ||
| * @param[in] target_data_len Length of the target manufacturer data. | ||
| * | ||
| * @retval true If manufacturer-specific data whose first @p target_data_len bytes match |
There was a problem hiding this comment.
| * @retval true If manufacturer-specific data whose first @p target_data_len bytes match | |
| * @retval true If manufacturer-specific data in which the first @p target_data_len bytes matches |
Add ble_adv_data_manufacturer_data_find() to locate manufacturer-specific data in an advertising payload and prefix-match it against a target value. Follows the pattern of existing _find helpers for name, uuid and appearance. Modified unit tests to align with changes. Added changelog. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
Expand the comment around the match_all cache logic to explain the on-air ADV → SCAN_REQ → SCAN_RSP exchange and why the paired SCAN_RSP is guaranteed to arrive before an ADV from another device. Also clarify the purpose of the buffer swap. No functional changes. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
4dcd5d0 to
e3f6b95
Compare
Port the manufacturer data scan filter from NCS to Bare Metal. Adds BLE_SCAN_MANUFACTURER_DATA_FILTER type, manufacturer_data_filter_match flag in ble_scan_filter_match, and plumbing through ble_scan_filter_add, ble_scan_filters_enable, ble_scan_filters_disable, ble_scan_all_filter_remove and the adv report event handler. New Kconfig options: - CONFIG_BLE_SCAN_MANUFACTURER_DATA_COUNT - CONFIG_BLE_SCAN_MANUFACTURER_DATA_MAX_LEN Modified unit tests to align with changes. Added changelog. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
e3f6b95 to
356109f
Compare
Port the manufacturer data scan filter from NCS to Bare Metal.
ble_adv_data: newble_adv_data_manufacturer_data_find()helper.ble_scan: newBLE_SCAN_MANUFACTURER_DATA_FILTERfilter type withCONFIG_BLE_SCAN_MANUFACTURER_DATA_COUNTandCONFIG_BLE_SCAN_MANUFACTURER_DATA_MAX_LENKconfig options. Wired through filter add/enable/disable/remove and the adv report handler.Unit tests added for the new find helper, filter-add paths and event handler, plus regression guards in existing tests.
Changelog entries added under
lib_ble_advandlib_ble_scan.Clarified the comment around the
match_allADV/SCAN_RSP cache logic.Feature verified end-to-end using locally modified
ble_hrsandble_hrs_centralsamples (peripheral advertising Nordic company ID0x0059and central configured with a manufacturer data filter). Sample changes are not included in this PR.