Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BLE] Update Matter BT API #32

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef _MATTER_BLEMGR_COMMON_H_
#define _MATTER_BLEMGR_COMMON_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
MATTER_BLEMGR_GAP_CONNECT_CB,
MATTER_BLEMGR_GAP_DISCONNECT_CB,
MATTER_BLEMGR_RX_CHAR_WRITE_CB,
MATTER_BLEMGR_TX_CHAR_CCCD_WRITE_CB,
MATTER_BLEMGR_TX_COMPLETE_CB
} T_MATTER_BLEMGR_CALLBACK_TYPE;

typedef struct
{
uint8_t conn_id;
} T_MATTER_BLEMGR_GAP_CONNECT_CB_ARG;

typedef struct
{
uint8_t conn_id;
uint16_t disc_cause;
} T_MATTER_BLEMGR_GAP_DISCONNECT_CB_ARG;

typedef struct
{
uint8_t conn_id;
uint8_t *p_value;
uint16_t len;
} T_MATTER_BLEMGR_RX_CHAR_WRITE_CB_ARG;

typedef struct
{
uint8_t conn_id;
uint8_t indicationsEnabled;
uint8_t notificationsEnabled;
} T_MATTER_BLEMGR_TX_CHAR_CCCD_WRITE_CB_ARG;

typedef struct
{
uint8_t conn_id;
} T_MATTER_BLEMGR_TX_COMPLETE_CB_ARG;

typedef int (*matter_blemgr_callback)(void *param, T_MATTER_BLEMGR_CALLBACK_TYPE cb_type, void *p_cb_data);

int matter_blemgr_init(void);
void matter_blemgr_set_callback_func(matter_blemgr_callback p, void *data);
int matter_blemgr_start_adv(void);
int matter_blemgr_stop_adv(void);
int matter_blemgr_config_adv(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t *adv_data, uint8_t adv_data_length);
uint16_t matter_blemgr_get_mtu(uint8_t connect_id);
int matter_blemgr_set_device_name(char *device_name, uint8_t device_name_length);
int matter_blemgr_disconnect(uint8_t connect_id);
int matter_blemgr_send_indication(uint8_t connect_id, uint8_t *data, uint16_t data_length);

#ifdef __cplusplus
}
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
#include <diag.h>
#include "platform_stdlib.h"

#define BT_MATTER_ADAPTER_SERVICE_CHAR_RX_INDEX 0x02
#define BT_MATTER_ADAPTER_SERVICE_CHAR_TX_INDEX 0x04
#define BT_MATTER_ADAPTER_SERVICE_CHAR_NOTIFY_CCCD_INDEX (BT_MATTER_ADAPTER_SERVICE_CHAR_TX_INDEX + 1)
#define BT_MATTER_ADAPTER_SERVICE_C3_INDEX 0x07

