Demo application for using the AT&T IoT Starter Kit Powered by AWS.
Dependencies: SDFileSystem
Fork of ATT_AWS_IoT_demo by
network_interface.h
00001 /* 00002 * Copyright 2010-2015 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 /** 00017 * @file network_interface.h 00018 * @brief Network interface definition for MQTT client. 00019 * 00020 * Defines an interface to the TLS layer to be used by the MQTT client. 00021 * Starting point for porting the SDK to the networking layer of a new platform. 00022 */ 00023 00024 #ifndef __NETWORK_INTERFACE_H_ 00025 #define __NETWORK_INTERFACE_H_ 00026 00027 #include "aws_iot_shadow_interface.h" 00028 00029 //===================================================================================================================== 00030 // 00031 // NOTE: This defines our Network Connection. Only comment in ONE of these defines. This setup allows us to to build 00032 // in multiple network targets in the future that operate off of mbed-os. 00033 // 00034 // The Avnet M14A2A Cellular Shield (uses the AT&T LTE network) 00035 #define USING_AVNET_SHIELD 00036 // 00037 // The FRDM-K64F wired Ethernet lwip 00038 //#define USING_FRDM_K64F_LWIP 00039 //===================================================================================================================== 00040 00041 #ifdef USING_AVNET_SHIELD 00042 // TODO including this here breaks the compiler because of "Timer". Added to network.cpp instead. 00043 /* 00044 #include "WNCTCPSocketConnection.h" 00045 00046 // Exposes the Avnet socket 00047 extern WNCTCPSocketConnection* _tcpsocket; 00048 */ 00049 #endif 00050 00051 #ifdef USING_FRDM_K64F_LWIP 00052 #include "TCPSocket.h" 00053 00054 // Exposes the FRDM socket 00055 extern TCPSocket* _tcpsocket; 00056 #endif 00057 00058 /** 00059 * @brief Network Type 00060 * 00061 * Defines a type for the network struct. See structure definition below. 00062 */ 00063 typedef struct Network Network; 00064 00065 /** 00066 * @brief TLS Connection Parameters 00067 * 00068 * Defines a type containing TLS specific parameters to be passed down to the 00069 * TLS networking layer to create a TLS secured socket. 00070 */ 00071 typedef struct{ 00072 char* pRootCALocation; ///< Pointer to string containing the filename (including path) of the root CA file. 00073 char* pDeviceCertLocation; ///< Pointer to string containing the filename (including path) of the device certificate. 00074 char* pDevicePrivateKeyLocation; ///< Pointer to string containing the filename (including path) of the device private key file. 00075 char* pDestinationURL; ///< Pointer to string containing the endpoint of the MQTT service. 00076 int DestinationPort; ///< Integer defining the connection port of the MQTT service. 00077 unsigned int timeout_ms; ///< Unsigned integer defining the TLS handshake timeout value in milliseconds. 00078 unsigned char ServerVerificationFlag; ///< Boolean. True = perform server certificate hostname validation. False = skip validation \b NOT recommended. 00079 }TLSConnectParams; 00080 00081 /** 00082 * @brief Network Structure 00083 * 00084 * Structure for defining a network connection. 00085 */ 00086 struct Network{ 00087 int my_socket; ///< Integer holding the socket file descriptor 00088 int (*connect) (Network *, TLSConnectParams); 00089 int (*mqttread) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to read from the network 00090 int (*mqttwrite) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to write to the network 00091 void (*disconnect) (Network*); ///< Function pointer pointing to the network function to disconnect from the network 00092 int (*isConnected) (Network*); ///< Function pointer pointing to the network function to check if physical layer is connected 00093 int (*destroy) (Network*); ///< Function pointer pointing to the network function to destroy the network object 00094 }; 00095 00096 /** 00097 * @brief Boots the WNC modem 00098 */ 00099 int net_modem_boot(void); 00100 00101 int mbedtls_mqtt_config_parse_file(ShadowParameters_t *sp, const char *path ); 00102 00103 /** 00104 * @brief Initialize the TLS implementation 00105 * 00106 * Perform any initialization required by the TLS layer. 00107 * Connects the interface to implementation by setting up 00108 * the network layer function pointers to platform implementations. 00109 * 00110 * @param pNetwork - Pointer to a Network struct defining the network interface. 00111 * @return integer defining successful initialization or TLS error 00112 */ 00113 int iot_tls_init(Network *pNetwork); 00114 00115 /** 00116 * @brief Create a TLS socket and open the connection 00117 * 00118 * Creates an open socket connection including TLS handshake. 00119 * 00120 * @param pNetwork - Pointer to a Network struct defining the network interface. 00121 * @param TLSParams - TLSConnectParams defines the properties of the TLS connection. 00122 * @return integer - successful connection or TLS error 00123 */ 00124 int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams); 00125 00126 /** 00127 * @brief Write bytes to the network socket 00128 * 00129 * @param Network - Pointer to a Network struct defining the network interface. 00130 * @param unsigned char pointer - buffer to write to socket 00131 * @param integer - number of bytes to write 00132 * @param integer - write timeout value in milliseconds 00133 * @return integer - number of bytes written or TLS error 00134 */ 00135 int iot_tls_write(Network*, unsigned char*, int, int); 00136 00137 /** 00138 * @brief Read bytes from the network socket 00139 * 00140 * @param Network - Pointer to a Network struct defining the network interface. 00141 * @param unsigned char pointer - pointer to buffer where read bytes should be copied 00142 * @param integer - number of bytes to read 00143 * @param integer - read timeout value in milliseconds 00144 * @return integer - number of bytes read or TLS error 00145 */ 00146 int iot_tls_read(Network*, unsigned char*, int, int); 00147 00148 /** 00149 * @brief Disconnect from network socket 00150 * 00151 * @param Network - Pointer to a Network struct defining the network interface. 00152 */ 00153 void iot_tls_disconnect(Network *pNetwork); 00154 00155 /** 00156 * @brief Perform any tear-down or cleanup of TLS layer 00157 * 00158 * Called to cleanup any resources required for the TLS layer. 00159 * 00160 * @param Network - Pointer to a Network struct defining the network interface. 00161 * @return integer - successful cleanup or TLS error 00162 */ 00163 int iot_tls_destroy(Network *pNetwork); 00164 00165 /** 00166 * @brief Check if TLS layer is still connected 00167 * 00168 * Called to check if the TLS layer is still connected or not. 00169 * 00170 * @param Network - Pointer to a Network struct defining the network interface. 00171 * @return int - integer indicating status of network physical layer connection 00172 */ 00173 int iot_tls_is_connected(Network *pNetwork); 00174 00175 #endif //__NETWORK_INTERFACE_H_ 00176 00177
Generated on Tue Jul 12 2022 22:13:21 by 1.7.2