Commit graph

31 commits

Author SHA1 Message Date
Pisit Sawangvonganan
10f495e0fd net: lib: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/lib` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-12 09:33:20 -04:00
Benjamin Cabé
1f0c22eb01 net: ptp: fix incorrect req_timestamp decoding
Removed incorrect use of ntoh to decode Delay_Req timestamp

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-07-01 18:13:42 +02:00
Benjamin Cabé
a89a5ee52d net: ptp: fix offset check by adding missing int64_t cast
Add cast to NSEC_PER_SEC macro to correctly check offset.
Prior to this commit, the would eval to true incorrectly.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-07-01 18:13:42 +02:00
Adam Wojasinski
3b78e76554 net: lib: ptp: Fix issues raised by static analyzer
Fix minor issues reported by static analysis tool.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-27 08:48:59 -04:00
Chris Friedt
72bd951ac4 net: ptp: do not use a reserved id in global scope
Generally, we should avoid using reserved names in global
contexts.

subsys/net/lib/ptp/clock.c:58:25: \
  error: 'clock' redeclared as different kind of symbol
   58 | static struct ptp_clock clock = { 0 };

/opt/toolchains/zephyr-sdk-0.16.8/arm-zephyr-eabi/picolibc/ \
  include/time.h💯12: \
  note: previous declaration of 'clock' with type 'clock_t(void)' \
  {aka 'long unsigned int(void)'}
  100 | clock_t    clock (void);

subsys/net/lib/ptp/clock.c:58:25: \
  error: 'clock' defined but not used [-Werror=unused-variable]
   58 | static struct ptp_clock clock = { 0 };

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-18 19:54:53 -04:00
Adam Wojasinski
08689e1a20 net: ptp: Network interface status check in PTP thread
Adding network interface status monitor function. Depending
on the interface operation state and change of the state
events are generated and handled by the function.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
28111ba254 net: ptp: Implement PTP thread
This commit adds implementation of the PTP thread that will
poll sockets descriptors and PTP Port's timeres for timeouts,
generate events and handle them and trigger STATE_DECISION_EVENT
handling when needed.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
db07aa2c00 net: ptp: Add handler for STATE_DECISION_EVENT
The STATE_DECISION_EVENT in PTP is a pivotal mechanism that
facilitates dynamic state management within the protocol,
allowing devices to adapt their operational states based on the BTCA's
recommendations and the health of the network.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
edfe4cd8cc net: ptp: Add event generation and event handler for PTP Port
Introduction of PTP stack's core functions responsible for
event generation and handling of these events. Events are generated
base on timeouts and/or PTP messages received via BSD sockets
assigned to a specific PTP Port. These function will be used
in PTP thread.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
f22f36dd90 net: ptp: Implement PTP Port enabling and disabling functions
The commit adds functions that enable and disable PTP Port.
This is going to be used by event handling routine.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
e14e878084 net: ptp: Add timers processing for PTP Port
Timers are used to trigger message transmission and detect
inactivity of other PTP Clocks what should result in an action
of the PTP Port.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
73eaab29a0 net: ptp: Add functions for messages transmission
This commit introduces routines for PTP message transmission.
It includes transmission of three types of messages (Announce,
Sync, Delay_Req) that should be send periodically depending
on the PTP Port's state.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
cb35cc919a net: ptp: Add management message processing
Introduction of routines processing received PTP Management messages.
The processing is split into clock-oriented and port-oriented parts.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
fe0cc7dd26 net: ptp: Implement Best TimeTransmitter Clock algorithm for PTP stack
Add handler for STATE_DECISION_EVENT it consists of following routines:
- state decision algorithm
- best timeTransmitter clock algorithm
- data sets comparison algorithm

Based on IEEE 1588-2019 section 9.3.3

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
577e58cb17 net: ptp: Implement PTP message processing for ports
This commit adds routines for handling incoming messages
needed for correct operation of the PTP stack in end to end
mode with multicast operation mode.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
5c4be2be8c net: ptp: Introduce routines for PTP Hardware Clock adjustment
Initial implementation of the clock adjustment and delay calculation.
Timestamp values used for calculations will be obtained from
proper PTP messages (Sync, Follow_Up, Delay_Req, and Delay_Resp)

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
9aabe2e477 net: ptp: Add foreign timeTransmitter records
Foreign timeTransmitters are other PTP Clocks in a domain. They announce
their parameters via announce messages. PTP Ports should record
these foreign timeTransmitters.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
0575a500ce net: ptp: Add PTP Port ID comparison function
Based on Port ID decision about message processing can be made.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
3d7dd0d6fa net: ptp: Add sockets to PTP stack
This commit introduces module responsible for sending and receiving
messages. It is based on BSD Sockets API.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
8016fa1de1 net: ptp: Extend TLV with Management TLVs
This commit adds handling of Management TLVs

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
806ba0dcd3 net: ptp: Add TLV extension to PTP
Add allocation of container used for TLVs and dummy functions for
preparing correct byte order of data. TLV stands for Type, Length,
Value, and it is extension of PTP messages that's used to transmit
extra information. This data is attached at the end of PTP message.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
8f00c5f4de net: ptp: Add byte order manipulation for PTP messages
Add functions preparing messages to network byte order before sending
and changing to host byte order after reception and before processing
by PTP stack.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
e17cf5868d net: ptp: Add PTP message allocation and management
Add dynamic memory allocation for PTP messages. Memory allocation
is done with Zephyr's memory slab. It's size can be configured
with `PTP_MSG_POLL_SIZE` Kconfig symbol.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
7e45be1bf2 net: ptp: Add definition of PTP messages types
Introduces definition of structures for all types of PTP messages
defined in the IEEE 1588-2019 standard.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
af09e4abfb net: ptp: Add Kconfig symbols and preprocessor guards for some states
Based on IEEE 1588-2019 some of PTP Port states might not be used
if the option of 17.7 is implemented. This patch prepares state
machine implementation for such scenario.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
2e7dbf1091 net: ptp: Add TIME_RECEIVER_ONLY feature
Implement possibility to configure PTP stack in TIME_RECEIVER_ONLY mode.
This restrics stack behaviour and doesn't allow for any PTP Port
of the PTP Clock become a TimeTransmitter Clock.

The change includes:
- Kconfig option
- Additional field in `struct ptp_port` structure
- New state machine function for a timeReceiver-only PTP Port.
- Extra steps in PTP Clock and PTP Port initialization.

New finite state machine is based on the figure 31
in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
74a25772c5 net: ptp: Add PTP Clock and PTP Port initialization
This commit introduces PTP Clock and PTP Port structures
and API for initializing PTP Clock and PTP Ports. Configuration
options has been added as Kconfig symbols to configure parameters
of the Clock and Ports at compile time.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
70e3183c40 net: ptp: Add definitions for PTP datasets
Datasets defined in the header file are going to be used
in PTP Clock's structure and PTP Port's structure. They
gather data into structures defined in IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
424c3706d1 net: ptp: Add finite state machine implementation for PTP stack
The patch brings implementationof a state machine for full
PTP implementation. It returns new PTP Port's state based
on event that occured and previous state.

Based on the figure 30 in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
6a40371790 net: ptp: Add derived data type header
The header's file content is based on 5.3 section of
the IEEE 1588-2019 standard describing Precise Time Protocol (PTP)
used to synchronize devices in the network.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski
58a611d814 net: ptp: Initial PTP library implementation
This is an initial commit that introduces PTP library in the Zephyr.
It adds basic Kconfig symbols for enabling library, CMakeLists.txt
for compiling it, public header file, and initial PTP thread definition
and library initialization. Implementation of the functional PTP stack
will be introduced in following commits.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00