Bluetooth: hci_uart: Provide generic H:4 receive framework
Marcel Holtmann
maintainerPATCH 1/1 Bluetooth: hci_uart: Provide generic H:4 receive framework
Future H:4 based UART drivers require custom packet types and custom receive functions. To support this, extended the h4_recv_buf function with a packet definition table.
For the default H:4 packets types of ACL data, SCO data and events, provide helpers to reduce the amount of code duplication.
Signed-off-by Marcel Holtmann <[email protected]>
--- drivers/bluetooth/hci_ath.c | 9 +++- drivers/bluetooth/hci_bcm.c | 9 +++- drivers/bluetooth/hci_h4.c | 119 ++++++++++++++++++++++--------------------- drivers/bluetooth/hci_uart.h | 33 +++++++++++- 4 files changed, 110 insertions(+), 60 deletions(-)
drivers/bluetooth/hci_ath.c +8 -1
@@ -190,12 +190,19 @@ static struct sk_buff *ath_dequeue(struct hci_uart *hu)return skb_dequeue (&ath->txq); } +static const struct h4_recv_pkt ath_recv_pkts[] = { + {H4_RECV_ACL , .recv = hci_recv_frame }, + {H4_RECV_SCO , .recv = hci_recv_frame }, + {H4_RECV_EVENT , .recv = hci_recv_frame }, +}; +/* Recv data */ static int ath_recv (struct hci_uart *hu,const void *data,int count) {struct ath_struct *ath = hu->priv; - ath->rx_skb =h4_recv_buf (hu->hdev, ath->rx_skb, data, count); + ath->rx_skb =h4_recv_buf (hu->hdev, ath->rx_skb, data, count, + ath_recv_pkts,ARRAY_SIZE (ath_recv_pkts));if (IS_ERR (ath->rx_skb)) {int err =PTR_ERR (ath->rx_skb);BT_ERR ("%s: Frame reassembly failed (%d)" , hu->hdev->name, err);
drivers/bluetooth/hci_bcm.c +8 -1
@@ -86,6 +86,12 @@ static int bcm_setup(struct hci_uart *hu)return btbcm_setup_patchram (hu->hdev); } +static const struct h4_recv_pkt bcm_recv_pkts[] = { + {H4_RECV_ACL , .recv = hci_recv_frame }, + {H4_RECV_SCO , .recv = hci_recv_frame }, + {H4_RECV_EVENT , .recv = hci_recv_frame }, +}; +static int bcm_recv (struct hci_uart *hu,const void *data,int count) {struct bcm_data *bcm = hu->priv;
@@ -93,7 +99,8 @@ static int bcm_recv(struct hci_uart *hu, const void *data, int count)if (!test_bit (HCI_UART_REGISTERED , &hu->flags))return -EUNATCH ; - bcm->rx_skb =h4_recv_buf (hu->hdev, bcm->rx_skb, data, count); + bcm->rx_skb =h4_recv_buf (hu->hdev, bcm->rx_skb, data, count, + bcm_recv_pkts,ARRAY_SIZE (bcm_recv_pkts));if (IS_ERR (bcm->rx_skb)) {int err =PTR_ERR (bcm->rx_skb);BT_ERR ("%s: Frame reassembly failed (%d)" , hu->hdev->name, err);
drivers/bluetooth/hci_h4.c +62 -57
177 lines not on this page · raw message
drivers/bluetooth/hci_uart.h +32 -1
@@ -101,8 +101,39 @@ int hci_uart_init_ready(struct hci_uart *hu);int h4_init (void );int h4_deinit (void ); +struct h4_recv_pkt { +u8 type;/* Packet type */ +u8 hlen;/* Header length */ +u8 loff;/* Data length offset in header */ +u8 lsize;/* Data length field size */ +u16 maxlen;/* Max overall packet length */ +int (*recv)(struct hci_dev *hdev,struct sk_buff *skb); +}; + +#define H4_RECV_ACL \ + .type = HCI_ACLDATA_PKT, \ + .hlen = HCI_ACL_HDR_SIZE, \ + .loff = 2, \ + .lsize = 2, \ + .maxlen = HCI_MAX_FRAME_SIZE \ + +#define H4_RECV_SCO \ + .type = HCI_SCODATA_PKT, \ + .hlen = HCI_SCO_HDR_SIZE, \ + .loff = 2, \ + .lsize = 1, \ + .maxlen = HCI_MAX_SCO_SIZE + +#define H4_RECV_EVENT \ + .type = HCI_EVENT_PKT, \ + .hlen = HCI_EVENT_HDR_SIZE, \ + .loff = 1, \ + .lsize = 1, \ + .maxlen = HCI_MAX_EVENT_SIZE +struct sk_buff *h4_recv_buf (struct hci_dev *hdev,struct sk_buff *skb, -const unsigned char *buffer,int count); +const unsigned char *buffer,int count, +const struct h4_recv_pkt *pkts,int pkts_count);#endif #ifdef CONFIG_BT_HCIUART_BCSP
Signature · 1 line
2.1.0
Johan Hedberg
AppliedHi Marcel,
Quoted 7 lines · Marcel Holtmann
Future H:4 based UART drivers require custom packet types and custom receive functions. To support this, extended the
h4_recv_buffunction with a packet definition table.For the default H:4 packets types of ACL data, SCO data and events, provide helpers to reduce the amount of code duplication.
Quoted 7 lines
Signed-off-by Marcel Holtmann <[email protected]>--- drivers/bluetooth/hci_ath.c | 9 +++- drivers/bluetooth/hci_bcm.c | 9 +++- drivers/bluetooth/hci_h4.c | 119 ++++++++++++++++++++++--------------------- drivers/bluetooth/hci_uart.h | 33 +++++++++++- 4 files changed, 110 insertions(+), 60 deletions(-)
Applied to bluetooth-next. Thanks.
Johan