Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Md5 methodId instead of unsigned int counter #207

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include mk/erpc_common.mk
#.NOTPARALLEL:

ifeq "$(is_linux)" "1"
ERPCSNIFFER = erpcsniffer
#ERPCSNIFFER = erpcsniffer
endif

# Subdirectories to run make on.
Expand Down
28 changes: 16 additions & 12 deletions erpc_c/infra/erpc_basic_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@

using namespace erpc;


////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////

const uint8_t BasicCodec::kBasicCodecVersion = 1;

void BasicCodec::startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence)
void BasicCodec::startWriteMessage(message_type_t type, uint32_t service, const Md5Hash request, uint32_t sequence)
{
uint32_t header = (kBasicCodecVersion << 24) | ((service & 0xff) << 16) | ((request & 0xff) << 8) | (type & 0xff);

write(header);
PayloadHeader header(kBasicCodecVersion,
static_cast<uint8_t>((service & 0xff)),
request,
type
);

writeData(&header, sizeof(PayloadHeader));
write(sequence);
}

Expand Down Expand Up @@ -178,25 +182,25 @@ void BasicCodec::writeCallback(funPtr callback1, funPtr callback2)
}
}

void BasicCodec::startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence)
void BasicCodec::startReadMessage(message_type_t *type, uint32_t *service, Md5Hash request, uint32_t *sequence)
{
uint32_t header;
PayloadHeader header;
readData(&header, sizeof(PayloadHeader));

read(&header);

if (((header >> 24) & 0xffU) != kBasicCodecVersion)
if (header.codecVersion != kBasicCodecVersion)
{
updateStatus(kErpcStatus_InvalidMessageVersion);
}

if (!m_status)
{
*service = ((header >> 16) & 0xffU);
*request = ((header >> 8) & 0xffU);
*type = static_cast<message_type_t>(header & 0xffU);
*service = header.service;
std::memcpy(request, header.id, sizeof(Md5Hash));
*type = static_cast<message_type_t>(header.type);

read(sequence);
}

}

void BasicCodec::readData(void *value, uint32_t length)
Expand Down
4 changes: 2 additions & 2 deletions erpc_c/infra/erpc_basic_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class BasicCodec : public Codec
* @param[in] sequence Send sequence number to be sure that
* received message is reply for current request. or write function.
*/
virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) override;
virtual void startWriteMessage(message_type_t type, uint32_t service, const Md5Hash request, uint32_t sequence) override;

/*!
* @brief Prototype for write data stream.
Expand Down Expand Up @@ -219,7 +219,7 @@ class BasicCodec : public Codec
* @param[out] sequence Returned sequence number to be sure that
* received message is reply for current request.
*/
virtual void startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request,
virtual void startReadMessage(message_type_t *type, uint32_t *service, Md5Hash request,
uint32_t *sequence) override;

/*!
Expand Down
6 changes: 3 additions & 3 deletions erpc_c/infra/erpc_client_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ void ClientManager::verifyReply(RequestContext &request)
{
message_type_t msgType;
uint32_t service;
uint32_t requestNumber;
Md5Hash requestNumber;
uint32_t sequence;

// Some transport layers change the request's message buffer pointer (for things like zero
// copy support), so inCodec must be reset to work with correct buffer.
request.getCodec()->reset();

// Extract the reply header.
request.getCodec()->startReadMessage(&msgType, &service, &requestNumber, &sequence);
request.getCodec()->startReadMessage(&msgType, &service, requestNumber, &sequence);

if (request.getCodec()->isStatusOk() == true)
{
Expand Down Expand Up @@ -218,7 +218,7 @@ void ClientManager::releaseRequest(RequestContext &request)
m_codecFactory->dispose(request.getCodec());
}

void ClientManager::callErrorHandler(erpc_status_t err, uint32_t functionID)
void ClientManager::callErrorHandler(erpc_status_t err, const Md5Hash functionID)
{
if (m_errorHandler != NULL)
{
Expand Down
4 changes: 2 additions & 2 deletions erpc_c/infra/erpc_client_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
#endif

typedef void (*client_error_handler_t)(erpc_status_t err,
uint32_t functionID); /*!< eRPC error handler function type. */
const erpc::Md5Hash functionID); /*!< eRPC error handler function type. */

