Instrument data flow a bit

Use counters to grab some select data metrics.
diff --git a/stack/hcic/hcicmds.c b/stack/hcic/hcicmds.c
index 9ad2e2a..8e213d3 100644
--- a/stack/hcic/hcicmds.c
+++ b/stack/hcic/hcicmds.c
@@ -24,6 +24,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "counter.h"
 #include "gki.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
@@ -249,6 +250,8 @@
     BDADDR_TO_STREAM (pp, dest);
     UINT8_TO_STREAM  (pp, role);
 
+    counter_add("hci.conn.accept", 1);
+
     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
     return (TRUE);
 }
@@ -272,6 +275,8 @@
     BDADDR_TO_STREAM (pp, dest);
     UINT8_TO_STREAM (pp, reason);
 
+    counter_add("hci.conn.reject", 1);
+
     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
     return (TRUE);
 }
diff --git a/stack/l2cap/l2c_api.c b/stack/l2cap/l2c_api.c
index 4ee65cc..36f42f5 100644
--- a/stack/l2cap/l2c_api.c
+++ b/stack/l2cap/l2c_api.c
@@ -28,6 +28,7 @@
 
 #include "gki.h"
 #include "bt_types.h"
+#include "counter.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
 #include "l2cdefs.h"
@@ -236,6 +237,7 @@
     tL2C_CCB        *p_ccb;
     tL2C_RCB        *p_rcb;
 
