Skip to content

Commit

Permalink
Update GetField API for Udp.h/c
Browse files Browse the repository at this point in the history
Signed-off-by: Adriaan Niess <[email protected]>
  • Loading branch information
adriaan-niess committed Aug 25, 2024
1 parent 4f28c35 commit 92d42f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
6 changes: 5 additions & 1 deletion include/avtp/Udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef enum {
*
* @param pdu Pointer to the first bit of an IEEE 1722 UDP PDU.
*/
int Avtp_Udp_Init(Avtp_Udp_t* pdu);
void Avtp_Udp_Init(Avtp_Udp_t* pdu);

/**
* Returns the value of an an AVTP UDP field as specified in the IEEE 1722 Specification.
Expand All @@ -72,6 +72,8 @@ int Avtp_Udp_Init(Avtp_Udp_t* pdu);
*/
uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field);

uint32_t Avtp_Udp_GetEncapsulationSeqNo(Avtp_Udp_t* pdu);

/**
* Sets the value of an an AVTP UDP field as specified in the IEEE 1722 Specification.
*
Expand All @@ -80,3 +82,5 @@ uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field);
* @param value Pointer to location to store the value.
*/
void Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value);

void Avtp_Udp_SetEncapsulationSeqNo(Avtp_Udp_t* pdu, uint32_t value);
38 changes: 23 additions & 15 deletions src/avtp/Udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#include "avtp/Utils.h"
#include "avtp/Defines.h"

#define GET_FIELD(field) \
(Avtp_GetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*)pdu, field))
#define SET_FIELD(field, value) \
(Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*)pdu, field, value))

/**
* This table maps all IEEE 1722 UDP-specific header fields to a descriptor.
*/
Expand All @@ -41,27 +46,30 @@ static const Avtp_FieldDescriptor_t Avtp_UdpFieldDesc[AVTP_UDP_FIELD_MAX] = {
[AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO] = { .quadlet = 0, .offset = 0, .bits = 32 },
};

int Avtp_Udp_Init(Avtp_Udp_t* pdu) {

int res = 0;

if (!pdu)
return -EINVAL;

memset(pdu, 0, sizeof(Avtp_Udp_t));

Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu,
AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, 0);

return res;
void Avtp_Udp_Init(Avtp_Udp_t* pdu)
{
if (pdu != NULL) {
memset(pdu, 0, sizeof(Avtp_Udp_t));
Avtp_Udp_SetEncapsulationSeqNo(pdu, 0);
}
}

uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field)
{
return Avtp_GetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field);
return GET_FIELD(field);
}

uint32_t Avtp_Udp_GetEncapsulationSeqNo(Avtp_Udp_t* pdu)
{
return GET_FIELD(AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO);
}

void Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value)
{
Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value);
SET_FIELD(field, value);
}

void Avtp_Udp_SetEncapsulationSeqNo(Avtp_Udp_t* pdu, uint32_t value)
{
SET_FIELD(AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, value);
}

0 comments on commit 92d42f4

Please sign in to comment.