#ifdef __cplusplus
}
Expand Down Expand Up @@ -136,7 +136,7 @@ class ClientManager : public ClientServerCommon
* @param[in] err Specify function status at the end of eRPC call.
* @param[in] functionID Specify eRPC function call.
*/
void callErrorHandler(erpc_status_t err, uint32_t functionID);
void callErrorHandler(erpc_status_t err, const Md5Hash functionID);

#if ERPC_NESTED_CALLS
/*!
Expand Down
18 changes: 16 additions & 2 deletions erpc_c/infra/erpc_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ typedef enum _message_type
typedef void *funPtr; // Pointer to functions
typedef funPtr *arrayOfFunPtr; // Pointer to array of functions

using Md5Hash = char[33];

struct PayloadHeader{
const uint8_t codecVersion = 0;
uint8_t service = 0;
char id[32];
uint8_t type = 0;
PayloadHeader(){}
PayloadHeader(const uint8_t version, uint8_t service, const Md5Hash hash, message_type_t type) : codecVersion(version), service(service), type(static_cast<uint8_t>(type & 0xff)){
std::memcpy(id, hash, sizeof(Md5Hash)-1);
}
};


/*!
* @brief Abstract serialization encoder/decoder interface.
*
Expand Down Expand Up @@ -135,7 +149,7 @@ class Codec
* @param[in] sequence Send sequence number to be sure that
* received message is reply for current request.
*/
virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) = 0;
virtual void startWriteMessage(message_type_t type, uint32_t service, const Md5Hash request, uint32_t sequence) = 0;

/*!
* @brief Prototype for write boolean value.
Expand Down Expand Up @@ -287,7 +301,7 @@ class Codec
* @param[in] sequence Returned sequence number to be sure that
* received message is reply for current request.
*/
virtual void startReadMessage(message_type_t *type, uint32_t *service, uint32_t *request, uint32_t *sequence) = 0;
virtual void startReadMessage(message_type_t *type, uint32_t *service, Md5Hash request, uint32_t *sequence) = 0;

/*!
* @brief Prototype for read boolean value.
Expand Down
16 changes: 9 additions & 7 deletions erpc_c/infra/erpc_framed_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@

namespace erpc {



/*! @brief Contents of the header that prefixes each message. */
struct Header
{
uint16_t m_messageSize; //!< Size in bytes of the message, excluding the header.
uint16_t m_crc; //!< CRC-16 over the message data.
};

/*!
* @brief Base class for framed transport layers.
*
Expand Down Expand Up @@ -95,13 +104,6 @@ class FramedTransport : public Transport
*/
virtual erpc_status_t send(MessageBuffer *message) override;

/*! @brief Contents of the header that prefixes each message. */
struct Header
{
uint16_t m_messageSize; //!< Size in bytes of the message, excluding the header.
uint16_t m_crc; //!< CRC-16 over the message data.
};

