mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #8591 from 0xc0170/fix_coding_style_features
features: fix coding stylepull/8697/head
commit
9d95d46d6c
|
@ -3,17 +3,22 @@ cmsis
|
||||||
features/cryptocell
|
features/cryptocell
|
||||||
features/mbedtls
|
features/mbedtls
|
||||||
features/lwipstack/lwip
|
features/lwipstack/lwip
|
||||||
|
features/lwipstack/lwip-sys
|
||||||
rtos/TARGET_CORTEX/rtx4
|
rtos/TARGET_CORTEX/rtx4
|
||||||
features/storage/filesystem/littlefs/littlefs/
|
features/storage/filesystem/littlefs/littlefs/
|
||||||
features/storage/filesystem/fat/ChaN
|
features/storage/filesystem/fat/ChaN
|
||||||
features/storage/FEATURE_STORAGE
|
features/storage/FEATURE_STORAGE
|
||||||
features/frameworks
|
features/frameworks
|
||||||
features/FEATURE_BLE/targets
|
features/FEATURE_BLE
|
||||||
features/unsupported/
|
features/unsupported/
|
||||||
|
features/netsocket/emac-drivers
|
||||||
hal/storage_abstraction
|
hal/storage_abstraction
|
||||||
FEATURE_NANOSTACK/coap-service
|
TESTS/mbed_hal/trng/pithy
|
||||||
FEATURE_NANOSTACK/sal-stack-nanostack
|
features/nanostack/coap-service
|
||||||
|
features/nanostack/sal-stack-nanostack
|
||||||
rtos/TARGET_CORTEX/rtx5
|
rtos/TARGET_CORTEX/rtx5
|
||||||
TESTS/mbed_hal/trng/pithy
|
TESTS/mbed_hal/trng/pithy
|
||||||
targets
|
targets
|
||||||
|
components/802.15.4_RF
|
||||||
|
components/wifi
|
||||||
tools
|
tools
|
||||||
|
|
|
@ -66,6 +66,7 @@ Case cases[] = {
|
||||||
|
|
||||||
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
Harness::run(specification);
|
Harness::run(specification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ void wifi_connect(void)
|
||||||
{
|
{
|
||||||
WiFiInterface *wifi = get_interface();
|
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->set_credentials(ssid, NULL));
|
||||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect());
|
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());
|
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
|
||||||
|
|
||||||
// Driver is expected to cache the credentials
|
// 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->connect());
|
||||||
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
|
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
|
||||||
|
|
|
@ -422,10 +422,10 @@ TEST_F(Test_LoRaPHY, compute_rx_win_params)
|
||||||
list[0] = 125000;
|
list[0] = 125000;
|
||||||
object->get_phy_params().bandwidths.table = list;
|
object->get_phy_params().bandwidths.table = list;
|
||||||
uint8_t list2[1];
|
uint8_t list2[1];
|
||||||
list2[0]= 12;
|
list2[0] = 12;
|
||||||
object->get_phy_params().datarates.table = &list2;
|
object->get_phy_params().datarates.table = &list2;
|
||||||
channel_params_t ch_lst[16];
|
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].band = 0;
|
||||||
ch_lst[0].dr_range.fields.min = DR_0;
|
ch_lst[0].dr_range.fields.min = DR_0;
|
||||||
ch_lst[0].dr_range.fields.max = DR_5;
|
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;
|
object->get_phy_params().max_channel_cnt = 16;
|
||||||
channel_params_t li[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;
|
object->get_phy_params().channels.channel_list = li;
|
||||||
li[0].frequency = 0;
|
li[0].frequency = 0;
|
||||||
li[1].frequency = 5;
|
li[1].frequency = 5;
|
||||||
|
@ -673,7 +673,7 @@ TEST_F(Test_LoRaPHY, set_next_channel)
|
||||||
ch = 5;
|
ch = 5;
|
||||||
t1 = 16;
|
t1 = 16;
|
||||||
t2 = 32;
|
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.size = 2;
|
||||||
object->get_phy_params().bands.table = &b;
|
object->get_phy_params().bands.table = &b;
|
||||||
b[0].off_time = 0;
|
b[0].off_time = 0;
|
||||||
|
@ -767,7 +767,7 @@ TEST_F(Test_LoRaPHY, set_tx_cont_mode)
|
||||||
|
|
||||||
cw_mode_params_t p;
|
cw_mode_params_t p;
|
||||||
p.max_eirp = 0;
|
p.max_eirp = 0;
|
||||||
p.channel=0;
|
p.channel = 0;
|
||||||
p.tx_power = -1;
|
p.tx_power = -1;
|
||||||
p.datarate = 0;
|
p.datarate = 0;
|
||||||
p.antenna_gain = 1;
|
p.antenna_gain = 1;
|
||||||
|
|
|
@ -35,7 +35,8 @@ using namespace mbed;
|
||||||
// Ticker operations
|
// Ticker operations
|
||||||
#if MBED_CONF_RTOS_PRESENT
|
#if MBED_CONF_RTOS_PRESENT
|
||||||
|
|
||||||
unsigned equeue_tick() {
|
unsigned equeue_tick()
|
||||||
|
{
|
||||||
return osKernelGetTickCount();
|
return osKernelGetTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,16 +56,18 @@ unsigned equeue_tick() {
|
||||||
static bool equeue_tick_inited = false;
|
static bool equeue_tick_inited = false;
|
||||||
static volatile unsigned equeue_minutes = 0;
|
static volatile unsigned equeue_minutes = 0;
|
||||||
static unsigned equeue_timer[
|
static unsigned equeue_timer[
|
||||||
(sizeof(ALIAS_TIMER)+sizeof(unsigned)-1)/sizeof(unsigned)];
|
(sizeof(ALIAS_TIMER) + sizeof(unsigned) - 1) / sizeof(unsigned)];
|
||||||
static unsigned equeue_ticker[
|
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() {
|
static void equeue_tick_update()
|
||||||
equeue_minutes += reinterpret_cast<ALIAS_TIMER*>(equeue_timer)->read_ms();
|
{
|
||||||
reinterpret_cast<ALIAS_TIMER*>(equeue_timer)->reset();
|
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),
|
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),
|
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
|
||||||
|
@ -79,7 +82,8 @@ static void equeue_tick_init() {
|
||||||
equeue_tick_inited = true;
|
equeue_tick_inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned equeue_tick() {
|
unsigned equeue_tick()
|
||||||
|
{
|
||||||
if (!equeue_tick_inited) {
|
if (!equeue_tick_inited) {
|
||||||
equeue_tick_init();
|
equeue_tick_init();
|
||||||
}
|
}
|
||||||
|
@ -89,7 +93,7 @@ unsigned equeue_tick() {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
minutes = equeue_minutes;
|
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);
|
} while (minutes != equeue_minutes);
|
||||||
|
|
||||||
return minutes + ms;
|
return minutes + ms;
|
||||||
|
@ -98,14 +102,19 @@ unsigned equeue_tick() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Mutex operations
|
// 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_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();
|
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();
|
core_util_critical_section_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +122,8 @@ void equeue_mutex_unlock(equeue_mutex_t *m) {
|
||||||
// Semaphore operations
|
// Semaphore operations
|
||||||
#ifdef MBED_CONF_RTOS_PRESENT
|
#ifdef MBED_CONF_RTOS_PRESENT
|
||||||
|
|
||||||
int equeue_sema_create(equeue_sema_t *s) {
|
int equeue_sema_create(equeue_sema_t *s)
|
||||||
|
{
|
||||||
osEventFlagsAttr_t attr;
|
osEventFlagsAttr_t attr;
|
||||||
memset(&attr, 0, sizeof(attr));
|
memset(&attr, 0, sizeof(attr));
|
||||||
attr.cb_mem = &s->mem;
|
attr.cb_mem = &s->mem;
|
||||||
|
@ -123,15 +133,18 @@ int equeue_sema_create(equeue_sema_t *s) {
|
||||||
return !s->id ? -1 : 0;
|
return !s->id ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void equeue_sema_destroy(equeue_sema_t *s) {
|
void equeue_sema_destroy(equeue_sema_t *s)
|
||||||
|
{
|
||||||
osEventFlagsDelete(s->id);
|
osEventFlagsDelete(s->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void equeue_sema_signal(equeue_sema_t *s) {
|
void equeue_sema_signal(equeue_sema_t *s)
|
||||||
|
{
|
||||||
osEventFlagsSet(s->id, 1);
|
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) {
|
if (ms < 0) {
|
||||||
ms = osWaitForever;
|
ms = osWaitForever;
|
||||||
}
|
}
|
||||||
|
@ -142,29 +155,34 @@ bool equeue_sema_wait(equeue_sema_t *s, int ms) {
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Semaphore operations
|
// Semaphore operations
|
||||||
int equeue_sema_create(equeue_sema_t *s) {
|
int equeue_sema_create(equeue_sema_t *s)
|
||||||
|
{
|
||||||
*s = false;
|
*s = false;
|
||||||
return 0;
|
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;
|
*s = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void equeue_sema_timeout(equeue_sema_t *s) {
|
static void equeue_sema_timeout(equeue_sema_t *s)
|
||||||
|
{
|
||||||
*s = -1;
|
*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;
|
int signal = 0;
|
||||||
ALIAS_TIMEOUT timeout;
|
ALIAS_TIMEOUT timeout;
|
||||||
if (ms == 0) {
|
if (ms == 0) {
|
||||||
return false;
|
return false;
|
||||||
} else if (ms > 0) {
|
} 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();
|
core_util_critical_section_enter();
|
||||||
|
|
|
@ -223,7 +223,7 @@ static void test_credentials()
|
||||||
|
|
||||||
static void test_other()
|
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);
|
TEST_ASSERT(nw->get_3gpp_error() == 0);
|
||||||
|
|
||||||
CellularNetwork::RateControlExceptionReports reports;
|
CellularNetwork::RateControlExceptionReports reports;
|
||||||
|
|
|
@ -73,7 +73,7 @@ static void wait_for_power(CellularPower *pwr)
|
||||||
|
|
||||||
static void test_power_interface()
|
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 = new CELLULAR_DEVICE(queue);
|
||||||
cellular_device->set_timeout(5000);
|
cellular_device->set_timeout(5000);
|
||||||
CellularPower *pwr = cellular_device->open_power(&cellular_serial);
|
CellularPower *pwr = cellular_device->open_power(&cellular_serial);
|
||||||
|
@ -89,12 +89,12 @@ static void test_power_interface()
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
wait_for_power(pwr);
|
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);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
|
||||||
if (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
|
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
|
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
|
((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);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
|
||||||
if (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
|
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
|
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
|
((AT_CellularPower *)pwr)->get_device_error().errType == 3); // 3 == CME error from the modem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ static EventQueue queue(8 * EVENTS_EVENT_SIZE);
|
||||||
static rtos::Semaphore network_semaphore(0);
|
static rtos::Semaphore network_semaphore(0);
|
||||||
static CellularConnectionFSM *cellularConnectionFSM;
|
static CellularConnectionFSM *cellularConnectionFSM;
|
||||||
static CellularConnectionFSM::CellularState cellular_target_state;
|
static CellularConnectionFSM::CellularState cellular_target_state;
|
||||||
static CellularSMS* sms;
|
static CellularSMS *sms;
|
||||||
static char service_center_address[SMS_MAX_PHONE_NUMBER_SIZE];
|
static char service_center_address[SMS_MAX_PHONE_NUMBER_SIZE];
|
||||||
static int service_address_type;
|
static int service_address_type;
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ static void test_get_sms()
|
||||||
|
|
||||||
wait(7);
|
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(phone_num, MBED_CONF_APP_CELLULAR_PHONE_NUMBER) == 0);
|
||||||
TEST_ASSERT(strcmp(buf, TEST_MESSAGE) == 0);
|
TEST_ASSERT(strcmp(buf, TEST_MESSAGE) == 0);
|
||||||
TEST_ASSERT(buf_size == 0);
|
TEST_ASSERT(buf_size == 0);
|
||||||
|
|
|
@ -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
|
// Consume to delimiter or stop_tag
|
||||||
if (!delimiter_found && !_stop_tag->found) {
|
if (!delimiter_found && !_stop_tag->found) {
|
||||||
match_pos = 0;
|
match_pos = 0;
|
||||||
while(1) {
|
while (1) {
|
||||||
int c = get_char();
|
int c = get_char();
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
set_error(NSAPI_ERROR_DEVICE_ERROR);
|
set_error(NSAPI_ERROR_DEVICE_ERROR);
|
||||||
|
|
|
@ -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);
|
int len = _at.read_string(time_stamp, SMS_MAX_TIME_STAMP_SIZE);
|
||||||
if (len < (SMS_MAX_TIME_STAMP_SIZE - 2)) {
|
if (len < (SMS_MAX_TIME_STAMP_SIZE - 2)) {
|
||||||
time_stamp[len++] = ',';
|
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>
|
(void)_at.consume_to_stop_tag(); // consume until <CR><LF>
|
||||||
|
|
|
@ -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());
|
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
|
// setup internet connection profile for sockets
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
|
|
||||||
#include "AT_CellularDevice.h"
|
#include "AT_CellularDevice.h"
|
||||||
|
|
||||||
namespace mbed
|
namespace mbed {
|
||||||
{
|
|
||||||
|
|
||||||
class UBLOX_AT : public AT_CellularDevice {
|
class UBLOX_AT : public AT_CellularDevice {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -54,7 +54,7 @@ AT_CellularNetwork::RegistrationMode UBLOX_AT_CellularNetwork::has_registration(
|
||||||
|
|
||||||
nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
|
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)
|
#if defined(TARGET_UBLOX_C030_U201) || defined(TARGET_UBLOX_C027)
|
||||||
case RAT_GSM:
|
case RAT_GSM:
|
||||||
case RAT_GSM_COMPACT:
|
case RAT_GSM_COMPACT:
|
||||||
|
@ -119,9 +119,9 @@ nsapi_error_t UBLOX_AT_CellularNetwork::open_data_channel()
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
int active = 0;
|
int active = 0;
|
||||||
char * config = NULL;
|
char *config = NULL;
|
||||||
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
|
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
|
// do check for stack to validate that we have support for stack
|
||||||
_stack = get_stack();
|
_stack = get_stack();
|
||||||
|
@ -142,14 +142,14 @@ nsapi_error_t UBLOX_AT_CellularNetwork::open_data_channel()
|
||||||
if (_apn == NULL) {
|
if (_apn == NULL) {
|
||||||
err = get_imsi(imsi);
|
err = get_imsi(imsi);
|
||||||
if (err == NSAPI_ERROR_OK) {
|
if (err == NSAPI_ERROR_OK) {
|
||||||
config = (char*)apnconfig(imsi);
|
config = (char *)apnconfig(imsi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
do {
|
do {
|
||||||
get_next_credentials(&config);
|
get_next_credentials(&config);
|
||||||
if(_uname && _pwd) {
|
if (_uname && _pwd) {
|
||||||
_auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
|
_auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
|
||||||
} else {
|
} else {
|
||||||
_auth = NSAPI_SECURITY_NONE;
|
_auth = NSAPI_SECURITY_NONE;
|
||||||
|
@ -166,9 +166,9 @@ nsapi_error_t UBLOX_AT_CellularNetwork::open_data_channel()
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UBLOX_AT_CellularNetwork::activate_profile(const char* apn,
|
bool UBLOX_AT_CellularNetwork::activate_profile(const char *apn,
|
||||||
const char* username,
|
const char *username,
|
||||||
const char* password)
|
const char *password)
|
||||||
{
|
{
|
||||||
bool activated = false;
|
bool activated = false;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
@ -283,7 +283,7 @@ bool UBLOX_AT_CellularNetwork::disconnect_modem_stack()
|
||||||
return success;
|
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.lock();
|
||||||
_at.cmd_start("AT+CIMI");
|
_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.
|
// 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) {
|
if (*config) {
|
||||||
_apn = _APN_GET(*config);
|
_apn = _APN_GET(*config);
|
||||||
|
|
|
@ -21,11 +21,9 @@
|
||||||
#include "AT_CellularNetwork.h"
|
#include "AT_CellularNetwork.h"
|
||||||
#include "APN_db.h"
|
#include "APN_db.h"
|
||||||
|
|
||||||
namespace mbed
|
namespace mbed {
|
||||||
{
|
|
||||||
|
|
||||||
class UBLOX_AT_CellularNetwork : public AT_CellularNetwork
|
class UBLOX_AT_CellularNetwork : public AT_CellularNetwork {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
UBLOX_AT_CellularNetwork(ATHandler &atHandler);
|
UBLOX_AT_CellularNetwork(ATHandler &atHandler);
|
||||||
virtual ~UBLOX_AT_CellularNetwork();
|
virtual ~UBLOX_AT_CellularNetwork();
|
||||||
|
@ -69,7 +67,7 @@ private:
|
||||||
* NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
|
* NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
|
||||||
* @return True if successful, otherwise false.
|
* @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.
|
/** Convert nsapi_security_t to the modem security numbers.
|
||||||
*
|
*
|
||||||
|
@ -86,11 +84,11 @@ private:
|
||||||
|
|
||||||
/** Read IMSI of modem.
|
/** 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.
|
/** Get the next set of credentials from the database.
|
||||||
*/
|
*/
|
||||||
void get_next_credentials(char ** config);
|
void get_next_credentials(char **config);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -20,11 +20,9 @@
|
||||||
|
|
||||||
#include "AT_CellularPower.h"
|
#include "AT_CellularPower.h"
|
||||||
|
|
||||||
namespace mbed
|
namespace mbed {
|
||||||
{
|
|
||||||
|
|
||||||
class UBLOX_AT_CellularPower : public AT_CellularPower
|
class UBLOX_AT_CellularPower : public AT_CellularPower {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
UBLOX_AT_CellularPower(ATHandler &atHandler);
|
UBLOX_AT_CellularPower(ATHandler &atHandler);
|
||||||
virtual ~UBLOX_AT_CellularPower();
|
virtual ~UBLOX_AT_CellularPower();
|
||||||
|
|
|
@ -47,11 +47,11 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_accept(void *server, void **socket,
|
||||||
// Callback for Socket Read URC.
|
// Callback for Socket Read URC.
|
||||||
void UBLOX_AT_CellularStack::UUSORD_URC()
|
void UBLOX_AT_CellularStack::UUSORD_URC()
|
||||||
{
|
{
|
||||||
int a,b;
|
int a, b;
|
||||||
CellularSocket *socket;
|
CellularSocket *socket;
|
||||||
|
|
||||||
a =_at.read_int();
|
a = _at.read_int();
|
||||||
b =_at.read_int();
|
b = _at.read_int();
|
||||||
|
|
||||||
socket = find_socket(a);
|
socket = find_socket(a);
|
||||||
if (socket != NULL) {
|
if (socket != NULL) {
|
||||||
|
@ -67,11 +67,11 @@ void UBLOX_AT_CellularStack::UUSORD_URC()
|
||||||
// Callback for Socket Read From URC.
|
// Callback for Socket Read From URC.
|
||||||
void UBLOX_AT_CellularStack::UUSORF_URC()
|
void UBLOX_AT_CellularStack::UUSORF_URC()
|
||||||
{
|
{
|
||||||
int a,b;
|
int a, b;
|
||||||
CellularSocket *socket;
|
CellularSocket *socket;
|
||||||
|
|
||||||
a =_at.read_int();
|
a = _at.read_int();
|
||||||
b =_at.read_int();
|
b = _at.read_int();
|
||||||
|
|
||||||
socket = find_socket(a);
|
socket = find_socket(a);
|
||||||
if (socket != NULL) {
|
if (socket != NULL) {
|
||||||
|
@ -90,7 +90,7 @@ void UBLOX_AT_CellularStack::UUSOCL_URC()
|
||||||
int a;
|
int a;
|
||||||
CellularSocket *socket;
|
CellularSocket *socket;
|
||||||
|
|
||||||
a =_at.read_int();
|
a = _at.read_int();
|
||||||
socket = find_socket(a);
|
socket = find_socket(a);
|
||||||
clear_socket(socket);
|
clear_socket(socket);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ void UBLOX_AT_CellularStack::UUPSDD_URC()
|
||||||
int a;
|
int a;
|
||||||
CellularSocket *socket;
|
CellularSocket *socket;
|
||||||
|
|
||||||
a =_at.read_int();
|
a = _at.read_int();
|
||||||
socket = find_socket(a);
|
socket = find_socket(a);
|
||||||
clear_socket(socket);
|
clear_socket(socket);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
|
||||||
_at.resp_start("+USOCR:");
|
_at.resp_start("+USOCR:");
|
||||||
sock_id = _at.read_int();
|
sock_id = _at.read_int();
|
||||||
_at.resp_stop();
|
_at.resp_stop();
|
||||||
} else if(socket->proto == NSAPI_TCP) {
|
} else if (socket->proto == NSAPI_TCP) {
|
||||||
_at.cmd_start("AT+USOCR=6");
|
_at.cmd_start("AT+USOCR=6");
|
||||||
_at.cmd_stop();
|
_at.cmd_stop();
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
|
||||||
if (socket) {
|
if (socket) {
|
||||||
if (!socket->created) {
|
if (!socket->created) {
|
||||||
nsapi_error_t err = create_socket_impl(socket);
|
nsapi_error_t err = create_socket_impl(socket);
|
||||||
if(err != NSAPI_ERROR_OK) {
|
if (err != NSAPI_ERROR_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_close_impl(int sock_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find or create a socket from the list.
|
// 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;
|
CellularSocket *socket = NULL;
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ UBLOX_AT_CellularStack::CellularSocket * UBLOX_AT_CellularStack::find_socket(int
|
||||||
|
|
||||||
|
|
||||||
// Clear out the storage for a socket
|
// 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) {
|
if (socket != NULL) {
|
||||||
socket->id = SOCKET_UNUSED;
|
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.lock();
|
||||||
_at.cmd_start("AT+UPSND=" PROFILE ",0");
|
_at.cmd_start("AT+UPSND=" PROFILE ",0");
|
||||||
|
@ -449,7 +449,7 @@ const char * UBLOX_AT_CellularStack::get_ip_address()
|
||||||
if (_at.info_resp()) {
|
if (_at.info_resp()) {
|
||||||
_at.skip_param();
|
_at.skip_param();
|
||||||
_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) {
|
if (len == -1) {
|
||||||
_ip[0] = '\0';
|
_ip[0] = '\0';
|
||||||
_at.unlock();
|
_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
|
// in case stack type is not IPV4 only, try to look also for IPV6 address
|
||||||
if (_stack_type != IPV4_STACK) {
|
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();
|
_at.resp_stop();
|
||||||
|
|
|
@ -23,11 +23,9 @@
|
||||||
#include "drivers/Timer.h"
|
#include "drivers/Timer.h"
|
||||||
|
|
||||||
|
|
||||||
namespace mbed
|
namespace mbed {
|
||||||
{
|
|
||||||
|
|
||||||
class UBLOX_AT_CellularStack : public AT_CellularStack
|
class UBLOX_AT_CellularStack : public AT_CellularStack {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
|
UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
|
||||||
virtual ~UBLOX_AT_CellularStack();
|
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_listen(nsapi_socket_t handle, int backlog);
|
||||||
|
|
||||||
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
|
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
|
protected: // AT_CellularStack
|
||||||
|
|
||||||
|
@ -97,14 +95,14 @@ private:
|
||||||
* @param id Socket ID.
|
* @param id Socket ID.
|
||||||
* @return Socket if True, otherwise NULL.
|
* @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.
|
/** Clear out the storage for a socket.
|
||||||
*
|
*
|
||||||
* @param id Cellular Socket.
|
* @param id Cellular Socket.
|
||||||
* @return None
|
* @return None
|
||||||
*/
|
*/
|
||||||
void clear_socket(CellularSocket * socket);
|
void clear_socket(CellularSocket *socket);
|
||||||
};
|
};
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
#endif /* UBLOX_AT_CELLULARSTACK_H_ */
|
#endif /* UBLOX_AT_CELLULARSTACK_H_ */
|
||||||
|
|
|
@ -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")
|
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) { }
|
static void feature_lwip(void) { }
|
||||||
void dummy_feature_lwip_is_deprecated(void) { feature_lwip(); }
|
void dummy_feature_lwip_is_deprecated(void)
|
||||||
|
{
|
||||||
|
feature_lwip();
|
||||||
|
}
|
||||||
|
|
|
@ -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")
|
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) { }
|
static void feature_nanostack(void) { }
|
||||||
void dummy_feature_nanostack_is_deprecated(void) { feature_nanostack(); }
|
void dummy_feature_nanostack_is_deprecated(void)
|
||||||
|
{
|
||||||
|
feature_nanostack();
|
||||||
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ int inject_dummy_rot_key()
|
||||||
|
|
||||||
memcpy(key, "1234567812345678", DEVICE_KEY_16BYTE);
|
memcpy(key, "1234567812345678", DEVICE_KEY_16BYTE);
|
||||||
int size = 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);
|
return devkey.device_inject_root_of_trust(key, size);
|
||||||
#else
|
#else
|
||||||
return DEVICEKEY_SUCCESS;
|
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.";
|
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
|
||||||
int key_type = DEVICE_KEY_16BYTE;
|
int key_type = DEVICE_KEY_16BYTE;
|
||||||
uint16_t actual_size = 0;
|
uint16_t actual_size = 0;
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
size_t salt_size = sizeof(salt);
|
size_t salt_size = sizeof(salt);
|
||||||
|
|
||||||
if (strcmp(key, MSG_KEY_DEVICE_TEST_STEP1) == 0) {
|
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";
|
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
|
||||||
int key_type = DEVICE_KEY_32BYTE;
|
int key_type = DEVICE_KEY_32BYTE;
|
||||||
uint16_t actual_size = 0;
|
uint16_t actual_size = 0;
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
size_t salt_size = sizeof(salt);
|
size_t salt_size = sizeof(salt);
|
||||||
|
|
||||||
if (strcmp(key, MSG_KEY_DEVICE_TEST_STEP3) == 0) {
|
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()
|
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)];
|
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
|
||||||
|
|
||||||
memcpy(key, "12345678123456788765432187654321", DEVICE_KEY_32BYTE);
|
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()
|
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)];
|
uint32_t rkey[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
|
||||||
uint16_t actual_size;
|
uint16_t actual_size;
|
||||||
uint32_t key[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
|
uint32_t key[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
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()
|
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)];
|
uint32_t rkey[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
|
||||||
uint16_t actual_size;
|
uint16_t actual_size;
|
||||||
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
|
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
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()
|
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)];
|
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
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 empty_buffer[DEVICE_KEY_16BYTE];
|
||||||
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
|
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
|
||||||
int key_type = DEVICE_KEY_16BYTE;
|
int key_type = DEVICE_KEY_16BYTE;
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
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 empty_buffer[DEVICE_KEY_32BYTE];
|
||||||
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
|
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
|
||||||
int key_type = DEVICE_KEY_32BYTE;
|
int key_type = DEVICE_KEY_32BYTE;
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
||||||
|
@ -369,8 +369,8 @@ void generate_derived_key_key_type_16_test()
|
||||||
unsigned char expectedString[] = "Some String";
|
unsigned char expectedString[] = "Some String";
|
||||||
int key_type = DEVICE_KEY_16BYTE;
|
int key_type = DEVICE_KEY_16BYTE;
|
||||||
size_t salt_size = sizeof(salt);
|
size_t salt_size = sizeof(salt);
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
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;
|
int key_type = DEVICE_KEY_32BYTE;
|
||||||
size_t salt_size = sizeof(salt);
|
size_t salt_size = sizeof(salt);
|
||||||
unsigned char expectedString[] = "Some String";
|
unsigned char expectedString[] = "Some String";
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
|
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 output[DEVICE_KEY_16BYTE];
|
||||||
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
|
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
|
||||||
size_t salt_size = sizeof(salt);
|
size_t salt_size = sizeof(salt);
|
||||||
DeviceKey& devkey = DeviceKey::get_instance();
|
DeviceKey &devkey = DeviceKey::get_instance();
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
|
|
||||||
nvstore.init();
|
nvstore.init();
|
||||||
int ret = nvstore.reset();
|
int ret = nvstore.reset();
|
||||||
|
|
|
@ -117,7 +117,7 @@ int DeviceKey::write_key_to_nvstore(uint32_t *input, size_t isize)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
NVStore& nvstore = NVStore::get_instance();
|
NVStore &nvstore = NVStore::get_instance();
|
||||||
ret = nvstore.set(NVSTORE_DEVICEKEY_KEY, (uint16_t)isize, input);
|
ret = nvstore.set(NVSTORE_DEVICEKEY_KEY, (uint16_t)isize, input);
|
||||||
if (NVSTORE_WRITE_ERROR == ret || NVSTORE_BUFF_TOO_SMALL == ret) {
|
if (NVSTORE_WRITE_ERROR == ret || NVSTORE_BUFF_TOO_SMALL == ret) {
|
||||||
return DEVICEKEY_SAVE_FAILED;
|
return DEVICEKEY_SAVE_FAILED;
|
||||||
|
@ -130,15 +130,15 @@ int DeviceKey::write_key_to_nvstore(uint32_t *input, size_t isize)
|
||||||
return DEVICEKEY_SUCCESS;
|
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;
|
return DEVICEKEY_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t in_size = size;
|
uint16_t in_size = size;
|
||||||
uint16_t out_size = 0;
|
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);
|
int nvStatus = nvstore.get(NVSTORE_DEVICEKEY_KEY, in_size, output, out_size);
|
||||||
if (NVSTORE_NOT_FOUND == nvStatus) {
|
if (NVSTORE_NOT_FOUND == nvStatus) {
|
||||||
return DEVICEKEY_NOT_FOUND;
|
return DEVICEKEY_NOT_FOUND;
|
||||||
|
@ -190,7 +190,7 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
|
||||||
goto finish;
|
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));
|
ret = mbedtls_cipher_cmac_update(&ctx, (unsigned char *)counter_enc, sizeof(counter_enc));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -217,7 +217,7 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_cipher_free( &ctx );
|
mbedtls_cipher_free(&ctx);
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
if (DEVICEKEY_SUCCESS != ret) {
|
if (DEVICEKEY_SUCCESS != ret) {
|
||||||
mbedtls_cipher_free( &ctx );
|
mbedtls_cipher_free(&ctx);
|
||||||
return DEVICEKEY_ERR_CMAC_GENERIC_FAILURE;
|
return DEVICEKEY_ERR_CMAC_GENERIC_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
*
|
*
|
||||||
* @returns Singleton instance reference.
|
* @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
|
// 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
|
// 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
|
* Output: The actual size of the written data
|
||||||
* @return 0 on success, negative error code on failure
|
* @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
|
/** Set a device key into the NVStore
|
||||||
* @param input Input buffer contain the key.
|
* @param input Input buffer contain the key.
|
||||||
|
|
|
@ -184,8 +184,7 @@ typedef struct radio_events {
|
||||||
/**
|
/**
|
||||||
* Interface for the radios, contains the main functions that a radio needs, and five callback functions.
|
* Interface for the radios, contains the main functions that a radio needs, and five callback functions.
|
||||||
*/
|
*/
|
||||||
class LoRaRadio
|
class LoRaRadio {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -246,7 +245,7 @@ public:
|
||||||
* @param rx_continuous Sets the reception in continuous mode.
|
* @param rx_continuous Sets the reception in continuous mode.
|
||||||
* [false: single mode, true: 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 datarate, uint8_t coderate,
|
||||||
uint32_t bandwidth_afc, uint16_t preamble_len,
|
uint32_t bandwidth_afc, uint16_t preamble_len,
|
||||||
uint16_t symb_timeout, bool fix_len,
|
uint16_t symb_timeout, bool fix_len,
|
||||||
|
|
|
@ -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.
|
//Application should not use reserved and illegal port numbers.
|
||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
return allow_port_0;
|
return allow_port_0;
|
||||||
} else if (port == COMPLIANCE_TESTING_PORT){
|
} else if (port == COMPLIANCE_TESTING_PORT) {
|
||||||
#if !defined(LORAWAN_COMPLIANCE_TEST)
|
#if !defined(LORAWAN_COMPLIANCE_TEST)
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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 + 2] << 16);
|
||||||
mic_rx |= ((uint32_t) payload[size - LORAMAC_MFR_LEN + 3] << 24);
|
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;
|
sequence_counter_diff = sequence_counter - sequence_counter_prev;
|
||||||
*downlink_counter += sequence_counter_diff;
|
*downlink_counter += sequence_counter_diff;
|
||||||
if (sequence_counter < sequence_counter_prev) {
|
if (sequence_counter < sequence_counter_prev) {
|
||||||
|
@ -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) {
|
if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
|
||||||
_lora_time.stop(_rx2_closure_timer_for_class_c);
|
_lora_time.stop(_rx2_closure_timer_for_class_c);
|
||||||
open_rx2_window();
|
open_rx2_window();
|
||||||
} else if (_device_class != CLASS_C){
|
} else if (_device_class != CLASS_C) {
|
||||||
_lora_time.stop(_params.timers.rx_window1_timer);
|
_lora_time.stop(_params.timers.rx_window1_timer);
|
||||||
_lora_phy->put_radio_to_sleep();
|
_lora_phy->put_radio_to_sleep();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ void LoRaMacChannelPlan::activate_channelplan_subsystem(LoRaPHY *phy)
|
||||||
_lora_phy = 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;
|
lorawan_status_t status;
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
|
lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t &plan,
|
||||||
const channel_params_t* channel_list)
|
const channel_params_t *channel_list)
|
||||||
{
|
{
|
||||||
uint8_t max_num_channels;
|
uint8_t max_num_channels;
|
||||||
uint16_t *channel_mask;
|
uint16_t *channel_mask;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
* @return LORAWAN_STATUS_OK if everything goes well otherwise
|
* @return LORAWAN_STATUS_OK if everything goes well otherwise
|
||||||
* a negative error code is returned.
|
* 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
|
/** Access the active channel plan
|
||||||
*
|
*
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
* @return LORAWAN_STATUS_OK if everything goes well otherwise
|
* @return LORAWAN_STATUS_OK if everything goes well otherwise
|
||||||
* a negative error code is returned.
|
* 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
|
/** Remove the active channel plan
|
||||||
*
|
*
|
||||||
|
|
|
@ -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,
|
lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, uint8_t mac_index,
|
||||||
uint8_t commands_size, uint8_t snr,
|
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,
|
lora_mac_system_params_t &mac_sys_params,
|
||||||
LoRaPHY &lora_phy)
|
LoRaPHY &lora_phy)
|
||||||
{
|
{
|
||||||
|
|
|
@ -116,9 +116,9 @@ public:
|
||||||
*/
|
*/
|
||||||
lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index,
|
lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index,
|
||||||
uint8_t commands_size, uint8_t snr,
|
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_params,
|
lora_mac_system_params_t &mac_params,
|
||||||
LoRaPHY& lora_phy);
|
LoRaPHY &lora_phy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds a new LinkCheckReq MAC command to be sent.
|
* @brief Adds a new LinkCheckReq MAC command to be sent.
|
||||||
|
|
|
@ -63,30 +63,35 @@ int LoRaMacCrypto::compute_mic(const uint8_t *buffer, uint16_t size,
|
||||||
|
|
||||||
mbedtls_cipher_init(aes_cmac_ctx);
|
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) {
|
if (NULL != cipher_info) {
|
||||||
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
|
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
|
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, mic_block_b0, sizeof(mic_block_b0));
|
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, mic_block_b0, sizeof(mic_block_b0));
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
|
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
|
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
*mic = (uint32_t) ((uint32_t) computed_mic[3] << 24
|
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24
|
||||||
| (uint32_t) computed_mic[2] << 16
|
| (uint32_t) computed_mic[2] << 16
|
||||||
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
|
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,8 +117,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
|
||||||
|
|
||||||
mbedtls_aes_init(&aes_ctx);
|
mbedtls_aes_init(&aes_ctx);
|
||||||
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
|
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
a_block[0] = 0x01;
|
a_block[0] = 0x01;
|
||||||
a_block[5] = dir;
|
a_block[5] = dir;
|
||||||
|
@ -133,8 +139,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
|
||||||
ctr++;
|
ctr++;
|
||||||
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
|
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
|
||||||
s_block);
|
s_block);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[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);
|
a_block[15] = ((ctr) & 0xFF);
|
||||||
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
|
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
|
||||||
s_block);
|
s_block);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
|
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
|
||||||
|
@ -177,26 +185,30 @@ int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *buffer, uint16_t size,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
mbedtls_cipher_init(aes_cmac_ctx);
|
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) {
|
if (NULL != cipher_info) {
|
||||||
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
|
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
|
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
|
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
|
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
*mic = (uint32_t) ((uint32_t) computed_mic[3] << 24
|
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24
|
||||||
| (uint32_t) computed_mic[2] << 16
|
| (uint32_t) computed_mic[2] << 16
|
||||||
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
|
| (uint32_t) computed_mic[1] << 8 | (uint32_t) computed_mic[0]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,13 +229,15 @@ int LoRaMacCrypto::decrypt_join_frame(const uint8_t *buffer, uint16_t size,
|
||||||
mbedtls_aes_init(&aes_ctx);
|
mbedtls_aes_init(&aes_ctx);
|
||||||
|
|
||||||
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
|
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, buffer,
|
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, buffer,
|
||||||
dec_buffer);
|
dec_buffer);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if optional CFList is included
|
// Check if optional CFList is included
|
||||||
if (size >= 16) {
|
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);
|
mbedtls_aes_init(&aes_ctx);
|
||||||
|
|
||||||
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
|
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
memset(nonce, 0, sizeof(nonce));
|
memset(nonce, 0, sizeof(nonce));
|
||||||
nonce[0] = 0x01;
|
nonce[0] = 0x01;
|
||||||
memcpy(nonce + 1, app_nonce, 6);
|
memcpy(nonce + 1, app_nonce, 6);
|
||||||
memcpy(nonce + 7, p_dev_nonce, 2);
|
memcpy(nonce + 7, p_dev_nonce, 2);
|
||||||
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, nwk_skey);
|
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, nwk_skey);
|
||||||
if (0 != ret)
|
if (0 != ret) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
memset(nonce, 0, sizeof(nonce));
|
memset(nonce, 0, sizeof(nonce));
|
||||||
nonce[0] = 0x02;
|
nonce[0] = 0x02;
|
||||||
|
@ -279,7 +295,7 @@ LoRaMacCrypto::LoRaMacCrypto()
|
||||||
// user knows what is wrong and in addition to that these ensure that
|
// user knows what is wrong and in addition to that these ensure that
|
||||||
// Mbed-OS compiles properly under normal conditions where LoRaWAN in conjunction
|
// Mbed-OS compiles properly under normal conditions where LoRaWAN in conjunction
|
||||||
// with mbedTLS is not being used.
|
// 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 *)
|
uint8_t dir, uint32_t, uint32_t *)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
|
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;
|
return LORAWAN_STATUS_CRYPTO_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
|
int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint32_t,
|
||||||
uint8_t , uint32_t , uint8_t *)
|
uint8_t, uint32_t, uint8_t *)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
|
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;
|
return LORAWAN_STATUS_CRYPTO_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
|
int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint32_t,
|
||||||
uint8_t , uint32_t , uint8_t *)
|
uint8_t, uint32_t, uint8_t *)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
|
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;
|
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");
|
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;
|
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");
|
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;
|
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 *)
|
uint8_t *, uint8_t *)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
|
MBED_ASSERT(0 && "[LoRaCrypto] Must enable AES, CMAC & CIPHER from mbedTLS");
|
||||||
|
|
|
@ -34,8 +34,7 @@ SPDX-License-Identifier: BSD-3-Clause
|
||||||
#include "mbedtls/cmac.h"
|
#include "mbedtls/cmac.h"
|
||||||
|
|
||||||
|
|
||||||
class LoRaMacCrypto
|
class LoRaMacCrypto {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
|
|
@ -404,7 +404,7 @@ void LoRaPHY::get_rx_window_params(double t_symb, uint8_t min_rx_symb,
|
||||||
{
|
{
|
||||||
// Computed number of symbols
|
// 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_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,
|
int8_t LoRaPHY::compute_tx_power(int8_t tx_power_idx, float max_eirp,
|
||||||
|
|
|
@ -147,7 +147,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return bit mask, according to the LoRaWAN spec 1.0.2.
|
* @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.
|
/** Process PHY layer state after a successful transmission.
|
||||||
* @brief set_last_tx_done Updates times of the last transmission for the particular channel and
|
* @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.
|
* @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.
|
/** 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.
|
* @return True, if an ADR request should be performed.
|
||||||
*/
|
*/
|
||||||
bool get_next_ADR(bool restore_channel_mask, int8_t& dr_out,
|
bool get_next_ADR(bool restore_channel_mask, int8_t &dr_out,
|
||||||
int8_t& tx_power_out, uint32_t& adr_ack_counter);
|
int8_t &tx_power_out, uint32_t &adr_ack_counter);
|
||||||
|
|
||||||
/** Configure radio reception.
|
/** Configure radio reception.
|
||||||
*
|
*
|
||||||
|
@ -198,7 +198,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return True, if the configuration was applied successfully.
|
* @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
|
/** Computing Receive Windows
|
||||||
*
|
*
|
||||||
|
@ -268,8 +268,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return True, if the configuration was applied successfully.
|
* @return True, if the configuration was applied successfully.
|
||||||
*/
|
*/
|
||||||
virtual bool tx_config(tx_config_params_t* tx_config, int8_t* tx_power,
|
virtual bool tx_config(tx_config_params_t *tx_config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa);
|
lorawan_time_t *tx_toa);
|
||||||
|
|
||||||
/** Processes a Link ADR Request.
|
/** Processes a Link ADR Request.
|
||||||
*
|
*
|
||||||
|
@ -285,10 +285,10 @@ public:
|
||||||
*
|
*
|
||||||
* @return The status of the operation, according to the LoRaMAC specification.
|
* @return The status of the operation, according to the LoRaMAC specification.
|
||||||
*/
|
*/
|
||||||
virtual uint8_t link_ADR_request(adr_req_params_t* params,
|
virtual uint8_t link_ADR_request(adr_req_params_t *params,
|
||||||
int8_t* dr_out, int8_t* tx_power_out,
|
int8_t *dr_out, int8_t *tx_power_out,
|
||||||
uint8_t* nb_rep_out,
|
uint8_t *nb_rep_out,
|
||||||
uint8_t* nb_bytes_parsed);
|
uint8_t *nb_bytes_parsed);
|
||||||
|
|
||||||
/** Accept or rejects RxParamSetupReq MAC command
|
/** Accept or rejects RxParamSetupReq MAC command
|
||||||
*
|
*
|
||||||
|
@ -299,7 +299,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return The status of the operation, according to the LoRaWAN specification.
|
* @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.
|
* @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].
|
* @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,
|
virtual lorawan_status_t set_next_channel(channel_selection_params_t *nextChanParams,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregatedTimeOff);
|
lorawan_time_t *aggregatedTimeOff);
|
||||||
|
|
||||||
/** Adds a channel to the channel list.
|
/** Adds a channel to the channel list.
|
||||||
*
|
*
|
||||||
|
@ -361,7 +361,7 @@ public:
|
||||||
* @return LORAWAN_STATUS_OK if everything goes fine, negative error code
|
* @return LORAWAN_STATUS_OK if everything goes fine, negative error code
|
||||||
* otherwise.
|
* 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.
|
/** Removes a channel from the channel list.
|
||||||
*
|
*
|
||||||
|
@ -377,7 +377,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param [in] frequency Frequency to transmit at
|
* @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);
|
uint32_t frequency = 0);
|
||||||
|
|
||||||
/** Computes new data rate according to the given offset
|
/** 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
|
* @param get_default If true the default mask is returned, otherwise the current mask is returned
|
||||||
* @return A channel mask
|
* @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
|
* @brief get_max_nb_channels Gets maximum number of channels supported
|
||||||
|
@ -486,7 +486,7 @@ public:
|
||||||
* @brief get_phy_channels Gets PHY channels
|
* @brief get_phy_channels Gets PHY channels
|
||||||
* @return 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
|
* @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.
|
* 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.
|
* 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
|
* 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.
|
* 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);
|
uint8_t stop_idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy channel masks.
|
* 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.
|
* 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);
|
uint8_t nb_bands);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the parameter of an LinkAdrRequest.
|
* 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
|
* Verifies and updates the datarate, the TX power and the number of repetitions
|
||||||
* of a LinkAdrRequest.
|
* of a LinkAdrRequest.
|
||||||
*/
|
*/
|
||||||
uint8_t verify_link_ADR_req(verify_adr_params_t* verify_params, int8_t* dr,
|
uint8_t verify_link_ADR_req(verify_adr_params_t *verify_params, int8_t *dr,
|
||||||
int8_t* tx_pow, uint8_t* nb_rep);
|
int8_t *tx_pow, uint8_t *nb_rep);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the RX window timeout and the RX window offset.
|
* Computes the RX window timeout and the RX window offset.
|
||||||
*/
|
*/
|
||||||
void get_rx_window_params(double t_symbol, uint8_t min_rx_symbols,
|
void get_rx_window_params(double t_symbol, uint8_t min_rx_symbols,
|
||||||
uint32_t rx_error, uint32_t wakeup_time,
|
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.
|
* 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 get_bandwidth(uint8_t dr_index);
|
||||||
|
|
||||||
uint8_t enabled_channel_count(uint8_t datarate,
|
uint8_t enabled_channel_count(uint8_t datarate,
|
||||||
const uint16_t *mask, uint8_t* enabledChannels,
|
const uint16_t *mask, uint8_t *enabledChannels,
|
||||||
uint8_t* delayTx);
|
uint8_t *delayTx);
|
||||||
|
|
||||||
bool is_datarate_supported(const int8_t datarate) const;
|
bool is_datarate_supported(const int8_t datarate) const;
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Computes the symbol time for LoRa modulation.
|
* 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.
|
* Computes the symbol time for FSK modulation.
|
||||||
|
|
|
@ -194,13 +194,13 @@ static const band_t AS923_BAND0 = {100, AS923_MAX_TX_POWER, 0, 0, 0, 923000000,
|
||||||
* LoRaMac default channel 1
|
* LoRaMac default channel 1
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 2
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* 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};
|
static const uint32_t bandwidths_AS923[] = {125000, 125000, 125000, 125000, 125000, 125000, 250000, 0};
|
||||||
|
|
||||||
#if (MBED_CONF_LORA_DWELL_TIME == 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[] = {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_with_repeater[] = {51, 51, 51, 115, 222, 222, 222, 222};
|
||||||
#else
|
#else
|
||||||
// this is the default, i.e.,
|
// 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[] = {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};
|
static const uint8_t max_payload_table_with_repeater[] = {0, 0, 11, 53, 125, 242, 242, 242};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -336,9 +336,9 @@ int8_t LoRaPHYAS923::get_alternate_DR(uint8_t nb_trials)
|
||||||
return AS923_DWELL_LIMIT_DATARATE;
|
return AS923_DWELL_LIMIT_DATARATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next_channel_prams,
|
lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t *next_channel_prams,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregate_timeoff)
|
lorawan_time_t *aggregate_timeoff)
|
||||||
{
|
{
|
||||||
uint8_t next_channel_idx = 0;
|
uint8_t next_channel_idx = 0;
|
||||||
uint8_t nb_enabled_channels = 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++) {
|
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];
|
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
|
// Perform carrier sense for AS923_CARRIER_SENSE_TIME
|
||||||
// If the channel is free, we can stop the LBT mechanism
|
// 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
|
// Datarate not supported by any channel, restore defaults
|
||||||
channel_mask[0] |= LC( 1 ) + LC( 2 );
|
channel_mask[0] |= LC(1) + LC(2);
|
||||||
*time = 0;
|
*time = 0;
|
||||||
return LORAWAN_STATUS_NO_CHANNEL_FOUND;
|
return LORAWAN_STATUS_NO_CHANNEL_FOUND;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ public:
|
||||||
|
|
||||||
virtual int8_t get_alternate_DR(uint8_t nb_trials);
|
virtual int8_t get_alternate_DR(uint8_t nb_trials);
|
||||||
|
|
||||||
virtual lorawan_status_t set_next_channel(channel_selection_params_t* nextChanParams,
|
virtual lorawan_status_t set_next_channel(channel_selection_params_t *nextChanParams,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregatedTimeOff );
|
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:
|
private:
|
||||||
channel_params_t channels[AS923_MAX_NB_CHANNELS];
|
channel_params_t channels[AS923_MAX_NB_CHANNELS];
|
||||||
|
|
|
@ -193,32 +193,37 @@ static const uint8_t datarates_AU915[] = {12, 11, 10, 9, 8, 7, 8, 0, 12, 11, 10,
|
||||||
*/
|
*/
|
||||||
static const uint32_t bandwidths_AU915[] = { 125000, 125000, 125000, 125000,
|
static const uint32_t bandwidths_AU915[] = { 125000, 125000, 125000, 125000,
|
||||||
125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000,
|
125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000,
|
||||||
0, 0 };
|
0, 0
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Up/Down link data rates offset definition
|
* Up/Down link data rates offset definition
|
||||||
*/
|
*/
|
||||||
static const int8_t datarate_offsets_AU915[7][6] = { { DR_8, DR_8, DR_8, DR_8,
|
static const int8_t datarate_offsets_AU915[7][6] = { {
|
||||||
DR_8, DR_8 }, // DR_0
|
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_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_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_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_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_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
|
{ 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.
|
* 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,
|
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.
|
* 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,
|
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;
|
static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK;
|
||||||
|
|
||||||
|
@ -232,14 +237,14 @@ LoRaPHYAU915::LoRaPHYAU915()
|
||||||
// 125 kHz channels Upstream only
|
// 125 kHz channels Upstream only
|
||||||
for (uint8_t i = 0; i < AU915_MAX_NB_CHANNELS - 8; i++) {
|
for (uint8_t i = 0; i < AU915_MAX_NB_CHANNELS - 8; i++) {
|
||||||
channels[i].frequency = 915200000 + i * 200000;
|
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;
|
channels[i].band = 0;
|
||||||
}
|
}
|
||||||
// 500 kHz channels
|
// 500 kHz channels
|
||||||
// Upstream and downstream both
|
// Upstream and downstream both
|
||||||
for (uint8_t i = AU915_MAX_NB_CHANNELS - 8; i < AU915_MAX_NB_CHANNELS; i++) {
|
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].frequency = 915900000 + (i - (AU915_MAX_NB_CHANNELS - 8)) * 1600000;
|
||||||
channels[i].dr_range.value = ( DR_6 << 4) | DR_6;
|
channels[i].dr_range.value = (DR_6 << 4) | DR_6;
|
||||||
channels[i].band = 0;
|
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;
|
int8_t dr = params->datarate;
|
||||||
uint8_t max_payload = 0;
|
uint8_t max_payload = 0;
|
||||||
|
@ -377,8 +382,8 @@ bool LoRaPHYAU915::rx_config(rx_config_params_t* params)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoRaPHYAU915::tx_config(tx_config_params_t* params, int8_t* tx_power,
|
bool LoRaPHYAU915::tx_config(tx_config_params_t *params, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa)
|
lorawan_time_t *tx_toa)
|
||||||
{
|
{
|
||||||
int8_t phy_dr = datarates_AU915[params->datarate];
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t* params,
|
uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t *params,
|
||||||
int8_t* dr_out, int8_t* tx_power_out,
|
int8_t *dr_out, int8_t *tx_power_out,
|
||||||
uint8_t* nb_rep_out,
|
uint8_t *nb_rep_out,
|
||||||
uint8_t* nb_bytes_parsed)
|
uint8_t *nb_bytes_parsed)
|
||||||
{
|
{
|
||||||
uint8_t status = 0x07;
|
uint8_t status = 0x07;
|
||||||
link_adr_params_t adr_settings = {};
|
link_adr_params_t adr_settings = {};
|
||||||
|
@ -505,7 +510,7 @@ uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t* params,
|
||||||
return status;
|
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;
|
uint8_t status = 0x07;
|
||||||
uint32_t freq = params->frequency;
|
uint32_t freq = params->frequency;
|
||||||
|
@ -553,9 +558,9 @@ int8_t LoRaPHYAU915::get_alternate_DR(uint8_t nb_trials)
|
||||||
return datarate;
|
return datarate;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t* next_chan_params,
|
lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t *next_chan_params,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregated_timeOff)
|
lorawan_time_t *aggregated_timeOff)
|
||||||
{
|
{
|
||||||
uint8_t nb_enabled_channels = 0;
|
uint8_t nb_enabled_channels = 0;
|
||||||
uint8_t delay_tx = 0;
|
uint8_t delay_tx = 0;
|
||||||
|
|
|
@ -49,30 +49,30 @@
|
||||||
#define AU915_CHANNEL_MASK_SIZE 5
|
#define AU915_CHANNEL_MASK_SIZE 5
|
||||||
|
|
||||||
|
|
||||||
class LoRaPHYAU915 : public LoRaPHY{
|
class LoRaPHYAU915 : public LoRaPHY {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LoRaPHYAU915();
|
LoRaPHYAU915();
|
||||||
virtual ~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,
|
virtual bool tx_config(tx_config_params_t *config, int8_t *txPower,
|
||||||
lorawan_time_t* txTimeOnAir);
|
lorawan_time_t *txTimeOnAir);
|
||||||
|
|
||||||
virtual uint8_t link_ADR_request(adr_req_params_t* params,
|
virtual uint8_t link_ADR_request(adr_req_params_t *params,
|
||||||
int8_t* drOut, int8_t* txPowOut,
|
int8_t *drOut, int8_t *txPowOut,
|
||||||
uint8_t* nbRepOut,
|
uint8_t *nbRepOut,
|
||||||
uint8_t* nbBytesParsed);
|
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 int8_t get_alternate_DR(uint8_t nb_trials);
|
||||||
|
|
||||||
virtual lorawan_status_t set_next_channel(channel_selection_params_t* next_chan_params,
|
virtual lorawan_status_t set_next_channel(channel_selection_params_t *next_chan_params,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregate_timeoff);
|
lorawan_time_t *aggregate_timeoff);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -212,10 +212,9 @@ LoRaPHYCN470::LoRaPHYCN470()
|
||||||
|
|
||||||
// Channels
|
// Channels
|
||||||
// 125 kHz 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].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;
|
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;
|
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;
|
int8_t dr = config->datarate;
|
||||||
uint8_t max_payload = 0;
|
uint8_t max_payload = 0;
|
||||||
|
@ -375,8 +374,7 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
|
||||||
|
|
||||||
_radio->unlock();
|
_radio->unlock();
|
||||||
|
|
||||||
if( config->rx_slot == RX_SLOT_WIN_1 )
|
if (config->rx_slot == RX_SLOT_WIN_1) {
|
||||||
{
|
|
||||||
// Apply window 1 frequency
|
// Apply window 1 frequency
|
||||||
frequency = CN470_FIRST_RX1_CHANNEL + (config->channel % 48) * CN470_STEPWIDTH_RX1_CHANNEL;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
|
bool LoRaPHYCN470::tx_config(tx_config_params_t *config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa)
|
lorawan_time_t *tx_toa)
|
||||||
{
|
{
|
||||||
int8_t phy_dr = datarates_CN470[config->datarate];
|
int8_t phy_dr = datarates_CN470[config->datarate];
|
||||||
|
|
||||||
|
@ -446,10 +444,10 @@ bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
|
uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t *params,
|
||||||
int8_t* dr_out, int8_t* tx_power_out,
|
int8_t *dr_out, int8_t *tx_power_out,
|
||||||
uint8_t* nb_rep_out,
|
uint8_t *nb_rep_out,
|
||||||
uint8_t* nb_bytes_parsed)
|
uint8_t *nb_bytes_parsed)
|
||||||
{
|
{
|
||||||
uint8_t status = 0x07;
|
uint8_t status = 0x07;
|
||||||
link_adr_params_t adr_settings;
|
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
|
// Initialize local copy of channels mask
|
||||||
copy_channel_mask(temp_channel_masks, channel_mask, CN470_CHANNEL_MASK_SIZE);
|
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
|
// Get ADR request parameters
|
||||||
next_index = parse_link_ADR_req(&(params->payload[bytes_processed]), &adr_settings);
|
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;
|
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
|
status &= 0xFE; // Channel mask KO
|
||||||
|
|
||||||
|
@ -492,7 +490,7 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 16; i++) {
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
|
||||||
if (((adr_settings.channel_mask & (1 << i)) != 0 ) &&
|
if (((adr_settings.channel_mask & (1 << i)) != 0) &&
|
||||||
(channels[adr_settings.ch_mask_ctrl * 16 + i].frequency == 0)) {
|
(channels[adr_settings.ch_mask_ctrl * 16 + i].frequency == 0)) {
|
||||||
// Trying to enable an undefined channel
|
// Trying to enable an undefined channel
|
||||||
status &= 0xFE; // Channel mask KO
|
status &= 0xFE; // Channel mask KO
|
||||||
|
@ -533,7 +531,7 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
|
||||||
return status;
|
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;
|
uint8_t status = 0x07;
|
||||||
uint32_t freq = params->frequency;
|
uint32_t freq = params->frequency;
|
||||||
|
|
|
@ -60,16 +60,16 @@ public:
|
||||||
uint8_t *channel, lorawan_time_t *time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t *aggregate_timeoff);
|
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,
|
virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa);
|
lorawan_time_t *tx_toa);
|
||||||
|
|
||||||
virtual uint8_t link_ADR_request(adr_req_params_t* params, int8_t* dr_out,
|
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,
|
int8_t *tx_power_out, uint8_t *nb_rep_out,
|
||||||
uint8_t* nb_bytes_parsed);
|
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:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -191,18 +191,18 @@ static const band_t CN779_BAND0 = {100, CN779_MAX_TX_POWER, 0, 0, 0, 779500000,
|
||||||
* LoRaMac default channel 1
|
* LoRaMac default channel 1
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 2
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 3
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac channels which are allowed for the join procedure
|
||||||
|
|
|
@ -191,19 +191,19 @@ static const band_t EU433_BAND0 = {100, EU433_MAX_TX_POWER, 0, 0, 0, 433175000,
|
||||||
* LoRaMac default channel 1
|
* LoRaMac default channel 1
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 2
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 3
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac channels which are allowed for the join procedure
|
||||||
|
|
|
@ -182,12 +182,12 @@
|
||||||
* Band 0 definition
|
* Band 0 definition
|
||||||
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
|
* { 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
|
* Band 1 definition
|
||||||
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
|
* { 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
|
* 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 3 definition
|
||||||
* Band = { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
|
* 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 4 definition
|
||||||
* Band = { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
|
* 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
|
* 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
|
* LoRaMac default channel 1
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 2
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 3
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac channels which are allowed for the join procedure
|
||||||
|
|
|
@ -182,25 +182,25 @@
|
||||||
* Band 0 definition
|
* Band 0 definition
|
||||||
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
|
* { 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
|
* LoRaMac default channel 1
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 2
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 3
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac channels which are allowed for the join procedure
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
LoRaPHYIN865();
|
LoRaPHYIN865();
|
||||||
virtual ~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:
|
private:
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -186,25 +186,25 @@
|
||||||
* Band 0 definition
|
* Band 0 definition
|
||||||
* { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff }
|
* { 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
|
* LoRaMac default channel 1
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 2
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac default channel 3
|
||||||
* Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
|
* 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
|
* LoRaMac channels which are allowed for the join procedure
|
||||||
|
@ -254,7 +254,7 @@ LoRaPHYKR920::LoRaPHYKR920()
|
||||||
channels[2].band = 0;
|
channels[2].band = 0;
|
||||||
|
|
||||||
// Initialize the channels default mask
|
// 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
|
// Update the channels mask
|
||||||
copy_channel_mask(channel_mask, default_channel_mask, KR920_CHANNEL_MASK_SIZE);
|
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
|
// Verify if the frequency is valid. The frequency must be in a specified
|
||||||
// range and can be set to specific values.
|
// 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
|
// Range ok, check for specific value
|
||||||
tmp_freq -= 920900000;
|
tmp_freq -= 920900000;
|
||||||
if ((tmp_freq % 200000) == 0) {
|
if ((tmp_freq % 200000) == 0) {
|
||||||
|
@ -367,8 +367,8 @@ bool LoRaPHYKR920::verify_frequency_for_band(uint32_t freq, uint8_t band) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoRaPHYKR920::tx_config(tx_config_params_t* config, int8_t* tx_power,
|
bool LoRaPHYKR920::tx_config(tx_config_params_t *config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa)
|
lorawan_time_t *tx_toa)
|
||||||
{
|
{
|
||||||
int8_t phy_dr = datarates_KR920[config->datarate];
|
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_channel(channels[config->channel].frequency);
|
||||||
|
|
||||||
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
|
_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
|
// Setup maximum payload lenght of the radio driver
|
||||||
_radio->set_max_payload_length(MODEM_LORA, config->pkt_len);
|
_radio->set_max_payload_length(MODEM_LORA, config->pkt_len);
|
||||||
// Get the time-on-air of the next tx frame
|
// 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();
|
_radio->unlock();
|
||||||
|
|
||||||
|
@ -406,9 +406,9 @@ bool LoRaPHYKR920::tx_config(tx_config_params_t* config, int8_t* tx_power,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* params,
|
lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t *params,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregate_timeoff)
|
lorawan_time_t *aggregate_timeoff)
|
||||||
{
|
{
|
||||||
uint8_t next_channel_idx = 0;
|
uint8_t next_channel_idx = 0;
|
||||||
uint8_t nb_enabled_channels = 0;
|
uint8_t nb_enabled_channels = 0;
|
||||||
|
@ -443,7 +443,7 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
|
||||||
for (uint8_t i = 0, j = get_random(0, nb_enabled_channels - 1);
|
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];
|
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
|
// Perform carrier sense for KR920_CARRIER_SENSE_TIME
|
||||||
// If the channel is free, we can stop the LBT mechanism
|
// 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,
|
if (_radio->perform_carrier_sense(MODEM_LORA,
|
||||||
channels[next_channel_idx].frequency,
|
channels[next_channel_idx].frequency,
|
||||||
KR920_RSSI_FREE_TH,
|
KR920_RSSI_FREE_TH,
|
||||||
KR920_CARRIER_SENSE_TIME ) == true) {
|
KR920_CARRIER_SENSE_TIME) == true) {
|
||||||
// Free channel found
|
// Free channel found
|
||||||
*channel = next_channel_idx;
|
*channel = next_channel_idx;
|
||||||
*time = 0;
|
*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;
|
(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.
|
// Take the minimum between the max_eirp and params->max_eirp.
|
||||||
// The value of params->max_eirp could have changed during runtime,
|
// The value of params->max_eirp could have changed during runtime,
|
||||||
// e.g. due to a MAC command.
|
// 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
|
// Calculate physical TX power
|
||||||
phy_tx_power = compute_tx_power(params->tx_power, max_eirp, params->antenna_gain);
|
phy_tx_power = compute_tx_power(params->tx_power, max_eirp, params->antenna_gain);
|
||||||
|
|
|
@ -56,14 +56,14 @@ public:
|
||||||
|
|
||||||
virtual bool verify_frequency_for_band(uint32_t freq, uint8_t band) const;
|
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,
|
virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa);
|
lorawan_time_t *tx_toa);
|
||||||
|
|
||||||
virtual lorawan_status_t set_next_channel(channel_selection_params_t* params, uint8_t* channel,
|
virtual lorawan_status_t set_next_channel(channel_selection_params_t *params, uint8_t *channel,
|
||||||
lorawan_time_t* time,
|
lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregate_timeOff);
|
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);
|
uint32_t frequency = 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -192,10 +192,9 @@ static const uint32_t bandwidths_US915[] = {125000, 125000, 125000, 125000, 5000
|
||||||
/*!
|
/*!
|
||||||
* Up/Down link data rates offset definition
|
* Up/Down link data rates offset definition
|
||||||
*/
|
*/
|
||||||
static const int8_t datarate_offsets_US915[5][4] =
|
static const int8_t datarate_offsets_US915[5][4] = {
|
||||||
{
|
{ DR_10, DR_9, DR_8, DR_8 }, // DR_0
|
||||||
{ DR_10, DR_9 , DR_8 , DR_8 }, // DR_0
|
{ DR_11, DR_10, DR_9, DR_8 }, // DR_1
|
||||||
{ DR_11, DR_10, DR_9 , DR_8 }, // DR_1
|
|
||||||
{ DR_12, DR_11, DR_10, DR_9 }, // DR_2
|
{ DR_12, DR_11, DR_10, DR_9 }, // DR_2
|
||||||
{ DR_13, DR_12, DR_11, DR_10 }, // DR_3
|
{ DR_13, DR_12, DR_11, DR_10 }, // DR_3
|
||||||
{ DR_13, DR_13, DR_12, DR_11 }, // DR_4
|
{ DR_13, DR_13, DR_12, DR_11 }, // DR_4
|
||||||
|
@ -222,13 +221,13 @@ LoRaPHYUS915::LoRaPHYUS915()
|
||||||
// 125 kHz channels - Upstream
|
// 125 kHz channels - Upstream
|
||||||
for (uint8_t i = 0; i < US915_MAX_NB_CHANNELS - 8; i++) {
|
for (uint8_t i = 0; i < US915_MAX_NB_CHANNELS - 8; i++) {
|
||||||
channels[i].frequency = 902300000 + i * 200000;
|
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;
|
channels[i].band = 0;
|
||||||
}
|
}
|
||||||
// 500 kHz channels - Upstream
|
// 500 kHz channels - Upstream
|
||||||
for (uint8_t i = US915_MAX_NB_CHANNELS - 8; i < US915_MAX_NB_CHANNELS; i++) {
|
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].frequency = 903000000 + (i - (US915_MAX_NB_CHANNELS - 8)) * 1600000;
|
||||||
channels[i].dr_range.value = ( DR_4 << 4) | DR_4;
|
channels[i].dr_range.value = (DR_4 << 4) | DR_4;
|
||||||
channels[i].band = 0;
|
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;
|
int8_t tx_power_out = tx_power;
|
||||||
|
|
||||||
// Limit tx power to the band max
|
// 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) {
|
if (datarate == DR_4) {
|
||||||
// Limit tx power to max 26dBm
|
// 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 {
|
} else {
|
||||||
|
|
||||||
if (num_active_channels(channel_mask, 0, 4) < 50) {
|
if (num_active_channels(channel_mask, 0, 4) < 50) {
|
||||||
// Limit tx power to max 21dBm
|
// 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);
|
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;
|
int8_t dr = config->datarate;
|
||||||
uint8_t max_payload = 0;
|
uint8_t max_payload = 0;
|
||||||
|
@ -410,8 +409,8 @@ bool LoRaPHYUS915::rx_config(rx_config_params_t* config)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
|
bool LoRaPHYUS915::tx_config(tx_config_params_t *config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa)
|
lorawan_time_t *tx_toa)
|
||||||
{
|
{
|
||||||
int8_t phy_dr = datarates_US915[config->datarate];
|
int8_t phy_dr = datarates_US915[config->datarate];
|
||||||
int8_t tx_power_limited = limit_tx_power(config->tx_power,
|
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;
|
int8_t phy_tx_power = 0;
|
||||||
|
|
||||||
// Calculate physical TX power
|
// 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();
|
_radio->lock();
|
||||||
|
|
||||||
|
@ -445,9 +444,9 @@ bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
|
uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t *params,
|
||||||
int8_t* dr_out, int8_t* tx_power_out,
|
int8_t *dr_out, int8_t *tx_power_out,
|
||||||
uint8_t* nb_rep_out, uint8_t* nb_bytes_parsed)
|
uint8_t *nb_rep_out, uint8_t *nb_bytes_parsed)
|
||||||
{
|
{
|
||||||
uint8_t status = 0x07;
|
uint8_t status = 0x07;
|
||||||
|
|
||||||
|
@ -543,7 +542,7 @@ uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
|
||||||
return status;
|
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;
|
uint8_t status = 0x07;
|
||||||
uint32_t freq = params->frequency;
|
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
|
// 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
|
status &= 0xFB; // Rx1DrOffset range KO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,9 +591,9 @@ int8_t LoRaPHYUS915::get_alternate_DR(uint8_t nb_trials)
|
||||||
return datarate;
|
return datarate;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* params,
|
lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t *params,
|
||||||
uint8_t* channel, lorawan_time_t* time,
|
uint8_t *channel, lorawan_time_t *time,
|
||||||
lorawan_time_t* aggregate_timeOff)
|
lorawan_time_t *aggregate_timeOff)
|
||||||
{
|
{
|
||||||
uint8_t nb_enabled_channels = 0;
|
uint8_t nb_enabled_channels = 0;
|
||||||
uint8_t delay_tx = 0;
|
uint8_t delay_tx = 0;
|
||||||
|
@ -654,7 +652,7 @@ 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;
|
(void)given_frequency;
|
||||||
|
|
||||||
|
|
|
@ -56,24 +56,24 @@ public:
|
||||||
|
|
||||||
virtual void restore_default_channels();
|
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,
|
virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power,
|
||||||
lorawan_time_t* tx_toa);
|
lorawan_time_t *tx_toa);
|
||||||
|
|
||||||
virtual uint8_t link_ADR_request(adr_req_params_t* params,
|
virtual uint8_t link_ADR_request(adr_req_params_t *params,
|
||||||
int8_t* dr_out, int8_t* tx_power_out,
|
int8_t *dr_out, int8_t *tx_power_out,
|
||||||
uint8_t* nb_rep_out,
|
uint8_t *nb_rep_out,
|
||||||
uint8_t* nb_bytes_parsed);
|
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 int8_t get_alternate_DR(uint8_t nb_trials);
|
||||||
|
|
||||||
virtual lorawan_status_t set_next_channel(channel_selection_params_t* params, uint8_t* channel,
|
virtual lorawan_status_t set_next_channel(channel_selection_params_t *params, uint8_t *channel,
|
||||||
lorawan_time_t* time, lorawan_time_t* aggregate_timeOff);
|
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);
|
uint32_t frequency = 0);
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -307,7 +307,7 @@ typedef struct {
|
||||||
/*!
|
/*!
|
||||||
* A pointer to the payload containing the MAC commands.
|
* A pointer to the payload containing the MAC commands.
|
||||||
*/
|
*/
|
||||||
const uint8_t* payload;
|
const uint8_t *payload;
|
||||||
/*!
|
/*!
|
||||||
* The size of the 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.
|
* A pointer to the first element of the channels mask.
|
||||||
*/
|
*/
|
||||||
uint16_t* channel_mask;
|
uint16_t *channel_mask;
|
||||||
} verify_adr_params_t;
|
} verify_adr_params_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,38 +48,38 @@
|
||||||
#define mbed_lora_concat(x) mbed_lora_concat_(x)
|
#define mbed_lora_concat(x) mbed_lora_concat_(x)
|
||||||
#define LORA_REGION mbed_lora_concat(MBED_CONF_LORA_PHY)
|
#define LORA_REGION mbed_lora_concat(MBED_CONF_LORA_PHY)
|
||||||
|
|
||||||
#if LORA_REGION == LORA_REGION_EU868
|
#if LORA_REGION == LORA_REGION_EU868
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
|
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
|
||||||
#define LoRaPHY_region LoRaPHYEU868
|
#define LoRaPHY_region LoRaPHYEU868
|
||||||
#elif LORA_REGION == LORA_REGION_AS923
|
#elif LORA_REGION == LORA_REGION_AS923
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
|
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
|
||||||
#define LoRaPHY_region LoRaPHYAS923
|
#define LoRaPHY_region LoRaPHYAS923
|
||||||
#elif LORA_REGION == LORA_REGION_AU915
|
#elif LORA_REGION == LORA_REGION_AU915
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
|
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
|
||||||
#define LoRaPHY_region LoRaPHYAU915
|
#define LoRaPHY_region LoRaPHYAU915
|
||||||
#elif LORA_REGION == LORA_REGION_CN470
|
#elif LORA_REGION == LORA_REGION_CN470
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
|
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
|
||||||
#define LoRaPHY_region LoRaPHYCN470
|
#define LoRaPHY_region LoRaPHYCN470
|
||||||
#elif LORA_REGION == LORA_REGION_CN779
|
#elif LORA_REGION == LORA_REGION_CN779
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
|
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
|
||||||
#define LoRaPHY_region LoRaPHYCN779
|
#define LoRaPHY_region LoRaPHYCN779
|
||||||
#elif LORA_REGION == LORA_REGION_EU433
|
#elif LORA_REGION == LORA_REGION_EU433
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
|
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
|
||||||
#define LoRaPHY_region LoRaPHYEU433
|
#define LoRaPHY_region LoRaPHYEU433
|
||||||
#elif LORA_REGION == LORA_REGION_IN865
|
#elif LORA_REGION == LORA_REGION_IN865
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
|
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
|
||||||
#define LoRaPHY_region LoRaPHYIN865
|
#define LoRaPHY_region LoRaPHYIN865
|
||||||
#elif LORA_REGION == LORA_REGION_KR920
|
#elif LORA_REGION == LORA_REGION_KR920
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
|
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
|
||||||
#define LoRaPHY_region LoRaPHYKR920
|
#define LoRaPHY_region LoRaPHYKR920
|
||||||
#elif LORA_REGION == LORA_REGION_US915
|
#elif LORA_REGION == LORA_REGION_US915
|
||||||
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
|
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
|
||||||
#define LoRaPHY_region LoRaPHYUS915
|
#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
|
|
||||||
#else
|
#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 //MBED_CONF_LORA_PHY
|
||||||
|
|
||||||
#endif // LORAPHY_TARGET
|
#endif // LORAPHY_TARGET
|
||||||
|
|
|
@ -34,7 +34,7 @@ void LoRaWANTimeHandler::activate_timer_subsystem(events::EventQueue *queue)
|
||||||
_queue = 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();
|
const uint32_t current_time = _queue->tick();
|
||||||
return (lorawan_time_t)current_time;
|
return (lorawan_time_t)current_time;
|
||||||
|
|
|
@ -26,8 +26,7 @@ SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
#include "lorawan_data_structures.h"
|
#include "lorawan_data_structures.h"
|
||||||
|
|
||||||
class LoRaWANTimeHandler
|
class LoRaWANTimeHandler {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LoRaWANTimeHandler();
|
LoRaWANTimeHandler();
|
||||||
~LoRaWANTimeHandler();
|
~LoRaWANTimeHandler();
|
||||||
|
|
|
@ -78,8 +78,8 @@ typedef uint32_t lorawan_time_t;
|
||||||
*/
|
*/
|
||||||
// reject if user tries to set more than MTU
|
// reject if user tries to set more than MTU
|
||||||
#if MBED_CONF_LORA_TX_MAX_SIZE > 255
|
#if MBED_CONF_LORA_TX_MAX_SIZE > 255
|
||||||
#warning "Cannot set TX Max size more than MTU=255"
|
#warning "Cannot set TX Max size more than MTU=255"
|
||||||
#define MBED_CONF_LORA_TX_MAX_SIZE 255
|
#define MBED_CONF_LORA_TX_MAX_SIZE 255
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -186,7 +186,7 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
|
||||||
|
|
||||||
if (interface->client_callback && connectedStatusPrev != interface->connected
|
if (interface->client_callback && connectedStatusPrev != interface->connected
|
||||||
&& interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */
|
&& 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);
|
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)
|
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);
|
interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case NETIF_ADD_MAC_FILTER:
|
case NETIF_ADD_MAC_FILTER: {
|
||||||
{
|
|
||||||
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
|
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
|
||||||
uint8_t addr[6];
|
uint8_t addr[6];
|
||||||
addr[0] = LL_IP4_MULTICAST_ADDR_0;
|
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);
|
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case NETIF_ADD_MAC_FILTER:
|
case NETIF_ADD_MAC_FILTER: {
|
||||||
{
|
|
||||||
uint32_t group32 = ntohl(group->addr[3]);
|
uint32_t group32 = ntohl(group->addr[3]);
|
||||||
uint8_t addr[6];
|
uint8_t addr[6];
|
||||||
addr[0] = LL_IP6_MULTICAST_ADDR_0;
|
addr[0] = LL_IP6_MULTICAST_ADDR_0;
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "LWIPStack.h"
|
#include "LWIPStack.h"
|
||||||
|
|
||||||
#ifndef LWIP_SOCKET_MAX_MEMBERSHIPS
|
#ifndef LWIP_SOCKET_MAX_MEMBERSHIPS
|
||||||
#define LWIP_SOCKET_MAX_MEMBERSHIPS 4
|
#define LWIP_SOCKET_MAX_MEMBERSHIPS 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
|
void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
|
||||||
|
@ -273,7 +273,7 @@ nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
|
||||||
|
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
// Enable IPv6 (or dual-stack)
|
// 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
|
#endif
|
||||||
|
|
||||||
s->conn = netconn_new_with_callback(lwip_proto, &LWIP::socket_callback);
|
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;
|
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 count = 0;
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
// Set upper limit on while loop, should break out when the membership pair is found
|
// Set upper limit on while loop, should break out when the membership pair is found
|
||||||
|
@ -522,7 +523,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->conn->pcb.tcp->keep_idle = *(int*)optval;
|
s->conn->pcb.tcp->keep_idle = *(int *)optval;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case NSAPI_KEEPINTVL:
|
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;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->conn->pcb.tcp->keep_intvl = *(int*)optval;
|
s->conn->pcb.tcp->keep_intvl = *(int *)optval;
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#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 (optname == NSAPI_ADD_MEMBERSHIP) {
|
||||||
if (!s->multicast_memberships) {
|
if (!s->multicast_memberships) {
|
||||||
// First multicast join on this socket, allocate space for membership tracking
|
// 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) {
|
if (!s->multicast_memberships) {
|
||||||
return NSAPI_ERROR_NO_MEMORY;
|
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;
|
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();
|
adaptation.lock();
|
||||||
|
|
||||||
#if LWIP_IPV4
|
#if LWIP_IPV4
|
||||||
if (IP_IS_V4(&if_addr)) {
|
if (IP_IS_V4(&if_addr)) {
|
||||||
igmp_err = igmp_joingroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
|
igmp_err = igmp_joingroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
if (IP_IS_V6(&if_addr)) {
|
if (IP_IS_V6(&if_addr)) {
|
||||||
igmp_err = mld6_joingroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
|
igmp_err = mld6_joingroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
adaptation.unlock();
|
adaptation.unlock();
|
||||||
|
|
||||||
|
@ -626,16 +627,16 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
|
||||||
|
|
||||||
adaptation.lock();
|
adaptation.lock();
|
||||||
|
|
||||||
#if LWIP_IPV4
|
#if LWIP_IPV4
|
||||||
if (IP_IS_V4(&if_addr)) {
|
if (IP_IS_V4(&if_addr)) {
|
||||||
igmp_err = igmp_leavegroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
|
igmp_err = igmp_leavegroup(ip_2_ip4(&if_addr), ip_2_ip4(&multi_addr));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
if (IP_IS_V6(&if_addr)) {
|
if (IP_IS_V6(&if_addr)) {
|
||||||
igmp_err = mld6_leavegroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
|
igmp_err = mld6_leavegroup(ip_2_ip6(&if_addr), ip_2_ip6(&multi_addr));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
adaptation.unlock();
|
adaptation.unlock();
|
||||||
}
|
}
|
||||||
|
@ -662,7 +663,8 @@ void LWIP::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *
|
||||||
s->data = data;
|
s->data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
LWIP &LWIP::get_instance() {
|
LWIP &LWIP::get_instance()
|
||||||
|
{
|
||||||
static LWIP lwip;
|
static LWIP lwip;
|
||||||
return lwip;
|
return lwip;
|
||||||
}
|
}
|
||||||
|
@ -672,7 +674,8 @@ LWIP &LWIP::get_instance() {
|
||||||
#define LWIP 0x11991199
|
#define LWIP 0x11991199
|
||||||
#if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP
|
#if MBED_CONF_NSAPI_DEFAULT_STACK == LWIP
|
||||||
#undef LWIP
|
#undef LWIP
|
||||||
OnboardNetworkStack &OnboardNetworkStack::get_default_instance() {
|
OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
|
||||||
|
{
|
||||||
return LWIP::get_instance();
|
return LWIP::get_instance();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -120,24 +120,24 @@ public:
|
||||||
static void netif_status_irq(struct netif *netif);
|
static void netif_status_irq(struct netif *netif);
|
||||||
static Interface *our_if_from_netif(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);
|
static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
|
||||||
void emac_input(emac_mem_buf_t *buf);
|
void emac_input(emac_mem_buf_t *buf);
|
||||||
void emac_state_change(bool up);
|
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);
|
static err_t emac_igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action);
|
||||||
#endif
|
#endif
|
||||||
#if LWIP_IPV6_MLD
|
#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);
|
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);
|
static err_t emac_if_init(struct netif *netif);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
union {
|
union {
|
||||||
#if LWIP_ETHERNET
|
#if LWIP_ETHERNET
|
||||||
EMAC *emac; /**< HW specific emac implementation */
|
EMAC *emac; /**< HW specific emac implementation */
|
||||||
#endif
|
#endif
|
||||||
void *hw; /**< alternative implementation pointer - used for PPP */
|
void *hw; /**< alternative implementation pointer - used for PPP */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -147,17 +147,17 @@ public:
|
||||||
osSemaphoreId_t unlinked;
|
osSemaphoreId_t unlinked;
|
||||||
mbed_rtos_storage_semaphore_t has_any_addr_sem;
|
mbed_rtos_storage_semaphore_t has_any_addr_sem;
|
||||||
osSemaphoreId_t has_any_addr;
|
osSemaphoreId_t has_any_addr;
|
||||||
#define HAS_ANY_ADDR 1
|
#define HAS_ANY_ADDR 1
|
||||||
#if PREF_ADDR_TIMEOUT
|
#if PREF_ADDR_TIMEOUT
|
||||||
mbed_rtos_storage_semaphore_t has_pref_addr_sem;
|
mbed_rtos_storage_semaphore_t has_pref_addr_sem;
|
||||||
osSemaphoreId_t has_pref_addr;
|
osSemaphoreId_t has_pref_addr;
|
||||||
#define HAS_PREF_ADDR 2
|
#define HAS_PREF_ADDR 2
|
||||||
#endif
|
#endif
|
||||||
#if BOTH_ADDR_TIMEOUT
|
#if BOTH_ADDR_TIMEOUT
|
||||||
mbed_rtos_storage_semaphore_t has_both_addr_sem;
|
mbed_rtos_storage_semaphore_t has_both_addr_sem;
|
||||||
osSemaphoreId_t has_both_addr;
|
osSemaphoreId_t has_both_addr;
|
||||||
#define HAS_BOTH_ADDR 4
|
#define HAS_BOTH_ADDR 4
|
||||||
#endif
|
#endif
|
||||||
char has_addr_state;
|
char has_addr_state;
|
||||||
nsapi_connection_status_t connected;
|
nsapi_connection_status_t connected;
|
||||||
bool dhcp_started;
|
bool dhcp_started;
|
||||||
|
@ -301,7 +301,7 @@ protected:
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
|
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
|
/** Send data over a TCP socket
|
||||||
*
|
*
|
||||||
|
@ -487,21 +487,29 @@ private:
|
||||||
struct mbed_lwip_socket *arena_alloc();
|
struct mbed_lwip_socket *arena_alloc();
|
||||||
void arena_dealloc(struct mbed_lwip_socket *s);
|
void arena_dealloc(struct mbed_lwip_socket *s);
|
||||||
|
|
||||||
static uint32_t next_registered_multicast_member(const struct mbed_lwip_socket *s, uint32_t 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++; }
|
{
|
||||||
|
while (!(s->multicast_memberships_registry & (0x0001 << index))) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t next_free_multicast_member(const struct mbed_lwip_socket *s, uint32_t 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++; }
|
{
|
||||||
|
while ((s->multicast_memberships_registry & (0x0001 << index))) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
return 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);
|
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);
|
s->multicast_memberships_registry &= ~(0x0001 << index);
|
||||||
}
|
}
|
||||||
static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);
|
static int32_t find_multicast_member(const struct mbed_lwip_socket *s, const nsapi_ip_mreq_t *imr);
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
#include "netsocket/nsapi_types.h"
|
#include "netsocket/nsapi_types.h"
|
||||||
|
|
||||||
/* LWIP error remapping */
|
/* LWIP error remapping */
|
||||||
nsapi_error_t LWIP::err_remap(err_t err) {
|
nsapi_error_t LWIP::err_remap(err_t err)
|
||||||
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case ERR_OK:
|
case ERR_OK:
|
||||||
case ERR_CLSD:
|
case ERR_CLSD:
|
||||||
|
|
|
@ -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;
|
nsapi_error_t mapped_err_code = NSAPI_ERROR_NO_CONNECTION;
|
||||||
|
|
||||||
switch(err_code) {
|
switch (err_code) {
|
||||||
case PPPERR_NONE:
|
case PPPERR_NONE:
|
||||||
mapped_err_code = NSAPI_ERROR_OK;
|
mapped_err_code = NSAPI_ERROR_OK;
|
||||||
tr_info("status_cb: Connected");
|
tr_info("status_cb: Connected");
|
||||||
|
@ -247,7 +247,7 @@ static void ppp_input()
|
||||||
fhs.fh = my_stream;
|
fhs.fh = my_stream;
|
||||||
fhs.events = POLLIN;
|
fhs.events = POLLIN;
|
||||||
poll(&fhs, 1, 0);
|
poll(&fhs, 1, 0);
|
||||||
if (fhs.revents & (POLLHUP|POLLERR|POLLNVAL)) {
|
if (fhs.revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
||||||
handle_modem_hangup();
|
handle_modem_hangup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,8 @@ static void ppp_input()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stream_cb() {
|
static void stream_cb()
|
||||||
|
{
|
||||||
if (my_stream && !event_queued) {
|
if (my_stream && !event_queued) {
|
||||||
event_queued = true;
|
event_queued = true;
|
||||||
if (event_queue->call(callback(ppp_input)) == 0) {
|
if (event_queue->call(callback(ppp_input)) == 0) {
|
||||||
|
|
|
@ -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,
|
_socket = socket,
|
||||||
_stack = parent->_stack;
|
_stack = parent->_stack;
|
||||||
|
|
|
@ -70,12 +70,14 @@ public:
|
||||||
* @param stack Network stack as target for socket
|
* @param stack Network stack as target for socket
|
||||||
* @return 0 on success, negative error code on failure
|
* @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);
|
return tcp_socket.open(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename S>
|
template <typename S>
|
||||||
nsapi_error_t open(S *stack) {
|
nsapi_error_t open(S *stack)
|
||||||
|
{
|
||||||
return open(nsapi_create_stack(stack));
|
return open(nsapi_create_stack(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,8 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
|
||||||
_clicert(NULL),
|
_clicert(NULL),
|
||||||
#endif
|
#endif
|
||||||
_ssl_conf(NULL),
|
_ssl_conf(NULL),
|
||||||
_connect_transport(control==TRANSPORT_CONNECT || 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),
|
_close_transport(control == TRANSPORT_CLOSE || control == TRANSPORT_CONNECT_AND_CLOSE),
|
||||||
_handshake_completed(false),
|
_handshake_completed(false),
|
||||||
_cacert_allocated(false),
|
_cacert_allocated(false),
|
||||||
_clicert_allocated(false),
|
_clicert_allocated(false),
|
||||||
|
@ -50,7 +50,8 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TLSSocketWrapper::~TLSSocketWrapper() {
|
TLSSocketWrapper::~TLSSocketWrapper()
|
||||||
|
{
|
||||||
if (_transport) {
|
if (_transport) {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -120,13 +121,13 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, siz
|
||||||
int ret;
|
int ret;
|
||||||
mbedtls_x509_crt *crt = new mbedtls_x509_crt;
|
mbedtls_x509_crt *crt = new mbedtls_x509_crt;
|
||||||
mbedtls_x509_crt_init(crt);
|
mbedtls_x509_crt_init(crt);
|
||||||
if((ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(client_cert),
|
if ((ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(client_cert),
|
||||||
client_cert_len)) != 0) {
|
client_cert_len)) != 0) {
|
||||||
print_mbedtls_error("mbedtls_x509_crt_parse", ret);
|
print_mbedtls_error("mbedtls_x509_crt_parse", ret);
|
||||||
return NSAPI_ERROR_PARAMETER;
|
return NSAPI_ERROR_PARAMETER;
|
||||||
}
|
}
|
||||||
mbedtls_pk_init(&_pkctx);
|
mbedtls_pk_init(&_pkctx);
|
||||||
if((ret = mbedtls_pk_parse_key(&_pkctx, static_cast<const unsigned char *>(client_private_key_pem),
|
if ((ret = mbedtls_pk_parse_key(&_pkctx, static_cast<const unsigned char *>(client_private_key_pem),
|
||||||
client_private_key_len, NULL, 0)) != 0) {
|
client_private_key_len, NULL, 0)) != 0) {
|
||||||
print_mbedtls_error("mbedtls_pk_parse_key", ret);
|
print_mbedtls_error("mbedtls_pk_parse_key", ret);
|
||||||
return NSAPI_ERROR_PARAMETER;
|
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;
|
nsapi_error_t _error;
|
||||||
const char DRBG_PERS[] = "mbed TLS client";
|
const char DRBG_PERS[] = "mbed TLS client";
|
||||||
|
|
||||||
|
@ -154,7 +156,7 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = mbedtls_ctr_drbg_seed(&_ctr_drbg, mbedtls_entropy_func, &_entropy,
|
if ((ret = mbedtls_ctr_drbg_seed(&_ctr_drbg, mbedtls_entropy_func, &_entropy,
|
||||||
(const unsigned char *) DRBG_PERS,
|
(const unsigned char *) DRBG_PERS,
|
||||||
sizeof (DRBG_PERS))) != 0) {
|
sizeof(DRBG_PERS))) != 0) {
|
||||||
print_mbedtls_error("mbedtls_crt_drbg_init", ret);
|
print_mbedtls_error("mbedtls_crt_drbg_init", ret);
|
||||||
_error = ret;
|
_error = ret;
|
||||||
return _error;
|
return _error;
|
||||||
|
@ -177,7 +179,7 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
|
||||||
return _error;
|
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
|
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
||||||
/* Start the handshake, the rest will be done in onReceive() */
|
/* Start the handshake, the rest will be done in onReceive() */
|
||||||
|
@ -205,13 +207,13 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
|
||||||
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
||||||
/* Prints the server certificate and verify it. */
|
/* Prints the server certificate and verify it. */
|
||||||
const size_t buf_size = 1024;
|
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_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);
|
tr_debug("Server certificate:\r\n%s\r\n", buf);
|
||||||
|
|
||||||
uint32_t flags = mbedtls_ssl_get_verify_result(&_ssl);
|
uint32_t flags = mbedtls_ssl_get_verify_result(&_ssl);
|
||||||
if( flags != 0 ) {
|
if (flags != 0) {
|
||||||
/* Verification failed. */
|
/* Verification failed. */
|
||||||
mbedtls_x509_crt_verify_info(buf, buf_size, "\r ! ", flags);
|
mbedtls_x509_crt_verify_info(buf, buf_size, "\r ! ", flags);
|
||||||
tr_error("Certificate verification failed:\r\n%s", buf);
|
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;
|
int ret;
|
||||||
|
|
||||||
if (!_transport) {
|
if (!_transport) {
|
||||||
|
@ -255,7 +258,8 @@ nsapi_size_or_error_t TLSSocketWrapper::sendto(const SocketAddress &, const void
|
||||||
return send(data, size);
|
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;
|
int ret;
|
||||||
|
|
||||||
if (!_transport) {
|
if (!_transport) {
|
||||||
|
@ -287,7 +291,8 @@ nsapi_size_or_error_t TLSSocketWrapper::recvfrom(SocketAddress *address, void *d
|
||||||
return recv(data, size);
|
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
|
#ifdef MBEDTLS_ERROR_C
|
||||||
char *buf = new char[128];
|
char *buf = new char[128];
|
||||||
mbedtls_strerror(err, buf, 128);
|
mbedtls_strerror(err, buf, 128);
|
||||||
|
@ -309,8 +314,8 @@ void TLSSocketWrapper::my_debug(void *ctx, int level, const char *file, int line
|
||||||
(void) ctx;
|
(void) ctx;
|
||||||
|
|
||||||
/* Extract basename from file */
|
/* Extract basename from file */
|
||||||
for(p = basename = file; *p != '\0'; p++) {
|
for (p = basename = file; *p != '\0'; p++) {
|
||||||
if(*p == '/' || *p == '\\') {
|
if (*p == '/' || *p == '\\') {
|
||||||
basename = p + 1;
|
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);
|
mbedtls_x509_crt_info(buf, buf_size - 1, " ", crt);
|
||||||
tr_debug("%s", buf);
|
tr_debug("%s", buf);
|
||||||
|
|
||||||
if (*flags == 0)
|
if (*flags == 0) {
|
||||||
tr_info("No verification issue for this certificate\n");
|
tr_info("No verification issue for this certificate\n");
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
mbedtls_x509_crt_verify_info(buf, buf_size, " ! ", *flags);
|
mbedtls_x509_crt_verify_info(buf, buf_size, " ! ", *flags);
|
||||||
tr_info("%s\n", buf);
|
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 */
|
#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;
|
int recv;
|
||||||
|
|
||||||
TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx);
|
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) {
|
if (NSAPI_ERROR_WOULD_BLOCK == recv) {
|
||||||
return MBEDTLS_ERR_SSL_WANT_READ;
|
return MBEDTLS_ERR_SSL_WANT_READ;
|
||||||
} else if(recv < 0) {
|
} else if (recv < 0) {
|
||||||
tr_error("Socket recv error %d", recv);
|
tr_error("Socket recv error %d", recv);
|
||||||
}
|
}
|
||||||
// Propagate also Socket errors to SSL, it allows negative error codes to be returned here.
|
// Propagate also Socket errors to SSL, it allows negative error codes to be returned here.
|
||||||
return recv;
|
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;
|
int size = -1;
|
||||||
TLSSocketWrapper *my = static_cast<TLSSocketWrapper *>(ctx);
|
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) {
|
if (NSAPI_ERROR_WOULD_BLOCK == size) {
|
||||||
return MBEDTLS_ERR_SSL_WANT_WRITE;
|
return MBEDTLS_ERR_SSL_WANT_WRITE;
|
||||||
} else if(size < 0){
|
} else if (size < 0) {
|
||||||
tr_error("Socket send error %d", size);
|
tr_error("Socket send error %d", size);
|
||||||
}
|
}
|
||||||
// Propagate also Socket errors to SSL, it allows negative error codes to be returned here.
|
// Propagate also Socket errors to SSL, it allows negative error codes to be returned here.
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
||||||
|
|
||||||
|
@ -401,7 +407,7 @@ int TLSSocketWrapper::set_own_cert(mbedtls_x509_crt *crt)
|
||||||
}
|
}
|
||||||
_clicert = crt;
|
_clicert = crt;
|
||||||
if (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);
|
print_mbedtls_error("mbedtls_ssl_conf_own_cert", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,7 +448,7 @@ mbedtls_ssl_config *TLSSocketWrapper::get_ssl_config()
|
||||||
MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
|
MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
|
||||||
print_mbedtls_error("mbedtls_ssl_config_defaults", ret);
|
print_mbedtls_error("mbedtls_ssl_config_defaults", ret);
|
||||||
set_ssl_config(NULL);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* It is possible to disable authentication by passing
|
/* It is possible to disable authentication by passing
|
||||||
|
|
|
@ -219,17 +219,17 @@ private:
|
||||||
Socket *_transport;
|
Socket *_transport;
|
||||||
|
|
||||||
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
#ifdef MBEDTLS_X509_CRT_PARSE_C
|
||||||
mbedtls_x509_crt* _cacert;
|
mbedtls_x509_crt *_cacert;
|
||||||
mbedtls_x509_crt* _clicert;
|
mbedtls_x509_crt *_clicert;
|
||||||
#endif
|
#endif
|
||||||
mbedtls_ssl_config* _ssl_conf;
|
mbedtls_ssl_config *_ssl_conf;
|
||||||
|
|
||||||
bool _connect_transport:1;
|
bool _connect_transport: 1;
|
||||||
bool _close_transport:1;
|
bool _close_transport: 1;
|
||||||
bool _handshake_completed:1;
|
bool _handshake_completed: 1;
|
||||||
bool _cacert_allocated:1;
|
bool _cacert_allocated: 1;
|
||||||
bool _clicert_allocated:1;
|
bool _clicert_allocated: 1;
|
||||||
bool _ssl_conf_allocated:1;
|
bool _ssl_conf_allocated: 1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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");
|
success = at->send("AT+CLCK=\"SC\",1,\"%s\"", pin) && at->recv("OK");
|
||||||
} else {
|
} else {
|
||||||
/* use the SIM unlocked */
|
/* 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;
|
return NSAPI_ERROR_AUTH_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +399,7 @@ bool PPPCellularInterface::nwk_registration(uint8_t nwk_type)
|
||||||
retry_counter++;
|
retry_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
give_up:
|
give_up:
|
||||||
return registered;
|
return registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +446,8 @@ nsapi_error_t PPPCellularInterface::initialize_sim_card()
|
||||||
return nsapi_error;
|
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 */
|
/* overwrite the default pin by user provided pin */
|
||||||
_pin = pin;
|
_pin = pin;
|
||||||
}
|
}
|
||||||
|
@ -583,7 +586,7 @@ nsapi_error_t PPPCellularInterface::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
retry_init:
|
retry_init:
|
||||||
|
|
||||||
retcode = NSAPI_ERROR_OK;
|
retcode = NSAPI_ERROR_OK;
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,14 @@ class NetworkStack;
|
||||||
* UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5)
|
* UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5)
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GSM=0,
|
GSM = 0,
|
||||||
COMPACT_GSM=1,
|
COMPACT_GSM = 1,
|
||||||
UTRAN=2,
|
UTRAN = 2,
|
||||||
EDGE=3,
|
EDGE = 3,
|
||||||
HSDPA=4,
|
HSDPA = 4,
|
||||||
HSUPA=5,
|
HSUPA = 5,
|
||||||
HSDPA_HSUPA=6,
|
HSDPA_HSUPA = 6,
|
||||||
LTE=7
|
LTE = 7
|
||||||
} radio_access_nwk_type;
|
} radio_access_nwk_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,7 @@ typedef enum {
|
||||||
* to connect.
|
* to connect.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CIRCUIT_SWITCHED=0,
|
CIRCUIT_SWITCHED = 0,
|
||||||
PACKET_SWITCHED
|
PACKET_SWITCHED
|
||||||
} nwk_type;
|
} nwk_type;
|
||||||
|
|
||||||
|
@ -54,15 +54,15 @@ typedef enum {
|
||||||
* UBX-13001820 - AT Commands Example Application Note (Section 7.10.3)
|
* UBX-13001820 - AT Commands Example Application Note (Section 7.10.3)
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CSD_NOT_REGISTERED_NOT_SEARCHING=0,
|
CSD_NOT_REGISTERED_NOT_SEARCHING = 0,
|
||||||
CSD_REGISTERED=1,
|
CSD_REGISTERED = 1,
|
||||||
CSD_NOT_REGISTERED_SEARCHING=2,
|
CSD_NOT_REGISTERED_SEARCHING = 2,
|
||||||
CSD_REGISTRATION_DENIED=3,
|
CSD_REGISTRATION_DENIED = 3,
|
||||||
CSD_UNKNOWN_COVERAGE=4,
|
CSD_UNKNOWN_COVERAGE = 4,
|
||||||
CSD_REGISTERED_ROAMING=5,
|
CSD_REGISTERED_ROAMING = 5,
|
||||||
CSD_SMS_ONLY=6,
|
CSD_SMS_ONLY = 6,
|
||||||
CSD_SMS_ONLY_ROAMING=7,
|
CSD_SMS_ONLY_ROAMING = 7,
|
||||||
CSD_CSFB_NOT_PREFERRED=9
|
CSD_CSFB_NOT_PREFERRED = 9
|
||||||
} nwk_registration_status_csd;
|
} nwk_registration_status_csd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,20 +70,20 @@ typedef enum {
|
||||||
* UBX-13001820 - AT Commands Example Application Note (Section 18.27.3)
|
* UBX-13001820 - AT Commands Example Application Note (Section 18.27.3)
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PSD_NOT_REGISTERED_NOT_SEARCHING=0,
|
PSD_NOT_REGISTERED_NOT_SEARCHING = 0,
|
||||||
PSD_REGISTERED=1,
|
PSD_REGISTERED = 1,
|
||||||
PSD_NOT_REGISTERED_SEARCHING=2,
|
PSD_NOT_REGISTERED_SEARCHING = 2,
|
||||||
PSD_REGISTRATION_DENIED=3,
|
PSD_REGISTRATION_DENIED = 3,
|
||||||
PSD_UNKNOWN_COVERAGE=4,
|
PSD_UNKNOWN_COVERAGE = 4,
|
||||||
PSD_REGISTERED_ROAMING=5,
|
PSD_REGISTERED_ROAMING = 5,
|
||||||
PSD_EMERGENCY_SERVICES_ONLY=8
|
PSD_EMERGENCY_SERVICES_ONLY = 8
|
||||||
} nwk_registration_status_psd;
|
} nwk_registration_status_psd;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char ccid[20+1]; //!< Integrated Circuit Card ID
|
char ccid[20 + 1]; //!< Integrated Circuit Card ID
|
||||||
char imsi[15+1]; //!< International Mobile Station Identity
|
char imsi[15 + 1]; //!< International Mobile Station Identity
|
||||||
char imei[15+1]; //!< International Mobile Equipment Identity
|
char imei[15 + 1]; //!< International Mobile Equipment Identity
|
||||||
char meid[18+1]; //!< Mobile Equipment IDentifier
|
char meid[18 + 1]; //!< Mobile Equipment IDentifier
|
||||||
int flags;
|
int flags;
|
||||||
radio_access_nwk_type rat;
|
radio_access_nwk_type rat;
|
||||||
nwk_registration_status_csd reg_status_csd;
|
nwk_registration_status_csd reg_status_csd;
|
||||||
|
@ -403,7 +403,7 @@ protected:
|
||||||
*
|
*
|
||||||
* @return true if registration is successful
|
* @return true if registration is successful
|
||||||
*/
|
*/
|
||||||
bool nwk_registration(uint8_t nwk_type=PACKET_SWITCHED);
|
bool nwk_registration(uint8_t nwk_type = PACKET_SWITCHED);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,8 @@ Case cases[] = { Case("UDP echo test", test_udp_echo),
|
||||||
Case("TCP async echo test", test_tcp_echo_async),
|
Case("TCP async echo test", test_tcp_echo_async),
|
||||||
#endif
|
#endif
|
||||||
Case("Connect with credentials", test_connect_credentials),
|
Case("Connect with credentials", test_connect_credentials),
|
||||||
Case("Connect with preset credentials", test_connect_preset_credentials) };
|
Case("Connect with preset credentials", test_connect_preset_credentials)
|
||||||
|
};
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
||||||
|
@ -284,13 +285,13 @@ static int fix(int size, int limit)
|
||||||
static void do_udp_echo(UDPSocket *sock, SocketAddress *host_address, int size)
|
static void do_udp_echo(UDPSocket *sock, SocketAddress *host_address, int size)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
void * recv_data = malloc(size);
|
void *recv_data = malloc(size);
|
||||||
TEST_ASSERT(recv_data != NULL);
|
TEST_ASSERT(recv_data != NULL);
|
||||||
|
|
||||||
// Retry this a few times, don't want to fail due to a flaky link
|
// 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++) {
|
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);
|
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)
|
if ((sock->sendto(*host_address, (void *) test_data, size) == size)
|
||||||
&& (sock->recvfrom(host_address, recv_data, size) == size)) {
|
&& (sock->recvfrom(host_address, recv_data, size) == size)) {
|
||||||
TEST_ASSERT(memcmp(test_data, recv_data, size) == 0);
|
TEST_ASSERT(memcmp(test_data, recv_data, size) == 0);
|
||||||
success = true;
|
success = true;
|
||||||
|
@ -340,7 +341,7 @@ static void async_cb(bool *callback_triggered)
|
||||||
static void do_tcp_echo_async(TCPSocket *sock, int size,
|
static void do_tcp_echo_async(TCPSocket *sock, int size,
|
||||||
bool *callback_triggered)
|
bool *callback_triggered)
|
||||||
{
|
{
|
||||||
void * recv_data = malloc(size);
|
void *recv_data = malloc(size);
|
||||||
int recv_size = 0;
|
int recv_size = 0;
|
||||||
int remaining_size;
|
int remaining_size;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -370,7 +371,7 @@ static void do_tcp_echo_async(TCPSocket *sock, int size,
|
||||||
y = memcmp(test_data, recv_data, size);
|
y = memcmp(test_data, recv_data, size);
|
||||||
if (y != 0) {
|
if (y != 0) {
|
||||||
tr_debug("Sent %d, |%*.*s|", size, size, size, test_data);
|
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
|
// 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
|
// 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.
|
// 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)
|
static void use_connection(OnboardCellularInterface *driver)
|
||||||
{
|
{
|
||||||
const char * ip_address = driver->get_ip_address();
|
const char *ip_address = driver->get_ip_address();
|
||||||
const char * net_mask = driver->get_netmask();
|
const char *net_mask = driver->get_netmask();
|
||||||
const char * gateway = driver->get_gateway();
|
const char *gateway = driver->get_gateway();
|
||||||
|
|
||||||
TEST_ASSERT(driver->is_connected());
|
TEST_ASSERT(driver->is_connected());
|
||||||
|
|
||||||
|
|
|
@ -82,11 +82,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
|
||||||
int val_rand;
|
int val_rand;
|
||||||
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
|
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
|
||||||
val_rand = rand();
|
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 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],
|
read_block[i_ind],
|
||||||
write_block[i_ind] );
|
write_block[i_ind]);
|
||||||
}
|
}
|
||||||
TEST_ASSERT_EQUAL(0xff & val_rand, read_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 *write_block = new (std::nothrow) uint8_t[block_size];
|
||||||
uint8_t *read_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");
|
utest_printf("\n Not enough memory for test");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ using namespace utest::v1;
|
||||||
|
|
||||||
// TODO HACK, replace with available ram/heap property
|
// TODO HACK, replace with available ram/heap property
|
||||||
#if defined(TARGET_MTB_MTS_XDOT)
|
#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
|
#endif
|
||||||
|
|
||||||
#define TEST_BLOCK_SIZE 128
|
#define TEST_BLOCK_SIZE 128
|
||||||
|
@ -45,7 +45,8 @@ const struct {
|
||||||
|
|
||||||
|
|
||||||
// Simple test that read/writes random set of blocks
|
// 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];
|
uint8_t *dummy = new (std::nothrow) uint8_t[TEST_BLOCK_DEVICE_SIZE];
|
||||||
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
||||||
delete[] dummy;
|
delete[] dummy;
|
||||||
|
@ -55,19 +56,19 @@ void test_read_write() {
|
||||||
int err = bd.init();
|
int err = bd.init();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
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"};
|
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||||
for (int i = 3; i >= 0; i--) {
|
for (int i = 3; i >= 0; i--) {
|
||||||
bd_size_t size = (bd.*ATTRS[a].method)();
|
bd_size_t size = (bd.*ATTRS[a].method)();
|
||||||
if (size >= (1ULL << 10*i)) {
|
if (size >= (1ULL << 10 * i)) {
|
||||||
printf("%s: %llu%sbytes (%llubytes)\n",
|
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;
|
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();
|
bd_size_t block_size = bd.get_erase_size();
|
||||||
uint8_t *write_block = new (std::nothrow) uint8_t[block_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++) {
|
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
||||||
// Find a random block
|
// 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
|
// Use next random number as temporary seed to keep
|
||||||
// the address progressing in the pseudorandom sequence
|
// the address progressing in the pseudorandom sequence
|
||||||
|
@ -119,13 +120,13 @@ void test_read_write() {
|
||||||
|
|
||||||
// Find error mask for debugging
|
// Find error mask for debugging
|
||||||
memset(error_mask, 0, TEST_ERROR_MASK);
|
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);
|
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++) {
|
for (bd_size_t j = 0; j < error_scale; j++) {
|
||||||
if ((0xff & rand()) != read_block[i*error_scale + j]) {
|
if ((0xff & rand()) != read_block[i * error_scale + j]) {
|
||||||
error_mask[i/8] |= 1 << (i%8);
|
error_mask[i / 8] |= 1 << (i % 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +156,8 @@ end:
|
||||||
|
|
||||||
|
|
||||||
// Test setup
|
// 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");
|
GREENTEA_SETUP(30, "default_auto");
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
}
|
}
|
||||||
|
@ -166,6 +168,7 @@ Case cases[] = {
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return !Harness::run(specification);
|
return !Harness::run(specification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ using namespace utest::v1;
|
||||||
|
|
||||||
// TODO HACK, replace with available ram/heap property
|
// TODO HACK, replace with available ram/heap property
|
||||||
#if defined(TARGET_MTB_MTS_XDOT)
|
#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
|
#endif
|
||||||
|
|
||||||
#define BLOCK_COUNT 16
|
#define BLOCK_COUNT 16
|
||||||
#define BLOCK_SIZE 512
|
#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
|
// Testing formatting of master boot record
|
||||||
void test_mbr_format()
|
void test_mbr_format()
|
||||||
|
@ -42,10 +42,10 @@ void test_mbr_format()
|
||||||
delete[] dummy;
|
delete[] dummy;
|
||||||
|
|
||||||
// Create two partitions splitting device in ~half
|
// 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);
|
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);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Load both partitions, as well as a third to check for invalid partitions
|
// 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 erase size: %llu bytes\n", part1.get_erase_size());
|
||||||
printf("partition 1 size: %llu bytes\n", part1.size());
|
printf("partition 1 size: %llu bytes\n", part1.size());
|
||||||
TEST_ASSERT_EQUAL(1, part1.get_partition_number());
|
TEST_ASSERT_EQUAL(1, part1.get_partition_number());
|
||||||
TEST_ASSERT_EQUAL(1*BLOCK_SIZE, part1.get_partition_start());
|
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((BLOCK_COUNT / 2)*BLOCK_SIZE, part1.get_partition_stop());
|
||||||
TEST_ASSERT_EQUAL(0x83, part1.get_partition_type());
|
TEST_ASSERT_EQUAL(0x83, part1.get_partition_type());
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_read_size());
|
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_program_size());
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, part1.get_erase_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 number: %d\n", part2.get_partition_number());
|
||||||
printf("partition 2 partition start: 0x%llx\n", part2.get_partition_start());
|
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 erase size: %llu bytes\n", part2.get_erase_size());
|
||||||
printf("partition 2 size: %llu bytes\n", part2.size());
|
printf("partition 2 size: %llu bytes\n", part2.size());
|
||||||
TEST_ASSERT_EQUAL(2, part2.get_partition_number());
|
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 / 2)*BLOCK_SIZE, part2.get_partition_start());
|
||||||
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, part2.get_partition_stop());
|
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, part2.get_partition_stop());
|
||||||
TEST_ASSERT_EQUAL(0x83, part2.get_partition_type());
|
TEST_ASSERT_EQUAL(0x83, part2.get_partition_type());
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_read_size());
|
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_program_size());
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, part2.get_erase_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
|
// Deinit partitions
|
||||||
err = part1.deinit();
|
err = part1.deinit();
|
||||||
|
@ -177,7 +177,7 @@ void test_mbr_read_write()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check with original block device
|
// 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);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Check that the data was unmodified
|
// Check that the data was unmodified
|
||||||
|
@ -209,7 +209,7 @@ void test_mbr_read_write()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check with original block device
|
// 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);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Check that the data was unmodified
|
// Check that the data was unmodified
|
||||||
|
@ -232,7 +232,8 @@ end:
|
||||||
|
|
||||||
|
|
||||||
// Test setup
|
// 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");
|
GREENTEA_SETUP(10, "default_auto");
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
}
|
}
|
||||||
|
@ -245,6 +246,7 @@ Case cases[] = {
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return !Harness::run(specification);
|
return !Harness::run(specification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ using namespace utest::v1;
|
||||||
|
|
||||||
// TODO HACK, replace with available ram/heap property
|
// TODO HACK, replace with available ram/heap property
|
||||||
#if defined(TARGET_MTB_MTS_XDOT)
|
#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
|
#endif
|
||||||
|
|
||||||
#define BLOCK_COUNT 16
|
#define BLOCK_COUNT 16
|
||||||
|
@ -36,17 +36,18 @@ using namespace utest::v1;
|
||||||
|
|
||||||
|
|
||||||
// Simple test which read/writes blocks on a sliced block device
|
// 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];
|
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
|
||||||
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
||||||
delete[] dummy;
|
delete[] dummy;
|
||||||
|
|
||||||
int err;
|
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 slice1(&bd, 0, (BLOCK_COUNT / 2)*BLOCK_SIZE);
|
||||||
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);
|
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT / 2)*BLOCK_SIZE);
|
||||||
|
|
||||||
// Test with first slice of block device
|
// Test with first slice of block device
|
||||||
err = slice1.init();
|
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_program_size());
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_erase_size(BLOCK_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 *write_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
|
||||||
uint8_t *read_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(0, err);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice2.get_program_size());
|
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
|
// Fill with random sequence
|
||||||
srand(1);
|
srand(1);
|
||||||
|
@ -123,7 +124,7 @@ void test_slicing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check with original block device
|
// 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);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Check that the data was unmodified
|
// Check that the data was unmodified
|
||||||
|
@ -141,15 +142,16 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple test which read/writes blocks on a chain of block devices
|
// 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];
|
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
|
||||||
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
||||||
delete[] dummy;
|
delete[] dummy;
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
HeapBlockDevice bd1((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);
|
HeapBlockDevice bd2((BLOCK_COUNT / 2)*BLOCK_SIZE, BLOCK_SIZE);
|
||||||
|
|
||||||
// Test with chain of block device
|
// Test with chain of block device
|
||||||
BlockDevice *bds[] = {&bd1, &bd2};
|
BlockDevice *bds[] = {&bd1, &bd2};
|
||||||
|
@ -167,8 +169,8 @@ void test_chaining() {
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
|
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_SIZE, chain.get_erase_size((BLOCK_COUNT / 2)*BLOCK_SIZE + 1));
|
||||||
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());
|
TEST_ASSERT_EQUAL(BLOCK_COUNT * BLOCK_SIZE, chain.size());
|
||||||
|
|
||||||
// Fill with random sequence
|
// Fill with random sequence
|
||||||
srand(1);
|
srand(1);
|
||||||
|
@ -190,10 +192,10 @@ void test_chaining() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write, sync, and read the block
|
// 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);
|
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);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Check that the data was unmodified
|
// Check that the data was unmodified
|
||||||
|
@ -211,7 +213,8 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple test which read/writes blocks on a chain of block devices
|
// 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];
|
uint8_t *dummy = new (std::nothrow) uint8_t[BLOCK_COUNT * BLOCK_SIZE];
|
||||||
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory for test");
|
||||||
delete[] dummy;
|
delete[] dummy;
|
||||||
|
@ -219,7 +222,7 @@ void test_profiling() {
|
||||||
int err;
|
int err;
|
||||||
bd_size_t read_count, program_count, erase_count;
|
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
|
// Test under profiling
|
||||||
ProfilingBlockDevice profiler(&bd);
|
ProfilingBlockDevice profiler(&bd);
|
||||||
|
|
||||||
|
@ -227,7 +230,7 @@ void test_profiling() {
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(BLOCK_SIZE, profiler.get_erase_size());
|
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 *write_block = new (std::nothrow) uint8_t[BLOCK_SIZE];
|
||||||
uint8_t *read_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
|
// 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");
|
GREENTEA_SETUP(10, "default_auto");
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
}
|
}
|
||||||
|
@ -300,6 +304,7 @@ Case cases[] = {
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return !Harness::run(specification);
|
return !Harness::run(specification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,17 @@
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
#ifndef MBED_EXTENDED_TESTS
|
#ifndef MBED_EXTENDED_TESTS
|
||||||
#error [NOT_SUPPORTED] Filesystem tests not supported by default
|
#error [NOT_SUPPORTED] Filesystem tests not supported by default
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Test block device
|
// Test block device
|
||||||
#define BLOCK_SIZE 512
|
#define BLOCK_SIZE 512
|
||||||
HeapBlockDevice bd(128*BLOCK_SIZE, BLOCK_SIZE);
|
HeapBlockDevice bd(128 * BLOCK_SIZE, BLOCK_SIZE);
|
||||||
|
|
||||||
|
|
||||||
// Test formatting
|
// Test formatting
|
||||||
void test_format() {
|
void test_format()
|
||||||
|
{
|
||||||
int err = FATFileSystem::format(&bd);
|
int err = FATFileSystem::format(&bd);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +44,8 @@ void test_format() {
|
||||||
|
|
||||||
// Simple test for reading/writing files
|
// Simple test for reading/writing files
|
||||||
template <ssize_t TEST_SIZE>
|
template <ssize_t TEST_SIZE>
|
||||||
void test_read_write() {
|
void test_read_write()
|
||||||
|
{
|
||||||
FATFileSystem fs("fat");
|
FATFileSystem fs("fat");
|
||||||
|
|
||||||
int err = fs.mount(&bd);
|
int err = fs.mount(&bd);
|
||||||
|
@ -86,7 +88,8 @@ void test_read_write() {
|
||||||
|
|
||||||
|
|
||||||
// Simple test for iterating dir entries
|
// Simple test for iterating dir entries
|
||||||
void test_read_dir() {
|
void test_read_dir()
|
||||||
|
{
|
||||||
FATFileSystem fs("fat");
|
FATFileSystem fs("fat");
|
||||||
|
|
||||||
int err = fs.mount(&bd);
|
int err = fs.mount(&bd);
|
||||||
|
@ -147,20 +150,22 @@ void test_read_dir() {
|
||||||
|
|
||||||
|
|
||||||
// Test setup
|
// 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");
|
GREENTEA_SETUP(10, "default_auto");
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
}
|
}
|
||||||
|
|
||||||
Case cases[] = {
|
Case cases[] = {
|
||||||
Case("Testing formating", test_format),
|
Case("Testing formating", test_format),
|
||||||
Case("Testing read write < block", test_read_write<BLOCK_SIZE/2>),
|
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<2 * BLOCK_SIZE>),
|
||||||
Case("Testing dir iteration", test_read_dir),
|
Case("Testing dir iteration", test_read_dir),
|
||||||
};
|
};
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return !Harness::run(specification);
|
return !Harness::run(specification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1959,7 +1959,7 @@ static void FS_fill_data_and_seek()
|
||||||
|
|
||||||
for (i = 1; i <= 255; i++) {
|
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);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
j = getc(fd[0]);
|
j = getc(fd[0]);
|
||||||
|
|
|
@ -27,22 +27,23 @@
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
#ifndef MBED_EXTENDED_TESTS
|
#ifndef MBED_EXTENDED_TESTS
|
||||||
#error [NOT_SUPPORTED] Filesystem tests not supported by default
|
#error [NOT_SUPPORTED] Filesystem tests not supported by default
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Test block device
|
// Test block device
|
||||||
#define BLOCK_SIZE 512
|
#define BLOCK_SIZE 512
|
||||||
#define BLOCK_COUNT 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
|
// Test formatting and partitioning
|
||||||
void test_format() {
|
void test_format()
|
||||||
|
{
|
||||||
// Create two partitions splitting device in ~half
|
// 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);
|
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);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
// Load both partitions
|
// Load both partitions
|
||||||
|
@ -72,7 +73,8 @@ void test_format() {
|
||||||
|
|
||||||
// Simple multipartition test for reading/writing files
|
// Simple multipartition test for reading/writing files
|
||||||
template <ssize_t TEST_SIZE>
|
template <ssize_t TEST_SIZE>
|
||||||
void test_read_write() {
|
void test_read_write()
|
||||||
|
{
|
||||||
// Load both partitions
|
// Load both partitions
|
||||||
MBRBlockDevice part1(&bd, 1);
|
MBRBlockDevice part1(&bd, 1);
|
||||||
int err = part1.init();
|
int err = part1.init();
|
||||||
|
@ -163,37 +165,38 @@ void test_read_write() {
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_single_mbr() {
|
void test_single_mbr()
|
||||||
|
{
|
||||||
int err = bd.init();
|
int err = bd.init();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
const bd_addr_t MBR_OFFSET = 0;
|
const bd_addr_t MBR_OFFSET = 0;
|
||||||
const bd_addr_t FAT1_OFFSET = 1;
|
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);
|
uint8_t *buffer = (uint8_t *)malloc(BLOCK_SIZE);
|
||||||
TEST_ASSERT(buffer);
|
TEST_ASSERT(buffer);
|
||||||
|
|
||||||
// Check that all three header blocks have the 0x55aa signature
|
// 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_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_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_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
|
// Check that the headers for both filesystems contain a jump code
|
||||||
// indicating they are actual FAT superblocks and not an extra MBR
|
// 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_EQUAL(0, err);
|
||||||
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
|
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_EQUAL(0, err);
|
||||||
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
|
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
|
||||||
|
|
||||||
|
@ -205,20 +208,22 @@ void test_single_mbr() {
|
||||||
|
|
||||||
|
|
||||||
// Test setup
|
// 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");
|
GREENTEA_SETUP(10, "default_auto");
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
}
|
}
|
||||||
|
|
||||||
Case cases[] = {
|
Case cases[] = {
|
||||||
Case("Testing formating", test_format),
|
Case("Testing formating", test_format),
|
||||||
Case("Testing read write < block", test_read_write<BLOCK_SIZE/2>),
|
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<2 * BLOCK_SIZE>),
|
||||||
Case("Testing for no extra MBRs", test_single_mbr),
|
Case("Testing for no extra MBRs", test_single_mbr),
|
||||||
};
|
};
|
||||||
|
|
||||||
Specification specification(test_setup, cases);
|
Specification specification(test_setup, cases);
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
return !Harness::run(specification);
|
return !Harness::run(specification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,7 @@ typedef uint64_t bd_size_t;
|
||||||
|
|
||||||
/** A hardware device capable of writing and reading blocks
|
/** A hardware device capable of writing and reading blocks
|
||||||
*/
|
*/
|
||||||
class BlockDevice
|
class BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Return the default block device
|
/** Return the default block device
|
||||||
|
|
|
@ -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);
|
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) {
|
if (aligned_addr != _curr_aligned_addr) {
|
||||||
// Need to flush if moved to another program unit
|
// 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);
|
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
|
// Need to flush if moved to another program unit
|
||||||
if (aligned_addr != _curr_aligned_addr) {
|
if (aligned_addr != _curr_aligned_addr) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
|
||||||
return BD_ERROR_DEVICE_ERROR;
|
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
|
// Find block devices containing blocks, may span multiple block devices
|
||||||
for (size_t i = 0; i < _bd_count && size > 0; i++) {
|
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;
|
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
|
// Find block devices containing blocks, may span multiple block devices
|
||||||
for (size_t i = 0; i < _bd_count && size > 0; i++) {
|
for (size_t i = 0; i < _bd_count && size > 0; i++) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
* @note All block devices must have the same block size
|
* @note All block devices must have the same block size
|
||||||
*/
|
*/
|
||||||
template <size_t Size>
|
template <size_t Size>
|
||||||
ChainingBlockDevice(BlockDevice *(&bds)[Size])
|
ChainingBlockDevice(BlockDevice * (&bds)[Size])
|
||||||
: _bds(bds), _bd_count(sizeof(bds) / sizeof(bds[0]))
|
: _bds(bds), _bd_count(sizeof(bds) / sizeof(bds[0]))
|
||||||
, _read_size(0), _program_size(0), _erase_size(0), _size(0), _init_ref_count(0)
|
, _read_size(0), _program_size(0), _erase_size(0), _size(0), _init_ref_count(0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
* after a configurable number of cycles.
|
* after a configurable number of cycles.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ExhaustibleBlockDevice : public BlockDevice
|
class ExhaustibleBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/** Lifetime of the block device
|
/** Lifetime of the block device
|
||||||
*
|
*
|
||||||
|
|
|
@ -53,7 +53,7 @@ int HeapBlockDevice::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_blocks) {
|
if (!_blocks) {
|
||||||
_blocks = new uint8_t*[_count];
|
_blocks = new uint8_t *[_count];
|
||||||
for (size_t i = 0; i < _count; i++) {
|
for (size_t i = 0; i < _count; i++) {
|
||||||
_blocks[i] = 0;
|
_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;
|
return BD_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = static_cast<uint8_t*>(b);
|
uint8_t *buffer = static_cast<uint8_t *>(b);
|
||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
bd_addr_t hi = addr / _erase_size;
|
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;
|
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) {
|
while (size > 0) {
|
||||||
bd_addr_t hi = addr / _erase_size;
|
bd_addr_t hi = addr / _erase_size;
|
||||||
bd_addr_t lo = addr % _erase_size;
|
bd_addr_t lo = addr % _erase_size;
|
||||||
|
|
||||||
if (!_blocks[hi]) {
|
if (!_blocks[hi]) {
|
||||||
_blocks[hi] = (uint8_t*)malloc(_erase_size);
|
_blocks[hi] = (uint8_t *)malloc(_erase_size);
|
||||||
if (!_blocks[hi]) {
|
if (!_blocks[hi]) {
|
||||||
return BD_ERROR_DEVICE_ERROR;
|
return BD_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,7 @@
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
class HeapBlockDevice : public BlockDevice
|
class HeapBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Lifetime of the memory block device
|
/** Lifetime of the memory block device
|
||||||
|
@ -60,7 +59,7 @@ public:
|
||||||
* @param block Block size in bytes. Minimum read, program, and erase sizes are
|
* @param block Block size in bytes. Minimum read, program, and erase sizes are
|
||||||
* configured to this value
|
* 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
|
/** Lifetime of the memory block device
|
||||||
*
|
*
|
||||||
* @param size Size of the Block Device in bytes
|
* @param size Size of the Block Device in bytes
|
||||||
|
|
|
@ -60,7 +60,7 @@ static inline uint32_t fromle32(uint32_t a)
|
||||||
|
|
||||||
static void tochs(uint32_t lba, uint8_t chs[3])
|
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[0] = (sector >> 6) & 0xff;
|
||||||
chs[1] = ((sector >> 0) & 0x3f) | ((sector >> 16) & 0xc0);
|
chs[1] = ((sector >> 0) & 0x3f) | ((sector >> 16) & 0xc0);
|
||||||
chs[2] = (sector >> 14) & 0xff;
|
chs[2] = (sector >> 14) & 0xff;
|
||||||
|
@ -77,20 +77,20 @@ static int partition_absolute(
|
||||||
uint32_t buffer_size = std::max<uint32_t>(bd->get_program_size(), sizeof(struct mbr_table));
|
uint32_t buffer_size = std::max<uint32_t>(bd->get_program_size(), sizeof(struct mbr_table));
|
||||||
|
|
||||||
// Prevent alignment issues
|
// 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());
|
buffer_size += bd->get_program_size() - (buffer_size % bd->get_program_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = new uint8_t[buffer_size];
|
uint8_t *buffer = new uint8_t[buffer_size];
|
||||||
|
|
||||||
// Check for existing MBR
|
// 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) {
|
if (err) {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mbr_table *table = reinterpret_cast<struct mbr_table*>(
|
struct mbr_table *table = reinterpret_cast<struct mbr_table *>(
|
||||||
&buffer[buffer_size - sizeof(struct mbr_table)]);
|
&buffer[buffer_size - sizeof(struct mbr_table)]);
|
||||||
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
|
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
|
||||||
// Setup default values for MBR
|
// Setup default values for MBR
|
||||||
|
@ -104,8 +104,8 @@ static int partition_absolute(
|
||||||
// partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
|
// partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
|
||||||
// /0x80 (active) for valid partition status.
|
// /0x80 (active) for valid partition status.
|
||||||
for (int i = 1; i <= 4; i++) {
|
for (int i = 1; i <= 4; i++) {
|
||||||
if (table->entries[i-1].status != 0x00 &&
|
if (table->entries[i - 1].status != 0x00 &&
|
||||||
table->entries[i-1].status != 0x80) {
|
table->entries[i - 1].status != 0x80) {
|
||||||
memset(table->entries, 0, sizeof(table->entries));
|
memset(table->entries, 0, sizeof(table->entries));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -113,26 +113,26 @@ static int partition_absolute(
|
||||||
|
|
||||||
// Setup new partition
|
// Setup new partition
|
||||||
MBED_ASSERT(part >= 1 && part <= 4);
|
MBED_ASSERT(part >= 1 && part <= 4);
|
||||||
table->entries[part-1].status = 0x00; // inactive (not bootable)
|
table->entries[part - 1].status = 0x00; // inactive (not bootable)
|
||||||
table->entries[part-1].type = type;
|
table->entries[part - 1].type = type;
|
||||||
|
|
||||||
// lba dimensions
|
// lba dimensions
|
||||||
MBED_ASSERT(bd->is_valid_erase(offset, size));
|
MBED_ASSERT(bd->is_valid_erase(offset, size));
|
||||||
uint32_t sector = std::max<uint32_t>(bd->get_erase_size(), 512);
|
uint32_t sector = std::max<uint32_t>(bd->get_erase_size(), 512);
|
||||||
uint32_t lba_offset = offset / sector;
|
uint32_t lba_offset = offset / sector;
|
||||||
uint32_t lba_size = size / sector;
|
uint32_t lba_size = size / sector;
|
||||||
table->entries[part-1].lba_offset = tole32(lba_offset);
|
table->entries[part - 1].lba_offset = tole32(lba_offset);
|
||||||
table->entries[part-1].lba_size = tole32(lba_size);
|
table->entries[part - 1].lba_size = tole32(lba_size);
|
||||||
|
|
||||||
// chs dimensions
|
// chs dimensions
|
||||||
tochs(lba_offset, table->entries[part-1].chs_start);
|
tochs(lba_offset, table->entries[part - 1].chs_start);
|
||||||
tochs(lba_offset+lba_size-1, table->entries[part-1].chs_stop);
|
tochs(lba_offset + lba_size - 1, table->entries[part - 1].chs_stop);
|
||||||
|
|
||||||
// Check that we don't overlap other entries
|
// Check that we don't overlap other entries
|
||||||
for (int i = 1; i <= 4; i++) {
|
for (int i = 1; i <= 4; i++) {
|
||||||
if (i != part && table->entries[i-1].type != 0x00) {
|
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_offset = fromle32(table->entries[i - 1].lba_offset);
|
||||||
uint32_t neighbor_lba_size = fromle32(table->entries[i-1].lba_size);
|
uint32_t neighbor_lba_size = fromle32(table->entries[i - 1].lba_size);
|
||||||
MBED_ASSERT(
|
MBED_ASSERT(
|
||||||
(lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
|
(lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
|
||||||
(lba_offset + lba_size <= neighbor_lba_offset));
|
(lba_offset + lba_size <= neighbor_lba_offset));
|
||||||
|
@ -148,7 +148,7 @@ static int partition_absolute(
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bd->program(buffer, 512-buffer_size, buffer_size);
|
err = bd->program(buffer, 512 - buffer_size, buffer_size);
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -243,13 +243,13 @@ int MBRBlockDevice::init()
|
||||||
buffer_size = std::max<uint32_t>(_bd->get_read_size(), sizeof(struct mbr_table));
|
buffer_size = std::max<uint32_t>(_bd->get_read_size(), sizeof(struct mbr_table));
|
||||||
buffer = new uint8_t[buffer_size];
|
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) {
|
if (err) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for valid table
|
// 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) {
|
if (table->signature[0] != 0x55 || table->signature[1] != 0xaa) {
|
||||||
err = BD_ERROR_INVALID_MBR;
|
err = BD_ERROR_INVALID_MBR;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -257,8 +257,8 @@ int MBRBlockDevice::init()
|
||||||
|
|
||||||
// Check for valid partition status
|
// Check for valid partition status
|
||||||
// Same reason as in partition_absolute regarding Windows-formatted SD card
|
// Same reason as in partition_absolute regarding Windows-formatted SD card
|
||||||
if (table->entries[_part-1].status != 0x00 &&
|
if (table->entries[_part - 1].status != 0x00 &&
|
||||||
table->entries[_part-1].status != 0x80) {
|
table->entries[_part - 1].status != 0x80) {
|
||||||
err = BD_ERROR_INVALID_PARTITION;
|
err = BD_ERROR_INVALID_PARTITION;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -266,18 +266,18 @@ int MBRBlockDevice::init()
|
||||||
// Check for valid entry
|
// Check for valid entry
|
||||||
// 0x00 = no entry
|
// 0x00 = no entry
|
||||||
// 0x05, 0x0f = extended partitions, currently not supported
|
// 0x05, 0x0f = extended partitions, currently not supported
|
||||||
if ((table->entries[_part-1].type == 0x00 ||
|
if ((table->entries[_part - 1].type == 0x00 ||
|
||||||
table->entries[_part-1].type == 0x05 ||
|
table->entries[_part - 1].type == 0x05 ||
|
||||||
table->entries[_part-1].type == 0x0f)) {
|
table->entries[_part - 1].type == 0x0f)) {
|
||||||
err = BD_ERROR_INVALID_PARTITION;
|
err = BD_ERROR_INVALID_PARTITION;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get partition attributes
|
// Get partition attributes
|
||||||
sector = std::max<uint32_t>(_bd->get_erase_size(), 512);
|
sector = std::max<uint32_t>(_bd->get_erase_size(), 512);
|
||||||
_type = table->entries[_part-1].type;
|
_type = table->entries[_part - 1].type;
|
||||||
_offset = fromle32(table->entries[_part-1].lba_offset) * sector;
|
_offset = fromle32(table->entries[_part - 1].lba_offset) * sector;
|
||||||
_size = fromle32(table->entries[_part-1].lba_size) * sector;
|
_size = fromle32(table->entries[_part - 1].lba_size) * sector;
|
||||||
|
|
||||||
// Check that block addresses are valid
|
// Check that block addresses are valid
|
||||||
if (!_bd->is_valid_erase(_offset, _size)) {
|
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
|
bd_size_t MBRBlockDevice::get_partition_stop() const
|
||||||
{
|
{
|
||||||
return _offset+_size;
|
return _offset + _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MBRBlockDevice::get_partition_type() const
|
uint8_t MBRBlockDevice::get_partition_type() const
|
||||||
|
|
|
@ -87,8 +87,7 @@ enum {
|
||||||
* - At most 4 partitions are supported
|
* - At most 4 partitions are supported
|
||||||
* - Extended partitions are currently not supported and will error during init
|
* - Extended partitions are currently not supported and will error during init
|
||||||
*/
|
*/
|
||||||
class MBRBlockDevice : public BlockDevice
|
class MBRBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/** Format the MBR to contain the following partition
|
/** Format the MBR to contain the following partition
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
#include "platform/Callback.h"
|
#include "platform/Callback.h"
|
||||||
|
|
||||||
|
|
||||||
class ObservingBlockDevice : public BlockDevice
|
class ObservingBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Lifetime of the block device
|
/** Lifetime of the block device
|
||||||
|
|
|
@ -43,8 +43,7 @@
|
||||||
* printf("erase count: %lld\n", profiler.get_erase_count());
|
* printf("erase count: %lld\n", profiler.get_erase_count());
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
class ProfilingBlockDevice : public BlockDevice
|
class ProfilingBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/** Lifetime of the memory block device
|
/** Lifetime of the memory block device
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
#include "PlatformMutex.h"
|
#include "PlatformMutex.h"
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlyBlockDevice : public BlockDevice
|
class ReadOnlyBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Lifetime of the block device
|
/** Lifetime of the block device
|
||||||
|
|
|
@ -45,8 +45,7 @@
|
||||||
* SlicingBlockDevice slice3(&mem, 16*512, -16*512);
|
* SlicingBlockDevice slice3(&mem, 16*512, -16*512);
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
class SlicingBlockDevice : public BlockDevice
|
class SlicingBlockDevice : public BlockDevice {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/** Lifetime of the memory block device
|
/** Lifetime of the memory block device
|
||||||
*
|
*
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
|
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
|
||||||
* @return 0 on success, negative error code on failure
|
* @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
|
/** Close a file
|
||||||
*
|
*
|
||||||
|
|
|
@ -139,7 +139,8 @@ size_t FileSystem::dir_size(fs_dir_t dir)
|
||||||
template <typename F>
|
template <typename F>
|
||||||
class Managed : public F {
|
class Managed : public F {
|
||||||
public:
|
public:
|
||||||
virtual int close() {
|
virtual int close()
|
||||||
|
{
|
||||||
int err = F::close();
|
int err = F::close();
|
||||||
delete this;
|
delete this;
|
||||||
return err;
|
return err;
|
||||||
|
@ -159,7 +160,8 @@ int FileSystem::open(FileHandle **file, const char *path, int flags)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileSystem::open(DirHandle **dir, const char *path) {
|
int FileSystem::open(DirHandle **dir, const char *path)
|
||||||
|
{
|
||||||
Dir *d = new Managed<Dir>;
|
Dir *d = new Managed<Dir>;
|
||||||
int err = d->open(this, path);
|
int err = d->open(this, path);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ using namespace mbed;
|
||||||
|
|
||||||
static int fat_error_remap(FRESULT res)
|
static int fat_error_remap(FRESULT res)
|
||||||
{
|
{
|
||||||
switch(res) {
|
switch (res) {
|
||||||
case FR_OK: // (0) Succeeded
|
case FR_OK: // (0) Succeeded
|
||||||
return 0;
|
return 0;
|
||||||
case FR_DISK_ERR: // (1) A hard error occurred in the low level disk I/O layer
|
case FR_DISK_ERR: // (1) A hard error occurred in the low level disk I/O layer
|
||||||
|
@ -86,8 +86,8 @@ public:
|
||||||
T _t;
|
T _t;
|
||||||
Callback<void(T)> _ondefer;
|
Callback<void(T)> _ondefer;
|
||||||
|
|
||||||
Deferred(const Deferred&);
|
Deferred(const Deferred &);
|
||||||
Deferred &operator=(const Deferred&);
|
Deferred &operator=(const Deferred &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Deferred(T t, Callback<void(T)> ondefer = NULL)
|
Deferred(T t, Callback<void(T)> ondefer = NULL)
|
||||||
|
@ -115,7 +115,7 @@ static void dodelete(const char *data)
|
||||||
|
|
||||||
// Adds prefix needed internally by fatfs, this can be avoided for the first fatfs
|
// Adds prefix needed internally by fatfs, this can be avoided for the first fatfs
|
||||||
// (id 0) otherwise a prefix of "id:/" is inserted in front of the string.
|
// (id 0) otherwise a prefix of "id:/" is inserted in front of the string.
|
||||||
static Deferred<const char*> fat_path_prefix(int id, const char *path)
|
static Deferred<const char *> fat_path_prefix(int id, const char *path)
|
||||||
{
|
{
|
||||||
// We can avoid dynamic allocation when only on fatfs is in use
|
// We can avoid dynamic allocation when only on fatfs is in use
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
|
@ -132,7 +132,7 @@ static Deferred<const char*> fat_path_prefix(int id, const char *path)
|
||||||
buffer[1] = ':';
|
buffer[1] = ':';
|
||||||
buffer[2] = '/';
|
buffer[2] = '/';
|
||||||
strcpy(buffer + strlen("0:/"), path);
|
strcpy(buffer + strlen("0:/"), path);
|
||||||
return Deferred<const char*>(buffer, dodelete);
|
return Deferred<const char *>(buffer, dodelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,11 +150,11 @@ DWORD get_fattime(void)
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
struct tm *ptm = localtime(&rawtime);
|
struct tm *ptm = localtime(&rawtime);
|
||||||
return (DWORD)(ptm->tm_year - 80) << 25
|
return (DWORD)(ptm->tm_year - 80) << 25
|
||||||
| (DWORD)(ptm->tm_mon + 1 ) << 21
|
| (DWORD)(ptm->tm_mon + 1) << 21
|
||||||
| (DWORD)(ptm->tm_mday ) << 16
|
| (DWORD)(ptm->tm_mday) << 16
|
||||||
| (DWORD)(ptm->tm_hour ) << 11
|
| (DWORD)(ptm->tm_hour) << 11
|
||||||
| (DWORD)(ptm->tm_min ) << 5
|
| (DWORD)(ptm->tm_min) << 5
|
||||||
| (DWORD)(ptm->tm_sec/2 );
|
| (DWORD)(ptm->tm_sec / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ff_memalloc(UINT size)
|
void *ff_memalloc(UINT size)
|
||||||
|
@ -207,8 +207,8 @@ DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
|
||||||
{
|
{
|
||||||
debug_if(FFS_DBG, "disk_read(sector %lu, count %u) on pdrv [%d]\n", sector, count, pdrv);
|
debug_if(FFS_DBG, "disk_read(sector %lu, count %u) on pdrv [%d]\n", sector, count, pdrv);
|
||||||
DWORD ssize = disk_get_sector_size(pdrv);
|
DWORD ssize = disk_get_sector_size(pdrv);
|
||||||
bd_addr_t addr = (bd_addr_t)sector*ssize;
|
bd_addr_t addr = (bd_addr_t)sector * ssize;
|
||||||
bd_size_t size = (bd_size_t)count*ssize;
|
bd_size_t size = (bd_size_t)count * ssize;
|
||||||
int err = _ffs[pdrv]->read(buff, addr, size);
|
int err = _ffs[pdrv]->read(buff, addr, size);
|
||||||
return err ? RES_PARERR : RES_OK;
|
return err ? RES_PARERR : RES_OK;
|
||||||
}
|
}
|
||||||
|
@ -217,8 +217,8 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
|
||||||
{
|
{
|
||||||
debug_if(FFS_DBG, "disk_write(sector %lu, count %u) on pdrv [%d]\n", sector, count, pdrv);
|
debug_if(FFS_DBG, "disk_write(sector %lu, count %u) on pdrv [%d]\n", sector, count, pdrv);
|
||||||
DWORD ssize = disk_get_sector_size(pdrv);
|
DWORD ssize = disk_get_sector_size(pdrv);
|
||||||
bd_addr_t addr = (bd_addr_t)sector*ssize;
|
bd_addr_t addr = (bd_addr_t)sector * ssize;
|
||||||
bd_size_t size = (bd_size_t)count*ssize;
|
bd_size_t size = (bd_size_t)count * ssize;
|
||||||
int err = _ffs[pdrv]->erase(addr, size);
|
int err = _ffs[pdrv]->erase(addr, size);
|
||||||
if (err) {
|
if (err) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
|
@ -246,27 +246,27 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
|
||||||
if (_ffs[pdrv] == NULL) {
|
if (_ffs[pdrv] == NULL) {
|
||||||
return RES_NOTRDY;
|
return RES_NOTRDY;
|
||||||
} else {
|
} else {
|
||||||
*((DWORD*)buff) = disk_get_sector_count(pdrv);
|
*((DWORD *)buff) = disk_get_sector_count(pdrv);
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
case GET_SECTOR_SIZE:
|
case GET_SECTOR_SIZE:
|
||||||
if (_ffs[pdrv] == NULL) {
|
if (_ffs[pdrv] == NULL) {
|
||||||
return RES_NOTRDY;
|
return RES_NOTRDY;
|
||||||
} else {
|
} else {
|
||||||
*((WORD*)buff) = disk_get_sector_size(pdrv);
|
*((WORD *)buff) = disk_get_sector_size(pdrv);
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
case GET_BLOCK_SIZE:
|
case GET_BLOCK_SIZE:
|
||||||
*((DWORD*)buff) = 1; // default when not known
|
*((DWORD *)buff) = 1; // default when not known
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
case CTRL_TRIM:
|
case CTRL_TRIM:
|
||||||
if (_ffs[pdrv] == NULL) {
|
if (_ffs[pdrv] == NULL) {
|
||||||
return RES_NOTRDY;
|
return RES_NOTRDY;
|
||||||
} else {
|
} else {
|
||||||
DWORD *sectors = (DWORD*)buff;
|
DWORD *sectors = (DWORD *)buff;
|
||||||
DWORD ssize = disk_get_sector_size(pdrv);
|
DWORD ssize = disk_get_sector_size(pdrv);
|
||||||
bd_addr_t addr = (bd_addr_t)sectors[0]*ssize;
|
bd_addr_t addr = (bd_addr_t)sectors[0] * ssize;
|
||||||
bd_size_t size = (bd_size_t)(sectors[1]-sectors[0]+1)*ssize;
|
bd_size_t size = (bd_size_t)(sectors[1] - sectors[0] + 1) * ssize;
|
||||||
int err = _ffs[pdrv]->trim(addr, size);
|
int err = _ffs[pdrv]->trim(addr, size);
|
||||||
return err ? RES_PARERR : RES_OK;
|
return err ? RES_PARERR : RES_OK;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,8 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
|
||||||
|
|
||||||
// Filesystem implementation (See FATFilySystem.h)
|
// Filesystem implementation (See FATFilySystem.h)
|
||||||
FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd)
|
FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd)
|
||||||
: FileSystem(name), _id(-1) {
|
: FileSystem(name), _id(-1)
|
||||||
|
{
|
||||||
if (bd) {
|
if (bd) {
|
||||||
mount(bd);
|
mount(bd);
|
||||||
}
|
}
|
||||||
|
@ -353,7 +354,7 @@ int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
// erase first handful of blocks
|
// erase first handful of blocks
|
||||||
bd_size_t header = 2*bd->get_erase_size();
|
bd_size_t header = 2 * bd->get_erase_size();
|
||||||
err = bd->erase(0, header);
|
err = bd->erase(0, header);
|
||||||
if (err) {
|
if (err) {
|
||||||
bd->deinit();
|
bd->deinit();
|
||||||
|
@ -457,7 +458,7 @@ int FATFileSystem::reformat(BlockDevice *bd, int allocation_unit)
|
||||||
|
|
||||||
int FATFileSystem::remove(const char *path)
|
int FATFileSystem::remove(const char *path)
|
||||||
{
|
{
|
||||||
Deferred<const char*> fpath = fat_path_prefix(_id, path);
|
Deferred<const char *> fpath = fat_path_prefix(_id, path);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_unlink(fpath);
|
FRESULT res = f_unlink(fpath);
|
||||||
|
@ -474,8 +475,8 @@ int FATFileSystem::remove(const char *path)
|
||||||
|
|
||||||
int FATFileSystem::rename(const char *oldpath, const char *newpath)
|
int FATFileSystem::rename(const char *oldpath, const char *newpath)
|
||||||
{
|
{
|
||||||
Deferred<const char*> oldfpath = fat_path_prefix(_id, oldpath);
|
Deferred<const char *> oldfpath = fat_path_prefix(_id, oldpath);
|
||||||
Deferred<const char*> newfpath = fat_path_prefix(_id, newpath);
|
Deferred<const char *> newfpath = fat_path_prefix(_id, newpath);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_rename(oldfpath, newfpath);
|
FRESULT res = f_rename(oldfpath, newfpath);
|
||||||
|
@ -489,7 +490,7 @@ int FATFileSystem::rename(const char *oldpath, const char *newpath)
|
||||||
|
|
||||||
int FATFileSystem::mkdir(const char *path, mode_t mode)
|
int FATFileSystem::mkdir(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
Deferred<const char*> fpath = fat_path_prefix(_id, path);
|
Deferred<const char *> fpath = fat_path_prefix(_id, path);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_mkdir(fpath);
|
FRESULT res = f_mkdir(fpath);
|
||||||
|
@ -503,7 +504,7 @@ int FATFileSystem::mkdir(const char *path, mode_t mode)
|
||||||
|
|
||||||
int FATFileSystem::stat(const char *path, struct stat *st)
|
int FATFileSystem::stat(const char *path, struct stat *st)
|
||||||
{
|
{
|
||||||
Deferred<const char*> fpath = fat_path_prefix(_id, path);
|
Deferred<const char *> fpath = fat_path_prefix(_id, path);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FILINFO f;
|
FILINFO f;
|
||||||
|
@ -575,7 +576,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags)
|
||||||
debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", path, getName(), _id);
|
debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", path, getName(), _id);
|
||||||
|
|
||||||
FIL *fh = new FIL;
|
FIL *fh = new FIL;
|
||||||
Deferred<const char*> fpath = fat_path_prefix(_id, path);
|
Deferred<const char *> fpath = fat_path_prefix(_id, path);
|
||||||
|
|
||||||
/* POSIX flags -> FatFS open mode */
|
/* POSIX flags -> FatFS open mode */
|
||||||
BYTE openmode;
|
BYTE openmode;
|
||||||
|
@ -617,7 +618,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags)
|
||||||
|
|
||||||
int FATFileSystem::file_close(fs_file_t file)
|
int FATFileSystem::file_close(fs_file_t file)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_close(fh);
|
FRESULT res = f_close(fh);
|
||||||
|
@ -629,7 +630,7 @@ int FATFileSystem::file_close(fs_file_t file)
|
||||||
|
|
||||||
ssize_t FATFileSystem::file_read(fs_file_t file, void *buffer, size_t len)
|
ssize_t FATFileSystem::file_read(fs_file_t file, void *buffer, size_t len)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
UINT n;
|
UINT n;
|
||||||
|
@ -646,7 +647,7 @@ ssize_t FATFileSystem::file_read(fs_file_t file, void *buffer, size_t len)
|
||||||
|
|
||||||
ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len)
|
ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
UINT n;
|
UINT n;
|
||||||
|
@ -663,7 +664,7 @@ ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len
|
||||||
|
|
||||||
int FATFileSystem::file_sync(fs_file_t file)
|
int FATFileSystem::file_sync(fs_file_t file)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_sync(fh);
|
FRESULT res = f_sync(fh);
|
||||||
|
@ -677,12 +678,12 @@ int FATFileSystem::file_sync(fs_file_t file)
|
||||||
|
|
||||||
off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence)
|
off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
if (whence == SEEK_END) {
|
if (whence == SEEK_END) {
|
||||||
offset += f_size(fh);
|
offset += f_size(fh);
|
||||||
} else if(whence==SEEK_CUR) {
|
} else if (whence == SEEK_CUR) {
|
||||||
offset += f_tell(fh);
|
offset += f_tell(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,7 +701,7 @@ off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence)
|
||||||
|
|
||||||
off_t FATFileSystem::file_tell(fs_file_t file)
|
off_t FATFileSystem::file_tell(fs_file_t file)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
off_t res = f_tell(fh);
|
off_t res = f_tell(fh);
|
||||||
|
@ -711,7 +712,7 @@ off_t FATFileSystem::file_tell(fs_file_t file)
|
||||||
|
|
||||||
off_t FATFileSystem::file_size(fs_file_t file)
|
off_t FATFileSystem::file_size(fs_file_t file)
|
||||||
{
|
{
|
||||||
FIL *fh = static_cast<FIL*>(file);
|
FIL *fh = static_cast<FIL *>(file);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
off_t res = f_size(fh);
|
off_t res = f_size(fh);
|
||||||
|
@ -725,7 +726,7 @@ off_t FATFileSystem::file_size(fs_file_t file)
|
||||||
int FATFileSystem::dir_open(fs_dir_t *dir, const char *path)
|
int FATFileSystem::dir_open(fs_dir_t *dir, const char *path)
|
||||||
{
|
{
|
||||||
FATFS_DIR *dh = new FATFS_DIR;
|
FATFS_DIR *dh = new FATFS_DIR;
|
||||||
Deferred<const char*> fpath = fat_path_prefix(_id, path);
|
Deferred<const char *> fpath = fat_path_prefix(_id, path);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_opendir(dh, fpath);
|
FRESULT res = f_opendir(dh, fpath);
|
||||||
|
@ -743,7 +744,7 @@ int FATFileSystem::dir_open(fs_dir_t *dir, const char *path)
|
||||||
|
|
||||||
int FATFileSystem::dir_close(fs_dir_t dir)
|
int FATFileSystem::dir_close(fs_dir_t dir)
|
||||||
{
|
{
|
||||||
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
|
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
FRESULT res = f_closedir(dh);
|
FRESULT res = f_closedir(dh);
|
||||||
|
@ -755,7 +756,7 @@ int FATFileSystem::dir_close(fs_dir_t dir)
|
||||||
|
|
||||||
ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
|
ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
|
||||||
{
|
{
|
||||||
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
|
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
|
||||||
FILINFO finfo;
|
FILINFO finfo;
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
|
@ -784,7 +785,7 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
|
||||||
|
|
||||||
void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset)
|
void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset)
|
||||||
{
|
{
|
||||||
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
|
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
|
||||||
off_t dptr = static_cast<off_t>(dh->dptr);
|
off_t dptr = static_cast<off_t>(dh->dptr);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
|
@ -809,7 +810,7 @@ void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset)
|
||||||
|
|
||||||
off_t FATFileSystem::dir_tell(fs_dir_t dir)
|
off_t FATFileSystem::dir_tell(fs_dir_t dir)
|
||||||
{
|
{
|
||||||
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
|
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
off_t offset = dh->dptr;
|
off_t offset = dh->dptr;
|
||||||
|
@ -820,7 +821,7 @@ off_t FATFileSystem::dir_tell(fs_dir_t dir)
|
||||||
|
|
||||||
void FATFileSystem::dir_rewind(fs_dir_t dir)
|
void FATFileSystem::dir_rewind(fs_dir_t dir)
|
||||||
{
|
{
|
||||||
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
|
FATFS_DIR *dh = static_cast<FATFS_DIR *>(dir);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
f_rewinddir(dh);
|
f_rewinddir(dh);
|
||||||
|
|
|
@ -33,17 +33,28 @@ extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
|
||||||
static int lfs_toerror(int err)
|
static int lfs_toerror(int err)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case LFS_ERR_OK: return 0;
|
case LFS_ERR_OK:
|
||||||
case LFS_ERR_IO: return -EIO;
|
return 0;
|
||||||
case LFS_ERR_NOENT: return -ENOENT;
|
case LFS_ERR_IO:
|
||||||
case LFS_ERR_EXIST: return -EEXIST;
|
return -EIO;
|
||||||
case LFS_ERR_NOTDIR: return -ENOTDIR;
|
case LFS_ERR_NOENT:
|
||||||
case LFS_ERR_ISDIR: return -EISDIR;
|
return -ENOENT;
|
||||||
case LFS_ERR_INVAL: return -EINVAL;
|
case LFS_ERR_EXIST:
|
||||||
case LFS_ERR_NOSPC: return -ENOSPC;
|
return -EEXIST;
|
||||||
case LFS_ERR_NOMEM: return -ENOMEM;
|
case LFS_ERR_NOTDIR:
|
||||||
case LFS_ERR_CORRUPT: return -EILSEQ;
|
return -ENOTDIR;
|
||||||
default: return err;
|
case LFS_ERR_ISDIR:
|
||||||
|
return -EISDIR;
|
||||||
|
case LFS_ERR_INVAL:
|
||||||
|
return -EINVAL;
|
||||||
|
case LFS_ERR_NOSPC:
|
||||||
|
return -ENOSPC;
|
||||||
|
case LFS_ERR_NOMEM:
|
||||||
|
return -ENOMEM;
|
||||||
|
case LFS_ERR_CORRUPT:
|
||||||
|
return -EILSEQ;
|
||||||
|
default:
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +73,14 @@ static int lfs_fromflags(int flags)
|
||||||
static int lfs_fromwhence(int whence)
|
static int lfs_fromwhence(int whence)
|
||||||
{
|
{
|
||||||
switch (whence) {
|
switch (whence) {
|
||||||
case SEEK_SET: return LFS_SEEK_SET;
|
case SEEK_SET:
|
||||||
case SEEK_CUR: return LFS_SEEK_CUR;
|
return LFS_SEEK_SET;
|
||||||
case SEEK_END: return LFS_SEEK_END;
|
case SEEK_CUR:
|
||||||
default: return whence;
|
return LFS_SEEK_CUR;
|
||||||
|
case SEEK_END:
|
||||||
|
return LFS_SEEK_END;
|
||||||
|
default:
|
||||||
|
return whence;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,39 +88,47 @@ static int lfs_tomode(int type)
|
||||||
{
|
{
|
||||||
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LFS_TYPE_DIR: return mode | S_IFDIR;
|
case LFS_TYPE_DIR:
|
||||||
case LFS_TYPE_REG: return mode | S_IFREG;
|
return mode | S_IFDIR;
|
||||||
default: return 0;
|
case LFS_TYPE_REG:
|
||||||
|
return mode | S_IFREG;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lfs_totype(int type)
|
static int lfs_totype(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LFS_TYPE_DIR: return DT_DIR;
|
case LFS_TYPE_DIR:
|
||||||
case LFS_TYPE_REG: return DT_REG;
|
return DT_DIR;
|
||||||
default: return DT_UNKNOWN;
|
case LFS_TYPE_REG:
|
||||||
|
return DT_REG;
|
||||||
|
default:
|
||||||
|
return DT_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////// Block device operations //////
|
////// Block device operations //////
|
||||||
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
|
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
|
||||||
lfs_off_t off, void *buffer, lfs_size_t size) {
|
lfs_off_t off, void *buffer, lfs_size_t size)
|
||||||
|
{
|
||||||
BlockDevice *bd = (BlockDevice *)c->context;
|
BlockDevice *bd = (BlockDevice *)c->context;
|
||||||
return bd->read(buffer, (bd_addr_t)block*c->block_size + off, size);
|
return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
|
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
|
||||||
lfs_off_t off, const void *buffer, lfs_size_t size) {
|
lfs_off_t off, const void *buffer, lfs_size_t size)
|
||||||
|
{
|
||||||
BlockDevice *bd = (BlockDevice *)c->context;
|
BlockDevice *bd = (BlockDevice *)c->context;
|
||||||
return bd->program(buffer, (bd_addr_t)block*c->block_size + off, size);
|
return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
|
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
|
||||||
{
|
{
|
||||||
BlockDevice *bd = (BlockDevice *)c->context;
|
BlockDevice *bd = (BlockDevice *)c->context;
|
||||||
return bd->erase((bd_addr_t)block*c->block_size, c->block_size);
|
return bd->erase((bd_addr_t)block * c->block_size, c->block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lfs_bd_sync(const struct lfs_config *c)
|
static int lfs_bd_sync(const struct lfs_config *c)
|
||||||
|
@ -125,13 +148,15 @@ LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
|
||||||
, _read_size(read_size)
|
, _read_size(read_size)
|
||||||
, _prog_size(prog_size)
|
, _prog_size(prog_size)
|
||||||
, _block_size(block_size)
|
, _block_size(block_size)
|
||||||
, _lookahead(lookahead) {
|
, _lookahead(lookahead)
|
||||||
|
{
|
||||||
if (bd) {
|
if (bd) {
|
||||||
mount(bd);
|
mount(bd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LittleFileSystem::~LittleFileSystem() {
|
LittleFileSystem::~LittleFileSystem()
|
||||||
|
{
|
||||||
// nop if unmounted
|
// nop if unmounted
|
||||||
unmount();
|
unmount();
|
||||||
}
|
}
|
||||||
|
@ -168,7 +193,7 @@ int LittleFileSystem::mount(BlockDevice *bd)
|
||||||
_config.block_size = _block_size;
|
_config.block_size = _block_size;
|
||||||
}
|
}
|
||||||
_config.block_count = bd->size() / _config.block_size;
|
_config.block_count = bd->size() / _config.block_size;
|
||||||
_config.lookahead = 32 * ((_config.block_count+31)/32);
|
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
|
||||||
if (_config.lookahead > _lookahead) {
|
if (_config.lookahead > _lookahead) {
|
||||||
_config.lookahead = _lookahead;
|
_config.lookahead = _lookahead;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +237,8 @@ int LittleFileSystem::unmount()
|
||||||
|
|
||||||
int LittleFileSystem::format(BlockDevice *bd,
|
int LittleFileSystem::format(BlockDevice *bd,
|
||||||
lfs_size_t read_size, lfs_size_t prog_size,
|
lfs_size_t read_size, lfs_size_t prog_size,
|
||||||
lfs_size_t block_size, lfs_size_t lookahead) {
|
lfs_size_t block_size, lfs_size_t lookahead)
|
||||||
|
{
|
||||||
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
|
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
|
||||||
bd, read_size, prog_size, block_size, lookahead);
|
bd, read_size, prog_size, block_size, lookahead);
|
||||||
int err = bd->init();
|
int err = bd->init();
|
||||||
|
@ -243,7 +269,7 @@ int LittleFileSystem::format(BlockDevice *bd,
|
||||||
_config.block_size = block_size;
|
_config.block_size = block_size;
|
||||||
}
|
}
|
||||||
_config.block_count = bd->size() / _config.block_size;
|
_config.block_count = bd->size() / _config.block_size;
|
||||||
_config.lookahead = 32 * ((_config.block_count+31)/32);
|
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
|
||||||
if (_config.lookahead > lookahead) {
|
if (_config.lookahead > lookahead) {
|
||||||
_config.lookahead = lookahead;
|
_config.lookahead = lookahead;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,11 @@ public:
|
||||||
* The lookahead buffer requires only 1 bit per block so it can be quite
|
* The lookahead buffer requires only 1 bit per block so it can be quite
|
||||||
* large with little ram impact. Should be a multiple of 32.
|
* large with little ram impact. Should be a multiple of 32.
|
||||||
*/
|
*/
|
||||||
LittleFileSystem(const char *name=NULL, BlockDevice *bd=NULL,
|
LittleFileSystem(const char *name = NULL, BlockDevice *bd = NULL,
|
||||||
lfs_size_t read_size=MBED_LFS_READ_SIZE,
|
lfs_size_t read_size = MBED_LFS_READ_SIZE,
|
||||||
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
|
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
|
||||||
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
|
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
|
||||||
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
|
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
|
||||||
virtual ~LittleFileSystem();
|
virtual ~LittleFileSystem();
|
||||||
|
|
||||||
/** Formats a block device with the LittleFileSystem
|
/** Formats a block device with the LittleFileSystem
|
||||||
|
@ -82,10 +82,10 @@ public:
|
||||||
* large with little ram impact. Should be a multiple of 32.
|
* large with little ram impact. Should be a multiple of 32.
|
||||||
*/
|
*/
|
||||||
static int format(BlockDevice *bd,
|
static int format(BlockDevice *bd,
|
||||||
lfs_size_t read_size=MBED_LFS_READ_SIZE,
|
lfs_size_t read_size = MBED_LFS_READ_SIZE,
|
||||||
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
|
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
|
||||||
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
|
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
|
||||||
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
|
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
|
||||||
|
|
||||||
/** Mounts a filesystem to a block device
|
/** Mounts a filesystem to a block device
|
||||||
*
|
*
|
||||||
|
|
|
@ -157,9 +157,9 @@ static int file_scanf(File *file, const char *format, ...)
|
||||||
int res = file->read(buf, sizeof(buf) - 1);
|
int res = file->read(buf, sizeof(buf) - 1);
|
||||||
TEST_ASSERT_OR_EXIT(res >= 0);
|
TEST_ASSERT_OR_EXIT(res >= 0);
|
||||||
|
|
||||||
va_start (args, format);
|
va_start(args, format);
|
||||||
int count = vsscanf((char*)buf, format, args);
|
int count = vsscanf((char *)buf, format, args);
|
||||||
va_end (args);
|
va_end(args);
|
||||||
TEST_ASSERT_OR_EXIT(count >= 0);
|
TEST_ASSERT_OR_EXIT(count >= 0);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
@ -176,9 +176,9 @@ static int file_printf(File *file, const char *format, ...)
|
||||||
{
|
{
|
||||||
uint8_t buf[BUFFER_SIZE];
|
uint8_t buf[BUFFER_SIZE];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, format);
|
va_start(args, format);
|
||||||
int size = vsprintf((char*)buf, format, args);
|
int size = vsprintf((char *)buf, format, args);
|
||||||
va_end (args);
|
va_end(args);
|
||||||
TEST_ASSERT_OR_EXIT((size >= 0) && (size <= (int)sizeof(buf)));
|
TEST_ASSERT_OR_EXIT((size >= 0) && (size <= (int)sizeof(buf)));
|
||||||
|
|
||||||
if (file_write(file, buf, size)) {
|
if (file_write(file, buf, size)) {
|
||||||
|
@ -254,7 +254,7 @@ static void check_file_rename(FileSystem *fs)
|
||||||
|
|
||||||
int files = 0;
|
int files = 0;
|
||||||
int valids = 0;
|
int valids = 0;
|
||||||
const char * const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
|
const char *const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
File file;
|
File file;
|
||||||
|
@ -300,7 +300,7 @@ static void setup_file_rename_replace(FileSystem *fs)
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
uint8_t buf[BUFFER_SIZE];
|
uint8_t buf[BUFFER_SIZE];
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
const int length = sprintf((char*)buf, FILE_RENAME_REPLACE_FMT, count);
|
const int length = sprintf((char *)buf, FILE_RENAME_REPLACE_FMT, count);
|
||||||
TEST_ASSERT_OR_EXIT(length > 0);
|
TEST_ASSERT_OR_EXIT(length > 0);
|
||||||
|
|
||||||
res = file.write(buf, length);
|
res = file.write(buf, length);
|
||||||
|
@ -602,7 +602,7 @@ static bool format_required(BlockDevice *bd)
|
||||||
|
|
||||||
// Get the test version
|
// Get the test version
|
||||||
uint32_t version = 0;
|
uint32_t version = 0;
|
||||||
res = sscanf((char*)buf, FILE_SETUP_COMPLETE_FMT, &version);
|
res = sscanf((char *)buf, FILE_SETUP_COMPLETE_FMT, &version);
|
||||||
if (res != 1) {
|
if (res != 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,8 +300,8 @@ void test_multi_block_directory()
|
||||||
res = fs.mkdir("cactus", 0777);
|
res = fs.mkdir("cactus", 0777);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
sprintf((char*)buffer, "cactus/test%d", i);
|
sprintf((char *)buffer, "cactus/test%d", i);
|
||||||
res = fs.mkdir((char*)buffer, 0777);
|
res = fs.mkdir((char *)buffer, 0777);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
}
|
}
|
||||||
res = fs.unmount();
|
res = fs.unmount();
|
||||||
|
@ -326,10 +326,10 @@ void test_multi_block_directory()
|
||||||
res = ent.d_type;
|
res = ent.d_type;
|
||||||
TEST_ASSERT_EQUAL(DT_DIR, res);
|
TEST_ASSERT_EQUAL(DT_DIR, res);
|
||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
sprintf((char*)buffer, "test%d", i);
|
sprintf((char *)buffer, "test%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
}
|
}
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
|
|
|
@ -167,7 +167,7 @@ void test_small_file_test()
|
||||||
chunk = (chunk < size - i) ? chunk : size - i;
|
chunk = (chunk < size - i) ? chunk : size - i;
|
||||||
res = file[0].read(buffer, chunk);
|
res = file[0].read(buffer, chunk);
|
||||||
TEST_ASSERT_EQUAL(chunk, res);
|
TEST_ASSERT_EQUAL(chunk, res);
|
||||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||||
res = buffer[b];
|
res = buffer[b];
|
||||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ void test_medium_file_test()
|
||||||
chunk = (chunk < size - i) ? chunk : size - i;
|
chunk = (chunk < size - i) ? chunk : size - i;
|
||||||
res = file[0].read(buffer, chunk);
|
res = file[0].read(buffer, chunk);
|
||||||
TEST_ASSERT_EQUAL(chunk, res);
|
TEST_ASSERT_EQUAL(chunk, res);
|
||||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||||
res = buffer[b];
|
res = buffer[b];
|
||||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ void test_large_file_test()
|
||||||
chunk = (chunk < size - i) ? chunk : size - i;
|
chunk = (chunk < size - i) ? chunk : size - i;
|
||||||
res = file[0].read(buffer, chunk);
|
res = file[0].read(buffer, chunk);
|
||||||
TEST_ASSERT_EQUAL(chunk, res);
|
TEST_ASSERT_EQUAL(chunk, res);
|
||||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||||
res = buffer[b];
|
res = buffer[b];
|
||||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ void test_non_overlap_check()
|
||||||
chunk = (chunk < size - i) ? chunk : size - i;
|
chunk = (chunk < size - i) ? chunk : size - i;
|
||||||
res = file[0].read(buffer, chunk);
|
res = file[0].read(buffer, chunk);
|
||||||
TEST_ASSERT_EQUAL(chunk, res);
|
TEST_ASSERT_EQUAL(chunk, res);
|
||||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||||
res = buffer[b];
|
res = buffer[b];
|
||||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ void test_non_overlap_check()
|
||||||
chunk = (chunk < size - i) ? chunk : size - i;
|
chunk = (chunk < size - i) ? chunk : size - i;
|
||||||
res = file[0].read(buffer, chunk);
|
res = file[0].read(buffer, chunk);
|
||||||
TEST_ASSERT_EQUAL(chunk, res);
|
TEST_ASSERT_EQUAL(chunk, res);
|
||||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||||
res = buffer[b];
|
res = buffer[b];
|
||||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ void test_non_overlap_check()
|
||||||
chunk = (chunk < size - i) ? chunk : size - i;
|
chunk = (chunk < size - i) ? chunk : size - i;
|
||||||
res = file[0].read(buffer, chunk);
|
res = file[0].read(buffer, chunk);
|
||||||
TEST_ASSERT_EQUAL(chunk, res);
|
TEST_ASSERT_EQUAL(chunk, res);
|
||||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||||
res = buffer[b];
|
res = buffer[b];
|
||||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,13 +113,13 @@ void test_parallel_file_test()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
res = file[0].write((const void*)"a", 1);
|
res = file[0].write((const void *)"a", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[1].write((const void*)"b", 1);
|
res = file[1].write((const void *)"b", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[2].write((const void*)"c", 1);
|
res = file[2].write((const void *)"c", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[3].write((const void*)"d", 1);
|
res = file[3].write((const void *)"d", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ void test_parallel_remove_file_test()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
res = file[0].write((const void*)"e", 1);
|
res = file[0].write((const void *)"e", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
}
|
}
|
||||||
res = fs.remove("a");
|
res = fs.remove("a");
|
||||||
|
@ -238,7 +238,7 @@ void test_parallel_remove_file_test()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
res = file[0].write((const void*)"e", 1);
|
res = file[0].write((const void *)"e", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,22 +303,22 @@ void test_remove_inconveniently_test()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
res = file[0].write((const void*)"e", 1);
|
res = file[0].write((const void *)"e", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[1].write((const void*)"f", 1);
|
res = file[1].write((const void *)"f", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[2].write((const void*)"g", 1);
|
res = file[2].write((const void *)"g", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
}
|
}
|
||||||
res = fs.remove("f");
|
res = fs.remove("f");
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
res = file[0].write((const void*)"e", 1);
|
res = file[0].write((const void *)"e", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[1].write((const void*)"f", 1);
|
res = file[1].write((const void *)"f", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = file[2].write((const void*)"g", 1);
|
res = file[2].write((const void *)"g", 1);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,8 @@ void test_seek_tests()
|
||||||
res = fs.mkdir("hello", 0777);
|
res = fs.mkdir("hello", 0777);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
for (int i = 0; i < 132; i++) {
|
for (int i = 0; i < 132; i++) {
|
||||||
sprintf((char*)buffer, "hello/kitty%d", i);
|
sprintf((char *)buffer, "hello/kitty%d", i);
|
||||||
res = file[0].open(&fs, (char*)buffer,
|
res = file[0].open(&fs, (char *)buffer,
|
||||||
O_WRONLY | O_CREAT | O_APPEND);
|
O_WRONLY | O_CREAT | O_APPEND);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
|
@ -137,10 +137,10 @@ void test_simple_dir_seek()
|
||||||
off_t pos;
|
off_t pos;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
sprintf((char*)buffer, "kitty%d", i);
|
sprintf((char *)buffer, "kitty%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
pos = dir[0].tell();
|
pos = dir[0].tell();
|
||||||
}
|
}
|
||||||
|
@ -148,14 +148,14 @@ void test_simple_dir_seek()
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
|
|
||||||
dir[0].seek(pos);
|
dir[0].seek(pos);
|
||||||
sprintf((char*)buffer, "kitty%d", i);
|
sprintf((char *)buffer, "kitty%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
dir[0].rewind();
|
dir[0].rewind();
|
||||||
sprintf((char*)buffer, "kitty%d", 0);
|
sprintf((char *)buffer, "kitty%d", 0);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, ".");
|
res = strcmp(ent.d_name, ".");
|
||||||
|
@ -166,14 +166,14 @@ void test_simple_dir_seek()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
dir[0].seek(pos);
|
dir[0].seek(pos);
|
||||||
sprintf((char*)buffer, "kitty%d", i);
|
sprintf((char *)buffer, "kitty%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
res = dir[0].close();
|
res = dir[0].close();
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
@ -207,10 +207,10 @@ void test_large_dir_seek()
|
||||||
off_t pos;
|
off_t pos;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 128; i++) {
|
for (i = 0; i < 128; i++) {
|
||||||
sprintf((char*)buffer, "kitty%d", i);
|
sprintf((char *)buffer, "kitty%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
pos = dir[0].tell();
|
pos = dir[0].tell();
|
||||||
}
|
}
|
||||||
|
@ -218,14 +218,14 @@ void test_large_dir_seek()
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
|
|
||||||
dir[0].seek(pos);
|
dir[0].seek(pos);
|
||||||
sprintf((char*)buffer, "kitty%d", i);
|
sprintf((char *)buffer, "kitty%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
dir[0].rewind();
|
dir[0].rewind();
|
||||||
sprintf((char*)buffer, "kitty%d", 0);
|
sprintf((char *)buffer, "kitty%d", 0);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, ".");
|
res = strcmp(ent.d_name, ".");
|
||||||
|
@ -236,14 +236,14 @@ void test_large_dir_seek()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
dir[0].seek(pos);
|
dir[0].seek(pos);
|
||||||
sprintf((char*)buffer, "kitty%d", i);
|
sprintf((char *)buffer, "kitty%d", i);
|
||||||
res = dir[0].read(&ent);
|
res = dir[0].read(&ent);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ent.d_name, (char*)buffer);
|
res = strcmp(ent.d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
res = dir[0].close();
|
res = dir[0].close();
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
@ -580,26 +580,26 @@ void test_out_of_bounds_seek()
|
||||||
|
|
||||||
size = strlen("kittycatcat");
|
size = strlen("kittycatcat");
|
||||||
res = file[0].size();
|
res = file[0].size();
|
||||||
TEST_ASSERT_EQUAL(132*size, res);
|
TEST_ASSERT_EQUAL(132 * size, res);
|
||||||
res = file[0].seek((132+4)*size,
|
res = file[0].seek((132 + 4) * size,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||||
res = file[0].read(buffer, size);
|
res = file[0].read(buffer, size);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
memcpy(buffer, "porcupineee", size);
|
memcpy(buffer, "porcupineee", size);
|
||||||
res = file[0].write(buffer, size);
|
res = file[0].write(buffer, size);
|
||||||
TEST_ASSERT_EQUAL(size, res);
|
TEST_ASSERT_EQUAL(size, res);
|
||||||
res = file[0].seek((132+4)*size,
|
res = file[0].seek((132 + 4) * size,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||||
res = file[0].read(buffer, size);
|
res = file[0].read(buffer, size);
|
||||||
TEST_ASSERT_EQUAL(size, res);
|
TEST_ASSERT_EQUAL(size, res);
|
||||||
res = memcmp(buffer, "porcupineee", size);
|
res = memcmp(buffer, "porcupineee", size);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
res = file[0].seek(132*size,
|
res = file[0].seek(132 * size,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
TEST_ASSERT_EQUAL(132*size, res);
|
TEST_ASSERT_EQUAL(132 * size, res);
|
||||||
res = file[0].read(buffer, size);
|
res = file[0].read(buffer, size);
|
||||||
TEST_ASSERT_EQUAL(size, res);
|
TEST_ASSERT_EQUAL(size, res);
|
||||||
res = memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size);
|
res = memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size);
|
||||||
|
|
|
@ -117,10 +117,10 @@ void test_bad_mount()
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
|
|
||||||
{
|
{
|
||||||
res = bd.erase(0, 2*bd.get_erase_size());
|
res = bd.erase(0, 2 * bd.get_erase_size());
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
memset(buffer, 0, bd.get_program_size());
|
memset(buffer, 0, bd.get_program_size());
|
||||||
for (int i = 0; i < 2*bd.get_erase_size(); i += bd.get_program_size()) {
|
for (int i = 0; i < 2 * bd.get_erase_size(); i += bd.get_program_size()) {
|
||||||
res = bd.program(buffer, i, bd.get_program_size());
|
res = bd.program(buffer, i, bd.get_program_size());
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ void test_resilience()
|
||||||
bd_size_t block_size = bd.get_erase_size();
|
bd_size_t block_size = bd.get_erase_size();
|
||||||
bd.deinit();
|
bd.deinit();
|
||||||
|
|
||||||
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT*block_size);
|
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT * block_size);
|
||||||
|
|
||||||
// Setup the test
|
// Setup the test
|
||||||
setup_atomic_operations(&slice, true);
|
setup_atomic_operations(&slice, true);
|
||||||
|
|
|
@ -62,11 +62,11 @@ static uint32_t test_wear_leveling_size(uint32_t block_count)
|
||||||
bd_size_t block_size = bd.get_erase_size();
|
bd_size_t block_size = bd.get_erase_size();
|
||||||
bd.deinit();
|
bd.deinit();
|
||||||
|
|
||||||
SlicingBlockDevice slice(&bd, 0, block_count*block_size);
|
SlicingBlockDevice slice(&bd, 0, block_count * block_size);
|
||||||
ExhaustibleBlockDevice ebd(&slice, MBED_TEST_ERASE_CYCLES);
|
ExhaustibleBlockDevice ebd(&slice, MBED_TEST_ERASE_CYCLES);
|
||||||
|
|
||||||
printf("Testing size %llu bytes (%lux%llu) blocks\n",
|
printf("Testing size %llu bytes (%lux%llu) blocks\n",
|
||||||
block_count*block_size, block_count, block_size);
|
block_count * block_size, block_count, block_size);
|
||||||
setup_atomic_operations(&ebd, true);
|
setup_atomic_operations(&ebd, true);
|
||||||
|
|
||||||
int64_t cycles = 0;
|
int64_t cycles = 0;
|
||||||
|
|
|
@ -301,8 +301,8 @@ void test_multi_block_directory()
|
||||||
res = mkdir("/fs/" "cactus", 0777);
|
res = mkdir("/fs/" "cactus", 0777);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
sprintf((char*)buffer, "/fs/" "cactus/test%d", i);
|
sprintf((char *)buffer, "/fs/" "cactus/test%d", i);
|
||||||
res = mkdir((char*)buffer, 0777);
|
res = mkdir((char *)buffer, 0777);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
}
|
}
|
||||||
res = fs.unmount();
|
res = fs.unmount();
|
||||||
|
@ -327,10 +327,10 @@ void test_multi_block_directory()
|
||||||
res = ed->d_type;
|
res = ed->d_type;
|
||||||
TEST_ASSERT_EQUAL(DT_DIR, res);
|
TEST_ASSERT_EQUAL(DT_DIR, res);
|
||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
sprintf((char*)buffer, "test%d", i);
|
sprintf((char *)buffer, "test%d", i);
|
||||||
res = ((ed = readdir(dd[0])) != NULL);
|
res = ((ed = readdir(dd[0])) != NULL);
|
||||||
TEST_ASSERT_EQUAL(1, res);
|
TEST_ASSERT_EQUAL(1, res);
|
||||||
res = strcmp(ed->d_name, (char*)buffer);
|
res = strcmp(ed->d_name, (char *)buffer);
|
||||||
TEST_ASSERT_EQUAL(0, res);
|
TEST_ASSERT_EQUAL(0, res);
|
||||||
}
|
}
|
||||||
res = ((ed = readdir(dd[0])) != NULL);
|
res = ((ed = readdir(dd[0])) != NULL);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue