Lines Matching +full:1 +full:d

34 tx_pkt(fido_dev_t *d, const void *pkt, size_t len, int *ms)
40 return (-1);
42 n = d->io.write(d->io_handle, pkt, len);
45 return (-1);
51 tx_empty(fido_dev_t *d, uint8_t cmd, int *ms) in tx_empty() argument
54 unsigned char pkt[sizeof(*fp) + 1]; in tx_empty()
55 const size_t len = d->tx_len + 1; in tx_empty()
59 fp = (struct frame *)(pkt + 1); in tx_empty()
60 fp->cid = d->cid; in tx_empty()
63 if (len > sizeof(pkt) || (n = tx_pkt(d, pkt, len, ms)) < 0 || in tx_empty()
65 return (-1); in tx_empty()
71 tx_preamble(fido_dev_t *d, uint8_t cmd, const void *buf, size_t count, int *ms) in tx_preamble() argument
74 unsigned char pkt[sizeof(*fp) + 1]; in tx_preamble()
75 const size_t len = d->tx_len + 1; in tx_preamble()
78 if (d->tx_len - CTAP_INIT_HEADER_LEN > sizeof(fp->body.init.data)) in tx_preamble()
82 fp = (struct frame *)(pkt + 1); in tx_preamble()
83 fp->cid = d->cid; in tx_preamble()
87 count = MIN(count, d->tx_len - CTAP_INIT_HEADER_LEN); in tx_preamble()
90 if (len > sizeof(pkt) || (n = tx_pkt(d, pkt, len, ms)) < 0 || in tx_preamble()
98 tx_frame(fido_dev_t *d, uint8_t seq, const void *buf, size_t count, int *ms) in tx_frame() argument
101 unsigned char pkt[sizeof(*fp) + 1]; in tx_frame()
102 const size_t len = d->tx_len + 1; in tx_frame()
105 if (d->tx_len - CTAP_CONT_HEADER_LEN > sizeof(fp->body.cont.data)) in tx_frame()
109 fp = (struct frame *)(pkt + 1); in tx_frame()
110 fp->cid = d->cid; in tx_frame()
112 count = MIN(count, d->tx_len - CTAP_CONT_HEADER_LEN); in tx_frame()
115 if (len > sizeof(pkt) || (n = tx_pkt(d, pkt, len, ms)) < 0 || in tx_frame()
123 tx(fido_dev_t *d, uint8_t cmd, const unsigned char *buf, size_t count, int *ms) in tx() argument
127 if ((sent = tx_preamble(d, cmd, buf, count, ms)) == 0) { in tx()
129 return (-1); in tx()
135 return (-1); in tx()
137 if ((n = tx_frame(d, seq++, buf + sent, count - sent, in tx()
140 return (-1); in tx()
148 transport_tx(fido_dev_t *d, uint8_t cmd, const void *buf, size_t count, int *ms) in transport_tx() argument
154 return (-1); in transport_tx()
156 n = d->transport.tx(d, cmd, buf, count); in transport_tx()
159 return (-1); in transport_tx()
165 fido_tx(fido_dev_t *d, uint8_t cmd, const void *buf, size_t count, int *ms) in fido_tx() argument
167 fido_log_debug("%s: dev=%p, cmd=0x%02x", __func__, (void *)d, cmd); in fido_tx()
170 if (d->transport.tx != NULL) in fido_tx()
171 return (transport_tx(d, cmd, buf, count, ms)); in fido_tx()
172 if (d->io_handle == NULL || d->io.write == NULL || count > UINT16_MAX) { in fido_tx()
174 return (-1); in fido_tx()
177 return (count == 0 ? tx_empty(d, cmd, ms) : tx(d, cmd, buf, count, ms)); in fido_tx()
181 rx_frame(fido_dev_t *d, struct frame *fp, int *ms) in rx_frame() argument
189 return (-1); in rx_frame()
191 if (d->rx_len > sizeof(*fp) || (n = d->io.read(d->io_handle, in rx_frame()
192 (unsigned char *)fp, d->rx_len, *ms)) < 0 || (size_t)n != d->rx_len) in rx_frame()
193 return (-1); in rx_frame()
199 rx_preamble(fido_dev_t *d, uint8_t cmd, struct frame *fp, int *ms) in rx_preamble() argument
202 if (rx_frame(d, fp, ms) < 0) in rx_preamble()
203 return (-1); in rx_preamble()
205 fp->cid = d->cid; in rx_preamble()
207 } while (fp->cid != d->cid || (fp->cid == d->cid && in rx_preamble()
210 if (d->rx_len > sizeof(*fp)) in rx_preamble()
211 return (-1); in rx_preamble()
213 fido_log_xxd(fp, d->rx_len, "%s", __func__); in rx_preamble()
218 if (fp->cid != d->cid || fp->body.init.cmd != (CTAP_FRAME_INIT | cmd)) { in rx_preamble()
220 __func__, fp->cid, d->cid, fp->body.init.cmd, cmd); in rx_preamble()
221 return (-1); in rx_preamble()
228 rx(fido_dev_t *d, uint8_t cmd, unsigned char *buf, size_t count, int *ms) in rx() argument
233 if (d->rx_len <= CTAP_INIT_HEADER_LEN || in rx()
234 d->rx_len <= CTAP_CONT_HEADER_LEN) in rx()
235 return (-1); in rx()
237 init_data_len = d->rx_len - CTAP_INIT_HEADER_LEN; in rx()
238 cont_data_len = d->rx_len - CTAP_CONT_HEADER_LEN; in rx()
242 return (-1); in rx()
244 if (rx_preamble(d, cmd, &f, ms) < 0) { in rx()
246 return (-1); in rx()
254 return (-1); in rx()
266 if (rx_frame(d, &f, ms) < 0) { in rx()
268 return (-1); in rx()
271 fido_log_xxd(&f, d->rx_len, "%s", __func__); in rx()
273 f.cid = d->cid; in rx()
277 if (f.cid != d->cid || f.body.cont.seq != seq) { in rx()
278 fido_log_debug("%s: cid (0x%x, 0x%x), seq (%d, %d)", in rx()
279 __func__, f.cid, d->cid, f.body.cont.seq, seq); in rx()
280 return (-1); in rx()
296 transport_rx(fido_dev_t *d, uint8_t cmd, void *buf, size_t count, int *ms) in transport_rx() argument
302 return (-1); in transport_rx()
304 n = d->transport.rx(d, cmd, buf, count, *ms); in transport_rx()
307 return (-1); in transport_rx()
313 fido_rx(fido_dev_t *d, uint8_t cmd, void *buf, size_t count, int *ms) in fido_rx() argument
317 fido_log_debug("%s: dev=%p, cmd=0x%02x, ms=%d", __func__, (void *)d, in fido_rx()
320 if (d->transport.rx != NULL) in fido_rx()
321 return (transport_rx(d, cmd, buf, count, ms)); in fido_rx()
322 if (d->io_handle == NULL || d->io.read == NULL || count > UINT16_MAX) { in fido_rx()
324 return (-1); in fido_rx()
326 if ((n = rx(d, cmd, buf, count, ms)) >= 0) in fido_rx()
333 fido_rx_cbor_status(fido_dev_t *d, int *ms) in fido_rx_cbor_status() argument
344 if ((msglen = fido_rx(d, CTAP_CMD_CBOR, msg, FIDO_MAXMSG, ms)) < 0 || in fido_rx_cbor_status()
345 (size_t)msglen < 1) { in fido_rx_cbor_status()