/*!
* @brief This functions sets the CRC-16 implementation.
*
Expand Down
8 changes: 4 additions & 4 deletions erpc_c/infra/erpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ void Server::removeService(Service *service)
}
}

erpc_status_t Server::readHeadOfMessage(Codec *codec, message_type_t &msgType, uint32_t &serviceId, uint32_t &methodId,
uint32_t &sequence)
erpc_status_t Server::readHeadOfMessage(Codec *codec, message_type_t &msgType, uint32_t &serviceId, Md5Hash methodId,
uint32_t& sequence)
{
codec->startReadMessage(&msgType, &serviceId, &methodId, &sequence);
codec->startReadMessage(&msgType, &serviceId, methodId, &sequence);
return codec->getStatus();
}

erpc_status_t Server::processMessage(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
erpc_status_t Server::processMessage(Codec *codec, message_type_t msgType, uint32_t serviceId, Md5Hash methodId,
uint32_t sequence)
{
erpc_status_t err = kErpcStatus_Success;
Expand Down
6 changes: 3 additions & 3 deletions erpc_c/infra/erpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Service
*
* @return Based on handleInvocation implementation.
*/
virtual erpc_status_t handleInvocation(uint32_t methodId, uint32_t sequence, Codec *codec,
virtual erpc_status_t handleInvocation(Md5Hash methodId, uint32_t sequence, Codec *codec,
MessageBufferFactory *messageFactory) = 0;

protected:
Expand Down Expand Up @@ -186,7 +186,7 @@ class Server : public ClientServerCommon
*
* @returns #kErpcStatus_Success or based on codec startReadMessage.
*/
virtual erpc_status_t processMessage(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
virtual erpc_status_t processMessage(Codec *codec, message_type_t msgType, uint32_t serviceId, Md5Hash methodId,
uint32_t sequence);

/*!
Expand All @@ -201,7 +201,7 @@ class Server : public ClientServerCommon
* @returns #kErpcStatus_Success or based on service handleInvocation.
*/
virtual erpc_status_t readHeadOfMessage(Codec *codec, message_type_t &msgType, uint32_t &serviceId,
uint32_t &methodId, uint32_t &sequence);
Md5Hash methodId, uint32_t &sequence);

/*!
* @brief This function finds service base on service ID.
Expand Down
6 changes: 3 additions & 3 deletions erpc_c/infra/erpc_simple_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ erpc_status_t SimpleServer::runInternal(void)
// Handle the request.
message_type_t msgType;
uint32_t serviceId;
uint32_t methodId;
Md5Hash methodId;
uint32_t sequence;

erpc_status_t err = runInternalBegin(&codec, buff, msgType, serviceId, methodId, sequence);
Expand All @@ -49,7 +49,7 @@ erpc_status_t SimpleServer::runInternal(void)
}

erpc_status_t SimpleServer::runInternalBegin(Codec **codec, MessageBuffer &buff, message_type_t &msgType,
uint32_t &serviceId, uint32_t &methodId, uint32_t &sequence)
uint32_t &serviceId, Md5Hash methodId, uint32_t &sequence)
{
erpc_status_t err = kErpcStatus_Success;

Expand Down Expand Up @@ -116,7 +116,7 @@ erpc_status_t SimpleServer::runInternalBegin(Codec **codec, MessageBuffer &buff,
return err;
}

erpc_status_t SimpleServer::runInternalEnd(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
erpc_status_t SimpleServer::runInternalEnd(Codec *codec, message_type_t msgType, uint32_t serviceId, Md5Hash methodId,
uint32_t sequence)
{
erpc_status_t err = processMessage(codec, msgType, serviceId, methodId, sequence);
Expand Down
4 changes: 2 additions & 2 deletions erpc_c/infra/erpc_simple_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SimpleServer : public Server
* @returns #kErpcStatus_Success or based on service handleInvocation.
*/
erpc_status_t runInternalBegin(Codec **codec, MessageBuffer &buff, message_type_t &msgType, uint32_t &serviceId,
uint32_t &methodId, uint32_t &sequence);
Md5Hash methodId, uint32_t &sequence);

