chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
# Changelog for coreMQTT Agent Library
## v1.3.1 (August 2024)
### Changes
- [#117](https://github.com/FreeRTOS/coreMQTT-Agent/pull/117) Update the incorrect version number.
## v1.3.0 (August 2024)
### Changes
- [#114](https://github.com/FreeRTOS/coreMQTT-Agent/pull/114) Update CMock submodule pointer to latest version v2.5.3.
- [#111](https://github.com/FreeRTOS/coreMQTT-Agent/pull/111) Update coreMQTT-Agent to work with the coreMQTT v2.3.1.
- [#110](https://github.com/FreeRTOS/coreMQTT-Agent/pull/110) Fix MISRA violation.
- [#109](https://github.com/FreeRTOS/coreMQTT-Agent/pull/109) Update CMakeList optionally build UT/Coverity & Update Coverity configuration.
- [#108](https://github.com/FreeRTOS/coreMQTT-Agent/pull/108) Use CBMC version 5.95.1.
- [#107](https://github.com/FreeRTOS/coreMQTT-Agent/pull/107) Add documentation about configuration options.
- [#105](https://github.com/FreeRTOS/coreMQTT-Agent/pull/105) Update this repository to use new CI-CD Actions.
- [#103](https://github.com/FreeRTOS/coreMQTT-Agent/pull/103) Update Agent to treat MQTTNeedMoreBytes correctly.
- [#84](https://github.com/FreeRTOS/coreMQTT-Agent/pull/84) Create pull_request_template.md.
- [#83](https://github.com/FreeRTOS/coreMQTT-Agent/pull/83) Add CBMC proof-running GitHub Action.
- [#81](https://github.com/FreeRTOS/coreMQTT-Agent/pull/81) Fix unsigned comparison IAR compiler warnings.
## v1.2.0 (October 2022)
### Changes
- [#77](https://github.com/FreeRTOS/coreMQTT-Agent/pull/77) Update coreMQTT-Agent to work with the coreMQTT v2.1.0. No breaking changes from the previous version.
- [#75](https://github.com/FreeRTOS/coreMQTT-Agent/pull/75) Update coreMQTT-Agent to work with the coreMQTT v2.0.0.
## v1.1.0 (November 2021)
### Changes
- [#59](https://github.com/FreeRTOS/coreMQTT-Agent/pull/59) Update doxygen version used for documentation to 1.9.2.
## v1.0.1 (July 2021)
### Changes
- [#56](https://github.com/FreeRTOS/coreMQTT-Agent/pull/56) Add header guards for C++ linkage and update coreMQTT submodule.
## v1.0.0 (April 2021)
This is the first release of the coreMQTT Agent library in this repository.

View File

@@ -0,0 +1,13 @@
if(DEFINED CONFIG_SDK_MODULE_COREMQTT_AGENT)
listenai_library_named(coreMQTT-Agent)
listenai_library_sources(
source/core_mqtt_agent_command_functions.c
source/core_mqtt_agent.c)
listenai_include_directories(
source/include
)
endif()

View File

@@ -0,0 +1,4 @@
## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
opensource-codeofconduct@amazon.com with any additional questions or comments.

View File

@@ -0,0 +1,8 @@
menu "coreMQTT-Agent"
config SDK_MODULE_COREMQTT_AGENT
bool "enable sdk module core mqtt agent"
default n
depends on SDK_MODULE_COREMQTT
endmenu

View File

@@ -0,0 +1,19 @@
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,39 @@
# MISRA Compliance
The coreMQTT Agent library files conform to the [MISRA C:2012](https://www.misra.org.uk)
guidelines, with some noted exceptions. Compliance is checked with Coverity static analysis.
Deviations from the MISRA standard are listed below:
### Ignored by [Coverity Configuration](tools/coverity/misra.config)
| Deviation | Category | Justification |
| :-: | :-: | :-: |
| Directive 4.5 | Advisory | Allow names that MISRA considers ambiguous (such as LogInfo and LogError) |
| Directive 4.8 | Advisory | Allow inclusion of unused types. Header files from coreMQTT may define types that are not used by the agent. |
| Directive 4.9 | Advisory | Allow inclusion of function like macros. The `assert` macro is used throughout the library for parameter validation, and logging is done using function like macros. |
| Rule 2.3 | Advisory | Allow unused types. Both the agent and coreMQTT headers define types that are not directly used by the library but are still intended to be used by the application. |
| Rule 2.4 | Advisory | Allow unused tags. Some compilers warn if types are not tagged. |
| Rule 2.5 | Advisory | Allow unused macros. Library headers may define macros intended for the application's use, but are not used by a specific file. |
| Rule 3.1 | Required | Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks. |
| Rule 11.5 | Advisory | Allow casts from `void *`. Fields such as command parameters are passed as `void *` for generalization and must be cast to the correct data type before use. |
### Flagged by Coverity
| Deviation | Category | Justification |
| :-: | :-: | :-: |
| Rule 8.7 | Advisory | API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application. |
| Rule 8.13 | Advisory | Functions that are passed as pointers to coreMQTT or the agent must exactly match function signatures with the pointer type definition, so `const` modifiers cannot be added even if a specific function implementation does not modify a given parameter. |
### Suppressed with Coverity Comments
To find the deviation references in the source files run grep on the source code
with ( Assuming rule 11.3 violation; with justification in point 1 ):
```
grep 'MISRA Ref 11.3.1' . -rI
```
#### Rule 11.3
_Ref 11.3.1_
- MISRA C-2012 Rule 11.3 states that a cast shall not be performed between a pointer to
to object type and a pointer to a different object type. In this library, the MQTT stack
processes data as byte stream, requiring casting to specific data structure. However this
casting is safe because the buffers are aligned to a 4-byte boundaries, ensuring that no
unaligned memory access occurs.

View File

@@ -0,0 +1,154 @@
## coreMQTT Agent Library
The coreMQTT Agent library is a high level API that adds thread safety to the [coreMQTT](https://github.com/FreeRTOS/coreMQTT) library. The library provides thread safe equivalents to the coreMQTT's APIs, greatly simplifying its use in multi-threaded environments. The coreMQTT Agent library manages the MQTT connection by serializing the access to the coreMQTT library and reducing implementation overhead (e.g., removing the need for the application to repeatedly call to `MQTT_ProcessLoop`). This allows your multi-threaded applications to share the same MQTT connection, and enables you to design an embedded application without having to worry about coreMQTT thread safety.
This library has gone through code quality checks including verification that no function has a [GNU Complexity](https://www.gnu.org/software/complexity/manual/complexity.html) score over 8, and checks against deviations from mandatory rules in the [MISRA coding standard](https://www.misra.org.uk). Deviations from the MISRA C:2012 guidelines are documented under [MISRA Deviations](MISRA.md). This library has also undergone both static code analysis from [Coverity static analysis](https://scan.coverity.com/), and validation of memory safety through the [CBMC automated reasoning tool](https://www.cprover.org/cbmc/).
See memory requirements for this library [here](./docs/doxygen/include/size_table.md).
## Cloning this repository
This repo uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to bring in dependent components.
To clone using HTTPS:
```
git clone https://github.com/FreeRTOS/coreMQTT-Agent.git --recurse-submodules
```
Using SSH:
```
git clone git@github.com:FreeRTOS/coreMQTT-Agent.git --recurse-submodules
```
If you have downloaded the repo without using the `--recurse-submodules` argument, you need to run:
```
git submodule update --init --recursive
```
## coreMQTT Agent Library Configurations
The MQTT Agent library uses the same `core_mqtt_config.h` configuration file as coreMQTT, with the addition of configuration constants listed at the top of [core_mqtt_agent.h](source/include/core_mqtt_agent.h) and [core_mqtt_agent_command_functions.h](source/include/core_mqtt_agent_command_functions.h). Documentation for these configurations can be found [here](https://freertos.github.io/coreMQTT-Agent/main/core_mqtt_agent_config.html).
To provide values for these configuration values, they must be either:
* Defined in `core_mqtt_config.h` used by coreMQTT
**OR**
* Passed as compile time preprocessor macros
### Configuration values to modify timing performance
#### Agent queue block time:
Some TCP stacks provide a select functionality which allows any given observer to be notified of any incoming packet on the socket. This allows us to make the MQTT-Agent event driven by calling `MQTTAgent_ProcessLoop` when the observer is notified of any incoming packets on the socket. FreeRTOS+TCP can also use socket callbacks to notify the socket owner of incoming data on the socket.
If your TCP stack does not provide this functionality, the agent will block on its event queue for a maximum of `MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME` milliseconds after which it calls `MQTTAgent_ProcessLoop`. This leads to delay between when the packet actually arrives and when it actually gets processed. Thus, if you want to make the MQTT Agent more responsive, you can make the `MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME` value smaller. This would cause the agent to check the socket more often thereby reducing the time between when an incoming packet is received and when it is processed.
NOTE: While making the above change it is very important to understand that reducing the `MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME` value would cause the agent process loop to run more often which might have an impact on the runtime of other tasks.
#### Socket read/recv timeout:
Most TCP stacks allow applications to block on a socket read (also called recv()) call when there is no data to be read. If you are using the MQTT Agent, then the socket read timeout must be set to 0 – that is, the socket must be non-blocking.
When the socket is set to blocking - every read operation of the socket blocks the Agent for the duration of the timeout. This stops the agent from processing other incoming requests such as processing a message which the application wants to publish.
This is emphasized in cases where QoS0 publishes are involved because in this case there is no incoming packet (e.g. PUB-ACK) to unblock the agent from the socket read operation. Thus, when the application decides to publish a message, that message has to wait in the agent queue as the agent is blocked. This leads to very slow turn-around time.
#### Agent task priority:
MQTT Agent is designed to work best when its priority is set to be higher than all the tasks using it. This allows the agent to quickly process all the requests from the application as well as incoming data from the MQTT message broker.
If the agent is of lower priority than the tasks using it then the user-task can continuously put requests in the agent queue without giving agent a chance to process those requests. This process would go on till the agent queue is fully filled and the producer task blocks. Only then the Agent task might get a chance to process a message from the queue.
## Porting the coreMQTT Agent Library
In order to use the MQTT Agent library on a platform, you need to supply thread safe functions for the agent's [messaging interface](source/include/core_mqtt_agent_message_interface.h).
### Messaging Interface
Each of the following functions must be thread safe.
| Function Pointer | Description |
| :-: | --- |
| `MQTTAgentMessageSend_t` | A function that sends commands (as `MQTTAgentCommand_t *` pointers) to be received by `MQTTAgent_CommandLoop`. This can be implemented by pushing to a thread safe queue. |
| `MQTTAgentMessageRecv_t` | A function used by `MQTTAgent_CommandLoop` to receive `MQTTAgentCommand_t *` pointers that were sent by API functions. This can be implemented by receiving from a thread safe queue. |
| `MQTTAgentCommandGet_t` | A function that returns a pointer to an allocated `MQTTAgentCommand_t` structure, which is used to hold information and arguments for a command to be executed in `MQTTAgent_CommandLoop()`. If using dynamic memory, this can be implemented using `malloc()`. |
| `MQTTAgentCommandRelease_t` | A function called to indicate that a command structure that had been allocated with the `MQTTAgentCommandGet_t` function pointer will no longer be used by the agent, so it may be freed or marked as not in use. If using dynamic memory, this can be implemented with `free()`. |
Reference implementations for the interface functions can be found in the [reference examples](#reference-examples) below.
### Additional Considerations
#### Static Memory
If only static allocation is used, then the `MQTTAgentCommandGet_t` and `MQTTAgentCommandRelease_t` could instead be implemented with a pool of `MQTTAgentCommand_t` structures, with a queue or semaphore used to control access and provide thread safety. The below [reference examples](#reference-examples) use static memory with a command pool.
#### Subscription Management
The MQTT Agent does not track subscriptions for MQTT topics. The receipt of any incoming PUBLISH packet will result in the invocation of a single `MQTTAgentIncomingPublishCallback_t` callback, which is passed to `MQTTAgent_Init()` for initialization. If it is desired for different handlers to be invoked for different incoming topics, then the publish callback will have to manage subscriptions and fan out messages. A platform independent subscription manager example is implemented in the [reference examples](#reference-examples) below.
## Building the Library
You can build the MQTT Agent source files that are in the [source](source/) directory, and add [source/include](source/include) to your compiler's include path. Additionally, the MQTT Agent library requires the coreMQTT library, whose files follow the same `source/` and `source/include` pattern as the agent library; its build instructions can be found [here](https://github.com/FreeRTOS/coreMQTT#building-the-library).
If using CMake, the [mqttAgentFilePaths.cmake](mqttAgentFilePaths.cmake) file contains the above information of the source files and the header include path from this repository. The same information is found for coreMQTT from `mqttFilePaths.cmake` in the [coreMQTT submodule](source/dependency/).
For a CMake example of building the MQTT Agent library with the `mqttAgentFilePaths.cmake` file, refer to the `coverity_analysis` library target in [test/CMakeLists.txt](test/CMakeLists.txt) file.
## Building Unit Tests
### Checkout CMock Submodule
To build unit tests, the submodule dependency of CMock is required. Use the following command to clone the submodule:
```
git submodule update --checkout --init --recursive test/unit-test/CMock
```
### Unit Test Platform Prerequisites
- For running unit tests
- **C90 compiler** like gcc
- **CMake 3.13.0 or later**
- **Ruby 2.0.0 or later** is additionally required for the CMock test framework (that we use).
- For running the coverage target, **gcov** and **lcov** are additionally required.
### Steps to build **Unit Tests**
1. Go to the root directory of this repository. (Make sure that the **CMock** submodule is cloned as described [above](#checkout-cmock-submodule))
1. Run the *cmake* command: `cmake -S test -B build`
1. Run this command to build the library and unit tests: `make -C build all`
1. The generated test executables will be present in `build/bin/tests` folder.
1. Run `cd build && ctest` to execute all tests and view the test run summary.
## CBMC
To learn more about CBMC and proofs specifically, review the training material [here](https://model-checking.github.io/cbmc-training).
The `test/cbmc/proofs` directory contains CBMC proofs.
In order to run these proofs you will need to install CBMC and other tools by following the instructions [here](https://model-checking.github.io/cbmc-training/installation.html).
## Reference examples
Please refer to the demos of the MQTT Agent library in the following locations for reference examples on FreeRTOS platforms:
| Location |
| :-: |
| [coreMQTT Agent Demos](https://github.com/FreeRTOS/coreMQTT-Agent-Demos) |
| [FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask) |
## Documentation
The MQTT Agent API documentation can be found [here](https://freertos.github.io/coreMQTT-Agent/main/index.html).
### Generating documentation
The Doxygen references were created using Doxygen version 1.9.2. To generate the
Doxygen pages yourself, please run the following command from the root of this repository:
```shell
doxygen docs/doxygen/config.doxyfile
```
## Getting help
You can use your Github login to get support from both the FreeRTOS community and directly from the primary FreeRTOS developers on our [active support forum](https://forums.freertos.org). You can find a list of [frequently asked questions](https://www.freertos.org/Why-FreeRTOS/FAQs) here.
## Contributing
See [CONTRIBUTING.md](./.github/CONTRIBUTING.md) for information on contributing.
## License
This library is licensed under the MIT License. See the [LICENSE](LICENSE) file.

View File

@@ -0,0 +1,22 @@
---
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: '0.2'
# Allows things like stringLength
allowCompoundWords: true
useGitignore: true
# Could split this up? And do a dictionary for each repo?
# But feel like if this isn't super slow
# That having just one single dictionary might be nicer?
dictionaryDefinitions:
- name: freertos-words
path: '.github/.cSpellWords.txt'
addWords: true
dictionaries:
- freertos-words
ignorePaths:
- 'node_modules'
- '.cSpellWords.txt'
- 'dependency'
- 'docs'
- 'ThirdParty'

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
<table>
<tr>
<td colspan="3"><center><b>Code Size of coreMQTT Agent (example generated with GCC for ARM Cortex-M)</b></center></td>
</tr>
<tr>
<td><b>File</b></td>
<td><b><center>With -O1 Optimization</center></b></td>
<td><b><center>With -Os Optimization</center></b></td>
</tr>
<tr>
<td>core_mqtt_agent.c</td>
<td><center>1.7K</center></td>
<td><center>1.5K</center></td>
</tr>
<tr>
<td>core_mqtt_agent_command_functions.c</td>
<td><center>0.3K</center></td>
<td><center>0.2K</center></td>
</tr>
<tr>
<td>core_mqtt.c (coreMQTT)</td>
<td><center>4.1K</center></td>
<td><center>3.5K</center></td>
</tr>
<tr>
<td>core_mqtt_state.c (coreMQTT)</td>
<td><center>1.7K</center></td>
<td><center>1.3K</center></td>
</tr>
<tr>
<td>core_mqtt_serializer.c (coreMQTT)</td>
<td><center>2.8K</center></td>
<td><center>2.2K</center></td>
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>10.6K</center></b></td>
<td><b><center>8.7K</center></b></td>
</tr>
</table>

View File

@@ -0,0 +1,228 @@
<doxygenlayout version="1.0">
<!-- Generated by doxygen 1.8.20 -->
<!-- Navigation index tabs for HTML output -->
<navindex>
<tab type="mainpage" visible="yes" title=""/>
<tab type="pages" visible="yes" title="" intro=""/>
<!-- Hide the default "Data Structures" tab and use the "Modules" tab for data
structures. This allows internal data structures to be hidden. -->
<tab type="modules" visible="yes" title="Data types and Constants" intro="This library defines the following data types and constants."/>
<tab type="namespaces" visible="yes" title="">
<tab type="namespacelist" visible="yes" title="" intro=""/>
<tab type="namespacemembers" visible="yes" title="" intro=""/>
</tab>
<tab type="interfaces" visible="no" title="">
<tab type="interfacelist" visible="no" title="" intro=""/>
<tab type="interfaceindex" visible="no" title=""/>
<tab type="interfacehierarchy" visible="yes" title="" intro=""/>
</tab>
<tab type="classes" visible="no" title="">
<tab type="classlist" visible="no" title="" intro=""/>
<tab type="classindex" visible="no" title=""/>
<tab type="hierarchy" visible="no" title="" intro=""/>
<tab type="classmembers" visible="no" title="" intro=""/>
</tab>
<tab type="structs" visible="no" title="">
<tab type="structlist" visible="no" title="" intro=""/>
<tab type="structindex" visible="no" title=""/>
</tab>
<tab type="exceptions" visible="no" title="">
<tab type="exceptionlist" visible="no" title="" intro=""/>
<tab type="exceptionindex" visible="no" title=""/>
<tab type="exceptionhierarchy" visible="yes" title="" intro=""/>
</tab>
<tab type="files" visible="no" title="">
<tab type="filelist" visible="yes" title="Files" intro="The following files are associated with this library."/>
<tab type="globals" visible="no" title="" intro=""/>
</tab>
<tab type="examples" visible="yes" title="" intro=""/>
</navindex>
<!-- Layout definition for a class page -->
<class>
<briefdescription visible="yes"/>
<includes visible="$SHOW_INCLUDE_FILES"/>
<inheritancegraph visible="$CLASS_GRAPH"/>
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
<memberdecl>
<nestedclasses visible="yes" title=""/>
<publictypes title=""/>
<services title=""/>
<interfaces title=""/>
<publicslots title=""/>
<signals title=""/>
<publicmethods title=""/>
<publicstaticmethods title=""/>
<publicattributes title=""/>
<publicstaticattributes title=""/>
<protectedtypes title=""/>
<protectedslots title=""/>
<protectedmethods title=""/>
<protectedstaticmethods title=""/>
<protectedattributes title=""/>
<protectedstaticattributes title=""/>
<packagetypes title=""/>
<packagemethods title=""/>
<packagestaticmethods title=""/>
<packageattributes title=""/>
<packagestaticattributes title=""/>
<properties title=""/>
<events title=""/>
<privatetypes title=""/>
<privateslots title=""/>
<privatemethods title=""/>
<privatestaticmethods title=""/>
<privateattributes title=""/>
<privatestaticattributes title=""/>
<friends title=""/>
<related title="" subtitle=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<inlineclasses title=""/>
<typedefs title=""/>
<enums title=""/>
<services title=""/>
<interfaces title=""/>
<constructors title=""/>
<functions title=""/>
<related title=""/>
<variables title=""/>
<properties title=""/>
<events title=""/>
</memberdef>
<allmemberslink visible="yes"/>
<usedfiles visible="$SHOW_USED_FILES"/>
<authorsection visible="yes"/>
</class>
<!-- Layout definition for a namespace page -->
<namespace>
<briefdescription visible="yes"/>
<memberdecl>
<nestednamespaces visible="yes" title=""/>
<constantgroups visible="yes" title=""/>
<interfaces visible="yes" title=""/>
<classes visible="yes" title=""/>
<structs visible="yes" title=""/>
<exceptions visible="yes" title=""/>
<typedefs title=""/>
<sequences title=""/>
<dictionaries title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<inlineclasses title=""/>
<typedefs title=""/>
<sequences title=""/>
<dictionaries title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
</memberdef>
<authorsection visible="yes"/>
</namespace>
<!-- Layout definition for a file page -->
<file>
<briefdescription visible="yes"/>
<includes visible="$SHOW_INCLUDE_FILES"/>
<includegraph visible="$INCLUDE_GRAPH"/>
<includedbygraph visible="$INCLUDED_BY_GRAPH"/>
<sourcelink visible="yes"/>
<memberdecl>
<interfaces visible="yes" title=""/>
<classes visible="yes" title=""/>
<structs visible="yes" title=""/>
<exceptions visible="yes" title=""/>
<namespaces visible="yes" title=""/>
<constantgroups visible="yes" title=""/>
<defines title=""/>
<typedefs title=""/>
<sequences title=""/>
<dictionaries title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<inlineclasses title=""/>
<defines title=""/>
<typedefs title=""/>
<sequences title=""/>
<dictionaries title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
</memberdef>
<authorsection/>
</file>
<!-- Layout definition for a group page -->
<group>
<briefdescription visible="yes"/>
<groupgraph visible="$GROUP_GRAPHS"/>
<memberdecl>
<nestedgroups visible="yes" title=""/>
<dirs visible="yes" title=""/>
<files visible="yes" title=""/>
<namespaces visible="yes" title=""/>
<classes visible="yes" title=""/>
<defines title=""/>
<typedefs title=""/>
<sequences title=""/>
<dictionaries title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
<membergroups visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
<memberdef>
<pagedocs/>
<inlineclasses title=""/>
<defines title=""/>
<typedefs title=""/>
<sequences title=""/>
<dictionaries title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
</memberdef>
<authorsection visible="yes"/>
</group>
<!-- Layout definition for a directory page -->
<directory>
<briefdescription visible="yes"/>
<directorygraph visible="yes"/>
<memberdecl>
<dirs visible="yes"/>
<files visible="yes"/>
</memberdecl>
<detaileddescription title=""/>
</directory>
</doxygenlayout>

View File

@@ -0,0 +1,318 @@
/**
@mainpage Overview
@anchor mqtt_agent
@brief Thread safe MQTT 3.1.1 client
The coreMQTT Agent is a thread-safe library to serialize calls to coreMQTT, to be executed by a single thread. It provides APIs for a single, dedicated agent task to process coreMQTT related commands, and the APIs for other tasks to enqueue these commands for processing.
@section coreMQTT_brief Why is there a higher level library based on coreMQTT?
[coreMQTT](@ref mqtt) is an MIT licensed open source C MQTT client library for microcontroller and small microprocessor based IoT devices. Its design is intentionally simple to ensure it has no dependency on any other library or operating system, and to better enable static analysis including memory safety proofs. That simplicity and lack of operating system dependency (coreMQTT does not require multithreading at all) means coreMQTT does not build thread safety directly into its implementation. Instead, thread safety must be provided by higher level software. The coreMQTT Agent library is a coreMQTT extension that provides that higher level functionality in the form of an MQTT agent (or MQTT daemon).
@section core_mqtt_agent_memory_requirements Memory Requirements
@brief Memory requirements of the MQTT Agent library, including the coreMQTT library.
@include{doc} size_table.md
*/
/**
@page mqtt_agent_design Design
@brief Architecture of the MQTT Agent library.
@section mqtt_agent_task_thread_safety Thread Safe and Unsafe APIs
The MQTT Agent APIs are designed to be used by two types of tasks:
- An MQTT agent task that manages an MQTT connection and calls coreMQTT APIs. The APIs used by this task are not thread safe, and each agent task should use a unique @ref MQTTAgentContext_t (multiple agent tasks may be used to handle multiple simultaneous MQTT connections, but each must have a unique context). This task is expected to invoke @ref MQTTAgent_CommandLoop to process commands from other tasks to call coreMQTT APIs. The APIs for this task are:
- @ref MQTTAgent_Init
- @ref MQTTAgent_CommandLoop
- @ref MQTTAgent_ResumeSession
- @ref MQTTAgent_CancelAll
- Application tasks that want to perform MQTT operations with thread safety. These tasks are any task that is <i>not</i> an MQTT agent task. The APIs used by application tasks are thread safe, and send commands that are processed by an MQTT agent task in @ref MQTTAgent_CommandLoop. These APIs can accept several structures used by either the command or completion callback, and these structures MUST remain in scope until the associated command has been completed, including @ref MQTTPublishInfo_t, @ref MQTTAgentSubscribeArgs_t, @ref MQTTAgentConnectArgs_t, and @ref MQTTAgentCommandContext_t. The APIs are asynchronous, so will return as soon as the command has been sent; they will <i>not</i> wait for the command to be processed. These APIs are:
- @ref MQTTAgent_Publish
- @ref MQTTAgent_Subscribe
- @ref MQTTAgent_Unsubscribe
- @ref MQTTAgent_Ping
- @ref MQTTAgent_Connect
- @ref MQTTAgent_Disconnect
- @ref MQTTAgent_Terminate
@section mqtt_agent_interfaces Interfaces and Callbacks
Similar to coreMQTT, the MQTT Agent library relies on interfaces to dissociate itself from platform specific functionality. Interfaces used by the MQTT Agent library are simply function pointers with expectations of behavior.
The MQTT Agent library expects the application to provide implementations for the following interfaces:
<table>
<tr>
<td><b>Function Pointer</b></td>
<td><b>Use</b></td>
</tr>
<tr>
<td>@ref MQTTAgentMessageRecv_t</td>
<td>Receiving commands sent to the agent task.</td>
</tr>
<tr>
<td>@ref MQTTAgentMessageSend_t</td>
<td>Sending commands to the agent task from the application</td>
</tr>
<tr>
<td>@ref MQTTAgentCommandGet_t</td>
<td>Allocating storage for a command to be sent to the agent task.</td>
</tr>
<tr>
<td>@ref MQTTAgentCommandRelease_t</td>
<td>Releasing a command obtained from @ref MQTTAgentCommandGet_t.</td>
</tr>
<tr>
<td>@ref MQTTAgentIncomingPublishCallback_t</td>
<td>Accepting incoming publish messages, with the possibility of further distributing them to other tasks.</td>
</tr>
</table>
@section mqtt_agent_command_completion Command Completion
Commands do not have any timeout associated with them. The only way for a task to be aware of a command's completion is through the invocation of an optional @ref MQTTAgentCommandCallback_t completion callback.
The completion callback will be invoked with an optional @ref MQTTAgentCommandContext_t, which is the incomplete type <b>struct MQTTAgentCommandContext</b>. This type must be defined by the application, and should contain information that would be useful in distinguishing commands.<br>
<b>Example code:</b>
@code{c}
struct MQTTAgentCommandContext
{
//Allow the calling thread to view the return code by copying it here.
MQTTStatus_t returnCode;
//pthread mutex and condition variables to signal to the thread that created the command.
pthread_mutex_t lock;
pthread_cond_t cond;
};
@endcode
<br>
The completion callback using such a context could be:
@code{c}
void commandCompleteCallback( MQTTAgentCommandContext_t * pCmdContext, MQTTAgentReturnInfo_t * pReturnInfo )
{
pthread_mutex_lock( &( pCmdContext->lock ) );
//Set return code so the thread that created the command can view.
pCmdContext->returnCode = pReturnInfo->returnCode;
pthread_mutex_unlock( &( pCmdContext->lock ) );
//Signal the thread using the condition variable.
pthread_cond_broadcast( &( pCmdContext->cond ) );
}
@endcode
<br>
The completion callback and completion context are each optional, and passed at time of command creation in the @ref MQTTAgentCommandInfo_t parameter. If a command completion context is passed, it MUST remain in scope until the completion callback has been invoked.
*/
/**
@page core_mqtt_agent_config Configurations
@brief Configurations of the MQTT Agent.
<!-- @par configpagestyle allows the @section titles to be styled according to style.css -->
@par configpagestyle
Configuration settings are C preprocessor constants. They can be set with a `#define` in the config file (**core_mqtt_config.h**) or by using a compiler option such as -D in gcc. The MQTT Agent uses the same configuration file as [coreMQTT](@ref mqtt).
@section MQTT_AGENT_MAX_OUTSTANDING_ACKS
@copydoc MQTT_AGENT_MAX_OUTSTANDING_ACKS
@section MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME
@copydoc MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME
@section MQTT_AGENT_FUNCTION_TABLE
@copydoc MQTT_AGENT_FUNCTION_TABLE
*/
/**
@page mqtt_agent_functions Functions
@brief Functions of the MQTT Agent library<br><br>
@section mqtt_agent_thread_unsafe_functions Thread Unsafe Functions
These functions are not thread safe and are designed to be used only by an MQTT agent task -
a task dedicated to interfacing with the [coreMQTT](@ref mqtt) API.<br><br>
@subpage mqtt_agent_init_function <br>
@subpage mqtt_agent_command_function <br>
@subpage mqtt_agent_resume_function <br>
@subpage mqtt_agent_cancel_function <br><br>
@section mqtt_agent_thread_safe_functions Thread Safe Functions
These functions are thread safe and designed to be used by any application task (one that is *not* the MQTT agent task).<br><br>
@subpage mqtt_agent_publish_function <br>
@subpage mqtt_agent_subscribe_function <br>
@subpage mqtt_agent_unsubscribe_function <br>
@subpage mqtt_agent_connect_function <br>
@subpage mqtt_agent_disconnect_function <br>
@subpage mqtt_agent_ping_function <br>
@subpage mqtt_agent_terminate_function <br><br>
@page mqtt_agent_init_function MQTTAgent_Init
@snippet core_mqtt_agent.h declare_mqtt_agent_init
@copydoc MQTTAgent_Init
@page mqtt_agent_command_function MQTTAgent_CommandLoop
@snippet core_mqtt_agent.h declare_mqtt_agent_commandloop
@copydoc MQTTAgent_CommandLoop
@page mqtt_agent_resume_function MQTTAgent_ResumeSession
@snippet core_mqtt_agent.h declare_mqtt_agent_resumesession
@copydoc MQTTAgent_ResumeSession
@page mqtt_agent_cancel_function MQTTAgent_CancelAll
@snippet core_mqtt_agent.h declare_mqtt_agent_cancelall
@copydoc MQTTAgent_CancelAll
@page mqtt_agent_publish_function MQTTAgent_Publish
@snippet core_mqtt_agent.h declare_mqtt_agent_publish
@copydoc MQTTAgent_Publish
@page mqtt_agent_subscribe_function MQTTAgent_Subscribe
@snippet core_mqtt_agent.h declare_mqtt_agent_subscribe
@copydoc MQTTAgent_Subscribe
@page mqtt_agent_unsubscribe_function MQTTAgent_Unsubscribe
@snippet core_mqtt_agent.h declare_mqtt_agent_unsubscribe
@copydoc MQTTAgent_Unsubscribe
@page mqtt_agent_connect_function MQTTAgent_Connect
@snippet core_mqtt_agent.h declare_mqtt_agent_connect
@copydoc MQTTAgent_Connect
@page mqtt_agent_disconnect_function MQTTAgent_Disconnect
@snippet core_mqtt_agent.h declare_mqtt_agent_disconnect
@copydoc MQTTAgent_Disconnect
@page mqtt_agent_ping_function MQTTAgent_Ping
@snippet core_mqtt_agent.h declare_mqtt_agent_ping
@copydoc MQTTAgent_Ping
@page mqtt_agent_terminate_function MQTTAgent_Terminate
@snippet core_mqtt_agent.h declare_mqtt_agent_terminate
@copydoc MQTTAgent_Terminate
*/
/**
@page mqtt_agent_message_interface Message Interface
@brief Messaging interface used by the MQTT Agent.<br><br>
@section mqtt_agent_message_interface_overview Message Interface Overview
The message interface is a set of APIs to send MQTT Agent commands from application tasks to the MQTT agent task, as well as functions to allocate and release storage for these commands.
It must be implemented with thread safety, as multiple tasks can send commands concurrently. The message interface is defined in @ref core_mqtt_agent_message_interface.h.<br>
The functions that must be implemented are:<br>
- [Message Send](@ref MQTTAgentMessageSend_t)
- [Message Receive](@ref MQTTAgentMessageRecv_t)
- [Get Command](@ref MQTTAgentCommandGet_t)
- [Release Command](@ref MQTTAgentCommandRelease_t)
The send and receive functions take in an opaque context @ref MQTTAgentMessageContext_t. The functions above and the context are grouped together in the @ref MQTTAgentMessageInterface_t structure:<br>
@snippet core_mqtt_agent_message_interface.h define_messageinterface
<br>
@section mqtt_agent_message_interface_implement Implementing the Message Interface
The following steps give guidance on implementing the messaging interface:<br>
-# Implementing @ref MQTTAgentMessageContext_t<br><br>
@snippet core_mqtt_agent_message_interface.h define_messagectx
<br>
@ref MQTTAgentMessageContext_t is the incomplete type <b>struct MQTTAgentMessageContext</b>. The implemented struct MQTTAgentMessageContext must contain all of the information needed to send and receive commands with @ref MQTTAgentMessageSend_t and @ref MQTTAgentMessageRecv_t with thread safety. For example, this may be a handle to a thread safe queue, or a queue along with synchronization primitives. Commands are sent by pointer, so this structure should be able to relay pointers of type [MQTTAgentCommand_t](@ref MQTTAgentCommand).<br><br>
<b>Example code:</b>
@code{c}
struct MQTTAgentMessageContext
{
//Queue holding MQTTAgentCommand_t * pointers.
Queue_t queue;
};
@endcode
<br>
-# Implementing @ref MQTTAgentMessageSend_t<br><br>
@snippet core_mqtt_agent_message_interface.h define_messagesend
<br>
This function is expected to send the pointer that is pointed to by <b>pCommandToSend</b> using the message context.
It will return `true` if the send was successful, else `false`.<br><br>
<b>Example code:</b>
@code{c}
bool myMessageSendImplementation( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t * const * pCommandToSend,
uint32_t blockTimeMs )
{
int status = EXIT_FAILURE;
if( ( pMsgCtx != NULL ) && ( pCommandToSend != NULL ) )
{
//A function to send data to via pointer to a queue.
status = Queue_SendToBack( pMsgCtx->queue, pCommandToSend, blockTimeMs );
}
return ( status == EXIT_SUCCESS );
}
@endcode
<br>
-# Implementing @ref MQTTAgentMessageRecv_t<br><br>
@snippet core_mqtt_agent_message_interface.h define_messagerecv
<br>
This function is expected to receive a pointer that has been previously sent to the message context, and return in via the <b>pReceivedCommand</b> parameter.
It will return `true` if the receive was successful, else `false`.<br><br>
<b>Example code:</b>
@code{c}
bool myMessageRecvImplementation( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t ** pReceivedCommand,
uint32_t blockTimeMs )
{
int status = EXIT_FAILURE;
void * pReceivedPointer;
if( ( pMsgCtx != NULL ) && ( pCommandToSend != NULL ) )
{
//A function to receive data from a queue.
status = Queue_Recv( pMsgCtx->queue, &pReceivedPointer, blockTimeMs );
if( status == EXIT_SUCCESS )
{
*pReceivedCommand = ( MQTTAgentCommand_t * ) pReceivedPointer;
}
}
return ( status == EXIT_SUCCESS );
}
@endcode
<br>
-# Implementing @ref MQTTAgentCommandGet_t<br><br>
@snippet core_mqtt_agent_message_interface.h define_messageget
<br>
This function is expected to allocate storage for an [MQTTAgentCommand_t](@ref MQTTAgentCommand) struct. This function must be thread safe.
It will return a pointer to the allocated command, or `NULL` if allocation failed.<br><br>
<b>Example code:</b>
@code{c}
MQTTAgentCommand_t * myGetCommandImplementation( uint32_t blockTimeMs )
{
MQTTAgentCommand_t * ret = ( MQTTAgentCommand_t * ) malloc( sizeof( MQTTAgentCommand_t ) );
return ret;
}
@endcode
<br>
-# Implementing @ref MQTTAgentCommandRelease_t<br><br>
@snippet core_mqtt_agent_message_interface.h define_messagerelease
<br>
This function will release a [MQTTAgentCommand_t](@ref MQTTAgentCommand) struct that had been allocated with @ref MQTTAgentCommandGet_t.
It will return a `true` if the command was release, else `false`.<br><br>
<b>Example code:</b>
@code{c}
bool myReleaseCommandImplementation( MQTTAgentCommand_t * pCommandToRelease )
{
free( pCommandToRelease );
//free() does not have a return value.
return true;
}
@endcode
<br>
*/
/**
@defgroup mqtt_agent_enum_types Enumerated Types
@brief Enumerated types of the MQTT Agent
*/
/**
@defgroup mqtt_agent_callback_types Callback Types
@brief Callback function pointer types of the MQTT Agent
*/
/**
@defgroup mqtt_agent_struct_types Parameter Structures
@brief Structures passed as parameters to [MQTT Agent functions](@ref mqtt_agent_functions)
These structures are passed as parameters to library functions. Documentation for these structures will state the functions associated with each parameter structure and the purpose of each member.
*/

View File

@@ -0,0 +1,132 @@
/*
* Stylesheet for Doxygen HTML output.
*
* This file defines styles for custom elements in the header/footer and
* overrides some of the default Doxygen styles.
*
* Styles in this file do not affect the treeview sidebar.
*/
/* Set the margins to place a small amount of whitespace on the left and right
* side of the page. */
div.contents {
margin-left:4em;
margin-right:4em;
}
/* Justify text in paragraphs. */
p {
text-align: justify;
}
/* Style of section headings. */
h1 {
border-bottom: 1px solid #879ECB;
color: #354C7B;
font-size: 160%;
font-weight: normal;
padding-bottom: 4px;
padding-top: 8px;
}
/* Style of subsection headings. */
h2:not(.memtitle):not(.groupheader) {
font-size: 125%;
margin-bottom: 0px;
margin-top: 16px;
padding: 0px;
}
/* Style of paragraphs immediately after subsection headings. */
h2 + p {
margin: 0px;
padding: 0px;
}
/* Style of subsection headings. */
h3 {
font-size: 100%;
margin-bottom: 0px;
margin-left: 2em;
margin-right: 2em;
}
/* Style of paragraphs immediately after subsubsection headings. */
h3 + p {
margin-top: 0px;
margin-left: 2em;
margin-right: 2em;
}
/* Style of the prefix "AWS IoT Device SDK C" that appears in the header. */
#csdkprefix {
color: #757575;
}
/* Style of the "Return to main page" link that appears in the header. */
#returntomain {
padding: 0.5em;
}
/* Style of the dividers on Configuration Settings pages. */
div.configpagedivider {
margin-left: 0px !important;
margin-right: 0px !important;
margin-top: 20px !important;
}
/* Style of configuration setting names. */
dl.section.user ~ h1 {
border-bottom: none;
color: #000000;
font-family: monospace, fixed;
font-size: 16px;
margin-bottom: 0px;
margin-left: 2em;
margin-top: 1.5em;
}
/* Style of paragraphs on a configuration settings page. */
dl.section.user ~ * {
margin-bottom: 10px;
margin-left: 4em;
margin-right: 4em;
margin-top: 0px;
}
/* Hide the configuration setting marker. */
dl.section.user {
display: none;
}
/* Overrides for code fragments and lines. */
div.fragment {
background: #ffffff;
border: none;
padding: 5px;
}
div.line {
color: #3a3a3a;
}
/* Overrides for code syntax highlighting colors. */
span.comment {
color: #008000;
}
span.keyword, span.keywordtype, span.keywordflow {
color: #0000ff;
}
span.preprocessor {
color: #50015a;
}
span.stringliteral, span.charliteral {
color: #800c0c;
}
a.code, a.code:visited, a.line, a.line:visited {
color: #496194;
}

View File

@@ -0,0 +1,21 @@
name : "coreMQTT Agent"
version: "v1.3.1"
description: |
"Agent for thread-safe use of coreMQTT.\n"
license: "MIT"
dependencies:
- name : "coreMQTT"
version: "v2.3.1"
license: "MIT"
repository:
type: "git"
url: "https://github.com/FreeRTOS/coreMQTT/"
path: source/dependency/coreMQTT
- name: "CMock"
version: "v2.5.3"
license: "MIT"
repository:
type: "git"
url: " https://github.com/ThrowTheSwitch/CMock.git"
path: "test/unit-test/CMock"

View File

@@ -0,0 +1,17 @@
# This file is to add source files and include directories
# into variables so that it can be reused from different repositories
# in their Cmake based build system by including this file.
#
# Files specific to the repository such as test runner, platform tests
# are not added to the variables.
# MQTT Agent library Public Include directories.
set( MQTT_AGENT_INCLUDE_PUBLIC_DIRS
"${CMAKE_CURRENT_LIST_DIR}/source/include" )
# MQTT Agent library source files.
set( MQTT_AGENT_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/source/core_mqtt_agent.c"
"${CMAKE_CURRENT_LIST_DIR}/source/core_mqtt_agent_command_functions.c" )

View File

@@ -0,0 +1,52 @@
SPDXVersion: SPDX-2.2
DataLicense: CC0-1.0
SPDXID: SPDXRef-DOCUMENT
DocumentName: coreMQTT Agent
DocumentNamespace: https://github.com/FreeRTOS/coreMQTT Agent/blob/v1.3.1/sbom.spdx
Creator: Organization:Amazon Web Services
Created: 2024-08-29T09:04:54Z
CreatorComment: NOASSERTION
DocumentComment: NOASSERTION
PackageName: coreMQTT Agent
SPDXID: SPDXRef-Package-coreMQTT Agent
PackageVersion: v1.3.1
PackageDownloadLocation: https://github.com/FreeRTOS/coreMQTT-Agent/tree/v1.3.1
PackageLicenseDeclared: MIT
PackageLicenseConcluded: MIT
PackageLicenseInfoFromFiles: NOASSERTION
FilesAnalyzed: true
PackageVerificationCode: a6de60f11ecfc1b23ccf8436bd6f1da0be555423
PackageCopyrightText: NOASSERTION
PackageSummary: NOASSERTION
PackageDescription: "Agent for thread-safe use of coreMQTT.\n"
FileName: ./core_mqtt_agent.c
SPDXID: SPDXRef-File-coremqttagent.c
FileChecksum: SHA1: be5a720e74e50451cd1e675ad73d2e7e5daffed0
LicenseConcluded: MIT
FileCopyrightText: NOASSERTION
FileComment: NOASSERTION
FileName: ./core_mqtt_agent_command_functions.c
SPDXID: SPDXRef-File-coremqttagentcommandfunctions.c
FileChecksum: SHA1: 9c6f652d280eea97cfe2f14e5a65650ad60dd44d
LicenseConcluded: MIT
FileCopyrightText: NOASSERTION
FileComment: NOASSERTION
PackageName: coreMQTT
SPDXID: SPDXRef-Package-coreMQTT
PackageVersion: v2.3.1
PackageDownloadLocation: https://github.com/FreeRTOS/coreMQTT/
PackageLicenseDeclared: MIT
PackageLicenseConcluded: MIT
PackageLicenseInfoFromFiles: NOASSERTION
FilesAnalyzed: true
PackageVerificationCode: da39a3ee5e6b4b0d3255bfef95601890afd80709
PackageCopyrightText: NOASSERTION
PackageSummary: NOASSERTION
PackageDescription: NOASSERTION
Relationship: SPDXRef-Package-coreMQTT Agent DEPENDS_ON SPDXRef-Package-coreMQTT

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,245 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_agent_command_functions.c
* @brief Implements functions to process MQTT agent commands.
*/
/* Standard includes. */
#include <string.h>
#include <stdio.h>
#include <assert.h>
/* MQTT agent include. */
#include "core_mqtt_agent.h"
/* Header include. */
#include "core_mqtt_agent_command_functions.h"
/* MQTT Agent default logging configuration include. */
#include "core_mqtt_agent_default_logging.h"
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_ProcessLoop( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
( void ) pUnusedArg;
( void ) pMqttAgentContext;
assert( pReturnFlags != NULL );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pReturnFlags->runProcessLoop = true;
return MQTTSuccess;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Publish( MQTTAgentContext_t * pMqttAgentContext,
void * pPublishArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
const MQTTPublishInfo_t * pPublishInfo;
MQTTStatus_t ret;
assert( pMqttAgentContext != NULL );
assert( pPublishArg != NULL );
assert( pReturnFlags != NULL );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pPublishInfo = ( const MQTTPublishInfo_t * ) ( pPublishArg );
if( pPublishInfo->qos != MQTTQoS0 )
{
pReturnFlags->packetId = MQTT_GetPacketId( &( pMqttAgentContext->mqttContext ) );
}
LogInfo( ( "Publishing message to %.*s.\n", ( int ) pPublishInfo->topicNameLength, pPublishInfo->pTopicName ) );
ret = MQTT_Publish( &( pMqttAgentContext->mqttContext ), pPublishInfo, pReturnFlags->packetId );
/* Add to pending ack list, or call callback if QoS 0. */
pReturnFlags->addAcknowledgment = ( pPublishInfo->qos != MQTTQoS0 ) && ( ret == MQTTSuccess );
pReturnFlags->runProcessLoop = true;
return ret;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Subscribe( MQTTAgentContext_t * pMqttAgentContext,
void * pVoidSubscribeArgs,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
const MQTTAgentSubscribeArgs_t * pSubscribeArgs;
MQTTStatus_t ret;
assert( pMqttAgentContext != NULL );
assert( pVoidSubscribeArgs != NULL );
assert( pReturnFlags != NULL );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pSubscribeArgs = ( const MQTTAgentSubscribeArgs_t * ) ( pVoidSubscribeArgs );
pReturnFlags->packetId = MQTT_GetPacketId( &( pMqttAgentContext->mqttContext ) );
ret = MQTT_Subscribe( &( pMqttAgentContext->mqttContext ),
pSubscribeArgs->pSubscribeInfo,
pSubscribeArgs->numSubscriptions,
pReturnFlags->packetId );
pReturnFlags->addAcknowledgment = ( ret == MQTTSuccess );
pReturnFlags->runProcessLoop = true;
return ret;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Unsubscribe( MQTTAgentContext_t * pMqttAgentContext,
void * pVoidSubscribeArgs,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
const MQTTAgentSubscribeArgs_t * pSubscribeArgs;
MQTTStatus_t ret;
assert( pMqttAgentContext != NULL );
assert( pVoidSubscribeArgs != NULL );
assert( pReturnFlags != NULL );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pSubscribeArgs = ( const MQTTAgentSubscribeArgs_t * ) ( pVoidSubscribeArgs );
pReturnFlags->packetId = MQTT_GetPacketId( &( pMqttAgentContext->mqttContext ) );
ret = MQTT_Unsubscribe( &( pMqttAgentContext->mqttContext ),
pSubscribeArgs->pSubscribeInfo,
pSubscribeArgs->numSubscriptions,
pReturnFlags->packetId );
pReturnFlags->addAcknowledgment = ( ret == MQTTSuccess );
pReturnFlags->runProcessLoop = true;
return ret;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Connect( MQTTAgentContext_t * pMqttAgentContext,
void * pVoidConnectArgs,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
MQTTStatus_t ret;
MQTTAgentConnectArgs_t * pConnectInfo;
assert( pMqttAgentContext != NULL );
assert( pVoidConnectArgs != NULL );
assert( pReturnFlags != NULL );
pConnectInfo = ( MQTTAgentConnectArgs_t * ) ( pVoidConnectArgs );
ret = MQTT_Connect( &( pMqttAgentContext->mqttContext ),
pConnectInfo->pConnectInfo,
pConnectInfo->pWillInfo,
pConnectInfo->timeoutMs,
&( pConnectInfo->sessionPresent ) );
/* Resume a session if one existed, else clear the list of acknowledgments. */
if( ret == MQTTSuccess )
{
LogInfo( ( "Session present flag: %d", pConnectInfo->sessionPresent ) );
ret = MQTTAgent_ResumeSession( pMqttAgentContext,
pConnectInfo->sessionPresent );
}
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
return ret;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Disconnect( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
MQTTStatus_t ret;
( void ) pUnusedArg;
assert( pMqttAgentContext != NULL );
assert( pReturnFlags != NULL );
ret = MQTT_Disconnect( &( pMqttAgentContext->mqttContext ) );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pReturnFlags->endLoop = true;
return ret;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Ping( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
MQTTStatus_t ret;
( void ) pUnusedArg;
assert( pMqttAgentContext != NULL );
assert( pReturnFlags != NULL );
ret = MQTT_Ping( &( pMqttAgentContext->mqttContext ) );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pReturnFlags->runProcessLoop = true;
return ret;
}
/*-----------------------------------------------------------*/
MQTTStatus_t MQTTAgentCommand_Terminate( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags )
{
MQTTStatus_t ret;
( void ) pUnusedArg;
assert( pMqttAgentContext != NULL );
assert( pMqttAgentContext->agentInterface.releaseCommand != NULL );
assert( pReturnFlags != NULL );
LogInfo( ( "Terminating command loop.\n" ) );
( void ) memset( pReturnFlags, 0x00, sizeof( MQTTAgentCommandFuncReturns_t ) );
pReturnFlags->endLoop = true;
ret = MQTTAgent_CancelAll( pMqttAgentContext );
return ret;
}
/*-----------------------------------------------------------*/

View File

@@ -0,0 +1,932 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_agent.h
* @brief Functions for running a coreMQTT client in a dedicated thread.
*/
#ifndef CORE_MQTT_AGENT_H
#define CORE_MQTT_AGENT_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* MQTT library includes. */
#include "core_mqtt.h"
#include "core_mqtt_state.h"
#include "core_mqtt_agent_config_defaults.h"
/* Command messaging interface include. */
#include "core_mqtt_agent_message_interface.h"
/**
* @ingroup mqtt_agent_enum_types
* @brief A type of command for interacting with the MQTT API.
*/
typedef enum MQTTCommandType
{
NONE = 0, /**< @brief No command received. Must be zero (its memset() value). */
PROCESSLOOP, /**< @brief Call MQTT_ProcessLoop(). */
PUBLISH, /**< @brief Call MQTT_Publish(). */
SUBSCRIBE, /**< @brief Call MQTT_Subscribe(). */
UNSUBSCRIBE, /**< @brief Call MQTT_Unsubscribe(). */
PING, /**< @brief Call MQTT_Ping(). */
CONNECT, /**< @brief Call MQTT_Connect(). */
DISCONNECT, /**< @brief Call MQTT_Disconnect(). */
TERMINATE, /**< @brief Exit the command loop and stop processing commands. */
NUM_COMMANDS /**< @brief The number of command types handled by the agent. */
} MQTTAgentCommandType_t;
struct MQTTAgentContext;
struct MQTTAgentCommandContext;
/**
* @ingroup mqtt_agent_struct_types
* @brief Struct holding return codes and outputs from a command
*/
typedef struct MQTTAgentReturnInfo
{
MQTTStatus_t returnCode; /**< Return code of the MQTT command. */
uint8_t * pSubackCodes; /**< Array of SUBACK statuses, for a SUBSCRIBE command. */
} MQTTAgentReturnInfo_t;
/**
* @ingroup mqtt_agent_struct_types
* @brief Struct containing context for a specific command.
*
* @note An instance of this struct and any variables it points to MUST stay
* in scope until the associated command is processed, and its callback called.
*/
typedef struct MQTTAgentCommandContext MQTTAgentCommandContext_t;
/**
* @ingroup mqtt_agent_callback_types
* @brief Callback function called when a command completes.
*
* @param[in] pCmdCallbackContext The callback context passed to the original command.
* @param[in] pReturnInfo A struct of status codes and outputs from the command.
*
* @note A command should not be considered complete until this callback is
* called, and the arguments that the command uses MUST stay in scope until such happens.
*
* @note The callback MUST NOT block as it runs in the context of the MQTT agent
* task. If the callback calls any MQTT Agent API to enqueue a command, the
* blocking time (blockTimeMs member of MQTTAgentCommandInfo_t) MUST be zero. If the
* application wants to enqueue command(s) with non-zero blocking time, the
* callback can notify a different task to enqueue command(s) to the MQTT agent.
*/
typedef void (* MQTTAgentCommandCallback_t )( MQTTAgentCommandContext_t * pCmdCallbackContext,
MQTTAgentReturnInfo_t * pReturnInfo );
/**
* @ingroup mqtt_agent_struct_types
* @brief The commands sent from the APIs to the MQTT agent task.
*
* @note The structure used to pass information from the public facing API into the
* agent task. */
struct MQTTAgentCommand
{
MQTTAgentCommandType_t commandType; /**< @brief Type of command. */
void * pArgs; /**< @brief Arguments of command. */
MQTTAgentCommandCallback_t pCommandCompleteCallback; /**< @brief Callback to invoke upon completion. */
MQTTAgentCommandContext_t * pCmdContext; /**< @brief Context for completion callback. */
};
/**
* @ingroup mqtt_agent_struct_types
* @brief Information for a pending MQTT ack packet expected by the agent.
*/
typedef struct MQTTAckInfo
{
uint16_t packetId; /**< Packet ID of the pending acknowledgment. */
MQTTAgentCommand_t * pOriginalCommand; /**< Command expecting acknowledgment. */
} MQTTAgentAckInfo_t;
/**
* @ingroup mqtt_agent_callback_types
* @brief Callback function called when receiving a publish.
*
* @param[in] pMqttAgentContext The context of the MQTT agent.
* @param[in] packetId The packet ID of the received publish.
* @param[in] pPublishInfo Deserialized publish information.
*
* @note The callback MUST NOT block as it runs in the context of the MQTT agent
* task. If the callback calls any MQTT Agent API to enqueue a command, the
* blocking time (blockTimeMs member of MQTTAgentCommandInfo_t) MUST be zero. If the
* application wants to enqueue command(s) with non-zero blocking time, the
* callback can notify a different task to enqueue command(s) to the MQTT agent.
*/
typedef void (* MQTTAgentIncomingPublishCallback_t )( struct MQTTAgentContext * pMqttAgentContext,
uint16_t packetId,
MQTTPublishInfo_t * pPublishInfo );
/**
* @ingroup mqtt_agent_struct_types
* @brief Information used by each MQTT agent. A context will be initialized by
* MQTTAgent_Init(), and every API function will accept a pointer to the
* initalized struct.
*/
typedef struct MQTTAgentContext
{
MQTTContext_t mqttContext; /**< MQTT connection information used by coreMQTT. */
MQTTAgentMessageInterface_t agentInterface; /**< Struct of function pointers for agent messaging. */
MQTTAgentAckInfo_t pPendingAcks[ MQTT_AGENT_MAX_OUTSTANDING_ACKS ]; /**< List of pending acknowledgment packets. */
MQTTAgentIncomingPublishCallback_t pIncomingCallback; /**< Callback to invoke for incoming publishes. */
void * pIncomingCallbackContext; /**< Context for incoming publish callback. */
bool packetReceivedInLoop; /**< Whether a MQTT_ProcessLoop() call received a packet. */
} MQTTAgentContext_t;
/**
* @ingroup mqtt_agent_struct_types
* @brief Struct holding arguments for a SUBSCRIBE or UNSUBSCRIBE call.
*/
typedef struct MQTTAgentSubscribeArgs
{
MQTTSubscribeInfo_t * pSubscribeInfo; /**< @brief List of MQTT subscriptions. */
size_t numSubscriptions; /**< @brief Number of elements in `pSubscribeInfo`. */
} MQTTAgentSubscribeArgs_t;
/**
* @ingroup mqtt_agent_struct_types
* @brief Struct holding arguments for a CONNECT call.
*/
typedef struct MQTTAgentConnectArgs
{
MQTTConnectInfo_t * pConnectInfo; /**< @brief MQTT CONNECT packet information. */
MQTTPublishInfo_t * pWillInfo; /**< @brief Optional Last Will and Testament. */
uint32_t timeoutMs; /**< @brief Maximum timeout for a CONNACK packet. */
bool sessionPresent; /**< @brief Output flag set if a previous session was present. */
} MQTTAgentConnectArgs_t;
/**
* @ingroup mqtt_agent_struct_types
* @brief Struct holding arguments that are common to every command.
*/
typedef struct MQTTAgentCommandInfo
{
MQTTAgentCommandCallback_t cmdCompleteCallback; /**< @brief Callback to invoke upon completion. */
MQTTAgentCommandContext_t * pCmdCompleteCallbackContext; /**< @brief Context for completion callback. */
uint32_t blockTimeMs; /**< @brief Maximum block time for enqueueing the command. */
} MQTTAgentCommandInfo_t;
/*-----------------------------------------------------------*/
/**
* @brief Perform any initialization the MQTT agent requires before it can
* be used. Must be called before any other function.
*
* @param[in] pMqttAgentContext Pointer to struct to initialize.
* @param[in] pMsgInterface Command interface to use for allocating and sending commands.
* @param[in] pNetworkBuffer Pointer to network buffer to use.
* @param[in] pTransportInterface Transport interface to use with the MQTT library.
* See https://www.freertos.org/Documentation/03-Libraries/03-FreeRTOS-core/06-Transport-Interface/01-Transport-interface
* @param[in] getCurrentTimeMs Pointer to a function that returns a count value
* that increments every millisecond.
* @param[in] incomingCallback The callback to execute when receiving publishes.
* @param[in] pIncomingPacketContext A pointer to a context structure defined by
* the application writer.
*
* @note The @p pIncomingPacketContext context provided for the incoming publish
* callback MUST remain in scope throughout the period that the agent task is running.
*
* @return Appropriate status code from MQTT_Init().
*
* <b>Example</b>
* @code{c}
*
* // Function for obtaining a timestamp.
* uint32_t getTimeStampMs();
* // Callback function for receiving packets.
* void incomingPublishCallback( MQTTAgentContext_t * pMqttAgentContext,
* uint16_t packetId,
* MQTTPublishInfo_t * pPublishInfo );
* // Platform function for network send interface.
* int32_t networkSend( NetworkContext_t * pContext, const void * pBuffer, size_t bytes );
* // Platform for network receive interface.
* int32_t networkRecv( NetworkContext_t * pContext, void * pBuffer, size_t bytes );
*
* // Platform function for Agent Message Send.
* bool agentSendMessage( MQTTAgentMessageContext_t * pMsgCtx,
* MQTTAgentCommand_t * const * pCommandToSend,
* uint32_t blockTimeMs );
* // Platform function for Agent Message Receive.
* bool agentReceiveMessage( MQTTAgentMessageContext_t * pMsgCtx,
* MQTTAgentCommand_t ** pCommandToSend,
* uint32_t blockTimeMs );
* // Platform function to Get Agent Command.
* MQTTAgentCommand_t * getCommand( uint32_t blockTimeMs );
* // Platform function to Release Agent Command.
* bool releaseCommand( MQTTAgentCommand_t * pCommandToRelease );
*
* // Variables used in this example.
* MQTTAgentMessageInterface_t messageInterface;
* MQTTAgentMessageContext_t messageContext;
* MQTTAgentContext_t agentContext;
* TransportInterface_t transport;
* // Buffer for storing outgoing and incoming MQTT packets.
* MQTTFixedBuffer_t fixedBuffer;
* uint8_t buffer[ 1024 ];
* MQTTStatus_t status;
*
* // Set transport interface members.
* transport.pNetworkContext = &someTransportContext;
* transport.send = networkSend;
* transport.recv = networkRecv;
*
* // Set agent message interface members.
* messageInterface.pMsgCtx = &messageContext;
* messageInterface.send = agentSendMessage;
* messageInterface.recv = agentReceiveMessage;
* messageInterface.getCommand = getCommand;
* messageInterface.releaseCommand = releaseCommand;
*
* // Set buffer members.
* fixedBuffer.pBuffer = buffer;
* fixedBuffer.size = 1024;
*
* status = MQTTAgent_Init( &agentContext,
* &messageInterface,
* &networkBuffer,
* &transportInterface,
* stubGetTime,
* stubPublishCallback,
* incomingPacketContext );
*
* if( status == MQTTSuccess )
* {
* // Do something with agentContext. The transport and message interfaces, and
* // fixedBuffer structs were copied into the context, so the original structs
* // do not need to stay in scope.
* }
* @endcode
*/
/* @[declare_mqtt_agent_init] */
MQTTStatus_t MQTTAgent_Init( MQTTAgentContext_t * pMqttAgentContext,
const MQTTAgentMessageInterface_t * pMsgInterface,
const MQTTFixedBuffer_t * pNetworkBuffer,
const TransportInterface_t * pTransportInterface,
MQTTGetCurrentTimeFunc_t getCurrentTimeMs,
MQTTAgentIncomingPublishCallback_t incomingCallback,
void * pIncomingPacketContext );
/* @[declare_mqtt_agent_init] */
/**
* @brief Process commands from the command queue in a loop.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
*
* @return appropriate error code, or #MQTTSuccess from a successful disconnect
* or termination.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTStatus_t status;
* MQTTAgentContext_t mqttAgentContext;
*
* status = MQTTAgent_CommandLoop( &mqttAgentContext );
*
* // The function returns on either receiving a terminate command,
* // undergoing network disconnection OR encountering an error.
* if( ( status == MQTTSuccess ) && ( mqttAgentContext.mqttContext.connectStatus == MQTTNotConnected ) )
* {
* // A terminate command was processed and MQTT connection was closed.
* // Need to close socket connection.
* Platform_DisconnectNetwork( mqttAgentContext.mqttContext.transportInterface.pNetworkContext );
* }
* else if( status == MQTTSuccess )
* {
* // Terminate command was processed but MQTT connection was not
* // closed. Thus, need to close both MQTT and socket connections.
* status = MQTT_Disconnect( &( mqttAgentContext.mqttContext ) );
* assert( status == MQTTSuccess );
* Platform_DisconnectNetwork( mqttAgentContext.mqttContext.transportInterface.pNetworkContext );
* }
* else
* {
* // Handle error.
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_commandloop] */
MQTTStatus_t MQTTAgent_CommandLoop( MQTTAgentContext_t * pMqttAgentContext );
/* @[declare_mqtt_agent_commandloop] */
/**
* @brief Resume a session by resending publishes if a session is present in
* the broker, or clear state information if not.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] sessionPresent The session present flag from the broker.
*
* @note This function is NOT thread-safe and should only be called
* from the context of the task responsible for #MQTTAgent_CommandLoop.
*
* @return #MQTTSuccess if it succeeds in resending publishes, else an
* appropriate error code from `MQTT_Publish()`
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTStatus_t status;
* MQTTAgentContext_t mqttAgentContext;
* MQTTConnectInfo_t connectInfo = { 0 };
* MQTTPublishInfo_t willInfo = { 0 };
* bool sessionPresent;
*
* // The example assumes that all variables have been filled with
* // data for the MQTT_Connect call
* // Refer to the MQTT_Connect API for a more detailed example.
*
* // Attempt to resume session with the broker.
* status = MQTT_Connect( &( mqttAgentContext.mqttContext ), &connectInfo, &willInfo, 100, &sessionPresent )
*
* if( status == MQTTSuccess )
* {
* // Process the session present status sent by the broker.
* status = MQTTAgent_ResumeSession( &mqttAgentContext, sessionPresent );
* }
* @endcode
*/
/* @[declare_mqtt_agent_resumesession] */
MQTTStatus_t MQTTAgent_ResumeSession( MQTTAgentContext_t * pMqttAgentContext,
bool sessionPresent );
/* @[declare_mqtt_agent_resumesession] */
/**
* @brief Cancel all enqueued commands and those awaiting acknowledgment
* while the command loop is not running.
*
* Canceled commands will be terminated with return code #MQTTRecvFailed.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
*
* @note This function is NOT thread-safe and should only be called
* from the context of the task responsible for #MQTTAgent_CommandLoop.
*
* @return #MQTTBadParameter if an invalid context is given, else #MQTTSuccess.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTStatus_t status;
* MQTTAgentContext_t mqttAgentContext;
*
* status = MQTTAgent_CommandLoop( &mqttAgentContext );
*
* //An error was returned, but reconnection is not desired. Cancel all commands
* //that are in the queue or awaiting an acknowledgment.
* if( status != MQTTSuccess )
* {
* //Cancel commands so any completion callbacks will be invoked.
* status = MQTTAgent_CancelAll( &mqttAgentContext );
* }
*
* Platform_DisconnectNetwork( mqttAgentContext.mqttContext.transportInterface.pNetworkContext );
*
* @endcode
*/
/* @[declare_mqtt_agent_cancelall] */
MQTTStatus_t MQTTAgent_CancelAll( MQTTAgentContext_t * pMqttAgentContext );
/* @[declare_mqtt_agent_cancelall] */
/**
* @brief Add a command to call MQTT_Subscribe() for an MQTT connection.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pSubscriptionArgs Struct describing topic to subscribe to.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
* MQTTSubscribeInfo_t subscribeInfo = { 0 };
* MQTTAgentSubscribeArgs_t subscribeArgs = { 0 };
*
* // Function for command complete callback.
* void subscribeCmdCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.CmdCompleteCallback = subscribeCmdCompleteCb;
* commandInfo.blockTimeMs = 500;
*
* // Fill the information for topic filters to subscribe to.
* subscribeInfo.qos = Qos1;
* subscribeInfo.pTopicFilter = "/foo/bar";
* subscribeInfo.topicFilterLength = strlen("/foo/bar");
* subscribeArgs.pSubscribeInfo = &subscribeInfo;
* subscribeArgs.numSubscriptions = 1U;
*
* status = MQTTAgent_Subscribe( &agentContext, &subscribeArgs, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command to send subscribe request to the server has been queued. Notification
* // about completion of the subscribe operation will be notified to application
* // through invocation of subscribeCmdCompleteCb().
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_subscribe] */
MQTTStatus_t MQTTAgent_Subscribe( const MQTTAgentContext_t * pMqttAgentContext,
MQTTAgentSubscribeArgs_t * pSubscriptionArgs,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_subscribe] */
/**
* @brief Add a command to call MQTT_Unsubscribe() for an MQTT connection.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pSubscriptionArgs List of topics to unsubscribe from.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
* MQTTSubscribeInfo_t unsubscribeInfo = { 0 };
* MQTTAgentSubscribeArgs_t unsubscribeArgs = { 0 };
*
* // Function for command complete callback.
* void unsubscribeCmdCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = unsubscribeCmdCompleteCb;
* commandInfo.blockTimeMs = 500;
*
* // Fill the information for topics to unsubscribe from.
* unsubscribeInfo.pTopicFilter = "/foo/bar";
* unsubscribeInfo.topicFilterLength = strlen("/foo/bar");
* unsubscribeArgs.pSubscribeInfo = &unsubscribeInfo;
* unsubscribeArgs.numSubscriptions = 1U;
*
* status = MQTTAgent_Unsubscribe( &agentContext, &unsubscribeArgs, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command to send Unsubscribe request to the server has been queued. Notification
* // about completion of the Unsubscribe operation will be notified to application
* // through invocation of unsubscribeCompleteCb().
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_unsubscribe] */
MQTTStatus_t MQTTAgent_Unsubscribe( const MQTTAgentContext_t * pMqttAgentContext,
MQTTAgentSubscribeArgs_t * pSubscriptionArgs,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_unsubscribe] */
/**
* @brief Add a command to call MQTT_Publish() for an MQTT connection.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pPublishInfo MQTT PUBLISH information.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
* MQTTPublishInfo_t publishInfo = { 0 };
*
* // Function for command complete callback.
* void publishCmdCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = publishCmdCompleteCb;
* commandInfo.blockTimeMs = 500;
*
* // Fill the information for publish operation.
* publishInfo.qos = MQTTQoS1;
* publishInfo.pTopicName = "/some/topic/name";
* publishInfo.topicNameLength = strlen( publishInfo.pTopicName );
* publishInfo.pPayload = "Hello World!";
* publishInfo.payloadLength = strlen( "Hello World!" );
*
* status = MQTTAgent_Publish( &agentContext, &publishInfo, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command to publish message to broker has been queued.
* // The event of publish operation completion will be notified with
* // the invocation of the publishCmdCompleteCb().
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_publish] */
MQTTStatus_t MQTTAgent_Publish( const MQTTAgentContext_t * pMqttAgentContext,
MQTTPublishInfo_t * pPublishInfo,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_publish] */
/**
* @brief Send a message to the MQTT agent purely to trigger an iteration of its loop,
* which will result in a call to MQTT_ProcessLoop(). This function can be used to
* wake the MQTT agent task when it is known data may be available on the connected
* socket.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
*
* // Function for command complete callback.
* void cmdCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = cmdCompleteCb;
* commandInfo.blockTimeMs = 500;
*
* status = MQTTAgent_ProcessLoop( &agentContext, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command to call MQTT_ProcessLoop() has been queued.
* // After processing the command, if an incoming publish is received,
* // the event will be notified with invocation of the incoming publish
* // callback configured in the agent context.
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_processloop] */
MQTTStatus_t MQTTAgent_ProcessLoop( const MQTTAgentContext_t * pMqttAgentContext,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_processloop] */
/**
* @brief Add a command to call MQTT_Ping() for an MQTT connection.
*
* @note This API function ONLY enqueues a command to send a ping request to the server,
* and DOES NOT wait for a ping response to be received from the server. To detect whether
* a Ping Response, has not been received from the server, the @ref MQTTAgent_CommandLoop
* function SHOULD be used, which returns the #MQTTKeepAliveTimeout return code on a ping
* response (or keep-alive) timeout.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
*
* // Function for command complete callback.
* void pingRequestCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = pingRequestCompleteCb;
* commandInfo.blockTimeMs = 500;
*
* status = MQTTAgent_Ping( &agentContext, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command for sending request has been queued. Application can
* // handle keep-alive timeout if detected through return value of
* // MQTTAgent_CommandLoop in the task running the agent.
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_ping] */
MQTTStatus_t MQTTAgent_Ping( const MQTTAgentContext_t * pMqttAgentContext,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_ping] */
/**
* @brief Add a command to call MQTT_Connect() for an MQTT connection. If a session
* is resumed with the broker, it will also resend the necessary QoS1/2 publishes.
*
* @note The MQTTAgent_Connect function is provided to give a thread safe equivalent
* to the MQTT_Connect API. However, it is RECOMMENDED that instead of the application
* tasks (i.e. tasks other than the agent task), the agent be responsible for creating
* the MQTT connection (by calling MQTT_Connect) before starting the command loop (with
* the MQTTAgent_CommandLoop() call). In that case, the agent SHOULD also be responsible
* for disconnecting the MQTT connection after the command loop has terminated (through
* an MQTTAgent_Terminate() call from an application task).
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in, out] pConnectArgs Struct holding args for MQTT_Connect(). On a successful
* connection after the command is processed, the sessionPresent member will be filled
* to indicate whether the broker resumed an existing session.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTConnectInfo_t connectInfo = { 0 };
* MQTTPublishInfo_t willInfo = { 0 };
* MQTTAgentConnectArgs_t connectionArgs;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
*
* // True for creating a new session with broker, false if we want to resume an old one.
* connectInfo.cleanSession = true;
* // Client ID must be unique to broker. This field is required.
* connectInfo.pClientIdentifier = "someClientID";
* connectInfo.clientIdentifierLength = strlen( connectInfo.pClientIdentifier );
*
* // Value for keep alive.
* connectInfo.keepAliveSeconds = 60;
* // The following fields are optional.
* // Optional username and password.
* connectInfo.pUserName = "someUserName";
* connectInfo.userNameLength = strlen( connectInfo.pUserName );
* connectInfo.pPassword = "somePassword";
* connectInfo.passwordLength = strlen( connectInfo.pPassword );
*
* // The last will and testament is optional, it will be published by the broker
* // should this client disconnect without sending a DISCONNECT packet.
* willInfo.qos = MQTTQoS0;
* willInfo.pTopicName = "/lwt/topic/name";
* willInfo.topicNameLength = strlen( willInfo.pTopicName );
* willInfo.pPayload = "LWT Message";
* willInfo.payloadLength = strlen( "LWT Message" );
*
* // Fill the MQTTAgentConnectArgs_t structure.
* connectArgs.pConnectInfo = &connectInfo;
* connectArgs.pWillInfo = &willInfo;
* // Time to block for CONNACK response when command is processed.
* connectArgs.timeoutMs = 500;
*
* // Function for command complete callback.
* void connectCmdCallback( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = connectCmdCallback;
* commandInfo.blockTimeMs = 500;
*
* status = MQTTAgent_Connect( &agentContext, &connectArgs, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command for creating the MQTT connection has been queued.
* // The MQTT connection event will be notified through the
* // invocation of connectCmdCallback().
* }
* @endcode
*/
/* @[declare_mqtt_agent_connect] */
MQTTStatus_t MQTTAgent_Connect( const MQTTAgentContext_t * pMqttAgentContext,
MQTTAgentConnectArgs_t * pConnectArgs,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_connect] */
/**
* @brief Add a command to disconnect an MQTT connection.
*
* @note #MQTTAgent_CommandLoop will return after processing a #DISCONNECT
* command to allow the network connection to be disconnected. However, any
* pending commands in the queue, as well as those waiting for an acknowledgment,
* will NOT be terminated.
*
* @note The MQTTAgent_Disconnect function is provided to give a thread safe
* equivalent to the MQTT_Disconnect API. However, if the agent task is responsible
* for creating the MQTT connection (before calling MQTTAgent_CommandLoop()), then
* it is RECOMMENDED that an application task (i.e. a task other than the agent task)
* use MQTTAgent_Terminate to terminate the command loop in the agent, and the agent
* task be responsible for disconnecting the MQTT connection.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
*
* // Function for command complete callback.
* void disconnectCmdCallback( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = disconnectCmdCallback;
* commandInfo.blockTimeMs = 500;
*
* status = MQTTAgent_Disconnect( &agentContext, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command for closing the MQTT connection has been queued.
* // The MQTT disconnection event will be notified through the
* // invocation of disconnectCmdCallback().
* }
*
* @endcode
*/
/* @[declare_mqtt_agent_disconnect] */
MQTTStatus_t MQTTAgent_Disconnect( const MQTTAgentContext_t * pMqttAgentContext,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_disconnect] */
/**
* @brief Add a termination command to the command queue.
*
* On command loop termination, all pending commands in the queue, as well
* as those waiting for an acknowledgment, will be terminated with error code
* #MQTTRecvFailed.
*
* @note Commands may still be posted to the command queue after #MQTTAgent_CommandLoop
* has returned. It is the responsibility of the application to cancel any
* commands that are posted while the command loop is not running, such as by
* invoking #MQTTAgent_CancelAll.
*
* @note We RECOMMEND that this function is used from application task(s),
* that is a task not running the agent, to terminate the agent loop instead
* of calling MQTTAgent_Disconnect, so that the logic for creating and closing
* MQTT connection is owned by the agent task.
*
* @param[in] pMqttAgentContext The MQTT agent to use.
* @param[in] pCommandInfo The information pertaining to the command, including:
* - cmdCompleteCallback Optional callback to invoke when the command completes.
* - pCmdCompleteCallbackContext Optional completion callback context.
* - blockTimeMs The maximum amount of time in milliseconds to wait for the
* command to be posted to the MQTT agent, should the agent's event queue
* be full. Tasks wait in the Blocked state so don't use any CPU time.
*
* @note The context passed to the callback through pCmdContext member of
* @p pCommandInfo parameter MUST remain in scope at least until the callback
* has been executed by the agent task.
*
* @return #MQTTSuccess if the command was posted to the MQTT agent's event queue.
* Otherwise an enumerated error code.
*
* <b>Example</b>
* @code{c}
*
* // Variables used in this example.
* MQTTAgentContext_t agentContext;
* MQTTStatus_t status;
* MQTTAgentCommandInfo_t commandInfo = { 0 };
*
* // Function for command complete callback.
* void terminateCallback( MQTTAgentCommandContext_t * pCmdCallbackContext,
* MQTTAgentReturnInfo_t * pReturnInfo );
*
* // Fill the command information.
* commandInfo.cmdCompleteCallback = terminateCallback;
* commandInfo.blockTimeMs = 500;
*
* status = MQTTAgent_Terminate( &agentContext, &commandInfo );
*
* if( status == MQTTSuccess )
* {
* // Command to terminate the agent loop has been queued.
* }
*
* @endcode
*
*/
/* @[declare_mqtt_agent_terminate] */
MQTTStatus_t MQTTAgent_Terminate( const MQTTAgentContext_t * pMqttAgentContext,
const MQTTAgentCommandInfo_t * pCommandInfo );
/* @[declare_mqtt_agent_terminate] */
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* CORE_MQTT_AGENT_H */

View File

@@ -0,0 +1,269 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_agent_command_functions.h
* @brief Functions for processing an MQTT agent command.
*/
#ifndef CORE_MQTT_AGENT_COMMAND_FUNCTIONS_H
#define CORE_MQTT_AGENT_COMMAND_FUNCTIONS_H
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* MQTT Agent include. */
#include "core_mqtt_agent.h"
/**
* @brief An array of function pointers mapping command types to a function to
* execute. Configurable to allow a linker to remove unneeded functions.
*
* @note This array controls the behavior of each command. Altering the array
* would allow a linker to discard unused MQTT functions if desired. The size
* of this array MUST equal #NUM_COMMANDS and the order MUST correspond to
* #MQTTAgentCommandType_t commands if not using C99 designated initializers. If any
* function is desired not to be linked, it may be set to #MQTTAgentCommand_ProcessLoop
* or a custom function matching an #MQTTAgentCommandFunc_t prototype.
*
* <b>Default value:</b> @code{c}
* {
* [ NONE ] = MQTTAgentCommand_ProcessLoop,
* [ PROCESSLOOP ] = MQTTAgentCommand_ProcessLoop,
* [ PUBLISH ] = MQTTAgentCommand_Publish,
* [ SUBSCRIBE ] = MQTTAgentCommand_Subscribe,
* [ UNSUBSCRIBE ] = MQTTAgentCommand_Unsubscribe,
* [ PING ] = MQTTAgentCommand_Ping,
* [ CONNECT ] = MQTTAgentCommand_Connect,
* [ DISCONNECT ] = MQTTAgentCommand_Disconnect,
* [ TERMINATE ] = MQTTAgentCommand_Terminate
* }
* @endcode
*/
#ifndef MQTT_AGENT_FUNCTION_TABLE
/* Designated initializers are only in C99+. */
#if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L )
#define MQTT_AGENT_FUNCTION_TABLE \
{ \
[ NONE ] = MQTTAgentCommand_ProcessLoop, \
[ PROCESSLOOP ] = MQTTAgentCommand_ProcessLoop, \
[ PUBLISH ] = MQTTAgentCommand_Publish, \
[ SUBSCRIBE ] = MQTTAgentCommand_Subscribe, \
[ UNSUBSCRIBE ] = MQTTAgentCommand_Unsubscribe, \
[ PING ] = MQTTAgentCommand_Ping, \
[ CONNECT ] = MQTTAgentCommand_Connect, \
[ DISCONNECT ] = MQTTAgentCommand_Disconnect, \
[ TERMINATE ] = MQTTAgentCommand_Terminate \
}
#else /* if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) */
/* If not using designated initializers, this must correspond
* to the order of MQTTAgentCommandType_t commands. */
#define MQTT_AGENT_FUNCTION_TABLE \
{ \
MQTTAgentCommand_ProcessLoop, \
MQTTAgentCommand_ProcessLoop, \
MQTTAgentCommand_Publish, \
MQTTAgentCommand_Subscribe, \
MQTTAgentCommand_Unsubscribe, \
MQTTAgentCommand_Ping, \
MQTTAgentCommand_Connect, \
MQTTAgentCommand_Disconnect, \
MQTTAgentCommand_Terminate \
}
#endif /* if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) */
#endif /* ifndef MQTT_AGENT_FUNCTION_TABLE */
/*-----------------------------------------------------------*/
/**
* @ingroup mqtt_agent_struct_types
* @brief A structure of values and flags expected to be returned
* by command functions.
*/
typedef struct MQTTAgentCommandFuncReturns
{
uint16_t packetId; /**< @brief Packet ID of packet sent by command. */
bool endLoop; /**< @brief Flag to indicate command loop should terminate. */
bool addAcknowledgment; /**< @brief Flag to indicate an acknowledgment should be tracked. */
bool runProcessLoop; /**< @brief Flag to indicate MQTT_ProcessLoop() should be called after this command. */
} MQTTAgentCommandFuncReturns_t;
/**
* @brief Function prototype for a command.
*
* @note These functions should only be called from within
* #MQTTAgent_CommandLoop.
*
* @param[in] pMqttAgentContext MQTT Agent context.
* @param[in] pArgs Arguments for the command.
* @param[out] pFlags Return flags set by the function.
*
* @return Return code of MQTT call.
*/
typedef MQTTStatus_t (* MQTTAgentCommandFunc_t ) ( MQTTAgentContext_t * pMqttAgentContext,
void * pArgs,
MQTTAgentCommandFuncReturns_t * pFlags );
/*-----------------------------------------------------------*/
/**
* @brief Function to execute for a NONE command. This function does not call
* #MQTT_ProcessLoop itself, but instead sets a flag to indicate it should be called.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.runProcessLoop
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pUnusedArg Unused NULL argument.
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return #MQTTSuccess.
*/
MQTTStatus_t MQTTAgentCommand_ProcessLoop( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for a PUBLISH command.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.runProcessLoop
* - MQTTAgentCommandFuncReturns_t.addAcknowledgment (for QoS > 0)
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pPublishArg Publish information for MQTT_Publish().
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return Status code of MQTT_Publish().
*/
MQTTStatus_t MQTTAgentCommand_Publish( MQTTAgentContext_t * pMqttAgentContext,
void * pPublishArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for a SUBSCRIBE command.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.runProcessLoop
* - MQTTAgentCommandFuncReturns_t.addAcknowledgment
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pVoidSubscribeArgs Arguments for MQTT_Subscribe().
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return Status code of MQTT_Subscribe().
*/
MQTTStatus_t MQTTAgentCommand_Subscribe( MQTTAgentContext_t * pMqttAgentContext,
void * pVoidSubscribeArgs,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for an UNSUBSCRIBE command.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.runProcessLoop
* - MQTTAgentCommandFuncReturns_t.addAcknowledgment
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pVoidSubscribeArgs Arguments for MQTT_Unsubscribe().
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return Status code of MQTT_Unsubscribe().
*/
MQTTStatus_t MQTTAgentCommand_Unsubscribe( MQTTAgentContext_t * pMqttAgentContext,
void * pVoidSubscribeArgs,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for a CONNECT command.
*
* This sets all return flags to `false`.
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pVoidConnectArgs Arguments for MQTT_Connect().
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return Status code of MQTT_Connect().
*/
MQTTStatus_t MQTTAgentCommand_Connect( MQTTAgentContext_t * pMqttAgentContext,
void * pVoidConnectArgs,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for a DISCONNECT command.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.endLoop
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pUnusedArg Unused NULL argument.
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return Status code of MQTT_Disconnect().
*/
MQTTStatus_t MQTTAgentCommand_Disconnect( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for a PING command.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.runProcessLoop
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pUnusedArg Unused NULL argument.
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return Status code of MQTT_Ping().
*/
MQTTStatus_t MQTTAgentCommand_Ping( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/**
* @brief Function to execute for a TERMINATE command. Calls #MQTTAgent_CancelAll
* to terminate all unfinished commands with #MQTTRecvFailed.
*
* This sets the following flags to `true`:
* - MQTTAgentCommandFuncReturns_t.endLoop
*
* @param[in] pMqttAgentContext MQTT Agent context information.
* @param[in] pUnusedArg Unused NULL argument.
* @param[out] pReturnFlags Flags set to indicate actions the MQTT agent should take.
*
* @return #MQTTSuccess.
*/
MQTTStatus_t MQTTAgentCommand_Terminate( MQTTAgentContext_t * pMqttAgentContext,
void * pUnusedArg,
MQTTAgentCommandFuncReturns_t * pReturnFlags );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* CORE_MQTT_AGENT_COMMAND_FUNCTIONS_H */

View File

@@ -0,0 +1,119 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_agent_config_defaults.h
* @brief This represents the default values for the configuration macros
* for the MQTT-Agent library.
*
* @note This file SHOULD NOT be modified. If custom values are needed for
* any configuration macro, a core_mqtt_agent_config.h file should be provided to
* the MQTT-Agent library to override the default values defined in this file.
* To use the custom config file, the MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG
* preprocessor macro SHOULD NOT be set.
*/
#ifndef CORE_MQTT_AGENT_CONFIG_DEFAULTS_H_
#define CORE_MQTT_AGENT_CONFIG_DEFAULTS_H_
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG allows building the MQTT library
* without a custom config. If a custom config is provided, the
* MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG macro should be defined. */
#ifndef MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "core_mqtt_agent_config.h"
#endif
/* The macro definition for MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG is for Doxygen
* documentation only. */
/**
* @brief Define this macro to build the MQTT library without the custom config
* file core_mqtt_agent_config.h.
*
* Without the custom config, the MQTT library builds with
* default values of config macros defined in core_mqtt_agent_config_defaults.h file.
*
* If a custom config is provided, then MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG should
* be defined.
*/
#ifdef DOXYGEN
#define MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG
#endif
/**
* @brief The maximum number of pending acknowledgments to track for a single
* connection.
*
* @note The MQTT agent tracks MQTT commands (such as PUBLISH and SUBSCRIBE) th
* at are still waiting to be acknowledged. MQTT_AGENT_MAX_OUTSTANDING_ACKS set
* the maximum number of acknowledgments that can be outstanding at any one time.
* The higher this number is the greater the agent's RAM consumption will be.
*
* <b>Possible values:</b> Any positive integer up to SIZE_MAX. <br>
* <b>Default value:</b> `20`
*/
#ifndef MQTT_AGENT_MAX_OUTSTANDING_ACKS
#define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U )
#endif
/**
* @brief Time in milliseconds that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop().
*
* @note It is important MQTT_ProcessLoop() is called often if there is known
* MQTT traffic, but calling it too often can take processing time away from
* lower priority tasks and waste CPU time and power.
*
* <b>Possible values:</b> Any positive 32 bit integer. <br>
* <b>Default value:</b> `1000`
*/
#ifndef MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME
#define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000U )
#endif
/**
* @brief Whether the agent should configure the coreMQTT library to be used with publishes
* greater than QoS0. Setting this to 0 will disallow the coreMQTT library to send publishes
* with QoS > 0.
*
* <b>Possible values:</b> 0 or 1 <br>
* <b>Default value:</b> `1`
*/
#ifndef MQTT_AGENT_USE_QOS_1_2_PUBLISH
#define MQTT_AGENT_USE_QOS_1_2_PUBLISH ( 1 )
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* ifndef CORE_MQTT_AGENT_CONFIG_DEFAULTS_H_ */

View File

@@ -0,0 +1,129 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_agent_default_logging.h
* @brief This represents the default values for the logging macros for the MQTT-Agent
* library.
*
* @note This file SHOULD NOT be modified. If custom values are needed for
* any configuration macro, a core_mqtt_agent_config.h file should be provided to
* the MQTT-Agent library to override the default values defined in this file.
* To use the custom config file, the MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG preprocessor
* macro SHOULD NOT be set.
*/
#ifndef CORE_MQTT_AGENT_DEFAULT_LOGGING_H_
#define CORE_MQTT_AGENT_DEFAULT_LOGGING_H_
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* @brief Macro that is called in the MQTT-Agent library for logging "Error" level
* messages.
*
* To enable error level logging in the MQTT-Agent library, this macro should be mapped to the
* application-specific logging implementation that supports error logging.
*
* @note This logging macro is called in the MQTT-Agent library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
*
* <b>Default value</b>: Error logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogError
#define LogError( message )
#endif
/**
* @brief Macro that is called in the MQTT-Agent library for logging "Warning" level messages.
*
* To enable warning level logging in the MQTT-Agent library, this macro should be mapped to the
* application-specific logging implementation that supports warning logging.
*
* @note This logging macro is called in the MQTT-Agent library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Warning logs are turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogWarn
#define LogWarn( message )
#endif
/**
* @brief Macro that is called in the MQTT-Agent library for logging "Info" level
* messages.
*
* To enable info level logging in the MQTT-Agent library, this macro should be mapped to the
* application-specific logging implementation that supports info logging.
*
* @note This logging macro is called in the MQTT-Agent library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Info logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogInfo
#define LogInfo( message )
#endif
/**
* @brief Macro that is called in the MQTT-Agent library for logging "Debug" level
* messages.
*
* To enable debug level logging from MQTT-Agent library, this macro should be mapped to the
* application-specific logging implementation that supports debug logging.
*
* @note This logging macro is called in the MQTT-Agent library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Debug logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogDebug
#define LogDebug( message )
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* ifndef CORE_MQTT_AGENT_DEFAULT_LOGGING_H_ */

View File

@@ -0,0 +1,148 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_agent_message_interface.h
* @brief Functions to interact with queues.
*/
#ifndef CORE_MQTT_AGENT_MESSAGE_INTERFACE_H
#define CORE_MQTT_AGENT_MESSAGE_INTERFACE_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Declare here so interface functions can use. */
struct MQTTAgentCommand;
struct MQTTAgentMessageContext;
/**
* @brief The commands sent from the APIs to the MQTT agent task.
*/
typedef struct MQTTAgentCommand MQTTAgentCommand_t;
/**
* @ingroup mqtt_agent_struct_types
* @brief Context with which tasks may deliver messages to the agent.
*/
/* @[define_messagectx] */
typedef struct MQTTAgentMessageContext MQTTAgentMessageContext_t;
/* @[define_messagectx] */
/**
* @brief Send a message to the specified context.
* Must be thread safe.
*
* @param[in] pMsgCtx An #MQTTAgentMessageContext_t.
* @param[in] pCommandToSend Pointer to address to send to queue.
* @param[in] blockTimeMs Block time to wait for a send.
*
* @return `true` if send was successful, else `false`.
*/
/* @[define_messagesend] */
typedef bool ( * MQTTAgentMessageSend_t )( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t * const * pCommandToSend,
uint32_t blockTimeMs );
/* @[define_messagesend] */
/**
* @brief Receive a message from the specified context.
* Must be thread safe.
*
* @param[in] pMsgCtx An #MQTTAgentMessageContext_t.
* @param[out] pReceivedCommand Pointer to write address of received command.
* @param[in] blockTimeMs Block time to wait for a receive.
*
* @return `true` if receive was successful, else `false`.
*/
/* @[define_messagerecv] */
typedef bool ( * MQTTAgentMessageRecv_t )( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t ** pReceivedCommand,
uint32_t blockTimeMs );
/* @[define_messagerecv] */
/**
* @brief Obtain a MQTTAgentCommand_t structure.
*
* @note MQTTAgentCommand_t structures hold everything the MQTT agent needs to process a
* command that originates from application. Examples of commands are PUBLISH and
* SUBSCRIBE. The MQTTAgentCommand_t structure must persist for the duration of the command's
* operation.
*
* @param[in] blockTimeMs The length of time the calling task should remain in the
* Blocked state (so not consuming any CPU time) to wait for a MQTTAgentCommand_t structure to
* become available should one not be immediately at the time of the call.
*
* @return A pointer to a MQTTAgentCommand_t structure if one becomes available before
* blockTimeMs time expired, otherwise NULL.
*/
/* @[define_messageget] */
typedef MQTTAgentCommand_t * ( * MQTTAgentCommandGet_t )( uint32_t blockTimeMs );
/* @[define_messageget] */
/**
* @brief Give a MQTTAgentCommand_t structure back to the application.
*
* @note MQTTAgentCommand_t structures hold everything the MQTT agent needs to process a
* command that originates from application. Examples of commands are PUBLISH and
* SUBSCRIBE. The MQTTAgentCommand_t structure must persist for the duration of the command's
* operation.
*
* @param[in] pCommandToRelease A pointer to the MQTTAgentCommand_t structure to return to
* the application. The structure must first have been obtained by calling
* an #MQTTAgentCommandGet_t, otherwise it will have no effect.
*
* @return true if the MQTTAgentCommand_t structure was returned to the application, otherwise false.
*/
/* @[define_messagerelease] */
typedef bool ( * MQTTAgentCommandRelease_t )( MQTTAgentCommand_t * pCommandToRelease );
/* @[define_messagerelease] */
/**
* @ingroup mqtt_agent_struct_types
* @brief Function pointers and contexts used for sending and receiving commands,
* and allocating memory for them.
*/
/* @[define_messageinterface] */
typedef struct MQTTAgentMessageInterface
{
MQTTAgentMessageContext_t * pMsgCtx; /**< Context with which tasks may deliver messages to the agent. */
MQTTAgentMessageSend_t send; /**< Function to send a command to the agent. */
MQTTAgentMessageRecv_t recv; /**< Function for the agent to receive a command. */
MQTTAgentCommandGet_t getCommand; /**< Function to obtain a pointer to an allocated command. */
MQTTAgentCommandRelease_t releaseCommand; /**< Function to release an allocated command. */
} MQTTAgentMessageInterface_t;
/* @[define_messageinterface] */
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* CORE_MQTT_AGENT_MESSAGE_INTERFACE_H */

View File

@@ -0,0 +1,110 @@
cmake_minimum_required ( VERSION 3.22.0 )
project ( "MQTTAgent tests"
VERSION 1.3.1
LANGUAGES C )
# Allow the project to be organized into folders.
set_property( GLOBAL PROPERTY USE_FOLDERS ON )
# Use C90 if not specified.
if( NOT DEFINED CMAKE_C_STANDARD )
set( CMAKE_C_STANDARD 90 )
endif()
if( NOT DEFINED CMAKE_C_STANDARD_REQUIRED )
set( CMAKE_C_STANDARD_REQUIRED ON )
endif()
# If no configuration is defined, turn everything on.
if( NOT DEFINED COV_ANALYSIS AND NOT DEFINED UNITTEST )
set( COV_ANALYSIS TRUE )
set( UNITTEST TRUE )
endif()
# Do not allow in-source build.
if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
endif()
# Set global path variables.
get_filename_component(__MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
set(MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "coreMQTT-Agent repository root.")
# Configure options to always show in CMake GUI.
option( BUILD_CLONE_SUBMODULES
"Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned."
OFF )
# Set output directories.
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
# ===================================== Coverity Analysis Configuration =================================================
if( COV_ANALYSIS )
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )
# Target for Coverity analysis that builds the library.
add_library( coverity_analysis
${MQTT_AGENT_SOURCES}
${MQTT_SOURCES}
${MQTT_SERIALIZER_SOURCES} )
# Build MQTT library target without custom config dependency.
target_compile_definitions( coverity_analysis PUBLIC MQTT_DO_NOT_USE_CUSTOM_CONFIG=1 MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG=1 )
# MQTT AGENT public include path.
target_include_directories( coverity_analysis PUBLIC ${MQTT_AGENT_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} )
# Remove inclusion of assert.
add_compile_definitions( NDEBUG=1 )
endif()
# ==================================== Test Configuration ========================================
if( UNITTEST )
# Define a CMock resource path.
set( CMOCK_DIR ${MODULE_ROOT_DIR}/test/unit-test/CMock CACHE INTERNAL "CMock library source directory." )
# Include CMock build configuration.
include( unit-test/cmock_build.cmake )
# Check if the CMock source directory exists, and if not present, clone the submodule
# if BUILD_CLONE_SUBMODULES configuration is enabled.
if( NOT EXISTS ${CMOCK_DIR}/src )
# Attempt to clone CMock.
if( ${BUILD_CLONE_SUBMODULES} )
clone_cmock()
else()
message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set\
BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
endif()
endif()
# Add unit test and coverage configuration.
# Use CTest utility for managing test runs. This has to be added BEFORE
# defining test targets with add_test()
enable_testing()
# Add build targets for CMock and Unit, required for unit testing.
add_cmock_targets()
# Add function to enable CMock based tests and coverage.
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/tools/cmock/create_test.cmake )
# Include build configuration for unit tests.
add_subdirectory( unit-test )
# ==================================== Coverage Analysis configuration ========================================
# Add a target for running coverage on tests.
add_custom_target( coverage
COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR}
-P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake
DEPENDS cmock unity mqtt_agent_utest mqtt_agent_command_functions_utest
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()

View File

@@ -0,0 +1,24 @@
# Emitted when running CBMC proofs
proofs/**/logs
proofs/**/gotos
proofs/**/report
proofs/**/html
proofs/output
# Emitted by CBMC Viewer
TAGS-*
# Emitted by Arpa
arpa_cmake/
arpa-validation-logs/
Makefile.arpa
# Emitted by litani
.ninja_deps
.ninja_log
.litani_cache_dir
# These files should be overwritten whenever prepare.py runs
cbmc-batch.yaml
__pycache__/

View File

@@ -0,0 +1,6 @@
CBMC proof include files
========================
This directory contains include files written for CBMC proof. It is
common to write some code to model aspects of the system under test,
and the header files for this code go here.

View File

@@ -0,0 +1,61 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file agent_command_pool_stubs.h
* @brief Stub functions to get and release command structure from a command pool.
*/
#ifndef AGENT_COMMAND_POOL_STUBS_H
#define AGENT_COMMAND_POOL_STUBS_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/* core_mqtt_agent.h must precede including this header. */
/**
* @brief Send a message to the specified context.
*
* @param[in] blockTimeMs The length of time the calling task should remain in the
* Blocked state (so not consuming any CPU time) to wait for a MQTTAgentCommand_t structure to
* become available should one not be immediately at the time of the call.
*
* @return A pointer to a MQTTAgentCommand_t structure if one becomes available before
* blockTimeMs time expired, otherwise NULL.
*/
MQTTAgentCommand_t * AgentGetCommandStub( uint32_t blockTimeMs );
/**
* @brief Receive a message from the specified context.
* Must be thread safe.
*
* @param[in] pCommandToRelease A pointer to the MQTTAgentCommand_t structure to return to
* the pool. The structure must first have been obtained by calling
* Agent_GetCommand(), otherwise Agent_ReleaseCommand() will
* have no effect.
*
* @return true if the MQTTAgentCommand_t structure was returned to the pool, otherwise false.
*/
bool Agent_ReleaseCommand( MQTTAgentCommand_t * pCommandToRelease );
#endif /* AGENT_COMMAND_POOL_STUBS_H */

View File

@@ -0,0 +1,63 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file agent_message_stubs.h
* @brief Stub functions to interact with queues.
*/
#ifndef AGENT_MESSAGE_STUBS_H
#define AGENT_MESSAGE_STUBS_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/* core_mqtt_agent.h must precede including this header. */
/**
* @brief Send a message to the specified context.
*
* @param[in] pMsgCtx An #MQTTAgentMessageContext_t.
* @param[in] pData Pointer to element to send to queue.
* @param[in] blockTimeMs Block time to wait for a send.
*
* @return `true` if send was successful, else `false`.
*/
bool AgentMessageSendStub( MQTTAgentMessageContext_t * pMsgCtx,
const void * pData,
uint32_t blockTimeMs );
/**
* @brief Receive a message from the specified context.
* Must be thread safe.
*
* @param[in] pMsgCtx An #MQTTAgentMessageContext_t.
* @param[in] pBuffer Pointer to buffer to write received data.
* @param[in] blockTimeMs Block time to wait for a receive.
*
* @return `true` if receive was successful, else `false`.
*/
bool AgentMessageRecvStub( MQTTAgentMessageContext_t * pMsgCtx,
void * pBuffer,
uint32_t blockTimeMs );
#endif /* AGENT_MESSAGE_STUBS_H */

View File

@@ -0,0 +1,2 @@
/* An empty config file for the CBMC proofs to compile with the default
* definitions of configuration macros. */

View File

@@ -0,0 +1,91 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_mqtt_config.h
* @brief This header sets configuration macros for the MQTT library.
*/
#ifndef CORE_MQTT_CONFIG_H_
#define CORE_MQTT_CONFIG_H_
/* Mock a network context for the CBMC proofs. */
struct NetworkContext
{
int NetworkContext;
};
/**
* @brief Determines the maximum number of MQTT PUBLISH messages, pending
* acknowledgement at a time, that are supported for incoming and outgoing
* direction of messages, separately.
*
* QoS 1 and 2 MQTT PUBLISHes require acknowledgement from the server before
* they can be completed. While they are awaiting the acknowledgement, the
* client must maintain information about their state. The value of this
* macro sets the limit on how many simultaneous PUBLISH states an MQTT
* context maintains, separately, for both incoming and outgoing direction of
* PUBLISHes.
*
* @note This definition must exist in order to compile. 10U is a typical value
* used in the MQTT demos.
*/
#define MQTT_STATE_ARRAY_MAX_COUNT ( 10U )
/**
* @brief Retry count for reading CONNACK from network.
*
* The MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT will be used only when the
* timeoutMs parameter of #MQTT_Connect() is passed as 0 . The transport
* receive for CONNACK will be retried MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT
* times before timing out. A value of 0 for this config will cause the
* transport receive for CONNACK to be invoked only once.
*/
#define MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT ( 2U )
/**
* @brief Number of milliseconds to wait for a ping response to a ping
* request as part of the keep-alive mechanism.
*
* If a ping response is not received before this timeout, then
* #MQTT_ProcessLoop will return #MQTTKeepAliveTimeout.
*/
#define MQTT_PINGRESP_TIMEOUT_MS ( 500U )
/**
* @brief The maximum duration of receiving no data over network when
* attempting to read an incoming MQTT packet by the #MQTT_ProcessLoop or
* #MQTT_ReceiveLoop API functions.
*
* When an incoming MQTT packet is detected, the transport receive function
* may be called multiple times until all the expected number of bytes for the
* packet are received. This timeout represents the maximum duration of polling
* for any data to be received over the network for the incoming.
* If the timeout expires, the #MQTT_ProcessLoop or #MQTT_ReceiveLoop functions
* return #MQTTRecvFailed.
*
* This is set to 1 to exit right away after a zero is received in the transport
* receive stub. There is no added value, in proving memory safety, to repeat
* the logic that checks if the polling timeout is reached.
*/
#define MQTT_RECV_POLLING_TIMEOUT_MS ( 1U )
#endif /* ifndef CORE_MQTT_CONFIG_H_ */

View File

@@ -0,0 +1,38 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file get_time_stub.h
* @brief Stub definition for the application defined callback to retrieve the
* current time in milliseconds.
*/
#ifndef GET_TIME_STUB_H_
#define GET_TIME_STUB_H_
/**
* Application defined callback to retrieve the current time in milliseconds.
*
* @return The current time in milliseconds.
*/
uint32_t GetCurrentTimeStub( void );
#endif /* ifndef GET_TIME_STUB_H_ */

View File

@@ -0,0 +1,44 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file incoming_publish_callback_stub.h
* @brief Stub definition for the application defined MQTT library incoming
* publish callback.
*/
#ifndef INCOMING_PUBLISH_CALLBACK_STUB_H_
#define INCOMING_PUBLISH_CALLBACK_STUB_H_
/* core_mqtt_agent.h must precede including this header. */
/**
* @brief Callback function called when receiving a publish.
*
* @param[in] pMqttAgentContext The context of the MQTT agent.
* @param[in] packetId The packet ID of the received publish.
* @param[in] pPublishInfo Deserialized publish information.
*/
void IncomingPublishCallbackStub( MQTTAgentContext_t * pContext,
uint16_t packetId,
MQTTPublishInfo_t * pPublishInfo );
#endif /* ifndef INCOMING_PUBLISH_CALLBACK_STUB_H_ */

View File

@@ -0,0 +1,120 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file mqtt_agent_cbmc_state.h
* @brief Allocation and assumption utilities for the MQTT Agent library CBMC proofs.
*/
#ifndef MQTT_AGENT_CBMC_STATE_H_
#define MQTT_AGENT_CBMC_STATE_H_
#include <stdbool.h>
/* core_mqtt_agent.h must precede including this header. */
/**
* @brief Allocate a #MQTTFixedBuffer_t object.
*
* @param[in] pBuffer #MQTTFixedBuffer_t object information.
*
* @return NULL or allocated #MQTTFixedBuffer_t memory.
*/
MQTTFixedBuffer_t * allocateMqttFixedBuffer( MQTTFixedBuffer_t * pFixedBuffer );
/**
* @brief Validate a #MQTTFixedBuffer_t object.
*
* @param[in] pBuffer #MQTTFixedBuffer_t object to validate.
*
* @return True if the #MQTTFixedBuffer_t object is valid, false otherwise.
*
* @note A NULL object is a valid object. This is for coverage of the NULL
* parameter checks in the function under proof.
*/
bool isValidMqttFixedBuffer( const MQTTFixedBuffer_t * pFixedBuffer );
/**
* @brief Allocate a #MQTTAgentContext_t object.
*
* @param[in] pContext #MQTTAgentContext_t object information.
*
* @return NULL or allocated #MQTTAgentContext_t memory.
*/
MQTTAgentContext_t * allocateMqttAgentContext( MQTTAgentContext_t * pContext );
/**
* @brief Validate a #MQTTAgentContext_t object.
*
* @param[in] pContext #MQTTAgentContext_t object to validate.
*
* @return True if the #MQTTAgentContext_t object is valid, false otherwise.
*
* @note A NULL object is a valid object. This is for coverage of the NULL
* parameter checks in the function under proof.
*/
bool isValidMqttAgentContext( const MQTTAgentContext_t * pContext );
/**
* @brief Function to check if the status is a valid status for the MQTT Agent
* functions that send a command to the queue. The functions are:
* - MQTTAgent_Connect
* - MQTTAgent_Disconnect
* - MQTTAgent_Subscribe
* - MQTTAgent_Unsubscribe
* - MQTTAgent_Ping
* - MQTTAgent_Publish
* - MQTTAgent_ProcessLoop
* - MQTTAgent_Terminate
*
* @param[in] mqttStatus MQTT status to check if it is a valid MQTTAgent_Connect
* status.
*
* @return true if an MQTTAgent_Connect status, false otherwise.
*/
bool isAgentSendCommandFunctionStatus( MQTTStatus_t mqttStatus );
/**
* @brief Allocate a #MQTTAgentConnectArgs_t object.
*
* @param[in] pConnectArgs #MQTTAgentConnectArgs_t object information.
*
* @return NULL or allocated #MQTTAgentConnectArgs_t memory.
*/
MQTTAgentConnectArgs_t * allocateConnectArgs( MQTTAgentConnectArgs_t * pConnectArgs );
/**
* @brief Add Pending ACKs to the MQTTAgentContext.
*
* @param[in] pContext #MQTTAgentContext_t object to add ACKs.
*/
void addPendingAcks( MQTTAgentContext_t * pContext );
/**
* @brief Allocate a #MQTTAgentSubscribeArgs_t object.
*
* @param[in] pSubscribeArgs #MQTTAgentSubscribeArgs_t object information.
*
* @return NULL or allocated #MQTTAgentSubscribeArgs_t memory.
*/
MQTTAgentSubscribeArgs_t * allocateSubscribeArgs( MQTTAgentSubscribeArgs_t * pSubscribeArgs );
#endif /* ifndef MQTT_AGENT_CBMC_STATE_H_ */

View File

@@ -0,0 +1,59 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file network_interface_stubs.h
* @brief Stub definitions for the application defined transport interface send
* and receive callback.
*/
#ifndef NETWORK_INTERFACE_STUBS_H_
#define NETWORK_INTERFACE_STUBS_H_
/* transport_interface.h must precede including this header. */
/**
* @brief Application defined network interface receive function.
*
* @param[in] pNetworkContext Application defined network interface context.
* @param[out] pBuffer MQTT network receive buffer.
* @param[in] bytesToRecv MQTT requested bytes.
*
* @return Any value from INT32_MIN to INT32_MAX.
*/
int32_t NetworkInterfaceReceiveStub( NetworkContext_t * pNetworkContext,
void * pBuffer,
size_t bytesToRecv );
/**
* @brief Application defined network interface send function.
*
* @param[in] pNetworkContext Application defined network interface context.
* @param[out] pBuffer MQTT network send buffer.
* @param[in] bytesToSend Number of bytes to send over the network.
*
* @return Any value from INT32_MIN to INT32_MAX.
*/
int32_t NetworkInterfaceSendStub( NetworkContext_t * pNetworkContext,
const void * pBuffer,
size_t bytesToSend );
#endif /* ifndef NETWORK_INTERFACE_STUBS_H_ */

View File

@@ -0,0 +1,45 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Connect_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Connect function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
MQTTAgentConnectArgs_t * pConnectArgs;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
pConnectArgs = allocateConnectArgs( NULL );
__CPROVER_assume( pConnectArgs != NULL );
MQTTAgentCommand_Connect( pMqttAgentContext, pConnectArgs, pReturnFlags );
}

View File

@@ -0,0 +1,21 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Connect_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Connect
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Connect proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Connect.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Connect()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Connect",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,43 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Disconnect_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Disconnect function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
MQTTAgentCommand_Disconnect( pMqttAgentContext, NULL, pReturnFlags );
}

View File

@@ -0,0 +1,20 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Disconnect_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Disconnect
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Disconnect proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Disconnect.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Disconnect()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Disconnect",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,42 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Ping_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Ping function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
MQTTAgentCommand_Ping( pMqttAgentContext, NULL, pReturnFlags );
}

View File

@@ -0,0 +1,20 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Ping_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Ping
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Ping proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Ping.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Ping()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Ping",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,42 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_ProcessLoop_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_ProcessLoop function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
MQTTAgentCommand_ProcessLoop( pMqttAgentContext, NULL, pReturnFlags );
}

View File

@@ -0,0 +1,20 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_ProcessLoop_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_ProcessLoop
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_ProcessLoop proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_ProcessLoop.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_ProcessLoop()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_ProcessLoop",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,45 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Publish_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Publish function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
MQTTPublishInfo_t * pPublishArg;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
pPublishArg = malloc( sizeof( MQTTPublishInfo_t ) );
__CPROVER_assume( pPublishArg != NULL );
MQTTAgentCommand_Publish( pMqttAgentContext, pPublishArg, pReturnFlags );
}

View File

@@ -0,0 +1,20 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Publish_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Publish
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Publish proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Publish.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Publish()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Publish",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,45 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Subscribe_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Subscribe function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
MQTTAgentSubscribeArgs_t * pSubscribeArgs;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
pSubscribeArgs = allocateSubscribeArgs( NULL );
MQTTAgentCommand_Subscribe( pMqttAgentContext, pSubscribeArgs, pReturnFlags );
}

View File

@@ -0,0 +1,21 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Subscribe_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Subscribe
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Subscribe proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Subscribe.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Subscribe()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Subscribe",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,49 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Terminate_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Terminate function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
pMqttAgentContext = allocateMqttAgentContext( NULL );
__CPROVER_assume( pMqttAgentContext != NULL );
__CPROVER_assume( pMqttAgentContext->agentInterface.releaseCommand != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
if( pMqttAgentContext != NULL )
{
addPendingAcks( pMqttAgentContext );
}
MQTTAgentCommand_Terminate( pMqttAgentContext, NULL, pReturnFlags );
}

View File

@@ -0,0 +1,42 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Terminate_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Terminate
# MQTT_AGENT_MAX_OUTSTANDING_ACKS set the maximum number of acknowledgments
# that can be outstanding at any one time. A small number 2 will be enough
# for proving the memory safety and making the proofs run faster.
MQTT_AGENT_MAX_OUTSTANDING_ACKS=2
MAX_BOUND_FOR_RECEIVE_COMMAND_LOOP=2
# Bound for loop unwinding for the loops trying to read and write into the
# outstanding acks array. The size of the array is determined by
# MQTT_AGENT_MAX_OUTSTANDING_ACKS. The max bound will be one more than
# array size for the proofs.
MAX_BOUND_FOR_PENDING_ACK_LOOPS=$(shell expr $(MQTT_AGENT_MAX_OUTSTANDING_ACKS) + 1 )
DEFINES += -DMQTT_AGENT_MAX_OUTSTANDING_ACKS=$(MQTT_AGENT_MAX_OUTSTANDING_ACKS)
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY += MQTTAgent_CancelAll
UNWINDSET += addPendingAcks.0:$(MAX_BOUND_FOR_PENDING_ACK_LOOPS)
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/incoming_publish_callback_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_command_pool_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_message_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/core_mqtt_stubs.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Terminate proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Terminate.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Terminate()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Terminate",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,45 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgentCommand_Unsubscribe_harness.c
* @brief Implements the proof harness for MQTTAgentCommand_Unsubscribe function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent_command_functions.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandFuncReturns_t * pReturnFlags;
MQTTAgentSubscribeArgs_t * pSubscribeArgs;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
__CPROVER_assume( pMqttAgentContext != NULL );
pReturnFlags = malloc( sizeof( MQTTAgentCommandFuncReturns_t ) );
__CPROVER_assume( pReturnFlags != NULL );
pSubscribeArgs = allocateSubscribeArgs( NULL );
MQTTAgentCommand_Unsubscribe( pMqttAgentContext, pSubscribeArgs, pReturnFlags );
}

View File

@@ -0,0 +1,21 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgentCommand_Unsubscribe_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgentCommand_Unsubscribe
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent_command_functions.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgentCommand_Unsubscribe proof
==============
This directory contains a memory safety proof for MQTTAgentCommand_Unsubscribe.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgentCommand_Unsubscribe()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgentCommand_Unsubscribe",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,44 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file MQTTAgent_CancelAll_harness.c
* @brief Implements the proof harness for MQTTAgent_CancelAll function.
*/
/* MQTT agent include. */
#include "core_mqtt_agent.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
pMqttAgentContext = allocateMqttAgentContext( NULL );
if( pMqttAgentContext != NULL )
{
addPendingAcks( pMqttAgentContext );
}
MQTTAgent_CancelAll( pMqttAgentContext );
}

View File

@@ -0,0 +1,43 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgent_CancelAll_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgent_CancelAll
# MQTT_AGENT_MAX_OUTSTANDING_ACKS set the maximum number of acknowledgments
# that can be outstanding at any one time. A small number 2 will be enough
# for proving the memory safety and making the proofs run faster.
MQTT_AGENT_MAX_OUTSTANDING_ACKS=2
MAX_BOUND_FOR_RECEIVE_COMMAND_LOOP=2
# Bound for loop unwinding for the loops trying to read and write into the
# outstanding acks array. The size of the array is determined by
# MQTT_AGENT_MAX_OUTSTANDING_ACKS. The max bound will be one more than
# array size for the proofs.
MAX_BOUND_FOR_PENDING_ACK_LOOPS=$(shell expr $(MQTT_AGENT_MAX_OUTSTANDING_ACKS) + 1 )
DEFINES += -DMQTT_AGENT_MAX_OUTSTANDING_ACKS=$(MQTT_AGENT_MAX_OUTSTANDING_ACKS)
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET += addPendingAcks.0:$(MAX_BOUND_FOR_PENDING_ACK_LOOPS)
UNWINDSET += MQTTAgent_CancelAll.0:$(MAX_BOUND_FOR_RECEIVE_COMMAND_LOOP)
UNWINDSET += MQTTAgent_CancelAll.1:$(MAX_BOUND_FOR_PENDING_ACK_LOOPS)
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/incoming_publish_callback_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_command_pool_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_message_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/core_mqtt_stubs.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent.c
include ../Makefile.common

View File

@@ -0,0 +1,23 @@
MQTTAgent_CancelAll proof
==============
This directory contains a memory safety proof for MQTTAgent_CancelAll.
The proof runs within 3 minutes on a t2.2xlarge. It provides complete coverage of:
* MQTTAgent_CancelAll()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgent_CancelAll",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,40 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* MQTT agent include. */
#include "core_mqtt_agent.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext = NULL;
pMqttAgentContext = allocateMqttAgentContext( pMqttAgentContext );
if( pMqttAgentContext != NULL )
{
pMqttAgentContext->mqttContext.connectStatus = MQTTConnected;
}
MQTTAgent_CommandLoop( pMqttAgentContext );
}

View File

@@ -0,0 +1,57 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgent_CommandLoop_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgent_CommandLoop
# MQTT_AGENT_MAX_OUTSTANDING_ACKS set the maximum number of acknowledgments
# that can be outstanding at any one time. A small number 2 will be enough
# for proving the memory safety and making the proofs run faster.
MQTT_AGENT_MAX_OUTSTANDING_ACKS=2
# Bound for loop unwinding for the loops trying to read and write into the
# outstanding acks array. The size of the array is determined by
# MQTT_AGENT_MAX_OUTSTANDING_ACKS. The max bound will be one more than
# array size for the proofs.
MAX_BOUND_FOR_PENDING_ACK_LOOPS=$(shell expr $(MQTT_AGENT_MAX_OUTSTANDING_ACKS) + 1 )
# Bound for loop unwinding for the main loop in MQTTAgent_CommandLoop. Unwinding
# the loop 3 times will be enough for proving memory safety.
MAX_BOUND_FOR_COMMAND_LOOP=3
# Bound for loop unwinding for loop in processCommand function. Unwinding
# the loop 2 times will be enough for proving memory safety.
MAX_BOUND_FOR_PROCESS_COMMAND_LOOP=2
# Force CBMC to only use the AgentMessageRecvStub function as the pointee of
# the recv function.
RESTRICT_FUNCTION_POINTER += MQTTAgent_CommandLoop.function_pointer_call.1/AgentMessageRecvStub
DEFINES += -DMQTT_AGENT_MAX_OUTSTANDING_ACKS=$(MQTT_AGENT_MAX_OUTSTANDING_ACKS)
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET += MQTTAgent_CommandLoop.0:$(MAX_BOUND_FOR_COMMAND_LOOP)
UNWINDSET += __CPROVER_file_local_core_mqtt_agent_c_addAwaitingOperation.0:$(MAX_BOUND_FOR_PENDING_ACK_LOOPS)
UNWINDSET += __CPROVER_file_local_core_mqtt_agent_c_getAwaitingOperation.0:$(MAX_BOUND_FOR_PENDING_ACK_LOOPS)
UNWINDSET += __CPROVER_file_local_core_mqtt_agent_c_processCommand.0:$(MAX_BOUND_FOR_PROCESS_COMMAND_LOOP)
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/incoming_publish_callback_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_command_pool_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_message_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_command_functions_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/core_mqtt_stubs.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent.c
include ../Makefile.common

View File

@@ -0,0 +1,51 @@
MQTTAgent_CommandLoop proof
==============
This directory contains a memory safety proof for MQTTAgent_CommandLoop.
The proof runs within 3 minutes on a t2.2xlarge. It provides complete coverage of:
* MQTTAgent_CommandLoop()
* MQTTAgent_Init()
* addAwaitingOperation()
* getAgentFromMQTTContext()
* getAwaitingOperation()
* handleAcks()
* mqttEventCallback()
For this proof, stubs are used for the implementation of functions in the following interfaces and
function types. Since the implementation for these functions will be provided by the applications,
the proof only will require stubs.
* MQTTAgentMessageInterface_t
* TransportInterface_t
* MQTTGetCurrentTimeFunc_t
* MQTTAgentIncomingPublishCallback_t
* MQTTAgentCommandCallback_t
In addition to the interfaces and the function types, stubs are used for the below listed functions.
CBMC proofs are written for these functions separately.
* MQTTAgentCommand_ProcessLoop()
* MQTTAgentCommand_Publish()
* MQTTAgentCommand_Subscribe()
* MQTTAgentCommand_Unsubscribe()
* MQTTAgentCommand_Connect()
* MQTTAgentCommand_Disconnect()
* MQTTAgentCommand_Ping()
* MQTTAgentCommand_Terminate()
* MQTT_ProcessLoop()
* MQTT_Init()
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgent_CommandLoop",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,47 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* MQTT agent include. */
#include "core_mqtt_agent.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentConnectArgs_t * pConnectArgs;
MQTTAgentCommandInfo_t * pCommandInfo;
MQTTStatus_t mqttStatus;
pMqttAgentContext = allocateMqttAgentContext( NULL );
__CPROVER_assume( isValidMqttAgentContext( pMqttAgentContext ) );
pConnectArgs = malloc( sizeof( MQTTAgentConnectArgs_t ) );
pCommandInfo = malloc( sizeof( MQTTAgentCommandInfo_t ) );
mqttStatus = MQTTAgent_Connect( pMqttAgentContext,
pConnectArgs,
pCommandInfo );
__CPROVER_assert( isAgentSendCommandFunctionStatus( mqttStatus ), "The return value is a MQTTStatus_t." );
}

View File

@@ -0,0 +1,29 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgent_Connect_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgent_Connect
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/incoming_publish_callback_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_command_pool_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_message_stubs.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent.c
PROJECT_SOURCES += $(SRCDIR)/source/dependency/coreMQTT/source/core_mqtt.c
PROJECT_SOURCES += $(SRCDIR)/source/dependency/coreMQTT/source/core_mqtt_serializer.c
include ../Makefile.common

View File

@@ -0,0 +1,35 @@
MQTTAgent_Connect proof
==============
This directory contains a memory safety proof for MQTTAgent_Connect.
The proof runs within 10 seconds on a t2.2xlarge. It provides complete coverage of:
* MQTTAgent_Connect()
* MQTTAgent_Init()
* addCommandToQueue()
* createAndAddCommand()
* validateStruct()
For this proof, stubs are used for the implementation of functions in the following interfaces and
function types. Since the implementation for these functions will be provided by the applications,
the proof only will require stubs.
* MQTTAgentMessageInterface_t
* TransportInterface_t
* MQTTGetCurrentTimeFunc_t
* MQTTAgentIncomingPublishCallback_t
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgent_Connect",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,40 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* MQTT agent include. */
#include "core_mqtt_agent.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandInfo_t * pCommandInfo;
pMqttAgentContext = allocateMqttAgentContext( NULL );
__CPROVER_assume( isValidMqttAgentContext( pMqttAgentContext ) );
pCommandInfo = malloc( sizeof( MQTTAgentCommandInfo_t ) );
MQTTAgent_Disconnect( pMqttAgentContext,
pCommandInfo );
}

View File

@@ -0,0 +1,29 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgent_Disconnect_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgent_Disconnect
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_agent_cbmc_state.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/incoming_publish_callback_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_command_pool_stubs.c
PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/agent_message_stubs.c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent.c
PROJECT_SOURCES += $(SRCDIR)/source/dependency/coreMQTT/source/core_mqtt.c
PROJECT_SOURCES += $(SRCDIR)/source/dependency/coreMQTT/source/core_mqtt_serializer.c
include ../Makefile.common

View File

@@ -0,0 +1,20 @@
MQTTAgent_Disconnect proof
==============
This directory contains a memory safety proof for MQTTAgent_Disconnect.
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgent_Disconnect",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,48 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* MQTT agent include. */
#include "core_mqtt_agent.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentMessageInterface_t * pMsgInterface;
MQTTFixedBuffer_t * pNetworkBuffer;
TransportInterface_t * pTransportInterface;
MQTTGetCurrentTimeFunc_t getCurrentTimeMs;
MQTTAgentIncomingPublishCallback_t incomingCallback;
void * pIncomingPacketContext;
pMqttAgentContext = malloc( sizeof( MQTTAgentContext_t ) );
pMsgInterface = malloc( sizeof( MQTTAgentMessageInterface_t ) );
pNetworkBuffer = malloc( sizeof( MQTTFixedBuffer_t ) );
pTransportInterface = malloc( sizeof( TransportInterface_t ) );
MQTTAgent_Init( pMqttAgentContext,
pMsgInterface,
pNetworkBuffer,
pTransportInterface,
getCurrentTimeMs,
incomingCallback,
pIncomingPacketContext );
}

View File

@@ -0,0 +1,21 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
HARNESS_ENTRY = harness
HARNESS_FILE = MQTTAgent_Init_harness
# This should be a unique identifier for this proof, and will appear on the
# Litani dashboard. It can be human-readable and contain spaces if you wish.
PROOF_UID = MQTTAgent_Init
DEFINES +=
INCLUDES +=
REMOVE_FUNCTION_BODY +=
UNWINDSET +=
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_agent.c
include ../Makefile.common

View File

@@ -0,0 +1,20 @@
MQTTAgent_Init proof
==============
This directory contains a memory safety proof for MQTTAgent_Init.
To run the proof.
-------------
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer`
to your path.
* Run `make`.
* Open html/index.html in a web browser.
To use [`arpa`](https://awslabs.github.io/aws-proof-build-assistant) to simplify writing Makefiles.
-------------
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof.
* Use Makefile.arpa as the starting point for your proof Makefile by:
1. Modifying Makefile.arpa (if required).
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`).

View File

@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.

View File

@@ -0,0 +1,7 @@
{ "expected-missing-functions":
[
],
"proof-name": "MQTTAgent_Init",
"proof-root": "test/cbmc/proofs"
}

View File

@@ -0,0 +1,45 @@
/*
* coreMQTT Agent <v1.3.1>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* MQTT agent include. */
#include "core_mqtt_agent.h"
#include "mqtt_agent_cbmc_state.h"
void harness()
{
MQTTAgentContext_t * pMqttAgentContext;
MQTTAgentCommandInfo_t * pCommandInfo;
MQTTStatus_t mqttStatus;
pMqttAgentContext = allocateMqttAgentContext( NULL );
__CPROVER_assume( isValidMqttAgentContext( pMqttAgentContext ) );
/* MQTTAgentCommandInfo is only added to Queue in MQTTAgent_Ping and
* non deterministic values for the members of MQTTAgentCommandInfo_t
* type will be sufficient for this proof. */
pCommandInfo = malloc( sizeof( MQTTAgentCommandInfo_t ) );
mqttStatus = MQTTAgent_Ping( pMqttAgentContext,
pCommandInfo );
__CPROVER_assert( isAgentSendCommandFunctionStatus( mqttStatus ), "The return value is a MQTTStatus_t." );
}

Some files were not shown because too many files have changed in this diff Show More