Skip to content

Commit 23f6eb9

Browse files
Tomasz Bursztykajukkar
Tomasz Bursztyka
authored andcommitted
drivers: ieee802154: Implement get_lqi() relevantly
Change-Id: Idc433b77ea3cb38af648d70ad285429c29e53c08 Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent bf33494 commit 23f6eb9

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

drivers/ieee802154/ieee802154_cc2520.c

+19-9
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ static void cc2520_rx(int arg, int unused2)
575575
struct net_buf *pkt_buf = NULL;
576576
struct net_buf *buf;
577577
uint8_t pkt_len;
578-
uint8_t lqi;
579578

580579
ARG_UNUSED(unused2);
581580

@@ -643,18 +642,22 @@ static void cc2520_rx(int arg, int unused2)
643642
* else:
644643
* lqi = (lqi - 50) * 4
645644
*/
646-
lqi = pkt_buf->data[pkt_len - 1] & CC2520_FCS_CORRELATION;
647-
if (lqi <= 50) {
648-
lqi = 0;
649-
} else if (lqi >= 110) {
650-
lqi = 255;
645+
cc2520->lqi = pkt_buf->data[pkt_len - 1] &
646+
CC2520_FCS_CORRELATION;
647+
if (cc2520->lqi <= 50) {
648+
cc2520->lqi = 0;
649+
} else if (cc2520->lqi >= 110) {
650+
cc2520->lqi = 255;
651651
} else {
652-
lqi = (lqi - 50) << 2;
652+
cc2520->lqi = (cc2520->lqi - 50) << 2;
653653
}
654654

655-
net_buf_add_u8(pkt_buf, lqi);
655+
#if defined(CONFIG_TI_CC2520_RAW)
656+
net_buf_add_u8(pkt_buf, cc2520->lqi);
657+
#endif
656658

657-
SYS_LOG_DBG("Caught a packet (%u) (LQI: %u)\n", pkt_len, lqi);
659+
SYS_LOG_DBG("Caught a packet (%u) (LQI: %u)\n",
660+
pkt_len, cc2520->lqi);
658661

659662
if (net_recv_data(cc2520->iface, buf) < 0) {
660663
SYS_LOG_DBG("Packet dropped by NET stack\n");
@@ -897,6 +900,12 @@ static int cc2520_stop(struct device *dev)
897900
return 0;
898901
}
899902

903+
static uint8_t cc2520_get_lqi(struct device *dev)
904+
{
905+
struct cc2520_context *cc2520 = dev->driver_data;
906+
907+
return cc2520->lqi;
908+
}
900909

901910
/******************
902911
* Initialization *
@@ -1053,6 +1062,7 @@ static struct ieee802154_radio_api cc2520_radio_api = {
10531062
.start = cc2520_start,
10541063
.stop = cc2520_stop,
10551064
.tx = cc2520_tx,
1065+
.get_lqi = cc2520_get_lqi,
10561066
};
10571067

10581068
#if defined(CONFIG_TI_CC2520_RAW)

drivers/ieee802154/ieee802154_cc2520.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct cc2520_context {
5555
char __stack cc2520_rx_stack[CONFIG_CC2520_RX_STACK_SIZE];
5656
struct nano_sem rx_lock;
5757
bool overflow;
58+
uint8_t lqi;
5859
};
5960

6061
extern struct device **cc2520_configure_gpios(void);

drivers/ieee802154/ieee802154_uart_pipe.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ static uint8_t *upipe_rx(uint8_t *buf, size_t *off)
7979
net_buf_frag_insert(nbuf, pkt_buf);
8080

8181
memcpy(pkt_buf->data, upipe->rx_buf, upipe->rx_len);
82-
/* packet length plus missing LQI (one byte) */
83-
net_buf_add(pkt_buf, upipe->rx_len + 1);
82+
net_buf_add(pkt_buf, upipe->rx_len);
8483

8584
if (ieee802154_radio_handle_ack(upipe->iface, nbuf) == NET_OK) {
8685
SYS_LOG_DBG("ACK packet handled");

net/yaip/l2/ieee802154/ieee802154.c

+6-14
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ static void pkt_hexdump(struct net_buf *buf, bool each_frag_reserve)
9292
#define pkt_hexdump(...)
9393
#endif
9494

95-
static inline uint8_t get_lqi(struct net_buf *buf)
96-
{
97-
uint8_t *lqi;
98-
99-
buf->len -= 1;
100-
101-
lqi = net_buf_tail(buf);
102-
103-
return *lqi;
104-
}
105-
10695
#ifdef CONFIG_NET_L2_IEEE802154_ACK_REPLY
10796
static inline void ieee802154_acknowledge(struct net_if *iface,
10897
struct ieee802154_mpdu *mpdu)
@@ -258,9 +247,6 @@ static enum net_verdict ieee802154_recv(struct net_if *iface,
258247
{
259248
struct ieee802154_mpdu mpdu;
260249

261-
/* Let's remove LQI for now as it is not used */
262-
get_lqi(buf->frags);
263-
264250
if (!ieee802154_validate_frame(net_nbuf_ll(buf),
265251
net_buf_frags_len(buf), &mpdu)) {
266252
return NET_DROP;
@@ -316,6 +302,12 @@ static enum net_verdict ieee802154_send(struct net_if *iface,
316302

317303
frag = buf->frags;
318304
while (frag) {
305+
if (frag->len > IEEE802154_MTU) {
306+
NET_ERR("Frag %p as too big length %u",
307+
frag, frag->len);
308+
return NET_DROP;
309+
}
310+
319311
if (!ieee802154_create_data_frame(iface, buf,
320312
frag->data - reserved_space,
321313
reserved_space)) {

0 commit comments

Comments
 (0)