Bluetooth GATT Client Exported Functions

group BT_GATT_CLIENT_Exported_Functions

Functions

T_GAP_CAUSE gatt_client_start_discovery_all(uint16_t conn_handle, P_FUN_GATT_CLIENT_CB p_general_cb)

Send discovery all primary services request.

Example usage

void test(void)
{
    T_GAP_CAUSE cause;
    cause = gatt_client_start_discovery_all(conn_handle, app_ble_gap_client_cb);
}

T_APP_RESULT app_ble_gap_client_cb(uint16_t conn_handle, T_GATT_CLIENT_EVENT type,
                                          void *p_data)
{
    if (type == GATT_CLIENT_EVENT_DIS_ALL_STATE)
    {
        APP_PRINT_INFO2("app_ble_gap_client_cb:is_success %d, load_from_ftl %d",
                        p_disc->state, p_disc->load_from_ftl);
    }
    return APP_RESULT_SUCCESS;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_general_cb -- [in] General client callback function for this ACL link.

    • NULL Not send any general client callback event to application.

    • Others Send general client callback event to application, such as GATT_CLIENT_EVENT_DIS_ALL_STATE.

Return values:
  • GAP_CAUSE_SUCCESS -- Discovery request success.

  • Others -- Discovery request failed.

Returns:

Operation result. T_GAP_CAUSE.

T_GAP_CAUSE gatt_client_enable_srv_cccd(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, uint8_t cccd_cfg)

Enable all the characteristic CCCD in a service.

Example usage

bool bass_enable_cccd(uint16_t conn_handle)
{
    T_ATTR_UUID srv_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_INVALID_PARAM;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    cause = gatt_client_enable_srv_cccd(conn_handle, &srv_uuid, GATT_CLIENT_CONFIG_ALL);
    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id needs to be the actual value of service instance_id.

  • cccd_cfg -- [in] CCCD value GATT Client Configure CCCD.

Return values:
  • GAP_CAUSE_SUCCESS -- Enable CCCD request success.

  • Others -- Enable CCCD request failed.

Returns:

Operation result. T_GAP_CAUSE.

T_GAP_CAUSE gatt_client_enable_char_cccd(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid, uint8_t cccd_cfg)

Send enable characteristic CCCD request.

Example usage

bool ascs_client_enable_cccd(uint16_t conn_handle)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_SUCCESS;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_ASCS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = 0;
    T_ASCS_CLIENT_DB *p_ascs_db = ascs_check_link(conn_handle);
    if (p_ascs_db != 0)
    {
        char_uuid.p.uuid16 = ASCS_UUID_CHAR_ASE_CONTROL_POINT;
        if (gatt_client_check_cccd_enabled(conn_handle, &srv_uuid, &char_uuid) == false)
        {
            cause = gatt_client_enable_char_cccd(conn_handle, &srv_uuid, &char_uuid,
                                                 GATT_CLIENT_CONFIG_ALL);
        }
    }

    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id needs to be the actual value of service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID. The instance_id can be set to 0 if the cccd_cfg set to GATT_CLIENT_CONFIG_ALL.

  • cccd_cfg -- [in] CCCD value GATT Client Configure CCCD.

Return values:
  • GAP_CAUSE_SUCCESS -- Enable CCCD request success.

  • Others -- Enable CCCD request failed.

Returns:

Operation result. T_GAP_CAUSE.

bool gatt_client_get_char_cccd(uint16_t conn_handle, uint16_t handle, uint16_t *p_ccc_bits)

Get characteristic CCCD bits value.

Added Since 2.13.1.0:
Example usage
void test(void)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    uint16_t cccd_bits = 0;
    uint16_t handle = 0;
    uint8_t cccd_prop = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = instance_id;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    if (gatt_client_find_char_cccd_handle(conn_handle, &srv_uuid, &char_uuid, &handle, &cccd_prop))
    {
        gatt_client_get_char_cccd(conn_handle, handle, &cccd_bits);
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • handle -- [in] Attribute handle.

  • p_ccc_bits -- [inout] Pointer to characteristic CCCD value.

Return values:
  • true -- Get characteristic CCCD bits value success.

  • false -- Get characteristic CCCD bits value failed.

Returns:

Operation result.

bool gatt_client_check_cccd_enabled(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid)

Check whether characteristic CCCD is enabled.

Added Since 2.13.1.0:
Example usage
bool bass_enable_cccd(uint16_t conn_handle)
{
    T_ATTR_UUID srv_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_SUCCESS;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    if (gatt_client_check_cccd_enabled(conn_handle, &srv_uuid, NULL) == false)
    {
        cause = gatt_client_enable_srv_cccd(conn_handle, &srv_uuid, GATT_CLIENT_CONFIG_ALL);
    }

    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id need to be the actual value of service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID.

    • NULL Check all the CCCD of service.

    • Others Check the specific characteristic CCCD. The instance_id can be set to 0 when p_char_uuid is not NULL.

Return values:
  • true -- Characteristic CCCD is enabled.

  • false -- Characteristic CCCD is not enabled.

Returns:

Operation result.

T_GAP_CAUSE gatt_client_read(uint16_t conn_handle, uint16_t handle, P_FUN_GATT_CLIENT_CB p_req_cb)

Read characteristic value or characteristic descriptors by handle.

Example usage

//case 1
bool bass_read_brs_value(uint16_t conn_handle, uint8_t instance_id)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_INVALID_PARAM;
    uint16_t handle = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = instance_id;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    if (gatt_client_find_char_handle(conn_handle, &srv_uuid, &char_uuid, &handle))
    {
        cause = gatt_client_read(conn_handle, handle, read_brs_cb);
    }
    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
T_APP_RESULT read_brs_cb(uint16_t conn_handle, T_GATT_CLIENT_EVENT type, void *p_data)
{
    PROTOCOL_PRINT_TRACE2("read_brs_cb: conn_handle 0x%x, type 0x%x",
                          conn_handle, type);
    return APP_RESULT_SUCCESS;
}

//case 2
bool bass_read_brs_value(uint16_t conn_handle, uint8_t instance_id)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_INVALID_PARAM;
    uint16_t handle = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = instance_id;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    if (gatt_client_find_char_handle(conn_handle, &srv_uuid, &char_uuid, &handle))
    {
        cause = gatt_client_read(conn_handle, handle, NULL);
    }
    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
bool bass_client_init(void)
{
    T_ATTR_UUID srv_uuid = {0};
    srv_uuid.is_uuid16 = true;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    gatt_client_spec_register(&srv_uuid, bass_client_cb);
    ble_dm_cback_register(bass_client_dm_cback);
    return true;
}
T_APP_RESULT bass_client_cb(uint16_t conn_handle, T_GATT_CLIENT_EVENT type, void *p_data)
{
    T_APP_RESULT  result = APP_RESULT_SUCCESS;
    T_GATT_CLIENT_DATA *p_client_cb_data = (T_GATT_CLIENT_DATA *)p_data;
    T_BASS_CLIENT_DB *p_bass_db = bass_check_link(conn_handle);
    if (p_bass_db == NULL && type != GATT_CLIENT_EVENT_DIS_DONE)
    {
        goto error;
    }
    switch (type)
    {
    case GATT_CLIENT_EVENT_READ_RESULT:
        {
            PROTOCOL_PRINT_INFO7("[BAP][BASS] GATT_CLIENT_EVENT_READ_RESULT: conn_handle 0x%x, cause 0x%x, char_type %d, srv_instance_id %d, uuid16[%d] 0x%x, handle 0x%x",
                                 conn_handle, p_client_cb_data->read_result.cause,
                                 p_client_cb_data->read_result.char_type,
                                 p_client_cb_data->read_result.srv_instance_id,
                                 p_client_cb_data->read_result.char_uuid.instance_id,
                                 p_client_cb_data->read_result.char_uuid.p.uuid16,
                                 p_client_cb_data->read_result.handle);
            PROTOCOL_PRINT_INFO2("[BAP][BASS] GATT_CLIENT_EVENT_READ_RESULT: value[%d] %b",
                                 p_client_cb_data->read_result.value_size,
                                 TRACE_BINARY(p_client_cb_data->read_result.value_size,
                                              p_client_cb_data->read_result.p_value));
        }
        break;

    default:
        break;
    }

    return result;
error:
    return APP_RESULT_APP_ERR;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • handle -- [in] Request handle.

  • p_req_cb -- [in] Specific client read request callback function.

Return values:
  • GAP_CAUSE_SUCCESS -- Read request success.

  • Others -- Read request failed.

Returns:

Operation result. T_GAP_CAUSE.

T_GAP_CAUSE gatt_client_read_uuid(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16, P_FUN_GATT_CLIENT_CB p_req_cb)

Read Using Characteristic UUID.

Example usage

bool tmas_read_role_by_uuid(uint16_t conn_handle)
{
    if (gatt_client_read_uuid(conn_handle, 0x01,
                              0xffff, TMAS_UUID_CHAR_ROLE, NULL) == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
T_APP_RESULT tmap_client_cb(uint16_t conn_handle, T_GATT_CLIENT_EVENT type, void *p_data)
{
    T_APP_RESULT result = APP_RESULT_SUCCESS;
    T_GATT_CLIENT_DATA *p_client_cb_data = (T_GATT_CLIENT_DATA *)p_data;

    switch (type)
    {
    case GATT_CLIENT_EVENT_READ_UUID_RESULT:
        {
            PROTOCOL_PRINT_INFO2("GATT_CLIENT_EVENT_READ_UUID_RESULT: conn_handle 0x%x, cause 0x%x",
                                 conn_handle, p_client_cb_data->read_result.cause);
        }
        break;

    default:
        break;
    }

    return result;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • start_handle -- [in] Start handle of range to be searched.

  • end_handle -- [in] End handle of range to be searched.

  • uuid16 -- [in] Request 16-bit UUID.

  • p_req_cb -- [in] Specific client read request callback function.

Return values:
  • GAP_CAUSE_SUCCESS -- Read request success.

  • Others -- Read request failed.

Returns:

Operation result. T_GAP_CAUSE.

T_GAP_CAUSE gatt_client_write(uint16_t conn_handle, T_GATT_WRITE_TYPE write_type, uint16_t handle, uint16_t length, uint8_t *p_data, P_FUN_GATT_CLIENT_CB p_req_cb)

Write characteristic value or characteristic descriptors by handle.

Example usage

bool mics_write_mute_value(uint16_t conn_handle, T_MICS_MUTE mic_mute)
{
    T_BLE_AUDIO_LINK *p_link = ble_audio_link_find_by_conn_handle(conn_handle);

    if (p_link == NULL)
    {
        return false;
    }

    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_INVALID_PARAM;
    uint16_t handle = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_MICS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = 0;
    char_uuid.p.uuid16 = MICS_UUID_CHAR_MUTE;

    if (gatt_client_find_char_handle(conn_handle, &srv_uuid, &char_uuid, &handle))
    {
        cause = gatt_client_write(conn_handle, GATT_WRITE_TYPE_REQ, handle, 1, &mic_mute, NULL);
    }

    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
static T_APP_RESULT mics_client_callback(uint16_t conn_handle, T_GATT_CLIENT_EVENT type,
                                         void *p_data)
{
    T_APP_RESULT  result = APP_RESULT_SUCCESS;
    T_GATT_CLIENT_DATA *p_client_cb_data = (T_GATT_CLIENT_DATA *)p_data;
    T_BLE_AUDIO_LINK *p_link = ble_audio_link_find_by_conn_handle(conn_handle);

    if (p_link == NULL)
    {
        return APP_RESULT_APP_ERR;
    }

    switch (type)
    {
    case GATT_CLIENT_EVENT_WRITE_RESULT:
        {
            PROTOCOL_PRINT_INFO2("GATT_CLIENT_EVENT_WRITE_RESULT: conn_handle 0x%x, cause 0x%x",
                                 conn_handle, p_client_cb_data->write_result.cause);
        }
        break;

    default:
        break;
    }

    return result;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • write_type -- [in] Type of write.

  • handle -- [in] Attribute handle.

  • length -- [in] Length of data to be written. If write_type is GATT_WRITE_TYPE_REQ, range of length is from 0 to 512. If write_type is GATT_WRITE_TYPE_CMD, range of length is from 0 to (mtu_size - 3). GATT_WRITE_TYPE_SIGNED_CMD is not supported. uint16_t mtu_size is acquired by le_get_conn_param(GAP_PARAM_CONN_MTU_SIZE, &mtu_size, conn_id) or gap_chann_get_info().

  • p_data -- [in] Pointer to the data to be written.

  • p_req_cb -- [in] Specific client write request callback function.

Return values:
  • GAP_CAUSE_SUCCESS -- Write request success.

  • Others -- Write request failed.

Returns:

Operation result. T_GAP_CAUSE.

T_GAP_CAUSE gatt_client_ind_confirm(uint16_t conn_handle, uint16_t cid)

Confirm from application when receive indication from server, if APP wants to send confirmation itself and the return cause of GATT_CLIENT_EVENT_NOTIFY_IND is APP_RESULT_PENDING.

Added Since 2.13.1.0:
Example usage
T_APP_RESULT test_client_cb(uint16_t conn_handle, T_GATT_CLIENT_EVENT type, void *p_data)
{
    T_APP_RESULT  result = APP_RESULT_SUCCESS;
    T_GATT_CLIENT_DATA *p_client_cb_data = (T_GATT_CLIENT_DATA *)p_data;
    switch (type)
    {
    case GATT_CLIENT_EVENT_NOTIFY_IND:
        {
            gatt_client_ind_confirm(conn_handle, p_client_cb_data->notify_ind.cid);
            result = APP_RESULT_PENDING;
        }
        break;
    default:
        break;
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • cid -- [in] Local CID. The value shall be get from GATT_CLIENT_EVENT_NOTIFY_IND callback.

Return values:
  • GAP_CAUSE_SUCCESS -- Confirm success.

  • Others -- Confirm failed.

Returns:

Operation result. T_GAP_CAUSE.

T_GAP_CAUSE gatt_client_spec_register(T_ATTR_UUID *p_srv_uuid, P_FUN_GATT_CLIENT_CB p_fun_cb)

Used by specific client, register callback.

Example usage

bool bass_client_init(void)
{
    T_ATTR_UUID srv_uuid = {0};
    srv_uuid.is_uuid16 = true;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    gatt_client_spec_register(&srv_uuid, bass_client_cb);
    ble_dm_cback_register(bass_client_dm_cback);
    return true;
}
T_APP_RESULT bass_client_cb(uint16_t conn_handle, T_GATT_CLIENT_EVENT type, void *p_data)
{
    T_APP_RESULT  result = APP_RESULT_SUCCESS;
    T_GATT_CLIENT_DATA *p_client_cb_data = (T_GATT_CLIENT_DATA *)p_data;
    T_BASS_CLIENT_DB *p_bass_db = bass_check_link(conn_handle);
    if (p_bass_db == NULL && type != GATT_CLIENT_EVENT_DIS_DONE)
    {
        goto error;
    }
    switch (type)
    {
    case GATT_CLIENT_EVENT_DIS_DONE:
        PROTOCOL_PRINT_INFO2("[BAP][BASS] GATT_CLIENT_EVENT_DIS_DONE: is_found %d, srv_instance_num %d",
                             p_client_cb_data->dis_done.is_found,
                             p_client_cb_data->dis_done.srv_instance_num);
        break;
    case GATT_CLIENT_EVENT_READ_RESULT:
        break;
    case GATT_CLIENT_EVENT_NOTIFY_IND:
        break;
    case GATT_CLIENT_EVENT_WRITE_RESULT:
        break;
    default:
        break;
    }
}
Parameters:
  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID.

  • p_fun_cb -- [in] Specific client callback function.

Return values:
  • GAP_CAUSE_SUCCESS -- Register callback request success.

  • Others -- Register callback request failed.

Returns:

Operation result. T_GAP_CAUSE.

bool gatt_client_find_char_descriptor_range(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid, uint16_t *p_start_handle, uint16_t *p_end_handle, uint16_t *p_cccd_handle)

Get characteristic descriptor handle range.

Added Since 2.12.0.0:
Example usage
void test(uint16_t conn_handle)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    uint16_t start_handle = 0;
    uint16_t end_handle = 0;
    uint16_t cccd_handle = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = instance_id;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    gatt_client_find_char_descriptor_range(conn_handle, &srv_uuid, &char_uuid,
                                           &start_handle, &end_handle, &cccd_handle);
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id need to be the actual value of service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID. The instance_id need to be the actual value of characteristic instance_id.

  • p_start_handle -- [inout] Pointer to start handle.

  • p_end_handle -- [inout] Pointer to end handle.

  • p_cccd_handle -- [inout] Pointer to CCCD handle. When CCCD handle is zero, this characteristic does not contain the Client Characteristic Configuration descriptor.

Return values:
  • true -- Get characteristic descriptor handle range success.

  • false -- Get characteristic descriptor handle range failed.

Returns:

Operation result.

bool gatt_client_find_char_handle(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid, uint16_t *p_handle)

Find characteristic value handle.

Example usage

bool bass_read_brs_value(uint16_t conn_handle, uint8_t instance_id)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    T_GAP_CAUSE cause = GAP_CAUSE_INVALID_PARAM;
    uint16_t handle = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = instance_id;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    if (gatt_client_find_char_handle(conn_handle, &srv_uuid, &char_uuid, &handle))
    {
        cause = gatt_client_read(conn_handle, handle, NULL);
    }
    if (cause == GAP_CAUSE_SUCCESS)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id needs to be the actual value of the service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID. The instance_id needs to be the actual value of the service instance_id.

  • p_handle -- [inout] Pointer to the characteristic attribute value handle.

Return values:
  • true -- Find characteristic value handle success.

  • false -- Find characteristic value handle failed.

Returns:

Operation result.

bool gatt_client_find_char_cccd_handle(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid, uint16_t *p_handle, uint8_t *p_cccd_prop)

Find characteristic CCCD attribute handle.

Added Since 2.13.1.0:
Example usage
void test(uint16_t conn_handle, uint16_t instance_id)
{
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    uint16_t cccd_bits = 0;
    uint16_t handle = 0;
    uint8_t cccd_prop = 0;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = instance_id;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    if (gatt_client_find_char_cccd_handle(conn_handle, &srv_uuid, &char_uuid, &handle, &cccd_prop))
    {
        gatt_client_get_char_cccd(conn_handle, handle, &cccd_bits);
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id needs to be the actual value of the service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID. The instance_id needs to be the actual value of the characteristic instance_id.

  • p_handle -- [inout] Pointer to the characteristic CCCD attribute handle.

  • p_cccd_prop -- [inout] Pointer to the characteristic CCCD property.

Return values:
  • true -- Find characteristic CCCD attribute handle success.

  • false -- Find characteristic CCCD attribute handle failed.

Returns:

Operation result.

bool gatt_client_find_primary_srv_by_include(uint16_t conn_handle, T_ATTR_UUID *p_included_srv, T_ATTR_UUID *p_primary_srv)

Find primary service by included service.

Example usage

uint16_t csip_ts_handle_msg(T_LE_AUDIO_MSG msg, void *buf)
{
    uint16_t cb_result = BLE_AUDIO_CB_RESULT_SUCCESS;
    switch (msg)
    {
    case LE_AUDIO_MSG_CSIS_CLIENT_DIS_DONE:
        {
            T_CSIS_CLIENT_DIS_DONE *p_dis_done = (T_CSIS_CLIENT_DIS_DONE *)buf;
            APP_PRINT_INFO4("LE_AUDIO_MSG_CSIS_CLIENT_DIS_DONE: conn_handle 0x%x, is_found %d, load_from_ftl %d, srv_num %d",
                            p_dis_done->conn_handle, p_dis_done->is_found,
                            p_dis_done->load_from_ftl, p_dis_done->srv_num);
            if (p_dis_done->is_found)
            {
                if (p_dis_done->srv_num)
                {
                    T_ATTR_UUID srv_uuid;
                    T_ATTR_UUID include_srv;
                    srv_uuid.is_uuid16 = true;
                    srv_uuid.p.uuid16 = GATT_UUID_CSIS;
                    for (uint8_t i = 0; i < p_dis_done->srv_num; i++)
                    {
                        srv_uuid.instance_id = i;
                        if (gatt_client_find_primary_srv_by_include(p_dis_done->conn_handle, &srv_uuid,
                                                                    &include_srv))
                        {
                            PROTOCOL_PRINT_INFO2("LE_AUDIO_MSG_CSIS_CLIENT_DIS_DONE: instance_id %d, serv 0x%x",
                                                 include_srv.instance_id, include_srv.p.uuid16);
                        }
                    }
                }
            }
        }
        break;

    default:
        break;
    }
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_included_srv -- [in] Pointer to included service UUID T_ATTR_UUID. The instance_id needs to be the actual value of the service instance_id.

  • p_primary_srv -- [inout] Pointer to primary service UUID T_ATTR_UUID.

Return values:
  • true -- Find primary service by included service success.

  • false -- Find primary service by included service failed.

Returns:

Operation result.

bool gatt_client_find_include_srv_by_primary(uint16_t conn_handle, T_ATTR_UUID *p_primary_srv, T_ATTR_UUID *p_included_srv, T_ATTR_INSTANCE *p_attr_instance)

Find included service by primary service.

Example usage

T_APP_RESULT cap_cas_callback(uint16_t conn_handle, T_GATT_CLIENT_EVENT type, void *p_data)
{
    T_APP_RESULT  result = APP_RESULT_SUCCESS;
    T_GATT_CLIENT_DATA *p_client_cb_data = (T_GATT_CLIENT_DATA *)p_data;

    switch (type)
    {
    case GATT_CLIENT_EVENT_DIS_DONE:
        {
            T_BLE_AUDIO_LINK *p_link = ble_audio_link_find_by_conn_handle(conn_handle);
            if (p_link == NULL)
            {
                return APP_RESULT_APP_ERR;
            }
            if (p_client_cb_data->dis_done.is_found)
            {
                T_ATTR_UUID srv_uuid;
                T_ATTR_UUID inc_uuid;
                T_ATTR_INSTANCE attr_instance;

                p_link->cap_discov_flags |= CAP_CAS_FLAG;

                srv_uuid.is_uuid16 = true;
                srv_uuid.instance_id = 0;
                srv_uuid.p.uuid16 = GATT_UUID_CAS;
                inc_uuid.is_uuid16 = true;
                inc_uuid.instance_id = 0;
                inc_uuid.p.uuid16 = GATT_UUID_CSIS;
                if (gatt_client_find_include_srv_by_primary(conn_handle, &srv_uuid, &inc_uuid, &attr_instance))
                {
                    if (attr_instance.instance_num == 1)
                    {
                        PROTOCOL_PRINT_INFO0("[CAP][VCP] cap_cas_callback: support csis");
                    }
                }
            }
        }
        break;

    default:
        break;
    }

    return result;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_primary_srv -- [in] Pointer to primary service UUID T_ATTR_UUID. The instance_id needs to be the actual value of the service instance_id.

  • p_included_srv -- [in] Pointer to included service UUID T_ATTR_UUID. The instance_id can be set to 0.

  • p_attr_instance -- [inout] Pointer to the service attribute instance T_ATTR_INSTANCE.

Return values:
  • true -- Find included service by primary service success.

  • false -- Find included service by primary service failed.

Returns:

Operation result.

uint8_t gatt_client_get_char_num(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid)

Get the number of characteristics with the same uuid.

Example usage

void test(uint16_t conn_handle)
{
    uint8_t brs_num = 0;
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_BASS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = 0;
    char_uuid.p.uuid16 = BASS_UUID_CHAR_BROADCAST_RECEIVE_STATE;
    brs_num = gatt_client_get_char_num(conn_handle, &srv_uuid, &char_uuid);
    return;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id needs to be the actual value of service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID. The instance_id can be set to 0.

Returns:

The number of service characteristics.

bool gatt_client_get_char_prop(uint16_t conn_handle, T_ATTR_UUID *p_srv_uuid, T_ATTR_UUID *p_char_uuid, uint16_t *p_properties)

Get service characteristic properties.

Example usage

void test(void)
{
    T_PACS_CLIENT_DIS_DONE dis_done;
    T_PACS_CLIENT_DB *p_pacs_db;
    uint16_t properties;
    memset(&dis_done, 0, sizeof(T_PACS_CLIENT_DIS_DONE));
    T_ATTR_UUID srv_uuid;
    T_ATTR_UUID char_uuid;
    srv_uuid.is_uuid16 = true;
    srv_uuid.instance_id = 0;
    srv_uuid.p.uuid16 = GATT_UUID_PACS;
    char_uuid.is_uuid16 = true;
    char_uuid.instance_id = 0;
    char_uuid.p.uuid16 = PACS_UUID_CHAR_SINK_PAC;
    if (gatt_client_get_char_prop(conn_handle, &srv_uuid, &char_uuid, &properties) == false)
    {
        dis_done.sink_loc_exist = false;
    }
    else
    {
        if (properties & GATT_CHAR_PROP_WRITE)
        {
            p_pacs_db->sink_loc_writable = true;
            dis_done.sink_loc_writable = true;
        }
    }
    return;
}
Parameters:
  • conn_handle -- [in] Connection handle of the ACL link.

  • p_srv_uuid -- [in] Pointer to service UUID T_ATTR_UUID. The instance_id needs to be the actual value of service instance_id.

  • p_char_uuid -- [in] Pointer to characteristic UUID T_ATTR_UUID. The instance_id needs to be the actual value of characteristic instance_id.

  • p_properties -- [inout] Pointer to characteristic properties GATT Attribute.

Return values:
  • true -- Get service characteristic properties successfully.

  • false -- Get service characteristic properties failed.

Returns:

Operation result.

bool gatt_client_is_load_from_ftl(uint16_t conn_handle)

Whether to get the service table from FTL.

Added Since 2.12.0.0:
Example usage
void cap_check_disc_done(T_BLE_AUDIO_LINK *p_link, uint16_t conn_handle, uint8_t flags)
{
    PROTOCOL_PRINT_INFO2("[CAP][VCP] cap_check_disc_done: cap_init_flags 0x%x, flags 0x%x",
                         p_link->cap_init_flags, flags);
    if (p_link->cap_init_flags & flags)
    {
        p_link->cap_init_flags &= ~flags;
        if (p_link->cap_init_flags == 0)
        {
            T_CAP_DIS_DONE dis_done = {0};

            dis_done.conn_handle = conn_handle;
            dis_done.load_from_ftl = gatt_client_is_load_from_ftl(conn_handle);
            if (p_link->cap_discov_flags & CAP_CAS_FLAG)
            {
                dis_done.cas_is_found = true;
                if (p_link->cap_discov_flags & CAP_CSIS_FLAG)
                {
                    dis_done.cas_inc_csis = true;
                }
            }
        }
    }
}
Parameters:

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

Return values:
  • true -- Get the service table from FTL.

  • false -- Do not get the service table from FTL.

Returns:

Operation result.

bool gatt_client_cfg_client_supported_feature(uint8_t feature)

Configure default client supported features.

Added Since 2.13.1.0:
Example usage
void test(void)
{
    gatt_client_init(GATT_CLIENT_DISCOV_MODE_REG_SVC_BIT |
                     GATT_CLIENT_DISCOV_MODE_CCCD_STORAGE_BIT |
                     GATT_CLIENT_DISCOV_MODE_USE_EXT_CLIENT |
                     GATT_CLIENT_DISCOV_MODE_GATT_SVC);
    gatt_client_cfg_client_supported_feature(GATT_SVC_CLIENT_SUPPORTED_FEATURES_EATT_BEARER_BIT);
}
Parameters:

feature -- [in] Client supported features.

Return values:
  • true -- Configure the feature success.

  • false -- Configure the feature failed.

Returns:

Operation result.

bool gatt_client_init(uint16_t mode)

Initialize GATT client discover mode.

Added Since 2.12.0.0:
Example usage
void test(void)
{
    gatt_client_init(GATT_CLIENT_DISCOV_MODE_REG_SVC_BIT | GATT_CLIENT_DISCOV_MODE_CCCD_STORAGE_BIT);
}

Note

Application can't use functions client_init and client_cfg_use_ext_api when use function gatt_client_init to initialize the GATT client module.

Parameters:

mode -- [in] Discover mode GATT Client Discover Mode Bit Field.

Return values:
  • true -- Initialize GATT client success.

  • false -- Initialize GATT client failed.

Returns:

Operation result.

void gatt_client_cfg_pending_num(T_GATT_CLIENT_PENDING_NUM num)

Set the Maximum pending packets in the Bluetooth GATT client module.

Experimental Added Since 2.14.0.0:
Example usage
void test(void)
{
    gatt_client_init(GATT_CLIENT_DISCOV_MODE_REG_SVC_BIT |
                     GATT_CLIENT_DISCOV_MODE_CCCD_STORAGE_BIT |
                     GATT_CLIENT_DISCOV_MODE_USE_EXT_CLIENT |
                     GATT_CLIENT_DISCOV_MODE_GATT_SVC);
    gatt_client_cfg_client_supported_feature(GATT_SVC_CLIENT_SUPPORTED_FEATURES_EATT_BEARER_BIT);

    T_GATT_CLIENT_PENDING_NUM num;
    num.write_cmd_num = 20;
    gatt_client_cfg_pending_num(num);
}
Parameters:

num -- [in] Pending packet number T_GATT_CLIENT_PENDING_NUM. The default number is 10.

bool gatt_client_storage_register(P_FUN_GATT_STORAGE_CB p_fun_cb)

Register storage callback function.

Example usage

void test(void)
{
    gatt_client_storage_register(gattc_tbl_storage_cb);
}
Parameters:

p_fun_cb -- [in] Storage callback function P_FUN_GATT_STORAGE_CB.

Return values:
  • true -- Register storage callback function success.

  • false -- Register storage callback function failed.

Returns:

Operation result.