| /* main.c - Application main entry point */ |
| |
| /* |
| * Copyright (c) 2017 Intel Corporation |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| #include <sys/printk.h> |
| |
| #include <settings/settings.h> |
| |
| #include <bluetooth/bluetooth.h> |
| #include <bluetooth/mesh.h> |
| |
| #include "board.h" |
| |
| static struct bt_mesh_health_srv health_srv = { |
| }; |
| |
| BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0); |
| |
| static struct bt_mesh_model_pub gen_level_pub; |
| static struct bt_mesh_model_pub gen_onoff_pub; |
| |
| static void gen_onoff_get(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_onoff_set(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_onoff_set_unack(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static const struct bt_mesh_model_op gen_onoff_op[] = { |
| { BT_MESH_MODEL_OP_2(0x82, 0x01), 0, gen_onoff_get }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x02), 2, gen_onoff_set }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x03), 2, gen_onoff_set_unack }, |
| BT_MESH_MODEL_OP_END, |
| }; |
| |
| static void gen_level_get(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_level_set(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_level_set_unack(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_delta_set(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_delta_set_unack(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_move_set(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static void gen_move_set_unack(struct bt_mesh_model *model, |
| struct bt_mesh_msg_ctx *ctx, |
| struct net_buf_simple *buf) |
| { |
| } |
| |
| static const struct bt_mesh_model_op gen_level_op[] = { |
| { BT_MESH_MODEL_OP_2(0x82, 0x05), 0, gen_level_get }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x06), 3, gen_level_set }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x07), 3, gen_level_set_unack }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x09), 5, gen_delta_set }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x0a), 5, gen_delta_set_unack }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x0b), 3, gen_move_set }, |
| { BT_MESH_MODEL_OP_2(0x82, 0x0c), 3, gen_move_set_unack }, |
| BT_MESH_MODEL_OP_END, |
| }; |
| |
| static struct bt_mesh_model root_models[] = { |
| BT_MESH_MODEL_CFG_SRV, |
| BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), |
| BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_SRV, gen_onoff_op, |
| &gen_onoff_pub, NULL), |
| BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_LEVEL_SRV, gen_level_op, |
| &gen_level_pub, NULL), |
| }; |
| |
| static struct bt_mesh_elem elements[] = { |
| BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE), |
| }; |
| |
| static const struct bt_mesh_comp comp = { |
| .cid = BT_COMP_ID_LF, |
| .elem = elements, |
| .elem_count = ARRAY_SIZE(elements), |
| }; |
| |
| static int output_number(bt_mesh_output_action_t action, uint32_t number) |
| { |
| printk("OOB Number: %u\n", number); |
| |
| board_output_number(action, number); |
| |
| return 0; |
| } |
| |
| static void prov_complete(uint16_t net_idx, uint16_t addr) |
| { |
| board_prov_complete(); |
| } |
| |
| static void prov_reset(void) |
| { |
| bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); |
| } |
| |
| static const uint8_t dev_uuid[16] = { 0xdd, 0xdd }; |
| |
| static const struct bt_mesh_prov prov = { |
| .uuid = dev_uuid, |
| .output_size = 4, |
| .output_actions = BT_MESH_DISPLAY_NUMBER, |
| .output_number = output_number, |
| .complete = prov_complete, |
| .reset = prov_reset, |
| }; |
| |
| static void bt_ready(int err) |
| { |
| if (err) { |
| printk("Bluetooth init failed (err %d)\n", err); |
| return; |
| } |
| |
| printk("Bluetooth initialized\n"); |
| |
| board_init(); |
| |
| err = bt_mesh_init(&prov, &comp); |
| if (err) { |
| printk("Initializing mesh failed (err %d)\n", err); |
| return; |
| } |
| |
| if (IS_ENABLED(CONFIG_SETTINGS)) { |
| settings_load(); |
| } |
| |
| /* This will be a no-op if settings_load() loaded provisioning info */ |
| bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); |
| |
| printk("Mesh initialized\n"); |
| } |
| |
| void main(void) |
| { |
| int err; |
| |
| printk("Initializing...\n"); |
| |
| /* Initialize the Bluetooth Subsystem */ |
| err = bt_enable(bt_ready); |
| if (err) { |
| printk("Bluetooth init failed (err %d)\n", err); |
| } |
| } |