11 Commits

Author SHA1 Message Date
Ian Craggs
092bdcfd72 Add required Eclipse meta docs 2024-01-18 15:50:40 +00:00
tomoaki
e263dc37b1 Bugfix of #248
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
2021-11-12 16:11:07 +09:00
tomoaki
9c67c75939 Bugfix of #246
Revert a line deleted by commit 15c527e


Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
2021-10-02 11:21:21 +09:00
Tomoaki Yamaguchi
a37803ac04 Merge pull request #245 from eclipse/develop
Update Gateway
2021-09-16 15:32:13 +09:00
tomoaki
52500a0c79 Update README
delete unused include statement
2021-09-16 11:13:13 +09:00
tomoaki
0398566e82 Bugfix of #241
DTLS Enhancement #90 complete.
OpenSSL version 1.1.1k 25 Mar. 2021 is required.
This fix does not work with version 1.1.1 11 sep. 2018

Merge branch 'dtls' into develop
2021-08-11 18:49:31 +09:00
tomoaki
4dcfa98303 Bugfix of DTLS6 #241
This fix doesn't work on OpenSSL version 1.1.1 11.sep 2018
Upgrade to version 1.1.1k 25 Mar. 2021

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
2021-08-11 18:30:51 +09:00
tomoaki
fa0925d24e settings was changed
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
2021-08-01 19:27:17 +09:00
tomoaki
f2dcda358f Bugfix of #234
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
2021-07-14 11:28:20 +09:00
tomoaki
776099ebb3 Bugfix Set a secure flag to a Client instance.
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
2021-07-09 07:45:39 +09:00
Tomoaki Yamaguchi
ca467548b4 Merge pull request #217 from eclipse/develop
Merge latest develop branch to master
2020-10-13 15:41:02 +09:00
27 changed files with 478 additions and 195 deletions

View File

@@ -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 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"> <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="DTLS"/>
<listOptionValue builtIn="false" value="DEBUG_NW"/>
</option> </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1626802967" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1626802967" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool> </tool>
@@ -81,7 +80,8 @@
</toolChain> </toolChain>
</folderInfo> </folderInfo>
<sourceEntries> <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"/> <entry excluding="samples|test" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket"/>
</sourceEntries> </sourceEntries>
</configuration> </configuration>
@@ -153,7 +153,8 @@
</folderInfo> </folderInfo>
<sourceEntries> <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="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"/> <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
</sourceEntries> </sourceEntries>
</configuration> </configuration>

View File

@@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-176156747064280842" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-190494363728860458" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>
@@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-176157551606184930" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-190493586662438402" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

94
CODE_OF_CONDUCT.md Normal file
View 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 respondents 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 Committees 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.
Its impossible to spell out every possible scenario that might be deemed a violation of this Code. Instead, we rely on one anothers good judgment to uphold a high standard of integrity within all Eclipse Spaces. Sometimes, identifying the right thing to do isnt 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
View 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

View File

@@ -40,14 +40,14 @@ $(SUBDIR)/Util.cpp \
CXX := g++ CXX := g++
CPPFLAGS += CPPFLAGS +=
INCLUDES += -I$(SUBDIR) INCLUDES += -I$(SUBDIR) -I/usr/local/opt/openssl/include
DEF1 := DEF1 :=
DEF2 := DEF2 :=
DEFS := -D$(SN) $(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 := LDFLAGS :=
CXXFLAGS := -Wall -O3 -std=c++11 CXXFLAGS := -Wall -O3 -std=c++11
LDADD := -lbluetooth -lssl -lcrypto LDADD := -lssl -lcrypto $(LDADDBLT)
OUTDIR := Build OUTDIR := Build
PROG := $(OUTDIR)/$(PROGTEST) PROG := $(OUTDIR)/$(PROGTEST)

View File

@@ -8,6 +8,7 @@ if [ $1 == "udp" ] ; then
elif [ $1 == "udp6" ] ; then elif [ $1 == "udp6" ] ; then
make SN=UDP6 $DEF1 $DEF2 make SN=UDP6 $DEF1 $DEF2
elif [ $1 == "rfcomm" ] ; then elif [ $1 == "rfcomm" ] ; then
export LDADDBLT=-lbluetooth
make SN=RFCOMM $DEF1 $DEF2 make SN=RFCOMM $DEF1 $DEF2
elif [ $1 == "dtls" ] ; then elif [ $1 == "dtls" ] ; then
make SN=DTLS $DEF1 $DEF2 make SN=DTLS $DEF1 $DEF2
@@ -16,7 +17,7 @@ elif [ $1 == "dtls6" ] ; then
elif [ $1 == "clean" ] ; then elif [ $1 == "clean" ] ; then
make clean make clean
else else
echo "Usage: build.sh [ udp | udp6 | rfcomm | dtls | dtls6] | clean" echo "Usage: build.sh [ udp | udp6 | rfcomm | dtls | dtls6 | clean]"
fi fi

View File

@@ -52,7 +52,7 @@ extern LScreen* theScreen;
* UDP,DTLS Configuration (theNetcon) * UDP,DTLS Configuration (theNetcon)
*------------------------------------------------------*/ *------------------------------------------------------*/
UDPCONF = { "GatewayTestClient", // ClientId UDPCONF = { "GatewayTestClient", // ClientId
{ 225, 1, 1, 1 }, // Multicast group IP { 225, 1, 1, 1 }, // Multicast group IP
1883, // Multicast group Port 1883, // Multicast group Port
20020, // Local PortNo 20020, // Local PortNo
}; };
@@ -78,13 +78,13 @@ RFCOMMCONF = { "GatewayTestClient", // ClientId
/*------------------------------------------------------ /*------------------------------------------------------
* Client Configuration (theMqcon) * Client Configuration (theMqcon)
*------------------------------------------------------*/ *------------------------------------------------------*/
MQTTSNCONF = { 60, //KeepAlive [seconds] MQTTSNCONF = { 60, //KeepAlive [seconds]
true, //Clean session true, //Clean session
300, //Sleep duration [seconds] 300, //Sleep duration [seconds]
"", //WillTopic "willtopic", //WillTopic
"", //WillMessage "willmsg", //WillMessage
0, //WillQos 0, //WillQos
false //WillRetain false //WillRetain
}; };
/*------------------------------------------------------ /*------------------------------------------------------

View File

@@ -207,12 +207,12 @@ int LGwProxy::getConnectResponce(void)
if (_network.sslConnect() > 0) if (_network.sslConnect() > 0)
{ {
_status = GW_CONNECTING; _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; break;
} }
else 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 #else

View File

@@ -252,11 +252,11 @@ typedef enum
/*================================= /*=================================
* Starting prompt * 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_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_COPYRIGHT3 " * Author : Tomoaki YAMAGUCHI"
#define PAHO_COPYRIGHT4 " ***************************************************************************" #define PAHO_COPYRIGHT4 " ***************************************************************************"

View File

@@ -224,7 +224,6 @@ bool LDtlsPort::open(LUdpConfig *config)
if (setsockopt(_sockfdMcast, IPPROTO_IP, IP_MULTICAST_LOOP, &optval, sizeof(optval)) < 0) 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"); 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(); close();
return false; return false;
} }
@@ -236,7 +235,6 @@ bool LDtlsPort::open(LUdpConfig *config)
if (setsockopt(_sockfdMcast, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) 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"); 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(); close();
return false; return false;
} }
@@ -256,7 +254,6 @@ int LDtlsPort::unicast(const uint8_t *buf, uint32_t length)
{ {
int rc = 0; int rc = 0;
SSL_get_error(_ssl, rc); SSL_get_error(_ssl, rc);
D_NWLOG("errno == %d in LDtlsPort::unicast\n", rc);
DISPLAY("errno == %d in LDtlsPort::unicast\n", rc); DISPLAY("errno == %d in LDtlsPort::unicast\n", rc);
} }
else else
@@ -386,7 +383,7 @@ bool LDtlsPort::checkRecvBuf()
return true; return true;
} }
} }
_castStat = 0; _castStat = STAT_NONE;
return false; return false;
} }

View File

@@ -36,13 +36,14 @@
#define SOCKET_MAXRECV 500 #define SOCKET_MAXRECV 500
#define SOCKET_MAXBUFFER_LENGTH 500 // buffer size #define SOCKET_MAXBUFFER_LENGTH 500 // buffer size
#define STAT_UNICAST 1
#define STAT_MULTICAST 2
#define STAT_SSL 3
using namespace std; using namespace std;
namespace linuxAsyncClient { namespace linuxAsyncClient {
#define STAT_NONE 0
#define STAT_UNICAST 1
#define STAT_MULTICAST 2
#define STAT_SSL 3
/*======================================== /*========================================
Class LDtlsPort Class LDtlsPort
=======================================*/ =======================================*/

