Bluetooth: host: Device name handling of invalid length
Add a build assert if the device name has been misconfigured. The device name has a max length of 248. When configured as dynamic make sure that the initial device length can fit in the dynamic max length. This prevents us from having to handle length overflow when setting device name in advertising data which has an 8-bit length field. Log a warning if failing to set the device name in bt_enable. Remove unused defines in the shell. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
8672976120
commit
d76bba4b5e
2 changed files with 11 additions and 4 deletions
|
@ -3541,7 +3541,10 @@ int bt_enable(bt_ready_cb_t cb)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bt_set_name(CONFIG_BT_DEVICE_NAME);
|
err = bt_set_name(CONFIG_BT_DEVICE_NAME);
|
||||||
|
if (err) {
|
||||||
|
BT_WARN("Failed to set device name (%d)", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ready_cb = cb;
|
ready_cb = cb;
|
||||||
|
@ -3584,6 +3587,13 @@ int bt_enable(bt_ready_cb_t cb)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DEVICE_NAME_LEN (sizeof(CONFIG_BT_DEVICE_NAME) - 1)
|
||||||
|
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
||||||
|
BUILD_ASSERT(DEVICE_NAME_LEN < CONFIG_BT_DEVICE_NAME_MAX);
|
||||||
|
#else
|
||||||
|
BUILD_ASSERT(DEVICE_NAME_LEN < 248);
|
||||||
|
#endif
|
||||||
|
|
||||||
int bt_set_name(const char *name)
|
int bt_set_name(const char *name)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
#if defined(CONFIG_BT_DEVICE_NAME_DYNAMIC)
|
||||||
|
|
|
@ -36,9 +36,6 @@
|
||||||
#include "ll.h"
|
#include "ll.h"
|
||||||
#include "hci.h"
|
#include "hci.h"
|
||||||
|
|
||||||
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
|
|
||||||
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
|
||||||
|
|
||||||
/* Multiply bt 1.25 to get MS */
|
/* Multiply bt 1.25 to get MS */
|
||||||
#define BT_INTERVAL_TO_MS(interval) ((interval) * 5 / 4)
|
#define BT_INTERVAL_TO_MS(interval) ((interval) * 5 / 4)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue