Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/classic/hfp_hf.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
}


static void hfp_hf_emit_enhanced_voice_recognition_text(hfp_connection_t * hfp_connection){

Check warning on line 252 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "hfp_connection" is "struct hfp_connection *".

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6TV&open=AZ0aS-mbuBFMN0bhY6TV&pullRequest=549
btstack_assert(hfp_connection != NULL);
uint8_t event[HFP_MAX_VR_TEXT_SIZE + 11];
int pos = 0;
Expand Down Expand Up @@ -314,7 +314,7 @@
const int size = sizeof(buffer);
int offset = snprintf(buffer, size, "AT%s=", HFP_AVAILABLE_CODECS);
offset += join(buffer+offset, size-offset, hfp_hf_codecs, hfp_hf_codecs_nr);
offset += snprintf(buffer+offset, size-offset, "\r");

Check warning on line 317 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'offset' is never read

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Ti&open=AZ0aS-mbuBFMN0bhY6Ti&pullRequest=549
return send_str_over_rfcomm(cid, buffer);
}

Expand All @@ -323,7 +323,7 @@
const int size = sizeof(buffer);
int offset = snprintf(buffer, size, "AT%s=", HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
offset += join_bitmap(buffer+offset, size-offset, indicators_status, indicators_nr);
offset += snprintf(buffer+offset, size-offset, "\r");

Check warning on line 326 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'offset' is never read

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tj&open=AZ0aS-mbuBFMN0bhY6Tj&pullRequest=549
return send_str_over_rfcomm(cid, buffer);
}

Expand All @@ -332,7 +332,7 @@
const int size = sizeof(buffer);
int offset = snprintf(buffer, size, "AT%s=", HFP_GENERIC_STATUS_INDICATOR);
offset += join(buffer+offset, size-offset, hfp_hf_indicators, hfp_hf_indicators_nr);
offset += snprintf(buffer+offset, size-offset, "\r");

Check warning on line 335 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'offset' is never read

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tk&open=AZ0aS-mbuBFMN0bhY6Tk&pullRequest=549
return send_str_over_rfcomm(cid, buffer);
}

Expand Down Expand Up @@ -549,7 +549,7 @@
return done;
}

