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,200 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <aos/aos.h>
#include <stdio.h>
#include <ali_common.h>
#include <bluetooth/gatt.h>
#include <bluetooth/conn.h>
#include <api_export.h>
#include <dis.h>
#ifdef AOS_BINS
#include "hal/soc/uart.h"
uart_dev_t uart_0;
#endif
#define MODEL_ID 0x3126 /* Model ID, obtained from Ali-Cloud. */
#define SOFTWARE_VERSION "0.2.0" /* Version number defined by user. Must be in format "%d.%d.%d". */
#define SOFTWARE_VERSION_LEN 5
extern uint32_t *fetch_ali_context();
uint8_t const m_secret[40] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; /* Todo: add correct secret here! */
static uint8_t m_addr[BD_ADDR_LEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; /* Todo: add correct address here! */
#define MOD "aisapp"
#define DEVICE_MANUFACURE_NAME "AliOSThings"
#define DEVICE_MODEL_NUM "AIS"
static uint8_t sys_id[] = {0x12, 0x34};
static struct bt_data ad[3] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x0a, 0x18),
};
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, \
sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};
static void advertising_start(void)
{
int err;
uint32_t err_code;
uint8_t manuf_spec_data_raw[16] = {0};
uint16_t length = sizeof(manuf_spec_data_raw);
uint32_t *ctx = fetch_ali_context();
err_code = ali_get_manuf_spec_adv_data(ctx,
manuf_spec_data_raw,
&length);
if (err_code) {
LOGE(MOD, "ali_get_manuf_spec_adv_data failed (err: %d)", err_code);
return;
}
ad[2].type = 0xFF;
ad[2].data_len = length;
ad[2].data = manuf_spec_data_raw;
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
if (err) {
LOGE(MOD, "Advertising failed to start (err %d)\n", err);
return;
}
}
/* @brief Event handler for Ali-SDK. */
static void dev_status_changed_handler(alink_event_t event)
{
switch (event)
{
case CONNECTED:
LOGI(MOD, "dev_status_changed(): Connected.");
break;
case DISCONNECTED:
LOGI(MOD, "dev_status_changed(): Disconnected.");
break;
case AUTHENTICATED:
LOGI(MOD, "dev_status_changed(): Authenticated.");
break;
case TX_DONE:
LOGI(MOD, "dev_status_changed(): Tx-done.");
break;
default:
break;
}
}
/* @brief Data handler for query command 0x00. */
static void set_dev_status_handler(uint8_t * buffer, uint32_t length)
{
/* Flip one of the bits and then echo. */
buffer[length-1] ^= 1;
alink_post_fast(buffer, length);
}
/* @brief Data handler for control command 0x02. */
static void get_dev_status_handler(uint8_t * buffer, uint32_t length)
{
/* Flip one of the bits and then echo. */
buffer[length-1] ^= 2;
alink_post(buffer, length);
}
static void get_bd_addr(uint8_t *addr)
{
int err;
bt_addr_le_t laddr;
err = ais_ota_get_local_addr(&laddr);
if (err != 0) {
LOGE(MOD, "Failed to get local addr, default will be used.");
memcpy(addr, m_addr, BD_ADDR_LEN);
} else {
memcpy(addr, laddr.a.val, BD_ADDR_LEN);
LOGD(MOD, "Local addr got (%02x:%02x:%02x:%02x:%02x:%02x).",
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
}
}
static void ali_lib_init(void)
{
bool ret;
uint32_t err_code;
struct device_config init_alink;
uint8_t bd_addr[BD_ADDR_LEN] = {0};
get_bd_addr(bd_addr);
memset(&init_alink, 0, sizeof(struct device_config));
init_alink.product_id = 127678;
init_alink.status_changed_cb = dev_status_changed_handler;
init_alink.set_cb = set_dev_status_handler;
init_alink.get_cb = get_dev_status_handler;
#ifdef CONFIG_AIS_OTA
init_alink.enable_ota = true;
#endif
init_alink.enable_auth = true;
init_alink.auth_type = ALI_AUTH_BY_PRODUCT_SECRET;
memcpy(init_alink.bd_addr, bd_addr, BD_ADDR_LEN);
init_alink.device_secret_len = strlen("gjeRzfwWcMg8Rw036OjsPEreGPDMl1wI");
memcpy(init_alink.device_secret, "gjeRzfwWcMg8Rw036OjsPEreGPDMl1wI", init_alink.device_secret_len);
init_alink.product_key_len = strlen("a13wpkvcQDQ");
memcpy(init_alink.product_key, "a13wpkvcQDQ", init_alink.product_key_len);
init_alink.device_key_len = strlen("mSLKAvSYdQz5JsshCyTE");
memcpy(init_alink.device_name, "mSLKAvSYdQz5JsshCyTE", init_alink.device_key_len);
memcpy(init_alink.version, SOFTWARE_VERSION, SOFTWARE_VERSION_LEN);
ret = alink_start(&init_alink);
if (ret != 0) LOGE(MOD, "alink_start failed.\r\n");
else printf("alink_start succeed.\r\n");
}
static void bt_ready(int err)
{
ali_lib_init();
printf("ali_lib_init finished.\n");
dis_init(DEVICE_MODEL_NUM, DEVICE_MANUFACURE_NAME);
printf("dis_init succeed.\n");
advertising_start();
printf("advertising_start succeed.\n");
}
extern int hci_driver_init();
static void app_delayed_action(void *arg)
{
int err;
(void *)arg;
hci_driver_init();
ais_ota_bt_storage_init();
err = bt_enable(bt_ready);
if (err) {
printf("Bluetooth init failed (err %d)\n", err);
return;
}
printf("Bluetooth init succeed.\n");
}
int application_start( void )
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,130 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <ble_app_framework.h>
#include <aos/aos.h>
static int connection_handler()
{
}
static int disconnection_handler()
{
}
typedef enum {
HDLS_GENERIC_ATTRIBUTE = 0x1,
HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED,
HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED_VALUE,
HDLS_GENERIC_ACCESS = 0x14,
HDLC_GENERIC_ACCESS_DEVICE_NAME,
HDLC_GENERIC_ACCESS_DEVICE_NAME_VALUE,
HDLC_GENERIC_ACCESS_APPEARANCE,
HDLC_GENERIC_ACCESS_APPEARANCE_VALUE,
HDLS_DEV_INFO = 0x50,
HDLC_DEV_INFO_MFR_NAME,
HDLC_DEV_INFO_MFR_NAME_VALUE,
HDLC_DEV_INFO_MODEL_NUM,
HDLC_DEV_INFO_MODEL_NUM_VALUE,
HDLC_DEV_INFO_SYSTEM_ID,
HDLC_DEV_INFO_SYSTEM_ID_VALUE,
} adv_db_tags;
static const uint8_t adv_gatt_db[] = {
/* Declare mandatory GATT service */
PRIMARY_SERVICE_UUID16( HDLS_GENERIC_ATTRIBUTE, UUID_SERVCLASS_GATT_SERVER ),
CHARACTERISTIC_UUID16( HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED,
HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED_VALUE,
GATT_UUID_GATT_SRV_CHGD,
LEGATTDB_CHAR_PROP_INDICATE,
LEGATTDB_PERM_NONE ),
/* Declare mandatory GAP service. Device Name and Appearance are mandatory
* characteristics of GAP service */
PRIMARY_SERVICE_UUID16( HDLS_GENERIC_ACCESS,
UUID_SERVCLASS_GAP_SERVER ),
/* Declare mandatory GAP service characteristic: Dev Name */
CHARACTERISTIC_UUID16(
HDLC_GENERIC_ACCESS_DEVICE_NAME,
HDLC_GENERIC_ACCESS_DEVICE_NAME_VALUE,
GATT_UUID_GAP_DEVICE_NAME,
LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE ),
/* Declare mandatory GAP service characteristic: Appearance */
CHARACTERISTIC_UUID16( HDLC_GENERIC_ACCESS_APPEARANCE,
HDLC_GENERIC_ACCESS_APPEARANCE_VALUE,
GATT_UUID_GAP_ICON,
LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE ),
/* Declare Device info service */
PRIMARY_SERVICE_UUID16( HDLS_DEV_INFO,
UUID_SERVCLASS_DEVICE_INFO ),
/* Handle 0x4e: characteristic Manufacturer Name */
CHARACTERISTIC_UUID16( HDLC_DEV_INFO_MFR_NAME,
HDLC_DEV_INFO_MFR_NAME_VALUE,
GATT_UUID_MANU_NAME,
LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE ),
/* Handle 0x50: characteristic Model Number */
CHARACTERISTIC_UUID16( HDLC_DEV_INFO_MODEL_NUM,
HDLC_DEV_INFO_MODEL_NUM_VALUE,
GATT_UUID_MODEL_NUMBER_STR,
LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE ),
/* Handle 0x52: characteristic System ID */
CHARACTERISTIC_UUID16( HDLC_DEV_INFO_SYSTEM_ID,
HDLC_DEV_INFO_SYSTEM_ID_VALUE,
GATT_UUID_SYSTEM_ID,
LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE ),
};
static int adv_complete_cb(void *arg)
{
}
#define DEVICE_MANUFACURE_NAME "BleAdvertisementsSampleManufacture"
#define DEVICE_MODEL_NUM "BleAdvertismentsSampleDeviceModel"
static uint8_t sys_id[] = {0x12, 0x34};
static void app_delayed_action(void *arg)
{
peripheral_hdl_t hdl;
peripheral_init_t p = {CONFIG_BT_DEVICE_NAME, 0, 1};
hdl = ble_peripheral_init(&p, connection_handler, disconnection_handler,
adv_gatt_db, sizeof(adv_gatt_db));
ble_adv_start(adv_complete_cb, DEVICE_MANUFACURE_NAME, hdl);
ble_attr_add(HDLC_DEV_INFO_MFR_NAME_VALUE,
sizeof(DEVICE_MANUFACURE_NAME) - 1, DEVICE_MANUFACURE_NAME);
ble_attr_add(HDLC_DEV_INFO_MODEL_NUM_VALUE,
sizeof(DEVICE_MODEL_NUM) - 1, DEVICE_MODEL_NUM);
ble_attr_add(HDLC_DEV_INFO_SYSTEM_ID_VALUE, sizeof(sys_id),
(const uint8_t *)&sys_id);
}
int application_start( void )
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,9 @@
NAME := ble_Advertisements
$(NAME)_SOURCES := ble_advertisements.c
ble = 1
$(NAME)_COMPONENTS := bluetooth.ble_app_framework yloop
GLOBAL_CFLAGS += -DCONFIG_BT_DEVICE_NAME=\"AosBleAdvertisementsSampleDevice\"

View file

@ -0,0 +1,173 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <aos/aos.h>
#include <ble_app_framework.h>
static int connection_handler()
{
LOG("Hello %s", __func__);
}
static int disconnection_handler()
{
LOG("Hello %s", __func__);
}
/* UUID value of the TIME Service */
#define UUID_TIME_SERVICE 0x5E, 0x67, 0x21, 0x8A, 0x3f, 0x4b, 0x4D, 0x32, 0x91, 0x36, 0x38, 0xE3, 0xD8, 0xED, 0x63, 0x71
/* UUID value of the TIME Characteristic, Data OUT */
#define UUID_TIME_SERVICE_CHARACTERISTIC_OUT 0x32, 0x15, 0x1a, 0x5e, 0x82, 0x2e, 0x12, 0x2a, 0x91, 0x43, 0x27, 0x52, 0xba, 0x1d, 0xf3, 0x30
typedef enum {
HDLS_GENERIC_ATTRIBUTE = 0x1,
HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED,
HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED_VALUE,
HDLS_GENERIC_ACCESS = 0x14,
HDLC_GENERIC_ACCESS_DEVICE_NAME,
HDLC_GENERIC_ACCESS_DEVICE_NAME_VALUE,
HDLC_GENERIC_ACCESS_APPEARANCE,
HDLC_GENERIC_ACCESS_APPEARANCE_VALUE,
HDLS_TIME = 0x40,
HDLC_TIME_OUT,
HDLC_TIME_OUT_VALUE,
HDLC_TIME_OUT_CCC,
HDLC_TIME_OUT_DESCRIPTION,
HDLS_DEV_INFO = 0x50,
HDLC_DEV_INFO_MFR_NAME,
HDLC_DEV_INFO_MFR_NAME_VALUE,
HDLC_DEV_INFO_MODEL_NUM,
HDLC_DEV_INFO_MODEL_NUM_VALUE,
HDLC_DEV_INFO_SYSTEM_ID,
HDLC_DEV_INFO_SYSTEM_ID_VALUE,
} adv_db_tags;
static const uint8_t adv_gatt_db[] = {
/* Declare mandatory GATT service */
PRIMARY_SERVICE_UUID16( HDLS_GENERIC_ATTRIBUTE, UUID_SERVCLASS_GATT_SERVER ),
CHARACTERISTIC_UUID16( HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED,
HDLC_GENERIC_ATTRIBUTE_SERVICE_CHANGED_VALUE,
GATT_UUID_GATT_SRV_CHGD,
LEGATTDB_CHAR_PROP_INDICATE,
LEGATTDB_PERM_NONE ),
/* Declare mandatory GAP service. Device Name and Appearance are mandatory
* characteristics of GAP service */
PRIMARY_SERVICE_UUID16( HDLS_GENERIC_ACCESS, UUID_SERVCLASS_GAP_SERVER ),
/* Declare mandatory GAP service characteristic: Dev Name */
CHARACTERISTIC_UUID16( HDLC_GENERIC_ACCESS_DEVICE_NAME, HDLC_GENERIC_ACCESS_DEVICE_NAME_VALUE,
GATT_UUID_GAP_DEVICE_NAME,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE ),
/* Declare mandatory GAP service characteristic: Appearance */
CHARACTERISTIC_UUID16( HDLC_GENERIC_ACCESS_APPEARANCE, HDLC_GENERIC_ACCESS_APPEARANCE_VALUE,
GATT_UUID_GAP_ICON,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE ),
// /* Declare TIME Service with 128 byte UUID */
PRIMARY_SERVICE_UUID128( HDLS_TIME, UUID_TIME_SERVICE ),
/* Declare characteristic used to send time data to client */
CHARACTERISTIC_UUID128( HDLC_TIME_OUT, HDLC_TIME_OUT_VALUE,
UUID_TIME_SERVICE_CHARACTERISTIC_OUT,
LEGATTDB_CHAR_PROP_INDICATE | LEGATTDB_CHAR_PROP_NOTIFY, LEGATTDB_PERM_NONE ),
CHAR_DESCRIPTOR_UUID16_WRITABLE( HDLC_TIME_OUT_CCC, GATT_UUID_CHAR_CLIENT_CONFIG,
LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ ),
CHAR_DESCRIPTOR_UUID16( HDLC_TIME_OUT_DESCRIPTION, GATT_UUID_CHAR_DESCRIPTION,
LEGATTDB_PERM_READABLE ),
/* Declare Device info service */
PRIMARY_SERVICE_UUID16( HDLS_DEV_INFO, UUID_SERVCLASS_DEVICE_INFO ),
/* Handle 0x4e: characteristic Manufacturer Name */
CHARACTERISTIC_UUID16( HDLC_DEV_INFO_MFR_NAME, HDLC_DEV_INFO_MFR_NAME_VALUE,
GATT_UUID_MANU_NAME,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE ),
/* Handle 0x50: characteristic Model Number */
CHARACTERISTIC_UUID16( HDLC_DEV_INFO_MODEL_NUM, HDLC_DEV_INFO_MODEL_NUM_VALUE,
GATT_UUID_MODEL_NUMBER_STR,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE ),
/* Handle 0x52: characteristic System ID */
CHARACTERISTIC_UUID16( HDLC_DEV_INFO_SYSTEM_ID, HDLC_DEV_INFO_SYSTEM_ID_VALUE,
GATT_UUID_SYSTEM_ID,
LEGATTDB_CHAR_PROP_READ|LEGATTDB_CHAR_PROP_WRITE, LEGATTDB_PERM_READABLE|LEGATTDB_PERM_WRITABLE ),
};
static int adv_complete_cb(void *arg)
{
}
struct indicate_arg_s {
ble_gatt_attr_t *attr;
peripheral_hdl_t hdl;
};
static void indicate_handler(void *arg)
{
struct indicate_arg_s *ind = (struct indicate_arg_s *)arg;
long long time = aos_now_ms();
ble_attr_notify(ind->attr, ind->hdl, sizeof(time), (uint8_t *)&time);
aos_post_delayed_action(1000, indicate_handler, arg);
}
#define DEVICE_MANUFACURE_NAME "BleAdvertisementsSampleManufacture"
#define DEVICE_MODEL_NUM "BleAdvertismentsSampleDeviceModel"
static uint8_t sys_id[] = {0x12, 0x34};
static const struct adv_data ad[] = {
ADV_DATA_BYTES(EIRADV_DATA_FLAGS, (AD_FLAG_GENERAL | AD_FLAG_NO_BREDR)),
ADV_DATA_BYTES(EIRADV_DATA_UUID16_ALL, 0x0a, 0x18),
};
static const struct adv_data sd[] = {
ADV_DATA(EIRADV_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
};
int application_start( void )
{
peripheral_hdl_t hdl;
ble_gatt_attr_t *attr;
struct indicate_arg_s ind_arg;
peripheral_init_t p = {CONFIG_BT_DEVICE_NAME, 0, 1};
hdl = ble_peripheral_init(&p, connection_handler, disconnection_handler,
adv_gatt_db, sizeof(adv_gatt_db));
ble_set_ad_data(hdl, ad, sizeof(ad) / sizeof(ad[0]));
ble_set_sd_data(hdl, sd, sizeof(sd) / sizeof(sd[0]));
ble_adv_start(adv_complete_cb, DEVICE_MANUFACURE_NAME, hdl);
ble_attr_add(HDLC_DEV_INFO_MFR_NAME_VALUE,
sizeof(DEVICE_MANUFACURE_NAME) - 1, DEVICE_MANUFACURE_NAME);
ble_attr_add(HDLC_DEV_INFO_MODEL_NUM_VALUE,
sizeof(DEVICE_MODEL_NUM) - 1, DEVICE_MODEL_NUM);
ble_attr_add(HDLC_DEV_INFO_SYSTEM_ID_VALUE, sizeof(sys_id),
(const uint8_t *)&sys_id);
attr = ble_attr_add(HDLC_TIME_OUT_VALUE, 0, NULL);
ind_arg.hdl = hdl;
ind_arg.attr = attr;
aos_post_delayed_action(1000, indicate_handler, &ind_arg);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,9 @@
NAME := app_ble_show_system_time
$(NAME)_SOURCES := ble_show_system_time.c
ble = 1
$(NAME)_COMPONENTS := bluetooth.ble_app_framework
GLOBAL_CFLAGS += -DCONFIG_BT_DEVICE_NAME=\"AosBleShowSysTimeSampleDevice\"

View file

@ -0,0 +1,11 @@
NAME := bleadv
$(NAME)_SOURCES := main.c
$(NAME)_INCLUDES := ../../../kernel/protocols/bluetooth/include \
../../../kernel/protocols/bluetooth/core/include
ble = 1
$(NAME)_COMPONENTS += protocols.bluetooth yloop cli
GLOBAL_DEFINES += AOS_NO_WIFI CONFIG_BT_SMP

View file

@ -0,0 +1,76 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <string.h>
#include <aos/aos.h>
#include <aos/kernel.h>
#include <misc/slist.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
extern int hci_driver_init();
extern int bt_enable(bt_ready_cb_t cb);
void ble_sample(void)
{
bt_addr_t addr = {.val = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x05 }};
struct bt_le_adv_param adv_param = {
.options = 0, \
.interval_min = BT_GAP_ADV_FAST_INT_MIN_2, \
.interval_max = BT_GAP_ADV_FAST_INT_MAX_2, \
.own_addr = &addr, \
};
int err;
uint8_t data[] = { 0x6 }; // LE General Discoverable and BR/EDR not supported
char *adv_name = "AOS-BLE-HELLO";
const struct bt_data adv_data[] = {
BT_DATA(BT_DATA_FLAGS, data, 1),
BT_DATA(BT_DATA_NAME_COMPLETE, adv_name, strlen(adv_name))
};
printf("Starting Advertiser Demo\n");
hci_driver_init();
err = bt_enable(NULL);
if (err) {
printf("Bluetooth init failed (err %d)\n", err);
return;
}
printf("Bluetooth initialized\n");
do {
aos_msleep(400);
/* Start advertising */
err = bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), NULL, 0);
if (err) {
printf("Advertising failed to start (err %d)\n", err);
return;
}
aos_msleep(400);
err = bt_le_adv_stop();
if (err) {
printf("Advertising failed to stop (err %d)\n", err);
return;
}
} while (1);
}
static void app_delayed_action(void *arg)
{
ble_sample();
}
int application_start(int argc, char **argv)
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,12 @@
NAME := blemesh
$(NAME)_SOURCES := main.c
$(NAME)_INCLUDES := ../../../kernel/protocols/bluetooth/include \
../../../kernel/protocols/bluetooth/core/include
ble = 1
bt_mesh = 1
$(NAME)_COMPONENTS += protocols.bluetooth yloop cli
GLOBAL_DEFINES += AOS_NO_WIFI CONFIG_BT_SMP CONFIG_BT_MESH_PROV CONFIG_BT_MESH_PB_ADV CONFIG_BT_MESH_PB_GATT CONFIG_BT_TINYCRYPT_ECC CONFIG_BT_MESH_CFG_CLI CONFIG_BT_MESH_PROXY

