Skip to content

WIP: Avb ptp management#98

Draft
ntonnaett wants to merge 12 commits intokebag-logic:masterfrom
ntonnaett:avb-ptp-management
Draft

WIP: Avb ptp management#98
ntonnaett wants to merge 12 commits intokebag-logic:masterfrom
ntonnaett:avb-ptp-management

Conversation

@ntonnaett
Copy link
Copy Markdown

@ntonnaett ntonnaett commented Jan 14, 2026

This adds a new gptp object. It periodically checks the ptp management unix socket.

It should help us getting information of the ptp status, if it's locked, grandmaster changes, etc.

TODO:

  • gPTP request packet instead of PTPv2
  • Test that it works
  • Add events like "gm_changed"

}

uint8_t buf[sizeof(struct ptp_management_msg) + sizeof(struct ptp_parent_data_set)];
if (read(gptp->ptp_fd, &buf, sizeof(buf)) == -1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should verify that the whole size was actually read:

https://man7.org/linux/man-pages/man2/read.2.html

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails now if the response is incomplete. Maybe I should wait for the rest in some way? Not sure how to do that in a nice way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check if my change to read the buffer until it's complete is correct?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's wrong...


ioctl(gptp->ptp_fd, FIONREAD, &avail);
pw_log_debug("Flushing stale data: %u bytes", avail);
while (avail-- && read(gptp->ptp_fd, &tmp, 1));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if read return -1?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it should fail.

req.management_message_length_be = htobe16(2);
req.management_id_be = htobe16(PTP_MGMT_ID_PARENT_DATA_SET);

if (write(gptp->ptp_fd, &req, sizeof(req)) == -1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should verify that the whole data is written.

https://man7.org/linux/man-pages/man2/write.2.html

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✓

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the event of a partial write, the
caller can make another write() call to transfer the remaining
bytes. The subsequent call will either transfer further bytes or
may result in an error (e.g., if the disk is now full).

Does this mean that I just repeat the same write() although I don't want to write the part that was already written? Is it magic?

int avail;
uint8_t tmp;

ioctl(gptp->ptp_fd, FIONREAD, &avail);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check return is valid

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✓

if ((res = setup_socket(server)) < 0)
goto error_free;

server->gptp = avb_gptp_new(server);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check for whether the return value is NULL

str = pw_properties_get(impl->props, "ptp.management-socket");
gptp->ptp_mgmt_socket_path = str ? strdup(str) : NULL;

if(gptp->ptp_mgmt_socket_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize in this case write an error, and stop everything, as it is a crucial element to continue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. In the rtp-sap module the management socket thing is optional. Should we require the usage of the management socket? The management socket is optional in the PTP standards AFAIK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants