diff options
author | Pavlin Radoslavov <pavlin@google.com> | 2015-09-18 10:51:31 -0700 |
---|---|---|
committer | Scott James Remnant <keybuk@google.com> | 2015-10-19 10:36:20 -0700 |
commit | 2e3d006b96eafb0651fe7f78d28250faf89405de (patch) | |
tree | 096eb08052260cac8fcfd6cf9f91691493e18749 | |
parent | 6b24485cec18ea111b05bc23f61d9c3f6a6b8747 (diff) | |
download | bt-2e3d006b96eafb0651fe7f78d28250faf89405de.tar.gz |
GKI cleanup - Eliminate usage of pool buffers
* Replace usage of function GKI_getpoolbuf() with GKI_getbuf()
* Remove usage of function GKI_poolutilization()
* Remove usage of function GKI_poolfreecount()
Change-Id: Ide938192b878bbfb4912642c903fce548f2b5368
33 files changed, 226 insertions, 249 deletions
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c index a7e3679ca..843afe610 100644 --- a/bta/dm/bta_dm_act.c +++ b/bta/dm/bta_dm_act.c @@ -3782,7 +3782,6 @@ static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result) *******************************************************************************/ static void bta_dm_set_eir (char *local_name) { - BT_HDR *p_buf; UINT8 *p; UINT8 *p_length; #if (BTA_EIR_CANNED_UUID_LIST != TRUE) @@ -3821,7 +3820,8 @@ static void bta_dm_set_eir (char *local_name) #endif // BTA_EIR_CANNED_UUID_LIST /* Allocate a buffer to hold HCI command */ - if ((p_buf = (BT_HDR *)GKI_getpoolbuf(BTM_CMD_POOL_ID)) == NULL) + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BTM_CMD_BUF_SIZE); + if (p_buf == NULL) { APPL_TRACE_ERROR("bta_dm_set_eir couldn't allocate buffer"); return; diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c index 6a4b9bf18..fa49793b7 100644 --- a/bta/gatt/bta_gattc_cache.c +++ b/bta/gatt/bta_gattc_cache.c @@ -140,9 +140,9 @@ static void bta_gattc_display_explore_record(tBTA_GATTC_ATTR_REC *p_rec, UINT8 n *******************************************************************************/ BT_HDR *bta_gattc_alloc_cache_buf(tBTA_GATTC_SERV *p_srvc_cb) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(GATT_DB_BUF_SIZE); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_DB_POOL_ID)) == NULL) + if (p_buf == NULL) { APPL_TRACE_DEBUG("No resources: GKI buffer allocation failed."); utl_freebuf((void **)&p_srvc_cb->p_srvc_list); diff --git a/bta/hl/bta_hl_utils.c b/bta/hl/bta_hl_utils.c index 3fa142b91..e12b4b15d 100644 --- a/bta/hl/bta_hl_utils.c +++ b/bta/hl/bta_hl_utils.c @@ -299,15 +299,10 @@ BT_HDR * bta_hl_get_buf(UINT16 data_size) BT_HDR *p_new; UINT16 size = data_size + L2CAP_MIN_OFFSET + BT_HDR_SIZE; - if (size < GKI_MAX_BUF_SIZE) - { - p_new = (BT_HDR *)GKI_getbuf(size); - } - else - { - p_new = (BT_HDR *) GKI_getpoolbuf(BTA_HL_LRG_DATA_POOL_ID); - } + if (size >= GKI_MAX_BUF_SIZE) + size = BTA_HL_LRG_DATA_BUF_SIZE; + p_new = (BT_HDR *)GKI_getbuf(size); if (p_new) { p_new->len = data_size; diff --git a/bta/include/bta_pan_ci.h b/bta/include/bta_pan_ci.h index 4f314fd74..385659d35 100644 --- a/bta/include/bta_pan_ci.h +++ b/bta/include/bta_pan_ci.h @@ -89,7 +89,7 @@ extern void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable); ** the RX path is configured to use a push interface with ** zero copy. The function sends an event to PAN containing ** the data buffer. The buffer must be allocated using -** functions GKI_getbuf() or GKI_getpoolbuf(). The buffer +** functions GKI_getbuf(). The buffer ** will be freed by BTA; the phone must not free the buffer. ** ** diff --git a/bta/pan/bta_pan_act.c b/bta/pan/bta_pan_act.c index d4bd1c17d..0b2a88898 100644 --- a/bta/pan/bta_pan_act.c +++ b/bta/pan/bta_pan_act.c @@ -207,10 +207,10 @@ static void bta_pan_data_buf_ind_cback(UINT16 handle, BD_ADDR src, BD_ADDR dst, if ( sizeof(tBTA_PAN_DATA_PARAMS) > p_buf->offset ) { /* offset smaller than data structure in front of actual data */ - p_new_buf = (BT_HDR *)GKI_getpoolbuf( PAN_POOL_ID ); + p_new_buf = (BT_HDR *)GKI_getbuf(PAN_BUF_SIZE); if(!p_new_buf) { - APPL_TRACE_WARNING("Cannot get a PAN GKI buffer"); + APPL_TRACE_WARNING("Cannot get a PAN buffer"); GKI_freebuf( p_buf ); return; } diff --git a/bta/pan/bta_pan_ci.c b/bta/pan/bta_pan_ci.c index 653c6436c..57c81bb7e 100644 --- a/bta/pan/bta_pan_ci.c +++ b/bta/pan/bta_pan_ci.c @@ -129,12 +129,10 @@ void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable) void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol, UINT8 *p_data, UINT16 len, BOOLEAN ext) { - BT_HDR * p_buf; + BT_HDR * p_buf = (BT_HDR *) GKI_getbuf(PAN_BUF_SIZE); - if((p_buf = (BT_HDR *) GKI_getpoolbuf(PAN_POOL_ID)) != NULL) + if (p_buf != NULL) { - - p_buf->offset = PAN_MINIMUM_OFFSET; /* copy all other params before the data */ @@ -162,7 +160,7 @@ void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protoco ** the RX path is configured to use a push interface with ** zero copy. The function sends an event to PAN containing ** the data buffer. The buffer must be allocated using -** functions GKI_getbuf() or GKI_getpoolbuf(). The buffer +** functions GKI_getbuf(). The buffer ** will be freed by BTA; the phone must not free the buffer. ** ** diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c index 5fb669c5f..ac3d51f3b 100644 --- a/btif/src/btif_hl.c +++ b/btif/src/btif_hl.c @@ -410,7 +410,7 @@ void * btif_hl_get_buf(UINT16 size) else { BTIF_TRACE_DEBUG("btif_hl_get_buf use HL large data pool"); - p_new = GKI_getpoolbuf(4); + p_new = GKI_getbuf(GKI_BUF4_SIZE); } return p_new; diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index 9c18365c5..8a6a5ceab 100644 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -2511,7 +2511,8 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame) while (nb_frame) { - if (NULL == (p_buf = GKI_getpoolbuf(BTIF_MEDIA_AA_POOL_ID))) + p_buf = GKI_getbuf(BTIF_MEDIA_AA_BUF_SIZE); + if (p_buf == NULL) { APPL_TRACE_ERROR ("ERROR btif_media_aa_prep_sbc_2_send no buffer TxCnt %d ", GKI_queue_length(&btif_media_cb.TxAaQ)); diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c index 13ada4e4b..91680dd18 100644 --- a/btif/src/btif_pan.c +++ b/btif/src/btif_pan.c @@ -671,7 +671,7 @@ static void btu_exec_tap_fd_read(void *p_param) { // give other profiles a chance to run by limiting the amount of memory // PAN can use from the shared pool buffer. for (int i = 0; i < PAN_POOL_MAX && btif_is_enabled() && btpan_cb.flow; i++) { - BT_HDR *buffer = (BT_HDR *)GKI_getpoolbuf(PAN_POOL_ID); + BT_HDR *buffer = (BT_HDR *)GKI_getbuf(PAN_BUF_SIZE); if (!buffer) { BTIF_TRACE_WARNING("%s unable to allocate buffer for packet.", __func__); break; diff --git a/gki/common/gki.h b/gki/common/gki.h index e6800620c..61d3afa6f 100644 --- a/gki/common/gki.h +++ b/gki/common/gki.h @@ -66,10 +66,7 @@ typedef struct void GKI_freebuf (void *); void *GKI_getbuf (UINT16); UINT16 GKI_get_buf_size (void *); -void *GKI_getpoolbuf (UINT8); UINT16 GKI_poolcount (UINT8); -UINT16 GKI_poolfreecount (UINT8); -UINT16 GKI_poolutilization (UINT8); /* User buffer queue management diff --git a/gki/common/gki_buffer.c b/gki/common/gki_buffer.c index 633b2223a..e27ac4d25 100644 --- a/gki/common/gki_buffer.c +++ b/gki/common/gki_buffer.c @@ -212,26 +212,6 @@ void *GKI_getbuf (UINT16 size) /******************************************************************************* ** -** Function GKI_getpoolbuf -** -** Description Called by an application to get a free buffer from -** a specific buffer pool. -** -** Note: If there are no more buffers available from the pool, -** the public buffers are searched for an available buffer. -** -** Parameters pool_id - (input) pool ID to get a buffer out of. -** -** Returns A pointer to the buffer, or NULL if none available -** -*******************************************************************************/ -void *GKI_getpoolbuf (UINT8 pool_id) -{ - return GKI_getbuf(gki_cb.com.pool_size[pool_id]); -} - -/******************************************************************************* -** ** Function GKI_freebuf ** ** Description Called by an application to return a buffer to the free pool. @@ -499,30 +479,6 @@ UINT16 GKI_poolcount (UINT8 pool_id) /******************************************************************************* ** -** Function GKI_poolfreecount -** -** Description Called by an application to get the number of free buffers -** in the specified buffer pool. -** -** Parameters pool_id - (input) pool ID to get the free count of. -** -** Returns the number of free buffers in the pool -** -*******************************************************************************/ -UINT16 GKI_poolfreecount (UINT8 pool_id) -{ - FREE_QUEUE_T *Q; - - if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS) - return (0); - - Q = &gki_cb.com.freeq[pool_id]; - - return ((UINT16)(Q->total - Q->cur_cnt)); -} - -/******************************************************************************* -** ** Function GKI_get_pool_bufsize ** ** Description Called by an application to get the size of buffers in a pool @@ -539,30 +495,3 @@ UINT16 GKI_get_pool_bufsize (UINT8 pool_id) return (0); } - -/******************************************************************************* -** -** Function GKI_poolutilization -** -** Description Called by an application to get the buffer utilization -** in the specified buffer pool. -** -** Parameters pool_id - (input) pool ID to get the free count of. -** -** Returns % of buffers used from 0 to 100 -** -*******************************************************************************/ -UINT16 GKI_poolutilization (UINT8 pool_id) -{ - FREE_QUEUE_T *Q; - - if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS) - return (100); - - Q = &gki_cb.com.freeq[pool_id]; - - if (Q->total == 0) - return (100); - - return ((Q->cur_cnt * 100) / Q->total); -} diff --git a/include/bt_target.h b/include/bt_target.h index 57ff43d2c..6b369dfe6 100644 --- a/include/bt_target.h +++ b/include/bt_target.h @@ -197,7 +197,7 @@ #define HCI_CMD_POOL_BUF_SIZE GKI_BUF2_SIZE #endif -/* Receives ACL data packets from thelower-layer. */ +/* Receives ACL data packets from the lower-layer. */ #ifndef HCI_ACL_POOL_ID #define HCI_ACL_POOL_ID GKI_POOL_ID_3 #endif @@ -213,16 +213,28 @@ #endif /* Sends SDP data packets. */ +#ifndef SDP_DATA_BUF_SIZE +#define SDP_DATA_BUF_SIZE (4096+16) +#endif + #ifndef SDP_POOL_ID #define SDP_POOL_ID 3 #endif /* Sends RFCOMM command packets. */ +#ifndef RFCOMM_CMD_BUF_SIZE +#define RFCOMM_CMD_BUF_SIZE 660 +#endif + #ifndef RFCOMM_CMD_POOL_ID #define RFCOMM_CMD_POOL_ID GKI_POOL_ID_2 #endif /* Sends RFCOMM data packets. */ +#ifndef RFCOMM_DATA_BUF_SIZE +#define RFCOMM_DATA_BUF_SIZE (4096+16) +#endif + #ifndef RFCOMM_DATA_POOL_ID #define RFCOMM_DATA_POOL_ID GKI_POOL_ID_3 #endif @@ -232,6 +244,10 @@ #endif /* Sends L2CAP packets to the peer and HCI messages to the controller. */ +#ifndef L2CAP_CMD_BUF_SIZE +#define L2CAP_CMD_BUF_SIZE 660 +#endif + #ifndef L2CAP_CMD_POOL_ID #define L2CAP_CMD_POOL_ID GKI_POOL_ID_2 #endif @@ -246,6 +262,10 @@ #define L2CAP_FCR_RX_POOL_ID HCI_ACL_POOL_ID #endif +#ifndef L2CAP_FCR_ERTM_BUF_SIZE +#define L2CAP_FCR_ERTM_BUF_SIZE (10240 + 24) +#endif + /* Number of ACL buffers to assign to LE if the HCI buffer pool is shared with BR/EDR */ #ifndef L2C_DEF_NUM_BLE_BUF_SHARED @@ -253,6 +273,10 @@ #endif /* Used by BTM when it sends HCI commands to the controller. */ +#ifndef BTM_CMD_BUF_SIZE +#define BTM_CMD_BUF_SIZE 660 +#endif + #ifndef BTM_CMD_POOL_ID #define BTM_CMD_POOL_ID GKI_POOL_ID_2 #endif @@ -264,7 +288,12 @@ #ifndef OBX_LRG_DATA_POOL_ID #define OBX_LRG_DATA_POOL_ID GKI_POOL_ID_4 #endif + /* Used to send data to L2CAP. */ +#ifndef GAP_DATA_BUF_SIZE +#define GAP_DATA_BUF_SIZE (4096+16) +#endif + #ifndef GAP_DATA_POOL_ID #define GAP_DATA_POOL_ID GKI_POOL_ID_3 #endif @@ -274,6 +303,10 @@ #endif /* BNEP data and protocol messages. */ +#ifndef BNEP_BUF_SIZE +#define BNEP_BUF_SIZE (4096+16) +#endif + #ifndef BNEP_POOL_ID #define BNEP_POOL_ID GKI_POOL_ID_3 #endif @@ -283,6 +316,11 @@ #define RPC_SCRATCH_POOL_ID GKI_POOL_ID_2 #endif +/* AVDTP buffer size for protocol messages */ +#ifndef AVDT_CMD_BUF_SIZE +#define AVDT_CMD_BUF_SIZE 660 +#endif + /* AVDTP pool for protocol messages */ #ifndef AVDT_CMD_POOL_ID #define AVDT_CMD_POOL_ID GKI_POOL_ID_2 @@ -293,17 +331,31 @@ #define AVDT_DATA_POOL_SIZE GKI_BUF3_SIZE #endif +#ifndef PAN_BUF_SIZE +#define PAN_BUF_SIZE (4096+16) +#endif + #ifndef PAN_POOL_ID #define PAN_POOL_ID GKI_POOL_ID_3 /* Maximum amount of the shared buffer to allocate for PAN */ #define PAN_POOL_MAX (GKI_BUF3_MAX / 4) #endif +/* AVCTP buffer size for protocol messages */ +#ifndef AVCT_CMD_BUF_SIZE +#define AVCT_CMD_BUF_SIZE 288 +#endif + /* AVCTP pool for protocol messages */ #ifndef AVCT_CMD_POOL_ID #define AVCT_CMD_POOL_ID GKI_POOL_ID_1 #endif +/* AVRCP buffer size for protocol messages */ +#ifndef AVRC_CMD_BUF_SIZE +#define AVRC_CMD_BUF_SIZE 288 +#endif + /* AVRCP pool for protocol messages */ #ifndef AVRC_CMD_POOL_ID #define AVRC_CMD_POOL_ID GKI_POOL_ID_1 @@ -314,6 +366,11 @@ #define AVRC_CMD_POOL_SIZE GKI_BUF1_SIZE #endif +/* AVRCP Metadata buffer size for protocol messages */ +#ifndef AVRC_META_CMD_BUF_SIZE +#define AVRC_META_CMD_BUF_SIZE 660 +#endif + /* AVRCP Metadata pool for protocol messages */ #ifndef AVRC_META_CMD_POOL_ID #define AVRC_META_CMD_POOL_ID GKI_POOL_ID_2 @@ -330,15 +387,29 @@ #define AVRC_BROWSE_POOL_SIZE GKI_MAX_BUF_SIZE #endif +#ifndef BTA_HL_LRG_DATA_BUF_SIZE +#define BTA_HL_LRG_DATA_BUF_SIZE (10240 + 24) +#endif + #ifndef BTA_HL_LRG_DATA_POOL_ID #define BTA_HL_LRG_DATA_POOL_ID GKI_POOL_ID_7 #endif +/* GATT Server Database buffer size */ +#ifndef GATT_DB_BUF_SIZE +#define GATT_DB_BUF_SIZE 128 +#endif + /* GATT Server Database pool ID */ #ifndef GATT_DB_POOL_ID #define GATT_DB_POOL_ID GKI_POOL_ID_8 #endif +/* GATT Data sending buffer size, use default ACL pool for fix channel data */ +#ifndef GATT_DATA_BUF_SIZE +#define GATT_DATA_BUF_SIZE (4096+16) +#endif + /* GATT Data sending buffer pool ID, use default ACL pool for fix channel data */ #ifndef GATT_BUF_POOL_ID #define GATT_BUF_POOL_ID HCI_ACL_POOL_ID @@ -354,7 +425,7 @@ #ifndef HCI_GET_CMD_BUF #if (!defined(HCI_USE_VARIABLE_SIZE_CMD_BUF) || (HCI_USE_VARIABLE_SIZE_CMD_BUF == FALSE)) /* Allocate fixed-size buffer from HCI_CMD_POOL (default case) */ -#define HCI_GET_CMD_BUF(paramlen) ((BT_HDR *)GKI_getpoolbuf (HCI_CMD_POOL_ID)) +#define HCI_GET_CMD_BUF(paramlen) ((BT_HDR *)GKI_getbuf (HCI_CMD_POOL_BUF_SIZE)) #else /* Allocate smallest possible buffer (for platforms with limited RAM) */ #define HCI_GET_CMD_BUF(paramlen) ((BT_HDR *)GKI_getbuf ((UINT16)(BT_HDR_SIZE + HCIC_PREAMBLE_SIZE + (paramlen)))) @@ -1444,10 +1515,18 @@ Range: 2 octets #define HID_DEV_SUBCLASS COD_MINOR_POINTING #endif +#ifndef HID_CONTROL_BUF_SIZE +#define HID_CONTROL_BUF_SIZE (4096+16) +#endif + #ifndef HID_CONTROL_POOL_ID #define HID_CONTROL_POOL_ID 2 #endif +#ifndef HID_INTERRUPT_BUF_SIZE +#define HID_INTERRUPT_BUF_SIZE (4096+16) +#endif + #ifndef HID_INTERRUPT_POOL_ID #define HID_INTERRUPT_POOL_ID 2 #endif diff --git a/stack/avct/avct_lcb_act.c b/stack/avct/avct_lcb_act.c index 589af0bdf..2d9c6b95e 100644 --- a/stack/avct/avct_lcb_act.c +++ b/stack/avct/avct_lcb_act.c @@ -675,7 +675,6 @@ void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) UINT8 label, type, cr_ipid; UINT16 pid; tAVCT_CCB *p_ccb; - BT_HDR *p_buf; /* this p_buf is to be reported through p_msg_cback. The layer_specific * needs to be set properly to indicate that it is received through @@ -720,7 +719,8 @@ void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) /* if command send reject */ if (cr_ipid == AVCT_CMD) { - if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVCT_CMD_POOL_ID)) != NULL) + BT_HDR *p_buf = (BT_HDR *) GKI_getbuf(AVCT_CMD_BUF_SIZE); + if (p_buf != NULL) { p_buf->len = AVCT_HDR_LEN_SINGLE; p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; diff --git a/stack/avdt/avdt_ccb_act.c b/stack/avdt/avdt_ccb_act.c index 4dd9b239b..1f4006542 100644 --- a/stack/avdt/avdt_ccb_act.c +++ b/stack/avdt/avdt_ccb_act.c @@ -819,7 +819,8 @@ void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) if ((!p_ccb->cong) && (p_ccb->p_curr_msg == NULL) && (p_ccb->p_curr_cmd != NULL)) { /* make copy of message in p_curr_cmd and send it */ - if ((p_msg = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) != NULL) + p_msg = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); + if (p_msg != NULL) { memcpy(p_msg, p_ccb->p_curr_cmd, (sizeof(BT_HDR) + p_ccb->p_curr_cmd->offset + p_ccb->p_curr_cmd->len)); @@ -856,7 +857,8 @@ void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data) if ((p_msg = (BT_HDR *) GKI_dequeue(&p_ccb->cmd_q)) != NULL) { /* make a copy of buffer in p_curr_cmd */ - if ((p_ccb->p_curr_cmd = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) != NULL) + p_ccb->p_curr_cmd = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); + if (p_ccb->p_curr_cmd != NULL) { memcpy(p_ccb->p_curr_cmd, p_msg, (sizeof(BT_HDR) + p_msg->offset + p_msg->len)); diff --git a/stack/avdt/avdt_msg.c b/stack/avdt/avdt_msg.c index 1bf6b7f66..9680ad4a6 100644 --- a/stack/avdt/avdt_msg.c +++ b/stack/avdt/avdt_msg.c @@ -1243,7 +1243,8 @@ BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg) (p_tbl->peer_mtu - 1) + 2; /* get a new buffer for fragment we are sending */ - if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); + if (p_buf == NULL) { /* do we even want to try and recover from this? could do so by setting retransmission timer */ @@ -1264,7 +1265,8 @@ BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg) hdr_len = AVDT_LEN_TYPE_CONT; /* get a new buffer for fragment we are sending */ - if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); + if (p_buf == NULL) { /* do we even want to try and recover from this? could do so by setting retransmission timer */ @@ -1481,7 +1483,7 @@ void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p UINT8 *p_start; /* get a buffer */ - p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID); + p_buf = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); if (p_buf == NULL) { AVDT_TRACE_ERROR("avdt_msg_send_cmd out of buffer!!"); @@ -1550,7 +1552,7 @@ void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params) UINT8 *p_start; /* get a buffer */ - p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID); + p_buf = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); if (p_buf == NULL) return; /* set up gki buf pointer and offset */ @@ -1595,7 +1597,7 @@ void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params) UINT8 *p_start; /* get a buffer */ - p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID); + p_buf = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); if (p_buf == NULL) return; /* set up gki buf pointer and offset */ @@ -1656,7 +1658,7 @@ void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params) UINT8 *p_start; /* get a buffer */ - p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID); + p_buf = (BT_HDR *) GKI_getbuf(AVDT_CMD_BUF_SIZE); if (p_buf == NULL) return; /* set up gki buf pointer and offset */ diff --git a/stack/avrc/avrc_api.c b/stack/avrc/avrc_api.c index 70b6f3897..adf966d53 100755 --- a/stack/avrc/avrc_api.c +++ b/stack/avrc/avrc_api.c @@ -831,17 +831,16 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, ******************************************************************************/ static BT_HDR * avrc_pass_msg(tAVRC_MSG_PASS *p_msg) { - BT_HDR *p_cmd = NULL; - UINT8 *p_data; - assert(p_msg != NULL); assert(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->pass_len)); - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) + BT_HDR *p_cmd = (BT_HDR *) GKI_getbuf(AVRC_CMD_BUF_SIZE); + if (p_cmd != NULL) { p_cmd->offset = AVCT_MSG_OFFSET; p_cmd->layer_specific = AVCT_DATA_CTRL; - p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; + + UINT8 *p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK); *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); /* Panel subunit & id=0 */ *p_data++ = AVRC_OP_PASS_THRU; diff --git a/stack/avrc/avrc_opt.c b/stack/avrc/avrc_opt.c index 28a3f1afc..6f4f28cde 100644 --- a/stack/avrc/avrc_opt.c +++ b/stack/avrc/avrc_opt.c @@ -52,12 +52,13 @@ static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) assert(p_msg != NULL); #if AVRC_METADATA_INCLUDED == TRUE - assert(AVRC_META_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_META_CMD_POOL_ID)) != NULL) + assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); + p_cmd = (BT_HDR *) GKI_getbuf(AVRC_META_CMD_BUF_SIZE); #else - assert(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) + assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len)); + p_cmd = (BT_HDR *) GKI_getbuf(AVRC_CMD_BUF_SIZE); #endif + if (p_cmd != NULL) { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; @@ -98,10 +99,10 @@ static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) ******************************************************************************/ UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label) { - BT_HDR *p_cmd; + BT_HDR *p_cmd = (BT_HDR *) GKI_getbuf(AVRC_CMD_BUF_SIZE); UINT8 *p_data; - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) + if (p_cmd != NULL) { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; @@ -143,10 +144,10 @@ UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label) ******************************************************************************/ UINT16 AVRC_SubCmd(UINT8 handle, UINT8 label, UINT8 page) { - BT_HDR *p_cmd; + BT_HDR *p_cmd = (BT_HDR *) GKI_getbuf(AVRC_CMD_BUF_SIZE); UINT8 *p_data; - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) + if (p_cmd != NULL) { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; diff --git a/stack/bnep/bnep_api.c b/stack/bnep/bnep_api.c index 76bffca50..a62702839 100644 --- a/stack/bnep/bnep_api.c +++ b/stack/bnep/bnep_api.c @@ -535,8 +535,9 @@ tBNEP_RESULT BNEP_Write (UINT16 handle, if (GKI_queue_length(&p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) return (BNEP_Q_SIZE_EXCEEDED); - /* Get a buffer to copy teh data into */ - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + /* Get a buffer to copy the data into */ + p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP_Write() not able to get buffer"); return (BNEP_NO_RESOURCES); diff --git a/stack/bnep/bnep_utils.c b/stack/bnep/bnep_utils.c index 0cf3b3fae..0115c1acd 100644 --- a/stack/bnep/bnep_utils.c +++ b/stack/bnep/bnep_utils.c @@ -171,12 +171,12 @@ void bnepu_release_bcb (tBNEP_CONN *p_bcb) *******************************************************************************/ void bnep_send_conn_req (tBNEP_CONN *p_bcb) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p, *p_start; BNEP_TRACE_DEBUG ("%s: sending setup req with dst uuid %x", __func__, p_bcb->dst_uuid.uu.uuid16); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("%s: not able to send connection request", __func__); return; @@ -233,11 +233,11 @@ void bnep_send_conn_req (tBNEP_CONN *p_bcb) *******************************************************************************/ void bnep_send_conn_responce (tBNEP_CONN *p_bcb, UINT16 resp_code) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p; BNEP_TRACE_EVENT ("BNEP - bnep_send_conn_responce for CID: 0x%x", p_bcb->l2cap_cid); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP - not able to send connection response"); return; @@ -272,13 +272,13 @@ void bnep_send_conn_responce (tBNEP_CONN *p_bcb, UINT16 resp_code) *******************************************************************************/ void bnepu_send_peer_our_filters (tBNEP_CONN *p_bcb) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p; UINT16 xx; BNEP_TRACE_DEBUG ("BNEP sending peer our filters"); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP - no buffer send filters"); return; @@ -322,13 +322,13 @@ void bnepu_send_peer_our_filters (tBNEP_CONN *p_bcb) *******************************************************************************/ void bnepu_send_peer_our_multi_filters (tBNEP_CONN *p_bcb) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p; UINT16 xx; BNEP_TRACE_DEBUG ("BNEP sending peer our multicast filters"); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP - no buffer to send multicast filters"); return; @@ -374,11 +374,11 @@ void bnepu_send_peer_our_multi_filters (tBNEP_CONN *p_bcb) *******************************************************************************/ void bnepu_send_peer_filter_rsp (tBNEP_CONN *p_bcb, UINT16 response_code) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p; BNEP_TRACE_DEBUG ("BNEP sending filter response"); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP - no buffer filter rsp"); return; @@ -412,11 +412,11 @@ void bnepu_send_peer_filter_rsp (tBNEP_CONN *p_bcb, UINT16 response_code) *******************************************************************************/ void bnep_send_command_not_understood (tBNEP_CONN *p_bcb, UINT8 cmd_code) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p; BNEP_TRACE_EVENT ("BNEP - bnep_send_command_not_understood for CID: 0x%x, cmd 0x%x", p_bcb->l2cap_cid, cmd_code); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP - not able to send connection response"); return; @@ -1151,11 +1151,11 @@ void bnepu_process_peer_multicast_filter_set (tBNEP_CONN *p_bcb, UINT8 *p_filter *******************************************************************************/ void bnepu_send_peer_multicast_filter_rsp (tBNEP_CONN *p_bcb, UINT16 response_code) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(BNEP_BUF_SIZE); UINT8 *p; BNEP_TRACE_DEBUG ("BNEP sending multicast filter response %d", response_code); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (BNEP_POOL_ID)) == NULL) + if (p_buf == NULL) { BNEP_TRACE_ERROR ("BNEP - no buffer filter rsp"); return; diff --git a/stack/gap/gap_conn.c b/stack/gap/gap_conn.c index 6c6c5e741..64a36f7cf 100644 --- a/stack/gap/gap_conn.c +++ b/stack/gap/gap_conn.c @@ -529,12 +529,14 @@ UINT16 GAP_ConnWriteData (UINT16 gap_handle, UINT8 *p_data, UINT16 max_len, UINT { if (p_ccb->cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (p_ccb->ertm_info.user_tx_pool_id)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(L2CAP_FCR_ERTM_BUF_SIZE); + if (p_buf == NULL) return (GAP_ERR_CONGESTED); } else { - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (GAP_DATA_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(GAP_DATA_BUF_SIZE); + if (p_buf == NULL) return (GAP_ERR_CONGESTED); } diff --git a/stack/gatt/att_protocol.c b/stack/gatt/att_protocol.c index 00512e2c9..8492116ad 100644 --- a/stack/gatt/att_protocol.c +++ b/stack/gatt/att_protocol.c @@ -71,10 +71,10 @@ BT_HDR *attp_build_mtu_cmd(UINT8 op_code, UINT16 rx_mtu) *******************************************************************************/ BT_HDR *attp_build_exec_write_cmd (UINT8 op_code, UINT8 flag) { - BT_HDR *p_buf = NULL; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(GATT_DATA_BUF_SIZE); UINT8 *p; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_BUF_POOL_ID)) != NULL) + if (p_buf != NULL) { p = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET; diff --git a/stack/gatt/gatt_db.c b/stack/gatt/gatt_db.c index ef4f468b6..12e150846 100644 --- a/stack/gatt/gatt_db.c +++ b/stack/gatt/gatt_db.c @@ -1103,11 +1103,11 @@ static BOOLEAN copy_extra_byte_in_db(tGATT_SVC_DB *p_db, void **p_dst, UINT16 le *******************************************************************************/ static BOOLEAN allocate_svc_db_buf(tGATT_SVC_DB *p_db) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(GATT_DB_BUF_SIZE); GATT_TRACE_DEBUG("allocate_svc_db_buf allocating extra buffer"); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_DB_POOL_ID)) == NULL) + if (p_buf == NULL) { GATT_TRACE_ERROR("allocate_svc_db_buf failed, no resources"); return FALSE; diff --git a/stack/hid/hidh_conn.c b/stack/hid/hidh_conn.c index 7b3db4acd..f3df0bb11 100644 --- a/stack/hid/hidh_conn.c +++ b/stack/hid/hidh_conn.c @@ -881,7 +881,7 @@ tHID_STATUS hidh_conn_snd_data (UINT8 dhandle, UINT8 trans_type, UINT8 param, BOOLEAN seg_req = FALSE; UINT16 data_size; UINT16 cid; - UINT8 pool_id; + UINT16 buf_size; UINT8 use_data = 0 ; BOOLEAN blank_datc = FALSE; @@ -909,11 +909,11 @@ tHID_STATUS hidh_conn_snd_data (UINT8 dhandle, UINT8 trans_type, UINT8 param, case HID_TRANS_GET_IDLE: case HID_TRANS_SET_IDLE: cid = p_hcon->ctrl_cid; - pool_id = HID_CONTROL_POOL_ID; + buf_size = HID_CONTROL_BUF_SIZE; break; case HID_TRANS_DATA: cid = p_hcon->intr_cid; - pool_id = HID_INTERRUPT_POOL_ID; + buf_size = HID_INTERRUPT_BUF_SIZE; break; default: return (HID_ERR_INVALID_PARAM) ; @@ -928,7 +928,8 @@ tHID_STATUS hidh_conn_snd_data (UINT8 dhandle, UINT8 trans_type, UINT8 param, { if ( buf == NULL || blank_datc ) { - if((p_buf = (BT_HDR *)GKI_getpoolbuf (pool_id)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(buf_size); + if (p_buf == NULL) return (HID_ERR_NO_RESOURCES); p_buf->offset = L2CAP_MIN_OFFSET; @@ -939,7 +940,8 @@ tHID_STATUS hidh_conn_snd_data (UINT8 dhandle, UINT8 trans_type, UINT8 param, } else if ( (buf->len > (p_hcon->rem_mtu_size - 1))) { - if((p_buf = (BT_HDR *)GKI_getpoolbuf (pool_id)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(buf_size); + if (p_buf == NULL) return (HID_ERR_NO_RESOURCES); p_buf->offset = L2CAP_MIN_OFFSET; diff --git a/stack/include/l2cdefs.h b/stack/include/l2cdefs.h index a6e25eb9e..46e0101ce 100644 --- a/stack/include/l2cdefs.h +++ b/stack/include/l2cdefs.h @@ -273,6 +273,7 @@ * including the l2cap headers in each packet - to match the latter - the -5 is added */ #define L2CAP_MAX_SDU_LENGTH (GKI_BUF4_SIZE - (L2CAP_MIN_OFFSET + L2CAP_MAX_HEADER_FCS) -5) +#define L2CAP_MAX_BUF_SIZE (10240 + 24) /* Part of L2CAP_MIN_OFFSET that is not part of L2CAP */ diff --git a/stack/l2cap/l2c_fcr.c b/stack/l2cap/l2c_fcr.c index 3df5cba7e..29c150cfc 100644 --- a/stack/l2cap/l2c_fcr.c +++ b/stack/l2cap/l2c_fcr.c @@ -41,6 +41,9 @@ /* Flag passed to retransmit_i_frames() when all packets should be retransmitted */ #define L2C_FCR_RETX_ALL_PKTS 0xFF +/* this is the minimal offset required by OBX to process incoming packets */ +static const uint16_t OBX_BUF_MIN_OFFSET = 4; + #if BT_TRACE_VERBOSE == TRUE static char *SAR_types[] = { "Unsegmented", "Start", "End", "Continuation" }; static char *SUP_types[] = { "RR", "REJ", "RNR", "SREJ" }; @@ -322,34 +325,14 @@ void l2c_fcr_cleanup (tL2C_CCB *p_ccb) ** Returns pointer to new buffer ** *******************************************************************************/ -BT_HDR *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes, UINT8 pool) +BT_HDR *l2c_fcr_clone_buf(BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes) { assert(p_buf != NULL); - BT_HDR *p_buf2; - - /* If using the common pool, should be at least 10% free. */ - if ( (pool == HCI_ACL_POOL_ID) && (GKI_poolutilization (pool) > 90) ) - { - L2CAP_TRACE_ERROR ("L2CAP - failed to clone buffer on HCI_ACL_POOL_ID Utilization: %u", GKI_poolutilization(pool)); - return (NULL); - } + uint16_t buf_size = no_of_bytes + sizeof(BT_HDR) + new_offset; + BT_HDR *p_buf2 = (BT_HDR *)GKI_getbuf(buf_size); - if ((p_buf2 = (BT_HDR *)GKI_getpoolbuf(pool)) != NULL) + if (p_buf2 != NULL) { - UINT16 pool_buf_size = GKI_get_pool_bufsize (pool); - - /* Make sure buffer fits into buffer pool */ - if ((no_of_bytes + sizeof(BT_HDR) + new_offset) > pool_buf_size) - { - L2CAP_TRACE_ERROR("##### l2c_fcr_clone_buf (NumBytes %d) -> Exceeds poolsize %d [bytes %d + BT_HDR %d + offset %d]", - (no_of_bytes + sizeof(BT_HDR) + new_offset), - pool_buf_size, no_of_bytes, sizeof(BT_HDR), - new_offset); - - GKI_freebuf(p_buf2); - return (NULL); - } - p_buf2->offset = new_offset; p_buf2->len = no_of_bytes; @@ -359,7 +342,8 @@ BT_HDR *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes, } else { - L2CAP_TRACE_ERROR ("L2CAP - failed to clone buffer, Pool: %u Count: %u", pool, GKI_poolfreecount(pool)); + L2CAP_TRACE_ERROR("L2CAP - failed to clone buffer, Size: %u", + buf_size); } return (p_buf2); @@ -538,7 +522,8 @@ void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, UINT16 function_code, UINT16 pf_bit) ctrl_word |= (p_ccb->fcrb.next_seq_expected << L2CAP_FCR_REQ_SEQ_BITS_SHIFT); ctrl_word |= pf_bit; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (L2CAP_CMD_POOL_ID)) != NULL) + p_buf = (BT_HDR *)GKI_getbuf(L2CAP_CMD_BUF_SIZE); + if (p_buf != NULL) { p_buf->offset = HCI_DATA_PREAMBLE_SIZE; p_buf->len = L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD; @@ -1115,17 +1100,6 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B return; } - /* If there are no free buffers in the user Rx queue, drop the */ - /* received buffer now before we update any sequence numbers */ - if (GKI_poolfreecount (p_ccb->ertm_info.user_rx_pool_id) == 0) - { - L2CAP_TRACE_WARNING ("L2CAP CID: 0x%04x Dropping I-Frame seq: %u User RX Pool: %u (Size: %u) has no free buffers!!", - p_ccb->local_cid, tx_seq, p_ccb->ertm_info.user_rx_pool_id, - GKI_poolcount (p_ccb->ertm_info.user_rx_pool_id)); - GKI_freebuf(p_buf); - return; - } - /* Check if tx-sequence is the expected one */ if (tx_seq != p_fcrb->next_seq_expected) { @@ -1159,7 +1133,7 @@ static void process_i_frame (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_word, B p_buf->offset -= L2CAP_FCR_OVERHEAD; p_buf->len += L2CAP_FCR_OVERHEAD; - p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len, p_ccb->ertm_info.fcr_rx_pool_id); + p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len); if (p_buf2) { @@ -1422,14 +1396,14 @@ static BOOLEAN do_sar_reassembly (tL2C_CCB *p_ccb, BT_HDR *p_buf, UINT16 ctrl_wo L2CAP_TRACE_WARNING ("SAR - SDU len: %u larger than MTU: %u", p_fcrb->rx_sdu_len, p_fcrb->rx_sdu_len); packet_ok = FALSE; } - else if ((p_fcrb->p_rx_sdu = (BT_HDR *)GKI_getpoolbuf (p_ccb->ertm_info.user_rx_pool_id)) == NULL) + else if ((p_fcrb->p_rx_sdu = (BT_HDR *)GKI_getbuf(L2CAP_MAX_BUF_SIZE)) == NULL) { - L2CAP_TRACE_ERROR ("SAR - no buffer for SDU start user_rx_pool_id:%d", p_ccb->ertm_info.user_rx_pool_id); + L2CAP_TRACE_ERROR ("SAR - no buffer for SDU start"); packet_ok = FALSE; } else { - p_fcrb->p_rx_sdu->offset = 4; /* this is the minimal offset required by OBX to process incoming packets */ + p_fcrb->p_rx_sdu->offset = OBX_BUF_MIN_OFFSET; p_fcrb->p_rx_sdu->len = 0; } } @@ -1570,7 +1544,7 @@ static BOOLEAN retransmit_i_frames (tL2C_CCB *p_ccb, UINT8 tx_seq) while (p_buf != NULL) { - p_buf2 = l2c_fcr_clone_buf (p_buf, p_buf->offset, p_buf->len, p_ccb->ertm_info.fcr_tx_pool_id); + p_buf2 = l2c_fcr_clone_buf(p_buf, p_buf->offset, p_buf->len); if (p_buf2) { @@ -1660,8 +1634,8 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length mid_seg = TRUE; /* Get a new buffer and copy the data that can be sent in a PDU */ - p_xmit = l2c_fcr_clone_buf (p_buf, L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET, - max_pdu, p_ccb->ertm_info.fcr_tx_pool_id); + p_xmit = l2c_fcr_clone_buf(p_buf, L2CAP_MIN_OFFSET + L2CAP_SDU_LEN_OFFSET, + max_pdu); if (p_xmit != NULL) { @@ -1676,7 +1650,7 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length } else /* Should never happen if the application has configured buffers correctly */ { - L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer, for segmentation, pool: %u", p_ccb->ertm_info.fcr_tx_pool_id); + L2CAP_TRACE_ERROR ("L2CAP - cannot get buffer for segmentation, max_pdu: %u", max_pdu); return (NULL); } } @@ -1733,12 +1707,12 @@ BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length if (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) { - BT_HDR *p_wack = l2c_fcr_clone_buf (p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len, p_ccb->ertm_info.fcr_tx_pool_id); + BT_HDR *p_wack = l2c_fcr_clone_buf(p_xmit, HCI_DATA_PREAMBLE_SIZE, p_xmit->len); if (!p_wack) { - L2CAP_TRACE_ERROR ("L2CAP - no buffer for xmit cloning, CID: 0x%04x Pool: %u Count: %u", - p_ccb->local_cid, p_ccb->ertm_info.fcr_tx_pool_id, GKI_poolfreecount(p_ccb->ertm_info.fcr_tx_pool_id)); + L2CAP_TRACE_ERROR("L2CAP - no buffer for xmit cloning, CID: 0x%04x Length: %u", + p_ccb->local_cid, p_xmit->len); /* We will not save the FCS in case we reconfigure and change options */ if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h index cbaca8251..2f06fb893 100644 --- a/stack/l2cap/l2c_int.h +++ b/stack/l2cap/l2c_int.h @@ -714,7 +714,7 @@ extern void l2c_fcr_proc_pdu (tL2C_CCB *p_ccb, BT_HDR *p_buf); extern void l2c_fcr_proc_tout (tL2C_CCB *p_ccb); extern void l2c_fcr_proc_ack_tout (tL2C_CCB *p_ccb); extern void l2c_fcr_send_S_frame (tL2C_CCB *p_ccb, UINT16 function_code, UINT16 pf_bit); -extern BT_HDR *l2c_fcr_clone_buf (BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes, UINT8 pool); +extern BT_HDR *l2c_fcr_clone_buf(BT_HDR *p_buf, UINT16 new_offset, UINT16 no_of_bytes); extern BOOLEAN l2c_fcr_is_flow_controlled (tL2C_CCB *p_ccb); extern BT_HDR *l2c_fcr_get_next_xmit_sdu_seg (tL2C_CCB *p_ccb, UINT16 max_packet_length); extern void l2c_fcr_start_timer (tL2C_CCB *p_ccb); diff --git a/stack/l2cap/l2c_utils.c b/stack/l2cap/l2c_utils.c index e80d16b0f..68152ec21 100644 --- a/stack/l2cap/l2c_utils.c +++ b/stack/l2cap/l2c_utils.c @@ -341,7 +341,7 @@ BOOLEAN l2c_is_cmd_rejected (UINT8 cmd_code, UINT8 id, tL2C_LCB *p_lcb) *******************************************************************************/ BT_HDR *l2cu_build_header (tL2C_LCB *p_lcb, UINT16 len, UINT8 cmd, UINT8 id) { - BT_HDR *p_buf = (BT_HDR *)GKI_getpoolbuf (L2CAP_CMD_POOL_ID); + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(L2CAP_CMD_BUF_SIZE); UINT8 *p; if (!p_buf) @@ -1046,12 +1046,6 @@ void l2cu_send_peer_echo_rsp (tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data, UINT16 d } else p_lcb->cur_echo_id = id; - /* Don't respond if we more than 10% of our buffers are used */ - if (GKI_poolutilization (L2CAP_CMD_POOL_ID) > 10) - { - L2CAP_TRACE_WARNING ("L2CAP gki pool used up to more than 10%%, ignore echo response"); - return; - } uint16_t acl_data_size = controller_get_interface()->get_acl_data_size_classic(); uint16_t acl_packet_size = controller_get_interface()->get_acl_packet_size_classic(); @@ -3156,10 +3150,6 @@ static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb) if ( GKI_queue_is_empty(&p_ccb->xmit_hold_q)) continue; - /* If using the common pool, should be at least 10% free. */ - if ( (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) && (GKI_poolutilization (HCI_ACL_POOL_ID) > 90) ) - continue; - /* If in eRTM mode, check for window closure */ if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) continue; @@ -3230,10 +3220,6 @@ static tL2C_CCB *l2cu_get_next_channel(tL2C_LCB *p_lcb) if (p_ccb->xmit_hold_q.count == 0) continue; - /* If using the common pool, should be at least 10% free. */ - if ( (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) && (GKI_poolutilization (HCI_ACL_POOL_ID) > 90) ) - continue; - /* If in eRTM mode, check for window closure */ if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) continue; @@ -3282,10 +3268,6 @@ BT_HDR *l2cu_get_next_buffer_to_send (tL2C_LCB *p_lcb) if (GKI_queue_is_empty(&p_ccb->xmit_hold_q)) continue; - /* If using the common pool, should be at least 10% free. */ - if ( (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID) && (GKI_poolutilization (HCI_ACL_POOL_ID) > 90) ) - continue; - /* If in eRTM mode, check for window closure */ if ( (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) && (l2c_fcr_is_flow_controlled (p_ccb)) ) continue; diff --git a/stack/pan/pan_api.c b/stack/pan/pan_api.c index 583f1d236..3b8fdbb4c 100644 --- a/stack/pan/pan_api.c +++ b/stack/pan/pan_api.c @@ -523,9 +523,9 @@ tPAN_RESULT PAN_Write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol, return PAN_SUCCESS; } - buffer = (BT_HDR *)GKI_getpoolbuf(PAN_POOL_ID); + buffer = (BT_HDR *)GKI_getbuf(PAN_BUF_SIZE); if (!buffer) { - PAN_TRACE_ERROR("%s unable to acquire buffer from pool.", __func__); + PAN_TRACE_ERROR("%s unable to acquire buffer.", __func__); return PAN_NO_RESOURCES; } diff --git a/stack/rfcomm/port_api.c b/stack/rfcomm/port_api.c index 5fa5013c9..23c83bd25 100644 --- a/stack/rfcomm/port_api.c +++ b/stack/rfcomm/port_api.c @@ -1594,7 +1594,7 @@ int PORT_WriteDataCO (UINT16 handle, int* p_len) } /* continue with rfcomm data write */ - p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_DATA_POOL_ID); + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_DATA_BUF_SIZE); if (!p_buf) break; @@ -1723,7 +1723,7 @@ int PORT_WriteData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len) break; /* continue with rfcomm data write */ - p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_DATA_POOL_ID); + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_DATA_BUF_SIZE); if (!p_buf) break; @@ -1804,7 +1804,8 @@ int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len) return (PORT_UNKNOWN_ERROR); } - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) != NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf != NULL) { p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2; diff --git a/stack/rfcomm/rfc_ts_frames.c b/stack/rfcomm/rfc_ts_frames.c index 812089378..925856807 100644 --- a/stack/rfcomm/rfc_ts_frames.c +++ b/stack/rfcomm/rfc_ts_frames.c @@ -45,7 +45,8 @@ void rfc_send_sabme (tRFC_MCB *p_mcb, UINT8 dlci) UINT8 *p_data; UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET; @@ -77,7 +78,8 @@ void rfc_send_ua (tRFC_MCB *p_mcb, UINT8 dlci) UINT8 *p_data; UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, FALSE); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET; @@ -109,7 +111,8 @@ void rfc_send_dm (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN pf) UINT8 *p_data; UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, FALSE); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET; @@ -141,7 +144,8 @@ void rfc_send_disc (tRFC_MCB *p_mcb, UINT8 dlci) UINT8 *p_data; UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET; @@ -237,7 +241,8 @@ void rfc_send_pn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT16 mtu, U BT_HDR *p_buf; UINT8 *p_data; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -282,7 +287,8 @@ void rfc_send_fcon (tRFC_MCB *p_mcb, BOOLEAN is_command) BT_HDR *p_buf; UINT8 *p_data; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -310,7 +316,8 @@ void rfc_send_fcoff (tRFC_MCB *p_mcb, BOOLEAN is_command) BT_HDR *p_buf; UINT8 *p_data; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -345,7 +352,8 @@ void rfc_send_msc (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, signals = p_pars->modem_signal; break_duration = p_pars->break_signal; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -389,10 +397,10 @@ void rfc_send_msc (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, *******************************************************************************/ void rfc_send_rls (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT8 status) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); UINT8 *p_data; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -420,10 +428,10 @@ void rfc_send_rls (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT8 status *******************************************************************************/ void rfc_send_nsc (tRFC_MCB *p_mcb) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); UINT8 *p_data; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -453,10 +461,10 @@ void rfc_send_nsc (tRFC_MCB *p_mcb) void rfc_send_rpn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, tPORT_STATE *p_pars, UINT16 mask) { - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); UINT8 *p_data; - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_CTRL_FRAME_LEN; @@ -542,11 +550,11 @@ void rfc_send_test (tRFC_MCB *p_mcb, BOOLEAN is_command, BT_HDR *p_buf) *******************************************************************************/ void rfc_send_credit(tRFC_MCB *p_mcb, UINT8 dlci, UINT8 credit) { - BT_HDR *p_buf; UINT8 *p_data; UINT8 cr = RFCOMM_CR(p_mcb->is_initiator, TRUE); + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(RFCOMM_CMD_BUF_SIZE); - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (RFCOMM_CMD_POOL_ID)) == NULL) + if (p_buf == NULL) return; p_buf->offset = L2CAP_MIN_OFFSET; diff --git a/stack/sdp/sdp_discovery.c b/stack/sdp/sdp_discovery.c index 646a62dd3..59bd6a35d 100644 --- a/stack/sdp/sdp_discovery.c +++ b/stack/sdp/sdp_discovery.c @@ -119,11 +119,11 @@ static UINT8 *sdpu_build_uuid_seq (UINT8 *p_out, UINT16 num_uuids, tSDP_UUID *p_ static void sdp_snd_service_search_req(tCONN_CB *p_ccb, UINT8 cont_len, UINT8 * p_cont) { UINT8 *p, *p_start, *p_param_len; - BT_HDR *p_cmd; + BT_HDR *p_cmd = (BT_HDR *) GKI_getbuf(SDP_DATA_BUF_SIZE); UINT16 param_len; - /* Get a buffer to send the packet to L2CAP */ - if ((p_cmd = (BT_HDR *) GKI_getpoolbuf (SDP_POOL_ID)) == NULL) + /* Check the buffer for sending the packet to L2CAP */ + if (p_cmd == NULL) { sdp_disconnect (p_ccb, SDP_NO_RESOURCES); return; @@ -485,7 +485,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply) /* Now, ask for the next handle. Re-use the buffer we just got. */ if (p_ccb->cur_handle < p_ccb->num_handles) { - BT_HDR *p_msg = (BT_HDR *) GKI_getpoolbuf (SDP_POOL_ID); + BT_HDR *p_msg = (BT_HDR *) GKI_getbuf(SDP_DATA_BUF_SIZE); UINT8 *p; if (!p_msg) @@ -631,7 +631,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply) /* If continuation request (or first time request) */ if ((cont_request_needed) || (!p_reply)) { - BT_HDR *p_msg = (BT_HDR *) GKI_getpoolbuf (SDP_POOL_ID); + BT_HDR *p_msg = (BT_HDR *) GKI_getbuf(SDP_DATA_BUF_SIZE); UINT8 *p; if (!p_msg) diff --git a/stack/sdp/sdp_server.c b/stack/sdp/sdp_server.c index 5dd6b92c3..b4a950136 100644 --- a/stack/sdp/sdp_server.c +++ b/stack/sdp/sdp_server.c @@ -256,7 +256,8 @@ static void process_service_search (tCONN_CB *p_ccb, UINT16 trans_num, } /* Get a buffer to use to build the response */ - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(SDP_DATA_BUF_SIZE); + if (p_buf == NULL) { SDP_TRACE_ERROR ("SDP - no buf for search rsp"); return; @@ -521,7 +522,8 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num, } /* Get a buffer to use to build the response */ - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(SDP_DATA_BUF_SIZE); + if (p_buf == NULL) { SDP_TRACE_ERROR ("SDP - no buf for search rsp"); return; @@ -857,7 +859,8 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num, } /* Get a buffer to use to build the response */ - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) + p_buf = (BT_HDR *)GKI_getbuf(SDP_DATA_BUF_SIZE); + if (p_buf == NULL) { SDP_TRACE_ERROR ("SDP - no buf for search rsp"); return; diff --git a/stack/sdp/sdp_utils.c b/stack/sdp/sdp_utils.c index 6d7da74bc..b65e6ac07 100644 --- a/stack/sdp/sdp_utils.c +++ b/stack/sdp/sdp_utils.c @@ -318,14 +318,14 @@ void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_co { UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len; UINT16 rsp_param_len; - BT_HDR *p_buf; + BT_HDR *p_buf = (BT_HDR *)GKI_getbuf(SDP_DATA_BUF_SIZE); SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x", error_code, p_ccb->connection_id); - /* Get a buffer to use to build and send the packet to L2CAP */ - if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL) + /* Check the buffer to use to build and send the packet to L2CAP */ + if (p_buf == NULL) { SDP_TRACE_ERROR ("SDP - no buf for err msg"); return; |