The host-based adv auto-resume function has both a problematic implementation and disagreement in the community around how it should behave. See the issue linked resolved below for details. This patch makes the deprecation visible to the user. The user will be better served by a auto-resume tailored their applications use case, based on more primitive host API like `conn_cb.recycled`, which has obvious behavior that is unlikely to change. Resolves: https://github.com/zephyrproject-rtos/zephyr/issues/72567 Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
112 lines
2.7 KiB
C
112 lines
2.7 KiB
C
/* main.c - Application main entry point */
|
|
|
|
/*
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr/types.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <zephyr/sys/printk.h>
|
|
#include <zephyr/sys/byteorder.h>
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
#include <zephyr/bluetooth/hci.h>
|
|
#include <zephyr/bluetooth/conn.h>
|
|
#include <zephyr/bluetooth/uuid.h>
|
|
#include <zephyr/bluetooth/gatt.h>
|
|
#include <zephyr/settings/settings.h>
|
|
|
|
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;
|
|
}
|