Commit 168655e6 authored by Alessandro Rubini's avatar Alessandro Rubini

fsm: when no frame, set msgtype to PPM_NO_MESSAGE

This removes a number of explicit checks in the states themselves.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b0797a47
......@@ -198,6 +198,8 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
packet = NULL;
plen = 0;
}
if (!plen)
ppi->received_ptp_header.messageType = PPM_NO_MESSAGE;
state = ppi->state;
......
......@@ -86,7 +86,8 @@ static int wr_master_msg(struct pp_instance *ppi, unsigned char *pkt, int plen,
MsgSignaling wrsig_msg;
TimeInternal *time = &ppi->last_rcv_time;
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if (msgtype != PPM_NO_MESSAGE)
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
switch (msgtype) {
......
......@@ -31,9 +31,6 @@ int wr_calibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
return 0; /* non-wr */
}
if (plen == 0)
goto out;
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
&(wrp->msgTmpWrMessageID));
......@@ -46,7 +43,6 @@ int wr_calibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
ppi->next_state = WRS_WR_LINK_ON;
}
out:
ppi->next_delay = wrp->wrStateTimeout;
return 0;
}
......@@ -34,9 +34,6 @@ int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
e = msg_issue_wrsig(ppi, LOCKED);
}
if (plen == 0)
goto out;
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
......@@ -46,7 +43,6 @@ int wr_locked(struct pp_instance *ppi, unsigned char *pkt, int plen)
ppi->next_state = WRS_RESP_CALIB_REQ;
}
out:
if (e != 0)
ppi->next_state = PPS_FAULTY;
ppi->next_delay = wrp->wrStateTimeout;
......
......@@ -34,9 +34,6 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
__pp_timeout_set(ppi, PP_TO_EXT_0, WR_M_LOCK_TIMEOUT_MS);
}
if (plen == 0)
goto out;
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
......@@ -46,7 +43,6 @@ int wr_m_lock(struct pp_instance *ppi, unsigned char *pkt, int plen)
ppi->next_state = WRS_CALIBRATION;
}
out:
if (e != 0)
ppi->next_state = PPS_FAULTY;
ppi->next_delay = wrp->wrStateTimeout;
......
......@@ -38,9 +38,6 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
e = msg_issue_wrsig(ppi, SLAVE_PRESENT);
}
if (plen == 0)
goto out;
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
......@@ -50,7 +47,6 @@ int wr_present(struct pp_instance *ppi, unsigned char *pkt, int plen)
ppi->next_state = WRS_S_LOCK;
}
out:
if (e == 0)
st_com_execute_slave(ppi);
else
......
......@@ -35,9 +35,6 @@ int wr_resp_calib_req(struct pp_instance *ppi, unsigned char *pkt, int plen)
wrp->otherNodeCalPeriod / 1000);
}
if (plen == 0)
goto out;
if (ppi->received_ptp_header.messageType == PPM_SIGNALING) {
msg_unpack_wrsig(ppi, pkt, &wrsig_msg,
......@@ -53,7 +50,6 @@ int wr_resp_calib_req(struct pp_instance *ppi, unsigned char *pkt, int plen)
}
}
out:
ppi->next_delay = wrp->wrStateTimeout;
return e;
}
......@@ -22,9 +22,6 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
e = pp_lib_may_issue_request(ppi);
if (plen == 0)
goto out;
switch (ppi->received_ptp_header.messageType) {
case PPM_ANNOUNCE:
......
......@@ -65,9 +65,6 @@ int pp_master(struct pp_instance *ppi, uint8_t *pkt, int plen)
else /* please check commit '6d7bf7e3' about below, I'm not sure */
pp_timeout_set(ppi, PP_TO_REQUEST);
if (plen == 0)
goto out;
/*
* An extension can do special treatment of this message type,
* possibly returning error or eating the message by returning
......@@ -86,7 +83,7 @@ int pp_master(struct pp_instance *ppi, uint8_t *pkt, int plen)
/*
* The management of messages is now table-driven
*/
if (plen && msgtype < ARRAY_SIZE(actions)
if (msgtype < ARRAY_SIZE(actions)
&& actions[msgtype]) {
e = actions[msgtype](ppi, pkt, plen);
} else {
......
......@@ -17,9 +17,6 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
e = pp_lib_may_issue_request(ppi);
if (plen == 0)
goto no_incoming_msg;
switch (ppi->received_ptp_header.messageType) {
case PPM_ANNOUNCE:
......@@ -51,7 +48,6 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
}
no_incoming_msg:
if (e == 0)
e = st_com_execute_slave(ppi);
......
......@@ -95,7 +95,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
/*
* The management of messages is now table-driven
*/
if (plen && hdr->messageType < ARRAY_SIZE(actions)
if (hdr->messageType < ARRAY_SIZE(actions)
&& actions[hdr->messageType]) {
e = actions[hdr->messageType](ppi, pkt, plen);
} else {
......
......@@ -13,9 +13,6 @@ int pp_uncalibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0; /* error var, to check errors in msg handling */
if (plen == 0)
goto no_incoming_msg;
switch (ppi->received_ptp_header.messageType) {
case PPM_ANNOUNCE:
......@@ -35,7 +32,6 @@ int pp_uncalibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
}
no_incoming_msg:
if (e == 0)
e = st_com_execute_slave(ppi);
......
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