Skip to contentSkip to conversation

mesh: Fix unpacking NetKey/AppKey 3-octet index combo

PATCH New Inga Stotland 1 participant 1 message Oct 17, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mesh: Fix unpacking NetKey/AppKey 3-octet index combo

This fixes how we unpack 3-octet combination of NetKey and AppKey indices received in the payload of AppKeyAdd/Update/Delete messages.

For example, if the config client sends a message to add AppKey with index 0x456 bound to NetKey with index 0x123, the received packed 3-octet will be: 0x56 0x34 0x12
The fix takes into account the correct byte ordering when unpacking indices.

---
 mesh/cfgmod-server.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
mesh/cfgmod-server.c +5 -4
index 55cc8e9eb..79538037c 100644
@@ -1022,8 +1022,8 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst, uint16_t unicast,
 		if (size != 19)
 			return true;
 
-		n_idx = l_get_le16(pkt) & 0xfff;
-		a_idx = l_get_le16(pkt + 1) >> 4;
+		n_idx = l_get_le16(pkt + 1) >> 4;
+		a_idx = l_get_le16(pkt) & 0xfff;
 
 		if (opcode == OP_APPKEY_ADD)
 			b_res = appkey_key_add(net, n_idx, a_idx, pkt + 3);
@@ -1048,9 +1048,10 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst, uint16_t unicast,
 		if (size != 3)
 			return true;
 
-		n_idx = l_get_le16(pkt) & 0xfff;
-		a_idx = l_get_le16(pkt + 1) >> 4;
+		n_idx = l_get_le16(pkt + 1) >> 4;
+		a_idx = l_get_le16(pkt) & 0xfff;
 		b_res = appkey_key_delete(net, n_idx, a_idx);
+
 		l_debug("Delete AppKey %s Net_Idx %3.3x to App_Idx %3.3x",
 			(b_res == MESH_STATUS_SUCCESS) ? "success" : "fail",
 							n_idx, a_idx);
Signature · 1 line
2.21.0