Merge pull request #8763 from cmonr/rollup-b.1

Rollup PR: Retest CI-troubled PRs target for 5.11 v2
pull/8767/head
Martin Kojtal 2018-11-16 09:15:56 +00:00 committed by GitHub
commit 8a2044b5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
393 changed files with 9937 additions and 7697 deletions

View File

@ -16,6 +16,7 @@ hal/storage_abstraction
TESTS/mbed_hal/trng/pithy
features/nanostack/coap-service
features/nanostack/sal-stack-nanostack
features/nanostack/targets
rtos/TARGET_CORTEX/rtx5
TESTS/mbed_hal/trng/pithy
targets

View File

@ -132,7 +132,9 @@ matrix:
- git diff --name-only $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-files-changed.out;
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
git --no-pager diff;
echo "Please fix style issues as shown above";
echo "";
echo "AStyle check failed, please fix style issues as shown above";
(exit 1);
else
echo "Coding style check OK";
fi
@ -155,7 +157,6 @@ matrix:
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") files)"
fi
- bash -c "$STATUS" success "$STATUSM"
- env:
- NAME=events
- EVENTS=events

View File

@ -183,7 +183,7 @@ void test_set_time_twice()
/* Set the time to NEW_TIME and check it */
set_time(NEW_TIME);
current_time = time(NULL);
TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME));
TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME));
/* Wait 2 seconds */
wait_ms(2000);
@ -191,7 +191,7 @@ void test_set_time_twice()
/* set the time to NEW_TIME again and check it */
set_time(NEW_TIME);
current_time = time(NULL);
TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME));
TEST_ASSERT_EQUAL(true, (current_time == NEW_TIME));
}
Case cases[] = {

View File

@ -215,6 +215,10 @@ void exp_cb()
TEST_F(Test_LoRaMac, set_device_class)
{
object->set_device_class(CLASS_B, exp_cb);
my_phy phy;
object->bind_phy(phy);
object->set_device_class(CLASS_C, exp_cb);
}
TEST_F(Test_LoRaMac, setup_link_check_request)

View File

@ -26,7 +26,8 @@ class stubInternetSocket : public InternetSocket {
protected:
nsapi_error_t return_value;
public:
stubInternetSocket() {
stubInternetSocket()
{
return_value = 0;
}
virtual nsapi_error_t connect(const SocketAddress &address)

View File

@ -26,7 +26,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
return NULL;
}
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),_power_ref_count(0), _sim_ref_count(0),
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
{
}
@ -41,11 +41,11 @@ events::EventQueue *CellularDevice::get_queue()
return NULL;
}
void CellularDevice::set_plmn(char const*)
void CellularDevice::set_plmn(char const *)
{
}
void CellularDevice::set_sim_pin(char const*)
void CellularDevice::set_sim_pin(char const *)
{
}

View File

@ -26,7 +26,8 @@ public:
std::list<nsapi_error_t> return_values;
nsapi_error_t return_value;
NetworkStackstub() {
NetworkStackstub()
{
return_value = 0;
}

View File

@ -182,7 +182,7 @@ int QSPIFBlockDevice::init()
}
// Soft Reset
if ( -1 == _reset_flash_mem()) {
if (-1 == _reset_flash_mem()) {
tr_error("Init - Unable to initialize flash memory, tests failed");
status = QSPIF_BD_ERROR_DEVICE_ERROR;
goto exit_point;
@ -211,21 +211,21 @@ int QSPIFBlockDevice::init()
}
//Synchronize Device
if ( false == _is_mem_ready()) {
if (false == _is_mem_ready()) {
tr_error("Init - _is_mem_ready Failed");
status = QSPIF_BD_ERROR_READY_FAILED;
goto exit_point;
}
/**************************** Parse SFDP Header ***********************************/
if ( 0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
if (0 != _sfdp_parse_sfdp_headers(basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
tr_error("Init - Parse SFDP Headers Failed");
status = QSPIF_BD_ERROR_PARSING_FAILED;
goto exit_point;
}
/**************************** Parse Basic Parameters Table ***********************************/
if ( 0 != _sfdp_parse_basic_param_table(basic_table_addr, basic_table_size) ) {
if (0 != _sfdp_parse_basic_param_table(basic_table_addr, basic_table_size)) {
tr_error("Init - Parse Basic Param Table Failed");
status = QSPIF_BD_ERROR_PARSING_FAILED;
goto exit_point;
@ -236,10 +236,10 @@ int QSPIFBlockDevice::init()
_device_size_bytes; // If there's no region map, we have a single region sized the entire device size
_region_high_boundary[0] = _device_size_bytes - 1;
if ( (sector_map_table_addr != 0) && (0 != sector_map_table_size) ) {
if ((sector_map_table_addr != 0) && (0 != sector_map_table_size)) {
tr_info("Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", sector_map_table_addr,
sector_map_table_size);
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size) ) {
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size)) {
tr_error("Init - Parse Sector Map Table Failed");
status = QSPIF_BD_ERROR_PARSING_FAILED;
goto exit_point;
@ -348,7 +348,7 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
}
result = _qspi_send_program_command(_prog_instruction, buffer, addr, &written_bytes);
if ( (result != QSPI_STATUS_OK) || (chunk != written_bytes) ) {
if ((result != QSPI_STATUS_OK) || (chunk != written_bytes)) {
tr_error("Write failed");
program_failed = true;
status = QSPIF_BD_ERROR_DEVICE_ERROR;
@ -359,7 +359,7 @@ int QSPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
addr += chunk;
size -= chunk;
if ( false == _is_mem_ready()) {
if (false == _is_mem_ready()) {
tr_error("Device not ready after write, failed");
program_failed = true;
status = QSPIF_BD_ERROR_READY_FAILED;
@ -397,7 +397,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
return QSPIF_BD_ERROR_INVALID_ERASE_PARAMS;
}
if ( ((addr % get_erase_size(addr)) != 0 ) || (((addr + in_size) % get_erase_size(addr + in_size - 1)) != 0 ) ) {
if (((addr % get_erase_size(addr)) != 0) || (((addr + in_size) % get_erase_size(addr + in_size - 1)) != 0)) {
tr_error("Invalid erase - unaligned address and size");
return QSPIF_BD_ERROR_INVALID_ERASE_PARAMS;
}
@ -409,7 +409,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
type = _utils_iterate_next_largest_erase_type(bitfield, size, (int)addr, _region_high_boundary[region]);
cur_erase_inst = _erase_type_inst_arr[type];
offset = addr % _erase_type_size_arr[type];
chunk = ( (offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
tr_debug("Erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu ",
addr, size, cur_erase_inst, chunk);
@ -425,7 +425,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
goto exit_point;
}
if (QSPI_STATUS_OK != _qspi_send_erase_command(cur_erase_inst, addr, size) ) {
if (QSPI_STATUS_OK != _qspi_send_erase_command(cur_erase_inst, addr, size)) {
tr_error("QSPI Erase command failed!");
erase_failed = true;
status = QSPIF_BD_ERROR_DEVICE_ERROR;
@ -435,13 +435,13 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
addr += chunk;
size -= chunk;
if ( (size > 0) && (addr > _region_high_boundary[region]) ) {
if ((size > 0) && (addr > _region_high_boundary[region])) {
// erase crossed to next region
region++;
bitfield = _region_erase_types_bitfield[region];
}
if ( false == _is_mem_ready()) {
if (false == _is_mem_ready()) {
tr_error("QSPI After Erase Device not ready - failed");
erase_failed = true;
status = QSPIF_BD_ERROR_READY_FAILED;
@ -525,7 +525,7 @@ int QSPIFBlockDevice::get_erase_value() const
static PinName *generate_initialized_active_qspif_csel_arr()
{
PinName *init_arr = new PinName[QSPIF_MAX_ACTIVE_FLASH_DEVICES];
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
init_arr[i_ind] = NC;
}
return init_arr;
@ -535,13 +535,13 @@ int QSPIFBlockDevice::add_new_csel_instance(PinName csel)
{
int status = 0;
_devices_mutex->lock();
if (_number_of_active_qspif_flash_csel >= QSPIF_MAX_ACTIVE_FLASH_DEVICES ) {
if (_number_of_active_qspif_flash_csel >= QSPIF_MAX_ACTIVE_FLASH_DEVICES) {
status = -2;
goto exit_point;
}
// verify the device is unique(no identical csel already exists)
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
status = -1;
goto exit_point;
@ -549,7 +549,7 @@ int QSPIFBlockDevice::add_new_csel_instance(PinName csel)
}
// Insert new csel into existing device list
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
if (_active_qspif_flash_csel_arr[i_ind] == NC) {
_active_qspif_flash_csel_arr[i_ind] = csel;
break;
@ -567,7 +567,7 @@ int QSPIFBlockDevice::remove_csel_instance(PinName csel)
int status = -1;
_devices_mutex->lock();
// remove the csel from existing device list
for ( int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++ ) {
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
_active_qspif_flash_csel_arr[i_ind] = NC;
if (_number_of_active_qspif_flash_csel > 0) {
@ -602,7 +602,7 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
}
// Currently we support only Single Map Descriptor
if (! ( (sector_map_table[0] & 0x3) == 0x03 ) && (sector_map_table[1] == 0x0) ) {
if (!((sector_map_table[0] & 0x3) == 0x03) && (sector_map_table[1] == 0x0)) {
tr_error("Sector Map - Supporting Only Single! Map Descriptor (not map commands)");
return -1;
}
@ -664,8 +664,8 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
uint32_t density_bits = (
(param_table[7] << 24) |
(param_table[6] << 16) |
(param_table[5] << 8 ) |
param_table[4] );
(param_table[5] << 8) |
param_table[4]);
_device_size_bytes = (density_bits + 1) / 8;
// Set Default read/program/erase Instructions
@ -704,8 +704,8 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
return 0;
}
int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_t& basic_table_size,
uint32_t& sector_map_table_addr, size_t& sector_map_table_size)
int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t &basic_table_size,
uint32_t &sector_map_table_addr, size_t &sector_map_table_size)
{
uint8_t sfdp_header[QSPIF_SFDP_HEADER_SIZE];
uint8_t param_header[QSPIF_PARAM_HEADER_SIZE];
@ -758,14 +758,14 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_
if ((param_header[0] == 0) && (param_header[7] == 0xFF)) {
// Found Basic Params Table: LSB=0x00, MSB=0xFF
tr_debug("Found Basic Param Table at Table: %d", i_ind + 1);
basic_table_addr = ( (param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]) );
basic_table_addr = ((param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]));
// Supporting up to 64 Bytes Table (16 DWORDS)
basic_table_size = ((param_header[3] * 4) < SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES) ? (param_header[3] * 4) : 64;
} else if ((param_header[0] == 81) && (param_header[7] == 0xFF)) {
// Found Sector Map Table: LSB=0x81, MSB=0xFF
tr_debug("Found Sector Map Table at Table: %d", i_ind + 1);
sector_map_table_addr = ( (param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]) );
sector_map_table_addr = ((param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]));
sector_map_table_size = param_header[3] * 4;
}
@ -780,8 +780,8 @@ int QSPIFBlockDevice::_sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr)
uint8_t config_reg[1];
// QPI 4-4-4 Enable Procedure is specified in 5 Bits
uint8_t en_seq_444_value = ( ((basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE] & 0xF0) >> 4) | ((
basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE + 1] & 0x01) << 4 ));
uint8_t en_seq_444_value = (((basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE] & 0xF0) >> 4) | ((
basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_444_MODE_EN_SEQ_BYTE + 1] & 0x01) << 4));
switch (en_seq_444_value) {
case 1:
@ -884,7 +884,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
// Read Status Register
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
status_reg,
sr_read_size) ) { // store received values in status_value
sr_read_size)) { // store received values in status_value
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
} else {
tr_error("Reading Status Register failed");
@ -904,7 +904,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, (char *)status_reg,
sr_write_size, NULL,
0) ) { // Write QE to status_register
0)) { // Write QE to status_register
tr_debug("_setQuadEnable - Writing Status Register Success: value = 0x%x",
(int)status_reg[0]);
} else {
@ -912,7 +912,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
return -1;
}
if ( false == _is_mem_ready()) {
if (false == _is_mem_ready()) {
tr_error("Device not ready after write, failed");
return -1;
}
@ -922,7 +922,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
(char *)status_reg,
sr_read_size) ) { // store received values in status_value
sr_read_size)) { // store received values in status_value
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
} else {
tr_error("Reading Status Register failed");
@ -938,7 +938,7 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
if (basic_param_table_size > QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE) {
// Page Size is specified by 4 Bits (N), calculated by 2^N
int page_to_power_size = ( (int)basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
int page_to_power_size = ((int)basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
page_size = local_math_power(2, page_to_power_size);
tr_debug("Detected Page Size: %d", page_size);
} else {
@ -948,7 +948,7 @@ int QSPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_ptr, int
}
int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
unsigned int& erase4k_inst,
unsigned int &erase4k_inst,
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr)
{
erase4k_inst = 0xff;
@ -970,7 +970,7 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
// if size==1 type is not supported
erase_type_inst_arr[i_ind] = basic_param_table_ptr[QSPIF_BASIC_PARAM_ERASE_TYPE_1_BYTE + 2 * i_ind];
if ((erase_type_size_arr[i_ind] < _min_common_erase_size) || (_min_common_erase_size == 0) ) {
if ((erase_type_size_arr[i_ind] < _min_common_erase_size) || (_min_common_erase_size == 0)) {
//Set default minimal common erase for singal region
_min_common_erase_size = erase_type_size_arr[i_ind];
}
@ -1001,8 +1001,8 @@ int QSPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_para
}
int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size,
bool& set_quad_enable,
bool& is_qpi_mode, unsigned int& read_inst)
bool &set_quad_enable,
bool &is_qpi_mode, unsigned int &read_inst)
{
set_quad_enable = false;
is_qpi_mode = false;
@ -1100,7 +1100,7 @@ int QSPIFBlockDevice::_reset_flash_mem()
tr_info("_reset_flash_mem:");
//Read the Status Register from device
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RDSR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, status_value,
QSPI_MAX_STATUS_REGISTER_SIZE) ) { // store received values in status_value
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_value[0]);
} else {
tr_error("Reading Status Register failed: value = 0x%x", (int)status_value[0]);
@ -1110,7 +1110,7 @@ int QSPIFBlockDevice::_reset_flash_mem()
if (0 == status) {
//Send Reset Enable
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RSTEN, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
0) ) { // store received values in status_value
0)) { // store received values in status_value
tr_debug("Sending RSTEN Success");
} else {
tr_error("Sending RSTEN failed");
@ -1151,7 +1151,7 @@ bool QSPIFBlockDevice::_is_mem_ready()
QSPI_MAX_STATUS_REGISTER_SIZE)) { // store received values in status_value
tr_error("Reading Status Register failed");
}
} while ( (status_value[0] & QSPIF_STATUS_BIT_WIP) != 0 && retries < IS_MEM_READY_MAX_RETRIES );
} while ((status_value[0] & QSPIF_STATUS_BIT_WIP) != 0 && retries < IS_MEM_READY_MAX_RETRIES);
if ((status_value[0] & QSPIF_STATUS_BIT_WIP) != 0) {
tr_error("_is_mem_ready FALSE: status value = 0x%x ", (int)status_value[0]);
@ -1172,7 +1172,7 @@ int QSPIFBlockDevice::_set_write_enable()
break;
}
if ( false == _is_mem_ready()) {
if (false == _is_mem_ready()) {
tr_error("Device not ready, write failed");
break;
}
@ -1208,7 +1208,7 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
// Read Status Register
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
&status_reg[1],
QSPI_MAX_STATUS_REGISTER_SIZE - 1) ) { // store received values in status_value
QSPI_MAX_STATUS_REGISTER_SIZE - 1)) { // store received values in status_value
tr_debug("Reading Config Register Success: value = 0x%x", (int)status_reg[2]);
} else {
tr_error("Reading Config Register failed");
@ -1228,7 +1228,7 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, status_reg,
QSPI_MAX_STATUS_REGISTER_SIZE, NULL,
0) ) { // Write Fast mode bit to status_register
0)) { // Write Fast mode bit to status_register
tr_debug("fast mode enable - Writing Config Register Success: value = 0x%x",
(int)status_reg[2]);
} else {
@ -1236,7 +1236,7 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
return -1;
}
if ( false == _is_mem_ready()) {
if (false == _is_mem_ready()) {
tr_error("Device not ready after write, failed");
return -1;
}
@ -1245,7 +1245,7 @@ int QSPIFBlockDevice::_enable_fast_mdoe()
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
&status_reg[1],
QSPI_MAX_STATUS_REGISTER_SIZE - 1) ) { // store received values in status_value
QSPI_MAX_STATUS_REGISTER_SIZE - 1)) { // store received values in status_value
tr_debug("Verifying Config Register Success: value = 0x%x", (int)status_reg[2]);
} else {
tr_error("Verifying Config Register failed");
@ -1279,7 +1279,7 @@ int QSPIFBlockDevice::_utils_find_addr_region(bd_size_t offset)
}
int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t& bitfield, int size, int offset, int boundry)
int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t &bitfield, int size, int offset, int boundry)
{
// Iterate on all supported Erase Types of the Region to which the offset belong to.
// Iterates from highest type to lowest
@ -1289,8 +1289,8 @@ int QSPIFBlockDevice::_utils_iterate_next_largest_erase_type(uint8_t& bitfield,
for (i_ind = 3; i_ind >= 0; i_ind--) {
if (bitfield & type_mask) {
largest_erase_type = i_ind;
if ( (size > (int)(_erase_type_size_arr[largest_erase_type])) &&
((boundry - offset) > (int)(_erase_type_size_arr[largest_erase_type])) ) {
if ((size > (int)(_erase_type_size_arr[largest_erase_type])) &&
((boundry - offset) > (int)(_erase_type_size_arr[largest_erase_type]))) {
break;
} else {
bitfield &= ~type_mask;
@ -1320,7 +1320,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(unsigned int read_inst,
// Send Read command to device driver
size_t buf_len = size;
if (_qspi.read(read_inst, -1, (unsigned int )addr, (char *)buffer, &buf_len) != QSPI_STATUS_OK ) {
if (_qspi.read(read_inst, -1, (unsigned int)addr, (char *)buffer, &buf_len) != QSPI_STATUS_OK) {
tr_error("Read failed");
return QSPI_STATUS_ERROR;
}

View File

@ -121,7 +121,10 @@ public:
/** Desctruct QSPIFBlockDevie
*/
~QSPIFBlockDevice() {deinit();}
~QSPIFBlockDevice()
{
deinit();
}
/** Read blocks from a block device
*
@ -266,8 +269,8 @@ private:
/* SFDP Detection and Parsing Functions */
/****************************************/
// Parse SFDP Headers and retrieve Basic Param and Sector Map Tables (if exist)
int _sfdp_parse_sfdp_headers(uint32_t& basic_table_addr, size_t& basic_table_size,
uint32_t& sector_map_table_addr, size_t& sector_map_table_size);
int _sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t &basic_table_size,
uint32_t &sector_map_table_addr, size_t &sector_map_table_size);
// Parse and Detect required Basic Parameters from Table
int _sfdp_parse_basic_param_table(uint32_t basic_table_addr, size_t basic_table_size);
@ -276,8 +279,8 @@ private:
int _sfdp_parse_sector_map_table(uint32_t sector_map_table_addr, size_t sector_map_table_size);
// Detect fastest read Bus mode supported by device
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, bool& set_quad_enable,
bool& is_qpi_mode, unsigned int& read_inst);
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, bool &set_quad_enable,
bool &is_qpi_mode, unsigned int &read_inst);
// Enable Quad mode if supported (1-1-4, 1-4-4, 4-4-4 bus modes)
int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
@ -290,7 +293,7 @@ private:
// Detect all supported erase types
int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr, int basic_param_table_size,
unsigned int& erase4k_inst,
unsigned int &erase4k_inst,
unsigned int *erase_type_inst_arr, unsigned int *erase_type_size_arr);
/***********************/
@ -301,7 +304,7 @@ private:
// Iterate on all supported Erase Types of the Region to which the offset belong to.
// Iterates from highest type to lowest
int _utils_iterate_next_largest_erase_type(uint8_t& bitfield, int size, int offset, int boundry);
int _utils_iterate_next_largest_erase_type(uint8_t &bitfield, int size, int offset, int boundry);
private:
// Internal Members

View File

@ -43,7 +43,7 @@ static SingletonPtr<PlatformMutex> _mutex;
// Mutex is protecting rand() per srand for buffer writing and verification.
// Mutex is also protecting printouts for clear logs.
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
void basic_erase_program_read_test(QSPIFBlockDevice& blockD, bd_size_t block_size, uint8_t *write_block,
void basic_erase_program_read_test(QSPIFBlockDevice &blockD, bd_size_t block_size, uint8_t *write_block,
uint8_t *read_block, unsigned addrwidth)
{
int err = 0;
@ -79,10 +79,10 @@ void basic_erase_program_read_test(QSPIFBlockDevice& blockD, bd_size_t block_siz
int val_rand;
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
val_rand = rand();
if ( (0xff & val_rand) != read_block[i_ind] ) {
if ((0xff & val_rand) != read_block[i_ind]) {
utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size);
utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand), read_block[i_ind],
write_block[i_ind] );
write_block[i_ind]);
}
TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]);
}
@ -208,7 +208,7 @@ static void test_qspif_thread_job(void *vBlockD/*, int thread_num*/)
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
if (!write_block || !read_block ) {
if (!write_block || !read_block) {
utest_printf("\n Not enough memory for test");
goto end;
}

View File

@ -100,7 +100,7 @@ int SPIFReducedBlockDevice::init()
uint32_t table_addr = (
(header[14] << 24) |
(header[13] << 16) |
(header[12] << 8 ));
(header[12] << 8));
uint8_t table[8];
_cmdread(SPIF_SFDP, 4, 8, table_addr, table);
@ -121,8 +121,8 @@ int SPIFReducedBlockDevice::init()
uint32_t density = (
(table[7] << 24) |
(table[6] << 16) |
(table[5] << 8 ) |
(table[4] << 0 ));
(table[5] << 8) |
(table[4] << 0));
// Table bytes 5-8 : Bits 0|30 indicate Flash Density (size) in bits (divide by 8 for Bytes)
_size = (density / 8) + 1;

View File

@ -114,7 +114,7 @@ public:
}
protected:
#if !defined(DOXYGEN_ONLY)
#if !defined(DOXYGEN_ONLY)
virtual void lock()
{
_mutex->lock();
@ -127,7 +127,7 @@ protected:
analogin_t _adc;
static SingletonPtr<PlatformMutex> _mutex;
#endif //!defined(DOXYGEN_ONLY)
#endif //!defined(DOXYGEN_ONLY)
};
} // namespace mbed

View File

@ -141,7 +141,7 @@ public:
}
protected:
#if !defined(DOXYGEN_ONLY)
#if !defined(DOXYGEN_ONLY)
virtual void lock()
{
_mutex.lock();
@ -154,7 +154,7 @@ protected:
dac_t _dac;
PlatformMutex _mutex;
#endif //!defined(DOXYGEN_ONLY)
#endif //!defined(DOXYGEN_ONLY)
};
} // namespace mbed

View File

@ -121,9 +121,9 @@ public:
}
protected:
#if !defined(DOXYGEN_ONLY)
#if !defined(DOXYGEN_ONLY)
gpio_t gpio;
#endif //!defined(DOXYGEN_ONLY)
#endif //!defined(DOXYGEN_ONLY)
};
} // namespace mbed

View File

@ -165,9 +165,9 @@ public:
}
protected:
#if !defined(DOXYGEN_ONLY)
#if !defined(DOXYGEN_ONLY)
gpio_t gpio;
#endif //!defined(DOXYGEN_ONLY)
#endif //!defined(DOXYGEN_ONLY)
};
} // namespace mbed

