Handle received packets
Some checks failed
/ build-hamnet70 (push) Failing after 29s
/ build-doc (push) Successful in 16s
/ deploy-doc (push) Has been skipped

This commit is contained in:
Thomas Kolb 2024-09-22 15:34:50 +02:00
parent a07ffa265e
commit f0770baf31
3 changed files with 17 additions and 7 deletions

View file

@ -10,7 +10,7 @@
#define SEQ_NR_MASK 0xF
result_t connection_init(connection_ctx_t *ctx, const ham64_t *my_addr, const ham64_t *peer_addr)
result_t connection_init(connection_ctx_t *ctx, const ham64_t *my_addr, const ham64_t *peer_addr, connection_data_callback_t data_cb)
{
ctx->last_acked_seq = 0;
ctx->next_expected_seq = 0;
@ -22,6 +22,8 @@ result_t connection_init(connection_ctx_t *ctx, const ham64_t *my_addr, const ha
ctx->my_addr = *my_addr;
ctx->peer_addr = *peer_addr;
ctx->data_cb = data_cb;
ctx->conn_state = CONN_STATE_INITIALIZED;
return OK;

View file

@ -50,9 +50,10 @@ typedef struct connection_ctx_s {
* \param ctx The connection context to initialize.
* \param my_addr The local link layer address.
* \param peer_addr The remote link layer address.
* \param data_cb Callback for handling received payload data.
* \returns OK if everything worked or a fitting error code.
*/
result_t connection_init(connection_ctx_t *ctx, const ham64_t *my_addr, const ham64_t *peer_addr);
result_t connection_init(connection_ctx_t *ctx, const ham64_t *my_addr, const ham64_t *peer_addr, connection_data_callback_t data_cb);
/*!\brief Destroy the given layer 2 connection context.
*/

View file

@ -120,6 +120,17 @@ static result_t transmit(const uint8_t *data, size_t len)
}
void rx_data_to_tun(struct connection_ctx_s *conn, const uint8_t *data, size_t len)
{
(void)conn;
int ret = write(m_tunfd, data, len);
if(ret < 0) {
LOG(LVL_ERR, "write(tun): %s", strerror(errno));
}
}
int main(int argc, char **argv)
{
// initialize the console logger
@ -146,7 +157,7 @@ int main(int argc, char **argv)
ham64_t my_address, peer_address;
ham64_encode(MY_CALL, &my_address);
ham64_encode(PEER_CALL, &peer_address);
RESULT_CHECK(connection_init(&l2conn, &my_address, &peer_address));
RESULT_CHECK(connection_init(&l2conn, &my_address, &peer_address, rx_data_to_tun));
// force connection into the established state
l2conn.conn_state = CONN_STATE_ESTABLISHED;
@ -207,8 +218,6 @@ int main(int argc, char **argv)
pfd_bcast.fd = m_bcast_sock;
pfd_bcast.events = POLLIN;
unsigned rx_retries = 0;
double old = get_hires_time();
size_t total_bytes = 0;
double next_stats_print_time = old + 0.5;
@ -341,8 +350,6 @@ int main(int argc, char **argv)
old = new;
}
rx_retries = 0;
fprintf(stderr, "r");
}
}