1 /*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #define BT_MESH_DFU_OP_UPDATE_INFO_GET BT_MESH_MODEL_OP_2(0x83, 0x08)
8 #define BT_MESH_DFU_OP_UPDATE_INFO_STATUS BT_MESH_MODEL_OP_2(0x83, 0x09)
9
10 #define BT_MESH_DFU_OP_UPDATE_METADATA_CHECK BT_MESH_MODEL_OP_2(0x83, 0x0a)
11 #define BT_MESH_DFU_OP_UPDATE_METADATA_STATUS BT_MESH_MODEL_OP_2(0x83, 0x0b)
12
13 #define BT_MESH_DFU_OP_UPDATE_GET BT_MESH_MODEL_OP_2(0x83, 0x0c)
14 #define BT_MESH_DFU_OP_UPDATE_START BT_MESH_MODEL_OP_2(0x83, 0x0d)
15 #define BT_MESH_DFU_OP_UPDATE_CANCEL BT_MESH_MODEL_OP_2(0x83, 0x0e)
16 #define BT_MESH_DFU_OP_UPDATE_APPLY BT_MESH_MODEL_OP_2(0x83, 0x0f)
17 #define BT_MESH_DFU_OP_UPDATE_STATUS BT_MESH_MODEL_OP_2(0x83, 0x10)
18
19 #define DFU_UPDATE_INFO_STATUS_MSG_MINLEN (4 + CONFIG_BT_MESH_DFU_FWID_MAXLEN + \
20 CONFIG_BT_MESH_DFU_URI_MAXLEN)
21 #define DFU_UPDATE_START_MSG_MAXLEN (12 + CONFIG_BT_MESH_DFU_METADATA_MAXLEN)
22
dfu_metadata_checksum(struct net_buf_simple * buf)23 static inline uint16_t dfu_metadata_checksum(struct net_buf_simple *buf)
24 {
25 /* Simple Fletcher-16 checksum to ensure duplicate start messages don't
26 * have different metadata.
27 */
28 struct net_buf_simple_state state;
29 uint8_t sum[2] = {0, 0};
30
31 net_buf_simple_save(buf, &state);
32
33
34 while (buf->len) {
35 uint8_t byte = net_buf_simple_pull_u8(buf);
36
37 sum[0] += byte;
38 sum[1] += sum[0];
39 }
40
41 net_buf_simple_restore(buf, &state);
42
43 return (sum[0] << 8U) | sum[1];
44 }
45