Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lora wan interface #6

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The initial prototype can be seen in the images below.
* [_COMPLETED_] GPS Works, gpsd installed.
* [_COMPLETED_] CI/CD Works.
* [_TESTING_] WSPR Working, Still requires real-world tests.
* [_IN PROGRESS_] Lora works, LoraWan not.
* [_IN PROGRESS_] Lora works, LoraWan not tested, added EU region, missing others in kernel driver.
* [_TODO_] "Glue" shell scripts to tack everything together.
* [_TODO_] CSI Camera Interface with CSI/MIPI camera.
* [_TODO_] Camera Images to Lorawan Packets.
Expand Down
2 changes: 1 addition & 1 deletion docs/LoraWanHelium.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ _Overall_ - there are two choices.

The former, while a PITA initially, actually provides what initially appears to be an easy to use interface to Lora, with functions such as spreading factor, band etc all controllable using ioctl calls.

The solution here will likely be to create the MAC "Driver" in userland. Should it be there? Absolutely not. (But, once again future improvement, otherwise the project will never get finished.)
It appears that Starnight has also produced a LoraWan driver, which is currently written for the 4.11 kernel, which needs updating to the current kernel and testing.

5 changes: 5 additions & 0 deletions sysdrv/cfg/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ $(eval $(call MACRO_CHECK_ENABLE_PKG, RK_ENABLE_OTA))
CONFIG_SYSDRV_ENABLE_STRACE=n
$(eval $(call MACRO_CHECK_ENABLE_PKG, RK_ENABLE_STRACE))


# Enable build lorawan-bridge
CONFIG_SYSDRV_ENABLE_LORAWAN_BRIDGE=y
$(eval $(call MACRO_CHECK_ENABLE_PKG, RK_ENABLE_LORAWAN_BRIDGE))

# Enable build WSPR
CONFIG_SYSDRV_ENABLE_WSPR=y
$(eval $(call MACRO_CHECK_ENABLE_PKG, RK_ENABLE_WSPR))
2 changes: 1 addition & 1 deletion sysdrv/drv_ko/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PKG_BIN := out

M_OUT_DIR := $(CURRENT_DIR)/$(PKG_BIN)
export M_OUT_DIR
M_DIRS := rockit kmpp wifi motor sx1276
M_DIRS := rockit kmpp wifi motor sx1276 lorawan
################################################################################
## build target
################################################################################
Expand Down
77 changes: 74 additions & 3 deletions sysdrv/drv_ko/lorawan/lrwreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,64 @@ static struct lrw_dr us902_928_drs[] = {
{},
};

static struct lrw_dr eu863_870_drs[] = {
{.sf = 12, .bw = 125000, .mode = LRW_LORA},
{.sf = 11, .bw = 125000, .mode = LRW_LORA},
{.sf = 10, .bw = 125000, .mode = LRW_LORA},
{.sf = 9, .bw = 125000, .mode = LRW_LORA},
{.sf = 8, .bw = 125000, .mode = LRW_LORA},
{.sf = 7, .bw = 125000, .mode = LRW_LORA},
{.sf = 7, .bw = 250000, .mode = LRW_LORA},
{},
};

static struct lrw_tx_power eu863_870_txpws[] = {
{.dbm = 16},
{.dbm = 14},
{.dbm = 12},
{.dbm = 10},
{.dbm = 8},
{.dbm = 6},
{.dbm = 4},
{.dbm = 2}
};

static struct lrw_payload_len eu863_870_pl_nofopt[] = {
{.m = 59, .n = 51},
{.m = 59, .n = 51},
{.m = 59, .n = 51},
{.m = 123, .n = 115},
{.m = 250, .n = 242},
{.m = 250, .n = 242},
{.m = 250, .n = 242},
{},
};

static struct lrw_payload_len eu863_870_pl_fopt[] = {
{.m = 59, .n = 51},
{.m = 59, .n = 51},
{.m = 59, .n = 51},
{.m = 123, .n = 115},
{.m = 230, .n = 222},
{.m = 230, .n = 222},
{.m = 230, .n = 222},
{},
};

u32 eu863_870_ch2frq(u8 dir, u8 ch)
{
u32 frq_base;
u32 frq;
u32 step;

frq_base = 863100000;
step = 200000;
frq = frq_base + step * ch;

return frq;
}


static struct lrw_tx_power us902_928_txpws[] = {
{.dbm = 30},
{.dbm = 28},
Expand Down Expand Up @@ -165,7 +223,20 @@ u32 as923_ch2frq(u8 dir, u8 ch)
}

