From 32128116c3988421d801264f261501e6ca00d3bf Mon Sep 17 00:00:00 2001
From: Pawel Szewczyk
Date: Mon, 7 Sep 2015 12:50:44 +0200
Subject: [PATCH] config: Add config del command at libusbg backend
Change-Id: Iad8c91119093d48b85a6354ee360a4e49d07701f
Signed-off-by: Pawel Szewczyk
---
source/config/src/configuration_libusbg.c | 52 ++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/source/config/src/configuration_libusbg.c b/source/config/src/configuration_libusbg.c
index 4c51e22..c9262a6 100644
--- a/source/config/src/configuration_libusbg.c
+++ b/source/config/src/configuration_libusbg.c
@@ -109,6 +109,56 @@ static int add_func(void *data)
return 0;
}
+static int del_func(void *data)
+{
+ int usbg_ret = USBG_SUCCESS;
+ usbg_binding *b, *found = NULL;
+ usbg_config *c;
+ usbg_gadget *g;
+ usbg_function *f;
+ struct gt_config_add_del_data *dt;
+
+ dt = (struct gt_config_add_del_data *)data;
+
+ g = usbg_get_gadget(backend_ctx.libusbg_state, dt->gadget);
+ if (g == NULL) {
+ fprintf(stderr, "Unable to get gadget\n");
+ return -1;
+ }
+
+ c = usbg_get_config(g, dt->config_id, dt->config_label);
+ if (c == NULL) {
+ fprintf(stderr, "Unable to get config\n");
+ return -1;
+ }
+
+ usbg_for_each_binding(b, c) {
+ f = usbg_get_binding_target(b);
+ if (f == NULL) {
+ fprintf(stderr, "Unable to get binding target\n");
+ return -1;
+ }
+
+ if (strcmp(usbg_get_function_type_str(usbg_get_function_type(f)), dt->type) == 0 &&
+ strcmp(usbg_get_function_instance(f), dt->instance) == 0) {
+ found = b;
+ break;
+ }
+ }
+
+ if (found) {
+ usbg_ret = usbg_rm_binding(found);
+ if (usbg_ret != USBG_SUCCESS) {
+ fprintf(stderr, "Error removing binding\n");
+ return -1;
+ }
+ } else {
+ fprintf(stderr, "Function not found in given config\n");
+ }
+
+ return 0;
+}
+
int gt_print_config_libusbg(usbg_config *c, int opts)
{
usbg_binding *b;
@@ -270,7 +320,7 @@ struct gt_config_backend gt_config_backend_libusbg = {
.get = NULL,
.set = NULL,
.show = show_func,
- .del = NULL,
+ .del = del_func,
.template_default = NULL,
.template_get = NULL,
.template_set = NULL,
--
2.7.4