2016-03-16 22:04:26 +08:00
|
|
|
/** @file
|
|
|
|
* @brief DIS Service sample
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-03-16 22:04:26 +08:00
|
|
|
*/
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-03-16 22:04:26 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <misc/printk.h>
|
|
|
|
#include <misc/byteorder.h>
|
|
|
|
#include <zephyr.h>
|
|
|
|
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
#include <bluetooth/conn.h>
|
|
|
|
#include <bluetooth/uuid.h>
|
|
|
|
#include <bluetooth/gatt.h>
|
|
|
|
|
|
|
|
static const char *dis_model;
|
|
|
|
static const char *dis_manuf;
|
|
|
|
|
|
|
|
static ssize_t read_model(struct bt_conn *conn,
|
|
|
|
const struct bt_gatt_attr *attr, void *buf,
|
2017-04-21 22:47:21 +08:00
|
|
|
u16_t len, u16_t offset)
|
2016-03-16 22:04:26 +08:00
|
|
|
{
|
|
|
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, dis_model,
|
|
|
|
strlen(dis_model));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t read_manuf(struct bt_conn *conn,
|
|
|
|
const struct bt_gatt_attr *attr, void *buf,
|
2017-04-21 22:47:21 +08:00
|
|
|
u16_t len, u16_t offset)
|
2016-03-16 22:04:26 +08:00
|
|
|
{
|
|
|
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, dis_manuf,
|
|
|
|
strlen(dis_manuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Device Information Service Declaration */
|
|
|
|
static struct bt_gatt_attr attrs[] = {
|
|
|
|
BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS),
|
|
|
|
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_CHRC_READ),
|
|
|
|
BT_GATT_DESCRIPTOR(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_PERM_READ,
|
|
|
|
read_model, NULL, NULL),
|
|
|
|
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME,
|
|
|
|
BT_GATT_CHRC_READ),
|
|
|
|
BT_GATT_DESCRIPTOR(BT_UUID_DIS_MANUFACTURER_NAME, BT_GATT_PERM_READ,
|
|
|
|
read_manuf, NULL, NULL),
|
|
|
|
};
|
|
|
|
|
2017-06-12 05:26:19 +08:00
|
|
|
static struct bt_gatt_service dis_svc = BT_GATT_SERVICE(attrs);
|
|
|
|
|
2016-03-16 22:04:26 +08:00
|
|
|
void dis_init(const char *model, const char *manuf)
|
|
|
|
{
|
|
|
|
dis_model = model;
|
|
|
|
dis_manuf = manuf;
|
|
|
|
|
2017-06-12 05:26:19 +08:00
|
|
|
bt_gatt_service_register(&dis_svc);
|
2016-03-16 22:04:26 +08:00
|
|
|
}
|