test_connection: complete verification of the connection request packet
All checks were successful
/ build-hamnet70 (push) Successful in 39s
/ build-doc (push) Successful in 21s
/ deploy-doc (push) Has been skipped

This commit is contained in:
Thomas Kolb 2025-02-22 16:17:33 +01:00
commit d4f101793b

View file

@ -1,6 +1,10 @@
#include <stdio.h>
#include <string.h>
#include "layer2/packet_queue.h"
#include "layer2/packet_structs.h"
#include <stdio.h>
#include "utils.h"
#include "config.h"
#define LOGGER_MODULE_NAME "testconn"
#include "logger.h"
@ -53,6 +57,8 @@ int main(void)
LOG(LVL_INFO, "Hello World!");
unsigned int crc_size = crc_sizeof_key(PAYLOAD_CRC_SCHEME);
expected_state_t expected_state = {
.conn_state = CONN_STATE_INITIALIZED,
};
@ -106,8 +112,8 @@ int main(void)
header.tx_seq_nr = 0;
header.tx_request = 1;
uint8_t payload[256] = {CONN_MGMT_TYPE_BEACON};
packet_len = layer2_encode_packet(&header, payload, 1, packet_buf, sizeof(packet_buf));
uint8_t static_payload[256] = {CONN_MGMT_TYPE_BEACON};
packet_len = layer2_encode_packet(&header, static_payload, 1, packet_buf, sizeof(packet_buf));
ASSERT_EQUAL_UINT(11, packet_len);
ASSERT_RESULT(OK, connection_handle_packet(&conn, packet_buf, packet_len, &data_packet, &tx_req_rcvd));
@ -122,4 +128,32 @@ int main(void)
ASSERT_EQUAL_UINT(13, packet_len);
ASSERT_TRUE(end_burst);
// verify the CRC was appended correctly
bool crc_ok = crc_check_key(PAYLOAD_CRC_SCHEME, (unsigned char*)packet_buf, packet_len - crc_size);
ASSERT_TRUE(crc_ok);
// check that the header can be decoded and check the message type
memset(&header, 0, sizeof(header));
bool header_decoded_ok = layer2_decode_packet_header(packet_buf, packet_len, &header);
LOG(LVL_DUMP, "Header of supposed connection request packet:");
layer2_dump_packet_header(LVL_DUMP, &header);
ASSERT_TRUE(header_decoded_ok);
ASSERT_EQUAL_UINT(L2_MSG_TYPE_CONN_MGMT, header.msg_type);
// extract and check the payload
size_t header_size = layer2_get_encoded_header_size(&header);
size_t payload_len = packet_len - header_size - crc_size;
uint8_t *payload = packet_buf + header_size;
LOG(LVL_DUMP, "Payload of supposed connection request packet:");
hexdump(payload, payload_len);
// verify the payload length is 1 byte
ASSERT_EQUAL_UINT(1, payload_len);
// check the connection request type
ASSERT_EQUAL_UINT(CONN_MGMT_TYPE_CONNECTION_REQUEST, packet_buf[header_size]);
}