in nimble/host/mesh/src/subnet.c [729:811]
bool bt_mesh_net_cred_find(struct bt_mesh_net_rx *rx, struct os_mbuf *in,
struct os_mbuf *out,
bool (*cb)(struct bt_mesh_net_rx *rx,
struct os_mbuf *in,
struct os_mbuf *out,
const struct bt_mesh_net_cred *cred))
{
int i, j;
BT_DBG("");
#if MYNEWT_VAL(BLE_MESH_LOW_POWER)
if (bt_mesh_lpn_waiting_update()) {
rx->sub = bt_mesh.lpn.sub;
for (j = 0; j < ARRAY_SIZE(bt_mesh.lpn.cred); j++) {
if (!rx->sub->keys[j].valid) {
continue;
}
if (cb(rx, in, out, &bt_mesh.lpn.cred[j])) {
rx->new_key = (j > 0);
rx->friend_cred = 1U;
rx->ctx.net_idx = rx->sub->net_idx;
return true;
}
}
/* LPN Should only receive on the friendship credentials when in
* a friendship.
*/
return false;
}
#endif
#if MYNEWT_VAL(BLE_MESH_FRIEND)
/** Each friendship has unique friendship credentials */
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
if (!frnd->subnet) {
continue;
}
rx->sub = frnd->subnet;
for (j = 0; j < ARRAY_SIZE(frnd->cred); j++) {
if (!rx->sub->keys[j].valid) {
continue;
}
if (cb(rx, in, out, &frnd->cred[j])) {
rx->new_key = (j > 0);
rx->friend_cred = 1U;
rx->ctx.net_idx = rx->sub->net_idx;
return true;
}
}
}
#endif
for (i = 0; i < ARRAY_SIZE(subnets); i++) {
rx->sub = &subnets[i];
if (rx->sub->net_idx == BT_MESH_KEY_UNUSED) {
continue;
}
for (j = 0; j < ARRAY_SIZE(rx->sub->keys); j++) {
if (!rx->sub->keys[j].valid) {
continue;
}
if (cb(rx, in, out, &rx->sub->keys[j].msg)) {
rx->new_key = (j > 0);
rx->friend_cred = 0U;
rx->ctx.net_idx = rx->sub->net_idx;
return true;
}
}
}
return false;
}