Skip to content

Commit

Permalink
Merge remote-tracking branch 'internal/develop_rel_1_1_18' into develop
Browse files Browse the repository at this point in the history
* internal/develop_rel_1_1_18: (27 commits)
  Update core version to 1.1.18
  easysetup: fix debug log
  security: software: fixed build error regarding rsa
  port: os: use unsigned char data type to clear eventgroup
  add 'extern C' to capability helper file
  update capability helper for capabilities in devWS
  Change publishing events way in a asynchronous manner
  Retry MQTT connect when critical rejects happen instead of clean.
  iot_api: iot_wifi_ctrl_reqeust: Change its usage by sync-operation fo… (#509)
  cmake: add iot_dump_log.c into library source
  [TC BUILD ERROR FIX] Match MACRO with latest header
  [Bug fix] Release MQTT chunk memory by chunk onwer.
  test: iot_main: Update Unit TC
  easysetup: update boilerplate
  include: bsp: fix doxygen
  test: add TC for st_mqtt_create failure case
  mqtt: use iot_os_free instead of free
  to add logging logdump id for tcp
  to change easysetup internal logging option to CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE
  to change log mode for logdump
  ...
  • Loading branch information
stdk-scm committed Jun 17, 2020
2 parents 7e6557c + 9b5690d commit a958d42
Show file tree
Hide file tree
Showing 112 changed files with 4,960 additions and 624 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_library(iotcore
iot_util.c
iot_uuid.c
iot_root_ca.c
iot_dump_log.c
)

target_link_libraries(iotcore
Expand Down
5 changes: 3 additions & 2 deletions src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ config STDK_IOT_CORE_EASYSETUP_HTTP
help
If this option is enabled, STDK will use httpd for easy setup.

config STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT
config STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE
bool "Logging via device-to-device"
default n
depends on STDK_IOT_CORE_EASYSETUP_HTTP
help
If this option is enabled, STDK will support logging via device-to-device mechanism.
If Logfile logging isn't supported, this optioin can be useful instead of logfile.
If this option is enabled, STDK can support logging via device-to-device mechanism without logfile system.

config STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SIZE
int "log buffer size in byte"
Expand Down
8 changes: 4 additions & 4 deletions src/easysetup/http/iot_easysetup_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static const char http_status_400[] = "HTTP/1.1 400 Bad Request";
static const char http_status_500[] = "HTTP/1.1 500 Internal Server Error";
static const char http_header[] = "\r\nServer: SmartThings Device SDK\r\nConnection: "CONNECTION_TYPE"\r\nContent-Type: application/json\r\nContent-Length: ";
STATIC_VARIABLE int ref_step;
#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT)
#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
static bool dump_enable;
static char *log_buffer;
unsigned int log_len;
Expand All @@ -60,7 +60,7 @@ const char *get_cgi_cmds[]=
IOT_ES_URI_GET_LOGS_DUMP,
};

#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT)
#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
void iot_debug_save_log(char* buf)
{
if(dump_enable) {
Expand Down Expand Up @@ -425,7 +425,7 @@ iot_error_t iot_easysetup_init(struct iot_context *ctx)
es_http_init();
ref_step = 0;

#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT)
#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
if ((log_buffer = (char *)malloc(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SIZE)) == NULL) {
IOT_ERROR("failed to malloc for log buffer");
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_MEM_ALLOC_ERROR, 0);
Expand All @@ -450,7 +450,7 @@ void iot_easysetup_deinit(struct iot_context *ctx)

es_http_deinit();

#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT)
#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
if (log_buffer) {
dump_enable = false;
free(log_buffer);
Expand Down
1 change: 1 addition & 0 deletions src/easysetup/http/iot_easysetup_http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* MIT License
*
* Copyright (c) 2020 Samsung Electronics
* Copyright (c) 2019 Aleksey Kurepin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
51 changes: 33 additions & 18 deletions src/easysetup/http/tcp/iot_easysetup_d2d_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,6 @@ iot_error_t _es_confirm_check_manager(struct iot_context *ctx, enum ownership_va
return err;
}

err = iot_wifi_ctrl_request(ctx, IOT_WIFI_MODE_SCAN);
if (err != IOT_ERROR_NONE) {
IOT_ERROR("Can't send WIFI mode scan.(%d)", err);
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_WIFI_SCAN_NOT_FOUND, err);
err = IOT_ERROR_EASYSETUP_WIFI_SCAN_NOT_FOUND;
}

out:
if (dev_sn)
free(dev_sn);
Expand Down Expand Up @@ -1097,13 +1090,6 @@ iot_error_t _es_confirm_handler(struct iot_context *ctx, char *in_payload, char

*out_payload = final_msg;

err = iot_wifi_ctrl_request(ctx, IOT_WIFI_MODE_SCAN);
if (err != IOT_ERROR_NONE) {
IOT_ERROR("Can't send WIFI mode scan.(%d)", err);
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_WIFI_SCAN_NOT_FOUND, err);
err = IOT_ERROR_EASYSETUP_WIFI_SCAN_NOT_FOUND;
}

out:
if (plain_msg) {
free(plain_msg);
Expand Down Expand Up @@ -1143,6 +1129,14 @@ iot_error_t _es_wifiscaninfo_handler(struct iot_context *ctx, char **out_payload
return err;
}

err = iot_wifi_ctrl_request(ctx, IOT_WIFI_MODE_SCAN);
if (err != IOT_ERROR_NONE) {
IOT_ERROR("Can't control WIFI mode scan.(%d)", err);
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_WIFI_SCAN_NOT_FOUND, err);
err = IOT_ERROR_EASYSETUP_WIFI_SCAN_NOT_FOUND;
return err;
}

if (!ctx->scan_num) {
IOT_ERROR("wifi AP isn't found!!");
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_WIFI_SCAN_NOT_FOUND, ctx->scan_num);
Expand Down Expand Up @@ -1669,7 +1663,6 @@ iot_error_t _es_setupcomplete_handler(struct iot_context *ctx, char *in_payload,
return err;
}

#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT)
static iot_error_t _es_log_systeminfo_handler(struct iot_context *ctx, char **out_payload)
{
char *output_ptr = NULL;
Expand Down Expand Up @@ -1727,6 +1720,12 @@ static iot_error_t _es_log_get_dump_handler(struct iot_context *ctx, char **out_
JSON_H *item = NULL;
JSON_H *root = NULL;
iot_error_t err = IOT_ERROR_NONE;
#if !defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
char *sumo_dump = NULL;
size_t log_dump_size = 2048;
size_t sumo_dump_size = 200;
size_t written_size = 0;
#endif

item = JSON_CREATE_OBJECT();
if (!item) {
Expand All @@ -1736,9 +1735,28 @@ static iot_error_t _es_log_get_dump_handler(struct iot_context *ctx, char **out_
goto out;
}

#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
log_dump = iot_debug_get_log();
#else
err = iot_dump_create_all_log_dump(ctx, &log_dump, log_dump_size, &written_size, IOT_DUMP_MODE_NEED_BASE64 | IOT_DUMP_MODE_NEED_DUMP_STATE);
if (err < 0) {
IOT_ERROR("Fail to get log dump!\n");
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_CREATE_LOGDUMP_FAIL, 0);
goto out;
}
err = iot_dump_create_all_log_dump(ctx, &sumo_dump, sumo_dump_size, &written_size, IOT_DUMP_MODE_NEED_BASE64);
if (err < 0) {
IOT_ERROR("Fail to get sumo dump!\n");
IOT_ES_DUMP(IOT_DEBUG_LEVEL_ERROR, IOT_DUMP_EASYSETUP_CREATE_SUMODUMP_FAIL, 0);
goto out;
}
#endif

JSON_ADD_NUMBER_TO_OBJECT(item, "code", 1);
JSON_ADD_ITEM_TO_OBJECT(item, "message", JSON_CREATE_STRING(log_dump));
#if !defined(CONFIG_STDK_IOT_CORE_EASYSETUP_LOG_SUPPORT_NO_USE_LOGFILE)
JSON_ADD_ITEM_TO_OBJECT(item, "sumomessage", JSON_CREATE_STRING(sumo_dump));
#endif

root = JSON_CREATE_OBJECT();
if (!root) {
Expand All @@ -1761,7 +1779,6 @@ static iot_error_t _es_log_get_dump_handler(struct iot_context *ctx, char **out_
JSON_DELETE(root);
return err;
}
#endif

iot_error_t iot_easysetup_request_handler(struct iot_context *ctx, struct iot_easysetup_payload request)
{
Expand Down Expand Up @@ -1797,7 +1814,6 @@ iot_error_t iot_easysetup_request_handler(struct iot_context *ctx, struct iot_ea
case IOT_EASYSETUP_STEP_SETUPCOMPLETE:
err = _es_setupcomplete_handler(ctx, request.payload, &response.payload);
break;
#if defined(CONFIG_STDK_IOT_CORE_EASYSETUP_HTTP_LOG_SUPPORT)
case IOT_EASYSETUP_STEP_LOG_SYSTEMINFO:
err = _es_log_systeminfo_handler(ctx, &response.payload);
break;
Expand All @@ -1807,7 +1823,6 @@ iot_error_t iot_easysetup_request_handler(struct iot_context *ctx, struct iot_ea
case IOT_EASYSETUP_STEP_LOG_GET_DUMP:
err = _es_log_get_dump_handler(ctx, &response.payload);
break;
#endif
default:
err = IOT_ERROR_EASYSETUP_INTERNAL_SERVER_ERROR;
break;
Expand Down
10 changes: 9 additions & 1 deletion src/easysetup/http/tcp/iot_easysetup_http_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ static void es_tcp_task(void *pvParameters)
tx_buffer = NULL;
}
//Transfer finished in this loop, sock resources should be clean.
shutdown(sock, SHUT_RD);
shutdown(sock, SHUT_RDWR);
while (1) {
memset(rx_buffer, '\0', sizeof(rx_buffer));
rx_buffer[len] = '\0';
len = recv(sock, rx_buffer, sizeof(rx_buffer) - 1, 0);
if (len > 0)
continue;
break;
}
close(sock);
sock = -1;
}
Expand Down
11 changes: 10 additions & 1 deletion src/easysetup/iot_easysetup_st_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void _iot_mqtt_registration_client_callback(st_mqtt_event event, void *event_dat
} else {
IOT_WARN("No msg delivery handler for %s", md->topic);
}
IOT_DEBUG("raw msg (len:%d) : %s", md->payloadlen, mqtt_payload);
IOT_DEBUG("raw msg (len:%d) : %s", md->payloadlen, md->payload);
break;
}
default:
Expand Down Expand Up @@ -649,6 +649,7 @@ iot_error_t _iot_es_mqtt_connect(struct iot_context *ctx, st_mqtt_client target_
/* This case means Server can't start service for MQTT Things
* This case is totally server-side issue, so we just report it to Apps
*/
ctx->mqtt_connect_critical_reject_count = 0;
iot_ret = IOT_ERROR_MQTT_SERVER_UNAVAIL;
break;

Expand All @@ -660,6 +661,11 @@ iot_error_t _iot_es_mqtt_connect(struct iot_context *ctx, st_mqtt_client target_
/* These cases are related to device's clientID, serialNumber, deviceId & web token
* So we try to cleanup all data & reboot
*/
if (ctx->mqtt_connect_critical_reject_count++ < IOT_MQTT_CONNECT_CRITICAL_REJECT_MAX) {
IOT_WARN("MQTT critical reject retry %d", ctx->mqtt_connect_critical_reject_count);
iot_ret = IOT_ERROR_MQTT_CONNECT_FAIL;
break;
}
IOT_WARN("Rejected by Server!! cleanup all & reboot");

reboot = true;
Expand All @@ -672,9 +678,12 @@ iot_error_t _iot_es_mqtt_connect(struct iot_context *ctx, st_mqtt_client target_
* network conditions (outside of the device) or, related to WIFI conditions
* (inside of the device). So we try to do re-connecting limitedly
*/
ctx->mqtt_connect_critical_reject_count = 0;
iot_ret = IOT_ERROR_MQTT_CONNECT_FAIL;
break;
}
} else {
ctx->mqtt_connect_critical_reject_count = 0;
}

#if defined(STDK_MQTT_TASK)
Expand Down
2 changes: 1 addition & 1 deletion src/include/bsp/iot_bsp_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ iot_error_t iot_bsp_fs_open_from_stnv(const char* filename, iot_bsp_fs_handle_t*
*
* @param[in] handle This is iot_bsp_fs_handle_t handle from iot_bsp_fs_open().
* @param[out] buffer A pointer to buffer array to store the read data from the file.
* @param[in] length The size of buffer and this will be set to the actual length of the value read
* @param[in/out] length The size of buffer and this will be set to the actual length of the value read
* @retval IOT_ERROR_NONE File read successful.
* @retval IOT_ERROR_FS_READ_FAIL File read failed.
* @retval IOT_ERROR_FS_NO_FILE No file.
Expand Down
9 changes: 8 additions & 1 deletion src/include/caps/iot_caps_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@
#define _ATTR_BIT_VALUE_REQUIRED 2
#define _ATTR_BIT_UNIT_REQUIRED 3
#define _ATTR_BIT_MAX_LENGTH 4
#define _ATTR_BIT_VALUE_ARRAY 5

#define ATTR_SET_VALUE_MIN (1 << _ATTR_BIT_VALUE_MIN)
#define ATTR_SET_VALUE_MAX (1 << _ATTR_BIT_VALUE_MAX)
#define ATTR_SET_VALUE_REQUIRED (1 << _ATTR_BIT_VALUE_REQUIRED)
#define ATTR_SET_UNIT_REQUIRED (1 << _ATTR_BIT_UNIT_REQUIRED)
#define ATTR_SET_MAX_LENGTH (1 << _ATTR_BIT_MAX_LENGTH)
#define ATTR_SET_VALUE_ARRAY (1 << _ATTR_BIT_VALUE_ARRAY)

#endif /* _IOT_CAPS_HELPER_ */
#define VALUE_TYPE_INTEGER 1
#define VALUE_TYPE_NUMBER 2
#define VALUE_TYPE_STRING 3
#define VALUE_TYPE_OBJECT 4

#endif /* _IOT_CAPS_HELPER_ */
42 changes: 26 additions & 16 deletions src/include/caps/iot_caps_helper_accelerationSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,36 @@

#include "iot_caps_helper.h"

#ifdef __cplusplus
extern "C" {
#endif

enum {
CAPS_HELPER_ACCELERATION_SENSOR_VALUE_ACTIVE = 0,
CAPS_HELPER_ACCELERATION_SENSOR_VALUE_INACTIVE,
CAPS_HELPER_ACCELERATION_SENSOR_VALUE_MAX
CAP_ENUM_ACCELERATIONSENSOR_ACCELERATION_VALUE_ACTIVE,
CAP_ENUM_ACCELERATIONSENSOR_ACCELERATION_VALUE_INACTIVE,
CAP_ENUM_ACCELERATIONSENSOR_ACCELERATION_VALUE_MAX
};

const static struct iot_caps_accelerationSensor {
const char *id;
const struct accelerationSensor_attr_acceleration {
const char *name;
const unsigned char property;
const char *values[CAPS_HELPER_ACCELERATION_SENSOR_VALUE_MAX];
} attr_acceleration;
const char *id;
const struct accelerationSensor_attr_acceleration {
const char *name;
const unsigned char property;
const unsigned char value_type;
const char *values[CAP_ENUM_ACCELERATIONSENSOR_ACCELERATION_VALUE_MAX];
} attr_acceleration;
} caps_helper_accelerationSensor = {
.id = "accelerationSensor",
.attr_acceleration = {
.name = "acceleration",
.property = ATTR_SET_VALUE_REQUIRED,
.values = { "active", "inactive" },
}
.id = "accelerationSensor",
.attr_acceleration = {
.name = "acceleration",
.property = ATTR_SET_VALUE_REQUIRED,
.value_type = VALUE_TYPE_STRING,
.values = {"active", "inactive"},
},
};

#endif /* _IOT_CAPS_HELPER_ACCELERATION_SENSOR_ */
#ifdef __cplusplus
}
#endif

#endif /* _IOT_CAPS_HERLPER_ACCELERATION_SENSOR_ */
64 changes: 64 additions & 0 deletions src/include/caps/iot_caps_helper_activityLightingMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* ***************************************************************************
*
* Copyright 2019-2020 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/

#ifndef _IOT_CAPS_HELPER_ACTIVITY_LIGHTING_MODE_
#define _IOT_CAPS_HELPER_ACTIVITY_LIGHTING_MODE_

#include "iot_caps_helper.h"

#ifdef __cplusplus
extern "C" {
#endif

enum {
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_READING,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_WRITING,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_COMPUTER,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_NIGHT,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_SLEEPPREPARATION,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_DAY,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_COZY,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_SOFT,
CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_MAX
};

const static struct iot_caps_activityLightingMode {
const char *id;
const struct activityLightingMode_attr_lightingMode {
const char *name;
const unsigned char property;
const unsigned char value_type;
const char *values[CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_MAX];
} attr_lightingMode;
const struct activityLightingMode_cmd_setLightingMode { const char* name; } cmd_setLightingMode;
} caps_helper_activityLightingMode = {
.id = "activityLightingMode",
.attr_lightingMode = {
.name = "lightingMode",
.property = ATTR_SET_VALUE_REQUIRED,
.value_type = VALUE_TYPE_STRING,
.values = {"reading", "writing", "computer", "night", "sleepPreparation", "day", "cozy", "soft"},
},
.cmd_setLightingMode = { .name = "setLightingMode" }, // arguments: lightingMode(string)
};

#ifdef __cplusplus
}
#endif

#endif /* _IOT_CAPS_HERLPER_ACTIVITY_LIGHTING_MODE_ */
Loading

0 comments on commit a958d42

Please sign in to comment.