[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190128161306.27805-11-ben.whitten@lairdtech.com>
Date: Mon, 28 Jan 2019 16:13:04 +0000
From: Ben Whitten <ben.whitten@...il.com>
To: afaerber@...e.de
Cc: linux-lpwan@...ts.infradead.org,
Ben Whitten <ben.whitten@...rdtech.com>,
"David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH lora-next 10/11] net: lora: sx130x: make use of lora address metadata in transmission
We take the metadata encoded in the lora address and apply it to the
outgoing transmission.
Signed-off-by: Ben Whitten <ben.whitten@...rdtech.com>
---
drivers/net/lora/sx130x.c | 58 ++++++++++++++++++++++++++++++++-------
1 file changed, 48 insertions(+), 10 deletions(-)
diff --git a/drivers/net/lora/sx130x.c b/drivers/net/lora/sx130x.c
index f96f32d2e1ff..428e82b4ccb8 100644
--- a/drivers/net/lora/sx130x.c
+++ b/drivers/net/lora/sx130x.c
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/gpio/consumer.h>
#include <linux/lora/dev.h>
+#include <linux/lora/skb.h>
#include <linux/spi/spi.h>
#include "sx130x.h"
@@ -688,12 +689,13 @@ static int sx130x_agc_init(struct sx130x_priv *priv)
return ret;
}
-static int sx130x_tx(struct sx130x_priv *priv, void *data, int len)
+static int sx130x_tx(struct sx130x_priv *priv, struct sk_buff *skb)
{
int ret, i;
u8 buff[256 + 16];
struct sx130x_tx_header *hdr = (struct sx130x_tx_header *)buff;
struct net_device *netdev = dev_get_drvdata(priv->dev);
+ u8 sf;
/* TODO general checks to make sure we CAN send */
@@ -722,11 +724,47 @@ static int sx130x_tx(struct sx130x_priv *priv, void *data, int len)
hdr->tx_power = 15; /* HACK power entry 15 */
hdr->u.lora.crc16_en = 1; /* Enable CRC16 */
- hdr->u.lora.cr = 1; /* CR 4/5 */
- hdr->u.lora.sf = 7; /* SF7 */
- hdr->u.lora.payload_len = len; /* Set the data len to the skb len */
+
+ switch (lora_skb_prv(skb)->cr) {
+ case 5:
+ hdr->u.lora.cr = 1; /* CR 4/5 */
+ break;
+ case 6:
+ hdr->u.lora.cr = 2; /* CR 4/6 */
+ break;
+ case 7:
+ hdr->u.lora.cr = 3; /* CR 4/7 */
+ break;
+ case 8:
+ hdr->u.lora.cr = 4; /* CR 4/8 */
+ break;
+ default:
+ return -ENXIO;
+ }
+
+ sf = lora_skb_prv(skb)->sf;
+ if ((sf < 6) || (sf > 12))
+ return -ENXIO;
+
+ hdr->u.lora.sf = sf;
+
+ hdr->u.lora.payload_len = skb->len; /* Set the data length */
hdr->u.lora.implicit_header = 0; /* No implicit header */
- hdr->u.lora.mod_bw = 0; /* Set 125KHz BW */
+
+ switch(lora_skb_prv(skb)->bw) {
+ case 125:
+ hdr->u.lora.mod_bw = 0; /* 125KHz BW */
+ break;
+ case 250:
+ hdr->u.lora.mod_bw = 1; /* 250KHz BW */
+ break;
+ case 500:
+ hdr->u.lora.mod_bw = 2; /* 500KHz BW */
+ break;
+ default:
+ return -ENXIO;
+ }
+
hdr->u.lora.ppm_offset = 0; /* TODO no ppm offset? */
hdr->u.lora.invert_pol = 0; /* TODO set no inverted polarity */
@@ -737,7 +775,7 @@ static int sx130x_tx(struct sx130x_priv *priv, void *data, int len)
/* Copy the TX data into the buffer ready to go */
- memcpy((void *)&buff[16], data, len);
+ memcpy((void *)&buff[16], skb->data, skb->len);
/* Reset any transmissions */
ret = regmap_write(priv->regmap, SX1301_TX_TRIG, 0);
@@ -749,7 +787,7 @@ static int sx130x_tx(struct sx130x_priv *priv, void *data, int len)
if (ret)
return ret;
ret = regmap_noinc_write(priv->regmap, SX1301_TX_DATA_BUF_DATA, buff,
- len + 16);
+ skb->len + 16);
if (ret)
return ret;
@@ -758,8 +796,8 @@ static int sx130x_tx(struct sx130x_priv *priv, void *data, int len)
if (ret)
return ret;
- netdev_dbg(netdev, "Transmitting packet of size %d: ", len);
- for (i = 0; i < len + 16; i++)
+ netdev_dbg(netdev, "Transmitting packet of size %d: ", skb->len);
+ for (i = 0; i < skb->len + 16; i++)
netdev_dbg(netdev, "%X", buff[i]);
return ret;
@@ -791,7 +829,7 @@ static void sx130x_tx_work_handler(struct work_struct *ws)
netdev_dbg(netdev, "%s\n", __func__);
if (priv->tx_skb) {
- ret = sx130x_tx(priv, priv->tx_skb->data, priv->tx_skb->len);
+ ret = sx130x_tx(priv, priv->tx_skb);
if (ret) {
netdev->stats.tx_errors++;
} else {
--
2.17.1
Powered by blists - more mailing lists