Skip to content

Commit 4ffe458

Browse files
author
Pani
committed
Paho name changed to Eclipse Paho
Renamed the Makefiles in the samples directory Device Shadow - Delete functionality macro fixed subscribe_publish_sample.c file updated This commit closes #1, closes #3
1 parent 8c43511 commit 4ffe458

File tree

13 files changed

+528
-14
lines changed

13 files changed

+528
-14
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
## 1.0.0 (October 8, 2015)
1+
## [1.0.1](https://github.com/aws/aws-iot-device-sdk-embedded-C/releases/tag/v1.0.1) (October 21,2015)
2+
3+
Bugfixes/Improvements:
4+
- Paho name changed to Eclipse Paho
5+
- Renamed the Makefiles in the samples directory
6+
- Device Shadow - Delete functionality macro fixed
7+
- `subscribe_publish_sample` updated
8+
9+
## [1.0.0](https://github.com/aws/aws-iot-device-sdk-embedded-C/releases/tag/v1.0.0) (October 8, 2015)
210

311
Features:
412
- Release to github

PortingGuide.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
The scope of this document is to provide instructions to modify the provided source files and functions in of this SDK to run in a variety of embedded C–based environments (e.g. real-time OS, embedded Linux) and to be adjusted to use a specific TLS implementation as available with specific hardware platforms.
55

