From a6d7e98db3277e8ed6ef6bfe7a680129377bc674 Mon Sep 17 00:00:00 2001 From: hackerman-kl Date: Tue, 2 Dec 2025 08:47:43 +0100 Subject: [PATCH] module-avb: milan: introducing controller deregister unsolicited notification --- src/modules/meson.build | 1 + ...cmd-deregister-unsolicited-notifications.c | 68 +++++++++++++++++++ ...cmd-deregister-unsolicited-notifications.h | 23 +++++++ 3 files changed, 92 insertions(+) create mode 100644 src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.c create mode 100644 src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.h diff --git a/src/modules/meson.build b/src/modules/meson.build index cd6024e0b..bafcce1de 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -739,6 +739,7 @@ if build_module_avb 'module-avb/aecp-aem-cmds-resps/cmd-lock-entity.c', 'module-avb/aecp-aem-cmds-resps/cmd-available.c', 'module-avb/aecp-aem-cmds-resps/cmd-register-unsolicited-notifications.c', + 'module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.c', 'module-avb/es-builder.c', 'module-avb/avdecc.c', 'module-avb/maap.c', diff --git a/src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.c b/src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.c new file mode 100644 index 000000000..37a4f5f96 --- /dev/null +++ b/src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.c @@ -0,0 +1,68 @@ +/* AVB support */ +/* SPDX-FileCopyrightText: Copyright © 2025 Kebag-Logic */ +/* SPDX-FileCopyrightText: Copyright © 2025 Alex Malki */ +/* SPDX-FileCopyrightText: Copyright © 2025 Simon Gapp */ +/* SPDX-License-Identifier: MIT */ + +#include +#include + +#include "../aecp-aem.h" +#include "../aecp-aem-state.h" +#include "../aecp-aem-milan.h" + +#include "cmd-deregister-unsolicited-notifications.h" +#include "cmd-resp-helpers.h" + +int handle_cmd_deregister_unsol_notif_milan_v12(struct aecp *aecp, int64_t now, + const void *m, int len) +{ + const struct avb_ethernet_header *h = m; + const struct avb_packet_aecp_aem *p = SPA_PTROFF(h, sizeof(*h), void); + struct descriptor *desc; + struct aecp_aem_entity_milan_state *entity_state; + struct aecp_aem_unsol_notification_state *unsol; + uint64_t controller_id = htobe64(p->aecp.controller_guid); + const uint32_t ctrler_max = AECP_AEM_MILAN_MAX_CONTROLLER; + uint16_t index; + + desc = server_find_descriptor(aecp->server, AVB_AEM_DESC_ENTITY, 0); + if (desc == NULL) + return reply_status(aecp, AVB_AECP_AEM_STATUS_NO_SUCH_DESCRIPTOR, p, len); + + entity_state = (struct aecp_aem_entity_milan_state *) desc->ptr; + unsol = entity_state->unsol_notif_state; + + /** First check if the controller was already registered */ + for (index = 0; index < ctrler_max; index++) { + uint64_t ctrl_eid = unsol[index].ctrler_entity_id; + bool ctrler_reged = unsol[index].is_registered; + + if ((ctrl_eid == controller_id) && ctrler_reged) { + pw_log_debug("controller 0x%"PRIx64", already registered", + controller_id); + return reply_success(aecp, m, len); + } + } + + /** When one slot is in the array is available use it */ + for (index = 0; index < ctrler_max; index++) { + if (!unsol[index].is_registered) { + break; + } + } + + /** Reach the maximum controller allocated */ + if (index == ctrler_max) { + return reply_no_resources(aecp, m, len); + } + + unsol[index].ctrler_entity_id = controller_id; + memcpy(unsol[index].ctrler_mac_addr, h->src, sizeof(h->src)); + unsol[index].is_registered = true; + unsol[index].port_id = 0; + unsol[index].next_seq_id = 0; + + pw_log_info("Unsol registration for 0x%"PRIx64, controller_id); + return reply_success(aecp, m, len); +} diff --git a/src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.h b/src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.h new file mode 100644 index 000000000..e4372bfa6 --- /dev/null +++ b/src/modules/module-avb/aecp-aem-cmds-resps/cmd-deregister-unsolicited-notifications.h @@ -0,0 +1,23 @@ +/* AVB support */ +/* SPDX-FileCopyrightText: Copyright © 2025 Kebag-Logic */ +/* SPDX-FileCopyrightText: Copyright © 2025 Alex Malki */ +/* SPDX-FileCopyrightText: Copyright © 2025 Simon Gapp */ +/* SPDX-License-Identifier: MIT */ + +#ifndef __AVB_DEREGISTER_UNSOLICITED_NOTIFICATIONS_H__ +#define __AVB_DEREGISTER_UNSOLICITED_NOTIFICATIONS_H__ + +#include + +/** + * @brief Command handling will generate the response to the + * received command when deregistering the a controller from + * the list of subscribed controller entities. + * + * @see IEEE1722.1-2021 Section 7.4.38 . + * @see Milan V1.2 Section 5.4.2.22. + */ +int handle_cmd_deregister_unsol_notif_milan_v12(struct aecp *aecp, int64_t now, + const void *m, int len); + +#endif // __AVB_DEREGISTER_UNSOLICITED_NOTIFICATIONS_H__