View File

@ -144,9 +144,9 @@ public:
}
protected:
#if !defined(DOXYGEN_ONLY)
#if !defined(DOXYGEN_ONLY)
gpio_t gpio;
#endif //!defined(DOXYGEN_ONLY)
#endif //!defined(DOXYGEN_ONLY)
};
} // namespace mbed

View File

@ -185,7 +185,7 @@ public:
#if defined(DOXYGEN_ONLY)
#if defined(DOXYGEN_ONLY)
/** Calls an event on the queue
*
* The specified callback will be executed in the context of the event
@ -266,8 +266,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...Args>
int call(T *obj, R (T::*method)(Args ...args), Args ...args);
// *INDENT-ON*
/** Calls an event on the queue after a specified delay
*
@ -346,8 +349,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...Args>
int call_in(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
// *INDENT-ON*
/** Calls an event on the queue periodically
*
@ -440,8 +446,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...Args>
int call_every(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
// *INDENT-ON*
/** Creates an event bound to the event queue
*
@ -483,8 +492,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename R, typename ...BoundArgs, typename ...Args>
Event<void(Args...)> event(R (*func)(BoundArgs...), Args ...args);
// *INDENT-ON*
/** Creates an event bound to the event queue
*
@ -528,8 +540,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
Event<void(Args...)> event(T *obj, R (T::*method)(BoundArgs..., Args...), ContextArgs ...context_args);
// *INDENT-ON*
/** Creates an event bound to the event queue
*
@ -569,7 +584,7 @@ public:
template <typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
Event<void(Args...)> event(mbed::Callback<R(BoundArgs..., Args...)> cb, ContextArgs ...context_args);
#else
#else
/** Calls an event on the queue
*
@ -2800,10 +2815,10 @@ public:
*/
template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
Event<void(A0, A1, A2, A3, A4)> event(mbed::Callback<R(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
#endif
#endif
protected:
#if !defined(DOXYGEN_ONLY)
#if !defined(DOXYGEN_ONLY)
template <typename F>
friend class Event;
struct equeue _equeue;
@ -3380,7 +3395,7 @@ protected:
f(c0, c1, c2, c3, c4, a0, a1, a2, a3, a4);
}
};
#endif //!defined(DOXYGEN_ONLY)
#endif //!defined(DOXYGEN_ONLY)
};
}

View File

