Handle received packets
This commit is contained in:
parent
a07ffa265e
commit
f0770baf31
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#define SEQ_NR_MASK 0xF
|
#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->last_acked_seq = 0;
|
||||||
ctx->next_expected_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->my_addr = *my_addr;
|
||||||
ctx->peer_addr = *peer_addr;
|
ctx->peer_addr = *peer_addr;
|
||||||
|
|
||||||
|
ctx->data_cb = data_cb;
|
||||||
|
|
||||||
ctx->conn_state = CONN_STATE_INITIALIZED;
|
ctx->conn_state = CONN_STATE_INITIALIZED;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|
|
@ -50,9 +50,10 @@ typedef struct connection_ctx_s {
|
||||||
* \param ctx The connection context to initialize.
|
* \param ctx The connection context to initialize.
|
||||||
* \param my_addr The local link layer address.
|
* \param my_addr The local link layer address.
|
||||||
* \param peer_addr The remote 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.
|
* \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.
|
/*!\brief Destroy the given layer 2 connection context.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// initialize the console logger
|
// initialize the console logger
|
||||||
|
@ -146,7 +157,7 @@ int main(int argc, char **argv)
|
||||||
ham64_t my_address, peer_address;
|
ham64_t my_address, peer_address;
|
||||||
ham64_encode(MY_CALL, &my_address);
|
ham64_encode(MY_CALL, &my_address);
|
||||||
ham64_encode(PEER_CALL, &peer_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
|
// force connection into the established state
|
||||||
l2conn.conn_state = CONN_STATE_ESTABLISHED;
|
l2conn.conn_state = CONN_STATE_ESTABLISHED;
|
||||||
|
@ -207,8 +218,6 @@ int main(int argc, char **argv)
|
||||||
pfd_bcast.fd = m_bcast_sock;
|
pfd_bcast.fd = m_bcast_sock;
|
||||||
pfd_bcast.events = POLLIN;
|
pfd_bcast.events = POLLIN;
|
||||||
|
|
||||||
unsigned rx_retries = 0;
|
|
||||||
|
|
||||||
double old = get_hires_time();
|
double old = get_hires_time();
|
||||||
size_t total_bytes = 0;
|
size_t total_bytes = 0;
|
||||||
double next_stats_print_time = old + 0.5;
|
double next_stats_print_time = old + 0.5;
|
||||||
|
@ -341,8 +350,6 @@ int main(int argc, char **argv)
|
||||||
old = new;
|
old = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_retries = 0;
|
|
||||||
|
|
||||||
fprintf(stderr, "r");
|
fprintf(stderr, "r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue