예제 #1
0
static int
is_connection_established(const HANDLE hRadio, BLUETOOTH_DEVICE_INFO *device_info)
{
    /* NOTE: Sometimes the Bluetooth connection appears to be established
     *       even though the Move decided that it is not really connected
     *       yet. That is why we cannot simply stop trying to connect after
     *       the first successful check. Instead, we require a minimum
     *       number of successive successful checks to be sure.
     */

    unsigned int i;
    for (i = 0; i < CONN_CHECK_NUM_TRIES; i++) {
        /* read device info again to check if we have a connection */
        DWORD result = BluetoothGetDeviceInfo(hRadio, device_info);
        if (result != ERROR_SUCCESS) {
            WINPAIR_DEBUG("Failed to read device info");
            return 0;
        }

        if (device_info->fConnected && device_info->fRemembered && is_hid_service_enabled(hRadio, device_info)) {
        } else {
            return 0;
        }

        Sleep(CONN_CHECK_DELAY);
    }

    return 1;
}
예제 #2
0
bool BtPCModul ::GetDeviceInfo(NXTclass *nxtclass)
{
    BLUETOOTH_DEVICE_INFO m_device_info = {sizeof(BLUETOOTH_DEVICE_INFO),str2ba(nxtclass->BTaddr),};

    if (ERROR_SUCCESS!=BluetoothGetDeviceInfo(m_radio,&m_device_info))
    {
        printf("	!!!ERROR Get Params\n");   //) {cout<<"Not_Search_Device"<<endl; return 0;}
        nxtclass->authenticated=0;
        return 0;
    }
    else
    {
        wprintf(L"  \tInstance Name: %s\r\n", m_device_info.szName);
        wprintf(L"  \tAddress: %02X:%02X:%02X:%02X:%02X:%02X\r\n",
            m_device_info.Address.rgBytes[5],m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[3],
            m_device_info.Address.rgBytes[2],m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[0]);
        wprintf(L"  \tClass: 0x%08x\r\n", m_device_info.ulClassofDevice);
        wprintf(L"  \tConnected: %s\r\n", m_device_info.fConnected ? L"true" : L"false");
        wprintf(L"  \tAuthenticated: %s\r\n", m_device_info.fAuthenticated ? L"true" : L"false");
        wprintf(L"  \tRemembered: %s\r\n", m_device_info.fRemembered ? L"true" : L"false");
//        cout<<"  \tCOM-port: "<<nxtclass->port<<"\r\n";
    }
    nxtclass->authenticated=((m_device_info.fAuthenticated)&&(m_device_info.fRemembered));
    for(int i=0; i<BLUETOOTH_MAX_SIZE_NAME; i++)
        nxtclass->Name[i]=m_device_info.szName[i];
    return 1;
}
예제 #3
0
static int
update_device_info(const HANDLE hRadio, BLUETOOTH_DEVICE_INFO *device_info)
{
    DWORD result = BluetoothGetDeviceInfo(hRadio, device_info);
    if (result != ERROR_SUCCESS) {
        WINPAIR_DEBUG("Failed to read device info");
        return 1;
    }

    return 0;
}
static BluetoothPairDeviceState::eStatus
AsyncBluetoothPairDeviceRequest__attemptConnection(
    BluetoothPairDeviceState *state)
{
    assert(state->isWorkerThread());
    BluetoothPairDeviceState::eStatus nextSubStatus= 
        state->getSubStatus_WorkerThread<BluetoothPairDeviceState::eStatus>();
    bool success= true;

    SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") 
        << "Connection attempt: " << state->connectionAttemptCount << "/" << CONN_RETRIES;

    if (BluetoothGetDeviceInfo(state->hRadio, &state->deviceInfo) != ERROR_SUCCESS) 
    {
        SERVER_MT_LOG_ERROR("AsyncBluetoothPairDeviceRequest") << "Failed to read device info";

        // Fail and go back to the device scan stage
        state->connectionAttemptCount= CONN_RETRIES;
        success= false;
    }

    if (success && !state->deviceInfo.fConnected)
    {
        SERVER_MT_LOG_ERROR("AsyncBluetoothPairDeviceRequest") << "Device not connected";
        success= false;
    }

    // Keep track of how many connection attempts we have made
    ++state->connectionAttemptCount;

    if (state->connectionAttemptCount >= CONN_RETRIES)
    {
        // Fall back to scanning devices again
        nextSubStatus= BluetoothPairDeviceState::deviceScan;
    }
    else if (success)
    {
        // Move on to the patch registry state
        nextSubStatus= BluetoothPairDeviceState::patchRegistry;
    }
    else
    {
        Sleep(CONN_DELAY);
    }

    return nextSubStatus;
}
예제 #5
0
bool BtPCModul ::Authenticating(NXTclass * nxtclass)
{
    BLUETOOTH_DEVICE_INFO m_device_info = {sizeof(BLUETOOTH_DEVICE_INFO),str2ba(nxtclass->BTaddr),};
    BluetoothGetDeviceInfo(m_radio,&m_device_info);
    DWORD re=BluetoothAuthenticateDevice(0,0,&m_device_info,pin,4);
    if ((re==ERROR_NO_MORE_ITEMS)||(re==ERROR_SUCCESS))
    {
        nxtclass->authenticated=true;
        printf("Device #%d Authenticate OK.\n",nxtclass->Number);
    }
    else
    {
        nxtclass->authenticated=false;
        printf("Device #%d Authenticate ERROR.\n",nxtclass->Number);
        return 0;//ReBtConnectError(re);
    }
    return nxtclass->authenticated;
}
static BluetoothPairDeviceState::eStatus
AsyncBluetoothPairDeviceRequest__verifyConnection(
    BluetoothPairDeviceState *state)
{
    assert(state->isWorkerThread());
    BluetoothPairDeviceState::eStatus nextSubStatus= 
        state->getSubStatus_WorkerThread<BluetoothPairDeviceState::eStatus>();

    bool success= true;

    SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") 
        << "Verification attempt " << state->verifyConnectionCount
        << " / " << CONN_CHECK_NUM_TRIES;

    /* NOTE: Sometimes the Bluetooth connection appears to be established
        *       even though the Move decided that it is not really connected
        *       yet. That is why we cannot simply stop trying to connect after
        *       the first successful check. Instead, we require a minimum
        *       number of successive successful checks to be sure.
        */
    if (BluetoothGetDeviceInfo(state->hRadio, &state->deviceInfo) == ERROR_SUCCESS) 
    {
        if (state->deviceInfo.fConnected)
        {
            SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "Device Connected";
        }

        if (state->deviceInfo.fRemembered)
        {
            SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "Device Remembered";
        }

        if (is_hid_service_enabled(state->hRadio, &state->deviceInfo))
        {
            SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "HID service enabled";
        }

        if (state->deviceInfo.fConnected && state->deviceInfo.fRemembered && 
            is_hid_service_enabled(state->hRadio, &state->deviceInfo))
        {
            SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "Connected, Remembered, and HID service enabled";
        }
        else
        {
            SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "HID service not enabled";
            success= false;
        }
    }
    else
    {
        SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "Failed to read device info";
        success= false;
    }

    if (success)
    {
        ++state->verifyConnectionCount;

        if (state->verifyConnectionCount >= CONN_CHECK_NUM_TRIES)
        {
            SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "Verified connection!";
            nextSubStatus= BluetoothPairDeviceState::success;
        }
        else
        {
            nextSubStatus= BluetoothPairDeviceState::verifyConnection;
            Sleep(CONN_CHECK_DELAY);
        }
    }
    else
    {
        // Try and re-establish the connection
        SERVER_MT_LOG_INFO("AsyncBluetoothPairDeviceRequest") << "Verified failed. Re-establish connection";
        nextSubStatus= BluetoothPairDeviceState::attemptConnection;

        // Reset the connection attempt count before starting the connection attempts
        state->connectionAttemptCount= 0;
    }

    return nextSubStatus;
}