|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | NTP_PACKET_LEN 48u |
| One NTP packet on the wire is exactly 48 octets (no extension/auth fields). | |
| #define | NTP_UNIX_OFFSET 2208988800u |
| Seconds between the NTP epoch (1900-01-01) and the Unix epoch (1970-01-01). | |
| #define | NTP_REFID_LOCL 0x4C4F434Cu |
| Reference ID "LOCL" - an undisciplined local clock (RFC 5905 sec 7.3). | |
| #define | NTP_REFID_GPS 0x47505320u |
| Reference ID "GPS " - a GPS-disciplined reference clock (use with stratum 1). | |
Functions | |
| size_t | pc_ntp_server_build_response (const uint8_t *req, size_t req_len, uint8_t stratum, uint32_t refid, uint32_t pc_ntp_secs, uint32_t pc_ntp_frac, uint8_t *out, size_t out_cap) |
| Build a server (mode 4) reply to a client NTP request. Pure - no clock, no I/O. | |
| bool | pc_ntp_server_begin (uint8_t stratum, uint32_t refid=NTP_REFID_LOCL) |
| Start answering NTP requests on UDP/123 from the device's own clock. | |
| #define NTP_PACKET_LEN 48u |
One NTP packet on the wire is exactly 48 octets (no extension/auth fields).
Definition at line 31 of file ntp_server.h.
| #define NTP_UNIX_OFFSET 2208988800u |
Seconds between the NTP epoch (1900-01-01) and the Unix epoch (1970-01-01).
Definition at line 34 of file ntp_server.h.
| #define NTP_REFID_LOCL 0x4C4F434Cu |
Reference ID "LOCL" - an undisciplined local clock (RFC 5905 sec 7.3).
Definition at line 37 of file ntp_server.h.
| #define NTP_REFID_GPS 0x47505320u |
Reference ID "GPS " - a GPS-disciplined reference clock (use with stratum 1).
Definition at line 40 of file ntp_server.h.
| size_t pc_ntp_server_build_response | ( | const uint8_t * | req, |
| size_t | req_len, | ||
| uint8_t | stratum, | ||
| uint32_t | refid, | ||
| uint32_t | pc_ntp_secs, | ||
| uint32_t | pc_ntp_frac, | ||
| uint8_t * | out, | ||
| size_t | out_cap | ||
| ) |
Build a server (mode 4) reply to a client NTP request. Pure - no clock, no I/O.
Echoes the request's protocol version, copies the client's transmit timestamp into the response's origin field, and stamps the reference / receive / transmit times with (pc_ntp_secs, pc_ntp_frac). Leap indicator 0, root dispersion ~1 s (a coarse clock).
| req | the received request bytes. |
| req_len | length of req (must be >= NTP_PACKET_LEN). |
| stratum | stratum to advertise (1-15). |
| refid | reference identifier (e.g. NTP_REFID_LOCL). |
| pc_ntp_secs | current time, seconds since the NTP epoch (Unix seconds + NTP_UNIX_OFFSET). |
| pc_ntp_frac | sub-second fraction as a 32-bit binary fraction of a second. |
| out | output buffer. |
| out_cap | capacity of out (must be >= NTP_PACKET_LEN). |
| bool pc_ntp_server_begin | ( | uint8_t | stratum, |
| uint32_t | refid = NTP_REFID_LOCL |
||
| ) |
Start answering NTP requests on UDP/123 from the device's own clock.
Uses pc_time_now() for the seconds and pc_millis() for the sub-second fraction. While the device has no time (pc_time_now() returns 0) the server does not reply, so a client falls through to its next configured source rather than trusting an unset clock.
| stratum | the stratum to advertise (1 for a GPS/reference clock, 2-15 for a relay). |
| refid | the reference identifier to advertise (NTP_REFID_LOCL, NTP_REFID_GPS, ...). |