xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/mesh/src/lpn.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*  Bluetooth Mesh */
2 
3 /*
4  * Copyright (c) 2017 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 #ifndef __LPN_H__
9 #define __LPN_H__
10 
11 #include "mesh/mesh.h"
12 
13 int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
14 			      struct os_mbuf *buf);
15 int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
16 			     struct os_mbuf *buf);
17 int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx,
18 				 struct os_mbuf *buf);
19 int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
20 			       struct os_mbuf *buf);
21 
bt_mesh_lpn_established(void)22 static inline bool bt_mesh_lpn_established(void)
23 {
24 #if (MYNEWT_VAL(BLE_MESH_LOW_POWER))
25 	return bt_mesh.lpn.established;
26 #else
27 	return false;
28 #endif
29 }
30 
bt_mesh_lpn_match(u16_t addr)31 static inline bool bt_mesh_lpn_match(u16_t addr)
32 {
33 #if (MYNEWT_VAL(BLE_MESH_LOW_POWER))
34 	if (bt_mesh_lpn_established()) {
35 		return (addr == bt_mesh.lpn.frnd);
36 	}
37 #endif
38 	return false;
39 }
40 
bt_mesh_lpn_waiting_update(void)41 static inline bool bt_mesh_lpn_waiting_update(void)
42 {
43 #if (MYNEWT_VAL(BLE_MESH_LOW_POWER))
44 	return (bt_mesh.lpn.state == BT_MESH_LPN_WAIT_UPDATE);
45 #else
46 	return false;
47 #endif
48 }
49 
bt_mesh_lpn_timer(void)50 static inline bool bt_mesh_lpn_timer(void)
51 {
52 #if MYNEWT_VAL(BLE_MESH_LOW_POWER) && MYNEWT_VAL(BLE_MESH_LPN_AUTO)
53 	return (bt_mesh.lpn.state == BT_MESH_LPN_TIMER);
54 #else
55 	return false;
56 #endif
57 }
58 
59 void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx);
60 
61 void bt_mesh_lpn_group_add(u16_t group);
62 void bt_mesh_lpn_group_del(u16_t *groups, size_t group_count);
63 
64 void bt_mesh_lpn_disable(bool force);
65 
66 int bt_mesh_lpn_init(void);
67 
68 #endif
69