Merge pull request #8591 from 0xc0170/fix_coding_style_features

features: fix coding style
pull/8697/head
Cruz Monrreal 2018-11-09 09:40:56 -06:00 committed by GitHub
commit 9d95d46d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
124 changed files with 1494 additions and 1385 deletions

View File

@ -3,17 +3,22 @@ cmsis
features/cryptocell
features/mbedtls
features/lwipstack/lwip
features/lwipstack/lwip-sys
rtos/TARGET_CORTEX/rtx4
features/storage/filesystem/littlefs/littlefs/
features/storage/filesystem/fat/ChaN
features/storage/FEATURE_STORAGE
features/frameworks
features/FEATURE_BLE/targets
features/FEATURE_BLE
features/unsupported/
features/netsocket/emac-drivers
hal/storage_abstraction
FEATURE_NANOSTACK/coap-service
FEATURE_NANOSTACK/sal-stack-nanostack
TESTS/mbed_hal/trng/pithy
features/nanostack/coap-service
features/nanostack/sal-stack-nanostack
rtos/TARGET_CORTEX/rtx5
TESTS/mbed_hal/trng/pithy
targets
components/802.15.4_RF
components/wifi
tools

View File

@ -53,7 +53,7 @@ static void minimum_data_test()
}
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(30, "default_auto");
return greentea_test_setup_handler(number_of_cases);
@ -66,6 +66,7 @@ Case cases[] = {
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -31,7 +31,7 @@ void wifi_connect(void)
{
WiFiInterface *wifi = get_interface();
char ssid[SSID_MAX_LEN+1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;
char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(ssid, NULL));
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect());
@ -42,7 +42,7 @@ void wifi_connect(void)
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
// Driver is expected to cache the credentials
memset(ssid, 0, SSID_MAX_LEN+1);
memset(ssid, 0, SSID_MAX_LEN + 1);
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect());
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());

View File

@ -27,7 +27,7 @@ public:
phy_params.adr_ack_delay = 1;
}
virtual ~my_LoRaPHY()
virtual ~my_LoRaPHY()
{
}
@ -40,19 +40,19 @@ public:
class my_radio : public LoRaRadio {
public:
virtual void init_radio(radio_events_t *events)
virtual void init_radio(radio_events_t *events)
{
};
virtual void radio_reset()
virtual void radio_reset()
{
};
virtual void sleep(void)
virtual void sleep(void)
{
};
virtual void standby(void)
virtual void standby(void)
{
};
@ -62,7 +62,7 @@ public:
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous)
bool iq_inverted, bool rx_continuous)
{
};
@ -70,23 +70,23 @@ public:
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout)
uint8_t hop_period, bool iq_inverted, uint32_t timeout)
{
};
virtual void send(uint8_t *buffer, uint8_t size)
virtual void send(uint8_t *buffer, uint8_t size)
{
};
virtual void receive(void)
virtual void receive(void)
{
};
virtual void set_channel(uint32_t freq)
virtual void set_channel(uint32_t freq)
{
};
virtual uint32_t random(void)
virtual uint32_t random(void)
{
};
@ -95,15 +95,15 @@ public:
return uint8_value;
};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max)
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max)
{
};
virtual void set_public_network(bool enable)
virtual void set_public_network(bool enable)
{
};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
};
@ -115,7 +115,7 @@ public:
return bool_value;
};
virtual void start_cad(void)
virtual void start_cad(void)
{
};
@ -124,15 +124,15 @@ public:
return bool_value;
};
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time)
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time)
{
};
virtual void lock(void)
virtual void lock(void)
{
};
virtual void unlock(void)
virtual void unlock(void)
{
};
@ -422,10 +422,10 @@ TEST_F(Test_LoRaPHY, compute_rx_win_params)
list[0] = 125000;
object->get_phy_params().bandwidths.table = list;
uint8_t list2[1];
list2[0]= 12;
list2[0] = 12;
object->get_phy_params().datarates.table = &list2;
channel_params_t ch_lst[16];
memset(ch_lst, 0, sizeof(channel_params_t)*16);
memset(ch_lst, 0, sizeof(channel_params_t) * 16);
ch_lst[0].band = 0;
ch_lst[0].dr_range.fields.min = DR_0;
ch_lst[0].dr_range.fields.max = DR_5;
@ -513,7 +513,7 @@ TEST_F(Test_LoRaPHY, link_ADR_request)
object->get_phy_params().max_channel_cnt = 16;
channel_params_t li[16];
memset(li, 0, sizeof(channel_params_t)*16);
memset(li, 0, sizeof(channel_params_t) * 16);
object->get_phy_params().channels.channel_list = li;
li[0].frequency = 0;
li[1].frequency = 5;
@ -673,7 +673,7 @@ TEST_F(Test_LoRaPHY, set_next_channel)
ch = 5;
t1 = 16;
t2 = 32;
memset(b, 0, sizeof(band_t)*4);
memset(b, 0, sizeof(band_t) * 4);
object->get_phy_params().bands.size = 2;
object->get_phy_params().bands.table = &b;
b[0].off_time = 0;
@ -767,7 +767,7 @@ TEST_F(Test_LoRaPHY, set_tx_cont_mode)
cw_mode_params_t p;
p.max_eirp = 0;
p.channel=0;
p.channel = 0;
p.tx_power = -1;
p.datarate = 0;
p.antenna_gain = 1;

View File

@ -44,9 +44,9 @@ public:
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous)
{
{
};
};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,

View File

