Deleted Added
full compact
bulk.c (256281) bulk.c (269879)
1/* ----------------------------------------------------------------------------
2 * "THE BEER-WARE LICENSE" (Revision 42) (by Poul-Henning Kamp):
3 * <joerg@FreeBSD.ORG> wrote this file. As long as you retain this notice you
4 * can do whatever you want with this stuff. If we meet some day, and you think
5 * this stuff is worth it, you can buy me a beer in return. Joerg Wunsch
6 * ----------------------------------------------------------------------------
7 *
1/* ----------------------------------------------------------------------------
2 * "THE BEER-WARE LICENSE" (Revision 42) (by Poul-Henning Kamp):
3 * <joerg@FreeBSD.ORG> wrote this file. As long as you retain this notice you
4 * can do whatever you want with this stuff. If we meet some day, and you think
5 * this stuff is worth it, you can buy me a beer in return. Joerg Wunsch
6 * ----------------------------------------------------------------------------
7 *
8 * $FreeBSD: stable/10/share/examples/libusb20/bulk.c 238603 2012-07-18 21:30:17Z joerg $
8 * $FreeBSD: stable/10/share/examples/libusb20/bulk.c 269879 2014-08-12 14:53:02Z emaste $
9 */
10
11/*
12 * Simple demo program to illustrate the handling of FreeBSD's
13 * libusb20.
14 *
15 * Issues a bulk output, and then requests a bulk input.
16 */

--- 19 unchanged lines hidden (view full) ---

36#include <stdint.h>
37#include <stdlib.h>
38#include <sysexits.h>
39#include <unistd.h>
40
41#include <libusb20.h>
42#include <libusb20_desc.h>
43
9 */
10
11/*
12 * Simple demo program to illustrate the handling of FreeBSD's
13 * libusb20.
14 *
15 * Issues a bulk output, and then requests a bulk input.
16 */

--- 19 unchanged lines hidden (view full) ---

36#include <stdint.h>
37#include <stdlib.h>
38#include <sysexits.h>
39#include <unistd.h>
40
41#include <libusb20.h>
42#include <libusb20_desc.h>
43
44#include "aux.h"
44#include "util.h"
45
46/*
47 * If you want to see the details of the internal datastructures
48 * in the debugger, unifdef the following.
49 */
50#ifdef DEBUG
51# include <sys/queue.h>
52# include "/usr/src/lib/libusb/libusb20_int.h"

--- 16 unchanged lines hidden (view full) ---

