static bool id_match(const conn_instance* p, conn_type type, conn_id id)
{
    bool match = FALSE;

    if(p != NULL)
    {
        if(p->type == type)
        {
            switch(type)
            {
            case conn_rfcomm:
                /* Searching for an RFCOMM connection instance is complicated as only limited
                   data is available during the early phases of connection establishment.  It's
                   not until the completion of parameter negotiation that the mux id and server 
                   channel have been assigned */
                if(id.rfcomm_id.server_channel == INVALID_SERVER_CHANNEL)
                {
                    /* Invalid Server Channel, match on Bluetooth Device Address and Multiplexer id */
                    if(BdaddrIsSame(&p->id.rfcomm_id.bd_addr, &id.rfcomm_id.bd_addr) || (p->id.rfcomm_id.mux_id == id.rfcomm_id.mux_id))
                    {
                        match = TRUE;
                    }
                    if(BdaddrIsZero(&id.rfcomm_id.bd_addr) && (p->id.rfcomm_id.mux_id == id.rfcomm_id.mux_id))
                    {
                        if(p->id.rfcomm_id.server_channel == 0xff)
                            match = TRUE;
                    }
                }
                else if(id.rfcomm_id.mux_id == INVALID_MUX_ID)
                {
                    /* Invalid Multiplexer ID, match on Bluetooth Address and Server Channel */
                    if (BdaddrIsSame(&p->id.rfcomm_id.bd_addr, &id.rfcomm_id.bd_addr) && (p->id.rfcomm_id.server_channel == id.rfcomm_id.server_channel))
                        match = TRUE;
                }
                else
                {
                    /* Match on Multiplexer ID and Server Channel */
                    if((p->id.rfcomm_id.mux_id == id.rfcomm_id.mux_id && p->id.rfcomm_id.server_channel == id.rfcomm_id.server_channel))
                    {
                        match = TRUE;
                    }
                }
                break;

            case conn_l2cap:
                if(p->id.l2cap_id.cid == id.l2cap_id.cid && id.l2cap_id.cid != L2CA_CID_INVALID)
                    match = TRUE;
				else if ((p->id.l2cap_id.psm == id.l2cap_id.psm) && (id.l2cap_id.psm != L2CA_PSM_INVALID) &&
					(id.l2cap_id.cid != L2CA_CID_INVALID) &&(p->id.l2cap_id.cid == L2CA_CID_INVALID))
					match = FALSE;
                else if (p->id.l2cap_id.psm == id.l2cap_id.psm && id.l2cap_id.psm != L2CA_PSM_INVALID && 
                    p->id.l2cap_id.cid == L2CA_CID_INVALID)
                    match = TRUE;
                break;
            }
        }
    }

    return match;
}
/****************************************************************************
NAME	
	connectionHandleSdpCloseSearchRequest

DESCRIPTION
	Issue a close search request to BlueStack

RETURNS
	void	
*/
void connectionHandleSdpCloseSearchRequest(const connectionSdpState *state, const CL_INTERNAL_SDP_CLOSE_SEARCH_REQ_T *req)
{
	/* Check the state of the resource lock */
	if (state->sdpLock)
	{
		/* Check if we have a search session currently open */
		if (!BdaddrIsZero(&state->sdpServerAddr))
		{
			/* We do have a search session open */
			if (state->sdpLock == req->theAppTask)
			{
				/* Only allow the task that opened the search to close it */
				MAKE_PRIM_T(SDC_CLOSE_SEARCH_REQ);
				VmSendSdpPrim(prim);
			}
			else
			{
				/* Task requesting the search be closed did not open it - send error */
				sendSdpCloseSearchCfm(req->theAppTask, sdp_task_did_not_open_search);
			}
		}
		else
		{
			/* We don't have a search session open, reply immediately with error */
			sendSdpCloseSearchCfm(req->theAppTask, sdp_search_not_open);
		}
	}
	else
	{
		/* There can't be a search open, reply immediately with an error */	
		sendSdpCloseSearchCfm(req->theAppTask, sdp_search_not_open);
	}
}
/****************************************************************************
NAME	
	sendSearchRequest

DESCRIPTION
	Decide whather a search request primitive can be sent to BlueStack or not

RETURNS
	sdp_search_req - see typedef above
*/
static sdp_search_req sendSearchRequest(Task theAppTask, const connectionSdpState *state, const bdaddr *bd_addr)
{
	/* Check the first lock */
	if (state->sdpLock)
	{
		/* SDP search session open or non search primitive sent to BlueStack */
		if (BdaddrIsZero(&state->sdpServerAddr))
		{
			/* 
				SDP search session not open but another prim is currently 
				being handled (sdpLock set) so we can't start the search yet
			*/
			return sdp_lock_set;
		}
		else
		{
			/* Addr set - SDP search session open */
			if (state->sdpSearchLock)
			{
				/* Search currently active so can't start another one */
				return sdp_search_lock_set;
			}
			else
			{
				/* SDP session open but no active search */
				if (BdaddrIsSame(&state->sdpServerAddr, bd_addr))
				{
					/* 
						SDP search session open to the device we want to search 
						so we can just start our search
					*/
					return sdp_start_search;
				}
				else
				{
					/* 
						SDP search session open to a different device so we can't
						do our search until this session is closed.
					*/
					return sdp_session_open_other_dev;
				}
			}
		}
	}
	else
	{
		/* Check if we currently have a search active, block internal requests if sdpLock not set */
		if (state->sdpSearchLock || theAppTask == connectionGetCmTask())
		{
			/* Search currently active */
			return sdp_search_lock_set;
		}
		else
		{
			/* No search currently active */
			return sdp_start_search;
		}
	}
}
Example #4
0
/*
	Connect to PBAP Server
*/
void pbapConnect(const bdaddr pAddr)
{
    if(!BdaddrIsZero(&pAddr))
    {
        PBAP_DEBUG(("Connecting Pbap profile, Addr %x,%x,%lx\n", pAddr.nap, pAddr.uap, pAddr.lap ));
        PbapcConnect(&pAddr, PBAP_DEF_PACKET);
    }
}
Example #5
0
/****************************************************************************
NAME    
    AuthInitPermanentPairing
    
DESCRIPTION
    Add devices stored in CONFIG_PERMANENT_PAIRING to Connection library's PDL
    
RETURNS
    void
*/
void AuthInitPermanentPairing (void)
{
    bdaddr ps_bd_addr;
    
    AUTH_DEBUG(("AuthInitPermanentPairing\n"));
    
    /* Obtain just the bluetooth address of a permanently paired device */
    readPsPermanentPairing(&ps_bd_addr, 0, 0, 0);
    AUTH_DEBUG(("   ps bd_addr = [%x:%x:%lx]\n", ps_bd_addr.uap, ps_bd_addr.nap, ps_bd_addr.lap));
    
    if ( !BdaddrIsZero(&ps_bd_addr) )
    {   /* A valid address has been obtained, ask CL for info on it */
        ConnectionSmGetAuthDevice(&theSink.task, (const bdaddr *)&ps_bd_addr);
    }
}
/****************************************************************************
NAME
    commActionConnect

DESCRIPTION
    Handles connect comm action. Connects to device with Bluetooth address of
    the_app->connect_bdaddr.
    
*/
static bool commActionConnect(mvdCommAction *comm_action)
{
    bool command_to_process = FALSE;
    
    switch ( the_app->app_state )
    {
        case AppStateIdle:
        {
            if (profileSlcAreAnyRemoteDevicesConnecting())
            {            
                break;
            }   
            
            /* Attempt to connect to either current or last known device */
            if (!BdaddrIsZero(&the_app->connect_bdaddr))
            {         
                the_app->comm_action = *comm_action;
                the_app->connect_attempts = 0;
                profileSlcConnectReq();                                                              
            }
            
            /* No last paired device, ignore this command and check for any queued action */
            command_to_process = checkPendingCommAction(comm_action);
            break;
        }    
        case AppStateConnecting:
        {
            /* Already connecting - ignore */
            break;
        }        
        case AppStateStreaming:
        case AppStateInCall:
        {
            /* In correct state, check for any queued action */
            command_to_process = checkPendingCommAction(comm_action);
            break;
        }
        default:
        {
            /* Command issued in wrong state, queue it */
            the_app->pending_comm_action = *comm_action;
            break;
        }
    }    
    return command_to_process;
}
Example #7
0
/****************************************************************************
NAME    
    handleGetAuthDeviceCfm
    
DESCRIPTION
    Called in response to CL_SM_GET_AUTH_DEVICE_CFM message, which is generated
    due to calling updatePermanentPairing.
    Both the BDADDR and linkkey contained in CL_SM_GET_AUTH_DEVICE_CFM are used to
    update CONFIG_PERMANENT_PAIRING to retain this as the permanently paired device
    
RETURNS
    void
*/
void handleGetAuthDeviceCfm (CL_SM_GET_AUTH_DEVICE_CFM_T *cfm)
{
    AUTH_DEBUG(("handleGetAuthDeviceCfm\n"));
    AUTH_DEBUG(("   status = %u\n",cfm->status));
    AUTH_DEBUG(("   ps bd_addr = [%x:%x:%lx]\n", cfm->bd_addr.uap, cfm->bd_addr.nap, cfm->bd_addr.lap));
    AUTH_DEBUG(("   trusted = %u\n",cfm->trusted));
    AUTH_DEBUG(("   link key type = %u",cfm->link_key_type));
    AUTH_DEBUG(("   link key size = %u\n",cfm->size_link_key));
    
    if ( cfm->status == success )
    {   /* Device exists in CL PDL */
        sink_attributes attributes;
        uint16 link_key_status = ((cfm->trusted & 0xF)<<8) | ((cfm->link_key_type & 0xF)<<4) | (cfm->size_link_key & 0xF);
        
        /* Update permanent pairing info */
        writePsPermanentPairing(&cfm->bd_addr, cfm->link_key, link_key_status, 0);
        
        /* Update attributes */
        readPsPermanentPairing(0, 0, 0, &attributes);
        deviceManagerStoreAttributes(&attributes, (const bdaddr *)&cfm->bd_addr);
        
        /* Mark the device as trusted and push it to the top of the PDL */
        ConnectionSmUpdateMruDevice((const bdaddr *)&cfm->bd_addr);
#ifdef ENABLE_SOUNDBAR
        /* ensure priority devices are shifted back to top of PDL */
        ConnectionAuthSetPriorityDevice((const bdaddr *)&cfm->bd_addr, FALSE);            
#endif            
    }
    else
    {   /* Device *does not* exist in CL PDL */ 
        bdaddr ps_bd_addr;
        uint16 ps_link_key_status;
        uint16 ps_link_key[LINK_KEY_SIZE];
    
        readPsPermanentPairing(&ps_bd_addr, ps_link_key, &ps_link_key_status, 0);
    
        if ( !BdaddrIsZero(&ps_bd_addr) )
        {   /* We have permanently paired device, add it to CL PDL */
            bool trusted = (bool)((ps_link_key_status>>8) & 0xF);
            cl_sm_link_key_type key_type = (cl_sm_link_key_type)((ps_link_key_status>>4) & 0xF);
            uint16 size_link_key = ps_link_key_status & 0xF;
        
            ConnectionSmAddAuthDevice(&theSink.task, (const bdaddr *)&ps_bd_addr, trusted, TRUE, key_type, size_link_key, (const uint16 *)ps_link_key);
        }
    }
Example #8
0
/****************************************************************************
NAME    
    AuthRemovePermanentPairing
    
DESCRIPTION
    Removes permanent paired device from Connection library's PDL.
    Will also erase CONFIG_PERMANENT_PAIRING if erase_ps_key set TRUE.
    
RETURNS
    void
*/
void AuthRemovePermanentPairing (bool erase_ps_key)
{
    bdaddr ps_bd_addr;
    
    AUTH_DEBUG(("AuthRemovePermanentPairing  erase_ps_key = %u\n", erase_ps_key));
    
    readPsPermanentPairing(&ps_bd_addr, 0, 0, 0);
    AUTH_DEBUG(("   ps bd_addr = [%x:%x:%lx]\n", ps_bd_addr.uap, ps_bd_addr.nap, ps_bd_addr.lap));
    
    if ( !BdaddrIsZero(&ps_bd_addr) )
    {
        ConnectionSmDeleteAuthDeviceReq(TYPED_BDADDR_PUBLIC, (const bdaddr *)&ps_bd_addr);
    }
    
    if ( erase_ps_key )
    {
        PsStore(CONFIG_PERMANENT_PAIRING, 0, 0);
    }
}