Lines Matching refs:h4
76 struct h4_data *h4 = dev->data; in h4_get_type() local
79 if (uart_fifo_read(cfg->uart, &h4->rx.type, 1) != 1) { in h4_get_type()
81 h4->rx.type = BT_HCI_H4_NONE; in h4_get_type()
85 switch (h4->rx.type) { in h4_get_type()
87 h4->rx.remaining = sizeof(h4->rx.evt); in h4_get_type()
88 h4->rx.hdr_len = h4->rx.remaining; in h4_get_type()
91 h4->rx.remaining = sizeof(h4->rx.acl); in h4_get_type()
92 h4->rx.hdr_len = h4->rx.remaining; in h4_get_type()
96 h4->rx.remaining = sizeof(h4->rx.iso); in h4_get_type()
97 h4->rx.hdr_len = h4->rx.remaining; in h4_get_type()
102 LOG_ERR("Unknown H:4 type 0x%02x", h4->rx.type); in h4_get_type()
103 h4->rx.type = BT_HCI_H4_NONE; in h4_get_type()
110 struct h4_data *h4 = dev->data; in h4_read_hdr() local
111 int bytes_read = h4->rx.hdr_len - h4->rx.remaining; in h4_read_hdr()
114 ret = uart_fifo_read(cfg->uart, h4->rx.hdr + bytes_read, h4->rx.remaining); in h4_read_hdr()
118 h4->rx.remaining -= ret; in h4_read_hdr()
124 struct h4_data *h4 = dev->data; in get_acl_hdr() local
128 if (!h4->rx.remaining) { in get_acl_hdr()
129 struct bt_hci_acl_hdr *hdr = &h4->rx.acl; in get_acl_hdr()
131 h4->rx.remaining = sys_le16_to_cpu(hdr->len); in get_acl_hdr()
132 LOG_DBG("Got ACL header. Payload %u bytes", h4->rx.remaining); in get_acl_hdr()
133 h4->rx.have_hdr = true; in get_acl_hdr()
139 struct h4_data *h4 = dev->data; in get_iso_hdr() local
143 if (!h4->rx.remaining) { in get_iso_hdr()
144 struct bt_hci_iso_hdr *hdr = &h4->rx.iso; in get_iso_hdr()
146 h4->rx.remaining = bt_iso_hdr_len(sys_le16_to_cpu(hdr->len)); in get_iso_hdr()
147 LOG_DBG("Got ISO header. Payload %u bytes", h4->rx.remaining); in get_iso_hdr()
148 h4->rx.have_hdr = true; in get_iso_hdr()
154 struct h4_data *h4 = dev->data; in get_evt_hdr() local
156 struct bt_hci_evt_hdr *hdr = &h4->rx.evt; in get_evt_hdr()
160 if (h4->rx.hdr_len == sizeof(*hdr) && h4->rx.remaining < sizeof(*hdr)) { in get_evt_hdr()
161 switch (h4->rx.evt.evt) { in get_evt_hdr()
163 h4->rx.remaining++; in get_evt_hdr()
164 h4->rx.hdr_len++; in get_evt_hdr()
169 h4->rx.discardable = true; in get_evt_hdr()
175 if (!h4->rx.remaining) { in get_evt_hdr()
176 if (h4->rx.evt.evt == BT_HCI_EVT_LE_META_EVENT && in get_evt_hdr()
177 (h4->rx.hdr[sizeof(*hdr)] == BT_HCI_EVT_LE_ADVERTISING_REPORT)) { in get_evt_hdr()
179 h4->rx.discardable = true; in get_evt_hdr()
182 h4->rx.remaining = hdr->len - (h4->rx.hdr_len - sizeof(*hdr)); in get_evt_hdr()
184 h4->rx.have_hdr = true; in get_evt_hdr()
189 static inline void copy_hdr(struct h4_data *h4) in copy_hdr() argument
191 net_buf_add_mem(h4->rx.buf, h4->rx.hdr, h4->rx.hdr_len); in copy_hdr()
194 static void reset_rx(struct h4_data *h4) in reset_rx() argument
196 h4->rx.type = BT_HCI_H4_NONE; in reset_rx()
197 h4->rx.remaining = 0U; in reset_rx()
198 h4->rx.have_hdr = false; in reset_rx()
199 h4->rx.hdr_len = 0U; in reset_rx()
200 h4->rx.discardable = false; in reset_rx()
203 static struct net_buf *get_rx(struct h4_data *h4, k_timeout_t timeout) in get_rx() argument
205 LOG_DBG("type 0x%02x, evt 0x%02x", h4->rx.type, h4->rx.evt.evt); in get_rx()
207 switch (h4->rx.type) { in get_rx()
209 return bt_buf_get_evt(h4->rx.evt.evt, h4->rx.discardable, timeout); in get_rx()
225 struct h4_data *h4 = dev->data; in rx_thread() local
234 LOG_DBG("rx.buf %p", h4->rx.buf); in rx_thread()
240 if (h4->rx.have_hdr && !h4->rx.buf) { in rx_thread()
241 h4->rx.buf = get_rx(h4, K_FOREVER); in rx_thread()
242 LOG_DBG("Got rx.buf %p", h4->rx.buf); in rx_thread()
243 if (h4->rx.remaining > net_buf_tailroom(h4->rx.buf)) { in rx_thread()
245 h4->rx.discard = h4->rx.remaining; in rx_thread()
246 reset_rx(h4); in rx_thread()
248 copy_hdr(h4); in rx_thread()
255 buf = k_fifo_get(&h4->rx.fifo, K_FOREVER); in rx_thread()
260 h4->recv(dev, buf); in rx_thread()
269 buf = k_fifo_get(&h4->rx.fifo, K_NO_WAIT); in rx_thread()
291 struct h4_data *h4 = dev->data; in read_payload() local
295 if (!h4->rx.buf) { in read_payload()
298 h4->rx.buf = get_rx(h4, K_NO_WAIT); in read_payload()
299 if (!h4->rx.buf) { in read_payload()
300 if (h4->rx.discardable) { in read_payload()
301 LOG_WRN("Discarding event 0x%02x", h4->rx.evt.evt); in read_payload()
302 h4->rx.discard = h4->rx.remaining; in read_payload()
303 reset_rx(h4); in read_payload()
312 LOG_DBG("Allocated rx.buf %p", h4->rx.buf); in read_payload()
314 buf_tailroom = net_buf_tailroom(h4->rx.buf); in read_payload()
315 if (buf_tailroom < h4->rx.remaining) { in read_payload()
316 LOG_ERR("Not enough space in buffer %u/%zu", h4->rx.remaining, in read_payload()
318 h4->rx.discard = h4->rx.remaining; in read_payload()
319 reset_rx(h4); in read_payload()
323 copy_hdr(h4); in read_payload()
326 read = uart_fifo_read(cfg->uart, net_buf_tail(h4->rx.buf), h4->rx.remaining); in read_payload()
332 net_buf_add(h4->rx.buf, read); in read_payload()
333 h4->rx.remaining -= read; in read_payload()
335 LOG_DBG("got %d bytes, remaining %u", read, h4->rx.remaining); in read_payload()
336 LOG_DBG("Payload (len %u): %s", h4->rx.buf->len, in read_payload()
337 bt_hex(h4->rx.buf->data, h4->rx.buf->len)); in read_payload()
339 if (h4->rx.remaining) { in read_payload()
343 buf = h4->rx.buf; in read_payload()
344 h4->rx.buf = NULL; in read_payload()
346 if (h4->rx.type == BT_HCI_H4_EVT) { in read_payload()
352 reset_rx(h4); in read_payload()
355 k_fifo_put(&h4->rx.fifo, buf); in read_payload()
360 struct h4_data *h4 = dev->data; in read_header() local
362 switch (h4->rx.type) { in read_header()
383 if (h4->rx.have_hdr && h4->rx.buf) { in read_header()
384 if (h4->rx.remaining > net_buf_tailroom(h4->rx.buf)) { in read_header()
386 h4->rx.discard = h4->rx.remaining; in read_header()
387 reset_rx(h4); in read_header()
389 copy_hdr(h4); in read_header()
397 struct h4_data *h4 = dev->data; in process_tx() local
400 if (!h4->tx.buf) { in process_tx()
401 h4->tx.buf = k_fifo_get(&h4->tx.fifo, K_NO_WAIT); in process_tx()
402 if (!h4->tx.buf) { in process_tx()
409 if (!h4->tx.type) { in process_tx()
410 switch (bt_buf_get_type(h4->tx.buf)) { in process_tx()
412 h4->tx.type = BT_HCI_H4_ACL; in process_tx()
415 h4->tx.type = BT_HCI_H4_CMD; in process_tx()
419 h4->tx.type = BT_HCI_H4_ISO; in process_tx()
428 bytes = uart_fifo_fill(cfg->uart, &h4->tx.type, 1); in process_tx()
431 h4->tx.type = BT_HCI_H4_NONE; in process_tx()
436 bytes = uart_fifo_fill(cfg->uart, h4->tx.buf->data, h4->tx.buf->len); in process_tx()
440 net_buf_pull(h4->tx.buf, bytes); in process_tx()
443 if (h4->tx.buf->len) { in process_tx()
448 h4->tx.type = BT_HCI_H4_NONE; in process_tx()
449 net_buf_unref(h4->tx.buf); in process_tx()
450 h4->tx.buf = k_fifo_get(&h4->tx.fifo, K_NO_WAIT); in process_tx()
451 if (!h4->tx.buf) { in process_tx()
459 struct h4_data *h4 = dev->data; in process_rx() local
462 h4->rx.remaining, h4->rx.discard, h4->rx.have_hdr, h4->rx.buf, in process_rx()
463 h4->rx.buf ? h4->rx.buf->len : 0); in process_rx()
465 if (h4->rx.discard) { in process_rx()
466 h4->rx.discard -= h4_discard(cfg->uart, h4->rx.discard); in process_rx()
470 if (h4->rx.have_hdr) { in process_rx()
495 struct h4_data *h4 = dev->data; in h4_send() local
499 k_fifo_put(&h4->tx.fifo, buf); in h4_send()
520 struct h4_data *h4 = dev->data; in h4_open() local
534 h4->recv = recv; in h4_open()