69 * Open the device, allocating memory for two possible (bulk or
70 * interrupt) transfers.
71 *
72 * If only control transfers are intended (via
73 * libusb20_dev_request_sync()), transfer_max can be given as 0.
74 */
75 if ((rv = libusb20_dev_open(dev, 2)) != 0)
76 {
45
46/*
47 * If you want to see the details of the internal datastructures
48 * in the debugger, unifdef the following.
49 */
50#ifdef DEBUG
51# include <sys/queue.h>
52# include "/usr/src/lib/libusb/libusb20_int.h"

--- 16 unchanged lines hidden (view full) ---

69 * Open the device, allocating memory for two possible (bulk or
70 * interrupt) transfers.
71 *
72 * If only control transfers are intended (via
73 * libusb20_dev_request_sync()), transfer_max can be given as 0.
74 */
75 if ((rv = libusb20_dev_open(dev, 2)) != 0)
76 {
77 fprintf(stderr, "libusb20_dev_open: %s\n", usb_error(rv));
77 fprintf(stderr, "libusb20_dev_open: %s\n", libusb20_strerror(rv));
78 return;
79 }
80
81 /*
82 * If the device has more than one configuration, select the desired
83 * one here.
84 */
85 if ((rv = libusb20_dev_set_config_index(dev, 0)) != 0)
86 {
78 return;
79 }
80
81 /*
82 * If the device has more than one configuration, select the desired
83 * one here.
84 */
85 if ((rv = libusb20_dev_set_config_index(dev, 0)) != 0)
86 {
87 fprintf(stderr, "libusb20_dev_set_config_index: %s\n", usb_error(rv));
87 fprintf(stderr, "libusb20_dev_set_config_index: %s\n", libusb20_strerror(rv));
88 return;
89 }
90
91 /*
92 * Two transfers have been requested in libusb20_dev_open() above;
93 * obtain the corresponding transfer struct pointers.
94 */
95 struct libusb20_transfer *xfr_out = libusb20_tr_get_pointer(dev, 0);
96 struct libusb20_transfer *xfr_in = libusb20_tr_get_pointer(dev, 1);
97
98 if (xfr_in == NULL || xfr_out == NULL)
99 {
88 return;
89 }
90
91 /*
92 * Two transfers have been requested in libusb20_dev_open() above;
93 * obtain the corresponding transfer struct pointers.
94 */
95 struct libusb20_transfer *xfr_out = libusb20_tr_get_pointer(dev, 0);
96 struct libusb20_transfer *xfr_in = libusb20_tr_get_pointer(dev, 1);
97
98 if (xfr_in == NULL || xfr_out == NULL)
99 {
100 fprintf(stderr, "libusb20_tr_get_pointer: %s\n", usb_error(rv));
100 fprintf(stderr, "libusb20_tr_get_pointer: %s\n", libusb20_strerror(rv));
101 return;
102 }
103
104 /*
105 * Open both transfers, the "out" one for the write endpoint, the
106 * "in" one for the read endpoint (ep | 0x80).
107 */
108 if ((rv = libusb20_tr_open(xfr_out, 0, 1, out_ep)) != 0)
109 {
101 return;
102 }
103
104 /*
105 * Open both transfers, the "out" one for the write endpoint, the
106 * "in" one for the read endpoint (ep | 0x80).
107 */
108 if ((rv = libusb20_tr_open(xfr_out, 0, 1, out_ep)) != 0)
109 {
110 fprintf(stderr, "libusb20_tr_open: %s\n", usb_error(rv));
110 fprintf(stderr, "libusb20_tr_open: %s\n", libusb20_strerror(rv));
111 return;
112 }
113 if ((rv = libusb20_tr_open(xfr_in, 0, 1, in_ep)) != 0)
114 {
111 return;
112 }
113 if ((rv = libusb20_tr_open(xfr_in, 0, 1, in_ep)) != 0)
114 {
115 fprintf(stderr, "libusb20_tr_open: %s\n", usb_error(rv));
115 fprintf(stderr, "libusb20_tr_open: %s\n", libusb20_strerror(rv));
116 return;
117 }
118
119 uint8_t in_buf[BUFLEN];
120 uint32_t rlen;
121
122 if (out_len > 0)
123 {
124 if ((rv = libusb20_tr_bulk_intr_sync(xfr_out, out_buf, out_len, &rlen, TIMEOUT))
125 != 0)
126 {
116 return;
117 }
118
119 uint8_t in_buf[BUFLEN];
120 uint32_t rlen;
121
122 if (out_len > 0)
123 {
124 if ((rv = libusb20_tr_bulk_intr_sync(xfr_out, out_buf, out_len, &rlen, TIMEOUT))
125 != 0)
126 {
127 fprintf(stderr, "libusb20_tr_bulk_intr_sync (OUT): %s\n", usb_error(rv));
127 fprintf(stderr, "libusb20_tr_bulk_intr_sync (OUT): %s\n", libusb20_strerror(rv));
128 }
129 printf("sent %d bytes\n", rlen);
130 }
131
132 if ((rv = libusb20_tr_bulk_intr_sync(xfr_in, in_buf, BUFLEN, &rlen, TIMEOUT))
133 != 0)
134 {
128 }
129 printf("sent %d bytes\n", rlen);
130 }
131
132 if ((rv = libusb20_tr_bulk_intr_sync(xfr_in, in_buf, BUFLEN, &rlen, TIMEOUT))
133 != 0)
134 {
135 fprintf(stderr, "libusb20_tr_bulk_intr_sync: %s\n", usb_error(rv));
135 fprintf(stderr, "libusb20_tr_bulk_intr_sync: %s\n", libusb20_strerror(rv));
136 }
137 printf("received %d bytes\n", rlen);
138 if (rlen > 0)
139 print_formatted(in_buf, rlen);
140
141 libusb20_tr_close(xfr_out);
142 libusb20_tr_close(xfr_in);
143

--- 100 unchanged lines hidden ---
136 }
137 printf("received %d bytes\n", rlen);
138 if (rlen > 0)
139 print_formatted(in_buf, rlen);
140
141 libusb20_tr_close(xfr_out);
142 libusb20_tr_close(xfr_in);
143

--- 100 unchanged lines hidden ---