summaryrefslogtreecommitdiff
path: root/mesh/cfgmod-server.c
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2020-08-06 18:38:33 -0700
committerBrian Gix <brian.gix@intel.com>2020-08-10 14:47:09 -0700
commit1836a4e09efa68e2c5d911e0b49de9563eea3cd3 (patch)
tree85c7038a9128a1b7b7f99687093f883b0dcd4e39 /mesh/cfgmod-server.c
parent639dabe1c262247fa1c47a328157cfb9c62b7dc8 (diff)
downloadbluez-1836a4e09efa68e2c5d911e0b49de9563eea3cd3.tar.gz
mesh: Clean up handling of config KR phase messages
This modification allows using a single point for sending out the composed status messages by the Config Server. Also, this checks for the correct relationship between KR transition and KR phase values. Correct error codes are sent on unsuccessful requests and malformed requests are ignored.
Diffstat (limited to 'mesh/cfgmod-server.c')
-rw-r--r--mesh/cfgmod-server.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 191c5b8ef..ea0741969 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -417,6 +417,43 @@ static uint16_t cfg_relay_msg(struct mesh_node *node, const uint8_t *pkt,
return n;
}
+static uint16_t cfg_key_refresh_phase(struct mesh_node *node,
+ const uint8_t *pkt, int opcode)
+{
+ struct mesh_net *net = node_get_net(node);
+ uint16_t n, idx = l_get_le16(pkt);
+ uint8_t phase;
+ int status;
+
+ n = mesh_model_opcode_set(OP_CONFIG_KEY_REFRESH_PHASE_STATUS, msg);
+ status = mesh_net_key_refresh_phase_get(net, idx, &phase);
+
+ if (status == MESH_STATUS_SUCCESS &&
+ opcode == OP_CONFIG_KEY_REFRESH_PHASE_SET) {
+
+ if (pkt[2] == KEY_REFRESH_TRANS_TWO) {
+ if (phase == KEY_REFRESH_PHASE_TWO)
+ goto done;
+ else if (phase != KEY_REFRESH_PHASE_ONE)
+ return 0;
+ }
+
+ status = mesh_net_key_refresh_phase_set(net, idx, pkt[2]);
+ l_debug("Set KR Phase: net=%3.3x transition=%d", idx, pkt[2]);
+
+ if (status == MESH_STATUS_SUCCESS)
+ mesh_net_key_refresh_phase_get(net, idx, &phase);
+ }
+
+done:
+ msg[n] = status;
+ l_put_le16(idx, msg + n);
+ msg[n + 2] = (status != MESH_STATUS_SUCCESS) ?
+ KEY_REFRESH_PHASE_NONE : phase;
+
+ return n + 3;
+}
+
static void hb_pub_timeout_func(struct l_timeout *timeout, void *user_data)
{
struct mesh_net *net = user_data;
@@ -723,8 +760,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
int b_res = MESH_STATUS_SUCCESS;
struct mesh_net_heartbeat *hb;
uint16_t n_idx;
- uint8_t state, status;
- uint8_t phase;
+ uint8_t state;
bool virt = false;
uint16_t n;
@@ -934,37 +970,17 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
break;
case OP_CONFIG_KEY_REFRESH_PHASE_SET:
- if (size != 3 || pkt[2] > 0x03)
+ if (size != 3 || (pkt[2] != KEY_REFRESH_TRANS_THREE &&
+ pkt[2] != KEY_REFRESH_TRANS_TWO))
return true;
- b_res = mesh_net_key_refresh_phase_set(net, l_get_le16(pkt),
- pkt[2]);
- size = 2;
/* Fall Through */
case OP_CONFIG_KEY_REFRESH_PHASE_GET:
- if (size != 2)
+ if (size != 2 && opcode == OP_CONFIG_KEY_REFRESH_PHASE_GET)
return true;
- n_idx = l_get_le16(pkt);
-
- n = mesh_model_opcode_set(OP_CONFIG_KEY_REFRESH_PHASE_STATUS,
- msg);
-
- /* State: 0x00-0x03 phase of key refresh */
- status = mesh_net_key_refresh_phase_get(net, n_idx,
- &phase);
- if (status != MESH_STATUS_SUCCESS) {
- b_res = status;
- phase = KEY_REFRESH_PHASE_NONE;
- }
-
- msg[n++] = b_res;
- l_put_le16(n_idx, msg + n);
- n += 2;
- msg[n++] = phase;
-
- l_debug("Get/Set Key Refresh State (%d)", msg[n-1]);
+ n = cfg_key_refresh_phase(node, pkt, opcode);
break;
case OP_APPKEY_ADD: