Skip to content

Commit

Permalink
os/board/rtl8730e: add API to return BLE indication queue count
Browse files Browse the repository at this point in the history
- add ble_server_get_indicate_pending_count API that returns current indication queue count to application
  • Loading branch information
yeetee179 committed May 27, 2024
1 parent 028e27b commit 5860646
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 0 deletions.
13 changes: 13 additions & 0 deletions framework/src/ble_manager/ble_manager_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ ble_result_e ble_server_charact_indicate(ble_attr_handle attr_handle, ble_conn_h
RETURN_RESULT(res, msg);
}

ble_result_e ble_server_get_indicate_pending_count(ble_conn_handle con_handle, uint8_t *count)
{
if (count == NULL)
{
return BLE_MANAGER_INVALID_ARGS;
}
blemgr_msg_params param = { 2, {(void *)&con_handle, (void *)count} };
blemgr_msg_s msg = {BLE_CMD_GET_INDICATE_PENDING_CNT, BLE_MANAGER_FAIL, (void *)(&param), NULL};
int res = blemgr_post_message(&msg);

RETURN_RESULT(res, msg);
}

ble_result_e ble_server_attr_set_data(ble_attr_handle attr_handle, ble_data *data)
{
blemgr_msg_params param = { 2, {(void *)&attr_handle, (void *)data} };
Expand Down
1 change: 1 addition & 0 deletions framework/src/ble_manager/ble_manager_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef enum {
BLE_CMD_GET_PROFILE_COUNT,
BLE_CMD_CHARACT_NOTI,
BLE_CMD_CHARACT_INDI,
BLE_CMD_GET_INDICATE_PENDING_CNT,
BLE_CMD_ATTR_SET_DATA,
BLE_CMD_ATTR_GET_DATA,
BLE_CMD_ATTR_REJECT,
Expand Down
11 changes: 11 additions & 0 deletions framework/src/ble_manager/ble_manager_lwnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ trble_result_e ble_drv_charact_indicate(trble_attr_handle attr_handle, trble_con
return res;
}

trble_result_e ble_drv_get_indicate_pending_cnt(trble_conn_handle *conn_handle, uint8_t *indicate_count)
{
trble_result_e res = TRBLE_SUCCESS;
lwnl_msg_params msg_data = { 2, {(void *)conn_handle, (void *)indicate_count} };
lwnl_msg msg = {BLE_INTF_NAME, {LWNL_REQ_BLE_GET_INDICATE_PENDDING_CNT}, sizeof(msg_data), (void *)&msg_data, (void *)&res};
if (_send_msg(&msg) < 0) {
res = TRBLE_FILE_ERROR;
}
return res;
}

trble_result_e ble_drv_attr_set_data(trble_attr_handle attr_handle, trble_data *data)
{
trble_result_e res = TRBLE_SUCCESS;
Expand Down
10 changes: 10 additions & 0 deletions framework/src/ble_manager/ble_manager_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,16 @@ ble_result_e blemgr_handle_request(blemgr_msg_s *msg)
ret = ble_drv_charact_indicate(attr_handle, con_handle, data);
} break;

case BLE_CMD_GET_INDICATE_PENDDING_CNT: {
BLE_STATE_CHECK;

blemgr_msg_params *param = (blemgr_msg_params *)msg->param;
trble_conn_handle *conn_handle = (trble_conn_handle *)param->param[0];
uint8_t *indicate_count = (uint8_t *)param->param[1];

ret = ble_drv_get_indicate_pending_cnt(conn_handle, indicate_count);
} break;

case BLE_CMD_ATTR_SET_DATA: {
BLE_STATE_CHECK;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <mem_types.h>
#include <bt_utils.h>
#include <rtk_service_config.h>
#include <rtk_stack_gatt.h>
#include <gap_msg.h>
#include <ble_tizenrt_service.h>

Expand Down Expand Up @@ -310,6 +311,26 @@ trble_result_e rtw_ble_server_charact_indicate(trble_attr_handle attr_handle, tr
osif_mem_free(param.data);
return TRBLE_SUCCESS;
}

extern rtk_bt_gatts_app_priv_t *g_rtk_bt_gatts_priv;
trble_result_e rtw_ble_server_indicate_queue_cnt(trble_conn_handle *con_handle, uint8_t *indication_count)
{
uint8_t con_id;
rtk_bt_le_gap_get_conn_id(*con_handle, &con_id);
rtk_bt_gatt_queue_t *queue;
queue = &g_rtk_bt_gatts_priv->indicate_queue[con_id];
*indication_count = queue->pending_ele_num;

/* The number of element in pending queue should be limited, otherwise
the notification of high frequnce will use up memory */
if (queue->pending_ele_num >= BT_QUEUE_PENDING_ELEMENT_MAX)
{
printf("Error: GATTS pending queue full, wait a moment to send data again !!!\r\n");
return TRBLE_BUSY;
}

return TRBLE_SUCCESS;
}

trble_result_e rtw_ble_server_reject(trble_attr_handle attr_handle, uint8_t app_errorcode)
{
Expand Down
7 changes: 7 additions & 0 deletions os/board/rtl8730e/src/component/os/tizenrt/rtk_blemgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ trble_result_e trble_netmgr_operation_write_no_response(struct bledev *dev, trbl
trble_result_e trble_netmgr_get_profile_count(struct bledev *dev, uint16_t *count);
trble_result_e trble_netmgr_charact_notify(struct bledev *dev, trble_attr_handle attr_handle, trble_conn_handle con_handle, trble_data *data);
trble_result_e trble_netmgr_charact_indicate(struct bledev *dev, trble_attr_handle attr_handle, trble_conn_handle con_handle, trble_data *data);
trble_result_e trble_netmgr_indicate_queue_count(struct bledev *dev, trble_conn_handle *con_handle, uint8_t *count);
trble_result_e trble_netmgr_attr_set_data(struct bledev *dev, trble_attr_handle attr_handle, trble_data *data);
trble_result_e trble_netmgr_attr_get_data(struct bledev *dev, trble_attr_handle attr_handle, trble_data *data);
trble_result_e trble_netmgr_attr_reject(struct bledev *dev, trble_attr_handle attr_handle, uint8_t app_errorcode);
Expand Down Expand Up @@ -140,6 +141,7 @@ struct trble_ops g_trble_drv_ops = {
trble_netmgr_get_profile_count,
trble_netmgr_charact_notify,
trble_netmgr_charact_indicate,
trble_netmgr_indicate_queue_count,
trble_netmgr_attr_set_data,
trble_netmgr_attr_get_data,
trble_netmgr_attr_reject,
Expand Down Expand Up @@ -377,6 +379,11 @@ trble_result_e trble_netmgr_charact_indicate(struct bledev *dev, trble_attr_hand
return rtw_ble_server_charact_indicate(attr_handle, con_handle, data->data, data->length);
}

trble_result_e trble_netmgr_indicate_queue_count(struct bledev *dev, trble_conn_handle *con_handle, uint8_t *count)
{
return rtw_ble_server_indicate_queue_cnt(con_handle, count);
}

trble_result_e trble_netmgr_attr_set_data(struct bledev *dev, trble_attr_handle attr_handle, trble_data *data)
{
trble_result_e ret = rtw_ble_server_att_set_data_ptr(attr_handle, data->data);
Expand Down
3 changes: 3 additions & 0 deletions os/include/tinyara/net/if/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef enum {
LWNL_REQ_BLE_GET_PROFILE_COUNT,
LWNL_REQ_BLE_CHARACT_NOTI,
LWNL_REQ_BLE_CHARACT_INDI,
LWNL_REQ_BLE_GET_INDICATE_PENDDING_CNT,
LWNL_REQ_BLE_ATTR_SET_DATA,
LWNL_REQ_BLE_ATTR_GET_DATA,
LWNL_REQ_BLE_ATTR_REJECT,
Expand Down Expand Up @@ -365,6 +366,7 @@ typedef trble_result_e (*trble_get_profile_count)(struct bledev *dev, uint16_t *
typedef trble_result_e (*trble_charact_notify)(struct bledev *dev, trble_attr_handle attr_handle, trble_conn_handle con_handle, trble_data *data);
// API for sending a characteristic value indicate to the selected target(s). (notify to all clients conn_handle (notify all = 0x99))
typedef trble_result_e (*trble_charact_indicate)(struct bledev *dev, trble_attr_handle attr_handle, trble_conn_handle con_handle, trble_data *data);
typedef trble_result_e (*trble_get_indicate_queue_cnt)(struct bledev *dev, trble_conn_handle *con_handle, uint8_t *count);
typedef trble_result_e (*trble_attr_set_data)(struct bledev *dev, trble_attr_handle attr_handle, trble_data *data);
typedef trble_result_e (*trble_attr_get_data)(struct bledev *dev, trble_attr_handle attr_handle, trble_data *data);
// reject attribute request in callback function and return error code
Expand Down Expand Up @@ -424,6 +426,7 @@ struct trble_ops {
trble_get_profile_count get_profile_count;
trble_charact_notify charact_noti;
trble_charact_indicate charact_indi;
trble_get_indicate_queue_cnt get_indi_queue_cnt;
trble_attr_set_data attr_set_data;
trble_attr_get_data attr_get_data;
trble_attr_reject attr_reject;
Expand Down
18 changes: 18 additions & 0 deletions os/net/blemgr/bledev.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,24 @@ int bledev_handle(struct bledev *dev, lwnl_req cmd, void *data, uint32_t data_le
TRBLE_DRV_CALL(ret, dev, charact_indi, (dev, attr_handle, con_handle, buf));
}
break;
case LWNL_REQ_BLE_GET_INDICATE_PENDDING_CNT:
{
trble_conn_handle *con_handle = NULL;
uint8_t *indicate_count = NULL;

lwnl_msg_params param = { 0, };
if (data != NULL) {
memcpy(&param, data, data_len);
} else {
return TRBLE_INVALID_ARGS;
}

con_handle = (trble_conn_handle *)param.param[0];
indicate_count = (uint8_t *)param.param[1];

TRBLE_DRV_CALL(ret, dev, get_indi_queue_cnt, (dev, con_handle, indicate_count));
}
break;
case LWNL_REQ_BLE_ATTR_SET_DATA:
{
trble_attr_handle attr_handle = 0;
Expand Down

0 comments on commit 5860646

Please sign in to comment.