Ejemplo n.º 1
0
void SwatInit(Task clientTask, uint16 max_remote_devs, swat_role role, bool auto_handle, const uint8 *service_record, uint16 size_service_record, const sync_config_params * esco_config)
{
    /* Attempt to initialise the task data */
    if ( !swat )
    {
        swat = PanicUnlessNew(swatTaskData);
        memset( swat, 0, sizeof(swatTaskData) );
        
        SWAT_DEBUG(("[SWAT] Sizeof(swatTaskData) = %u\n", sizeof(swatTaskData)));
        
        /* Initialise the swat profile data */
        swat->l2cap_task.handler = swatL2capHandler;
        swat->profile_task.handler = swatProfileHandler;
        swat->command_task.handler = swatCommandHandler;
        swat->clientTask = clientTask;
        swat->auto_handle = auto_handle;
        swat->role = role;
        swat->max_remote_devs = max_remote_devs;

        /* Allocate memory to store remote device data depending on number of allowed devices */
        swat->remote_devs = (remoteDevice *)PanicNull(malloc(max_remote_devs * sizeof(remoteDevice)));
        memset(swat->remote_devs, 0, (max_remote_devs * sizeof(remoteDevice)));
        
        /* Use service record supplied by client */
        if (service_record)
        {
            ConnectionRegisterServiceRecord(&swat->l2cap_task, (sizeof(uint8) * size_service_record), service_record);
        }
        /* Use library default service record */
        else
        {
            ConnectionRegisterServiceRecord(&swat->l2cap_task, sizeof(swat_service_record), swat_service_record);
        }
        
        /* Use eSCO config supplied by client */
        if (esco_config)
        {
            swat->esco_config = esco_config;
        }
        else
        {
            swat->esco_config = NULL;
        }
    }
    else
    {
        swatSendInitCfmToClient(swat_init_failed);
    }
}
static void sppHandleRfcommRegisterCfm(const CL_RFCOMM_REGISTER_CFM_T *cfm)
{
    
#if SPP_DEBUG_LIB
    if (!sppsClientTask)
        SPP_DEBUG(("sppsClientTask is NULL!\n"));
#endif

    if (cfm->status != success)
    {
        sendSppStartServiceCfm(spp_start_rfc_chan_fail);
        sppsClientTask = 0;
    }
    else if (cfm->server_channel != SPP_DEFAULT_CHANNEL)
    {
        sendSppStartServiceCfm(spp_start_rfc_default_fail);
        sppsClientTask = 0;
    }
    else
    {
        ConnectionRegisterServiceRecord(
            (Task)&sppsServiceTask,
            sizeof(spp_service_record),
            (const uint8 *)&spp_service_record
            );
    }  
}
/**************************************************************************
 * NAME
 *  mapcRegSdpRecord
 *
 * DESCRIPTION
 *  Register an SDP record for the MNS Service
 **************************************************************************/
