ptpv2.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2024 The Apache Software Foundation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD
  7. */
  8. /****************************************************************************
  9. * apps/netutils/ptpd/ptpv2.h
  10. *
  11. * Licensed to the Apache Software Foundation (ASF) under one or more
  12. * contributor license agreements. See the NOTICE file distributed with
  13. * this work for additional information regarding copyright ownership. The
  14. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  15. * "License"); you may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  23. * License for the specific language governing permissions and limitations
  24. * under the License.
  25. *
  26. ****************************************************************************/
  27. #ifndef __APPS_NETUTILS_PTPD_PTPV2_H
  28. #define __APPS_NETUTILS_PTPD_PTPV2_H
  29. /****************************************************************************
  30. * Included Files
  31. ****************************************************************************/
  32. #include <stdint.h>
  33. /****************************************************************************
  34. * Pre-processor Definitions
  35. ****************************************************************************/
  36. /* Time-critical messages (id < 8) are sent to port 319,
  37. * other messages to port 320.
  38. */
  39. #define PTP_UDP_PORT_EVENT 319
  40. #define PTP_UDP_PORT_INFO 320
  41. /* Multicast address to send to: 224.0.1.129 */
  42. #define PTP_MULTICAST_ADDR ((in_addr_t)0xE0000181)
  43. /* Message types */
  44. #define PTP_MSGTYPE_MASK 0x0F
  45. #define PTP_MSGTYPE_SYNC 0
  46. #define PTP_MSGTYPE_DELAY_REQ 1
  47. #define PTP_MSGTYPE_FOLLOW_UP 8
  48. #define PTP_MSGTYPE_DELAY_RESP 9
  49. #define PTP_MSGTYPE_ANNOUNCE 11
  50. /* Message flags */
  51. #define PTP_FLAGS0_TWOSTEP (1 << 1)
  52. /****************************************************************************
  53. * Public Types
  54. ****************************************************************************/
  55. /* Defined in IEEE 1588-2008 Precision Time Protocol
  56. * All multi-byte fields are big-endian.
  57. */
  58. /* Common header for all message types */
  59. struct ptp_header_s
  60. {
  61. uint8_t messagetype;
  62. uint8_t version;
  63. uint8_t messagelength[2];
  64. uint8_t domain;
  65. uint8_t reserved1;
  66. uint8_t flags[2];
  67. uint8_t correction[8];
  68. uint8_t reserved2[4];
  69. uint8_t sourceidentity[8];
  70. uint8_t sourceportindex[2];
  71. uint8_t sequenceid[2];
  72. uint8_t controlfield;
  73. uint8_t logmessageinterval;
  74. };
  75. /* Announce a master clock */
  76. struct ptp_announce_s
  77. {
  78. struct ptp_header_s header;
  79. uint8_t origintimestamp[10];
  80. uint8_t utcoffset[2];
  81. uint8_t reserved;
  82. uint8_t gm_priority1;
  83. uint8_t gm_quality[4];
  84. uint8_t gm_priority2;
  85. uint8_t gm_identity[8];
  86. uint8_t stepsremoved[2];
  87. uint8_t timesource;
  88. };
  89. /* Sync: transmit timestamp from master clock */
  90. struct ptp_sync_s
  91. {
  92. struct ptp_header_s header;
  93. uint8_t origintimestamp[10];
  94. };
  95. /* FollowUp: actual timestamp of when sync message was sent */
  96. struct ptp_follow_up_s
  97. {
  98. struct ptp_header_s header;
  99. uint8_t origintimestamp[10];
  100. };
  101. /* DelayReq: request delay measurement */
  102. struct ptp_delay_req_s
  103. {
  104. struct ptp_header_s header;
  105. uint8_t origintimestamp[10];
  106. };
  107. /* DelayResp: response to DelayReq */
  108. struct ptp_delay_resp_s
  109. {
  110. struct ptp_header_s header;
  111. uint8_t receivetimestamp[10];
  112. uint8_t reqidentity[8];
  113. uint8_t reqportindex[2];
  114. };
  115. #endif /* __APPS_NETUTILS_PTPD_PTPV2_H */