rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,74 @@
/** @file
* @brief BAS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#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 struct bt_gatt_ccc_cfg blvl_ccc_cfg[BT_GATT_CCC_MAX] = {};
static u8_t simulate_blvl;
static u8_t battery = 100;
static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr,
u16_t value)
{
simulate_blvl = (value == BT_GATT_CCC_NOTIFY) ? 1 : 0;
}
static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
{
const char *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
sizeof(*value));
}
/* Battery Service Declaration */
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY),
BT_GATT_DESCRIPTOR(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_PERM_READ,
read_blvl, NULL, &battery),
BT_GATT_CCC(blvl_ccc_cfg, blvl_ccc_cfg_changed),
};
static struct bt_gatt_service bas_svc = BT_GATT_SERVICE(attrs);
void bas_init(void)
{
bt_gatt_service_register(&bas_svc);
}
void bas_notify(void)
{
if (!simulate_blvl) {
return;
}
battery--;
if (!battery) {
/* Software eco battery charger */
battery = 100;
}
bt_gatt_notify(NULL, &attrs[2], &battery, sizeof(battery));
}

View file

@ -0,0 +1,20 @@
/** @file
* @brief BAS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void bas_init(void);
void bas_notify(void);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,115 @@
/** @file
* @brief CTS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#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 struct bt_gatt_ccc_cfg ct_ccc_cfg[BT_GATT_CCC_MAX] = {};
static u8_t ct[10];
static u8_t ct_update;
static void ct_ccc_cfg_changed(const struct bt_gatt_attr *attr, u16_t value)
{
/* TODO: Handle value */
}
static ssize_t read_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
{
const char *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
sizeof(ct));
}
static ssize_t write_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *buf, u16_t len, u16_t offset,
u8_t flags)
{
u8_t *value = attr->user_data;
if (offset + len > sizeof(ct)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}
memcpy(value + offset, buf, len);
ct_update = 1;
return len;
}
/* Current Time Service Declaration */
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(BT_UUID_CTS),
BT_GATT_CHARACTERISTIC(BT_UUID_CTS_CURRENT_TIME, BT_GATT_CHRC_READ |
BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE),
BT_GATT_DESCRIPTOR(BT_UUID_CTS_CURRENT_TIME,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_ct, write_ct, ct),
BT_GATT_CCC(ct_ccc_cfg, ct_ccc_cfg_changed),
};
static struct bt_gatt_service cts_svc = BT_GATT_SERVICE(attrs);
static void generate_current_time(u8_t *buf)
{
u16_t year;
/* 'Exact Time 256' contains 'Day Date Time' which contains
* 'Date Time' - characteristic contains fields for:
* year, month, day, hours, minutes and seconds.
*/
year = sys_cpu_to_le16(2015);
memcpy(buf, &year, 2); /* year */
buf[2] = 5; /* months starting from 1 */
buf[3] = 30; /* day */
buf[4] = 12; /* hours */
buf[5] = 45; /* minutes */
buf[6] = 30; /* seconds */
/* 'Day of Week' part of 'Day Date Time' */
buf[7] = 1; /* day of week starting from 1 */
/* 'Fractions 256 part of 'Exact Time 256' */
buf[8] = 0;
/* Adjust reason */
buf[9] = 0; /* No update, change, etc */
}
void cts_init(void)
{
/* Simulate current time for Current Time Service */
generate_current_time(ct);
bt_gatt_service_register(&cts_svc);
}
void cts_notify(void)
{ /* Current Time Service updates only when time is changed */
if (!ct_update) {
return;
}
ct_update = 0;
bt_gatt_notify(NULL, &attrs[3], &ct, sizeof(ct));
}

View file

