From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 1/3] mesh: Use static array to hold config server response
Date: Mon, 13 Jul 2020 16:05:26 -0700 [thread overview]
Message-ID: <20200713230528.107948-2-inga.stotland@intel.com> (raw)
In-Reply-To: <20200713230528.107948-1-inga.stotland@intel.com>
This eliminates dynamic allocation for long responses and local
arrays for short responses. Instead, aclear text response from
config server is written into a static buffer and then encoded
into dynamically allocated messafe buffer to use in actual
transmission.
---
mesh/cfgmod-server.c | 53 +++++++++++++-------------------------------
1 file changed, 16 insertions(+), 37 deletions(-)
diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 14b4a980e..08a74d014 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -32,21 +32,20 @@
#include "mesh/mesh-config.h"
#include "mesh/cfgmod.h"
-#define CFG_MAX_MSG_LEN 380
-
/* Supported composition pages, sorted high to low */
/* Only page 0 is currently supported */
static const uint8_t supported_pages[] = {
0
};
+static uint8_t msg[MAX_MSG_LEN];
+
static void send_pub_status(struct mesh_node *node, uint16_t net_idx,
uint16_t src, uint16_t dst,
uint8_t status, uint16_t ele_addr, uint32_t mod_id,
uint16_t pub_addr, uint16_t idx, bool cred_flag,
uint8_t ttl, uint8_t period, uint8_t retransmit)
{
- uint8_t msg[16];
size_t n;
n = mesh_model_opcode_set(OP_CONFIG_MODEL_PUB_STATUS, msg);
@@ -193,7 +192,6 @@ static void send_sub_status(struct mesh_node *node, uint16_t net_idx,
uint8_t status, uint16_t ele_addr,
uint16_t addr, uint32_t mod)
{
- uint8_t msg[12];
int n = mesh_model_opcode_set(OP_CONFIG_MODEL_SUB_STATUS, msg);
msg[n++] = status;
@@ -224,7 +222,6 @@ static bool config_sub_get(struct mesh_node *node, uint16_t net_idx,
int status;
uint8_t *msg_status;
uint16_t buf_size;
- uint8_t msg[5 + sizeof(uint16_t) * MAX_GRP_PER_MOD];
/* Incoming message has already been size-checked */
ele_addr = l_get_le16(pkt);
@@ -430,7 +427,6 @@ static void send_model_app_status(struct mesh_node *node, uint16_t net_idx,
uint8_t status, uint16_t addr,
uint32_t id, uint16_t idx)
{
- uint8_t msg[12];
size_t n = mesh_model_opcode_set(OP_MODEL_APP_STATUS, msg);
msg[n++] = status;
@@ -455,21 +451,14 @@ static void model_app_list(struct mesh_node *node, uint16_t net_idx,
{
uint16_t ele_addr;
uint32_t mod_id = 0xffff;
- uint8_t *msg = NULL;
uint8_t *status;
- uint16_t n, buf_size;
+ uint16_t n;
int result;
- buf_size = MAX_BINDINGS * sizeof(uint16_t);
- msg = l_malloc(7 + buf_size);
- if (!msg)
- return;
-
ele_addr = l_get_le16(pkt);
switch (size) {
default:
- l_free(msg);
return;
case 4:
n = mesh_model_opcode_set(OP_MODEL_APP_LIST, msg);
@@ -495,7 +484,7 @@ static void model_app_list(struct mesh_node *node, uint16_t net_idx,
result = mesh_model_get_bindings(node, ele_addr, mod_id, msg + n,
- buf_size, &size);
+ MAX_MSG_LEN - n, &size);
n += size;
if (result >= 0) {
@@ -503,8 +492,6 @@ static void model_app_list(struct mesh_node *node, uint16_t net_idx,
mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx,
DEFAULT_TTL, false, msg, n);
}
-
- l_free(msg);
}
static bool model_app_bind(struct mesh_node *node, uint16_t net_idx,
@@ -736,8 +723,6 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
struct timeval time_now;
uint32_t opcode, tmp32;
int b_res = MESH_STATUS_SUCCESS;
- uint8_t msg[11];
- uint8_t *long_msg = NULL;
struct mesh_net_heartbeat *hb;
uint16_t n_idx, a_idx;
uint8_t state, status;
@@ -771,9 +756,8 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
if (size != 1)
return false;
- long_msg = l_malloc(CFG_MAX_MSG_LEN);
- n = mesh_model_opcode_set(OP_DEV_COMP_STATUS, long_msg);
- n += get_composition(node, pkt[0], long_msg + n);
+ n = mesh_model_opcode_set(OP_DEV_COMP_STATUS, msg);
+ n += get_composition(node, pkt[0], msg + n);
break;
@@ -1040,14 +1024,13 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
n_idx = l_get_le16(pkt);
- long_msg = l_malloc(CFG_MAX_MSG_LEN);
- n = mesh_model_opcode_set(OP_APPKEY_LIST, long_msg);
+ n = mesh_model_opcode_set(OP_APPKEY_LIST, msg);
- status = appkey_list(net, n_idx, long_msg + n + 3,
- CFG_MAX_MSG_LEN - n - 3, &size);
+ status = appkey_list(net, n_idx, msg + n + 3,
+ MAX_MSG_LEN - n - 3, &size);
- long_msg[n] = status;
- l_put_le16(n_idx, long_msg + n + 1);
+ msg[n] = status;
+ l_put_le16(n_idx, msg + n + 1);
n += (size + 3);
break;
@@ -1088,11 +1071,10 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
break;
case OP_NETKEY_GET:
- long_msg = l_malloc(CFG_MAX_MSG_LEN);
- n = mesh_model_opcode_set(OP_NETKEY_LIST, long_msg);
- size = CFG_MAX_MSG_LEN - n;
+ n = mesh_model_opcode_set(OP_NETKEY_LIST, msg);
+ size = MAX_MSG_LEN - n;
- if (mesh_net_key_list_get(net, long_msg + n, &size))
+ if (mesh_net_key_list_get(net, msg + n, &size))
n += size;
else
n = 0;
@@ -1244,11 +1226,8 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
}
if (n)
- mesh_model_send(node, dst, src,
- APP_IDX_DEV_LOCAL, net_idx, DEFAULT_TTL, false,
- long_msg ? long_msg : msg, n);
-
- l_free(long_msg);
+ mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx,
+ DEFAULT_TTL, false, msg, n);
return true;
}
--
2.26.2
next prev parent reply other threads:[~2020-07-13 23:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-13 23:05 [PATCH BlueZ 0/3] Code re-org and clean up Inga Stotland
2020-07-13 23:05 ` Inga Stotland [this message]
2020-07-13 23:05 ` [PATCH BlueZ 2/3] mesh: Add size checks for every opcode in config server Inga Stotland
2020-07-13 23:05 ` [PATCH BlueZ 3/3] mesh: move model functionality out of node.c to model.c Inga Stotland
2020-07-16 17:20 ` [PATCH BlueZ 0/3] Code re-org and clean up Gix, Brian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200713230528.107948-2-inga.stotland@intel.com \
--to=inga.stotland@intel.com \
--cc=brian.gix@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).