Skip to content

Release candidate for mbed-os-5.11.0-rc2 #8974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c0dd29d
travis: mangodb key update not needed anymore
0xc0170 Dec 3, 2018
b4ecd7c
travis: rabbitmq signature update
0xc0170 Dec 3, 2018
586f7b2
STM32L4: before calling HAL_CRYP_DeInit initialize the Instance member
Dec 3, 2018
1c26ba5
Fix target handling in build.ppy
orenc17 Dec 1, 2018
a7b9645
MTB_ADV_WISE_1570: disable MPU code until target properly supported
Nov 30, 2018
6e4104b
Disable MPU code until target properly supported
Nov 30, 2018
9f4dadb
mbedtls: Update Mbed TLS to 2.15.1
Patater Nov 30, 2018
910c09e
BLE: Fix set check in GenerigGap::stopAdvertising.
pan- Nov 27, 2018
2b482cd
BLE: Remove double handling of DM_CONN_OPEN_IND .
pan- Nov 27, 2018
a48c6d4
consistent errors
paul-szczepanek-arm Nov 27, 2018
c6a29d1
BLE: Fix extraction of advertising element type.
pan- Nov 28, 2018
07e7fa3
BLE: protect event signaling flag from concurent accesses.
pan- Nov 28, 2018
6330878
BLE: Use RANDOM address per default for Advertising, Scan and Connect…
pan- Nov 29, 2018
0d38246
BLE: Ensure scan process is stopped before connecting.
pan- Nov 29, 2018
df00415
BLE: Fix ble::Gap::getMaxAdvertisingDataLength return type.
pan- Nov 29, 2018
3f56b22
BLE: Fix name of DisconnectionEvent into DisconnectionCompleteEvent f…
pan- Nov 29, 2018
a49dd7f
BLE: provide better default connection parameters.
pan- Nov 29, 2018
7e180c7
BLE: Change parameter order of ble::Gap::startScan
pan- Dec 3, 2018
d33106a
BLE: Rename ConnectionParameters::setFilterPolicy into setFilter for …
pan- Dec 3, 2018
16dd70f
BLE: Reintroduce refactored type identifier in privacy configuration …
pan- Dec 3, 2018
c8c3554
BLE: rename ConnectionParameters::getFilterPolicy into getFilter for …
pan- Dec 3, 2018
c3899d1
BLE: rename AdvertisingReportEvent::getAdvertisingData into getPayload.
pan- Dec 3, 2018
4e37874
BLE: Fix doxygen parameter declaration order.
pan- Dec 3, 2018
6e99157
Add rather than override PSOC 6 macros
c1728p9 Dec 3, 2018
26f842e
Turn off MPU for PSOC 6
c1728p9 Dec 3, 2018
5b2df6e
Update FEATURE_BLE README
Dec 3, 2018
4b67db7
Capitalization and punctuation
Dec 4, 2018
a325dd7
crypto: storage: Fix PSA_PS_ERROR_OFFSET typo
Patater Nov 30, 2018
a107404
psa: storage: Fix PSA_PS_ERROR_OFFSET typo
Patater Nov 30, 2018
0ba9623
Fix PSA-SPM Documentation
Nov 27, 2018
c660d36
Melinda's remarks
Nov 27, 2018
93cdd59
set proper groups for spm and HAL
Nov 27, 2018
2b9c41d
More fixes by Melinda
Nov 28, 2018
b675f5d
Grammatical and capitalization changes
Dec 4, 2018
16a73d1
spm spe: remove space
0xc0170 Dec 4, 2018
41adc4e
Fix PSA internal storage misconfiguration
Nov 29, 2018
0c5fb61
Optimize error handling
Nov 29, 2018
ef353c0
Replace PID and UID order in file name
Nov 29, 2018
9256d6f
Better PID handling
Dec 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ before_install:
# Setup ppa to make sure arm-none-eabi-gcc is correct version
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
- sudo add-apt-repository -y ppa:deadsnakes/ppa
# Fix for "The following signatures were invalid: KEYEXPIRED 1515625755" failed". See https://github.com/travis-ci/travis-ci/issues/9037
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
# import the new keys for rabbitmq (fix for https://github.com/ARMmbed/mbed-os/issues/8945)
- curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash
# Loop until update succeeds (timeouts can occur)
- travis_retry $(! sudo apt-get update 2>&1 |grep Failed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "psa_prot_internal_storage.h"
#include "pits_impl.h"
#include "mbed_error.h"
#include "mbed_toolchain.h"

#ifdef __cplusplus
extern "C"
Expand All @@ -48,52 +49,101 @@ const uint8_t base64_coding_table[] = {
'4', '5', '6', '7', '8', '9', '+', '-'
};


/*
* \brief Get default KVStore instance for internal flesh storage
*
* \return valid pointer to KVStore
*/
static KVStore *get_kvstore_instance(void)
{
KVMap &kv_map = KVMap::get_instance();

return kv_map.get_main_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
if (!kvstore) {
// Can only happen due to system misconfiguration.
// Thus considered as unrecoverable error for runtime.
error("Failed getting kvstore instance\n");
}
return kvstore;
}

static void generate_fn(char *tdb_filename, uint32_t tdb_file_len, uint32_t uid, uint32_t pid)
/*
* \brief Convert KVStore stauts codes to PSA internal storage status codes
*
* \param[in] status - KVStore status code
* \return PSA internal storage status code
*/
static psa_its_status_t convert_status(int status)
{
switch (status) {
case MBED_SUCCESS:
return PSA_ITS_SUCCESS;
case MBED_ERROR_WRITE_PROTECTED:
return PSA_ITS_ERROR_WRITE_ONCE;
case MBED_ERROR_MEDIA_FULL:
return PSA_ITS_ERROR_INSUFFICIENT_SPACE;
case MBED_ERROR_ITEM_NOT_FOUND:
return PSA_ITS_ERROR_KEY_NOT_FOUND;
default:
return PSA_ITS_ERROR_STORAGE_FAILURE;
}
}

/*
* \brief Logic shift right
*
* \note must operate on unsinged integers to prevent negative carry
* \param x[in] input number for shifting
* \param n[in] number of bits to shift right
* \return the result
*/
MBED_FORCEINLINE uint32_t lsr(uint32_t x, uint32_t n)
{
return x >> n;
}

/*
* \breif Generate KVStore file name
*
* Generate KVStore file name by Base64 encoding PID and UID with a delimiter.
* Delimiter is required for determining between PID and UID.
*
* \param[out] tdb_filename - pointer to a buffer for the file name
* \param[in] tdb_filename_size - output buffer size
* \param[in] uid - PSA internal storage unique ID
* \param[in] pid - owner PSA partition ID
*/
static void generate_fn(char *tdb_filename, uint32_t tdb_filename_size, uint32_t uid, int32_t pid)
{
MBED_ASSERT(tdb_filename != NULL);
MBED_ASSERT(tdb_file_len >= PSA_ITS_FILENAME_MAX_LEN);
MBED_ASSERT(tdb_filename_size == PSA_ITS_FILENAME_MAX_LEN);

uint8_t filename_idx = 0;
uint32_t tmp_uid = uid;
uint32_t tmp_pid = pid;
uint32_t unsigned_pid = (uint32_t)pid; // binary only representation for bitwise operations

// Iterate on UID; each time convert 6 bits of UID into a character; first iteration must be done
// Iterate on PID; each time convert 6 bits of PID into a character; first iteration must be done
do {
MBED_ASSERT(filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
tdb_filename[filename_idx++] = base64_coding_table[tmp_uid & 0x3F];
tmp_uid = tmp_uid >> 6;
} while (tmp_uid != 0);
tdb_filename[filename_idx++] = base64_coding_table[unsigned_pid & 0x3F];
unsigned_pid = lsr(unsigned_pid, 6);
} while (unsigned_pid != 0);

// Write delimiter
MBED_ASSERT(filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
tdb_filename[filename_idx++] = '#';

// Iterate on PID; each time convert 6 bits of PID into a character; first iteration must be done
// Iterate on UID; each time convert 6 bits of UID into a character; first iteration must be done
do {
MBED_ASSERT(filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
tdb_filename[filename_idx++] = base64_coding_table[tmp_pid & 0x3F];
tmp_pid = tmp_pid >> 6;
} while (tmp_pid != 0);
tdb_filename[filename_idx++] = base64_coding_table[uid & 0x3F];
uid = lsr(uid, 6);
} while (uid != 0);

tdb_filename[filename_idx++] = '\0';
MBED_ASSERT(filename_idx <= PSA_ITS_FILENAME_MAX_LEN);
tdb_filename[filename_idx] = '\0';
}


psa_its_status_t psa_its_set_impl(uint32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
psa_its_status_t psa_its_set_impl(int32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
{
KVStore *kvstore = get_kvstore_instance();
if (!kvstore) {
error("psa_its_set_impl() - Failed getting kvstore instance\n");
}
MBED_ASSERT(kvstore);

if ((create_flags != 0) && (create_flags != PSA_ITS_WRITE_ONCE_FLAG)) {
return PSA_ITS_ERROR_FLAGS_NOT_SUPPORTED;
Expand All @@ -108,53 +158,26 @@ psa_its_status_t psa_its_set_impl(uint32_t pid, uint32_t uid, uint32_t data_leng
kv_create_flags = KVStore::WRITE_ONCE_FLAG;
}

int kvstore_status = kvstore->set(kv_key, p_data, data_length, kv_create_flags);

psa_its_status_t status = PSA_ITS_SUCCESS;
if (kvstore_status != MBED_SUCCESS) {
switch (kvstore_status) {
case MBED_ERROR_WRITE_PROTECTED:
status = PSA_ITS_ERROR_WRITE_ONCE;
break;
case MBED_ERROR_MEDIA_FULL:
status = PSA_ITS_ERROR_INSUFFICIENT_SPACE;
break;
default:
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
}
int status = kvstore->set(kv_key, p_data, data_length, kv_create_flags);

return status;
return convert_status(status);
}

psa_its_status_t psa_its_get_impl(uint32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
psa_its_status_t psa_its_get_impl(int32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
{
KVStore *kvstore = get_kvstore_instance();
if (!kvstore) {
error("psa_its_get_impl() - Failed getting kvstore instance\n");
}
MBED_ASSERT(kvstore);

// Generate KVStore key
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
generate_fn(kv_key, PSA_ITS_FILENAME_MAX_LEN, uid, pid);

KVStore::info_t kv_info;
int kvstore_status = kvstore->get_info(kv_key, &kv_info);

psa_its_status_t status = PSA_ITS_SUCCESS;
if (kvstore_status != MBED_SUCCESS) {
switch (kvstore_status) {
case MBED_ERROR_ITEM_NOT_FOUND:
status = PSA_ITS_ERROR_KEY_NOT_FOUND;
break;
default:
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
}
int status = kvstore->get_info(kv_key, &kv_info);

if (kvstore_status == MBED_SUCCESS) {
if (status == MBED_SUCCESS) {
if (data_offset > kv_info.size) {
return PSA_PS_ERROR_OFFSET_INVALID;
return PSA_ITS_ERROR_OFFSET_INVALID;
}

// Verify (size + offset) does not wrap around
Expand All @@ -167,90 +190,53 @@ psa_its_status_t psa_its_get_impl(uint32_t pid, uint32_t uid, uint32_t data_offs
}

size_t actual_size = 0;
kvstore_status = kvstore->get(kv_key, p_data, data_length, &actual_size, data_offset);
status = kvstore->get(kv_key, p_data, data_length, &actual_size, data_offset);

if (kvstore_status == MBED_SUCCESS) {
if (status == MBED_SUCCESS) {
if (actual_size < data_length) {
status = PSA_ITS_ERROR_INCORRECT_SIZE;
}
} else {
switch (kvstore_status) {
case MBED_ERROR_ITEM_NOT_FOUND:
status = PSA_ITS_ERROR_KEY_NOT_FOUND;
break;
default:
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
}
}

return status;
return convert_status(status);
}

psa_its_status_t psa_its_get_info_impl(uint32_t pid, uint32_t uid, struct psa_its_info_t *p_info)
psa_its_status_t psa_its_get_info_impl(int32_t pid, uint32_t uid, struct psa_its_info_t *p_info)
{
KVStore *kvstore = get_kvstore_instance();
if (!kvstore) {
error("psa_its_get_info_impl() - Failed getting kvstore instance\n");
}
MBED_ASSERT(kvstore);

// Generate KVStore key
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
generate_fn(kv_key, PSA_ITS_FILENAME_MAX_LEN, uid, pid);

KVStore::info_t kv_info;
int kvstore_status = kvstore->get_info(kv_key, &kv_info);

psa_its_status_t status = PSA_ITS_SUCCESS;
if (kvstore_status != MBED_SUCCESS) {
switch (kvstore_status) {
case MBED_ERROR_ITEM_NOT_FOUND:
status = PSA_ITS_ERROR_KEY_NOT_FOUND;
break;
default:
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
}
int status = kvstore->get_info(kv_key, &kv_info);

if (kvstore_status == MBED_SUCCESS) {
if (status == MBED_SUCCESS) {
p_info->flags = 0;
if (kv_info.flags & KVStore::WRITE_ONCE_FLAG) {
p_info->flags |= PSA_ITS_WRITE_ONCE_FLAG;
}
p_info->size = (uint32_t)(kv_info.size); // kv_info.size is of type size_t
}

return status;
return convert_status(status);
}

psa_its_status_t psa_its_remove_impl(uint32_t pid, uint32_t uid)
psa_its_status_t psa_its_remove_impl(int32_t pid, uint32_t uid)
{
KVStore *kvstore = get_kvstore_instance();
if (!kvstore) {
error("psa_its_remove_impl() - Failed getting kvstore instance\n");
}
MBED_ASSERT(kvstore);

// Generate KVStore key
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
generate_fn(kv_key, PSA_ITS_FILENAME_MAX_LEN, uid, pid);

int kvstore_status = kvstore->remove(kv_key);

psa_its_status_t status = PSA_ITS_SUCCESS;
if (kvstore_status != MBED_SUCCESS) {
switch (kvstore_status) {
case MBED_ERROR_WRITE_PROTECTED:
status = PSA_ITS_ERROR_WRITE_ONCE;
break;
case MBED_ERROR_ITEM_NOT_FOUND:
status = PSA_ITS_ERROR_KEY_NOT_FOUND;
break;
default:
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
}
int status = kvstore->remove(kv_key);

return status;
return convert_status(status);
}

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ extern "C"

#define PITS_DATA_PTR_AT_OFFSET(ptr, offset) ((void *)(((uintptr_t)ptr) + ((uintptr_t)offset)))

psa_its_status_t psa_its_set_impl(uint32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags);
psa_its_status_t psa_its_get_impl(uint32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data);
psa_its_status_t psa_its_get_info_impl(uint32_t pid, uint32_t uid, struct psa_its_info_t *p_info);
psa_its_status_t psa_its_remove_impl(uint32_t pid, uint32_t uid);
psa_its_status_t psa_its_set_impl(int32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags);
psa_its_status_t psa_its_get_impl(int32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data);
psa_its_status_t psa_its_get_info_impl(int32_t pid, uint32_t uid, struct psa_its_info_t *p_info);
psa_its_status_t psa_its_remove_impl(int32_t pid, uint32_t uid);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef uint32_t psa_its_status_t;
#define PSA_ITS_ERROR_BAD_POINTER 6 /**< The operation failed because one of the provided pointers is invalid, for example is `NULL` or references memory the caller cannot access */
#define PSA_ITS_ERROR_KEY_NOT_FOUND 7 /**< The operation failed because the provided key value was not found in the storage */
#define PSA_ITS_ERROR_INCORRECT_SIZE 8 /**< The operation failed because the data associated with provided key is not the same size as `data_size` */
#define PSA_PS_ERROR_OFFSET_INVALID 9 /**< The operation failed because an offset was supplied that is invalid for the existing data associated with the uid. For example, offset + size is
#define PSA_ITS_ERROR_OFFSET_INVALID 9 /**< The operation failed because an offset was supplied that is invalid for the existing data associated with the uid. For example, offset + size is
past the end of the data */

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ psa_its_status_t psa_its_set(uint32_t uid, uint32_t data_length, const void *p_d
* \retval PSA_ITS_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
* \retval PSA_ITS_ERROR_BAD_POINTER The operation failed because one of the provided pointers(`p_data`, `p_data_length`)
* is invalid. For example is `NULL` or references memory the caller cannot access
* \retval PSA_PS_ERROR_OFFSET_INVALID The operation failed because an offset was supplied that is invalid for the existing data associated with the
* \retval PSA_ITS_ERROR_OFFSET_INVALID The operation failed because an offset was supplied that is invalid for the existing data associated with the
* uid. For example, offset + size is invalid,
*/
psa_its_status_t psa_its_get(uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data);
Expand Down
Loading