コード例 #1
0
/*******************************************************************************
**
** Function         btif_hd_upstreams_evt
**
** Description      Executes events in btif context
**
** Returns          void
**
*******************************************************************************/
static void btif_hd_upstreams_evt(UINT16 event, char* p_param)
{
    tBTA_HD *p_data = (tBTA_HD *)p_param;

    BTIF_TRACE_API("%s: event=%s", __FUNCTION__, dump_hd_event(event));

    switch (event)
    {
        case BTA_HD_ENABLE_EVT:
            BTIF_TRACE_DEBUG("%s: status=%d", __FUNCTION__, p_data->status);
            if (p_data->status == BTA_HD_OK)
            {
                btif_storage_load_hidd();
                btif_hd_cb.status = BTIF_HD_ENABLED;
            }
            else
            {
                btif_hd_cb.status = BTIF_HD_DISABLED;
                BTIF_TRACE_WARNING("Failed to enable BT-HD, status=%d", p_data->status);
            }
            break;

        case BTA_HD_DISABLE_EVT:
            BTIF_TRACE_DEBUG("%s: status=%d", __FUNCTION__, p_data->status);
            btif_hd_cb.status = BTIF_HD_DISABLED;
            if (p_data->status == BTA_HD_OK)
                memset(&btif_hd_cb, 0, sizeof(btif_hd_cb));
            else
                BTIF_TRACE_WARNING("Failed to disable BT-HD, status=%d", p_data->status);
            break;

        case BTA_HD_REGISTER_APP_EVT:
            {
                bt_bdaddr_t *addr = (bt_bdaddr_t*) &p_data->reg_status.bda;

                if (!p_data->reg_status.in_use)
                {
                    addr = NULL;
                }

                btif_hd_cb.app_registered = TRUE;
                HAL_CBACK(bt_hd_callbacks, application_state_cb, addr, BTHD_APP_STATE_REGISTERED);
        }
            break;

        case BTA_HD_UNREGISTER_APP_EVT:
            btif_hd_cb.app_registered = FALSE;
            HAL_CBACK(bt_hd_callbacks, application_state_cb, NULL, BTHD_APP_STATE_NOT_REGISTERED);
            break;

        case BTA_HD_OPEN_EVT:
            btif_storage_set_hidd((bt_bdaddr_t*) &p_data->conn.bda);

            HAL_CBACK(bt_hd_callbacks, connection_state_cb, (bt_bdaddr_t*) &p_data->conn.bda,
                BTHD_CONN_STATE_CONNECTED);
            break;

        case BTA_HD_CLOSE_EVT:
             HAL_CBACK(bt_hd_callbacks, connection_state_cb, (bt_bdaddr_t*) &p_data->conn.bda,
                BTHD_CONN_STATE_DISCONNECTED);
             break;

        case BTA_HD_GET_REPORT_EVT:
            HAL_CBACK(bt_hd_callbacks, get_report_cb,
                        p_data->get_report.report_type, p_data->get_report.report_id,
                        p_data->get_report.buffer_size);
            break;

        case BTA_HD_SET_REPORT_EVT:
            HAL_CBACK(bt_hd_callbacks, set_report_cb, p_data->set_report.report_type,
                p_data->set_report.report_id, p_data->set_report.len,
                p_data->set_report.p_data);
            break;

        case BTA_HD_SET_PROTOCOL_EVT:
            HAL_CBACK(bt_hd_callbacks, set_protocol_cb, p_data->set_protocol);
            break;

        case BTA_HD_INTR_DATA_EVT:
            HAL_CBACK(bt_hd_callbacks, intr_data_cb, p_data->intr_data.report_id,
                p_data->intr_data.len, p_data->intr_data.p_data);
            break;

        case BTA_HD_VC_UNPLUG_EVT:
            HAL_CBACK(bt_hd_callbacks, connection_state_cb, (bt_bdaddr_t*) &p_data->conn.bda,
                BTHD_CONN_STATE_DISCONNECTED);
            if (bta_dm_check_if_only_hd_connected(p_data->conn.bda)) {
                BTIF_TRACE_DEBUG("%s: Removing bonding as only HID profile connected",
                    __FUNCTION__);
                BTA_DmRemoveDevice((UINT8 *) &p_data->conn.bda);
            } else {
                bt_bdaddr_t *bd_addr = (bt_bdaddr_t*)&p_data->conn.bda;
                BTIF_TRACE_DEBUG("%s: Only removing HID data as some other profiles "
                    "connected", __FUNCTION__);
                btif_hd_remove_device(*bd_addr);
            }
            HAL_CBACK(bt_hd_callbacks, vc_unplug_cb);
            break;

        default:
            BTIF_TRACE_WARNING("%s: unknown event (%d)", __FUNCTION__, event);
            break;
    }
}
コード例 #2
0
ファイル: btc_gap_ble.c プロジェクト: altran-nl/esp-idf
void btc_gap_ble_call_handler(btc_msg_t *msg)
{
    btc_ble_gap_args_t *arg = (btc_ble_gap_args_t *)msg->arg;

    LOG_DEBUG("%s act %d\n", __FUNCTION__, msg->act);

    switch (msg->act) {
    case BTC_GAP_BLE_ACT_CFG_ADV_DATA: {
        if (arg->cfg_adv_data.adv_data.set_scan_rsp == false) {
            btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data, btc_adv_data_callback);
        } else {
            btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data, btc_scan_rsp_data_callback);
        }
        break;
    }
    case BTC_GAP_BLE_ACT_SET_SCAN_PARAM:
        btc_ble_set_scan_params(&arg->set_scan_param.scan_params, btc_scan_params_callback);
        break;
    case BTC_GAP_BLE_ACT_START_SCAN:
        btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback, btc_start_scan_callback);
        break;
    case BTC_GAP_BLE_ACT_STOP_SCAN:
        btc_ble_stop_scanning(btc_stop_scan_callback);
        break;
    case BTC_GAP_BLE_ACT_START_ADV:
        btc_ble_start_advertising(&arg->start_adv.adv_params, btc_start_adv_callback);
        break;
    case BTC_GAP_BLE_ACT_STOP_ADV:
        btc_ble_stop_advertising(btc_stop_adv_callback);
        break;
    case BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM:
        btc_ble_update_conn_params(arg->conn_update_params.conn_params.bda,
                                   arg->conn_update_params.conn_params.min_int,
                                   arg->conn_update_params.conn_params.max_int,
                                   arg->conn_update_params.conn_params.latency,
                                   arg->conn_update_params.conn_params.timeout);
        break;
    case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN:
        btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length, btc_set_pkt_length_callback);
        break;
    case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS: {
        BD_ADDR bd_addr;
        memcpy(bd_addr, arg->set_rand_addr.rand_addr, sizeof(BD_ADDR));
        btc_ble_set_rand_addr(bd_addr);
        break;
    }
    case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
        btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback);
        break;
    case BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST:
        BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, btc_add_whitelist_complete_callback);
        break;
    case BTC_GAP_BLE_ACT_READ_RSSI:
        BTA_DmBleReadRSSI(arg->read_rssi.remote_addr, btc_read_ble_rssi_cmpl_callback);
        break;
    case BTC_GAP_BLE_ACT_SET_CONN_PARAMS:
        BTA_DmSetBlePrefConnParams(arg->set_conn_params.bd_addr, arg->set_conn_params.min_conn_int,
                                                        arg->set_conn_params.max_conn_int, arg->set_conn_params.slave_latency,
                                                        arg->set_conn_params.supervision_tout);
        break;
    case BTC_GAP_BLE_ACT_SET_DEV_NAME:
        BTA_DmSetDeviceName(arg->set_dev_name.device_name);
        break;
    case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
        btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
                                 arg->cfg_adv_data_raw.raw_adv_len,
                                 btc_adv_data_raw_callback);
        break;
    case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW:
        btc_ble_set_scan_rsp_data_raw(arg->cfg_scan_rsp_data_raw.raw_scan_rsp,
                                      arg->cfg_scan_rsp_data_raw.raw_scan_rsp_len,
                                      btc_scan_rsp_data_raw_callback);
        break;
