diff --git a/impl/src/layer2/connection.c b/impl/src/layer2/connection.c index 2c458e4..ab9d970 100644 --- a/impl/src/layer2/connection.c +++ b/impl/src/layer2/connection.c @@ -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; diff --git a/impl/src/layer2/connection.h b/impl/src/layer2/connection.h index 038105c..a10e627 100644 --- a/impl/src/layer2/connection.h +++ b/impl/src/layer2/connection.h @@ -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. */ diff --git a/impl/test/layer2_over_udp/l2udptest.c b/impl/test/layer2_over_udp/l2udptest.c index 21ac440..bf7d522 100644 --- a/impl/test/layer2_over_udp/l2udptest.c +++ b/impl/test/layer2_over_udp/l2udptest.c @@ -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"); } }