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