@ -35,7 +35,8 @@ using namespace mbed;
// Ticker operations
#if MBED_CONF_RTOS_PRESENT
unsigned equeue_tick() {
unsigned equeue_tick()
{
return osKernelGetTickCount();
}
@ -55,20 +56,22 @@ unsigned equeue_tick() {
static bool equeue_tick_inited = false;
static volatile unsigned equeue_minutes = 0;
static unsigned equeue_timer[
(sizeof(ALIAS_TIMER)+sizeof(unsigned)-1)/sizeof(unsigned)];
(sizeof(ALIAS_TIMER) + sizeof(unsigned) - 1) / sizeof(unsigned)];
static unsigned equeue_ticker[
(sizeof(ALIAS_TICKER)+sizeof(unsigned)-1)/sizeof(unsigned)];
(sizeof(ALIAS_TICKER) + sizeof(unsigned) - 1) / sizeof(unsigned)];
static void equeue_tick_update() {
equeue_minutes += reinterpret_cast<ALIAS_TIMER*>(equeue_timer)->read_ms();
reinterpret_cast<ALIAS_TIMER*>(equeue_timer)->reset();
static void equeue_tick_update()
{
equeue_minutes += reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->read_ms();
reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->reset();
}
static void equeue_tick_init() {
static void equeue_tick_init()
{
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
"The equeue_timer buffer must fit the class Timer");
"The equeue_timer buffer must fit the class Timer");
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
"The equeue_ticker buffer must fit the class Ticker");
"The equeue_ticker buffer must fit the class Ticker");
ALIAS_TIMER *timer = new (equeue_timer) ALIAS_TIMER;
ALIAS_TICKER *ticker = new (equeue_ticker) ALIAS_TICKER;
@ -79,7 +82,8 @@ static void equeue_tick_init() {
equeue_tick_inited = true;
}
unsigned equeue_tick() {
unsigned equeue_tick()
{
if (!equeue_tick_inited) {
equeue_tick_init();
}
@ -89,7 +93,7 @@ unsigned equeue_tick() {
do {
minutes = equeue_minutes;
ms = reinterpret_cast<ALIAS_TIMER*>(equeue_timer)->read_ms();
ms = reinterpret_cast<ALIAS_TIMER *>(equeue_timer)->read_ms();
} while (minutes != equeue_minutes);
return minutes + ms;
@ -98,14 +102,19 @@ unsigned equeue_tick() {
#endif
// Mutex operations
int equeue_mutex_create(equeue_mutex_t *m) { return 0; }
int equeue_mutex_create(equeue_mutex_t *m)
{
return 0;
}
void equeue_mutex_destroy(equeue_mutex_t *m) { }
void equeue_mutex_lock(equeue_mutex_t *m) {
void equeue_mutex_lock(equeue_mutex_t *m)
{
core_util_critical_section_enter();
}
void equeue_mutex_unlock(equeue_mutex_t *m) {
void equeue_mutex_unlock(equeue_mutex_t *m)
{
core_util_critical_section_exit();
}
@ -113,7 +122,8 @@ void equeue_mutex_unlock(equeue_mutex_t *m) {
// Semaphore operations
#ifdef MBED_CONF_RTOS_PRESENT
int equeue_sema_create(equeue_sema_t *s) {
int equeue_sema_create(equeue_sema_t *s)
{
osEventFlagsAttr_t attr;
memset(&attr, 0, sizeof(attr));
attr.cb_mem = &s->mem;
@ -123,15 +133,18 @@ int equeue_sema_create(equeue_sema_t *s) {
return !s->id ? -1 : 0;
}
void equeue_sema_destroy(equeue_sema_t *s) {
void equeue_sema_destroy(equeue_sema_t *s)
{
osEventFlagsDelete(s->id);
}
void equeue_sema_signal(equeue_sema_t *s) {
void equeue_sema_signal(equeue_sema_t *s)
{
osEventFlagsSet(s->id, 1);
}
bool equeue_sema_wait(equeue_sema_t *s, int ms) {
bool equeue_sema_wait(equeue_sema_t *s, int ms)
{
if (ms < 0) {
ms = osWaitForever;
}
@ -142,29 +155,34 @@ bool equeue_sema_wait(equeue_sema_t *s, int ms) {
#else
// Semaphore operations
int equeue_sema_create(equeue_sema_t *s) {
int equeue_sema_create(equeue_sema_t *s)
{
*s = false;
return 0;
}
void equeue_sema_destroy(equeue_sema_t *s) {
void equeue_sema_destroy(equeue_sema_t *s)
{
}
void equeue_sema_signal(equeue_sema_t *s) {
void equeue_sema_signal(equeue_sema_t *s)
{
*s = 1;
}
static void equeue_sema_timeout(equeue_sema_t *s) {
static void equeue_sema_timeout(equeue_sema_t *s)
{
*s = -1;
}
bool equeue_sema_wait(equeue_sema_t *s, int ms) {
bool equeue_sema_wait(equeue_sema_t *s, int ms)
{
int signal = 0;
ALIAS_TIMEOUT timeout;
if (ms == 0) {
return false;
} else if (ms > 0) {
timeout.attach_us(callback(equeue_sema_timeout, s), (us_timestamp_t)ms*1000);
timeout.attach_us(callback(equeue_sema_timeout, s), (us_timestamp_t)ms * 1000);
}
core_util_critical_section_enter();

View File

@ -84,8 +84,8 @@ static void test_information_interface()
TEST_ASSERT(info->get_model(buf, kbuf_size) == NSAPI_ERROR_OK);
TEST_ASSERT(info->get_revision(buf, kbuf_size) == NSAPI_ERROR_OK);
TEST_ASSERT((info->get_serial_number(buf, kbuf_size, CellularInformation::SN) == NSAPI_ERROR_OK) ||
((((AT_CellularInformation *)info)->get_device_error().errType == 3) && // 3 == CME error from the modem
(((AT_CellularInformation *)info)->get_device_error().errCode == 4))); // 4 == "operation not supported"
((((AT_CellularInformation *)info)->get_device_error().errType == 3) && // 3 == CME error from the modem
(((AT_CellularInformation *)info)->get_device_error().errCode == 4))); // 4 == "operation not supported"
nsapi_error_t err = info->get_serial_number(buf, kbuf_size, CellularInformation::IMEI);
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);

View File

@ -223,7 +223,7 @@ static void test_credentials()
static void test_other()
{
const char* devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
TEST_ASSERT(nw->get_3gpp_error() == 0);
CellularNetwork::RateControlExceptionReports reports;
@ -244,8 +244,8 @@ static void test_other()
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR || err == NSAPI_ERROR_PARAMETER);
if (err == NSAPI_ERROR_DEVICE_ERROR) {
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "TELIT_HE910") != 0 && strcmp(devi, "SARA4_PPP") != 0) { // QUECTEL_BG96 does not give any specific reason for device error
TEST_ASSERT(((AT_CellularNetwork *)nw)->get_device_error().errCode == 100 && // 100 == unknown command for modem
((AT_CellularNetwork *)nw)->get_device_error().errType == 3); // 3 == CME error from the modem
TEST_ASSERT(((AT_CellularNetwork *)nw)->get_device_error().errCode == 100 && // 100 == unknown command for modem
((AT_CellularNetwork *)nw)->get_device_error().errType == 3); // 3 == CME error from the modem
}
} else if (err == NSAPI_ERROR_PARAMETER) {
TEST_ASSERT(uplinkRate == -1);
@ -277,8 +277,8 @@ static void test_other()
if (err == NSAPI_ERROR_DEVICE_ERROR) {
if (strcmp(devi, "TELIT_HE910") != 0) { // TELIT_HE910 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
}
} else {
// should have some values, only not optional are apn and bearer id
@ -292,8 +292,8 @@ static void test_other()
if (err == NSAPI_ERROR_DEVICE_ERROR) {
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "TELIT_HE910") != 0) {// QUECTEL_BG96 does not give any specific reason for device error
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
}
} else {
// we should have some values which are not optional
@ -306,9 +306,9 @@ static void test_other()
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
if (err == NSAPI_ERROR_DEVICE_ERROR) {
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
} else {
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
} else {
// test for values
TEST_ASSERT(rssi >= 0);
TEST_ASSERT(ber >= 0);
@ -339,8 +339,8 @@ static void test_other()
if (err == NSAPI_ERROR_DEVICE_ERROR) {
// if device error then we must check was that really device error or that modem/network does not support the commands
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 4) || // 4 == NOT SUPPORTED BY THE MODEM
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 4) || // 4 == NOT SUPPORTED BY THE MODEM
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
} else {
CellularNetwork::operator_names_t *opn = op_names.get_head();
TEST_ASSERT(strlen(opn->numeric) > 0);
@ -358,8 +358,8 @@ static void test_other()
// if device error then we must check was that really device error or that modem/network does not support the commands
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) {
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
}
} else {
TEST_ASSERT(supported_opt != CellularNetwork::SUPPORTED_UE_OPT_MAX);
@ -372,8 +372,8 @@ static void test_other()
// if device error then we must check was that really device error or that modem/network does not support the commands
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) {
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
}
}
}

View File

@ -73,7 +73,7 @@ static void wait_for_power(CellularPower *pwr)
static void test_power_interface()
{
const char* devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
cellular_device = new CELLULAR_DEVICE(queue);
cellular_device->set_timeout(5000);
CellularPower *pwr = cellular_device->open_power(&cellular_serial);
@ -89,12 +89,12 @@ static void test_power_interface()
TEST_ASSERT(err == NSAPI_ERROR_OK);
wait_for_power(pwr);
err = pwr->opt_power_save_mode(0,0);
err = pwr->opt_power_save_mode(0, 0);
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
if (err == NSAPI_ERROR_DEVICE_ERROR) {
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0)) { // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
TEST_ASSERT(((AT_CellularPower*)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem
((AT_CellularPower*)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
TEST_ASSERT(((AT_CellularPower *)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem
((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
}
}
@ -102,8 +102,8 @@ static void test_power_interface()
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
if (err == NSAPI_ERROR_DEVICE_ERROR) {
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0)) { // TELIT_HE910 and QUECTEL_BG96 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
TEST_ASSERT(((AT_CellularPower*)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem
((AT_CellularPower*)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
TEST_ASSERT(((AT_CellularPower *)pwr)->get_device_error().errCode == 100 && // 100 == unknown command for modem
((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
}
}

View File

@ -52,7 +52,7 @@ static EventQueue queue(8 * EVENTS_EVENT_SIZE);
static rtos::Semaphore network_semaphore(0);
static CellularConnectionFSM *cellularConnectionFSM;
static CellularConnectionFSM::CellularState cellular_target_state;
static CellularSMS* sms;
static CellularSMS *sms;
static char service_center_address[SMS_MAX_PHONE_NUMBER_SIZE];
static int service_address_type;
@ -199,7 +199,7 @@ static void test_get_sms()
wait(7);
TEST_ASSERT(sms->get_sms(buf, buf_len, phone_num, SMS_MAX_PHONE_NUMBER_SIZE, time_stamp, SMS_MAX_TIME_STAMP_SIZE, &buf_size) == buf_len-1);
TEST_ASSERT(sms->get_sms(buf, buf_len, phone_num, SMS_MAX_PHONE_NUMBER_SIZE, time_stamp, SMS_MAX_TIME_STAMP_SIZE, &buf_size) == buf_len - 1);
TEST_ASSERT(strcmp(phone_num, MBED_CONF_APP_CELLULAR_PHONE_NUMBER) == 0);
TEST_ASSERT(strcmp(buf, TEST_MESSAGE) == 0);
TEST_ASSERT(buf_size == 0);

View File

@ -537,15 +537,15 @@ public:
*/
virtual nsapi_error_t get_registration_params(registration_params_t &reg_params) = 0;
/** Gets the network registration parameters based on required registration type:
* status, access technology, cell_id, lac, active_time, periodic_tau.
*
* @param type see RegistrationType values
* @param reg_params see registration_params_t
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if the modem does not support RegistrationType
* NSAPI_ERROR_DEVICE_ERROR on failure
*/
/** Gets the network registration parameters based on required registration type:
* status, access technology, cell_id, lac, active_time, periodic_tau.
*
* @param type see RegistrationType values
* @param reg_params see registration_params_t
* @return NSAPI_ERROR_OK on success
* NSAPI_ERROR_UNSUPPORTED if the modem does not support RegistrationType
* NSAPI_ERROR_DEVICE_ERROR on failure
*/
virtual nsapi_error_t get_registration_params(RegistrationType type, registration_params_t &reg_params) = 0;
};

View File

@ -501,7 +501,7 @@ ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
// Consume to delimiter or stop_tag
if (!delimiter_found && !_stop_tag->found) {
match_pos = 0;
while(1) {
while (1) {
int c = get_char();
if (c == -1) {
set_error(NSAPI_ERROR_DEVICE_ERROR);
@ -951,8 +951,8 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
int c = get_char();
if (c == -1) {
break;
// compares c against tag at current position and if this match fails
// compares c against tag[0] and also resets match_pos to 0
// compares c against tag at current position and if this match fails
// compares c against tag[0] and also resets match_pos to 0
} else if (c == tag[match_pos] || ((match_pos = 1) && (c == tag[--match_pos]))) {
match_pos++;
if (match_pos == strlen(tag)) {

View File

@ -249,7 +249,7 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
{
if (NSAPI_ERROR_OK != _at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)) ||
NSAPI_ERROR_OK != _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) {
NSAPI_ERROR_OK != _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) {
return NSAPI_ERROR_NO_MEMORY;
}
@ -625,7 +625,7 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char *b
int len = _at.read_string(time_stamp, SMS_MAX_TIME_STAMP_SIZE);
if (len < (SMS_MAX_TIME_STAMP_SIZE - 2)) {
time_stamp[len++] = ',';
_at.read_string(&time_stamp[len], SMS_MAX_TIME_STAMP_SIZE-len);
_at.read_string(&time_stamp[len], SMS_MAX_TIME_STAMP_SIZE - len);
}
}
(void)_at.consume_to_stop_tag(); // consume until <CR><LF>

View File

@ -40,7 +40,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
#endif // CELLULAR_DEVICE
CellularDevice::CellularDevice() : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
_info_ref_count(0)
_info_ref_count(0)
{
}

View File

@ -520,7 +520,7 @@ sisr_retry:
tr_debug("Socket %d, recvfrom %s, %d bytes (err %d)", socket->id, socket->remoteAddress.get_ip_address(), len, _at.get_last_error());
return (_at.get_last_error() == NSAPI_ERROR_OK) ? ( recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK ) : NSAPI_ERROR_DEVICE_ERROR;
return (_at.get_last_error() == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR;
}
// setup internet connection profile for sockets

View File

@ -49,38 +49,38 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
_at.lock();
if (socket->proto == NSAPI_TCP) {
_at.cmd_start("AT+QIOPEN=");
_at.write_int(_cid);
_at.write_int(request_connect_id);
_at.write_string("TCP");
_at.write_string(address.get_ip_address());
_at.write_int(address.get_port());
_at.write_int(socket->localAddress.get_port());
_at.write_int(0);
_at.cmd_stop();
_at.cmd_start("AT+QIOPEN=");
_at.write_int(_cid);
_at.write_int(request_connect_id);
_at.write_string("TCP");
_at.write_string(address.get_ip_address());
_at.write_int(address.get_port());
_at.write_int(socket->localAddress.get_port());
_at.write_int(0);
_at.cmd_stop();
handle_open_socket_response(modem_connect_id, err);
handle_open_socket_response(modem_connect_id, err);
if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) {
_at.cmd_start("AT+QICLOSE=");
_at.write_int(modem_connect_id);
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) {
_at.cmd_start("AT+QICLOSE=");
_at.write_int(modem_connect_id);
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
_at.cmd_start("AT+QIOPEN=");
_at.write_int(_cid);
_at.write_int(request_connect_id);
_at.write_string("TCP");
_at.write_string(address.get_ip_address());
_at.write_int(address.get_port());
_at.write_int(socket->localAddress.get_port());
_at.write_int(0);
_at.cmd_stop();
_at.cmd_start("AT+QIOPEN=");
_at.write_int(_cid);
_at.write_int(request_connect_id);
_at.write_string("TCP");
_at.write_string(address.get_ip_address());
_at.write_int(address.get_port());
_at.write_int(socket->localAddress.get_port());
_at.write_int(0);
_at.cmd_stop();
handle_open_socket_response(modem_connect_id, err);
}
}
handle_open_socket_response(modem_connect_id, err);
}
}
// If opened successfully BUT not requested one, close it
if (!err && (modem_connect_id != request_connect_id)) {

View File

@ -20,8 +20,7 @@
#include "AT_CellularDevice.h"
namespace mbed
{
namespace mbed {
class UBLOX_AT : public AT_CellularDevice {
public:

View File

@ -54,7 +54,7 @@ AT_CellularNetwork::RegistrationMode UBLOX_AT_CellularNetwork::has_registration(
nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
{
switch(opRat) {
switch (opRat) {
#if defined(TARGET_UBLOX_C030_U201) || defined(TARGET_UBLOX_C027)
case RAT_GSM:
case RAT_GSM_COMPACT:
@ -119,9 +119,9 @@ nsapi_error_t UBLOX_AT_CellularNetwork::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();
@ -142,14 +142,14 @@ nsapi_error_t UBLOX_AT_CellularNetwork::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;
@ -166,9 +166,9 @@ nsapi_error_t UBLOX_AT_CellularNetwork::open_data_channel()
return err;
}
bool UBLOX_AT_CellularNetwork::activate_profile(const char* apn,
const char* username,
const char* password)
bool UBLOX_AT_CellularNetwork::activate_profile(const char *apn,
const char *username,
const char *password)
{
bool activated = false;
bool success = false;
@ -283,7 +283,7 @@ bool UBLOX_AT_CellularNetwork::disconnect_modem_stack()
return success;
}
nsapi_error_t UBLOX_AT_CellularNetwork::get_imsi(char* imsi)
nsapi_error_t UBLOX_AT_CellularNetwork::get_imsi(char *imsi)
{
_at.lock();
_at.cmd_start("AT+CIMI");
@ -299,7 +299,7 @@ nsapi_error_t UBLOX_AT_CellularNetwork::get_imsi(char* imsi)
}
// Get the next set of credentials, based on IMSI.
void UBLOX_AT_CellularNetwork::get_next_credentials(char ** config)
void UBLOX_AT_CellularNetwork::get_next_credentials(char **config)
{
if (*config) {
_apn = _APN_GET(*config);

View File

@ -21,11 +21,9 @@
#include "AT_CellularNetwork.h"
#include "APN_db.h"
namespace mbed
{
namespace mbed {
class UBLOX_AT_CellularNetwork : public AT_CellularNetwork
{
class UBLOX_AT_CellularNetwork : public AT_CellularNetwork {
public:
UBLOX_AT_CellularNetwork(ATHandler &atHandler);
virtual ~UBLOX_AT_CellularNetwork();
@ -69,7 +67,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.
*
@ -86,11 +84,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

@ -20,11 +20,9 @@
#include "AT_CellularPower.h"
namespace mbed
{
namespace mbed {
class UBLOX_AT_CellularPower : public AT_CellularPower
{
class UBLOX_AT_CellularPower : public AT_CellularPower {
public:
UBLOX_AT_CellularPower(ATHandler &atHandler);
virtual ~UBLOX_AT_CellularPower();

View File

@ -47,11 +47,11 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_accept(void *server, void **socket,
// Callback for Socket Read URC.
void UBLOX_AT_CellularStack::UUSORD_URC()
{
int a,b;
int a, b;
CellularSocket *socket;
a =_at.read_int();
b =_at.read_int();
a = _at.read_int();
b = _at.read_int();
socket = find_socket(a);
if (socket != NULL) {
@ -67,11 +67,11 @@ void UBLOX_AT_CellularStack::UUSORD_URC()
// Callback for Socket Read From URC.
void UBLOX_AT_CellularStack::UUSORF_URC()
{
int a,b;
int a, b;
CellularSocket *socket;
a =_at.read_int();
b =_at.read_int();
a = _at.read_int();
b = _at.read_int();
socket = find_socket(a);
if (socket != NULL) {
@ -90,7 +90,7 @@ void UBLOX_AT_CellularStack::UUSOCL_URC()
int a;
CellularSocket *socket;
a =_at.read_int();
a = _at.read_int();
socket = find_socket(a);
clear_socket(socket);
}
@ -101,7 +101,7 @@ void UBLOX_AT_CellularStack::UUPSDD_URC()
int a;
CellularSocket *socket;
a =_at.read_int();
a = _at.read_int();
socket = find_socket(a);
clear_socket(socket);
}
@ -128,7 +128,7 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
_at.resp_start("+USOCR:");
sock_id = _at.read_int();
_at.resp_stop();
} else if(socket->proto == NSAPI_TCP) {
} else if (socket->proto == NSAPI_TCP) {
_at.cmd_start("AT+USOCR=6");
_at.cmd_stop();
@ -164,7 +164,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
if (socket) {
if (!socket->created) {
nsapi_error_t err = create_socket_impl(socket);
if(err != NSAPI_ERROR_OK) {
if (err != NSAPI_ERROR_OK) {
return err;
}
}
@ -190,7 +190,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
}
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size)
const void *data, nsapi_size_t size)
{
int sent_len = 0;
uint8_t ch = 0, cont = 50;
@ -262,7 +262,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
}
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size)
void *buffer, nsapi_size_t size)
{
nsapi_size_or_error_t nsapi_error_size = NSAPI_ERROR_DEVICE_ERROR;
bool success = true;
@ -411,7 +411,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_close_impl(int sock_id)
}
// Find or create a socket from the list.
UBLOX_AT_CellularStack::CellularSocket * UBLOX_AT_CellularStack::find_socket(int id)
UBLOX_AT_CellularStack::CellularSocket *UBLOX_AT_CellularStack::find_socket(int id)
{
CellularSocket *socket = NULL;
@ -428,7 +428,7 @@ UBLOX_AT_CellularStack::CellularSocket * UBLOX_AT_CellularStack::find_socket(int
// Clear out the storage for a socket
void UBLOX_AT_CellularStack::clear_socket(CellularSocket * socket)
void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
{
if (socket != NULL) {
socket->id = SOCKET_UNUSED;
@ -439,7 +439,7 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket * socket)
}
}
const char * UBLOX_AT_CellularStack::get_ip_address()
const char *UBLOX_AT_CellularStack::get_ip_address()
{
_at.lock();
_at.cmd_start("AT+UPSND=" PROFILE ",0");
@ -449,7 +449,7 @@ const char * UBLOX_AT_CellularStack::get_ip_address()
if (_at.info_resp()) {
_at.skip_param();
_at.skip_param();
int len = _at.read_string(_ip, NSAPI_IPv4_SIZE-1);
int len = _at.read_string(_ip, NSAPI_IPv4_SIZE - 1);
if (len == -1) {
_ip[0] = '\0';
_at.unlock();
@ -459,7 +459,7 @@ const char * UBLOX_AT_CellularStack::get_ip_address()
// in case stack type is not IPV4 only, try to look also for IPV6 address
if (_stack_type != IPV4_STACK) {
len = _at.read_string(_ip, PDP_IPV6_SIZE-1);
len = _at.read_string(_ip, PDP_IPV6_SIZE - 1);
}
}
_at.resp_stop();

View File

@ -23,11 +23,9 @@
#include "drivers/Timer.h"
namespace mbed
{
namespace mbed {
class UBLOX_AT_CellularStack : public AT_CellularStack
{
class UBLOX_AT_CellularStack : public AT_CellularStack {
public:
UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
virtual ~UBLOX_AT_CellularStack();
@ -41,7 +39,7 @@ protected:
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address=0);
nsapi_socket_t *handle, SocketAddress *address = 0);
protected: // AT_CellularStack
@ -78,10 +76,10 @@ protected: // AT_CellularStack
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size);
const void *data, nsapi_size_t size);
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size);
void *buffer, nsapi_size_t size);
virtual nsapi_error_t socket_close_impl(int sock_id);
@ -97,14 +95,14 @@ private:
* @param id Socket ID.
* @return Socket if True, otherwise NULL.
*/
CellularSocket * find_socket(int id = SOCKET_UNUSED);
CellularSocket *find_socket(int id = SOCKET_UNUSED);
/** Clear out the storage for a socket.
*
* @param id Cellular Socket.
* @return None
*/
void clear_socket(CellularSocket * socket);
void clear_socket(CellularSocket *socket);
};
} // namespace mbed
#endif /* UBLOX_AT_CELLULARSTACK_H_ */

View File

@ -21,4 +21,7 @@
MBED_DEPRECATED_SINCE("5.10", "FEATURE_LWIP is deprecated. You do not need to enable it anymore in mbed_app.json")
static void feature_lwip(void) { }
void dummy_feature_lwip_is_deprecated(void) { feature_lwip(); }
void dummy_feature_lwip_is_deprecated(void)
{
feature_lwip();
}

View File

@ -21,4 +21,7 @@
MBED_DEPRECATED_SINCE("5.10", "FEATURE_NANOSTACK is deprecated. You do not need to enable it anymore in mbed_app.json")
static void feature_nanostack(void) { }
void dummy_feature_nanostack_is_deprecated(void) { feature_nanostack(); }
void dummy_feature_nanostack_is_deprecated(void)
{
feature_nanostack();
}

View File

@ -52,7 +52,7 @@ int inject_dummy_rot_key()
memcpy(key, "1234567812345678", DEVICE_KEY_16BYTE);
int size = DEVICE_KEY_16BYTE;
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
return devkey.device_inject_root_of_trust(key, size);
#else
return DEVICEKEY_SUCCESS;
@ -86,8 +86,8 @@ void generate_derived_key_consistency_16_byte_key_long_consistency_test(char *ke
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
int key_type = DEVICE_KEY_16BYTE;
uint16_t actual_size = 0;
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
size_t salt_size = sizeof(salt);
if (strcmp(key, MSG_KEY_DEVICE_TEST_STEP1) == 0) {
@ -145,8 +145,8 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
int key_type = DEVICE_KEY_32BYTE;
uint16_t actual_size = 0;
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
size_t salt_size = sizeof(salt);
if (strcmp(key, MSG_KEY_DEVICE_TEST_STEP3) == 0) {
@ -198,7 +198,7 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
*/
void device_inject_root_of_trust_wrong_size_test()
{
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
memcpy(key, "12345678123456788765432187654321", DEVICE_KEY_32BYTE);
@ -217,11 +217,11 @@ void device_inject_root_of_trust_wrong_size_test()
*/
void device_inject_root_of_trust_16_byte_size_test()
{
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
uint32_t rkey[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
uint16_t actual_size;
uint32_t key[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
NVStore& nvstore = NVStore::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -243,11 +243,11 @@ void device_inject_root_of_trust_16_byte_size_test()
*/
void device_inject_root_of_trust_32_byte_size_test()
{
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
uint32_t rkey[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
uint16_t actual_size;
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
NVStore& nvstore = NVStore::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -269,9 +269,9 @@ void device_inject_root_of_trust_32_byte_size_test()
*/
void device_inject_root_of_trust_several_times_test()
{
DeviceKey& devkey = DeviceKey::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
NVStore& nvstore = NVStore::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -299,8 +299,8 @@ void generate_derived_key_consistency_16_byte_key_test()
unsigned char empty_buffer[DEVICE_KEY_16BYTE];
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
int key_type = DEVICE_KEY_16BYTE;
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -334,8 +334,8 @@ void generate_derived_key_consistency_32_byte_key_test()
unsigned char empty_buffer[DEVICE_KEY_32BYTE];
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
int key_type = DEVICE_KEY_32BYTE;
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -369,8 +369,8 @@ void generate_derived_key_key_type_16_test()
unsigned char expectedString[] = "Some String";
int key_type = DEVICE_KEY_16BYTE;
size_t salt_size = sizeof(salt);
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -400,8 +400,8 @@ void generate_derived_key_key_type_32_test()
int key_type = DEVICE_KEY_32BYTE;
size_t salt_size = sizeof(salt);
unsigned char expectedString[] = "Some String";
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
int ret = nvstore.reset();
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@ -429,8 +429,8 @@ void generate_derived_key_wrong_key_type_test()
unsigned char output[DEVICE_KEY_16BYTE];
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
size_t salt_size = sizeof(salt);
DeviceKey& devkey = DeviceKey::get_instance();
NVStore& nvstore = NVStore::get_instance();
DeviceKey &devkey = DeviceKey::get_instance();
NVStore &nvstore = NVStore::get_instance();
nvstore.init();
int ret = nvstore.reset();

View File

@ -117,7 +117,7 @@ int DeviceKey::write_key_to_nvstore(uint32_t *input, size_t isize)
return ret;
}
NVStore& nvstore = NVStore::get_instance();
NVStore &nvstore = NVStore::get_instance();
ret = nvstore.set(NVSTORE_DEVICEKEY_KEY, (uint16_t)isize, input);
if (NVSTORE_WRITE_ERROR == ret || NVSTORE_BUFF_TOO_SMALL == ret) {
return DEVICEKEY_SAVE_FAILED;
@ -130,15 +130,15 @@ int DeviceKey::write_key_to_nvstore(uint32_t *input, size_t isize)
return DEVICEKEY_SUCCESS;
}
int DeviceKey::read_key_from_nvstore(uint32_t *output, size_t& size)
int DeviceKey::read_key_from_nvstore(uint32_t *output, size_t &size)
{
if (size > (uint16_t)-1) {
if (size > (uint16_t) -1) {
return DEVICEKEY_INVALID_PARAM;
}
uint16_t in_size = size;
uint16_t out_size = 0;
NVStore& nvstore = NVStore::get_instance();
NVStore &nvstore = NVStore::get_instance();
int nvStatus = nvstore.get(NVSTORE_DEVICEKEY_KEY, in_size, output, out_size);
if (NVSTORE_NOT_FOUND == nvStatus) {
return DEVICEKEY_NOT_FOUND;
@ -179,18 +179,18 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
do {
mbedtls_cipher_init(&ctx);
ret = mbedtls_cipher_setup(&ctx, cipher_info);
if (ret != 0) {
goto finish;
}
mbedtls_cipher_init(&ctx);
ret = mbedtls_cipher_setup(&ctx, cipher_info);
if (ret != 0) {
goto finish;
}
ret = mbedtls_cipher_cmac_starts(&ctx, (unsigned char *)ikey_buff, ikey_size * 8);
if (ret != 0) {
goto finish;
}
DEVKEY_WRITE_UINT8_LE(counter_enc, (counter+1));
DEVKEY_WRITE_UINT8_LE(counter_enc, (counter + 1));
ret = mbedtls_cipher_cmac_update(&ctx, (unsigned char *)counter_enc, sizeof(counter_enc));
if (ret != 0) {
@ -217,7 +217,7 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
goto finish;
}
mbedtls_cipher_free( &ctx );
mbedtls_cipher_free(&ctx);
counter++;
@ -225,7 +225,7 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
finish:
if (DEVICEKEY_SUCCESS != ret) {
mbedtls_cipher_free( &ctx );
mbedtls_cipher_free(&ctx);
return DEVICEKEY_ERR_CMAC_GENERIC_FAILURE;
}

View File

@ -61,7 +61,7 @@ public:
*
* @returns Singleton instance reference.
*/
static DeviceKey& get_instance()
static DeviceKey &get_instance()
{
// Use this implementation of singleton (Meyer's) rather than the one that allocates
// the instance on the heap, as it ensures destruction at program end (preventing warnings
@ -100,7 +100,7 @@ private:
* Output: The actual size of the written data
* @return 0 on success, negative error code on failure
*/
int read_key_from_nvstore(uint32_t *output, size_t& size);
int read_key_from_nvstore(uint32_t *output, size_t &size);
/** Set a device key into the NVStore
* @param input Input buffer contain the key.
@ -109,7 +109,7 @@ private:
*/
int write_key_to_nvstore(uint32_t *input, size_t isize);
/** Get a derived key base on a salt string. The methods implements Section 5.1
/** Get a derived key base on a salt string. The methods implements Section 5.1
* in NIST SP 800-108, Recommendation for Key Derivation Using Pseudorandom Functions
* @param ikey_buff Input buffer holding the ROT key
* @param ikey_size Size of the input key. Must be 16 bytes or 32 bytes.

View File

@ -166,11 +166,11 @@ typedef struct radio_events {
*/
mbed::Callback<void()> rx_error;
/**
* FHSS Change Channel callback prototype.
*
* @param current_channel The index number of the current channel.
*/
/**
* FHSS Change Channel callback prototype.
*
* @param current_channel The index number of the current channel.
*/
mbed::Callback<void(uint8_t current_channel)> fhss_change_channel;
/**
@ -184,8 +184,7 @@ typedef struct radio_events {
/**
* Interface for the radios, contains the main functions that a radio needs, and five callback functions.
*/
class LoRaRadio
{
class LoRaRadio {
public:
@ -246,7 +245,7 @@ public:
* @param rx_continuous Sets the reception in continuous mode.
* [false: single mode, true: continuous mode]
*/
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
virtual void set_rx_config(radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
@ -284,10 +283,10 @@ public:
* @param timeout The transmission timeout [ms].
*/
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout) = 0;
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout) = 0;
/**
* Sends the buffer of size

View File

@ -800,7 +800,7 @@ bool LoRaWANStack::is_port_valid(const uint8_t port, bool allow_port_0)
//Application should not use reserved and illegal port numbers.
if (port == 0) {
return allow_port_0;
} else if (port == COMPLIANCE_TESTING_PORT){
} else if (port == COMPLIANCE_TESTING_PORT) {
#if !defined(LORAWAN_COMPLIANCE_TEST)
return false;
#endif
@ -943,9 +943,9 @@ void LoRaWANStack::mlme_confirm_handler()
if (_callbacks.link_check_resp) {
const int ret = _queue->call(
_callbacks.link_check_resp,
_loramac.get_mlme_confirmation()->demod_margin,
_loramac.get_mlme_confirmation()->nb_gateways);
_callbacks.link_check_resp,
_loramac.get_mlme_confirmation()->demod_margin,
_loramac.get_mlme_confirmation()->nb_gateways);
MBED_ASSERT(ret != 0);
(void) ret;
}
@ -1057,17 +1057,17 @@ void LoRaWANStack::mcps_indication_handler()
if ((_loramac.get_device_class() != CLASS_C
&& mcps_indication->fpending_status)
|| (_loramac.get_device_class() == CLASS_C
&& mcps_indication->type == MCPS_CONFIRMED)) {
&& mcps_indication->type == MCPS_CONFIRMED)) {
#if (MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE)
// Do not queue an automatic uplink of there is one already outgoing
// This means we have not received an ack for the previous automatic uplink
if (!_automatic_uplink_ongoing) {
tr_debug("Sending empty uplink message...");
_automatic_uplink_ongoing = true;
const int ret = _queue->call(this, &LoRaWANStack::send_automatic_uplink_message, mcps_indication->port);
MBED_ASSERT(ret != 0);
(void)ret;
}
// Do not queue an automatic uplink of there is one already outgoing
// This means we have not received an ack for the previous automatic uplink
if (!_automatic_uplink_ongoing) {
tr_debug("Sending empty uplink message...");
_automatic_uplink_ongoing = true;
const int ret = _queue->call(this, &LoRaWANStack::send_automatic_uplink_message, mcps_indication->port);
MBED_ASSERT(ret != 0);
(void)ret;
}
#else
send_event_to_application(UPLINK_REQUIRED);
#endif
@ -1193,7 +1193,7 @@ void LoRaWANStack::process_joining_state(lorawan_status_t &op_status)
}
if (_device_current_state == DEVICE_STATE_AWAITING_JOIN_ACCEPT &&
_loramac.get_current_slot() != RX_SLOT_WIN_1) {
_loramac.get_current_slot() != RX_SLOT_WIN_1) {
_device_current_state = DEVICE_STATE_JOINING;
// retry join
bool can_continue = _loramac.continue_joining_process();

View File

@ -289,7 +289,7 @@ void LoRaMac::handle_join_accept_frame(const uint8_t *payload, uint16_t size)
void LoRaMac::check_frame_size(uint16_t size)
{
uint8_t value = _lora_phy->get_max_payload(_mcps_indication.rx_datarate,
_params.is_repeater_supported);
_params.is_repeater_supported);
if (MAX(0, (int16_t)((int16_t)size - (int16_t)LORA_MAC_FRMPAYLOAD_OVERHEAD))
> (int32_t) value) {
@ -319,7 +319,7 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 2] << 16);
mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 3] << 24);
sequence_counter_prev = (uint16_t)*downlink_counter;
sequence_counter_prev = (uint16_t) * downlink_counter;
sequence_counter_diff = sequence_counter - sequence_counter_prev;
*downlink_counter += sequence_counter_diff;
if (sequence_counter < sequence_counter_prev) {
@ -600,8 +600,8 @@ void LoRaMac::handle_data_frame(const uint8_t *const payload,
}
if (_device_class == CLASS_C) {
_lora_time.stop(_rx2_closure_timer_for_class_c);
}
_lora_time.stop(_rx2_closure_timer_for_class_c);
}
if (_params.is_node_ack_requested && fctrl.bits.ack) {
_mcps_confirmation.ack_received = fctrl.bits.ack;
@ -699,7 +699,7 @@ void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
_lora_time.stop(_rx2_closure_timer_for_class_c);
open_rx2_window();
} else if (_device_class != CLASS_C){
} else if (_device_class != CLASS_C) {
_lora_time.stop(_params.timers.rx_window1_timer);
_lora_phy->put_radio_to_sleep();
}
@ -1118,9 +1118,9 @@ lorawan_status_t LoRaMac::schedule_tx()
next_channel.last_aggregate_tx_time = _params.timers.aggregated_last_tx_time;
lorawan_status_t status = _lora_phy->set_next_channel(&next_channel,
&_params.channel,
&backoff_time,
&_params.timers.aggregated_timeoff);
&_params.channel,
&backoff_time,
&_params.timers.aggregated_timeoff);
switch (status) {
case LORAWAN_STATUS_NO_CHANNEL_FOUND:
@ -1139,20 +1139,20 @@ lorawan_status_t LoRaMac::schedule_tx()
}
uint8_t rx1_dr = _lora_phy->apply_DR_offset(_params.sys_params.channel_data_rate,
_params.sys_params.rx1_dr_offset);
_params.sys_params.rx1_dr_offset);
tr_debug("TX: Channel=%d, TX DR=%d, RX1 DR=%d",
_params.channel, _params.sys_params.channel_data_rate, rx1_dr);
_lora_phy->compute_rx_win_params(rx1_dr, MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window1_config);
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window1_config);
_lora_phy->compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window2_config);
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window2_config);
if (!_is_nwk_joined) {
_params.rx_window1_delay = _params.sys_params.join_accept_delay1
@ -1177,8 +1177,8 @@ lorawan_status_t LoRaMac::schedule_tx()
fopts_len) == false) {
tr_error("Allowed FRMPayload = %d, FRMPayload = %d, MAC commands pending = %d",
_lora_phy->get_max_payload(_params.sys_params.channel_data_rate,
_params.is_repeater_supported),
_ongoing_tx_msg.f_buffer_size, fopts_len);
_params.is_repeater_supported),
_ongoing_tx_msg.f_buffer_size, fopts_len);
return LORAWAN_STATUS_LENGTH_ERROR;
}
_params.rx_window1_delay = _params.sys_params.recv_delay1
@ -1201,7 +1201,7 @@ void LoRaMac::calculate_backOff(uint8_t channel)
{
lorawan_time_t elapsed_time = _lora_time.get_elapsed_time(_params.timers.mac_init_time);
_lora_phy->calculate_backoff(_is_nwk_joined, _params.is_last_tx_join_request, _params.is_dutycycle_on,
channel, elapsed_time, _params.timers.tx_toa);
channel, elapsed_time, _params.timers.tx_toa);
// Update aggregated time-off. This must be an assignment and no incremental
// update as we do only calculate the time-off based on the last transmission
@ -1301,7 +1301,7 @@ int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
_ongoing_tx_msg.port = port;
uint8_t max_possible_size = 0;
uint8_t fopts_len = _mac_commands.get_mac_cmd_length()
+ _mac_commands.get_repeat_commands_length();
+ _mac_commands.get_repeat_commands_length();
// Handles unconfirmed messages
if (flags & MSG_UNCONFIRMED_FLAG) {
@ -1420,9 +1420,9 @@ void LoRaMac::set_device_class(const device_class_t &device_class,
_params.is_node_ack_requested = false;
_lora_phy->put_radio_to_sleep();
_lora_phy->compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window2_config);
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window2_config);
}
if (CLASS_C == _device_class) {
@ -1607,9 +1607,9 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
if (_params.sys_params.adr_on) {
if (_lora_phy->get_next_ADR(true,
_params.sys_params.channel_data_rate,
_params.sys_params.channel_tx_power,
_params.adr_ack_counter)) {
_params.sys_params.channel_data_rate,
_params.sys_params.channel_tx_power,
_params.adr_ack_counter)) {
fctrl->bits.adr_ack_req = 1;
}
}
@ -1696,7 +1696,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
_params.tx_buffer_len += LORAMAC_MFR_LEN;
}
break;
break;
case FRAME_TYPE_PROPRIETARY:
if ((fbuffer != NULL) && (_params.tx_buffer_len > 0)) {
memcpy(_params.tx_buffer + pkt_header_len, (uint8_t *) fbuffer,

View File

@ -38,7 +38,7 @@ void LoRaMacChannelPlan::activate_channelplan_subsystem(LoRaPHY *phy)
_lora_phy = phy;
}
lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t &plan)
{
lorawan_status_t status;
@ -66,8 +66,8 @@ lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
const channel_params_t* channel_list)
lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t &plan,
const channel_params_t *channel_list)
{
uint8_t max_num_channels;
uint16_t *channel_mask;

View File

@ -67,7 +67,7 @@ public:
* @return LORAWAN_STATUS_OK if everything goes well otherwise
* a negative error code is returned.
*/
lorawan_status_t set_plan(const lorawan_channelplan_t& plan);
lorawan_status_t set_plan(const lorawan_channelplan_t &plan);
/** Access the active channel plan
*
@ -81,7 +81,7 @@ public:
* @return LORAWAN_STATUS_OK if everything goes well otherwise
* a negative error code is returned.
*/
lorawan_status_t get_plan(lorawan_channelplan_t& plan, const channel_params_t* channel_list);
lorawan_status_t get_plan(lorawan_channelplan_t &plan, const channel_params_t *channel_list);
/** Remove the active channel plan
*

View File

@ -129,7 +129,7 @@ bool LoRaMacCommand::has_sticky_mac_cmd() const
lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, uint8_t mac_index,
uint8_t commands_size, uint8_t snr,
loramac_mlme_confirm_t& mlme_conf,
loramac_mlme_confirm_t &mlme_conf,
lora_mac_system_params_t &mac_sys_params,
LoRaPHY &lora_phy)
{
@ -180,7 +180,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
// Update MAC index
mac_index += link_adr_nb_bytes_pasred - 1;
}
break;
break;
case SRV_MAC_DUTY_CYCLE_REQ:
mac_sys_params.max_duty_cycle = payload[mac_index++];
mac_sys_params.aggregated_duty_cycle = 1 << mac_sys_params.max_duty_cycle;
@ -207,7 +207,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
}
ret_value = add_rx_param_setup_ans(status);
}
break;
break;
case SRV_MAC_DEV_STATUS_REQ: {
uint8_t battery_level = BAT_LEVEL_NO_MEASURE;
if (_battery_level_cb) {
@ -231,7 +231,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
ret_value = add_new_channel_ans(status);
}
break;
break;
case SRV_MAC_RX_TIMING_SETUP_REQ: {
uint8_t delay = payload[mac_index++] & 0x0F;
@ -242,7 +242,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
mac_sys_params.recv_delay2 = mac_sys_params.recv_delay1 + 1000;
ret_value = add_rx_timing_setup_ans();
}
break;
break;
case SRV_MAC_TX_PARAM_SETUP_REQ: {
uint8_t eirpDwellTime = payload[mac_index++];
uint8_t ul_dwell_time;
@ -270,7 +270,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
ret_value = add_tx_param_setup_ans();
}
}
break;
break;
case SRV_MAC_DL_CHANNEL_REQ: {
uint8_t channel_id = payload[mac_index++];
uint32_t rx1_frequency;
@ -283,7 +283,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
ret_value = add_dl_channel_ans(status);
}
break;
break;
default:
// Unknown command. ABORT MAC commands processing
tr_error("Invalid MAC command (0x%X)!", payload[mac_index]);

View File

@ -116,9 +116,9 @@ public:
*/
lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index,
uint8_t commands_size, uint8_t snr,
loramac_mlme_confirm_t& mlme_conf,
lora_mac_system_params_t& mac_params,
LoRaPHY& lora_phy);
loramac_mlme_confirm_t &mlme_conf,
lora_mac_system_params_t &mac_params,
LoRaPHY &lora_phy);
/**
* @brief Adds a new LinkCheckReq MAC command to be sent.

View File

@ -63,32 +63,37 @@ int LoRaMacCrypto::compute_mic(const uint8_t *buffer, uint16_t size,
mbedtls_cipher_init(aes_cmac_ctx);
const mbedtls_cipher_info_t* cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
const mbedtls_cipher_info_t *cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
if (NULL != cipher_info) {
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, mic_block_b0, sizeof(mic_block_b0));
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
if (0 != ret)
if (0 != ret) {
goto exit;
}
*mic = (uint32_t) ((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
} else {
ret = MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
}
@ -112,8 +117,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
a_block[0] = 0x01;
a_block[5] = dir;
@ -133,8 +139,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
ctr++;
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
s_block);
if (0 != ret)
if (0 != ret) {
goto exit;
}
for (i = 0; i < 16; i++) {
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
@ -147,8 +154,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
a_block[15] = ((ctr) & 0xFF);
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
s_block);
if (0 != ret)
if (0 != ret) {
goto exit;
}
for (i = 0; i < size; i++) {
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
@ -177,28 +185,32 @@ int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *buffer, uint16_t size,
int ret = 0;
mbedtls_cipher_init(aes_cmac_ctx);
const mbedtls_cipher_info_t* cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
const mbedtls_cipher_info_t *cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB);
if (NULL != cipher_info) {
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
if (0 != ret)
if (0 != ret) {
goto exit;
}
*mic = (uint32_t) ((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
} else {
ret = MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
}
@ -217,13 +229,15 @@ int LoRaMacCrypto::decrypt_join_frame(const uint8_t *buffer, uint16_t size,
mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, buffer,
dec_buffer);
if (0 != ret)
if (0 != ret) {
goto exit;
}
// Check if optional CFList is included
if (size >= 16) {
@ -247,16 +261,18 @@ int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *key, uint32_t key
mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
memset(nonce, 0, sizeof(nonce));
nonce[0] = 0x01;
memcpy(nonce + 1, app_nonce, 6);
memcpy(nonce + 7, p_dev_nonce, 2);
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, nwk_skey);
if (0 != ret)
if (0 != ret) {
goto exit;
}
memset(nonce, 0, sizeof(nonce));
nonce[0] = 0x02;
@ -279,7 +295,7 @@ LoRaMacCrypto::LoRaMacCrypto()
// user knows what is wrong and in addition to that these ensure that
// Mbed-OS compiles properly under normal conditions where LoRaWAN in conjunction
// with mbedTLS is not being used.
int LoRaMacCrypto::compute_mic(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
int LoRaMacCrypto::compute_mic(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint32_t,
uint8_t dir, uint32_t, uint32_t *)
{
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
@ -288,8 +304,8 @@ int LoRaMacCrypto::compute_mic(const uint8_t *, uint16_t , const uint8_t *, uint
return LORAWAN_STATUS_CRYPTO_FAIL;
}
int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
uint8_t , uint32_t , uint8_t *)
int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint32_t,
uint8_t, uint32_t, uint8_t *)
{
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
@ -297,8 +313,8 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t , const uint8_t *,
return LORAWAN_STATUS_CRYPTO_FAIL;
}
int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
uint8_t , uint32_t , uint8_t *)
int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint32_t,
uint8_t, uint32_t, uint8_t *)
{
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
@ -306,7 +322,7 @@ int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t , const uint8_t *,
return LORAWAN_STATUS_CRYPTO_FAIL;
}
int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t *)
int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint32_t *)
{
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
@ -314,7 +330,7 @@ int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *, uint16_t , const uint
return LORAWAN_STATUS_CRYPTO_FAIL;
}
int LoRaMacCrypto::decrypt_join_frame(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint8_t *)
int LoRaMacCrypto::decrypt_join_frame(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint8_t *)
{
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
@ -322,7 +338,7 @@ int LoRaMacCrypto::decrypt_join_frame(const uint8_t *, uint16_t , const uint8_t
return LORAWAN_STATUS_CRYPTO_FAIL;
}
int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *, uint32_t, const uint8_t *, uint16_t ,
int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *, uint32_t, const uint8_t *, uint16_t,
uint8_t *, uint8_t *)
{
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");

View File

@ -34,8 +34,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "mbedtls/cmac.h"
class LoRaMacCrypto
{
class LoRaMacCrypto {
public:
/**
* Constructor

View File

@ -404,7 +404,7 @@ void LoRaPHY::get_rx_window_params(double t_symb, uint8_t min_rx_symb,
{
// Computed number of symbols
*window_timeout = MAX((uint32_t) ceil(((2 * min_rx_symb - 8) * t_symb + 2 * rx_error) / t_symb), min_rx_symb);
*window_offset = (int32_t) ceil((4.0 * t_symb) - ((*window_timeout * t_symb) / 2.0 ) - wakeup_time);
*window_offset = (int32_t) ceil((4.0 * t_symb) - ((*window_timeout * t_symb) / 2.0) - wakeup_time);
}
int8_t LoRaPHY::compute_tx_power(int8_t tx_power_idx, float max_eirp,

View File

@ -147,7 +147,7 @@ public:
*
* @return bit mask, according to the LoRaWAN spec 1.0.2.
*/
virtual uint8_t request_new_channel(int8_t channel_id, channel_params_t* new_channel);
virtual uint8_t request_new_channel(int8_t channel_id, channel_params_t *new_channel);
/** Process PHY layer state after a successful transmission.
* @brief set_last_tx_done Updates times of the last transmission for the particular channel and
@ -174,7 +174,7 @@ public:
* @param size Size of the payload.
*
*/
virtual void apply_cf_list(const uint8_t* payload, uint8_t size);
virtual void apply_cf_list(const uint8_t *payload, uint8_t size);
/** Calculates the next datarate to set, when ADR is on or off.
*
@ -189,8 +189,8 @@ public:
*
* @return True, if an ADR request should be performed.
*/
bool get_next_ADR(bool restore_channel_mask, int8_t& dr_out,
int8_t& tx_power_out, uint32_t& adr_ack_counter);
bool get_next_ADR(bool restore_channel_mask, int8_t &dr_out,
int8_t &tx_power_out, uint32_t &adr_ack_counter);
/** Configure radio reception.
*
@ -198,7 +198,7 @@ public:
*
* @return True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* config);
virtual bool rx_config(rx_config_params_t *config);
/** Computing Receive Windows
*
@ -268,8 +268,8 @@ public:
*
* @return True, if the configuration was applied successfully.
*/
virtual bool tx_config(tx_config_params_t* tx_config, int8_t* tx_power,
lorawan_time_t* tx_toa);
virtual bool tx_config(tx_config_params_t *tx_config, int8_t *tx_power,
lorawan_time_t *tx_toa);
/** Processes a Link ADR Request.
*
@ -285,10 +285,10 @@ public:
*
* @return The status of the operation, according to the LoRaMAC specification.
*/
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
virtual uint8_t link_ADR_request(adr_req_params_t *params,
int8_t *dr_out, int8_t *tx_power_out,
uint8_t *nb_rep_out,
uint8_t *nb_bytes_parsed);
/** Accept or rejects RxParamSetupReq MAC command
*
@ -299,7 +299,7 @@ public:
*
* @return The status of the operation, according to the LoRaWAN specification.
*/
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params);
/**
* @brief accept_tx_param_setup_req Makes decision whether to accept or reject TxParamSetupReq MAC command.
@ -345,9 +345,9 @@ public:
*
* @return Function status [1: OK, 0: Unable to find a channel on the current datarate].
*/
virtual lorawan_status_t set_next_channel(channel_selection_params_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff);
virtual lorawan_status_t set_next_channel(channel_selection_params_t *nextChanParams,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregatedTimeOff);
/** Adds a channel to the channel list.
*
@ -361,7 +361,7 @@ public:
* @return LORAWAN_STATUS_OK if everything goes fine, negative error code
* otherwise.
*/
virtual lorawan_status_t add_channel(const channel_params_t* new_channel, uint8_t id);
virtual lorawan_status_t add_channel(const channel_params_t *new_channel, uint8_t id);
/** Removes a channel from the channel list.
*
@ -377,7 +377,7 @@ public:
*
* @param [in] frequency Frequency to transmit at
*/
virtual void set_tx_cont_mode(cw_mode_params_t* continuous_wave,
virtual void set_tx_cont_mode(cw_mode_params_t *continuous_wave,
uint32_t frequency = 0);
/** Computes new data rate according to the given offset
@ -474,7 +474,7 @@ public:
* @param get_default If true the default mask is returned, otherwise the current mask is returned
* @return A channel mask
*/
uint16_t* get_channel_mask(bool get_default = false);
uint16_t *get_channel_mask(bool get_default = false);
/**
* @brief get_max_nb_channels Gets maximum number of channels supported
@ -486,7 +486,7 @@ public:
* @brief get_phy_channels Gets PHY channels
* @return PHY channels
*/
channel_params_t* get_phy_channels();
channel_params_t *get_phy_channels();
/**
* @brief is_custom_channel_plan_supported Checks if custom channel plan is supported
@ -553,12 +553,12 @@ protected:
/**
* Verifies, if a datarate is available on an active channel.
*/
bool verify_channel_DR(uint16_t* channelsMask, int8_t dr);
bool verify_channel_DR(uint16_t *channelsMask, int8_t dr);
/**
* Disables a channel in a given channels mask.
*/
bool disable_channel(uint16_t* channel_mask, uint8_t id, uint8_t max_channels);
bool disable_channel(uint16_t *channel_mask, uint8_t id, uint8_t max_channels);
/**
* Counts number of bits on in a given mask
@ -568,38 +568,38 @@ protected:
/**
* Counts the number of active channels in a given channels mask.
*/
uint8_t num_active_channels(uint16_t* channel_mask, uint8_t start_idx,
uint8_t num_active_channels(uint16_t *channel_mask, uint8_t start_idx,
uint8_t stop_idx);
/**
* Copy channel masks.
*/
void copy_channel_mask(uint16_t* dest_mask, uint16_t* src_mask, uint8_t len);
void copy_channel_mask(uint16_t *dest_mask, uint16_t *src_mask, uint8_t len);
/**
* Updates the time-offs of the bands.
*/
lorawan_time_t update_band_timeoff(bool joined, bool dutyCycle, band_t* bands,
lorawan_time_t update_band_timeoff(bool joined, bool dutyCycle, band_t *bands,
uint8_t nb_bands);
/**
* Parses the parameter of an LinkAdrRequest.
*/
uint8_t parse_link_ADR_req(const uint8_t* payload, link_adr_params_t* adr_params);
uint8_t parse_link_ADR_req(const uint8_t *payload, link_adr_params_t *adr_params);
/**
* Verifies and updates the datarate, the TX power and the number of repetitions
* of a LinkAdrRequest.
*/
uint8_t verify_link_ADR_req(verify_adr_params_t* verify_params, int8_t* dr,
int8_t* tx_pow, uint8_t* nb_rep);
uint8_t verify_link_ADR_req(verify_adr_params_t *verify_params, int8_t *dr,
int8_t *tx_pow, uint8_t *nb_rep);
/**
* Computes the RX window timeout and the RX window offset.
*/
void get_rx_window_params(double t_symbol, uint8_t min_rx_symbols,
uint32_t rx_error, uint32_t wakeup_time,
uint32_t* window_timeout, int32_t* window_offset);
uint32_t *window_timeout, int32_t *window_offset);
/**
* Computes the txPower, based on the max EIRP and the antenna gain.
@ -622,8 +622,8 @@ protected:
uint8_t get_bandwidth(uint8_t dr_index);
uint8_t enabled_channel_count(uint8_t datarate,
const uint16_t *mask, uint8_t* enabledChannels,
uint8_t* delayTx);
const uint16_t *mask, uint8_t *enabledChannels,
uint8_t *delayTx);
bool is_datarate_supported(const int8_t datarate) const;
@ -632,7 +632,7 @@ private:
/**
* Computes the symbol time for LoRa modulation.
*/
double compute_symb_timeout_lora(uint8_t phy_dr, uint32_t bandwidth );
double compute_symb_timeout_lora(uint8_t phy_dr, uint32_t bandwidth);
/**
* Computes the symbol time for FSK modulation.

View File

@ -194,13 +194,13 @@ static const band_t AS923_BAND0 = {100, AS923_MAX_TX_POWER, 0, 0, 0, 923000000,
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t AS923_LC1 = { 923200000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t AS923_LC1 = { 923200000, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t AS923_LC2 = { 923400000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t AS923_LC2 = { 923400000, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac channels which are allowed for the join procedure
@ -228,12 +228,12 @@ static const uint8_t datarates_AS923[] = {12, 11, 10, 9, 8, 7, 7, 50};
static const uint32_t bandwidths_AS923[] = {125000, 125000, 125000, 125000, 125000, 125000, 250000, 0};
#if (MBED_CONF_LORA_DWELL_TIME == 0)
static const uint8_t max_payload_table[] = {51, 51, 51, 115, 242, 242, 242, 242};
static const uint8_t max_payload_table_with_repeater[] = {51, 51, 51, 115, 222, 222, 222, 222};
static const uint8_t max_payload_table[] = {51, 51, 51, 115, 242, 242, 242, 242};
static const uint8_t max_payload_table_with_repeater[] = {51, 51, 51, 115, 222, 222, 222, 222};
#else
// this is the default, i.e.,
static const uint8_t max_payload_table[] = {0, 0, 11, 53, 125, 242, 242, 242};
static const uint8_t max_payload_table_with_repeater[] = {0, 0, 11, 53, 125, 242, 242, 242};
// this is the default, i.e.,
static const uint8_t max_payload_table[] = {0, 0, 11, 53, 125, 242, 242, 242};
static const uint8_t max_payload_table_with_repeater[] = {0, 0, 11, 53, 125, 242, 242, 242};
#endif
/*!
@ -336,9 +336,9 @@ int8_t LoRaPHYAS923::get_alternate_DR(uint8_t nb_trials)
return AS923_DWELL_LIMIT_DATARATE;
}
lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next_channel_prams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregate_timeoff)
lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t *next_channel_prams,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeoff)
{
uint8_t next_channel_idx = 0;
uint8_t nb_enabled_channels = 0;
@ -375,7 +375,7 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next
for (uint8_t i = 0, j = get_random(0, nb_enabled_channels - 1); i < AS923_MAX_NB_CHANNELS; i++) {
next_channel_idx = enabled_channels[j];
j = ( j + 1 ) % nb_enabled_channels;
j = (j + 1) % nb_enabled_channels;
// Perform carrier sense for AS923_CARRIER_SENSE_TIME
// If the channel is free, we can stop the LBT mechanism
@ -402,7 +402,7 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next
}
// Datarate not supported by any channel, restore defaults
channel_mask[0] |= LC( 1 ) + LC( 2 );
channel_mask[0] |= LC(1) + LC(2);
*time = 0;
return LORAWAN_STATUS_NO_CHANNEL_FOUND;
}

View File

@ -55,11 +55,11 @@ public:
virtual int8_t get_alternate_DR(uint8_t nb_trials);
virtual lorawan_status_t set_next_channel(channel_selection_params_t* nextChanParams,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregatedTimeOff );
virtual lorawan_status_t set_next_channel(channel_selection_params_t *nextChanParams,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregatedTimeOff);
virtual uint8_t apply_DR_offset(int8_t dr, int8_t drOffset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t drOffset);
private:
channel_params_t channels[AS923_MAX_NB_CHANNELS];

View File

@ -192,33 +192,38 @@ static const uint8_t datarates_AU915[] = {12, 11, 10, 9, 8, 7, 8, 0, 12, 11, 10,
* Bandwidths table definition in Hz
*/
static const uint32_t bandwidths_AU915[] = { 125000, 125000, 125000, 125000,
125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000,
0, 0 };
125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000,
0, 0
};
/*!
* Up/Down link data rates offset definition
*/
static const int8_t datarate_offsets_AU915[7][6] = { { DR_8, DR_8, DR_8, DR_8,
DR_8, DR_8 }, // DR_0
static const int8_t datarate_offsets_AU915[7][6] = { {
DR_8, DR_8, DR_8, DR_8,
DR_8, DR_8
}, // DR_0
{ DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1
{ DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2
{ DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3
{ DR_12, DR_11, DR_10, DR_9, DR_8, DR_8 }, // DR_4
{ DR_13, DR_12, DR_11, DR_10, DR_9, DR_8 }, // DR_5
{ DR_13, DR_13, DR_12, DR_11, DR_10, DR_9 }, // DR_6
};
};
/*!
* Maximum payload with respect to the datarate index. Cannot operate with repeater.
*/
static const uint8_t max_payload_AU915[] = { 51, 51, 51, 115, 242, 242,
242, 0, 53, 129, 242, 242, 242, 242, 0, 0 };
242, 0, 53, 129, 242, 242, 242, 242, 0, 0
};
/*!
* Maximum payload with respect to the datarate index. Can operate with repeater.
*/
static const uint8_t max_payload_with_repeater_AU915[] = { 51, 51, 51, 115,
222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0 };
222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0
};
static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK;
@ -232,14 +237,14 @@ LoRaPHYAU915::LoRaPHYAU915()
// 125 kHz channels Upstream only
for (uint8_t i = 0; i < AU915_MAX_NB_CHANNELS - 8; i++) {
channels[i].frequency = 915200000 + i * 200000;
channels[i].dr_range.value = ( DR_5 << 4) | DR_0;
channels[i].dr_range.value = (DR_5 << 4) | DR_0;
channels[i].band = 0;
}
// 500 kHz channels
// Upstream and downstream both
for (uint8_t i = AU915_MAX_NB_CHANNELS - 8; i < AU915_MAX_NB_CHANNELS; i++) {
channels[i].frequency = 915900000 + (i - ( AU915_MAX_NB_CHANNELS - 8)) * 1600000;
channels[i].dr_range.value = ( DR_6 << 4) | DR_6;
channels[i].frequency = 915900000 + (i - (AU915_MAX_NB_CHANNELS - 8)) * 1600000;
channels[i].dr_range.value = (DR_6 << 4) | DR_6;
channels[i].band = 0;
}
@ -335,7 +340,7 @@ LoRaPHYAU915::~LoRaPHYAU915()
{
}
bool LoRaPHYAU915::rx_config(rx_config_params_t* params)
bool LoRaPHYAU915::rx_config(rx_config_params_t *params)
{
int8_t dr = params->datarate;
uint8_t max_payload = 0;
@ -349,7 +354,7 @@ bool LoRaPHYAU915::rx_config(rx_config_params_t* params)
if (params->rx_slot == RX_SLOT_WIN_1) {
// Apply window 1 frequency
frequency = AU915_FIRST_RX1_CHANNEL
+ (params->channel % 8) * AU915_STEPWIDTH_RX1_CHANNEL;
+ (params->channel % 8) * AU915_STEPWIDTH_RX1_CHANNEL;
}
// Read the physical datarate from the datarates table
@ -377,8 +382,8 @@ bool LoRaPHYAU915::rx_config(rx_config_params_t* params)
return true;
}
bool LoRaPHYAU915::tx_config(tx_config_params_t* params, int8_t* tx_power,
lorawan_time_t* tx_toa)
bool LoRaPHYAU915::tx_config(tx_config_params_t *params, int8_t *tx_power,
lorawan_time_t *tx_toa)
{
int8_t phy_dr = datarates_AU915[params->datarate];
@ -414,10 +419,10 @@ bool LoRaPHYAU915::tx_config(tx_config_params_t* params, int8_t* tx_power,
return true;
}
uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed)
uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t *params,
int8_t *dr_out, int8_t *tx_power_out,
uint8_t *nb_rep_out,
uint8_t *nb_bytes_parsed)
{
uint8_t status = 0x07;
link_adr_params_t adr_settings = {};
@ -505,7 +510,7 @@ uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t* params,
return status;
}
uint8_t LoRaPHYAU915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
uint8_t LoRaPHYAU915::accept_rx_param_setup_req(rx_param_setup_req_t *params)
{
uint8_t status = 0x07;
uint32_t freq = params->frequency;
@ -517,7 +522,7 @@ uint8_t LoRaPHYAU915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
|| (freq < AU915_FIRST_RX1_CHANNEL)
|| (freq > AU915_LAST_RX1_CHANNEL)
|| (((freq - (uint32_t) AU915_FIRST_RX1_CHANNEL)
% (uint32_t) AU915_STEPWIDTH_RX1_CHANNEL) != 0)) {
% (uint32_t) AU915_STEPWIDTH_RX1_CHANNEL) != 0)) {
status &= 0xFE; // Channel frequency KO
}
@ -553,9 +558,9 @@ int8_t LoRaPHYAU915::get_alternate_DR(uint8_t nb_trials)
return datarate;
}
lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t* next_chan_params,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregated_timeOff)
lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t *next_chan_params,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregated_timeOff)
{
uint8_t nb_enabled_channels = 0;
uint8_t delay_tx = 0;
@ -619,7 +624,7 @@ uint8_t LoRaPHYAU915::apply_DR_offset(int8_t dr, int8_t dr_offset)
}
void LoRaPHYAU915::intersect_channel_mask(const uint16_t *source,
uint16_t *destination, uint8_t size)
uint16_t *destination, uint8_t size)
{
for (uint8_t i = 0; i < size; i++) {
destination[i] &= source[i];
@ -627,9 +632,9 @@ void LoRaPHYAU915::intersect_channel_mask(const uint16_t *source,
}
void LoRaPHYAU915::fill_channel_mask_with_fsb(const uint16_t *expectation,
const uint16_t *fsb_mask,
uint16_t *destination,
uint8_t size)
const uint16_t *fsb_mask,
uint16_t *destination,
uint8_t size)
{
for (uint8_t i = 0; i < size; i++) {
destination[i] = expectation[i] & fsb_mask[i];
@ -638,7 +643,7 @@ void LoRaPHYAU915::fill_channel_mask_with_fsb(const uint16_t *expectation,
}
void LoRaPHYAU915::fill_channel_mask_with_value(uint16_t *channel_mask,
uint16_t value, uint8_t size)
uint16_t value, uint8_t size)
{
for (uint8_t i = 0; i < size; i++) {
channel_mask[i] = value;

View File

@ -49,30 +49,30 @@
#define AU915_CHANNEL_MASK_SIZE 5
class LoRaPHYAU915 : public LoRaPHY{
class LoRaPHYAU915 : public LoRaPHY {
public:
LoRaPHYAU915();
virtual ~LoRaPHYAU915();
virtual bool rx_config(rx_config_params_t* config);
virtual bool rx_config(rx_config_params_t *config);
virtual bool tx_config(tx_config_params_t* config, int8_t* txPower,
lorawan_time_t* txTimeOnAir);
virtual bool tx_config(tx_config_params_t *config, int8_t *txPower,
lorawan_time_t *txTimeOnAir);
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* drOut, int8_t* txPowOut,
uint8_t* nbRepOut,
uint8_t* nbBytesParsed);
virtual uint8_t link_ADR_request(adr_req_params_t *params,
int8_t *drOut, int8_t *txPowOut,
uint8_t *nbRepOut,
uint8_t *nbBytesParsed);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params);
virtual int8_t get_alternate_DR(uint8_t nb_trials);
virtual lorawan_status_t set_next_channel(channel_selection_params_t* next_chan_params,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregate_timeoff);
virtual lorawan_status_t set_next_channel(channel_selection_params_t *next_chan_params,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeoff);
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);

View File

@ -212,10 +212,9 @@ LoRaPHYCN470::LoRaPHYCN470()
// Channels
// 125 kHz channels
for( uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++ )
{
for (uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++) {
channels[i].frequency = 470300000 + i * 200000;
channels[i].dr_range.value = ( DR_5 << 4 ) | DR_0;
channels[i].dr_range.value = (DR_5 << 4) | DR_0;
channels[i].band = 0;
}
@ -359,7 +358,7 @@ lorawan_status_t LoRaPHYCN470::set_next_channel(channel_selection_params_t *para
return LORAWAN_STATUS_NO_CHANNEL_FOUND;
}
bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
bool LoRaPHYCN470::rx_config(rx_config_params_t *config)
{
int8_t dr = config->datarate;
uint8_t max_payload = 0;
@ -375,8 +374,7 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
_radio->unlock();
if( config->rx_slot == RX_SLOT_WIN_1 )
{
if (config->rx_slot == RX_SLOT_WIN_1) {
// Apply window 1 frequency
frequency = CN470_FIRST_RX1_CHANNEL + (config->channel % 48) * CN470_STEPWIDTH_RX1_CHANNEL;
}
@ -409,8 +407,8 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
return true;
}
bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa)
bool LoRaPHYCN470::tx_config(tx_config_params_t *config, int8_t *tx_power,
lorawan_time_t *tx_toa)
{
int8_t phy_dr = datarates_CN470[config->datarate];
@ -429,9 +427,9 @@ bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
_radio->set_channel(channels[config->channel].frequency);
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, 0, phy_dr, 1,
MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH, false, true,
0, 0, false, 3000);
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, 0, phy_dr, 1,
MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH, false, true,
0, 0, false, 3000);
// Setup maximum payload lenght of the radio driver
_radio->set_max_payload_length(MODEM_LORA, config->pkt_len);
@ -446,10 +444,10 @@ bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
return true;
}
uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed)
uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t *params,
int8_t *dr_out, int8_t *tx_power_out,
uint8_t *nb_rep_out,
uint8_t *nb_bytes_parsed)
{
uint8_t status = 0x07;
link_adr_params_t adr_settings;
@ -462,7 +460,7 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
// Initialize local copy of channels mask
copy_channel_mask(temp_channel_masks, channel_mask, CN470_CHANNEL_MASK_SIZE);
while(bytes_processed < params->payload_size) {
while (bytes_processed < params->payload_size) {
// Get ADR request parameters
next_index = parse_link_ADR_req(&(params->payload[bytes_processed]), &adr_settings);
@ -484,7 +482,7 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
temp_channel_masks[i] = 0xFFFF;
}
} else if( adr_settings.ch_mask_ctrl == 7 ) {
} else if (adr_settings.ch_mask_ctrl == 7) {
status &= 0xFE; // Channel mask KO
@ -492,8 +490,8 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
for (uint8_t i = 0; i < 16; i++) {
if (((adr_settings.channel_mask & (1 << i)) != 0 ) &&
(channels[adr_settings.ch_mask_ctrl * 16 + i].frequency == 0)) {
if (((adr_settings.channel_mask & (1 << i)) != 0) &&
(channels[adr_settings.ch_mask_ctrl * 16 + i].frequency == 0)) {
// Trying to enable an undefined channel
status &= 0xFE; // Channel mask KO
}
@ -533,7 +531,7 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
return status;
}
uint8_t LoRaPHYCN470::accept_rx_param_setup_req(rx_param_setup_req_t* params)
uint8_t LoRaPHYCN470::accept_rx_param_setup_req(rx_param_setup_req_t *params)
{
uint8_t status = 0x07;
uint32_t freq = params->frequency;

View File

@ -57,19 +57,19 @@ public:
virtual ~LoRaPHYCN470();
virtual lorawan_status_t set_next_channel(channel_selection_params_t *params,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeoff);
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeoff);
virtual bool rx_config(rx_config_params_t* config);
virtual bool rx_config(rx_config_params_t *config);
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);
virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power,
lorawan_time_t *tx_toa);
virtual uint8_t link_ADR_request(adr_req_params_t* params, int8_t* dr_out,
int8_t* tx_power_out, uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
virtual uint8_t link_ADR_request(adr_req_params_t *params, int8_t *dr_out,
int8_t *tx_power_out, uint8_t *nb_rep_out,
uint8_t *nb_bytes_parsed);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params);
private:

View File

@ -191,18 +191,18 @@ static const band_t CN779_BAND0 = {100, CN779_MAX_TX_POWER, 0, 0, 0, 779500000,
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t CN779_LC1 = {779500000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0};
static const channel_params_t CN779_LC1 = {779500000, 0, { ((DR_5 << 4) | DR_0) }, 0};
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t CN779_LC2 = {779700000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0};
static const channel_params_t CN779_LC2 = {779700000, 0, { ((DR_5 << 4) | DR_0) }, 0};
/*!
* LoRaMac default channel 3
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t CN779_LC3 = {779900000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0};
static const channel_params_t CN779_LC3 = {779900000, 0, { ((DR_5 << 4) | DR_0) }, 0};
/*!
* LoRaMac channels which are allowed for the join procedure

View File

@ -191,19 +191,19 @@ static const band_t EU433_BAND0 = {100, EU433_MAX_TX_POWER, 0, 0, 0, 433175000,
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t EU433_LC1 = {433175000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0};
static const channel_params_t EU433_LC1 = {433175000, 0, { ((DR_5 << 4) | DR_0) }, 0};
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t EU433_LC2 = {433375000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0};
static const channel_params_t EU433_LC2 = {433375000, 0, { ((DR_5 << 4) | DR_0) }, 0};
/*!
* LoRaMac default channel 3
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t EU433_LC3 = {433575000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0};
static const channel_params_t EU433_LC3 = {433575000, 0, { ((DR_5 << 4) | DR_0) }, 0};
/*!
* LoRaMac channels which are allowed for the join procedure

View File

@ -182,12 +182,12 @@
* Band 0 definition
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
*/
static const band_t EU868_BAND0 = {100 , EU868_MAX_TX_POWER, 0, 0, 0,865000000, 868000000}; // 1.0 %
static const band_t EU868_BAND0 = {100, EU868_MAX_TX_POWER, 0, 0, 0, 865000000, 868000000}; // 1.0 %
/*!
* Band 1 definition
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
*/
static const band_t EU868_BAND1 = {100 , EU868_MAX_TX_POWER, 0, 0, 0, 868100000, 868600000}; // 1.0 %
static const band_t EU868_BAND1 = {100, EU868_MAX_TX_POWER, 0, 0, 0, 868100000, 868600000}; // 1.0 %
/*!
* Band 2 definition
@ -199,13 +199,13 @@ static const band_t EU868_BAND2 = {1000, EU868_MAX_TX_POWER, 0, 0, 0, 868700000,
* Band 3 definition
* Band = { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
*/
static const band_t EU868_BAND3 = {10 , EU868_MAX_TX_POWER, 0, 0, 0, 869400000, 869650000}; // 10.0 %
static const band_t EU868_BAND3 = {10, EU868_MAX_TX_POWER, 0, 0, 0, 869400000, 869650000}; // 10.0 %
/*!
* Band 4 definition
* Band = { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
*/
static const band_t EU868_BAND4 = {100 , EU868_MAX_TX_POWER, 0, 0, 0, 869700000, 870000000}; // 1.0 %
static const band_t EU868_BAND4 = {100, EU868_MAX_TX_POWER, 0, 0, 0, 869700000, 870000000}; // 1.0 %
/*!
* Band 5 definition - It's actually a sub part of Band 2
@ -217,19 +217,19 @@ static const band_t EU868_BAND5 = {1000, EU868_MAX_TX_POWER, 0, 0, 0, 863000000,
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t EU868_LC1 = {868100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1};
static const channel_params_t EU868_LC1 = {868100000, 0, { ((DR_5 << 4) | DR_0) }, 1};
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t EU868_LC2 = {868300000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1};
static const channel_params_t EU868_LC2 = {868300000, 0, { ((DR_5 << 4) | DR_0) }, 1};
/*!
* LoRaMac default channel 3
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t EU868_LC3 = {868500000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 1};
static const channel_params_t EU868_LC3 = {868500000, 0, { ((DR_5 << 4) | DR_0) }, 1};
/*!
* LoRaMac channels which are allowed for the join procedure

View File

@ -182,25 +182,25 @@
* Band 0 definition
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
*/
static const band_t IN865_BAND0 = { 1 , IN865_MAX_TX_POWER, 0, 0, 0, 865000000, 867000000 }; // 100.0 %
static const band_t IN865_BAND0 = { 1, IN865_MAX_TX_POWER, 0, 0, 0, 865000000, 867000000 }; // 100.0 %
/*!
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t IN865_LC1 = { 865062500, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t IN865_LC1 = { 865062500, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t IN865_LC2 = { 865402500, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t IN865_LC2 = { 865402500, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac default channel 3
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t IN865_LC3 = { 865985000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t IN865_LC3 = { 865985000, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac channels which are allowed for the join procedure

View File

@ -55,7 +55,7 @@ public:
LoRaPHYIN865();
virtual ~LoRaPHYIN865();
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset );
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);
private:
/*!

View File

@ -186,25 +186,25 @@
* Band 0 definition
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
*/
static const band_t KR920_BAND0 = { 1 , KR920_MAX_TX_POWER, 0, 0, 0 }; // 100.0 %
static const band_t KR920_BAND0 = { 1, KR920_MAX_TX_POWER, 0, 0, 0 }; // 100.0 %
/*!
* LoRaMac default channel 1
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t KR920_LC1 = { 922100000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t KR920_LC1 = { 922100000, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac default channel 2
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t KR920_LC2 = { 922300000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t KR920_LC2 = { 922300000, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac default channel 3
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
*/
static const channel_params_t KR920_LC3 = { 922500000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 };
static const channel_params_t KR920_LC3 = { 922500000, 0, { ((DR_5 << 4) | DR_0) }, 0 };
/*!
* LoRaMac channels which are allowed for the join procedure
@ -254,7 +254,7 @@ LoRaPHYKR920::LoRaPHYKR920()
channels[2].band = 0;
// Initialize the channels default mask
default_channel_mask[0] = LC( 1 ) + LC( 2 ) + LC( 3 );
default_channel_mask[0] = LC(1) + LC(2) + LC(3);
// Update the channels mask
copy_channel_mask(channel_mask, default_channel_mask, KR920_CHANNEL_MASK_SIZE);
@ -356,7 +356,7 @@ bool LoRaPHYKR920::verify_frequency_for_band(uint32_t freq, uint8_t band) const
// Verify if the frequency is valid. The frequency must be in a specified
// range and can be set to specific values.
if ((tmp_freq >= 920900000) && (tmp_freq <=923300000)) {
if ((tmp_freq >= 920900000) && (tmp_freq <= 923300000)) {
// Range ok, check for specific value
tmp_freq -= 920900000;
if ((tmp_freq % 200000) == 0) {
@ -367,8 +367,8 @@ bool LoRaPHYKR920::verify_frequency_for_band(uint32_t freq, uint8_t band) const
return false;
}
bool LoRaPHYKR920::tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa)
bool LoRaPHYKR920::tx_config(tx_config_params_t *config, int8_t *tx_power,
lorawan_time_t *tx_toa)
{
int8_t phy_dr = datarates_KR920[config->datarate];
@ -393,12 +393,12 @@ bool LoRaPHYKR920::tx_config(tx_config_params_t* config, int8_t* tx_power,
_radio->set_channel(channels[config->channel].frequency);
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
false, true, 0, 0, false, 3000 );
false, true, 0, 0, false, 3000);
// Setup maximum payload lenght of the radio driver
_radio->set_max_payload_length(MODEM_LORA, config->pkt_len);
// Get the time-on-air of the next tx frame
*tx_toa =_radio->time_on_air(MODEM_LORA, config->pkt_len);
*tx_toa = _radio->time_on_air(MODEM_LORA, config->pkt_len);
_radio->unlock();
@ -406,9 +406,9 @@ bool LoRaPHYKR920::tx_config(tx_config_params_t* config, int8_t* tx_power,
return true;
}
lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* params,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregate_timeoff)
lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t *params,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeoff)
{
uint8_t next_channel_idx = 0;
uint8_t nb_enabled_channels = 0;
@ -441,9 +441,9 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
if (nb_enabled_channels > 0) {
for (uint8_t i = 0, j = get_random(0, nb_enabled_channels - 1);
i < KR920_MAX_NB_CHANNELS; i++) {
i < KR920_MAX_NB_CHANNELS; i++) {
next_channel_idx = enabled_channels[j];
j = ( j + 1 ) % nb_enabled_channels;
j = (j + 1) % nb_enabled_channels;
// Perform carrier sense for KR920_CARRIER_SENSE_TIME
// If the channel is free, we can stop the LBT mechanism
@ -452,7 +452,7 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
if (_radio->perform_carrier_sense(MODEM_LORA,
channels[next_channel_idx].frequency,
KR920_RSSI_FREE_TH,
KR920_CARRIER_SENSE_TIME ) == true) {
KR920_CARRIER_SENSE_TIME) == true) {
// Free channel found
*channel = next_channel_idx;
*time = 0;
@ -480,7 +480,7 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
}
}
void LoRaPHYKR920::set_tx_cont_mode(cw_mode_params_t* params, uint32_t given_frequency)
void LoRaPHYKR920::set_tx_cont_mode(cw_mode_params_t *params, uint32_t given_frequency)
{
(void)given_frequency;
@ -495,7 +495,7 @@ void LoRaPHYKR920::set_tx_cont_mode(cw_mode_params_t* params, uint32_t given_fre
// Take the minimum between the max_eirp and params->max_eirp.
// The value of params->max_eirp could have changed during runtime,
// e.g. due to a MAC command.
max_eirp = MIN (params->max_eirp, max_eirp);
max_eirp = MIN(params->max_eirp, max_eirp);
// Calculate physical TX power
phy_tx_power = compute_tx_power(params->tx_power, max_eirp, params->antenna_gain);

View File

@ -56,14 +56,14 @@ public:
virtual bool verify_frequency_for_band(uint32_t freq, uint8_t band) const;
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);
virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power,
lorawan_time_t *tx_toa);
virtual lorawan_status_t set_next_channel(channel_selection_params_t* params, uint8_t* channel,
lorawan_time_t* time,
lorawan_time_t* aggregate_timeOff);
virtual lorawan_status_t set_next_channel(channel_selection_params_t *params, uint8_t *channel,
lorawan_time_t *time,
lorawan_time_t *aggregate_timeOff);
virtual void set_tx_cont_mode(cw_mode_params_t* continuousWave,
virtual void set_tx_cont_mode(cw_mode_params_t *continuousWave,
uint32_t frequency = 0);

View File

@ -192,10 +192,9 @@ static const uint32_t bandwidths_US915[] = {125000, 125000, 125000, 125000, 5000
/*!
* Up/Down link data rates offset definition
*/
static const int8_t datarate_offsets_US915[5][4] =
{
{ DR_10, DR_9 , DR_8 , DR_8 }, // DR_0
{ DR_11, DR_10, DR_9 , DR_8 }, // DR_1
static const int8_t datarate_offsets_US915[5][4] = {
{ DR_10, DR_9, DR_8, DR_8 }, // DR_0
{ DR_11, DR_10, DR_9, DR_8 }, // DR_1
{ DR_12, DR_11, DR_10, DR_9 }, // DR_2
{ DR_13, DR_12, DR_11, DR_10 }, // DR_3
{ DR_13, DR_13, DR_12, DR_11 }, // DR_4
@ -222,13 +221,13 @@ LoRaPHYUS915::LoRaPHYUS915()
// 125 kHz channels - Upstream
for (uint8_t i = 0; i < US915_MAX_NB_CHANNELS - 8; i++) {
channels[i].frequency = 902300000 + i * 200000;
channels[i].dr_range.value = ( DR_3 << 4) | DR_0;
channels[i].dr_range.value = (DR_3 << 4) | DR_0;
channels[i].band = 0;
}
// 500 kHz channels - Upstream
for (uint8_t i = US915_MAX_NB_CHANNELS - 8; i < US915_MAX_NB_CHANNELS; i++) {
channels[i].frequency = 903000000 + (i - ( US915_MAX_NB_CHANNELS - 8)) * 1600000;
channels[i].dr_range.value = ( DR_4 << 4) | DR_4;
channels[i].frequency = 903000000 + (i - (US915_MAX_NB_CHANNELS - 8)) * 1600000;
channels[i].dr_range.value = (DR_4 << 4) | DR_4;
channels[i].band = 0;
}
@ -325,16 +324,16 @@ int8_t LoRaPHYUS915::limit_tx_power(int8_t tx_power, int8_t max_band_tx_power,
int8_t tx_power_out = tx_power;
// Limit tx power to the band max
tx_power_out = MAX (tx_power, max_band_tx_power);
tx_power_out = MAX(tx_power, max_band_tx_power);
if (datarate == DR_4) {
// Limit tx power to max 26dBm
tx_power_out = MAX (tx_power, TX_POWER_2);
tx_power_out = MAX(tx_power, TX_POWER_2);
} else {
if (num_active_channels(channel_mask, 0, 4) < 50) {
// Limit tx power to max 21dBm
tx_power_out = MAX (tx_power, TX_POWER_5);
tx_power_out = MAX(tx_power, TX_POWER_5);
}
}
@ -350,7 +349,7 @@ void LoRaPHYUS915::restore_default_channels()
intersect_channel_mask(channel_mask, current_channel_mask, US915_CHANNEL_MASK_SIZE);
}
bool LoRaPHYUS915::rx_config(rx_config_params_t* config)
bool LoRaPHYUS915::rx_config(rx_config_params_t *config)
{
int8_t dr = config->datarate;
uint8_t max_payload = 0;
@ -410,8 +409,8 @@ bool LoRaPHYUS915::rx_config(rx_config_params_t* config)
return true;
}
bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa)
bool LoRaPHYUS915::tx_config(tx_config_params_t *config, int8_t *tx_power,
lorawan_time_t *tx_toa)
{
int8_t phy_dr = datarates_US915[config->datarate];
int8_t tx_power_limited = limit_tx_power(config->tx_power,
@ -422,7 +421,7 @@ bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
int8_t phy_tx_power = 0;
// Calculate physical TX power
phy_tx_power = compute_tx_power( tx_power_limited, US915_DEFAULT_MAX_ERP, 0 );
phy_tx_power = compute_tx_power(tx_power_limited, US915_DEFAULT_MAX_ERP, 0);
_radio->lock();
@ -445,9 +444,9 @@ bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
return true;
}
uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out, uint8_t* nb_bytes_parsed)
uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t *params,
int8_t *dr_out, int8_t *tx_power_out,
uint8_t *nb_rep_out, uint8_t *nb_bytes_parsed)
{
uint8_t status = 0x07;
@ -504,7 +503,7 @@ uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
// FCC 15.247 paragraph F mandates to hop on at least 2 125 kHz channels
if ((adr_settings.datarate < DR_4) &&
(num_active_channels(temp_channel_masks, 0, 4) < 2)) {
(num_active_channels(temp_channel_masks, 0, 4) < 2)) {
status &= 0xFE; // Channel mask KO
@ -543,7 +542,7 @@ uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
return status;
}
uint8_t LoRaPHYUS915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
uint8_t LoRaPHYUS915::accept_rx_param_setup_req(rx_param_setup_req_t *params)
{
uint8_t status = 0x07;
uint32_t freq = params->frequency;
@ -572,8 +571,7 @@ uint8_t LoRaPHYUS915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
}
// Verify datarate offset
if (val_in_range( params->dr_offset, US915_MIN_RX1_DR_OFFSET, US915_MAX_RX1_DR_OFFSET ) == 0 )
{
if (val_in_range(params->dr_offset, US915_MIN_RX1_DR_OFFSET, US915_MAX_RX1_DR_OFFSET) == 0) {
status &= 0xFB; // Rx1DrOffset range KO
}
@ -593,9 +591,9 @@ int8_t LoRaPHYUS915::get_alternate_DR(uint8_t nb_trials)
return datarate;
}
lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* params,
uint8_t* channel, lorawan_time_t* time,
lorawan_time_t* aggregate_timeOff)
lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t *params,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeOff)
{
uint8_t nb_enabled_channels = 0;
uint8_t delay_tx = 0;
@ -654,13 +652,13 @@ lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* para
}
}
void LoRaPHYUS915::set_tx_cont_mode(cw_mode_params_t* params, uint32_t given_frequency)
void LoRaPHYUS915::set_tx_cont_mode(cw_mode_params_t *params, uint32_t given_frequency)
{
(void)given_frequency;
int8_t tx_power_limited = limit_tx_power(params->tx_power,
bands[channels[params->channel].band].max_tx_pwr,
params->datarate);
bands[channels[params->channel].band].max_tx_pwr,
params->datarate);
int8_t phyTxPower = 0;
uint32_t frequency = channels[params->channel].frequency;
@ -681,7 +679,7 @@ uint8_t LoRaPHYUS915::apply_DR_offset(int8_t dr, int8_t dr_offset)
void LoRaPHYUS915::intersect_channel_mask(const uint16_t *source,
uint16_t *destination, uint8_t size)
uint16_t *destination, uint8_t size)
{
for (uint8_t i = 0; i < size; i++) {
destination[i] &= source[i];
@ -689,9 +687,9 @@ void LoRaPHYUS915::intersect_channel_mask(const uint16_t *source,
}
void LoRaPHYUS915::fill_channel_mask_with_fsb(const uint16_t *expectation,
const uint16_t *fsb_mask,
uint16_t *destination,
uint8_t size)
const uint16_t *fsb_mask,
uint16_t *destination,
uint8_t size)
{
for (uint8_t i = 0; i < size; i++) {
destination[i] = expectation[i] & fsb_mask[i];
@ -700,7 +698,7 @@ void LoRaPHYUS915::fill_channel_mask_with_fsb(const uint16_t *expectation,
}
void LoRaPHYUS915::fill_channel_mask_with_value(uint16_t *channel_mask,
uint16_t value, uint8_t size)
uint16_t value, uint8_t size)
{
for (uint8_t i = 0; i < size; i++) {
channel_mask[i] = value;

View File

@ -56,24 +56,24 @@ public:
virtual void restore_default_channels();
virtual bool rx_config(rx_config_params_t* config);
virtual bool rx_config(rx_config_params_t *config);
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);
virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power,
lorawan_time_t *tx_toa);
virtual uint8_t link_ADR_request(adr_req_params_t* params,
int8_t* dr_out, int8_t* tx_power_out,
uint8_t* nb_rep_out,
uint8_t* nb_bytes_parsed);
virtual uint8_t link_ADR_request(adr_req_params_t *params,
int8_t *dr_out, int8_t *tx_power_out,
uint8_t *nb_rep_out,
uint8_t *nb_bytes_parsed);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t* params);
virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params);
virtual int8_t get_alternate_DR(uint8_t nb_trials);
virtual lorawan_status_t set_next_channel(channel_selection_params_t* params, uint8_t* channel,
lorawan_time_t* time, lorawan_time_t* aggregate_timeOff);
virtual lorawan_status_t set_next_channel(channel_selection_params_t *params, uint8_t *channel,
lorawan_time_t *time, lorawan_time_t *aggregate_timeOff);
virtual void set_tx_cont_mode(cw_mode_params_t* continuousWave,
virtual void set_tx_cont_mode(cw_mode_params_t *continuousWave,
uint32_t frequency = 0);
virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset);

View File

@ -307,7 +307,7 @@ typedef struct {
/*!
* A pointer to the payload containing the MAC commands.
*/
const uint8_t* payload;
const uint8_t *payload;
/*!
* The size of the payload.
*/
@ -402,7 +402,7 @@ typedef struct verify_adr_params_s {
/*!
* A pointer to the first element of the channels mask.
*/
uint16_t* channel_mask;
uint16_t *channel_mask;
} verify_adr_params_t;
/**

View File

@ -48,38 +48,38 @@
#define mbed_lora_concat(x) mbed_lora_concat_(x)
#define LORA_REGION mbed_lora_concat(MBED_CONF_LORA_PHY)
#if LORA_REGION == LORA_REGION_EU868
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
#define LoRaPHY_region LoRaPHYEU868
#elif LORA_REGION == LORA_REGION_AS923
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
#define LoRaPHY_region LoRaPHYAS923
#elif LORA_REGION == LORA_REGION_AU915
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
#define LoRaPHY_region LoRaPHYAU915
#elif LORA_REGION == LORA_REGION_CN470
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
#define LoRaPHY_region LoRaPHYCN470
#elif LORA_REGION == LORA_REGION_CN779
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
#define LoRaPHY_region LoRaPHYCN779
#elif LORA_REGION == LORA_REGION_EU433
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
#define LoRaPHY_region LoRaPHYEU433
#elif LORA_REGION == LORA_REGION_IN865
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
#define LoRaPHY_region LoRaPHYIN865
#elif LORA_REGION == LORA_REGION_KR920
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
#define LoRaPHY_region LoRaPHYKR920
#elif LORA_REGION == LORA_REGION_US915
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
#define LoRaPHY_region LoRaPHYUS915
#else
#error "Invalid region configuration, update mbed_app.json with correct MBED_CONF_LORA_PHY value"
#endif //MBED_CONF_LORA_PHY == VALUE
#if LORA_REGION == LORA_REGION_EU868
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
#define LoRaPHY_region LoRaPHYEU868
#elif LORA_REGION == LORA_REGION_AS923
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
#define LoRaPHY_region LoRaPHYAS923
#elif LORA_REGION == LORA_REGION_AU915
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
#define LoRaPHY_region LoRaPHYAU915
#elif LORA_REGION == LORA_REGION_CN470
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
#define LoRaPHY_region LoRaPHYCN470
#elif LORA_REGION == LORA_REGION_CN779
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
#define LoRaPHY_region LoRaPHYCN779
#elif LORA_REGION == LORA_REGION_EU433
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
#define LoRaPHY_region LoRaPHYEU433
#elif LORA_REGION == LORA_REGION_IN865
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
#define LoRaPHY_region LoRaPHYIN865
#elif LORA_REGION == LORA_REGION_KR920
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
#define LoRaPHY_region LoRaPHYKR920
#elif LORA_REGION == LORA_REGION_US915
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
#define LoRaPHY_region LoRaPHYUS915
#else
#error "Must set LoRa PHY layer parameters."
#error "Invalid region configuration, update mbed_app.json with correct MBED_CONF_LORA_PHY value"
#endif //MBED_CONF_LORA_PHY == VALUE
#else
#error "Must set LoRa PHY layer parameters."
#endif //MBED_CONF_LORA_PHY
#endif // LORAPHY_TARGET

View File

@ -34,7 +34,7 @@ void LoRaWANTimeHandler::activate_timer_subsystem(events::EventQueue *queue)
_queue = queue;
}
lorawan_time_t LoRaWANTimeHandler::get_current_time( void )
lorawan_time_t LoRaWANTimeHandler::get_current_time(void)
{
const uint32_t current_time = _queue->tick();
return (lorawan_time_t)current_time;

View File

@ -26,8 +26,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "lorawan_data_structures.h"
class LoRaWANTimeHandler
{
class LoRaWANTimeHandler {
public:
LoRaWANTimeHandler();
~LoRaWANTimeHandler();
@ -62,7 +61,7 @@ public:
* @param [in] obj The structure containing the timer object parameters.
* @param [in] callback The function callback called at the end of the timeout.
*/
void init(timer_event_t &obj, mbed::Callback<void()> callback);
void init(timer_event_t &obj, mbed::Callback<void()> callback);
/** Starts and adds the timer object to the list of timer events.
*

View File

@ -78,8 +78,8 @@ typedef uint32_t lorawan_time_t;
*/
// reject if user tries to set more than MTU
#if MBED_CONF_LORA_TX_MAX_SIZE > 255
#warning "Cannot set TX Max size more than MTU=255"
#define MBED_CONF_LORA_TX_MAX_SIZE 255
#warning "Cannot set TX Max size more than MTU=255"
#define MBED_CONF_LORA_TX_MAX_SIZE 255
#endif
/*!

View File

@ -59,10 +59,10 @@ static void add_dns_addr_to_dns_list_index(const u8_t addr_type, const u8_t inde
if (addr_type == IPADDR_TYPE_V6) {
/* 2001:4860:4860::8888 google */
ip_addr_t ipv6_dns_addr = IPADDR6_INIT(
PP_HTONL(0x20014860UL),
PP_HTONL(0x48600000UL),
PP_HTONL(0x00000000UL),
PP_HTONL(0x00008888UL));
PP_HTONL(0x20014860UL),
PP_HTONL(0x48600000UL),
PP_HTONL(0x00000000UL),
PP_HTONL(0x00008888UL));
dns_setserver(index, &ipv6_dns_addr);
}
#endif
@ -186,7 +186,7 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
if (interface->client_callback && connectedStatusPrev != interface->connected
&& interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ {
&& interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
}
}
@ -235,7 +235,7 @@ void LWIP::Interface::netif_status_irq(struct netif *netif)
}
if (interface->client_callback && (connectedStatusPrev != interface->connected)
&& interface->connected != NSAPI_STATUS_DISCONNECTED) /* advertised by bring_down */ {
&& interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
}
}
@ -262,8 +262,8 @@ static void mbed_lwip_clear_ipv6_addresses(struct netif *netif)
char *LWIP::Interface::get_mac_address(char *buf, nsapi_size_t buflen)
{
(void) snprintf(buf, buflen, "%02x:%02x:%02x:%02x:%02x:%02x",
netif.hwaddr[0], netif.hwaddr[1], netif.hwaddr[2],
netif.hwaddr[3], netif.hwaddr[4], netif.hwaddr[5]);
netif.hwaddr[0], netif.hwaddr[1], netif.hwaddr[2],
netif.hwaddr[3], netif.hwaddr[4], netif.hwaddr[5]);
return buf;
}
@ -317,9 +317,9 @@ char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
}
LWIP::Interface::Interface() :
hw(NULL), has_addr_state(0),
connected(NSAPI_STATUS_DISCONNECTED),
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false)
hw(NULL), has_addr_state(0),
connected(NSAPI_STATUS_DISCONNECTED),
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false)
{
memset(&netif, 0, sizeof netif);
@ -379,9 +379,9 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN
if (!netif_add(&interface->netif,
#if LWIP_IPV4
0, 0, 0,
0, 0, 0,
#endif
interface, &LWIP::Interface::emac_if_init, tcpip_input)) {
interface, &LWIP::Interface::emac_if_init, tcpip_input)) {
return NSAPI_ERROR_DEVICE_ERROR;
}
@ -497,8 +497,8 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
ip4_addr_t gw_addr;
if (!inet_aton(ip, &ip_addr) ||
!inet_aton(netmask, &netmask_addr) ||
!inet_aton(gw, &gw_addr)) {
!inet_aton(netmask, &netmask_addr) ||
!inet_aton(gw, &gw_addr)) {
return NSAPI_ERROR_PARAMETER;
}
@ -512,14 +512,14 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
}
if (ppp) {
err_t err = ppp_lwip_connect(hw);
if (err) {
connected = NSAPI_STATUS_DISCONNECTED;
if (client_callback) {
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
}
return err_remap(err);
}
err_t err = ppp_lwip_connect(hw);
if (err) {
connected = NSAPI_STATUS_DISCONNECTED;
if (client_callback) {
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
}
return err_remap(err);
}
}
if (!netif_is_link_up(&netif)) {
@ -598,16 +598,16 @@ nsapi_error_t LWIP::Interface::bringdown()
if (ppp) {
/* this is a blocking call, returns when PPP is properly closed */
err_t err = ppp_lwip_disconnect(hw);
if (err) {
return err_remap(err);
}
MBED_ASSERT(!netif_is_link_up(&netif));
/*if (netif_is_link_up(&netif)) {
if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) {
return NSAPI_ERROR_DEVICE_ERROR;
}
}*/
err_t err = ppp_lwip_disconnect(hw);
if (err) {
return err_remap(err);
}
MBED_ASSERT(!netif_is_link_up(&netif));
/*if (netif_is_link_up(&netif)) {
if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) {
return NSAPI_ERROR_DEVICE_ERROR;
}
}*/
} else {
netif_set_down(&netif);
}

View File

@ -74,8 +74,7 @@ err_t LWIP::Interface::emac_igmp_mac_filter(struct netif *netif, const ip4_addr_
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
switch (action) {
case NETIF_ADD_MAC_FILTER:
{
case NETIF_ADD_MAC_FILTER: {
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
uint8_t addr[6];
addr[0] = LL_IP4_MULTICAST_ADDR_0;
@ -112,8 +111,7 @@ err_t LWIP::Interface::emac_mld_mac_filter(struct netif *netif, const ip6_addr_t
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
switch (action) {
case NETIF_ADD_MAC_FILTER:
{
case NETIF_ADD_MAC_FILTER: {
uint32_t group32 = ntohl(group->addr[3]);
uint8_t addr[6];
addr[0] = LL_IP6_MULTICAST_ADDR_0;

View File

@ -38,7 +38,7 @@
#include "LWIPStack.h"
#ifndef LWIP_SOCKET_MAX_MEMBERSHIPS
#define LWIP_SOCKET_MAX_MEMBERSHIPS 4
#define LWIP_SOCKET_MAX_MEMBERSHIPS 4
#endif
void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
@ -54,8 +54,8 @@ void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
for (int i = 0; i < MEMP_NUM_NETCONN; i++) {
if (lwip.arena[i].in_use
&& lwip.arena[i].conn == nc
&& lwip.arena[i].cb) {
&& lwip.arena[i].conn == nc
&& lwip.arena[i].cb) {
lwip.arena[i].cb(lwip.arena[i].data);
}
}
@ -101,15 +101,15 @@ static bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in)
{
#if LWIP_IPV6
if (in->version == NSAPI_IPv6) {
IP_SET_TYPE(out, IPADDR_TYPE_V6);
SMEMCPY(ip_2_ip6(out), in->bytes, sizeof(ip6_addr_t));
return true;
IP_SET_TYPE(out, IPADDR_TYPE_V6);
SMEMCPY(ip_2_ip6(out), in->bytes, sizeof(ip6_addr_t));
return true;
}
#if !LWIP_IPV4
/* For bind() and other purposes, need to accept "null" of other type */
/* (People use IPv4 0.0.0.0 as a general null) */
if (in->version == NSAPI_UNSPEC ||
(in->version == NSAPI_IPv4 && all_zeros(in->bytes, 4))) {
(in->version == NSAPI_IPv4 && all_zeros(in->bytes, 4))) {
ip_addr_set_zero_ip6(out);
return true;
}
@ -118,14 +118,14 @@ static bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in)
#if LWIP_IPV4
if (in->version == NSAPI_IPv4) {
IP_SET_TYPE(out, IPADDR_TYPE_V4);
SMEMCPY(ip_2_ip4(out), in->bytes, sizeof(ip4_addr_t));
return true;
IP_SET_TYPE(out, IPADDR_TYPE_V4);
SMEMCPY(ip_2_ip4(out), in->bytes, sizeof(ip4_addr_t));
return true;
}
#if !LWIP_IPV6
/* For symmetry with above, accept IPv6 :: as a general null */
if (in->version == NSAPI_UNSPEC ||
(in->version == NSAPI_IPv6 && all_zeros(in->bytes, 16))) {
(in->version == NSAPI_IPv6 && all_zeros(in->bytes, 16))) {
ip_addr_set_zero_ip4(out);
return true;
}
@ -273,7 +273,7 @@ nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
#if LWIP_IPV6
// Enable IPv6 (or dual-stack)
lwip_proto = (enum netconn_type) (lwip_proto | NETCONN_TYPE_IPV6);
lwip_proto = (enum netconn_type)(lwip_proto | NETCONN_TYPE_IPV6);
#endif
s->conn = netconn_new_with_callback(lwip_proto, &LWIP::socket_callback);
@ -485,7 +485,8 @@ nsapi_size_or_error_t LWIP::socket_recvfrom(nsapi_socket_t handle, SocketAddress
return recv;
}
int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr) {
int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr)
{
uint32_t count = 0;
uint32_t index = 0;
// Set upper limit on while loop, should break out when the membership pair is found
@ -493,7 +494,7 @@ int32_t LWIP::find_multicast_member(const struct mbed_lwip_socket *s, const nsap
index = next_registered_multicast_member(s, index);
if (memcmp(&s->multicast_memberships[index].imr_multiaddr, &imr->imr_multiaddr, sizeof(nsapi_addr_t)) == 0 &&
memcmp(&s->multicast_memberships[index].imr_interface, &imr->imr_interface, sizeof(nsapi_addr_t)) == 0) {
memcmp(&s->multicast_memberships[index].imr_interface, &imr->imr_interface, sizeof(nsapi_addr_t)) == 0) {
return index;
}
count++;
@ -522,7 +523,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
return NSAPI_ERROR_UNSUPPORTED;
}
s->conn->pcb.tcp->keep_idle = *(int*)optval;
s->conn->pcb.tcp->keep_idle = *(int *)optval;
return 0;
case NSAPI_KEEPINTVL:
@ -530,7 +531,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
return NSAPI_ERROR_UNSUPPORTED;
}
s->conn->pcb.tcp->keep_intvl = *(int*)optval;
s->conn->pcb.tcp->keep_intvl = *(int *)optval;
return 0;
#endif
@ -582,11 +583,11 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
if (optname == NSAPI_ADD_MEMBERSHIP) {
if (!s->multicast_memberships) {
// First multicast join on this socket, allocate space for membership tracking
s->multicast_memberships = (nsapi_ip_mreq_t*)malloc(sizeof(nsapi_ip_mreq_t) * LWIP_SOCKET_MAX_MEMBERSHIPS);
s->multicast_memberships = (nsapi_ip_mreq_t *)malloc(sizeof(nsapi_ip_mreq_t) * LWIP_SOCKET_MAX_MEMBERSHIPS);
if (!s->multicast_memberships) {
return NSAPI_ERROR_NO_MEMORY;
}
} else if(s->multicast_memberships_count == LWIP_SOCKET_MAX_MEMBERSHIPS) {
} else if (s->multicast_memberships_count == LWIP_SOCKET_MAX_MEMBERSHIPS) {
return NSAPI_ERROR_NO_MEMORY;
}
@ -598,16 +599,16 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
adaptation.lock();
#if LWIP_IPV4
#if LWIP_IPV4
if (IP_IS_V4(&if_addr)) {
igmp_err = igmp_joingroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
}
#endif
#if LWIP_IPV6
#endif
#if LWIP_IPV6
if (IP_IS_V6(&if_addr)) {
igmp_err = mld6_joingroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
}
#endif
#endif
adaptation.unlock();
@ -626,22 +627,22 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
adaptation.lock();
#if LWIP_IPV4
#if LWIP_IPV4
if (IP_IS_V4(&if_addr)) {
igmp_err = igmp_leavegroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
}
#endif
#if LWIP_IPV6
#endif
#if LWIP_IPV6
if (IP_IS_V6(&if_addr)) {
igmp_err = mld6_leavegroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
}
#endif
#endif
adaptation.unlock();
}
return err_remap(igmp_err);
}
}
default:
return NSAPI_ERROR_UNSUPPORTED;
@ -662,7 +663,8 @@ void LWIP::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *
s->data = data;
}
LWIP &LWIP::get_instance() {
LWIP &LWIP::get_instance()
{
static LWIP lwip;
return lwip;
}
@ -672,7 +674,8 @@ LWIP &LWIP::get_instance() {
#define LWIP 0x11991199
#if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP
#undef LWIP
OnboardNetworkStack &OnboardNetworkStack::get_default_instance() {
OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
{
return LWIP::get_instance();
}
#endif

View File

@ -53,7 +53,7 @@ public:
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true
);
);
/** Disconnect interface from the network
*
@ -120,24 +120,24 @@ public:
static void netif_status_irq(struct netif *netif);
static Interface *our_if_from_netif(struct netif *netif);
#if LWIP_ETHERNET
#if LWIP_ETHERNET
static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
void emac_input(emac_mem_buf_t *buf);
void emac_state_change(bool up);
#if LWIP_IGMP
#if LWIP_IGMP
static err_t emac_igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
#endif
#if LWIP_IPV6_MLD
#endif
#if LWIP_IPV6_MLD
static err_t emac_mld_mac_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action);
#endif
#endif
static err_t emac_if_init(struct netif *netif);
#endif
#endif
union {
#if LWIP_ETHERNET
#if LWIP_ETHERNET
EMAC *emac; /**< HW specific emac implementation */
#endif
#endif
void *hw; /**< alternative implementation pointer - used for PPP */
};
@ -147,17 +147,17 @@ public:
osSemaphoreId_t unlinked;
mbed_rtos_storage_semaphore_t has_any_addr_sem;
osSemaphoreId_t has_any_addr;
#define HAS_ANY_ADDR 1
#if PREF_ADDR_TIMEOUT
#define HAS_ANY_ADDR 1
#if PREF_ADDR_TIMEOUT
mbed_rtos_storage_semaphore_t has_pref_addr_sem;
osSemaphoreId_t has_pref_addr;
#define HAS_PREF_ADDR 2
#endif
#if BOTH_ADDR_TIMEOUT
#define HAS_PREF_ADDR 2
#endif
#if BOTH_ADDR_TIMEOUT
mbed_rtos_storage_semaphore_t has_both_addr_sem;
osSemaphoreId_t has_both_addr;
#define HAS_BOTH_ADDR 4
#endif
#define HAS_BOTH_ADDR 4
#endif
char has_addr_state;
nsapi_connection_status_t connected;
bool dhcp_started;
@ -301,7 +301,7 @@ protected:
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address=0);
nsapi_socket_t *handle, SocketAddress *address = 0);
/** Send data over a TCP socket
*
@ -487,21 +487,29 @@ private:
struct mbed_lwip_socket *arena_alloc();
void arena_dealloc(struct mbed_lwip_socket *s);
static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index) {
while (!(s->multicast_memberships_registry & (0x0001 << index))) { index++; }
static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
{
while (!(s->multicast_memberships_registry & (0x0001 << index))) {
index++;
}
return index;
}
static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index) {
while ((s->multicast_memberships_registry & (0x0001 << index))) { index++; }
static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t index)
{
while ((s->multicast_memberships_registry & (0x0001 << index))) {
index++;
}
return index;
}
static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index) {
static void set_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
{
s->multicast_memberships_registry |= (0x0001 << index);
}
static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index) {
static void clear_multicast_member_registry_bit(struct mbed_lwip_socket *s, uint32_t index)
{
s->multicast_memberships_registry &= ~(0x0001 << index);
}
static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);

View File

@ -27,7 +27,8 @@
#include "netsocket/nsapi_types.h"
/* LWIP error remapping */
nsapi_error_t LWIP::err_remap(err_t err) {
nsapi_error_t LWIP::err_remap(err_t err)
{
switch (err) {
case ERR_OK:
case ERR_CLSD:
@ -103,7 +104,7 @@ bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
if (IP_IS_V6(ip_addr)) {
for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
ip6_addr_cmp(netif_ip6_addr(netif, i), ip_2_ip6(ip_addr))) {
ip6_addr_cmp(netif_ip6_addr(netif, i), ip_2_ip6(ip_addr))) {
return true;
}
}
@ -113,7 +114,7 @@ bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
#if LWIP_IPV4
if (IP_IS_V4(ip_addr)) {
if (!ip4_addr_isany(netif_ip4_addr(netif)) &&
ip4_addr_cmp(netif_ip4_addr(netif), ip_2_ip4(ip_addr))) {
ip4_addr_cmp(netif_ip4_addr(netif), ip_2_ip4(ip_addr))) {
return true;
}
}
@ -185,7 +186,7 @@ void LWIP::arena_dealloc(struct mbed_lwip_socket *s)
index = next_registered_multicast_member(s, index);
setsockopt(s, NSAPI_SOCKET, NSAPI_DROP_MEMBERSHIP, &s->multicast_memberships[index],
sizeof(s->multicast_memberships[index]));
sizeof(s->multicast_memberships[index]));
index++;
}

View File

@ -25,7 +25,7 @@
#include <sys/time.h>
#endif
// Operating System
// Operating System
#define NO_SYS 0
#if MBED_CONF_LWIP_IPV4_ENABLED

View File

@ -120,7 +120,7 @@ static void ppp_link_status(ppp_pcb *pcb, int err_code, void *ctx)
{
nsapi_error_t mapped_err_code = NSAPI_ERROR_NO_CONNECTION;
switch(err_code) {
switch (err_code) {
case PPPERR_NONE:
mapped_err_code = NSAPI_ERROR_OK;
tr_info("status_cb: Connected");
@ -247,7 +247,7 @@ static void ppp_input()
fhs.fh = my_stream;
fhs.events = POLLIN;
poll(&fhs, 1, 0);
if (fhs.revents & (POLLHUP|POLLERR|POLLNVAL)) {
if (fhs.revents & (POLLHUP | POLLERR | POLLNVAL)) {
handle_modem_hangup();
return;
}
@ -268,7 +268,8 @@ static void ppp_input()
return;
}
static void stream_cb() {
static void stream_cb()
{
if (my_stream && !event_queued) {
event_queued = true;
if (event_queue->call(callback(ppp_input)) == 0) {
@ -280,17 +281,17 @@ static void stream_cb() {
extern "C" err_t ppp_lwip_connect(void *pcb)
{
#if PPP_AUTH_SUPPORT
ppp_set_auth(my_ppp_pcb, PPPAUTHTYPE_ANY, login, pwd);
ppp_set_auth(my_ppp_pcb, PPPAUTHTYPE_ANY, login, pwd);
#endif //PPP_AUTH_SUPPORT
ppp_active = true;
err_t ret = ppp_connect(my_ppp_pcb, 0);
// lwIP's ppp.txt says input must not be called until after connect
if (ret == ERR_OK) {
my_stream->sigio(callback(stream_cb));
} else {
ppp_active = false;
}
return ret;
ppp_active = true;
err_t ret = ppp_connect(my_ppp_pcb, 0);
// lwIP's ppp.txt says input must not be called until after connect
if (ret == ERR_OK) {
my_stream->sigio(callback(stream_cb));
} else {
ppp_active = false;
}
return ret;
}
extern "C" err_t ppp_lwip_disconnect(void *pcb)
@ -315,7 +316,7 @@ extern "C" nsapi_error_t ppp_lwip_if_init(void *pcb, struct netif *netif, const
if (!my_ppp_pcb) {
my_ppp_pcb = pppos_create(netif,
ppp_output, ppp_link_status, NULL);
ppp_output, ppp_link_status, NULL);
if (!my_ppp_pcb) {
return NSAPI_ERROR_DEVICE_ERROR;
}

View File

@ -57,7 +57,7 @@ public:
}
/** Create a SocketAddress from a raw IP address and port
*
*
* To construct from a host name, use NetworkInterface::gethostbyname
*
* @param addr Raw IP address

View File

@ -22,7 +22,7 @@ TCPSocket::TCPSocket()
{
}
TCPSocket::TCPSocket(TCPSocket* parent, nsapi_socket_t socket, SocketAddress address)
TCPSocket::TCPSocket(TCPSocket *parent, nsapi_socket_t socket, SocketAddress address)
{
_socket = socket,
_stack = parent->_stack;

View File

@ -70,12 +70,14 @@ public:
* @param stack Network stack as target for socket
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t open(NetworkStack *stack) {
virtual nsapi_error_t open(NetworkStack *stack)
{
return tcp_socket.open(stack);
}
template <typename S>
nsapi_error_t open(S *stack) {
nsapi_error_t open(S *stack)
{
return open(nsapi_create_stack(stack));
}

View File

@ -33,8 +33,8 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
_clicert(NULL),
#endif
_ssl_conf(NULL),
_connect_transport(control==TRANSPORT_CONNECT || control==TRANSPORT_CONNECT_AND_CLOSE),
_close_transport(control==TRANSPORT_CLOSE || control==TRANSPORT_CONNECT_AND_CLOSE),
_connect_transport(control == TRANSPORT_CONNECT || control == TRANSPORT_CONNECT_AND_CLOSE),
_close_transport(control == TRANSPORT_CLOSE || control == TRANSPORT_CONNECT_AND_CLOSE),
_handshake_completed(false),
_cacert_allocated(false),
_clicert_allocated(false),
@ -50,7 +50,8 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
}
}
TLSSocketWrapper::~TLSSocketWrapper() {
TLSSocketWrapper::~TLSSocketWrapper()
{
if (_transport) {
close();
}
@ -90,7 +91,7 @@ nsapi_error_t TLSSocketWrapper::set_root_ca_cert(const void *root_ca, size_t len
/* Parse CA certification */
int ret;
if ((ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(root_ca),
len)) != 0) {
len)) != 0) {
print_mbedtls_error("mbedtls_x509_crt_parse", ret);
return NSAPI_ERROR_PARAMETER;
}
@ -111,7 +112,7 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const char *client_cert_pem,
}
nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, size_t client_cert_len,
const void *client_private_key_pem, size_t client_private_key_len)
const void *client_private_key_pem, size_t client_private_key_len)
{
#if !defined(MBEDTLS_X509_CRT_PARSE_C)
return NSAPI_ERROR_UNSUPPORTED;
@ -120,14 +121,14 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, siz
int ret;
mbedtls_x509_crt *crt = new mbedtls_x509_crt;
mbedtls_x509_crt_init(crt);
if((ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(client_cert),
client_cert_len)) != 0) {
if ((ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(client_cert),
client_cert_len)) != 0) {
print_mbedtls_error("mbedtls_x509_crt_parse", ret);
return NSAPI_ERROR_PARAMETER;
}
mbedtls_pk_init(&_pkctx);
if((ret = mbedtls_pk_parse_key(&_pkctx, static_cast<const unsigned char *>(client_private_key_pem),
client_private_key_len, NULL, 0)) != 0) {
if ((ret = mbedtls_pk_parse_key(&_pkctx, static_cast<const unsigned char *>(client_private_key_pem),
client_private_key_len, NULL, 0)) != 0) {
print_mbedtls_error("mbedtls_pk_parse_key", ret);
return NSAPI_ERROR_PARAMETER;
}
@ -139,7 +140,8 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, siz
}
nsapi_error_t TLSSocketWrapper::do_handshake() {
nsapi_error_t TLSSocketWrapper::do_handshake()
{
nsapi_error_t _error;
const char DRBG_PERS[] = "mbed TLS client";
@ -153,8 +155,8 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
*/
int ret;
if ((ret = mbedtls_ctr_drbg_seed(&_ctr_drbg, mbedtls_entropy_func, &_entropy,
(const unsigned char *) DRBG_PERS,
sizeof (DRBG_PERS))) != 0) {
(const unsigned char *) DRBG_PERS,
sizeof(DRBG_PERS))) != 0) {
print_mbedtls_error("mbedtls_crt_drbg_init", ret);
_error = ret;
return _error;
@ -177,7 +179,7 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
return _error;
}
mbedtls_ssl_set_bio(&_ssl, this, ssl_send, ssl_recv, NULL );
mbedtls_ssl_set_bio(&_ssl, this, ssl_send, ssl_recv, NULL);
#ifdef MBEDTLS_X509_CRT_PARSE_C
/* Start the handshake, the rest will be done in onReceive() */
@ -189,7 +191,7 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
do {
ret = mbedtls_ssl_handshake(&_ssl);
} while (ret != 0 && (ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE));
ret == MBEDTLS_ERR_SSL_WANT_WRITE));
if (ret < 0) {
print_mbedtls_error("mbedtls_ssl_handshake", ret);
return ret;
@ -205,13 +207,13 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
#ifdef MBEDTLS_X509_CRT_PARSE_C
/* Prints the server certificate and verify it. */
const size_t buf_size = 1024;
char* buf = new char[buf_size];
char *buf = new char[buf_size];
mbedtls_x509_crt_info(buf, buf_size, "\r ",
mbedtls_ssl_get_peer_cert(&_ssl));
mbedtls_ssl_get_peer_cert(&_ssl));
tr_debug("Server certificate:\r\n%s\r\n", buf);
uint32_t flags = mbedtls_ssl_get_verify_result(&_ssl);
if( flags != 0 ) {
if (flags != 0) {
/* Verification failed. */
mbedtls_x509_crt_verify_info(buf, buf_size, "\r ! ", flags);
tr_error("Certificate verification failed:\r\n%s", buf);
@ -228,7 +230,8 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
}
nsapi_error_t TLSSocketWrapper::send(const void *data, nsapi_size_t size) {
nsapi_error_t TLSSocketWrapper::send(const void *data, nsapi_size_t size)
{
int ret;
if (!_transport) {
@ -239,7 +242,7 @@ nsapi_error_t TLSSocketWrapper::send(const void *data, nsapi_size_t size) {
ret = mbedtls_ssl_write(&_ssl, (const unsigned char *) data, size);
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE ||
ret == MBEDTLS_ERR_SSL_WANT_READ) {
ret == MBEDTLS_ERR_SSL_WANT_READ) {
// translate to socket error
return NSAPI_ERROR_WOULD_BLOCK;
}
@ -255,7 +258,8 @@ nsapi_size_or_error_t TLSSocketWrapper::sendto(const SocketAddress &, const void
return send(data, size);
}
nsapi_size_or_error_t TLSSocketWrapper::recv(void *data, nsapi_size_t size) {
nsapi_size_or_error_t TLSSocketWrapper::recv(void *data, nsapi_size_t size)
{
int ret;
if (!_transport) {
@ -265,7 +269,7 @@ nsapi_size_or_error_t TLSSocketWrapper::recv(void *data, nsapi_size_t size) {
ret = mbedtls_ssl_read(&_ssl, (unsigned char *) data, size);
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE ||
ret == MBEDTLS_ERR_SSL_WANT_READ) {
ret == MBEDTLS_ERR_SSL_WANT_READ) {
// translate to socket error
return NSAPI_ERROR_WOULD_BLOCK;
} else if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
@ -287,7 +291,8 @@ nsapi_size_or_error_t TLSSocketWrapper::recvfrom(SocketAddress *address, void *d
return recv(data, size);
}
void TLSSocketWrapper::print_mbedtls_error(const char *name, int err) {
void TLSSocketWrapper::print_mbedtls_error(const char *name, int err)
{
#ifdef MBEDTLS_ERROR_C
char *buf = new char[128];
mbedtls_strerror(err, buf, 128);
@ -303,14 +308,14 @@ void TLSSocketWrapper::print_mbedtls_error(const char *name, int err) {
#if MBED_CONF_TLS_SOCKET_DEBUG_LEVEL > 0
void TLSSocketWrapper::my_debug(void *ctx, int level, const char *file, int line,
const char *str)
const char *str)
{
const char *p, *basename;
(void) ctx;
/* Extract basename from file */
for(p = basename = file; *p != '\0'; p++) {
if(*p == '/' || *p == '\\') {
for (p = basename = file; *p != '\0'; p++) {
if (*p == '/' || *p == '\\') {
basename = p + 1;
}
}
@ -329,10 +334,9 @@ int TLSSocketWrapper::my_verify(void *data, mbedtls_x509_crt *crt, int depth, ui
mbedtls_x509_crt_info(buf, buf_size - 1, " ", crt);
tr_debug("%s", buf);
if (*flags == 0)
if (*flags == 0) {
tr_info("No verification issue for this certificate\n");
else
{
} else {
mbedtls_x509_crt_verify_info(buf, buf_size, " ! ", *flags);
tr_info("%s\n", buf);
}
@ -345,7 +349,8 @@ int TLSSocketWrapper::my_verify(void *data, mbedtls_x509_crt *crt, int depth, ui
#endif /* MBED_CONF_TLS_SOCKET_DEBUG_LEVEL > 0 */
int TLSSocketWrapper::ssl_recv(void *ctx, unsigned char *buf, size_t len) {
int TLSSocketWrapper::ssl_recv(void *ctx, unsigned char *buf, size_t len)
{
int recv;
TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx);
@ -358,14 +363,15 @@ int TLSSocketWrapper::ssl_recv(void *ctx, unsigned char *buf, size_t len) {
if (NSAPI_ERROR_WOULD_BLOCK == recv) {
return MBEDTLS_ERR_SSL_WANT_READ;
} else if(recv < 0) {
} else if (recv < 0) {
tr_error("Socket recv error %d", recv);
}
// Propagate also Socket errors to SSL, it allows negative error codes to be returned here.
return recv;
}
int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len) {
int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len)
{
int size = -1;
TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx);
@ -377,12 +383,12 @@ int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len)
if (NSAPI_ERROR_WOULD_BLOCK == size) {
return MBEDTLS_ERR_SSL_WANT_WRITE;
} else if(size < 0){
} else if (size < 0) {
tr_error("Socket send error %d", size);
}
// Propagate also Socket errors to SSL, it allows negative error codes to be returned here.
return size;
}
}
#ifdef MBEDTLS_X509_CRT_PARSE_C
@ -401,7 +407,7 @@ int TLSSocketWrapper::set_own_cert(mbedtls_x509_crt *crt)
}
_clicert = crt;
if (crt) {
if((ret = mbedtls_ssl_conf_own_cert(get_ssl_config(), _clicert, &_pkctx)) != 0) {
if ((ret = mbedtls_ssl_conf_own_cert(get_ssl_config(), _clicert, &_pkctx)) != 0) {
print_mbedtls_error("mbedtls_ssl_conf_own_cert", ret);
}
}
@ -437,12 +443,12 @@ mbedtls_ssl_config *TLSSocketWrapper::get_ssl_config()
tr_info("mbedtls_ssl_config_defaults()");
if ((ret = mbedtls_ssl_config_defaults(_ssl_conf,
MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
print_mbedtls_error("mbedtls_ssl_config_defaults", ret);
set_ssl_config(NULL);
MBED_ERROR( MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_OUT_OF_MEMORY), "mbedtls_ssl_config_defaults() failed" );
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_OUT_OF_MEMORY), "mbedtls_ssl_config_defaults() failed");
return NULL;
}
/* It is possible to disable authentication by passing

View File

@ -123,7 +123,7 @@ public:
virtual nsapi_error_t connect(const SocketAddress &address = SocketAddress());
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, const void *data, nsapi_size_t size);
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address,
void *data, nsapi_size_t size);
void *data, nsapi_size_t size);
virtual nsapi_error_t bind(const SocketAddress &address);
virtual void set_blocking(bool blocking);
virtual void set_timeout(int timeout);
@ -190,7 +190,7 @@ protected:
* Just prints on the USB serial port
*/
static void my_debug(void *ctx, int level, const char *file, int line,
const char *str);
const char *str);
/**
* Certificate verification callback for mbed TLS
@ -219,17 +219,17 @@ private:
Socket *_transport;
#ifdef MBEDTLS_X509_CRT_PARSE_C
mbedtls_x509_crt* _cacert;
mbedtls_x509_crt* _clicert;
mbedtls_x509_crt *_cacert;
mbedtls_x509_crt *_clicert;
#endif
mbedtls_ssl_config* _ssl_conf;
mbedtls_ssl_config *_ssl_conf;
bool _connect_transport:1;
bool _close_transport:1;
bool _handshake_completed:1;
bool _cacert_allocated:1;
bool _clicert_allocated:1;
bool _ssl_conf_allocated:1;
bool _connect_transport: 1;
bool _close_transport: 1;
bool _handshake_completed: 1;
bool _cacert_allocated: 1;
bool _clicert_allocated: 1;
bool _ssl_conf_allocated: 1;
};

View File

@ -29,9 +29,9 @@
*/
OnboardCellularInterface::OnboardCellularInterface(bool debug) :
UARTCellularInterface(MDMTXD, MDMRXD, MDMDCD, MDMRTS,
MDMCTS, MDMRI, MDMDTR, MDMDSR,
MBED_CONF_PPP_CELL_IFACE_BAUD_RATE, MDM_PIN_POLARITY, debug)
UARTCellularInterface(MDMTXD, MDMRXD, MDMDCD, MDMRTS,
MDMCTS, MDMRI, MDMDTR, MDMDSR,
MBED_CONF_PPP_CELL_IFACE_BAUD_RATE, MDM_PIN_POLARITY, debug)
{
}

View File

@ -91,7 +91,7 @@ static bool get_MEID(ATCmdParser *at)
{
// Mobile equipment identifier
bool success = at->send("AT+GSN")
&& at->recv("%18[^\n]\nOK\n", dev_info.meid);
&& at->recv("%18[^\n]\nOK\n", dev_info.meid);
tr_debug("DevInfo: MEID=%s", dev_info.meid);
return success;
}
@ -156,10 +156,12 @@ static nsapi_error_t do_sim_pin_check(ATCmdParser *at, const char *pin)
success = at->send("AT+CLCK=\"SC\",1,\"%s\"", pin) && at->recv("OK");
} else {
/* use the SIM unlocked */
success = at->send("AT+CLCK=\"SC\",0,\"%s\"",pin) && at->recv("OK");
success = at->send("AT+CLCK=\"SC\",0,\"%s\"", pin) && at->recv("OK");
}
if (success) return NSAPI_ERROR_OK;
if (success) {
return NSAPI_ERROR_OK;
}
return NSAPI_ERROR_AUTH_FAILURE;
}
@ -170,12 +172,12 @@ static nsapi_error_t do_sim_pin_check(ATCmdParser *at, const char *pin)
static nsapi_error_t do_change_sim_pin(ATCmdParser *at, const char *old_pin, const char *new_pin)
{
/* changes the SIM pin */
bool success = at->send("AT+CPWD=\"SC\",\"%s\",\"%s\"", old_pin, new_pin) && at->recv("OK");
if (success) {
return NSAPI_ERROR_OK;
}
bool success = at->send("AT+CPWD=\"SC\",\"%s\",\"%s\"", old_pin, new_pin) && at->recv("OK");
if (success) {
return NSAPI_ERROR_OK;
}
return NSAPI_ERROR_AUTH_FAILURE;
return NSAPI_ERROR_AUTH_FAILURE;
}
static void set_nwk_reg_status_csd(unsigned int status)
@ -240,15 +242,15 @@ static void set_nwk_reg_status_psd(unsigned int status)
static bool is_registered_csd()
{
return (dev_info.reg_status_csd == CSD_REGISTERED) ||
(dev_info.reg_status_csd == CSD_REGISTERED_ROAMING) ||
(dev_info.reg_status_csd == CSD_CSFB_NOT_PREFERRED);
return (dev_info.reg_status_csd == CSD_REGISTERED) ||
(dev_info.reg_status_csd == CSD_REGISTERED_ROAMING) ||
(dev_info.reg_status_csd == CSD_CSFB_NOT_PREFERRED);
}
static bool is_registered_psd()
{
return (dev_info.reg_status_psd == PSD_REGISTERED) ||
(dev_info.reg_status_psd == PSD_REGISTERED_ROAMING);
(dev_info.reg_status_psd == PSD_REGISTERED_ROAMING);
}
PPPCellularInterface::PPPCellularInterface(FileHandle *fh, bool debug)
@ -335,70 +337,70 @@ void PPPCellularInterface::set_new_sim_pin(const char *new_pin)
bool PPPCellularInterface::nwk_registration(uint8_t nwk_type)
{
bool success = false;
bool registered = false;
bool registered = false;
char str[35];
int retcode;
int retry_counter = 0;
unsigned int reg_status;
char str[35];
int retcode;
int retry_counter = 0;
unsigned int reg_status;
success = nwk_type == PACKET_SWITCHED ?
_at->send("AT+CGREG=0") :
_at->send("AT+CREG=0") && _at->recv("OK\n");
success = nwk_type == PACKET_SWITCHED ?
_at->send("AT+CGREG=0") :
_at->send("AT+CREG=0") && _at->recv("OK\n");
success = _at->send("AT+COPS=0") //initiate auto-registration
&& _at->recv("OK");
if (!success) {
tr_error("Modem not responding.");
return false;
}
success = _at->send("AT+COPS=0") //initiate auto-registration
&& _at->recv("OK");
if (!success) {
tr_error("Modem not responding.");
return false;
}
//Network search
//If not registered after 60 attempts, i.e., 30 seconds wait, give up
tr_debug("Searching Network ...");
//Network search
//If not registered after 60 attempts, i.e., 30 seconds wait, give up
tr_debug("Searching Network ...");
while (!registered) {
while (!registered) {
if (retry_counter > 60) {
success = false;
goto give_up;
}
if (retry_counter > 60) {
success = false;
goto give_up;
}
success = nwk_type == PACKET_SWITCHED ?
_at->send("AT+CGREG?")
&& _at->recv("+CGREG: %34[^\n]\n", str)
&& _at->recv("OK\n") :
_at->send("AT+CREG?")
&& _at->recv("+CREG: %34[^\n]\n", str)
&& _at->recv("OK\n");
success = nwk_type == PACKET_SWITCHED ?
_at->send("AT+CGREG?")
&& _at->recv("+CGREG: %34[^\n]\n", str)
&& _at->recv("OK\n") :
_at->send("AT+CREG?")
&& _at->recv("+CREG: %34[^\n]\n", str)
&& _at->recv("OK\n");
retcode = sscanf(str, "%*u,%u", &reg_status);
retcode = sscanf(str, "%*u,%u", &reg_status);
if (retcode >= 1) {
if (nwk_type == PACKET_SWITCHED) {
set_nwk_reg_status_psd(reg_status);
if (is_registered_psd()) {
registered = true;
}
} else if (nwk_type == CIRCUIT_SWITCHED) {
set_nwk_reg_status_csd(reg_status);
if (is_registered_csd()) {
registered = true;
}
}
}
if (retcode >= 1) {
if (nwk_type == PACKET_SWITCHED) {
set_nwk_reg_status_psd(reg_status);
if (is_registered_psd()) {
registered = true;
}
} else if (nwk_type == CIRCUIT_SWITCHED) {
set_nwk_reg_status_csd(reg_status);
if (is_registered_csd()) {
registered = true;
}
}
}
if (registered) {
break;
} else {
wait_ms(500);
}
if (registered) {
break;
} else {
wait_ms(500);
}
retry_counter++;
}
retry_counter++;
}
give_up:
return registered;
give_up:
return registered;
}
bool PPPCellularInterface::is_connected()
@ -444,7 +446,8 @@ nsapi_error_t PPPCellularInterface::initialize_sim_card()
return nsapi_error;
}
void PPPCellularInterface::set_sim_pin(const char *pin) {
void PPPCellularInterface::set_sim_pin(const char *pin)
{
/* overwrite the default pin by user provided pin */
_pin = pin;
}
@ -473,11 +476,11 @@ nsapi_error_t PPPCellularInterface::setup_context_and_credentials()
retry_without_dual_stack:
#endif
success = _at->send("AT"
"+FCLASS=0;" // set to connection (ATD) to data mode
"+CGDCONT=" CTX ",\"%s\",\"%s%s\"",
pdp_type, auth, _apn
)
&& _at->recv("OK");
"+FCLASS=0;" // set to connection (ATD) to data mode
"+CGDCONT=" CTX ",\"%s\",\"%s%s\"",
pdp_type, auth, _apn
)
&& _at->recv("OK");
#if NSAPI_PPP_IPV4_AVAILABLE && NSAPI_PPP_IPV6_AVAILABLE
if (_stack == IPV4V6_STACK) {
@ -513,7 +516,7 @@ void PPPCellularInterface::setup_at_parser()
}
_at = new ATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE, AT_PARSER_TIMEOUT,
_debug_trace_on ? true : false);
_debug_trace_on ? true : false);
/* Error cases, out of band handling */
_at->oob("ERROR", callback(parser_abort, _at));
@ -583,7 +586,7 @@ nsapi_error_t PPPCellularInterface::connect()
}
do {
retry_init:
retry_init:
retcode = NSAPI_ERROR_OK;
@ -608,12 +611,12 @@ nsapi_error_t PPPCellularInterface::connect()
}
success = nwk_registration(PACKET_SWITCHED) //perform network registration
&& get_CCID(_at)//get integrated circuit ID of the SIM
&& get_IMSI(_at)//get international mobile subscriber information
&& get_IMEI(_at)//get international mobile equipment identifier
&& get_MEID(_at)//its same as IMEI
&& set_CMGF(_at)//set message format for SMS
&& set_CNMI(_at);//set new SMS indication
&& get_CCID(_at)//get integrated circuit ID of the SIM
&& get_IMSI(_at)//get international mobile subscriber information
&& get_IMEI(_at)//get international mobile equipment identifier
&& get_MEID(_at)//its same as IMEI
&& set_CMGF(_at)//set message format for SMS
&& set_CNMI(_at);//set new SMS indication
if (!success) {
retcode = NSAPI_ERROR_NO_CONNECTION;
@ -712,7 +715,7 @@ nsapi_error_t PPPCellularInterface::connect()
_connect_status = NSAPI_STATUS_GLOBAL_UP;
}
} while ((_connect_status == NSAPI_STATUS_CONNECTING && _connect_is_blocking) &&
apn_config && *apn_config);
apn_config && *apn_config);
if (retcode != NSAPI_ERROR_OK) {

View File

@ -30,14 +30,14 @@ class NetworkStack;
* UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5)
*/
typedef enum {
GSM=0,
COMPACT_GSM=1,
UTRAN=2,
EDGE=3,
HSDPA=4,
HSUPA=5,
HSDPA_HSUPA=6,
LTE=7
GSM = 0,
COMPACT_GSM = 1,
UTRAN = 2,
EDGE = 3,
HSDPA = 4,
HSUPA = 5,
HSDPA_HSUPA = 6,
LTE = 7
} radio_access_nwk_type;
/**
@ -45,7 +45,7 @@ typedef enum {
* to connect.
*/
typedef enum {
CIRCUIT_SWITCHED=0,
CIRCUIT_SWITCHED = 0,
PACKET_SWITCHED
} nwk_type;
@ -54,15 +54,15 @@ typedef enum {
* UBX-13001820 - AT Commands Example Application Note (Section 7.10.3)
*/
typedef enum {
CSD_NOT_REGISTERED_NOT_SEARCHING=0,
CSD_REGISTERED=1,
CSD_NOT_REGISTERED_SEARCHING=2,
CSD_REGISTRATION_DENIED=3,
CSD_UNKNOWN_COVERAGE=4,
CSD_REGISTERED_ROAMING=5,
CSD_SMS_ONLY=6,
CSD_SMS_ONLY_ROAMING=7,
CSD_CSFB_NOT_PREFERRED=9
CSD_NOT_REGISTERED_NOT_SEARCHING = 0,
CSD_REGISTERED = 1,
CSD_NOT_REGISTERED_SEARCHING = 2,
CSD_REGISTRATION_DENIED = 3,
CSD_UNKNOWN_COVERAGE = 4,
CSD_REGISTERED_ROAMING = 5,
CSD_SMS_ONLY = 6,
CSD_SMS_ONLY_ROAMING = 7,
CSD_CSFB_NOT_PREFERRED = 9
} nwk_registration_status_csd;
/**
@ -70,20 +70,20 @@ typedef enum {
* UBX-13001820 - AT Commands Example Application Note (Section 18.27.3)
*/
typedef enum {
PSD_NOT_REGISTERED_NOT_SEARCHING=0,
PSD_REGISTERED=1,
PSD_NOT_REGISTERED_SEARCHING=2,
PSD_REGISTRATION_DENIED=3,
PSD_UNKNOWN_COVERAGE=4,
PSD_REGISTERED_ROAMING=5,
PSD_EMERGENCY_SERVICES_ONLY=8
PSD_NOT_REGISTERED_NOT_SEARCHING = 0,
PSD_REGISTERED = 1,
PSD_NOT_REGISTERED_SEARCHING = 2,
PSD_REGISTRATION_DENIED = 3,
PSD_UNKNOWN_COVERAGE = 4,
PSD_REGISTERED_ROAMING = 5,
PSD_EMERGENCY_SERVICES_ONLY = 8
} nwk_registration_status_psd;
typedef struct {
char ccid[20+1]; //!< Integrated Circuit Card ID
char imsi[15+1]; //!< International Mobile Station Identity
char imei[15+1]; //!< International Mobile Equipment Identity
char meid[18+1]; //!< Mobile Equipment IDentifier
char ccid[20 + 1]; //!< Integrated Circuit Card ID
char imsi[15 + 1]; //!< International Mobile Station Identity
char imei[15 + 1]; //!< International Mobile Equipment Identity
char meid[18 + 1]; //!< Mobile Equipment IDentifier
int flags;
radio_access_nwk_type rat;
nwk_registration_status_csd reg_status_csd;
@ -135,7 +135,7 @@ public:
*/
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.")
virtual void set_credentials(const char *apn, const char *uname = 0,
const char *pwd = 0);
const char *pwd = 0);
/** Set the pin code for SIM card
*
@ -403,7 +403,7 @@ protected:
*
* @return true if registration is successful
*/
bool nwk_registration(uint8_t nwk_type=PACKET_SWITCHED);
bool nwk_registration(uint8_t nwk_type = PACKET_SWITCHED);
};

View File

@ -86,10 +86,10 @@ static void unlock();
* Verification tests for a successful porting
* These tests must pass:
*
* test_udp_echo()
* test_tcp_echo_async
* test_connect_credentials
* test_connect_preset_credentials
* test_udp_echo()
* test_tcp_echo_async
* test_connect_credentials
* test_connect_preset_credentials
*/
/**
@ -148,7 +148,7 @@ void test_tcp_echo_async()
TEST_ASSERT(do_connect(&driver) == 0);
TEST_ASSERT(
driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0);
driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0);
host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT);
tr_debug("TCP: Server %s address: %s on port %d.",
@ -172,7 +172,7 @@ void test_tcp_echo_async()
drop_connection(&driver);
tr_debug("TCP packets of size up to %d byte(s) echoed asynchronously and successfully.",
MBED_CONF_APP_TCP_MAX_PACKET_SIZE);
MBED_CONF_APP_TCP_MAX_PACKET_SIZE);
}
/**
@ -196,7 +196,7 @@ void test_connect_preset_credentials()
driver.disconnect();
driver.set_sim_pin(MBED_CONF_APP_DEFAULT_PIN);
driver.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME,
MBED_CONF_APP_PASSWORD);
MBED_CONF_APP_PASSWORD);
int num_retries = 0;
nsapi_error_t err = NSAPI_ERROR_OK;
while (!driver.is_connected()) {
@ -226,10 +226,11 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
*/
Case cases[] = { Case("UDP echo test", test_udp_echo),
#if MBED_CONF_LWIP_TCP_ENABLED
Case("TCP async echo test", test_tcp_echo_async),
Case("TCP async echo test", test_tcp_echo_async),
#endif
Case("Connect with credentials", test_connect_credentials),
Case("Connect with preset credentials", test_connect_preset_credentials) };
Case("Connect with credentials", test_connect_credentials),
Case("Connect with preset credentials", test_connect_preset_credentials)
};
Specification specification(test_setup, cases);
@ -255,7 +256,7 @@ static nsapi_error_t do_connect(OnboardCellularInterface *iface)
nsapi_error_t err = NSAPI_ERROR_OK;
while (!iface->is_connected()) {
err = driver.connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
if (err == NSAPI_ERROR_OK || num_retries > MBED_CONF_APP_MAX_RETRIES) {
break;
}
@ -284,14 +285,14 @@ static int fix(int size, int limit)
static void do_udp_echo(UDPSocket *sock, SocketAddress *host_address, int size)
{
bool success = false;
void * recv_data = malloc(size);
void *recv_data = malloc(size);
TEST_ASSERT(recv_data != NULL);
// Retry this a few times, don't want to fail due to a flaky link
for (int x = 0; !success && (x < NUM_UDP_RETRIES); x++) {
tr_debug("Echo testing UDP packet size %d byte(s), try %d.", size, x + 1);
if ((sock->sendto(*host_address, (void*) test_data, size) == size)
&& (sock->recvfrom(host_address, recv_data, size) == size)) {
if ((sock->sendto(*host_address, (void *) test_data, size) == size)
&& (sock->recvfrom(host_address, recv_data, size) == size)) {
TEST_ASSERT(memcmp(test_data, recv_data, size) == 0);
success = true;
}
@ -340,7 +341,7 @@ static void async_cb(bool *callback_triggered)
static void do_tcp_echo_async(TCPSocket *sock, int size,
bool *callback_triggered)
{
void * recv_data = malloc(size);
void *recv_data = malloc(size);
int recv_size = 0;
int remaining_size;
int x, y;
@ -370,7 +371,7 @@ static void do_tcp_echo_async(TCPSocket *sock, int size,
y = memcmp(test_data, recv_data, size);
if (y != 0) {
tr_debug("Sent %d, |%*.*s|", size, size, size, test_data);
tr_debug("Rcvd %d, |%*.*s|", size, size, size, (char * ) recv_data);
tr_debug("Rcvd %d, |%*.*s|", size, size, size, (char *) recv_data);
// We do not assert a failure here because ublox TCP echo server doesn't send
// back original data. It actually constructs a ublox message string. They need to fix it as
// at the minute in case of TCP, their server is not behaving like a echo TCP server.
@ -386,9 +387,9 @@ static void do_tcp_echo_async(TCPSocket *sock, int size,
*/
static void use_connection(OnboardCellularInterface *driver)
{
const char * ip_address = driver->get_ip_address();
const char * net_mask = driver->get_netmask();
const char * gateway = driver->get_gateway();
const char *ip_address = driver->get_ip_address();
const char *net_mask = driver->get_netmask();
const char *gateway = driver->get_gateway();
TEST_ASSERT(driver->is_connected());

View File

@ -19,8 +19,8 @@
UARTCellularInterface::UARTCellularInterface(PinName txd, PinName rxd, PinName dcd, PinName rts, PinName cts, PinName ri,
PinName dtr, PinName dsr, int baud, bool active_high, bool debug) :
PPPCellularInterface(&_serial, debug),
_serial(txd, rxd, baud)
PPPCellularInterface(&_serial, debug),
_serial(txd, rxd, baud)
{
_dcd_pin = dcd;
_active_high = active_high;

View File

@ -42,9 +42,9 @@ public:
*/
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use mbed-os/features/cellular/easy_cellular/EasyCellularConnection.h instead.")
UARTCellularInterface(PinName tx, PinName rx, PinName dcd = NC, PinName rts = NC, PinName cts = NC, PinName ri = NC,
PinName dtr = NC, PinName dsr = NC, int baud = MBED_CONF_PPP_CELL_IFACE_BAUD_RATE,
bool active_high = false,
bool debug = false);
PinName dtr = NC, PinName dsr = NC, int baud = MBED_CONF_PPP_CELL_IFACE_BAUD_RATE,
bool active_high = false,
bool debug = false);
/** Destructor
*

View File

@ -38,7 +38,7 @@ void functionality_test()
uint8_t *dummy = new (std::nothrow) uint8_t[num_blocks * erase_size];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
HeapBlockDevice heap_bd(num_blocks * erase_size, read_size, prog_size, erase_size);
FlashSimBlockDevice bd(&heap_bd, blank);

View File

@ -82,11 +82,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
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),
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]);
}
@ -153,7 +153,7 @@ static void test_thread_job(void *block_device_ptr)
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

@ -25,7 +25,7 @@ using namespace utest::v1;
// TODO HACK, replace with available ram/heap property
#if defined(TARGET_MTB_MTS_XDOT)
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#endif
#define TEST_BLOCK_SIZE 128
@ -45,7 +45,8 @@ const struct {
// Simple test that read/writes random set of blocks
void test_read_write() {
void test_read_write()
{
uint8_t *dummy = new (std::nothrow) uint8_t[TEST_BLOCK_DEVICE_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
@ -55,19 +56,19 @@ void test_read_write() {
int err = bd.init();
TEST_ASSERT_EQUAL(0, err);
for (unsigned a = 0; a < sizeof(ATTRS)/sizeof(ATTRS[0]); a++) {
for (unsigned a = 0; a < sizeof(ATTRS) / sizeof(ATTRS[0]); a++) {
static const char *prefixes[] = {"", "k", "M", "G"};
for (int i = 3; i >= 0; i--) {
bd_size_t size = (bd.*ATTRS[a].method)();
if (size >= (1ULL << 10*i)) {
if (size >= (1ULL << 10 * i)) {
printf("%s: %llu%sbytes (%llubytes)\n",
ATTRS[a].name, size >> 10*i, prefixes[i], size);
ATTRS[a].name, size >> 10 * i, prefixes[i], size);
break;
}
}
}
unsigned addrwidth = ceil(log(float(bd.size()-1)) / log(float(16)))+1;
unsigned addrwidth = ceil(log(float(bd.size() - 1)) / log(float(16))) + 1;
bd_size_t block_size = bd.get_erase_size();
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
@ -81,7 +82,7 @@ void test_read_write() {
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
// Find a random block
bd_addr_t block = (rand()*block_size) % bd.size();
bd_addr_t block = (rand() * block_size) % bd.size();
// Use next random number as temporary seed to keep
// the address progressing in the pseudorandom sequence
@ -119,13 +120,13 @@ void test_read_write() {
// Find error mask for debugging
memset(error_mask, 0, TEST_ERROR_MASK);
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8);
bd_size_t error_scale = block_size / (TEST_ERROR_MASK * 8);
srand(seed);
for (bd_size_t i = 0; i < TEST_ERROR_MASK*8; i++) {
for (bd_size_t i = 0; i < TEST_ERROR_MASK * 8; i++) {
for (bd_size_t j = 0; j < error_scale; j++) {
if ((0xff & rand()) != read_block[i*error_scale + j]) {
error_mask[i/8] |= 1 << (i%8);
if ((0xff & rand()) != read_block[i * error_scale + j]) {
error_mask[i / 8] |= 1 << (i % 8);
}
}
}
@ -142,7 +143,7 @@ void test_read_write() {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}
}
err = bd.deinit();
TEST_ASSERT_EQUAL(0, err);
@ -155,7 +156,8 @@ end:
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(30, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
@ -166,6 +168,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -26,13 +26,13 @@ using namespace utest::v1;
// TODO HACK, replace with available ram/heap property
#if defined(TARGET_MTB_MTS_XDOT)
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#endif
#define BLOCK_COUNT 16
#define BLOCK_SIZE 512
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT *BLOCK_SIZE, BLOCK_SIZE);
// Testing formatting of master boot record
void test_mbr_format()
@ -42,10 +42,10 @@ void test_mbr_format()
delete[] dummy;
// Create two partitions splitting device in ~half
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT/2)*BLOCK_SIZE);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Load both partitions, as well as a third to check for invalid partitions
@ -95,13 +95,13 @@ void test_mbr_attr()
printf("partition 1 erase size: %llu bytes\n", part1.get_erase_size());
printf("partition 1 size: %llu bytes\n", part1.size());
TEST_ASSERT_EQUAL(1, part1.get_partition_number());
TEST_ASSERT_EQUAL(1*BLOCK_SIZE, part1.get_partition_start());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, part1.get_partition_stop());
TEST_ASSERT_EQUAL(1 * BLOCK_SIZE, part1.get_partition_start());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, part1.get_partition_stop());
TEST_ASSERT_EQUAL(0x83, part1.get_partition_type());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_read_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_erase_size());
TEST_ASSERT_EQUAL(((BLOCK_COUNT/2)-1)*BLOCK_SIZE, part1.size());
TEST_ASSERT_EQUAL(((BLOCK_COUNT / 2) - 1)*BLOCK_SIZE, part1.size());
printf("partition 2 partition number: %d\n", part2.get_partition_number());
printf("partition 2 partition start: 0x%llx\n", part2.get_partition_start());
@ -112,13 +112,13 @@ void test_mbr_attr()
printf("partition 2 erase size: %llu bytes\n", part2.get_erase_size());
printf("partition 2 size: %llu bytes\n", part2.size());
TEST_ASSERT_EQUAL(2, part2.get_partition_number());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, part2.get_partition_start());
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, part2.get_partition_stop());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, part2.get_partition_start());
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, part2.get_partition_stop());
TEST_ASSERT_EQUAL(0x83, part2.get_partition_type());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_read_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_erase_size());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, part2.size());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, part2.size());
// Deinit partitions
err = part1.deinit();
@ -177,7 +177,7 @@ void test_mbr_read_write()
}
// Check with original block device
err = bd.read(read_block, 1*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(read_block, 1 * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -209,7 +209,7 @@ void test_mbr_read_write()
}
// Check with original block device
err = bd.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(read_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -232,7 +232,8 @@ end:
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
@ -245,6 +246,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -28,7 +28,7 @@ using namespace utest::v1;
// TODO HACK, replace with available ram/heap property
#if defined(TARGET_MTB_MTS_XDOT)
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#error [NOT_SUPPORTED] Insufficient heap for heap block device tests
#endif
#define BLOCK_COUNT 16
@ -36,17 +36,18 @@ using namespace utest::v1;
// Simple test which read/writes blocks on a sliced block device
void test_slicing() {
void test_slicing()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
int err;
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT * BLOCK_SIZE, BLOCK_SIZE);
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT / 2)*BLOCK_SIZE);
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT / 2)*BLOCK_SIZE);
// Test with first slice of block device
err = slice1.init();
@ -54,7 +55,7 @@ void test_slicing() {
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_erase_size(BLOCK_SIZE));
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, slice1.size());
uint8_t *write_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
uint8_t *read_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
@ -97,7 +98,7 @@ void test_slicing() {
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice2.get_program_size());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice2.size());
TEST_ASSERT_EQUAL((BLOCK_COUNT / 2)*BLOCK_SIZE, slice2.size());
// Fill with random sequence
srand(1);
@ -123,7 +124,7 @@ void test_slicing() {
}
// Check with original block device
err = bd.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(read_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -141,15 +142,16 @@ end:
}
// Simple test which read/writes blocks on a chain of block devices
void test_chaining() {
void test_chaining()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
int err;
HeapBlockDevice bd1((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd2((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd1((BLOCK_COUNT / 2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd2((BLOCK_COUNT / 2)*BLOCK_SIZE, BLOCK_SIZE);
// Test with chain of block device
BlockDevice *bds[] = {&bd1, &bd2};
@ -167,8 +169,8 @@ void test_chaining() {
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_erase_size((BLOCK_COUNT/2)*BLOCK_SIZE+1));
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_erase_size((BLOCK_COUNT / 2)*BLOCK_SIZE + 1));
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, chain.size());
// Fill with random sequence
srand(1);
@ -190,10 +192,10 @@ void test_chaining() {
}
// Write, sync, and read the block
err = chain.program(write_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = chain.program(write_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
err = chain.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
err = chain.read(read_block, (BLOCK_COUNT / 2) * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Check that the data was unmodified
@ -211,7 +213,8 @@ end:
}
// Simple test which read/writes blocks on a chain of block devices
void test_profiling() {
void test_profiling()
{
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
delete[] dummy;
@ -219,7 +222,7 @@ void test_profiling() {
int err;
bd_size_t read_count, program_count, erase_count;
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT * BLOCK_SIZE, BLOCK_SIZE);
// Test under profiling
ProfilingBlockDevice profiler(&bd);
@ -227,7 +230,7 @@ void test_profiling() {
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT_EQUAL(BLOCK_SIZE, profiler.get_erase_size());
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, profiler.size());
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, profiler.size());
uint8_t *write_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
uint8_t *read_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
@ -287,7 +290,8 @@ end:
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
@ -300,6 +304,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -26,16 +26,17 @@
using namespace utest::v1;
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#endif
// Test block device
#define BLOCK_SIZE 512
HeapBlockDevice bd(128*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(128 * BLOCK_SIZE, BLOCK_SIZE);
// Test formatting
void test_format() {
void test_format()
{
int err = FATFileSystem::format(&bd);
TEST_ASSERT_EQUAL(0, err);
}
@ -43,7 +44,8 @@ void test_format() {
// Simple test for reading/writing files
template <ssize_t TEST_SIZE>
void test_read_write() {
void test_read_write()
{
FATFileSystem fs("fat");
int err = fs.mount(&bd);
@ -51,7 +53,7 @@ void test_read_write() {
uint8_t *buffer = (uint8_t *)malloc(TEST_SIZE);
TEST_ASSERT(buffer);
// Fill with random sequence
srand(1);
for (int i = 0; i < TEST_SIZE; i++) {
@ -86,7 +88,8 @@ void test_read_write() {
// Simple test for iterating dir entries
void test_read_dir() {
void test_read_dir()
{
FATFileSystem fs("fat");
int err = fs.mount(&bd);
@ -147,20 +150,22 @@ void test_read_dir() {
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case("Testing formating", test_format),
Case("Testing read write < block", test_read_write<BLOCK_SIZE/2>),
Case("Testing read write > block", test_read_write<2*BLOCK_SIZE>),
Case("Testing read write < block", test_read_write < BLOCK_SIZE / 2 >),
Case("Testing read write > block", test_read_write<2 * BLOCK_SIZE>),
Case("Testing dir iteration", test_read_dir),
};
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -1959,7 +1959,7 @@ static void FS_fill_data_and_seek()
for (i = 1; i <= 255; i++) {
res = fseek(fd[0], (long)-i, SEEK_END);
res = fseek(fd[0], (long) - i, SEEK_END);
TEST_ASSERT_EQUAL(0, res);
j = getc(fd[0]);

View File

@ -27,22 +27,23 @@
using namespace utest::v1;
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#error [NOT_SUPPORTED] Filesystem tests not supported by default
#endif
// Test block device
#define BLOCK_SIZE 512
#define BLOCK_COUNT 512
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd(BLOCK_COUNT *BLOCK_SIZE, BLOCK_SIZE);
// Test formatting and partitioning
void test_format() {
void test_format()
{
// Create two partitions splitting device in ~half
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
int err = MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT/2)*BLOCK_SIZE);
err = MBRBlockDevice::partition(&bd, 2, 0x83, -(BLOCK_COUNT / 2) * BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
// Load both partitions
@ -72,7 +73,8 @@ void test_format() {
// Simple multipartition test for reading/writing files
template <ssize_t TEST_SIZE>
void test_read_write() {
void test_read_write()
{
// Load both partitions
MBRBlockDevice part1(&bd, 1);
int err = part1.init();
@ -97,7 +99,7 @@ void test_read_write() {
uint8_t *buffer2 = (uint8_t *)malloc(TEST_SIZE);
TEST_ASSERT(buffer2);
// Fill with random sequence
srand(1);
@ -163,37 +165,38 @@ void test_read_write() {
TEST_ASSERT_EQUAL(0, err);
}
void test_single_mbr() {
void test_single_mbr()
{
int err = bd.init();
TEST_ASSERT_EQUAL(0, err);
const bd_addr_t MBR_OFFSET = 0;
const bd_addr_t FAT1_OFFSET = 1;
const bd_addr_t FAT2_OFFSET = BLOCK_COUNT/2;
const bd_addr_t FAT2_OFFSET = BLOCK_COUNT / 2;
uint8_t *buffer = (uint8_t *)malloc(BLOCK_SIZE);
TEST_ASSERT(buffer);
// Check that all three header blocks have the 0x55aa signature
err = bd.read(buffer, MBR_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(buffer, MBR_OFFSET * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE - 2], "\x55\xaa", 2) == 0);
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(buffer, FAT1_OFFSET * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE - 2], "\x55\xaa", 2) == 0);
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(buffer, FAT2_OFFSET * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE - 2], "\x55\xaa", 2) == 0);
// Check that the headers for both filesystems contain a jump code
// indicating they are actual FAT superblocks and not an extra MBR
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(buffer, FAT1_OFFSET * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
err = bd.read(buffer, FAT2_OFFSET * BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
@ -205,20 +208,22 @@ void test_single_mbr() {
// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
Case cases[] = {
Case("Testing formating", test_format),
Case("Testing read write < block", test_read_write<BLOCK_SIZE/2>),
Case("Testing read write > block", test_read_write<2*BLOCK_SIZE>),
Case("Testing read write < block", test_read_write < BLOCK_SIZE / 2 >),
Case("Testing read write > block", test_read_write<2 * BLOCK_SIZE>),
Case("Testing for no extra MBRs", test_single_mbr),
};
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -40,8 +40,7 @@ typedef uint64_t bd_size_t;
/** A hardware device capable of writing and reading blocks
*/
class BlockDevice
{
class BlockDevice {
public:
/** Return the default block device
@ -198,9 +197,9 @@ public:
bool is_valid_read(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_read_size() == 0 &&
size % get_read_size() == 0 &&
addr + size <= this->size());
addr % get_read_size() == 0 &&
size % get_read_size() == 0 &&
addr + size <= this->size());
}
/** Convenience function for checking block program validity
@ -212,9 +211,9 @@ public:
bool is_valid_program(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_program_size() == 0 &&
size % get_program_size() == 0 &&
addr + size <= this->size());
addr % get_program_size() == 0 &&
size % get_program_size() == 0 &&
addr + size <= this->size());
}
/** Convenience function for checking block erase validity
@ -226,9 +225,9 @@ public:
bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_erase_size(addr) == 0 &&
(addr + size) % get_erase_size(addr + size - 1) == 0 &&
addr + size <= this->size());
addr % get_erase_size(addr) == 0 &&
(addr + size) % get_erase_size(addr + size - 1) == 0 &&
addr + size <= this->size());
}
};

View File

@ -119,7 +119,7 @@ int BufferedBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
bd_addr_t aligned_addr = align_down(addr, _bd_program_size);
uint8_t *buf = static_cast<uint8_t *> (b);
uint8_t *buf = static_cast<uint8_t *>(b);
if (aligned_addr != _curr_aligned_addr) {
// Need to flush if moved to another program unit
@ -159,7 +159,7 @@ int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
bd_addr_t aligned_addr = align_down(addr, _bd_program_size);
const uint8_t *buf = static_cast <const uint8_t *> (b);
const uint8_t *buf = static_cast <const uint8_t *>(b);
// Need to flush if moved to another program unit
if (aligned_addr != _curr_aligned_addr) {

View File

@ -141,7 +141,7 @@ int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
uint8_t *buffer = static_cast<uint8_t*>(b);
uint8_t *buffer = static_cast<uint8_t *>(b);
// Find block devices containing blocks, may span multiple block devices
for (size_t i = 0; i < _bd_count && size > 0; i++) {
@ -176,7 +176,7 @@ int ChainingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
const uint8_t *buffer = static_cast<const uint8_t*>(b);
const uint8_t *buffer = static_cast<const uint8_t *>(b);
// Find block devices containing blocks, may span multiple block devices
for (size_t i = 0; i < _bd_count && size > 0; i++) {

View File

@ -61,7 +61,7 @@ public:
* @note All block devices must have the same block size
*/
template <size_t Size>
ChainingBlockDevice(BlockDevice *(&bds)[Size])
ChainingBlockDevice(BlockDevice * (&bds)[Size])
: _bds(bds), _bd_count(sizeof(bds) / sizeof(bds[0]))
, _read_size(0), _program_size(0), _erase_size(0), _size(0), _init_ref_count(0)
{

View File

@ -31,8 +31,7 @@
* after a configurable number of cycles.
*
*/
class ExhaustibleBlockDevice : public BlockDevice
{
class ExhaustibleBlockDevice : public BlockDevice {
public:
/** Lifetime of the block device
*

View File

@ -53,7 +53,7 @@ int HeapBlockDevice::init()
}
if (!_blocks) {
_blocks = new uint8_t*[_count];
_blocks = new uint8_t *[_count];
for (size_t i = 0; i < _count; i++) {
_blocks[i] = 0;
}
@ -120,7 +120,7 @@ int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
uint8_t *buffer = static_cast<uint8_t*>(b);
uint8_t *buffer = static_cast<uint8_t *>(b);
while (size > 0) {
bd_addr_t hi = addr / _erase_size;
@ -148,14 +148,14 @@ int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
return BD_ERROR_DEVICE_ERROR;
}
const uint8_t *buffer = static_cast<const uint8_t*>(b);
const uint8_t *buffer = static_cast<const uint8_t *>(b);
while (size > 0) {
bd_addr_t hi = addr / _erase_size;
bd_addr_t lo = addr % _erase_size;
if (!_blocks[hi]) {
_blocks[hi] = (uint8_t*)malloc(_erase_size);
_blocks[hi] = (uint8_t *)malloc(_erase_size);
if (!_blocks[hi]) {
return BD_ERROR_DEVICE_ERROR;
}

View File

@ -50,8 +50,7 @@
* }
* @endcode
*/
class HeapBlockDevice : public BlockDevice
{
class HeapBlockDevice : public BlockDevice {
public:
/** Lifetime of the memory block device
@ -60,7 +59,7 @@ public:
* @param block Block size in bytes. Minimum read, program, and erase sizes are
* configured to this value
*/
HeapBlockDevice(bd_size_t size, bd_size_t block=512);
HeapBlockDevice(bd_size_t size, bd_size_t block = 512);
/** Lifetime of the memory block device
*
* @param size Size of the Block Device in bytes

View File

@ -60,7 +60,7 @@ static inline uint32_t fromle32(uint32_t a)
static void tochs(uint32_t lba, uint8_t chs[3])
{
uint32_t sector = std::min<uint32_t>(lba, 0xfffffd)+1;
uint32_t sector = std::min<uint32_t>(lba, 0xfffffd) + 1;
chs[0] = (sector >> 6) & 0xff;
chs[1] = ((sector >> 0) & 0x3f) | ((sector >> 16) & 0xc0);
chs[2] = (sector >> 14) & 0xff;
@ -70,28 +70,28 @@ static void tochs(uint32_t lba, uint8_t chs[3])
// Partition after address are turned into absolute
// addresses, assumes bd is initialized
static int partition_absolute(
BlockDevice *bd, int part, uint8_t type,
bd_size_t offset, bd_size_t size)
BlockDevice *bd, int part, uint8_t type,
bd_size_t offset, bd_size_t size)
{
// Allocate smallest buffer necessary to write MBR
uint32_t buffer_size = std::max<uint32_t>(bd->get_program_size(), sizeof(struct mbr_table));
// Prevent alignment issues
if(buffer_size % bd->get_program_size() != 0) {
if (buffer_size % bd->get_program_size() != 0) {
buffer_size += bd->get_program_size() - (buffer_size % bd->get_program_size());
}
uint8_t *buffer = new uint8_t[buffer_size];
// Check for existing MBR
int err = bd->read(buffer, 512-buffer_size, buffer_size);
int err = bd->read(buffer, 512 - buffer_size, buffer_size);
if (err) {
delete[] buffer;
return err;
}
struct mbr_table *table = reinterpret_cast<struct mbr_table*>(
&buffer[buffer_size - sizeof(struct mbr_table)]);
struct mbr_table *table = reinterpret_cast<struct mbr_table *>(
&buffer[buffer_size - sizeof(struct mbr_table)]);
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
// Setup default values for MBR
table->signature[0] = 0x55;
@ -104,8 +104,8 @@ static int partition_absolute(
// partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
// /0x80 (active) for valid partition status.
for (int i = 1; i <= 4; i++) {
if (table->entries[i-1].status != 0x00 &&
table->entries[i-1].status != 0x80) {
if (table->entries[i - 1].status != 0x00 &&
table->entries[i - 1].status != 0x80) {
memset(table->entries, 0, sizeof(table->entries));
break;
}
@ -113,29 +113,29 @@ static int partition_absolute(
// Setup new partition
MBED_ASSERT(part >= 1 && part <= 4);
table->entries[part-1].status = 0x00; // inactive (not bootable)
table->entries[part-1].type = type;
table->entries[part - 1].status = 0x00; // inactive (not bootable)
table->entries[part - 1].type = type;
// lba dimensions
MBED_ASSERT(bd->is_valid_erase(offset, size));
uint32_t sector = std::max<uint32_t>(bd->get_erase_size(), 512);
uint32_t lba_offset = offset / sector;
uint32_t lba_size = size / sector;
table->entries[part-1].lba_offset = tole32(lba_offset);
table->entries[part-1].lba_size = tole32(lba_size);
table->entries[part - 1].lba_offset = tole32(lba_offset);
table->entries[part - 1].lba_size = tole32(lba_size);
// chs dimensions
tochs(lba_offset, table->entries[part-1].chs_start);
tochs(lba_offset+lba_size-1, table->entries[part-1].chs_stop);
tochs(lba_offset, table->entries[part - 1].chs_start);
tochs(lba_offset + lba_size - 1, table->entries[part - 1].chs_stop);
// Check that we don't overlap other entries
for (int i = 1; i <= 4; i++) {
if (i != part && table->entries[i-1].type != 0x00) {
uint32_t neighbor_lba_offset = fromle32(table->entries[i-1].lba_offset);
uint32_t neighbor_lba_size = fromle32(table->entries[i-1].lba_size);
if (i != part && table->entries[i - 1].type != 0x00) {
uint32_t neighbor_lba_offset = fromle32(table->entries[i - 1].lba_offset);
uint32_t neighbor_lba_size = fromle32(table->entries[i - 1].lba_size);
MBED_ASSERT(
(lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
(lba_offset + lba_size <= neighbor_lba_offset));
(lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
(lba_offset + lba_size <= neighbor_lba_offset));
(void)neighbor_lba_offset;
(void)neighbor_lba_size;
}
@ -148,7 +148,7 @@ static int partition_absolute(
return err;
}
err = bd->program(buffer, 512-buffer_size, buffer_size);
err = bd->program(buffer, 512 - buffer_size, buffer_size);
delete[] buffer;
return err;
}
@ -184,7 +184,7 @@ int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type, bd_addr_t
}
int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type,
bd_addr_t start, bd_addr_t stop)
bd_addr_t start, bd_addr_t stop)
{
int err = bd->init();
if (err) {
@ -243,13 +243,13 @@ int MBRBlockDevice::init()
buffer_size = std::max<uint32_t>(_bd->get_read_size(), sizeof(struct mbr_table));
buffer = new uint8_t[buffer_size];
err = _bd->read(buffer, 512-buffer_size, buffer_size);
err = _bd->read(buffer, 512 - buffer_size, buffer_size);
if (err) {
goto fail;
}
// Check for valid table
table = reinterpret_cast<struct mbr_table*>(&buffer[buffer_size - sizeof(struct mbr_table)]);
table = reinterpret_cast<struct mbr_table *>(&buffer[buffer_size - sizeof(struct mbr_table)]);
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
err = BD_ERROR_INVALID_MBR;
goto fail;
@ -257,8 +257,8 @@ int MBRBlockDevice::init()
// Check for valid partition status
// Same reason as in partition_absolute regarding Windows-formatted SD card
if (table->entries[_part-1].status != 0x00 &&
table->entries[_part-1].status != 0x80) {
if (table->entries[_part - 1].status != 0x00 &&
table->entries[_part - 1].status != 0x80) {
err = BD_ERROR_INVALID_PARTITION;
goto fail;
}
@ -266,18 +266,18 @@ int MBRBlockDevice::init()
// Check for valid entry
// 0x00 = no entry
// 0x05, 0x0f = extended partitions, currently not supported
if ((table->entries[_part-1].type == 0x00 ||
table->entries[_part-1].type == 0x05 ||
table->entries[_part-1].type == 0x0f)) {
if ((table->entries[_part - 1].type == 0x00 ||
table->entries[_part - 1].type == 0x05 ||
table->entries[_part - 1].type == 0x0f)) {
err = BD_ERROR_INVALID_PARTITION;
goto fail;
}
// Get partition attributes
sector = std::max<uint32_t>(_bd->get_erase_size(), 512);
_type = table->entries[_part-1].type;
_offset = fromle32(table->entries[_part-1].lba_offset) * sector;
_size = fromle32(table->entries[_part-1].lba_size) * sector;
_type = table->entries[_part - 1].type;
_offset = fromle32(table->entries[_part - 1].lba_offset) * sector;
_size = fromle32(table->entries[_part - 1].lba_size) * sector;
// Check that block addresses are valid
if (!_bd->is_valid_erase(_offset, _size)) {
@ -408,7 +408,7 @@ bd_size_t MBRBlockDevice::get_partition_start() const
bd_size_t MBRBlockDevice::get_partition_stop() const
{
return _offset+_size;
return _offset + _size;
}
uint8_t MBRBlockDevice::get_partition_type() const

View File

@ -87,15 +87,14 @@ enum {
* - At most 4 partitions are supported
* - Extended partitions are currently not supported and will error during init
*/
class MBRBlockDevice : public BlockDevice
{
class MBRBlockDevice : public BlockDevice {
public:
/** Format the MBR to contain the following partition
*
* @param bd Block device to partition
* @param part Partition to use, 1-4
* @param type 8-bit partition type to identitfy partition's contents
* @param start Start block address to map to block 0 of partition,
* @param start Start block address to map to block 0 of partition,
* negative addresses are calculated from the end of the
* underlying block devices. Block 0 is implicitly ignored
* from the range to store the MBR.
@ -109,7 +108,7 @@ public:
* @param bd Block device to partition
* @param part Partition to use, 1-4
* @param type 8-bit partition type to identitfy partition's contents
* @param start Start block address to map to block 0 of partition,
* @param start Start block address to map to block 0 of partition,
* negative addresses are calculated from the end of the
* underlying block devices. Block 0 is implicitly ignored
* from the range to store the MBR.

View File

@ -27,8 +27,7 @@
#include "platform/Callback.h"
class ObservingBlockDevice : public BlockDevice
{
class ObservingBlockDevice : public BlockDevice {
public:
/** Lifetime of the block device

View File

@ -43,8 +43,7 @@
* printf("erase count: %lld\n", profiler.get_erase_count());
* @endcode
*/
class ProfilingBlockDevice : public BlockDevice
{
class ProfilingBlockDevice : public BlockDevice {
public:
/** Lifetime of the memory block device
*

View File

@ -26,8 +26,7 @@
#include "PlatformMutex.h"
class ReadOnlyBlockDevice : public BlockDevice
{
class ReadOnlyBlockDevice : public BlockDevice {
public:
/** Lifetime of the block device

View File

@ -45,8 +45,7 @@
* SlicingBlockDevice slice3(&mem, 16*512, -16*512);
* @endcode
*/
class SlicingBlockDevice : public BlockDevice
{
class SlicingBlockDevice : public BlockDevice {
public:
/** Lifetime of the memory block device
*

View File

@ -35,7 +35,7 @@ public:
*/
Dir();
/** Open a directory on a filesystem
/** Open a directory on a filesystem
*
* @param fs Filesystem as target for a directory
* @param path Name of the directory to open
@ -86,7 +86,7 @@ public:
*/
virtual void rewind();
/** Get the sizeof the directory
/** Get the sizeof the directory
*
* @return Number of files in the directory
*/

View File

@ -35,7 +35,7 @@ public:
*/
File();
/** Create a file on a filesystem
/** Create a file on a filesystem
*
* Creates and opens a file on a filesystem
*
@ -60,7 +60,7 @@ public:
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
* @return 0 on success, negative error code on failure
*/
virtual int open(FileSystem *fs, const char *path, int flags=O_RDONLY);
virtual int open(FileSystem *fs, const char *path, int flags = O_RDONLY);
/** Close a file
*
@ -80,7 +80,7 @@ public:
/** Write the contents of a buffer to a file
*
* @param buffer The buffer to write from
* @param size The number of bytes to write
* @param size The number of bytes to write
* @return The number of bytes written, negative error on failure
*/
virtual ssize_t write(const void *buffer, size_t size);

View File

@ -139,7 +139,8 @@ size_t FileSystem::dir_size(fs_dir_t dir)
template <typename F>
class Managed : public F {
public:
virtual int close() {
virtual int close()
{
int err = F::close();
delete this;
return err;
@ -159,7 +160,8 @@ int FileSystem::open(FileHandle **file, const char *path, int flags)
return 0;
}
int FileSystem::open(DirHandle **dir, const char *path) {
int FileSystem::open(DirHandle **dir, const char *path)
{
Dir *d = new Managed<Dir>;
int err = d->open(this, path);
if (err) {

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