/*******************************************************************************
**
** Function         bta_pan_open
**
** Description
**
** Returns          void
**
*******************************************************************************/
void bta_pan_open(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
{
    tPAN_RESULT status;
    tBTA_PAN_OPEN data;
    tBTA_PAN_OPENING    opening;


    status = PAN_Connect (p_data->api_open.bd_addr, p_data->api_open.local_role, p_data->api_open.peer_role,
                        &p_scb->handle);


    if(status == PAN_SUCCESS)
    {

        bdcpy(p_scb->bd_addr, p_data->api_open.bd_addr);
        p_scb->local_role = p_data->api_open.local_role;
        p_scb->peer_role = p_data->api_open.peer_role;
        bdcpy(opening.bd_addr, p_data->api_open.bd_addr);
        opening.handle = p_scb->handle;
        bta_pan_cb.p_cback(BTA_PAN_OPENING_EVT, (tBTA_PAN *)&opening);


    }
    else
    {
        bta_pan_scb_dealloc(p_scb);
        bdcpy(data.bd_addr, p_data->api_open.bd_addr);
        data.status = BTA_PAN_FAIL;
        data.local_role = p_data->api_open.local_role;
        data.peer_role = p_data->api_open.peer_role;
        bta_pan_cb.p_cback(BTA_PAN_OPEN_EVT, (tBTA_PAN *)&data);
    }

}
/*******************************************************************************
**
** Function         bta_pan_data_buf_ind_cback
**
** Description      data indication callback from pan profile
**
**
** Returns          void
**
*******************************************************************************/
static void bta_pan_data_buf_ind_cback(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 protocol, BT_HDR *p_buf,
                                   BOOLEAN ext, BOOLEAN forward)
{
    tBTA_PAN_SCB *p_scb;
    BT_HDR * p_event;
    BT_HDR *p_new_buf;

    if ( sizeof(tBTA_PAN_DATA_PARAMS) > p_buf->offset )
    {
        /* offset smaller than data structure in front of actual data */
        p_new_buf = (BT_HDR *)GKI_getpoolbuf( PAN_POOL_ID );
        if(!p_new_buf)
        {
            APPL_TRACE_WARNING0("Cannot get a PAN GKI buffer");
            GKI_freebuf( p_buf );
            return;
        }
        else
        {
            memcpy( (UINT8 *)(p_new_buf+1)+sizeof(tBTA_PAN_DATA_PARAMS), (UINT8 *)(p_buf+1)+p_buf->offset, p_buf->len );
            p_new_buf->len    = p_buf->len;
            p_new_buf->offset = sizeof(tBTA_PAN_DATA_PARAMS);
            GKI_freebuf( p_buf );
        }
    }
    else
    {
        p_new_buf = p_buf;
    }
    /* copy params into the space before the data */
    bdcpy(((tBTA_PAN_DATA_PARAMS *)p_new_buf)->src, src);
    bdcpy(((tBTA_PAN_DATA_PARAMS *)p_new_buf)->dst, dst);
    ((tBTA_PAN_DATA_PARAMS *)p_new_buf)->protocol = protocol;
    ((tBTA_PAN_DATA_PARAMS *)p_new_buf)->ext = ext;
    ((tBTA_PAN_DATA_PARAMS *)p_new_buf)->forward = forward;


    if((p_scb = bta_pan_scb_by_handle(handle)) == NULL)
    {

        GKI_freebuf( p_new_buf );
        return;
    }

    GKI_enqueue(&p_scb->data_queue, p_new_buf);
    if ((p_event = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
    {
        p_event->layer_specific = handle;
        p_event->event = BTA_PAN_RX_FROM_BNEP_READY_EVT;
        bta_sys_sendmsg(p_event);
    }

}
Beispiel #3
0
static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
{
    /* Save link key, if not temporary */
    LOG_DEBUG("%s, status = %d", __func__, p_auth_cmpl->success);
    bt_status_t status = BT_STATUS_FAIL;
    int addr_type;
    bt_bdaddr_t bdaddr;
    bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
    bdcpy(pairing_cb.bd_addr, p_auth_cmpl->bd_addr);

    if (p_auth_cmpl->success) {
        status = BT_STATUS_SUCCESS;
        LOG_DEBUG ("%s, -  p_auth_cmpl->bd_addr: %08x%04x", __func__,
                             (p_auth_cmpl->bd_addr[0] << 24) + (p_auth_cmpl->bd_addr[1] << 16) + (p_auth_cmpl->bd_addr[2] << 8) + p_auth_cmpl->bd_addr[3],
                             (p_auth_cmpl->bd_addr[4] << 8) + p_auth_cmpl->bd_addr[5]);
        LOG_DEBUG ("%s, -  pairing_cb.bd_addr: %08x%04x", __func__,
                             (pairing_cb.bd_addr[0] << 24) + (pairing_cb.bd_addr[1] << 16) + (pairing_cb.bd_addr[2] << 8) + pairing_cb.bd_addr[3],
                             (pairing_cb.bd_addr[4] << 8) + pairing_cb.bd_addr[5]);
         if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) {
            btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
        }
        /* check the irk has been save in the flash or not, if the irk has already save, means that the peer device has bonding
           before. */
        if(pairing_cb.ble.is_pid_key_rcvd) {
            btc_storage_compare_address_key_value(&bdaddr, BTM_LE_KEY_PID,
                                                  (void *)&pairing_cb.ble.pid_key, sizeof(tBTM_LE_PID_KEYS));
        }
        btc_save_ble_bonding_keys();
    } else {
        /*Map the HCI fail reason  to  bt status  */
        switch (p_auth_cmpl->fail_reason) {
        case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
        case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
            btc_dm_remove_ble_bonding_keys();
            status = BT_STATUS_AUTH_FAILURE;
            break;
        case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
            status = BT_STATUS_AUTH_REJECTED;
            break;
        default:
            btc_dm_remove_ble_bonding_keys();
            status =  BT_STATUS_FAIL;
            break;
        }

    }

    LOG_DEBUG("%s, authentication status = %x", __func__, status);
    return;

}
/*******************************************************************************
**
** Function         bta_pan_conn_open
**
** Description      process connection open event
**
** Returns          void
**
*******************************************************************************/
void bta_pan_conn_open(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
{

    tBTA_PAN_OPEN data;

    bdcpy(data.bd_addr, p_scb->bd_addr);
    data.handle = p_scb->handle;
    data.local_role = p_scb->local_role;
    data.peer_role = p_scb->peer_role;

    if(p_data->conn.result == PAN_SUCCESS)
    {
        data.status = BTA_PAN_SUCCESS;
        bta_pan_co_open(p_scb->handle, p_scb->app_id, p_scb->local_role, p_scb->peer_role, p_scb->bd_addr);

    }
    else
    {
        bta_pan_scb_dealloc(p_scb);
        data.status = BTA_PAN_FAIL;
    }

    p_scb->pan_flow_enable = TRUE;
    p_scb->app_flow_enable = TRUE;

    bta_sys_conn_open( BTA_ID_PAN ,p_scb->app_id, p_scb->bd_addr);

    bta_pan_cb.p_cback(BTA_PAN_OPEN_EVT, (tBTA_PAN *)&data);


}
/*******************************************************************************
**
** Function         bta_pan_conn_state_cback
**
** Description      Connection state callback from Pan profile
**
**
** Returns          void
**
*******************************************************************************/
static void bta_pan_conn_state_cback(UINT16 handle, BD_ADDR bd_addr, tPAN_RESULT state,
                                     BOOLEAN is_role_change, UINT8 src_role, UINT8 dst_role)
{

    tBTA_PAN_CONN * p_buf;
    tBTA_PAN_SCB     *p_scb;


    if ((p_buf = (tBTA_PAN_CONN *) GKI_getbuf(sizeof(tBTA_PAN_CONN))) != NULL)
    {
        if((state == PAN_SUCCESS) && !is_role_change)
        {
            p_buf->hdr.event = BTA_PAN_CONN_OPEN_EVT;
            if((p_scb = bta_pan_scb_by_handle(handle)) == NULL)
            {
                /* allocate an scb */
                p_scb = bta_pan_scb_alloc();

            }
            /* we have exceeded maximum number of connections */
            if(!p_scb)
            {
                PAN_Disconnect (handle);
                return;
            }

            p_scb->handle = handle;
            p_scb->local_role = src_role;
            p_scb->peer_role = dst_role;
            p_scb->pan_flow_enable = TRUE;
            bdcpy(p_scb->bd_addr, bd_addr);
            GKI_init_q(&p_scb->data_queue);

            if(src_role == PAN_ROLE_CLIENT)
                p_scb->app_id = bta_pan_cb.app_id[0];
            else if (src_role == PAN_ROLE_GN_SERVER)
                p_scb->app_id = bta_pan_cb.app_id[1];
            else if (src_role == PAN_ROLE_NAP_SERVER)
                p_scb->app_id = bta_pan_cb.app_id[2];

        }
        else if((state != PAN_SUCCESS) && !is_role_change)
        {
            p_buf->hdr.event = BTA_PAN_CONN_CLOSE_EVT;

        }
        else
        {
            return;
        }

        p_buf->result = state;
        p_buf->hdr.layer_specific = handle;
        bta_sys_sendmsg(p_buf);

    }



}
Beispiel #6
0
/*******************************************************************************
 **
 ** Function        app_dm_set_ble_adv_param
 **
 ** Description     Configure the BLE Prefer Advertisement parameters
 **
 ** Parameters      pointer to tBSA_DM_BLE_ADV_PARAM
 **
 ** Returns         status: 0 if success / -1 otherwise
 **
 *******************************************************************************/
int app_dm_set_ble_adv_param(tBSA_DM_BLE_ADV_PARAM *p_req)
{
    tBSA_DM_SET_CONFIG bt_config;
    tBSA_STATUS bsa_status;

    APP_DEBUG1("BDA:%02X:%02X:%02X:%02X:%02X:%02X  ",
            p_req->dir_bda.bd_addr[0], p_req->dir_bda.bd_addr[1],
            p_req->dir_bda.bd_addr[2], p_req->dir_bda.bd_addr[3],
            p_req->dir_bda.bd_addr[4], p_req->dir_bda.bd_addr[5]);

    APP_DEBUG1("adv_int_min:%d adv_int_max:%d", p_req->adv_int_min, p_req->adv_int_max);

    /* Set Bluetooth configuration */
    BSA_DmSetConfigInit(&bt_config);

    /* Obviously */
    bt_config.enable = TRUE;

    /* Configure the Inquiry Scan parameters */
    bt_config.config_mask = BSA_DM_CONFIG_BLE_ADV_PARAM_MASK;
    bdcpy(bt_config.ble_adv_param.dir_bda.bd_addr, p_req->dir_bda.bd_addr);
    bt_config.ble_adv_param.adv_int_min = p_req->adv_int_min;
    bt_config.ble_adv_param.adv_int_max = p_req->adv_int_max;

    bsa_status = BSA_DmSetConfig(&bt_config);
    if (bsa_status != BSA_SUCCESS)
    {
        APP_ERROR1("BSA_DmSetConfig failed status:%d ", bsa_status);
        return(-1);
    }
    return 0;
}
/*******************************************************************************
**
** Function         bta_ag_svc_conn_open
**
** Description      Service level connection opened
**
**
** Returns          void
**
*******************************************************************************/
void bta_ag_svc_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
{
    tBTA_AG_CONN evt;
    UNUSED(p_data);

    if (!p_scb->svc_conn)
    {
        /* set state variable */
        p_scb->svc_conn = TRUE;

        /* Clear AT+BIA mask from previous SLC if any. */
        p_scb->bia_masked_out = 0;

        /* stop timer */
        bta_sys_stop_timer(&p_scb->act_timer);

        /* call callback */
        evt.hdr.handle = bta_ag_scb_to_idx(p_scb);
        evt.hdr.app_id = p_scb->app_id;
        evt.peer_feat = p_scb->peer_features;
        bdcpy(evt.bd_addr, p_scb->peer_addr);
#if (BTM_WBS_INCLUDED == TRUE )
        evt.peer_codec  = p_scb->peer_codecs;
#endif

        if ((p_scb->call_ind != BTA_AG_CALL_INACTIVE) ||
            (p_scb->callsetup_ind != BTA_AG_CALLSETUP_NONE))
        {
            bta_sys_sco_use(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
        }

        (*bta_ag_cb.p_cback)(BTA_AG_CONN_EVT, (tBTA_AG *) &evt);
    }
}
Beispiel #8
0
/*******************************************************************************
 **
 ** Function         bta_av_co_audio_disc_res
 **
 ** Description      This callout function is executed by AV to report the
 **                  number of stream end points (SEP) were found during the
 **                  AVDT stream discovery process.
 **
 **
 ** Returns          void.
 **
 *******************************************************************************/
BTA_API void bta_av_co_audio_disc_res(tBTA_AV_HNDL hndl, UINT8 num_seps, UINT8 num_snk,
        BD_ADDR addr)
{
    tBTA_AV_CO_PEER *p_peer;

    FUNC_TRACE();

    APPL_TRACE_DEBUG3("bta_av_co_audio_disc_res h:x%x num_seps:%d num_snk:%d",
            hndl, num_seps, num_snk);

    /* Find the peer info */
    p_peer = bta_av_co_get_peer(hndl);
    if (p_peer == NULL)
    {
        APPL_TRACE_ERROR0("bta_av_co_audio_disc_res could not find peer entry");
        return;
    }

    /* Sanity check : this should never happen */
    if (p_peer->opened)
    {
        APPL_TRACE_ERROR0("bta_av_co_audio_disc_res peer already opened");
    }

    /* Copy the discovery results */
    bdcpy(p_peer->addr, addr);
    p_peer->num_snks = num_snk;
    p_peer->num_seps = num_seps;
    p_peer->num_rx_snks = 0;
    p_peer->num_sup_snks = 0;
}
Beispiel #9
0
static void bta_mce_search_cback(UINT16 result, void * user_data)
{
    tSDP_DISC_REC *p_rec = NULL;
    tBTA_MCE_MAS_DISCOVERY_COMP evt_data;
    int found = 0;

    APPL_TRACE_DEBUG1("bta_mce_start_discovery_cback res: 0x%x", result);

    bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_NONE;

    if (bta_mce_cb.p_dm_cback == NULL) return;

    evt_data.status = BTA_MCE_FAILURE;
    bdcpy(evt_data.remote_addr, bta_mce_cb.remote_addr);
    evt_data.num_mas = 0;

    if (result == SDP_SUCCESS || result == SDP_DB_FULL)
    {
        do
        {
            tSDP_DISC_ATTR *p_attr;
            tSDP_PROTOCOL_ELEM pe;

            p_rec = SDP_FindServiceUUIDInDb(p_bta_mce_cfg->p_sdp_db, (tBT_UUID*) &bta_mce_mas_uuid, p_rec);

            APPL_TRACE_DEBUG1("p_rec:%p", p_rec);

            if (p_rec == NULL)
                break;

            if (!SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
                continue;

            evt_data.mas[found].scn = pe.params[0];

            if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) == NULL)
                continue;

            evt_data.mas[found].p_srv_name = (char *) p_attr->attr_value.v.array;
            evt_data.mas[found].srv_name_len= SDP_DISC_ATTR_LEN(p_attr->attr_len_type);

            if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID)) == NULL)
                break;

                 evt_data.mas[found].instance_id = p_attr->attr_value.v.u8;

            if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE)) == NULL)
                break;

            evt_data.mas[found].msg_type = p_attr->attr_value.v.u8;

            found++;
        } while (p_rec != NULL && found < BTA_MCE_MAX_MAS_INSTANCES);

        evt_data.num_mas = found;
        evt_data.status = BTA_MCE_SUCCESS;
    }

    bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, (tBTA_MCE*) &evt_data, user_data);
}
/*******************************************************************************
**
** Function         bta_hf_client_start_open
**
** Description      This starts an HF Client open.
**
**
** Returns          void
**
*******************************************************************************/
void bta_hf_client_start_open(tBTA_HF_CLIENT_DATA *p_data)
{
    BD_ADDR pending_bd_addr;

    /* store parameters */
    if (p_data)
    {
        bdcpy(bta_hf_client_cb.scb.peer_addr, p_data->api_open.bd_addr);
        bta_hf_client_cb.scb.cli_sec_mask = p_data->api_open.sec_mask;
    }

    /* Check if RFCOMM has any incoming connection to avoid collision. */
    if (PORT_IsOpening (pending_bd_addr))
    {
        /* Let the incoming connection goes through.                        */
        /* Issue collision for now.                                         */
        /* We will decide what to do when we find incoming connection later.*/
        bta_hf_client_collision_cback (0, BTA_ID_HS, 0, bta_hf_client_cb.scb.peer_addr);
        return;
    }

    /* close server */
    bta_hf_client_close_server();

    /* set role */
    bta_hf_client_cb.scb.role = BTA_HF_CLIENT_INT;

    /* do service search */
    bta_hf_client_do_disc();
}
/*******************************************************************************
**
** Function         bta_ag_start_open
**
** Description      This starts an AG open.
**
**
** Returns          void
**
*******************************************************************************/
void bta_ag_start_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
{
    BD_ADDR pending_bd_addr;

    /* store parameters */
    if (p_data)
    {
        bdcpy(p_scb->peer_addr, p_data->api_open.bd_addr);
        p_scb->open_services = p_data->api_open.services;
        p_scb->cli_sec_mask = p_data->api_open.sec_mask;
    }

    /* Check if RFCOMM has any incoming connection to avoid collision. */
    if (PORT_IsOpening (pending_bd_addr))
    {
        /* Let the incoming connection goes through.                        */
        /* Issue collision for this scb for now.                            */
        /* We will decide what to do when we find incoming connetion later. */
        bta_ag_collision_cback (0, BTA_ID_AG, 0, p_scb->peer_addr);
        return;
    }

    /* close servers */
    bta_ag_close_servers(p_scb, p_scb->reg_services);

    /* set role */
    p_scb->role = BTA_AG_INT;

    /* do service search */
    bta_ag_do_disc(p_scb, p_scb->open_services);
}
Beispiel #12
0
static void _btc_read_le_key(const uint8_t key_type, const size_t key_len, bt_bdaddr_t bd_addr,
                 const uint8_t addr_type, const bool add_key, bool *device_added, bool *key_found)
{
    assert(device_added);
    assert(key_found);

    char buffer[100];
    memset(buffer, 0, sizeof(buffer));

    bt_status_t ret = _btc_storage_get_ble_bonding_key(&bd_addr, key_type, buffer, key_len);

    if (ret == BT_STATUS_SUCCESS) {
        if (add_key) {
            BD_ADDR bta_bd_addr;
            bdcpy(bta_bd_addr, bd_addr.address);

            if (!*device_added) {
                BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                *device_added = true;
            }

            char bd_str[20] = {0};
            LOG_DEBUG("%s() Adding key type %d for %s", __func__,
                key_type, bdaddr_to_string(&bd_addr, bd_str, sizeof(bd_str)));
            BTA_DmAddBleKey(bta_bd_addr, (tBTA_LE_KEY_VALUE *)buffer, key_type);
        }

        *key_found = true;
    }
}
Beispiel #13
0
/*******************************************************************************
 **
 ** Function        app_3dtv_set_slave_mode
 **
 ** Description     Function example to configure 3DTV in Slave mode
 **
 ** Parameters      p_req: pointer to the tAPP_3DTV_SLAVE_MODE
 **
 ** Returns         0 if successful, -1 in case of error
 **
 *******************************************************************************/
