@@ -110,6 +110,23 @@ static struct pacs {
110
110
ATOMIC_DEFINE (flags , PACS_FLAG_NUM );
111
111
112
112
struct pacs_client clients [CONFIG_BT_MAX_PAIRED ];
113
+
114
+ struct bt_gatt_attr * available_ctx_attr ;
115
+ #if defined(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE )
116
+ struct bt_gatt_attr * supported_ctx_attr ;
117
+ #endif /* CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE */
118
+ #if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE )
119
+ struct bt_gatt_attr * snk_pac_attr ;
120
+ #endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE */
121
+ #if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE )
122
+ struct bt_gatt_attr * snk_pac_loc_attr ;
123
+ #endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */
124
+ #if defined(CONFIG_BT_PAC_SRC_NOTIFIABLE )
125
+ struct bt_gatt_attr * src_pac_attr ;
126
+ #endif /* CONFIG_BT_PAC_SRC_NOTIFIABLE */
127
+ #if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE )
128
+ struct bt_gatt_attr * src_pac_loc_attr ;
129
+ #endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
113
130
} pacs ;
114
131
115
132
@@ -860,6 +877,35 @@ int bt_pacs_register(const struct bt_pacs_register_param *param)
860
877
return - ENOEXEC ;
861
878
}
862
879
880
+ pacs .available_ctx_attr = bt_gatt_find_by_uuid (pacs_svc .attrs , pacs_svc .attr_count ,
881
+ BT_UUID_PACS_AVAILABLE_CONTEXT );
882
+ __ASSERT_NO_MSG (pacs .available_ctx_attr != NULL );
883
+ #if defined(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE )
884
+ pacs .supported_ctx_attr = bt_gatt_find_by_uuid (pacs_svc .attrs , pacs_svc .attr_count ,
885
+ BT_UUID_PACS_SUPPORTED_CONTEXT );
886
+ __ASSERT_NO_MSG (pacs .supported_ctx_attr != NULL );
887
+ #endif /* CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE */
888
+ #if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE )
889
+ pacs .snk_pac_attr =
890
+ bt_gatt_find_by_uuid (pacs_svc .attrs , pacs_svc .attr_count , BT_UUID_PACS_SNK );
891
+ __ASSERT_NO_MSG (pacs .snk_pac_attr != NULL );
892
+ #endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE */
893
+ #if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE )
894
+ pacs .snk_pac_loc_attr =
895
+ bt_gatt_find_by_uuid (pacs_svc .attrs , pacs_svc .attr_count , BT_UUID_PACS_SNK_LOC );
896
+ __ASSERT_NO_MSG (pacs .snk_pac_loc_attr != NULL );
897
+ #endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */
898
+ #if defined(CONFIG_BT_PAC_SRC_NOTIFIABLE )
899
+ pacs .src_pac_attr =
900
+ bt_gatt_find_by_uuid (pacs_svc .attrs , pacs_svc .attr_count , BT_UUID_PACS_SRC );
901
+ __ASSERT_NO_MSG (pacs .src_pac_attr != NULL );
902
+ #endif /* CONFIG_BT_PAC_SRC_NOTIFIABLE */
903
+ #if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE )
904
+ pacs .src_pac_loc_attr =
905
+ bt_gatt_find_by_uuid (pacs_svc .attrs , pacs_svc .attr_count , BT_UUID_PACS_SRC_LOC );
906
+ __ASSERT_NO_MSG (pacs .src_pac_loc_attr != NULL );
907
+ #endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
908
+
863
909
return 0 ;
864
910
}
865
911
@@ -1005,6 +1051,7 @@ static int available_contexts_notify(struct bt_conn *conn)
1005
1051
return 0 ;
1006
1052
}
1007
1053
1054
+ #if defined(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE )
1008
1055
static int supported_contexts_notify (struct bt_conn * conn )
1009
1056
{
1010
1057
struct bt_pacs_context context = {
@@ -1022,6 +1069,7 @@ static int supported_contexts_notify(struct bt_conn *conn)
1022
1069
}
1023
1070
return 0 ;
1024
1071
}
1072
+ #endif /* CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE */
1025
1073
1026
1074
void pacs_gatt_notify_complete_cb (struct bt_conn * conn , void * user_data )
1027
1075
{
@@ -1096,7 +1144,8 @@ static void notify_cb(struct bt_conn *conn, void *data)
1096
1144
}
1097
1145
1098
1146
#if defined(CONFIG_BT_PAC_SNK_NOTIFIABLE )
1099
- if (atomic_test_bit (client -> flags , FLAG_SINK_PAC_CHANGED )) {
1147
+ if (atomic_test_bit (client -> flags , FLAG_SINK_PAC_CHANGED ) &&
1148
+ bt_gatt_is_subscribed (conn , pacs .snk_pac_attr , BT_GATT_CCC_NOTIFY )) {
1100
1149
LOG_DBG ("Notifying Sink PAC" );
1101
1150
err = pac_notify (conn , BT_AUDIO_DIR_SINK );
1102
1151
if (!err ) {
@@ -1106,7 +1155,8 @@ static void notify_cb(struct bt_conn *conn, void *data)
1106
1155
#endif /* CONFIG_BT_PAC_SNK_NOTIFIABLE */
1107
1156
1108
1157
#if defined(CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE )
1109
- if (atomic_test_bit (client -> flags , FLAG_SINK_AUDIO_LOCATIONS_CHANGED )) {
1158
+ if (atomic_test_bit (client -> flags , FLAG_SINK_AUDIO_LOCATIONS_CHANGED ) &&
1159
+ bt_gatt_is_subscribed (conn , pacs .snk_pac_loc_attr , BT_GATT_CCC_NOTIFY )) {
1110
1160
LOG_DBG ("Notifying Sink Audio Location" );
1111
1161
err = pac_notify_loc (conn , BT_AUDIO_DIR_SINK );
1112
1162
if (!err ) {
@@ -1116,7 +1166,8 @@ static void notify_cb(struct bt_conn *conn, void *data)
1116
1166
#endif /* CONFIG_BT_PAC_SNK_LOC_NOTIFIABLE */
1117
1167
1118
1168
#if defined(CONFIG_BT_PAC_SRC_NOTIFIABLE )
1119
- if (atomic_test_bit (client -> flags , FLAG_SOURCE_PAC_CHANGED )) {
1169
+ if (atomic_test_bit (client -> flags , FLAG_SOURCE_PAC_CHANGED ) &&
1170
+ bt_gatt_is_subscribed (conn , pacs .src_pac_attr , BT_GATT_CCC_NOTIFY )) {
1120
1171
LOG_DBG ("Notifying Source PAC" );
1121
1172
err = pac_notify (conn , BT_AUDIO_DIR_SOURCE );
1122
1173
if (!err ) {
@@ -1126,7 +1177,8 @@ static void notify_cb(struct bt_conn *conn, void *data)
1126
1177
#endif /* CONFIG_BT_PAC_SRC_NOTIFIABLE */
1127
1178
1128
1179
#if defined(CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE )
1129
- if (atomic_test_and_clear_bit (client -> flags , FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED )) {
1180
+ if (atomic_test_bit (client -> flags , FLAG_SOURCE_AUDIO_LOCATIONS_CHANGED ) &&
1181
+ bt_gatt_is_subscribed (conn , pacs .src_pac_loc_attr , BT_GATT_CCC_NOTIFY )) {
1130
1182
LOG_DBG ("Notifying Source Audio Location" );
1131
1183
err = pac_notify_loc (conn , BT_AUDIO_DIR_SOURCE );
1132
1184
if (!err ) {
@@ -1135,22 +1187,25 @@ static void notify_cb(struct bt_conn *conn, void *data)
1135
1187
}
1136
1188
#endif /* CONFIG_BT_PAC_SRC_LOC_NOTIFIABLE */
1137
1189
1138
- if (atomic_test_bit (client -> flags , FLAG_AVAILABLE_AUDIO_CONTEXT_CHANGED )) {
1190
+ if (atomic_test_bit (client -> flags , FLAG_AVAILABLE_AUDIO_CONTEXT_CHANGED ) &&
1191
+ bt_gatt_is_subscribed (conn , pacs .available_ctx_attr , BT_GATT_CCC_NOTIFY )) {
1139
1192
LOG_DBG ("Notifying Available Contexts" );
1140
1193
err = available_contexts_notify (conn );
1141
1194
if (!err ) {
1142
1195
atomic_clear_bit (client -> flags , FLAG_AVAILABLE_AUDIO_CONTEXT_CHANGED );
1143
1196
}
1144
1197
}
1145
1198
1146
- if (IS_ENABLED (CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE ) &&
1147
- atomic_test_bit (client -> flags , FLAG_SUPPORTED_AUDIO_CONTEXT_CHANGED )) {
1199
+ #if defined(CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE )
1200
+ if (atomic_test_bit (client -> flags , FLAG_SUPPORTED_AUDIO_CONTEXT_CHANGED ) &&
1201
+ bt_gatt_is_subscribed (conn , pacs .supported_ctx_attr , BT_GATT_CCC_NOTIFY )) {
1148
1202
LOG_DBG ("Notifying Supported Contexts" );
1149
1203
err = supported_contexts_notify (conn );
1150
1204
if (!err ) {
1151
1205
atomic_clear_bit (client -> flags , FLAG_SUPPORTED_AUDIO_CONTEXT_CHANGED );
1152
1206
}
1153
1207
}
1208
+ #endif /* CONFIG_BT_PACS_SUPPORTED_CONTEXT_NOTIFIABLE */
1154
1209
}
1155
1210
1156
1211
static void deferred_nfy_work_handler (struct k_work * work )
0 commit comments