Use symbolic names rather than magic numbers. Remove unneeded extra pointer in send_seg(). --- mesh/mesh-defs.h | 9 +++++++++ mesh/mesh-io-generic.c | 3 ++- mesh/mesh-io-mgmt.c | 3 ++- mesh/mesh-io-unit.c | 4 +++- mesh/net-keys.c | 6 ++++-- mesh/net.c | 17 +++++++++-------- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h index 25ce0126c708..a12acaf59453 100644 --- a/mesh/mesh-defs.h +++ b/mesh/mesh-defs.h @@ -12,6 +12,15 @@ #define MESH_AD_TYPE_NETWORK 0x2A #define MESH_AD_TYPE_BEACON 0x2B +/* + * MshPRT_v1.1, section 3.3.1 / Core_v5.3, section 2.3.1.3 + * Maximum length of AdvData without 'Length' field (30) + */ +#define MESH_AD_MAX_LEN (BT_AD_MAX_DATA_LEN - 1) + +/* Max size of a Network PDU, prior prepending AD type (29)*/ +#define MESH_NET_MAX_PDU_LEN (MESH_AD_MAX_LEN - 1) + #define FEATURE_RELAY 1 #define FEATURE_PROXY 2 #define FEATURE_FRIEND 4 diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c index 1ec4f379def0..0875a359bd78 100644 --- a/mesh/mesh-io-generic.c +++ b/mesh/mesh-io-generic.c @@ -19,6 +19,7 @@ #include <ell/ell.h> #include "monitor/bt.h" +#include "src/shared/ad.h" #include "src/shared/hci.h" #include "src/shared/mgmt.h" #include "lib/bluetooth.h" @@ -52,7 +53,7 @@ struct tx_pkt { struct mesh_io_send_info info; bool delete; uint8_t len; - uint8_t pkt[30]; + uint8_t pkt[MESH_AD_MAX_LEN]; }; struct tx_pattern { diff --git a/mesh/mesh-io-mgmt.c b/mesh/mesh-io-mgmt.c index 4ca7ff93c863..065067fc2821 100644 --- a/mesh/mesh-io-mgmt.c +++ b/mesh/mesh-io-mgmt.c @@ -23,6 +23,7 @@ #include "lib/bluetooth.h" #include "lib/bluetooth.h" #include "lib/mgmt.h" +#include "src/shared/ad.h" #include "src/shared/mgmt.h" #include "mesh/mesh-defs.h" @@ -60,7 +61,7 @@ struct tx_pkt { struct mesh_io_send_info info; bool delete; uint8_t len; - uint8_t pkt[30]; + uint8_t pkt[MESH_AD_MAX_LEN]; }; struct tx_pattern { diff --git a/mesh/mesh-io-unit.c b/mesh/mesh-io-unit.c index 936f5a9514c5..f9a5aaa3e210 100644 --- a/mesh/mesh-io-unit.c +++ b/mesh/mesh-io-unit.c @@ -22,6 +22,8 @@ #include <time.h> #include <ell/ell.h> +#include "src/shared/ad.h" + #include "mesh/mesh-defs.h" #include "mesh/dbus.h" #include "mesh/mesh-io.h" @@ -59,7 +61,7 @@ struct tx_pkt { struct mesh_io_send_info info; bool delete; uint8_t len; - uint8_t pkt[30]; + uint8_t pkt[MESH_AD_MAX_LEN]; }; struct tx_pattern { diff --git a/mesh/net-keys.c b/mesh/net-keys.c index 22ab5b626a84..9b11bb7a1da2 100644 --- a/mesh/net-keys.c +++ b/mesh/net-keys.c @@ -16,6 +16,8 @@ #include <ell/ell.h> +#include "src/shared/ad.h" + #include "mesh/mesh-defs.h" #include "mesh/util.h" #include "mesh/crypto.h" @@ -74,8 +76,8 @@ static struct l_queue *keys; static uint32_t last_flooding_id; /* To avoid re-decrypting same packet for multiple nodes, cache and check */ -static uint8_t cache_pkt[29]; -static uint8_t cache_plain[29]; +static uint8_t cache_pkt[MESH_NET_MAX_PDU_LEN]; +static uint8_t cache_plain[MESH_NET_MAX_PDU_LEN]; static size_t cache_len; static size_t cache_plainlen; static uint32_t cache_id; diff --git a/mesh/net.c b/mesh/net.c index d711f80c83d1..cf4f337616d5 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -19,6 +19,8 @@ #include <ell/ell.h> +#include "src/shared/ad.h" + #include "mesh/mesh-defs.h" #include "mesh/util.h" #include "mesh/crypto.h" @@ -203,7 +205,7 @@ struct oneshot_tx { uint16_t interval; uint8_t cnt; uint8_t size; - uint8_t packet[30]; + uint8_t packet[MESH_AD_MAX_LEN]; }; struct net_beacon_data { @@ -2246,7 +2248,7 @@ static bool match_by_dst(const void *a, const void *b) static void send_relay_pkt(struct mesh_net *net, uint8_t *data, uint8_t size) { - uint8_t packet[30]; + uint8_t packet[MESH_AD_MAX_LEN]; struct mesh_io *io = net->io; struct mesh_io_send_info info = { .type = MESH_IO_TIMING_TYPE_GENERAL, @@ -3130,8 +3132,7 @@ static bool send_seg(struct mesh_net *net, uint8_t cnt, uint16_t interval, { struct mesh_subnet *subnet; uint8_t seg_len; - uint8_t gatt_data[30]; - uint8_t *packet = gatt_data; + uint8_t packet[MESH_AD_MAX_LEN]; uint8_t packet_len; uint8_t segN = SEG_MAX(msg->segmented, msg->len); uint16_t seg_off = SEG_OFF(segO); @@ -3193,7 +3194,7 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id, uint16_t src, uint16_t dst, uint32_t hdr, const void *seg, uint16_t seg_len) { - uint8_t packet[30]; + uint8_t packet[MESH_AD_MAX_LEN]; uint8_t packet_len; bool segmented = !!((hdr >> SEG_HDR_SHIFT) & 0x1); uint8_t key_aid = (hdr >> KEY_HDR_SHIFT) & KEY_ID_MASK; @@ -3353,7 +3354,7 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t net_key_id, uint32_t hdr; uint8_t data[7]; uint8_t pkt_len; - uint8_t pkt[30]; + uint8_t pkt[MESH_AD_MAX_LEN]; /* * MshPRFv1.0.1 section 3.4.5.2, Interface output filter: @@ -3400,7 +3401,7 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t net_key_id, uint16_t msg_len) { uint8_t pkt_len; - uint8_t pkt[30]; + uint8_t pkt[MESH_AD_MAX_LEN]; bool result = false; if (!net->src_addr) @@ -3416,7 +3417,7 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t net_key_id, ttl = net->default_ttl; /* Range check the Opcode and msg length*/ - if (*msg & 0xc0 || (9 + msg_len + 8 > 29)) + if (*msg & 0xc0 || (9 + msg_len + 8 > MESH_NET_MAX_PDU_LEN)) return; /* -- 2.43.0