Skip to content

Commit 8189693

Browse files
committed
Fix ScanEntry prefix matching for all
1 parent 9285252 commit 8189693

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

shared-module/_bleio/ScanEntry.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
5656
if (prefixes_length == 0) {
5757
return true;
5858
}
59+
if (len == 0) {
60+
// Prefixes exist, but no data.
61+
return false;
62+
}
5963
size_t i = 0;
6064
while(i < prefixes_length) {
6165
uint8_t prefix_length = prefixes[i];
6266
i += 1;
6367
size_t j = 0;
68+
bool prefix_matched = false;
69+
mp_printf(&mp_plat_print,"i %d\n", i); // XXX
6470
while (j < len) {
71+
mp_printf(&mp_plat_print," j %d\n", j); // XXX
6572
uint8_t structure_length = data[j];
6673
j += 1;
6774
if (structure_length == 0) {
@@ -71,13 +78,21 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
7178
if (any) {
7279
return true;
7380
}
74-
} else if (!any) {
75-
return false;
81+
prefix_matched = true;
82+
mp_printf(&mp_plat_print," match\n"); // XXX
83+
break;
7684
}
7785
j += structure_length;
7886
}
87+
// If all (!any), the current prefix must have matched at least one field.
88+
if (!prefix_matched && !any) {
89+
mp_printf(&mp_plat_print,"<prefix not matched\n"); // XXX
90+
return false;
91+
}
7992
i += prefix_length;
8093
}
94+
// All prefixes matched some field (if !any), or none did (if any).
95+
mp_printf(&mp_plat_print,"<all matched\n"); // XXX
8196
return !any;
8297
}
8398

0 commit comments

Comments
 (0)