/*!
* @brief This function process message and handle sending respond.
Expand All @@ -92,7 +92,7 @@ class SimpleServer : public Server
*
* @returns #kErpcStatus_Success or based on service handleInvocation.
*/
erpc_status_t runInternalEnd(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
erpc_status_t runInternalEnd(Codec *codec, message_type_t msgType, uint32_t serviceId, Md5Hash methodId,
uint32_t sequence);

#if ERPC_NESTED_CALLS
Expand Down
4 changes: 2 additions & 2 deletions erpc_c/infra/erpc_transport_arbitrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ erpc_status_t TransportArbitrator::receive(MessageBuffer *message)
erpc_status_t err;
message_type_t msgType;
uint32_t service;
uint32_t requestNumber;
Md5Hash requestNumber;
uint32_t sequence;
PendingClientInfo *client;

Expand Down Expand Up @@ -94,7 +94,7 @@ erpc_status_t TransportArbitrator::receive(MessageBuffer *message)
m_codec->setBuffer(*message);

// Parse the message header.
m_codec->startReadMessage(&msgType, &service, &requestNumber, &sequence);
m_codec->startReadMessage(&msgType, &service, requestNumber, &sequence);
err = m_codec->getStatus();
if (err != kErpcStatus_Success)
{
Expand Down
6 changes: 4 additions & 2 deletions erpc_c/port/erpc_threading_pthreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ Thread::Thread(const char *name)
{
}

Thread::Thread(thread_entry_t entry, uint32_t priority, uint32_t stackSize, const char *name)
Thread::Thread(thread_entry_t entry, uint32_t priority, uint32_t stackSize, const char *name, thread_stack_pointer ptr)
: m_name(name)
, m_entry(entry)
, m_arg(0)
, m_stackSize(stackSize)
, m_priority(priority)
, m_thread(0)
,m_stackPtr(ptr)
{
}

Thread::~Thread(void) {}

void Thread::init(thread_entry_t entry, uint32_t priority, uint32_t stackSize)
void Thread::init(thread_entry_t entry, uint32_t priority, uint32_t stackSize, thread_stack_pointer ptr)
{
m_entry = entry;
m_stackSize = stackSize;
m_priority = priority;
m_stackPtr = ptr;
}

void Thread::start(void *arg)
Expand Down
1 change: 1 addition & 0 deletions erpcgen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
$(ERPC_ROOT)/erpcgen/src/UniqueIdChecker.cpp \
$(ERPC_ROOT)/erpcgen/src/CGenerator.cpp \
$(ERPC_ROOT)/erpcgen/src/PythonGenerator.cpp \
$(ERPC_ROOT)/erpcgen/src/md5.cpp \
$(ERPC_ROOT)/erpcgen/src/erpcgen.cpp \
$(ERPC_ROOT)/erpcgen/src/ErpcLexer.cpp \
$(ERPC_ROOT)/erpcgen/src/Generator.cpp \
Expand Down
13 changes: 10 additions & 3 deletions erpcgen/src/CGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#include "ParseErrors.h"
#include "annotations.h"
#include "format_string.h"
#include "md5.h"

#include <algorithm>
#include <set>
#include <sstream>


using namespace erpcgen;
using namespace cpptempl;
using namespace std;
Expand Down Expand Up @@ -1692,7 +1694,9 @@ data_map CGenerator::getFunctionTemplateData(Group *group, Function *fn)
string proto = getFunctionPrototype(group, fn);
info["prototype"] = proto;
info["name"] = getOutputName(fn);
info["id"] = fn->getUniqueId();
std::string specialProto = getFunctionPrototype(group, fn, "", true);
std::string hash = md5(specialProto);
info["id"] = hash;

return info;
}
Expand Down Expand Up @@ -1943,7 +1947,7 @@ string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionTyp
return proto + ");";
}

string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, std::string name)
string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, std::string name, bool skipVariableNames)
{
DataType *dataTypeReturn = fn->getReturnType();
string proto = getExtraPointerInReturn(dataTypeReturn);
Expand Down Expand Up @@ -1992,7 +1996,10 @@ string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, std::str
for (auto it : params)
{
bool isLast = (n == params.size() - 1);
string paramSignature = getOutputName(it);
string paramSignature = "";
if(!skipVariableNames){
paramSignature = getOutputName(it);
}
DataType *dataType = it->getDataType();
DataType *trueDataType = dataType->getTrueDataType();

Expand Down
Loading