GATT Server Exported Functions
- group GATT_SERVER_Exported_Functions
-
Functions
-
bool server_add_service(T_SERVER_ID *p_out_service_id, uint8_t *p_database, uint16_t length, const T_FUN_GATT_SERVICE_CBS srv_cbs)
-
Register specific service without start handle.
Add specific service information to gatt_svc_table struct, will be registered to GATT later.
Example usage
T_SERVER_ID bas_add_service(void *p_func) { T_SERVER_ID service_id; if (false == server_add_service(&service_id, (uint8_t *)bas_attr_tbl, bas_attr_tbl_size, bas_cbs)) { APP_PRINT_ERROR1("bas_add_service: service_id %d", service_id); service_id = 0xFF; } pfn_bas_cb = (P_FUN_SERVER_GENERAL_CB)p_func; return service_id; }
- Parameters:
p_out_service_id -- [inout] Pointer to Service ID of specific service.
p_database -- [in] Pointer to Database of specific service.
length -- [in] Length of Database of specific service.
srv_cbs -- [in] Service callback functions of specific service.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
bool server_add_service_by_start_handle(uint8_t *p_out_service_id, uint8_t *p_database, uint16_t length, const T_FUN_GATT_SERVICE_CBS srv_cbs, uint16_t start_handle)
-
Register specific service with start handle.
Add specific service information to gatt_svc_table struct, will be registered to GATT later.
Example usage
T_SERVER_ID bas_add_service(void *p_func) { T_SERVER_ID service_id; if (false == server_add_service_by_start_handle(&service_id, (uint8_t *)bas_attr_tbl, bas_attr_tbl_size, bas_cbs, 0x00f0)) { APP_PRINT_ERROR1("bas_add_service: service_id %d", service_id); service_id = 0xFF; } pfn_bas_cb = (P_FUN_SERVER_GENERAL_CB)p_func; return service_id; }
- Parameters:
p_out_service_id -- [inout] Pointer to Service ID of specific service.
p_database -- [in] Pointer to Database of specific service.
length -- [in] Length of Database of specific service.
srv_cbs -- [in] Service callback functions of specific service.
start_handle -- [in] Start handle of this service.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
void server_register_app_cb(P_FUN_SERVER_GENERAL_CB p_fun_cb)
-
Register callback function to send events to application.
Example usage
void app_le_profile_init(void) { server_init(service_num); simp_srv_id = simp_ble_service_add_service(app_profile_callback); server_register_app_cb(app_profile_callback); }
- Parameters:
-
p_fun_cb -- [in] Callback function.
-
bool server_attr_read_confirm(uint8_t conn_id, T_SERVER_ID service_id, uint16_t attrib_index, uint8_t *p_data, uint16_t data_len, T_APP_RESULT cause)
-
Confirm from application when receiving a read request from client.
- Parameters:
conn_id -- [in] Connection ID indicates which link it is.
service_id -- [in] Service ID T_SERVER_ID.
attrib_index -- [in] Attribute index of attribute to read confirm from application.
p_data -- [in] Pointer to the read value.
data_len -- [in] The length of the data.
cause -- [in] Cause for read confirmation. Value is T_APP_RESULT.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
bool server_exec_write_confirm(uint8_t conn_id, uint16_t cause, uint16_t handle)
-
Confirm from application when receiving an Execute Write Request from the client.
- Parameters:
conn_id -- [in] Connection ID indicates which link it is.
cause -- [in] Cause for execute write confirmation. Value is T_APP_RESULT.
handle -- [in] GATT attribute handle.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
bool server_attr_write_confirm(uint8_t conn_id, T_SERVER_ID service_id, uint16_t attrib_index, T_APP_RESULT cause)
-
Confirm from application when receiving a Write Request from the client.
- Parameters:
conn_id -- [in] Connection ID indicates which link it is.
service_id -- [in] Service ID T_SERVER_ID.
attrib_index -- [in] Attribute index of attribute to write confirm from application.
cause -- [in] Cause for write confirmation. Value is T_APP_RESULT.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
bool server_send_data(uint8_t conn_id, T_SERVER_ID service_id, uint16_t attrib_index, uint8_t *p_data, uint16_t data_len, T_GATT_PDU_TYPE type)
-
Send a notification or indication to peer device.
If sending request operation is successful, the sending result will be returned by callback registered by server_register_app_cb with service_id set to SERVICE_PROFILE_GENERAL_ID, and eventId of p_data (T_SERVER_APP_CB_DATA) set to PROFILE_EVT_SEND_DATA_COMPLETE.
Example usage
bool bas_battery_level_value_notify(uint8_t conn_id, uint8_t service_id, uint8_t battery_level) { return server_send_data(conn_id, service_id, GATT_SVC_BAS_BATTERY_LEVEL_INDEX, &battery_level, sizeof(battery_level), GATT_PDU_TYPE_ANY); }
- Parameters:
conn_id -- [in] Connection ID indicates which link it is.
service_id -- [in] Service ID T_SERVER_ID.
attrib_index -- [in] Attribute index of characteristic.
p_data -- [in] Pointer to data to be sent.
data_len -- [in] Length of value to be sent, range: 0~(mtu_size - 3). uint16_t mtu_size is acquired by le_get_conn_param (GAP_PARAM_CONN_MTU_SIZE, &mtu_size, conn_id).
type -- [in] GATT PDU type T_GATT_PDU_TYPE.
- Return values:
true -- Sending request operation is successful.
false -- Sending request operation is failed.
- Returns:
-
The result of sending request.
-
bool server_get_write_cmd_data_buffer(uint8_t conn_id, uint8_t **pp_buffer, uint16_t *p_offset)
-
Get the header point of the write command data buffer.
This function is used to get the buffer point of the write command data. This function only can be called in write_attr_cb.
Example usage
uint8_t *p_data_buf; uint16_t data_offset; T_APP_RESULT simp_ble_service_attr_write_cb(uint8_t conn_id, T_SERVER_ID service_id, uint16_t attrib_index, T_WRITE_TYPE write_type, uint16_t length, uint8_t *p_value, P_FUN_WRITE_IND_POST_PROC *p_write_ind_post_proc) { ...... server_get_write_cmd_data_buffer(conn_id, &p_data_buf, &data_offset); return APP_RESULT_NOT_RELEASE; } void release(void) { if(p_data_buf != NULL) { gap_buffer_free(p_data_buf); p_data_buf = NULL; } }
- Parameters:
conn_id -- [in] Connection ID indicates which link it is.
pp_buffer -- [inout] Pointer to the address of the buffer.
p_offset -- [inout] Pointer to the offset of the data.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
bool server_send_multi_notify(uint8_t conn_id, uint8_t *p_data, uint16_t data_len)
-
Send the multiple variable notification.
If sending request operation is successful, the sending result will be returned by callback registered by server_register_app_cb with service_id set to SERVICE_PROFILE_GENERAL_ID, and eventId of p_data (T_SERVER_APP_CB_DATA) set to PROFILE_EVT_SEND_DATA_COMPLETE.
Example usage
bool simp_ble_service_send_v3_v8_notify(uint8_t conn_id, T_SERVER_ID service_id, void *p_v3_value, uint16_t v3_length, void *p_v8_value, uint16_t v8_length) { bool ret; uint8_t *p_value; uint8_t *p_data; uint16_t length = v3_length + v8_length + 2 * 4; uint16_t handle; p_value = os_mem_zalloc(OS_MEM_TYPE_DATA, length); if (p_value == NULL) { return false; } p_data = p_value; handle = server_get_start_handle(service_id) + SIMPLE_BLE_SERVICE_CHAR_V3_NOTIFY_INDEX; LE_UINT16_TO_STREAM(p_data, handle); LE_UINT16_TO_STREAM(p_data, v3_length); memcpy(p_data, p_v3_value, v3_length); p_data += v3_length; handle = server_get_start_handle(service_id) + SIMPLE_BLE_SERVICE_CHAR_V8_NOTIFY_INDICATE_INDEX; LE_UINT16_TO_STREAM(p_data, handle); LE_UINT16_TO_STREAM(p_data, v8_length); memcpy(p_data, p_v8_value, v8_length); p_data += v8_length; ret = server_send_multi_notify(conn_id, p_value, length); if (p_value) { os_mem_free(p_value); } return ret; }
- Parameters:
conn_id -- [in] Connection ID indicates which link it is.
p_data -- [in] Pointer to data to be sent.
data_len -- [in] Length of value to be sent, range: 0~(mtu_size - 1). uint16_t mtu_size is acquired by le_get_conn_param (GAP_PARAM_CONN_MTU_SIZE, &mtu_size, conn_id).
- Return values:
true -- Sending request operation is successful.
false -- Sending request operation is failed.
- Returns:
-
The result of sending request.
-
bool server_get_cccd_info(uint8_t conn_id, T_SERVER_ID service_id, uint16_t attrib_index, uint16_t *p_cccd)
-
Get the CCCD information.
Example usage
bool simp_ble_service_send_v3_notify(uint8_t conn_id, T_SERVER_ID service_id, void *p_value, uint16_t length) { uint16_t cccd_bits; APP_PRINT_INFO0("simp_ble_service_send_v3_notify"); if (server_get_cccd_info(conn_id, service_id, SIMPLE_BLE_SERVICE_CHAR_NOTIFY_CCCD_INDEX, &cccd_bits)) { APP_PRINT_INFO1("simp_ble_service_send_v3_notify: cccd_bits 0x%x", cccd_bits); } return server_send_data(conn_id, service_id, SIMPLE_BLE_SERVICE_CHAR_V3_NOTIFY_INDEX, p_value, length, GATT_PDU_TYPE_ANY); }
- Parameters:
conn_id -- [in] Connection ID to indicate which link it is.
service_id -- [in] Service ID T_SERVER_ID.
attrib_index -- [in] Attribute index of the attribute to get CCCD.
p_cccd -- [inout] Pointer to location to get CCCD information.
- Return values:
true -- Operation success.
false -- Operation failure.
- Returns:
-
Operation result.
-
bool server_add_service(T_SERVER_ID *p_out_service_id, uint8_t *p_database, uint16_t length, const T_FUN_GATT_SERVICE_CBS srv_cbs)