-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DTLS support to MQTT-SN client #348
Conversation
5ff973a
to
f262a6b
Compare
examples/mqttnet.c
Outdated
#if defined(WOLFMQTT_SN) && defined(WOLFSSL_DTLS) | ||
if (wolfSSL_dtls(mqttCtx->client.tls.ssl)) { | ||
break; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like this, but during the handshake, wolfSSL calls read with a max size of 1900b, never intending to fully fill the buffer. So I needed a way to break out of the loop. I am very open to suggestions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just means you got some data and instead of waiting for "all" data you just break out for DTLS. Seems fine to me. However you can likely do this for the TLS case too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and working. Perhaps add some of the PR notes into the SN example section of the README
I added a new README for the MQTT-SN examples. It was getting pretty long, so makes sense to move it. |
examples/mqttnet.c
Outdated
#if defined(WOLFMQTT_SN) && defined(WOLFSSL_DTLS) | ||
if (wolfSSL_dtls(mqttCtx->client.tls.ssl)) { | ||
break; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just means you got some data and instead of waiting for "all" data you just break out for DTLS. Seems fine to me. However you can likely do this for the TLS case too...
src/mqtt_packet.c
Outdated
/* Read first 2 bytes using MSG_PEEK */ | ||
rc = MqttSocket_Peek(client, rx_buf, 2, timeout_ms); | ||
/* Read first 2 bytes */ | ||
if (client->flags & MQTT_CLIENT_FLAG_IS_TLS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a flag for DTLS? Seems like you could use this flag for the mqtt_socket.c TLS method?
src/mqtt_socket.c
Outdated
@@ -359,7 +359,21 @@ int MqttSocket_Peek(MqttClient *client, byte* buf, int buf_len, int timeout_ms) | |||
|
|||
return rc; | |||
} | |||
|
|||
#if defined(ENABLE_MQTT_TLS) && defined(WOLFSSL_DTLS) | |||
void MqttSocket_SetDTLS(MqttClient *client, int value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the API to be in mqtt_client.c and named MqttClient_SetFlags
API that takes in uint32_t
of enum MqttClientFlags
values as an argument.
Something like:
word32 MqttClient_SetFlags(MqttClient *client, word32 mask, word32 flags)
{
if (client != NULL) {
client->flags &= ~mask;
client->flags |= flags;
return client->flags;
}
return 0;
}
This is multi-purpose because you can set or clear any flags and return the final state.
src/mqtt_client.c
Outdated
#ifdef WOLFMQTT_MULTITHREAD | ||
wm_SemUnlock(&client->lockClient); | ||
#endif | ||
return client->flags; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please get the final flags before unlock.
Ready for merge! |
Tested with mosquitto as broker, https://github.com/eclipse/paho.mqtt-sn.embedded-c as gateway.
MQTTSNGateway/gateway.conf
. Also set paths to DTLS cert / key.<gateway-folder>/MQTTSNGateway$ ./build.sh dtls
./configure --enable-dtls && make && sudo make install
./configure --enable-sn && make
mosquitto
<gateway-folder>/MQTTSNGateway$ ./bin/MQTT-SNGateway
./examples/sn-client/sn-client -t