View file

@ -0,0 +1,245 @@
/* main.c - Application main entry point */
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include <aos/aos.h>
#include <aos/kernel.h>
#include <misc/printk.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/mesh.h>
#include "mesh.h"
#include "net.h"
#include "transport.h"
#include "bluetooth/mesh/cfg_cli.h"
#define CID_INTEL 0x0002
#define NODE_ADDR 0x000f
#if !defined(NODE_ADDR)
#define NODE_ADDR 0x0b0c
#endif
#define GROUP_ADDR 0xc000
#define PUBLISHER_ADDR 0x000f
#define OP_VENDOR_BUTTON BT_MESH_MODEL_OP_3(0x00, CID_INTEL)
static const u8_t net_key[16] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static const u8_t dev_key[16] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static const u8_t app_key[16] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static u16_t net_idx;
static const u16_t app_idx;
static const u32_t iv_index;
static u8_t flags;
static u16_t addr = NODE_ADDR;
static u32_t seq;
static void heartbeat(u8_t hops, u16_t feat)
{
printk("aos ble mesh, hello world\r\n");
}
static struct bt_mesh_cfg_srv cfg_srv = {
#if defined(CONFIG_BOARD_BBC_MICROBIT)
.relay = BT_MESH_RELAY_ENABLED,
.beacon = BT_MESH_BEACON_DISABLED,
#else
.relay = BT_MESH_RELAY_ENABLED,
.beacon = BT_MESH_BEACON_ENABLED,
#endif
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
.relay_retransmit = BT_MESH_TRANSMIT(3, 20),
.hb_sub.func = heartbeat,
};
static struct bt_mesh_cfg_cli cfg_cli = {
};
static void attention_on(struct bt_mesh_model *model)
{
printk("attention_on()\n");
}
static void attention_off(struct bt_mesh_model *model)
{
printk("attention_off()\n");
}
static const struct bt_mesh_health_srv_cb health_srv_cb = {
.attn_on = attention_on,
.attn_off = attention_off,
};
static struct bt_mesh_health_srv health_srv = {
.cb = &health_srv_cb,
};
static struct bt_mesh_model_pub health_pub = {
.msg = BT_MESH_HEALTH_FAULT_MSG(0),
};
static struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
};
static struct bt_mesh_model vnd_models[] = {
};
static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(0, root_models, vnd_models),
};
static const struct bt_mesh_comp comp = {
.cid = CID_INTEL,
.elem = elements,
.elem_count = ARRAY_SIZE(elements),
};
static void configure(void)
{
printk("Configuring...\n");
/* Add Application Key */
bt_mesh_cfg_app_key_add(net_idx, addr, net_idx, app_idx, app_key, NULL);
/* Bind to Health model */
bt_mesh_cfg_mod_app_bind(net_idx, addr, addr, app_idx,
BT_MESH_MODEL_ID_HEALTH_SRV, NULL);
#if NODE_ADDR == PUBLISHER_ADDR
{
struct bt_mesh_cfg_hb_pub pub = {
.dst = GROUP_ADDR,
.count = 0xff,
.period = 0x05,
.ttl = 0x07,
.feat = 0,
.net_idx = net_idx,
};
bt_mesh_cfg_hb_pub_set(net_idx, addr, &pub, NULL);
printk("Publishing heartbeat messages\n");
}
#else
{
struct bt_mesh_cfg_hb_sub sub = {
.src = PUBLISHER_ADDR,
.dst = GROUP_ADDR,
.period = 0x10,
};
bt_mesh_cfg_hb_sub_set(net_idx, addr, &sub, NULL);
printk("Subscribing to heartbeat messages\n");
}
#endif
printk("Configuration complete\n");
}
static const u8_t dev_uuid[16] = { 0xdd, 0xde };
static int output_number(bt_mesh_output_action_t action, uint32_t number)
{
printk("OOB Number: %u\n", number);
return 0;
}
static void prov_complete(u16_t netidx, u16_t laddr)
{
}
static void prov_reset(void)
{
bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT);
}
static const struct bt_mesh_prov prov = {
.uuid = dev_uuid,
.output_size = 4,
.output_actions = BT_MESH_DISPLAY_NUMBER,
.output_number = output_number,
.complete = prov_complete,
.reset = prov_reset,
};
static void bt_ready(int err)
{
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
err = bt_mesh_init(&prov, &comp);
if (err) {
printk("Initializing mesh failed (err %d)\n", err);
return;
}
printk("Mesh initialized\n");
err = bt_mesh_provision(net_key, net_idx, flags, iv_index, seq, addr,
dev_key);
if (err) {
printk("Provisioning failed (err %d)\n", err);
return;
}
printk("Provisioning completed\n");
configure();
}
extern int hci_driver_init(void);
void blemesh_sample(void)
{
int err;
printk("Initializing...\n");
printk("Unicast address: 0x%04x, seq 0x%06x\n", addr, seq);
hci_driver_init();
/* Initialize the Bluetooth Subsystem */
err = bt_enable(bt_ready);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
}
}
static void app_delayed_action(void *arg)
{
blemesh_sample();
}
int application_start(int argc, char **argv)
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,12 @@
NAME := blemesh_cli
$(NAME)_SOURCES := main.c
$(NAME)_INCLUDES := ../../../kernel/protocols/bluetooth/include \
../../../kernel/protocols/bluetooth/core/include
ble = 1
bt_mesh = 1
$(NAME)_COMPONENTS += protocols.bluetooth yloop cli
GLOBAL_DEFINES += AOS_NO_WIFI CONFIG_BT_SMP CONFIG_BT_MESH_PROV CONFIG_BT_MESH_PB_ADV CONFIG_BT_MESH_PB_GATT CONFIG_BT_TINYCRYPT_ECC CONFIG_BT_MESH_CFG_CLI CONFIG_BT_MESH_PROXY CONFIG_BT_MESH_GATT_PROXY CONFIG_BT_CONN