int app_3dtv_set_slave_mode(tAPP_3DTV_SLAVE_MODE *p_req)
{
    int status = -1;
    tBSA_STATUS bsa_status;
    tBSA_DM_SET_CONFIG  bt_config;

    if (p_req == NULL)
    {
        APP_ERROR0("Null p_req parameter");
        return status;
    }

    APP_DEBUG1("BrcmMask:x%x BdAddr:%02X:%02X:%02X:%02X:%02X:%02X", p_req->brcm_mask,
            p_req->bd_addr_to_lock[0], p_req->bd_addr_to_lock[1],
            p_req->bd_addr_to_lock[2], p_req->bd_addr_to_lock[3],
            p_req->bd_addr_to_lock[4], p_req->bd_addr_to_lock[5]);

    /* Set Bluetooth configuration */
    BSA_DmSetConfigInit(&bt_config);

    /* Indicate the specific entries to configure */
    bt_config.config_mask = 0;

    /* Obviously Enable Bluetooth*/
    bt_config.enable = TRUE;

    /* Set device BD name */
    bt_config.config_mask |= BSA_DM_CONFIG_NAME_MASK;
    strncpy((char *)bt_config.name, "BSA SlaveTV", sizeof(bt_config.name) - 1);
    bt_config.name[sizeof(bt_config.name) - 1] = '\0';

    /* Configure the Broadcom specific entries */
    bt_config.config_mask |= BSA_DM_CONFIG_BRCM_MASK;

    /* The pass loss threshold configuration (beyond this loss, should not connect) */
    bt_config.path_loss_threshold = p_req->path_loss_threshold;

    /* Set Slave and Reset Master bits of the requested mode */
    bt_config.brcm_mask = p_req->brcm_mask;
    bt_config.brcm_mask |= BSA_DM_3DTV_SLAVE_MASK;
    bt_config.brcm_mask &= ~BSA_DM_3DTV_MASTER_MASK;

    /* Copy the Master BdAddr to lock/connect to */
    bdcpy(bt_config.master_3d_bd_addr, p_req->bd_addr_to_lock);

    /* Set callback */
    bt_config.callback = app_3dtv_callback;

    bsa_status = BSA_DmSetConfig(&bt_config);
    if (bsa_status != BSA_SUCCESS)
    {
        APP_ERROR1("BSA_DmSetConfig failed status:%d ", bsa_status);
        return(-1);
    }

    /* 3DTV is in Slave mode */
    app_3dtv_cb.dtv_mode = APP_3DTV_MODE_SLAVE;

    return 0;
}
Beispiel #14
0
/***************************************************************************
 **
 ** Function       btif_rc_get_connected_peer
 **
 ** Description    Fetches the connected headset's BD_ADDR if any
 **
 ***************************************************************************/
BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr)
{
    if (btif_rc_cb.rc_connected == TRUE) {
        bdcpy(peer_addr, btif_rc_cb.rc_addr);
        return TRUE;
    }
    return FALSE;
}
static void btif_gatt_set_encryption_cb (BD_ADDR bd_addr, tBTA_STATUS result)
{
    if (result != BTA_SUCCESS)
    {
        bt_bdaddr_t bda;
        bdcpy(bda.address, bd_addr);

        btif_dm_remove_bond(&bda);
    }
}
Beispiel #16
0
/*******************************************************************************
**
** Function         BTA_AvDisconnect
**
** Description      Close the connection to the address.
**
** Returns          void
**
*******************************************************************************/
void BTA_AvDisconnect(BD_ADDR bd_addr)
{
    tBTA_AV_API_DISCNT  *p_buf;

    if ((p_buf = (tBTA_AV_API_DISCNT *) GKI_getbuf(sizeof(tBTA_AV_API_DISCNT))) != NULL) {
        p_buf->hdr.event = BTA_AV_API_DISCONNECT_EVT;
        bdcpy(p_buf->bd_addr, bd_addr);
        bta_sys_sendmsg(p_buf);
    }
}
/*******************************************************************************
**
** Function         bta_hf_client_cback_open
**
** Description      Send open callback event to application.
**
**
** Returns          void
**
*******************************************************************************/
static void bta_hf_client_cback_open(tBTA_HF_CLIENT_DATA *p_data, tBTA_HF_CLIENT_STATUS status)
{
    tBTA_HF_CLIENT evt;

    memset(&evt, 0, sizeof(evt));

    /* call app callback with open event */
    evt.open.status = status;
    if(p_data)
    {
        /* if p_data is provided then we need to pick the bd address from the open api structure */
        bdcpy(evt.open.bd_addr, p_data->api_open.bd_addr);
    }
    else
    {
        bdcpy(evt.open.bd_addr, bta_hf_client_cb.scb.peer_addr);
    }

    (*bta_hf_client_cb.p_cback)(BTA_HF_CLIENT_OPEN_EVT, &evt);
}
/*******************************************************************************
**
** Function         bta_ag_cback_open
**
** Description      Send open callback event to application.
**
**
** Returns          void
**
*******************************************************************************/
static void bta_ag_cback_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data, tBTA_AG_STATUS status)
{
    tBTA_AG_OPEN    open;

    /* call app callback with open event */
    open.hdr.handle = bta_ag_scb_to_idx(p_scb);
    open.hdr.app_id = p_scb->app_id;
    open.status = status;
    open.service_id = bta_ag_svc_id[p_scb->conn_service];
    if(p_data)
    {
        /* if p_data is provided then we need to pick the bd address from the open api structure */
        bdcpy(open.bd_addr, p_data->api_open.bd_addr);
    }
    else
    {
        bdcpy(open.bd_addr, p_scb->peer_addr);
    }

    (*bta_ag_cb.p_cback)(BTA_AG_OPEN_EVT, (tBTA_AG *) &open);
}
/*******************************************************************************
**
** Function         BTA_HfClientOpen
**
** Description      Opens a connection to an audio gateway.
**                  When connection is open callback function is called
**                  with a BTA_AG_OPEN_EVT. Only the data connection is
**                  opened. The audio connection is not opened.
**
**
** Returns          void
**
*******************************************************************************/
BTA_API void BTA_HfClientOpen(UINT16 handle, BD_ADDR bd_addr, tBTA_SEC sec_mask)
{
    tBTA_HF_CLIENT_API_OPEN  *p_buf;

    if ((p_buf = (tBTA_HF_CLIENT_API_OPEN *) GKI_getbuf(sizeof(tBTA_HF_CLIENT_API_OPEN))) != NULL)
    {
        p_buf->hdr.event = BTA_HF_CLIENT_API_OPEN_EVT;
        p_buf->hdr.layer_specific = handle;
        bdcpy(p_buf->bd_addr, bd_addr);
        p_buf->sec_mask = sec_mask;
        bta_sys_sendmsg(p_buf);
    }
}
/*******************************************************************************
**
** Function         connect
**
** Description     connect to audio gateway
**
** Returns         bt_status_t
**
*******************************************************************************/
static bt_status_t connect_int( bt_bdaddr_t *bd_addr, uint16_t uuid )
{
    if (is_connected(bd_addr))
        return BT_STATUS_BUSY;

    btif_hf_client_cb.state = BTHF_CLIENT_CONNECTION_STATE_CONNECTING;
    bdcpy(btif_hf_client_cb.connected_bda.address, bd_addr->address);

    BTA_HfClientOpen(btif_hf_client_cb.handle, btif_hf_client_cb.connected_bda.address,
               BTIF_HF_CLIENT_SECURITY);

    return BT_STATUS_SUCCESS;
}
Beispiel #21
0
/*******************************************************************************
**
** Function         BTA_AgOpen
**
** Description      Opens a connection to a headset or hands-free device.
**                  When connection is open callback function is called
**                  with a BTA_AG_OPEN_EVT. Only the data connection is
**                  opened. The audio connection is not opened.
**
**
** Returns          void
**
*******************************************************************************/
void BTA_AgOpen(UINT16 handle, BD_ADDR bd_addr, tBTA_SEC sec_mask, tBTA_SERVICE_MASK services)
{
    tBTA_AG_API_OPEN  *p_buf;

    if ((p_buf = (tBTA_AG_API_OPEN *) GKI_getbuf(sizeof(tBTA_AG_API_OPEN))) != NULL)
    {
        p_buf->hdr.event = BTA_AG_API_OPEN_EVT;
        p_buf->hdr.layer_specific = handle;
        bdcpy(p_buf->bd_addr, bd_addr);
        p_buf->services = services;
        p_buf->sec_mask = sec_mask;
        bta_sys_sendmsg(p_buf);
    }
}
Beispiel #22
0
static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
{
    esp_ble_gap_cb_param_t param;
    btc_msg_t msg;

    msg.sig = BTC_SIG_API_CB;
    msg.pid = BTC_PID_GAP_BLE;
    msg.act = ESP_GAP_BLE_SCAN_RESULT_EVT;

    param.scan_rst.search_evt = event;
    switch (event) {
    case BTA_DM_INQ_RES_EVT: {
        bdcpy(param.scan_rst.bda, p_data->inq_res.bd_addr);
        param.scan_rst.dev_type = p_data->inq_res.device_type;
        param.scan_rst.rssi = p_data->inq_res.rssi;
        param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
        param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type;
        param.scan_rst.flag = p_data->inq_res.flag;
        param.scan_rst.num_resps = 1;
        param.scan_rst.adv_data_len = p_data->inq_res.adv_data_len;
        param.scan_rst.scan_rsp_len = p_data->inq_res.scan_rsp_len;
        memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir, sizeof(param.scan_rst.ble_adv));
        break;
    }
    case BTA_DM_INQ_CMPL_EVT: {
        param.scan_rst.num_resps = p_data->inq_cmpl.num_resps;
        LOG_ERROR("%s  BLE observe complete. Num Resp %d\n", __FUNCTION__, p_data->inq_cmpl.num_resps);
        break;
    }
    case BTA_DM_DISC_RES_EVT:
        LOG_ERROR("BTA_DM_DISC_RES_EVT\n");
        break;
    case BTA_DM_DISC_BLE_RES_EVT:
        LOG_ERROR("BTA_DM_DISC_BLE_RES_EVT\n");
        break;
    case BTA_DM_DISC_CMPL_EVT:
        LOG_ERROR("BTA_DM_DISC_CMPL_EVT\n");
        break;
    case BTA_DM_DI_DISC_CMPL_EVT:
        LOG_ERROR("BTA_DM_DI_DISC_CMPL_EVT\n");
        break;
    case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
        LOG_ERROR("BTA_DM_SEARCH_CANCEL_CMPL_EVT\n");
        break;
    default:
        LOG_ERROR("%s : Unknown event 0x%x\n", __FUNCTION__, event);
        return;
    }
    btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL);
}
/*******************************************************************************
**
** Function         bta_dm_pm_btm_cback
**
** Description      BTM power manager callback.
**
**
** Returns          void
**
*******************************************************************************/
static void bta_dm_pm_btm_cback(BD_ADDR bd_addr, tBTM_PM_STATUS status, UINT16 value, UINT8 hci_status)
{
   tBTA_DM_PM_BTM_STATUS  *p_buf;

   if ((p_buf = (tBTA_DM_PM_BTM_STATUS *) GKI_getbuf(sizeof(tBTA_DM_PM_BTM_STATUS))) != NULL)
    {
        p_buf->hdr.event = BTA_DM_PM_BTM_STATUS_EVT;
        p_buf->status = status;
        p_buf->value = value;
        p_buf->hci_status = hci_status;
        bdcpy(p_buf->bd_addr, bd_addr);
        bta_sys_sendmsg(p_buf);
    }
}
Beispiel #24
0
/*******************************************************************************
**
** Function         bta_dm_ci_rmt_oob
**
** Description      This function must be called in response to function
**                  bta_dm_co_rmt_oob() to provide the OOB data associated
**                  with the remote device.
**
** Returns          void
**
*******************************************************************************/
void bta_dm_ci_rmt_oob(BOOLEAN accept, BD_ADDR bd_addr, BT_OCTET16 c, BT_OCTET16 r)
{
    tBTA_DM_CI_RMT_OOB    *p_msg;

    if ((p_msg = (tBTA_DM_CI_RMT_OOB *) GKI_getbuf(sizeof(tBTA_DM_CI_RMT_OOB))) != NULL)
    {
        p_msg->hdr.event = BTA_DM_CI_RMT_OOB_EVT;
        bdcpy(p_msg->bd_addr, bd_addr);
        p_msg->accept    = accept;
        memcpy(p_msg->c, c, BT_OCTET16_LEN);
        memcpy(p_msg->r, r, BT_OCTET16_LEN);
        bta_sys_sendmsg(p_msg);
    }
}
Beispiel #25
0
/*******************************************************************************
**
** Function         connect
**
** Description     connect to headset
**
** Returns         bt_status_t
**
*******************************************************************************/
static bt_status_t connect_int( bt_bdaddr_t *bd_addr )
{
    if (!is_connected(bd_addr))
    {
        btif_hf_cb.state = BTHF_CONNECTION_STATE_CONNECTING;
        bdcpy(btif_hf_cb.connected_bda.address, bd_addr->address);

        BTA_AgOpen(btif_hf_cb.handle, btif_hf_cb.connected_bda.address,
                   BTIF_HF_SECURITY, BTIF_HF_SERVICES);
        return BT_STATUS_SUCCESS;
    }

    return BT_STATUS_BUSY;
}
void bta_av_conn_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
{
    tBTA_AV_STR_MSG     *p_msg;
    UINT16  evt = 0;
    tBTA_AV_SCB *p_scb = NULL;

#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
    if (event == BTA_AR_AVDT_CONN_EVT ||
        event == AVDT_CONNECT_IND_EVT || event == AVDT_DISCONNECT_IND_EVT)
#else
    if (event == AVDT_CONNECT_IND_EVT || event == AVDT_DISCONNECT_IND_EVT)
#endif
    {
        evt = BTA_AV_SIG_CHG_EVT;
        if(AVDT_DISCONNECT_IND_EVT == event)
            p_scb = bta_av_addr_to_scb(bd_addr);
#if (defined(BTA_AV_DEBUG) && BTA_AV_DEBUG == TRUE)
        else if (AVDT_CONNECT_IND_EVT == event)
        {
            APPL_TRACE_DEBUG1("CONN_IND is ACP:%d", p_data->hdr.err_param);
        }
#endif

        if (/*((p_scb && (p_scb->role & BTA_AV_ROLE_AD_ACP)) ||

            //(AVDT_CONNECT_IND_EVT == event && AVDT_ACP == p_data->hdr.err_param))

            (AVDT_CONNECT_IND_EVT == event))&& */
            (p_msg = (tBTA_AV_STR_MSG *) GKI_getbuf((UINT16) (sizeof(tBTA_AV_STR_MSG)))) != NULL)
        {
            p_msg->hdr.event = evt;
            p_msg->hdr.layer_specific = event;
            p_msg->hdr.offset = p_data->hdr.err_param;
            bdcpy(p_msg->bd_addr, bd_addr);
#if (defined(BTA_AV_DEBUG) && BTA_AV_DEBUG == TRUE)
            if(p_scb)
            {
                APPL_TRACE_DEBUG2("scb hndl x%x, role x%x", p_scb->hndl, p_scb->role);
            }
#endif
            APPL_TRACE_DEBUG6("conn_cback bd_addr:%02x-%02x-%02x-%02x-%02x-%02x",
                          bd_addr[0], bd_addr[1],
                          bd_addr[2], bd_addr[3],
                          bd_addr[4], bd_addr[5]);
            bta_sys_sendmsg(p_msg);
        }
    }

}
/*******************************************************************************
**
** Function         BTA_AvOpen
**
** Description      Opens an advanced audio/video connection to a peer device.
**                  When connection is open callback function is called
**                  with a BTA_AV_OPEN_EVT.
**
** Returns          void
**
*******************************************************************************/
void BTA_AvOpen(BD_ADDR bd_addr, tBTA_AV_HNDL handle, BOOLEAN use_rc, tBTA_SEC sec_mask)
{
    tBTA_AV_API_OPEN  *p_buf;

    if ((p_buf = (tBTA_AV_API_OPEN *) GKI_getbuf(sizeof(tBTA_AV_API_OPEN))) != NULL)
    {
        p_buf->hdr.event = BTA_AV_API_OPEN_EVT;
        p_buf->hdr.layer_specific   = handle;
        bdcpy(p_buf->bd_addr, bd_addr);
        p_buf->use_rc = use_rc;
        p_buf->sec_mask = sec_mask;
        p_buf->switch_res = BTA_AV_RS_NONE;
        bta_sys_sendmsg(p_buf);
    }
}
Beispiel #28
0
/*******************************************************************************
**
** Function         BTA_PanOpen
**
** Description      Opens a connection to a peer device.
**                  When connection is open callback function is called
**                  with a BTA_PAN_OPEN_EVT.
**
**
** Returns          void
**
*******************************************************************************/
void BTA_PanOpen(BD_ADDR bd_addr, tBTA_PAN_ROLE    local_role, tBTA_PAN_ROLE    peer_role)
{

    tBTA_PAN_API_OPEN  *p_buf;

    if ((p_buf = (tBTA_PAN_API_OPEN *) GKI_getbuf(sizeof(tBTA_PAN_API_OPEN))) != NULL)
    {
        p_buf->hdr.event = BTA_PAN_API_OPEN_EVT;
        p_buf->local_role = local_role;
        p_buf->peer_role = peer_role;
        bdcpy(p_buf->bd_addr, bd_addr);
        bta_sys_sendmsg(p_buf);
    }

}
void btif_gatt_check_encrypted_link (BD_ADDR bd_addr)
{
    char buf[100];

    bt_bdaddr_t bda;
    bdcpy(bda.address, bd_addr);

    if ((btif_storage_get_ble_bonding_key(&bda, BTIF_DM_LE_KEY_PENC,
                    buf, sizeof(btif_dm_ble_penc_keys_t)) == BT_STATUS_SUCCESS)
        && !btif_gatt_is_link_encrypted(bd_addr))
    {
        BTA_DmSetEncryption(bd_addr,
                            &btif_gatt_set_encryption_cb, BTM_BLE_SEC_ENCRYPT);
    }
}
Beispiel #30
0
/*******************************************************************************
**
** Function         bta_dm_ci_io_req
**
** Description      This function must be called in response to function
**                  bta_dm_co_io_req(), if *p_oob_data to BTA_OOB_UNKNOWN
**                  by bta_dm_co_io_req().
**
** Returns          void
**
*******************************************************************************/
void bta_dm_ci_io_req(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, tBTA_OOB_DATA oob_data,
                                     tBTA_AUTH_REQ auth_req)

{
    tBTA_DM_CI_IO_REQ    *p_msg;

    if ((p_msg = (tBTA_DM_CI_IO_REQ *) GKI_getbuf(sizeof(tBTA_DM_CI_IO_REQ))) != NULL)
    {
        p_msg->hdr.event = BTA_DM_CI_IO_REQ_EVT;
        bdcpy(p_msg->bd_addr, bd_addr);
        p_msg->io_cap   = io_cap;
        p_msg->oob_data = oob_data;
        p_msg->auth_req = auth_req;
        bta_sys_sendmsg(p_msg);
    }
}