void mapcRegSdpRecord( void )
{
    ConnectionRegisterServiceRecord( mapcGetProfileTask(), 
                                     sizeof( serviceRecord ),
                                     serviceRecord );

    mapcSetSdpState( mapc_sdp_reg_progress );
}
Ejemplo n.º 4
0
/****************************************************************************
 Register the service record corresponding to the specified profile
*/
void aghfpRegisterServiceRecord(AGHFP *aghfp, aghfp_profile profile, uint8 chan)
{
	uint16 length;
	uint8 *service_record = 0;


	if (supportedProfileIsHsp(profile))
	{
		/* Create a copy of the service record that we can modify */
		length = sizeof(aghfp_hsp_service_record);
		service_record = (uint8 *)PanicUnlessMalloc(length);
		memcpy(service_record, aghfp_hsp_service_record, length);
	}
	else if (supportedProfileIsHfp(profile))
	{
		/* Create a copy of the service record that we can modify */
		length = sizeof(aghfp_hfp_service_record);
		service_record = (uint8 *)PanicUnlessMalloc(length);
		memcpy(service_record, aghfp_hfp_service_record, length);

		/* Insert the supported features into the service record */
		if (!insertHfpSupportedFeatures(service_record, service_record + length, aghfp->supported_profile))
		{
			/* Failed to insert the supported features into the service record */
			MAKE_AGHFP_MESSAGE(AGHFP_INTERNAL_SDP_REGISTER_CFM);
			message->status = aghfp_fail;
			MessageSend(&aghfp->task, AGHFP_INTERNAL_SDP_REGISTER_CFM, message);

			/* Free the allocated memory */
			free(service_record);
			return;
		}
	}
	else
	{
		/* Unknown profile, send an error */
		MAKE_AGHFP_MESSAGE(AGHFP_INTERNAL_SDP_REGISTER_CFM);
		message->status = aghfp_fail;
		MessageSend(&aghfp->task, AGHFP_INTERNAL_SDP_REGISTER_CFM, message);
		return;
	}

	if (!insertRfcommServerChannel(service_record, service_record + length, chan))
	{
		/* If we fail to insert the rfcomm channel return an error to the app */
		MAKE_AGHFP_MESSAGE(AGHFP_INTERNAL_SDP_REGISTER_CFM);
		message->status = aghfp_fail;
		MessageSend(&aghfp->task, AGHFP_INTERNAL_SDP_REGISTER_CFM, message);

		/* Free the allocated memory */
		free(service_record);
	}
	else
	{
		/* Send the service record to the connection lib to be registered with BlueStack */
		ConnectionRegisterServiceRecord(&aghfp->task, length, service_record);
	}
}
void avrcpRegisterServiceRecord(AVRCP *avrcp)
{
    uint16 size_record = 0;
    const uint8 *service_record = 0;

    if (avrcp->device_type == avrcp_target)
    {
        size_record = sizeof(serviceRecordTarget);
        service_record = serviceRecordTarget;
    }
    else if (avrcp->device_type == avrcp_controller)
    {
        size_record = sizeof(serviceRecordController);
        service_record = serviceRecordController;
    }
    else if (avrcp->device_type == avrcp_target_and_controller)
    {
        /* 
            If we need to register both records try and keep track of which 
            one we need to register next. Register target first. 
        */
        size_record = sizeof(serviceRecordTarget);
        service_record = serviceRecordTarget;
        avrcp->device_type = avrcp_device_none;
    }
    else if (avrcp->device_type == avrcp_device_none)
    {
        /* Time to register the controller service record */
        size_record = sizeof(serviceRecordController);
        service_record = serviceRecordController;
        avrcp->device_type = avrcp_target_and_controller;
    }
    else
    {
        /* Some unknown value has been passed in so fail the init. */
        avrcpSendInternalInitCfm(&avrcp->task, avrcp_fail);
        return;
    }

    /* Register the service record */
    ConnectionRegisterServiceRecord(&avrcp->task, size_record, service_record);
}
Ejemplo n.º 6
0
/****************************************************************************
NAME    
    hfpRegisterServiceRecord

DESCRIPTION
    Register the service record corresponding to the specified service

RETURNS
    void
*/
void hfpRegisterServiceRecord(hfp_service_data* service)
{
    /* Ignore this silently if service is already registered */
    if(service->sdp_record_handle == 0 && !hfpGetVisibleServiceFromProfile(service->profile))
    {
        if(!theHfp->busy_channel)
        {
            const uint8* service_record      = NULL;
            uint16       size_service_record = 0;
            
            theHfp->busy_channel  = service->rfc_server_channel;
            
            /* Create a copy of the service record that we can modify */
            if (supportedProfileIsHsp(service->profile))
            {
                size_service_record = sizeof(hsp_service_record);
                
                /* If RFC channel matches use a constant record */
                if(service->rfc_server_channel == HSP_DEFAULT_CHANNEL)
                    service_record = hsp_service_record;
                else if(service->rfc_server_channel == HSP_DEFAULT_CHANNEL_2)
                    service_record = hsp_service_record_2;
                else
                    service_record = hfpSdpHspRecordCreate(service->rfc_server_channel);
            }
            else if (supportedProfileIsHfp(service->profile))
            {
                uint16 features = BRSF_BITMAP_TO_SDP_BITMAP(theHfp->hf_supported_features);
                uint16 version = supportedProfileIsHfp106(service->profile) ? HFP_1_6_VERSION_NUMBER : HFP_1_5_VERSION_NUMBER;
                
                size_service_record = sizeof(hfp_service_record);
                
                /* If features, version and RFC channel match use a constant record */
                if(features == HFP_DEFAULT_FEATURES && version == HFP_DEFAULT_VERSION)
                {
                    if(service->rfc_server_channel == HFP_DEFAULT_CHANNEL)
                        service_record = hfp_service_record;
                    else if(service->rfc_server_channel == HFP_DEFAULT_CHANNEL_2)
                        service_record = hfp_service_record_2;
                }
                
                /* Something didn't match, use a dynamic record */
                if(!service_record)
                    service_record = hfpSdpRecordCreate(service->rfc_server_channel, version, features);
            }
            else
            {
                /* If this is going to fail it will be during init, send init fail */
                hfpInitSdpRegisterComplete(hfp_fail);
                return;
            }
            
            /* Send the service record to the connection lib to be registered with BlueStack */
            ConnectionRegisterServiceRecord(&theHfp->task, size_service_record, service_record);
        }
        else
        {
            /* Queue registering this service */
            MAKE_HFP_MESSAGE(HFP_INTERNAL_SDP_REGISTER_REQ);
            message->service = service;
            MessageSendConditionally(&theHfp->task, HFP_INTERNAL_SDP_REGISTER_REQ, message, (uint16*)&theHfp->busy_channel);
        }
    }
    else if(!theHfp->initialised && service == HFP_SERVICE_TOP)
    {
        /* Make sure we complete init if we're not registering the top service */
        theHfp->busy_channel = service->rfc_server_channel;
        hfpInitSdpRegisterComplete(hfp_success);
    }
}
Ejemplo n.º 7
0
void A2dpInit(Task clientTask, uint16 role, service_record_type *service_records, uint16 size_seps, sep_data_type *seps, uint16 linkloss_timeout)
{
    /* Initialise the task data */
    if ( !a2dp )
    {
        uint8 device_id;
        
        a2dp = PanicUnlessNew(A2DP);
        memset( a2dp, 0, sizeof(A2DP) );
        for (device_id=0; device_id<A2DP_MAX_REMOTE_DEVICES_DEFAULT; device_id++)
        {
            a2dpInitialiseRemoteDevice(&a2dp->remote_conn[device_id],device_id);
        }
        
        PRINT(("sizeof(A2DP)=0x%u\n", sizeof(A2DP)));
        
        /* Set the handler function */
        a2dp->task.handler = a2dpProfileHandler;
        /* Set up the lib client */
        a2dp->clientTask = clientTask;
        a2dp->linkloss_timeout = linkloss_timeout;
        a2dp->max_remote_devs = A2DP_MAX_REMOTE_DEVICES_DEFAULT;
        a2dp->profile_role = role;
        
        blockInit();
        
        if ( seps && size_seps && validateSeps(seps, size_seps) )
        {
            for (device_id=0; device_id<A2DP_MAX_REMOTE_DEVICES; device_id++)
            {
                sep_data_type *sep_list = (sep_data_type *)PanicNull( blockAdd( device_id, data_block_sep_list, size_seps, sizeof(sep_data_type) ) );
                memmove( sep_list, (sep_data_type *)seps, size_seps*sizeof(sep_data_type) );
            }
        }
        else
        {
            a2dpSendInitCfmToClient(a2dp_invalid_parameters);
            return;
        }
    
    
        /* Used to count the number of SDP records registered.  Decremented again by a2dpHandleSdpRegisterCfm() and will 
           kick off a call to a2dpRegisterL2cap() when it hits zero - i.e. all CFM messages for SDP regsitering process
           have been received.                                                                                           */
        a2dp->sdp_register_outstanding = 0;
        
        if (service_records)
        {
            if (service_records->size_service_record_a && service_records->service_record_a)
            {
                /* Client has supplied their own record so register it without checking */
                ConnectionRegisterServiceRecord(&a2dp->task, service_records->size_service_record_a, service_records->service_record_a);
                a2dp->sdp_register_outstanding++;
            }
            if (service_records->size_service_record_b && service_records->service_record_b)
            {
                /* Client has supplied their own record so register it without checking */
                ConnectionRegisterServiceRecord(&a2dp->task, service_records->size_service_record_b, service_records->service_record_b);
                a2dp->sdp_register_outstanding++;
            }
        }
        else
        {
            /* Client using default library record */
            if (role & A2DP_INIT_ROLE_SINK)
            {
                ConnectionRegisterServiceRecord(&a2dp->task, sizeof(a2dp_sink_service_record), a2dp_sink_service_record);
                PRINT(("Register Sink Service Rec\n"));
                a2dp->sdp_register_outstanding++;
            }
            if (role & A2DP_INIT_ROLE_SOURCE)
            {
                ConnectionRegisterServiceRecord(&a2dp->task, sizeof(a2dp_source_service_record), a2dp_source_service_record);
                PRINT(("Register Source Service Rec\n"));
                a2dp->sdp_register_outstanding++;
            }
        }
    
        if ( a2dp->sdp_register_outstanding==0 )
        {
            /* Skip the service record registering if the user doesn't require any at this point. */
            a2dpRegisterL2cap();
        }
    }
}
static void sppsConnectionHandler(Task task, MessageId id, Message message)
{
   	SPP* spp = (SPP*) task;

    switch(spp->c.state)
    {
    case sppConnecting:
        switch(id)
        {
        case CL_RFCOMM_SERVER_CONNECT_CFM:
            sppsHandleRfcommServerConnectCfm(
                spp,
                (CL_RFCOMM_SERVER_CONNECT_CFM_T *)message
                );
            break;
        
        case CL_RFCOMM_CONTROL_IND:
            sppForwardRfcommControlInd(spp, (CL_RFCOMM_CONTROL_IND_T*)message);
            break;

        case CL_RFCOMM_PORTNEG_IND:
            sppHandleRfcommPortnegInd(spp, (CL_RFCOMM_PORTNEG_IND_T*)message);
            break;
            
        default:
            sppHandleUnexpectedMsg(spp->c.state, id);
            break;
        }
        break;

    case sppConnected:
        switch(id)
        {
        case CL_SDP_UNREGISTER_CFM: 
                sppsHandleSdpUnregisterCfm(
                    spp, 
                    (CL_SDP_UNREGISTER_CFM_T *)message
                    );
                break;
            
        case CL_RFCOMM_DISCONNECT_IND:
            sppHandleRfcommDisconnectInd(
                spp,
                (CL_RFCOMM_DISCONNECT_IND_T *)message
                );
            break;
            
        case CL_RFCOMM_CONTROL_IND:
            sppForwardRfcommControlInd(spp, (CL_RFCOMM_CONTROL_IND_T*)message);
            break;
        
        case CL_SM_ENCRYPTION_CHANGE_IND:
            sppForwardSmEncryptionChangeInd(
                spp,
                (CL_SM_ENCRYPTION_CHANGE_IND_T *)message
                );
            break;

        case CL_RFCOMM_PORTNEG_IND:
            sppHandleRfcommPortnegInd(spp, (CL_RFCOMM_PORTNEG_IND_T*)message);
            break;

        case MESSAGE_MORE_DATA:
            sppForwardMessageMoreData(spp, (MessageMoreData *)message);
            break;
            
        case MESSAGE_MORE_SPACE:
            sppForwardMessageMoreSpace(spp, (MessageMoreSpace *)message);
            break;


        /* Ignored messages */
        case MESSAGE_STREAM_DISCONNECT:
        case MESSAGE_SOURCE_EMPTY:
            break;

        default:
            sppHandleUnexpectedMsg(spp->c.state, id);
            break;
        }
        break;

    case sppDisconnecting:
        switch(id)
        {
        case CL_RFCOMM_DISCONNECT_CFM:
            sppHandleRfcommDisconnectCfm(
                spp, 
                (CL_RFCOMM_DISCONNECT_CFM_T *)message
                );
            break;

        case SPP_INTERNAL_DISCONNECT_REQ:
            /* If the Service record is unregistered */
            if (!sppGetServiceHandle())
                /* Restore the SPP service record again. */
                ConnectionRegisterServiceRecord(
                    &spp->c.task,
                    SSP_SERVICE_RECORD_SIZE,
                    (const uint8 *)&spp_service_record
                );
            else
                /* Otherwise go straight to deleting the task. */
                MessageSend(&spp->c.task, SPP_INTERNAL_TASK_DELETE_REQ, 0);
        
            break;

       case CL_SDP_REGISTER_CFM: 
            sppsHandleSdpRegisterCfm(spp,(CL_SDP_REGISTER_CFM_T *)message);
            break;
            
        case SPP_INTERNAL_TASK_DELETE_REQ:
            sppDeleteTask(spp);
            break;    

        /* Ignored messages */
        case MESSAGE_STREAM_DISCONNECT:
        case MESSAGE_SOURCE_EMPTY:
            break;

        default:
            sppHandleUnexpectedMsg(spp->c.state, id);
            break;
        }
        break;

    default:
        SPP_DEBUG(("Unexpected SPP Server state %d\n", spp->c.state));
        break;
    }
}
Ejemplo n.º 9
0
/****************************************************************************
NAME	
	hfpRegisterServiceRecord

DESCRIPTION
	Register the service record corresponding to the specified profile 

RETURNS
	void
*/
void hfpRegisterServiceRecord(HFP *hfp)
{
	uint8 *service_record = 0;
    hfp_profile profile = hfp->hfpSupportedProfile;
    uint8 chan = hfp->local_rfc_server_channel;

	if (!hfp->service_record)
	{
		if (supportedProfileIsHsp(profile))
        {
            hfp->size_service_record = sizeof(hsp_service_record);
			hfp->service_record = (uint8 *) hsp_service_record;
        }
		else if (supportedProfileIsHfp(profile))
        {
            hfp->size_service_record = sizeof(hfp_service_record);
			hfp->service_record = (uint8 *) hfp_service_record;
        }
		else
		{
			/* Unknown profile, send an error */
            sendInternalSdpRegisterCfmMessage(hfp, hfp_fail);
			return;
		}
	}

	/* Create a copy of the service record that we can modify */
	service_record = (uint8 *)PanicUnlessMalloc(hfp->size_service_record);
	memmove(service_record, hfp->service_record, hfp->size_service_record);
	
	if (supportedProfileIsHfp(profile))
	{
		/* Insert the supported features into the service record. */
		if (!insertHfpSupportedFeatures(service_record, service_record + hfp->size_service_record, hfp->hfpSupportedFeatures))
		{
			/* Failed to insert the supported features into the service record */
            sendInternalSdpRegisterCfmMessage(hfp, hfp_fail);

			/* Free the allocated memory */
			free(service_record);
			return;
		}

        /* Insert the profile version number */
        if (!insertHfpProfileVersion(service_record, service_record + hfp->size_service_record, profile))
        {
            /* SDP register failed */
            sendInternalSdpRegisterCfmMessage(hfp, hfp_fail);

			/* Free the allocated memory */
			free(service_record);
			return;
        }
	}
	
	if (!insertRfcommServerChannel(service_record, service_record + hfp->size_service_record, chan))
	{
		/* If we fail to insert the rfcomm channel return an error to the app */		
        sendInternalSdpRegisterCfmMessage(hfp, hfp_fail);
		
		/* Free the allocated memory */
		free(service_record);
	}
	else
	{
		/* Send the service record to the connection lib to be registered with BlueStack */
		ConnectionRegisterServiceRecord(&hfp->task, hfp->size_service_record, service_record);
	}
}