static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connection){

Check failure on line 552 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 35 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6TX&open=AZ0aS-mbuBFMN0bhY6TX&pullRequest=549
if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) {
return 0;
}
Expand All @@ -575,7 +575,7 @@
}
switch(hfp_connection->ag_vra_state){
case HFP_VOICE_RECOGNITION_STATE_AG_READY:
switch (hfp_connection->ag_vra_status){

Check failure on line 578 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6TY&open=AZ0aS-mbuBFMN0bhY6TY&pullRequest=549
case 0:
hfp_connection->vra_state_requested = HFP_VRA_W4_VOICE_RECOGNITION_OFF;
break;
Expand Down Expand Up @@ -751,7 +751,7 @@
static void hfp_hf_run_for_context(hfp_connection_t * hfp_connection){

btstack_assert(hfp_connection != NULL);
btstack_assert(hfp_connection->local_role == HFP_ROLE_HF);

Check failure on line 754 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Access to field 'local_role' results in a dereference of a null pointer (loaded from variable 'hfp_connection')

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tl&open=AZ0aS-mbuBFMN0bhY6Tl&pullRequest=549

// during SDP query, RFCOMM CID is not set
if (hfp_connection->rfcomm_cid == 0) return;
Expand Down Expand Up @@ -1046,7 +1046,7 @@
int i;
for (i=0; i < hfp_hf_indicators_nr; i++){
if (get_bit(hfp_connection->generic_status_update_bitmap, i)){
if (hfp_connection->generic_status_indicators[i].state){

Check failure on line 1049 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6TZ&open=AZ0aS-mbuBFMN0bhY6TZ&pullRequest=549
hfp_connection->ok_pending = 1;
hfp_connection->generic_status_update_bitmap = store_bit(hfp_connection->generic_status_update_bitmap, i, 0);
char buffer[30];
Expand Down Expand Up @@ -1135,7 +1135,7 @@
}
}

static bool hfp_hf_switch_on_ok_pending(hfp_connection_t *hfp_connection, uint8_t status){

Check failure on line 1138 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 30 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Ta&open=AZ0aS-mbuBFMN0bhY6Ta&pullRequest=549
bool event_emited = true;

// cache state and reset
Expand Down Expand Up @@ -1270,7 +1270,7 @@
}
}

static void hfp_hf_handle_transfer_ag_indicator_status(hfp_connection_t * hfp_connection) {

Check failure on line 1273 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 28 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tb&open=AZ0aS-mbuBFMN0bhY6Tb&pullRequest=549
uint16_t i;

for (i = 0; i < hfp_connection->ag_indicators_nr; i++){
Expand All @@ -1279,7 +1279,7 @@
hfp_callsetup_status_t new_hf_callsetup_status = (hfp_callsetup_status_t) hfp_connection->ag_indicators[i].status;
bool ringing_old = hfp_is_ringing(hfp_hf_callsetup_status);
bool ringing_new = hfp_is_ringing(new_hf_callsetup_status);
if (ringing_old != ringing_new){

Check failure on line 1282 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tc&open=AZ0aS-mbuBFMN0bhY6Tc&pullRequest=549
if (ringing_new){
hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_START_RINGING);
} else {
Expand All @@ -1293,7 +1293,7 @@
(void) hfp_hf_callheld_status;
} else if (strcmp(hfp_connection->ag_indicators[i].name, "call") == 0){
hfp_call_status_t new_hf_call_status = (hfp_call_status_t) hfp_connection->ag_indicators[i].status;
if (hfp_hf_call_status != new_hf_call_status){

Check failure on line 1296 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Td&open=AZ0aS-mbuBFMN0bhY6Td&pullRequest=549
if (new_hf_call_status == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS){
hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_CALL_TERMINATED);
} else {
Expand Down Expand Up @@ -1379,7 +1379,7 @@
}

// handle error response for voice activation (HF initiated)
switch(hfp_connection->vra_state_requested){

Check warning on line 1382 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this "switch" statement by "if" statements to increase readability.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Te&open=AZ0aS-mbuBFMN0bhY6Te&pullRequest=549
case HFP_VRA_W4_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO:
hfp_emit_enhanced_voice_recognition_hf_ready_for_audio_event(hfp_connection, ERROR_CODE_UNSPECIFIED_ERROR);
break;
Expand Down Expand Up @@ -1453,7 +1453,7 @@

// process messages byte-wise
uint8_t pos;
for (pos = 0; pos < size; pos++){

Check warning on line 1456 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declare the variable "pos" inside the loop.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tf&open=AZ0aS-mbuBFMN0bhY6Tf&pullRequest=549
hfp_parse(hfp_connection, packet[pos], 1);
// parse until end of line "\r" or "\n"
if (!hfp_parser_is_end_of_line(packet[pos])) continue;
Expand Down Expand Up @@ -1556,10 +1556,7 @@
btstack_assert(codecs_nr <= HFP_MAX_NUM_CODECS);

hfp_hf_codecs_nr = codecs_nr;
int i;
for (i=0; i<codecs_nr; i++){
hfp_hf_codecs[i] = codecs[i];
}
memcpy(hfp_hf_codecs, codecs, codecs_nr);

Check failure on line 1559 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Memory copy function overflows the destination buffer

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tm&open=AZ0aS-mbuBFMN0bhY6Tm&pullRequest=549
}

void hfp_hf_init_supported_features(uint32_t supported_features){
Expand All @@ -1571,7 +1568,7 @@

hfp_hf_indicators_nr = indicators_nr;
int i;
for (i = 0; i < hfp_hf_indicators_nr ; i++){

Check warning on line 1571 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declare the variable "i" inside the loop.

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Tg&open=AZ0aS-mbuBFMN0bhY6Tg&pullRequest=549
hfp_hf_indicators[i] = (uint8_t) indicators[i];
}
}
Expand Down Expand Up @@ -1953,7 +1950,7 @@
return ERROR_CODE_SUCCESS;
}

static bool hfp_hf_echo_canceling_and_noise_reduction_supported(hfp_connection_t * hfp_connection){

Check warning on line 1953 in src/classic/hfp_hf.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "hfp_connection" is "struct hfp_connection *".

See more on https://sonarcloud.io/project/issues?id=bluekitchen_btstack&issues=AZ0aS-mbuBFMN0bhY6Th&open=AZ0aS-mbuBFMN0bhY6Th&pullRequest=549
int ag = get_bit(hfp_connection->remote_supported_features, HFP_AGSF_EC_NR_FUNCTION);
int hf = get_bit(hfp_hf_supported_features, HFP_HFSF_EC_NR_FUNCTION);
return hf && ag;
Expand Down