2022-03-22 19:40:23 +01:00
|
|
|
/* AVB support
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2022 Wim Taymans
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <spa/debug/mem.h>
|
|
|
|
|
|
|
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
#include "msrp.h"
|
|
|
|
|
|
|
|
|
|
static const uint8_t mac[6] = AVB_MSRP_MAC;
|
|
|
|
|
|
|
|
|
|
struct attr {
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_msrp_attribute attr;
|
2022-03-22 19:40:23 +01:00
|
|
|
struct spa_list link;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct msrp {
|
|
|
|
|
struct server *server;
|
|
|
|
|
struct spa_hook server_listener;
|
2022-03-23 19:57:25 +01:00
|
|
|
struct spa_hook mrp_listener;
|
2022-03-22 19:40:23 +01:00
|
|
|
|
|
|
|
|
struct spa_list attributes;
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static void debug_msrp_talker_common(const struct avb_packet_msrp_talker *t)
|
2022-03-22 19:40:23 +01:00
|
|
|
{
|
2022-03-23 19:57:25 +01:00
|
|
|
char buf[128];
|
2022-03-25 10:28:18 +01:00
|
|
|
pw_log_info(" stream-id: %s", avb_utils_format_id(buf, sizeof(buf), be64toh(t->stream_id)));
|
|
|
|
|
pw_log_info(" dest-addr: %s", avb_utils_format_addr(buf, sizeof(buf), t->dest_addr));
|
2022-03-23 19:57:25 +01:00
|
|
|
pw_log_info(" vlan-id: %d", ntohs(t->vlan_id));
|
|
|
|
|
pw_log_info(" tspec-max-frame-size: %d", ntohs(t->tspec_max_frame_size));
|
|
|
|
|
pw_log_info(" tspec-max-interval-frames: %d", ntohs(t->tspec_max_interval_frames));
|
|
|
|
|
pw_log_info(" priority: %d", t->priority);
|
|
|
|
|
pw_log_info(" rank: %d", t->rank);
|
|
|
|
|
pw_log_info(" accumulated-latency: %d", ntohl(t->accumulated_latency));
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static void debug_msrp_talker(const struct avb_packet_msrp_talker *t)
|
2022-03-24 17:00:40 +01:00
|
|
|
{
|
|
|
|
|
pw_log_info("talker");
|
|
|
|
|
debug_msrp_talker_common(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void notify_talker(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
|
|
|
|
|
{
|
|
|
|
|
pw_log_info("> notify talker: %d", notify);
|
|
|
|
|
debug_msrp_talker(&attr->attr.attr.talker);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
static int process_talker(struct msrp *msrp, uint64_t now, uint8_t attr_type,
|
2022-03-22 19:40:23 +01:00
|
|
|
const void *m, uint8_t event, uint8_t param, int num)
|
|
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
const struct avb_packet_msrp_talker *t = m;
|
2022-03-22 19:40:23 +01:00
|
|
|
struct attr *a;
|
2022-03-24 17:00:40 +01:00
|
|
|
spa_list_for_each(a, &msrp->attributes, link)
|
|
|
|
|
if (a->attr.type == attr_type &&
|
|
|
|
|
a->attr.attr.talker.stream_id == t->stream_id) {
|
|
|
|
|
a->attr.attr.talker = *t;
|
2022-03-25 17:01:51 +01:00
|
|
|
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
|
2022-03-24 17:00:40 +01:00
|
|
|
}
|
2022-03-23 19:57:25 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static void debug_msrp_talker_fail(const struct avb_packet_msrp_talker_fail *t)
|
2022-03-23 19:57:25 +01:00
|
|
|
{
|
|
|
|
|
char buf[128];
|
2022-03-24 17:00:40 +01:00
|
|
|
pw_log_info("talker fail");
|
|
|
|
|
debug_msrp_talker_common(&t->talker);
|
2022-03-25 10:28:18 +01:00
|
|
|
pw_log_info(" bridge-id: %s", avb_utils_format_id(buf, sizeof(buf), be64toh(t->bridge_id)));
|
2022-03-23 19:57:25 +01:00
|
|
|
pw_log_info(" failure-code: %d", t->failure_code);
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
static int process_talker_fail(struct msrp *msrp, uint64_t now, uint8_t attr_type,
|
2022-03-22 19:40:23 +01:00
|
|
|
const void *m, uint8_t event, uint8_t param, int num)
|
|
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
const struct avb_packet_msrp_talker_fail *t = m;
|
2022-03-24 17:00:40 +01:00
|
|
|
struct attr *a;
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
debug_msrp_talker_fail(t);
|
2022-03-24 17:00:40 +01:00
|
|
|
|
|
|
|
|
spa_list_for_each(a, &msrp->attributes, link)
|
|
|
|
|
if (a->attr.type == attr_type &&
|
|
|
|
|
a->attr.attr.talker_fail.talker.stream_id == t->talker.stream_id)
|
2022-03-25 17:01:51 +01:00
|
|
|
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
|
2022-03-23 19:57:25 +01:00
|
|
|
return 0;
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static void debug_msrp_listener(const struct avb_packet_msrp_listener *l)
|
2022-03-22 19:40:23 +01:00
|
|
|
{
|
|
|
|
|
char buf[128];
|
2022-03-24 17:00:40 +01:00
|
|
|
pw_log_info("listener");
|
2022-03-25 10:28:18 +01:00
|
|
|
pw_log_info(" %s", avb_utils_format_id(buf, sizeof(buf), be64toh(l->stream_id)));
|
2022-03-24 17:00:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void notify_listener(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
|
|
|
|
|
{
|
|
|
|
|
pw_log_info("> notify listener: %d", notify);
|
|
|
|
|
debug_msrp_listener(&attr->attr.attr.listener);
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
static int process_listener(struct msrp *msrp, uint64_t now, uint8_t attr_type,
|
2022-03-22 19:40:23 +01:00
|
|
|
const void *m, uint8_t event, uint8_t param, int num)
|
|
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
const struct avb_packet_msrp_listener *l = m;
|
2022-03-24 17:00:40 +01:00
|
|
|
struct attr *a;
|
|
|
|
|
spa_list_for_each(a, &msrp->attributes, link)
|
|
|
|
|
if (a->attr.type == attr_type &&
|
|
|
|
|
a->attr.attr.listener.stream_id == l->stream_id)
|
2022-03-25 17:01:51 +01:00
|
|
|
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
|
2022-03-23 19:57:25 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2022-03-24 17:00:40 +01:00
|
|
|
static int encode_listener(struct msrp *msrp, struct attr *a, void *m)
|
|
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_packet_msrp_msg *msg = m;
|
|
|
|
|
struct avb_packet_mrp_vector *v;
|
|
|
|
|
struct avb_packet_msrp_listener *l;
|
|
|
|
|
struct avb_packet_mrp_footer *f;
|
2022-03-24 17:00:40 +01:00
|
|
|
uint8_t *ev;
|
|
|
|
|
size_t attr_list_length = sizeof(*v) + sizeof(*l) + sizeof(*f) + 1 + 1;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
msg->attribute_type = AVB_MSRP_ATTRIBUTE_TYPE_LISTENER;
|
2022-03-24 17:00:40 +01:00
|
|
|
msg->attribute_length = sizeof(*l);
|
|
|
|
|
msg->attribute_list_length = htons(attr_list_length);
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
v = (struct avb_packet_mrp_vector *)msg->attribute_list;
|
2022-03-24 17:00:40 +01:00
|
|
|
v->lva = 0;
|
2022-03-25 10:28:18 +01:00
|
|
|
AVB_MRP_VECTOR_SET_NUM_VALUES(v, 1);
|
2022-03-24 17:00:40 +01:00
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
l = (struct avb_packet_msrp_listener *)v->first_value;
|
2022-03-24 17:00:40 +01:00
|
|
|
*l = a->attr.attr.listener;
|
|
|
|
|
|
|
|
|
|
ev = SPA_PTROFF(l, sizeof(*l), uint8_t);
|
|
|
|
|
*ev = a->attr.mrp->pending_send * 6 * 6;
|
|
|
|
|
|
|
|
|
|
ev = SPA_PTROFF(ev, sizeof(*ev), uint8_t);
|
|
|
|
|
*ev = a->attr.param * 4 * 4 * 4;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
f = SPA_PTROFF(ev, sizeof(*ev), struct avb_packet_mrp_footer);
|
2022-03-24 17:00:40 +01:00
|
|
|
f->end_mark = 0;
|
|
|
|
|
|
|
|
|
|
return attr_list_length + sizeof(*msg);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static void debug_msrp_domain(const struct avb_packet_msrp_domain *d)
|
2022-03-23 19:57:25 +01:00
|
|
|
{
|
2022-03-24 17:00:40 +01:00
|
|
|
pw_log_info("domain");
|
2022-03-22 19:40:23 +01:00
|
|
|
pw_log_info(" %d", d->sr_class_id);
|
|
|
|
|
pw_log_info(" %d", d->sr_class_priority);
|
|
|
|
|
pw_log_info(" %d", ntohs(d->sr_class_vid));
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
static void notify_domain(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
|
|
|
|
|
{
|
|
|
|
|
pw_log_info("> notify domain: %d", notify);
|
|
|
|
|
debug_msrp_domain(&attr->attr.attr.domain);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
static int process_domain(struct msrp *msrp, uint64_t now, uint8_t attr_type,
|
|
|
|
|
const void *m, uint8_t event, uint8_t param, int num)
|
|
|
|
|
{
|
2022-03-24 17:00:40 +01:00
|
|
|
struct attr *a;
|
|
|
|
|
spa_list_for_each(a, &msrp->attributes, link)
|
|
|
|
|
if (a->attr.type == attr_type)
|
2022-03-25 17:01:51 +01:00
|
|
|
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
|
2022-03-23 19:57:25 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
static int encode_domain(struct msrp *msrp, struct attr *a, void *m)
|
|
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_packet_msrp_msg *msg = m;
|
|
|
|
|
struct avb_packet_mrp_vector *v;
|
|
|
|
|
struct avb_packet_msrp_domain *d;
|
|
|
|
|
struct avb_packet_mrp_footer *f;
|
2022-03-24 17:00:40 +01:00
|
|
|
uint8_t *ev;
|
|
|
|
|
size_t attr_list_length = sizeof(*v) + sizeof(*d) + sizeof(*f) + 1;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
msg->attribute_type = AVB_MSRP_ATTRIBUTE_TYPE_DOMAIN;
|
2022-03-24 17:00:40 +01:00
|
|
|
msg->attribute_length = sizeof(*d);
|
|
|
|
|
msg->attribute_list_length = htons(attr_list_length);
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
v = (struct avb_packet_mrp_vector *)msg->attribute_list;
|
2022-03-24 17:00:40 +01:00
|
|
|
v->lva = 0;
|
2022-03-25 10:28:18 +01:00
|
|
|
AVB_MRP_VECTOR_SET_NUM_VALUES(v, 1);
|
2022-03-24 17:00:40 +01:00
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
d = (struct avb_packet_msrp_domain *)v->first_value;
|
2022-03-24 17:00:40 +01:00
|
|
|
*d = a->attr.attr.domain;
|
|
|
|
|
|
|
|
|
|
ev = SPA_PTROFF(d, sizeof(*d), uint8_t);
|
|
|
|
|
*ev = a->attr.mrp->pending_send * 36;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
f = SPA_PTROFF(ev, sizeof(*ev), struct avb_packet_mrp_footer);
|
2022-03-24 17:00:40 +01:00
|
|
|
f->end_mark = 0;
|
|
|
|
|
|
|
|
|
|
return attr_list_length + sizeof(*msg);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-22 19:40:23 +01:00
|
|
|
static const struct {
|
2022-03-25 17:01:51 +01:00
|
|
|
const char *name;
|
2022-03-23 19:57:25 +01:00
|
|
|
int (*dispatch) (struct msrp *msrp, uint64_t now, uint8_t attr_type,
|
|
|
|
|
const void *m, uint8_t event, uint8_t param, int num);
|
2022-03-24 17:00:40 +01:00
|
|
|
int (*encode) (struct msrp *msrp, struct attr *attr, void *m);
|
|
|
|
|
void (*notify) (struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify);
|
2022-03-22 19:40:23 +01:00
|
|
|
} dispatch[] = {
|
2022-03-25 17:01:51 +01:00
|
|
|
[AVB_MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE] = { "talker", process_talker, NULL, notify_talker, },
|
|
|
|
|
[AVB_MSRP_ATTRIBUTE_TYPE_TALKER_FAILED] = { "talker-fail", process_talker_fail, NULL, NULL },
|
|
|
|
|
[AVB_MSRP_ATTRIBUTE_TYPE_LISTENER] = { "listener", process_listener, encode_listener, notify_listener },
|
|
|
|
|
[AVB_MSRP_ATTRIBUTE_TYPE_DOMAIN] = { "domain", process_domain, encode_domain, notify_domain, },
|
2022-03-22 19:40:23 +01:00
|
|
|
};
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
static bool msrp_check_header(void *data, const void *hdr, size_t *hdr_size, bool *has_params)
|
|
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
const struct avb_packet_msrp_msg *msg = hdr;
|
2022-03-23 19:57:25 +01:00
|
|
|
uint8_t attr_type = msg->attribute_type;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
if (!AVB_MSRP_ATTRIBUTE_TYPE_VALID(attr_type))
|
2022-03-23 19:57:25 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
*hdr_size = sizeof(*msg);
|
2022-03-25 10:28:18 +01:00
|
|
|
*has_params = attr_type == AVB_MSRP_ATTRIBUTE_TYPE_LISTENER;
|
2022-03-23 19:57:25 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int msrp_attr_event(void *data, uint64_t now, uint8_t attribute_type, uint8_t event)
|
|
|
|
|
{
|
|
|
|
|
struct msrp *msrp = data;
|
|
|
|
|
struct attr *a;
|
|
|
|
|
spa_list_for_each(a, &msrp->attributes, link)
|
|
|
|
|
if (a->attr.type == attribute_type)
|
2022-03-25 17:01:51 +01:00
|
|
|
avb_mrp_attribute_update_state(a->attr.mrp, now, event);
|
2022-03-22 19:40:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
static int msrp_process(void *data, uint64_t now, uint8_t attribute_type, const void *value,
|
|
|
|
|
uint8_t event, uint8_t param, int index)
|
|
|
|
|
{
|
|
|
|
|
struct msrp *msrp = data;
|
|
|
|
|
return dispatch[attribute_type].dispatch(msrp, now,
|
|
|
|
|
attribute_type, value, event, param, index);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static const struct avb_mrp_parse_info info = {
|
|
|
|
|
AVB_VERSION_MRP_PARSE_INFO,
|
2022-03-23 19:57:25 +01:00
|
|
|
.check_header = msrp_check_header,
|
|
|
|
|
.attr_event = msrp_attr_event,
|
|
|
|
|
.process = msrp_process,
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-22 19:40:23 +01:00
|
|
|
|
|
|
|
|
static int msrp_message(void *data, uint64_t now, const void *message, int len)
|
|
|
|
|
{
|
|
|
|
|
struct msrp *msrp = data;
|
2022-03-25 10:28:18 +01:00
|
|
|
const struct avb_packet_mrp *p = message;
|
2022-03-22 19:40:23 +01:00
|
|
|
|
|
|
|
|
if (ntohs(p->eth.type) != AVB_MSRP_ETH)
|
|
|
|
|
return 0;
|
|
|
|
|
if (memcmp(p->eth.dest, mac, 6) != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
pw_log_debug("MSRP");
|
2022-03-25 10:28:18 +01:00
|
|
|
return avb_mrp_parse_packet(msrp->server->mrp,
|
2022-03-23 19:57:25 +01:00
|
|
|
now, message, len, &info, msrp);
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void msrp_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct msrp *msrp = data;
|
|
|
|
|
spa_hook_remove(&msrp->server_listener);
|
|
|
|
|
free(msrp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct server_events server_events = {
|
2022-03-25 10:28:18 +01:00
|
|
|
AVB_VERSION_SERVER_EVENTS,
|
2022-03-22 19:40:23 +01:00
|
|
|
.destroy = msrp_destroy,
|
|
|
|
|
.message = msrp_message
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_msrp_attribute *avb_msrp_attribute_new(struct avb_msrp *m,
|
2022-03-23 19:57:25 +01:00
|
|
|
uint8_t type)
|
|
|
|
|
{
|
|
|
|
|
struct msrp *msrp = (struct msrp*)m;
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_mrp_attribute *attr;
|
2022-03-23 19:57:25 +01:00
|
|
|
struct attr *a;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
attr = avb_mrp_attribute_new(msrp->server->mrp, sizeof(struct attr));
|
2022-03-23 19:57:25 +01:00
|
|
|
|
|
|
|
|
a = attr->user_data;
|
|
|
|
|
a->attr.mrp = attr;
|
|
|
|
|
a->attr.type = type;
|
2022-03-24 17:00:40 +01:00
|
|
|
spa_list_append(&msrp->attributes, &a->link);
|
2022-03-23 19:57:25 +01:00
|
|
|
|
|
|
|
|
return &a->attr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
static void msrp_event(void *data, uint64_t now, uint8_t event)
|
2022-03-23 19:57:25 +01:00
|
|
|
{
|
2022-03-24 17:00:40 +01:00
|
|
|
struct msrp *msrp = data;
|
|
|
|
|
uint8_t buffer[2048];
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_packet_mrp *p = (struct avb_packet_mrp*)buffer;
|
|
|
|
|
struct avb_packet_mrp_footer *f;
|
2022-03-24 17:00:40 +01:00
|
|
|
void *msg = SPA_PTROFF(buffer, sizeof(*p), void);
|
|
|
|
|
struct attr *a;
|
|
|
|
|
int len, count = 0;
|
|
|
|
|
size_t total = sizeof(*p) + 2;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
p->version = AVB_MRP_PROTOCOL_VERSION;
|
2022-03-24 17:00:40 +01:00
|
|
|
|
|
|
|
|
spa_list_for_each(a, &msrp->attributes, link) {
|
|
|
|
|
if (!a->attr.mrp->pending_send)
|
|
|
|
|
continue;
|
|
|
|
|
if (dispatch[a->attr.type].encode == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-03-25 17:01:51 +01:00
|
|
|
pw_log_debug("send %s %d", dispatch[a->attr.type].name,
|
|
|
|
|
a->attr.mrp->pending_send);
|
|
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
len = dispatch[a->attr.type].encode(msrp, a, msg);
|
|
|
|
|
if (len < 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
msg = SPA_PTROFF(msg, len, void);
|
|
|
|
|
total += len;
|
|
|
|
|
}
|
2022-03-25 10:28:18 +01:00
|
|
|
f = (struct avb_packet_mrp_footer *)msg;
|
2022-03-24 17:00:40 +01:00
|
|
|
f->end_mark = 0;
|
|
|
|
|
|
|
|
|
|
if (count > 0)
|
2022-03-25 10:28:18 +01:00
|
|
|
avb_server_send_packet(msrp->server, mac, AVB_MSRP_ETH,
|
2022-03-24 17:00:40 +01:00
|
|
|
buffer, total);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static void msrp_notify(void *data, uint64_t now, struct avb_mrp_attribute *attr, uint8_t notify)
|
2022-03-24 17:00:40 +01:00
|
|
|
{
|
|
|
|
|
struct msrp *msrp = data;
|
|
|
|
|
struct attr *a = attr->user_data;
|
|
|
|
|
if (dispatch[a->attr.type].notify != NULL)
|
|
|
|
|
dispatch[a->attr.type].notify(msrp, now, a, notify);
|
2022-03-23 19:57:25 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
static const struct avb_mrp_events mrp_events = {
|
2022-03-25 17:01:51 +01:00
|
|
|
AVB_VERSION_MRP_EVENTS,
|
2022-03-24 17:00:40 +01:00
|
|
|
.event = msrp_event,
|
|
|
|
|
.notify = msrp_notify
|
2022-03-23 19:57:25 +01:00
|
|
|
};
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_msrp *avb_msrp_register(struct server *server)
|
2022-03-22 19:40:23 +01:00
|
|
|
{
|
|
|
|
|
struct msrp *msrp;
|
|
|
|
|
|
|
|
|
|
msrp = calloc(1, sizeof(*msrp));
|
|
|
|
|
if (msrp == NULL)
|
2022-03-23 19:57:25 +01:00
|
|
|
return NULL;
|
2022-03-22 19:40:23 +01:00
|
|
|
|
|
|
|
|
msrp->server = server;
|
|
|
|
|
spa_list_init(&msrp->attributes);
|
|
|
|
|
|
|
|
|
|
avdecc_server_add_listener(server, &msrp->server_listener, &server_events, msrp);
|
2022-03-25 10:28:18 +01:00
|
|
|
avb_mrp_add_listener(server->mrp, &msrp->mrp_listener, &mrp_events, msrp);
|
2022-03-22 19:40:23 +01:00
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
return (struct avb_msrp*)msrp;
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|