⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a2dp_sd_discover.c

📁 CSR蓝牙MP3播放USB DONGLE源码
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.5.2-release

FILE NAME
    a2dp_sd_discover.c

DESCRIPTION
    Discover available sinks.

NOTES
    
*/


/****************************************************************************
    Header files
*/
#include "a2dp_sd_private.h"
#include "a2dp_sd_discover.h"
#include "a2dp_sd_init.h"
#include "a2dp_sd_initiate.h"

#include <bdaddr.h>
#include <connection.h>
#include <ps.h>
#include <stdlib.h>


/* Service search pattern */
static const uint8 service_search_pattern[] = {0x35,0x03,0x19,0x11,0x0D};


/* Issue an inquiry request */
static void startInquiry(void)
{
    /* 
        Issue an inquiry request - set max responses to 1, the timeout to 61.44 seconds 
        and filter on class of device.
    */
    ConnectionInquire(getTheAppTask(), 0x9e8b33, 1, 0x30, (uint32) AV_MAJOR_DEVICE_CLASS);
}


/****************************************************************************
NAME    
    a2dpSdDiscover
    
DESCRIPTION
    We're in the right state so kick off a discovery process.

RETURNS
    void
*/
void a2dpSdDiscover(a2dpSourceDongleTaskData *theApp)
{
    /* Update the local state */
    avSourceDongleUpdateA2dpState(a2dp_state_discovering);
    
    /* Reset discovery pending flag */
    theApp->discover_pending = 0;

    /* Reset the PS key storing the last sink we connected to */
    if (!BdaddrIsZero(&theApp->av_sink_addr))
    {
        /* Reset the sink address. */
        BdaddrSetZero(&theApp->av_sink_addr);

        /* Reset the address in PS as well. */
        (void)PsStore(PS_AV_SINK_ADDR, &theApp->av_sink_addr, sizeof(bdaddr));
    }

    /* Start an inquiry */
    startInquiry();

    /* Set the discovery timeout */
    MessageSendLater(&theApp->task, APP_DISCOVER_TIMEOUT_IND, 0x00, (uint32) DISCOVER_TIMEOUT);
}


/****************************************************************************
NAME    
    a2dpSdInquiryResult
    
DESCRIPTION
    Have received an inquiry result that matches our criteria, try an 
    SDP search on the device.

RETURNS
    void
*/
void a2dpSdInquiryResult(const bdaddr *bd_addr)
{
    /* Delete the link key for this device */
    (void) ConnectionSmDeleteAuthDevice(bd_addr);

    /* Disable outgoing SDP security */
    ConnectionSmSetSdpSecurityOut(TRUE, bd_addr);

    /* Issue a service search */
    ConnectionSdpServiceSearchRequest(getTheAppTask(), bd_addr, 0x32, sizeof(service_search_pattern), service_search_pattern);
}


/****************************************************************************
NAME    
    a2dpDiscoverServiceSearchSuccess
    
DESCRIPTION
    Called to indicate that the SDP search on the discovered device
    succeeded, meaning that the device does support the service we're looking
    for.

RETURNS
    void
*/
void a2dpDiscoverServiceSearchSuccess(const CL_SDP_SERVICE_SEARCH_CFM_T *cfm)
{
    Task app_task = getTheAppTask();

    /* Update the local state */
    avSourceDongleUpdateA2dpState(a2dp_state_accepting);

    /* Cancel the discovery timer message */
    (void) MessageCancelAll(app_task, APP_DISCOVER_TIMEOUT_IND);

    /* Send an internal message so we can go through the state machine */
    a2dpSdInitiateRequest(&cfm->bd_addr);
}


/****************************************************************************
NAME    
    a2dpDiscoverServiceSearchFail
    
DESCRIPTION
    The remote device found does not support the AV service so we need to keep
    looking.

RETURNS
    void
*/
void a2dpDiscoverServiceSearchFail(a2dpSourceDongleTaskData *theApp)
{
    /* Reset the address the device does not support the services we're looking for */
    BdaddrSetZero(&theApp->av_sink_addr);

    /* Start an inquiry */
    startInquiry();
}


/****************************************************************************
NAME    
    a2dpDiscoverTimeout
    
DESCRIPTION
    The discover timeout has fired meaning that we have not succeeded in
    discovering a suitable device to connect to. 

RETURNS
    void
*/
void a2dpDiscoverTimeout(void)
{
    Task app_task = getTheAppTask();

    /* Update the local state */
    avSourceDongleUpdateA2dpState(a2dp_state_accepting);

    /* Cancel the inquiry, in case there's one ongoing */
    ConnectionInquireCancel(app_task);

    /* Cancel the SDP search, in case there's one ongoing */
    ConnectionSdpTerminatePrimitiveRequest(app_task);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -