summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2016-09-16 14:27:15 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2016-10-04 08:12:14 +0300
commitc4fb8f88208e5c4dd522fc35992f73e63f1a94c1 (patch)
tree72e888a800d332b4caf1c217e798a09a53e98001 /samples
parent51c146b95b24b4ea6a2e01c5e4e1cb25feb40c7b (diff)
Bluetooth: eddystone: Add missing characteristics
This adds last 2 missing characteristics: (Advanced) Factory reset - a3c8750b-8ed3-4bdf-8a39-a01bebede295 (Advanced) Remain Connectable - a3c8750c-8ed3-4bdf-8a39-a01bebede295 Change-Id: I749b4be65469080a24957805d40395563a74a972 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/bluetooth/eddystone/src/main.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/samples/bluetooth/eddystone/src/main.c b/samples/bluetooth/eddystone/src/main.c
index ab03e1bfa..c1a4da226 100644
--- a/samples/bluetooth/eddystone/src/main.c
+++ b/samples/bluetooth/eddystone/src/main.c
@@ -112,6 +112,16 @@ static struct bt_uuid_128 eds_data_uuid = BT_UUID_INIT_128(
0x95, 0xe2, 0xed, 0xeb, 0x1b, 0xa0, 0x39, 0x8a,
0xdf, 0x4b, 0xd3, 0x8e, 0x0a, 0x75, 0xc8, 0xa3);
+/* Characteristic UUID a3c8750b-8ed3-4bdf-8a39-a01bebede295 */
+static struct bt_uuid_128 eds_reset_uuid = BT_UUID_INIT_128(
+ 0x95, 0xe2, 0xed, 0xeb, 0x1b, 0xa0, 0x39, 0x8a,
+ 0xdf, 0x4b, 0xd3, 0x8e, 0x0b, 0x75, 0xc8, 0xa3);
+
+/* Characteristic UUID a3c8750c-8ed3-4bdf-8a39-a01bebede295 */
+static struct bt_uuid_128 eds_connectable_uuid = BT_UUID_INIT_128(
+ 0x95, 0xe2, 0xed, 0xeb, 0x1b, 0xa0, 0x39, 0x8a,
+ 0xdf, 0x4b, 0xd3, 0x8e, 0x0c, 0x75, 0xc8, 0xa3);
+
enum {
EDS_TYPE_UID = 0x00,
EDS_TYPE_URL = 0x10,
@@ -153,6 +163,7 @@ enum {
struct eds_slot {
uint8_t type;
uint8_t state;
+ uint8_t connectable;
uint16_t interval;
uint8_t tx_power;
uint8_t adv_tx_power;
@@ -518,6 +529,55 @@ static ssize_t write_adv_data(struct bt_conn *conn,
}
}
+static ssize_t write_reset(struct bt_conn *conn,
+ const struct bt_gatt_attr *attr,
+ const void *buf, uint16_t len, uint16_t offset,
+ uint8_t flags)
+{
+ /* TODO: Power cycle or reload for storage the values */
+ return BT_GATT_ERR(BT_ATT_ERR_WRITE_NOT_PERMITTED);
+}
+
+static ssize_t read_connectable(struct bt_conn *conn,
+ const struct bt_gatt_attr *attr, void *buf,
+ uint16_t len, uint16_t offset)
+{
+ uint8_t connectable = 0x01;
+
+ /* Returning a non-zero value indicates that the beacon is capable
+ * of becoming non-connectable
+ */
+ return bt_gatt_attr_read(conn, attr, buf, len, offset,
+ &connectable, sizeof(connectable));
+}
+
+static ssize_t write_connectable(struct bt_conn *conn,
+ const struct bt_gatt_attr *attr,
+ const void *buf, uint16_t len, uint16_t offset,
+ uint8_t flags)
+{
+ struct eds_slot *slot = &eds_slots[eds_active_slot];
+
+ if (slot->state == EDS_LOCKED) {
+ return BT_GATT_ERR(BT_ATT_ERR_WRITE_NOT_PERMITTED);
+ }
+
+ if (offset) {
+ return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
+ }
+
+ if (len > sizeof(slot->connectable)) {
+ return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
+ }
+
+ /* If any non-zero value is written, the beacon shall remain in its
+ * connectable state until any other value is written.
+ */
+ memcpy(&slot->connectable, buf, len);
+
+ return len;
+}
+
/* Eddystone Configuration Service Declaration */
static struct bt_gatt_attr eds_attrs[] = {
BT_GATT_PRIMARY_SERVICE(&eds_uuid),
@@ -587,6 +647,19 @@ static struct bt_gatt_attr eds_attrs[] = {
BT_GATT_DESCRIPTOR(&eds_eid_uuid.uuid,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_adv_data, write_adv_data, NULL),
+ /* ADV Factory Reset */
+ BT_GATT_CHARACTERISTIC(&eds_reset_uuid.uuid, BT_GATT_CHRC_WRITE),
+ /* Must be unlocked write. */
+ BT_GATT_DESCRIPTOR(&eds_reset_uuid.uuid,
+ BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
+ NULL, write_reset, NULL),
+ /* ADV Remain Connectable */
+ BT_GATT_CHARACTERISTIC(&eds_connectable_uuid.uuid,
+ BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE),
+ /* Must be unlocked for write. */
+ BT_GATT_DESCRIPTOR(&eds_connectable_uuid.uuid,
+ BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
+ read_connectable, write_connectable, NULL),
};
static void bt_ready(int err)
@@ -633,7 +706,13 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
+ struct eds_slot *slot = &eds_slots[eds_active_slot];
+
printk("Disconnected (reason %u)\n", reason);
+
+ if (!slot->connectable) {
+ nano_delayed_work_submit(&idle_work, 0);
+ }
}
static struct bt_conn_cb conn_callbacks = {