Skip to content

Commit

Permalink
Merge pull request #29 from mbed-ce/upstream-fixes
Browse files Browse the repository at this point in the history
Merge latest fixes in from upstream (Apr through June)
  • Loading branch information
multiplemonomials committed Jul 9, 2022
2 parents ee41930 + 2a7efd8 commit d00ea7d
Show file tree
Hide file tree
Showing 29 changed files with 484 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/basic_checks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This workflow performs the checks like license check,
# This workflow performs the checks like license check,
# doxygen, unit tests etc.
name: Basic Checks

Expand Down
16 changes: 16 additions & 0 deletions connectivity/FEATURE_BLE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ This is the Github repository for the `BLE_API`. Please see the [Mbed OS Example
* [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.

## Privacy notice

The Cordio Bluetooth stack only stores one single signing key. This key is then
shared across all bonded devices. If a malicious device bonds with the Mbed OS
application it then gains knowledge of the shared signing key of the Mbed OS device.
The malicious device can then track the Mbed OS device whenever a signing write
is issued from it.

To overcome this privacy issue do not issue signed writes from the Mbed OS device.
A signed write occurs when the member function `write` of `GattClient` is called
with its `cmd` argument set to `GATT_OP_SIGNED_WRITE_CMD`.

Instead of using signed writes, enable encryption on the connection. This is achieved
by calling the function `setLinkEncryption` of the `SecurityManager`. Set the encryption
to at least `ENCRYPTED`.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AT_CellularDevice : public CellularDevice {
};

public:
AT_CellularDevice(FileHandle *fh);
AT_CellularDevice(FileHandle *fh, char *delim = "\r");
virtual ~AT_CellularDevice();

virtual nsapi_error_t clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ using namespace std::chrono_literals;
#define DEFAULT_AT_TIMEOUT 1s // at default timeout
const int MAX_SIM_RESPONSE_LENGTH = 16;

AT_CellularDevice::AT_CellularDevice(FileHandle *fh) :
AT_CellularDevice::AT_CellularDevice(FileHandle *fh, char *delim):
CellularDevice(),
_at(fh, _queue, DEFAULT_AT_TIMEOUT, "\r"),
_at(fh, _queue, DEFAULT_AT_TIMEOUT, delim),
#if MBED_CONF_CELLULAR_USE_SMS
_sms(0),
#endif // MBED_CONF_CELLULAR_USE_SMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ bool AT_CellularDevice_stub::pin_needed = false;
bool AT_CellularDevice_stub::supported_bool = false;
int AT_CellularDevice_stub::max_sock_value = 1;

AT_CellularDevice::AT_CellularDevice(FileHandle *fh) :
AT_CellularDevice::AT_CellularDevice(FileHandle *fh, char *delim) :
CellularDevice(),
_at(fh, _queue, get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), "\r"),
_at(fh, _queue, get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), delim),
#if MBED_CONF_CELLULAR_USE_SMS
_sms(0),
#endif // MBED_CONF_CELLULAR_USE_SMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input()
message_length -= CRC_LENGTH_BYTES;
}
p = _memory_manager->alloc_heap(SMSC9220_ETH_MAX_FRAME_SIZE,
p = _memory_manager->alloc_heap(message_length,
SMSC9220_BUFF_ALIGNMENT);
if (p != NULL) {
_RXLockMutex.lock();
received_bytes = smsc9220_receive_by_chunks(dev,
(char*)_memory_manager->get_ptr(p),
_memory_manager->get_len(p));
received_bytes = smsc9220_receive_packet(dev,
_memory_manager->get_ptr(p));
if(received_bytes == 0){
_memory_manager->free(p);
p = nullptr;
Expand Down Expand Up @@ -148,7 +147,6 @@ bool SMSC9220_EMAC::link_out(emac_mem_buf_t *buf)
if(buf == NULL) {
return false;
} else {
uint32_t buffer_chain_length = 0;
enum smsc9220_error_t error = SMSC9220_ERROR_NONE;
/* If buffer is chained or not aligned then
* make a contiguous aligned copy of it */
Expand All @@ -170,16 +168,12 @@ bool SMSC9220_EMAC::link_out(emac_mem_buf_t *buf)
buf = copy_buf;
}
buffer_chain_length = _memory_manager->get_total_len(buf);
_TXLockMutex.lock();
error = smsc9220_send_by_chunks(dev,
buffer_chain_length,
true,
(const char*)_memory_manager->get_ptr(buf),
error = smsc9220_send_packet(dev,
_memory_manager->get_ptr(buf),
_memory_manager->get_len(buf));
_memory_manager->free(buf);
_TXLockMutex.unlock();
_TXLockMutex.unlock();
return (error == SMSC9220_ERROR_NONE);
}
}
Expand Down Expand Up @@ -211,7 +205,7 @@ bool SMSC9220_EMAC::power_up()
this));
/* Initialize the hardware */
enum smsc9220_error_t init_successful = smsc9220_init(dev, &ThisThread::sleep_for);
enum smsc9220_error_t init_successful = smsc9220_init(dev, &thread_sleep_for);
if (init_successful != SMSC9220_ERROR_NONE) {
return false;
}
Expand All @@ -237,7 +231,7 @@ bool SMSC9220_EMAC::power_up()
&SMSC9220_EMAC::link_status_task));
/* Allow the Link Status task to detect the initial link state */
ThisThread::sleep_for(10);
ThisThread::sleep_for(10ms);
_link_status_task_handle = mbed::mbed_event_queue()->call_every(
LINK_STATUS_TASK_PERIOD_MS,
mbed::callback(this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define FLAG_RX 1U
#define LINK_STATUS_THREAD_PRIORITY (osPriorityNormal)
#define LINK_STATUS_THREAD_STACKSIZE 512U
#define LINK_STATUS_TASK_PERIOD_MS 200U
#define LINK_STATUS_TASK_PERIOD_MS 200ms
#define PHY_STATE_LINK_DOWN false
#define PHY_STATE_LINK_UP true
#define CRC_LENGTH_BYTES 4U
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
* 1. BE for byte sequence in word
* 2. BE for word sequence in double-word
*/
TDES_Open(CRPT
TDES_Open(CRPT,
0, // Channel number (0~4)
enc, // 0: decode, 1: encode
(tdes_opmode & CRPT_TDES_CTL_TMODE_Msk) ? 1 : 0, // 0: DES, 1: TDES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp,
return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
}

/* NOTE: Engine doesn't support P + Q when P and Q are the same. Workaround by 2*P */
if (mbedtls_ecp_point_cmp(P, Q) == 0) {
return internal_run_eccop(grp, R, NULL, P, NULL, NULL, ECCOP_POINT_DOUBLE);
}

int ret;
bool ecc_done;

Expand Down
7 changes: 6 additions & 1 deletion connectivity/lwipstack/lwip/src/apps/lwiperf/lwip_lwiperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ lwiperf_tcp_close(lwiperf_state_tcp_t *conn, enum lwiperf_report_type report_typ
/* don't want to wait for free memory here... */
tcp_abort(conn->conn_pcb);
}
} else {
} else if (conn->server_pcb != NULL) {
/* no conn pcb, this is the listener pcb */
err = tcp_close(conn->server_pcb);
LWIP_ASSERT("error", err == ERR_OK);
Expand Down Expand Up @@ -565,6 +565,11 @@ lwiperf_tcp_err(void *arg, err_t err)
{
lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)arg;
LWIP_UNUSED_ARG(err);

/* pcb is already deallocated, prevent double-free */
conn->conn_pcb = NULL;
conn->server_pcb = NULL;

lwiperf_tcp_close(conn, LWIPERF_TCP_ABORTED_REMOTE);
}

Expand Down
2 changes: 2 additions & 0 deletions connectivity/mbedtls/source/ecp_curves.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id )
ECP_VALIDATE_RET( grp != NULL );
mbedtls_ecp_group_free( grp );

mbedtls_ecp_group_init( grp );

grp->id = id;

switch( id )
Expand Down
9 changes: 8 additions & 1 deletion drivers/include/drivers/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,15 @@ class PwmOut {

/** Read the PWM pulsewidth
* @returns
* The PWM pulsewith, specified in microseconds (int)
* The PWM pulsewidth, specified in microseconds (int)
*/
int read_pulsewidth_us();

/** Read the PWM pulsewidth
* @returns
* The PWM pulsewidth, specified in microseconds (int)
*/
MBED_DEPRECATED("use read_pulsewidth_us() instead")
int read_pulsewitdth_us();

/** Suspend PWM operation
Expand Down
7 changes: 6 additions & 1 deletion drivers/source/PwmOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@ void PwmOut::pulsewidth_us(int us)
core_util_critical_section_exit();
}

int PwmOut::read_pulsewitdth_us()
int PwmOut::read_pulsewidth_us()
{
core_util_critical_section_enter();
auto val = pwmout_read_pulsewidth_us(&_pwm);
core_util_critical_section_exit();
return val;
}

int PwmOut::read_pulsewitdth_us()
{
return read_pulsewidth_us();
}

void PwmOut::suspend()
{
core_util_critical_section_enter();
Expand Down
2 changes: 1 addition & 1 deletion hal/include/hal/pwmout_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void pwmout_pulsewidth_us(pwmout_t *obj, int us);
/** Read the PWM pulsewidth specified in microseconds
*
* @param obj The pwmout object
* @return A int output pulsewitdth
* @return A int output pulsewidth
*/
int pwmout_read_pulsewidth_us(pwmout_t *obj);

Expand Down
1 change: 1 addition & 0 deletions platform/tests/UNITTESTS/doubles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ target_sources(mbed-stubs-platform
nvic_wrapper_stub.c
randLIB_stub.c
randLIB_stub.cpp
../../../source/SingletonPtr.cpp
)
target_include_directories(mbed-stubs-platform
PUBLIC
Expand Down
1 change: 1 addition & 0 deletions storage/filesystem/fat/source/FATFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ int FATFileSystem::file_truncate(fs_file_t file, off_t length)
return fat_error_remap(res);
}

unlock();
return 0;
}

Expand Down
Loading

0 comments on commit d00ea7d

Please sign in to comment.