From 7fa43dbbdbeebec4df6572b0f410c069abdf0978 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher <manuel.bleichenbacher@gmail.com>
Date: Tue, 27 Jul 2021 22:08:00 +0200
Subject: [PATCH] Allow disabling subband seletion

---
 include/TheThingsNetwork.h | 2 +-
 include/ttn.h              | 2 +-
 src/hal/hal_esp32.c        | 2 +-
 src/lmic/hal.h             | 3 ++-
 src/ttn.c                  | 3 ++-
 src/ttn_logging.c          | 2 +-
 6 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/TheThingsNetwork.h b/include/TheThingsNetwork.h
index 1fb0038..5d7446c 100644
--- a/include/TheThingsNetwork.h
+++ b/include/TheThingsNetwork.h
@@ -203,7 +203,7 @@ public:
      * 
      * If not set, it defaults to sub-band 2 as defined by TTN.
      * 
-     * @param band band (between 1 and 8)
+     * @param band band (0 for all bands, or value between 1 and 8)
      */
     void setSubband(int band) { ttn_set_subband(band); }
 
diff --git a/include/ttn.h b/include/ttn.h
index b419ffa..ea981f9 100644
--- a/include/ttn.h
+++ b/include/ttn.h
@@ -198,7 +198,7 @@ void ttn_configure_pins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, u
  * 
  * If not set, it defaults to sub-band 2 as defined by TTN.
  * 
- * @param band band (between 1 and 8)
+ * @param band band (0 for all bands, or value between 1 and 8)
  */
 void ttn_set_subband(int band);
 
diff --git a/src/hal/hal_esp32.c b/src/hal/hal_esp32.c
index cf73b66..efb2b88 100755
--- a/src/hal/hal_esp32.c
+++ b/src/hal/hal_esp32.c
@@ -509,7 +509,7 @@ void hal_esp32_stop_lmic_task(void)
 
 static hal_failure_handler_t* custom_hal_failure_handler = NULL;
 
-void hal_set_failure_handler(const hal_failure_handler_t* const handler)
+void hal_set_failure_handler(hal_failure_handler_t* const handler)
 {
     custom_hal_failure_handler = handler;
 }
diff --git a/src/lmic/hal.h b/src/lmic/hal.h
index f232480..59af982 100644
--- a/src/lmic/hal.h
+++ b/src/lmic/hal.h
@@ -133,7 +133,8 @@ void hal_failed (const char *file, u2_t line);
  * set a custom hal failure handler routine. The default behaviour, defined in
  * hal_failed(), is to halt by looping infintely.
  */
-void hal_set_failure_handler(const hal_failure_handler_t* const);
+void hal_set_failure_handler(hal_failure_handler_t* const);
+// ttn-esp32: too much const
 
 /*
  * get the calibration value for radio_rssi
diff --git a/src/ttn.c b/src/ttn.c
index 4c017d2..b1f050a 100644
--- a/src/ttn.c
+++ b/src/ttn.c
@@ -211,7 +211,8 @@ bool join_core()
     waiting_reason = TTN_WAITING_FOR_JOIN;
 
 #if defined(CFG_us915) || defined(CFG_au915)
-    LMIC_selectSubBand(subband - 1);
+    if (subband != 0)
+        LMIC_selectSubBand(subband - 1);
 #endif
 
     LMIC_startJoining();
diff --git a/src/ttn_logging.c b/src/ttn_logging.c
index 0810bf0..b6cec5e 100644
--- a/src/ttn_logging.c
+++ b/src/ttn_logging.c
@@ -50,7 +50,7 @@ typedef struct {
 } TTNLogMessage;
 
 static void loggingTask(void* param);
-static void logFatal(const char* file, uint16_t line);
+static void logFatal(const char* const file, const uint16_t line);
 
 static void printMessage(TTNLogMessage* log);
 static void printFatalError(TTNLogMessage* log);