From 817e6e1e7f0c3affce078bac7b060ba675043664 Mon Sep 17 00:00:00 2001 From: Anand Singh Date: Thu, 4 Jun 2020 17:14:37 -0700 Subject: [PATCH] Release 2.0.4-9-g3d5c686 --- .travis.yml | 18 + CHANGELOG.md | 22 + Dockerfile | 32 + LICENSE | 17 +- README.md | 2 +- ROADMAP.md | 26 + VERSION.txt | 2 +- deps/lgw/.gitignore | 2 + deps/lgw/makefile | 30 +- deps/lgw/prep.sh | 44 +- deps/lgw1302/.gitignore | 2 + deps/lgw1302/V1.0.5-corecell.patch | 300 +++++ deps/lgw1302/makefile | 72 + deps/lgw1302/prep.sh | 53 + deps/mbedtls/.gitignore | 2 + deps/mbedtls/makefile | 27 +- deps/mbedtls/prep.sh | 26 + deps/smtcpico/.gitignore | 2 + deps/smtcpico/V0.2.2-linuxpico.patch | 463 +++++++ deps/smtcpico/makefile | 72 + deps/smtcpico/prep.sh | 52 + examples/corecell/README.md | 22 + examples/corecell/lns-ttn/.gitignore | 4 + examples/corecell/lns-ttn/station.conf | 53 + examples/corecell/lns-ttn/tc.trust | 28 + examples/corecell/lns-ttn/tc.uri | 1 + examples/corecell/lns-ttn/version.txt | 1 + examples/corecell/reset_lgw.sh | 70 + examples/corecell/rinit.sh | 2 + examples/corecell/start-station.sh | 88 ++ examples/cups/README.md | 16 +- examples/cups/emulate.sh | 26 + examples/cups/makefile | 26 + examples/cups/prep.sh | 26 + examples/cups/sim.py | 25 +- examples/live-s2.sm.tc/.gitignore | 8 + examples/live-s2.sm.tc/makefile | 26 + examples/simulation/.gitignore | 7 + examples/simulation/makefile | 26 + examples/simulation/sim.py | 17 +- examples/station2pkfwd/bgtask.py | 17 +- examples/station2pkfwd/id6.py | 17 +- examples/station2pkfwd/main.py | 17 +- examples/station2pkfwd/pkfwdc.py | 17 +- examples/station2pkfwd/router.py | 17 +- examples/station2pkfwd/router_config.py | 17 +- makefile.s2core | 39 +- pysys/id6.py | 23 +- pysys/simutils.py | 338 +++-- pysys/tcutils.py | 176 ++- pysys/testutils.py | 40 + regr-tests/.gitignore | 7 + regr-tests/makefile | 62 + regr-tests/pki-data/cups-0.ca | 29 + regr-tests/pki-data/cups-0.crt | 25 + regr-tests/pki-data/cups-0.key | 27 + regr-tests/pki-data/cups-router-1.ca | 29 + regr-tests/pki-data/cups-router-1.crt | 24 + regr-tests/pki-data/cups-router-1.key | 27 + regr-tests/pki-data/cups-router-2.ca | 29 + regr-tests/pki-data/cups-router-2.crt | 24 + regr-tests/pki-data/cups-router-2.key | 27 + regr-tests/pki-data/infos-0.ca | 29 + regr-tests/pki-data/infos-0.crt | 25 + regr-tests/pki-data/infos-0.key | 27 + regr-tests/pki-data/muxs-0.ca | 29 + regr-tests/pki-data/muxs-0.crt | 25 + regr-tests/pki-data/muxs-0.key | 27 + regr-tests/pki-data/tc-router-1.ca | 29 + regr-tests/pki-data/tc-router-1.crt | 24 + regr-tests/pki-data/tc-router-1.key | 27 + regr-tests/pki-data/tc-router-2.ca | 29 + regr-tests/pki-data/tc-router-2.crt | 24 + regr-tests/pki-data/tc-router-2.key | 27 + regr-tests/run-regression-tests | 177 +++ regr-tests/test1-selftests/.gitignore | 2 + regr-tests/test1-selftests/makefile | 33 + regr-tests/test1-selftests/station.conf | 9 + regr-tests/test1-selftests/tc.uri | 1 + regr-tests/test1-selftests/test.sh | 31 + regr-tests/test2-fs/.gitignore | 2 + regr-tests/test2-fs/data.txt | 22 + regr-tests/test2-fs/makefile | 33 + regr-tests/test2-fs/test.sh | 155 +++ regr-tests/test2-gps/.gitignore | 6 + regr-tests/test2-gps/makefile | 33 + regr-tests/test2-gps/slave-0.conf | 2 + regr-tests/test2-gps/station.conf | 33 + regr-tests/test2-gps/tc.uri | 1 + regr-tests/test2-gps/test.py | 119 ++ regr-tests/test2-gps/test.sh | 37 + regr-tests/test2-pps/.gitignore | 6 + regr-tests/test2-pps/makefile | 33 + regr-tests/test2-pps/slave-0.conf | 2 + regr-tests/test2-pps/station.conf | 33 + regr-tests/test2-pps/tc.uri | 1 + regr-tests/test2-pps/test.py | 124 ++ regr-tests/test2-pps/test.sh | 37 + regr-tests/test3-updn-tls/.gitignore | 10 + regr-tests/test3-updn-tls/infos-0.crt | 1 + regr-tests/test3-updn-tls/infos-0.key | 1 + regr-tests/test3-updn-tls/infos-0.trust | 1 + regr-tests/test3-updn-tls/makefile | 33 + regr-tests/test3-updn-tls/muxs-0.crt | 1 + regr-tests/test3-updn-tls/muxs-0.key | 1 + regr-tests/test3-updn-tls/muxs-0.trust | 1 + regr-tests/test3-updn-tls/radioinit1.sh | 4 + regr-tests/test3-updn-tls/radioinit2.sh | 3 + regr-tests/test3-updn-tls/radioinit3.sh | 3 + regr-tests/test3-updn-tls/slave-0.conf | 2 + regr-tests/test3-updn-tls/station.conf | 30 + regr-tests/test3-updn-tls/test.py | 162 +++ regr-tests/test3-updn-tls/test.sh | 90 ++ regr-tests/test3a-updn-tls/.gitignore | 9 + regr-tests/test3a-updn-tls/infos-0.crt | 1 + regr-tests/test3a-updn-tls/infos-0.key | 1 + regr-tests/test3a-updn-tls/infos-0.trust | 1 + regr-tests/test3a-updn-tls/makefile | 33 + regr-tests/test3a-updn-tls/muxs-0.crt | 1 + regr-tests/test3a-updn-tls/muxs-0.key | 1 + regr-tests/test3a-updn-tls/muxs-0.trust | 1 + regr-tests/test3a-updn-tls/slave-0.conf | 2 + regr-tests/test3a-updn-tls/station.conf | 29 + regr-tests/test3a-updn-tls/test.py | 163 +++ regr-tests/test3a-updn-tls/test.sh | 57 + regr-tests/test3b-dnC/.gitignore | 6 + regr-tests/test3b-dnC/makefile | 33 + regr-tests/test3b-dnC/slave-0.conf | 2 + regr-tests/test3b-dnC/station.conf | 35 + regr-tests/test3b-dnC/test.py | 152 +++ regr-tests/test3b-dnC/test.sh | 33 + regr-tests/test3b-dnC_2ant/.gitignore | 7 + regr-tests/test3b-dnC_2ant/makefile | 33 + regr-tests/test3b-dnC_2ant/slave-0.conf | 1 + regr-tests/test3b-dnC_2ant/slave-1.conf | 2 + regr-tests/test3b-dnC_2ant/station.conf.in | 35 + regr-tests/test3b-dnC_2ant/test.py | 168 +++ regr-tests/test3b-dnC_2ant/test.sh | 40 + regr-tests/test3b-rx2_2ant/.gitignore | 7 + regr-tests/test3b-rx2_2ant/makefile | 33 + regr-tests/test3b-rx2_2ant/slave-0.conf | 2 + regr-tests/test3b-rx2_2ant/slave-1.conf | 2 + regr-tests/test3b-rx2_2ant/station.conf.in | 35 + regr-tests/test3b-rx2_2ant/test.py | 215 +++ regr-tests/test3b-rx2_2ant/test.sh | 40 + regr-tests/test3c-cca/.gitignore | 6 + regr-tests/test3c-cca/makefile | 33 + regr-tests/test3c-cca/slave-0.conf | 2 + regr-tests/test3c-cca/station.conf | 35 + regr-tests/test3c-cca/test.py | 181 +++ regr-tests/test3c-cca/test.sh | 33 + regr-tests/test3d-bcns/.gitignore | 6 + regr-tests/test3d-bcns/makefile | 33 + regr-tests/test3d-bcns/slave-0.conf | 2 + regr-tests/test3d-bcns/station.conf | 34 + regr-tests/test3d-bcns/test.py | 223 ++++ regr-tests/test3d-bcns/test.sh | 35 + regr-tests/test4-cups/.gitignore | 22 + regr-tests/test4-cups/makefile | 35 + regr-tests/test4-cups/sig-0.key | 1 + regr-tests/test4-cups/slave-0.conf | 2 + regr-tests/test4-cups/station.conf | 34 + regr-tests/test4-cups/test.py | 220 ++++ regr-tests/test4-cups/test.sh | 119 ++ regr-tests/test4-cups/v1.bin | 5 + regr-tests/test4-cups/v1.bin.sig-0 | Bin 0 -> 72 bytes regr-tests/test5-rmtsh/.gitignore | 6 + regr-tests/test5-rmtsh/makefile | 33 + regr-tests/test5-rmtsh/slave-0.conf | 2 + regr-tests/test5-rmtsh/station.conf | 35 + regr-tests/test5-rmtsh/tc.uri | 1 + regr-tests/test5-rmtsh/test.py | 183 +++ regr-tests/test5-rmtsh/test.sh | 32 + regr-tests/test5-runcmd/.gitignore | 7 + regr-tests/test5-runcmd/cmd.sh | 3 + regr-tests/test5-runcmd/cmd2.sh | 4 + regr-tests/test5-runcmd/makefile | 33 + regr-tests/test5-runcmd/slave-0.conf | 2 + regr-tests/test5-runcmd/slave.py | 54 + regr-tests/test5-runcmd/station.conf | 29 + regr-tests/test5-runcmd/test.py | 158 +++ regr-tests/test5-runcmd/test.sh | 47 + regr-tests/test5-runcmd/update_bin | 6 + regr-tests/test7-respawn/.gitignore | 5 + regr-tests/test7-respawn/makefile | 33 + regr-tests/test7-respawn/slave-0.conf | 2 + regr-tests/test7-respawn/station.conf | 25 + regr-tests/test7-respawn/test.sh | 125 ++ regr-tests/test8-web/.gitignore | 2 + regr-tests/test8-web/makefile | 33 + regr-tests/test8-web/ref.400 | 2 + regr-tests/test8-web/ref.404 | 3 + regr-tests/test8-web/ref.405 | 2 + regr-tests/test8-web/ref.a | 5 + regr-tests/test8-web/ref.empty | 0 regr-tests/test8-web/ref.index.html | 5 + regr-tests/test8-web/ref.sub.b.txt | 5 + regr-tests/test8-web/ref.test.js | 5 + regr-tests/test8-web/ref.test.json | 5 + regr-tests/test8-web/ref.toobig.gz | 3 + regr-tests/test8-web/slave-0.conf | 1 + regr-tests/test8-web/station.conf | 8 + regr-tests/test8-web/tc.uri | 1 + regr-tests/test8-web/test.sh | 133 ++ regr-tests/test8-web/web/a | 1 + regr-tests/test8-web/web/index.html | 1 + regr-tests/test8-web/web/sub/b.txt | 1 + regr-tests/test8-web/web/test.js | 1 + regr-tests/test8-web/web/test.json | 1 + regr-tests/testlib.sh | 130 ++ setup.gmk | 50 +- src-linux/cmdfifo.c | 47 +- src-linux/commands.c | 45 +- src-linux/gps.c | 195 ++- src-linux/leds.c | 45 +- src-linux/ral_master.c | 96 +- src-linux/ral_slave.c | 59 +- src-linux/ralsub.h | 51 +- src-linux/rmtsh.c | 45 +- src-linux/station_main.c | 45 +- src-linux/sys_linux.c | 57 +- src-linux/sys_linux.h | 45 +- src-linux/sys_log.c | 53 +- src-linux/web_linux.c | 45 +- src/aio.c | 45 +- src/argp.c | 45 +- src/argp2.h | 45 +- src/crc32.c | 47 +- src/cups.c | 95 +- src/cups.h | 45 +- src/flashsim.c | 45 +- src/fs.c | 45 +- src/fs.h | 45 +- src/genkwcrcs.c | 45 +- src/http.h | 45 +- src/httpd.h | 45 +- src/kwcrc.h | 38 + src/kwlist.txt | 40 + src/lgwsim.c | 1371 +++++++++++++++++++- src/log.c | 55 +- src/lora.c | 109 +- src/net.c | 103 +- src/net.h | 47 +- src/ral.c | 149 +++ src/ral.h | 94 +- src/ral_lgw.c | 142 +- src/ral_lgw2.c | 108 +- src/rt.c | 54 +- src/rt.h | 52 +- src/s2conf.c | 63 +- src/s2conf.h | 68 +- src/s2e.c | 435 ++++++- src/s2e.h | 66 +- src/selftest_fs.c | 45 +- src/selftest_lora.c | 45 +- src/selftest_rt.c | 45 +- src/selftest_ujdec.c | 50 +- src/selftest_ujenc.c | 49 +- src/selftest_xprintf.c | 45 +- src/selftest_xq.c | 45 +- src/selftests.c | 45 +- src/selftests.h | 45 +- src/sx1301conf.c | 447 ------- src/sx1301conf.h | 65 - src/sx1301v2conf.c | 174 ++- src/sx1301v2conf.h | 49 +- src/sx130xconf.c | 713 ++++++++++ src/sx130xconf.h | 70 + src/sys.c | 51 +- src/sys.h | 73 +- src/tc.c | 63 +- src/tc.h | 45 +- src/timesync.c | 124 +- src/timesync.h | 45 +- src/tls.c | 52 +- src/tls.h | 45 +- src/uj.c | 64 +- src/uj.h | 45 +- src/web.c | 45 +- src/web.h | 45 +- src/ws.h | 45 +- src/xq.c | 47 +- src/xq.h | 50 +- 283 files changed, 12438 insertions(+), 2574 deletions(-) create mode 100644 .travis.yml create mode 100644 Dockerfile create mode 100644 ROADMAP.md create mode 100644 deps/lgw/.gitignore create mode 100644 deps/lgw1302/.gitignore create mode 100644 deps/lgw1302/V1.0.5-corecell.patch create mode 100644 deps/lgw1302/makefile create mode 100755 deps/lgw1302/prep.sh create mode 100644 deps/mbedtls/.gitignore create mode 100644 deps/smtcpico/.gitignore create mode 100644 deps/smtcpico/V0.2.2-linuxpico.patch create mode 100644 deps/smtcpico/makefile create mode 100755 deps/smtcpico/prep.sh create mode 100644 examples/corecell/README.md create mode 100644 examples/corecell/lns-ttn/.gitignore create mode 100644 examples/corecell/lns-ttn/station.conf create mode 100644 examples/corecell/lns-ttn/tc.trust create mode 100644 examples/corecell/lns-ttn/tc.uri create mode 100644 examples/corecell/lns-ttn/version.txt create mode 100755 examples/corecell/reset_lgw.sh create mode 100644 examples/corecell/rinit.sh create mode 100755 examples/corecell/start-station.sh create mode 100644 examples/live-s2.sm.tc/.gitignore create mode 100644 examples/simulation/.gitignore create mode 100644 pysys/testutils.py create mode 100644 regr-tests/.gitignore create mode 100644 regr-tests/makefile create mode 100644 regr-tests/pki-data/cups-0.ca create mode 100644 regr-tests/pki-data/cups-0.crt create mode 100644 regr-tests/pki-data/cups-0.key create mode 100644 regr-tests/pki-data/cups-router-1.ca create mode 100644 regr-tests/pki-data/cups-router-1.crt create mode 100644 regr-tests/pki-data/cups-router-1.key create mode 100644 regr-tests/pki-data/cups-router-2.ca create mode 100644 regr-tests/pki-data/cups-router-2.crt create mode 100644 regr-tests/pki-data/cups-router-2.key create mode 100644 regr-tests/pki-data/infos-0.ca create mode 100644 regr-tests/pki-data/infos-0.crt create mode 100644 regr-tests/pki-data/infos-0.key create mode 100644 regr-tests/pki-data/muxs-0.ca create mode 100644 regr-tests/pki-data/muxs-0.crt create mode 100644 regr-tests/pki-data/muxs-0.key create mode 100644 regr-tests/pki-data/tc-router-1.ca create mode 100644 regr-tests/pki-data/tc-router-1.crt create mode 100644 regr-tests/pki-data/tc-router-1.key create mode 100644 regr-tests/pki-data/tc-router-2.ca create mode 100644 regr-tests/pki-data/tc-router-2.crt create mode 100644 regr-tests/pki-data/tc-router-2.key create mode 100755 regr-tests/run-regression-tests create mode 100644 regr-tests/test1-selftests/.gitignore create mode 100644 regr-tests/test1-selftests/makefile create mode 100644 regr-tests/test1-selftests/station.conf create mode 100644 regr-tests/test1-selftests/tc.uri create mode 100755 regr-tests/test1-selftests/test.sh create mode 100644 regr-tests/test2-fs/.gitignore create mode 100644 regr-tests/test2-fs/data.txt create mode 100644 regr-tests/test2-fs/makefile create mode 100755 regr-tests/test2-fs/test.sh create mode 100644 regr-tests/test2-gps/.gitignore create mode 100644 regr-tests/test2-gps/makefile create mode 100644 regr-tests/test2-gps/slave-0.conf create mode 100644 regr-tests/test2-gps/station.conf create mode 100644 regr-tests/test2-gps/tc.uri create mode 100644 regr-tests/test2-gps/test.py create mode 100755 regr-tests/test2-gps/test.sh create mode 100644 regr-tests/test2-pps/.gitignore create mode 100644 regr-tests/test2-pps/makefile create mode 100644 regr-tests/test2-pps/slave-0.conf create mode 100644 regr-tests/test2-pps/station.conf create mode 100644 regr-tests/test2-pps/tc.uri create mode 100644 regr-tests/test2-pps/test.py create mode 100755 regr-tests/test2-pps/test.sh create mode 100644 regr-tests/test3-updn-tls/.gitignore create mode 120000 regr-tests/test3-updn-tls/infos-0.crt create mode 120000 regr-tests/test3-updn-tls/infos-0.key create mode 120000 regr-tests/test3-updn-tls/infos-0.trust create mode 100644 regr-tests/test3-updn-tls/makefile create mode 120000 regr-tests/test3-updn-tls/muxs-0.crt create mode 120000 regr-tests/test3-updn-tls/muxs-0.key create mode 120000 regr-tests/test3-updn-tls/muxs-0.trust create mode 100644 regr-tests/test3-updn-tls/radioinit1.sh create mode 100644 regr-tests/test3-updn-tls/radioinit2.sh create mode 100644 regr-tests/test3-updn-tls/radioinit3.sh create mode 100644 regr-tests/test3-updn-tls/slave-0.conf create mode 100644 regr-tests/test3-updn-tls/station.conf create mode 100644 regr-tests/test3-updn-tls/test.py create mode 100755 regr-tests/test3-updn-tls/test.sh create mode 100644 regr-tests/test3a-updn-tls/.gitignore create mode 120000 regr-tests/test3a-updn-tls/infos-0.crt create mode 120000 regr-tests/test3a-updn-tls/infos-0.key create mode 120000 regr-tests/test3a-updn-tls/infos-0.trust create mode 100644 regr-tests/test3a-updn-tls/makefile create mode 120000 regr-tests/test3a-updn-tls/muxs-0.crt create mode 120000 regr-tests/test3a-updn-tls/muxs-0.key create mode 120000 regr-tests/test3a-updn-tls/muxs-0.trust create mode 100644 regr-tests/test3a-updn-tls/slave-0.conf create mode 100644 regr-tests/test3a-updn-tls/station.conf create mode 100644 regr-tests/test3a-updn-tls/test.py create mode 100755 regr-tests/test3a-updn-tls/test.sh create mode 100644 regr-tests/test3b-dnC/.gitignore create mode 100644 regr-tests/test3b-dnC/makefile create mode 100644 regr-tests/test3b-dnC/slave-0.conf create mode 100644 regr-tests/test3b-dnC/station.conf create mode 100644 regr-tests/test3b-dnC/test.py create mode 100755 regr-tests/test3b-dnC/test.sh create mode 100644 regr-tests/test3b-dnC_2ant/.gitignore create mode 100644 regr-tests/test3b-dnC_2ant/makefile create mode 100644 regr-tests/test3b-dnC_2ant/slave-0.conf create mode 100644 regr-tests/test3b-dnC_2ant/slave-1.conf create mode 100644 regr-tests/test3b-dnC_2ant/station.conf.in create mode 100644 regr-tests/test3b-dnC_2ant/test.py create mode 100755 regr-tests/test3b-dnC_2ant/test.sh create mode 100644 regr-tests/test3b-rx2_2ant/.gitignore create mode 100644 regr-tests/test3b-rx2_2ant/makefile create mode 100644 regr-tests/test3b-rx2_2ant/slave-0.conf create mode 100644 regr-tests/test3b-rx2_2ant/slave-1.conf create mode 100644 regr-tests/test3b-rx2_2ant/station.conf.in create mode 100644 regr-tests/test3b-rx2_2ant/test.py create mode 100755 regr-tests/test3b-rx2_2ant/test.sh create mode 100644 regr-tests/test3c-cca/.gitignore create mode 100644 regr-tests/test3c-cca/makefile create mode 100644 regr-tests/test3c-cca/slave-0.conf create mode 100644 regr-tests/test3c-cca/station.conf create mode 100644 regr-tests/test3c-cca/test.py create mode 100755 regr-tests/test3c-cca/test.sh create mode 100644 regr-tests/test3d-bcns/.gitignore create mode 100644 regr-tests/test3d-bcns/makefile create mode 100644 regr-tests/test3d-bcns/slave-0.conf create mode 100644 regr-tests/test3d-bcns/station.conf create mode 100644 regr-tests/test3d-bcns/test.py create mode 100755 regr-tests/test3d-bcns/test.sh create mode 100644 regr-tests/test4-cups/.gitignore create mode 100644 regr-tests/test4-cups/makefile create mode 100644 regr-tests/test4-cups/sig-0.key create mode 100644 regr-tests/test4-cups/slave-0.conf create mode 100644 regr-tests/test4-cups/station.conf create mode 100644 regr-tests/test4-cups/test.py create mode 100755 regr-tests/test4-cups/test.sh create mode 100644 regr-tests/test4-cups/v1.bin create mode 100644 regr-tests/test4-cups/v1.bin.sig-0 create mode 100644 regr-tests/test5-rmtsh/.gitignore create mode 100644 regr-tests/test5-rmtsh/makefile create mode 100644 regr-tests/test5-rmtsh/slave-0.conf create mode 100644 regr-tests/test5-rmtsh/station.conf create mode 100644 regr-tests/test5-rmtsh/tc.uri create mode 100644 regr-tests/test5-rmtsh/test.py create mode 100755 regr-tests/test5-rmtsh/test.sh create mode 100644 regr-tests/test5-runcmd/.gitignore create mode 100755 regr-tests/test5-runcmd/cmd.sh create mode 100644 regr-tests/test5-runcmd/cmd2.sh create mode 100644 regr-tests/test5-runcmd/makefile create mode 100644 regr-tests/test5-runcmd/slave-0.conf create mode 100644 regr-tests/test5-runcmd/slave.py create mode 100644 regr-tests/test5-runcmd/station.conf create mode 100644 regr-tests/test5-runcmd/test.py create mode 100755 regr-tests/test5-runcmd/test.sh create mode 100644 regr-tests/test5-runcmd/update_bin create mode 100644 regr-tests/test7-respawn/.gitignore create mode 100644 regr-tests/test7-respawn/makefile create mode 100644 regr-tests/test7-respawn/slave-0.conf create mode 100644 regr-tests/test7-respawn/station.conf create mode 100755 regr-tests/test7-respawn/test.sh create mode 100644 regr-tests/test8-web/.gitignore create mode 100644 regr-tests/test8-web/makefile create mode 100644 regr-tests/test8-web/ref.400 create mode 100644 regr-tests/test8-web/ref.404 create mode 100644 regr-tests/test8-web/ref.405 create mode 100644 regr-tests/test8-web/ref.a create mode 100644 regr-tests/test8-web/ref.empty create mode 100644 regr-tests/test8-web/ref.index.html create mode 100644 regr-tests/test8-web/ref.sub.b.txt create mode 100644 regr-tests/test8-web/ref.test.js create mode 100644 regr-tests/test8-web/ref.test.json create mode 100644 regr-tests/test8-web/ref.toobig.gz create mode 100644 regr-tests/test8-web/slave-0.conf create mode 100644 regr-tests/test8-web/station.conf create mode 100644 regr-tests/test8-web/tc.uri create mode 100755 regr-tests/test8-web/test.sh create mode 100644 regr-tests/test8-web/web/a create mode 100644 regr-tests/test8-web/web/index.html create mode 100644 regr-tests/test8-web/web/sub/b.txt create mode 100644 regr-tests/test8-web/web/test.js create mode 100644 regr-tests/test8-web/web/test.json create mode 100644 regr-tests/testlib.sh create mode 100644 src/ral.c delete mode 100644 src/sx1301conf.c delete mode 100644 src/sx1301conf.h create mode 100644 src/sx130xconf.c create mode 100644 src/sx130xconf.h diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e4aff84 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: minimal + +services: docker + +env: Dimg=lorabasics; Dname=basicstation-test + +before_install: +- sudo chown -R 1000:1000 $TRAVIS_BUILD_DIR +- docker build . -t $Dimg +- docker run --init -d --name $Dname -v $TRAVIS_BUILD_DIR:/home/nonprivuser/travis -w /home/nonprivuser/travis $Dimg tail -f /dev/null +- export Dcmd="docker exec -t $Dname bash -c" + +install: +# nothing to install + +script: +# all commands must be quoted +- $Dcmd "make -C regr-tests ci s2core.info" diff --git a/CHANGELOG.md b/CHANGELOG.md index 511308c..f741e6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog +## 2.0.4 - 2020-03-17 + +* lgw1302: Added sx1302 hal and integrated with corecell platform +* sys_linux: Fixed decoder pointer dereferencing (#39) +* s2e: Fixed memory corruption bug in JoinEui filter parsing (#31) +* s2e: Added DR and Freq fields to dntxed message (#37) +* s2e: Added error message type for printing LNS error into Station's log (#33) +* s2e: Added fts field to updf message +* net: Added Websocket PONG (#29) +* net: Added option for TLS server name indication/verification +* rt: Added MCU clock drift compensation for UTC time offset +* ral: Fixed dntxed message for short transmissions +* ral: Added Automatic channel allocation feature +* ral: Added fine timestamping in lgw2 +* ral: Added automatic AES key derivation in lgw2 +* ral: Added support for smtcpico platform (experimental) (#16) +* timesync: Correct UTC offset in case PPS offset is known +* lgwsim: Added lgw2 support +* pysys: Fixed Id6 category parsing (#28) +* tests: Added regression tests +* tests: Added Dockerfile + ## 2.0.3 - 2019-03-14 * sys_linux: Fixed stdout/stderr redirection for logging diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1926cac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:18.04 + +ENV container=docker TERM=xterm LC_ALL=en_US LANGUAGE=en_US LANG=en_US.UTF-8 +ENV DEBIAN_FRONTEND=noninteractive + +# locale +RUN apt-get update -q > /dev/null && \ + apt-get install --no-install-recommends -yq apt-utils locales language-pack-en dialog \ + > /dev/null && \ + locale-gen $LANGUAGE $LANG + +# sudo commmand +RUN apt-get -yq install sudo > /dev/null + +# non-privileged user +RUN echo "nonprivuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers +RUN useradd --no-log-init --home-dir /home/nonprivuser --create-home --shell /bin/bash -u 1000 \ + nonprivuser && adduser nonprivuser sudo +USER nonprivuser +WORKDIR /home/nonprivuser + +# system packages +RUN sudo apt-get install --no-install-recommends -yq \ + git psmisc build-essential lcov curl netcat-openbsd \ + python3 python3-pip python3-setuptools python3-wheel \ + > /dev/null && \ + sudo apt-get clean -q && \ + sudo ln -s /usr/bin/python3 /usr/bin/python + +RUN pip3 install aiohttp websockets + + diff --git a/LICENSE b/LICENSE index 23e467f..828ae85 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,5 @@ --- Revised 3-Clause BSD License --- -Copyright (C) 2016-2019, SEMTECH (International) AG. -All rights reserved. +Copyright Semtech Corporation 2020. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. + * Neither the name of the Semtech corporation nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 4face9b..7685421 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Basic Station +# LoRa Basics™ Station [Basic Station](https://doc.sm.tc/station) is a LoRaWAN Gateway implementation, including features like diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..f9582f4 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,26 @@ +# Basic Station Feature Roadmap + +## Medium-term outlook + +- **Station-internal health report** + Gateway health reporting is generally not viewed as core functionality of Basic Station. Therefore, it is expected that health and status reports are generated by tools and scripts running on the Gateway base system. Basic Station provides means to submit these reports via a UNIX named pipe to the LNS. In the future, Station will provide a way to generate internal health reports reflecting core metrics of internal components of Basic Station. The reports should be able to be sent periodically, triggered by an on-gateway process and queried by the LNS. + +- **Response to router_config message** + The router_config message contains all the LNS-side configuration for the gateway, in particular the channel plan. Currently, no response to this message is sent by Station. In case of failure, the connection is closed. In the future, Station should respond to the router_config message, proving details in case the configuration could not be applied. + +## Long-term outlook + +- **Built-in AES key derivation for V2 gateways** + On V2 gateways the fine timestamps are encrypted with a chip-specific key. Semtech is moving away from this scheme. In the future, the encryption key will be derived by Basic Station directly and only decrypted fine timestamps are used. + +- **NACK messages for failed TX** + Currently, the Basic Station protocol provides acknowledgements (`dntxed` message) for transmitted downlinks, giving the network server a guarantee that scheduled downlink message was put on air. In cases where the transmission could not be guaranteed, no notification is sent to the server. In the future, the Basic Station will provide feedback for dropped frame indicating the reason. + +- **Protobuf message encoding** + Currently, the Basic Station Protocol uses JSON encoding for the messages exchanged over Websockets. In situations where backhaul connection bandwidth is scarce a more efficient encoding is desirable. First tests have shown that using "Protocol Buffers" encoding can reduce the message size of the most common messages by up to 70%. + +- **Low-level PHY control option** + The Basic Station Protocol operates on LoRaWAN semantics, which allows LoRaWAN network server to abstract away all PHY layer control. In some situations, LoRaWAN network servers may want to have more fine-grained control over the PHY in order to support proprietary messages for example. It needs to be explored how the Basic Station protocol can provide the choice for lower-level control transparently while not forcing deep PHY knowledge on all protocol users. + +- **Forwarding of non-LoRaWAN messages to separate on-gateway process** + Currently, Basic Station drops non-LoRaWAN messages. In cases where LoRaWAN solutions are augmented with proprietary messages, it may be beneficial to allow processing these messages locally on the gateway. To facilitate on-gateway processing, Basic Station will have an option to forward non-LoRaWAN messages to a gateway-local destination. diff --git a/VERSION.txt b/VERSION.txt index 50ffc5a..f1e4c70 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -2.0.3 +2.0.4-9-g3d5c686 diff --git a/deps/lgw/.gitignore b/deps/lgw/.gitignore new file mode 100644 index 0000000..f6f9172 --- /dev/null +++ b/deps/lgw/.gitignore @@ -0,0 +1,2 @@ +git-repo +platform-*/ diff --git a/deps/lgw/makefile b/deps/lgw/makefile index c4c568c..a7e93c6 100644 --- a/deps/lgw/makefile +++ b/deps/lgw/makefile @@ -1,3 +1,28 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TD=../.. include ${TD}/setup.gmk @@ -6,6 +31,9 @@ PLT=platform-${platform} LGWLIB=${TD}/${BD}/lib/liblgw.a LGWINC=${TD}/${BD}/include/lgw +LGWVERSION.default = 5.0.1 +LGWVERSION ?= $(or ${LGWVERSION.${platform}}, ${LGWVERSION.default}) + HFILES = $(wildcard ${PLT}/libloragw/inc/*.h) SRCS = $(wildcard ${PLT}/libloragw/inc/*.c) ARTEFACTS = ${LGWLIB} ${LGWINC} $(patsubst %, ${LGWINC}/%, $(notdir ${HFILES}) config.h) @@ -31,7 +59,7 @@ ${LGWINC}/%.h: ${PLT}/libloragw/inc/%.h | ${LGWINC} @cp $< $@ ${PLT}: prep.sh - platform=${platform} variant=${variant} ./prep.sh + platform=${platform} variant=${variant} lgwversion=${LGWVERSION} ./prep.sh $(MAKE) --no-print-directory all platform=${platform} variant=${variant} clean: diff --git a/deps/lgw/prep.sh b/deps/lgw/prep.sh index 17ef527..53cc788 100755 --- a/deps/lgw/prep.sh +++ b/deps/lgw/prep.sh @@ -1,26 +1,52 @@ #!/bin/bash +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + set -e cd $(dirname $0) -LGW_VERSION=v5.0.1 +lgwversion="v${lgwversion:-5.0.1}" if [[ ! -d git-repo ]]; then - git clone -b $LGW_VERSION --single-branch --depth 1 https://github.com/Lora-net/lora_gateway.git git-repo + git clone https://github.com/Lora-net/lora_gateway.git git-repo fi -if [[ -z "$platform" ]] || [[ -z "$variant" ]]; then +if [[ -z "${platform}" ]] || [[ -z "${variant}" ]]; then echo "Expecting env vars platform/variant to be set - comes naturally if called from a makefile" echo "If calling manually try: variant=std platform=linux $0" exit 1 fi -if [[ ! -d platform-$platform ]]; then - git clone git-repo platform-$platform +if [[ ! -d platform-${platform} ]]; then + git clone -b ${lgwversion} git-repo platform-${platform} - cd platform-$platform - if [ -f ../$LGW_VERSION-$platform.patch ]; then - echo "Applying $LGW_VERSION-$platform.patch ..." - git apply ../$LGW_VERSION-$platform.patch + cd platform-${platform} + if [ -f ../${lgwversion}-${platform}.patch ]; then + echo "Applying ${lgwversion}-${platform}.patch ..." + git apply ../${lgwversion}-${platform}.patch fi fi diff --git a/deps/lgw1302/.gitignore b/deps/lgw1302/.gitignore new file mode 100644 index 0000000..f6f9172 --- /dev/null +++ b/deps/lgw1302/.gitignore @@ -0,0 +1,2 @@ +git-repo +platform-*/ diff --git a/deps/lgw1302/V1.0.5-corecell.patch b/deps/lgw1302/V1.0.5-corecell.patch new file mode 100644 index 0000000..27caa24 --- /dev/null +++ b/deps/lgw1302/V1.0.5-corecell.patch @@ -0,0 +1,300 @@ +diff --git a/libloragw/Makefile b/libloragw/Makefile +index 262167a..45b7444 100644 +--- a/libloragw/Makefile ++++ b/libloragw/Makefile +@@ -12,6 +12,7 @@ CC := $(CROSS_COMPILE)gcc + AR := $(CROSS_COMPILE)ar + + CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -I../libtools/inc ++CFLAGS += -DNODEBUG + + OBJDIR = obj + INCLUDES = $(wildcard inc/*.h) $(wildcard ../libtools/inc/*.h) +diff --git a/libloragw/inc/loragw_sx1302_timestamp.h b/libloragw/inc/loragw_sx1302_timestamp.h +index aa6635b..8e5c308 100644 +--- a/libloragw/inc/loragw_sx1302_timestamp.h ++++ b/libloragw/inc/loragw_sx1302_timestamp.h +@@ -43,13 +43,12 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + @struct timestamp_counter_s + @brief context to maintain the internal counters (inst and pps trig) rollover status + */ +-struct timestamp_info_s { +- uint32_t counter_us_27bits_ref; /* reference value (last read) */ +- uint8_t counter_us_27bits_wrap; /* rollover/wrap status */ +-}; + typedef struct timestamp_counter_s { +- struct timestamp_info_s inst; /* holds current reference of the instantaneous counter */ +- struct timestamp_info_s pps; /* holds current reference of the pps-trigged counter */ ++ struct timestamp_info_s { ++ uint32_t counter_subus; ++ int32_t epochs_subus; ++ int64_t clmono_ref; ++ } inst, pps; + } timestamp_counter_t; + + /* -------------------------------------------------------------------------- */ +@@ -73,27 +72,19 @@ void timestamp_counter_delete(timestamp_counter_t * self); + @brief Update the counter wrapping status based on given current counter + @param self Pointer to the counter handler + @param pps Set to true to update the PPS trig counter status +-@param cnt Current value of the counter to be used for the update ++@param cnt Current value of the sub microsecond counter to be used for the update + @return N/A + */ + void timestamp_counter_update(timestamp_counter_t * self, bool pps, uint32_t cnt); + + /** +-@brief Convert the 27-bits counter given by the SX1302 to a 32-bits counter which wraps on a uint32_t. +-@param self Pointer to the counter handler +-@param pps Set to true to expand the counter based on the PPS trig wrapping status +-@param cnt_us The 27-bits counter to be expanded +-@return the 32-bits counter +-*/ +-uint32_t timestamp_counter_expand(timestamp_counter_t * self, bool pps, uint32_t cnt_us); +- +-/** +-@brief Convert the 27-bits packet timestamp to a 32-bits counter which wraps on a uint32_t. +-@param self Pointer to the counter handler +-@param cnt_us The packet 27-bits counter to be expanded +-@return the 32-bits counter ++@brief Convert the 32-bits sub-microsecond counter given by the SX1302 to a 32-bits microsecond counter. ++@param self Pointer to the counter state ++@param pps Set to true to expand the counter based on the PPS trig wrapping status ++@param cnt_subus The 32-bits sub microsecond counter to be converted ++@return the 32-bits microsecond counter + */ +-uint32_t timestamp_pkt_expand(timestamp_counter_t * self, uint32_t cnt_us); ++uint32_t timestamp_counter_expand(timestamp_counter_t * self, bool pps, uint32_t cnt_subus); + + /** + @brief Reads the SX1302 internal counter register, and return the 32-bits 1 MHz counter +diff --git a/libloragw/src/loragw_debug.c b/libloragw/src/loragw_debug.c +index 2415d80..2151332 100644 +--- a/libloragw/src/loragw_debug.c ++++ b/libloragw/src/loragw_debug.c +@@ -29,6 +29,15 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + + #include "tinymt32.h" + ++ ++#if defined(NODEBUG) ++void dbg_init_random(void) {} ++void dbg_init_gpio(void) {} ++void dbg_log_buffer_to_file(FILE * file, uint8_t * buffer, uint16_t size) { (void) file; (void) buffer; (void) size; } ++void dbg_log_payload_diff_to_file(FILE * file, uint8_t * buffer1, uint8_t * buffer2, uint16_t size) { (void) file; (void) buffer1; (void) buffer2; (void) size; } ++int dbg_check_payload(struct lgw_conf_debug_s * context, FILE * file, uint8_t * payload_received, uint8_t size, uint8_t ref_payload_idx, uint8_t sf) {(void) context; (void) file; (void) payload_received; (void) size; (void) ref_payload_idx; (void) sf; return 0;} ++#else ++ + /* -------------------------------------------------------------------------- */ + /* --- DEBUG CONSTANTS ------------------------------------------------------ */ + +@@ -199,3 +208,4 @@ int dbg_check_payload(struct lgw_conf_debug_s * context, FILE * file, uint8_t * + + return 0; /* ignored */ + } ++#endif +diff --git a/libloragw/src/loragw_sx1302.c b/libloragw/src/loragw_sx1302.c +index 251fb36..6e1ce4d 100644 +--- a/libloragw/src/loragw_sx1302.c ++++ b/libloragw/src/loragw_sx1302.c +@@ -1812,17 +1812,24 @@ int sx1302_parse(lgw_context_t * context, struct lgw_pkt_rx_s * p) { + timestamp_correction = 0; + } + +- /* Update counter reference / wrap status before expanding */ +- timestamp_counter_get(&counter_us, false); ++ /* Convert sub-us value into micros and do correction */ ++ p->count_us = timestamp_counter_expand(&counter_us, false, pkt.timestamp_cnt) - timestamp_correction; + +- /* Scale 32 MHz packet timestamp to 1 MHz (microseconds) */ +- p->count_us = pkt.timestamp_cnt / 32; +- +- /* Expand 27-bits counter to 32-bits counter, based on current wrapping status */ +- p->count_us = timestamp_pkt_expand(&counter_us, p->count_us); +- +- /* Packet timestamp corrected */ +- p->count_us = p->count_us - timestamp_correction; ++#if 0 // debug code to check for failed submicros/micros handling ++ { ++ static uint32_t last_valid = 0; ++ static uint32_t last_us32 = 0; ++ int32_t diff = p->count_us - last_us32; ++ printf("XXXXXXXXXXXXXXXX pkt=%08X last=%08X diff=%08X/%d seqno=%04X\n", ++ p->count_us, last_us32, diff, diff, (p->payload[1]<<8)|p->payload[2]); ++ if( last_valid && diff > 30000000 ) { ++ printf("XXXXXXXXXXXXXXXX ERROR jump ahead count_us\n"); ++ exit(1); ++ } ++ last_us32 = p->count_us; ++ last_valid = 1; ++ } ++#endif + + /* Packet CRC status */ + p->crc = pkt.rx_crc16_value; +diff --git a/libloragw/src/loragw_sx1302_timestamp.c b/libloragw/src/loragw_sx1302_timestamp.c +index 77c3d4d..487283f 100644 +--- a/libloragw/src/loragw_sx1302_timestamp.c ++++ b/libloragw/src/loragw_sx1302_timestamp.c +@@ -21,9 +21,11 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + /* -------------------------------------------------------------------------- */ + /* --- DEPENDANCIES --------------------------------------------------------- */ + ++#define _POSIX_C_SOURCE 199309L + #include /* C99 types */ + #include /* printf fprintf */ + #include /* memset */ ++#include /* clock monotonic */ + + #include "loragw_sx1302_timestamp.h" + #include "loragw_reg.h" +@@ -62,6 +64,16 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + /* -------------------------------------------------------------------------- */ + /* --- PRIVATE FUNCTIONS DEFINITION ----------------------------------------- */ + ++static int64_t clock_monotonic() { ++ struct timespec ts; ++ if( clock_gettime(CLOCK_MONOTONIC, &ts) != 0 ) { ++ printf("ERROR: clock_gettime(CLOCK_MONOTONIC, ..) failed!\n"); ++ return 0; ++ } ++ /* Return subus resolution - rounded, +1 makes sure 0 is never returned */ ++ return ((ts.tv_sec+1)*1000000000LL + ts.tv_nsec + 16) / 32; ++} ++ + /* -------------------------------------------------------------------------- */ + /* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */ + +@@ -77,17 +89,36 @@ void timestamp_counter_delete(timestamp_counter_t * self) { + + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +-void timestamp_counter_update(timestamp_counter_t * self, bool pps, uint32_t cnt) { +- struct timestamp_info_s* tinfo = (pps == true) ? &self->pps : &self->inst; +- +- /* Check if counter has wrapped, and update wrap status if necessary */ +- if (cnt < tinfo->counter_us_27bits_ref) { +- tinfo->counter_us_27bits_wrap += 1; +- tinfo->counter_us_27bits_wrap %= 32; ++void timestamp_counter_update(timestamp_counter_t * self, bool pps, uint32_t cnt_subus) { ++ struct timestamp_info_s* tinfo = pps ? &self->pps : &self->inst; ++ int64_t now = clock_monotonic(); ++ if( tinfo->clmono_ref == 0 ) { ++ tinfo->clmono_ref = now; ++ tinfo->counter_subus = cnt_subus; ++ return; + } +- +- /* Update counter reference */ +- tinfo->counter_us_27bits_ref = cnt; ++ /* ++ * Let m1,m2 be previous/current clock monotonic (64bit) ++ * and u1,u2 corresponding 32bit submicrosecond recordings from SX1302 ++ * There are the following errors to consider: ++ * e1 = (int32_t)(m1-u1) ++ * e2 = (int32_t)(m2-u2) ++ * e1,e2 are related to local CPU processing jitter since the time between clock_monotonic() and ++ * the retrieval of the submicrosecond counter varies due to processing overhead. ++ * e3 = (int2_t)((uint32_t)(u2-u1) - (uint32_t)(m2-m2)) ++ * e3 is the CPU clock drift against the submicrosecond counter. ++ * E=e1+e2+e3 is significantly smaller than 2^31 submicroseconds (<<<~67s) ++ * The assumption is that the submicrosecond counter may have rolled over possibly multiple times ++ * betwen calls to timestamp_counter_update(). ++ * Thus: ++ * m2-m1 = k*2^32 + (uint32_t)(u2-u1) + E ++ * and the number of rollovers is calculated as: ++ * k*2^32 = (m2-m1) - (uint32_t)(u2-u1) - E and -2^31 <<< E <<< 2^31 ++ */ ++ int64_t diff = now - tinfo->clmono_ref - (uint32_t)(cnt_subus - tinfo->counter_subus); ++ tinfo->epochs_subus += ((diff + (1U<<31)) >> 32) + (cnt_subus < tinfo->counter_subus ? 1:0); ++ tinfo->counter_subus = cnt_subus; ++ tinfo->clmono_ref = now; + } + + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +@@ -95,7 +126,7 @@ void timestamp_counter_update(timestamp_counter_t * self, bool pps, uint32_t cnt + uint32_t timestamp_counter_get(timestamp_counter_t * self, bool pps) { + int x; + uint8_t buff[4]; +- uint32_t counter_us_raw_27bits_now; ++ uint32_t counter_subus; + int32_t msb; + + /* Get the 32MHz timestamp counter - 4 bytes */ +@@ -128,25 +159,22 @@ uint32_t timestamp_counter_get(timestamp_counter_t * self, bool pps) { + } + } + +- counter_us_raw_27bits_now = (buff[0]<<24) | (buff[1]<<16) | (buff[2]<<8) | buff[3]; +- +- /* Scale to 1MHz */ +- counter_us_raw_27bits_now /= 32; ++ counter_subus = (buff[0]<<24) | (buff[1]<<16) | (buff[2]<<8) | buff[3]; + + /* Update counter wrapping status */ +- timestamp_counter_update(self, pps, counter_us_raw_27bits_now); ++ timestamp_counter_update(self, pps, counter_subus); + +- /* Convert 27-bits counter to 32-bits counter */ +- return timestamp_counter_expand(self, pps, counter_us_raw_27bits_now); ++ /* Convert 1/32 microsecond to microsecond counter */ ++ return timestamp_counter_expand(self, pps, counter_subus); + } + + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +-uint32_t timestamp_counter_expand(timestamp_counter_t * self, bool pps, uint32_t cnt_us) { ++uint32_t timestamp_counter_expand(timestamp_counter_t * self, bool pps, uint32_t cnt_subus) { + struct timestamp_info_s* tinfo = (pps == true) ? &self->pps : &self->inst; +- uint32_t counter_us_32bits; +- +- counter_us_32bits = (tinfo->counter_us_27bits_wrap << 27) | cnt_us; ++ /* Convert submicroseconds (1/32us = 31.25ns) into microseconds */ ++ int32_t delta_subus = (int32_t)(cnt_subus - tinfo->counter_subus); /* this *must* be a 32bit signed value */ ++ uint32_t counter_us_32bits = (((int64_t)tinfo->epochs_subus << 32) + tinfo->counter_subus + delta_subus) >> 5; + + #if 0 + /* DEBUG: to be enabled when running test_loragw_counter test application +@@ -154,41 +182,13 @@ uint32_t timestamp_counter_expand(timestamp_counter_t * self, bool pps, uint32_t + > set datafile separator comma + > plot for [col=1:2:1] 'log_count.txt' using col with lines + */ +- printf("%u,%u,%u\n", cnt_us, counter_us_32bits, tinfo->counter_us_27bits_wrap); ++ printf("%u,%u,%llu\n", cnt_subus, counter_us_32bits, tinfo->counter_subus); + #endif + + return counter_us_32bits; + } + + +-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +- +-uint32_t timestamp_pkt_expand(timestamp_counter_t * self, uint32_t pkt_cnt_us) { +- struct timestamp_info_s* tinfo = &self->inst; +- uint32_t counter_us_32bits; +- uint8_t wrap_status; +- +- /* Check if counter has wrapped since the packet has been received in the sx1302 internal FIFO */ +- /* If the sx1302 counter was greater than the pkt timestamp, it means that the internal counter +- hasn't rolled over since the packet has been received by the sx1302 +- case 1: --|-P--|----|--R-|----|--||-|----|-- : use current wrap status counter +- case 2: --|-P-||-|-R--|-- : use previous wrap status counter +- P : packet received in sx1302 internal FIFO +- R : read packet from sx1302 internal FIFO +- | : last update internal counter ref value. +- ||: sx1302 internal counter rollover (wrap) +- */ +- +- /* Use current wrap counter or previous ? */ +- wrap_status = tinfo->counter_us_27bits_wrap - ((tinfo->counter_us_27bits_ref >= pkt_cnt_us) ? 0 : 1); +- wrap_status &= 0x1F; /* [0..31] */ +- +- /* Expand packet counter */ +- counter_us_32bits = (wrap_status << 27) | pkt_cnt_us; +- +- return counter_us_32bits; +-} +- + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + + int timestamp_counter_mode(bool enable_precision_ts, uint8_t max_ts_metrics, uint8_t nb_symbols) { diff --git a/deps/lgw1302/makefile b/deps/lgw1302/makefile new file mode 100644 index 0000000..2bac66b --- /dev/null +++ b/deps/lgw1302/makefile @@ -0,0 +1,72 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +TD=../.. +include ${TD}/setup.gmk +PLT=platform-${platform} + +LGWLIB=${TD}/${BD}/lib/liblgw1302.a +LGWINC=${TD}/${BD}/include/lgw + +LGWVERSION.default = 1.0.5 +LGWVERSION ?= $(or ${LGWVERSION.${platform}}, ${LGWVERSION.default}) + +HFILES = $(wildcard ${PLT}/libloragw/inc/*.h) +SRCS = $(wildcard ${PLT}/libloragw/src/*.c) +ARTEFACTS = ${LGWLIB} ${LGWINC} $(patsubst %, ${LGWINC}/%, $(notdir ${HFILES}) config.h) + +all: $(if ${HFILES},${ARTEFACTS},${PLT}) + +${LGWINC}: + @mkdir -p $@ + +${LGWLIB}: ${PLT}/libloragw/libloragw.a + @mkdir -p ${@D} + @echo " CP ${ $@" + @cp $< $@ + +${PLT}/libloragw/libloragw.a: ${SRCS} ${HFILES} + ${MAKE} -C ${PLT}/libloragw libloragw.a CC=${CC} AR=${AR} LD=${LD} TDfull=${TDfull} + +${PLT}/libloragw/inc/config.h: ${PLT}/libloragw/library.cfg + ${MAKE} -C ${PLT}/libloragw inc/config.h CC=${CC} AR=${AR} LD=${LD} TDfull=${TDfull} + +${LGWINC}/%.h: ${PLT}/libloragw/inc/%.h | ${LGWINC} + @echo " CP ${ $@" + @cp $< $@ + +${PLT}: prep.sh + platform=${platform} variant=${variant} lgwversion=${LGWVERSION} ./prep.sh + $(MAKE) --no-print-directory all platform=${platform} variant=${variant} + +clean: + rm -rf ${ARTEFACTS} + if [ -d ${PLT} ]; then ${MAKE} -C ${PLT}/libloragw clean; fi + +super-clean: clean + rm -rf git-repo platform-* + +.PHONY: all clean super-clean platform-${platform} diff --git a/deps/lgw1302/prep.sh b/deps/lgw1302/prep.sh new file mode 100755 index 0000000..e2f2fe3 --- /dev/null +++ b/deps/lgw1302/prep.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -e +cd $(dirname $0) + +lgwversion="V${lgwversion:-1.0.5}" + +if [[ ! -d git-repo ]]; then + git clone https://github.com/Lora-net/sx1302_hal.git git-repo +fi + +if [[ -z "${platform}" ]] || [[ -z "${variant}" ]]; then + echo "Expecting env vars platform/variant to be set - comes naturally if called from a makefile" + echo "If calling manually try: variant=std platform=corecell $0" + exit 1 +fi + +if [[ ! -d platform-${platform} ]]; then + (cd git-repo && git checkout tags/${lgwversion}) + git clone -b ${lgwversion} git-repo platform-${platform} + + cd platform-${platform} + if [ -f ../${lgwversion}-${platform}.patch ]; then + echo "Applying ${lgwversion}-${platform}.patch ..." + git apply ../${lgwversion}-${platform}.patch + fi +fi diff --git a/deps/mbedtls/.gitignore b/deps/mbedtls/.gitignore new file mode 100644 index 0000000..c78c731 --- /dev/null +++ b/deps/mbedtls/.gitignore @@ -0,0 +1,2 @@ +git-repo +platform-* diff --git a/deps/mbedtls/makefile b/deps/mbedtls/makefile index 43836a8..841c352 100644 --- a/deps/mbedtls/makefile +++ b/deps/mbedtls/makefile @@ -1,3 +1,28 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TD=../.. include ${TD}/setup.gmk @@ -15,7 +40,7 @@ ${MBEDINC}: @mkdir -p $@ ${PLT}/library/%.a: ${PLT} - ${MAKE} -C $< lib CC=${CC} AR=${AR} LD=${LD} + ${MAKE} -C $< lib CC="${CC}" AR="${AR}" LD="${LD}" ${TD}/${BD}/lib/%.a: ${PLT}/library/%.a @mkdir -p ${@D} diff --git a/deps/mbedtls/prep.sh b/deps/mbedtls/prep.sh index 0a14646..2875cd7 100755 --- a/deps/mbedtls/prep.sh +++ b/deps/mbedtls/prep.sh @@ -1,5 +1,31 @@ #!/bin/bash +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + set -e cd $(dirname $0) diff --git a/deps/smtcpico/.gitignore b/deps/smtcpico/.gitignore new file mode 100644 index 0000000..f6f9172 --- /dev/null +++ b/deps/smtcpico/.gitignore @@ -0,0 +1,2 @@ +git-repo +platform-*/ diff --git a/deps/smtcpico/V0.2.2-linuxpico.patch b/deps/smtcpico/V0.2.2-linuxpico.patch new file mode 100644 index 0000000..587e16c --- /dev/null +++ b/deps/smtcpico/V0.2.2-linuxpico.patch @@ -0,0 +1,463 @@ +diff --git a/libloragw/inc/loragw_fpga.h b/libloragw/inc/loragw_fpga.h +new file mode 100644 +index 0000000..f599f73 +--- /dev/null ++++ b/libloragw/inc/loragw_fpga.h +@@ -0,0 +1,135 @@ ++/* ++ / _____) _ | | ++( (____ _____ ____ _| |_ _____ ____| |__ ++ \____ \| ___ | (_ _) ___ |/ ___) _ \ ++ _____) ) ____| | | || |_| ____( (___| | | | ++(______/|_____)_|_|_| \__)_____)\____)_| |_| ++ (C)2013 Semtech-Cycleo ++ ++Description: ++ Functions used to handle FPGA register access for LoRa concentrator. ++ Registers are addressed by name. ++ Multi-bytes registers are handled automatically. ++ Read-modify-write is handled automatically. ++ ++License: Revised BSD License, see LICENSE.TXT file include in the project ++Maintainer: Michael Coracin ++*/ ++ ++#ifndef _LORAGW_FPGA_REG_H ++#define _LORAGW_FPGA_REG_H ++ ++/* -------------------------------------------------------------------------- */ ++/* --- DEPENDANCIES --------------------------------------------------------- */ ++ ++#include /* C99 types */ ++#include /* bool type */ ++ ++/* -------------------------------------------------------------------------- */ ++/* --- PUBLIC CONSTANTS ----------------------------------------------------- */ ++ ++#define LGW_REG_SUCCESS 0 ++#define LGW_REG_ERROR -1 ++ ++#define LGW_MIN_NOTCH_FREQ 126000U /* 126 KHz */ ++#define LGW_MAX_NOTCH_FREQ 250000U /* 250 KHz */ ++#define LGW_DEFAULT_NOTCH_FREQ 129000U /* 129 KHz */ ++ ++/* ++auto generated register mapping for C code ++this file contains autogenerated C struct used to access the FPGA registers ++this file is autogenerated from registers description ++*/ ++ ++#define LGW_FPGA_SOFT_RESET 0 ++#define LGW_FPGA_FEATURE 1 ++#define LGW_FPGA_LBT_INITIAL_FREQ 2 ++#define LGW_FPGA_VERSION 3 ++#define LGW_FPGA_STATUS 4 ++#define LGW_FPGA_CTRL_FEATURE_START 5 ++#define LGW_FPGA_CTRL_RADIO_RESET 6 ++#define LGW_FPGA_CTRL_INPUT_SYNC_I 7 ++#define LGW_FPGA_CTRL_INPUT_SYNC_Q 8 ++#define LGW_FPGA_CTRL_OUTPUT_SYNC 9 ++#define LGW_FPGA_CTRL_INVERT_IQ 10 ++#define LGW_FPGA_CTRL_ACCESS_HISTO_MEM 11 ++#define LGW_FPGA_CTRL_CLEAR_HISTO_MEM 12 ++#define LGW_FPGA_HISTO_RAM_ADDR 13 ++#define LGW_FPGA_HISTO_RAM_DATA 14 ++#define LGW_FPGA_HISTO_NB_READ 15 ++#define LGW_FPGA_LBT_TIMESTAMP_CH 16 ++#define LGW_FPGA_LBT_TIMESTAMP_SELECT_CH 17 ++#define LGW_FPGA_LBT_CH0_FREQ_OFFSET 18 ++#define LGW_FPGA_LBT_CH1_FREQ_OFFSET 19 ++#define LGW_FPGA_LBT_CH2_FREQ_OFFSET 20 ++#define LGW_FPGA_LBT_CH3_FREQ_OFFSET 21 ++#define LGW_FPGA_LBT_CH4_FREQ_OFFSET 22 ++#define LGW_FPGA_LBT_CH5_FREQ_OFFSET 23 ++#define LGW_FPGA_LBT_CH6_FREQ_OFFSET 24 ++#define LGW_FPGA_LBT_CH7_FREQ_OFFSET 25 ++#define LGW_FPGA_SCAN_FREQ_OFFSET 26 ++#define LGW_FPGA_LBT_SCAN_TIME_CH0 27 ++#define LGW_FPGA_LBT_SCAN_TIME_CH1 28 ++#define LGW_FPGA_LBT_SCAN_TIME_CH2 29 ++#define LGW_FPGA_LBT_SCAN_TIME_CH3 30 ++#define LGW_FPGA_LBT_SCAN_TIME_CH4 31 ++#define LGW_FPGA_LBT_SCAN_TIME_CH5 32 ++#define LGW_FPGA_LBT_SCAN_TIME_CH6 33 ++#define LGW_FPGA_LBT_SCAN_TIME_CH7 34 ++#define LGW_FPGA_RSSI_TARGET 35 ++#define LGW_FPGA_HISTO_SCAN_FREQ 36 ++#define LGW_FPGA_NOTCH_FREQ_OFFSET 37 ++#define LGW_FPGA_TOTALREGS 38 ++ ++/* -------------------------------------------------------------------------- */ ++/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */ ++ ++/** ++@brief LoRa concentrator TX notch filter delay ++@return delay in microseconds introduced by TX notch filter ++*/ ++float lgw_fpga_get_tx_notch_delay(void); ++ ++/** ++@brief LoRa concentrator FPGA configuration ++@param tx_notch_freq TX notch filter frequency, in Hertz ++@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR) ++*/ ++int lgw_fpga_configure(uint32_t tx_notch_freq); ++ ++/** ++@brief LoRa concentrator FPGA register write ++@param register_id register number in the data structure describing registers ++@param reg_value signed value to write to the register (for u32, use cast) ++@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR) ++*/ ++int lgw_fpga_reg_w(uint16_t register_id, int32_t reg_value); ++ ++/** ++@brief LoRa concentrator FPGA register read ++@param register_id register number in the data structure describing registers ++@param reg_value pointer to a variable where to write register read value ++@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR) ++*/ ++int lgw_fpga_reg_r(uint16_t register_id, int32_t *reg_value); ++ ++/** ++@brief LoRa concentrator FPGA register burst write ++@param register_id register number in the data structure describing registers ++@param data pointer to byte array that will be sent to the LoRa concentrator ++@param size size of the transfer, in byte(s) ++@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR) ++*/ ++int lgw_fpga_reg_wb(uint16_t register_id, uint8_t *data, uint16_t size); ++ ++/** ++@brief LoRa concentrator FPGA register burst read ++@param register_id register number in the data structure describing registers ++@param data pointer to byte array that will be written from the LoRa concentrator ++@param size size of the transfer, in byte(s) ++@return status of register operation (LGW_REG_SUCCESS/LGW_REG_ERROR) ++*/ ++int lgw_fpga_reg_rb(uint16_t register_id, uint8_t *data, uint16_t size); ++ ++#endif ++/* --- EOF ------------------------------------------------------------------ */ +diff --git a/libloragw/inc/loragw_hal.h b/libloragw/inc/loragw_hal.h +index 080867c..01d7eb3 100644 +--- a/libloragw/inc/loragw_hal.h ++++ b/libloragw/inc/loragw_hal.h +@@ -44,6 +44,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + /* return status code */ + #define LGW_HAL_SUCCESS 0 + #define LGW_HAL_ERROR -1 ++#define LGW_LBT_ISSUE 1 + + /* radio-specific parameters */ + #define LGW_XTAL_FREQU 32000000 /* frequency of the RF reference oscillator */ +@@ -151,6 +152,9 @@ License: Revised BSD License, see LICENSE.TXT file include in the project + /* Maximum size of Tx gain LUT */ + #define TX_GAIN_LUT_SIZE_MAX 16 + ++/* LBT constants */ ++#define LBT_CHANNEL_FREQ_NB 8 /* Number of LBT channels */ ++ + /* -------------------------------------------------------------------------- */ + /* --- PUBLIC TYPES --------------------------------------------------------- */ + +@@ -175,6 +179,27 @@ struct lgw_conf_board_s { + uint8_t clksrc; /*!> Index of RF chain which provides clock to concentrator */ + }; + ++/** ++@struct lgw_conf_lbt_chan_s ++@brief Configuration structure for LBT channels ++*/ ++struct lgw_conf_lbt_chan_s { ++ uint32_t freq_hz; ++ uint16_t scan_time_us; ++}; ++ ++/** ++@struct lgw_conf_lbt_s ++@brief Configuration structure for LBT specificities ++*/ ++struct lgw_conf_lbt_s { ++ bool enable; /*!> enable or disable LBT */ ++ int8_t rssi_target; /*!> RSSI threshold to detect if channel is busy or not (dBm) */ ++ uint8_t nb_channel; /*!> number of LBT channels */ ++ struct lgw_conf_lbt_chan_s channels[LBT_CHANNEL_FREQ_NB]; ++ int8_t rssi_offset; /*!> RSSI offset to be applied to SX127x RSSI values */ ++}; ++ + /** + @struct lgw_conf_rxrf_s + @brief Configuration structure for a RF chain +@@ -185,6 +210,7 @@ struct lgw_conf_rxrf_s { + float rssi_offset; /*!> Board-specific RSSI correction factor */ + enum lgw_radio_type_e type; /*!> Radio type for that RF chain (SX1255, SX1257....) */ + bool tx_enable; /*!> enable or disable TX on that RF chain */ ++ uint32_t tx_notch_freq; /*!> TX notch filter frequency [126KHz..250KHz] */ + }; + + /** +@@ -387,6 +413,12 @@ int lgw_mcu_version_info(void); + */ + uint32_t lgw_time_on_air(struct lgw_pkt_tx_s *packet); + ++extern uint8_t lgwx_device_mode; ++extern uint8_t lgwx_beacon_len; ++extern uint8_t lgwx_beacon_sf; ++extern uint8_t lgwx_lbt_mode; ++enum { LGWX_LBT_MODE_DFLT=0, LGWX_LBT_MODE_OFF = 1 }; ++ + #endif + + /* --- EOF ------------------------------------------------------------------ */ +diff --git a/libloragw/inc/loragw_lbt.h b/libloragw/inc/loragw_lbt.h +new file mode 100644 +index 0000000..aa04060 +--- /dev/null ++++ b/libloragw/inc/loragw_lbt.h +@@ -0,0 +1,73 @@ ++/* ++ / _____) _ | | ++( (____ _____ ____ _| |_ _____ ____| |__ ++ \____ \| ___ | (_ _) ___ |/ ___) _ \ ++ _____) ) ____| | | || |_| ____( (___| | | | ++(______/|_____)_|_|_| \__)_____)\____)_| |_| ++ (C)2013 Semtech-Cycleo ++ ++Description: ++ Functions used to handle the Listen Before Talk feature ++ ++License: Revised BSD License, see LICENSE.TXT file include in the project ++Maintainer: Michael Coracin ++*/ ++ ++#ifndef _LORAGW_LBT_H ++#define _LORAGW_LBT_H ++ ++/* -------------------------------------------------------------------------- */ ++/* --- DEPENDANCIES --------------------------------------------------------- */ ++ ++#include /* C99 types */ ++#include /* bool type */ ++ ++#include "loragw_hal.h" ++ ++/* -------------------------------------------------------------------------- */ ++/* --- PUBLIC CONSTANTS ----------------------------------------------------- */ ++ ++#define LGW_LBT_SUCCESS 0 ++#define LGW_LBT_ERROR -1 ++ ++// Originally in loragw_hal.h ++int lgw_lbt_setconf(struct lgw_conf_lbt_s conf); ++ ++/* -------------------------------------------------------------------------- */ ++/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */ ++ ++/** ++@brief Set the configuration parameters for LBT feature ++@param conf structure containing the configuration parameters ++@return LGW_LBT_ERROR id the operation failed, LGW_LBT_SUCCESS else ++*/ ++int lbt_setconf(struct lgw_conf_lbt_s * conf); ++ ++/** ++@brief Configure the concentrator for LBT feature ++@return LGW_LBT_ERROR id the operation failed, LGW_LBT_SUCCESS else ++*/ ++int lbt_setup(void); ++ ++/** ++@brief Start the LBT FSM ++@return LGW_LBT_ERROR id the operation failed, LGW_LBT_SUCCESS else ++*/ ++int lbt_start(void); ++ ++/** ++@brief Configure the concentrator for LBT feature ++@param pkt_data pointer to downlink packet to be trabsmitted ++@param tx_allowed pointer to receive permission for transmission ++@return LGW_LBT_ERROR id the operation failed, LGW_LBT_SUCCESS else ++*/ ++int lbt_is_channel_free(struct lgw_pkt_tx_s * pkt_data, uint16_t tx_start_delay, bool * tx_allowed); ++ ++/** ++@brief Check if LBT is enabled ++@return true if enabled, false otherwise ++*/ ++bool lbt_is_enabled(void); ++ ++#endif ++/* --- EOF ------------------------------------------------------------------ */ +diff --git a/libloragw/src/loragw_hal.c b/libloragw/src/loragw_hal.c +index 2c46381..a4e4b85 100644 +--- a/libloragw/src/loragw_hal.c ++++ b/libloragw/src/loragw_hal.c +@@ -225,11 +225,18 @@ int load_firmware(uint8_t target, uint8_t *firmware, uint16_t size) { + + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + ++uint8_t lgwx_device_mode = 0; ++uint8_t lgwx_beacon_len = 0; ++uint8_t lgwx_beacon_sf = 0; ++uint8_t lgwx_lbt_mode = 0; ++ + void lgw_constant_adjust(void) { + + /* I/Q path setup */ + // lgw_reg_w(LGW_RX_INVERT_IQ,0); /* default 0 */ + // lgw_reg_w(LGW_MODEM_INVERT_IQ,1); /* default 1 */ ++ if( lgwx_device_mode ) ++ lgw_reg_w(LGW_MODEM_INVERT_IQ,0); + // lgw_reg_w(LGW_CHIRP_INVERT_RX,1); /* default 1 */ + // lgw_reg_w(LGW_RX_EDGE_SELECT,0); /* default 0 */ + // lgw_reg_w(LGW_MBWSSF_MODEM_INVERT_IQ,0); /* default 0 */ +@@ -279,6 +286,8 @@ void lgw_constant_adjust(void) { + + // lgw_reg_w(LGW_PREAMBLE_FINE_TIMING_GAIN,1); /* default 1 */ + // lgw_reg_w(LGW_ONLY_CRC_EN,1); /* default 1 */ ++ if( lgwx_device_mode ) ++ lgw_reg_w(LGW_ONLY_CRC_EN,0); + // lgw_reg_w(LGW_PAYLOAD_FINE_TIMING_GAIN,2); /* default 2 */ + // lgw_reg_w(LGW_TRACKING_INTEGRAL,0); /* default 0 */ + // lgw_reg_w(LGW_ADJUST_MODEM_START_OFFSET_RDX8,0); /* default 0 */ +@@ -299,11 +308,24 @@ void lgw_constant_adjust(void) { + lgw_reg_w(LGW_MBWSSF_FRAME_SYNCH_PEAK2_POS, 2); /* default 2 */ + } + // lgw_reg_w(LGW_MBWSSF_ONLY_CRC_EN,1); /* default 1 */ ++ if( lgwx_device_mode ) ++ lgw_reg_w(LGW_MBWSSF_ONLY_CRC_EN,0); + // lgw_reg_w(LGW_MBWSSF_PAYLOAD_FINE_TIMING_GAIN,2); /* default 2 */ + // lgw_reg_w(LGW_MBWSSF_PREAMBLE_FINE_TIMING_GAIN,1); /* default 1 */ + // lgw_reg_w(LGW_MBWSSF_TRACKING_INTEGRAL,0); /* default 0 */ + // lgw_reg_w(LGW_MBWSSF_AGC_FREEZE_ON_DETECT,1); /* default 1 */ + ++ if( lgwx_device_mode && lgwx_beacon_len ) { ++ lgw_reg_w(LGW_MBWSSF_MODEM_INVERT_IQ,0); ++ lgw_reg_w(LGW_MBWSSF_RATE_SF, lgwx_beacon_sf); ++ lgw_reg_w(LGW_MBWSSF_IMPLICIT_HEADER,1); /* no header */ ++ lgw_reg_w(LGW_MBWSSF_IMPLICIT_CRC_EN,0); ++ lgw_reg_w(LGW_MBWSSF_IMPLICIT_CODING_RATE,1); ++ lgw_reg_w(LGW_MBWSSF_IMPLICIT_PAYLOAD_LENGHT, lgwx_beacon_len); ++ } else { ++ lgw_reg_w(LGW_MBWSSF_MODEM_INVERT_IQ,1); //XXX:? correct? ++ } ++ + /* Improvement of reference clock frequency error tolerance */ + lgw_reg_w(LGW_ADJUST_MODEM_START_OFFSET_RDX4, 1); /* default 0 */ + lgw_reg_w(LGW_ADJUST_MODEM_START_OFFSET_SF12_RDX4, 4094); /* default 4092 */ +@@ -587,6 +609,11 @@ int lgw_board_setconf(struct lgw_conf_board_s conf) { + return lgw_mcu_board_setconf(conf); + } + ++int lgw_lbt_setconf (struct lgw_conf_lbt_s conf) { ++ (void) conf; ++ return LGW_HAL_ERROR; ++} ++ + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + + int lgw_rxrf_setconf(uint8_t rf_chain, struct lgw_conf_rxrf_s conf) { +@@ -1154,6 +1181,11 @@ int lgw_send(struct lgw_pkt_tx_s pkt_data) { + return LGW_HAL_ERROR; + } + ++ if( lgwx_device_mode ) { ++ pkt_data.invert_pol = false; ++ pkt_data.no_crc = false; ++ } ++ + /* send packet data to concentrator MCU */ + return lgw_mcu_send(pkt_data); + } +diff --git a/libloragw/src/loragw_com_linux.c b/libloragw/src/loragw_com_linux.c +index 4ef7e37..d708321 100644 +--- a/libloragw/src/loragw_com_linux.c ++++ b/libloragw/src/loragw_com_linux.c +@@ -205,6 +205,7 @@ int lgw_com_receive_ans_linux(lgw_com_ans_t *ans, lgw_handle_t handle) { + size_t cmd_size; + ssize_t buf_size = 0; + ssize_t lencheck; ++ int readtries = 0; + + /* Initialize variables */ + memset(bufferrx, 0, sizeof bufferrx); +@@ -213,8 +214,17 @@ int lgw_com_receive_ans_linux(lgw_com_ans_t *ans, lgw_handle_t handle) { + buffer_idx = 0; + while ((checkcmd_linux(bufferrx[0]) != true) || (buffer_idx < CMD_HEADER_RX_SIZE)) { + lencheck = read(handle, &bufferrx[buffer_idx], CMD_HEADER_RX_SIZE - buffer_idx); +- if (lencheck < 0) { +- DEBUG_PRINTF("WARNING: failed to read from communication bridge (%d - %s), retry...\n", errno, strerror(errno)); ++ if (lencheck==0) { ++ // In case of non-blocking IO we may get 0 bytes back ++ if( ++readtries > 4 ) { ++ printf("ERROR: failed to read from communication bridge - no data\n"); ++ return LGW_COM_ERROR; ++ } ++ wait_ns_linux(250000); ++ } ++ else if (lencheck < 0) { ++ //DEBUG_PRINTF("WARNING: failed to read from communication bridge (%d - %s), retry...\n", errno, strerror(errno)); ++ printf("ERROR: failed to read from communication bridge (%d - %s), retry...\n", errno, strerror(errno)); + return LGW_COM_ERROR; + } + buffer_idx += lencheck; +@@ -266,9 +276,7 @@ int lgw_com_receive_ans_linux(lgw_com_ans_t *ans, lgw_handle_t handle) { + int lgw_com_open_linux(void **com_target_ptr, const char *com_path) { + + int *usb_device = NULL; +- char portname[50]; +- int x; +- int fd; ++ int fd = -1; + + /*check input variables*/ + CHECK_NULL(com_target_ptr); +@@ -280,26 +288,36 @@ int lgw_com_open_linux(void **com_target_ptr, const char *com_path) { + } + + /* open tty port */ +- sprintf(portname, "%s", com_path); +- fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC); ++ fd = open(com_path, O_RDWR | O_NOCTTY | O_SYNC); + if (fd < 0) { +- printf("ERROR: failed to open COM port %s - %s\n", portname, strerror(errno)); ++ printf("ERROR: failed to open COM port %s - %s\n", com_path, strerror(errno)); + } else { +- x = set_interface_attribs_linux(fd, B115200); +- x |= set_blocking_linux(fd, true); +- if (x != 0) { +- printf("ERROR: failed to configure COM port %s\n", portname); +- free(usb_device); +- return LGW_COM_ERROR; ++ if( set_interface_attribs_linux(fd, B115200) != LGW_COM_SUCCESS || ++ set_blocking_linux(fd, false) != LGW_COM_SUCCESS ) { ++ printf("ERROR: failed to configure COM port %s\n", com_path); ++ goto fail; + } + + *usb_device = fd; + *com_target_ptr = (void*)usb_device; + +- return LGW_COM_SUCCESS; ++ uint8_t eui[8]; ++ int tries = 0; ++ do { ++ int err = lgw_mcu_get_unique_id(eui); // NOTE: uses *com_target_ptr! ++ if( err == LGW_MCU_SUCCESS ) { ++ if( set_blocking_linux(fd, true) != LGW_COM_SUCCESS ) { ++ printf("ERROR: failed to configure COM port %s\n", com_path); ++ goto fail; ++ } ++ return LGW_COM_SUCCESS; ++ } ++ } while( ++tries < 4 ); + } +- ++ fail: ++ close(fd); + free(usb_device); ++ *com_target_ptr = NULL; + return LGW_COM_ERROR; + } + diff --git a/deps/smtcpico/makefile b/deps/smtcpico/makefile new file mode 100644 index 0000000..0afa8d3 --- /dev/null +++ b/deps/smtcpico/makefile @@ -0,0 +1,72 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +TD=../.. +include ${TD}/setup.gmk +PLT=platform-${platform} + +LGWLIB=${TD}/${BD}/lib/liblgw.a +LGWINC=${TD}/${BD}/include/lgw + +LGWVERSION.default = 0.2.2 +LGWVERSION ?= $(or ${LGWVERSION.${platform}}, ${LGWVERSION.default}) + +HFILES = $(wildcard ${PLT}/libloragw/inc/*.h) +SRCS = $(wildcard ${PLT}/libloragw/inc/*.c) +ARTEFACTS = ${LGWLIB} ${LGWINC} $(patsubst %, ${LGWINC}/%, $(notdir ${HFILES}) config.h) + +all: $(if ${HFILES},${ARTEFACTS},${PLT}) + +${LGWINC}: + @mkdir -p $@ + +${LGWLIB}: ${PLT}/libloragw/libloragw.a + @mkdir -p ${@D} + @echo " CP ${ $@" + @cp $< $@ + +${PLT}/libloragw/libloragw.a: ${SRCS} ${HFILES} + ${MAKE} -C ${PLT}/libloragw libloragw.a CC=${CC} AR=${AR} LD=${LD} TDfull=${TDfull} + +${PLT}/libloragw/inc/config.h: ${PLT}/libloragw/library.cfg + ${MAKE} -C ${PLT}/libloragw inc/config.h CC=${CC} AR=${AR} LD=${LD} TDfull=${TDfull} + +${LGWINC}/%.h: ${PLT}/libloragw/inc/%.h | ${LGWINC} + @echo " CP ${ $@" + @cp $< $@ + +${PLT}: prep.sh + platform=${platform} variant=${variant} lgwversion=${LGWVERSION} ./prep.sh + $(MAKE) --no-print-directory all platform=${platform} variant=${variant} + +clean: + rm -rf ${ARTEFACTS} + if [ -d ${PLT} ]; then ${MAKE} -C ${PLT}/libloragw clean; fi + +super-clean: clean + rm -rf git-repo platform-* + +.PHONY: all clean super-clean platform-${platform} diff --git a/deps/smtcpico/prep.sh b/deps/smtcpico/prep.sh new file mode 100755 index 0000000..a531660 --- /dev/null +++ b/deps/smtcpico/prep.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -e +cd $(dirname $0) + +lgwversion="V${lgwversion:-0.2.2}" + +if [[ ! -d git-repo ]]; then + git clone https://github.com/Lora-net/picoGW_hal.git git-repo +fi + +if [[ -z "${platform}" ]] || [[ -z "${variant}" ]]; then + echo "Expecting env vars platform/variant to be set - comes naturally if called from a makefile" + echo "If calling manually try: variant=std platform=linux $0" + exit 1 +fi + +if [[ ! -d platform-${platform} ]]; then + git clone -b ${lgwversion} git-repo platform-${platform} + + cd platform-${platform} + if [ -f ../${lgwversion}-${platform}.patch ]; then + echo "Applying ${lgwversion}-${platform}.patch ..." + git apply ../${lgwversion}-${platform}.patch + fi +fi diff --git a/examples/corecell/README.md b/examples/corecell/README.md new file mode 100644 index 0000000..97c92cb --- /dev/null +++ b/examples/corecell/README.md @@ -0,0 +1,22 @@ +## How to build station for "corecell" platform +* Copy or clone this repo to the corecell platform, which is a Raspberry Pi +* Execute the below command from the top folder for debug variant + ``` + make platform=corecell variant=debug + ``` +* After build finishes the corecell build artifacts can be found at "build-corecell-debug" folder +* For standard build (less debug prints) use 'variant=std' e.g. + ``` + make platform=corecell variant=std + ``` + +## Example to Test with "TTN" LNS with variant "std" +``` sourceCode +cd example/corecell +./start-station.sh -l ./lns-ttn +``` +## Example to Test with "TTN" LNS with variant "debug" +``` sourceCode +cd example/corecell +./start-station.sh -dl ./lns-ttn +``` diff --git a/examples/corecell/lns-ttn/.gitignore b/examples/corecell/lns-ttn/.gitignore new file mode 100644 index 0000000..cc6ee02 --- /dev/null +++ b/examples/corecell/lns-ttn/.gitignore @@ -0,0 +1,4 @@ +tc-bak.* +station.log +station.pid + diff --git a/examples/corecell/lns-ttn/station.conf b/examples/corecell/lns-ttn/station.conf new file mode 100644 index 0000000..4618940 --- /dev/null +++ b/examples/corecell/lns-ttn/station.conf @@ -0,0 +1,53 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1302_conf": { /* Actual channel plan is controlled by server */ + "device": "/dev/spidev0.0", + "lorawan_public": true, /* is default */ + "clksrc": 0, /* radio_0 provides clock to concentrator */ + "full_duplex": false, + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1250", + "rssi_offset": -215.4, + "rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0}, + "tx_enable": true, + "antenna_gain": 0, /* antenna gain, in dBi */ + "tx_gain_lut":[ + {"rf_power": 12, "pa_gain": 0, "pwr_idx": 15}, + {"rf_power": 13, "pa_gain": 0, "pwr_idx": 16}, + {"rf_power": 14, "pa_gain": 0, "pwr_idx": 17}, + {"rf_power": 15, "pa_gain": 0, "pwr_idx": 19}, + {"rf_power": 16, "pa_gain": 0, "pwr_idx": 20}, + {"rf_power": 17, "pa_gain": 0, "pwr_idx": 22}, + {"rf_power": 18, "pa_gain": 1, "pwr_idx": 1}, + {"rf_power": 19, "pa_gain": 1, "pwr_idx": 2}, + {"rf_power": 20, "pa_gain": 1, "pwr_idx": 3}, + {"rf_power": 21, "pa_gain": 1, "pwr_idx": 4}, + {"rf_power": 22, "pa_gain": 1, "pwr_idx": 5}, + {"rf_power": 23, "pa_gain": 1, "pwr_idx": 6}, + {"rf_power": 24, "pa_gain": 1, "pwr_idx": 7}, + {"rf_power": 25, "pa_gain": 1, "pwr_idx": 9}, + {"rf_power": 26, "pa_gain": 1, "pwr_idx": 11}, + {"rf_power": 27, "pa_gain": 1, "pwr_idx": 14} + ] + }, + "radio_1": { + "type": "SX1250", + "rssi_offset": -215.4, + "rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0}, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "radio_init": "rinit.sh", + "RADIO_INIT_WAIT": "5s", + "RX_POLL_INTV": "10ms", + "TC_TIMEOUT": "360s", + "log_file": "stderr", /* "station.log" */ + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3 + } +} + diff --git a/examples/corecell/lns-ttn/tc.trust b/examples/corecell/lns-ttn/tc.trust new file mode 100644 index 0000000..60e3d69 --- /dev/null +++ b/examples/corecell/lns-ttn/tc.trust @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow +SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT +GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC +AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF +q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8 +SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0 +Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA +a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj +/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T +AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG +CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv +bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k +c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw +VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC +ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz +MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu +Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF +AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo +uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/ +wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu +X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG +PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 +KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== +-----END CERTIFICATE----- + diff --git a/examples/corecell/lns-ttn/tc.uri b/examples/corecell/lns-ttn/tc.uri new file mode 100644 index 0000000..48d6f83 --- /dev/null +++ b/examples/corecell/lns-ttn/tc.uri @@ -0,0 +1 @@ +wss://lns.us.thethings.network:443 diff --git a/examples/corecell/lns-ttn/version.txt b/examples/corecell/lns-ttn/version.txt new file mode 100644 index 0000000..2165f8f --- /dev/null +++ b/examples/corecell/lns-ttn/version.txt @@ -0,0 +1 @@ +2.0.4 diff --git a/examples/corecell/reset_lgw.sh b/examples/corecell/reset_lgw.sh new file mode 100755 index 0000000..0136d72 --- /dev/null +++ b/examples/corecell/reset_lgw.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# This script is intended to be used on SX1302 CoreCell platform, it performs +# the following actions: +# - export/unpexort GPIO23 and GPIO18 used to reset the SX1302 chip and to enable the LDOs +# +# Usage examples: +# ./reset_lgw.sh stop +# ./reset_lgw.sh start + +# GPIO mapping has to be adapted with HW +# + +SX1302_RESET_PIN=23 +SX1302_POWER_EN_PIN=18 + +WAIT_GPIO() { + sleep 0.1 +} + +init() { + # setup GPIOs + echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO + echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO + + # set GPIOs as output + echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO + echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO +} + +reset() { + echo "CoreCell reset through GPIO$SX1302_RESET_PIN..." + echo "CoreCell power enable through GPIO$SX1302_POWER_EN_PIN..." + + # write output for SX1302 CoreCell power_enable and reset + echo "1" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/value; WAIT_GPIO + + echo "1" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO + echo "0" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO +} + +term() { + # cleanup all GPIOs + if [ -d /sys/class/gpio/gpio$SX1302_RESET_PIN ] + then + echo "$SX1302_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO + fi + if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ] + then + echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO + fi +} + +case "$1" in + start) + term # just in case + init + reset + ;; + stop) + reset + term + ;; + *) + echo "Usage: $0 {start|stop}" + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/examples/corecell/rinit.sh b/examples/corecell/rinit.sh new file mode 100644 index 0000000..27d3d03 --- /dev/null +++ b/examples/corecell/rinit.sh @@ -0,0 +1,2 @@ +#!/bin/bash +./reset_lgw.sh start diff --git a/examples/corecell/start-station.sh b/examples/corecell/start-station.sh new file mode 100755 index 0000000..5317c19 --- /dev/null +++ b/examples/corecell/start-station.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# A POSIX variable +OPTIND=1 # Reset in case getopts has been used previously in the shell. + +# Initialize our own variables: +lns_config="" +variant=std + +show_help() +{ + printf "$GREEN" + printf "\tUsage: ./start-station.sh -l {lns-home} -d\n" + printf "\t-l : LNS configuration folder \n" + printf "\t-d : To run debug variant of station\n" + printf "$NC" + printf "\t\t e.g: ./start-station.sh -l ./lns-ttn\n" + printf "\t\t ./start-station.sh -dl ./lns-ttn\n" + exit +} + + +while getopts "h?dl:" opt; do + case "$opt" in + h|\?) + show_help + exit 0 + ;; + d) variant=debug + ;; + l) lns_config=$OPTARG + ;; + esac +done + +shift $((OPTIND-1)) + +[ "${1:-}" = "--" ] && shift + + +if [ -z "$lns_config" ]; then + printf "$RED" + printf "$RED \tError: No LNS home folder provided$NC\n" + printf "$NC" + show_help +fi + +STATION_BIN="../../build-corecell-$variant/bin/station" + + +if [ -f "$STATION_BIN" ]; then + printf "Using variant=$variant, lns_config='$lns_config'\n" + printf "$GREEN Starting Station ... $NC\n" + $STATION_BIN -h $lns_config +else + printf "$RED [ERROR]: Binary not found @ $STATION_BIN $NC\n" +fi diff --git a/examples/cups/README.md b/examples/cups/README.md index 8844cef..16ed012 100644 --- a/examples/cups/README.md +++ b/examples/cups/README.md @@ -8,15 +8,15 @@ Using the Station simulation environment, this example implements the two CUPS s ``` CUPS "A" CA - +- cups-0.{crt,key} server auth - +- cups-router-1.{crt,key} client auth + ├── cups-0.{crt,key} server auth + └── cups-router-1.{crt,key} client auth CUPS "B" CA - +- cups-1.{crt,key} server auth - +- cups-router-1.{crt,key} client auth + ├── cups-1.{crt,key} server auth + └── cups-router-1.{crt,key} client auth TC CA - +- muxs-0.{crt,key} server auth - +- infos-0.{crt,key} server auth - +- tc-router-1.{crt,key} client auth + ├── muxs-0.{crt,key} server auth + ├── infos-0.{crt,key} server auth + └── tc-router-1.{crt,key} client auth ``` **Disclaimer:** The focus of this example is to demonstrate the capabilities of the CUPS protocol based on a common usage scenario for gateway management. For this purpose and the sake of simplicity, the PKI employed in this example is setup in very simple way and does not resemble a production grade PKI. @@ -76,7 +76,7 @@ tc-0/tc-router-1.crt: OK == Prepare FW Update 1.0.0 -> 2.0.0 == ``` -The `emulate` target first executes the `prep.sh` script which sets up the folder structure as expected by the simulation. First, the three self-signed CA certificates are generated and used to sign the certificates of all our server entities `cups-0`, `cups-1`, `tc-0`, as well as the client certificates for `router-1` expected by each of them. A signing key pair is generated and a signed updated is placed in `cups-1`. The public part of the signing key is copied to the Station home directory `./shome`. The final directory structure will look like this: +The `emulate` target first executes the `prep.sh` script which sets up the folder structure as expected by the simulation. First, the three self-signed CA certificates are generated and used to sign the certificates of all our server entities `cups-0`, `cups-1`, `tc-0`, as well as the client certificates for `router-1` expected by each of them. A code signing key pair is generated and a signed update is placed in `cups-1`. The public part of the signing key is copied to the Station home directory `./shome`. The final directory structure will look like this: ``` . diff --git a/examples/cups/emulate.sh b/examples/cups/emulate.sh index 393f9b3..bdcf998 100755 --- a/examples/cups/emulate.sh +++ b/examples/cups/emulate.sh @@ -1,5 +1,31 @@ #!/bin/bash +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # emulate.sh # # Emualte the behavior of Station by subsequent curl requests to CUPS. diff --git a/examples/cups/makefile b/examples/cups/makefile index c70caad..8487192 100644 --- a/examples/cups/makefile +++ b/examples/cups/makefile @@ -1,3 +1,29 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + TD=../.. platform?=linux variant?=testsim diff --git a/examples/cups/prep.sh b/examples/cups/prep.sh index 05f9926..f7e3209 100755 --- a/examples/cups/prep.sh +++ b/examples/cups/prep.sh @@ -1,5 +1,31 @@ #!/bin/bash +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # prep.sh - Prepare the environment for the CUPS example. diff --git a/examples/cups/sim.py b/examples/cups/sim.py index d196189..bd0d011 100644 --- a/examples/cups/sim.py +++ b/examples/cups/sim.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -36,16 +35,11 @@ sys.path.append('../../pysys') import tcutils as tu +import testutils as tstu import simutils as su import logging -handler = logging.StreamHandler(sys.stdout) -handler.setLevel(logging.DEBUG) -handler.setFormatter(logging.Formatter('%(asctime)s [%(name).8s:%(levelname).5s] %(message)s')) - logger = logging.getLogger('cups-sim') -logger.setLevel(logging.DEBUG) -logger.addHandler(handler) station = None infos = None @@ -189,6 +183,7 @@ def sigHandler(signum, frame): sys.stdout.flush() quit() +tstu.setup_logging() signal.signal(signal.SIGINT, sigHandler) task = asyncio.ensure_future(test_start()) diff --git a/examples/live-s2.sm.tc/.gitignore b/examples/live-s2.sm.tc/.gitignore new file mode 100644 index 0000000..9cd25ce --- /dev/null +++ b/examples/live-s2.sm.tc/.gitignore @@ -0,0 +1,8 @@ +update.bin +cups.* +cups-bak.* +tc.* +tc-bak.* +station.log +station.pid + diff --git a/examples/live-s2.sm.tc/makefile b/examples/live-s2.sm.tc/makefile index 410a3e5..80fce24 100644 --- a/examples/live-s2.sm.tc/makefile +++ b/examples/live-s2.sm.tc/makefile @@ -1,3 +1,29 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + TD=../.. platform?=linux variant?=std diff --git a/examples/simulation/.gitignore b/examples/simulation/.gitignore new file mode 100644 index 0000000..4edaec3 --- /dev/null +++ b/examples/simulation/.gitignore @@ -0,0 +1,7 @@ +update.bin +cups.* +cups-bak.* +tc-bak.* +station.log +station.pid + diff --git a/examples/simulation/makefile b/examples/simulation/makefile index 73d2a22..51da284 100644 --- a/examples/simulation/makefile +++ b/examples/simulation/makefile @@ -1,3 +1,29 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + TD=../.. platform?=linux variant?=testsim diff --git a/examples/simulation/sim.py b/examples/simulation/sim.py index adaac3f..07de890 100644 --- a/examples/simulation/sim.py +++ b/examples/simulation/sim.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/station2pkfwd/bgtask.py b/examples/station2pkfwd/bgtask.py index 4b43547..a676301 100644 --- a/examples/station2pkfwd/bgtask.py +++ b/examples/station2pkfwd/bgtask.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/station2pkfwd/id6.py b/examples/station2pkfwd/id6.py index af99146..8fab414 100644 --- a/examples/station2pkfwd/id6.py +++ b/examples/station2pkfwd/id6.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/station2pkfwd/main.py b/examples/station2pkfwd/main.py index 90c0e1c..a4cc073 100644 --- a/examples/station2pkfwd/main.py +++ b/examples/station2pkfwd/main.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/station2pkfwd/pkfwdc.py b/examples/station2pkfwd/pkfwdc.py index 87b201c..51111ce 100644 --- a/examples/station2pkfwd/pkfwdc.py +++ b/examples/station2pkfwd/pkfwdc.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/station2pkfwd/router.py b/examples/station2pkfwd/router.py index 5252c73..08137b3 100644 --- a/examples/station2pkfwd/router.py +++ b/examples/station2pkfwd/router.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/station2pkfwd/router_config.py b/examples/station2pkfwd/router_config.py index 48731d2..fd8193b 100644 --- a/examples/station2pkfwd/router_config.py +++ b/examples/station2pkfwd/router_config.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/makefile.s2core b/makefile.s2core index 577dc5c..259a7be 100644 --- a/makefile.s2core +++ b/makefile.s2core @@ -1,4 +1,28 @@ -# -*- makefile -*- +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TD=../.. include ${TD}/setup.gmk @@ -11,12 +35,12 @@ VPATH+=${TD}/src $(patsubst %/, %, $(filter %/, $(wildcard ${TD}/src/*/))) $(pat SRCS = $(notdir $(wildcard ${VPATH:%=%/*.c})) ASRCS = $(notdir $(wildcard ${VPATH:%=%/*.S})) -OBJS=${SRCS:.c=.o} ${ASRCS:.S=.s.o} ${FILES:=.o} +OBJS=${SRCS:.c=.o} ${ASRCS:.S=.s.o} ${FILES:=.o} ${FILES:=.crc.o} DEPS=${SRCS:.c=.d} all: ${TARGET} -../bin/station: station_main.c ../lib/libs2core.a +../bin/station: station_main.c ../lib/libs2core.a $(wildcard ../lib/*.a) @echo " [${ARCH}] CC $@" ${NQ} ${Q}${CC} ${CFLAGS} ${LDFLAGS} $^ ${LIBS} -o $@ @echo " platform=${platform} variant=${variant} STATION EXE built" @@ -78,6 +102,15 @@ perso.h: $(patsubst %.asc, %,${PERSO}) @echo " [${ARCH}] STR $@ " ${NQ} ${Q} cp $< $@ ; printf "\0" >> $@ +# Linking crcs (*.crc) +%.crc.o: %.crc + @echo " [${ARCH}] OC $@ " ${NQ} + ${Q} ${OC} ${OCFLAGS} ${ $@ + clean super-clean: rm -rf *.o *.d *.gcno ../lib/libs2core.a rm -f ${TARGET} diff --git a/pysys/id6.py b/pysys/id6.py index a86b5e3..3e6d4d6 100644 --- a/pysys/id6.py +++ b/pysys/id6.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -296,15 +295,13 @@ def __init__(self, idspec:Union[int,str,'Id6',Eui], cat:str='') -> None: self._idstr = idspec._idstr # type: str self.cat = cat or idspec.cat # type: str elif isinstance(idspec,str): - try: + if '-' in idspec: pos = idspec.index('-') if pos > 0 and not Id6.EUI_REGEX.match(idspec): self.cat = idspec[0:pos] if cat and self.cat != cat: - raise ValueError('Ambiguous categories') + raise ValueError("Conflicting category '%s' - expecting '%s'" % (self.cat, cat)) idspec = idspec[pos+1:] - except: - pass self.id = Id6.str2int(idspec) self._idstr = Id6.int2str(self.id) # nomalized repr elif isinstance(idspec,int): diff --git a/pysys/simutils.py b/pysys/simutils.py index 320d78c..d766ad5 100644 --- a/pysys/simutils.py +++ b/pysys/simutils.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,22 +9,22 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from typing import Any,Dict,List,Tuple +from typing import Any,Dict,List,Tuple,Union import os import sys import asyncio @@ -34,55 +33,190 @@ import time import logging -handler = logging.StreamHandler(sys.stdout) -handler.setLevel(logging.DEBUG) -handler.setFormatter(logging.Formatter('%(asctime)s [%(name).8s:%(levelname).5s] %(message)s')) - logger = logging.getLogger('simutils') -logger.setLevel(logging.DEBUG) -logger.addHandler(handler) - -STAT_CRC_OK = 0x10 - -MOD_LORA = 0x10 -MOD_FSK = 0x20 - -BW_500KHZ = 0x01 -BW_250KHZ = 0x02 -BW_125KHZ = 0x03 - -DR_LORA_SF7 = 0x02 -DR_LORA_SF8 = 0x04 -DR_LORA_SF9 = 0x08 -DR_LORA_SF10 = 0x10 -DR_LORA_SF11 = 0x20 -DR_LORA_SF12 = 0x40 - -CR_LORA_4_5 = 0x01 -CR_LORA_4_6 = 0x02 -CR_LORA_4_7 = 0x03 -CR_LORA_4_8 = 0x04 - -DR_MAP = { - 7: DR_LORA_SF7 , - 8: DR_LORA_SF8 , - 9: DR_LORA_SF9 , - 10: DR_LORA_SF10, - 11: DR_LORA_SF11, - 12: DR_LORA_SF12, -} -BW_MAP = { - 125: BW_125KHZ, - 250: BW_250KHZ, - 500: BW_500KHZ, -} - - -SIZE_PKT_RX = 300 -SIZE_PKT_TX = 288 -OFF_PKT_RX_PAYLOAD = 44 -OFF_PKT_TX_PAYLOAD = 30 -PPM = (1<<32) + +class LgwHAL(): + BW_500KHZ = 0x01 + BW_250KHZ = 0x02 + BW_125KHZ = 0x03 + + BW_MAP = { + 125: BW_125KHZ, + 250: BW_250KHZ, + 500: BW_500KHZ, + } + + DR_LORA_SF7 = 0x02 + DR_LORA_SF8 = 0x04 + DR_LORA_SF9 = 0x08 + DR_LORA_SF10 = 0x10 + DR_LORA_SF11 = 0x20 + DR_LORA_SF12 = 0x40 + + DR_MAP = { + 7: DR_LORA_SF7 , + 8: DR_LORA_SF8 , + 9: DR_LORA_SF9 , + 10: DR_LORA_SF10, + 11: DR_LORA_SF11, + 12: DR_LORA_SF12, + } + + CR_LORA_4_5 = 0x01 + CR_LORA_4_6 = 0x02 + CR_LORA_4_7 = 0x03 + CR_LORA_4_8 = 0x04 + + @classmethod + def add_rps(cls, pkt, rps): + pkt['bandwidth'] = cls.BW_MAP[rps[1]] + pkt['datarate'] = cls.DR_MAP[rps[0]] + +class Lgw1(LgwHAL): + SIZE_PKT_TX = 288 + SIZE_PKT_RX = 300 + OFF_PKT_RX_PAYLOAD = 44 + OFF_PKT_TX_PAYLOAD = 30 + STAT_CRC_OK = 0x10 + MOD_LORA = 0x10 + MOD_FSK = 0x20 + IMMEDIATE = 0 + TIMESTAMPED = 1 + ON_GPS = 2 + + @classmethod + def pack_pkt_rx (cls, pkt:Dict[str,Any], xticks): + count_us = xticks & 0xFFFFFFFF + p = pkt.get('payload',b'') + f = ( + pkt.get('freq_hz' , 0), # central frequency of the IF chain */ + pkt.get('if_chain' , 0), # by which IF chain was packet received */ + pkt.get('status' , cls.STAT_CRC_OK), # status of the received packet */ + pkt.get('count_us' , count_us), # internal concentrator counter for timestamping, 1 microsecond resolution */ + pkt.get('rf_chain' , 0), # through which RF chain the packet was received */ + pkt.get('modulation', cls.MOD_LORA), # modulation used by the packet */ + pkt.get('bandwidth' , cls.BW_125KHZ), # modulation bandwidth (LoRa only) */ + pkt.get('datarate' , cls.DR_LORA_SF7), # RX datarate of the packet (SF for LoRa) */ + pkt.get('coderate' , cls.CR_LORA_4_5), # error-correcting code of the packet (LoRa only) */ + pkt.get('rssi' , -50.0), # average packet RSSI in dB */ + pkt.get('snr' , 9.0), # average packet SNR, in dB (LoRa only) */ + pkt.get('snr_min' , 8.7), # minimum packet SNR, in dB (LoRa only) */ + pkt.get('snr_max' , 9.3), # maximum packet SNR, in dB (LoRa only) */ + pkt.get('crc' , 0), # CRC that was received in the payload */ + pkt.get('size' , len(p)), # payload size in bytes */ + ) + data = struct.pack("@IBBIBBBIBffffHH", *f) + return data + p + b'\x00' * (cls.SIZE_PKT_RX-cls.OFF_PKT_RX_PAYLOAD-len(p)) + + @classmethod + def unpack_pkt_tx (cls, data): + assert len(data) == cls.SIZE_PKT_TX + fields = \ + ('freq_hz' , # central frequency of the IF chain */ + 'tx_mode' , # select on what event/time the TX is triggered */ + 'count_us' , # internal concentrator counter for timestamping, 1 microsecond resolution */ + 'rf_chain' , # through which RF chain the packet was received */ + 'rf_power' , # TX power, in dBm */ + 'modulation', # modulation used by the packet */ + 'bandwidth' , # modulation bandwidth (LoRa only) */ + 'datarate' , # RX datarate of the packet (SF for LoRa) */ + 'coderate' , # error-correcting code of the packet (LoRa only) */ + 'invert_pol', # invert signal polarity, for orthogonal downlinks (LoRa only) */ + 'f_dev' , # frequency deviation, in kHz (FSK only) */ + 'preamble' , # set the preamble length, 0 for default */ + 'no_crc' , # if true, do not send a CRC in the packet */ + 'no_header' , # if true, enable implicit header mode (LoRa), fixed length (FSK) */ + 'size' # payload size in bytes */ + ) + elems = struct.unpack_from("@IBIBbBBIBBBHBBH", data, 0) + pkt = dict(zip(fields, elems)) + pkt['payload'] = data[cls.OFF_PKT_TX_PAYLOAD:cls.OFF_PKT_TX_PAYLOAD+pkt['size']] + return pkt + +class Lgw2(LgwHAL): + SIZE_PKT_TX = 296 + SIZE_PKT_RX = 284 + OFF_PKT_RX_PAYLOAD = 30 + OFF_PKT_TX_PAYLOAD = 30 + STAT_CRC_OK = 0x3 + MOD_LORA = 0x1 + MOD_FSK = 0x2 + + @classmethod + def pack_pkt_rx (cls, pkt:Dict[str,Any], xticks): + count_us = xticks & 0xFFFFFFFF + p = pkt.get('payload',b'') + f = ( + pkt.get('status' , cls.STAT_CRC_OK), # status of the received packet */ + pkt.get('freq_hz' , 0), # central frequency of the IF chain */ + pkt.get('count_us' , count_us), # internal concentrator counter for timestamping, 1 microsecond resolution */ + pkt.get('modulation', cls.MOD_LORA), # modulation used by the packet */ + pkt.get('bandwidth' , cls.BW_125KHZ), # modulation bandwidth (LoRa only) */ + pkt.get('datarate' , cls.DR_LORA_SF7), # RX datarate of the packet (SF for LoRa) */ + pkt.get('coderate' , cls.CR_LORA_4_5), # error-correcting code of the packet (LoRa only) */ + pkt.get('size' , len(p)), # payload size in bytes */ + ) + data = struct.pack("@IIIIIIIB", *f) + data += p + b'\x00' * (cls.SIZE_PKT_RX-cls.OFF_PKT_RX_PAYLOAD-len(p)) + data += b'\x00' # Padding + + #NOT_USED pkt.get('snr_min' , 8.7), # minimum packet SNR, in dB (LoRa only) */ + #NOT_USED pkt.get('snr_max' , 9.3), # maximum packet SNR, in dB (LoRa only) */ + #NOT_USED pkt.get('crc' , 0), # CRC that was received in the payload */ + + f = ( + 1, # is_valid; /*!> Is there a signal on this antenna? */ + 0, # fine_received; /*!> Have we received a valid fine timestamp? */ + 1, # sig_info_received; /*!> Have we received signal information from DSP (RSSI, SNR...)? */ + pkt.get('if_chain' , 0), # chan; /*!> Channel on which packet was received */ + 0, # freq_offset; /*!> Frequency offset, in Hz */ + b'\xAB'*16, # fine_tmst_enc[SX1301AR_BOARD_AES_DATA_SIZE]; /*!> Main fine timestamp of packet arrival (encrypted) */ + 0, # fine_tmst; /*!> Main fine timestamp of packet arrival (clear) */ + 0, # fine_tmst_status; /*!> Main fine timestamp status */ + 0, # fine_tmst_version; /*!> Version of the main fine timestamp */ + pkt.get('rssi' , -50.0), # rssi_chan; /*!> Channel RSSI in dB */ + pkt.get('rssi' , -50.0), # rssi_sig; /*!> Signal RSSI in dB */ + 1, # rssi_sig_std; /*!> Standard deviation of RSSI during preamble */ + pkt.get('snr' , 9.0), # snr; /*!> Average packet SNR, in dB (LoRa only) */ + 0, # fine_tmst_alt; /*!> Alternative fine timestamp: delta in nanoseconds compared to main fine timestamp */ + 0, # fine_tmst_debug1; /*!> Fine timestamp debug info 1 */ + 0, # fine_tmst_debug2; /*!> Fine timestamp debug info 2 */ + 0, # padding + ) + rsig = struct.pack("@BBBBH16sIBBffIfhHHH", *f) + if pkt.get('rf_chain', 0) == 0: + rsig = rsig + bytes(len(rsig)) + else: + rsig = bytes(len(rsig)) + rsig + data += rsig + return data + + + @classmethod + def unpack_pkt_tx (cls, data): + assert len(data) == cls.SIZE_PKT_TX + fields = \ + ( + 'tx_mode' , # select on what event/time the TX is triggered */ + 'count_us' , # internal concentrator counter for timestamping, 1 microsecond resolution */ + 'freq_hz' , # central frequency of the IF chain */ + 'rf_power' , # TX power, in dBm */ + 'rf_chain' , # through which RF chain the packet was received */ + 'modulation', # modulation used by the packet */ + 'bandwidth' , # modulation bandwidth (LoRa only) */ + 'datarate' , # RX datarate of the packet (SF for LoRa) */ + 'coderate' , # error-correcting code of the packet (LoRa only) */ + 'f_dev' , # frequency deviation, in kHz (FSK only) */ + 'preamble' , # set the preamble length, 0 for default */ + 'invert_pol', # invert signal polarity, for orthogonal downlinks (LoRa only) */ + 'no_crc' , # if true, do not send a CRC in the packet */ + 'no_header' , # if true, enable implicit header mode (LoRa), fixed length (FSK) */ + 'size' # payload size in bytes */ + ) + elems = struct.unpack_from("@IIIbBIIIIBHBBBB", data, 0) + pkt = dict(zip(fields, elems)) + pkt['payload'] = data[cls.OFF_PKT_TX_PAYLOAD:cls.OFF_PKT_TX_PAYLOAD+pkt['size']] + return pkt MAX_CCA_INFOS = 10 # keep in sync with lgwsim.c MAGIC_CCA_FREQ = 0xCCAFCCAF # ditto @@ -106,60 +240,6 @@ def makeDF(mhdr=FrmType.DAUP, fctrl=0, fcnt=0, devaddr=1, fopts=b'', port=-1, pa return b -def add_rps(pkt, rps): - pkt['bandwidth'] = BW_MAP[rps[1]] - pkt['datarate'] = DR_MAP[rps[0]] - - -def pack_pkt_rx (pkt:Dict[str,Any], xticks): - count_us = xticks & 0xFFFFFFFF - p = pkt.get('payload',b'') - f = \ - (pkt.get('freq_hz' , 0), # central frequency of the IF chain */ - pkt.get('if_chain' , 0), # by which IF chain was packet received */ - pkt.get('status' , STAT_CRC_OK), # status of the received packet */ - pkt.get('count_us' , count_us), # internal concentrator counter for timestamping, 1 microsecond resolution */ - pkt.get('rf_chain' , 0), # through which RF chain the packet was received */ - pkt.get('modulation', MOD_LORA), # modulation used by the packet */ - pkt.get('bandwidth' , BW_125KHZ), # modulation bandwidth (LoRa only) */ - pkt.get('datarate' , DR_LORA_SF7), # RX datarate of the packet (SF for LoRa) */ - pkt.get('coderate' , CR_LORA_4_5), # error-correcting code of the packet (LoRa only) */ - pkt.get('rssi' , -50.0), # average packet RSSI in dB */ - pkt.get('snr' , 9.0), # average packet SNR, in dB (LoRa only) */ - pkt.get('snr_min' , 8.7), # minimum packet SNR, in dB (LoRa only) */ - pkt.get('snr_max' , 9.3), # maximum packet SNR, in dB (LoRa only) */ - pkt.get('crc' , 0), # CRC that was received in the payload */ - pkt.get('size' , len(p)), # payload size in bytes */ - ) - data = struct.pack("@IBBIBBBIBffffHH", *f) - return data + p + b'\x00' * (SIZE_PKT_RX-OFF_PKT_RX_PAYLOAD-len(p)) - - -def unpack_pkt_tx (data): - assert len(data) == SIZE_PKT_TX - fields = \ - ('freq_hz' , # central frequency of the IF chain */ - 'tx_mode' , # select on what event/time the TX is triggered */ - 'count_us' , # internal concentrator counter for timestamping, 1 microsecond resolution */ - 'rf_chain' , # through which RF chain the packet was received */ - 'rf_power' , # TX power, in dBm */ - 'modulation', # modulation used by the packet */ - 'bandwidth' , # modulation bandwidth (LoRa only) */ - 'datarate' , # RX datarate of the packet (SF for LoRa) */ - 'coderate' , # error-correcting code of the packet (LoRa only) */ - 'invert_pol', # invert signal polarity, for orthogonal downlinks (LoRa only) */ - 'f_dev' , # frequency deviation, in kHz (FSK only) */ - 'preamble' , # set the preamble length, 0 for default */ - 'no_crc' , # if true, do not send a CRC in the packet */ - 'no_header' , # if true, enable implicit header mode (LoRa), fixed length (FSK) */ - 'size' # payload size in bytes */ - ) - elems = struct.unpack_from("@IBIBbBBIBBBHBBH", data, 0) - pkt = dict(zip(fields, elems)) - pkt['payload'] = data[OFF_PKT_TX_PAYLOAD:OFF_PKT_TX_PAYLOAD+pkt['size']] - return pkt - - class LgwSimServer: def __init__(self, path:str='spidev') -> None: self.path = path @@ -177,19 +257,23 @@ def close(self): self.units = {} async def connected(self, reader, writer) -> None: - p = await reader.read(SIZE_PKT_TX) - assert len(p) == SIZE_PKT_TX - pkt = unpack_pkt_tx(p) - assert pkt['tx_mode'] == 255 + p = await reader.read(Lgw1.SIZE_PKT_TX) + assert len(p) == Lgw1.SIZE_PKT_TX + pkt = Lgw1.unpack_pkt_tx(p) + hal = Lgw1 + if pkt['tx_mode'] != 255: + hal = Lgw2 + p += await reader.read(Lgw2.SIZE_PKT_TX - Lgw1.SIZE_PKT_TX) + pkt = Lgw2.unpack_pkt_tx(p) timeOffset = (pkt['freq_hz']<<32) + pkt['count_us'] unitIdx = pkt['f_dev'] - lgwsim = self.make_lgwsim(unitIdx, timeOffset, reader, writer) + lgwsim = self.make_lgwsim(unitIdx, hal, timeOffset, reader, writer) logger.debug(' LgwSimServer: SPI device #%d connected (timeOffset=0x%X xticksNow=0x%X)' % (unitIdx, timeOffset, lgwsim.xticks())) self.units[unitIdx] = lgwsim await self.on_connected(lgwsim) - def make_lgwsim(self, unitIdx, timeOffset, reader, writer) -> 'LgwSim': - return LgwSim(self, unitIdx, timeOffset, reader, writer) + def make_lgwsim(self, unitIdx, hal, timeOffset, reader, writer) -> 'LgwSim': + return LgwSim(self, unitIdx, hal, timeOffset, reader, writer) async def on_connected(self, lgwsim:'LgwSim') -> None: await lgwsim.on_connected() @@ -199,13 +283,13 @@ async def on_tx(self, lgwsim, pkt): class LgwSim: - def __init__(self, server, unitIdx:int , timeOffset:int, reader:asyncio.StreamReader, writer:asyncio.StreamWriter) -> None: + def __init__(self, server, unitIdx:int, hal:Union[Lgw1,Lgw2], timeOffset:int, reader:asyncio.StreamReader, writer:asyncio.StreamWriter) -> None: self.unitIdx = unitIdx self.server = server + self.hal = hal self.reader = reader self.writer = writer - self.timeOffset = timeOffset - # self.timeOffset = int(time.monotonic()*1e6) - 0x10200000 + self.timeOffset = timeOffset # This assumes target to run on the same system clock as simulation self.read_task = asyncio.ensure_future(self.read_loop()) def xticks(self) -> int: @@ -225,12 +309,12 @@ def close(self): async def read_loop(self): try: while True: - p = await self.reader.read(SIZE_PKT_TX) + p = await self.reader.read(self.hal.SIZE_PKT_TX) if p == b'': # EOF logger.debug(' LGWSIM(%d) - read EOF' % self.unitIdx) break else: - pkt = unpack_pkt_tx(p) + pkt = self.hal.unpack_pkt_tx(p) await self.on_tx(pkt) except BrokenPipeError: pass @@ -247,8 +331,8 @@ async def send_rx(self, rps:Tuple[int,int], freq=869.515, rxtime=None, frame=b'' 'freq_hz': int(freq*1e6), 'payload': frame } - add_rps(pkt, rps) - p = pack_pkt_rx(pkt, rxtime or self.xticks()) + self.hal.add_rps(pkt, rps) + p = self.hal.pack_pkt_rx(pkt, rxtime or self.xticks()) self.writer.write(p) await self.writer.drain() @@ -258,7 +342,7 @@ async def send_cca(self, cca_infos:List[Tuple[int,int,int]]): p = (struct.pack("@II", MAGIC_CCA_FREQ, 0) + b''.join(struct.pack("@IQQ", int(i[0]*1e6), i[1], i[2]) for i in cca_infos)) - p += b'\x00' * (SIZE_PKT_RX - len(p)) + p += b'\x00' * (self.hal.SIZE_PKT_RX - len(p)) self.writer.write(p) await self.writer.drain() diff --git a/pysys/tcutils.py b/pysys/tcutils.py index c59c1e1..bd134b2 100644 --- a/pysys/tcutils.py +++ b/pysys/tcutils.py @@ -1,6 +1,5 @@ # --- Revised 3-Clause BSD License --- -# Copyright (C) 2016-2019, SEMTECH (International) AG. -# All rights reserved. +# Copyright Semtech Corporation 2020. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -10,17 +9,17 @@ # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# * Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -31,6 +30,7 @@ import base64 import os import sys +from datetime import datetime import struct import json import asyncio @@ -45,43 +45,71 @@ logger = logging.getLogger('_tcutils') -handler = logging.StreamHandler(sys.stdout) -handler.setLevel(logging.DEBUG) -handler.setFormatter(logging.Formatter('%(asctime)s [%(name).8s:%(levelname).5s] %(message)s')) - -logger.setLevel(logging.DEBUG) -logger.addHandler(handler) +base_regions = { + "EU863" : { + 'msgtype': 'router_config', + 'region': 'EU863', + 'DRs': [(12, 125, 0), + (11, 125, 0), + (10, 125, 0), + (9, 125, 0), + (8, 125, 0), + (7, 125, 0), + (7, 250, 0), + (0, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0)], + 'max_eirp': 16.0, + 'protocol': 1, + 'freq_range': [863000000, 870000000] + }, + "US902": { + 'msgtype': 'router_config', + 'region': 'US902', + 'DRs': [(10, 125, 0), + (9, 125, 0), + (8, 125, 0), + (7, 125, 0), + (8, 500, 0), + (-1, 0, 0), + (-1, 0, 0), + (-1, 0, 0), + (12, 500, 1), + (11, 500, 1), + (10, 500, 1), + (9, 500, 1), + (8, 500, 1), + (7, 500, 1), + (-1, 0, 0), + (-1, 0, 0)], + 'max_eirp': 30.0, + 'protocol': 1, + 'freq_range': [902000000, 928000000] + } +} +base_regions["KR920"] = { + 'msgtype': 'router_config', + 'region': 'KR920', + 'DRs': base_regions["EU863"]["DRs"], + 'max_eirp': 23.0, + 'protocol': 1, + 'freq_range': [920900000, 923300000], + } router_config_EU863_6ch = { - 'DRs': [[12, 125, 0], - [11, 125, 0], - [10, 125, 0], - [9, 125, 0], - [8, 125, 0], - [7, 125, 0], - [7, 250, 0], - [0, 0, 0], - [-1, 0, 0], - [-1, 0, 0], - [-1, 0, 0], - [-1, 0, 0], - [-1, 0, 0], - [-1, 0, 0], - [-1, 0, 0], - [-1, 0, 0]], + **base_regions['EU863'], 'JoinEui': None, 'NetID': None, 'bcning': None, 'config': {}, - 'nodc': True, - 'freq_range': [863000000, 870000000], 'hwspec': 'sx1301/1', - 'max_eirp': 16.0, - 'msgtype': 'router_config', - 'protocol': 1, - 'region': 'EU863', - 'regionid': 1002, 'sx1301_conf': [{'chan_FSK': {'enable': False}, 'chan_Lora_std': {'enable': False}, 'chan_multiSF_0': {'enable': True, 'if': -375000, 'radio': 0}, @@ -102,34 +130,43 @@ [869525000, 0, 5]] } +router_config_US902_8ch = { + **base_regions['US902'], + 'JoinEui': None, + 'NetID': None, + 'bcning': None, + 'config': {}, + 'hwspec': 'sx1301/1', + 'sx1301_conf': [{'chan_FSK': {'enable': False}, + 'chan_Lora_std': {'enable': True, 'if': 300000, 'radio': 0}, + 'chan_multiSF_0': {'enable': True, 'if': -400000, 'radio': 0}, + 'chan_multiSF_1': {'enable': True, 'if': -200000, 'radio': 0}, + 'chan_multiSF_2': {'enable': True, 'if': 0, 'radio': 0}, + 'chan_multiSF_3': {'enable': True, 'if': 200000, 'radio': 0}, + 'chan_multiSF_4': {'enable': True, 'if': -200000, 'radio': 1}, + 'chan_multiSF_5': {'enable': True, 'if': 0, 'radio': 1}, + 'chan_multiSF_6': {'enable': True, 'if': 200000, 'radio': 1}, + 'chan_multiSF_7': {'enable': True, 'if': 400000, 'radio': 1}, + 'radio_0': {'enable': True, 'freq': 902700000}, + 'radio_1': {'enable': True, 'freq': 903300000}}], + 'upchannels': [[902300000, 0, 5], + [902500000, 0, 5], + [902700000, 0, 5], + [902900000, 0, 5], + [903100000, 0, 5], + [903300000, 0, 5], + [903500000, 0, 5], + [903700000, 0, 5]] +} + + router_config_KR920 = { - 'DRs': [(12, 125, 0), - (11, 125, 0), - (10, 125, 0), - (9, 125, 0), - (8, 125, 0), - (7, 125, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0), - (-1, 0, 0)], + **base_regions['KR920'], 'JoinEui': None, 'NetID': None, 'bcning': None, 'config': {}, - 'freq_range': [920900000, 923300000], 'hwspec': 'sx1301/1', - 'max_eirp': 23.0, - 'msgtype': 'router_config', - 'protocol': 1, - 'region': 'KR920', - 'regionid': 8, 'sx1301_conf': [{'chan_FSK': {'enable': False}, 'chan_Lora_std': {'enable': False}, 'chan_multiSF_0': {'enable': True, 'if': -200000, 'radio': 0}, @@ -147,6 +184,9 @@ (922500000, 0, 5)] } +GPS_EPOCH=datetime(1980,1,6) +UPC_EPOCH=datetime(1970,1,1) +UTC_GPS_LEAPS=18 class ServerABC: def __init__(self, port:int=6000, tlsidentity:Optional[str]=None, tls_no_ca=False): @@ -230,6 +270,7 @@ async def handle_ws(self, ws, path): logger.debug('. MUXS connect: %s' % (path,)) if path != '/router': await ws.close(1020) + self.ws = ws rconf = self.get_router_config() await ws.send(json.dumps(rconf)) logger.debug('< MUXS: router_config.') @@ -272,6 +313,19 @@ async def handle_connection(self, ws): async def handle_version(self, ws, msg): logger.debug('> MUXS: Station Version: %r' % (msg,)) + async def handle_timesync(self, ws, msg): + logger.debug("> MUXS: %r", msg) + await asyncio.sleep(0.05) + reply = { + 'msgtype': 'timesync', + 'gpstime': int(((datetime.utcnow() - GPS_EPOCH).total_seconds() + UTC_GPS_LEAPS)*1e6), + 'txtime' : msg['txtime'], + 'MuxTime': time.time(), + } + await asyncio.sleep(0.05) + logger.debug("< MUXS: %r", reply) + await ws.send(json.dumps(reply)) + class Cups(ServerABC): def __init__(self, tlsidentity:Optional[str]=None, tls_no_ca=False, homedir='.', tcdir='.'): @@ -312,7 +366,7 @@ def normalizePEM(self, data:bytes, fmt="PEM") -> List[bytes]: def rdPEM(self, fn, fmt="PEM"): if not os.path.exists(fn): - return b'' + return b'\x00'*4 with open(fn,'rb') as f: return self.normalizePEM(f.read(), fmt)[0] diff --git a/pysys/testutils.py b/pysys/testutils.py new file mode 100644 index 0000000..ed557e7 --- /dev/null +++ b/pysys/testutils.py @@ -0,0 +1,40 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import logging + +def setup_logging(): + logging.basicConfig( + level=logging.DEBUG, + format='T %(asctime)s [%(name).8s:%(levelname)s] %(message)s', + ) + logging.getLogger("aiohttp").setLevel(logging.WARNING) + loglevel = os.environ.get('LOGLEVEL','') + if loglevel: + for a in loglevel.split(','): + lgr, lvl = (':'+a if ':' not in a else a).split(':',1) + logging.getLogger(lgr).setLevel(lvl) diff --git a/regr-tests/.gitignore b/regr-tests/.gitignore new file mode 100644 index 0000000..d2ca30e --- /dev/null +++ b/regr-tests/.gitignore @@ -0,0 +1,7 @@ +s2core-html +s2core.info +station.pid +station.log* +updtest.txt +version.txt +t.log diff --git a/regr-tests/makefile b/regr-tests/makefile new file mode 100644 index 0000000..84cd456 --- /dev/null +++ b/regr-tests/makefile @@ -0,0 +1,62 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +INFOS=$(shell find . -name 'test*.info') + +all: + ./run-regression-tests --nohw + +ci: + ./run-regression-tests --nohw --verbose --travis + +# Reset test state +reset: + rm -rf t.log + +# Pack all info files together into a single report +s2core.info: ${INFOS} + lcov -t "s2core" $(patsubst %, -a %, ${INFOS}) -o temp1.info + genhtml -o s2core-html temp1.info +# lcov -r temp.info '*/test.c' '*/log.c' -o temp.2.info +# rm temp.info + lcov -l temp1.info +# We're not close to 100% currently +# lcov -l temp.2.info | grep -P 'Total:.\s+100%\s+\d+.\s+100%\s+' + mv temp1.info $@ + +clean: + rm -rf s2core-html s2core.info + for m in $$(find test* -name makefile); do \ + printf "####################\n%s\n####################" $$m; \ + ${MAKE} -C $$(dirname $$m) $@; \ + done + + variant=testsim make -C .. s-clean + variant=testms make -C .. s-clean + +super-clean: clean + +.PHONY: all reset clean diff --git a/regr-tests/pki-data/cups-0.ca b/regr-tests/pki-data/cups-0.ca new file mode 100644 index 0000000..abc84a5 --- /dev/null +++ b/regr-tests/pki-data/cups-0.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDgzOVoXDTIyMDUyMjIwNDgzOVowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAw9ay +2pT7vm58x5afhlg//nxrsOTvSQUcpmQHm+gG/22zp26FiRfvHeTRNGtduUd4234u +zD9HjlzaNb96AvJk46d5GEgfVTaLLC7NXrDsgEBO5nXtGzKiR+B2WgeYP8u13R4q +eNIWXM0Lc5aIl7Tl+awwkhA+5+8jxDd64TFmPLQatMx+J7DQcvf+lyt7orYPVerA +PPfg7DcWKdv35mZ2SReXeX7GF3027L56cb/VgUzRHQTMEi28SWlEkL2e2Ik1iqwn +aYQWPy0Z+qXCMvEkY+nQ83+ynneiNDKs/gBWARxIjX9JGoRCacyKecMOcWWhlHiD +OXjfsy+BkOygkHtMkN9PLyxZC7AWWUot62uXlMSgexryHFq2sDQoaiL8VayPCjoq +i53aUoHql/ERDvLFn/VLjgbzSDRpbxJTU1tV+TDeeco0AThlxHefVISIXymfAQ0Z +WnF7zEYm4dI65KHfRafCvnQ3mIErxrGo16fvVIbp9UNMnbOeBoSBB13AT5Hf/Xu/ +UQgGGzGbGV1fr788XefdaZ8rGksSzBEdavRb32CbimzRSSmKcYfaG4Dgnh58BEsI +WYaiByJiMd95q7wdP2R3pqwFOSsO++dXOw/yHfgPC7wVPDCzXx+pBN6NWVFQM1Mp +y0Mgyhn+5r9pw/ce7T/jDVugw3heWv0Brg+7HQMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEAKTgA8pyQWrPKgbNQAxG3kgtdaWcb7slS4NdcjL2flWplTiGtUMZYkQyK +CIXYZieOim0aSewH76r/MIuLomM33p1+ltA29LTRtxmjrxSGBRDCWOWysa0snp3a +W2WjkWXNFhCTP+urHTSAZqvnXIxN6emsvwLtO3wisbIzhCUzzwvpI84hxvByViWc +EPChEfOMMqn6uF4Kpdeo7GT8JFV3p+Tpn8S0TzXLVRGdIqTZ5aAa2uHOlc+3bmm+ +CH06YkxVhVi/bkJ3XFE0x+GUvE7jz3Zceznfbhilwbqmma7M/HSA+8QKlSUWwppO +qbAUXK+kZz7flrPrST+vw9ZmvJIWWdRb1m0PjQn1xclE+Fgrgs5HJ2GUmgID2kch +aHxpY0tS6r4tMvch8bCbJ5SQqe1VSp8Yly9ePPBnBHRaQf5ZiXPorSfwhDBhuwGl +dyLqhfmE5TFCH0ElRy6cW5xTZ7P1gche4b9e2FkQMeZgMvqvves5fclEXiFHotzt +WT2yDiIznZsF68Y0U4d5c2gLJDZS9MzERT9ZOwugAJDdxOl8ovSCZqqcIT2OFKDu +aD0YGQ0bVWIYXRdthaIr+LfDtafHlx869HY5U3HQAq1fbVXnAn87+aqILRQm+9Sl +xaXXmfOwmnP8toLo1957OtAlWO4oFDxWS0rYAxiE08xPtsTqZzU= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/cups-0.crt b/regr-tests/pki-data/cups-0.crt new file mode 100644 index 0000000..386498c --- /dev/null +++ b/regr-tests/pki-data/cups-0.crt @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEIjCCAgqgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQwWhcNMjIwNTIyMjA0ODQwWjBIMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +ETAPBgNVBAMMCGN1cHMtOjowMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC +AQEAwGjk9WYmvJRhW3mk8nNDEc8qRGh3zCUVt/3Tpgx4p2PPskayZNQCNDCuO6xy +a890cyppmxxeKflxazxB9qXODeli/++39TJL3p7CtIVdiECoKsQiQBFfLbLitoiI +hG9wv4tFaT5IE2A3hewBeRWc4/egUvPDvz9SsO/+fAILcQTA0cjW6uPe+Frvmegr +5a3BKXOMhqvap2xqN3Gxf1IW1b7tvjP7LoezxnakepvUC6MxZgWQ3pkhLd0La78N +LKx0e76J4C2NjXaZbGtgLO7/v7EllRSfJ5Z8bbfpJk9BjK0MAQLyPTUtn/QMvoNV +et53UhxUF1mBqmdK7Y1tNEflEwIDAQABoxgwFjAUBgNVHREEDTALgglsb2NhbGhv +c3QwDQYJKoZIhvcNAQELBQADggIBAH9255J407pOHfCbxB61YhLEwErZvgADOltb +S1H5K842uUcQbS+0lYODnEJJR71uoLNjoelFMowfxdhqpskzL4fLGLG2qG1pF37v +E4u/sUIoeDTHeoKl/T4ksYyxGKdpWupzSLF9exUbCMmLNTQPjti3hbt3syZ4iDJx +7K4xIOPbyKZsA1YajTn1IGjSPTrnrlwvPlQg5bsPR858NpksT+nfb/KPZvMV60iI +VSGzGbdX1hqkbtIihqp+VhOoHPhLK3ay7hkoR0GzX8pdQ45tGHgJRUFpn8bHGm9W +nlfmI6JSwGkKUN+8ZCZBm8luG5M8WlqvfhkN1HBXTAtAL5HVZsG5Qb8nAkF8lGjv +kZQBMJTtgPvkgTm5eH3uOS4v+Bdml0pTeiG38VTJgY/SjJvbzTG/z9Twd01uXnTt +Xi7d8yhe3wXlnwqg4T6AyJIms9V/awn4+hCaV8u6frZlNYKVbRjYlfBsmSRUilNm +c77HzKLhhUCq+wq2pSqQhwOh2OTtlHYAg/oW1m+gj4KagNH7OWwjFCXDxb7+Evqt +F0YIw0lKN2ag6rDHCWfUsSJL6WCOAuH6yYYdiTb/ercucxNSzrPP2EVMbpnZK6eU +fS4badasOAtX5gyET5SzR+xSDBaLQznZx6qh0w3ycm7b/65tEgpnA6RsfExY0/Mc +RVvBNr0Q +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/cups-0.key b/regr-tests/pki-data/cups-0.key new file mode 100644 index 0000000..66dbba4 --- /dev/null +++ b/regr-tests/pki-data/cups-0.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAwGjk9WYmvJRhW3mk8nNDEc8qRGh3zCUVt/3Tpgx4p2PPskay +ZNQCNDCuO6xya890cyppmxxeKflxazxB9qXODeli/++39TJL3p7CtIVdiECoKsQi +QBFfLbLitoiIhG9wv4tFaT5IE2A3hewBeRWc4/egUvPDvz9SsO/+fAILcQTA0cjW +6uPe+Frvmegr5a3BKXOMhqvap2xqN3Gxf1IW1b7tvjP7LoezxnakepvUC6MxZgWQ +3pkhLd0La78NLKx0e76J4C2NjXaZbGtgLO7/v7EllRSfJ5Z8bbfpJk9BjK0MAQLy +PTUtn/QMvoNVet53UhxUF1mBqmdK7Y1tNEflEwIDAQABAoIBAH2G8Xi4ACWfmDSZ +k+cpE2SXBzhB/4YL27OBwYbfNAfgsivYu6HUPuvVppX/11ZGre5EiUlMpJI1zqzr +Tw2e9mNVE+Vte1JYUe8XHGexamft5sif1Mh/jNy/i/ER+h6Mpb4RGmOi4lrhtteE +NSHN2+FOOCZmKhqnMUeGCzzUCKreD6ysX1mir2dlfFeGilruQxXokS6XBAPJYW7J +C1BL+DzIGk/GAfCRr6EApgGCRcxXnE4aT//EzBqch+MzN55LZqe09T4IihVw6epL +7HcyzhHVDjdgi6E4BYEFyu7YS+7UpWbpZmx5E/QnrZlLqaOGaj/fUJspvwuSLH0w +Ld8IQ8ECgYEA940yVDajXT4fRy723Y/8bPSsEHmIo1aWoWz+/09VUvEaKo919pPx +bjid4suUVl5BB6XW1biiTulGD4OHO0ZFXHCIGoZ7lt2/rVRgoW3YpqSN2S8wgkSa +aCORfKV5fnWRXiw8jLkehLM7qGqRNp5LYE2Xux3WNmYeSMjAuT84EgsCgYEAxvnv +mpgTI7Y6Y94BICaOQRfZknkyuFEdOC47dIIwA8NNqYh03WgOF3VeSG/Gqa5z5/NA +fT/ZY0OOXv1AWme2vtX/lYhQm1Rsd0uSMF6rZ4UfCPoBHz9D+/+M7fLLBBJKbYEm +NkBu43mGEBEFt8lLa9u41E68fzrjuV0sb6gxphkCgYEAiRTMMOwMrL6QzXdJRsnL +633Vpk3WhzSUtxFHZ5PD2OkgJz9IAGJOSE3byFIZc3ZAJn8EJ1dVscLlhAO+p+ky +0YyTIbUkzRdAZDgcRmgwl5752bGS+CALLO29S7vKOmfaNr7iTL7aEnu55noUrZ0c +elidVAWisH79+CoK5soGP58CgYBkZcBMVOdzYYNc2KvguROWLJ6Pla/N6L/BlTJS +u03W2DjbjgrJnLNfis0j56JqA6hgJREpIYpi17eCnm5WL3a6G+h2Xu2tMo/4MZ11 +4o7CER1zvhHK3nVDNdK6TYO6bjA3yK6rOR+6j5rhiHVGIr93kMpV9dSOrfwxj53Y +SRmkIQKBgQCf0MEWvI1CtzqRGy4sDGQBiKHGlJeguuV17ZhjaWyNVZRQXFIe+0Fc +OUV0pigzpNYwHYbZNf01rkl9V34jcXlDnzN/8i42ySgjzjgMewBj18+Oy41Qp/lD +m0dUrTDTvj8FbBmVDbpYcxrrOXsxPMLETQkMUxT7+wA9fEbh60xSYQ== +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/pki-data/cups-router-1.ca b/regr-tests/pki-data/cups-router-1.ca new file mode 100644 index 0000000..5bcc1d7 --- /dev/null +++ b/regr-tests/pki-data/cups-router-1.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDg0MFoXDTIyMDUyMjIwNDg0MFowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA2biQ +IKlJuVjq8s5eYXFNUXkMo1lQkeeI91JJ6nMOhjkF8f1MTuijoVULUBxRSN8Zx8yg +BYD84DYn4NwyQuoVa0bMlPBjRKCBdvXTDDqvO1Qa8UL+awhTcM7U4Ki03BhQrB3c +sf6QMN9FTvcP7VCDilUXEmdgM5EasF2xCRJWQvOeKPylCojUYlYaENhUYjEtTR4M +ln7omr6dA3gmmbfMix2RTmv8CP2m0gYKOmH9hzo5S4fmeo2L9bdStrDJdHjSNykc +iJxTBsO5Q+rx8cFCXugH0G0cIDJXFXEd/TG3YqOjNXAwv6EaTJC6B0GA83PZUxyE +XUFTQEoHIlvArdH1IJKqguI69gUrkmbE5WQtKpLEZxeGP2QgWH6DzrvG/xTSc21V +DkHhVB9oL8NdNsDPXvHlhSdX8SPn+95MCeqsS6TmpVdllsqc0x5mx9CXGEZ7vsjl +Hzla/5TP7lKOQWV7WpZ6z2e6EeO6nVlB/IdBxFzuppWzTVeddjbo1qOJ8Jip/rgz +DE1adb2jLLY2wnXD2aPLcRp5O25va6TV110YJpPZuraQr8mt0G99G+LzAhV1pk2M +u+YVuxt4vcauITGHnyEpVCywEUyoOoyA2qnzsP6UtgBFDHMFGbBfqjtYk9TpVMwV +CeisO2j4aMvf7kx0/lKe69ssj+3ckGNlDsGQHdcCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEAVXyYan79ptRfoRBN6thLgU+LYjzyt0Z7xZDRRZgUCYd21j+IEyRuqhjh +g6w/bmgJ85M3/GbcTinjOxCFV0d0+yo5/2kQ/0TySiToAWgGhQbTOaCY13oTAlMI +W1ZHOmnsCbdTA0QNB1REpyEu/WY7Gq5Uzhk/k0LpCPW735wwbPEuZqxaCmkrBlMp +ubtPWIV3Br8IrpjglB0kM62TPcVxYCV1f7uyWviUYKxNrWXr8Rh+EorlZRZ9tQQG +ZVnrrfbUCSwnHZ4Axx/7V86EXT642Mu9dFKZSVG44cHIqp9VRoqDub4E6P6+p4ml +RiaN8hjz7NDtXV6+Cxtqm7Zh1s25T31WFTCd4VJadqV7NneLOUOLdV0qgaaxK7Um +B9JgcQimV69YmZ00qYyd+rQzzkfhZhLKS55X7yIwvnuuOSABqMzE7xAEXqPmNv2c +TuYT6voCoS5gVauKKmn3pddQERy94QpDc8HmWfkQDmopG6hTFJ0pC0WPmwn2NXaz +/FA5PHD5i9w5mz+Bxpr3xFvnAFJEux+ZxY4URJZypSnUMvlUGcn1bxJwY6hMGbeP +XckEqnCU2+IrxI2IUGwL/H9L3bQp4fGw7LTTcImDtEv1/8uplK+K007zG3lbiPKt +JRRBYORcbZfQRkuYphJkf9W4t20XL6++v7OVRahu6vNx9TqGw6I= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/cups-router-1.crt b/regr-tests/pki-data/cups-router-1.crt new file mode 100644 index 0000000..7cd60d9 --- /dev/null +++ b/regr-tests/pki-data/cups-router-1.crt @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIECjCCAfKgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQwWhcNMjIwNTIyMjA0ODQwWjBKMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +EzARBgNVBAMMCnJvdXRlci06OjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQDEPCHeQckoP7YjEJBWk+qKjgsDed33TlqqBc9GzPNn4hvNetZ57bOKi25S +KRB9tfdyXGEZREFmKdoENp2iYDWwCOxj9KnZYJLeUS+DZFF1/whjKJlr4MM/V7/Y +pnTBIqHKgdTN8727v1N4uUlWhW1cncEXaWFlsl7s7XRDGUPdO0JzNR8DL0p4jBOO +QlaO5RGH/+MaHrAIo5eQ+oBHRuHcFRNH4iDTxnlpDTp1uI2c6vh6PQ7VnnEoYHFR +bMF11CTpluaiEYCt/SzwVjOwT+mz74HCSk8jwI8J86rjdStXgezG1wTWmSKnsgcC +Y7MNYBKLeaZg3UlsTo2HftKo/CKxAgMBAAEwDQYJKoZIhvcNAQELBQADggIBAFPH +3c42YjjhhEBzrBXBGN/4s8zjzuendBJxNPvCC/XqmKGmqtSL464JSppoKdgNvPG8 +0/0vmbPg/9/UNLDRdZPwvdgRxz7YMl0YoglWbI0+m5vGKfzKL/4T5YsQAghjixp0 +zrbM072TlJLSJzGbLwuvTAdQjfNnxFLslaOVrBlx83cKpF74PmMQBy8l3EyHf70r +hwJflppib0cRjY7UYLCZb6LssCFO7BIjfsLrlQox4OrUZKfnZMmHBiBVAbijbFQk +cnZ2bh4nWJsUgWF7P2+c39LOWQv34hp0EBqBVzfIsrjbgxWzLu8ZIEXGEPOgcFsp +KEu1DraMxzVm3OHxDmDMO1l1sLV2Ilo2BXs/GfqvxhrwcuJLesf7orkEhZEjd2R2 +ofsdT3dbWZTZrXmWDP9jbdIhSh2mHEoAJppe5GWTS9SkKNx5Ne7nNPGQGVeru8y+ +FW7NJDiOqdH4UttWYE+GWPE7hDNq9bz27gR4WtHwZ3MhRjZD0ricUoNVxkXoFI2p +oZi8M5bt0e1+qNACGvLBd3NfS9D7Uk0mkcKZEgxtA1iERxzl7knwi2hMj1GMv4p8 +FTjBXtaDmizDufQm9x/rLtsG8mtg7auhvUSkhW3rFbO/5OGWxZKqMDX40+ZTzE1F +9dDslePP+W83PV8MdjVy+bcC9R6KL0B4RbT+Egqh +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/cups-router-1.key b/regr-tests/pki-data/cups-router-1.key new file mode 100644 index 0000000..b5df21a --- /dev/null +++ b/regr-tests/pki-data/cups-router-1.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAxDwh3kHJKD+2IxCQVpPqio4LA3nd905aqgXPRszzZ+IbzXrW +ee2ziotuUikQfbX3clxhGURBZinaBDadomA1sAjsY/Sp2WCS3lEvg2RRdf8IYyiZ +a+DDP1e/2KZ0wSKhyoHUzfO9u79TeLlJVoVtXJ3BF2lhZbJe7O10QxlD3TtCczUf +Ay9KeIwTjkJWjuURh//jGh6wCKOXkPqAR0bh3BUTR+Ig08Z5aQ06dbiNnOr4ej0O +1Z5xKGBxUWzBddQk6ZbmohGArf0s8FYzsE/ps++BwkpPI8CPCfOq43UrV4HsxtcE +1pkip7IHAmOzDWASi3mmYN1JbE6Nh37SqPwisQIDAQABAoIBAGeg3b3Sfdk8dAHm +cGLYMCbFRjmqtLYx8Z0R/lkESJIWjNohQXwYNBU49qR6vRO18Zu5/yjpq6O4/EH3 +WZ1zM0boH3XVsZBy+Hxg4TeA1af7a0F6IjMe+dzMiSpvFP8dO9WGZIvyaMLqEbmS +F5GSWqNrR5oGc4HSBWEXMKtyfy0nffE/FTCJCVK2xFr2nIH9poAqxrVx0fj/4sGu +rRoEdIKvBbRzu78o+salKlPEKa7NXbc2OwBj3sA06JKdKvdnuLhIeu/GbH/2uuLS +eizadUlya9Bvb2MhuUT52vDfbucSpLtCG6ByH0XKqDoJ065Al9sAoMUSOrU4UKPW +5fBsJEECgYEA8BwsMI4nkjxf1lPf9y1ZaQVZLL5pD/r+SPRHoysm0VzG6COYPMct +Gvzy/9ZPyP8FXvhxoLUV9PqFMHd0fdbNQdpD3/DR+62v9byaepMz5pvEyWuXTikZ +jMGtozOlszE6SAMLmXO4CYMhXTfrZhtpYR/QWGKFEdE2RxEdoOQG3dkCgYEA0Til +7YkNTElHjE9+zYgRSZCZihI9RjRJzTTIlw5PozTuyi3uVIy86z1+sbTKRVpgnxKW ++h++HJh2oJQZs4otYxIn5oVyw2vBRkAv4H/27ieITdEScLDLFo87NX2RWgaJH2Jg +3DypSHvXhKkd56ayrXVzh96Hy7u1KjosEkVabJkCgYEAtrXZcoFZ30+N5fwhO2gI +13+4YfHq5Lwr77vjH2jguwQMX+1mFSnDSvwctU2RnPNiVOhdHtttf+N6omzj+jYQ +LwI2EByizQ9YDHieXJPTNLJnxpXWpyVjSda/mKbeekMFhHK8yuJhsutT4imBOUu2 +nq+kzPz7IZm/4chGcX3TM9ECgYBa2yrTWGz57+iuOedrAeff9nd2yizpy9Mw1fc2 +AfT7fwUjr4aMGQIBdhcKvOQJ8hF7gusle5tnd54sZaQzn5HOMBg7tz/7NVQdWcpw +x6FIEsrSYDSN03ieN10TAZCZc7Ugd+xwN7ebzovtBDQEYRO+1/5vxmdaRg2KZPC2 +jn+SIQKBgQDNKHyX+IpPiA1wjC0yDLfhBYVjKEMV8O7B2Zd6ZX45T1lQKMSSYqxn +VxB+pB8AgtwPSxV4MV8zzyvM1gysvaG9YR2q1RNGmSLa08L8fqtAeOyRMphT2QqB +35ApbhA3zDceCcbtDjcf2bt+vpIwQb1QWMaqIiJIqtSIvvBrcv5EqA== +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/pki-data/cups-router-2.ca b/regr-tests/pki-data/cups-router-2.ca new file mode 100644 index 0000000..5bcc1d7 --- /dev/null +++ b/regr-tests/pki-data/cups-router-2.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDg0MFoXDTIyMDUyMjIwNDg0MFowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA2biQ +IKlJuVjq8s5eYXFNUXkMo1lQkeeI91JJ6nMOhjkF8f1MTuijoVULUBxRSN8Zx8yg +BYD84DYn4NwyQuoVa0bMlPBjRKCBdvXTDDqvO1Qa8UL+awhTcM7U4Ki03BhQrB3c +sf6QMN9FTvcP7VCDilUXEmdgM5EasF2xCRJWQvOeKPylCojUYlYaENhUYjEtTR4M +ln7omr6dA3gmmbfMix2RTmv8CP2m0gYKOmH9hzo5S4fmeo2L9bdStrDJdHjSNykc +iJxTBsO5Q+rx8cFCXugH0G0cIDJXFXEd/TG3YqOjNXAwv6EaTJC6B0GA83PZUxyE +XUFTQEoHIlvArdH1IJKqguI69gUrkmbE5WQtKpLEZxeGP2QgWH6DzrvG/xTSc21V +DkHhVB9oL8NdNsDPXvHlhSdX8SPn+95MCeqsS6TmpVdllsqc0x5mx9CXGEZ7vsjl +Hzla/5TP7lKOQWV7WpZ6z2e6EeO6nVlB/IdBxFzuppWzTVeddjbo1qOJ8Jip/rgz +DE1adb2jLLY2wnXD2aPLcRp5O25va6TV110YJpPZuraQr8mt0G99G+LzAhV1pk2M +u+YVuxt4vcauITGHnyEpVCywEUyoOoyA2qnzsP6UtgBFDHMFGbBfqjtYk9TpVMwV +CeisO2j4aMvf7kx0/lKe69ssj+3ckGNlDsGQHdcCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEAVXyYan79ptRfoRBN6thLgU+LYjzyt0Z7xZDRRZgUCYd21j+IEyRuqhjh +g6w/bmgJ85M3/GbcTinjOxCFV0d0+yo5/2kQ/0TySiToAWgGhQbTOaCY13oTAlMI +W1ZHOmnsCbdTA0QNB1REpyEu/WY7Gq5Uzhk/k0LpCPW735wwbPEuZqxaCmkrBlMp +ubtPWIV3Br8IrpjglB0kM62TPcVxYCV1f7uyWviUYKxNrWXr8Rh+EorlZRZ9tQQG +ZVnrrfbUCSwnHZ4Axx/7V86EXT642Mu9dFKZSVG44cHIqp9VRoqDub4E6P6+p4ml +RiaN8hjz7NDtXV6+Cxtqm7Zh1s25T31WFTCd4VJadqV7NneLOUOLdV0qgaaxK7Um +B9JgcQimV69YmZ00qYyd+rQzzkfhZhLKS55X7yIwvnuuOSABqMzE7xAEXqPmNv2c +TuYT6voCoS5gVauKKmn3pddQERy94QpDc8HmWfkQDmopG6hTFJ0pC0WPmwn2NXaz +/FA5PHD5i9w5mz+Bxpr3xFvnAFJEux+ZxY4URJZypSnUMvlUGcn1bxJwY6hMGbeP +XckEqnCU2+IrxI2IUGwL/H9L3bQp4fGw7LTTcImDtEv1/8uplK+K007zG3lbiPKt +JRRBYORcbZfQRkuYphJkf9W4t20XL6++v7OVRahu6vNx9TqGw6I= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/cups-router-2.crt b/regr-tests/pki-data/cups-router-2.crt new file mode 100644 index 0000000..94dfcca --- /dev/null +++ b/regr-tests/pki-data/cups-router-2.crt @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIECjCCAfKgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQwWhcNMjIwNTIyMjA0ODQwWjBKMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +EzARBgNVBAMMCnJvdXRlci06OjIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQDwyTrvZAnfyXEA3HP+V54UJ3AtWcJF8uwONHfxPDmMwdz2eeRG5jwgC92R +f7OHUM66eHUfXEzoZ3w1HnMEu+mQT9LJ5cb0aGkryRDr4J6KiGp58hO4SYCgVLpk +DOnTq3OdAlow4KRDhxC2p5jt0SMUtzZ6jIv5l57HTmFNRoJaP5fR5B4ofiSHXXpo +nbIgm9rWAkEAPj5b0Pf3mPhlXMqzeIDDKBP5eG6VE6C9t9XdyAcq4yuiwrp2654A +JP6utgiMzU+U3jxzxXPklJlYPVFjWhTgAfTC3Q8YSuvKEKFtPHKTYh+BAKr/jnPD +6tbyysxjkbg0fY7GIh9lRq5CAN+vAgMBAAEwDQYJKoZIhvcNAQELBQADggIBAK5G +HBejXZ0kK9k5Os9cSAhpIrXVXk5wc8EYZxSy3Ohm1R/Q5jWOX+iFUT+njQ2e2l4e +5gFj5NSwyTQC9gnLGIWEQ2ZjVvCTvXYKRSWspMTi+9/0J6VFZwGNe8WQBWiczyFL +s4001ns0Ok1azd64S53pUPHmR/LIayEisxYwtQGdTUl5HvRrwTy5KtVMoz1AzjYw +fqaUcb3PnJpraCX4ERV5SapdSzLzjtC7OahYwGcWmcsEGa28JuGlEo5O4vZmpHD6 +MWxjzuoIwQBKN9DQ5Er4MHu1uxo+HpqP7C1O1HTi15abJ1FQ6awV6XIrxLXbJJ9M +liFUu3oupMB7sZMKfgEzeruFkoVdDvjOmnvwg4NP03NQK9BeGKbA19N0/j5l+3Ar +V7Rpt1PjvalpthQTayBh0aWZV0nLSgyPNar9k6Pn7r2yyaF2vN3Wi1ug0Mv5QlMD +AfFKJ1IAHFEjZJmyKHXH7JhMhI9/0h/bnSxY8yC7Hf/hPm4iU/3zEIMA8Xcfft/6 +VsQMK1dtJNdBVHVOtQJt+NcNscXzMCDRg9gDluwseP1djIEUgbxyp/Pwkr1ftuFp +9KgRQ1qpoJLWu5kn8zFR1dWGSLxHx7kXDx/hVZL3BIRP3D47M4gVRsh7Lq2GtrhY +T/fzGIge3Sj9NId0fWcaG07MR5OfpilS9GTO9EQO +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/cups-router-2.key b/regr-tests/pki-data/cups-router-2.key new file mode 100644 index 0000000..dd165cd --- /dev/null +++ b/regr-tests/pki-data/cups-router-2.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEA8Mk672QJ38lxANxz/leeFCdwLVnCRfLsDjR38Tw5jMHc9nnk +RuY8IAvdkX+zh1DOunh1H1xM6Gd8NR5zBLvpkE/SyeXG9GhpK8kQ6+CeiohqefIT +uEmAoFS6ZAzp06tznQJaMOCkQ4cQtqeY7dEjFLc2eoyL+Zeex05hTUaCWj+X0eQe +KH4kh116aJ2yIJva1gJBAD4+W9D395j4ZVzKs3iAwygT+XhulROgvbfV3cgHKuMr +osK6duueACT+rrYIjM1PlN48c8Vz5JSZWD1RY1oU4AH0wt0PGErryhChbTxyk2If +gQCq/45zw+rW8srMY5G4NH2OxiIfZUauQgDfrwIDAQABAoIBAQDDKlgasXtPaHev +uwBJp7r5mv3RxG8zQzMSUHTnk2kSLhBrt2DQFs2lK/jrdhaOF3F4syo7wRSVS0vh +wkx4CdfGoOy5uQUKFZcpZk/Q4L+gifHD5fMV7H3VdtedQNpGNzH+kWmJNIvwMAnc +AvxxxpIouFfv/Pt30u1fnqg/emctvcsp8HX46eZdG1TnBlydfAnyOQRh+LHFo+Op +wDydKJe16YKXI5SQIE1BwAfBC2PO9+sObks82o6sZpF3N8k8DCyikar6RLy/arBR +ENx3HTnmyYZhsEbxKCjkHSIAMx0Yiz9mG38lo3/gbfd9V7x9Sd/yC0WUgXIfluF7 +QBhhAHABAoGBAP+mnCo7YmZZfNlu8xFx/MAL3FUWyMO+2+6UH36LQ0lQkPP7/MKT +LK8cNez7SVRvjRmOaBEjK3uRPCYND47ftev9PcRPZATzfzCoNxLj/N+TUv8gCslG +7kNfpA7wtjG6eZVsnRA0zcS7w5rCg6tWkaQ4mTK1EhwtSey9N7r24JAfAoGBAPEd +bDG41FgNyswlBjcGaANvJVmVlDooksF1MM8lfJD4LjelrKZHMp+KEwPydH8k/23j +m12HbY00skE2lg0rHnNQVwkOCa6JVmEsoSlEyIk79oUx0pQwwaOQ1bcUKZAHE93W +wXzJQYYDucS/ohxlSpjEDdgBPIilI3NXFkIXzn5xAoGBAKJTm0Mhk9hjJ+g0D7jb +BN64aT3KCs5nyORTPzAtoxrRQkj5jsPJiYziv8bqw+QONKyuhJulFj4OuP98OY3B +tJTUpryYoGyYZAF0PgwLoYwg0olWQiMNm8pB1zz5UOaAfiUH4y7gKGurwYbpzYsk +m7OHkJbm7Enh49ejSdi4W1yHAoGBAO2JAvHpGKi2zbdYMks7MHVRpgYfaivxlMKp +5S/tyk43cbC4suIM+j5aFGmrDkHD/TARLxpxNOgLpiDA2gqXFCSeXWA6SCd+fW62 +PP8fGEC6ph6J+t6rOdkd8q2uW1Pc5SGDVJLO4pJYUUcXU2mOEHN3kfvfG/eyWL5k +aTUrpu7BAoGABhRWpvc+fc1+6HP9Ivw2eQ6HE0bbISVYaT3LMcqc4oQWjQL0IPQU +1qAh/HxuPMwd1TlLOLmwUNNONrdvoNMxwNosM1WEap/yHzSwwn157n1jhSadlObn +l0p2sITUA0TdKm6g0VYAbcbuABFQ+/8tvmyI/2LrTVZjTvZBA56mXQg= +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/pki-data/infos-0.ca b/regr-tests/pki-data/infos-0.ca new file mode 100644 index 0000000..a57013f --- /dev/null +++ b/regr-tests/pki-data/infos-0.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDg0MVoXDTIyMDUyMjIwNDg0MVowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAw9uK +AnUd4May00pDyx+FLedjIFy57Abw9VTaVMAtF2DO4M4aBgQHXhKGt/9WQF0eorYU +3m0mbM6J5n8DkJB0h0YwgnHTm3BNUNf5mwaKIp7q+3iVbgiZTYRbiIyKluUGEbkG +vxsRizdDt0z8wnKd6EFbC53aFXeoxMzy0A+eTHBWr0VfBf8q0lGC0yta7HvrFv4q +UzHmzctVcfyxG5+SovFQnfoVr0Qx/GnKEThEiflrXntlcIGiyl5fFHz/7GCvtnNz +2GziFWj1JbobNJjHy9EgFYPUPSLYzvlS6QRqTv83JX/iwq7Q1IiBpHdJygm80yr3 +FSAEu7yKXaDG4bEE1PPOqmo+RvuCgRlw/rtIdEz6iLTPO9G1KtXQCc4/bletwn8k +bFXwLe0dABRF81UgRK9OCF1McMlrINEViV9q98P6ADKn4O39PrSupuqSJG5rijjN +1/7W8kFcwWtk3rMgQMnqtc7X/+CsK1MAD/8Wspwn3RcQGWYYA8yYAzz9h2Hypiuc +ef5WVlSuwL696MPhiRZ+FGtFY+30FaiTBJtIyCJEdUo6T0uEg6xN3DaJ/wuNuaMf +JKMGBWYv+5YlLKgY+ti337VlQ1CbfVPetLExzxB9sYhRVs03yA7SmEa9rDO4Ucp0 +xMPZbJ9nNB8qnP4lHZdD72HOJJDqLdjOxZdVjiMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEANWyLwBRTrzqO/mNMX6A0DTDGjRGD+w3rMVzFmliosn+7CNbHQl1km3g8 +zvvX2+W0GBkXZm0y3i3MfdiUlW3/l54ysvIkLB0RL3RS0OxO0U9LjRzo8W32D9Gw +wO2aBE3qYGx2PJMghaJNTUIkqNjISmbvTKvR/1qjHJytJP1OCn1ssEtF3h+qvjNW +6GUDhHcKka/9o/XjWSq6nB1i1LDKtfkkoBVDk6xN7UogeJfjHbKfYVHl22kWfmTW +spXG5uIYzkOxWIuWVeOBmUyZqSnqbjDIYtOzLPJ+FxYgf+s6fX+MYjzmOsiHpEUb +jpX5qLT4Mn0DXwuBQ2cV+hH6SZphZOsVt/g6kRrWnxQY+tcKcBSVxlHv5M8JWUMf +p/rjDmUUFPkCi/Rd9mCaBlsCB71q8DBNLBIpWF0y5bARkSGXmesbpF4iT4l8sJhy +IkShtoEuThEi5BGFm8OItwglc//oyqK+fDN5R/GIvn10tAYD30t/VYapOE3C8LDy +Yo9+pMWxZIO7gr1dOe0Fi6JBIdh1XSnF72FCv9q7YQUnX1EkbDSyuOilE3qJYkOj +EwdlVXXhIYsEIX66RlVYidUgIF9UabMQbJ4wfec+bZb0KHrvEyMaLC0UJlV6d7wK +gKj/nR8McJ3zETt3mmvNwM4TlKR60F+SDScVmabETxe7u45M+/k= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/infos-0.crt b/regr-tests/pki-data/infos-0.crt new file mode 100644 index 0000000..83e185f --- /dev/null +++ b/regr-tests/pki-data/infos-0.crt @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEIzCCAgugAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQxWhcNMjIwNTIyMjA0ODQxWjBJMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +EjAQBgNVBAMMCWluZm9zLTo6MDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAMe27DmxOgqNh5R9FIm5SRv05kFD5JqrayARmkUgvsLcmldZt79F5RURpGO3 +DFHd8jPu9C5Gg8sDGCgeGgBZUdoN5ieO/DEs+8vdMYOPb/qY0749u0qjBV7hS+oN +aPxgauA10wVE3yWV4Gynn7UgEgodFxRtIaF9m3ZUE7EjefPK5nDkd+BVL6vtajLC +JQtox/pcYgsUjIbVNwRkFnYwdUWOoAfWHnuodoM5T7JmYx1thvATU1RJeQGFDvIK +s+lLMtvdZJqlJhh5jt713fsRhKfI268qCYC5O+rUm1TQe2JCNvRvA5ftnIRYLYVM +vEL5hOjfxDoIvm8wsWT7JI9IOx8CAwEAAaMYMBYwFAYDVR0RBA0wC4IJbG9jYWxo +b3N0MA0GCSqGSIb3DQEBCwUAA4ICAQA0/9zCdlZl7LfiqQSIc84cgJFmSuaVNXRf +miIjtM4Uzcot33JOiwfaKiJi9NnyDDjwfj/7xbBkrt0xSLxwTuPU9hpbfoFoQRzo +KprR8tGOGIIF8Vvypkoo/T5iPDbOHxIthw80r7FjSG7dqhvGP/2avLOexb+xsypU +hgWlc0qaCp6TcWzFaCo3Qabtubv7isBH1bU7UHDvmPynHTANi8B3tcy5NSjjD8Hn +PjNIqwwVhQIqbCfO5o8RSU4ss6deLSNtoFIeeA0nfvuDlUXNitkK/GWB95LMchX8 +WWdNWhMoM/k90GroNjiwQrzsaZjiOqu8c54S3MwdG1rO0fkfSo4FrVIr0ISfywFv +37FvdxX55fZ4vAtXKUNUD/x4UlI/A+53sNSzwcyH6S5UZq8IvV1JgXOwChP+rPLA +JiHhD0oHmIR1hjtfJvWpO85g2CqKve7yM9iottQvcWq+liRDvKbwrJwFTkuKsK+S +td5wZYRE/ngOVMEL0rNBd+3mYTPtwu40a+DEdckqk0cJAx2cgFaRxEof0DWyUE/q +J1hS8B9UYvqtufe2jfXqGMZK/tmPyAtbFutibB0wSJ5tiu+5sbIIZGzxYhHAjTro +FfHcXZqJvVjeCJfSIWoN8RVhz5TJwhGkoE/NsiIrVemcMHGFKRjE9bvOuEj3vGKc +0NLRypONVA== +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/infos-0.key b/regr-tests/pki-data/infos-0.key new file mode 100644 index 0000000..0c36baf --- /dev/null +++ b/regr-tests/pki-data/infos-0.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAx7bsObE6Co2HlH0UiblJG/TmQUPkmqtrIBGaRSC+wtyaV1m3 +v0XlFRGkY7cMUd3yM+70LkaDywMYKB4aAFlR2g3mJ478MSz7y90xg49v+pjTvj27 +SqMFXuFL6g1o/GBq4DXTBUTfJZXgbKeftSASCh0XFG0hoX2bdlQTsSN588rmcOR3 +4FUvq+1qMsIlC2jH+lxiCxSMhtU3BGQWdjB1RY6gB9Yee6h2gzlPsmZjHW2G8BNT +VEl5AYUO8gqz6Usy291kmqUmGHmO3vXd+xGEp8jbryoJgLk76tSbVNB7YkI29G8D +l+2chFgthUy8QvmE6N/EOgi+bzCxZPskj0g7HwIDAQABAoIBAFmL6kU/8r9SkC0D +HFdYTbCMUUWINJMpMyIw4lQGh6IFmep6nsnThBC7VVMkexCmDHg+txucoHFBVO5/ ++LaZVfsIal7oXKmL+uaAqjfL87CQH7jYIwcnKzxMlmY+Vwl6DdG0MIbXR5qppfPy +AMkMtSn1uyh8eizXjgIzVpUBTCgD0h0dqIYTL16H6wE6bIsWPfhJa7QE7p4fVAGw +9Zb5L0/+J1cHKDg1Wb6fSVBLpybfDqnE8CiMeQXpH6mrSxhkjpLH341bork2S3RF +2CkPs0HbVycYxFE59SubQ81NlsW3j3S8gOziS1IuZOVe7dSiiIgxB0tgjGoQrqGl +UHmLrukCgYEA5f6Riz2cp5BIaUulwmPTR/fIQYmke4K6UjEWDcRuOwrG49BCgjEj +qd8zIwKW4CZTv90UeUb0HSU8WzPL08Z2A192wVL/OGMCSku3spa37xsWCB2tvDgG +taYh45KanPecxpFgzaskkHpaQKVGlYzwIR2Fl2CPvd+D2/Jvulq76BUCgYEA3kvf +F/0Orhgu88XK8IYfkyv09cvA8UTwj7xgFScr22qI8gmthr5JXfS2tq/1gBpoh1/E +vDErNtlP27uSSRvbhy+cL+fikBeARSvdULKBf9xa7oTqObMaOlJR3R6ATYjY/GlC +PcDrOxjC1x+a7ogarnmy/TNPuhXJJDfEA+TDT2MCgYEAjlVi4Rb6EcD67x7/sDNz +F8DCT7zM7BrVD/SMv2xnA2cB+w5xenzKo2AcF3iMwp81iTFacEt222ql1ZNSevcB +Jck4hx/EDrNHQY9mWcFohzLuCYvEbw0FKflsU5fw019xyHlDvURC1p7Bp+wgqICW +QwgwGqSJkGn5Am8gseVhEJkCgYACCrxf4gkyfDJiNtzoXLMJjQvQ/jAlhzaWe2p+ +hz+V4mKjpocbh7/wxwCuqOseZB+1rqGGAQWemVxsbkqntUPM+Bj9L6obHLwm5oI/ +7YPXAtUq/7mPEiAZjQwHdfJDxBAKMYVUP+NpRY70nuuzaTilhaSpQsFmujCAzqpU +RtOsdQKBgCiO/qGLZqfSFM6vdaYtzM4a9IedQYSMjpjqUNSQQ4kPnLLlnPxCjWLa +885VMht4dBrwWKUEb7+DRQVaCDX9V1LNKzilYnIOHQQ2UYAiXQkAIGOvllJbdB7B +Y+pRObz37Q5DOcwK5FHJKMZqPJFXNVk/LjJ/myuE0U2qz9DV/H98 +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/pki-data/muxs-0.ca b/regr-tests/pki-data/muxs-0.ca new file mode 100644 index 0000000..a57013f --- /dev/null +++ b/regr-tests/pki-data/muxs-0.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDg0MVoXDTIyMDUyMjIwNDg0MVowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAw9uK +AnUd4May00pDyx+FLedjIFy57Abw9VTaVMAtF2DO4M4aBgQHXhKGt/9WQF0eorYU +3m0mbM6J5n8DkJB0h0YwgnHTm3BNUNf5mwaKIp7q+3iVbgiZTYRbiIyKluUGEbkG +vxsRizdDt0z8wnKd6EFbC53aFXeoxMzy0A+eTHBWr0VfBf8q0lGC0yta7HvrFv4q +UzHmzctVcfyxG5+SovFQnfoVr0Qx/GnKEThEiflrXntlcIGiyl5fFHz/7GCvtnNz +2GziFWj1JbobNJjHy9EgFYPUPSLYzvlS6QRqTv83JX/iwq7Q1IiBpHdJygm80yr3 +FSAEu7yKXaDG4bEE1PPOqmo+RvuCgRlw/rtIdEz6iLTPO9G1KtXQCc4/bletwn8k +bFXwLe0dABRF81UgRK9OCF1McMlrINEViV9q98P6ADKn4O39PrSupuqSJG5rijjN +1/7W8kFcwWtk3rMgQMnqtc7X/+CsK1MAD/8Wspwn3RcQGWYYA8yYAzz9h2Hypiuc +ef5WVlSuwL696MPhiRZ+FGtFY+30FaiTBJtIyCJEdUo6T0uEg6xN3DaJ/wuNuaMf +JKMGBWYv+5YlLKgY+ti337VlQ1CbfVPetLExzxB9sYhRVs03yA7SmEa9rDO4Ucp0 +xMPZbJ9nNB8qnP4lHZdD72HOJJDqLdjOxZdVjiMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEANWyLwBRTrzqO/mNMX6A0DTDGjRGD+w3rMVzFmliosn+7CNbHQl1km3g8 +zvvX2+W0GBkXZm0y3i3MfdiUlW3/l54ysvIkLB0RL3RS0OxO0U9LjRzo8W32D9Gw +wO2aBE3qYGx2PJMghaJNTUIkqNjISmbvTKvR/1qjHJytJP1OCn1ssEtF3h+qvjNW +6GUDhHcKka/9o/XjWSq6nB1i1LDKtfkkoBVDk6xN7UogeJfjHbKfYVHl22kWfmTW +spXG5uIYzkOxWIuWVeOBmUyZqSnqbjDIYtOzLPJ+FxYgf+s6fX+MYjzmOsiHpEUb +jpX5qLT4Mn0DXwuBQ2cV+hH6SZphZOsVt/g6kRrWnxQY+tcKcBSVxlHv5M8JWUMf +p/rjDmUUFPkCi/Rd9mCaBlsCB71q8DBNLBIpWF0y5bARkSGXmesbpF4iT4l8sJhy +IkShtoEuThEi5BGFm8OItwglc//oyqK+fDN5R/GIvn10tAYD30t/VYapOE3C8LDy +Yo9+pMWxZIO7gr1dOe0Fi6JBIdh1XSnF72FCv9q7YQUnX1EkbDSyuOilE3qJYkOj +EwdlVXXhIYsEIX66RlVYidUgIF9UabMQbJ4wfec+bZb0KHrvEyMaLC0UJlV6d7wK +gKj/nR8McJ3zETt3mmvNwM4TlKR60F+SDScVmabETxe7u45M+/k= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/muxs-0.crt b/regr-tests/pki-data/muxs-0.crt new file mode 100644 index 0000000..db2a81d --- /dev/null +++ b/regr-tests/pki-data/muxs-0.crt @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIEIjCCAgqgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQxWhcNMjIwNTIyMjA0ODQxWjBIMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +ETAPBgNVBAMMCG11eHMtOjowMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC +AQEA1+llowMdHalG80S5GBjfDaiUWzf5oIgQP2ohGTBWd5iDq/uHX6jgcbjgKI6b +HtD5rrfA/5bfky53fEzXYTKNdNgSfkAq75ZcP4IyIG6fy+0l9XMYnIukKwipqT/l +33NM5ksKykKIIdidPOeXnLWKHdhwomcJHMOY+4j5CE19MY0V3suynmnp+KiXavQc +vrlb53xjTDcOyBJD3bzh2QrGqqKYzCNxlvSRp9WvDAqimy6O5ykEuBp+WdfqsYHq +sMU9tyto2RDDqxRKR0HmRiTJ2JX6Jjoa6GMsfWpRZhVsqx17bwj2CfTUFEaEaan6 +0bGU4EVieR2nEwjoTw82acfKVwIDAQABoxgwFjAUBgNVHREEDTALgglsb2NhbGhv +c3QwDQYJKoZIhvcNAQELBQADggIBAFDOs2CQmAdyEsPoriz5oRD0wH6NL/Z/jbUY +EId4Y46q7pXqh+EDS+xbwpi8DR/S8DOn1EFs6VtQ/8Ib0wSjyupAWtQOju/9jcIy +5xEVXEAap7NulW0hGjGMRQVFsVwt0sWP89SKIFGjnexU/DikjAVjxDzQa7VW570Q +G4Vbc1AnlinReE+TPhwwKycor3HRjc6pWZymrE7xP9y0ab89bY33PcKtZdA9Auqx +2Z9dthgQYpk+LGW0apVB5FMS9nSsOPG9JX4/opATloRAcHSHijQZPub2Zpo+JeAK +JYGX7FxfcrpNWiDL+CJAzZKnUy68+RgVubfXNna3IDU8YzdOQjcfUYh8+sVCHWwt +NtPDk0fj7gPHobgC8jinU69Pk/vhNPYTkmX81g4Rf5MRanFQiNz/PPFkyil/Lwr6 +2EUoD4Noajc9jggSoLINQP29E66Fmt15apgNcS5yWPR4/Jc/HSGQB03Bqfix15Qj +sJtwj5RcnK3JPE+525RRJMc90wrfWHCrx7eL3Pe+gzA4EdA+HHnkg7J9NbMe94VE +akmc1rimT+IL42tVAmtkvdxHufDo68k37Kimv+rOcbK5K5fGfa44wqOFflq+G1az +On8uRoAVfhYiV1dFiAPfNcqGxw4Qb1N3Izwu2qiWnhYtSvbxzF9RNckVT9GrWyoC +HcFTFCY7 +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/muxs-0.key b/regr-tests/pki-data/muxs-0.key new file mode 100644 index 0000000..489bf5d --- /dev/null +++ b/regr-tests/pki-data/muxs-0.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA1+llowMdHalG80S5GBjfDaiUWzf5oIgQP2ohGTBWd5iDq/uH +X6jgcbjgKI6bHtD5rrfA/5bfky53fEzXYTKNdNgSfkAq75ZcP4IyIG6fy+0l9XMY +nIukKwipqT/l33NM5ksKykKIIdidPOeXnLWKHdhwomcJHMOY+4j5CE19MY0V3suy +nmnp+KiXavQcvrlb53xjTDcOyBJD3bzh2QrGqqKYzCNxlvSRp9WvDAqimy6O5ykE +uBp+WdfqsYHqsMU9tyto2RDDqxRKR0HmRiTJ2JX6Jjoa6GMsfWpRZhVsqx17bwj2 +CfTUFEaEaan60bGU4EVieR2nEwjoTw82acfKVwIDAQABAoIBAQC7QLpbBCpOPS9B +cAqvMXLRn7D647LlXNvqg5qtA9UZ5/XaRE0F06rENjiCNBuoQEkrFEaX5DuGpDgQ +X3wz2eoAuhxfzjruixL6KWpb4lVIQSY4l1dy/VCl2d963+X3Q0IgQFjdTZJO+FR2 +K8y7pl5gwAP/dSjb/29AR2zjnIDFZSSZhlA2TGZnUGNV3rXOt1FFlZt3Dh7DFt3l +ohrJcAdfUQBFkkqQtBXEIjGAUx2N93cC6e5lQEvKRa8dmOs6Gf6kCAg7fvsfVvkE +5+FI7r2K/i2Ow1bN8pugWcmYWE2geCfloETH32lbsn22LqeX09ODAXvTnY3RZjjr +5lxAda1BAoGBAPbDQVzoO/iL6MkJy0ta52uJumQxdMcM6WHAMfwKX7m1pt5pL9j4 +9nxYkJ9V5OG3AIeBBnA0nLA0sSE7mSPcNjusgKrB/Q3DcVzlZKBKuO+g/7Y2eiW/ +C7a/XJv4tjnqZqkKn/fJG98bQD+FVVnCZF+gC6AugW3EfEVCpgWSP3HRAoGBAN/+ +fokSpPjuB4HkFRUtmsFwb8HYxIrDfBz/sujapSx4WJys5Wq3dJK4BlAZSZHvu4g2 +ZaqPXrRqYXx40ZhhUnGGeH6RRA3UvwD3YpLhV8V0a235D2SFtoGAqpD2RtvNtGpA +RODHPzFd5bwTEl3rqMlynLoLS59PTky5RQ8Mi5unAoGAJmqxk2BIbeKCREI1Fy84 +1iIkFZMphg+5idFdNsr6qjPgncGshFAGN8emBFhgAM/30iDBOtjGCBy78tuPdOjE +vLeXdH4tAmaKEJdZ+iaH8i6TgO+sRpIepb3XEiU/YXbfsrOHwhDaOPrKHtmINygv +bj/Bb5et6MPtQO8mX7msDPECgYEA32HgMzciyxYm6oTZ+arnYO6OpZVWPMTDa/Ad +LleOzhCe3nEWwhx+5ysbMJpnYmDgdvE45qXgXrCQ1B9xdzPnkkv2stKQOfLnIUGV +TsHoVITL9nqhvTAUWIZGlBbnh6FXwXaiukA6ZzMrPysN8Bhq1au1XVySaCghACbs +Fhv+xpUCgYA9RmUahfUbP8DIeTS7wzAmOIOHWs7ocYoAH5pGlw4LX73QUCSEedPi +gHvmCDqK48GTotJVumH74+4CDgl3yHncDlZUbyUmw/JLWM6wtk/FNq/FyouK8PK2 +88sbGUyjgxkPU6C9+T6edhSQqJZRtuiYg1/ZdaS7czK7X8BQHbvIfQ== +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/pki-data/tc-router-1.ca b/regr-tests/pki-data/tc-router-1.ca new file mode 100644 index 0000000..a57013f --- /dev/null +++ b/regr-tests/pki-data/tc-router-1.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDg0MVoXDTIyMDUyMjIwNDg0MVowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAw9uK +AnUd4May00pDyx+FLedjIFy57Abw9VTaVMAtF2DO4M4aBgQHXhKGt/9WQF0eorYU +3m0mbM6J5n8DkJB0h0YwgnHTm3BNUNf5mwaKIp7q+3iVbgiZTYRbiIyKluUGEbkG +vxsRizdDt0z8wnKd6EFbC53aFXeoxMzy0A+eTHBWr0VfBf8q0lGC0yta7HvrFv4q +UzHmzctVcfyxG5+SovFQnfoVr0Qx/GnKEThEiflrXntlcIGiyl5fFHz/7GCvtnNz +2GziFWj1JbobNJjHy9EgFYPUPSLYzvlS6QRqTv83JX/iwq7Q1IiBpHdJygm80yr3 +FSAEu7yKXaDG4bEE1PPOqmo+RvuCgRlw/rtIdEz6iLTPO9G1KtXQCc4/bletwn8k +bFXwLe0dABRF81UgRK9OCF1McMlrINEViV9q98P6ADKn4O39PrSupuqSJG5rijjN +1/7W8kFcwWtk3rMgQMnqtc7X/+CsK1MAD/8Wspwn3RcQGWYYA8yYAzz9h2Hypiuc +ef5WVlSuwL696MPhiRZ+FGtFY+30FaiTBJtIyCJEdUo6T0uEg6xN3DaJ/wuNuaMf +JKMGBWYv+5YlLKgY+ti337VlQ1CbfVPetLExzxB9sYhRVs03yA7SmEa9rDO4Ucp0 +xMPZbJ9nNB8qnP4lHZdD72HOJJDqLdjOxZdVjiMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEANWyLwBRTrzqO/mNMX6A0DTDGjRGD+w3rMVzFmliosn+7CNbHQl1km3g8 +zvvX2+W0GBkXZm0y3i3MfdiUlW3/l54ysvIkLB0RL3RS0OxO0U9LjRzo8W32D9Gw +wO2aBE3qYGx2PJMghaJNTUIkqNjISmbvTKvR/1qjHJytJP1OCn1ssEtF3h+qvjNW +6GUDhHcKka/9o/XjWSq6nB1i1LDKtfkkoBVDk6xN7UogeJfjHbKfYVHl22kWfmTW +spXG5uIYzkOxWIuWVeOBmUyZqSnqbjDIYtOzLPJ+FxYgf+s6fX+MYjzmOsiHpEUb +jpX5qLT4Mn0DXwuBQ2cV+hH6SZphZOsVt/g6kRrWnxQY+tcKcBSVxlHv5M8JWUMf +p/rjDmUUFPkCi/Rd9mCaBlsCB71q8DBNLBIpWF0y5bARkSGXmesbpF4iT4l8sJhy +IkShtoEuThEi5BGFm8OItwglc//oyqK+fDN5R/GIvn10tAYD30t/VYapOE3C8LDy +Yo9+pMWxZIO7gr1dOe0Fi6JBIdh1XSnF72FCv9q7YQUnX1EkbDSyuOilE3qJYkOj +EwdlVXXhIYsEIX66RlVYidUgIF9UabMQbJ4wfec+bZb0KHrvEyMaLC0UJlV6d7wK +gKj/nR8McJ3zETt3mmvNwM4TlKR60F+SDScVmabETxe7u45M+/k= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/tc-router-1.crt b/regr-tests/pki-data/tc-router-1.crt new file mode 100644 index 0000000..8706563 --- /dev/null +++ b/regr-tests/pki-data/tc-router-1.crt @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIECjCCAfKgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQyWhcNMjIwNTIyMjA0ODQyWjBKMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +EzARBgNVBAMMCnJvdXRlci06OjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCmyGZ2I+Y2+lhmBaE3ROLLjOn0Y5vVZNr5J4HhylXHeVI4AWG5CaRu8ndD +NUOdPoZtKZ91ul4NnH4ALf47AgDbmWSCLkloBu/A1JiVC9U051oQujF4KkViOUxT +CT6BkuE1+FpkiKngu8vGOielD3h5v/KGDuMuHakjhEBVrnC94KUUOWIjapx4JX8f +IU8KNuIZK9xJ7AgQLclKRrEWJRjQA79tZvkW1zIw9gXUE7Q8TNKYY+sC7OWyEH8t +fWgwz+8iwA9txEN2YUgRHBsQ3/27UjWDxYxT2INF7ok5gBSda5SdkCdfX9Ap5eTw +u+67Vq0FE8LHi7OGNpM7agW3RKJLAgMBAAEwDQYJKoZIhvcNAQELBQADggIBAJyi +PGApEGr3CcnKLCgCpZeCnew6cilJhl9zJKbZ5XNuqNOoN2YhnM+hW7BnAWrOaApm +387S9dNEcfJtk/w+aK+20G4t9EDNmjEoKrKit4h8tdpCaiBsr3NnGxlhoM8wx6DT +i0GP/vKCMyTeaI9JU8vxd028tI+jUiwrrrY8iSQ9qUTAzPY7ksoaSVuzyLROq+kl +3YiozLSTm7bN+GSDz2jkyCmsuZIU7MBE2NQpQWRavhtCV2cIQEa2blVJlqid16zR +JulbnyOxKqJD0DYOvEtEEzPUUgPCrE9o59PFnzjY+j1xhlPIXPCbdknnChv6RU3v +5vP5egUGxls5rNRsMH7ITnCXD690wRNUu5OXoYIZMZigvjG/af5H/ULGuFyQLzjs +v6dc+PHKwi3NhjsxVhMpK4TfOXQbjitraqMWaOubxHCQdcB9dQhAOA/4hiCheLKA +6chVnMZ9Qh2AAjzmpP/4ktb4YODHbhqmHD+MN803DCRWlU3Ks/fDW+LufHA7Ub0t +IjiuC2EYbJaWITgC69qzMB0UqRU1NKWjHFAiNZWB9cGmgfWZMCea1JuH1iavtgyD +VI0gSHg13JVSmANsZOwdBOUkIzgd54kHr+h+jiuLn56acsvtJRAcL9sjgnPOKTlx +0MHWlxsN8GUm4+NFPhUuiAKVgjb2rOhfYTU9WQN8 +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/tc-router-1.key b/regr-tests/pki-data/tc-router-1.key new file mode 100644 index 0000000..2d7a465 --- /dev/null +++ b/regr-tests/pki-data/tc-router-1.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEApshmdiPmNvpYZgWhN0Tiy4zp9GOb1WTa+SeB4cpVx3lSOAFh +uQmkbvJ3QzVDnT6GbSmfdbpeDZx+AC3+OwIA25lkgi5JaAbvwNSYlQvVNOdaELox +eCpFYjlMUwk+gZLhNfhaZIip4LvLxjonpQ94eb/yhg7jLh2pI4RAVa5wveClFDli +I2qceCV/HyFPCjbiGSvcSewIEC3JSkaxFiUY0AO/bWb5FtcyMPYF1BO0PEzSmGPr +AuzlshB/LX1oMM/vIsAPbcRDdmFIERwbEN/9u1I1g8WMU9iDRe6JOYAUnWuUnZAn +X1/QKeXk8Lvuu1atBRPCx4uzhjaTO2oFt0SiSwIDAQABAoIBAAilv1pExjz3gfnY +NOGuuqufJMo9F+laj1f3ym4wlX4ANlkdCToU2+e8vp5HdrgCc+nZDKGIBjRids3/ +lHzuv6ijLWjqiXfRVEEFRNwFfwp9LFhNrx7x4iMToXd0tT72pKKtu9IWm+hBFHG0 +tjWCtdZqM2LsBq9vbkOfKc7HeqT9mV8WbFpJtFh5IQ2f0Owf09peBNIBriWZwwhd +5GFSMRpIH/zkviNKe2xwkM/4L4KMyV37yL1NpGwq+iZZZktPYKk6BNFWtCKkp8A5 +OjQezuGnfmy3Pt4eWX33nN4JF+7o29Q/CEr1Ev6Gbtd6ae4HbNStLm8jZITSP5qr +qXS7QWECgYEA17U++8uqqcCQNVsEEJOwrba1Yeqojrh58xnjqOO2CC1oHyU0gE9v +ZHxB5GYy1cZ+NZ+dzAgmzzeCLjec+RBwZAz6gpNm2yPCf4rZhjbZbrlCqx6ghVuO +2Hwakznq59HDpCnhZPxJbtsanOO+MdTl9mUksTTiMINpcYWkZs9kTbMCgYEAxe+k +tPFJBC6oTyI4xtR9d5JjQKk1TH68E4E7C99eKEF6whuKsNQEAGoekJai+uH4gfFN +048pZ46kI/V1Z7CYgFdqYyn1VFT4tSvuUiak2DPBe+oRBMHzz4eY+8AmlJyVzWlf +KUzVvk48CRMTByaGzFCGt3GtTfThl3hZ4JI8/QkCgYA8bTqaoOBLM3VybO/DkQwC +bdd7+ZeEe6s17b+31SpuOgIcD3kYpKgI10JCMFr3ReafMPqsaHAuxlcCiXPA1dkW +PgiDQbWjl+3pesUa8wyQFvfVJfxDv3VRsdpj+eqTTFDpEQ5iEsajdl+LKcVjAkf1 +cToJJk5i1r1YHt8CKgDoPwKBgQCs7DLh3VYj8Dscf1JI6oT+fIZ3jBxDSwk2pRUX +xzn0Q1hi0jr1RxSD5DH1sZSLR/WaWFzcsdrDXQurWpsKTm682SHZpmNtHJr3dHzN +inNDatvjTNc3Z9Z//P+7GODbvnzlKuR3KWgmzSSH7QEXoyHqx4MaKpb0Xzbi5MLo +ffoIOQKBgCNkYLf9d5lIitjvet/szVw4ondlQheUAL8hHXB8160Ev9a5vZmpFYPx +D+QhhJG5ILFvy3nQVn3FthiBWYGQlveLASZSHjK7fRbNNqhosW6UPePoHbD7REnr +VvH79ZYxCf8OTpteX/AdtW/hvI0gXsG2RoJ7vBHvGcU1TjdgYdSl +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/pki-data/tc-router-2.ca b/regr-tests/pki-data/tc-router-2.ca new file mode 100644 index 0000000..8344ba6 --- /dev/null +++ b/regr-tests/pki-data/tc-router-2.ca @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFAjCCAuoCAQEwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMxEDAOBgNV +BAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYDVQQDDAdSb290 +IENBMB4XDTIwMDUyMjIwNDg0MloXDTIyMDUyMjIwNDg0MlowRzELMAkGA1UEBhMC +VVMxEDAOBgNVBAsMB1NlbXRlY2gxFDASBgNVBAoMC3NlbXRlY2guY29tMRAwDgYD +VQQDDAdSb290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA4ZUC +uFvDZIFEKmH2A3zqFxGEJj9Jp6CsEyOpxPdu6qUu66SZSPTZy+kI2LYhSdxlC+Q0 +nziv7+z3h+otJ9/Z/li61n3M6douPW4vzWG/9iNAGbt/uGGlpdQjFqa2Zm5G149M +8Jg8EbHNgdEiW/5BleHYsNiyow0ONOTsYAOYBeHYCa+Ya3XnusDsyOq6cP3gEFEx +33pMNGzipvKDZQ+KZi+cNMABMzenRs2JnT3LPN0B3elvrKNfFpKOJ25UEMqu4+me +ZJfO4W6LYVxKXKdEH3X/LbokfTxr9fq4vqmeuWHF+ou29JsexuCJ/kC+7BliHx7Z +3ggvo0KCiE8gr6go1Rat1nX19UXxRfebQTdXidEWdzCQ6uUK4YBCtK5cNWe72E01 +lW/ZlPJPCAcpEnDXD8OV3SjE4PsrXvM+GaxEIo2BP6dXLJWOH59K1Zs42UrW50Nf +d0nLR62MdyVYely4vWZChQJKMHiDw3PenAebvSgNIJ7h3VqTp6NRUCVSvFY6NUHf +GQWUhfqfG7AyLJyBL/PjzPkctJIeaCKXU5aG+wohqmUIqQc3ThezQoIufFf8NVLh +OLz+7I0trgDPOehMczpf2s3I7TyWbwIxMgt0V5mOXOTFRmyLN9ncXDBvk9aZPvni +v9yuaqOBOHZY4LL0J+tZPfqy6mN+I7Qim6Z7BJMCAwEAATANBgkqhkiG9w0BAQsF +AAOCAgEASFMdOUwAO/OhNeLVOOJXWKQESN9eiwf460c9MmQdVzL3iWxZnWu2cuHa +Twb0ihlMHY29WO22tBtwdblBvYeYvM0qNaakWgXcJ/JvKNqt2KgjCVxDU29hnScw +h8lnEc6mQEONc6ZrYx3w56DaSiVV0TsZbREFTlMUx0MZYFQS5abVixJCbYNoeRmU +tcr/I0toPjEr98EhvwOYgyUh64fNozQoWTL8DmyAkesIzY2RxYzrKWE+fWDFySLy +uUQ5iYiJe+2Yapu2JJ4kCxMhRYozlSn5LOr/jZKXh+8VSQn5qY89YIYRSEQzYN9a +4mIgDWVjE+ankvENbgScBox3HJsMA7GurGb40RdEqsG80fuSYLwPOzMFXVxMfS// +AZnAocN+Y5QR6L73ESiQkkobvpWCaEzokpDc8eo+5CZMvs+MuDt93voyG5XADuRA +4DmKHLfVwxa/bEUt6W14YuC6rOuXzdHsdDvWXNNTNu5nsICfOWySdkF2qmq0wthV +qcZMGllqUK3b5JuDu0iWi8CeHqb2GQH28Bn3y0exezvDPmMoy+l+CRJvW2a+cgZd +rZgl2VRcw/38w+3gAxiSB0pzQqUp4YT+WWsKvMVws7y2d8fxUsWD3akQd8ZMeUE8 +GRRqT/IPfOLCy1G6PoB0a5mdMEk0nfhjZQUDxVwdmkvCcTYhxG8= +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/tc-router-2.crt b/regr-tests/pki-data/tc-router-2.crt new file mode 100644 index 0000000..85032f8 --- /dev/null +++ b/regr-tests/pki-data/tc-router-2.crt @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIECjCCAfKgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMQswCQYDVQQGEwJVUzEQ +MA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20xEDAOBgNVBAMM +B1Jvb3QgQ0EwHhcNMjAwNTIyMjA0ODQyWhcNMjIwNTIyMjA0ODQyWjBKMQswCQYD +VQQGEwJVUzEQMA4GA1UECwwHU2VtdGVjaDEUMBIGA1UECgwLc2VtdGVjaC5jb20x +EzARBgNVBAMMCnJvdXRlci06OjIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQC74duk/4n3N4BUv/eo3HZlXkwfWai5SIb8rQxGum3F7YP73eOabjqCxDBd +/gBWMcFPYHmGC5TfPtGaHgdqJYIMLenTUsRSmqIONzyMC9DwueGza/o2B4g0Xhff +e5Ctp2XyZLfiKMn/r6mErjrQhnbNfT1euXrcyCgjRgJDp4xlnOMDZdT6O48yQLmK +XKa/QeW9MT+/ZeD+YHbn1dq7VoSoL86f3+PdG4UNJnnwydmf1nXndHarH7FguSAf +p6KBc75Hu4ytDSdHCJENaH+tcPR0wi3Kvva5MRp0BY2eNMv6QFtCJ6myNxZR4I8F +C42ozSjyb2oA4MRsp0rFbRmj8a3RAgMBAAEwDQYJKoZIhvcNAQELBQADggIBALLY +OidUmGkamyXfWaTHTdo9NU73NYjr9xQWoKee2+oe+2HVb5ltOoSsQNt+9kmenX4n +jYmomz6lTNar97/49nmU/7HiK51NspWfqBOBHMst2z9EeEFJTswIGU3wlsP0ZARe +1LeXioCFje3COveY6CaOwcVpqFTKeJiYJcCg5J2yKyv+vF6mlIQGggJWgvw1ATZG +JblS0lXVNL6p8hw3UHzoKRubNmHVz3OM0IM4hWWM87oQlOGE7lXUAXZY+0x7XfT6 +0IQGZVSjlyNLeIqt5NTJcCS6e/kZb2eHSWu0SyQEN8fIYFv7wZ+QwWVnyfMZRm+D +8O3Uhpp+HjxwcS1QodAKpTbjGUwFQQJY9NEPdCIuwEWmbDOO0vCnhW4MZiJwuNN4 +w5QAK4kb/ATegSP/PM5KCosPyo0io5unXCnT6DKj9r47/lAoiQk6YcUGoILNBKXi +Hkx0xHl0uRa+UIbiLjiOUhySLGuoU5v9TTRJ8twevG9ExlAyyInvtyj0CNR9g820 +pu5Bt8ONrINQA4AYgw6DaD5wpNat00wgswanx606ggHyS8UmfwIqI1MI8Dpvwuwn +XbWslbxDU2+fmbumoZQX23s9m6Tu025n06yNVUunMxBha7PJdc2YT/vLQ5yXhNDw +3u4hFbTYd+IRfNR7ohV5FD/zFVfEke5iBErTThod +-----END CERTIFICATE----- diff --git a/regr-tests/pki-data/tc-router-2.key b/regr-tests/pki-data/tc-router-2.key new file mode 100644 index 0000000..21cabbc --- /dev/null +++ b/regr-tests/pki-data/tc-router-2.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAu+HbpP+J9zeAVL/3qNx2ZV5MH1mouUiG/K0MRrptxe2D+93j +mm46gsQwXf4AVjHBT2B5hguU3z7Rmh4HaiWCDC3p01LEUpqiDjc8jAvQ8Lnhs2v6 +NgeINF4X33uQradl8mS34ijJ/6+phK460IZ2zX09Xrl63MgoI0YCQ6eMZZzjA2XU ++juPMkC5ilymv0HlvTE/v2Xg/mB259Xau1aEqC/On9/j3RuFDSZ58MnZn9Z153R2 +qx+xYLkgH6eigXO+R7uMrQ0nRwiRDWh/rXD0dMItyr72uTEadAWNnjTL+kBbQiep +sjcWUeCPBQuNqM0o8m9qAODEbKdKxW0Zo/Gt0QIDAQABAoIBAQCWbKuFvE7Czv4B +XL01xmVInaoGw6sxxV7GOOqGSkcPXC363tmW0EAqaFdtOasdV7K1EcHaT7V+0/XP +FdHL64HmrG/0kOS8Wi/7f8ALRH6h7cFF/OKUlY04mEk21eCtGESoQHl1KkEoZIUt +xK00PSQrO+WBzLEQyXRRYYD4l9Hxm7zkdmwDkSxAMDCrRu2Mm2o82f9aGGay/27G +qphSsl/MoSu3m4zIvs2Y7Moy8CoRQkT9Tj0CH3h8O12bhr92SdmAhIvDkV1Et0at +/llM9YvHVj/EI2w4WM6HmpOTamcpdpa6G64/HD4Bs0V27RC4aXcyr4efyOZOuZvy +ZmeONtLBAoGBAPEyCWNbkC5UmoAhGUIHjOuGsPJw7+e7W40ICUgFkQFbypVq6VjY +gkFO42zrRitYaTl8nJ56zvwwZ3piZjTXphLa/76lYmV9xcxxYEW7frdCI5behJaU +RggtijqKn43u27S6/nc9NCGam9EiMTP/GXC/Ighqn7t4BWllzEWPb4/ZAoGBAMdq +GRQnsSkm7ZLjPgNLHOX+VZTa2hqi5L5JKCZae/OWANf1B2IO62djwbdERktrxJOc +KGXyp1CVK8188zwKO6kFxPYKh8Gz7XuwOIffwO3vmR1sB44q+QpNHJNgGADg6fcR +8Zc4woKZWs7iGpeeFuFBZ1DbDvPo8CToM39p7kq5AoGBAMtto2Nst7eL3d+RiwcY +7S89JALnZEBz0mypyYI4R6v4qm3JhVRND9dbXQ/hhAZNBDrbMhGsjOVBQhWD5qZM ++CJRGYDHZq0pHmonecZ2tBKGsxOtS/Dg0AxXtI1Zm+cO/bl6OeOB+HUbPK5wA0XS +s7dXTbIBlAV+3jmeBWLp7nNJAoGBAIWwwsl5ZtOBDqt4f92zYNdssLGQG8LZzGMq +Jqm35fvDaCNgWafK+tUg0wFr23i68lpHyem3SabDq08jYuqwrZi+jnKpUqRxXVic +Jvoo725VQKCyCUqt0rKuSecf+Fe2cgS7We2ZFwZ5i6DBgzR8vzgbIgnaIucxFraX +mdblDOW5AoGAULiz9vvXQoCmsofwMyg9ojgqbqN6QW0w1QcanglyCI9R7+Mqd/qG +LmlhMQ+stNSrO5gxEi/6get6B9qbIbt3zwz/sj+7aNB0Z5V9nNifIe7bIUPTq461 +fZA/lKszeh2QwLLbhvkv8IFGgNZo2Pg812ADhqQqwMv1xeYFpXQ6i/g= +-----END RSA PRIVATE KEY----- diff --git a/regr-tests/run-regression-tests b/regr-tests/run-regression-tests new file mode 100755 index 0000000..9a56782 --- /dev/null +++ b/regr-tests/run-regression-tests @@ -0,0 +1,177 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +R=$(echo -e "\033[31m") +G=$(echo -e "\033[32m") +B=$(echo -e "\033[34m") +X=$(echo -e "\033[0m") + +cd $(dirname $0) + +mkdir -p t.log +variants="testsim testms" +tests="$(echo test[0-9]*-*)" + +verbose=0 +nohw=0 +forcebuild=0 +cleanrun=0 +travis=0 + +export IGNORE="livecups" + +while [ "$1" != "" ]; do + case $1 in + -v | --verbose ) verbose=1 ;; + -n | --nohw ) export IGNORE="-hw$|$IGNORE";; + -b | --build ) forcebuild=1 ;; + -c | --clean ) cleanrun=1 ;; + -t | --travis ) travis=1 ;; + esac + shift +done + +set -e +btarget="" +[[ $forcebuild -eq 1 ]] && btarget="deps s-clean s-all" +# Make sure variants are up-to-date +for variant in $variants; do + [[ $travis -eq 1 ]] && echo "travis_fold:start:build.$variant" + echo "Build $variant" + variant=$variant make -C .. $btarget + [[ $travis -eq 1 ]] && echo "travis_fold:end:build.$variant" +done +set +e + + +onego=1 +fails=0 +allok=1 +tdir=t.log + +# If previous has all tests ok then remove directory +# and start over with a new test. +for testdir in $tests; do + rvar=$variants + [[ $testdir =~ "-hw" ]] && rvar="hardware" + for variant in $rvar; do + test="${testdir}__$variant" + tfile="$tdir/ok-$test.log" + if [ ! -f "$tfile" ]; then + allok=0 + break + fi + done +done +if [[ $allok -eq 1 ]] || [[ cleanrun -eq 1 ]]; then + echo "Removing logs of successful regression tests." + rm -f $tdir/* +fi + +for testdir in $tests; do + rvar=$variants + [[ $testdir =~ "-hw" ]] && rvar="hardware" + for variant in $rvar; do + test="${testdir}__$variant" + tfile="$tdir/fail-$test.log" + tfileOK="$tdir/ok-$test.log" + tfileOFF="$tdir/off-$test.log" + if [ -f "$tfileOK" ]; then + onego=0 + echo "${B}Test already passed in previous run: $test${X}" + continue + fi + beg=$(date +%s) + f="tlog/$test.log" + if [[ $travis -eq 1 ]]; then + echo "travis_fold:start:$test" + echo "Running $test" + else + echo -ne "Running $test...\r" + fi + set -o pipefail + if [[ "$IGNORE" != "" ]] && [[ "$testdir" =~ $IGNORE ]]; then + echo "--- Test N/A ---" > "$tfile" + elif [[ $verbose -eq 1 ]]; then + TEST_VARIANT=$variant make -C $testdir | tee "$tfile" 2>&1 + else + TEST_VARIANT=$variant make -C $testdir >"$tfile" 2>&1 + fi + xcode=$? + set +o pipefail + [[ $travis -eq 1 ]] && echo "travis_fold:end:$test" + end=$(date +%s) + mins=$(printf "[%3dsecs]" $(($end-$beg))) + if grep -- "--- Test N/A ---" "$tfile" >/dev/null 2>&1; then + mv "$tfile" "$tfileOFF" + echo "${B}$mins Test n/a: $test${X}" + else + if [ $xcode -eq 0 ]; then + mv "$tfile" "$tfileOK" + echo "${G}$mins Test completed: $test${X}" + else + echo "${R}$mins Test FAILED: $test - details see '$tfile'.${X}" + ((fails++)) + fi + fi + done +done + +if [[ $verbose -eq 1 ]]; then + echo "__ Summary _________________________________" + for testdir in $tests; do + rvar=$variants + [[ $testdir =~ "-hw" ]] && rvar="hardware" + for variant in $rvar; do + test="${testdir}__$variant" + tfileOK="$tdir/ok-$test.log" + tfileOFF="$tdir/off-$test.log" + printf ' Test %-26s ' $test + if [ -f "$tfileOK" ]; then + echo "[${G}PASSED${X}]" + elif [ -f "$tfileOFF" ]; then + echo "[${B}N/A${X}]" + else + echo "[${R}FAILED${X}]" + fi + done + done +fi + +if [[ $fails -ne 0 ]]; then + echo "${R}$fails tests failed - fix the problems and rerun this script.${X}" + echo "Check the files '$tdir/fail-*.log'." + exit 2 +fi +if [[ $onego -eq 0 ]]; then + echo "${G}All tests completed - ${R}however not in a single run.${X}" + echo "Your fixes might have broken earlier tests." + echo "For maximum safety remove $tdir directory and rerun this script...or dont." + exit 1 +fi +echo "${G}All tests completed in a single run.${X}" diff --git a/regr-tests/test1-selftests/.gitignore b/regr-tests/test1-selftests/.gitignore new file mode 100644 index 0000000..e190918 --- /dev/null +++ b/regr-tests/test1-selftests/.gitignore @@ -0,0 +1,2 @@ +*.info +station.flash \ No newline at end of file diff --git a/regr-tests/test1-selftests/makefile b/regr-tests/test1-selftests/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test1-selftests/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test1-selftests/station.conf b/regr-tests/test1-selftests/station.conf new file mode 100644 index 0000000..7ea91cd --- /dev/null +++ b/regr-tests/test1-selftests/station.conf @@ -0,0 +1,9 @@ +{ + "station_conf": { + /* Test s2conf.c */ + "GPS_REOPEN_FIFO_INTV": "abc", /* fail */ + "GPS_REOPEN_FIFO_INTV": 600, + "GPS_REOPEN_FIFO_INTV": 500, /* replace previous value */ + "GPS_XXX": 500 /* not a parameter */ + } +} diff --git a/regr-tests/test1-selftests/tc.uri b/regr-tests/test1-selftests/tc.uri new file mode 100644 index 0000000..22c178c --- /dev/null +++ b/regr-tests/test1-selftests/tc.uri @@ -0,0 +1 @@ +ws://localhost:6038 \ No newline at end of file diff --git a/regr-tests/test1-selftests/test.sh b/regr-tests/test1-selftests/test.sh new file mode 100755 index 0000000..1aee44a --- /dev/null +++ b/regr-tests/test1-selftests/test.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh +STATION_SELFTESTS=1 GPS_REPORT_DELAY=10 station -p +collect_gcda diff --git a/regr-tests/test2-fs/.gitignore b/regr-tests/test2-fs/.gitignore new file mode 100644 index 0000000..008234f --- /dev/null +++ b/regr-tests/test2-fs/.gitignore @@ -0,0 +1,2 @@ +station.flash +*.info diff --git a/regr-tests/test2-fs/data.txt b/regr-tests/test2-fs/data.txt new file mode 100644 index 0000000..30c05e5 --- /dev/null +++ b/regr-tests/test2-fs/data.txt @@ -0,0 +1,22 @@ +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF +0123456789ABCDEF diff --git a/regr-tests/test2-fs/makefile b/regr-tests/test2-fs/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test2-fs/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test2-fs/test.sh b/regr-tests/test2-fs/test.sh new file mode 100755 index 0000000..b7e8515 --- /dev/null +++ b/regr-tests/test2-fs/test.sh @@ -0,0 +1,155 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +function fs () { + station --fscd /s2 --fscmd "$*" +} + +function fs_native () { + station --fscd . --fscmd "$*" +} + + +rm -f station.flash + +fs ? +fs info +[[ ! $(fs fsck) ]] +fs dump + +fs write cups.uri < data.txt +fs write sig-0.key < data.txt +fs write cups-temp.cpy < /dev/null +fs write cups-bak.uri < data.txt +fs write cups-bak.done < /dev/null +fs unlink cups-temp.cpy + +fs write tc-temp.uri < data.txt +fs write cups-temp.trust < data.txt +fs write cups-temp.crt < data.txt +fs write cups-temp.key < data.txt +fs write tc-temp.trust < data.txt +fs write tc-temp.crt < data.txt +fs write tc-temp.key < data.txt + +fs write cups-temp.upd < /dev/null +fs rename cups-temp.trust cups.trust +fs rename cups-temp.crt cups.crt +fs rename cups-temp.key cups.key +fs unlink cups-temp.upd + +fs write tc-temp.upd < /dev/null +fs rename tc-temp.trust tc.trust +fs rename tc-temp.crt tc.crt +fs rename tc-temp.key tc.key +fs rename tc-temp.uri tc.uri +fs unlink tc-temp.upd + +fs write tc-temp.cpy < /dev/null +fs write tc-temp.trust < data.txt +fs write tc-temp.crt < data.txt +fs write tc-temp.key < data.txt +fs write tc-temp.uri < data.txt +fs write tc-temp.done < /dev/null +fs unlink tc-temp.cpy + +fs dump +fs gc +fs dump + +for f in cups.trust cups.crt cups.key tc.trust tc.crt tc.key; do + fs read $f 2>/dev/null | cmp - data.txt +done + +fs access tc-temp.key +fs access tc-temp.cpy | grep "File tc-temp.cpy does not exist" && echo "Failed as expected" +fs stat tc-temp.key +fs stat tc-temp.cpy | grep "Failed" && echo "Failed as expected" + +fs foocmd >/dev/null 2>&1 | grep "Unknown command" && echo "Failed as expected" +fs unlink >/dev/null 2>&1 | grep "usage" && echo "Failed as expected" +fs rename >/dev/null 2>&1 | grep "usage" && echo "Failed as expected" +fs access >/dev/null 2>&1 | grep "usage" && echo "Failed as expected" +fs stat >/dev/null 2>&1 | grep "usage" && echo "Failed as expected" +fs read >/dev/null 2>&1 | grep "usage" && echo "Failed as expected" +fs write >/dev/null 2>&1 | grep "usage" && echo "Failed as expected" + +fs write somedata.txt < data.txt +fs info | grep "active: section B" && echo "Auto-GC due to dirt at the end" +fs read somedata.txt 2>/dev/null | cmp - data.txt + +VERYLONGNAME=verylooooooooooooooooooooooooooooooooooooooooooooooooooooongnameverylooooooooooooooooooooooooooooooooooooooooooooooooooooongnameverylooooooooooooooooooooooooooooooooooooooooooooooooooooongnameverylooooooooooooooooooooooooooooooooooooooooooooooooooooongname + +fs unlink $VERYLONGNAME 2>&1 | grep "File name too long" +fs rename $VERYLONGNAME $VERYLONGNAME 2>&1 | grep "File name too long" +fs rename cups.uri $VERYLONGNAME 2>&1 | grep "File name too long" +fs write $VERYLONGNAME < data.txt 2>&1 | grep "File name too long" + +fs read " " || echo "Expected failure" + +fs_native read data.txt +fs_native write /tmp/data2.txt < data.txt +fs_native stat /tmp/data2.txt +fs_native access /tmp/data2.txt +fs_native rename /tmp/data2.txt /tmp/data3.txt +fs_native read /tmp/data3.txt +fs_native unlink /tmp/data3.txt +fs_native access /tmp/data3.txt | grep "File /tmp/data3.txt does not exist" && echo "Failed as expected" + +fs gc # move back to section A +fs info | grep "active: section A" + +echo "==== TEST: Dirt at the end ======" +OFFSET=$(fs info 2>/dev/null | sed -n 's/fbase=\([^ ]\+\).*/\1/p') +USED=$(fs info 2>/dev/null | sed -n 's/used=\([^ ]\+\) bytes$/\1/p') +printf '\xee\xdd\xcc\xbb' | dd of=station.flash bs=1 seek=$(($OFFSET + $USED)) count=4 conv=notrunc + +fs dump + +fs gc # move to section A +fs info | grep "active: section A" + +echo " ==== TEST: Corrupt magic ===========" +fs gc # Move to section B +# Mess with section A magic +printf '\x10\x00\xb5\xa4' | dd of=station.flash bs=1 seek=$(($OFFSET)) count=4 conv=notrunc +fs info 2>&1 | grep "FSCK discovered strange magics" + +echo " ==== TEST: Corrupt data ===========" +printf 'SCHMUTZZ' | dd of=station.flash bs=1 seek=$(($OFFSET+64)) count=8 conv=notrunc +fs info + +echo "TEST: Random flash init" +dd if=/dev/urandom of=station.flash bs=1M count=4 conv=notrunc +fs info 2>&1 | grep "initializing pristine flash" + +fs erase + +collect_gcda diff --git a/regr-tests/test2-gps/.gitignore b/regr-tests/test2-gps/.gitignore new file mode 100644 index 0000000..40c85c5 --- /dev/null +++ b/regr-tests/test2-gps/.gitignore @@ -0,0 +1,6 @@ +*.fifo +*.info +tc-bak.* +spidev +station.lastpos +station.pid diff --git a/regr-tests/test2-gps/makefile b/regr-tests/test2-gps/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test2-gps/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test2-gps/slave-0.conf b/regr-tests/test2-gps/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test2-gps/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test2-gps/station.conf b/regr-tests/test2-gps/station.conf new file mode 100644 index 0000000..1979f35 --- /dev/null +++ b/regr-tests/test2-gps/station.conf @@ -0,0 +1,33 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "f::4002", + "gps": "~/gps.fifo", + "device": "spidev", + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* Send GPS report not fast than every 1sec */ + "GPS_REPORT_DELAY": 1 + } +} + diff --git a/regr-tests/test2-gps/tc.uri b/regr-tests/test2-gps/tc.uri new file mode 100644 index 0000000..22c178c --- /dev/null +++ b/regr-tests/test2-gps/tc.uri @@ -0,0 +1 @@ +ws://localhost:6038 \ No newline at end of file diff --git a/regr-tests/test2-gps/test.py b/regr-tests/test2-gps/test.py new file mode 100644 index 0000000..b49dddf --- /dev/null +++ b/regr-tests/test2-gps/test.py @@ -0,0 +1,119 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test2-gps') + +import tcutils as tu +import simutils as su +import testutils as tstu + +station = None +infos = None +muxs = None +sim = None +timeout = None + +def nmea_cksum(b:bytes) -> bytes: + v = 0 + for bi in b: + v ^= bi + return b'$' + b + b'*%02X\r\n' % (v&0xFF) + + +class TestMuxs(tu.Muxs): + cmdcnt = 0 + gpscnt = 0 + gpsmove = 0 + gpsnofix = 0 + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_alarm(self, ws, msg): + text = msg['text'] + if 'GPS' in text: + self.gpscnt += 1 + if text.startswith('GPS move'): + self.gpsmove += 1 + if text.startswith('No GPS fix'): + self.gpsnofix += 1 + + if text.startswith('CMD'): + self.cmdcnt += 1 + logger.debug('ALARM(%d/%d): %s' % (self.gpscnt, self.cmdcnt, text)) + + +async def timeout(): + await asyncio.sleep(30) + await muxs.testDone(2) + + +async def test_start(): + global station, infos, muxs, sim, timeout + infos = tu.Infos() + muxs = TestMuxs() + sim = su.LgwSimServer() + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + + asyncio.ensure_future(timeout()) + with open("./gps.fifo", "wb", 0) as f: + with open("./cmd.fifo", "wb", 0) as c: + await asyncio.sleep(1.0) + for i in range(20): + logger.debug('Writing GPGGA...') + fixquality = (i&4)*2 # 4x 0 then 4x 2 + lat = b'00849.8387' if i&1 else b'00848.8387' + f.write(nmea_cksum(b'GPGGA,165848.000,4714.7671,N,%s,E,%d,9,1.01,480.0,M,48.0,M,0000,0000' % (lat, fixquality))) + logger.debug('Writing cmd.fifo...') + c.write(b'{"msgtype":"alarm","text":"CMD test no.%d"}\n' % (i,)) + await asyncio.sleep(1) + notok = 1 + logger.debug('gpscnt=%d gpsmove=%d gpsnofix=%d cmdcnt=%d' % (muxs.gpscnt, muxs.gpsmove, muxs.gpsnofix, muxs.cmdcnt)) + if muxs.gpscnt >= 1 and muxs.gpsmove >= 1 and muxs.gpsnofix >= 1 and muxs.cmdcnt >= 15: + notok = 0 + await muxs.testDone(notok) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test2-gps/test.sh b/regr-tests/test2-gps/test.sh new file mode 100755 index 0000000..a06364a --- /dev/null +++ b/regr-tests/test2-gps/test.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +[[ -p gps.fifo ]] || mkfifo gps.fifo +[[ -p cmd.fifo ]] || mkfifo cmd.fifo + +# Trigger move alarm +python test.py + +collect_gcda \ No newline at end of file diff --git a/regr-tests/test2-pps/.gitignore b/regr-tests/test2-pps/.gitignore new file mode 100644 index 0000000..40c85c5 --- /dev/null +++ b/regr-tests/test2-pps/.gitignore @@ -0,0 +1,6 @@ +*.fifo +*.info +tc-bak.* +spidev +station.lastpos +station.pid diff --git a/regr-tests/test2-pps/makefile b/regr-tests/test2-pps/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test2-pps/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test2-pps/slave-0.conf b/regr-tests/test2-pps/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test2-pps/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test2-pps/station.conf b/regr-tests/test2-pps/station.conf new file mode 100644 index 0000000..6f51d96 --- /dev/null +++ b/regr-tests/test2-pps/station.conf @@ -0,0 +1,33 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "pps": true, + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "f::4002", + "gps": "~/gps.fifo", + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* Send GPS report not fast than every 1sec */ + "GPS_REPORT_DELAY": 1 + } +} + diff --git a/regr-tests/test2-pps/tc.uri b/regr-tests/test2-pps/tc.uri new file mode 100644 index 0000000..22c178c --- /dev/null +++ b/regr-tests/test2-pps/tc.uri @@ -0,0 +1 @@ +ws://localhost:6038 \ No newline at end of file diff --git a/regr-tests/test2-pps/test.py b/regr-tests/test2-pps/test.py new file mode 100644 index 0000000..ffba6f4 --- /dev/null +++ b/regr-tests/test2-pps/test.py @@ -0,0 +1,124 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test2-pps') + +import tcutils as tu +import simutils as su +import testutils as tstu + +station = None +infos = None +muxs = None +sim = None +timeout = None + +def nmea_cksum(b:bytes) -> bytes: + v = 0 + for bi in b: + v ^= bi + return b'$' + b + b'*%02X\r\n' % (v&0xFF) + + +class TestMuxs(tu.Muxs): + tscnt = 0 + first = None + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_timesync(self, ws, msg): + t = int(time.time()*1e6) + if not self.first: + self.first = t + if t < self.first + 3e6: + await asyncio.sleep(2.01) + else: + if self.tscnt >= 3: + print('FAILED to fix after %d tries in 2nd volley of timesync messages' % (self.tscnt,)) + await self.testDone(0) + self.tscnt += 1 + msg['servertime'] = t + await ws.send(json.dumps(msg)) + + async def handle_alarm(self, ws, msg): + print('ALARM: %r' % (msg,)) + + +async def timeout(): + await asyncio.sleep(20) + await muxs.testDone(2) + + +async def test_start(): + global station, infos, muxs, sim, timeout + infos = tu.Infos() + muxs = TestMuxs() + sim = su.LgwSimServer() + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + + asyncio.ensure_future(timeout()) + with open("./gps.fifo", "wb", 0) as f: + # Send an NMEA sentence every 1sec + # These are not used to sync time in any way - they are only indicative of + # having a fix and being able to produce a PPS signal + with open("./cmd.fifo", "wb", 0) as c: + await asyncio.sleep(1.0) + for i in range(30): + print('Writing GPGGA...') + fixquality = (i&4)*2 # 4x 0 then 4x 2 + f.write(nmea_cksum(b'GPGGA,165848.000,4714.7671,N,00849.8387,E,%d,9,1.01,480.0,M,48.0,M,0000,0000' % fixquality)) + print('Writing cmd.fifo...') + c.write(b'{"msgtype":"alarm","text":"CMD test no.%d"}\n' % (i,)) + await asyncio.sleep(1) + if muxs.tscnt > 0: + await muxs.testDone(0) + + print('No 2nd volley of timesync messages') + await muxs.testDone(1) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test2-pps/test.sh b/regr-tests/test2-pps/test.sh new file mode 100755 index 0000000..e21e642 --- /dev/null +++ b/regr-tests/test2-pps/test.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +[[ -p gps.fifo ]] || mkfifo gps.fifo +[[ -p cmd.fifo ]] || mkfifo cmd.fifo + +# Trigger move alarm +python test.py + +collect_gcda diff --git a/regr-tests/test3-updn-tls/.gitignore b/regr-tests/test3-updn-tls/.gitignore new file mode 100644 index 0000000..992cc2e --- /dev/null +++ b/regr-tests/test3-updn-tls/.gitignore @@ -0,0 +1,10 @@ +tc.uri +tc.key +tc.crt +tc.trust +tc-bak.* +*.info +station.log +station.pid +radioinit.args +spidev diff --git a/regr-tests/test3-updn-tls/infos-0.crt b/regr-tests/test3-updn-tls/infos-0.crt new file mode 120000 index 0000000..99b9aba --- /dev/null +++ b/regr-tests/test3-updn-tls/infos-0.crt @@ -0,0 +1 @@ +../pki-data/infos-0.crt \ No newline at end of file diff --git a/regr-tests/test3-updn-tls/infos-0.key b/regr-tests/test3-updn-tls/infos-0.key new file mode 120000 index 0000000..7841658 --- /dev/null +++ b/regr-tests/test3-updn-tls/infos-0.key @@ -0,0 +1 @@ +../pki-data/infos-0.key \ No newline at end of file diff --git a/regr-tests/test3-updn-tls/infos-0.trust b/regr-tests/test3-updn-tls/infos-0.trust new file mode 120000 index 0000000..c047c58 --- /dev/null +++ b/regr-tests/test3-updn-tls/infos-0.trust @@ -0,0 +1 @@ +../pki-data/tc-router-1.ca \ No newline at end of file diff --git a/regr-tests/test3-updn-tls/makefile b/regr-tests/test3-updn-tls/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3-updn-tls/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3-updn-tls/muxs-0.crt b/regr-tests/test3-updn-tls/muxs-0.crt new file mode 120000 index 0000000..48abd34 --- /dev/null +++ b/regr-tests/test3-updn-tls/muxs-0.crt @@ -0,0 +1 @@ +../pki-data/muxs-0.crt \ No newline at end of file diff --git a/regr-tests/test3-updn-tls/muxs-0.key b/regr-tests/test3-updn-tls/muxs-0.key new file mode 120000 index 0000000..dc09b9d --- /dev/null +++ b/regr-tests/test3-updn-tls/muxs-0.key @@ -0,0 +1 @@ +../pki-data/muxs-0.key \ No newline at end of file diff --git a/regr-tests/test3-updn-tls/muxs-0.trust b/regr-tests/test3-updn-tls/muxs-0.trust new file mode 120000 index 0000000..c047c58 --- /dev/null +++ b/regr-tests/test3-updn-tls/muxs-0.trust @@ -0,0 +1 @@ +../pki-data/tc-router-1.ca \ No newline at end of file diff --git a/regr-tests/test3-updn-tls/radioinit1.sh b/regr-tests/test3-updn-tls/radioinit1.sh new file mode 100644 index 0000000..b02037e --- /dev/null +++ b/regr-tests/test3-updn-tls/radioinit1.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo 1 $LORAGW_SPI "$@" > radioinit.args +echo --- "$0" --- diff --git a/regr-tests/test3-updn-tls/radioinit2.sh b/regr-tests/test3-updn-tls/radioinit2.sh new file mode 100644 index 0000000..ef55d1c --- /dev/null +++ b/regr-tests/test3-updn-tls/radioinit2.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo 2 $LORAGW_SPI "$@" > radioinit.args diff --git a/regr-tests/test3-updn-tls/radioinit3.sh b/regr-tests/test3-updn-tls/radioinit3.sh new file mode 100644 index 0000000..8ab5aec --- /dev/null +++ b/regr-tests/test3-updn-tls/radioinit3.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo 3 $LORAGW_SPI "$@" > radioinit.args diff --git a/regr-tests/test3-updn-tls/slave-0.conf b/regr-tests/test3-updn-tls/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3-updn-tls/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3-updn-tls/station.conf b/regr-tests/test3-updn-tls/station.conf new file mode 100644 index 0000000..db35473 --- /dev/null +++ b/regr-tests/test3-updn-tls/station.conf @@ -0,0 +1,30 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + "log_file": "stderr", /* "station.log" */ + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + "radio_init": "radioinit1.sh" + } +} + diff --git a/regr-tests/test3-updn-tls/test.py b/regr-tests/test3-updn-tls/test.py new file mode 100644 index 0000000..0eb2dad --- /dev/null +++ b/regr-tests/test3-updn-tls/test.py @@ -0,0 +1,162 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3-updn-tls') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + + +class TestLgwSimServer(su.LgwSimServer): + fcnt = 0 + updf_task = None + txcnt = 0 + + async def on_connected(self, lgwsim:su.LgwSim) -> None: + self.updf_task = asyncio.ensure_future(self.send_updf()) + + async def on_close(self): + self.updf_task.cancel() + self.updf_task = None + logger.debug('LGWSIM - close') + + async def on_tx(self, lgwsim, pkt): + logger.debug('LGWSIM: TX %r' % (pkt,)) + self.txcnt += 1 + + async def send_updf(self) -> None: + try: + while True: + logger.debug('LGWSIM - UPDF FCnt=%d' % (self.fcnt,)) + if self.fcnt < 5: + # First we're sending on 10% band and expect a reply for every frame + freq = 869.525 + port = 1 + elif self.fcnt < 10: + # Send on a .1% band - only 1st reply, other blocked by DC + freq = 867.100 + port = 2 + else: + freq = 869.525 + port = 3 if self.txcnt >= 6 else 4 # signal termination + if 0 not in self.units: + return + lgwsim = self.units[0] + await lgwsim.send_rx(rps=(7,125), freq=freq, frame=su.makeDF(fcnt=self.fcnt, port=port)) + self.fcnt += 1 + await asyncio.sleep(1.0) + except asyncio.CancelledError: + logger.debug('send_updf canceled.') + except Exception as exc: + logger.error('send_updf failed!', exc_info=True) + + +class TestMuxs(tu.Muxs): + exp_seqno = [] + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_dntxed(self, ws, msg): + if [msg['seqno']] != self.exp_seqno[0:1]: + logger.error('DNTXED: %r\nbut expected seqno=%r' % (msg, self.exp_seqno)) + await self.testDone(2) + del self.exp_seqno[0] + + async def handle_updf(self, ws, msg): + fcnt = msg['FCnt'] + logger.debug('UPDF: rctx=%r Fcnt=%d Freq=%.3fMHz FPort=%d' % (msg['upinfo']['rctx'], fcnt, msg['Freq']/1e6, msg['FPort'])) + port = msg['FPort'] + if port >= 3: + await self.testDone(0 if port == 3 else 1) + dnframe = { + 'msgtype': 'dnframe', + 'DR' : msg['DR'], + 'Freq' : msg['Freq'], + 'DevEui' : '00-00-00-00-11-00-00-01', + 'xtime' : msg['upinfo']['xtime']+1000000, + 'seqno' : fcnt, + 'MuxTime': time.time(), + 'rctx' : msg['upinfo']['rctx'], + 'pdu' : '0A0B0C0D0E0F', + } + # 6..9 not TXed due to DC limits + if fcnt <= 5 or fcnt >= 10: + self.exp_seqno.append(dnframe['seqno']) + await ws.send(json.dumps(dnframe)) + +tls_mode = (sys.argv[1:2] == ['tls']) +tls_no_ca = (sys.argv[2:3] == ['no_ca']) + +ws = 'wss' if tls_mode else 'ws' + +with open("tc.uri","w") as f: + f.write('%s://localhost:6038' % ws) + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos(muxsuri = ('%s://localhost:6039/router' % ws), + tlsidentity = ('infos-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + muxs = TestMuxs(tlsidentity = ('muxs-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + sim = TestLgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + a = os.environ.get('STATION_ARGS','') + args = [] if not a else a.split(' ') + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + args + station = await subprocess.create_subprocess_exec(*station_args) + + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3-updn-tls/test.sh b/regr-tests/test3-updn-tls/test.sh new file mode 100755 index 0000000..2f7f283 --- /dev/null +++ b/regr-tests/test3-updn-tls/test.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function cleanup () { + default_cleanup + echo "Extra cleanup.." + rm -f tc.{crt,key,trust} +} + +. ../testlib.sh + +# radioinit args +if [[ "$TEST_VARIANT" = "testms" ]]; then + riargs="./spidev 0" +else + riargs="./spidev" +fi + +# Plain TCP/ws +unset STATION_ARGS +unset STATION_RADIOINIT +python test.py +banner TCP/ws done +collect_gcda _tcp_ws + +expect="1 ./spidev radioinit1.sh $riargs" +if [[ "$(cat radioinit.args)" != "$expect" ]]; then + echo "radioinit1.sh failed" + echo " ----------> $(cat radioinit.args)" + echo " vs> $expect" + exit 1 +fi + +# Plain TLS/wss no client auth +export STATION_ARGS="-i radioinit2.sh" +ln -s ../pki-data/muxs-0.ca tc.trust +python test.py tls no_ca +banner TLS/wss no client auth done +collect_gcda _tls_no_ca +unset STATION_ARGS + +expect="2 ./spidev radioinit2.sh $riargs" +if [[ "$(cat radioinit.args)" != "$expect" ]]; then + echo "radioinit2.sh failed" + echo " ----------> $(cat radioinit.args)" + echo " vs> $expect" + exit 1 +fi + +# Plain TLS/wss with client auth +export STATION_RADIOINIT="radioinit3.sh" +ln -s ../pki-data/tc-router-1.key tc.key +ln -s ../pki-data/tc-router-1.crt tc.crt +python test.py tls +banner TLS/wss with client auth done +collect_gcda _tls_ca +unset STATION_RADIOINIT + +expect="3 ./spidev radioinit3.sh $riargs" +if [[ "$(cat radioinit.args)" != "$expect" ]]; then + echo "radioinit3.sh failed" + echo " --------------> $(cat radioinit.args)" + echo " vs> $expect" + exit 1 +fi diff --git a/regr-tests/test3a-updn-tls/.gitignore b/regr-tests/test3a-updn-tls/.gitignore new file mode 100644 index 0000000..00457f3 --- /dev/null +++ b/regr-tests/test3a-updn-tls/.gitignore @@ -0,0 +1,9 @@ +tc.uri +tc.key +tc.crt +tc.trust +tc-bak.* +*.info +station.log +station.pid +spidev diff --git a/regr-tests/test3a-updn-tls/infos-0.crt b/regr-tests/test3a-updn-tls/infos-0.crt new file mode 120000 index 0000000..99b9aba --- /dev/null +++ b/regr-tests/test3a-updn-tls/infos-0.crt @@ -0,0 +1 @@ +../pki-data/infos-0.crt \ No newline at end of file diff --git a/regr-tests/test3a-updn-tls/infos-0.key b/regr-tests/test3a-updn-tls/infos-0.key new file mode 120000 index 0000000..7841658 --- /dev/null +++ b/regr-tests/test3a-updn-tls/infos-0.key @@ -0,0 +1 @@ +../pki-data/infos-0.key \ No newline at end of file diff --git a/regr-tests/test3a-updn-tls/infos-0.trust b/regr-tests/test3a-updn-tls/infos-0.trust new file mode 120000 index 0000000..c047c58 --- /dev/null +++ b/regr-tests/test3a-updn-tls/infos-0.trust @@ -0,0 +1 @@ +../pki-data/tc-router-1.ca \ No newline at end of file diff --git a/regr-tests/test3a-updn-tls/makefile b/regr-tests/test3a-updn-tls/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3a-updn-tls/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3a-updn-tls/muxs-0.crt b/regr-tests/test3a-updn-tls/muxs-0.crt new file mode 120000 index 0000000..48abd34 --- /dev/null +++ b/regr-tests/test3a-updn-tls/muxs-0.crt @@ -0,0 +1 @@ +../pki-data/muxs-0.crt \ No newline at end of file diff --git a/regr-tests/test3a-updn-tls/muxs-0.key b/regr-tests/test3a-updn-tls/muxs-0.key new file mode 120000 index 0000000..dc09b9d --- /dev/null +++ b/regr-tests/test3a-updn-tls/muxs-0.key @@ -0,0 +1 @@ +../pki-data/muxs-0.key \ No newline at end of file diff --git a/regr-tests/test3a-updn-tls/muxs-0.trust b/regr-tests/test3a-updn-tls/muxs-0.trust new file mode 120000 index 0000000..c047c58 --- /dev/null +++ b/regr-tests/test3a-updn-tls/muxs-0.trust @@ -0,0 +1 @@ +../pki-data/tc-router-1.ca \ No newline at end of file diff --git a/regr-tests/test3a-updn-tls/slave-0.conf b/regr-tests/test3a-updn-tls/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3a-updn-tls/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3a-updn-tls/station.conf b/regr-tests/test3a-updn-tls/station.conf new file mode 100644 index 0000000..86dce8b --- /dev/null +++ b/regr-tests/test3a-updn-tls/station.conf @@ -0,0 +1,29 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + "log_file": "stderr", /* "station.log" */ + "log_level": "VERBOSE", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3 + } +} + diff --git a/regr-tests/test3a-updn-tls/test.py b/regr-tests/test3a-updn-tls/test.py new file mode 100644 index 0000000..97694bd --- /dev/null +++ b/regr-tests/test3a-updn-tls/test.py @@ -0,0 +1,163 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3a-updn-tls') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + + +class TestLgwSimServer(su.LgwSimServer): + fcnt = 0 + updf_task = None + txcnt = 0 + + async def on_connected(self, lgwsim:su.LgwSim) -> None: + self.updf_task = asyncio.ensure_future(self.send_updf()) + + async def on_close(self): + self.updf_task.cancel() + self.updf_task = None + logger.debug('LGWSIM - close') + + async def on_tx(self, lgwsim, pkt): + logger.debug('LGWSIM: TX %r' % (pkt,)) + self.txcnt += 1 + + async def send_updf(self) -> None: + try: + while True: + logger.debug('LGWSIM - UPDF FCnt=%d' % (self.fcnt,)) + if self.fcnt < 5: + # First we're sending on 10% band and expect a reply for every frame + freq = 869.525 + port = 1 + elif self.fcnt < 10: + # Send on a .1% band - only 1st reply, other blocked by DC + freq = 867.100 + port = 2 + else: + freq = 869.525 + port = 3 if self.txcnt >= 6 else 4 # signal termination + if 0 not in self.units: + return + lgwsim = self.units[0] + await lgwsim.send_rx(rps=(7,125), freq=freq, frame=su.makeDF(fcnt=self.fcnt, port=port)) + self.fcnt += 1 + await asyncio.sleep(1.0) + except asyncio.CancelledError: + logger.debug('send_updf canceled.') + except Exception as exc: + logger.error('send_updf failed!', exc_info=True) + + +class TestMuxs(tu.Muxs): + exp_seqno = [] + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_dntxed(self, ws, msg): + if [msg['seqno']] != self.exp_seqno[0:1]: + logger.error('DNTXED: %r\nbut expected seqno=%r' % (msg, self.exp_seqno)) + await self.testDone(2) + del self.exp_seqno[0] + + async def handle_updf(self, ws, msg): + fcnt = msg['FCnt'] + logger.debug('UPDF: rctx=%r Fcnt=%d Freq=%.3fMHz FPort=%d' % (msg['upinfo']['rctx'], fcnt, msg['Freq']/1e6, msg['FPort'])) + port = msg['FPort'] + if port >= 3: + await self.testDone(0 if port == 3 else 1) + dnframe = { + 'msgtype' : 'dnmsg', + 'dC' : 0, + 'dnmode' : 'updn', + 'priority': 0, + 'RxDelay' : 0, + 'RX1DR' : msg['DR'], + 'RX1Freq' : msg['Freq'], + 'DevEui' : '00-00-00-00-11-00-00-01', + 'xtime' : msg['upinfo']['xtime']+1000000, + 'seqno' : fcnt, + 'MuxTime' : time.time(), + 'rctx' : msg['upinfo']['rctx'], + 'pdu' : '0A0B0C0D0E0F', + } + # 6..9 not TXed due to DC limits + if fcnt <= 5 or fcnt >= 10: + self.exp_seqno.append(dnframe['seqno']) + await ws.send(json.dumps(dnframe)) + +tls_mode = (sys.argv[1:2] == ['tls']) +tls_no_ca = (sys.argv[2:3] == ['no_ca']) + +ws = 'wss' if tls_mode else 'ws' + +with open("tc.uri","w") as f: + f.write('%s://localhost:6038' % ws) + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos(muxsuri = ('%s://localhost:6039/router' % ws), + tlsidentity = ('infos-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + muxs = TestMuxs(tlsidentity = ('muxs-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + sim = TestLgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3a-updn-tls/test.sh b/regr-tests/test3a-updn-tls/test.sh new file mode 100755 index 0000000..4b7d7f1 --- /dev/null +++ b/regr-tests/test3a-updn-tls/test.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +function banner () { + s='==============================' + echo $s + echo "$@" + echo $s + echo +} + +# Plain TCP/ws +python test.py +banner TCP/ws done +collect_gcda _tcp_ws + +# Plain TLS/wss no client auth +rm -f tc-bak.* tc.trust +ln -s ../pki-data/muxs-0.ca tc.trust +python test.py tls no_ca +banner TLS/wss no client auth done +collect_gcda _tls_no_ca + +# Plain TLS/wss with client auth +rm -f tc-bak.* tc.key tc.crt +ln -s ../pki-data/tc-router-1.key tc.key +ln -s ../pki-data/tc-router-1.crt tc.crt +python test.py tls +banner TLS/wss with client auth done +collect_gcda _tls_ca diff --git a/regr-tests/test3b-dnC/.gitignore b/regr-tests/test3b-dnC/.gitignore new file mode 100644 index 0000000..c84bd03 --- /dev/null +++ b/regr-tests/test3b-dnC/.gitignore @@ -0,0 +1,6 @@ +tc.uri +tc-bak.* +station.log +station.pid +spidev* +*.info diff --git a/regr-tests/test3b-dnC/makefile b/regr-tests/test3b-dnC/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3b-dnC/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3b-dnC/slave-0.conf b/regr-tests/test3b-dnC/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3b-dnC/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3b-dnC/station.conf b/regr-tests/test3b-dnC/station.conf new file mode 100644 index 0000000..d05cc6a --- /dev/null +++ b/regr-tests/test3b-dnC/station.conf @@ -0,0 +1,35 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0, + "antenna_type": "omni" + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + /* "log_file": "station.log", */ + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* required for success checks of tests */ + "nodc": true, + "CLASS_C_BACKOFF_BY": "100ms", + "CLASS_C_BACKOFF_MAX": 10 + } +} + diff --git a/regr-tests/test3b-dnC/test.py b/regr-tests/test3b-dnC/test.py new file mode 100644 index 0000000..6e7f3e6 --- /dev/null +++ b/regr-tests/test3b-dnC/test.py @@ -0,0 +1,152 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import random +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3b-dnC') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + + +class TestMuxs(tu.Muxs): + exp_seqno = [] + seqno = 0 + ws = None + send_task = None + ev = None + + async def handle_connection(self, ws): + self.ws = ws + self.ev = asyncio.Event() + self.send_task = asyncio.ensure_future(self.send_classC()) + await super().handle_connection(ws) + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_dntxed(self, ws, msg): + if [msg['seqno']] != self.exp_seqno[0:1]: + logger.error('DNTXED: %r\nbut expected seqno=%r' % (msg, self.exp_seqno)) + await self.testDone(2) + del self.exp_seqno[0] + self.ev.set() + + + def make_dnmsgC(self, rx2dr=0, rx2freq=869.525, plen=5): + dnmsg = { + 'msgtype' : 'dnmsg', + 'dC' : 2, # device class C + 'dnmode' : 'dn', + 'priority': 0, + 'RxDelay' : 0, + 'RX2DR' : rx2dr, + 'RX2Freq' : int(rx2freq*1e6), + 'DevEui' : '00-00-00-00-11-00-00-01', + #'xtime' : 0, # not required + 'seqno' : self.seqno, + 'MuxTime' : time.time(), + 'rctx' : 0, # antenna#0 + 'pdu' : bytes(range(plen)).hex(), + } + if random.random() > 0.5: + dnmsg.pop('RxDelay') + self.seqno += 1 + return dnmsg + + async def send_classC(self): + try: + await asyncio.sleep(1.0) + + dnmsg1 = self.make_dnmsgC(rx2dr=0, plen=20) # airtime: 1.3s + dnmsg2 = self.make_dnmsgC(rx2dr=0, plen=20) # cannot be sent - blocked previous (for 1s) + self.exp_seqno.append(dnmsg1['seqno']) + await self.ws.send(json.dumps(dnmsg1)) + await self.ws.send(json.dumps(dnmsg2)) + + self.ev.clear() + await asyncio.wait_for(self.ev.wait(), 5.0) + await asyncio.sleep(2.0) # make sure previous frames are done with TX + assert self.exp_seqno == [] + + dnmsg1 = self.make_dnmsgC(rx2dr=1, plen=30) # airtime: 0.91s + dnmsg2 = self.make_dnmsgC(rx2dr=0, plen=20) # can be sent - pushed back by 1s + self.exp_seqno.append(dnmsg1['seqno']) + self.exp_seqno.append(dnmsg2['seqno']) + await self.ws.send(json.dumps(dnmsg1)) + await self.ws.send(json.dumps(dnmsg2)) + + while self.exp_seqno: + self.ev.clear() + await asyncio.wait_for(self.ev.wait(), 5.0) + + await asyncio.sleep(2.0) # make sure previous frames are done with TX + await self.testDone(0) + except Exception as exc: + logger.error('send_classC failed: %s', exc, exc_info=True) + await self.testDone(1) + + +with open("tc.uri","w") as f: + f.write('ws://localhost:6038') + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos() + muxs = TestMuxs() + sim = su.LgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3b-dnC/test.sh b/regr-tests/test3b-dnC/test.sh new file mode 100755 index 0000000..c468155 --- /dev/null +++ b/regr-tests/test3b-dnC/test.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +python test.py +banner class C scheduling done +collect_gcda diff --git a/regr-tests/test3b-dnC_2ant/.gitignore b/regr-tests/test3b-dnC_2ant/.gitignore new file mode 100644 index 0000000..b67e6b1 --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/.gitignore @@ -0,0 +1,7 @@ +tc.uri +tc-bak.* +station.conf +station.log +station.pid +spidev* +*.info diff --git a/regr-tests/test3b-dnC_2ant/makefile b/regr-tests/test3b-dnC_2ant/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3b-dnC_2ant/slave-0.conf b/regr-tests/test3b-dnC_2ant/slave-0.conf new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/slave-0.conf @@ -0,0 +1 @@ +{} diff --git a/regr-tests/test3b-dnC_2ant/slave-1.conf b/regr-tests/test3b-dnC_2ant/slave-1.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/slave-1.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3b-dnC_2ant/station.conf.in b/regr-tests/test3b-dnC_2ant/station.conf.in new file mode 100644 index 0000000..d9c416b --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/station.conf.in @@ -0,0 +1,35 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0, + "antenna_type": "ATYPE" + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + /* "log_file": "station.log", */ + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* required for success checks of tests */ + "nodc": true, + "CLASS_C_BACKOFF_BY": "100ms", + "CLASS_C_BACKOFF_MAX": 10 + } +} + diff --git a/regr-tests/test3b-dnC_2ant/test.py b/regr-tests/test3b-dnC_2ant/test.py new file mode 100644 index 0000000..df6c335 --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/test.py @@ -0,0 +1,168 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3b-dnC_2ant') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + +n_ant = 1 if os.environ['TEST_VARIANT']=='testsim' else 2 +omni = (os.environ['ANTENNA_TYPE'] == 'omni') + + +class TestMuxs(tu.Muxs): + expected = [] + seqno = 0 + ws = None + send_task = None + ev = None + + async def handle_connection(self, ws): + self.ws = ws + self.ev = asyncio.Event() + self.send_task = asyncio.ensure_future(self.send_classC()) + await super().handle_connection(ws) + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_dntxed(self, ws, msg): + if (msg['seqno'], msg['rctx']) != (self.expected[0] if self.expected else None): + logger.error('DNTXED: %r\nbut expected seqno=%r' % (msg, self.expected)) + await self.testDone(2) + logger.debug('DNTXED %d ant#%d' % (msg['seqno'], msg['rctx'])) + del self.expected[0] + self.ev.set() + + + def make_dnmsgC(self, rx2dr=0, rx2freq=869.525, plen=5, rctx=0, delayms=0): + dnmsg = { + 'msgtype' : 'dnmsg', + 'dC' : 2, # device class C + 'dnmode' : 'dn', + 'priority': 0, + 'RxDelay' : 0, + 'RX2DR' : rx2dr, + 'RX2Freq' : int(rx2freq*1e6), + 'DevEui' : '00-00-00-00-11-00-00-01', + 'xtime' : 0, # not required + 'seqno' : self.seqno, + 'MuxTime' : time.time(), + 'rctx' : rctx, # antenna + 'pdu' : bytes(range(plen)).hex(), + 'delayms' : delayms, + } + self.seqno += 1 + return dnmsg + + async def send_classC_seq(self, dnmsgs, exp): + self.expected.extend((dnmsgs[i]['seqno'], ant) for i, ant in exp) + for dnmsg in dnmsgs: + delayms = dnmsg.pop('delayms',0) + if delayms: await asyncio.sleep(delayms/1e3) + await self.ws.send(json.dumps(dnmsg)) + while self.expected: + self.ev.clear() + await asyncio.wait_for(self.ev.wait(), 5.0) + await asyncio.sleep(3.0) # assure no late dntxed is coming in and all frame are done with TX + logger.debug('%s ok: %r' % ('-'*30, exp)) + + + async def send_classC(self): + try: + if n_ant == 2 and omni: + dnmsgs = [ + self.make_dnmsgC(rx2dr=0, plen=20), # airtime: 1.3s - blocks ant#0 + self.make_dnmsgC(rx2dr=0, plen=20), # airtime: 1.3s - switches to ant#1 + self.make_dnmsgC(rx2dr=0, plen=20) ] # cannot be sent - blocked previous (for 1s) + await self.send_classC_seq(dnmsgs, [(0,0),(1,1)]) + + dnmsgs = [ + self.make_dnmsgC(rx2dr=1, plen=30), # airtime: 0.91s - blocks ant#0 + self.make_dnmsgC(rx2dr=2, plen=30), # airtime: 0.45s - blocks ant#1 + self.make_dnmsgC(rx2dr=0, plen=20) ] # can be sent after push back by 0.5/1s + await self.send_classC_seq(dnmsgs, [(0,0),(1,1),(2,1)]) # 1 has shorter txtime, dntxed arrives before 0 + # OLD: If dntxed is sent at txend then order of dntxed is determined by frame length + # OLD: 1 has shorter txtime, dntxed arrives before 0 + # OLD: await self.send_classC_seq(dnmsgs, [(1,1),(0,0),(2,1)]) + await self.testDone(0) + + if n_ant == 1 or not omni: + dnmsgs = [ + self.make_dnmsgC(rx2dr=0, plen=20, delayms=0), # airtime: 1.3s - blocks ant#0 + self.make_dnmsgC(rx2dr=0, plen=20, delayms=0), # airtime: 1.3s - blocked by previous + self.make_dnmsgC(rx2dr=0, plen=20, delayms=500) ] # can be sent by push back + await self.send_classC_seq(dnmsgs, [(0,0),(2,0)]) + await self.testDone(0) + + await self.testDone(1) + + except Exception as exc: + logger.error('send_classC failed: %s', exc, exc_info=True) + await self.testDone(1) + + +with open("tc.uri","w") as f: + f.write('ws://localhost:6038') + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos() + muxs = TestMuxs() + sim = su.LgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3b-dnC_2ant/test.sh b/regr-tests/test3b-dnC_2ant/test.sh new file mode 100755 index 0000000..eed3926 --- /dev/null +++ b/regr-tests/test3b-dnC_2ant/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Need master/slave simulation to handle multiple radios +. ../testlib.sh + +for t in omni sector; do + cleanup + export ANTENNA_TYPE=$t + banner 'class C scheduling - $ANTENNA_TYPE antenna(s)' + sed -e "s/ATYPE/$t/" station.conf.in > station.conf + python test.py + banner class C scheduling done + collect_gcda _$t +done diff --git a/regr-tests/test3b-rx2_2ant/.gitignore b/regr-tests/test3b-rx2_2ant/.gitignore new file mode 100644 index 0000000..b67e6b1 --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/.gitignore @@ -0,0 +1,7 @@ +tc.uri +tc-bak.* +station.conf +station.log +station.pid +spidev* +*.info diff --git a/regr-tests/test3b-rx2_2ant/makefile b/regr-tests/test3b-rx2_2ant/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3b-rx2_2ant/slave-0.conf b/regr-tests/test3b-rx2_2ant/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3b-rx2_2ant/slave-1.conf b/regr-tests/test3b-rx2_2ant/slave-1.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/slave-1.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3b-rx2_2ant/station.conf.in b/regr-tests/test3b-rx2_2ant/station.conf.in new file mode 100644 index 0000000..d9c416b --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/station.conf.in @@ -0,0 +1,35 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0, + "antenna_type": "ATYPE" + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + /* "log_file": "station.log", */ + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* required for success checks of tests */ + "nodc": true, + "CLASS_C_BACKOFF_BY": "100ms", + "CLASS_C_BACKOFF_MAX": 10 + } +} + diff --git a/regr-tests/test3b-rx2_2ant/test.py b/regr-tests/test3b-rx2_2ant/test.py new file mode 100644 index 0000000..8a510aa --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/test.py @@ -0,0 +1,215 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3b-rx2_2ant') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + +n_ant = 1 if os.environ['TEST_VARIANT']=='testsim' else 2 +omni = (os.environ['ANTENNA_TYPE'] == 'omni') + + +class TestLgwSimServer(su.LgwSimServer): + fcnt = 0 + updf_task = None + txcnt = 0 + + async def on_connected(self, lgwsim:su.LgwSim) -> None: + if lgwsim.unitIdx == 0: + self.updf_task = asyncio.ensure_future(self.send_updf()) + muxs.xticks = lgwsim.xticks + + async def on_close(self): + if self.updf_task: + self.updf_task.cancel() + self.updf_task = None + logger.debug('LGWSIM - close') + + async def on_tx(self, lgwsim, pkt): + logger.debug('LGWSIM: TX %r' % (pkt,)) + self.txcnt += 1 + + async def send_updf(self) -> None: + try: + await asyncio.sleep(1.0) + lgwsim = self.units[0] + await lgwsim.send_rx(rps=(7,125), freq=869.525, frame=su.makeDF(fcnt=0, port=1)) + self.updf_task = None + except Exception as exc: + logger.error('send_updf failed!', exc_info=True) + + +class TestMuxs(tu.Muxs): + expected = [] + seqno = 0 + ws = None + send_task = None + ev = None + xtime_ext = 0 + xticks = None + + async def handle_connection(self, ws): + self.ws = ws + self.ev = asyncio.Event() + await super().handle_connection(ws) + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_updf(self, ws, msg): + logger.debug('UPDF: rctx=%r Fcnt=%d Freq=%.3fMHz FPort=%d' % (msg['upinfo']['rctx'], msg['FCnt'], msg['Freq']/1e6, msg['FPort'])) + xtime = msg['upinfo']['xtime'] + self.xtime_ext = xtime >> 32 + logger.debug('xtime_ext: 0x%X - xtime=0x%X xticks=0x%X' % (self.xtime_ext, xtime, self.xticks())) + self.send_task = asyncio.ensure_future(self.send_classA()) + + async def handle_dntxed(self, ws, msg): + if (msg['seqno'], msg['rctx']) != (self.expected[0] if self.expected else None): + logger.debug('DNTXED: %r\nbut expected seqno=%r' % (msg, self.expected)) + await self.testDone(2) + logger.debug('DNTXED %d ant#%d' % (msg['seqno'], msg['rctx'])) + del self.expected[0] + self.ev.set() + + + def make_dnmsgA(self, rx1dr=0, rx1freq=869.525, rx2dr=0, rx2freq=869.525, dr=-1, plen=5, + rctx=0, delayms=0, xoff=0): + if dr >= 0: + rx1dr = rx2dr = dr + dnmsg = { + 'msgtype' : 'dnmsg', + 'dC' : 0, # device class A + 'dnmode' : 'updn', + 'priority': 0, + 'RxDelay' : 1, + 'RX1DR' : rx1dr, + 'RX1Freq' : int(rx1freq*1e6), + 'RX2DR' : rx2dr, + 'RX2Freq' : int(rx2freq*1e6), + 'DevEui' : '00-00-00-00-11-00-00-01', + 'xtime' : 0, # replaced when actually sent + 'seqno' : self.seqno, + 'MuxTime' : time.time(), + 'rctx' : rctx, # antenna + 'pdu' : bytes(range(plen)).hex(), + 'delayms' : delayms, + } + if xoff: + dnmsg['xoff'] = xoff + self.seqno += 1 + return dnmsg + + async def send_classA_seq(self, dnmsgs, exp): + self.expected.extend((dnmsgs[i]['seqno'], ant) for i, ant in exp) + for dnmsg in dnmsgs: + delayms = dnmsg.pop('delayms',0) + if delayms: await asyncio.sleep(delayms/1e3) + dnmsg['xtime'] = self.xticks() + dnmsg.pop('xoff', -500000) + (self.xtime_ext<<32) + await self.ws.send(json.dumps(dnmsg)) + while self.expected: + self.ev.clear() + await asyncio.wait_for(self.ev.wait(), 5.0) + await asyncio.sleep(4.0) # assure no late dntxed is coming in and previous frames done with TX + assert not self.expected + logger.debug('%s ok: %r' % ('-'*30, exp)) + + + async def send_classA(self): + try: + if n_ant == 2 and omni: + dnmsgs = [ + self.make_dnmsgA(dr=0, plen=20), # airtime: 1.3s - blocks ant#0 + self.make_dnmsgA(dr=0, plen=20), # airtime: 1.3s - switches to ant#1 + self.make_dnmsgA(dr=0, plen=20) ] # cannot be sent - blocked previous (for 1s) + await self.send_classA_seq(dnmsgs, [(0,0),(1,1)]) + dnmsgs = [ + self.make_dnmsgA(dr=1, plen=30), # airtime: 0.91s - blocks ant#0 + self.make_dnmsgA(dr=2, plen=30), # airtime: 0.45s - blocks ant#1 + self.make_dnmsgA(dr=0, plen=30), # can be sent after switch to RX2 +1.0s ant#0 + self.make_dnmsgA(dr=0, plen=20), # can be sent after switch to RX2 +1.0s ant#1 + self.make_dnmsgA(dr=0, plen=20) ] # cannot be sent anymore + # 1/3 has shorter txtime, dntxed arrives before 0/2 + await self.send_classA_seq(dnmsgs, [(0,0),(1,1),(2,0),(3,1)]) + # if dntxed sent at end of frame (old): await self.send_classA_seq(dnmsgs, [(1,1),(0,0),(3,1),(2,0)]) + await self.testDone(0) + + if n_ant == 1 or not omni: + dnmsgs = [ + self.make_dnmsgA(dr=1, plen=30, delayms=0), # airtime: 0.91s - blocks ant#0 + self.make_dnmsgA(dr=0, plen=20, delayms=0), # airtime: 1.3s - switch to RX2 + self.make_dnmsgA(dr=0, plen=20, delayms=0) ] # cannot be sent by RX2 + await self.send_classA_seq(dnmsgs, [(0,0),(1,0)]) + await self.testDone(0) + + await self.testDone(1) + + except Exception as exc: + logger.error('send_classA failed: %s', exc, exc_info=True) + await self.testDone(1) + + +with open("tc.uri","w") as f: + f.write('ws://localhost:6038') + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos() + muxs = TestMuxs() + sim = TestLgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3b-rx2_2ant/test.sh b/regr-tests/test3b-rx2_2ant/test.sh new file mode 100755 index 0000000..e950a08 --- /dev/null +++ b/regr-tests/test3b-rx2_2ant/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Need master/slave simulation to handle multiple radios +. ../testlib.sh + +for t in omni sector; do + cleanup + export ANTENNA_TYPE=$t + banner "switch to RX2 - $ANTENNA_TYPE antenna(s)" + sed -e "s/ATYPE/$t/" station.conf.in > station.conf + python test.py + banner "switch to RX2 done - $ANTENNA_TYPE antenna(s)" + collect_gcda _$t +done diff --git a/regr-tests/test3c-cca/.gitignore b/regr-tests/test3c-cca/.gitignore new file mode 100644 index 0000000..c84bd03 --- /dev/null +++ b/regr-tests/test3c-cca/.gitignore @@ -0,0 +1,6 @@ +tc.uri +tc-bak.* +station.log +station.pid +spidev* +*.info diff --git a/regr-tests/test3c-cca/makefile b/regr-tests/test3c-cca/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3c-cca/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3c-cca/slave-0.conf b/regr-tests/test3c-cca/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3c-cca/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3c-cca/station.conf b/regr-tests/test3c-cca/station.conf new file mode 100644 index 0000000..d05cc6a --- /dev/null +++ b/regr-tests/test3c-cca/station.conf @@ -0,0 +1,35 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0, + "antenna_type": "omni" + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + /* "log_file": "station.log", */ + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* required for success checks of tests */ + "nodc": true, + "CLASS_C_BACKOFF_BY": "100ms", + "CLASS_C_BACKOFF_MAX": 10 + } +} + diff --git a/regr-tests/test3c-cca/test.py b/regr-tests/test3c-cca/test.py new file mode 100644 index 0000000..6e6eabb --- /dev/null +++ b/regr-tests/test3c-cca/test.py @@ -0,0 +1,181 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3c-cca') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + +FREQ1 = 922.1 +FREQ2 = 922.3 +FREQ3 = 922.5 + + +class TestLgwSimServer(su.LgwSimServer): + fcnt = 0 + updf_task = None + txcnt = 0 + exp_txfreq = [] + + async def on_connected(self, lgwsim:su.LgwSim) -> None: + now = lgwsim.xticks() + await lgwsim.send_cca([(FREQ2, now, now+int(20e6))]) + + async def on_close(self): + self.updf_task.cancel() + self.updf_task = None + logger.debug('LGWSIM - close') + + async def on_tx(self, lgwsim, pkt): + logger.debug('LGWSIM: TX %r' % (pkt,)) + assert pkt['rf_power'] == 23 + self.txcnt += 1 + if [pkt['freq_hz']] != self.exp_txfreq[0:1]: + logger.debug('LGWSIM: freq=%.3fMHz but expected %.3fMHz' % (pkt['freq_hz']/1e6, self.exp_txfreq[0]/1e6)) + await self.testDone(2) + del self.exp_txfreq[0] + + +class TestMuxs(tu.Muxs): + exp_seqno = [] + seqno = 0 + ws = None + send_task = None + ev = None + + def get_router_config(self): + return tu.router_config_KR920 + + async def handle_connection(self, ws): + self.ws = ws + self.ev = asyncio.Event() + self.send_task = asyncio.ensure_future(self.send_classC()) + await super().handle_connection(ws) + + async def testDone(self, status): + global station + if station: + try: + station.terminate() + except Exception as exc: + logger.error('Shutting down station: %s', exc, exc_info=True) + try: + await station.wait() + logger.error('Exit code station: %d', station.returncode) + station = None + except Exception as exc: + logger.error('Failed to get exit code of station: %s', exc, exc_info=True) + os._exit(status) + + async def handle_dntxed(self, ws, msg): + if [msg['seqno']] != self.exp_seqno[0:1]: + logger.debug('DNTXED: %r\nbut expected seqno=%r' % (msg, self.exp_seqno)) + await self.testDone(2) + del self.exp_seqno[0] + self.ev.set() + + + # airtime: dr=4 (SF8) plen=12 <83ms + def make_dnmsgC(self, rx2dr=4, rx2freq=FREQ1, plen=12): + dnmsg = { + 'msgtype' : 'dnmsg', + 'dC' : 2, # device class C + 'dnmode' : 'dn', + 'priority': 0, + 'RX2DR' : rx2dr, + 'RX2Freq' : int(rx2freq*1e6), + 'DevEui' : '00-00-00-00-11-00-00-01', + #'xtime' : 0, # not required + 'seqno' : self.seqno, + 'MuxTime' : time.time(), + 'rctx' : 0, # antenna#0 + 'pdu' : bytes(range(plen)).hex(), + } + self.seqno += 1 + return dnmsg + + async def send_classC(self): + try: + await asyncio.sleep(1.0) + assert self.seqno & 1 == 0 + + for f in (FREQ1,FREQ2,FREQ3,FREQ2): + dnmsg = self.make_dnmsgC(rx2freq=f) + if f != FREQ2: + self.exp_seqno.append(dnmsg['seqno']) + sim.exp_txfreq.append(dnmsg['RX2Freq']) + await self.ws.send(json.dumps(dnmsg)) + + while self.exp_seqno: + self.ev.clear() + await asyncio.wait_for(self.ev.wait(), 5.0) + + await asyncio.sleep(2.0) + assert sim.exp_txfreq == [] + await self.testDone(0) + except asyncio.CancelledError: + logger.debug('send_classC canceled.') + except Exception as exc: + logger.error('send_classC failed: %s', exc, exc_info=True) + await self.testDone(1) + + +with open("tc.uri","w") as f: + f.write('ws://localhost:6038') + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos() + muxs = TestMuxs() + sim = TestLgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3c-cca/test.sh b/regr-tests/test3c-cca/test.sh new file mode 100755 index 0000000..c468155 --- /dev/null +++ b/regr-tests/test3c-cca/test.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +python test.py +banner class C scheduling done +collect_gcda diff --git a/regr-tests/test3d-bcns/.gitignore b/regr-tests/test3d-bcns/.gitignore new file mode 100644 index 0000000..c84bd03 --- /dev/null +++ b/regr-tests/test3d-bcns/.gitignore @@ -0,0 +1,6 @@ +tc.uri +tc-bak.* +station.log +station.pid +spidev* +*.info diff --git a/regr-tests/test3d-bcns/makefile b/regr-tests/test3d-bcns/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test3d-bcns/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test3d-bcns/slave-0.conf b/regr-tests/test3d-bcns/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test3d-bcns/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test3d-bcns/station.conf b/regr-tests/test3d-bcns/station.conf new file mode 100644 index 0000000..899b62d --- /dev/null +++ b/regr-tests/test3d-bcns/station.conf @@ -0,0 +1,34 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "pps": true, + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0, + "antenna_type": "omni" + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + /* "log_file": "station.log", */ + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + "nodc": true, + "BEACON_INTVL": "2s" + } +} + diff --git a/regr-tests/test3d-bcns/test.py b/regr-tests/test3d-bcns/test.py new file mode 100644 index 0000000..bda2275 --- /dev/null +++ b/regr-tests/test3d-bcns/test.py @@ -0,0 +1,223 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test3d-bcns') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + +REGION = os.environ.get('REGION','KR920') +PPM = 1000000 +BINTV = 2 + +class TestLgwSimServer(su.LgwSimServer): + fcnt = 0 + updf_task = None + txcnt = 0 + seen_bcnfreqs = set() + mono2utc = 0.0 + last_secs = 0 + test_muxs = None + last_chnl = -1 + + async def on_connected(self, lgwsim:su.LgwSim) -> None: + self.mono2utc = int((time.time() - time.monotonic()) * 1e6) + + async def on_close(self): + self.updf_task.cancel() + self.updf_task = None + logger.debug('LGWSIM - close') + + async def on_tx(self, lgwsim, pkt): + try: + if pkt['tx_mode'] != lgwsim.hal.ON_GPS: + logger.debug('LGWSIM: tx_mode!=ON_GPS (ignored): %r', pkt) + return + xticks = pkt['count_us'] + mono = lgwsim.xticks2mono(xticks) + utc = mono + self.mono2utc + logger.info('LGWSIM: ON_GPS xticks=%d/%X mono=%d/%X utc=%d/%X', + xticks, xticks, mono, mono, utc, utc) + logger.debug('LGWSIM: ON_GPS %r', pkt) + d = utc % PPM + if d >= PPM//2: d -= PPM + assert abs(d) < 10 + assert (utc - d) % PPM == 0 + secs = (utc - d) // PPM + assert self.last_secs==0 or self.last_secs+BINTV == secs + self.last_secs = secs + if REGION == 'KR920': + assert pkt['freq_hz'] == 923100000 + assert pkt['size'] == 17 + if REGION == 'US915': + chnl = (pkt['freq_hz'] - 923300000) / 600000 + assert self.last_chnl < 0 or (self.last_chnl + 1) % 8 == chnl + self.last_chnl = chnl + assert pkt['size'] == 23 + + self.txcnt += 1 + if self.txcnt >= 10: + await self.test_muxs.testDone(0) + except Exception as exc: + logger.error('FAILED: %s', exc, exc_info=True) + await self.test_muxs.testDone(1) + + +class TestMuxs(tu.Muxs): + exp_seqno = [] + seqno = 0 + ws = None + send_task = None + ev = None + + def get_router_config(self): + if REGION == 'US915': + conf = tu.router_config_US902_8ch + conf['bcning'] = { + 'DR': 8, + 'layout': [5,11,23], + 'freqs': [923300000 + chx * 600000 for chx in range(8)] + } + else: + conf = tu.router_config_KR920 + conf['bcning'] = { + 'DR': 3, + 'layout': [2,8,17], + 'freqs': [923100000] + } + return conf + + async def handle_connection(self, ws): + self.ws = ws + self.ev = asyncio.Event() + #XXX:old: self.send_task = asyncio.ensure_future(self.send_classC()) + await super().handle_connection(ws) + + async def testDone(self, status): + global station + if station: + try: + station.terminate() + except Exception as exc: + logger.error('Shutting down station: %s', exc, exc_info=True) + try: + await station.wait() + logger.error('Exit code station: %d', station.returncode) + station = None + except Exception as exc: + logger.error('Failed to get exit code of station: %s', exc, exc_info=True) + os._exit(status) + + async def handle_dntxed(self, ws, msg): + if [msg['seqno']] != self.exp_seqno[0:1]: + logger.debug('DNTXED: %r\nbut expected seqno=%r' % (msg, self.exp_seqno)) + await self.testDone(2) + del self.exp_seqno[0] + self.ev.set() + + +#XXX:old: # airtime: dr=4 (SF8) plen=12 <83ms +#XXX:old: def make_dnmsgC(self, rx2dr=4, rx2freq=FREQ1, plen=12): +#XXX:old: dnmsg = { +#XXX:old: 'msgtype' : 'dnmsg', +#XXX:old: 'dC' : 2, # device class C +#XXX:old: 'dnmode' : 'dn', +#XXX:old: 'priority': 0, +#XXX:old: 'RX2DR' : rx2dr, +#XXX:old: 'RX2Freq' : int(rx2freq*1e6), +#XXX:old: 'DevEui' : '00-00-00-00-11-00-00-01', +#XXX:old: #'xtime' : 0, # not required +#XXX:old: 'seqno' : self.seqno, +#XXX:old: 'MuxTime' : time.time(), +#XXX:old: 'rctx' : 0, # antenna#0 +#XXX:old: 'pdu' : bytes(range(plen)).hex(), +#XXX:old: } +#XXX:old: self.seqno += 1 +#XXX:old: return dnmsg +#XXX:old: +#XXX:old: async def send_classC(self): +#XXX:old: try: +#XXX:old: await asyncio.sleep(1.0) +#XXX:old: assert self.seqno & 1 == 0 +#XXX:old: +#XXX:old: for f in (FREQ1,FREQ2,FREQ3,FREQ2): +#XXX:old: dnmsg = self.make_dnmsgC(rx2freq=f) +#XXX:old: if f != FREQ2: +#XXX:old: self.exp_seqno.append(dnmsg['seqno']) +#XXX:old: sim.exp_txfreq.append(dnmsg['RX2Freq']) +#XXX:old: await self.ws.send(json.dumps(dnmsg)) +#XXX:old: +#XXX:old: while self.exp_seqno: +#XXX:old: self.ev.clear() +#XXX:old: await asyncio.wait_for(self.ev.wait(), 5.0) +#XXX:old: +#XXX:old: await asyncio.sleep(2.0) +#XXX:old: assert sim.exp_txfreq == [] +#XXX:old: await self.testDone(0) +#XXX:old: except asyncio.CancelledError: +#XXX:old: logger.debug('send_classC canceled.') +#XXX:old: except Exception as exc: +#XXX:old: logger.error('send_classC failed: %s', exc, exc_info=True) +#XXX:old: await self.testDone(1) + + +with open("tc.uri","w") as f: + f.write('ws://localhost:6038') + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos() + muxs = TestMuxs() + sim = TestLgwSimServer() + sim.test_muxs = muxs + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test3d-bcns/test.sh b/regr-tests/test3d-bcns/test.sh new file mode 100755 index 0000000..d1d89d6 --- /dev/null +++ b/regr-tests/test3d-bcns/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +for R in US915 KR923; do + REGION=$R python test.py + #banner $R beaconing done +done +collect_gcda diff --git a/regr-tests/test4-cups/.gitignore b/regr-tests/test4-cups/.gitignore new file mode 100644 index 0000000..d248842 --- /dev/null +++ b/regr-tests/test4-cups/.gitignore @@ -0,0 +1,22 @@ +*.info +update.bin +updtest.txt +version.txt +station.pid +cups.crt +cups.key +cups.trust +cups.uri +cups-bak.* +cups-temp.* +cups-router-1.cfg +tc.crt +tc.key +tc.trust +tc.uri +tc-bak.* +tc-temp.* +spidev +_cups +_shome +_tc \ No newline at end of file diff --git a/regr-tests/test4-cups/makefile b/regr-tests/test4-cups/makefile new file mode 100644 index 0000000..9448175 --- /dev/null +++ b/regr-tests/test4-cups/makefile @@ -0,0 +1,35 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -rf $$(cat .gitignore) + rm -f cmd.fifo + rm -rf _tc _shome _cups + +.PHONY: all clean diff --git a/regr-tests/test4-cups/sig-0.key b/regr-tests/test4-cups/sig-0.key new file mode 100644 index 0000000..2df5ac3 --- /dev/null +++ b/regr-tests/test4-cups/sig-0.key @@ -0,0 +1 @@ +‰őH§zĄ»˙gL&N¨—!OnŇă(Rg2(.Ä /ńźË‹Ł’߬GŻp 2J2=§ýŐřŕ“çy¶ \ No newline at end of file diff --git a/regr-tests/test4-cups/slave-0.conf b/regr-tests/test4-cups/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test4-cups/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test4-cups/station.conf b/regr-tests/test4-cups/station.conf new file mode 100644 index 0000000..aa1eae0 --- /dev/null +++ b/regr-tests/test4-cups/station.conf @@ -0,0 +1,34 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + "euiprefix": "::0", + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + "TC_TIMEOUT": "2s", + "CUPS_CONN_TIMEOUT": "3s", + "CUPS_OKSYNC_INTV": "4s", + "CUPS_RESYNC_INTV": "4s" + } +} + diff --git a/regr-tests/test4-cups/test.py b/regr-tests/test4-cups/test.py new file mode 100644 index 0000000..71a30ae --- /dev/null +++ b/regr-tests/test4-cups/test.py @@ -0,0 +1,220 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test4-cups') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +restarts = 0 +station = None +infos = None +muxs = None +cups = None +sim = None + + +class TestLgwSimServer(su.LgwSimServer): + fcnt = 0 + updf_task = None + + def __init__(self) -> None: + super().__init__(path='_shome/spidev') + + async def on_connected(self, lgwsim:su.LgwSim) -> None: + self.fcnt = 0 + self.updf_task = asyncio.ensure_future(self.send_updf()) + + async def on_close(self): + self.updf_task.cancel() + self.updf_task = None + logger.debug('LGWSIM - close') + + async def send_updf(self) -> None: + try: + await asyncio.sleep(3) + while True: + logger.debug('LGWSIM - UPDF FCnt=%d' % (self.fcnt,)) + if self.fcnt < 5: + # First we're sending on 10% band and expect a reply for every frame + freq = 869.525 + port = 1 + elif self.fcnt < 10: + # Send on a .1% band - only 1st reply, other blocked by DC + freq = 867.100 + port = 2 + else: + freq = 869.525 + port = 3 if cups.qcnt >= 2 else 4 # signal termination + if 0 not in self.units: + return + lgwsim = self.units[0] + await lgwsim.send_rx(rps=(7,125), freq=freq, frame=su.makeDF(fcnt=self.fcnt, port=port)) + self.fcnt += 1 + await asyncio.sleep(1.0) + except asyncio.CancelledError as err: + logger.warning('send_updf task canceled.') + except Exception as exc: + logger.error('send_updf failed!', exc_info=True) + +class TestMuxs(tu.Muxs): + exp_seqno = [] + station_args = ['station','-p', '--temp', './_shome', '-h', './_shome'] + #station_args = ['valgrind', '--leak-check=full', 'station','-p', '--temp', '.'] + restart_station_handle = None + + async def testDone(self, status): + if self.restart_station_handle: + self.restart_station_handle.cancel() + self.restart_station_handle = None + global station + if station: + station.terminate() + await station.wait() + station = None + sys.stdout.flush() + os._exit(status) + + async def restart_station(self): + global station + while True: + if not station: + station = await subprocess.create_subprocess_exec(*self.station_args) + retcode = await station.wait() + logger.debug('STATION EXIT: code=%d' % (retcode,)) + if not restarts: + sys.stdout.flush() + sys.exit(1 if restarts==0 else 0) + restarts -= 1 + logger.debug('RESTARTING STATION...: code=%d' % (retcode,)) + station = None + + async def handle_connection(self, ws): + self.exp_seqno = [] + await super().handle_connection(ws) + + async def handle_dntxed(self, ws, msg): + if [msg['seqno']] != self.exp_seqno[0:1]: + logger.debug('MUXS DNTXED: %r\nbut expected seqno=%r' % (msg, self.exp_seqno)) + # Lift the reliable downlink requirement for now. + # Reason: The CUPS connection establishment is blocking. During that time no + # downlinks can be scheduled which may result in unreliable downlinks. + # await self.testDone(2) + logger.debug('MUXS DNTXED: expected %r - ok' % (msg['seqno'],)) + del self.exp_seqno[0] + + async def handle_updf(self, ws, msg): + fcnt = msg['FCnt'] + logger.debug('MUXS UPDF: rctx=%r Fcnt=%d Freq=%.3fMHz FPort=%d' % (msg['upinfo']['rctx'], fcnt, msg['Freq']/1e6, msg['FPort'])) + port = msg['FPort'] + if port >= 3: + await self.testDone(0 if port == 3 else 1) + dnframe = { + 'msgtype': 'dnframe', + 'DR' : msg['DR'], + 'Freq' : msg['Freq'], + 'DevEui' : '00-00-00-00-11-00-00-01', + 'xtime' : msg['upinfo']['xtime']+1000000, + 'seqno' : fcnt, + 'MuxTime': time.time(), + 'rctx' : msg['upinfo']['rctx'], + 'pdu' : '0A0B0C0D0E0F', + } + # 6..9 not TXed due to DC limits + if fcnt <= 5 or fcnt >= 10: + self.exp_seqno.append(dnframe['seqno']) + await ws.send(json.dumps(dnframe)) + + +class TestCups(tu.Cups): + qcnt = 0 + + def on_response(self, r_cupsUri:bytes, r_tcUri:bytes, r_cupsCred:bytes, r_tcCred:bytes, r_sig:bytes, r_updbin:bytes) -> bytes: + logger.debug("cupsUri={}, cupsCred={} ({})".format(r_cupsUri, r_cupsCred[2:6].hex(), r_cupsCred[0:2].hex())) + logger.debug("tcUri={}, tcCred={} ({})".format(r_tcUri, r_tcCred[2:6].hex(), r_cupsCred[:2].hex())) + try: + b = super().on_response(r_cupsUri, r_tcUri, r_cupsCred, r_tcCred, r_sig, r_updbin) + if b == b'\x00'*14: + self.qcnt += 1 + return b + except Exception as exc: + logger.error('on_response failed: %s', exc, exc_info=True) + + +tls_mode = (sys.argv[1:2] == ['tls']) +tls_no_ca = (sys.argv[2:3] == ['no_ca']) + +isTLS = 's' if tls_mode else '' + +with open("_shome/cups.uri","w") as f: + f.write('http://localhost:%d' % (6041 if isTLS else 6040,)) +with open("_cups/cups-router-1.cfg","w") as f: + f.write( + ('{' + '"cupsUri": "http%s://localhost:6040",' + '"tcUri" : "ws%s://localhost:6038",' + '"version": "v1"' + '}') % (isTLS, isTLS)) + +async def test_start(): + global station, infos, muxs, cups, sim + sim = TestLgwSimServer() + infos = tu.Infos(muxsuri = ('ws%s://localhost:6039/router' % isTLS), + homedir = '_tc', + tlsidentity = ('infos-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + muxs = TestMuxs(homedir = '_tc', + tlsidentity = ('muxs-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + cups = TestCups(homedir = '_cups', tcdir = '_tc', + tlsidentity = ('cups-0' if tls_mode else None), + tls_no_ca = tls_no_ca) + cups2 = TestCups(homedir = '_cups', tcdir = '_tc', tlsidentity=None) + cups2.port = 6041 + await sim.start_server() + await infos.start_server() + await muxs.start_server() + await cups.start_server() + await cups2.start_server() + await asyncio.sleep(0.3) # give python some time to start up + muxs.restart_station_handle = asyncio.ensure_future(muxs.restart_station()) + + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test4-cups/test.sh b/regr-tests/test4-cups/test.sh new file mode 100755 index 0000000..23da4af --- /dev/null +++ b/regr-tests/test4-cups/test.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function cleanup () { + default_cleanup + rm -f /tmp/update.bin* +} + +. ../testlib.sh + +PKI_DATA=../pki-data + +export UPDTEST=$$ +function check_updtest() { + updtest="$(cat _shome/updtest.txt)" + if [ "$UPDTEST" != "$updtest" ]; then + echo "$1: updtest.txt='$updtest' != '$UPDTEST'" + exit 1 + fi +} + +function setup_A () { + # Note: How to create a signing key and create a signature: + # openssl ecparam -name prime256v1 -genkey | openssl ec -out sig-0.pem # Create private key + # openssl ec -in sig-0.pem -pubout -out sig-0.pub # Create public key + # openssl ec -in sig-0.pub -inform PEM -outform DER -pubin | tail -c 64 > sig-0.key # Convert public key to compact binary format + # openssl dgst -sha512 -sign sig-0.pem v1.bin > v1.bin.sig-0 # Create signature + rm -rf /tmp/update.bin* _shome _cups _tc + killall -q station || true + mkdir -p _shome _cups _tc + cp v1.bin* sig-0.key _cups/ + cp station.conf slave-0.conf sig-0.key _shome/ +} + +function setup_B () { + cp $PKI_DATA/cups-0.{crt,key} _cups/ + cp $PKI_DATA/cups-router-1.ca _cups/cups-0.trust + cp $PKI_DATA/cups-0.ca _cups/cups.ca + cp $PKI_DATA/{muxs,infos}-0.{crt,key} _tc/ + cp $PKI_DATA/muxs-0.ca _tc/tc.ca + cp $PKI_DATA/tc-router-1.ca _tc/infos-0.trust + cp $PKI_DATA/tc-router-1.ca _tc/muxs-0.trust +} + +function setup_C () { + cp $PKI_DATA/cups-router-1.{crt,key} _cups/ + cp $PKI_DATA/tc-router-1.{crt,key} _tc/ +} + +function test_plain() { + # Plain TCP/ws ===================== + banner TCP/ws - Starting... + setup_A + + echo "v0" > _shome/version.txt + rm -f _shome/updtest.txt /tmp/update.bin + python test.py + banner TCP/ws done + collect_gcda _tcp_ws + check_updtest TCP +} + +function test_tls_noauth() { + # TLS/wss without client auth ========= + banner TLS/wss NO client auth - Starting... + setup_A + setup_B + + echo "v0" > _shome/version.txt + rm -f _shome/updtest.txt /tmp/update.bin + python test.py tls no_ca + banner TLS/wss NO client auth - DONE + collect_gcda _tls_no_ca + check_updtest TLS +} + +function test_tls_auth() { + # TLS/wss with client auth ============ + banner TLS/wss with client auth - Starting... + setup_A + setup_B + setup_C + + echo "v0" > _shome/version.txt + rm -f _shome/updtest.txt /tmp/update.bin + python test.py tls + banner TLS/wss with client auth - DONE + collect_gcda _tls_ca + check_updtest TLS +} + +test_plain +test_tls_noauth +test_tls_auth diff --git a/regr-tests/test4-cups/v1.bin b/regr-tests/test4-cups/v1.bin new file mode 100644 index 0000000..e7f0032 --- /dev/null +++ b/regr-tests/test4-cups/v1.bin @@ -0,0 +1,5 @@ +#!/bin/bash +echo "v1" > _shome/version.txt +echo $UPDTEST > _shome/updtest.txt +rm -f /tmp/update.bin +echo "update.bin: update completed" diff --git a/regr-tests/test4-cups/v1.bin.sig-0 b/regr-tests/test4-cups/v1.bin.sig-0 new file mode 100644 index 0000000000000000000000000000000000000000..ee953b1180926d77341837fb0145968c0be8727a GIT binary patch literal 72 zcmV-O0Jr}zMgk!KsLN%87uufi@7?eHvqftTmf6z{XWEA42Nw-05}~VE0wDm^M2++p erJ7Rh(~xE_JdA~#05;$S=)^yA7Ga%*GLrhui6Nx` literal 0 HcmV?d00001 diff --git a/regr-tests/test5-rmtsh/.gitignore b/regr-tests/test5-rmtsh/.gitignore new file mode 100644 index 0000000..13a4bf4 --- /dev/null +++ b/regr-tests/test5-rmtsh/.gitignore @@ -0,0 +1,6 @@ +tc-bak.* +test.txt +station.log +station.pid +spidev* +*.info diff --git a/regr-tests/test5-rmtsh/makefile b/regr-tests/test5-rmtsh/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test5-rmtsh/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test5-rmtsh/slave-0.conf b/regr-tests/test5-rmtsh/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test5-rmtsh/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test5-rmtsh/station.conf b/regr-tests/test5-rmtsh/station.conf new file mode 100644 index 0000000..d05cc6a --- /dev/null +++ b/regr-tests/test5-rmtsh/station.conf @@ -0,0 +1,35 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0, + "antenna_type": "omni" + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + /* "log_file": "station.log", */ + "log_file": "stderr", + "log_level": "DEBUG", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3, + /* required for success checks of tests */ + "nodc": true, + "CLASS_C_BACKOFF_BY": "100ms", + "CLASS_C_BACKOFF_MAX": 10 + } +} + diff --git a/regr-tests/test5-rmtsh/tc.uri b/regr-tests/test5-rmtsh/tc.uri new file mode 100644 index 0000000..22c178c --- /dev/null +++ b/regr-tests/test5-rmtsh/tc.uri @@ -0,0 +1 @@ +ws://localhost:6038 \ No newline at end of file diff --git a/regr-tests/test5-rmtsh/test.py b/regr-tests/test5-rmtsh/test.py new file mode 100644 index 0000000..4a98b0e --- /dev/null +++ b/regr-tests/test5-rmtsh/test.py @@ -0,0 +1,183 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +from pprint import pformat +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test5-rmtsh') + +import tcutils as tu +import simutils as su +import testutils as tstu + + +station = None +infos = None +muxs = None +sim = None + + +class TestMuxs(tu.Muxs): + exp_seqno = [] + seqno = 0 + ws = None + send_task = None + ev = None + rmtsh_status = None + rmtsh_status_ev = asyncio.Event() + output = b'' + + async def handle_connection(self, ws): + self.ws = ws + self.ev = asyncio.Event() + self.send_task = asyncio.ensure_future(self.run_rmtsh()) + await super().handle_connection(ws) + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + station = None + os._exit(status) + + async def handle_binaryData(self, ws, data): + if not data: + return + rmtsh_idx = data[0] + logger.debug('RMTSH %d binary data:<<<%s>>>' % (rmtsh_idx, data[1:].decode('utf-8'))) + self.output += data[1:] + #sys.stdout.write(data.decode('utf-8')) + #sys.stdout.flush() + + async def handle_rmtsh(self, ws, msg): + logger.debug('RMTSH: %s' % (pformat(msg),)) + self.rmtsh_status = msg['rmtsh'] + self.rmtsh_status_ev.set() + + async def waitForRmtshStatus(self): + self.rmtsh_status = None + self.rmtsh_status_ev.clear() + await asyncio.wait_for(self.rmtsh_status_ev.wait(), 3.0) + return self.rmtsh_status + + async def run_rmtsh(self): + try: + await asyncio.sleep(1.0) # let station start up + + dnmsg = {'msgtype':'rmtsh'} + await self.ws.send(json.dumps(dnmsg)) + await self.waitForRmtshStatus() + assert (self.rmtsh_status[0]['started'] == False and + self.rmtsh_status[1]['started'] == False) + + dnmsg = b'\x00Some stuff' + await self.ws.send(dnmsg) + await asyncio.sleep(1.0) + + dnmsg = {'msgtype':'rmtsh','start':0,'user':'Test session'} + await self.ws.send(json.dumps(dnmsg)) + await self.waitForRmtshStatus() + assert (self.rmtsh_status[0]['started'] == True and + self.rmtsh_status[1]['started'] == False) + assert self.rmtsh_status[0]['user'] == 'Test session' + + dnmsg = b'\x00ls\n' + await self.ws.send(dnmsg) + await asyncio.sleep(1.0) + assert b'spidev' in self.output + self.output = b'' + + txt = b'%f' % time.time() + dnmsg = b'\x00echo "%s" > test.txt; ls\n' % txt + await self.ws.send(dnmsg) + await asyncio.sleep(1.0) + assert b'test.txt' in self.output + self.output = b'' + with open('test.txt','rb') as f: + assert f.read() == txt+b'\n' + + dnmsg = {'msgtype':'rmtsh','stop':0} + await self.ws.send(json.dumps(dnmsg)) + await self.waitForRmtshStatus() + assert (self.rmtsh_status[0]['started'] == False and + self.rmtsh_status[1]['started'] == False) + assert self.rmtsh_status[0]['user'] == 'Test session' + + await asyncio.sleep(1.0) + + await self.ws.send(json.dumps({'msgtype':'rmtsh','start':1,'user':'Test2','term':'xterm','foo':2})) + await self.waitForRmtshStatus() + assert (self.rmtsh_status[0]['started'] == False and + self.rmtsh_status[1]['started'] == True) + + await self.ws.send(b'\x0Fls\n') + await self.ws.send(b'\x01head -c 1024 /dev/urandom | hd\n') + await asyncio.sleep(1.0) + + assert (self.rmtsh_status[0]['started'] == False and + self.rmtsh_status[1]['started'] == True) + + dnmsg = {'msgtype':'rmtsh','stop':1} + await self.ws.send(json.dumps(dnmsg)) + await self.waitForRmtshStatus() + assert (self.rmtsh_status[0]['started'] == False and + self.rmtsh_status[1]['started'] == False) + assert self.rmtsh_status[0]['user'] == 'Test session' + + await asyncio.sleep(1.0) + + await self.testDone(0) + except Exception as exc: + logger.error('run_rmtsh failed: %s', exc, exc_info=True) + await self.testDone(1) + + +async def test_start(): + global station, infos, muxs, sim + infos = tu.Infos() + muxs = TestMuxs() + sim = su.LgwSimServer() + + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + # 'valgrind', '--leak-check=full', + station_args = ['station','-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test5-rmtsh/test.sh b/regr-tests/test5-rmtsh/test.sh new file mode 100755 index 0000000..40e0a8c --- /dev/null +++ b/regr-tests/test5-rmtsh/test.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +python test.py +collect_gcda diff --git a/regr-tests/test5-runcmd/.gitignore b/regr-tests/test5-runcmd/.gitignore new file mode 100644 index 0000000..198bcaa --- /dev/null +++ b/regr-tests/test5-runcmd/.gitignore @@ -0,0 +1,7 @@ +tc-bak.* +station.log +station.pid +update.bin +tc.uri +cmd.fifo +*.info \ No newline at end of file diff --git a/regr-tests/test5-runcmd/cmd.sh b/regr-tests/test5-runcmd/cmd.sh new file mode 100755 index 0000000..d35eeac --- /dev/null +++ b/regr-tests/test5-runcmd/cmd.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "executable shell script $0 - $@" +echo '{"msgtype":"alarm","id":1}' > cmd.fifo diff --git a/regr-tests/test5-runcmd/cmd2.sh b/regr-tests/test5-runcmd/cmd2.sh new file mode 100644 index 0000000..62a01d7 --- /dev/null +++ b/regr-tests/test5-runcmd/cmd2.sh @@ -0,0 +1,4 @@ +set -e +echo "shell script $0 - $@" +echo '{"msgtype":"alarm","id":2}' > cmd.fifo + diff --git a/regr-tests/test5-runcmd/makefile b/regr-tests/test5-runcmd/makefile new file mode 100644 index 0000000..b79c084 --- /dev/null +++ b/regr-tests/test5-runcmd/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -f $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test5-runcmd/slave-0.conf b/regr-tests/test5-runcmd/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test5-runcmd/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test5-runcmd/slave.py b/regr-tests/test5-runcmd/slave.py new file mode 100644 index 0000000..d5faa23 --- /dev/null +++ b/regr-tests/test5-runcmd/slave.py @@ -0,0 +1,54 @@ + +import asyncio +import slaveutils as su + +slave = None + +class TestSlave(su.Slave): + txh = None + fcnt = 0 + expected_rctx = [0,1,2,3,4,5,10] + fail = False + + async def slave_eof(self): + pass + + async def ral_config(self, hwspec, config): + await super().ral_config(hwspec, config) + self.txh = asyncio.get_event_loop().call_later(1, self.send_updf) + + async def ral_tx(self, rctx, txpow_eirp, rps, freq, txtime, txdata): + await super().ral_tx(rctx, txpow_eirp, rps, freq, txtime, txdata) + rctx >>= 8 + if not self.expected_rctx or rctx != self.expected_rctx[0]: + print('UNEXPECTED: rctx=%r - expected: %r' % (rctx, self.expected_rctx)) + self.fail = True + else: + del self.expected_rctx[0] + + def send_updf(self): + print('PySlave - UPDF FCnt=%d' % (self.fcnt,)) + if self.fcnt < 5: + # First we're sending on 10% band and expect a reply for every frame + freq = 869.525 + port = 1 + elif self.fcnt < 10: + # Send on a .1% band - only 1st reply, other blocked by DC + freq = 867.100 + port = 2 + else: + freq = 869.525 + port = 3 if not self.fail else 4 # signal termination + self.send_rx(rctx=(self.fcnt<<8), freq=freq, rxdata=su.makeDF(fcnt=self.fcnt, port=port)) + self.fcnt += 1 + self.txh = asyncio.get_event_loop().call_later(1, self.send_updf) + + +async def test_start(): + global slave + slave = TestSlave() + await slave.start_slave() + + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test5-runcmd/station.conf b/regr-tests/test5-runcmd/station.conf new file mode 100644 index 0000000..5cb9aec --- /dev/null +++ b/regr-tests/test5-runcmd/station.conf @@ -0,0 +1,29 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1", + "log_file": "station.log", + "log_level": "VERBOSE", /* XDEBUG,DEBUG,VERBOSE,INFO,NOTICE,WARNING,ERROR,CRITICAL */ + "log_size": 10000000, + "log_rotate": 3 + } +} + diff --git a/regr-tests/test5-runcmd/test.py b/regr-tests/test5-runcmd/test.py new file mode 100644 index 0000000..9c20f42 --- /dev/null +++ b/regr-tests/test5-runcmd/test.py @@ -0,0 +1,158 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys +import time +import json +import asyncio +from asyncio import subprocess + +import logging +logger = logging.getLogger('test5-runcmd') + +import tcutils as tu +import simutils as su +import testutils as tstu + +station = None +infos = None +muxs = None +sim = None + + +class TestMuxs(tu.Muxs): + alarms = 0 + + async def testDone(self, status): + global station + if station: + station.terminate() + await station.wait() + logger.debug('Station exe code:%d' % (station.returncode,)) + station = None + logger.debug('Test Done: %d' % (status,)) + os._exit(status) + + def get_router_config(self): + return { + **self.router_config, + 'MuxTime': time.time(), + 'nodc': True, + 'nocca': True, + 'nodwell': True, + } + + async def handle_connection(self, ws): + asyncio.ensure_future(self.send_test_runcmd(ws)) + await super().handle_connection(ws) + + + async def send_test_runcmd(self, ws): + try: + await ws.send(json.dumps({ + # 'msgtype' : 'runcmd', # no msgtype + 'arguments': ["1", "2"], + 'superfluous_filed': 1 + })) + await ws.send(json.dumps({ + 'msgtype' : 'unknown_msgtype', # unknown msgtype + 'arguments': ["1", "2"], + 'superfluous_filed': 1 + })) + await ws.send(json.dumps({ + 'msgtype' : 'runcmd', + # 'command' : 'echo "Inline script - $TEST - $@"', # command missing + 'arguments': ["1", "2"], + 'superfluous_filed': 1 + })) + await ws.send(json.dumps({ + 'msgtype' : 'runcmd', + 'command' : 'echo "DEBUG" > cmd.fifo', + })) + runcmd = { + 'msgtype' : 'runcmd', + 'command' : 'echo "Inline script - $TEST - $@"', + 'arguments': ['x11','x22','x33'] + } + await ws.send(json.dumps(runcmd)) + await asyncio.sleep(1) + + runcmd = { + 'msgtype' : 'runcmd', + 'command' : './cmd.sh', + 'arguments': ['a11','a22','a33'] + } + await ws.send(json.dumps(runcmd)) + await asyncio.sleep(1) + + runcmd = { + 'msgtype' : 'runcmd', + 'command' : 'cmd2.sh', + 'arguments': ['b11','b22','b33'] + } + await ws.send(json.dumps(runcmd)) + await asyncio.sleep(4) + + await self.testDone(0 if self.alarms==3 else 1) + + except Exception as exc: + logger.error('send_test_runcmd exception: %s', exc, exc_info=True) + raise + + + async def handle_alarm(self, ws, msg): + logger.debug('MUXS alarm: %r' % (msg,)) + self.alarms |= msg.get('id',0) + + +with open("tc.uri","w") as f: + f.write('ws://localhost:6038') + + +async def timeout(): + await asyncio.sleep(20) + await muxs.testDone(2) + + +async def test_start(): + global station, infos, muxs + infos = tu.Infos() + muxs = TestMuxs() + sim = su.LgwSimServer() + await infos.start_server() + await muxs.start_server() + await sim.start_server() + + station_args = ['station', '-p', '--temp', '.'] + station = await subprocess.create_subprocess_exec(*station_args) + + asyncio.ensure_future(timeout()) + +tstu.setup_logging() + +asyncio.ensure_future(test_start()) +asyncio.get_event_loop().run_forever() diff --git a/regr-tests/test5-runcmd/test.sh b/regr-tests/test5-runcmd/test.sh new file mode 100755 index 0000000..8e506f9 --- /dev/null +++ b/regr-tests/test5-runcmd/test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +. ../testlib.sh + +[[ -p cmd.fifo ]] || mkfifo cmd.fifo + +# When station starts up and finds update.bin - run it! +banner TCP/ws - start... +export TEST='++Test++' +cp update_bin /tmp/update.bin +chmod +x /tmp/update.bin +python test.py +banner TCP/ws - done +collect_gcda _tcp_ws + +set -x +grep 'update.bin done' station.log +[ ! -f update.bin ] +grep 'Inline script - ++Test++ - x11 x22 x33' station.log +grep 'executable shell script ./cmd.sh - a11 a22 a33' station.log +grep 'shell script cmd2.sh - cmd2.sh b11 b22 b33' station.log +set +x diff --git a/regr-tests/test5-runcmd/update_bin b/regr-tests/test5-runcmd/update_bin new file mode 100644 index 0000000..fc820d2 --- /dev/null +++ b/regr-tests/test5-runcmd/update_bin @@ -0,0 +1,6 @@ +#!/bin/bash +set -e +echo "Firmware update..." +echo "Removing $0" +rm $0 +echo "--- update.bin done ---" diff --git a/regr-tests/test7-respawn/.gitignore b/regr-tests/test7-respawn/.gitignore new file mode 100644 index 0000000..0489ee9 --- /dev/null +++ b/regr-tests/test7-respawn/.gitignore @@ -0,0 +1,5 @@ +*.info +tc.uri +tc-bak* +station.pid +station.log diff --git a/regr-tests/test7-respawn/makefile b/regr-tests/test7-respawn/makefile new file mode 100644 index 0000000..be592b7 --- /dev/null +++ b/regr-tests/test7-respawn/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -rf $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test7-respawn/slave-0.conf b/regr-tests/test7-respawn/slave-0.conf new file mode 100644 index 0000000..311847d --- /dev/null +++ b/regr-tests/test7-respawn/slave-0.conf @@ -0,0 +1,2 @@ +{} + diff --git a/regr-tests/test7-respawn/station.conf b/regr-tests/test7-respawn/station.conf new file mode 100644 index 0000000..2ca3ae9 --- /dev/null +++ b/regr-tests/test7-respawn/station.conf @@ -0,0 +1,25 @@ +{ + /* If slave-X.conf present this acts as default settings */ + "SX1301_conf": { /* Actual channel plan is controlled by server */ + "lorawan_public": true, /* is default */ + "clksrc": 1, /* radio_1 provides clock to concentrator */ + "device": "spidev", + "radio_0": { + /* freq/enable provided by LNS - only HW specific settings listed here */ + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": true, + "antenna_gain": 0 + }, + "radio_1": { + "type": "SX1257", + "rssi_offset": -166.0, + "tx_enable": false + } + /* chan_multiSF_X, chan_Lora_std, chan_FSK provided by LNS */ + }, + "station_conf": { + "routerid": "::1" + } +} + diff --git a/regr-tests/test7-respawn/test.sh b/regr-tests/test7-respawn/test.sh new file mode 100755 index 0000000..3a16cfc --- /dev/null +++ b/regr-tests/test7-respawn/test.sh @@ -0,0 +1,125 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +function workerPid () { + # Process started by daemon to do the work + # - All station processes + # - the one whose parent pid is not 1 + # - column 2 is pid + local pid=$(cat station.pid) + ps -eo ppid,pid,pgid,command | \ + grep 'station[ ]' | \ + grep -P "^ *$pid " | \ + awk '{print $2}' +} +function validatePid () { + # Make sure all running processes named station and /proc/self/exe (slave procs) + # match all processes in process group listed in station.pid + local pid=$(cat station.pid) + cmp <(ps -eo pid,ppid,pgid,command | grep -P "station[ ]|/proc/self/ex[e]") \ + <(ps -eo pid,ppid,pgid,command | grep "$pid[ ]") +} + + +# Startup fails - no uri files +rm -f *.uri +if station --temp . -d; then + echo "Should have failed" + exit 1 +else + xcode=$? + [ $xcode -eq 1 ] || (echo "Should have failed with exit code 1: $xcode"; exit 1) +fi + +collect_gcda _notcuri + +echo "ws://localhost:6038" > tc.uri + +# No other station running - start new daemon +rm -f station.log +banner 'Starting first daemon' +station --temp . -d +sleep 0.5 +pid=$(cat station.pid) +echo "Daemon station.pid=$pid" +validatePid + +collect_gcda _1 + +# No other station running - start new daemon +banner 'Trying to start 2nd daemon (no force)' +if station --temp . -d; then + echo "ERROR: Should not succeed starting another daemon" + exit 1 +else + xcode=$? + if [[ $xcode -ne 6 ]]; then + echo "ERROR: Wrong exit code: $xcode" + exit 1 + fi +fi + +wpid=$(workerPid) +grep "$wpid started" station.log || (echo "Missing wpid: $wpid started"; exit 1) + +collect_gcda _2 + +# Force start - kill old daemon +banner 'Trying to start 3rd daemon with force - kill old one' +pid=$(cat station.pid) +echo " - old pid=$pid" +station --temp . -d -f +sleep 0.5 +validatePid + +if (ps -eo pid,ppid,pgid,command | grep "$pid[ ]"); then + echo "ERROR: old daemon pid=$pid still around!" + exit 1 +fi + +wpid1=$(workerPid) +banner "Kill worker process $wpid1" +kill -9 $wpid1 +sleep 2 # wait for restart +wpid2=$(workerPid) + +grep "$wpid1 died" station.log || (echo "Missing wpid1: $wpid1 died"; exit 1) +grep "$wpid2 started" station.log || (echo "Missing wpid2: $wpid2 started"; exit 1) + + +# Kill process group +banner 'Kill daemon process group' +([ -f station.pid ] && kill -9 -- -$(cat station.pid)) || true +if (ps -eo pid,ppid,pgid,command | grep "station[ ]"); then + echo "Kill process group failed" + exit 1 +fi + +collect_gcda _f diff --git a/regr-tests/test8-web/.gitignore b/regr-tests/test8-web/.gitignore new file mode 100644 index 0000000..eda163d --- /dev/null +++ b/regr-tests/test8-web/.gitignore @@ -0,0 +1,2 @@ +station.log +*.info diff --git a/regr-tests/test8-web/makefile b/regr-tests/test8-web/makefile new file mode 100644 index 0000000..be592b7 --- /dev/null +++ b/regr-tests/test8-web/makefile @@ -0,0 +1,33 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +all: + ./test.sh + +clean: + rm -rf $$(cat .gitignore) + +.PHONY: all clean diff --git a/regr-tests/test8-web/ref.400 b/regr-tests/test8-web/ref.400 new file mode 100644 index 0000000..dae0431 --- /dev/null +++ b/regr-tests/test8-web/ref.400 @@ -0,0 +1,2 @@ +HTTP/1.1 400 Bad Request + diff --git a/regr-tests/test8-web/ref.404 b/regr-tests/test8-web/ref.404 new file mode 100644 index 0000000..8182e74 --- /dev/null +++ b/regr-tests/test8-web/ref.404 @@ -0,0 +1,3 @@ +HTTP/1.1 404 Not Found + +Resource not found! diff --git a/regr-tests/test8-web/ref.405 b/regr-tests/test8-web/ref.405 new file mode 100644 index 0000000..164f63c --- /dev/null +++ b/regr-tests/test8-web/ref.405 @@ -0,0 +1,2 @@ +HTTP/1.1 405 Method Not Allowed + diff --git a/regr-tests/test8-web/ref.a b/regr-tests/test8-web/ref.a new file mode 100644 index 0000000..72a2046 --- /dev/null +++ b/regr-tests/test8-web/ref.a @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Type: application/octet-stream +Content-Encoding: identity + +This is A diff --git a/regr-tests/test8-web/ref.empty b/regr-tests/test8-web/ref.empty new file mode 100644 index 0000000..e69de29 diff --git a/regr-tests/test8-web/ref.index.html b/regr-tests/test8-web/ref.index.html new file mode 100644 index 0000000..e8e5794 --- /dev/null +++ b/regr-tests/test8-web/ref.index.html @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Type: text/html +Content-Encoding: identity + +Hello index diff --git a/regr-tests/test8-web/ref.sub.b.txt b/regr-tests/test8-web/ref.sub.b.txt new file mode 100644 index 0000000..a7cdcdc --- /dev/null +++ b/regr-tests/test8-web/ref.sub.b.txt @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Type: text/plain +Content-Encoding: identity + +B test file diff --git a/regr-tests/test8-web/ref.test.js b/regr-tests/test8-web/ref.test.js new file mode 100644 index 0000000..f5a29a6 --- /dev/null +++ b/regr-tests/test8-web/ref.test.js @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Type: application/javascript +Content-Encoding: identity + +function () {} diff --git a/regr-tests/test8-web/ref.test.json b/regr-tests/test8-web/ref.test.json new file mode 100644 index 0000000..650660b --- /dev/null +++ b/regr-tests/test8-web/ref.test.json @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Type: application/json +Content-Encoding: identity + +{"abc":123} diff --git a/regr-tests/test8-web/ref.toobig.gz b/regr-tests/test8-web/ref.toobig.gz new file mode 100644 index 0000000..338edcb --- /dev/null +++ b/regr-tests/test8-web/ref.toobig.gz @@ -0,0 +1,3 @@ +HTTP/1.1 507 Insufficient Storage + +Resource too big! diff --git a/regr-tests/test8-web/slave-0.conf b/regr-tests/test8-web/slave-0.conf new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/regr-tests/test8-web/slave-0.conf @@ -0,0 +1 @@ +{} diff --git a/regr-tests/test8-web/station.conf b/regr-tests/test8-web/station.conf new file mode 100644 index 0000000..afeaff9 --- /dev/null +++ b/regr-tests/test8-web/station.conf @@ -0,0 +1,8 @@ +{ + "station_conf": { + "web_port": 8080, + "web_dir": "web", + "log_level": "DEBUG" + } +} + diff --git a/regr-tests/test8-web/tc.uri b/regr-tests/test8-web/tc.uri new file mode 100644 index 0000000..e7fc2bc --- /dev/null +++ b/regr-tests/test8-web/tc.uri @@ -0,0 +1 @@ +ws://clc1.trackio.ch:7000 diff --git a/regr-tests/test8-web/test.sh b/regr-tests/test8-web/test.sh new file mode 100755 index 0000000..b5ece18 --- /dev/null +++ b/regr-tests/test8-web/test.sh @@ -0,0 +1,133 @@ +#!/bin/bash + +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +. ../testlib.sh + +function curlit () { + # $1 -> allow empty responses + local path=$2 + local ref=ref.$(echo $path | tr / .) + local msg=" CURL $path vs $ref" + local resp=`curl --noproxy 127.0.0.1 -sD - http://127.0.0.1:8080/$path` + if [ "$resp" != "" ]; then + echo "$resp" | diff - $ref \ + || (echo "[FAILED] $msg" && (cat station.log) && false) + else + echo "[WRN] Empty response to $path" && $1 + fi +} + +export -f curlit # make function available to GNU parallel + +station -k +station --temp . -f -L station.log -l DEBUG & +sleep 1 + +echo "---- Testing Proper HTTP Requests" + +TFILES="test.js test.json a sub/b.txt 404" + +for f in $TFILES; do + curlit false $f +done + +curl --noproxy 127.0.0.1 -sD - http://127.0.0.1:8080/config -o /dev/null +curl --noproxy 127.0.0.1 -sD - -X POST http://127.0.0.1:8080/config -o /dev/null +curl --noproxy 127.0.0.1 -sD - http://127.0.0.1:8080/version -o /dev/null +curl --noproxy 127.0.0.1 -sD - -X POST http://127.0.0.1:8080/version -o /dev/null +curl --noproxy 127.0.0.1 -sD - http://127.0.0.1:8080/api -o /dev/null + + +echo "---- Testing Big Resource HTTP Requests" +head -c 60k /dev/urandom | gzip > web/toobig.gz +curlit false toobig.gz +rm web/toobig.gz + +echo "---- Testing Broken HTTP Requests" + +REQLIST=( +"GET /a HTTP/1.1\r\nHost: localhost:8080\r\nAccept: */*\r\n\r\n~~~ref.a" +"GET / HTTP/1.1\r\nAuthorization: xxxxxxxxxxxxxxxxxx\r\n\r\n~~~~~~ref.index.html" +"GET / HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.index.html" +"GET /index.html HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.index.html" +"GET /sub/b.txt HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.sub.b.txt" +"POST SCHMUTZ HTPP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"POST_/SCHMUTZ HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"POST SCHMUTZ HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"GET / HTTP//1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"GET / HTTP/1.1 \r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"GET /\n HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"GET /\n\r HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.400" +"GET /not_existing_file HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~ref.404" +"POST /version HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.405" +"POP /version HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.405" +"VERYLONGMETHOD1_@!#_!@# /version HTTP/1.1\r\n\r\n~~~~~~~~~~~~~~~~ref.405" +"GET / HTTP/1.1\r\n \r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.empty" +"GET / HTTP/1.1\n\r\n\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.empty" +"GET\0 HTTP/1.1\n\r\n\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.empty" +"SCHMUTZ SCHMUTZ SCHMUTZ\rSCHMUTZ\nSCHMUTZ\r\n~~~~~~~~~~~~~~~~~~~~ref.empty" +"SCHMUTZ SCHMUTZ SCHMUTZ\r\n\r\nSCHMUTZ\nSCHMUTZ~~~~~~~~~~~~~~~~~~ref.empty" +"\r\n\r\nSCHMUTZ SCHMUTZ SCHMUTZ\r\n\r\nSCHMUTZ\nSCHMUTZ~~~~~~~~~~ref.empty" +"\r\n\r\nSCHMUTZ\0SCHMUTZ SCHMUTZ\r\0\n\r\nSCHMUTZ\nSCHMUTZ~~~~~~~ref.empty" +"\\//\/\../\\/..//\/\/./\.\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ref.empty" +) + +NREQ=${#REQLIST[@]} +ROUNDS=1500 + +function ncit () { + # $1 -> allow empty responses + local REQ="${2%%~*}" + local REF="${2##*~}" + local resp="`printf "$REQ" | nc -N 127.0.0.1 8080`" + if [ "$resp" == "" ] && [ "$REF" != "ref.empty" ]; then + echo "[WRN] Unexpected empty response to $REQ -> expected $REF" && $1 + else + diff <(echo -n "$resp") <( echo -n "`cat $REF`" ) \ + || (echo "[FAILED] $REQ -> $REF" && false) + fi +} + +export -f ncit # make function available to GNU parallel + +for ((n=0;n<$ROUNDS;n++)); do + RND=$((RANDOM%NREQ)) + ncit false "${REQLIST[$RND]}" +done + +# echo "---- Testing Parallel HTTP Requests" + +# parallel --halt now,fail=1 curlit true ::: `printf "$TFILES %.0s" {1..100}` +# for k in `shuf -i 0-$((NREQ-1)) -n $ROUNDS -r`; do echo ${REQLIST[$k]}; done \ +# | parallel --halt now,fail=1 ncit true + +kill -SIGTERM $(cat station.pid) + +sleep 0.5 + +collect_gcda _web diff --git a/regr-tests/test8-web/web/a b/regr-tests/test8-web/web/a new file mode 100644 index 0000000..e32836f --- /dev/null +++ b/regr-tests/test8-web/web/a @@ -0,0 +1 @@ +This is A diff --git a/regr-tests/test8-web/web/index.html b/regr-tests/test8-web/web/index.html new file mode 100644 index 0000000..60f9f6a --- /dev/null +++ b/regr-tests/test8-web/web/index.html @@ -0,0 +1 @@ +Hello index diff --git a/regr-tests/test8-web/web/sub/b.txt b/regr-tests/test8-web/web/sub/b.txt new file mode 100644 index 0000000..b3d640a --- /dev/null +++ b/regr-tests/test8-web/web/sub/b.txt @@ -0,0 +1 @@ +B test file diff --git a/regr-tests/test8-web/web/test.js b/regr-tests/test8-web/web/test.js new file mode 100644 index 0000000..6c53273 --- /dev/null +++ b/regr-tests/test8-web/web/test.js @@ -0,0 +1 @@ +function () {} diff --git a/regr-tests/test8-web/web/test.json b/regr-tests/test8-web/web/test.json new file mode 100644 index 0000000..0e04079 --- /dev/null +++ b/regr-tests/test8-web/web/test.json @@ -0,0 +1 @@ +{"abc":123} diff --git a/regr-tests/testlib.sh b/regr-tests/testlib.sh new file mode 100644 index 0000000..c4e2723 --- /dev/null +++ b/regr-tests/testlib.sh @@ -0,0 +1,130 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set -e + +R=$(echo -e "\033[31m") # red +G=$(echo -e "\033[32m") # green +B=$(echo -e "\033[34m") # blue +HB=$(echo -e "\033[30;43m") # b/f reversed - headline +X=$(echo -e "\033[0m") + +TD=${TDfull:-../..} +export TEST_VARIANT=${TEST_VARIANT:-testsim} +export BUILD_DIR=${TD}/build-${platform:-linux}-${TEST_VARIANT} + +export PATH=$BUILD_DIR/bin:$PATH +# export PYTHONPATH=${TD}/regr-tests/pysys:..:$PYTHONPATH +export PYTHONPATH=${TD}/pysys:$PYTHONPATH + +TEST_NAME=$(basename $(dirname $(realpath $0))) + +# Cleanup any coverage file +GCDA_DIR=$BUILD_DIR/s2core +rm -f $GCDA_DIR/*.gcda + +function collect_gcda () { + echo "Collecting GCDA from $GCDA_DIR into $TEST_VARIANT$1.info" + lcov -c -d $GCDA_DIR -o $TEST_VARIANT$1.info + rm -f $GCDA_DIR/*.gcda +} + +function disable_test () { + # run-regression-tests will check ..N/A.. marker if we fail + banner "--- Test N/A --- temporarily ${1:-disabled}" + exit 1 +} + +function banner () { + s="======================================================================" + echo -e "\n${s}\n${HB}[${TEST_NAME}]${X} -- ${HB}${@}${X}\n${s}\n" +} + +function default_cleanup () { + echo "Default cleanup..." + exec 1>/dev/null 2>&1 # hide noisy output + # Kill any station process + killall -q station || true + sleep 1 + killall -q -s9 station || true + # Kill any other processes related to test script + pids="$timerpid $(jobs -p)" + kill $pids || true + sleep 1 + kill -9 $pids || true + # Remove files unless requested to keep them + if [[ $keep_files = 0 ]]; then + rm -rf $(cat .gitignore | grep -v '\.info$') || true + fi + exec 1>&3 2>&4 # restore stdout.stderr for caller +} +# typically overwritten in script +if [[ "$(type -t cleanup)" = "" ]]; then + # If not overriden by sourceing test script + function cleanup () { + default_cleanup + } +fi + +if [[ "$IGNORE" != "" ]] && [[ "$TEST_NAME" =~ $IGNORE ]]; then + disable_test ignored + exit 1 +fi + +trap cleanup EXIT +exec 3>&1 4>&2 # save stdout/stderr +cleanup + +# Start after cleasnup - otherwise timerpid is killed immediately +testpid=$$ +timeout=${timeout:-120} +echo "Timeout is ${timeout}s on PID $testpid" + +if [[ "$timeout" != "" ]]; then + (cnt=0 + while ((cnt++ < $timeout)); do + sleep 1; + if [[ ! -d /proc/$timeout ]]; then + exit 0 + fi + done + echo -e "\n\n${R}${TEST_NAME} - Timeout - KILLING $testpid!${X}" >&3 + kill $testpid + ) & + timerpid=$! +fi + +# ------------------------------------------------------------ +# if 1st argument is +# --keep +# then don't delete .gitignore files +# +keep_files=0 +if [[ "$1" == "--keep" ]]; then + shift + keep_files=1 +fi + diff --git a/setup.gmk b/setup.gmk index a4ccfae..a123556 100644 --- a/setup.gmk +++ b/setup.gmk @@ -1,3 +1,27 @@ +# --- Revised 3-Clause BSD License --- +# Copyright Semtech Corporation 2020. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of the Semtech corporation nor the names of its +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # -*- makefile -*- # Top dir of s2core @@ -17,6 +41,9 @@ variant ?= std LOCAL_ARCH := $(shell gcc -dumpmachine) ARCH.linux = x86_64-linux-gnu +ARCH.linuxV2 = x86_64-linux-gnu +ARCH.linuxpico = x86_64-linux-gnu +ARCH.corecell = arm-linux-gnueabihf ARCH.rpi = arm-linux-gnueabihf ARCH.kerlink = arm-klk-linux-gnueabi ARCH=${ARCH.${platform}} @@ -38,17 +65,18 @@ else TOOLPREFIX=${TOOLCHAIN}/bin/${ARCH}- endif -ifeq (kerlink,${platform}) -# Needed for loader to find libmpfr.so.4 -export LD_LIBRARY_PATH=${TOOLCHAIN}/usr/lib -endif - CC=${TOOLPREFIX}gcc LD=${TOOLPREFIX}ld AR=${TOOLPREFIX}ar OD=${TOOLPREFIX}objdump OC=${TOOLPREFIX}objcopy +ifeq (kerlink,${platform}) +# Needed for loader to find libmpfr.so.4 +export LD_LIBRARY_PATH=${TOOLCHAIN}/usr/lib +endif + + # Everything being build is somewhere in here BD=build-${platform}-${variant} @@ -70,6 +98,9 @@ CFG.debugn = logini_lvl=DEBUG selftests tlsdebug ral_master_slave # -- Platform specific CFG.linux = linux lgw1 no_leds +CFG.linuxpico = linux lgw1 no_leds smtcpico +CFG.linuxV2 = linux lgw2 no_leds lgw2genkey +CFG.corecell = linux lgw1 no_leds sx1302 CFG.rpi = linux lgw1 no_leds CFG.kerlink = linux lgw1 no_leds @@ -82,6 +113,9 @@ UTILS.linux = mtuns UTILS = $(or ${UTILS.${platform}}, ${UTILS.default}) DEPS.default = mbedtls lgw +DEPS.linuxpico = mbedtls smtcpico +DEPS.linuxV2 = mbedtls lgw2 +DEPS.corecell = mbedtls lgw1302 DEPS.rpi = mbedtls lgw DEPS = $(or ${DEPS.${platform}}, ${DEPS.default}) @@ -98,6 +132,9 @@ ifneq (minihub,$(platform)) SYSLIBS = -lm endif +CFLAGS.linuxpico.debug = -g -O0 +CFLAGS.corecell.debug = -g -O0 +CFLAGS.linuxpico.debugn = -g -O0 CFLAGS.linux.testsim = -g -O0 --coverage CFLAGS.linux.testms = -g -O0 --coverage CFLAGS.linux.testfs = -g -O0 --coverage @@ -105,6 +142,9 @@ CFLAGS.linux.testpin = -g -O3 CFLAGS.linux.std = -g -O3 LIBS.linux = -llgw ${MBEDLIBS} -lpthread +LIBS.linuxV2 = -llgw2 ${MBEDLIBS} -lrt -lpthread -lspi +LIBS.linuxpico = -llgw ${MBEDLIBS} -lpthread +LIBS.corecell = -llgw1302 ${MBEDLIBS} -lpthread -lrt LIBS.rpi = -llgw ${MBEDLIBS} -lpthread LIBS.kerlink = -llgw ${MBEDLIBS} -lrt -lpthread diff --git a/src-linux/cmdfifo.c b/src-linux/cmdfifo.c index caea36f..69609bf 100644 --- a/src-linux/cmdfifo.c +++ b/src-linux/cmdfifo.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_linux) @@ -135,7 +134,7 @@ static int fifo_reopen () { } if( stat(fifo, &st) == -1 || (st.st_mode & S_IFMT) != S_IFIFO ) return 0; // no such file or not a FIFO - if( (fd = open(fifo, O_RDONLY | O_NONBLOCK)) == -1 ) { + if( (fd = open(fifo, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1 ) { LOG(ERROR, "Failed to open cmd FIFO '%s': %s", fifo, strerror(errno)); return 0; } diff --git a/src-linux/commands.c b/src-linux/commands.c index 3352e36..028a27f 100644 --- a/src-linux/commands.c +++ b/src-linux/commands.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/src-linux/gps.c b/src-linux/gps.c index 92bdcf2..1f2179b 100644 --- a/src-linux/gps.c +++ b/src-linux/gps.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_nogps) @@ -44,11 +43,15 @@ int sys_enableGPS (str_t _device) { #include #include -#include "s2conf.h" #include "rt.h" -#include "tc.h" #include "sys_linux.h" +#include "s2e.h" +#include "tc.h" + +#include "sys.h" +#include "s2conf.h" + #if defined(CFG_ubx) // We don't need UBX to operate station - we get time from server @@ -214,26 +217,108 @@ static int send_alarm (str_t fmt, ...) { } +str_t GPSEV_MOVE = "move"; +str_t GPSEV_FIX = "fix"; +str_t GPSEV_NOFIX = "nofix"; + +static int send_gpsev_fix(str_t gpsev, float lat, float lon, float alt, float dilution, int satellites, int quality, float from_lat, float from_lon) { + assert(gpsev == GPSEV_MOVE || gpsev == GPSEV_FIX || gpsev == GPSEV_NOFIX); + ujbuf_t sendbuf = (*TC->s2ctx.getSendbuf)(&TC->s2ctx, MIN_UPJSON_SIZE); + if( sendbuf.buf == NULL ) { + LOG(MOD_S2E|ERROR, "Failed to send gps event, no buffer space"); + return 0; + } + uj_encOpen(&sendbuf, '{'); + uj_encKVn(&sendbuf, + "msgtype", 's', "event", + "evcat", 's', "gps", + "evmsg", '{', + /**/ "evtype", 's', gpsev, + /**/ "lat", 'g', lat, + /**/ "lon", 'g', lon, + /**/ "alt", 'g', alt, + /**/ "dilution", 'g', dilution, + /**/ "satellites", 'i', satellites, + /**/ "quality", 'i', quality, + "}", + NULL); + uj_encClose(&sendbuf, '}'); + (*TC->s2ctx.sendText)(&TC->s2ctx, &sendbuf); + + if( gpsev == GPSEV_FIX ) { + LOG(MOD_GPS|INFO, "GPS fix: %.7f,%.7f alt=%.1f dilution=%f satellites=%d quality=%d", + lat, lon, alt, dilution, satellites, quality); + return send_alarm("{\"msgtype\":\"alarm\"," + "\"text\":\"GPS fix: %.7f,%.7f alt=%.1f dilution=%f satellites=%d quality=%d\"}", + lat, lon, alt, dilution, satellites, quality); + } else { + LOG(MOD_GPS|INFO, "GPS move %.7f,%.7f => %.7f,%.7f (alt=%.1f dilution=%f satellites=%d quality=%d)", + from_lat, from_lon, lat, lon, alt, dilution, satellites, quality); + return send_alarm("{\"msgtype\":\"alarm\"," + "\"text\":\"GPS move %.7f,%.7f => %.7f,%.7f (alt=%.1f dilution=%f satellites=%d quality=%d)\"}", + from_lat, from_lon, lat,lon, alt, dilution, satellites, quality); + } +} + + +static int send_gpsev_nofix(ustime_t since) { + ujbuf_t sendbuf = (*TC->s2ctx.getSendbuf)(&TC->s2ctx, MIN_UPJSON_SIZE); + if( sendbuf.buf == NULL ) { + LOG(MOD_S2E|ERROR, "Failed to send gps event', no buffer space"); + return 0; + } + uj_encOpen(&sendbuf, '{'); + uj_encKVn(&sendbuf, + "msgtype", 's', "event", + "evcat", 's', "gps", + "evmsg", '{', + /**/ "evtype", 's', GPSEV_NOFIX, + /**/ "since", 'I', since, + "}", + NULL); + uj_encClose(&sendbuf, '}'); + (*TC->s2ctx.sendText)(&TC->s2ctx, &sendbuf); + + LOG(MOD_GPS|INFO, "GPS nofix: since %~T", since); + + return send_alarm("{\"msgtype\":\"alarm\"," + "\"text\":\"No GPS fix since %~T\"}", since); +} + + + + +static float nmea_p2dec(float lat, char d) { + s4_t dd = (s4_t)(lat/100); + float ss = lat - dd * 100; + float dec = (ss/60.0 + dd); + return (d == 'S' || d == 'W') ? (-1 * dec) : dec; +} + + static void nmea_gga (char* p) { double time_of_fix, lat, lon, dilution, alt; char *latD, *lonD; + char *pp = p; sL_t quality, satellites; if( !nmea_float (&p, &time_of_fix) || - !nmea_float (&p, &lat) || - !nmea_str (&p, 1, &latD) || - !nmea_float (&p, &lon) || - !nmea_str (&p, 1, &lonD) || - !nmea_decimal(&p, &quality) || - !nmea_decimal(&p, &satellites) || - !nmea_float (&p, &dilution) || - !nmea_float (&p, &alt) ) { - LOG(MOD_GPS|ERROR, "Failed to parse GPS GGA sentence: %s", p); + !nmea_float (&p, &lat ) || + !nmea_str (&p, 1, &latD ) || + !nmea_float (&p, &lon ) || + !nmea_str (&p, 1, &lonD ) || + !nmea_decimal(&p, &quality ) || + !nmea_decimal(&p, &satellites ) || + !nmea_float (&p, &dilution ) || + !nmea_float (&p, &alt )) { + int len = 0; + while (pp[len]>31 && pp[len]<128 && ++len ); + LOG(MOD_GPS|ERROR, "Failed to parse GPS GGA sentence: (len=%d) %.*s", len, len, pp); return; } - s4_t lati = (s4_t)lat/100; - lat = (latD[0] == 'E' ? -1 : 1) * lati + (lat - lati*100)/60.0; - s4_t loni = (s4_t)lon/100; - lon = (lonD[0] == 'S' ? -1 : 1) * loni + (lon - loni*100)/60.0; + + lat = nmea_p2dec(lat, latD[0]); + lon = nmea_p2dec(lon, lonD[0]); + LOG(MOD_GPS|XDEBUG, "nmea_gga: lat %f, lon %f", lat, lon); if( (quality == 0) ^ (last_quality == 0) ) time_fixchange = rt_getTime(); @@ -241,18 +326,22 @@ static void nmea_gga (char* p) { int fix = (quality == 0 ? -1 : 1); ustime_t now = rt_getTime(); ustime_t delay = GPS_REPORT_DELAY; + + //if (fix > 0) { + // send_gpsev_fix(GPSEV_FIX, lat, lon, alt, dilution, satellites, quality, 0.0, 0.0); + //} else { + // send_gpsev_nofix(0); + //} + if( last_reported_fix <= 0 && fix > 0 && now > time_fixchange + delay && - send_alarm("{\"msgtype\":\"alarm\"," - "\"text\":\"GPS fix: %.7f,%.7f alt=%.1f dilution=%f satellites=%d quality=%d\"}", - lat, lon, alt, dilution, satellites, quality) ) { + send_gpsev_fix(GPSEV_FIX, lat, lon, alt, dilution, satellites, quality, 0.0, 0.0)) { last_reported_fix = fix; nofix_backoff = 0; } if( fix < 0 ) { ustime_t thres = time_fixchange + (1< thres && - send_alarm("{\"msgtype\":\"alarm\"," - "\"text\":\"No GPS fix since %~T\"}", time_fixchange-now) ){ + send_gpsev_nofix(time_fixchange-now)) { last_reported_fix = fix; nofix_backoff = max(nofix_backoff+1, 16); } @@ -260,7 +349,7 @@ static void nmea_gga (char* p) { if( quality > 0 ) { if( check_tolerance(orig_lat, lat, 0.001) || - check_tolerance(orig_lon, lon, 0.002) ) { + check_tolerance(orig_lon, lon, 0.001) ) { // GW changed position char json[100]; dbuf_t jbuf = dbuf_ini(json); @@ -282,10 +371,14 @@ static void nmea_gga (char* p) { last_quality = quality; if( report_move && - send_alarm("{\"msgtype\":\"alarm\"," - "\"text\":\"GPS move %.7f,%.7f => %.7f,%.7f (alt=%.1f dilution=%f satellites=%d quality=%d)\"}", - from_lat, from_lon, orig_lat, orig_lon, alt, dilution, satellites, quality) ) { + send_gpsev_fix(GPSEV_MOVE, lat, lon, alt, dilution, satellites, quality, from_lon, from_lon)) { + //send_alarm("{\"msgtype\":\"alarm\"," + //"\"text\":\"GPS move %.7f,%.7f => %.7f,%.7f (alt=%.1f dilution=%f satellites=%d quality=%d)\"}", + // from_lat, from_lon, orig_lat, orig_lon, alt, dilution, satellites, quality) ) { report_move = 0; + //LOG(MOD_GPS|INFO, "GPS move %.7f,%.7f => %.7f,%.7f (alt=%.1f dilution=%f satellites=%d quality=%d)", + // from_lat, from_lon, orig_lat, orig_lon, alt, dilution, satellites, quality); + } } @@ -479,6 +572,13 @@ static int gps_reopen () { } +int sys_getLatLon (double* lat, double* lon) { + *lat = orig_lat; + *lon = orig_lon; + return 1; +} + + // // NOTE: Reading NMEA sentences from a GPS device is not used to sync time in any way. // This information is only indicative of having a fix (and how good) and is used to @@ -521,3 +621,4 @@ int sys_enableGPS (str_t _device) { } #endif + diff --git a/src-linux/leds.c b/src-linux/leds.c index c97113a..9690d8b 100644 --- a/src-linux/leds.c +++ b/src-linux/leds.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "sys.h" diff --git a/src-linux/ral_master.c b/src-linux/ral_master.c index ea5c6fe..2860fe7 100644 --- a/src-linux/ral_master.c +++ b/src-linux/ral_master.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgw1) && defined(CFG_ral_master_slave) @@ -45,7 +44,7 @@ #include "tc.h" #include "sys.h" #include "sys_linux.h" -#include "sx1301conf.h" +#include "sx130xconf.h" #include "ral.h" #include "ralsub.h" @@ -66,6 +65,7 @@ typedef struct slave { u1_t restartCnt; u1_t antennaType; dbuf_t sx1301confJson; + chdefl_t upchs; int last_expcmd; // Read Spill Buffer struct { @@ -351,6 +351,7 @@ static void send_config (slave_t* slave) { if( jlen > 0 ) { req.region = region; req.jsonlen = jlen; + req.upchs = slave->upchs; memcpy(req.json, slave->sx1301confJson.buf, jlen); LOG(MOD_RAL|INFO, "Master sending %d bytes of JSON sx1301conf to slave (%d)", jlen, (int)(slave-slaves)); if( !write_slave_pipe(slave, &req, sizeof(req)) ) @@ -422,11 +423,11 @@ static void restart_slave (tmr_t* tmr) { u1_t ral_altAntennas (u1_t txunit) { - if( txunit >= n_slaves || slaves[txunit].antennaType != SX1301_ANT_OMNI ) + if( txunit >= n_slaves || slaves[txunit].antennaType != SX130X_ANT_OMNI ) return 0; u1_t v = 0; for( int sidx=0; sidx < n_slaves; sidx++ ) { - if( sidx == txunit || slaves[sidx].antennaType != SX1301_ANT_OMNI ) + if( sidx == txunit || slaves[sidx].antennaType != SX130X_ANT_OMNI ) continue; v |= 1<chip > n1301 ) break; + slaves[ch->chip].upchs.freq[ch->chan] = ch->chdef.freq; + slaves[ch->chip].upchs.rps[ch->chan] = ch->chdef.rps; + break; + } + case CHALLOC_CHIP_DONE: { + break; + } + case CHALLOC_DONE: { + break; + } + } +} + +int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen, chdefl_t* upchs) { if( strncmp(hwspec, "sx1301/", 7) != 0 ) { LOG(MOD_RAL|ERROR, "Unsupported hwspec=%s", hwspec); return 0; @@ -534,6 +560,9 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { LOG(MOD_RAL|ERROR, "sx1301_conf is empty but a hw setup IS required - no fallbacks"); return 0; } + + ral_challoc(upchs, slave_challoc_cb, &n1301); + str_t s = hwspec+7; int specn = rt_readDec(&s); if( specn != n1301 ) { @@ -541,7 +570,7 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { return 0; } if( n1301 > n_slaves ) { - LOG(MOD_RAL|ERROR, "Region plan asks for hwspec=%s which exceeds actual hardware: sx1301/%d", hwspec, n1301); + LOG(MOD_RAL|ERROR, "Region plan asks for hwspec=%s which exceeds actual hardware: sx1301/%d", hwspec, n_slaves); return 0; } if( n1301 < n_slaves ) { @@ -549,8 +578,10 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { LOG(MOD_RAL|WARNING, "Region plan hwspec '%s' cannot be replicated onto routers 'sx1301/%d' - router is underutilized", hwspec, n_slaves); } else { - for( int si=n1301, sj=0; si < n_slaves; si++, sj=(sj+1)%n1301 ) + for( int si=n1301, sj=0; si < n_slaves; si++, sj=(sj+1)%n1301 ) { + slaves[si].upchs = slaves[sj].upchs; slaves[si].sx1301confJson = dbuf_dup(slaves[sj].sx1301confJson); + } LOG(MOD_RAL|WARNING, "Region plan hwspec '%s' replicated %d times onto slaves 'sx1301/%d' - assuming antenna diversity", hwspec, n_slaves/n1301, n_slaves); } @@ -558,8 +589,9 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { LOG(MOD_RAL|INFO, "Region plan hwspec '%s' mapped to %d slaves 'sx1301/1'", hwspec, n_slaves); } region = cca_region; - for( int i=0; i < n_slaves; i++ ) + for( int i=0; i < n_slaves; i++ ) { send_config(&slaves[i]); + } return 1; } @@ -585,8 +617,8 @@ void ral_ini () { slaves = rt_mallocN(slave_t, n_slaves); int allok = 1; for( int sidx=0; sidx < n_slaves; sidx++ ) { - struct sx1301conf sx1301conf; - if( !sx1301conf_parse_setup(&sx1301conf, sidx, "sx1301/1", "{}", 2) ) { + struct sx130xconf sx1301conf; + if( !sx130xconf_parse_setup(&sx1301conf, sidx, "sx1301/1", "{}", 2) ) { allok = 0; } else { slaves[sidx].antennaType = sx1301conf.antennaType; diff --git a/src-linux/ral_slave.c b/src-linux/ral_slave.c index a12cfaa..fca12af 100644 --- a/src-linux/ral_slave.c +++ b/src-linux/ral_slave.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgw1) && defined(CFG_ral_master_slave) @@ -39,7 +38,7 @@ #include "ralsub.h" #include "timesync.h" #include "sys_linux.h" -#include "sx1301conf.h" +#include "sx130xconf.h" #include "lgw/loragw_hal.h" @@ -206,12 +205,14 @@ static void pipe_read (aio_t* aio) { else if( n >= off + sizeof(struct ral_config_req) && req->cmd == RAL_CMD_CONFIG) { off += sizeof(struct ral_config_req); struct ral_config_req* confreq = (struct ral_config_req*)req; - struct sx1301conf sx1301conf; + struct sx130xconf sx1301conf; + int status = 0; // Note: sx1301conf_start can take considerable amount of time (if LBT on up to 8s!!) - if( !sx1301conf_parse_setup(&sx1301conf, sys_slaveIdx, confreq->hwspec, confreq->json, confreq->jsonlen) || - !sys_runRadioInit(sx1301conf.device) || - !sx1301conf_start(&sx1301conf, confreq->region) ) - rt_fatal("Slave radio start up failed"); + if( (status = !sx130xconf_parse_setup(&sx1301conf, sys_slaveIdx, confreq->hwspec, confreq->json, confreq->jsonlen)) || + (status = !sx130xconf_challoc(&sx1301conf, &confreq->upchs) << 1) || + (status = !sys_runRadioInit(sx1301conf.device) << 2) || + (status = !sx130xconf_start(&sx1301conf, confreq->region) << 3) ) + rt_fatal("Slave radio start up failed with status 0x%02x", status); if( sx1301conf.pps && sys_slaveIdx ) { LOG(MOD_RAL|ERROR, "Only slave#0 may have PPS enabled"); sx1301conf.pps = 0; diff --git a/src-linux/ralsub.h b/src-linux/ralsub.h index 0db6086..20f9f02 100644 --- a/src-linux/ralsub.h +++ b/src-linux/ralsub.h @@ -1,34 +1,34 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _ralsub_h_ #define _ralsub_h_ + #if defined(CFG_lgw1) && defined(CFG_ral_master_slave) #include "timesync.h" @@ -76,8 +76,9 @@ struct ral_config_req { u1_t cmd; u2_t jsonlen; u4_t region; // 0=no LBT, !=0 LBT for this region + chdefl_t upchs; char hwspec[MAX_HWSPEC_SIZE]; - char json[PIPE_BUF-16-MAX_HWSPEC_SIZE]; // 16 >= 8+1+2+4 + char json[PIPE_BUF-16-MAX_HWSPEC_SIZE-sizeof(chdefl_t)]; // 16 >= 8+1+2+4 }; struct ral_tx_req { @@ -128,6 +129,6 @@ struct lgw_pkt_rx_s; rps_t ral_lgw2rps (struct lgw_pkt_rx_s* p); void ral_rps2lgw (rps_t rps, struct lgw_pkt_tx_s* p); - #endif // defined(CFG_lgw1) && defined(CFG_ral_master_slave) + #endif // _ralsub_h_ diff --git a/src-linux/rmtsh.c b/src-linux/rmtsh.c index 4a24def..d4567e3 100644 --- a/src-linux/rmtsh.c +++ b/src-linux/rmtsh.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if !defined(CFG_no_rmtsh) diff --git a/src-linux/station_main.c b/src-linux/station_main.c index 224473c..a4ecc8a 100644 --- a/src-linux/station_main.c +++ b/src-linux/station_main.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_linux) diff --git a/src-linux/sys_linux.c b/src-linux/sys_linux.c index f8286c8..5b637c9 100644 --- a/src-linux/sys_linux.c +++ b/src-linux/sys_linux.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE // syncfs(fd) @@ -453,7 +452,7 @@ void sys_updateStart (int len) { return; } makeFilepath("/tmp/update", ".bi_", &temp_updfile, 0); - updfd = open(temp_updfile, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP); + updfd = open(temp_updfile, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP); if( updfd == -1 ) LOG(MOD_SYS|ERROR, "Failed to open '%s': %s", temp_updfile, strerror(errno)); } @@ -498,7 +497,7 @@ void sys_runUpdate () { } void sys_abortUpdate () { - unlink("/tmp/update"); + unlink("/tmp/update.bin"); sync(); } @@ -538,7 +537,7 @@ int sys_execCommand (ustime_t max_wait, str_t* argv) { argv = argv2; } else { // Assume file with Shell statements - argv2[1] = "/bin/sh"; + argv2[1] = "/bin/bash"; argv2[2] = argv[0]; argv = &argv2[1]; } @@ -561,6 +560,7 @@ int sys_execCommand (ustime_t max_wait, str_t* argv) { return -1; } LOG(MOD_SYS|VERBOSE, "%s: Forked, waiting...", argv[0]); + log_flushIO(); int wmode = WNOHANG; if( max_wait == 0 ) { // detached child forks a grand child - child exits max_wait = USTIME_MAX; // basically forever @@ -578,6 +578,7 @@ int sys_execCommand (ustime_t max_wait, str_t* argv) { int xcode = WEXITSTATUS(status); if( xcode == 0 ) { LOG(MOD_SYS|INFO, "Process %s (pid=%d) completed", argv[0], pid1); + log_flushIO(); return 0; } LOG(MOD_SYS|ERROR, "Process %s (pid=%d) failed with exit code %d", argv[0], pid1, xcode); @@ -724,8 +725,8 @@ static int parseStationConf () { case J_nodc: case J_nodwell: case J_device_mode: { - LOG(MOD_S2E|WARNING, "Feature not supported in production level code (station.conf) - ignored: %s", D->field.name); - uj_skipValue(D); + LOG(MOD_S2E|WARNING, "Feature not supported in production level code (station.conf) - ignored: %s", D.field.name); + uj_skipValue(&D); break; } #else // !defined(CFG_prod) diff --git a/src-linux/sys_linux.h b/src-linux/sys_linux.h index ac6fcf9..002a9b9 100644 --- a/src-linux/sys_linux.h +++ b/src-linux/sys_linux.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _sys_linux_h_ diff --git a/src-linux/sys_log.c b/src-linux/sys_log.c index 8db3511..cce7a35 100644 --- a/src-linux/sys_log.c +++ b/src-linux/sys_log.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE @@ -179,7 +178,7 @@ static void addLog (const char *logline, int len) { int k = min(LOG_OUTSIZ-outfill, len); memcpy(outbuf + outfill, logline, k); outfill += k; - int notify = (outfill >= LOG_HIGHWATER); + int notify = (len == 0 || outfill >= LOG_HIGHWATER); pthread_mutex_unlock(&mxfill); if( notify ) { pthread_cond_signal(&condvar); @@ -233,7 +232,11 @@ void sys_flushLog (void) { void sys_addLog (const char *logline, int len) { - addLog(logline, len); + if( len == 0 ) { + sys_flushLog(); + } else { + addLog(logline, len); + } } diff --git a/src-linux/web_linux.c b/src-linux/web_linux.c index 9d43cb4..6eef4cb 100644 --- a/src-linux/web_linux.c +++ b/src-linux/web_linux.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "sys.h" diff --git a/src/aio.c b/src/aio.c index c4af6b8..90f24e9 100644 --- a/src/aio.c +++ b/src/aio.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/src/argp.c b/src/argp.c index 431ef75..fca18a9 100644 --- a/src/argp.c +++ b/src/argp.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_argp) diff --git a/src/argp2.h b/src/argp2.h index fd8e738..070ffec 100644 --- a/src/argp2.h +++ b/src/argp2.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_argp) diff --git a/src/crc32.c b/src/crc32.c index ac3ad83..33bf398 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_prog_crc32) @@ -109,7 +108,7 @@ int main (int argc, char** argv) { fprintf(stderr, "Failed to read '%s': %s\n", file, strerror(errno)); continue; } - printf("0x%08X %s\n", crc, file); + printf("0x%08X %s\n", crc, file[0] == '-' ? "" : file); fclose(f); } if( argc > 2 ) diff --git a/src/cups.c b/src/cups.c index 270c254..e3d6079 100644 --- a/src/cups.c +++ b/src/cups.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "s2conf.h" @@ -41,6 +40,7 @@ #define FAIL_CNT_THRES 6 +#define SIGCRC_LEN 4 static tmr_t cups_sync_tmr; static cups_t* CUPS; @@ -137,6 +137,7 @@ static void cups_ondone (tmr_t* tmr) { run_update = 1; } else { LOG(MOD_CUP|ERROR, "Keyfile present, but no signature provided. Aborting update."); + sys_sigKey(-1); } } if (run_update) { @@ -215,6 +216,7 @@ static void cups_update_info (conn_t* _conn, int ev) { xprintf(&b, "POST /update-info HTTP/1.1\r\n" "Host: %*s\r\n" + "Content-Type: application/json\r\n" "Content-Length: 00000\r\n" "%s\r\n", cui.hostportEnd-cui.hostportBeg, cupsuri.buf+cui.hostportBeg, @@ -226,8 +228,8 @@ static void cups_update_info (conn_t* _conn, int ev) { "router", '6', sys_eui(), "cupsUri", 's', sys_uri(SYS_CRED_CUPS, SYS_CRED_REG), "tcUri", 's', sys_uri(SYS_CRED_TC, SYS_CRED_REG), - "cupsCredCrc",'u', sys_crcCred(SYS_CRED_CUPS), - "tcCredCrc", 'u', sys_crcCred(SYS_CRED_TC), + "cupsCredCrc",'u', sys_crcCred(SYS_CRED_CUPS, SYS_CRED_REG), + "tcCredCrc", 'u', sys_crcCred(SYS_CRED_TC, SYS_CRED_REG), "station", 's', CFG_version " " CFG_bdate, "model", 's', CFG_platform, "package", 's', version, @@ -301,8 +303,9 @@ static void cups_update_info (conn_t* _conn, int ev) { // Not enough data in body buffer get_more: if( !http_getMore(&cups->hc) ) { + LOG(MOD_CUP|ERROR, "Unexpected end of data"); proto_err: - LOG(MOD_CUP|ERROR, "Protocol error - unexpected end of data"); + LOG(MOD_CUP|ERROR, "CUPS Protocol error. Closing connection."); cups_done(cups, CUPS_ERR_FAILED); } return; // waiting for next chunk @@ -319,6 +322,10 @@ static void cups_update_info (conn_t* _conn, int ev) { cups->temp_n = 0; continue; } + if( segm_len < 0 ) { + LOG(MOD_CUP|ERROR, "Segment %d length not allowed (must be <2GB): 0x%08x bytes", cstate-CUPS_FEED_CUPS_URI, segm_len); + goto proto_err; + } cups->segm_off = 0; cups->segm_len = segm_len; cups->temp_n = 4; @@ -326,15 +333,19 @@ static void cups_update_info (conn_t* _conn, int ev) { if( cstate == CUPS_FEED_CUPS_CRED ) { sys_credStart(SYS_CRED_CUPS, segm_len); cups->uflags |= UPDATE_FLAG(CUPS_CRED); - LOG(MOD_CUP|INFO, "CUPS credentials segment (%d bytes)", segm_len); + LOG(MOD_CUP|INFO, "CUPS Credentials segment (%d bytes)", segm_len); } else if( cstate == CUPS_FEED_TC_CRED ) { sys_credStart(SYS_CRED_TC, segm_len); cups->uflags |= UPDATE_FLAG(TC_CRED); - LOG(MOD_CUP|INFO, "TC credentials segment (%d bytes)", segm_len); + LOG(MOD_CUP|INFO, "TC Credentials segment (%d bytes)", segm_len); } else if( cstate == CUPS_FEED_SIGNATURE ) { LOG(MOD_CUP|INFO, "Signature segment (%d bytes)", segm_len); rt_free(cups->sig); + if( segm_len < 8 || segm_len > sizeof(cups->sig->signature) + SIGCRC_LEN ) { + LOG(MOD_CUP|ERROR, "Illegal signature segment length (must be 8-%d bytes): %d", sizeof(cups->sig->signature) + SIGCRC_LEN, segm_len); + goto proto_err; + } cups->sig = rt_malloc(cups_sig_t); } else { // cstate == CUPS_FEED_UPDATE assert(cstate == CUPS_FEED_UPDATE); @@ -355,16 +366,10 @@ static void cups_update_info (conn_t* _conn, int ev) { sys_credComplete(SYS_CRED_TC, cups->segm_len); LOG(MOD_CUP|INFO, "TC credentials updated (%d bytes)", cups->segm_len); } else if( cstate == CUPS_FEED_SIGNATURE ) { - if ( cups->segm_len - 4 > sizeof(cups->sig->signature) ) { - LOG(MOD_CUP|ERROR, "CUPS provided oversized signature %d bytes (%d allowed).", - cups->segm_len - 4, sizeof(cups->sig->signature)); - rt_free(cups->sig); - } else { - cups->uflags |= UPDATE_FLAG(SIGNATURE); - cups->sig->len = cups->segm_len - 4; - mbedtls_sha512_init(&cups->sig->sha); - mbedtls_sha512_starts(&cups->sig->sha, 0); - } + cups->uflags |= UPDATE_FLAG(SIGNATURE); + cups->sig->len = cups->segm_len - SIGCRC_LEN; + mbedtls_sha512_init(&cups->sig->sha); + mbedtls_sha512_starts(&cups->sig->sha, 0); } else { // cstate == CUPS_FEED_UPDATE if( sys_updateCommit(cups->segm_len) ) { @@ -391,15 +396,15 @@ static void cups_update_info (conn_t* _conn, int ev) { else if( cstate == CUPS_FEED_SIGNATURE ) { // CRC of signature comes just after length int siglen = dlen; - if( segm_off < 4 ) { // CRC before signature - int d = min(4-segm_off, siglen); + if( segm_off < SIGCRC_LEN ) { // CRC before signature + int d = min(SIGCRC_LEN-segm_off, siglen); memcpy(cups->sig->keycrcb + segm_off, data, d); segm_off += d; data += d; siglen -= d; } - if (siglen > 0 && segm_off + siglen - 4 <= sizeof(cups->sig->signature)) { - memcpy(cups->sig->signature+segm_off-4, data, siglen); + if (siglen > 0 && segm_off + siglen - SIGCRC_LEN <= sizeof(cups->sig->signature)) { + memcpy(cups->sig->signature+segm_off-SIGCRC_LEN, data, siglen); } } else { assert(cstate == CUPS_FEED_UPDATE); @@ -467,7 +472,7 @@ void cups_start (cups_t* cups) { LOG(MOD_CUP|ERROR,"Bad CUPS URI: %s", cupsuri); goto errexit; } - if( ok == URI_TLS && !conn_setup_tls(&cups->hc.c, SYS_CRED_CUPS, cups_credset) ) { + if( ok == URI_TLS && !conn_setup_tls(&cups->hc.c, SYS_CRED_CUPS, cups_credset, hostname) ) { goto errexit; } if( !http_connect(&cups->hc, hostname, port) ) { @@ -498,9 +503,13 @@ void sys_triggerCUPS (int delay) { sys_stopTC(); } #endif // defined(CFG_cups_exclusive) + if( delay < 0 ) { + delay = CUPS_RESYNC_INTV/1000000; + } LOG(MOD_CUP|INFO, "Starting a CUPS session in %d seconds.", delay); sys_inState(SYSIS_CUPS_INTERACT); CUPS = cups_ini(); + rt_clrTimer(&cups_sync_tmr); rt_setTimerCb(&CUPS->timeout, rt_seconds_ahead(delay), delayedCUPSstart); } diff --git a/src/cups.h b/src/cups.h index 3bb57ec..2b849e5 100644 --- a/src/cups.h +++ b/src/cups.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _cups_h_ diff --git a/src/flashsim.c b/src/flashsim.c index 48dfa51..72b46ce 100644 --- a/src/flashsim.c +++ b/src/flashsim.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_linux) || defined(CFG_flashsim) diff --git a/src/fs.c b/src/fs.c index 2f08f2d..0d485dc 100644 --- a/src/fs.c +++ b/src/fs.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/src/fs.h b/src/fs.h index d88d65e..01a2a52 100644 --- a/src/fs.h +++ b/src/fs.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _fs_h_ diff --git a/src/genkwcrcs.c b/src/genkwcrcs.c index 44eda18..4b41f7e 100644 --- a/src/genkwcrcs.c +++ b/src/genkwcrcs.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_prog_genkwcrcs) diff --git a/src/http.h b/src/http.h index 670b111..83c4b1f 100644 --- a/src/http.h +++ b/src/http.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _http_h_ diff --git a/src/httpd.h b/src/httpd.h index 6fabfa0..d871c85 100644 --- a/src/httpd.h +++ b/src/httpd.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _httpd_h_ diff --git a/src/kwcrc.h b/src/kwcrc.h index 33ab036..02a6fd7 100644 --- a/src/kwcrc.h +++ b/src/kwcrc.h @@ -1,6 +1,7 @@ // Auto generated by genkwcrcs - DO NOT CHANGE! #define UJ_UPDATE_CRC(crc,c) ((((crc)>>(32-8))*65537) ^ ((crc)*257) ^ ((c)&0x7F)) #define UJ_FINISH_CRC(crc) ((crc) ? (crc) : 1) +#define J_addcrc ((ujcrc_t)(0x1991DA5B)) #define J_antenna_gain ((ujcrc_t)(0xB5F37EF4)) #define J_antenna_type ((ujcrc_t)(0x7D4274ED)) #define J_api ((ujcrc_t)(0x00617278)) @@ -9,6 +10,7 @@ #define J_AS923JP ((ujcrc_t)(0x6616F98E)) #define J_asap ((ujcrc_t)(0x61D4E603)) #define J_AU915 ((ujcrc_t)(0xD8599E68)) +#define J_bcning ((ujcrc_t)(0x1EE5E245)) #define J_beaconing ((ujcrc_t)(0x58428CA7)) #define J_cca ((ujcrc_t)(0x00636361)) #define J_CN470 ((ujcrc_t)(0xD75F977D)) @@ -17,6 +19,7 @@ #define J_config ((ujcrc_t)(0xF7A3E35F)) #define J_dC ((ujcrc_t)(0x00006427)) #define J_DevEui ((ujcrc_t)(0x0F01F1A4)) +#define J_DevEUI ((ujcrc_t)(0x0F01D1A4)) #define J_device ((ujcrc_t)(0xF0921352)) #define J_device_mode ((ujcrc_t)(0x2DB3FCE7)) #define J_diid ((ujcrc_t)(0x64D5D500)) @@ -39,8 +42,10 @@ #define J_cmd ((ujcrc_t)(0x0063716A)) #define J_freq ((ujcrc_t)(0x66E0EB00)) #define J_Freq ((ujcrc_t)(0x46C0CB20)) +#define J_freqs ((ujcrc_t)(0x47ADEB15)) #define J_freq_range ((ujcrc_t)(0x38A2732C)) #define J_gateway_conf ((ujcrc_t)(0x186A380C)) +#define J_getxtime ((ujcrc_t)(0x286076CA)) #define J_gps ((ujcrc_t)(0x00677E64)) #define J_gpstime ((ujcrc_t)(0xCC004EB5)) #define J_hello ((ujcrc_t)(0x46DBE30A)) @@ -49,7 +54,9 @@ #define J_IL915 ((ujcrc_t)(0xE1689771)) #define J_infos_uri ((ujcrc_t)(0xE3215635)) #define J_JoinEui ((ujcrc_t)(0x5B616676)) +#define J_JoinEUI ((ujcrc_t)(0x5B618676)) #define J_KR920 ((ujcrc_t)(0xFB789669)) +#define J_layout ((ujcrc_t)(0x11950A24)) #define J_log_file ((ujcrc_t)(0x7886C6B6)) #define J_log_level ((ujcrc_t)(0x7B397448)) #define J_log_rotate ((ujcrc_t)(0x240F1106)) @@ -68,6 +75,7 @@ #define J_ontime ((ujcrc_t)(0xF9E41F34)) #define J_pa_gain ((ujcrc_t)(0xDEE8634E)) #define J_pdu ((ujcrc_t)(0x00708461)) +#define J_preamble ((ujcrc_t)(0x05167D25)) #define J_priority ((ujcrc_t)(0xF00C8E15)) #define J_pps ((ujcrc_t)(0x00707073)) #define J_radio ((ujcrc_t)(0x6A861A03)) @@ -103,6 +111,7 @@ #define J_txpow_adjust ((ujcrc_t)(0x03E0F6FD)) #define J_txtime ((ujcrc_t)(0x02CB1104)) #define J_type ((ujcrc_t)(0x74F5FE18)) +#define J_upchannels ((ujcrc_t)(0x7FCAA9EB)) #define J_updf ((ujcrc_t)(0x75EFDB07)) #define J_upgrade ((ujcrc_t)(0xF49BF544)) #define J_uri ((ujcrc_t)(0x00757C6E)) @@ -126,17 +135,33 @@ #define J_rf_power ((ujcrc_t)(0x95FCE8DC)) #define J_rssi_offset ((ujcrc_t)(0x2C99BDFE)) #define J_rssi_offset_lbt ((ujcrc_t)(0xAFDE7647)) +#define J_SX1250 ((ujcrc_t)(0x1FBE0E5B)) #define J_SX1255 ((ujcrc_t)(0x1FBE0E5E)) #define J_SX1257 ((ujcrc_t)(0x1FBE0E5C)) #define J_SX1272 ((ujcrc_t)(0x1FBE0C5B)) #define J_SX1276 ((ujcrc_t)(0x1FBE0C5F)) #define J_sx1301_conf ((ujcrc_t)(0x2AF5BD41)) #define J_SX1301_conf ((ujcrc_t)(0xCF76EBC6)) +#define J_sx1302_conf ((ujcrc_t)(0x2BF4BF45)) +#define J_SX1302_conf ((ujcrc_t)(0x76DDEBC0)) #define J_sync_word ((ujcrc_t)(0xA4BF704D)) #define J_sync_word_size ((ujcrc_t)(0xE6AAAB54)) #define J_tx_enable ((ujcrc_t)(0x631F9A2D)) #define J_tx_gain_lut ((ujcrc_t)(0x43B971DB)) #define J_tx_notch_freq ((ujcrc_t)(0xA8FCE052)) +#define J_pwr_idx ((ujcrc_t)(0xDFD7588B)) +#define J_rssi_tcomp ((ujcrc_t)(0x47CB0C8F)) +#define J_coeff_a ((ujcrc_t)(0x87785402)) +#define J_coeff_b ((ujcrc_t)(0x87785401)) +#define J_coeff_c ((ujcrc_t)(0x87785400)) +#define J_coeff_d ((ujcrc_t)(0x87785407)) +#define J_coeff_e ((ujcrc_t)(0x87785406)) +#define J_implicit_hdr ((ujcrc_t)(0xC842AB12)) +#define J_implicit_payload_length ((ujcrc_t)(0xA83D6605)) +#define J_implicit_crc_en ((ujcrc_t)(0x531037C1)) +#define J_implicit_coderate ((ujcrc_t)(0x644EF1C1)) +#define J_sx1302_conf ((ujcrc_t)(0x2BF4BF45)) +#define J_SX1302_conf ((ujcrc_t)(0x76DDEBC0)) #define J_tx_lut ((ujcrc_t)(0x25A75023)) #define J_rf_power ((ujcrc_t)(0x95FCE8DC)) #define J_fpga_dig_gain ((ujcrc_t)(0xB17E4194)) @@ -191,6 +216,19 @@ #define J_aes_key ((ujcrc_t)(0xD9FE95FC)) #define J_calibration_temperature_celsius_room ((ujcrc_t)(0x8D9594E4)) #define J_calibration_temperature_code_ad9361 ((ujcrc_t)(0x2D301DEC)) +#define J_fpga_flavor ((ujcrc_t)(0x1A5CFA3E)) +#define J_SX1388_A11 ((ujcrc_t)(0x7D70D2A0)) +#define J_SX1388_SAGEMCOM ((ujcrc_t)(0xD7A4F74B)) +#define J_SX1388_B11 ((ujcrc_t)(0x7D73CEA3)) +#define J_SX1388_KERLINK ((ujcrc_t)(0xEBC39360)) +#define J_SX1388_C11 ((ujcrc_t)(0x7D72CEA2)) +#define J_SX1388_CISCO ((ujcrc_t)(0x4432F439)) +#define J_SX1388_E11 ((ujcrc_t)(0x7D7CD2A4)) +#define J_SX1388_SEMTECH ((ujcrc_t)(0xE9AC9268)) +#define J_SX1388_F11 ((ujcrc_t)(0x7D7FCEA7)) +#define J_SX1388_FOXCONN ((ujcrc_t)(0x9CA462ED)) +#define J_SX1388_L11 ((ujcrc_t)(0x7D75D2AD)) +#define J_SX1388_MULTITECH ((ujcrc_t)(0xA42F71FA)) #define J_lbt_enable ((ujcrc_t)(0x1C7A0E2A)) #define J_freq_band ((ujcrc_t)(0xB067FA9A)) #define J_rx_freq ((ujcrc_t)(0xEB1D6E55)) diff --git a/src/kwlist.txt b/src/kwlist.txt index 2601a1f..c12925f 100644 --- a/src/kwlist.txt +++ b/src/kwlist.txt @@ -1,3 +1,4 @@ +addcrc antenna_gain antenna_type api @@ -6,6 +7,7 @@ AS923 AS923JP asap AU915 +bcning beaconing cca CN470 @@ -14,6 +16,7 @@ command config dC DevEui +DevEUI device device_mode diid @@ -36,8 +39,10 @@ shell cmd freq Freq +freqs freq_range gateway_conf +getxtime gps gpstime hello @@ -46,7 +51,9 @@ if IL915 infos_uri JoinEui +JoinEUI KR920 +layout log_file log_level log_rotate @@ -65,6 +72,7 @@ no_gps_capture ontime pa_gain pdu +preamble priority pps radio @@ -100,6 +108,7 @@ threshold txpow_adjust txtime type +upchannels updf upgrade uri @@ -125,18 +134,36 @@ rf_chain rf_power rssi_offset rssi_offset_lbt +SX1250 SX1255 SX1257 SX1272 SX1276 sx1301_conf SX1301_conf +sx1302_conf +SX1302_conf sync_word sync_word_size tx_enable tx_gain_lut tx_notch_freq # ---------------------------------------- +# sx1302 conf +pwr_idx +rssi_tcomp +coeff_a +coeff_b +coeff_c +coeff_d +coeff_e +implicit_hdr +implicit_payload_length +implicit_crc_en +implicit_coderate +sx1302_conf +SX1302_conf +# ---------------------------------------- # sx1301v2 conf tx_lut # --- obj rf_power @@ -192,6 +219,19 @@ dsp_stat_interval aes_key calibration_temperature_celsius_room calibration_temperature_code_ad9361 +fpga_flavor +SX1388_A11 +SX1388_SAGEMCOM +SX1388_B11 +SX1388_KERLINK +SX1388_C11 +SX1388_CISCO +SX1388_E11 +SX1388_SEMTECH +SX1388_F11 +SX1388_FOXCONN +SX1388_L11 +SX1388_MULTITECH # --------------------------------------- # tekui config lbt_enable diff --git a/src/lgwsim.c b/src/lgwsim.c index 8291bd9..1f707c8 100644 --- a/src/lgwsim.c +++ b/src/lgwsim.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgwsim) @@ -36,12 +35,23 @@ #include #include #include + +#if defined(CFG_lgw1) #include "lgw/loragw_reg.h" #include "lgw/loragw_hal.h" +#include "lgw/loragw_fpga.h" #include "lgw/loragw_lbt.h" +#elif defined(CFG_lgw2) +#include "lgw2/sx1301ar_hal.h" +#include "lgw2/sx1301ar_err.h" +#include "lgw2/sx1301ar_gps.h" +#include "lgw2/sx1301ar_dsp.h" +#endif + #include "rt.h" #include "s2e.h" #include "sys.h" + #include "sys_linux.h" #define MAX_CCA_INFOS 10 @@ -60,16 +70,22 @@ struct cca_msg { struct cca_info infos[MAX_CCA_INFOS]; }; -static sL_t timeOffset; +#if defined(CFG_lgw1) static struct lgw_pkt_tx_s tx_pkt; +static struct lgw_pkt_rx_s rx_pkts[RX_NPKTS+1]; +static u1_t ppsLatched; +#elif defined(CFG_lgw2) +static sx1301ar_tx_pkt_t tx_pkt; +static sx1301ar_rx_pkt_t rx_pkts[RX_NPKTS+1]; +#endif + +static sL_t timeOffset; static sL_t txbeg; static sL_t txend; -static struct lgw_pkt_rx_s rx_pkts[RX_NPKTS+1]; static int rxblen = sizeof(rx_pkts[0])*RX_NPKTS; static int rx_ridx = 0; static int rx_widx = 0; static u4_t rx_dsc = 0; -static u1_t ppsLatched; static aio_t* aio; static tmr_t conn_tmr; static struct sockaddr_un sockAddr; @@ -107,6 +123,7 @@ static sL_t xticks () { static u4_t airtime (int datarate, int bandwidth, int plen) { int sf, bw; +#if defined(CFG_lgw1) switch(bandwidth) { case BW_125KHZ: bw = BW125; break; case BW_250KHZ: bw = BW250; break; @@ -120,7 +137,23 @@ static u4_t airtime (int datarate, int bandwidth, int plen) { case DR_LORA_SF8 : sf = SF8 ; break; case DR_LORA_SF7 : sf = SF7 ; break; } - return s2e_calcDnAirTime(rps_make(sf,bw), plen); +#elif defined(CFG_lgw2) + switch(bandwidth) { + case BW_125K: bw = BW125; break; + case BW_250K: bw = BW250; break; + case BW_500K: bw = BW500; break; + default: bw = BWNIL; break; + } + switch(datarate) { + case MR_SF12: sf = SF12; break; + case MR_SF11: sf = SF11; break; + case MR_SF10: sf = SF10; break; + case MR_SF9 : sf = SF9 ; break; + case MR_SF8 : sf = SF8 ; break; + case MR_SF7 : sf = SF7 ; break; + } +#endif + return s2e_calcDnAirTime(rps_make(sf,bw), plen, /*addcrc*/0, /*preamble*/0); } @@ -149,7 +182,7 @@ static void try_connecting (tmr_t* tmr) { tx_pkt.count_us = timeOffset; tx_pkt.freq_hz = timeOffset>>32; tx_pkt.f_dev = max(0, sys_slaveIdx); - LOG(MOD_SIM|INFO, "LGWSIM: Connected txunit#%d timeOffset=0x%lX xticksNow=0x%lX", sys_slaveIdx, timeOffset, xticks()); + LOG(MOD_SIM|INFO, "LGWSIM: Connected txunit#%d timeOffset=0x%lX xticksNow=0x%lX", max(0, sys_slaveIdx), timeOffset, xticks()); write_socket(aio); read_socket(aio); return; @@ -224,6 +257,10 @@ static void write_socket (aio_t* aio) { aio_set_wrfn(aio, NULL); } +#if defined(CFG_lgw1) +/* ********************************************** + **** LGW 1 **** + ********************************************** */ int lgw_receive (uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) { int npkts = 0; @@ -318,16 +355,242 @@ int lgw_board_setconf (struct lgw_conf_board_s conf) { int lgw_rxrf_setconf (uint8_t rf_chain, struct lgw_conf_rxrf_s conf) { + /* check input range (segfault prevention) */ + if (rf_chain >= LGW_RF_CHAIN_NB) { + LOG(MOD_SIM|ERROR, "ERROR: NOT A VALID RF_CHAIN NUMBER\n"); + return LGW_HAL_ERROR; + } + + /* check if radio type is supported */ + if ((conf.type != LGW_RADIO_TYPE_SX1255) && (conf.type != LGW_RADIO_TYPE_SX1257)) { + LOG(MOD_SIM|ERROR, "ERROR: NOT A VALID RADIO TYPE\n"); + return LGW_HAL_ERROR; + } + + /* check if TX notch filter frequency is supported */ + if ((conf.tx_enable == true) && ((conf.tx_notch_freq < LGW_MIN_NOTCH_FREQ) || (conf.tx_notch_freq > LGW_MAX_NOTCH_FREQ))) { + LOG(MOD_SIM|ERROR, "WARNING: NOT A VALID TX NOTCH FILTER FREQUENCY [%u..%u]Hz\n", LGW_MIN_NOTCH_FREQ, LGW_MAX_NOTCH_FREQ); + conf.tx_notch_freq = 0; + } + + /* set internal config according to parameters */ + // rf_enable[rf_chain] = conf.enable; + // rf_rx_freq[rf_chain] = conf.freq_hz; + // rf_rssi_offset[rf_chain] = conf.rssi_offset; + // rf_radio_type[rf_chain] = conf.type; + // rf_tx_enable[rf_chain] = conf.tx_enable; + // rf_tx_notch_freq[rf_chain] = conf.tx_notch_freq; + + LOG(MOD_SIM|INFO, "Note: rf_chain %d configuration; en:%d freq:%d rssi_offset:%f radio_type:%d tx_enable:%d tx_notch_freq:%u\n", + rf_chain, conf.enable, conf.freq_hz, conf.rssi_offset, conf.type, conf.tx_enable, conf.tx_notch_freq); + return LGW_HAL_SUCCESS; } +#define LGW_RF_RX_BANDWIDTH_125KHZ 925000 /* for 125KHz channels */ +#define LGW_RF_RX_BANDWIDTH_250KHZ 1000000 /* for 250KHz channels */ +#define LGW_RF_RX_BANDWIDTH_500KHZ 1100000 /* for 500KHz channels */ + +int32_t lgw_bw_getval(int x) { + switch (x) { + case BW_500KHZ: return 500000; + case BW_250KHZ: return 250000; + case BW_125KHZ: return 125000; + case BW_62K5HZ: return 62500; + case BW_31K2HZ: return 31200; + case BW_15K6HZ: return 15600; + case BW_7K8HZ : return 7800; + default: return -1; + } +} + int lgw_rxif_setconf (uint8_t if_chain, struct lgw_conf_rxif_s conf) { + int32_t bw_hz; + uint32_t rf_rx_bandwidth; + uint8_t ifmod_config[LGW_IF_CHAIN_NB] = LGW_IFMODEM_CONFIG; + // uint8_t fsk_sync_word_size = 3; /* default number of bytes for FSK sync word */ + uint64_t fsk_sync_word = 0xC194C1; /* default FSK sync word (ALIGNED RIGHT, MSbit first) */ + + /* check input range (segfault prevention) */ + if (if_chain >= LGW_IF_CHAIN_NB) { + LOG(MOD_SIM|ERROR, "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) { + LOG(MOD_SIM|INFO, "Note: if_chain %d disabled\n", if_chain); + return LGW_HAL_SUCCESS; + } + + if (conf.rf_chain >= LGW_RF_CHAIN_NB) { + LOG(MOD_SIM|ERROR, "ERROR: INVALID RF_CHAIN TO ASSOCIATE WITH A LORA_STD IF CHAIN\n"); + return LGW_HAL_ERROR; + } + /* check if IF frequency is optimal based on channel and radio bandwidths */ + switch (conf.bandwidth) { + case BW_250KHZ: + rf_rx_bandwidth = LGW_RF_RX_BANDWIDTH_250KHZ; /* radio bandwidth */ + break; + case BW_500KHZ: + rf_rx_bandwidth = LGW_RF_RX_BANDWIDTH_500KHZ; /* radio bandwidth */ + break; + default: + /* For 125KHz and below */ + rf_rx_bandwidth = LGW_RF_RX_BANDWIDTH_125KHZ; /* radio bandwidth */ + break; + } + bw_hz = lgw_bw_getval(conf.bandwidth); /* channel bandwidth */ + if ((conf.freq_hz + ((bw_hz==-1)?LGW_REF_BW:bw_hz)/2) > ((int32_t)rf_rx_bandwidth/2)) { + LOG(MOD_SIM|ERROR, "ERROR: IF FREQUENCY %d TOO HIGH\n", conf.freq_hz); + return LGW_HAL_ERROR; + } else if ((conf.freq_hz - ((bw_hz==-1)?LGW_REF_BW:bw_hz)/2) < -((int32_t)rf_rx_bandwidth/2)) { + LOG(MOD_SIM|ERROR, "ERROR: IF FREQUENCY %d TOO LOW\n", conf.freq_hz); + return LGW_HAL_ERROR; + } + + /* check parameters according to the type of IF chain + modem, + fill default if necessary, and commit configuration if everything is OK */ + switch (ifmod_config[if_chain]) { + case IF_LORA_STD: + /* fill default parameters if needed */ + if (conf.bandwidth == BW_UNDEFINED) { + conf.bandwidth = BW_250KHZ; + } + if (conf.datarate == DR_UNDEFINED) { + conf.datarate = DR_LORA_SF9; + } + /* check BW & DR */ + if (!IS_LORA_BW(conf.bandwidth)) { + LOG(MOD_SIM|ERROR, "ERROR: BANDWIDTH NOT SUPPORTED BY LORA_STD IF CHAIN\n"); + return LGW_HAL_ERROR; + } + if (!IS_LORA_STD_DR(conf.datarate)) { + LOG(MOD_SIM|ERROR, "ERROR: DATARATE NOT SUPPORTED BY LORA_STD IF CHAIN\n"); + return LGW_HAL_ERROR; + } + /* set internal configuration */ + // if_enable[if_chain] = conf.enable; + // if_rf_chain[if_chain] = conf.rf_chain; + // if_freq[if_chain] = conf.freq_hz; + // lora_rx_bw = conf.bandwidth; + // lora_rx_sf = (uint8_t)(DR_LORA_MULTI & conf.datarate); /* filter SF out of the 7-12 range */ + // if (SET_PPM_ON(conf.bandwidth, conf.datarate)) { + // lora_rx_ppm_offset = true; + // } else { + // lora_rx_ppm_offset = false; + // } + LOG(MOD_SIM|INFO, "Note: LoRa 'std' if_chain %d configuration; en:%d rf_chain:%d freq:%d bw:%d dr:%d\n", + if_chain, conf.enable, conf.rf_chain, conf.freq_hz, conf.bandwidth, (uint8_t)(DR_LORA_MULTI & conf.datarate)); + break; + + case IF_LORA_MULTI: + /* fill default parameters if needed */ + if (conf.bandwidth == BW_UNDEFINED) { + conf.bandwidth = BW_125KHZ; + } + if (conf.datarate == DR_UNDEFINED) { + conf.datarate = DR_LORA_MULTI; + } + /* check BW & DR */ + if (conf.bandwidth != BW_125KHZ) { + LOG(MOD_SIM|ERROR, "ERROR: BANDWIDTH NOT SUPPORTED BY LORA_MULTI IF CHAIN\n"); + return LGW_HAL_ERROR; + } + if (!IS_LORA_MULTI_DR(conf.datarate)) { + LOG(MOD_SIM|ERROR, "ERROR: DATARATE(S) NOT SUPPORTED BY LORA_MULTI IF CHAIN\n"); + return LGW_HAL_ERROR; + } + /* set internal configuration */ + // if_enable[if_chain] = conf.enable; + // if_rf_chain[if_chain] = conf.rf_chain; + // if_freq[if_chain] = conf.freq_hz; + // lora_multi_sfmask[if_chain] = (uint8_t)(DR_LORA_MULTI & conf.datarate); /* filter SF out of the 7-12 range */ + LOG(MOD_SIM|INFO, "Note: LoRa 'multi' if_chain %d configuration; en:%d rf_chain:%d freq:%d SF_mask:0x%02x\n", + if_chain, conf.enable, conf.rf_chain, conf.freq_hz, (uint8_t)(DR_LORA_MULTI & conf.datarate)); + break; + + case IF_FSK_STD: + /* fill default parameters if needed */ + if (conf.bandwidth == BW_UNDEFINED) { + conf.bandwidth = BW_250KHZ; + } + if (conf.datarate == DR_UNDEFINED) { + conf.datarate = 64000; /* default datarate */ + } + /* check BW & DR */ + if(!IS_FSK_BW(conf.bandwidth)) { + LOG(MOD_SIM|ERROR, "ERROR: BANDWIDTH NOT SUPPORTED BY FSK IF CHAIN\n"); + return LGW_HAL_ERROR; + } + if(!IS_FSK_DR(conf.datarate)) { + LOG(MOD_SIM|ERROR, "ERROR: DATARATE NOT SUPPORTED BY FSK IF CHAIN\n"); + return LGW_HAL_ERROR; + } + /* set internal configuration */ + // if_enable[if_chain] = conf.enable; + // if_rf_chain[if_chain] = conf.rf_chain; + // if_freq[if_chain] = conf.freq_hz; + // fsk_rx_bw = conf.bandwidth; + // fsk_rx_dr = conf.datarate; + if (conf.sync_word > 0) { + // fsk_sync_word_size = conf.sync_word_size; + fsk_sync_word = conf.sync_word; + } + LOG(MOD_SIM|INFO, "Note: FSK if_chain %d configuration; en:%d rf_chain:%d freq:%d bw:%d dr:%d (%d real dr) sync:0x%0X\n", + if_chain, conf.enable, conf.rf_chain, conf.freq_hz, conf.bandwidth, conf.datarate, LGW_XTAL_FREQU/(LGW_XTAL_FREQU/conf.datarate), fsk_sync_word); + break; + + default: + LOG(MOD_SIM|ERROR, "ERROR: IF CHAIN %d TYPE NOT SUPPORTED\n", if_chain); + return LGW_HAL_ERROR; +} return LGW_HAL_SUCCESS; } int lgw_txgain_setconf (struct lgw_tx_gain_lut_s* conf) { + int i; + + /* Check LUT size */ + if ((conf->size < 1) || (conf->size > TX_GAIN_LUT_SIZE_MAX)) { + LOG(MOD_SIM|ERROR, "ERROR: TX gain LUT must have at least one entry and maximum %d entries\n", TX_GAIN_LUT_SIZE_MAX); + return LGW_HAL_ERROR; + } + + // txgain_lut.size = conf->size; + + for (i = 0; i < conf->size; i++) { + /* Check gain range */ + if (conf->lut[i].dig_gain > 3) { + LOG(MOD_SIM|ERROR, "ERROR: TX gain LUT: SX1301 digital gain must be between 0 and 3\n"); + return LGW_HAL_ERROR; + } + if (conf->lut[i].dac_gain != 3) { + LOG(MOD_SIM|ERROR, "ERROR: TX gain LUT: SX1257 DAC gains != 3 are not supported\n"); + return LGW_HAL_ERROR; + } + if (conf->lut[i].mix_gain > 15) { + LOG(MOD_SIM|ERROR, "ERROR: TX gain LUT: SX1257 mixer gain must not exceed 15\n"); + return LGW_HAL_ERROR; + } else if (conf->lut[i].mix_gain < 8) { + LOG(MOD_SIM|ERROR, "ERROR: TX gain LUT: SX1257 mixer gains < 8 are not supported\n"); + return LGW_HAL_ERROR; + } + if (conf->lut[i].pa_gain > 3) { + LOG(MOD_SIM|ERROR, "ERROR: TX gain LUT: External PA gain must not exceed 3\n"); + return LGW_HAL_ERROR; + } + + // /* Set internal LUT */ + // txgain_lut.lut[i].dig_gain = conf->lut[i].dig_gain; + // txgain_lut.lut[i].dac_gain = conf->lut[i].dac_gain; + // txgain_lut.lut[i].mix_gain = conf->lut[i].mix_gain; + // txgain_lut.lut[i].pa_gain = conf->lut[i].pa_gain; + // txgain_lut.lut[i].rf_power = conf->lut[i].rf_power; + } + return LGW_HAL_SUCCESS; } @@ -338,5 +601,1057 @@ int lgw_lbt_setconf (struct lgw_conf_lbt_s conf) { str_t lgw_version_info () { return "LGW Simulation"; } + +#if defined(CFG_smtcpico) +int lgw_connect (const char *com_path) { + return LGW_HAL_SUCCESS; +} +#endif + +#endif // CFG_lgw1 +#if defined(CFG_lgw2) +/* ********************************************** + **** LGW 2 **** + ********************************************** */ + +static struct +{ + sx1301ar_btype_t btype; /* Board type: Master or slave */ + int16_t fpga_version; /* FPGA version */ + bool is_started; /* Is the board started or not */ + /* Radio configuration */ + uint32_t rx_freq; /* Center RX frequency of the radio, in Hz */ + uint32_t rx_bw; /* RX bandwidth of the radio, in Hz */ + bool full_duplex; /* Full-duplex / Half-duplex mode */ + /* Radio chains configuration */ + sx1301ar_rfchain_t rf_chain[SX1301AR_BOARD_RFCHAIN_NB]; + bool rf_diversity; /* indicates if antenna diversity is used on this board */ + /* Phy parameters that can be protocol-specific */ + uint32_t fsk_sync_msb; /* FSK sync word register value (aligned left) */ + uint32_t fsk_sync_lsb; /* FSK sync word register value (aligned left) */ + uint8_t fsk_sync_size; /* FSK sync word size */ + bool loramac_public; /* Enable ONLY for *public* networks using the LoRa MAC protocol */ + /* SX1301 settings */ + uint8_t chip_nb; /* Number of chip per board */ + bool chip_en[SX1301AR_BOARD_CHIPS_NB]; /* Is SX1301 enabled or not */ + uint8_t chip_rf_chain[SX1301AR_BOARD_CHIPS_NB]; /* Select Rx RF path */ + uint32_t chip_freq[SX1301AR_BOARD_CHIPS_NB]; /* Center RX frequency of the SX1301 chips, in Hz */ + /* Channels settings */ + uint32_t chan_en[SX1301AR_BOARD_CHIPS_NB][SX1301AR_CHIP_CHAN_NB]; /* Is RX channel enabled or not */ + uint32_t chan_freq[SX1301AR_BOARD_CHIPS_NB][SX1301AR_CHIP_CHAN_NB]; /* Center RX frequency of the channels, in Hz */ + uint8_t multi_sf[SX1301AR_BOARD_CHIPS_NB][SX1301AR_CHIP_MULTI_NB]; /* SF mask for LoRa multi-SF channels */ + sx1301ar_bandw_t lsa_bw[SX1301AR_BOARD_CHIPS_NB]; /* RX bandwidth for the LoRa stand-alone channel */ + uint8_t lsa_sf[SX1301AR_BOARD_CHIPS_NB]; /* Spreading factor for the LoRa stand-alone channel */ + sx1301ar_bandw_t fsk_bw[SX1301AR_BOARD_CHIPS_NB]; /* RX bandwidth for the FSK channel */ + uint32_t fsk_br[SX1301AR_BOARD_CHIPS_NB]; /* Baud rate for the FSK channel */ + /* DSP settings */ + uint8_t dsp_nb; /* Number of DSP */ + int16_t dsp_version; /* DSP version, -1 if unknown */ + uint8_t dsp_stat_interval; + int8_t room_temp_ref; /* reference room temperature (Tref) */ + uint8_t ad9361_temp_ref; /* temperature code returned by radio sensor when room is at Tref */ + /* Options */ + bool match_tmst_crc_err; /* match fine timestamps for packets with CRC error */ + uint8_t main_tmst_version; /* version of the encrypted/main fine timestamp to be sent by the DSP */ + bool debug_tmst; /* enable/disable fine timestamp debug mode of DSP */ +} +brd_cfg_priv[SX1301AR_MAX_BOARD_NB]; + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define CHAN_IF_MAX 1500000 /* filter has ~3 MHz bandwidth */ +#define MULTI_DEFAULT_SF MR_SF7_10 /* LoRa multi-SF default SFs */ +#define LSA_DEFAULT_BW BW_125K /* LoRa stand-alone default bandwidth */ +#define LSA_DEFAULT_SF 10 /* LoRa stand-alone default SF */ +#define FSK_DEFAULT_BW BW_125K /* FSK default bandwidth */ +#define FSK_DEFAULT_MR MR_64K /* FSK default modulation rate */ + + +const char * sx1301ar_version_info( uint8_t brd, int16_t *fpga_version, int16_t *dsp_version ) { + return "LGW2 Simulation"; +} + +/* + Configuration functions + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Affect the internal configuration state of the library. + Check to consistency of user-set parameters. +*/ + +int sx1301ar_conf_tx_gain( uint8_t brd, uint8_t rf_chain, const sx1301ar_tx_gain_lut_t * cfg ); + +int sx1301ar_conf_board( uint8_t brd, const sx1301ar_board_cfg_t * cfg ) +{ + int i, x; + uint64_t sync_word_reg; + + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( cfg->rx_freq_hz < SX1301AR_MIN_FREQ ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + if( (cfg->spi_read == NULL) || (cfg->spi_write == NULL) ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + if( cfg->fsk_sync_size > 8 ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + if( (cfg->rx_bw_hz != 4e6) && (cfg->rx_bw_hz != 7e6) && (cfg->rx_bw_hz != 8e6) && (cfg->rx_bw_hz != 13e6) ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + if( (cfg->board_type != BRD_MASTER) && (cfg->board_type != BRD_SLAVE) ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + if( (cfg->nb_chip == 0) || (cfg->nb_chip > SX1301AR_BOARD_CHIPS_NB) ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + + /* initialize memory for global variables */ + // memset( &brd_channel_diversity_table[brd], 0, sizeof brd_channel_diversity_table[brd] ); + + /* No reconfiguration if board is running */ + if( brd_cfg_priv[brd].is_started == true ) + { + SX1301AR_ERR_RETURN( ERR_CANT_CFG ); + } + + /* Default values */ + brd_cfg_priv[brd].fpga_version = -1; /* unknown yet */ + brd_cfg_priv[brd].dsp_version = -1; /* unknown yet */ + brd_cfg_priv[brd].rf_diversity = false; /* unknown yet */ + + /* Record configuration values */ + brd_cfg_priv[brd].btype = cfg->board_type; + brd_cfg_priv[brd].chip_nb = cfg->nb_chip; + brd_cfg_priv[brd].dsp_nb = cfg->nb_dsp; + brd_cfg_priv[brd].rx_freq = cfg->rx_freq_hz; + brd_cfg_priv[brd].rx_bw = cfg->rx_bw_hz; + brd_cfg_priv[brd].full_duplex = cfg->full_duplex; + for( i = 0; i < SX1301AR_BOARD_RFCHAIN_NB; i++ ) + { + brd_cfg_priv[brd].rf_chain[i].rx_enable = cfg->rf_chain[i].rx_enable; + brd_cfg_priv[brd].rf_chain[i].tx_enable = cfg->rf_chain[i].tx_enable; + brd_cfg_priv[brd].rf_chain[i].rssi_offset = cfg->rf_chain[i].rssi_offset; + brd_cfg_priv[brd].rf_chain[i].rssi_offset_coeff_a = cfg->rf_chain[i].rssi_offset_coeff_a; + brd_cfg_priv[brd].rf_chain[i].rssi_offset_coeff_b = cfg->rf_chain[i].rssi_offset_coeff_b; + if( cfg->rf_chain[i].tx_lut.size > 0 ) + { + x = sx1301ar_conf_tx_gain( brd, i, &(cfg->rf_chain[i].tx_lut) ); + if( x != 0 ) + { + printf( "ERROR: failed to configure TX Gain LUT for RF chain %d (%s)\n", i, sx1301ar_err_message( sx1301ar_errno ) ); + } + } + } + brd_cfg_priv[brd].room_temp_ref = cfg->room_temp_ref; + brd_cfg_priv[brd].ad9361_temp_ref = cfg->ad9361_temp_ref; + + brd_cfg_priv[brd].fsk_sync_size = cfg->fsk_sync_size; + if( cfg->fsk_sync_size > 0 ) + { + sync_word_reg = cfg->fsk_sync_word << (8 - cfg->fsk_sync_size) * 8; /* left-align the sync word */ + brd_cfg_priv[brd].fsk_sync_msb = 0xFFFFFFFF & (sync_word_reg >> 32); + brd_cfg_priv[brd].fsk_sync_lsb = 0xFFFFFFFF & sync_word_reg; + } + brd_cfg_priv[brd].loramac_public = cfg->loramac_public; + brd_cfg_priv[brd].dsp_stat_interval = cfg->dsp_stat_interval; + // memcpy(brd_aes_key[brd], cfg->aes_key, sizeof brd_aes_key[brd]); + + brd_cfg_priv[brd].match_tmst_crc_err = cfg->match_tmst_crc_err; + brd_cfg_priv[brd].main_tmst_version = cfg->main_tmst_version; + brd_cfg_priv[brd].debug_tmst = cfg->debug_tmst; + + /* Record SPI callbacks */ + // return sx1301ar_reg_setup( brd, cfg->board_type, cfg->spi_read, cfg->spi_write ); + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_get_conf_board( uint8_t brd, sx1301ar_board_cfg_t * cfg ) +{ + int i; + + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( cfg == NULL ) + { + SX1301AR_ERR_RETURN( ERR_NULL_POINTER ); + } + + /* Get recorded configuration values */ + cfg->board_type = brd_cfg_priv[brd].btype; + cfg->nb_chip = brd_cfg_priv[brd].chip_nb; + cfg->nb_dsp = brd_cfg_priv[brd].dsp_nb; + cfg->rx_freq_hz = brd_cfg_priv[brd].rx_freq; + cfg->rx_bw_hz = brd_cfg_priv[brd].rx_bw; + cfg->full_duplex = brd_cfg_priv[brd].full_duplex; + for( i = 0; i < SX1301AR_BOARD_RFCHAIN_NB; i++ ) + { + cfg->rf_chain[i].rx_enable = brd_cfg_priv[brd].rf_chain[i].rx_enable; + cfg->rf_chain[i].tx_enable = brd_cfg_priv[brd].rf_chain[i].tx_enable; + } + + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_conf_chip( uint8_t brd, uint8_t chip, const sx1301ar_chip_cfg_t * cfg ) +{ + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( chip >= SX1301AR_BOARD_CHIPS_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CHIP_NB ); + } + if( (cfg->enable == true) && (cfg->freq_hz < SX1301AR_MIN_FREQ) ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + + /* No reconfiguration if board is running */ + if( brd_cfg_priv[brd].is_started == true ) + { + SX1301AR_ERR_RETURN( ERR_CANT_CFG ); + } + + /* Record enable setting */ + brd_cfg_priv[brd].chip_en[chip] = cfg->enable; + brd_cfg_priv[brd].chip_rf_chain[chip] = cfg->rf_chain; + + if( cfg->enable == true ) + { + /* Record frequency setting */ + brd_cfg_priv[brd].chip_freq[chip] = cfg->freq_hz; + } + + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_conf_chan( uint8_t brd, uint8_t chan, const sx1301ar_chan_cfg_t * cfg ) +{ + uint8_t chip = chan >> 4; + uint8_t cx = chan & 0x0F; /* local channel address in the chip */ + int sf; + + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( chip >= SX1301AR_BOARD_CHIPS_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CHAN_NB ); + } + if( cx >= SX1301AR_CHIP_CHAN_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CHAN_NB ); + } + if( (cfg->enable == true) && (cfg->freq_hz < SX1301AR_MIN_FREQ) ) + { + SX1301AR_ERR_RETURN( ERR_BAD_CFG ); + } + + /* No reconfiguration if board is running */ + if( brd_cfg_priv[brd].is_started == true ) + { + SX1301AR_ERR_RETURN( ERR_CANT_CFG ); + } + + /* Record enable setting */ + brd_cfg_priv[brd].chan_en[chip][cx] = cfg->enable; + + if( cfg->enable == true ) + { + /* Check that the corresponding chip is enabled */ + if( brd_cfg_priv[brd].chip_en[chip] == false ) + { + SX1301AR_ERR_RETURN( ERR_CHIP_DISABLE ); + } + + /* Check channel frequency against radio & chip configuration: + * => we want to ensure that all channels fit in the the sx1301 band + * AND in the radio band. + * Note: the sx1301 bandwidth could be partly outside from the radio + * band as long as there is no channel in this "outer" band. + * + * rx_freq (ad9361) + * ^ chip_freq (sx1301) + * | ^ chan_freq + * | | ^ + * | | | + * |<----------rx_bw/2--------> + * -----------------------------|--------------------|----|-- + * / | | | \ + * / | -----------|----|---\-- + * | /<--------->| | \ \ + * | / CHAN_IF_MAX| | \ \ + * | / | | \ \ + *--------------------------------|-----/--------------|-|--|--|----\-\----->f + * | / |<--->| \ \ + * | chan_bw + */ + /* Check that the channel is in the SX1301 band */ + if( cfg->freq_hz > (brd_cfg_priv[brd].chip_freq[chip] + CHAN_IF_MAX - sx1301ar_bw_enum2nb(cfg->bandwidth)/2) ) + { + SX1301AR_ERR_RETURN( ERR_IF_LIMIT ); + } + if( cfg->freq_hz < (brd_cfg_priv[brd].chip_freq[chip] - CHAN_IF_MAX + sx1301ar_bw_enum2nb(cfg->bandwidth)/2) ) + { + SX1301AR_ERR_RETURN( ERR_IF_LIMIT ); + } + /* Check that the channel is in the radio band */ + if( cfg->freq_hz > (brd_cfg_priv[brd].rx_freq + brd_cfg_priv[brd].rx_bw/2 - sx1301ar_bw_enum2nb(cfg->bandwidth)/2) ) + { + SX1301AR_ERR_RETURN( ERR_IF_LIMIT ); + } + if( cfg->freq_hz < (brd_cfg_priv[brd].rx_freq - brd_cfg_priv[brd].rx_bw/2 + sx1301ar_bw_enum2nb(cfg->bandwidth)/2) ) + { + SX1301AR_ERR_RETURN( ERR_IF_LIMIT ); + } + + /* Record frequency setting */ + brd_cfg_priv[brd].chan_freq[chip][cx] = cfg->freq_hz; + + /* Check and record channel-specific settings */ + if( cx < SX1301AR_CHIP_MULTI_NB ) + { + /* LoRa multi-SF channel */ + if( (cfg->bandwidth != BW_UNDEFINED) && (cfg->bandwidth != BW_125K) ) + { + SX1301AR_ERR_RETURN( ERR_INVALID_BW ); /* only 125 kHz bandwidth is supported */ + } + + if( cfg->modrate == MR_UNDEFINED ) + { + brd_cfg_priv[brd].multi_sf[chip][cx] = MULTI_DEFAULT_SF; /* force default setting */ + } + else if( (cfg->modrate & ~MR_SF7_12) == 0 ) + { + brd_cfg_priv[brd].multi_sf[chip][cx] = (uint8_t)(cfg->modrate & MR_SF7_12); + } + else + { + SX1301AR_ERR_RETURN( ERR_INVALID_SF ); + } + } + else if( cx == SX1301AR_CHIP_LSA_IDX ) + { + /* LoRa stand-alone channel */ + if( cfg->bandwidth == BW_UNDEFINED ) + { + brd_cfg_priv[brd].lsa_bw[chip] = LSA_DEFAULT_BW; /* force default setting */ + } + else if( (cfg->bandwidth == BW_125K) || (cfg->bandwidth == BW_250K) || (cfg->bandwidth == BW_500K) ) + { + brd_cfg_priv[brd].lsa_bw[chip] = cfg->bandwidth; + } + else + { + SX1301AR_ERR_RETURN( ERR_INVALID_BW ); + } + + if( cfg->modrate == MR_UNDEFINED ) + { + brd_cfg_priv[brd].lsa_sf[chip] = LSA_DEFAULT_SF; /* force default setting */ + } + else + { + sf = sx1301ar_sf_enum2nb( cfg->modrate ); + if( sf != -1 ) + { + brd_cfg_priv[brd].lsa_sf[chip] = sf; + } + else + { + SX1301AR_ERR_RETURN( ERR_INVALID_SF ); + } + } + } + else if( cx == SX1301AR_CHIP_FSK_IDX ) + { + /* FSK channel */ + if( cfg->bandwidth == BW_UNDEFINED ) + { + brd_cfg_priv[brd].fsk_bw[chip] = FSK_DEFAULT_BW; /* force default setting */ + } + else if( cfg->bandwidth <= BW_7K8 ) /* bandwidth index in the enum is inversely proportional to bandwidth */ + { + brd_cfg_priv[brd].fsk_bw[chip] = cfg->bandwidth; + } + else + { + SX1301AR_ERR_RETURN( ERR_INVALID_BW ); + } + + if( cfg->modrate == MR_UNDEFINED ) + { + brd_cfg_priv[brd].fsk_br[chip] = FSK_DEFAULT_MR; + } + else if( (cfg->modrate >= MR_300) && (cfg->modrate <= MR_250K) ) + { + brd_cfg_priv[brd].fsk_br[chip] = cfg->modrate; + } + else + { + SX1301AR_ERR_RETURN( ERR_INVALID_BR ); + } + } + } + + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_conf_lbt( uint8_t brd, const sx1301ar_lbt_cfg_t * cfg ) +{ + + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( cfg == NULL ) + { + SX1301AR_ERR_RETURN( ERR_NULL_POINTER ); + } + + /* No reconfiguration if board is running */ + if( brd_cfg_priv[brd].is_started == true ) + { + SX1301AR_ERR_RETURN( ERR_CANT_CFG ); + } + + // x = sx1301ar_i_conf_lbt( brd, cfg ); + // SX1301AR_ERR_PROPAGATE( x ); + + return 0; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_conf_tx_gain( uint8_t brd, uint8_t rf_chain, const sx1301ar_tx_gain_lut_t * cfg ) +{ + int i; + + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( cfg == NULL ) + { + SX1301AR_ERR_RETURN( ERR_NULL_POINTER ); + } + if( (cfg->size < 1) || (cfg->size > SX1301AR_BOARD_MAX_LUT_NB) ) + { + SX1301AR_ERR_RETURN( ERR_INVALID_LUT ); + } + if( rf_chain >= SX1301AR_BOARD_RFCHAIN_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_RFCHAIN_NB ); + } + + /* Update internal TX gain LUT with given values */ + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.size = cfg->size; + + for( i = 0; i < cfg->size; i++ ) + { + /* Check parameter range */ + if( cfg->lut[i].fpga_dig_gain > 13 ) + { + SX1301AR_ERR_RETURN( ERR_INVALID_LUT ); + } + if( cfg->lut[i].ad9361_gain.auxdac_word > 1023 ) + { + SX1301AR_ERR_RETURN( ERR_INVALID_LUT ); + } + + + /* Set internal LUT */ + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].rf_power = cfg->lut[i].rf_power; + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].fpga_dig_gain = cfg->lut[i].fpga_dig_gain; + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].ad9361_gain.atten = cfg->lut[i].ad9361_gain.atten; + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].ad9361_gain.auxdac_vref = cfg->lut[i].ad9361_gain.auxdac_vref; + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].ad9361_gain.auxdac_word = cfg->lut[i].ad9361_gain.auxdac_word; + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].ad9361_tcomp.coeff_a = cfg->lut[i].ad9361_tcomp.coeff_a; + brd_cfg_priv[brd].rf_chain[rf_chain].tx_lut.lut[i].ad9361_tcomp.coeff_b = cfg->lut[i].ad9361_tcomp.coeff_b; + } + + return 0; +} + +/* + Core functions + ~~~~~~~~~~~~~~~ + + Interact with the hardware concentrator board. +*/ + +int sx1301ar_start( uint8_t nb_brd ) { + const char* sockPath = getenv("LORAGW_SPI"); + if( aio ) + return -1; + memset(&cca_msg, 0, sizeof(cca_msg)); + memset(&sockAddr, 0, sizeof(sockAddr)); + // Make xticks different from ustime to cover more test ground. + // xticks start at ~(1<<28) whenever a radio simulation starts. + timeOffset = sys_time() - 0x10000000; + sockAddr.sun_family = AF_UNIX; + snprintf(sockAddr.sun_path, sizeof(sockAddr.sun_path), "%s", sockPath); + rt_yieldTo(&conn_tmr, try_connecting); + return 0; +} + +int sx1301ar_stop( uint8_t nb_brd ) { + rt_clrTimer(&conn_tmr); + txbeg = txend = 0; + aio_close(aio); + aio = NULL; + return 0; +} + +int sx1301ar_fetch( uint8_t brd, sx1301ar_rx_pkt_t * p, uint8_t max_nb, uint8_t * nb_pkt ) { + int npkts = 0; + while( npkts < max_nb && rbused(rx_widx, rx_ridx, rxblen) >= sizeof(rx_pkts[0]) ){ + p[npkts] = rx_pkts[rx_ridx/sizeof(rx_pkts[0])]; + rx_ridx = (rx_ridx+sizeof(rx_pkts[0])) % rxblen; + npkts += 1; + } + if( npkts ) + LOG(MOD_SIM|DEBUG, "LGWSIM(%s): received %d packets", sockAddr.sun_path, npkts); + *nb_pkt = npkts; + return 0; +} + +int sx1301ar_send( uint8_t brd, const sx1301ar_tx_pkt_t * p ) { + sL_t t = xticks(); + txbeg = t + (s4_t)((u4_t)p->count_us - (u4_t)t); + txend = txbeg + airtime(p->modrate, p->bandwidth, p->size); + if( !cca(txbeg, p->freq_hz) ) + return -1; + tx_pkt = *p; + if( !aio || aio->ctx == NULL || aio->fd == 0 ) + return -1; + aio_set_wrfn(aio, write_socket); + write_socket(aio); + return 0; +} + +int sx1301ar_tx_status( uint8_t brd, sx1301ar_tstat_t * s ) { + sL_t t = xticks(); + if( t <= txbeg ) + *s = TX_SCHEDULED; + else if( t <= txend ) + *s = TX_EMITTING; + else + *s = TX_FREE; + return 0; + +} + +int sx1301ar_abort_tx( uint8_t brd ) { + txbeg = txend = 0; + return 0; +} + +// int sx1301ar_brd_status( uint8_t brd, sx1301ar_bstat_t * s ) { +// return 0; +// } + +int sx1301ar_get_instcnt( uint8_t brd, uint32_t * cnt_us ) { + sL_t t = xticks(); + cnt_us[0] = t & 0xFFffFFff; + return 0; +} + +int sx1301ar_get_trigcnt( uint8_t brd, uint32_t * cnt_us ) { + sL_t t = xticks(); + t -= sys_utc()%1000000; + cnt_us[0] = t & 0xFFffFFff; + return 0; +} + +// int sx1301ar_get_trighs( uint8_t brd, uint32_t * cnt_hs) { +// return 0; +// } + +// int sx1301ar_get_temperature( uint8_t brd, uint8_t * temp_code, int16_t * temp_celsius ) { +// return 0; +// } + +// double sx1301ar_rx_pkt_time_on_air( const sx1301ar_rx_pkt_t * pkt, double * t_preamble, double * t_syncword, double * t_payload ) { +// return 0; +// } + +// double sx1301ar_tx_pkt_time_on_air( uint8_t brd, const sx1301ar_tx_pkt_t * pkt, double * t_preamble, double * t_syncword, double * t_payload ) { +// return 0; +// } + +/* + Helper functions + ~~~~~~~~~~~~~~~~~ + + Assist for internal types manipulation. + Initialize structures defined by the library. + Covert to/from abstract (enum) types. +*/ + +sx1301ar_board_cfg_t sx1301ar_init_board_cfg( void ) +{ + sx1301ar_board_cfg_t a; + int i; + + a.board_type = BRD_TYPE_UNKNOWN; + a.spi_read = NULL; + a.spi_write = NULL; + a.rx_freq_hz = 0; + a.rx_bw_hz = 0; + a.full_duplex = false; + + /* RF chain initialization */ + for( i = 0; i < SX1301AR_BOARD_RFCHAIN_NB; i++ ) + { + a.rf_chain[i].rx_enable = false; + a.rf_chain[i].tx_enable = false; + a.rf_chain[i].rssi_offset = SX1301AR_DEFAULT_RSSI_OFFSET; + a.rf_chain[i].rssi_offset_coeff_a = 0; + a.rf_chain[i].rssi_offset_coeff_b = 0; + a.rf_chain[i].tx_lut = sx1301ar_init_tx_gain_lut( ); + } + + /* No board-specific corrections */ + a.room_temp_ref = SX1301AR_DEFAULT_ROOM_TEMP_REF; + a.ad9361_temp_ref = SX1301AR_DEFAULT_AD9361_TEMP_REF; + + /* Phy parameters that are protocol dependant */ + a.fsk_sync_word = 0; + a.fsk_sync_size = 0; + a.loramac_public = false; + + /* Localization parameters */ + a.dsp_stat_interval = 0; /* Turn off dsp report by default */ + memset(a.aes_key, 0, sizeof a.aes_key); + a.match_tmst_crc_err = false; + a.main_tmst_version = SX1301AR_DEFAULT_FTS_VERSION; + a.debug_tmst = false; + + a.nb_chip = 0; + a.nb_dsp = 0; + + return a; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_chip_cfg_t sx1301ar_init_chip_cfg( void ) +{ + sx1301ar_chip_cfg_t a; + + a.enable = false; + a.freq_hz = 0; + a.rf_chain = 0; + + return a; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_chan_cfg_t sx1301ar_init_chan_cfg( void ) +{ + sx1301ar_chan_cfg_t a; + + a.enable = false; + a.freq_hz = 0; + a.modrate = MR_UNDEFINED; + a.bandwidth = BW_UNDEFINED; + + return a; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_lbt_cfg_t sx1301ar_init_lbt_cfg( void ) +{ + sx1301ar_lbt_cfg_t a; + + a.enable = false; + a.rssi_target = 0; + a.rssi_shift = 0; + a.nb_channel = 0; + memset( a.channels, 0, sizeof a.channels ); + + return a; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_tx_pkt_t sx1301ar_init_tx_pkt( void ) +{ + sx1301ar_tx_pkt_t a; + + a.tx_mode = TX_IMMEDIATE; + a.count_us = 0; + a.freq_hz = 0; + a.rf_power = 0; + a.modulation = MOD_UNDEFINED; + a.bandwidth = BW_UNDEFINED; + a.modrate = MR_UNDEFINED; + a.coderate = CR_UNDEFINED; + a.f_dev = 0; + a.preamble = 0; + a.invert_pol = false; + a.no_crc = false; + a.no_header = false; + a.size = 0; + memset( (void *)(a.payload), 0, ARRAY_SIZE(a.payload) ); + + return a; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_tx_gain_t sx1301ar_init_tx_gain( void ) +{ + sx1301ar_tx_gain_t a; + + a.rf_power = 0; + a.fpga_dig_gain = 0; + a.ad9361_gain.atten = 0; + a.ad9361_gain.auxdac_vref = 0; + a.ad9361_gain.auxdac_word = 0; + a.ad9361_tcomp.coeff_a = 0; + a.ad9361_tcomp.coeff_b = 0; + + return a; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_tx_gain_lut_t sx1301ar_init_tx_gain_lut( void ) +{ + sx1301ar_tx_gain_lut_t a; + + a.size = SX1301AR_BOARD_MAX_LUT_NB; + memset( a.lut, 0, sizeof( sx1301ar_tx_gain_lut_t ) ); + + return a; +} + + +sx1301ar_modr_t sx1301ar_sf_nb2enum( int x ) +{ + switch( x ) + { + case 7 : return MR_SF7; + case 8 : return MR_SF8; + case 9 : return MR_SF9; + case 10: return MR_SF10; + case 11: return MR_SF11; + case 12: return MR_SF12; + default: return MR_UNDEFINED; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_sf_enum2nb( sx1301ar_modr_t x ) +{ + switch( x ) + { + case MR_SF7 : return 7; + case MR_SF8 : return 8; + case MR_SF9 : return 9; + case MR_SF10: return 10; + case MR_SF11: return 11; + case MR_SF12: return 12; + default: return -1; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_modr_t sx1301ar_sf_range_nb2enum( int a, int b ) +{ + switch( a ) + { + case 7 : + switch( b ) + { + case 7 : return MR_SF7; + case 8 : return MR_SF7_8; + case 9 : return MR_SF7_9; + case 10: return MR_SF7_10; + case 11: return MR_SF7_11; + case 12: return MR_SF7_12; + default: return MR_UNDEFINED; + } + case 8 : + switch( b ) + { + case 7 : return MR_SF7_8; + case 8 : return MR_SF8; + case 9 : return MR_SF8_9; + case 10: return MR_SF8_10; + case 11: return MR_SF8_11; + case 12: return MR_SF8_12; + default: return MR_UNDEFINED; + } + case 9 : + switch( b ) + { + case 7 : return MR_SF7_9; + case 8 : return MR_SF8_9; + case 9 : return MR_SF9; + case 10: return MR_SF9_10; + case 11: return MR_SF9_11; + case 12: return MR_SF9_12; + default: return MR_UNDEFINED; + } + case 10: + switch( b ) + { + case 7 : return MR_SF7_10; + case 8 : return MR_SF8_10; + case 9 : return MR_SF9_10; + case 10: return MR_SF10; + case 11: return MR_SF10_11; + case 12: return MR_SF10_12; + default: return MR_UNDEFINED; + } + case 11: + switch( b ) + { + case 7 : return MR_SF7_11; + case 8 : return MR_SF8_11; + case 9 : return MR_SF9_11; + case 10: return MR_SF10_11; + case 11: return MR_SF11; + case 12: return MR_SF11_12; + default: return MR_UNDEFINED; + } + case 12: + switch( b ) + { + case 7 : return MR_SF7_12; + case 8 : return MR_SF8_12; + case 9 : return MR_SF9_12; + case 10: return MR_SF10_12; + case 11: return MR_SF11_12; + case 12: return MR_SF12; + default: return MR_UNDEFINED; + } + default: return MR_UNDEFINED; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_sf_min_enum2nb( sx1301ar_modr_t x ) +{ + switch( x ) + { + case MR_SF7 : return 7; + case MR_SF7_8 : return 7; + case MR_SF7_9 : return 7; + case MR_SF7_10 : return 7; + case MR_SF7_11 : return 7; + case MR_SF7_12 : return 7; + case MR_SF8 : return 8; + case MR_SF8_9 : return 8; + case MR_SF8_10 : return 8; + case MR_SF8_11 : return 8; + case MR_SF8_12 : return 8; + case MR_SF9 : return 9; + case MR_SF9_10 : return 9; + case MR_SF9_11 : return 9; + case MR_SF9_12 : return 9; + case MR_SF10 : return 10; + case MR_SF10_11: return 10; + case MR_SF10_12: return 10; + case MR_SF11 : return 11; + case MR_SF11_12: return 11; + case MR_SF12 : return 12; + default: return -1; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_sf_max_enum2nb( sx1301ar_modr_t x ) +{ + switch( x ) + { + case MR_SF7 : return 7; + case MR_SF7_8 : return 8; + case MR_SF7_9 : return 9; + case MR_SF7_10 : return 10; + case MR_SF7_11 : return 11; + case MR_SF7_12 : return 12; + case MR_SF8 : return 8; + case MR_SF8_9 : return 9; + case MR_SF8_10 : return 10; + case MR_SF8_11 : return 11; + case MR_SF8_12 : return 12; + case MR_SF9 : return 9; + case MR_SF9_10 : return 10; + case MR_SF9_11 : return 11; + case MR_SF9_12 : return 12; + case MR_SF10 : return 10; + case MR_SF10_11: return 11; + case MR_SF10_12: return 12; + case MR_SF11 : return 11; + case MR_SF11_12: return 12; + case MR_SF12 : return 12; + default: return -1; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_coder_t sx1301ar_cr_nb2enum( int x ) +{ + switch( x ) + { + case 1: return CR_4_5; + case 2: return CR_4_6; + case 3: return CR_4_7; + case 4: return CR_4_8; + default: return CR_UNDEFINED; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +int sx1301ar_cr_enum2nb( sx1301ar_coder_t x ) +{ + switch( x ) + { + case CR_4_5: return 1; + case CR_4_6: return 2; + case CR_4_7: return 3; + case CR_4_8: return 4; + default: return -1; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +const char * sx1301ar_cr_enum2str( sx1301ar_coder_t x ) +{ + switch( x ) + { + case CR_4_5: return "4/5"; + case CR_4_6: return "4/6"; + case CR_4_7: return "4/7"; + case CR_4_8: return "4/8"; + default: return "???"; + } +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +sx1301ar_bandw_t sx1301ar_bw_nb2enum( long x ) +{ + if( x <= 0 ) return BW_UNDEFINED; + else if( x <= 7800 ) return BW_7K8; + else if( x <= 15600 ) return BW_15K6; + else if( x <= 31200 ) return BW_31K2; + else if( x <= 62500 ) return BW_62K5; + else if( x <= 125000 ) return BW_125K; + else if( x <= 250000 ) return BW_250K; + else if( x <= 500000 ) return BW_500K; + else return BW_UNDEFINED; +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +long sx1301ar_bw_enum2nb( sx1301ar_bandw_t x ) +{ + switch( x ) + { + case BW_500K: return 500000; + case BW_250K: return 250000; + case BW_125K: return 125000; + case BW_62K5: return 62500; + case BW_31K2: return 31200; + case BW_15K6: return 15600; + case BW_7K8 : return 7800; + default: return -1; + } +} + +// int8_t sx1301ar_ad9361_temp2atten( uint8_t T, uint8_t Tref, int16_t a, int16_t b ) { +// return 0; +// } + +// float sx1301ar_ad9361_temp2rssi( uint8_t T, uint8_t Tref, int16_t a, int16_t b ) { +// return 0; +// } + +/** sx1301ar_gps.c ___________________________________________________________________ */ + +sx1301ar_tref_t sx1301ar_init_tref( void ) +{ + sx1301ar_tref_t a; + + a.systime = (time_t)(-1); + a.hs_pps = 0; + a.count_us = 0; + a.utc.tv_sec = (time_t)(-1); + a.utc.tv_nsec = 0; + a.xtal_err = 1.0; + a.xtal_hs_err = 1.0; + a.sync_cnt = 0; + + return a; +} + +int sx1301ar_set_xtal_err( uint8_t brd, sx1301ar_tref_t ref ) { + return 0; +} + +/** sx1301ar_dsp.c ___________________________________________________________________ */ + +int sx1301ar_get_trighs( uint8_t brd, uint32_t * cnt_hs) +{ + /* Check input parameters */ + if( brd >= SX1301AR_MAX_BOARD_NB ) + { + SX1301AR_ERR_RETURN( ERR_BAD_BOARD_NB ); + } + if( cnt_hs == NULL ) + { + SX1301AR_ERR_RETURN( ERR_NULL_POINTER ); + } + + /* Get high speed counter value at last PPS (HSPPS) */ + sL_t t = xticks(); + t -= sys_utc()%1000000; + cnt_hs[0] = (t & 0xFFffFFff)*256; + return 0; +} + +#endif + // LCOV_EXCL_STOP #endif // CFG_lgwsim diff --git a/src/log.c b/src/log.c index 217c637..5783ddd 100644 --- a/src/log.c +++ b/src/log.c @@ -1,32 +1,32 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "s2conf.h" #include "sys.h" #include "rt.h" #include "uj.h" @@ -63,7 +63,7 @@ const char* MODSTR[] = { #define CFG_logini_lvl INFO #endif -static char logline[512]; +static char logline[LOGLINE_LEN]; static dbuf_t logbuf = { .buf=logline, .bufsize=sizeof(logline), .pos=0 }; static char slaveMod[4]; static u1_t logLevels[32] = { @@ -178,4 +178,11 @@ void log_flush () { xeol(&logbuf); xeos(&logbuf); sys_addLog(logbuf.buf, logbuf.pos); + logbuf.pos = 0; } + +void log_flushIO () { + log_flush(); + sys_addLog(logbuf.buf, 0); +} + diff --git a/src/lora.c b/src/lora.c index fac59bb..3ad023a 100644 --- a/src/lora.c +++ b/src/lora.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "s2conf.h" @@ -85,13 +84,16 @@ u4_t s2e_netidFilter[4] = { 0xffFFffFF, 0xffFFffFF, 0xffFFffFF, 0xffFFffFF }; int s2e_parse_lora_frame (ujbuf_t* buf, const u1_t* frame , int len, dbuf_t* lbuf) { + if( len == 0 ) { + badframe: + LOG(MOD_S2E|DEBUG, "Not a LoRaWAN frame: %16.4H", len, frame); + return 0; + } int ftype = frame[OFF_mhdr] & MHDR_FTYPE; - if( (len < OFF_df_minlen) || + if( (len < OFF_df_minlen && ftype != FRMTYPE_PROP) || // (FTYPE_BIT(ftype) & DNFRAME_TYPE) != 0 || --- because of device_mode feature we parse everything (frame[OFF_mhdr] & (MHDR_RFU|MHDR_MAJOR)) != MAJOR_V1 ) { - badframe: - LOG(MOD_S2E|DEBUG, "Not a LoRaWAN UP frame: %16.4H", len, frame); - return 0; + goto badframe; } if( ftype == FRMTYPE_PROP || ftype == FRMTYPE_JACC ) { str_t msgtype = ftype == FRMTYPE_PROP ? "propdf" : "jacc"; @@ -126,13 +128,13 @@ int s2e_parse_lora_frame (ujbuf_t* buf, const u1_t* frame , int len, dbuf_t* lbu uj_encKVn(buf, "msgtype", 's', msgtype, "MHdr", 'i', mhdr, - "JoinEui", 'E', joineui, - "DevEui", 'E', deveui, + rt_joineui,'E', joineui, + rt_deveui, 'E', deveui, "DevNonce",'i', devnonce, "MIC", 'i', mic, NULL); - xprintf(lbuf, "%s MHdr=%02X JoinEui=%:E DevEui=%:E DevNonce=%d MIC=%d", - msgtype, mhdr, joineui, deveui, devnonce, mic); + xprintf(lbuf, "%s MHdr=%02X %s=%:E %s=%:E DevNonce=%d MIC=%d", + msgtype, mhdr, rt_joineui, joineui, rt_deveui, deveui, devnonce, mic); return 1; } u1_t foptslen = frame[OFF_fctrl] & 0xF; @@ -168,3 +170,48 @@ int s2e_parse_lora_frame (ujbuf_t* buf, const u1_t* frame , int len, dbuf_t* lbu max(0, len-4-portoff), &frame[portoff], mic, len); return 1; } + + +static int crc16_no_table(uint8_t* pdu, int len) { + uint32_t remainder = 0; + uint32_t polynomial = 0x1021; + for( int i=0; i>(8*i); + uint32_t ulon = (uint32_t)(lon / 180 * (1U<<31)); + uint32_t ulat = (uint32_t)(lat / 90 * (1U<<31)); + for( int i=0; i<3; i++ ) { + pdu[infodesc_off+1+i] = ulon>>(8*i); + pdu[infodesc_off+4+i] = ulat>>(8*i); + } + pdu[infodesc_off] = infodesc; + int crc1 = crc16_no_table(&pdu[0],infodesc_off-2); + int crc2 = crc16_no_table(&pdu[infodesc_off], bcn_len-2-infodesc_off); + for( int i=0; i<2; i++ ) { + pdu[infodesc_off-2] = crc1>>(8*i); + pdu[bcn_len-2] = crc2>>(8*i); + } +} diff --git a/src/net.c b/src/net.c index fbfa02b..c14953b 100644 --- a/src/net.c +++ b/src/net.c @@ -1,32 +1,33 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "s2conf.h" #include "sys.h" #include "uj.h" #include "ws.h" @@ -508,7 +509,7 @@ static void ws_closing_w (aio_t* aio) { static void ws_connected_w (aio_t* aio) { ws_t* conn = (ws_t*)aio->ctx; assert(conn->state == WS_CONNECTED); - LOG(MOD_AIO|XDEBUG, "[%d] ws_connected_w state=%d", conn->netctx.fd, conn->state); + // LOG(MOD_AIO|XDEBUG, "[%d] ws_connected_w state=%d", conn->netctx.fd, conn->state); int e; again: if( conn->wpos < conn->wend ) { @@ -558,7 +559,7 @@ static void ws_connected_w (aio_t* aio) { static void ws_connected_r (aio_t* aio) { ws_t* conn = (ws_t*)aio->ctx; assert(conn->state >= WS_CONNECTED); // also called during close - LOG(MOD_AIO|XDEBUG, "[%d] ws_connected_r state=%d", conn->netctx.fd, conn->state); + // LOG(MOD_AIO|XDEBUG, "[%d|WS] ws_connected_r state=%d", conn->netctx.fd, conn->state); int e; again: if( (e = readData(conn, WS_FRAME)) == IO_ERROR ) { @@ -571,12 +572,34 @@ static void ws_connected_r (aio_t* aio) { u1_t* p = &conn->rbuf[conn->rbeg]; u1_t opcode = p[-1]; switch(opcode) { - case WSHDR_PING: + case WSHDR_PING: { + int plen = conn->rend-conn->rbeg; + LOG(MOD_AIO|XDEBUG, "[%d|WS] < PING (%H)", conn->netctx.fd, plen, p); + dbuf_t wbuf = ws_getSendbuf(conn, plen); + if( wbuf.buf == NULL ) { + LOG(MOD_AIO|WARNING, "[%d] Cannot respond to PING message of length %d", conn->netctx.fd, plen); + break; + } + wbuf.buf[0-WSHDR_INTRA] = plen>>8; + wbuf.buf[1-WSHDR_INTRA] = plen; + wbuf.buf[2-WSHDR_INTRA] = WSHDR_PONG; + conn->wfill += plen+WSHDR_INTRA; + memcpy(wbuf.buf, p, plen); + aio_set_wrfn(conn->aio, ws_connected_w); + LOG(MOD_AIO|XDEBUG, "[%d|WS] > PONG", conn->netctx.fd); + break; + } case WSHDR_PONG: { - LOG(MOD_AIO|WARNING, "[%d] Ignoring WS ping/pong message", conn->netctx.fd); + LOG(MOD_AIO|XDEBUG, "[%d|WS] Ignoring incoming WS PONG", conn->netctx.fd); break; } case WSHDR_TEXT: { + int offset = 0; + int plen = conn->rend - conn->rbeg; + while( offset < plen ) { + LOG(MOD_AIO|XDEBUG, "[%d|WS] %c %.*s", conn->netctx.fd, offset ? '.' : '<', min((LOGLINE_LEN-50),plen-offset), p+offset); + offset += (LOGLINE_LEN-50); + } conn->evcb(conn, WSEV_TEXTRCVD); if( conn->aio == NULL ) return; @@ -590,7 +613,7 @@ static void ws_connected_r (aio_t* aio) { } case WSHDR_CLOSE: { u2_t reason = rt_rmsbf2(p); - LOG(MOD_AIO|DEBUG, "[%d] Server sent close: reason=%d", conn->netctx.fd, reason); + LOG(MOD_AIO|DEBUG, "[%d|WS] Server sent close: reason=%d", conn->netctx.fd, reason); if( conn->state > WS_CONNECTED ) { ws_shutdown(conn); return; @@ -600,7 +623,7 @@ static void ws_connected_r (aio_t* aio) { break; } default: { - LOG(MOD_AIO|WARNING, "[%d] Unsupported WS opcode: %d", conn->netctx.fd, opcode); + LOG(MOD_AIO|WARNING, "[%d|WS] Unsupported WS opcode: %d", conn->netctx.fd, opcode); break; } } @@ -682,6 +705,13 @@ static void ws_handshaking (aio_t* aio) { aio_set_wrfn(conn->aio, ws_handshaking); return; } + if( err == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) { + char errmsg[128] = {0}; + u4_t flags = mbedtls_ssl_get_verify_result(conn->tlsctx); + mbedtls_x509_crt_verify_info(errmsg, sizeof(errmsg), "", flags); + LOG(MOD_AIO|INFO, "TLS server certificate verification failed: %.*s", sizeof(errmsg), errmsg) + } + ws_shutdown(conn); return; } @@ -797,6 +827,13 @@ void ws_sendData (ws_t* conn, dbuf_t* b, int binaryData) { void ws_sendText (ws_t* conn, dbuf_t* b) { + int offset = 0; + int plen = b->pos; + while( offset < plen ) { + LOG(MOD_AIO|XDEBUG, "[%d|WS] %c %.*s", conn->netctx.fd, offset ? '.' : '>', min((LOGLINE_LEN-50),plen-offset), b->buf+offset); + offset += (LOGLINE_LEN-50); + } + ws_sendData(conn, b, 0); } @@ -845,6 +882,8 @@ void ws_free (ws_t* conn) { conn->host = NULL; conn->port = NULL; conn->uripath = NULL; + rt_free((void*)conn->authtoken); + conn->authtoken = NULL; rt_clrTimer(&conn->tmr); aio_close(conn->aio); conn->aio = NULL; @@ -1397,12 +1436,12 @@ static int validateAuthToken (str_t s) { return 0; if( p[1] == 0 ) return 1; - s = p+1; // next line + s = p = p+1; // next line } } -int conn_setup_tls (conn_t* conn, int cred_cat, int cred_set) { +int conn_setup_tls (conn_t* conn, int cred_cat, int cred_set, const char* servername) { tlsconf_t* tlsconf = tls_makeConf(); str_t elems[SYS_CRED_NELEMS]; int elemslen[SYS_CRED_NELEMS]; @@ -1444,7 +1483,7 @@ int conn_setup_tls (conn_t* conn, int cred_cat, int cred_set) { LOG(MOD_AIO|INFO, errmsg, sys_credcat2str(cred_cat), sys_credset2str(cred_set)); assert(conn->tlsconf==NULL && conn->tlsctx==NULL); conn->tlsconf = tlsconf; - conn->tlsctx = tls_makeSession(tlsconf, NULL); + conn->tlsctx = tls_makeSession(tlsconf, servername); return 1; errexit: LOG(MOD_AIO|ERROR, errmsg, sys_credcat2str(cred_cat), sys_credset2str(cred_set)); diff --git a/src/net.h b/src/net.h index 34e8c8e..6865b78 100644 --- a/src/net.h +++ b/src/net.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _net_h_ @@ -74,7 +73,7 @@ typedef struct conn { // conn_t.evcb must not be NULL - use this void conn_evcb_nil(conn_t* conn, int wsev); -int conn_setup_tls (conn_t* conn, int cred_cat, int cred_set); +int conn_setup_tls (conn_t* conn, int cred_cat, int cred_set, const char* servername); struct uri_info { diff --git a/src/ral.c b/src/ral.c new file mode 100644 index 0000000..4fab1ac --- /dev/null +++ b/src/ral.c @@ -0,0 +1,149 @@ +/* + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "kwcrc.h" +#include "sys.h" +#include "ral.h" + +#define SX130X_RFE_MAXCOFF_125 (( 925000 - 125000)/2) +#define SX130X_RFE_MAXCOFF_250 ((1000000 - 250000)/2) +#define SX130X_RFE_MAXCOFF_500 ((1100000 - 500000)/2) + +#define SX130X_RFF_NB 2 +#define SX130X_IF_NB 10 + +int ral_challoc (chdefl_t* upchs, challoc_cb alloc_cb, void* ctx) { + u4_t rfe_spans[MAX_130X*SX130X_RFF_NB*2] = {0}; + for( int chip=0; chipfreq[multi_chslot] || upchs->rps[multi_chslot].maxSF == FSK || upchs->rps[multi_chslot].bw != BW125 ) { + multi_chslot++; + continue; + } + u4_t ch_freq = upchs->freq[multi_chslot]; + for( int rfe_idx=0; rfe_idxrps[multi_chslot]} + }, CHALLOC_CH); + ch_freq = 0; multi_chslot++; // Channel allocated, move on to next slot + break; + } + } + if( ch_freq ) break; + } + + // FSK + while( fsk_chslot < MAX_UPCHNLS ) { + if( !upchs->freq[fsk_chslot] || upchs->rps[fsk_chslot].maxSF != FSK ) { + fsk_chslot++; + continue; + } + if( chip_idx >= MAX_130X ) break; // Too many chips + u4_t ch_freq = upchs->freq[fsk_chslot]; + for( int rfe_idx=0; rfe_idx= rfe_span[1] - 2*SX130X_RFE_MAXCOFF_125 && + ch_freq <= rfe_span[0] + 2*SX130X_RFE_MAXCOFF_125) ) { + rfe_span[0] = min(ch_freq, rfe_span[0]); + rfe_span[1] = max(ch_freq, rfe_span[1]); + alloc_cb(ctx, &(challoc_t) { + .chip = chip_idx, .chan = SX130X_IF_NB-1, .rff = rfe_idx, + .rff_freq = (rfe_span[0]+rfe_span[1])/2, + .chdef = {.freq = ch_freq, .rps = upchs->rps[fsk_chslot]} + }, CHALLOC_CH); + fsk_chslot++; + modem_idx++; + break; + } + } + break; + } + + // Fast LoRa + while( fl_chslot < MAX_UPCHNLS ) { + if( !upchs->freq[fl_chslot] || (upchs->rps[fl_chslot].bw != BW250 && upchs->rps[fl_chslot].bw != BW500) ) { + fl_chslot++; + continue; + } + if( chip_idx >= MAX_130X ) break; // Too many chips + u4_t ch_freq = upchs->freq[fl_chslot]; + int maxcoff = upchs->rps[fl_chslot].bw == BW250 ? SX130X_RFE_MAXCOFF_250 : SX130X_RFE_MAXCOFF_500; + for( int rfe_idx=0; rfe_idx= cmin - maxcoff && ch_freq <= cmax + maxcoff) ) { + rfe_span[0] = min(ch_freq, rfe_span[0]); + rfe_span[1] = max(ch_freq, rfe_span[1]); + alloc_cb(ctx, &(challoc_t) { + .chip = chip_idx, .chan = SX130X_IF_NB-2, .rff = rfe_idx, + .rff_freq = (max(cmin, ch_freq-maxcoff)+min(cmax, ch_freq+maxcoff))/2, + .chdef = { .freq = ch_freq, .rps = upchs->rps[fl_chslot]} + }, CHALLOC_CH); + fl_chslot++; + modem_idx++; + break; + } + } + break; + } + + alloc_cb(ctx, &(challoc_t) { + .chipid = chip_idx, + .chans = modem_idx, + .minFreq= modem_idx ? rfe_spans[4*chip_idx] : 0, + .maxFreq= modem_idx ? max(rfe_spans[4*chip_idx+3],rfe_spans[4*chip_idx+1]) : 0, + }, CHALLOC_CHIP_DONE); + chip_idx++; + } + + // Done allocating + alloc_cb(ctx, NULL, CHALLOC_DONE); + return 1; +} diff --git a/src/ral.h b/src/ral.h index 28b3d52..c04d92d 100644 --- a/src/ral.h +++ b/src/ral.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _ral_h_ @@ -60,9 +59,56 @@ #define ral_xtime2rctx( xtime) ((sL_t)ral_xtime2txunit(xtime)) #define ral_rctx2txunit( rctx) ((u1_t)((rctx)&RAL_TXUNIT_MASK)) +struct chrps { + u1_t minSF :3; // s2w SF* enum + u1_t maxSF :3; + u1_t bw :2; // s2e BW* enum +}; + +typedef struct { + u4_t freq[MAX_UPCHNLS]; + struct chrps rps[MAX_UPCHNLS]; +} chdefl_t; + +typedef struct { + u4_t freq; + struct chrps rps; +} chdef_t; + +enum { + CHALLOC_START, + CHALLOC_CHIP_START, + CHALLOC_CH, + CHALLOC_CHIP_DONE, + CHALLOC_DONE +}; + +typedef union { +struct { + u1_t chip :3 ; // MAX_130X <= 8 + u1_t chan :4 ; // 10 channels per chip + u1_t rff :1 ; // 2 RFF per chip + u4_t rff_freq; + chdef_t chdef; +}; +// CHALLOC_CHIP_DONE +struct { + u1_t chipid :4 ; // MAX_130X <= 8 + u1_t chans :4 ; // 10 channels per chip + u4_t minFreq; + u4_t maxFreq; +}; +} challoc_t; + +typedef void (*challoc_cb) (void* ctx, challoc_t* ch, int flag); +int ral_challoc (chdefl_t* upchs, challoc_cb alloc_cb, void* ctx); + +int ral_rps2bw (rps_t rps); +int ral_rps2sf (rps_t rps); + void ral_ini (); void ral_stop (); -int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen); +int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen, chdefl_t* upchs); int ral_txstatus (u1_t txunit); void ral_txabort (u1_t txunit); int ral_tx (txjob_t* txjob, s2ctx_t* s2ctx, int nocca); diff --git a/src/ral_lgw.c b/src/ral_lgw.c index a3a180c..3e7ac54 100644 --- a/src/ral_lgw.c +++ b/src/ral_lgw.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgw1) @@ -37,10 +36,13 @@ #include "tc.h" #include "timesync.h" #include "sys.h" -#include "sx1301conf.h" +#include "sx130xconf.h" #include "ral.h" #include "lgw/loragw_reg.h" #include "lgw/loragw_hal.h" +#if defined(CFG_sx1302) +#include "lgw/loragw_sx1302.h" +#endif // defined(CFG_sx1302) #define RAL_MAX_RXBURST 10 @@ -99,14 +101,24 @@ void ral_rps2lgw (rps_t rps, struct lgw_pkt_tx_s* p) { } else { p->modulation = MOD_LORA; p->datarate = SF_MAP[rps_sf(rps)]; - p->bandwidth = BW_MAP[rps_bw(rps)];; + p->bandwidth = BW_MAP[rps_bw(rps)]; } } +int ral_rps2bw (rps_t rps) { + assert(rps != RPS_ILLEGAL); + return BW_MAP[rps_bw(rps)]; +} + +int ral_rps2sf (rps_t rps) { + assert(rps != RPS_ILLEGAL); + return SF_MAP[rps_sf(rps)]; +} + // Make a clock sync measurement: // pps_en w/o checking on latches PPS xticks // last_xtime read and update last xticks to form a continuous 64 bit time -// timesync return measured data - isochronous times for MCU/SX1301 and opt. latched PPS +// timesync return measured data - isochronous times for MCU/SX130X and opt. latched PPS // Return: // Measure of quality (absolute value) - caller uses this to weed out bad measurements // In this impl. we return the time the measurement took - smallest values are best values @@ -118,22 +130,34 @@ int ral_getTimesync (u1_t pps_en, sL_t* last_xtime, timesync_t* timesync) { // Read last latched value - when PPS occurred. If no PPS happened this returns // the time when LGW_GPS_EN was set to 1. lgw_get_trigcnt(&pps_xticks); +#if defined(CFG_sx1302) + sx1302_gps_enable(false); +#else lgw_reg_w(LGW_GPS_EN, 0); // PPS latch holds current +#endif } ustime_t t0 = rt_getTime(); u4_t xticks = 0; +#if defined(CFG_sx1302) + lgw_get_instcnt(&xticks); +#else lgw_get_trigcnt(&xticks); +#endif ustime_t t1 = rt_getTime(); sL_t d = (s4_t)(xticks - *last_xtime); if( d < 0 ) { - LOG(MOD_SYN|CRITICAL, "SX1301 time sync roll over - no update for a long time!"); + LOG(MOD_SYN|CRITICAL, "SX130X time sync roll over - no update for a long time!"); d += (sL_t)1<<32; } timesync->xtime = *last_xtime += d; timesync->ustime = (t0+t1)/2; if( pps_en ) { // PPS latch will hold now current xticks +#if defined(CFG_sx1302) + sx1302_gps_enable(true); +#else lgw_reg_w(LGW_GPS_EN, 1); +#endif timesync->pps_xtime = timesync->xtime + (s4_t)(pps_xticks - xticks); } else { // Signal no PPS @@ -168,12 +192,16 @@ int ral_tx (txjob_t* txjob, s2ctx_t* s2ctx, int nocca) { struct lgw_pkt_tx_s pkt_tx; memset(&pkt_tx, 0, sizeof(pkt_tx)); - if( txjob->txflags & TXFLAG_BCN ) { - pkt_tx.tx_mode = ON_GPS; - pkt_tx.preamble = 10; + if( txjob->preamble == 0 ) { + if( txjob->txflags & TXFLAG_BCN ) { + pkt_tx.tx_mode = ON_GPS; + pkt_tx.preamble = 10; + } else { + pkt_tx.tx_mode = TIMESTAMPED; + pkt_tx.preamble = 8; + } } else { - pkt_tx.tx_mode = TIMESTAMPED; - pkt_tx.preamble = 8; + pkt_tx.preamble = txjob->preamble; } rps_t rps = s2e_dr2rps(s2ctx, txjob->dr); ral_rps2lgw(rps, &pkt_tx); @@ -183,13 +211,17 @@ int ral_tx (txjob_t* txjob, s2ctx_t* s2ctx, int nocca) { pkt_tx.rf_power = (float)(txjob->txpow - txpowAdjust) / TXPOW_SCALE; pkt_tx.coderate = CR_LORA_4_5; pkt_tx.invert_pol = true; - pkt_tx.no_crc = true; + pkt_tx.no_crc = !txjob->addcrc; pkt_tx.no_header = false; - pkt_tx.size = txjob->len; + pkt_tx.size = txjob->len; memcpy(pkt_tx.payload, &s2ctx->txq.txdata[txjob->off], pkt_tx.size); // NOTE: nocca not possible to implement with current libloragw API +#if defined(CFG_sx1302) + int err = lgw_send(&pkt_tx); +#else int err = lgw_send(pkt_tx); +#endif if( err != LGW_HAL_SUCCESS ) { if( err != LGW_LBT_ISSUE ) { LOG(MOD_RAL|ERROR, "lgw_send failed"); @@ -203,7 +235,11 @@ int ral_tx (txjob_t* txjob, s2ctx_t* s2ctx, int nocca) { int ral_txstatus (u1_t txunit) { u1_t status; +#if defined(CFG_sx1302) + int err = lgw_status(txunit, TX_STATUS, &status); +#else int err = lgw_status(TX_STATUS, &status); +#endif if (err != LGW_HAL_SUCCESS) { LOG(MOD_RAL|ERROR, "lgw_status failed"); return TXSTATUS_IDLE; @@ -217,7 +253,11 @@ int ral_txstatus (u1_t txunit) { void ral_txabort (u1_t txunit) { +#if defined(CFG_sx1302) + lgw_abort_tx(txunit); +#else lgw_abort_tx(); +#endif } //ATTR_FASTCODE @@ -237,7 +277,7 @@ static void rxpolling (tmr_t* tmr) { rxjob_t* rxjob = !TC ? NULL : s2e_nextRxjob(&TC->s2ctx); if( rxjob == NULL ) { - LOG(ERROR, "SX1301 RX frame dropped - out of space"); + LOG(ERROR, "SX130X RX frame dropped - out of space"); break; // Allow to flush RX jobs } if( pkt_rx.status != STAT_CRC_OK ) { @@ -254,8 +294,12 @@ static void rxpolling (tmr_t* tmr) { rxjob->len = pkt_rx.size; rxjob->freq = pkt_rx.freq_hz; rxjob->xtime = ts_xticks2xtime(pkt_rx.count_us, last_xtime); +#if defined(CFG_sx1302) + rxjob->rssi = (u1_t)-pkt_rx.rssis; +#else rxjob->rssi = (u1_t)-pkt_rx.rssi; - rxjob->snr = (s1_t)(pkt_rx.snr*8); +#endif + rxjob->snr = (s1_t)(pkt_rx.snr*4); rps_t rps = ral_lgw2rps(&pkt_rx); rxjob->dr = s2e_rps2dr(&TC->s2ctx, rps); if( rxjob->dr == DR_ILLEGAL ) { @@ -270,19 +314,19 @@ static void rxpolling (tmr_t* tmr) { } -int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { +int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen, chdefl_t* upchs) { if( strcmp(hwspec, "sx1301/1") != 0 ) { - LOG(ERROR, "Unsupported hwspec=%s", hwspec); + LOG(MOD_RAL|ERROR, "Unsupported hwspec=%s", hwspec); return 0; } ujdec_t D; uj_iniDecoder(&D, json, jsonlen); if( uj_decode(&D) ) { - LOG(ERROR, "Parsing of sx1301 channel setup JSON failed"); + LOG(MOD_RAL|ERROR, "Parsing of sx130x channel setup JSON failed"); return 0; } if( uj_null(&D) ) { - LOG(ERROR, "sx1301_conf is null but a hw setup IS required - no fallbacks"); + LOG(MOD_RAL|ERROR, "sx130x_conf is null but a hw setup IS required - no fallbacks"); return 0; } uj_enterArray(&D); @@ -290,14 +334,18 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { while( (slaveIdx = uj_nextSlot(&D)) >= 0 ) { dbuf_t json = uj_skipValue(&D); if( slaveIdx == 0 ) { - struct sx1301conf sx1301conf; - - if( sx1301conf_parse_setup(&sx1301conf, -1, hwspec, json.buf, json.bufsize) && - sys_runRadioInit(sx1301conf.device) && - sx1301conf_start(&sx1301conf, cca_region) ) { + struct sx130xconf sx130xconf; + int status = 0; + + if( (status = !sx130xconf_parse_setup(&sx130xconf, -1, hwspec, json.buf, json.bufsize) << 0) || + (status = !sx130xconf_challoc(&sx130xconf, upchs) << 1) || + (status = !sys_runRadioInit(sx130xconf.device) << 2) || + (status = !sx130xconf_start(&sx130xconf, cca_region) << 3) ) { + LOG(MOD_RAL|ERROR, "ral_config failed with status 0x%02x", status); + } else { // Radio started - txpowAdjust = sx1301conf.txpowAdjust; - pps_en = sx1301conf.pps; + txpowAdjust = sx130xconf.txpowAdjust; + pps_en = sx130xconf.pps; last_xtime = ts_newXtimeSession(0); rt_yieldTo(&rxpollTmr, rxpolling); rt_yieldTo(&syncTmr, synctime); diff --git a/src/ral_lgw2.c b/src/ral_lgw2.c index a4f3315..8dd9c39 100644 --- a/src/ral_lgw2.c +++ b/src/ral_lgw2.c @@ -1,34 +1,37 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgw2) +#if defined(CFG_ral_master_slave) +#error ral_master_slave not compatible with lgw2 +#endif + #include "s2conf.h" #include "tc.h" #include "timesync.h" @@ -40,6 +43,7 @@ #include "sx1301v2conf.h" #include "ral.h" #include "lgw2/sx1301ar_err.h" +#include "lgw2/sx1301ar_gps.h" #include "lgw2/spi_linuxdev.h" static u1_t pps_en; @@ -103,6 +107,8 @@ static void ral_rps2lgw (rps_t rps, sx1301ar_tx_pkt_t* p) { if( rps_sf(rps) == FSK ) { p->modulation = MOD_FSK; p->modrate = MR_57600; + p->f_dev = 25; + p->preamble = 5; } else { p->modulation = MOD_LORA; p->modrate = SF_MAP[rps_sf(rps)]; @@ -110,6 +116,16 @@ static void ral_rps2lgw (rps_t rps, sx1301ar_tx_pkt_t* p) { } } +int ral_rps2bw (rps_t rps) { + assert(rps != RPS_ILLEGAL); + return BW_MAP[rps_bw(rps)]; +} + +int ral_rps2sf (rps_t rps) { + assert(rps != RPS_ILLEGAL); + return SF_MAP[rps_sf(rps)]; +} + // Make a clock sync measurement: // pps_en w/o checking on latches PPS xticks // last_xtime read and update last xticks to form a continuous 64 bit time @@ -130,6 +146,11 @@ int ral_getTimesync (u1_t pps_en, sL_t* last_xtime, timesync_t* timesync) { // Signal no PPS timesync->pps_xtime = 0; } + u4_t hs_pps = 0; + if( sx1301ar_get_trighs(SX1301AR_BOARD_MASTER, &hs_pps) != 0 ) hs_pps = 0; + + sx1301ar_tref_t tref = sx1301ar_init_tref(); + sx1301ar_set_xtal_err(0,tref); ustime_t t0 = rt_getTime(); u4_t xticks = 0; if( sx1301ar_get_instcnt(SX1301AR_BOARD_MASTER, &xticks) != 0 ) @@ -144,15 +165,20 @@ int ral_getTimesync (u1_t pps_en, sL_t* last_xtime, timesync_t* timesync) { } timesync->xtime = *last_xtime += d; timesync->ustime = (t0+t1)/2; + if( pps_en ) { + timesync->pps_xtime = timesync->xtime + (s4_t)(pps_xticks - xticks); + } else { + // Signal no PPS + timesync->pps_xtime = 0; + } return (int)(t1-t0); failed: LOG(MOD_SYN|CRITICAL, "SX1301 time sync failed: %s", sx1301ar_err_message(sx1301ar_errno)); return INT_MAX; } - static void synctime (tmr_t* tmr) { - timesync_t timesync; + timesync_t timesync = {0}; int quality = ral_getTimesync(pps_en, &last_xtime, ×ync); ustime_t delay = ts_updateTimesync(0, quality, ×ync); rt_setTimer(&syncTmr, rt_micros_ahead(delay)); @@ -167,21 +193,26 @@ u1_t ral_altAntennas (u1_t txunit) { int ral_tx (txjob_t* txjob, s2ctx_t* s2ctx, int nocca) { sx1301ar_tx_pkt_t pkt_tx = sx1301ar_init_tx_pkt(); - if( txjob->txflags & TXFLAG_BCN ) { - pkt_tx.tx_mode = TX_ON_GPS; - pkt_tx.preamble = 10; + if( txjob->preamble == 0 ) { + if( txjob->txflags & TXFLAG_BCN ) { + pkt_tx.tx_mode = TX_ON_GPS; + pkt_tx.preamble = 10; + } else { + pkt_tx.tx_mode = TX_TIMESTAMPED; + pkt_tx.preamble = 8; + } } else { - pkt_tx.tx_mode = TX_TIMESTAMPED; - pkt_tx.preamble = 8; + pkt_tx.preamble = txjob->preamble; } - ral_rps2lgw(s2e_dr2rps(s2ctx, txjob->dr), &pkt_tx); + rps_t rps = s2e_dr2rps(s2ctx, txjob->dr); + ral_rps2lgw(rps, &pkt_tx); pkt_tx.freq_hz = txjob->freq; pkt_tx.count_us = txjob->xtime; pkt_tx.rf_chain = 0; pkt_tx.rf_power = (float)(txjob->txpow - txpowAdjust) / TXPOW_SCALE; pkt_tx.coderate = CR_4_5; pkt_tx.invert_pol = true; - pkt_tx.no_crc = true; + pkt_tx.no_crc = !txjob->addcrc; pkt_tx.no_header = false; pkt_tx.size = txjob->len; memcpy(pkt_tx.payload, &s2ctx->txq.txdata[txjob->off], pkt_tx.size); @@ -260,8 +291,10 @@ static void rxpolling (tmr_t* tmr) { if(rxjob->rssi < -p->rsig[j].rssi_chan || !p->rsig[j].is_valid) { continue; } - rxjob->rssi = (u1_t)-p->rsig[j].rssi_chan; - rxjob->snr = p->rsig[j].snr*8; + rxjob->fts = p->rsig[j].fine_received ? p->rsig[j].fine_tmst : -1; + rxjob->rssi = (u1_t)-p->rsig[j].rssi_chan; + rxjob->snr = p->rsig[j].snr*4; + rxjob->rctx = j; } rps_t rps = ral_lgw2rps(p); rxjob->dr = s2e_rps2dr(&TC->s2ctx, rps); @@ -276,7 +309,7 @@ static void rxpolling (tmr_t* tmr) { rt_setTimer(tmr, rt_micros_ahead(RX_POLL_INTV)); } -int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { +int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen, chdefl_t* upchs) { struct sx1301v2conf sx1301v2conf; if( !sx1301v2conf_parse_setup(&sx1301v2conf, -1, hwspec, json, jsonlen) ) return 0; @@ -304,6 +337,7 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { rt_fatal("Radio device '%s' in use by process: %d%s", device, pids[0], n>1?".. (and others)":""); #endif // defined(CFG_linux) +#if !defined(CFG_variant_testsim) int err; if( (err = spi_linuxdev_open(device, /*default speed*/-1, &spiFd)) != 0 ) { LOG(MOD_RAL|ERROR, "Failed to open SPI device '%s': ret=%d errno=%s", device, err, strerror(errno)); @@ -317,8 +351,10 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { LOG(MOD_RAL|ERROR, "Failed to set mode for SPI device '%s': %s", device, err); goto errexit; } +#endif if( !sys_runRadioInit(sx1301v2conf.boards[0].device) || + !sx1301v2conf_challoc(&sx1301v2conf, upchs) || !sx1301v2conf_start(&sx1301v2conf, cca_region) ) { goto errexit; } @@ -334,7 +370,9 @@ int ral_config (str_t hwspec, u4_t cca_region, char* json, int jsonlen) { errexit: if( spiFd >= 0 ) { +#if !defined(CFG_variant_testsim) (void)spi_linuxdev_close(spiFd); +#endif spiFd = -1; } return 0; diff --git a/src/rt.c b/src/rt.c index c68419a..c7549bc 100644 --- a/src/rt.c +++ b/src/rt.c @@ -1,35 +1,38 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "sys.h" #include "rt.h" +// More recent version of protocol uses standards compliant +// fields with capital EUI spelling +str_t rt_deveui = "DevEui"; +str_t rt_joineui = "JoinEui"; // We're using a simple linked list. // Complexity is O(n) but we don't expect to have many entries on a router. @@ -38,6 +41,7 @@ static tmr_t* timerQ = TMR_END; static dbuf_t features; ustime_t rt_utcOffset; +ustime_t rt_utcOffset_ts; void rt_usleep (sL_t us) { @@ -125,7 +129,9 @@ void rt_ini() { // If system does not have a native UTC time then sys_utc() returns zero and we run with // ustime_t (time since startup) for the time being. Once we get a connection to TC we // replace this offset with MuxTime which is the servers UTC time. - rt_utcOffset = sys_utc() - rt_getTime(); + ustime_t now = rt_getTime(); + rt_utcOffset = sys_utc() - now; + rt_utcOffset_ts = now; } diff --git a/src/rt.h b/src/rt.h index d27e359..c46d275 100644 --- a/src/rt.h +++ b/src/rt.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _rt_h_ @@ -125,6 +124,7 @@ void log_vmsg (u1_t mod_level, const char* fmt, va_list args); int log_special (u1_t mod_level, dbuf_t* buf); void log_specialFlush (int len); void log_flush (); +void log_flushIO (); #if defined(CFG_log_file_line) @@ -184,6 +184,7 @@ uL_t rt_eui(); void rt_usleep (ustime_t us); extern ustime_t rt_utcOffset; +extern ustime_t rt_utcOffset_ts; ustime_t rt_getTime (); ustime_t rt_getUTC (); @@ -211,11 +212,11 @@ void _rt_free_d (void* p, const char* f, int l); #if defined(CFG_variant_debug) #define rt_malloc(type) ((type*)_rt_malloc_d(sizeof(type), 1, __FILE__, __LINE__)) -#define rt_mallocN(type,num) ((type*)_rt_malloc_d(sizeof(type)*num, 1, __FILE__, __LINE__)) +#define rt_mallocN(type,num) ((type*)_rt_malloc_d(sizeof(type)*(num), 1, __FILE__, __LINE__)) #define rt_free(p) _rt_free_d(p, __FILE__, __LINE__) #else #define rt_malloc(type) ((type*)_rt_malloc(sizeof(type), 1)) -#define rt_mallocN(type,num) ((type*)_rt_malloc(sizeof(type)*num, 1)) +#define rt_mallocN(type,num) ((type*)_rt_malloc(sizeof(type)*(num), 1)) #define rt_free free #endif @@ -230,6 +231,7 @@ u4_t rt_crc32 (u4_t crc, const void* buf, int size); void rt_addFeature (str_t s); str_t rt_features (); +extern str_t rt_deveui, rt_joineui; // -------------------------------------------------------------------------------- // diff --git a/src/s2conf.c b/src/s2conf.c index 3cf9c0b..a1f3180 100644 --- a/src/s2conf.c +++ b/src/s2conf.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -40,6 +39,7 @@ #include "s2conf.h" +static int parse_bool (struct conf_param* param); static int parse_u4 (struct conf_param* param); static int parse_str (struct conf_param* param); static int parse_tspan_h (struct conf_param* param); @@ -60,6 +60,23 @@ struct conf_param conf_params[] = { }; +static int parse_bool (struct conf_param* param) { + ujdec_t D; + char* v = rt_strdup(param->value); + uj_iniDecoder(&D, v, strlen(v)); + if( uj_decode(&D) ) { + LOG(ERROR, "Parsing of config param '%s' (%s) as bool failed: %s", + param->name, param->src, param->value); + free(v); + return 0; + } + *(bool*)param->pvalue = uj_bool(&D); + uj_assertEOF(&D); + rt_free(v); + return 1; +} + + static int parse_u4 (struct conf_param* param) { ujdec_t D; char* v = rt_strdup(param->value); diff --git a/src/s2conf.h b/src/s2conf.h index e4c1300..86de43b 100644 --- a/src/s2conf.h +++ b/src/s2conf.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _s2conf_h_ @@ -43,23 +42,32 @@ #define DFLT_TC_SEND_BUFSZ (80*1024) #define DFLT_RADIO_INIT_WAIT "\"200ms\"" #define DFLT_MAX_TXUNITS 4 +#define DFLT_MAX_130X 8 #define DFLT_MAX_TXJOBS 128 #define DFLT_MAX_RXJOBS 64 #define DFLT_RADIODEV "\"/dev/spidev?.0\"" #define DFLT_TX_MIN_GAP "\"10ms\"" // worst case for ODU as of 07.2018 (horrible SPI performance) #define DFLT_TX_AIM_GAP "\"20ms\"" // -ditto- +#define DFLT_TX_MAX_AHEAD "\"600s\"" #define DFLT_TXCHECK_FUDGE "\"5ms\"" /* TCP keepalive */ -#define DFLT_TCP_KEEPALIVE "1" // Connections use keep alive +#define DFLT_TCP_KEEPALIVE "1" // Connections use keep alive #define DFLT_TCP_KEEPIDLE "60" // Connection idle time (in seconds) before sending keepalive probes #define DFLT_TCP_KEEPINTVL "15" // The time (in seconds) between individual keepalive probes #define DFLT_TCP_KEEPCNT "4" // The maximum number of keepalive probes sent before dropping the connection #define DFLT_MAX_RMTSH 2 // The maximum number of keepalive probes sent before dropping the connection +#define DFLT_BEACON_INTVL "\"128s\"" // Time between beacons in microseconds +#if defined(CFG_platform_cisco) || defined(CFG_platform_rpi64) +#undef DFLT_TX_MIN_GAP +#undef DFLT_TX_AIM_GAP +#define DFLT_TX_MIN_GAP "\"10ms\"" +#define DFLT_TX_AIM_GAP "\"60ms\"" +#endif // defined(CFG_platform_cisco) @@ -106,6 +114,8 @@ enum { MAX_CMDARGS = 64 }; enum { MUXS_PROTOCOL_VERSION = 2 }; enum { MAX_RMTSH = DFLT_MAX_RMTSH }; +enum { LOGLINE_LEN = 512 }; + // -------------------------------------------------------------------------------- // Lora processing // -------------------------------------------------------------------------------- @@ -114,6 +124,7 @@ enum { RTT_SAMPLES = 100 }; enum { MAX_WSSFRAMES = 32 }; enum { MIN_UPJSON_SIZE = 384 }; enum { MAX_TXUNITS = DFLT_MAX_TXUNITS }; +enum { MAX_130X = DFLT_MAX_130X }; enum { MAX_TXJOBS = DFLT_MAX_TXJOBS }; enum { MAX_TXFRAME_LEN = 255 }; enum { MAX_RXFRAME_LEN = 255 }; @@ -176,9 +187,12 @@ CONF_PARAM(TIMESYNC_LNS_RETRY , ustime, tspan_s , "\"71ms\"", "resend CONF_PARAM(TIMESYNC_LNS_PAUSE , ustime, tspan_s , "\"5s\"", "pause after unsuccessful volley of timesync messages") CONF_PARAM(TIMESYNC_LNS_BURST , u4 , u4 , "10", "volley of timesync messages before pausing") CONF_PARAM(TIMESYNC_REPORTS , ustime, tspan_s , "\"5m\"", "report interval for current timesync status") -CONF_PARAM(TX_MIN_GAP , ustime, tspan_s, DFLT_TX_MIN_GAP, "min distance between two frames being TXed") -CONF_PARAM(TX_AIM_GAP , ustime, tspan_s, DFLT_TX_AIM_GAP, "aim for this TX lead time, if delayed should not fall under min") -CONF_PARAM(TXCHECK_FUDGE , ustime, tspan_s, DFLT_TXCHECK_FUDGE, "check radio state this time into ongoing TX") +CONF_PARAM(TX_MIN_GAP , ustime, tspan_s , DFLT_TX_MIN_GAP, "min distance between two frames being TXed") +CONF_PARAM(TX_AIM_GAP , ustime, tspan_s , DFLT_TX_AIM_GAP, "aim for this TX lead time, if delayed should not fall under min") +CONF_PARAM(TX_MAX_AHEAD , ustime, tspan_s , DFLT_TX_MAX_AHEAD, "maximum time message can be scheduled into the future") +CONF_PARAM(TXCHECK_FUDGE , ustime, tspan_s , DFLT_TXCHECK_FUDGE, "check radio state this time into ongoing TX") +CONF_PARAM(BEACON_INTVL , ustime, tspan_s , DFLT_BEACON_INTVL, "beaconing interval") +CONF_PARAM(TLS_SNI , u4, bool , "true", "Set and verify server name of TLS connections") #endif // _s2conf_x_ diff --git a/src/s2e.c b/src/s2e.c index 54f8a41..f8fd7f5 100644 --- a/src/s2e.c +++ b/src/s2e.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -47,6 +46,7 @@ extern inline rps_t rps_make (int sf, int bw); // Fwd decl. static void s2e_txtimeout (tmr_t* tmr); +static void s2e_bcntimeout (tmr_t* tmr); static void setDC (s2ctx_t* s2ctx, ustime_t t) { @@ -87,12 +87,15 @@ void s2e_ini (s2ctx_t* s2ctx) { s2ctx->txunits[u].timer.ctx = s2ctx; s2ctx->txunits[u].head = TXIDX_END; } + rt_iniTimer(&s2ctx->bcntimer, s2e_bcntimeout); + s2ctx->bcntimer.ctx = s2ctx; } void s2e_free (s2ctx_t* s2ctx) { for( int u=0; u < MAX_TXUNITS; u++ ) rt_clrTimer(&s2ctx->txunits[u].timer); + rt_clrTimer(&s2ctx->bcntimer); memset(s2ctx, 0, sizeof(*s2ctx)); ts_iniTimesync(); ral_stop(); @@ -124,7 +127,7 @@ void s2e_addRxjob (s2ctx_t* s2ctx, rxjob_t* rxjob) { if( (8*rxjob->snr - rxjob->rssi) > (8*p->snr - p->rssi) ) { // Drop previous frame p LOG(MOD_S2E|DEBUG, "Dropped mirror frame freq=%F snr=%5.1f rssi=%d (vs. freq=%F snr=%5.1f rssi=%d) - DR%d mic=%d (%d byes)", - p->freq, p->snr/8.0, -p->rssi, rxjob->freq, rxjob->snr/8.0, -rxjob->rssi, + p->freq, p->snr/4.0, -p->rssi, rxjob->freq, rxjob->snr/4.0, -rxjob->rssi, p->dr, (s4_t)rt_rlsbf4(&s2ctx->rxq.rxdata[p->off]+rxjob->len-4), p->len); rxq_commitJob(&s2ctx->rxq, rxjob); @@ -132,7 +135,7 @@ void s2e_addRxjob (s2ctx_t* s2ctx, rxjob_t* rxjob) { } else { // else: Drop newly retrieved frame - aka don't commit it LOG(MOD_S2E|DEBUG, "Dropped mirror frame freq=%F snr=%5.1f rssi=%d (vs. freq=%F snr=%5.1f rssi=%d) - DR%d mic=%d (%d byes)", - rxjob-> freq, rxjob->snr/8.0, -rxjob->rssi, p->freq, p->snr/8.0, -p->rssi, + rxjob-> freq, rxjob->snr/4.0, -rxjob->rssi, p->freq, p->snr/4.0, -p->rssi, rxjob->dr, (s4_t)rt_rlsbf4(&s2ctx->rxq.rxdata[rxjob->off]+rxjob->len-4), rxjob->len); } return; @@ -154,7 +157,7 @@ void s2e_flushRxjobs (s2ctx_t* s2ctx) { dbuf_t lbuf = { .buf = NULL }; if( log_special(MOD_S2E|VERBOSE, &lbuf) ) xprintf(&lbuf, "RX %F DR%d %R snr=%.1f rssi=%d xtime=0x%lX - ", - j->freq, j->dr, s2e_dr2rps(s2ctx, j->dr), j->snr/8.0, -j->rssi, j->xtime); + j->freq, j->dr, s2e_dr2rps(s2ctx, j->dr), j->snr/4.0, -j->rssi, j->xtime); uj_encOpen(&sendbuf, '{'); if( !s2e_parse_lora_frame(&sendbuf, &s2ctx->rxq.rxdata[j->off], j->len, lbuf.buf ? &lbuf : NULL) ) { @@ -177,8 +180,9 @@ void s2e_flushRxjobs (s2ctx_t* s2ctx) { /**/ "rctx", 'I', j->rctx, /**/ "xtime", 'I', j->xtime, /**/ "gpstime", 'I', ts_xtime2gpstime(j->xtime), + /**/ "fts", 'i', j->fts, /**/ "rssi", 'i', -(s4_t)j->rssi, - /**/ "snr", 'g', j->snr/8.0, + /**/ "snr", 'g', j->snr/4.0, /**/ "rxtime", 'T', rt_getUTC()/1e6, "}", NULL); @@ -208,7 +212,9 @@ static const u2_t DC_EU863BAND_RATE[] = { }; -static ustime_t _calcAirTime (rps_t rps, u1_t plen, u1_t nocrc) { +static ustime_t _calcAirTime (rps_t rps, u1_t plen, u1_t nocrc, u2_t preamble) { + if( preamble == 0 ) + preamble = 8; if( rps == RPS_ILLEGAL ) return 0; // The impl has been taken from lmic.c and adapted @@ -231,7 +237,7 @@ static ustime_t _calcAirTime (rps_t rps, u1_t plen, u1_t nocrc) { } else { tmp = 8; } - tmp = (tmp<<2) + /*preamble*/49 /* 4 * (8 + 4.25) */; + tmp = (tmp<<2) + /*preamble: 4*4.25*/ 17 + /*preamble*/(4*preamble); // bw = 125000 = 15625 * 2^3 // 250000 = 15625 * 2^4 // 500000 = 15625 * 2^5 @@ -251,12 +257,12 @@ static ustime_t _calcAirTime (rps_t rps, u1_t plen, u1_t nocrc) { return (((ustime_t)tmp << sfx) * rt_seconds(1) + div/2) / div; } -ustime_t s2e_calcDnAirTime (rps_t rps, u1_t plen) { - return _calcAirTime(rps, plen, 1); +ustime_t s2e_calcDnAirTime (rps_t rps, u1_t plen, u1_t addcrc, u2_t preamble) { + return _calcAirTime(rps, plen, !addcrc, preamble); } ustime_t s2e_calcUpAirTime (rps_t rps, u1_t plen) { - return _calcAirTime(rps, plen, 0); + return _calcAirTime(rps, plen, 0, 8); } static void send_dntxed (s2ctx_t* s2ctx, txjob_t* txjob) { @@ -272,7 +278,9 @@ static void send_dntxed (s2ctx_t* s2ctx, txjob_t* txjob) { "msgtype", 's', "dntxed", "seqno", 'I', txjob->diid, // for older servers (remove if obsoleted) "diid", 'I', txjob->diid, // newer servers - "DevEui", 'E', txjob->deveui, + "DR", 'i', txjob->dr, + "Freq", 'u', txjob->freq, + rt_deveui, 'E', txjob->deveui, "rctx", 'i', txjob->txunit, // antenna that sent this frame "xtime", 'I', txjob->xtime, "txtime", 'T', txjob->txtime/1e6, @@ -281,8 +289,9 @@ static void send_dntxed (s2ctx_t* s2ctx, txjob_t* txjob) { uj_encClose(&sendbuf, '}'); (*s2ctx->sendText)(s2ctx, &sendbuf); } - LOG(MOD_S2E|INFO, "TX %J - dntxed: %F %.1fdBm ant#%d(%d) DR%d %R frame=%12.4H", - txjob, txjob->freq, (double)txjob->txpow/TXPOW_SCALE, + LOG(MOD_S2E|INFO, "TX %J - %s: %F %.1fdBm ant#%d(%d) DR%d %R frame=%12.4H", + txjob, txjob->deveui ? "dntxed" : "on air", + txjob->freq, (double)txjob->txpow/TXPOW_SCALE, txjob->txunit, ral_rctx2txunit(txjob->rctx), // sending/receiving antenna txjob->dr, s2e_dr2rps(s2ctx, txjob->dr), txjob->len, &s2ctx->txq.txdata[txjob->off]); @@ -390,7 +399,7 @@ static s2_t calcTxpow (s2ctx_t* s2ctx, txjob_t* txjob) { } static void updateAirtimeTxpow (s2ctx_t* s2ctx, txjob_t* txjob) { - txjob->airtime = s2e_calcDnAirTime(s2e_dr2rps(s2ctx, txjob->dr), txjob->len); + txjob->airtime = s2e_calcDnAirTime(s2e_dr2rps(s2ctx, txjob->dr), txjob->len, txjob->addcrc, txjob->preamble); txjob->txpow = calcTxpow(s2ctx, txjob); } @@ -421,7 +430,7 @@ static int altTxTime (s2ctx_t* s2ctx, txjob_t* txjob, ustime_t earliest) { txjob->rx2freq = 0; // invalidate RX2 updateAirtimeTxpow(s2ctx, txjob); if( txjob->xtime == 0 ) { - LOG(MOD_S2E|VERBOSE, "%J - class C dropped - no time sync to SX1301 yet", txjob); + LOG(MOD_S2E|VERBOSE, "%J - class C dropped - no time sync to SX130X yet", txjob); return 0; } } @@ -518,7 +527,13 @@ int s2e_addTxjob (s2ctx_t* s2ctx, txjob_t* txjob, int relocate, ustime_t now) { txjob->altAnts = ral_altAntennas(txunit); updateAirtimeTxpow(s2ctx, txjob); + if( txtime > now + TX_MAX_AHEAD ) { + LOG(MOD_S2E|WARNING, "%J - Tx job too far ahead: %~T", txjob, txtime-now); + return 0; + } + if( txtime < earliest && !altTxTime(s2ctx, txjob, earliest) ) + return 0; goto start; } @@ -528,6 +543,7 @@ int s2e_addTxjob (s2ctx_t* s2ctx, txjob_t* txjob, int relocate, ustime_t now) { // No more alternative antennas - try later TX time if( !altTxTime(s2ctx, txjob, earliest) ) { LOG(MOD_S2E|WARNING, "%J - unable to place frame", txjob); + return 0; } // and reset antenna options @@ -603,6 +619,11 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { if( now >= txend ) { // TX is over - drop job LOG(MOD_S2E|DEBUG, "Tx done diid=%ld", curr->diid); + if( !(curr->txflags & TXFLAG_TXCHECKED) ) { + update_DC(s2ctx, curr); + curr->txflags |= TXFLAG_TXCHECKED; + send_dntxed(s2ctx, curr); + } txq_unqJob(&s2ctx->txq, phead); txq_freeJob(&s2ctx->txq, curr); goto again; @@ -620,6 +641,14 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { } // Looks like it's on air update_DC(s2ctx, curr); + + + + + + + + curr->txflags |= TXFLAG_TXCHECKED; // sending dntxed here instead @txend gives nwks more time to update/inform muxs (join) send_dntxed(s2ctx, curr); @@ -628,7 +657,7 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { } if( txdelta < TX_MIN_GAP ) { // Missed TX start time - try alternative or drop frame - LOG(MOD_S2E|ERROR, "%J - missed TX time: txdelta=%ld min=%d", curr, txdelta, TX_MIN_GAP); + LOG(MOD_S2E|ERROR, "%J - missed TX time: txdelta=%~T min=%~T", curr, txdelta, TX_MIN_GAP); check_alt: txq_unqJob(&s2ctx->txq, phead); if( !s2e_addTxjob(s2ctx, curr, /*relocate*/1, now) ) // note: might change queue head! (reload @ again) @@ -681,6 +710,7 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { } } while(1); + LOG(MOD_S2E|VERBOSE, "%J - starting TX in %~T", curr, txdelta); int txerr = ral_tx(curr, s2ctx, ccaDisabled); if( txerr != RAL_TX_OK ) { if( txerr == RAL_TX_NOCA ) { @@ -691,7 +721,6 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { goto check_alt; } curr->txflags |= TXFLAG_TXING; - LOG(MOD_S2E|VERBOSE, "%J - starting TX in %~T", curr, txdelta); // Unqueue all overlapping subsequent txjobs and find alternatives (antenna/txtime) // If no alternatives drop txjob. @@ -699,6 +728,7 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { txjob_t* next_txjob = txq_idx2job(&s2ctx->txq, curr->next); if( next_txjob == NULL || txend < next_txjob->txtime - TX_MIN_GAP ) break; // no next or no overlap + LOG(MOD_S2E|INFO, "%J - displaces %J due to %~T overlap", curr, next_txjob, next_txjob->txtime - TX_MIN_GAP - txend); txq_unqJob(&s2ctx->txq, &curr->next); if( !s2e_addTxjob(s2ctx, next_txjob, /*relocate*/1, now) ) // note: might change next! txq_freeJob(&s2ctx->txq, next_txjob); @@ -708,7 +738,7 @@ ustime_t s2e_nextTxAction (s2ctx_t* s2ctx, u1_t txunit) { -void s2e_txtimeout (tmr_t* tmr) { +static void s2e_txtimeout (tmr_t* tmr) { s2ctx_t* s2ctx = tmr->ctx; u1_t txunit = (s2txunit_t*)((u1_t*)tmr - offsetof(s2txunit_t, timer)) - s2ctx->txunits; ustime_t t = s2e_nextTxAction(s2ctx, txunit); @@ -718,14 +748,112 @@ void s2e_txtimeout (tmr_t* tmr) { } +static void s2e_bcntimeout (tmr_t* tmr) { + s2ctx_t* s2ctx = tmr->ctx; + ustime_t now = rt_getTime(); + sL_t xtime = ts_ustime2xtime(0, now); + sL_t gpstime = ts_xtime2gpstime(xtime); + double lat, lon; + int latlon_ok; + ustime_t ahead; + + if( gpstime == 0 || !(latlon_ok = sys_getLatLon(&lat, &lon)) ) { + // We don't have PPS or we are not yet time synced -- retry after a while + ahead = rt_seconds(10); + LOG(MOD_S2E|INFO, "Beaconing suspended for %~T - insufficient GPS data: %s %s", + ahead, gpstime==0?"time":"", latlon_ok?"position":""); + rt_setTimer(tmr, now + ahead); + return; + } + + // Next beacon TX time is on upcoming multipl of 128s GPS time which is at least 1s ahead + ahead = BEACON_INTVL - gpstime % BEACON_INTVL; + sL_t gpstxtime = gpstime + ahead; + txjob_t* txjob = txq_reserveJob(&s2ctx->txq); + if( txjob == NULL ) { + LOG(MOD_S2E|ERROR, "Out of TX jobs - cannot send beacon"); + goto nextbcn; + } + int ctrl = s2ctx->bcn.ctrl; + int bcn_len = s2ctx->bcn.layout[2]; + u1_t* p = txq_reserveData(&s2ctx->txq, bcn_len); + if( p == NULL ) { + LOG(MOD_S2E|ERROR, "Out of TX data space - cannot send beacon"); + goto nextbcn; + } + sL_t epoch = gpstxtime/BEACON_INTVL; + txjob->gpstime = gpstxtime; + txjob->xtime = ts_gpstime2xtime(0, txjob->gpstime); + txjob->txtime = ts_xtime2ustime(txjob->xtime); + txjob->freq = s2ctx->bcn.freqs[epoch % (ctrl>>4)]; + txjob->dr = ctrl & 0xF; + txjob->txflags = TXFLAG_BCN; + txjob->prio = PRIO_BEACON; + txjob->len = bcn_len; + s2e_make_beacon(s2ctx->bcn.layout, epoch*128, 0, lat, lon, p); + + txq_commitJob(&s2ctx->txq, txjob); + if( !s2e_addTxjob(s2ctx, txjob, /*initial placement*/0, now) ) + txq_freeJob(&s2ctx->txq, txjob); + + nextbcn: + // Sleep until next beacon is 800ms ahead + ahead += BEACON_INTVL - rt_millis(800); + rt_setTimer(tmr, now + ahead); +} + +static bool hasFastLora(s2ctx_t* s2ctx, int minDR, int maxDR, rps_t* rpsp) { + for( int dr=minDR; dr<=maxDR; dr++ ) { + rps_t rps = s2e_dr2rps(s2ctx, dr); + if( rps_bw(rps) == BW250 || rps_bw(rps) == BW500 ) { + *rpsp = rps; + return true; + } + } + return false; +} + +static bool hasFSK(s2ctx_t* s2ctx, int minDR, int maxDR) { + for( int dr=minDR; dr<=maxDR; dr++ ) { + if( s2e_dr2rps(s2ctx, dr) == RPS_FSK ) + return true; + } + return false; +} + +static bool any125kHz(s2ctx_t* s2ctx, int minDR, int maxDR, rps_t* min_rps, rps_t* max_rps) { + *min_rps = *max_rps = RPS_ILLEGAL; + bool any125kHz = false; + for( int dr=minDR; dr<=maxDR; dr++ ) { + rps_t rps = s2e_dr2rps(s2ctx, dr); + if( rps != RPS_FSK && rps_bw(rps) == BW125 ) { + any125kHz = true; + *min_rps = rps; + if( *max_rps == RPS_ILLEGAL ) *max_rps = rps; + } + } + return any125kHz; +} + +inline static void upch_insert (chdefl_t* upchs, uint idx, u4_t freq, u1_t bw, u1_t minSF, u2_t maxSF) { + if( idx >= MAX_UPCHNLS ) return; + upchs->freq[idx] = freq; + upchs->rps[idx].bw = bw; + upchs->rps[idx].minSF = minSF; + upchs->rps[idx].maxSF = maxSF; +} + static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { char hwspec[MAX_HWSPEC_SIZE] = { 0 }; - ujbuf_t sx1301conf = { .buf=NULL }; + ujbuf_t sx130xconf = { .buf=NULL }; ujcrc_t field; u1_t ccaDisabled=0, dcDisabled=0, dwellDisabled=0; // fields not present s2_t default_txpow = 14 * TXPOW_SCALE; // builtin default int jlistlen = 0; - + chdefl_t upchs = {{0}}; + int chslots = 0; + s2bcn_t bcn = { 0 }; + while( (field = uj_nextField(D)) ) { switch(field) { case J_freq_range: { @@ -758,6 +886,30 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { uj_exitArray(D); break; } + case J_upchannels: { + uj_enterArray(D); + while( uj_nextSlot(D) >= 0 ) { + if( chslots > MAX_UPCHNLS-1 ) { + uj_skipValue(D); + continue; + } + uj_enterArray(D); + u4_t freq = (uj_nextSlot(D), uj_int(D)); + int insert = chslots; + while( insert > 0 && upchs.freq[insert-1] > freq ) { + upch_insert(&upchs, insert, upchs.freq[insert-1], + BWNIL, upchs.rps[insert-1].minSF, upchs.rps[insert-1].maxSF); + insert--; + } + int minDR = (uj_nextSlot(D), uj_intRange(D, 0, DR_CNT-1)); + int maxDR = (uj_nextSlot(D), uj_intRange(D, 0, DR_CNT-1)); + upch_insert(&upchs, insert, freq, BWNIL, minDR, maxDR); + uj_exitArray(D); + chslots++; + } + uj_exitArray(D); + break; + } case J_NetID: { if( !uj_null(D) ) { for( int i=0; i<4; i++ ) @@ -774,6 +926,11 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { } break; } + case J_JoinEUI: { + rt_joineui = "JoinEUI"; + rt_deveui = "DevEUI"; + // FALL THRU + } case J_JoinEui: { for( int i=0; i<2*MAX_JOINEUI_RANGES; i++ ) s2e_joineuiFilter[i] = 0; @@ -850,6 +1007,7 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { case J_MuxTime: { s2e_updateMuxtime(s2ctx, uj_num(D), 0); rt_utcOffset = s2ctx->muxtime*1e6 - s2ctx->reftime; + rt_utcOffset_ts = s2ctx->reftime; break; } case J_hwspec: { @@ -886,9 +1044,13 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { break; } #endif // !defined(CFG_prod) - case J_sx1301_conf: { + case J_sx1301_conf: + case J_SX1301_conf: + case J_sx1302_conf: + case J_SX1302_conf: + case J_radio_conf: { // Processed in ral layer - sx1301conf = uj_skipValue(D); + sx130xconf = uj_skipValue(D); break; } case J_msgtype: { @@ -896,6 +1058,48 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { uj_skipValue(D); break; } + case J_bcning: { + if( uj_null(D) ) + break; + uj_enterObject(D); + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_DR: { + bcn.ctrl = (uj_uint(D) & 0xF) | (bcn.ctrl & 0xF0); + break; + } + case J_layout: { + uj_enterArray(D); + bcn.layout[0] = (uj_nextSlot(D), uj_uint(D)); + bcn.layout[1] = (uj_nextSlot(D), uj_uint(D)); + bcn.layout[2] = (uj_nextSlot(D), uj_uint(D)); + uj_exitArray(D); + break; + } + case J_freqs: { + uj_enterArray(D); + int off = 0; + while( uj_nextSlot(D) >= 0 ) { + if( off < SIZE_ARRAY(bcn.freqs) ) { + bcn.freqs[off++] = uj_int(D); + } else { + LOG(MOD_S2E|ERROR, "Too many beacon frequencies: %d - max %d supported", off, SIZE_ARRAY(bcn.freqs)); + } + } + uj_exitArray(D); + bcn.ctrl = (bcn.ctrl & 0xF) | (off<<4); + break; + } + default: { + LOG(MOD_S2E|WARNING, "Unknown field in router_config.bcning - ignored: %s (0x%X)", D->field.name, D->field.crc); + uj_skipValue(D); + break; + } + } + } + uj_exitObject(D); + break; + } default: { LOG(MOD_S2E|WARNING, "Unknown field in router_config - ignored: %s (0x%X)", D->field.name, D->field.crc); uj_skipValue(D); @@ -904,18 +1108,40 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { } } if( !hwspec[0] ) { - LOG(ERROR, "No 'hwspec' in 'router_config' message"); + LOG(MOD_S2E|ERROR, "No 'hwspec' in 'router_config' message"); return 0; } - if( sx1301conf.buf == NULL ) { - LOG(ERROR, "No 'sx1301_conf' in 'router_config' message"); + if( sx130xconf.buf == NULL ) { + LOG(MOD_S2E|ERROR, "No 'sx1301_conf' or 'sx1302_conf' in 'router_config' message"); return 0; } + int chdefs = chslots; + for( int chslot=0; chslotccaEnabled ? s2ctx->region : 0, - sx1301conf.buf, sx1301conf.bufsize) ) + sx130xconf.buf, sx130xconf.bufsize, + &upchs) ) { return 0; + } // Override local settings with server settings if provided if( ccaDisabled ) s2e_ccaDisabled = ccaDisabled & 2; if( dcDisabled ) s2e_dcDisabled = dcDisabled & 2; @@ -942,12 +1168,21 @@ static int handle_router_config (s2ctx_t* s2ctx, ujdec_t* D) { LOG(MOD_S2E|VERBOSE, " %.1f dBm EIRP for %F..%F", s2ctx->txpow2/(double)TXPOW_SCALE, s2ctx->txpow2_freq[0], s2ctx->txpow2_freq[1]); } - LOG(MOD_S2E|VERBOSE, " JoinEui list: %d entries", jlistlen); + LOG(MOD_S2E|VERBOSE, " %s list: %d entries", rt_joineui, jlistlen); LOG(MOD_S2E|VERBOSE, " NetID filter: %08X-%08X-%08X-%08X", - s2e_netidFilter[0], s2e_netidFilter[0], s2e_netidFilter[0], s2e_netidFilter[0]); + s2e_netidFilter[3], s2e_netidFilter[2], s2e_netidFilter[1], s2e_netidFilter[0]); LOG(MOD_S2E|VERBOSE, " Dev/test settings: nocca=%d nodc=%d nodwell=%d", (s2e_ccaDisabled!=0), (s2e_dcDisabled!=0), (s2e_dwellDisabled!=0)); } + if( (bcn.ctrl&0xF0) != 0 ) { + // At least one beacon frequency was specified + LOG(MOD_S2E|VERBOSE, "Beaconing every %~T on %F(%d) @ DR%d (frame layout %d/%d/%d)", + BEACON_INTVL, bcn.freqs[0], + (bcn.ctrl>>4), bcn.ctrl & 0xF, + bcn.layout[0], bcn.layout[1], bcn.layout[2]); + s2ctx->bcn = bcn; + s2e_bcntimeout(&s2ctx->bcntimer); + } return 1; } @@ -957,7 +1192,7 @@ void handle_dnframe (s2ctx_t* s2ctx, ujdec_t* D) { ustime_t now = rt_getTime(); txjob_t* txjob = txq_reserveJob(&s2ctx->txq); if( txjob == NULL ) { - LOG(MOD_S2E|ERROR, "Out of TX jobs - dropping incomming message"); + LOG(MOD_S2E|ERROR, "Out of TX jobs - dropping incoming message"); return; } int flags = 0; @@ -978,6 +1213,7 @@ void handle_dnframe (s2ctx_t* s2ctx, ujdec_t* D) { flags |= 0x02; break; } + case J_DevEUI: case J_DevEui: { txjob->deveui = uj_eui(D); flags |= 0x04; @@ -1050,7 +1286,7 @@ void handle_dnmsg (s2ctx_t* s2ctx, ujdec_t* D) { ustime_t now = rt_getTime(); txjob_t* txjob = txq_reserveJob(&s2ctx->txq); if( txjob == NULL ) { - LOG(MOD_S2E|ERROR, "Out of TX jobs - dropping incomming message"); + LOG(MOD_S2E|ERROR, "Out of TX jobs - dropping incoming message"); return; } int flags = 0; @@ -1061,6 +1297,7 @@ void handle_dnmsg (s2ctx_t* s2ctx, ujdec_t* D) { uj_skipValue(D); break; } + case J_DevEUI: case J_DevEui: { txjob->deveui = uj_eui(D); flags |= 0x01; @@ -1155,6 +1392,14 @@ void handle_dnmsg (s2ctx_t* s2ctx, ujdec_t* D) { txjob->gpstime = uj_uint(D); break; } + case J_preamble: { + txjob->preamble = uj_uint(D); + break; + } + case J_addcrc: { + txjob->addcrc = uj_uint(D); + break; + } default: { LOG(MOD_S2E|WARNING, "Unknown field in dnmsg - ignored: %s", D->field.name); uj_skipValue(D); @@ -1240,6 +1485,10 @@ void handle_dnsched (s2ctx_t* s2ctx, ujdec_t* D) { uj_enterObject(D); while( (field = uj_nextField(D)) ) { switch(field) { + case J_diid: { // newer servers use this field name + txjob->diid = uj_int(D); + break; + } case J_priority: { txjob->prio = uj_intRange(D, 0, 255); break; @@ -1285,6 +1534,14 @@ void handle_dnsched (s2ctx_t* s2ctx, ujdec_t* D) { txjob->rctx = uj_int(D); break; } + case J_preamble: { + txjob->preamble = uj_uint(D); + break; + } + case J_addcrc: { + txjob->addcrc = uj_uint(D); + break; + } default: { LOG(MOD_S2E|WARNING, "Unknown field in dnsched.schedule[%d] - ignored: %s", slot, D->field.name); uj_skipValue(D); @@ -1306,8 +1563,8 @@ void handle_dnsched (s2ctx_t* s2ctx, ujdec_t* D) { txjob->txflags = TXFLAG_CLSA; } if( txjob->txtime != 0 ) { - LOG(MOD_S2E|INFO, "DNSCHED %>T %~T DR%-2d %F - %d bytes", - rt_ustime2utc(txjob->txtime), txjob->txtime-now, txjob->dr, txjob->freq, txjob->len); + LOG(MOD_S2E|INFO, "DNSCHED diid=%ld %>T %~T DR%-2d %F - %d bytes", + txjob->diid, rt_ustime2utc(txjob->txtime), txjob->txtime-now, txjob->dr, txjob->freq, txjob->len); txq_commitJob(&s2ctx->txq, txjob); if( !s2e_addTxjob(s2ctx, txjob, /*initial placement*/0, now) ) txq_freeJob(&s2ctx->txq, txjob); @@ -1374,6 +1631,56 @@ void handle_timesync (s2ctx_t* s2ctx, ujdec_t* D) { } +void handle_getxtime (s2ctx_t* s2ctx, ujdec_t* D) { + // No fields required - skip everything + ujcrc_t field; + double muxtime = 0; + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_msgtype: { + uj_skipValue(D); + break; + } + case J_MuxTime: { + muxtime = uj_num(D); + break; + } + default: { + LOG(MOD_S2E|WARNING, "Unknown field in getxtime - ignored: %s", D->field.name); + uj_skipValue(D); + break; + } + } + } + // Get a send buffer - parse frame / check filter + ujbuf_t sendbuf = (*s2ctx->getSendbuf)(s2ctx, MIN_UPJSON_SIZE); + if( sendbuf.buf == NULL ) { + // Websocket has no space - WS will call again + return; + } + ustime_t ustime = rt_getTime(); + uj_encOpen(&sendbuf, '{'); + uj_encKVn(&sendbuf, + "msgtype", 's', "getxtime", + "MuxTime", 'T', muxtime, + "ustime", 'T', ustime/1e6, + "UTCtime", 'T', rt_ustime2utc(ustime)/1e6, + "xtimes", '[', 0); + for( int txunit=0; txunitsendText)(s2ctx, &sendbuf); + assert(sendbuf.buf==NULL); + } +} + + void handle_runcmd (s2ctx_t* s2ctx, ujdec_t* D) { ujcrc_t field; char* argv[MAX_CMDARGS+2] = { NULL }; @@ -1470,6 +1777,10 @@ int s2e_onMsg (s2ctx_t* s2ctx, char* json, ujoff_t jsonlen) { handle_timesync(s2ctx, &D); break; } + case J_getxtime: { + handle_getxtime(s2ctx, &D); + break; + } case J_runcmd: { handle_runcmd(s2ctx, &D); break; @@ -1478,6 +1789,22 @@ int s2e_onMsg (s2ctx_t* s2ctx, char* json, ujoff_t jsonlen) { s2e_handleRmtsh(s2ctx, &D); break; } + case J_error: { + ujcrc_t field; + while( (field = uj_nextField(&D)) ) { + switch(field) { + case J_error: { + LOG(MOD_S2E|WARNING, "LNS ERROR Msg: %s", uj_str(&D)); + break; + } + default: { + uj_skipValue(&D); + break; + } + } + } + break; + } default: { // Platform specific commands if( !s2e_handleCommands(msgtype, s2ctx, &D) ) diff --git a/src/s2e.h b/src/s2e.h index 5557a34..fe0d973 100644 --- a/src/s2e.h +++ b/src/s2e.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _s2e_h_ @@ -38,7 +37,8 @@ extern uL_t* s2e_joineuiFilter; extern u4_t s2e_netidFilter[4]; -int s2e_parse_lora_frame(ujbuf_t* buf, const u1_t* frame , int len, dbuf_t* lbuf); +int s2e_parse_lora_frame(ujbuf_t* buf, const u1_t* frame , int len, dbuf_t* lbuf); +void s2e_make_beacon (uint8_t* layout, sL_t epoch_secs, int infodesc, double lat, double lon, uint8_t* buf); enum { SF12, SF11, SF10, SF9, SF8, SF7, FSK, SFNIL }; @@ -77,14 +77,16 @@ enum { TXCOND_NODC, // definitely no DC }; -enum { PRIO_PENALTY_ALTTXTIME = 10 }; -enum { PRIO_PENALTY_ALTANTENNA = 10 }; -enum { PRIO_PENALTY_CCA = 8 }; +enum { PRIO_PENALTY_ALTTXTIME = 10 }; +enum { PRIO_PENALTY_ALTANTENNA = 10 }; +enum { PRIO_PENALTY_CCA = 8 }; +enum { PRIO_BEACON = 128 }; enum { DC_DECI, DC_CENTI, DC_MILLI, DC_NUM_BANDS }; enum { MAX_DNCHNLS = 48 }; +enum { MAX_UPCHNLS = MAX_130X * 10 }; // 10 channels per chip enum { DR_CNT = 16 }; enum { DR_ILLEGAL = 16 }; @@ -95,6 +97,12 @@ typedef struct s2txunit { tmr_t timer; } s2txunit_t; +typedef struct s2bcn { + u1_t ctrl; // 0x0F => DR, 0xF0 = n frequencies + u1_t layout[3]; // time_off, infodesc_off, bcn_len + u4_t freqs[8]; // 1 or up to 8 frequencies +} s2bcn_t; + typedef struct s2ctx { dbuf_t (*getSendbuf) (struct s2ctx* s2ctx, int minsize); // wired to TC/websocket void (*sendText) (struct s2ctx* s2ctx, dbuf_t* buf); // ditto @@ -117,6 +125,8 @@ typedef struct s2ctx { double muxtime; // time stamp from muxs ustime_t reftime; // local time at arrival of muxtime s2txunit_t txunits[MAX_TXUNITS]; + s2bcn_t bcn; // beacon definition + tmr_t bcntimer; } s2ctx_t; @@ -131,7 +141,7 @@ extern u1_t s2e_dwellDisabled; // ignore dwell time limits - override for test/d rps_t s2e_dr2rps (s2ctx_t*, u1_t dr); u1_t s2e_rps2dr (s2ctx_t*, rps_t rps); ustime_t s2e_calcUpAirTime (rps_t rps, u1_t plen); -ustime_t s2e_calcDnAirTime (rps_t rps, u1_t plen); +ustime_t s2e_calcDnAirTime (rps_t rps, u1_t plen, u1_t lcrc, u2_t preamble); ustime_t s2e_updateMuxtime(s2ctx_t* s2ctx, double muxstime, ustime_t now); // now=0 => rt_getTime(), return now void s2e_ini (s2ctx_t*); diff --git a/src/selftest_fs.c b/src/selftest_fs.c index 0cb0ffa..01222c1 100644 --- a/src/selftest_fs.c +++ b/src/selftest_fs.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_linux) || defined(CFG_flashsim) diff --git a/src/selftest_lora.c b/src/selftest_lora.c index a476bf5..159786e 100644 --- a/src/selftest_lora.c +++ b/src/selftest_lora.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "selftests.h" diff --git a/src/selftest_rt.c b/src/selftest_rt.c index 62aaf94..bde790c 100644 --- a/src/selftest_rt.c +++ b/src/selftest_rt.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "selftests.h" diff --git a/src/selftest_ujdec.c b/src/selftest_ujdec.c index 198f1c1..7b6d93e 100644 --- a/src/selftest_ujdec.c +++ b/src/selftest_ujdec.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -107,7 +106,7 @@ static const char* T8 = " 125e-2 "; static const char* T9 = " 128e+2 "; static const char* T10= " -125.68e-2 "; static const char* T11= " -0.00128e+4 "; -static const char* T12= " \" \\\\-\\b-\\f-\\t-\\n-\\r-\\\"-\\/-\\u0041 \" "; +static const char* T12= " \" \\\\-\\b-\\f-\\t-\\n-\\r-\\\"-\\/-\\u0041\\u00c2\\u00bf\\uc2bf \" "; static const char* T13= " 7654321 "; static const char* T14= " -7654321 "; static const char* T15= " \"91-A2-B3-C4-D5-E6-F7-08\" "; @@ -182,7 +181,8 @@ static void test_simple_values() { SETUP(T12); TCHECK(t == UJ_STRING); - TCHECK(strcmp(D.str.beg, " \\-\b-\f-\t-\n-\r-\"-/-A ")==0); + // \u00c2 \u00bf \uc2bf + TCHECK(strcmp(D.str.beg, " \\-\b-\f-\t-\n-\r-\"-/-A\xc3\x82\xc2\xbf\xec\x8a\xbf ")==0); uj_assertEOF(&D); SETUP(T13); diff --git a/src/selftest_ujenc.c b/src/selftest_ujenc.c index 0556eea..eb7dae4 100644 --- a/src/selftest_ujenc.c +++ b/src/selftest_ujenc.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "selftests.h" @@ -60,7 +59,7 @@ static void test_simple_values() { uj_encNum (&B, 1.5); uj_encTime(&B, 21.5); uj_encDate(&B, 1451649600L*1000000LL); - uj_encStr (&B, "-\"\\\b\f\n\r\t\x01-"); + uj_encStr (&B, "-\"\\\b\f\n\r\t\x01\x02\xc2\xbf-"); uj_encHex (&B, (const u1_t*)"ABC", 3); uj_encMac (&B, 0x1A2B3C4DA1B2C3D4); uj_encEui (&B, 0x91A2B3C4D5E6F708); @@ -74,7 +73,7 @@ static void test_simple_values() { uj_encClose(&B, ']'); TCHECK(xeos(&B) == 1 ); T = "[null,false,true,-1,1,1.5,21.500000,\"2016-01-01 12:00:00\"," - "\"-\\\"\\\\\\b\\f\\n\\r\\t\\u0001-\"," + "\"-\\\"\\\\\\b\\f\\n\\r\\t\\u0001\\u0002\xc2\xbf-\"," "\"414243\"," "\"3C:4D:A1:B2:C3:D4\"," "\"91-A2-B3-C4-D5-E6-F7-08\"," diff --git a/src/selftest_xprintf.c b/src/selftest_xprintf.c index dafeb68..95818f9 100644 --- a/src/selftest_xprintf.c +++ b/src/selftest_xprintf.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "selftests.h" diff --git a/src/selftest_xq.c b/src/selftest_xq.c index 863b897..8c4be9a 100644 --- a/src/selftest_xq.c +++ b/src/selftest_xq.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "selftests.h" diff --git a/src/selftests.c b/src/selftests.c index 9d16b4d..1e27b6e 100644 --- a/src/selftests.c +++ b/src/selftests.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/src/selftests.h b/src/selftests.h index e7bbf2c..d3860e5 100644 --- a/src/selftests.h +++ b/src/selftests.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _selftests_h_ diff --git a/src/sx1301conf.c b/src/sx1301conf.c deleted file mode 100644 index bca649c..0000000 --- a/src/sx1301conf.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if defined(CFG_lgw1) - -#include "uj.h" -#include "kwcrc.h" -#include "sys.h" -#if defined(CFG_linux) -#include "sys_linux.h" -#endif // defined(CFG_linux) -#include "sx1301conf.h" -#include "lgw/loragw_reg.h" - -static void parse_tx_gain_lut (ujdec_t* D, struct lgw_tx_gain_lut_s* txlut) { - int slot; - uj_enterArray(D); - while( (slot = uj_nextSlot(D)) >= 0 ) { - if( slot >= TX_GAIN_LUT_SIZE_MAX ) - uj_error(D, "Too many TX_GAIN_LUT entries (no more than %d allowed)", TX_GAIN_LUT_SIZE_MAX); - ujcrc_t field; - uj_enterObject(D); - while( (field = uj_nextField(D)) ) { - switch(field) { - case J_pa_gain: { txlut->lut[slot].pa_gain = uj_intRange(D, 0, 3); break; } - case J_dig_gain: { txlut->lut[slot].dig_gain = uj_intRange(D, 0, 3); break; } - case J_dac_gain: { txlut->lut[slot].dac_gain = uj_intRange(D, 0, 3); break; } - case J_mix_gain: { txlut->lut[slot].mix_gain = uj_intRange(D, 0, 15); break; } - case J_rf_power: { txlut->lut[slot].rf_power = uj_intRange(D, -128,127); break; } - default: { - uj_error(D, "Illegal field: %s", D->field.name); - } - } - } - uj_exitObject(D); - txlut->size = slot+1; - } - uj_exitArray(D); -} - - -static u1_t parse_antenna_type (str_t s) { - if( strcasecmp(s,"omni") == 0 ) - return SX1301_ANT_OMNI; - if( strcasecmp(s,"sector") == 0 ) - return SX1301_ANT_SECTOR; - LOG(MOD_RAL|ERROR,"Unknown antenna info: %s (treating as undefined)", s); - return SX1301_ANT_UNDEF; -} - - -static void parse_rfconf (ujdec_t* D, struct sx1301conf* sx1301conf, int rfidx) { - struct lgw_conf_rxrf_s* rfconf = &sx1301conf->rfconf[rfidx]; - ujcrc_t field; - uj_enterObject(D); - while( (field = uj_nextField(D)) ) { - switch(field) { - case J_enable: { rfconf->enable = uj_bool(D); break; } - case J_tx_enable: { rfconf->tx_enable = uj_bool(D); break; } - case J_txpow_adjust: - case J_antenna_gain: { sx1301conf->txpowAdjust = (s2_t)(uj_num(D)*TXPOW_SCALE); break; } - case J_antenna_type: { sx1301conf->antennaType = parse_antenna_type(uj_str(D)); break; } - case J_freq: { rfconf->freq_hz = uj_intRangeOr(D, 1000000, 1000000000, 0); break; } - case J_tx_notch_freq: { rfconf->tx_notch_freq = uj_intRange(D, LGW_MIN_NOTCH_FREQ, LGW_MAX_NOTCH_FREQ); break; } - case J_rssi_offset: { rfconf->rssi_offset = uj_num(D); break; } - case J_rssi_offset_lbt:{ sx1301conf->lbt.rssi_offset = uj_intRange(D, -128, 127); break; } - case J_type: { - uj_str(D); - /**/ if( D->str.crc == J_SX1255 ) rfconf->type = LGW_RADIO_TYPE_SX1255; - else if( D->str.crc == J_SX1257 ) rfconf->type = LGW_RADIO_TYPE_SX1257; - else if( D->str.crc == J_SX1272 ) rfconf->type = LGW_RADIO_TYPE_SX1272; - else if( D->str.crc == J_SX1276 ) rfconf->type = LGW_RADIO_TYPE_SX1276; - else uj_error(D, "Illegal value for field \"type\": %s", D->str.beg); - break; - } - default: { - uj_error(D, "Illegal field: %s", D->field.name); - } - } - } - uj_exitObject(D); -} - - -static int parse_bandwidth (ujdec_t* D) { - sL_t bw = uj_int(D); - switch(bw) { - case 500000: return BW_500KHZ; break; - case 250000: return BW_250KHZ; break; - case 125000: return BW_125KHZ; break; - default: - uj_error(D, "Illegal bandwidth value: %ld (must be 125000, 250000, or 500000)"); - return BW_UNDEFINED; // NOT REACHED - } -} - - -static int parse_spread_factor (ujdec_t* D) { - sL_t sf = uj_int(D); - switch(sf) { - case 7: return DR_LORA_SF7; break; - case 8: return DR_LORA_SF8; break; - case 9: return DR_LORA_SF9; break; - case 10: return DR_LORA_SF10; break; - case 11: return DR_LORA_SF11; break; - case 12: return DR_LORA_SF12; break; - default: - uj_error(D, "Illegal spread_factor value: %ld (must be 7,..,12)", sf); - return DR_UNDEFINED; // NOT REACHED - } -} - - -static void parse_ifconf (ujdec_t* D, struct lgw_conf_rxif_s* ifconf) { - ujcrc_t field; - uj_enterObject(D); - while( (field = uj_nextField(D)) ) { - switch(field) { - case J_enable: { ifconf->enable = uj_bool(D); break; } - case J_radio: - case J_rf_chain: { ifconf->rf_chain = uj_intRange(D, 0, LGW_RF_CHAIN_NB-1); break; } - case J_if: - case J_freq: { ifconf->freq_hz = uj_int(D); break; } - case J_bandwidth: { ifconf->bandwidth = parse_bandwidth(D); break; } - case J_spread_factor: { ifconf->datarate = parse_spread_factor(D); break; } // Lora only - case J_datarate: { ifconf->datarate = uj_int(D); break; } // FSK only - case J_sync_word: { ifconf->sync_word = uj_uint(D); break; } - case J_sync_word_size:{ ifconf->sync_word_size = uj_uint(D); break; } - default: { - uj_error(D, "Illegal field: %s", D->field.name); - } - } - } - uj_exitObject(D); -} - -static void setDevice (struct sx1301conf* sx1301conf, str_t device) { - str_t dev = sys_radioDevice(device); - int sz = sizeof(sx1301conf->device); - int n = snprintf(sx1301conf->device, sz, "%s", dev); - if( n > sz-1 ) - LOG(ERROR, "Device string too long (max %d chars): %s", sz-1, dev); - rt_free((void*)dev); -} - - -static void parse_sx1301_conf (ujdec_t* D, struct sx1301conf* sx1301conf) { - ujcrc_t field; - uj_enterObject(D); - while( (field = uj_nextField(D)) ) { - switch(field) { - case J_lorawan_public: { - sx1301conf->boardconf.lorawan_public = uj_bool(D); - break; - } - case J_device: { - // Slave config might override shared device specification - setDevice(sx1301conf, uj_str(D)); - break; - } - case J_no_gps_capture: { - sx1301conf->pps = !uj_bool(D); - break; - } - case J_pps: { - sx1301conf->pps = uj_bool(D); - break; - } - case J_clksrc: { - sx1301conf->boardconf.clksrc = uj_intRange(D, 0, LGW_RF_CHAIN_NB-1); - break; - } - case J_tx_gain_lut: { - parse_tx_gain_lut(D, &sx1301conf->txlut); - break; - } - case J_chan_FSK: { - parse_ifconf(D, &sx1301conf->ifconf[LGW_MULTI_NB+1]); - break; - } - case J_chan_Lora_std: { - parse_ifconf(D, &sx1301conf->ifconf[LGW_MULTI_NB]); - break; - } - default: { - int n = uj_indexedField(D, "chan_multiSF_"); - if( n >= 0 ) { - if( n >= LGW_IF_CHAIN_NB ) - uj_error(D, "Illegal field (index suffix out range, not in 0..%d): %s", LGW_IF_CHAIN_NB-1, D->field.name); - parse_ifconf(D, &sx1301conf->ifconf[n]); - break; - } - n = uj_indexedField(D, "radio_"); - if( n >= 0 ) { - if( n >= LGW_RF_CHAIN_NB ) - uj_error(D, "Illegal field (index suffix out range, not in 0..%d): %s", LGW_RF_CHAIN_NB-1, D->field.name); - parse_rfconf(D, sx1301conf, n); - break; - } - LOG(MOD_RAL|WARNING, "Ignoring unsupported/unknown field: %s", D->field.name); - uj_skipValue(D); - break; - } - } - } - uj_exitObject(D); -} - - -static int find_sx1301_conf (str_t filename, struct sx1301conf* sx1301conf) { - dbuf_t jbuf = sys_readFile(filename); - if( jbuf.buf == NULL ) - return 0; - ujdec_t D; - uj_iniDecoder(&D, jbuf.buf, jbuf.bufsize); - if( uj_decode(&D) ) { - LOG(MOD_RAL|ERROR, "Parsing of JSON failed - '%s' ignored", filename); - free(jbuf.buf); - return 0; - } - ujcrc_t field; - uj_enterObject(&D); - while( (field = uj_nextField(&D)) ) { - switch(field) { - case J_sx1301_conf: - case J_SX1301_conf: - case J_radio_conf: { - parse_sx1301_conf(&D, sx1301conf); - break; - } - case J_station_conf: { - // Parsed elsewhere - uj_skipValue(&D); - break; - } - default: { - LOG(MOD_RAL|WARNING, "Ignoring unsupported/unknown field: %s", D.field.name); - uj_skipValue(&D); - break; - } - } - } - uj_exitObject(&D); - uj_assertEOF(&D); - rt_free(jbuf.buf); - return 1; -} - - -static int setup_LBT (struct sx1301conf* sx1301conf, u4_t cca_region) { - u2_t scantime_us = 0; - - if( cca_region == J_AS923JP ) { - scantime_us = 5000; - sx1301conf->lbt.rssi_target = -80; - } - else if( cca_region == J_KR920 ) { - scantime_us = 5000; - sx1301conf->lbt.rssi_target = -67; - } - else { - LOG(MOD_RAL|ERROR, "Failed to setup CCA/LBT for region (crc=0x%08X)", cca_region); - return 0; - } - // By default use up link frequencies as LBT frequencies - // Otherwise we should have gotten a freq list from the server - if( sx1301conf->lbt.nb_channel == 0 ) { - for( int rfi=0; rfi < LGW_RF_CHAIN_NB; rfi++ ) { - if( !sx1301conf->rfconf[rfi].enable ) - continue; - u4_t cfreq = sx1301conf->rfconf[rfi].freq_hz; - int n = max(8,LGW_IF_CHAIN_NB); // only consider normal Lora modems (aka not fast/FSK) - for( int ifi=0; ifi < n; ifi++ ) { - if( !sx1301conf->ifconf[ifi].enable ) - continue; - if( sx1301conf->lbt.nb_channel < LBT_CHANNEL_FREQ_NB ) { - u4_t freq = cfreq + sx1301conf->ifconf[ifi].freq_hz; - sx1301conf->lbt.channels[sx1301conf->lbt.nb_channel].freq_hz = freq; - sx1301conf->lbt.nb_channel += 1; - } - } - } - } - for( int i=0; ilbt.nb_channel; i++ ) - sx1301conf->lbt.channels[i].scan_time_us = scantime_us; - sx1301conf->lbt.enable = 1; - int e = lgw_lbt_setconf(sx1301conf->lbt); - if( e != LGW_HAL_SUCCESS ) { - LOG(MOD_RAL|ERROR, "lgw_lbt_setconf failed: %s", sx1301conf->device); - return 0; - } - return 1; -} - - -int sx1301conf_parse_setup (struct sx1301conf* sx1301conf, int slaveIdx, - str_t hwspec, char* json, int jsonlen) { - if( strcmp(hwspec, "sx1301/1") != 0 ) { - LOG(MOD_RAL|ERROR, "Unsupported hwspec: %s", hwspec); - return 0; - } - // Zero and setup some defaults - memset(sx1301conf, 0, sizeof(*sx1301conf)); - sx1301conf->boardconf.lorawan_public = 1; - setDevice(sx1301conf, NULL); - - if( !find_sx1301_conf("station.conf", sx1301conf) ) - return 0; - if( slaveIdx >= 0 ) { - char cfname[64]; - snprintf(cfname, sizeof(cfname), "slave-%d.conf", slaveIdx); - if( !find_sx1301_conf(cfname, sx1301conf) ) - return 0; - } - - ujdec_t D; - uj_iniDecoder(&D, json, jsonlen); - if( uj_decode(&D) ) { - LOG(MOD_RAL|ERROR, "Parsing of JSON failed - 'router_config.sx1301_conf' ignored"); - return 0; - } - parse_sx1301_conf(&D, sx1301conf); - uj_assertEOF(&D); - return 1; -} - - -int sx1301conf_start (struct sx1301conf* sx1301conf, u4_t cca_region) { -#if defined(CFG_linux) - u4_t pids[1]; - int n = sys_findPids(sx1301conf->device, pids, SIZE_ARRAY(pids)); - if( n > 0 ) - rt_fatal("Radio device '%s' in use by process: %d%s", sx1301conf->device, pids[0], n>1?".. (and others)":""); -#endif // defined(CFG_linux) - - lgw_stop(); - LOG(MOD_RAL|INFO,"Lora gateway library version: %s", lgw_version_info()); - - if( lgw_board_setconf(sx1301conf->boardconf) != LGW_HAL_SUCCESS ) { - LOG(MOD_RAL|ERROR,"lgw_board_setconf failed"); - goto fail; - } - if( sx1301conf->txlut.size > 0) { - if( lgw_txgain_setconf(&sx1301conf->txlut) != LGW_HAL_SUCCESS ) { - LOG(MOD_RAL|INFO,"lgw_txgain_setconf failed"); - goto fail; - } - } - for( int i=0; irfconf[i]) != LGW_HAL_SUCCESS ) { - LOG(MOD_RAL|INFO,"lgw_rxrf_setconf(%d) failed", i); - goto fail; - } - } - for( int i=0; iifconf[i]) != LGW_HAL_SUCCESS ) { - LOG(MOD_RAL|INFO,"lgw_rxif_setconf(%d) failed", i); - goto fail; - } - } - - if( cca_region && !setup_LBT(sx1301conf, cca_region) ) { - goto fail; - } - - if( log_shallLog(MOD_RAL|VERBOSE) ) { - LOG(MOD_RAL|DEBUG, "SX1301 txlut table (%d entries)", sx1301conf->txlut.size); - for( int i=0; itxlut.size; i++ ) { - LOG(MOD_RAL|VERBOSE, - "SX1301 txlut %2d: dig_gain=%d pa_gain=%d dac_gain=%d mix_gain=%d rf_power=%d", i, - sx1301conf->txlut.lut[i].dig_gain, - sx1301conf->txlut.lut[i].pa_gain, - sx1301conf->txlut.lut[i].dac_gain, - sx1301conf->txlut.lut[i].mix_gain, - sx1301conf->txlut.lut[i].rf_power); - } - for( int i=0; irfconf[i].enable, - sx1301conf->rfconf[i].freq_hz, - sx1301conf->rfconf[i].rssi_offset, - sx1301conf->rfconf[i].type, - sx1301conf->rfconf[i].tx_enable, - sx1301conf->rfconf[i].tx_notch_freq); - } - for( int i=0; iifconf[i].enable, - sx1301conf->ifconf[i].rf_chain, - sx1301conf->ifconf[i].freq_hz, - sx1301conf->ifconf[i].bandwidth, - sx1301conf->ifconf[i].datarate, - sx1301conf->ifconf[i].sync_word, sx1301conf->ifconf[i].sync_word_size); - } - if( sx1301conf->lbt.enable ) { - LOG(MOD_RAL|VERBOSE, "SX1301 LBT enabled: rssi_target=%d rssi_offset=%d", - sx1301conf->lbt.rssi_target, sx1301conf->lbt.rssi_offset); - for( int i=0; i < sx1301conf->lbt.nb_channel; i++ ) { - LOG(MOD_RAL|VERBOSE, " %2d: freq=%F scan=%dus", - i, sx1301conf->lbt.channels[i].freq_hz, sx1301conf->lbt.channels[i].scan_time_us); - } - } else { - LOG(MOD_RAL|VERBOSE, "SX1301 LBT not enabled"); - } - } - - LOG(MOD_RAL|INFO, "Station device: %s (PPS capture %sabled)", sx1301conf->device, sx1301conf->pps ? "en":"dis"); - lgwx_device_mode = sys_deviceMode; - int err = lgw_start(); - if( err == LGW_HAL_SUCCESS ) { - lgw_reg_w(LGW_GPS_EN, sx1301conf->pps ? 1 : 0); - return 1; - } - LOG(MOD_RAL|ERROR, "lgw_start failed: %s", sx1301conf->device); - fail: - return 0; -} - -#endif // defined(CFG_lgw1) diff --git a/src/sx1301conf.h b/src/sx1301conf.h deleted file mode 100644 index fad05fb..0000000 --- a/src/sx1301conf.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _sx1301conf_h_ -#define _sx1301conf_h_ -#if defined(CFG_lgw1) - -#include // loragw_fpga.h refers to FILE -#include "lgw/loragw_hal.h" -#include "lgw/loragw_lbt.h" -#include "lgw/loragw_fpga.h" -#include "s2conf.h" - - -#define SX1301_ANT_NIL 0 -#define SX1301_ANT_OMNI 1 -#define SX1301_ANT_SECTOR 2 -#define SX1301_ANT_UNDEF 3 - -struct sx1301conf { - struct lgw_conf_board_s boardconf; - struct lgw_tx_gain_lut_s txlut; - struct lgw_conf_rxrf_s rfconf[LGW_RF_CHAIN_NB]; - struct lgw_conf_rxif_s ifconf[LGW_IF_CHAIN_NB]; - struct lgw_conf_lbt_s lbt; - s2_t txpowAdjust; // assuming there is only one TX path / SX1301 (scaled by TXPOW_SCALE) - u1_t pps; // enable PPS latch of trigger count - u1_t antennaType; // type of antenna - char device[MAX_DEVICE_LEN]; // SPI device, FTDI spec etc. -}; - -extern str_t station_conf_USAGE; - -int sx1301conf_parse_setup (struct sx1301conf* sx1301conf, int slaveIdx, str_t hwspec, char* json, int jsonlen); -int sx1301conf_start (struct sx1301conf* sx1301conf, u4_t region); - - -#endif // defined(CFG_lgw1) -#endif // _sx1301conf_h_ diff --git a/src/sx1301v2conf.c b/src/sx1301v2conf.c index 24df124..a7d63ad 100644 --- a/src/sx1301v2conf.c +++ b/src/sx1301v2conf.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_lgw2) @@ -35,7 +34,7 @@ #include "sys.h" #include "sx1301v2conf.h" #include "lgw2/sx1301ar_err.h" - +#include "lgw2/sx1301ar_reg.h" // Describes radio config for HW spec sx1301/n as sent by LNS struct lns_sx1301_conf { @@ -146,7 +145,7 @@ static int parse_bandwidth (ujdec_t* D) { case 250000: return BW_250K; break; case 125000: return BW_125K; break; default: - uj_error(D, "Illegal bandwidth value: %ld (must be 125000, 250000, or 500000)"); + uj_error(D, "Illegal bandwidth value: %ld (must be 125000, 250000, or 500000)", bw); return BW_UNDEFINED; // NOT REACHED } } @@ -303,6 +302,11 @@ static void parse_radio_conf (ujdec_t* D, struct sx1301v2conf* sx1301v2conf) { boardconf->dsp_stat_interval = uj_intRange(D,0,255); break; } + case J_fpga_flavor: { + uj_str(D); + sx1301v2conf->boards[boardidx].fpga_flavor = D->str.crc; + break; + } case J_aes_key: { int n = uj_hexstr(D, boardconf->aes_key, sizeof(boardconf->aes_key)); if( n != 16 ) @@ -438,7 +442,7 @@ static int setup_LBT (struct sx1301v2conf* sx1301v2conf, u4_t cca_region) { static int parse_sx1301_lns_conf (ujdec_t* D, struct lns_sx1301_conf* confs) { - int sx1301idx, sx1301num; + int sx1301idx = 0, sx1301num = 0; uj_enterArray(D); while( (sx1301idx = uj_nextSlot(D)) >= 0 ) { sx1301num = sx1301idx+1; @@ -624,6 +628,15 @@ int sx1301v2conf_parse_setup (struct sx1301v2conf* sx1301v2conf, int slaveIdx, c->chipConf.freq_hz = (maxFreq+minFreq)/2; } + // if( + // lns_sx1301_num == 2 && + // sx1301v2conf->sx1301[1].chipConf.freq_hz == sx1301v2conf->sx1301[0].chipConf.freq_hz && + // sx1301v2conf->boards[0].boardConf.rf_chain[1].rx_enable && + // sx1301v2conf->boards[0].boardConf.rf_chain[0].rx_enable + // ) { + // sx1301v2conf->sx1301[1].chipConf.rf_chain = 1; + // } + return 1; @@ -632,29 +645,113 @@ int sx1301v2conf_parse_setup (struct sx1301v2conf* sx1301v2conf, int slaveIdx, static void dump_boardConf (int bid, sx1301ar_board_cfg_t* c) { LOG(MOD_RAL|VERBOSE, - "BRD#%d: rx_freq_hz=%d rx_bw_hz=%d", + "__ BRD#%d : %^8F bw=%F %s", bid, c->rx_freq_hz, - c->rx_bw_hz); + c->rx_bw_hz, + c->board_type == BRD_MASTER ? "MASTER" : "SLAVE_"); + if( c->board_type == BRD_MASTER ) { + for( int r = 0; r < SX1301AR_BOARD_RFCHAIN_NB; r++ ) { + sx1301ar_rfchain_t* rfc = &c->rf_chain[r]; + LOG(MOD_RAL|VERBOSE, " rf %d : %s%s%s", r, + rfc->rx_enable ? "RX " : "", + rfc->tx_enable ? "TX" : "", + !rfc->rx_enable && !rfc->tx_enable ? "disabled" : "" + ); + } + } } static void dump_chipConf (int chipid, sx1301ar_chip_cfg_t* c) { + if( !c->enable ) { + LOG(MOD_RAL|VERBOSE, "SX1301#%d : disabled", chipid); + return; + } LOG(MOD_RAL|VERBOSE, - "SX1301#%d: enable=%d rf_chain=%d freq=%d", + "SX1301#%d : %^8F rf_chain=%d", chipid, - c->enable, - c->rf_chain, - c->freq_hz); + c->freq_hz, + c->rf_chain); } static void dump_chanConf (int chipid, int chanid, sx1301ar_chan_cfg_t* c) { + if( ! c->enable ) { + LOG(MOD_RAL|VERBOSE, " ch %d,%d : disabled", chipid, chanid); + return; + } + if( chanid == SX1301AR_CHIP_FSK_IDX ) { + LOG(MOD_RAL|VERBOSE, + " ch %d,%d : %^8F FSK %d baud", + chipid, + chanid, + c->freq_hz, + c->modrate); + return; + } LOG(MOD_RAL|VERBOSE, - "SX1301#%d chan %2d: enable=%d freq=%d bandwidth=%d modrate=%d", - chipid, chanid, - c->enable, + " ch %d,%d : %^8F bw=%^5~F SF%d-%d", + chipid, + chanid, c->freq_hz, - c->bandwidth, - c->modrate); + sx1301ar_bw_enum2nb(c->bandwidth), + sx1301ar_sf_min_enum2nb(c->modrate), + sx1301ar_sf_max_enum2nb(c->modrate)); +} + + +static void sx1301v2conf_challoc_cb (void* ctx, challoc_t* ch, int flag) { + if( ctx == NULL ) return; + struct sx1301v2conf* sx1301v2conf = (struct sx1301v2conf*)ctx; + + switch( flag ) { + case CHALLOC_START: { + break; + } + case CHALLOC_CHIP_START: { + break; + } + case CHALLOC_CH: { + sx1301ar_chan_cfg_t* chanc = &sx1301v2conf->sx1301[ch->chip].chanConfs[ch->chan]; + chanc->enable = 1; + chanc->freq_hz = ch->chdef.freq; + + if( ch->chan == SX1301AR_CHIP_FSK_IDX ) { + chanc->modrate = MR_56000; + chanc->bandwidth = BW_UNDEFINED; + } + else if( ch->chan == SX1301AR_CHIP_LSA_IDX ) { + chanc->modrate = ral_rps2sf(rps_make(ch->chdef.rps.maxSF, ch->chdef.rps.bw)); + chanc->bandwidth = ral_rps2bw(rps_make(ch->chdef.rps.maxSF, ch->chdef.rps.bw)); + } + else { + chanc->modrate = sx1301ar_sf_range_nb2enum( + sx1301ar_sf_enum2nb(ral_rps2sf(rps_make(ch->chdef.rps.minSF, ch->chdef.rps.bw))), + sx1301ar_sf_enum2nb(ral_rps2sf(rps_make(ch->chdef.rps.maxSF, ch->chdef.rps.bw)))); + chanc->bandwidth = BW_125K; + } + + break; + } + case CHALLOC_CHIP_DONE: { + if( !ch->chans ) break; + sx1301v2conf->sx1301[ch->chipid].chipConf.enable = 1; + sx1301v2conf->sx1301[ch->chipid].chipConf.rf_chain = 0; + sx1301v2conf->sx1301[ch->chipid].chipConf.freq_hz = (ch->maxFreq+ch->minFreq)/2; + break; + } + case CHALLOC_DONE: { + if( sx1301v2conf->boards[0].boardConf.rf_chain[1].rx_enable && + !sx1301v2conf->sx1301[1].chipConf.enable ) { + memcpy(&sx1301v2conf->sx1301[1], &sx1301v2conf->sx1301[0], sizeof(struct chip_conf)); + sx1301v2conf->sx1301[1].chipConf.rf_chain = 1; + } + break; + } + } +} + +int sx1301v2conf_challoc (struct sx1301v2conf* sx1301v2conf, chdefl_t* upchs) { + return ral_challoc(upchs, sx1301v2conf_challoc_cb, sx1301v2conf); } @@ -680,9 +777,9 @@ int sx1301v2conf_start (struct sx1301v2conf* sx1301v2conf, u4_t cca_region) { return 0; } for( int chanidx=0; chanidx < SX1301AR_CHIP_CHAN_NB; chanidx++ ) { + dump_chanConf(chipidx, chanidx, &cc->chanConfs[chanidx]); if( !cc->chanConfs[chanidx].enable ) continue; - dump_chanConf(chipidx, chanidx, &cc->chanConfs[chanidx]); if( sx1301ar_conf_chan(boardidx, (chipidx << 4) | chanidx, &cc->chanConfs[chanidx]) != 0 ) { LOG(MOD_RAL|ERROR, "sx1301ar_conf_chan(%d,%d,%d,..) failed: %s", boardidx, chipidx, chanidx, sx1301ar_err_message(sx1301ar_errno)); @@ -703,4 +800,5 @@ int sx1301v2conf_start (struct sx1301v2conf* sx1301v2conf, u4_t cca_region) { return 0; } + #endif // defined(CFG_lgw2) diff --git a/src/sx1301v2conf.h b/src/sx1301v2conf.h index 335f588..99d9ee0 100644 --- a/src/sx1301v2conf.h +++ b/src/sx1301v2conf.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _sx1301v2conf_h_ @@ -33,6 +32,7 @@ #include "lgw2/sx1301ar_hal.h" #include "s2conf.h" +#include "ral.h" #define SX1301_ANT_NIL 0 @@ -48,6 +48,7 @@ struct board_conf { float txpowAdjusts[SX1301AR_BOARD_RFCHAIN_NB]; u1_t antennaTypes[SX1301AR_BOARD_RFCHAIN_NB]; u1_t pps; // enable PPS latch of trigger count + ujcrc_t fpga_flavor; }; struct chip_conf { @@ -62,8 +63,8 @@ struct sx1301v2conf { int sx1301v2conf_parse_setup (struct sx1301v2conf* sx1301v2conf, int slaveIdx, str_t hwspec, char* json, int jsonlen); +int sx1301v2conf_challoc (struct sx1301v2conf* sx1301v2conf, chdefl_t* upchs); int sx1301v2conf_start (struct sx1301v2conf* sx1301v2conf, u4_t region); - #endif // defined(CFG_lgw2) #endif // _sx1301v2conf_h_ diff --git a/src/sx130xconf.c b/src/sx130xconf.c new file mode 100644 index 0000000..02258d6 --- /dev/null +++ b/src/sx130xconf.c @@ -0,0 +1,713 @@ +/* + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(CFG_lgw1) + +#include "uj.h" +#include "kwcrc.h" +#include "sys.h" +#if defined(CFG_linux) +#include "sys_linux.h" +#endif // defined(CFG_linux) +#include "sx130xconf.h" +#include "lgw/loragw_reg.h" +#if defined(CFG_sx1302) +#include "lgw/loragw_sx1302.h" +#endif // defined(CFG_sx1302) + +#define SX130X_RFE_MAX 400000 // Max if offset 400kHz + +static void parse_tx_gain_lut (ujdec_t* D, struct lgw_tx_gain_lut_s* txlut) { + int slot; + uj_enterArray(D); + while( (slot = uj_nextSlot(D)) >= 0 ) { + if( slot >= TX_GAIN_LUT_SIZE_MAX ) + uj_error(D, "Too many TX_GAIN_LUT entries (no more than %d allowed)", TX_GAIN_LUT_SIZE_MAX); + ujcrc_t field; + uj_enterObject(D); + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_pa_gain: { txlut->lut[slot].pa_gain = uj_intRange(D, 0, 3); break; } +#if defined(CFG_sx1302) + case J_pwr_idx: { + /*Setting for sx1250 */ + txlut->lut[slot].pwr_idx = uj_intRange(D, 0, 27); + /*TODO: rework this, should not be needed for sx1250 */ + txlut->lut[slot].mix_gain = 5; + /* This is only dac_gain supported for now */ + txlut->lut[slot].dac_gain = 3; + break; + } +#else + case J_dig_gain: { txlut->lut[slot].dig_gain = uj_intRange(D, 0, 3); break; } + case J_dac_gain: { txlut->lut[slot].dac_gain = uj_intRange(D, 0, 3); break; } + case J_mix_gain: { txlut->lut[slot].mix_gain = uj_intRange(D, 0, 15); break; } +#endif + case J_rf_power: { txlut->lut[slot].rf_power = uj_intRange(D, -128,127); break; } + default: { + uj_error(D, "Illegal field: %s", D->field.name); + } + } + } + uj_exitObject(D); + txlut->size = slot+1; + } + uj_exitArray(D); +} + +#if defined(CFG_sx1302) +static void parse_rssi_tcomp (ujdec_t* D, struct lgw_rssi_tcomp_s* rssi_tcomp) { + ujcrc_t field; + uj_enterObject(D); + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_coeff_a: { rssi_tcomp->coeff_a = uj_num(D); break; } + case J_coeff_b: { rssi_tcomp->coeff_b = uj_num(D); break; } + case J_coeff_c: { rssi_tcomp->coeff_c = uj_num(D); break; } + case J_coeff_d: { rssi_tcomp->coeff_d = uj_num(D); break; } + case J_coeff_e: { rssi_tcomp->coeff_e = uj_num(D); break; } + } + } + uj_exitObject(D); +} +#endif + +static u1_t parse_antenna_type (str_t s) { + if( strcasecmp(s,"omni") == 0 ) + return SX130X_ANT_OMNI; + if( strcasecmp(s,"sector") == 0 ) + return SX130X_ANT_SECTOR; + LOG(MOD_RAL|ERROR,"Unknown antenna info: %s (treating as undefined)", s); + return SX130X_ANT_UNDEF; +} + + +static void parse_rfconf (ujdec_t* D, struct sx130xconf* sx130xconf, int rfidx) { + struct lgw_conf_rxrf_s* rfconf = &sx130xconf->rfconf[rfidx]; + ujcrc_t field; + uj_enterObject(D); + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_enable: { rfconf->enable = uj_bool(D); break; } + case J_tx_enable: { rfconf->tx_enable = uj_bool(D); break; } + case J_txpow_adjust: + case J_antenna_gain: { sx130xconf->txpowAdjust = (s2_t)(uj_num(D)*TXPOW_SCALE); break; } + case J_antenna_type: { sx130xconf->antennaType = parse_antenna_type(uj_str(D)); break; } + case J_freq: { rfconf->freq_hz = uj_intRangeOr(D, 1000000, 1000000000, 0); break; } +#if !defined(CFG_sx1302) + case J_tx_notch_freq: { rfconf->tx_notch_freq = uj_intRange(D, LGW_MIN_NOTCH_FREQ, LGW_MAX_NOTCH_FREQ); break; } + case J_rssi_offset_lbt:{ sx130xconf->lbt.rssi_offset = uj_intRange(D, -128, 127); break; } +#endif + case J_rssi_offset: { rfconf->rssi_offset = uj_num(D); break; } + case J_type: { + uj_str(D); + /**/ if( D->str.crc == J_SX1255 ) rfconf->type = LGW_RADIO_TYPE_SX1255; + else if( D->str.crc == J_SX1257 ) rfconf->type = LGW_RADIO_TYPE_SX1257; + else if( D->str.crc == J_SX1272 ) rfconf->type = LGW_RADIO_TYPE_SX1272; + else if( D->str.crc == J_SX1276 ) rfconf->type = LGW_RADIO_TYPE_SX1276; +#if defined(CFG_sx1302) + else if( D->str.crc == J_SX1250 ) rfconf->type = LGW_RADIO_TYPE_SX1250; +#endif + else uj_error(D, "Illegal value for field \"type\": %s", D->str.beg); + break; + } +#if defined(CFG_sx1302) + case J_tx_gain_lut: { + parse_tx_gain_lut(D, &sx130xconf->txlut); + break; + } + case J_rssi_tcomp: { + parse_rssi_tcomp(D, &sx130xconf->rfconf->rssi_tcomp); + break; + } +#endif + default: { + uj_error(D, "Illegal field: %s", D->field.name); + } + } + } + uj_exitObject(D); +} + + +static int parse_bandwidth (ujdec_t* D) { + sL_t bw = uj_int(D); + switch(bw) { + case 500000: return BW_500KHZ; break; + case 250000: return BW_250KHZ; break; + case 125000: return BW_125KHZ; break; + default: + uj_error(D, "Illegal bandwidth value: %ld (must be 125000, 250000, or 500000)", bw); + return BW_UNDEFINED; // NOT REACHED + } +} + + +static int parse_spread_factor (ujdec_t* D) { + sL_t sf = uj_int(D); + switch(sf) { + case 7: return DR_LORA_SF7; break; + case 8: return DR_LORA_SF8; break; + case 9: return DR_LORA_SF9; break; + case 10: return DR_LORA_SF10; break; + case 11: return DR_LORA_SF11; break; + case 12: return DR_LORA_SF12; break; + default: + uj_error(D, "Illegal spread_factor value: %ld (must be 7,..,12)", sf); + return DR_UNDEFINED; // NOT REACHED + } +} + + +static void parse_ifconf (ujdec_t* D, struct lgw_conf_rxif_s* ifconf) { + ujcrc_t field; + uj_enterObject(D); + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_enable: { ifconf->enable = uj_bool(D); break; } + case J_radio: + case J_rf_chain: { ifconf->rf_chain = uj_intRange(D, 0, LGW_RF_CHAIN_NB-1); break; } + case J_if: + case J_freq: { ifconf->freq_hz = uj_int(D); break; } + case J_bandwidth: { ifconf->bandwidth = parse_bandwidth(D); break; } + case J_spread_factor: { ifconf->datarate = parse_spread_factor(D); break; } // Lora only + case J_datarate: { ifconf->datarate = uj_int(D); break; } // FSK only + case J_sync_word: { ifconf->sync_word = uj_uint(D); break; } + case J_sync_word_size:{ ifconf->sync_word_size = uj_uint(D); break; } +#if defined(CFG_sx1302) + /* implicit hdr */ + case J_implicit_hdr: { ifconf->implicit_hdr = uj_bool(D); break; } + case J_implicit_payload_length:{ ifconf->implicit_payload_length = uj_uint(D); break; } + case J_implicit_crc_en: { ifconf->implicit_crc_en = uj_bool(D); break; } + case J_implicit_coderate: { ifconf->implicit_coderate = uj_uint(D); break; } +#endif + default: { + uj_error(D, "Illegal field: %s", D->field.name); + } + } + } + uj_exitObject(D); +} + +static void setDevice (struct sx130xconf* sx130xconf, str_t device) { + str_t dev = sys_radioDevice(device); + int sz = sizeof(sx130xconf->device); + int n = snprintf(sx130xconf->device, sz, "%s", dev); + if( n > sz-1 ) + LOG(ERROR, "Device string too long (max %d chars): %s", sz-1, dev); +#if defined(CFG_sx1302) + sz = sizeof(sx130xconf->boardconf.spidev_path); + n = snprintf(sx130xconf->boardconf.spidev_path, sz, "%s", dev); + if( n > sz-1 ) + LOG(ERROR, "Device string too long (max %d chars): %s", sz-1, dev); +#endif + rt_free((void*)dev); +} + + +static void parse_sx130x_conf (ujdec_t* D, struct sx130xconf* sx130xconf) { + ujcrc_t field; + uj_enterObject(D); + while( (field = uj_nextField(D)) ) { + switch(field) { + case J_lorawan_public: { + sx130xconf->boardconf.lorawan_public = uj_bool(D); + break; + } + case J_device: { + // Slave config might override shared device specification + setDevice(sx130xconf, uj_str(D)); + break; + } + case J_no_gps_capture: { + sx130xconf->pps = !uj_bool(D); + break; + } + case J_pps: { + sx130xconf->pps = uj_bool(D); + break; + } + case J_clksrc: { + sx130xconf->boardconf.clksrc = uj_intRange(D, 0, LGW_RF_CHAIN_NB-1); + break; + } +#if defined(CFG_sx1302) + case J_full_duplex: { + sx130xconf->boardconf.full_duplex = uj_bool(D); + break; + } +#else + case J_tx_gain_lut: { + parse_tx_gain_lut(D, &sx130xconf->txlut); + break; + } +#endif + case J_chan_FSK: { + parse_ifconf(D, &sx130xconf->ifconf[LGW_MULTI_NB+1]); + break; + } + case J_chan_Lora_std: { + parse_ifconf(D, &sx130xconf->ifconf[LGW_MULTI_NB]); + break; + } + default: { + int n = uj_indexedField(D, "chan_multiSF_"); + if( n >= 0 ) { + if( n >= LGW_IF_CHAIN_NB ) + uj_error(D, "Illegal field (index suffix out range, not in 0..%d): %s", LGW_IF_CHAIN_NB-1, D->field.name); + parse_ifconf(D, &sx130xconf->ifconf[n]); + break; + } + n = uj_indexedField(D, "radio_"); + if( n >= 0 ) { + if( n >= LGW_RF_CHAIN_NB ) + uj_error(D, "Illegal field (index suffix out range, not in 0..%d): %s", LGW_RF_CHAIN_NB-1, D->field.name); + parse_rfconf(D, sx130xconf, n); + break; + } + LOG(MOD_RAL|WARNING, "Ignoring unsupported/unknown field: %s", D->field.name); + uj_skipValue(D); + break; + } + } + } + uj_exitObject(D); +} + + +static int find_sx130x_conf (str_t filename, struct sx130xconf* sx130xconf) { + dbuf_t jbuf = sys_readFile(filename); + if( jbuf.buf == NULL ) + return 0; + ujdec_t D; + uj_iniDecoder(&D, jbuf.buf, jbuf.bufsize); + if( uj_decode(&D) ) { + LOG(MOD_RAL|ERROR, "Parsing of JSON failed - '%s' ignored", filename); + free(jbuf.buf); + return 0; + } + ujcrc_t field; + uj_enterObject(&D); + while( (field = uj_nextField(&D)) ) { + switch(field) { + case J_sx1301_conf: + case J_SX1301_conf: + case J_sx1302_conf: + case J_SX1302_conf: + case J_radio_conf: { + parse_sx130x_conf(&D, sx130xconf); + break; + } + case J_station_conf: { + // Parsed elsewhere + uj_skipValue(&D); + break; + } + default: { + LOG(MOD_RAL|WARNING, "Ignoring unsupported/unknown field: %s", D.field.name); + uj_skipValue(&D); + break; + } + } + } + uj_exitObject(&D); + uj_assertEOF(&D); + rt_free(jbuf.buf); + return 1; +} + + +static int setup_LBT (struct sx130xconf* sx130xconf, u4_t cca_region) { +#if !defined(CFG_sx1302) // For now sx1302 does not support CCA + u2_t scantime_us = 0; + + if( cca_region == J_AS923JP ) { + scantime_us = 5000; + sx130xconf->lbt.rssi_target = -80; + } + else if( cca_region == J_KR920 ) { + scantime_us = 5000; + sx130xconf->lbt.rssi_target = -67; + } + else { + LOG(MOD_RAL|ERROR, "Failed to setup CCA/LBT for region (crc=0x%08X)", cca_region); + return 0; + } + // By default use up link frequencies as LBT frequencies + // Otherwise we should have gotten a freq list from the server + if( sx130xconf->lbt.nb_channel == 0 ) { + for( int rfi=0; rfi < LGW_RF_CHAIN_NB; rfi++ ) { + if( !sx130xconf->rfconf[rfi].enable ) + continue; + u4_t cfreq = sx130xconf->rfconf[rfi].freq_hz; + int n = max(8,LGW_IF_CHAIN_NB); // only consider normal Lora modems (aka not fast/FSK) + for( int ifi=0; ifi < n; ifi++ ) { + if( !sx130xconf->ifconf[ifi].enable ) + continue; + if( sx130xconf->lbt.nb_channel < LBT_CHANNEL_FREQ_NB ) { + u4_t freq = cfreq + sx130xconf->ifconf[ifi].freq_hz; + sx130xconf->lbt.channels[sx130xconf->lbt.nb_channel].freq_hz = freq; + sx130xconf->lbt.nb_channel += 1; + } + } + } + } + for( int i=0; ilbt.nb_channel; i++ ) + sx130xconf->lbt.channels[i].scan_time_us = scantime_us; + sx130xconf->lbt.enable = 1; + int e = lgw_lbt_setconf(sx130xconf->lbt); + if( e != LGW_HAL_SUCCESS ) { + LOG(MOD_RAL|ERROR, "lgw_lbt_setconf failed: %s", sx130xconf->device); + return 0; + } +#endif // !defined(CFG_sx1302) + return 1; +} + + +int sx130xconf_parse_setup (struct sx130xconf* sx130xconf, int slaveIdx, + str_t hwspec, char* json, int jsonlen) { + if( strcmp(hwspec, "sx1301/1") != 0 ) { + LOG(MOD_RAL|ERROR, "Unsupported hwspec: %s", hwspec); + return 0; + } + // Zero and setup some defaults + memset(sx130xconf, 0, sizeof(*sx130xconf)); + sx130xconf->boardconf.lorawan_public = 1; + setDevice(sx130xconf, NULL); + + if( !find_sx130x_conf("station.conf", sx130xconf) ) + return 0; + if( slaveIdx >= 0 ) { + char cfname[64]; + snprintf(cfname, sizeof(cfname), "slave-%d.conf", slaveIdx); + if( !find_sx130x_conf(cfname, sx130xconf) ) + return 0; + } + + ujdec_t D; + uj_iniDecoder(&D, json, jsonlen); + if( uj_decode(&D) ) { + LOG(MOD_RAL|ERROR, "Parsing of JSON failed - 'router_config.sx130x_conf' ignored"); + return 0; + } + parse_sx130x_conf(&D, sx130xconf); + uj_assertEOF(&D); + return 1; +} + + +static void sx130xconf_challoc_cb (void* ctx, challoc_t* ch, int flag) { + if( ctx == NULL ) return; + struct sx130xconf* sx130xconf = (struct sx130xconf*)ctx; + + switch( flag ) { + case CHALLOC_START: { + break; + } + case CHALLOC_CHIP_START: { + break; + } + case CHALLOC_CH: { + if( ch->chip > 0 ) return; + + sx130xconf->rfconf[ch->rff].freq_hz = ch->rff_freq; + sx130xconf->rfconf[ch->rff].enable = true; + + struct lgw_conf_rxif_s * ifconf = &sx130xconf->ifconf[ch->chan]; + ifconf->freq_hz = ch->chdef.freq; // Write full frequency for now + ifconf->rf_chain = ch->rff; + + if( ch->chan < LGW_IF_CHAIN_NB-2 ) { + // MultiSF + ifconf->bandwidth = BW125; +#if defined(CFG_sx1302) + ifconf->datarate = DR_UNDEFINED; +#else + ifconf->datarate = DR_LORA_MULTI; +#endif + ifconf->enable = true; + } + else if( ch->chan == LGW_IF_CHAIN_NB-1 ) { + // FSK + ifconf->bandwidth = BW_UNDEFINED; + ifconf->datarate = 50000; + ifconf->enable = true; + ifconf->sync_word = 0; + } + else if( ch->chan == LGW_IF_CHAIN_NB-2 ) { + // Fast LoRa + ifconf->bandwidth = ral_rps2bw(rps_make(ch->chdef.rps.maxSF, ch->chdef.rps.bw)); + ifconf->datarate = ral_rps2sf(rps_make(ch->chdef.rps.maxSF, ch->chdef.rps.bw)); + ifconf->enable = true; + } + break; + } + case CHALLOC_CHIP_DONE: { + // Convert full if frequency to frequency offset + if( !ch->chans ) break; + for( int ch=0; chifconf[ch].enable && sx130xconf->ifconf[ch].freq_hz && abs(sx130xconf->ifconf[ch].freq_hz) > SX130X_RFE_MAX ) { + sx130xconf->ifconf[ch].freq_hz = sx130xconf->ifconf[ch].freq_hz - + sx130xconf->rfconf[sx130xconf->ifconf[ch].rf_chain].freq_hz; + } + } + break; + } + case CHALLOC_DONE: { + break; + } + } +} + +int sx130xconf_challoc (struct sx130xconf* sx130xconf, chdefl_t* upchs) { + return ral_challoc(upchs, sx130xconf_challoc_cb, sx130xconf); +} + + +int sx130xconf_start (struct sx130xconf* sx130xconf, u4_t cca_region) { + str_t errmsg = ""; + lgw_stop(); + LOG(MOD_RAL|INFO,"Lora gateway library version: %s", lgw_version_info()); + +#if defined(CFG_linux) + u4_t pids[1]; + int n = sys_findPids(sx130xconf->device, pids, SIZE_ARRAY(pids)); + if( n > 0 ) + rt_fatal("Radio device '%s' in use by process: %d%s", sx130xconf->device, pids[0], n>1?".. (and others)":""); +#endif // defined(CFG_linux) + + LOG(MOD_RAL|VERBOSE,"Connecting to device: %s", sx130xconf->device); +#if defined(CFG_smtcpico) + // Picocell needs some time to start up from reset before we can connect + sys_usleep(rt_millis(250)); + log_flushIO(); // lgw_connect might block - make sure log output is flushed + lgw_connect(sx130xconf->device); + sys_usleep(rt_millis(250)); + // Force a reset because MCU software may be in a weird state when we connect the first time +#endif + + if( log_shallLog(MOD_RAL|VERBOSE) ) { + LOG(MOD_RAL|DEBUG, "SX130x txlut table (%d entries)", sx130xconf->txlut.size); + for( int i=0; itxlut.size; i++ ) { +#if !defined(CFG_sx1302) + LOG(MOD_RAL|VERBOSE, + "SX1301 txlut %2d: dig_gain=%d pa_gain=%d dac_gain=%d mix_gain=%d rf_power=%d", i, + sx130xconf->txlut.lut[i].dig_gain, + sx130xconf->txlut.lut[i].pa_gain, + sx130xconf->txlut.lut[i].dac_gain, + sx130xconf->txlut.lut[i].mix_gain, + sx130xconf->txlut.lut[i].rf_power); +#else + LOG(MOD_RAL|VERBOSE, + "SX1302 txlut %2d: rf_power=%d pa_gain=%d pwr_idx=%d", i, + sx130xconf->txlut.lut[i].rf_power, + sx130xconf->txlut.lut[i].pa_gain, + sx130xconf->txlut.lut[i].pwr_idx); +#endif + + } +#if defined(CFG_sx1302) + LOG(MOD_RAL|VERBOSE, "SX1302 rssi_tcomp: coeff_a=%.03f coeff_b=%.03f coeff_c=%.03f coeff_d=%.03f coeff_e=%.03f\n", + sx130xconf->rfconf->rssi_tcomp.coeff_a, + sx130xconf->rfconf->rssi_tcomp.coeff_b, + sx130xconf->rfconf->rssi_tcomp.coeff_c, + sx130xconf->rfconf->rssi_tcomp.coeff_d, + sx130xconf->rfconf->rssi_tcomp.coeff_e); +#endif + for( int i=0; irfconf[i].enable, + sx130xconf->rfconf[i].freq_hz, + sx130xconf->rfconf[i].rssi_offset, + sx130xconf->rfconf[i].type, + sx130xconf->rfconf[i].tx_enable +#if !defined(CFG_sx1302) + , sx130xconf->rfconf[i].tx_notch_freq +#endif + ); + } + for( int i=0; iifconf[i].enable, + sx130xconf->ifconf[i].rf_chain, + sx130xconf->ifconf[i].freq_hz, + sx130xconf->ifconf[i].bandwidth, + sx130xconf->ifconf[i].datarate, + sx130xconf->ifconf[i].sync_word, sx130xconf->ifconf[i].sync_word_size); +#else + if(i == LGW_MULTI_NB){ + LOG(MOD_RAL|VERBOSE, + "SX1302 ifchain %2d: enable=%d rf_chain=%d freq=%d bw=%d SF=%d sync_word=%lX/%d [STD] %s", i, + sx130xconf->ifconf[i].enable, + sx130xconf->ifconf[i].rf_chain, + sx130xconf->ifconf[i].freq_hz, + sx130xconf->ifconf[i].bandwidth, + sx130xconf->ifconf[i].datarate, + sx130xconf->ifconf[i].sync_word, sx130xconf->ifconf[i].sync_word_size, + (sx130xconf->ifconf[i].implicit_hdr == true) ? "Implicit header" : "Explicit header"); + }else{ + LOG(MOD_RAL|VERBOSE, + "SX1302 ifchain %2d: enable=%d rf_chain=%d freq=%d bw=%d SF=%d sync_word=%lX/%d", i, + sx130xconf->ifconf[i].enable, + sx130xconf->ifconf[i].rf_chain, + sx130xconf->ifconf[i].freq_hz, + sx130xconf->ifconf[i].bandwidth, + sx130xconf->ifconf[i].datarate, + sx130xconf->ifconf[i].sync_word, sx130xconf->ifconf[i].sync_word_size); + } +#endif + } +#if !defined(CFG_sx1302) + if( sx130xconf->lbt.enable ) { + LOG(MOD_RAL|VERBOSE, "SX130x LBT enabled: rssi_target=%d rssi_offset=%d", + sx130xconf->lbt.rssi_target, sx130xconf->lbt.rssi_offset); + for( int i=0; i < sx130xconf->lbt.nb_channel; i++ ) { + LOG(MOD_RAL|VERBOSE, " %2d: freq=%F scan=%dus", + i, sx130xconf->lbt.channels[i].freq_hz, sx130xconf->lbt.channels[i].scan_time_us); + } + } else { + LOG(MOD_RAL|VERBOSE, "SX130x LBT not enabled"); + } +#endif + } + +#if defined(CFG_sx1302) + if( lgw_board_setconf(&sx130xconf->boardconf) != LGW_HAL_SUCCESS ) { +#else + if( lgw_board_setconf(sx130xconf->boardconf) != LGW_HAL_SUCCESS ) { +#endif + errmsg = "lgw_board_setconf"; + goto fail; + } + if( sx130xconf->txlut.size > 0) { +#if defined(CFG_sx1302) + if( lgw_txgain_setconf(0, &sx130xconf->txlut) != LGW_HAL_SUCCESS ) { +#else + if( lgw_txgain_setconf(&sx130xconf->txlut) != LGW_HAL_SUCCESS ) { +#endif + errmsg = "lgw_txgain_setconf"; + goto fail; + } + } + for( int i=0; irfconf[i]) != LGW_HAL_SUCCESS ) { +#else + if( lgw_rxrf_setconf(i, sx130xconf->rfconf[i]) != LGW_HAL_SUCCESS ) { +#endif + LOG(MOD_RAL|ERROR,"lgw_rxrf_setconf(%d) failed", i); + errmsg = "lgw_rxrf_setconf"; + goto fail; + } + } + for( int i=0; iifconf[i]) != LGW_HAL_SUCCESS ) { +#else + if( lgw_rxif_setconf(i, sx130xconf->ifconf[i]) != LGW_HAL_SUCCESS ) { +#endif + LOG(MOD_RAL|ERROR,"lgw_rxif_setconf(%d) failed", i); + errmsg = "lgw_rxif_setconf"; + goto fail; + } + } + + if( cca_region && !setup_LBT(sx130xconf, cca_region) ) { + errmsg = "setup_LBT"; + goto fail; + } + + LOG(MOD_RAL|VERBOSE, "Station device: %s (PPS capture %sabled)", sx130xconf->device, sx130xconf->pps ? "en":"dis"); + log_flushIO(); // flush output since lgw_start may block for quite some time on some concentrators +#if defined(CFG_sx1302) + (void) sys_deviceMode; // TODO: Add device mode to sx1302 hal +#else + lgwx_device_mode = sys_deviceMode; +#endif + ustime_t t0 = rt_getTime(); + int err = lgw_start(); + if( err != LGW_HAL_SUCCESS ) { + errmsg = "lgw_start"; + goto fail; + } +#if defined(CFG_sx1302) + if( sx1302_gps_enable(sx130xconf->pps ? 1 : 0) != LGW_REG_SUCCESS ) { +#else + if( lgw_reg_w(LGW_GPS_EN, sx130xconf->pps ? 1 : 0) != LGW_REG_SUCCESS ) { +#endif + errmsg = "LGW GPS Enable"; + goto fail; + } + LOG(MOD_RAL|VERBOSE, "Concentrator started (%~T)", rt_getTime()- t0); +#if defined(CFG_smtcpico) + { + // Avoid timing issues with picocell MCU firmware - re-adjusts time after first TX + // (see cmdUSB.cpp Sx1308.firsttx). Seems to have a bad influence on station tracking + // local MCU clock vs concentrator microsecond ticks. + // Send a dummy frame to get into a stable state. + struct lgw_pkt_tx_s pkt_tx; + memset(&pkt_tx, 0, sizeof(pkt_tx)); + pkt_tx.tx_mode = IMMEDIATE; + pkt_tx.preamble = 8; + pkt_tx.modulation = MOD_LORA; + pkt_tx.datarate = DR_LORA_SF7; + pkt_tx.bandwidth = BW_125KHZ; + pkt_tx.freq_hz = sx130xconf->rfconf[0].freq_hz; + pkt_tx.count_us = 0; + pkt_tx.rf_chain = 0; + pkt_tx.rf_power = (float)0.0; + pkt_tx.coderate = CR_LORA_4_5; + pkt_tx.invert_pol = true; + pkt_tx.no_crc = 1; + pkt_tx.no_header = false; + pkt_tx.size = 1; + pkt_tx.preamble = 8; + pkt_tx.payload[0] = 0xE0; // proprietary LoRaWAN frame + // NOTE: nocca not possible to implement with current libloragw API + int err = lgw_send(pkt_tx); + if( err != LGW_HAL_SUCCESS ) { + errmsg = "lgw_send"; + goto fail; + } + } +#endif // defined(CFG_smtcpico) + return 1; + fail: + LOG(MOD_RAL|ERROR, "Concentrator start failed: %s", errmsg); + return 0; +} + +#endif // defined(CFG_lgw1) diff --git a/src/sx130xconf.h b/src/sx130xconf.h new file mode 100644 index 0000000..a1491dc --- /dev/null +++ b/src/sx130xconf.h @@ -0,0 +1,70 @@ +/* + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _sx130xconf_h_ +#define _sx130xconf_h_ +#if defined(CFG_lgw1) + +#include // loragw_fpga.h refers to FILE +#include "lgw/loragw_hal.h" +#if !defined(CFG_sx1302) +#include "lgw/loragw_lbt.h" +#include "lgw/loragw_fpga.h" +#endif +#include "s2conf.h" +#include "ral.h" //chdefl_t + + +#define SX130X_ANT_NIL 0 +#define SX130X_ANT_OMNI 1 +#define SX130X_ANT_SECTOR 2 +#define SX130X_ANT_UNDEF 3 + +struct sx130xconf { + struct lgw_conf_board_s boardconf; + struct lgw_tx_gain_lut_s txlut; + struct lgw_conf_rxrf_s rfconf[LGW_RF_CHAIN_NB]; + struct lgw_conf_rxif_s ifconf[LGW_IF_CHAIN_NB]; +#if !defined(CFG_sx1302) + struct lgw_conf_lbt_s lbt; +#endif + s2_t txpowAdjust; // assuming there is only one TX path / SX130X (scaled by TXPOW_SCALE) + u1_t pps; // enable PPS latch of trigger count + u1_t antennaType; // type of antenna + char device[MAX_DEVICE_LEN]; // SPI device, FTDI spec etc. +}; + +extern str_t station_conf_USAGE; + +int sx130xconf_parse_setup (struct sx130xconf* sx130xconf, int slaveIdx, str_t hwspec, char* json, int jsonlen); +int sx130xconf_challoc (struct sx130xconf* sx130xconf, chdefl_t* upchs); +int sx130xconf_start (struct sx130xconf* sx130xconf, u4_t region); + + +#endif // defined(CFG_lgw1) +#endif // _sx130xconf_h_ diff --git a/src/sys.c b/src/sys.c index f1cc2d8..e8fe6ee 100644 --- a/src/sys.c +++ b/src/sys.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -467,10 +466,10 @@ int sys_cred (int cred_cat, int cred_set, str_t* elems, int* elemslen) { } -u4_t sys_crcCred (int cred_cat) { +u4_t sys_crcCred (int cred_cat, int cred_set) { u4_t crc = 0; for( int ext=FN_TRUST; ext < FN_URI; ext++ ) { - dbuf_t data = readFile(configFilename(cred_cat, FN_REG, ext), 0); + dbuf_t data = readFile(configFilename(cred_cat, cred_set, ext), 0); if( data.buf && data.bufsize != 0 ) crc = rt_crc32(crc, data.buf, data.bufsize); else @@ -561,7 +560,7 @@ void sys_credComplete (int cred_cat, int len) { } if (ko > len) { - LOG(MOD_SYS|ERROR, "Failed to parse %s credentials: expecting more data", categoryName(cred_cat)); + LOG(MOD_SYS|ERROR, "Failed to parse %s credentials: expecting more data (key_offset=%d, total_len=%d)", categoryName(cred_cat), ko, len); goto parsing_failed; } diff --git a/src/sys.h b/src/sys.h index 5ae6521..e705ea8 100644 --- a/src/sys.h +++ b/src/sys.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _sys_h_ @@ -86,7 +85,7 @@ void sys_backupConfig (int cred_cat); str_t sys_version (); str_t sys_uri (int cred_cat, int cred_set); void sys_saveUri (int cred_cat, str_t uri); -u4_t sys_crcCred (int cred_cat); +u4_t sys_crcCred (int cred_cat, int cred_set); void sys_runUpdate (); void sys_abortUpdate (); @@ -96,23 +95,25 @@ int sys_execCommand (ustime_t max_wait, str_t* argv); dbuf_t sys_sigKey (int key_id); u4_t sys_crcSigkey (int key_id); -dbuf_t sys_readFile (str_t filename); // should this be here? - only used in sx1301conf.c +dbuf_t sys_readFile (str_t filename); // should this be here? - only used in sx130xconf.c str_t sys_makeFilepath (str_t fn, int complain); void sys_iniTC (); -void sys_stopTC(); -void sys_startTC(); -s1_t sys_statusTC(); +void sys_stopTC (); +void sys_startTC (); +s1_t sys_statusTC (); -void sys_iniCUPS(); -void sys_triggerCUPS(int delay); -void sys_clearCUPS(); -void sys_delayCUPS(); -s1_t sys_statusCUPS(); +void sys_iniCUPS (); +void sys_triggerCUPS (int delay); +void sys_clearCUPS (); +void sys_delayCUPS (); +s1_t sys_statusCUPS (); -void sys_iniWeb(); -void sys_stopWeb(); +void sys_iniWeb (); +void sys_stopWeb (); -void sys_keepAlive(int fd); +void sys_keepAlive (int fd); + +int sys_getLatLon (double* lat, double* lon); #endif // _sys_h_ diff --git a/src/tc.c b/src/tc.c index 63e52cb..5d1d944 100644 --- a/src/tc.c +++ b/src/tc.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "s2conf.h" @@ -123,7 +122,7 @@ static void tc_connect_muxs (tc_t* tc) { char* path = &u[(u1_t)u[2]]; ws_ini(&tc->ws, TC_RECV_BUFFER_SIZE, TC_SEND_BUFFER_SIZE); - if( tlsmode == URI_TLS && !conn_setup_tls(&tc->ws, SYS_CRED_TC, SYS_CRED_REG) ) { + if( tlsmode == URI_TLS && !conn_setup_tls(&tc->ws, SYS_CRED_TC, SYS_CRED_REG, hostname) ) { goto errexit; } if( !ws_connect(&tc->ws, hostname, port, path) ) { @@ -303,12 +302,12 @@ void tc_free (tc_t* tc) { void tc_start (tc_t* tc) { assert(tc->tstate == TC_INI); + int tstate_err = TC_ERR_NOURI; str_t tcuri = sys_uri(SYS_CRED_TC, tc->credset); if( tcuri == NULL ) { LOG(MOD_TCE|ERROR, "No TC URI configured"); - tc_done(tc, TC_ERR_NOURI); - return; + goto errexit; } // Use a WS buffer as temp place for host/port strings // Gets destroyed while ramping up connection @@ -319,9 +318,10 @@ void tc_start (tc_t* tc) { LOG(MOD_TCE|ERROR,"Bad TC URI: %s", tc); goto errexit; } - if( ok == URI_TLS && !conn_setup_tls(&tc->ws, SYS_CRED_TC, tc->credset) ) { + if( ok == URI_TLS && !conn_setup_tls(&tc->ws, SYS_CRED_TC, tc->credset, hostname) ) { goto errexit; } + tstate_err = TC_ERR_FAILED; if( !ws_connect(&tc->ws, hostname, port, "/router-info") ) { LOG(MOD_TCE|ERROR, "TC connect failed - URI: %s", tcuri); goto errexit; @@ -331,9 +331,8 @@ void tc_start (tc_t* tc) { tc->tstate = TC_INFOS_REQ_PEND; LOG(MOD_TCE|INFO, "Connecting to INFOS: %s", tcuri); return; - errexit: - tc_done(tc, TC_ERR_FAILED); + tc_done(tc, tstate_err); return; } @@ -341,10 +340,10 @@ void tc_start (tc_t* tc) { void tc_continue (tc_t* tc) { s1_t tstate = tc->tstate; - if( (tc->tstate == TC_ERR_REJECTED || tc->retries >= 10) && !sys_noCUPS ) { - LOG(MOD_TCE|INFO, "Router rejected or retry limit reached. Invoking CUPS in 30 seconds."); + if( (tstate == TC_ERR_REJECTED || tstate == TC_ERR_NOURI || tc->retries >= 10) && !sys_noCUPS ) { + LOG(MOD_TCE|INFO, "Router rejected or retry limit reached. Invoking CUPS."); sys_stopTC(); - sys_triggerCUPS(30); + sys_triggerCUPS(-1); return; } diff --git a/src/tc.h b/src/tc.h index cef83f7..f65d179 100644 --- a/src/tc.h +++ b/src/tc.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _tc_h_ diff --git a/src/timesync.c b/src/timesync.c index ba20dd6..0000216 100644 --- a/src/timesync.c +++ b/src/timesync.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -34,6 +33,11 @@ #include "timesync.h" #include "ral.h" +#if defined(CFG_smtcpico) +#define _MAX_DT 300 +#else +#define _MAX_DT 100 +#endif #define SYNC_QUAL_GOOD 100 // values considered good #define SYNC_QUAL_THRES 90 // cut off quantile - for sync quality @@ -45,14 +49,15 @@ #define PPM ((sL_t)1000000) // 1sec in micros #define iPPM_SCALE 10 // keep drifts in deci ppm as ints #define fPPM_SCALE 10.0 // -double- -#define MIN_MCU_DRIFT_THRES 2*iPPM_SCALE // deviation in deci ppm -#define MAX_MCU_DRIFT_THRES 100*iPPM_SCALE // deviation in deci ppm +#define MIN_MCU_DRIFT_THRES 2*iPPM_SCALE // deviation in deci ppm +#define MAX_MCU_DRIFT_THRES _MAX_DT*iPPM_SCALE // deviation in deci ppm #define MAX_PPS_ERROR 1000 // deviation in micros #define MAX_PPS_OFFSET_CHANGE 50 // update if more than this #define NO_PPS_ALARM_INI 10 // seconds #define NO_PPS_ALARM_RATE 2.0 // growth rate alarm threshold #define NO_PPS_ALARM_MAX 3600 // seconds #define XTICKS_DECAY 100000 // max age of xticks from FIFO (us) +#define UTC_GPS_EPOCH_US 315964800 // UTC epoch expressed in s since GPS epoch #define ustimeRoundSecs(x) (((x) + PPM/2) / PPM * PPM) #define ustime2xtime(sync, _ustime) ((sync)->xtime + ((_ustime)-(sync)->ustime)) @@ -100,12 +105,21 @@ static void timesyncReport (int force) { if( !force && now < lastReport + TIMESYNC_REPORTS ) return; lastReport = now; + uL_t pps_ustime = xtime2ustime(×yncs[0], ppsSync.pps_xtime); LOG(MOD_SYN|INFO, "Time sync: ustime=0x%lX utc=0x%lX gpsOffset=0x%lX ppsOffset=%ld syncQual=%d\n", - now, rt_ustime2utc(now), gpsOffset, ppsOffset, syncQual); - LOG(MOD_SYN|INFO, "Time sync: MCU/SX1301#0 ustime=0x%lX xtime=0x%lX pps_xtime=0x%lX", + now, rt_ustime2utc(now), gpsOffset, ppsOffset, syncQual[0]); + LOG(MOD_SYN|INFO, "Time sync: MCU/SX130X#0 ustime=0x%lX xtime=0x%lX pps_xtime=0x%lX", timesyncs[0].ustime, timesyncs[0].xtime, timesyncs[0].pps_xtime); - LOG(MOD_SYN|INFO, "Time sync: Last PPS ustime=0x%lX xtime=0x%lX pps_xtime=0x%lX", - ppsSync.ustime, ppsSync.xtime, ppsSync.pps_xtime); + if( !ppsOffset ) + return; + LOG(MOD_SYN|INFO, "Time sync: Last PPS ustime=0x%lX xtime=0x%lX pps_ustime=0x%lX pps_xtime=0x%lX", + ppsSync.ustime, ppsSync.xtime, pps_ustime, ppsSync.pps_xtime); + if( !gpsOffset ) + return; + LOG(MOD_SYN|INFO, "Time ref: Last PPS sys->UTC=%>.6T SX130X->GPS=%>.6T leaps=%02lus diff=%~T", + rt_ustime2utc(pps_ustime), ts_xtime2gpstime(ppsSync.pps_xtime) + UTC_GPS_EPOCH_US*PPM, + (ts_xtime2gpstime(ppsSync.pps_xtime) + UTC_GPS_EPOCH_US*PPM - rt_ustime2utc(pps_ustime) + PPM/2)/PPM, + (ts_xtime2gpstime(ppsSync.pps_xtime) + UTC_GPS_EPOCH_US*PPM - rt_ustime2utc(pps_ustime) + PPM/2)%PPM - PPM/2 ); } @@ -113,8 +127,12 @@ static int encodeDriftPPM (double drift) { return (int)round((drift - 1.0) * PPM * iPPM_SCALE); } -static double decodeDriftPPM (double drift) { - return 1.0 + drift / (PPM * fPPM_SCALE); +static double decodeDriftPPM (double scaled_ppm) { + return 1.0 + scaled_ppm / (PPM * fPPM_SCALE); +} + +static double decodePPM (double scaled_ppm) { + return scaled_ppm / fPPM_SCALE; } static int cmp_abs_int (const void* a, const void* b) { @@ -137,7 +155,7 @@ static int drift_stats (int* drifts, struct quants *q, int thresQ, int* auxQ) { static int log_drift_stats (str_t msg, int* drifts, int thresQ, int* auxQ) { struct quants q; int thres = drift_stats(drifts, &q, thresQ, auxQ); - LOG(MOD_SYN|INFO, "%s: min: %.1fppm q50: %.1fppm q80: %.1fppm max: %.1fppm - threshold q%d: %.1fppm", + LOG(MOD_SYN|INFO, "%s: min: %+4.1fppm q50: %+4.1fppm q80: %+4.1fppm max: %+4.1fppm - threshold q%d: %+4.1fppm", msg, q.qmin / fPPM_SCALE, q.q50 / fPPM_SCALE, q.q80 / fPPM_SCALE, q.qmax / fPPM_SCALE, thresQ, thres / fPPM_SCALE); @@ -178,7 +196,7 @@ ustime_t ts_updateTimesync (u1_t txunit, int quality, const timesync_t* curr) { ustime_t dus = curr->ustime - last->ustime; sL_t dxc = curr->xtime - last->xtime; if( dxc <= 0 ) { - LOG(MOD_SYN|ERROR, "SX1301#%d trigger count not ticking or weird value: 0x%lX .. 0x%lX (dxc=%d)", + LOG(MOD_SYN|ERROR, "SX130X#%d trigger count not ticking or weird value: 0x%lX .. 0x%lX (dxc=%d)", txunit, last->xtime, curr->xtime, dxc); return TIMESYNC_RADIO_INTV; } @@ -196,14 +214,19 @@ ustime_t ts_updateTimesync (u1_t txunit, int quality, const timesync_t* curr) { - int thres = log_drift_stats("MCU/SX1301 drift stats", stats->mcu_drifts, MCU_DRIFT_THRES, NULL); + int thres = log_drift_stats("MCU/SX130X drift stats", stats->mcu_drifts, MCU_DRIFT_THRES, NULL); stats->drift_thres = max(MIN_MCU_DRIFT_THRES, min(MAX_MCU_DRIFT_THRES, abs(thres))); - LOG(MOD_SYN|INFO, "Avg MCU drift vs SX1301#0: %.1fppm", decodeDriftPPM((double)sum_mcu_drifts / N_DRIFTS)); + double mean_ppm = decodePPM( ((double)sum_mcu_drifts) / N_DRIFTS); + LOG(MOD_SYN|INFO, "Mean MCU drift vs SX130X#0: %.1fppm", mean_ppm); + if( rt_utcOffset_ts != 0 && !ppsSync.pps_xtime) { + rt_utcOffset -= (curr->ustime - rt_utcOffset_ts) * mean_ppm/PPM; + rt_utcOffset_ts = curr->ustime; + } } if( abs(drift_ppm) > stats->drift_thres ) { stats->excessive_drift_cnt += 1; if( (stats->excessive_drift_cnt % QUICK_RETRIES) == 0 ) { - LOG(MOD_SYN|ERROR, "Repeated excessive clock drifts between MCU/SX1301#%d (%d retries): %.1fppm (threshold %.1fppm)", + LOG(MOD_SYN|ERROR, "Repeated excessive clock drifts between MCU/SX130X#%d (%d retries): %.1fppm (threshold %.1fppm)", txunit, stats->excessive_drift_cnt, drift_ppm/fPPM_SCALE, stats->drift_thres/fPPM_SCALE); } if( stats->excessive_drift_cnt >= 2*QUICK_RETRIES ) @@ -228,7 +251,7 @@ ustime_t ts_updateTimesync (u1_t txunit, int quality, const timesync_t* curr) { } } // We update ppsSync only if we have two consecutive time syncs with valid PPS timestamps - // and if they are apart ~1s - we might be weird values if no PPS pulse occured during time sync span. + // and if they are apart ~1s - we might be weird values if no PPS pulse occurred during time sync span. if( !last->pps_xtime || !curr->pps_xtime ) goto done; if( curr->xtime - curr->pps_xtime > PPM+TX_MIN_GAP ) @@ -247,7 +270,7 @@ ustime_t ts_updateTimesync (u1_t txunit, int quality, const timesync_t* curr) { pps_drifts[pps_drifts_widx] = encodeDriftPPM(pps_drift); pps_drifts_widx = (pps_drifts_widx + 1) % N_DRIFTS; if( pps_drifts_widx == 0 ) - pps_drifts_thres = log_drift_stats("PPS/SX1301 drift stats", pps_drifts, PPS_DRIFT_THRES, NULL); + pps_drifts_thres = log_drift_stats("PPS/SX130X drift stats", pps_drifts, PPS_DRIFT_THRES, NULL); ustime_t pps_ustime = xtime2ustime(curr, curr->pps_xtime); ustime_t off = pps_ustime % PPM; @@ -260,10 +283,13 @@ ustime_t ts_updateTimesync (u1_t txunit, int quality, const timesync_t* curr) { } else if( abs(ppsOffset-off) > (stats->drift_thres * TIMESYNC_RADIO_INTV)/PPM ) { LOG(MOD_SYN|INFO, "Changed PPS offset: %ld => %ld (delta: %ld)", ppsOffset, off, off-ppsOffset); + // Adjust ppsOffset to accout for MCU/PPS drift ppsOffset = off; } + // Correct the fractional second of the UTC reference by ppsOffset (expects s-precision UTC time reference) + rt_utcOffset = rt_utcOffset - rt_utcOffset%PPM + (PPM-ppsOffset); // Shift timesync into the middle of two PPS pulses - // Avoid turning off PPS latching during SX1301 sync procedure near the PPS. + // Avoid turning off PPS latching during SX130X sync procedure near the PPS. // We might miss a PPS pulse and a scheduled frame might not be sent. // Also wobble the sync time a bir otherwise we might track the value when enabling PPS latching // as PPS. This happens with a rate resembling 1Hz @@ -284,7 +310,7 @@ ustime_t ts_updateTimesync (u1_t txunit, int quality, const timesync_t* curr) { sL_t ts_gpstime2xtime (u1_t txunit, sL_t gpstime) { if( txunit >= MAX_TXUNITS || !timesyncs[txunit].xtime || !ppsSync.pps_xtime || ppsOffset < 0 || !gpsOffset ) { LOG(MOD_SYN|ERROR, "Cannot convert GPS time - missing %s time sync", - !timesyncs[txunit].xtime ? "SX1301" + !timesyncs[txunit].xtime ? "SX130X" : !ppsSync.pps_xtime || ppsOffset ? "PPS" : !gpsOffset ? "GPS" : "?"); return 0; @@ -325,7 +351,7 @@ sL_t ts_ustime2xtime (u1_t txunit, ustime_t ustime) { ustime_t ts_xtime2ustime (sL_t xtime) { int txunit = ral_xtime2txunit(xtime); if( txunit >= MAX_TXUNITS || timesyncs[txunit].xtime == 0 ) { - LOG(MOD_SYN|ERROR, "Cannot convert xtime=0x%lX - missing SX1301#%d time sync", + LOG(MOD_SYN|ERROR, "Cannot convert xtime=0x%lX - missing SX130X#%d time sync", timesyncs[txunit].xtime, txunit); return 0; } @@ -355,18 +381,18 @@ sL_t ts_xtime2xtime (sL_t xtime, u1_t dst_txunit) { } -// Convert a 32bit SX1301 tick counter into a xtime reported back to the LNS +// Convert a 32bit SX130X tick counter into a xtime reported back to the LNS // This can only be called in a process with access to libloragw (aka not ral_master) sL_t ts_xticks2xtime (u4_t xticks, sL_t last_xtime) { // Time sync should be frequent so that we should never see a roll over // from positive to negative (takes 2^31us ~ 35min) // However, we might see small negative numbers because time sync might - // be slightly younger than time stamps of frames being stuck in the SX1301 fifo. + // be slightly younger than time stamps of frames being stuck in the SX130X fifo. // sL_t d; if( (d = (s4_t)(xticks - last_xtime)) < -XTICKS_DECAY ) { LOG(MOD_SYN|CRITICAL, - "SX1301 RX time roll over - no update for a long time: xticks=0x%X last_xtime=0x%lX", + "SX130X RX time roll over - no update for a long time: xticks=0x%X last_xtime=0x%lX", xticks, last_xtime); return 0; } @@ -375,8 +401,8 @@ sL_t ts_xticks2xtime (u4_t xticks, sL_t last_xtime) { sL_t ts_newXtimeSession (u1_t txunit) { - // This disambiguates SX1301 timestamps - // If we have a new session (currently reconnect to TC) the SX1301 counter restarts + // This disambiguates SX130X timestamps + // If we have a new session (currently reconnect to TC) the SX130X counter restarts // Old timestamps coming in from TC with timestamps before the restart must be rejetced. sL_t ext = ((sL_t)rand() & RAL_XTSESS_MASK) << RAL_XTSESS_SHIFT; if( !ext ) ext = (sL_t)1<= 2*PPM || gpsOffset ) return; // need ppsOffset || roundtrip too long || we already have a solution @@ -511,7 +538,6 @@ void ts_processTimesyncLns (ustime_t txtime, ustime_t rxtime, sL_t gpstime) { gpsOffset = gps_s - delta; LOG(MOD_SYN|INFO, "Timesync with LNS: gpsOffset=0x%lX", gpsOffset); timesyncReport(1); - } // -------------------------------------------------------------------------------- diff --git a/src/timesync.h b/src/timesync.h index 1075898..f519af0 100644 --- a/src/timesync.h +++ b/src/timesync.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _timesync_h_ diff --git a/src/tls.c b/src/tls.c index 21c4129..69c57db 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "mbedtls/net_sockets.h" @@ -35,6 +34,7 @@ #include "mbedtls/error.h" #include "mbedtls/debug.h" +#include "s2conf.h" #include "sys.h" #include "rt.h" #include "uj.h" @@ -178,7 +178,7 @@ static int _readCAs (mbedtls_x509_crt** pcas, const char* cafile, int len, const if( len <= 0 ) { dbuf_t dbuf = sys_readFile(cafile); if( dbuf.buf == NULL ) { - LOG(MOD_AIO|ERROR, "Reading %s from '%s", what, cafile); + LOG(MOD_AIO|ERROR, "Reading %s from '%s' failed", what, cafile); goto errexit; } certb = (u1_t*)dbuf.buf; @@ -193,7 +193,7 @@ static int _readCAs (mbedtls_x509_crt** pcas, const char* cafile, int len, const if( len <= 0 ) { // Reuse buffer to print cert info before freeing mbedtls_x509_crt_info( (char*)certb, certl, "", cas ); - LOG(INFO,"%s",certb); + LOG(INFO,"%s: \n%s", cafile, certb); rt_free(certb); } @@ -273,7 +273,7 @@ tlsctx_p tls_makeSession (tlsconf_t* conf, const char* servername) { rt_free(sslctx); return NULL; } - if( servername ) { + if( servername && TLS_SNI ) { if( (ret = mbedtls_ssl_set_hostname(sslctx, servername)) != 0 ) { log_mbedError(ERROR, ret, "mbedtls_ssl_set_hostname"); goto fail; diff --git a/src/tls.h b/src/tls.h index 2600a8a..9c738ea 100644 --- a/src/tls.h +++ b/src/tls.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _tls_h_ diff --git a/src/uj.c b/src/uj.c index afaefce..4697eb5 100644 --- a/src/uj.c +++ b/src/uj.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include @@ -126,6 +125,23 @@ static void parseString (ujdec_t* dec) { uj_error(dec, "Malformed \\u escape sequence"); // NOT REACHED } + if( c >= (1<<7) ) { + char cu[2]; + int ci; + if( c < (1<<11) ) { // 2^7 <= c < 2^11 ==> 5+6 bits + ci = 1; + cu[1] = 0xC0 | (c>>6); // encode 5 bits + } else { // 2^11 <= c < 2^16 ==> 4+6+6 bits + ci = 0; + cu[0] = 0xE0 | (c>>12); // encode 4 bits + cu[1] = 0x80 | ((c>>6)&0x3F); // 6 bits + } + for(; ci < 2; ci++ ) { + if( wp ) *wp++ = cu[ci]; + crc = UJ_UPDATE_CRC(crc,cu[ci]); + } + c = 0x80|(c&0x3F); // encode 6 bits + } break; } default: @@ -785,7 +801,7 @@ void uj_encStr (ujbuf_t* b, const char* s) { case '\r': c = 'r'; break; case '\t': c = 't'; break; default: - if( c < 0x20 ) { + if( c >=0 && c < 0x20 ) { addChar(b,'\\'); addChar(b,'u'); addHex2(b,0); diff --git a/src/uj.h b/src/uj.h index fe7aade..e97efa7 100644 --- a/src/uj.h +++ b/src/uj.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _uj_h_ diff --git a/src/web.c b/src/web.c index 0f0d42d..0f52067 100644 --- a/src/web.c +++ b/src/web.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "s2conf.h" diff --git a/src/web.h b/src/web.h index 35088cf..37a7466 100644 --- a/src/web.h +++ b/src/web.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _web_h_ diff --git a/src/ws.h b/src/ws.h index fb809a7..2f63ffe 100644 --- a/src/ws.h +++ b/src/ws.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _ws_h_ diff --git a/src/xq.c b/src/xq.c index b2f9585..04aa421 100644 --- a/src/xq.c +++ b/src/xq.c @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "xq.h" @@ -211,6 +210,7 @@ rxjob_t* rxq_nextJob (rxq_t* rxq) { if( first==next ) { rxq->first = rxq->next = 0; jobs[0].off = jobs[0].len = 0; + jobs[0].fts = -1; return &jobs[0]; } if( next >= MAX_RXJOBS ) { @@ -243,6 +243,7 @@ rxjob_t* rxq_nextJob (rxq_t* rxq) { last += 1; last->off = end; last->len = 0; + last->fts = -1; return last; } diff --git a/src/xq.h b/src/xq.h index 5b3a1be..c218fb8 100644 --- a/src/xq.h +++ b/src/xq.h @@ -1,30 +1,29 @@ /* - * --- Revised 3-Clause BSD License --- - * Copyright (C) 2016-2019, SEMTECH (International) AG. - * All rights reserved. + * --- Revised 3-Clause BSD License --- + * Copyright Semtech Corporation 2020. All rights reserved. * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION. BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _xq_h_ @@ -64,6 +63,8 @@ typedef struct txjob { u1_t prio; // priority u1_t dnchnl; // channel number (internal use only - for DC tracking) u1_t dnchnl2; // -ditto- RX2 + u1_t addcrc; // add CRC to Lora DN frame + u2_t preamble; // preamble length - if zero use default } txjob_t; typedef struct txq { @@ -94,10 +95,11 @@ typedef u1_t rxidx_t; typedef struct rxjob { sL_t rctx; sL_t xtime; + s4_t fts; u4_t freq; rxoff_t off; // frame start in rxdata u1_t rssi; // scaled RSSI (*-1) - s1_t snr; // scaled SNR (*8) + s1_t snr; // scaled SNR (*4) u1_t dr; u1_t len; // frame end } rxjob_t;