diff options
-rw-r--r-- | drivers/nfc/pn544_hci.c | 32 | ||||
-rw-r--r-- | net/nfc/hci/shdlc.c | 27 |
2 files changed, 32 insertions, 27 deletions
diff --git a/drivers/nfc/pn544_hci.c b/drivers/nfc/pn544_hci.c index 9458d53cdb59..d90aecfce739 100644 --- a/drivers/nfc/pn544_hci.c +++ b/drivers/nfc/pn544_hci.c | |||
@@ -128,6 +128,8 @@ static struct nfc_hci_gate pn544_gates[] = { | |||
128 | 128 | ||
129 | /* Largest headroom needed for outgoing custom commands */ | 129 | /* Largest headroom needed for outgoing custom commands */ |
130 | #define PN544_CMDS_HEADROOM 2 | 130 | #define PN544_CMDS_HEADROOM 2 |
131 | #define PN544_FRAME_HEADROOM 1 | ||
132 | #define PN544_FRAME_TAILROOM 2 | ||
131 | 133 | ||
132 | struct pn544_hci_info { | 134 | struct pn544_hci_info { |
133 | struct i2c_client *i2c_dev; | 135 | struct i2c_client *i2c_dev; |
@@ -576,15 +578,40 @@ static int pn544_hci_ready(struct nfc_shdlc *shdlc) | |||
576 | return 0; | 578 | return 0; |
577 | } | 579 | } |
578 | 580 | ||
581 | static void pn544_hci_add_len_crc(struct sk_buff *skb) | ||
582 | { | ||
583 | u16 crc; | ||
584 | int len; | ||
585 | |||
586 | len = skb->len + 2; | ||
587 | *skb_push(skb, 1) = len; | ||
588 | |||
589 | crc = crc_ccitt(0xffff, skb->data, skb->len); | ||
590 | crc = ~crc; | ||
591 | *skb_put(skb, 1) = crc & 0xff; | ||
592 | *skb_put(skb, 1) = crc >> 8; | ||
593 | } | ||
594 | |||
595 | static void pn544_hci_remove_len_crc(struct sk_buff *skb) | ||
596 | { | ||
597 | skb_pull(skb, PN544_FRAME_HEADROOM); | ||
598 | skb_trim(skb, PN544_FRAME_TAILROOM); | ||
599 | } | ||
600 | |||
579 | static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb) | 601 | static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb) |
580 | { | 602 | { |
581 | struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc); | 603 | struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc); |
582 | struct i2c_client *client = info->i2c_dev; | 604 | struct i2c_client *client = info->i2c_dev; |
605 | int r; | ||
583 | 606 | ||
584 | if (info->hard_fault != 0) | 607 | if (info->hard_fault != 0) |
585 | return info->hard_fault; | 608 | return info->hard_fault; |
586 | 609 | ||
587 | return pn544_hci_i2c_write(client, skb->data, skb->len); | 610 | pn544_hci_add_len_crc(skb); |
611 | r = pn544_hci_i2c_write(client, skb->data, skb->len); | ||
612 | pn544_hci_remove_len_crc(skb); | ||
613 | |||
614 | return r; | ||
588 | } | 615 | } |
589 | 616 | ||
590 | static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, | 617 | static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, |
@@ -874,7 +901,8 @@ static int __devinit pn544_hci_probe(struct i2c_client *client, | |||
874 | 901 | ||
875 | info->shdlc = nfc_shdlc_allocate(&pn544_shdlc_ops, | 902 | info->shdlc = nfc_shdlc_allocate(&pn544_shdlc_ops, |
876 | &init_data, protocols, | 903 | &init_data, protocols, |
877 | PN544_CMDS_HEADROOM, 0, | 904 | PN544_FRAME_HEADROOM + PN544_CMDS_HEADROOM, |
905 | PN544_FRAME_TAILROOM, | ||
878 | PN544_HCI_LLC_MAX_PAYLOAD, | 906 | PN544_HCI_LLC_MAX_PAYLOAD, |
879 | dev_name(&client->dev)); | 907 | dev_name(&client->dev)); |
880 | if (!info->shdlc) { | 908 | if (!info->shdlc) { |
diff --git a/net/nfc/hci/shdlc.c b/net/nfc/hci/shdlc.c index 824fb09384ed..ed8796b78f39 100644 --- a/net/nfc/hci/shdlc.c +++ b/net/nfc/hci/shdlc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/sched.h> | 22 | #include <linux/sched.h> |
23 | #include <linux/export.h> | 23 | #include <linux/export.h> |
24 | #include <linux/wait.h> | 24 | #include <linux/wait.h> |
25 | #include <linux/crc-ccitt.h> | ||
26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
27 | #include <linux/skbuff.h> | 26 | #include <linux/skbuff.h> |
28 | 27 | ||
@@ -30,7 +29,6 @@ | |||
30 | #include <net/nfc/shdlc.h> | 29 | #include <net/nfc/shdlc.h> |
31 | 30 | ||
32 | #define SHDLC_LLC_HEAD_ROOM 2 | 31 | #define SHDLC_LLC_HEAD_ROOM 2 |
33 | #define SHDLC_LLC_TAIL_ROOM 2 | ||
34 | 32 | ||
35 | #define SHDLC_MAX_WINDOW 4 | 33 | #define SHDLC_MAX_WINDOW 4 |
36 | #define SHDLC_SREJ_SUPPORT false | 34 | #define SHDLC_SREJ_SUPPORT false |
@@ -94,28 +92,13 @@ static struct sk_buff *nfc_shdlc_alloc_skb(struct nfc_shdlc *shdlc, | |||
94 | struct sk_buff *skb; | 92 | struct sk_buff *skb; |
95 | 93 | ||
96 | skb = alloc_skb(shdlc->client_headroom + SHDLC_LLC_HEAD_ROOM + | 94 | skb = alloc_skb(shdlc->client_headroom + SHDLC_LLC_HEAD_ROOM + |
97 | shdlc->client_tailroom + SHDLC_LLC_TAIL_ROOM + | 95 | shdlc->client_tailroom + payload_len, GFP_KERNEL); |
98 | payload_len, GFP_KERNEL); | ||
99 | if (skb) | 96 | if (skb) |
100 | skb_reserve(skb, shdlc->client_headroom + SHDLC_LLC_HEAD_ROOM); | 97 | skb_reserve(skb, shdlc->client_headroom + SHDLC_LLC_HEAD_ROOM); |
101 | 98 | ||
102 | return skb; | 99 | return skb; |
103 | } | 100 | } |
104 | 101 | ||
105 | static void nfc_shdlc_add_len_crc(struct sk_buff *skb) | ||
106 | { | ||
107 | u16 crc; | ||
108 | int len; | ||
109 | |||
110 | len = skb->len + 2; | ||
111 | *skb_push(skb, 1) = len; | ||
112 | |||
113 | crc = crc_ccitt(0xffff, skb->data, skb->len); | ||
114 | crc = ~crc; | ||
115 | *skb_put(skb, 1) = crc & 0xff; | ||
116 | *skb_put(skb, 1) = crc >> 8; | ||
117 | } | ||
118 | |||
119 | /* immediately sends an S frame. */ | 102 | /* immediately sends an S frame. */ |
120 | static int nfc_shdlc_send_s_frame(struct nfc_shdlc *shdlc, | 103 | static int nfc_shdlc_send_s_frame(struct nfc_shdlc *shdlc, |
121 | enum sframe_type sframe_type, int nr) | 104 | enum sframe_type sframe_type, int nr) |
@@ -131,8 +114,6 @@ static int nfc_shdlc_send_s_frame(struct nfc_shdlc *shdlc, | |||
131 | 114 | ||
132 | *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_S | (sframe_type << 3) | nr; | 115 | *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_S | (sframe_type << 3) | nr; |
133 | 116 | ||
134 | nfc_shdlc_add_len_crc(skb); | ||
135 | |||
136 | r = shdlc->ops->xmit(shdlc, skb); | 117 | r = shdlc->ops->xmit(shdlc, skb); |
137 | 118 | ||
138 | kfree_skb(skb); | 119 | kfree_skb(skb); |
@@ -151,8 +132,6 @@ static int nfc_shdlc_send_u_frame(struct nfc_shdlc *shdlc, | |||
151 | 132 | ||
152 | *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_U | uframe_modifier; | 133 | *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_U | uframe_modifier; |
153 | 134 | ||
154 | nfc_shdlc_add_len_crc(skb); | ||
155 | |||
156 | r = shdlc->ops->xmit(shdlc, skb); | 135 | r = shdlc->ops->xmit(shdlc, skb); |
157 | 136 | ||
158 | kfree_skb(skb); | 137 | kfree_skb(skb); |
@@ -509,8 +488,6 @@ static void nfc_shdlc_handle_send_queue(struct nfc_shdlc *shdlc) | |||
509 | shdlc->nr); | 488 | shdlc->nr); |
510 | /* SHDLC_DUMP_SKB("shdlc frame written", skb); */ | 489 | /* SHDLC_DUMP_SKB("shdlc frame written", skb); */ |
511 | 490 | ||
512 | nfc_shdlc_add_len_crc(skb); | ||
513 | |||
514 | r = shdlc->ops->xmit(shdlc, skb); | 491 | r = shdlc->ops->xmit(shdlc, skb); |
515 | if (r < 0) { | 492 | if (r < 0) { |
516 | shdlc->hard_fault = r; | 493 | shdlc->hard_fault = r; |
@@ -880,7 +857,7 @@ struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops, | |||
880 | 857 | ||
881 | shdlc->hdev = nfc_hci_allocate_device(&shdlc_ops, init_data, protocols, | 858 | shdlc->hdev = nfc_hci_allocate_device(&shdlc_ops, init_data, protocols, |
882 | tx_headroom + SHDLC_LLC_HEAD_ROOM, | 859 | tx_headroom + SHDLC_LLC_HEAD_ROOM, |
883 | tx_tailroom + SHDLC_LLC_TAIL_ROOM, | 860 | tx_tailroom, |
884 | max_link_payload); | 861 | max_link_payload); |
885 | if (shdlc->hdev == NULL) | 862 | if (shdlc->hdev == NULL) |
886 | goto err_allocdev; | 863 | goto err_allocdev; |