+    counter_add("l2cap.conn.req", 1);
     L2CAP_TRACE_API ("L2CA_ErtmConnectReq()  PSM: 0x%04x  BDA: %08x%04x  p_ertm_info: 0x%08x allowed:0x%x preferred:%d", psm,
                       (p_bd_addr[0]<<24)+(p_bd_addr[1]<<16)+(p_bd_addr[2]<<8)+p_bd_addr[3],
                       (p_bd_addr[4]<<8)+p_bd_addr[5], p_ertm_info,
@@ -362,6 +364,7 @@
     tL2C_LCB        *p_lcb;
     tL2C_CCB        *p_ccb;
 
+    counter_add("l2cap.conn.rsp", 1);
     L2CAP_TRACE_API ("L2CA_ErtmConnectRsp()  CID: 0x%04x  Result: %d  Status: %d  BDA: %08x%04x  p_ertm_info:0x%08x",
                       lcid, result, status,
                       (p_bd_addr[0]<<24)+(p_bd_addr[1]<<16)+(p_bd_addr[2]<<8)+p_bd_addr[3],
@@ -445,6 +448,7 @@
 {
     tL2C_CCB        *p_ccb;
 
+    counter_add("l2cap.cfg.req", 1);
     L2CAP_TRACE_API ("L2CA_ConfigReq()  CID 0x%04x: fcr_present:%d (mode %d) mtu_present:%d (%d)",
         cid, p_cfg->fcr_present, p_cfg->fcr.mode, p_cfg->mtu_present, p_cfg->mtu);
 
@@ -496,6 +500,7 @@
 {
     tL2C_CCB        *p_ccb;
 
+    counter_add("l2cap.cfg.rsp", 1);
     L2CAP_TRACE_API ("L2CA_ConfigRsp()  CID: 0x%04x  Result: %d MTU present:%d Flush TO:%d FCR:%d FCS:%d",
         cid, p_cfg->result, p_cfg->mtu_present, p_cfg->flush_to_present, p_cfg->fcr_present, p_cfg->fcs_present);
 
@@ -540,6 +545,7 @@
 {
     tL2C_CCB        *p_ccb;
 
+    counter_add("l2cap.disconn.req", 1);
     L2CAP_TRACE_API ("L2CA_DisconnectReq()  CID: 0x%04x", cid);
 
     /* Find the channel control block. We don't know the link it is on. */
@@ -568,6 +574,7 @@
 {
     tL2C_CCB        *p_ccb;
 
+    counter_add("l2cap.disconn.rsp", 1);
     L2CAP_TRACE_API ("L2CA_DisconnectRsp()  CID: 0x%04x", cid);
 
     /* Find the channel control block. We don't know the link it is on. */
diff --git a/stack/l2cap/l2c_link.c b/stack/l2cap/l2c_link.c
index 0cea8b4..bc5b472 100644
--- a/stack/l2cap/l2c_link.c
+++ b/stack/l2cap/l2c_link.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 
 #include "controller.h"
+#include "counter.h"
 #include "gki.h"
 #include "bt_types.h"
 #include "bt_utils.h"
@@ -97,6 +98,8 @@
                 p_lcb->link_role = l2cu_get_conn_role(p_lcb);
         }
 
+        counter_add("l2cap.conn.accept", 1);
+
         /* Tell the other side we accept the connection */
         btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role);
 
@@ -117,6 +120,7 @@
         else
             p_lcb->link_role = l2cu_get_conn_role(p_lcb);
 
+        counter_add("l2cap.conn.accept", 1);
         btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role);
 
         p_lcb->link_state = LST_CONNECTING;
@@ -125,6 +129,7 @@
     else if (p_lcb->link_state == LST_DISCONNECTING)
     {
         /* In disconnecting state, reject the connection. */
+        counter_add("l2cap.conn.reject.disconn", 1);
         btsnd_hcic_reject_conn (bd_addr, HCI_ERR_HOST_REJECT_DEVICE);
     }
     else
@@ -132,6 +137,7 @@
         L2CAP_TRACE_ERROR("L2CAP got conn_req while connected (state:%d). Reject it",
                 p_lcb->link_state);
         /* Reject the connection with ACL Connection Already exist reason */
+        counter_add("l2cap.conn.reject.exists", 1);
         btsnd_hcic_reject_conn (bd_addr, HCI_ERR_CONNECTION_EXISTS);
     }
     return (FALSE);
@@ -187,6 +193,7 @@
     {
         /* Connected OK. Change state to connected */
         p_lcb->link_state = LST_CONNECTED;
+        counter_add("l2cap.conn.ok", 1);
 
         /* Get the peer information if the l2cap flow-control/rtrans is supported */
         l2cu_send_peer_info_req (p_lcb, L2CAP_EXTENDED_FEATURES_INFO_TYPE);
diff --git a/stack/l2cap/l2c_main.c b/stack/l2cap/l2c_main.c
index caef05f..e59b760 100755
--- a/stack/l2cap/l2c_main.c
+++ b/stack/l2cap/l2c_main.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 
 #include "controller.h"
+#include "counter.h"
 #include "gki.h"
 #include "hcimsgs.h"
 #include "l2cdefs.h"
@@ -99,6 +100,9 @@
 
     if (p_buf->len <= controller_get_interface()->get_acl_packet_size_classic())
     {
+        counter_add("l2cap.ch2.tx.bytes", p_buf->len);
+        counter_add("l2cap.ch2.tx.pkts", 1);
+
         bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL);
     }
 }
@@ -218,11 +222,15 @@
     /* Send the data through the channel state machine */
     if (rcv_cid == L2CAP_SIGNALLING_CID)
     {
+        counter_add("l2cap.sig.rx.bytes", l2cap_len);
+        counter_add("l2cap.sig.rx.pkts", 1);
         process_l2cap_cmd (p_lcb, p, l2cap_len);
         GKI_freebuf (p_msg);
     }
     else if (rcv_cid == L2CAP_CONNECTIONLESS_CID)
     {
+        counter_add("l2cap.ch2.rx.bytes", l2cap_len);
+        counter_add("l2cap.ch2.rx.pkts", 1);
         /* process_connectionless_data (p_lcb); */
         STREAM_TO_UINT16 (psm, p);
         L2CAP_TRACE_DEBUG( "GOT CONNECTIONLESS DATA PSM:%d", psm ) ;
@@ -240,6 +248,8 @@
 #if (BLE_INCLUDED == TRUE)
     else if (rcv_cid == L2CAP_BLE_SIGNALLING_CID)
     {
+        counter_add("l2cap.ble.rx.bytes", l2cap_len);
+        counter_add("l2cap.ble.rx.pkts", 1);
         l2cble_process_sig_cmd (p_lcb, p, l2cap_len);
         GKI_freebuf (p_msg);
     }
@@ -248,6 +258,8 @@
     else if ((rcv_cid >= L2CAP_FIRST_FIXED_CHNL) && (rcv_cid <= L2CAP_LAST_FIXED_CHNL) &&
              (l2cb.fixed_reg[rcv_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb != NULL) )
     {
+        counter_add("l2cap.fix.rx.bytes", l2cap_len);
+        counter_add("l2cap.fix.rx.pkts", 1);
         /* If no CCB for this channel, allocate one */
         if (p_lcb &&
             /* discard fixed channel data when link is disconnecting */
@@ -272,6 +284,8 @@
 
     else
     {
+        counter_add("l2cap.dyn.rx.bytes", l2cap_len);
+        counter_add("l2cap.dyn.rx.pkts", 1);
         if (p_ccb == NULL)
             GKI_freebuf (p_msg);
         else
@@ -972,6 +986,9 @@
         return (L2CAP_DW_FAILED);
     }
 
+    counter_add("l2cap.dyn.tx.bytes", p_data->len);
+    counter_add("l2cap.dyn.tx.pkts", 1);
+
     l2c_csm_execute (p_ccb, L2CEVT_L2CA_DATA_WRITE, p_data);
 
     if (p_ccb->cong_sent)
diff --git a/stack/l2cap/l2c_utils.c b/stack/l2cap/l2c_utils.c
index d393c34..ed1f2db 100644
--- a/stack/l2cap/l2c_utils.c
+++ b/stack/l2cap/l2c_utils.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 
 #include "controller.h"
+#include "counter.h"
 #include "gki.h"
 #include "bt_types.h"
 #include "hcimsgs.h"
@@ -382,11 +383,16 @@
 #if (BLE_INCLUDED == TRUE)
     if (p_lcb->transport == BT_TRANSPORT_LE)
     {
+        counter_add("l2cap.ble.tx.bytes", p_buf->len);
+        counter_add("l2cap.ble.tx.pkts", 1);
+
         UINT16_TO_STREAM (p, L2CAP_BLE_SIGNALLING_CID);
     }
     else
 #endif
     {
+        counter_add("l2cap.sig.tx.bytes", p_buf->len);
+        counter_add("l2cap.sig.tx.pkts", 1);
         UINT16_TO_STREAM (p, L2CAP_SIGNALLING_CID);
     }
 
diff --git a/stack/rfcomm/port_api.c b/stack/rfcomm/port_api.c
index 83c94da..c375497 100644
--- a/stack/rfcomm/port_api.c
+++ b/stack/rfcomm/port_api.c
@@ -24,6 +24,7 @@
 
 #include <string.h>
 #include "bt_target.h"
+#include "counter.h"
 #include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
@@ -84,6 +85,8 @@
     tRFC_MCB   *p_mcb = port_find_mcb (bd_addr);
     UINT16     rfcomm_mtu;
 
+    counter_add("rfcomm.conn.created", 1);
+
     RFCOMM_TRACE_API ("RFCOMM_CreateConnection()  BDA: %02x-%02x-%02x-%02x-%02x-%02x",
                        bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
 
@@ -209,6 +212,8 @@
 {
     tPORT      *p_port;
 
+    counter_add("rfcomm.conn.destroyed", 1);
+
     RFCOMM_TRACE_API ("RFCOMM_RemoveConnection() handle:%d", handle);
 
     /* Check if handle is valid to avoid crashing */
diff --git a/stack/rfcomm/rfc_l2cap_if.c b/stack/rfcomm/rfc_l2cap_if.c
index 5889257..9c11d06 100644
--- a/stack/rfcomm/rfc_l2cap_if.c
+++ b/stack/rfcomm/rfc_l2cap_if.c
@@ -23,6 +23,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "counter.h"
 #include "gki.h"
 
 #include "rfcdefs.h"
@@ -364,6 +365,9 @@
 
     if (event == RFC_EVENT_UIH)
     {
+        counter_add("rfcomm.rx.frames", 1);
+        counter_add("rfcomm.rx.bytes", p_buf->len);
+
         if (p_buf->len > 0)
             rfc_port_sm_execute (p_port, event, p_buf);
         else
diff --git a/stack/rfcomm/rfc_ts_frames.c b/stack/rfcomm/rfc_ts_frames.c
index 6b15831..5addf4a 100644
--- a/stack/rfcomm/rfc_ts_frames.c
+++ b/stack/rfcomm/rfc_ts_frames.c
@@ -22,6 +22,7 @@
  *
  ******************************************************************************/
 #include "bt_target.h"
+#include "counter.h"
 #include "gki.h"
 #include "rfcdefs.h"
 #include "port_api.h"
@@ -215,7 +216,8 @@
     }
     else
     {
-
+        counter_add("rfcomm.tx.frames", 1);
+        counter_add("rfcomm.tx.bytes", p_buf->len);
         L2CA_DataWrite (p_mcb->lcid, p_buf);
     }
 }