feat(aws_iot): add aws_iot support

IDF: release/v3.1, commit: 66dad0c5
This commit is contained in:
Wu Jian Gang
2018-07-10 22:07:16 +08:00
parent 0248c6dc2a
commit 1d1ae209af
118 changed files with 20683 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
/**
* @file aws_iot_config.h
* @brief IoT Client Unit Testing - IoT Config
*/
#ifndef IOT_TESTS_UNIT_CONFIG_H_
#define IOT_TESTS_UNIT_CONFIG_H_
// Get from console
// =================================================
#define AWS_IOT_MQTT_HOST "localhost"
#define AWS_IOT_MQTT_PORT 8883
#define AWS_IOT_MQTT_CLIENT_ID "C-SDK_UnitTestClient"
#define AWS_IOT_MY_THING_NAME "C-SDK_UnitTestThing"
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt"
#define AWS_IOT_CERTIFICATE_FILENAME "cert.crt"
#define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem"
// =================================================
// MQTT PubSub
#define AWS_IOT_MQTT_TX_BUF_LEN 512
#define AWS_IOT_MQTT_RX_BUF_LEN 512
#define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5
// Thing Shadow specific configs
#define SHADOW_MAX_SIZE_OF_RX_BUFFER 512
#define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 /** {"clientToken": ">>uniqueClientID<<+sequenceNumber"}*/
#define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 /** {"clientToken": ">>uniqueClientID+sequenceNumber<<"}*/
#define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 /** >>{"clientToken": "uniqueClientID+sequenceNumber"}<<*/
#define MAX_SIZE_OF_THINGNAME 30
#define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10
#define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10
#define MAX_JSON_TOKEN_EXPECTED 120
#define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60
#define MAX_SIZE_OF_THING_NAME 20
#define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME
// Auto Reconnect specific config
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000
#endif /* IOT_TESTS_UNIT_CONFIG_H_ */

View File

@ -0,0 +1,95 @@
/*
* Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
/**
* @file aws_iot_tests_unit_helper_functions.h
* @brief IoT Client Unit Testing - Helper Functions
*/
#ifndef IOT_TESTS_UNIT_HELPER_FUNCTIONS_H_
#define IOT_TESTS_UNIT_HELPER_FUNCTIONS_H_
#include <string.h>
#include "aws_iot_mqtt_client_interface.h"
typedef struct {
unsigned char PacketType;
unsigned int RemainingLength;
unsigned int ProtocolLength;
unsigned char ProtocolName[4];
unsigned int ProtocolLevel;
unsigned char ConnectFlag;
unsigned int KeepAlive;
} ConnectBufferProofread;
void ResetInvalidParameters(void);
void InitMQTTParamsSetup(IoT_Client_Init_Params *params, char *pHost, uint16_t port, bool enableAutoReconnect,
iot_disconnect_handler disconnectHandler);
void ConnectMQTTParamsSetup(IoT_Client_Connect_Params *params, char *pClientID, uint16_t clientIDLen);
void ConnectMQTTParamsSetup_Detailed(IoT_Client_Connect_Params *params, char *pClientID, uint16_t clientIDLen,
QoS qos, bool isCleanSession, bool isWillMsgPresent, char *pWillTopicName,
uint16_t willTopicNameLen, char *pWillMessage, uint16_t willMsgLen,
char *pUsername, uint16_t userNameLen, char *pPassword,
uint16_t passwordLen);
void printBuffer(unsigned char *buffer, size_t len);
void setTLSRxBufferForConnack(IoT_Client_Connect_Params *params, unsigned char sessionPresent,
unsigned char connackResponseCode);
void setTLSRxBufferForPuback(void);
void setTLSRxBufferForSuback(char *topicName, size_t topicNameLen, QoS qos, IoT_Publish_Message_Params params);
void setTLSRxBufferForDoubleSuback(char *topicName, size_t topicNameLen, QoS qos, IoT_Publish_Message_Params params);
void setTLSRxBufferForSubFail(void);
void setTLSRxBufferWithMsgOnSubscribedTopic(char *topicName, size_t topicNameLen, QoS qos,
IoT_Publish_Message_Params params, char *pMsg);
void setTLSRxBufferForUnsuback(void);
void setTLSRxBufferForPingresp(void);
void setTLSRxBufferForConnackAndSuback(IoT_Client_Connect_Params *conParams, unsigned char sessionPresent,
char *topicName, size_t topicNameLen, QoS qos);
unsigned char isLastTLSTxMessagePuback(void);
unsigned char isLastTLSTxMessagePingreq(void);
unsigned char isLastTLSTxMessageDisconnect(void);
void setTLSRxBufferDelay(int seconds, int microseconds);
void ResetTLSBuffer(void);
unsigned char generateMultipleSubTopics(char *des, int boundary);
void encodeRemainingLength(unsigned char *buf, size_t *st, size_t length);
unsigned char *connectTxBufferHeaderParser(ConnectBufferProofread *params, unsigned char *buf);
bool isConnectTxBufFlagCorrect(IoT_Client_Connect_Params *settings, ConnectBufferProofread *readRes);
bool isConnectTxBufPayloadCorrect(IoT_Client_Connect_Params *settings, unsigned char *payloadBuf);
void printPrfrdParams(ConnectBufferProofread *params);
#endif /* IOT_TESTS_UNIT_HELPER_FUNCTIONS_H_ */

View File

@ -0,0 +1,43 @@
/*
* Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
/**
* @file aws_iot_tests_unit_shadow_helper.h
* @brief IoT Client Unit Testing - Shadow Helper functions
*/
#ifndef IOT_TESTS_UNIT_SHADOW_HELPER_FUNCTIONS_H_
#define IOT_TESTS_UNIT_SHADOW_HELPER_FUNCTIONS_H_
#define AWS_THINGS_TOPIC "$aws/things/"
#define SHADOW_TOPIC "/shadow/"
#define ACCEPTED_TOPIC "/accepted"
#define REJECTED_TOPIC "/rejected"
#define UPDATE_TOPIC "update"
#define GET_TOPIC "get"
#define DELETE_TOPIC "delete"
#define GET_ACCEPTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC GET_TOPIC ACCEPTED_TOPIC
#define GET_REJECTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC GET_TOPIC REJECTED_TOPIC
#define GET_PUB_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC GET_TOPIC
#define DELETE_ACCEPTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC DELETE_TOPIC ACCEPTED_TOPIC
#define DELETE_REJECTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC DELETE_TOPIC REJECTED_TOPIC
#define UPDATE_ACCEPTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC UPDATE_TOPIC ACCEPTED_TOPIC
#define UPDATE_REJECTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC UPDATE_TOPIC REJECTED_TOPIC
#endif /* IOT_TESTS_UNIT_SHADOW_HELPER_FUNCTIONS_H_ */