@ -0,0 +1,20 @@
/** @file
* @brief CTS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void cts_init(void);
void cts_notify(void);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,64 @@
/** @file
* @brief DIS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#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,
u16_t len, u16_t offset)
{
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,
u16_t len, u16_t offset)
{
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),
};
static struct bt_gatt_service dis_svc = BT_GATT_SERVICE(attrs);
void dis_init(const char *model, const char *manuf)
{
dis_model = model;
dis_manuf = manuf;
bt_gatt_service_register(&dis_svc);
}

View file

@ -0,0 +1,19 @@
/** @file
* @brief DIS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void dis_init(const char *model, const char *manuf);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,170 @@
/** @file
* @brief HoG Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#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>
enum {
HIDS_REMOTE_WAKE = BIT(0),
HIDS_NORMALLY_CONNECTABLE = BIT(1),
};
struct hids_info {
u16_t version; /* version number of base USB HID Specification */
u8_t code; /* country HID Device hardware is localized for. */
u8_t flags;
} __packed;
struct hids_report {
u8_t id; /* report id */
u8_t type; /* report type */
} __packed;
static struct hids_info info = {
.version = 0x0000,
.code = 0x00,
.flags = HIDS_NORMALLY_CONNECTABLE,
};
enum {
HIDS_INPUT = 0x01,
HIDS_OUTPUT = 0x02,
HIDS_FEATURE = 0x03,
};
static struct hids_report input = {
.id = 0x01,
.type = HIDS_INPUT,
};
static struct bt_gatt_ccc_cfg input_ccc_cfg[BT_GATT_CCC_MAX] = {};
static u8_t simulate_input;
static u8_t ctrl_point;
static u8_t report_map[] = {
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x02, /* Usage (Mouse) */
0xA1, 0x01, /* Collection (Application) */
0x09, 0x01, /* Usage (Pointer) */
0xA1, 0x00, /* Collection (Physical) */
0x05, 0x09, /* Usage Page (Button) */
0x19, 0x01, /* Usage Minimum (0x01) */
0x29, 0x03, /* Usage Maximum (0x03) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x95, 0x03, /* Report Count (3) */
0x75, 0x01, /* Report Size (1) */
0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x05, /* Report Size (5) */
0x81, 0x03, /* Input (Const,Var,Abs,No Wrap,Linear,...) */
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x30, /* Usage (X) */
0x09, 0x31, /* Usage (Y) */
0x15, 0x81, /* Logical Minimum (129) */
0x25, 0x7F, /* Logical Maximum (127) */
0x75, 0x08, /* Report Size (8) */
0x95, 0x02, /* Report Count (2) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0xC0, /* End Collection */
0xC0, /* End Collection */
};
static ssize_t read_info(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset)
{
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data,
sizeof(struct hids_info));
}
static ssize_t read_report_map(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset)
{
return bt_gatt_attr_read(conn, attr, buf, len, offset, report_map,
sizeof(report_map));
}
static ssize_t read_report(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset)
{
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data,
sizeof(struct hids_report));
}
static void input_ccc_changed(const struct bt_gatt_attr *attr, u16_t value)
{
simulate_input = (value == BT_GATT_CCC_NOTIFY) ? 1 : 0;
}
static ssize_t read_input_report(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset)
{
return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0);
}
static ssize_t write_ctrl_point(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, u16_t len, u16_t offset,
u8_t flags)
{
u8_t *value = attr->user_data;
if (offset + len > sizeof(ctrl_point)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}
memcpy(value + offset, buf, len);
return len;
}
/* HID Service Declaration */
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(BT_UUID_HIDS),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_INFO, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_INFO, BT_GATT_PERM_READ,
read_info, NULL, &info),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT_MAP, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_MAP, BT_GATT_PERM_READ,
read_report_map, NULL, NULL),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT, BT_GATT_PERM_READ_AUTHEN,
read_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_cfg, input_ccc_changed),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ,
read_report, NULL, &input),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_CTRL_POINT,
BT_GATT_CHRC_WRITE_WITHOUT_RESP),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_CTRL_POINT, BT_GATT_PERM_WRITE,
NULL, write_ctrl_point, &ctrl_point),
};
static struct bt_gatt_service hog_svc = BT_GATT_SERVICE(attrs);
void hog_init(void)
{
bt_gatt_service_register(&hog_svc);
}

