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 <pipewire/pipewire.h>
|
|
|
|
|
|
|
|
|
|
#include "mvrp.h"
|
|
|
|
|
|
|
|
|
|
static const uint8_t mac[6] = AVB_MVRP_MAC;
|
|
|
|
|
|
2022-03-23 19:57:25 +01:00
|
|
|
struct attr {
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_mvrp_attribute attr;
|
2022-03-23 19:57:25 +01:00
|
|
|
struct spa_list link;
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-22 19:40:23 +01:00
|
|
|
struct mvrp {
|
|
|
|
|
struct server *server;
|
|
|
|
|
struct spa_hook server_listener;
|
2022-03-23 19:57:25 +01:00
|
|
|
|
|
|
|
|
struct spa_list attributes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool mvrp_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_mvrp_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_MVRP_ATTRIBUTE_TYPE_VALID(attr_type))
|
2022-03-23 19:57:25 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
*hdr_size = sizeof(*msg);
|
|
|
|
|
*has_params = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int mvrp_attr_event(void *data, uint64_t now, uint8_t attribute_type, uint8_t event)
|
|
|
|
|
{
|
|
|
|
|
struct mvrp *mvrp = data;
|
|
|
|
|
struct attr *a;
|
|
|
|
|
spa_list_for_each(a, &mvrp->attributes, link)
|
|
|
|
|
if (a->attr.type == attribute_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 void debug_vid(const void *p)
|
2022-03-23 19:57:25 +01:00
|
|
|
{
|
2022-03-25 10:28:18 +01:00
|
|
|
const struct avb_packet_mvrp_vid *t = p;
|
2022-03-23 19:57:25 +01:00
|
|
|
pw_log_info("vid");
|
2022-03-24 17:00:40 +01:00
|
|
|
pw_log_info(" %d", ntohs(t->vlan));
|
|
|
|
|
}
|
2022-03-23 19:57:25 +01:00
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
static int process_vid(struct mvrp *mvrp, uint64_t now, uint8_t attr_type,
|
|
|
|
|
const void *m, uint8_t event, uint8_t param, int num)
|
|
|
|
|
{
|
|
|
|
|
return mvrp_attr_event(mvrp, now, attr_type, event);
|
2022-03-23 19:57:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct {
|
2022-03-24 17:00:40 +01:00
|
|
|
void (*debug) (const void *p);
|
2022-03-23 19:57:25 +01:00
|
|
|
int (*dispatch) (struct mvrp *mvrp, uint64_t now, uint8_t attr_type,
|
|
|
|
|
const void *m, uint8_t event, uint8_t param, int num);
|
|
|
|
|
} dispatch[] = {
|
2022-03-25 10:28:18 +01:00
|
|
|
[AVB_MVRP_ATTRIBUTE_TYPE_VID] = { debug_vid, process_vid, },
|
2022-03-23 19:57:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int mvrp_process(void *data, uint64_t now, uint8_t attribute_type, const void *value,
|
|
|
|
|
uint8_t event, uint8_t param, int index)
|
|
|
|
|
{
|
|
|
|
|
struct mvrp *mvrp = data;
|
|
|
|
|
return dispatch[attribute_type].dispatch(mvrp, 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 = mvrp_check_header,
|
|
|
|
|
.attr_event = mvrp_attr_event,
|
|
|
|
|
.process = mvrp_process,
|
2022-03-22 19:40:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int mvrp_message(void *data, uint64_t now, const void *message, int len)
|
|
|
|
|
{
|
2022-03-23 19:57:25 +01:00
|
|
|
struct mvrp *mvrp = 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_MVRP_ETH)
|
|
|
|
|
return 0;
|
|
|
|
|
if (memcmp(p->eth.dest, mac, 6) != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2022-03-24 17:00:40 +01:00
|
|
|
pw_log_debug("MVRP");
|
2022-03-25 10:28:18 +01:00
|
|
|
return avb_mrp_parse_packet(mvrp->server->mrp,
|
2022-03-23 19:57:25 +01:00
|
|
|
now, message, len, &info, mvrp);
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mvrp_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct mvrp *mvrp = data;
|
|
|
|
|
spa_hook_remove(&mvrp->server_listener);
|
|
|
|
|
free(mvrp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 = mvrp_destroy,
|
|
|
|
|
.message = mvrp_message
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_mvrp_attribute *avb_mvrp_attribute_new(struct avb_mvrp *m,
|
2022-03-24 17:00:40 +01:00
|
|
|
uint8_t type)
|
|
|
|
|
{
|
|
|
|
|
struct mvrp *mvrp = (struct mvrp*)m;
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_mrp_attribute *attr;
|
2022-03-24 17:00:40 +01:00
|
|
|
struct attr *a;
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
attr = avb_mrp_attribute_new(mvrp->server->mrp, sizeof(struct attr));
|
2022-03-24 17:00:40 +01:00
|
|
|
|
|
|
|
|
a = attr->user_data;
|
|
|
|
|
a->attr.mrp = attr;
|
|
|
|
|
a->attr.type = type;
|
|
|
|
|
spa_list_append(&mvrp->attributes, &a->link);
|
|
|
|
|
|
|
|
|
|
return &a->attr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
struct avb_mvrp *avb_mvrp_register(struct server *server)
|
2022-03-22 19:40:23 +01:00
|
|
|
{
|
|
|
|
|
struct mvrp *mvrp;
|
|
|
|
|
|
|
|
|
|
mvrp = calloc(1, sizeof(*mvrp));
|
|
|
|
|
if (mvrp == NULL)
|
2022-03-23 19:57:25 +01:00
|
|
|
return NULL;
|
2022-03-22 19:40:23 +01:00
|
|
|
|
|
|
|
|
mvrp->server = server;
|
2022-03-23 19:57:25 +01:00
|
|
|
spa_list_init(&mvrp->attributes);
|
2022-03-22 19:40:23 +01:00
|
|
|
|
|
|
|
|
avdecc_server_add_listener(server, &mvrp->server_listener, &server_events, mvrp);
|
|
|
|
|
|
2022-03-25 10:28:18 +01:00
|
|
|
return (struct avb_mvrp*)mvrp;
|
2022-03-22 19:40:23 +01:00
|
|
|
}
|