Lines Matching +full:rx +full:- +full:extra +full:- +full:mode
4 * SPDX-License-Identifier: Apache-2.0
62 struct bt_mesh_net_rx *rx; member
128 val = sys_get_be32(tail - 4) ^ sys_get_be32(tail - 8); in check_dup()
131 if (dup_cache[--i] == val) { in check_dup()
137 if (dup_cache[--i] == val) { in check_dup()
153 if (msg_cache[--i].src == SRC(pdu->data) && in msg_cache_match()
154 msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17))) { in msg_cache_match()
160 if (msg_cache[--i].src == SRC(pdu->data) && in msg_cache_match()
161 msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17))) { in msg_cache_match()
169 static void msg_cache_add(struct bt_mesh_net_rx *rx) in msg_cache_add() argument
172 msg_cache[msg_cache_next].src = rx->ctx.addr; in msg_cache_add()
173 msg_cache[msg_cache_next].seq = rx->seq; in msg_cache_add()
252 /* Reset the duration variable - needed for some PTS tests */ in bt_mesh_iv_update_test()
282 /* Discard [iv, false] --> [iv, true] */ in bt_mesh_net_iv_update()
345 LOG_DBG("Normal mode entered"); in bt_mesh_net_iv_update()
404 struct bt_mesh_net_rx rx = { in bt_mesh_net_local() local
406 .net_idx = buf->sub->net_idx, in bt_mesh_net_local()
409 .recv_ttl = TTL(buf->data), in bt_mesh_net_local()
412 .addr = SRC(buf->data), in bt_mesh_net_local()
413 .recv_dst = DST(buf->data), in bt_mesh_net_local()
417 .sub = buf->sub, in bt_mesh_net_local()
418 .old_iv = (IVI(buf->data) != (bt_mesh.iv_index & 0x01)), in bt_mesh_net_local()
419 .ctl = CTL(buf->data), in bt_mesh_net_local()
420 .seq = SEQ(buf->data), in bt_mesh_net_local()
421 .new_key = SUBNET_KEY_TX_IDX(buf->sub), in bt_mesh_net_local()
426 LOG_DBG("src: 0x%04x dst: 0x%04x seq 0x%06x sub %p", rx.ctx.addr, rx.ctx.addr, in bt_mesh_net_local()
427 rx.seq, buf->sub); in bt_mesh_net_local()
429 net_buf_simple_init_with_data(&sbuf, buf->data, buf->len); in bt_mesh_net_local()
430 (void)bt_mesh_trans_recv(&sbuf, &rx); in bt_mesh_net_local()
438 if (tx->friend_cred && bt_mesh.lpn.frnd) { in net_tx_cred_get()
439 return &bt_mesh.lpn.cred[SUBNET_KEY_TX_IDX(tx->sub)]; in net_tx_cred_get()
443 tx->friend_cred = 0U; in net_tx_cred_get()
444 return &tx->sub->keys[SUBNET_KEY_TX_IDX(tx->sub)].msg; in net_tx_cred_get()
450 const bool ctl = (tx->ctx->app_idx == BT_MESH_KEY_UNUSED); in net_header_encode()
454 return -EINVAL; in net_header_encode()
457 return -EINVAL; in net_header_encode()
460 LOG_DBG("src 0x%04x dst 0x%04x ctl %u seq 0x%06x", tx->src, tx->ctx->addr, ctl, in net_header_encode()
463 net_buf_simple_push_be16(buf, tx->ctx->addr); in net_header_encode()
464 net_buf_simple_push_be16(buf, tx->src); in net_header_encode()
468 net_buf_simple_push_u8(buf, tx->ctx->send_ttl | 0x80); in net_header_encode()
470 net_buf_simple_push_u8(buf, tx->ctx->send_ttl); in net_header_encode()
484 err = bt_mesh_net_encrypt(&cred->enc, buf, iv_index, proxy); in net_encrypt()
489 return bt_mesh_net_obfuscate(buf->data, iv_index, &cred->privacy); in net_encrypt()
499 err = net_header_encode(tx, cred->nid, buf); in bt_mesh_net_encode()
516 return -ENOMEM; in net_loopback()
519 buf->sub = tx->sub; in net_loopback()
521 (void)memcpy(buf->data, data, len); in net_loopback()
522 buf->len = len; in net_loopback()
524 sys_slist_append(&bt_mesh.local_queue, &buf->node); in net_loopback()
537 LOG_DBG("src 0x%04x dst 0x%04x len %u headroom %zu tailroom %zu", tx->src, tx->ctx->addr, in bt_mesh_net_send()
538 adv->b.len, net_buf_simple_headroom(&adv->b), net_buf_simple_tailroom(&adv->b)); in bt_mesh_net_send()
539 LOG_DBG("Payload len %u: %s", adv->b.len, bt_hex(adv->b.data, adv->b.len)); in bt_mesh_net_send()
543 err = net_header_encode(tx, cred->nid, &adv->b); in bt_mesh_net_send()
549 if (bt_mesh_fixed_group_match(tx->ctx->addr) || in bt_mesh_net_send()
550 bt_mesh_has_addr(tx->ctx->addr)) { in bt_mesh_net_send()
551 err = net_loopback(tx, adv->b.data, adv->b.len); in bt_mesh_net_send()
554 if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr) || in bt_mesh_net_send()
555 tx->ctx->send_ttl == 1U) { in bt_mesh_net_send()
569 if (tx->ctx->send_ttl == 1U) { in bt_mesh_net_send()
570 err = -EINVAL; in bt_mesh_net_send()
574 err = net_encrypt(&adv->b, cred, BT_MESH_NET_IVI_TX, BT_MESH_NONCE_NETWORK); in bt_mesh_net_send()
579 adv->ctx.cb = cb; in bt_mesh_net_send()
580 adv->ctx.cb_data = cb_data; in bt_mesh_net_send()
584 (void)bt_mesh_proxy_relay(adv, tx->ctx->addr); in bt_mesh_net_send()
611 if (net_idx == BT_MESH_KEY_ANY || net_idx == buf->sub->net_idx) { in bt_mesh_net_loopback_clear()
612 LOG_DBG("Dropped 0x%06x", SEQ(buf->data)); in bt_mesh_net_loopback_clear()
615 sys_slist_append(&new_list, &buf->node); in bt_mesh_net_loopback_clear()
622 static bool net_decrypt(struct bt_mesh_net_rx *rx, struct net_buf_simple *in, in net_decrypt() argument
626 bool proxy = (rx->net_if == BT_MESH_NET_IF_PROXY_CFG); in net_decrypt()
628 if (NID(in->data) != cred->nid) { in net_decrypt()
632 LOG_DBG("NID 0x%02x", NID(in->data)); in net_decrypt()
633 LOG_DBG("IVI %u net->iv_index 0x%08x", IVI(in->data), bt_mesh.iv_index); in net_decrypt()
635 rx->old_iv = (IVI(in->data) != (bt_mesh.iv_index & 0x01)); in net_decrypt()
638 net_buf_simple_add_mem(out, in->data, in->len); in net_decrypt()
640 if (bt_mesh_net_obfuscate(out->data, BT_MESH_NET_IVI_RX(rx), in net_decrypt()
641 &cred->privacy)) { in net_decrypt()
645 rx->ctx.addr = SRC(out->data); in net_decrypt()
646 if (!BT_MESH_ADDR_IS_UNICAST(rx->ctx.addr)) { in net_decrypt()
647 LOG_DBG("Ignoring non-unicast src addr 0x%04x", rx->ctx.addr); in net_decrypt()
651 if (bt_mesh_has_addr(rx->ctx.addr)) { in net_decrypt()
656 if (rx->net_if == BT_MESH_NET_IF_ADV && msg_cache_match(out)) { in net_decrypt()
661 LOG_DBG("src 0x%04x", rx->ctx.addr); in net_decrypt()
663 return bt_mesh_net_decrypt(&cred->enc, out, BT_MESH_NET_IVI_RX(rx), in net_decrypt()
685 static void bt_mesh_net_relay(struct net_buf_simple *sbuf, struct bt_mesh_net_rx *rx, bool bridge) in bt_mesh_net_relay() argument
691 if (rx->ctx.recv_ttl <= 1U) { in bt_mesh_net_relay()
695 if (rx->net_if == BT_MESH_NET_IF_ADV && !rx->friend_cred && !bridge && in bt_mesh_net_relay()
702 LOG_DBG("TTL %u CTL %u dst 0x%04x", rx->ctx.recv_ttl, rx->ctl, rx->ctx.recv_dst); in bt_mesh_net_relay()
704 /* The Relay Retransmit state is only applied to adv-adv relaying. in bt_mesh_net_relay()
708 if (rx->net_if == BT_MESH_NET_IF_ADV && !rx->friend_cred && !bridge) { in bt_mesh_net_relay()
722 sbuf->data[1] &= 0x80; in bt_mesh_net_relay()
723 sbuf->data[1] |= rx->ctx.recv_ttl - 1U; in bt_mesh_net_relay()
725 net_buf_simple_add_mem(&adv->b, sbuf->data, sbuf->len); in bt_mesh_net_relay()
727 cred = &rx->sub->keys[SUBNET_KEY_TX_IDX(rx->sub)].msg; in bt_mesh_net_relay()
729 LOG_DBG("Relaying packet. TTL is now %u", TTL(adv->b.data)); in bt_mesh_net_relay()
731 /* Update NID if RX, RX was with friend credentials or when bridging the message */ in bt_mesh_net_relay()
732 if (rx->friend_cred || bridge) { in bt_mesh_net_relay()
733 adv->b.data[0] &= 0x80; /* Clear everything except IVI */ in bt_mesh_net_relay()
734 adv->b.data[0] |= cred->nid; in bt_mesh_net_relay()
737 /* We re-encrypt and obfuscate using the received IVI rather than in bt_mesh_net_relay()
741 if (net_encrypt(&adv->b, cred, BT_MESH_NET_IVI_RX(rx), BT_MESH_NONCE_NETWORK)) { in bt_mesh_net_relay()
742 LOG_ERR("Re-encrypting failed"); in bt_mesh_net_relay()
751 (rx->friend_cred || in bt_mesh_net_relay()
754 bt_mesh_proxy_relay(adv, rx->ctx.recv_dst); in bt_mesh_net_relay()
757 if (relay_to_adv(rx->net_if) || rx->friend_cred || bridge) { in bt_mesh_net_relay()
770 return sub->net_idx == *net_idx; in find_subnet_cb()
785 ctx->rx->sub = subnet; in bt_mesh_sbr_check_cb()
786 ctx->rx->ctx.net_idx = new_net_idx; in bt_mesh_sbr_check_cb()
788 net_buf_simple_restore(ctx->sbuf, ctx->state); in bt_mesh_sbr_check_cb()
789 bt_mesh_net_relay(ctx->sbuf, ctx->rx, true); in bt_mesh_sbr_check_cb()
795 struct bt_mesh_net_rx *rx) in bt_mesh_net_header_parse() argument
797 rx->old_iv = (IVI(buf->data) != (bt_mesh.iv_index & 0x01)); in bt_mesh_net_header_parse()
798 rx->ctl = CTL(buf->data); in bt_mesh_net_header_parse()
799 rx->ctx.recv_ttl = TTL(buf->data); in bt_mesh_net_header_parse()
800 rx->seq = SEQ(buf->data); in bt_mesh_net_header_parse()
801 rx->ctx.addr = SRC(buf->data); in bt_mesh_net_header_parse()
802 rx->ctx.recv_dst = DST(buf->data); in bt_mesh_net_header_parse()
806 struct bt_mesh_net_rx *rx, struct net_buf_simple *out) in bt_mesh_net_decode() argument
808 if (in->len < BT_MESH_NET_MIN_PDU_LEN) { in bt_mesh_net_decode()
809 LOG_WRN("Dropping too short mesh packet (len %u)", in->len); in bt_mesh_net_decode()
810 LOG_WRN("%s", bt_hex(in->data, in->len)); in bt_mesh_net_decode()
811 return -EINVAL; in bt_mesh_net_decode()
814 if (in->len > BT_MESH_NET_MAX_PDU_LEN) { in bt_mesh_net_decode()
815 LOG_WRN("Dropping too long mesh packet (len %u)", in->len); in bt_mesh_net_decode()
816 return -EINVAL; in bt_mesh_net_decode()
820 return -EINVAL; in bt_mesh_net_decode()
823 LOG_DBG("%u bytes: %s", in->len, bt_hex(in->data, in->len)); in bt_mesh_net_decode()
825 rx->net_if = net_if; in bt_mesh_net_decode()
827 if (!bt_mesh_net_cred_find(rx, in, out, net_decrypt)) { in bt_mesh_net_decode()
829 return -ENOENT; in bt_mesh_net_decode()
833 rx->ctx.app_idx = BT_MESH_KEY_UNUSED; in bt_mesh_net_decode()
835 rx->ctx.recv_ttl = TTL(out->data); in bt_mesh_net_decode()
837 /* Default to responding with TTL 0 for non-routed messages */ in bt_mesh_net_decode()
838 if (rx->ctx.recv_ttl == 0U) { in bt_mesh_net_decode()
839 rx->ctx.send_ttl = 0U; in bt_mesh_net_decode()
841 rx->ctx.send_ttl = BT_MESH_TTL_DEFAULT; in bt_mesh_net_decode()
844 rx->ctl = CTL(out->data); in bt_mesh_net_decode()
845 rx->seq = SEQ(out->data); in bt_mesh_net_decode()
846 rx->ctx.recv_dst = DST(out->data); in bt_mesh_net_decode()
848 LOG_DBG("Decryption successful. Payload len %u", out->len); in bt_mesh_net_decode()
851 rx->ctx.recv_dst == BT_MESH_ADDR_UNASSIGNED) { in bt_mesh_net_decode()
853 return -EBADMSG; in bt_mesh_net_decode()
856 LOG_DBG("src 0x%04x dst 0x%04x ttl %u", rx->ctx.addr, rx->ctx.recv_dst, rx->ctx.recv_ttl); in bt_mesh_net_decode()
857 LOG_DBG("PDU: %s", bt_hex(out->data, out->len)); in bt_mesh_net_decode()
859 msg_cache_add(rx); in bt_mesh_net_decode()
868 struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi }; in bt_mesh_net_recv() local
878 if (bt_mesh_net_decode(data, net_if, &rx, &buf)) { in bt_mesh_net_recv()
889 rx.local_match = (bt_mesh_fixed_group_match(rx.ctx.recv_dst) || in bt_mesh_net_recv()
890 bt_mesh_has_addr(rx.ctx.recv_dst)); in bt_mesh_net_recv()
894 bt_mesh_proxy_addr_add(data, rx.ctx.addr); in bt_mesh_net_recv()
898 !rx.local_match) { in bt_mesh_net_recv()
904 err = bt_mesh_trans_recv(&buf, &rx); in bt_mesh_net_recv()
905 if (err == -EAGAIN) { in bt_mesh_net_recv()
909 * Low Power mode, but the message was not encrypted with the friend in bt_mesh_net_recv()
915 msg_cache[--msg_cache_next].src = BT_MESH_ADDR_UNASSIGNED; in bt_mesh_net_recv()
916 dup_cache[--dup_cache_next] = 0; in bt_mesh_net_recv()
918 } else if (err == -EBADMSG) { in bt_mesh_net_recv()
926 if (!BT_MESH_ADDR_IS_UNICAST(rx.ctx.recv_dst) || in bt_mesh_net_recv()
927 (!rx.local_match && !rx.friend_match)) { in bt_mesh_net_recv()
929 bt_mesh_net_relay(&buf, &rx, false); in bt_mesh_net_recv()
936 .rx = &rx, in bt_mesh_net_recv()
944 if (bt_mesh_rpl_check(&rx, NULL, true)) { in bt_mesh_net_recv()
948 bt_mesh_brg_cfg_tbl_foreach_subnet(rx.ctx.addr, rx.ctx.recv_dst, rx.ctx.net_idx, in bt_mesh_net_recv()
964 : "IVU Normal mode", in ivu_refresh()
1023 /* One extra copying since net.dev_key is from packed structure in net_set()
1097 bt_mesh.seq += (CONFIG_BT_MESH_SEQ_STORE_RATE - in seq_set()
1099 bt_mesh.seq--; in seq_set()
1115 return -EINVAL; in dev_key_cand_set()