View file

@ -0,0 +1,201 @@
/* main.c - Application main entry point */
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include <aos/aos.h>
#include <aos/kernel.h>
#include <misc/printk.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/mesh.h>
#define CID_INTEL 0x0002
#define ID_TEMP_CELSIUS 0x2A1F
#define BT_MESH_MODEL_OP_SENSOR_STATUS BT_MESH_MODEL_OP_1(0x52)
#define BT_MESH_MODEL_OP_SENSOR_GET BT_MESH_MODEL_OP_2(0x82, 0x31)
static struct k_work temp_work;
static struct k_timer temp_timer;
static u16_t node_addr = BT_MESH_ADDR_UNASSIGNED;
static struct bt_mesh_cfg_cli cfg_cli = {
};
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BT_MESH_RELAY_DISABLED,
.beacon = BT_MESH_BEACON_ENABLED,
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
.gatt_proxy = BT_MESH_GATT_PROXY_ENABLED,
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
};
static struct bt_mesh_model_pub temp_cli_pub = {
.msg = NET_BUF_SIMPLE(2),
};
static void temp_cli_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
}
static void temp_cli_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
printk("Got the sensor status \n");
printk("Sensor ID: 0x%04x\n", net_buf_simple_pull_le16(buf));
printk("Temperature value: %d\n\n", net_buf_simple_pull_le16(buf));
}
/* Sensor client model Opcode */
static const struct bt_mesh_model_op temp_cli_op[] = {
/* Opcode, message length, message handler */
{ BT_MESH_MODEL_OP_SENSOR_GET, 2, temp_cli_get },
{ BT_MESH_MODEL_OP_SENSOR_STATUS, 2, temp_cli_status },
BT_MESH_MODEL_OP_END,
};
static struct bt_mesh_model root_models[] = {
/* Mandatory Configuration Server model. Should be the first model
* of root element */
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL(BT_MESH_MODEL_ID_SENSOR_CLI, temp_cli_op,
&temp_cli_pub, NULL),
};
static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE),
};
/* Node composition data used to configure a node while provisioning */
static const struct bt_mesh_comp comp = {
.cid = CID_INTEL,
.elem = elements,
.elem_count = ARRAY_SIZE(elements),
};
static int output_number(bt_mesh_output_action_t action, uint32_t number)
{
printk("OOB Number: %u\n", number);
return 0;
}
static void temp_work_thread(struct k_work *work)
{
struct bt_mesh_model *model = &root_models[2];
struct net_buf_simple *msg = model->pub->msg;
int ret;
if (node_addr == BT_MESH_ADDR_UNASSIGNED) {
goto exit;
}
/* sensor status */
bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_SENSOR_GET);
net_buf_simple_add_le16(msg, ID_TEMP_CELSIUS);
ret = bt_mesh_model_publish(model);
if (ret) {
printk("ERR: Unable to send sensor status get request: %d\n", ret);
goto exit;
}
printk("Sensor status Get request sent with OpCode 0x%08x\n", BT_MESH_MODEL_OP_SENSOR_GET);
exit:
k_timer_start(&temp_timer, K_SECONDS(5));
}
static void temp_timer_thread(void *work, void *args)
{
k_work_submit(&temp_work);
}
static void prov_complete(u16_t net_idx, u16_t addr)
{
printk("Provisioning completed!\n");
printk("Net ID: %u\n", net_idx);
printk("Unicast addr: 0x%04x\n", addr);
node_addr = addr;
k_work_init(&temp_work, temp_work_thread);
k_timer_init(&temp_timer, temp_timer_thread, NULL);
k_timer_start(&temp_timer, K_SECONDS(50));
}
/* UUID for identifying the unprovisioned node */
static const uint8_t dev_uuid[16] = { 0xdd, 0xdd };
/* Only displaying the number while provisioning is supported */
static const struct bt_mesh_prov prov = {
.uuid = dev_uuid,
.output_size = 4,
.output_actions = BT_MESH_DISPLAY_NUMBER,
.output_number = output_number,
.complete = prov_complete,
};
static void bt_ready(int err)
{
int ret;
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
ret = bt_mesh_init(&prov, &comp);
if (ret) {
printk("Initializing mesh failed (err %d)\n", ret);
return;
}
bt_mesh_prov_enable(BT_MESH_PROV_GATT | BT_MESH_PROV_ADV);
printk("Mesh initialized\n");
}
extern int hci_driver_init();
void blemesh_sample(void)
{
int ret;
printk("Initializing...\n");
hci_driver_init();
/* Initialize the Bluetooth Subsystem */
ret = bt_enable(bt_ready);
if (ret) {
printk("Bluetooth init failed (err %d)\n", ret);
}
}
static void app_delayed_action(void *arg)
{
blemesh_sample();
}
int application_start(int argc, char **argv)
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,12 @@
NAME := blemesh_srv
$(NAME)_SOURCES := main.c
$(NAME)_INCLUDES := ../../../kernel/protocols/bluetooth/include \
../../../kernel/protocols/bluetooth/core/include
ble = 1
bt_mesh = 1
$(NAME)_COMPONENTS += protocols.bluetooth yloop cli
GLOBAL_DEFINES += AOS_NO_WIFI CONFIG_BT_SMP CONFIG_BT_MESH_PROV CONFIG_BT_MESH_PB_ADV CONFIG_BT_MESH_PB_GATT CONFIG_BT_TINYCRYPT_ECC CONFIG_BT_MESH_CFG_CLI CONFIG_BT_MESH_PROXY CONFIG_BT_MESH_GATT_PROXY CONFIG_BT_CONN

View file

@ -0,0 +1,208 @@
/* main.c - Application main entry point */
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include <aos/aos.h>
#include <aos/kernel.h>
#include <misc/printk.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/mesh.h>
#define CID_INTEL 0x0002
#define ID_TEMP_CELSIUS 0x2A1F
#define BT_MESH_MODEL_OP_SENSOR_STATUS BT_MESH_MODEL_OP_1(0x52)
#define BT_MESH_MODEL_OP_SENSOR_GET BT_MESH_MODEL_OP_2(0x82, 0x31)
static u16_t node_addr;
static struct bt_mesh_cfg_cli cfg_cli = {
};
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BT_MESH_RELAY_DISABLED,
.beacon = BT_MESH_BEACON_ENABLED,
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
.gatt_proxy = BT_MESH_GATT_PROXY_ENABLED,
.default_ttl = 7,
/* 3 transmissions with 20ms interval */
.net_transmit = BT_MESH_TRANSMIT(2, 20),
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
};
static struct bt_mesh_model_pub temp_srv_pub = {
.msg = NET_BUF_SIMPLE(2 + 2),
};
static struct bt_mesh_model_pub health_pub = {
.msg = BT_MESH_HEALTH_FAULT_MSG(0),
};
/*
* Health Server Declaration
*/
static void attention_on(struct bt_mesh_model *model)
{
printk("attention_on()\n");
}
static void attention_off(struct bt_mesh_model *model)
{
printk("attention_off()\n");
}
static const struct bt_mesh_health_srv_cb health_srv_cb = {
.attn_on = attention_on,
.attn_off = attention_off,
};
static struct bt_mesh_health_srv health_srv = {
.cb = &health_srv_cb,
};
static void temp_srv_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct net_buf_simple *msg = model->pub->msg;
int ret;
printk("Sensor Status Get request received\n");
/* sensor status */
bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_SENSOR_STATUS);
/* id: termperature in celsius */
net_buf_simple_add_le16(msg, ID_TEMP_CELSIUS);
/* raw temperature value in celsius */
net_buf_simple_add_le16(msg, 27);
ret = bt_mesh_model_publish(model);
if (ret) {
printk("ERR: Unable to publish sensor status: %d\n", ret);
return;
}
printk("Sensor status sent with OpCode 0x%08x\n", BT_MESH_MODEL_OP_SENSOR_STATUS);
}
/* Sensor server model Opcode */
static const struct bt_mesh_model_op temp_srv_op[] = {
/* Opcode, message length, message handler */
{ BT_MESH_MODEL_OP_SENSOR_GET, 2, temp_srv_status },
BT_MESH_MODEL_OP_END,
};
static struct bt_mesh_model root_models[] = {
/* Mandatory Configuration Server model. Should be the first model
* of root element */
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
BT_MESH_MODEL(BT_MESH_MODEL_ID_SENSOR_SRV, temp_srv_op,
&temp_srv_pub, NULL),
};
static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE),
};
/* Node composition data used to configure a node while provisioning */
static const struct bt_mesh_comp comp = {
.cid = CID_INTEL,
.elem = elements,
.elem_count = ARRAY_SIZE(elements),
};
static int output_number(bt_mesh_output_action_t action, uint32_t number)
{
printk("OOB Number: %u\n", number);
return 0;
}
static void prov_complete(u16_t net_idx, u16_t addr)
{
printk("Provisioning completed!\n");
printk("Net ID: %u\n", net_idx);
printk("Unicast addr: 0x%04x\n", addr);
node_addr = addr;
}
static void prov_reset(void)
{
bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT);
}
/* UUID for identifying the unprovisioned node */
static const uint8_t dev_uuid[16] = { 0xdd, 0xdd };
/* Only displaying the number while provisioning is supported */
static const struct bt_mesh_prov prov = {
.uuid = dev_uuid,
.output_size = 4,
.output_actions = BT_MESH_DISPLAY_NUMBER,
.output_number = output_number,
.complete = prov_complete,
.reset = prov_reset,
};
static void bt_ready(int err)
{
int ret;
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
printk("Server\n");
ret = bt_mesh_init(&prov, &comp);
if (ret) {
printk("Initializing mesh failed (err %d)\n", ret);
return;
}
bt_mesh_prov_enable(BT_MESH_PROV_GATT | BT_MESH_PROV_ADV);
printk("Mesh initialized\n");
}
extern int hci_driver_init();
void blemesh_sample(void)
{
int ret;
printk("Initializing...\n");
hci_driver_init();
/* Initialize the Bluetooth Subsystem */
ret = bt_enable(bt_ready);
if (ret) {
printk("Bluetooth init failed (err %d)\n", ret);
}
}
static void app_delayed_action(void *arg)
{
blemesh_sample();
}
int application_start(int argc, char **argv)
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,13 @@
NAME := bleperipheral
$(NAME)_MBINS_TYPE := app
$(NAME)_SOURCES := main.c
$(NAME)_INCLUDES := ../../../kernel/protocols/bluetooth/include \
../../../kernel/protocols/bluetooth/core/include
ble = 1
$(NAME)_COMPONENTS += protocols.bluetooth yloop cli bluetooth.profile
GLOBAL_DEFINES += AOS_NO_WIFI CONFIG_BT_SMP