static const struct lrw_region_parm reg_parms[] = {
[LRW_EU863_870] = {},
[LRW_EU863_870] = {
.sync_word = 0x34,
.preamble_len = 8,
.drt = eu863_870_drs,
.pwt = eu863_870_txpws,
.plt[0] = eu863_870_pl_fopt,
.plt[1] = eu863_870_pl_nofopt,
.ch_2_frq = eu863_870_ch2frq,
.rx_delay1 = HZ,
.rx_delay2 = 2 * HZ,
.join_accept_delay1 = 5 * HZ,
.join_accept_delay2 = 6 * HZ,
.ack_timeout = 2 * HZ,
},
[LRW_US902_928] = {
.sync_word = 0x34,
.preamble_len = 8,
Expand All @@ -181,9 +252,9 @@ static const struct lrw_region_parm reg_parms[] = {
.ack_timeout = 2 * HZ,
},
[LRW_CN779_787] = {},
[LRW_EU443] = {},
// [LRW_EU443] = {},
[LRW_AU915_928] = {},
[LRW_CN470_510] = {},
// [LRW_CN470_510] = {},
[LRW_AS923] = {
.sync_word = 0x34,
.preamble_len = 8,
Expand Down
2 changes: 1 addition & 1 deletion sysdrv/drv_ko/lorawan/lrwsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ lrw_aes_enc(struct crypto_skcipher *tfm, u8 *in, size_t len, u8 *out)
{
u8 iv[16];
struct scatterlist src, dst;
SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
SKCIPHER_REQUEST_ON_STACK(req, tfm);
int err;

memset(iv, 0, 16);
Expand Down
14 changes: 14 additions & 0 deletions sysdrv/drv_ko/lorawan/lrwsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,18 @@ int lrw_decrypt_buf(struct crypto_skcipher *tfm,
u8 dir, u8 *devaddr, u32 fcnt, u8 *buf, size_t len);
void lrw_encrypt_key_free(struct crypto_skcipher *tfm);

/*
#define SKCIPHER_REQUEST_ON_STACK(name, tfm) \
char __##name##_desc[sizeof(struct skcipher_request) + \
crypto_skcipher_reqsize(tfm)] CRYPTO_MINALIGN_ATTR; \
struct skcipher_request *name = (void *)__##name##_desc
*/

#define SKCIPHER_MAX_REQSIZE 472

#define SKCIPHER_REQUEST_ON_STACK(name, tfm) \
char __##name##_desc[sizeof(struct skcipher_request) + \
SKCIPHER_MAX_REQSIZE] CRYPTO_MINALIGN_ATTR; \
struct skcipher_request *name = (void *)__##name##_desc

#endif
3 changes: 2 additions & 1 deletion sysdrv/drv_ko/lorawan/socket.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <linux/list.h>
#include <linux/net.h>
#include <linux/if_arp.h>
#include <linux/sockptr.h>
#include <linux/termios.h> /* For TIOCOUTQ/INQ */
#include <net/sock.h>

Expand Down Expand Up @@ -380,7 +381,7 @@ dgram_getsockopt(struct sock *sk, int level, int optname,

static int
dgram_setsockopt(struct sock *sk, int level, int optname,
struct sockptr_t *optval, unsigned int optlen)
sockptr_t optval, unsigned int optlen)
{
int val;
int err = 0;
Expand Down
7 changes: 7 additions & 0 deletions sysdrv/tools/board/Makefile.tools.board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tools_board-builds: \
board-build-e2fsprogs \
board-build-sysstat \
board-build-mtd_utils \
board-build-lorawan-bridge \
board-build-wspr
@echo "build tools board done"

Expand All @@ -24,6 +25,7 @@ tools_board-clean:
$(MAKE) -C $(SYSDRV_DIR)/tools/board/stressapptest distclean
$(MAKE) -C $(SYSDRV_DIR)/tools/board/rk_ota distclean
$(MAKE) -C $(SYSDRV_DIR)/tools/board/sysstat distclean
$(MAKE) -C $(SYSDRV_DIR)/tools/board/lorawan-bridge distclean
$(MAKE) -C $(SYSDRV_DIR)/tools/board/wspr distclean

board-build-toolkits:
Expand Down Expand Up @@ -82,6 +84,11 @@ ifeq ($(ENABLE_SYSSTAT),y)
$(MAKE) -C $(SYSDRV_DIR)/tools/board/sysstat
endif

board-build-lorawan-bridge:
ifeq ($(ENABLE_LORAWAN_BRIDGE),y)
$(MAKE) -C $(SYSDRV_DIR)/tools/board/lorawan-bridge
endif

board-build-wspr:
ifeq ($(ENABLE_WSPR),y)
$(MAKE) -C $(SYSDRV_DIR)/tools/board/wspr
Expand Down
25 changes: 25 additions & 0 deletions sysdrv/tools/board/lorawan-bridge/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#ifeq ($(SYSDRV_PARAM), )
LORAWAN_BRIDGE_PARAM:=../../../Makefile.param
include $(LORAWAN_BRIDGE_PARAM)
#endif

export LC_ALL=C
SHELL:=/bin/bash

CURRENT_DIR := $(shell pwd)
PKG_NAME := lbr
PKG_BIN := out

all:
@test -f $(PKG_BIN)/usr/sbin/$(PKG_NAME)_noexist || (\
mkdir -p $(CURRENT_DIR)/$(PKG_BIN)/usr/sbin; \
$(SYSDRV_CROSS)-gcc -g main.c -o $(CURRENT_DIR)/$(PKG_BIN)/usr/sbin/$(PKG_NAME); \
)
$(call MAROC_COPY_PKG_TO_SYSDRV_OUTPUT, $(SYSDRV_DIR_OUT_ROOTFS), $(PKG_BIN))
# $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL_DIR) M=$(shell pwd) $@ -j12

clean: distclean

distclean:
-rm -rf $(PKG_NAME) $(PKG_BIN)
Loading
Loading