View file

@ -0,0 +1,19 @@
/** @file
* @brief HoG Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void hog_init(void);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,86 @@
/** @file
* @brief HRS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#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 struct bt_gatt_ccc_cfg hrmc_ccc_cfg[BT_GATT_CCC_MAX] = {};
static u8_t simulate_hrm;
static u8_t heartrate = 90;
static u8_t hrs_blsc;
static void hrmc_ccc_cfg_changed(const struct bt_gatt_attr *attr,
u16_t value)
{
simulate_hrm = (value == BT_GATT_CCC_NOTIFY) ? 1 : 0;
}
static ssize_t read_blsc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
{
return bt_gatt_attr_read(conn, attr, buf, len, offset, &hrs_blsc,
sizeof(hrs_blsc));
}
/* Heart Rate Service Declaration */
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(BT_UUID_HRS),
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_MEASUREMENT, BT_GATT_CHRC_NOTIFY),
BT_GATT_DESCRIPTOR(BT_UUID_HRS_MEASUREMENT, BT_GATT_PERM_READ, NULL,
NULL, NULL),
BT_GATT_CCC(hrmc_ccc_cfg, hrmc_ccc_cfg_changed),
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_BODY_SENSOR, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_HRS_BODY_SENSOR, BT_GATT_PERM_READ,
read_blsc, NULL, NULL),
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_CONTROL_POINT, BT_GATT_CHRC_WRITE),
/* TODO: Add write permission and callback */
BT_GATT_DESCRIPTOR(BT_UUID_HRS_CONTROL_POINT, BT_GATT_PERM_READ, NULL,
NULL, NULL),
};
static struct bt_gatt_service hrs_svc = BT_GATT_SERVICE(attrs);
void hrs_init(u8_t blsc)
{
hrs_blsc = blsc;
bt_gatt_service_register(&hrs_svc);
}
void hrs_notify(void)
{
static u8_t hrm[2];
/* Heartrate measurements simulation */
if (!simulate_hrm) {
return;
}
heartrate++;
if (heartrate == 160) {
heartrate = 90;
}
hrm[0] = 0x06; /* uint8, sensor contact */
hrm[1] = heartrate;
bt_gatt_notify(NULL, &attrs[2], &hrm, sizeof(hrm));
}

View file

@ -0,0 +1,20 @@
/** @file
* @brief HRS Service sample
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void hrs_init(u8_t blsc);
void hrs_notify(void);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,82 @@
/** @file
* @brief IP Support Service sample
*/
/*
* 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 <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>
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define UNKNOWN_APPEARANCE 0x0000
static struct bt_gatt_attr attrs[] = {
/* IP Support Service Declaration */
BT_GATT_PRIMARY_SERVICE(BT_UUID_IPSS),
};
static struct bt_gatt_service ipss_svc = BT_GATT_SERVICE(attrs);
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, 0x20, 0x18),
};
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
static void connected(struct bt_conn *conn, u8_t err)
{
if (err) {
printk("Connection failed (err %u)\n", err);
} else {
printk("Connected\n");
}
}
static void disconnected(struct bt_conn *conn, u8_t reason)
{
printk("Disconnected (reason %u)\n", reason);
}
static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
};
void ipss_init(void)
{
bt_gatt_service_register(&ipss_svc);
bt_conn_cb_register(&conn_callbacks);
}
int ipss_advertise(void)
{
int err;
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
if (err) {
return err;
}
return 0;
}

View file

@ -0,0 +1,20 @@
/** @file
* @brief IPSP Service sample
*/
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef __cplusplus
extern "C" {
#endif
void ipss_init(void);
int ipss_advertise(void);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,7 @@
NAME := profile
$(NAME)_MBINS_TYPE := kernel
$(NAME)_SOURCES := bas.c cts.c cts.h dis.c hrs.c
GLOBAL_INCLUDES += .