@ -536,7 +536,7 @@ void AT_CellularContext::do_connect()
#if !NSAPI_PPP_AVAILABLE
// in PPP mode we did not activate any context, just searched the correct _cid
if (_status_cb) {
_status_cb((nsapi_event_t)CellularActivatePDPContext, (intptr_t )&_cb_data);
_status_cb((nsapi_event_t)CellularActivatePDPContext, (intptr_t)&_cb_data);
}
#endif // !NSAPI_PPP_AVAILABLE
}
@ -810,7 +810,7 @@ nsapi_error_t AT_CellularContext::get_pdpcontext_params(pdpContextList_t &params
void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
{
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
cell_callback_data_t* data = (cell_callback_data_t*)ptr;
cell_callback_data_t *data = (cell_callback_data_t *)ptr;
cellular_connection_status_t st = (cellular_connection_status_t)ev;
_cb_data.error = data->error;
tr_debug("AT_CellularContext::cellular_callback, network_callback called with event: %d, err: %d, data: %d", ev, data->error, data->status_data);

View File

@ -56,10 +56,10 @@ AT_CellularDevice::~AT_CellularDevice()
close_sim();
close_information();
AT_CellularContext* curr = _context_list;
AT_CellularContext* next;
AT_CellularContext *curr = _context_list;
AT_CellularContext *next;
while (curr) {
next = (AT_CellularContext*)curr->_next;
next = (AT_CellularContext *)curr->_next;
delete curr;
curr = next;
}
@ -134,17 +134,17 @@ CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *a
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
AT_CellularContext *ctx = create_context_impl(*atHandler, apn);
AT_CellularContext* curr = _context_list;
AT_CellularContext *curr = _context_list;
if (_context_list == NULL) {
_context_list = ctx;
return ctx;
}
AT_CellularContext* prev;
AT_CellularContext *prev;
while (curr) {
prev = curr;
curr = (AT_CellularContext*)curr->_next;
curr = (AT_CellularContext *)curr->_next;
}
prev->_next = ctx;
@ -160,20 +160,20 @@ AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const
void AT_CellularDevice::delete_context(CellularContext *context)
{
AT_CellularContext* curr = _context_list;
AT_CellularContext* prev = NULL;
AT_CellularContext *curr = _context_list;
AT_CellularContext *prev = NULL;
while (curr) {
if (curr == context) {
if (prev == NULL) {
_context_list = (AT_CellularContext*)curr->_next;
_context_list = (AT_CellularContext *)curr->_next;
} else {
prev->_next = curr->_next;
}
}
prev = curr;
curr = (AT_CellularContext*)curr->_next;
curr = (AT_CellularContext *)curr->_next;
}
delete (AT_CellularContext*)context;
delete (AT_CellularContext *)context;
}
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)

View File

@ -75,9 +75,9 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
{
bool success = false;
int active = 0;
char * config = NULL;
char *config = NULL;
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
char imsi[MAX_IMSI_LENGTH+1];
char imsi[MAX_IMSI_LENGTH + 1];
// do check for stack to validate that we have support for stack
_stack = get_stack();
@ -98,14 +98,14 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
if (_apn == NULL) {
err = get_imsi(imsi);
if (err == NSAPI_ERROR_OK) {
config = (char*)apnconfig(imsi);
config = (char *)apnconfig(imsi);
}
}
// Attempt to connect
do {
get_next_credentials(&config);
if(_uname && _pwd) {
if (_uname && _pwd) {
_auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
} else {
_auth = NSAPI_SECURITY_NONE;
@ -122,9 +122,9 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
return err;
}
bool UBLOX_AT_CellularContext::activate_profile(const char* apn,
const char* username,
const char* password)
bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
const char *username,
const char *password)
{
bool activated = false;
bool success = false;
@ -253,7 +253,7 @@ bool UBLOX_AT_CellularContext::disconnect_modem_stack()
return success;
}
nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char* imsi)
nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char *imsi)
{
_at.lock();
_at.cmd_start("AT+CIMI");
@ -269,7 +269,7 @@ nsapi_error_t UBLOX_AT_CellularContext::get_imsi(char* imsi)
}
// Get the next set of credentials, based on IMSI.
void UBLOX_AT_CellularContext::get_next_credentials(char ** config)
void UBLOX_AT_CellularContext::get_next_credentials(char **config)
{
if (*config) {
_apn = _APN_GET(*config);

View File

@ -59,7 +59,7 @@ private:
* NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
* @return True if successful, otherwise false.
*/
bool activate_profile(const char* apn, const char* username, const char* password);
bool activate_profile(const char *apn, const char *username, const char *password);
/** Convert nsapi_security_t to the modem security numbers.
*
@ -76,11 +76,11 @@ private:
/** Read IMSI of modem.
*/
nsapi_error_t get_imsi(char* imsi);
nsapi_error_t get_imsi(char *imsi);
/** Get the next set of credentials from the database.
*/
void get_next_credentials(char ** config);
void get_next_credentials(char **config);
};
} /* namespace mbed */

View File

@ -0,0 +1 @@
test/*

View File

@ -98,7 +98,7 @@ void randLIB_seed_random(void)
/* Spell out expressions so we get known ordering of 4 seed calls */
uint64_t s = (uint64_t) arm_random_seed_get() << 32;
state[0] ^= ( s | arm_random_seed_get());
state[0] ^= (s | arm_random_seed_get());
s = (uint64_t) arm_random_seed_get() << 32;
state[1] ^= s | arm_random_seed_get();
@ -129,19 +129,19 @@ void randLIB_add_seed(uint64_t seed)
uint8_t randLIB_get_8bit(void)
{
uint64_t r = randLIB_get_64bit();
return (uint8_t) (r >> 56);
return (uint8_t)(r >> 56);
}
uint16_t randLIB_get_16bit(void)
{
uint64_t r = randLIB_get_64bit();
return (uint16_t) (r >> 48);
return (uint16_t)(r >> 48);
}
uint32_t randLIB_get_32bit(void)
{
uint64_t r = randLIB_get_64bit();
return (uint32_t) (r >> 32);
return (uint32_t)(r >> 32);
}

View File

@ -11,6 +11,7 @@ INCLUDE_DIRS =\
../../../..\
../../../../source\
../../../../mbed-client-randlib\
../../../../../../../libService/libService\
/usr/include\
$(CPPUTEST_HOME)/include\

View File

@ -6,7 +6,7 @@
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
int main(int ac, char **av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

View File

@ -6,12 +6,10 @@
TEST_GROUP(randLIB)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};

View File

@ -18,9 +18,9 @@ bool test_randLIB_get_8bit()
randLIB_reset();
randLIB_seed_random();
uint8_t test = randLIB_get_8bit();
if( test == 0 ) {
if (test == 0) {
test = randLIB_get_8bit();
if( test == 0 ) {
if (test == 0) {
return false;
}
}
@ -32,9 +32,9 @@ bool test_randLIB_get_16bit()
randLIB_reset();
randLIB_seed_random();
uint16_t test = randLIB_get_16bit();
if( test == 0 ) {
if (test == 0) {
test = randLIB_get_16bit();
if( test == 0 ) {
if (test == 0) {
return false;
}
}
@ -46,9 +46,9 @@ bool test_randLIB_get_32bit()
randLIB_reset();
randLIB_seed_random();
uint32_t test = randLIB_get_32bit();
if( test == 0 ) {
if (test == 0) {
test = randLIB_get_32bit();
if( test == 0 ) {
if (test == 0) {
return false;
}
}
@ -145,7 +145,7 @@ bool test_randLIB_get_n_bytes_random()
uint8_t dat[5];
void *ret = randLIB_get_n_bytes_random(dat, 5);
if(ret != dat){
if (ret != dat) {
return false;
}
@ -164,12 +164,12 @@ bool test_randLIB_get_random_in_range()
randLIB_seed_random();
uint16_t ret = randLIB_get_random_in_range(2, 2);
if( ret != 2 ){
if (ret != 2) {
return false;
}
ret = randLIB_get_random_in_range(2, 3);
if( ret != 2 && ret != 3){
if (ret != 2 && ret != 3) {
return false;
}
@ -183,12 +183,12 @@ bool test_randLIB_randomise_base()
randLIB_reset();
randLIB_seed_random();
uint32_t ret = randLIB_randomise_base(0,0,0);
if( ret ){
uint32_t ret = randLIB_randomise_base(0, 0, 0);
if (ret) {
return false;
}
ret = randLIB_randomise_base(0xffff0000,0x8888,0x8888);
if( ret != 0xffffffff ){
ret = randLIB_randomise_base(0xffff0000, 0x8888, 0x8888);
if (ret != 0xffffffff) {
return false;
}
return true;

View File

@ -11,7 +11,7 @@ int __wrap_open(const char *path, int flags, ...)
if (allow_open) {
if (flags & O_CREAT) {
va_list vl;
va_start(vl,flags);
va_start(vl, flags);
mode_t mode = va_arg(vl, mode_t);
va_end(vl);
return __real_open(path, flags, mode);

View File

@ -1,7 +1,8 @@
/*
* Copyright (c) 2016, ARM Limited, All Rights Reserved
*/
#include "random_stub.h"
#include "ns_types.h"
static uint32_t seed_value = 4;
static bool seed_inc = false;

View File

@ -107,6 +107,43 @@ Set the output function, `printf` by default:
mbed_trace_print_function_set(printf)
```
### Tracing level
Run time tracing level is set using `mbed_trace_set_config()` function. Possible levels and examples how to set them is presented below.
```c
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); // (same as ALL)
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_CMD);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE);
```
Build time optimization can be done with `MBED_TRACE_MAX_LEVEL` definition. Setting max level to `TRACE_LEVEL_DEBUG` includes all traces to the build. Setting max level to `TRACE_LEVEL_INFO` includes all but `tr_debug()` traces to the build. Other maximum tracing levels follow the same behavior and no messages above the selected level are included in the build.
```c
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_WARN
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_ERROR
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_CMD
```
In Mbed OS, the build time maximum tracing level can be set through `mbed_app.json` as shown below.
```
{
"target_overrides":{
"*":{
"mbed-trace.enable": true,
"mbed-trace.max-level": "TRACE_LEVEL_INFO"
}
}
}
```
### Helping functions
The purpose of the helping functions is to provide simple conversions, for example from an array to C string, so that you can print everything to single trace line. They must be called inside the actual trace calls, for example:

View File

@ -180,11 +180,11 @@ extern "C" {
* Initialize trace functionality
* @return 0 when all success, otherwise non zero
*/
int mbed_trace_init( void );
int mbed_trace_init(void);
/**
* Free trace memory
*/
void mbed_trace_free( void );
void mbed_trace_free(void);
/**
* Resize buffers (line / tmp ) sizes
* @param lineLength new maximum length for trace line (0 = do no resize)
@ -226,7 +226,7 @@ uint8_t mbed_trace_config_get(void);
* char* trace_time(){ return "rtc-time-in-string"; }
* mbed_trace_prefix_function_set( &trace_time );
*/
void mbed_trace_prefix_function_set( char* (*pref_f)(size_t) );
void mbed_trace_prefix_function_set(char *(*pref_f)(size_t));
/**
* Set trace suffix function
* suffix -function return string with null terminated
@ -235,18 +235,18 @@ void mbed_trace_prefix_function_set( char* (*pref_f)(size_t) );
* char* trace_suffix(){ return " END"; }
* mbed_trace_suffix_function_set( &trace_suffix );
*/
void mbed_trace_suffix_function_set(char* (*suffix_f)(void) );
void mbed_trace_suffix_function_set(char *(*suffix_f)(void));
/**
* Set trace print function
* By default, trace module print using printf() function,
* but with this you can write own print function,
* for e.g. to other IO device.
*/
void mbed_trace_print_function_set( void (*print_f)(const char*) );
void mbed_trace_print_function_set(void (*print_f)(const char *));
/**
* Set trace print function for tr_cmdline()
*/
void mbed_trace_cmdprint_function_set( void (*printf)(const char*) );
void mbed_trace_cmdprint_function_set(void (*printf)(const char *));
/**
* Set trace mutex wait function
* By default, trace calls are not thread safe.
@ -270,10 +270,10 @@ void mbed_trace_mutex_release_function_set(void (*mutex_release_f)(void));
* mbed_trace_exclude_filters_set("mygr");
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed");
*/
void mbed_trace_exclude_filters_set(char* filters);
void mbed_trace_exclude_filters_set(char *filters);
/** get trace exclude filters
*/
const char* mbed_trace_exclude_filters_get(void);
const char *mbed_trace_exclude_filters_get(void);
/**
* When trace group contains text in filter,
* trace will be printed.
@ -282,10 +282,10 @@ const char* mbed_trace_exclude_filters_get(void);
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There");
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed");
*/
void mbed_trace_include_filters_set(char* filters);
void mbed_trace_include_filters_set(char *filters);
/** get trace include filters
*/
const char* mbed_trace_include_filters_get(void);
const char *mbed_trace_include_filters_get(void);
/**
* General trace function
* This should be used every time when user want to print out something important thing
@ -298,9 +298,9 @@ const char* mbed_trace_include_filters_get(void);
* @param ... variable arguments related to fmt
*/
#if defined(__GNUC__) || defined(__CC_ARM)
void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...) __attribute__ ((__format__(__printf__, 3, 4)));
void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) __attribute__((__format__(__printf__, 3, 4)));
#else
void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...);
void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...);
#endif
/**
* General trace function
@ -318,16 +318,16 @@ void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...);
* @param ap variable arguments list (like vprintf)
*/
#if defined(__GNUC__) || defined(__CC_ARM)
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap) __attribute__ ((__format__(__printf__, 3, 0)));
void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap) __attribute__((__format__(__printf__, 3, 0)));
#else
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap);
void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap);
#endif
/**
* Get last trace from buffer
*/
const char* mbed_trace_last(void);
const char *mbed_trace_last(void);
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
/**
* mbed_tracef helping function for convert ipv6
@ -339,7 +339,7 @@ const char* mbed_trace_last(void);
* @param add_ptr IPv6 Address pointer
* @return temporary buffer where ipv6 is in string format
*/
char* mbed_trace_ipv6(const void *addr_ptr);
char *mbed_trace_ipv6(const void *addr_ptr);
/**
* mbed_tracef helping function for print ipv6 prefix
* usage e.g.
@ -350,7 +350,7 @@ char* mbed_trace_ipv6(const void *addr_ptr);
* @param prefix_len prefix length
* @return temporary buffer where ipv6 is in string format
*/
char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
#endif
/**
* mbed_tracef helping function for convert hex-array to string.
@ -364,7 +364,7 @@ char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
* if array as string not fit to temp buffer, this function write '*' as last character,
* which indicate that buffer is too small for array.
*/
char* mbed_trace_array(const uint8_t* buf, uint16_t len);
char *mbed_trace_array(const uint8_t *buf, uint16_t len);
#ifdef __cplusplus
}

View File

@ -5,6 +5,12 @@
"help": "Used to globally enable traces.",
"value": null
},
"max-level": {
"help": "This flag is used to optimize the code size. For example, setting trace optimization level to TRACE_LEVEL_INFO will define all tr_debug() macros empty, which reduces the binary size. The possible optimization levels are TRACE_LEVEL_DEBUG, TRACE_LEVEL_INFO, TRACE_LEVEL_WARN, TRACE_LEVEL_ERROR and TRACE_LEVEL_CMD. To set the output tracing level, please use mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO). The possible tracing levels for mbed_trace_config_set() are TRACE_ACTIVE_LEVEL_ALL, TRACE_ACTIVE_LEVEL_DEBUG (same as ALL), TRACE_ACTIVE_LEVEL_INFO, TRACE_ACTIVE_LEVEL_WARN, TRACE_ACTIVE_LEVEL_ERROR, TRACE_ACTIVE_LEVEL_CMD and TRACE_LEVEL_NONE.",
"value": null,
"macro_name": "MBED_TRACE_MAX_LEVEL"
},
"fea-ipv6": {
"help": "Used to globally disable ipv6 tracing features.",
"value": null

View File

@ -93,7 +93,7 @@
#endif
/** default print function, just redirect str to printf */
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length);
static void mbed_trace_realloc(char **buffer, int *length_ptr, int new_length);
static void mbed_trace_default_print(const char *str);
static void mbed_trace_reset_tmp(void);
@ -209,7 +209,7 @@ void mbed_trace_free(void)
m_trace.mutex_release_f = 0;
m_trace.mutex_lock_count = 0;
}
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length)
static void mbed_trace_realloc(char **buffer, int *length_ptr, int new_length)
{
MBED_TRACE_MEM_FREE(*buffer);
*buffer = MBED_TRACE_MEM_ALLOC(new_length);
@ -217,11 +217,11 @@ static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length)
}
void mbed_trace_buffer_sizes(int lineLength, int tmpLength)
{
if( lineLength > 0 ) {
mbed_trace_realloc( &(m_trace.line), &m_trace.line_length, lineLength );
if (lineLength > 0) {
mbed_trace_realloc(&(m_trace.line), &m_trace.line_length, lineLength);
}
if( tmpLength > 0 ) {
mbed_trace_realloc( &(m_trace.tmp_data), &m_trace.tmp_data_length, tmpLength);
if (tmpLength > 0) {
mbed_trace_realloc(&(m_trace.tmp_data), &m_trace.tmp_data_length, tmpLength);
mbed_trace_reset_tmp();
}
}
@ -311,9 +311,9 @@ void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...)
mbed_vtracef(dlevel, grp, fmt, ap);
va_end(ap);
}
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap)
{
if ( m_trace.mutex_wait_f ) {
if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f();
m_trace.mutex_lock_count++;
}
@ -476,7 +476,7 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
}
end:
if ( m_trace.mutex_release_f ) {
if (m_trace.mutex_release_f) {
// Store the mutex lock count to temp variable so that it won't get
// clobbered during last loop iteration when mutex gets released
int count = m_trace.mutex_lock_count;
@ -507,7 +507,7 @@ const char *mbed_trace_last(void)
char *mbed_trace_ipv6(const void *addr_ptr)
{
/** Acquire mutex. It is released before returning from mbed_vtracef. */
if ( m_trace.mutex_wait_f ) {
if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f();
m_trace.mutex_lock_count++;
}
@ -528,7 +528,7 @@ char *mbed_trace_ipv6(const void *addr_ptr)
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
{
/** Acquire mutex. It is released before returning from mbed_vtracef. */
if ( m_trace.mutex_wait_f ) {
if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f();
m_trace.mutex_lock_count++;
}
@ -551,7 +551,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
char *mbed_trace_array(const uint8_t *buf, uint16_t len)
{
/** Acquire mutex. It is released before returning from mbed_vtracef. */
if ( m_trace.mutex_wait_f ) {
if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f();
m_trace.mutex_lock_count++;
}
@ -581,7 +581,7 @@ char *mbed_trace_array(const uint8_t *buf, uint16_t len)
wptr += retval;
}
if (wptr > str) {
if( overflow ) {
if (overflow) {
// replace last character as 'star',
// which indicate buffer len is not enough
*(wptr - 1) = '*';

View File

@ -39,26 +39,24 @@ void my_mutex_release()
char buf[1024];
#include <stdio.h>
void myprint(const char* str)
void myprint(const char *str)
{
if ( check_mutex_lock_status ) {
CHECK( (mutex_wait_count - mutex_release_count) > 0 );
if (check_mutex_lock_status) {
CHECK((mutex_wait_count - mutex_release_count) > 0);
}
strcpy(buf, str);
}
TEST_GROUP(trace)
{
void setup()
{
void setup() {
mbed_trace_init();
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_print_function_set( myprint );
mbed_trace_mutex_wait_function_set( my_mutex_wait );
mbed_trace_mutex_release_function_set( my_mutex_release );
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_print_function_set(myprint);
mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set(my_mutex_release);
}
void teardown()
{
void teardown() {
CHECK(mutex_wait_count == mutex_release_count); // Check the mutex count with every test
mbed_trace_free();
}
@ -67,8 +65,8 @@ TEST_GROUP(trace)
/* Unity test code starts */
TEST(trace, MutexNotSet)
{
mbed_trace_mutex_wait_function_set( 0 );
mbed_trace_mutex_release_function_set( 0 );
mbed_trace_mutex_wait_function_set(0);
mbed_trace_mutex_release_function_set(0);
int mutex_call_count_at_entry = mutex_wait_count;
check_mutex_lock_status = false;
@ -76,19 +74,21 @@ TEST(trace, MutexNotSet)
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "Hello hello!");
STRCMP_EQUAL(expectedStr, buf);
CHECK( mutex_call_count_at_entry == mutex_wait_count );
CHECK( mutex_call_count_at_entry == mutex_release_count );
CHECK(mutex_call_count_at_entry == mutex_wait_count);
CHECK(mutex_call_count_at_entry == mutex_release_count);
mbed_trace_mutex_wait_function_set( my_mutex_wait );
mbed_trace_mutex_release_function_set( my_mutex_release );
mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set(my_mutex_release);
check_mutex_lock_status = true;
}
TEST(trace, Array)
{
unsigned char longStr[200] = {0x66};
for(int i=0;i<200;i++) {longStr[i] = 0x66; }
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200) );
for (int i = 0; i < 200; i++) {
longStr[i] = 0x66;
}
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200));
}
TEST(trace, Null0Array)
@ -107,23 +107,29 @@ TEST(trace, Null0Array)
TEST(trace, LongString)
{
char longStr[1000] = {0x36};
for(int i=0;i<999;i++) {longStr[i] = 0x36; }
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr );
for (int i = 0; i < 999; i++) {
longStr[i] = 0x36;
}
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
}
TEST(trace, TooLong)
{
#define TOO_LONG_SIZE 9400
#define TRACE_LINE_SIZE 1024
#define TOO_LONG_SIZE 9400
#define TRACE_LINE_SIZE 1024
char longStr[TOO_LONG_SIZE] = {0};
for(int i=0;i<TOO_LONG_SIZE;i++) { longStr[i] = 0x36; }
for (int i = 0; i < TOO_LONG_SIZE; i++) {
longStr[i] = 0x36;
}
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr );
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
char shouldStr[TRACE_LINE_SIZE] = "[DBG ][mygr]: ";
for(int i=14;i<TRACE_LINE_SIZE;i++) { shouldStr[i] = 0x36; }
shouldStr[TRACE_LINE_SIZE-1] = 0;
for (int i = 14; i < TRACE_LINE_SIZE; i++) {
shouldStr[i] = 0x36;
}
shouldStr[TRACE_LINE_SIZE - 1] = 0;
STRCMP_EQUAL(shouldStr, buf);
}
@ -139,7 +145,7 @@ TEST(trace, BufferResize)
mbed_trace_buffer_sizes(0, 15);
STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4));
const char * expectedStr = "0123456789";
const char *expectedStr = "0123456789";
mbed_trace_buffer_sizes(11, 0);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
STRCMP_EQUAL(expectedStr, buf);
@ -159,16 +165,16 @@ TEST(trace, PreInitConfiguration)
memset(arr, '0', 20);
mbed_trace_free();
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_print_function_set( myprint );
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_print_function_set(myprint);
mbed_trace_buffer_sizes(11, 10);
mbed_trace_mutex_wait_function_set( my_mutex_wait );
mbed_trace_mutex_release_function_set( my_mutex_release );
mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set(my_mutex_release);
mbed_trace_init();
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
const char * expectedStr = "0123456789";
const char *expectedStr = "0123456789";
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
STRCMP_EQUAL(expectedStr, buf);
}
@ -218,7 +224,7 @@ TEST(trace, active_level_all_ipv6)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 };
uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 };
ip6tos_stub.output_string = "2001:db8::1:0:0:1";
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_ipv6(arr));
CHECK(memcmp(ip6tos_stub.input_array, arr, 16) == 0);
@ -228,17 +234,20 @@ TEST(trace, active_level_all_ipv6)
TEST(trace, config_change)
{
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
CHECK(mbed_trace_config_get() == TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_NONE);
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_NONE);
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
CHECK(mbed_trace_config_get() == TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_NONE);
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_NONE);
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
}
TEST(trace, active_level_all_color)
{
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
// unknown debug level
mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
STRCMP_EQUAL(" hep", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf);
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one");
@ -255,11 +264,11 @@ TEST(trace, change_levels)
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_MODE_PLAIN);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG | TRACE_MODE_PLAIN);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("hep", buf);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_MODE_COLOR);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG | TRACE_MODE_COLOR);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "hep");
STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: hep\x1b[0m", buf);
@ -269,6 +278,10 @@ TEST(trace, active_level_debug)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
// unknown debug level
mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
STRCMP_EQUAL(" hep", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
@ -353,7 +366,7 @@ TEST(trace, active_level_none)
TEST(trace, active_level_all_1)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_exclude_filters_set((char*)"mygr");
mbed_trace_exclude_filters_set((char *)"mygr");
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
STRCMP_EQUAL("[DBG ][mygu]: hep", buf);
@ -364,7 +377,7 @@ TEST(trace, active_level_all_1)
TEST(trace, active_level_all_2)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_exclude_filters_set((char*)"mygr,mygu");
mbed_trace_exclude_filters_set((char *)"mygr,mygu");
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
STRCMP_EQUAL("", mbed_trace_last());
@ -375,7 +388,7 @@ TEST(trace, active_level_all_2)
TEST(trace, active_level_all_3)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_include_filters_set((char*)"mygr");
mbed_trace_include_filters_set((char *)"mygr");
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
STRCMP_EQUAL("", mbed_trace_last());
@ -396,36 +409,37 @@ TEST(trace, active_level_all_array)
size_t time_length;
char trace_prefix_str[] = "[<TIME>]";
char* trace_prefix(size_t length){
char *trace_prefix(size_t length)
{
time_length = length;
return trace_prefix_str;
}
TEST(trace, prefix)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_prefix_function_set( &trace_prefix );
mbed_trace_prefix_function_set(&trace_prefix);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test %d %d", 1, 2);
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test 1 2", buf);
//TEST_ASSERT_EQUAL_INT(4, time_length);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_PLAIN);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_PLAIN);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
STRCMP_EQUAL("test", buf);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_COLOR);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_COLOR);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "test");
STRCMP_EQUAL("\x1b[31m[<TIME>][ERR ][mygr]: test\x1b[0m", buf);
}
char trace_suffix_str[] = "[END]";
char* trace_suffix()
char *trace_suffix()
{
return trace_suffix_str;
}
TEST(trace, suffix)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_prefix_function_set( &trace_prefix );
mbed_trace_suffix_function_set( &trace_suffix );
mbed_trace_prefix_function_set(&trace_prefix);
mbed_trace_suffix_function_set(&trace_suffix);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test[END]", buf);
}
@ -442,13 +456,13 @@ TEST(trace, formatting)
}
TEST(trace, filters_control)
{
mbed_trace_include_filters_set((char*)"hello");
mbed_trace_include_filters_set((char *)"hello");
STRCMP_EQUAL("hello", mbed_trace_include_filters_get());
mbed_trace_include_filters_set(0);
STRCMP_EQUAL("", mbed_trace_include_filters_get());
mbed_trace_exclude_filters_set((char*)"hello");
mbed_trace_exclude_filters_set((char *)"hello");
STRCMP_EQUAL("hello", mbed_trace_exclude_filters_get());
mbed_trace_exclude_filters_set(0);
@ -461,7 +475,7 @@ TEST(trace, cmd_printer)
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "default printer");
STRCMP_EQUAL("default printer", buf);
mbed_trace_cmdprint_function_set( myprint );
mbed_trace_cmdprint_function_set(myprint);
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "custom printer");
STRCMP_EQUAL("\n", buf); // because there is two print calls, second one add line feeds
}

View File

@ -186,31 +186,31 @@ NS_INLINE uint16_t common_read_16_bit_inverse(const uint8_t data_buf[__static 2]
/*
* Count bits in a byte
*
* \param byte byte to inspect
* \param value byte to inspect
*
* \return number of 1-bits in byte
*/
NS_INLINE uint_fast8_t common_count_bits(uint8_t byte);
NS_INLINE uint_fast8_t common_count_bits(uint8_t value);
/*
* Count leading zeros in a byte
*
* \deprecated Use common_count_leading_zeros_8
*
* \param byte byte to inspect
* \param value byte to inspect
*
* \return number of leading zeros in byte (0-8)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t byte);
NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t value);
/*
* Count leading zeros in a byte
*
* \param byte byte to inspect
* \param value byte to inspect
*
* \return number of leading zeros in byte (0-8)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t byte);
NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t value);
/*
* Count leading zeros in a 16-bit value
@ -490,11 +490,11 @@ COMMON_FUNCTIONS_FN uint16_t common_read_16_bit_inverse(const uint8_t data_buf[_
return temp_16;
}
COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte)
COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t value)
{
/* First step sets each bit pair to be count of bits (00,01,10) */
/* [00-00 = 00, 01-00 = 01, 10-01 = 01, 11-01 = 10] */
uint_fast8_t count = byte - ((byte >> 1) & 0x55);
uint_fast8_t count = value - ((value >> 1) & 0x55);
/* Add bit pairs to make each nibble contain count of bits (0-4) */
count = (count & 0x33) + ((count >> 2) & 0x33);
/* Final result is sum of nibbles (0-8) */
@ -502,31 +502,31 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte)
return count;
}
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte)
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t value)
{
return common_count_leading_zeros_8(byte);
return common_count_leading_zeros_8(value);
}
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t byte)
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t value)
{
#ifdef __CC_ARM
return byte ? __clz((unsigned int) byte << 24) : 8;
return value ? __clz((unsigned int) value << 24) : 8;
#elif defined __GNUC__
return byte ? __builtin_clz((unsigned int) byte << 24) : 8;
return value ? __builtin_clz((unsigned int) value << 24) : 8;
#else
uint_fast8_t cnt = 0;
if (byte == 0) {
if (value == 0) {
return 8;
}
if ((byte & 0xF0) == 0) {
byte <<= 4;
if ((value & 0xF0) == 0) {
value <<= 4;
cnt += 4;
}
if ((byte & 0xC0) == 0) {
byte <<= 2;
if ((value & 0xC0) == 0) {
value <<= 2;
cnt += 2;
}
if ((byte & 0x80) == 0) {
if ((value & 0x80) == 0) {
cnt += 1;
}

View File

@ -120,7 +120,7 @@ typedef int_fast32_t int_fast24_t;
#if defined __CC_ARM || defined __TASKING__
#define alignas(n) __align(n)
#define __alignas_is_defined 1
#elif (__STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L)
#elif (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L)
#include <stdalign.h>
#elif defined __GNUC__
#define alignas(n) __attribute__((__aligned__(n)))
@ -213,7 +213,7 @@ typedef int_fast32_t int_fast24_t;
# define NS_STATIC_ASSERT(test, str) _Static_assert(test, str);
# elif defined __GNUC__ && NS_GCC_VERSION >= 40600 && !defined __CC_ARM
# ifdef _Static_assert
/*
/*
* Some versions of glibc cdefs.h (which comes in via <stdint.h> above)
* attempt to define their own _Static_assert (if GCC < 4.6 or
* __STRICT_ANSI__) using an extern declaration, which doesn't work in a

View File

@ -59,7 +59,7 @@ static void ipv4_itoa(char *string, uint8_t byte)
do {
*string++ = '0' + byte % 10;
byte /= 10;
} while(byte);
} while (byte);
//We put the final \0, then go back one step on the last digit for the swap
*string-- = '\0';

View File

@ -74,8 +74,7 @@ bool stoip6(const char *ip6addr, size_t len, void *dest)
coloncolon = field_no;
q++;
len -= 2;
}
else {
} else {
len -= 1;
}
}
@ -150,11 +149,13 @@ int stoip6_prefix(const char *ip6addr, void *dest, int_fast16_t *prefix_len_out)
static bool is_hex(char c)
{
// 'A' (0x41) and 'a' (0x61) are mapped in the ASCII table in such a way that masking the 0x20 bit turn 'a' in 'A'
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F')
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F') {
return true;
}
if (c >= '0' && c <= '9')
if (c >= '0' && c <= '9') {
return true;
}
return false;
}

View File

@ -108,7 +108,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
h_size -= (sizeof(ns_mem_word_size_t) - temp_int);
}
book = heap;
book->heap_main = (ns_mem_word_size_t *)&(book[1]); // SET Heap Pointer
book->heap_main = (ns_mem_word_size_t *) & (book[1]); // SET Heap Pointer
book->heap_size = h_size - sizeof(ns_mem_book_t); //Set Heap Size
temp_int = (book->heap_size / sizeof(ns_mem_word_size_t));
temp_int -= 2;
@ -127,7 +127,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
memset(book->mem_stat_info_ptr, 0, sizeof(mem_stat_t));
book->mem_stat_info_ptr->heap_sector_size = book->heap_size;
}
book->temporary_alloc_heap_limit = book->heap_size/100 * (100-TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
book->temporary_alloc_heap_limit = book->heap_size / 100 * (100 - TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
#endif
//There really is no support to standard malloc in this library anymore
book->heap_failure_callback = passed_fptr;
@ -154,12 +154,12 @@ int ns_mem_set_temporary_alloc_free_heap_threshold(ns_mem_book_t *book, uint8_t
return -1;
}
if (free_heap_amount && free_heap_amount < book->heap_size/2) {
if (free_heap_amount && free_heap_amount < book->heap_size / 2) {
heap_limit = book->heap_size - free_heap_amount;
}
if (!free_heap_amount && free_heap_percentage && free_heap_percentage < 50) {
heap_limit = book->heap_size/100 * (100 - free_heap_percentage);
heap_limit = book->heap_size / 100 * (100 - free_heap_percentage);
}
if (free_heap_amount == 0 && free_heap_percentage == 0) {
@ -215,7 +215,7 @@ static ns_mem_word_size_t convert_allocation_size(ns_mem_book_t *book, ns_mem_bl
heap_failure(book, NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED);
} else if (requested_bytes < 1) {
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t)) ) {
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t))) {
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
}
return (requested_bytes + sizeof(ns_mem_word_size_t) - 1) / sizeof(ns_mem_word_size_t);
@ -295,7 +295,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
ns_mem_word_size_t hole_size = block_data_size - data_size - 2;
ns_mem_word_size_t *hole_ptr;
//There is enough room for a new hole so create it first
if ( direction > 0 ) {
if (direction > 0) {
hole_ptr = block_ptr + 1 + data_size + 1;
// Hole will be left at end of area.
// Would like to just replace this block_ptr with new descriptor, but
@ -324,7 +324,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
block_ptr[0] = data_size;
block_ptr[1 + data_size] = data_size;
done:
done:
if (book->mem_stat_info_ptr) {
if (block_ptr) {
//Update Allocate OK
@ -433,7 +433,7 @@ static void ns_mem_free_and_merge_with_adjacent_blocks(ns_mem_book_t *book, ns_m
} else {
// Didn't find adjacent descriptors, but may still
// be merging with small blocks without descriptors.
if ( merged_data_size >= HOLE_T_SIZE ) {
if (merged_data_size >= HOLE_T_SIZE) {
// Locate hole position in list, if we don't already know
// from merging with the block above.
if (!existing_end) {

View File

@ -60,7 +60,7 @@ static NS_LIST_DEFINE(ns_nvm_request_list, ns_nvm_request_t, link);
*/
void ns_nvm_callback_func(platform_nvm_status status, void *args)
{
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t*)args;
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t *)args;
int client_retval = NS_NVM_OK;
if (status == PLATFORM_NVM_ERROR) {
@ -69,7 +69,7 @@ void ns_nvm_callback_func(platform_nvm_status status, void *args)
client_retval = NS_NVM_DATA_NOT_FOUND;
}
switch(ns_nvm_request_ptr->operation) {
switch (ns_nvm_request_ptr->operation) {
case NS_NVM_INIT:
ns_nvm_operation_continue(ns_nvm_request_ptr->original_request, true);
ns_dyn_mem_free(ns_nvm_request_ptr);
@ -185,7 +185,7 @@ static int ns_nvm_operation_continue(ns_nvm_request_t *request, bool free_reques
platform_nvm_status ret = PLATFORM_NVM_OK;
ns_nvm_operation_in_progress = true;
switch(request->operation) {
switch (request->operation) {
case NS_NVM_KEY_WRITE:
request->operation = NS_NVM_KEY_CREATE;
ret = platform_nvm_key_create(ns_nvm_callback_func, request->client_key_name, *request->buffer_len, 0, request);

View File

@ -64,8 +64,7 @@ TEST(ip6tos, ip6_prefix_tos_func)
/***********************************************************/
/* Second test group for the old tests that were once lost */
const char string_addr[][40] =
{
const char string_addr[][40] = {
"2001:db8::1:0:0:1", // 1
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
"2001:db8::1", // 3
@ -81,20 +80,19 @@ const char string_addr[][40] =
};
const uint8_t hex_addr[][16] =
{
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 },
const uint8_t hex_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,0,0,0,0,0,0,1 },
{ 0x20, 0x01, 0xd,0xb8, 0,0,0,0,0,0,0,0, 0,2,0,1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0,0, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,1 },
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,0 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x20, 0x01, 0xd, 0xb8 },
{ 0,0,0,0,0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
};
char buf[40];
@ -102,13 +100,11 @@ int i = 0;
TEST_GROUP(ip6tos_2)
{
void setUp(void)
{
void setUp(void) {
memset(buf, 0, 40);
}
void tearDown(void)
{
void tearDown(void) {
i++;
}
};

View File

@ -32,12 +32,12 @@ TEST_GROUP(dynmem)
TEST(dynmem, init)
{
uint16_t size = 1000;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
mem_stat_t info;
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size-72));
CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed());
CHECK(ns_dyn_mem_get_mem_stat() == &info);
free(heap);
@ -46,11 +46,11 @@ TEST(dynmem, init)
TEST(dynmem, different_sizes)
{
reset_heap_error();
for (uint16_t size = 1000; size<32768; size++) {
for (uint16_t size = 1000; size < 32768; size++) {
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size-72));
CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed());
CHECK(ns_dyn_mem_alloc(10));
free(heap);
@ -61,14 +61,15 @@ TEST(dynmem, diff_alignment)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap;
CHECK(NULL != heap);
reset_heap_error();
for (int i=0; i<16; i++) {
ptr++; size--;
for (int i = 0; i < 16; i++) {
ptr++;
size--;
ns_dyn_mem_init(ptr, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size-72));
CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed());
}
free(heap);
@ -79,7 +80,7 @@ TEST(dynmem, ns_dyn_mem_alloc)
uint16_t size = 1000;
mem_stat_t info;
void *p[size];
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -87,17 +88,18 @@ TEST(dynmem, ns_dyn_mem_alloc)
int block = 1;
int i;
for (i=0; i<size; i++) {
for (i = 0; i < size; i++) {
p[i] = ns_dyn_mem_alloc(block);
if (!p[i])
if (!p[i]) {
break;
}
}
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1);
CHECK(info.heap_sector_alloc_cnt == i);
CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max);
for (; i>=0; i--) {
for (; i >= 0; i--) {
ns_dyn_mem_free(p[i]);
}
CHECK(!heap_have_failed());
@ -110,7 +112,7 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
uint16_t size = 1000;
mem_stat_t info;
void *p[size];
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -118,17 +120,18 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
int block = 1;
int i;
for (i=0; i<size; i++) {
for (i = 0; i < size; i++) {
p[i] = ns_dyn_mem_temporary_alloc(block);
if (!p[i])
if (!p[i]) {
break;
}
}
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1);
CHECK(info.heap_sector_alloc_cnt == i);
CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max);
for (; i>=0; i--) {
for (; i >= 0; i--) {
ns_dyn_mem_free(p[i]);
}
CHECK(!heap_have_failed());
@ -142,24 +145,24 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
mem_stat_t info;
void *p1, *p2;
int ret_val;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(!heap_have_failed());
// test1: temporary alloc will fail if there is less than 5% heap free
p1 = ns_dyn_mem_temporary_alloc((size-72)*0.96);
p1 = ns_dyn_mem_temporary_alloc((size - 72) * 0.96);
CHECK(!heap_have_failed());
CHECK(p1);
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.02);
p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.02);
CHECK(p2 == NULL);
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1);
// Test2, disable threshold feature and try p2 allocation again
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0);
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.02);
p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.02);
CHECK(!heap_have_failed());
CHECK(p2);
ns_dyn_mem_free(p1);
@ -169,10 +172,10 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
// Test3, enable feature by free heap percentage
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(40, 0);
p1 = ns_dyn_mem_temporary_alloc((size-72)*0.65);
p1 = ns_dyn_mem_temporary_alloc((size - 72) * 0.65);
CHECK(p1);
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.10);
CHECK(p2==NULL);
p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.10);
CHECK(p2 == NULL);
ns_dyn_mem_free(p1);
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 2);
@ -180,21 +183,21 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
// Test4, enable feature by free heap amount
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 200);
p1 = ns_dyn_mem_temporary_alloc(size-72-100 /*828 bytes */);
p1 = ns_dyn_mem_temporary_alloc(size - 72 - 100 /*828 bytes */);
CHECK(p1);
p2 = ns_dyn_mem_temporary_alloc(1);
CHECK(p2==NULL);
CHECK(p2 == NULL);
ns_dyn_mem_free(p1);
// Test5, illegal API parameters
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size/2);
CHECK(ret_val==-2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size*2);
CHECK(ret_val==-2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size / 2);
CHECK(ret_val == -2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size * 2);
CHECK(ret_val == -2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(51, 0);
CHECK(ret_val==-2);
CHECK(ret_val == -2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(255, 0);
CHECK(ret_val==-2);
CHECK(ret_val == -2);
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 3);
@ -202,20 +205,21 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
free(heap);
// Test6, feature is disabled if info is not set
heap = (uint8_t*)malloc(size);
heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0);
CHECK(ret_val==-1);
CHECK(ret_val == -1);
CHECK(!heap_have_failed());
free(heap);
}
TEST(dynmem, test_both_allocs_with_hole_usage) {
TEST(dynmem, test_both_allocs_with_hole_usage)
{
uint16_t size = 112;
mem_stat_t info;
void *p[size];
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -240,11 +244,12 @@ TEST(dynmem, test_both_allocs_with_hole_usage) {
free(heap);
}
TEST(dynmem, test_temp_alloc_with_skipping_hole) {
TEST(dynmem, test_temp_alloc_with_skipping_hole)
{
uint16_t size = 1000;
mem_stat_t info;
void *p[size];
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -268,7 +273,7 @@ TEST(dynmem, zero_allocate)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap;
CHECK(NULL != heap);
reset_heap_error();
@ -284,7 +289,7 @@ TEST(dynmem, too_big)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap;
CHECK(NULL != heap);
reset_heap_error();
@ -300,7 +305,7 @@ TEST(dynmem, corrupted_memory)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap;
CHECK(NULL != heap);
reset_heap_error();
@ -315,10 +320,11 @@ TEST(dynmem, corrupted_memory)
free(heap);
}
TEST(dynmem, no_big_enough_sector) {
TEST(dynmem, no_big_enough_sector)
{
uint16_t size = 112;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap;
CHECK(NULL != heap);
reset_heap_error();
@ -342,13 +348,13 @@ TEST(dynmem, diff_sizes)
uint16_t size = 1000;
mem_stat_t info;
void *p;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(!heap_have_failed());
int i;
for (i=1; i<(size-72); i++) {
for (i = 1; i < (size - 72); i++) {
p = ns_dyn_mem_temporary_alloc(i);
CHECK(p);
ns_dyn_mem_free(p);
@ -363,7 +369,7 @@ TEST(dynmem, double_free)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
void *p;
CHECK(NULL != heap);
reset_heap_error();
@ -383,13 +389,13 @@ TEST(dynmem, middle_free)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
void *p[3];
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(!heap_have_failed());
for (int i=0; i<3; i++) {
for (int i = 0; i < 3; i++) {
p[i] = ns_dyn_mem_temporary_alloc(100);
CHECK(p);
}
@ -406,7 +412,7 @@ TEST(dynmem, over_by_one)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
CHECK(NULL != heap);
reset_heap_error();
@ -425,7 +431,7 @@ TEST(dynmem, not_from_this_heap)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
CHECK(NULL != heap);
reset_heap_error();
@ -447,7 +453,7 @@ TEST(dynmem, free_on_empty_heap)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
CHECK(NULL != heap);
reset_heap_error();
@ -463,7 +469,7 @@ TEST(dynmem, not_negative_stats)
{
uint16_t size = 1000;
mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
void *p;
CHECK(NULL != heap);
reset_heap_error();
@ -479,7 +485,7 @@ TEST(dynmem, not_negative_stats)
CHECK(info.heap_sector_allocated_bytes >= 16);
CHECK(info.heap_sector_allocated_bytes < last_value);
last_value = info.heap_sector_allocated_bytes;
for (int i=0; i<10; i++) {
for (int i = 0; i < 10; i++) {
p = ns_dyn_mem_alloc(1);
ns_dyn_mem_free(p);
}
@ -487,9 +493,10 @@ TEST(dynmem, not_negative_stats)
free(heap);
}
TEST(dynmem, test_invalid_pointer_freed) {
TEST(dynmem, test_invalid_pointer_freed)
{
uint16_t size = 92;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL);
@ -503,9 +510,10 @@ TEST(dynmem, test_invalid_pointer_freed) {
free(heap);
}
TEST(dynmem, test_merge_corrupted_previous_block) {
TEST(dynmem, test_merge_corrupted_previous_block)
{
uint16_t size = 1000;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
CHECK(NULL != heap);
reset_heap_error();
@ -524,9 +532,10 @@ TEST(dynmem, test_merge_corrupted_previous_block) {
free(heap);
}
TEST(dynmem, test_free_corrupted_next_block) {
TEST(dynmem, test_free_corrupted_next_block)
{
uint16_t size = 1000;
uint8_t *heap = (uint8_t*)malloc(size);
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
CHECK(NULL != heap);
reset_heap_error();
@ -546,7 +555,8 @@ TEST(dynmem, test_free_corrupted_next_block) {
}
//NOTE! This test must be last!
TEST(dynmem, uninitialized_test){
TEST(dynmem, uninitialized_test)
{
void *p = ns_dyn_mem_alloc(4);
ns_dyn_mem_free(p);
CHECK(p == NULL);

View File

@ -19,15 +19,18 @@
heap_fail_t current_heap_error;
static bool failed;
void heap_fail_callback(heap_fail_t err) {
void heap_fail_callback(heap_fail_t err)
{
current_heap_error = err;
failed = true;
}
void reset_heap_error() {
void reset_heap_error()
{
failed = false;
}
bool heap_have_failed() {
bool heap_have_failed()
{
return failed;
}

View File

@ -106,8 +106,7 @@ TEST(stoip6, InvalidAddresses)
uint8_t ip[16];
uint8_t correct[16] = {0};
const char *invalidArray[] =
{
const char *invalidArray[] = {
"FFFF:FFFF::FFFF::FFFF", // Two ::
"F:F:F:FqF:F:F:F:F", // Non-hex character
"F:F:F:FFFFF:F:F:F:F" // >4 hex characters in a segment
@ -122,8 +121,7 @@ TEST(stoip6, InvalidAddresses)
/***********************************************************/
/* Second test group for the old tests that were once lost */
const char string_addr[][40] =
{
const char string_addr[][40] = {
"2001:db8::1:0:0:1", // 1
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
"2001:db8::1", // 3
@ -139,20 +137,19 @@ const char string_addr[][40] =
};
const uint8_t hex_addr[][16] =
{
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 },
const uint8_t hex_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,0,0,0,0,0,0,1 },
{ 0x20, 0x01, 0xd,0xb8, 0,0,0,0,0,0,0,0, 0,2,0,1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0,0, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,1 },
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,0 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x20, 0x01, 0xd, 0xb8 },
{ 0,0,0,0,0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
};
char buf[40];
@ -160,13 +157,11 @@ int i = 0;
TEST_GROUP(stoip6_2)
{
void setUp(void)
{
void setUp(void) {
memset(buf, 0, 40);
}
void tearDown(void)
{
void tearDown(void) {
i++;
}
};
@ -240,8 +235,7 @@ TEST(stoip6_2, test_2_12)
/***********************************************************/
/* Third test group for stoip6_prefix */
const char string_prefix_addr[][40] =
{
const char string_prefix_addr[][40] = {
"2001:db8::1:0:0:1/64", // 1
"2001::/60", // 2
"::1/48", // 3
@ -254,12 +248,11 @@ const char string_prefix_addr[][40] =
};
const uint8_t hex_prefix_addr[][16] =
{
const uint8_t hex_prefix_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, // 1
{ 0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 2
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }, // 3
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, // 4
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, // 3
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 4
{ 0x20, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, // 5
{ 0x20, 0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }, // 6
{ 0x20, 0x04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, // 7

View File

@ -28,8 +28,8 @@ struct ip6_addresses_and_its_binary_form_t {
{ "2001:db8::2:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 }},
{ "2001:db8:aaaa:bbbb:cccc:dddd:0:1", { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 }},
{ "2001:db8::aaaa:0:0:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }},
{ "2001:0:0:1::1", { 0x20, 0x01, 0, 0 , 0, 0 , 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }},
{ "2001:0:0:1::", { 0x20, 0x01, 0, 0 , 0, 0 , 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }},
{ "2001:0:0:1::1", { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }},
{ "2001:0:0:1::", { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }},
{ "2001:db8::", { 0x20, 0x01, 0xd, 0xb8 }},
{ "::aaaa:0:0:1", { 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }},
{ "::1", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }},

View File

@ -31,27 +31,21 @@ void ns_dyn_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(
void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
return(nsdynmemlib_stub.expectedPointer);
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
return(nsdynmemlib_stub.expectedPointer);
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}

View File

@ -24,7 +24,7 @@ extern "C" {
typedef struct {
uint8_t returnCounter;
void* expectedPointer;
void *expectedPointer;
} nsdynmemlib_stub_data_t;
extern nsdynmemlib_stub_data_t nsdynmemlib_stub;

View File

@ -294,6 +294,15 @@ void tearDown(void);
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, (message))
#define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, (message))
/*-------------------------------------------------------
* Error code checking
*-------------------------------------------------------*/
// Use these to check whether error code equals what we expect.
// Only display error code (without other information)
#define TEST_ASSERT_EQUAL_ERROR_CODE(expected, actual) TEST_ASSERT_EQUAL(MBED_GET_ERROR_CODE(expected), MBED_GET_ERROR_CODE(actual))
#define TEST_ASSERT_EQUAL_ERROR_CODE_MESSAGE(expected, actual, message) TEST_ASSERT_EQUAL_MESSAGE(MBED_GET_ERROR_CODE(expected), MBED_GET_ERROR_CODE(actual))
/*-------------------------------------------------------
* Test skipping
*-------------------------------------------------------*/

View File

@ -310,6 +310,7 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
if (_link_check_requested) {
_loramac.setup_link_check_request();
}
_qos_cnt = 1;
lorawan_status_t status;

View File

@ -80,7 +80,8 @@ LoRaMac::LoRaMac()
_can_cancel_tx(true),
_continuous_rx2_window_open(false),
_device_class(CLASS_A),
_prev_qos_level(LORAWAN_DEFAULT_QOS)
_prev_qos_level(LORAWAN_DEFAULT_QOS),
_demod_ongoing(false)
{
memset(&_params, 0, sizeof(_params));
_params.keys.dev_eui = NULL;
@ -99,7 +100,6 @@ LoRaMac::LoRaMac()
_params.rx_buffer_len = 0;
_params.ul_frame_counter = 0;
_params.dl_frame_counter = 0;
_params.is_ul_frame_counter_fixed = false;
_params.is_rx_window_enabled = true;
_params.adr_ack_counter = 0;
_params.is_node_ack_requested = false;
@ -166,23 +166,19 @@ void LoRaMac::post_process_mcps_req()
_params.is_node_ack_requested = false;
_mcps_confirmation.ack_received = false;
_mcps_indication.is_ack_recvd = false;
if (_params.is_ul_frame_counter_fixed == false) {
_params.ul_frame_counter++;
_params.adr_ack_counter++;
}
} else {
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
}
} else {
//UNCONFIRMED or PROPRIETARY
if (_params.is_ul_frame_counter_fixed == false) {
_params.ul_frame_counter++;
_params.adr_ack_counter++;
if (_params.sys_params.nb_trans > 1) {
_mcps_confirmation.nb_retries = _params.ul_nb_rep_counter;
}
}
}
}
void LoRaMac::post_process_mcps_ind()
@ -650,8 +646,8 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
if ((_mcps_confirmation.req_type == MCPS_UNCONFIRMED)
&& (_params.sys_params.nb_trans > 1)) {
//MBED_ASSERT(_params.ul_nb_rep_counter <= _params.sys_params.nb_trans);
_params.ul_nb_rep_counter++;
MBED_ASSERT(_params.ul_nb_rep_counter <= _params.sys_params.nb_trans);
}
if (_params.is_rx_window_enabled == true) {
@ -696,6 +692,7 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr)
{
_demod_ongoing = false;
if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
_lora_time.stop(_rx2_closure_timer_for_class_c);
open_rx2_window();
@ -765,6 +762,7 @@ void LoRaMac::on_radio_tx_timeout(void)
void LoRaMac::on_radio_rx_timeout(bool is_timeout)
{
_demod_ongoing = false;
if (_device_class == CLASS_A) {
_lora_phy->put_radio_to_sleep();
}
@ -887,6 +885,7 @@ void LoRaMac::on_backoff_timer_expiry(void)
void LoRaMac::open_rx1_window(void)
{
Lock lock(*this);
_demod_ongoing = true;
_continuous_rx2_window_open = false;
_lora_time.stop(_params.timers.rx_window1_timer);
_params.rx_slot = RX_SLOT_WIN_1;
@ -912,6 +911,10 @@ void LoRaMac::open_rx1_window(void)
void LoRaMac::open_rx2_window()
{
if (_demod_ongoing) {
tr_info("RX1 Demodulation ongoing, skip RX2 window opening");
return;
}
Lock lock(*this);
_continuous_rx2_window_open = true;
_lora_time.stop(_params.timers.rx_window2_timer);
@ -1243,6 +1246,8 @@ void LoRaMac::reset_mac_parameters(void)
}
_params.channel = 0;
_params.last_channel_idx = _params.channel;
_demod_ongoing = false;
}
uint8_t LoRaMac::get_default_tx_datarate()

View File

@ -696,6 +696,8 @@ private:
device_class_t _device_class;
uint8_t _prev_qos_level;
bool _demod_ongoing;
};
#endif // MBED_LORAWAN_MAC_H__

View File

@ -1127,12 +1127,6 @@ typedef struct {
*/
bool is_repeater_supported;
/*!
* IsPacketCounterFixed enables the MIC field tests by fixing the
* ul_frame_counter value
*/
bool is_ul_frame_counter_fixed;
/*!
* Used for test purposes. Disables the opening of the reception windows.
*/

View File

@ -105,7 +105,7 @@ typedef int coap_service_request_recv_cb(int8_t service_id, uint8_t source_addre
*
* \return 0 for success / -1 for failure
*/
typedef int coap_service_security_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len);
typedef int coap_service_security_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw, uint8_t *pw_len);
/**
* \brief CoAP service security done callback
@ -142,7 +142,7 @@ extern int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port,
*
* \param service_id Id number of the current service.
*/
extern void coap_service_delete( int8_t service_id );
extern void coap_service_delete(int8_t service_id);
/**
* \brief Close secure connection
@ -261,7 +261,7 @@ extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, co
* \return -1 For failure
*- 0 For success
*/
extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len);
extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
/**
* \brief Sends CoAP service response
@ -280,9 +280,7 @@ extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_
* \return -1 For failure
*- 0 For success
*/
extern int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len);
extern int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
/**
* \brief Delete CoAP request transaction
@ -297,6 +295,15 @@ extern int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t op
*/
extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);
/**
* \brief Delete CoAP requests from service id
*
* Removes pending CoAP requests from service specified by service_id.
*
* \param service_id Id number of the current service.
*/
extern void coap_service_request_delete_by_service_id(int8_t service_id);
/**
* \brief Set DTLS handshake timeout values
*

View File

@ -32,7 +32,7 @@ typedef enum session_state_e {
SECURE_SESSION_HANDSHAKE_ONGOING = 0,
SECURE_SESSION_OK,
SECURE_SESSION_CLOSED
}session_state_t;
} session_state_t;
typedef struct internal_socket_s {
coap_conn_handler_t *parent;
@ -64,7 +64,7 @@ static NS_LIST_DEFINE(socket_list, internal_socket_t, link);
static uint8_t max_handshakes = MAX_ONGOING_HANDSHAKES;
static uint8_t max_sessions = MAX_SECURE_SESSION_COUNT;
static void timer_cb(void* param);
static void timer_cb(void *param);
static void recv_sckt_msg(void *cb_res);
#ifdef COAP_SECURITY_AVAILABLE
@ -132,11 +132,11 @@ static void secure_session_delete(secure_session_t *this)
if (this) {
ns_list_remove(&secure_session_list, this);
transactions_delete_all(this->remote_host.address, this->remote_host.identifier);
if( this->sec_handler ){
if (this->sec_handler) {
coap_security_destroy(this->sec_handler);
this->sec_handler = NULL;
}
if(this->timer.timer){
if (this->timer.timer) {
eventOS_timeout_cancel(this->timer.timer);
}
ns_dyn_mem_free(this);
@ -160,21 +160,21 @@ static int8_t virtual_socket_id_allocate()
static secure_session_t *secure_session_create(internal_socket_t *parent, const uint8_t *address_ptr, uint16_t port, SecureConnectionMode secure_mode)
{
uint8_t handshakes = 0;
if(!address_ptr){
if (!address_ptr) {
return NULL;
}
if(max_sessions <= ns_list_count(&secure_session_list)){
if (max_sessions <= ns_list_count(&secure_session_list)) {
// Seek & destroy oldest session where close notify have been sent
secure_session_t *to_be_removed = NULL;
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if(cur_ptr->session_state == SECURE_SESSION_CLOSED){
if(!to_be_removed || cur_ptr->last_contact_time < to_be_removed->last_contact_time){
if (cur_ptr->session_state == SECURE_SESSION_CLOSED) {
if (!to_be_removed || cur_ptr->last_contact_time < to_be_removed->last_contact_time) {
to_be_removed = cur_ptr;
}
}
}
if(!to_be_removed){
if (!to_be_removed) {
tr_err("max session count exceeded");
return NULL;
}
@ -184,11 +184,11 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
// Count for ongoing handshakes
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if(cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING){
if (cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) {
handshakes++;
}
}
if(handshakes >= max_handshakes) {
if (handshakes >= max_handshakes) {
tr_err("ongoing handshakes exceeded");
return NULL;
}
@ -201,8 +201,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
uint8_t timer_id = 1;
while(secure_session_find_by_timer_id(timer_id)){
if(timer_id == 0xff){
while (secure_session_find_by_timer_id(timer_id)) {
if (timer_id == 0xff) {
ns_dyn_mem_free(this);
return NULL;
}
@ -216,7 +216,7 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
this->sec_handler = coap_security_create(parent->socket, this->timer.id, this, secure_mode,
&secure_session_sendto, &secure_session_recvfrom, &start_timer, &timer_status);
if( !this->sec_handler ){
if (!this->sec_handler) {
tr_err("security create failed");
ns_dyn_mem_free(this);
return NULL;
@ -230,11 +230,12 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
}
static void clear_secure_sessions(internal_socket_t *this){
if( this ){
static void clear_secure_sessions(internal_socket_t *this)
{
if (this) {
ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) {
if( cur_ptr->parent == this ){
coap_security_send_close_alert( cur_ptr->sec_handler );
if (cur_ptr->parent == this) {
coap_security_send_close_alert(cur_ptr->sec_handler);
secure_session_delete(cur_ptr);
}
}
@ -245,7 +246,7 @@ static secure_session_t *secure_session_find(internal_socket_t *parent, const ui
{
secure_session_t *this = NULL;
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if( cur_ptr->sec_handler ){
if (cur_ptr->sec_handler) {
if (cur_ptr->parent == parent && cur_ptr->remote_host.identifier == port &&
memcmp(cur_ptr->remote_host.address, address_ptr, 16) == 0) {
this = cur_ptr;
@ -297,13 +298,13 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem
this->real_socket = real_socket;
this->bypass_link_sec = bypassSec;
this->socket = -1;
if( real_socket ){
if( use_ephemeral_port ){ //socket_api creates ephemeral port if the one provided is 0
if (real_socket) {
if (use_ephemeral_port) { //socket_api creates ephemeral port if the one provided is 0
listen_port = 0;
}
if( !is_secure ){
if (!is_secure) {
this->socket = socket_open(SOCKET_UDP, listen_port, recv_sckt_msg);
}else{
} else {
#ifdef COAP_SECURITY_AVAILABLE
this->socket = socket_open(SOCKET_UDP, listen_port, secure_recv_sckt_msg);
#else
@ -311,18 +312,24 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem
#endif
}
// Socket create failed
if(this->socket < 0){
if (this->socket < 0) {
ns_dyn_mem_free(this);
return NULL;
}
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_LINK_LAYER_SECURITY, &(const int8_t) {bypassSec ? 0 : 1}, sizeof(int8_t));
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_LINK_LAYER_SECURITY, &(const int8_t) {
bypassSec ? 0 : 1
}, sizeof(int8_t));
// XXX API for this? May want to get clever to do recommended first query = 1 hop, retries = whole PAN
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_MULTICAST_HOPS, &(const int16_t) {16}, sizeof(int16_t));
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_MULTICAST_HOPS, &(const int16_t) {
16
}, sizeof(int16_t));
// Set socket option to receive packet info
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_RECVPKTINFO, &(const bool) {1}, sizeof(bool));
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_RECVPKTINFO, &(const bool) {
1
}, sizeof(bool));
if (socket_interface_selection > 0) {
// Interface selection requested as socket_interface_selection set
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_INTERFACE_SELECT, &socket_interface_selection, sizeof(socket_interface_selection));
@ -343,15 +350,15 @@ static void int_socket_delete(internal_socket_t *this)
{
if (this) {
this->usage_counter--;
if(this->usage_counter == 0){
if (this->usage_counter == 0) {
clear_secure_sessions(this);
socket_close(this->socket);
ns_list_remove(&socket_list, this);
if( this->data ){
if (this->data) {
ns_dyn_mem_free(this->data);
this->data = NULL;
}
if(this->parent){
if (this->parent) {
ns_dyn_mem_free(this->parent);
}
ns_dyn_mem_free(this);
@ -363,7 +370,7 @@ static internal_socket_t *int_socket_find_by_socket_id(int8_t id)
{
internal_socket_t *this = NULL;
ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) {
if( cur_ptr->socket == id ) {
if (cur_ptr->socket == id) {
this = cur_ptr;
break;
}
@ -377,7 +384,7 @@ static internal_socket_t *int_socket_find(uint16_t port, bool is_secure, bool is
internal_socket_t *this = NULL;
ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) {
if( cur_ptr->listen_port == port && cur_ptr->real_socket == is_real_socket &&
if (cur_ptr->listen_port == port && cur_ptr->real_socket == is_real_socket &&
is_secure == cur_ptr->is_secure /*&& bypass_link_sec == bypassSec*/) {
this = cur_ptr;
break;
@ -412,7 +419,7 @@ static int send_to_real_socket(int8_t socket_id, const ns_address_t *address, co
cmsg->cmsg_level = SOCKET_IPPROTO_IPV6;
cmsg->cmsg_len = NS_CMSG_LEN(sizeof(ns_in6_pktinfo_t));
pktinfo = (ns_in6_pktinfo_t*)NS_CMSG_DATA(cmsg);
pktinfo = (ns_in6_pktinfo_t *)NS_CMSG_DATA(cmsg);
pktinfo->ipi6_ifindex = 0;
memcpy(pktinfo->ipi6_addr, source_address, 16);
}
@ -424,14 +431,15 @@ static int secure_session_sendto(int8_t socket_id, void *handle, const void *buf
{
secure_session_t *session = handle;
internal_socket_t *sock = int_socket_find_by_socket_id(socket_id);
if(!sock){
if (!sock) {
return -1;
}
if(!sock->real_socket){
if (!sock->real_socket) {
// Send to virtual socket cb
int ret = sock->parent->_send_cb(sock->socket, session->remote_host.address, session->remote_host.identifier, buf, len);
if( ret < 0 )
if (ret < 0) {
return ret;
}
return len;
}
@ -457,7 +465,7 @@ static int secure_session_recvfrom(int8_t socket_id, unsigned char *buf, size_t
(void)len;
internal_socket_t *sock = int_socket_find_by_socket_id(socket_id);
if (sock->data && sock->data_len > 0) {
memcpy( buf, sock->data, sock->data_len );
memcpy(buf, sock->data, sock->data_len);
int l = sock->data_len;
ns_dyn_mem_free(sock->data);
sock->data = NULL;
@ -477,21 +485,19 @@ static void timer_cb(void *param)
{
secure_session_t *sec = param;
if( sec && is_secure_session_valid(sec)){
if(sec->timer.fin_ms > sec->timer.int_ms){
if (sec && is_secure_session_valid(sec)) {
if (sec->timer.fin_ms > sec->timer.int_ms) {
/* Intermediate expiry */
sec->timer.fin_ms -= sec->timer.int_ms;
sec->timer.state = TIMER_STATE_INT_EXPIRY;
int error = coap_security_handler_continue_connecting(sec->sec_handler);
if(MBEDTLS_ERR_SSL_TIMEOUT == error) {
if (MBEDTLS_ERR_SSL_TIMEOUT == error) {
//TODO: How do we handle timeouts?
secure_session_delete(sec);
} else {
sec->timer.timer = eventOS_timeout_ms(timer_cb, sec->timer.int_ms, (void *)sec);
}
else{
sec->timer.timer = eventOS_timeout_ms(timer_cb, sec->timer.int_ms, (void*)sec);
}
}
else{
} else {
/* We have counted the number of cycles - finish */
eventOS_timeout_cancel(sec->timer.timer);
sec->timer.fin_ms = 0;
@ -499,7 +505,7 @@ static void timer_cb(void *param)
sec->timer.timer = NULL;
sec->timer.state = TIMER_STATE_FIN_EXPIRY;
int error = coap_security_handler_continue_connecting(sec->sec_handler);
if(MBEDTLS_ERR_SSL_TIMEOUT == error) {
if (MBEDTLS_ERR_SSL_TIMEOUT == error) {
//TODO: How do we handle timeouts?
secure_session_delete(sec);
}
@ -510,12 +516,12 @@ static void timer_cb(void *param)
static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms)
{
secure_session_t *sec = secure_session_find_by_timer_id(timer_id);
if( sec ){
if (sec) {
if ((int_ms > 0) && (fin_ms > 0)) {
sec->timer.int_ms = int_ms;
sec->timer.fin_ms = fin_ms;
sec->timer.state = TIMER_STATE_NO_EXPIRY;
if(sec->timer.timer){
if (sec->timer.timer) {
eventOS_timeout_cancel(sec->timer.timer);
}
sec->timer.timer = eventOS_timeout_ms(timer_cb, int_ms, sec);
@ -533,7 +539,7 @@ static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms)
static int timer_status(int8_t timer_id)
{
secure_session_t *sec = secure_session_find_by_timer_id(timer_id);
if( sec ){
if (sec) {
return (int)sec->timer.state;
}
return TIMER_STATE_CANCELLED;
@ -577,7 +583,7 @@ static int read_data(socket_callback_t *sckt_data, internal_socket_t *sock, ns_a
while (cmsg) {
switch (cmsg->cmsg_type) {
case SOCKET_IPV6_PKTINFO:
pkt = (ns_in6_pktinfo_t*)NS_CMSG_DATA(cmsg);
pkt = (ns_in6_pktinfo_t *)NS_CMSG_DATA(cmsg);
break;
default:
break;
@ -649,7 +655,7 @@ static void secure_recv_sckt_msg(void *cb_res)
session->last_contact_time = coap_service_get_internal_timer_ticks();
// Start handshake
if (!coap_security_handler_is_started(session->sec_handler)) {
if(-1 == coap_security_handler_connect_non_blocking(session->sec_handler, true, DTLS, keys, sock->timeout_min, sock->timeout_max)) {
if (-1 == coap_security_handler_connect_non_blocking(session->sec_handler, true, DTLS, keys, sock->timeout_min, sock->timeout_max)) {
tr_err("Connection start failed");
secure_session_delete(session);
}
@ -664,12 +670,12 @@ static void secure_recv_sckt_msg(void *cb_res)
eventOS_timeout_cancel(session->timer.timer);
session->timer.timer = NULL;
session->session_state = SECURE_SESSION_OK;
if( sock->parent->_security_done_cb ){
if (sock->parent->_security_done_cb) {
sock->parent->_security_done_cb(sock->socket, src_address.address,
src_address.identifier,
(void *)coap_security_handler_keyblock(session->sec_handler));
}
} else if (ret < 0){
} else if (ret < 0) {
// error handling
// TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed.
secure_session_delete(session);
@ -679,7 +685,7 @@ static void secure_recv_sckt_msg(void *cb_res)
unsigned char *data = ns_dyn_mem_temporary_alloc(sock->data_len);
int len = 0;
len = coap_security_handler_read(session->sec_handler, data, sock->data_len);
if( len < 0 ){
if (len < 0) {
if (len != MBEDTLS_ERR_SSL_WANT_READ && len != MBEDTLS_ERR_SSL_WANT_WRITE &&
len != MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) {
secure_session_delete(session);
@ -715,7 +721,7 @@ static void recv_sckt_msg(void *cb_res)
int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len)
{
if(!handler || !handler->socket) {
if (!handler || !handler->socket) {
return -1;
}
internal_socket_t *sock = handler->socket;
@ -768,16 +774,15 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
if (coap_security_handler_is_started(session->sec_handler)) {
if (session->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) {
int ret = coap_security_handler_continue_connecting(session->sec_handler);
if(ret == 0){
if (ret == 0) {
session->session_state = SECURE_SESSION_OK;
if( handler->_security_done_cb ){
if (handler->_security_done_cb) {
handler->_security_done_cb(sock->socket,
address, port,
(void *)coap_security_handler_keyblock(session->sec_handler));
}
return 0;
}
else if (ret < 0) {
} else if (ret < 0) {
// error handling
// TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed.
secure_session_delete(session);
@ -821,14 +826,14 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
send_to_socket_cb *send_to_cb,
get_pw_cb *pw_cb,
security_done_cb *done_cb )
security_done_cb *done_cb)
{
if(recv_from_cb == NULL) {
if (recv_from_cb == NULL) {
return NULL;
}
coap_conn_handler_t *handler = ns_dyn_mem_alloc(sizeof(coap_conn_handler_t));
if(!handler){
if (!handler) {
return NULL;
}
memset(handler, 0, sizeof(coap_conn_handler_t));
@ -844,7 +849,7 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave)
{
if(handler){
if (handler) {
if (multicast_group_leave) {
coap_multicast_group_join_or_leave(handler->socket->socket, SOCKET_IPV6_LEAVE_GROUP, handler->socket_interface_selection);
}
@ -856,13 +861,13 @@ void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_gro
}
}
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port )
void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port)
{
if (handler) {
if (handler->socket && handler->socket->is_secure) {
secure_session_t *session = secure_session_find( handler->socket, destination_addr_ptr, port );
secure_session_t *session = secure_session_find(handler->socket, destination_addr_ptr, port);
if (session) {
coap_security_send_close_alert( session->sec_handler );
coap_security_send_close_alert(session->sec_handler);
session->session_state = SECURE_SESSION_CLOSED;
session->last_contact_time = coap_service_get_internal_timer_ticks();
}
@ -883,7 +888,7 @@ int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16
int_socket_delete(handler->socket);
}
internal_socket_t *current = !use_ephemeral_port?int_socket_find(listen_port, is_secure, is_real_socket, bypassSec):NULL;
internal_socket_t *current = !use_ephemeral_port ? int_socket_find(listen_port, is_secure, is_real_socket, bypassSec) : NULL;
if (!current) {
handler->socket = int_socket_create(listen_port, use_ephemeral_port, is_secure, is_real_socket, bypassSec, handler->socket_interface_selection, handler->registered_to_multicast);
if (!handler->socket) {
@ -918,7 +923,7 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_add
memset(&security_material, 0, sizeof(coap_security_keys_t));
if (!handler->_get_password_cb || 0 != handler->_get_password_cb(handler->socket->socket, (uint8_t*)dest_addr->address, dest_addr->identifier, &security_material)) {
if (!handler->_get_password_cb || 0 != handler->_get_password_cb(handler->socket->socket, (uint8_t *)dest_addr->address, dest_addr->identifier, &security_material)) {
return -1;
}
@ -932,7 +937,7 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_add
} else if (session->session_state == SECURE_SESSION_OK) {
session->last_contact_time = coap_service_get_internal_timer_ticks();
if (0 > coap_security_handler_send_message(session->sec_handler, data_ptr, data_len )) {
if (0 > coap_security_handler_send_message(session->sec_handler, data_ptr, data_len)) {
return -1;
}
}
@ -964,11 +969,11 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_add
bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int8_t socket_id)
{
if( !handler || !handler->socket){
if (!handler || !handler->socket) {
return false;
}
if( handler->socket->socket == socket_id){
if (handler->socket->socket == socket_id) {
return true;
}
return false;
@ -976,7 +981,7 @@ bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int
int8_t coap_connection_handler_set_timeout(coap_conn_handler_t *handler, uint32_t min, uint32_t max)
{
if(!handler || !handler->socket){
if (!handler || !handler->socket) {
return -1;
}
handler->socket->timeout_max = max;
@ -999,19 +1004,19 @@ int8_t coap_connection_handler_handshake_limits_set(uint8_t handshakes_limit, ui
/* No need to call every second - call rather like every minute (SECURE_SESSION_CLEAN_INTERVAL sets this) */
void coap_connection_handler_exec(uint32_t time)
{
if(ns_list_count(&secure_session_list)){
if (ns_list_count(&secure_session_list)) {
// Seek & destroy old sessions where close notify have been sent
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if(cur_ptr->session_state == SECURE_SESSION_CLOSED) {
if((cur_ptr->last_contact_time + CLOSED_SECURE_SESSION_TIMEOUT) <= time){
ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) {
if (cur_ptr->session_state == SECURE_SESSION_CLOSED) {
if ((cur_ptr->last_contact_time + CLOSED_SECURE_SESSION_TIMEOUT) <= time) {
secure_session_delete(cur_ptr);
}
} else if(cur_ptr->session_state == SECURE_SESSION_OK){
if((cur_ptr->last_contact_time + OPEN_SECURE_SESSION_TIMEOUT) <= time){
} else if (cur_ptr->session_state == SECURE_SESSION_OK) {
if ((cur_ptr->last_contact_time + OPEN_SECURE_SESSION_TIMEOUT) <= time) {
secure_session_delete(cur_ptr);
}
} else if(cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING){
if((cur_ptr->last_contact_time + ONGOING_HANDSHAKE_TIMEOUT) <= time){
} else if (cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) {
if ((cur_ptr->last_contact_time + ONGOING_HANDSHAKE_TIMEOUT) <= time) {
secure_session_delete(cur_ptr);
}
}

View File

@ -98,6 +98,18 @@ static coap_transaction_t *transaction_find_by_address(uint8_t *address_ptr, uin
return this;
}
static coap_transaction_t *transaction_find_by_service_id(int8_t service_id)
{
coap_transaction_t *this = NULL;
ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) {
if (cur_ptr->service_id == service_id) {
this = cur_ptr;
break;
}
}
return this;
}
/* retransmission valid time is calculated to be max. time that CoAP message sending can take: */
/* Number of retransmisisons, each retransmission is 2 * previous retransmisison time */
/* + random factor (max. 1.5) */
@ -160,6 +172,21 @@ void transactions_delete_all(uint8_t *address_ptr, uint16_t port)
}
}
static void transactions_delete_all_by_service_id(int8_t service_id)
{
coap_transaction_t *transaction = transaction_find_by_service_id(service_id);
while (transaction) {
ns_list_remove(&request_list, transaction);
if (transaction->resp_cb) {
transaction->resp_cb(transaction->service_id, transaction->remote_address, transaction->remote_port, NULL);
}
sn_coap_protocol_delete_retransmission(coap_service_handle->coap, transaction->msg_id);
transaction_free(transaction);
transaction = transaction_find_by_service_id(service_id);
}
}
static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_ptr, void *param)
{
coap_transaction_t *this = NULL;
@ -173,7 +200,7 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
if (!resp_ptr || !address_ptr) {
return -1;
}
if(resp_ptr->token_ptr){
if (resp_ptr->token_ptr) {
this = transaction_find_client_by_token(resp_ptr->token_ptr, resp_ptr->token_len, address_ptr->addr_ptr, address_ptr->port);
}
if (!this) {
@ -189,7 +216,8 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
}
coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *)){
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *))
{
if ((used_malloc_func_ptr == NULL) || (used_free_func_ptr == NULL) || (used_tx_callback_ptr == NULL)) {
return NULL;
@ -209,7 +237,7 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
handle->sn_coap_service_malloc = used_malloc_func_ptr;
handle->coap = sn_coap_protocol_init(used_malloc_func_ptr, used_free_func_ptr, used_tx_callback_ptr, &coap_rx_function);
if( !handle->coap ){
if (!handle->coap) {
ns_dyn_mem_free(handle);
return NULL;
}
@ -226,12 +254,13 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
return handle;
}
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle){
if( !handle ){
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
{
if (!handle) {
return -1;
}
if( handle->coap ){
if (handle->coap) {
sn_coap_protocol_destroy(handle->coap);
}
@ -258,9 +287,10 @@ coap_transaction_t *coap_message_handler_transaction_valid(coap_transaction_t *t
coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port)
{
if( !address_ptr )
if (!address_ptr) {
return NULL;
return transaction_find_by_address( address_ptr, port );
}
return transaction_find_by_address(address_ptr, port);
}
int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16],
@ -322,6 +352,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
goto exit;
/* Response received */
} else {
transaction_delete(transaction_ptr); // transaction_ptr not needed in response
if (coap_message->token_ptr) {
this = transaction_find_client_by_token(coap_message->token_ptr, coap_message->token_len, source_addr_ptr, port);
}
@ -385,10 +416,10 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
request.uri_path_len = strlen(uri);
request.content_format = cont_type;
do{
randLIB_get_n_bytes_random(token,4);
}while(transaction_find_client_by_token(token, 4, destination_addr, destination_port));
memcpy(transaction_ptr->token,token,4);
do {
randLIB_get_n_bytes_random(token, 4);
} while (transaction_find_client_by_token(token, 4, destination_addr, destination_port));
memcpy(transaction_ptr->token, token, 4);
transaction_ptr->token_len = 4;
request.token_ptr = transaction_ptr->token;
request.token_len = 4;
@ -400,7 +431,7 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
data_len = sn_coap_builder_calc_needed_packet_data_size_2(&request, sn_coap_protocol_get_configured_blockwise_size(handle->coap));
data_ptr = own_alloc(data_len);
if(data_len > 0 && !data_ptr){
if (data_len > 0 && !data_ptr) {
transaction_delete(transaction_ptr);
return 0;
}
@ -423,11 +454,11 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
// Free allocated data
own_free(data_ptr);
if(request.options_list_ptr) {
if (request.options_list_ptr) {
own_free(request.options_list_ptr);
}
if(request_response_cb == NULL){
if (request_response_cb == NULL) {
//No response expected
return 0;
}
@ -484,7 +515,7 @@ int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t ser
}
response = sn_coap_build_response(handle->coap, request_ptr, message_code);
if( !response ){
if (!response) {
return -1;
}
response->payload_len = payload_len;
@ -494,14 +525,14 @@ int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t ser
ret_val = coap_message_handler_resp_build_and_send(handle, response, transaction_ptr);
sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response);
if(ret_val == 0) {
if (ret_val == 0) {
transaction_delete(transaction_ptr);
}
return ret_val;
}
int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len)
int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{
sn_coap_hdr_s response;
coap_transaction_t *transaction_ptr;
@ -533,7 +564,7 @@ int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle,
}
ret_val = coap_message_handler_resp_build_and_send(handle, &response, transaction_ptr);
if(ret_val == 0) {
if (ret_val == 0) {
transaction_delete(transaction_ptr);
}
@ -551,6 +582,7 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
tr_error("invalid params");
return -1;
}
sn_coap_protocol_delete_retransmission(handle->coap, msg_id);
transaction_ptr = transaction_find_client(msg_id);
@ -558,13 +590,32 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
tr_error("response transaction not found");
return -2;
}
if (transaction_ptr->resp_cb) {
transaction_ptr->resp_cb(transaction_ptr->service_id, transaction_ptr->remote_address, transaction_ptr->remote_port, NULL);
}
transaction_delete(transaction_ptr);
return 0;
}
int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time){
int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_id)
{
tr_debug("Service %d, delete all CoAP requests", service_id);
if( !handle ){
if (!handle) {
tr_error("invalid params");
return -1;
}
transactions_delete_all_by_service_id(service_id);
return 0;
}
int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time)
{
if (!handle) {
return -1;
}

View File

@ -84,16 +84,17 @@ static const int PSK_SUITES[] = {
#define TRACE_GROUP "CsSh"
static void set_timer( void *sec_obj, uint32_t int_ms, uint32_t fin_ms );
static int get_timer( void *sec_obj );
static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms);
static int get_timer(void *sec_obj);
int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen );
int entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen);
//Point these back to M2MConnectionHandler!!!
int f_send( void *ctx, const unsigned char *buf, size_t len );
int f_send(void *ctx, const unsigned char *buf, size_t len);
int f_recv(void *ctx, unsigned char *buf, size_t len);
static int coap_security_handler_init(coap_security_t *sec){
static int coap_security_handler_init(coap_security_t *sec)
{
const char *pers = "dtls_client";
#ifdef COAP_SERVICE_PROVIDE_STRONG_ENTROPY_SOURCE
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_STRONG;
@ -101,15 +102,15 @@ static int coap_security_handler_init(coap_security_t *sec){
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_WEAK;
#endif
mbedtls_ssl_init( &sec->_ssl );
mbedtls_ssl_config_init( &sec->_conf );
mbedtls_ctr_drbg_init( &sec->_ctr_drbg );
mbedtls_entropy_init( &sec->_entropy );
mbedtls_ssl_init(&sec->_ssl);
mbedtls_ssl_config_init(&sec->_conf);
mbedtls_ctr_drbg_init(&sec->_ctr_drbg);
mbedtls_entropy_init(&sec->_entropy);
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_init( &sec->_cacert );
mbedtls_x509_crt_init( &sec->_owncert );
mbedtls_pk_init( &sec->_pkey );
mbedtls_x509_crt_init(&sec->_cacert);
mbedtls_x509_crt_init(&sec->_owncert);
mbedtls_pk_init(&sec->_pkey);
#endif
memset(&sec->_cookie, 0, sizeof(simple_cookie_t));
@ -117,15 +118,14 @@ static int coap_security_handler_init(coap_security_t *sec){
sec->_is_started = false;
if( mbedtls_entropy_add_source( &sec->_entropy, entropy_poll, NULL,
128, entropy_source_type ) < 0 ){
if (mbedtls_entropy_add_source(&sec->_entropy, entropy_poll, NULL,
128, entropy_source_type) < 0) {
return -1;
}
if( ( mbedtls_ctr_drbg_seed( &sec->_ctr_drbg, mbedtls_entropy_func, &sec->_entropy,
if ((mbedtls_ctr_drbg_seed(&sec->_ctr_drbg, mbedtls_entropy_func, &sec->_entropy,
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
strlen(pers))) != 0) {
return -1;
}
return 0;
@ -141,15 +141,16 @@ const void *coap_security_handler_keyblock(const coap_security_t *sec)
return sec->_keyblk.value;
}
static void coap_security_handler_reset(coap_security_t *sec){
static void coap_security_handler_reset(coap_security_t *sec)
{
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&sec->_cacert);
mbedtls_x509_crt_free(&sec->_owncert);
mbedtls_pk_free(&sec->_pkey);
#endif
mbedtls_entropy_free( &sec->_entropy );
mbedtls_ctr_drbg_free( &sec->_ctr_drbg );
mbedtls_entropy_free(&sec->_entropy);
mbedtls_ctr_drbg_free(&sec->_ctr_drbg);
mbedtls_ssl_config_free(&sec->_conf);
mbedtls_ssl_free(&sec->_ssl);
}
@ -165,7 +166,7 @@ coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *h
return NULL;
}
coap_security_t *this = ns_dyn_mem_alloc(sizeof(coap_security_t));
if( !this ){
if (!this) {
return NULL;
}
memset(this, 0, sizeof(coap_security_t));
@ -187,8 +188,9 @@ coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *h
return this;
}
void coap_security_destroy(coap_security_t *sec){
if( sec ){
void coap_security_destroy(coap_security_t *sec)
{
if (sec) {
coap_security_handler_reset(sec);
ns_dyn_mem_free(sec);
sec = NULL;
@ -290,19 +292,19 @@ static int export_key_block(void *ctx,
}
#endif
static int coap_security_handler_configure_keys (coap_security_t *sec, coap_security_keys_t keys, bool is_server)
static int coap_security_handler_configure_keys(coap_security_t *sec, coap_security_keys_t keys, bool is_server)
{
(void) is_server;
int ret = -1;
switch( sec->_conn_mode ){
case CERTIFICATE:{
switch (sec->_conn_mode) {
case CERTIFICATE: {
#if defined(MBEDTLS_X509_CRT_PARSE_C)
if( keys._cert && mbedtls_x509_crt_parse( &sec->_owncert, keys._cert, keys._cert_len ) < 0 ){
if (keys._cert && mbedtls_x509_crt_parse(&sec->_owncert, keys._cert, keys._cert_len) < 0) {
break;
}
if( mbedtls_pk_parse_key(&sec->_pkey, keys._priv_key, keys._priv_key_len, NULL, 0) < 0){
if (mbedtls_pk_parse_key(&sec->_pkey, keys._priv_key, keys._priv_key_len, NULL, 0) < 0) {
break;
}
@ -310,15 +312,15 @@ static int coap_security_handler_configure_keys (coap_security_t *sec, coap_secu
break;
}
mbedtls_ssl_conf_authmode( &sec->_conf, MBEDTLS_SSL_VERIFY_NONE );
mbedtls_ssl_conf_ca_chain( &sec->_conf, &sec->_owncert, NULL );
mbedtls_ssl_conf_authmode(&sec->_conf, MBEDTLS_SSL_VERIFY_NONE);
mbedtls_ssl_conf_ca_chain(&sec->_conf, &sec->_owncert, NULL);
ret = 0;
#endif
break;
}
case PSK: {
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
if( 0 != mbedtls_ssl_conf_psk(&sec->_conf, keys._priv_key, keys._priv_key_len, keys._cert, keys._cert_len) ){
if (0 != mbedtls_ssl_conf_psk(&sec->_conf, keys._priv_key, keys._priv_key_len, keys._cert, keys._cert_len)) {
break;
}
mbedtls_ssl_conf_ciphersuites(&sec->_conf, PSK_SUITES);
@ -328,7 +330,7 @@ static int coap_security_handler_configure_keys (coap_security_t *sec, coap_secu
}
case ECJPAKE: {
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
if( mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, keys._key, keys._key_len) != 0 ){
if (mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, keys._key, keys._key_len) != 0) {
return -1;
}
mbedtls_ssl_conf_ciphersuites(&sec->_conf, ECJPAKE_SUITES);
@ -350,52 +352,49 @@ static int coap_security_handler_configure_keys (coap_security_t *sec, coap_secu
int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max)
{
if( !sec ){
if (!sec) {
return -1;
}
sec->_is_blocking = false;
int endpoint = MBEDTLS_SSL_IS_CLIENT;
if( is_server ){
if (is_server) {
endpoint = MBEDTLS_SSL_IS_SERVER;
}
int mode = MBEDTLS_SSL_TRANSPORT_DATAGRAM;
if( sock_mode == TLS ){
if (sock_mode == TLS) {
mode = MBEDTLS_SSL_TRANSPORT_STREAM;
}
if( ( mbedtls_ssl_config_defaults( &sec->_conf,
if ((mbedtls_ssl_config_defaults(&sec->_conf,
endpoint,
mode, 0 ) ) != 0 )
{
mode, 0)) != 0) {
return -1;
}
if(!timeout_max && !timeout_min){
mbedtls_ssl_conf_handshake_timeout( &sec->_conf, DTLS_HANDSHAKE_TIMEOUT_MIN, DTLS_HANDSHAKE_TIMEOUT_MAX );
}
else{
mbedtls_ssl_conf_handshake_timeout( &sec->_conf, timeout_min, timeout_max );
if (!timeout_max && !timeout_min) {
mbedtls_ssl_conf_handshake_timeout(&sec->_conf, DTLS_HANDSHAKE_TIMEOUT_MIN, DTLS_HANDSHAKE_TIMEOUT_MAX);
} else {
mbedtls_ssl_conf_handshake_timeout(&sec->_conf, timeout_min, timeout_max);
}
mbedtls_ssl_conf_rng( &sec->_conf, mbedtls_ctr_drbg_random, &sec->_ctr_drbg );
mbedtls_ssl_conf_rng(&sec->_conf, mbedtls_ctr_drbg_random, &sec->_ctr_drbg);
if( ( mbedtls_ssl_setup( &sec->_ssl, &sec->_conf ) ) != 0 )
{
if ((mbedtls_ssl_setup(&sec->_ssl, &sec->_conf)) != 0) {
return -1;
}
mbedtls_ssl_set_bio( &sec->_ssl, sec,
f_send, f_recv, NULL );
mbedtls_ssl_set_bio(&sec->_ssl, sec,
f_send, f_recv, NULL);
mbedtls_ssl_set_timer_cb( &sec->_ssl, sec, set_timer,
get_timer );
mbedtls_ssl_set_timer_cb(&sec->_ssl, sec, set_timer,
get_timer);
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
//TODO: Figure out better way!!!
//Password should never be stored in multiple places!!!
if ((sec->_conn_mode == ECJPAKE) && is_server && keys._key_len > 0){
if ((sec->_conn_mode == ECJPAKE) && is_server && keys._key_len > 0) {
memcpy(sec->_pw, keys._key, keys._key_len);
sec->_pw_len = keys._key_len;
}
@ -417,46 +416,46 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
sec->_is_started = true;
int ret = mbedtls_ssl_handshake_step( &sec->_ssl );
if( ret == 0 ){
ret = mbedtls_ssl_handshake_step( &sec->_ssl );
if( is_server && 0 == ret){
ret = coap_security_handler_continue_connecting( sec );
int ret = mbedtls_ssl_handshake_step(&sec->_ssl);
if (ret == 0) {
ret = mbedtls_ssl_handshake_step(&sec->_ssl);
if (is_server && 0 == ret) {
ret = coap_security_handler_continue_connecting(sec);
}
}
if( ret >= 0){
if (ret >= 0) {
ret = 1;
}else{
} else {
ret = -1;
}
return ret;
}
int coap_security_handler_continue_connecting(coap_security_t *sec){
int coap_security_handler_continue_connecting(coap_security_t *sec)
{
int ret = -1;
while( ret != MBEDTLS_ERR_SSL_WANT_READ ){
ret = mbedtls_ssl_handshake_step( &sec->_ssl );
if( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED == ret){
while (ret != MBEDTLS_ERR_SSL_WANT_READ) {
ret = mbedtls_ssl_handshake_step(&sec->_ssl);
if (MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED == ret) {
mbedtls_ssl_session_reset(&sec->_ssl);
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
if( mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, sec->_pw, sec->_pw_len) != 0 ){
if (mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, sec->_pw, sec->_pw_len) != 0) {
return -1;
}
#endif
return 1;
}
else if(ret && (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)){
} else if (ret && (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)) {
return ret;
}
if( sec->_ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER ){
if (sec->_ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER) {
return 0;
}
}
if(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE){
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
return 1;
}
@ -464,13 +463,15 @@ int coap_security_handler_continue_connecting(coap_security_t *sec){
}
int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len){
int ret=-1;
int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len)
{
int ret = -1;
if( sec ){
do ret = mbedtls_ssl_write( &sec->_ssl, (unsigned char *) message, len );
while( ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE );
if (sec) {
do {
ret = mbedtls_ssl_write(&sec->_ssl, (unsigned char *) message, len);
} while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
return ret; //bytes written
@ -478,25 +479,26 @@ int coap_security_handler_send_message(coap_security_t *sec, unsigned char *mess
int coap_security_send_close_alert(coap_security_t *sec)
{
if( !sec ){
if (!sec) {
return -1;
}
if(!mbedtls_ssl_close_notify(&sec->_ssl)){
if (!mbedtls_ssl_close_notify(&sec->_ssl)) {
return 0;
}
return -1;
}
int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len){
int ret=-1;
int coap_security_handler_read(coap_security_t *sec, unsigned char *buffer, size_t len)
{
int ret = -1;
int max_loops = 100;
if( sec && buffer ){
memset( buffer, 0, len );
if (sec && buffer) {
memset(buffer, 0, len);
do {
ret = mbedtls_ssl_read( &sec->_ssl, buffer, len );
} while( (ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret = mbedtls_ssl_read(&sec->_ssl, buffer, len);
} while ((ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE)
&& --max_loops);
}
@ -516,8 +518,8 @@ int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size
static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms)
{
coap_security_t *sec = (coap_security_t *)sec_obj;
if( sec->_start_timer_cb ){
sec->_start_timer_cb( sec->_timer_id, int_ms, fin_ms);
if (sec->_start_timer_cb) {
sec->_start_timer_cb(sec->_timer_id, int_ms, fin_ms);
}
}
@ -531,41 +533,43 @@ static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms)
static int get_timer(void *sec_obj)
{
coap_security_t *sec = (coap_security_t *)sec_obj;
if( sec->_timer_status_cb ){
if (sec->_timer_status_cb) {
return sec->_timer_status_cb(sec->_timer_id);
}
return -1;
}
int f_send( void *ctx, const unsigned char *buf, size_t len){
int f_send(void *ctx, const unsigned char *buf, size_t len)
{
coap_security_t *sec = (coap_security_t *)ctx;
return sec->_send_cb(sec->_socket_id, sec->_handle, buf, len);
}
int f_recv(void *ctx, unsigned char *buf, size_t len){
int f_recv(void *ctx, unsigned char *buf, size_t len)
{
coap_security_t *sec = (coap_security_t *)ctx;
return sec->_receive_cb(sec->_socket_id, buf, len);
}
int entropy_poll( void *ctx, unsigned char *output, size_t len,
size_t *olen )
int entropy_poll(void *ctx, unsigned char *output, size_t len,
size_t *olen)
{
(void)ctx;
//TODO: change to more secure random
randLIB_seed_random();
char *c = (char*)ns_dyn_mem_temporary_alloc(len);
if( !c ){
char *c = (char *)ns_dyn_mem_temporary_alloc(len);
if (!c) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
}
memset(c, 0, len);
for(uint16_t i=0; i < len; i++){
for (uint16_t i = 0; i < len; i++) {
*(c + i) = (char)randLIB_get_8bit();
}
memmove(output, c, len);
*olen = len;
ns_dyn_mem_free(c);
return( 0 );
return (0);
}
#endif // COAP_SECURITY_AVAILABLE

View File

@ -95,7 +95,7 @@ static coap_service_t *service_find_by_socket(int8_t socket_id)
{
coap_service_t *this = NULL;
ns_list_foreach(coap_service_t, cur_ptr, &instance_list) {
if( coap_connection_handler_socket_belongs_to(cur_ptr->conn_handler, socket_id) ){
if (coap_connection_handler_socket_belongs_to(cur_ptr->conn_handler, socket_id)) {
this = cur_ptr;
break;
}
@ -201,9 +201,10 @@ static void service_event_handler(arm_event_s *event)
tr_debug("service tasklet initialised");
/*initialize coap service and listen socket*/
}
if (event->event_type == ARM_LIB_SYSTEM_TIMER_EVENT && event->event_id == COAP_TICK_TIMER) {
coap_message_handler_exec(coap_service_handle, coap_ticks++);
if(coap_ticks && !coap_ticks % SECURE_SESSION_CLEAN_INTERVAL){
if (coap_ticks && !(coap_ticks % SECURE_SESSION_CLEAN_INTERVAL)) {
coap_connection_handler_exec(coap_ticks);
}
}
@ -233,7 +234,7 @@ static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_m
if (uri_reg_ptr && uri_reg_ptr->request_recv_cb) {
tr_debug("Service %d, call request recv cb uri %.*s", this->service_id, coap_message->uri_path_len, coap_message->uri_path_ptr);
if ((this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS ) {//TODO Add secure bypass option
if ((this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS) { //TODO Add secure bypass option
// Service has secure bypass active TODO this is not defined in interface
// this check can be removed I think
transaction_ptr->options = COAP_REQUEST_OPTIONS_SECURE_BYPASS;
@ -273,7 +274,7 @@ static int virtual_send_cb(int8_t socket_id, const uint8_t address[static 16], u
coap_service_t *this = service_find_by_socket(socket_id);
if (this && this->virtual_socket_send_cb) {
tr_debug("send to virtual socket, service: %d", this->service_id);
return this->virtual_socket_send_cb(this->service_id, (uint8_t*)address, port, data_ptr, data_len);
return this->virtual_socket_send_cb(this->service_id, (uint8_t *)address, port, data_ptr, data_len);
}
return -1;
}
@ -365,7 +366,7 @@ int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_
}
this->conn_handler = connection_handler_create(recv_cb, virtual_send_cb, get_passwd_cb, sec_done_cb);
if(!this->conn_handler){
if (!this->conn_handler) {
ns_dyn_mem_free(this);
return -1;
}
@ -407,7 +408,7 @@ void coap_service_delete(int8_t service_id)
return;
}
if (this->conn_handler){
if (this->conn_handler) {
bool leave_multicast_group = false;
if (coap_service_can_leave_multicast_group(this->conn_handler)) {
// This is the last handler joined to multicast group
@ -434,7 +435,7 @@ extern void coap_service_close_secure_connection(int8_t service_id, uint8_t dest
if (!this || !destination_addr_ptr) {
return;
}
if (this->conn_handler){
if (this->conn_handler) {
connection_handler_close_secure_connection(this->conn_handler, destination_addr_ptr, port);
}
}
@ -475,7 +476,7 @@ int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t all
uri_reg_ptr = uri_registration_find(this, uri, uri_len);
if (!uri_reg_ptr) {
uri_reg_ptr = ns_dyn_mem_alloc(sizeof(uri_registration_t));
if( !uri_reg_ptr ){
if (!uri_reg_ptr) {
tr_error("Uri registration failed, OOM");
return -2;
}
@ -522,17 +523,20 @@ int8_t coap_service_unregister_uri(int8_t service_id, const char *uri)
}
uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri,
sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb){
sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb)
{
//TODO: coap_service_response_recv is an ugly cast, this should be refactored away + sn_coap_hdr_s MUST NOT be exposed to users of coap-service!
//Callback would be still needed, but where to store callback?
return coap_message_handler_request_send(coap_service_handle, service_id, options, destination_addr, destination_port, msg_type, msg_code, uri, cont_type, payload_ptr, payload_len, request_response_cb);
}
int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len){
int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{
return coap_message_handler_response_send(coap_service_handle, service_id, options, request_ptr, message_code, content_type, payload_ptr, payload_len);
}
int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len) {
int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{
return coap_message_handler_response_send_by_msg_id(coap_service_handle, service_id, options, msg_id, message_code, content_type, payload_ptr, payload_len);
}
@ -541,10 +545,15 @@ int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id)
return coap_message_handler_request_delete(coap_service_handle, service_id, msg_id);
}
void coap_service_request_delete_by_service_id(int8_t service_id)
{
coap_message_handler_request_delete_by_service_id(coap_service_handle, service_id);
}
int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint32_t max)
{
coap_service_t *this = service_find(service_id);
if(!this){
if (!this) {
return -1;
}
@ -576,7 +585,7 @@ uint16_t coap_service_id_find_by_socket(int8_t socket_id)
{
coap_service_t *this = service_find_by_socket(socket_id);
return this ? this->service_id:0;
return this ? this->service_id : 0;
}
int8_t coap_service_certificate_set(int8_t service_id, const unsigned char *cert, uint16_t cert_len, const unsigned char *priv_key, uint8_t priv_key_len)

View File

@ -39,7 +39,7 @@ typedef int receive_from_socket_cb(int8_t socket_id, uint8_t src_address[static
typedef int get_pw_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr);
typedef void security_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]);
typedef struct coap_conn_handler_s{
typedef struct coap_conn_handler_s {
struct internal_socket_s *socket;
coap_security_keys_t *security_keys;
@ -57,9 +57,9 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
get_pw_cb *pw_cb,
security_done_cb *done_cb);
void connection_handler_destroy( coap_conn_handler_t *handler, bool multicast_group_leave);
void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave);
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port );
void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port);
int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec);

View File

@ -96,6 +96,8 @@ extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int
extern int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id);
extern int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_id);
extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time);
extern void transaction_delete(coap_transaction_t *this);
@ -103,6 +105,6 @@ extern void transaction_delete(coap_transaction_t *this);
extern void transactions_delete_all(uint8_t *address_ptr, uint16_t port);
extern int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code,
sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len);
sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
#endif

View File

@ -55,13 +55,13 @@ typedef int timer_status_cb(int8_t timer_id);
typedef enum {
DTLS = 0,
TLS = 1
}SecureSocketMode;
} SecureSocketMode;
typedef enum {
CERTIFICATE,
PSK,
ECJPAKE
}SecureConnectionMode;
} SecureConnectionMode;
typedef struct {
SecureConnectionMode mode;
@ -96,7 +96,7 @@ int coap_security_handler_send_message(coap_security_t *sec, unsigned char *mess
int coap_security_send_close_alert(coap_security_t *sec);
int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len);
int coap_security_handler_read(coap_security_t *sec, unsigned char *buffer, size_t len);
bool coap_security_handler_is_started(const coap_security_t *sec);

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_connection_handler)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
int main(int ac, char **av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

View File

@ -50,16 +50,19 @@ void sec_done_cb_test(int8_t socket_id, uint8_t address[static 16], uint16_t por
bool test_connection_handler_create()
{
coap_security_handler_stub.counter = -1;
if( NULL != connection_handler_create(NULL, NULL, NULL, NULL) )
if (NULL != connection_handler_create(NULL, NULL, NULL, NULL)) {
return false;
}
if( NULL != connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL) )
if (NULL != connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL);
if( NULL == handler )
if (NULL == handler) {
return false;
}
ns_dyn_mem_free(handler);
return true;
}
@ -80,35 +83,42 @@ bool test_coap_connection_handler_open_connection()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL);
if( -1 != coap_connection_handler_open_connection(NULL, 0,false,false,false,false) )
if (-1 != coap_connection_handler_open_connection(NULL, 0, false, false, false, false)) {
return false;
}
if( -1 != coap_connection_handler_open_connection(handler, 0,false,false,false,false) )
if (-1 != coap_connection_handler_open_connection(handler, 0, false, false, false, false)) {
return false;
}
ns_dyn_mem_free(handler);
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
if( -1 != coap_connection_handler_open_connection(handler, 0,true,true,true,false) )
if (-1 != coap_connection_handler_open_connection(handler, 0, true, true, true, false)) {
return false;
}
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 0,true,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 0, true, true, true, false)) {
return false;
}
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,true) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, true, true)) {
return false;
}
//open second one
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler2, 22,false,true,true,true) )
if (0 != coap_connection_handler_open_connection(handler2, 22, false, true, true, true)) {
return false;
}
if( 0 != coap_connection_handler_open_connection(handler, 23,false,false,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 23, false, false, false, false)) {
return false;
}
connection_handler_destroy(handler2, false);
connection_handler_destroy(handler, false);
@ -118,8 +128,9 @@ bool test_coap_connection_handler_open_connection()
bool test_coap_connection_handler_send_data()
{
coap_security_handler_stub.counter = -1;
if( -1 != coap_connection_handler_send_data(NULL, NULL, ns_in6addr_any, NULL, 0, false))
if (-1 != coap_connection_handler_send_data(NULL, NULL, ns_in6addr_any, NULL, 0, false)) {
return false;
}
ns_address_t addr;
memset(addr.address, 1, 16);
@ -128,11 +139,13 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, false, false)) {
return false;
}
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (-1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
@ -141,14 +154,17 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 4;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, false, false)) {
return false;
}
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (-1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (-1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
@ -159,23 +175,27 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, false, false, false)) {
return false;
}
if( 1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
connection_handler_destroy(handler ,false);
}
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, false, true, false)) {
return false;
}
socket_api_stub.int8_value = 7;
if( 1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
//<-- NON SECURE HERE
@ -188,65 +208,77 @@ bool test_coap_connection_handler_virtual_recv()
coap_security_handler_stub.counter = -1;
uint8_t buf[16];
memset(&buf, 1, 16);
if( -1 != coap_connection_handler_virtual_recv(NULL,buf, 12, NULL, 0) )
if (-1 != coap_connection_handler_virtual_recv(NULL, buf, 12, NULL, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, true, false)) {
return false;
}
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, NULL, 0) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, NULL, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, NULL, 0) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, NULL, 0)) {
return false;
}
ns_timer_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 3;
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, &buf, 1)) {
return false;
}
//handler->socket->data still in memory
coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc();
ns_timer_stub.int8_value = -1;
nsdynmemlib_stub.returnCounter = 3;
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, &buf, 1)) {
return false;
}
ns_timer_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 3;
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, &buf, 1)) {
return false;
}
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb_test);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler2, 24,false,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler2, 24, false, true, true, false)) {
return false;
}
nsdynmemlib_stub.returnCounter = 3;
if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) )
if (0 != coap_connection_handler_virtual_recv(handler2, buf, 12, &buf, 1)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_security_handler_stub.int_value = 0;
if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) )
if (0 != coap_connection_handler_virtual_recv(handler2, buf, 12, &buf, 1)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) )
if (0 != coap_connection_handler_virtual_recv(handler2, buf, 12, &buf, 1)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_security_handler_stub.int_value = MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY;
if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) )
if (0 != coap_connection_handler_virtual_recv(handler2, buf, 12, &buf, 1)) {
return false;
}
connection_handler_destroy(handler2, false);
@ -256,12 +288,14 @@ bool test_coap_connection_handler_virtual_recv()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler3 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb_test);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler3, 26,false,false,true,false) )
if (0 != coap_connection_handler_open_connection(handler3, 26, false, false, true, false)) {
return false;
}
nsdynmemlib_stub.returnCounter = 3;
if( 0 != coap_connection_handler_virtual_recv(handler3,buf, 12, &buf, 1) )
if (0 != coap_connection_handler_virtual_recv(handler3, buf, 12, &buf, 1)) {
return false;
}
connection_handler_destroy(handler3, false);
@ -271,21 +305,25 @@ bool test_coap_connection_handler_virtual_recv()
bool test_coap_connection_handler_socket_belongs_to()
{
coap_security_handler_stub.counter = -1;
if( false != coap_connection_handler_socket_belongs_to(NULL, 2) )
if (false != coap_connection_handler_socket_belongs_to(NULL, 2)) {
return false;
}
socket_api_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, true, false)) {
return false;
}
if( true != coap_connection_handler_socket_belongs_to(handler, 0) )
if (true != coap_connection_handler_socket_belongs_to(handler, 0)) {
return false;
}
if( false != coap_connection_handler_socket_belongs_to(handler, 3) )
if (false != coap_connection_handler_socket_belongs_to(handler, 3)) {
return false;
}
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 0;
@ -301,8 +339,9 @@ bool test_timer_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, true, false)) {
return false;
}
//handler->socket->data still in memory
coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc();
@ -310,25 +349,28 @@ bool test_timer_callbacks()
ns_timer_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 3;
ns_timer_stub.int8_value = 5;
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, &buf, 1)) {
return false;
}
//Note next tests will affect ns_timer test (cycle & cycle_count
if( coap_security_handler_stub.start_timer_cb ){
if (coap_security_handler_stub.start_timer_cb) {
coap_security_handler_stub.start_timer_cb(1, 0, 0);
coap_security_handler_stub.start_timer_cb(1, 1, 2);
}
if( coap_security_handler_stub.timer_status_cb ){
if( -1 != coap_security_handler_stub.timer_status_cb(4) )
return false;
if( 0 != coap_security_handler_stub.timer_status_cb(1) )
if (coap_security_handler_stub.timer_status_cb) {
if (-1 != coap_security_handler_stub.timer_status_cb(4)) {
return false;
}
if( ns_timer_stub.cb ){
if (0 != coap_security_handler_stub.timer_status_cb(1)) {
return false;
}
}
if (ns_timer_stub.cb) {
ns_timer_stub.cb(4, 0);
ns_timer_stub.cb(5, 0);
@ -360,10 +402,11 @@ bool test_socket_api_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, false, true, false)) {
return false;
}
if( socket_api_stub.recv_cb ){
if (socket_api_stub.recv_cb) {
sckt_data->event_type = SOCKET_DATA;
sckt_data->d_len = 1;
socket_api_stub.int8_value = -1;
@ -382,10 +425,11 @@ bool test_socket_api_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb_test);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler2, 22,false,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler2, 22, false, true, true, false)) {
return false;
}
if( socket_api_stub.recv_cb ){
if (socket_api_stub.recv_cb) {
nsdynmemlib_stub.returnCounter = 1;
socket_api_stub.int8_value = 1;
sckt_data->socket_id = 1;
@ -438,10 +482,11 @@ bool test_security_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, true, false)) {
return false;
}
if( socket_api_stub.recv_cb ){
if (socket_api_stub.recv_cb) {
sckt_data->event_type = SOCKET_DATA;
sckt_data->d_len = 1;
nsdynmemlib_stub.returnCounter = 2;
@ -450,10 +495,10 @@ bool test_security_callbacks()
socket_api_stub.recv_cb(sckt_data);
}
if( coap_security_handler_stub.send_cb ){
if (coap_security_handler_stub.send_cb) {
coap_security_handler_stub.send_cb(0, buf, 22, &buf, 16);
}
if( coap_security_handler_stub.receive_cb ){
if (coap_security_handler_stub.receive_cb) {
coap_security_handler_stub.receive_cb(0, &buf, 16);
}

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_message_handler)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};
@ -63,6 +61,11 @@ TEST(coap_message_handler, test_coap_message_handler_request_delete)
CHECK(test_coap_message_handler_request_delete());
}
TEST(coap_message_handler, test_coap_message_handler_request_delete_by_service_id)
{
CHECK(test_coap_message_handler_request_delete_by_service_id());
}
TEST(coap_message_handler, test_coap_message_handler_exec)
{
CHECK(test_coap_message_handler_exec());

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
int main(int ac, char **av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

View File

@ -30,7 +30,7 @@ int transaction_cb = 0;
static void *test_own_alloc(uint16_t size)
{
if( retCounter > 0 ){
if (retCounter > 0) {
retCounter--;
return malloc(size);
}
@ -49,7 +49,8 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
return 0;
}
int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr){
int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr)
{
return retValue;
}
@ -66,25 +67,31 @@ static int transaction_recv_cb(int8_t service_id, uint8_t source_address[static
bool test_coap_message_handler_init()
{
if( NULL != coap_message_handler_init(NULL, NULL, NULL) )
if (NULL != coap_message_handler_init(NULL, NULL, NULL)) {
return false;
if( NULL != coap_message_handler_init(&test_own_alloc, NULL, NULL) )
}
if (NULL != coap_message_handler_init(&test_own_alloc, NULL, NULL)) {
return false;
if( NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, NULL) )
}
if (NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, NULL)) {
return false;
if( NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function) )
}
if (NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = NULL;
if( NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function) )
if (NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
if( NULL == handle )
if (NULL == handle) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
free(handle);
@ -93,16 +100,18 @@ bool test_coap_message_handler_init()
bool test_coap_message_handler_destroy()
{
if( -1 != coap_message_handler_destroy(NULL) )
if (-1 != coap_message_handler_destroy(NULL)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
if( 0 != coap_message_handler_destroy(handle) )
if (0 != coap_message_handler_destroy(handle)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
return true;
@ -110,10 +119,11 @@ bool test_coap_message_handler_destroy()
bool test_coap_message_handler_find_transaction()
{
if( NULL != coap_message_handler_find_transaction(NULL, 0))
if (NULL != coap_message_handler_find_transaction(NULL, 0)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
@ -127,11 +137,13 @@ bool test_coap_message_handler_find_transaction()
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
return false;
}
if( NULL == coap_message_handler_find_transaction(&buf, 24))
if (NULL == coap_message_handler_find_transaction(&buf, 24)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
@ -145,27 +157,30 @@ bool test_coap_message_handler_coap_msg_process()
memset(&buf, 1, 16);
bool ret_val = false;
/*Handler is null*/
if( -1 != coap_message_handler_coap_msg_process(NULL, 0, buf, 22, ns_in6addr_any, NULL, 0, NULL))
if (-1 != coap_message_handler_coap_msg_process(NULL, 0, buf, 22, ns_in6addr_any, NULL, 0, NULL)) {
goto exit;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
sn_coap_protocol_stub.expectedHeader = NULL;
/* Coap parse returns null */
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
sn_coap_protocol_stub.expectedHeader->coap_status = 66;
nsdynmemlib_stub.returnCounter = 1;
/* Coap library responds */
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
@ -174,8 +189,9 @@ bool test_coap_message_handler_coap_msg_process()
retValue = 0;
/* request received */
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
@ -183,8 +199,9 @@ bool test_coap_message_handler_coap_msg_process()
sn_coap_protocol_stub.expectedHeader->msg_code = 1;
nsdynmemlib_stub.returnCounter = 1;
retValue = -1;
if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
@ -192,8 +209,9 @@ bool test_coap_message_handler_coap_msg_process()
sn_coap_protocol_stub.expectedHeader->msg_code = 333;
nsdynmemlib_stub.returnCounter = 1;
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
@ -207,13 +225,15 @@ bool test_coap_message_handler_coap_msg_process()
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader->msg_id = 2;
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
ret_val = true;
exit:
@ -226,68 +246,77 @@ exit:
bool test_coap_message_handler_request_send()
{
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
uint8_t buf[16];
memset(&buf, 1, 16);
char uri[3];
uri[0] = "r";
uri[1] = "s";
uri[2] = "\0";
if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL))
char uri[3] = "rs";
if (0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) {
return false;
}
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL))
if (0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) {
return false;
}
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL))
if (0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) {
return false;
}
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL))
if (0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) {
return false;
}
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
return false;
}
/* Clear all transactions */
if( 0 != coap_message_handler_exec(handle, 0xffffffff))
if (0 != coap_message_handler_exec(handle, 0xffffffff)) {
return false;
}
sn_coap_protocol_stub.expectedInt16 = -4;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb)) {
return false;
}
transaction_cb = 0;
sn_coap_protocol_stub.expectedInt8 = 0;
if( 0 != coap_message_handler_exec(handle, 12))
if (0 != coap_message_handler_exec(handle, 12)) {
return false;
}
if (transaction_cb != 1)
if (transaction_cb != 1) {
return false;
}
sn_coap_protocol_stub.expectedInt16 = -2;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb))
return false;
transaction_cb = 0;
if( 0 != coap_message_handler_exec(handle, 2)) {
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb)) {
return false;
}
if (transaction_cb != 1)
transaction_cb = 0;
if (0 != coap_message_handler_exec(handle, 2)) {
return false;
}
if (transaction_cb != 1) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
@ -299,7 +328,7 @@ bool test_coap_message_handler_request_send()
bool test_coap_message_handler_request_delete()
{
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
@ -310,19 +339,23 @@ bool test_coap_message_handler_request_delete()
uri[0] = "r";
uri[1] = "s";
uri[2] = "\0";
if( 0 == coap_message_handler_request_delete(NULL, 1, 1))
if (0 == coap_message_handler_request_delete(NULL, 1, 1)) {
return false;
}
if( 0 == coap_message_handler_request_delete(handle, 1, 1))
if (0 == coap_message_handler_request_delete(handle, 1, 1)) {
return false;
}
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
return false;
}
if( 0 != coap_message_handler_request_delete(handle, 1, 2))
if (0 != coap_message_handler_request_delete(handle, 1, 2)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
@ -330,21 +363,61 @@ bool test_coap_message_handler_request_delete()
return true;
}
bool test_coap_message_handler_request_delete_by_service_id()
{
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
coap_service_handle = handle;
uint8_t buf[16];
memset(&buf, 1, 16);
char uri[3] = "rs";
if (0 == coap_message_handler_request_delete_by_service_id(NULL, 1)) {
return false;
}
if (0 != coap_message_handler_request_delete_by_service_id(handle, 1)) {
return false;
}
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
return false;
}
if (0 != coap_message_handler_request_delete_by_service_id(handle, 3)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
coap_message_handler_destroy(handle);
coap_service_handle = NULL;
return true;
}
bool test_coap_message_handler_response_send()
{
if( -1 != coap_message_handler_response_send(NULL, 2, 0, NULL, 1,3,NULL, 0))
if (-1 != coap_message_handler_response_send(NULL, 2, 0, NULL, 1, 3, NULL, 0)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
sn_coap_hdr_s *header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(header, 0, sizeof(sn_coap_hdr_s));
if( -2 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
if (-2 != coap_message_handler_response_send(handle, 2, 0, header, 1, 3, NULL, 0)) {
return false;
}
uint8_t buf[16];
memset(&buf, 1, 16);
@ -354,30 +427,34 @@ bool test_coap_message_handler_response_send()
uri[2] = "\0";
sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
return false;
}
header->msg_id = 2;
sn_coap_builder_stub.expectedUint16 = 2;
coap_transaction_t * tx = coap_message_handler_find_transaction(&buf, 24);
if( tx ){
coap_transaction_t *tx = coap_message_handler_find_transaction(&buf, 24);
if (tx) {
tx->client_request = false;
}
sn_coap_builder_stub.expectedHeader = NULL;
if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
if (-1 != coap_message_handler_response_send(handle, 2, 0, header, 1, 3, NULL, 0)) {
return false;
}
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
nsdynmemlib_stub.returnCounter = 0;
if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
if (-1 != coap_message_handler_response_send(handle, 2, 0, header, 1, 3, NULL, 0)) {
return false;
}
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
if (0 != coap_message_handler_response_send(handle, 2, 0, header, 1, 3, NULL, 0)) {
return false;
}
free(header);
free(sn_coap_protocol_stub.expectedCoap);
@ -389,52 +466,62 @@ bool test_coap_message_handler_response_send()
bool test_coap_message_handler_exec()
{
/* Null as a parameter */
if( -1 != coap_message_handler_exec(NULL, 0))
if (-1 != coap_message_handler_exec(NULL, 0)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s));
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
if( 0 != coap_message_handler_exec(handle, 0))
if (0 != coap_message_handler_exec(handle, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_transaction_t *transact_ptr = transaction_create();
/* Transaction not timed out*/
if( 0 != coap_message_handler_exec(handle, 0))
if (0 != coap_message_handler_exec(handle, 0)) {
return false;
}
if (transaction_cb != 0)
if (transaction_cb != 0) {
return false;
}
/* Timed out, no CB */
if( 0 != coap_message_handler_exec(handle, 300))
if (0 != coap_message_handler_exec(handle, 300)) {
return false;
}
if (transaction_cb != 0)
if (transaction_cb != 0) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
transact_ptr = transaction_create();
transact_ptr->resp_cb = transaction_recv_cb;
/* Transaction not timed out */
if( 0 != coap_message_handler_exec(handle, 0))
if (0 != coap_message_handler_exec(handle, 0)) {
return false;
}
if (transaction_cb != 0)
if (transaction_cb != 0) {
return false;
}
/* Transaction timed out */
if( 0 != coap_message_handler_exec(handle, 300))
if (0 != coap_message_handler_exec(handle, 300)) {
return false;
}
if (transaction_cb == 0)
if (transaction_cb == 0) {
return false;
}
/* Teardown */
free(sn_coap_protocol_stub.expectedCoap);

View File

@ -30,6 +30,7 @@ bool test_coap_message_handler_coap_msg_process();
bool test_coap_message_handler_request_send();
bool test_coap_message_handler_response_send();
bool test_coap_message_handler_request_delete();
bool test_coap_message_handler_request_delete_by_service_id();
bool test_coap_message_handler_exec();
#ifdef __cplusplus

View File

@ -21,14 +21,12 @@
TEST_GROUP(coap_security_handler)
{
void setup()
{
void setup() {
nsdynmemlib_stub.returnCounter = 0;
mbedtls_stub.useCounter = false;
}
void teardown()
{
void teardown() {
}
};

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
int main(int ac, char **av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

View File

@ -43,28 +43,33 @@ static int timer_status_callback(int8_t timer_id)
bool test_thread_security_create()
{
if( NULL != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, NULL) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, NULL)) {
return false;
}
if( NULL != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
mbedtls_stub.expected_int = -1;
if( NULL != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback)) {
return false;
}
mbedtls_stub.expected_int = 0;
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = -1;
if( NULL != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback)) {
return false;
}
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
coap_security_destroy(handle);
@ -75,9 +80,10 @@ bool test_thread_security_destroy()
{
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
coap_security_destroy(handle);
return true;
@ -87,16 +93,18 @@ bool test_coap_security_handler_connect()
{
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
unsigned char pw = "pwd";
coap_security_keys_t keys;
keys._key = &pw;
keys._key_len = 3;
if( -1 != coap_security_handler_connect_non_blocking(NULL, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(NULL, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.useCounter = true;
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = -1;
@ -108,19 +116,22 @@ bool test_coap_security_handler_connect()
mbedtls_stub.retArray[6] = -1;
mbedtls_stub.retArray[7] = -1;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0;
mbedtls_stub.retArray[1] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
simple_cookie_t c;
memset(&c, 0, sizeof(simple_cookie_t));
@ -131,8 +142,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[0] = 0;
// mbedtls_stub.retArray[1] = 0;
mbedtls_stub.retArray[2] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
c.len = 8;
memset(&c.value, 1, 8);
@ -145,8 +157,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[1] = 0;
// mbedtls_stub.retArray[2] = 0;
mbedtls_stub.retArray[3] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0;
@ -154,8 +167,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[2] = 0;
// mbedtls_stub.retArray[3] = 0;
mbedtls_stub.retArray[4] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0;
@ -165,20 +179,23 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[4] = 0;
mbedtls_stub.retArray[6] = 0;
mbedtls_stub.retArray[7] = 0;
if( 1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[5] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[5] = HANDSHAKE_FINISHED_VALUE;
if( 1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -188,9 +205,10 @@ bool test_coap_security_handler_continue_connecting()
{
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
mbedtls_stub.useCounter = true;
mbedtls_stub.counter = 0;
@ -198,34 +216,39 @@ bool test_coap_security_handler_continue_connecting()
mbedtls_stub.retArray[1] = -1;
mbedtls_stub.retArray[2] = -1;
if( -1 != coap_security_handler_continue_connecting(handle) )
if (-1 != coap_security_handler_continue_connecting(handle)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED;
mbedtls_stub.retArray[1] = 0;
mbedtls_stub.retArray[2] = 0;
if( 1 != coap_security_handler_continue_connecting(handle) )
if (1 != coap_security_handler_continue_connecting(handle)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED;
if( MBEDTLS_ERR_SSL_BAD_HS_FINISHED != coap_security_handler_continue_connecting(handle) )
if (MBEDTLS_ERR_SSL_BAD_HS_FINISHED != coap_security_handler_continue_connecting(handle)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_WANT_READ;
if( 1 != coap_security_handler_continue_connecting(handle) )
if (1 != coap_security_handler_continue_connecting(handle)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = HANDSHAKE_FINISHED_VALUE_RETURN_ZERO;
if( 0 != coap_security_handler_continue_connecting(handle) )
if (0 != coap_security_handler_continue_connecting(handle)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -235,17 +258,20 @@ bool test_coap_security_handler_send_message()
{
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
if( -1 != coap_security_handler_send_message(NULL, NULL, 0))
if (-1 != coap_security_handler_send_message(NULL, NULL, 0)) {
return false;
}
mbedtls_stub.expected_int = 6;
unsigned char cbuf[6];
if( 6 != coap_security_handler_send_message(handle, &cbuf, 6))
if (6 != coap_security_handler_send_message(handle, &cbuf, 6)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -255,16 +281,19 @@ bool test_thread_security_send_close_alert()
{
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
if( -1 != coap_security_send_close_alert(NULL))
if (-1 != coap_security_send_close_alert(NULL)) {
return false;
}
mbedtls_stub.expected_int = 0;
if( 0 != coap_security_send_close_alert(handle))
if (0 != coap_security_send_close_alert(handle)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -274,17 +303,20 @@ bool test_coap_security_handler_read()
{
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if (NULL == handle) {
return false;
}
if( -1 != coap_security_handler_read(NULL, NULL, 0))
if (-1 != coap_security_handler_read(NULL, NULL, 0)) {
return false;
}
mbedtls_stub.expected_int = 6;
unsigned char cbuf[6];
if( 6 != coap_security_handler_read(handle, &cbuf, 6))
if (6 != coap_security_handler_read(handle, &cbuf, 6)) {
return false;
}
coap_security_destroy(handle);
return true;

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_service_api)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};
@ -68,6 +66,11 @@ TEST(coap_service_api, test_coap_service_request_delete)
CHECK(test_coap_service_request_delete());
}
TEST(coap_service_api, test_coap_service_request_delete_by_service_id)
{
CHECK(test_coap_service_request_delete_by_service_id());
}
TEST(coap_service_api, test_coap_service_response_send)
{
CHECK(test_coap_service_response_send());

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
int main(int ac, char **av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

View File

@ -25,11 +25,12 @@
#include "net_interface.h"
#include "coap_service_api.c"
int sec_done_cb_test(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40]){
int sec_done_cb_test(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40])
{
return 2;
}
int sec_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len)
int sec_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw, uint8_t *pw_len)
{
return 0;
}
@ -46,40 +47,45 @@ int virtual_sock_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static
bool test_coap_service_initialize()
{
if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.handler_obj = NULL;
if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
coap_message_handler_stub.coap_ptr = NULL;
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.int_value = -1;
if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.int_value = 0;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
if( 2 != coap_service_initialize(3, 4, 0, NULL, NULL ))
if (2 != coap_service_initialize(3, 4, 0, NULL, NULL)) {
return false;
}
coap_service_delete(2);
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
}
@ -88,17 +94,18 @@ bool test_coap_service_delete()
{
coap_service_delete(1);
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
@ -107,24 +114,27 @@ bool test_coap_service_delete()
bool test_coap_service_virtual_socket_recv()
{
uint8_t buf[16];
if( -1 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0) )
if (-1 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
thread_conn_handler_stub.int_value = 5;
if( 5 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0) )
if (5 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0)) {
return false;
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
thread_conn_handler_stub.int_value = 0;
@ -134,23 +144,26 @@ bool test_coap_service_virtual_socket_recv()
bool test_coap_service_virtual_socket_set_cb()
{
if( -1 != coap_service_virtual_socket_set_cb(1, NULL) )
if (-1 != coap_service_virtual_socket_set_cb(1, NULL)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
if( 0 != coap_service_virtual_socket_set_cb(1, NULL) )
if (0 != coap_service_virtual_socket_set_cb(1, NULL)) {
return false;
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
@ -158,31 +171,36 @@ bool test_coap_service_virtual_socket_set_cb()
bool test_coap_service_register_uri()
{
if( -1 != coap_service_register_uri(1, "as", 1, &request_recv_cb))
if (-1 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
if( -2 != coap_service_register_uri(1, "as", 1, &request_recv_cb) )
if (-2 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
if( -2 != coap_service_register_uri(1, "as", 1, &request_recv_cb) )
if (-2 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_service_register_uri(1, "as", 1, &request_recv_cb) )
if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
@ -190,31 +208,36 @@ bool test_coap_service_register_uri()
bool test_coap_service_unregister_uri()
{
if( -1 != coap_service_unregister_uri(1, "as"))
if (-1 != coap_service_unregister_uri(1, "as")) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
thread_conn_handler_stub.int_value = 0;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_service_register_uri(1, "as", 1, &request_recv_cb) )
if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
if( -2 != coap_service_unregister_uri(1, "ts") )
if (-2 != coap_service_unregister_uri(1, "ts")) {
return false;
}
if( 0 != coap_service_unregister_uri(1, "as") )
if (0 != coap_service_unregister_uri(1, "as")) {
return false;
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
@ -224,15 +247,23 @@ bool test_coap_service_request_send()
{
uint8_t buf[16];
coap_message_handler_stub.uint16_value = 6;
if( 6 != coap_service_request_send(0,0,&buf,0,0,0,NULL, 0,NULL,0,NULL))
if (6 != coap_service_request_send(0, 0, &buf, 0, 0, 0, NULL, 0, NULL, 0, NULL)) {
return false;
}
return true;
}
bool test_coap_service_request_delete()
{
if( 0 != coap_service_request_delete(NULL,0))
if (0 != coap_service_request_delete(NULL, 0)) {
return false;
}
return true;
}
bool test_coap_service_request_delete_by_service_id()
{
coap_service_request_delete_by_service_id(0);
return true;
}
@ -240,29 +271,33 @@ bool test_coap_service_response_send()
{
uint8_t buf[16];
coap_message_handler_stub.int8_value = 6;
if( 6 != coap_service_response_send(0,0,NULL, 65, 0,NULL, 0))
if (6 != coap_service_response_send(0, 0, NULL, 65, 0, NULL, 0)) {
return false;
}
return true;
}
bool test_coap_callbacks()
{
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t));
memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t));
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(0))
if (0 != coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
void *handle = coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(5);
if( 0 == handle )
if (0 == handle) {
return false;
}
coap_message_handler_stub.coap_ptr->sn_coap_service_free(handle);
@ -273,34 +308,38 @@ bool test_coap_callbacks()
addr.addr_len = 2;
addr.port = 4;
addr.addr_ptr = &data;
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL))
if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL)) {
return false;
}
coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t));
memset(tr, 0, sizeof(coap_transaction_t));
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr))
if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) {
return false;
}
tr->service_id = 1;
thread_conn_handler_stub.int_value = -2;
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr))
if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr))
if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr)) {
return false;
}
free(tr->data_ptr);
free(tr);
coap_service_delete(1);
free( coap_message_handler_stub.coap_ptr );
free(coap_message_handler_stub.coap_ptr);
coap_message_handler_stub.coap_ptr = NULL;
coap_service_handle = NULL;
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
@ -309,13 +348,14 @@ bool test_coap_callbacks()
#define COAP_TICK_TIMER 0xf1 //MUST BE SAME AS IN coap_service_api.c
bool test_eventOS_callbacks()
{
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
if( eventOs_event_stub.event_ptr ){
if (eventOs_event_stub.event_ptr) {
arm_event_s event;
event.event_type = ARM_LIB_TASKLET_INIT_EVENT;
eventOs_event_stub.event_ptr(&event);
@ -326,7 +366,7 @@ bool test_eventOS_callbacks()
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
}
@ -334,65 +374,75 @@ bool test_eventOS_callbacks()
bool test_conn_handler_callbacks()
{
uint8_t buf[16];
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, COAP_SERVICE_OPTIONS_SECURE_BYPASS, &sec_start_cb, &sec_done_cb_test ))
return false;
if( thread_conn_handler_stub.send_to_sock_cb ){
thread_conn_handler_stub.bool_value = true;
coap_service_virtual_socket_set_cb(1, &virtual_sock_send_cb);
if( 2 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0))
return false;
thread_conn_handler_stub.bool_value = false;
if( -1 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0))
if (1 != coap_service_initialize(1, 2, COAP_SERVICE_OPTIONS_SECURE_BYPASS, &sec_start_cb, &sec_done_cb_test)) {
return false;
}
if( thread_conn_handler_stub.receive_from_sock_cb ){
coap_message_handler_stub.int16_value = 2;
if( -1 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, NULL, 0))
if (thread_conn_handler_stub.send_to_sock_cb) {
thread_conn_handler_stub.bool_value = true;
coap_service_virtual_socket_set_cb(1, &virtual_sock_send_cb);
if (2 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) {
return false;
}
thread_conn_handler_stub.bool_value = false;
if (-1 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) {
return false;
}
}
if (thread_conn_handler_stub.receive_from_sock_cb) {
coap_message_handler_stub.int16_value = 2;
if (-1 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, NULL, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
uint8_t * ptr = ns_dyn_mem_alloc(5);
uint8_t *ptr = ns_dyn_mem_alloc(5);
memset(ptr, 3, 5);
nsdynmemlib_stub.returnCounter = 1;
if( 2 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, ptr, 5))
if (2 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, ptr, 5)) {
return false;
}
ns_dyn_mem_free(ptr);
coap_message_handler_stub.int16_value = 0;
//This could be moved to own test function,
//but thread_conn_handler_stub.receive_from_sock_cb must be called successfully
if( coap_message_handler_stub.cb ){
if( -1 != coap_message_handler_stub.cb(1, NULL, NULL) )
if (coap_message_handler_stub.cb) {
if (-1 != coap_message_handler_stub.cb(1, NULL, NULL)) {
return false;
}
sn_coap_hdr_s * coap = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
sn_coap_hdr_s *coap = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(coap, 0, sizeof(sn_coap_hdr_s));
uint8_t uri[2] = "as";
coap->uri_path_ptr = &uri;
coap->uri_path_len=2;
coap->uri_path_len = 2;
if( -1 != coap_message_handler_stub.cb(1, coap, NULL) )
if (-1 != coap_message_handler_stub.cb(1, coap, NULL)) {
return false;
}
thread_conn_handler_stub.bool_value = true;
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_service_register_uri(1, "as", 1, &request_recv_cb) )
if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
if( -1 != coap_message_handler_stub.cb(1, coap, NULL) )
if (-1 != coap_message_handler_stub.cb(1, coap, NULL)) {
return false;
}
coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t));
memset(tr, 0, sizeof(coap_transaction_t));
if( 2 != coap_message_handler_stub.cb(1, coap, tr) )
if (2 != coap_message_handler_stub.cb(1, coap, tr)) {
return false;
}
free(tr);
tr = NULL;
@ -403,20 +453,22 @@ bool test_conn_handler_callbacks()
}
}
if(thread_conn_handler_stub.get_passwd_cb){
if (thread_conn_handler_stub.get_passwd_cb) {
coap_security_keys_t security_ptr;
memset(&security_ptr, 0, sizeof(coap_security_keys_t));
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.bool_value = true;
if( 0 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, &security_ptr))
return false;
free(security_ptr._key);
thread_conn_handler_stub.bool_value = false;
if( -1 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL))
if (0 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, &security_ptr)) {
return false;
}
free(security_ptr._key);
thread_conn_handler_stub.bool_value = false;
if (-1 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL)) {
return false;
}
}
if(thread_conn_handler_stub.sec_done_cb){
if (thread_conn_handler_stub.sec_done_cb) {
uint8_t block[40];
thread_conn_handler_stub.bool_value = true;
@ -437,7 +489,7 @@ bool test_conn_handler_callbacks()
}
coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj );
free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL;
return true;
@ -451,12 +503,13 @@ bool test_certificate_set()
}
/* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
/* Allocation fails */
if (-1 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) {
@ -485,12 +538,13 @@ bool test_handshake_timeout_set()
}
/* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
/* All OK */
nsdynmemlib_stub.returnCounter = 1;
@ -515,17 +569,18 @@ bool test_coap_duplcate_msg_buffer_set()
}
/* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t));
memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
ret = false;
}
/* All OK */
if(0 != coap_service_set_duplicate_message_buffer(0, 0)) {
if (0 != coap_service_set_duplicate_message_buffer(0, 0)) {
ret = false;
}
@ -554,22 +609,23 @@ bool test_coap_service_if_find_by_socket()
}
/* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t));
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.bool_value = 0;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
/* No matching service ID - return false */
if(0 != coap_service_id_find_by_socket(1)) {
if (0 != coap_service_id_find_by_socket(1)) {
return false;
}
thread_conn_handler_stub.bool_value = 1;
/* All OK */
if(1 != coap_service_id_find_by_socket(1)) {
if (1 != coap_service_id_find_by_socket(1)) {
return false;
}

View File

@ -39,6 +39,8 @@ bool test_coap_service_request_send();
bool test_coap_service_request_delete();
bool test_coap_service_request_delete_by_service_id();
bool test_coap_service_response_send();
bool test_coap_callbacks();

View File

@ -36,7 +36,7 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int),
int (*send_cb)(int8_t socket_id, uint8_t const address[static 16], uint16_t port, const void *, int),
int (*pw_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr),
void(*done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static KEY_BLOCK_LEN]) )
void(*done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static KEY_BLOCK_LEN]))
{
thread_conn_handler_stub.send_to_sock_cb = send_cb;
thread_conn_handler_stub.receive_from_sock_cb = recv_cb;
@ -45,11 +45,11 @@ coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id,
return thread_conn_handler_stub.handler_obj;
}
void connection_handler_destroy( coap_conn_handler_t *handler, bool multicast_group_leave)
void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave)
{
}
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port )
void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port)
{
}

View File

@ -22,7 +22,7 @@ coap_message_handler_stub_def coap_message_handler_stub;
coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *))
{
if(coap_message_handler_stub.coap_ptr){
if (coap_message_handler_stub.coap_ptr) {
coap_message_handler_stub.coap_ptr->sn_coap_service_malloc = used_malloc_func_ptr;
coap_message_handler_stub.coap_ptr->sn_coap_service_free = used_free_func_ptr;
coap_message_handler_stub.coap_ptr->sn_coap_tx_callback = used_tx_callback_ptr;
@ -39,6 +39,7 @@ void transactions_delete_all(uint8_t *address_ptr, uint16_t port)
{
}
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
{
return coap_message_handler_stub.int8_value;
@ -68,7 +69,7 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
return coap_message_handler_stub.uint16_value;
}
int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code,sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{
return coap_message_handler_stub.int8_value;
}
@ -78,13 +79,18 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
return 0;
}
int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_id)
{
return 0;
}
int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time)
{
return coap_message_handler_stub.int8_value;
}
int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code,
sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len)
sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{
return coap_message_handler_stub.int8_value;
}

View File

@ -56,7 +56,7 @@ void coap_security_destroy(coap_security_t *sec)
int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max)
{
sec->_is_started = true;
if( coap_security_handler_stub.counter >= 0){
if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
}
return coap_security_handler_stub.int_value;
@ -64,7 +64,7 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
int coap_security_handler_continue_connecting(coap_security_t *sec)
{
if( coap_security_handler_stub.counter >= 0){
if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
}
@ -74,7 +74,7 @@ int coap_security_handler_continue_connecting(coap_security_t *sec)
int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len)
{
if( coap_security_handler_stub.counter >= 0){
if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
}
return coap_security_handler_stub.int_value;
@ -82,15 +82,15 @@ int coap_security_handler_send_message(coap_security_t *sec, unsigned char *mess
int coap_security_send_close_alert(coap_security_t *sec)
{
if( coap_security_handler_stub.counter >= 0){
if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
}
return coap_security_handler_stub.int_value;
}
int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len)
int coap_security_handler_read(coap_security_t *sec, unsigned char *buffer, size_t len)
{
if( coap_security_handler_stub.counter >= 0){
if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
}
return coap_security_handler_stub.int_value;

View File

@ -20,7 +20,7 @@
#include <inttypes.h>
#include "coap_security_handler.h"
typedef struct tsh{
typedef struct tsh {
coap_security_t *sec_obj;
int int_value;
int counter;

View File

@ -67,7 +67,7 @@ uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uin
return 0;
}
int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len)
int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{
return 0;
}

View File

@ -20,157 +20,179 @@
mbedtls_stub_def mbedtls_stub;
//From ssl.h
int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl )
int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
{
if( mbedtls_stub.useCounter ){
if (mbedtls_stub.useCounter) {
if( mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE ||
mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO){
if (mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE ||
mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
ssl->state = MBEDTLS_SSL_HANDSHAKE_OVER;
if(mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO)
if (mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
return 0;
}
}
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
int mbedtls_ssl_close_notify( mbedtls_ssl_context *a )
int mbedtls_ssl_close_notify(mbedtls_ssl_context *a)
{
if( mbedtls_stub.useCounter ){
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
void mbedtls_ssl_init( mbedtls_ssl_context *a ){
void mbedtls_ssl_init(mbedtls_ssl_context *a)
{
}
void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor ){
}
void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor ){
}
void mbedtls_ssl_config_init( mbedtls_ssl_config *a ){
}
void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *a, uint32_t b, uint32_t c)
void mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major, int minor)
{
}
void mbedtls_ssl_free( mbedtls_ssl_context *a ){
void mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
{
}
int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *a,
void mbedtls_ssl_config_init(mbedtls_ssl_config *a)
{
}
void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *a, uint32_t b, uint32_t c)
{
}
void mbedtls_ssl_free(mbedtls_ssl_context *a)
{
}
int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *a,
mbedtls_x509_crt *b,
mbedtls_pk_context *c ){
if( mbedtls_stub.useCounter ){
mbedtls_pk_context *c)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *a, int c ){
void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *a, int c)
{
}
void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *a,
void mbedtls_ssl_conf_ca_chain(mbedtls_ssl_config *a,
mbedtls_x509_crt *b,
mbedtls_x509_crl *c ){
mbedtls_x509_crl *c)
{
}
int mbedtls_ssl_conf_psk( mbedtls_ssl_config *a,
int mbedtls_ssl_conf_psk(mbedtls_ssl_config *a,
const unsigned char *b, size_t c,
const unsigned char *d, size_t e ){
if( mbedtls_stub.useCounter ){
const unsigned char *d, size_t e)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
int mbedtls_ssl_config_defaults( mbedtls_ssl_config *a,
int b, int c, int d){
if( mbedtls_stub.useCounter ){
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *a,
int b, int c, int d)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
void mbedtls_ssl_conf_rng( mbedtls_ssl_config *a,
void mbedtls_ssl_conf_rng(mbedtls_ssl_config *a,
int (*f_rng)(void *, unsigned char *, size_t),
void *b ){
void *b)
{
}
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *a,
void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *a,
const int *b)
{
}
int mbedtls_ssl_setup( mbedtls_ssl_context *a,
const mbedtls_ssl_config *b ){
if( mbedtls_stub.useCounter ){
int mbedtls_ssl_setup(mbedtls_ssl_context *a,
const mbedtls_ssl_config *b)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl,
void *p_bio,
int (*f_send)(void *, const unsigned char *, size_t),
int (*f_recv)(void *, unsigned char *, size_t),
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) ){
if( p_bio != NULL ){
if( f_send )
f_send( p_bio, NULL, 0 );
if( f_recv )
f_recv( p_bio, NULL, 0 );
if( f_recv_timeout )
f_recv_timeout( p_bio, NULL, 0, 0 );
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t))
{
if (p_bio != NULL) {
if (f_send) {
f_send(p_bio, NULL, 0);
}
if (f_recv) {
f_recv(p_bio, NULL, 0);
}
if (f_recv_timeout) {
f_recv_timeout(p_bio, NULL, 0, 0);
}
}
}
void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *a,
void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *a,
void *ctx,
void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms),
int (*f_get_timer)(void *) ){
int (*f_get_timer)(void *))
{
f_set_timer(ctx, 1, 2);
f_get_timer(ctx);
if(mbedtls_stub.invalidate_timer){
if (mbedtls_stub.invalidate_timer) {
f_set_timer(ctx, 0, 0);
}
f_get_timer(ctx);
}
int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ){
if( mbedtls_stub.useCounter ){
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *a ){
uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *a)
{
return mbedtls_stub.uint32_value;
}
int mbedtls_ssl_read( mbedtls_ssl_context *a, unsigned char *b, size_t c){
if( mbedtls_stub.useCounter ){
int mbedtls_ssl_read(mbedtls_ssl_context *a, unsigned char *b, size_t c)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
int mbedtls_ssl_write( mbedtls_ssl_context *a, const unsigned char *b, size_t c ){
if( mbedtls_stub.useCounter ){
int mbedtls_ssl_write(mbedtls_ssl_context *a, const unsigned char *b, size_t c)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
@ -179,144 +201,157 @@ int mbedtls_ssl_write( mbedtls_ssl_context *a, const unsigned char *b, size_t c
//From crt_drbg.h
int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *a,
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *a,
int (*f_entropy)(void *, unsigned char *, size_t),
void *b,
const unsigned char *c,
size_t d ){
size_t d)
{
return mbedtls_stub.crt_expected_int;
}
void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *a ){
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *a)
{
}
void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *a ){
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *a)
{
}
int mbedtls_ctr_drbg_random_with_add( void *a,
int mbedtls_ctr_drbg_random_with_add(void *a,
unsigned char *b, size_t c,
const unsigned char *d, size_t e ){
const unsigned char *d, size_t e)
{
return mbedtls_stub.crt_expected_int;
}
int mbedtls_ctr_drbg_random( void *p_rng,
unsigned char *output, size_t output_len ){
int mbedtls_ctr_drbg_random(void *p_rng,
unsigned char *output, size_t output_len)
{
return mbedtls_stub.crt_expected_int;
}
//From x509_crt.h
void mbedtls_x509_crt_init( mbedtls_x509_crt *a ){
void mbedtls_x509_crt_init(mbedtls_x509_crt *a)
{
}
void mbedtls_x509_crt_free( mbedtls_x509_crt *a ){
void mbedtls_x509_crt_free(mbedtls_x509_crt *a)
{
}
int mbedtls_x509_crt_parse( mbedtls_x509_crt *a, const unsigned char *b, size_t c ){
if( mbedtls_stub.useCounter ){
int mbedtls_x509_crt_parse(mbedtls_x509_crt *a, const unsigned char *b, size_t c)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
//From entropy.h
void mbedtls_entropy_init( mbedtls_entropy_context *a ){
void mbedtls_entropy_init(mbedtls_entropy_context *a)
{
}
void mbedtls_entropy_free( mbedtls_entropy_context *ctx ){
void mbedtls_entropy_free(mbedtls_entropy_context *ctx)
{
}
int mbedtls_entropy_func( void *a, unsigned char *b, size_t c ){
if( mbedtls_stub.useCounter ){
int mbedtls_entropy_func(void *a, unsigned char *b, size_t c)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
int mbedtls_entropy_add_source( mbedtls_entropy_context *a,
int mbedtls_entropy_add_source(mbedtls_entropy_context *a,
mbedtls_entropy_f_source_ptr f_source, void *b,
size_t c, int d ){
size_t c, int d)
{
unsigned char buf[2];
size_t len;
f_source(NULL, buf, 1, &len);
if( mbedtls_stub.useCounter ){
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
//From pk.h
int mbedtls_pk_parse_key( mbedtls_pk_context *a,
int mbedtls_pk_parse_key(mbedtls_pk_context *a,
const unsigned char *b, size_t c,
const unsigned char *d, size_t e ){
if( mbedtls_stub.useCounter ){
const unsigned char *d, size_t e)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
void mbedtls_pk_init( mbedtls_pk_context *ctx )
void mbedtls_pk_init(mbedtls_pk_context *ctx)
{
}
void mbedtls_pk_free( mbedtls_pk_context *ctx )
void mbedtls_pk_free(mbedtls_pk_context *ctx)
{
}
void mbedtls_ssl_config_free( mbedtls_ssl_config *a)
void mbedtls_ssl_config_free(mbedtls_ssl_config *a)
{
}
int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
const unsigned char *pw,
size_t pw_len )
size_t pw_len)
{
if( mbedtls_stub.useCounter ){
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
}
void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf,
void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf,
mbedtls_ssl_cookie_write_t *f_cookie_write,
mbedtls_ssl_cookie_check_t *f_cookie_check,
void *p_cookie )
void *p_cookie)
{
if( mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0 ){
if (mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0) {
f_cookie_check(mbedtls_stub.cookie_obj, &mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0);
}
if( mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0 ){
if (mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0) {
unsigned char out[16];
unsigned char *ptr = &out;
f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr+mbedtls_stub.cookie_len, NULL, 0);
f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr + mbedtls_stub.cookie_len, NULL, 0);
}
}
void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf,
void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config *conf,
mbedtls_ssl_export_keys_t *f_export_keys,
void *p_export_keys )
void *p_export_keys)
{
if( f_export_keys && p_export_keys){
if (f_export_keys && p_export_keys) {
unsigned char value[40];
memset(&value, 1, 40);
f_export_keys(p_export_keys, &value, "", 0, 0,0); //failure case
f_export_keys(p_export_keys, &value, "", 0, 0, 0); //failure case
f_export_keys(p_export_keys, &value, "", 0, 20,0); //success case
f_export_keys(p_export_keys, &value, "", 0, 20, 0); //success case
}
}
int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl )
int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
{
if( mbedtls_stub.useCounter ){
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;

View File

@ -37,27 +37,21 @@ void ns_dyn_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(
void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
return(nsdynmemlib_stub.expectedPointer);
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
return(nsdynmemlib_stub.expectedPointer);
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}

View File

@ -25,7 +25,7 @@ extern "C" {
typedef struct {
uint8_t returnCounter;
void* expectedPointer;
void *expectedPointer;
} nsdynmemlib_stub_data_t;
extern nsdynmemlib_stub_data_t nsdynmemlib_stub;

View File

@ -48,8 +48,8 @@ uint32_t randLIB_get_32bit(void)
void *randLIB_get_n_bytes_random(void *data_ptr, uint8_t count)
{
if(data_ptr && count > 0){
*((int*)data_ptr) = counter++%255;
if (data_ptr && count > 0) {
*((int *)data_ptr) = counter++ % 255;
}
return data_ptr;
}

View File

@ -49,7 +49,7 @@ struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), vo
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *),
int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *param))
{
if( sn_coap_protocol_stub.expectedCoap ){
if (sn_coap_protocol_stub.expectedCoap) {
sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_free = used_free_func_ptr;
sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_malloc = used_malloc_func_ptr;
sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback = used_rx_callback_ptr;

View File

@ -22,7 +22,7 @@ const uint8_t ns_in6addr_any[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
int8_t socket_raw_open(void (*passed_fptr)(void *))
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -31,7 +31,7 @@ int8_t socket_raw_open(void (*passed_fptr)(void *))
int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(void *))
{
socket_api_stub.recv_cb = passed_fptr;
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -40,7 +40,7 @@ int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(vo
int8_t socket_close(int8_t socket)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -48,7 +48,7 @@ int8_t socket_close(int8_t socket)
}
int8_t socket_listen(int8_t socket, uint8_t backlog)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -56,7 +56,7 @@ int8_t socket_listen(int8_t socket, uint8_t backlog)
}
int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_take_src_number)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -64,7 +64,7 @@ int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_tak
}
int8_t socket_bind(int8_t socket, const ns_address_t *address)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -73,11 +73,11 @@ int8_t socket_bind(int8_t socket, const ns_address_t *address)
int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length)
{
if( address ){
if (address) {
memset(&address->address, 0, 16);
address->identifier = 0;
}
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -85,7 +85,7 @@ int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint1
}
int8_t socket_getpeername(int8_t socket, ns_address_t *address)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -93,7 +93,7 @@ int8_t socket_getpeername(int8_t socket, ns_address_t *address)
}
int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const void *opt_value, uint16_t opt_len)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -101,7 +101,7 @@ int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const v
}
int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *opt_value, uint16_t *opt_len)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}
@ -109,7 +109,7 @@ int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *o
}
int16_t socket_sendmsg(int8_t socket, const ns_msghdr_t *msg, int flags)
{
if( socket_api_stub.counter >= 0){
if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--];
}

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
#include "eventOS_event_timer.h"
#include "eventOS_event_timer.h"
// Timeout structure, already typedefed to timeout_t
struct timeout_entry_t {

View File

@ -32,7 +32,10 @@ public:
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_connection_status_t get_connection_status() const;
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
void get_mac_address(uint8_t *buf) const
{
interface_phy.get_mac_address(buf);
}
/**
* \brief Callback from C-layer
@ -40,15 +43,24 @@ public:
* */
void network_handler(mesh_connection_status_t status);
int8_t get_interface_id() const { return interface_id; }
int8_t get_driver_id() const { return _device_id; }
int8_t get_interface_id() const
{
return interface_id;
}
int8_t get_driver_id() const
{
return _device_id;
}
private:
NanostackPhy &interface_phy;
protected:
Interface(NanostackPhy &phy);
virtual nsapi_error_t register_phy();
NanostackPhy &get_phy() const { return interface_phy; }
NanostackPhy &get_phy() const
{
return interface_phy;
}
int8_t interface_id;
int8_t _device_id;
rtos::Semaphore connect_semaphore;
@ -62,7 +74,10 @@ protected:
class Nanostack::MeshInterface : public Nanostack::Interface {
protected:
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
NanostackRfPhy &get_phy() const
{
return static_cast<NanostackRfPhy &>(Interface::get_phy());
}
};
@ -116,12 +131,18 @@ public:
/** Get the interface ID
/return Interface identifier
*/
int8_t get_interface_id() const { return _interface->get_interface_id(); }
int8_t get_interface_id() const
{
return _interface->get_interface_id();
}
protected:
InterfaceNanostack();
virtual Nanostack *get_stack(void);
Nanostack::Interface *get_interface() const { return _interface; }
Nanostack::Interface *get_interface() const
{
return _interface;
}
virtual nsapi_error_t do_initialize() = 0;
Nanostack::Interface *_interface;
@ -147,7 +168,10 @@ public:
protected:
MeshInterfaceNanostack() : _phy(NULL) { }
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
Nanostack::MeshInterface *get_interface() const
{
return static_cast<Nanostack::MeshInterface *>(_interface);
}
NanostackRfPhy *_phy;
};

View File

@ -35,7 +35,10 @@ private:
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
nsapi_error_t initialize();
protected:
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
NanostackEthernetPhy &get_phy() const
{
return static_cast<NanostackEthernetPhy &>(Interface::get_phy());
}
};
/** Ethernet interface for Nanostack.
@ -50,7 +53,10 @@ public:
nsapi_error_t initialize(NanostackEthernetPhy *phy);
protected:
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
Nanostack::EthernetInterface *get_interface() const
{
return static_cast<Nanostack::EthernetInterface *>(_interface);
}
virtual nsapi_error_t do_initialize();
};

View File

@ -8,8 +8,7 @@
#include "ns_trace.h"
#define TRACE_GROUP "nslp"
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface
{
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
@ -29,7 +28,7 @@ private:
Nanostack::LoWPANNDInterface *LoWPANNDInterface::get_interface() const
{
return static_cast<Nanostack::LoWPANNDInterface*>(_interface);
return static_cast<Nanostack::LoWPANNDInterface *>(_interface);
}
nsapi_error_t LoWPANNDInterface::do_initialize()

View File

@ -134,7 +134,7 @@ void Nanostack::Interface::network_handler(mesh_connection_status_t status)
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
_connect_status = NSAPI_STATUS_GLOBAL_UP;
}
} else if (status == MESH_CONNECTED_LOCAL ) {
} else if (status == MESH_CONNECTED_LOCAL) {
_connect_status = NSAPI_STATUS_LOCAL_UP;
} else if (status == MESH_CONNECTED_GLOBAL) {
_connect_status = NSAPI_STATUS_GLOBAL_UP;

View File

@ -8,16 +8,15 @@
#include "arm_hal_phy.h"
#include "EMAC.h"
class EMACPhy : public NanostackEthernetPhy
{
class EMACPhy : public NanostackEthernetPhy {
public:
EMACPhy(NanostackMemoryManager &mem, EMAC &m);
virtual int8_t phy_register();
virtual void get_mac_address(uint8_t *mac);
virtual void set_mac_address(uint8_t *mac);
int8_t address_write(phy_address_type_e , uint8_t *);
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow);
int8_t address_write(phy_address_type_e, uint8_t *);
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
void emac_phy_rx(emac_mem_buf_t *mem);
@ -34,23 +33,23 @@ static EMACPhy *single_phy;
extern "C"
{
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
{
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
{
return single_phy->address_write(address_type, address_ptr);
}
}
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
{
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
{
return -1;
}
}
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
{
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
{
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
}
}
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
{
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
{
/* Same default address logic as lwIP glue uses */
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
mac_addr[0] = MBED_MAC_ADDR_0;
@ -65,18 +64,18 @@ EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), em
/* We have a default MAC address, so do don't force them to supply one */
/* They may or may not update hwaddr with their address */
emac.get_hwaddr(mac_addr);
}
}
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
{
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
{
const uint8_t *ptr = NULL;
uint8_t *tmpbuf = NULL;
uint32_t total_len;
if (memory_manager.get_next(mem) == NULL) {
// Easy contiguous case
ptr = static_cast<const uint8_t*>(memory_manager.get_ptr(mem));
ptr = static_cast<const uint8_t *>(memory_manager.get_ptr(mem));
total_len = memory_manager.get_len(mem);
} else {
// Nanostack can't accept chunked data - make temporary contiguous copy
@ -92,7 +91,7 @@ void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
}
ns_dyn_mem_free(tmpbuf);
memory_manager.free(mem);
}
}
} // extern "C"
@ -106,7 +105,7 @@ int8_t EMACPhy::address_write(phy_address_type_e address_type, uint8_t *address_
return 0;
}
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
{
emac_mem_buf_t *mem = memory_manager.alloc_pool(data_len, 0);
if (!mem) {
@ -126,7 +125,7 @@ int8_t EMACPhy::phy_register()
phy.PHY_MAC = mac_addr;
phy.address_write = emac_phy_address_write;
phy.driver_description = const_cast<char*>("ETH");
phy.driver_description = const_cast<char *>("ETH");
phy.link_type = PHY_LINK_ETHERNET_TYPE;
phy.phy_MTU = 0;
phy.phy_header_length = 0;
@ -155,7 +154,7 @@ int8_t EMACPhy::phy_register()
device_id = arm_net_phy_register(&phy);
// driver_readiness_status_callback = driver_status_cb;
if (device_id < 0){
if (device_id < 0) {
//tr_error("Ethernet Driver failed to register with Stack. RetCode=%i", eth_driver_enabled);
//driver_readiness_status_callback(0, eth_interface_id);
emac.power_down();
@ -188,7 +187,7 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Nan
}
if (mac_addr) {
single_phy->set_mac_address(const_cast<uint8_t*>(mac_addr));
single_phy->set_mac_address(const_cast<uint8_t *>(mac_addr));
}
Nanostack::EthernetInterface *interface;

View File

@ -44,7 +44,7 @@ nsapi_error_t NanostackEthernetInterface::initialize(NanostackEthernetPhy *phy)
}
return get_interface()->initialize();
}
}
nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,

View File

@ -19,8 +19,7 @@
#include "mbed_assert.h"
#include "NanostackMemoryManager.h"
struct ns_stack_mem_t
{
struct ns_stack_mem_t {
ns_stack_mem_t *next;
void *payload;
uint32_t len;

View File

@ -7,8 +7,7 @@
#include "ns_trace.h"
#define TRACE_GROUP "nsth"
class Nanostack::ThreadInterface : public Nanostack::MeshInterface
{
class Nanostack::ThreadInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
@ -73,7 +72,7 @@ private:
Nanostack::ThreadInterface *ThreadInterface::get_interface() const
{
return static_cast<Nanostack::ThreadInterface*>(_interface);
return static_cast<Nanostack::ThreadInterface *>(_interface);
}
nsapi_error_t ThreadInterface::do_initialize()

View File

@ -197,9 +197,10 @@ static void enet_tasklet_poll_network_status(void *param)
}
} else {
if (tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
enet_tasklet_network_state_changed(MESH_DISCONNECTED);
}
}
}
/*

View File

@ -54,7 +54,7 @@ void mesh_system_init(void)
{
if (mesh_initialized == false) {
#if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE+1);
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE + 1);
MBED_ASSERT(app_stack_heap);
#endif
ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE,

View File

@ -272,7 +272,7 @@ void nd_tasklet_configure_and_connect_to_network(void)
MBED_CONF_MBED_MESH_API_6LOWPAN_ND_PANID_FILTER);
// Enable MPL by default
const uint8_t all_mpl_forwarders[16] = {0xff, 0x03, [15]=0xfc};
const uint8_t all_mpl_forwarders[16] = {0xff, 0x03, [15] = 0xfc};
multicast_mpl_domain_subscribe(tasklet_data_ptr->network_interface_id,
all_mpl_forwarders,
MULTICAST_MPL_SEED_ID_DEFAULT,
@ -327,7 +327,7 @@ void nd_tasklet_trace_bootstrap_info()
tr_error("MAC Address read fail\n");
} else {
uint8_t temp[2];
common_write_16_bit(app_link_address_info.mac_short,temp);
common_write_16_bit(app_link_address_info.mac_short, temp);
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
common_write_16_bit(app_link_address_info.PANId, temp);
tr_debug("PAN ID: %s", trace_array(temp, 2));

View File

@ -246,12 +246,14 @@ void thread_tasklet_poll_network_status(void *param)
}
} else {
if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
thread_tasklet_network_state_changed(MESH_DISCONNECTED);
}
}
}
void read_link_configuration() {
void read_link_configuration()
{
thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID;
TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId);
@ -300,13 +302,12 @@ void read_link_configuration() {
void thread_tasklet_configure_and_connect_to_network(void)
{
int8_t status;
link_configuration_s* temp_link_config=NULL;
link_configuration_s *temp_link_config = NULL;
if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) {
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST;
}
else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
} else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST;
} else {
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
@ -325,7 +326,7 @@ void thread_tasklet_configure_and_connect_to_network(void)
// PSKd
const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD;
if(device_configuration.PSKd_len==0) {
if (device_configuration.PSKd_len == 0) {
int ret = thread_tasklet_device_pskd_set(PSKd);
MBED_ASSERT(!ret);
}
@ -382,7 +383,7 @@ void thread_tasklet_trace_bootstrap_info()
tr_error("MAC Address read fail\n");
} else {
uint8_t temp[2];
common_write_16_bit(app_link_address_info.mac_short,temp);
common_write_16_bit(app_link_address_info.mac_short, temp);
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
common_write_16_bit(app_link_address_info.PANId, temp);
tr_debug("PAN ID: %s", trace_array(temp, 2));
@ -486,16 +487,16 @@ void thread_tasklet_device_eui64_get(uint8_t *eui64)
uint8_t thread_tasklet_device_pskd_set(const char *pskd)
{
int len = strlen(pskd);
if(len < 6 || len > 32) {
if (len < 6 || len > 32) {
return MESH_ERROR_PARAM;
}
char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd)+1);
char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd) + 1);
if (!dyn_buf) {
return MESH_ERROR_MEMORY;
}
strcpy(dyn_buf, pskd);
ns_dyn_mem_free(device_configuration.PSKd_ptr);
device_configuration.PSKd_ptr = (uint8_t*)dyn_buf;
device_configuration.PSKd_ptr = (uint8_t *)dyn_buf;
device_configuration.PSKd_len = strlen(pskd);
return 0;
}

View File

@ -36,8 +36,7 @@ static const fhss_api_t *fhss_active_handle = NULL;
static EventQueue *equeue;
#endif
struct fhss_timeout_s
{
struct fhss_timeout_s {
void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t);
uint32_t start_time;
uint32_t stop_time;

View File

@ -94,7 +94,7 @@ uint16_t platform_timer_get_remaining_slots(void)
{
uint32_t elapsed = timer->read_us();
if (elapsed < due) {
return (uint16_t) ((due - elapsed) / 50);
return (uint16_t)((due - elapsed) / 50);
} else {
return 0;
}

Some files were not shown because too many files have changed in this diff Show More