#define UUID_RX 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18
#define UUID_TX 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18
#define UUID_C3 0x04, 0x8F, 0x21, 0x83, 0x8A, 0x74, 0x7D, 0xB8, 0xF2, 0x45, 0x72, 0x87, 0x38, 0x02, 0x63, 0x64
Expand Down Expand Up @@ -83,7 +78,7 @@ T_ATTRIB_APPL bt_matter_adapter_service_tbl[] =
{ /* type_value */
LO_WORD(GATT_UUID_CHARACTERISTIC),
HI_WORD(GATT_UUID_CHARACTERISTIC),
(GATT_CHAR_PROP_READ | GATT_CHAR_PROP_NOTIFY) /* characteristic properties */
(GATT_CHAR_PROP_READ | GATT_CHAR_PROP_INDICATE) /* characteristic properties */
/* characteristic UUID not needed here, is UUID of next attrib. */
},
1, /* bValueLen */
Expand Down Expand Up @@ -283,9 +278,9 @@ void bt_matter_adapter_service_cccd_update_cb(uint8_t conn_id, T_SERVER_ID servi
//printf("simp_ble_service_cccd_update_cb: index = %d, cccbits 0x%x\r\n", index, cccbits);
switch (index)
{
case BT_MATTER_ADAPTER_SERVICE_CHAR_NOTIFY_CCCD_INDEX:
case BT_MATTER_ADAPTER_SERVICE_CHAR_INDICATE_CCCD_INDEX:
{
if (cccbits & GATT_CLIENT_CHAR_CONFIG_NOTIFY)
if (cccbits & GATT_CLIENT_CHAR_CONFIG_INDICATE)
{
// Enable Notification
callback_data.msg_data.notification_indification_index = MATTER_NOTIFY_INDICATE_V3_ENABLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ typedef enum
//#define SIMP_NOTIFY_INDICATE_V4_ENABLE 3
//#define SIMP_NOTIFY_INDICATE_V4_DISABLE 4

#define BT_MATTER_ADAPTER_SERVICE_CHAR_RX_INDEX 0x02
#define BT_MATTER_ADAPTER_SERVICE_CHAR_TX_INDEX 0x04
#define BT_MATTER_ADAPTER_SERVICE_CHAR_INDICATE_CCCD_INDEX (BT_MATTER_ADAPTER_SERVICE_CHAR_TX_INDEX + 1)
#define BT_MATTER_ADAPTER_SERVICE_C3_INDEX 0x07

/** @defgroup SIMP_Service_Read_Info SIMP Service Read Info
* @brief Parameter for reading characteristic value.
* @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <gap_le_types.h>
#include <simple_ble_service.h>
#include <gcs_client.h>
#include "matter_blemgr_common.h"

/*********************************************************************************************************/
int bt_mesh_device_matter_scan_state = 0;
Expand All @@ -72,21 +73,15 @@ bool mesh_initial_state = FALSE;

uint8_t bt_mesh_device_matter_config_adv_flag = 0;

chip_blemgr_callback chip_blemgr_callback_func = NULL;
void *chip_blemgr_callback_data = NULL;
extern matter_blemgr_callback matter_blemgr_callback_func;
extern void *matter_blemgr_callback_data;

extern uint8_t bt_mesh_device_matter_adv_data[31];
extern uint8_t bt_mesh_device_matter_le_adv_start_enable;
extern void bt_mesh_device_matter_le_adv_start(void);
extern void bt_mesh_device_matter_le_adv_stop(void);

/*************************************************************************************************************************/
void chip_blemgr_set_callback_func(chip_blemgr_callback p, void *data)
{
chip_blemgr_callback_func = p;
chip_blemgr_callback_data = data;
}

int bt_mesh_device_matter_app_handle_upstream_msg(uint16_t subtype, void *pdata)
{
int ret = 0;
Expand All @@ -108,46 +103,90 @@ void bt_mesh_device_matter_handle_callback_msg(T_IO_MSG callback_msg)//receive

switch (msg_type)
{
case BT_MATTER_SEND_CB_MSG_DISCONNECTED:
case BT_MATTER_SEND_CB_MSG_CONNECTED:
{
if (chip_blemgr_callback_func) {
chip_blemgr_callback_func(chip_blemgr_callback_data, callback_msg.u.buf, 0, CB_GAP_MSG_CONN_EVENT);
BT_MATTER_CONN_EVENT *connected = callback_msg.u.buf;
T_MATTER_BLEMGR_GAP_CONNECT_CB_ARG gap_connect_cb_arg;
gap_connect_cb_arg.conn_id = connected->conn_id;
if (matter_blemgr_callback_func) {
matter_blemgr_callback_func(matter_blemgr_callback_data, MATTER_BLEMGR_GAP_CONNECT_CB, &gap_connect_cb_arg);
}
os_mem_free(callback_msg.u.buf);
callback_msg.u.buf = NULL;
}
break;
case BT_MATTER_SEND_CB_MSG_ALL_GAP_MSG:

case BT_MATTER_SEND_CB_MSG_DISCONNECTED:
{
BT_MATTER_CONN_EVENT *disconnected = callback_msg.u.buf;
T_MATTER_BLEMGR_GAP_DISCONNECT_CB_ARG gap_disconnect_cb_arg;
gap_disconnect_cb_arg.conn_id = disconnected->conn_id;
gap_disconnect_cb_arg.disc_cause = disconnected->disc_cause;
if (matter_blemgr_callback_func) {
matter_blemgr_callback_func(matter_blemgr_callback_data, MATTER_BLEMGR_GAP_DISCONNECT_CB, &gap_disconnect_cb_arg);
}
os_mem_free(callback_msg.u.buf);
callback_msg.u.buf = NULL;
}
break;
case BT_MATTER_SEND_CB_MSG_SEND_DATA_COMPLETE:

case BT_MATTER_SEND_CB_MSG_READ_WRITE_CHAR:
{
uint8_t service_id = callback_msg.subtype;
if (chip_blemgr_callback_func) {
chip_blemgr_callback_func(chip_blemgr_callback_data, callback_msg.u.buf, service_id, CB_PROFILE_CALLBACK);
T_MATTER_CALLBACK_DATA *read_write_char_val = callback_msg.u.buf;
T_MATTER_BLEMGR_RX_CHAR_WRITE_CB_ARG rx_char_write_cb_arg;
rx_char_write_cb_arg.conn_id = read_write_char_val->conn_id;
rx_char_write_cb_arg.p_value = read_write_char_val->msg_data.write.p_value;
rx_char_write_cb_arg.len = read_write_char_val->msg_data.write.len;
if (matter_blemgr_callback_func) {
matter_blemgr_callback_func(matter_blemgr_callback_data, MATTER_BLEMGR_RX_CHAR_WRITE_CB, &rx_char_write_cb_arg);
}
if (read_write_char_val->msg_data.write.len != 0)
{
os_mem_free(read_write_char_val->msg_data.write.p_value);
read_write_char_val->msg_data.write.p_value = NULL;
}
os_mem_free(callback_msg.u.buf);
callback_msg.u.buf = NULL;
}
break;
case BT_MATTER_SEND_CB_MSG_IND_NTF_DISABLE:

case BT_MATTER_SEND_CB_MSG_IND_NTF_ENABLE:
case BT_MATTER_SEND_CB_MSG_READ_WRITE_CHAR:
case BT_MATTER_SEND_CB_MSG_IND_NTF_DISABLE:
{
uint8_t service_id = callback_msg.subtype;
if (chip_blemgr_callback_func) {
chip_blemgr_callback_func(chip_blemgr_callback_data, callback_msg.u.buf, service_id, CB_PROFILE_CALLBACK);
T_MATTER_CALLBACK_DATA *indication_notification_enable = callback_msg.u.buf;
T_MATTER_BLEMGR_TX_CHAR_CCCD_WRITE_CB_ARG tx_char_cccd_write_cb_arg;
tx_char_cccd_write_cb_arg.conn_id = indication_notification_enable->conn_id;
if (msg_type == BT_MATTER_SEND_CB_MSG_IND_NTF_DISABLE)
tx_char_cccd_write_cb_arg.indicationsEnabled = 0;
else if (msg_type == BT_MATTER_SEND_CB_MSG_IND_NTF_ENABLE)
tx_char_cccd_write_cb_arg.indicationsEnabled = 1;
tx_char_cccd_write_cb_arg.notificationsEnabled = 0;
if (matter_blemgr_callback_func) {
matter_blemgr_callback_func(matter_blemgr_callback_data, MATTER_BLEMGR_TX_CHAR_CCCD_WRITE_CB, &tx_char_cccd_write_cb_arg);
}
T_MATTER_CALLBACK_DATA *pp_param = (T_MATTER_CALLBACK_DATA *)callback_msg.u.buf;
if (pp_param->msg_data.write.len !=0)
if (indication_notification_enable->msg_data.write.len != 0)
{
os_mem_free(pp_param->msg_data.write.p_value);
pp_param->msg_data.write.p_value = NULL;
os_mem_free(indication_notification_enable->msg_data.write.p_value);
indication_notification_enable->msg_data.write.p_value = NULL;
}
os_mem_free(callback_msg.u.buf);
callback_msg.u.buf = NULL;
}
break;

case BT_MATTER_SEND_CB_MSG_SEND_DATA_COMPLETE:
{
T_SERVER_APP_CB_DATA *send_data_complete = callback_msg.u.buf;
T_MATTER_BLEMGR_TX_COMPLETE_CB_ARG tx_complete_cb_arg;
tx_complete_cb_arg.conn_id = send_data_complete->event_data.send_data_result.conn_id;
if (matter_blemgr_callback_func) {
matter_blemgr_callback_func(matter_blemgr_callback_data, MATTER_BLEMGR_TX_COMPLETE_CB, &tx_complete_cb_arg);
}
os_mem_free(callback_msg.u.buf);
callback_msg.u.buf = NULL;
}
break;

default:
break;
}
Expand Down Expand Up @@ -202,9 +241,11 @@ void bt_mesh_device_matter_app_handle_io_msg(T_IO_MSG io_msg)
gap_sched_scan(false);
} else if (io_msg.subtype == 3) {
gap_sched_scan(true);
}
else if (io_msg.subtype == 4) {
} else if (io_msg.subtype == 4) {
bt_mesh_device_matter_app_handle_upstream_msg(io_msg.subtype, io_msg.u.buf);
} else if (io_msg.subtype == 5) {
uint8_t conn_id = io_msg.u.buf;
le_disconnect(conn_id);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ typedef enum
{
BT_MATTER_SEND_CB_MSG_DISCONNECTED = 1,
BT_MATTER_SEND_CB_MSG_CONNECTED,
BT_MATTER_SEND_CB_MSG_ALL_GAP_MSG,
BT_MATTER_SEND_CB_MSG_SEND_DATA_COMPLETE,
BT_MATTER_SEND_CB_MSG_IND_NTF_ENABLE,
BT_MATTER_SEND_CB_MSG_IND_NTF_DISABLE,
Expand Down
Loading