From a07f2ccedaa4fb9495d112f5455f396d978ca97e Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 28 Dec 2017 22:47:52 +0100 Subject: [PATCH] - IEC 61850 client: Added ClientGooseControlBlock_getDstAddress/ClientGooseControlBlock_setDstAddress; marked old access functions deprecated --- src/iec61850/client/client_goose_control.c | 91 ++++++++++++++++++++++ src/iec61850/inc/iec61850_client.h | 30 +++++-- src/vs/libiec61850-wo-goose.def | 4 +- src/vs/libiec61850.def | 4 +- 4 files changed, 119 insertions(+), 10 deletions(-) diff --git a/src/iec61850/client/client_goose_control.c b/src/iec61850/client/client_goose_control.c index 89c1a8a9..c2a5d05d 100644 --- a/src/iec61850/client/client_goose_control.c +++ b/src/iec61850/client/client_goose_control.c @@ -183,6 +183,97 @@ newEmptyPhyCommAddress(void) { return self; } +PhyComAddress +ClientGooseControlBlock_getDstAddress(ClientGooseControlBlock self) +{ + PhyComAddress retVal; + memset(&retVal, 0, sizeof(retVal)); + + if (self->dstAddress == NULL) goto exit_error; + + if (MmsValue_getType(self->dstAddress) != MMS_STRUCTURE) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - addr has wrong type\n"); + goto exit_error; + } + + if (MmsValue_getArraySize(self->dstAddress) != 4) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - addr has wrong type\n"); + goto exit_error; + } + + MmsValue* addr = MmsValue_getElement(self->dstAddress, 0); + + if (MmsValue_getType(addr) != MMS_OCTET_STRING) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - addr has wrong type\n"); + goto exit_error; + } + + if (MmsValue_getOctetStringSize(addr) != 6) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - addr has wrong size\n"); + goto exit_error; + } + + uint8_t* addrBuf = MmsValue_getOctetStringBuffer(addr); + + memcpy(&(retVal.dstAddress), addrBuf, 6); + + MmsValue* prio = MmsValue_getElement(self->dstAddress, 1); + + if (MmsValue_getType(prio) != MMS_UNSIGNED) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - prio has wrong type\n"); + goto exit_error; + } + + retVal.vlanPriority = MmsValue_toUint32(prio); + + MmsValue* vid = MmsValue_getElement(self->dstAddress, 2); + + if (MmsValue_getType(vid) != MMS_UNSIGNED) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - vid has wrong type\n"); + goto exit_error; + } + + retVal.vlanId = MmsValue_toUint32(vid); + + MmsValue* appID = MmsValue_getElement(self->dstAddress, 3); + + if (MmsValue_getType(appID) != MMS_UNSIGNED) { + if (DEBUG_IED_CLIENT) printf("IED_CLIENT: GoCB - appID has wrong type\n"); + goto exit_error; + } + + retVal.appId = MmsValue_toUint32(appID); + +exit_error: + return retVal; +} + +void +ClientGooseControlBlock_setDstAddress(ClientGooseControlBlock self, PhyComAddress value) +{ + if (self->dstAddress == NULL) + self->dstAddress = newEmptyPhyCommAddress(); + + if (self->dstAddress) { + + MmsValue* addr = MmsValue_getElement(self->dstAddress, 0); + + MmsValue_setOctetString(addr, value.dstAddress, 6); + + MmsValue* prio = MmsValue_getElement(self->dstAddress, 1); + + MmsValue_setUint8(prio, value.vlanPriority); + + MmsValue* vid = MmsValue_getElement(self->dstAddress, 2); + + MmsValue_setUint16(vid, value.vlanId); + + MmsValue* appID = MmsValue_getElement(self->dstAddress, 3); + + MmsValue_setUint16(appID, value.appId); + } +} + MmsValue* ClientGooseControlBlock_getDstAddress_addr(ClientGooseControlBlock self) { diff --git a/src/iec61850/inc/iec61850_client.h b/src/iec61850/inc/iec61850_client.h index e790cad1..0cecd640 100644 --- a/src/iec61850/inc/iec61850_client.h +++ b/src/iec61850/inc/iec61850_client.h @@ -34,6 +34,14 @@ extern "C" { #include "mms_client_connection.h" #include "linked_list.h" +#ifndef DEPRECATED +#if defined(__GNUC__) || defined(__clang__) + #define DEPRECATED __attribute__((deprecated)) +#else + #define DEPRECATED +#endif +#endif + /** * * \defgroup iec61850_client_api_group IEC 61850/MMS client API */ @@ -545,28 +553,34 @@ ClientGooseControlBlock_getMaxTime(ClientGooseControlBlock self); bool ClientGooseControlBlock_getFixedOffs(ClientGooseControlBlock self); -MmsValue* /* MMS_OCTET_STRING */ -ClientGooseControlBlock_getDstAddress_addr(ClientGooseControlBlock self); +PhyComAddress +ClientGooseControlBlock_getDstAddress(ClientGooseControlBlock self); void +ClientGooseControlBlock_setDstAddress(ClientGooseControlBlock self, PhyComAddress value); + +DEPRECATED MmsValue* /* MMS_OCTET_STRING */ +ClientGooseControlBlock_getDstAddress_addr(ClientGooseControlBlock self); + +DEPRECATED void ClientGooseControlBlock_setDstAddress_addr(ClientGooseControlBlock self, MmsValue* macAddr); -uint8_t +DEPRECATED uint8_t ClientGooseControlBlock_getDstAddress_priority(ClientGooseControlBlock self); -void +DEPRECATED void ClientGooseControlBlock_setDstAddress_priority(ClientGooseControlBlock self, uint8_t priorityValue); -uint16_t +DEPRECATED uint16_t ClientGooseControlBlock_getDstAddress_vid(ClientGooseControlBlock self); -void +DEPRECATED void ClientGooseControlBlock_setDstAddress_vid(ClientGooseControlBlock self, uint16_t vidValue); -uint16_t +DEPRECATED uint16_t ClientGooseControlBlock_getDstAddress_appid(ClientGooseControlBlock self); -void +DEPRECATED void ClientGooseControlBlock_setDstAddress_appid(ClientGooseControlBlock self, uint16_t appidValue); diff --git a/src/vs/libiec61850-wo-goose.def b/src/vs/libiec61850-wo-goose.def index d2defa15..9b5cb3e8 100644 --- a/src/vs/libiec61850-wo-goose.def +++ b/src/vs/libiec61850-wo-goose.def @@ -574,4 +574,6 @@ EXPORTS MmsServer_setLocalIpAddress MmsServer_isRunning IedServer_createWithTlsSupport - IedConnection_createWithTlsSupport \ No newline at end of file + IedConnection_createWithTlsSupport + ClientGooseControlBlock_getDstAddress + ClientGooseControlBlock_setDstAddress \ No newline at end of file diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index 909a3511..a5415dcb 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -655,4 +655,6 @@ EXPORTS MmsServer_setLocalIpAddress MmsServer_isRunning IedServer_createWithTlsSupport - IedConnection_createWithTlsSupport \ No newline at end of file + IedConnection_createWithTlsSupport + ClientGooseControlBlock_getDstAddress + ClientGooseControlBlock_setDstAddress \ No newline at end of file