1
0
mirror of https://github.com/FreeRTOS/coreMQTT synced 2025-06-30 23:51:10 +08:00

446 Commits

Author SHA1 Message Date
abhidixi11
87821eb365 Reconnect Logic (#995)
feature: Reconnect Logic

Sample  reconnect logic code for POSIX platform.
2020-07-01 12:26:39 -07:00
leegeth
e01a96320f MQTT_Connect with retries (#994)
Update the logic in MQTT_Connect to work with retries if a timeout of 0ms is passed
2020-06-30 15:53:00 -07:00
leegeth
e4451c3c4b Handle session present error case (#1025)
Handle session present error case

Handle an error case when a session present flag is received from
broker and a clean session is requested.
2020-06-30 12:35:46 -07:00
leegeth
7ecb117dae MISRA violation fixes (#1027) 2020-06-30 12:23:25 -07:00
leegeth
2699c5a753 MQTT - Handle resends (#1007)
Handling the resend and receive of duplicate packets when an MQTT session is reestablished.

These are the cases that is handled in this PR,

When a session is reestablished,
Outgoing publishes:

Resend PUBLISHes for which and ack is not received(PUBACK and PUBREC).
Resend PUBRELs for PUBLISHes for which PUBCOMP was not received.
Incoming publishes:

Handle duplicate QoS1 and QoS2 PUBLISHes
Handle duplicate PUBRELs.

This change also handles the message ordering requirement in MQTT3.1.1 spec while re sending publishes and PUBRELs.
2020-06-29 17:33:28 -07:00
Muneeb Ahmed
fffa63d4be Initialize transport interface for MQTT init happy path test (#1023) 2020-06-29 14:25:15 -07:00
SarenaAWS
21e3b6faee CBMC Proofs for MQTT_Init, MQTT_GetPacketId, and MQTT_GetIncomingPacketTypeAndLength (#1005)
+ CBMC proof infrastructure.
2020-06-25 13:19:06 -07:00
Muneeb Ahmed
c763afec06 Add MQTT Receive Loop without keep alive (#990)
* Add MQTT Receive Loop without keep alive

* Add unit test for receive loop

* Enforce presence of getTime function
2020-06-25 11:28:39 -07:00
SarenaAWS
8a3811124c Small checks for MQTT_GetPacketId and MQTT_GetIncomingPacketTypeAndLength (#1014)
* MQTT library updates for intentional overflow check and null parameter check.
2020-06-25 10:25:48 -07:00
Archit Aggarwal
23b937b552 MQTT Integration tests for Pub/Sub with all QoS levels (#1000)
* Complete transport utilities library

* Get a building integration test for PubSub with Qos 0

* Updates to CMake for building integration test target

* Working QoS1 test and new test for QoS0

* Fix flaky behavior of QoS1 test by increasing ProcessLoop timeout

* Minor changes for logging configuration in test and tls_utils files

* Updates to CMock tooling for building mqtt_system_utest target

* Add a test case for Pub/Sub with QoS2

* Changes from review comments

* Change Publish request to not set retain flag to prevent inter-test side-effects

* Doc hygiene changes from more review comments

* Doc fix in demos/transport/CMakeLists.txt

* Remaining hygiene changes from review comments

* Rename integration test file to mqtt_system_test.c

* Update filename for @file tags in transport_utils files

* Update header macros for transport header files

* Remove MQTT build dependency from transport_utils. Rename CMake variables from utest to stest for integration tests

* Add inclue path for logging headers to transport_utils

* Use spaces instead of tabs
2020-06-18 16:09:24 -07:00
Muneeb Ahmed
85ee3f07c6 Rename MQTTNetworkContext_t to NetworkContext_t (#999) 2020-06-17 16:09:37 -07:00
Archit Aggarwal
70e130a5aa Update logConnackResponse to log success response at Info level (#1001) 2020-06-16 16:39:08 -07:00
Muneeb Ahmed
468a237cf4 Fix MQTT MISRA violations (#993)
* Fix MQTT MISRA violations

* Remove unnecessary const

* Remove unused function

* Fix string.h warning and add macro to disable logs

* Use ternary for MISRA 10.5

* Remove TODO from logging header
2020-06-15 14:58:42 -07:00
leegeth
fa62c7170a Fix buffer corruption for incoming publishes (#998) 2020-06-15 10:10:34 -07:00
Archit Aggarwal
6fc8503210 Fix/logging macro redefinition in demos (#989)
* Use #ifndef around logging macro definitions in config files to resolve macro re-definition warning in demo builds

* Complete changes to HTTP and MQTT demos for logging config

* Add comments for config file includes in MQTT and HTTP library files

* Minor doc update for logging configuration across all config files
2020-06-12 11:33:52 -07:00
Muneeb Ahmed
ee1f736b80 MQTT State engine refactor and hygiene (#979)
* Refactor state engine

* Reduce complexity and add strerror for state engine

* Fix MQTT build warnings and add status strerror

* Fix publish unit test to not trigger assert
2020-06-11 19:49:32 -07:00
Oscar Michael Abrina
3f700ff11e Add MQTT ping and subscribe unit tests (#965)
* Add setupSubscriptionInfo

* Add simple test for subscribe

* Add passing happy path test for MQTT_Subscribe

* Achieve full coverage for MQTT_Subscribe and MQTT_Unsubscribe and its private functions

* Add coverage for MQTT_Ping

* Update comments

* Move private method to top

* Use MQTT_GetUnsubscribePacketSize for Unsubscribe tests

* Make calls one line

* Fix test_MQTT_SerializeConnect_Invalid_Params by setting connectInfo
2020-05-28 17:00:09 -07:00
leegeth
87021d0a72 Fix warnings when logs are enabled in MQTT (#974) 2020-05-28 16:00:12 -07:00
Muneeb Ahmed
67af5c2266 Increase coverage of lightweight unit tests (#968)
* Add tests for MQTT_SerializePublishHeader

* Add tests for MQTT_SerializeAck and packet sizes

* Verify buffers for serializer unit tests
2020-05-28 15:05:46 -07:00
Oscar Michael Abrina
4da8efdf72 Add CMock unit tests for MQTT_ProcessLoop (#963)
* Add setup for testing handleIncomingPublish

* Add coverage for handleIncomingPublish

* Add callbacks for pubrec, pubrel, puback

* Coverage for Acks

* Add coverage for SUBACK and PINGRESP

* Add coverage for all methods except handleKeepAlive

* Add changes to mqtt_utest.c

* Create expectProcessLoopCalls private method to make tests look much cleaner

* Decouple context and expectProcessLoopCalls

* Full coverage

* Add @brief for all methods and variables

* Update expectProcessLoopCalls from adding MQTT_GetPingreqPacketSize

* Update comments

* Address PR comments

* Change parameter names in expectProcessLoopCalls

* Update comments

* Set remaining length when modifying packet type

* Change case of method names

* Address PR comments

* Address PR comments

* Add timer overflow test

* Address PR comments

* Add param docs

* Rename macro to context instead of interface

* Remove modifyIncomingPacket

* Add divider
2020-05-28 13:38:13 -07:00
Muneeb Ahmed
62a48b88c3 Add MQTT connect and publish unit tests (#964)
* Add unit tests for MQTT_Connect, MQTT_Publish, MQTT_Disconnect, MQTT_GetPacketId

* Update MQTT_GetPacketId for NULL checks

* Update MQTT_Connect for parameter checks
2020-05-28 12:16:32 -07:00
Muneeb Ahmed
eb0b272c8d Import lightweight unit tests (#957)
* Import existing lightweight unit tests

* Add overflow checking for serialized buffers
2020-05-28 11:08:27 -07:00
Oscar Michael Abrina
8901bbccdc Add MQTT_SerializeDisconnect unit tests using Unity (#949)
* Achieve full coverage on MQTT_SerializeDisconnect

* Add docs

* Remove accidental update of mqtt_utest.c

* Add setupNetworkBuffer

* Add checks for serialized buffer

* Remove redefinition of setupNetworkBuffer

* Remove accidental update of mqtt_utest.c

* Update case for consistency

* Remove warnings in mqtt_state_utest.c
2020-05-22 10:16:08 -07:00
Oscar Michael Abrina
fe43992552 Add MQTT_SerializeConnect unit tests using Unity (#942)
* Add mqtt_lightweight_utest.c

* Achieve 100% coverage on MQTT_SerializeConnect

* Remove accidental changes

* Move comment

* Change TEST_ASSERT to correct order (expected, actual)

* Add checks for serialized network packet

* Update docs

* Remove warning about suiteTearDown

* Add docs for private methods

* Address PR comments

* Explicitly declare combinations of willInfo and connectInfo being used for the test

* Rename to pDestination

* Remove tools/cmake/filePaths.cmake

* Merge mqtt/utest/CMakeLists.txt

* Add assert for pSource
2020-05-22 02:46:45 -07:00
Muneeb Ahmed
ee4326f148 Add MQTT state engine unit tests (#951)
* Add MQTT state engine unit tests

* Update parameter validations in library state engine
2020-05-21 16:27:58 -07:00
Muneeb Ahmed
bfb3dd0e3a Fix some build warnings (#959)
* Update mqtt demo makefiles
2020-05-20 16:30:17 -07:00
Archit Aggarwal
22c9b0ad99 Logging/update to new infrastructure (#945) 2020-05-20 14:12:01 -07:00
abhidixi11
20460f4993 fix: MQTT library issues found during demo development. (#950)
* fix: MQTT library issues found during demo development.

 1. Make serialize ping request behavior same as disconnect.
 2. Remove unnecessary function call from serialize disconnect.
 3. Fix serialize unsubscribe.
2020-05-20 12:33:03 -07:00
leegeth
589f57afde Fix issues in MQTT library. (#955)
Below are the issues fixed in this commit
1. Remove the incorrect and duplicate pointer initialization in
sendPacket function.
2. Remove NULL check for the packet Id pointer passed to MQTT_DeserializeAck
when packet type is either CONNACK or PINGRESP.
2020-05-19 18:36:23 -07:00
Oscar Michael Abrina
930a7e6f32 Add MQTT_Init unit tests using Unity Framework (#941)
* Coverage for MQTT_Init

* Remove mock for mqtt_lightweight

* Change to expected, actual order for TEST_ASSERT

* Provide updated comments for unity fixtures

* Add validation for context.nextPacketId

* Add tests for null parameters

* Add missing sc;

* Remove warning for suiteTearDown

* Do not return numFailures

* Return correct error code

* return numFailures

* Add docs
2020-05-18 14:34:29 -07:00
leegeth
fd3c47151f Add parameter validation to MQTT_Init (#943) 2020-05-18 10:46:25 -07:00
leegeth
fdf66212ef Fix build warning for incorrect type (#940) 2020-05-14 18:18:08 -07:00
Muneeb Ahmed
782f4370f6 Implement MQTTProcessLoop (#901)
* Add implementation of receive loop

* Add keep alive to process loop

* Add timer to packet reception

* Add packet identifier to app callback

* Add publish info to app callback
2020-05-14 16:31:40 -07:00
leegeth
856f573677 MQTT CONNACK receive in MQTT_Connect (#934) 2020-05-14 14:16:54 -07:00
Archit Aggarwal
92e5f74419 Fix issues with CMake setup for http and mqtt (#938) 2020-05-14 12:14:42 -07:00
Archit Aggarwal
0f6d6aa153 Update logConnackResponse function to log CONNACK error response with… (#937)
Update logConnackResponse function to log CONNACK error response without dependency on LOG_NONE
2020-05-13 15:45:32 -07:00
Archit Aggarwal
c2899bcec1 Rename Log() -> SdkLog() to avoid naming collision (#933)
* Rename Log() -> SdkLog() to avoid naming collision

* Remove IOT_ prefix from log level macros

* Remove AWS_IOT from USE_AWS_IOT_CSD_LOGGING config
2020-05-13 13:36:43 -07:00
leegeth
0f73cbac3f Update publish with state machine updates (#935) 2020-05-13 13:29:06 -07:00
leegeth
70c5e7ff6b MISRA fixes (#927) 2020-05-13 12:04:25 -07:00
Archit Aggarwal
b5de1de1cc Remove Iot_ prefix from logging and clock (#932)
* Remove Iot_ prefix from logging and clock

* Remove Iot prefix from new log call-sites in http introduced from rebasing with development
2020-05-12 17:13:39 -07:00
Oscar Michael Abrina
13373d715a Add CMake build for demos and unit tests (#926)
* Add CMakeLists from v4 beta

* More cmake changes

* Successfully compile mqtt_demo_plaintext executable

* Add filePaths.cmake for mqtt demos

* Compile demos using cmake

* Add unity and cmock as submodules

* Add 3rdparty CMakeLists.txt

* Add example utest for http with cmake file

* Add tests directory for defining unit test

* Do not add dependency if mock_name is empty

* Make basic test finally work

* Remove tests/CMakeLists.txt

* Add separate folder for tests in bin

* Fix format

* Get logging to work

* Remove include_dir from create_test.cmake

* Remove duplicate unity 3rdparty library

* Add mock for mqtt tests

* Add README for unit testing

* Update README

* Compile all tests for coverage target

* Remove accidental Makefile

* Remove unity submodule

* Add more docs

* Update README

* Change CMAKE_C_STANDARD

* Update docs

* Indent correctly

* Add missing defines to config.h

* Link cmock to test target

* Remove double include of <stddef.h>

* Add comment for tools/cmock dir

* Address PR comments

* Move allutest README.md to a single docs folder in root

* Add steps to build the demos

* Update README.md with correct build steps

* Address PR comments

* Remove filePaths.cmake for demos

* Remove BUILD_CLONE_SUBMODULES

* Address PR comments

* Add BUILD_CLONE_SUBMODULES option

* Rename filepaths.cmake to filePaths.cmake

* Remove platform/include from filePaths.cmake
2020-05-12 14:26:57 -07:00
leegeth
107be67794 Add missing logs and argument validations. (#925) 2020-05-08 10:39:51 -07:00
leegeth
40dd8a3b11 Implement MQTT Ping request. (#917)
* Implement MQTT Ping request.

The public APIs implemented are
1. MQTT_Ping
2. MQTT_SerializePingreq
2020-05-08 08:21:25 -07:00
leegeth
ec78af468e Implement MQTT SUBSCRIBE and UNSUBSCRIBE (#916)
* Implement MQTT SUBSCRIBE and UNSUBSCRIBE

Please find the list of public API functions implemented
1. MQTT_Subscribe
2. MQTT_Unsubscribe
3. MQTT_GetSubscribePacketSize
4. MQTT_SerializeSubscribe
5. MQTT_GetUnsubscribePacketSize
6. MQTT_SerializeUnsubscribe
2020-05-08 08:15:22 -07:00
leegeth
495a79e59d Implement MQTT Publish (#905)
* Implement MQTT Publish

The list of functions implemented are
1. MQTT_Publish
2. MQTT_GetPublishPacketSize
3. MQTT_SerializePublish
4. MQTT_SerializePublishHeader
2020-05-07 10:16:37 -07:00
Muneeb Ahmed
c8766b0411 Add state engine (#874)
* Add state engine

* Remove packet ID collision check

According to 2.3.1 of the MQTT spec, since
client and server assign packet identifiers
independently, it's possible for concurrent
exchanges to use the same packet identifiers.

* Refactor state engine for simplicity

* Rename invalid state to null state

* Add state select

* Define bool for C89

* Add asserts to static functions

* Remove leading underscore from functions
2020-05-07 09:25:42 -07:00
Muneeb Ahmed
9e97b2473e Implement publish deserializers (#911)
* Add deserializers for publish and acks

* Add ACK serializer
2020-05-05 21:22:39 -07:00
leegeth
1681a075d2 Add logging macros for MQTT (#919)
* Add logging macros for MQTT

* Add a new line character at the end of the file
2020-05-04 11:08:07 -07:00
Gordon Wang
33cc3f3723 Add basic MQTT TLS demo (#903) 2020-04-30 12:19:36 -07:00
Gordon Wang
002bce85d8 Document MQTT lightweight and API functions (#902) 2020-04-29 14:36:05 -07:00