Add The forwarder Encapsulation mesage #27 #69

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2018-07-26 17:42:12 +09:00
parent 4d75351a06
commit 9940aadd4b
28 changed files with 1322 additions and 433 deletions

View File

@@ -14,14 +14,14 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1685199227" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1685199227" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="cdt.managedbuild.config.gnu.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1685199227." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.102264757" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.2137160061" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
<builder buildPath="${workspace_loc:/MQTTSN-embedded-C}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.767762182" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.602829827" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.109068141" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1710260957" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1710260957" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1258567310" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.dialect.std.1678347248" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.dialect.flags.1711182709" name="Other dialect flags" superClass="gnu.cpp.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=c++11" valueType="string"/>

View File

@@ -220,7 +220,7 @@ TASK_LIST = {// e.g. TASK( task, executing duration in second),
*------------------------------------------------------*/
void setup(void)
{
//SetForwarderMode();
}

View File

@@ -1,5 +1,5 @@
/**************************************************************************************
* Copyright (c) 2016, Tomoaki Yamaguchi
* Copyright (c) 2016-2018, Tomoaki Yamaguchi
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -29,6 +29,8 @@ extern void setUint16(uint8_t* pos, uint16_t val);
extern uint16_t getUint16(const uint8_t* pos);
extern LMqttsnClient* theClient;
extern LScreen* theScreen;
/*=====================================
Class GwProxy
======================================*/
@@ -58,6 +60,7 @@ LGwProxy::LGwProxy(){
_tSleep = 0;
_tWake = 0;
_initialized = 0;
_isForwarderMode = false;
}
LGwProxy::~LGwProxy(){
@@ -342,7 +345,7 @@ uint16_t LGwProxy::registerTopic(char* topicName, uint16_t topicId){
int LGwProxy::writeMsg(const uint8_t* msg){
uint16_t len;
uint8_t pos;
uint8_t rc;
uint8_t rc = 0;
if (msg[0] == 0x01){
len = getUint16(msg + 1);
@@ -354,6 +357,24 @@ int LGwProxy::writeMsg(const uint8_t* msg){
if (msg[0] == 3 && msg[1] == MQTTSN_TYPE_SEARCHGW){
rc = _network.broadcast(msg,len);
}else
{
if ( _isForwarderMode )
{
// create a forwarder encapsulation message WirelessNodeId is a 4bytes fake data
uint8_t* buf = (uint8_t*)malloc(len + 7);
buf[0] = 7;
buf[1] = MQTTSN_TYPE_ENCAPSULATED;
buf[2] = 1;
buf[3] = 'w';
buf[4] = 'n';
buf[5] = 'I';
buf[6] = 'd';
memcpy(buf + 7, msg, len);
if ( buf)
rc = _network.unicast(buf, len + 7);
free(buf);
DISPLAY(" Encapsulated\n ");
}else{
rc = _network.unicast(msg,len);
}
@@ -363,10 +384,8 @@ int LGwProxy::writeMsg(const uint8_t* msg){
{
DISPLAY(" send %s\n", packet_names[msg[pos]]);
}
return rc;
}
//_status = GW_LOST;
//_gwId = 0;
}
return rc;
}
@@ -378,7 +397,9 @@ void LGwProxy::writeGwMsg(void){
int LGwProxy::readMsg(void){
int len = 0;
_mqttsnMsg = _network.getMessage(&len);
uint8_t* msg = _network.getMessage(&len);
_mqttsnMsg = msg;
if (len == 0){
return 0;
}
@@ -393,6 +414,23 @@ int LGwProxy::readMsg(void){
_mqttsnMsg += 1;
len -= 1;
}
if ( *_mqttsnMsg == MQTTSN_TYPE_ENCAPSULATED )
{
int lenEncap = len + 1;
if (msg[lenEncap] == 0x01){
int msgLen = (int) getUint16((const uint8_t*)(msg + lenEncap + 1));
msg += (lenEncap + 3);
len = msgLen - 3;
}else{
msg += (lenEncap + 1);
len = *(msg - 1);
}
_mqttsnMsg = msg;
DISPLAY(" recv encapslated message\n" );
}
if ( *_mqttsnMsg >= MQTTSN_TYPE_ADVERTISE && *_mqttsnMsg <= MQTTSN_TYPE_WILLMSGRESP )
{
DISPLAY(" recv %s\n", packet_names[*_mqttsnMsg]);
@@ -491,4 +529,7 @@ const char* LGwProxy::getClientId(void) {
return _clientId;
}
void LGwProxy::setForwarderMode(void)
{
_isForwarderMode = true;
}

View File

@@ -65,6 +65,7 @@ public:
void setCleanSession(bool);
void setKeepAliveDuration(uint16_t duration);
void setAdvertiseDuration(uint16_t duration);
void setForwarderMode(void);
void reconnect(void);
int writeMsg(const uint8_t* msg);
void setPingReqTimer(void);
@@ -107,6 +108,7 @@ private:
LTimer _keepAliveTimer;
uint16_t _tSleep;
uint16_t _tWake;
bool _isForwarderMode;
char _msg[MQTTSN_MAX_MSG_LENGTH + 1];
};

View File

@@ -1,5 +1,5 @@
/**************************************************************************************
* Copyright (c) 2016, Tomoaki Yamaguchi
* Copyright (c) 2016-2018, Tomoaki Yamaguchi
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -105,6 +105,7 @@ typedef enum
#define END_OF_SUBSCRIBE_LIST {MQTTSN_TOPIC_TYPE_NORMAL,0,0,0, 0}
#define UDPCONF LUdpConfig theNetcon
#define MQTTSNCONF LMqttsnConfig theMqcon
#define SetForwarderMode theClient->getGwProxy()->setForwarderMode
#ifdef CLIENT_MODE
#define DISPLAY(...)
#define PROMPT(...)
@@ -168,6 +169,7 @@ typedef enum
#define MQTTSN_TYPE_WILLTOPICRESP 0x1B
#define MQTTSN_TYPE_WILLMSGUPD 0x1C
#define MQTTSN_TYPE_WILLMSGRESP 0x1D
#define MQTTSN_TYPE_ENCAPSULATED 0xFE
#define MQTTSN_TOPIC_TYPE 0x03

View File

@@ -76,12 +76,12 @@ uint8_t* LNetwork::getMessage(int* len){
}else{
*len = _rxDataBuf[0];
}
if(recvLen != *len){
*len = 0;
return 0;
}else{
//if(recvLen != *len){
// *len = 0;
// return 0;
//}else{
return _rxDataBuf;
}
//}
}
}
return 0;

View File

@@ -10,6 +10,7 @@ TESTAPPL := mainTestProcess
CONFIG := gateway.conf
CLIENTS := clients.conf
PREDEFTOPIC := predefinedTopic.conf
FORWARDERS := forwarders.conf
SRCDIR := src
SUBDIR := ../MQTTSNPacket/src
@@ -36,6 +37,8 @@ $(SRCDIR)/MQTTSNGWPacketHandleTask.cpp \
$(SRCDIR)/MQTTSNGWProcess.cpp \
$(SRCDIR)/MQTTSNGWPublishHandler.cpp \
$(SRCDIR)/MQTTSNGWSubscribeHandler.cpp \
$(SRCDIR)/MQTTSNGWEncapsulatedPacket.cpp \
$(SRCDIR)/MQTTSNGWForwarder.cpp \
$(SRCDIR)/$(OS)/$(SENSORNET)/SensorNetwork.cpp \
$(SRCDIR)/$(OS)/Timer.cpp \
$(SRCDIR)/$(OS)/Network.cpp \
@@ -137,6 +140,8 @@ install:
cp -pf $(CONFIG) ../../
cp -pf $(CLIENTS) ../../
cp -pf $(PREDEFTOPIC) ../../
cp -pf $(FORWARDERS) ../../
exectest:
./$(OUTDIR)/$(TESTPROGNAME) -f ./gateway.conf

View File

@@ -31,10 +31,13 @@ BrokerPortNo=1883
BrokerSecurePortNo=8883
ClientAuthentication=NO
#ClientsList=/path/to/your_clients.conf
ClientsList=/path/to/your_clients.conf
PredefinedTopic=NO
#PredefinedTopicFile=/path/to/your_predefinedTopic.conf
PredefinedTopicList=/path/to/your_predefinedTopic.conf
Forwarder=NO
ForwardersList=/home/tomoaki/tmp/forwarders.conf
#RootCAfile=/path/to/your_Root_CA.crt
#RootCApath=/path/to/your_certs_directory/
@@ -64,7 +67,8 @@ Client should know the MulticastIP and MulticastPortNo to send a SEARCHGW messag
**GatewayId** is used by GWINFO message.
**KeepAlive** is a duration of ADVERTISE message in seconds.
when **ClientAuthentication** is YES, see MQTTSNGWClient.cpp line53, clients file specified by ClientsList is required. This file defines connect allowed clients by ClientId and SensorNetwork Address. e.g. IP address and Port No.
When **PredefinedTopic** is YES, Pre-definedTopicID file specified by PredefinedTopicFile is effective. This file defines Pre-definedTopics of the clients. In this file, ClientID,TopicName and TopicID are declared in CSV format.
When **PredefinedTopic** is YES, Pre-definedTopicID file specified by PredefinedTopicList is effective. This file defines Pre-definedTopics of the clients. In this file, ClientID,TopicName and TopicID are declared in CSV format.
When **Forwarder** is YES, Forwarder Encapsulation Message is available. Connectable Forwarders are specifed by ForwardersList file. In this file, ForwarderIds and those sensorNet addresses are declared in CSV format.

View File

@@ -0,0 +1,16 @@
#***********************************************************************
# Copyright (c) 2018, Tomoaki Yamaguchi
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v1.0 which accompany this distribution.
#
# The Eclipse Public License is available at
# http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#***********************************************************************
#
# SensorNetwork address format is defined by SensorNetAddress::setAddress(string* data) function.
#
Forwarder01,172.16.1.7:12002

View File

@@ -1,5 +1,5 @@
#**************************************************************************
# Copyright (c) 2016, Tomoaki Yamaguchi
# Copyright (c) 2016-2018, Tomoaki Yamaguchi
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
@@ -18,10 +18,13 @@ BrokerPortNo=1883
BrokerSecurePortNo=8883
ClientAuthentication=NO
#ClientsList=/path/to/your_clients.conf
ClientsList=/path/to/your_clients.conf
PredefinedTopic=NO
#PredefinedTopicFile=/path/to/your_predefinedTopic.conf
PredefinedTopicList=/path/to/your_predefinedTopic.conf
Forwarder=NO
ForwardersList=/path/to/your_forwarers.conf
#RootCAfile=/etc/ssl/certs/ca-certificates.crt
#RootCApath=/etc/ssl/certs/

View File

@@ -19,6 +19,7 @@
#include "MQTTSNGWClient.h"
#include "MQTTSNGateway.h"
#include "SensorNetwork.h"
#include "MQTTSNGWForwarder.h"
#include "Network.h"
#include <string>
#include <string.h>
@@ -75,7 +76,7 @@ bool ClientList::authorize(const char* fileName)
{
FILE* fp;
char buf[MAX_CLIENTID_LENGTH + 256];
size_t pos;;
size_t pos;
bool secure;
bool stable;
SensorNetAddress netAddr;
@@ -167,6 +168,11 @@ bool ClientList::setPredefinedTopics(const char* fileName)
fclose(fp);
rc = true;
}
else
{
WRITELOG("Can not open the Predefined Topic List. %s\n", fileName);
return false;
}
return rc;
}
@@ -196,6 +202,11 @@ void ClientList::erase(Client*& client)
_endClient = prev;
}
_clientCnt--;
Forwarder* fwd = client->getForwarder();
if ( fwd )
{
fwd->eraseClient(client);
}
delete client;
client = 0;
_mutex.unlock();
@@ -203,6 +214,8 @@ void ClientList::erase(Client*& client)
}
Client* ClientList::getClient(SensorNetAddress* addr)
{
if ( addr )
{
_mutex.lock();
Client* client = _firstClient;
@@ -217,6 +230,7 @@ Client* ClientList::getClient(SensorNetAddress* addr)
client = client->_nextClient;
}
_mutex.unlock();
}
return 0;
}
@@ -401,6 +415,7 @@ Client::Client(bool secure)
_clientSleepPacketQue.setMaxSize(MAX_SAVED_PUBLISH);
_hasPredefTopic = false;
_holdPingRequest = false;
_forwarder = 0;
}
Client::~Client()
@@ -519,6 +534,16 @@ void Client::setKeepAlive(MQTTSNPacket* packet)
}
}
void Client::setForwarder(Forwarder* forwarder)
{
_forwarder = forwarder;
}
Forwarder* Client::getForwarder(void)
{
return _forwarder;
}
void Client::setSessionStatus(bool status)
{
_sessionStatus = status;

View File

@@ -26,6 +26,8 @@
#include "Network.h"
#include "SensorNetwork.h"
#include "MQTTSNPacket.h"
#include "MQTTSNGWEncapsulatedPacket.h"
#include "MQTTSNGWForwarder.h"
namespace MQTTSNGW
{
@@ -230,13 +232,13 @@ private:
/*=====================================
Class Client
=====================================*/
#define MQTTSN_CLIENTID_LENGTH 23
typedef enum
{
Cstat_Disconnected = 0, Cstat_TryConnecting, Cstat_Connecting, Cstat_Active, Cstat_Asleep, Cstat_Awake, Cstat_Lost
} ClientStatus;
class Forwarder;
class Client
{
@@ -281,6 +283,9 @@ public:
void setClientAddress(SensorNetAddress* sensorNetAddr);
void setSensorNetType(bool stable);
Forwarder* getForwarder(void);
void setForwarder(Forwarder* forwader);
void setClientId(MQTTSNString id);
void setWillTopic(MQTTSNString willTopic);
void setWillMsg(MQTTSNString willmsg);
@@ -339,6 +344,9 @@ private:
bool _sensorNetype; // false: unstable network like a G3
SensorNetAddress _sensorNetAddr;
Forwarder* _forwarder;
bool _sessionStatus;
bool _hasPredefTopic;
@@ -373,5 +381,7 @@ private:
bool _authorize;
};
}
#endif /* MQTTSNGWCLIENT_H_ */

View File

@@ -16,7 +16,12 @@
#include "MQTTSNGWClientRecvTask.h"
#include "MQTTSNGateway.h"
#include <string.h>
#include "MQTTSNPacket.h"
#include "MQTTSNGWForwarder.h"
#include "MQTTSNGWEncapsulatedPacket.h"
#include <cstring>
using namespace MQTTSNGW;
char* currentDateTime(void);
/*=====================================
Class ClientRecvTask
@@ -55,8 +60,12 @@ void ClientRecvTask::run()
Client* client = 0;
char buf[128];
while (true)
{
Forwarder* fwd = 0;
WirelessNodeId nodeId;
MQTTSNPacket* packet = new MQTTSNPacket();
int packetLen = packet->recv(_sensorNetwork);
@@ -89,8 +98,38 @@ void ClientRecvTask::run()
continue;
}
if ( packet->getType() == MQTTSN_ENCAPSULATED )
{
fwd = _gateway->getForwarderList()->getForwarder(_sensorNetwork->getSenderAddress());
if ( fwd == 0 )
{
log(0, packet);
WRITELOG("%s Forwarder %s is not authorized.%s\n", ERRMSG_HEADER, _sensorNetwork->getSenderAddress()->sprint(buf), ERRMSG_FOOTER);
delete packet;
continue;
}
else
{
MQTTSNString fwdName;
fwdName.lenstring.data = const_cast<char *>( fwd->getName() );
fwdName.lenstring.len = strlen(fwdName.lenstring.data);
log(0, packet, &fwdName);
MQTTSNGWEncapsulatedPacket encap;
encap.desirialize(packet->getPacketData(), packet->getPacketLength());
nodeId.setId( encap.getWirelessNodeId() );
client = fwd->getClient(&nodeId);
delete packet;
packet = encap.getMQTTSNPacket();
}
}
else
{
/* get client from the ClientList of Gateway by sensorNetAddress. */
client = _gateway->getClientList()->getClient(_sensorNetwork->getSenderAddress());
}
if ( client )
{
@@ -117,15 +156,28 @@ void ClientRecvTask::run()
client = _gateway->getClientList()->getClient(&data.clientID);
if ( fwd )
{
if ( client == 0 )
{
/* create a new client */
client = _gateway->getClientList()->createClient(0, &data.clientID, false, false);
}
/* Add to af forwarded client list of forwarder. */
fwd->addClient(client, &nodeId);
}
else
{
if ( client )
{
/* set SensorNet Address */
/* Client exists. Set SensorNet Address of it. */
client->setClientAddress(_sensorNetwork->getSenderAddress());
}
else
{
/* create a client */
/* create a new client */
client = _gateway->getClientList()->createClient(_sensorNetwork->getSenderAddress(), &data.clientID, false, false);
}
}
log(client, packet, &data.clientID);
@@ -137,7 +189,7 @@ void ClientRecvTask::run()
continue;
}
/* set sensorNetAddress & post Event */
/* post Client RecvEvent */
ev = new Event();
ev->setClientRecvEvent(client, packet);
_gateway->getPacketEventQue()->post(ev);
@@ -145,16 +197,18 @@ void ClientRecvTask::run()
else
{
log(client, packet);
WRITELOG("%s Client(%s) is not connecting. message has been discarded.%s\n", ERRMSG_HEADER, _sensorNetwork->getSenderAddress()->sprint(buf), ERRMSG_FOOTER);
delete packet;
/* Send DISCONNECT */
SensorNetAddress* addr = new SensorNetAddress();
*addr = (*_sensorNetwork->getSenderAddress());
if ( fwd == 0 )
{
packet = new MQTTSNPacket();
packet->setDISCONNECT(0);
ev = new Event();
ev->setClientSendEvent(addr, packet);
ev->setClientSendEvent(_sensorNetwork->getSenderAddress(), packet);
_gateway->getClientSendQue()->post(ev);
continue;
}
}
}
}
@@ -211,6 +265,9 @@ void ClientRecvTask::log(Client* client, MQTTSNPacket* packet, MQTTSNString* id)
case MQTTSN_PUBCOMP:
WRITELOG(FORMAT_G_MSGID_G_G, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROW, clientId, packet->print(pbuf));
break;
case MQTTSN_ENCAPSULATED:
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW, clientId, packet->print(pbuf));
break;
default:
WRITELOG(FORMAT_W_NL, currentDateTime(), packet->getName(), LEFTARROW, clientId, packet->print(pbuf));
break;

View File

@@ -17,6 +17,7 @@
#include "MQTTSNGWPacket.h"
#include "MQTTSNGWPacket.h"
#include "MQTTSNGateway.h"
#include "MQTTSNGWEncapsulatedPacket.h"
using namespace MQTTSNGW;
using namespace std;
@@ -56,9 +57,23 @@ void ClientSendTask::run()
{
client = ev->getClient();
packet = ev->getMQTTSNPacket();
Forwarder* fwd = client->getForwarder();
if ( fwd )
{
MQTTSNGWEncapsulatedPacket encap(packet);
WirelessNodeId* wnId = fwd->getWirelessNodeId(client);
encap.setWirelessNodeId(wnId);
log(fwd, &encap);
log(client, packet);
rc = encap.unicast(_sensorNetwork,fwd->getSensorNetAddr());
}
else
{
log(client, packet);
rc = packet->unicast(_sensorNetwork, client->getSensorNetAddress());
}
}
else if (ev->getEventType() == EtBroadcast)
{
packet = ev->getMQTTSNPacket();
@@ -119,3 +134,10 @@ void ClientSendTask::log(Client* client, MQTTSNPacket* packet)
break;
}
}
void ClientSendTask::log(Forwarder* forwarder, MQTTSNGWEncapsulatedPacket* packet)
{
char pbuf[SIZE_OF_LOG_PACKET * 3];
const char* forwarderId = forwarder->getId();
WRITELOG(FORMAT_Y_W_G, currentDateTime(), packet->getName(), RIGHTARROW, forwarderId, packet->print(pbuf));
}

View File

@@ -35,6 +35,7 @@ public:
private:
void log(Client*, MQTTSNPacket*);
void log(Forwarder*, MQTTSNGWEncapsulatedPacket*);
Gateway* _gateway;
SensorNetwork* _sensorNetwork;

View File

@@ -218,7 +218,6 @@ void MQTTSNConnectionHandler::handleWillmsg(Client* client, MQTTSNPacket* packet
void MQTTSNConnectionHandler::handleDisconnect(Client* client, MQTTSNPacket* packet)
{
uint16_t duration = 0;
Event* ev = new Event();
if ( packet->getDISCONNECT(&duration) != 0 )
{
@@ -226,7 +225,7 @@ void MQTTSNConnectionHandler::handleDisconnect(Client* client, MQTTSNPacket* pac
{
MQTTGWPacket* mqMsg = new MQTTGWPacket();
mqMsg->setHeader(DISCONNECT);
ev = new Event();
Event* ev = new Event();
ev->setBrokerSendEvent(client, mqMsg);
_gateway->getBrokerSendQue()->post(ev);
}
@@ -270,8 +269,6 @@ void MQTTSNConnectionHandler::handleWillmsgupd(Client* client, MQTTSNPacket* pac
*/
void MQTTSNConnectionHandler::handlePingreq(Client* client, MQTTSNPacket* packet)
{
MQTTGWPacket* msg = 0;
if ( ( client->isSleep() || client->isAwake() ) && client->getClientSleepPacket() )
{
sendStoredPublish(client);

View File

@@ -26,6 +26,7 @@ namespace MQTTSNGW
#define CONFIG_FILE "gateway.conf"
#define CLIENT_LIST "clients.conf"
#define PREDEFINEDTOPIC_FILE "predefinedTopic.conf"
#define FORWARDER_LIST "forwarders.conf"
/*==========================================================
* Gateway default parameters
@@ -41,7 +42,7 @@ namespace MQTTSNGW
#define MAX_INFLIGHTMESSAGES (10) // Number of inflight messages
#define MAX_SAVED_PUBLISH (20) // Max number of PUBLISH message for Asleep state
#define MAX_TOPIC_PAR_CLIENT (50) // Max Topic count for a client. it should be less than 256
#define MQTTSNGW_MAX_PACKET_SIZE (1024) // Max Packet size (5+2+TopicLen+PayloadLen)
#define MQTTSNGW_MAX_PACKET_SIZE (1024) // Max Packet size (5+2+TopicLen+PayloadLen + Foward Encapsulation)
#define SIZE_OF_LOG_PACKET (500) // Length of the packet log in bytes
/*=================================

View File

@@ -0,0 +1,179 @@
/**************************************************************************************
* Copyright (c) 2018, Tomoaki Yamaguchi
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/
#include "MQTTSNGWPacket.h"
#include "MQTTSNGWEncapsulatedPacket.h"
#include "MQTTSNPacket.h"
#include <string.h>
using namespace MQTTSNGW;
using namespace std;
WirelessNodeId::WirelessNodeId()
:
_len{0},
_nodeId{0}
{
}
WirelessNodeId::~WirelessNodeId()
{
if ( _nodeId )
{
free(_nodeId);
}
}
void WirelessNodeId::setId(uint8_t* id, uint8_t len)
{
if ( _nodeId )
{
free(_nodeId);
}
uint8_t* buf = (uint8_t*)malloc(len);
if ( buf )
{
memcpy(buf, id, len);
_len = len;
_nodeId = buf;
}
else
{
_nodeId = 0;
_len = 0;
}
}
void WirelessNodeId::setId(WirelessNodeId* id)
{
setId(id->_nodeId, id->_len);
}
bool WirelessNodeId::operator ==(WirelessNodeId& id)
{
if ( _len == id._len )
{
return memcmp(_nodeId, id._nodeId, _len) == 0;
}
else
{
return false;
}
}
/*
* Class MQTTSNGWEncapsulatedPacket
*/
MQTTSNGWEncapsulatedPacket::MQTTSNGWEncapsulatedPacket()
: _mqttsn{0},
_ctrl{0}
{
}
MQTTSNGWEncapsulatedPacket::MQTTSNGWEncapsulatedPacket(MQTTSNPacket* packet)
: _mqttsn{packet},
_ctrl{0}
{
}
MQTTSNGWEncapsulatedPacket::~MQTTSNGWEncapsulatedPacket()
{
/* Do not delete the MQTTSNPacket. MQTTSNPacket is deleted by delete Event */
}
int MQTTSNGWEncapsulatedPacket::unicast(SensorNetwork* network, SensorNetAddress* sendTo)
{
uint8_t buf[MQTTSNGW_MAX_PACKET_SIZE];
int len = serialize(buf);
return network->unicast(buf, len, sendTo);
}
int MQTTSNGWEncapsulatedPacket::serialize(uint8_t* buf)
{
int len = 0;
buf[0] = _id._len + 3;
buf[1] = MQTTSN_ENCAPSULATED;
buf[2] = _ctrl;
memcpy( buf + 3, _id._nodeId, _id._len);
if ( _mqttsn )
{
len = _mqttsn->getPacketLength();
memcpy(buf + buf[0], _mqttsn->getPacketData(), len);
}
return buf[0] + len;
}
int MQTTSNGWEncapsulatedPacket::desirialize(unsigned char* buf, unsigned short len)
{
if ( _mqttsn )
{
delete _mqttsn;
_mqttsn = 0;
}
_ctrl = buf[2];
_id.setId(buf + 3, buf[0] - 3);
_mqttsn = new MQTTSNPacket;
_mqttsn->desirialize(buf + buf[0], len - buf[0]);
return buf[0];
}
int MQTTSNGWEncapsulatedPacket::getType(void)
{
return MQTTSN_ENCAPSULATED;
}
const char* MQTTSNGWEncapsulatedPacket::getName()
{
return MQTTSNPacket_name(MQTTSN_ENCAPSULATED);
}
MQTTSNPacket* MQTTSNGWEncapsulatedPacket::getMQTTSNPacket(void)
{
return _mqttsn;
}
WirelessNodeId* MQTTSNGWEncapsulatedPacket::getWirelessNodeId(void)
{
return &_id;
}
void MQTTSNGWEncapsulatedPacket::setWirelessNodeId(WirelessNodeId* id)
{
_id.setId(id);
}
char* MQTTSNGWEncapsulatedPacket::print(char* pbuf)
{
char* ptr = pbuf;
char** pptr = &pbuf;
uint8_t buf[MQTTSNGW_MAX_PACKET_SIZE];
int len = serialize(buf);
int size = len > SIZE_OF_LOG_PACKET ? SIZE_OF_LOG_PACKET : len;
for (int i = 1; i < size; i++)
{
sprintf(*pptr, " %02X", *(buf + i));
*pptr += 3;
}
**pptr = 0;
return ptr;
}

View File

@@ -0,0 +1,65 @@
/**************************************************************************************
* Copyright (c) 2018, Tomoaki Yamaguchi
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/
#ifndef MQTTSNGATEWAY_SRC_MQTTSNGWENCAPSULATEDPACKET_H_
#define MQTTSNGATEWAY_SRC_MQTTSNGWENCAPSULATEDPACKET_H_
namespace MQTTSNGW
{
class WirelessNodeId
{
friend class MQTTSNGWEncapsulatedPacket;
public:
WirelessNodeId();
~WirelessNodeId();
void setId(uint8_t* id, uint8_t len);
void setId(WirelessNodeId* id);
bool operator ==(WirelessNodeId& id);
private:
uint8_t _len;
uint8_t* _nodeId;
};
class MQTTSNGWEncapsulatedPacket
{
public:
MQTTSNGWEncapsulatedPacket();
MQTTSNGWEncapsulatedPacket(MQTTSNPacket* packet);
~MQTTSNGWEncapsulatedPacket();
int unicast(SensorNetwork* network, SensorNetAddress* sendTo);
int serialize(uint8_t* buf);
int desirialize(unsigned char* buf, unsigned short len);
int getType(void);
unsigned char* getPacketData(void);
int getPacketLength(void);
const char* getName();
MQTTSNPacket* getMQTTSNPacket(void);
void setWirelessNodeId(WirelessNodeId* id);
WirelessNodeId* getWirelessNodeId(void);
char* print(char* buf);
private:
MQTTSNPacket* _mqttsn;
WirelessNodeId _id;
uint8_t _ctrl;
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWENCAPSULATEDPACKET_H_ */

View File

@@ -0,0 +1,321 @@
/**************************************************************************************
* Copyright (c) 2018, Tomoaki Yamaguchi
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/
#include <string.h>
#include "MQTTSNGWForwarder.h"
using namespace MQTTSNGW;
using namespace std;
/*
* Class ForwarderList
*/
ForwarderList::ForwarderList()
{
_head = 0;
}
ForwarderList::~ForwarderList()
{
if ( _head )
{
Forwarder* p = _head;
while ( p )
{
Forwarder* next = p->_next;
delete p;
p = next;
}
}
}
Forwarder* ForwarderList::getForwarder(SensorNetAddress* addr)
{
Forwarder* p = _head;
while ( p )
{
if ( p->_sensorNetAddr.isMatch(addr) )
{
break;
}
p = p->_next;
}
return p;
}
bool ForwarderList::setFowerder(const char* fileName)
{
FILE* fp;
char buf[MAX_CLIENTID_LENGTH + 256];
size_t pos;
SensorNetAddress netAddr;
if ((fp = fopen(fileName, "r")) != 0)
{
while (fgets(buf, MAX_CLIENTID_LENGTH + 254, fp) != 0)
{
if (*buf == '#')
{
continue;
}
string data = string(buf);
while ((pos = data.find_first_of("  \t\n")) != string::npos)
{
data.erase(pos, 1);
}
if (data.empty())
{
continue;
}
pos = data.find_first_of(",");
string id = data.substr(0, pos);
string addr = data.substr(pos + 1);
if (netAddr.setAddress(&addr) == 0)
{
addForwarder(&netAddr, &id);
}
else
{
WRITELOG("Invalid address %s\n", data.c_str());
return false;
}
}
fclose(fp);
}
else
{
WRITELOG("Can not open the forwarders List. %s\n", fileName);
return false;
}
return true;
}
Forwarder* ForwarderList::addForwarder(SensorNetAddress* addr, string* forwarderId)
{
Forwarder* fdr = new Forwarder(addr, forwarderId);
if ( _head == 0 )
{
_head = fdr;
}
else
{
Forwarder* p = _head;
while ( p )
{
if ( p->_next == 0 )
{
p->_next = fdr;
break;
}
else
{
p = p->_next;
}
}
}
return fdr;
}
Forwarder::Forwarder()
{
_headClient = 0;
_next = 0;
}
/*
* Class Forwarder
*/
Forwarder::Forwarder(SensorNetAddress* addr, string* forwarderId)
{
_forwarderName = *forwarderId;
_sensorNetAddr = *addr;
_headClient = 0;
_next = 0;
}
Forwarder::~Forwarder(void)
{
if ( _headClient )
{
ForwardedClient* p = _headClient;
while ( p )
{
ForwardedClient* next = p->_next;
delete p;
p = next;
}
}
}
const char* Forwarder::getId(void)
{
return _forwarderName.c_str();
}
void Forwarder::addClient(Client* client, WirelessNodeId* id)
{
ForwardedClient* p = _headClient;
ForwardedClient* prev = 0;
client->setForwarder(this);
if ( p != 0 )
{
while ( p )
{
if ( p->_client == client )
{
client->setForwarder(this);
return;
}
prev = p;
p = p->_next;
}
}
ForwardedClient* fclient = new ForwardedClient();
fclient->setClient(client);
fclient->setWirelessNodeId(id);
if ( prev )
{
prev->_next = fclient;
}
else
{
_headClient = fclient;
}
}
Client* Forwarder::getClient(WirelessNodeId* id)
{
Client* cl = 0;
_mutex.lock();
ForwardedClient* p = _headClient;
while ( p )
{
if ( *(p->_wirelessNodeId) == *id )
{
cl = p->_client;
break;
}
else
{
p = p->_next;
}
}
_mutex.unlock();
return cl;
}
const char* Forwarder::getName(void)
{
return _forwarderName.c_str();
}
WirelessNodeId* Forwarder::getWirelessNodeId(Client* client)
{
WirelessNodeId* nodeId = 0;
_mutex.lock();
ForwardedClient* p = _headClient;
while ( p )
{
if ( p->_client == client )
{
nodeId = p->_wirelessNodeId;
break;
}
else
{
p = p->_next;
}
}
_mutex.unlock();
return nodeId;
}
void Forwarder::eraseClient(Client* client)
{
ForwardedClient* prev = 0;
_mutex.lock();
ForwardedClient* p = _headClient;
while ( p )
{
if ( p->_client == client )
{
if ( prev )
{
prev->_next = p->_next;
}
else
{
_headClient = p->_next;
}
delete p;
break;
}
else
{
p = p->_next;
}
}
_mutex.unlock();
}
SensorNetAddress* Forwarder::getSensorNetAddr(void)
{
return &_sensorNetAddr;
}
/*
* Class ForwardedClient
*/
ForwardedClient::ForwardedClient()
: _client{0}
, _wirelessNodeId{0}
, _next{0}
{
}
ForwardedClient::~ForwardedClient()
{
if (_wirelessNodeId)
{
delete _wirelessNodeId;
}
}
void ForwardedClient::setClient(Client* client)
{
_client = client;
}
void ForwardedClient::setWirelessNodeId(WirelessNodeId* id)
{
if ( _wirelessNodeId == 0 )
{
_wirelessNodeId = new WirelessNodeId();
}
_wirelessNodeId->setId(id);
}

View File

@@ -0,0 +1,88 @@
/**************************************************************************************
* Copyright (c) 2018, Tomoaki Yamaguchi
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/
#ifndef MQTTSNGATEWAY_SRC_MQTTSNGWFORWARDER_H_
#define MQTTSNGATEWAY_SRC_MQTTSNGWFORWARDER_H_
#include "MQTTSNGWClient.h"
#include "MQTTSNGWEncapsulatedPacket.h"
#include "SensorNetwork.h"
namespace MQTTSNGW
{
class Client;
class WirelessNodeId;
class ForwardedClient
{
friend class Forwarder;
public:
ForwardedClient();
~ForwardedClient();
void setClient(Client* client);
void setWirelessNodeId(WirelessNodeId* id);
private:
Client* _client;
WirelessNodeId* _wirelessNodeId;
ForwardedClient* _next;
};
class Forwarder
{
friend class ForwarderList;
public:
Forwarder();
Forwarder(SensorNetAddress* addr, string* forwarderId);
~Forwarder();
const char* getId(void);
void addClient(Client* client, WirelessNodeId* id);
Client* getClient(WirelessNodeId* id);
WirelessNodeId* getWirelessNodeId(Client* client);
void eraseClient(Client* client);
SensorNetAddress* getSensorNetAddr(void);
const char* getName(void);
private:
string _forwarderName;
SensorNetAddress _sensorNetAddr;
ForwardedClient* _headClient;
Forwarder* _next;
Mutex _mutex;
};
class ForwarderList
{
public:
ForwarderList();
~ForwarderList();
Forwarder* getForwarder(SensorNetAddress* addr);
bool setFowerder(const char* fileName);
Forwarder* addForwarder(SensorNetAddress* addr, string* forwarderId);
private:
Forwarder* _head;
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWFORWARDER_H_ */

View File

@@ -17,6 +17,6 @@
#ifndef MQTTSNGWVERSION_H_IN_
#define MQTTSNGWVERSION_H_IN_
#define PAHO_GATEWAY_VERSION "1.1.0"
#define PAHO_GATEWAY_VERSION "1.2.0"
#endif /* MQTTSNGWVERSION_H_IN_ */

View File

@@ -46,6 +46,8 @@ Gateway::Gateway()
_params.privateKey = 0;
_params.clientListName = 0;
_params.configName = 0;
_params.predefinedTopicFileName = 0;
_params.forwarderListName = 0;
_packetEventQue.setMaxSize(MAX_INFLIGHTMESSAGES * MAX_CLIENTS);
}
@@ -99,6 +101,14 @@ Gateway::~Gateway()
{
free(_params.configName);
}
if ( _params.predefinedTopicFileName )
{
free(_params.predefinedTopicFileName);
}
if ( _params.forwarderListName )
{
free(_params.forwarderListName);
}
}
void Gateway::initialize(int argc, char** argv)
@@ -214,7 +224,7 @@ void Gateway::initialize(int argc, char** argv)
{
if (!strcasecmp(param, "YES") )
{
if (getParam("PredefinedTopicFile", param) == 0)
if (getParam("PredefinedTopicList", param) == 0)
{
fileName = string(param);
}
@@ -234,6 +244,30 @@ void Gateway::initialize(int argc, char** argv)
}
}
if (getParam("Forwarder", param) == 0 )
{
if (!strcasecmp(param, "YES") )
{
if (getParam("ForwardersList", param) == 0)
{
fileName = string(param);
}
else
{
fileName = *getConfigDirName() + string(FORWARDER_LIST);
}
if ( !_forwarderList.setFowerder(fileName.c_str()) )
{
throw Exception("Gateway::initialize: No ForwardersList file defined by the configuration..");
}
_params.forwarderListName = strdup(fileName.c_str());
}
else
{
_params.forwarderListName = 0;
}
}
fileName = *getConfigDirName() + *getConfigFileName();
_params.configName = strdup(fileName.c_str());
}
@@ -254,12 +288,17 @@ void Gateway::run(void)
{
WRITELOG(" ClientList: %s\n", _params.clientListName);
}
WRITELOG(" SensorN/W: %s\n", _sensorNetwork.getDescription());
WRITELOG(" Broker: %s : %s, %s\n", _params.brokerName, _params.port, _params.portSecure);
if ( _params.predefinedTopicFileName )
{
WRITELOG(" PreDefFile: %s\n", _params.predefinedTopicFileName);
}
if ( _params.forwarderListName )
{
WRITELOG(" Forwarders: %s\n", _params.forwarderListName);
}
WRITELOG(" SensorN/W: %s\n", _sensorNetwork.getDescription());
WRITELOG(" Broker: %s : %s, %s\n", _params.brokerName, _params.port, _params.portSecure);
WRITELOG(" RootCApath: %s\n", _params.rootCApath);
WRITELOG(" RootCAfile: %s\n", _params.rootCAfile);
WRITELOG(" CertKey: %s\n", _params.certKey);
@@ -305,6 +344,11 @@ ClientList* Gateway::getClientList()
return &_clientList;
}
ForwarderList* Gateway::getForwarderList(void)
{
return &_forwarderList;
}
SensorNetwork* Gateway::getSensorNetwork()
{
return &_sensorNetwork;

View File

@@ -17,6 +17,7 @@
#define MQTTSNGATEWAY_H_
#include "MQTTSNGWClient.h"
#include "MQTTSNGWForwarder.h"
#include "MQTTSNGWProcess.h"
#include "MQTTSNPacket.h"
@@ -42,6 +43,7 @@ namespace MQTTSNGW
#define CLIENT "Client"
#define CLIENTS "Clients"
#define UNKNOWNCL "Unknown Client !"
#define LEFTARROW "<---"
#define RIGHTARROW "--->"
#define LEFTARROWB "<==="
@@ -69,14 +71,6 @@ namespace MQTTSNGW
#define ERRMSG_HEADER "\033[0m\033[0;31mError:"
#define ERRMSG_FOOTER "\033[0m\033[0;37m"
/*=====================================
Predefined TopicId for OTA
====================================*/
//#define OTA_CLIENTS
//#define PREDEFINEDID_OTA_REQ (0x0ff0)
//#define PREDEFINEDID_OTA_READY (0x0ff1)
//#define PREDEFINEDID_OTA_NO_CLIENT (0x0ff2)
/*=====================================
Class Event
====================================*/
@@ -161,6 +155,7 @@ typedef struct
char* certKey;
char* privateKey;
char* predefinedTopicFileName;
char* forwarderListName;
}GatewayParams;
/*=====================================
@@ -177,12 +172,14 @@ public:
EventQue* getClientSendQue(void);
EventQue* getBrokerSendQue(void);
ClientList* getClientList(void);
ForwarderList* getForwarderList(void);
SensorNetwork* getSensorNetwork(void);
LightIndicator* getLightIndicator(void);
GatewayParams* getGWParams(void);
private:
ClientList _clientList;
ForwarderList _forwarderList;
EventQue _packetEventQue;
EventQue _brokerSendQue;
EventQue _clientSendQue;

View File

@@ -93,10 +93,10 @@ void TestProcess::run(void)
delete tque;
/* Test Tree23 */
printf("Test Tree23 ");
TestTree23* tree23 = new TestTree23();
tree23->test();
delete tree23;
//printf("Test Tree23 ");
//TestTree23* tree23 = new TestTree23();
//tree23->test();
//delete tree23;
/* Test TopicTable */
printf("Test Topic ");
@@ -111,6 +111,7 @@ void TestProcess::run(void)
delete testMap;
/* Test EventQue */
/*
printf("Test EventQue ");
Client* client = new Client();
_evQue.setMaxSize(EVENT_CNT);
@@ -122,6 +123,7 @@ void TestProcess::run(void)
ev->setClientSendEvent(client, packet);
_evQue.post(ev);
}
delete client;
*/
//MultiTaskProcess::run();
}

View File

@@ -19,7 +19,7 @@
using namespace MQTTSNGW;
TestProcess* test = new TestProcess();
TestTask* task = new TestTask(test);
//TestTask* task = new TestTask(test);
int main(int argc, char** argv)
{

View File

@@ -29,6 +29,7 @@ static const char* packet_names[] =
"WILLMSGRESP"
};
static const char* encapsulation_packet_name = "ENCAPSULATED";
/**
* Returns a character string representing the packet name given a MsgType code
@@ -37,6 +38,10 @@ static const char* packet_names[] =
*/
const char* MQTTSNPacket_name(int code)
{
if ( code == MQTTSN_ENCAPSULATED )
{
return encapsulation_packet_name;
}
return (code >= 0 && code <= MQTTSN_WILLMSGRESP) ? packet_names[code] : "UNKNOWN";
}

View File

@@ -26,7 +26,7 @@ enum errors
{
MQTTSNPACKET_BUFFER_TOO_SHORT = -2,
MQTTSNPACKET_READ_ERROR = -1,
MQTTSNPACKET_READ_COMPLETE,
MQTTSNPACKET_READ_COMPLETE
};
#define MQTTSN_PROTOCOL_VERSION 0x01
@@ -43,7 +43,7 @@ typedef enum
{
MQTTSN_TOPIC_TYPE_NORMAL, /* topic id in publish, topic name in subscribe */
MQTTSN_TOPIC_TYPE_PREDEFINED,
MQTTSN_TOPIC_TYPE_SHORT,
MQTTSN_TOPIC_TYPE_SHORT
}MQTTSN_topicTypes;
enum MQTTSN_msgTypes
@@ -57,8 +57,10 @@ enum MQTTSN_msgTypes
MQTTSN_PINGREQ, MQTTSN_PINGRESP,
MQTTSN_DISCONNECT, MQTTSN_RESERVED3,
MQTTSN_WILLTOPICUPD, MQTTSN_WILLTOPICRESP, MQTTSN_WILLMSGUPD, MQTTSN_WILLMSGRESP,
MQTTSN_ENCAPSULATED = 0xfe
};
typedef struct
{
MQTTSN_topicTypes type;