Files
hpw421/component/ble/ip/ble/api/xc_gatt_server_api.c
T
2026-07-03 18:08:25 +08:00

131 lines
4.7 KiB
C

/**
****************************************************************************************
* @file xc_gatt_server_api.c
* @brief GATT server APIs source code
* Copyright (c) 2022 - 2025, XinChip
* All rights reserved.
****************************************************************************************
*/
#include "rwip_config.h"
#if (BLE_APP_PRESENT)
#include "xc_gatt_server_api.h"
//uint16_t xc_ble_gatt_user_srv_register(uint16_t pref_mtu, uint8_t prio_level,
// const gatt_srv_cb_t *p_cb,
// uint8_t *p_user_lid)
//{
// return gatt_user_srv_register(pref_mtu, prio_level, p_cb, p_user_lid);
//}
uint16_t xc_ble_gatt_service_add(uint8_t user_lid, uint8_t info,
const uint8_t *p_uuid, uint8_t nb_att,
const uint8_t *p_att_mask,
const gatt_att_desc_t *p_atts,
uint8_t nb_att_rsvd, uint16_t *p_start_hdl)
{
return gatt_db_svc_add(user_lid, info, p_uuid, nb_att, p_att_mask, p_atts,
nb_att_rsvd, p_start_hdl);
}
//uint16_t xc_ble_gatt_service16_add(uint8_t user_lid, uint8_t info,
// uint16_t uuid16, uint8_t nb_att,
// const uint8_t *p_att_mask,
// const gatt_att16_desc_t *p_atts,
// uint8_t nb_att_rsvd, uint16_t *p_start_hdl)
//{
// return gatt_db_svc16_add(user_lid, info, uuid16, nb_att, p_att_mask, p_atts,
// nb_att_rsvd, p_start_hdl);
//}
#if (MIN_STACK)
uint16_t xc_ble_gatt_service_remove(uint8_t user_lid, uint16_t start_hdl)
{
return gatt_db_svc_remove(user_lid, start_hdl);
}
#endif // (MIN_STACK)
//uint16_t xc_ble_gatt_srv_notify(uint8_t conidx, uint8_t user_lid,
// uint16_t dummy, uint16_t hdl, uint16_t length,
// const uint8_t *p_value)
//{
// co_buf_t *p_data;
// uint16_t status;
// // allocate a buffer for event transmission
// if (co_buf_alloc(&p_data, GATT_BUFFER_HEADER_LEN, length,
// GATT_BUFFER_TAIL_LEN) != CO_BUF_ERR_NO_ERROR) {
// status = ATT_ERR_INSUFF_RESOURCE;
// } else {
// // copy data into buffer
// co_buf_copy_data_from_mem(p_data, p_value, length);
// // request event to be sent
// status = gatt_srv_event_send(conidx, user_lid, dummy, GATT_NOTIFY, hdl,
// p_data);
// co_buf_release(p_data);
// }
// return status;
//}
uint16_t xc_ble_gatt_srv_indicate(uint8_t conidx, uint8_t user_lid,
uint16_t dummy, uint16_t hdl, uint16_t length,
const uint8_t *p_value)
{
co_buf_t *p_data;
uint16_t status;
// allocate a buffer for event transmission
if (co_buf_alloc(&p_data, GATT_BUFFER_HEADER_LEN, length,
GATT_BUFFER_TAIL_LEN) != CO_BUF_ERR_NO_ERROR) {
status = ATT_ERR_INSUFF_RESOURCE;
} else {
// copy data into buffer
co_buf_copy_data_from_mem(p_data, p_value, length);
// request event to be sent
status = gatt_srv_event_send(conidx, user_lid, dummy, GATT_INDICATE,
hdl, p_data);
co_buf_release(p_data);
}
return status;
}
//uint16_t xc_ble_gatt_srv_read_cfm(uint8_t conidx, uint8_t user_lid,
// uint16_t token, uint16_t status,
// uint16_t att_length, uint16_t length,
// const uint8_t *p_value)
//{
// co_buf_t *p_data = NULL;
// uint8_t state;
// if (status == GAP_ERR_NO_ERROR) {
// // allocate a buffer for event transmission
// if (co_buf_alloc(&p_data, GATT_BUFFER_HEADER_LEN, length,
// GATT_BUFFER_TAIL_LEN) != CO_BUF_ERR_NO_ERROR) {
// status = ATT_ERR_INSUFF_RESOURCE;
// } else {
// // copy data into buffer
// co_buf_copy_data_from_mem(p_data, p_value, length);
// }
// }
// // execute confirmation native function
// state = gatt_srv_att_read_get_cfm(conidx, user_lid, token, status,
// att_length, p_data);
// // release buffer
// if (p_data != NULL) {
// co_buf_release(p_data);
// }
// return state;
//}
//uint16_t xc_ble_gatt_srv_write_cfm(uint8_t conidx, uint8_t user_lid,
// uint16_t token, uint16_t status)
//{
// return gatt_srv_att_val_set_cfm(conidx, user_lid, token, status);
//}
#endif // (BLE_APP_PRESENT)