hostapd: fix ubus reconnect handling
[openwrt/staging/yousong.git] / package / network / services / hostapd / patches / 700-ubus_support.patch
index c5ff795233fd952889ba211fb69cea408917c12d..c1759c8fb8e085d328fe00465f74dfc49a989556 100644 (file)
@@ -40,7 +40,7 @@
        struct hostapd_data **bss;
 --- /dev/null
 +++ b/src/ap/ubus.c
-@@ -0,0 +1,356 @@
+@@ -0,0 +1,373 @@
 +/*
 + * hostapd / ubus support
 + * Copyright (c) 2013, Felix Fietkau <nbd@openwrt.org>
 +      ubus_handle_event(ctx);
 +}
 +
++static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
++{
++      if (ubus_reconnect(ctx, NULL)) {
++              eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
++              return;
++      }
++
++      eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
++}
++
++static void hostapd_ubus_connection_lost(struct ubus_context *ctx)
++{
++      eloop_unregister_read_sock(ctx->sock.fd);
++      eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
++}
++
 +static bool hostapd_ubus_init(void)
 +{
 +      if (ctx)
@@ -81,6 +97,7 @@
 +      if (!ctx)
 +              return false;
 +
++      ctx->connection_lost = hostapd_ubus_connection_lost;
 +      eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
 +      return true;
 +}
 +#endif
 --- a/src/ap/hostapd.c
 +++ b/src/ap/hostapd.c
-@@ -270,6 +270,7 @@ static int hostapd_broadcast_wep_set(str
+@@ -241,6 +241,7 @@ static int hostapd_broadcast_wep_set(str
  
  static void hostapd_free_hapd_data(struct hostapd_data *hapd)
  {
        iapp_deinit(hapd->iapp);
        hapd->iapp = NULL;
        accounting_deinit(hapd);
-@@ -834,6 +835,8 @@ static int hostapd_setup_bss(struct host
+@@ -806,6 +807,8 @@ static int hostapd_setup_bss(struct host
        if (hapd->driver && hapd->driver->set_operstate)
                hapd->driver->set_operstate(hapd->drv_priv, 1);
  
        return 0;
  }
  
-@@ -984,6 +987,7 @@ int hostapd_setup_interface_complete(str
+@@ -956,6 +959,7 @@ int hostapd_setup_interface_complete(str
        if (err)
                goto error;
  
        wpa_printf(MSG_DEBUG, "Completing interface initialization");
        if (hapd->iconf->channel) {
                iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
-@@ -1076,6 +1080,7 @@ int hostapd_setup_interface_complete(str
+@@ -1048,6 +1052,7 @@ int hostapd_setup_interface_complete(str
  
  error:
        wpa_printf(MSG_ERROR, "Interface initialization failed");
        eloop_terminate();
        return -1;
  }
-@@ -1174,6 +1179,8 @@ void hostapd_interface_deinit_free(struc
+@@ -1146,6 +1151,8 @@ void hostapd_interface_deinit_free(struc
        void *drv_priv;
        if (iface == NULL)
                return;