提交 c30faa90 编写于 作者: C calin.cerchez

working on parser

上级 b0d09979
......@@ -32,26 +32,26 @@ RRC::~RRC() {
}
void RRC::initialize(int stage) {
char lac[2] = {0x5b, 0x10};
char tmsi[4] = {0x19, 0x02, 0x2c, 0xba};
std::vector<unsigned char> mcc;
std::vector<unsigned char> mnc;
mcc.push_back(2);
mcc.push_back(6);
mcc.push_back(0);
mnc.push_back(0);
mnc.push_back(2);
PlmnIdentity plmnId = PlmnIdentity(mcc, mnc);
Lai lai = Lai(plmnId, lac);
TmsiAndLaiGsmMap *tmsiAndLaiGsmMap = new TmsiAndLaiGsmMap(tmsi, lai);
InitialUeIdentity initUeId = InitialUeIdentity();
initUeId.setValue(tmsiAndLaiGsmMap, tmsiAndLai);
RRCConnectionRequest *rrcConnReq = new RRCConnectionRequest(initUeId, interRATCellReselection, noError);
UlCcchMessageType ulCchMessageType = UlCcchMessageType();
ulCchMessageType.setValue(rrcConnReq, rrcConnectionRequest);
UlCcchMessage ulCchMessage = UlCcchMessage(ulCchMessageType);
PerEncoder perEnc = PerEncoder(UNALIGNED);
perEnc.encodeSequence(ulCchMessage);
LTEUtils().printBytes(perEnc.getBuffer(), perEnc.getLength());
// char lac[2] = {0x5b, 0x10};
// char tmsi[4] = {0x19, 0x02, 0x2c, 0xba};
// std::vector<unsigned char> mcc;
// std::vector<unsigned char> mnc;
// mcc.push_back(2);
// mcc.push_back(6);
// mcc.push_back(0);
// mnc.push_back(0);
// mnc.push_back(2);
// PlmnIdentity plmnId = PlmnIdentity(mcc, mnc);
// Lai lai = Lai(plmnId, lac);
// TmsiAndLaiGsmMap *tmsiAndLaiGsmMap = new TmsiAndLaiGsmMap(tmsi, lai);
// InitialUeIdentity initUeId = InitialUeIdentity();
// initUeId.setValue(tmsiAndLaiGsmMap, tmsiAndLai);
// RRCConnectionRequest *rrcConnReq = new RRCConnectionRequest(initUeId, interRATCellReselection, noError);
// UlCcchMessageType ulCchMessageType = UlCcchMessageType();
// ulCchMessageType.setValue(rrcConnReq, rrcConnectionRequest);
// UlCcchMessage ulCchMessage = UlCcchMessage(ulCchMessageType);
// PerEncoder perEnc = PerEncoder(UNALIGNED);
// perEnc.encodeSequence(ulCchMessage);
// LTEUtils().printBytes(perEnc.getBuffer(), perEnc.getLength());
}
......@@ -1134,7 +1134,7 @@ InitialPriorityDelayList ::= SEQUENCE (SIZE (1..maxASC)) OF
NS-IP
InitialUE-Identity ::= CHOICE {
imsi IMSI-GSM-MAPIMSI-GSM-MAP,
imsi IMSI-GSM-MAP,
tmsi-and-LAI TMSI-and-LAI-GSM-MAP,
p-TMSI-and-RAI P-TMSI-and-RAI-GSM-MAP,
imei IMEI,
......
//
// Copyright (C) 2012 Calin Cerchez
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "RRCIe.h"
const void *Fdd::itemsInfo[1] = {
&MeasurementQuantity::theInfo
};
bool Fdd::itemsPres[1] = {
1
};
const Fdd::Info Fdd::theInfo = {
Fdd::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
1, 0, 0
};
const void *ImsiAndEsnDs41::itemsInfo[2] = {
&ImsiDs41::theInfo,
&EsnDs41::theInfo,
};
bool ImsiAndEsnDs41::itemsPres[2] = {
1,
1
};
const ImsiAndEsnDs41::Info ImsiAndEsnDs41::theInfo = {
ImsiAndEsnDs41::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
const void *IntegrityCheckInfo::itemsInfo[2] = {
&MessageAuthenticationCode::theInfo,
&RrcMessageSequenceNumber::theInfo,
};
bool IntegrityCheckInfo::itemsPres[2] = {
1,
1
};
const IntegrityCheckInfo::Info IntegrityCheckInfo::theInfo = {
IntegrityCheckInfo::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
Mcc *toMcc(std::vector<unsigned char> mcc) {
Mcc *ret = new Mcc();
for (unsigned i = 0; i < mcc.size(); i++)
ret->push_back(Digit(mcc.at(i)));
return ret;
}
std::vector<unsigned char> fromMcc(Mcc *mcc) {
std::vector<unsigned char> ret;
for (unsigned i = 0; i < mcc->size(); i++)
ret.push_back(static_cast<const Digit>(mcc->at(i)).getValue());
return ret;
}
Mnc *toMnc(std::vector<unsigned char> mnc) {
Mnc *ret = new Mnc();
for (unsigned i = 0; i < mnc.size(); i++)
ret->push_back(Digit(mnc.at(i)));
return ret;
}
std::vector<unsigned char> fromMnc(Mcc *mnc) {
std::vector<unsigned char> ret;
for (unsigned i = 0; i < mnc->size(); i++)
ret.push_back(static_cast<const Digit>(mnc->at(i)).getValue());
return ret;
}
const void *MeasurementQuantity::choicesInfo[4] = {
&CpichEcN0::theInfo,
&CpichRscp::theInfo,
&Pathloss::theInfo,
&Spare::theInfo,
};
const MeasurementQuantity::Info MeasurementQuantity::theInfo = {
MeasurementQuantity::create,
CHOICE,
0,
false,
choicesInfo,
3
};
const void *MeasuredResultsOnRACH::itemsInfo[2] = {
&DummyIe::theInfo,
&DummyIe::theInfo,
};
bool MeasuredResultsOnRACH::itemsPres[2] = {
1,
0
};
const MeasuredResultsOnRACH::Info MeasuredResultsOnRACH::theInfo = {
MeasuredResultsOnRACH::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 1, 0
};
const void *PlmnIdentity::itemsInfo[2] = {
&Mcc::theInfo,
&Mnc::theInfo,
};
bool PlmnIdentity::itemsPres[2] = {
1,
1
};
const PlmnIdentity::Info PlmnIdentity::theInfo = {
PlmnIdentity::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
PlmnIdentity::PlmnIdentity(std::vector<unsigned char>mcc, std::vector<unsigned char>mnc) : Sequence(&theInfo) {
setMcc(mcc);
setMnc(mnc);
}
const void *Lai::itemsInfo[2] = {
&PlmnIdentity::theInfo,
&Lac::theInfo,
};
bool Lai::itemsPres[2] = {
1,
1
};
const Lai::Info Lai::theInfo = {
Lai::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
Lai::Lai(PlmnIdentity& plmnId, char *lac) : Sequence(&theInfo) {
setPlmnIdentity(plmnId);
setLac(lac);
}
const void *Rai::itemsInfo[2] = {
&Lai::theInfo,
&RoutingAreaCode::theInfo,
};
bool Rai::itemsPres[2] = {
1,
1
};
const Rai::Info Rai::theInfo = {
Rai::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
const void *PTmsiAndRaiGsmMap::itemsInfo[2] = {
&PTmsiGsmMap::theInfo,
&Rai::theInfo,
};
bool PTmsiAndRaiGsmMap::itemsPres[2] = {
1,
1
};
const PTmsiAndRaiGsmMap::Info PTmsiAndRaiGsmMap::theInfo = {
PTmsiAndRaiGsmMap::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
const void *SfnSfnObsTimeDifference::choicesInfo[2] = {
&SfnSfnObsTimeDifference1::theInfo,
&SfnSfnObsTimeDifference2::theInfo,
};
const SfnSfnObsTimeDifference::Info SfnSfnObsTimeDifference::theInfo = {
SfnSfnObsTimeDifference::create,
CHOICE,
0,
false,
choicesInfo,
1
};
const void *Tdd::itemsInfo[2] = {
&TimeslotIscp::theInfo,
&PrimaryCcphRscp::theInfo
};
bool Tdd::itemsPres[2] = {
0,
0
};
const Tdd::Info Tdd::theInfo = {
Tdd::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 2, 0
};
const void *TmsiAndLaiGsmMap::itemsInfo[2] = {
&TmsiGsmMap::theInfo,
&Lai::theInfo,
};
bool TmsiAndLaiGsmMap::itemsPres[2] = {
1,
1
};
const TmsiAndLaiGsmMap::Info TmsiAndLaiGsmMap::theInfo = {
TmsiAndLaiGsmMap::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 0, 0
};
TmsiAndLaiGsmMap::TmsiAndLaiGsmMap(char *tmsi, Lai& lai) : Sequence(&theInfo) {
setTmsiGsmMap(tmsi);
setLai(lai);
}
const void *InitialUeIdentity::choicesInfo[8] = {
&ImsiGsmMap::theInfo,
&TmsiAndLaiGsmMap::theInfo,
&PTmsiAndRaiGsmMap::theInfo,
&Imei::theInfo,
&EsnDs41::theInfo,
&ImsiDs41::theInfo,
&ImsiAndEsnDs41::theInfo,
&TmsiDs41::theInfo,
};
const InitialUeIdentity::Info InitialUeIdentity::theInfo = {
InitialUeIdentity::create,
CHOICE,
0,
false,
choicesInfo,
7
};
const void *V3d0NonCriticalExtensions::itemsInfo[2] = {
&DummyIe::theInfo,
&DummyIe::theInfo,
};
bool V3d0NonCriticalExtensions::itemsPres[2] = {
1,
0
};
const V3d0NonCriticalExtensions::Info V3d0NonCriticalExtensions::theInfo = {
V3d0NonCriticalExtensions::create,
SEQUENCE,
0,
false,
itemsInfo,
itemsPres,
2, 1, 0
};
此差异已折叠。
......@@ -9,18 +9,16 @@ IMPORTS
hiRM,
maxAC,
MBMS-NeighbouringCellSCCPCH-r6 ::= SEQUENCE {
secondaryCCPCH-Info MBMS-CommonPhyChIdentity,
secondaryCCPCHPwrOffsetDiff MBMS-SCCPCHPwrOffsetDiff OPTIONAL,
layer1Combining CHOICE {
fdd SEQUENCE {
softComb-TimingOffset MBMS-SoftComb-TimingOffset,
mbms-L1CombiningTransmTimeDiff MBMS-L1CombiningTransmTimeDiff,
mbms-L1CombiningSchedule MBMS-L1CombiningSchedule OPTIONAL
},
tdd NULL
} OPTIONAL,
mbms-L23Configuration MBMS-L23Configuration
AllowedTFI-List ::= SEQUENCE (SIZE (1..maxTF)) OF
INTEGER (0..31)
GSM-MessageList ::= SEQUENCE (SIZE (1..maxInterSysMessages)) OF
BIT STRING (SIZE (1..512))
ReqDataBitAssistance ::= SEQUENCE {
ganssSignalID DGANSS-Sig-Id-Req,
ganssDataBitInterval INTEGER(0..15),
ganssSatelliteInfo SEQUENCE (SIZE (1..maxGANSSSat)) OF INTEGER(0..63) OPTIONAL
}
MBSFN-TDM-Info-List ::= SEQUENCE (SIZE (1..maxMBMSservUnmodif)) OF
......
......@@ -88,6 +88,39 @@ bool OpenType::encode(PerEncoder &encoder) const {
return encoder.encodeOpenType(*this);
}
const Boolean::Info Boolean::theInfo = {
&Boolean::create,
BOOLEAN,
0,
};
Boolean::Boolean(bool value, const void *info) : AbstractType(info) {
this->value = value;
}
Boolean& Boolean::operator=(const Boolean& other) {
this->value = other.value;
return *this;
}
int64_t Boolean::compare(const AbstractType& other) const {
const Boolean& that = dynamic_cast<const Boolean&>(other);
if (value == that.value)
return 1;
else
return -1;
}
bool Boolean::decode(char *buffer) {
return PerDecoder(buffer).decodeBoolean(*this);
}
bool Boolean::encode(PerEncoder &encoder) const {
return encoder.encodeBoolean(*this);
}
const Null::Info Null::theInfo = {
&Null::create,
_NULL,
......
......@@ -136,8 +136,8 @@ public:
/* Constructors. */
OpenType(const void *info = &theInfo) : AbstractType(info) {}
OpenType(char *val, int64_t len, const void *info = &theInfo);
OpenType(AbstractType *val, const void *info = &theInfo);
OpenType(char *value, int64_t length, const void *info = &theInfo);
OpenType(AbstractType *value, const void *info = &theInfo);
OpenType(const OpenType& other) : AbstractType(other) { operator=(other); }
virtual ~OpenType() {}
......@@ -163,6 +163,42 @@ public:
bool encode(PerEncoder& encoder) const;
};
/*
* Class for ASN.1 BOOLEAN type
*/
class Boolean : public AbstractType {
private:
bool value;
public:
static const Info theInfo;
/* Constructors. */
Boolean(const void *info = &theInfo) : AbstractType(info) {}
Boolean(bool val, const void *info = &theInfo);
Boolean(const Boolean& other) : AbstractType(other) { operator=(other); }
virtual ~Boolean() {}
/* Operator methods. */
Boolean &operator=(const Boolean& other);
/* Setter methods. */
void setValue(bool value) { this->value = value; }
/* Getter methods. */
bool getValue() const { return value; }
/* Utility methods. */
virtual AbstractType *clone() const { return new Boolean(*this); }
virtual int64_t compare(const AbstractType& other) const;
static AbstractType *create(const void *info) { return new Boolean(info); }
/* Wrapper methods. */
bool decode(char *buffer);
bool encode(PerEncoder& encoder) const;
};
/*
* Class for ASN.1 NULL type
*/
......@@ -172,7 +208,7 @@ public:
/* Constructors. */
Null(const void *info = &theInfo) : AbstractType(info) {}
Null(const OpenType& other) : AbstractType(other) { operator=(other); }
Null(const Null& other) : AbstractType(other) { operator=(other); }
virtual ~Null() {}
......
......@@ -173,6 +173,8 @@ bool PerDecoder::decodeAbstractType(AbstractType& abstractType) {
return decodeBitString(dynamic_cast<BitStringBase&>(abstractType));
case OCTETSTRING:
return decodeOctetString(dynamic_cast<OctetStringBase&>(abstractType));
case BOOLEAN:
return decodeBoolean(dynamic_cast<Boolean&>(abstractType));
case _NULL:
return decodeNull(dynamic_cast<Null&>(abstractType));
case SEQUENCE:
......@@ -198,6 +200,11 @@ bool PerDecoder::decodeOpenType(OpenType& openType) {
return true;
}
bool PerDecoder::decodeBoolean(Boolean& boolean) {
boolean.setValue(decodeBits(1));
return true;
}
bool PerDecoder::decodeNull(Null& null) {
return true;
}
......
......@@ -58,6 +58,7 @@ public:
/* Decoding methods. */
bool decodeAbstractType(AbstractType& abstractType);
bool decodeOpenType(OpenType& openType);
bool decodeBoolean(Boolean& boolean);
bool decodeNull(Null& null);
bool decodeInteger(IntegerBase& integer);
bool decodeEnumerated(EnumeratedBase& enumerated);
......
......@@ -196,6 +196,8 @@ bool PerEncoder::encodeAbstractType(const AbstractType& abstractType) {
return encodeBitString(static_cast<const BitStringBase&>(abstractType));
case OCTETSTRING:
return encodeOctetString(static_cast<const OctetStringBase&>(abstractType));
case BOOLEAN:
return encodeBoolean(static_cast<const Boolean&>(abstractType));
case _NULL:
return encodeNull(static_cast<const Null&>(abstractType));
case SEQUENCE:
......@@ -224,6 +226,11 @@ bool PerEncoder::encodeOpenType(const OpenType& openType) {
return true;
}
bool PerEncoder::encodeBoolean(const Boolean& boolean) {
encodeBits(boolean.getValue(), 1);
return true;
}
bool PerEncoder::encodeNull(const Null& null) {
return true;
}
......
......@@ -59,6 +59,7 @@ public:
/* Encoding methods */
bool encodeAbstractType(const AbstractType& abstractType);
bool encodeOpenType(const OpenType& openType);
bool encodeBoolean(const Boolean& boolean);
bool encodeNull(const Null& null);
bool encodeInteger(const IntegerBase& integer);
bool encodeEnumerated(const EnumeratedBase& enumerated);
......
......@@ -11,14 +11,17 @@ sequencetxt = 'SEQUENCE'
choicetxt = 'CHOICE'
enumeratedtxt = 'ENUMERATED'
nulltxt = 'NULL'
booleantxt = 'BOOLEAN'
asnobjs = list()
openparanthesis = '('
closedparanthesis = ')'
importstxt = 'IMPORTS'
optionaltxt = 'OPTIONAL'
defaulttxt = 'DEFAULT'
endtxt = 'END'
oftxt = ' OF '
size = 'SIZE'
comment = '-- '
comment = '--'
comma = ','
tripledash = '...'
typeslist = ['Integer',
......@@ -28,7 +31,8 @@ typeslist = ['Integer',
'Sequence',
'SequenceOf',
'Choice',
'_Null']
'_Null',
'Boolean']
class ASNObject:
type = ''
......@@ -107,9 +111,14 @@ def parsesize(asnobj, string):
def parsetype(asnobj, string):
type = ""
if string.split()[-1] == optionaltxt:
asnobj.opt = 1
string = string.split(optionaltxt)[0].strip()
if defaulttxt in string:
asnobj.opt = 1
string = string.split(defaulttxt)[0].strip()
for i in range(0, len(string)):
if string[i] == openparanthesis or string[i] == openbracket or string[i] == comma:
break
......@@ -124,7 +133,7 @@ def parsetype(asnobj, string):
elif type == octetstringtxt:
asnobj.type = "OctetString"
elif type == sequencetxt:
if ' OF ' in string:
if oftxt in string and openbracket not in string:
asnobj.type = "SequenceOf"
else:
asnobj.type = "Sequence"
......@@ -134,16 +143,17 @@ def parsetype(asnobj, string):
asnobj.type = "Enumerated"
elif type == nulltxt:
asnobj.type = "_Null"
elif type == booleantxt:
asnobj.type = "Boolean"
else:
asnobj.type = type.replace("-", "")
def parsestring(string):
asnobj = ASNObject()
words = list()
if importstxt in string:
return asnobj
if assign in string:
string = string.replace("\t", ' ')
string = string.replace("\n", '')
......@@ -154,7 +164,7 @@ def parsestring(string):
words = string.split(' ', 1)
asnobj.name = words[0].replace("-", "_").strip()
#print string
if len(words) > 1:
parsetype(asnobj, words[1])
if asnobj.type != "Enumerated":
......@@ -181,8 +191,12 @@ def parsestring(string):
if asnobj.type == "SequenceOf":
objs = list()
obj = ASNObject()
obj.type = words[1].split()[-1].replace("-", "")
objstring = words[1].split(oftxt)[1]
objstring = asnobj.name + "Item " + objstring
obj = parsestring(objstring.strip())
objs.append(obj)
asnobj.objs = objs
return asnobj
......@@ -221,11 +235,11 @@ def checkandhandledeps(asnobj, hdrfile, srcfile):
def writeobject(asnobj, hdrfile, srcfile):
if asnobj.written == 0:
# Null
# Null and Boolean
if asnobj.type == "_Null":
if asnobj.type == "_Null" or asnobj.type == "Boolean":
hdrfile.write("typedef " + asnobj.type + " " + asnobj.name + ";\n")
asnobj.type = asnobj.name
hdrfile.write("typedef _Null " + asnobj.name + ";\n")
# Constraint types
......@@ -334,6 +348,24 @@ def writeobject(asnobj, hdrfile, srcfile):
srcfile.write("\n")
asnobj.written = 1
def writeheader(file):
file.write("//\n" +
"// Copyright (C) 2012 Calin Cerchez\n" +
"//\n" +
"// This program is free software: you can redistribute it and/or modify\n" +
"// it under the terms of the GNU Lesser General Public License as published by\n" +
"// the Free Software Foundation, either version 3 of the License, or\n" +
"// (at your option) any later version.\n" +
"//\n" +
"// This program is distributed in the hope that it will be useful,\n" +
"// but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
"// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
"// GNU Lesser General Public License for more details.\n" +
"//\n" +
"// You should have received a copy of the GNU Lesser General Public License\n" +
"// along with this program. If not, see http://www.gnu.org/licenses/.\n" +
"//\n\n")
def main():
usage = "usage: %prog [options] input filename"
parser = OptionParser(usage)
......@@ -342,9 +374,10 @@ def main():
(options, args) = parser.parse_args()
filename = "rrc_ie_def"
directory = "/root/Desktop/omnetpp-4.2.2/samples/4Gsim/src/linklayer/lte/rrc/message/"
filename = "RRCIe"
file = open(filename + ".asn", "r")
file = open(directory + filename + ".asn", "r")
lines = file.readlines()
file.close()
......@@ -356,18 +389,30 @@ def main():
if len(objectstring) > 0:
asnobjs.append(parsestring(objectstring))
objectstring = line
elif comment not in line and line != "\n":
elif comment not in line and line != "\n" and line[:-1] != endtxt:
objectstring += line
asnobjs.append(parsestring(objectstring))
#printobjects(asnobjs)
print ("writing source files...")
hdrfile = open(filename + ".h", 'w')
srcfile = open(filename + ".cc", 'w')
hdrfile = open(directory + filename + ".h", 'w')
srcfile = open(directory + filename + ".cc", 'w')
writeheader(hdrfile)
writeheader(srcfile)
hdrfile.write("#ifndef " + filename.upper() + "_H_\n" +
"#define " + filename.upper() + "_H_\n\n" +
"#include \"ASNTypes.h\"\n\n")
srcfile.write("#include \"" + filename + ".h\"\n\n")
for i in range (0, len(asnobjs)):
asnobj = asnobjs[i]
writeobject(asnobj, hdrfile, srcfile)
hdrfile.write("#endif /* " + filename.upper() + "_H_ */\n")
srcfile.close()
hdrfile.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册