Esempio n. 1
0
/****************************************************************************
 Outcome of the RFCOMM connect request or response.
*/
static void aghfpHandleRfcommConnectCfm(AGHFP *aghfp, rfcomm_connect_status status)
{
    /* Check the status of the rfcomm connect cfm */
    if (status == rfcomm_connect_success)
    {
        /* RFCOMM connection is up! Check which profile is supported by this task */
        if (supportedProfileIsHsp(aghfp->supported_profile))
        {
            /* HSP supported - SLC is up so tell the app */
   			aghfpSendSlcConnectCfmToApp(aghfp_connect_success, aghfp);
        }
        else if (supportedProfileIsHfp(aghfp->supported_profile))
        {
            /* HFP supported - RFCOMM is up, so just wait for HF to send us some AT commends */
        }
        else
        {
            /* This should never happen */
            AGHFP_DEBUG_PANIC(("Unhandled profile type 0x%x\n", aghfp->supported_profile));
        }

  		/* Check for data in the buffer */
  		aghfpHandleReceivedData(aghfp, StreamSourceFromSink(aghfp->rfcomm_sink));
    }
    else
    {
        /* RFCOMM connect failed - Tell the app. */
        aghfpSendSlcConnectCfmToApp(convertRfcommConnectStatus(status), aghfp);
    }
	
	aghfp->rfcomm_lock = FALSE;
}
/****************************************************************************
 All messages for this profile lib are handled by this function
*/
void aghfpProfileHandler(Task task, MessageId id, Message message)
{
	AGHFP *aghfp = (AGHFP*)task;
	aghfp_state profileState = aghfp->state;

    /*printf("%s - ", stateNames[profileState]);*/
	if (id >= AGHFP_INTERNAL_MSG_BASE && id < AGHFP_INTERNAL_MSG_TOP)
	{
		handleAghfpMessages(task, id, message);
	}
	else
	{
		/* Check the message id */
		switch (id)
		{
	       case CL_DM_SYNC_RENEGOTIATE_IND:
				PRINT(("CL_DM_SYNC_RENEGOTIATE_IND \n" ));
	       break ;
    
			/*************************************************************************/
			/* SDP Messages                                                          */
			/*************************************************************************/
	
			case CL_SDP_REGISTER_CFM:
				PRINT(("CL_SDP_REGISTER_CFM\n"));
	
				switch(profileState)
				{
					case aghfp_initialising:
					case aghfp_ready:
					case aghfp_slc_connecting:
						/* Handle the register cfm */
						aghfpHandleSdpRegisterCfm(aghfp, (CL_SDP_REGISTER_CFM_T *) message);
						break;
	
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
	        case CL_SDP_UNREGISTER_CFM:
	            switch(profileState)
				{
					case aghfp_initialising:
					case aghfp_ready:
					case aghfp_slc_connecting:
	                case aghfp_slc_connected:
	                case aghfp_incoming_call_establish:
	                case aghfp_outgoing_call_establish:
	                case aghfp_active_call:
						/* Handle the register cfm */
						aghfpHandleSdpUnregisterCfm(aghfp, (CL_SDP_UNREGISTER_CFM_T *) message);
						break;
	
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
			case CL_SDP_SERVICE_SEARCH_ATTRIBUTE_CFM:
				PRINT(("CL_SDP_SERVICE_SEARCH_ATTRIBUTE_CFM\n"));
	
				switch(profileState)
				{
					case aghfp_slc_connecting:
						/* Currently we only look for attributes during SLC establishment */
						aghfpHandleServiceSearchAttributeCfm(aghfp, (CL_SDP_SERVICE_SEARCH_ATTRIBUTE_CFM_T *) message);
						break;
	                case aghfp_slc_connected:
	                case aghfp_incoming_call_establish:
	                case aghfp_outgoing_call_establish:
	                case aghfp_active_call:
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
	
			/*************************************************************************/
			/* RFCOMM Messages                                                       */
			/*************************************************************************/
	
			case CL_RFCOMM_REGISTER_CFM:
				PRINT(("CL_RFCOMM_REGISTER_CFM\n"));
	
				switch(profileState)
				{
					case aghfp_initialising:
						aghfpHandleRfcommRegisterCfm(aghfp, (CL_RFCOMM_REGISTER_CFM_T *) message);
						break;
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
			case CL_RFCOMM_CONNECT_IND:
				PRINT(("CL_RFCOMM_CONNECT_IND\n"));
	
				switch(profileState)
				{
					case aghfp_ready:
						/* Handle the connect indication */
						aghfpHandleRfcommConnectInd(aghfp, (CL_RFCOMM_CONNECT_IND_T *) message);
						break;
	
					case aghfp_slc_connecting:
					case aghfp_slc_connected:
					case aghfp_incoming_call_establish:
					case aghfp_outgoing_call_establish:
						/*  Reject the connect request - this shouldn't happen too often as we
						unregister our service record after we establish an SLC */
						aghfpHandleSlcConnectIndReject(aghfp, (CL_RFCOMM_CONNECT_IND_T *) message);
						break;
	
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
			case CL_RFCOMM_CONNECT_CFM:
				PRINT(("CL_RFCOMM_CONNECT_CFM\n"));
	
				switch(profileState)
				{
					case aghfp_slc_connecting:
						/* Handle the connect cfm */
						aghfpHandleRfcommConnectCfm(aghfp, (CL_RFCOMM_CONNECT_CFM_T *) message);
						break;
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
			case CL_RFCOMM_DISCONNECT_IND:
				PRINT(("CL_RFCOMM_DISCONNECT_IND\n"));
	
				switch(profileState)
				{
					case aghfp_ready:
					case aghfp_slc_connecting:
					case aghfp_slc_connected:
					case aghfp_incoming_call_establish:
					case aghfp_outgoing_call_establish:
	                case aghfp_active_call:
						aghfpHandleRfcommDisconnectInd(aghfp, (CL_RFCOMM_DISCONNECT_IND_T*) message);
						break;
	
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
			/*************************************************************************/
			/* Audio Connection Messages                                             */
			/*************************************************************************/
	
			case CL_DM_SYNC_CONNECT_IND:
				PRINT(("CL_DM_SYNC_CONNECT_IND\n"));
	
				switch(profileState)
				{
					case aghfp_slc_connected:
					case aghfp_incoming_call_establish:
					case aghfp_outgoing_call_establish:
					case aghfp_active_call:
						aghfpHandleSyncConnectInd(aghfp, (CL_DM_SYNC_CONNECT_IND_T *)message);
						break;
					default:
						/* Reject request outright because we are in the wrong state */
						aghfpHandleSyncConnectIndReject(aghfp, (CL_DM_SYNC_CONNECT_IND_T *)message);
						break;
				}
				break;
	
			case CL_DM_SYNC_CONNECT_CFM:
				PRINT(("CL_DM_SYNC_CONNECT_CFM\n"));
	
				switch(profileState)
				{
					case aghfp_slc_connected:
					case aghfp_incoming_call_establish:
					case aghfp_outgoing_call_establish:
					case aghfp_active_call:
						aghfpHandleSyncConnectCfm(aghfp, (CL_DM_SYNC_CONNECT_CFM_T *)message);
						break;
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
			case CL_DM_SYNC_DISCONNECT_IND:
				PRINT(("CL_DM_SYNC_DISCONNECT_IND\n"));
	
				switch(profileState)
				{
					case aghfp_slc_connected:
					case aghfp_incoming_call_establish:
					case aghfp_outgoing_call_establish:
					case aghfp_active_call:
						aghfpHandleSyncDisconnectInd(aghfp, (CL_DM_SYNC_DISCONNECT_IND_T *)message);
						break;
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
				
				
			/*************************************************************************/
			/* Misc Other Messages                                                   */
			/*************************************************************************/
	
			case MESSAGE_MORE_DATA:
				PRINT(("MESSAGE_MORE_DATA\n"));
	
				switch(profileState)
				{
					case aghfp_slc_connecting:
					case aghfp_slc_connected:
					case aghfp_incoming_call_establish:
					case aghfp_outgoing_call_establish:
					case aghfp_active_call:
						/* We have received more data into the RFCOMM buffer */
						aghfpHandleReceivedData(aghfp, ((MessageMoreData *) message)->source);
						break;
	
					default:
						/* Panic in debug and ignore in release lib variants */
						handleUnexpected(aghfpUnexpectedClPrim, profileState, id);
						break;
				}
				break;
	
	        case CL_DM_SYNC_REGISTER_CFM:
	            PRINT(("CL_DM_SYNC_REGISTER_CFM\n"));
	
				switch(profileState)
				{
	            case aghfp_initialising:
	            case aghfp_ready:
	            case aghfp_slc_connecting:
	            case aghfp_slc_connected:
	            case aghfp_incoming_call_establish:
	            case aghfp_outgoing_call_establish:
	            case aghfp_active_call:
	                /* Registered for Synchronous connection indications */
	    			aghfpHandleSyncRegisterCfm(aghfp);
	                break;
	
	            default:
	                break;
	            }
	            break;
	
	
	        /* Unhandled messages */
            case CL_SM_ENCRYPTION_CHANGE_IND:
			case CL_SM_ENCRYPTION_KEY_REFRESH_IND:
	        case MESSAGE_MORE_SPACE:
	        case MESSAGE_SOURCE_EMPTY:
	            break;
	
	
			default:
				PRINT(("Unhandled message\n"));
				/* Received an unhandled message */
				handleUnexpected(aghfpUnexpectedMessage, profileState, id);
				break;
		}
	}
}