#if (SMP_INCLUDED == TRUE)
    case BTC_GAP_BLE_SET_ENCRYPTION_EVT: {
        BD_ADDR bd_addr;
        memcpy(bd_addr, arg->set_encryption.bd_addr, sizeof(BD_ADDR));
        BTA_DmSetEncryption(bd_addr, BT_TRANSPORT_LE, btc_set_encryption_callback,
                                          (tBTA_DM_BLE_SEC_ACT)arg->set_encryption.sec_act);
        break;
    }
    case BTC_GAP_BLE_SET_SECURITY_PARAM_EVT: {
        switch(arg->set_security_param.param_type) {
            case ESP_BLE_SM_PASSKEY:
                break;
            case ESP_BLE_SM_AUTHEN_REQ_MODE: {
                uint8_t authen_req = 0;
                STREAM_TO_UINT8(authen_req, arg->set_security_param.value);
                bta_dm_co_ble_set_auth_req(authen_req);
                break;
            }
            case ESP_BLE_SM_IOCAP_MODE: {
                uint8_t iocap = 0;
                STREAM_TO_UINT8(iocap, arg->set_security_param.value);
                bta_dm_co_ble_set_io_cap(iocap);
                break;
            }
            case ESP_BLE_SM_SET_INIT_KEY: {
                uint8_t init_key = 0;
                STREAM_TO_UINT8(init_key, arg->set_security_param.value);
                bta_dm_co_ble_set_init_key_req(init_key);
                break;
            }
            case ESP_BLE_SM_SET_RSP_KEY: {
                uint8_t rsp_key = 0;
                STREAM_TO_UINT8(rsp_key, arg->set_security_param.value);
                bta_dm_co_ble_set_rsp_key_req(rsp_key);
                break;
            }
            case ESP_BLE_SM_MAX_KEY_SIZE: {
                uint8_t key_size = 0;
                STREAM_TO_UINT8(key_size, arg->set_security_param.value);
                bta_dm_co_ble_set_max_key_size(key_size);
                break;
            }
            default:
                break;
        }
        break;
    }
    case BTC_GAP_BLE_SECURITY_RSP_EVT: {
        BD_ADDR bd_addr;
        tBTA_DM_BLE_SEC_GRANT res = arg->sec_rsp.accept ? BTA_DM_SEC_GRANTED : BTA_DM_SEC_PAIR_NOT_SPT;
        memcpy(bd_addr, arg->sec_rsp.bd_addr, sizeof(BD_ADDR));
        BTA_DmBleSecurityGrant(bd_addr, res);
        break;
    }
    case BTC_GAP_BLE_PASSKEY_REPLY_EVT: {
        BD_ADDR bd_addr;
        memcpy(bd_addr, arg->enc_passkey_replay.bd_addr, sizeof(BD_ADDR));
        BTA_DmBlePasskeyReply(bd_addr, arg->enc_passkey_replay.accept, arg->enc_passkey_replay.passkey);
        break;
    }
    case BTC_GAP_BLE_CONFIRM_REPLY_EVT: {
        BD_ADDR bd_addr;
        memcpy(bd_addr, arg->enc_comfirm_replay.bd_addr, sizeof(BD_ADDR));
        BTA_DmBleConfirmReply(bd_addr, arg->enc_comfirm_replay.accept);
        break;
    }
    case BTC_GAP_BLE_REMOVE_BOND_DEV_EVT: {
        BD_ADDR bd_addr;
        memcpy(bd_addr, arg->remove_bond_device.bd_addr, sizeof(BD_ADDR));
        BTA_DmRemoveDevice(bd_addr);
        break;
    }
#endif  ///SMP_INCLUDED == TRUE
    case BTC_GAP_BLE_DISCONNECT_EVT:
        btc_ble_disconnect(arg->disconnect.remote_device);
        break;
    default:
        break;
    }

    btc_gap_ble_arg_deep_free(msg);
}