This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 9fdf62935bb7d78126beced60e82e389d0134093
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Thu Sep 10 22:46:17 2026 -0300

    netutils/ptpd: add diagnostic logging for RX and Delay_Resp checks
    
    Add ptpinfo()/ptpwarn() calls, gated by the existing
    CONFIG_DEBUG_PTP_INFO/_WARN symbols (zero cost when disabled), at
    points that previously failed silently: an unrecognized L2 protocol,
    a domain mismatch, and a Delay_Resp rejected by the source/requester
    identity check. These were essential to diagnosing the drift and
    Delay_Req bugs fixed in the two preceding commits on real hardware,
    and are kept for future maintainers debugging this path.
    
    Assisted-by: Claude:claude-sonnet-5
    Assisted-by: Gemini:gemini-3.8-flash-medium
    Signed-off-by: Daniel P. Carvalho <[email protected]>
---
 netutils/ptpd/ptpd.c | 93 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 36 deletions(-)

diff --git a/netutils/ptpd/ptpd.c b/netutils/ptpd/ptpd.c
index bf0fe9189..d75acca97 100644
--- a/netutils/ptpd/ptpd.c
+++ b/netutils/ptpd/ptpd.c
@@ -1360,15 +1360,20 @@ static int ptp_process_delay_resp(FAR struct 
ptp_state_s *state,
   uint16_t sequence;
   int interval;
   int64_t max_path_delay;
+  bool source_match;
+  bool request_match;
 
-  if (!state->selected_source_valid ||
-      memcmp(msg->header.sourceidentity,
-             state->selected_source.header.sourceidentity,
-             sizeof(msg->header.sourceidentity)) != 0 ||
-      memcmp(msg->reqidentity,
-             state->own_identity.header.sourceidentity,
-             sizeof(msg->reqidentity)) != 0)
+  source_match = memcmp(msg->header.sourceidentity,
+                        state->selected_source.header.sourceidentity,
+                        sizeof(msg->header.sourceidentity)) == 0;
+  request_match = memcmp(msg->reqidentity,
+                         state->own_identity.header.sourceidentity,
+                         sizeof(msg->reqidentity)) == 0;
+
+  if (!state->selected_source_valid || !source_match || !request_match)
     {
+      ptpwarn("Delay_Resp ignored: valid=%d, src_match=%d, req_match=%d\n",
+              state->selected_source_valid, source_match, request_match);
       return OK; /* This packet wasn't for us */
     }
 
@@ -1454,6 +1459,8 @@ static int ptp_process_rx_packet(FAR struct ptp_state_s 
*state,
 
       if (htons(header->h_proto) != ETHERTYPE_PTP)
         {
+          ptpwarn("RX dropped: non-PTP proto 0x%04x (expected 0x%04x)\n",
+                  ntohs(header->h_proto), ETHERTYPE_PTP);
           return -EINVAL;
         }
 
@@ -1468,8 +1475,20 @@ static int ptp_process_rx_packet(FAR struct ptp_state_s 
*state,
       return OK;
     }
 
+  ptpinfo("RX PTP: type=0x%02x (masked: 0x%02x), ver=0x%02x, domain=%d, "
+          "seq=%d, len=%zd\n",
+          state->rxbuf.header.messagetype,
+          state->rxbuf.header.messagetype & PTP_MSGTYPE_MASK,
+          state->rxbuf.header.version,
+          state->rxbuf.header.domain,
+          ptp_get_sequence(&state->rxbuf.header),
+          length);
+
   if (state->rxbuf.header.domain != CONFIG_NETUTILS_PTPD_DOMAIN)
     {
+      ptpwarn("RX dropped: domain mismatch %d != %d\n",
+              state->rxbuf.header.domain, CONFIG_NETUTILS_PTPD_DOMAIN);
+
       /* Part of different clock domain, ignore */
 
       return OK;
@@ -1479,35 +1498,37 @@ static int ptp_process_rx_packet(FAR struct ptp_state_s 
*state,
 
   switch (state->rxbuf.header.messagetype & PTP_MSGTYPE_MASK)
     {
-    case PTP_MSGTYPE_ANNOUNCE:
-      ptpinfo("Got announce packet, seq %ld\n",
-              (long)ptp_get_sequence(&state->rxbuf.header));
-      return ptp_process_announce(state, &state->rxbuf.announce);
-
-    case PTP_MSGTYPE_SYNC:
-      ptpinfo("Got sync packet, seq %ld\n",
-              (long)ptp_get_sequence(&state->rxbuf.header));
-      return ptp_process_sync(state, &state->rxbuf.sync);
-
-    case PTP_MSGTYPE_FOLLOW_UP:
-      ptpinfo("Got follow-up packet, seq %ld\n",
-              (long)ptp_get_sequence(&state->rxbuf.header));
-      return ptp_process_followup(state, &state->rxbuf.follow_up);
-
-    case PTP_MSGTYPE_DELAY_RESP:
-      ptpinfo("Got delay-resp, seq %ld\n",
-              (long)ptp_get_sequence(&state->rxbuf.header));
-      return ptp_process_delay_resp(state, &state->rxbuf.delay_resp);
-
-    case PTP_MSGTYPE_DELAY_REQ:
-      ptpinfo("Got delay req, seq %ld\n",
-              (long)ptp_get_sequence(&state->rxbuf.header));
-      return ptp_process_delay_req(state, &state->rxbuf.delay_req);
-
-    default:
-      ptpinfo("Ignoring unknown PTP packet type: 0x%02x\n",
-              state->rxbuf.header.messagetype);
-      return OK;
+      case PTP_MSGTYPE_ANNOUNCE:
+        ptpinfo("Got announce packet, seq %d\n",
+                ptp_get_sequence(&state->rxbuf.header));
+        return ptp_process_announce(state, &state->rxbuf.announce);
+
+      case PTP_MSGTYPE_SYNC:
+        ptpinfo("Got sync packet, seq %d\n",
+                ptp_get_sequence(&state->rxbuf.header));
+        return ptp_process_sync(state, &state->rxbuf.sync);
+
+      case PTP_MSGTYPE_FOLLOW_UP:
+        ptpinfo("Got follow-up packet, seq %d\n",
+                ptp_get_sequence(&state->rxbuf.header));
+        return ptp_process_followup(state, &state->rxbuf.follow_up);
+
+      case PTP_MSGTYPE_DELAY_RESP:
+        ptpinfo("Got delay-resp, seq %d\n",
+                ptp_get_sequence(&state->rxbuf.header));
+        return ptp_process_delay_resp(state, &state->rxbuf.delay_resp);
+
+      case PTP_MSGTYPE_DELAY_REQ:
+        ptpinfo("Got delay req, seq %d\n",
+                ptp_get_sequence(&state->rxbuf.header));
+        return ptp_process_delay_req(state, &state->rxbuf.delay_req);
+
+      default:
+        ptpwarn("Ignoring unknown PTP packet type: 0x%02x "
+                "(masked: 0x%02x)\n",
+                state->rxbuf.header.messagetype,
+                state->rxbuf.header.messagetype & PTP_MSGTYPE_MASK);
+        return OK;
     }
 }
 

Reply via email to