diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h
index 25ce012..a12acaf 100644
--- a/mesh/mesh-defs.h
+++ b/mesh/mesh-defs.h
#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 1ec4f37..0875a35 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
#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"
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 4ca7ff9..065067f 100644
--- a/mesh/mesh-io-mgmt.c
+++ b/mesh/mesh-io-mgmt.c
#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"
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 936f5a9..f9a5aaa 100644
--- a/mesh/mesh-io-unit.c
+++ b/mesh/mesh-io-unit.c
#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"
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 22ab5b6..9b11bb7 100644
--- a/mesh/net-keys.c
+++ b/mesh/net-keys.c
#include <ell/ell.h>
+#include "src/shared/ad.h"
+
#include "mesh/mesh-defs.h"
#include "mesh/util.h"
#include "mesh/crypto.h"
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 d711f80..cf4f337 100644
--- a/mesh/net.c
+++ b/mesh/net.c
#include <ell/ell.h>
+#include "src/shared/ad.h"
+
#include "mesh/mesh-defs.h"
#include "mesh/util.h"
#include "mesh/crypto.h"
uint16_t interval;
uint8_t cnt;
uint8_t size;
- uint8_t packet[30];
+ uint8_t packet[MESH_AD_MAX_LEN];
};
struct net_beacon_data {
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,
{
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);
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;
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:
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)
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;
/*