libusbgx-0.3.0
Loading...
Searching...
No Matches
usbg.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Linaro Limited
3 *
4 * Matt Porter <mporter@linaro.org>
5 *
6 * Copyright (C) 2013 - 2015 Samsung Electronics
7 *
8 * Krzysztof Opasiak <k.opasiak@samsung.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 */
20
21#ifndef __USBG_H__
22#define __USBG_H__
23
24#include <dirent.h>
25#include <sys/queue.h>
26#include <netinet/ether.h>
27#include <stdint.h>
28#include <limits.h>
29#include <stdbool.h>
30#include <stdio.h> /* For FILE * */
31#include <malloc.h>
32
33#include "usbg_version.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
50#define DEFAULT_UDC NULL
51#define LANG_US_ENG 0x0409
52#define DEFAULT_CONFIG_LABEL "config"
53
54#define GUID_BIN_LENGTH 16
55#define GUID_CHAR_LENGTH 36 /* 32 bytes + 4 dashes */
56
57/* This one has to be at least 18 bytes to hold network address */
58#define USBG_MAX_STR_LENGTH 256
59#define USBG_MAX_NAME_LENGTH 40
60/* Dev name for ffs is a part of function name, we subtract 4 char for "ffs." */
61#define USBG_MAX_DEV_LENGTH (USBG_MAX_NAME_LENGTH - 4)
62
63#define USBG_TO_UNION(UNAME, FIELD, WHAT) \
64 ((union UNAME){ .FIELD = WHAT, })
65
71#define USBG_RM_RECURSE 1
72
73/*
74 * Internal structures
75 */
76struct usbg_state;
77struct usbg_gadget;
78struct usbg_config;
79struct usbg_function;
80struct usbg_binding;
81struct usbg_udc;
82
86typedef struct usbg_state usbg_state;
87
91typedef struct usbg_gadget usbg_gadget;
92
96typedef struct usbg_config usbg_config;
97
102
107
111typedef struct usbg_udc usbg_udc;
112
118typedef enum {
119 USBG_GADGET_ATTR_MIN = 0,
120 USBG_BCD_USB = USBG_GADGET_ATTR_MIN,
121 USBG_B_DEVICE_CLASS,
122 USBG_B_DEVICE_SUB_CLASS,
123 USBG_B_DEVICE_PROTOCOL,
124 USBG_B_MAX_PACKET_SIZE_0,
125 USBG_ID_VENDOR,
126 USBG_ID_PRODUCT,
127 USBG_BCD_DEVICE,
128 USBG_GADGET_ATTR_MAX,
130
135{
136 uint16_t bcdUSB;
137 uint8_t bDeviceClass;
138 uint8_t bDeviceSubClass;
139 uint8_t bDeviceProtocol;
140 uint8_t bMaxPacketSize0;
141 uint16_t idVendor;
142 uint16_t idProduct;
143 uint16_t bcdDevice;
144};
145
146typedef enum {
147 USBG_GADGET_STR_MIN = 0,
148 USBG_STR_MANUFACTURER = USBG_GADGET_STR_MIN,
149 USBG_STR_PRODUCT,
150 USBG_STR_SERIAL_NUMBER,
151 USBG_GADGET_STR_MAX,
152} usbg_gadget_str;
153
158{
159 char *manufacturer;
160 char *product;
161 char *serial;
162};
163
168{
169 bool use;
170 uint8_t b_vendor_code;
171 char *qw_sign;
172};
173
178typedef enum {
179 USBG_GADGET_OS_DESC_MIN = 0,
180 OS_DESC_USE = USBG_GADGET_OS_DESC_MIN,
181 OS_DESC_B_VENDOR_CODE,
182 OS_DESC_QW_SIGN,
183 USBG_GADGET_OS_DESC_MAX,
185
190{
191 uint8_t bmAttributes;
192 uint8_t bMaxPower;
193};
194
199{
200 char *configuration;
201};
202
207typedef enum
208{
209 USBG_FUNCTION_TYPE_MIN = 0,
210 USBG_F_SERIAL = USBG_FUNCTION_TYPE_MIN,
211 USBG_F_ACM,
212 USBG_F_OBEX,
213 USBG_F_ECM,
214 USBG_F_SUBSET,
215 USBG_F_NCM,
216 USBG_F_EEM,
217 USBG_F_RNDIS,
218 USBG_F_PHONET,
219 USBG_F_FFS,
220 USBG_F_MASS_STORAGE,
221 USBG_F_MIDI,
222 USBG_F_LOOPBACK,
223 USBG_F_HID,
224 USBG_F_UAC2,
225 USBG_F_UVC,
226 USBG_F_PRINTER,
227 USBG_F_9PFS,
228 USBG_FUNCTION_TYPE_MAX,
230
235{
236 char *compatible_id;
237 char *sub_compatible_id;
238};
239
240/* Error codes */
241
246typedef enum {
247 USBG_SUCCESS = 0,
248 USBG_ERROR_NO_MEM = -1,
249 USBG_ERROR_NO_ACCESS = -2,
250 USBG_ERROR_INVALID_PARAM = -3,
251 USBG_ERROR_NOT_FOUND = -4,
252 USBG_ERROR_IO = -5,
253 USBG_ERROR_EXIST = -6,
254 USBG_ERROR_NO_DEV = -7,
255 USBG_ERROR_BUSY = -8,
256 USBG_ERROR_NOT_SUPPORTED = -9,
257 USBG_ERROR_PATH_TOO_LONG = -10,
258 USBG_ERROR_INVALID_FORMAT = -11,
259 USBG_ERROR_MISSING_TAG = -12,
260 USBG_ERROR_INVALID_TYPE = -13,
261 USBG_ERROR_INVALID_VALUE = -14,
262 USBG_ERROR_NOT_EMPTY = -15,
263 USBG_ERROR_OTHER_ERROR = -99
264} usbg_error;
265
271extern const char *usbg_error_name(usbg_error e);
272
278extern const char *usbg_strerror(usbg_error e);
279
280/* Library init and cleanup */
281
288extern int usbg_init(const char *configfs_path, usbg_state **state);
289
294extern void usbg_cleanup(usbg_state *s);
295
304extern const char *usbg_get_configfs_path(usbg_state *s);
305
315extern int usbg_get_configfs_path_s(usbg_state *s, char *buf, int len);
316
317/* USB gadget queries */
318
325extern usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name);
326
335 usbg_function_type type, const char *instance);
336
347extern usbg_config *usbg_get_config(usbg_gadget *g, int id, const char *label);
348
355extern usbg_udc *usbg_get_udc(usbg_state *s, const char *name);
356
357/* USB gadget/config/function/binding removal */
358
365extern int usbg_rm_binding(usbg_binding *b);
366
374extern int usbg_rm_config(usbg_config *c, int opts);
375
383extern int usbg_rm_function(usbg_function *f, int opts);
384
392extern int usbg_rm_gadget(usbg_gadget *g, int opts);
393
400extern int usbg_rm_config_strs(usbg_config *c, int lang);
401
408extern int usbg_rm_gadget_strs(usbg_gadget *g, int lang);
409
410/* USB gadget allocation and configuration */
411
421extern int usbg_create_gadget_vid_pid(usbg_state *s, const char *name,
422 uint16_t idVendor, uint16_t idProduct, usbg_gadget **g);
423
435extern int usbg_create_gadget(usbg_state *s, const char *name,
436 const struct usbg_gadget_attrs *g_attrs,
437 const struct usbg_gadget_strs *g_strs,
438 usbg_gadget **g);
439
446extern const char *usbg_get_gadget_attr_str(usbg_gadget_attr attr);
447
453extern int usbg_lookup_gadget_attr(const char *name);
454
460extern int usbg_lookup_gadget_str(const char *name);
461
467extern const char *usbg_get_gadget_str_name(usbg_gadget_str str);
468
475
485extern int usbg_set_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr, int val);
486
497
505 const struct usbg_gadget_attrs *g_attrs);
506
514 struct usbg_gadget_attrs *g_attrs);
515
524extern const char *usbg_get_gadget_name(usbg_gadget *g);
525
535extern int usbg_get_gadget_name_s(usbg_gadget *g, char *buf, int len);
536
543extern int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
544
551extern int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
552
560 uint8_t bDeviceClass);
561
569 uint8_t bDeviceProtocol);
570
578 uint8_t bDeviceSubClass);
579
587 uint8_t bMaxPacketSize0);
588
596 uint16_t bcdDevice);
597
604extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
605
613extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
614 struct usbg_gadget_strs *g_strs);
615
622extern int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs);
623
630static inline void usbg_free_gadget_strs(struct usbg_gadget_strs *g_strs)
631{
632 if (!g_strs)
633 return;
634
635 free(g_strs->manufacturer);
636 free(g_strs->product);
637 free(g_strs->serial);
638}
639
647extern int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang,
648 const char *val);
649
657extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
658 const struct usbg_gadget_strs *g_strs);
659
667extern int usbg_set_gadget_serial_number(usbg_gadget *g, int lang,
668 const char *ser);
669
677extern int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang,
678 const char *mnf);
679
687extern int usbg_set_gadget_product(usbg_gadget *g, int lang,
688 const char *prd);
689
698 struct usbg_gadget_os_descs *g_os_descs);
699
706static inline void usbg_free_gadget_os_desc(
707 struct usbg_gadget_os_descs *g_os_desc)
708{
709 if (!g_os_desc)
710 return;
711
712 free(g_os_desc->qw_sign);
713}
714
723 const struct usbg_gadget_os_descs *g_os_descs);
724
725/* USB function allocation and configuration */
726
739 const char *instance, void *f_attrs, usbg_function **f);
740
749extern const char *usbg_get_function_instance(usbg_function *f);
750
760extern int usbg_get_function_instance_s(usbg_function *f, char *buf, int len);
761
767extern const char *usbg_get_function_type_str(usbg_function_type type);
768
774extern int usbg_lookup_function_type(const char *name);
775
784extern void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs);
785
793
804extern int usbg_get_function_attrs(usbg_function *f, void *f_attrs);
805
812extern int usbg_set_function_attrs(usbg_function *f, void *f_attrs);
813
821extern int usbg_get_interf_os_desc(usbg_function *f, const char *iname,
822 struct usbg_function_os_desc *f_os_desc);
823
830static inline void usbg_free_interf_os_desc(
831 struct usbg_function_os_desc *f_os_desc)
832{
833 if (!f_os_desc)
834 return;
835
836 free(f_os_desc->compatible_id);
837 free(f_os_desc->sub_compatible_id);
838}
839
847extern int usbg_set_interf_os_desc(usbg_function *f, const char *iname,
848 const struct usbg_function_os_desc *f_os_desc);
849
850/* USB configurations allocation and configuration */
851
863extern int usbg_create_config(usbg_gadget *g, int id, const char *label,
864 const struct usbg_config_attrs *c_attrs,
865 const struct usbg_config_strs *c_strs,
866 usbg_config **c);
867
876extern const char *usbg_get_config_label(usbg_config *c);
877
887extern int usbg_get_config_label_s(usbg_config *c, char *buf, int len);
888
894extern int usbg_get_config_id(usbg_config *c);
895
903 const struct usbg_config_attrs *c_attrs);
904
912 struct usbg_config_attrs *c_attrs);
913
920extern int usbg_set_config_max_power(usbg_config *c, int bMaxPower);
921
928extern int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
929
937extern int usbg_get_config_strs(usbg_config *c, int lang,
938 struct usbg_config_strs *c_strs);
939
946extern int usbg_get_config_strs_langs(usbg_config *c, int **langs);
947
954static inline void usbg_free_config_strs(struct usbg_config_strs *c_strs)
955{
956 if (!c_strs)
957 return;
958
959 free(c_strs->configuration);
960}
961
969extern int usbg_set_config_strs(usbg_config *c, int lang,
970 const struct usbg_config_strs *c_strs);
971
979extern int usbg_set_config_string(usbg_config *c, int lang, const char *string);
980
988extern int usbg_add_config_function(usbg_config *c, const char *name,
989 usbg_function *f);
990
997
1006extern const char *usbg_get_binding_name(usbg_binding *b);
1007
1017extern int usbg_get_binding_name_s(usbg_binding *b, char *buf, int len);
1018
1025
1033
1034/* USB gadget setup and teardown */
1035
1043extern int usbg_enable_gadget(usbg_gadget *g, usbg_udc *udc);
1044
1050extern int usbg_disable_gadget(usbg_gadget *g);
1051
1060extern const char *usbg_get_udc_name(usbg_udc *u);
1061
1071extern int usbg_get_udc_name_s(usbg_udc *u, char *buf, int len);
1072
1079
1086
1091#define usbg_for_each_gadget(g, s) \
1092 for (g = usbg_get_first_gadget(s); \
1093 g != NULL; \
1094 g = usbg_get_next_gadget(g))
1095
1100#define usbg_for_each_function(f, g) \
1101 for (f = usbg_get_first_function(g); \
1102 f != NULL; \
1103 f = usbg_get_next_function(f))
1104
1109#define usbg_for_each_config(c, g) \
1110 for (c = usbg_get_first_config(g); \
1111 c != NULL; \
1112 c = usbg_get_next_config(c))
1113
1118#define usbg_for_each_binding(b, c) \
1119 for (b = usbg_get_first_binding(c); \
1120 b != NULL; \
1121 b = usbg_get_next_binding(b))
1122
1127#define usbg_for_each_udc(u, s) \
1128 for (u = usbg_get_first_udc(s); \
1129 u != NULL; \
1130 u = usbg_get_next_udc(u))
1131
1139
1147
1155
1163
1171
1178
1185
1192
1199
1206
1207/* Import / Export API */
1208
1215extern int usbg_export_function(usbg_function *f, FILE *stream);
1216
1223extern int usbg_export_config(usbg_config *c, FILE *stream);
1224
1231extern int usbg_export_gadget(usbg_gadget *g, FILE *stream);
1232
1242extern int usbg_import_function(usbg_gadget *g, FILE *stream,
1243 const char *instance, usbg_function **f);
1244
1254extern int usbg_import_config(usbg_gadget *g, FILE *stream, int id,
1255 usbg_config **c);
1256
1266extern int usbg_import_gadget(usbg_state *s, FILE *stream,
1267 const char *name, usbg_gadget **g);
1268
1274extern const char *usbg_get_func_import_error_text(usbg_gadget *g);
1275
1282
1288extern const char *usbg_get_config_import_error_text(usbg_gadget *g);
1289
1296
1302extern const char *usbg_get_gadget_import_error_text(usbg_state *s);
1303
1310
1315#ifdef __cplusplus
1316}
1317#endif
1318
1319#endif /* __USBG_H__ */
const char * usbg_get_binding_name(usbg_binding *b)
Get binding name.
Definition usbg.c:2446
int usbg_get_config_strs(usbg_config *c, int lang, struct usbg_config_strs *c_strs)
Get the USB configuration strings.
Definition usbg.c:2329
int usbg_create_gadget(usbg_state *s, const char *name, const struct usbg_gadget_attrs *g_attrs, const struct usbg_gadget_strs *g_strs, usbg_gadget **g)
Create a new USB gadget device and set given attributes and strings.
Definition usbg.c:1532
usbg_function_type
Supported USB function types.
Definition usbg.h:208
int usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0)
Set the maximum packet size for a gadget.
Definition usbg.c:1781
usbg_function * usbg_get_function(usbg_gadget *g, usbg_function_type type, const char *instance)
Get a function by name.
Definition usbg.c:1165
int usbg_get_config_strs_langs(usbg_config *c, int **langs)
Get the array of languages available in this config.
Definition usbg.c:1863
usbg_config * usbg_get_config(usbg_gadget *g, int id, const char *label)
Get a configuration by name.
Definition usbg.c:1177
int usbg_create_gadget_vid_pid(usbg_state *s, const char *name, uint16_t idVendor, uint16_t idProduct, usbg_gadget **g)
Create a new USB gadget device.
Definition usbg.c:1493
int usbg_rm_gadget_strs(usbg_gadget *g, int lang)
Remove gadget strings for given language.
Definition usbg.c:1423
const char * usbg_get_config_label(usbg_config *c)
Get config label.
Definition usbg.c:2257
const char * usbg_strerror(usbg_error e)
Get the short description of error.
Definition usbg_error.c:123
usbg_function * usbg_get_binding_target(usbg_binding *b)
Get target function of given binding.
Definition usbg.c:2441
int usbg_set_gadget_product(usbg_gadget *g, int lang, const char *prd)
Set the product name for a gadget.
Definition usbg.c:1985
const char * usbg_get_udc_name(usbg_udc *u)
Get name of udc.
Definition usbg.c:1598
int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, const char *ser)
Set the serial number for a gadget.
Definition usbg.c:1937
const char * usbg_get_config_import_error_text(usbg_gadget *g)
Get text of error which occurred during last config import.
Definition usbg_schemes_libconfig.c:1865
int usbg_lookup_function_type(const char *name)
Lookup function type suitable for given name.
Definition usbg.c:118
int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, const char *mnf)
Set the manufacturer name for a gadget.
Definition usbg.c:1961
int usbg_rm_gadget(usbg_gadget *g, int opts)
Remove existing USB gadget.
Definition usbg.c:1350
int usbg_set_function_attrs(usbg_function *f, void *f_attrs)
Set attributes of given function.
Definition usbg.c:2615
int usbg_get_config_label_s(usbg_config *c, char *buf, int len)
Get config label into user buffer.
Definition usbg.c:2262
int usbg_import_function(usbg_gadget *g, FILE *stream, const char *instance, usbg_function **f)
Imports usb function from file and adds it to given gadget.
Definition usbg_schemes_libconfig.c:1717
int usbg_export_gadget(usbg_gadget *g, FILE *stream)
Exports whole gadget to file.
Definition usbg_schemes_libconfig.c:776
usbg_gadget * usbg_get_gadget(usbg_state *s, const char *name)
Get a gadget device by name.
Definition usbg.c:1154
int usbg_rm_config_strs(usbg_config *c, int lang)
Remove configuration strings for given language.
Definition usbg.c:1404
int usbg_set_gadget_strs(usbg_gadget *g, int lang, const struct usbg_gadget_strs *g_strs)
Set the USB gadget strings.
Definition usbg.c:1900
int usbg_rm_function(usbg_function *f, int opts)
Remove existing USB function.
Definition usbg.c:1301
int usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
Set the USB gadget protocol code.
Definition usbg.c:1769
int usbg_lookup_gadget_attr(const char *name)
Lookup attr code based on its name.
Definition usbg.c:141
int usbg_set_config_max_power(usbg_config *c, int bMaxPower)
Set the configuration maximum power.
Definition usbg.c:2317
usbg_binding * usbg_get_first_binding(usbg_config *c)
Get first binding in binding list.
Definition usbg.c:2640
usbg_function * usbg_get_first_function(usbg_gadget *g)
Get first function in function list.
Definition usbg.c:2630
usbg_function * usbg_get_next_function(usbg_function *f)
Get the next function on a list.
Definition usbg.c:2655
int usbg_get_gadget_attrs(usbg_gadget *g, struct usbg_gadget_attrs *g_attrs)
Get the USB gadget strings.
Definition usbg.c:1578
int usbg_add_config_function(usbg_config *c, const char *name, usbg_function *f)
Add a function to a configuration.
Definition usbg.c:2368
int usbg_set_config_strs(usbg_config *c, int lang, const struct usbg_config_strs *c_strs)
Set the USB configuration strings.
Definition usbg.c:2336
int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
Set the USB gadget vendor id.
Definition usbg.c:1751
const char * usbg_get_func_import_error_text(usbg_gadget *g)
Get text of error which occurred during last function import.
Definition usbg_schemes_libconfig.c:1849
usbg_gadget * usbg_get_next_gadget(usbg_gadget *g)
Get the next gadget on a list.
Definition usbg.c:2650
usbg_error
Errors which could be returned by library functions.
Definition usbg.h:246
int usbg_set_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr, int val)
Set selected attribute to value.
Definition usbg.c:1612
int usbg_set_interf_os_desc(usbg_function *f, const char *iname, const struct usbg_function_os_desc *f_os_desc)
Set OS Descriptor compatibility of given function.
Definition usbg.c:2150
usbg_udc * usbg_get_next_udc(usbg_udc *u)
Get the next udc on a list.
Definition usbg.c:2670
int usbg_set_gadget_attrs(usbg_gadget *g, const struct usbg_gadget_attrs *g_attrs)
Set the USB gadget attributes.
Definition usbg.c:1703
int usbg_import_gadget(usbg_state *s, FILE *stream, const char *name, usbg_gadget **g)
Imports usb gadget from file.
Definition usbg_schemes_libconfig.c:1805
usbg_gadget * usbg_get_first_gadget(usbg_state *s)
Get first gadget in gadget list.
Definition usbg.c:2625
int usbg_get_config_id(usbg_config *c)
Get config id.
Definition usbg.c:2271
int usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
Set the gadget device BCD release number.
Definition usbg.c:1787
const char * usbg_get_configfs_path(usbg_state *s)
Get ConfigFS path.
Definition usbg.c:1141
usbg_udc * usbg_get_first_udc(usbg_state *s)
Get first udc in udc list.
Definition usbg.c:2645
usbg_gadget_os_desc_strs
Microsoft OS Descriptors strings.
Definition usbg.h:178
int usbg_get_udc_name_s(usbg_udc *u, char *buf, int len)
Get udc name into user buffer.
Definition usbg.c:1603
int usbg_export_config(usbg_config *c, FILE *stream)
Exports configuration to file.
Definition usbg_schemes_libconfig.c:749
usbg_function_type usbg_get_function_type(usbg_function *f)
Get type of given function.
Definition usbg.c:2598
usbg_config * usbg_get_first_config(usbg_gadget *g)
Get first config in config list.
Definition usbg.c:2635
int usbg_get_configfs_path_s(usbg_state *s, char *buf, int len)
Get ConfigFS path into user buffer.
Definition usbg.c:1146
int usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
Set the USB gadget device class code.
Definition usbg.c:1763
int usbg_get_interf_os_desc(usbg_function *f, const char *iname, struct usbg_function_os_desc *f_os_desc)
Get OS Descriptor compatibility of given function.
Definition usbg.c:2115
int usbg_get_function_instance_s(usbg_function *f, char *buf, int len)
Get function instance name into user buffer.
Definition usbg.c:2281
int usbg_create_config(usbg_gadget *g, int id, const char *label, const struct usbg_config_attrs *c_attrs, const struct usbg_config_strs *c_strs, usbg_config **c)
Create a new USB gadget configuration.
Definition usbg.c:2179
int usbg_enable_gadget(usbg_gadget *g, usbg_udc *udc)
Enable a USB gadget device.
Definition usbg.c:2548
int usbg_rm_config(usbg_config *c, int opts)
Remove configuration.
Definition usbg.c:1247
usbg_config * usbg_get_os_desc_binding(usbg_gadget *g)
Get configuration selected for OS Descriptors.
Definition usbg.c:1242
int usbg_set_config_attrs(usbg_config *c, const struct usbg_config_attrs *c_attrs)
Set the USB configuration attributes.
Definition usbg.c:2289
int usbg_lookup_gadget_str(const char *name)
Lookup str code based on its name.
Definition usbg.c:157
int usbg_get_gadget_os_descs(usbg_gadget *g, struct usbg_gadget_os_descs *g_os_descs)
Get the USB gadget OS Descriptor.
Definition usbg.c:2009
const char * usbg_get_gadget_os_desc_name(usbg_gadget_os_desc_strs str)
Get name of selected OS Descriptor string.
Definition usbg.c:187
int usbg_import_config(usbg_gadget *g, FILE *stream, int id, usbg_config **c)
Imports usb configuration from file and adds it to given gadget.
Definition usbg_schemes_libconfig.c:1762
int usbg_init(const char *configfs_path, usbg_state **state)
Initialize the libusbgx library state.
Definition usbg.c:1091
usbg_udc * usbg_get_gadget_udc(usbg_gadget *g)
Get udc to which gadget is bound.
Definition usbg.c:1648
int usbg_get_gadget_name_s(usbg_gadget *g, char *buf, int len)
Get gadget name into user buffer.
Definition usbg.c:1590
const char * usbg_get_gadget_name(usbg_gadget *g)
Get gadget name.
Definition usbg.c:1585
const char * usbg_get_gadget_attr_str(usbg_gadget_attr attr)
Get string representing selected gadget attribute.
Definition usbg.c:173
int usbg_export_function(usbg_function *f, FILE *stream)
Exports usb function to file.
Definition usbg_schemes_libconfig.c:722
const char * usbg_get_function_instance(usbg_function *f)
Get function instance name.
Definition usbg.c:2276
int usbg_rm_binding(usbg_binding *b)
Remove binding between configuration and function.
Definition usbg.c:1221
int usbg_set_config_string(usbg_config *c, int lang, const char *string)
Set the configuration string.
Definition usbg.c:2342
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition usbg.c:1136
usbg_udc * usbg_get_udc(usbg_state *s, const char *name)
Get a udc by name.
Definition usbg.c:1188
int usbg_get_func_import_error_line(usbg_gadget *g)
Get line number where function import error occurred.
Definition usbg_schemes_libconfig.c:1857
usbg_gadget * usbg_get_udc_gadget(usbg_udc *u)
Get gadget which is attached to this UDC.
Definition usbg.c:1678
int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang, const char *val)
Set selected string.
Definition usbg.c:1868
int usbg_get_gadget_import_error_line(usbg_state *s)
Get line number where gadget import error occurred.
Definition usbg_schemes_libconfig.c:1889
int usbg_disable_gadget(usbg_gadget *g)
Disable a USB gadget device.
Definition usbg.c:2576
int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
Set the configuration bitmap attributes.
Definition usbg.c:2323
int usbg_create_function(usbg_gadget *g, usbg_function_type type, const char *instance, void *f_attrs, usbg_function **f)
Create a new USB gadget function and set its attributes.
Definition usbg.c:2051
int usbg_set_os_desc_config(usbg_gadget *g, usbg_config *c)
Set configuration for OS Descriptors.
Definition usbg.c:2527
void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs)
Cleanup content of function attributes.
Definition usbg.c:2609
usbg_binding * usbg_get_next_binding(usbg_binding *b)
Get the next binding on a list.
Definition usbg.c:2665
const char * usbg_get_function_type_str(usbg_function_type type)
Get function type as a string.
Definition usbg.c:134
int usbg_get_config_attrs(usbg_config *c, struct usbg_config_attrs *c_attrs)
Get the USB configuration strings.
Definition usbg.c:2310
usbg_gadget_attr
Gadget attributes which can be set using usbg_set_gadget_attr() function.
Definition usbg.h:118
int usbg_get_config_import_error_line(usbg_gadget *g)
Get line number where config import error occurred.
Definition usbg_schemes_libconfig.c:1873
const char * usbg_get_gadget_import_error_text(usbg_state *s)
Get text of error which occurred during last gadget import.
Definition usbg_schemes_libconfig.c:1881
int usbg_get_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr)
Get value of selected attribute.
Definition usbg.c:1630
int usbg_get_function_attrs(usbg_function *f, void *f_attrs)
Get attributes of given function.
Definition usbg.c:2603
int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs)
Get the array of languages available in this gadget.
Definition usbg.c:1858
int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
Set the USB gadget product id.
Definition usbg.c:1757
int usbg_set_gadget_os_descs(usbg_gadget *g, const struct usbg_gadget_os_descs *g_os_descs)
Set the USB gadget OS Descriptor.
Definition usbg.c:2016
const char * usbg_error_name(usbg_error e)
Get the error name as a constant string.
Definition usbg_error.c:62
int usbg_get_gadget_strs(usbg_gadget *g, int lang, struct usbg_gadget_strs *g_strs)
Get the USB gadget strings.
Definition usbg.c:1799
int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
Set the gadget device BCD USB version.
Definition usbg.c:1793
const char * usbg_get_gadget_str_name(usbg_gadget_str str)
Get name of selected gadget string.
Definition usbg.c:180
usbg_config * usbg_get_next_config(usbg_config *c)
Get the next config on a list.
Definition usbg.c:2660
int usbg_get_binding_name_s(usbg_binding *b, char *buf, int len)
Get binding name into user buffer.
Definition usbg.c:2451
int usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
Set the USB gadget device subclass code.
Definition usbg.c:1775
USB configuration attributes.
Definition usbg.h:190
USB configuration strings.
Definition usbg.h:199
USB OS Descriptor function attributes.
Definition usbg.h:235
USB gadget device attributes.
Definition usbg.h:135
USB gadget Microsoft OS Descriptors.
Definition usbg.h:168
USB gadget device strings.
Definition usbg.h:158
Definition usbg_internal.h:143
Definition usbg_internal.h:117
Definition usbg_internal.h:129
Definition usbg_internal.h:103
Definition usbg_internal.h:93
Definition usbg_internal.h:153
Definition usbg_internal.h:51