From df13c052a8cd49d956a654e34d7c2a1ac74b5ce6 Mon Sep 17 00:00:00 2001 From: Mariusz Suchora Date: Mon, 19 Mar 2018 14:04:45 +0100 Subject: [PATCH 1/6] Improve UDPv6 code portability Signed-off-by: Mariusz Suchora --- MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp index e4f0039..5e56fff 100644 --- a/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp +++ b/MQTTSNGateway/src/linux/udp6/SensorNetwork.cpp @@ -14,6 +14,7 @@ * Contributors: * Benjamin Aigner - Adaption of the UDPv4 code to use UDPv6 * Tomoaki Yamaguchi - initial API and implementation and/or initial documentation + * Tieto Poland Sp. z o.o. - improve portability **************************************************************************************/ #include #include @@ -94,10 +95,10 @@ char* SensorNetAddress::getAddress(void) bool SensorNetAddress::isMatch(SensorNetAddress* addr) { return ((this->_portNo == addr->_portNo) && \ - (this->_IpAddr.sin6_addr.__in6_u.__u6_addr32[0] == addr->_IpAddr.sin6_addr.__in6_u.__u6_addr32[0]) && \ - (this->_IpAddr.sin6_addr.__in6_u.__u6_addr32[1] == addr->_IpAddr.sin6_addr.__in6_u.__u6_addr32[1]) && \ - (this->_IpAddr.sin6_addr.__in6_u.__u6_addr32[2] == addr->_IpAddr.sin6_addr.__in6_u.__u6_addr32[2]) && \ - (this->_IpAddr.sin6_addr.__in6_u.__u6_addr32[3] == addr->_IpAddr.sin6_addr.__in6_u.__u6_addr32[3])); + (this->_IpAddr.sin6_addr.s6_addr32[0] == addr->_IpAddr.sin6_addr.s6_addr32[0]) && \ + (this->_IpAddr.sin6_addr.s6_addr32[1] == addr->_IpAddr.sin6_addr.s6_addr32[1]) && \ + (this->_IpAddr.sin6_addr.s6_addr32[2] == addr->_IpAddr.sin6_addr.s6_addr32[2]) && \ + (this->_IpAddr.sin6_addr.s6_addr32[3] == addr->_IpAddr.sin6_addr.s6_addr32[3])); } SensorNetAddress& SensorNetAddress::operator =(SensorNetAddress& addr) From 004b90a2983e54e08e5d0a57def69b1afe5370b0 Mon Sep 17 00:00:00 2001 From: Tomoaki Yamaguchi Date: Tue, 15 Jan 2019 10:50:37 +0900 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0818f6..ffdb259 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ It is dual licensed under the EPL and EDL (see about.html and notice.html for mo There are three sub-projects: 1. MQTTSNPacket - simple de/serialization of MQTT-SN packets, plus helper functions -2. MQTTGateway - MQTT-SN transparent gateway - connects MQTT-SN clients with an MQTT server. See the README within the project for more information. +2. MQTTGateway - MQTT-SN transparent/aggregating gateway - connects MQTT-SN clients with an MQTT server. See the README within the project for more information. 3. MQTTSNClient - high(er) level C++ client (not yet complete) The *MQTTSNPacket* directory contains the lowest level C library with the smallest requirements. This supplies simple serialization From 502ba1f117733f3b96e3129eb5a2c84c9d8cb780 Mon Sep 17 00:00:00 2001 From: Tomoaki Yamaguchi Date: Tue, 15 Jan 2019 10:51:38 +0900 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffdb259..9059ed5 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The *MQTTSNPacket* directory contains the lowest level C library with the smalle and deserialization routines. They serve as a base for the higher level libraries, but can also be used on their own. It is mainly up to you to write and read to and from the network. -The *MQTTSNGateway* directory contains an MQTT-SN to MQTT transparent gateway (see the MQTT-SN specification for a description of that.) It can +The *MQTTSNGateway* directory contains an MQTT-SN to MQTT transparent/aggregating gateway (see the MQTT-SN specification for a description of that.) It can be used to connect the MQTT-SN client to an MQTT server. The *MQTTSNClient* directory contains the next level C++ library. This is intended to mirror the way the MQTTClient works in the Paho embedded From 438a9a131f1203ed183cee0b47a267aa7acf0ce5 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Thu, 9 Jul 2020 12:01:17 +0100 Subject: [PATCH 4/6] Bug fixes from #209 --- MQTTSNGateway/src/MQTTSNGWConnectionHandler.cpp | 10 +++++++--- MQTTSNGateway/src/linux/Network.cpp | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/MQTTSNGateway/src/MQTTSNGWConnectionHandler.cpp b/MQTTSNGateway/src/MQTTSNGWConnectionHandler.cpp index 33b3ef8..76367ce 100644 --- a/MQTTSNGateway/src/MQTTSNGWConnectionHandler.cpp +++ b/MQTTSNGateway/src/MQTTSNGWConnectionHandler.cpp @@ -1,5 +1,5 @@ /************************************************************************************** - * Copyright (c) 2016, Tomoaki Yamaguchi + * Copyright (c) 2016, 2020 Tomoaki Yamaguchi and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -104,10 +104,14 @@ void MQTTSNConnectionHandler::handleConnect(Client* client, MQTTSNPacket* packet connectData->keepAliveTimer = data.duration; connectData->flags.bits.will = data.willFlag; - if ((const char*) _gateway->getGWParams()->loginId != nullptr && (const char*) _gateway->getGWParams()->password != 0) + if ((const char*) _gateway->getGWParams()->loginId != nullptr) + { + connectData->flags.bits.username = 1; + } + + if ((const char*) _gateway->getGWParams()->password != 0) { connectData->flags.bits.password = 1; - connectData->flags.bits.username = 1; } client->setSessionStatus(false); diff --git a/MQTTSNGateway/src/linux/Network.cpp b/MQTTSNGateway/src/linux/Network.cpp index 4f6f5a9..5c5e88d 100644 --- a/MQTTSNGateway/src/linux/Network.cpp +++ b/MQTTSNGateway/src/linux/Network.cpp @@ -541,6 +541,15 @@ loop: case SSL_ERROR_WANT_WRITE: readBlockedOnWrite = true; break; + case SSL_ERROR_SYSCALL: + SSL_free(_ssl); + _ssl = 0; + _numOfInstance--; + //TCPStack::close(); + _busy = false; + _mutex.unlock(); + return -1; + break; default: ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg)); WRITELOG("Network::recv() %s\n", errmsg); From 9cd214a8bbb626d6121f1c4adafcd607cd9cc189 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Thu, 9 Jul 2020 12:05:54 +0100 Subject: [PATCH 5/6] Improve handling of no config file --- MQTTSNGateway/src/MQTTSNGWProcess.cpp | 3 +-- MQTTSNGateway/src/mainGateway.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/MQTTSNGateway/src/MQTTSNGWProcess.cpp b/MQTTSNGateway/src/MQTTSNGWProcess.cpp index 88ba292..2abe3a5 100644 --- a/MQTTSNGateway/src/MQTTSNGWProcess.cpp +++ b/MQTTSNGateway/src/MQTTSNGWProcess.cpp @@ -162,8 +162,7 @@ int Process::getParam(const char* parameter, char* value) if ((fp = fopen(configPath.c_str(), "r")) == NULL) { - WRITELOG("No config file:[%s]\n", configPath.c_str()); - return -1; + throw Exception("No config file:[" + configPath + "]\n"); } while (true) diff --git a/MQTTSNGateway/src/mainGateway.cpp b/MQTTSNGateway/src/mainGateway.cpp index 6fcbbc4..e196d96 100644 --- a/MQTTSNGateway/src/mainGateway.cpp +++ b/MQTTSNGateway/src/mainGateway.cpp @@ -1,5 +1,5 @@ /************************************************************************************** - * Copyright (c) 2016, Tomoaki Yamaguchi + * Copyright (c) 2016, 2020 Tomoaki Yamaguchi and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -34,7 +34,12 @@ BrokerSendTask task5(&gateway); int main(int argc, char** argv) { - gateway.initialize(argc, argv); - gateway.run(); + try { + gateway.initialize(argc, argv); + gateway.run(); + } catch (const std::exception &ex) { + WRITELOG("\nEclipse Paho MQTT-SN Gateway exception: %s\n", ex.what()); + WRITELOG("MQTT-SNGateway [-f Config file name]\n"); + } return 0; } From ab94a094b543b1b24c28ab58d741ffb928cec48f Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Thu, 9 Jul 2020 12:06:20 +0100 Subject: [PATCH 6/6] Update copyright statement --- MQTTSNGateway/src/MQTTGWConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MQTTSNGateway/src/MQTTGWConnectionHandler.cpp b/MQTTSNGateway/src/MQTTGWConnectionHandler.cpp index 47ad782..0e5d85e 100644 --- a/MQTTSNGateway/src/MQTTGWConnectionHandler.cpp +++ b/MQTTSNGateway/src/MQTTGWConnectionHandler.cpp @@ -1,5 +1,5 @@ /************************************************************************************** - * Copyright (c) 2016, Tomoaki Yamaguchi + * Copyright (c) 2016, 2020 Tomoaki Yamaguchi and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0