AWS IoT Device SDK C: Platform
Platform portability layer
Return to main page ↑
iot_network.h
Go to the documentation of this file.
1 /*
2  * IoT Platform V1.1.0
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
28 #ifndef IOT_NETWORK_H_
29 #define IOT_NETWORK_H_
30 
31 /* The config header is always included first. */
32 #include "iot_config.h"
33 
34 /* Standard includes. */
35 #include <stdint.h>
36 #include <stdlib.h>
37 
38 /* Platform types include. */
40 
45 typedef enum IotNetworkError
46 {
53 
58 typedef enum IotNetworkCloseReason
59 {
66 
112 /* @[declare_platform_network_receivecallback] */
113 typedef void ( * IotNetworkReceiveCallback_t )( IotNetworkConnection_t pConnection,
114  void * pContext );
115 /* @[declare_platform_network_receivecallback] */
116 
128 /* @[declare_platform_network_closecallback] */
129 typedef void ( * IotNetworkCloseCallback_t )( IotNetworkConnection_t pConnection,
131  void * pContext );
132 /* @[declare_platform_network_closecallback] */
133 
147 /* @[declare_platform_network_create] */
149  IotNetworkCredentials_t pCredentialInfo,
150  IotNetworkConnection_t * pConnection );
151 /* @[declare_platform_network_create] */
152 
173 /* @[declare_platform_network_setreceivecallback] */
175  IotNetworkReceiveCallback_t receiveCallback,
176  void * pContext );
177 /* @[declare_platform_network_setreceivecallback] */
178 
199 /* @[declare_platform_network_setclosecallback] */
201  IotNetworkCloseCallback_t closeCallback,
202  void * pContext );
203 /* @[declare_platform_network_setclosecallback] */
204 
219 /* @[declare_platform_network_send] */
220 typedef size_t ( * IotNetworkSend_t )( IotNetworkConnection_t pConnection,
221  const uint8_t * pMessage,
222  size_t messageLength );
223 /* @[declare_platform_network_send] */
224 
241 /* @[declare_platform_network_receive] */
242 typedef size_t ( * IotNetworkReceive_t )( IotNetworkConnection_t pConnection,
243  uint8_t * pBuffer,
244  size_t bytesRequested );
245 /* @[declare_platform_network_receive] */
246 
266 /* @[declare_platform_network_close] */
267 typedef IotNetworkError_t ( * IotNetworkClose_t )( IotNetworkConnection_t pConnection );
268 /* @[declare_platform_network_close] */
269 
285 /* @[declare_platform_network_destroy] */
287 /* @[declare_platform_network_destroy] */
288 
296 typedef struct IotNetworkInterface
297 {
298  IotNetworkCreate_t create;
299  IotNetworkSetReceiveCallback_t setReceiveCallback;
300  IotNetworkSetCloseCallback_t setCloseCallback;
301  IotNetworkSend_t send;
302  IotNetworkReceive_t receive;
303  IotNetworkClose_t close;
304  IotNetworkDestroy_t destroy;
306 
316 {
317  const char * pHostName;
318  uint16_t port;
319 };
320 
330 {
340  const char * pAlpnProtos;
350 
354  bool disableSni;
355 
356  const char * pRootCa;
357  size_t rootCaSize;
358  const char * pClientCert;
359  size_t clientCertSize;
360  const char * pPrivateKey;
361  size_t privateKeySize;
362  const char * pUserName;
363  size_t userNameSize;
364  const char * pPassword;
365  size_t passwordSize;
366 };
367 
368 #endif /* ifndef IOT_NETWORK_H_ */
IotNetworkCloseReason_t
Disconnect reasons for the network close callback.
Definition: iot_network.h:58
_IotNetworkCredentials_t IotNetworkCredentials_t
The type used to represent network credentials, configured with the type _IotNetworkCredentials_t.
Definition: iot_platform_types.h:160
Definition: iot_network.h:64
uint16_t port
Server port in host-order.
Definition: iot_network.h:363
Definition: iot_network.h:61
Types of the platform layer.
const char * pPrivateKey
String representing the client certificate&#39;s private key.
Definition: iot_network.h:405
IotNetworkError_t(* IotNetworkCreate_t)(IotNetworkServerInfo_t pServerInfo, IotNetworkCredentials_t pCredentialInfo, IotNetworkConnection_t *pConnection)
Create a new network connection.
Definition: iot_network.h:193
void(* IotNetworkCloseCallback_t)(IotNetworkConnection_t pConnection, IotNetworkCloseReason_t reason, void *pContext)
Provide an asynchronous notification of network closing.
Definition: iot_network.h:174
const char * pHostName
Server host name. Must be NULL-terminated.
Definition: iot_network.h:362
_IotNetworkConnection_t IotNetworkConnection_t
The type used to represent network connections, configured with the type _IotNetworkConnection_t.
Definition: iot_platform_types.h:170
size_t(* IotNetworkSend_t)(IotNetworkConnection_t pConnection, const uint8_t *pMessage, size_t messageLength)
Send data over a return connection.
Definition: iot_network.h:265
Represents the functions of a network stack.
Definition: iot_network.h:341
const char * pAlpnProtos
Set this to a non-NULL value to use ALPN.
Definition: iot_network.h:385
size_t(* IotNetworkReceive_t)(IotNetworkConnection_t pConnection, uint8_t *pBuffer, size_t bytesRequested)
Block and wait for incoming network data.
Definition: iot_network.h:287
IotNetworkError_t(* IotNetworkDestroy_t)(IotNetworkConnection_t pConnection)
Free resources used by a network connection.
Definition: iot_network.h:331
IotNetworkError_t(* IotNetworkSetReceiveCallback_t)(IotNetworkConnection_t pConnection, IotNetworkReceiveCallback_t receiveCallback, void *pContext)
Register an IotNetworkReceiveCallback_t.
Definition: iot_network.h:219
Definition: iot_network.h:51
const char * pPassword
String representing the password for MQTT.
Definition: iot_network.h:409
size_t privateKeySize
Size associated with IotNetworkCredentials.pPrivateKey.
Definition: iot_network.h:406
Definition: iot_network.h:50
Information on the remote server for connection setup.
Definition: iot_network.h:360
size_t passwordSize
Size associated with IotNetworkCredentials.pPassword.
Definition: iot_network.h:410
Definition: iot_network.h:48
IotNetworkError_t
Return codes for network functions.
Definition: iot_network.h:45
bool disableSni
Disable server name indication (SNI) for a TLS session.
Definition: iot_network.h:399
const char * pClientCert
String representing the client certificate.
Definition: iot_network.h:403
size_t rootCaSize
Size associated with IotNetworkCredentials.pRootCa.
Definition: iot_network.h:402
Contains the credentials necessary for connection setup.
Definition: iot_network.h:374
Definition: iot_network.h:47
const char * pRootCa
String representing a trusted server root certificate.
Definition: iot_network.h:401
void(* IotNetworkReceiveCallback_t)(IotNetworkConnection_t pConnection, void *pContext)
Provide an asynchronous notification of incoming network data.
Definition: iot_network.h:158
IotNetworkError_t(* IotNetworkClose_t)(IotNetworkConnection_t pConnection)
Close a network connection.
Definition: iot_network.h:312
Definition: iot_network.h:63
Definition: iot_network.h:62
size_t clientCertSize
Size associated with IotNetworkCredentials.pClientCert.
Definition: iot_network.h:404
size_t userNameSize
Size associated with IotNetworkCredentials.pUserName.
Definition: iot_network.h:408
_IotNetworkServerInfo_t IotNetworkServerInfo_t
The type used to represent network server info, configured with the type _IotNetworkServerInfo_t.
Definition: iot_platform_types.h:145
size_t maxFragmentLength
Set this to a non-zero value to use TLS max fragment length negotiation (TLS MFLN).
Definition: iot_network.h:394
const char * pUserName
String representing the username for MQTT.
Definition: iot_network.h:407
Definition: iot_network.h:60
Definition: iot_network.h:49
IotNetworkError_t(* IotNetworkSetCloseCallback_t)(IotNetworkConnection_t pConnection, IotNetworkCloseCallback_t closeCallback, void *pContext)
Register an IotNetworkReceiveCallback_t.
Definition: iot_network.h:245