初始提交
This commit is contained in:
8
application/samples/bt/sle/sle_uuid_server/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_uuid_server/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
add_subdirectory_if_exist(src)
|
||||
|
||||
set(SOURCES "${SOURCES}" PARENT_SCOPE)
|
||||
set(PUBLIC_HEADER "${PUBLIC_HEADER}" "${CMAKE_CURRENT_SOURCE_DIR}/inc" PARENT_SCOPE)
|
91
application/samples/bt/sle/sle_uuid_server/inc/sle_server_adv.h
Executable file
91
application/samples/bt/sle/sle_uuid_server/inc/sle_server_adv.h
Executable file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2023. All rights reserved.
|
||||
*
|
||||
* Description: SLE ADV Config.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup bluetooth_sle_adv API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SLE_SERVER_ADV_H
|
||||
#define SLE_SERVER_ADV_H
|
||||
|
||||
/* 广播ID */
|
||||
#define SLE_ADV_HANDLE_DEFAULT 1
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of BLE ADV 通用广播结构.
|
||||
* @else
|
||||
* @brief SLE 广播普通数据结构。
|
||||
* @endif
|
||||
*/
|
||||
struct sle_adv_common_value {
|
||||
uint8_t length;
|
||||
uint8_t type;
|
||||
uint8_t value;
|
||||
};
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of BLE ADV Channel mapping.
|
||||
* @else
|
||||
* @brief SLE 广播信道映射。
|
||||
* @endif
|
||||
*/
|
||||
typedef enum {
|
||||
SLE_ADV_CHANNEL_MAP_77 = 0x01,
|
||||
SLE_ADV_CHANNEL_MAP_78 = 0x02,
|
||||
SLE_ADV_CHANNEL_MAP_79 = 0x04,
|
||||
SLE_ADV_CHANNEL_MAP_DEFAULT = 0x07
|
||||
} sle_adv_channel_map;
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of SLE ADV Data Type.
|
||||
* @else
|
||||
* @brief SLE 广播数据类型
|
||||
* @endif
|
||||
*/
|
||||
typedef enum {
|
||||
SLE_ADV_DATA_TYPE_DISCOVERY_LEVEL = 0x01, /*!< 发现等级 */
|
||||
SLE_ADV_DATA_TYPE_ACCESS_MODE = 0x02, /*!< 接入层能力 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_DATA_16BIT_UUID = 0x03, /*!< 标准服务数据信息 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_DATA_128BIT_UUID = 0x04, /*!< 自定义服务数据信息 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LIST_OF_16BIT_SERVICE_UUIDS = 0x05, /*!< 完整标准服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LIST_OF_128BIT_SERVICE_UUIDS = 0x06, /*!< 完整自定义服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_INCOMPLETE_LIST_OF_16BIT_SERVICE_UUIDS = 0x07, /*!< 部分标准服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_INCOMPLETE_LIST_OF_128BIT_SERVICE_UUIDS = 0x08, /*!< 部分自定义服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_STRUCTURE_HASH_VALUE = 0x09, /*!< 服务结构散列值 */
|
||||
SLE_ADV_DATA_TYPE_SHORTENED_LOCAL_NAME = 0x0A, /*!< 设备缩写本地名称 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LOCAL_NAME = 0x0B, /*!< 设备完整本地名称 */
|
||||
SLE_ADV_DATA_TYPE_TX_POWER_LEVEL = 0x0C, /*!< 广播发送功率 */
|
||||
SLE_ADV_DATA_TYPE_SLB_COMMUNICATION_DOMAIN = 0x0D, /*!< SLB通信域域名 */
|
||||
SLE_ADV_DATA_TYPE_SLB_MEDIA_ACCESS_LAYER_ID = 0x0E, /*!< SLB媒体接入层标识 */
|
||||
SLE_ADV_DATA_TYPE_EXTENDED = 0xFE, /*!< 数据类型扩展 */
|
||||
SLE_ADV_DATA_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF /*!< 厂商自定义信息 */
|
||||
} sle_adv_data_type;
|
||||
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle adv data config.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle广播数据配置。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_adv_init(void);
|
||||
#endif
|
89
application/samples/bt/sle/sle_uuid_server/inc/sle_uuid_server.h
Executable file
89
application/samples/bt/sle/sle_uuid_server/inc/sle_uuid_server.h
Executable file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE UUID Server module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup SLE UUID SERVER API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
#ifndef SLE_UUID_SERVER_H
|
||||
#define SLE_UUID_SERVER_H
|
||||
|
||||
#include "sle_ssap_server.h"
|
||||
|
||||
/* Service UUID */
|
||||
#define SLE_UUID_SERVER_SERVICE 0xABCD
|
||||
|
||||
/* Property UUID */
|
||||
#define SLE_UUID_SERVER_NTF_REPORT 0x1122
|
||||
|
||||
/* Property Property */
|
||||
#define SLE_UUID_TEST_PROPERTIES (SSAP_PERMISSION_READ | SSAP_PERMISSION_WRITE)
|
||||
|
||||
/* Descriptor Property */
|
||||
#define SLE_UUID_TEST_DESCRIPTOR (SSAP_PERMISSION_READ | SSAP_PERMISSION_WRITE)
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief SLE uuid server inir.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief SLE UUID服务器初始化。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_init(void);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief send data to peer device by uuid on uuid server.
|
||||
* @attention NULL
|
||||
* @param [in] value send value.
|
||||
* @param [in] len Length of send value。
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief 通过uuid server 发送数据给对端。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_send_report_by_uuid(const uint8_t *data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief send data to peer device by handle on uuid server.
|
||||
* @attention NULL
|
||||
* @param [in] value send value.
|
||||
* @param [in] len Length of send value。
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief 通过uuid server 发送数据给对端。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_send_report_by_handle(const uint8_t *data, uint8_t len);
|
||||
#endif
|
8
application/samples/bt/sle/sle_uuid_server/src/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_uuid_server/src/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_server_adv.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_uuid_server.c"
|
||||
PARENT_SCOPE)
|
198
application/samples/bt/sle/sle_uuid_server/src/sle_server_adv.c
Executable file
198
application/samples/bt/sle/sle_uuid_server/src/sle_server_adv.c
Executable file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2023. All rights reserved.
|
||||
* Description: sle adv config for sle uuid server.
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "errcode.h"
|
||||
#include "osal_addr.h"
|
||||
#include "osal_debug.h"
|
||||
#include "sle_common.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_errcode.h"
|
||||
#include "sle_server_adv.h"
|
||||
|
||||
/* sle device name */
|
||||
#define NAME_MAX_LENGTH 15
|
||||
/* 连接调度间隔12.5ms,单位125us */
|
||||
#define SLE_CONN_INTV_MIN_DEFAULT 0x64
|
||||
/* 连接调度间隔12.5ms,单位125us */
|
||||
#define SLE_CONN_INTV_MAX_DEFAULT 0x64
|
||||
/* 连接调度间隔25ms,单位125us */
|
||||
#define SLE_ADV_INTERVAL_MIN_DEFAULT 0xC8
|
||||
/* 连接调度间隔25ms,单位125us */
|
||||
#define SLE_ADV_INTERVAL_MAX_DEFAULT 0xC8
|
||||
/* 超时时间5000ms,单位10ms */
|
||||
#define SLE_CONN_SUPERVISION_TIMEOUT_DEFAULT 0x1F4
|
||||
/* 超时时间4990ms,单位10ms */
|
||||
#define SLE_CONN_MAX_LATENCY 0x1F3
|
||||
/* 广播发送功率 */
|
||||
#define SLE_ADV_TX_POWER 10
|
||||
/* 最大广播数据长度 */
|
||||
#define SLE_ADV_DATA_LEN_MAX 251
|
||||
/* 广播名称 */
|
||||
uint8_t sle_local_name[ NAME_MAX_LENGTH] = { 's', 'l', 'e', '_', 'u', 'u', 'i', 'd', '_', 's',
|
||||
'e', 'r', 'v', 'e', 'r' };
|
||||
|
||||
static uint16_t sle_set_adv_local_name(uint8_t *adv_data, uint16_t max_len)
|
||||
{
|
||||
errno_t ret;
|
||||
uint8_t index = 0;
|
||||
|
||||
uint8_t *local_name = sle_local_name;
|
||||
uint8_t local_name_len = (uint8_t)strlen((char *)local_name);
|
||||
for (uint8_t i = 0; i < local_name_len; i++) {
|
||||
osal_printk("local_name[%d] = 0x%02x\r\n", i, local_name[i]);
|
||||
}
|
||||
|
||||
adv_data[index++] = local_name_len + 1;
|
||||
adv_data[index++] = SLE_ADV_DATA_TYPE_COMPLETE_LOCAL_NAME;
|
||||
ret = memcpy_s(&adv_data[index], max_len - index, local_name, local_name_len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
return (uint16_t)index + local_name_len;
|
||||
}
|
||||
|
||||
static uint16_t sle_set_adv_data(uint8_t *adv_data)
|
||||
{
|
||||
size_t len = 0;
|
||||
uint16_t idx = 0;
|
||||
errno_t ret = 0;
|
||||
|
||||
len = sizeof(struct sle_adv_common_value);
|
||||
struct sle_adv_common_value adv_disc_level = {
|
||||
.length = len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_DISCOVERY_LEVEL,
|
||||
.value = SLE_ANNOUNCE_LEVEL_NORMAL,
|
||||
};
|
||||
ret = memcpy_s(&adv_data[idx], SLE_ADV_DATA_LEN_MAX - idx, &adv_disc_level, len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("adv_disc_level memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += len;
|
||||
|
||||
len = sizeof(struct sle_adv_common_value);
|
||||
struct sle_adv_common_value adv_access_mode = {
|
||||
.length = len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_ACCESS_MODE,
|
||||
.value = 0,
|
||||
};
|
||||
ret = memcpy_s(&adv_data[idx], SLE_ADV_DATA_LEN_MAX - idx, &adv_access_mode, len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += len;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static uint16_t sle_set_scan_response_data(uint8_t *scan_rsp_data)
|
||||
{
|
||||
uint16_t idx = 0;
|
||||
errno_t ret;
|
||||
size_t scan_rsp_data_len = sizeof(struct sle_adv_common_value);
|
||||
|
||||
struct sle_adv_common_value tx_power_level = {
|
||||
.length = scan_rsp_data_len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_TX_POWER_LEVEL,
|
||||
.value = SLE_ADV_TX_POWER,
|
||||
};
|
||||
ret = memcpy_s(scan_rsp_data, SLE_ADV_DATA_LEN_MAX, &tx_power_level, scan_rsp_data_len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("sle scan response data memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += scan_rsp_data_len;
|
||||
|
||||
/* set local name */
|
||||
idx += sle_set_adv_local_name(&scan_rsp_data[idx], SLE_ADV_DATA_LEN_MAX - idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
static int sle_set_default_announce_param(void)
|
||||
{
|
||||
sle_announce_param_t param = {0};
|
||||
param.announce_mode = SLE_ANNOUNCE_MODE_CONNECTABLE_SCANABLE;
|
||||
param.announce_handle = SLE_ADV_HANDLE_DEFAULT;
|
||||
param.announce_gt_role = SLE_ANNOUNCE_ROLE_T_CAN_NEGO;
|
||||
param.announce_level = SLE_ANNOUNCE_LEVEL_NORMAL;
|
||||
param.announce_channel_map = SLE_ADV_CHANNEL_MAP_DEFAULT;
|
||||
param.announce_interval_min = SLE_ADV_INTERVAL_MIN_DEFAULT;
|
||||
param.announce_interval_max = SLE_ADV_INTERVAL_MAX_DEFAULT;
|
||||
param.conn_interval_min = SLE_CONN_INTV_MIN_DEFAULT;
|
||||
param.conn_interval_max = SLE_CONN_INTV_MAX_DEFAULT;
|
||||
param.conn_max_latency = SLE_CONN_MAX_LATENCY;
|
||||
param.conn_supervision_timeout = SLE_CONN_SUPERVISION_TIMEOUT_DEFAULT;
|
||||
return sle_set_announce_param(param.announce_handle, ¶m);
|
||||
}
|
||||
|
||||
static int sle_set_default_announce_data(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
uint8_t announce_data_len = 0;
|
||||
uint8_t seek_data_len = 0;
|
||||
sle_announce_data_t data = {0};
|
||||
uint8_t adv_handle = SLE_ADV_HANDLE_DEFAULT;
|
||||
uint8_t announce_data[SLE_ADV_DATA_LEN_MAX] = {0};
|
||||
uint8_t seek_rsp_data[SLE_ADV_DATA_LEN_MAX] = {0};
|
||||
|
||||
osal_printk("set adv data default\r\n");
|
||||
announce_data_len = sle_set_adv_data(announce_data);
|
||||
data.announce_data = announce_data;
|
||||
data.announce_data_len = announce_data_len;
|
||||
|
||||
seek_data_len = sle_set_scan_response_data(seek_rsp_data);
|
||||
data.seek_rsp_data = seek_rsp_data;
|
||||
data.seek_rsp_data_len = seek_data_len;
|
||||
|
||||
ret = sle_set_announce_data(adv_handle, &data);
|
||||
if (ret == ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[SLE DD SDK] set announce data success.");
|
||||
} else {
|
||||
osal_printk("[SLE DD SDK] set adv param fail.");
|
||||
}
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
void sle_announce_enable_cbk(uint32_t announce_id, errcode_t status)
|
||||
{
|
||||
osal_printk("sle announce enable id:%02x, state:%02x\r\n", announce_id, status);
|
||||
}
|
||||
|
||||
void sle_announce_disable_cbk(uint32_t announce_id, errcode_t status)
|
||||
{
|
||||
osal_printk("sle announce disable id:%02x, state:%02x\r\n", announce_id, status);
|
||||
}
|
||||
|
||||
void sle_announce_terminal_cbk(uint32_t announce_id)
|
||||
{
|
||||
osal_printk("sle announce terminal id:%02x\r\n", announce_id);
|
||||
}
|
||||
|
||||
void sle_enable_cbk(errcode_t status)
|
||||
{
|
||||
osal_printk("sle enable status:%02x\r\n", status);
|
||||
}
|
||||
|
||||
void sle_announce_register_cbks(void)
|
||||
{
|
||||
sle_announce_seek_callbacks_t seek_cbks = {0};
|
||||
seek_cbks.announce_enable_cb = sle_announce_enable_cbk;
|
||||
seek_cbks.announce_disable_cb = sle_announce_disable_cbk;
|
||||
seek_cbks.announce_terminal_cb = sle_announce_terminal_cbk;
|
||||
seek_cbks.sle_enable_cb = sle_enable_cbk;
|
||||
sle_announce_seek_register_callbacks(&seek_cbks);
|
||||
}
|
||||
|
||||
errcode_t sle_uuid_server_adv_init(void)
|
||||
{
|
||||
osal_printk("sle_uuid_server_adv_init in\r\n");
|
||||
sle_announce_register_cbks();
|
||||
sle_set_default_announce_param();
|
||||
sle_set_default_announce_data();
|
||||
sle_start_announce(SLE_ADV_HANDLE_DEFAULT);
|
||||
osal_printk("sle_uuid_server_adv_init out\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
297
application/samples/bt/sle/sle_uuid_server/src/sle_uuid_server.c
Executable file
297
application/samples/bt/sle/sle_uuid_server/src/sle_uuid_server.c
Executable file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2023. All rights reserved.
|
||||
* Description: sle uuid server sample.
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "errcode.h"
|
||||
#include "osal_addr.h"
|
||||
#include "soc_osal.h"
|
||||
#include "app_init.h"
|
||||
#include "sle_common.h"
|
||||
#include "sle_errcode.h"
|
||||
#include "sle_ssap_server.h"
|
||||
#include "sle_connection_manager.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_server_adv.h"
|
||||
#include "sle_uuid_server.h"
|
||||
|
||||
#define OCTET_BIT_LEN 8
|
||||
#define UUID_LEN_2 2
|
||||
#define BT_INDEX_4 4
|
||||
#define BT_INDEX_5 5
|
||||
#define BT_INDEX_0 0
|
||||
|
||||
#define encode2byte_little(_ptr, data) \
|
||||
do { \
|
||||
*(uint8_t *)((_ptr) + 1) = (uint8_t)((data) >> 8); \
|
||||
*(uint8_t *)(_ptr) = (uint8_t)(data); \
|
||||
} while (0)
|
||||
|
||||
/* sle server app uuid for test */
|
||||
char g_sle_uuid_app_uuid[UUID_LEN_2] = {0x0, 0x0};
|
||||
/* server notify property uuid for test */
|
||||
char g_sle_property_value[OCTET_BIT_LEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
/* sle connect acb handle */
|
||||
uint16_t g_sle_conn_hdl = 0;
|
||||
/* sle server handle */
|
||||
uint8_t g_server_id = 0;
|
||||
/* sle service handle */
|
||||
uint16_t g_service_handle = 0;
|
||||
/* sle ntf property handle */
|
||||
uint16_t g_property_handle = 0;
|
||||
|
||||
static uint8_t sle_uuid_base[] = { 0x37, 0xBE, 0xA8, 0x80, 0xFC, 0x70, 0x11, 0xEA, \
|
||||
0xB7, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static void sle_uuid_set_base(sle_uuid_t *out)
|
||||
{
|
||||
(void)memcpy_s(out->uuid, SLE_UUID_LEN, sle_uuid_base, SLE_UUID_LEN);
|
||||
out->len = UUID_LEN_2;
|
||||
}
|
||||
|
||||
static void sle_uuid_setu2(uint16_t u2, sle_uuid_t *out)
|
||||
{
|
||||
sle_uuid_set_base(out);
|
||||
out->len = UUID_LEN_2;
|
||||
encode2byte_little(&out->uuid[14], u2);
|
||||
}
|
||||
|
||||
static void ssaps_read_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_read_cb_t *read_cb_para,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] ssaps read request cbk server_id:%x, conn_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, conn_id, read_cb_para->handle, status);
|
||||
}
|
||||
|
||||
static void ssaps_write_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_write_cb_t *write_cb_para,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] ssaps write request cbk server_id:%x, conn_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, conn_id, write_cb_para->handle, status);
|
||||
}
|
||||
|
||||
static void ssaps_mtu_changed_cbk(uint8_t server_id, uint16_t conn_id, ssap_exchange_info_t *mtu_size,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] ssaps write request cbk server_id:%x, conn_id:%x, mtu_size:%x, status:%x\r\n",
|
||||
server_id, conn_id, mtu_size->mtu_size, status);
|
||||
}
|
||||
|
||||
static void ssaps_start_service_cbk(uint8_t server_id, uint16_t handle, errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] start service cbk server_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, handle, status);
|
||||
}
|
||||
|
||||
static void sle_ssaps_register_cbks(void)
|
||||
{
|
||||
ssaps_callbacks_t ssaps_cbk = {0};
|
||||
ssaps_cbk.start_service_cb = ssaps_start_service_cbk;
|
||||
ssaps_cbk.mtu_changed_cb = ssaps_mtu_changed_cbk;
|
||||
ssaps_cbk.read_request_cb = ssaps_read_request_cbk;
|
||||
ssaps_cbk.write_request_cb = ssaps_write_request_cbk;
|
||||
ssaps_register_callbacks(&ssaps_cbk);
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_service_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
sle_uuid_t service_uuid = {0};
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_SERVICE, &service_uuid);
|
||||
ret = ssaps_add_service_sync(g_server_id, &service_uuid, 1, &g_service_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add service fail, ret:%x\r\n", ret);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_property_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
ssaps_property_info_t property = {0};
|
||||
ssaps_desc_info_t descriptor = {0};
|
||||
uint8_t ntf_value[] = {0x01, 0x0};
|
||||
|
||||
property.permissions = SLE_UUID_TEST_PROPERTIES;
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_NTF_REPORT, &property.uuid);
|
||||
property.value = osal_vmalloc(sizeof(g_sle_property_value));
|
||||
if (property.value == NULL) {
|
||||
osal_printk("[uuid server] sle property mem fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(property.value, sizeof(g_sle_property_value), g_sle_property_value,
|
||||
sizeof(g_sle_property_value)) != EOK) {
|
||||
osal_vfree(property.value);
|
||||
osal_printk("[uuid server] sle property mem cpy fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ret = ssaps_add_property_sync(g_server_id, g_service_handle, &property, &g_property_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add property fail, ret:%x\r\n", ret);
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
descriptor.permissions = SLE_UUID_TEST_DESCRIPTOR;
|
||||
descriptor.value = osal_vmalloc(sizeof(ntf_value));
|
||||
if (descriptor.value == NULL) {
|
||||
osal_printk("[uuid server] sle descriptor mem fail\r\n");
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(descriptor.value, sizeof(ntf_value), ntf_value, sizeof(ntf_value)) != EOK) {
|
||||
osal_printk("[uuid server] sle descriptor mem cpy fail\r\n");
|
||||
osal_vfree(property.value);
|
||||
osal_vfree(descriptor.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ret = ssaps_add_descriptor_sync(g_server_id, g_service_handle, g_property_handle, &descriptor);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add descriptor fail, ret:%x\r\n", ret);
|
||||
osal_vfree(property.value);
|
||||
osal_vfree(descriptor.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_vfree(property.value);
|
||||
osal_vfree(descriptor.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
sle_uuid_t app_uuid = {0};
|
||||
|
||||
osal_printk("[uuid server] sle uuid add service in\r\n");
|
||||
app_uuid.len = sizeof(g_sle_uuid_app_uuid);
|
||||
if (memcpy_s(app_uuid.uuid, app_uuid.len, g_sle_uuid_app_uuid, sizeof(g_sle_uuid_app_uuid)) != EOK) {
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ssaps_register_server(&app_uuid, &g_server_id);
|
||||
|
||||
if (sle_uuid_server_service_add() != ERRCODE_SLE_SUCCESS) {
|
||||
ssaps_unregister_server(g_server_id);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
|
||||
if (sle_uuid_server_property_add() != ERRCODE_SLE_SUCCESS) {
|
||||
ssaps_unregister_server(g_server_id);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_printk("[uuid server] sle uuid add service, server_id:%x, service_handle:%x, property_handle:%x\r\n",
|
||||
g_server_id, g_service_handle, g_property_handle);
|
||||
ret = ssaps_start_service(g_server_id, g_service_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add service fail, ret:%x\r\n", ret);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_printk("[uuid server] sle uuid add service out\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
/* device通过uuid向host发送数据:report */
|
||||
errcode_t sle_uuid_server_send_report_by_uuid(const uint8_t *data, uint16_t len)
|
||||
{
|
||||
ssaps_ntf_ind_by_uuid_t param = {0};
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.start_handle = g_service_handle;
|
||||
param.end_handle = g_property_handle;
|
||||
param.value_len = len;
|
||||
param.value = osal_vmalloc(len);
|
||||
if (param.value == NULL) {
|
||||
osal_printk("[uuid server] send report new fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(param.value, param.value_len, data, len) != EOK) {
|
||||
osal_printk("[uuid server] send input report memcpy fail\r\n");
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_NTF_REPORT, ¶m.uuid);
|
||||
ssaps_notify_indicate_by_uuid(g_server_id, g_sle_conn_hdl, ¶m);
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
/* device通过handle向host发送数据:report */
|
||||
errcode_t sle_uuid_server_send_report_by_handle(const uint8_t *data, uint8_t len)
|
||||
{
|
||||
ssaps_ntf_ind_t param = {0};
|
||||
|
||||
param.handle = g_property_handle;
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.value = osal_vmalloc(len);
|
||||
param.value_len = len;
|
||||
if (param.value == NULL) {
|
||||
osal_printk("[uuid server] send report new fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(param.value, param.value_len, data, len) != EOK) {
|
||||
osal_printk("[uuid server] send input report memcpy fail\r\n");
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ssaps_notify_indicate(g_server_id, g_sle_conn_hdl, ¶m);
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static void sle_connect_state_changed_cbk(uint16_t conn_id, const sle_addr_t *addr,
|
||||
sle_acb_state_t conn_state, sle_pair_state_t pair_state, sle_disc_reason_t disc_reason)
|
||||
{
|
||||
osal_printk("[uuid server] connect state changed conn_id:0x%02x, conn_state:0x%x, pair_state:0x%x, \
|
||||
disc_reason:0x%x\r\n", conn_id, conn_state, pair_state, disc_reason);
|
||||
osal_printk("[uuid server] connect state changed addr:%02x:**:**:**:%02x:%02x\r\n",
|
||||
addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4], addr->addr[BT_INDEX_5]);
|
||||
g_sle_conn_hdl = conn_id;
|
||||
if (conn_state == SLE_ACB_STATE_DISCONNECTED) {
|
||||
sle_start_announce(SLE_ADV_HANDLE_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
static void sle_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] pair complete conn_id:%02x, status:%x\r\n",
|
||||
conn_id, status);
|
||||
osal_printk("[uuid server] pair complete addr:%02x:**:**:**:%02x:%02x\r\n",
|
||||
addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4], addr->addr[BT_INDEX_5]);
|
||||
}
|
||||
|
||||
static void sle_conn_register_cbks(void)
|
||||
{
|
||||
sle_connection_callbacks_t conn_cbks = {0};
|
||||
conn_cbks.connect_state_changed_cb = sle_connect_state_changed_cbk;
|
||||
conn_cbks.pair_complete_cb = sle_pair_complete_cbk;
|
||||
sle_connection_register_callbacks(&conn_cbks);
|
||||
}
|
||||
|
||||
/* 初始化uuid server */
|
||||
errcode_t sle_uuid_server_init(void)
|
||||
{
|
||||
enable_sle();
|
||||
sle_conn_register_cbks();
|
||||
sle_ssaps_register_cbks();
|
||||
sle_uuid_server_add();
|
||||
sle_uuid_server_adv_init();
|
||||
osal_printk("[uuid server] init ok\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
#define SLE_UUID_SERVER_TASK_PRIO 26
|
||||
#define SLE_UUID_SERVER_STACK_SIZE 0x2000
|
||||
|
||||
static void sle_uuid_server_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle= osal_kthread_create((osal_kthread_handler)sle_uuid_server_init, 0, "sle_uuid_server",
|
||||
SLE_UUID_SERVER_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, SLE_UUID_SERVER_TASK_PRIO);
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the app entry. */
|
||||
app_run(sle_uuid_server_entry);
|
Reference in New Issue
Block a user