66
##Contents of the SDK
7-
The SDK ported for linux could be downloaded from this link The C-code files of this SDK are delivered via the following directory structure (see comment behind folder name for an explanation of its content).
7+
8+
The SDK ported for linux can be downloaded from the below links.
9+
* [OpenSSL](https://s3.amazonaws.com/aws-iot-device-sdk-embedded-c/linux_mqtt_openssl-1.0.1.tar)
10+
* [mbedTLS from ARM](https://s3.amazonaws.com/aws-iot-device-sdk-embedded-c/linux_mqtt_mbedtls-1.0.1.tar)
11+
12+
The C-code files of this SDK are delivered via the following directory structure (see comment behind folder name for an explanation of its content).
813

914
Directory structure Current SDK Directory Layout (OpenSSL)
1015

@@ -30,7 +35,7 @@ All makefiles in this SDK were configured using the documented folder structure
3035

3136
`aws_mqtt_embedded_client_lib` : The source code for the Embedded C MQTT client. This client is a modified version of the [Eclipse Paho](http://www.eclipse.org/paho/clients/c/embedded/) Embedded C client. The modifications include improved keep alive handling (callback on disconnect), a fix for unsubscribe functionality, buffer protection against too large MQTT messages and additional callback context to allow for a better layered architecture of the AWS IoT SDK.
3237

33-
`certs` : This directory is initially empty and will need to contain the private key, the client certificate and the root CA. The client certificate and private key can be downloaded from the AWS IoT console or be created using the AWS CLI commands. The root CA can be downloaded from here.
38+
`certs` : This directory is initially empty and will need to contain the private key, the client certificate and the root CA. The client certificate and private key can be downloaded from the AWS IoT console or be created using the AWS CLI commands. The root CA can be downloaded from [Symantec](https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem).
3439

3540
`docs` : SDK API and file documentation.
3641

@@ -66,9 +71,9 @@ left_ms - query time in milliseconds left on the timer.
6671

6772
###Network Functions
6873

69-
In order to for the MQTT client stack to be able to communicate via the TCP/IP network protocol stack using a mutually authenticated TLS connection, the following API calls need to be implemented for your platform.
74+
In order for the MQTT client stack to be able to communicate via the TCP/IP network protocol stack using a mutually authenticated TLS connection, the following API calls need to be implemented for your platform.
7075

71-
For additional details about API parameters refer to the API documentation.
76+
For additional details about API parameters refer to the [API documentation](http://aws-iot-device-sdk-embedded-c-docs.s3-website-us-east-1.amazonaws.com/index.html).
7277

7378
```
7479
int iot_tls_init(Network *pNetwork);

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Ensure you understand the AWS IoT platform and create the necessary certificates
2929

3030
In order to quickly get started with the AWS IoT platform, we have ported the SDK for POSIX type Operating Systems like Ubuntu, OS X and RHEL. The porting of the SDK happens at the TLS layer, and for the MQTT protocol. The SDK is configured for two TLS libraries and can be built out of the box with *GCC* using *make utility*. The tarballs can be downloaded from the below links.
3131

32-
* [OpenSSL](https://s3.amazonaws.com/aws-iot-device-sdk-embedded-c/linux_mqtt_openssl-1.0.0.tar)
33-
* [mbedTLS from ARM](https://s3.amazonaws.com/aws-iot-device-sdk-embedded-c/linux_mqtt_mbedtls-1.0.0.tar)
32+
* [OpenSSL](https://s3.amazonaws.com/aws-iot-device-sdk-embedded-c/linux_mqtt_openssl-1.0.1.tar)
33+
* [mbedTLS from ARM](https://s3.amazonaws.com/aws-iot-device-sdk-embedded-c/linux_mqtt_mbedtls-1.0.1.tar)
3434

3535
##Installation
3636
This section explains the individual steps to retrieve the necessary files and be able to build your first application using the AWS IoT device SDK for embedded C.
@@ -53,7 +53,7 @@ Steps:
5353
* Explore the example. It connects to AWS IoT platform using MQTT and demonstrates few actions that can be performed by the SDK
5454
* Build the example using make. (''make'')
5555
* Place device identity cert and private key in locations referenced in the example (certs/). Alternatively, you can run the sample application with the ''-c'' flag to point to a specific certificate directory.
56-
* Download certificate authority CA file from this [link](https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem) and place in location referenced in the example (certs/). Ensure the names of the cert files are the same as in the `aws_iot_config.h` file
56+
* Download certificate authority CA file from [Symantec](https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem) and place in location referenced in the example (certs/). Ensure the names of the cert files are the same as in the `aws_iot_config.h` file
5757
* Run sample application (./subscribe_publish_sample or ./shadow_sample). The sample will print status messages to stdout.
5858
* More information on the examples could be found in the sample source file
5959

@@ -95,4 +95,4 @@ ShadowUpdateStatusCallback,
9595
pCallbackContext,
9696
TIMEOUT_4SEC,
9797
persistenSubscription);
98-
```
98+
```

aws_iot_src/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl/network_openssl_wrapper.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
#include <openssl/x509_vfy.h>
2121
#include <sys/socket.h>
2222
#include <fcntl.h>
23+
#include <errno.h>
24+
#include <string.h>
2325
#include <sys/select.h>
2426
#include <arpa/inet.h>
2527
#include <netinet/in.h>
2628
#include <netdb.h>
2729

2830
#include "aws_iot_error.h"
31+
#include "aws_iot_log.h"
2932
#include "network_interface.h"
3033
#include "openssl_hostname_validation.h"
3134

@@ -57,6 +60,7 @@ int iot_tls_init(Network *pNetwork) {
5760
method = TLSv1_2_method();
5861

5962
if ((pSSLContext = SSL_CTX_new(method)) == NULL) {
63+
ERROR(" SSL INIT Failed - Unable to create SSL Context");
6064
ret_val = SSL_INIT_ERROR;
6165
}
6266

@@ -103,14 +107,17 @@ int iot_tls_connect(Network *pNetwork, TLSConnectParams params) {
103107
}
104108

105109
if (!SSL_CTX_load_verify_locations(pSSLContext, params.pRootCALocation, NULL)) {
110+
ERROR(" Root CA Loading error");
106111
ret_val = SSL_CERT_ERROR;
107112
}
108113

109114
if (!SSL_CTX_use_certificate_file(pSSLContext, params.pDeviceCertLocation, SSL_FILETYPE_PEM)) {
115+
ERROR(" Device Certificate Loading error");
110116
ret_val = SSL_CERT_ERROR;
111117
}
112118

113119
if(1 != SSL_CTX_use_PrivateKey_file(pSSLContext, params.pDevicePrivateKeyLocation, SSL_FILETYPE_PEM)){
120+
ERROR(" Device Private Key Loading error");
114121
ret_val = SSL_CERT_ERROR;
115122
}
116123
if(params.ServerVerificationFlag){
@@ -125,23 +132,29 @@ int iot_tls_connect(Network *pNetwork, TLSConnectParams params) {
125132
pDestinationURL = params.pDestinationURL;
126133
ret_val = Connect_TCPSocket(server_TCPSocket, params.pDestinationURL, params.DestinationPort);
127134
if(NONE_ERROR != ret_val){
135+
ERROR(" TCP Connection error");
128136
return ret_val;
129137
}
130138

131139
SSL_set_fd(pSSLHandle, server_TCPSocket);
132140

133-
if(NONE_ERROR == ret_val){
141+
if(ret_val == NONE_ERROR){
134142
ret_val = setSocketToNonBlocking(server_TCPSocket);
143+
if(ret_val != NONE_ERROR){
144+
ERROR(" Unable to set the socket to Non-Blocking");
145+
}
135146
}
136147

137148
if(NONE_ERROR == ret_val){
138149
ret_val = ConnectOrTimeoutOrExitOnError(pSSLHandle, params.timeout_ms);
139150
if(X509_V_OK != SSL_get_verify_result(pSSLHandle)){
151+
ERROR(" Server Certificate Verification failed");
140152
ret_val = SSL_CONNECT_ERROR;
141153
}
142154
else{
143155
// ensure you have a valid certificate returned, otherwise no certificate exchange happened
144156
if(NULL == SSL_get_peer_certificate(pSSLHandle)){
157+
ERROR(" No certificate exchange happened");
145158
ret_val = SSL_CONNECT_ERROR;
146159
}
147160
}
@@ -210,6 +223,7 @@ IoT_Error_t setSocketToNonBlocking( server_fd) {
210223

211224
status = fcntl(server_TCPSocket, F_SETFL, flags | O_NONBLOCK);
212225
if (status < 0) {
226+
ERROR("fcntl - %s", strerror(errno));
213227
ret_val = TCP_CONNECT_ERROR;
214228
}
215229

@@ -247,8 +261,10 @@ IoT_Error_t ConnectOrTimeoutOrExitOnError(SSL *pSSL, int timeout_ms){
247261
FD_SET(server_TCPSocket, &readFds);
248262
select_retCode = select(server_TCPSocket + 1, (void *) &readFds, NULL, NULL, &timeout);
249263
if (SELECT_TIMEOUT == select_retCode) {
264+
ERROR(" SSL Connect time out while waiting for read");
250265
ret_val = SSL_CONNECT_TIMEOUT_ERROR;
251266
} else if (SELECT_ERROR == select_retCode) {
267+
ERROR(" SSL Connect Select error for read %d", select_retCode);
252268
ret_val = SSL_CONNECT_ERROR;
253269
}
254270
}
@@ -258,8 +274,10 @@ IoT_Error_t ConnectOrTimeoutOrExitOnError(SSL *pSSL, int timeout_ms){
258274
FD_SET(server_TCPSocket, &writeFds);
259275
select_retCode = select(server_TCPSocket + 1, NULL, (void *) &writeFds, NULL, &timeout);
260276
if (SELECT_TIMEOUT == select_retCode) {
277+
ERROR(" SSL Connect time out while waiting for write");
261278
ret_val = SSL_CONNECT_TIMEOUT_ERROR;
262279
} else if (SELECT_ERROR == select_retCode) {
280+
ERROR(" SSL Connect Select error for write %d", select_retCode);
263281
ret_val = SSL_CONNECT_ERROR;
264282
}
265283
}

aws_iot_src/shadow/aws_iot_shadow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ IoT_Error_t aws_iot_shadow_delete(MQTTClient_t *pClient, const char *pThingName,
143143

144144
char deleteRequestJsonBuf[MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE];
145145
iot_shadow_delete_request_json(deleteRequestJsonBuf);
146-
ret_val = iot_shadow_action(pClient, pThingName, SHADOW_GET, deleteRequestJsonBuf, callback, pContextData,
146+
ret_val = iot_shadow_action(pClient, pThingName, SHADOW_DELETE, deleteRequestJsonBuf, callback, pContextData,
147147
timeout_seconds, isPersistentSubscribe);
148148

149149
return ret_val;

aws_iot_src/utils/aws_iot_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/**
4040
* @brief PATCH version when backwards-compatible bug fixes are made.
4141
*/
42-
#define VERSION_PATCH 0
42+
#define VERSION_PATCH 1
4343
/**
4444
* @brief TAG is an (optional) tag appended to the version if a more descriptive verion is needed.
4545
*/
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
CC = gcc
2+
3+
#remove @ for no make command prints
4+
DEBUG=@
5+
6+
APP_DIR = .
7+
APP_INCLUDE_DIRS += -I $(APP_DIR)
8+
APP_NAME=shadow_sample
9+
APP_SRC_FILES=$(APP_NAME).c
10+
11+
#IoT client directory
12+
IOT_CLIENT_DIR=../../aws_iot_src
13+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt
14+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper
15+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux
16+
IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR)
17+
IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR)
18+
IOT_INCLUDE_DIRS += -I $(SHADOW_SRC_DIR)
19+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/utils
20+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/shadow
21+
22+
PLATFORM_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/mbedtls
23+
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
24+
SHADOW_SRC_DIR= $(IOT_CLIENT_DIR)/shadow
25+
26+
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/aws_iot_mqtt_embedded_client_wrapper.c
27+
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/utils/jsmn.c
28+
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/utils/aws_iot_json_utils.c
29+
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
30+
IOT_SRC_FILES += $(shell find $(SHADOW_SRC_DIR)/ -name '*.c')
31+
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
32+
33+
#MQTT Paho Embedded C client directory
34+
MQTT_DIR = ../../aws_mqtt_embedded_client_lib
35+
MQTT_C_DIR = $(MQTT_DIR)/MQTTClient-C/src
36+
MQTT_EMB_DIR = $(MQTT_DIR)/MQTTPacket/src
37+
38+
MQTT_INCLUDE_DIR += -I $(MQTT_EMB_DIR)
39+
MQTT_INCLUDE_DIR += -I $(MQTT_C_DIR)
40+
41+
MQTT_SRC_FILES += $(shell find $(MQTT_EMB_DIR)/ -name '*.c')
42+
MQTT_SRC_FILES += $(MQTT_C_DIR)/MQTTClient.c
43+
44+
45+
#TLS - mbedtls
46+
MBEDTLS_DIR=../../mbedtls_lib
47+
TLS_LIB_DIR = $(MBEDTLS_DIR)/library
48+
TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include
49+
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
50+
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
51+
LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a
52+
53+
54+
#Aggregate all include and src directories
55+
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
56+
INCLUDE_ALL_DIRS += $(MQTT_INCLUDE_DIR)
57+
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
58+
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
59+
60+
SRC_FILES += $(MQTT_SRC_FILES)
61+
SRC_FILES += $(APP_SRC_FILES)
62+
SRC_FILES += $(IOT_SRC_FILES)
63+
64+
# Logging level control
65+
LOG_FLAGS += -DIOT_DEBUG
66+
LOG_FLAGS += -DIOT_INFO
67+
LOG_FLAGS += -DIOT_WARN
68+
LOG_FLAGS += -DIOT_ERROR
69+
70+
COMPILER_FLAGS += -g
71+
COMPILER_FLAGS += $(LOG_FLAGS)
72+
73+
MBED_TLS_MAKE_CMD = cd $(MBEDTLS_DIR) && make
74+
75+
PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD)
76+
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
77+
78+
all:
79+
$(PRE_MAKE_CMD)
80+
$(DEBUG)$(MAKE_CMD)
81+
$(POST_MAKE_CMD)
82+
83+
clean:
84+
rm -rf $(APP_DIR)/$(APP_NAME)
85+
$(MBED_TLS_MAKE_CMD) clean
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
CC = gcc
2+
3+
#remove @ for no make command prints
4+
DEBUG=@
5+
6+
APP_DIR = .
7+
APP_NAME=shadow_sample
8+
APP_INCLUDE_DIRS += -I $(APP_DIR)
9+
APP_SRC_FILES=$(APP_NAME).c
10+
11+
#IoT client directory
12+
13+
14+
IOT_CLIENT_DIR=../../aws_iot_src
15+
16+
PLATFORM_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/openssl
17+
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux/common
18+
SHADOW_SRC_DIR= $(IOT_CLIENT_DIR)/shadow
19+
20+
21+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt
22+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper
23+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/platform_linux
24+
IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR)
25+
IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR)
26+
IOT_INCLUDE_DIRS += -I $(SHADOW_SRC_DIR)
27+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/utils
28+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/shadow
29+
30+
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/protocol/mqtt/aws_iot_embedded_client_wrapper/aws_iot_mqtt_embedded_client_wrapper.c
31+
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/utils/jsmn.c
32+
IOT_SRC_FILES += $(IOT_CLIENT_DIR)/utils/aws_iot_json_utils.c
33+
IOT_SRC_FILES += $(shell find $(SHADOW_SRC_DIR)/ -name '*.c')
34+
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
35+
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
36+
37+
#MQTT Paho Embedded C client directory
38+
MQTT_DIR = ../../aws_mqtt_embedded_client_lib
39+
MQTT_C_DIR = $(MQTT_DIR)/MQTTClient-C/src
40+
MQTT_EMB_DIR = $(MQTT_DIR)/MQTTPacket/src
41+
42+
MQTT_INCLUDE_DIR += -I $(MQTT_EMB_DIR)
43+
MQTT_INCLUDE_DIR += -I $(MQTT_C_DIR)
44+
45+
MQTT_SRC_FILES += $(shell find $(MQTT_EMB_DIR)/ -name '*.c')
46+
MQTT_SRC_FILES += $(MQTT_C_DIR)/MQTTClient.c
47+
48+
#TLS - openSSL
49+
TLS_LIB_DIR = /usr/lib/
50+
TLS_INCLUDE_DIR = -I /usr/include/openssl
51+
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
52+
LD_FLAG := -ldl -lssl -lcrypto
53+
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
54+
55+
#Aggregate all include and src directories
56+
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
57+
INCLUDE_ALL_DIRS += $(MQTT_INCLUDE_DIR)
58+
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
59+
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
60+
61+
SRC_FILES += $(MQTT_SRC_FILES)
62+
SRC_FILES += $(APP_SRC_FILES)
63+
SRC_FILES += $(IOT_SRC_FILES)
64+
65+
# Logging level control
66+
LOG_FLAGS += -DIOT_DEBUG
67+
LOG_FLAGS += -DIOT_INFO
68+
LOG_FLAGS += -DIOT_WARN
69+
LOG_FLAGS += -DIOT_ERROR
70+
71+
COMPILER_FLAGS += -g
72+
COMPILER_FLAGS += $(LOG_FLAGS)
73+
74+
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(EXTERNAL_LIBS) $(LD_FLAG) $(INCLUDE_ALL_DIRS)
75+
76+
all:
77+
$(DEBUG)$(MAKE_CMD)
78+
79+
clean:
80+
rm -rf $(APP_DIR)/$(APP_NAME)

0 commit comments

Comments
 (0)