Netdev List
 help / color / mirror / Atom feed
From: Ben Whitten <ben.whitten@gmail.com>
To: afaerber@suse.de
Cc: linux-lpwan@lists.infradead.org,
	Ben Whitten <ben.whitten@lairdtech.com>,
	"David S. Miller" <davem@davemloft.net>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH lora-next 09/11] net: lora: introduce lora socket addressing for metadata
Date: Mon, 28 Jan 2019 16:13:03 +0000	[thread overview]
Message-ID: <20190128161306.27805-10-ben.whitten@lairdtech.com> (raw)
In-Reply-To: <20190128161306.27805-1-ben.whitten@lairdtech.com>

Information such as spreading factor, coding rate and power are on a per
transmission basis so we can encode this information in the lora socket
address.
In future we may have a different format for receive with additional
fields which get populated.

Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
---
 include/linux/lora/skb.h  |  9 ++++++++
 include/uapi/linux/lora.h | 14 ++++++++++++
 net/lora/dgram.c          | 45 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)

diff --git a/include/linux/lora/skb.h b/include/linux/lora/skb.h
index 8806741464d0..6abeb39b8b7f 100644
--- a/include/linux/lora/skb.h
+++ b/include/linux/lora/skb.h
@@ -12,6 +12,15 @@
 
 struct lora_skb_priv {
 	int ifindex;
+
+	u64 freq;
+	u8 sf;
+	u8 cr;
+	u16 bw;
+
+	u8 sync;
+
+	s8 power;
 };
 
 static inline struct lora_skb_priv *lora_skb_prv(struct sk_buff *skb)
diff --git a/include/uapi/linux/lora.h b/include/uapi/linux/lora.h
index 4ff00b9c3c20..4c458ee3ed9a 100644
--- a/include/uapi/linux/lora.h
+++ b/include/uapi/linux/lora.h
@@ -10,6 +10,18 @@
 #include <linux/types.h>
 #include <linux/socket.h>
 
+/* TX addressing definition */
+struct tx_addr {
+	__u64 freq;
+	__u8 sf;
+	__u8 cr;
+	__u16 bw;
+
+	__u8 sync;
+
+	__s8 power;
+};
+
 /* particular protocols of the protocol family PF_LORA */
 #define LORA_PROTO_DATAGRAM	0
 #define LORA_NPROTO		1
@@ -17,7 +29,9 @@
 struct sockaddr_lora {
 	__kernel_sa_family_t lora_family;
 	int lora_ifindex;
+	__u8 lora_protocol;
 	union {
+		struct tx_addr	tx;
 	} lora_addr;
 };
 
diff --git a/net/lora/dgram.c b/net/lora/dgram.c
index 4d931fd3778a..1556ad0f8835 100644
--- a/net/lora/dgram.c
+++ b/net/lora/dgram.c
@@ -20,6 +20,15 @@ struct dgram_sock {
 	int ifindex;
 	bool bound;
 	struct notifier_block notifier;
+
+	u64 freq;
+	u8 sf;
+	u8 cr;
+	u16 bw;
+
+	u8 sync;
+
+	s8 power;
 };
 
 static inline struct dgram_sock *dgram_sk(const struct sock *sk)
@@ -69,6 +78,12 @@ static int dgram_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 		ifindex = 0;
 
 	dgram->ifindex = ifindex;
+	dgram->freq = addr->lora_addr.tx.freq;
+	dgram->sf = addr->lora_addr.tx.sf;
+	dgram->cr = addr->lora_addr.tx.cr;
+	dgram->bw = addr->lora_addr.tx.bw;
+	dgram->sync = addr->lora_addr.tx.sync;
+	dgram->power = addr->lora_addr.tx.power;
 	dgram->bound = true;
 
 out:
@@ -118,6 +133,12 @@ static int dgram_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 
 	lora_skb_reserve(skb);
 	lora_skb_prv(skb)->ifindex = netdev->ifindex;
+	lora_skb_prv(skb)->freq = dgram->freq;
+	lora_skb_prv(skb)->sf = dgram->sf;
+	lora_skb_prv(skb)->cr = dgram->cr;
+	lora_skb_prv(skb)->bw = dgram->bw;
+	lora_skb_prv(skb)->sync = dgram->sync;
+	lora_skb_prv(skb)->power = dgram->power;
 
 	ret = memcpy_from_msg(skb_put(skb, size), msg, size);
 	if (ret < 0)
