diff --git a/wireless/wifictld/src/ubus.c b/wireless/wifictld/src/ubus.c index 7898ae9..301081f 100644 --- a/wireless/wifictld/src/ubus.c +++ b/wireless/wifictld/src/ubus.c @@ -6,6 +6,7 @@ #include "ubus_events.h" #include "ubus_service.h" +#define UBUS_SOCKET "/var/run/ubus.sock" static struct ubus_context *ctx; @@ -18,7 +19,7 @@ int wifictld_ubus_init() int ret = 0; // connect to ubus - ctx = ubus_connect(NULL); + ctx = ubus_connect(UBUS_SOCKET); if (!ctx) { log_error("Failed to connect to ubus"); return 1; diff --git a/wireless/wifictld/src/ubus_events.c b/wireless/wifictld/src/ubus_events.c index 3ae2774..a968457 100644 --- a/wireless/wifictld/src/ubus_events.c +++ b/wireless/wifictld/src/ubus_events.c @@ -11,8 +11,6 @@ bool client_probe_steering = true; // steering contains learning already bool client_probe_learning = false; -static struct blob_buf b; - // bind on every hostapd by receive all ubus registered services static void recieve_interfaces(struct ubus_context *ctx, struct ubus_object_data *obj, void *priv); @@ -34,10 +32,8 @@ struct ubus_subscriber sub = { */ int wifictld_ubus_bind_events(struct ubus_context *ctx) { - int ret = 0; - // register subscriber on ubus - ret = ubus_register_subscriber(ctx, &sub); + int ret = ubus_register_subscriber(ctx, &sub); if (ret) { log_error("Error while registering subscriber: %s", ubus_strerror(ret)); ubus_free(ctx); @@ -61,22 +57,29 @@ static void recieve_interfaces(struct ubus_context *ctx, struct ubus_object_data if (lenpath < lenpre || strncmp(path_prefix, obj->path, lenpre) != 0) { return; } + char *path = malloc((lenpath+1) * sizeof(char)); + strncpy(path, obj->path, lenpath); + path[lenpath] = '\0'; //change hostapd to wait for response + struct blob_buf b = {}; blob_buf_init(&b, 0); blobmsg_add_u32(&b, str, 1); ret = ubus_invoke(ctx, obj->id, str, b.head, NULL, NULL, 100); + + blob_buf_free(&b); + if (ret) { - log_error("Error while register response for event '%s': %s\n", obj->path, ubus_strerror(ret)); + log_error("Error while register response for event '%s': %s\n", path, ubus_strerror(ret)); } //subscribe hostapd with THIS interface ret = ubus_subscribe(ctx, &sub, obj->id); if (ret) { - log_error("Error while register subscribe for event '%s': %s\n", obj->path, ubus_strerror(ret)); + log_error("Error while register subscribe for event '%s': %s\n", path, ubus_strerror(ret)); } - log_info("subscribe %s: %d:%d\n", obj->path, obj->id, obj->type_id); + log_info("subscribe %s\n", path); } diff --git a/wireless/wifictld/src/ubus_service.c b/wireless/wifictld/src/ubus_service.c index bea8dfa..fe1a7d8 100644 --- a/wireless/wifictld/src/ubus_service.c +++ b/wireless/wifictld/src/ubus_service.c @@ -5,7 +5,7 @@ #include "wifi_clients.h" #include "ubus_events.h" -static struct blob_buf b; +static struct blob_buf b = {}; static int ubus_get_clients(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)