Re: [PATCH RFC lora-next 4/4] net: lora: sx1301: introduce a lora frame for packet metadata
From: Andreas FÃrber
Date: Sun Dec 30 2018 - 18:38:53 EST
Hi Ben,
Am 19.12.18 um 16:56 schrieb Ben Whitten:
> Information such as spreading factor, coding rate and power are on a per
> transmission basis so it makes sence to include this in a header much
"sense" (even in British English! :))
> like CAN frames do.
Any pointer for that? My understanding of CAN was that it actually uses
the CAN or CAN FD frame for transmission on the wire.
Whereas here you use it for metadata that does not go over the air.
>
> Signed-off-by: Ben Whitten <ben.whitten@xxxxxxxxxxxxx>
> ---
> drivers/net/lora/dev.c | 2 -
> drivers/net/lora/sx1301.c | 79 +++++++++++++++++++++++++++++++++------
> include/uapi/linux/lora.h | 46 +++++++++++++++++++++++
> 3 files changed, 114 insertions(+), 13 deletions(-)
If we should seriously consider this new approach, please always cleanly
split it off from sx1301 driver changes. The most important changes are
at the very bottom here otherwise.
Some of the enums may be useful either way.
[snip]
> diff --git a/include/uapi/linux/lora.h b/include/uapi/linux/lora.h
> index 4ff00b9c3c20..d675025d2a6e 100644
> --- a/include/uapi/linux/lora.h
> +++ b/include/uapi/linux/lora.h
> @@ -21,4 +21,50 @@ struct sockaddr_lora {
> } lora_addr;
> };
>
> +#define LORA_MAX_DLEN 256
Note: According to Helmut, "SX1276 can do MTU sizes up to 2048 bytes".
But I have failed to find mention of LoRa-mode interrupts other than
TxDone or any such how-to in the SX1276 manual or on Google; only the
FSK/OOK modem has a FIFO-less Continuous mode documented.
> +
> +enum lora_bw {
> + LORA_BW_125KHZ,
> + LORA_BW_250KHZ,
> + LORA_BW_500KHZ,
Lacking lower bandwidths. SX127x can go as low as 7.8 kHz.
Would it work to have it as an integer in Hz for flexibility?
> +};
> +
> +enum lora_cr {
> + LORA_CR_4_5,
> + LORA_CR_4_6,
> + LORA_CR_4_7,
> + LORA_CR_4_8,
> +};
If we have this as ABI, we should probably go safe and initialize the
first one to 0.
> +
> +enum lora_sf {
> + LORA_SF_6,
> + LORA_SF_7,
> + LORA_SF_8,
> + LORA_SF_9,
> + LORA_SF_10,
> + LORA_SF_11,
> + LORA_SF_12,
> +};
Wouldn't an integer be sufficient for the Spreading Factor?
We'll need to safeguard code against unexpected values anyway.
An added bonus for the enum/defines would be if we could have
LORA_SF_6 = 64
up to
LORA_SF_12 = 4096
(chips per symbol)
> +
> +/**
> + * struct lora_frame - LoRa frame structure
> + * @freq: Frequency of LoRa transmission in Hz
> + * @power: Power of transmission in dBm
> + * @bw: bandwidth, 125, 250 or 500 KHz
> + * @cr: coding rate, 4/5 to 4/8
> + * @sf: spreading factor from SF6 to 12
> + * @data: LoRa frame payload (up to LORA_MAX_DLEN byte)
> + */
> +struct lora_frame {
> + __u32 freq; /* transmission frequency in Hz */
> + __u8 power; /* transmission power in dBm */
> + enum lora_bw bw; /* bandwidth */
> + enum lora_cr cr; /* coding rate */
> + enum lora_sf sf; /* spreading factor */
> + __u8 len;
> + __u8 data[LORA_MAX_DLEN] __attribute__((aligned(8)));
> +};
I'm not comfortable with making this arbitrary format a userspace ABI.
For example, hardcoding the frequency as __u32 will limit us to 4 GHz,
which is sufficient for 2.4 GHz, but Wifi is already at 5 and 60 GHz.
Having the data at the end means we can't easily add header fields, such
as Sync Word (that you're missing above) or a frequency extension word.
Reuse with FSK/OOK or other LPWAN technologies could be a bonus goal.
In my presentation I had suggested to use the socket address for storing
most of that metadata. The counter-proposal was to use netlink for any
global setting changes and have the socket just send the actual data.
Reminder: We can set SX127x registers before each TX, but RX remained
unsolved. For SX130x we can set some metadata per TX (multi-channel),
but radio/channel need to have been configured appropriately. Wifi cards
may support MIMO but still show up as one wlan0 netdev, so it seemed
questionable to diverge for SX130x by having ~10 netdevs and impractical
since we have a lot of radio initializations in .ndo_open.
Compare slides 16 ff. vs. slide 27:
https://events.linuxfoundation.org/wp-content/uploads/2017/12/ELCE2018_LoRa_final_Andreas-Farber.pdf
Ultimately the skb is where we need any per-transaction metadata, and
outside uapi/ I'm much less concerned about ABI changes. So from my
perspective such fields would go into linux/lora/skb.h struct lora_priv
after the ifindex, if we go with PF_LORA. As mentioned before, if we
have to go with PF_PACKET then I'm clueless where to store such data...
> +
> +#define LORA_MTU (sizeof(struct lora_frame))
Even if Helmut's comment was mistaken, it doesn't strike me as a good
idea to hardcode this here - you could just use data[0] and leave actual
MTU to the driver/user.
> +
> #endif /* _UAPI_LINUX_LORA_H */
Cheers,
Andreas
--
SUSE Linux GmbH, Maxfeldstr. 5, 90409 NÃrnberg, Germany
GF: Felix ImendÃrffer, Jane Smithard, Graham Norton
HRB 21284 (AG NÃrnberg)