mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-16 17:06:51 +01:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07a95121fc | ||
|
|
59797127e7 | ||
|
|
27b5c7623e | ||
|
|
4508461fc1 | ||
|
|
b5f2fd655d | ||
|
|
c4e2ac4026 | ||
|
|
273c71774b | ||
|
|
135e79e4da | ||
|
|
debc21760b | ||
|
|
59fd3ec598 | ||
|
|
9c67c75939 | ||
|
|
a37803ac04 | ||
|
|
52500a0c79 | ||
|
|
0398566e82 | ||
|
|
4dcfa98303 | ||
|
|
fa0925d24e | ||
|
|
f2dcda358f | ||
|
|
776099ebb3 | ||
|
|
ca467548b4 |
@@ -38,7 +38,6 @@
|
||||
<option id="gnu.cpp.compiler.option.debugging.sanitaddress.501742254" name="Sanitize address (-fsanitize=address)" superClass="gnu.cpp.compiler.option.debugging.sanitaddress" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.preprocessor.def.1354093543" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="DTLS"/>
|
||||
<listOptionValue builtIn="false" value="DEBUG_NW"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1626802967" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
</tool>
|
||||
@@ -81,7 +80,8 @@
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="src/linux/udp6|src/linux/udp|GatewayTester|src/linux/dtls/SensorNetSubTask.cpp|GatewayTester/samples/ClientSub|GatewayTester/samples/ClientPubQoS-1|GatewayTester/samples/ClientPub|src/linux/rfcomm|src/tests|src/linux/xbee|src/mainLogmonitor.cpp|src/linux/loralink" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway"/>
|
||||
<entry excluding="GatewayTester|src/linux/udp6|src/linux/udp|src/linux/dtls/SensorNetSubTask.cpp|GatewayTester/samples/ClientSub|GatewayTester/samples/ClientPubQoS-1|GatewayTester/samples/ClientPub|src/linux/rfcomm|src/tests|src/linux/xbee|src/mainLogmonitor.cpp|src/linux/loralink" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway"/>
|
||||
<entry excluding="mainTest.cpp|ClientSub|ClientPubQoS-1|ClientPub" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/GatewayTester/samples"/>
|
||||
<entry excluding="samples|test" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
@@ -153,7 +153,8 @@
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/GatewayTester/samples/ClientPub|MQTTSNGateway/src/tests/mainTestProcess.cpp|MQTTSNGateway/src/linux|MQTTSNGateway|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/GatewayTester/samples/ClientSub|MQTTSNClient|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/GatewayTester/samples/ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src|MQTTSNPacket/src|MQTTSNGateway/GatewayTester|ClientPubQoS-1" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
|
||||
<entry excluding="linux/udp6|linux/udp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/src"/>
|
||||
<entry excluding="mainTest.cpp|ClientSub|ClientPubQoS-1|ClientPub" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/GatewayTester/samples"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/src"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
|
||||
94
CODE_OF_CONDUCT.md
Normal file
94
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# Community Code of Conduct
|
||||
|
||||
**Version 2.0
|
||||
January 1, 2023**
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as community members, contributors, Committers[^1], and Project Leads (collectively "Contributors") pledge to make participation in our projects and our community a harassment-free and inclusive experience for everyone.
|
||||
|
||||
This Community Code of Conduct ("Code") outlines our behavior expectations as members of our community in all Eclipse Foundation activities, both offline and online. It is not intended to govern scenarios or behaviors outside of the scope of Eclipse Foundation activities. Nor is it intended to replace or supersede the protections offered to all our community members under the law. Please follow both the spirit and letter of this Code and encourage other Contributors to follow these principles into our work. Failure to read or acknowledge this Code does not excuse a Contributor from compliance with the Code.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contribute to creating a positive and professional environment include:
|
||||
|
||||
- Using welcoming and inclusive language;
|
||||
- Actively encouraging all voices;
|
||||
- Helping others bring their perspectives and listening actively. If you find yourself dominating a discussion, it is especially important to encourage other voices to join in;
|
||||
- Being respectful of differing viewpoints and experiences;
|
||||
- Gracefully accepting constructive criticism;
|
||||
- Focusing on what is best for the community;
|
||||
- Showing empathy towards other community members;
|
||||
- Being direct but professional; and
|
||||
- Leading by example by holding yourself and others accountable
|
||||
|
||||
Examples of unacceptable behavior by Contributors include:
|
||||
|
||||
- The use of sexualized language or imagery;
|
||||
- Unwelcome sexual attention or advances;
|
||||
- Trolling, insulting/derogatory comments, and personal or political attacks;
|
||||
- Public or private harassment, repeated harassment;
|
||||
- Publishing others' private information, such as a physical or electronic address, without explicit permission;
|
||||
- Violent threats or language directed against another person;
|
||||
- Sexist, racist, or otherwise discriminatory jokes and language;
|
||||
- Posting sexually explicit or violent material;
|
||||
- Sharing private content, such as emails sent privately or non-publicly, or unlogged forums such as IRC channel history;
|
||||
- Personal insults, especially those using racist or sexist terms;
|
||||
- Excessive or unnecessary profanity;
|
||||
- Advocating for, or encouraging, any of the above behavior; and
|
||||
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
With the support of the Eclipse Foundation employees, consultants, officers, and directors (collectively, the "Staff"), Committers, and Project Leads, the Eclipse Foundation Conduct Committee (the "Conduct Committee") is responsible for clarifying the standards of acceptable behavior. The Conduct Committee takes appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code applies within all Project, Working Group, and Interest Group spaces and communication channels of the Eclipse Foundation (collectively, "Eclipse spaces"), within any Eclipse-organized event or meeting, and in public spaces when an individual is representing an Eclipse Foundation Project, Working Group, Interest Group, or their communities. Examples of representing a Project or community include posting via an official social media account, personal accounts, or acting as an appointed representative at an online or offline event. Representation of Projects, Working Groups, and Interest Groups may be further defined and clarified by Committers, Project Leads, or the Staff.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Conduct Committee via conduct@eclipse-foundation.org. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Without the explicit consent of the reporter, the Conduct Committee is obligated to maintain confidentiality with regard to the reporter of an incident. The Conduct Committee is further obligated to ensure that the respondent is provided with sufficient information about the complaint to reply. If such details cannot be provided while maintaining confidentiality, the Conduct Committee will take the respondent‘s inability to provide a defense into account in its deliberations and decisions. Further details of enforcement guidelines may be posted separately.
|
||||
|
||||
Staff, Committers and Project Leads have the right to report, remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code, or to block temporarily or permanently any Contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. Any such actions will be reported to the Conduct Committee for transparency and record keeping.
|
||||
|
||||
Any Staff (including officers and directors of the Eclipse Foundation), Committers, Project Leads, or Conduct Committee members who are the subject of a complaint to the Conduct Committee will be recused from the process of resolving any such complaint.
|
||||
|
||||
## Responsibility
|
||||
|
||||
The responsibility for administering this Code rests with the Conduct Committee, with oversight by the Executive Director and the Board of Directors. For additional information on the Conduct Committee and its process, please write to <conduct@eclipse-foundation.org>.
|
||||
|
||||
## Investigation of Potential Code Violations
|
||||
|
||||
All conflict is not bad as a healthy debate may sometimes be necessary to push us to do our best. It is, however, unacceptable to be disrespectful or offensive, or violate this Code. If you see someone engaging in objectionable behavior violating this Code, we encourage you to address the behavior directly with those involved. If for some reason, you are unable to resolve the matter or feel uncomfortable doing so, or if the behavior is threatening or harassing, please report it following the procedure laid out below.
|
||||
|
||||
Reports should be directed to <conduct@eclipse-foundation.org>. It is the Conduct Committee’s role to receive and address reported violations of this Code and to ensure a fair and speedy resolution.
|
||||
|
||||
The Eclipse Foundation takes all reports of potential Code violations seriously and is committed to confidentiality and a full investigation of all allegations. The identity of the reporter will be omitted from the details of the report supplied to the accused. Contributors who are being investigated for a potential Code violation will have an opportunity to be heard prior to any final determination. Those found to have violated the Code can seek reconsideration of the violation and disciplinary action decisions. Every effort will be made to have all matters disposed of within 60 days of the receipt of the complaint.
|
||||
|
||||
## Actions
|
||||
Contributors who do not follow this Code in good faith may face temporary or permanent repercussions as determined by the Conduct Committee.
|
||||
|
||||
This Code does not address all conduct. It works in conjunction with our [Communication Channel Guidelines](https://www.eclipse.org/org/documents/communication-channel-guidelines/), [Social Media Guidelines](https://www.eclipse.org/org/documents/social_media_guidelines.php), [Bylaws](https://www.eclipse.org/org/documents/eclipse-foundation-be-bylaws-en.pdf), and [Internal Rules](https://www.eclipse.org/org/documents/ef-be-internal-rules.pdf) which set out additional protections for, and obligations of, all contributors. The Foundation has additional policies that provide further guidance on other matters.
|
||||
|
||||
It’s impossible to spell out every possible scenario that might be deemed a violation of this Code. Instead, we rely on one another’s good judgment to uphold a high standard of integrity within all Eclipse Spaces. Sometimes, identifying the right thing to do isn’t an easy call. In such a scenario, raise the issue as early as possible.
|
||||
|
||||
## No Retaliation
|
||||
|
||||
The Eclipse community relies upon and values the help of Contributors who identify potential problems that may need to be addressed within an Eclipse Space. Any retaliation against a Contributor who raises an issue honestly is a violation of this Code. That a Contributor has raised a concern honestly or participated in an investigation, cannot be the basis for any adverse action, including threats, harassment, or discrimination. If you work with someone who has raised a concern or provided information in an investigation, you should continue to treat the person with courtesy and respect. If you believe someone has retaliated against you, report the matter as described by this Code. Honest reporting does not mean that you have to be right when you raise a concern; you just have to believe that the information you are providing is accurate.
|
||||
|
||||
False reporting, especially when intended to retaliate or exclude, is itself a violation of this Code and will not be accepted or tolerated.
|
||||
|
||||
Everyone is encouraged to ask questions about this Code. Your feedback is welcome, and you will get a response within three business days. Write to <conduct@eclipse-foundation.org>.
|
||||
|
||||
## Amendments
|
||||
|
||||
The Eclipse Foundation Board of Directors may amend this Code from time to time and may vary the procedures it sets out where appropriate in a particular case.
|
||||
|
||||
### Attribution
|
||||
|
||||
This Code was inspired by the [Contributor Covenant](https://www.contributor-covenant.org/), version 1.4, available [here](https://www.contributor-covenant.org/version/1/4/code-of-conduct/).
|
||||
|
||||
[^1]: Capitalized terms used herein without definition shall have the meanings assigned to them in the Bylaws.
|
||||
|
||||
13
LICENSE
Normal file
13
LICENSE
Normal file
@@ -0,0 +1,13 @@
|
||||
Eclipse Public License - v 2.0
|
||||
|
||||
This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
For an explanation of what dual-licensing means to you, see:
|
||||
https://www.eclipse.org/legal/eplfaq.php#DUALLIC
|
||||
@@ -40,14 +40,14 @@ $(SUBDIR)/Util.cpp \
|
||||
CXX := g++
|
||||
CPPFLAGS +=
|
||||
|
||||
INCLUDES += -I$(SUBDIR)
|
||||
INCLUDES += -I$(SUBDIR) -I/usr/local/opt/openssl/include
|
||||
DEF1 :=
|
||||
DEF2 :=
|
||||
DEFS := -D$(SN) $(DEF1) $(DEF2)
|
||||
LIBS += -L/usr/local/lib -L/usr/local/opt/openssl
|
||||
LIBS += -L/usr/local/lib -L/usr/local/opt/openssl/lib
|
||||
LDFLAGS :=
|
||||
CXXFLAGS := -Wall -O3 -std=c++11
|
||||
LDADD := -lbluetooth -lssl -lcrypto
|
||||
LDADD := -lssl -lcrypto $(LDADDBLT)
|
||||
OUTDIR := Build
|
||||
|
||||
PROG := $(OUTDIR)/$(PROGTEST)
|
||||
|
||||
@@ -8,6 +8,7 @@ if [ $1 == "udp" ] ; then
|
||||
elif [ $1 == "udp6" ] ; then
|
||||
make SN=UDP6 $DEF1 $DEF2
|
||||
elif [ $1 == "rfcomm" ] ; then
|
||||
export LDADDBLT=-lbluetooth
|
||||
make SN=RFCOMM $DEF1 $DEF2
|
||||
elif [ $1 == "dtls" ] ; then
|
||||
make SN=DTLS $DEF1 $DEF2
|
||||
@@ -16,7 +17,7 @@ elif [ $1 == "dtls6" ] ; then
|
||||
elif [ $1 == "clean" ] ; then
|
||||
make clean
|
||||
else
|
||||
echo "Usage: build.sh [ udp | udp6 | rfcomm | dtls | dtls6] | clean"
|
||||
echo "Usage: build.sh [ udp | udp6 | rfcomm | dtls | dtls6 | clean]"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
@@ -207,12 +207,12 @@ int LGwProxy::getConnectResponce(void)
|
||||
if (_network.sslConnect() > 0)
|
||||
{
|
||||
_status = GW_CONNECTING;
|
||||
DISPLAY("\033[0m\033[0;32m\n\nLGwProxy::getConnectResponce SSL connection established.\033[0m\033[0;37m\n\n");
|
||||
DISPLAY("\033[0m\033[0;32m\n\nLGwProxy::getConnectResponce DTLS connection established.\033[0m\033[0;37m\n\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
DISPLAY("\033[0m\033[0;32m\n\nLGwProxy::getConnectResponce SSL connection failed.\033[0m\033[0;37m\n\n");
|
||||
DISPLAY("\033[0m\033[0;32m\n\nLGwProxy::getConnectResponce DTLS connection failed.\033[0m\033[0;37m\n\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -252,11 +252,11 @@ typedef enum
|
||||
/*=================================
|
||||
* Starting prompt
|
||||
==================================*/
|
||||
#define TESTER_VERSION " * Version: 2.0.0"
|
||||
#define TESTER_VERSION " * Version: 2.1.0"
|
||||
|
||||
#define PAHO_COPYRIGHT0 " * MQTT-SN Gateway Tester"
|
||||
#define PAHO_COPYRIGHT0 " * "
|
||||
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
|
||||
#define PAHO_COPYRIGHT2 " * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)"
|
||||
#define PAHO_COPYRIGHT2 " * (https://github.com/eclipse/paho.mqtt-sn.embedded-c.git)"
|
||||
#define PAHO_COPYRIGHT3 " * Author : Tomoaki YAMAGUCHI"
|
||||
#define PAHO_COPYRIGHT4 " ***************************************************************************"
|
||||
|
||||
|
||||
@@ -224,7 +224,6 @@ bool LDtlsPort::open(LUdpConfig *config)
|
||||
if (setsockopt(_sockfdMcast, IPPROTO_IP, IP_MULTICAST_LOOP, &optval, sizeof(optval)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror IP_MULTICAST_LOOP in LDtlsPort::open\033[0m\033[0;37m\n");
|
||||
DISPLAY("\033[0m\033[0;31m\nerror IP_MULTICAST_LOOP in LDtlsPort::open\033[0m\033[0;37m\n");
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
@@ -236,7 +235,6 @@ bool LDtlsPort::open(LUdpConfig *config)
|
||||
if (setsockopt(_sockfdMcast, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror IP_ADD_MEMBERSHIP in LDtlsPort::open\033[0m\033[0;37m\n");
|
||||
DISPLAY("\033[0m\033[0;31m\nerror IP_ADD_MEMBERSHIP in LDtlsPort::open\033[0m\033[0;37m\n");
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
@@ -256,7 +254,6 @@ int LDtlsPort::unicast(const uint8_t *buf, uint32_t length)
|
||||
{
|
||||
int rc = 0;
|
||||
SSL_get_error(_ssl, rc);
|
||||
D_NWLOG("errno == %d in LDtlsPort::unicast\n", rc);
|
||||
DISPLAY("errno == %d in LDtlsPort::unicast\n", rc);
|
||||
}
|
||||
else
|
||||
@@ -386,7 +383,7 @@ bool LDtlsPort::checkRecvBuf()
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_castStat = 0;
|
||||
_castStat = STAT_NONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,14 @@
|
||||
#define SOCKET_MAXRECV 500
|
||||
#define SOCKET_MAXBUFFER_LENGTH 500 // buffer size
|
||||
|
||||
#define STAT_UNICAST 1
|
||||
#define STAT_MULTICAST 2
|
||||
#define STAT_SSL 3
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace linuxAsyncClient {
|
||||
#define STAT_NONE 0
|
||||
#define STAT_UNICAST 1
|
||||
#define STAT_MULTICAST 2
|
||||
#define STAT_SSL 3
|
||||
/*========================================
|
||||
Class LDtlsPort
|
||||
=======================================*/
|
||||
|
||||
@@ -75,8 +75,8 @@ uint8_t* LNetwork::getMessage(int *len)
|
||||
if (checkRecvBuf())
|
||||
{
|
||||
uint16_t recvLen = LDtls6Port::recv(_rxDataBuf, MQTTSN_MAX_PACKET_SIZE, false, &_ipAddress, &_portNo);
|
||||
int diffAddr = memcmp(_ipAddress.s6_addr, _gwIpAddress.s6_addr, sizeof(_gwIpAddress.s6_addr));
|
||||
if (isUnicast() && diffAddr && (_portNo != _gwPortNo))
|
||||
int addrFlg = memcmp(_ipAddress.s6_addr, _gwIpAddress.s6_addr, sizeof(_gwIpAddress.s6_addr));
|
||||
if (isUnicast() && addrFlg && (_portNo != _gwPortNo))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -141,11 +141,14 @@ int LNetwork::sslConnect(void)
|
||||
LDtls6Port::LDtls6Port()
|
||||
{
|
||||
_disconReq = false;
|
||||
memset(_pollfds, 0, sizeof(_pollfds));
|
||||
_sock = 0;
|
||||
_castStat = 0;
|
||||
_castStat = STAT_NONE;
|
||||
_ifIndex = 0;
|
||||
_gIpAddrStr = NULL;
|
||||
_gIpAddrStr = nullptr;
|
||||
_sockfdMcast = 0;
|
||||
_sockfdSsl = 0;
|
||||
_ctx = nullptr;
|
||||
_ssl = nullptr;
|
||||
_gPortNo = _uPortNo = 0;
|
||||
}
|
||||
|
||||
LDtls6Port::~LDtls6Port()
|
||||
@@ -159,12 +162,14 @@ LDtls6Port::~LDtls6Port()
|
||||
|
||||
void LDtls6Port::close()
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
if (_sockfdMcast > 0)
|
||||
{
|
||||
if (_pollfds[i].fd > 0)
|
||||
::close(_sockfdMcast);
|
||||
_sockfdMcast = 0;
|
||||
if (_sockfdSsl > 0)
|
||||
{
|
||||
::close(_pollfds[i].fd);
|
||||
_pollfds[i].fd = 0;
|
||||
::close(_sockfdSsl);
|
||||
_sockfdSsl = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +177,6 @@ void LDtls6Port::close()
|
||||
bool LDtls6Port::open(LUdp6Config *config)
|
||||
{
|
||||
int optval = 1;
|
||||
int sock = 0;
|
||||
sockaddr_in6 addr6;
|
||||
char errmsg[256];
|
||||
|
||||
@@ -205,22 +209,22 @@ bool LDtls6Port::open(LUdp6Config *config)
|
||||
}
|
||||
|
||||
/* create a multicast socket */
|
||||
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (sock < 0)
|
||||
_sockfdMcast = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (_sockfdMcast < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
optval = 1;
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
|
||||
setsockopt(_sockfdMcast, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
||||
setsockopt(_sockfdMcast, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
|
||||
|
||||
memset(&addr6, 0, sizeof(addr6));
|
||||
addr6.sin6_family = AF_INET6;
|
||||
addr6.sin6_port = _gPortNo;
|
||||
addr6.sin6_addr = in6addr_any;
|
||||
|
||||
if (::bind(sock, (sockaddr*) &addr6, sizeof(addr6)) < 0)
|
||||
if (::bind(_sockfdMcast, (sockaddr*) &addr6, sizeof(addr6)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror %s ::bind() in Udp6Port::open\033[0m\033[0;37m\n", strerror(errno));
|
||||
return false;
|
||||
@@ -229,21 +233,21 @@ bool LDtls6Port::open(LUdp6Config *config)
|
||||
ipv6_mreq addrm;
|
||||
addrm.ipv6mr_interface = _ifIndex;
|
||||
inet_pton(AF_INET6, config->ipAddress, &addrm.ipv6mr_multiaddr);
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &addrm, sizeof(addrm)) < 0)
|
||||
if (setsockopt(_sockfdMcast, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &addrm, sizeof(addrm)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror %s IPV6_ADD_MEMBERSHIP in Udp6Port::open\033[0m\033[0;37m\n", strerror(errno));
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
optval = 0;
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &optval, sizeof(optval)) < 0)
|
||||
|
||||
optval = 1;
|
||||
if (setsockopt(_sockfdMcast, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &optval, sizeof(optval)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror %s IPV6_MULTICAST_LOOP in Udp6Port::open\033[0m\033[0;37m\n", strerror(errno));
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
_pollfds[1].fd = sock;
|
||||
_pollfds[1].events = POLLIN;
|
||||
|
||||
_gIpAddr.sin6_family = AF_INET6;
|
||||
_gIpAddr.sin6_port = _gPortNo;
|
||||
memcpy(&_gIpAddr.sin6_addr, (const void*) &addrm.ipv6mr_multiaddr, sizeof(addrm.ipv6mr_multiaddr));
|
||||
@@ -253,7 +257,7 @@ bool LDtls6Port::open(LUdp6Config *config)
|
||||
|
||||
bool LDtls6Port::isUnicast()
|
||||
{
|
||||
return (_sock == _pollfds[0].fd && _sock > 0);
|
||||
return (_castStat == STAT_UNICAST);
|
||||
}
|
||||
|
||||
int LDtls6Port::unicast(const uint8_t *buf, uint32_t length)
|
||||
@@ -267,11 +271,13 @@ int LDtls6Port::unicast(const uint8_t *buf, uint32_t length)
|
||||
}
|
||||
else
|
||||
{
|
||||
D_NWLOG("sendto gateway via DTLS ");
|
||||
D_NWLOG("sendto gateway via DTLS6 ");
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
D_NWLOG(" %02x", *(buf + i));
|
||||
}D_NWLOG("\n");
|
||||
}
|
||||
|
||||
D_NWLOG("\n");
|
||||
|
||||
if (!theClientMode)
|
||||
{
|
||||
@@ -299,12 +305,12 @@ int LDtls6Port::multicast(const uint8_t *buf, uint32_t length)
|
||||
{
|
||||
char sbuf[SCREEN_BUFF_SIZE];
|
||||
char portStr[8];
|
||||
sprintf(portStr, "%d", ntohs(_gPortNo));
|
||||
sprintf(portStr, "%d", ntohs(_gIpAddr.sin6_port));
|
||||
|
||||
int status = ::sendto(_pollfds[1].fd, buf, length, 0, (sockaddr*) &_gIpAddr, sizeof(_gIpAddr));
|
||||
int status = ::sendto(_sockfdMcast, buf, length, 0, (sockaddr*) &_gIpAddr, sizeof(_gIpAddr));
|
||||
if (status < 0)
|
||||
{
|
||||
D_NWLOG("multicast to [%s]:%-6s ", _gIpAddrStr, portStr);D_NWLOG("\033[0m\033[0;31merrno = %d %s in Udp6Port::multicast\033[0m\033[0;37m\n", errno, strerror(errno));
|
||||
DISPLAY("\033[0m\033[0;31merrno == %d in LDtls6Port::multicast\033[0m\033[0;37m\n", errno);
|
||||
return errno;
|
||||
}
|
||||
else
|
||||
@@ -313,7 +319,9 @@ int LDtls6Port::multicast(const uint8_t *buf, uint32_t length)
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
D_NWLOG(" %02x", *(buf + i));
|
||||
}D_NWLOG("\n");
|
||||
}
|
||||
|
||||
D_NWLOG("\n");
|
||||
|
||||
if (!theClientMode)
|
||||
{
|
||||
@@ -339,32 +347,52 @@ int LDtls6Port::multicast(const uint8_t *buf, uint32_t length)
|
||||
|
||||
bool LDtls6Port::checkRecvBuf()
|
||||
{
|
||||
timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 50000; // 50 msec
|
||||
|
||||
uint8_t buf[2];
|
||||
fd_set recvfds;
|
||||
int maxSock = 0;
|
||||
|
||||
int cnt = poll(_pollfds, 2, 2000); // Timeout 2secs
|
||||
if (cnt == 0)
|
||||
FD_ZERO(&recvfds);
|
||||
if (_sockfdMcast)
|
||||
{
|
||||
return false;
|
||||
FD_SET(_sockfdMcast, &recvfds);
|
||||
}
|
||||
if (_sockfdSsl)
|
||||
{
|
||||
FD_SET(_sockfdSsl, &recvfds);
|
||||
}
|
||||
|
||||
if (_pollfds[0].revents & POLLIN)
|
||||
if (_sockfdMcast > _sockfdSsl)
|
||||
{
|
||||
if (::recv(_pollfds[0].fd, buf, 1, MSG_DONTWAIT | MSG_PEEK) > 0)
|
||||
{
|
||||
_castStat = STAT_SSL;
|
||||
_sock = _pollfds[0].fd;
|
||||
return true;
|
||||
maxSock = _sockfdMcast;
|
||||
}
|
||||
}
|
||||
else if (_pollfds[1].revents & POLLIN)
|
||||
else
|
||||
{
|
||||
if (::recv(_pollfds[1].fd, buf, 1, MSG_DONTWAIT | MSG_PEEK) > 0)
|
||||
maxSock = _sockfdSsl;
|
||||
}
|
||||
|
||||
select(maxSock + 1, &recvfds, 0, 0, &timeout);
|
||||
|
||||
if (FD_ISSET(_sockfdMcast, &recvfds))
|
||||
{
|
||||
if (::recv(_sockfdMcast, buf, 1, MSG_DONTWAIT | MSG_PEEK) > 0)
|
||||
{
|
||||
_castStat = STAT_MULTICAST;
|
||||
_sock = _pollfds[1].fd;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (FD_ISSET(_sockfdSsl, &recvfds))
|
||||
{
|
||||
if (::recv(_sockfdSsl, buf, 1, MSG_DONTWAIT | MSG_PEEK) > 0)
|
||||
{
|
||||
_castStat = STAT_SSL;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_castStat = STAT_NONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -393,7 +421,7 @@ int LDtls6Port::recvfrom(uint8_t *buf, uint16_t length, int flags, in6_addr *ipA
|
||||
else if (_castStat == STAT_MULTICAST)
|
||||
{
|
||||
D_NWLOG("Mcast ");
|
||||
status = ::recvfrom(_sock, buf, length, flags, (sockaddr*) &sender, &addrlen);
|
||||
status = ::recvfrom(_sockfdMcast, buf, length, flags, (sockaddr*) &sender, &addrlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -445,63 +473,82 @@ int LDtls6Port::recvfrom(uint8_t *buf, uint16_t length, int flags, in6_addr *ipA
|
||||
return status;
|
||||
}
|
||||
|
||||
int LDtls6Port::sslConnect(in6_addr ipAddress, uint16_t portNo)
|
||||
int LDtls6Port::sslConnect(in6_addr ipAddress, in_port_t portNo)
|
||||
{
|
||||
int optval = 1;
|
||||
int sock = _pollfds[0].fd;
|
||||
|
||||
if (_ssl != 0)
|
||||
{
|
||||
D_NWLOG("LDtls6Port::sslConnect SSL exists.\n");
|
||||
SSL_shutdown(_ssl);
|
||||
SSL_free(_ssl);
|
||||
_sockfdSsl = 0;
|
||||
_ssl = 0;
|
||||
}
|
||||
|
||||
if (sock > 0)
|
||||
if (_sockfdSsl > 0)
|
||||
{
|
||||
::close(sock);
|
||||
D_NWLOG("LDtls6Port::sslConnect socket exists.\n");
|
||||
::close(_sockfdSsl);
|
||||
}
|
||||
|
||||
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (sock <= 0)
|
||||
_sockfdSsl = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (_sockfdSsl <= 0)
|
||||
{
|
||||
D_NWLOG("LDtls6Port::sslConnect Can't create a socket\n");
|
||||
return -1;
|
||||
}
|
||||
optval = 1;
|
||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR || SO_REUSEPORT, &optval, sizeof(optval));
|
||||
setsockopt(_sockfdSsl, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
|
||||
setsockopt(_sockfdSsl, SOL_SOCKET, SO_REUSEADDR || SO_REUSEPORT, &optval, sizeof(optval));
|
||||
|
||||
if (_ifIndex > 0)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &_ifIndex, sizeof(_ifIndex));
|
||||
setsockopt(_sockfdSsl, IPPROTO_IP, IP_BOUND_IF, &_ifIndex, sizeof(_ifIndex));
|
||||
#else
|
||||
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, _interfaceName.c_str(), _interfaceName.size());
|
||||
setsockopt(_sockfdSsl, SOL_SOCKET, SO_BINDTODEVICE, _interfaceName.c_str(), _interfaceName.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
struct sockaddr_in6 addr;
|
||||
sockaddr_in6 addr;
|
||||
addr.sin6_family = AF_INET6;
|
||||
addr.sin6_port = _uPortNo;
|
||||
addr.sin6_addr = in6addr_any;
|
||||
|
||||
if (::bind(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0)
|
||||
if (::bind(_sockfdSsl, (struct sockaddr*) &addr, sizeof(addr)) < 0)
|
||||
{
|
||||
::close(_sockfdSsl);
|
||||
D_NWLOG("LDtlsPort::sslConnect Can't bind a socket\n");
|
||||
return -1;
|
||||
}
|
||||
_pollfds[0].fd = sock;
|
||||
_pollfds[0].events = POLLIN;
|
||||
|
||||
uint16_t listenPort = htons(portNo);
|
||||
struct sockaddr_in6 dest;
|
||||
// Destination is a gateway address and portNo
|
||||
int rc = 0;
|
||||
sockaddr_in6 dest;
|
||||
dest.sin6_family = AF_INET6;
|
||||
dest.sin6_port = htons(listenPort);
|
||||
dest.sin6_port = portNo;
|
||||
memcpy(dest.sin6_addr.s6_addr, (const void*) ipAddress.s6_addr, sizeof(ipAddress.s6_addr));
|
||||
|
||||
int rc = 0;
|
||||
BIO *cbio = BIO_new_dgram(_sockfdSsl, BIO_NOCLOSE);
|
||||
if (connect(_sockfdSsl, (sockaddr*) &dest, sizeof(sockaddr_in6)) < 0)
|
||||
{
|
||||
D_NWLOG("socket can't connect %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, &dest) <0)
|
||||
{
|
||||
D_NWLOG("BIO_ctrl %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
BIO *cbio = BIO_new_dgram(sock, BIO_NOCLOSE);
|
||||
connect(sock, (sockaddr*) &dest, sizeof(sockaddr_in6));
|
||||
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, &dest);
|
||||
_ssl = SSL_new(_ctx);
|
||||
if (_ssl == nullptr)
|
||||
{
|
||||
D_NWLOG("SSL_new %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
SSL_set_bio(_ssl, cbio, cbio);
|
||||
|
||||
#ifdef DEBUG_NW
|
||||
@@ -510,7 +557,12 @@ int LDtls6Port::sslConnect(in6_addr ipAddress, uint16_t portNo)
|
||||
D_NWLOG("connect to %-15s:%-6u\n", addrBuf, ntohs(dest.sin6_port));
|
||||
#endif
|
||||
|
||||
timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);
|
||||
errno = 0;
|
||||
|
||||
int stat = SSL_connect(_ssl);
|
||||
if (stat != 1)
|
||||
{
|
||||
@@ -519,6 +571,7 @@ int LDtls6Port::sslConnect(in6_addr ipAddress, uint16_t portNo)
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = 1;
|
||||
D_NWLOG("SSL connected\n");
|
||||
}
|
||||
return rc;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#define SOCKET_MAXRECV 500
|
||||
#define SOCKET_MAXBUFFER_LENGTH 500 // buffer size
|
||||
|
||||
#define STAT_NONE 0
|
||||
#define STAT_UNICAST 1
|
||||
#define STAT_MULTICAST 2
|
||||
#define STAT_SSL 3
|
||||
@@ -68,9 +69,10 @@ private:
|
||||
void close();
|
||||
int recvfrom ( uint8_t* buf, uint16_t len, int flags, in6_addr* ipaddress, in_port_t* port );
|
||||
|
||||
int _sockfdMcast;
|
||||
int _sockfdSsl;
|
||||
SSL_CTX *_ctx;
|
||||
SSL *_ssl;
|
||||
pollfd _pollfds[2];
|
||||
in_port_t _gPortNo;
|
||||
in_port_t _uPortNo;
|
||||
sockaddr_in6 _gIpAddr;
|
||||
@@ -78,7 +80,6 @@ private:
|
||||
uint32_t _ifIndex;
|
||||
string _interfaceName;
|
||||
uint8_t _castStat;
|
||||
int _sock;
|
||||
bool _disconReq;
|
||||
|
||||
};
|
||||
|
||||
@@ -197,6 +197,7 @@ bool LUdpPort::open(LUdpConfig *config)
|
||||
|
||||
if (::bind(_sockfdUcast, (struct sockaddr*) &addr, sizeof(addr)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror %s ::bind() to unicast address\033[0m\033[0;37m\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -216,6 +217,7 @@ bool LUdpPort::open(LUdpConfig *config)
|
||||
|
||||
if (::bind(_sockfdMcast, (struct sockaddr*) &addrm, sizeof(addrm)) < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror %s ::bind() in UdpPort::open\033[0m\033[0;37m\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ bool LUdp6Port::checkRecvBuf()
|
||||
{
|
||||
uint8_t buf[2];
|
||||
|
||||
int cnt = poll(_pollfds, 2, 2000); // Timeout 2secs
|
||||
int cnt = poll(_pollfds, 2, 50); // Timeout 50m secs
|
||||
if (cnt == 0)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ $ cd paho.mqtt-sn.embedded-c/MQTTSNGateway
|
||||
```
|
||||
In order to build a gateway, one sensor network argument is required.
|
||||
```
|
||||
$ ./build.sh [udp|udp6|xbee|loralink|rfcomm]
|
||||
$ ./build.sh [udp|udp6|xbee|loralink|rfcomm|dtls|dtls6]
|
||||
```
|
||||
|
||||
MQTT-SNGateway and MQTT-SNLogmonitor (executable programs) are built in ./bin directory.
|
||||
@@ -69,17 +69,17 @@ BrokerSecurePortNo=8883
|
||||
**BrokerSecurePortNo** is a broker's port no of TLS connection.
|
||||
```
|
||||
#
|
||||
# CertsKey for TLS connections to a broker
|
||||
# CertKey for TLS connections to a broker
|
||||
#
|
||||
|
||||
#RootCAfile=/etc/ssl/certs/ca-certificates.crt
|
||||
#RootCApath=/etc/ssl/certs/
|
||||
#CertsKey=/path/to/certKey.pem
|
||||
#CertKey=/path/to/certKey.pem
|
||||
#PrivateKey=/path/to/privateKey.pem
|
||||
```
|
||||
**RootCAfile** is a CA file name.
|
||||
**RootCApath** is a CA path. **SSL_CTX_load_verify_locations(ctx, CAfile, CApath)** function requires these parameters.
|
||||
**CertsKey** is a certificate pem file.
|
||||
**CertKey** is a certificate pem file.
|
||||
**PrivateKey** is a private key pem file.
|
||||
Clients can connect to the broker via TLS by setting '**Secure Connection**' for each client in the client conf file.
|
||||
```
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
WORK_DIR=$(realpath $(dirname "$0")/..)
|
||||
BDIR=build.gateway
|
||||
ODIR=bin/
|
||||
|
||||
build () {
|
||||
echo "Start building MQTT-SN Gateway $1"
|
||||
|
||||
cd $SCRIPT_DIR/..
|
||||
BDIR='build.gateway'
|
||||
pushd "$WORK_DIR"
|
||||
if [ ! -d ./$BDIR ]; then
|
||||
mkdir $BDIR
|
||||
fi
|
||||
@@ -13,12 +16,10 @@ build () {
|
||||
make MQTTSNPacket
|
||||
make MQTT-SNGateway
|
||||
make MQTT-SNLogmonitor
|
||||
cd ../MQTTSNGateway
|
||||
cp *.conf ./bin/
|
||||
popd
|
||||
cp *.conf ./$ODIR
|
||||
}
|
||||
|
||||
SCRIPT_DIR=$(cd $(dirname $0); pwd)
|
||||
|
||||
if [ $1 == "udp" ] ; then
|
||||
build $1 $2 $3
|
||||
elif [ $1 == "udp6" ] ; then
|
||||
@@ -34,7 +35,10 @@ elif [ $1 == "dtls" ] ; then
|
||||
elif [ $1 == "dtls6" ] ; then
|
||||
build dtls "${2} ${3} -DDTLS6"
|
||||
elif [ $1 == "clean" ] ; then
|
||||
rm -rf ../builg.gateway
|
||||
pushd "$WORK_DIR"
|
||||
rm -rf ./$BDIR
|
||||
popd
|
||||
rm -rf ./$ODIR
|
||||
else
|
||||
echo "Usage: build.sh [ udp | udp6 | xbee | loralink | rfcomm | dtls | dtls6 | clean]"
|
||||
fi
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
# Lines bigning with # are comment line.
|
||||
# ClientId, SensorNetAddress, "unstableLine", "secureConnection"
|
||||
# in case of UDP, SensorNetAddress format is IPAddress: port no.
|
||||
# if the SensorNetwork is not stable, write "unstableLine".
|
||||
# if Broker's Connection is SSL, write "secureConnection".
|
||||
# if the client is a forwarder, "forwarder" is required.
|
||||
# if the client send PUBLISH QoS-1, "QoS-1" is required.
|
||||
# if the SensorNetwork is not stable, specify "unstableLine".
|
||||
# if Broker's Connection is TLS, specify "secureConnection".
|
||||
# if the client is a forwarder,specify "forwarder".
|
||||
# if the client send PUBLISH QoS-1, specify "QoS-1".
|
||||
#
|
||||
# Ex:
|
||||
# #Client List
|
||||
@@ -31,6 +31,17 @@
|
||||
#
|
||||
# SensorNetwork address format is defined by SensorNetAddress::setAddress(string* data) function.
|
||||
#
|
||||
# UDP6 (IPv6 UDP) [IPv6 address]:PortNo
|
||||
# RFCOMM Device_address.channel (1-30)
|
||||
# XBee FFFFFFFFFFFFFFFF 8bytes Hex
|
||||
# LoRaLink 1-254
|
||||
#
|
||||
#
|
||||
# This is a sample of UDP.
|
||||
#
|
||||
# REWRITE ALL ACCORDING TO YOUR CLIENTS.
|
||||
#
|
||||
|
||||
GatewayTester, 172.16.1.11:20020
|
||||
ClientPUB,172.16.1.11:2010
|
||||
Client01,172.16.1.11:12001
|
||||
|
||||
@@ -31,7 +31,7 @@ BrokerSecurePortNo=8883
|
||||
|
||||
#RootCAfile=/etc/ssl/certs/ca-certificates.crt
|
||||
#RootCApath=/etc/ssl/certs/
|
||||
#CertsKey=/path/to/certKey.pem
|
||||
#CertKey=/path/to/certKey.pem
|
||||
#PrivateKey=/path/to/privateKey.pem
|
||||
|
||||
#
|
||||
|
||||
@@ -81,7 +81,7 @@ ADD_LIBRARY(mqtt-sngateway_common
|
||||
link_directories("/usr/local/lib")
|
||||
|
||||
# Mac
|
||||
link_directories("/usr/local/opt/openssl")
|
||||
link_directories("/usr/local/opt/openssl/lib")
|
||||
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(mqtt-sngateway_common
|
||||
@@ -91,6 +91,7 @@ TARGET_INCLUDE_DIRECTORIES(mqtt-sngateway_common
|
||||
${OS}/${SENSORNET}
|
||||
../../MQTTSNPacket/src
|
||||
/usr/local/include
|
||||
/usr/local/opt/openssl/include
|
||||
)
|
||||
|
||||
IF(SENSORNET MATCHES "rfcomm")
|
||||
|
||||
@@ -101,6 +101,7 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
||||
topicId.type = tp->getType();
|
||||
topicId.data.long_.len = pub.topiclen;
|
||||
topicId.data.long_.name = pub.topic;
|
||||
topicId.data.id = tp->getTopicId();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ char* currentDateTime(void);
|
||||
static const char* theClientStatus[] = { "InPool", "Disconnected", "TryConnecting", "Connecting", "Active", "Asleep", "Awake",
|
||||
"Lost" };
|
||||
|
||||
Client::Client(bool secure)
|
||||
Client::Client()
|
||||
{
|
||||
_packetId = 0;
|
||||
_snMsgId = 0;
|
||||
@@ -45,8 +45,7 @@ Client::Client(bool secure)
|
||||
_willTopic = nullptr;
|
||||
_willMsg = nullptr;
|
||||
_connectData = MQTTPacket_Connect_Initializer;
|
||||
_network = new Network(secure);
|
||||
_secureNetwork = secure;
|
||||
_network = new Network();
|
||||
_sensorNetype = true;
|
||||
_connAck = nullptr;
|
||||
_waitWillMsgFlg = false;
|
||||
@@ -426,7 +425,7 @@ bool Client::isConnecting(void)
|
||||
|
||||
bool Client::isSecureNetwork(void)
|
||||
{
|
||||
return _secureNetwork;
|
||||
return _network->isSecure();
|
||||
}
|
||||
|
||||
bool Client::isSensorNetStable(void)
|
||||
|
||||
@@ -179,8 +179,7 @@ class Client
|
||||
friend class ClientList;
|
||||
friend class ClientsPool;
|
||||
public:
|
||||
Client(bool secure = false);
|
||||
Client(uint8_t maxInflightMessages, bool secure);
|
||||
Client();
|
||||
~Client();
|
||||
|
||||
Connect* getConnectData(void);
|
||||
|
||||
@@ -424,7 +424,8 @@ Client* ClientList::createPredefinedTopic(MQTTSNString* clientId, string topicNa
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
client = createClient(NULL, clientId, aggregate); // <=== BUGFIX
|
||||
client = createClient(NULL, clientId, aggregate);
|
||||
|
||||
if (client == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#include "MQTTSNGWEncapsulatedPacket.h"
|
||||
#include <cstring>
|
||||
|
||||
//#include "MQTTSNGWForwarder.h"
|
||||
|
||||
using namespace MQTTSNGW;
|
||||
char* currentDateTime(void);
|
||||
/*=====================================
|
||||
@@ -45,7 +43,7 @@ void ClientRecvTask::initialize(int argc, char** argv)
|
||||
|
||||
/*
|
||||
* Receive a packet from clients via sensor netwwork
|
||||
* and generate a event to execute the packet handling procedure
|
||||
* and creats a event to execute the packet handling procedure
|
||||
* of MQTTSNPacketHandlingTask.
|
||||
*/
|
||||
void ClientRecvTask::run()
|
||||
@@ -98,11 +96,11 @@ void ClientRecvTask::run()
|
||||
continue;
|
||||
}
|
||||
|
||||
SensorNetAddress* senderAddr = _gateway->getSensorNetwork()->getSenderAddress();
|
||||
SensorNetAddress senderAddr = *_gateway->getSensorNetwork()->getSenderAddress();
|
||||
|
||||
if (packet->getType() == MQTTSN_ENCAPSULATED)
|
||||
{
|
||||
fwd = _gateway->getAdapterManager()->getForwarderList()->getForwarder(senderAddr);
|
||||
fwd = _gateway->getAdapterManager()->getForwarderList()->getForwarder(&senderAddr);
|
||||
|
||||
if (fwd != nullptr)
|
||||
{
|
||||
@@ -124,7 +122,7 @@ void ClientRecvTask::run()
|
||||
|
||||
if (qosm1Proxy->isActive())
|
||||
{
|
||||
const char* clientName = qosm1Proxy->getClientId(senderAddr);
|
||||
const char *clientName = qosm1Proxy->getClientId(&senderAddr);
|
||||
|
||||
if (clientName != nullptr)
|
||||
{
|
||||
@@ -134,7 +132,7 @@ void ClientRecvTask::run()
|
||||
{
|
||||
log(clientName, packet);
|
||||
WRITELOG("%s %s %s can send only PUBLISH with QoS-1.%s\n",
|
||||
ERRMSG_HEADER, clientName, senderAddr->sprint(buf), ERRMSG_FOOTER);
|
||||
ERRMSG_HEADER, clientName, senderAddr.sprint(buf), ERRMSG_FOOTER);
|
||||
delete packet;
|
||||
continue;
|
||||
}
|
||||
@@ -143,7 +141,7 @@ void ClientRecvTask::run()
|
||||
|
||||
if (client == nullptr)
|
||||
{
|
||||
client = _gateway->getClientList()->getClient(senderAddr);
|
||||
client = _gateway->getClientList()->getClient(&senderAddr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +181,7 @@ void ClientRecvTask::run()
|
||||
{
|
||||
log(0, packet, &data.clientID);
|
||||
WRITELOG("%s CONNECT message form %s is incorrect.%s\n",
|
||||
ERRMSG_HEADER, senderAddr->sprint(buf),
|
||||
ERRMSG_HEADER, senderAddr.sprint(buf),
|
||||
ERRMSG_FOOTER);
|
||||
delete packet;
|
||||
continue;
|
||||
@@ -208,13 +206,13 @@ void ClientRecvTask::run()
|
||||
/* Authentication is not required */
|
||||
if (_gateway->getGWParams()->clientAuthentication == false)
|
||||
{
|
||||
client->setClientAddress(senderAddr);
|
||||
client->setClientAddress(&senderAddr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create a new client */
|
||||
client = clientList->createClient(senderAddr, &data.clientID, clientType);
|
||||
client = clientList->createClient(&senderAddr, &data.clientID, clientType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +221,7 @@ void ClientRecvTask::run()
|
||||
if (client == nullptr)
|
||||
{
|
||||
WRITELOG("%s Client(%s) was rejected. CONNECT message has been discarded.%s\n",
|
||||
ERRMSG_HEADER, senderAddr->sprint(buf),
|
||||
ERRMSG_HEADER, senderAddr.sprint(buf),
|
||||
ERRMSG_FOOTER);
|
||||
delete packet;
|
||||
continue;
|
||||
@@ -247,7 +245,7 @@ void ClientRecvTask::run()
|
||||
else
|
||||
{
|
||||
WRITELOG("%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n",
|
||||
ERRMSG_HEADER, senderAddr->sprint(buf),
|
||||
ERRMSG_HEADER, senderAddr.sprint(buf),
|
||||
ERRMSG_FOOTER);
|
||||
}
|
||||
delete packet;
|
||||
|
||||
@@ -17,6 +17,6 @@
|
||||
#ifndef MQTTSNGWVERSION_H_IN_
|
||||
#define MQTTSNGWVERSION_H_IN_
|
||||
|
||||
#define PAHO_GATEWAY_VERSION "1.6.0"
|
||||
#define PAHO_GATEWAY_VERSION "1.5.1"
|
||||
|
||||
#endif /* MQTTSNGWVERSION_H_IN_ */
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace MQTTSNGW
|
||||
/*=================================
|
||||
* Starting prompt
|
||||
==================================*/
|
||||
#define PAHO_COPYRIGHT0 " * "
|
||||
#define PAHO_COPYRIGHT0 " * MQTT-SN Gateway"
|
||||
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
|
||||
#define PAHO_COPYRIGHT2 " * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)"
|
||||
#define PAHO_COPYRIGHT2 " * (https://github.com/eclipse/paho.mqtt-sn.embedded-c.git)"
|
||||
#define PAHO_COPYRIGHT3 " * Author : Tomoaki YAMAGUCHI"
|
||||
#define PAHO_COPYRIGHT4 " ***************************************************************************"
|
||||
/*==========================================================
|
||||
|
||||
@@ -238,11 +238,11 @@ int Network::_numOfInstance = 0;
|
||||
SSL_CTX* Network::_ctx = 0;
|
||||
SSL_SESSION* Network::_session = 0;
|
||||
|
||||
Network::Network(bool secure) :
|
||||
Network::Network() :
|
||||
TCPStack()
|
||||
{
|
||||
_ssl = 0;
|
||||
_secureFlg = secure;
|
||||
_secureFlg = false;
|
||||
_busy = false;
|
||||
_sslValid = false;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
class Network: public TCPStack
|
||||
{
|
||||
public:
|
||||
Network(bool secure);
|
||||
Network();
|
||||
virtual ~Network();
|
||||
|
||||
bool connect(const char* host, const char* port, const char* caPath, const char* caFile, const char* cert, const char* prvkey);
|
||||
|
||||
@@ -61,6 +61,7 @@ unsigned char cookie_secret[COOKIE_SECRET_LENGTH];
|
||||
SensorNetAddress::SensorNetAddress()
|
||||
{
|
||||
_portNo = 0;
|
||||
_pfdsIndex = 0;
|
||||
memset(&_ipAddr, 0, sizeof(_ipAddr));
|
||||
}
|
||||
|
||||
@@ -223,7 +224,6 @@ void SensorNetAddress::setSockaddr4(sockaddr_in *sockaddr)
|
||||
_ipAddr.af = sockaddr->sin_family;
|
||||
_portNo = sockaddr->sin_port;
|
||||
memcpy((void*) &_ipAddr.addr.ad4, (void*) &sockaddr->sin_addr, sizeof(_ipAddr.addr.ad4));
|
||||
this->_pfdsIndex = 0;
|
||||
}
|
||||
|
||||
void SensorNetAddress::setSockaddr6(sockaddr_in6 *sockaddr)
|
||||
@@ -231,7 +231,6 @@ void SensorNetAddress::setSockaddr6(sockaddr_in6 *sockaddr)
|
||||
_ipAddr.af = sockaddr->sin6_family;
|
||||
_portNo = sockaddr->sin6_port;
|
||||
memcpy((void*) &_ipAddr.addr.ad6, (void*) &sockaddr->sin6_addr, sizeof(_ipAddr.addr.ad6));
|
||||
this->_pfdsIndex = 0;
|
||||
}
|
||||
|
||||
void SensorNetAddress::cpyAddr4(sockaddr_in *sockaddr)
|
||||
@@ -244,8 +243,15 @@ void SensorNetAddress::cpyAddr4(sockaddr_in *sockaddr)
|
||||
void SensorNetAddress::cpyAddr6(sockaddr_in6 *sockaddr)
|
||||
{
|
||||
sockaddr->sin6_family = _ipAddr.af;
|
||||
memcpy((void*) &sockaddr->sin6_addr, (void*) &_ipAddr.addr.ad6, sizeof(_ipAddr.addr.ad6));
|
||||
sockaddr->sin6_port = _portNo;
|
||||
memcpy((void*) &sockaddr->sin6_addr, (void*) &_ipAddr.addr.ad6, sizeof(_ipAddr.addr.ad6));
|
||||
}
|
||||
|
||||
void SensorNetAddress::cpyAddr(SensorNetAddress *addr)
|
||||
{
|
||||
addr->_portNo = _portNo;
|
||||
memcpy((void*) &addr->_ipAddr, (const void*) &_ipAddr, sizeof(_ipAddr));
|
||||
addr->_pfdsIndex = _pfdsIndex;
|
||||
}
|
||||
|
||||
char* SensorNetAddress::sprint(char *buf)
|
||||
@@ -269,6 +275,7 @@ char* SensorNetAddress::sprint(char *buf)
|
||||
return buf;
|
||||
}
|
||||
sprintf(buf + strlen(buf), "%d", ntohs(_portNo));
|
||||
sprintf(buf + strlen(buf), " index=%d", _pfdsIndex);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -392,6 +399,7 @@ int Connections::getSockClient(int index)
|
||||
|
||||
void Connections::close(int index)
|
||||
{
|
||||
D_NWSTACK("Connection %d closed\n", index);
|
||||
int idx = index + POLL_SSL;
|
||||
_mutex.lock();
|
||||
int sock = _pollfds[idx].fd;
|
||||
@@ -435,6 +443,7 @@ int Connections::addClientSSL(SSL *ssl, int sock)
|
||||
int rc = _numfds - POLL_SSL;
|
||||
_numfds++;
|
||||
_mutex.unlock();
|
||||
D_NWSTACK("Add client connection index=%d, ssl=%ld, sock=%d\n", rc, (long int )ssl, sock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -453,6 +462,14 @@ SSL* Connections::getClientSSL(int index)
|
||||
return _ssls[index + POLL_SSL];
|
||||
}
|
||||
|
||||
void Connections::print(void)
|
||||
{
|
||||
for (int i = 0; i < _numfds; i++)
|
||||
{
|
||||
printf("index=%d fd=%d ssl=%ld \n", i, _pollfds[i].fd, (long int) _ssls[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*================================================================
|
||||
Class SensorNetwork
|
||||
|
||||
@@ -468,6 +485,8 @@ SSL* Connections::getClientSSL(int index)
|
||||
#define DTLS_APPL 23
|
||||
#define DTLS_OTHERS 100
|
||||
|
||||
#define DTLS_TIMEOUT 4
|
||||
|
||||
/* Certificate verification. Returns 1 if trusted, else 0 */
|
||||
int verify_cert(int ok, X509_STORE_CTX *ctx);
|
||||
|
||||
@@ -479,9 +498,6 @@ int verify_cookie(SSL *ssl, const unsigned char *cookie, unsigned int cookie_len
|
||||
|
||||
SensorNetwork::SensorNetwork()
|
||||
{
|
||||
_senderAddr = new SensorNetAddress();
|
||||
_multicastAddr = new SensorNetAddress();
|
||||
_unicastAddr = new SensorNetAddress();
|
||||
_conns = new Connections();
|
||||
_dtlsctx = nullptr;
|
||||
_af = 0;
|
||||
@@ -493,24 +509,18 @@ SensorNetwork::~SensorNetwork()
|
||||
{
|
||||
delete _conns;
|
||||
}
|
||||
if (_senderAddr != nullptr)
|
||||
{
|
||||
delete _senderAddr;
|
||||
}
|
||||
if (_multicastAddr != nullptr)
|
||||
{
|
||||
delete _multicastAddr;
|
||||
}
|
||||
if (_unicastAddr != nullptr)
|
||||
{
|
||||
delete _unicastAddr;
|
||||
}
|
||||
}
|
||||
|
||||
int SensorNetwork::unicast(const uint8_t *payload, uint16_t payloadLength, SensorNetAddress *sendToAddr)
|
||||
{
|
||||
_mutex.lock();
|
||||
#ifdef DEBUG_NW
|
||||
char buf[256];
|
||||
_conns->print();
|
||||
sendToAddr->sprint(buf);
|
||||
D_NWSTACK("sendto %s\n", buf);
|
||||
#endif
|
||||
|
||||
_mutex.lock();
|
||||
SSL *ssl = _conns->getClientSSL(sendToAddr->getIndex());
|
||||
int len = SSL_write(ssl, payload, payloadLength);
|
||||
int rc = SSL_get_error(ssl, len);
|
||||
@@ -530,7 +540,7 @@ int SensorNetwork::broadcast(const uint8_t *payload, uint16_t payloadLength)
|
||||
int status;
|
||||
#ifndef DTLS6
|
||||
sockaddr_in dest;
|
||||
_multicastAddr->cpyAddr4(&dest);
|
||||
_multicastAddr.cpyAddr4(&dest);
|
||||
|
||||
status = ::sendto(_conns->getSockUnicast(), payload, payloadLength, 0, (const sockaddr*) &dest, sizeof(dest));
|
||||
if (status < 0)
|
||||
@@ -542,7 +552,7 @@ int SensorNetwork::broadcast(const uint8_t *payload, uint16_t payloadLength)
|
||||
|
||||
#else
|
||||
sockaddr_in6 dest;
|
||||
_multicastAddr->cpyAddr6(&dest);
|
||||
_multicastAddr.cpyAddr6(&dest);
|
||||
|
||||
status = ::sendto(_conns->getSockUnicast(), payload, payloadLength, 0, (const sockaddr*) &dest, sizeof(dest));
|
||||
if (status < 0)
|
||||
@@ -577,7 +587,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
client.setFamily(_af);
|
||||
|
||||
// Check POLL_IN
|
||||
int cnt = _conns->poll(2000); // Timeout 2secs
|
||||
int cnt = _conns->poll(6000); // Timeout 6secs
|
||||
if (cnt == 0)
|
||||
{
|
||||
// Timeout
|
||||
@@ -588,21 +598,21 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
_mutex.lock();
|
||||
|
||||
// Check Unicast Port
|
||||
|
||||
if (_conns->getEventUnicast() & POLLIN)
|
||||
{
|
||||
D_NWSTACK("Connect RECV\n");
|
||||
D_NWSTACK("RECV Unicast SSL_connect\n");
|
||||
|
||||
// SSL connection request from a client
|
||||
optval = 1;
|
||||
|
||||
client.clear();
|
||||
client.setFamily(_af);
|
||||
|
||||
#ifdef DEBUG_NW
|
||||
int dtls = getUnicastClient(&client);
|
||||
D_NWSTACK("Packet type = %d\n", dtls);
|
||||
#else
|
||||
getUnicastClient(&client);
|
||||
#endif
|
||||
sockListen = _conns->getSockUnicast();
|
||||
|
||||
// Listen Connection
|
||||
@@ -615,7 +625,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
int rc = 0;
|
||||
|
||||
// SSL Listen
|
||||
D_NWSTACK("Listen SSL\n");
|
||||
D_NWSTACK("DTLSv1_listen\n");
|
||||
|
||||
rc = DTLSv1_listen(ssl, (BIO_ADDR*) &client_addr);
|
||||
|
||||
@@ -631,6 +641,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
#ifndef DTLS6
|
||||
// DTLS over IPv4
|
||||
int client_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
optval = 1;
|
||||
setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &optval, sizeof(optval));
|
||||
// Bind to Dtls PortNo
|
||||
bind(client_fd, (sockaddr*) &_serverAddr4, sizeof(sockaddr_in));
|
||||
@@ -639,6 +650,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
#else
|
||||
// DTLS over IPv6
|
||||
int client_fd = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
optval = 1;
|
||||
setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &optval, sizeof(optval));
|
||||
// Bind to Dtls PortNo
|
||||
bind(client_fd, (sockaddr*) &_serverAddr6, sizeof(sockaddr_in6));
|
||||
@@ -650,12 +662,18 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
BIO_set_fd(cbio, client_fd, BIO_NOCLOSE);
|
||||
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, &client_addr);
|
||||
|
||||
// set timeout
|
||||
timeval timeout;
|
||||
timeout.tv_sec = DTLS_TIMEOUT;
|
||||
timeout.tv_usec = 0;
|
||||
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);
|
||||
|
||||
// Finish handshake
|
||||
int ret = SSL_accept(ssl);
|
||||
if (ret <= 0)
|
||||
{
|
||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||
WRITELOG("SSL_accept ret=%d %s\n", ret, errmsg);
|
||||
WRITELOG("SSL_accept %s\n", errmsg);
|
||||
SSL_shutdown(ssl);
|
||||
SSL_free(ssl);
|
||||
::close(client_fd);
|
||||
@@ -667,11 +685,13 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
|
||||
// save SensorNetworkAddress of Client
|
||||
client.setIndex(index);
|
||||
_senderAddr = &client;
|
||||
client.cpyAddr(&_senderAddr);
|
||||
|
||||
#ifdef DEBUG_NW
|
||||
char clientaddrBuf[128];
|
||||
client.sprint(clientaddrBuf);
|
||||
D_NWSTACK("Client %s SSL Accepted. idx=%d\n", clientaddrBuf, index);
|
||||
_senderAddr.sprint(clientaddrBuf);
|
||||
D_NWSTACK("DTLS accepted client is %s index=%d client_fd=%d\n", clientaddrBuf, _senderAddr.getIndex(),
|
||||
client_fd);
|
||||
#endif
|
||||
}
|
||||
_mutex.unlock();
|
||||
@@ -716,22 +736,23 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
|
||||
// The packet is a MQTT-SN message
|
||||
ssl = _conns->getClientSSL(i);
|
||||
int len = SSL_read_ex(ssl, (void*) buf, (size_t) bufLen, &recvlen);
|
||||
if (SSL_get_error(ssl, len) >= 0)
|
||||
{
|
||||
#ifdef DEBUG_NW
|
||||
char clientaddrBuf[128];
|
||||
client.sprint(clientaddrBuf);
|
||||
D_NWSTACK("Client %s SSL Accepted. idx=%d\n", clientaddrBuf, i);
|
||||
#endif
|
||||
_senderAddr = &client;
|
||||
_senderAddr->setIndex(i);
|
||||
}
|
||||
else
|
||||
if (SSL_get_error(ssl, len) < 0)
|
||||
{
|
||||
D_NWSTACK("SSL RECV Error\n");
|
||||
_conns->close(i);
|
||||
recvlen = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
client.cpyAddr(&_senderAddr);
|
||||
_senderAddr.setIndex(i);
|
||||
|
||||
#ifdef DEBUG_NW
|
||||
char clientaddrBuf[128];
|
||||
_senderAddr.sprint(clientaddrBuf);
|
||||
D_NWSTACK("Client %s ssl=%ld Received. idx=%d\n", clientaddrBuf, (long int )ssl, i);
|
||||
#endif
|
||||
}
|
||||
_mutex.unlock();
|
||||
return recvlen;
|
||||
}
|
||||
@@ -880,7 +901,7 @@ const char* SensorNetwork::getDescription(void)
|
||||
|
||||
SensorNetAddress* SensorNetwork::getSenderAddress(void)
|
||||
{
|
||||
return _senderAddr;
|
||||
return &_senderAddr;
|
||||
}
|
||||
|
||||
int SensorNetwork::openV4(string *ipAddress, uint16_t multiPortNo, uint16_t uniPortNo, uint32_t ttl)
|
||||
@@ -966,9 +987,9 @@ int SensorNetwork::openV4(string *ipAddress, uint16_t multiPortNo, uint16_t uniP
|
||||
D_NWSTACK("error %d IP_MULTICAST_LOOP in UDP4_6Port::openV4 %s\n", errno, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
_multicastAddr->setFamily(AF_INET);
|
||||
_multicastAddr->setIpAddress(ipAddress);
|
||||
_multicastAddr->setPort(multiPortNo);
|
||||
_multicastAddr.setFamily(AF_INET);
|
||||
_multicastAddr.setIpAddress(ipAddress);
|
||||
_multicastAddr.setPort(multiPortNo);
|
||||
_conns->setSockMulticast(sock);
|
||||
return 0;
|
||||
}
|
||||
@@ -987,10 +1008,10 @@ int SensorNetwork::openV6(string *ipAddress, string *interface, uint16_t multiPo
|
||||
return -1;
|
||||
}
|
||||
|
||||
_multicastAddr->setPort(multiPortNo);
|
||||
_unicastAddr->setPort(uniPortNo);
|
||||
_multicastAddr.setPort(multiPortNo);
|
||||
_unicastAddr.setPort(uniPortNo);
|
||||
|
||||
if (_multicastAddr->setIpAddress(ipAddress) < 0)
|
||||
if (_multicastAddr.setIpAddress(ipAddress) < 0)
|
||||
{
|
||||
D_NWSTACK("Incorrect IPV6 address in SensorNetwork::openV6 error %s\n", strerror(errno));
|
||||
return -1;
|
||||
@@ -1073,12 +1094,12 @@ int SensorNetwork::openV6(string *ipAddress, string *interface, uint16_t multiPo
|
||||
}
|
||||
|
||||
struct ipv6_mreq mreq;
|
||||
mreq.ipv6mr_multiaddr = _multicastAddr->getIpAddress()->addr.ad6;
|
||||
mreq.ipv6mr_multiaddr = _multicastAddr.getIpAddress()->addr.ad6;
|
||||
mreq.ipv6mr_interface = ifindex;
|
||||
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0)
|
||||
{
|
||||
D_NWSTACK("Multicast IPV6_ADD_MEMBERSHIP in SensorNetwork::openV6 error %s\n", strerror(errno));
|
||||
D_NWSTACK("Multicast IPV6_JOIN_GROUP in SensorNetwork::openV6 error %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1099,9 +1120,9 @@ int SensorNetwork::openV6(string *ipAddress, string *interface, uint16_t multiPo
|
||||
D_NWSTACK("Multicast IPV6_MULTICAST_HOPS in SensorNetwork::openV6 error %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
_multicastAddr->setFamily(AF_INET6);
|
||||
_multicastAddr->setIpAddress(ipAddress);
|
||||
_multicastAddr->setPort(multiPortNo);
|
||||
_multicastAddr.setFamily(AF_INET6);
|
||||
_multicastAddr.setIpAddress(ipAddress);
|
||||
_multicastAddr.setPort(multiPortNo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1169,14 +1190,14 @@ int SensorNetwork::getSenderAddress(int sock, SensorNetAddress *addr)
|
||||
|
||||
if (len < 0 && errno != EAGAIN)
|
||||
{
|
||||
D_NWSTACK("errno = %d in UDPPort::getSender\n", errno);
|
||||
D_NWSTACK("errno = %d in SensorNetwork::getSenderAddress\n", errno);
|
||||
return -1;
|
||||
}
|
||||
addr->setFamily(AF_INET);
|
||||
addr->getIpAddress()->addr.ad4 = sender4.sin_addr;
|
||||
addr->setPort(sender4.sin_port);
|
||||
D_NWSTACK("SensorNetwork::getSenderAddress recved from %s:%d length = %d\n", inet_ntoa(sender4.sin_addr),
|
||||
ntohs(sender4.sin_port), len);
|
||||
|
||||
addr->setSockaddr4(&sender4);
|
||||
|
||||
D_NWSTACK("SensorNetwork::getSenderAddress recved from %s:%d length = %d fd=%d\n", inet_ntoa(sender4.sin_addr),
|
||||
ntohs(addr->getPort()), len, sock);
|
||||
|
||||
if (len >= 13)
|
||||
{
|
||||
@@ -1191,27 +1212,34 @@ int SensorNetwork::getSenderAddress(int sock, SensorNetAddress *addr)
|
||||
//AF_INET6
|
||||
sockaddr_in6 sender6 = { 0 };
|
||||
socklen_t addrlen6 = sizeof(sender6);
|
||||
unsigned long int buf = 0;
|
||||
len = ::recvfrom(sock, &buf, 1, MSG_PEEK, (sockaddr*) &sender6, &addrlen6);
|
||||
char buf[16];
|
||||
int rc = DTLS_OTHERS;
|
||||
|
||||
len = ::recvfrom(sock, &buf, 15, MSG_PEEK, (sockaddr*) &sender6, &addrlen6);
|
||||
|
||||
if (len < 0 && errno != EAGAIN)
|
||||
{
|
||||
D_NWSTACK("errno = %d in SensorNetwork::getSender\n", errno);
|
||||
return len;
|
||||
D_NWSTACK("errno = %d in SensorNetwork::getSenderAddress\n", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr->setFamily(AF_INET6);
|
||||
addr->setSockaddr6(&sender6);
|
||||
addr->setPort(sender4.sin_port);
|
||||
|
||||
#ifdef DEBUG_NW
|
||||
char senderstr[INET6_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET6, &sender6.sin6_addr,senderstr,INET6_ADDRSTRLEN);
|
||||
D_NWSTACK("recved from %s:%d length = %d\n",senderstr ,ntohs(sender6.sin6_port), len);
|
||||
D_NWSTACK("recved from %s:%d length = %d fd=%d\n",senderstr ,ntohs(addr->getPort()), len, sock);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return len;
|
||||
if (len >= 13)
|
||||
{
|
||||
if (buf[0] == DTLS_CLIENTHELLO || buf[0] == DTLS_APPL)
|
||||
{
|
||||
rc = buf[0];
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
void SensorNetwork::clearRecvData(int sock)
|
||||
@@ -1220,6 +1248,12 @@ void SensorNetwork::clearRecvData(int sock)
|
||||
::recv(sock, buf, MQTTSNGW_MAX_PACKET_SIZE, 0);
|
||||
}
|
||||
|
||||
Connections* SensorNetwork::getConnections(void)
|
||||
{
|
||||
return _conns;
|
||||
}
|
||||
|
||||
|
||||
int verify_cert(int ok, X509_STORE_CTX *ctx)
|
||||
{
|
||||
return 1;
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
void setSockaddr6(sockaddr_in6 *sockaddr);
|
||||
void cpyAddr4(sockaddr_in *sockaddr);
|
||||
void cpyAddr6(sockaddr_in6 *sockaddr);
|
||||
void cpyAddr(SensorNetAddress *addr);
|
||||
in_port_t getPort(void);
|
||||
ipAddr_t* getIpAddress(void);
|
||||
void setIndex(int index);
|
||||
@@ -109,6 +110,7 @@ public:
|
||||
int getEventUnicast(void);
|
||||
int getEventListen(void);
|
||||
void closeSSL(int index);
|
||||
void print(void);
|
||||
private:
|
||||
pollfd *_pollfds;
|
||||
SSL **_ssls;
|
||||
@@ -133,6 +135,7 @@ public:
|
||||
void initialize(void);
|
||||
const char* getDescription(void);
|
||||
SensorNetAddress* getSenderAddress(void);
|
||||
Connections* getConnections(void);
|
||||
void close();
|
||||
|
||||
private:
|
||||
@@ -145,9 +148,9 @@ private:
|
||||
void clearRecvData(int sock);
|
||||
|
||||
Mutex _mutex;
|
||||
SensorNetAddress *_senderAddr;
|
||||
SensorNetAddress *_multicastAddr;
|
||||
SensorNetAddress *_unicastAddr;
|
||||
SensorNetAddress _senderAddr;
|
||||
SensorNetAddress _multicastAddr;
|
||||
SensorNetAddress _unicastAddr;
|
||||
string _description;
|
||||
SSL_CTX *_dtlsctx;
|
||||
Connections *_conns;
|
||||
|
||||
@@ -360,9 +360,9 @@ int UDPPort6::open(uint16_t uniPortNo, uint16_t multiPortNo, const char *multica
|
||||
ipv6_mreq addrm;
|
||||
addrm.ipv6mr_interface = ifindex;
|
||||
inet_pton(AF_INET6, multicastAddr, &addrm.ipv6mr_multiaddr);
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &addrm, sizeof(addrm)) < 0)
|
||||
if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &addrm, sizeof(addrm)) < 0)
|
||||
{
|
||||
D_NWSTACK("\033[0m\033[0;31m error %d IPV6_ADD_MEMBERSHIP in Udp6Port::open\033[0m\033[0;37m\n", errno);
|
||||
D_NWSTACK("\033[0m\033[0;31m error %d IPV6_JOIN_GROUP in Udp6Port::open\033[0m\033[0;37m\n", errno);
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
@@ -416,12 +416,24 @@ int UDPPort6::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* add
|
||||
|
||||
int UDPPort6::broadcast(const uint8_t* buf, uint32_t length)
|
||||
{
|
||||
int err = unicast(buf, length, &_grpAddr);
|
||||
sockaddr_in6 dest;
|
||||
memset(&dest, 0, sizeof(dest));
|
||||
dest.sin6_family = AF_INET6;
|
||||
dest.sin6_port = _grpAddr.getPortNo();
|
||||
memcpy(dest.sin6_addr.s6_addr, (const void*) &_grpAddr.getIpAddress()->sin6_addr, sizeof(in6_addr));
|
||||
|
||||
if (err < 0)
|
||||
#ifdef DEBUG_NW
|
||||
char addrBuf[INET6_ADDRSTRLEN];
|
||||
addr->sprint(addrBuf);
|
||||
D_NWSTACK("sendto %s\n", addrBuf);
|
||||
#endif
|
||||
|
||||
int status = ::sendto(_pollfds[1].fd, buf, length, 0, (const sockaddr*) &dest, sizeof(dest));
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
D_NWSTACK("UDP6::broadcast - sendto: %s", strerror(errno));
|
||||
return err;
|
||||
return status;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
55
NOTICE
Normal file
55
NOTICE
Normal file
@@ -0,0 +1,55 @@
|
||||
# Notices for Eclipse Paho
|
||||
|
||||
This content is produced and maintained by the Eclipse Paho project.
|
||||
|
||||
* Project home: https://projects.eclipse.org/projects/iot.paho
|
||||
|
||||
## Trademarks
|
||||
|
||||
Paho™ is a trademark of the Eclipse Foundation.
|
||||
|
||||
## Copyright
|
||||
|
||||
All content is the property of the respective authors or their employers. For
|
||||
more information regarding authorship of content, please consult the listed
|
||||
source code repository logs.
|
||||
|
||||
## Declared Project Licenses
|
||||
|
||||
This program and the accompanying materials are made available under the terms
|
||||
of the Eclipse Public License v2.0 which is available at
|
||||
https://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
v1.0 which is available at https://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
## Source Code
|
||||
|
||||
The project maintains the following source code repositories:
|
||||
|
||||
* https://github.com/eclipse/paho-website
|
||||
* https://github.com/eclipse/paho.golang
|
||||
* https://github.com/eclipse/paho.mqtt-sn.embedded-c
|
||||
* https://github.com/eclipse/paho.mqtt-spy
|
||||
* https://github.com/eclipse/paho.mqtt.android
|
||||
* https://github.com/eclipse/paho.mqtt.c
|
||||
* https://github.com/eclipse/paho.mqtt.cpp
|
||||
* https://github.com/eclipse/paho.mqtt.d
|
||||
* https://github.com/eclipse/paho.mqtt.embedded-c
|
||||
* https://github.com/eclipse/paho.mqtt.golang
|
||||
* https://github.com/eclipse/paho.mqtt.java
|
||||
* https://github.com/eclipse/paho.mqtt.javascript
|
||||
* https://github.com/eclipse/paho.mqtt.m2mqtt
|
||||
* https://github.com/eclipse/paho.mqtt.python
|
||||
* https://github.com/eclipse/paho.mqtt.ruby
|
||||
* https://github.com/eclipse/paho.mqtt.rust
|
||||
* https://github.com/eclipse/paho.mqtt.testing
|
||||
|
||||
## Cryptography
|
||||
|
||||
Content may contain encryption software. The country in which you are currently
|
||||
may have restrictions on the import, possession, and use, and/or re-export to
|
||||
another country, of encryption software. BEFORE using any encryption software,
|
||||
please check the country's laws, regulations and policies concerning the import,
|
||||
possession, or use, and re-export of encryption software, to see if this is
|
||||
permitted.
|
||||
16
SECURITY.md
Normal file
16
SECURITY.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Security Policy
|
||||
|
||||
This project follows the [Eclipse Vulnerability Reporting Policy](https://www.eclipse.org/security/policy.php).
|
||||
Vulnerabilities are tracked by the Eclipse security team, in cooperation with the project lead.
|
||||
Fixing vulnerabilities is taken care of by the project committers, with assistance and guidance of the security
|
||||
team.
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Eclipse Paho provides security updates for the most recent version only.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
We recommend that in case of suspected vulnerabilities you do not create a GitHub issue, but instead contact the
|
||||
Eclipse Security Team directly sending an email to security@eclipse.org.
|
||||
|
||||
Reference in New Issue
Block a user