1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #ifndef _MESH_GLUE_
21 #define _MESH_GLUE_
22
23 #include <assert.h>
24 #include <errno.h>
25
26 #include "syscfg/syscfg.h"
27 #include "logcfg/logcfg.h"
28 #include "modlog/modlog.h"
29 #include "nimble/nimble_npl.h"
30
31 #include "os/os_mbuf.h"
32 #include "os/queue.h"
33
34 #include "nimble/ble.h"
35 #include "host/ble_hs.h"
36 #include "host/ble_uuid.h"
37 #include "../src/ble_sm_priv.h"
38 #include "../src/ble_hs_hci_priv.h"
39
40 #include "tinycrypt/aes.h"
41 #include "tinycrypt/constants.h"
42 #include "tinycrypt/utils.h"
43 #include "tinycrypt/cmac_mode.h"
44 #include "tinycrypt/ecc_dh.h"
45
46 #if MYNEWT_VAL(BLE_MESH_SETTINGS)
47 #include "config/config.h"
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 #define u8_t uint8_t
55 #define s8_t int8_t
56 #define u16_t uint16_t
57 #define s16_t int16_t
58 #define u32_t uint32_t
59 #define u64_t uint64_t
60 #define s64_t int64_t
61 #define s32_t int32_t
62
63 /** @brief Helper to declare elements of bt_data arrays
64 *
65 * This macro is mainly for creating an array of struct bt_data
66 * elements which is then passed to bt_le_adv_start().
67 *
68 * @param _type Type of advertising data field
69 * @param _data Pointer to the data field payload
70 * @param _data_len Number of bytes behind the _data pointer
71 */
72 #define BT_DATA(_type, _data, _data_len) \
73 { \
74 .type = (_type), \
75 .data_len = (_data_len), \
76 .data = (const u8_t *)(_data), \
77 }
78
79 /** @brief Helper to declare elements of bt_data arrays
80 *
81 * This macro is mainly for creating an array of struct bt_data
82 * elements which is then passed to bt_le_adv_start().
83 *
84 * @param _type Type of advertising data field
85 * @param _bytes Variable number of single-byte parameters
86 */
87 #define BT_DATA_BYTES(_type, _bytes...) \
88 BT_DATA(_type, ((u8_t []) { _bytes }), \
89 sizeof((u8_t []) { _bytes }))
90
91 /* EIR/AD data type definitions */
92 #define BT_DATA_FLAGS 0x01 /* AD flags */
93 #define BT_DATA_UUID16_SOME 0x02 /* 16-bit UUID, more available */
94 #define BT_DATA_UUID16_ALL 0x03 /* 16-bit UUID, all listed */
95 #define BT_DATA_UUID32_SOME 0x04 /* 32-bit UUID, more available */
96 #define BT_DATA_UUID32_ALL 0x05 /* 32-bit UUID, all listed */
97 #define BT_DATA_UUID128_SOME 0x06 /* 128-bit UUID, more available */
98 #define BT_DATA_UUID128_ALL 0x07 /* 128-bit UUID, all listed */
99 #define BT_DATA_NAME_SHORTENED 0x08 /* Shortened name */
100 #define BT_DATA_NAME_COMPLETE 0x09 /* Complete name */
101 #define BT_DATA_TX_POWER 0x0a /* Tx Power */
102 #define BT_DATA_SOLICIT16 0x14 /* Solicit UUIDs, 16-bit */
103 #define BT_DATA_SOLICIT128 0x15 /* Solicit UUIDs, 128-bit */
104 #define BT_DATA_SVC_DATA16 0x16 /* Service data, 16-bit UUID */
105 #define BT_DATA_GAP_APPEARANCE 0x19 /* GAP appearance */
106 #define BT_DATA_SOLICIT32 0x1f /* Solicit UUIDs, 32-bit */
107 #define BT_DATA_SVC_DATA32 0x20 /* Service data, 32-bit UUID */
108 #define BT_DATA_SVC_DATA128 0x21 /* Service data, 128-bit UUID */
109 #define BT_DATA_URI 0x24 /* URI */
110 #define BT_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */
111 #define BT_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */
112 #define BT_DATA_MESH_BEACON 0x2b /* Mesh Beacon */
113
114 #define BT_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */
115
116 #define BT_LE_AD_LIMITED 0x01 /* Limited Discoverable */
117 #define BT_LE_AD_GENERAL 0x02 /* General Discoverable */
118 #define BT_LE_AD_NO_BREDR 0x04 /* BR/EDR not supported */
119
120 #define sys_put_be16(a, b) put_be16(b, a)
121 #define sys_put_le16(a, b) put_le16(b, a)
122 #define sys_put_be32(a, b) put_be32(b, a)
123 #define sys_get_be16(a) get_be16(a)
124 #define sys_get_le16(a) get_le16(a)
125 #define sys_get_be32(a) get_be32(a)
126 #define sys_cpu_to_be16(a) htobe16(a)
127 #define sys_cpu_to_be32(a) htobe32(a)
128 #define sys_be32_to_cpu(a) be32toh(a)
129 #define sys_be16_to_cpu(a) be16toh(a)
130 #define sys_le16_to_cpu(a) le16toh(a)
131
132 #ifndef ARRAY_SIZE
133 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
134 #endif
135
136 #define CODE_UNREACHABLE __builtin_unreachable()
137 #define __ASSERT(code, str) \
138 do { \
139 if (!(code)) BT_ERR(str); \
140 assert(code); \
141 } while (0);
142
143 #define __ASSERT_NO_MSG(test) __ASSERT(test, "")
144
145 /* Mesh is designed to not use mbuf chains */
146 #if BT_DBG_ENABLED
147 #define ASSERT_NOT_CHAIN(om) assert(SLIST_NEXT(om, om_next) == NULL)
148 #else
149 #define ASSERT_NOT_CHAIN(om) (void)(om)
150 #endif
151
152 #define __packed __attribute__((__packed__))
153
154 #define MSEC_PER_SEC (1000)
155 #define K_MSEC(ms) (ms)
156 #define K_SECONDS(s) K_MSEC((s) * MSEC_PER_SEC)
157 #define K_MINUTES(m) K_SECONDS((m) * 60)
158 #define K_HOURS(h) K_MINUTES((h) * 60)
159
160 #ifndef BIT
161 #define BIT(n) (1UL << (n))
162 #endif
163
164 #define BIT_MASK(n) (BIT(n) - 1)
165
166 #define BT_GAP_ADV_FAST_INT_MIN_1 0x0030 /* 30 ms */
167 #define BT_GAP_ADV_FAST_INT_MAX_1 0x0060 /* 60 ms */
168 #define BT_GAP_ADV_FAST_INT_MIN_2 0x00a0 /* 100 ms */
169 #define BT_GAP_ADV_FAST_INT_MAX_2 0x00f0 /* 150 ms */
170 #define BT_GAP_ADV_SLOW_INT_MIN 0x0640 /* 1 s */
171 #define BT_GAP_ADV_SLOW_INT_MAX 0x0780 /* 1.2 s */
172
173 #ifndef MESH_LOG_MODULE
174 #define MESH_LOG_MODULE BLE_MESH_LOG
175 #endif
176 #define BT_DBG_ENABLED 1
177
178 #define BT_DBG(fmt, ...) \
179 if (BT_DBG_ENABLED) { \
180 BLE_HS_LOG(DEBUG, "%s: " fmt "\n", __func__, ## __VA_ARGS__); \
181 }
182 #define BT_INFO(fmt, ...) BLE_HS_LOG(INFO, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
183 #define BT_WARN(fmt, ...) BLE_HS_LOG(WARN, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
184 #define BT_ERR(fmt, ...) BLE_HS_LOG(ERROR, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
185
186 #define BT_GATT_ERR(_att_err) (-(_att_err))
187
188 typedef ble_addr_t bt_addr_le_t;
189
190 #define k_fifo_init(queue) ble_npl_eventq_init(queue)
191 #define net_buf_simple_tailroom(buf) OS_MBUF_TRAILINGSPACE(buf)
192 #define net_buf_tailroom(buf) net_buf_simple_tailroom(buf)
193 #define net_buf_headroom(buf) ((buf)->om_data - &(buf)->om_databuf[(buf)->om_pkthdr_len])
194 #define net_buf_simple_headroom(buf) net_buf_headroom(buf)
195 #define net_buf_simple_tail(buf) ((buf)->om_data + (buf)->om_len)
196
197 struct net_buf_simple_state {
198 /** Offset of the data pointer from the beginning of the storage */
199 u16_t offset;
200 /** Length of data */
201 u16_t len;
202 };
203
NET_BUF_SIMPLE(uint16_t size)204 static inline struct os_mbuf *NET_BUF_SIMPLE(uint16_t size)
205 {
206 struct os_mbuf *buf;
207 buf = os_msys_get(size, 0);
208 assert(buf);
209 return buf;
210 }
211
212 #define K_NO_WAIT (0)
213 #define K_FOREVER (-1)
214
215 #if MYNEWT_VAL(BLE_EXT_ADV)
216 #define BT_MESH_ADV_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES))
217
218 #if MYNEWT_VAL(BLE_MESH_PROXY)
219 /* Note that BLE_MULTI_ADV_INSTANCES contains number of additional instances.
220 * Instance 0 is always there
221 */
222 #if MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) < 1
223 #error "Mesh needs at least BLE_MULTI_ADV_INSTANCES set to 1"
224 #endif
225 #define BT_MESH_ADV_GATT_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) - 1)
226 #endif /* BLE_MESH_PROXY */
227 #endif /* BLE_EXT_ADV */
228
229 /* This is by purpose */
net_buf_simple_init(struct os_mbuf * buf,size_t reserve_head)230 static inline void net_buf_simple_init(struct os_mbuf *buf,
231 size_t reserve_head)
232 {
233 /* This is called in Zephyr after init.
234 * Note in Mynewt case we don't care abour reserved head
235 */
236 buf->om_data = &buf->om_databuf[buf->om_pkthdr_len] + reserve_head;
237 buf->om_len = 0;
238 }
239
240 void net_buf_put(struct ble_npl_eventq *fifo, struct os_mbuf *buf);
241 void *net_buf_ref(struct os_mbuf *om);
242 void net_buf_unref(struct os_mbuf *om);
243 uint16_t net_buf_simple_pull_le16(struct os_mbuf *om);
244 uint16_t net_buf_simple_pull_be16(struct os_mbuf *om);
245 uint32_t net_buf_simple_pull_be32(struct os_mbuf *om);
246 uint32_t net_buf_simple_pull_le32(struct os_mbuf *om);
247 uint8_t net_buf_simple_pull_u8(struct os_mbuf *om);
248 void net_buf_simple_add_le16(struct os_mbuf *om, uint16_t val);
249 void net_buf_simple_add_be16(struct os_mbuf *om, uint16_t val);
250 void net_buf_simple_add_u8(struct os_mbuf *om, uint8_t val);
251 void net_buf_simple_add_be32(struct os_mbuf *om, uint32_t val);
252 void net_buf_simple_add_le32(struct os_mbuf *om, uint32_t val);
253 void net_buf_add_zeros(struct os_mbuf *om, uint8_t len);
254 void net_buf_simple_push_le16(struct os_mbuf *om, uint16_t val);
255 void net_buf_simple_push_be16(struct os_mbuf *om, uint16_t val);
256 void net_buf_simple_push_u8(struct os_mbuf *om, uint8_t val);
257 void *net_buf_simple_pull(struct os_mbuf *om, uint8_t len);
258 void *net_buf_simple_pull_mem(struct os_mbuf *om, uint8_t len);
259 void *net_buf_simple_add(struct os_mbuf *om, uint8_t len);
260 bool k_fifo_is_empty(struct ble_npl_eventq *q);
261 void *net_buf_get(struct ble_npl_eventq *fifo, s32_t t);
262 uint8_t *net_buf_simple_push(struct os_mbuf *om, uint8_t len);
263 void net_buf_reserve(struct os_mbuf *om, size_t reserve);
264
265 #define net_buf_add_mem(a, b, c) os_mbuf_append(a, b, c)
266 #define net_buf_simple_add_mem(a, b, c) os_mbuf_append(a, b, c)
267 #define net_buf_add_u8(a, b) net_buf_simple_add_u8(a, b)
268 #define net_buf_add(a, b) net_buf_simple_add(a, b)
269
270 #define net_buf_clone(a, b) os_mbuf_dup(a)
271 #define net_buf_add_be32(a, b) net_buf_simple_add_be32(a, b)
272 #define net_buf_add_be16(a, b) net_buf_simple_add_be16(a, b)
273 #define net_buf_pull(a, b) net_buf_simple_pull(a, b)
274 #define net_buf_pull_mem(a, b) net_buf_simple_pull_mem(a, b)
275 #define net_buf_pull_u8(a) net_buf_simple_pull_u8(a)
276 #define net_buf_pull_be16(a) net_buf_simple_pull_be16(a)
277 #define net_buf_skip(a, b) net_buf_simple_pull_mem(a, b)
278
279 #define BT_GATT_CCC_NOTIFY BLE_GATT_CHR_PROP_NOTIFY
280
281 /** Description of different data types that can be encoded into
282 * advertising data. Used to form arrays that are passed to the
283 * bt_le_adv_start() function.
284 */
285 struct bt_data {
286 u8_t type;
287 u8_t data_len;
288 const u8_t *data;
289 };
290
291 struct bt_pub_key_cb {
292 /** @brief Callback type for Public Key generation.
293 *
294 * Used to notify of the local public key or that the local key is not
295 * available (either because of a failure to read it or because it is
296 * being regenerated).
297 *
298 * @param key The local public key, or NULL in case of no key.
299 */
300 void (*func)(const u8_t key[64]);
301
302 struct bt_pub_key_cb *_next;
303 };
304
305 typedef void (*bt_dh_key_cb_t)(const u8_t key[32]);
306 int bt_dh_key_gen(const u8_t remote_pk[64], bt_dh_key_cb_t cb);
307 int bt_pub_key_gen(struct bt_pub_key_cb *new_cb);
308 uint8_t *bt_pub_key_get(void);
309 int bt_rand(void *buf, size_t len);
310 const char *bt_hex(const void *buf, size_t len);
311 int bt_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *enc_data);
312 void bt_mesh_register_gatt(void);
313 int bt_le_adv_start(const struct ble_gap_adv_params *param,
314 const struct bt_data *ad, size_t ad_len,
315 const struct bt_data *sd, size_t sd_len);
316 int bt_le_adv_stop(bool proxy);
317
318 struct k_delayed_work {
319 struct ble_npl_callout work;
320 };
321
322 void k_work_init(struct ble_npl_callout *work, ble_npl_event_fn handler);
323 void k_delayed_work_init(struct k_delayed_work *w, ble_npl_event_fn *f);
324 void k_delayed_work_cancel(struct k_delayed_work *w);
325 void k_delayed_work_submit(struct k_delayed_work *w, uint32_t ms);
326 int64_t k_uptime_get(void);
327 u32_t k_uptime_get_32(void);
328 void k_sleep(int32_t duration);
329 void k_work_submit(struct ble_npl_callout *w);
330 void k_work_add_arg(struct ble_npl_callout *w, void *arg);
331 void k_delayed_work_add_arg(struct k_delayed_work *w, void *arg);
332 uint32_t k_delayed_work_remaining_get(struct k_delayed_work *w);
333
net_buf_simple_save(struct os_mbuf * buf,struct net_buf_simple_state * state)334 static inline void net_buf_simple_save(struct os_mbuf *buf,
335 struct net_buf_simple_state *state)
336 {
337 state->offset = net_buf_simple_headroom(buf);
338 state->len = buf->om_len;
339 }
340
net_buf_simple_restore(struct os_mbuf * buf,struct net_buf_simple_state * state)341 static inline void net_buf_simple_restore(struct os_mbuf *buf,
342 struct net_buf_simple_state *state)
343 {
344 buf->om_data = &buf->om_databuf[buf->om_pkthdr_len] + state->offset;
345 buf->om_len = state->len;
346 }
347
sys_memcpy_swap(void * dst,const void * src,size_t length)348 static inline void sys_memcpy_swap(void *dst, const void *src, size_t length)
349 {
350 size_t Length = length;
351 const void *src_tmp = src;
352 __ASSERT(((src < dst && (src + Length) <= dst) ||
353 (src > dst && (dst + Length) <= src)),
354 "Source and destination buffers must not overlap");
355 src_tmp += Length - 1;
356
357 for (; Length > 0; Length--) {
358 *((u8_t *)dst++) = *((u8_t *)src_tmp--);
359 }
360 }
361
362 #define popcount(x) __builtin_popcount(x)
363
find_lsb_set(u32_t op)364 static inline unsigned int find_lsb_set(u32_t op)
365 {
366 return __builtin_ffs(op);
367 }
368
find_msb_set(u32_t op)369 static inline unsigned int find_msb_set(u32_t op)
370 {
371 if (!op) {
372 return 0;
373 }
374
375 return 32 - __builtin_clz(op);
376 }
377
378 #define CONFIG_BT_MESH_FRIEND BLE_MESH_FRIEND
379 #define CONFIG_BT_MESH_GATT_PROXY BLE_MESH_GATT_PROXY
380 #define CONFIG_BT_MESH_IV_UPDATE_TEST BLE_MESH_IV_UPDATE_TEST
381 #define CONFIG_BT_MESH_LOW_POWER BLE_MESH_LOW_POWER
382 #define CONFIG_BT_MESH_LPN_AUTO BLE_MESH_LPN_AUTO
383 #define CONFIG_BT_MESH_LPN_ESTABLISHMENT BLE_MESH_LPN_ESTABLISHMENT
384 #define CONFIG_BT_MESH_PB_ADV BLE_MESH_PB_ADV
385 #define CONFIG_BT_MESH_PB_GATT BLE_MESH_PB_GATT
386 #define CONFIG_BT_MESH_PROV BLE_MESH_PROV
387 #define CONFIG_BT_MESH_PROXY BLE_MESH_PROXY
388 #define CONFIG_BT_TESTING BLE_MESH_TESTING
389 #define CONFIG_BT_SETTINGS BLE_MESH_SETTINGS
390 #define CONFIG_SETTINGS BLE_MESH_SETTINGS
391 #define CONFIG_BT_MESH_PROVISIONER BLE_MESH_PROVISIONER
392
393 /* Above flags are used with IS_ENABLED macro */
394 #define IS_ENABLED(config) MYNEWT_VAL(config)
395
396 #define CONFIG_BT_MESH_LPN_GROUPS MYNEWT_VAL(BLE_MESH_LPN_GROUPS)
397 #define CONFIG_BT_MESH_ADV_BUF_COUNT MYNEWT_VAL(BLE_MESH_ADV_BUF_COUNT)
398 #define CONFIG_BT_MESH_FRIEND_QUEUE_SIZE MYNEWT_VAL(BLE_MESH_FRIEND_QUEUE_SIZE)
399 #define CONFIG_BT_MESH_FRIEND_RECV_WIN MYNEWT_VAL(BLE_MESH_FRIEND_RECV_WIN)
400 #define CONFIG_BT_MESH_LPN_POLL_TIMEOUT MYNEWT_VAL(BLE_MESH_LPN_POLL_TIMEOUT)
401 #define CONFIG_BT_MESH_MODEL_GROUP_COUNT MYNEWT_VAL(BLE_MESH_MODEL_GROUP_COUNT)
402 #define CONFIG_BT_MESH_MODEL_KEY_COUNT MYNEWT_VAL(BLE_MESH_MODEL_KEY_COUNT)
403 #define CONFIG_BT_MESH_NODE_ID_TIMEOUT MYNEWT_VAL(BLE_MESH_NODE_ID_TIMEOUT)
404 #define CONFIG_BT_MAX_CONN MYNEWT_VAL(BLE_MAX_CONNECTIONS)
405 #define CONFIG_BT_MESH_SEQ_STORE_RATE MYNEWT_VAL(BLE_MESH_SEQ_STORE_RATE)
406 #define CONFIG_BT_MESH_RPL_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_RPL_STORE_TIMEOUT)
407 #define CONFIG_BT_MESH_APP_KEY_COUNT MYNEWT_VAL(BLE_MESH_APP_KEY_COUNT)
408 #define CONFIG_BT_MESH_SUBNET_COUNT MYNEWT_VAL(BLE_MESH_SUBNET_COUNT)
409 #define CONFIG_BT_MESH_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_STORE_TIMEOUT)
410 #define CONFIG_BT_MESH_IVU_DIVIDER MYNEWT_VAL(BLE_MESH_IVU_DIVIDER)
411 #define CONFIG_BT_DEVICE_NAME MYNEWT_VAL(BLE_MESH_DEVICE_NAME)
412 #define CONFIG_BT_MESH_TX_SEG_MAX MYNEWT_VAL(BLE_MESH_TX_SEG_MAX)
413 #define CONFIG_BT_MESH_LABEL_COUNT MYNEWT_VAL(BLE_MESH_LABEL_COUNT)
414 #define CONFIG_BT_MESH_NODE_COUNT MYNEWT_VAL(BLE_MESH_NODE_COUNT)
415
416 #define printk console_printf
417
418 #define CONTAINER_OF(ptr, type, field) \
419 ((type *)(((char *)(ptr)) - offsetof(type, field)))
420
421 #define k_sem ble_npl_sem
422
k_sem_init(struct k_sem * sem,unsigned int initial_count,unsigned int limit)423 static inline void k_sem_init(struct k_sem *sem, unsigned int initial_count,
424 unsigned int limit)
425 {
426 ble_npl_sem_init(sem, initial_count);
427 }
428
k_sem_take(struct k_sem * sem,s32_t timeout)429 static inline int k_sem_take(struct k_sem *sem, s32_t timeout)
430 {
431 uint32_t ticks;
432 ble_npl_time_ms_to_ticks(timeout, &ticks);
433 return - ble_npl_sem_pend(sem, ticks);
434 }
435
k_sem_give(struct k_sem * sem)436 static inline void k_sem_give(struct k_sem *sem)
437 {
438 ble_npl_sem_release(sem);
439 }
440
441 /* Helpers to access the storage array, since we don't have access to its
442 * type at this point anymore.
443 */
444
445 #define BUF_SIZE(pool) ((pool)->omp_pool->mp_block_size)
446
net_buf_id(struct os_mbuf * buf)447 static inline int net_buf_id(struct os_mbuf *buf)
448 {
449 struct os_mbuf_pool *pool = buf->om_omp;
450 u8_t *pool_start = (u8_t *)pool->omp_pool->mp_membuf_addr;
451 u8_t *buf_ptr = (u8_t *)buf;
452 return (buf_ptr - pool_start) / BUF_SIZE(pool);
453 }
454
455 /* XXX: We should not use os_mbuf_pkthdr chains to represent a list of
456 * packets, this is a hack. For now this is not an issue, because mesh
457 * does not use os_mbuf chains. We should change this in the future.
458 */
459 STAILQ_HEAD(net_buf_slist_t, os_mbuf_pkthdr);
460
461 void net_buf_slist_init(struct net_buf_slist_t *list);
462 bool net_buf_slist_is_empty(struct net_buf_slist_t *list);
463 struct os_mbuf *net_buf_slist_peek_head(struct net_buf_slist_t *list);
464 struct os_mbuf *net_buf_slist_peek_next(struct os_mbuf *buf);
465 struct os_mbuf *net_buf_slist_get(struct net_buf_slist_t *list);
466 void net_buf_slist_put(struct net_buf_slist_t *list, struct os_mbuf *buf);
467 void net_buf_slist_remove(struct net_buf_slist_t *list, struct os_mbuf *prev,
468 struct os_mbuf *cur);
469 void net_buf_slist_merge_slist(struct net_buf_slist_t *list,
470 struct net_buf_slist_t *list_to_append);
471 #define NET_BUF_SLIST_FOR_EACH_NODE(head, var) STAILQ_FOREACH(var, head, omp_next)
472
473 #if MYNEWT_VAL(BLE_MESH_SETTINGS)
474
475 #define settings_load conf_load
476 int settings_bytes_from_str(char *val_str, void *vp, int *len);
477 char *settings_str_from_bytes(const void *vp, int vp_len,
478 char *buf, int buf_len);
479
480 #define snprintk snprintf
481 #define BT_SETTINGS_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1)
482 #define settings_save_one conf_save_one
483
484 #else
485
settings_load(void)486 static inline int settings_load(void)
487 {
488 return 0;
489 }
490
491 #endif /* MYNEWT_VAL(MYNEWT_VAL_BLE_MESH_SETTINGS) */
492
493 #define BUILD_ASSERT(cond) _Static_assert(cond, "")
494
495 #ifdef __cplusplus
496 }
497 #endif
498
499 #endif /* _MESH_GLUE_ */
500