diff --git a/src/sampled_values/sv_publisher.c b/src/sampled_values/sv_publisher.c index 02dfee64..90d2de7b 100644 --- a/src/sampled_values/sv_publisher.c +++ b/src/sampled_values/sv_publisher.c @@ -85,7 +85,7 @@ struct sSVPublisher { static bool -preparePacketBuffer(SVPublisher self, CommParameters* parameters, const char* interfaceId) +preparePacketBuffer(SVPublisher self, CommParameters* parameters, const char* interfaceId, bool useVlanTags) { uint8_t defaultDstAddr[] = CONFIG_SV_DEFAULT_DST_ADDRESS; @@ -134,17 +134,19 @@ preparePacketBuffer(SVPublisher self, CommParameters* parameters, const char* in int bufPos = 12; - /* Priority tag - IEEE 802.1Q */ - self->buffer[bufPos++] = 0x81; - self->buffer[bufPos++] = 0x00; + if (useVlanTags) { + /* Priority tag - IEEE 802.1Q */ + self->buffer[bufPos++] = 0x81; + self->buffer[bufPos++] = 0x00; - uint8_t tci1 = priority << 5; - tci1 += vlanId / 256; + uint8_t tci1 = priority << 5; + tci1 += vlanId / 256; - uint8_t tci2 = vlanId % 256; + uint8_t tci2 = vlanId % 256; - self->buffer[bufPos++] = tci1; /* Priority + VLAN-ID */ - self->buffer[bufPos++] = tci2; /* VLAN-ID */ + self->buffer[bufPos++] = tci1; /* Priority + VLAN-ID */ + self->buffer[bufPos++] = tci2; /* VLAN-ID */ + } /* EtherType Sampled Values */ self->buffer[bufPos++] = 0x88; @@ -293,14 +295,14 @@ encodeUtcTime(uint64_t timeval, uint8_t* buffer, int bufPos) } SVPublisher -SVPublisher_create(CommParameters* parameters, const char* interfaceId) +SVPublisher_createEx(CommParameters* parameters, const char* interfaceId, bool useVlanTag) { SVPublisher self = (SVPublisher) GLOBAL_CALLOC(1, sizeof(struct sSVPublisher)); if (self) { self->asduList = NULL; - if (preparePacketBuffer(self, parameters, interfaceId) == false) { + if (preparePacketBuffer(self, parameters, interfaceId, useVlanTag) == false) { GLOBAL_FREEMEM(self); self = NULL; } @@ -310,6 +312,12 @@ SVPublisher_create(CommParameters* parameters, const char* interfaceId) return self; } +SVPublisher +SVPublisher_create(CommParameters* parameters, const char* interfaceId) +{ + return SVPublisher_createEx(parameters, interfaceId, true); +} + SVPublisher_ASDU SVPublisher_addASDU(SVPublisher self, const char* svID, const char* datset, uint32_t confRev) { diff --git a/src/sampled_values/sv_publisher.h b/src/sampled_values/sv_publisher.h index dae01d27..3c59c1b4 100644 --- a/src/sampled_values/sv_publisher.h +++ b/src/sampled_values/sv_publisher.h @@ -70,6 +70,9 @@ typedef struct sSVPublisher_ASDU* SVPublisher_ASDU; /** * \brief Create a new IEC61850-9-2 Sampled Values publisher. * + * NOTE: VLAN tagging is enabled when calling this constructor. To disable VLAN tagging + * use \ref SVPublisher_createEx instead. + * * \param[in] interfaceId the name of the interface over which the SV publisher should send SV packets. * \param[in] parameters optional parameters for setting VLAN options and destination MAC address. Use NULL for default values. * \return the new SV publisher instance. @@ -77,6 +80,17 @@ typedef struct sSVPublisher_ASDU* SVPublisher_ASDU; LIB61850_API SVPublisher SVPublisher_create(CommParameters* parameters, const char* interfaceId); +/** + * \brief Create a new IEC61850-9-2 Sampled Values publisher. + * + * \param[in] interfaceId the name of the interface over which the SV publisher should send SV packets. + * \param[in] parameters optional parameters for setting VLAN options and destination MAC address. Use NULL for default values. + * \param[in] useVlanTags enable(true)/disable(false) VLAN tagging + * \return the new SV publisher instance. + */ +LIB61850_API SVPublisher +SVPublisher_createEx(CommParameters* parameters, const char* interfaceId, bool useVlanTag); + /** * \brief Create an Application Service Data Unit (ASDU) and add it to an existing Sampled Values publisher. *