![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
V.06 11/3
Dependencies: FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts
Fork of ATT_AWS_IoT_demo by
AWS_openssl/aws_iot_src/protocol/mqtt/aws_iot_embedded_client_wrapper/network_interface.h@15:6f2798e45099, 2016-12-01 (annotated)
- Committer:
- ampembeng
- Date:
- Thu Dec 01 18:05:38 2016 +0000
- Revision:
- 15:6f2798e45099
- Child:
- 16:02008a2a2569
Initial commit. Demo works with both the FRDM wired Ethernet and the Avnet Shield wireless modem.
Who changed what in which revision?
User | Revision | Line number | New 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 | 15:6f2798e45099 | 27 | //===================================================================================================================== |
ampembeng | 15:6f2798e45099 | 28 | // |
ampembeng | 15:6f2798e45099 | 29 | // NOTE: Internet Connection |
ampembeng | 15:6f2798e45099 | 30 | // The Avnet M14A2A Cellular Shield uses the AT&T LTE network by default. If you want to debug with the |
ampembeng | 15:6f2798e45099 | 31 | // FRDM-K64F wired Ethernet comment this define out. |
ampembeng | 15:6f2798e45099 | 32 | // |
ampembeng | 15:6f2798e45099 | 33 | #define USING_AVNET_SHIELD |
ampembeng | 15:6f2798e45099 | 34 | //===================================================================================================================== |
ampembeng | 15:6f2798e45099 | 35 | |
ampembeng | 15:6f2798e45099 | 36 | #ifdef USING_AVNET_SHIELD |
ampembeng | 15:6f2798e45099 | 37 | // TODO including this here breaks the compile because of "Timer" |
ampembeng | 15:6f2798e45099 | 38 | //#include "WNCTCPSocketConnection.h" |
ampembeng | 15:6f2798e45099 | 39 | // Exposes the Avnet socket |
ampembeng | 15:6f2798e45099 | 40 | //extern WNCTCPSocketConnection* _tcpsocket; |
ampembeng | 15:6f2798e45099 | 41 | #else |
ampembeng | 15:6f2798e45099 | 42 | #include "TCPSocket.h" |
ampembeng | 15:6f2798e45099 | 43 | // Exposes the FRDM socket |
ampembeng | 15:6f2798e45099 | 44 | extern TCPSocket* _tcpsocket; |
ampembeng | 15:6f2798e45099 | 45 | #endif |
ampembeng | 15:6f2798e45099 | 46 | |
ampembeng | 15:6f2798e45099 | 47 | /** |
ampembeng | 15:6f2798e45099 | 48 | * @brief Network Type |
ampembeng | 15:6f2798e45099 | 49 | * |
ampembeng | 15:6f2798e45099 | 50 | * Defines a type for the network struct. See structure definition below. |
ampembeng | 15:6f2798e45099 | 51 | */ |
ampembeng | 15:6f2798e45099 | 52 | typedef struct Network Network; |
ampembeng | 15:6f2798e45099 | 53 | |
ampembeng | 15:6f2798e45099 | 54 | /** |
ampembeng | 15:6f2798e45099 | 55 | * @brief TLS Connection Parameters |
ampembeng | 15:6f2798e45099 | 56 | * |
ampembeng | 15:6f2798e45099 | 57 | * Defines a type containing TLS specific parameters to be passed down to the |
ampembeng | 15:6f2798e45099 | 58 | * TLS networking layer to create a TLS secured socket. |
ampembeng | 15:6f2798e45099 | 59 | */ |
ampembeng | 15:6f2798e45099 | 60 | typedef struct{ |
ampembeng | 15:6f2798e45099 | 61 | char* pRootCALocation; ///< Pointer to string containing the filename (including path) of the root CA file. |
ampembeng | 15:6f2798e45099 | 62 | char* pDeviceCertLocation; ///< Pointer to string containing the filename (including path) of the device certificate. |
ampembeng | 15:6f2798e45099 | 63 | char* pDevicePrivateKeyLocation; ///< Pointer to string containing the filename (including path) of the device private key file. |
ampembeng | 15:6f2798e45099 | 64 | char* pDestinationURL; ///< Pointer to string containing the endpoint of the MQTT service. |
ampembeng | 15:6f2798e45099 | 65 | int DestinationPort; ///< Integer defining the connection port of the MQTT service. |
ampembeng | 15:6f2798e45099 | 66 | unsigned int timeout_ms; ///< Unsigned integer defining the TLS handshake timeout value in milliseconds. |
ampembeng | 15:6f2798e45099 | 67 | unsigned char ServerVerificationFlag; ///< Boolean. True = perform server certificate hostname validation. False = skip validation \b NOT recommended. |
ampembeng | 15:6f2798e45099 | 68 | }TLSConnectParams; |
ampembeng | 15:6f2798e45099 | 69 | |
ampembeng | 15:6f2798e45099 | 70 | /** |
ampembeng | 15:6f2798e45099 | 71 | * @brief Network Structure |
ampembeng | 15:6f2798e45099 | 72 | * |
ampembeng | 15:6f2798e45099 | 73 | * Structure for defining a network connection. |
ampembeng | 15:6f2798e45099 | 74 | */ |
ampembeng | 15:6f2798e45099 | 75 | struct Network{ |
ampembeng | 15:6f2798e45099 | 76 | int my_socket; ///< Integer holding the socket file descriptor |
ampembeng | 15:6f2798e45099 | 77 | int (*connect) (Network *, TLSConnectParams); |
ampembeng | 15:6f2798e45099 | 78 | int (*mqttread) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to read from the network |
ampembeng | 15:6f2798e45099 | 79 | int (*mqttwrite) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to write to the network |
ampembeng | 15:6f2798e45099 | 80 | void (*disconnect) (Network*); ///< Function pointer pointing to the network function to disconnect from the network |
ampembeng | 15:6f2798e45099 | 81 | int (*isConnected) (Network*); ///< Function pointer pointing to the network function to check if physical layer is connected |
ampembeng | 15:6f2798e45099 | 82 | int (*destroy) (Network*); ///< Function pointer pointing to the network function to destroy the network object |
ampembeng | 15:6f2798e45099 | 83 | }; |
ampembeng | 15:6f2798e45099 | 84 | |
ampembeng | 15:6f2798e45099 | 85 | /** |
ampembeng | 15:6f2798e45099 | 86 | * @brief Boots the WNC modem |
ampembeng | 15:6f2798e45099 | 87 | */ |
ampembeng | 15:6f2798e45099 | 88 | int net_modem_boot(void); |
ampembeng | 15:6f2798e45099 | 89 | |
ampembeng | 15:6f2798e45099 | 90 | /** |
ampembeng | 15:6f2798e45099 | 91 | * @brief Initialize the TLS implementation |
ampembeng | 15:6f2798e45099 | 92 | * |
ampembeng | 15:6f2798e45099 | 93 | * Perform any initialization required by the TLS layer. |
ampembeng | 15:6f2798e45099 | 94 | * Connects the interface to implementation by setting up |
ampembeng | 15:6f2798e45099 | 95 | * the network layer function pointers to platform implementations. |
ampembeng | 15:6f2798e45099 | 96 | * |
ampembeng | 15:6f2798e45099 | 97 | * @param pNetwork - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 98 | * @return integer defining successful initialization or TLS error |
ampembeng | 15:6f2798e45099 | 99 | */ |
ampembeng | 15:6f2798e45099 | 100 | int iot_tls_init(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 101 | |
ampembeng | 15:6f2798e45099 | 102 | /** |
ampembeng | 15:6f2798e45099 | 103 | * @brief Create a TLS socket and open the connection |
ampembeng | 15:6f2798e45099 | 104 | * |
ampembeng | 15:6f2798e45099 | 105 | * Creates an open socket connection including TLS handshake. |
ampembeng | 15:6f2798e45099 | 106 | * |
ampembeng | 15:6f2798e45099 | 107 | * @param pNetwork - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 108 | * @param TLSParams - TLSConnectParams defines the properties of the TLS connection. |
ampembeng | 15:6f2798e45099 | 109 | * @return integer - successful connection or TLS error |
ampembeng | 15:6f2798e45099 | 110 | */ |
ampembeng | 15:6f2798e45099 | 111 | int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams); |
ampembeng | 15:6f2798e45099 | 112 | |
ampembeng | 15:6f2798e45099 | 113 | /** |
ampembeng | 15:6f2798e45099 | 114 | * @brief Write bytes to the network socket |
ampembeng | 15:6f2798e45099 | 115 | * |
ampembeng | 15:6f2798e45099 | 116 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 117 | * @param unsigned char pointer - buffer to write to socket |
ampembeng | 15:6f2798e45099 | 118 | * @param integer - number of bytes to write |
ampembeng | 15:6f2798e45099 | 119 | * @param integer - write timeout value in milliseconds |
ampembeng | 15:6f2798e45099 | 120 | * @return integer - number of bytes written or TLS error |
ampembeng | 15:6f2798e45099 | 121 | */ |
ampembeng | 15:6f2798e45099 | 122 | int iot_tls_write(Network*, unsigned char*, int, int); |
ampembeng | 15:6f2798e45099 | 123 | |
ampembeng | 15:6f2798e45099 | 124 | /** |
ampembeng | 15:6f2798e45099 | 125 | * @brief Read bytes from the network socket |
ampembeng | 15:6f2798e45099 | 126 | * |
ampembeng | 15:6f2798e45099 | 127 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 128 | * @param unsigned char pointer - pointer to buffer where read bytes should be copied |
ampembeng | 15:6f2798e45099 | 129 | * @param integer - number of bytes to read |
ampembeng | 15:6f2798e45099 | 130 | * @param integer - read timeout value in milliseconds |
ampembeng | 15:6f2798e45099 | 131 | * @return integer - number of bytes read or TLS error |
ampembeng | 15:6f2798e45099 | 132 | */ |
ampembeng | 15:6f2798e45099 | 133 | int iot_tls_read(Network*, unsigned char*, int, int); |
ampembeng | 15:6f2798e45099 | 134 | |
ampembeng | 15:6f2798e45099 | 135 | /** |
ampembeng | 15:6f2798e45099 | 136 | * @brief Disconnect from network socket |
ampembeng | 15:6f2798e45099 | 137 | * |
ampembeng | 15:6f2798e45099 | 138 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 139 | */ |
ampembeng | 15:6f2798e45099 | 140 | void iot_tls_disconnect(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 141 | |
ampembeng | 15:6f2798e45099 | 142 | /** |
ampembeng | 15:6f2798e45099 | 143 | * @brief Perform any tear-down or cleanup of TLS layer |
ampembeng | 15:6f2798e45099 | 144 | * |
ampembeng | 15:6f2798e45099 | 145 | * Called to cleanup any resources required for the TLS layer. |
ampembeng | 15:6f2798e45099 | 146 | * |
ampembeng | 15:6f2798e45099 | 147 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 148 | * @return integer - successful cleanup or TLS error |
ampembeng | 15:6f2798e45099 | 149 | */ |
ampembeng | 15:6f2798e45099 | 150 | int iot_tls_destroy(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 151 | |
ampembeng | 15:6f2798e45099 | 152 | /** |
ampembeng | 15:6f2798e45099 | 153 | * @brief Check if TLS layer is still connected |
ampembeng | 15:6f2798e45099 | 154 | * |
ampembeng | 15:6f2798e45099 | 155 | * Called to check if the TLS layer is still connected or not. |
ampembeng | 15:6f2798e45099 | 156 | * |
ampembeng | 15:6f2798e45099 | 157 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 158 | * @return int - integer indicating status of network physical layer connection |
ampembeng | 15:6f2798e45099 | 159 | */ |
ampembeng | 15:6f2798e45099 | 160 | int iot_tls_is_connected(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 161 | |
ampembeng | 15:6f2798e45099 | 162 | #endif //__NETWORK_INTERFACE_H_ |
ampembeng | 15:6f2798e45099 | 163 | |
ampembeng | 15:6f2798e45099 | 164 |