Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tr>
<td>core_mqtt.c</td>
<td><center>7.5K</center></td>
<td><center>6.6K</center></td>
<td><center>6.7K</center></td>
</tr>
<tr>
<td>core_mqtt_state.c</td>
Expand All @@ -19,8 +19,8 @@
</tr>
<tr>
<td>core_mqtt_serializer.c</td>
<td><center>8.5K</center></td>
<td><center>7.0K</center></td>
<td><center>8.7K</center></td>
<td><center>7.2K</center></td>
</tr>
<tr>
<td>core_mqtt_serializer_private.c</td>
Expand All @@ -39,7 +39,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>20.9K</center></b></td>
<td><b><center>17.5K</center></b></td>
<td><b><center>21.1K</center></b></td>
<td><b><center>17.8K</center></b></td>
</tr>
</table>
30 changes: 17 additions & 13 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2388,9 +2388,6 @@ static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
/* Update the number of bytes in the MQTT fixed buffer. */
pContext->index += ( size_t ) recvBytes;

/* Reset this value so that it will not be counted in the next iteration. */
recvBytes = 0;

status = MQTT_ProcessIncomingPacketTypeAndLength( pContext->networkBuffer.pBuffer,
&( pContext->index ),
&incomingPacket );
Expand Down Expand Up @@ -2422,6 +2419,10 @@ static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
}
}
}
else
{
recvBytes = 0;
}

/* Check whether there is data available before processing the packet further. */
if( ( status == MQTTNeedMoreBytes ) || ( status == MQTTNoDataAvailable ) )
Expand Down Expand Up @@ -2485,6 +2486,10 @@ static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
LogError( ( "Failed to send disconnect following a malformed disconnect "
"from the server. coreMQTT will forcefully disconnect now." ) );
}
else
{
status = MQTTStatusNotConnected;
}
}
else /* At this point the callback has failed. */
{
Expand All @@ -2504,16 +2509,16 @@ static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
* Should the packet be re-sent to the app? */
}

/* Update the index to reflect the remaining bytes in the buffer. */
pContext->index -= totalMQTTPacketLength;

/* Move the remaining bytes to the front of the buffer. */
( void ) memmove( pContext->networkBuffer.pBuffer,
&( pContext->networkBuffer.pBuffer[ totalMQTTPacketLength ] ),
pContext->index );

if( status == MQTTSuccess )
{
/* Update the index to reflect the remaining bytes in the buffer. */
pContext->index -= totalMQTTPacketLength;

/* Move the remaining bytes to the front of the buffer. */
( void ) memmove( pContext->networkBuffer.pBuffer,
&( pContext->networkBuffer.pBuffer[ totalMQTTPacketLength ] ),
pContext->index );

pContext->lastPacketRxTime = pContext->getTime();
}
}
Expand Down Expand Up @@ -3140,7 +3145,6 @@ static MQTTStatus_t sendConnectWithoutCopy( MQTTContext_t * pContext,
connectPropLen = pPropertyBuilder->currentIndex;
}

