Skip to content

Commit

Permalink
lorawan_lbm: Add LoRa Basics Modem LoRaWAN stack
Browse files Browse the repository at this point in the history
This stack is based on the lora_basics_modem external module.

It provides configuration for LBM as well as a standalone
"main" LBM thread that needs to be manually started.

Signed-off-by: Félix Piédallu <[email protected]>
  • Loading branch information
Salamandar committed Aug 27, 2024
1 parent 907df2c commit f129e6c
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/zephyr/lorawan_lbm/lbm_main_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extern "C" {
* @param hal_cb User provided callbacks for Device Management
*/

void lora_basics_modem_start_work_thread(
void (*event_callback)(void), struct smtc_modem_hal_cb *hal_cb);
void lora_basics_modem_start_work_thread(void (*event_callback)(void),
struct smtc_modem_hal_cb *hal_cb);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ add_subdirectory_ifdef(CONFIG_IMG_MANAGER dfu)
add_subdirectory_ifdef(CONFIG_INPUT input)
add_subdirectory_ifdef(CONFIG_JWT jwt)
add_subdirectory_ifdef(CONFIG_LLEXT llext)
add_subdirectory_ifdef(CONFIG_LORA_BASICS_MODEM lorawan_lbm)
add_subdirectory_ifdef(CONFIG_MODEM_MODULES modem)
add_subdirectory_ifdef(CONFIG_NET_BUF net)
add_subdirectory_ifdef(CONFIG_RETENTION retention)
Expand Down
1 change: 1 addition & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ source "subsys/jwt/Kconfig"
source "subsys/llext/Kconfig"
source "subsys/logging/Kconfig"
source "subsys/lorawan/Kconfig"
source "subsys/lorawan_lbm/Kconfig"
source "subsys/mem_mgmt/Kconfig"
source "subsys/mgmt/Kconfig"
source "subsys/modbus/Kconfig"
Expand Down
15 changes: 15 additions & 0 deletions subsys/lorawan_lbm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2024 Semtech Corporation
# SPDX-License-Identifier: Apache-2.0


if(CONFIG_LORA_BASICS_MODEM)

zephyr_library()

if(CONFIG_LORA_BASICS_MODEM_MAIN_THREAD)
zephyr_library_sources(
${CMAKE_CURRENT_LIST_DIR}/lbm_main_thread.c
)
endif()

endif()
341 changes: 341 additions & 0 deletions subsys/lorawan_lbm/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
# LoRaWAN configuration options

# Copyright (c) 2024 Semtech Corporation
# SPDX-License-Identifier: Apache-2.0

config LORA_BASICS_MODEM_USER_STORAGE_IMPL
bool "Use a user-provided LoRa Basics Modem storage implementation"
default n
help
Enable if user storage implementation is required.
This disables the default storage implementation in the HAL
that uses the settings subsystem.

menuconfig LORA_BASICS_MODEM
bool "LoRa Basics Modem LoRaWAN stack support [EXPERIMENTAL]"
depends on EXPERIMENTAL
depends on LORA_BASICS_MODEM_DRIVERS
depends on LORA_BASICS_MODEM_DRIVERS_RAL_RALF
depends on REBOOT
# depends on REQUIRES_FULL_LIBC
depends on SETTINGS || LORA_BASICS_MODEM_USER_STORAGE_IMPL
depends on TEST_RANDOM_GENERATOR || ENTROPY_HAS_DRIVER
select ZEPHYR_LORA_BASICS_MODEM_MODULE
depends on !LORAWAN
help
This option enables the LoRa Basics Modem stack for LoRaWAN support.
Full libc is required for floorf.
Also make sure some source of randomness is used.

if LORA_BASICS_MODEM

module = LORA_BASICS_MODEM
module-str = LoRa Basics Modem
source "subsys/logging/Kconfig.template.log_config"

config LORA_BASICS_MODEM_LOG_LEVEL_DEEP_DBG
bool "Deep debug log level (requires LOG_LEVEL_DBG=y)"
help
An even more verbose log level than debug

# Taken from `make help` output and options.mk

#-----------------------------------------------------------------------------
# Internal LBM features management
#-----------------------------------------------------------------------------

choice
prompt "LoRaWAN Regional Parameters version"
default LORA_BASICS_MODEM_RP2_103
help
Specify which Regional Parameters version to use

config LORA_BASICS_MODEM_RP2_101
bool "Use RP 1.0.1"

config LORA_BASICS_MODEM_RP2_103
bool "Use RP 1.0.3"

endchoice

config LORA_BASICS_MODEM_ENABLE_ALL_REGIONS
bool "Support for all supported regions"
default y
select LORA_BASICS_MODEM_REGION_AS_923
select LORA_BASICS_MODEM_REGION_AU_915
select LORA_BASICS_MODEM_REGION_CN_470
select LORA_BASICS_MODEM_REGION_CN_470_RP_1_0
select LORA_BASICS_MODEM_REGION_EU_868
select LORA_BASICS_MODEM_REGION_IN_865
select LORA_BASICS_MODEM_REGION_KR_920
select LORA_BASICS_MODEM_REGION_RU_864
select LORA_BASICS_MODEM_REGION_US_915
select LORA_BASICS_MODEM_REGION_WW_2G4

config LORA_BASICS_MODEM_REGION_AS_923
bool "Support for AS_923 region"

config LORA_BASICS_MODEM_REGION_AU_915
bool "Support for AU_915 region"

config LORA_BASICS_MODEM_REGION_CN_470
bool "Support for CN_470 region"

config LORA_BASICS_MODEM_REGION_CN_470_RP_1_0
bool "Support for CN_470_RP_1_0 region"

config LORA_BASICS_MODEM_REGION_EU_868
bool "Support for EU_868 region"

config LORA_BASICS_MODEM_REGION_IN_865
bool "Support for IN_865 region"

config LORA_BASICS_MODEM_REGION_KR_920
bool "Support for KR_920 region"

config LORA_BASICS_MODEM_REGION_RU_864
bool "Support for RU_864 region"

config LORA_BASICS_MODEM_REGION_US_915
bool "Support for US_915 region"

config LORA_BASICS_MODEM_REGION_WW_2G4
bool "Support for WW_2G4 region"


choice
prompt "Cryptography engine"
default LORA_BASICS_MODEM_CRYPTOGRAPHY_SOFT
help
Specify which crypto engine will be used

config LORA_BASICS_MODEM_CRYPTOGRAPHY_SOFT
bool "Use software based cryptography module"

config LORA_BASICS_MODEM_CRYPTOGRAPHY_LR11XX
bool "Use lr11xx hardware cryptography module"
depends on DT_HAS_SEMTECH_LR1110_ENABLED || DT_HAS_SEMTECH_LR1120_ENABLED

config LORA_BASICS_MODEM_CRYPTOGRAPHY_LR11XX_WITH_CREDENTIALS
bool "Use lr11xx hardware cryptography module with its embedded credentials"
depends on DT_HAS_SEMTECH_LR1110_ENABLED || DT_HAS_SEMTECH_LR1120_ENABLED

endchoice

#-----------------------------------------------------------------------------
# LoRaWAN Stack related options
#-----------------------------------------------------------------------------

config LORA_BASICS_MODEM_CLASS_B
bool "Class B support"
default n

config LORA_BASICS_MODEM_CLASS_C
bool "Class C support"
default n

config LORA_BASICS_MODEM_MULTICAST
bool "Multicast support"
default n
depends on LORA_BASICS_MODEM_CLASS_B || LORA_BASICS_MODEM_CLASS_C

config LORA_BASICS_MODEM_CSMA
bool "CSMA support"
default y
depends on SEMTECH_LR11XX || SEMTECH_SX126X

config LORA_BASICS_MODEM_CSMA_BY_DEFAULT
bool "CSMA at startup"
default n
depends on LORA_BASICS_MODEM_CSMA

#-----------------------------------------------------------------------------
# LoRaWAN Package related options
#-----------------------------------------------------------------------------

config LORA_BASICS_MODEM_ALC_SYNC
bool "ALCSync service"
default n

choice
prompt "ALCSync service version to be used"
depends on LORA_BASICS_MODEM_ALC_SYNC
default LORA_BASICS_MODEM_ALC_SYNC_V1 if LORA_BASICS_MODEM_FUOTA_V1
default LORA_BASICS_MODEM_ALC_SYNC_V2 if LORA_BASICS_MODEM_FUOTA_V2
config LORA_BASICS_MODEM_ALC_SYNC_V1
bool "1"
config LORA_BASICS_MODEM_ALC_SYNC_V2
bool "2"
endchoice

config LORA_BASICS_MODEM_ALC_SYNC_VERSION
int
default 1 if LORA_BASICS_MODEM_ALC_SYNC_V1
default 2 if LORA_BASICS_MODEM_ALC_SYNC_V2


config LORA_BASICS_MODEM_FUOTA
bool "LoRaWan services for Firmware Upgrade Over The Air (FUOTA)"
default n
select LORA_BASICS_MODEM_CLASS_B
select LORA_BASICS_MODEM_CLASS_C
select LORA_BASICS_MODEM_MULTICAST
select LORA_BASICS_MODEM_ALC_SYNC

# FIXME: maybe use 0 as not-configured value?
config LORA_BASICS_MODEM_FUOTA_MAX_NB_OF_FRAGMENTS_CONFIG
bool "Allow configuration of the maximum number of fragments for LBM FUOTA"
default n

config LORA_BASICS_MODEM_FUOTA_MAX_NB_OF_FRAGMENTS
int "The maximum number of fragments for LBM FUOTA"
depends on LORA_BASICS_MODEM_FUOTA_MAX_NB_OF_FRAGMENTS_CONFIG

config LORA_BASICS_MODEM_FUOTA_MAX_SIZE_OF_FRAGMENTS_CONFIG
bool "Allow configuration of the maximum fragments size for LBM FUOTA"
default n

config LORA_BASICS_MODEM_FUOTA_MAX_SIZE_OF_FRAGMENTS
int "The maximum fragments size for LBM FUOTA"
depends on LORA_BASICS_MODEM_FUOTA_MAX_SIZE_OF_FRAGMENTS_CONFIG

config LORA_BASICS_MODEM_FUOTA_MAX_FRAGMENTS_REDUNDANCY_CONFIG
bool "Allow configuration of the maximum fragments redundancy for LBM FUOTA"
default n

config LORA_BASICS_MODEM_FUOTA_MAX_FRAGMENTS_REDUNDANCY
int "The maximum fragments redundancy for LBM FUOTA"
depends on LORA_BASICS_MODEM_FUOTA_MAX_FRAGMENTS_REDUNDANCY_CONFIG


choice
prompt "LoRaWan services for Firmware Upgrade Over The Air (FUOTA) version to use"
depends on LORA_BASICS_MODEM_FUOTA
config LORA_BASICS_MODEM_FUOTA_V1
bool "1"
config LORA_BASICS_MODEM_FUOTA_V2
bool "2"
endchoice

config LORA_BASICS_MODEM_FUOTA_VERSION
int
default 1 if LORA_BASICS_MODEM_FUOTA_V1
default 2 if LORA_BASICS_MODEM_FUOTA_V2


config LORA_BASICS_MODEM_FUOTA_FMP
bool "LoRaWAN FUOTA Firmware Management Package support"
depends on LORA_BASICS_MODEM_FUOTA
default y

config LORA_BASICS_MODEM_FUOTA_MPA
bool "LoRaWAN FUOTA Multi-Package Access support"
depends on LORA_BASICS_MODEM_FUOTA
default n

#-----------------------------------------------------------------------------
# LoRaCloud related options
#-----------------------------------------------------------------------------

config LORA_BASICS_MODEM_ALMANAC
bool "Cloud Almanac Update service (only applicable for lr1110 and lr1120 targets)"
depends on DT_HAS_SEMTECH_LR1110_ENABLED || DT_HAS_SEMTECH_LR1120_ENABLED
default n

config LORA_BASICS_MODEM_STREAM
bool "Stream service"
default n

config LORA_BASICS_MODEM_LFU
bool "Large File Upload service"
default n

config LORA_BASICS_MODEM_DEVICE_MANAGEMENT
bool "Device Management service"
default n

config LORA_BASICS_MODEM_GEOLOCATION
bool "Geolocation service"
depends on DT_HAS_SEMTECH_LR1110_ENABLED || DT_HAS_SEMTECH_LR1120_ENABLED
default n

config LORA_BASICS_MODEM_STORE_AND_FORWARD
bool "Store And Forward service"
default n

#-----------------------------------------------------------------------------
# Relay and beacon options
#-----------------------------------------------------------------------------

# TODO:
config LORA_BASICS_MODEM_BEACON_TX
bool "Beacon transmission support"
default n

# TODO:
config LORA_BASICS_MODEM_RELAY_TX
bool "Relay TX feature"
default n

# TODO: not released yet
# config LORA_BASICS_MODEM_RELAY_RX
# bool "Relay RX support"
# default n

#-----------------------------------------------------------------------------
# Miscellaneous options
#-----------------------------------------------------------------------------

config LORA_BASICS_MODEM_NUMBER_OF_STACKS
int "Number of LoRa Basics Modem stacks (only 1 is supported for now)"
default 1
help
Number of stacks to be used by the modem library.


config LORA_BASICS_MODEM_PERF_TEST
bool "Build LoRa Basics Modem in perf test"
default n
help
Useful only when building the hardware modem sample

config LORA_BASICS_MODEM_DISABLE_JOIN_DUTY_CYCLE
bool "Disable the Join duty cycle. ONLY ENABLE FOR ISOLATED SETUPS!"
default n
help
Enable this if you are testing in an isolated setup (e.g with coaxial cables
between gateway and device) for faster joins.
You should keep this disabled to follow the LoRaWAN standard.


# FIXME: is it useful?
config LORA_BASICS_MODEM_CONTEXT_BUFFER_SIZE
int "Context backup/restoration buffer size"
default 512

config LORA_BASICS_MODEM_MAIN_THREAD
bool "Build a main loop thread that runs the LBM stack."
default n
help
This thread needs to be manually started. It initializes the LBM stack,
and runs it.
The chosen zephyr,lora-transceiver device will be used as transceiver.
TODO: Add this to the doc/build/dts/api/api.rst too.

if LORA_BASICS_MODEM_MAIN_THREAD

config LORA_BASICS_MODEM_MAIN_THREAD_STACK_SIZE
int "Stack size of the LBM main thread"
default 2048
help
Stack size for the LBM main thread

config LORA_BASICS_MODEM_MAIN_THREAD_PRIORITY
int "Priority of the LBM main thread"
default 2
help
Thread priority of the LBM main thread

endif # LORA_BASICS_MODEM_MAIN_THREAD

endif # LORA_BASICS_MODEM
Loading

0 comments on commit f129e6c

Please sign in to comment.