hci_cmd: split cases for better coverage count, add LCOV_EXCL_BR_LINE to exclude va_arg branch line

This commit is contained in:
Milanka Ringwald 2021-06-18 19:33:51 +02:00
parent 23e56acec0
commit c56de76b13

View File

@ -51,6 +51,7 @@
#include <string.h> #include <string.h>
#ifdef ENABLE_SDP #ifdef ENABLE_SDP
#include "classic/sdp_util.h" #include "classic/sdp_util.h"
#endif #endif
@ -86,31 +87,37 @@ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *
while (*format) { while (*format) {
switch(*format) { switch(*format) {
case '1': // 8 bit value case '1': // 8 bit value
case '2': // 16 bit value // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
case 'H': // hci_handle word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE
word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
hci_cmd_buffer[pos++] = word & 0xffu; hci_cmd_buffer[pos++] = word & 0xffu;
if (*format == '2') { break;
hci_cmd_buffer[pos++] = word >> 8; case '2': // 16 bit value
} else if (*format == 'H') { // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
// TODO implement opaque client connection handles word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE
// pass module handle for now hci_cmd_buffer[pos++] = word & 0xffu;
hci_cmd_buffer[pos++] = word >> 8; hci_cmd_buffer[pos++] = word >> 8;
} break;
case 'H': // hci_handle
// minimal va_arg is int: 2 bytes on 8+16 bit CPUs
word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE
hci_cmd_buffer[pos++] = word & 0xffu;
hci_cmd_buffer[pos++] = word >> 8;
break; break;
case '3': case '3':
case '4': longword = va_arg(argptr, uint32_t); // LCOV_EXCL_BR_LINE
longword = va_arg(argptr, uint32_t);
// longword = va_arg(argptr, int);
hci_cmd_buffer[pos++] = longword; hci_cmd_buffer[pos++] = longword;
hci_cmd_buffer[pos++] = longword >> 8; hci_cmd_buffer[pos++] = longword >> 8;
hci_cmd_buffer[pos++] = longword >> 16; hci_cmd_buffer[pos++] = longword >> 16;
if (*format == '4'){ break;
hci_cmd_buffer[pos++] = longword >> 24; case '4':
} longword = va_arg(argptr, uint32_t); // LCOV_EXCL_BR_LINE
hci_cmd_buffer[pos++] = longword;
hci_cmd_buffer[pos++] = longword >> 8;
hci_cmd_buffer[pos++] = longword >> 16;
hci_cmd_buffer[pos++] = longword >> 24;
break; break;
case 'B': // bt-addr case 'B': // bt-addr
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
hci_cmd_buffer[pos++] = ptr[5]; hci_cmd_buffer[pos++] = ptr[5];
hci_cmd_buffer[pos++] = ptr[4]; hci_cmd_buffer[pos++] = ptr[4];
hci_cmd_buffer[pos++] = ptr[3]; hci_cmd_buffer[pos++] = ptr[3];
@ -119,17 +126,17 @@ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *
hci_cmd_buffer[pos++] = ptr[0]; hci_cmd_buffer[pos++] = ptr[0];
break; break;
case 'D': // 8 byte data block case 'D': // 8 byte data block
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
(void)memcpy(&hci_cmd_buffer[pos], ptr, 8); (void)memcpy(&hci_cmd_buffer[pos], ptr, 8);
pos += 8; pos += 8;
break; break;
case 'E': // Extended Inquiry Information 240 octets case 'E': // Extended Inquiry Information 240 octets
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
(void)memcpy(&hci_cmd_buffer[pos], ptr, 240); (void)memcpy(&hci_cmd_buffer[pos], ptr, 240);
pos += 240; pos += 240;
break; break;
case 'N': { // UTF-8 string, null terminated case 'N': { // UTF-8 string, null terminated
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
uint16_t len = strlen((const char*) ptr); uint16_t len = strlen((const char*) ptr);
if (len > 248u) { if (len > 248u) {
len = 248; len = 248;
@ -143,20 +150,20 @@ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *
break; break;
} }
case 'P': // 16 byte PIN code or link key in little endian case 'P': // 16 byte PIN code or link key in little endian
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
(void)memcpy(&hci_cmd_buffer[pos], ptr, 16); (void)memcpy(&hci_cmd_buffer[pos], ptr, 16);
pos += 16; pos += 16;
break; break;
#ifdef ENABLE_BLE #ifdef ENABLE_BLE
case 'A': // 31 bytes advertising data case 'A': // 31 bytes advertising data
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
(void)memcpy(&hci_cmd_buffer[pos], ptr, 31); (void)memcpy(&hci_cmd_buffer[pos], ptr, 31);
pos += 31; pos += 31;
break; break;
#endif #endif
#ifdef ENABLE_SDP #ifdef ENABLE_SDP
case 'S': { // Service Record (Data Element Sequence) case 'S': { // Service Record (Data Element Sequence)
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
uint16_t len = de_get_len(ptr); uint16_t len = de_get_len(ptr);
(void)memcpy(&hci_cmd_buffer[pos], ptr, len); (void)memcpy(&hci_cmd_buffer[pos], ptr, len);
pos += len; pos += len;
@ -165,13 +172,13 @@ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *
#endif #endif
#ifdef ENABLE_LE_SECURE_CONNECTIONS #ifdef ENABLE_LE_SECURE_CONNECTIONS
case 'Q': case 'Q':
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
reverse_bytes(ptr, &hci_cmd_buffer[pos], 32); reverse_bytes(ptr, &hci_cmd_buffer[pos], 32);
pos += 32; pos += 32;
break; break;
#endif #endif
case 'K': // 16 byte OOB Data or Link Key in big endian case 'K': // 16 byte OOB Data or Link Key in big endian
ptr = va_arg(argptr, uint8_t *); ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE
reverse_bytes(ptr, &hci_cmd_buffer[pos], 16); reverse_bytes(ptr, &hci_cmd_buffer[pos], 16);
pos += 16; pos += 16;
break; break;