View File

@@ -75,8 +75,8 @@ uint8_t* LNetwork::getMessage(int *len)
if (checkRecvBuf()) if (checkRecvBuf())
{ {
uint16_t recvLen = LDtls6Port::recv(_rxDataBuf, MQTTSN_MAX_PACKET_SIZE, false, &_ipAddress, &_portNo); 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)); int addrFlg = memcmp(_ipAddress.s6_addr, _gwIpAddress.s6_addr, sizeof(_gwIpAddress.s6_addr));
if (isUnicast() && diffAddr && (_portNo != _gwPortNo)) if (isUnicast() && addrFlg && (_portNo != _gwPortNo))
{ {
return 0; return 0;
} }
@@ -141,11 +141,14 @@ int LNetwork::sslConnect(void)
LDtls6Port::LDtls6Port() LDtls6Port::LDtls6Port()
{ {
_disconReq = false; _disconReq = false;
memset(_pollfds, 0, sizeof(_pollfds)); _castStat = STAT_NONE;
_sock = 0;
_castStat = 0;
_ifIndex = 0; _ifIndex = 0;
_gIpAddrStr = NULL; _gIpAddrStr = nullptr;
_sockfdMcast = 0;
_sockfdSsl = 0;
_ctx = nullptr;
_ssl = nullptr;
_gPortNo = _uPortNo = 0;
} }
LDtls6Port::~LDtls6Port() LDtls6Port::~LDtls6Port()
@@ -159,12 +162,14 @@ LDtls6Port::~LDtls6Port()
void LDtls6Port::close() 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); ::close(_sockfdSsl);
_pollfds[i].fd = 0; _sockfdSsl = 0;
} }
} }
} }
@@ -172,7 +177,6 @@ void LDtls6Port::close()
bool LDtls6Port::open(LUdp6Config *config) bool LDtls6Port::open(LUdp6Config *config)
{ {
int optval = 1; int optval = 1;
int sock = 0;
sockaddr_in6 addr6; sockaddr_in6 addr6;
char errmsg[256]; char errmsg[256];
@@ -205,22 +209,22 @@ bool LDtls6Port::open(LUdp6Config *config)
} }
/* create a multicast socket */ /* create a multicast socket */
sock = socket(AF_INET6, SOCK_DGRAM, 0); _sockfdMcast = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0) if (_sockfdMcast < 0)
{ {
return false; return false;
} }
optval = 1; optval = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); setsockopt(_sockfdMcast, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)); setsockopt(_sockfdMcast, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
memset(&addr6, 0, sizeof(addr6)); memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6; addr6.sin6_family = AF_INET6;
addr6.sin6_port = _gPortNo; addr6.sin6_port = _gPortNo;
addr6.sin6_addr = in6addr_any; 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)); D_NWLOG("\033[0m\033[0;31merror %s ::bind() in Udp6Port::open\033[0m\033[0;37m\n", strerror(errno));
return false; return false;
@@ -229,21 +233,21 @@ bool LDtls6Port::open(LUdp6Config *config)
ipv6_mreq addrm; ipv6_mreq addrm;
addrm.ipv6mr_interface = _ifIndex; addrm.ipv6mr_interface = _ifIndex;
inet_pton(AF_INET6, config->ipAddress, &addrm.ipv6mr_multiaddr); 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)); D_NWLOG("\033[0m\033[0;31merror %s IPV6_ADD_MEMBERSHIP in Udp6Port::open\033[0m\033[0;37m\n", strerror(errno));
close(); close();
return false; 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)); D_NWLOG("\033[0m\033[0;31merror %s IPV6_MULTICAST_LOOP in Udp6Port::open\033[0m\033[0;37m\n", strerror(errno));
close(); close();
return false; return false;
} }
_pollfds[1].fd = sock;
_pollfds[1].events = POLLIN;
_gIpAddr.sin6_family = AF_INET6; _gIpAddr.sin6_family = AF_INET6;
_gIpAddr.sin6_port = _gPortNo; _gIpAddr.sin6_port = _gPortNo;
memcpy(&_gIpAddr.sin6_addr, (const void*) &addrm.ipv6mr_multiaddr, sizeof(addrm.ipv6mr_multiaddr)); 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() bool LDtls6Port::isUnicast()
{ {
return (_sock == _pollfds[0].fd && _sock > 0); return (_castStat == STAT_UNICAST);
} }
int LDtls6Port::unicast(const uint8_t *buf, uint32_t length) 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 else
{ {
D_NWLOG("sendto gateway via DTLS "); D_NWLOG("sendto gateway via DTLS6 ");
for (uint16_t i = 0; i < length; i++) for (uint16_t i = 0; i < length; i++)
{ {
D_NWLOG(" %02x", *(buf + i)); D_NWLOG(" %02x", *(buf + i));
}D_NWLOG("\n"); }
D_NWLOG("\n");
if (!theClientMode) if (!theClientMode)
{ {
@@ -299,12 +305,12 @@ int LDtls6Port::multicast(const uint8_t *buf, uint32_t length)
{ {
char sbuf[SCREEN_BUFF_SIZE]; char sbuf[SCREEN_BUFF_SIZE];
char portStr[8]; 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) 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; return errno;
} }
else else
@@ -313,7 +319,9 @@ int LDtls6Port::multicast(const uint8_t *buf, uint32_t length)
for (uint16_t i = 0; i < length; i++) for (uint16_t i = 0; i < length; i++)
{ {
D_NWLOG(" %02x", *(buf + i)); D_NWLOG(" %02x", *(buf + i));
}D_NWLOG("\n"); }
D_NWLOG("\n");
if (!theClientMode) if (!theClientMode)
{ {
@@ -339,32 +347,52 @@ int LDtls6Port::multicast(const uint8_t *buf, uint32_t length)
bool LDtls6Port::checkRecvBuf() bool LDtls6Port::checkRecvBuf()
{ {
timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 50000; // 50 msec
uint8_t buf[2]; uint8_t buf[2];
fd_set recvfds;
int maxSock = 0;
int cnt = poll(_pollfds, 2, 2000); // Timeout 2secs FD_ZERO(&recvfds);
if (cnt == 0) 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) maxSock = _sockfdMcast;
{
_castStat = STAT_SSL;
_sock = _pollfds[0].fd;
return true;
}
} }
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; _castStat = STAT_MULTICAST;
_sock = _pollfds[1].fd;
return true; 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; 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) else if (_castStat == STAT_MULTICAST)
{ {
D_NWLOG("Mcast "); D_NWLOG("Mcast ");
status = ::recvfrom(_sock, buf, length, flags, (sockaddr*) &sender, &addrlen); status = ::recvfrom(_sockfdMcast, buf, length, flags, (sockaddr*) &sender, &addrlen);
} }
else else
{ {
@@ -445,63 +473,82 @@ int LDtls6Port::recvfrom(uint8_t *buf, uint16_t length, int flags, in6_addr *ipA
return status; 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 optval = 1;
int sock = _pollfds[0].fd;
if (_ssl != 0) if (_ssl != 0)
{ {
D_NWLOG("LDtls6Port::sslConnect SSL exists.\n");
SSL_shutdown(_ssl);
SSL_free(_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); _sockfdSsl = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock <= 0) if (_sockfdSsl <= 0)
{ {
D_NWLOG("LDtls6Port::sslConnect Can't create a socket\n");
return -1; return -1;
} }
optval = 1; optval = 1;
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)); setsockopt(_sockfdSsl, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval));
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR || SO_REUSEPORT, &optval, sizeof(optval)); setsockopt(_sockfdSsl, SOL_SOCKET, SO_REUSEADDR || SO_REUSEPORT, &optval, sizeof(optval));
if (_ifIndex > 0) if (_ifIndex > 0)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &_ifIndex, sizeof(_ifIndex)); setsockopt(_sockfdSsl, IPPROTO_IP, IP_BOUND_IF, &_ifIndex, sizeof(_ifIndex));
#else #else
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, _interfaceName.c_str(), _interfaceName.size()); setsockopt(_sockfdSsl, SOL_SOCKET, SO_BINDTODEVICE, _interfaceName.c_str(), _interfaceName.size());
#endif #endif
} }
struct sockaddr_in6 addr; sockaddr_in6 addr;
addr.sin6_family = AF_INET6; addr.sin6_family = AF_INET6;
addr.sin6_port = _uPortNo; addr.sin6_port = _uPortNo;
addr.sin6_addr = in6addr_any; 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; return -1;
} }
_pollfds[0].fd = sock;
_pollfds[0].events = POLLIN;
uint16_t listenPort = htons(portNo); // Destination is a gateway address and portNo
struct sockaddr_in6 dest; int rc = 0;
sockaddr_in6 dest;
dest.sin6_family = AF_INET6; 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)); 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); _ssl = SSL_new(_ctx);
if (_ssl == nullptr)
{
D_NWLOG("SSL_new %s\n",strerror(errno));
return -1;
}
SSL_set_bio(_ssl, cbio, cbio); SSL_set_bio(_ssl, cbio, cbio);
#ifdef DEBUG_NW #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)); D_NWLOG("connect to %-15s:%-6u\n", addrBuf, ntohs(dest.sin6_port));
#endif #endif
timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);
errno = 0; errno = 0;
int stat = SSL_connect(_ssl); int stat = SSL_connect(_ssl);
if (stat != 1) if (stat != 1)
{ {
@@ -519,6 +571,7 @@ int LDtls6Port::sslConnect(in6_addr ipAddress, uint16_t portNo)
} }
else else
{ {
rc = 1;
D_NWLOG("SSL connected\n"); D_NWLOG("SSL connected\n");
} }
return rc; return rc;

View File

@@ -37,6 +37,7 @@
#define SOCKET_MAXRECV 500 #define SOCKET_MAXRECV 500
#define SOCKET_MAXBUFFER_LENGTH 500 // buffer size #define SOCKET_MAXBUFFER_LENGTH 500 // buffer size
#define STAT_NONE 0
#define STAT_UNICAST 1 #define STAT_UNICAST 1
#define STAT_MULTICAST 2 #define STAT_MULTICAST 2
#define STAT_SSL 3 #define STAT_SSL 3
@@ -68,9 +69,10 @@ private:
void close(); void close();
int recvfrom ( uint8_t* buf, uint16_t len, int flags, in6_addr* ipaddress, in_port_t* port ); 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_CTX *_ctx;
SSL *_ssl; SSL *_ssl;
pollfd _pollfds[2];
in_port_t _gPortNo; in_port_t _gPortNo;
in_port_t _uPortNo; in_port_t _uPortNo;
sockaddr_in6 _gIpAddr; sockaddr_in6 _gIpAddr;
@@ -78,7 +80,6 @@ private:
uint32_t _ifIndex; uint32_t _ifIndex;
string _interfaceName; string _interfaceName;
uint8_t _castStat; uint8_t _castStat;
int _sock;
bool _disconReq; bool _disconReq;
}; };

View File

@@ -197,6 +197,7 @@ bool LUdpPort::open(LUdpConfig *config)
if (::bind(_sockfdUcast, (struct sockaddr*) &addr, sizeof(addr)) < 0) 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; return false;
} }
@@ -216,6 +217,7 @@ bool LUdpPort::open(LUdpConfig *config)
if (::bind(_sockfdMcast, (struct sockaddr*) &addrm, sizeof(addrm)) < 0) 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; return false;
} }

View File

@@ -350,7 +350,7 @@ bool LUdp6Port::checkRecvBuf()
{ {
uint8_t buf[2]; uint8_t buf[2];
int cnt = poll(_pollfds, 2, 2000); // Timeout 2secs int cnt = poll(_pollfds, 2, 50); // Timeout 50m secs
if (cnt == 0) if (cnt == 0)
{ {
return false; return false;

View File

@@ -9,7 +9,7 @@ $ cd paho.mqtt-sn.embedded-c/MQTTSNGateway
``` ```
In order to build a gateway, one sensor network argument is required. 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. MQTT-SNGateway and MQTT-SNLogmonitor (executable programs) are built in ./bin directory.

View File

@@ -15,10 +15,10 @@
# Lines bigning with # are comment line. # Lines bigning with # are comment line.
# ClientId, SensorNetAddress, "unstableLine", "secureConnection" # ClientId, SensorNetAddress, "unstableLine", "secureConnection"
# in case of UDP, SensorNetAddress format is IPAddress: port no. # in case of UDP, SensorNetAddress format is IPAddress: port no.
# if the SensorNetwork is not stable, write "unstableLine". # if the SensorNetwork is not stable, specify "unstableLine".
# if Broker's Connection is SSL, write "secureConnection". # if Broker's Connection is TLS, specify "secureConnection".
# if the client is a forwarder, "forwarder" is required. # if the client is a forwarder,specify "forwarder".
# if the client send PUBLISH QoS-1, "QoS-1" is required. # if the client send PUBLISH QoS-1, specify "QoS-1".
# #
# Ex: # Ex:
# #Client List # #Client List
@@ -31,6 +31,17 @@
# #
# SensorNetwork address format is defined by SensorNetAddress::setAddress(string* data) function. # 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 GatewayTester, 172.16.1.11:20020
ClientPUB,172.16.1.11:2010 ClientPUB,172.16.1.11:2010
Client01,172.16.1.11:12001 Client01,172.16.1.11:12001

View File

@@ -81,7 +81,7 @@ ADD_LIBRARY(mqtt-sngateway_common
link_directories("/usr/local/lib") link_directories("/usr/local/lib")
# Mac # Mac
link_directories("/usr/local/opt/openssl") link_directories("/usr/local/opt/openssl/lib")
TARGET_INCLUDE_DIRECTORIES(mqtt-sngateway_common TARGET_INCLUDE_DIRECTORIES(mqtt-sngateway_common
@@ -91,6 +91,7 @@ TARGET_INCLUDE_DIRECTORIES(mqtt-sngateway_common
${OS}/${SENSORNET} ${OS}/${SENSORNET}
../../MQTTSNPacket/src ../../MQTTSNPacket/src
/usr/local/include /usr/local/include
/usr/local/opt/openssl/include
) )
IF(SENSORNET MATCHES "rfcomm") IF(SENSORNET MATCHES "rfcomm")

View File

@@ -101,6 +101,7 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
topicId.type = tp->getType(); topicId.type = tp->getType();
topicId.data.long_.len = pub.topiclen; topicId.data.long_.len = pub.topiclen;
topicId.data.long_.name = pub.topic; topicId.data.long_.name = pub.topic;
topicId.data.id = tp->getTopicId();
} }
else else
{ {

View File

@@ -424,7 +424,8 @@ Client* ClientList::createPredefinedTopic(MQTTSNString* clientId, string topicNa
return nullptr; return nullptr;
} }
client = createClient(NULL, clientId, aggregate); // <=== BUGFIX client = createClient(NULL, clientId, aggregate);
if (client == nullptr) if (client == nullptr)
{ {
return nullptr; return nullptr;

View File

@@ -20,8 +20,6 @@
#include "MQTTSNGWEncapsulatedPacket.h" #include "MQTTSNGWEncapsulatedPacket.h"
#include <cstring> #include <cstring>
//#include "MQTTSNGWForwarder.h"
using namespace MQTTSNGW; using namespace MQTTSNGW;
char* currentDateTime(void); char* currentDateTime(void);
/*===================================== /*=====================================
@@ -45,7 +43,7 @@ void ClientRecvTask::initialize(int argc, char** argv)
/* /*
* Receive a packet from clients via sensor netwwork * 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. * of MQTTSNPacketHandlingTask.
*/ */
void ClientRecvTask::run() void ClientRecvTask::run()
@@ -98,11 +96,11 @@ void ClientRecvTask::run()
continue; continue;
} }
SensorNetAddress* senderAddr = _gateway->getSensorNetwork()->getSenderAddress(); SensorNetAddress senderAddr = *_gateway->getSensorNetwork()->getSenderAddress();
if (packet->getType() == MQTTSN_ENCAPSULATED) if (packet->getType() == MQTTSN_ENCAPSULATED)
{ {
fwd = _gateway->getAdapterManager()->getForwarderList()->getForwarder(senderAddr); fwd = _gateway->getAdapterManager()->getForwarderList()->getForwarder(&senderAddr);
if (fwd != nullptr) if (fwd != nullptr)
{ {
@@ -124,7 +122,7 @@ void ClientRecvTask::run()
if (qosm1Proxy->isActive()) if (qosm1Proxy->isActive())
{ {
const char* clientName = qosm1Proxy->getClientId(senderAddr); const char *clientName = qosm1Proxy->getClientId(&senderAddr);
if (clientName != nullptr) if (clientName != nullptr)
{ {
@@ -134,7 +132,7 @@ void ClientRecvTask::run()
{ {
log(clientName, packet); log(clientName, packet);
WRITELOG("%s %s %s can send only PUBLISH with QoS-1.%s\n", 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; delete packet;
continue; continue;
} }
@@ -143,7 +141,7 @@ void ClientRecvTask::run()
if (client == nullptr) if (client == nullptr)
{ {
client = _gateway->getClientList()->getClient(senderAddr); client = _gateway->getClientList()->getClient(&senderAddr);
} }
} }
@@ -151,7 +149,7 @@ void ClientRecvTask::run()
{ {
log(client, packet, 0); log(client, packet, 0);
if (client->isDisconnect() && packet->getType() != MQTTSN_CONNECT) if (client->isDisconnect() && packet->getType() != MQTTSN_CONNECT && packet->getType() != MQTTSN_WILLTOPIC && packet->getType() != MQTTSN_WILLMSG)
{ {
WRITELOG("%s MQTTSNGWClientRecvTask %s is not connecting.%s\n", WRITELOG("%s MQTTSNGWClientRecvTask %s is not connecting.%s\n",
ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER); ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
@@ -183,7 +181,7 @@ void ClientRecvTask::run()
{ {
log(0, packet, &data.clientID); log(0, packet, &data.clientID);
WRITELOG("%s CONNECT message form %s is incorrect.%s\n", WRITELOG("%s CONNECT message form %s is incorrect.%s\n",
ERRMSG_HEADER, senderAddr->sprint(buf), ERRMSG_HEADER, senderAddr.sprint(buf),
ERRMSG_FOOTER); ERRMSG_FOOTER);
delete packet; delete packet;
continue; continue;
@@ -208,13 +206,13 @@ void ClientRecvTask::run()
/* Authentication is not required */ /* Authentication is not required */
if (_gateway->getGWParams()->clientAuthentication == false) if (_gateway->getGWParams()->clientAuthentication == false)
{ {
client->setClientAddress(senderAddr); client->setClientAddress(&senderAddr);
} }
} }
else else
{ {
/* create a new client */ /* 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) if (client == nullptr)
{ {
WRITELOG("%s Client(%s) was rejected. CONNECT message has been discarded.%s\n", 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); ERRMSG_FOOTER);
delete packet; delete packet;
continue; continue;
@@ -247,7 +245,7 @@ void ClientRecvTask::run()
else else
{ {
WRITELOG("%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n", 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); ERRMSG_FOOTER);
} }
delete packet; delete packet;

View File

@@ -27,9 +27,9 @@ namespace MQTTSNGW
/*================================= /*=================================
* Starting prompt * Starting prompt
==================================*/ ==================================*/
#define PAHO_COPYRIGHT0 " * " #define PAHO_COPYRIGHT0 " * MQTT-SN Gateway"
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse" #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_COPYRIGHT3 " * Author : Tomoaki YAMAGUCHI"
#define PAHO_COPYRIGHT4 " ***************************************************************************" #define PAHO_COPYRIGHT4 " ***************************************************************************"
/*========================================================== /*==========================================================

View File

@@ -61,6 +61,7 @@ unsigned char cookie_secret[COOKIE_SECRET_LENGTH];
SensorNetAddress::SensorNetAddress() SensorNetAddress::SensorNetAddress()
{ {
_portNo = 0; _portNo = 0;
_pfdsIndex = 0;
memset(&_ipAddr, 0, sizeof(_ipAddr)); memset(&_ipAddr, 0, sizeof(_ipAddr));
} }
@@ -223,7 +224,6 @@ void SensorNetAddress::setSockaddr4(sockaddr_in *sockaddr)
_ipAddr.af = sockaddr->sin_family; _ipAddr.af = sockaddr->sin_family;
_portNo = sockaddr->sin_port; _portNo = sockaddr->sin_port;
memcpy((void*) &_ipAddr.addr.ad4, (void*) &sockaddr->sin_addr, sizeof(_ipAddr.addr.ad4)); memcpy((void*) &_ipAddr.addr.ad4, (void*) &sockaddr->sin_addr, sizeof(_ipAddr.addr.ad4));
this->_pfdsIndex = 0;
} }
void SensorNetAddress::setSockaddr6(sockaddr_in6 *sockaddr) void SensorNetAddress::setSockaddr6(sockaddr_in6 *sockaddr)
@@ -231,7 +231,6 @@ void SensorNetAddress::setSockaddr6(sockaddr_in6 *sockaddr)
_ipAddr.af = sockaddr->sin6_family; _ipAddr.af = sockaddr->sin6_family;
_portNo = sockaddr->sin6_port; _portNo = sockaddr->sin6_port;
memcpy((void*) &_ipAddr.addr.ad6, (void*) &sockaddr->sin6_addr, sizeof(_ipAddr.addr.ad6)); memcpy((void*) &_ipAddr.addr.ad6, (void*) &sockaddr->sin6_addr, sizeof(_ipAddr.addr.ad6));
this->_pfdsIndex = 0;
} }
void SensorNetAddress::cpyAddr4(sockaddr_in *sockaddr) void SensorNetAddress::cpyAddr4(sockaddr_in *sockaddr)
@@ -244,8 +243,15 @@ void SensorNetAddress::cpyAddr4(sockaddr_in *sockaddr)
void SensorNetAddress::cpyAddr6(sockaddr_in6 *sockaddr) void SensorNetAddress::cpyAddr6(sockaddr_in6 *sockaddr)
{ {
sockaddr->sin6_family = _ipAddr.af; sockaddr->sin6_family = _ipAddr.af;
memcpy((void*) &sockaddr->sin6_addr, (void*) &_ipAddr.addr.ad6, sizeof(_ipAddr.addr.ad6));
sockaddr->sin6_port = _portNo; 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) char* SensorNetAddress::sprint(char *buf)
@@ -269,6 +275,7 @@ char* SensorNetAddress::sprint(char *buf)
return buf; return buf;
} }
sprintf(buf + strlen(buf), "%d", ntohs(_portNo)); sprintf(buf + strlen(buf), "%d", ntohs(_portNo));
sprintf(buf + strlen(buf), " index=%d", _pfdsIndex);
return buf; return buf;
} }
@@ -392,6 +399,7 @@ int Connections::getSockClient(int index)
void Connections::close(int index) void Connections::close(int index)
{ {
D_NWSTACK("Connection %d closed\n", index);
int idx = index + POLL_SSL; int idx = index + POLL_SSL;
_mutex.lock(); _mutex.lock();
int sock = _pollfds[idx].fd; int sock = _pollfds[idx].fd;
@@ -435,6 +443,7 @@ int Connections::addClientSSL(SSL *ssl, int sock)
int rc = _numfds - POLL_SSL; int rc = _numfds - POLL_SSL;
_numfds++; _numfds++;
_mutex.unlock(); _mutex.unlock();
D_NWSTACK("Add client connection index=%d, ssl=%ld, sock=%d\n", rc, (long int )ssl, sock);
return rc; return rc;
} }
@@ -453,6 +462,14 @@ SSL* Connections::getClientSSL(int index)
return _ssls[index + POLL_SSL]; 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 Class SensorNetwork
@@ -468,6 +485,8 @@ SSL* Connections::getClientSSL(int index)
#define DTLS_APPL 23 #define DTLS_APPL 23
#define DTLS_OTHERS 100 #define DTLS_OTHERS 100
#define DTLS_TIMEOUT 4
/* Certificate verification. Returns 1 if trusted, else 0 */ /* Certificate verification. Returns 1 if trusted, else 0 */
int verify_cert(int ok, X509_STORE_CTX *ctx); 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() SensorNetwork::SensorNetwork()
{ {
_senderAddr = new SensorNetAddress();
_multicastAddr = new SensorNetAddress();
_unicastAddr = new SensorNetAddress();
_conns = new Connections(); _conns = new Connections();
_dtlsctx = nullptr; _dtlsctx = nullptr;
_af = 0; _af = 0;
@@ -493,24 +509,18 @@ SensorNetwork::~SensorNetwork()
{ {
delete _conns; 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) 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()); SSL *ssl = _conns->getClientSSL(sendToAddr->getIndex());
int len = SSL_write(ssl, payload, payloadLength); int len = SSL_write(ssl, payload, payloadLength);
int rc = SSL_get_error(ssl, len); int rc = SSL_get_error(ssl, len);
@@ -530,7 +540,7 @@ int SensorNetwork::broadcast(const uint8_t *payload, uint16_t payloadLength)
int status; int status;
#ifndef DTLS6 #ifndef DTLS6
sockaddr_in dest; sockaddr_in dest;
_multicastAddr->cpyAddr4(&dest); _multicastAddr.cpyAddr4(&dest);
status = ::sendto(_conns->getSockUnicast(), payload, payloadLength, 0, (const sockaddr*) &dest, sizeof(dest)); status = ::sendto(_conns->getSockUnicast(), payload, payloadLength, 0, (const sockaddr*) &dest, sizeof(dest));
if (status < 0) if (status < 0)
@@ -542,7 +552,7 @@ int SensorNetwork::broadcast(const uint8_t *payload, uint16_t payloadLength)
#else #else
sockaddr_in6 dest; sockaddr_in6 dest;
_multicastAddr->cpyAddr6(&dest); _multicastAddr.cpyAddr6(&dest);
status = ::sendto(_conns->getSockUnicast(), payload, payloadLength, 0, (const sockaddr*) &dest, sizeof(dest)); status = ::sendto(_conns->getSockUnicast(), payload, payloadLength, 0, (const sockaddr*) &dest, sizeof(dest));
if (status < 0) if (status < 0)
@@ -577,7 +587,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
client.setFamily(_af); client.setFamily(_af);
// Check POLL_IN // Check POLL_IN
int cnt = _conns->poll(2000); // Timeout 2secs int cnt = _conns->poll(6000); // Timeout 6secs
if (cnt == 0) if (cnt == 0)
{ {
// Timeout // Timeout
@@ -588,21 +598,21 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
return -1; return -1;
} }
_mutex.lock(); _mutex.lock();
// Check Unicast Port // Check Unicast Port
if (_conns->getEventUnicast() & POLLIN) if (_conns->getEventUnicast() & POLLIN)
{ {
D_NWSTACK("Connect RECV\n"); D_NWSTACK("RECV Unicast SSL_connect\n");
// SSL connection request from a client // SSL connection request from a client
optval = 1; #ifdef DEBUG_NW
int dtls = getUnicastClient(&client);
client.clear(); D_NWSTACK("Packet type = %d\n", dtls);
client.setFamily(_af); #else
getUnicastClient(&client); getUnicastClient(&client);
#endif
sockListen = _conns->getSockUnicast(); sockListen = _conns->getSockUnicast();
// Listen Connection // Listen Connection
@@ -615,7 +625,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
int rc = 0; int rc = 0;
// SSL Listen // SSL Listen
D_NWSTACK("Listen SSL\n"); D_NWSTACK("DTLSv1_listen\n");
rc = DTLSv1_listen(ssl, (BIO_ADDR*) &client_addr); rc = DTLSv1_listen(ssl, (BIO_ADDR*) &client_addr);
@@ -631,6 +641,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
#ifndef DTLS6 #ifndef DTLS6
// DTLS over IPv4 // DTLS over IPv4
int client_fd = socket(AF_INET, SOCK_DGRAM, 0); int client_fd = socket(AF_INET, SOCK_DGRAM, 0);
optval = 1;
setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &optval, sizeof(optval)); setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &optval, sizeof(optval));
// Bind to Dtls PortNo // Bind to Dtls PortNo
bind(client_fd, (sockaddr*) &_serverAddr4, sizeof(sockaddr_in)); bind(client_fd, (sockaddr*) &_serverAddr4, sizeof(sockaddr_in));
@@ -639,6 +650,7 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
#else #else
// DTLS over IPv6 // DTLS over IPv6
int client_fd = socket(AF_INET6, SOCK_DGRAM, 0); int client_fd = socket(AF_INET6, SOCK_DGRAM, 0);
optval = 1;
setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &optval, sizeof(optval)); setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &optval, sizeof(optval));
// Bind to Dtls PortNo // Bind to Dtls PortNo
bind(client_fd, (sockaddr*) &_serverAddr6, sizeof(sockaddr_in6)); 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_set_fd(cbio, client_fd, BIO_NOCLOSE);
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, &client_addr); 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 // Finish handshake
int ret = SSL_accept(ssl); int ret = SSL_accept(ssl);
if (ret <= 0) if (ret <= 0)
{ {
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg)); 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_shutdown(ssl);
SSL_free(ssl); SSL_free(ssl);
::close(client_fd); ::close(client_fd);
@@ -667,11 +685,13 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
// save SensorNetworkAddress of Client // save SensorNetworkAddress of Client
client.setIndex(index); client.setIndex(index);
_senderAddr = &client; client.cpyAddr(&_senderAddr);
#ifdef DEBUG_NW #ifdef DEBUG_NW
char clientaddrBuf[128]; char clientaddrBuf[128];
client.sprint(clientaddrBuf); _senderAddr.sprint(clientaddrBuf);
D_NWSTACK("Client %s SSL Accepted. idx=%d\n", clientaddrBuf, index); D_NWSTACK("DTLS accepted client is %s index=%d client_fd=%d\n", clientaddrBuf, _senderAddr.getIndex(),
client_fd);
#endif #endif
} }
_mutex.unlock(); _mutex.unlock();
@@ -716,22 +736,23 @@ int SensorNetwork::read(uint8_t *buf, uint16_t bufLen)
// The packet is a MQTT-SN message // The packet is a MQTT-SN message
ssl = _conns->getClientSSL(i); ssl = _conns->getClientSSL(i);
int len = SSL_read_ex(ssl, (void*) buf, (size_t) bufLen, &recvlen); int len = SSL_read_ex(ssl, (void*) buf, (size_t) bufLen, &recvlen);
if (SSL_get_error(ssl, len) >= 0) 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
{ {
D_NWSTACK("SSL RECV Error\n"); D_NWSTACK("SSL RECV Error\n");
_conns->close(i); _conns->close(i);
recvlen = -1; 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(); _mutex.unlock();
return recvlen; return recvlen;
} }
@@ -880,7 +901,7 @@ const char* SensorNetwork::getDescription(void)
SensorNetAddress* SensorNetwork::getSenderAddress(void) SensorNetAddress* SensorNetwork::getSenderAddress(void)
{ {
return _senderAddr; return &_senderAddr;
} }
int SensorNetwork::openV4(string *ipAddress, uint16_t multiPortNo, uint16_t uniPortNo, uint32_t ttl) 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)); D_NWSTACK("error %d IP_MULTICAST_LOOP in UDP4_6Port::openV4 %s\n", errno, strerror(errno));
return -1; return -1;
} }
_multicastAddr->setFamily(AF_INET); _multicastAddr.setFamily(AF_INET);
_multicastAddr->setIpAddress(ipAddress); _multicastAddr.setIpAddress(ipAddress);
_multicastAddr->setPort(multiPortNo); _multicastAddr.setPort(multiPortNo);
_conns->setSockMulticast(sock); _conns->setSockMulticast(sock);
return 0; return 0;
} }
@@ -987,10 +1008,10 @@ int SensorNetwork::openV6(string *ipAddress, string *interface, uint16_t multiPo
return -1; return -1;
} }
_multicastAddr->setPort(multiPortNo); _multicastAddr.setPort(multiPortNo);
_unicastAddr->setPort(uniPortNo); _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)); D_NWSTACK("Incorrect IPV6 address in SensorNetwork::openV6 error %s\n", strerror(errno));
return -1; return -1;
@@ -1073,12 +1094,12 @@ int SensorNetwork::openV6(string *ipAddress, string *interface, uint16_t multiPo
} }
struct ipv6_mreq mreq; struct ipv6_mreq mreq;
mreq.ipv6mr_multiaddr = _multicastAddr->getIpAddress()->addr.ad6; mreq.ipv6mr_multiaddr = _multicastAddr.getIpAddress()->addr.ad6;
mreq.ipv6mr_interface = ifindex; 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; 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)); D_NWSTACK("Multicast IPV6_MULTICAST_HOPS in SensorNetwork::openV6 error %s\n", strerror(errno));
return -1; return -1;
} }
_multicastAddr->setFamily(AF_INET6); _multicastAddr.setFamily(AF_INET6);
_multicastAddr->setIpAddress(ipAddress); _multicastAddr.setIpAddress(ipAddress);
_multicastAddr->setPort(multiPortNo); _multicastAddr.setPort(multiPortNo);
return 0; return 0;
} }
@@ -1169,14 +1190,14 @@ int SensorNetwork::getSenderAddress(int sock, SensorNetAddress *addr)
if (len < 0 && errno != EAGAIN) 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; return -1;
} }
addr->setFamily(AF_INET);
addr->getIpAddress()->addr.ad4 = sender4.sin_addr; addr->setSockaddr4(&sender4);
addr->setPort(sender4.sin_port);
D_NWSTACK("SensorNetwork::getSenderAddress recved from %s:%d length = %d\n", inet_ntoa(sender4.sin_addr), D_NWSTACK("SensorNetwork::getSenderAddress recved from %s:%d length = %d fd=%d\n", inet_ntoa(sender4.sin_addr),
ntohs(sender4.sin_port), len); ntohs(addr->getPort()), len, sock);
if (len >= 13) if (len >= 13)
{ {
@@ -1191,27 +1212,34 @@ int SensorNetwork::getSenderAddress(int sock, SensorNetAddress *addr)
//AF_INET6 //AF_INET6
sockaddr_in6 sender6 = { 0 }; sockaddr_in6 sender6 = { 0 };
socklen_t addrlen6 = sizeof(sender6); socklen_t addrlen6 = sizeof(sender6);
unsigned long int buf = 0; char buf[16];
len = ::recvfrom(sock, &buf, 1, MSG_PEEK, (sockaddr*) &sender6, &addrlen6); int rc = DTLS_OTHERS;
len = ::recvfrom(sock, &buf, 15, MSG_PEEK, (sockaddr*) &sender6, &addrlen6);
if (len < 0 && errno != EAGAIN) if (len < 0 && errno != EAGAIN)
{ {
D_NWSTACK("errno = %d in SensorNetwork::getSender\n", errno); D_NWSTACK("errno = %d in SensorNetwork::getSenderAddress\n", errno);
return len; return -1;
} }
addr->setFamily(AF_INET6);
addr->setSockaddr6(&sender6); addr->setSockaddr6(&sender6);
addr->setPort(sender4.sin_port);
#ifdef DEBUG_NW #ifdef DEBUG_NW
char senderstr[INET6_ADDRSTRLEN]; char senderstr[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &sender6.sin6_addr,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
#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) void SensorNetwork::clearRecvData(int sock)
@@ -1220,6 +1248,12 @@ void SensorNetwork::clearRecvData(int sock)
::recv(sock, buf, MQTTSNGW_MAX_PACKET_SIZE, 0); ::recv(sock, buf, MQTTSNGW_MAX_PACKET_SIZE, 0);
} }
Connections* SensorNetwork::getConnections(void)
{
return _conns;
}
int verify_cert(int ok, X509_STORE_CTX *ctx) int verify_cert(int ok, X509_STORE_CTX *ctx)
{ {
return 1; return 1;

View File

@@ -57,6 +57,7 @@ public:
void setSockaddr6(sockaddr_in6 *sockaddr); void setSockaddr6(sockaddr_in6 *sockaddr);
void cpyAddr4(sockaddr_in *sockaddr); void cpyAddr4(sockaddr_in *sockaddr);
void cpyAddr6(sockaddr_in6 *sockaddr); void cpyAddr6(sockaddr_in6 *sockaddr);
void cpyAddr(SensorNetAddress *addr);
in_port_t getPort(void); in_port_t getPort(void);
ipAddr_t* getIpAddress(void); ipAddr_t* getIpAddress(void);
void setIndex(int index); void setIndex(int index);
@@ -109,6 +110,7 @@ public:
int getEventUnicast(void); int getEventUnicast(void);
int getEventListen(void); int getEventListen(void);
void closeSSL(int index); void closeSSL(int index);
void print(void);
private: private:
pollfd *_pollfds; pollfd *_pollfds;
SSL **_ssls; SSL **_ssls;
@@ -133,6 +135,7 @@ public:
void initialize(void); void initialize(void);
const char* getDescription(void); const char* getDescription(void);
SensorNetAddress* getSenderAddress(void); SensorNetAddress* getSenderAddress(void);
Connections* getConnections(void);
void close(); void close();
private: private:
@@ -145,9 +148,9 @@ private:
void clearRecvData(int sock); void clearRecvData(int sock);
Mutex _mutex; Mutex _mutex;
SensorNetAddress *_senderAddr; SensorNetAddress _senderAddr;
SensorNetAddress *_multicastAddr; SensorNetAddress _multicastAddr;
SensorNetAddress *_unicastAddr; SensorNetAddress _unicastAddr;
string _description; string _description;
SSL_CTX *_dtlsctx; SSL_CTX *_dtlsctx;
Connections *_conns; Connections *_conns;

View File

@@ -360,9 +360,9 @@ int UDPPort6::open(uint16_t uniPortNo, uint16_t multiPortNo, const char *multica
ipv6_mreq addrm; ipv6_mreq addrm;
addrm.ipv6mr_interface = ifindex; addrm.ipv6mr_interface = ifindex;
inet_pton(AF_INET6, multicastAddr, &addrm.ipv6mr_multiaddr); 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(); close();
return false; return false;
} }

55
NOTICE Normal file
View 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
View 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.