Steven Blair / rapid61850example
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gse.c Source File

gse.c

00001 /**
00002  * Rapid-prototyping protection schemes with IEC 61850
00003  *
00004  * Copyright (c) 2011 Steven Blair
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "gsePacketData.h"
00022 #include "gseDecode.h"
00023 #include "gseEncode.h"
00024 
00025 struct gseData ItlPositions_Itl;
00026 struct gseData SyckResult_SynChk;
00027 struct gseData MMXUResult_MMXUResult;
00028 
00029 
00030 
00031 
00032 // returns 1 if buf contains valid packet data
00033 int gse_send_ItlPositions_Itl(unsigned char *buf, CTYPE_BOOLEAN statusChange, CTYPE_INT32U timeAllowedToLive) {
00034     ItlPositions_Itl.timeAllowedToLive = timeAllowedToLive;
00035 
00036     if (statusChange) {
00037         ItlPositions_Itl.stNum++;
00038         if (ItlPositions_Itl.stNum == 0) {
00039             ItlPositions_Itl.stNum = 1;
00040         }
00041         ItlPositions_Itl.sqNum = 0;
00042     }
00043     else {
00044         ItlPositions_Itl.sqNum++;
00045         if (ItlPositions_Itl.sqNum == 0) {
00046             ItlPositions_Itl.sqNum = 1;
00047         }
00048     }
00049 
00050     return gseEncodePacket(&ItlPositions_Itl, buf);
00051 }
00052 
00053 // returns 1 if buf contains valid packet data
00054 int gse_send_SyckResult_SynChk(unsigned char *buf, CTYPE_BOOLEAN statusChange, CTYPE_INT32U timeAllowedToLive) {
00055     SyckResult_SynChk.timeAllowedToLive = timeAllowedToLive;
00056 
00057     if (statusChange) {
00058         SyckResult_SynChk.stNum++;
00059         if (SyckResult_SynChk.stNum == 0) {
00060             SyckResult_SynChk.stNum = 1;
00061         }
00062         SyckResult_SynChk.sqNum = 0;
00063     }
00064     else {
00065         SyckResult_SynChk.sqNum++;
00066         if (SyckResult_SynChk.sqNum == 0) {
00067             SyckResult_SynChk.sqNum = 1;
00068         }
00069     }
00070 
00071     return gseEncodePacket(&SyckResult_SynChk, buf);
00072 }
00073 
00074 // returns 1 if buf contains valid packet data
00075 int gse_send_MMXUResult_MMXUResult(unsigned char *buf, CTYPE_BOOLEAN statusChange, CTYPE_INT32U timeAllowedToLive) {
00076     MMXUResult_MMXUResult.timeAllowedToLive = timeAllowedToLive;
00077 
00078     if (statusChange) {
00079         MMXUResult_MMXUResult.stNum++;
00080         if (MMXUResult_MMXUResult.stNum == 0) {
00081             MMXUResult_MMXUResult.stNum = 1;
00082         }
00083         MMXUResult_MMXUResult.sqNum = 0;
00084     }
00085     else {
00086         MMXUResult_MMXUResult.sqNum++;
00087         if (MMXUResult_MMXUResult.sqNum == 0) {
00088             MMXUResult_MMXUResult.sqNum = 1;
00089         }
00090     }
00091 
00092     return gseEncodePacket(&MMXUResult_MMXUResult, buf);
00093 }
00094 
00095 void init_gse() {
00096     ItlPositions_Itl.ethHeaderData.destMACAddress[0] = 0x01;
00097     ItlPositions_Itl.ethHeaderData.destMACAddress[1] = 0x0C;
00098     ItlPositions_Itl.ethHeaderData.destMACAddress[2] = 0xCD;
00099     ItlPositions_Itl.ethHeaderData.destMACAddress[3] = 0x01;
00100     ItlPositions_Itl.ethHeaderData.destMACAddress[4] = 0x00;
00101     ItlPositions_Itl.ethHeaderData.destMACAddress[5] = 0x04;
00102     ItlPositions_Itl.ethHeaderData.APPID = 0x3000;
00103     ItlPositions_Itl.ethHeaderData.VLAN_PRIORITY = 0x4;
00104     ItlPositions_Itl.ethHeaderData.VLAN_ID = 4;
00105     ItlPositions_Itl.goID = (unsigned char *) malloc(4);
00106     strncpy((char *) ItlPositions_Itl.goID, "Itl\0", 4);
00107     ItlPositions_Itl.t = 0;
00108     ItlPositions_Itl.gocbRef = (unsigned char *) malloc(28);
00109     strncpy((char *) ItlPositions_Itl.gocbRef, "E1Q1SB1C1/LLN0$ItlPositions\0", 28);
00110     ItlPositions_Itl.datSet = (unsigned char *) malloc(25);
00111     strncpy((char *) ItlPositions_Itl.datSet, "E1Q1SB1C1/LLN0$Positions\0", 25);
00112     ItlPositions_Itl.timeAllowedToLive = 0;
00113     ItlPositions_Itl.stNum = 0;
00114     ItlPositions_Itl.sqNum = 0;
00115     ItlPositions_Itl.test = 0;
00116     ItlPositions_Itl.confRev = 1;
00117     ItlPositions_Itl.ndsCom = 0;
00118     ItlPositions_Itl.numDatSetEntries = 6;
00119     ItlPositions_Itl.encodeDataset = &ber_encode_Itl;
00120     ItlPositions_Itl.getDatasetLength = &ber_get_length_Itl;
00121 
00122     SyckResult_SynChk.ethHeaderData.destMACAddress[0] = 0x01;
00123     SyckResult_SynChk.ethHeaderData.destMACAddress[1] = 0x0C;
00124     SyckResult_SynChk.ethHeaderData.destMACAddress[2] = 0xCD;
00125     SyckResult_SynChk.ethHeaderData.destMACAddress[3] = 0x01;
00126     SyckResult_SynChk.ethHeaderData.destMACAddress[4] = 0x00;
00127     SyckResult_SynChk.ethHeaderData.destMACAddress[5] = 0x02;
00128     SyckResult_SynChk.ethHeaderData.APPID = 0x3001;
00129     SyckResult_SynChk.ethHeaderData.VLAN_PRIORITY = 0x4;
00130     SyckResult_SynChk.ethHeaderData.VLAN_ID = 4;
00131     SyckResult_SynChk.goID = (unsigned char *) malloc(7);
00132     strncpy((char *) SyckResult_SynChk.goID, "SynChk\0", 7);
00133     SyckResult_SynChk.t = 0;
00134     SyckResult_SynChk.gocbRef = (unsigned char *) malloc(26);
00135     strncpy((char *) SyckResult_SynChk.gocbRef, "D1Q1SB4C1/LLN0$SyckResult\0", 26);
00136     SyckResult_SynChk.datSet = (unsigned char *) malloc(26);
00137     strncpy((char *) SyckResult_SynChk.datSet, "D1Q1SB4C1/LLN0$SyckResult\0", 26);
00138     SyckResult_SynChk.timeAllowedToLive = 0;
00139     SyckResult_SynChk.stNum = 0;
00140     SyckResult_SynChk.sqNum = 0;
00141     SyckResult_SynChk.test = 0;
00142     SyckResult_SynChk.confRev = 0;
00143     SyckResult_SynChk.ndsCom = 0;
00144     SyckResult_SynChk.numDatSetEntries = 1;
00145     SyckResult_SynChk.encodeDataset = &ber_encode_SynChk;
00146     SyckResult_SynChk.getDatasetLength = &ber_get_length_SynChk;
00147 
00148     MMXUResult_MMXUResult.ethHeaderData.destMACAddress[0] = 0x01;
00149     MMXUResult_MMXUResult.ethHeaderData.destMACAddress[1] = 0x0C;
00150     MMXUResult_MMXUResult.ethHeaderData.destMACAddress[2] = 0xCD;
00151     MMXUResult_MMXUResult.ethHeaderData.destMACAddress[3] = 0x01;
00152     MMXUResult_MMXUResult.ethHeaderData.destMACAddress[4] = 0x00;
00153     MMXUResult_MMXUResult.ethHeaderData.destMACAddress[5] = 0x02;
00154     MMXUResult_MMXUResult.ethHeaderData.APPID = 0x3001;
00155     MMXUResult_MMXUResult.ethHeaderData.VLAN_PRIORITY = 0x4;
00156     MMXUResult_MMXUResult.ethHeaderData.VLAN_ID = 4;
00157     MMXUResult_MMXUResult.goID = (unsigned char *) malloc(11);
00158     strncpy((char *) MMXUResult_MMXUResult.goID, "MMXUResult\0", 11);
00159     MMXUResult_MMXUResult.t = 0;
00160     MMXUResult_MMXUResult.gocbRef = (unsigned char *) malloc(26);
00161     strncpy((char *) MMXUResult_MMXUResult.gocbRef, "D1Q1SB4C1/LLN0$MMXUResult\0", 26);
00162     MMXUResult_MMXUResult.datSet = (unsigned char *) malloc(26);
00163     strncpy((char *) MMXUResult_MMXUResult.datSet, "D1Q1SB4C1/LLN0$MMXUResult\0", 26);
00164     MMXUResult_MMXUResult.timeAllowedToLive = 0;
00165     MMXUResult_MMXUResult.stNum = 0;
00166     MMXUResult_MMXUResult.sqNum = 0;
00167     MMXUResult_MMXUResult.test = 0;
00168     MMXUResult_MMXUResult.confRev = 0;
00169     MMXUResult_MMXUResult.ndsCom = 0;
00170     MMXUResult_MMXUResult.numDatSetEntries = 1;
00171     MMXUResult_MMXUResult.encodeDataset = &ber_encode_MMXUResult;
00172     MMXUResult_MMXUResult.getDatasetLength = &ber_get_length_MMXUResult;
00173 
00174 }
00175