diff --git a/.travis.yml b/.travis.yml index dc3c2fdb09f..4dccc58572a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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) diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp index 1e520c5c93d..e6c515f93c5 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp @@ -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" @@ -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; @@ -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 @@ -167,52 +190,31 @@ 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; @@ -220,37 +222,21 @@ psa_its_status_t psa_its_get_info_impl(uint32_t pid, uint32_t uid, struct psa_it 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 diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h index 06bde2d8fd5..bb41bedbb21 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h @@ -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 } diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/psa_prot_internal_storage.h b/components/TARGET_PSA/services/psa_prot_internal_storage/psa_prot_internal_storage.h index 366f7897ffc..26766ad5337 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/psa_prot_internal_storage.h +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/psa_prot_internal_storage.h @@ -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 */ /** @@ -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); diff --git a/components/TARGET_PSA/spm/COMPONENT_SPE/handles_manager.h b/components/TARGET_PSA/spm/COMPONENT_SPE/handles_manager.h index 8a1b7337ba7..76193715d72 100644 --- a/components/TARGET_PSA/spm/COMPONENT_SPE/handles_manager.h +++ b/components/TARGET_PSA/spm/COMPONENT_SPE/handles_manager.h @@ -26,24 +26,22 @@ /* -------------------------------- Handle Manager Module ---------------------------- */ -/* The Handle Manager Module manages handles. - * - * It basically generates and exposes a unique handle identifier [handle] per - * handle memory [handle_mem] it receives from the user. - * Then users can use the exposed handle identifier to relate to the "registered" +/* + * The Handle Manager module generates and exposes a unique + * identifier (handle) per handle memory (handle_mem) it receives. + * You can use the exposed handle identifier to relate to the "registered" * handle memory. * - * Users can: - * - Ask for a unique handle identifier for a given handle memory [handle_create] + * You can: + * - Ask for a unique handle identifier for a given handle memory [`handle_create`]. * - Ask for a pointer to the handle memory corresponding to a - * handle identifier [handle_get_mem] - * - Remove a handle from the handle manager module [handle_destroy] + * handle identifier [`handle_get_mem`]. + * - Remove a handle from the handle manager module [`handle_destroy`]. * * Note: - * Handles generation is done exclusively. - * Once we got a handle, removing a handle or getting its memory can be - * done non-exclusive. - * The assumption is that only one context is dealing with a handle after it was + * Handle generation is done exclusively. + * Once you have a handle, you can remove or get its memory non-exclusively. + * The assumption is that only one context is dealing with a handle after it is * generated. */ @@ -61,9 +59,9 @@ extern "C" { #define PSA_HANDLE_MGR_INVALID_FRIEND_OWNER 0 // Denoting invalid friend or invalid owner -// Handles manager pool indexes must be in range 0 - 0x7FFF. -// The reason for this limitation is that the index is stored in the upper 16 bits of a handle, -// and the most significant bit must be zero to keep handles non negative. +// Handle manager pool indexes must be in range 0 - 0x7FFF. +// This is because the index is stored in the upper 16 bits of a handle, +// and the most significant bit must be zero to keep handles non-negative. #define PSA_HANDLE_MGR_MAX_HANDLES_NUM 0x8000 @@ -72,19 +70,19 @@ extern "C" { typedef struct psa_handle_item_t { - psa_handle_t handle; /* The user exposed handle [unique identifier] */ - int32_t handle_owner; /* The partition id of the handle creator - allowed to get_mem() / destroy() */ - int32_t handle_friend; /* The partition id of a "friend" partition - allowed to get_mem() */ - void *handle_mem; /* Points to memory allocated by the user */ + psa_handle_t handle; /* The user-exposed handle [unique identifier]. */ + int32_t handle_owner; /* The partition ID of the handle creator. Allowed to get_mem() / destroy(). */ + int32_t handle_friend; /* The partition ID of a "friend" partition. Allowed to get_mem(). */ + void *handle_mem; /* Points to memory allocated by the use.r */ } psa_handle_item_t; typedef struct psa_handle_manager_t { - uint32_t handle_generator; /* A counter supplying handle numbers */ - uint32_t pool_size; /* The maximum number of handles that pool can contain */ - psa_handle_item_t *handles_pool; /* Holding couples of handles and their memory "blocks" */ + uint32_t handle_generator; /* A counter supplying handle numbers. */ + uint32_t pool_size; /* The maximum number of handles that pool can contain. */ + psa_handle_item_t *handles_pool; /* Holds couples of handles and their memory "blocks". */ } psa_handle_manager_t; @@ -111,43 +109,43 @@ handles_pool /* - * @brief create unique handle identifier + * @brief Create unique handle identifier * - * This function generates a unique handle identifier, and "couples" it with the received handle memory. + * This function generates a unique handle identifier, and **couples** it with the received handle memory. * If there is no vacant space for the new handle, the function fails. * * @note This function is expected to pass since it is always coupled with memory pool allocation of the same size. * In case memory pool allocation fails, this function should not be called. - * This function will panic on non vacant space use case. + * This function will panic in the case of non-vacant space use. * - * @param[in] handle_mgr A pointer to the handle manager object - * @param[in] handle_mem A pointer to a pre-allocated handle memory to get a handle identifier for - * @param[in] friend_pid The partition id which is allowed to get_mem() and destroy() in addition to the handle owner. - * Use PSA_HANDLE_MGR_INVALID_FRIEND_OWNER to denote there is no friend partition. - * @return The created handle identifier + * @param[in] handle_mgr A pointer to the handle manager object. + * @param[in] handle_mem A pointer to a pre-allocated handle memory for which to get a handle identifier. + * @param[in] friend_pid The partition ID allowed to `get_mem()` and `destroy()` in addition to the handle owner. + * Use `PSA_HANDLE_MGR_INVALID_FRIEND_OWNER` to denote that there is no friend partition. + * @return The created handle identifier */ psa_handle_t psa_hndl_mgr_handle_create(psa_handle_manager_t *handle_mgr, void *handle_mem, int32_t friend_pid); /* - * @brief remove a handle from the handle manager. + * @brief Remove a handle from the handle manager. * - * @param handle_mgr A pointer to the handle manager object - * @param handle The handle to be removed + * @param handle_mgr A pointer to the handle manager object. + * @param handle The handle to be removed. */ void psa_hndl_mgr_handle_destroy(psa_handle_manager_t *handle_mgr, psa_handle_t handle); /* - * @brief dereference handle + * @brief De-reference handle * * This function retrieves the pointer associated with the input . * - * @note This function will panic in case caller not allowed to dereference the memory - * or handler does not correspond to a valid existing handle + * @note This function will panic if caller is not allowed to de-reference the memory, + * or handler does not correspond to a valid existing handle. * * @param handle_mgr A pointer to the handle manager object. - * @param handle The handle for which we request the corresponding memory handle. + * @param handle The handle for which you request the corresponding memory handle. * @return void* A pointer to the memory corresponding to the handle. */ void *psa_hndl_mgr_handle_get_mem(psa_handle_manager_t *handle_mgr, psa_handle_t handle); diff --git a/components/TARGET_PSA/spm/COMPONENT_SPE/spm_internal.h b/components/TARGET_PSA/spm/COMPONENT_SPE/spm_internal.h index f158f5760e5..0b3e1246b8e 100644 --- a/components/TARGET_PSA/spm/COMPONENT_SPE/spm_internal.h +++ b/components/TARGET_PSA/spm/COMPONENT_SPE/spm_internal.h @@ -110,11 +110,11 @@ typedef struct spm_ipc_channel { struct spm_partition *src_partition; /* Pointer to the Partition which connects to the Root of Trust Service.*/ spm_rot_service_t *dst_rot_service; /* Pointer to the connected Root of Trust Service.*/ void *rhandle; /* Reverse handle to be used for this channel.*/ - void *msg_ptr; /* message data sent from user */ - struct spm_ipc_channel *next; /* Next channel in the chain */ + void *msg_ptr; /* Message data sent from user. */ + struct spm_ipc_channel *next; /* Next channel in the chain.*/ uint8_t msg_type; /* The message type.*/ uint8_t state; /* The current processing state of the channel.*/ - uint8_t is_dropped; + uint8_t is_dropped; /* Indicates whether the channel has been dropped by the partition.*/ } spm_ipc_channel_t; /* @@ -127,7 +127,7 @@ typedef struct spm_active_msg { } spm_active_msg_t; /* - * Structure containing resources and attributes of a Secure Partition. + * Structure containing resources and attributes of a secure partition. */ typedef struct spm_partition { const int32_t partition_id; /* The Partition ID.*/ @@ -136,7 +136,7 @@ typedef struct spm_partition { const uint32_t flags_interrupts; /* Mask of all the IRQs & doorbell which the partition supports.*/ spm_rot_service_t *rot_services; /* Array of the Partition's Root of Trust Services.*/ const uint32_t rot_services_count; /* Number of the Partition's Root of Trust Services.*/ - const uint32_t *extern_sids; /* Array of Root of Trust Service IDs which the partition can connect to.*/ + const uint32_t *extern_sids; /* Array of Root of Trust Service IDs that the partition can connect to.*/ const uint32_t extern_sids_count; /* Number of Root of Trust Services which the partition can connect to.*/ osMutexId_t mutex; /* Mutex for all rot_service's queues operations. */ spm_signal_to_irq_mapper_t irq_mapper; /* a function which maps signal to irq number*/ @@ -171,19 +171,19 @@ const mem_region_t *get_mem_regions(int32_t partition_id, uint32_t *region_count // Platform dependent APIs /* - * Validates a memory block is accessable from a specific partition + * Validates that a memory block accessible from a specific partition * - * @param[in] ptr pointer to the beggining of the memory block. - * @param[in] size size of the memory block in bytes. - * @param[in] accessing_partition which partition is trying to access the memory. - * @return true if the entire memory block is accessable from given partition. + * @param[in] ptr - Pointer to the beggining of the memory block. + * @param[in] size - Size of the memory block in bytes. + * @param[in] accessing_partition - Which partition is trying to access the memory. + * @return `true` if the entire memory block is accessable from given partition. */ bool is_buffer_accessible(const void *ptr, size_t size, spm_partition_t *accessing_partition); /** * Alerts NSPE that a proccess (connect or call) has ended. * - * @param[in] completion_sem_id semaphore id in NSPE. + * @param[in] completion_sem_id - semaphore id in NSPE. */ void nspe_done(osSemaphoreId_t completion_sem_id); diff --git a/components/TARGET_PSA/spm/COMPONENT_SPE/spm_server.h b/components/TARGET_PSA/spm/COMPONENT_SPE/spm_server.h index 718c512a2a2..c99efd7a0fc 100644 --- a/components/TARGET_PSA/spm/COMPONENT_SPE/spm_server.h +++ b/components/TARGET_PSA/spm/COMPONENT_SPE/spm_server.h @@ -35,7 +35,7 @@ extern "C" { #endif /** @addtogroup RoT-Service-API - * The C interface for a Root of Trust Service in a partition. + * The C interface for a root of trust (RoT) Service in a partition. * @{ */ @@ -75,8 +75,8 @@ int32_t psa_identity(psa_handle_t msg_handle); /** * Get the message that corresponds to a given signal. * - * @param[in] signum an asserted signal returned from psa_wait(). - * @param[out] msg pointer to a psa_msg structure. + * @param[in] signum An asserted signal returned from psa_wait(). + * @param[out] msg Pointer to a psa_msg structure. */ void psa_get(psa_signal_t signum, psa_msg_t *msg); diff --git a/components/TARGET_PSA/spm/doc/INTRO.md b/components/TARGET_PSA/spm/doc/INTRO.md deleted file mode 100644 index 7796b339d0a..00000000000 --- a/components/TARGET_PSA/spm/doc/INTRO.md +++ /dev/null @@ -1,117 +0,0 @@ -## The Secure Partition Manager - -The **Secure Partition Manager (SPM)** is a Platform Security Architecture (PSA) compliant software hypervisor that creates and manages independent Secure Partitions on Arm Cortex®-M microcontrollers. It increases resilience against malware and protects secrets from leaking between different modules in the same application. The SPM complements other important security features, such as safe firmware updates and secure crypto libraries. - -The SPM provides hardware-enforced partitions for individual code blocks by limiting access to memories and peripherals using the existing hardware security features of the Cortex®-M microcontrollers. It isolates software in partitions, managing the execution of software within those partitions and providing Inter Process Communication (IPC) between the partitions. Correct use of SPM prevents malware from becoming resident on the device and enables protection of device secrets, such as cryptographic keys. - -### Isolating partitions in the Secure Processing Environment - -The SPM and the secure partitions are located in the Secure Processing Environment (SPE), isolating them from the Non-Secure Processing Environment (NSPE), which contains the application firmware, OS kernel and libraries, and other nonsecure hardware resources. - -A secure partition is a container for one or more root of trust services, and a platform may have multiple secure partitions. Secure partitions provide the execution environment for security functionality. - -Platform hardware, such as the Security Attribution Unit (SAU) and Memory Protection Unit (MPU) in the new ARMv8-M platforms, enforces the separation of partitions. Other platforms may use different mechanisms to provide equivalent isolation for the partitions. - -#### PSA levels of isolation - -If you are prototyping software or using platforms without SAU or MPU, you can choose to have no isolation between the SPE and NSPE (sometimes referred to as Level 0), though the PSA does not specify this. However, for production software, consider implementing one of the following levels of isolation: - -* **Level 1 - SPE isolation** In this level, the SPE is fully isolated from the nonsecure application firmware and hardware. -* **Level 2 - Root of Trust isolation** In this level, the SPE is fully isolated from the nonsecure application firmware and hardware and the trusted partitions (secure partitions that implement Root of Trust services) are isolated from other secure partitions. -* **Level 3 - Maximum firmware isolation** In this level, the SPE is fully isolated from the nonsecure application firmware and hardware, and all secure and trusted partitions are individually sandboxed from one another and from the SPM. - -### Using secure partitions - -Secure partitions are located within the SPE, and must contain at least one set of related security operations (known as a root of trust service) or at least one Interrupt Request (IRQ). You can have multiple root of trust services in a single secure partition. - -For a secure partition, you need: - -* The **secure partition code**, which must: - * Be single threaded. - * Be structured as a loop that waits for inputs. - * Never exit its loop (considered as a programming error). - * Be written in C or 'extern "C"' to avoid C++ name mangling. - * Follow PSA IPC rules. Secure partitions communicate with one another using the IPC API defined in [IPC API](https://github.com/ARMmbed/PSA-IPC-doc/blob/master/IPC_revision.md). All IPC messages must eventually be completed [`call psa_end()`]. Note that the SPM does not schedule IPC messages fairly. -* A **manifest file** in JSON format, that describes the Secure Partition characteristics. The specifications in the manifest file are validated during the build process and at run time. - -### Manifest file example - -The secure partition manifest file describes the properties of the secure partitions. In this file: - -* **entry_point** is the function name of the partition's thread. -* **source_files** is the list of source files containing the partition's code. -* **heap_size** sets the heap size for platforms that have an isolation level of 2 and higher. -* **services** is the list of the partition's root of trust services with their properties. -* **extern_sids** defines a dependency to other Root of Trust Service (referenced by SID). If the manifest does not specify the access between a partition (acting as client) and a root of trust service (acting as server), then the client is not able to send any messages to the root of trust service. - -For example: - -```json -{ - "name": "BOX_MAIN", - "type": "APPLICATION-ROT", - "priority": "NORMAL", - "id": "0x7BADD00D", - "entry_point": "main", - "stack_size": 10, - "heap_size": "0x0400", - "mmio_regions": [ - { - "name": "CMU", - "permission": "READ-WRITE" - }, - { - "name": "MSC", - "permission": "READ-WRITE" - }, - { - "name": "GPIO", - "permission": "READ-WRITE" - }, - { - "name": "TIMER0", - "permission": "READ-WRITE" - }, - { - "name": "UART0", - "permission": "READ-WRITE" - }, - { - "base": "0x10000000", - "size": "0x1000", - "permission": "READ-ONLY" - }, - { - "base": "0x42000000", - "size": "0x02000000", - "permission": "READ-ONLY" - } - ], - "services": [ - { - "sid": "PSA_TRUSTED_UPDATE", - "signal": "PSA_TRUSTED_UPDATE", - "non_secure_clients": true, - "minor_version": 1, - "minor_policy": "STRICT" - } - ], - "extern_sids": [ - "PSA_CRYPTO_RSA", - "PSA_CRYPTO_AES" - ], - "source_files": [ - "../source/main.cpp" - ], - "irqs": [ - { - "signal": "MY_IRQ", - "line_num": 4 - } - ] -} -``` - -#### Code example - -[Mbed SPM example on GitHub](https://github.com/ARMmbed/mbed-os-example-spm) diff --git a/components/TARGET_PSA/spm/doc/README.md b/components/TARGET_PSA/spm/doc/README.md deleted file mode 100644 index fb7cf74fe0c..00000000000 --- a/components/TARGET_PSA/spm/doc/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Mbed Secure Partition Manager (SPM) - -The Platform Security Architecture (PSA) firmware framework specifications contain a logic component called the Secure Partition Manager (SPM). PSA defines a Secure Processing Environment (SPE) for: - -* Sensitive data, such as keys, credentials and firmware. -* The code that manages it. -* Its trusted hardware resources. - -The PSA SPM interfaces decouple components, allowing reuse of components in other device platform and helps to reduce an integration effort. - -Mbed SPM is an implementation of PSA SPM, which: - -* Secures low cost IoT devices, where a full Trusted Execution Environment (TEE) would not be appropriate. -* Protects sensitive assets (keys, credentials and firmware) by separating these from the application firmware and hardware. -* Is architecture agnostic and can be implemented on different Arm Cortex®-M architectures, offering variable level of protection, based on platform resources. - -![diagram](png/PSA-standardized-Interfaces-diagram.png) - -## Further reading - -* The [introduction to PSA SPM](INTRO.md) provides more details about PSA SPM. -* Visit the official Arm Platform Security Architecture web page https://pages.arm.com/psa-resources -* Trusted firmware presentation during the Linaro Connect event by James King on IOT http://connect.linaro.org/resource/hkg18/hkg18-212/ diff --git a/components/TARGET_PSA/spm/doc/png/PSA-standardized-Interfaces-diagram.png b/components/TARGET_PSA/spm/doc/png/PSA-standardized-Interfaces-diagram.png deleted file mode 100644 index f8c4cc80c64..00000000000 Binary files a/components/TARGET_PSA/spm/doc/png/PSA-standardized-Interfaces-diagram.png and /dev/null differ diff --git a/doxyfile_options b/doxyfile_options index 43aca60d4de..b477f1909be 100644 --- a/doxyfile_options +++ b/doxyfile_options @@ -2099,6 +2099,8 @@ PREDEFINED = DOXYGEN_ONLY \ DEVICE_SPISLAVE \ DEVICE_QSPI \ DEVICE_STORAGE \ + COMPONENT_SPE \ + COMPONENT_SPM_MAILBOX \ "MBED_DEPRECATED_SINCE(d, m)=" \ "MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=" \ "MBED_DEPRECATED(s)=" diff --git a/doxygen_options.json b/doxygen_options.json index fc1279a5ece..0e884b9a43f 100644 --- a/doxygen_options.json +++ b/doxygen_options.json @@ -6,7 +6,7 @@ "SEARCH_INCLUDES": "YES", "INCLUDE_PATH": "", "INCLUDE_FILE_PATTERNS": "", - "PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_CRC DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_ITM DEVICE_LPTICKER DEVICE_MPU DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_QSPI DEVICE_STORAGE \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\" \"MBED_DEPRECATED(s)=\"", + "PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_CRC DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_ITM DEVICE_LPTICKER DEVICE_MPU DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_QSPI DEVICE_STORAGE COMPONENT_SPE COMPONENT_SPM_MAILBOX \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\" \"MBED_DEPRECATED(s)=\"", "EXPAND_AS_DEFINED": "", "SKIP_FUNCTION_MACROS": "NO", "STRIP_CODE_COMMENTS": "NO", diff --git a/features/FEATURE_BLE/README.md b/features/FEATURE_BLE/README.md index 17821ec3b92..6030bd3515d 100644 --- a/features/FEATURE_BLE/README.md +++ b/features/FEATURE_BLE/README.md @@ -1,28 +1,10 @@ # mbed Bluetooth Low Energy Stack -This is the Github repo for the `BLE_API` used by developer.mbed.org. Please see the [mbed BLE Homepage](https://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all documentation, code examples and general help. -# Supported Services -Supported GATT services and constantly being added and can be found in the [ble/services/](https://github.com/ARMmbed/ble/tree/master/ble/services) folder. +This is the Github repository for the `BLE_API`. Please see the [Mbed OS Example BLE GitHub Repo](https://github.com/ARMmbed/mbed-os-example-ble) for all code examples, and the [Mbed OS BLE API page](https://os.mbed.com/docs/latest/apis/bluetooth.html) for all code documentation and general help. -Currently supported services include: -* Battery -* Device Firmware Update (DFU) -* Device Information -* Eddystone Configuration Service -* Health Thermometer -* Heart Rate -* Link Loss -* UART -* UriBeacon -* iBeacon +## Getting Started -The [documentation](https://docs.mbed.com/docs/ble-intros/en/latest/AdvSamples/Overview/) -contains an overview on how to create new, application-specific services. - -# Getting Started -The mbed BLE API is meant to be used in projects on developer.mbed.org. Please see examples and sample project files there. -A good starting point are these pages: -* [mbed BLE Homepage](https://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all things BLE -* [mbed BLE Getting Started Guide](https://developer.mbed.org/forum/team-63-Bluetooth-Low-Energy-community/topic/5262/) a wonderful primer on using BLE with mbed -* [mbed BLE doc](https://docs.mbed.com/docs/ble-intros/en/latest/) for an introduction to mbed BLE -* [mbed BLE API page](https://docs.mbed.com/docs/ble-api/en/latest/api/index.html) for the Doxygen API documentation +* [Mbed OS examples](https://os.mbed.com/teams/mbed-os-examples/) for all Mbed OS and BLE examples. +* [Mbed OS example BLE GitHub repo](https://github.com/ARMmbed/mbed-os-example-ble) for all Mbed OS BLE examples. +* [Mbed OS BLE introduction](https://os.mbed.com/docs/latest/apis/ble.html) for an introduction to Mbed BLE. +* [Mbed OS BLE API page](https://os.mbed.com/docs/latest/apis/bluetooth.html) for the Mbed BLE API documentation. diff --git a/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h b/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h index e41610b9fe0..1bc947cad02 100644 --- a/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h +++ b/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h @@ -87,7 +87,7 @@ class AdvertisingDataParser { element_t next() { element_t element = { - (ble::adv_data_type_t::type) data[TYPE_INDEX], + (ble::adv_data_type_t::type) data[position + TYPE_INDEX], data.subspan(position + VALUE_INDEX, current_length() - (TYPE_SIZE)) }; diff --git a/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h b/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h index 18e9c83f378..304abddaadd 100644 --- a/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h +++ b/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h @@ -135,7 +135,7 @@ class AdvertisingParameters { _minInterval(minInterval), _maxInterval(maxInterval), _peerAddressType(target_peer_address_type_t::PUBLIC), - _ownAddressType(own_address_type_t::PUBLIC), + _ownAddressType(own_address_type_t::RANDOM), _policy(advertising_filter_policy_t::NO_FILTER), _primaryPhy(phy_t::LE_1M), _secondaryPhy(phy_t::LE_1M), diff --git a/features/FEATURE_BLE/ble/gap/ConnectionParameters.h b/features/FEATURE_BLE/ble/gap/ConnectionParameters.h index d93052a48fd..33aeaf5c466 100644 --- a/features/FEATURE_BLE/ble/gap/ConnectionParameters.h +++ b/features/FEATURE_BLE/ble/gap/ConnectionParameters.h @@ -145,10 +145,10 @@ class ConnectionParameters { phy_t phy = phy_t::LE_1M, scan_interval_t scanInterval = scan_interval_t::min(), scan_window_t scanWindow = scan_window_t::min(), - conn_interval_t minConnectionInterval = conn_interval_t::min(), - conn_interval_t maxConnectionInterval = conn_interval_t::max(), + conn_interval_t minConnectionInterval = conn_interval_t(50), + conn_interval_t maxConnectionInterval = conn_interval_t(100), slave_latency_t slaveLatency = slave_latency_t::min(), - supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t::max(), + supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t(100), conn_event_length_t minEventLength = conn_event_length_t::min(), conn_event_length_t maxEventLength = conn_event_length_t::max() ); @@ -215,7 +215,7 @@ class ConnectionParameters { * * @return A reference to this. */ - ConnectionParameters &setFilterPolicy(initiator_filter_policy_t filterPolicy) + ConnectionParameters &setFilter(initiator_filter_policy_t filterPolicy) { _filterPolicy = filterPolicy; @@ -282,7 +282,7 @@ class ConnectionParameters { * * @return The initiator policy. */ - initiator_filter_policy_t getFilterPolicy() const + initiator_filter_policy_t getFilter() const { return _filterPolicy; } diff --git a/features/FEATURE_BLE/ble/gap/Events.h b/features/FEATURE_BLE/ble/gap/Events.h index 3c09137517c..38c910a34c6 100644 --- a/features/FEATURE_BLE/ble/gap/Events.h +++ b/features/FEATURE_BLE/ble/gap/Events.h @@ -152,7 +152,7 @@ struct AdvertisingReportEvent { } /** Get payload. */ - const mbed::Span &getAdvertisingData() const + const mbed::Span &getPayload() const { return advertisingData; } @@ -630,10 +630,10 @@ struct ScanRequestEvent { * * @see ble::Gap::EventHandler::onDisconnectionComplete(). */ -struct DisconnectionEvent { +struct DisconnectionCompleteEvent { #if !defined(DOXYGEN_ONLY) - DisconnectionEvent( + DisconnectionCompleteEvent( connection_handle_t connectionHandle, const disconnection_reason_t &reason ) : diff --git a/features/FEATURE_BLE/ble/gap/Gap.h b/features/FEATURE_BLE/ble/gap/Gap.h index ecf281fc1ba..194369c6230 100644 --- a/features/FEATURE_BLE/ble/gap/Gap.h +++ b/features/FEATURE_BLE/ble/gap/Gap.h @@ -427,7 +427,7 @@ class Gap { * * @see disconnect() */ - virtual void onDisconnectionComplete(const DisconnectionEvent &event) + virtual void onDisconnectionComplete(const DisconnectionCompleteEvent &event) { } @@ -536,7 +536,7 @@ class Gap { * * @return Maximum advertising data length supported. */ - virtual uint8_t getMaxAdvertisingDataLength(); + virtual uint16_t getMaxAdvertisingDataLength(); /** Create an advertising set and apply the passed in parameters. The handle returned * by this function must be used for all other calls that accept an advertising handle. @@ -711,8 +711,8 @@ class Gap { /** Start scanning. * - * @param filtering Filtering policy. * @param duration How long to scan for. Special value 0 means scan forever. + * @param filtering Filtering policy. * @param period How long to scan for in single period. If the period is 0 and duration * is nonzero the scan will last for single duration. * @@ -726,8 +726,8 @@ class Gap { * @see EventHandler::onScanTimeout when scanning timeout. */ virtual ble_error_t startScan( - duplicates_filter_t filtering = duplicates_filter_t::DISABLE, scan_duration_t duration = scan_duration_t::forever(), + duplicates_filter_t filtering = duplicates_filter_t::DISABLE, scan_period_t period = scan_period_t(0) ); diff --git a/features/FEATURE_BLE/ble/gap/ScanParameters.h b/features/FEATURE_BLE/ble/gap/ScanParameters.h index 494cc818f67..9eb9c610bc6 100644 --- a/features/FEATURE_BLE/ble/gap/ScanParameters.h +++ b/features/FEATURE_BLE/ble/gap/ScanParameters.h @@ -121,7 +121,7 @@ class ScanParameters { scan_window_t scan_interval = scan_interval_t::min(), scan_interval_t scan_window = scan_window_t::min(), bool active_scanning = false, - own_address_type_t own_address_type = own_address_type_t::PUBLIC, + own_address_type_t own_address_type = own_address_type_t::RANDOM, scanning_filter_policy_t scanning_filter_policy = scanning_filter_policy_t::NO_FILTER ) : own_address_type(own_address_type), diff --git a/features/FEATURE_BLE/ble/gap/Types.h b/features/FEATURE_BLE/ble/gap/Types.h index 59f07ba91b8..1eab24978a7 100644 --- a/features/FEATURE_BLE/ble/gap/Types.h +++ b/features/FEATURE_BLE/ble/gap/Types.h @@ -891,6 +891,9 @@ struct peripheral_privacy_configuration_t { PERFORM_AUTHENTICATION_PROCEDURE }; + MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.") + typedef resolution_strategy_t ResolutionStrategy; + /** * Connection strategy to use when a connection request contains a * private resolvable address. @@ -941,6 +944,9 @@ struct central_privay_configuration_t { RESOLVE_AND_FILTER }; + MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.") + typedef resolution_strategy_t ResolutionStrategy; + /** * Resolution strategy applied to advertising packets received by the * local device. diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index d3a02ffdd94..8b3fd4af131 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -90,7 +90,7 @@ class GenericGap : /** @copydoc Gap::getMaxAdvertisingDataLength */ - virtual uint8_t getMaxAdvertisingDataLength(); + virtual uint16_t getMaxAdvertisingDataLength(); /** @copydoc Gap::createAdvertisingSet */ @@ -175,8 +175,8 @@ class GenericGap : /** @copydoc Gap::startScan */ virtual ble_error_t startScan( - duplicates_filter_t filtering, scan_duration_t duration, + duplicates_filter_t filtering, scan_period_t period ); diff --git a/features/FEATURE_BLE/source/BLE.cpp b/features/FEATURE_BLE/source/BLE.cpp index e61356c075f..e9f66c3bb27 100644 --- a/features/FEATURE_BLE/source/BLE.cpp +++ b/features/FEATURE_BLE/source/BLE.cpp @@ -17,6 +17,7 @@ #include #include "ble/BLE.h" #include "ble/BLEInstanceBase.h" +#include "platform/mbed_critical.h" #if defined(TARGET_OTA_ENABLED) #include "ble/services/DFUService.h" @@ -299,16 +300,19 @@ void BLE::waitForEvent(void) void BLE::processEvents() { + core_util_critical_section_enter(); if (event_signaled == false) { + core_util_critical_section_exit(); return; } + event_signaled = false; + core_util_critical_section_exit(); + if (!transport) { MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_BACKEND_NOT_INITIALIZED), "bad handle to underlying transport"); } - event_signaled = false; - transport->processEvents(); } @@ -328,11 +332,14 @@ void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& callback) void BLE::signalEventsToProcess() { + core_util_critical_section_enter(); if (event_signaled == true) { + core_util_critical_section_exit(); return; } event_signaled = true; + core_util_critical_section_exit(); if (whenEventsToProcess) { OnEventsToProcessCallbackContext params = { diff --git a/features/FEATURE_BLE/source/gap/ConnectionParameters.cpp b/features/FEATURE_BLE/source/gap/ConnectionParameters.cpp index 3ed5b646ef9..837a706f850 100644 --- a/features/FEATURE_BLE/source/gap/ConnectionParameters.cpp +++ b/features/FEATURE_BLE/source/gap/ConnectionParameters.cpp @@ -30,7 +30,7 @@ ConnectionParameters::ConnectionParameters( conn_event_length_t maxEventLength ) : _filterPolicy(initiator_filter_policy_t::NO_FILTER), - _ownAddressType(own_address_type_t::PUBLIC) + _ownAddressType(own_address_type_t::RANDOM) { for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) { _enabledPhy[i] = false; diff --git a/features/FEATURE_BLE/source/gap/Gap.cpp b/features/FEATURE_BLE/source/gap/Gap.cpp index 4cb4c6a50e8..3515ddd531d 100644 --- a/features/FEATURE_BLE/source/gap/Gap.cpp +++ b/features/FEATURE_BLE/source/gap/Gap.cpp @@ -30,7 +30,7 @@ uint8_t Gap::getMaxAdvertisingSetNumber() return 1; } -uint8_t Gap::getMaxAdvertisingDataLength() +uint16_t Gap::getMaxAdvertisingDataLength() { /* Requesting action from porter(s): override this API if this capability is supported. */ return LEGACY_ADVERTISING_MAX_SIZE; @@ -145,8 +145,8 @@ ble_error_t Gap::setScanParameters(const ScanParameters ¶ms) }; ble_error_t Gap::startScan( - duplicates_filter_t filtering, scan_duration_t duration, + duplicates_filter_t filtering, scan_period_t period ) { diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index a4928a07dff..9191b55fbed 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -675,10 +675,13 @@ ble_error_t GenericGap::connect( return BLE_ERROR_INVALID_PARAM; } + // ensure scan is stopped. + _pal_gap.scan_enable(false, false); + return _pal_gap.create_connection( connectionParams.getScanIntervalArray()[0], connectionParams.getScanWindowArray()[0], - connectionParams.getFilterPolicy(), + connectionParams.getFilter(), (pal::connection_peer_address_type_t::type) peerAddressType.value(), peerAddress, connectionParams.getOwnAddressType(), @@ -691,6 +694,9 @@ ble_error_t GenericGap::connect( ); } + // ensure scan is stopped. + _pal_gap.extended_scan_enable(false, pal::duplicates_filter_t::DISABLE, 0, 0); + // reduce the address type to public or random peer_address_type_t adjusted_address_type(peer_address_type_t::PUBLIC); @@ -701,7 +707,7 @@ ble_error_t GenericGap::connect( } return _pal_gap.extended_create_connection( - connectionParams.getFilterPolicy(), + connectionParams.getFilter(), connectionParams.getOwnAddressType(), adjusted_address_type, peerAddress, @@ -1442,7 +1448,7 @@ void GenericGap::processDisconnectionEvent( if (_eventHandler) { _eventHandler->onDisconnectionComplete( - DisconnectionEvent( + DisconnectionCompleteEvent( handle, (disconnection_reason_t::type) reason ) @@ -1997,7 +2003,7 @@ uint8_t GenericGap::getMaxAdvertisingSetNumber() } } -uint8_t GenericGap::getMaxAdvertisingDataLength() +uint16_t GenericGap::getMaxAdvertisingDataLength() { useVersionTwoAPI(); return _pal_gap.get_maximum_advertising_data_length(); @@ -2053,7 +2059,7 @@ ble_error_t GenericGap::destroyAdvertisingSet(advertising_handle_t handle) return BLE_ERROR_INVALID_PARAM; } - if (_existing_sets.get(handle) == false) { + if (!_existing_sets.get(handle)) { return BLE_ERROR_INVALID_PARAM; } @@ -2357,10 +2363,14 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle) return BLE_ERROR_INVALID_PARAM; } - if (_existing_sets.get(handle)) { + if (!_existing_sets.get(handle)) { return BLE_ERROR_INVALID_PARAM; } + if (!_active_sets.get(handle)) { + return BLE_ERROR_INVALID_STATE; + } + ble_error_t status; if (is_extended_advertising_available()) { @@ -2427,7 +2437,7 @@ ble_error_t GenericGap::setPeriodicAdvertisingParameters( } if (!_existing_sets.get(handle)) { - return BLE_ERROR_INVALID_STATE; + return BLE_ERROR_INVALID_PARAM; } return _pal_gap.set_periodic_advertising_parameters( @@ -2454,7 +2464,7 @@ ble_error_t GenericGap::setPeriodicAdvertisingPayload( } if (!_existing_sets.get(handle)) { - return BLE_ERROR_INVALID_STATE; + return BLE_ERROR_INVALID_PARAM; } if (payload.size() > getMaxAdvertisingDataLength()) { @@ -2511,7 +2521,7 @@ ble_error_t GenericGap::startPeriodicAdvertising(advertising_handle_t handle) } if (!_existing_sets.get(handle)) { - return BLE_ERROR_INVALID_STATE; + return BLE_ERROR_INVALID_PARAM; } if (_active_sets.get(handle) == false) { @@ -2544,7 +2554,7 @@ ble_error_t GenericGap::stopPeriodicAdvertising(advertising_handle_t handle) } if (!_existing_sets.get(handle)) { - return BLE_ERROR_INVALID_STATE; + return BLE_ERROR_INVALID_PARAM; } if (_active_periodic_sets.get(handle) == false) { @@ -2859,8 +2869,8 @@ ble_error_t GenericGap::setScanParameters(const ScanParameters ¶ms) } ble_error_t GenericGap::startScan( - duplicates_filter_t filtering, scan_duration_t duration, + duplicates_filter_t filtering, scan_period_t period ) { diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp index 1179fa776e3..7b15cfe3d9d 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp @@ -510,30 +510,7 @@ void Gap::gap_handler(const wsfMsgHdr_t *msg) handler->on_periodic_advertising_sync_loss(evt->syncHandle); } break; - - case DM_CONN_OPEN_IND: { - if (!handler) { - break; - } - - // TODO: filter with old event ... - const hciLeConnCmplEvt_t *evt = (const hciLeConnCmplEvt_t *) msg; - handler->on_enhanced_connection_complete( - hci_error_code_t(evt->status), - evt->handle, - connection_role_t(evt->role), - connection_peer_address_type_t(evt->addrType), - evt->peerAddr, - evt->localRpa, - evt->peerRpa, - evt->connInterval, - evt->connLatency, - evt->supTimeout, - clock_accuracy_t(evt->clockAccuracy) - ); - } - break; - + case DM_SCAN_REQ_RCVD_IND: { if (!handler) { break; diff --git a/features/mbedtls/VERSION.txt b/features/mbedtls/VERSION.txt index 31b45ded6e8..a85e9b07f86 100644 --- a/features/mbedtls/VERSION.txt +++ b/features/mbedtls/VERSION.txt @@ -1,2 +1,2 @@ -mbedtls-2.15.0 -mbedcrypto-0.1.0b +mbedtls-2.15.1 +mbedcrypto-0.1.0b2 diff --git a/features/mbedtls/importer/Makefile b/features/mbedtls/importer/Makefile index 1ae8af23800..7c90dc3104a 100644 --- a/features/mbedtls/importer/Makefile +++ b/features/mbedtls/importer/Makefile @@ -27,7 +27,7 @@ # # Set the mbed TLS release to import (this can/should be edited before import) -MBED_TLS_RELEASE ?= mbedtls-2.15.0 +MBED_TLS_RELEASE ?= mbedtls-2.15.1 # Translate between mbed TLS namespace and mbed namespace TARGET_PREFIX:=../ diff --git a/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto.c b/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto.c index d100eb1fcb1..fc296d36557 100644 --- a/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto.c +++ b/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto.c @@ -3146,7 +3146,7 @@ static void psa_aead_abort( aead_operation_t *operation ) mbedtls_ccm_free( &operation->ctx.ccm ); break; #endif /* MBEDTLS_CCM_C */ -#if defined(MBEDTLS_CCM_C) +#if defined(MBEDTLS_GCM_C) case PSA_ALG_GCM: mbedtls_gcm_free( &operation->ctx.gcm ); break; @@ -3259,6 +3259,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key, } tag = ciphertext + plaintext_length; +#if defined(MBEDTLS_GCM_C) if( operation.core_alg == PSA_ALG_GCM ) { status = mbedtls_to_psa_error( @@ -3270,7 +3271,10 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key, plaintext, ciphertext, operation.tag_length, tag ) ); } - else if( operation.core_alg == PSA_ALG_CCM ) + else +#endif /* MBEDTLS_GCM_C */ +#if defined(MBEDTLS_CCM_C) + if( operation.core_alg == PSA_ALG_CCM ) { status = mbedtls_to_psa_error( mbedtls_ccm_encrypt_and_tag( &operation.ctx.ccm, @@ -3282,6 +3286,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key, tag, operation.tag_length ) ); } else +#endif /* MBEDTLS_CCM_C */ { return( PSA_ERROR_NOT_SUPPORTED ); } @@ -3339,6 +3344,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key, if( status != PSA_SUCCESS ) return( status ); +#if defined(MBEDTLS_GCM_C) if( operation.core_alg == PSA_ALG_GCM ) { status = psa_aead_unpadded_locate_tag( operation.tag_length, @@ -3356,7 +3362,10 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key, tag, operation.tag_length, ciphertext, plaintext ) ); } - else if( operation.core_alg == PSA_ALG_CCM ) + else +#endif /* MBEDTLS_GCM_C */ +#if defined(MBEDTLS_CCM_C) + if( operation.core_alg == PSA_ALG_CCM ) { status = psa_aead_unpadded_locate_tag( operation.tag_length, ciphertext, ciphertext_length, @@ -3374,6 +3383,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key, tag, operation.tag_length ) ); } else +#endif /* MBEDTLS_CCM_C */ { return( PSA_ERROR_NOT_SUPPORTED ); } @@ -4249,7 +4259,7 @@ static psa_status_t its_to_psa_error( psa_its_status_t ret ) return( PSA_ERROR_INSUFFICIENT_STORAGE ); case PSA_ITS_ERROR_INVALID_KEY: - case PSA_PS_ERROR_OFFSET_INVALID: + case PSA_ITS_ERROR_OFFSET_INVALID: case PSA_ITS_ERROR_INCORRECT_SIZE: case PSA_ITS_ERROR_BAD_POINTER: return( PSA_ERROR_INVALID_ARGUMENT ); diff --git a/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto_storage_its.c b/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto_storage_its.c index 29394b5d89c..35caa39adcd 100644 --- a/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto_storage_its.c +++ b/features/mbedtls/mbed-crypto/platform/TARGET_PSA/COMPONENT_PSA_SRV_IMPL/psa_crypto_storage_its.c @@ -52,7 +52,7 @@ static psa_status_t its_to_psa_error( psa_its_status_t ret ) return( PSA_ERROR_INSUFFICIENT_STORAGE ); case PSA_ITS_ERROR_INVALID_KEY: - case PSA_PS_ERROR_OFFSET_INVALID: + case PSA_ITS_ERROR_OFFSET_INVALID: case PSA_ITS_ERROR_INCORRECT_SIZE: case PSA_ITS_ERROR_BAD_POINTER: return( PSA_ERROR_INVALID_ARGUMENT ); diff --git a/features/mbedtls/targets/TARGET_STM/aes_alt.c b/features/mbedtls/targets/TARGET_STM/aes_alt.c index dae8721634a..84d3ed2c645 100644 --- a/features/mbedtls/targets/TARGET_STM/aes_alt.c +++ b/features/mbedtls/targets/TARGET_STM/aes_alt.c @@ -56,13 +56,14 @@ static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsig return (MBEDTLS_ERR_AES_INVALID_KEY_LENGTH); } + ctx->hcryp_aes.Init.DataType = CRYP_DATATYPE_8B; + ctx->hcryp_aes.Instance = CRYP; + /* Deinitializes the CRYP peripheral */ if (HAL_CRYP_DeInit(&ctx->hcryp_aes) == HAL_ERROR) { return (HAL_ERROR); } - ctx->hcryp_aes.Init.DataType = CRYP_DATATYPE_8B; - ctx->hcryp_aes.Instance = CRYP; /* Enable CRYP clock */ __HAL_RCC_CRYP_CLK_ENABLE(); diff --git a/hal/spm_api.h b/hal/spm_api.h index 1b05247643c..593fbff1c46 100644 --- a/hal/spm_api.h +++ b/hal/spm_api.h @@ -1,3 +1,6 @@ + +/** \addtogroup hal */ +/** @{*/ /* Copyright (c) 2017-2018 ARM Limited * * SPDX-License-Identifier: Apache-2.0 @@ -18,14 +21,6 @@ #ifndef __SPM_API_H__ #define __SPM_API_H__ - -/** @addtogroup SPM - * The Secure Partition Manager (SPM) is responsible for isolating software in - * partitions, managing the execution of software within partitions and - * providing IPC between partitions. - * @{ - */ - #include #include @@ -34,8 +29,8 @@ extern "C" { #endif -/** @addtogroup HAL-SPE - * The HAL functions for SPE. +/** @defgroup SPM-HAL SPM HAL API + * The HAL functions for PSA SPM * @{ */ @@ -92,12 +87,12 @@ void spm_hal_mailbox_notify(void); #endif // defined(COMPONENT_SPM_MAILBOX) -/** @}*/ // end of HAL-SPE group +/** @}*/ #ifdef __cplusplus } #endif -/** @}*/ // end of SPM group - #endif // __SPM_API_H__ + +/** @}*/ diff --git a/targets/targets.json b/targets/targets.json index 936f986264f..d2b66391ed8 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -3225,7 +3225,8 @@ "macros_add": [ "MBEDTLS_CONFIG_HW_SUPPORT", "WISE_1570", - "TWO_RAM_REGIONS" + "TWO_RAM_REGIONS", + "MBED_MPU_CUSTOM" ], "device_has_add": [ "ANALOGOUT", @@ -3233,8 +3234,7 @@ "SERIAL_ASYNCH", "SERIAL_FC", "TRNG", - "FLASH", - "MPU" + "FLASH" ], "device_has_remove": ["LPTICKER"], "release_versions": ["5"], @@ -3975,7 +3975,8 @@ "MBEDTLS_DES_C", "MBEDTLS_MD4_C", "MBEDTLS_MD5_C", - "MBEDTLS_SHA1_C" + "MBEDTLS_SHA1_C", + "MBED_MPU_CUSTOM" ], "device_has_add": [ "CAN", @@ -3984,8 +3985,7 @@ "FLASH", "WIFI", "SERIAL_FC", - "SERIAL", - "MPU" + "SERIAL" ], "features": ["BLE"], "device_has_remove": [], @@ -7534,6 +7534,7 @@ }, "MCU_PSOC6": { "inherits": ["Target"], + "macros": ["MBED_MPU_CUSTOM"], "default_toolchain": "GCC_ARM", "supported_toolchains": ["GCC_ARM", "IAR", "ARM"], "core": "Cortex-M4F", @@ -7558,12 +7559,8 @@ "STDIO_MESSAGES", "LPTICKER", "SLEEP", - "FLASH", - "MPU" + "FLASH" ], - "overrides": { - "mpu-rom-end": "0x1fffffff" - }, "release_versions": ["5"], "extra_labels": ["Cypress", "PSOC6"], "public": false @@ -7571,12 +7568,12 @@ "MCU_PSOC6_M0": { "inherits": ["MCU_PSOC6"], "core": "Cortex-M0+", - "macros": ["MCU_PSOC6_M0"], + "macros_add": ["MCU_PSOC6_M0"], "public": false }, "MCU_PSOC6_M4": { "inherits": ["MCU_PSOC6"], - "macros": ["MCU_PSOC6_M4"], + "macros_add": ["MCU_PSOC6_M4"], "public": false }, "FUTURE_SEQUANA_M0": { diff --git a/tools/build.py b/tools/build.py index a11cd2f56d3..40b0a52771f 100644 --- a/tools/build.py +++ b/tools/build.py @@ -188,7 +188,7 @@ mcu = TARGET_MAP[target] profile = extract_profile(parser, options, toolchain) - if Target.get_target(mcu).is_PSA_secure_target: + if mcu.is_PSA_secure_target: lib_build_res = build_library( ROOT, options.build_dir, mcu, toolchain, jobs=options.jobs,