Bluetooth: Improve Three-wire UART configuration handling
[deliverable/linux.git] / drivers / bluetooth / hci_h5.c
1 /*
2 *
3 * Bluetooth HCI Three-wire UART driver
4 *
5 * Copyright (C) 2012 Intel Corporation
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/skbuff.h>
27
28 #include <net/bluetooth/bluetooth.h>
29 #include <net/bluetooth/hci_core.h>
30
31 #include "hci_uart.h"
32
33 #define HCI_3WIRE_ACK_PKT 0
34 #define HCI_3WIRE_LINK_PKT 15
35
36 /* Sliding window size */
37 #define H5_TX_WIN_MAX 4
38
39 #define H5_ACK_TIMEOUT msecs_to_jiffies(250)
40 #define H5_SYNC_TIMEOUT msecs_to_jiffies(100)
41
42 /*
43 * Maximum Three-wire packet:
44 * 4 byte header + max value for 12-bit length + 2 bytes for CRC
45 */
46 #define H5_MAX_LEN (4 + 0xfff + 2)
47
48 /* Convenience macros for reading Three-wire header values */
49 #define H5_HDR_SEQ(hdr) ((hdr)[0] & 0x07)
50 #define H5_HDR_ACK(hdr) (((hdr)[0] >> 3) & 0x07)
51 #define H5_HDR_CRC(hdr) (((hdr)[0] >> 6) & 0x01)
52 #define H5_HDR_RELIABLE(hdr) (((hdr)[0] >> 7) & 0x01)
53 #define H5_HDR_PKT_TYPE(hdr) ((hdr)[1] & 0x0f)
54 #define H5_HDR_LEN(hdr) ((((hdr)[1] >> 4) & 0xff) + ((hdr)[2] << 4))
55
56 #define SLIP_DELIMITER 0xc0
57 #define SLIP_ESC 0xdb
58 #define SLIP_ESC_DELIM 0xdc
59 #define SLIP_ESC_ESC 0xdd
60
61 struct h5 {
62 struct sk_buff_head unack; /* Unack'ed packets queue */
63 struct sk_buff_head rel; /* Reliable packets queue */
64 struct sk_buff_head unrel; /* Unreliable packets queue */
65
66 struct sk_buff *rx_skb; /* Receive buffer */
67 size_t rx_pending; /* Expecting more bytes */
68 bool rx_esc; /* SLIP escape mode */
69 u8 rx_ack; /* Last ack number received */
70
71 int (*rx_func) (struct hci_uart *hu, u8 c);
72
73 struct timer_list timer; /* Retransmission timer */
74
75 bool tx_ack_req; /* Pending ack to send */
76 u8 tx_seq; /* Next seq number to send */
77 u8 tx_ack; /* Next ack number to send */
78 u8 tx_win; /* Sliding window size */
79
80 enum {
81 H5_UNINITIALIZED,
82 H5_INITIALIZED,
83 H5_ACTIVE,
84 } state;
85
86 enum {
87 H5_AWAKE,
88 H5_SLEEPING,
89 H5_WAKING_UP,
90 } sleep;
91 };
92
93 static void h5_reset_rx(struct h5 *h5);
94
95 static void h5_link_control(struct hci_uart *hu, const void *data, size_t len)
96 {
97 struct h5 *h5 = hu->priv;
98 struct sk_buff *nskb;
99
100 nskb = alloc_skb(3, GFP_ATOMIC);
101 if (!nskb)
102 return;
103
104 bt_cb(nskb)->pkt_type = HCI_3WIRE_LINK_PKT;
105
106 memcpy(skb_put(nskb, len), data, len);
107
108 skb_queue_tail(&h5->unrel, nskb);
109 }
110
111 static u8 h5_cfg_field(struct h5 *h5)
112 {
113 u8 field = 0;
114
115 /* Sliding window size (first 3 bits) */
116 field |= (h5->tx_win & 7);
117
118 return field;
119 }
120
121 static void h5_timed_event(unsigned long arg)
122 {
123 const unsigned char sync_req[] = { 0x01, 0x7e };
124 unsigned char conf_req[] = { 0x03, 0xfc, 0x01 };
125 struct hci_uart *hu = (struct hci_uart *) arg;
126 struct h5 *h5 = hu->priv;
127 struct sk_buff *skb;
128 unsigned long flags;
129
130 BT_DBG("%s", hu->hdev->name);
131
132 if (h5->state == H5_UNINITIALIZED)
133 h5_link_control(hu, sync_req, sizeof(sync_req));
134
135 if (h5->state == H5_INITIALIZED) {
136 conf_req[2] = h5_cfg_field(h5);
137 h5_link_control(hu, conf_req, sizeof(conf_req));
138 }
139
140 if (h5->state != H5_ACTIVE) {
141 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT);
142 goto wakeup;
143 }
144
145 if (h5->sleep != H5_AWAKE) {
146 h5->sleep = H5_SLEEPING;
147 goto wakeup;
148 }
149
150 BT_DBG("hu %p retransmitting %u pkts", hu, h5->unack.qlen);
151
152 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING);
153
154 while ((skb = __skb_dequeue_tail(&h5->unack)) != NULL) {
155 h5->tx_seq = (h5->tx_seq - 1) & 0x07;
156 skb_queue_head(&h5->rel, skb);
157 }
158
159 spin_unlock_irqrestore(&h5->unack.lock, flags);
160
161 wakeup:
162 hci_uart_tx_wakeup(hu);
163 }
164
165 static int h5_open(struct hci_uart *hu)
166 {
167 struct h5 *h5;
168 const unsigned char sync[] = { 0x01, 0x7e };
169
170 BT_DBG("hu %p", hu);
171
172 h5 = kzalloc(sizeof(*h5), GFP_KERNEL);
173 if (!h5)
174 return -ENOMEM;
175
176 hu->priv = h5;
177
178 skb_queue_head_init(&h5->unack);
179 skb_queue_head_init(&h5->rel);
180 skb_queue_head_init(&h5->unrel);
181
182 h5_reset_rx(h5);
183
184 init_timer(&h5->timer);
185 h5->timer.function = h5_timed_event;
186 h5->timer.data = (unsigned long) hu;
187
188 h5->tx_win = H5_TX_WIN_MAX;
189
190 set_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags);
191
192 /* Send initial sync request */
193 h5_link_control(hu, sync, sizeof(sync));
194 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT);
195
196 return 0;
197 }
198
199 static int h5_close(struct hci_uart *hu)
200 {
201 struct h5 *h5 = hu->priv;
202
203 skb_queue_purge(&h5->unack);
204 skb_queue_purge(&h5->rel);
205 skb_queue_purge(&h5->unrel);
206
207 del_timer(&h5->timer);
208
209 kfree(h5);
210
211 return 0;
212 }
213
214 static void h5_pkt_cull(struct h5 *h5)
215 {
216 struct sk_buff *skb, *tmp;
217 unsigned long flags;
218 int i, to_remove;
219 u8 seq;
220
221 spin_lock_irqsave(&h5->unack.lock, flags);
222
223 to_remove = skb_queue_len(&h5->unack);
224 if (to_remove == 0)
225 goto unlock;
226
227 seq = h5->tx_seq;
228
229 while (to_remove > 0) {
230 if (h5->rx_ack == seq)
231 break;
232
233 to_remove--;
234 seq = (seq - 1) % 8;
235 }
236
237 if (seq != h5->rx_ack)
238 BT_ERR("Controller acked invalid packet");
239
240 i = 0;
241 skb_queue_walk_safe(&h5->unack, skb, tmp) {
242 if (i++ >= to_remove)
243 break;
244
245 __skb_unlink(skb, &h5->unack);
246 kfree_skb(skb);
247 }
248
249 if (skb_queue_empty(&h5->unack))
250 del_timer(&h5->timer);
251
252 unlock:
253 spin_unlock_irqrestore(&h5->unack.lock, flags);
254 }
255
256 static void h5_handle_internal_rx(struct hci_uart *hu)
257 {
258 struct h5 *h5 = hu->priv;
259 const unsigned char sync_req[] = { 0x01, 0x7e };
260 const unsigned char sync_rsp[] = { 0x02, 0x7d };
261 unsigned char conf_req[] = { 0x03, 0xfc, 0x01 };
262 const unsigned char conf_rsp[] = { 0x04, 0x7b };
263 const unsigned char wakeup_req[] = { 0x05, 0xfa };
264 const unsigned char woken_req[] = { 0x06, 0xf9 };
265 const unsigned char sleep_req[] = { 0x07, 0x78 };
266 const unsigned char *hdr = h5->rx_skb->data;
267 const unsigned char *data = &h5->rx_skb->data[4];
268
269 BT_DBG("%s", hu->hdev->name);
270
271 if (H5_HDR_PKT_TYPE(hdr) != HCI_3WIRE_LINK_PKT)
272 return;
273
274 if (H5_HDR_LEN(hdr) < 2)
275 return;
276
277 conf_req[2] = h5_cfg_field(h5);
278
279 if (memcmp(data, sync_req, 2) == 0) {
280 h5_link_control(hu, sync_rsp, 2);
281 } else if (memcmp(data, sync_rsp, 2) == 0) {
282 h5->state = H5_INITIALIZED;
283 h5_link_control(hu, conf_req, 3);
284 } else if (memcmp(data, conf_req, 2) == 0) {
285 h5_link_control(hu, conf_rsp, 2);
286 h5_link_control(hu, conf_req, 3);
287 } else if (memcmp(data, conf_rsp, 2) == 0) {
288 if (H5_HDR_LEN(hdr) > 2)
289 h5->tx_win = (data[2] & 7);
290 BT_DBG("Three-wire init complete. tx_win %u", h5->tx_win);
291 h5->state = H5_ACTIVE;
292 hci_uart_init_ready(hu);
293 return;
294 } else if (memcmp(data, sleep_req, 2) == 0) {
295 BT_DBG("Peer went to sleep");
296 h5->sleep = H5_SLEEPING;
297 return;
298 } else if (memcmp(data, woken_req, 2) == 0) {
299 BT_DBG("Peer woke up");
300 h5->sleep = H5_AWAKE;
301 } else if (memcmp(data, wakeup_req, 2) == 0) {
302 BT_DBG("Peer requested wakeup");
303 h5_link_control(hu, woken_req, 2);
304 h5->sleep = H5_AWAKE;
305 } else {
306 BT_DBG("Link Control: 0x%02hhx 0x%02hhx", data[0], data[1]);
307 return;
308 }
309
310 hci_uart_tx_wakeup(hu);
311 }
312
313 static void h5_complete_rx_pkt(struct hci_uart *hu)
314 {
315 struct h5 *h5 = hu->priv;
316 const unsigned char *hdr = h5->rx_skb->data;
317
318 if (H5_HDR_RELIABLE(hdr)) {
319 h5->tx_ack = (h5->tx_ack + 1) % 8;
320 h5->tx_ack_req = true;
321 hci_uart_tx_wakeup(hu);
322 }
323
324 h5->rx_ack = H5_HDR_ACK(hdr);
325
326 h5_pkt_cull(h5);
327
328 switch (H5_HDR_PKT_TYPE(hdr)) {
329 case HCI_EVENT_PKT:
330 case HCI_ACLDATA_PKT:
331 case HCI_SCODATA_PKT:
332 bt_cb(h5->rx_skb)->pkt_type = H5_HDR_PKT_TYPE(hdr);
333
334 /* Remove Three-wire header */
335 skb_pull(h5->rx_skb, 4);
336
337 hci_recv_frame(h5->rx_skb);
338 h5->rx_skb = NULL;
339
340 break;
341
342 default:
343 h5_handle_internal_rx(hu);
344 break;
345 }
346
347 h5_reset_rx(h5);
348 }
349
350 static int h5_rx_crc(struct hci_uart *hu, unsigned char c)
351 {
352 struct h5 *h5 = hu->priv;
353
354 h5_complete_rx_pkt(hu);
355 h5_reset_rx(h5);
356
357 return 0;
358 }
359
360 static int h5_rx_payload(struct hci_uart *hu, unsigned char c)
361 {
362 struct h5 *h5 = hu->priv;
363 const unsigned char *hdr = h5->rx_skb->data;
364
365 if (H5_HDR_CRC(hdr)) {
366 h5->rx_func = h5_rx_crc;
367 h5->rx_pending = 2;
368 } else {
369 h5_complete_rx_pkt(hu);
370 h5_reset_rx(h5);
371 }
372
373 return 0;
374 }
375
376 static int h5_rx_3wire_hdr(struct hci_uart *hu, unsigned char c)
377 {
378 struct h5 *h5 = hu->priv;
379 const unsigned char *hdr = h5->rx_skb->data;
380
381 BT_DBG("%s rx: seq %u ack %u crc %u rel %u type %u len %u",
382 hu->hdev->name, H5_HDR_SEQ(hdr), H5_HDR_ACK(hdr),
383 H5_HDR_CRC(hdr), H5_HDR_RELIABLE(hdr), H5_HDR_PKT_TYPE(hdr),
384 H5_HDR_LEN(hdr));
385
386 if (((hdr[0] + hdr[1] + hdr[2] + hdr[3]) & 0xff) != 0xff) {
387 BT_ERR("Invalid header checksum");
388 h5_reset_rx(h5);
389 return 0;
390 }
391
392 if (H5_HDR_RELIABLE(hdr) && H5_HDR_SEQ(hdr) != h5->tx_ack) {
393 BT_ERR("Out-of-order packet arrived (%u != %u)",
394 H5_HDR_SEQ(hdr), h5->tx_ack);
395 h5_reset_rx(h5);
396 return 0;
397 }
398
399 if (h5->state != H5_ACTIVE &&
400 H5_HDR_PKT_TYPE(hdr) != HCI_3WIRE_LINK_PKT) {
401 BT_ERR("Non-link packet received in non-active state");
402 h5_reset_rx(h5);
403 }
404
405 h5->rx_func = h5_rx_payload;
406 h5->rx_pending = H5_HDR_LEN(hdr);
407
408 return 0;
409 }
410
411 static int h5_rx_pkt_start(struct hci_uart *hu, unsigned char c)
412 {
413 struct h5 *h5 = hu->priv;
414
415 if (c == SLIP_DELIMITER)
416 return 1;
417
418 h5->rx_func = h5_rx_3wire_hdr;
419 h5->rx_pending = 4;
420
421 h5->rx_skb = bt_skb_alloc(H5_MAX_LEN, GFP_ATOMIC);
422 if (!h5->rx_skb) {
423 BT_ERR("Can't allocate mem for new packet");
424 h5_reset_rx(h5);
425 return -ENOMEM;
426 }
427
428 h5->rx_skb->dev = (void *) hu->hdev;
429
430 return 0;
431 }
432
433 static int h5_rx_delimiter(struct hci_uart *hu, unsigned char c)
434 {
435 struct h5 *h5 = hu->priv;
436
437 if (c == SLIP_DELIMITER)
438 h5->rx_func = h5_rx_pkt_start;
439
440 return 1;
441 }
442
443 static void h5_unslip_one_byte(struct h5 *h5, unsigned char c)
444 {
445 const u8 delim = SLIP_DELIMITER, esc = SLIP_ESC;
446 const u8 *byte = &c;
447
448 if (!h5->rx_esc && c == SLIP_ESC) {
449 h5->rx_esc = true;
450 return;
451 }
452
453 if (h5->rx_esc) {
454 switch (c) {
455 case SLIP_ESC_DELIM:
456 byte = &delim;
457 break;
458 case SLIP_ESC_ESC:
459 byte = &esc;
460 break;
461 default:
462 BT_ERR("Invalid esc byte 0x%02hhx", c);
463 h5_reset_rx(h5);
464 return;
465 }
466
467 h5->rx_esc = false;
468 }
469
470 memcpy(skb_put(h5->rx_skb, 1), byte, 1);
471 h5->rx_pending--;
472
473 BT_DBG("unsliped 0x%02hhx, rx_pending %zu", *byte, h5->rx_pending);
474 }
475
476 static void h5_reset_rx(struct h5 *h5)
477 {
478 if (h5->rx_skb) {
479 kfree_skb(h5->rx_skb);
480 h5->rx_skb = NULL;
481 }
482
483 h5->rx_func = h5_rx_delimiter;
484 h5->rx_pending = 0;
485 h5->rx_esc = false;
486 }
487
488 static int h5_recv(struct hci_uart *hu, void *data, int count)
489 {
490 struct h5 *h5 = hu->priv;
491 unsigned char *ptr = data;
492
493 BT_DBG("%s pending %zu count %d", hu->hdev->name, h5->rx_pending,
494 count);
495
496 while (count > 0) {
497 int processed;
498
499 if (h5->rx_pending > 0) {
500 if (*ptr == SLIP_DELIMITER) {
501 BT_ERR("Too short H5 packet");
502 h5_reset_rx(h5);
503 continue;
504 }
505
506 h5_unslip_one_byte(h5, *ptr);
507
508 ptr++; count--;
509 continue;
510 }
511
512 processed = h5->rx_func(hu, *ptr);
513 if (processed < 0)
514 return processed;
515
516 ptr += processed;
517 count -= processed;
518 }
519
520 return 0;
521 }
522
523 static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
524 {
525 struct h5 *h5 = hu->priv;
526
527 if (skb->len > 0xfff) {
528 BT_ERR("Packet too long (%u bytes)", skb->len);
529 kfree_skb(skb);
530 return 0;
531 }
532
533 if (h5->state != H5_ACTIVE) {
534 BT_ERR("Ignoring HCI data in non-active state");
535 kfree_skb(skb);
536 return 0;
537 }
538
539 switch (bt_cb(skb)->pkt_type) {
540 case HCI_ACLDATA_PKT:
541 case HCI_COMMAND_PKT:
542 skb_queue_tail(&h5->rel, skb);
543 break;
544
545 case HCI_SCODATA_PKT:
546 skb_queue_tail(&h5->unrel, skb);
547 break;
548
549 default:
550 BT_ERR("Unknown packet type %u", bt_cb(skb)->pkt_type);
551 kfree_skb(skb);
552 break;
553 }
554
555 return 0;
556 }
557
558 static void h5_slip_delim(struct sk_buff *skb)
559 {
560 const char delim = SLIP_DELIMITER;
561
562 memcpy(skb_put(skb, 1), &delim, 1);
563 }
564
565 static void h5_slip_one_byte(struct sk_buff *skb, u8 c)
566 {
567 const char esc_delim[2] = { SLIP_ESC, SLIP_ESC_DELIM };
568 const char esc_esc[2] = { SLIP_ESC, SLIP_ESC_ESC };
569
570 switch (c) {
571 case SLIP_DELIMITER:
572 memcpy(skb_put(skb, 2), &esc_delim, 2);
573 break;
574 case SLIP_ESC:
575 memcpy(skb_put(skb, 2), &esc_esc, 2);
576 break;
577 default:
578 memcpy(skb_put(skb, 1), &c, 1);
579 }
580 }
581
582 static bool valid_packet_type(u8 type)
583 {
584 switch (type) {
585 case HCI_ACLDATA_PKT:
586 case HCI_COMMAND_PKT:
587 case HCI_SCODATA_PKT:
588 case HCI_3WIRE_LINK_PKT:
589 case HCI_3WIRE_ACK_PKT:
590 return true;
591 default:
592 return false;
593 }
594 }
595
596 static struct sk_buff *h5_prepare_pkt(struct hci_uart *hu, u8 pkt_type,
597 const u8 *data, size_t len)
598 {
599 struct h5 *h5 = hu->priv;
600 struct sk_buff *nskb;
601 u8 hdr[4];
602 int i;
603
604 if (!valid_packet_type(pkt_type)) {
605 BT_ERR("Unknown packet type %u", pkt_type);
606 return NULL;
607 }
608
609 /*
610 * Max len of packet: (original len + 4 (H5 hdr) + 2 (crc)) * 2
611 * (because bytes 0xc0 and 0xdb are escaped, worst case is when
612 * the packet is all made of 0xc0 and 0xdb) + 2 (0xc0
613 * delimiters at start and end).
614 */
615 nskb = alloc_skb((len + 6) * 2 + 2, GFP_ATOMIC);
616 if (!nskb)
617 return NULL;
618
619 bt_cb(nskb)->pkt_type = pkt_type;
620
621 h5_slip_delim(nskb);
622
623 hdr[0] = h5->tx_ack << 3;
624 h5->tx_ack_req = false;
625
626 /* Reliable packet? */
627 if (pkt_type == HCI_ACLDATA_PKT || pkt_type == HCI_COMMAND_PKT) {
628 hdr[0] |= 1 << 7;
629 hdr[0] |= h5->tx_seq;
630 h5->tx_seq = (h5->tx_seq + 1) % 8;
631 }
632
633 hdr[1] = pkt_type | ((len & 0x0f) << 4);
634 hdr[2] = len >> 4;
635 hdr[3] = ~((hdr[0] + hdr[1] + hdr[2]) & 0xff);
636
637 BT_DBG("%s tx: seq %u ack %u crc %u rel %u type %u len %u",
638 hu->hdev->name, H5_HDR_SEQ(hdr), H5_HDR_ACK(hdr),
639 H5_HDR_CRC(hdr), H5_HDR_RELIABLE(hdr), H5_HDR_PKT_TYPE(hdr),
640 H5_HDR_LEN(hdr));
641
642 for (i = 0; i < 4; i++)
643 h5_slip_one_byte(nskb, hdr[i]);
644
645 for (i = 0; i < len; i++)
646 h5_slip_one_byte(nskb, data[i]);
647
648 h5_slip_delim(nskb);
649
650 return nskb;
651 }
652
653 static struct sk_buff *h5_dequeue(struct hci_uart *hu)
654 {
655 struct h5 *h5 = hu->priv;
656 unsigned long flags;
657 struct sk_buff *skb, *nskb;
658
659 if (h5->sleep != H5_AWAKE) {
660 const unsigned char wakeup_req[] = { 0x05, 0xfa };
661
662 if (h5->sleep == H5_WAKING_UP)
663 return NULL;
664
665 h5->sleep = H5_WAKING_UP;
666 BT_DBG("Sending wakeup request");
667
668 mod_timer(&h5->timer, jiffies + HZ / 100);
669 return h5_prepare_pkt(hu, HCI_3WIRE_LINK_PKT, wakeup_req, 2);
670 }
671
672 if ((skb = skb_dequeue(&h5->unrel)) != NULL) {
673 nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
674 skb->data, skb->len);
675 if (nskb) {
676 kfree_skb(skb);
677 return nskb;
678 }
679
680 skb_queue_head(&h5->unrel, skb);
681 BT_ERR("Could not dequeue pkt because alloc_skb failed");
682 }
683
684 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING);
685
686 if (h5->unack.qlen >= h5->tx_win)
687 goto unlock;
688
689 if ((skb = skb_dequeue(&h5->rel)) != NULL) {
690 nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
691 skb->data, skb->len);
692 if (nskb) {
693 __skb_queue_tail(&h5->unack, skb);
694 mod_timer(&h5->timer, jiffies + H5_ACK_TIMEOUT);
695 spin_unlock_irqrestore(&h5->unack.lock, flags);
696 return nskb;
697 }
698
699 skb_queue_head(&h5->rel, skb);
700 BT_ERR("Could not dequeue pkt because alloc_skb failed");
701 }
702
703 unlock:
704 spin_unlock_irqrestore(&h5->unack.lock, flags);
705
706 if (h5->tx_ack_req)
707 return h5_prepare_pkt(hu, HCI_3WIRE_ACK_PKT, NULL, 0);
708
709 return NULL;
710 }
711
712 static int h5_flush(struct hci_uart *hu)
713 {
714 BT_DBG("hu %p", hu);
715 return 0;
716 }
717
718 static struct hci_uart_proto h5p = {
719 .id = HCI_UART_3WIRE,
720 .open = h5_open,
721 .close = h5_close,
722 .recv = h5_recv,
723 .enqueue = h5_enqueue,
724 .dequeue = h5_dequeue,
725 .flush = h5_flush,
726 };
727
728 int __init h5_init(void)
729 {
730 int err = hci_uart_register_proto(&h5p);
731
732 if (!err)
733 BT_INFO("HCI Three-wire UART (H5) protocol initialized");
734 else
735 BT_ERR("HCI Three-wire UART (H5) protocol init failed");
736
737 return err;
738 }
739
740 int __exit h5_deinit(void)
741 {
742 return hci_uart_unregister_proto(&h5p);
743 }
This page took 0.065059 seconds and 6 git commands to generate.