Skip to content

Commit 1e80833

Browse files
authored
Merge pull request #30 from Strooom/develop
Merge improvements into Main
2 parents 2b0bafd + 5244b2c commit 1e80833

File tree

15 files changed

+62
-52
lines changed

15 files changed

+62
-52
lines changed

lib/aes/aesblock.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void aesBlock::setFromWordArray(const uint32_t wordsIn[lengthInWords]) {
2222

2323
void aesBlock::setFromHexString(const char *string) {
2424
uint8_t tmpBytes[lengthInBytes];
25-
hexAscii::hexStringToByteArray(tmpBytes, string);
25+
hexAscii::hexStringToByteArray(tmpBytes, string, 32U);
2626
(void)memcpy(state.asByte, tmpBytes, lengthInBytes);
2727
}
2828

@@ -177,7 +177,7 @@ void aesBlock::mixColumns() {
177177
for (uint8_t column = 0; column < 4; column++) {
178178
for (uint8_t row = 0; row < 4; row++) {
179179
a[row] = tempState[row][column];
180-
b[row] = (tempState[row][column] << 1);
180+
b[row] = (tempState[row][column] << 1U);
181181

182182
if ((tempState[row][column] & 0x80) == 0x80) {
183183
b[row] ^= 0x1B;
@@ -195,13 +195,13 @@ void aesBlock::shiftLeft() {
195195
for (uint32_t byteIndex = 0; byteIndex < 16; byteIndex++) {
196196
if (byteIndex < 15) {
197197
if ((state.asByte[byteIndex + 1] & 0x80) == 0x80) {
198-
state.asByte[byteIndex] = (state.asByte[byteIndex] << 1) + 1;
198+
state.asByte[byteIndex] = (state.asByte[byteIndex] << 1U) + 1U;
199199

200200
} else {
201-
state.asByte[byteIndex] = (state.asByte[byteIndex] << 1);
201+
state.asByte[byteIndex] = (state.asByte[byteIndex] << 1U);
202202
}
203203
} else {
204-
state.asByte[byteIndex] = (state.asByte[byteIndex] << 1);
204+
state.asByte[byteIndex] = (state.asByte[byteIndex] << 1U);
205205
}
206206
}
207207
}

lib/aes/aeskey.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void aesKey::setFromWordArray(const uint32_t wordsIn[lengthInWords]) {
2525

2626
void aesKey::setFromHexString(const char* string) {
2727
uint8_t tmpBytes[lengthInBytes];
28-
hexAscii::hexStringToByteArray(tmpBytes, string);
28+
hexAscii::hexStringToByteArray(tmpBytes, string, 32U);
2929
(void)memcpy(key.asByte, tmpBytes, lengthInBytes);
3030
expandKey();
3131
}
@@ -39,7 +39,7 @@ uint32_t aesKey::swapLittleBigEndian( uint32_t wordIn) {
3939

4040
void aesKey::expandKey() {
4141
(void)memcpy(expandedKey, key.asByte, 16);
42-
for (auto round = 1; round <= 10; round++) {
42+
for (uint8_t round = 1; round <= 10; round++) {
4343
(void)memcpy(expandedKey + (round * 16), expandedKey + ((round - 1) * 16), 16);
4444
calculateRoundKey(round);
4545
}

lib/application/maincontroller.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ void mainController::showDeviceInfo() {
364364
void mainController::showLoRaWanConfig() {
365365
char tmpString[screen::maxTextLength2 + 1];
366366
screen::clearAllTexts();
367-
uint16_t devAddrEnd = LoRaWAN::DevAddr.asUint8[0] + (LoRaWAN::DevAddr.asUint8[1] << 8);
368-
uint16_t applicationKeyEnd = LoRaWAN::applicationKey.asBytes()[15] + (LoRaWAN::applicationKey.asBytes()[14] << 8);
369-
uint16_t networkKeyEnd = LoRaWAN::networkKey.asBytes()[15] + (LoRaWAN::networkKey.asBytes()[14] << 8);
367+
uint16_t devAddrEnd = LoRaWAN::DevAddr.asUint8[0] + (LoRaWAN::DevAddr.asUint8[1] << 8U);
368+
uint16_t applicationKeyEnd = LoRaWAN::applicationKey.asBytes()[15] + (LoRaWAN::applicationKey.asBytes()[14] << 8U);
369+
uint16_t networkKeyEnd = LoRaWAN::networkKey.asBytes()[15] + (LoRaWAN::networkKey.asBytes()[14] << 8U);
370370
snprintf(tmpString, screen::maxTextLength2, "%04X %04X %04X", devAddrEnd, applicationKeyEnd, networkKeyEnd);
371371
screen::setText(0, tmpString);
372372
snprintf(tmpString, screen::maxTextLength2, "DataRate : %u", static_cast<uint8_t>(LoRaWAN::currentDataRateIndex));

lib/display/display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ bool display::isBusy() {
233233
void display::write( uint8_t* data, const uint32_t length) {
234234
selectChip(true);
235235
#ifndef generic
236-
HAL_SPI_Transmit(&hspi2, data, length, 1000); // TODO : get the HAL timeout stuff right
236+
HAL_SPI_Transmit(&hspi2, data, static_cast<const uint16_t>(length), 1000); // TODO : get the HAL timeout stuff right
237237
#endif
238238
selectChip(false);
239239
}

lib/general/strl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
#if !defined strlcpy || !defined strlcat
99
#include <stdint.h> // required for uint8_t and similar type definitions
10-
#include <cstring> // required for memcpy()
10+
#include <cstring> // required for memcpy()
1111
#endif
1212

1313
#ifndef strlcpy
1414
// on some platforms, cstring does not contain strlcpy, so in this case we add it here directly
1515
size_t
1616
strlcpy(char* dst, const char* src, size_t maxlen) {
17-
const size_t srclen = strlen(src);
17+
const size_t srclen = strnlen(src, maxlen);
1818
if (srclen + 1 < maxlen) {
1919
(void)memcpy(dst, src, srclen + 1);
2020
} else if (maxlen != 0) {
@@ -29,7 +29,7 @@ strlcpy(char* dst, const char* src, size_t maxlen) {
2929
// on some platforms, cstring does not contain strlcpy, so in this case we add it here directly
3030
size_t
3131
strlcat(char* dst, const char* src, size_t maxlen) {
32-
const size_t srclen = strlen(src);
32+
const size_t srclen = strnlen(src, maxlen);
3333
const size_t dstlen = strnlen(dst, maxlen);
3434
if (dstlen == maxlen) return maxlen + srclen;
3535
if (srclen < maxlen - dstlen) {

lib/hexascii/hexascii.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <hexascii.hpp>
2-
#include "cstring"
3-
2+
#include <cstring>
3+
#include <logging.hpp>
44
uint8_t hexAscii::toUpperCase(const uint8_t characterToConvert) {
55
if (characterToConvert >= 'a' && characterToConvert <= 'z') {
66
return characterToConvert - 'a' + 'A';
@@ -35,17 +35,17 @@ uint8_t hexAscii::hexCharacterFromValue(const uint8_t valueToConvert) {
3535
return '?';
3636
}
3737

38-
void hexAscii::hexStringToByteArray(uint8_t *byteArrayOut, const char *hexStringIn) {
39-
uint32_t hexStringInLength = strlen(hexStringIn);
40-
uint32_t nmbrBytes = hexStringInLength / 2;
38+
void hexAscii::hexStringToByteArray(uint8_t *byteArrayOut, const char *hexStringIn, const uint32_t stringInLength) {
39+
uint32_t hexStringInLength = strnlen(hexStringIn, stringInLength);
40+
uint32_t nmbrBytes = hexStringInLength / 2;
4141

4242
for (uint32_t index = 0; index < nmbrBytes; index++) {
43-
uint8_t leftCharacter = hexStringIn[index * 2];
44-
uint8_t rightCharacter = hexStringIn[(index * 2) + 1];
43+
uint8_t leftCharacter = static_cast<uint8_t>(hexStringIn[index * 2]);
44+
uint8_t rightCharacter = static_cast<uint8_t>(hexStringIn[(index * 2) + 1]);
4545
leftCharacter = toUpperCase(leftCharacter);
4646
rightCharacter = toUpperCase(rightCharacter);
4747
if ((isHexCharacter(leftCharacter)) && (isHexCharacter(rightCharacter))) {
48-
byteArrayOut[index] = (valueFromHexCharacter(leftCharacter) << 4) + valueFromHexCharacter(rightCharacter);
48+
byteArrayOut[index] = (valueFromHexCharacter(leftCharacter) << 4U) + valueFromHexCharacter(rightCharacter);
4949
}
5050
}
5151
}

lib/hexascii/hexascii.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class hexAscii {
1010
public:
11-
static void hexStringToByteArray(uint8_t *byteArrayOut, const char *hexStringIn);
11+
static void hexStringToByteArray(uint8_t *byteArrayOut, const char *hexStringIn, const uint32_t stringInLength);
1212
static void byteArrayToHexString(char *hexStringOut, const uint8_t *byteArrayIn, const uint32_t binaryArrayInLength);
1313
static void uint64ToHexString(char *hexStringOut, const uint64_t dataIn);
1414

lib/logging/logging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ void logging::write(uint32_t dataLength) {
8585
}
8686
if (isActive(destination::uart2usb)) {
8787
#ifndef generic
88-
HAL_UART_Transmit(&huart2, (uint8_t *)buffer, dataLength, 1000);
88+
HAL_UART_Transmit(&huart2, (uint8_t *)buffer, static_cast<const uint16_t>(dataLength), 1000);
8989
#endif
9090
}
9191
if (isActive(destination::uart1)) {
9292
#ifndef generic
93-
HAL_UART_Transmit(&huart1, (uint8_t *)buffer, dataLength, 1000);
93+
HAL_UART_Transmit(&huart1, (uint8_t *)buffer, static_cast<const uint16_t>(dataLength), 1000);
9494
#endif
9595
}
9696
}

lib/lorawan/framecontrol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ frameControl::frameControl(linkDirection newLinkDirection) {
2626

2727
uint8_t frameControl::asByte() const {
2828
uint8_t result{0};
29-
result = result | (ADR << 7U);
30-
result = result | (ADRACKReq << 6U);
31-
result = result | (ACK << 5U);
32-
result = result | (ClassB << 4U);
29+
result = result | (static_cast<uint8_t>(ADR) << 7U);
30+
result = result | (static_cast<uint8_t>(ADRACKReq) << 6U);
31+
result = result | (static_cast<uint8_t>(ACK) << 5U);
32+
result = result | (static_cast<uint8_t>(ClassB) << 4U);
3333
result = result | (FOptsLen & 0x0F);
3434
return result;
3535
}

lib/lorawan/lorawan.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void LoRaWAN::insertBlockB0(linkDirection theDirection, frameCount& aFrameCount)
224224
rawMessage[12] = aFrameCount[2];
225225
rawMessage[13] = aFrameCount[3];
226226
rawMessage[14] = 0;
227-
rawMessage[15] = macHeaderLength + frameHeaderLength + framePortLength + framePayloadLength;
227+
rawMessage[15] = static_cast<uint8_t>(macHeaderLength + frameHeaderLength + framePortLength + framePayloadLength);
228228
}
229229

230230
void LoRaWAN::padForMicCalculation(const uint32_t messageLength) {
@@ -236,15 +236,15 @@ void LoRaWAN::padForMicCalculation(const uint32_t messageLength) {
236236
}
237237

238238
uint16_t LoRaWAN::receivedFramecount() {
239-
return (static_cast<uint16_t>(rawMessage[frameCountOffset]) + (static_cast<uint16_t>(rawMessage[frameCountOffset + 1]) << 8));
239+
return (static_cast<uint16_t>(rawMessage[frameCountOffset]) + (static_cast<uint16_t>(rawMessage[frameCountOffset + 1]) << 8U));
240240
}
241241

242242
uint32_t LoRaWAN::receivedDeviceAddress() {
243-
return (static_cast<uint32_t>(rawMessage[deviceAddressOffset]) + (static_cast<uint32_t>(rawMessage[deviceAddressOffset + 1]) << 8) + (static_cast<uint32_t>(rawMessage[deviceAddressOffset + 2]) << 16) + (static_cast<uint32_t>(rawMessage[deviceAddressOffset + 3]) << 24));
243+
return (static_cast<uint32_t>(rawMessage[deviceAddressOffset]) + (static_cast<uint32_t>(rawMessage[deviceAddressOffset + 1]) << 8U) + (static_cast<uint32_t>(rawMessage[deviceAddressOffset + 2]) << 16U) + (static_cast<uint32_t>(rawMessage[deviceAddressOffset + 3]) << 24U));
244244
}
245245

246246
uint32_t LoRaWAN::receivedMic() {
247-
return (static_cast<uint32_t>(rawMessage[micOffset]) + (static_cast<uint32_t>(rawMessage[micOffset + 1]) << 8) + (static_cast<uint32_t>(rawMessage[micOffset + 2]) << 16) + (static_cast<uint32_t>(rawMessage[micOffset + 3]) << 24));
247+
return (static_cast<uint32_t>(rawMessage[micOffset]) + (static_cast<uint32_t>(rawMessage[micOffset + 1]) << 8U) + (static_cast<uint32_t>(rawMessage[micOffset + 2]) << 16U) + (static_cast<uint32_t>(rawMessage[micOffset + 3]) << 24U));
248248
};
249249

250250
#pragma endregion
@@ -273,7 +273,7 @@ void LoRaWAN::prepareBlockAi(aesBlock& theBlock, linkDirection theDirection, uin
273273
theBlock[13] = downlinkFrameCount[3]; // MSByte
274274
} //
275275
theBlock[14] = 0x00; //
276-
theBlock[15] = blockIndex; // Blocks Ai are indexed from 1..k, where k is the number of blocks
276+
theBlock[15] = static_cast<uint8_t>(blockIndex); // Blocks Ai are indexed from 1..k, where k is the number of blocks
277277
}
278278

279279
void LoRaWAN::encryptDecryptPayload(aesKey& theKey, linkDirection theLinkDirection) {
@@ -454,9 +454,9 @@ void LoRaWAN::insertMic() {
454454

455455
void LoRaWAN::insertMic(uint32_t aMic) {
456456
rawMessage[micOffset] = aMic & 0x000000FF; // LSByte
457-
rawMessage[micOffset + 1] = (aMic & 0x0000FF00) >> 8; //
458-
rawMessage[micOffset + 2] = (aMic & 0x00FF0000) >> 16; //
459-
rawMessage[micOffset + 3] = (aMic & 0xFF000000) >> 24; // MSByte
457+
rawMessage[micOffset + 1] = (aMic & 0x0000FF00) >> 8U; //
458+
rawMessage[micOffset + 2] = (aMic & 0x00FF0000) >> 16U; //
459+
rawMessage[micOffset + 3] = (aMic & 0xFF000000) >> 24U; // MSByte
460460
}
461461

462462
#pragma endregion

0 commit comments

Comments
 (0)