tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: btuart and SOCKET Bluetooth CF



On Sat, 23 Jan 2010, Iain Hibbert wrote:

> In this direction, I can suggest some optimisation?  diff is attached
> (needs some work, is only general cut and paste)

Further optimisation attached (in addition to previous diff) by use of
'drop' indicator to drop pad bytes between packets rather than
recalculating sizes. Can lose the additional states for DTL packets.

regards,
iain
--- btuart.c.orig2      2010-01-23 20:11:27.000000000 +0000
+++ btuart.c    2010-01-23 20:28:52.000000000 +0000
@@ -55,6 +55,7 @@
        device_t        sc_dev;
        struct tty *    sc_tp;          /* tty pointer */
 
+       bool            sc_drop;        /* drop bytes between packets */
        bool            sc_dtl;         /* using Nokia DTL headers */
        bool            sc_enabled;     /* device is enabled */
        struct hci_unit *sc_unit;       /* Bluetooth HCI handle */
@@ -82,10 +83,7 @@
 #define BTUART_RECV_SCO_DATA           5       /* sco packet data */
 #define BTUART_RECV_EVENT_DATA         6       /* event packet data */
 #define BTUART_RECV_DTL_HDR            7       /* DTL header */
-#define BTUART_RECV_DTL_CTRL_DATA      8       /* DTL control data */
-#define BTUART_RECV_DTL_ACL_DATA       9       /* DTL acl data */
-#define BTUART_RECV_DTL_SCO_DATA       10      /* DTL sco data */
-#define BTUART_RECV_DTL_EVENT_DATA     11      /* DTL event data */
+#define BTUART_RECV_DTL_DATA           8       /* DTL data */
 
 struct btuart_dtl_header {     /* NOKIA DTL-1/4 header */
        uint8_t type;           /*   packet type */
@@ -393,6 +391,12 @@
 
        if (space == 0) {
                if (m == NULL) {
+                       /* drop padding between packets (for DTL) */
+                       if (sc->sc_drop) {
+                               sc->sc_drop = false;
+                               return 0;
+                       }
+
                        /* new packet */
                        MGETHDR(m, M_DONTWAIT, MT_DATA);
                        if (m == NULL) {
@@ -406,7 +410,7 @@
                        space = MHLEN;
 
                        if (sc->sc_dtl) {
-                               sc->sc_state = BTUART_RECV_DTL_HEADER;
+                               sc->sc_state = BTUART_RECV_DTL_HDR;
                                sc->sc_want = sizeof(struct btdtl_header);
                        } else {
                                sc->sc_state = BTUART_RECV_PKT_TYPE;
@@ -471,41 +475,43 @@
 
                break;
 
-       case BTUART_RECV_DTL_HEADER:    /* Got Nokia DTL header */
+       /*
+        * we assume (correctly of course :) that the packet headers all fit
+        * into a single pkthdr mbuf
+        */
+       case BTUART_RECV_DTL_HDR:       /* Got Nokia DTL header */
+               dtl = mtod(sc->sc_rxp, struct dtl_header *);
 
-               switch (c) {
-               case BTUART_DTL_HEADER_TYPE:
-                       sc->sc_state = BTUART_RECV_DTL_CTRL_DATA;
-                       break;
+               sc->sc_want = le16toh(dtlh->len);
+               if (sc->sc_want & 0x0001)
+                       sc->sc_drop = true;
 
+               switch (dtl->type) {
                case BTUART_DTL_HEADER_TYPE | HCI_ACL_DATA_PKT:
-                       sc->sc_state = BTUART_RECV_DTL_ACL_DATA;
+                       sc->sc_state = BTUART_RECV_ACL_DATA;
+                       dtl->type = HCI_ACL_DATA_PKT;
+                       m_adj(sc->sc_rxp, 1 - sizeof(struct dtl_header));
                        break;
 
                case BTUART_DTL_HEADER_TYPE | HCI_SCO_DATA_PKT:
-                       sc->sc_state = BTUART_RECV_DTL_SCO_DATA;
+                       sc->sc_state = BTUART_RECV_SCO_DATA;
+                       dtl->type = HCI_SCO_DATA_PKT;
+                       m_adj(sc->sc_rxp, 1 - sizeof(struct dtl_header));
                        break;
 
                case BTUART_DTL_HEADER_TYPE | HCI_EVENT_PKT:
-                       sc->sc_state = BTUART_RECV_DTL_EVENT_DATA;
+                       sc->sc_state = BTUART_RECV_EVENT_DATA;
+                       dtl->type = HCI_EVENT_DATA_PKT;
+                       m_adj(sc->sc_rxp, 1 - sizeof(struct dtl_header));
                        break;
 
+               case BTUART_DTL_HEADER_TYPE:
                default:
-                       aprint_error_dev(sc->sc_dev,
-                           "Unknown packet type=%#x!\n", dtlh->type);
-                       sc->sc_stats.err_rx++;
-                       m_adj(m, 1);
-                       sc->sc_want++;          /* (lost sync) try more 1byte */
-                       return 0;
+                       sc->sc_state = BTUART_RECV_DTL_DATA;
+                       break;
                }
-               dtlh->len = le16toh(dtlh->len);
-               sc->sc_want = (dtlh->len + 1) & ~0x0001;
                break;
 
-       /*
-        * we assume (correctly of course :) that the packet headers all fit
-        * into a single pkthdr mbuf
-        */
        case BTUART_RECV_ACL_HDR:       /* Got ACL Header */
                sc->sc_state = BTUART_RECV_ACL_DATA;
                sc->sc_want = mtod(m, hci_acldata_hdr_t *)->length;
@@ -522,20 +528,6 @@
                sc->sc_want = mtod(m, hci_event_hdr_t *)->length;
                break;
 
-       case BTUART_RECV_DTL_CTRL_DATA: /* Control Packet Complete */
-               btuart_dump(sc->sc_dev, sc->sc_rxp);
-               m_freem(sc->sc_rxp);
-               sc->sc_rxp = NULL;
-               break;
-
-       case BTUART_RECV_DTL_ACL_DATA:  /* ACL Packet Complete */
-               if (dtlh->len & 0x0001)
-                       m_adj(m, -1);
-               m_adj(sc->sc_rxp,
-                   sizeof(struct btuart_dtl_header) - sizeof(uint8_t));
-               *mtod(sc->sc_rxp, uint8_t *) = HCI_ACL_DATA_PKT;
-
-               /* FALLTHROUGH */
        case BTUART_RECV_ACL_DATA:      /* ACL Packet Complete */
                if (!hci_input_acl(sc->sc_unit, sc->sc_rxp))
                        sc->sc_stats.err_rx++;
@@ -544,14 +536,6 @@
                sc->sc_rxp = NULL;
                break;
 
-       case BTUART_RECV_DTL_SCO_DATA:  /* SCO Packet Complete */
-               if (dtlh->len & 0x0001)
-                       m_adj(m, -1);
-               m_adj(sc->sc_rxp,
-                   sizeof(struct btuart_dtl_header) - sizeof(uint8_t));
-               *mtod(sc->sc_rxp, uint8_t *) = HCI_SCO_DATA_PKT;
-
-               /* FALLTHROUGH */
        case BTUART_RECV_SCO_DATA:      /* SCO Packet Complete */
                if (!hci_input_sco(sc->sc_unit, sc->sc_rxp))
                        sc->sc_stats.err_rx++;
@@ -560,14 +544,6 @@
                sc->sc_rxp = NULL;
                break;
 
-       case BTUART_RECV_DTL_EVENT_DATA:/* Event Packet Complete */
-               if (dtlh->len & 0x0001)
-                       m_adj(m, -1);
-               m_adj(sc->sc_rxp,
-                   sizeof(struct btuart_dtl_header) - sizeof(uint8_t));
-               *mtod(sc->sc_rxp, uint8_t *) = HCI_EVENT_PKT;
-
-               /* FALLTHROUGH */
        case BTUART_RECV_EVENT_DATA:    /* Event Packet Complete */
                if (!hci_input_event(sc->sc_unit, sc->sc_rxp))
                        sc->sc_stats.err_rx++;
@@ -576,6 +552,12 @@
                sc->sc_rxp = NULL;
                break;
 
+       case BTUART_RECV_DTL_DATA:      /* (unknown) DTL Packet Complete */
+               btuart_dtl_dump(sc->sc_dev, sc->sc_rxp);
+               m_freem(sc->sc_rxp);
+               sc->sc_rxp = NULL;
+               break;
+
        default:
                panic("%s: invalid state %d!\n",
                    device_xname(sc->sc_dev), sc->sc_state);


Home | Main Index | Thread Index | Old Index