hci_h5.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. #include <linux/kernel.h>
  24. #include <linux/errno.h>
  25. #include <linux/skbuff.h>
  26. #include <net/bluetooth/bluetooth.h>
  27. #include <net/bluetooth/hci_core.h>
  28. #include "hci_uart.h"
  29. #define HCI_3WIRE_ACK_PKT 0
  30. #define HCI_3WIRE_LINK_PKT 15
  31. #define H5_TXWINSIZE 4
  32. #define H5_ACK_TIMEOUT msecs_to_jiffies(250)
  33. #define H5_SYNC_TIMEOUT msecs_to_jiffies(100)
  34. /*
  35. * Maximum Three-wire packet:
  36. * 4 byte header + max value for 12-bit length + 2 bytes for CRC
  37. */
  38. #define H5_MAX_LEN (4 + 0xfff + 2)
  39. /* Convenience macros for reading Three-wire header values */
  40. #define H5_HDR_SEQ(hdr) ((hdr)[0] & 0x07)
  41. #define H5_HDR_ACK(hdr) (((hdr)[0] >> 3) & 0x07)
  42. #define H5_HDR_CRC(hdr) (((hdr)[0] >> 6) & 0x01)
  43. #define H5_HDR_RELIABLE(hdr) (((hdr)[0] >> 7) & 0x01)
  44. #define H5_HDR_PKT_TYPE(hdr) ((hdr)[1] & 0x0f)
  45. #define H5_HDR_LEN(hdr) ((((hdr)[1] >> 4) & 0xff) + ((hdr)[2] << 4))
  46. #define SLIP_DELIMITER 0xc0
  47. #define SLIP_ESC 0xdb
  48. #define SLIP_ESC_DELIM 0xdc
  49. #define SLIP_ESC_ESC 0xdd
  50. struct h5 {
  51. struct sk_buff_head unack; /* Unack'ed packets queue */
  52. struct sk_buff_head rel; /* Reliable packets queue */
  53. struct sk_buff_head unrel; /* Unreliable packets queue */
  54. struct sk_buff *rx_skb; /* Receive buffer */
  55. size_t rx_pending; /* Expecting more bytes */
  56. bool rx_esc; /* SLIP escape mode */
  57. u8 rx_ack; /* Last ack number received */
  58. int (*rx_func) (struct hci_uart *hu, u8 c);
  59. struct timer_list timer; /* Retransmission timer */
  60. bool tx_ack_req; /* Pending ack to send */
  61. u8 tx_seq; /* Next seq number to send */
  62. u8 tx_ack; /* Next ack number to send */
  63. enum {
  64. H5_UNINITIALIZED,
  65. H5_INITIALIZED,
  66. H5_ACTIVE,
  67. } state;
  68. bool sleeping;
  69. };
  70. static void h5_reset_rx(struct h5 *h5);
  71. static void h5_link_control(struct hci_uart *hu, const void *data, size_t len)
  72. {
  73. struct h5 *h5 = hu->priv;
  74. struct sk_buff *nskb;
  75. nskb = alloc_skb(3, GFP_ATOMIC);
  76. if (!nskb)
  77. return;
  78. bt_cb(nskb)->pkt_type = HCI_3WIRE_LINK_PKT;
  79. memcpy(skb_put(nskb, len), data, len);
  80. skb_queue_tail(&h5->unrel, nskb);
  81. }
  82. static void h5_timed_event(unsigned long arg)
  83. {
  84. const unsigned char sync_req[] = { 0x01, 0x7e };
  85. const unsigned char conf_req[] = { 0x03, 0xfc, 0x01 };
  86. struct hci_uart *hu = (struct hci_uart *) arg;
  87. struct h5 *h5 = hu->priv;
  88. struct sk_buff *skb;
  89. unsigned long flags;
  90. if (h5->state == H5_UNINITIALIZED)
  91. h5_link_control(hu, sync_req, sizeof(sync_req));
  92. if (h5->state == H5_INITIALIZED)
  93. h5_link_control(hu, conf_req, sizeof(conf_req));
  94. if (h5->state != H5_ACTIVE) {
  95. mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT);
  96. goto wakeup;
  97. }
  98. BT_DBG("hu %p retransmitting %u pkts", hu, h5->unack.qlen);
  99. spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING);
  100. while ((skb = __skb_dequeue_tail(&h5->unack)) != NULL) {
  101. h5->tx_seq = (h5->tx_seq - 1) & 0x07;
  102. skb_queue_head(&h5->rel, skb);
  103. }
  104. spin_unlock_irqrestore(&h5->unack.lock, flags);
  105. wakeup:
  106. hci_uart_tx_wakeup(hu);
  107. }
  108. static int h5_open(struct hci_uart *hu)
  109. {
  110. struct h5 *h5;
  111. const unsigned char sync[] = { 0x01, 0x7e };
  112. BT_DBG("hu %p", hu);
  113. h5 = kzalloc(sizeof(*h5), GFP_KERNEL);
  114. if (!h5)
  115. return -ENOMEM;
  116. hu->priv = h5;
  117. skb_queue_head_init(&h5->unack);
  118. skb_queue_head_init(&h5->rel);
  119. skb_queue_head_init(&h5->unrel);
  120. h5_reset_rx(h5);
  121. init_timer(&h5->timer);
  122. h5->timer.function = h5_timed_event;
  123. h5->timer.data = (unsigned long) hu;
  124. set_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags);
  125. /* Send initial sync request */
  126. h5_link_control(hu, sync, sizeof(sync));
  127. mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT);
  128. return 0;
  129. }
  130. static int h5_close(struct hci_uart *hu)
  131. {
  132. struct h5 *h5 = hu->priv;
  133. skb_queue_purge(&h5->unack);
  134. skb_queue_purge(&h5->rel);
  135. skb_queue_purge(&h5->unrel);
  136. del_timer(&h5->timer);
  137. kfree(h5);
  138. return 0;
  139. }
  140. static void h5_pkt_cull(struct h5 *h5)
  141. {
  142. struct sk_buff *skb, *tmp;
  143. unsigned long flags;
  144. int i, to_remove;
  145. u8 seq;
  146. spin_lock_irqsave(&h5->unack.lock, flags);
  147. to_remove = skb_queue_len(&h5->unack);
  148. if (to_remove == 0)
  149. goto unlock;
  150. seq = h5->tx_seq;
  151. while (to_remove > 0) {
  152. if (h5->rx_ack == seq)
  153. break;
  154. to_remove--;
  155. seq = (seq - 1) % 8;
  156. }
  157. if (seq != h5->rx_ack)
  158. BT_ERR("Controller acked invalid packet");
  159. i = 0;
  160. skb_queue_walk_safe(&h5->unack, skb, tmp) {
  161. if (i++ >= to_remove)
  162. break;
  163. __skb_unlink(skb, &h5->unack);
  164. kfree_skb(skb);
  165. }
  166. if (skb_queue_empty(&h5->unack))
  167. del_timer(&h5->timer);
  168. unlock:
  169. spin_unlock_irqrestore(&h5->unack.lock, flags);
  170. }
  171. static void h5_handle_internal_rx(struct hci_uart *hu)
  172. {
  173. struct h5 *h5 = hu->priv;
  174. const unsigned char sync_req[] = { 0x01, 0x7e };
  175. const unsigned char sync_rsp[] = { 0x02, 0x7d };
  176. const unsigned char conf_req[] = { 0x03, 0xfc, 0x01 };
  177. const unsigned char conf_rsp[] = { 0x04, 0x7b, 0x01 };
  178. const unsigned char wakeup_req[] = { 0x05, 0xfa };
  179. const unsigned char woken_req[] = { 0x06, 0xf9 };
  180. const unsigned char sleep_req[] = { 0x07, 0x78 };
  181. const unsigned char *hdr = h5->rx_skb->data;
  182. const unsigned char *data = &h5->rx_skb->data[4];
  183. BT_DBG("%s", hu->hdev->name);
  184. if (H5_HDR_PKT_TYPE(hdr) != HCI_3WIRE_LINK_PKT)
  185. return;
  186. if (H5_HDR_LEN(hdr) < 2)
  187. return;
  188. if (memcmp(data, sync_req, 2) == 0) {
  189. h5_link_control(hu, sync_rsp, 2);
  190. } else if (memcmp(data, sync_rsp, 2) == 0) {
  191. h5->state = H5_INITIALIZED;
  192. h5_link_control(hu, conf_req, 3);
  193. } else if (memcmp(data, conf_req, 2) == 0) {
  194. h5_link_control(hu, conf_rsp, 2);
  195. h5_link_control(hu, conf_req, 3);
  196. } else if (memcmp(data, conf_rsp, 2) == 0) {
  197. BT_DBG("Three-wire init sequence complete");
  198. h5->state = H5_ACTIVE;
  199. hci_uart_init_ready(hu);
  200. return;
  201. } else if (memcmp(data, sleep_req, 2) == 0) {
  202. BT_DBG("Peer went to sleep");
  203. h5->sleeping = true;
  204. h5_link_control(hu, wakeup_req, 2);
  205. } else if (memcmp(data, woken_req, 2) == 0) {
  206. BT_DBG("Peer woke up");
  207. h5->sleeping = false;
  208. return;
  209. } else {
  210. BT_DBG("Link Control: 0x%02hhx 0x%02hhx", data[0], data[1]);
  211. return;
  212. }
  213. hci_uart_tx_wakeup(hu);
  214. }
  215. static void h5_complete_rx_pkt(struct hci_uart *hu)
  216. {
  217. struct h5 *h5 = hu->priv;
  218. const unsigned char *hdr = h5->rx_skb->data;
  219. if (H5_HDR_RELIABLE(hdr)) {
  220. h5->tx_ack = (h5->tx_ack + 1) % 8;
  221. h5->tx_ack_req = true;
  222. hci_uart_tx_wakeup(hu);
  223. }
  224. h5->rx_ack = H5_HDR_ACK(hdr);
  225. h5_pkt_cull(h5);
  226. switch (H5_HDR_PKT_TYPE(hdr)) {
  227. case HCI_EVENT_PKT:
  228. case HCI_ACLDATA_PKT:
  229. case HCI_SCODATA_PKT:
  230. bt_cb(h5->rx_skb)->pkt_type = H5_HDR_PKT_TYPE(hdr);
  231. /* Remove Three-wire header */
  232. skb_pull(h5->rx_skb, 4);
  233. hci_recv_frame(h5->rx_skb);
  234. h5->rx_skb = NULL;
  235. break;
  236. default:
  237. h5_handle_internal_rx(hu);
  238. break;
  239. }
  240. h5_reset_rx(h5);
  241. }
  242. static int h5_rx_crc(struct hci_uart *hu, unsigned char c)
  243. {
  244. struct h5 *h5 = hu->priv;
  245. h5_complete_rx_pkt(hu);
  246. h5_reset_rx(h5);
  247. return 0;
  248. }
  249. static int h5_rx_payload(struct hci_uart *hu, unsigned char c)
  250. {
  251. struct h5 *h5 = hu->priv;
  252. const unsigned char *hdr = h5->rx_skb->data;
  253. if (H5_HDR_CRC(hdr)) {
  254. h5->rx_func = h5_rx_crc;
  255. h5->rx_pending = 2;
  256. } else {
  257. h5_complete_rx_pkt(hu);
  258. h5_reset_rx(h5);
  259. }
  260. return 0;
  261. }
  262. static int h5_rx_3wire_hdr(struct hci_uart *hu, unsigned char c)
  263. {
  264. struct h5 *h5 = hu->priv;
  265. const unsigned char *hdr = h5->rx_skb->data;
  266. BT_DBG("%s rx: seq %u ack %u crc %u rel %u type %u len %u",
  267. hu->hdev->name, H5_HDR_SEQ(hdr), H5_HDR_ACK(hdr),
  268. H5_HDR_CRC(hdr), H5_HDR_RELIABLE(hdr), H5_HDR_PKT_TYPE(hdr),
  269. H5_HDR_LEN(hdr));
  270. if (((hdr[0] + hdr[1] + hdr[2] + hdr[3]) & 0xff) != 0xff) {
  271. BT_ERR("Invalid header checksum");
  272. h5_reset_rx(h5);
  273. return 0;
  274. }
  275. if (H5_HDR_RELIABLE(hdr) && H5_HDR_SEQ(hdr) != h5->tx_ack) {
  276. BT_ERR("Out-of-order packet arrived (%u != %u)",
  277. H5_HDR_SEQ(hdr), h5->tx_ack);
  278. h5_reset_rx(h5);
  279. return 0;
  280. }
  281. if (h5->state != H5_ACTIVE &&
  282. H5_HDR_PKT_TYPE(hdr) != HCI_3WIRE_LINK_PKT) {
  283. BT_ERR("Non-link packet received in non-active state");
  284. h5_reset_rx(h5);
  285. }
  286. h5->rx_func = h5_rx_payload;
  287. h5->rx_pending = H5_HDR_LEN(hdr);
  288. return 0;
  289. }
  290. static int h5_rx_pkt_start(struct hci_uart *hu, unsigned char c)
  291. {
  292. struct h5 *h5 = hu->priv;
  293. if (c == SLIP_DELIMITER)
  294. return 1;
  295. h5->rx_func = h5_rx_3wire_hdr;
  296. h5->rx_pending = 4;
  297. h5->rx_skb = bt_skb_alloc(H5_MAX_LEN, GFP_ATOMIC);
  298. if (!h5->rx_skb) {
  299. BT_ERR("Can't allocate mem for new packet");
  300. h5_reset_rx(h5);
  301. return -ENOMEM;
  302. }
  303. h5->rx_skb->dev = (void *) hu->hdev;
  304. return 0;
  305. }
  306. static int h5_rx_delimiter(struct hci_uart *hu, unsigned char c)
  307. {
  308. struct h5 *h5 = hu->priv;
  309. if (c == SLIP_DELIMITER)
  310. h5->rx_func = h5_rx_pkt_start;
  311. return 1;
  312. }
  313. static void h5_unslip_one_byte(struct h5 *h5, unsigned char c)
  314. {
  315. const u8 delim = SLIP_DELIMITER, esc = SLIP_ESC;
  316. const u8 *byte = &c;
  317. if (!h5->rx_esc && c == SLIP_ESC) {
  318. h5->rx_esc = true;
  319. return;
  320. }
  321. if (h5->rx_esc) {
  322. switch (c) {
  323. case SLIP_ESC_DELIM:
  324. byte = &delim;
  325. break;
  326. case SLIP_ESC_ESC:
  327. byte = &esc;
  328. break;
  329. default:
  330. BT_ERR("Invalid esc byte 0x%02hhx", c);
  331. h5_reset_rx(h5);
  332. return;
  333. }
  334. h5->rx_esc = false;
  335. }
  336. memcpy(skb_put(h5->rx_skb, 1), byte, 1);
  337. h5->rx_pending--;
  338. BT_DBG("unsliped 0x%02hhx, rx_pending %zu", *byte, h5->rx_pending);
  339. }
  340. static void h5_reset_rx(struct h5 *h5)
  341. {
  342. if (h5->rx_skb) {
  343. kfree_skb(h5->rx_skb);
  344. h5->rx_skb = NULL;
  345. }
  346. h5->rx_func = h5_rx_delimiter;
  347. h5->rx_pending = 0;
  348. h5->rx_esc = false;
  349. }
  350. static int h5_recv(struct hci_uart *hu, void *data, int count)
  351. {
  352. struct h5 *h5 = hu->priv;
  353. unsigned char *ptr = data;
  354. BT_DBG("%s pending %zu count %d", hu->hdev->name, h5->rx_pending,
  355. count);
  356. while (count > 0) {
  357. int processed;
  358. if (h5->rx_pending > 0) {
  359. if (*ptr == SLIP_DELIMITER) {
  360. BT_ERR("Too short H5 packet");
  361. h5_reset_rx(h5);
  362. continue;
  363. }
  364. h5_unslip_one_byte(h5, *ptr);
  365. ptr++; count--;
  366. continue;
  367. }
  368. processed = h5->rx_func(hu, *ptr);
  369. if (processed < 0)
  370. return processed;
  371. ptr += processed;
  372. count -= processed;
  373. }
  374. return 0;
  375. }
  376. static int h5_enqueue(struct hci_uart *hu, struct sk_buff *skb)
  377. {
  378. struct h5 *h5 = hu->priv;
  379. if (skb->len > 0xfff) {
  380. BT_ERR("Packet too long (%u bytes)", skb->len);
  381. kfree_skb(skb);
  382. return 0;
  383. }
  384. if (h5->state != H5_ACTIVE) {
  385. BT_ERR("Ignoring HCI data in non-active state");
  386. kfree_skb(skb);
  387. return 0;
  388. }
  389. switch (bt_cb(skb)->pkt_type) {
  390. case HCI_ACLDATA_PKT:
  391. case HCI_COMMAND_PKT:
  392. skb_queue_tail(&h5->rel, skb);
  393. break;
  394. case HCI_SCODATA_PKT:
  395. skb_queue_tail(&h5->unrel, skb);
  396. break;
  397. default:
  398. BT_ERR("Unknown packet type %u", bt_cb(skb)->pkt_type);
  399. kfree_skb(skb);
  400. break;
  401. }
  402. return 0;
  403. }
  404. static void h5_slip_delim(struct sk_buff *skb)
  405. {
  406. const char delim = SLIP_DELIMITER;
  407. memcpy(skb_put(skb, 1), &delim, 1);
  408. }
  409. static void h5_slip_one_byte(struct sk_buff *skb, u8 c)
  410. {
  411. const char esc_delim[2] = { SLIP_ESC, SLIP_ESC_DELIM };
  412. const char esc_esc[2] = { SLIP_ESC, SLIP_ESC_ESC };
  413. switch (c) {
  414. case SLIP_DELIMITER:
  415. memcpy(skb_put(skb, 2), &esc_delim, 2);
  416. break;
  417. case SLIP_ESC:
  418. memcpy(skb_put(skb, 2), &esc_esc, 2);
  419. break;
  420. default:
  421. memcpy(skb_put(skb, 1), &c, 1);
  422. }
  423. }
  424. static struct sk_buff *h5_build_pkt(struct hci_uart *hu, bool rel, u8 pkt_type,
  425. const u8 *data, size_t len)
  426. {
  427. struct h5 *h5 = hu->priv;
  428. struct sk_buff *nskb;
  429. u8 hdr[4];
  430. int i;
  431. /*
  432. * Max len of packet: (original len + 4 (H5 hdr) + 2 (crc)) * 2
  433. * (because bytes 0xc0 and 0xdb are escaped, worst case is when
  434. * the packet is all made of 0xc0 and 0xdb) + 2 (0xc0
  435. * delimiters at start and end).
  436. */
  437. nskb = alloc_skb((len + 6) * 2 + 2, GFP_ATOMIC);
  438. if (!nskb)
  439. return NULL;
  440. bt_cb(nskb)->pkt_type = pkt_type;
  441. h5_slip_delim(nskb);
  442. hdr[0] = h5->tx_ack << 3;
  443. h5->tx_ack_req = false;
  444. if (rel) {
  445. hdr[0] |= 1 << 7;
  446. hdr[0] |= h5->tx_seq;
  447. h5->tx_seq = (h5->tx_seq + 1) % 8;
  448. }
  449. hdr[1] = pkt_type | ((len & 0x0f) << 4);
  450. hdr[2] = len >> 4;
  451. hdr[3] = ~((hdr[0] + hdr[1] + hdr[2]) & 0xff);
  452. BT_DBG("%s tx: seq %u ack %u crc %u rel %u type %u len %u",
  453. hu->hdev->name, H5_HDR_SEQ(hdr), H5_HDR_ACK(hdr),
  454. H5_HDR_CRC(hdr), H5_HDR_RELIABLE(hdr), H5_HDR_PKT_TYPE(hdr),
  455. H5_HDR_LEN(hdr));
  456. for (i = 0; i < 4; i++)
  457. h5_slip_one_byte(nskb, hdr[i]);
  458. for (i = 0; i < len; i++)
  459. h5_slip_one_byte(nskb, data[i]);
  460. h5_slip_delim(nskb);
  461. return nskb;
  462. }
  463. static struct sk_buff *h5_prepare_pkt(struct hci_uart *hu, u8 pkt_type,
  464. const u8 *data, size_t len)
  465. {
  466. bool rel;
  467. switch (pkt_type) {
  468. case HCI_ACLDATA_PKT:
  469. case HCI_COMMAND_PKT:
  470. rel = true;
  471. break;
  472. case HCI_SCODATA_PKT:
  473. case HCI_3WIRE_LINK_PKT:
  474. case HCI_3WIRE_ACK_PKT:
  475. rel = false;
  476. break;
  477. default:
  478. BT_ERR("Unknown packet type %u", pkt_type);
  479. return NULL;
  480. }
  481. return h5_build_pkt(hu, rel, pkt_type, data, len);
  482. }
  483. static struct sk_buff *h5_dequeue(struct hci_uart *hu)
  484. {
  485. struct h5 *h5 = hu->priv;
  486. unsigned long flags;
  487. struct sk_buff *skb, *nskb;
  488. if ((skb = skb_dequeue(&h5->unrel)) != NULL) {
  489. nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
  490. skb->data, skb->len);
  491. if (nskb) {
  492. kfree_skb(skb);
  493. return nskb;
  494. }
  495. skb_queue_head(&h5->unrel, skb);
  496. BT_ERR("Could not dequeue pkt because alloc_skb failed");
  497. }
  498. spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING);
  499. if (h5->unack.qlen >= H5_TXWINSIZE)
  500. goto unlock;
  501. if ((skb = skb_dequeue(&h5->rel)) != NULL) {
  502. nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
  503. skb->data, skb->len);
  504. if (nskb) {
  505. __skb_queue_tail(&h5->unack, skb);
  506. mod_timer(&h5->timer, jiffies + H5_ACK_TIMEOUT);
  507. spin_unlock_irqrestore(&h5->unack.lock, flags);
  508. return nskb;
  509. }
  510. skb_queue_head(&h5->rel, skb);
  511. BT_ERR("Could not dequeue pkt because alloc_skb failed");
  512. }
  513. unlock:
  514. spin_unlock_irqrestore(&h5->unack.lock, flags);
  515. if (h5->tx_ack_req)
  516. return h5_prepare_pkt(hu, HCI_3WIRE_ACK_PKT, NULL, 0);
  517. return NULL;
  518. }
  519. static int h5_flush(struct hci_uart *hu)
  520. {
  521. BT_DBG("hu %p", hu);
  522. return 0;
  523. }
  524. static struct hci_uart_proto h5p = {
  525. .id = HCI_UART_3WIRE,
  526. .open = h5_open,
  527. .close = h5_close,
  528. .recv = h5_recv,
  529. .enqueue = h5_enqueue,
  530. .dequeue = h5_dequeue,
  531. .flush = h5_flush,
  532. };
  533. int __init h5_init(void)
  534. {
  535. int err = hci_uart_register_proto(&h5p);
  536. if (!err)
  537. BT_INFO("HCI Three-wire UART (H5) protocol initialized");
  538. else
  539. BT_ERR("HCI Three-wire UART (H5) protocol init failed");
  540. return err;
  541. }
  542. int __exit h5_deinit(void)
  543. {
  544. return hci_uart_unregister_proto(&h5p);
  545. }