summaryrefslogtreecommitdiff
path: root/libloragw
diff options
context:
space:
mode:
Diffstat (limited to 'libloragw')
-rw-r--r--libloragw/Makefile19
-rw-r--r--libloragw/README55
-rw-r--r--libloragw/README.TXT30
-rw-r--r--libloragw/doc/MANUAL.TXT16
-rw-r--r--libloragw/src/loragw_hal.c20
-rw-r--r--libloragw/tst/test_loragw_hal.c21
6 files changed, 99 insertions, 62 deletions
diff --git a/libloragw/Makefile b/libloragw/Makefile
index b910c92..db45383 100644
--- a/libloragw/Makefile
+++ b/libloragw/Makefile
@@ -2,6 +2,7 @@
include library.cfg
# constant symbols
+CROSS_COMPILE=
CC=gcc
CFLAGS=-O2 -Wall -Wextra -Iinc -I.
C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc -I.
@@ -43,35 +44,35 @@ endif
# static library
libloragw.a: obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
- ar rcs libloragw.a obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
+ $(CROSS_COMPILE)ar rcs libloragw.a obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
# library module target
obj/loragw_aux.o: .conf_ok src/loragw_aux.c inc/loragw_aux.h
- $(CC) -c $(CFLAGS) src/loragw_aux.c -o obj/loragw_aux.o $(FLAG_AUX)
+ $(CROSS_COMPILE)$(CC) -c $(CFLAGS) src/loragw_aux.c -o obj/loragw_aux.o $(FLAG_AUX)
obj/loragw_spi.o: .conf_ok src/loragw_spi.native.c src/loragw_spi.ftdi.c inc/loragw_spi.h
ifeq ($(LGW_PHY),native)
- $(CC) -c $(C99FLAGS) src/loragw_spi.native.c -o obj/loragw_spi.o $(FLAG_SPI)
+ $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.native.c -o obj/loragw_spi.o $(FLAG_SPI)
endif
ifeq ($(LGW_PHY),ftdi)
- $(CC) -c $(C99FLAGS) src/loragw_spi.ftdi.c -o obj/loragw_spi.o $(FLAG_SPI)
+ $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_spi.ftdi.c -o obj/loragw_spi.o $(FLAG_SPI)
endif
obj/loragw_reg.o: .conf_ok src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h
- $(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG)
+ $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_reg.c -o obj/loragw_reg.o $(FLAG_REG)
obj/loragw_hal.o: .conf_ok VERSION src/loragw_hal.c src/arb_fw.var src/agc_fw.var inc/loragw_hal.h inc/loragw_reg.h inc/loragw_spi.h inc/loragw_aux.h
- $(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL)
+ $(CROSS_COMPILE)$(CC) -c $(C99FLAGS) src/loragw_hal.c -o obj/loragw_hal.o -D LGW_PHY="\"$(LGW_PHY)\"" $(FLAG_HAL)
# test programs
test_loragw_spi: tst/test_loragw_spi.c obj/loragw_spi.o
- $(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS)
+ $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_spi.c obj/loragw_spi.o -o test_loragw_spi $(LDFLAGS)
test_loragw_reg: tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o
- $(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS)
+ $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_reg.c obj/loragw_reg.o obj/loragw_spi.o -o test_loragw_reg $(LDFLAGS)
test_loragw_hal: tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
- $(CC) $(C99FLAGS) tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_hal $(LDFLAGS)
+ $(CROSS_COMPILE)$(CC) $(C99FLAGS) tst/test_loragw_hal.c obj/loragw_hal.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o -o test_loragw_hal $(LDFLAGS)
diff --git a/libloragw/README b/libloragw/README
new file mode 100644
index 0000000..da4cd4d
--- /dev/null
+++ b/libloragw/README
@@ -0,0 +1,55 @@
+Lora Gateway HAL library
+=========================
+
+1. Content of subdirectories
+-----------------------------
+
+### 1.1. doc ###
+
+Contains the user manual, licensing informations, udev rules, etc.
+
+### 1.2. inc ###
+
+Contain C header files for the different sub-modules of the library.
+
+You *MUST* include loragw_hal.h in your application.
+You *MAY* include loragw_reg.h in your application if you need direct registers
+access.
+
+### 1.3. obj ###
+
+Contained the compiled intermediary objects.
+
+### 1.4. src ###
+
+Contain library C sources.
+
+### 1.5. tst ###
+
+Contain the C sources for test programs to validate SPI link, register access
+and hardware functionality.
+
+2. Legal notice
+----------------
+
+The information presented in this project documentation does not form part of
+any quotation or contract, is believed to be accurate and reliable and may be
+changed without notice. No liability will be accepted by the publisher for any
+consequence of its use. Publication thereof does not convey nor imply any
+license under patent or other industrial or intellectual property rights.
+Semtech assumes no responsibility or liability whatsoever for any failure or
+unexpected operation resulting from misuse, neglect improper installation,
+repair or improper handling or unusual physical or electrical stress
+including, but not limited to, exposure to parameters beyond the specified
+maximum ratings or operation outside the specified range.
+
+SEMTECH PRODUCTS ARE NOT DESIGNED, INTENDED, AUTHORIZED OR WARRANTED TO BE
+SUITABLE FOR USE IN LIFE-SUPPORT APPLICATIONS, DEVICES OR SYSTEMS OR OTHER
+CRITICAL APPLICATIONS. INCLUSION OF SEMTECH PRODUCTS IN SUCH APPLICATIONS IS
+UNDERSTOOD TO BE UNDERTAKEN SOLELY AT THE CUSTOMER’S OWN RISK. Should a
+customer purchase or use Semtech products for any such unauthorized
+application, the customer shall indemnify and hold Semtech and its officers,
+employees, subsidiaries, affiliates, and distributors harmless against all
+claims, costs damages and attorney fees which could arise.
+
+*EOF* \ No newline at end of file
diff --git a/libloragw/README.TXT b/libloragw/README.TXT
deleted file mode 100644
index 9d13a4a..0000000
--- a/libloragw/README.TXT
+++ /dev/null
@@ -1,30 +0,0 @@
-Lora Gateway HAL library - Content of subdirectories
-====================================================
-
-## 1. doc ##
-
-Contains the user manual, licensing informations, udev rules, etc.
-
-## 2. inc ##
-
-Contain C header files for the different sub-modules of the library.
-
-You *MUST* include loragw_hal.h in your application.
-You *MAY* include loragw_reg.h in your application if you need direct registers
-access.
-
-## 3. obj ##
-
-Contained the compiled intermediary objects.
-
-## 4. src ##
-
-Contain library C sources.
-
-## 5. tst ##
-
-Contain the C sources for test programs to validate SPI link, register access
-and hardware functionality.
-
-
-*EOF* \ No newline at end of file
diff --git a/libloragw/doc/MANUAL.TXT b/libloragw/doc/MANUAL.TXT
index 1659f03..a086761 100644
--- a/libloragw/doc/MANUAL.TXT
+++ b/libloragw/doc/MANUAL.TXT
@@ -200,14 +200,14 @@ started
A typical application flow for using the HAL is the following:
-<configure the radios and IF+modems>
-<start the Lora gateway>
-loop {
- <fetch packets that were received by the gateway>
- <process, store and/or forward received packets>
- <send packets through the gateway>
-}
-<stop the gateway>
+ <configure the radios and IF+modems>
+ <start the Lora gateway>
+ loop {
+ <fetch packets that were received by the gateway>
+ <process, store and/or forward received packets>
+ <send packets through the gateway>
+ }
+ <stop the gateway>
**/!\ Warning** The lgw_send function is non-blocking and returns while the
Lora gateway is still sending the packet, or even before the packet has started
diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c
index 5d9138d..c2329fc 100644
--- a/libloragw/src/loragw_hal.c
+++ b/libloragw/src/loragw_hal.c
@@ -454,11 +454,13 @@ int lgw_rxrf_setconf(uint8_t rf_chain, struct lgw_conf_rxrf_s conf) {
return LGW_HAL_ERROR;
}
- /* check input parameters */
- if (rf_chain > LGW_RF_CHAIN_NB) {
+ /* check input range (segfault prevention) */
+ if (rf_chain >= LGW_RF_CHAIN_NB) {
DEBUG_MSG("ERROR: NOT A VALID RF_CHAIN NUMBER\n");
return LGW_HAL_ERROR;
}
+
+ /* check input parameters */
if (conf.freq_hz > rf_rx_upfreq[rf_chain]) {
DEBUG_MSG("ERROR: FREQUENCY TOO HIGH FOR THAT RF_CHAIN\n");
return LGW_HAL_ERROR;
@@ -483,6 +485,12 @@ int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s conf) {
return LGW_HAL_ERROR;
}
+ /* check input range (segfault prevention) */
+ if (if_chain >= LGW_IF_CHAIN_NB) {
+ DEBUG_PRINTF("ERROR: %d NOT A VALID IF_CHAIN NUMBER\n", if_chain);
+ return LGW_HAL_ERROR;
+ }
+
/* if chain is disabled, don't care about most parameters */
if (conf.enable == false) {
if_enable[if_chain] = false;
@@ -492,10 +500,6 @@ int lgw_rxif_setconf(uint8_t if_chain, struct lgw_conf_rxif_s conf) {
}
/* check 'general' parameters */
- if (if_chain > LGW_IF_CHAIN_NB) {
- DEBUG_PRINTF("ERROR: %d NOT A VALID IF_CHAIN NUMBER\n", if_chain);
- return LGW_HAL_ERROR;
- }
if (ifmod_config[if_chain] == IF_UNDEFINED) {
DEBUG_PRINTF("ERROR: IF CHAIN %d NOT CONFIGURABLE\n", if_chain);
}
@@ -954,11 +958,13 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) {
return LGW_HAL_ERROR;
}
- /* check input variables */
+ /* check input range (segfault prevention) */
if (pkt_data.rf_chain >= LGW_RF_CHAIN_NB) {
DEBUG_MSG("ERROR: INVALID RF_CHAIN TO SEND PACKETS\n");
return LGW_HAL_ERROR;
}
+
+ /* check input variables */
if (rf_enable[pkt_data.rf_chain] == false) {
DEBUG_MSG("ERROR: SELECTED RF_CHAIN IS DISABLED\n");
return LGW_HAL_ERROR;
diff --git a/libloragw/tst/test_loragw_hal.c b/libloragw/tst/test_loragw_hal.c
index c777597..6881760 100644
--- a/libloragw/tst/test_loragw_hal.c
+++ b/libloragw/tst/test_loragw_hal.c
@@ -82,8 +82,6 @@ int main()
unsigned long loop_cnt = 0;
uint8_t status_var = 0;
- FILE * reg_dump = NULL;
-
/* configure signal handling */
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
@@ -180,14 +178,21 @@ int main()
printf("*** Library version information ***\n%s\n***\n", lgw_version_info());
/* connect, configure and start the Lora gateway */
- lgw_start();
+ i = lgw_start();
+ if (i == LGW_HAL_SUCCESS) {
+ printf("*** Concentrator started ***\n");
+ } else {
+ printf("*** Impossible to start concentrator ***\n");
+ return -1;
+ }
/* once configured, dump content of registers to a file, for reference */
- reg_dump = fopen("reg_dump.log", "w");
- if (reg_dump != NULL) {
- lgw_reg_check(reg_dump);
- fclose(reg_dump);
- }
+ // FILE * reg_dump = NULL;
+ // reg_dump = fopen("reg_dump.log", "w");
+ // if (reg_dump != NULL) {
+ // lgw_reg_check(reg_dump);
+ // fclose(reg_dump);
+ // }
while ((quit_sig != 1) && (exit_sig != 1)) {
loop_cnt++;