Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
aws_iot_mqtt_client_common_internal.h
00001 /* 00002 * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"). 00005 * You may not use this file except in compliance with the License. 00006 * A copy of the License is located at 00007 * 00008 * http://aws.amazon.com/apache2.0 00009 * 00010 * or in the "license" file accompanying this file. This file is distributed 00011 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 00012 * express or implied. See the License for the specific language governing 00013 * permissions and limitations under the License. 00014 */ 00015 00016 // Based on Eclipse Paho. 00017 /******************************************************************************* 00018 * Copyright (c) 2014 IBM Corp. 00019 * 00020 * All rights reserved. This program and the accompanying materials 00021 * are made available under the terms of the Eclipse Public License v1.0 00022 * and Eclipse Distribution License v1.0 which accompany this distribution. 00023 * 00024 * The Eclipse Public License is available at 00025 * http://www.eclipse.org/legal/epl-v10.html 00026 * and the Eclipse Distribution License is available at 00027 * http://www.eclipse.org/org/documents/edl-v10.php. 00028 * 00029 * Contributors: 00030 * Ian Craggs - initial API and implementation and/or initial documentation 00031 * Xiang Rong - 442039 Add makefile to Embedded C client 00032 *******************************************************************************/ 00033 00034 /** 00035 * @file aws_iot_mqtt_client_common_internal.h 00036 * @brief Internal MQTT functions not exposed to application 00037 */ 00038 00039 #ifndef AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H 00040 #define AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 #include <stdint.h> 00047 #include <stddef.h> 00048 #include <string.h> 00049 00050 #include "aws_iot_log.h" 00051 #include "aws_iot_mqtt_client_interface.h" 00052 00053 /* Enum order should match the packet ids array defined in MQTTFormat.c */ 00054 typedef enum msgTypes { 00055 UNKNOWN = -1, 00056 CONNECT = 1, 00057 CONNACK = 2, 00058 PUBLISH = 3, 00059 PUBACK = 4, 00060 PUBREC = 5, 00061 PUBREL = 6, 00062 PUBCOMP = 7, 00063 SUBSCRIBE = 8, 00064 SUBACK = 9, 00065 UNSUBSCRIBE = 10, 00066 UNSUBACK = 11, 00067 PINGREQ = 12, 00068 PINGRESP = 13, 00069 DISCONNECT = 14 00070 } MessageTypes; 00071 00072 /* Macros for parsing header fields from incoming MQTT frame. */ 00073 #define MQTT_HEADER_FIELD_TYPE(_byte) ((_byte >> 4) & 0x0F) 00074 #define MQTT_HEADER_FIELD_DUP(_byte) ((_byte & (1 << 3)) >> 3) 00075 #define MQTT_HEADER_FIELD_QOS(_byte) ((_byte & (3 << 1)) >> 1) 00076 #define MQTT_HEADER_FIELD_RETAIN(_byte) ((_byte & (1 << 0)) >> 0) 00077 00078 /** 00079 * Bitfields for the MQTT header byte. 00080 */ 00081 typedef union { 00082 unsigned char byte; /**< the whole byte */ 00083 } MQTTHeader; 00084 00085 IoT_Error_t aws_iot_mqtt_internal_init_header(MQTTHeader *pHeader, MessageTypes message_type, 00086 QoS qos, uint8_t dup, uint8_t retained); 00087 00088 IoT_Error_t aws_iot_mqtt_internal_serialize_ack(unsigned char *pTxBuf, size_t txBufLen, 00089 MessageTypes msgType, uint8_t dup, uint16_t packetId, 00090 uint32_t *pSerializedLen); 00091 IoT_Error_t aws_iot_mqtt_internal_deserialize_ack(unsigned char *, unsigned char *, 00092 uint16_t *, unsigned char *, size_t); 00093 00094 uint32_t aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length(uint32_t rem_len); 00095 00096 size_t aws_iot_mqtt_internal_write_len_to_buffer(unsigned char *buf, uint32_t length); 00097 IoT_Error_t aws_iot_mqtt_internal_decode_remaining_length_from_buffer(unsigned char *buf, uint32_t *decodedLen, 00098 uint32_t *readBytesLen); 00099 00100 uint16_t aws_iot_mqtt_internal_read_uint16_t(unsigned char **pptr); 00101 void aws_iot_mqtt_internal_write_uint_16(unsigned char **pptr, uint16_t anInt); 00102 00103 unsigned char aws_iot_mqtt_internal_read_char(unsigned char **pptr); 00104 void aws_iot_mqtt_internal_write_char(unsigned char **pptr, unsigned char c); 00105 void aws_iot_mqtt_internal_write_utf8_string(unsigned char **pptr, const char *string, uint16_t stringLen); 00106 00107 IoT_Error_t aws_iot_mqtt_internal_send_packet(AWS_IoT_Client *pClient, size_t length, awsTimer *pTimer); 00108 IoT_Error_t aws_iot_mqtt_internal_cycle_read(AWS_IoT_Client *pClient, awsTimer *pTimer, uint8_t *pPacketType); 00109 IoT_Error_t aws_iot_mqtt_internal_wait_for_read(AWS_IoT_Client *pClient, uint8_t packetType, awsTimer *pTimer); 00110 IoT_Error_t aws_iot_mqtt_internal_serialize_zero(unsigned char *pTxBuf, size_t txBufLen, 00111 MessageTypes packetType, size_t *pSerializedLength); 00112 IoT_Error_t aws_iot_mqtt_internal_deserialize_publish(uint8_t *dup, QoS *qos, 00113 uint8_t *retained, uint16_t *pPacketId, 00114 char **pTopicName, uint16_t *topicNameLen, 00115 unsigned char **payload, size_t *payloadLen, 00116 unsigned char *pRxBuf, size_t rxBufLen); 00117 00118 IoT_Error_t aws_iot_mqtt_set_client_state(AWS_IoT_Client *pClient, ClientState expectedCurrentState, 00119 ClientState newState); 00120 00121 #ifdef _ENABLE_THREAD_SUPPORT_ 00122 00123 IoT_Error_t aws_iot_mqtt_client_lock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex); 00124 00125 IoT_Error_t aws_iot_mqtt_client_unlock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex); 00126 00127 #endif 00128 00129 #ifdef __cplusplus 00130 } 00131 #endif 00132 00133 #endif /* AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H */
Generated on Tue Jul 12 2022 19:02:38 by
1.7.2