/******************************************************************************* ** ** Function rw_main_reset_stats ** ** Description Reset counters for statistics ** ** Returns void ** *******************************************************************************/ void rw_main_reset_stats (void) { memset (&rw_cb.stats, 0, sizeof (tRW_STATS)); /* Get current tick count */ rw_cb.stats.start_tick = GKI_get_tick_count (); }
/******************************************************************************* ** ** Function nfa_sys_ptim_timer_update ** ** Description Update the protocol timer list and handle expired timers. ** This function is called from the task running the protocol ** timers when the periodic GKI timer expires. ** ** Returns void ** *******************************************************************************/ void nfa_sys_ptim_timer_update (tPTIM_CB *p_cb) { TIMER_LIST_ENT *p_tle; BT_HDR *p_msg; UINT32 new_ticks_count; INT32 period_in_ticks; /* To handle the case when the function is called less frequently than the period we must convert determine the number of ticks since the last update, then convert back to milliseconds before updating timer list */ new_ticks_count = GKI_get_tick_count (); /* Check for wrapped condition */ if (new_ticks_count >= p_cb->last_gki_ticks) { period_in_ticks = (INT32) (new_ticks_count - p_cb->last_gki_ticks); } else { period_in_ticks = (INT32) (((UINT32) 0xffffffff - p_cb->last_gki_ticks) + new_ticks_count + 1); } /* update timer list */ GKI_update_timer_list (&p_cb->timer_queue, GKI_TICKS_TO_MS (period_in_ticks)); p_cb->last_gki_ticks = new_ticks_count; /* while there are expired timers */ while ((p_cb->timer_queue.p_first) && (p_cb->timer_queue.p_first->ticks <= 0)) { /* removed expired timer from list */ p_tle = p_cb->timer_queue.p_first; NFA_TRACE_DEBUG1 ("nfa_sys_ptim_timer_update expired: %08x", p_tle); GKI_remove_from_timer_list (&p_cb->timer_queue, p_tle); /* call timer callback */ if (p_tle->p_cback) { (*p_tle->p_cback) (p_tle); } else if (p_tle->event) { if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL) { p_msg->event = p_tle->event; p_msg->layer_specific = 0; nfa_sys_sendmsg (p_msg); } } } /* if timer list is empty stop periodic GKI timer */ if (p_cb->timer_queue.p_first == NULL) { NFA_TRACE_DEBUG0 ("ptim timer stop"); GKI_stop_timer (p_cb->timer_id); } }
/******************************************************************************* ** ** Function rw_main_log_stats ** ** Description Dump stats ** ** Returns void ** *******************************************************************************/ void rw_main_log_stats (void) { UINT32 ticks, elapsed_ms; ticks = GKI_get_tick_count () - rw_cb.stats.start_tick; elapsed_ms = GKI_TICKS_TO_MS (ticks); RW_TRACE_DEBUG5 ("NFC tx stats: cmds:%i, retries:%i, aborted: %i, tx_errs: %i, bytes sent:%i", rw_cb.stats.num_ops, rw_cb.stats.num_retries, rw_cb.stats.num_fail, rw_cb.stats.num_trans_err, rw_cb.stats.bytes_sent); RW_TRACE_DEBUG2 (" rx stats: rx-crc errors %i, bytes received: %i", rw_cb.stats.num_crc, rw_cb.stats.bytes_received); RW_TRACE_DEBUG1 (" time activated %i ms", elapsed_ms); }
/******************************************************************************* ** ** Function ptim_start_timer ** ** Description Start a protocol timer for the specified amount ** of time in seconds. ** ** Returns void ** *******************************************************************************/ void ptim_start_timer(tPTIM_CB *p_cb, TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout) { /* if timer list is currently empty, start periodic GKI timer */ if (p_cb->timer_queue.p_first == NULL) { p_cb->last_gki_ticks = GKI_get_tick_count(); GKI_start_timer(p_cb->timer_id, GKI_MS_TO_TICKS(p_cb->period), TRUE); } GKI_remove_from_timer_list(&p_cb->timer_queue, p_tle); p_tle->event = type; p_tle->ticks = timeout; p_tle->ticks_initial = timeout; GKI_add_to_timer_list(&p_cb->timer_queue, p_tle); }
/******************************************************************************* ** ** Function RFCOMM_ConnectInd ** ** Description This is a callback function called by L2CAP when ** L2CA_ConnectInd received. Allocate multiplexer control block ** and dispatch the event to it. ** *******************************************************************************/ void RFCOMM_ConnectInd (BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) { tRFC_MCB *p_mcb = rfc_alloc_multiplexer_channel(bd_addr, FALSE); UNUSED(psm); if ((p_mcb)&&(p_mcb->state != RFC_MX_STATE_IDLE)) { /* if this is collision case */ if ((p_mcb->is_initiator)&&(p_mcb->state == RFC_MX_STATE_WAIT_CONN_CNF)) { p_mcb->pending_lcid = lcid; p_mcb->pending_id = id; /* wait random timeout (2 - 12) to resolve collision */ /* if peer gives up then local device rejects incoming connection and continues as initiator */ /* if timeout, local device disconnects outgoing connection and continues as acceptor */ RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectInd start timer for collision, initiator's LCID(0x%x), acceptor's LCID(0x%x)", p_mcb->lcid, p_mcb->pending_lcid); rfc_timer_start(p_mcb, (UINT16)(GKI_get_tick_count()%10 + 2)); return; } else { /* we cannot accept connection request from peer at this state */ /* don't update lcid */ p_mcb = NULL; } } else { /* store mcb even if null */ rfc_save_lcid_mcb (p_mcb, lcid); } if (p_mcb == NULL) { L2CA_ConnectRsp (bd_addr, id, lcid, L2CAP_CONN_NO_RESOURCES, 0); return; } p_mcb->lcid = lcid; rfc_mx_sm_execute (p_mcb, RFC_MX_EVENT_CONN_IND, &id); }
/******************************************************************************* ** ** Function nfa_sys_ptim_start_timer ** ** Description Start a protocol timer for the specified amount ** of time in seconds. ** ** Returns void ** *******************************************************************************/ void nfa_sys_ptim_start_timer (tPTIM_CB *p_cb, TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout) { NFA_TRACE_DEBUG1 ("nfa_sys_ptim_start_timer %08x", p_tle); /* if timer list is currently empty, start periodic GKI timer */ if (p_cb->timer_queue.p_first == NULL) { NFA_TRACE_DEBUG0 ("ptim timer start"); p_cb->last_gki_ticks = GKI_get_tick_count (); GKI_start_timer (p_cb->timer_id, GKI_MS_TO_TICKS (p_cb->period), TRUE); } GKI_remove_from_timer_list (&p_cb->timer_queue, p_tle); p_tle->event = type; p_tle->ticks = timeout; GKI_add_to_timer_list (&p_cb->timer_queue, p_tle); }