lorawan: fix astyle coding style

pull/8591/head
Martin Kojtal 2018-10-30 15:10:03 +00:00
parent 7bd258154d
commit 884a7748b2
29 changed files with 330 additions and 315 deletions

View File

@ -67,24 +67,29 @@ int LoRaMacCrypto::compute_mic(const uint8_t *buffer, uint16_t size,
if (NULL != cipher_info) {
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, mic_block_b0, sizeof(mic_block_b0));
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
if (0 != ret)
if (0 != ret) {
goto exit;
}
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16
@ -112,8 +117,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
a_block[0] = 0x01;
a_block[5] = dir;
@ -133,8 +139,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
ctr++;
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
s_block);
if (0 != ret)
if (0 != ret) {
goto exit;
}
for (i = 0; i < 16; i++) {
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
@ -147,8 +154,9 @@ int LoRaMacCrypto::encrypt_payload(const uint8_t *buffer, uint16_t size,
a_block[15] = ((ctr) & 0xFF);
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, a_block,
s_block);
if (0 != ret)
if (0 != ret) {
goto exit;
}
for (i = 0; i < size; i++) {
enc_buffer[bufferIndex + i] = buffer[bufferIndex + i] ^ s_block[i];
@ -181,20 +189,24 @@ int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *buffer, uint16_t size,
if (NULL != cipher_info) {
ret = mbedtls_cipher_setup(aes_cmac_ctx, cipher_info);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_starts(aes_cmac_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_update(aes_cmac_ctx, buffer, size & 0xFF);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_cipher_cmac_finish(aes_cmac_ctx, computed_mic);
if (0 != ret)
if (0 != ret) {
goto exit;
}
*mic = (uint32_t)((uint32_t) computed_mic[3] << 24
| (uint32_t) computed_mic[2] << 16
@ -217,13 +229,15 @@ int LoRaMacCrypto::decrypt_join_frame(const uint8_t *buffer, uint16_t size,
mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, buffer,
dec_buffer);
if (0 != ret)
if (0 != ret) {
goto exit;
}
// Check if optional CFList is included
if (size >= 16) {
@ -247,16 +261,18 @@ int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *key, uint32_t key
mbedtls_aes_init(&aes_ctx);
ret = mbedtls_aes_setkey_enc(&aes_ctx, key, key_length);
if (0 != ret)
if (0 != ret) {
goto exit;
}
memset(nonce, 0, sizeof(nonce));
nonce[0] = 0x01;
memcpy(nonce + 1, app_nonce, 6);
memcpy(nonce + 7, p_dev_nonce, 2);
ret = mbedtls_aes_crypt_ecb(&aes_ctx, MBEDTLS_AES_ENCRYPT, nonce, nwk_skey);
if (0 != ret)
if (0 != ret) {
goto exit;
}
memset(nonce, 0, sizeof(nonce));
nonce[0] = 0x02;

View File

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

View File

@ -193,13 +193,16 @@ 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,
125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000,
0, 0 };
0, 0
};
/*!
* Up/Down link data rates offset definition
*/
static const int8_t datarate_offsets_AU915[7][6] = { { DR_8, DR_8, DR_8, DR_8,
DR_8, DR_8 }, // DR_0
static const int8_t datarate_offsets_AU915[7][6] = { {
DR_8, DR_8, DR_8, DR_8,
DR_8, DR_8
}, // DR_0
{ DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1
{ DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2
{ DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3
@ -212,13 +215,15 @@ DR_8, DR_8 }, // DR_0
* Maximum payload with respect to the datarate index. Cannot operate with repeater.
*/
static const uint8_t max_payload_AU915[] = { 51, 51, 51, 115, 242, 242,
242, 0, 53, 129, 242, 242, 242, 242, 0, 0 };
242, 0, 53, 129, 242, 242, 242, 242, 0, 0
};
/*!
* Maximum payload with respect to the datarate index. Can operate with repeater.
*/
static const uint8_t max_payload_with_repeater_AU915[] = { 51, 51, 51, 115,
222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0 };
222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0
};
static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK;

View File

@ -212,8 +212,7 @@ LoRaPHYCN470::LoRaPHYCN470()
// Channels
// 125 kHz channels
for( uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++ )
{
for (uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++) {
channels[i].frequency = 470300000 + i * 200000;
channels[i].dr_range.value = (DR_5 << 4) | DR_0;
channels[i].band = 0;
@ -375,8 +374,7 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
_radio->unlock();
if( config->rx_slot == RX_SLOT_WIN_1 )
{
if (config->rx_slot == RX_SLOT_WIN_1) {
// Apply window 1 frequency
frequency = CN470_FIRST_RX1_CHANNEL + (config->channel % 48) * CN470_STEPWIDTH_RX1_CHANNEL;
}

View File

@ -192,8 +192,7 @@ static const uint32_t bandwidths_US915[] = {125000, 125000, 125000, 125000, 5000
/*!
* Up/Down link data rates offset definition
*/
static const int8_t datarate_offsets_US915[5][4] =
{
static const int8_t datarate_offsets_US915[5][4] = {
{ DR_10, DR_9, DR_8, DR_8 }, // DR_0
{ DR_11, DR_10, DR_9, DR_8 }, // DR_1
{ DR_12, DR_11, DR_10, DR_9 }, // DR_2
@ -572,8 +571,7 @@ uint8_t LoRaPHYUS915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
}
// Verify datarate offset
if (val_in_range( params->dr_offset, US915_MIN_RX1_DR_OFFSET, US915_MAX_RX1_DR_OFFSET ) == 0 )
{
if (val_in_range(params->dr_offset, US915_MIN_RX1_DR_OFFSET, US915_MAX_RX1_DR_OFFSET) == 0) {
status &= 0xFB; // Rx1DrOffset range KO
}

View File

@ -26,8 +26,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "lorawan_data_structures.h"
class LoRaWANTimeHandler
{
class LoRaWANTimeHandler {
public:
LoRaWANTimeHandler();
~LoRaWANTimeHandler();