/* main.c - Application main entry point */ /* * Copyright (c) 2015-2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include #include #include #include #include #include #include #include #include #include #include static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)), }; static const struct bt_data sd[] = { BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; static void connected(struct bt_conn *conn, uint8_t err) { if (err) { printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err)); } else { printk("Connected\n"); } } static void disconnected(struct bt_conn *conn, uint8_t reason) { printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason)); } BT_CONN_CB_DEFINE(conn_callbacks) = { .connected = connected, .disconnected = disconnected, }; static int settings_runtime_load(void) { #if defined(CONFIG_BT_DIS_SETTINGS) settings_runtime_set("bt/dis/model", "Zephyr Model", sizeof("Zephyr Model")); settings_runtime_set("bt/dis/manuf", "Zephyr Manufacturer", sizeof("Zephyr Manufacturer")); #if defined(CONFIG_BT_DIS_SERIAL_NUMBER) settings_runtime_set("bt/dis/serial", CONFIG_BT_DIS_SERIAL_NUMBER_STR, sizeof(CONFIG_BT_DIS_SERIAL_NUMBER_STR)); #endif #if defined(CONFIG_BT_DIS_SW_REV) settings_runtime_set("bt/dis/sw", CONFIG_BT_DIS_SW_REV_STR, sizeof(CONFIG_BT_DIS_SW_REV_STR)); #endif #if defined(CONFIG_BT_DIS_FW_REV) settings_runtime_set("bt/dis/fw", CONFIG_BT_DIS_FW_REV_STR, sizeof(CONFIG_BT_DIS_FW_REV_STR)); #endif #if defined(CONFIG_BT_DIS_HW_REV) settings_runtime_set("bt/dis/hw", CONFIG_BT_DIS_HW_REV_STR, sizeof(CONFIG_BT_DIS_HW_REV_STR)); #endif #endif return 0; } int main(void) { int err; err = bt_enable(NULL); if (err) { printk("Bluetooth init failed (err %d)\n", err); return 0; } if (IS_ENABLED(CONFIG_BT_SETTINGS)) { settings_load(); } settings_runtime_load(); printk("Bluetooth initialized\n"); err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return 0; } printk("Advertising successfully started\n"); return 0; }