Loading...
Searching...
No Matches
usbg_internal.h File Reference
`#include <sys/queue.h>`
`#include <string.h>`
`#include <usbg/usbg.h>`
`#include <malloc.h>`
`#include <sys/types.h>`
`#include "usbg_internal_none.h"`

Go to the source code of this file.

## Data Structures

struct | usbg_function_type
struct | usbg_state
struct | usbg_gadget
struct | usbg_config
struct | usbg_function
struct | usbg_binding
struct | usbg_udc

## Macros

#define | offsetof(type, member)
#define | container_of(ptr, type, field)
#define | USBG_MAX_PATH_LENGTH PATH_MAX
#define | USBG_MAX_FILE_SIZE 4096
#define | ARRAY_SIZE(array)
#define | ARRAY_SIZE_SENTINEL(array, size)
#define | ERROR(msg, ...)
#define | ERRORNO(msg, ...)
#define | INSERT_TAILQ_STRING_ORDER(HeadPtr, HeadType, NameField, ToInsert, NodeField)
#define | STRINGS_DIR "strings"
#define | CONFIGS_DIR "configs"
#define | FUNCTIONS_DIR "functions"
#define | GADGETS_DIR "usb_gadget"
#define | OS_DESC_DIR "os_desc"
#define | usbg_read_dec(p, n, f, d)
#define | usbg_read_hex(p, n, f, d)
#define | usbg_write_dec(p, n, f, v)
#define | usbg_write_hex(p, n, f, v)
#define | usbg_write_hex16(p, n, f, v)
#define | usbg_write_hex8(p, n, f, v)
#define | usbg_write_bool(p, n, f, v)
#define | usbg_config_is_int(node)
#define | usbg_config_is_string(node)
#define | GENERIC_ALLOC_INST(prefix, _type, _member)
#define | GENERIC_FREE_INST(prefix, _type, _member)

## Typedefs

typedef int(* | usbg_attr_get_func) (const char *, const char *, const char *, void *)
typedef int(* | usbg_attr_set_func) (const char *, const char *, const char *, void *)
typedef int(* | usbg_import_node_func) (config_setting_t *root, const char *node_name, void *val)
typedef int(* | usbg_export_node_func) (config_setting_t *root, const char *node_name, void *val)

## Functions

int | usbg_translate_error (int error)
char * | usbg_ether_ntoa_r (const struct ether_addr *addr, char *buf)
int | usbg_read_buf (const char *path, const char *name, const char *file, char *buf)
int | usbg_read_buf_limited (const char *path, const char *name, const char *file, char *buf, int len)
int | usbg_read_int (const char *path, const char *name, const char *file, int base, int *dest)
int | usbg_read_bool (const char *path, const char *name, const char *file, bool *dest)
int | usbg_read_string (const char *path, const char *name, const char *file, char *buf)
int | usbg_read_string_limited (const char *path, const char *name, const char *file, char *buf, int len)
int | usbg_read_string_alloc (const char *path, const char *name, const char *file, char **dest)
int | usbg_read_buf_alloc (const char *path, const char *name, const char *file, char **dest, int len)
int | usbg_write_buf (const char *path, const char *name, const char *file, const char *buf, int len)
int | usbg_write_int (const char *path, const char *name, const char *file, int value, const char *str)
int | usbg_write_string (const char *path, const char *name, const char *file, const char *buf)
int | usbg_rm_file (const char *path, const char *name)
int | usbg_rm_dir (const char *path, const char *name)
int | usbg_rm_all_dirs (const char *path)
int | usbg_check_dir (const char *path)
int | usbg_init_function (struct usbg_function *f, struct usbg_function_type *ops, usbg_function_type type, const char *type_name, const char *instance, const char *path, struct usbg_gadget *parent)
void | usbg_cleanup_function (struct usbg_function *f)
int | usbg_get_ether_addr (const char *path, const char *name, const char *attr, void *val)
int | usbg_set_ether_addr (const char *path, const char *name, const char *attr, void *val)
int | usbg_get_dev (const char *path, const char *name, const char *attr, void *val)
int | usbg_write_guid (const char *path, const char *name, const char *file, const char *buf)

## Data Structure Documentation

## usbg_function_type

struct usbg_function_type

Examples
  show-gadgets.c.

Data Fields
int(*)(struct usbg_function_type *, usbg_function_type, const char *, const char *, usbg_gadget *, struct usbg_function **) | alloc_inst |
void(*)(struct usbg_function *, void *) | cleanup_attrs |
int(*)(struct usbg_function *, config_setting_t *) | export |
void(*)(struct usbg_function_type *, struct usbg_function *) | free_inst |
int(*)(struct usbg_function *, void *) | get_attrs |
int(*)(struct usbg_function *, config_setting_t *) | import |
char * | name |
char ** | os_desc_iname |
int(*)(struct usbg_function *, int) | remove |
int(*)(struct usbg_function *, void *) | set_attrs |

## Macro Definition Documentation

## ARRAY_SIZE

#define ARRAY_SIZE | ( |  | array | ) |

Value:
(sizeof(array)/sizeof(*array))

## ARRAY_SIZE_SENTINEL

