1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
|
'\" te
.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH UGEN 7D "Sep 10, 2013"
.SH NAME
ugen \- USB generic driver
.SH SYNOPSIS
.LP
.nf
\fBNode Name@unit-address\fR
.fi
.LP
.nf
\fB#include <sys/usb/clients/ugen/usb_ugen.h>\fR
.fi
.SH DESCRIPTION
.sp
.LP
\fBugen\fR is a generic USBA (Solaris USB Architecture) compliant client
character driver that presents USB devices to applications through a standard
\fBopen\fR(2), \fBclose\fR(2), \fBread\fR(2), \fBwrite\fR(2),
\fBaioread\fR(3C), \fBaiowrite\fR(3C) Unix interface. Uninterpreted raw data
are transfered to and from the device via file descriptors created for each USB
endpoint. Status is obtained by reading file descriptors created for endpoint
and full device status.
.sp
.LP
\fBugen\fR supports control, bulk, isochronous and interrupt (in and out)
transfers. \fBlibusb\fR(3LIB) uses \fBugen\fR to access devices that do not
contain drivers (such as digital cameras and PDAs). Refer to
\fB/usr/sfw/share/doc/libusb/libusb.txt\fR for details.
.SH BINDING
.sp
.LP
In general, no explicit binding of the \fBugen\fR driver is necessary because
\fBusb_mid\fR(7D) is the default driver for devices without a class or vendor
unique driver. \fBusb_mid\fR(7D) creates the same logical device names as
\fBugen\fR, but only if no child interfaces are explicitly bound to \fBugen\fR.
If it is necessary to bind \fBugen\fR explicitly to a device or interface, the
following section explains the necessary steps.
.sp
.LP
\fBugen\fR can bind to a device with one or more interfaces in its entirety, or
to a single interface of that device. The binding type depends on information
that is passed to \fBadd_drv\fR(1M) or \fBupdate_drv\fR(1M).
.sp
.LP
An \fBadd_drv\fR(1M) command binds \fBugen\fR to a list of device types it is
to control. \fBupdate_drv\fR(1M) adds an additional device type to the list of
device types being managed by the driver.
.sp
.LP
Names used to bind drivers can be found in \fB/var/adm/messages\fR. When a
device is on-lined after hot insertion, and no driver is found, there will be
an entry containing:
.sp
.in +2
.nf
USB 2.0 device (usb<vid>,<pid>)...
.fi
.in -2
.sp
.LP
where vid is the USB vendor identifier in hex and pid is the product
identifier in hex supplied by the device descriptor \fBusb_dev_descr\fR(9S).
.sp
.LP
When using ugen for the first time, you must add the driver utilizing
\fBadd_drv\fR(1M), using a command of the following form:
.sp
.in +2
.nf
Assuming that the vid is 472 and pid is b0b0:
add_drv -n -m '* <device perms> <owner> <group>'
-i '"usb472,b0b0"' ugen
.fi
.in -2
.sp
.LP
If the command fails with:
.sp
.in +2
.nf
(ugen) already in use as a driver or alias.
.fi
.in -2
.sp
.LP
\&...add the device using \fBupdate_drv\fR(1M):
.sp
.in +2
.nf
update_drv -a -m '* <device perms> <owner> <group>'
-i '"usb472,b0b0"' ugen
.fi
.in -2
.sp
.LP
This binds \fBugen\fR to the entire device.
.sp
.LP
If ugen only binds to one interface of the device, use the following
driver_alias instead of usb<vid>,<pid>:
.sp
.in +2
.nf
usbif<vid>,<pid>.config<cfg value>.<interface number>
.fi
.in -2
.sp
.LP
where cfg value is the value of bConfigurationValue in the configuration
descriptor (\fBusb_cfg_descr\fR(9S)). For example "usbif1234,4567.config1.0."
.sp
.LP
Note that you can use update_drv to also remove bindings. Please see
\fBupdate_drv\fR(1M) for more information.
.sp
.LP
After a successful add_drv or update_drv, remove the device and reinsert. Check
with the \fBprtconf\fR(1M) -D option to determine if \fBugen\fR is successfully
bound to the device and the nodes created in /dev/usb/<vid>.<pid> (see below).
.sp
.LP
An example showing how to bind a child device representing interface 0 of
configuration 1 of a composite device follows:
.sp
.in +2
.nf
update_drv -a -m '* 0666 root sys'
-i '"usbif472,b0b0.config1.0"' ugen
.fi
.in -2
.sp
.LP
Note that you can completely uninstall the \fBugen\fR driver and delete it from
the system by doing:
.sp
.in +2
.nf
pkgrm SUNWugen
.fi
.in -2
.sp
.LP
Any \fBpkgadd\fR of SUNWugen after the \fBpkgrm\fR reactivates any pre-existing
ugen driver device-bindings.
.sp
.LP
Any pre-existing ugen driver device-bindings are preserved across operating
system upgrades.
.SH LOGICAL DEVICE NAME FORMAT
.sp
.LP
For each device or child device it manages, \fBugen\fR creates one logical
device name for device-wide status and one logical device name for endpoint 0.
\fBugen\fR also creates logical device names for all other endpoints within the
device node's binding scope (interface or device), plus logical device names
for their status.
.sp
.LP
If separate \fBugen\fR instances control different interfaces of the same
device, the device-wide status and endpoint logical device names created for
each instance will share access to the same source or endpoint pipes. For
example, a device with two interfaces, each operated by their own \fBugen\fR
instance, will show \fBendpoint0\fR as \fBif0cntrl0\fR to the first interface,
and will show it as \fBif1cntrl0\fR to the second interface. Both of these
logical device names share \fBendpoint0\fR. Likewise for the same device,
\fBugen\fR makes the device-wide status available as \fBif0devstat\fR to the
first interface and as \fBif1devstat\fR to the second interface.
\fBif0devstat\fR and \fBif1devstat\fR both return the same data.
.sp
.LP
Any \fBugen\fR logical device name can be held open by only one user at a time,
regardless of whether the\fB O_EXCL\fR flag passed to \fBopen\fR(2). When a
single pipe or data source is shared by multiple logical device names, such as
if[0,1]cntrl0 or if[0,1]devstat above, more than one logical device name
sharing the pipe or data source can be open at a time. However, only one user
may access the shared pipe or data source at a time, regardless of the logical
device name used for access.
.sp
.LP
When \fBugen\fR is bound to an entire device, the following logical device
names are created (each on a single line). \fIN\fR represents the instance
number of the device type.
.sp
.in +2
.nf
Endpoint 0 (default endpoint):
/dev/usb/<vid>.<pid>/<N>/cntrl0
/dev/usb/<vid>.<pid>/<N>/cntrl0stat
For example:
/dev/usb/472.b0b0/0/cntrl0
/dev/usb/472.b0b0/0/cntrl0stat
Configuration index 1, Endpoints > 0, alternate 0:
/dev/usb/<vid>.<pid>/<N>/if<interface#>
<in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/if<interface#>
<in|out|cntrl><endpoint#>stat
For example:
/dev/usb/472.b0b0/0/if0in1
/dev/usb/472.b0b0/0/if0in1stat
Configuration index 1, Endpoints > 0, alternate > 0:
/dev/usb/<vid>.<pid>/<N>/if<interface#>.
<alternate><in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/if<interface#>.
<alternate<in|out|cntrl><endpoint#>stat
For example:
/dev/usb/472.b0b0/0/if0.1in3
/dev/usb/472.b0b0/0/if0.1in3stat
Configuration index> 1, Endpoints > 0, alternate 0:
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>
<in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>
<in|out|cntrl><endpoint#>stat
For example:
/dev/usb/472.b0b0/0/cfg2if0in1
/dev/usb/472.b0b0/0/cfg2if0in1stat
Note that the configuration value from the configuration
descriptor indexed by the configuration index is used in
the node name and not the configuration index itself.
Configuration index> 1, Endpoints > 0, alternate > 0:
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>.
<alternate<in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>.
<alternate<in|out|cntrl><endpoint#>stat
For example:
/dev/usb/472.b0b0/0/cfg2if0.1in1
/dev/usb/472.b0b0/0/cfg2if0.1in1stat
Device status:
/dev/usb/<vid>.<pid>/<N>/devstat
For example:
/dev/usb/472.b0b0/0/devstat
.fi
.in -2
.sp
.LP
When \fBugen\fR is bound to a single device interface, the following logical
device nodes are created:
.sp
.in +2
.nf
Endpoint 0 (default endpoint):
/dev/usb/<vid>.<pid>/<N>/if<interface#>cntrl0
/dev/usb/<vid>.<pid>/<N>/if<interface#>cntrl0stat
For example:
/dev/usb/472.b0b0/0/if0cntrl0
/dev/usb/472.b0b0/0/if0cntrl0stat
Device status:
/dev/usb/<vid>.<pid>/<N>/if<interface#>devstat
For example:
/dev/usb/472.b0b0/0/if0devstat
.fi
.in -2
.sp
.LP
The format for all other logical device names is identical to the format used
when \fBugen\fR is bound to the entire device.
.sp
.LP
Opening the endpoint of a different configuration or different alternate
interface will cause an implicit change of configuration or a switch to an
alternate interface. A configuration change is prohibited when any non-zero
endpoint device nodes are open. An alternate interface switch is prohibited if
any endpoint in the same interface is open.
.SH HOT-PLUGGING
.sp
.LP
A device may be hot-removed at any time. Following hot-removal, the device
status changes to USB_DEV_STAT_DISCONNECTED, the status of open endpoints
change to USB_LC_STAT_DISCONNECTED upon their access, and all subsequent
transfer requests fail. Endpoints are reactivated by first reinserting the
device and then closing and reopening all endpoints that were open when the
device was disconnected.
.SH CPR (CHECKPOINT/RESUME)
.sp
.LP
CPR (Checkpoint/Resume) may be initiated at any time and is treated similarly
to a hot-removal. Upon successful suspend and resume, all subsequent transfer
requests fail as an indication to the application to reinitialize. Applications
should close and reopen all endpoints to reinstate them. All endpoint and
device status on Resume (before close and reopen) is USB_LC_STAT_SUSPENDED. A
system suspend will fail while \fBugen\fR is performing a transfer.
.SH DEVICE POWER MANAGEMENT
.sp
.LP
Devices which support remote wakeup can be power managed when they have no open
logical device nodes. When an application opens the first logical device node
of a device, that application should assume that a reinitialization of device
state is required.
.SH DEVICE STATUS MANAGEMENT
.sp
.LP
Applications can monitor device status changes by reading the device status
from the device status logical name. When opened without O_NONBLOCK and
O_NDELAY, all reads from that file descriptor (with the exception of the the
intial read that follows the open) block until a device status change occurs.
Calls to read will always return immediately if opened with \fBO_NONBLOCK\fR or
\fBO_NDELAY\fR. Nonblocking calls to read which have no data to return, return
no error and zero bytes read.
.sp
.LP
Device statuses are:
.sp
.ne 2
.na
\fBUSB_DEV_STAT_ONLINE\fR
.ad
.RS 29n
Device is available.
.RE
.sp
.ne 2
.na
\fBUSB_DEV_STAT_DISCONNECTED\fR
.ad
.RS 29n
Device has been disconnected.
.RE
.sp
.ne 2
.na
\fBUSB_DEV_STAT_RESUMED\fR
.ad
.RS 29n
Device has been resumed, however, endpoints which were open on suspend have not
yet been closed and reopened.
.RE
.sp
.ne 2
.na
\fBUSB_DEV_STAT_UNAVAILABLE\fR
.ad
.RS 29n
Device has been reconnected, however, endpoints which were open on disconnect
have not yet been closed and reopened.
.RE
.sp
.LP
The following code reads the device status device logical name:
.sp
.in +2
.nf
int fd;
int status;
if ((fd = open("/dev/usb/472.b0b0/0/devstat",
O_RDONLY)) < 0) {
/* handle error */
}
if (read(fd, &status, sizeof(status)) != sizeof(status)) {
/* handle error */
}
switch (status) {
case USB_DEV_STAT_DISCONNECTED:
printf ("Terminating as device has been disconnected.\en");
exit (0);
case USB_DEV_STAT_RESUMED:
case USB_DEV_STAT_UNAVAILABLE:
/*
* Close and reopen endpoints to reestablish device access,
* then reset device.
*/
break;
case USB_DEV_STAT_ONLINE:
default:
break;
}
.fi
.in -2
.sp
.LP
Use \fBpoll\fR(2) to block on several logical names simultaneously, including
device status logical names. Poll indicates when reading a logical name would
return data. See \fBpoll\fR(2) for details. Calls to read may be done whether
or not they follow calls to poll.
.SH ENDPOINT STATUS MANAGEMENT
.sp
.LP
Each data endpoint has a corresponding status logical name. Use the status
logical name to retrieve the state of the data endpoint, including detail on
how its most recent transfer failed. Reads of the status file descriptors
always return immediately. See the ERRORS section for more information on
endpoint status values. All logical device name files created for returning
status must be opened with \fBO_RDONLY\fR.
.sp
.LP
The following code illustrates reading the status file descriptor of an
endpoint which just failed a data transfer in order to get more information on
the failure.
.sp
.in +2
.nf
int data_xfered, status;
int ep1_data_fd, ep1_stat_fd;
uchar_t request[8];
ep1_data_fd = open ("/dev/usb/472.b0b0/0/if0out1", O_WRONLY);
if (ep1_data_fd < 0) {
/* Handle open error. */
}
ep1_stat_fd = open ("/dev/usb/472.b0b0/0/if0out1stat",
O_RDONLY);
if (ep1_stat_fd < 0) {
/* Handle open error. */
}
data_xfered = write(ep1_data_fd, request, sizeof (request));
/* An error occured during the data transfer. */
if (data_xfered != sizeof (request)) {
/* Read status file descriptor for details on failure. */
if (read(ep1_stat_fd, (int *)&status, sizeof (status)) !=
sizeof (status)) {
status = USB_LC_STAT_UNSPECIFIED_ERR;
}
/* Take appropriate action. */
switch (status) {
case USB_LC_STAT_STALL:
printf ("Endpoint stalled.\en");
break;
case ...
...
}
}
.fi
.in -2
.SH CONTROL TRANSFERS
.sp
.LP
The control endpoint is typically used to set up the device and to query device
status or configuration.
.sp
.LP
Applications requiring I/O on a control endpoint should open the corresponding
logical device name and use regular UNIX I/O system calls. For example:
\fBread\fR(2), \fBwrite\fR(2), \fBaioread\fR(3C) and \fBaiowrite\fR(3C).
\fBpoll\fR(2) is not supported on control endpoints.
.sp
.LP
A control endpoint must be opened with \fBO_RDWR\fR since it is bidirectional.
It cannot be opened with \fBO_NONBLOCK\fR or \fBO_NDELAY\fR.
.sp
.LP
For example:
.sp
.in +2
.nf
fd = open("/dev/usb/472.b0b0/0/cntrl0", O_RDWR);
.fi
.in -2
.sp
.in +2
.nf
fdstat = open("/dev/usb/472.b0b0/0/cntrl0stat", O_RDONLY);
.fi
.in -2
.sp
.LP
Control endpoints can be read and written. A \fBread\fR operation receives data
\fBfrom\fR the device and a \fBwrite\fR operation sends data \fBto\fR the
device.
.sp
.LP
To perform a control-IN transfer, perform a \fBwrite\fR(2) of USB setup data
(see section 9.3 of the \fIUSB 1.1\fR or \fI2.0\fR specifications) followed by
a \fBread\fR(2) on the same control endpoint to fetch the desired data. For
example:
.sp
.in +2
.nf
void init_cntrl_req(
uchar_t *req, uchar_t bmRequestType, uchar_t bRequest,
ushort_t wValue, ushort_t wIndex, ushort_t wLength) {
req[0] = bmRequestType;
req[1] = bRequest;
req[2] = 0xFF & wValue;
req[3] = 0xFF & (wValue >> 8);
req[4] = 0xFF & wIndex;
req[5] = 0xFF & (wIndex >> 8);
req[6] = 0xFF & wLength;
req[7] = 0xFF & (wLength >> 8);
}
....
uchar_t dev_descr_req[8];
usb_dev_descr_t descr;
init_cntrl_req(dev_descr_req,
USB_DEV_REQ_DEV_TO_HOST, USB_REQ_GET_DESCR,
USB_DESCR_TYPE_SETUP_DEV, 0, sizeof (descr));
count = write(fd, dev_descr_req, sizeof (dev_descr_req));
if (count != sizeof (dev_descr_req)) {
/* do some error recovery */
...
}
count = read(fd, &descr, sizeof (descr));
if (count != sizeof (descr)) {
/* do some error recovery */
}
.fi
.in -2
.sp
.LP
The application can issue any number of reads to read data received on a
control endpoint. \fBugen\fR successfully completes all reads, returning the
number of bytes transferred. Zero is returned when there is no data to
transfer.
.sp
.LP
If the \fBread\fR/\fBwrite\fR fails and returns \fB-1\fR, you can access the
endpoint's status device logical name for precise error information:
.sp
.in +2
.nf
int status;
count = read(fdstat, &status, sizeof (status));
if (count == sizeof (status)) {
switch (status) {
case USB_LC_STAT_SUSPENDED:
case USB_LC_STAT_DISCONNECTED:
/* close all endpoints */
...
break;
default:
...
break;
}
}
.fi
.in -2
.sp
.LP
Refer to the ERRORS section for all possible error values.
.sp
.LP
To perform a control-OUT transfer, send in a single transfer, the USB setup
data followed by any accompanying data bytes.
.sp
.in +2
.nf
/* 1st 8 bytes of wbuf are setup. */
init_cntrl_req(wbuf, .......);
/* Data bytes begin at byte 8 of wbuf. */
bcopy(data, &wuf[8], sizeof (data));
/* Send it all in a single transfer. */
count = write(fd, wbuf, sizeof (wbuf));
.fi
.in -2
.sp
.LP
A \fBwrite\fR(2) returns the number of bytes (both setup and data) actually
transferred, (whether or not the \fBwrite\fR is completely successful),
provided that some data is actually transferred. When no data is transferred,
\fBwrite\fR(2) returns \fB-1\fR. Applications can read the corresponding
endpoint status to retrieve detailed error information. Note that it is an
error to specify a size different than:
.sp
.LP
(number of data bytes + number of setup bytes).
.sp
.LP
Here is a more extensive example which gets all descriptors of a device
configuration. For sake of brevity, uninteresting parts are omitted.
.sp
.in +2
.nf
#include <sys/usb/usba.h>
#include <sys/usb/clients/ugen/usb_ugen.h>
uchar_t *config_cloud;
uchar_t *curr_descr;
uchar_t *bytes;
int curr_descr_len;
int curr_descr_type;
usb_cfg_descr_t cfg_descr;
usb_if_descr_t if_descr;
usb_ep_descr_t ep_descr;
/* See 9.13 of USB 2.0 spec for ordering. */
static char *pipetypes[] = {
"Control", "Isochronous", "Bulk", "Interrupt"
};
/*
* Setup to send a request to read just the config descriptor. The
* size of the whole cloud, containing all cfg, interface, endpoint,
* class and vendor-specific descriptors, will be returned as part of
* the config descriptor.
*/
init_cntrl_req(&setup_data, USB_DEV_REQ_DEV_TO_HOST, USB_REQ_GET_DESCR,
USB_DESCR_TYPE_SETUP_CFG, 0, USB_CFG_DESCR_SIZE);
/*
* Write setup data. USB device will prepare to return the whole
* config cloud as a response to this. We will read this separately.
*/
count = write(ctrl_fd, &setup_data, sizeof (setup_data));
if (count != sizeof (setup_data)) {
/* Error recovery. */
} else {
count = read(ctrl_fd, &cfg_descr, USB_CFG_DESCR_SIZE);
if (count != USB_CFG_DESCR_SIZE) {
/* Error recovery. */
}
}
/* USB data is little endian. */
bytes = (uchar_t *)(&cfg_descr.wTotalLength);
totalLength = bytes[0] + (bytes[1] << 8);
/*
* The size of the whole cloud is in the bLength field. Set up
* to read this amount of data, to get the whole cloud.
*/
config_cloud = malloc(totalLength);
init_cntrl_req(&setup_data, USB_DEV_REQ_DEV_TO_HOST, USB_REQ_GET_DESCR,
USB_DESCR_TYPE_SETUP_CFG, 0, totalLength);
count = write(ctrl_fd, &setup_data, sizeof (setup_data));
if (count != sizeof (setup_data)) {
/* Error recovery. */
} else {
count = read(ctrl_fd, config_cloud, totalLength);
if (count != totalLength) {
/* Error recovery. */
}
}
/* Got the data. Now loop, dumping out the descriptors found. */
curr_descr = config_cloud;
offset = 0;
while (offset < totalLength) {
/* All descr have length and type at offset 0 and 1 */
curr_descr_len = curr_descr[0];
curr_descr_type = curr_descr[1];
switch (curr_descr_type) {
case USB_DESCR_TYPE_CFG:
/*
* Copy data into separate structure, needed for
* proper alignment of all non char fields. Note:
* non-char fields of all descriptors begin on aligned
* boundaries. The issue is that some structures may
* be adjacent to others which have an odd-numbered
* byte size, and may thus start on an odd-numbered
* boundary. */
bcopy(curr_descr, &cfg_descr, curr_descr_len);
/* Remember to read any words in endian-neutral way. */
(void) printf("\enConfig %d found.\en",
cfg_descr.bConfigurationValue);
break;
case USB_DESCR_TYPE_IF:
bcopy(curr_descr, &if_descr, curr_descr_len);
(void) printf("\en\etInterface %d, Alt %d found.\en",
if_descr.bInterfaceNumber,
if_descr.bAlternateSetting);
break;
case USB_DESCR_TYPE_EP:
bcopy(curr_descr, &ep_descr, curr_descr_len);
(void) printf("\en\et\etEndpoint %d (%s-%s) found.\en",
(ep_descr.bEndpointAddress & USB_EP_NUM_MASK),
(pipetypes[
ep_descr.bmAttributes & USB_EP_ATTR_MASK]),
((ep_descr.bEndpointAddress &
USB_EP_DIR_IN) ? "IN" : "OUT"));
break;
default:
(void) printf(
"\en\et\et\etOther descriptor found. Type:%d\en",
curr_descr_type);
break;
}
offset += curr_descr_len;
curr_descr = &config_cloud[offset];
}
.fi
.in -2
.SH INTERRUPT-IN TRANSFERS
.sp
.LP
Applications requiring data from an interrupt-IN endpoint should open the
corresponding logical device name and use \fBread\fR(2), \fBaioread\fR(3C) and
\fBpoll\fR(2) system calls.
.sp
.LP
An interrupt-IN endpoint must be opened with \fBO_RDONLY\fR. It can also be
opened using \fBO_NONBLOCK\fR or \fBO_NDELAY\fR if desired.
.sp
.in +2
.nf
fd = open("/dev/usb/472.b0b0/0/if0in1", O_RDONLY);
.fi
.in -2
.sp
.in +2
.nf
fdstat = open("/dev/usb/472.b0b0/0/if0in1stat", O_RDONLY);
.fi
.in -2
.sp
.LP
\fBugen\fR starts polling interrupt\(emIN endpoints immediately upon opening
them and stops polling them upon closure. (Polling refers to interrogation of
the device by the driver and should not be confused with \fBpoll\fR(2), which
is an interrogation of the driver by the application.)
.sp
.LP
A \fBread\fR(2) of an endpoint opened with the \fBO_NONBLOCK\fR or
\fBO_NDELAY\fR flags set will not block when there is insufficient data
available to satisfy the request. The \fBread\fR simply returns what it can
without signifying any error.
.sp
.LP
Applications should continuously check for and consume interrupt data.
\fBugen\fR enables buffering of up to one second of incoming data. In case of
buffer overflow, \fBugen\fR stops polling the interrupt-IN endpoint until the
application consumes all the data. In this case, a \fBread\fR(2) of an empty
buffer returns \fB-1\fR, sets the endpoint status to
\fBUSB_LC_STAT_INTR_BUF_FULL\fR (to indicate that the buffer had been full and
polling had been stopped) and causes \fBugen\fR to start polling the endpoint
again. To retrieve the status, the application can open and read the
corresponding endpoint's status device logical name.
.sp
.in +2
.nf
for (;;) {
count = read(fd, buf, sizeof(buf));
if (count == -1) {
int cnt, status;
cnt = read(fdstat, &status, sizeof (status));
if (cnt == -1) {
/* more error recovery here */
} else {
switch (status) {
case USB_LC_STAT_INTR_BUF_FULL:
...
break;
default:
...
break;
}
}
}
/* process the data */
....
}
.fi
.in -2
.sp
.LP
\fBugen\fR will never drop data. However, the device may drop data if the
application cannot read it at the rate that it is produced.
.sp
.LP
Applications requiring unbuffered data from an interrupt-IN endpoint should
open the associated status endpoint with O_RDWR before opening the associated
interrupt-IN endpoint and write a control byte with USB_EP_INTR_ONE_XFER set.
All other bits are reserved and should be 0.
.sp
.LP
"One transfer" mode will persist until disabled explicitly after the associated
interrupt-IN endpoint has been closed by writing a control byte with
USB_EP_INTR_ONE_XFER cleared.
.sp
.LP
"One transfer" mode is implicitly disabled when the status/control endpoint is
closed.
.sp
.LP
Attempts to change the "one transfer" mode while the endpoint is open will
result in \fBEINVAL\fR.
.sp
.LP
An application can open multiple interrupt-IN endpoints and can call
\fBpoll\fR(2) to monitor the availability of new data. (Note: poll works with
interrupt-IN data endpoints, not their status endpoints.)
.sp
.in +2
.nf
struct pollfd pfd[2];
bzero(pfd, sizeof (pfd));
pfd[0].fd = fd1; /* fd1 is one interrupt-IN endpoint. */
pfd[0].events = POLLIN;
pfd[1].fd = fd2; /* fd2 is another interrupt-IN endpoint. */
pfd[1].events = POLLIN;
for (;;) {
poll(pfd, 2, -1);
if (pfd[0].revents & POLLIN) {
count = read(fd1, buf, sizeof (buf));
....
}
if (pfd[1].revents & POLLIN) {
count = read(fd2, buf, sizeof (buf));
....
}
}
.fi
.in -2
.sp
.LP
You can monitor the device status endpoint via \fBpoll\fR(2) concurrently with
the multiple interrupt-IN endpoints. Simply add another pollfd element to the
pfd array in the previous code example, and initialize the new element's
\fBfd\fR field with the file descriptor of the device status endpoint (opened
without O_NONBLOCK or O_NDELAY). Set the new element's event field to POLLIN
like the other elements. Note that only interrupt-IN endpoints and the device
status endpoint can be monitored using \fBpoll\fR(2).
.SH INTERRUPT-OUT TRANSFERS
.sp
.LP
Applications requiring output on an interrupt-OUT endpoint can open the
corresponding logical device name and perform regular UNIX I/O system calls
such as \fBwrite\fR(2) and \fBaiowrite\fR(3C).
.sp
.LP
An interrupt-OUT endpoint must be opened with O_WRONLY.
.sp
.in +2
.nf
fd = open("/dev/usb/472.b0b0/0/if0out3", O_WRONLY);
fdstat = open("/dev/usb/472.b0b0/0/if0out3stat", O_RDONLY);
.fi
.in -2
.sp
.LP
Data can be written to an interrupt-OUT endpoint as follows:
.sp
.in +2
.nf
count = write(fd, buf, sizeof (buf)):
if (count == -1) {
/* error recovery */
}
.fi
.in -2
.SH BULK TRANSFERS
.sp
.LP
Applications requiring I/O on a bulk endpoint can open the corresponding
logical device name and perform regular UNIX I/O system calls. For example:
\fBread\fR(2), \fBwrite\fR(2), \fBaioread\fR(3C) and \fBaiowrite\fR(3C).
\fBpoll\fR(2) is not supported on bulk endpoints.
.sp
.LP
A bulk endpoint must be opened with \fBO_RDONLY\fR or \fBO_WRONLY\fR and cannot
be opened with \fBO_NONBLOCK\fR or \fBO_NDELAY:\fR
.sp
.in +2
.nf
fd = open("/dev/usb/472.b0b0/0/if0in2", O_RDONLY);
.fi
.in -2
.sp
.in +2
.nf
fdstat = open("/dev/usb/472.b0b0/0/if0in2stat", O_RDONLY);
.fi
.in -2
.sp
.LP
Data can be read from a bulk-IN endpoint as follows:
.sp
.in +2
.nf
count = read(fd, buf, sizeof (buf)):
if (count == -1) {
/* error recovery */
}
Data can be written to a bulk-OUT endpoint as follows:
count = write(fd, buf, sizeof (buf)):
if (count == -1) {
/* error recovery */
}
.fi
.in -2
.SH ISOCHRONOUS TRANSFERS
.sp
.LP
Applications requiring I/O on an isochronous endpoint can open the
corresponding logical device name and perform regular UNIX I/O system calls
such as \fBread\fR(2), \fBwrite\fR(2), \fBpoll\fR(2), \fBaioread\fR(3C) and
\fBaiowrite\fR(3C). An isochronous endpoint must be opened with \fBO_RDWR\fR.
.sp
.in +2
.nf
fd = open("/dev/usb/472.b0b0/0/if0.3in2", O_RDWR);
fdstat = open("/dev/usb/472.b0b0/0/if0.3in2stat", O_RDONLY);
.fi
.in -2
.sp
.LP
Applications can use the status logical name to retrieve the state of the
isochronous data endpoint, including details on why the most recent transfer
failed.
.sp
.LP
Applications have the flexibility to specify the number of isochronous packets
and the size of individual packets they want to transfer. Applications should
use the following data structures to exchange isochronous packet information
with the \fBugen\fR driver:
.sp
.in +2
.nf
typedef struct ugen_isoc_pkt_descr {
/*
* Set by the application, for all isochro.
* requests, to the num. of bytes to xfer
* in a packet.
*/
ushort_t dsc_isoc_pkt_len;
/*
* Set by ugen to actual num. of bytes sent/received
* in a packet.
*/
ushort_t dsc_isoc_pkt_actual_len;
/*
* Per pkt. status set by ugen driver both for the
* isochronous IN and OUT requests. Application can
* use USB_LC_STAT_* to parse the status.
*/
int dsc_isoc_pkt_status;
} ugen_isoc_pkt_descr_t;
typedef struct ugen_isoc_req_head {
/* pkt count of the isoc request */
int req_isoc_pkts_count;
/* pkt descriptors */
ugen_isoc_pkt_descr_t req_isoc_pkt_descrs[1];
} ugen_isoc_req_head_t;
.fi
.in -2
.sp
.LP
\fBreq_isoc_pkts_count\fR is limited by the capability of the USB host
controller driver. The current upper bound for the \fBuhci\fR and \fBohci\fR
drivers is 512. The upper bound for the \fBehci\fR driver is 1024.
.sp
.LP
For an isochronous-IN endpoint, applications must first use the
\fBugen_isoc_req_head_t\fR structure followed by \fBugen_isoc_pkt_descr_t\fR to
write packet request information to the \fBugen\fR node. The \fBugen\fR driver
then checks the validity of the request. If it is valid, the driver immediately
begins isochronous polling on the IN endpoint and applications can proceed with
\fBread\fR(2) of the data on the isochronous-IN endpoint. Upon successful
return of \fBread\fR(2), isochronous packet descriptors (whose
\fBdsc_isoc_pkt_actual_len\fR and \fBdsc_isoc_pkt_status\fR fields were filled
by the driver) are returned, followed by the request's device payload data.
.sp
.LP
Applications should continuously check for and consume isochronous data. The
\fBugen\fR driver enables buffering of up to eight seconds of incoming data for
full-speed isochronous endpoint, one second of data for high-speed isochronous
endpoints who request one transaction per microframe and 1/3 of a second of
incoming data for high-speed high-bandwidth isochronous endpoints who request
three transactions per microframe. In case of buffer overflow, \fBugen\fR
discards the oldest data.
.sp
.LP
The isochronous-IN polling can only be stopped by a \fBclose\fR(2) associated
file descriptor. If applications want to change packet information, they must
first \fBclose\fR(2) the endpoint to stop the isochronous-IN polling, then
\fBopen\fR(2) the endpoint and \fBwrite\fR(2) new packets request.
.sp
.LP
The following example shows how to read an isochronous-IN endpoint:
.sp
.in +2
.nf
#include <sys/usb/clients/ugen/usb_ugen.h>
char *buf, *p;
ushort_t pktlen;
int pktcnt, i;
int len;
ugen_isoc_req_head_t *req;
ugen_isoc_pkt_descr_t *pktdesc;
char rdbuf[5000];
pktcnt = 4; /* 4 packets in this request */
len = sizeof(int) +
sizeof(ugen_isoc_pkt_descr_t) * pktcount;
buf = malloc(len);
if (!buf) {
/* Error recovery. */
}
req = (ugen_isoc_req_head_t *)buf;
req->req_isoc_pkts_count = pktcnt;
pktdesc = (ugen_isoc_pkt_descr_t *)
(req->req_isoc_pkt_descrs);
for (i = 0; i < pktcnt; i++) {
/*
* pktlen should not exceed xfer
* capability of an endpoint
*/
pktdesc[i].dsc_isoc_pkt_len = pktlen;
pktdesc[i].dsc_isoc_pkt_actual_len = 0;
pktdesc[i].dsc_isoc_pkt_status = 0;
}
/*
* write request info to driver and len must
* be exactly the sum of
* sizeof(int) + sizeof(ugen_isoc_pkt_descr_t) * pktcnt.
* Otherwise, an error is returned.
*/
if (write(fd, buf, len) < 0) {
/* Error recovery. */
}
/*
* Read length should be sum of all pkt descriptors
* length + payload data length of all pkts
* (sizeof(ugen_isoc_pkt_descr_t) + pktlen) * pktcnt
*/
if (read(fd, rdbuf, (sizeof(ugen_isoc_pkt_descr_t) +
pktlen) * pktcnt) < 0) {
/* Error recovery. */
}
pktdesc = (ugen_isoc_pkt_descr_t *) rdbuf;
/* points to payload beginning */
p = rdbuf + pktcnt * sizeof(ugen_isoc_pkt_descr_t);
for (i = 0; i < pktcnt; i++) {
printf("packet %d len = %d,"
" actual_len = %d, status = 0x%x\en",
i, pktdesc->dsc_isoc_pkt_len,
pktdesc->dsc_isoc_pkt_actual_len,
pktdesc->dsc_isoc_pkt_status);
/* Processing data */
/*
* next packet data payload, do NOT use
* dsc_isoc_pkt_actual_len
*/
p += pktdesc->dsc_isoc_pkt_len;
pktdesc++;
}
.fi
.in -2
.sp
.LP
For an isochronous-OUT endpoint, applications use the same packet descriptor
and request structures to write request information to the \fBugen\fR node.
Following the packet request head information is the packet payload data. Upon
successful return of \fBwrite\fR(2), applications can \fBread\fR(2) the same
\fBugen\fR file immediately to retrieve the individual packet transfer status
of the last request. If the application isn't concerned about the status, it
can omit it.
.sp
.LP
In the following example, an application transfers data on an isochronous-OUT
endpoint:
.sp
.in +2
.nf
#include <sys/usb/clients/ugen/usb_ugen.h>
char *buf, *p;
ushort_t i, pktlen;
int len, pktcnt;
ugen_isoc_req_head_t *req;
ugen_isoc_pkt_descr_t *pktdesc;
char rdbuf[4096];
pktcnt = 4;
/*
* set packet length to a proper value, don't
* exceed endpoint's capability
*/
pktlen = 1024;
len = sizeof(int) +
sizeof(ugen_isoc_pkt_descr_t) * pktcount;
len += pktlen * pktcnt;
buf = malloc(len);
if (!buf) {
/* Error recovery. */
}
req = (ugen_isoc_req_head_t *)buf;
req->req_isoc_pkts_count = pktcnt;
pktdesc =
(ugen_isoc_pkt_descr_t *)(req->req_isoc_pkt_descrs);
for (i = 0; i < pktcnt; i++) {
pktdesc[i].dsc_isoc_pkt_len = pktlen;
pktdesc[i].dsc_isoc_pkt_actual_len = 0;
pktdesc[i].dsc_isoc_pkt_status = 0;
}
/* moving to beginning of payload data */
p = buf + sizeof(int) + sizeof(*pktdesc) * pktcnt;
for (i = 0; i < pktcnt; i++) {
/* fill in the data buffer */
p += pktlen;
}
/*
* write packet request information and data to ugen driver
*
* len should be the exact value of sizeof(int) +
* sizeof(ugen_isoc_pkt_descr_t) * pktcnt + payload length
*/
if (write(fd, buf, len) < 0) {
/* Error recovery. */
}
/* read packet status */
if (read(fd, rdbuf, sizeof(*pktdesc) * pktcnt) < 0) {
/* Error recovery. */
} else {
/* Parse every packet's transfer status */
}
.fi
.in -2
.SH ERRORS
.sp
.LP
The following statuses are returned by endpoint status device logical names:
.sp
.ne 2
.na
\fBUSB_LC_STAT_NOERROR\fR
.ad
.sp .6
.RS 4n
No error.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_CRC\fR
.ad
.sp .6
.RS 4n
CRC error detected.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_BITSTUFFING\fR
.ad
.sp .6
.RS 4n
Bit stuffing error.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_DATA_TOGGLE_MM\fR
.ad
.sp .6
.RS 4n
Data toggle did not match.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_STALL\fR
.ad
.sp .6
.RS 4n
Endpoint returned stall.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_DEV_NOT_RESP\fR
.ad
.sp .6
.RS 4n
Device not responding.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_UNEXP_PID\fR
.ad
.sp .6
.RS 4n
Unexpected Packet Identifier (PID).
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_PID_CHECKFAILURE\fR
.ad
.sp .6
.RS 4n
Check bits on PID failed.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_DATA_OVERRUN\fR
.ad
.sp .6
.RS 4n
Data overrun.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_DATA_UNDERRUN\fR
.ad
.sp .6
.RS 4n
Data underrun.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_BUFFER_OVERRUN\fR
.ad
.sp .6
.RS 4n
Buffer overrun.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_BUFFER_UNDERRUN\fR
.ad
.sp .6
.RS 4n
Buffer underrun.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_TIMEOUT\fR
.ad
.sp .6
.RS 4n
Command timed out.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_NOT_ACCESSED\fR
.ad
.sp .6
.RS 4n
Not accessed by the hardware.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_UNSPECIFIED_ERR\fR
.ad
.sp .6
.RS 4n
Unspecified USBA or HCD error.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_NO_BANDWIDTH\fR
.ad
.sp .6
.RS 4n
No bandwidth available.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_HW_ERR\fR
.ad
.sp .6
.RS 4n
Host Controller h/w error.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_SUSPENDED\fR
.ad
.sp .6
.RS 4n
Device was suspended.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_DISCONNECTED\fR
.ad
.sp .6
.RS 4n
Device was disconnected.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_INTR_BUF_FULL\fR
.ad
.sp .6
.RS 4n
Polling was stopped as the interrupt-IN data buffer was full. Buffer is now
empty and polling has been resumed.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_INTERRUPTED\fR
.ad
.sp .6
.RS 4n
Request was interrupted.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_NO_RESOURCES\fR
.ad
.sp .6
.RS 4n
No resources available for request.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_INTR_POLLING_FAILED\fR
.ad
.sp .6
.RS 4n
Failed to restart polling.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_ISOC_POLLING_FAILED\fR
.ad
.sp .6
.RS 4n
Failed to start isochronous polling.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_ISOC_UNINITIALIZED\fR
.ad
.sp .6
.RS 4n
Isochronous packet information not initialized.
.RE
.sp
.ne 2
.na
\fBUSB_LC_STAT_ISOC_PKT_ERROR\fR
.ad
.sp .6
.RS 4n
All packets in this isochronous request have errors. The polling on this
isochronous-IN endpoint is suspended and can be resumed on next \fBread\fR(2).
.RE
.sp
.LP
The following system call \fBerrno\fR values are returned:
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 11n
An attempt was made to enable or disable "one transfer" mode while the
associated endpoint was open.
.RE
.sp
.ne 2
.na
\fB\fBEBUSY\fR\fR
.ad
.RS 11n
The endpoint has been opened and another open is attempted.
.RE
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 11n
An endpoint open was attempted with incorrect flags.
.RE
.sp
.ne 2
.na
\fB\fBENOTSUP\fR\fR
.ad
.RS 11n
Operation not supported.
.RE
.sp
.ne 2
.na
\fB\fBENXIO\fR\fR
.ad
.RS 11n
Device associated with the file descriptor does not exist.
.RE
.sp
.ne 2
.na
\fBENODEV\fR
.ad
.RS 11n
Device has been hot-removed or a suspend/resume happened before this command.
.RE
.sp
.ne 2
.na
\fBEIO\fR
.ad
.RS 11n
An I/O error occurred. Send a read on the endpoint status minor node to get the
exact error information.
.RE
.sp
.ne 2
.na
\fBEINTR\fR
.ad
.RS 11n
Interrupted system call.
.RE
.sp
.ne 2
.na
\fBENOMEM\fR
.ad
.RS 11n
No memory for the allocation of internal structures.
.RE
.SH FILES
.sp
.in +2
.nf
/kernel/drv/ugen 32 bit ELF kernel module (x86 platform only)
/kernel/drv/sparcv9/ugen 64 bit ELF kernel module
/dev/usb/<vid>.<pid>/<N>/cntrl0
/dev/usb/<vid>.<pid>/<N>/cntrl0stat
/dev/usb/<vid>.<pid>/<N>/if<interface#>
<in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/if<interface#>
<in|out|cntrl><endpoint#>stat
/dev/usb/<vid>.<pid>/<N>/if<interface#>.
<alternate><in|out|cntrl<endpoint#>
/dev/usb/<vid>.<pid>/<N>/if<interface#>.
<alternate><in|out|cntrl><endpoint#>stat
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>
<in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>
<in|out|cntrl<endpoint#stat>
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>.
<alternate><in|out|cntrl><endpoint#>
/dev/usb/<vid>.<pid>/<N>/cfg<value>if<interface#>.
<alternate><in|out|cntrl><endpoint#>stat
/dev/usb/<vid>.<pid>/<N>/devstat
/dev/usb/<vid>.<pid>/<N>/if<interface#>cntrl0
/dev/usb/<vid>.<pid>/<N>/if<interface#>cntrl0stat
.fi
.in -2
.sp
.LP
where \fIN\fR is an integer representing the instance number of this type of
device. (All logical device names for a single device share the same \fIN\fR.)
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
Architecture PCI-based SPARC
.TE
.SH SEE ALSO
.sp
.LP
\fBlibusb\fR(3LIB), \fBclose\fR(2), \fBpoll\fR(2), \fBread\fR(2),
\fBwrite\fR(2), \fBaioread\fR(3C), \fBaiowrite\fR(3C), \fBusba\fR(7D),
\fBusb_dev_descr\fR(9S).
.SH DIAGNOSTICS
.sp
.LP
In addition to being logged, the following messages may appear on the system
console. All messages are formatted in the following manner:
.sp
.in +2
.nf
Warning: <device path> (ugen<instance num>): Error Message...
.fi
.in -2
.sp
.sp
.ne 2
.na
\fBToo many minor nodes. \fR
.ad
.sp .6
.RS 4n
Device has too many minor nodes. Not all are available.
.RE
.sp
.ne 2
.na
\fBInstance number too high (<\fInumber\fR>).\fR
.ad
.sp .6
.RS 4n
Too many devices are using this driver.
.RE
.sp
.ne 2
.na
\fBCannot access <device>. Please reconnect.\fR
.ad
.sp .6
.RS 4n
This device has been disconnected because a device other than the original one
has been inserted. The driver informs you of this fact by displaying the name
of the original device.
.RE
.sp
.ne 2
.na
\fBDevice is not identical to the previous one on this port. Please disconnect
and reconnect.\fR
.ad
.sp .6
.RS 4n
Same condition as described above; however in this case, the driver is unable
to identify the original device with a name string.
.RE
.SH NOTES
.sp
.LP
\fBugen\fR returns \fB-1\fR for all commands and sets \fBerrno\fR to
\fBENODEV\fR when device has been hot-removed or resumed from a suspend. The
application must close and reopen all open minor nodes to reinstate successful
communication.
|