![](/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@16:02008a2a2569, 2016-12-02 (annotated)
- Committer:
- ampembeng
- Date:
- Fri Dec 02 22:39:56 2016 +0000
- Revision:
- 16:02008a2a2569
- Parent:
- 15:6f2798e45099
- Child:
- 18:6370da1de572
Cleaned up some project TODOs added a quick start guide to the README.md that's in the root folder.
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 | 16:02008a2a2569 | 29 | // NOTE: This defines our Network Connection. Only comment in ONE of these defines. This setup allows us to to build |
ampembeng | 16:02008a2a2569 | 30 | // in multiple network targets in the future that operate off of mbed-os. |
ampembeng | 15:6f2798e45099 | 31 | // |
ampembeng | 16:02008a2a2569 | 32 | // The Avnet M14A2A Cellular Shield (uses the AT&T LTE network) |
ampembeng | 15:6f2798e45099 | 33 | #define USING_AVNET_SHIELD |
ampembeng | 16:02008a2a2569 | 34 | // |
ampembeng | 16:02008a2a2569 | 35 | // The FRDM-K64F wired Ethernet lwip |
ampembeng | 16:02008a2a2569 | 36 | //#define USING_FRDM_K64F_LWIP |
ampembeng | 15:6f2798e45099 | 37 | //===================================================================================================================== |
ampembeng | 15:6f2798e45099 | 38 | |
ampembeng | 15:6f2798e45099 | 39 | #ifdef USING_AVNET_SHIELD |
ampembeng | 16:02008a2a2569 | 40 | // TODO including this here breaks the compiler because of "Timer". Added to network.cpp instead. |
ampembeng | 16:02008a2a2569 | 41 | /* |
ampembeng | 16:02008a2a2569 | 42 | #include "WNCTCPSocketConnection.h" |
ampembeng | 16:02008a2a2569 | 43 | |
ampembeng | 15:6f2798e45099 | 44 | // Exposes the Avnet socket |
ampembeng | 16:02008a2a2569 | 45 | extern WNCTCPSocketConnection* _tcpsocket; |
ampembeng | 16:02008a2a2569 | 46 | */ |
ampembeng | 16:02008a2a2569 | 47 | #endif |
ampembeng | 16:02008a2a2569 | 48 | |
ampembeng | 16:02008a2a2569 | 49 | #ifdef USING_FRDM_K64F_LWIP |
ampembeng | 15:6f2798e45099 | 50 | #include "TCPSocket.h" |
ampembeng | 16:02008a2a2569 | 51 | |
ampembeng | 15:6f2798e45099 | 52 | // Exposes the FRDM socket |
ampembeng | 15:6f2798e45099 | 53 | extern TCPSocket* _tcpsocket; |
ampembeng | 15:6f2798e45099 | 54 | #endif |
ampembeng | 15:6f2798e45099 | 55 | |
ampembeng | 15:6f2798e45099 | 56 | /** |
ampembeng | 15:6f2798e45099 | 57 | * @brief Network Type |
ampembeng | 15:6f2798e45099 | 58 | * |
ampembeng | 15:6f2798e45099 | 59 | * Defines a type for the network struct. See structure definition below. |
ampembeng | 15:6f2798e45099 | 60 | */ |
ampembeng | 15:6f2798e45099 | 61 | typedef struct Network Network; |
ampembeng | 15:6f2798e45099 | 62 | |
ampembeng | 15:6f2798e45099 | 63 | /** |
ampembeng | 15:6f2798e45099 | 64 | * @brief TLS Connection Parameters |
ampembeng | 15:6f2798e45099 | 65 | * |
ampembeng | 15:6f2798e45099 | 66 | * Defines a type containing TLS specific parameters to be passed down to the |
ampembeng | 15:6f2798e45099 | 67 | * TLS networking layer to create a TLS secured socket. |
ampembeng | 15:6f2798e45099 | 68 | */ |
ampembeng | 15:6f2798e45099 | 69 | typedef struct{ |
ampembeng | 15:6f2798e45099 | 70 | char* pRootCALocation; ///< Pointer to string containing the filename (including path) of the root CA file. |
ampembeng | 15:6f2798e45099 | 71 | char* pDeviceCertLocation; ///< Pointer to string containing the filename (including path) of the device certificate. |
ampembeng | 15:6f2798e45099 | 72 | char* pDevicePrivateKeyLocation; ///< Pointer to string containing the filename (including path) of the device private key file. |
ampembeng | 15:6f2798e45099 | 73 | char* pDestinationURL; ///< Pointer to string containing the endpoint of the MQTT service. |
ampembeng | 15:6f2798e45099 | 74 | int DestinationPort; ///< Integer defining the connection port of the MQTT service. |
ampembeng | 15:6f2798e45099 | 75 | unsigned int timeout_ms; ///< Unsigned integer defining the TLS handshake timeout value in milliseconds. |
ampembeng | 15:6f2798e45099 | 76 | unsigned char ServerVerificationFlag; ///< Boolean. True = perform server certificate hostname validation. False = skip validation \b NOT recommended. |
ampembeng | 15:6f2798e45099 | 77 | }TLSConnectParams; |
ampembeng | 15:6f2798e45099 | 78 | |
ampembeng | 15:6f2798e45099 | 79 | /** |
ampembeng | 15:6f2798e45099 | 80 | * @brief Network Structure |
ampembeng | 15:6f2798e45099 | 81 | * |
ampembeng | 15:6f2798e45099 | 82 | * Structure for defining a network connection. |
ampembeng | 15:6f2798e45099 | 83 | */ |
ampembeng | 15:6f2798e45099 | 84 | struct Network{ |
ampembeng | 15:6f2798e45099 | 85 | int my_socket; ///< Integer holding the socket file descriptor |
ampembeng | 15:6f2798e45099 | 86 | int (*connect) (Network *, TLSConnectParams); |
ampembeng | 15:6f2798e45099 | 87 | int (*mqttread) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to read from the network |
ampembeng | 15:6f2798e45099 | 88 | int (*mqttwrite) (Network*, unsigned char*, int, int); ///< Function pointer pointing to the network function to write to the network |
ampembeng | 15:6f2798e45099 | 89 | void (*disconnect) (Network*); ///< Function pointer pointing to the network function to disconnect from the network |
ampembeng | 15:6f2798e45099 | 90 | int (*isConnected) (Network*); ///< Function pointer pointing to the network function to check if physical layer is connected |
ampembeng | 15:6f2798e45099 | 91 | int (*destroy) (Network*); ///< Function pointer pointing to the network function to destroy the network object |
ampembeng | 15:6f2798e45099 | 92 | }; |
ampembeng | 15:6f2798e45099 | 93 | |
ampembeng | 15:6f2798e45099 | 94 | /** |
ampembeng | 15:6f2798e45099 | 95 | * @brief Boots the WNC modem |
ampembeng | 15:6f2798e45099 | 96 | */ |
ampembeng | 15:6f2798e45099 | 97 | int net_modem_boot(void); |
ampembeng | 15:6f2798e45099 | 98 | |
ampembeng | 15:6f2798e45099 | 99 | /** |
ampembeng | 15:6f2798e45099 | 100 | * @brief Initialize the TLS implementation |
ampembeng | 15:6f2798e45099 | 101 | * |
ampembeng | 15:6f2798e45099 | 102 | * Perform any initialization required by the TLS layer. |
ampembeng | 15:6f2798e45099 | 103 | * Connects the interface to implementation by setting up |
ampembeng | 15:6f2798e45099 | 104 | * the network layer function pointers to platform implementations. |
ampembeng | 15:6f2798e45099 | 105 | * |
ampembeng | 15:6f2798e45099 | 106 | * @param pNetwork - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 107 | * @return integer defining successful initialization or TLS error |
ampembeng | 15:6f2798e45099 | 108 | */ |
ampembeng | 15:6f2798e45099 | 109 | int iot_tls_init(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 110 | |
ampembeng | 15:6f2798e45099 | 111 | /** |
ampembeng | 15:6f2798e45099 | 112 | * @brief Create a TLS socket and open the connection |
ampembeng | 15:6f2798e45099 | 113 | * |
ampembeng | 15:6f2798e45099 | 114 | * Creates an open socket connection including TLS handshake. |
ampembeng | 15:6f2798e45099 | 115 | * |
ampembeng | 15:6f2798e45099 | 116 | * @param pNetwork - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 117 | * @param TLSParams - TLSConnectParams defines the properties of the TLS connection. |
ampembeng | 15:6f2798e45099 | 118 | * @return integer - successful connection or TLS error |
ampembeng | 15:6f2798e45099 | 119 | */ |
ampembeng | 15:6f2798e45099 | 120 | int iot_tls_connect(Network *pNetwork, TLSConnectParams TLSParams); |
ampembeng | 15:6f2798e45099 | 121 | |
ampembeng | 15:6f2798e45099 | 122 | /** |
ampembeng | 15:6f2798e45099 | 123 | * @brief Write bytes to the network socket |
ampembeng | 15:6f2798e45099 | 124 | * |
ampembeng | 15:6f2798e45099 | 125 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 126 | * @param unsigned char pointer - buffer to write to socket |
ampembeng | 15:6f2798e45099 | 127 | * @param integer - number of bytes to write |
ampembeng | 15:6f2798e45099 | 128 | * @param integer - write timeout value in milliseconds |
ampembeng | 15:6f2798e45099 | 129 | * @return integer - number of bytes written or TLS error |
ampembeng | 15:6f2798e45099 | 130 | */ |
ampembeng | 15:6f2798e45099 | 131 | int iot_tls_write(Network*, unsigned char*, int, int); |
ampembeng | 15:6f2798e45099 | 132 | |
ampembeng | 15:6f2798e45099 | 133 | /** |
ampembeng | 15:6f2798e45099 | 134 | * @brief Read bytes from the network socket |
ampembeng | 15:6f2798e45099 | 135 | * |
ampembeng | 15:6f2798e45099 | 136 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 137 | * @param unsigned char pointer - pointer to buffer where read bytes should be copied |
ampembeng | 15:6f2798e45099 | 138 | * @param integer - number of bytes to read |
ampembeng | 15:6f2798e45099 | 139 | * @param integer - read timeout value in milliseconds |
ampembeng | 15:6f2798e45099 | 140 | * @return integer - number of bytes read or TLS error |
ampembeng | 15:6f2798e45099 | 141 | */ |
ampembeng | 15:6f2798e45099 | 142 | int iot_tls_read(Network*, unsigned char*, int, int); |
ampembeng | 15:6f2798e45099 | 143 | |
ampembeng | 15:6f2798e45099 | 144 | /** |
ampembeng | 15:6f2798e45099 | 145 | * @brief Disconnect from network socket |
ampembeng | 15:6f2798e45099 | 146 | * |
ampembeng | 15:6f2798e45099 | 147 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 148 | */ |
ampembeng | 15:6f2798e45099 | 149 | void iot_tls_disconnect(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 150 | |
ampembeng | 15:6f2798e45099 | 151 | /** |
ampembeng | 15:6f2798e45099 | 152 | * @brief Perform any tear-down or cleanup of TLS layer |
ampembeng | 15:6f2798e45099 | 153 | * |
ampembeng | 15:6f2798e45099 | 154 | * Called to cleanup any resources required for the TLS layer. |
ampembeng | 15:6f2798e45099 | 155 | * |
ampembeng | 15:6f2798e45099 | 156 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 157 | * @return integer - successful cleanup or TLS error |
ampembeng | 15:6f2798e45099 | 158 | */ |
ampembeng | 15:6f2798e45099 | 159 | int iot_tls_destroy(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 160 | |
ampembeng | 15:6f2798e45099 | 161 | /** |
ampembeng | 15:6f2798e45099 | 162 | * @brief Check if TLS layer is still connected |
ampembeng | 15:6f2798e45099 | 163 | * |
ampembeng | 15:6f2798e45099 | 164 | * Called to check if the TLS layer is still connected or not. |
ampembeng | 15:6f2798e45099 | 165 | * |
ampembeng | 15:6f2798e45099 | 166 | * @param Network - Pointer to a Network struct defining the network interface. |
ampembeng | 15:6f2798e45099 | 167 | * @return int - integer indicating status of network physical layer connection |
ampembeng | 15:6f2798e45099 | 168 | */ |
ampembeng | 15:6f2798e45099 | 169 | int iot_tls_is_connected(Network *pNetwork); |
ampembeng | 15:6f2798e45099 | 170 | |
ampembeng | 15:6f2798e45099 | 171 | #endif //__NETWORK_INTERFACE_H_ |
ampembeng | 15:6f2798e45099 | 172 | |
ampembeng | 15:6f2798e45099 | 173 |