Beispiel #1
0
void packet_handler(uint8_t * event, uint16_t event_size){
    if (event[0] == RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE){
        handle = READ_BT_16(event, 9);
        printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE received for handle 0x%04x\n", handle);
        return;
    }


    if (event[0] != HCI_EVENT_HFP_META) return;

    if (event[3]
        && event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
        && event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG 
        && event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES
        && event[2] != HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL){
        printf("ERROR, status: %u\n", event[3]);
        return;
    }

    switch (event[2]) {   
        case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
            printf("Service level connection established.\n");
            break;
        case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
            printf("Service level connection released.\n");
            break;
        case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
            printf("\n** Audio connection established **\n");
            break;
        case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
            printf("\n** Audio connection released **\n");
            break;
        case HFP_SUBEVENT_START_RINGINIG:
            printf("\n** Start Ringing **\n");
            break;        
        case HFP_SUBEVENT_STOP_RINGINIG:
            printf("\n** Stop Ringing **\n");
            break;
        case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER:
            printf("\n** Outgoing call '%s' **\n", &event[3]);
            // validate number
            if ( strcmp("1234567", (char*) &event[3]) == 0
              || strcmp("7654321", (char*) &event[3]) == 0
              || (memory_1_enabled && strcmp(">1",      (char*) &event[3]) == 0)){
                printf("Dialstring valid: accept call\n");
                hfp_ag_outgoing_call_accepted();
                // TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
                // hfp_ag_outgoing_call_ringing();
            } else {
                printf("Dialstring invalid: reject call\n");
                hfp_ag_outgoing_call_rejected();
            }
            break;
        case HFP_SUBEVENT_REDIAL_LAST_NUMBER:
            printf("\n** Redial last number\n");
            if (last_number_exists){
                hfp_ag_outgoing_call_accepted();
                printf("Last number exists: accept call\n");
                // TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
                // hfp_ag_outgoing_call_ringing();
            } else {
                printf("Last number missing: reject call\n");
                hfp_ag_outgoing_call_rejected();
            }
            break;
        case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
            printf("\n** Attach number to voice tag. Sending '1234567\n");
            hfp_ag_send_phone_number_for_voice_tag(device_addr, "1234567");
            break;
        case HFP_SUBEVENT_TRANSMIT_DTMF_CODES:
            printf("\n** Send DTMF Codes: '%s'\n", &event[3]);
            hfp_ag_send_dtmf_code_done(device_addr);
            break;
        case HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL:
            if (current_call_index == 0 && current_call_exists_a){
                printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 1\n");
                hfp_ag_send_current_call_status(device_addr, 1, current_call_dir, current_call_status_a,
                        HFP_ENHANCED_CALL_MODE_VOICE, current_call_mpty, 129, "1234567");
                current_call_index = 1;
                break;
            }
            if (current_call_index == 1 && current_call_exists_b){
                printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 2 \n");
                hfp_ag_send_current_call_status(device_addr, 2, current_call_dir, current_call_status_b,
                        HFP_ENHANCED_CALL_MODE_VOICE, current_call_mpty, 129, "7654321");
                current_call_index = 2;
                break;
            }
            printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 3\n");
            hfp_ag_send_current_call_status_done(device_addr);
            break;
        case HFP_CMD_CALL_ANSWERED:
            printf("Call answered by HF\n");
            if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){
                current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
            }
            if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){
                current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
            }
            break;
        case HFP_SUBEVENT_CONFERENCE_CALL:
            current_call_mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
            current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
            current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
            break;
        default:
            printf("Event not handled %u\n", event[2]);
            break;
    }

}
Beispiel #2
0
static void packet_handler(uint8_t * event, uint16_t event_size){

    if (event[0] == RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE){
        handle = READ_BT_16(event, 9);
        printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE received for handle 0x%04x\n", handle);
        return;
    }

    switch (event[0]){
        case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
            handle = READ_BT_16(event, 9);
            printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE received for handle 0x%04x\n", handle);
            return;

        case HCI_EVENT_INQUIRY_RESULT:
        case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:
        case HCI_EVENT_INQUIRY_COMPLETE:
        case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
            inquiry_packet_handler(HCI_EVENT_PACKET, event, event_size);
            break;

        default:
            break;
    }


    if (event[0] != HCI_EVENT_HFP_META) return;

    if (event[3]
        && event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
        && event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG 
        && event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){
        printf("ERROR, status: %u\n", event[3]);
        return;
    }

    switch (event[2]) {   
        case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
            printf("Service level connection established.\n");
            break;
        case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
            printf("Service level connection released.\n");
            break;
        case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
            printf("\n** Audio connection established **\n");
            break;
        case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
            printf("\n** Audio connection released **\n");
            break;
        case HFP_SUBEVENT_START_RINGINIG:
            printf("\n** Start Ringing **\n");
            break;        
        case HFP_SUBEVENT_STOP_RINGINIG:
            printf("\n** Stop Ringing **\n");
            break;
        case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER:
            printf("\n** Outgoing call '%s' **\n", &event[3]);
            // validate number
            if ( strcmp("1234567", (char*) &event[3]) == 0
              || strcmp("7654321", (char*) &event[3]) == 0
              || (memory_1_enabled && strcmp(">1",      (char*) &event[3]) == 0)){
                printf("Dialstring valid: accept call\n");
                hfp_ag_outgoing_call_accepted();
            } else {
                printf("Dialstring invalid: reject call\n");
                hfp_ag_outgoing_call_rejected();
            }
            break;
        
        case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
            printf("\n** Attach number to voice tag. Sending '1234567\n");
            hfp_ag_send_phone_number_for_voice_tag(device_addr, "1234567");
            break;
        case HFP_SUBEVENT_TRANSMIT_DTMF_CODES:
            printf("\n** Send DTMF Codes: '%s'\n", &event[3]);
            hfp_ag_send_dtmf_code_done(device_addr);
            break;
        case HFP_CMD_CALL_ANSWERED:
            printf("Call answered by HF\n");
            break;
        default:
            printf("Event not handled %u\n", event[2]);
            break;
    }
}