From 4e7efd4bcbe0487250992af0faee93cf78085506 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Wed, 29 Jun 2016 18:01:40 +0200 Subject: [PATCH] tests: net: Add a IEEE 802.15.4 ACK replies test - Parsing a proper ACK reply - Generating a ACK reply from a data packet requesting it, and comparing it to a proper one. Change-Id: I1717fedc899eafa0aa849e1e253f02cd3dc3d4fc Signed-off-by: Tomasz Bursztyka --- tests/net/ieee802154/src/ieee802154_test.c | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/net/ieee802154/src/ieee802154_test.c b/tests/net/ieee802154/src/ieee802154_test.c index 5eb5088e05d..0c5f1bce404 100644 --- a/tests/net/ieee802154/src/ieee802154_test.c +++ b/tests/net/ieee802154/src/ieee802154_test.c @@ -60,6 +60,17 @@ struct ieee802154_pkt_test test_ns_pkt = { .mhr_check.src_addr = (struct ieee802154_address_field *)(ns_pkt + 7), }; +uint8_t ack_pkt[] = { 0x02, 0x10, 0x16, 0xa2, 0x97 }; + +struct ieee802154_pkt_test test_ack_pkt = { + .name = "ACK frame", + .pkt = ack_pkt, + .length = sizeof(ack_pkt), + .mhr_check.fc_seq = (struct ieee802154_fcf_seq *)ack_pkt, + .mhr_check.dst_addr = NULL, + .mhr_check.src_addr = NULL, +}; + struct net_buf *current_buf; struct nano_sem driver_lock; struct net_if *iface; @@ -158,6 +169,59 @@ static inline int test_ns_sending(struct ieee802154_pkt_test *t) return TC_PASS; } +static inline int test_ack_reply(struct ieee802154_pkt_test *t) +{ + static uint8_t data_pkt[] = { + 0x61, 0xdc, 0x16, 0xcd, 0xab, 0x26, 0x11, 0x32, 0x00, 0x00, 0x4b, + 0x12, 0x00, 0x26, 0x18, 0x32, 0x00, 0x00, 0x4b, 0x12, 0x00, 0x7b, + 0x00, 0x3a, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x01, 0x0d, 0xb8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x87, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, + 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + 0x16, 0xf0, 0x02, 0xff, 0x16, 0xf0, 0x12, 0xff, 0x16, 0xf0, 0x32, + 0xff, 0x16, 0xf0, 0x00, 0xff, 0x16, 0xf0, 0x00, 0xff, 0x16 + }; + struct ieee802154_mpdu mpdu; + struct net_buf *buf, *frag; + + TC_PRINT("- Sending ACK reply to a data packet\n"); + + buf = net_nbuf_get_reserve_rx(0); + frag = net_nbuf_get_reserve_rx(0); + + memcpy(frag->data, data_pkt, sizeof(data_pkt)); + frag->len = sizeof(data_pkt); + + net_buf_frag_add(buf, frag); + + net_recv_data(iface, buf); + + nano_sem_take(&driver_lock, MSEC(20)); + + /* an ACK packet should be in current_buf */ + if (!current_buf) { + TC_ERROR("*** No ACK reply sent\n"); + return TC_FAIL; + } + + pkt_hexdump(net_nbuf_ll(current_buf), net_buf_frags_len(current_buf)); + + if (!ieee802154_validate_frame(net_nbuf_ll(current_buf), + net_buf_frags_len(current_buf), &mpdu)) { + TC_ERROR("*** ACK Reply is invalid\n"); + return TC_FAIL; + } + + if (memcmp(mpdu.mhr.fs, t->mhr_check.fc_seq, + sizeof(struct ieee802154_fcf_seq))) { + TC_ERROR("*** ACK Reply does not compare\n"); + return TC_FAIL; + } + + return TC_PASS; +} + static inline int initialize_test_environment(void) { struct device *dev; @@ -203,6 +267,14 @@ void main(void) goto end; } + if (test_packet_parsing(&test_ack_pkt) != TC_PASS) { + goto end; + } + + if (test_ack_reply(&test_ack_pkt) != TC_PASS) { + goto end; + } + status = TC_PASS; end: