OSDN Git Service

DO NOT MERGE Fix unexpected behavior in SDP
[android-x86/system-bt.git] / stack / gatt / gatt_utils.c
index e8e60d4..c2db770 100644 (file)
@@ -99,7 +99,7 @@ void gatt_free_pending_ind(tGATT_TCB *p_tcb)
 
     /* release all queued indications */
     while (!fixed_queue_is_empty(p_tcb->pending_ind_q))
-        osi_freebuf(fixed_queue_try_dequeue(p_tcb->pending_ind_q));
+        osi_free(fixed_queue_try_dequeue(p_tcb->pending_ind_q));
     fixed_queue_free(p_tcb->pending_ind_q, NULL);
     p_tcb->pending_ind_q = NULL;
 }
@@ -122,7 +122,7 @@ void gatt_free_pending_enc_queue(tGATT_TCB *p_tcb)
 
     /* release all queued indications */
     while (!fixed_queue_is_empty(p_tcb->pending_enc_clcb))
-        osi_freebuf(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb));
+        osi_free(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb));
     fixed_queue_free(p_tcb->pending_enc_clcb, NULL);
     p_tcb->pending_enc_clcb = NULL;
 }
@@ -150,7 +150,7 @@ void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr)
             memcpy(req.srv_chg.bda, bd_addr, BD_ADDR_LEN);
             (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_REMOVE_CLIENT,&req, NULL);
         }
-        osi_freebuf(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q,
+        osi_free(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q,
                                                       p_buf));
     }
 }
@@ -233,19 +233,17 @@ tGATTS_PENDING_NEW_SRV_START *gatt_sr_is_new_srv_chg(tBT_UUID *p_app_uuid128, tB
 *******************************************************************************/
 tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB  *p_tcb, tGATT_VALUE *p_ind)
 {
+    tGATT_VALUE *p_buf = (tGATT_VALUE *)osi_malloc(sizeof(tGATT_VALUE));
+
     GATT_TRACE_DEBUG("%s", __func__);
+    GATT_TRACE_DEBUG("enqueue a pending indication");
+
+    memcpy(p_buf, p_ind, sizeof(tGATT_VALUE));
+    fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf);
 
-    tGATT_VALUE *p_buf = (tGATT_VALUE *)osi_getbuf((UINT16)sizeof(tGATT_VALUE));
-    if (p_buf != NULL)
-    {
-        GATT_TRACE_DEBUG("enqueue a pending indication");
-        memcpy(p_buf, p_ind, sizeof(tGATT_VALUE));
-        fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf);
-    }
     return p_buf;
 }
 
-
 /*******************************************************************************
 **
 ** Function     gatt_add_pending_new_srv_start
@@ -257,16 +255,15 @@ tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB  *p_tcb, tGATT_VALUE *p_ind)
 *******************************************************************************/
 tGATTS_PENDING_NEW_SRV_START *gatt_add_pending_new_srv_start(tGATTS_HNDL_RANGE *p_new_srv_start)
 {
+    tGATTS_PENDING_NEW_SRV_START *p_buf =
+        (tGATTS_PENDING_NEW_SRV_START *)osi_malloc(sizeof(tGATTS_PENDING_NEW_SRV_START));
+
     GATT_TRACE_DEBUG("%s", __func__);
+    GATT_TRACE_DEBUG("enqueue a new pending new srv start");
+
+    p_buf->p_new_srv_start = p_new_srv_start;
+    fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf);
 
-    tGATTS_PENDING_NEW_SRV_START *p_buf =
-        (tGATTS_PENDING_NEW_SRV_START *)osi_getbuf((UINT16)sizeof(tGATTS_PENDING_NEW_SRV_START));
-    if (p_buf != NULL)
-    {
-        GATT_TRACE_DEBUG("enqueue a new pending new srv start");
-        p_buf->p_new_srv_start = p_new_srv_start;
-        fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf);
-    }
     return p_buf;
 }
 
@@ -282,20 +279,17 @@ tGATTS_PENDING_NEW_SRV_START *gatt_add_pending_new_srv_start(tGATTS_HNDL_RANGE *
 *******************************************************************************/
 tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg)
 {
-    GATT_TRACE_DEBUG ("%s", __func__);
+    tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)osi_malloc(sizeof(tGATTS_SRV_CHG));
 
-    tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)osi_getbuf((UINT16)sizeof(tGATTS_SRV_CHG));
-    if (p_buf != NULL)
-    {
-        GATT_TRACE_DEBUG ("enqueue a srv chg client");
-        memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG));
-        fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf);
-    }
+    GATT_TRACE_DEBUG("%s", __func__);
+    GATT_TRACE_DEBUG("enqueue a srv chg client");
+
+    memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG));
+    fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf);
 
     return p_buf;
 }
 
