예제 #1
0
파일: sink_scan.c 프로젝트: jrryu/HW--FW
/****************************************************************************
NAME    
    sinkEnableMultipointConnectable
    
DESCRIPTION
    when in multi point mode check to see if device can be made connectable,
    this will be when only one AG is currently connected. this function will
    be called upon certain button presses which will reset the 60 second timer
    and allow a second AG to connect should the device have become non discoverable
    
RETURNS
    none
*/
void sinkEnableMultipointConnectable( void )
{    
    /* only applicable to multipoint devices and don't go connectable when taking or making
       an active call, allow connectable in streaming music state */
    if((theSink.MultipointEnable)&&(stateManagerGetState() != deviceLimbo))
    {
       /* if only one hfp instance is connected then set connectable to active */
       if(deviceManagerNumConnectedDevs() < 2)
       {
            MAIN_DEBUG(("MP Go Conn \n" ));
            
            /* make device connectable */
            sinkEnableConnectable();
         
            /* cancel any currently running timers that would disable connectable mode */
            MessageCancelAll( &theSink.task, EventSysConnectableTimeout );
            
            /* remain connectable for a further 'x' seconds to allow a second 
               AG to be connected if non-zero, otherwise stay connecatable forever */
            if(theSink.conf1->timeouts.ConnectableTimeout_s)
            {
                MessageSendLater(&theSink.task, EventSysConnectableTimeout, 0, D_SEC(theSink.conf1->timeouts.ConnectableTimeout_s));
            }
       }
       /* otherwise do nothing */
    }
}
예제 #2
0
/***************************************************************************
NAME
    UpgradeSMInit  -  Initialise the State Machine

DESCRIPTION
    This function performs relevant initialisation of the state machine,
    currently just setting the initial state.

    This is currently determined by checking whether an upgraded
    application is running.

*/
void UpgradeSMInit()
{
    switch(UpgradeCtxGetPSKeys()->upgrade_in_progress_key)
    {
    /* UPGRADE_RESUME_POINT_PRE_VALIDATE:
        @todo: What do we do in this case ? */
    /* UPGRADE_RESUME_POINT_POST_REBOOT:
       UPGRADE_RESUME_POINT_COMMIT:
        @todo: Are these right, we want host to chat */
    default:
        SetState(UPGRADE_STATE_CHECK_STATUS);
        break;

    /*case UPGRADE_RESUME_POINT_PRE_REBOOT:
        SetState(UPGRADE_STATE_VALIDATED);
        break;*/

    case UPGRADE_RESUME_POINT_POST_REBOOT:
        SetState(UPGRADE_STATE_COMMIT_HOST_CONTINUE);
        MessageSendLater(UpgradeGetUpgradeTask(), UPGRADE_INTERNAL_RECONNECTION_TIMEOUT, NULL,
                D_SEC(UPGRADE_WAIT_FOR_RECONNECTION_TIME_SEC));
        break;

    /*case UPGRADE_RESUME_POINT_ERASE:
        MoveToState(UPGRADE_STATE_COMMIT);
        break;*/

    case UPGRADE_RESUME_POINT_ERROR:
        SetState(UPGRADE_STATE_ABORTING);
        break;
    }
}
예제 #3
0
/****************************************************************************
NAME 
	hidDisconnectingRemoteEnter
DESCRIPTION
	Called whenever the HID instance enters the remote disconnecting state.
	Starts the disconnect timer.
RETURNS
	void
*/
static void hidDisconnectingRemoteEnter(HID *hid)
{
	HID_PRINT(("hidDisconnectingRemoteEnter\n"));

    /* Start disconnect timer */
    MessageSendLater(&hid->task, HID_INTERNAL_DISCONNECT_TIMEOUT_IND, 0, D_SEC(HID_DISCONNECT_TIMEOUT));
}
void hfpHandlerRingInd ( void )
{
	/* Disconnect A2DP audio if it is streaming from a standalone A2DP source */
	if (!IsA2dpSourceAnAg())
		streamControlCeaseA2dpStreaming(TRUE);
	
    if ( !theHeadset.InBandRingEnabled )
    {
    	HFP_DEBUG(("HFP_DEBUG: OutBandRing\n")) ;
		
        /* Play ring tone from configuration */
    }    
	
	if ( (theHeadset.profile_connected == hfp_headset_profile) && !theHeadset.HSPCallAnswered )
    {
		/* If using HSP then use ring indication as incoming call */
		theHeadset.HSPIncomingCallInd = TRUE;
       
        stateManagerEnterIncomingCallEstablishState() ;
       
        MessageCancelAll ( &theHeadset.task , APP_CANCEL_HSP_INCOMING_CALL ) ;
        MessageSendLater ( &theHeadset.task , APP_CANCEL_HSP_INCOMING_CALL , 0 , D_SEC(6) ) ;
    }
    
}
예제 #5
0
파일: sink_usb.c 프로젝트: NemProjects/BC
/****************************************************************************
NAME 
    usbSetLowPowerMode
    
DESCRIPTION
    If delay is non zero queue a message to reset into low powered mode. If
    delay is zero do nothing.
    
RETURNS
    void
*/ 
static void usbSetLowPowerMode(uint8 delay)
{
    /* Only queue low power mode if not enumerated and attached to normal host/hub */
    if(!theSink.usb.enumerated && delay && (UsbAttachedStatus() == HOST_OR_HUB)) 
    {
        USB_DEBUG(("USB: Queue low power in %d sec\n", delay));
        MessageSendLater(&theSink.task, EventUsbLowPowerMode, 0, D_SEC(delay));
    }
}
예제 #6
0
/****************************************************************************
NAME    
    audio_start_active_timer - Starts the audio active timer in USB mode if the USB audio interfaces are inactive

*/
void audio_start_active_timer(void)
{
    MessageCancelFirst(&theSource->app_data.appTask, APP_USB_AUDIO_ACTIVE);
    MessageCancelFirst(&theSource->app_data.appTask, APP_USB_AUDIO_INACTIVE);
    
#ifndef ANALOGUE_INPUT_DEVICE    
    /* Audio active timer only applies to a USB device as an Analogue input device cannot be notified when audio is present */
    if ((theSource->ps_config->ps_timers.usb_audio_active_timer != TIMER_NO_TIMEOUT) &&
        (!theSource->audio_data.audio_usb_active))
    {
        /* send the audio inactive message after the PS configured delay */
        MessageSendLater(&theSource->app_data.appTask, APP_USB_AUDIO_INACTIVE, 0, D_SEC(theSource->ps_config->ps_timers.usb_audio_active_timer));        
    }
#endif    
}
예제 #7
0
/****************************************************************************
NAME 
 VolumeMuteOn

DESCRIPTION
 Enables Mute

RETURNS
 void
    
*/
void VolumeMuteOn ( void )
{
    VOL_DEBUG(("VOL: Mute\n")) ;        
    
	/* If headset wants to mute on or receive +VGM = 0 command from one AG, 
	   Send command to both AGs and mute itself 
	*/
	if(theHeadset.features.EnableSyncMuteMicophones)
	{
		VOL_DEBUG(("VOL: Send AT+VGM = 0 to AG1 if AG1 does not require to mute Mic\n")) ;
		if( !theHeadset.profile_data[PROFILE_INDEX(hfp_primary_link)].audio.gAgSyncMuteFlag )
			HfpVolumeSyncMicrophoneGainRequest(hfp_primary_link, 0);
		else
			theHeadset.profile_data[PROFILE_INDEX(hfp_primary_link)].audio.gAgSyncMuteFlag = 0;
			
		/* if AG2 is connected, send a message to AG2 */
   		if((theHeadset.conf->no_of_profiles_connected > 1))
   		{
			VOL_DEBUG(("VOL: Send AT+VGM = 0 to AG2 if AG2 does not require to mute Mic\n")) ;
			if( !theHeadset.profile_data[PROFILE_INDEX(hfp_secondary_link)].audio.gAgSyncMuteFlag )
				HfpVolumeSyncMicrophoneGainRequest(hfp_secondary_link, 0);
			else
				theHeadset.profile_data[PROFILE_INDEX(hfp_secondary_link)].audio.gAgSyncMuteFlag = 0;
		}     
	}

    if (theHeadset.features.MuteSpeakerAndMic)
        AudioSetMode ( AUDIO_MODE_MUTE_BOTH , NULL ) ;
    else
        AudioSetMode ( AUDIO_MODE_MUTE_MIC , NULL) ;

    PioSetMicrophoneBias ( FALSE ) ; 
 
    /*update the mutestate*/    
    theHeadset.gMuted = TRUE ;
	
	if(theHeadset.conf->timeouts.MuteRemindTime_s !=0)
    	MessageSendLater( &theHeadset.task , EventMuteReminder , 0 ,D_SEC(theHeadset.conf->timeouts.MuteRemindTime_s ) ) ;
}
예제 #8
0
파일: sink_audio.c 프로젝트: jrryu/HW--FW
/****************************************************************************
NAME
    ChangeHearingProfile
DESCRIPTION
    changes Hearing profiles. This function is called by user events to help the user change the current Hearing profile
	while DSP is running. When user event occures, this function sends a MESSAGE_HEARING_CHANGE_PARAMS to the plugin but only if the Audio is free.
	If Audio is busy the functin will just cancell all the pending MESSAGE_HEARING_CHANGE_PARAMS.

RETURNS
    void
*/
void ChangeHearingProfile(profile_direction dir)
{
    TaskData *plugin = NULL;

#ifdef HEP_1MIC
    plugin = (TaskData *)&alango_1mic_hearing_plugin;
#elif defined(HEP_2MIC)
    plugin = (TaskData *)&alango_2mic_hearing_plugin;
#endif
    if (theSink.HearPhones_conf->Hearing.ActiveHearing)
    {
        if ( dir == next_profile )
            theSink.HearPhones_conf->Hearing.profile = (theSink.HearPhones_conf->Hearing.profile == theSink.HearPhones_conf->Hearing.Num_Of_Profiles-1) ? 0 : theSink.HearPhones_conf->Hearing.profile + 1;
        else
            theSink.HearPhones_conf->Hearing.profile = (theSink.HearPhones_conf->Hearing.profile == 0) ? theSink.HearPhones_conf->Hearing.Num_Of_Profiles-1 : theSink.HearPhones_conf->Hearing.profile - 1;
        MessageCancelAll ( plugin, MESSAGE_HEARING_CHANGE_PARAMS);
        /* AlangoPluginChangeParamsHearing() uses SetAudioBusy() and only after receiving from Kalimba HEP_PARAMS_LOADED_MSG VM will will set SetAudioBusy() to false.
        	if kalimba stops repond with HEP_PARAMS_LOADED_MSG for any reason VM will NOT ask Kalimba to MESSAGE_HEARING_CHANGE_PARAMS again as long Audio is busy*/
        if ( IsAudioBusy() == FALSE )
            MessageSendLater ( plugin, MESSAGE_HEARING_CHANGE_PARAMS , NULL , D_SEC(0.15) );/* The message is sent with 150ms delay in order to prevent the user hiting
																								the profile change button to fast. any push fastr than 150ms will be cancelled
																								by MessageCancelAll() above and reschedualed to 150ms later*/
    }
}
예제 #9
0
/****************************************************************************
NAME	
	connectionHandleSdpServiceSearchCfm

DESCRIPTION
	SDP service search results received so handle them here.

RETURNS
	void	
*/
void connectionHandleSdpServiceSearchCfm(connectionSdpState *state, const SDC_EX_SERVICE_SEARCH_CFM_T *cfm)
{
	if (state->sdpSearchLock == connectionGetCmTask())
	{
		/* Internal CFM means we're SDP Pinging */
		uint8* sdp_ptr = (uint8 *) SdpPingServiceRequest;
		
		/* Create next request */
		MAKE_CL_MESSAGE(CL_INTERNAL_SDP_SERVICE_SEARCH_REQ);
	
		message->theAppTask = connectionGetCmTask();
		message->bd_addr = state->sdpServerAddr;
		message->max_responses = 1;
		message->length = sizeof(SdpPingServiceRequest);				 
		message->search_pattern = (uint8*) PanicUnlessMalloc(sizeof(SdpPingServiceRequest));
		memcpy(message->search_pattern, sdp_ptr, sizeof(SdpPingServiceRequest));
		
		/* Send after 2 seconds to avoid thrashing the radio */
		MessageSendLater(connectionGetCmTask(), CL_INTERNAL_SDP_SERVICE_SEARCH_REQ, message, D_SEC(2));
		
		/* Tidy up memory in cfm */
		if (cfm->size_rec_list)
        {
            uint8 *record_list = VmGetPointerFromHandle(cfm->rec_list);
            free(record_list);
        }
        
		/* Free the lock so the next request can be handled */
		state->sdpSearchLock = 0;
	}
    else if (state->sdpSearchLock)
    {
        /* Send a cfm to the client task */
        MAKE_CL_MESSAGE_WITH_LEN(CL_SDP_SERVICE_SEARCH_CFM, cfm->size_rec_list);
        message->status = connectionConvertSdpSearchStatus(cfm->response);
        message->num_records = cfm->num_recs_ret;
        message->error_code = cfm->err_code;
        connectionConvertBdaddr(&message->bd_addr, &cfm->bd_addr);
        message->size_records = cfm->size_rec_list;
        
        if (cfm->size_rec_list)
        {
            uint8 *record_list = VmGetPointerFromHandle(cfm->rec_list);
            memcpy(message->records, record_list, cfm->size_rec_list);
            free(record_list);
        }
        else
            message->records[0] = 0;
        
        MessageSend(state->sdpSearchLock, CL_SDP_SERVICE_SEARCH_CFM, message);
        
        /* Reset the resource lock */
        state->sdpSearchLock = 0;
    }
    else
    {
        if (cfm->size_rec_list)
        {
            uint8 *record_list = VmGetPointerFromHandle(cfm->rec_list);
            free(record_list);
        }
    }
}
/****************************************************************************
NAME
    sysHandleButtonsMessage

DESCRIPTION
    Handle messages received from button code.

*/
bool sysHandleButtonsMessage(MessageId id, Message message)
{
    switch(id)
    {
    case BUTTON_DEVICE_CONNECT_REQ:
    {
        DEBUG(("BUTTON_DEVICE_CONNECT_REQ\n"));
        if (the_app->dfu_requested)
        {
            the_app->dfu_requested = FALSE;
            testCancelDfuModeRequest();
        }
        else
        {
            /* If it is clearing pdl, no connection attempts are allowed */
            if (!the_app->clearing_pdl && the_app->audioAdaptorPoweredOn)
            {
                MAKE_APP_MESSAGE(APP_DEVICE_CONNECT_REQ);
                message->disconnect_current = TRUE;
#ifdef DUAL_STREAM
                MessageSendLater(&the_app->task, APP_DEVICE_CONNECT_REQ, message, 800);
#else /* DUAL_STREAM not defined */
                MessageSend(&the_app->task, APP_DEVICE_CONNECT_REQ, message);
#endif /* DUAL_STREAM */
                the_app->PowerOffIsEnabled  = TRUE;
            }
        }
        break;
    }
    case BUTTON_DEVICE_DISCOVER_REQ:
    {
        DEBUG(("BUTTON_DEVICE_DISCOVER_REQ\n"));
        if (the_app->dfu_requested)
        {
            the_app->dfu_requested = FALSE;
            testCancelDfuModeRequest();
        }
        else
        {
            /* If it is clearing pdl, no discovering attempts are allowed */
            if (!the_app->clearing_pdl && the_app->audioAdaptorPoweredOn)
            {
                MAKE_APP_MESSAGE(APP_DEVICE_DISCOVER_REQ);
                message->disconnect_current = TRUE;
                MessageSend(&the_app->task, APP_DEVICE_DISCOVER_REQ, message);
                the_app->PowerOffIsEnabled  = TRUE;
            }
        }
        break;
    }
    case BUTTONS_CLEAR_PDL_REQ:
    {
        DEBUG(("BUTTONS_CLEAR_PDL_REQ\n"));
        if (the_app->dfu_requested)
        {
            the_app->dfu_requested = FALSE;
            testCancelDfuModeRequest();
        }
        else
        {
            /* don't send clearing pdl request again, if it is still clearing it */
            if (!the_app->clearing_pdl)
            {
                the_app->clearing_pdl = TRUE;

                /* Disconnecting all connections */
                kickCommAction(CommActionDisconnect);

                /* Now just waiting for switch off */
                /* Set a timeout so that we will turn off eventually anyway */
                MessageSendLater ( &the_app->task , APP_RESET_PDL_REQ, 0 , D_SEC(3) ) ;
            }
        }
        break;
    }
    case BUTTON_PWR_OFF_REQ:
    {
        DEBUG(("BUTTON_PWR_OFF_REQ\n"));
        if (the_app->a2dp_source == SourceAnalog)
        {
            if (the_app->audioAdaptorPoweredOn)
            {
                MessageSend(&the_app->task, APP_POWEROFF_REQ, NULL);
            }
            else
            {
                MessageSend(&the_app->task, APP_POWERON_REQ, NULL);
            }
        }
        break;
    }
    case BUTTON_PWR_RELEASE:
    {
        DEBUG(("BUTTON_PWR_RELEASE\n"));
        if (!the_app->PowerOffIsEnabled)
        {
            the_app->PowerOffIsEnabled = TRUE;
        }
        break;
    }
    case BUTTON_CONNECT_SECOND_DEVICE_REQ:
    {
#ifdef DUAL_STREAM
        DEBUG(("BUTTON_CONNECT_2ND_DEVICE_REQ\n"));
        if (the_app->dfu_requested)
        {
            the_app->dfu_requested = FALSE;
            testCancelDfuModeRequest();
        }
        else
        {
            /* If it is clearing pdl, no connection attempts are allowed */
            if (!the_app->clearing_pdl && the_app->audioAdaptorPoweredOn)
            {
                MessageCancelAll(&the_app->task, APP_DEVICE_CONNECT_REQ);
                MessageSend(&the_app->task, APP_DEVICE_CONNECT_SECOND_REQ, NULL);
            }
        }
#endif /* DUAL_STREAM */
        break;
    }
#if defined DEV_PC_1645_USB || defined DEV_PC_1645_ANALOGUE || defined RED_PC_142
    case CHARGER_RAW:
    {
        DEBUG(("CHARGER_RAW 0x%x\n",((CHARGER_RAW_T*)message)->chg));

        if (the_app->a2dp_source == SourceAnalog)
        {
            if (((CHARGER_RAW_T*)message)->chg)
            {
                /* Send a message to indicate that charger is connected and
                   set the proper flash pattern */
                MessageSend(&the_app->task, APP_CHARGER_CONNECTED, 0 );
                the_app->chargerconnected = TRUE;
            }
            else
            {
                /* send a message to indicate that charger is disconnected */
                MessageSend(&the_app->task, APP_CHARGER_DISCONNECTED, 0 );
                the_app->chargerconnected = FALSE;
            }
        }
        break;
    }
#endif

#if ((defined DEV_PC_1645_USB || defined DEV_PC_1645_ANALOGUE) && defined DEMO_MODE)
    case BUTTON_MODE_FASTSTREAM:
    {
        uint16 i;
        bool codec_chosen = FALSE;
        DEBUG(("BUTTON_MODE_FASTSTREAM\n"));

        /* check the Faststream codec is enabled */
        if (!(the_app->a2dpCodecsEnabled & (1<<FASTSTREAM_CODEC_BIT)))
        {
            DEBUG(("    - codec not enabled\n"));
            break;
        }

        for (i = 0; i < MAX_NUM_DEV_CONNECTIONS; i++)
        {
            if (the_app->dev_inst[i] != NULL)
            {
                switch (the_app->dev_inst[i]->a2dp_state)
                {
                case A2dpStateConnected:
                case A2dpStateOpen:
                case A2dpStateStarting:
                case A2dpStateStreaming:
                case A2dpStateSuspending:
                {
                    the_app->dev_inst[i]->a2dp_closing = TRUE;
                    setA2dpState(the_app->dev_inst[i], A2dpStateClosing);
                    A2dpClose(the_app->dev_inst[i]->a2dp);
                    the_app->dev_inst[i]->a2dp_reopen_tries = 0;
#ifdef DUAL_STREAM
                    if (codec_chosen)
                        the_app->dev_inst[i]->a2dp_reopen_codec = FASTSTREAM_DS_SEID;
                    else
#endif
                        the_app->dev_inst[i]->a2dp_reopen_codec = FASTSTREAM_SEID;
                    codec_chosen = TRUE;
                    MessageSendConditionally(&the_app->dev_inst[i]->task, APP_MEDIA_CHANNEL_REOPEN_REQ, 0, &the_app->dev_inst[i]->a2dp_closing);
                    break;
                }
                default:
                {
                    break;
                }
                }
            }
        }
        break;
    }
    case BUTTON_MODE_SBC:
    {
        uint16 i;
        bool codec_chosen = FALSE;
        DEBUG(("BUTTON_MODE_SBC\n"));

        for (i = 0; i < MAX_NUM_DEV_CONNECTIONS; i++)
        {
            if (the_app->dev_inst[i] != NULL)
            {
                switch (the_app->dev_inst[i]->a2dp_state)
                {
                case A2dpStateConnected:
                case A2dpStateOpen:
                case A2dpStateStarting:
                case A2dpStateStreaming:
                case A2dpStateSuspending:
                {
                    the_app->dev_inst[i]->a2dp_closing = TRUE;
                    setA2dpState(the_app->dev_inst[i], A2dpStateClosing);
                    A2dpClose(the_app->dev_inst[i]->a2dp);
                    the_app->dev_inst[i]->a2dp_reopen_tries = 0;
#ifdef DUAL_STREAM
                    if (codec_chosen)
                        the_app->dev_inst[i]->a2dp_reopen_codec = SBC_DS_SEID;
                    else
#endif
                        the_app->dev_inst[i]->a2dp_reopen_codec = SBC_SEID;
                    codec_chosen = TRUE;
                    MessageSendConditionally(&the_app->dev_inst[i]->task, APP_MEDIA_CHANNEL_REOPEN_REQ, 0, &the_app->dev_inst[i]->a2dp_closing);
                    break;
                }
                default:
                {
                    break;
                }
                }
            }
        }
        break;
    }
    case BUTTON_MODE_MP3:
    {
#ifdef INCLUDE_MP3_ENCODER_PLUGIN
        uint16 i;
        bool codec_chosen = FALSE;
        DEBUG(("BUTTON_MODE_MP3\n"));

        /* check the MP3 codec is enabled */
        if (!(the_app->a2dpCodecsEnabled & (1<<MP3_CODEC_BIT)))
        {
            DEBUG(("    - codec not enabled\n"));
            break;
        }

        for (i = 0; i < MAX_NUM_DEV_CONNECTIONS; i++)
        {
            if (the_app->dev_inst[i] != NULL)
            {
                switch (the_app->dev_inst[i]->a2dp_state)
                {
                case A2dpStateConnected:
                case A2dpStateOpen:
                case A2dpStateStarting:
                case A2dpStateStreaming:
                case A2dpStateSuspending:
                {
                    if (!codec_chosen)
                    {
                        the_app->dev_inst[i]->a2dp_closing = TRUE;
                        setA2dpState(the_app->dev_inst[i], A2dpStateClosing);
                        A2dpClose(the_app->dev_inst[i]->a2dp);
                        the_app->dev_inst[i]->a2dp_reopen_tries = 0;
                        the_app->dev_inst[i]->a2dp_reopen_codec = MP3_SEID;
                        codec_chosen = TRUE;
                        MessageSendConditionally(&the_app->dev_inst[i]->task, APP_MEDIA_CHANNEL_REOPEN_REQ, 0, &the_app->dev_inst[i]->a2dp_closing);
                    }
                    break;
                }
                default:
                {
                    break;
                }
                }
            }
        }
#endif /* INCLUDE_MP3_ENCODER_PLUGIN */
        break;
    }
#endif /* (DEV_PC_1645_USB ||  DEV_PC_1645_ANALOGUE) && DEMO_MODE */

    default:
    {
        /* Unrecognised messages */
        return FALSE;
    }
    }

    return TRUE;
}
/****************************************************************************
NAME
    profileSlcConnectCfm

DESCRIPTION
    A profile connection attempt has ended.
    
*/
void profileSlcConnectCfm (devInstanceTaskData *inst, mvdProfiles profile, bool remote_connecting)
{
    bool all_responded;
    mvdProfiles connected_profiles = ProfileNone;
    
    if (profileSlcCheckPoweredOff(inst))
        return;
        
    inst->responding_profiles |= profile;    

   /* decide whether all supported profile has been responded */
   all_responded = ( (inst->responding_profiles & (ProfileAghfp | ProfileAghsp | ProfileAvrcp | ProfileA2dp)) == 
                  ( (inst->remote_profiles & (ProfileAghfp | ProfileAghsp | ProfileAvrcp | ProfileA2dp)) & 
                    (the_app->supported_profiles & (ProfileAghfp | ProfileAghsp | ProfileAvrcp | ProfileA2dp))) );
                 
   if (getAghfpState(inst) >= AghfpStateConnected)
   {
      connected_profiles |= ProfileAghfp;
   }
   if (getA2dpState(inst) >= A2dpStateOpen)
   {
      connected_profiles |= ProfileA2dp;
   }
   if (getAvrcpState(inst) == AvrcpStateConnected)
   {
      connected_profiles |= ProfileAvrcp;
   }

   DEBUG_CONN(("profileSlcConnectCfm conn'd:%x resp'd:%x all_resp'd:%x\n",connected_profiles, inst->responding_profiles, all_responded));

   /* Stop the profile connection timer */
   stopAppProfileConnectTimer( inst );    

    if ( connected_profiles==ProfileNone && all_responded ) 
    {    /* All profiles supported by remote device have responded, but none have connected */
        stopAppConnectTimer(inst);            
        profileSlcConnectComplete(inst, FALSE);
    }
    else if ( connected_profiles!=ProfileNone && all_responded )
    {    /* At least one profile is connected and all others have responded */            
        stopAppConnectTimer(inst);
        
        DEBUG_CONN(("connect_attempts=%u\n",the_app->connect_attempts));
/* don't retry to connect */
#if 0
        if ( ++the_app->connect_attempts<MAX_APP_CONNECT_ATTEMPTS && (connected_profiles != (inst->remote_profiles & the_app->supported_profiles)) ) /*&& (the_app->app_state==AppStatePaging || the_app->app_state==AppStatePaged) )*/
        {   
            /* Only keep profiles in responding bitmask that have connected */
            inst->responding_profiles = connected_profiles;
            
            /* Try to connect to the unconnected profiles again */
            profileSlcConnectReq();
        }
        else
#endif			
        {
            the_app->connect_attempts = 0;
            profileSlcConnectComplete(inst, TRUE);
        }
    }
    else        
    {    
        /* change the state to idle if the dongle was connecting */
        if (the_app->app_state == AppStateConnecting)
            setAppState(AppStateIdle);
            
        /* Still some outstanding profiles to connect/respond */
        if (remote_connecting)
        {   /* Start timer to take over connection process if necessary */
            /* when the remote device is connecting back                */
/*            startAppConnectTimer(inst);*/
        }
        else
        {   /* Kick off connection of next profile */
#ifdef WAIT_A2DP_CONNECT        /* this condition is only for test remote reaction */  
            MessageCancelAll(&inst->task, APP_LATE_CONNECT_TIMER);
            MessageSendLater(&inst->task, APP_LATE_CONNECT_TIMER, 0, D_SEC(5));
#else
            profileSlcConnectReq();
#endif            
        }
    }
}
예제 #12
0
/****************************************************************************
NAME    
    inquiry_process_results - Process the devices located during the inquiry procedure
*/
void inquiry_process_results(void)
{
    INQUIRY_DEBUG(("INQUIRY: inquiry_process_results\n"));
    if (inquiry_has_results())
    {
        PROFILES_T connect_profile = PROFILE_NONE;
        
        /* store the index of the remote device to try */
        theSource->inquiry_data->search_idx = theSource->inquiry_data->read_idx;
        /* increment inquiry read index */
        theSource->inquiry_data->read_idx++; 
        
        INQUIRY_DEBUG(("    has result\n"));
        
        if (AGHFP_PROFILE_IS_ENABLED &&
                ((theSource->inquiry_data->eir_data[theSource->inquiry_data->search_idx].profiles & PROFILE_AGHFP) == PROFILE_AGHFP))
        {
            /* connect with AGHFP profile if supported on Source and advertised as supported on remote device in EIR data */
            connect_profile = PROFILE_AGHFP;
        }
        else if (A2DP_PROFILE_IS_ENABLED && 
                ((theSource->inquiry_data->eir_data[theSource->inquiry_data->search_idx].profiles & PROFILE_A2DP) == PROFILE_A2DP))
        {
            /* connect with A2DP profile if supported on Source and advertised as supported on remote device in EIR data */
            connect_profile = PROFILE_A2DP;
        }
        else
        {
            /* connect with AGHFP profile if enabled otherwise use A2DP profile */
            connect_profile = AGHFP_PROFILE_IS_ENABLED ? PROFILE_AGHFP : PROFILE_A2DP;
        }
         
        /* initialise the connection with the connection manager */
        connection_mgr_start_connection_attempt(&theSource->inquiry_data->buffer[theSource->inquiry_data->search_idx], connect_profile, 0); 
    }
    else
    {               
        if (theSource->inquiry_data && theSource->inquiry_data->inquiry_state_timeout)
        {
            /* free inquiry memory */
            inquiry_complete();
            /* inquiry state has timed out, move to next procedure */
            if (theSource->ps_config->ps_timers.inquiry_idle_timer)
            {
                /* there is an idle time between inquiry attempts so move to discoverable state in the meantime */                
                if (theSource->ps_config->ps_timers.inquiry_idle_timer != TIMER_NO_TIMEOUT)
                {
                    MessageSendLater(&theSource->app_data.appTask, APP_INQUIRY_IDLE_TIMEOUT, 0, D_SEC(theSource->ps_config->ps_timers.inquiry_idle_timer));
                }
                states_set_state(SOURCE_STATE_DISCOVERABLE);
            }
            else
            {
                /* restart inquiry */
                inquiry_start_discovery();
            }            
        }
        else
        {
            /* restart inquiry */
            inquiry_start_discovery();
        }
    }
}
예제 #13
0
/****************************************************************************
NAME    
    inquiry_start_discovery - Begin inquiry procedure
*/
void inquiry_start_discovery(void)
{
    INQUIRY_DEBUG(("INQUIRY: inquiry_start_discovery\n"));
        
    if (theSource->inquiry_data == NULL)
    {
        theSource->inquiry_data = (INQUIRY_SCAN_DATA_T *) memory_create(sizeof(INQUIRY_SCAN_DATA_T));
        if (theSource->inquiry_data)
        {
            /* set read and write indexes */
            theSource->inquiry_data->read_idx = 0;
            theSource->inquiry_data->write_idx = 0;
            theSource->inquiry_data->search_idx = 0;             
            theSource->inquiry_data->inquiry_state_timeout = 0;
            if (theSource->ps_config->ps_timers.inquiry_state_timer != TIMER_NO_TIMEOUT)
            {
                MessageSendLater(&theSource->app_data.appTask, APP_INQUIRY_STATE_TIMEOUT, 0, D_SEC(theSource->ps_config->ps_timers.inquiry_state_timer));
            }
        }
    }
    
    if (theSource->inquiry_data)
    {
        /* start Bluetooth inquiry */
        ConnectionInquire(&theSource->connectionTask, INQUIRY_LAP, INQUIRY_MAX_RESPONSES, INQUIRY_TIMEOUT, (uint32)COD_MAJOR_AV);            
    }
    else
    {
        /* memory should exist here issue a Panic */
        Panic();
    }
}
void handleUEMessage( Task task, MessageId id, Message message )
{ 
    headsetHfpState lState = stateManagerGetHfpState() ;
    
    /* If we do not want the event received to be indicated then set this to FALSE. */
    bool lIndicateEvent = TRUE ;

	if (theHeadset.ProfileLibrariesInitialising)
	{
		if (!eventAllowedWhileProfilesInitialising(id))
		{
			EVENTS_DEBUG(("Event 0x%x while profiles initialising - queue\n",id));
			MessageSendConditionally(&theHeadset.task, id, 0, &theHeadset.ProfileLibrariesInitialising);
			return;
		}
	}    
    
    /* Deal with user generated Event specific actions*/
    switch ( id )
    {   
            /*these are the events that are not user generated and can occur at any time*/
        case EventOkBattery:
        case EventChargerDisconnected:
        case EventLEDEventComplete:
        case EventTrickleCharge:
		case EventFastCharge:
        case EventLowBattery:
        case EventPowerOff:
        case EventLinkLoss:
        case EventSLCConnected:
		case EventA2dpConnected:
        case EventError:
        case EventChargeError:
        case EventCancelLedIndication:
        case EventAutoSwitchOff:
		case EventHfpReconnectFailed:
		case EventA2dpReconnectFailed:
            /*do nothing for these events*/
        break ;
        default:
        break;
    }
    
    
    switch (id)
    {
    case EventPowerOn:
        EVENTS_DEBUG(("EventPowerOn\n"));
		
		if (!theHeadset.headsetPoweredOn)
		{
			theHeadset.headsetPoweredOn = TRUE;
			theHeadset.a2dp_list_index = 0xf;
			theHeadset.hfp_list_index = 0xf;
			theHeadset.switch_a2dp_source = FALSE;
		
        	stateManagerPowerOn();
			
			if(theHeadset.Timeouts.EncryptionRefreshTimeout_m != 0)
				MessageSendLater(&theHeadset.task, APP_EVENT_REFRESH_ENCRYPTION, 0, D_MIN(theHeadset.Timeouts.EncryptionRefreshTimeout_m));
			
        	theHeadset.PowerOffIsEnabled = TRUE ;
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
        break;
    case EventPowerOff:
        EVENTS_DEBUG(("EventPowerOff\n"));
		if (!theHeadset.PowerOffIsEnabled)
		{
			EVENTS_DEBUG(("Power off disabled - ignore event\n"));
			lIndicateEvent = FALSE ;
			break;
		}
		
		theHeadset.headsetPoweredOn = FALSE;
		theHeadset.a2dp_list_index = 0xf;
		theHeadset.hfp_list_index = 0xf;
		theHeadset.switch_a2dp_source = FALSE;
		
        stateManagerEnterPoweringOffState();
        AuthResetConfirmationFlags();
        if (theHeadset.gMuted)
            VolumeMuteOff() ;
        hfpCallClearQueuedEvent() ;
		
		if(theHeadset.Timeouts.EncryptionRefreshTimeout_m != 0)
    		MessageCancelAll ( &theHeadset.task, APP_EVENT_REFRESH_ENCRYPTION) ;
		
        MessageCancelAll ( &theHeadset.task , EventPairingFail) ;
        break;
    case EventEnterPairing:    
		EVENTS_DEBUG(("EventEnterPairing\n"));
        stateManagerEnterConnDiscoverableState( ) ;       
        break ;
    case EventPairingFail:  
        EVENTS_DEBUG(("EventPairingFail\n"));
        if (lState != headsetTestMode)
        {      
			stateManagerEnterHfpConnectableState( TRUE) ; 
        }
        break ;    
    case EventPairingSuccessful:
        EVENTS_DEBUG(("EventPairingSuccessful\n"));
        if (lState == headsetConnDiscoverable)
        {
            stateManagerEnterHfpConnectableState( FALSE) ;
        }
        break ;
    case EventConfirmationAccept:
        EVENTS_DEBUG(("EventConfirmationAccept\n"));
        headsetPairingAcceptRes();
        break;
    case EventConfirmationReject:
        EVENTS_DEBUG(("EventConfirmationReject\n"));
        headsetPairingRejectRes();
        break;
    case EventToggleDebugKeys:
        EVENTS_DEBUG(("EventToggleDebugKeys\n"));
        /* if debug keys functionality enabled toggle current state */
        if (theHeadset.features.debugKeysEnabled)
        {
            ConnectionSmSecModeConfig(&theHeadset.task,
                                      cl_sm_wae_acl_owner_none,
                                      !theHeadset.debugKeysInUse,
                                      TRUE);
        }
        break;
    case EventSLCConnected:
        EVENTS_DEBUG(("EventSLCConnected\n"));
        hfpCallRecallQueuedEvent() ;
        break;
    case EventLinkLoss:
        EVENTS_DEBUG(("EventLinkLoss\n"));        
        break;
    case EventSLCDisconnected:
        EVENTS_DEBUG(("EventSLCDisconnected\n"));
		if (lState == headsetPoweringOn )
			lIndicateEvent = FALSE ;
		
        theHeadset.voice_recognition_enabled = FALSE;
        break;
    case EventEstablishSLC:   
		EVENTS_DEBUG(("EventEstablishSLC\n"));
		
		/* Cancel inquiry and throw away results if one is in progress */
        inquiryStop();
		
		if (theHeadset.slcConnectFromPowerOn)
		{
			/* This is from power on so carry out the power on connect sequence */
			lIndicateEvent = FALSE ;			
		}
		else
		{
		    bdaddr bd_addr;
			/* Try a connection attempt to Last AG. */       
    		if (!hfpSlcConnectBdaddrRequest( hfp_handsfree_profile, &bd_addr ) )
				lIndicateEvent = FALSE ;
		}
        
        break;
    case EventHfpReconnectFailed:
        EVENTS_DEBUG(("EventHfpReconnectFailed\n"));
        break;
	case EventA2dpReconnectFailed:
        EVENTS_DEBUG(("EventA2dpReconnectFailed\n"));
        break;
    case EventInitateVoiceDial:                   
		EVENTS_DEBUG(("EventInitateVoiceDial [%d]\n", theHeadset.voice_recognition_enabled )) ; 
        /* Toggle the voice dial behaviour depending on whether we are currently active */
        if (theHeadset.voice_recognition_enabled)
        {
            hfpCallCancelVoiceDial() ;
            lIndicateEvent = FALSE ;
        }
        else
        {     
            if (!hfpCallInitiateVoiceDial())
				lIndicateEvent = FALSE ;
        }            
        break ;
    case EventLastNumberRedial:          
		if (theHeadset.features.LNRCancelsVoiceDialIfActive)
		{
			if (theHeadset.voice_recognition_enabled)
			{
				MessageSend(&theHeadset.task, EventInitateVoiceDial, 0);
				lIndicateEvent = FALSE ;
				break;
			}
		}
		
		EVENTS_DEBUG(("EventLastNumberRedial\n" )) ; 
		
        if (!hfpCallInitiateLNR())
			lIndicateEvent = FALSE ;
        break ;
    case EventAnswer:
        EVENTS_DEBUG(("EventAnswer\n" )) ;		
        /* Call the HFP lib function, this will determine the AT cmd to send
           depending on whether the profile instance is HSP or HFP compliant. */ 
        hfpCallAnswer();
        break ; 
    case EventReject:
        EVENTS_DEBUG(("EventReject\n" )) ;
        /* Reject incoming call - only valid for instances of HFP. */ 
        hfpCallReject();
        break ;
    case EventCancelEnd:
		if (theHeadset.features.EndCallWithNoSCOtransfersAudio && !HfpGetAudioSink(theHeadset.hfp_hsp))
		{
			lIndicateEvent = FALSE;
			MessageSend(&theHeadset.task, EventTransferToggle, 0);
		}
		else
		{
        	EVENTS_DEBUG(("EventCancelEnd\n" )) ;
        	/* Terminate the current ongoing call process */
        	hfpCallHangUp();
		}
        break ;
    case EventTransferToggle :
	    EVENTS_DEBUG(("EventTransferToggle\n")) ;    
        hfpCallTransferToggle() ;
	    break ;
    case EventSCOLinkOpen :        
        EVENTS_DEBUG(("EventScoLinkOpen\n")) ;
        break ;
    case EventSCOLinkClose:        
        EVENTS_DEBUG(("EventScoLinkClose\n")) ;
        break ;        
    case EventResetPairedDeviceList:          
		EVENTS_DEBUG(("EventResetPairedDeviceList\n")) ;  
        if ( stateManagerIsHfpConnected () )
        {
            /* Then we have an SLC active */
            hfpSlcDisconnect();
        }             
		if ( stateManagerIsA2dpConnected() )
    	{      
       		a2dpDisconnectRequest();
    	}
        configManagerReset() ;
        break ;
    case EventToggleMute:
        EVENTS_DEBUG(("EventToggleMute\n")) ;
        VolumeToggleMute() ;
        break ;    
    case EventMuteOn :
        EVENTS_DEBUG(("EventMuteOn\n")) ;
        VolumeMuteOn() ;
        break ;
    case EventMuteOff:
        EVENTS_DEBUG(("EventMuteOff\n")) ;
        VolumeMuteOff() ;
        break ;
    case EventMuteReminder :        
        EVENTS_DEBUG(("EventMuteReminder\n")) ;
        MessageSendLater( &theHeadset.task , EventMuteReminder , 0 ,D_SEC(theHeadset.Timeouts.MuteRemindTime_s ) )  ;            
        break;
    case EventEnterDutState :
        EVENTS_DEBUG(("EventEnterDutState\n")) ;            
		stateManagerEnterTestModeState() ;
        break;  
	case EventEnterDutMode :
        EVENTS_DEBUG(("EventEnterDutMode\n")) ; 
		if (lState != headsetTestMode)
        {
        	MessageSend( task , EventEnterDutState, 0 ) ;
        }
		ConnectionEnterDutMode();
        break;
	case EventEnterTXContTestMode:
		EVENTS_DEBUG(("EventEnterTXContTestMode\n"));
		if (lState != headsetTestMode)
        {
        	MessageSend( task , EventEnterDutState, 0 ) ;
        }
		MessageSendLater( task , APP_TX_TEST_MODE, 0, 1000 ) ;
		break;
    case EventResetComplete:
        EVENTS_DEBUG(("EventResetComplete\n"));
        break;
    case EventError:        
        EVENTS_DEBUG(("EventError\n")) ;
        break;
    case EventEndOfCall :        
        EVENTS_DEBUG(("EventEndOfCall\n")) ;
        break;    
	case EventA2dpConnected:
        EVENTS_DEBUG(("EventA2dpConnected\n")) ;		
        break;    
	case EventA2dpDisconnected:
        EVENTS_DEBUG(("EventA2dpDisconnected\n")) ;
		if (lState == headsetPoweringOn )
			lIndicateEvent = FALSE ;
        break; 
	case EventVolumeMax:
		EVENTS_DEBUG(("EventVolumeMax\n"));
		break;
	case EventVolumeMin:
		EVENTS_DEBUG(("EventVolumeMin\n"));
		break;
	case EventPlay:		
		EVENTS_DEBUG(("EventPlay\n"));
		/* Always indicate play event as will try to connect A2DP if not already connected */
		avrcpEventPlay();		
		break;
	case EventPause:		
		EVENTS_DEBUG(("EventPause\n"));
		avrcpEventPause();		
		break;
	case EventStop:		
		EVENTS_DEBUG(("EventStop\n"));
		avrcpEventStop();		
		break;
	case EventSkipForward:		
		/* Only indicate event if AVRCP connected */
		if ( stateManagerIsAvrcpConnected() )
		{
			EVENTS_DEBUG(("EventSkipForward\n"));
			avrcpEventSkipForward();
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
		break;
	case EventSkipBackward:		
		/* Only indicate event if AVRCP connected */
		if ( stateManagerIsAvrcpConnected() )
		{
			EVENTS_DEBUG(("EventSkipBackward\n"));
			avrcpEventSkipBackward();	
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
		break;
	case EventFFWDPress:		
		if ( stateManagerIsAvrcpConnected() )
		{
			EVENTS_DEBUG(("EventFFWDPress\n"));
			avrcpEventFastForwardPress();
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
		break;
	case EventFFWDRelease:		
		if ( stateManagerIsAvrcpConnected() )
		{
			EVENTS_DEBUG(("EventFFWDRelease\n"));
			avrcpEventFastForwardRelease();
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
		break;
	case EventRWDPress:		
		if ( stateManagerIsAvrcpConnected() )
		{
			EVENTS_DEBUG(("EventRWDPress\n"));
			avrcpEventFastRewindPress();
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
		break;
	case EventRWDRelease:		
		if ( stateManagerIsAvrcpConnected() )
		{
			EVENTS_DEBUG(("EventRWDRelease\n"));
			avrcpEventFastRewindRelease();
		}
		else
		{
			lIndicateEvent = FALSE ;
		}
		break;		
	case EventEnterDFUMode:
		EVENTS_DEBUG(("EventEnterDFUMode\n"));
		BootSetMode(0);
		break;		
	case EventSwitchA2dpSource:
		EVENTS_DEBUG(("EventSwitchA2dpSource\n"));
		a2dpSwitchSource();
		break;
	case EventSwitchAudioMode:
		EVENTS_DEBUG(("EventSwitchAudioMode\n"));
		if (theHeadset.eqMode >= eq_mode_passthrough)
		{
			theHeadset.eqMode = eq_mode_level1;
		}
		else
		{
			theHeadset.eqMode++;	
		}
		if ((theHeadset.dsp_process == dsp_process_a2dp))
		{
			/* Set audio mode for A2DP only (not used for Faststream) */
			AudioSetMode(theHeadset.eqMode, 0);
		}
		break;
	case EventToggleLEDS:
		EVENTS_DEBUG(("EventToggleLEDS\n"));
		
#ifdef ROM_LEDS			
		LedManagerToggleLEDS();
#endif
		
		break;
		
	/* threeway calling events */
	case EventThreeWayReleaseAllHeld:
		EVENTS_DEBUG(("EventThreeWayReleaseAllHeld\n"));
        HfpMultipleCallsReleaseHeldOrRejectWaiting(theHeadset.hfp);
        break;
 	case EventThreeWayAcceptWaitingReleaseActive:
        EVENTS_DEBUG(("EventThreeWayAcceptWaitingReleaseActive\n"));
        HfpMultipleCallsReleaseActiveAcceptOther(theHeadset.hfp);
        break;
	case EventThreeWayAcceptWaitingHoldActive:
		EVENTS_DEBUG(("EventThreeWayAcceptWaitingHoldActive\n"));
		HfpMultipleCallsHoldActiveAcceptOther(theHeadset.hfp);
		break;
	case EventThreeWayAddHeldTo3Way:
 		EVENTS_DEBUG(("EventThreeWayAddHeldTo3Way\n"));
		HfpMultipleCallsAddHeldCall(theHeadset.hfp);
 		break;
	case EventThreeWayConnect2Disconnect:
 		EVENTS_DEBUG(("EventThreeWayConnect2Disconnect\n"));
		HfpMultipleCallsExplicitCallTransfer(theHeadset.hfp);
		break;
        /* end threeway calling events */
		
	case EventRssiPair:
        EVENTS_DEBUG(("EventRssiPair\n"));
		/* start inquiry on this event */
        inquiryStart();
        break;
    case EventRssiPairReminder:
        EVENTS_DEBUG(("EventRssiPairReminder\n"));
		inquiryReminder();
        break;
    case EventRssiPairTimeout:
        EVENTS_DEBUG(("EventRssiPairTimeout\n"));
		/* Stop any pending inquiry now as this pairing mode has timed out */
        inquiryStop();
        break;

    default:
        EVENTS_DEBUG(("UNHANDLED EVENT: 0x%x\n",id));
        lIndicateEvent = FALSE ;
        break;
    }    
    
    if ( lIndicateEvent )
    {
        LEDManagerIndicateEvent ( id ) ;
    }   
}
/****************************************************************************
NAME
    aghfpMsgHandleLibMessage

DESCRIPTION
    Handles AGHFP library messages and calls the relevant handler function.
    
*/
void aghfpMsgHandleLibMessage(MessageId id, Message message)
{
    switch(id)
    {
        case AGHFP_INIT_CFM:
        {
            DEBUG_AGHFP(("AGHFP_INIT_CFM status = %u [0x%X]\n", ((AGHFP_INIT_CFM_T *)message)->status,(uint16)((AGHFP_INIT_CFM_T *)message)->aghfp));
            handleAghfpInitCfm((AGHFP_INIT_CFM_T *)message);
            break;
        }
        case AGHFP_SLC_CONNECT_IND:
        {
            AGHFP_SLC_CONNECT_IND_T *ind = (AGHFP_SLC_CONNECT_IND_T *)message;
			SendEvent(EVT_SLC_CONNECT_IND,0);
            DEBUG_AGHFP(("AGHFP_SLC_CONNECT_IND aghfp=0x%X from: 0x%X 0x%X 0x%lX\n", (uint16)ind->aghfp, ind->bd_addr.nap, ind->bd_addr.uap, ind->bd_addr.lap));
            handleAghfpSlcConnectInd(ind);
            break;
        }                
        case AGHFP_SLC_CONNECT_CFM:
        {
            AGHFP_SLC_CONNECT_CFM_T *cfm = (AGHFP_SLC_CONNECT_CFM_T *)message;
			SendEvent(EVT_SLC_CONNECT_CFM,cfm->status);
            DEBUG_AGHFP(("AGHFP_SLC_CONNECT_CFM aghfp = 0x%X status = %u\n", (uint16)cfm->aghfp, cfm->status));
            handleAghfpSlcConnectCfm(cfm);
            break;            
        }
        case AGHFP_SLC_DISCONNECT_IND:
        {
            AGHFP_SLC_DISCONNECT_IND_T *ind = (AGHFP_SLC_DISCONNECT_IND_T *)message;
			SendEvent(EVT_SLC_DISCONNECT_IND,ind->status);
            DEBUG_AGHFP(("AGHFP_SLC_DISCONNECT_IND aghfp = 0x%X status = %d\n", (uint16)ind->aghfp, (uint16)ind->status));
            handleAghfpSlcDisconnectInd(ind);
            break;
        }        
        case AGHFP_CALL_MGR_CREATE_WAITING_RESPONSE_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALL_MGR_CREATE_WAITING_RESPONSE_IND\n"));
            handleAghfpCallMgrCreateInd(((AGHFP_CALL_MGR_CREATE_WAITING_RESPONSE_IND_T *)message)->aghfp,
                        ((AGHFP_CALL_MGR_CREATE_WAITING_RESPONSE_IND_T *)message)->audio_sink, 
                        AGHFP_CALL_MGR_CREATE_WAITING_RESPONSE_IND);
            break;
        }
        case AGHFP_CALL_MGR_CREATE_ALERTING_REMOTE_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALL_MGR_CREATE_ALERTING_REMOTE_IND\n"));
            handleAghfpCallMgrCreateInd(((AGHFP_CALL_MGR_CREATE_ALERTING_REMOTE_IND_T *)message)->aghfp,
                        ((AGHFP_CALL_MGR_CREATE_ALERTING_REMOTE_IND_T *)message)->audio_sink, 
                        AGHFP_CALL_MGR_CREATE_ALERTING_REMOTE_IND);
            break;
        }        
        case AGHFP_CALL_MGR_CREATE_CFM:
        {
            DEBUG_AGHFP(("AGHFP_CALL_MGR_CREATE_CFM status = %u\n", ((AGHFP_CALL_MGR_CREATE_CFM_T *)message)->status));
            handleAghfpCallMgrCreateCfm((AGHFP_CALL_MGR_CREATE_CFM_T *)message);
            break;
        }
        case AGHFP_CALL_MGR_TERMINATE_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALL_MGR_TERMINATE_IND\n"));
            handleAghfpCallMgrTerminateInd((AGHFP_CALL_MGR_TERMINATE_IND_T *)message);
            break;
        }
        case AGHFP_AUDIO_CONNECT_IND:
        {
			SendEvent(EVT_AUDIO_CONNECT_IND,0);
            DEBUG_AGHFP(("AGHFP_AUDIO_CONNECT_IND\n"));
            handleAghfpAudioConnectInd((AGHFP_AUDIO_CONNECT_IND_T *)message);
            break;
        }
        case AGHFP_AUDIO_CONNECT_CFM:
        {
			SendEvent(EVT_AUDIO_CONNECT_CFM,((AGHFP_AUDIO_CONNECT_CFM_T *)message)->status);
            DEBUG_AGHFP(("AGHFP_AUDIO_CONNECT_CFM status = %u\n", ((AGHFP_AUDIO_CONNECT_CFM_T *)message)->status));
            handleAghfpAudioConnectCfm((AGHFP_AUDIO_CONNECT_CFM_T *)message);
            break;
        }        
        case AGHFP_AUDIO_DISCONNECT_IND:
        {
			SendEvent(EVT_AUDIO_DISCONNECT_IND,((AGHFP_AUDIO_DISCONNECT_IND_T *)message)->status);
            DEBUG_AGHFP(("AGHFP_AUDIO_DISCONNECT_IND\n"));
            handleAghfpAudioDisconnectInd((AGHFP_AUDIO_DISCONNECT_IND_T *)message);
            break;
        }
        case AGHFP_HS_CALL_ANSWER_IND:
        {
            DEBUG_AGHFP(("AGHFP_HS_CALL_ANSWER_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_ACTIVE,0);
            break;
        }    
        case AGHFP_HS_CALL_HANG_UP_IND:
        {
            DEBUG_AGHFP(("AGHFP_HS_CALL_HANG_UP_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_INACTIVE,0);
            break;
        }        
        case AGHFP_HS_AUDIO_REQUEST_IND:
        {
            DEBUG_AGHFP(("AGHFP_HS_AUDIO_REQUEST_IND\n"));
            if ( the_app->voip_call_active )
            {
            }
            else
            {
            }
            break;
        }        
        case AGHFP_ANSWER_IND:
        {
            DEBUG_AGHFP(("AGHFP_ANSWER_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_ACTIVE,0);
/*			aghfpCallAnswer(aghfp_call_type_incoming);*/
            break;
        }   
        case AGHFP_CALL_HANG_UP_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALL_HANG_UP_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_INACTIVE,0);
            break;
        }    
        case AGHFP_DIAL_IND:
        {
            DEBUG_AGHFP(("AGHFP_DIAL_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_OUTGOING,0);
            break;
        }    
        case AGHFP_MEMORY_DIAL_IND:
        {
            DEBUG_AGHFP(("AGHFP_MEMORY_DIAL_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_OUTGOING,0);
            break;
        }    
        case AGHFP_LAST_NUMBER_REDIAL_IND:
        {
            DEBUG_AGHFP(("AGHFP_LAST_NUMBER_REDIAL_IND\n"));
			MessageSend(&the_app->task,APP_VOIP_CALL_OUTGOING,0);
            break;
        }
        case AGHFP_CALLER_ID_SETUP_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALLER_ID_SETUP_IND\n"));
            /* Ignore this message for now, OK sent by library */
            DEBUG_AGHFP(("  - ignored\n"));
            break;
        }    
        case AGHFP_CALL_WAITING_SETUP_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALL_WAITING_SETUP_IND\n"));
            /* Ignore this message for now, OK sent by library */
            DEBUG_AGHFP(("  - ignored\n"));
            break;
        }    
        case AGHFP_CALL_HOLD_IND:
        {
            DEBUG_AGHFP(("AGHFP_CALL_HOLD_IND\n"));
            /* Ignore this message for now, OK sent by library */
            DEBUG_AGHFP(("  - ignored\n"));
            break;
        }    
        case AGHFP_NREC_SETUP_IND:
        {
            DEBUG_AGHFP(("AGHFP_NREC_SETUP_IND\n"));
            /* noise reduction not supported so send error */
            DEBUG_AGHFP(("  - unsupported, send ERROR\n"));
            AghfpSendError(((AGHFP_NREC_SETUP_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_VOICE_RECOGNITION_SETUP_IND:
        {
            DEBUG_AGHFP(("AGHFP_VOICE_RECOGNITION_SETUP_IND\n"));
            /* Ensure voice recongition activation is disabled before setting up call */
            /* on receipt of AGHFP_VOICE_RECOGNITION_ENABLE_CFM.                      */
            AghfpVoiceRecognitionEnable(((AGHFP_VOICE_RECOGNITION_SETUP_IND_T *)message)->aghfp, FALSE);
            break;
        }    
        case AGHFP_PHONE_NUMBER_REQUEST_IND:
        {
            DEBUG_AGHFP(("AGHFP_PHONE_NUMBER_REQUEST_IND\n"));
            /* Ignore this requiest, send ERROR */
            DEBUG_AGHFP(("  - ignored, send ERROR\n"));
            AghfpSendError(((AGHFP_PHONE_NUMBER_REQUEST_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_TRANSMIT_DTMF_CODE_IND:
        {
            DEBUG_AGHFP(("AGHFP_TRANSMIT_DTMF_CODE_IND\n"));
            /* Ignore this message for now, send OK even though we can't generate a DTMF tone */
            DEBUG_AGHFP(("  - ignored, send OK\n"));
            AghfpSendOk(((AGHFP_TRANSMIT_DTMF_CODE_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_SYNC_MICROPHONE_GAIN_IND:
        {
            DEBUG_AGHFP(("AGHFP_SYNC_MICROPHONE_GAIN_IND\n"));
            break;
        }    
        case AGHFP_SYNC_SPEAKER_VOLUME_IND:
        {
            uint8 vol = ((AGHFP_SYNC_SPEAKER_VOLUME_IND_T*)message)->volume;
            DEBUG_AGHFP(("AGHFP_SYNC_SPEAKER_VOLUME_IND\n"));
            the_app->speaker_volume = vol;
            break;
        }
        case AGHFP_RESPONSE_HOLD_STATUS_REQUEST_IND:
        {
            DEBUG_AGHFP(("AGHFP_RESPONSE_HOLD_STATUS_IND\n"));
            /* Just send OK back since we do not support Response and Hold */
            AghfpSendOk(((AGHFP_RESPONSE_HOLD_STATUS_REQUEST_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_SET_RESPONSE_HOLD_STATUS_IND:
        {
            DEBUG_AGHFP(("AGHFP_RESPONSE_HOLD_IND\n"));
            DEBUG_AGHFP(("  - ignored, send OK\n"));
            /* Not in a hold state so don't need AghfpConfirmResponseHoldState so just send OK*/
            AghfpSendOk(((AGHFP_SET_RESPONSE_HOLD_STATUS_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_SUBSCRIBER_NUMBER_IND:
        {
            DEBUG_AGHFP(("AGHFP_SUBSCRIBER_NUMBER_IND\n"));
            /* Ignore this message for now */
            DEBUG_AGHFP(("  - ignored\n"));
            AghfpSendSubscriberNumbersComplete(((AGHFP_SUBSCRIBER_NUMBER_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_SUBSCRIBER_NUMBER_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SUBSCRIBER_NUMBER_CFM\n"));
            /* Ignore this message for now */
            DEBUG_AGHFP(("  - ignored\n"));
            break;
        }
        case AGHFP_CURRENT_CALLS_IND:
        {
            DEBUG_AGHFP(("AGHFP_CURRENT_CALLS_IND\n"));
            /* Current calls list not supported so just send ok */
            DEBUG_AGHFP(("  - no current calls so just OK\n"));
            AghfpSendOk(((AGHFP_CURRENT_CALLS_IND_T *)message)->aghfp);
            break;
        }    
        case AGHFP_NETWORK_OPERATOR_IND:
        {
            char nwOP[4] = "VoIP";
            DEBUG_AGHFP(("AGHFP_NETWORK_OPERATOR_IND\n"));
            /* we don't have a network operator so just send a generic string */
            DEBUG_AGHFP(("  - respond with operator name VoIP\n"));
            AghfpSendNetworkOperator(((AGHFP_NETWORK_OPERATOR_IND_T *)message)->aghfp, 0, 4, (uint8*)nwOP);
            break;
        }
        /* AGHFP function call confirms - for debug output */
        case AGHFP_NETWORK_OPERATOR_CFM:
        {
            DEBUG_AGHFP(("AGHFP_NETWORK_OPERATOR_CFM\n"));
            break;
        }        
        case AGHFP_SEND_SERVICE_INDICATOR_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_SERVICE_INDICATOR_CFM\n"));
            break;
        }    
        case AGHFP_SEND_CALL_INDICATOR_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_CALL_INDICATOR_CFM\n"));
            break;
        }    
        case AGHFP_SEND_CALL_SETUP_INDICATOR_CFM:
        {
            DEBUG_AGHFP(("AGHFP_CALL_SETUP_INDICATOR_CFM\n"));
            break;
        }    
        case AGHFP_SEND_RING_ALERT_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_RING_ALERT_CFM\n"));
            break;
        }    
        case AGHFP_SEND_CALLER_ID_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_CALLER_ID_CFM\n"));
            break;
        }    
        case AGHFP_INBAND_RING_ENABLE_CFM:
        {
            DEBUG_AGHFP(("AGHFP_INBAND_RING_ENABLE\n"));
            break;
        }    
        case AGHFP_SEND_CALL_WAITING_NOTIFICATION_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_CALL_WAITING_NOTIFICATION_CFM\n"));
            break;
        }    
        case AGHFP_VOICE_RECOGNITION_ENABLE_CFM:
        {
            DEBUG_AGHFP(("AGHFP_VOICE_RECOGNITION_ENABLE_CFM\n"));
            break;
        }    
        case AGHFP_SEND_PHONE_NUMBER_FOR_VOICE_TAG_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_PHONE_NUMBER_FOR_VOICE_TAG_CFM\n"));
            break;
        }    
        case AGHFP_SET_REMOTE_MICROPHONE_GAIN_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SET_REMOTE_MICROPHONE_GAIN_CFM\n"));
            break;
        }    
        case AGHFP_SET_REMOTE_SPEAKER_VOLUME_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SET_REMOTE_SPEAKER_VOLUME_CFM\n"));
            break;
        }    
        case AGHFP_USER_DATA_CFM:
        {
            DEBUG_AGHFP(("AGHFP_USER_DATA_CFM status=%d\n", ((AGHFP_USER_DATA_CFM_T*)message)->status));
            break;
        }    
        case AGHFP_SEND_ERROR_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SEND_ERROR_CFM status=%d\n", ((AGHFP_SEND_ERROR_CFM_T*)message)->status));
            break;
        }    
        case AGHFP_SET_SERVICE_STATE_CFM:
        {
            DEBUG_AGHFP(("AGHFP_SET_SERVICE_STATE_CFM\n"));
            break;
        }    
		case AGHFP_READ_MESSAGE_IND:
		{
            DEBUG_AGHFP(("AGHFP_READ_MESSAGE_IND\n"));
			AghfpSendMessageBody( ((AGHFP_READ_MESSAGE_IND_T*)message)->aghfp,the_app->message_sender,the_app->message_body);
			break;
		}
		case AGHFP_NEW_MESSAGE_IND:
		{
            DEBUG_AGHFP(("AGHFP_READ_MESSAGE_IND\n"));
			SendEvent(EVT_SMS_READY,0);
			break;
		}
		case AGHFP_SEND_MESSAGE_IND:
		{
            DEBUG_AGHFP(("AGHFP_SEND_MESSAGE_IND\n"));
			
			SendData((uint8*)"\r\n+SMR=",7);
			SendData(((AGHFP_SEND_MESSAGE_IND_T*)message)->number,((AGHFP_SEND_MESSAGE_IND_T*)message)->size_number);

			
			the_app->waiting_msg = TRUE;
			MessageCancelAll(&the_app->task,APP_MSG_TIMEOUT);
			MessageSendLater(&the_app->task,APP_MSG_TIMEOUT,0,D_SEC(5));
			break;
		}
        case AGHFP_UNRECOGNISED_AT_CMD_IND:
        {
#ifdef ENABLE_DEBUGxx          
			uint16 i,len = ((AGHFP_UNRECOGNISED_AT_CMD_IND_T*)message)->size_data;
			uint8 *ptr = ((AGHFP_UNRECOGNISED_AT_CMD_IND_T*)message)->data;
            DEBUG_AGHFP(("AGHFP_UNRECOGNISED_AT_CMD_IND\n"));
			for(i=0;i<len;i++)
			{
				DEBUG_AGHFP(("[%c] %x\n",ptr[i],ptr[i]));
			}
#endif      
			if(the_app->waiting_msg)
			{
				MessageCancelAll(&the_app->task,APP_MSG_TIMEOUT);
				the_app->waiting_msg = FALSE;

				AghfpSendMessageAck(((AGHFP_UNRECOGNISED_AT_CMD_IND_T *)message)->aghfp);

				SendData((uint8*)",",1);
				SendHex(((AGHFP_UNRECOGNISED_AT_CMD_IND_T*)message)->data,((AGHFP_UNRECOGNISED_AT_CMD_IND_T*)message)->size_data);
				SendData((uint8*)"\r\n",2);
			}
			else
				AghfpSendError(((AGHFP_UNRECOGNISED_AT_CMD_IND_T *)message)->aghfp);
				
            break;
        }    
        case AGHFP_CSR_SUPPORTED_FEATURES_IND:
        {
            DEBUG_AGHFP(("AGHFP_CSR_SUPPORTED_FEATURES_IND\n"));
            break;
        } 
        default:
        {
            DEBUG_AGHFP(("Unhandled AGHFP message 0x%X\n", (uint16)id));            
            break;
        }
    }
}