test

Committer:
peyo
Date:
Wed Apr 12 14:07:09 2017 +0200
Revision:
0:cd5404401c2f
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peyo 0:cd5404401c2f 1 /*
peyo 0:cd5404401c2f 2 * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
peyo 0:cd5404401c2f 3 *
peyo 0:cd5404401c2f 4 * Licensed under the Apache License, Version 2.0 (the "License").
peyo 0:cd5404401c2f 5 * You may not use this file except in compliance with the License.
peyo 0:cd5404401c2f 6 * A copy of the License is located at
peyo 0:cd5404401c2f 7 *
peyo 0:cd5404401c2f 8 * http://aws.amazon.com/apache2.0
peyo 0:cd5404401c2f 9 *
peyo 0:cd5404401c2f 10 * or in the "license" file accompanying this file. This file is distributed
peyo 0:cd5404401c2f 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
peyo 0:cd5404401c2f 12 * express or implied. See the License for the specific language governing
peyo 0:cd5404401c2f 13 * permissions and limitations under the License.
peyo 0:cd5404401c2f 14 */
peyo 0:cd5404401c2f 15
peyo 0:cd5404401c2f 16 // Based on Eclipse Paho.
peyo 0:cd5404401c2f 17 /*******************************************************************************
peyo 0:cd5404401c2f 18 * Copyright (c) 2014 IBM Corp.
peyo 0:cd5404401c2f 19 *
peyo 0:cd5404401c2f 20 * All rights reserved. This program and the accompanying materials
peyo 0:cd5404401c2f 21 * are made available under the terms of the Eclipse Public License v1.0
peyo 0:cd5404401c2f 22 * and Eclipse Distribution License v1.0 which accompany this distribution.
peyo 0:cd5404401c2f 23 *
peyo 0:cd5404401c2f 24 * The Eclipse Public License is available at
peyo 0:cd5404401c2f 25 * http://www.eclipse.org/legal/epl-v10.html
peyo 0:cd5404401c2f 26 * and the Eclipse Distribution License is available at
peyo 0:cd5404401c2f 27 * http://www.eclipse.org/org/documents/edl-v10.php.
peyo 0:cd5404401c2f 28 *
peyo 0:cd5404401c2f 29 * Contributors:
peyo 0:cd5404401c2f 30 * Ian Craggs - initial API and implementation and/or initial documentation
peyo 0:cd5404401c2f 31 * Xiang Rong - 442039 Add makefile to Embedded C client
peyo 0:cd5404401c2f 32 *******************************************************************************/
peyo 0:cd5404401c2f 33
peyo 0:cd5404401c2f 34 /**
peyo 0:cd5404401c2f 35 * @file aws_iot_mqtt_client_common_internal.h
peyo 0:cd5404401c2f 36 * @brief Internal MQTT functions not exposed to application
peyo 0:cd5404401c2f 37 */
peyo 0:cd5404401c2f 38
peyo 0:cd5404401c2f 39 #ifndef AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H
peyo 0:cd5404401c2f 40 #define AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H
peyo 0:cd5404401c2f 41
peyo 0:cd5404401c2f 42 #ifdef __cplusplus
peyo 0:cd5404401c2f 43 extern "C" {
peyo 0:cd5404401c2f 44 #endif
peyo 0:cd5404401c2f 45
peyo 0:cd5404401c2f 46 #include <stdint.h>
peyo 0:cd5404401c2f 47 #include <stddef.h>
peyo 0:cd5404401c2f 48 #include <string.h>
peyo 0:cd5404401c2f 49
peyo 0:cd5404401c2f 50 #include "aws_iot_log.h"
peyo 0:cd5404401c2f 51 #include "aws_iot_mqtt_client_interface.h"
peyo 0:cd5404401c2f 52
peyo 0:cd5404401c2f 53 /* Enum order should match the packet ids array defined in MQTTFormat.c */
peyo 0:cd5404401c2f 54 typedef enum msgTypes {
peyo 0:cd5404401c2f 55 UNKNOWN = -1,
peyo 0:cd5404401c2f 56 CONNECT = 1,
peyo 0:cd5404401c2f 57 CONNACK = 2,
peyo 0:cd5404401c2f 58 PUBLISH = 3,
peyo 0:cd5404401c2f 59 PUBACK = 4,
peyo 0:cd5404401c2f 60 PUBREC = 5,
peyo 0:cd5404401c2f 61 PUBREL = 6,
peyo 0:cd5404401c2f 62 PUBCOMP = 7,
peyo 0:cd5404401c2f 63 SUBSCRIBE = 8,
peyo 0:cd5404401c2f 64 SUBACK = 9,
peyo 0:cd5404401c2f 65 UNSUBSCRIBE = 10,
peyo 0:cd5404401c2f 66 UNSUBACK = 11,
peyo 0:cd5404401c2f 67 PINGREQ = 12,
peyo 0:cd5404401c2f 68 PINGRESP = 13,
peyo 0:cd5404401c2f 69 DISCONNECT = 14
peyo 0:cd5404401c2f 70 } MessageTypes;
peyo 0:cd5404401c2f 71
peyo 0:cd5404401c2f 72 /**
peyo 0:cd5404401c2f 73 * Bitfields for the MQTT header byte.
peyo 0:cd5404401c2f 74 */
peyo 0:cd5404401c2f 75 typedef union {
peyo 0:cd5404401c2f 76 unsigned char byte; /**< the whole byte */
peyo 0:cd5404401c2f 77 #if defined(REVERSED)
peyo 0:cd5404401c2f 78 struct {
peyo 0:cd5404401c2f 79 unsigned int type : 4; /**< message type nibble */
peyo 0:cd5404401c2f 80 unsigned int dup : 1; /**< DUP flag bit */
peyo 0:cd5404401c2f 81 unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */
peyo 0:cd5404401c2f 82 unsigned int retain : 1; /**< retained flag bit */
peyo 0:cd5404401c2f 83 } bits;
peyo 0:cd5404401c2f 84 #else
peyo 0:cd5404401c2f 85 struct {
peyo 0:cd5404401c2f 86 unsigned int retain : 1; /**< retained flag bit */
peyo 0:cd5404401c2f 87 unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */
peyo 0:cd5404401c2f 88 unsigned int dup : 1; /**< DUP flag bit */
peyo 0:cd5404401c2f 89 unsigned int type : 4; /**< message type nibble */
peyo 0:cd5404401c2f 90 } bits;
peyo 0:cd5404401c2f 91 #endif
peyo 0:cd5404401c2f 92 } MQTTHeader;
peyo 0:cd5404401c2f 93
peyo 0:cd5404401c2f 94 IoT_Error_t aws_iot_mqtt_internal_init_header(MQTTHeader *pHeader, MessageTypes message_type,
peyo 0:cd5404401c2f 95 QoS qos, uint8_t dup, uint8_t retained);
peyo 0:cd5404401c2f 96
peyo 0:cd5404401c2f 97 IoT_Error_t aws_iot_mqtt_internal_serialize_ack(unsigned char *pTxBuf, size_t txBufLen,
peyo 0:cd5404401c2f 98 MessageTypes msgType, uint8_t dup, uint16_t packetId,
peyo 0:cd5404401c2f 99 uint32_t *pSerializedLen);
peyo 0:cd5404401c2f 100 IoT_Error_t aws_iot_mqtt_internal_deserialize_ack(unsigned char *, unsigned char *,
peyo 0:cd5404401c2f 101 uint16_t *, unsigned char *, size_t);
peyo 0:cd5404401c2f 102
peyo 0:cd5404401c2f 103 uint32_t aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length(uint32_t rem_len);
peyo 0:cd5404401c2f 104
peyo 0:cd5404401c2f 105 size_t aws_iot_mqtt_internal_write_len_to_buffer(unsigned char *buf, uint32_t length);
peyo 0:cd5404401c2f 106 IoT_Error_t aws_iot_mqtt_internal_decode_remaining_length_from_buffer(unsigned char *buf, uint32_t *decodedLen,
peyo 0:cd5404401c2f 107 uint32_t *readBytesLen);
peyo 0:cd5404401c2f 108
peyo 0:cd5404401c2f 109 uint16_t aws_iot_mqtt_internal_read_uint16_t(unsigned char **pptr);
peyo 0:cd5404401c2f 110 void aws_iot_mqtt_internal_write_uint_16(unsigned char **pptr, uint16_t anInt);
peyo 0:cd5404401c2f 111
peyo 0:cd5404401c2f 112 unsigned char aws_iot_mqtt_internal_read_char(unsigned char **pptr);
peyo 0:cd5404401c2f 113 void aws_iot_mqtt_internal_write_char(unsigned char **pptr, unsigned char c);
peyo 0:cd5404401c2f 114 void aws_iot_mqtt_internal_write_utf8_string(unsigned char **pptr, const char *string, uint16_t stringLen);
peyo 0:cd5404401c2f 115
peyo 0:cd5404401c2f 116 IoT_Error_t aws_iot_mqtt_internal_send_packet(AWS_IoT_Client *pClient, size_t length, TimerAWS *pTimer);
peyo 0:cd5404401c2f 117 IoT_Error_t aws_iot_mqtt_internal_cycle_read(AWS_IoT_Client *pClient, TimerAWS *pTimer, uint8_t *pPacketType);
peyo 0:cd5404401c2f 118 IoT_Error_t aws_iot_mqtt_internal_wait_for_read(AWS_IoT_Client *pClient, uint8_t packetType, TimerAWS *pTimer);
peyo 0:cd5404401c2f 119 IoT_Error_t aws_iot_mqtt_internal_serialize_zero(unsigned char *pTxBuf, size_t txBufLen,
peyo 0:cd5404401c2f 120 MessageTypes packetType, size_t *pSerializedLength);
peyo 0:cd5404401c2f 121 IoT_Error_t aws_iot_mqtt_internal_deserialize_publish(uint8_t *dup, QoS *qos,
peyo 0:cd5404401c2f 122 uint8_t *retained, uint16_t *pPacketId,
peyo 0:cd5404401c2f 123 char **pTopicName, uint16_t *topicNameLen,
peyo 0:cd5404401c2f 124 unsigned char **payload, size_t *payloadLen,
peyo 0:cd5404401c2f 125 unsigned char *pRxBuf, size_t rxBufLen);
peyo 0:cd5404401c2f 126
peyo 0:cd5404401c2f 127 IoT_Error_t aws_iot_mqtt_set_client_state(AWS_IoT_Client *pClient, ClientState expectedCurrentState,
peyo 0:cd5404401c2f 128 ClientState newState);
peyo 0:cd5404401c2f 129
peyo 0:cd5404401c2f 130 #ifdef _ENABLE_THREAD_SUPPORT_
peyo 0:cd5404401c2f 131
peyo 0:cd5404401c2f 132 IoT_Error_t aws_iot_mqtt_client_lock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex);
peyo 0:cd5404401c2f 133
peyo 0:cd5404401c2f 134 IoT_Error_t aws_iot_mqtt_client_unlock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex);
peyo 0:cd5404401c2f 135
peyo 0:cd5404401c2f 136 #endif
peyo 0:cd5404401c2f 137
peyo 0:cd5404401c2f 138 #ifdef __cplusplus
peyo 0:cd5404401c2f 139 }
peyo 0:cd5404401c2f 140 #endif
peyo 0:cd5404401c2f 141
peyo 0:cd5404401c2f 142 #endif /* AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H */