libusbgx-0.2.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/* 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_FUNCTION_TYPE_MAX,
224
229{
230 char *compatible_id;
231 char *sub_compatible_id;
232};
233
234/* Error codes */
235
240typedef enum {
241 USBG_SUCCESS = 0,
242 USBG_ERROR_NO_MEM = -1,
243 USBG_ERROR_NO_ACCESS = -2,
244 USBG_ERROR_INVALID_PARAM = -3,
245 USBG_ERROR_NOT_FOUND = -4,
246 USBG_ERROR_IO = -5,
247 USBG_ERROR_EXIST = -6,
248 USBG_ERROR_NO_DEV = -7,
249 USBG_ERROR_BUSY = -8,
250 USBG_ERROR_NOT_SUPPORTED = -9,
251 USBG_ERROR_PATH_TOO_LONG = -10,
252 USBG_ERROR_INVALID_FORMAT = -11,
253 USBG_ERROR_MISSING_TAG = -12,
254 USBG_ERROR_INVALID_TYPE = -13,
255 USBG_ERROR_INVALID_VALUE = -14,
256 USBG_ERROR_NOT_EMPTY = -15,
257 USBG_ERROR_OTHER_ERROR = -99
258} usbg_error;
259
265extern const char *usbg_error_name(usbg_error e);
266
272extern const char *usbg_strerror(usbg_error e);
273
274/* Library init and cleanup */
275
282extern int usbg_init(const char *configfs_path, usbg_state **state);
283
288extern void usbg_cleanup(usbg_state *s);
289
298extern const char *usbg_get_configfs_path(usbg_state *s);
299
309extern int usbg_get_configfs_path_s(usbg_state *s, char *buf, int len);
310
311/* USB gadget queries */
312
319extern usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name);
320
329 usbg_function_type type, const char *instance);
330
341extern usbg_config *usbg_get_config(usbg_gadget *g, int id, const char *label);
342
349extern usbg_udc *usbg_get_udc(usbg_state *s, const char *name);
350
351/* USB gadget/config/function/binding removal */
352
359extern int usbg_rm_binding(usbg_binding *b);
360
368extern int usbg_rm_config(usbg_config *c, int opts);
369
377extern int usbg_rm_function(usbg_function *f, int opts);
378
386extern int usbg_rm_gadget(usbg_gadget *g, int opts);
387
394extern int usbg_rm_config_strs(usbg_config *c, int lang);
395
402extern int usbg_rm_gadget_strs(usbg_gadget *g, int lang);
403
404/* USB gadget allocation and configuration */
405
415extern int usbg_create_gadget_vid_pid(usbg_state *s, const char *name,
416 uint16_t idVendor, uint16_t idProduct, usbg_gadget **g);
417
429extern int usbg_create_gadget(usbg_state *s, const char *name,
430 const struct usbg_gadget_attrs *g_attrs,
431 const struct usbg_gadget_strs *g_strs,
432 usbg_gadget **g);
433
440extern const char *usbg_get_gadget_attr_str(usbg_gadget_attr attr);
441
447extern int usbg_lookup_gadget_attr(const char *name);
448
454extern int usbg_lookup_gadget_str(const char *name);
455
461extern const char *usbg_get_gadget_str_name(usbg_gadget_str str);
462
469
479extern int usbg_set_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr, int val);
480
491
499 const struct usbg_gadget_attrs *g_attrs);
500
508 struct usbg_gadget_attrs *g_attrs);
509
518extern const char *usbg_get_gadget_name(usbg_gadget *g);
519
529extern int usbg_get_gadget_name_s(usbg_gadget *g, char *buf, int len);
530
537extern int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
538
545extern int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
546
554 uint8_t bDeviceClass);
555
563 uint8_t bDeviceProtocol);
564
572 uint8_t bDeviceSubClass);
573
581 uint8_t bMaxPacketSize0);
582
590 uint16_t bcdDevice);
591
598extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
599
607extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
608 struct usbg_gadget_strs *g_strs);
609
616extern int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs);
617
624static inline void usbg_free_gadget_strs(struct usbg_gadget_strs *g_strs)
625{
626 if (!g_strs)
627 return;
628
629 free(g_strs->manufacturer);
630 free(g_strs->product);
631 free(g_strs->serial);
632}
633
641extern int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang,
642 const char *val);
643
651extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
652 const struct usbg_gadget_strs *g_strs);
653
661extern int usbg_set_gadget_serial_number(usbg_gadget *g, int lang,
662 const char *ser);
663
671extern int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang,
672 const char *mnf);
673
681extern int usbg_set_gadget_product(usbg_gadget *g, int lang,
682 const char *prd);
683
692 struct usbg_gadget_os_descs *g_os_descs);
693
700static inline void usbg_free_gadget_os_desc(
701 struct usbg_gadget_os_descs *g_os_desc)
702{
703 if (!g_os_desc)
704 return;
705
706 free(g_os_desc->qw_sign);
707}
708
717 const struct usbg_gadget_os_descs *g_os_descs);
718
719/* USB function allocation and configuration */
720
733 const char *instance, void *f_attrs, usbg_function **f);
734
743extern const char *usbg_get_function_instance(usbg_function *f);
744
754extern int usbg_get_function_instance_s(usbg_function *f, char *buf, int len);
755
761extern const char *usbg_get_function_type_str(usbg_function_type type);
762
768extern int usbg_lookup_function_type(const char *name);
769
778extern void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs);
779
787
798extern int usbg_get_function_attrs(usbg_function *f, void *f_attrs);
799
806extern int usbg_set_function_attrs(usbg_function *f, void *f_attrs);
807
815extern int usbg_get_interf_os_desc(usbg_function *f, const char *iname,
816 struct usbg_function_os_desc *f_os_desc);
817
824static inline void usbg_free_interf_os_desc(
825 struct usbg_function_os_desc *f_os_desc)
826{
827 if (!f_os_desc)
828 return;
829
830 free(f_os_desc->compatible_id);
831 free(f_os_desc->sub_compatible_id);
832}
833
841extern int usbg_set_interf_os_desc(usbg_function *f, const char *iname,
842 const struct usbg_function_os_desc *f_os_desc);
843
844/* USB configurations allocation and configuration */
845
857extern int usbg_create_config(usbg_gadget *g, int id, const char *label,
858 const struct usbg_config_attrs *c_attrs,
859 const struct usbg_config_strs *c_strs,
860 usbg_config **c);
861
870extern const char *usbg_get_config_label(usbg_config *c);
871
881extern int usbg_get_config_label_s(usbg_config *c, char *buf, int len);
882
888extern int usbg_get_config_id(usbg_config *c);
889
897 const struct usbg_config_attrs *c_attrs);
898
906 struct usbg_config_attrs *c_attrs);
907
914extern int usbg_set_config_max_power(usbg_config *c, int bMaxPower);
915
922extern int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
923
931extern int usbg_get_config_strs(usbg_config *c, int lang,
932 struct usbg_config_strs *c_strs);
933
940extern int usbg_get_config_strs_langs(usbg_config *c, int **langs);
941
948static inline void usbg_free_config_strs(struct usbg_config_strs *c_strs)
949{
950 if (!c_strs)
951 return;
952
953 free(c_strs->configuration);
954}
955
963extern int usbg_set_config_strs(usbg_config *c, int lang,
964 const struct usbg_config_strs *c_strs);
965
973extern int usbg_set_config_string(usbg_config *c, int lang, const char *string);
974
982extern int usbg_add_config_function(usbg_config *c, const char *name,
983 usbg_function *f);
984
991
1000extern const char *usbg_get_binding_name(usbg_binding *b);
1001
1011extern int usbg_get_binding_name_s(usbg_binding *b, char *buf, int len);
1012
1019
1027
1028/* USB gadget setup and teardown */
1029
1037extern int usbg_enable_gadget(usbg_gadget *g, usbg_udc *udc);
1038
1044extern int usbg_disable_gadget(usbg_gadget *g);
1045
1054extern const char *usbg_get_udc_name(usbg_udc *u);
1055
1065extern int usbg_get_udc_name_s(usbg_udc *u, char *buf, int len);
1066
1073
1080
1085#define usbg_for_each_gadget(g, s) \
1086 for (g = usbg_get_first_gadget(s); \
1087 g != NULL; \
1088 g = usbg_get_next_gadget(g))
1089
1094#define usbg_for_each_function(f, g) \
1095 for (f = usbg_get_first_function(g); \
1096 f != NULL; \
1097 f = usbg_get_next_function(f))
1098
1103#define usbg_for_each_config(c, g) \
1104 for (c = usbg_get_first_config(g); \
1105 c != NULL; \
1106 c = usbg_get_next_config(c))
1107
1112#define usbg_for_each_binding(b, c) \
1113 for (b = usbg_get_first_binding(c); \
1114 b != NULL; \
1115 b = usbg_get_next_binding(b))
1116
1121#define usbg_for_each_udc(u, s) \
1122 for (u = usbg_get_first_udc(s); \
1123 u != NULL; \
1124 u = usbg_get_next_udc(u))
1125
1133
1141
1149
1157
1165
1172
1179
1186
1193
1200
1201/* Import / Export API */
1202
1209extern int usbg_export_function(usbg_function *f, FILE *stream);
1210
1217extern int usbg_export_config(usbg_config *c, FILE *stream);
1218
1225extern int usbg_export_gadget(usbg_gadget *g, FILE *stream);
1226
1236extern int usbg_import_function(usbg_gadget *g, FILE *stream,
1237 const char *instance, usbg_function **f);
1238
1248extern int usbg_import_config(usbg_gadget *g, FILE *stream, int id,
1249 usbg_config **c);
1250
1260extern int usbg_import_gadget(usbg_state *s, FILE *stream,
1261 const char *name, usbg_gadget **g);
1262
1268extern const char *usbg_get_func_import_error_text(usbg_gadget *g);
1269
1276
1282extern const char *usbg_get_config_import_error_text(usbg_gadget *g);
1283
1290
1296extern const char *usbg_get_gadget_import_error_text(usbg_state *s);
1297
1304
1309#ifdef __cplusplus
1310}
1311#endif
1312
1313#endif /* __USBG_H__ */
const char * usbg_get_binding_name(usbg_binding *b)
Get binding name.
Definition usbg.c:2441
int usbg_get_config_strs(usbg_config *c, int lang, struct usbg_config_strs *c_strs)
Get the USB configuration strings.
Definition usbg.c:2324
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:1527
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:1776
usbg_function * usbg_get_function(usbg_gadget *g, usbg_function_type type, const char *instance)
Get a function by name.
Definition usbg.c:1160
int usbg_get_config_strs_langs(usbg_config *c, int **langs)
Get the array of languages available in this config.
Definition usbg.c:1858
usbg_config * usbg_get_config(usbg_gadget *g, int id, const char *label)
Get a configuration by name.
Definition usbg.c:1172
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:1488
int usbg_rm_gadget_strs(usbg_gadget *g, int lang)
Remove gadget strings for given language.
Definition usbg.c:1418
const char * usbg_get_config_label(usbg_config *c)
Get config label.
Definition usbg.c:2252
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:2436
int usbg_set_gadget_product(usbg_gadget *g, int lang, const char *prd)
Set the product name for a gadget.
Definition usbg.c:1980
const char * usbg_get_udc_name(usbg_udc *u)
Get name of udc.
Definition usbg.c:1593
int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, const char *ser)
Set the serial number for a gadget.
Definition usbg.c:1932
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:112
int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, const char *mnf)
Set the manufacturer name for a gadget.
Definition usbg.c:1956
int usbg_rm_gadget(usbg_gadget *g, int opts)
Remove existing USB gadget.
Definition usbg.c:1345
int usbg_set_function_attrs(usbg_function *f, void *f_attrs)
Set attributes of given function.
Definition usbg.c:2610
int usbg_get_config_label_s(usbg_config *c, char *buf, int len)
Get config label into user buffer.
Definition usbg.c:2257
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:1149
int usbg_rm_config_strs(usbg_config *c, int lang)
Remove configuration strings for given language.
Definition usbg.c:1399
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:1895
int usbg_rm_function(usbg_function *f, int opts)
Remove existing USB function.
Definition usbg.c:1296
int usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
Set the USB gadget protocol code.
Definition usbg.c:1764
int usbg_lookup_gadget_attr(const char *name)
Lookup attr code based on its name.
Definition usbg.c:135
int usbg_set_config_max_power(usbg_config *c, int bMaxPower)
Set the configuration maximum power.
Definition usbg.c:2312
usbg_binding * usbg_get_first_binding(usbg_config *c)
Get first binding in binding list.
Definition usbg.c:2635
usbg_function * usbg_get_first_function(usbg_gadget *g)
Get first function in function list.
Definition usbg.c:2625
usbg_function * usbg_get_next_function(usbg_function *f)
Get the next function on a list.
Definition usbg.c:2650
int usbg_get_gadget_attrs(usbg_gadget *g, struct usbg_gadget_attrs *g_attrs)
Get the USB gadget strings.
Definition usbg.c:1573
int usbg_add_config_function(usbg_config *c, const char *name, usbg_function *f)
Add a function to a configuration.
Definition usbg.c:2363
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:2331
int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
Set the USB gadget vendor id.
Definition usbg.c:1746
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:2645
usbg_error
Errors which could be returned by library functions.
Definition usbg.h:240
int usbg_set_gadget_attr(usbg_gadget *g, usbg_gadget_attr attr, int val)
Set selected attribute to value.
Definition usbg.c:1607
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:2145
usbg_udc * usbg_get_next_udc(usbg_udc *u)
Get the next udc on a list.
Definition usbg.c:2665
int usbg_set_gadget_attrs(usbg_gadget *g, const struct usbg_gadget_attrs *g_attrs)
Set the USB gadget attributes.
Definition usbg.c:1698
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:2620
int usbg_get_config_id(usbg_config *c)
Get config id.
Definition usbg.c:2266
int usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
Set the gadget device BCD release number.
Definition usbg.c:1782
const char * usbg_get_configfs_path(usbg_state *s)
Get ConfigFS path.
Definition usbg.c:1136
usbg_udc * usbg_get_first_udc(usbg_state *s)
Get first udc in udc list.
Definition usbg.c:2640
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:1598
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:2593
usbg_config * usbg_get_first_config(usbg_gadget *g)
Get first config in config list.
Definition usbg.c:2630
int usbg_get_configfs_path_s(usbg_state *s, char *buf, int len)
Get ConfigFS path into user buffer.
Definition usbg.c:1141
int usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
Set the USB gadget device class code.
Definition usbg.c:1758
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:2110
int usbg_get_function_instance_s(usbg_function *f, char *buf, int len)
Get function instance name into user buffer.
Definition usbg.c:2276
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:2174
int usbg_enable_gadget(usbg_gadget *g, usbg_udc *udc)
Enable a USB gadget device.
Definition usbg.c:2543
int usbg_rm_config(usbg_config *c, int opts)
Remove configuration.
Definition usbg.c:1242
usbg_config * usbg_get_os_desc_binding(usbg_gadget *g)
Get configuration selected for OS Descriptors.
Definition usbg.c:1237
int usbg_set_config_attrs(usbg_config *c, const struct usbg_config_attrs *c_attrs)
Set the USB configuration attributes.
Definition usbg.c:2284
int usbg_lookup_gadget_str(const char *name)
Lookup str code based on its name.
Definition usbg.c:151
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:2004
const char * usbg_get_gadget_os_desc_name(usbg_gadget_os_desc_strs str)
Get name of selected OS Descriptor string.
Definition usbg.c:181
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:1086
usbg_udc * usbg_get_gadget_udc(usbg_gadget *g)
Get udc to which gadget is bound.
Definition usbg.c:1643
int usbg_get_gadget_name_s(usbg_gadget *g, char *buf, int len)
Get gadget name into user buffer.
Definition usbg.c:1585
const char * usbg_get_gadget_name(usbg_gadget *g)
Get gadget name.
Definition usbg.c:1580
const char * usbg_get_gadget_attr_str(usbg_gadget_attr attr)
Get string representing selected gadget attribute.
Definition usbg.c:167
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:2271
int usbg_rm_binding(usbg_binding *b)
Remove binding between configuration and function.
Definition usbg.c:1216
int usbg_set_config_string(usbg_config *c, int lang, const char *string)
Set the configuration string.
Definition usbg.c:2337
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition usbg.c:1131
usbg_udc * usbg_get_udc(usbg_state *s, const char *name)
Get a udc by name.
Definition usbg.c:1183
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:1673
int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang, const char *val)
Set selected string.
Definition usbg.c:1863
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:2571
int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
Set the configuration bitmap attributes.
Definition usbg.c:2318
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:2046
int usbg_set_os_desc_config(usbg_gadget *g, usbg_config *c)
Set configuration for OS Descriptors.
Definition usbg.c:2522
void usbg_cleanup_function_attrs(usbg_function *f, void *f_attrs)
Cleanup content of function attributes.
Definition usbg.c:2604
usbg_binding * usbg_get_next_binding(usbg_binding *b)
Get the next binding on a list.
Definition usbg.c:2660
const char * usbg_get_function_type_str(usbg_function_type type)
Get function type as a string.
Definition usbg.c:128
int usbg_get_config_attrs(usbg_config *c, struct usbg_config_attrs *c_attrs)
Get the USB configuration strings.
Definition usbg.c:2305
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:1625
int usbg_get_function_attrs(usbg_function *f, void *f_attrs)
Get attributes of given function.
Definition usbg.c:2598
int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs)
Get the array of languages available in this gadget.
Definition usbg.c:1853
int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
Set the USB gadget product id.
Definition usbg.c:1752
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:2011
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:1794
int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
Set the gadget device BCD USB version.
Definition usbg.c:1788
const char * usbg_get_gadget_str_name(usbg_gadget_str str)
Get name of selected gadget string.
Definition usbg.c:174
usbg_config * usbg_get_next_config(usbg_config *c)
Get the next config on a list.
Definition usbg.c:2655
int usbg_get_binding_name_s(usbg_binding *b, char *buf, int len)
Get binding name into user buffer.
Definition usbg.c:2446
int usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
Set the USB gadget device subclass code.
Definition usbg.c:1770
USB configuration attributes.
Definition usbg.h:187
USB configuration strings.
Definition usbg.h:196
USB OS Descriptor function attributes.
Definition usbg.h:229
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