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