From: Jakub Pawlowski Date: Sat, 27 Jan 2018 01:18:52 +0000 (-0800) Subject: Report LE CoC credits to GAP clients X-Git-Tag: android-x86-9.0-r1~135^2~1^2^2^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b9c95d5a61;p=android-x86%2Fsystem-bt.git Report LE CoC credits to GAP clients Test: manual with HA Change-Id: Ic4552b05b6e6c7dad5311e0b893da3166bf1895c --- diff --git a/bta/jv/bta_jv_act.cc b/bta/jv/bta_jv_act.cc index 16da349a6..87e5052e5 100644 --- a/bta/jv/bta_jv_act.cc +++ b/bta/jv/bta_jv_act.cc @@ -849,7 +849,8 @@ void bta_jv_delete_record(uint32_t handle) { * Returns void * ******************************************************************************/ -static void bta_jv_l2cap_client_cback(uint16_t gap_handle, uint16_t event) { +static void bta_jv_l2cap_client_cback(uint16_t gap_handle, uint16_t event, + tGAP_CB_DATA* data) { tBTA_JV_L2C_CB* p_cb = &bta_jv_cb.l2c_cb[gap_handle]; tBTA_JV evt_data; @@ -997,7 +998,8 @@ void bta_jv_l2cap_close(uint32_t handle, tBTA_JV_L2C_CB* p_cb) { * Returns void * ******************************************************************************/ -static void bta_jv_l2cap_server_cback(uint16_t gap_handle, uint16_t event) { +static void bta_jv_l2cap_server_cback(uint16_t gap_handle, uint16_t event, + tGAP_CB_DATA* data) { tBTA_JV_L2C_CB* p_cb = &bta_jv_cb.l2c_cb[gap_handle]; tBTA_JV evt_data; tBTA_JV_L2CAP_CBACK* p_cback; diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index 11fd8ffcd..663482f9f 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -93,6 +93,9 @@ static void gap_disconnect_ind(uint16_t l2cap_cid, bool ack_needed); static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg); static void gap_congestion_ind(uint16_t lcid, bool is_congested); static void gap_tx_complete_ind(uint16_t l2cap_cid, uint16_t sdu_sent); +static void gap_credits_received_cb(uint16_t l2cap_cid, + uint16_t credits_received, + uint16_t credit_count); static tGAP_CCB* gap_find_ccb_by_cid(uint16_t cid); static tGAP_CCB* gap_find_ccb_by_handle(uint16_t handle); @@ -123,6 +126,7 @@ void gap_conn_init(void) { conn.reg_info.pL2CA_DataInd_Cb = gap_data_ind; conn.reg_info.pL2CA_CongestionStatus_Cb = gap_congestion_ind; conn.reg_info.pL2CA_TxComplete_Cb = gap_tx_complete_ind; + conn.reg_info.pL2CA_CreditsReceived_Cb = gap_credits_received_cb; } /******************************************************************************* @@ -400,8 +404,9 @@ uint16_t GAP_ConnReadData(uint16_t gap_handle, uint8_t* p_data, mutex_global_unlock(); - DVLOG(1) << StringPrintf("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d", - p_ccb->rx_queue_size, *p_len); + DVLOG(1) << StringPrintf( + "GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d", + p_ccb->rx_queue_size, *p_len); return (BT_PASS); } @@ -432,8 +437,8 @@ int GAP_GetRxQueueCnt(uint16_t handle, uint32_t* p_rx_queue_count) { } else rc = GAP_INVALID_HANDLE; - DVLOG(1) << StringPrintf("GAP_GetRxQueueCnt - rc = 0x%04x, rx_queue_count=%d", rc, - *p_rx_queue_count); + DVLOG(1) << StringPrintf("GAP_GetRxQueueCnt - rc = 0x%04x, rx_queue_count=%d", + rc, *p_rx_queue_count); return (rc); } @@ -681,10 +686,20 @@ void gap_tx_complete_ind(uint16_t l2cap_cid, uint16_t sdu_sent) { if ((p_ccb->con_state == GAP_CCB_STATE_CONNECTED) && (sdu_sent == 0xFFFF)) { DVLOG(1) << StringPrintf("%s: GAP_EVT_TX_EMPTY", __func__); - p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_TX_EMPTY); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_TX_EMPTY, nullptr); } } +void gap_credits_received_cb(uint16_t l2cap_cid, uint16_t credits_received, + uint16_t credit_count) { + tGAP_CCB* p_ccb = gap_find_ccb_by_cid(l2cap_cid); + if (!p_ccb) return; + + tGAP_CB_DATA data{.coc_credits = {.credits_received = credits_received, + .credit_count = credit_count}}; + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_LE_COC_CREDITS, &data); +} + /******************************************************************************* * * Function gap_connect_ind @@ -747,7 +762,7 @@ static void gap_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid, } DVLOG(1) << StringPrintf("GAP_CONN - Rcvd L2CAP conn ind, CID: 0x%x", - p_ccb->connection_id); + p_ccb->connection_id); /* Send a Configuration Request. */ if (p_ccb->transport == BT_TRANSPORT_BR_EDR) @@ -770,7 +785,7 @@ static void gap_checks_con_flags(tGAP_CCB* p_ccb) { if ((p_ccb->con_flags & GAP_CCB_FLAGS_CONN_DONE) == GAP_CCB_FLAGS_CONN_DONE) { p_ccb->con_state = GAP_CCB_STATE_CONNECTED; - p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_OPENED); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_OPENED, nullptr); } } @@ -852,7 +867,7 @@ static void gap_connect_cfm(uint16_t l2cap_cid, uint16_t result) { } else { /* Tell the user if he has a callback */ if (p_ccb->p_callback) - (*p_ccb->p_callback)(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + (*p_ccb->p_callback)(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); gap_release_ccb(p_ccb); } @@ -929,7 +944,7 @@ static void gap_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { gap_checks_con_flags(p_ccb); } else { - p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); gap_release_ccb(p_ccb); } } @@ -955,7 +970,7 @@ static void gap_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) { if (ack_needed) L2CA_DISCONNECT_RSP(l2cap_cid); - p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_CLOSED, nullptr); gap_release_ccb(p_ccb); } @@ -987,7 +1002,7 @@ static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) { p_ccb->rx_queue_size, p_msg->len); */ - p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL); + p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL, nullptr); } else { osi_free(p_msg); } @@ -1003,16 +1018,17 @@ static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) { ******************************************************************************/ static void gap_congestion_ind(uint16_t lcid, bool is_congested) { DVLOG(1) << StringPrintf("GAP_CONN - Rcvd L2CAP Is Congested (%d), CID: 0x%x", - is_congested, lcid); + is_congested, lcid); tGAP_CCB* p_ccb = gap_find_ccb_by_cid(lcid); /* Find CCB based on CID */ if (!p_ccb) return; p_ccb->is_congested = is_congested; - p_ccb->p_callback(p_ccb->gap_handle, (is_congested) - ? GAP_EVT_CONN_CONGESTED - : GAP_EVT_CONN_UNCONGESTED); + p_ccb->p_callback( + p_ccb->gap_handle, + (is_congested) ? GAP_EVT_CONN_CONGESTED : GAP_EVT_CONN_UNCONGESTED, + nullptr); gap_try_write_queued_data(p_ccb); } @@ -1128,7 +1144,7 @@ static void gap_release_ccb(tGAP_CCB* p_ccb) { if ((p_ccb_local->con_state != GAP_CCB_STATE_IDLE) && (p_ccb_local->psm == p_ccb->psm)) { DVLOG(1) << __func__ << " : " << +p_ccb_local->psm - << " PSM is still in use, do not deregister"; + << " PSM is still in use, do not deregister"; return; } } diff --git a/stack/include/gap_api.h b/stack/include/gap_api.h index 11e49aed6..9293378f2 100644 --- a/stack/include/gap_api.h +++ b/stack/include/gap_api.h @@ -77,6 +77,7 @@ #define GAP_EVT_CONN_CONGESTED 0x0103 #define GAP_EVT_CONN_UNCONGESTED 0x0104 #define GAP_EVT_TX_EMPTY 0x0105 +#define GAP_EVT_LE_COC_CREDITS 0x0106 /* Values for 'chan_mode_mask' field */ /* GAP_ConnOpen() - optional channels to negotiate */ @@ -105,13 +106,24 @@ #define GAP_PREFER_CONN_SP_TOUT 2000 #endif +struct tGAP_COC_CREDITS { + uint16_t gap_handle; + uint16_t credits_received; + uint16_t credit_count; +}; + +union tGAP_CB_DATA { + tGAP_COC_CREDITS coc_credits; +}; + /***************************************************************************** * Type Definitions ****************************************************************************/ /* * Callback function for connection services */ -typedef void(tGAP_CONN_CALLBACK)(uint16_t gap_handle, uint16_t event); +typedef void(tGAP_CONN_CALLBACK)(uint16_t gap_handle, uint16_t event, + tGAP_CB_DATA* data); /* * Define the callback function prototypes. Parameters are specific