1 /*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/sys/printk.h>
8 #include <stdlib.h>
9 #include <zephyr/kernel.h>
10
11 #include <zephyr/shell/shell.h>
12
13 #include <zephyr/bluetooth/bluetooth.h>
14 #include <zephyr/bluetooth/mesh.h>
15 #include <zephyr/bluetooth/mesh/shell.h>
16
17 static struct bt_mesh_cfg_cli cfg_cli;
18
19 #if defined(CONFIG_BT_MESH_DFD_SRV)
20 static struct bt_mesh_dfd_srv dfd_srv;
21 #endif
22
23 #if defined(CONFIG_BT_MESH_SAR_CFG_CLI)
24 static struct bt_mesh_sar_cfg_cli sar_cfg_cli;
25 #endif
26
27 #if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI)
28 static struct bt_mesh_priv_beacon_cli priv_beacon_cli;
29 #endif
30
31 #if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI)
32 static struct bt_mesh_sol_pdu_rpl_cli srpl_cli;
33 #endif
34
35
36 #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI)
37 static struct bt_mesh_od_priv_proxy_cli od_priv_proxy_cli;
38 #endif
39
40 #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI)
41 struct bt_mesh_large_comp_data_cli large_comp_data_cli;
42 #endif
43
44 #if defined(CONFIG_BT_MESH_BRG_CFG_CLI)
45 static struct bt_mesh_brg_cfg_cli brg_cfg_cli;
46 #endif
47
48 BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub);
49
50 static const struct bt_mesh_model root_models[] = {
51 BT_MESH_MODEL_CFG_SRV,
52 BT_MESH_MODEL_CFG_CLI(&cfg_cli),
53 BT_MESH_MODEL_HEALTH_SRV(&bt_mesh_shell_health_srv, &health_pub, health_srv_meta),
54 BT_MESH_MODEL_HEALTH_CLI(&bt_mesh_shell_health_cli),
55 #if defined(CONFIG_BT_MESH_DFD_SRV)
56 BT_MESH_MODEL_DFD_SRV(&dfd_srv),
57 #else
58 #if defined(CONFIG_BT_MESH_SHELL_DFU_SRV)
59 BT_MESH_MODEL_DFU_SRV(&bt_mesh_shell_dfu_srv),
60 #elif defined(CONFIG_BT_MESH_SHELL_BLOB_SRV)
61 BT_MESH_MODEL_BLOB_SRV(&bt_mesh_shell_blob_srv),
62 #endif
63 #if defined(CONFIG_BT_MESH_SHELL_DFU_CLI)
64 BT_MESH_MODEL_DFU_CLI(&bt_mesh_shell_dfu_cli),
65 #elif defined(CONFIG_BT_MESH_SHELL_BLOB_CLI)
66 BT_MESH_MODEL_BLOB_CLI(&bt_mesh_shell_blob_cli),
67 #endif
68 #endif /* CONFIG_BT_MESH_DFD_SRV */
69 #if defined(CONFIG_BT_MESH_SHELL_RPR_CLI)
70 BT_MESH_MODEL_RPR_CLI(&bt_mesh_shell_rpr_cli),
71 #endif
72 #if defined(CONFIG_BT_MESH_RPR_SRV)
73 BT_MESH_MODEL_RPR_SRV,
74 #endif
75
76 #if defined(CONFIG_BT_MESH_SAR_CFG_SRV)
77 BT_MESH_MODEL_SAR_CFG_SRV,
78 #endif
79 #if defined(CONFIG_BT_MESH_SAR_CFG_CLI)
80 BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli),
81 #endif
82
83 #if defined(CONFIG_BT_MESH_OP_AGG_SRV)
84 BT_MESH_MODEL_OP_AGG_SRV,
85 #endif
86 #if defined(CONFIG_BT_MESH_OP_AGG_CLI)
87 BT_MESH_MODEL_OP_AGG_CLI,
88 #endif
89
90 #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
91 BT_MESH_MODEL_LARGE_COMP_DATA_SRV,
92 #endif
93 #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI)
94 BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&large_comp_data_cli),
95 #endif
96
97 #if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
98 BT_MESH_MODEL_PRIV_BEACON_SRV,
99 #endif
100 #if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI)
101 BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli),
102 #endif
103 #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI)
104 BT_MESH_MODEL_OD_PRIV_PROXY_CLI(&od_priv_proxy_cli),
105 #endif
106 #if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI)
107 BT_MESH_MODEL_SOL_PDU_RPL_CLI(&srpl_cli),
108 #endif
109 #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV)
110 BT_MESH_MODEL_OD_PRIV_PROXY_SRV,
111 #endif
112 #if defined(CONFIG_BT_MESH_BRG_CFG_SRV)
113 BT_MESH_MODEL_BRG_CFG_SRV,
114 #endif
115 #if defined(CONFIG_BT_MESH_BRG_CFG_CLI)
116 BT_MESH_MODEL_BRG_CFG_CLI(&brg_cfg_cli),
117 #endif
118 };
119
120 static const struct bt_mesh_elem elements[] = {
121 BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE),
122 };
123
124 static const struct bt_mesh_comp comp = {
125 .cid = CONFIG_BT_COMPANY_ID,
126 .elem = elements,
127 .elem_count = ARRAY_SIZE(elements),
128 };
129
bt_ready(int err)130 static void bt_ready(int err)
131 {
132 if (err && err != -EALREADY) {
133 printk("Bluetooth init failed (err %d)\n", err);
134 return;
135 }
136
137 printk("Bluetooth initialized\n");
138
139 err = bt_mesh_init(&bt_mesh_shell_prov, &comp);
140 if (err) {
141 printk("Initializing mesh failed (err %d)\n", err);
142 return;
143 }
144
145 if (IS_ENABLED(CONFIG_SETTINGS)) {
146 settings_load();
147 }
148
149 printk("Mesh initialized\n");
150
151 if (bt_mesh_is_provisioned()) {
152 printk("Mesh network restored from flash\n");
153 } else {
154 printk("Use \"prov pb-adv on\" or \"prov pb-gatt on\" to "
155 "enable advertising\n");
156 }
157 }
158
main(void)159 int main(void)
160 {
161 int err;
162
163 printk("Initializing...\n");
164
165 /* Initialize the Bluetooth Subsystem */
166 err = bt_enable(bt_ready);
167 if (err && err != -EALREADY) {
168 printk("Bluetooth init failed (err %d)\n", err);
169 }
170
171 printk("Press the <Tab> button for supported commands.\n");
172 printk("Before any Mesh commands you must run \"mesh init\"\n");
173 return 0;
174 }
175