#define ARRAY_SIZE_SENTINEL | ( |  | array,
|  |  | size )

Value:
static void __attribute__ ((unused)) array##_size_sentinel() \
{ \
char array##_smaller_than_expected[ \
(int)(ARRAY_SIZE(array) - size)] \
__attribute__ ((unused)); \
\
char array##_larger_than_expected[ \
(int)(size - ARRAY_SIZE(array))] \
__attribute__ ((unused)); \
}

## container_of

#define container_of | ( |  | ptr,
|  |  | type,
|  |  | field )

Value:
({ \
const typeof(((type *)0)->field) *member = (ptr); \
(type *)( (char *)member - offsetof(type, field) ); \
})

## ERROR

#define ERROR | ( |  | msg,
|  |  | ... )

Value:
do {\
fprintf(stderr, "%s() "msg" \n", \
__func__, ##__VA_ARGS__);\
fflush(stderr);\
} while (0)

## ERRORNO

#define ERRORNO | ( |  | msg,
|  |  | ... )

Value:
do {\
fprintf(stderr, "%s() %s: "msg" \n", \
__func__, strerror(errno), ##__VA_ARGS__);\
fflush(stderr);\
} while (0)

## GENERIC_ALLOC_INST

#define GENERIC_ALLOC_INST | ( |  | prefix,
|  |  | _type,
|  |  | _member )

Value:
static int prefix##_alloc_inst(struct usbg_function_type *type, \
usbg_function_type type_code, \
const char *instance, const char *path, \
struct usbg_gadget *parent, \
struct usbg_function **f) \
{ \
_type *ff; \
int ret; \
\
ff = malloc(sizeof(*ff)); \
if (!ff) \
return USBG_ERROR_NO_MEM; \
\
ret = usbg_init_function(&ff->_member, type, type_code, \
type->name, instance, path, parent); \
if (ret != USBG_SUCCESS) \
goto free_func; \
\
*f = &ff->_member; \
\
return ret; \
\
free_func: \
free(ff); \
return ret; \
}
usbg_function
Definition usbg_internal.h:129
usbg_gadget
Definition usbg_internal.h:103
usbg_function_type
Definition usbg_internal.h:51

## GENERIC_FREE_INST

#define GENERIC_FREE_INST | ( |  | prefix,
|  |  | _type,
|  |  | _member )

Value:
static void prefix##_free_inst(struct usbg_function_type *type, \
struct usbg_function *f) \
{ \
_type *ff = container_of(f, _type, _member); \
\
usbg_cleanup_function(&ff->_member); \
free(ff); \
}

## INSERT_TAILQ_STRING_ORDER

#define INSERT_TAILQ_STRING_ORDER | ( |  | HeadPtr,
|  |  | HeadType,
|  |  | NameField,
|  |  | ToInsert,
|  |  | NodeField )

Value:
do { \
if (TAILQ_EMPTY((HeadPtr)) || \
(strcmp((ToInsert)->NameField, TAILQ_FIRST((HeadPtr))->NameField) < 0)) \
TAILQ_INSERT_HEAD((HeadPtr), (ToInsert), NodeField); \
else if (strcmp((ToInsert)->NameField, TAILQ_LAST((HeadPtr), HeadType)->NameField) > 0) \
TAILQ_INSERT_TAIL((HeadPtr), (ToInsert), NodeField); \
else { \
typeof(ToInsert) _cur; \
TAILQ_FOREACH(_cur, (HeadPtr), NodeField) { \
if (strcmp((ToInsert)->NameField, _cur->NameField) > 0) \
continue; \
TAILQ_INSERT_BEFORE(_cur, (ToInsert), NodeField); \
break; \
} \
} \
} while (0)

## offsetof

#define offsetof | ( |  | type,
|  |  | member )

Value:
__builtin_offsetof (type, member)

## usbg_config_is_int

#define usbg_config_is_int | ( |  | node | ) |

Value:
(config_setting_type(node) == CONFIG_TYPE_INT)

## usbg_config_is_string

#define usbg_config_is_string | ( |  | node | ) |

Value:
(config_setting_type(node) == CONFIG_TYPE_STRING)

## usbg_read_dec

#define usbg_read_dec | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | d )

Value:
usbg_read_int(p, n, f, 10, d)

## usbg_read_hex

#define usbg_read_hex | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | d )

Value:
usbg_read_int(p, n, f, 16, d)

## usbg_write_bool

#define usbg_write_bool | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | v )

Value:
usbg_write_dec(p, n, f, !!v)

## usbg_write_dec

#define usbg_write_dec | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | v )

Value:
usbg_write_int(p, n, f, v, "%d\n")

## usbg_write_hex

#define usbg_write_hex | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | v )

Value:
usbg_write_int(p, n, f, v, "0x%x\n")

## usbg_write_hex16

#define usbg_write_hex16 | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | v )

Value:
usbg_write_int(p, n, f, v, "0x%04x\n")

## usbg_write_hex8

#define usbg_write_hex8 | ( |  | p,
|  |  | n,
|  |  | f,
|  |  | v )

Value:
usbg_write_int(p, n, f, v, "0x%02x\n")