libusbgx-0.2.0
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/* This one has to be at least 18 bytes to hold network address */
55#define USBG_MAX_STR_LENGTH 256
56#define USBG_MAX_NAME_LENGTH 40
57/* Dev name for ffs is a part of function name, we subtract 4 char for "ffs." */
58#define USBG_MAX_DEV_LENGTH (USBG_MAX_NAME_LENGTH - 4)
59
60#define USBG_TO_UNION(UNAME, FIELD, WHAT) \
61 ((union UNAME){ .FIELD = WHAT, })
62
68#define USBG_RM_RECURSE 1
69
70/*
71 * Internal structures
72 */
73struct usbg_state;
74struct usbg_gadget;
75struct usbg_config;
76struct usbg_function;
77struct usbg_binding;
78struct usbg_udc;
79
83typedef struct usbg_state usbg_state;
84
88typedef struct usbg_gadget usbg_gadget;
89
93typedef struct usbg_config usbg_config;
94
99
104
108typedef struct usbg_udc usbg_udc;
109
115typedef enum {
116 USBG_GADGET_ATTR_MIN = 0,
117 USBG_BCD_USB = USBG_GADGET_ATTR_MIN,
118 USBG_B_DEVICE_CLASS,
119 USBG_B_DEVICE_SUB_CLASS,
120 USBG_B_DEVICE_PROTOCOL,
121 USBG_B_MAX_PACKET_SIZE_0,
122 USBG_ID_VENDOR,
123 USBG_ID_PRODUCT,
124 USBG_BCD_DEVICE,
125 USBG_GADGET_ATTR_MAX,
127
132{
133 uint16_t bcdUSB;
134 uint8_t bDeviceClass;
135 uint8_t bDeviceSubClass;
136 uint8_t bDeviceProtocol;
137 uint8_t bMaxPacketSize0;
138 uint16_t idVendor;
139 uint16_t idProduct;
140 uint16_t bcdDevice;
141};
142
143typedef enum {
144 USBG_GADGET_STR_MIN = 0,
145 USBG_STR_MANUFACTURER = USBG_GADGET_STR_MIN,
146 USBG_STR_PRODUCT,
147 USBG_STR_SERIAL_NUMBER,
148 USBG_GADGET_STR_MAX,
149} usbg_gadget_str;
150
155{
156 char *manufacturer;
157 char *product;
158 char *serial;
159};
160
165{
166 bool use;
167 uint8_t b_vendor_code;
168 char *qw_sign;
169};
170
175typedef enum {
176 USBG_GADGET_OS_DESC_MIN = 0,
177 OS_DESC_USE = USBG_GADGET_OS_DESC_MIN,
178 OS_DESC_B_VENDOR_CODE,
179 OS_DESC_QW_SIGN,
180 USBG_GADGET_OS_DESC_MAX,
182
187{
188 uint8_t bmAttributes;
189 uint8_t bMaxPower;
190};
191
196{
197 char *configuration;
198};
199
204typedef enum
205{
206 USBG_FUNCTION_TYPE_MIN = 0,
207 USBG_F_SERIAL = USBG_FUNCTION_TYPE_MIN,
208 USBG_F_ACM,
209 USBG_F_OBEX,
210 USBG_F_ECM,
211 USBG_F_SUBSET,
212 USBG_F_NCM,
213 USBG_F_EEM,
214 USBG_F_RNDIS,
215 USBG_F_PHONET,
216 USBG_F_FFS,
217 USBG_F_MASS_STORAGE,
218 USBG_F_MIDI,
219 USBG_F_LOOPBACK,
220 USBG_F_HID,
221 USBG_F_UAC2,
222 USBG_F_UVC,
223 USBG_F_PRINTER,
224 USBG_FUNCTION_TYPE_MAX,
226
231{
232 char *compatible_id;
233 char *sub_compatible_id;
234};
235
236/* Error codes */
237
242typedef enum {
243 USBG_SUCCESS = 0,
244 USBG_ERROR_NO_MEM = -1,
245 USBG_ERROR_NO_ACCESS = -2,
246 USBG_ERROR_INVALID_PARAM = -3,
247 USBG_ERROR_NOT_FOUND = -4,
248 USBG_ERROR_IO = -5,
249 USBG_ERROR_EXIST = -6,
250 USBG_ERROR_NO_DEV = -7,
251 USBG_ERROR_BUSY = -8,
252 USBG_ERROR_NOT_SUPPORTED = -9,
253 USBG_ERROR_PATH_TOO_LONG = -10,
254 USBG_ERROR_INVALID_FORMAT = -11,
255 USBG_ERROR_MISSING_TAG = -12,
256 USBG_ERROR_INVALID_TYPE = -13,
257 USBG_ERROR_INVALID_VALUE = -14,
258 USBG_ERROR_NOT_EMPTY = -15,
259 USBG_ERROR_OTHER_ERROR = -99
260} usbg_error;
261
267extern const char *usbg_error_name(usbg_error e);
268
274extern const char *usbg_strerror(usbg_error e);
275
276/* Library init and cleanup */
277
284extern int usbg_init(const char *configfs_path, usbg_state **state);
285
290extern void usbg_cleanup(usbg_state *s);
291
300extern const char *usbg_get_configfs_path(usbg_state *s);
301
311extern int usbg_get_configfs_path_s(usbg_state *s, char *buf, int len);
312
313/* USB gadget queries */
314
321extern usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name);
322
331 usbg_function_type type, const char *instance);
332
343extern usbg_config *usbg_get_config(usbg_gadget *g, int id, const char *label);
344
351extern usbg_udc *usbg_get_udc(usbg_state *s, const char *name);
352
353/* USB gadget/config/function/binding removal */
354
361extern int usbg_rm_binding(usbg_binding *b);
362
370extern int usbg_rm_config(usbg_config *c, int opts);
371
379extern int usbg_rm_function(usbg_function *f, int opts);
380
388extern int usbg_rm_gadget(usbg_gadget *g, int opts);
389
396extern int usbg_rm_config_strs(usbg_config *c, int lang);
397
404extern int usbg_rm_gadget_strs(usbg_gadget *g, int lang);
405
406/* USB gadget allocation and configuration */
407
417extern int usbg_create_gadget_vid_pid(usbg_state *s, const char *name,
418 uint16_t idVendor, uint16_t idProduct, usbg_gadget **g);
419
431extern int usbg_create_gadget(usbg_state *s, const char *name,
432 const struct usbg_gadget_attrs *g_attrs,
433 const struct usbg_gadget_strs *g_strs,
434 usbg_gadget **g);
435
442extern const char *usbg_get_gadget_attr_str(usbg_gadget_attr attr);
443
449extern int usbg_lookup_gadget_attr(const char *name);
450
456extern int usbg_lookup_gadget_str(const char *name);
457
463extern const char *usbg_get_gadget_str_name(usbg_gadget_str str);
464
471
481extern int usbg_set_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr, int val);
482
493
501 const struct usbg_gadget_attrs *g_attrs);
502
510 struct usbg_gadget_attrs *g_attrs);
511
520extern const char *usbg_get_gadget_name(usbg_gadget *g);
521
531extern int usbg_get_gadget_name_s(usbg_gadget *g, char *buf, int len);
532
539extern int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
540
547extern int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
548
556 uint8_t bDeviceClass);
557
565 uint8_t bDeviceProtocol);
566
574 uint8_t bDeviceSubClass);
575
583 uint8_t bMaxPacketSize0);
584
592 uint16_t bcdDevice);
593
600extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
601
609extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
610 struct usbg_gadget_strs *g_strs);
611
618extern int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs);
619
626static inline void usbg_free_gadget_strs(struct usbg_gadget_strs *g_strs)
627{
628 if (!g_strs)
629 return;
630
631 free(g_strs->manufacturer);
632 free(g_strs->product);
633 free(g_strs->serial);
634}
635
643extern int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang,
644 const char *val);
645
653extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
654 const struct usbg_gadget_strs *g_strs);
655
663extern int usbg_set_gadget_serial_number(usbg_gadget *g, int lang,
664 const char *ser);
665
673extern int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang,
674 const char *mnf);
675
683extern int usbg_set_gadget_product(usbg_gadget *g, int lang,
684 const char *prd);
685
694 struct usbg_gadget_os_descs *g_os_descs);
695
702static inline void usbg_free_gadget_os_desc(
703 struct usbg_gadget_os_descs *g_os_desc)
704{
705 if (!g_os_desc)
706 return;
707
708 free(g_os_desc->qw_sign);
709}
710
719 const struct usbg_gadget_os_descs *g_os_descs);
720
721/* USB function allocation and configuration */
722
735 const char *instance, void *f_attrs, usbg_function **f);
736
745extern const char *usbg_get_function_instance(usbg_function *f);
746
756extern int usbg_get_function_instance_s(usbg_function *f, char *buf, int len);
757
763extern const char *usbg_get_function_type_str(usbg_function_type type);
764
770extern int usbg_lookup_function_type(const char *name);
771
780extern void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs);
781
789
800extern int usbg_get_function_attrs(usbg_function *f, void *f_attrs);
801
808extern int usbg_set_function_attrs(usbg_function *f, void *f_attrs);
809
817extern int usbg_get_interf_os_desc(usbg_function *f, const char *iname,
818 struct usbg_function_os_desc *f_os_desc);
819
826static inline void usbg_free_interf_os_desc(
827 struct usbg_function_os_desc *f_os_desc)
828{
829 if (!f_os_desc)
830 return;
831
832 free(f_os_desc->compatible_id);
833 free(f_os_desc->sub_compatible_id);
834}
835
843extern int usbg_set_interf_os_desc(usbg_function *f, const char *iname,
844 const struct usbg_function_os_desc *f_os_desc);
845
846/* USB configurations allocation and configuration */
847
859extern int usbg_create_config(usbg_gadget *g, int id, const char *label,
860 const struct usbg_config_attrs *c_attrs,
861 const struct usbg_config_strs *c_strs,
862 usbg_config **c);
863
872extern const char *usbg_get_config_label(usbg_config *c);
873
883extern int usbg_get_config_label_s(usbg_config *c, char *buf, int len);
884
890extern int usbg_get_config_id(usbg_config *c);
891
899 const struct usbg_config_attrs *c_attrs);
900
908 struct usbg_config_attrs *c_attrs);
909
916extern int usbg_set_config_max_power(usbg_config *c, int bMaxPower);
917
924extern int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
925
933extern int usbg_get_config_strs(usbg_config *c, int lang,
934 struct usbg_config_strs *c_strs);
935
942extern int usbg_get_config_strs_langs(usbg_config *c, int **langs);
943
950static inline void usbg_free_config_strs(struct usbg_config_strs *c_strs)
951{
952 if (!c_strs)
953 return;
954
955 free(c_strs->configuration);
956}
957
965extern int usbg_set_config_strs(usbg_config *c, int lang,
966 const struct usbg_config_strs *c_strs);
967
975extern int usbg_set_config_string(usbg_config *c, int lang, const char *string);
976
984extern int usbg_add_config_function(usbg_config *c, const char *name,
985 usbg_function *f);
986
993
1002extern const char *usbg_get_binding_name(usbg_binding *b);
1003
1013extern int usbg_get_binding_name_s(usbg_binding *b, char *buf, int len);
1014
1021
1029
1030/* USB gadget setup and teardown */
1031
1039extern int usbg_enable_gadget(usbg_gadget *g, usbg_udc *udc);
1040
1046extern int usbg_disable_gadget(usbg_gadget *g);
1047
1056extern const char *usbg_get_udc_name(usbg_udc *u);
1057
1067extern int usbg_get_udc_name_s(usbg_udc *u, char *buf, int len);
1068
1075
1082
1087#define usbg_for_each_gadget(g, s) \
1088 for (g = usbg_get_first_gadget(s); \
1089 g != NULL; \
1090 g = usbg_get_next_gadget(g))
1091
1096#define usbg_for_each_function(f, g) \
1097 for (f = usbg_get_first_function(g); \
1098 f != NULL; \
1099 f = usbg_get_next_function(f))
1100
1105#define usbg_for_each_config(c, g) \
1106 for (c = usbg_get_first_config(g); \
1107 c != NULL; \
1108 c = usbg_get_next_config(c))
1109
1114#define usbg_for_each_binding(b, c) \
1115 for (b = usbg_get_first_binding(c); \
1116 b != NULL; \
1117 b = usbg_get_next_binding(b))
1118
1123#define usbg_for_each_udc(u, s) \
1124 for (u = usbg_get_first_udc(s); \
1125 u != NULL; \
1126 u = usbg_get_next_udc(u))
1127
1135
1143
1151
1159
1167
1174
1181
1188
1195
1202
1203/* Import / Export API */
1204
1211extern int usbg_export_function(usbg_function *f, FILE *stream);
1212
1219extern int usbg_export_config(usbg_config *c, FILE *stream);
1220
1227extern int usbg_export_gadget(usbg_gadget *g, FILE *stream);
1228
1238extern int usbg_import_function(usbg_gadget *g, FILE *stream,
1239 const char *instance, usbg_function **f);
1240
1250extern int usbg_import_config(usbg_gadget *g, FILE *stream, int id,
1251 usbg_config **c);
1252
1262extern int usbg_import_gadget(usbg_state *s, FILE *stream,
1263 const char *name, usbg_gadget **g);
1264
1270extern const char *usbg_get_func_import_error_text(usbg_gadget *g);
1271
1278
1284extern const char *usbg_get_config_import_error_text(usbg_gadget *g);
1285
1292
1298extern const char *usbg_get_gadget_import_error_text(usbg_state *s);
1299
1306
1311#ifdef __cplusplus
1312}
1313#endif
1314
1315#endif /* __USBG_H__ */
const char * usbg_get_binding_name(usbg_binding *b)
Get binding name.
Definition: usbg.c:2444
int usbg_get_config_strs(usbg_config *c, int lang, struct usbg_config_strs *c_strs)
Get the USB configuration strings.
Definition: usbg.c:2327
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:1530
usbg_function_type
Supported USB function types.
Definition: usbg.h:205
int usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0)
Set the maximum packet size for a gadget.
Definition: usbg.c:1779
usbg_function * usbg_get_function(usbg_gadget *g, usbg_function_type type, const char *instance)
Get a function by name.
Definition: usbg.c:1163
int usbg_get_config_strs_langs(usbg_config *c, int **langs)
Get the array of languages available in this config.
Definition: usbg.c:1861
usbg_config * usbg_get_config(usbg_gadget *g, int id, const char *label)
Get a configuration by name.
Definition: usbg.c:1175
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:1491
int usbg_rm_gadget_strs(usbg_gadget *g, int lang)
Remove gadget strings for given language.
Definition: usbg.c:1421
const char * usbg_get_config_label(usbg_config *c)
Get config label.
Definition: usbg.c:2255
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:2439
int usbg_set_gadget_product(usbg_gadget *g, int lang, const char *prd)
Set the product name for a gadget.
Definition: usbg.c:1983
const char * usbg_get_udc_name(usbg_udc *u)
Get name of udc.
Definition: usbg.c:1596
int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, const char *ser)
Set the serial number for a gadget.
Definition: usbg.c:1935
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:116
int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, const char *mnf)
Set the manufacturer name for a gadget.
Definition: usbg.c:1959
int usbg_rm_gadget(usbg_gadget *g, int opts)
Remove existing USB gadget.
Definition: usbg.c:1348
int usbg_set_function_attrs(usbg_function *f, void *f_attrs)
Set attributes of given function.
Definition: usbg.c:2613
int usbg_get_config_label_s(usbg_config *c, char *buf, int len)
Get config label into user buffer.
Definition: usbg.c:2260
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:1152
int usbg_rm_config_strs(usbg_config *c, int lang)
Remove configuration strings for given language.
Definition: usbg.c:1402
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:1898
int usbg_rm_function(usbg_function *f, int opts)
Remove existing USB function.
Definition: usbg.c:1299
int usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
Set the USB gadget protocol code.
Definition: usbg.c:1767
int usbg_lookup_gadget_attr(const char *name)
Lookup attr code based on its name.
Definition: usbg.c:139
int usbg_set_config_max_power(usbg_config *c, int bMaxPower)
Set the configuration maximum power.
Definition: usbg.c:2315
usbg_binding * usbg_get_first_binding(usbg_config *c)
Get first binding in binding list.
Definition: usbg.c:2638
usbg_function * usbg_get_first_function(usbg_gadget *g)
Get first function in function list.
Definition: usbg.c:2628
usbg_function * usbg_get_next_function(usbg_function *f)
Get the next function on a list.
Definition: usbg.c:2653
int usbg_get_gadget_attrs(usbg_gadget *g, struct usbg_gadget_attrs *g_attrs)
Get the USB gadget strings.
Definition: usbg.c:1576
int usbg_add_config_function(usbg_config *c, const char *name, usbg_function *f)
Add a function to a configuration.
Definition: usbg.c:2366
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:2334
int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
Set the USB gadget vendor id.
Definition: usbg.c:1749
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:2648
usbg_error
Errors which could be returned by library functions.
Definition: usbg.h:242
int usbg_set_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr, int val)
Set selected attribute to value.
Definition: usbg.c:1610
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:2148
usbg_udc * usbg_get_next_udc(usbg_udc *u)
Get the next udc on a list.
Definition: usbg.c:2668
int usbg_set_gadget_attrs(usbg_gadget *g, const struct usbg_gadget_attrs *g_attrs)
Set the USB gadget attributes.
Definition: usbg.c:1701
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:2623
int usbg_get_config_id(usbg_config *c)
Get config id.
Definition: usbg.c:2269
int usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
Set the gadget device BCD release number.
Definition: usbg.c:1785
const char * usbg_get_configfs_path(usbg_state *s)
Get ConfigFS path.
Definition: usbg.c:1139
usbg_udc * usbg_get_first_udc(usbg_state *s)
Get first udc in udc list.
Definition: usbg.c:2643
usbg_gadget_os_desc_strs
Microsoft OS Descriptors strings.
Definition: usbg.h:175
int usbg_get_udc_name_s(usbg_udc *u, char *buf, int len)
Get udc name into user buffer.
Definition: usbg.c:1601
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:2596
usbg_config * usbg_get_first_config(usbg_gadget *g)
Get first config in config list.
Definition: usbg.c:2633
int usbg_get_configfs_path_s(usbg_state *s, char *buf, int len)
Get ConfigFS path into user buffer.
Definition: usbg.c:1144
int usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
Set the USB gadget device class code.
Definition: usbg.c:1761
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:2113
int usbg_get_function_instance_s(usbg_function *f, char *buf, int len)
Get function instance name into user buffer.
Definition: usbg.c:2279
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:2177
int usbg_enable_gadget(usbg_gadget *g, usbg_udc *udc)
Enable a USB gadget device.
Definition: usbg.c:2546
int usbg_rm_config(usbg_config *c, int opts)
Remove configuration.
Definition: usbg.c:1245
usbg_config * usbg_get_os_desc_binding(usbg_gadget *g)
Get configuration selected for OS Descriptors.
Definition: usbg.c:1240
int usbg_set_config_attrs(usbg_config *c, const struct usbg_config_attrs *c_attrs)
Set the USB configuration attributes.
Definition: usbg.c:2287
int usbg_lookup_gadget_str(const char *name)
Lookup str code based on its name.
Definition: usbg.c:155
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:2007
const char * usbg_get_gadget_os_desc_name(usbg_gadget_os_desc_strs str)
Get name of selected OS Descriptor string.
Definition: usbg.c:185
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:1089
usbg_udc * usbg_get_gadget_udc(usbg_gadget *g)
Get udc to which gadget is bound.
Definition: usbg.c:1646
int usbg_get_gadget_name_s(usbg_gadget *g, char *buf, int len)
Get gadget name into user buffer.
Definition: usbg.c:1588
const char * usbg_get_gadget_name(usbg_gadget *g)
Get gadget name.
Definition: usbg.c:1583
const char * usbg_get_gadget_attr_str(usbg_gadget_attr attr)
Get string representing selected gadget attribute.
Definition: usbg.c:171
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:2274
int usbg_rm_binding(usbg_binding *b)
Remove binding between configuration and function.
Definition: usbg.c:1219
int usbg_set_config_string(usbg_config *c, int lang, const char *string)
Set the configuration string.
Definition: usbg.c:2340
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition: usbg.c:1134
usbg_udc * usbg_get_udc(usbg_state *s, const char *name)
Get a udc by name.
Definition: usbg.c:1186
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:1676
int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang, const char *val)
Set selected string.
Definition: usbg.c:1866
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:2574
int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
Set the configuration bitmap attributes.
Definition: usbg.c:2321
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:2049
int usbg_set_os_desc_config(usbg_gadget *g, usbg_config *c)
Set configuration for OS Descriptors.
Definition: usbg.c:2525
void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs)
Cleanup content of function attributes.
Definition: usbg.c:2607
usbg_binding * usbg_get_next_binding(usbg_binding *b)
Get the next binding on a list.
Definition: usbg.c:2663
const char * usbg_get_function_type_str(usbg_function_type type)
Get function type as a string.
Definition: usbg.c:132
int usbg_get_config_attrs(usbg_config *c, struct usbg_config_attrs *c_attrs)
Get the USB configuration strings.
Definition: usbg.c:2308
usbg_gadget_attr
Gadget attributes which can be set using usbg_set_gadget_attr() function.
Definition: usbg.h:115
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:1628
int usbg_get_function_attrs(usbg_function *f, void *f_attrs)
Get attributes of given function.
Definition: usbg.c:2601
int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs)
Get the array of languages available in this gadget.
Definition: usbg.c:1856
int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
Set the USB gadget product id.
Definition: usbg.c:1755
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:2014
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:1797
int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
Set the gadget device BCD USB version.
Definition: usbg.c:1791
const char * usbg_get_gadget_str_name(usbg_gadget_str str)
Get name of selected gadget string.
Definition: usbg.c:178
usbg_config * usbg_get_next_config(usbg_config *c)
Get the next config on a list.
Definition: usbg.c:2658
int usbg_get_binding_name_s(usbg_binding *b, char *buf, int len)
Get binding name into user buffer.
Definition: usbg.c:2449
int usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
Set the USB gadget device subclass code.
Definition: usbg.c:1773
USB configuration attributes.
Definition: usbg.h:187
USB configuration strings.
Definition: usbg.h:196
USB OS Descriptor function attributes.
Definition: usbg.h:231
USB gadget device attributes.
Definition: usbg.h:132
USB gadget Microsoft OS Descriptors.
Definition: usbg.h:165
USB gadget device strings.
Definition: usbg.h:155
Definition: usbg_internal.h:143
Definition: usbg_internal.h:117
Definition: usbg_internal.h:51
Definition: usbg_internal.h:129
Definition: usbg_internal.h:103
Definition: usbg_internal.h:93
Definition: usbg_internal.h:153