summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Byzhynar <AByzhynar@luxoft.com>2018-04-06 19:33:55 +0300
committerAndriy Byzhynar <abyzhynar@luxoft.com>2018-05-18 19:57:21 +0300
commit3c143c901e9c73858437db29c0a9bbad26428b66 (patch)
treefa5249a2de3ec84e73ae9d0be32e5538eef1e279
parent65c1e7eb77fa949cce9c07f229e2cf747f297e14 (diff)
downloadsdl_core-3c143c901e9c73858437db29c0a9bbad26428b66.tar.gz
Initial implementation
Implemented function in PutFile which correctly calculates CRC32 checksum for std::vector<uint8_t> Added comparison of calculated CRC checksum with received in PutFile request. Added PutFile response generation in case of CRC sum mismatch Fixed handling of unsigned integer values
-rw-r--r--src/components/application_manager/include/application_manager/smart_object_keys.h1
-rw-r--r--src/components/application_manager/src/commands/mobile/put_file_request.cc46
-rw-r--r--src/components/application_manager/src/smart_object_keys.cc1
-rw-r--r--src/components/interfaces/MOBILE_API.xml7
-rw-r--r--src/components/smart_objects/include/smart_objects/number_schema_item.h16
-rw-r--r--src/components/smart_objects/src/number_schema_item.cc2
6 files changed, 59 insertions, 14 deletions
diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h
index 32a2315f23..5a3a5fe8b6 100644
--- a/src/components/application_manager/include/application_manager/smart_object_keys.h
+++ b/src/components/application_manager/include/application_manager/smart_object_keys.h
@@ -184,6 +184,7 @@ extern const char* sync_file_name;
extern const char* file_name;
extern const char* file_type;
extern const char* file_size;
+extern const char* crc32_check_sum;
extern const char* request_type;
extern const char* persistent_file;
extern const char* file_data;
diff --git a/src/components/application_manager/src/commands/mobile/put_file_request.cc b/src/components/application_manager/src/commands/mobile/put_file_request.cc
index 602b420ba0..269c9c814e 100644
--- a/src/components/application_manager/src/commands/mobile/put_file_request.cc
+++ b/src/components/application_manager/src/commands/mobile/put_file_request.cc
@@ -38,6 +38,22 @@
#include "application_manager/application_impl.h"
#include "utils/file_system.h"
+#include <boost/crc.hpp>
+
+namespace {
+/**
+* Calculates CRC32 checksum
+* @param binary_data - input data for which CRC32 should be calculated
+* @return calculated CRC32 checksum
+*/
+uint32_t GetCrc32CheckSum(const std::vector<uint8_t>& binary_data) {
+ const std::size_t file_size = binary_data.size();
+ boost::crc_32_type result;
+ result.process_bytes(&binary_data[0], file_size);
+ return result.checksum();
+}
+
+} // namespace
namespace application_manager {
@@ -137,7 +153,7 @@ void PutFileRequest::Run() {
is_persistent_file_ = false;
bool is_system_file = false;
length_ = binary_data.size();
- bool is_download_compleate = true;
+ bool is_download_complete = true;
bool offset_exist =
(*message_)[strings::msg_params].keyExists(strings::offset);
@@ -187,11 +203,29 @@ void PutFileRequest::Run() {
return;
}
const std::string full_path = file_path + "/" + sync_file_name_;
- UNUSED(full_path);
+ const size_t bin_data_size = binary_data.size();
+
+ if ((*message_)[strings::msg_params].keyExists(strings::crc32_check_sum)) {
+ LOG4CXX_TRACE(logger_, "Binary Data Size: " << bin_data_size);
+ const uint32_t crc_received =
+ (*message_)[strings::msg_params][strings::crc32_check_sum].asUInt();
+ LOG4CXX_TRACE(logger_, "CRC32 SUM Received: " << crc_received);
+ const uint32_t crc_calculated = GetCrc32CheckSum(binary_data);
+ LOG4CXX_TRACE(logger_, "CRC32 SUM Calculated: " << crc_calculated);
+ if (crc_calculated != crc_received) {
+ SendResponse(false,
+ mobile_apis::Result::CORRUPTED_DATA,
+ "CRC Check on file failed. File upload has been cancelled, "
+ "please retry.",
+ &response_params);
+ return;
+ }
+ }
+
LOG4CXX_DEBUG(logger_,
- "Wrtiting " << binary_data.size() << "bytes to " << full_path
- << " (current size is"
- << file_system::FileSize(full_path) << ")");
+ "Writing " << bin_data_size << " bytes to " << full_path
+ << " (current size is"
+ << file_system::FileSize(full_path) << ")");
mobile_apis::Result::eType save_result = application_manager_.SaveBinary(
binary_data, file_path, sync_file_name_, offset_);
@@ -211,7 +245,7 @@ void PutFileRequest::Run() {
if (!is_system_file) {
AppFile file(sync_file_name_,
is_persistent_file_,
- is_download_compleate,
+ is_download_complete,
file_type_);
if (0 == offset_) {
diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc
index c3aba90dd5..75125ec90c 100644
--- a/src/components/application_manager/src/smart_object_keys.cc
+++ b/src/components/application_manager/src/smart_object_keys.cc
@@ -148,6 +148,7 @@ const char* sync_file_name = "syncFileName";
const char* file_name = "fileName";
const char* file_type = "fileType";
const char* file_size = "fileSize";
+const char* crc32_check_sum = "crc";
const char* request_type = "requestType";
const char* persistent_file = "persistentFile";
const char* file_data = "fileData";
diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml
index a1c64aecda..ad9050fcf3 100644
--- a/src/components/interfaces/MOBILE_API.xml
+++ b/src/components/interfaces/MOBILE_API.xml
@@ -135,6 +135,9 @@
<element name="READ_ONLY">
<description>The value being set is read only</description>
</element>
+ <element name="CORRUPTED_DATA">
+ <description>The data sent failed to pass CRC check in receiver end</description>
+ </element>
</enum>
<enum name="ButtonPressMode">
@@ -5073,6 +5076,9 @@
If offset is set to 0, then length is the total length of the file to be downloaded
</description>
</param>
+ <param name="crc" type="Integer" minvalue="0" maxvalue="4294967295" mandatory="false">
+ <description> Additional CRC32 checksum to protect data integrity up to 512 Mbits . </description>
+ </param>
</function>
<function name="PutFile" functionID="PutFileID" messagetype="response">
@@ -5092,6 +5098,7 @@
<element name="GENERIC_ERROR"/>
<element name="REJECTED"/>
<element name="UNSUPPORTED_REQUEST"/>
+ <element name="CORRUPTED_DATA"/>
</param>
<param name="spaceAvailable" type="Integer" minvalue="0" maxvalue="2000000000" mandatory="true">
diff --git a/src/components/smart_objects/include/smart_objects/number_schema_item.h b/src/components/smart_objects/include/smart_objects/number_schema_item.h
index d549b9891a..34c5e3a8a6 100644
--- a/src/components/smart_objects/include/smart_objects/number_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/number_schema_item.h
@@ -39,6 +39,7 @@
#include "smart_objects/default_shema_item.h"
#include "smart_objects/schema_item_parameter.h"
#include "utils/convert_utils.h"
+#include "utils/helpers.h"
namespace NsSmartDeviceLink {
namespace NsSmartObjects {
@@ -123,15 +124,16 @@ bool TNumberSchemaItem<NumberType>::isValidNumberType(SmartType type) {
NumberType value(0);
if ((SmartType_Double == type) && (typeid(double) == typeid(value))) {
return true;
- } else if ((SmartType_Integer == type) &&
- (typeid(int32_t) == typeid(value) ||
- typeid(uint32_t) == typeid(value) ||
- typeid(int64_t) == typeid(value) ||
- typeid(double) == typeid(value))) {
+ } else if (((SmartType_Integer == type) || (SmartType_UInteger == type)) &&
+ helpers::Compare<const std::type_info&, helpers::EQ, helpers::ONE>(
+ typeid(value),
+ typeid(int32_t),
+ typeid(uint32_t),
+ typeid(int64_t),
+ typeid(double))) {
return true;
- } else {
- return false;
}
+ return false;
}
template <typename NumberType>
diff --git a/src/components/smart_objects/src/number_schema_item.cc b/src/components/smart_objects/src/number_schema_item.cc
index 78be9fe85d..9789434523 100644
--- a/src/components/smart_objects/src/number_schema_item.cc
+++ b/src/components/smart_objects/src/number_schema_item.cc
@@ -41,7 +41,7 @@ SmartType TNumberSchemaItem<int32_t>::getSmartType() const {
template <>
SmartType TNumberSchemaItem<uint32_t>::getSmartType() const {
- return SmartType_Integer;
+ return SmartType_UInteger;
}
template <>