avb: more work

Implement generic MRP parsing.
Implement more MRP messages.
Implement MRP timeouts.
Implement MRP join/leave.
Prepare for generating and sending MRP packets.
This commit is contained in:
Wim Taymans 2022-03-23 19:57:25 +01:00
parent 0efc02cea6
commit f64f8cdd4d
11 changed files with 707 additions and 137 deletions

View file

@ -28,13 +28,94 @@
static const uint8_t mac[6] = AVB_MVRP_MAC;
struct attr {
struct avbtp_mvrp_attribute attr;
struct spa_list link;
struct avbtp_mrp_attribute *a;
uint16_t vlan;
};
struct mvrp {
struct server *server;
struct spa_hook server_listener;
struct spa_list attributes;
};
static struct attr *find_attr_by_vlan(struct mvrp *mvrp, uint16_t vlan)
{
struct attr *a;
spa_list_for_each(a, &mvrp->attributes, link)
if (a->vlan == vlan)
return a;
return NULL;
}
static bool mvrp_check_header(void *data, const void *hdr, size_t *hdr_size, bool *has_params)
{
const struct avbtp_packet_mvrp_msg *msg = hdr;
uint8_t attr_type = msg->attribute_type;
if (!AVBTP_MVRP_ATTRIBUTE_TYPE_VALID(attr_type))
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;
pw_log_info("leave all");
spa_list_for_each(a, &mvrp->attributes, link)
if (a->attr.type == attribute_type)
avbtp_mrp_update_state(mvrp->server->mrp, now, a->a, event);
return 0;
}
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)
{
const struct avbtp_packet_mvrp_vid *t = m;
struct attr *a;
uint16_t vlan = ntohs(t->vlan);
pw_log_info("vid");
pw_log_info(" %d", vlan);
a = find_attr_by_vlan(mvrp, vlan);
if (a)
avbtp_mrp_rx_event(mvrp->server->mrp, now, a->a, event);
return 0;
}
static const struct {
int (*dispatch) (struct mvrp *mvrp, uint64_t now, uint8_t attr_type,
const void *m, uint8_t event, uint8_t param, int num);
} dispatch[] = {
[AVBTP_MVRP_ATTRIBUTE_TYPE_VID] = { process_vid, },
};
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);
}
static const struct avbtp_mrp_parse_info info = {
AVBTP_VERSION_MRP_PARSE_INFO,
.check_header = mvrp_check_header,
.attr_event = mvrp_attr_event,
.process = mvrp_process,
};
static int mvrp_message(void *data, uint64_t now, const void *message, int len)
{
struct mvrp *mvrp = data;
const struct avbtp_packet_mrp *p = message;
if (ntohs(p->eth.type) != AVB_MVRP_ETH)
@ -43,8 +124,8 @@ static int mvrp_message(void *data, uint64_t now, const void *message, int len)
return 0;
pw_log_info("MVRP");
return 0;
return avbtp_mrp_parse_packet(mvrp->server->mrp,
now, message, len, &info, mvrp);
}
static void mvrp_destroy(void *data)
@ -60,17 +141,18 @@ static const struct server_events server_events = {
.message = mvrp_message
};
int avbtp_mvrp_register(struct server *server)
struct avbtp_mvrp *avbtp_mvrp_register(struct server *server)
{
struct mvrp *mvrp;
mvrp = calloc(1, sizeof(*mvrp));
if (mvrp == NULL)
return -errno;
return NULL;
mvrp->server = server;
spa_list_init(&mvrp->attributes);
avdecc_server_add_listener(server, &mvrp->server_listener, &server_events, mvrp);
return 0;
return (struct avbtp_mvrp*)mvrp;
}