Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

Location:
azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/inc/azure_umqtt_c/mqtt_client.h

    r457 r464  
    4949typedef void(*ON_MQTT_DISCONNECTED_CALLBACK)(void* callbackCtx);
    5050
     51MOCKABLE_FUNCTION(, void, mqtt_client_clear_xio, MQTT_CLIENT_HANDLE, handle);
    5152MOCKABLE_FUNCTION(, MQTT_CLIENT_HANDLE, mqtt_client_init, ON_MQTT_MESSAGE_RECV_CALLBACK, msgRecv, ON_MQTT_OPERATION_CALLBACK, opCallback, void*, opCallbackCtx, ON_MQTT_ERROR_CALLBACK, onErrorCallBack, void*, errorCBCtx);
    5253MOCKABLE_FUNCTION(, void, mqtt_client_deinit, MQTT_CLIENT_HANDLE, handle);
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/inc/azure_umqtt_c/mqttconst.h

    r457 r464  
    3333    DISCONNECT_TYPE, 0xE0, \
    3434    PACKET_TYPE_ERROR, 0xE1, /* 0xE1 was assigned because ENUM_2 needs it */ \
    35     UNKNOWN_TYPE, 0xE2 /* 0xE2 was assigned because ENUM_2 needs it */
     35    UNKNOWN_TYPE, 0xE2,      /* 0xE2 was assigned because ENUM_2 needs it */ \
     36    PACKET_INVALID1_TYPE, 0x00, \
     37    PACKET_INVALID2_TYPE, 0xF0
    3638
    3739MU_DEFINE_ENUM_2(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES)
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src/mqtt_client.c

    r457 r464  
    770770                    /*Codes_SRS_MQTT_CLIENT_07_028: [If the actionResult parameter is of type CONNECT_ACK then the msgInfo value shall be a CONNECT_ACK structure.]*/
    771771                    CONNECT_ACK connack = { 0 };
    772                     connack.isSessionPresent = (byteutil_readByte(&iterator) == 0x1) ? true : false;
     772                    if (packetLength != 2) // CONNACK payload must be only 2 bytes
     773                    {
     774                        LogError("Invalid CONNACK packet.");
     775                        set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR);
     776                        break;
     777                    }
     778
     779                    uint8_t connect_acknowledge_flags = byteutil_readByte(&iterator);
     780                    if (connect_acknowledge_flags & 0xFE) // bits 7-1 must be zero
     781                    {
     782                        LogError("Invalid CONNACK packet.");
     783                        set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR);
     784                        break;
     785                    }
     786
     787                    connack.isSessionPresent = (connect_acknowledge_flags == 0x1) ? true : false;
    773788                    uint8_t rc = byteutil_readByte(&iterator);
    774789                    connack.returnCode =
     
    802817                case PUBCOMP_TYPE:
    803818                {
     819                    if (packetLength != 2) // PUBXXX payload must be only 2 bytes
     820                    {
     821                        LogError("Invalid packet length.");
     822                        set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR);
     823                        break;
     824                    }
     825
    804826                    /*Codes_SRS_MQTT_CLIENT_07_029: [If the actionResult parameter are of types PUBACK_TYPE, PUBREC_TYPE, PUBREL_TYPE or PUBCOMP_TYPE then the msgInfo value shall be a PUBLISH_ACK structure.]*/
    805827                    MQTT_CLIENT_EVENT_RESULT action = (packet == PUBACK_TYPE) ? MQTT_CLIENT_ON_PUBLISH_ACK :
     
    876898                        {
    877899                            uint8_t qosRet = byteutil_readByte(&iterator);
     900                            if (qosRet & 0x7C) // SUBACK QOS bits 6-2 must be zero
     901                            {
     902                                LogError("Invalid SUBACK_TYPE packet.");
     903                                set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR);
     904                                break;
     905                            }
    878906                            suback.qosReturn[suback.qosCount++] =
    879907                                (qosRet <= ((uint8_t)DELIVER_EXACTLY_ONCE)) ?
     
    909937                    /*Codes_SRS_MQTT_CLIENT_07_031: [If the actionResult parameter is of type UNSUBACK_TYPE then the msgInfo value shall be a UNSUBSCRIBE_ACK structure.]*/
    910938                    UNSUBSCRIBE_ACK unsuback = { 0 };
     939                    if (packetLength != 2) // UNSUBACK_TYPE payload must be only 2 bytes
     940                    {
     941                        LogError("Invalid UNSUBACK packet length.");
     942                        set_error_callback(mqtt_client, MQTT_CLIENT_COMMUNICATION_ERROR);
     943                        break;
     944                    }
     945
    911946                    unsuback.packetId = byteutil_read_uint16(&iterator, packetLength);
    912947
     
    943978    {
    944979        LogError("recvCompleteCallback context failed.");
     980    }
     981}
     982
     983void mqtt_client_clear_xio(MQTT_CLIENT_HANDLE handle)
     984{
     985    if (handle != NULL)
     986    {
     987        MQTT_CLIENT *mqtt_client = (MQTT_CLIENT *)handle;
     988
     989        // The upstream transport handle allocates and deallocates the xio handle.
     990        // The reference to that xio handle is shared between this layer (mqtt layer)
     991        // and the upstream layer. The clearing done here is to signal to this layer
     992        // that the handle is no longer available to be used. This is different from
     993        // deiniting the mqtt client in that we do not want an entire teardown, but
     994        // only a possible re-upping of the xio in the future.
     995        mqtt_client->xioHandle = NULL;
    945996    }
    946997}
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/umqtt/src/mqtt_codec.c

    r457 r464  
    568568            }
    569569        }
     570    }
     571    else if (codecData->remainLenIndex == (sizeof(codecData->storeRemainLen) / sizeof(codecData->storeRemainLen[0])))
     572    {
     573        // The maximum number of bytes in the Remaining Length field is four
     574        // This allows applications to send Control Packets of size up to 268,435,455 (256 MB).
     575        // The representation of this number on the wire is: 0xFF, 0xFF, 0xFF, 0x7F.
     576
     577        // The last byte has exceed the max value of 0x7F
     578        LogError("MQTT packet len is invalid");
     579        result = MU_FAILURE;
    570580    }
    571581    return result;
     
    10671077                {
    10681078                    codec_Data->currPacket = processControlPacketType(iterator, &codec_Data->headerFlags);
     1079
     1080                    // validate packet type and invalid reserved header flags
     1081                    switch (codec_Data->currPacket)
     1082                    {
     1083                        case PACKET_INVALID1_TYPE:
     1084                        case PACKET_INVALID2_TYPE:
     1085                            codec_Data->currPacket = PACKET_TYPE_ERROR;
     1086                            result = MU_FAILURE;
     1087                            break;
     1088
     1089                        case CONNECT_TYPE:
     1090                        case CONNACK_TYPE:
     1091                        case PUBACK_TYPE:
     1092                        case PUBREC_TYPE:
     1093                        case PUBCOMP_TYPE:
     1094                        case SUBACK_TYPE:
     1095                        case UNSUBACK_TYPE:
     1096                        case PINGREQ_TYPE:
     1097                        case PINGRESP_TYPE:
     1098                        case DISCONNECT_TYPE:
     1099                            if (codec_Data->headerFlags & 0x0F) // flags must be all zeros
     1100                            {
     1101                                codec_Data->currPacket = PACKET_TYPE_ERROR;
     1102                                result = MU_FAILURE;
     1103                            }
     1104                            break;
     1105
     1106                        case PUBREL_TYPE:
     1107                        case SUBSCRIBE_TYPE:
     1108                        case UNSUBSCRIBE_TYPE:
     1109                            if ((codec_Data->headerFlags & 0x0F) != 0x02) // only bit 1 must be set
     1110                            {
     1111                                codec_Data->currPacket = PACKET_TYPE_ERROR;
     1112                                result = MU_FAILURE;
     1113                            }
     1114                            break;
     1115
     1116                        case PUBLISH_TYPE:
     1117                        case CONTROL_PACKET_TYPE_INVALID:
     1118                        case PACKET_TYPE_ERROR:
     1119                        case UNKNOWN_TYPE:
     1120                            break;
     1121                    }
    10691122                }
    10701123                else
     
    10781131                    else if (codec_Data->currPacket == PINGRESP_TYPE)
    10791132                    {
    1080                         /* Codes_SRS_MQTT_CODEC_07_034: [Upon a constructing a complete MQTT packet mqtt_codec_bytesReceived shall call the ON_PACKET_COMPLETE_CALLBACK function.] */
    1081                         completePacketData(codec_Data);
     1133                        // PINGRESP must not have a payload
     1134                        if (((int8_t*)buffer)[index] == 0)
     1135                        {
     1136                            /* Codes_SRS_MQTT_CODEC_07_034: [Upon a constructing a complete MQTT packet mqtt_codec_bytesReceived shall call the ON_PACKET_COMPLETE_CALLBACK function.] */
     1137                            completePacketData(codec_Data);
     1138                        }
     1139                        else
     1140                        {
     1141                            codec_Data->currPacket = PACKET_TYPE_ERROR;
     1142                            result = MU_FAILURE;
     1143                        }
    10821144                    }
    10831145                }
Note: See TracChangeset for help on using the changeset viewer.