Skip to content

Modify SUBACK/UNSUBACK handling to not return ServerRefused on non-malformed packets#369

Open
AniruddhaKanhere wants to merge 4 commits intoFreeRTOS:mainfrom
AniruddhaKanhere:SubUnsubReturnSuccess
Open

Modify SUBACK/UNSUBACK handling to not return ServerRefused on non-malformed packets#369
AniruddhaKanhere wants to merge 4 commits intoFreeRTOS:mainfrom
AniruddhaKanhere:SubUnsubReturnSuccess

Conversation

@AniruddhaKanhere
Copy link
Copy Markdown
Member

Description

MQTTProcessLoop calls return ServerRefused when a SUBACK/UNSUBACK says that one of the subs was rejected by the server. This commit modifies that behavior so that processloop returns success since the packet was well formed and the application should decide what is to be done with the subscription.

This PR also fixes documentation of the functions to say what they actually return.

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Server rejection of individual topic filters (reason codes >= 0x80) in
SUBACK/UNSUBACK is not a library-level error. The application inspects
per-topic reason codes via MQTTDeserializedInfo_t.pReasonCode in the
event callback.

Previously, readSubackStatus returned MQTTServerRefused when all topics
were rejected, which propagated up through MQTT_ProcessLoop/ReceiveLoop
as an undocumented error code and also prevented the receive buffer from
being advanced.

Changes:
- readSubackStatus: return MQTTSuccess for all known reason codes
  (including rejections). Only unrecognized codes return MQTTBadResponse.
- handleSubUnsubAck: remove dead MQTTServerRefused branch.
- Update doxygen briefs for readSubackStatus, deserializeSubUnsubAck,
  handleSubUnsubAck, MQTT_DeserializeAck, MQTTEventCallback_t, and
  MQTTServerRefused enum.
- MQTT_ProcessLoop/MQTT_ReceiveLoop: Add MQTTNoMemory,
  MQTTPublishStoreFailed, MQTTEventCallbackFailed,
  MQTTStatusNotConnected, MQTTStatusDisconnectPending. Reorder to
  list MQTTSuccess and MQTTNeedMoreBytes first as non-error returns
  with explicit note that all other values indicate an error.
- MQTT_Publish: Add MQTTNoMemory, MQTTStateCollision, MQTTIllegalState.
- MQTT_Disconnect: Remove MQTTStatusDisconnectPending (never returned).
- MQTT_GetSubAckStatusCodes: Add MQTTBadResponse.
- MQTT_GetPacketId: Document zero return on NULL context.
The pOptionalMqttPacketType parameter of MQTTPropAdd_* functions
requires passing a pointer to a packet type byte for runtime
validation. The previous calling convention required compound
literals which are not C90 compatible and are cryptic:

  MQTTPropAdd_SessionExpiry(&p, 3600, &(uint8_t){MQTT_PACKET_TYPE_CONNECT});

Add MQTT_PROP_VALIDATE_CONNECT/PUBLISH/SUBSCRIBE/UNSUBSCRIBE/DISCONNECT
macros backed by static const variables (C90 safe) so users can write:

  MQTTPropAdd_SessionExpiry(&p, 3600, MQTT_PROP_VALIDATE_CONNECT);

MQTT_PROP_NO_VALIDATE (NULL) skips validation. Fully backward compatible.
- test_MQTTV5_suback: SUBACK with reason code 0x80 now yields
  MQTTSuccess instead of MQTTServerRefused.
- test_MQTT_ProcessLoop_handleIncomingAck_Happy_Paths5: Remove the
  MQTTServerRefused mock setup; the deserializer no longer produces
  that status for SUBACK, so the callback is invoked with
  MQTTSuccess (the default).
- size_table.md: Update core_mqtt_serializer.c and total sizes to
  match the new binary size after the code additions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant