1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-14 09:03:50 +01:00
RIOT/sys/net/gnrc/netapi/notify/gnrc_netapi_notify.c
2025-12-09 16:03:59 +01:00

64 lines
1.5 KiB
C

/*
* SPDX-FileCopyrightText: 2025 TU Dresden
* SPDX-License-Identifier: LGPL-2.1-only
*/
/**
* @{
* @ingroup net_gnrc_netapi_notify
* @file
* @brief Helper functions to extract data from netapi notify events.
*
* @author Elena Frank <elena.frank@tu-dresden.de>
*/
#include <assert.h>
#include <errno.h>
#include "net/gnrc/netapi/notify.h"
#include "net/ipv6/addr.h"
int _copy_l2_connection_data(gnrc_netapi_notify_t *notify, netapi_notify_l2_connection_t *data)
{
assert(notify->_data_len == sizeof(netapi_notify_l2_connection_t));
/* Parse event data */
netapi_notify_l2_connection_t *recv_data = notify->_data;
if (recv_data->l2addr_len > GNRC_NETIF_L2ADDR_MAXLEN) {
return -EINVAL;
}
memcpy(data->l2addr, recv_data->l2addr, recv_data->l2addr_len);
data->l2addr_len = recv_data->l2addr_len;
data->if_pid = recv_data->if_pid;
return sizeof(netapi_notify_l2_connection_t);
}
int gnrc_netapi_notify_copy_event_data(gnrc_netapi_notify_t *notify, uint8_t data_len, void *data)
{
int res;
switch (notify->event) {
case NETAPI_NOTIFY_L2_NEIGH_CONNECTED:
case NETAPI_NOTIFY_L2_NEIGH_DISCONNECTED:
if (data_len != sizeof(netapi_notify_l2_connection_t)) {
res = -EINVAL;
break;
}
res = _copy_l2_connection_data(notify, data);
break;
default:
res = -EINVAL;
break;
}
/* Acknowledge the read data */
gnrc_netapi_notify_ack(&notify->ack);
return res;
}
/** @} */