BLE5.2 1.0
开发文档说明
xc_gatt_server_api.c
浏览该文件的文档.
1
9#include "rwip_config.h"
10#if (BLE_APP_PRESENT)
11#include "xc_gatt_server_api.h"
12
13uint16_t xc_ble_gatt_user_srv_register(uint16_t pref_mtu, uint8_t prio_level,
14 const gatt_srv_cb_t *p_cb,
15 uint8_t *p_user_lid)
16{
17 return gatt_user_srv_register(pref_mtu, prio_level, p_cb, p_user_lid);
18}
19
20uint16_t xc_ble_gatt_service_add(uint8_t user_lid, uint8_t info,
21 const uint8_t *p_uuid, uint8_t nb_att,
22 const uint8_t *p_att_mask,
23 const gatt_att_desc_t *p_atts,
24 uint8_t nb_att_rsvd, uint16_t *p_start_hdl)
25{
26 return gatt_db_svc_add(user_lid, info, p_uuid, nb_att, p_att_mask, p_atts,
27 nb_att_rsvd, p_start_hdl);
28}
29
30uint16_t xc_ble_gatt_service16_add(uint8_t user_lid, uint8_t info,
31 uint16_t uuid16, uint8_t nb_att,
32 const uint8_t *p_att_mask,
33 const gatt_att16_desc_t *p_atts,
34 uint8_t nb_att_rsvd, uint16_t *p_start_hdl)
35{
36 return gatt_db_svc16_add(user_lid, info, uuid16, nb_att, p_att_mask, p_atts,
37 nb_att_rsvd, p_start_hdl);
38}
39
40uint16_t xc_ble_gatt_service_remove(uint8_t user_lid, uint16_t start_hdl)
41{
42 return gatt_db_svc_remove(user_lid, start_hdl);
43}
44
45uint16_t xc_ble_gatt_srv_notify(uint8_t conidx, uint8_t user_lid,
46 uint16_t dummy, uint16_t hdl, uint16_t length,
47 const uint8_t *p_value)
48{
49 co_buf_t *p_data;
50 uint16_t status;
51
52 // allocate a buffer for event transmission
53 if (co_buf_alloc(&p_data, GATT_BUFFER_HEADER_LEN, length,
54 GATT_BUFFER_TAIL_LEN) != CO_BUF_ERR_NO_ERROR) {
55 status = ATT_ERR_INSUFF_RESOURCE;
56 } else {
57 // copy data into buffer
58 co_buf_copy_data_from_mem(p_data, p_value, length);
59
60 // request event to be sent
61 status = gatt_srv_event_send(conidx, user_lid, dummy, GATT_NOTIFY, hdl,
62 p_data);
63
64 co_buf_release(p_data);
65 }
66 return status;
67}
68
69uint16_t xc_ble_gatt_srv_indicate(uint8_t conidx, uint8_t user_lid,
70 uint16_t dummy, uint16_t hdl, uint16_t length,
71 const uint8_t *p_value)
72{
73 co_buf_t *p_data;
74 uint16_t status;
75
76 // allocate a buffer for event transmission
77 if (co_buf_alloc(&p_data, GATT_BUFFER_HEADER_LEN, length,
78 GATT_BUFFER_TAIL_LEN) != CO_BUF_ERR_NO_ERROR) {
79 status = ATT_ERR_INSUFF_RESOURCE;
80 } else {
81 // copy data into buffer
82 co_buf_copy_data_from_mem(p_data, p_value, length);
83
84 // request event to be sent
85 status = gatt_srv_event_send(conidx, user_lid, dummy, GATT_INDICATE,
86 hdl, p_data);
87
88 co_buf_release(p_data);
89 }
90 return status;
91}
92
93uint16_t xc_ble_gatt_srv_read_cfm(uint8_t conidx, uint8_t user_lid,
94 uint16_t token, uint16_t status,
95 uint16_t att_length, uint16_t length,
96 const uint8_t *p_value)
97{
98
99 co_buf_t *p_data = NULL;
100 uint8_t state;
101 if (status == GAP_ERR_NO_ERROR) {
102 // allocate a buffer for event transmission
103 if (co_buf_alloc(&p_data, GATT_BUFFER_HEADER_LEN, length,
104 GATT_BUFFER_TAIL_LEN) != CO_BUF_ERR_NO_ERROR) {
105 status = ATT_ERR_INSUFF_RESOURCE;
106 } else {
107 // copy data into buffer
108 co_buf_copy_data_from_mem(p_data, p_value, length);
109 }
110 }
111
112 // execute confirmation native function
113 state = gatt_srv_att_read_get_cfm(conidx, user_lid, token, status,
114 att_length, p_data);
115
116 // release buffer
117 if (p_data != NULL) {
118 co_buf_release(p_data);
119 }
120 return state;
121}
122
123uint16_t xc_ble_gatt_srv_write_cfm(uint8_t conidx, uint8_t user_lid,
124 uint16_t token, uint16_t status)
125{
126 return gatt_srv_att_val_set_cfm(conidx, user_lid, token, status);
127}
128#endif // (BLE_APP_PRESENT)
uint16_t xc_ble_gatt_service_remove(uint8_t user_lid, uint16_t start_hdl)
Command used to remove a service from local attribute database.
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)
Command used to register a GATT user. This must be done prior to any GATT procedure execution.
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)
Upper layer provide attribute value requested by GATT Layer for a read procedure If rejected,...
uint16_t xc_ble_gatt_srv_write_cfm(uint8_t conidx, uint8_t user_lid, uint16_t token, uint16_t status)
Upper layer provide status of attribute value modification by GATT server user. Confirmation server u...
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)
Command used to add a service into local attribute database.
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)
Command used by a GATT server user to send indication
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)
Command used by a GATT server user to send notifications
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)
Command used to add a service into local attribute database.
GATT server API. Copyright (c) 2022 - 2025, XinChip All rights reserved.