View file

@ -0,0 +1,199 @@
/*
* copyright (c) 2015-2016 intel corporation
*
* licensed under the apache license, version 2.0 (the "license");
* you may not use this file except in compliance with the license.
* you may obtain a copy of the license at
*
* http://www.apache.org/licenses/license-2.0
*
* unless required by applicable law or agreed to in writing, software
* distributed under the license is distributed on an "as is" basis,
* without warranties or conditions of any kind, either express or implied.
* see the license for the specific language governing permissions and
* limitations under the license.
*/
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <aos/aos.h>
#include <aos/kernel.h>
#include <misc/byteorder.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
#include "hrs.h"
#include "bas.h"
#include "dis.h"
#define DEVICE_NAME "AOS-BLE-PERIPHERAL"
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
extern int hci_driver_init();
struct bt_conn *default_conn;
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, 0x0d, 0x18, 0x0f, 0x18, 0x05, 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, uint8_t err)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printf("Failed to connect to %s (%u)\n", addr, err);
return;
}
default_conn = bt_conn_ref(conn);
printf("Connected %s\n", addr);
if (bt_conn_security(conn, BT_SECURITY_HIGH)) {
printf("Failed to set security\n");
}
}
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (default_conn) {
bt_conn_unref(default_conn);
default_conn = NULL;
}
printf("Disconnected from %s (reason %u)\n", addr, reason);
}
static void identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa,
const bt_addr_le_t *identity)
{
char addr_identity[BT_ADDR_LE_STR_LEN];
char addr_rpa[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(identity, addr_identity, sizeof(addr_identity));
bt_addr_le_to_str(rpa, addr_rpa, sizeof(addr_rpa));
printf("Identity resolved %s -> %s\n", addr_rpa, addr_identity);
}
static void security_changed(struct bt_conn *conn, bt_security_t level)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printf("Security changed: %s level %u\n", addr, level);
}
static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.identity_resolved = identity_resolved,
.security_changed = security_changed,
};
static void bt_ready(int err)
{
if (err) {
printf("Bluetooth init failed (err %d)\n", err);
return;
}
printf("Bluetooth initialized\n");
hrs_init(0x01);
bas_init();
dis_init("AOS_BLE_MODEL", "Manufacturer");
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
if (err) {
printf("Advertising failed to start (err %d)\n", err);
return;
}
printf("Advertising successfully started\n");
}
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printf("Passkey for %s: %u\n", addr, passkey);
}
static void auth_cancel(struct bt_conn *conn)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printf("Pairing cancelled: %s\n", addr);
}
static struct bt_conn_auth_cb auth_cb_display = {
.passkey_display = auth_passkey_display,
.passkey_entry = NULL,
.cancel = auth_cancel,
};
extern int hci_driver_init();
void ble_sample(void)
{
int err = 0;
hci_driver_init();
err = bt_enable(bt_ready);
if (err) {
printf("Bluetooth init failed (err %d)\n", err);
return;
}
bt_conn_auth_cb_register(&auth_cb_display);
bt_conn_cb_register(&conn_callbacks);
while (1) {
aos_msleep(1000);
/* Heartrate measurements simulation */
hrs_notify();
/* Battery level simulation */
bas_notify();
}
printf("Advertising successfully started\n");
}
static void app_delayed_action(void *arg)
{
ble_sample();
}
int application_start(int argc, char **argv)
{
aos_post_delayed_action(1000, app_delayed_action, NULL);
aos_loop_run();
return 0;
}

