summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usbg/usbg.h16
-rw-r--r--src/usbg.c82
2 files changed, 98 insertions, 0 deletions
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 82eaef3..6fee7e1 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -182,6 +182,7 @@ typedef enum
F_PHONET,
F_FFS,
F_MASS_STORAGE,
+ F_MIDI,
USBG_FUNCTION_TYPE_MAX,
} usbg_function_type;
@@ -246,6 +247,19 @@ typedef struct {
} usbg_f_ms_attrs;
/**
+ * @typedef usbg_f_midi_attrs
+ * @brief Attributes for the MIDI function
+ */
+typedef struct {
+ int index;
+ const char *id;
+ unsigned int in_ports;
+ unsigned int out_ports;
+ unsigned int buflen;
+ unsigned int qlen;
+} usbg_f_midi_attrs;
+
+/**
* @typedef attrs
* @brief Attributes for a given function type
*/
@@ -255,6 +269,7 @@ typedef union {
usbg_f_phonet_attrs phonet;
usbg_f_ffs_attrs ffs;
usbg_f_ms_attrs ms;
+ usbg_f_midi_attrs midi;
} usbg_f_attrs;
typedef enum {
@@ -263,6 +278,7 @@ typedef enum {
USBG_F_ATTRS_PHONET,
USBG_F_ATTRS_FFS,
USBG_F_ATTRS_MS,
+ USBG_F_ATTRS_MIDI,
} usbg_f_attrs_type;
typedef struct {
diff --git a/src/usbg.c b/src/usbg.c
index 3a2700e..61027e3 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -51,6 +51,7 @@ const char *function_names[] =
"phonet",
"ffs",
"mass_storage",
+ "midi",
};
ARRAY_SIZE_SENTINEL(function_names, USBG_FUNCTION_TYPE_MAX);
@@ -252,6 +253,9 @@ int usbg_lookup_function_attrs_type(int f_type)
case F_MASS_STORAGE:
ret = USBG_F_ATTRS_MS;
break;
+ case F_MIDI:
+ ret = USBG_F_ATTRS_MIDI;
+ break;
default:
ret = USBG_ERROR_NOT_SUPPORTED;
}
@@ -1051,6 +1055,39 @@ out:
return ret;
}
+static int usbg_parse_function_midi_attrs(usbg_function *f,
+ usbg_f_midi_attrs *attrs)
+{
+ int ret;
+
+ ret = usbg_read_dec(f->path, f->name, "index", &(attrs->index));
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_string_alloc(f->path, f->name, "id", &(attrs->id));
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_dec(f->path, f->name, "in_ports", (int*)&(attrs->in_ports));
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_dec(f->path, f->name, "out_ports", (int*)&(attrs->out_ports));
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_dec(f->path, f->name, "buflen", (int*)&(attrs->buflen));
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_read_dec(f->path, f->name, "qlen", (int*)&(attrs->qlen));
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+out:
+ return ret;
+}
+
static int usbg_parse_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
{
@@ -1099,6 +1136,11 @@ static int usbg_parse_function_attrs(usbg_function *f,
ret = usbg_parse_function_ms_attrs(f, &(f_attrs->attrs.ms));
break;
+ case USBG_F_ATTRS_MIDI:
+ f_attrs->header.attrs_type = USBG_F_ATTRS_MIDI;
+ ret = usbg_parse_function_midi_attrs(f, &(f_attrs->attrs.midi));
+ break;
+
default:
ERROR("Unsupported function type\n");
ret = USBG_ERROR_NOT_SUPPORTED;
@@ -2922,6 +2964,11 @@ void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs)
break;
}
+ case USBG_F_ATTRS_MIDI:
+ free((char*)attrs->midi.id);
+ attrs->midi.id = NULL;
+ break;
+
default:
ERROR("Unsupported attrs type\n");
break;
@@ -3123,6 +3170,37 @@ out:
return ret;
}
+int usbg_set_function_midi_attrs(usbg_function *f,
+ const usbg_f_midi_attrs *attrs)
+{
+ int ret;
+
+ ret = usbg_write_dec(f->path, f->name, "index", attrs->index);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_string(f->path, f->name, "id", attrs->id);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_dec(f->path, f->name, "in_ports", attrs->in_ports);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_dec(f->path, f->name, "out_ports", attrs->out_ports);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_dec(f->path, f->name, "buflen", attrs->buflen);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_dec(f->path, f->name, "qlen", attrs->qlen);
+
+out:
+ return ret;
+}
+
int usbg_set_function_attrs(usbg_function *f,
const usbg_function_attrs *f_attrs)
{
@@ -3170,6 +3248,10 @@ int usbg_set_function_attrs(usbg_function *f,
ret = usbg_set_function_ms_attrs(f, &f_attrs->attrs.ms);
break;
+ case USBG_F_ATTRS_MIDI:
+ ret = usbg_set_function_midi_attrs(f, &f_attrs->attrs.midi);
+ break;
+
default:
ERROR("Unsupported function type\n");
ret = USBG_ERROR_NOT_SUPPORTED;