![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
DIYmall 0.96" Inch I2c IIC Serial 128x64 Oled LCD LED White Display Module
Dependencies: Adafruit_GFX SDFileSystem
Fork of ATT_AWS_IoT_demo by
AWS_openssl/aws_iot_src/protocol/mqtt/aws_iot_embedded_client_wrapper/network_interface.h@28:4650c541b029, 2018-10-09 (annotated)
- Committer:
- afmiee
- Date:
- Tue Oct 09 20:57:34 2018 +0000
- Revision:
- 28:4650c541b029
- Parent:
- 20:ee34856ae510
DIYmall 0.96" Inch I2c IIC Serial 128x64 Oled LCD LED White Display Module
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 | 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); |
ampembeng | 15:6f2798e45099 | 100 | |
ampembeng | 18:6370da1de572 | 101 | int mbedtls_mqtt_config_parse_file(ShadowParameters_t *sp, const char *path ); |
ampembeng | 18:6370da1de572 | 102 | |
ampembeng | 15:6f2798e45099 | 103 | /** |
ampembeng | 15:6f2798e45099 | 104 | * @brief Initialize the TLS implementation |
ampembeng | 15:6f2798e45099 | 105 | * |
ampembeng | 15:6f2798e45099 | 106 | * Perform any initialization required by the TLS layer. |
ampembeng | 15:6f2798e45099 | 107 | * Connects the interface to implementation by setting up |
ampembeng | 15:6f2798e45099 | 108 | * the network layer function pointers to platform implementations. |
ampembeng | 15:6f2798e45099 | 109 | * |
ampembeng | 15:6f2798e45099 | 110 | * @param pNetwork - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 111 | * @return integer defining successful initialization or TLS error |
ampembeng | 15:6f2798e45099 | 112 | */ |
ampembeng | 15:6f2798e45099 | 113 | int iot_tls_init(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 114 | |
ampembeng | 15:6f2798e45099 | 115 | /** |
ampembeng | 15:6f2798e45099 | 116 | * @brief Create a TLS socket and open the connection |
ampembeng | 15:6f2798e45099 | 117 | * |
ampembeng | 15:6f2798e45099 | 118 | * Creates an open socket connection including TLS handshake. |
ampembeng | 15:6f2798e45099 | 119 | * |
ampembeng | 15:6f2798e45099 | 120 | * @param pNetwork - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 121 | * @param TLSParams - TLSConnectParams defines the properties of the TLS connection. |
ampembeng | 15:6f2798e45099 | 122 | * @return integer - successful connection or TLS error |
ampembeng | 15:6f2798e45099 | 123 | */ |
ampembeng | 15:6f2798e45099 | 124 | int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams); |
ampembeng | 15:6f2798e45099 | 125 | |
ampembeng | 15:6f2798e45099 | 126 | /** |
ampembeng | 15:6f2798e45099 | 127 | * @brief Write bytes to the network socket |
ampembeng | 15:6f2798e45099 | 128 | * |
ampembeng | 15:6f2798e45099 | 129 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 130 | * @param unsigned char pointer - buffer to write to socket |
ampembeng | 15:6f2798e45099 | 131 | * @param integer - number of bytes to write |
ampembeng | 15:6f2798e45099 | 132 | * @param integer - write timeout value in milliseconds |
ampembeng | 15:6f2798e45099 | 133 | * @return integer - number of bytes written or TLS error |
ampembeng | 15:6f2798e45099 | 134 | */ |
ampembeng | 15:6f2798e45099 | 135 | int iot_tls_write(Network*, unsigned char*, int, int); |
ampembeng | 15:6f2798e45099 | 136 | |
ampembeng | 15:6f2798e45099 | 137 | /** |
ampembeng | 15:6f2798e45099 | 138 | * @brief Read bytes from the network socket |
ampembeng | 15:6f2798e45099 | 139 | * |
ampembeng | 15:6f2798e45099 | 140 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 141 | * @param unsigned char pointer - pointer to buffer where read bytes should be copied |
ampembeng | 15:6f2798e45099 | 142 | * @param integer - number of bytes to read |
ampembeng | 15:6f2798e45099 | 143 | * @param integer - read timeout value in milliseconds |
ampembeng | 15:6f2798e45099 | 144 | * @return integer - number of bytes read or TLS error |
ampembeng | 15:6f2798e45099 | 145 | */ |
ampembeng | 15:6f2798e45099 | 146 | int iot_tls_read(Network*, unsigned char*, int, int); |
ampembeng | 15:6f2798e45099 | 147 | |
ampembeng | 15:6f2798e45099 | 148 | /** |
ampembeng | 15:6f2798e45099 | 149 | * @brief Disconnect from network socket |
ampembeng | 15:6f2798e45099 | 150 | * |
ampembeng | 15:6f2798e45099 | 151 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 152 | */ |
ampembeng | 15:6f2798e45099 | 153 | void iot_tls_disconnect(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 154 | |
ampembeng | 15:6f2798e45099 | 155 | /** |
ampembeng | 15:6f2798e45099 | 156 | * @brief Perform any tear-down or cleanup of TLS layer |
ampembeng | 15:6f2798e45099 | 157 | * |
ampembeng | 15:6f2798e45099 | 158 | * Called to cleanup any resources required for the TLS layer. |
ampembeng | 15:6f2798e45099 | 159 | * |
ampembeng | 15:6f2798e45099 | 160 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 161 | * @return integer - successful cleanup or TLS error |
ampembeng | 15:6f2798e45099 | 162 | */ |
ampembeng | 15:6f2798e45099 | 163 | int iot_tls_destroy(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 164 | |
ampembeng | 15:6f2798e45099 | 165 | /** |
ampembeng | 15:6f2798e45099 | 166 | * @brief Check if TLS layer is still connected |
ampembeng | 15:6f2798e45099 | 167 | * |
ampembeng | 15:6f2798e45099 | 168 | * Called to check if the TLS layer is still connected or not. |
ampembeng | 15:6f2798e45099 | 169 | * |
ampembeng | 15:6f2798e45099 | 170 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 171 | * @return int - integer indicating status of network physical layer connection |
ampembeng | 15:6f2798e45099 | 172 | */ |
ampembeng | 15:6f2798e45099 | 173 | int iot_tls_is_connected(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 174 | |
ampembeng | 15:6f2798e45099 | 175 | #endif //__NETWORK_INTERFACE_H_ |
ampembeng | 15:6f2798e45099 | 176 | |
ampembeng | 15:6f2798e45099 | 177 |