GATT Server Extension Exported Functions

group GATT_SERVER_EXT_Exported_Functions

Functions

bool server_ext_add_service(T_SERVER_ID *p_out_service_id, uint8_t *p_database, uint16_t length, const T_FUN_GATT_EXT_SERVICE_CBS *p_srv_ext_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_ext_add_service(void *p_func)
{
    T_SERVER_ID service_id;
    if (false == server_ext_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_EXT_SERVER_GENERAL_CB)p_func;
    return service_id;
}
Parameters:
  • p_out_service_id -- [inout] Pointer to service ID of specific service T_SERVER_ID.

  • p_database -- [in] Pointer to Database of specific service.

  • length -- [in] Length of Database of specific service.

  • p_srv_ext_cbs -- [in] Pointer to service callback functions of specific service.

Return values:
  • true -- Operation success.

  • false -- Operation failure.

Returns:

Operation result.

bool server_ext_add_service_by_start_handle(uint8_t *p_out_service_id, uint8_t *p_database, uint16_t length, T_FUN_GATT_EXT_SERVICE_CBS *p_srv_ext_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_ext_add_service(void *p_func)
{
    T_SERVER_ID service_id;
    if (false == server_ext_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_EXT_SERVER_GENERAL_CB)p_func;
    return service_id;
}
Parameters:
  • p_out_service_id -- [inout] Pointer to service ID of specific service T_SERVER_ID.

  • p_database -- [in] Pointer to Database of specific service.

  • length -- [in] Length of Database of specific service.

  • p_srv_ext_cbs -- [in] Pointer to 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_ext_register_app_cb(P_FUN_EXT_SERVER_GENERAL_CB p_fun_cb)

Register callback function to send events to the application.

Example usage

void app_le_profile_init(void)
{
    server_init(service_num);
    simp_srv_id = simp_ble_service_ext_add_service(app_ext_profile_callback);
    server_ext_register_app_cb(app_ext_profile_callback);
}
Parameters:

p_fun_cb -- [in] Callback function.

bool server_ext_attr_read_confirm(uint16_t conn_handle, uint16_t cid, T_SERVER_ID service_id, uint16_t attrib_index, uint8_t *p_data, uint16_t data_len, uint16_t total_len, T_APP_RESULT cause)

Confirm from the application when receiving a read request from the client.

Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local Channel Identifier. The value shall be gotten from P_FUN_GATT_EXT_READ_ATTR_CB callback.

  • service_id -- [in] Service ID T_SERVER_ID.

  • attrib_index -- [in] Attribute index of the attribute to read confirmation from the application.

  • p_data -- [in] Pointer to the read value.

  • data_len -- [in] The length of the data.

  • total_len -- [in] Total length.

  • cause -- [in] Cause for read confirmation. Value is T_APP_RESULT.

Return values:
  • true -- Operation success.

  • false -- Operation failure.

Returns:

Operation result.

bool server_ext_exec_write_confirm(uint16_t conn_handle, uint16_t cid, uint16_t cause, uint16_t handle)

Confirm from the application when receiving an execute write request from the client.

Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local Channel Identifier. The value shall be gotten from P_FUN_GATT_EXT_WRITE_ATTR_CB callback.

  • 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_ext_attr_write_confirm(uint16_t conn_handle, uint16_t cid, T_SERVER_ID service_id, uint16_t attrib_index, T_APP_RESULT cause)

Confirm from the application when receiving a write request from the client.

Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local Channel Identifier. The value shall be gotten from P_FUN_GATT_EXT_WRITE_ATTR_CB callback.

  • service_id -- [in] Service ID T_SERVER_ID.

  • attrib_index -- [in] Attribute index of the attribute to write confirmation from the 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_ext_send_data(uint16_t conn_handle, uint16_t cid, 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_ext_register_app_cb with service_id set to SERVICE_PROFILE_GENERAL_ID, and eventId of p_data (T_SERVER_EXT_APP_CB_DATA) set to PROFILE_EVT_SEND_DATA_COMPLETE.

Example usage

bool simp_ext_service_send_v3_notify(uint16_t conn_handle,  uint16_t cid, T_SERVER_ID service_id,
                                    void *p_value,
                                    uint16_t length)
{
    APP_PRINT_INFO0("simp_ext_service_send_v3_notify");
    // send notification to client
    return server_ext_send_data(conn_handle, cid, service_id, SIMPLE_EXT_SERVICE_CHAR_V3_NOTIFY_INDEX,
                                p_value,
                                length,
                                GATT_PDU_TYPE_ANY);
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local Channel Identifier assigned by Bluetooth Host. Shall use the channel in the GAP_CHANNEL_STATE_CONNECTED state.

  • service_id -- [in] Service ID T_SERVER_ID.

  • attrib_index -- [in] Attribute index of the 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 gap_chann_get_info (conn_handle, cid, p_info).

  • 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_ext_get_write_cmd_data_buffer(uint16_t conn_handle, uint16_t cid, uint8_t **pp_buffer, uint16_t *p_offset)

Get the header pointer of the write command data buffer.

This function is used to get the buffer pointer 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_ext_service_attr_write_cb(uint16_t conn_handle,  uint16_t cid,
                                            T_SERVER_ID service_id,
                                            uint16_t attrib_index, T_WRITE_TYPE write_type, uint16_t length, uint8_t *p_value,
                                            P_FUN_EXT_WRITE_IND_POST_PROC *p_write_post_proc)
{
    ......
    server_ext_get_write_cmd_data_buffer(conn_handle, cid, &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_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local Channel Identifier. The value shall be gotten from P_FUN_GATT_EXT_WRITE_ATTR_CB callback.

  • 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_ext_send_multi_notify(uint16_t conn_handle, uint16_t cid, uint8_t *p_data, uint16_t data_len)

Send the multiple variable notifications.

If sending request operation is successful, the sending result will be returned by callback registered by server_ext_register_app_cb with service_id set to SERVICE_PROFILE_GENERAL_ID, and eventId of p_data (T_SERVER_EXT_APP_CB_DATA) set to PROFILE_EVT_SEND_DATA_COMPLETE.

Example usage

bool simp_ble_service_ext_send_v3_v8_notify(uint16_t conn_handle, uint16_t cid, 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_ext_send_multi_notify(conn_handle, cid, p_value, length);
    if (p_value)
    {
        os_mem_free(p_value);
    }
    return ret;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local Channel Identifier assigned by Bluetooth Host. Shall use the channel in the GAP_CHANNEL_STATE_CONNECTED state.

  • 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 gap_chann_get_info (conn_handle, cid, p_info).

Return values:
  • true -- Sending request operation is successful.

  • false -- Sending request operation is failed.

Returns:

The result of sending request.

bool server_ext_get_cccd_info(uint16_t conn_handle, T_SERVER_ID service_id, uint16_t attrib_index, uint16_t *p_cccd)

Get the CCCD information.

Example usage

bool simp_ble_service_ext_send_v3_notify(uint16_t conn_handle, uint16_t cid, T_SERVER_ID service_id, void *p_value,
                                    uint16_t length)
{
    uint16_t cccd_bits;
    APP_PRINT_INFO0("simp_ble_service_ext_send_v3_notify");
    if (server_ext_get_cccd_info(conn_handle, service_id, SIMPLE_BLE_SERVICE_CHAR_NOTIFY_CCCD_INDEX,
                            &cccd_bits))
    {
        APP_PRINT_INFO1("simp_ble_service_ext_send_v3_notify: cccd_bits 0x%x", cccd_bits);
    }
    return server_ext_send_data(conn_handle, cid, service_id, SIMPLE_BLE_SERVICE_CHAR_V3_NOTIFY_INDEX, p_value,
                            length,
                            GATT_PDU_TYPE_ANY);
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • service_id -- [in] Service ID T_SERVER_ID.

  • attrib_index -- [in] Attribute index of 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.