Lines Matching +full:transfer +full:- +full:function
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2009-2023 Hans Petter Selasky
95 if (ctx && ctx->debug_fixed == 0) in libusb_set_debug()
96 ctx->debug = level; in libusb_set_debug()
105 * We ignore any failures in this function, hence the in libusb_set_nonblocking()
106 * non-blocking flag is not critical to the operation of in libusb_set_nonblocking()
112 if (flags == -1) in libusb_set_nonblocking()
128 err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); in libusb_interrupt_event_handler()
167 ctx->debug = strtol(debug, &ep, 10); in libusb_init_context()
169 ctx->debug_fixed = 1; in libusb_init_context()
177 ctx->debug = 0; in libusb_init_context()
187 ctx->debug = (int)option[i].value.ival; in libusb_init_context()
188 if ((int64_t)ctx->debug == option[i].value.ival) { in libusb_init_context()
189 ctx->debug_fixed = 1; in libusb_init_context()
197 TAILQ_INIT(&ctx->pollfds); in libusb_init_context()
198 TAILQ_INIT(&ctx->tr_done); in libusb_init_context()
199 TAILQ_INIT(&ctx->hotplug_cbh); in libusb_init_context()
200 TAILQ_INIT(&ctx->hotplug_devs); in libusb_init_context()
202 if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { in libusb_init_context()
206 if (pthread_mutex_init(&ctx->hotplug_lock, NULL) != 0) { in libusb_init_context()
207 pthread_mutex_destroy(&ctx->ctx_lock); in libusb_init_context()
212 pthread_mutex_destroy(&ctx->ctx_lock); in libusb_init_context()
213 pthread_mutex_destroy(&ctx->hotplug_lock); in libusb_init_context()
218 pthread_mutex_destroy(&ctx->ctx_lock); in libusb_init_context()
219 pthread_mutex_destroy(&ctx->hotplug_lock); in libusb_init_context()
224 if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) { in libusb_init_context()
225 pthread_mutex_destroy(&ctx->ctx_lock); in libusb_init_context()
226 pthread_mutex_destroy(&ctx->hotplug_lock); in libusb_init_context()
233 ctx->ctx_handler = NO_THREAD; in libusb_init_context()
234 ctx->hotplug_handler = NO_THREAD; in libusb_init_context()
236 ret = pipe(ctx->ctrl_pipe); in libusb_init_context()
238 pthread_mutex_destroy(&ctx->ctx_lock); in libusb_init_context()
239 pthread_mutex_destroy(&ctx->hotplug_lock); in libusb_init_context()
240 pthread_cond_destroy(&ctx->ctx_cond); in libusb_init_context()
244 /* set non-blocking mode on the control pipe to avoid deadlock */ in libusb_init_context()
245 libusb_set_nonblocking(ctx->ctrl_pipe[0]); in libusb_init_context()
246 libusb_set_nonblocking(ctx->ctrl_pipe[1]); in libusb_init_context()
248 libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->ctrl_pipe[0], POLLIN); in libusb_init_context()
276 if (ctx->hotplug_handler != NO_THREAD) { in libusb_exit()
281 td = ctx->hotplug_handler; in libusb_exit()
282 ctx->hotplug_handler = NO_THREAD; in libusb_exit()
290 libusb10_remove_pollfd(ctx, &ctx->ctx_poll); in libusb_exit()
291 close(ctx->ctrl_pipe[0]); in libusb_exit()
292 close(ctx->ctrl_pipe[1]); in libusb_exit()
293 pthread_mutex_destroy(&ctx->ctx_lock); in libusb_exit()
294 pthread_mutex_destroy(&ctx->hotplug_lock); in libusb_exit()
295 pthread_cond_destroy(&ctx->ctx_cond); in libusb_exit()
347 libusb_unref_device((*list)[i - 1]); in libusb_get_device_list()
348 i--; in libusb_get_device_list()
360 /* init transfer queues */ in libusb_get_device_list()
361 TAILQ_INIT(&dev->tr_head); in libusb_get_device_list()
364 dev->ctx = ctx; in libusb_get_device_list()
367 dev->os_priv = pdev; in libusb_get_device_list()
368 pdev->privLuData = dev; in libusb_get_device_list()
399 return (libusb20_dev_get_bus_number(dev->os_priv)); in libusb_get_bus_number()
407 return (libusb20_dev_get_parent_port(dev->os_priv)); in libusb_get_port_number()
413 return (libusb20_dev_get_port_path(dev->os_priv, buf, bufsize)); in libusb_get_port_numbers()
420 return (libusb20_dev_get_port_path(dev->os_priv, buf, bufsize)); in libusb_get_port_path()
428 return (libusb20_dev_get_address(dev->os_priv)); in libusb_get_device_address()
437 switch (libusb20_dev_get_speed(dev->os_priv)) { in libusb_get_device_speed()
472 for (i = 0; i < pdconf->bNumInterfaces; i++) { in libusb_get_max_packet_size()
473 pinf = &pdconf->interface[i]; in libusb_get_max_packet_size()
474 for (j = 0; j < pinf->num_altsetting; j++) { in libusb_get_max_packet_size()
475 pdinf = &pinf->altsetting[j]; in libusb_get_max_packet_size()
476 for (k = 0; k < pdinf->bNumEndpoints; k++) { in libusb_get_max_packet_size()
477 pdend = &pdinf->endpoint[k]; in libusb_get_max_packet_size()
478 if (pdend->bEndpointAddress == endpoint) { in libusb_get_max_packet_size()
479 ret = pdend->wMaxPacketSize; in libusb_get_max_packet_size()
499 switch (libusb20_dev_get_speed(dev->os_priv)) { in libusb_get_max_iso_packet_size()
504 if (ret > -1) { in libusb_get_max_iso_packet_size()
521 CTX_LOCK(dev->ctx); in libusb_ref_device()
522 dev->refcnt++; in libusb_ref_device()
523 CTX_UNLOCK(dev->ctx); in libusb_ref_device()
534 CTX_LOCK(dev->ctx); in libusb_unref_device()
535 dev->refcnt--; in libusb_unref_device()
536 CTX_UNLOCK(dev->ctx); in libusb_unref_device()
538 if (dev->refcnt == 0) { in libusb_unref_device()
539 libusb20_dev_free(dev->os_priv); in libusb_unref_device()
547 libusb_context *ctx = dev->ctx; in libusb_open()
548 struct libusb20_device *pdev = dev->os_priv; in libusb_open()
569 * after a re-attach, to allow new transaction: in libusb_open()
572 dev->device_is_gone = 0; in libusb_open()
575 libusb10_add_pollfd(ctx, &dev->dev_poll, pdev, libusb20_dev_get_fd(pdev), POLLIN | in libusb_open()
609 tdev = devs[j]->os_priv; in libusb_open_device_with_vid_pid()
616 if (pdesc->idVendor == vendor_id && in libusb_open_device_with_vid_pid()
617 pdesc->idProduct == product_id) { in libusb_open_device_with_vid_pid()
638 ctx = dev->ctx; in libusb_close()
640 libusb10_remove_pollfd(ctx, &dev->dev_poll); in libusb_close()
656 return ((libusb_device *)pdev->privLuData); in libusb_get_device()
671 *config = pconf->desc.bConfigurationValue; in libusb_get_configuration()
700 found = (pconf->desc.bConfigurationValue in libusb_set_configuration()
714 libusb10_remove_pollfd(dev->ctx, &dev->dev_poll); in libusb_set_configuration()
718 libusb10_add_pollfd(dev->ctx, &dev->dev_poll, pdev, libusb20_dev_get_fd(pdev), POLLIN | in libusb_set_configuration()
737 if (pdev->auto_detach != 0) { in libusb_claim_interface()
743 CTX_LOCK(dev->ctx); in libusb_claim_interface()
744 dev->claimed_interfaces |= (1 << interface_number); in libusb_claim_interface()
745 CTX_UNLOCK(dev->ctx); in libusb_claim_interface()
763 if (pdev->auto_detach != 0) { in libusb_release_interface()
769 CTX_LOCK(dev->ctx); in libusb_release_interface()
770 if (!(dev->claimed_interfaces & (1 << interface_number))) in libusb_release_interface()
773 dev->claimed_interfaces &= ~(1 << interface_number); in libusb_release_interface()
774 CTX_UNLOCK(dev->ctx); in libusb_release_interface()
793 CTX_LOCK(dev->ctx); in libusb_set_interface_alt_setting()
794 if (!(dev->claimed_interfaces & (1 << interface_number))) in libusb_set_interface_alt_setting()
796 CTX_UNLOCK(dev->ctx); in libusb_set_interface_alt_setting()
803 libusb10_remove_pollfd(dev->ctx, &dev->dev_poll); in libusb_set_interface_alt_setting()
808 libusb10_add_pollfd(dev->ctx, &dev->dev_poll, in libusb_set_interface_alt_setting()
845 CTX_LOCK(dev->ctx); in libusb_clear_halt()
847 CTX_UNLOCK(dev->ctx); in libusb_clear_halt()
854 /* check if we opened the transfer */ in libusb_clear_halt()
856 CTX_LOCK(dev->ctx); in libusb_clear_halt()
858 CTX_UNLOCK(dev->ctx); in libusb_clear_halt()
875 libusb10_remove_pollfd(dev->ctx, &dev->dev_poll); in libusb_reset_device()
879 libusb10_add_pollfd(dev->ctx, &dev->dev_poll, in libusb_reset_device()
973 /* stub - currently not supported by libusb20 */ in libusb_attach_kernel_driver()
980 dev->auto_detach = (enable ? 1 : 0); in libusb_set_auto_detach_kernel_driver()
1007 uxfer->num_iso_packets = iso_packets; in libusb_alloc_transfer()
1020 /* check if we should free the transfer buffer */ in libusb_free_transfer()
1021 if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER) in libusb_free_transfer()
1022 free(uxfer->buffer); in libusb_free_transfer()
1025 (uint8_t *)uxfer - sizeof(*sxfer)); in libusb_free_transfer()
1035 switch (xfer->type) { in libusb10_get_maxframe()
1057 switch (xfer->type) { in libusb10_get_buffsize()
1059 ret = 0; /* kernel will auto-select */ in libusb10_get_buffsize()
1108 /* This function must be called locked */
1123 /* set transfer status */ in libusb10_complete_transfer()
1124 uxfer->status = status; in libusb10_complete_transfer()
1126 /* update super transfer state */ in libusb10_complete_transfer()
1127 sxfer->state = LIBUSB_SUPER_XFER_ST_NONE; in libusb10_complete_transfer()
1129 dev = libusb_get_device(uxfer->dev_handle); in libusb10_complete_transfer()
1131 TAILQ_INSERT_TAIL(&dev->ctx->tr_done, sxfer, entry); in libusb10_complete_transfer()
1134 /* This function must be called locked */
1152 return; /* cancelled - nothing to do */ in libusb10_isoc_proxy()
1157 if (iso_packets > uxfer->num_iso_packets) in libusb10_isoc_proxy()
1158 iso_packets = uxfer->num_iso_packets; in libusb10_isoc_proxy()
1164 uxfer->num_iso_packets = iso_packets; in libusb10_isoc_proxy()
1169 uxfer->actual_length = actlen; in libusb10_isoc_proxy()
1171 uxfer->iso_packet_desc[i].actual_length = in libusb10_isoc_proxy()
1181 &uxfer->buffer[actlen], in libusb10_isoc_proxy()
1182 uxfer->iso_packet_desc[i].length, i); in libusb10_isoc_proxy()
1183 actlen += uxfer->iso_packet_desc[i].length; in libusb10_isoc_proxy()
1187 sxfer->rem_len = 0; in libusb10_isoc_proxy()
1192 /* fork another USB transfer, if any */ in libusb10_isoc_proxy()
1193 libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint); in libusb10_isoc_proxy()
1201 /* This function must be called locked */
1219 return; /* cancelled - nothing to do */ in libusb10_bulk_intr_proxy()
1224 flags = uxfer->flags; in libusb10_bulk_intr_proxy()
1229 uxfer->actual_length += actlen; in libusb10_bulk_intr_proxy()
1232 if (sxfer->last_len != actlen) { in libusb10_bulk_intr_proxy()
1241 if (sxfer->rem_len == 0) { in libusb10_bulk_intr_proxy()
1248 if (max_bulk > sxfer->rem_len) { in libusb10_bulk_intr_proxy()
1249 max_bulk = sxfer->rem_len; in libusb10_bulk_intr_proxy()
1253 sxfer->curr_data, max_bulk, uxfer->timeout); in libusb10_bulk_intr_proxy()
1256 sxfer->last_len = max_bulk; in libusb10_bulk_intr_proxy()
1257 sxfer->curr_data += max_bulk; in libusb10_bulk_intr_proxy()
1258 sxfer->rem_len -= max_bulk; in libusb10_bulk_intr_proxy()
1262 /* check if we can fork another USB transfer */ in libusb10_bulk_intr_proxy()
1263 if (sxfer->rem_len == 0) in libusb10_bulk_intr_proxy()
1264 libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint); in libusb10_bulk_intr_proxy()
1273 /* This function must be called locked */
1291 return; /* cancelled - nothing to do */ in libusb10_ctrl_proxy()
1296 flags = uxfer->flags; in libusb10_ctrl_proxy()
1301 uxfer->actual_length += actlen; in libusb10_ctrl_proxy()
1304 actlen -= libusb20_tr_get_length(pxfer, 0); in libusb10_ctrl_proxy()
1307 if (sxfer->last_len != actlen) { in libusb10_ctrl_proxy()
1316 if (sxfer->rem_len == 0) { in libusb10_ctrl_proxy()
1323 if (max_bulk > sxfer->rem_len) { in libusb10_ctrl_proxy()
1324 max_bulk = sxfer->rem_len; in libusb10_ctrl_proxy()
1328 /* next fragment - don't send SETUP packet */ in libusb10_ctrl_proxy()
1331 /* first fragment - send SETUP packet */ in libusb10_ctrl_proxy()
1333 libusb20_tr_set_buffer(pxfer, uxfer->buffer, 0); in libusb10_ctrl_proxy()
1338 libusb20_tr_set_buffer(pxfer, sxfer->curr_data, 1); in libusb10_ctrl_proxy()
1345 sxfer->last_len = max_bulk; in libusb10_ctrl_proxy()
1346 sxfer->curr_data += max_bulk; in libusb10_ctrl_proxy()
1347 sxfer->rem_len -= max_bulk; in libusb10_ctrl_proxy()
1351 /* check if we can fork another USB transfer */ in libusb10_ctrl_proxy()
1352 if (sxfer->rem_len == 0) in libusb10_ctrl_proxy()
1353 libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint); in libusb10_ctrl_proxy()
1362 /* The following function must be called locked */
1399 if (sxfer->rem_len) in libusb10_submit_transfer_sub()
1408 if (sxfer->rem_len) in libusb10_submit_transfer_sub()
1417 /* find next transfer on same endpoint */ in libusb10_submit_transfer_sub()
1418 TAILQ_FOREACH(sxfer, &dev->tr_head, entry) { in libusb10_submit_transfer_sub()
1423 if (uxfer->endpoint == endpoint) { in libusb10_submit_transfer_sub()
1424 TAILQ_REMOVE(&dev->tr_head, sxfer, entry); in libusb10_submit_transfer_sub()
1425 sxfer->entry.tqe_prev = NULL; in libusb10_submit_transfer_sub()
1436 /* reset super transfer state */ in libusb10_submit_transfer_sub()
1437 sxfer->rem_len = uxfer->length; in libusb10_submit_transfer_sub()
1438 sxfer->curr_data = uxfer->buffer; in libusb10_submit_transfer_sub()
1439 uxfer->actual_length = 0; in libusb10_submit_transfer_sub()
1441 switch (uxfer->type) { in libusb10_submit_transfer_sub()
1451 if (sxfer->rem_len < 8) in libusb10_submit_transfer_sub()
1455 sxfer->rem_len -= 8; in libusb10_submit_transfer_sub()
1456 sxfer->curr_data += 8; in libusb10_submit_transfer_sub()
1465 /* make sure the transfer is opened */ in libusb10_submit_transfer_sub()
1467 endpoint, sxfer->stream_id); in libusb10_submit_transfer_sub()
1477 libusb_interrupt_event_handler(dev->ctx); in libusb10_submit_transfer_sub()
1480 /* The following function must be called unlocked */
1495 if (uxfer->dev_handle == NULL) in libusb_submit_transfer()
1498 endpoint = uxfer->endpoint; in libusb_submit_transfer()
1500 dev = libusb_get_device(uxfer->dev_handle); in libusb_submit_transfer()
1502 DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_submit_transfer enter"); in libusb_submit_transfer()
1505 (uint8_t *)uxfer - sizeof(*sxfer)); in libusb_submit_transfer()
1507 CTX_LOCK(dev->ctx); in libusb_submit_transfer()
1509 pxfer0 = libusb10_get_transfer(uxfer->dev_handle, endpoint, 0); in libusb_submit_transfer()
1510 pxfer1 = libusb10_get_transfer(uxfer->dev_handle, endpoint, 1); in libusb_submit_transfer()
1514 } else if ((sxfer->entry.tqe_prev != NULL) || in libusb_submit_transfer()
1518 } else if (dev->device_is_gone != 0) { in libusb_submit_transfer()
1523 sxfer->state = LIBUSB_SUPER_XFER_ST_PEND; in libusb_submit_transfer()
1525 /* insert transfer into transfer head list */ in libusb_submit_transfer()
1526 TAILQ_INSERT_TAIL(&dev->tr_head, sxfer, entry); in libusb_submit_transfer()
1530 uxfer->dev_handle, endpoint); in libusb_submit_transfer()
1535 CTX_UNLOCK(dev->ctx); in libusb_submit_transfer()
1537 DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_submit_transfer leave %d", err); in libusb_submit_transfer()
1542 /* Asynchronous transfer cancel */
1559 if ((devh = uxfer->dev_handle) == NULL) in libusb_cancel_transfer()
1562 endpoint = uxfer->endpoint; in libusb_cancel_transfer()
1566 DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter"); in libusb_cancel_transfer()
1569 (uint8_t *)uxfer - sizeof(*sxfer)); in libusb_cancel_transfer()
1573 CTX_LOCK(dev->ctx); in libusb_cancel_transfer()
1578 if (sxfer->state != LIBUSB_SUPER_XFER_ST_PEND) { in libusb_cancel_transfer()
1579 /* only update the transfer status */ in libusb_cancel_transfer()
1580 uxfer->status = LIBUSB_TRANSFER_CANCELLED; in libusb_cancel_transfer()
1582 } else if (sxfer->entry.tqe_prev != NULL) { in libusb_cancel_transfer()
1583 /* we are lucky - transfer is on a queue */ in libusb_cancel_transfer()
1584 TAILQ_REMOVE(&dev->tr_head, sxfer, entry); in libusb_cancel_transfer()
1585 sxfer->entry.tqe_prev = NULL; in libusb_cancel_transfer()
1589 libusb_interrupt_event_handler(dev->ctx); in libusb_cancel_transfer()
1596 if (dev->device_is_gone != 0) { in libusb_cancel_transfer()
1597 /* clear transfer pointer */ in libusb_cancel_transfer()
1600 libusb_interrupt_event_handler(dev->ctx); in libusb_cancel_transfer()
1610 if (dev->device_is_gone != 0) { in libusb_cancel_transfer()
1611 /* clear transfer pointer */ in libusb_cancel_transfer()
1614 libusb_interrupt_event_handler(dev->ctx); in libusb_cancel_transfer()
1625 CTX_UNLOCK(dev->ctx); in libusb_cancel_transfer()
1627 DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer leave"); in libusb_cancel_transfer()
1635 struct libusb20_device *pdev = dev->os_priv; in libusb10_cancel_all_transfer()
1665 /* complete pending transfer */ in libusb10_cancel_all_transfer_locked()
1669 while ((sxfer = TAILQ_FIRST(&dev->tr_head))) { in libusb10_cancel_all_transfer_locked()
1670 TAILQ_REMOVE(&dev->tr_head, sxfer, entry); in libusb10_cancel_all_transfer_locked()
1672 /* complete pending transfer */ in libusb10_cancel_all_transfer_locked()