Commit 79f423b5 authored by Davide Ciminaghi's avatar Davide Ciminaghi Committed by Alessandro Rubini

fsm: introduce leave_current_state()

This gets us ready for leaving a state as a consequence of filtered out
messages (9.5.2.3: discard announce AND switch state to PASSIVE).
parent d2b2c636
......@@ -81,6 +81,21 @@ get_current_state_table_item(struct pp_instance *ppi)
return out;
}
/*
* Returns delay to next state, which is always zero.
*/
static int leave_current_state(struct pp_instance *ppi)
{
ppi->state = ppi->next_state;
ppi->is_new_state = 1;
pp_timeout_setall(ppi);
ppi->flags &= ~PPI_FLAGS_WAITING;
pp_diag_fsm(ppi, ppi->current_state_item->name, STATE_LEAVE, 0);
ppi->current_state_item = NULL;
/* next_delay unused: go to new state now */
return 0;
}
/*
* This is the state machine code. i.e. the extension-independent
* function that runs the machine. Errors are managed and reported
......@@ -139,15 +154,9 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
ppi->port_name, err, ip->name);
/* done: if new state mark it, and enter it now (0 ms) */
if (ppi->state != ppi->next_state) {
ppi->state = ppi->next_state;
ppi->is_new_state = 1;
pp_timeout_setall(ppi);
ppi->flags &= ~PPI_FLAGS_WAITING;
pp_diag_fsm(ppi, ip->name, STATE_LEAVE, 0);
ppi->current_state_item = NULL;
return 0; /* next_delay unused: go to new state now */
}
if (ppi->state != ppi->next_state)
return leave_current_state(ppi);
ppi->is_new_state = 0;
pp_diag_fsm(ppi, ip->name, STATE_LOOP, 0);
return ppi->next_delay;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment