X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fbluetooth%2Fhci_bcsp.c;h=4d37bb312ee3bdd02ed60f90f4d7b7650c9dc993;hb=f894d18380e7e7ff05f6622ccb75d2881922c6e9;hp=d0cface535fb33e851aeab4548c2bcd6097340dd;hpb=c0bc8721b8d0380ec69fa97578c91201201b05a9;p=linux-2.6 diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c index d0cface535..4d37bb312e 100644 --- a/drivers/bluetooth/hci_bcsp.c +++ b/drivers/bluetooth/hci_bcsp.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -40,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -125,27 +126,6 @@ static void bcsp_crc_update(u16 *crc, u8 d) *crc = reg; } -/* - Get reverse of generated crc - - Implementation note - The crc generator (bcsp_crc_init() and bcsp_crc_update()) - creates a reversed crc, so it needs to be swapped back before - being passed on. -*/ -static u16 bcsp_crc_reverse(u16 crc) -{ - u16 b, rev; - - for (b = 0, rev = 0; b < 16; b++) { - rev = rev << 1; - rev |= (crc & 1); - crc = crc >> 1; - } - - return (rev); -} - /* ---- BCSP core ---- */ static void bcsp_slip_msgdelim(struct sk_buff *skb) @@ -236,9 +216,10 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data, } if (hciextn && chan == 5) { - struct hci_command_hdr *hdr = (struct hci_command_hdr *) data; + __le16 opcode = ((struct hci_command_hdr *)data)->opcode; - if (hci_opcode_ogf(__le16_to_cpu(hdr->opcode)) == OGF_VENDOR_CMD) { + /* Vendor specific commands */ + if (hci_opcode_ogf(__le16_to_cpu(opcode)) == 0x3f) { u8 desc = *(data + HCI_COMMAND_HDR_SIZE); if ((desc & 0xf0) == 0xc0) { data += HCI_COMMAND_HDR_SIZE + 1; @@ -296,7 +277,7 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data, /* Put CRC */ if (bcsp->use_crc) { - bcsp_txmsg_crc = bcsp_crc_reverse(bcsp_txmsg_crc); + bcsp_txmsg_crc = bitrev16(bcsp_txmsg_crc); bcsp_slip_one_byte(nskb, (u8) ((bcsp_txmsg_crc >> 8) & 0x00ff)); bcsp_slip_one_byte(nskb, (u8) (bcsp_txmsg_crc & 0x00ff)); } @@ -330,7 +311,7 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu) reliable packet if the number of packets sent but not yet ack'ed is < than the winsize */ - spin_lock_irqsave(&bcsp->unack.lock, flags); + spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING); if (bcsp->unack.qlen < BCSP_TXWINSIZE && (skb = skb_dequeue(&bcsp->rel)) != NULL) { struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type); @@ -566,6 +547,11 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu) bcsp->rx_skb = NULL; } +static u16 bscp_get_crc(struct bcsp_struct *bcsp) +{ + return get_unaligned_be16(&bcsp->rx_skb->data[bcsp->rx_skb->len - 2]); +} + /* Recv data */ static int bcsp_recv(struct hci_uart *hu, void *data, int count) { @@ -624,14 +610,10 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count) continue; case BCSP_W4_CRC: - if (bcsp_crc_reverse(bcsp->message_crc) != - (bcsp->rx_skb->data[bcsp->rx_skb->len - 2] << 8) + - bcsp->rx_skb->data[bcsp->rx_skb->len - 1]) { - + if (bitrev16(bcsp->message_crc) != bscp_get_crc(bcsp)) { BT_ERR ("Checksum failed: computed %04x received %04x", - bcsp_crc_reverse(bcsp->message_crc), - (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) + - bcsp->rx_skb->data[bcsp->rx_skb->len - 1]); + bitrev16(bcsp->message_crc), + bscp_get_crc(bcsp)); kfree_skb(bcsp->rx_skb); bcsp->rx_state = BCSP_W4_PKT_DELIMITER; @@ -696,7 +678,7 @@ static void bcsp_timed_event(unsigned long arg) BT_DBG("hu %p retransmitting %u pkts", hu, bcsp->unack.qlen); - spin_lock_irqsave(&bcsp->unack.lock, flags); + spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING); while ((skb = __skb_dequeue_tail(&bcsp->unack)) != NULL) { bcsp->msgq_txseq = (bcsp->msgq_txseq - 1) & 0x07;