|
67 | 67 | * @note This definition must exist in order to compile. 10U is a typical value
|
68 | 68 | * used in the MQTT demos.
|
69 | 69 | */
|
70 |
| -#define MAX_UNACKED_PACKETS ( 20U ) |
| 70 | +#define MAX_UNACKED_PACKETS ( 20U ) |
| 71 | + |
| 72 | +/** |
| 73 | + * @brief Gives the maximum number of transport vectors required to encode |
| 74 | + * a publish packet to send over the network interface. |
| 75 | + */ |
| 76 | +#define PUBLISH_PACKET_VECTORS ( 4U ) |
| 77 | + |
| 78 | +/** |
| 79 | + * @brief Definition of the MQTTVec_t struct that is used to pass the outgoing |
| 80 | + * publish packet content to the user callback function to store the packet for |
| 81 | + * retransmission purposes |
| 82 | + * |
| 83 | + * @note The definition of this struct is hidden from the application code. The intent |
| 84 | + * behind defining the struct here is to simulate the actual process flow. |
| 85 | + */ |
| 86 | +struct MQTTVec |
| 87 | +{ |
| 88 | + TransportOutVector_t * pVector; /**< Pointer to transport vector. USER SHOULD NOT ACCESS THIS DIRECTLY - IT IS AN INTERNAL DETAIL AND CAN CHANGE. */ |
| 89 | + size_t vectorLen; /**< Length of the transport vector. USER SHOULD NOT ACCESS THIS DIRECTLY - IT IS AN INTERNAL DETAIL AND CAN CHANGE. */ |
| 90 | +}; |
71 | 91 |
|
72 | 92 | MQTTPacketInfo_t * allocateMqttPacketInfo( MQTTPacketInfo_t * pPacketInfo )
|
73 | 93 | {
|
@@ -284,3 +304,50 @@ bool isValidMqttContext( const MQTTContext_t * pContext )
|
284 | 304 |
|
285 | 305 | return isValid;
|
286 | 306 | }
|
| 307 | + |
| 308 | +MQTTVec_t * allocateMqttVec( MQTTVec_t * mqttVec ) |
| 309 | +{ |
| 310 | + size_t vecLen; |
| 311 | + TransportOutVector_t * pVector; |
| 312 | + |
| 313 | + if( mqttVec == NULL ) |
| 314 | + { |
| 315 | + mqttVec = malloc( sizeof( MQTTVec_t ) ); |
| 316 | + } |
| 317 | + |
| 318 | + /* It is a part of the API contract that the #MQTT_GetBytesInMQTTVec API will be called |
| 319 | + * with the #MQTTVec_t pointer given by the library as an input to the user defined |
| 320 | + * #MQTTStorePacketForRetransmit callback function. The library would never provide with |
| 321 | + * a NULL pointer. As this is a simulation of the real flow, it can be assumed that the |
| 322 | + * mqttVec pointer is non-NULL. |
| 323 | + */ |
| 324 | + __CPROVER_assume( mqttVec != NULL ); |
| 325 | + __CPROVER_assume( vecLen <= PUBLISH_PACKET_VECTORS ); |
| 326 | + __CPROVER_assume( vecLen > 0U ); |
| 327 | + |
| 328 | + pVector = malloc( vecLen * sizeof( TransportOutVector_t ) ); |
| 329 | + |
| 330 | + /* The library is responsible with providing the memory for pVector within the mqttVec. Hence |
| 331 | + * it can be assumed that pVector is also non-NULL |
| 332 | + */ |
| 333 | + __CPROVER_assume( pVector != NULL ); |
| 334 | + |
| 335 | + for( int i = 0; i < vecLen; i++ ) |
| 336 | + { |
| 337 | + /* One of there vectors will also hold the buffer pointing to the publish payload. The |
| 338 | + * maximum size of thepublish payload is limited by the remaining length field. Hence the maximum |
| 339 | + * size of the buffer in the vector can be 268435455 B. |
| 340 | + */ |
| 341 | + __CPROVER_assume( pVector[ i ].iov_len <= 268435455 ); |
| 342 | + __CPROVER_assume( pVector[ i ].iov_len >= 0U ); |
| 343 | + |
| 344 | + pVector[ i ].iov_base = malloc( pVector[ i ].iov_len * sizeof( uint8_t ) ); |
| 345 | + |
| 346 | + __CPROVER_assume( pVector[ i ].iov_base != NULL ); |
| 347 | + } |
| 348 | + |
| 349 | + mqttVec->pVector = pVector; |
| 350 | + mqttVec->vectorLen = vecLen; |
| 351 | + |
| 352 | + return mqttVec; |
| 353 | +} |
0 commit comments