V.06 11/3

Dependencies:   FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts

Fork of ATT_AWS_IoT_demo by attiot

Committer:
jilee
Date:
Fri Nov 03 20:28:02 2017 +0000
Revision:
29:f71a0be59b99
Parent:
20:ee34856ae510
v.06 11/03/2016

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ampembeng 15:6f2798e45099 1 /*
ampembeng 15:6f2798e45099 2 * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
ampembeng 15:6f2798e45099 3 *
ampembeng 15:6f2798e45099 4 * Licensed under the Apache License, Version 2.0 (the "License").
ampembeng 15:6f2798e45099 5 * You may not use this file except in compliance with the License.
ampembeng 15:6f2798e45099 6 * A copy of the License is located at
ampembeng 15:6f2798e45099 7 *
ampembeng 15:6f2798e45099 8 * http://aws.amazon.com/apache2.0
ampembeng 15:6f2798e45099 9 *
ampembeng 15:6f2798e45099 10 * or in the "license" file accompanying this file. This file is distributed
ampembeng 15:6f2798e45099 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
ampembeng 15:6f2798e45099 12 * express or implied. See the License for the specific language governing
ampembeng 15:6f2798e45099 13 * permissions and limitations under the License.
ampembeng 15:6f2798e45099 14 */
ampembeng 15:6f2798e45099 15
ampembeng 15:6f2798e45099 16 /**
ampembeng 15:6f2798e45099 17 * @file network_interface.h
ampembeng 15:6f2798e45099 18 * @brief Network interface definition for MQTT client.
ampembeng 15:6f2798e45099 19 *
ampembeng 15:6f2798e45099 20 * Defines an interface to the TLS layer to be used by the MQTT client.
ampembeng 15:6f2798e45099 21 * Starting point for porting the SDK to the networking layer of a new platform.
ampembeng 15:6f2798e45099 22 */
ampembeng 15:6f2798e45099 23
ampembeng 15:6f2798e45099 24 #ifndef __NETWORK_INTERFACE_H_
ampembeng 15:6f2798e45099 25 #define __NETWORK_INTERFACE_H_
ampembeng 15:6f2798e45099 26
ampembeng 18:6370da1de572 27 #include "aws_iot_shadow_interface.h"
ampembeng 18:6370da1de572 28
ampembeng 15:6f2798e45099 29 //=====================================================================================================================
ampembeng 15:6f2798e45099 30 //
ampembeng 16:02008a2a2569 31 // NOTE: This defines our Network Connection. Only comment in ONE of these defines. This setup allows us to to build
ampembeng 16:02008a2a2569 32 // in multiple network targets in the future that operate off of mbed-os.
ampembeng 15:6f2798e45099 33 //
ampembeng 16:02008a2a2569 34 // The Avnet M14A2A Cellular Shield (uses the AT&T LTE network)
ampembeng 20:ee34856ae510 35 #define USING_AVNET_SHIELD
ampembeng 16:02008a2a2569 36 //
ampembeng 16:02008a2a2569 37 // The FRDM-K64F wired Ethernet lwip
ampembeng 20:ee34856ae510 38 //#define USING_FRDM_K64F_LWIP
ampembeng 15:6f2798e45099 39 //=====================================================================================================================
ampembeng 15:6f2798e45099 40
ampembeng 15:6f2798e45099 41 #ifdef USING_AVNET_SHIELD
ampembeng 16:02008a2a2569 42 // TODO including this here breaks the compiler because of "Timer". Added to network.cpp instead.
ampembeng 16:02008a2a2569 43 /*
ampembeng 16:02008a2a2569 44 #include "WNCTCPSocketConnection.h"
ampembeng 16:02008a2a2569 45
ampembeng 15:6f2798e45099 46 // Exposes the Avnet socket
ampembeng 16:02008a2a2569 47 extern WNCTCPSocketConnection* _tcpsocket;
ampembeng 16:02008a2a2569 48 */
ampembeng 16:02008a2a2569 49 #endif
ampembeng 16:02008a2a2569 50
ampembeng 16:02008a2a2569 51 #ifdef USING_FRDM_K64F_LWIP
ampembeng 15:6f2798e45099 52 #include "TCPSocket.h"
ampembeng 16:02008a2a2569 53
ampembeng 15:6f2798e45099 54 // Exposes the FRDM socket
ampembeng 15:6f2798e45099 55 extern TCPSocket* _tcpsocket;
ampembeng 15:6f2798e45099 56 #endif
ampembeng 15:6f2798e45099 57
ampembeng 15:6f2798e45099 58 /**
ampembeng 15:6f2798e45099 59 * @brief Network Type
ampembeng 15:6f2798e45099 60 *
ampembeng 15:6f2798e45099 61 * Defines a type for the network struct. See structure definition below.
ampembeng 15:6f2798e45099 62 */
ampembeng 15:6f2798e45099 63 typedef struct Network Network;
ampembeng 15:6f2798e45099 64
ampembeng 15:6f2798e45099 65 /**
ampembeng 15:6f2798e45099 66 * @brief TLS Connection Parameters
ampembeng 15:6f2798e45099 67 *
ampembeng 15:6f2798e45099 68 * Defines a type containing TLS specific parameters to be passed down to the
ampembeng 15:6f2798e45099 69 * TLS networking layer to create a TLS secured socket.
ampembeng 15:6f2798e45099 70 */
ampembeng 15:6f2798e45099 71 typedef struct{
ampembeng 15:6f2798e45099 72 char* pRootCALocation; ///< Pointer to string containing the filename (including path) of the root CA file.
ampembeng 15:6f2798e45099 73 char* pDeviceCertLocation; ///< Pointer to string containing the filename (including path) of the device certificate.
ampembeng 15:6f2798e45099 74 char* pDevicePrivateKeyLocation; ///< Pointer to string containing the filename (including path) of the device private key file.
ampembeng 15:6f2798e45099 75 char* pDestinationURL; ///< Pointer to string containing the endpoint of the MQTT service.
ampembeng 15:6f2798e45099 76 int DestinationPort; ///< Integer defining the connection port of the MQTT service.
ampembeng 15:6f2798e45099 77 unsigned int timeout_ms; ///< Unsigned integer defining the TLS handshake timeout value in milliseconds.
ampembeng 15:6f2798e45099 78 unsigned char ServerVerificationFlag; ///< Boolean. True = perform server certificate hostname validation. False = skip validation \b NOT recommended.
ampembeng 15:6f2798e45099 79 }TLSConnectParams;
ampembeng 15:6f2798e45099 80
ampembeng 15:6f2798e45099 81 /**
ampembeng 15:6f2798e45099 82 * @brief Network Structure
ampembeng 15:6f2798e45099 83 *
ampembeng 15:6f2798e45099 84 * Structure for defining a network connection.
ampembeng 15:6f2798e45099 85 */
ampembeng 15:6f2798e45099 86 struct Network{
ampembeng 15:6f2798e45099 87 int my_socket; ///< Integer holding the socket file descriptor
ampembeng 15:6f2798e45099 88 int (*connect) (Network *, TLSConnectParams);
ampembeng 15:6f2798e45099 89 int (*mqttread) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to read from the network
ampembeng 15:6f2798e45099 90 int (*mqttwrite) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to write to the network
ampembeng 15:6f2798e45099 91 void (*disconnect) (Network*); ///< Function pointer pointing to the network function to disconnect from the network
ampembeng 15:6f2798e45099 92 int (*isConnected) (Network*); ///< Function pointer pointing to the network function to check if physical layer is connected
ampembeng 15:6f2798e45099 93 int (*destroy) (Network*); ///< Function pointer pointing to the network function to destroy the network object
ampembeng 15:6f2798e45099 94 };
ampembeng 15:6f2798e45099 95
ampembeng 15:6f2798e45099 96 /**
ampembeng 15:6f2798e45099 97 * @brief Boots the WNC modem
ampembeng 15:6f2798e45099 98 */
ampembeng 15:6f2798e45099 99 int net_modem_boot(void);
jilee 29:f71a0be59b99 100 int GetSignalStrength(int16_t *dbm);
jilee 29:f71a0be59b99 101 int GetUpdateStatus(unsigned char *cStatus);
jilee 29:f71a0be59b99 102 int GetAllObjects();
ampembeng 15:6f2798e45099 103
ampembeng 18:6370da1de572 104 int mbedtls_mqtt_config_parse_file(ShadowParameters_t *sp, const char *path );
ampembeng 18:6370da1de572 105
ampembeng 15:6f2798e45099 106 /**
ampembeng 15:6f2798e45099 107 * @brief Initialize the TLS implementation
ampembeng 15:6f2798e45099 108 *
ampembeng 15:6f2798e45099 109 * Perform any initialization required by the TLS layer.
ampembeng 15:6f2798e45099 110 * Connects the interface to implementation by setting up
ampembeng 15:6f2798e45099 111 * the network layer function pointers to platform implementations.
ampembeng 15:6f2798e45099 112 *
ampembeng 15:6f2798e45099 113 * @param pNetwork - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 114 * @return integer defining successful initialization or TLS error
ampembeng 15:6f2798e45099 115 */
ampembeng 15:6f2798e45099 116 int iot_tls_init(Network *pNetwork);
ampembeng 15:6f2798e45099 117
ampembeng 15:6f2798e45099 118 /**
ampembeng 15:6f2798e45099 119 * @brief Create a TLS socket and open the connection
ampembeng 15:6f2798e45099 120 *
ampembeng 15:6f2798e45099 121 * Creates an open socket connection including TLS handshake.
ampembeng 15:6f2798e45099 122 *
ampembeng 15:6f2798e45099 123 * @param pNetwork - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 124 * @param TLSParams - TLSConnectParams defines the properties of the TLS connection.
ampembeng 15:6f2798e45099 125 * @return integer - successful connection or TLS error
ampembeng 15:6f2798e45099 126 */
ampembeng 15:6f2798e45099 127 int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams);
ampembeng 15:6f2798e45099 128
ampembeng 15:6f2798e45099 129 /**
ampembeng 15:6f2798e45099 130 * @brief Write bytes to the network socket
ampembeng 15:6f2798e45099 131 *
ampembeng 15:6f2798e45099 132 * @param Network - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 133 * @param unsigned char pointer - buffer to write to socket
ampembeng 15:6f2798e45099 134 * @param integer - number of bytes to write
ampembeng 15:6f2798e45099 135 * @param integer - write timeout value in milliseconds
ampembeng 15:6f2798e45099 136 * @return integer - number of bytes written or TLS error
ampembeng 15:6f2798e45099 137 */
ampembeng 15:6f2798e45099 138 int iot_tls_write(Network*, unsigned char*, int, int);
ampembeng 15:6f2798e45099 139
ampembeng 15:6f2798e45099 140 /**
ampembeng 15:6f2798e45099 141 * @brief Read bytes from the network socket
ampembeng 15:6f2798e45099 142 *
ampembeng 15:6f2798e45099 143 * @param Network - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 144 * @param unsigned char pointer - pointer to buffer where read bytes should be copied
ampembeng 15:6f2798e45099 145 * @param integer - number of bytes to read
ampembeng 15:6f2798e45099 146 * @param integer - read timeout value in milliseconds
ampembeng 15:6f2798e45099 147 * @return integer - number of bytes read or TLS error
ampembeng 15:6f2798e45099 148 */
ampembeng 15:6f2798e45099 149 int iot_tls_read(Network*, unsigned char*, int, int);
ampembeng 15:6f2798e45099 150
ampembeng 15:6f2798e45099 151 /**
ampembeng 15:6f2798e45099 152 * @brief Disconnect from network socket
ampembeng 15:6f2798e45099 153 *
ampembeng 15:6f2798e45099 154 * @param Network - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 155 */
ampembeng 15:6f2798e45099 156 void iot_tls_disconnect(Network *pNetwork);
ampembeng 15:6f2798e45099 157
ampembeng 15:6f2798e45099 158 /**
ampembeng 15:6f2798e45099 159 * @brief Perform any tear-down or cleanup of TLS layer
ampembeng 15:6f2798e45099 160 *
ampembeng 15:6f2798e45099 161 * Called to cleanup any resources required for the TLS layer.
ampembeng 15:6f2798e45099 162 *
ampembeng 15:6f2798e45099 163 * @param Network - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 164 * @return integer - successful cleanup or TLS error
ampembeng 15:6f2798e45099 165 */
ampembeng 15:6f2798e45099 166 int iot_tls_destroy(Network *pNetwork);
ampembeng 15:6f2798e45099 167
ampembeng 15:6f2798e45099 168 /**
ampembeng 15:6f2798e45099 169 * @brief Check if TLS layer is still connected
ampembeng 15:6f2798e45099 170 *
ampembeng 15:6f2798e45099 171 * Called to check if the TLS layer is still connected or not.
ampembeng 15:6f2798e45099 172 *
ampembeng 15:6f2798e45099 173 * @param Network - Pointer to a Network struct defining the network interface.
ampembeng 15:6f2798e45099 174 * @return int - integer indicating status of network physical layer connection
ampembeng 15:6f2798e45099 175 */
ampembeng 15:6f2798e45099 176 int iot_tls_is_connected(Network *pNetwork);
ampembeng 15:6f2798e45099 177
ampembeng 15:6f2798e45099 178 #endif //__NETWORK_INTERFACE_H_
ampembeng 15:6f2798e45099 179
ampembeng 15:6f2798e45099 180