View file

@ -0,0 +1,10 @@
menuconfig AOS_APP_BREEZEAPP
bool "breezeapp"
select AOS_COMP_BREEZE
select AOS_COMP_OTA_BLE if @CONDITION@
select AOS_COMP_CLI
help
if AOS_APP_BREEZEAPP
# Configurations for app breezeapp
endif

View file

@ -0,0 +1,53 @@
## Contents
```
breezeapp
.
├── breezeapp.c
└── breezeapp.mk
```
## Introduction
### Requirements
* Platform: Nordic's nRF52840/nRF52832 BLE SOCs or other BLE hardware already support AliOS things Breeze SDK.
* Quintuple: device info to access to Alibaba IoT cloud.
### Features
- Breeze transport : provide data transport over BLE link.
- Breeze authentication : provice secure access to Alibaba IoT cloud.
- Breeze auxiliary provision : provide provision ability(obtation SSID and password, etc) over BLE link.
- Breeze OTA : provide unified OTA framework over BLE link.
### Dependencies
- yloop
- breeze
- CLI
## Usage
Breezeapp demonstrate usage of breeze SDK functionalities.
### Build
aos make bluetooth.breezeapp@pca10056
### Install
On ble device, take pca10056 for example, use J-flash or other tools download the compilied binary, on mobile, use Xlinkdemo APPs provided by Alibaba.
### Run
Use APP to connect and auth BLE device, APPs offers date exchange, OTA functation, etc.
### Result
Chech the hint and result on APP.
## Reference
[蓝牙辅助WiFi配网开发说明](https://github.com/alibaba/AliOS-Things/wiki/%E8%93%9D%E7%89%99%E8%BE%85%E5%8A%A9WiFi%E9%85%8D%E7%BD%91%E5%BC%80%E5%8F%91%E8%AF%B4%E6%98%8E)

View file

@ -0,0 +1,165 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "aos/kernel.h"
#include <stdio.h>
#include <stdbool.h>
#include <breeze_export.h>
#ifdef CONFIG_AIS_OTA
#include <ota_breeze_export.h>
#endif
#define SOFTWARE_VERSION "0.2.0"
#define SOFTWARE_VERSION_LEN 5
#define PRODUCT_ID 850876
#define DEVICE_SECRET "PJ5ixkKx7BCgnqpgKA8OKBZ6odbJs9KD"
#define DEVICE_NAME "leo123456"
#define PRODUCT_KEY "a1Nxcg9mErA"
#define PRODUCT_SECRET "xaOXlxx6th1QNPY1"
static bool ble_connected = false;
/* @brief Event handler for Ali-SDK. */
static void dev_status_changed_handler(breeze_event_t event)
{
switch (event) {
case CONNECTED:
ble_connected = true;
printf("dev_status_changed(): Connected.\n");
break;
case DISCONNECTED:
ble_connected = false;
printf("dev_status_changed(): Disconnected.\n");
break;
case AUTHENTICATED:
printf("dev_status_changed(): Authenticated.\n");
break;
case TX_DONE:
printf("dev_status_changed(): Tx-done.\n");
break;
default:
break;
}
}
/* @brief Data handler for control command 0x00. */
static void set_dev_status_handler(uint8_t *buffer, uint32_t length)
{
printf("%s command (len: %d) received.\r\n", __func__, length);
}
/* @brief Data handler for query command 0x02. */
static void get_dev_status_handler(uint8_t *buffer, uint32_t length)
{
/* echo the receiving data */
uint8_t cmd = 0x03;
breeze_post_ext(cmd, buffer, length);
}
#ifdef CONTINUE_BEL_ADV
static void adv_work(void *arg)
{
#ifdef APPEND_USER_ADV
static uint8_t user_adv[] = {0x55, 0xaa};
user_adv[0]++;
user_adv[1]++;
breeze_append_adv_data(user_adv, sizeof(user_adv) / sizeof(user_adv[0]));
#endif
if (!ble_connected) breeze_restart_advertising();
aos_post_delayed_action(2000, adv_work, NULL);
}
#endif
static void apinfo_handler(breeze_apinfo_t *ap)
{
printf("Hello %s\r\n", __func__);
}
static void ota_handler(breeze_otainfo_t *ota)
{
/*need to move ota logic here*/
if(ota != NULL){
if(ota->type == OTA_CMD){
printf("RECV OTA CMD\n");
} else if(ota->type == OTA_EVT){
printf("RECV OTA EVT (%d)\n", ota->cmd_evt.m_evt.evt);
} else{
printf("unknown ota info\r\n");
}
}
}
static void alink_work(void *arg)
{
bool ret;
uint32_t err_code;
struct device_config init_bzlink;
uint8_t bd_addr[BD_ADDR_LEN] = { 0 };
#ifdef CONFIG_AIS_OTA
ota_breeze_service_manage_t ota_module;
#endif
(void)arg;
memset(&init_bzlink, 0, sizeof(struct device_config));
init_bzlink.product_id = PRODUCT_ID;
init_bzlink.status_changed_cb = dev_status_changed_handler;
init_bzlink.set_cb = set_dev_status_handler;
init_bzlink.get_cb = get_dev_status_handler;
init_bzlink.apinfo_cb = apinfo_handler;
init_bzlink.device_secret_len = strlen(DEVICE_SECRET);
memcpy(init_bzlink.device_secret, DEVICE_SECRET, init_bzlink.device_secret_len);
init_bzlink.product_secret_len = strlen(PRODUCT_SECRET);
memcpy(init_bzlink.product_secret, PRODUCT_SECRET,
init_bzlink.product_secret_len);
init_bzlink.product_key_len = strlen(PRODUCT_KEY);
memcpy(init_bzlink.product_key, PRODUCT_KEY, init_bzlink.product_key_len);
init_bzlink.device_key_len = strlen(DEVICE_NAME);
memcpy(init_bzlink.device_name, DEVICE_NAME, init_bzlink.device_key_len);
#ifdef CONFIG_AIS_OTA
ota_module.is_ota_enable = true;
ota_module.verison.fw_ver_len = strlen(SOFTWARE_VERSION);
if(ota_module.verison.fw_ver_len > 8) {
printf("breeze version too long, make sure < 8 bytes");
return;
}
memcpy(ota_module.verison.fw_ver, SOFTWARE_VERSION, ota_module.verison.fw_ver_len);
ota_module.get_dat_cb = NULL;
ota_breeze_service_init(&ota_module);
init_bzlink.ota_cb = ota_module.get_dat_cb;
#else
init_bzlink.ota_cb = ota_handler;
#endif
ret = breeze_start(&init_bzlink);
if (ret != 0) {
printf("breeze_start failed.\r\n");
} else {
printf("breeze_start succeed.\r\n");
}
}
int application_start(int argc, char **argv)
{
alink_work(NULL);
#ifdef CONTINUE_BEL_ADV
adv_work(NULL);
#endif
return 0;
}

View file

@ -0,0 +1,38 @@
NAME := breezeapp
$(NAME)_MBINS_TYPE := app
$(NAME)_VERSION := 1.0.0
$(NAME)_SUMMARY := breezeapp
$(NAME)_SOURCES := breezeapp.c
ble = 1
bz_en_auth = 1
bz_en_awss = 1
bz_en_ota = 0
$(NAME)_COMPONENTS := framework.bluetooth.breeze
GLOBAL_DEFINES += DEBUG
GLOBAL_DEFINES += CONFIG_BLE_LINK_PARAMETERS
GLOBAL_DEFINES += BUILD_AOS AOS_OTA_RSA
bz_en_ota ?= 0
ifeq ($(bz_en_ota),1)
ifeq ($(bz_en_auth), 0)
$(error OTA need authentication, please set "bz_en_auth = 1")
endif
GLOBAL_DEFINES += CONFIG_AIS_OTA
$(NAME)_COMPONENTS += ota_ble
endif
ifeq ($(continue_ble_adv),1)
GLOBAL_DEFINES += CONTINUE_BEL_ADV
endif
ifeq ($(append_user_adv),1)
GLOBAL_DEFINES += APPEND_USER_ADV
endif
GLOBAL_INCLUDES += ../