@@ -172,6 +193,12 @@ static int dgram_getname(struct socket *sock, struct sockaddr *uaddr,
 	memset(addr, 0, sizeof(*addr));
 	addr->lora_family = AF_LORA;
 	addr->lora_ifindex = dgram->ifindex;
+	addr->lora_addr.tx.freq = dgram->freq;
+	addr->lora_addr.tx.sf = dgram->sf;
+	addr->lora_addr.tx.cr = dgram->cr;
+	addr->lora_addr.tx.bw = dgram->bw;
+	addr->lora_addr.tx.sync = dgram->sync;
+	addr->lora_addr.tx.power = dgram->power;
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
 	return sizeof(*addr);
@@ -198,6 +225,12 @@ static int dgram_release(struct socket *sock)
 	lock_sock(sk);
 
 	dgram->ifindex = 0;
+	dgram->freq = 0;
+	dgram->sf = 0;
+	dgram->cr = 0;
+	dgram->bw = 0;
+	dgram->sync = 0;
+	dgram->power = 0;
 	dgram->bound = false;
 
 	sock_orphan(sk);
@@ -251,6 +284,12 @@ static int dgram_notifier(struct notifier_block *nb, unsigned long msg, void *pt
 		lock_sock(sk);
 
 		dgram->ifindex = 0;
+		dgram->freq = 0;
+		dgram->sf = 0;
+		dgram->cr = 0;
+		dgram->bw = 0;
+		dgram->sync = 0;
+		dgram->power = 0;
 		dgram->bound = false;
 
 		release_sock(sk);
@@ -277,6 +316,12 @@ static int dgram_init(struct sock *sk)
 	pr_debug("lora: %s\n", __func__);
 
 	dgram->bound = false;
+	dgram->freq = 0;
+	dgram->sf = 0;
+	dgram->cr = 0;
+	dgram->bw = 0;
+	dgram->sync = 0;
+	dgram->power = 0;
 	dgram->ifindex = 0;
 
 	dgram->notifier.notifier_call = dgram_notifier;
-- 
2.17.1


  parent reply	other threads:[~2019-01-28 17:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28 16:12 [PATCH lora-next 00/11] net: lora: Get SX130x to transmit lora packets Ben Whitten
2019-01-28 16:12 ` [PATCH lora-next 01/11] dt-bindings: net: lora: sx130x: add power lut binding Ben Whitten
2019-01-28 18:13   ` Rob Herring
2019-01-28 16:12 ` [PATCH lora-next 02/11] net: lora: sx130x: add loading of tx lut from DT Ben Whitten
2019-01-28 16:12 ` [PATCH lora-next 03/11] net: lora: sx130x: add CHRS to volatile register list Ben Whitten
2019-01-28 16:12 ` [PATCH lora-next 04/11] net: lora: sx130x: add helper function for writing to the SX130x MCU Ben Whitten
2019-01-28 16:12 ` [PATCH lora-next 05/11] net: lora: sx130x: initialise AGC Ben Whitten
2019-01-28 16:13 ` [PATCH lora-next 06/11] net: lora: sx130x: add detail to TODO in setup Ben Whitten
2019-01-28 16:13 ` [PATCH lora-next 07/11] net: lora: sx130x: add work queue to tx path Ben Whitten
2019-01-28 16:13 ` [PATCH lora-next 08/11] net: lora: sx130x: add test transmission Ben Whitten
2019-01-28 16:13 ` Ben Whitten [this message]
2019-01-28 16:13 ` [PATCH lora-next 10/11] net: lora: sx130x: make use of lora address metadata in transmission Ben Whitten
2019-01-28 16:13 ` [PATCH lora-next 11/11] net: lora: sx130x: add patch to register fields Ben Whitten

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190128161306.27805-10-ben.whitten@lairdtech.com \
    --to=ben.whitten@gmail.com \
    --cc=afaerber@suse.de \
    --cc=ben.whitten@lairdtech.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-lpwan@lists.infradead.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox