mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-04-29 06:46:38 -04:00
milan-avb: preparing acmp state machine dividing between milan and legacy avb
This commit is contained in:
parent
d46523e6ad
commit
9ee0ddf24f
6 changed files with 378 additions and 0 deletions
122
src/modules/module-avb/acmp-cmds-resps/acmp-common.c
Normal file
122
src/modules/module-avb/acmp-cmds-resps/acmp-common.c
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
/* SPDX-FileCopyrightText: Copyright © 2026 Alexandre Malki <alexandre.malki@kebag-logic.com> */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include "acmp-common.h"
|
||||||
|
|
||||||
|
struct pending *pending_find(struct acmp *acmp, uint32_t type, uint16_t sequence_id)
|
||||||
|
{
|
||||||
|
struct pending *p;
|
||||||
|
spa_list_for_each(p, &acmp->pending[type], link)
|
||||||
|
if (p->sequence_id == sequence_id)
|
||||||
|
return p;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pending_free(struct acmp *acmp, struct pending *p)
|
||||||
|
{
|
||||||
|
spa_list_remove(&p->link);
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pending_destroy(struct acmp *acmp)
|
||||||
|
{
|
||||||
|
struct pending *p, *t;
|
||||||
|
for (uint32_t list_id = 0; list_id < PENDING_CONTROLLER; list_id++) {
|
||||||
|
spa_list_for_each_safe(p, t, &acmp->pending[list_id], link) {
|
||||||
|
pending_free(acmp, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pending_new(struct acmp *acmp, uint32_t type, uint64_t now, uint32_t timeout_ms,
|
||||||
|
const void *m, size_t size)
|
||||||
|
{
|
||||||
|
struct pending *p;
|
||||||
|
struct avb_ethernet_header *h;
|
||||||
|
struct avb_packet_acmp *pm;
|
||||||
|
|
||||||
|
p = calloc(1, sizeof(*p) + size);
|
||||||
|
if (p == NULL)
|
||||||
|
return NULL;
|
||||||
|
p->last_time = now;
|
||||||
|
p->timeout = timeout_ms * SPA_NSEC_PER_MSEC;
|
||||||
|
p->sequence_id = acmp->sequence_id[type]++;
|
||||||
|
p->size = size;
|
||||||
|
p->ptr = SPA_PTROFF(p, sizeof(*p), void);
|
||||||
|
memcpy(p->ptr, m, size);
|
||||||
|
|
||||||
|
h = p->ptr;
|
||||||
|
pm = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
p->old_sequence_id = ntohs(pm->sequence_id);
|
||||||
|
pm->sequence_id = htons(p->sequence_id);
|
||||||
|
spa_list_append(&acmp->pending[type], &p->link);
|
||||||
|
|
||||||
|
return p->ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct stream *find_stream(struct server *server, enum spa_direction direction,
|
||||||
|
uint16_t index)
|
||||||
|
{
|
||||||
|
uint16_t type;
|
||||||
|
struct descriptor *desc;
|
||||||
|
struct stream *stream;
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case SPA_DIRECTION_INPUT:
|
||||||
|
type = AVB_AEM_DESC_STREAM_INPUT;
|
||||||
|
break;
|
||||||
|
case SPA_DIRECTION_OUTPUT:
|
||||||
|
type = AVB_AEM_DESC_STREAM_OUTPUT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pw_log_error("Unkown direction\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
desc = server_find_descriptor(server, type, index);
|
||||||
|
if (!desc) {
|
||||||
|
pw_log_error("Could not find stream type %u index %u\n",
|
||||||
|
type, index);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case SPA_DIRECTION_INPUT:
|
||||||
|
struct aecp_aem_stream_input_state *stream_in;
|
||||||
|
stream_in = desc->ptr;
|
||||||
|
stream = &stream_in->stream;
|
||||||
|
break;
|
||||||
|
case SPA_DIRECTION_OUTPUT:
|
||||||
|
struct aecp_aem_stream_output_state *stream_out;
|
||||||
|
stream_out = desc->ptr;
|
||||||
|
stream = &stream_out->stream;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reply_not_supported(struct acmp *acmp, uint8_t type, const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
uint8_t buf[len];
|
||||||
|
struct avb_ethernet_header *h = (void*)buf;
|
||||||
|
struct avb_packet_acmp *reply = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
|
||||||
|
memcpy(h, m, len);
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(reply, type);
|
||||||
|
AVB_PACKET_ACMP_SET_STATUS(reply, AVB_ACMP_STATUS_NOT_SUPPORTED);
|
||||||
|
|
||||||
|
return avb_server_send_packet(server, h->src, AVB_TSN_ETH, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int retry_pending(struct acmp *acmp, uint64_t now, struct pending *p)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
struct avb_ethernet_header *h = p->ptr;
|
||||||
|
p->retry++;
|
||||||
|
p->last_time = now;
|
||||||
|
return avb_server_send_packet(server, h->dest, AVB_TSN_ETH, p->ptr, p->size);
|
||||||
|
}
|
||||||
34
src/modules/module-avb/acmp-cmds-resps/acmp-common.h
Normal file
34
src/modules/module-avb/acmp-cmds-resps/acmp-common.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* SPDX-FileCopyrightText: Copyright © 2026 Alexandre Malki <alexandre.malki@kebag-logic.com> */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#ifndef AVB_ACMP_COMMON_H
|
||||||
|
#define AVB_ACMP_COMMON_H
|
||||||
|
|
||||||
|
struct pending {
|
||||||
|
struct spa_list link;
|
||||||
|
uint64_t last_time;
|
||||||
|
uint64_t timeout;
|
||||||
|
uint16_t old_sequence_id;
|
||||||
|
uint16_t sequence_id;
|
||||||
|
uint16_t retry;
|
||||||
|
size_t size;
|
||||||
|
void *ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pending *pending_find(struct acmp *acmp, uint32_t type, uint16_t sequence_id);
|
||||||
|
|
||||||
|
void pending_free(struct acmp *acmp, struct pending *p);
|
||||||
|
|
||||||
|
void pending_destroy(struct acmp *acmp);
|
||||||
|
|
||||||
|
void *pending_new(struct acmp *acmp, uint32_t type, uint64_t now,
|
||||||
|
uint32_t timeout_ms, const void *m, size_t size)
|
||||||
|
|
||||||
|
int retry_pending(struct acmp *acmp, uint64_t now, struct pending *p):
|
||||||
|
|
||||||
|
struct stream *find_stream(struct server *server, enum spa_direction direction,
|
||||||
|
uint16_t index);
|
||||||
|
|
||||||
|
int reply_not_supported(struct acmp *acmp, uint8_t type, const void *m, int len);
|
||||||
|
|
||||||
|
#endif //AVB_ACMP_COMMON_H
|
||||||
201
src/modules/module-avb/acmp-cmds-resps/acmp-legacy-avb.c
Normal file
201
src/modules/module-avb/acmp-cmds-resps/acmp-legacy-avb.c
Normal file
|
|
@ -0,0 +1,201 @@
|
||||||
|
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans */
|
||||||
|
/* SPDX-FileCopyrightText: Copyright © 2026 Alexandre Malki <alexandre.malki@kebag-logic.com> */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
int handle_connect_tx_command_legacy_avb(struct acmp *acmp, uint64_t now,
|
||||||
|
const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
uint8_t buf[len];
|
||||||
|
struct avb_ethernet_header *h = (void*)buf;
|
||||||
|
struct avb_packet_acmp *reply = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
const struct avb_packet_acmp *p = SPA_PTROFF(m, sizeof(*h), void);
|
||||||
|
int status = AVB_ACMP_STATUS_SUCCESS;
|
||||||
|
struct stream *stream;
|
||||||
|
|
||||||
|
if (be64toh(p->talker_guid) != server->entity_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(buf, m, len);
|
||||||
|
stream = find_stream(server, SPA_DIRECTION_OUTPUT, ntohs(reply->talker_unique_id));
|
||||||
|
if (stream == NULL) {
|
||||||
|
status = AVB_ACMP_STATUS_TALKER_NO_STREAM_INDEX;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(reply, AVB_ACMP_MESSAGE_TYPE_CONNECT_TX_RESPONSE);
|
||||||
|
reply->stream_id = htobe64(stream->id);
|
||||||
|
|
||||||
|
stream_activate(stream, ntohs(reply->talker_unique_id), now);
|
||||||
|
|
||||||
|
memcpy(reply->stream_dest_mac, stream->addr, 6);
|
||||||
|
reply->connection_count = htons(1);
|
||||||
|
reply->stream_vlan_id = htons(stream->vlan_id);
|
||||||
|
|
||||||
|
done:
|
||||||
|
AVB_PACKET_ACMP_SET_STATUS(reply, status);
|
||||||
|
return avb_server_send_packet(server, h->dest, AVB_TSN_ETH, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_connect_tx_response_legacy_avb(struct acmp *acmp, uint64_t now,
|
||||||
|
const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
struct avb_ethernet_header *h;
|
||||||
|
const struct avb_packet_acmp *resp = SPA_PTROFF(m, sizeof(*h), void);
|
||||||
|
struct avb_packet_acmp *reply;
|
||||||
|
struct pending *pending;
|
||||||
|
uint16_t sequence_id;
|
||||||
|
struct stream *stream;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if (be64toh(resp->listener_guid) != server->entity_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
sequence_id = ntohs(resp->sequence_id);
|
||||||
|
|
||||||
|
pending = pending_find(acmp, PENDING_TALKER, sequence_id);
|
||||||
|
if (pending == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
h = pending->ptr;
|
||||||
|
pending->size = SPA_MIN((int)pending->size, len);
|
||||||
|
memcpy(h, m, pending->size);
|
||||||
|
|
||||||
|
reply = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
reply->sequence_id = htons(pending->old_sequence_id);
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(reply, AVB_ACMP_MESSAGE_TYPE_CONNECT_RX_RESPONSE);
|
||||||
|
|
||||||
|
stream = find_stream(server, SPA_DIRECTION_INPUT, ntohs(reply->listener_unique_id));
|
||||||
|
if (stream == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
stream->peer_id = be64toh(reply->stream_id);
|
||||||
|
memcpy(stream->addr, reply->stream_dest_mac, 6);
|
||||||
|
stream_activate(stream, ntohs(reply->listener_unique_id), now);
|
||||||
|
|
||||||
|
res = avb_server_send_packet(server, h->dest, AVB_TSN_ETH, h, pending->size);
|
||||||
|
|
||||||
|
pending_free(acmp, pending);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_disconnect_tx_command_legacy_avb(struct acmp *acmp, uint64_t now,
|
||||||
|
const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
uint8_t buf[len];
|
||||||
|
struct avb_ethernet_header *h = (void*)buf;
|
||||||
|
struct avb_packet_acmp *reply = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
const struct avb_packet_acmp *p = SPA_PTROFF(m, sizeof(*h), void);
|
||||||
|
int status = AVB_ACMP_STATUS_SUCCESS;
|
||||||
|
struct stream *stream;
|
||||||
|
|
||||||
|
if (be64toh(p->talker_guid) != server->entity_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(buf, m, len);
|
||||||
|
stream = find_stream(server, SPA_DIRECTION_OUTPUT, ntohs(reply->talker_unique_id));
|
||||||
|
if (stream == NULL) {
|
||||||
|
status = AVB_ACMP_STATUS_TALKER_NO_STREAM_INDEX;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(reply, AVB_ACMP_MESSAGE_TYPE_DISCONNECT_TX_RESPONSE);
|
||||||
|
|
||||||
|
stream_deactivate(stream, now);
|
||||||
|
|
||||||
|
done:
|
||||||
|
AVB_PACKET_ACMP_SET_STATUS(reply, status);
|
||||||
|
return avb_server_send_packet(server, h->dest, AVB_TSN_ETH, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_disconnect_tx_response_legacy_avb(struct acmp *acmp, uint64_t now,
|
||||||
|
const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
struct avb_ethernet_header *h;
|
||||||
|
struct avb_packet_acmp *reply;
|
||||||
|
const struct avb_packet_acmp *resp = SPA_PTROFF(m, sizeof(*h), void);
|
||||||
|
struct pending *pending;
|
||||||
|
uint16_t sequence_id;
|
||||||
|
struct stream *stream;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if (be64toh(resp->listener_guid) != server->entity_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
sequence_id = ntohs(resp->sequence_id);
|
||||||
|
|
||||||
|
pending = pending_find(acmp, PENDING_TALKER, sequence_id);
|
||||||
|
if (pending == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
h = pending->ptr;
|
||||||
|
pending->size = SPA_MIN((int)pending->size, len);
|
||||||
|
memcpy(h, m, pending->size);
|
||||||
|
|
||||||
|
reply = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
reply->sequence_id = htons(pending->old_sequence_id);
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(reply, AVB_ACMP_MESSAGE_TYPE_DISCONNECT_RX_RESPONSE);
|
||||||
|
|
||||||
|
stream = find_stream(server, SPA_DIRECTION_INPUT, ntohs(reply->listener_unique_id));
|
||||||
|
if (stream == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
stream_deactivate(stream, now);
|
||||||
|
|
||||||
|
res = avb_server_send_packet(server, h->dest, AVB_TSN_ETH, h, pending->size);
|
||||||
|
|
||||||
|
pending_free(acmp, pending);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handle_connect_rx_command_legacy_avb(struct acmp *acmp, uint64_t now, const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
struct avb_ethernet_header *h;
|
||||||
|
const struct avb_packet_acmp *p = SPA_PTROFF(m, sizeof(*h), void);
|
||||||
|
struct avb_packet_acmp *cmd;
|
||||||
|
|
||||||
|
if (be64toh(p->listener_guid) != server->entity_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
h = pending_new(acmp, PENDING_TALKER, now,
|
||||||
|
AVB_ACMP_TIMEOUT_CONNECT_TX_COMMAND_MS, m, len);
|
||||||
|
if (h == NULL)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
cmd = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(cmd, AVB_ACMP_MESSAGE_TYPE_CONNECT_TX_COMMAND);
|
||||||
|
AVB_PACKET_ACMP_SET_STATUS(cmd, AVB_ACMP_STATUS_SUCCESS);
|
||||||
|
|
||||||
|
return avb_server_send_packet(server, h->dest, AVB_TSN_ETH, h, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
nt handle_disconnect_rx_command_legacy_avb(struct acmp *acmp, uint64_t now,
|
||||||
|
const void *m, int len)
|
||||||
|
{
|
||||||
|
struct server *server = acmp->server;
|
||||||
|
struct avb_ethernet_header *h;
|
||||||
|
const struct avb_packet_acmp *p = SPA_PTROFF(m, sizeof(*h), void);
|
||||||
|
struct avb_packet_acmp *cmd;
|
||||||
|
|
||||||
|
if (be64toh(p->listener_guid) != server->entity_id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
h = pending_new(acmp, PENDING_TALKER, now,
|
||||||
|
AVB_ACMP_TIMEOUT_DISCONNECT_TX_COMMAND_MS, m, len);
|
||||||
|
if (h == NULL)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
cmd = SPA_PTROFF(h, sizeof(*h), void);
|
||||||
|
AVB_PACKET_ACMP_SET_MESSAGE_TYPE(cmd, AVB_ACMP_MESSAGE_TYPE_DISCONNECT_TX_COMMAND);
|
||||||
|
AVB_PACKET_ACMP_SET_STATUS(cmd, AVB_ACMP_STATUS_SUCCESS);
|
||||||
|
|
||||||
|
return avb_server_send_packet(server, h->dest, AVB_TSN_ETH, h, len);
|
||||||
|
}
|
||||||
9
src/modules/module-avb/acmp-cmds-resps/acmp-legacy-avb.h
Normal file
9
src/modules/module-avb/acmp-cmds-resps/acmp-legacy-avb.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* SPDX-FileCopyrightText: Copyright © 2027 Alexandre Malki <alexandre.malki@kebag-logic.com> */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#ifndef AVB_ACMP_LEGACY_AVB_H
|
||||||
|
#define AVB_ACMP_LEGACY_AVB_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //AVB_ACMP_LEGACY_AVB_H
|
||||||
3
src/modules/module-avb/acmp-cmds-resps/acmp-milan-v12.c
Normal file
3
src/modules/module-avb/acmp-cmds-resps/acmp-milan-v12.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "../acmp.h"
|
||||||
|
#include "acmp-milan-v12.h"
|
||||||
|
|
||||||
9
src/modules/module-avb/acmp-cmds-resps/acmp-milan-v12.h
Normal file
9
src/modules/module-avb/acmp-cmds-resps/acmp-milan-v12.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* SPDX-FileCopyrightText: Copyright © 2027 Alexandre Malki <alexandre.malki@kebag-logic.com> */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#ifndef AVB_ACMP_MILAN_V12_H
|
||||||
|
#define AVB_ACMP_MILAN_V12_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //AVB_ACMP_MILAN_V12_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue