提交 265a3291 编写于 作者: C calin cerchez

rrc working

上级 68c52c4e
Session Transcript
February 21, 2006 16:45:20.5186
NAS_RRC_LTE.1/nas_rrc_r8_lte/1/ s tm 0.0 l $2119022cba260012d88280
......@@ -39,6 +39,7 @@ tkenv-plugin-path = ../../../etc/plugins
**.sgw.dumpFile = "sgw.pcap"
**.ext[0].device = "eth1"
**.pgw.numExtInterfaces = 1
**.dctDump.dumpFile = "dct.pcap"
# access point
......
//
// 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
......
//
// 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 "PDCP.h"
Define_Module(PDCP);
PDCP::PDCP() {
// TODO Auto-generated constructor stub
}
PDCP::~PDCP() {
// TODO Auto-generated destructor stub
}
//
// 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/.
//
#ifndef PDCP_H_
#define PDCP_H_
#include <omnetpp.h>
class PDCP : public cSimpleModule {
public:
PDCP();
virtual ~PDCP();
};
#endif /* PDCP_H_ */
//
// 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/.
//
package inet.linklayer.lte.pdcp;
simple PDCP
{
}
\ No newline at end of file
......@@ -16,7 +16,7 @@
//
#include "RRC.h"
//#include "RRCMessage.h"
#include "RRCMessage_m.h"
#include "PerEncoder.h"
#include "LTEUtils.h"
......@@ -33,7 +33,9 @@ RRC::~RRC() {
void RRC::initialize(int stage) {
using namespace rrc;
ULCCCHMessage ulcchMessage = ULCCCHMessage();
char lac[2] = {0x5b, 0x10};
char tmsi[4] = {0x19, 0x02, 0x2c, 0xba};
MNC mnc = MNC();
MCC mcc = MCC();
mcc.push_back(new Digit(2));
......@@ -41,38 +43,49 @@ void RRC::initialize(int stage) {
mcc.push_back(new Digit(0));
mnc.push_back(new Digit(0));
mnc.push_back(new Digit(2));
PLMNIdentity plmnId = PLMNIdentity();
plmnId.setMcc(mcc);
plmnId.setMnc(mnc);
char lac[2] = {0x5b, 0x10};
LAI lai = LAI();
lai.setPlmnIdentity(plmnId);
lai.setLAILac(LAILac(lac));
TMSIandLAIGSMMAP *tMSIandLAIGSMMAP = new TMSIandLAIGSMMAP();
char tmsi[4] = {0x19, 0x02, 0x2c, 0xba};
tMSIandLAIGSMMAP->setTmsi(TMSIGSMMAP(tmsi));
tMSIandLAIGSMMAP->setLai(lai);
PLMNIdentity plmnId = PLMNIdentity(mcc, mnc);
// plmnId.setMcc(mcc);
// plmnId.setMnc(mnc);
LAI lai = LAI(plmnId, LAILac(lac));
// lai.setPlmnIdentity(plmnId);
// lai.setLAILac(LAILac(lac));
TMSIandLAIGSMMAP *tMSIandLAIGSMMAP = new TMSIandLAIGSMMAP(TMSIGSMMAP(tmsi), lai);
// tMSIandLAIGSMMAP->setTmsi(TMSIGSMMAP(tmsi));
// tMSIandLAIGSMMAP->setLai(lai);
InitialUEIdentity initUeId = InitialUEIdentity();
initUeId.setValue(tMSIandLAIGSMMAP, InitialUEIdentity::tmsiandLAI);
RRCConnectionRequest *rrcConnReq = new RRCConnectionRequest(initUeId, EstablishmentCause(interRAT_CellReselection_EstablishmentCause), ProtocolErrorIndicator(noError_ProtocolErrorIndicator));
// rrcConnReq->setInitialUEIdentity(initUeId);
// rrcConnReq->setEstablishmentCause(EstablishmentCause(interRAT_CellReselection_EstablishmentCause));
// rrcConnReq->setProtocolErrorIndicator(ProtocolErrorIndicator(noError_ProtocolErrorIndicator));
// MeasuredResultsOnRACH measResOnRach = MeasuredResultsOnRACH();
// MeasuredResultsOnRACHCurrentCell measResOnRachCurrCell = MeasuredResultsOnRACHCurrentCell();
// MeasuredResultsOnRACHCurrentCellModeSpecificInfo measResOnRachCurrCellModeSpecInfo = MeasuredResultsOnRACHCurrentCellModeSpecificInfo();
// MeasuredResultsOnRACHCurrentCellModeSpecificInfoFdd *measResOnRachCurrCellModeSpecInfoFdd = new MeasuredResultsOnRACHCurrentCellModeSpecificInfoFdd();
// MeasuredResultsOnRACHCurrentCellModeSpecificInfoFddMeasurementQuantity measResOnRachCurrCellModeSpecInfoFddQuant = MeasuredResultsOnRACHCurrentCellModeSpecificInfoFddMeasurementQuantity();
// measResOnRachCurrCellModeSpecInfoFddQuant.setValue(new CPICHEcN0(37), MeasuredResultsOnRACHCurrentCellModeSpecificInfoFddMeasurementQuantity::cpichEcN0);
// measResOnRachCurrCellModeSpecInfoFdd->setMeasuredResultsOnRACHCurrentCellModeSpecificInfoFddMeasurementQuantity(measResOnRachCurrCellModeSpecInfoFddQuant);
// measResOnRachCurrCellModeSpecInfo.setValue(measResOnRachCurrCellModeSpecInfoFdd, MeasuredResultsOnRACHCurrentCellModeSpecificInfo::measuredResultsOnRACHCurrentCellModeSpecificInfoFdd);
// measResOnRachCurrCell.setMeasuredResultsOnRACHCurrentCellModeSpecificInfo(measResOnRachCurrCellModeSpecInfo);
// measResOnRach.setMeasuredResultsOnRACHCurrentCell(measResOnRachCurrCell);
// rrcConnReq->setMeasuredResultsOnRACH(measResOnRach);
// rrcConnReq->setOptFlag(0, true);
ULCCCHMessageType ulccchMessageType = ULCCCHMessageType();
ulccchMessageType.setValue(rrcConnReq, ULCCCHMessageType::rrcConnectionRequest);
ULCCCHMessage ulccchMessage = ULCCCHMessage();
ulccchMessage.setMessage(ulccchMessageType);
PerEncoder perEnc = PerEncoder(UNALIGNED);
perEnc.encodeSequence(ulccchMessage);
LTEUtils().printBytes(perEnc.getBuffer(), perEnc.getLength());
RRCMessage *rrcMsg = new RRCMessage();
rrcMsg->setValueArraySize(perEnc.getLength());
for (unsigned i = 0; i < rrcMsg->getValueArraySize(); i++) {
rrcMsg->setValue(i, perEnc.getByteAt(i));
}
send(rrcMsg, gate("rlcOut"));
}
void RRC::handleMessage(cMessage *msg) {
// 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());
}
......@@ -27,6 +27,7 @@ public:
virtual ~RRC();
void initialize(int stage);
void handleMessage(cMessage *msg);
};
#endif /* RRC_H_ */
......@@ -19,5 +19,9 @@ package inet.linklayer.lte.rrc;
simple RRC
{
gates:
input nasIn;
output nasOut;
input rlcIn;
output rlcOut;
}
\ No newline at end of file
......@@ -79,6 +79,9 @@ const DLDCCHMessage::Info DLDCCHMessage::theInfo = {
itemsPres,
2, 1, 0
};
DLDCCHMessage::DLDCCHMessage(const DLDCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *ULDCCHMessageType::choicesInfo[32] = {
&ActiveSetUpdateComplete::theInfo,
......@@ -140,6 +143,9 @@ const ULDCCHMessage::Info ULDCCHMessage::theInfo = {
itemsPres,
2, 1, 0
};
ULDCCHMessage::ULDCCHMessage(const ULDCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *DLCCCHMessageType::choicesInfo[8] = {
&CellUpdateConfirmCCCH::theInfo,
......@@ -177,6 +183,9 @@ const DLCCCHMessage::Info DLCCCHMessage::theInfo = {
itemsPres,
2, 1, 0
};
DLCCCHMessage::DLCCCHMessage(const DLCCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *ULCCCHMessageType::choicesInfo[4] = {
&CellUpdate::theInfo,
......@@ -210,6 +219,9 @@ const ULCCCHMessage::Info ULCCCHMessage::theInfo = {
itemsPres,
2, 1, 0
};
ULCCCHMessage::ULCCCHMessage(const ULCCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *PCCHMessageType::choicesInfo[2] = {
&PagingType1::theInfo,
......@@ -239,6 +251,9 @@ const PCCHMessage::Info PCCHMessage::theInfo = {
itemsPres,
1, 0, 0
};
PCCHMessage::PCCHMessage(const PCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *DLSHCCHMessageType::choicesInfo[2] = {
&PhysicalSharedChannelAllocation::theInfo,
......@@ -268,6 +283,9 @@ const DLSHCCHMessage::Info DLSHCCHMessage::theInfo = {
itemsPres,
1, 0, 0
};
DLSHCCHMessage::DLSHCCHMessage(const DLSHCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *ULSHCCHMessageType::choicesInfo[2] = {
&PUSCHCapacityRequest::theInfo,
......@@ -297,6 +315,9 @@ const ULSHCCHMessage::Info ULSHCCHMessage::theInfo = {
itemsPres,
1, 0, 0
};
ULSHCCHMessage::ULSHCCHMessage(const ULSHCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *BCCHFACHMessageType::choicesInfo[4] = {
&SystemInformationFACH::theInfo,
......@@ -328,6 +349,9 @@ const BCCHFACHMessage::Info BCCHFACHMessage::theInfo = {
itemsPres,
1, 0, 0
};
BCCHFACHMessage::BCCHFACHMessage(const BCCHFACHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *BCCHBCHMessage::itemsInfo[1] = {
&SystemInformationBCH::theInfo,
......@@ -344,6 +368,9 @@ const BCCHBCHMessage::Info BCCHBCHMessage::theInfo = {
itemsPres,
1, 0, 0
};
BCCHBCHMessage::BCCHBCHMessage(const SystemInformationBCH& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *MCCHMessageType::choicesInfo[16] = {
&MBMSAccessInformation::theInfo,
......@@ -387,6 +414,9 @@ const MCCHMessage::Info MCCHMessage::theInfo = {
itemsPres,
1, 0, 0
};
MCCHMessage::MCCHMessage(const MCCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
const void *MSCHMessageType::choicesInfo[4] = {
&MBMSSchedulingInformation::theInfo,
......@@ -418,5 +448,8 @@ const MSCHMessage::Info MSCHMessage::theInfo = {
itemsPres,
1, 0, 0
};
MSCHMessage::MSCHMessage(const MSCHMessageType& message) : Sequence(&theInfo) {
setMessage(message);
}
}
......@@ -79,6 +79,7 @@ private:
public:
static const Info theInfo;
DLDCCHMessage(): Sequence(&theInfo) {}
DLDCCHMessage(const DLDCCHMessageType& message);
void setIntegrityCheckInfo(const IntegrityCheckInfo& integrityCheckInfo) { *static_cast<IntegrityCheckInfo*>(items[0]) = integrityCheckInfo; }
void setMessage(const DLDCCHMessageType& message) { *static_cast<DLDCCHMessageType*>(items[1]) = message; }
......@@ -135,6 +136,7 @@ private:
public:
static const Info theInfo;
ULDCCHMessage(): Sequence(&theInfo) {}
ULDCCHMessage(const ULDCCHMessageType& message);
void setIntegrityCheckInfo(const IntegrityCheckInfo& integrityCheckInfo) { *static_cast<IntegrityCheckInfo*>(items[0]) = integrityCheckInfo; }
void setMessage(const ULDCCHMessageType& message) { *static_cast<ULDCCHMessageType*>(items[1]) = message; }
......@@ -169,6 +171,7 @@ private:
public:
static const Info theInfo;
DLCCCHMessage(): Sequence(&theInfo) {}
DLCCCHMessage(const DLCCCHMessageType& message);
void setIntegrityCheckInfo(const IntegrityCheckInfo& integrityCheckInfo) { *static_cast<IntegrityCheckInfo*>(items[0]) = integrityCheckInfo; }
void setMessage(const DLCCCHMessageType& message) { *static_cast<DLCCCHMessageType*>(items[1]) = message; }
......@@ -197,6 +200,7 @@ private:
public:
static const Info theInfo;
ULCCCHMessage(): Sequence(&theInfo) {}
ULCCCHMessage(const ULCCCHMessageType& message);
void setIntegrityCheckInfo(const IntegrityCheckInfo& integrityCheckInfo) { *static_cast<IntegrityCheckInfo*>(items[0]) = integrityCheckInfo; }
void setMessage(const ULCCCHMessageType& message) { *static_cast<ULCCCHMessageType*>(items[1]) = message; }
......@@ -223,6 +227,7 @@ private:
public:
static const Info theInfo;
PCCHMessage(): Sequence(&theInfo) {}
PCCHMessage(const PCCHMessageType& message);
void setMessage(const PCCHMessageType& message) { *static_cast<PCCHMessageType*>(items[0]) = message; }
};
......@@ -248,6 +253,7 @@ private:
public:
static const Info theInfo;
DLSHCCHMessage(): Sequence(&theInfo) {}
DLSHCCHMessage(const DLSHCCHMessageType& message);
void setMessage(const DLSHCCHMessageType& message) { *static_cast<DLSHCCHMessageType*>(items[0]) = message; }
};
......@@ -273,6 +279,7 @@ private:
public:
static const Info theInfo;
ULSHCCHMessage(): Sequence(&theInfo) {}
ULSHCCHMessage(const ULSHCCHMessageType& message);
void setMessage(const ULSHCCHMessageType& message) { *static_cast<ULSHCCHMessageType*>(items[0]) = message; }
};
......@@ -302,6 +309,7 @@ private:
public:
static const Info theInfo;
BCCHFACHMessage(): Sequence(&theInfo) {}
BCCHFACHMessage(const BCCHFACHMessageType& message);
void setMessage(const BCCHFACHMessageType& message) { *static_cast<BCCHFACHMessageType*>(items[0]) = message; }
};
......@@ -313,6 +321,7 @@ private:
public:
static const Info theInfo;
BCCHBCHMessage(): Sequence(&theInfo) {}
BCCHBCHMessage(const SystemInformationBCH& message);
void setMessage(const SystemInformationBCH& message) { *static_cast<SystemInformationBCH*>(items[0]) = message; }
};
......@@ -368,6 +377,7 @@ private:
public:
static const Info theInfo;
MCCHMessage(): Sequence(&theInfo) {}
MCCHMessage(const MCCHMessageType& message);
void setMessage(const MCCHMessageType& message) { *static_cast<MCCHMessageType*>(items[0]) = message; }
};
......@@ -399,6 +409,7 @@ private:
public:
static const Info theInfo;
MSCHMessage(): Sequence(&theInfo) {}
MSCHMessage(const MSCHMessageType& message);
void setMessage(const MSCHMessageType& message) { *static_cast<MSCHMessageType*>(items[0]) = message; }
};
......
//
// 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/.
//
message RRCMessage
{
char value[];
}
\ No newline at end of file
......@@ -17,10 +17,12 @@
package inet.nodes._4gsim;
import inet.linklayer.lte.rrc.RRC;
import inet.networklayer.ipv4.RoutingTable;
import inet.networklayer.common.InterfaceTable;
import inet.applications.pingapp.PingApp;
import inet.nodes.inet.NetworkLayer;
import inet.util.DCTDump;
import inet.util.subscriber.SubscriberTable;
import inet.base.NotificationBoard;
import inet.applications.nas.NAS;
......@@ -71,6 +73,12 @@ module UE
routingTable: RoutingTable {
@display("p=266,54");
}
rrc: RRC {
@display("p=381,281");
}
dctDump: DCTDump {
@display("p=381,398");
}
connections allowunconnected:
radioIn --> lteRadio.radioIn;
......@@ -80,4 +88,8 @@ module UE
networkLayer.ifOut++ --> lteRadio.netIN;
networkLayer.pingOut --> pingApp.pingIn;
pingApp.pingOut --> networkLayer.pingIn;
rrc.rlcOut --> dctDump.netIn++;
dctDump.netOut++ --> rrc.rlcIn;
dctDump.ifOut++ --> rrc.nasIn;
rrc.nasOut --> dctDump.ifIn++;
}
......@@ -18,6 +18,7 @@
#include <errno.h>
#include "DCTDump.h"
#include "IPSerializer.h"
#include "RRCMessage_m.h"
#define MAXBUFLENGTH 65536
#define MAXDCTLENGTH 100
......@@ -61,7 +62,7 @@ void DCTDump::handleMessage(cMessage *msg) {
if (dumpfile != NULL) {
const simtime_t stime = simulation.getSimTime();
std::stringstream vers;
const char *time = timestamp(stime);
std::string time = timestamp(stime);
uint8 buf[MAXBUFLENGTH];
int32 buf_len = 0;
std::string ascii_buf;
......@@ -86,6 +87,16 @@ void DCTDump::handleMessage(cMessage *msg) {
buf_len = IPSerializer().serialize(ipPacket, buf, sizeof(buf));
}
RRCMessage *rrcMsg = dynamic_cast<RRCMessage*>(msg);
if (rrcMsg) {
strncpy(p, "NAS_RRC_LTE.", 12);
p += 12;
write = true;
buf_len = rrcMsg->getValueArraySize();
for (int32 i = 0; i < buf_len; i++) {
buf[i] = rrcMsg->getValue(i);
}
}
// context port number - always 1
strncpy(p, "1/", 5);
......@@ -103,6 +114,14 @@ void DCTDump::handleMessage(cMessage *msg) {
*p = '/';
p++;
}
if (rrcMsg) {
// protocol name
strncpy(p, "nas_rrc_r8_lte/", 15);
p += 15;
// protocol version
strncpy(p, "1/", 2);
p += 2;
}
// direction
if (msg->getArrivalGate()->isName("ifIn")) {
......@@ -114,8 +133,8 @@ void DCTDump::handleMessage(cMessage *msg) {
// timestamp
strncpy(p, " tm ", 4);
p += 4;
strncpy(p, time, strlen(time));
p += strlen(time);
strncpy(p, time.c_str(), strlen(time.c_str()));
p += strlen(time.c_str());
if (write) {
fwrite(&dh, p - dh, 1, dumpfile);
......@@ -133,12 +152,12 @@ void DCTDump::handleMessage(cMessage *msg) {
send(msg, id);
}
const char *DCTDump::timestamp(simtime_t stime) {
std::string DCTDump::timestamp(simtime_t stime) {
std::stringstream out;
out << (int32)stime.dbl();
out << ".";
out << (uint32)((stime.dbl() - (int32)stime.dbl())*1000000);
return out.str().c_str();
return out.str();
}
void DCTDump::finish() {
......
......@@ -47,7 +47,7 @@
class DCTDump : public cSimpleModule {
private:
FILE *dumpfile;
const char *timestamp(simtime_t stime);
std::string timestamp(simtime_t stime);
void dumpPacket(uint8 *buf, int32 len);
public:
DCTDump();
......
......@@ -43,6 +43,11 @@ const OpenType::Info OpenType::theInfo = {
0,
};
OpenType::OpenType(const void *info) : AbstractType(info) {
this->value = NULL;
this->length = 0;
}
OpenType::OpenType(char *value, int64_t length, const void *info) : AbstractType(info) {
this->value = value;
this->length = length;
......@@ -57,7 +62,7 @@ OpenType::OpenType(AbstractType *val, const void *info) : AbstractType(info) {
OpenType& OpenType::operator=(const OpenType& other) {
this->length = other.length;
if (length) {
if (length > 0) {
value = (char*)calloc(sizeof(char), length);
memcpy(value, other.value, length);
} else
......
......@@ -140,7 +140,7 @@ public:
static const Info theInfo;
/* Constructors. */
OpenType(const void *info = &theInfo) : AbstractType(info) {}
OpenType(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); }
......
......@@ -21,7 +21,7 @@
PerEncoder::PerEncoder(bool alignment) {
usedBits = 8;
length = 0;
buffer = NULL;
memset(buffer, '\0', 65536);
alignmentFlag = alignment;
}
......@@ -100,14 +100,13 @@ void PerEncoder::print(bool type) {
void PerEncoder::encodeBytes(const char *value, int64_t length) {
// appends the bytes to the buffer and increases the size of it
if (alignmentFlag == ALIGNED) {
this->buffer = (char *)realloc(this->buffer, this->length + length);
memcpy(this->buffer + this->length, value, length);
this->length += length;
usedBits = 8;
} else {
for (int64_t i = 0; i < length; i++) {
encodeBits(value[i], 8);
this->length++;
//this->length++;
}
}
}
......@@ -152,7 +151,6 @@ void PerEncoder::encodeBits(char value, unsigned char length) {
// if there are 8 bits available in the last byte copy the
// value in this byte and set the number of used bits
if (usedBits == 8) {
this->buffer = (char *)realloc(this->buffer, this->length + 1);
memcpy(this->buffer + this->length++, &value, 1);
usedBits = length;
return;
......@@ -166,7 +164,6 @@ void PerEncoder::encodeBits(char value, unsigned char length) {
// and set the number of used bits according to this part
unsigned char tmpBits = length - (8 - usedBits);
value = (unsigned char)value << (length - tmpBits);
this->buffer = (char *)realloc(this->buffer, this->length + 1);
memcpy(this->buffer + this->length++, &value, 1);
usedBits = tmpBits;
......@@ -277,7 +274,8 @@ bool PerEncoder::encodeBitString(const BitStringBase& bitString) {
return false;
bytesNr = (bitString.getLength() + 7) / 8;
encodeBytes(bitString.getValue(), bytesNr);
usedBits = bytesNr * 8 - bitString.getLength();
if (this->alignmentFlag == ALIGNED)
usedBits = bytesNr * 8 - bitString.getLength();
} else {
if (!bitString.getLength()) {
return true;
......@@ -286,7 +284,8 @@ bool PerEncoder::encodeBitString(const BitStringBase& bitString) {
} else {
bytesNr = (bitString.getLength() + 7) / 8;
encodeBytes(bitString.getValue(), bytesNr);
usedBits = bytesNr * 8 - bitString.getLength();
if (this->alignmentFlag == ALIGNED)
usedBits = bytesNr * 8 - bitString.getLength();
}
}
......
......@@ -39,7 +39,7 @@ class PerEncoder {
private:
short usedBits;
int64_t length;
char *buffer;
char buffer[65536];
bool alignmentFlag;
/* Utility methods for encoding */
......@@ -78,7 +78,7 @@ public:
int64_t getLength() { return length; }
/* Setter methods */
void setBuffer(char *buffer) { this->buffer = buffer; }
// void setBuffer(char *buffer) { this->buffer = buffer; }
void setLength(int64_t length) { this->length = length; }
};
......
......@@ -4,6 +4,7 @@ from asnparser import *
asnobjs = list()
imports = list()
includes = list()
forbidden = ['explicit']
def firstlower(string):
return string[0].lower() + string[1:]
......@@ -84,6 +85,12 @@ def writeobject(asnobj, hdrfile, srcfile):
if asnobj.type == "Sequence":
optnr = 0
extnr = 0
objs = list()
if len(asnobj.objs) > 0:
for j in range(0, len(asnobj.objs)):
obj = asnobj.objs[j]
if obj.opt == 0:
objs.append(obj)
asnobj.type = asnobj.name
if checkandhandledeps(asnobj, hdrfile, srcfile) != 0:
return
......@@ -93,7 +100,14 @@ def writeobject(asnobj, hdrfile, srcfile):
"\tstatic bool itemsPres[" + str(len(asnobj.objs)) + "];\n" +
"public:\n" +
"\tstatic const Info theInfo;\n"
"\t" + asnobj.name + "(): Sequence(&theInfo) {}\n\n")
"\t" + asnobj.name + "(): Sequence(&theInfo) {}\n")
if len(objs) > 0:
hdrfile.write("\t" + asnobj.name + "(")
for j in range(0, len(objs) - 1):
obj = objs[j]
hdrfile.write("const " + obj.type + "& " + firstlower(obj.name) + ", ")
obj = objs[len(objs) - 1]
hdrfile.write("const " + obj.type + "& " + firstlower(obj.name) + ");\n\n")
for j in range(0, len(asnobj.objs)):
obj = asnobj.objs[j]
hdrfile.write("\tvoid set" + obj.name + "(const " + obj.type + "& " + firstlower(obj.name) + ") { *static_cast<" + obj.type + "*>(items[" + str(j) + "]) = " + firstlower(obj.name) + "; }\n")
......@@ -124,6 +138,17 @@ def writeobject(asnobj, hdrfile, srcfile):
"\titemsPres,\n"
"\t" + str(len(asnobj.objs)) + ", " + str(optnr) + ", " + str(extnr) + "\n" +
"};\n")
if len(objs) > 0:
srcfile.write(asnobj.name + "::" + asnobj.name + "(")
for j in range(0, len(objs) - 1):
obj = objs[j]
srcfile.write("const " + obj.type + "& " + firstlower(obj.name) + ", ")
obj = objs[len(objs) - 1]
srcfile.write("const " + obj.type + "& " + firstlower(obj.name) + ") : Sequence(&theInfo) {\n")
for j in range(0, len(objs)):
obj = objs[j]
srcfile.write("\tset" + obj.name + "(" + firstlower(obj.name) + ");\n")
srcfile.write("}\n")
srcfile.write("\n")
# Sequence Of
......@@ -148,6 +173,9 @@ def writeobject(asnobj, hdrfile, srcfile):
hdrfile.write("\tenum " + asnobj.name + "Choices {\n")
for j in range(0, len(asnobj.objs)):
obj = asnobj.objs[j]
obj.name = firstlower(obj.name)
if obj.name in forbidden:
obj.name = "_" + obj.name
hdrfile.write("\t\t" + firstlower(obj.name) + " = " + str(j) + ",\n")
hdrfile.write("\t};\n")
hdrfile.write("\tstatic const Info theInfo;\n"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册