OSDN Git Service

Avoid more annoying crashing
[android-x86/system-bt.git] / stack / avdt / avdt_ccb_act.c
index 24b7cf4..41b74e1 100644 (file)
@@ -34,6 +34,8 @@
 #include "btu.h"
 #include "btm_api.h"
 
+extern fixed_queue_t *btu_general_alarm_queue;
+
 /*******************************************************************************
 **
 ** Function         avdt_ccb_clear_ccb
@@ -54,26 +56,14 @@ static void avdt_ccb_clear_ccb(tAVDT_CCB *p_ccb)
     p_ccb->ret_count = 0;
 
     /* free message being fragmented */
-    if (p_ccb->p_curr_msg != NULL)
-    {
-        osi_freebuf(p_ccb->p_curr_msg);
-        p_ccb->p_curr_msg = NULL;
-    }
+    osi_free_and_reset((void **)&p_ccb->p_curr_msg);
 
     /* free message being reassembled */
-    if (p_ccb->p_rx_msg != NULL)
-    {
-        osi_freebuf(p_ccb->p_rx_msg);
-        p_ccb->p_rx_msg = NULL;
-    }
+    osi_free_and_reset((void **)&p_ccb->p_rx_msg);
 
     /* clear out response queue */
     while ((p_buf = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->rsp_q)) != NULL)
-    {
-        osi_freebuf(p_buf);
-    }
-    fixed_queue_free(p_ccb->rsp_q, NULL);
-    p_ccb->rsp_q = NULL;
+        osi_free(p_buf);
 }
 
 /*******************************************************************************
@@ -143,7 +133,12 @@ void avdt_ccb_chk_close(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
     /* if no active scbs start idle timer */
     if (i == AVDT_NUM_SEPS)
     {
-        btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_IDLE, avdt_cb.rcb.idle_tout);
+        alarm_cancel(p_ccb->ret_ccb_timer);
+        alarm_cancel(p_ccb->rsp_ccb_timer);
+        period_ms_t interval_ms = avdt_cb.rcb.idle_tout * 1000;
+        alarm_set_on_queue(p_ccb->idle_ccb_timer, interval_ms,
+                           avdt_ccb_idle_ccb_timer_timeout, p_ccb,
+                           btu_general_alarm_queue);
     }
 }
 
@@ -744,8 +739,7 @@ void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
             }
         }
 
-        osi_freebuf(p_ccb->p_curr_cmd);
-        p_ccb->p_curr_cmd = NULL;
+        osi_free_and_reset((void **)&p_ccb->p_curr_cmd);
     }
 }
 
@@ -763,12 +757,7 @@ void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
     UNUSED(p_data);
-
-    if (p_ccb->p_curr_cmd != NULL)
-    {
-        osi_freebuf(p_ccb->p_curr_cmd);
-        p_ccb->p_curr_cmd = NULL;
-    }
+    osi_free_and_reset((void **)&p_ccb->p_curr_cmd);
 }
 
 /*******************************************************************************
@@ -803,7 +792,6 @@ void avdt_ccb_cong_state(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
     UINT8   err_code = AVDT_ERR_TIMEOUT;
-    BT_HDR  *p_msg;
 
     p_ccb->ret_count++;
     if (p_ccb->ret_count == AVDT_RET_MAX)
@@ -821,17 +809,19 @@ 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 */
-            p_msg = (BT_HDR *) osi_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));
-                avdt_msg_send(p_ccb, p_msg);
-            }
+            BT_HDR *p_msg = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
+            memcpy(p_msg, p_ccb->p_curr_cmd,
+                   (sizeof(BT_HDR) + p_ccb->p_curr_cmd->offset + p_ccb->p_curr_cmd->len));
+            avdt_msg_send(p_ccb, p_msg);
         }
 
-        /* restart timer */
-        btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RET, avdt_cb.rcb.ret_tout);
+        /* restart ret timer */
+        alarm_cancel(p_ccb->idle_ccb_timer);
+        alarm_cancel(p_ccb->rsp_ccb_timer);
+        period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000;
+        alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms,
+                           avdt_ccb_ret_ccb_timer_timeout, p_ccb,
+                           btu_general_alarm_queue);
     }
 }
 
@@ -859,13 +849,10 @@ void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
         if ((p_msg = (BT_HDR *) fixed_queue_try_dequeue(p_ccb->cmd_q)) != NULL)
         {
             /* make a copy of buffer in p_curr_cmd */
-            p_ccb->p_curr_cmd = (BT_HDR *) osi_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));
-
-                avdt_msg_send(p_ccb, p_msg);
-            }
+            p_ccb->p_curr_cmd = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
+            memcpy(p_ccb->p_curr_cmd, p_msg,
+                   (sizeof(BT_HDR) + p_msg->offset + p_msg->len));
+            avdt_msg_send(p_ccb, p_msg);
         }
     }
 }
@@ -998,10 +985,7 @@ void avdt_ccb_chk_timer(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
     UNUSED(p_data);
 
-    if (p_ccb->timer_entry.event == BTU_TTYPE_AVDT_CCB_IDLE)
-    {
-        btu_stop_timer(&p_ccb->timer_entry);
-    }
+    alarm_cancel(p_ccb->idle_ccb_timer);
 }
 
 /*******************************************************************************