pIndex = propertyLength;
pIndex = encodeVariableLength( propertyLength, connectPropLen );
iterator->iov_base = propertyLength;
/* More details at: https://github.com/FreeRTOS/coreMQTT/blob/main/MISRA.md#rule-182 */
Expand Down Expand Up @@ -4748,7 +4752,7 @@ MQTTStatus_t MQTT_Disconnect( MQTTContext_t * pContext,
pContext->index = 0;
( void ) memset( pContext->networkBuffer.pBuffer, 0, pContext->networkBuffer.size );

LogError( ( "MQTT Connection Disconnected Successfully" ) );
LogInfo( ( "MQTT Connection Disconnected Successfully" ) );

status = sendDisconnectWithoutCopy( pContext, pReasonCode,
remainingLength, pPropertyBuilder );
Expand Down
18 changes: 11 additions & 7 deletions source/core_mqtt_prop_deserializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static inline MQTTStatus_t checkPropBuilderParams( MQTTPropBuilder_t * mqttPropB
else if( *currentIndex >= mqttPropBuilder->currentIndex )
{
LogWarn( ( "Index out of bounds." ) );
status = MQTTNoDataAvailable;
status = MQTTEndOfProperties;
}
else
{
Expand Down Expand Up @@ -183,12 +183,13 @@ static MQTTStatus_t getPropUint8( MQTTPropBuilder_t * pPropertyBuilder,
{
uint8_t * pLocalIndex = ( uint8_t * ) &pPropertyBuilder->pBuffer[ *currentIndex ];
uint32_t remainingPropLength = ( uint32_t ) ( pPropertyBuilder->currentIndex - *currentIndex - 1U );
bool tempBool = false;

pLocalIndex++;

status = decodeUint8t( property,
&remainingPropLength,
&( bool ) { false },
&tempBool,
&pLocalIndex );

if( status == MQTTSuccess )
Expand Down Expand Up @@ -233,13 +234,14 @@ static MQTTStatus_t getPropUint16( MQTTPropBuilder_t * pPropertyBuilder,
uint8_t * pLocalIndex = ( uint8_t * ) &pPropertyBuilder->pBuffer[ *currentIndex ];
/* Remaining properties = Total properties - current location in the buffer - 1 ( for property ID ). */
uint32_t remainingPropLength = ( uint32_t ) ( pPropertyBuilder->currentIndex - *currentIndex - 1U );
bool tempBool = false;

/* Move index to the beginning of the key. */
pLocalIndex++;

status = decodeUint16t( property,
&remainingPropLength,
&( bool ) { false },
&tempBool,
&pLocalIndex );

if( status == MQTTSuccess )
Expand Down Expand Up @@ -285,13 +287,14 @@ static MQTTStatus_t getPropUint32( MQTTPropBuilder_t * pPropertyBuilder,
uint8_t * pLocalIndex = ( uint8_t * ) &pPropertyBuilder->pBuffer[ *currentIndex ];
/* Remaining properties = Total properties - current location in the buffer - 1 ( for property ID ). */
uint32_t remainingPropLength = ( uint32_t ) ( pPropertyBuilder->currentIndex - *currentIndex - 1U );
bool tempBool = false;

/* Move index to the beginning of the key. */
pLocalIndex++;

status = decodeUint32t( property,
&remainingPropLength,
&( bool ) { false },
&tempBool,
&pLocalIndex );

if( status == MQTTSuccess )
Expand Down Expand Up @@ -337,13 +340,14 @@ static MQTTStatus_t getPropUtf8( MQTTPropBuilder_t * pPropertyBuilder,
{
uint8_t * pLocalIndex = ( uint8_t * ) &pPropertyBuilder->pBuffer[ *currentIndex ];
uint32_t remainingPropLength = ( uint32_t ) ( pPropertyBuilder->currentIndex - *currentIndex - 1U );
bool tempBool = false;

pLocalIndex++;

status = decodeUtf8( property,
propertyLength,
&remainingPropLength,
&( bool ) { false },
&tempBool,
&pLocalIndex );

if( status == MQTTSuccess )
Expand Down Expand Up @@ -517,7 +521,7 @@ MQTTStatus_t MQTTPropGet_MaxPacketSize( MQTTPropBuilder_t * pPropertyBuilder,
uint32_t * currentIndex,
uint32_t * pMaxPacketSize )
{
return getPropUint32( pPropertyBuilder, currentIndex, MQTT_SESSION_EXPIRY_ID, pMaxPacketSize );
return getPropUint32( pPropertyBuilder, currentIndex, MQTT_MAX_PACKET_SIZE_ID, pMaxPacketSize );
}

/*-----------------------------------------------------------*/
Expand Down Expand Up @@ -640,7 +644,7 @@ MQTTStatus_t MQTTPropGet_MessageExpiryInterval( MQTTPropBuilder_t * pPropertyBui
uint32_t * currentIndex,
uint32_t * pMessageExpiry )
{
return getPropUint32( pPropertyBuilder, currentIndex, MQTT_SESSION_EXPIRY_ID, pMessageExpiry );
return getPropUint32( pPropertyBuilder, currentIndex, MQTT_MSG_EXPIRY_ID, pMessageExpiry );
}

/*-----------------------------------------------------------*/
Expand Down
67 changes: 59 additions & 8 deletions source/core_mqtt_prop_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ static bool isValidPropertyInPacketType( const uint8_t * mqttPacketType,
UINT32_SET_BIT( allowedPropertiesMask, MQTT_USER_PROP_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_AUTHENTICATION_METHOD_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_AUTHENTICATION_DATA_POS );

/* Will properties. */
UINT32_SET_BIT( allowedPropertiesMask, MQTT_WILL_DELAY_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_PAYLOAD_FORMAT_INDICATOR_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_MESSAGE_EXPIRY_INTERVAL_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_CONTENT_TYPE_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_RESPONSE_TOPIC_POS );
UINT32_SET_BIT( allowedPropertiesMask, MQTT_CORRELATION_DATA_POS );

break;

case MQTT_PACKET_TYPE_CONNACK:
Expand Down Expand Up @@ -598,6 +607,11 @@ MQTTStatus_t MQTTPropAdd_SubscriptionId( MQTTPropBuilder_t * pPropertyBuilder,
LogError( ( "Subscription Id cannot be 0 for subscribe properties: Protocol Error." ) );
status = MQTTBadParameter;
}
else if( subscriptionId > MAX_VARIABLE_LENGTH_INT_VALUE )
{
LogError( ( "Subscription Id cannot be greater than 268435455: Protocol Error." ) );
status = MQTTBadParameter;
}
else if( pPropertyBuilder == NULL )
{
LogError( ( "Argument pPropertyBuilder cannot be NULL." ) );
Expand Down Expand Up @@ -855,7 +869,22 @@ MQTTStatus_t MQTTPropAdd_AuthData( MQTTPropBuilder_t * pPropertyBuilder,
{
MQTTStatus_t status = MQTTSuccess;

if( UINT32_CHECK_BIT( pPropertyBuilder->fieldSet, MQTT_AUTHENTICATION_METHOD_POS ) == false )
if( pPropertyBuilder == NULL )
{
LogError( ( "pPropertyBuilder cannot be NULL" ) );
status = MQTTBadParameter;
}
else if( pPropertyBuilder->pBuffer == NULL )
{
LogError( ( "pPropertyBuilder->pBuffer cannot be NULL" ) );
status = MQTTBadParameter;
}
else if( authData == NULL )
{
LogError( ( "authData cannot be NULL" ) );
status = MQTTBadParameter;
}
else if( UINT32_CHECK_BIT( pPropertyBuilder->fieldSet, MQTT_AUTHENTICATION_METHOD_POS ) == false )
{
LogError( ( "Auth method must be added before authentication data. "
"Not a protocol violation but a practice enforced by coreMQTT." ) );
Expand Down Expand Up @@ -945,13 +974,35 @@ MQTTStatus_t MQTTPropAdd_ResponseTopic( MQTTPropBuilder_t * pPropertyBuilder,
uint16_t responseTopicLength,
const uint8_t * pOptionalMqttPacketType )
{
/* No restriction and hence no additional checks on the response topic. */
return addPropUtf8( pPropertyBuilder,
responseTopic,
responseTopicLength,
MQTT_RESPONSE_TOPIC_ID,
MQTT_RESPONSE_TOPIC_POS,
pOptionalMqttPacketType );
MQTTStatus_t status;

if( responseTopic == NULL )
{
LogError( ( "Arguments cannot be NULL : responseTopic=%p.", ( void * ) responseTopic ) );
status = MQTTBadParameter;
}
else if( responseTopicLength == 0U )
{
LogError( ( "Response Topic Length cannot be 0" ) );
status = MQTTBadParameter;
}
else if( ( memchr( ( void * ) responseTopic, ( int ) '#', responseTopicLength ) != NULL ) ||
( memchr( ( void * ) responseTopic, ( int ) '+', responseTopicLength ) != NULL ) )
{
LogError( ( "Protocol Error : Response Topic contains wildcards (such as # or +)." ) );
status = MQTTBadParameter;
}
else
{
status = addPropUtf8( pPropertyBuilder,
responseTopic,
responseTopicLength,
MQTT_RESPONSE_TOPIC_ID,
MQTT_RESPONSE_TOPIC_POS,
pOptionalMqttPacketType );
}

return status;
}

/*-----------------------------------------------------------*/
Expand Down
Loading
Loading