Bluetooth: samples: Use sizeof() to evaluate fixed name length

This way we avoid bugs coming from wrongly (human) counted length.

Change-Id: I95eb87a78fc12d4c5e083ce1c65d8b690ad8db78
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-01-30 13:36:02 +02:00 committed by Anas Nashif
parent 7d8303bbbf
commit bd0065b3bd
6 changed files with 9 additions and 6 deletions

View File

@ -24,6 +24,9 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#define DEVICE_NAME "Test beacon"
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
/* Set Advertisement data */
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0xd8, 0xfe),
@ -33,7 +36,7 @@ static const struct bt_data ad[] = {
/* Set Scan Response data */
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, "Test beacon", 11),
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
static void bt_ready(int err)

View File

@ -35,7 +35,7 @@
#include <net/net_socket.h>
#define DEVICE_NAME "Test IPSP node"
#define DEVICE_NAME_LEN 14
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define UNKNOWN_APPEARANCE 0x0000
/* The 2001:db8::/32 is the private address space for documentation RFC 3849 */

View File

@ -31,7 +31,7 @@
#include <bluetooth/gatt.h>
#define DEVICE_NAME "Test peripheral"
#define DEVICE_NAME_LEN 15
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define HEART_RATE_APPEARANCE 0x0341
static int read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,

View File

@ -31,7 +31,7 @@
#include <bluetooth/gatt.h>
#define DEVICE_NAME "DIS peripheral"
#define DEVICE_NAME_LEN 14
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define APPEARANCE 0x0000
static int read_appearance(struct bt_conn *conn,

View File

@ -31,7 +31,7 @@
#include <bluetooth/gatt.h>
#define DEVICE_NAME "SC only peripheral"
#define DEVICE_NAME_LEN 18
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define APPEARANCE 0x0000
static int read_appearance(struct bt_conn *conn,

View File

@ -38,7 +38,7 @@
#include <misc/shell.h>
#define DEVICE_NAME "test shell"
#define DEVICE_NAME_LEN 10
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define AD_SHORT_NAME 0x08
#define AD_COMPLETE_NAME 0x09
#define CREDITS 10