@@ -73,6 +73,11 @@ static struct bt_hfp_ag bt_hfp_ag_pool[CONFIG_BT_MAX_CONN];
73
73
74
74
static struct bt_hfp_ag_cb * bt_ag ;
75
75
76
+ #define AG_SUPT_FEAT (ag , _feature ) ((ag->ag_features & (_feature)) != 0)
77
+ #define HF_SUPT_FEAT (ag , _feature ) ((ag->hf_features & (_feature)) != 0)
78
+ #define BOTH_SUPT_FEAT (ag , _hf_feature , _ag_feature ) \
79
+ (HF_SUPT_FEAT(ag, _hf_feature) && AG_SUPT_FEAT(ag, _ag_feature))
80
+
76
81
/* Sent but not acknowledged TX packets with a callback */
77
82
static struct bt_ag_tx ag_tx [CONFIG_BT_HFP_AG_TX_BUF_COUNT * 2 ];
78
83
static K_FIFO_DEFINE (ag_tx_free );
@@ -953,8 +958,7 @@ static int bt_hfp_ag_bac_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
953
958
return - ENOTSUP ;
954
959
}
955
960
956
- if (!(ag -> hf_features & BT_HFP_HF_FEATURE_CODEC_NEG ) ||
957
- !(ag -> ag_features & BT_HFP_AG_FEATURE_CODEC_NEG )) {
961
+ if (!BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_CODEC_NEG , BT_HFP_AG_FEATURE_CODEC_NEG )) {
958
962
return - ENOEXEC ;
959
963
}
960
964
@@ -1057,7 +1061,7 @@ static void bt_hfp_ag_set_in_band_ring(struct bt_hfp_ag *ag, void *user_data)
1057
1061
{
1058
1062
bool is_inband_ringtone ;
1059
1063
1060
- is_inband_ringtone = (ag -> ag_features & BT_HFP_AG_FEATURE_INBAND_RINGTONE ) ? true : false;
1064
+ is_inband_ringtone = AG_SUPT_FEAT (ag , BT_HFP_AG_FEATURE_INBAND_RINGTONE ) ? true : false;
1061
1065
1062
1066
if (is_inband_ringtone && !atomic_test_bit (ag -> flags , BT_HFP_AG_INBAND_RING )) {
1063
1067
int err = hfp_ag_send_data (ag , NULL , NULL , "\r\n+BSIR:1\r\n" );
@@ -1108,8 +1112,7 @@ static int bt_hfp_ag_cmer_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
1108
1112
1109
1113
if (number == 1 ) {
1110
1114
atomic_set_bit (ag -> flags , BT_HFP_AG_CMER_ENABLE );
1111
- if ((ag -> hf_features & BT_HFP_HF_FEATURE_3WAY_CALL ) &&
1112
- (ag -> ag_features & BT_HFP_AG_FEATURE_3WAY_CALL )) {
1115
+ if (BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_3WAY_CALL , BT_HFP_AG_FEATURE_3WAY_CALL )) {
1113
1116
LOG_DBG ("Waiting for AT+CHLD=?" );
1114
1117
return 0 ;
1115
1118
}
@@ -1513,8 +1516,7 @@ static int bt_hfp_ag_chld_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
1513
1516
int err ;
1514
1517
char * response ;
1515
1518
1516
- if (!((ag -> ag_features & BT_HFP_AG_FEATURE_3WAY_CALL ) &&
1517
- (ag -> hf_features & BT_HFP_HF_FEATURE_3WAY_CALL ))) {
1519
+ if (!BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_3WAY_CALL , BT_HFP_AG_FEATURE_3WAY_CALL )) {
1518
1520
return - ENOEXEC ;
1519
1521
}
1520
1522
@@ -1569,8 +1571,7 @@ static int bt_hfp_ag_bind_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
1569
1571
char * data ;
1570
1572
uint32_t len ;
1571
1573
1572
- if (!((ag -> ag_features & BT_HFP_AG_FEATURE_HF_IND ) &&
1573
- (ag -> hf_features & BT_HFP_HF_FEATURE_HF_IND ))) {
1574
+ if (!BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_HF_IND , BT_HFP_AG_FEATURE_HF_IND )) {
1574
1575
return - ENOEXEC ;
1575
1576
}
1576
1577
@@ -2527,8 +2528,8 @@ static int bt_hfp_ag_outgoing_call(struct bt_hfp_ag *ag, const char *number, uin
2527
2528
2528
2529
if (call_count ) {
2529
2530
#if defined(CONFIG_BT_HFP_AG_3WAY_CALL )
2530
- if (!(( ag -> ag_features & BT_HFP_AG_FEATURE_3WAY_CALL ) &&
2531
- ( ag -> hf_features & BT_HFP_HF_FEATURE_3WAY_CALL ) )) {
2531
+ if (!BOTH_SUPT_FEAT ( ag , BT_HFP_HF_FEATURE_3WAY_CALL ,
2532
+ BT_HFP_AG_FEATURE_3WAY_CALL )) {
2532
2533
return - ENOEXEC ;
2533
2534
}
2534
2535
@@ -2723,7 +2724,7 @@ static int bt_hfp_ag_nrec_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
2723
2724
return - ENOTSUP ;
2724
2725
}
2725
2726
2726
- if (!(ag -> ag_features & BT_HFP_AG_SDP_FEATURE_3WAY_CALL )) {
2727
+ if (!AG_SUPT_FEAT (ag , BT_HFP_AG_FEATURE_ECNR )) {
2727
2728
return - ENOTSUP ;
2728
2729
}
2729
2730
@@ -2883,8 +2884,7 @@ static int bt_hfp_ag_ccwa_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
2883
2884
int err ;
2884
2885
uint32_t value ;
2885
2886
2886
- if (!((ag -> ag_features & BT_HFP_AG_FEATURE_3WAY_CALL ) &&
2887
- (ag -> hf_features & BT_HFP_HF_FEATURE_3WAY_CALL ))) {
2887
+ if (!BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_3WAY_CALL , BT_HFP_AG_FEATURE_3WAY_CALL )) {
2888
2888
return - ENOEXEC ;
2889
2889
}
2890
2890
@@ -2913,8 +2913,8 @@ static void bt_hfp_ag_vr_activate(struct bt_hfp_ag *ag, void *user_data)
2913
2913
{
2914
2914
bool feature ;
2915
2915
2916
- feature = (ag -> ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG ) &&
2917
- ( ag -> hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG );
2916
+ feature = BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_ENH_VOICE_RECG ,
2917
+ BT_HFP_AG_FEATURE_ENH_VOICE_RECG );
2918
2918
2919
2919
#if defined(CONFIG_BT_HFP_AG_VOICE_RECG )
2920
2920
if (bt_ag && bt_ag -> voice_recognition ) {
@@ -2960,8 +2960,7 @@ static int bt_hfp_ag_bvra_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
2960
2960
int err ;
2961
2961
uint32_t value ;
2962
2962
2963
- if (!((ag -> ag_features & BT_HFP_AG_FEATURE_VOICE_RECG ) &&
2964
- (ag -> hf_features & BT_HFP_HF_FEATURE_VOICE_RECG ))) {
2963
+ if (!BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_VOICE_RECG , BT_HFP_AG_FEATURE_VOICE_RECG )) {
2965
2964
return - ENOEXEC ;
2966
2965
}
2967
2966
@@ -2995,8 +2994,8 @@ static int bt_hfp_ag_bvra_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
2995
2994
err = hfp_ag_next_step (ag , bt_hfp_ag_vr_activate , NULL );
2996
2995
break ;
2997
2996
case BT_HFP_BVRA_READY_TO_ACCEPT :
2998
- if (!(( ag -> ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG ) &&
2999
- ( ag -> hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG ) )) {
2997
+ if (!BOTH_SUPT_FEAT ( ag , BT_HFP_HF_FEATURE_ENH_VOICE_RECG ,
2998
+ BT_HFP_AG_FEATURE_ENH_VOICE_RECG )) {
3000
2999
LOG_WRN ("Enhance voice recognition is not supported" );
3001
3000
return - ENOEXEC ;
3002
3001
}
@@ -3021,7 +3020,7 @@ static int bt_hfp_ag_binp_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
3021
3020
char * number = NULL ;
3022
3021
#endif /* CONFIG_BT_HFP_AG_VOICE_TAG */
3023
3022
3024
- if (!(ag -> ag_features & BT_HFP_AG_FEATURE_VOICE_TAG )) {
3023
+ if (!AG_SUPT_FEAT (ag , BT_HFP_AG_FEATURE_VOICE_TAG )) {
3025
3024
return - ENOEXEC ;
3026
3025
}
3027
3026
@@ -3830,8 +3829,8 @@ int bt_hfp_ag_remote_incoming(struct bt_hfp_ag *ag, const char *number)
3830
3829
call_count = get_none_released_calls (ag );
3831
3830
if (call_count ) {
3832
3831
#if defined(CONFIG_BT_HFP_AG_3WAY_CALL )
3833
- if (!(( ag -> ag_features & BT_HFP_AG_FEATURE_3WAY_CALL ) &&
3834
- ( ag -> hf_features & BT_HFP_HF_FEATURE_3WAY_CALL ) )) {
3832
+ if (!BOTH_SUPT_FEAT ( ag , BT_HFP_HF_FEATURE_3WAY_CALL ,
3833
+ BT_HFP_AG_FEATURE_3WAY_CALL )) {
3835
3834
LOG_WRN ("3 Way call feature is not supported on both sides" );
3836
3835
return - ENOEXEC ;
3837
3836
}
@@ -3957,7 +3956,7 @@ int bt_hfp_ag_reject(struct bt_hfp_ag_call *call)
3957
3956
return - EINVAL ;
3958
3957
}
3959
3958
3960
- if (!(ag -> ag_features & BT_HFP_AG_FEATURE_REJECT_CALL )) {
3959
+ if (!AG_SUPT_FEAT (ag , BT_HFP_AG_FEATURE_REJECT_CALL )) {
3961
3960
LOG_ERR ("AG has not ability to reject call" );
3962
3961
return - ENOTSUP ;
3963
3962
}
@@ -4564,7 +4563,7 @@ int bt_hfp_ag_vgm(struct bt_hfp_ag *ag, uint8_t vgm)
4564
4563
}
4565
4564
hfp_ag_unlock (ag );
4566
4565
4567
- if (!(ag -> hf_features & BT_HFP_HF_FEATURE_VOLUME )) {
4566
+ if (!HF_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_VOLUME )) {
4568
4567
LOG_ERR ("Remote Audio Volume Control is unsupported" );
4569
4568
return - ENOTSUP ;
4570
4569
}
@@ -4599,7 +4598,7 @@ int bt_hfp_ag_vgs(struct bt_hfp_ag *ag, uint8_t vgs)
4599
4598
}
4600
4599
hfp_ag_unlock (ag );
4601
4600
4602
- if (!(ag -> hf_features & BT_HFP_HF_FEATURE_VOLUME )) {
4601
+ if (!HF_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_VOLUME )) {
4603
4602
LOG_ERR ("Remote Audio Volume Control is unsupported" );
4604
4603
return - ENOTSUP ;
4605
4604
}
@@ -4667,8 +4666,8 @@ int bt_hfp_ag_voice_recognition(struct bt_hfp_ag *ag, bool activate)
4667
4666
return - ENOTSUP ;
4668
4667
}
4669
4668
4670
- feature = (ag -> ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG ) &&
4671
- ( ag -> hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG );
4669
+ feature = BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_ENH_VOICE_RECG ,
4670
+ BT_HFP_AG_FEATURE_ENH_VOICE_RECG );
4672
4671
if (!feature ) {
4673
4672
bvra = "" ;
4674
4673
} else {
@@ -4713,8 +4712,8 @@ int bt_hfp_ag_vre_state(struct bt_hfp_ag *ag, uint8_t state)
4713
4712
return - EINVAL ;
4714
4713
}
4715
4714
4716
- feature = (ag -> ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG ) &&
4717
- ( ag -> hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG );
4715
+ feature = BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_ENH_VOICE_RECG ,
4716
+ BT_HFP_AG_FEATURE_ENH_VOICE_RECG );
4718
4717
if (!feature ) {
4719
4718
return - ENOTSUP ;
4720
4719
}
@@ -4762,14 +4761,14 @@ int bt_hfp_ag_vre_textual_representation(struct bt_hfp_ag *ag, uint8_t state, co
4762
4761
return - EINVAL ;
4763
4762
}
4764
4763
4765
- feature = (ag -> ag_features & BT_HFP_AG_FEATURE_ENH_VOICE_RECG ) &&
4766
- ( ag -> hf_features & BT_HFP_HF_FEATURE_ENH_VOICE_RECG );
4764
+ feature = BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_ENH_VOICE_RECG ,
4765
+ BT_HFP_AG_FEATURE_ENH_VOICE_RECG );
4767
4766
if (!feature ) {
4768
4767
return - ENOTSUP ;
4769
4768
}
4770
4769
4771
- feature = (ag -> ag_features & BT_HFP_AG_FEATURE_VOICE_RECG_TEXT ) &&
4772
- ( ag -> hf_features & BT_HFP_HF_FEATURE_VOICE_RECG_TEXT );
4770
+ feature = BOTH_SUPT_FEAT (ag , BT_HFP_HF_FEATURE_VOICE_RECG_TEXT ,
4771
+ BT_HFP_AG_FEATURE_VOICE_RECG_TEXT );
4773
4772
if (!feature ) {
4774
4773
return - ENOTSUP ;
4775
4774
}
0 commit comments