Newer
Older
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
From 856e2ae32fe39ba8116cc3870068b383199c2c73 Mon Sep 17 00:00:00 2001
From: Robert Nelson <robertcnelson@gmail.com>
Date: Wed, 17 Apr 2024 13:27:55 -0500
Subject: [PATCH] merge: to
https://github.com/linux-usb-gadgets/libusbgx/commit/a5bfa81017a9b2064bc449cf74f5f9d106445f62
Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
---
.gitignore | 16 +-
DoxygenLayout.xml | 1 -
LibUsbgxConfig.cmake.in | 24 +
Makefile.am | 4 +-
README | 5 +
configure.ac | 9 +-
examples/Makefile.am | 6 +-
examples/gadget-acm-ecm.c | 1 +
examples/gadget-import.c | 1 +
examples/gadget-ms.c | 3 +
examples/gadget-printer.c | 117 +
examples/gadget-uvc.c | 182 +
examples/gadget-vid-pid-remove.c | 24 +-
examples/show-gadgets.c | 2 +
examples/show-udcs.c | 1 +
include/usbg/function/ms.h | 36 +
include/usbg/function/net.h | 91 +-
include/usbg/function/printer.h | 56 +
include/usbg/function/uac2.h | 57 +
include/usbg/function/uvc.h | 156 +
include/usbg/usbg.h | 2 +
include/usbg/usbg_internal_libconfig.h | 1 +
libusbgx.pc.in | 2 +-
m4/.gitignore | 2 +
m4/libtool.m4 | 8001 ------------------------
m4/ltoptions.m4 | 384 --
m4/ltsugar.m4 | 123 -
m4/ltversion.m4 | 23 -
m4/lt~obsolete.m4 | 98 -
packaging/libusbgx.spec | 1 +
src/Makefile.am | 4 +-
src/function/ether.c | 3 +
src/function/hid.c | 4 +-
src/function/midi.c | 4 +-
src/function/ms.c | 1 +
src/function/printer.c | 34 +
src/function/uac2.c | 36 +
src/function/uvc.c | 1219 ++++
src/usbg.c | 7 +-
src/usbg_common.c | 2 +
tests/usbg-test.c | 27 +
41 files changed, 2112 insertions(+), 8658 deletions(-)
create mode 100644 LibUsbgxConfig.cmake.in
create mode 100644 examples/gadget-printer.c
create mode 100644 examples/gadget-uvc.c
create mode 100644 include/usbg/function/printer.h
create mode 100644 include/usbg/function/uvc.h
create mode 100644 m4/.gitignore
delete mode 100644 m4/libtool.m4
delete mode 100644 m4/ltoptions.m4
delete mode 100644 m4/ltsugar.m4
delete mode 100644 m4/ltversion.m4
delete mode 100644 m4/lt~obsolete.m4
create mode 100644 src/function/printer.c
create mode 100644 src/function/uvc.c
diff --git a/.gitignore b/.gitignore
index 7dfeaed..671c0a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,15 @@
/examples/*
!/examples/*.*
-/examples/.deps
-/examples/.libs
-/src/.deps
-/src/.libs
+/examples/.deps/
+/examples/.libs/
+/include/usbg/usbg_version.h
+/src/.deps/
+/src/.libs/
+/src/function/.deps/
+/src/function/.dirstamp
/tests/*
!/tests/*.*
-/tests/.deps
+/tests/.deps/
*.o
*.lo
*.la
@@ -26,4 +29,5 @@ Makefile.in
/missing
/install-sh
/doxygen.cfg
-/libusbg.pc
+/libusbgx.pc
+/LibUsbgxConfig.cmake
diff --git a/DoxygenLayout.xml b/DoxygenLayout.xml
index 5b60278..92949fd 100644
--- a/DoxygenLayout.xml
+++ b/DoxygenLayout.xml
@@ -18,7 +18,6 @@
<tab type="filelist" visible="yes" title="" intro=""/>
<tab type="globals" visible="yes" title="" intro=""/>
</tab>
- <tab type="dirs" visible="yes" title="" intro=""/>
<tab type="examples" visible="yes" title="" intro=""/>
</navindex>
diff --git a/LibUsbgxConfig.cmake.in b/LibUsbgxConfig.cmake.in
new file mode 100644
index 0000000..bbef363
--- /dev/null
+++ b/LibUsbgxConfig.cmake.in
@@ -0,0 +1,24 @@
+get_filename_component(LibUsbgx_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+include(CMakeFindDependencyMacro)
+
+# Compute the installation prefix relative to this file.
+get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
+get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
+get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
+get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
+if(_IMPORT_PREFIX STREQUAL "/")
+ set(_IMPORT_PREFIX "")
+endif()
+
+set(LibUsbgx_INCLUDE_DIRS "${_IMPORT_PREFIX}/include")
+
+if(NOT TARGET LibUsbgx::LibUsbgx)
+ add_library(LibUsbgx::LibUsbgx SHARED IMPORTED)
+ set_property(TARGET LibUsbgx::LibUsbgx APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+
+ set_target_properties(LibUsbgx::LibUsbgx PROPERTIES
+ IMPORTED_LOCATION "${_IMPORT_PREFIX}/lib/libusbgx.so"
+ INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include")
+endif()
+
+set(LibUsbgx_LIBRARIES LibUsbgx::LibUsbgx)
diff --git a/Makefile.am b/Makefile.am
index a3cc337..c12628b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,8 @@ EXTRA_DIST = doxygen.cfg
library_includedir=$(includedir)/usbg
library_include_HEADERS = include/usbg/usbg.h include/usbg/usbg_version.h
function_includedir=$(includedir)/usbg/function
-function_include_HEADERS = include/usbg/function/ffs.h include/usbg/function/loopback.h include/usbg/function/midi.h include/usbg/function/ms.h include/usbg/function/net.h include/usbg/function/phonet.h include/usbg/function/serial.h include/usbg/function/hid.h include/usbg/function/uac2.h
+function_include_HEADERS = include/usbg/function/ffs.h include/usbg/function/loopback.h include/usbg/function/midi.h include/usbg/function/ms.h include/usbg/function/net.h include/usbg/function/phonet.h include/usbg/function/serial.h include/usbg/function/hid.h include/usbg/function/uac2.h include/usbg/function/uvc.h include/usbg/function/printer.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libusbgx.pc
+cmakeconfigdir = $(libdir)/cmake/LibUsbgx
+cmakeconfig_DATA = LibUsbgxConfig.cmake
diff --git a/README b/README
index 08622a3..8f84e3e 100644
--- a/README
+++ b/README
@@ -12,8 +12,13 @@ See the Doxygen docs and examples for complete details on the
programming API and INSTALL for installation of the library and
examples.
+The library is licensed under the GNU LGPL-2.1 (or later) and
+the examples are licensed under the GNU GPL-2.0 (or later).
+
To run the examples:
+$ modprobe configfs
+$ modprobe libcomposite
$ mount -t configfs none /sys/kernel/config
$ gadget-acm-ecm
$ show-gadgets
diff --git a/configure.ac b/configure.ac
index 5a59b2b..3995556 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,18 +36,23 @@ AS_IF([test "x$with_libconfig" = xyes], [
AC_DEFINE(HAVE_LIBCONFIG_15, 1, [detected libconfig equal to or greater than 1.5]),
AC_DEFINE(HAVE_LIBCONFIG_15, 0, []))
])
+ libconfig_req="libconfig"
CFLAGS="$CFLAGS $LIBCONFIG_CFLAGS"
LIBS="$LIBS $LIBCONFIG_LIBS"
], [
+ libconfig_req=""
enable_gadget_schemes=no
])
+REQUIRES="$libconfig_req"
+
+AC_SUBST([REQUIRES])
+
AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$enable_examples" = xyes])
AS_IF([test "x$enable_tests" = xyes], [
PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.0.0],
AC_DEFINE(HAS_CMOCKA, 1, [detected cmocka]))
- AC_CONFIG_FILES([tests/Makefile])
])
AM_CONDITIONAL(BUILD_TESTS, [test "x$enable_tests" = xyes])
@@ -56,6 +61,6 @@ AS_IF([test "x$enable_gadget_schemes" = xyes],
AM_CONDITIONAL(TEST_GADGET_SCHEMES, [test "x$enable_gadget_schemes" != xno])
LT_INIT
-AC_CONFIG_FILES([Makefile src/Makefile examples/Makefile include/usbg/usbg_version.h libusbgx.pc doxygen.cfg])
+AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile examples/Makefile include/usbg/usbg_version.h libusbgx.pc doxygen.cfg LibUsbgxConfig.cmake])
DX_INIT_DOXYGEN([$PACKAGE_NAME],[doxygen.cfg])
AC_OUTPUT
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 9934321..a5961eb 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,11 +1,13 @@
-bin_PROGRAMS = show-gadgets gadget-acm-ecm gadget-vid-pid-remove gadget-ffs gadget-export gadget-import show-udcs gadget-ms gadget-midi gadget-hid gadget-rndis-os-desc gadget-uac2
+bin_PROGRAMS = show-gadgets gadget-acm-ecm gadget-vid-pid-remove gadget-uvc gadget-ffs gadget-export gadget-import show-udcs gadget-ms gadget-midi gadget-hid gadget-rndis-os-desc gadget-uac2 gadget-printer
gadget_acm_ecm_SOURCES = gadget-acm-ecm.c
+gadget_uvc_SOURCES = gadget-uvc.c
show_gadgets_SOURCES = show-gadgets.c
gadget_vid_pid_remove_SOURCES = gadget-vid-pid-remove.c
gadget_ffs_SOURCES = gadget-ffs.c
gadget_export_SOURCE = gadget-export.c
gadget_import_SOURCE = gadget-import.c
gadget_rndis_os_desc_SOURCES = gadget-rndis-os-desc.c
+gadget_printer_SOURCE = gadget_printer.c
show_udcs_SOURCE = show-udcs.c
-AM_CPPFLAGS=-I$(top_srcdir)/include/
+AM_CPPFLAGS=-I$(top_srcdir)/include/ -I$(top_builddir)/include/usbg
AM_LDFLAGS=-L../src/ -lusbgx
diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 1c5e2ca..29360da 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <stdio.h>
+#include <sys/sysmacros.h>
#include <linux/usb/ch9.h>
#include <usbg/usbg.h>
diff --git a/examples/gadget-import.c b/examples/gadget-import.c
index e684fdb..63df449 100644
--- a/examples/gadget-import.c
+++ b/examples/gadget-import.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
+#include <sys/sysmacros.h>
#include <usbg/usbg.h>
int main(int argc, char **argv)
diff --git a/examples/gadget-ms.c b/examples/gadget-ms.c
index 478c370..09fd212 100644
--- a/examples/gadget-ms.c
+++ b/examples/gadget-ms.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stdio.h>
+#include <sys/sysmacros.h>
#include <linux/usb/ch9.h>
#include <usbg/usbg.h>
#include <usbg/function/ms.h>
@@ -64,6 +65,7 @@ int main(int argc, char **argv)
.nofua = 0,
.removable = 1,
.file = "",
+ .inquiry_string = "Empty"
}, {
.id = -1, /* allows to place in any position */
.cdrom = 0,
@@ -71,6 +73,7 @@ int main(int argc, char **argv)
.nofua = 0,
.removable = 1,
.file = argv[1],
+ .inquiry_string = "Non-empty"
}
};
diff --git a/examples/gadget-printer.c b/examples/gadget-printer.c
new file mode 100644
index 0000000..4ba0b49
--- /dev/null
+++ b/examples/gadget-printer.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2021
+ *
+ * Aristo Chen <wmchen.aristo@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <linux/usb/ch9.h>
+#include <usbg/usbg.h>
+#include <usbg/function/printer.h>
+
+#define VENDOR 0x1d6b
+#define PRODUCT 0x0104
+
+int main(void)
+{
+ usbg_state *s;
+ usbg_gadget *g;
+ usbg_config *c;
+ usbg_function *f_printer;
+ int ret = -EINVAL;
+ int usbg_ret;
+
+ struct usbg_gadget_attrs g_attrs = {
+ .bcdUSB = 0x0200,
+ .bDeviceClass = USB_CLASS_PER_INTERFACE,
+ .bDeviceSubClass = 0x00,
+ .bDeviceProtocol = 0x00,
+ .bMaxPacketSize0 = 64, /* Max allowed ep0 packet size */
+ .idVendor = VENDOR,
+ .idProduct = PRODUCT,
+ .bcdDevice = 0x0001, /* Verson of device */
+ };
+
+ struct usbg_gadget_strs g_strs = {
+ .serial = "0123456789", /* Serial number */
+ .manufacturer = "Foo Inc.", /* Manufacturer */
+ .product = "Bar Gadget" /* Product string */
+ };
+
+ struct usbg_config_strs c_strs = {
+ .configuration = "PRINTER"};
+
+ usbg_ret = usbg_init("/sys/kernel/config", &s);
+ if (usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error on USB gadget init\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out1;
+ }
+
+ usbg_ret = usbg_create_gadget(s, "g1", &g_attrs, &g_strs, &g);
+ if (usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error on create gadget\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ usbg_ret = usbg_create_function(g, USBG_F_PRINTER, "usb0", NULL, &f_printer);
+ if (usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error creating printer function\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ /* NULL can be passed to use kernel defaults */
+ usbg_ret = usbg_create_config(g, 1, "The only one", NULL, &c_strs, &c);
+ if (usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error creating config\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ usbg_ret = usbg_add_config_function(c, "printer.1", f_printer);
+ if (usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error adding function\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ usbg_ret = usbg_enable_gadget(g, DEFAULT_UDC);
+ if (usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error enabling gadget\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ ret = 0;
+
+out2:
+ usbg_cleanup(s);
+
+out1:
+ return ret;
+}
diff --git a/examples/gadget-uvc.c b/examples/gadget-uvc.c
new file mode 100644
index 0000000..e61a505
--- /dev/null
+++ b/examples/gadget-uvc.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2021 Pengutronix
+ *
+ * Michael Grzeschik <mgr@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <sys/sysmacros.h>
+#include <linux/usb/ch9.h>
+#include <usbg/usbg.h>
+#include <usbg/function/uvc.h>
+
+/**
+ * @file gadget-uvc.c
+ * @example gadget-uvc.c
+ * This is an example of how to create an UVC gadget device.
+ */
+
+#define VENDOR 0x1d6b
+#define PRODUCT 0x0104
+
+int main(void)
+{
+ usbg_state *s;
+ usbg_gadget *g;
+ usbg_config *c;
+ usbg_function *f_uvc;
+ int ret = -EINVAL;
+ int usbg_ret;
+
+ struct usbg_gadget_attrs g_attrs = {
+ .bcdUSB = 0x0200,
+ .bDeviceClass = USB_CLASS_PER_INTERFACE,
+ .bDeviceSubClass = 0x00,
+ .bDeviceProtocol = 0x00,
+ .bMaxPacketSize0 = 64, /* Max allowed ep0 packet size */
+ .idVendor = VENDOR,
+ .idProduct = PRODUCT,
+ .bcdDevice = 0x0001, /* Verson of device */
+ };
+
+ struct usbg_gadget_strs g_strs = {
+ .serial = "0123456789", /* Serial number */
+ .manufacturer = "Foo Inc.", /* Manufacturer */
+ .product = "Bar Gadget" /* Product string */
+ };
+
+ struct usbg_config_strs c_strs = {
+ .configuration = "UVC"
+ };
+
+ struct usbg_f_uvc_frame_attrs uvc_frame_attrs_array[] = {
+ {
+ .bFrameIndex = 1,
+ .dwFrameInterval = 2000000,
+ .wHeight = 480,
+ .wWidth = 640,
+ }, {
+ .bFrameIndex = 2,
+ .dwFrameInterval = 2000000,
+ .wHeight = 1080,
+ .wWidth = 1920,
+ }, {
+ .bFrameIndex = 3,
+ .dwFrameInterval = 333333,
+ .wHeight = 1080,
+ .wWidth = 1920,
+ }, {
+ .bFrameIndex = 4,
+ .dwFrameInterval = 333333,
+ .wHeight = 2160,
+ .wWidth = 3840,
+ }
+ };
+
+ struct usbg_f_uvc_frame_attrs *uvc_frame_mjpeg_attrs[] = {
+ &uvc_frame_attrs_array[0],
+ &uvc_frame_attrs_array[1],
+ &uvc_frame_attrs_array[2],
+ &uvc_frame_attrs_array[3],
+ NULL,
+ };
+
+ struct usbg_f_uvc_frame_attrs *uvc_frame_uncompressed_attrs[] = {
+ &uvc_frame_attrs_array[0],
+ &uvc_frame_attrs_array[1],
+ &uvc_frame_attrs_array[2],
+ &uvc_frame_attrs_array[3],
+ NULL,
+ };
+
+ struct usbg_f_uvc_format_attrs uvc_format_attrs_array[] = {
+ {
+ .frames = uvc_frame_mjpeg_attrs,
+ .format = "mjpeg/m",
+ .bDefaultFrameIndex = 3,
+ }, {
+ .frames = uvc_frame_uncompressed_attrs,
+ .format = "uncompressed/u",
+ .bDefaultFrameIndex = 2,
+ }
+ };
+
+ struct usbg_f_uvc_format_attrs *uvc_format_attrs[] = {
+ &uvc_format_attrs_array[0],
+ &uvc_format_attrs_array[1],
+ NULL,
+ };
+
+ struct usbg_f_uvc_attrs uvc_attrs = {
+ .formats = uvc_format_attrs,
+ };
+
+ usbg_ret = usbg_init("/sys/kernel/config", &s);
+ if (usbg_ret != USBG_SUCCESS) {
+ fprintf(stderr, "Error on USB gadget init\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out1;
+ }
+
+ usbg_ret = usbg_create_gadget(s, "g1", &g_attrs, &g_strs, &g);
+ if (usbg_ret != USBG_SUCCESS) {
+ fprintf(stderr, "Error on create gadget\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ usbg_ret = usbg_create_function(g, USBG_F_UVC, "uvc", &uvc_attrs, &f_uvc);
+ if(usbg_ret != USBG_SUCCESS)
+ {
+ fprintf(stderr, "Error creating uvc function\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ /* NULL can be passed to use kernel defaults */
+ usbg_ret = usbg_create_config(g, 1, "The only one", NULL, &c_strs, &c);
+ if (usbg_ret != USBG_SUCCESS) {
+ fprintf(stderr, "Error creating config\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ usbg_ret = usbg_add_config_function(c, "uvc.cam", f_uvc);
+ if (usbg_ret != USBG_SUCCESS) {
+ fprintf(stderr, "Error adding acm.GS0\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ usbg_ret = usbg_enable_gadget(g, DEFAULT_UDC);
+ if (usbg_ret != USBG_SUCCESS) {
+ fprintf(stderr, "Error enabling gadget\n");
+ fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+ usbg_strerror(usbg_ret));
+ goto out2;
+ }
+
+ ret = 0;
+
+out2:
+ usbg_cleanup(s);
+
+out1:
+ return ret;
+}
diff --git a/examples/gadget-vid-pid-remove.c b/examples/gadget-vid-pid-remove.c
index f6b950b..dd3879b 100644
--- a/examples/gadget-vid-pid-remove.c
+++ b/examples/gadget-vid-pid-remove.c
@@ -23,6 +23,8 @@
#include <errno.h>
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
#include <usbg/usbg.h>
#define VENDOR 0x1d6b
@@ -60,13 +62,29 @@ out:
return usbg_ret;
}
-int main(void)
+int main(int argc, char **argv)
{
int usbg_ret;
int ret = -EINVAL;
usbg_state *s;
usbg_gadget *g;
struct usbg_gadget_attrs g_attrs;
+ char *cp;
+ int vendor = VENDOR, product = PRODUCT;
+
+ if (argc >= 2) {
+ cp = strchr(argv[1], ':');
+ if (!cp) {
+ ret = -EINVAL;
+ fprintf(stderr, "Usage: gadget-vid-pid-remove vid:pid\n");
+ goto out1;
+ }
+ *cp++ = 0;
+ if (&argv[1])
+ vendor = strtoul(argv[1], NULL, 16);
+ if (*cp)
+ product = strtoul(cp, NULL, 16);
+ }
usbg_ret = usbg_init("/sys/kernel/config", &s);
if (usbg_ret != USBG_SUCCESS) {
@@ -88,7 +106,7 @@ int main(void)
}
/* Compare attrs with given values and remove if suitable */
- if (g_attrs.idVendor == VENDOR && g_attrs.idProduct == PRODUCT) {
+ if (g_attrs.idVendor == vendor && g_attrs.idProduct == product) {
usbg_gadget *g_next = usbg_get_next_gadget(g);
usbg_ret = remove_gadget(g);
@@ -101,6 +119,8 @@ int main(void)
}
}
+ ret = 0;
+
out2:
usbg_cleanup(s);
out1:
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 707d448..0f2058b 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -21,6 +21,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <sys/sysmacros.h>
#include <netinet/ether.h>
#include <usbg/usbg.h>
#include <usbg/function/ms.h>
@@ -197,6 +198,7 @@ void show_function(usbg_function *f)
fprintf(stdout, " nofua\t\t%d\n", attrs->luns[i]->nofua);
fprintf(stdout, " removable\t\t%d\n", attrs->luns[i]->removable);
fprintf(stdout, " file\t\t%s\n", attrs->luns[i]->file);
+ fprintf(stdout, " inquiry_string\t\t%s\n", attrs->luns[i]->inquiry_string);
}
break;
}
diff --git a/examples/show-udcs.c b/examples/show-udcs.c
index 66e950f..2f5cc45 100644
--- a/examples/show-udcs.c
+++ b/examples/show-udcs.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <stdio.h>
+#include <sys/sysmacros.h>
#include <usbg/usbg.h>
int main(void)
diff --git a/include/usbg/function/ms.h b/include/usbg/function/ms.h
index 780464c..0715d38 100644
--- a/include/usbg/function/ms.h
+++ b/include/usbg/function/ms.h
@@ -30,6 +30,7 @@ struct usbg_f_ms_lun_attrs {
bool nofua;
bool removable;
const char *file;
+ const char *inquiry_string;
};
struct usbg_f_ms_attrs {
@@ -45,6 +46,7 @@ enum usbg_f_ms_lun_attr {
USBG_F_MS_LUN_NOFUA,
USBG_F_MS_LUN_REMOVABLE,
USBG_F_MS_LUN_FILE,
+ USBG_F_MS_LUN_INQUIRY_STRING,
USBG_F_MS_LUN_ATTR_MAX
};
@@ -54,6 +56,7 @@ union usbg_f_ms_lun_attr_val {
bool nofua;
bool removable;
const char *file;
+ const char *inquiry_string;
};
#define USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(WHAT) \
@@ -132,6 +135,8 @@ static inline void usbg_f_ms_cleanup_lun_attrs(struct usbg_f_ms_lun_attrs *lattr
if (lattrs) {
free((char *)lattrs->file);
lattrs->file = NULL;
+ free((char *)lattrs->inquiry_string);
+ lattrs->inquiry_string = NULL;
}
}
@@ -317,6 +322,37 @@ static inline int usbg_f_ms_set_lun_file(usbg_f_ms *mf, int lun_id,
USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(file));
}
+/**
+ * @brief Get the inquiry string of LUN which is used as name in SCSI inquiry
+ * by this LUN into newly allocated storage
+ * @param[in] mf Pointer to ms function
+ * @param[in] lun_id ID of lun
+ * @param[out] inquiry_string Newly allocated string name of LUN used in SCSI
+ * inquiry
+ * @return 0 on success usbg_error if error occurred.
+ * @note returned inquiry_string should be free() by caller
+ */
+static inline int usbg_f_ms_get_lun_inquiry_string(usbg_f_ms *mf, int lun_id,
+ char **inquiry_string)
+{
+ return usbg_f_ms_get_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_INQUIRY_STRING,
+ (union usbg_f_ms_lun_attr_val *)inquiry_string);
+}
+
+/**
+ * @brief Set the inquiry string which is used as name in SCSI inquiry by this LUN
+ * @param[in] mf Pointer to ms function
+ * @param[in] lun_id ID of lun
+ * @param[in] inquiry_string Name of LUN which used in SCSI inquiry
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_ms_set_lun_inquiry_string(usbg_f_ms *mf, int lun_id,
+ const char *inquiry_string)
+{
+ return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_INQUIRY_STRING,
+ USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(inquiry_string));
+}
+
/**
* @brief Get attributes of given ms function
* @param[in] mf Pointer to ms function
diff --git a/include/usbg/function/net.h b/include/usbg/function/net.h
index 646736b..b0409f1 100644
--- a/include/usbg/function/net.h
+++ b/include/usbg/function/net.h
@@ -29,6 +29,9 @@ struct usbg_f_net_attrs {
struct ether_addr host_addr;
const char *ifname;
int qmult;
+ unsigned int class_;
+ unsigned int subclass;
+ unsigned int protocol;
};
enum usbg_f_net_attr {
@@ -37,6 +40,9 @@ enum usbg_f_net_attr {
USBG_F_NET_HOST_ADDR,
USBG_F_NET_IFNAME,
USBG_F_NET_QMULT,
+ USBG_F_NET_CLASS,
+ USBG_F_NET_SUBCLASS,
+ USBG_F_NET_PROTOCOL,
USBG_F_NET_ATTR_MAX
};
@@ -45,6 +51,9 @@ union usbg_f_net_attr_val {
struct ether_addr host_addr;
const char *ifname;
int qmult;
+ unsigned int class_;
+ unsigned int subclass;
+ unsigned int protocol;
};
#define USBG_F_NET_ETHER_ADDR_TO_ATTR_VAL(WHAT) \
@@ -127,8 +136,8 @@ int usbg_f_net_set_attr_val(usbg_f_net *nf, enum usbg_f_net_attr attr,
static inline int usbg_f_net_get_dev_addr(usbg_f_net *nf,
struct ether_addr *addr)
{
- return usbg_f_net_get_attr_val(nf, USBG_F_NET_DEV_ADDR,
- (union usbg_f_net_attr_val *)addr);
+ union usbg_f_net_attr_val val = { .dev_addr = *addr, };
+ return usbg_f_net_get_attr_val(nf, USBG_F_NET_DEV_ADDR, &val);
}
/**
@@ -153,12 +162,12 @@ static inline int usbg_f_net_set_dev_addr(usbg_f_net *nf,
static inline int usbg_f_net_get_host_addr(usbg_f_net *nf,
struct ether_addr *addr)
{
- return usbg_f_net_get_attr_val(nf, USBG_F_NET_HOST_ADDR,
- (union usbg_f_net_attr_val *)addr);
+ union usbg_f_net_attr_val val = { .host_addr = *addr, };
+ return usbg_f_net_get_attr_val(nf, USBG_F_NET_HOST_ADDR, &val);
}
/**
- * @brief Set the value of device side MAC address
+ * @brief Set the value of host side MAC address
* @param[in] nf Pointer to net function
* @param[in] val Value of attribute which should be set
* @return 0 on success usbg_error if error occurred.
@@ -221,6 +230,78 @@ static inline int usbg_f_net_set_qmult(usbg_f_net *nf, int qmult)
USBG_F_NET_INT_TO_ATTR_VAL(qmult));
}
+/**
+ * @brief Get the value of usb function class
+ * @param[in] nf Pointer to net function
+ * @param[out] class_ Current class identification
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_net_get_class(usbg_f_net *nf, unsigned int *class_)
+{
+ return usbg_f_net_get_attr_val(nf, USBG_F_NET_CLASS,
+ (union usbg_f_net_attr_val *)class_);
+}
+
+/**
+ * @brief Set the value of usb function class
+ * @param[in] nf Pointer to net function
+ * @param[in] class_ Class identification
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_net_set_class(usbg_f_net *nf, unsigned int class_)
+{
+ return usbg_f_net_set_attr_val(nf, USBG_F_NET_CLASS,
+ USBG_F_NET_INT_TO_ATTR_VAL(class_));
+}
+
+/**
+ * @brief Get the value of usb function subclass
+ * @param[in] nf Pointer to net function
+ * @param[out] subclass Current subclass identification
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_net_get_subclass(usbg_f_net *nf, int *subclass)
+{
+ return usbg_f_net_get_attr_val(nf, USBG_F_NET_SUBCLASS,
+ (union usbg_f_net_attr_val *)subclass);
+}
+
+/**
+ * @brief Set the value of usb function subclass
+ * @param[in] nf Pointer to net function
+ * @param[in] subclass Subclass identification
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_net_set_subclass(usbg_f_net *nf, unsigned int subclass)
+{
+ return usbg_f_net_set_attr_val(nf, USBG_F_NET_SUBCLASS,
+ USBG_F_NET_INT_TO_ATTR_VAL(subclass));
+}
+
+/**
+ * @brief Get the value of usb function protocol
+ * @param[in] nf Pointer to net function
+ * @param[out] protocol Current protocol identification
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_net_get_protocol(usbg_f_net *nf, int *protocol)
+{
+ return usbg_f_net_get_attr_val(nf, USBG_F_NET_PROTOCOL,
+ (union usbg_f_net_attr_val *)protocol);
+}
+
+/**
+ * @brief Set the value of usb function protocol
+ * @param[in] nf Pointer to net function
+ * @param[in] protocol protocol identification
+ * @return 0 on success usbg_error if error occurred.
+ */
+static inline int usbg_f_net_set_protocol(usbg_f_net *nf, unsigned int protocol)
+{
+ return usbg_f_net_set_attr_val(nf, USBG_F_NET_PROTOCOL,
+ USBG_F_NET_INT_TO_ATTR_VAL(protocol));
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/include/usbg/function/printer.h b/include/usbg/function/printer.h
new file mode 100644
index 0000000..b556f39
--- /dev/null
+++ b/include/usbg/function/printer.h
@@ -0,0 +1,56 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+
+#ifndef USBG_FUNCTION_PRINTER__
+#define USBG_FUNCTION_PRINTER__
+
+#include <usbg/usbg.h>
+
+#include <malloc.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+struct usbg_f_printer;
+typedef struct usbg_f_printer usbg_f_printer;
+
+struct usbg_f_printer_attrs {
+ const char *pnp_string;
+ int q_len;
+};
+
+enum usbg_f_printer_attr {
+ USBG_F_PRINTER_ATTR_MIN = 0,
+ USBG_F_PRINTER_PNP_STRING = USBG_F_PRINTER_ATTR_MIN,
+ USBG_F_PRINTER_Q_LEN,
+ USBG_F_PRINTER_ATTR_MAX
+};
+
+union usbg_f_printer_attr_val {
+ const char *pnp_string;
+ int q_len;
+};
+
+#define USBG_F_PRINTER_ETHER_ADDR_TO_ATTR_VAL(WHAT) \
+ USBG_TO_UNION(usbg_f_printer_attr_val, dev_addr, WHAT)
+
+#define USBG_F_PRINTER_INT_TO_ATTR_VAL(WHAT) \
+ USBG_TO_UNION(usbg_f_printer_attr_val, qmult, WHAT)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* USBG_FUNCTION_PRINTER__ */
diff --git a/include/usbg/function/uac2.h b/include/usbg/function/uac2.h
index c1bbb14..6fc4d24 100644
--- a/include/usbg/function/uac2.h
+++ b/include/usbg/function/uac2.h
@@ -31,6 +31,26 @@ struct usbg_f_uac2_attrs {
int p_chmask;
int p_srate;
int p_ssize;
+ unsigned char p_hs_bint;
+ unsigned char c_hs_bint;
+
+ const char * c_sync;
+ unsigned int req_number;
+ unsigned int fb_max;
+
+ bool p_mute_present;
+ bool p_volume_present;
+ short p_volume_min;
+ short p_volume_max;
+ short p_volume_res;
+
+ bool c_mute_present;
+ bool c_volume_present;
+ short c_volume_min;
+ short c_volume_max;
+ short c_volume_res;
+
+ const char *function_name;
};
enum usbg_f_uac2_attr {
@@ -41,6 +61,22 @@ enum usbg_f_uac2_attr {
USBG_F_UAC2_P_CHMASK,
USBG_F_UAC2_P_SRATE,
USBG_F_UAC2_P_SSIZE,
+ USBG_F_UAC2_P_HS_BINT,
+ USBG_F_UAC2_C_HS_BINT,
+ USBG_F_UAC2_C_SYNC,
+ USBG_F_UAC2_REQ_NUMBER,