changeset 411:dadccf117097

fix segfault, fix discovery add a lifx workaround that doesn't seem to be worth it (that LIFX/QCA firmware is really broken)
author Louis Opter <kalessin@kalessin.fr>
date Thu, 31 Dec 2015 15:34:49 +0100
parents 1830822a9f63
children 65b0dc335243
files add_power_transition.patch network_discovery.patch open_gateway_on_any_bulb_response.patch series
diffstat 4 files changed, 73 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/add_power_transition.patch	Thu Dec 31 10:27:59 2015 +0100
+++ b/add_power_transition.patch	Thu Dec 31 15:34:49 2015 +0100
@@ -1,5 +1,5 @@
 # HG changeset patch
-# Parent  dfd2e5cf185c1db0f2072f78528a8d4cf0118043
+# Parent  1e86f3c192de24d85edf916e1dc2bad85a578c33
 Add a transition argument to the power functions
 
 diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -533,7 +533,7 @@
  #include "lightsd.h"
  
  struct lgtd_opts lgtd_opts = {
-@@ -181,6 +182,7 @@
+@@ -188,6 +189,7 @@
      lgtd_listen_close_all();
      lgtd_command_pipe_close_all();
      lgtd_client_close_all();
@@ -849,7 +849,7 @@
 new file mode 100644
 --- /dev/null
 +++ b/effects/power_transition.c
-@@ -0,0 +1,305 @@
+@@ -0,0 +1,303 @@
 +// Copyright (c) 2015, Louis Opter <kalessin@kalessin.fr>
 +//
 +// This file is part of lighstd.
@@ -1019,10 +1019,8 @@
 +        lgtd_effect_power_transition_off_power_off(&ctx->targets);
 +        break;
 +    default:
-+#ifndef NDEBUG
-+        lgtd_warnx("%s called with apply_cnt=%d", __func__, effect->apply_cnt);
-+        abort();
-+#endif
++        // we'll end up there if the transition was less long than
++        // LGTD_EFFECT_POWER_TRANSITION_OFF_RESTORE_LIGHT_COLOR_DELAY_MSECS
 +        break;
 +    }
 +}
--- a/network_discovery.patch	Thu Dec 31 10:27:59 2015 +0100
+++ b/network_discovery.patch	Thu Dec 31 15:34:49 2015 +0100
@@ -1,5 +1,5 @@
 # HG changeset patch
-# Parent  2f53e91d85172265ef669ad34b90677f25e25d43
+# Parent  722eaeb15d6f8eeffa3750987c72e9e1c0146215
 Properly broadcast LIFX discovery packets on all networks (closes GH-2)
 
 It does solve the issue but only is half the solution I'd like to have.
@@ -91,7 +91,7 @@
      struct lgtd_lifx_packet_header get_pan_gateway;
      lgtd_lifx_wire_setup_header(
          &get_pan_gateway,
-@@ -70,31 +92,56 @@
+@@ -70,31 +92,57 @@
          LGTD_LIFX_GET_PAN_GATEWAY
      );
  
@@ -145,9 +145,10 @@
 +                } else {
 +                    continue;
 +                }
-+                ok = ok || lgtd_lifx_broadcast_send_packet(
++                bool sent = lgtd_lifx_broadcast_send_packet(
 +                    &get_pan_gateway, sizeof(get_pan_gateway), addr, addrlen
 +                );
++                ok = sent || ok;
 +            }
          }
 -        return true;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open_gateway_on_any_bulb_response.patch	Thu Dec 31 15:34:49 2015 +0100
@@ -0,0 +1,63 @@
+# HG changeset patch
+# Parent  be66b2a6fedcf92e4c9bc27592c034f108a9febe
+Discover bulbs lazily on top of the regular discovery process
+
+By instantiating LIFX gateways on any kind of bulb response and not
+just on PAN_GATEWAY packets.
+
+diff --git a/lifx/gateway.c b/lifx/gateway.c
+--- a/lifx/gateway.c
++++ b/lifx/gateway.c
+@@ -123,10 +123,15 @@
+         assert(!memcmp(peer, gw->peer, addrlen));
+     } else {
+         gw = lgtd_lifx_gateway_get(peer, addrlen);
+-        if (!gw && hdr->packet_type == LGTD_LIFX_PAN_GATEWAY) {
++        // We should only open a new gateway on a LGTD_LIFX_PAN_GATEWAY packet
++        // but it looks like non-original bulbs aren't sending it sometimes, so
++        // let's lazily open a new gateway on any bulb response. Bulb responses
++        // are identified by a missing encode function (lightsd can receive
++        // broadcast traffic from other clients):
++        if (!gw && !pkt_info->encode) {
+             gw = lgtd_lifx_gateway_open(peer, addrlen, hdr->site, received_at);
+             if (!gw) {
+-                lgtd_warn("can't allocate gateway");
++                lgtd_warn("can't allocate a new gateway");
+                 return;
+             }
+         }
+diff --git a/lifx/wire_proto.c b/lifx/wire_proto.c
+--- a/lifx/wire_proto.c
++++ b/lifx/wire_proto.c
+@@ -112,7 +112,7 @@
+ #define NO_PAYLOAD                                          \
+     .encode = lgtd_lifx_wire_null_packet_encoder_decoder
+ #define RESPONSE_ONLY                                       \
+-    .encode = lgtd_lifx_wire_null_packet_encoder_decoder
++    .encode = NULL
+ #define REQUEST_ONLY                                        \
+     .decode = lgtd_lifx_wire_null_packet_encoder_decoder,   \
+     .handle = lgtd_lifx_wire_null_packet_handler
+@@ -134,7 +134,6 @@
+             .type = LGTD_LIFX_PAN_GATEWAY,
+             .size = sizeof(struct lgtd_lifx_packet_pan_gateway),
+             .decode = DECODER(lgtd_lifx_wire_decode_pan_gateway),
+-            .encode = ENCODER(lgtd_lifx_wire_encode_pan_gateway),
+             .handle = HANDLER(lgtd_lifx_gateway_handle_pan_gateway)
+         },
+         {
+@@ -932,14 +931,6 @@
+ }
+ 
+ void
+-lgtd_lifx_wire_encode_pan_gateway(struct lgtd_lifx_packet_pan_gateway *pkt)
+-{
+-    assert(pkt);
+-
+-    pkt->port = htole32(pkt->port);
+-}
+-
+-void
+ lgtd_lifx_wire_decode_light_status(struct lgtd_lifx_packet_light_status *pkt)
+ {
+     assert(pkt);
--- a/series	Thu Dec 31 10:27:59 2015 +0100
+++ b/series	Thu Dec 31 15:34:49 2015 +0100
@@ -3,6 +3,7 @@
 network_discovery.patch
 dont_use_ev_assign.patch
 add_power_transition.patch
+open_gateway_on_any_bulb_response.patch #+future
 make_gateway_write_callbacks_low_priority.patch #+future
 use_echo_request_reply_to_measure_latency.patch #+future
 add_ipv4_to_ieee8023mac.patch #+future #+linux