V.06 11/3
Dependencies: FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts
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 int GetSignalStrength(int16_t *dbm); 00101 int GetUpdateStatus(unsigned char *cStatus); 00102 int GetAllObjects(); 00103 00104 int mbedtls_mqtt_config_parse_file(ShadowParameters_t *sp, const char *path ); 00105 00106 /** 00107 * @brief Initialize the TLS implementation 00108 * 00109 * Perform any initialization required by the TLS layer. 00110 * Connects the interface to implementation by setting up 00111 * the network layer function pointers to platform implementations. 00112 * 00113 * @param pNetwork - Pointer to a Network struct defining the network interface. 00114 * @return integer defining successful initialization or TLS error 00115 */ 00116 int iot_tls_init(Network *pNetwork); 00117 00118 /** 00119 * @brief Create a TLS socket and open the connection 00120 * 00121 * Creates an open socket connection including TLS handshake. 00122 * 00123 * @param pNetwork - Pointer to a Network struct defining the network interface. 00124 * @param TLSParams - TLSConnectParams defines the properties of the TLS connection. 00125 * @return integer - successful connection or TLS error 00126 */ 00127 int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams); 00128 00129 /** 00130 * @brief Write bytes to the network socket 00131 * 00132 * @param Network - Pointer to a Network struct defining the network interface. 00133 * @param unsigned char pointer - buffer to write to socket 00134 * @param integer - number of bytes to write 00135 * @param integer - write timeout value in milliseconds 00136 * @return integer - number of bytes written or TLS error 00137 */ 00138 int iot_tls_write(Network*, unsigned char*, int, int); 00139 00140 /** 00141 * @brief Read bytes from the network socket 00142 * 00143 * @param Network - Pointer to a Network struct defining the network interface. 00144 * @param unsigned char pointer - pointer to buffer where read bytes should be copied 00145 * @param integer - number of bytes to read 00146 * @param integer - read timeout value in milliseconds 00147 * @return integer - number of bytes read or TLS error 00148 */ 00149 int iot_tls_read(Network*, unsigned char*, int, int); 00150 00151 /** 00152 * @brief Disconnect from network socket 00153 * 00154 * @param Network - Pointer to a Network struct defining the network interface. 00155 */ 00156 void iot_tls_disconnect(Network *pNetwork); 00157 00158 /** 00159 * @brief Perform any tear-down or cleanup of TLS layer 00160 * 00161 * Called to cleanup any resources required for the TLS layer. 00162 * 00163 * @param Network - Pointer to a Network struct defining the network interface. 00164 * @return integer - successful cleanup or TLS error 00165 */ 00166 int iot_tls_destroy(Network *pNetwork); 00167 00168 /** 00169 * @brief Check if TLS layer is still connected 00170 * 00171 * Called to check if the TLS layer is still connected or not. 00172 * 00173 * @param Network - Pointer to a Network struct defining the network interface. 00174 * @return int - integer indicating status of network physical layer connection 00175 */ 00176 int iot_tls_is_connected(Network *pNetwork); 00177 00178 #endif //__NETWORK_INTERFACE_H_ 00179 00180
Generated on Tue Jul 12 2022 14:16:20 by 1.7.2