Пример #1
0
/*******************************************************************************
**
** Function         bta_hd_hdl_event
**
** Description      HID device main event handling function.
**
** Returns          void
**
*******************************************************************************/
BOOLEAN bta_hd_hdl_event(BT_HDR *p_msg)
{
    tBTA_HD_CBACK_DATA  *p_data = (tBTA_HD_CBACK_DATA *) p_msg;

    APPL_TRACE_API2("%s: p_msg->event=%d", __FUNCTION__, p_msg->event);

    switch (p_msg->event)
    {
        case BTA_HD_API_ENABLE_EVT:
            bta_hd_api_enable((tBTA_HD_DATA *) p_msg);
            break;

        case BTA_HD_API_DISABLE_EVT:
            if (bta_hd_cb.state == BTA_HD_CONN_ST)
            {
                APPL_TRACE_WARNING1("%s: host connected, need to "
                    "disconnect before disabling", __FUNCTION__);

                // unregister (and disconnect)
                bta_hd_cb.disable_w4_close = TRUE;
                bta_hd_sm_execute(BTA_HD_API_UNREGISTER_APP_EVT,
                    (tBTA_HD_DATA *) p_msg);
            }
            else
            {
                bta_hd_api_disable();
            }
            break;

        default:
            bta_hd_sm_execute(p_msg->event, (tBTA_HD_DATA *) p_msg);
    }
    return (TRUE);
}
Пример #2
0
int socket_server_open(char *socket_name)
{
    int sock = -1;
    struct sockaddr_un server_address;
    int status;
    char errorstring[80];

    sock = socket(AF_UNIX, SOCK_STREAM, 0);
    if (sock < 0) 
    {
        strerror_r(errno, errorstring, sizeof(errorstring));
        APPL_TRACE_ERROR1("socket_server_open: socket failed(%s) \n", errorstring);
        return -1;
    }

    memset((char *) &server_address, 0 , sizeof(server_address));
    server_address.sun_family = AF_UNIX;
    server_address.sun_path[0] = 0;

    strncat(server_address.sun_path, (char*)socket_name, sizeof(server_address.sun_path)-1-strlen(server_address.sun_path));

     /* Remove old socket (if previous server closed without removing it) */
    if (unlink(server_address.sun_path) == 0)
    {
        APPL_TRACE_WARNING1("socket_server_open: removed old file:%s \n", socket_name);
    }

    
    if (bind(sock, (struct sockaddr *) &server_address,
            sizeof(server_address)) < 0)
    {
        strerror_r(errno, errorstring, sizeof(errorstring));
        APPL_TRACE_ERROR1("socket_server_open: bind failed(%s) \n", errorstring);
        close(sock);
        return -1;
    }

    /* Set up queue for incoming connections. */
    status = listen(sock, LISTEN_BACKLOG);
    if (status < 0)
    {
        strerror_r(errno, errorstring, sizeof(errorstring));
        APPL_TRACE_ERROR1("socket_server_open: listen failed(%s) \n", errorstring);
        close(sock);
        return -1;
    }

    return sock;
}
static inline rfc_slot_t* find_rfc_slot_by_id(uint32_t id)
{
    int i;
    if(id)
    {
        for(i = 0; i < MAX_RFC_CHANNEL; i++)
        {
            if(rfc_slots[i].id == id)
            {
                return &rfc_slots[i];
            }
        }
    }
    APPL_TRACE_WARNING1("invalid rfc slot id: %d", id);
    return NULL;
}
/*******************************************************************************
**
** Function         bta_pan_scb_by_handle
**
** Description      Find scb associated with handle.
**
**
** Returns          Pointer to scb or NULL if not found.
**
*******************************************************************************/
tBTA_PAN_SCB *bta_pan_scb_by_handle(UINT16 handle)
{
    tBTA_PAN_SCB     *p_scb = &bta_pan_cb.scb[0];
    UINT8 i;

    for (i = 0; i < BTA_PAN_NUM_CONN; i++, p_scb++)
    {
        if (p_scb->handle == handle)
        {
            return p_scb;;
        }
    }


    APPL_TRACE_WARNING1("No scb for handle %d", handle);

    return NULL;
}
Пример #5
0
/*******************************************************************************
**
** Function         bta_ag_scb_by_idx
**
** Description      Given an scb index return pointer to scb.
**
**
** Returns          Pointer to scb or NULL if not allocated.
**
*******************************************************************************/
tBTA_AG_SCB *bta_ag_scb_by_idx(UINT16 idx)
{
    tBTA_AG_SCB     *p_scb;

    /* verify index */
    if (idx > 0 && idx <= BTA_AG_NUM_SCB)
    {
        p_scb = &bta_ag_cb.scb[idx - 1];
        if (!p_scb->in_use)
        {
            p_scb = NULL;
            APPL_TRACE_WARNING1("ag scb idx %d not allocated", idx);
        }
    }
    else
    {
        p_scb = NULL;
        APPL_TRACE_DEBUG1("ag scb idx %d out of range", idx);
    }
    return p_scb;
}
Пример #6
0
/***************************************************************************
 *  Function       handle_rc_passthrough_cmd
 *
 *  - Argument:    tBTA_AV_RC rc_id   remote control command ID
 *                 tBTA_AV_STATE key_state status of key press
 *
 *  - Description: Remote control command handler
 *
 ***************************************************************************/
void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
{
    const char *status;
    int pressed, i;

    /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */
    if (p_remote_cmd)
    {
        /* queue AVRC PLAY if GAVDTP Open notification to app is pending (2 second timer) */
        if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btif_av_is_connected()))
        {
            if (p_remote_cmd->key_state == AVRC_STATE_PRESS)
            {
                APPL_TRACE_WARNING1("%s: AVDT not open, queuing the PLAY command", __FUNCTION__);
                btif_rc_cb.rc_pending_play = TRUE;
            }
            return;
        }

        if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btif_rc_cb.rc_pending_play))
        {
            APPL_TRACE_WARNING1("%s: Clear the pending PLAY on PAUSE received", __FUNCTION__);
            btif_rc_cb.rc_pending_play = FALSE;
            return;
        }
    }
    if (p_remote_cmd->key_state == AVRC_STATE_RELEASE) {
        status = "released";
        pressed = 0;
    } else {
        status = "pressed";
        pressed = 1;
    }

    /* If this is Play/Pause command (press or release)  before processing, check the following
     * a voice call has ended recently
     * the remote device is not of type headset
     * If the above conditions meet, drop the Play/Pause command
     * This fix is to interop with certain carkits which sends an automatic  PLAY  or PAUSE
     * commands right after call ends
     */
    if((p_remote_cmd->rc_id == BTA_AV_RC_PLAY || p_remote_cmd->rc_id == BTA_AV_RC_PAUSE)&&
       (btif_hf_call_terminated_recently() == TRUE) &&
       (check_cod( (const bt_bdaddr_t*)&(btif_rc_cb.rc_addr), COD_AV_HEADSETS) != TRUE))
    {
        BTIF_TRACE_DEBUG2("%s:Dropping the play/Pause command received right after call end cmd:%d",
                           __FUNCTION__,p_remote_cmd->rc_id);
        return;
    }

    for (i = 0; key_map[i].name != NULL; i++) {
        if (p_remote_cmd->rc_id == key_map[i].avrcp) {
            BTIF_TRACE_DEBUG3("%s: %s %s", __FUNCTION__, key_map[i].name, status);

           /* MusicPlayer uses a long_press_timeout of 1 second for PLAYPAUSE button
            * and maps that to autoshuffle. So if for some reason release for PLAY/PAUSE
            * comes 1 second after the press, the MediaPlayer UI goes into a bad state.
            * The reason for the delay could be sniff mode exit or some AVDTP procedure etc.
            * The fix is to generate a release right after the press and drown the 'actual'
            * release.
            */
            if ((key_map[i].release_quirk == 1) && (pressed == 0))
            {
                BTIF_TRACE_DEBUG2("%s: AVRC %s Release Faked earlier, drowned now",
                                  __FUNCTION__, key_map[i].name);
                return;
            }
            send_key(uinput_fd, key_map[i].mapped_id, pressed);
            if ((key_map[i].release_quirk == 1) && (pressed == 1))
            {
                GKI_delay(30); // 30ms
                BTIF_TRACE_DEBUG2("%s: AVRC %s Release quirk enabled, send release now",
                                  __FUNCTION__, key_map[i].name);
                send_key(uinput_fd, key_map[i].mapped_id, 0);
            }
            break;
        }
    }

    if (key_map[i].name == NULL)
        BTIF_TRACE_ERROR3("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
                        p_remote_cmd->rc_id, status);
}
/***************************************************************************
 *  Function       handle_rc_passthrough_cmd
 *
 *  - Argument:    tBTA_AV_RC rc_id   remote control command ID
 *                 tBTA_AV_STATE key_state status of key press
 *
 *  - Description: Remote control command handler
 *
 ***************************************************************************/
void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
{
    const char *status;
    int pressed, i;

    /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */
    if (p_remote_cmd)
    {
        /* queue AVRC PLAY if GAVDTP Open notification to app is pending (2 second timer) */
        if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btif_av_is_connected()))
        {
            if (p_remote_cmd->key_state == AVRC_STATE_PRESS)
            {
                APPL_TRACE_WARNING1("%s: AVDT not open, queuing the PLAY command", __FUNCTION__);
                btif_rc_cb.rc_pending_play = TRUE;
            }
            return;
        }

        if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btif_rc_cb.rc_pending_play))
        {
            APPL_TRACE_WARNING1("%s: Clear the pending PLAY on PAUSE received", __FUNCTION__);
            btif_rc_cb.rc_pending_play = FALSE;
            return;
        }
    }
    if (p_remote_cmd->key_state == AVRC_STATE_RELEASE) {
        status = "released";
        pressed = 0;
    } else {
        status = "pressed";
        pressed = 1;
    }


    for (i = 0; key_map[i].name != NULL; i++) {
        if (p_remote_cmd->rc_id == key_map[i].avrcp) {
            BTIF_TRACE_DEBUG3("%s: %s %s", __FUNCTION__, key_map[i].name, status);

           /* MusicPlayer uses a long_press_timeout of 1 second for PLAYPAUSE button
            * and maps that to autoshuffle. So if for some reason release for PLAY/PAUSE
            * comes 1 second after the press, the MediaPlayer UI goes into a bad state.
            * The reason for the delay could be sniff mode exit or some AVDTP procedure etc.
            * The fix is to generate a release right after the press and drown the 'actual'
            * release.
            */
            if ((key_map[i].release_quirk == 1) && (pressed == 0))
            {
                BTIF_TRACE_DEBUG2("%s: AVRC %s Release Faked earlier, drowned now",
                                  __FUNCTION__, key_map[i].name);
                return;
            }
            send_key(uinput_fd, key_map[i].mapped_id, pressed);
            if ((key_map[i].release_quirk == 1) && (pressed == 1))
            {
                GKI_delay(30); // 30ms
                BTIF_TRACE_DEBUG2("%s: AVRC %s Release quirk enabled, send release now",
                                  __FUNCTION__, key_map[i].name);
                send_key(uinput_fd, key_map[i].mapped_id, 0);
            }
            break;
        }
    }

    if (key_map[i].name == NULL)
        BTIF_TRACE_ERROR3("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
                        p_remote_cmd->rc_id, status);
}
Пример #8
0
/*******************************************************************************
**
** Function         bta_hf_client_sco_event
**
** Description      Handle SCO events
**
**
** Returns          void
**
*******************************************************************************/
static void bta_hf_client_sco_event(UINT8 event)
{
    APPL_TRACE_DEBUG3("%s state: %d event: %d", __FUNCTION__,
                        bta_hf_client_cb.scb.sco_state, event);

    switch (bta_hf_client_cb.scb.sco_state)
    {
        case BTA_HF_CLIENT_SCO_SHUTDOWN_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_LISTEN_E:
                    /* create sco listen connection */
                    bta_hf_client_sco_create(FALSE);
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_LISTEN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_SHUTDOWN_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_LISTEN_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_LISTEN_E:
                    /* create sco listen connection (Additional channel) */
                    bta_hf_client_sco_create(FALSE);
                    break;

                case BTA_HF_CLIENT_SCO_OPEN_E:
                    /* remove listening connection */
                    bta_hf_client_sco_remove(FALSE);

                    /* create sco connection to peer */
                    bta_hf_client_sco_create(TRUE);
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_OPENING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    /* remove listening connection */
                    bta_hf_client_sco_remove(FALSE);

                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTDOWN_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CLOSE_E:
                    /* remove listening connection */
                    /* Ignore the event. We need to keep listening SCO for the active SLC */
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_LISTEN_ST: Ignoring event %d", event);
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    /* sco failed; create sco listen connection */
                    bta_hf_client_sco_create(FALSE);
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_LISTEN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_LISTEN_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_OPENING_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_CLOSE_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_OPEN_CL_ST;
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTTING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_OPEN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_OPEN_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    /* sco failed; create sco listen connection */
                    bta_hf_client_sco_create(FALSE);
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_LISTEN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_OPENING_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_OPEN_CL_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_OPEN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_OPENING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTTING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_OPEN_E:
                    /* close sco connection */
                    bta_hf_client_sco_remove(TRUE);

                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_CLOSING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    /* sco failed; create sco listen connection */

                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_LISTEN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_OPEN_CL_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_OPEN_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_CLOSE_E:
                    /* close sco connection if active */
                    if (bta_hf_client_sco_remove(TRUE))
                    {
                        bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_CLOSING_ST;
                    }
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    /* remove all listening connections */
                    bta_hf_client_sco_remove(FALSE);

                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTTING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    /* peer closed sco; create sco listen connection */
                    bta_hf_client_sco_create(FALSE);
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_LISTEN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_OPEN_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_CLOSING_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_OPEN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_CLOSE_OP_ST;
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTTING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    /* peer closed sco; create sco listen connection */
                    bta_hf_client_sco_create(FALSE);

                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_LISTEN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_CLOSING_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_CLOSE_OP_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_CLOSE_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_CLOSING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTTING_ST;
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    /* open sco connection */
                    bta_hf_client_sco_create(TRUE);
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_OPENING_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_CLOSE_OP_ST: Ignoring event %d", event);
                    break;
            }
            break;

        case BTA_HF_CLIENT_SCO_SHUTTING_ST:
            switch (event)
            {
                case BTA_HF_CLIENT_SCO_CONN_OPEN_E:
                    /* close sco connection; wait for conn close event */
                    bta_hf_client_sco_remove(TRUE);
                    break;

                case BTA_HF_CLIENT_SCO_CONN_CLOSE_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTDOWN_ST;
                    break;

                case BTA_HF_CLIENT_SCO_SHUTDOWN_E:
                    bta_hf_client_cb.scb.sco_state = BTA_HF_CLIENT_SCO_SHUTDOWN_ST;
                    break;

                default:
                    APPL_TRACE_WARNING1("BTA_HF_CLIENT_SCO_SHUTTING_ST: Ignoring event %d", event);
                    break;
            }
            break;

        default:
            break;
    }
}