-
 /*******************************************************************************
 **
 ** Function     gatt_alloc_hdl_buffer
@@ -397,7 +391,7 @@ void gatt_free_hdl_buffer(tGATT_HDL_LIST_ELEM *p)
     if (p)
     {
         while (!fixed_queue_is_empty(p->svc_db.svc_buffer))
-            osi_freebuf(fixed_queue_try_dequeue(p->svc_db.svc_buffer));
+            osi_free(fixed_queue_try_dequeue(p->svc_db.svc_buffer));
         fixed_queue_free(p->svc_db.svc_buffer, NULL);
         memset(p, 0, sizeof(tGATT_HDL_LIST_ELEM));
     }
@@ -422,7 +416,7 @@ void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id)
         if (memcmp(p_app_id, &p_elem->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0)
         {
             while (!fixed_queue_is_empty(p_elem->svc_db.svc_buffer))
-                osi_freebuf(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer));
+                osi_free(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer));
             fixed_queue_free(p_elem->svc_db.svc_buffer, NULL);
             p_elem->svc_db.svc_buffer = NULL;
 
@@ -978,7 +972,6 @@ tGATT_TCB * gatt_allocate_tcb_by_bdaddr(BD_ADDR bda, tBT_TRANSPORT transport)
             p_tcb->pending_ind_q = fixed_queue_new(SIZE_MAX);
             p_tcb->conf_timer = alarm_new("gatt.conf_timer");
             p_tcb->ind_ack_timer = alarm_new("gatt.ind_ack_timer");
-            p_tcb->sr_cmd.multi_rsp_q = fixed_queue_new(SIZE_MAX);
             p_tcb->in_use = TRUE;
             p_tcb->tcb_idx = i;
             p_tcb->transport = transport;
@@ -2227,7 +2220,7 @@ void gatt_end_operation(tGATT_CLCB *p_clcb, tGATT_STATUS status, void *p_data)
         }
     }
 
-    osi_freebuf_and_reset((void **)&p_clcb->p_attr_buf);
+    osi_free_and_reset((void **)&p_clcb->p_attr_buf);
 
     operation =  p_clcb->operation;
     conn_id = p_clcb->conn_id;
@@ -2291,6 +2284,7 @@ void gatt_cleanup_upon_disc(BD_ADDR bda, UINT16 reason, tBT_TRANSPORT transport)
         gatt_free_pending_ind(p_tcb);
         gatt_free_pending_enc_queue(p_tcb);
         fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL);
+        p_tcb->sr_cmd.multi_rsp_q = NULL;
 
         for (i = 0; i < GATT_MAX_APPS; i ++)
         {
@@ -2373,10 +2367,9 @@ void gatt_dbg_display_uuid(tBT_UUID bt_uuid)
                 bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
     }
     else
-        BCM_STRNCPY_S(str_buf, sizeof(str_buf), "Unknown UUID 0", 15);
+        strlcpy(str_buf, "Unknown UUID 0", sizeof(str_buf));
 
     GATT_TRACE_DEBUG ("UUID=[%s]", str_buf);
-
 }
 
 
@@ -2799,16 +2792,15 @@ BOOLEAN gatt_update_auto_connect_dev (tGATT_IF gatt_if, BOOLEAN add, BD_ADDR bd_
 *******************************************************************************/
 tGATT_PENDING_ENC_CLCB* gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb)
 {
-    GATT_TRACE_DEBUG ("gatt_add_pending_new_srv_start");
-
     tGATT_PENDING_ENC_CLCB *p_buf =
-        (tGATT_PENDING_ENC_CLCB *)osi_getbuf((UINT16)sizeof(tGATT_PENDING_ENC_CLCB));
-    if (p_buf != NULL)
-    {
-        GATT_TRACE_DEBUG("enqueue a new pending encryption channel clcb");
-        p_buf->p_clcb = p_clcb;
-        fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf);
-    }
+        (tGATT_PENDING_ENC_CLCB *)osi_malloc(sizeof(tGATT_PENDING_ENC_CLCB));
+
+    GATT_TRACE_DEBUG ("%s", __func__);
+    GATT_TRACE_DEBUG("enqueue a new pending encryption channel clcb");
+
+    p_buf->p_clcb = p_clcb;
+    fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf);
+
     return p_buf;
 }
 /*******************************************************************************