hfp_hf.c (332ca98fda1296e6f80c1bbf4a598e99882ccff9) hfp_hf.c (1cc65c4fce14ad71d62f69eec6f702e5984158f4)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 457 unchanged lines hidden (view full) ---

466
467static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
468
469 if (hfp_connection->ok_pending) return 0;
470
471 if (hfp_connection->trigger_codec_exchange){
472 hfp_connection->trigger_codec_exchange = 0;
473
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 457 unchanged lines hidden (view full) ---

466
467static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
468
469 if (hfp_connection->ok_pending) return 0;
470
471 if (hfp_connection->trigger_codec_exchange){
472 hfp_connection->trigger_codec_exchange = 0;
473
474 hfp_connection->codec_confirmed = 0;
475 hfp_connection->suggested_codec = 0;
476 hfp_connection->negotiated_codec = 0;
477
478 hfp_connection->codecs_state = HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE;
479 hfp_connection->ok_pending = 1;
480 hfp_hf_cmd_trigger_codec_connection_setup(hfp_connection->rfcomm_cid);
481 return 1;
482 }
483
474 hfp_connection->ok_pending = 1;
475 hfp_hf_cmd_trigger_codec_connection_setup(hfp_connection->rfcomm_cid);
476 return 1;
477 }
478
484 switch (hfp_connection->command){
479 if (hfp_connection->hf_send_codec_confirm){
480 hfp_connection->hf_send_codec_confirm = false;
485
481
486 case HFP_CMD_AG_SUGGESTED_CODEC:{
487 if (hfp_supports_codec(hfp_connection->suggested_codec, hfp_codecs_nr, hfp_codecs)){
488 hfp_connection->codec_confirmed = hfp_connection->suggested_codec;
489 hfp_connection->ok_pending = 1;
490 hfp_connection->codecs_state = HFP_CODECS_HF_CONFIRMED_CODEC;
491 hfp_connection->negotiated_codec = hfp_connection->suggested_codec;
492 log_info("hfp: codec confirmed: %s", (hfp_connection->negotiated_codec == HFP_CODEC_MSBC) ? "mSBC" : "CVSD");
493 hfp_hf_cmd_confirm_codec(hfp_connection->rfcomm_cid, hfp_connection->codec_confirmed);
494 } else {
495 hfp_connection->codec_confirmed = 0;
496 hfp_connection->suggested_codec = 0;
497 hfp_connection->negotiated_codec = 0;
498 hfp_connection->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
499 hfp_connection->ok_pending = 1;
500 hfp_hf_cmd_notify_on_codecs(hfp_connection->rfcomm_cid);
482 hfp_connection->ok_pending = 1;
483 hfp_hf_cmd_confirm_codec(hfp_connection->rfcomm_cid, hfp_connection->codec_confirmed);
484 return 1;
485 }
501
486
502 }
503 break;
504 }
505 default:
506 break;
487 if (hfp_connection->hf_send_supported_codecs){
488 hfp_connection->hf_send_supported_codecs = false;
489
490 hfp_connection->ok_pending = 1;
491 hfp_hf_cmd_notify_on_codecs(hfp_connection->rfcomm_cid);
492 return 1;
507 }
493 }
494
508 return 0;
509}
510
511static int hfp_hf_run_for_audio_connection(hfp_connection_t * hfp_connection){
512 if ((hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) ||
513 (hfp_connection->state > HFP_W2_DISCONNECT_SCO)) return 0;
514
515 if (hfp_connection->release_audio_connection){

--- 343 unchanged lines hidden (view full) ---

859 // enable all indicators
860 int i;
861 for (i=0;i<hfp_indicators_nr;i++){
862 hfp_connection->generic_status_indicators[i].uuid = hfp_indicators[i];
863 hfp_connection->generic_status_indicators[i].state = 1;
864 }
865}
866
495 return 0;
496}
497
498static int hfp_hf_run_for_audio_connection(hfp_connection_t * hfp_connection){
499 if ((hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) ||
500 (hfp_connection->state > HFP_W2_DISCONNECT_SCO)) return 0;
501
502 if (hfp_connection->release_audio_connection){

--- 343 unchanged lines hidden (view full) ---

846 // enable all indicators
847 int i;
848 for (i=0;i<hfp_indicators_nr;i++){
849 hfp_connection->generic_status_indicators[i].uuid = hfp_indicators[i];
850 hfp_connection->generic_status_indicators[i].state = 1;
851 }
852}
853
854static void hfp_hf_handle_suggested_codec(hfp_connection_t * hfp_connection){
855 if (hfp_supports_codec(hfp_connection->suggested_codec, hfp_codecs_nr, hfp_codecs)){
856 // Codec supported, confirm
857 hfp_connection->negotiated_codec = hfp_connection->suggested_codec;
858 hfp_connection->codec_confirmed = hfp_connection->suggested_codec;
859 log_info("hfp: codec confirmed: %s", (hfp_connection->negotiated_codec == HFP_CODEC_MSBC) ? "mSBC" : "CVSD");
860 hfp_connection->codecs_state = HFP_CODECS_HF_CONFIRMED_CODEC;
861
862 hfp_connection->hf_send_codec_confirm = true;
863 } else {
864 // Codec not supported, send supported codecs
865 hfp_connection->codec_confirmed = 0;
866 hfp_connection->suggested_codec = 0;
867 hfp_connection->negotiated_codec = 0;
868 hfp_connection->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
869
870 hfp_connection->hf_send_supported_codecs = true;
871 }
872}
873
867static void hfp_hf_switch_on_ok(hfp_connection_t *hfp_connection){
868 hfp_connection->ok_pending = 0;
869 switch (hfp_connection->state){
870 case HFP_W4_EXCHANGE_SUPPORTED_FEATURES:
871 if (has_codec_negotiation_feature(hfp_connection)){
872 hfp_connection->state = HFP_NOTIFY_ON_CODECS;
873 break;
874 }

--- 187 unchanged lines hidden (view full) ---

1062 hfp_hf_handle_transfer_ag_indicator_status(hfp_connection);
1063 break;
1064 case HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS:
1065 for (i = 0; i < hfp_connection->ag_indicators_nr; i++){
1066 hfp_emit_ag_indicator_event(hfp_hf_callback, hfp_connection->ag_indicators[i]);
1067 }
1068 hfp_connection->command = HFP_CMD_NONE;
1069 break;
874static void hfp_hf_switch_on_ok(hfp_connection_t *hfp_connection){
875 hfp_connection->ok_pending = 0;
876 switch (hfp_connection->state){
877 case HFP_W4_EXCHANGE_SUPPORTED_FEATURES:
878 if (has_codec_negotiation_feature(hfp_connection)){
879 hfp_connection->state = HFP_NOTIFY_ON_CODECS;
880 break;
881 }

--- 187 unchanged lines hidden (view full) ---

1069 hfp_hf_handle_transfer_ag_indicator_status(hfp_connection);
1070 break;
1071 case HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS:
1072 for (i = 0; i < hfp_connection->ag_indicators_nr; i++){
1073 hfp_emit_ag_indicator_event(hfp_hf_callback, hfp_connection->ag_indicators[i]);
1074 }
1075 hfp_connection->command = HFP_CMD_NONE;
1076 break;
1077 case HFP_CMD_AG_SUGGESTED_CODEC:
1078 hfp_hf_handle_suggested_codec(hfp_connection);
1079 hfp_connection->command = HFP_CMD_NONE;
1080 break;
1070 default:
1071 break;
1072 }
1073}
1074
1075static int hfp_parser_is_end_of_line(uint8_t byte){
1076 return (byte == '\n') || (byte == '\r');
1077}

--- 211 unchanged lines hidden (view full) ---

1289 hfp_connection->negotiated_codec = hfp_connection->suggested_codec;
1290 hfp_init_link_settings(hfp_connection, hfp_hf_esco_s4_supported(hfp_connection));
1291 hfp_connection->state = HFP_W4_SCO_CONNECTED;
1292 } else {
1293 switch (hfp_connection->codecs_state){
1294 case HFP_CODECS_W4_AG_COMMON_CODEC:
1295 break;
1296 default:
1081 default:
1082 break;
1083 }
1084}
1085
1086static int hfp_parser_is_end_of_line(uint8_t byte){
1087 return (byte == '\n') || (byte == '\r');
1088}

--- 211 unchanged lines hidden (view full) ---

1300 hfp_connection->negotiated_codec = hfp_connection->suggested_codec;
1301 hfp_init_link_settings(hfp_connection, hfp_hf_esco_s4_supported(hfp_connection));
1302 hfp_connection->state = HFP_W4_SCO_CONNECTED;
1303 } else {
1304 switch (hfp_connection->codecs_state){
1305 case HFP_CODECS_W4_AG_COMMON_CODEC:
1306 break;
1307 default:
1308 hfp_connection->codec_confirmed = 0;
1309 hfp_connection->suggested_codec = 0;
1310 hfp_connection->negotiated_codec = 0;
1311 hfp_connection->codecs_state = HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE;
1297 hfp_connection->trigger_codec_exchange = 1;
1298 break;
1299 }
1300 }
1301
1302 hfp_run_for_context(hfp_connection);
1303}
1304

--- 455 unchanged lines hidden ---
1312 hfp_connection->trigger_codec_exchange = 1;
1313 break;
1314 }
1315 }
1316
1317 hfp_run_for_context(hfp_connection);
1318}
1319

--- 455 unchanged lines hidden ---