1 /*
2  * coreMQTT Agent v1.1.0
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /**
24  * @file agent_command_functions_stub.c
25  * @brief Function stubs for processing an MQTT agent command.
26  */
27 
28 /* MQTT Agent command functions include. */
29 #include "core_mqtt_agent_command_functions.h"
30 
MQTTAgentCommand_Stub(MQTTAgentContext_t * pMqttAgentContext,void * pArg,MQTTAgentCommandFuncReturns_t * pReturnFlags)31 static MQTTStatus_t MQTTAgentCommand_Stub( MQTTAgentContext_t * pMqttAgentContext,
32                                            void * pArg,
33                                            MQTTAgentCommandFuncReturns_t * pReturnFlags )
34 {
35     MQTTStatus_t returnStatus;
36     uint16_t packetId;
37 
38     __CPROVER_assert( pMqttAgentContext != NULL, "MQTT Agent context is not NULL." );
39     __CPROVER_assert( pReturnFlags != NULL, "Return flags pointer is not NULL." );
40 
41     __CPROVER_assume( packetId > 0U );
42 
43     pReturnFlags->packetId = packetId;
44     pReturnFlags->endLoop = nondet_bool();
45     pReturnFlags->addAcknowledgment = nondet_bool();
46     pReturnFlags->runProcessLoop = nondet_bool();
47 
48     return returnStatus;
49 }
50 
51 /*-----------------------------------------------------------*/
52 
MQTTAgentCommand_ProcessLoop(MQTTAgentContext_t * pMqttAgentContext,void * pUnusedArg,MQTTAgentCommandFuncReturns_t * pReturnFlags)53 MQTTStatus_t MQTTAgentCommand_ProcessLoop( MQTTAgentContext_t * pMqttAgentContext,
54                                            void * pUnusedArg,
55                                            MQTTAgentCommandFuncReturns_t * pReturnFlags )
56 {
57     MQTTStatus_t returnStatus;
58 
59     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
60                                           pUnusedArg,
61                                           pReturnFlags );
62 
63     pReturnFlags->runProcessLoop = false;
64     pReturnFlags->addAcknowledgment = false;
65 
66     return returnStatus;
67 }
68 
69 /*-----------------------------------------------------------*/
70 
MQTTAgentCommand_Publish(MQTTAgentContext_t * pMqttAgentContext,void * pPublishArg,MQTTAgentCommandFuncReturns_t * pReturnFlags)71 MQTTStatus_t MQTTAgentCommand_Publish( MQTTAgentContext_t * pMqttAgentContext,
72                                        void * pPublishArg,
73                                        MQTTAgentCommandFuncReturns_t * pReturnFlags )
74 {
75     MQTTStatus_t returnStatus;
76     MQTTPublishInfo_t * pPublishInfo;
77 
78     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
79                                           pPublishArg,
80                                           pReturnFlags );
81 
82     if( pPublishArg != NULL )
83     {
84         pPublishInfo = ( MQTTPublishInfo_t * ) pPublishArg;
85         pReturnFlags->addAcknowledgment = ( pPublishInfo->qos > MQTTQoS0 ) ? true : false;
86         pReturnFlags->runProcessLoop = ( pPublishInfo->qos > MQTTQoS0 ) ? true : false;
87     }
88 
89     return returnStatus;
90 }
91 
92 /*-----------------------------------------------------------*/
93 
MQTTAgentCommand_Subscribe(MQTTAgentContext_t * pMqttAgentContext,void * pVoidSubscribeArgs,MQTTAgentCommandFuncReturns_t * pReturnFlags)94 MQTTStatus_t MQTTAgentCommand_Subscribe( MQTTAgentContext_t * pMqttAgentContext,
95                                          void * pVoidSubscribeArgs,
96                                          MQTTAgentCommandFuncReturns_t * pReturnFlags )
97 {
98     MQTTStatus_t returnStatus;
99 
100     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
101                                           pVoidSubscribeArgs,
102                                           pReturnFlags );
103 
104     pReturnFlags->addAcknowledgment = true;
105     pReturnFlags->runProcessLoop = true;
106 
107     return returnStatus;
108 }
109 
110 /*-----------------------------------------------------------*/
111 
MQTTAgentCommand_Unsubscribe(MQTTAgentContext_t * pMqttAgentContext,void * pVoidSubscribeArgs,MQTTAgentCommandFuncReturns_t * pReturnFlags)112 MQTTStatus_t MQTTAgentCommand_Unsubscribe( MQTTAgentContext_t * pMqttAgentContext,
113                                            void * pVoidSubscribeArgs,
114                                            MQTTAgentCommandFuncReturns_t * pReturnFlags )
115 {
116     MQTTStatus_t returnStatus;
117 
118     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
119                                           pVoidSubscribeArgs,
120                                           pReturnFlags );
121 
122     pReturnFlags->addAcknowledgment = true;
123     pReturnFlags->runProcessLoop = true;
124 
125     return returnStatus;
126 }
127 
128 /*-----------------------------------------------------------*/
129 
MQTTAgentCommand_Connect(MQTTAgentContext_t * pMqttAgentContext,void * pConnectArgs,MQTTAgentCommandFuncReturns_t * pReturnFlags)130 MQTTStatus_t MQTTAgentCommand_Connect( MQTTAgentContext_t * pMqttAgentContext,
131                                        void * pConnectArgs,
132                                        MQTTAgentCommandFuncReturns_t * pReturnFlags )
133 {
134     MQTTStatus_t returnStatus;
135 
136     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
137                                           pConnectArgs,
138                                           pReturnFlags );
139 
140     pReturnFlags->addAcknowledgment = true;
141     pReturnFlags->runProcessLoop = true;
142 
143     return returnStatus;
144 }
145 
146 /*-----------------------------------------------------------*/
147 
MQTTAgentCommand_Disconnect(MQTTAgentContext_t * pMqttAgentContext,void * pUnusedArg,MQTTAgentCommandFuncReturns_t * pReturnFlags)148 MQTTStatus_t MQTTAgentCommand_Disconnect( MQTTAgentContext_t * pMqttAgentContext,
149                                           void * pUnusedArg,
150                                           MQTTAgentCommandFuncReturns_t * pReturnFlags )
151 {
152     MQTTStatus_t returnStatus;
153 
154     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
155                                           pUnusedArg,
156                                           pReturnFlags );
157 
158     pReturnFlags->addAcknowledgment = false;
159     pReturnFlags->runProcessLoop = false;
160 
161     return returnStatus;
162 }
163 
164 /*-----------------------------------------------------------*/
165 
MQTTAgentCommand_Ping(MQTTAgentContext_t * pMqttAgentContext,void * pUnusedArg,MQTTAgentCommandFuncReturns_t * pReturnFlags)166 MQTTStatus_t MQTTAgentCommand_Ping( MQTTAgentContext_t * pMqttAgentContext,
167                                     void * pUnusedArg,
168                                     MQTTAgentCommandFuncReturns_t * pReturnFlags )
169 {
170     MQTTStatus_t returnStatus;
171 
172     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
173                                           pUnusedArg,
174                                           pReturnFlags );
175 
176     pReturnFlags->addAcknowledgment = false;
177     pReturnFlags->runProcessLoop = false;
178 
179     return returnStatus;
180 }
181 
182 /*-----------------------------------------------------------*/
183 
MQTTAgentCommand_Terminate(MQTTAgentContext_t * pMqttAgentContext,void * pUnusedArg,MQTTAgentCommandFuncReturns_t * pReturnFlags)184 MQTTStatus_t MQTTAgentCommand_Terminate( MQTTAgentContext_t * pMqttAgentContext,
185                                          void * pUnusedArg,
186                                          MQTTAgentCommandFuncReturns_t * pReturnFlags )
187 {
188     MQTTStatus_t returnStatus;
189 
190     returnStatus = MQTTAgentCommand_Stub( pMqttAgentContext,
191                                           pUnusedArg,
192                                           pReturnFlags );
193 
194     pReturnFlags->endLoop = true;
195 
196     return returnStatus;
197 }
198 
199 /*-----------------------------------------------------------*/
200