@@ -1018,16 +1018,57 @@ static int net_id_adv(struct bt_mesh_subnet *sub)
1018
1018
return 0 ;
1019
1019
}
1020
1020
1021
- static s32_t gatt_proxy_advertise (void )
1021
+ static bool advertise_subnet (struct bt_mesh_subnet * sub )
1022
+ {
1023
+ if (sub -> net_idx == BT_MESH_KEY_UNUSED ) {
1024
+ return false;
1025
+ }
1026
+
1027
+ return (sub -> node_id == BT_MESH_NODE_IDENTITY_RUNNING ||
1028
+ bt_mesh_gatt_proxy_get () == BT_MESH_GATT_PROXY_ENABLED );
1029
+ }
1030
+
1031
+ static struct bt_mesh_subnet * next_sub (void )
1032
+ {
1033
+ static int next_idx ;
1034
+ int i ;
1035
+
1036
+ for (i = 0 ; i < ARRAY_SIZE (bt_mesh .sub ); i ++ ) {
1037
+ struct bt_mesh_subnet * sub ;
1038
+
1039
+ sub = & bt_mesh .sub [(i + next_idx ) % ARRAY_SIZE (bt_mesh .sub )];
1040
+ if (advertise_subnet (sub )) {
1041
+ next_idx = (next_idx + 1 ) % ARRAY_SIZE (bt_mesh .sub );
1042
+ return sub ;
1043
+ }
1044
+ }
1045
+
1046
+ return NULL ;
1047
+ }
1048
+
1049
+ static int sub_count (void )
1050
+ {
1051
+ int i , count = 0 ;
1052
+
1053
+ for (i = 0 ; i < ARRAY_SIZE (bt_mesh .sub ); i ++ ) {
1054
+ struct bt_mesh_subnet * sub = & bt_mesh .sub [i ];
1055
+
1056
+ if (advertise_subnet (sub )) {
1057
+ count ++ ;
1058
+ }
1059
+ }
1060
+
1061
+ return count ;
1062
+ }
1063
+
1064
+ static s32_t gatt_proxy_advertise (struct bt_mesh_subnet * sub )
1022
1065
{
1023
- /* TODO: Add support for multiple subnets */
1024
- struct bt_mesh_subnet * sub = & bt_mesh .sub [0 ];
1025
1066
s32_t remaining = K_FOREVER ;
1026
1067
1027
1068
BT_DBG ("" );
1028
1069
1029
- if (sub -> net_idx == BT_MESH_KEY_UNUSED ) {
1030
- BT_WARN ("First subnet is not valid " );
1070
+ if (! sub ) {
1071
+ BT_WARN ("No subnets to advertise on " );
1031
1072
return remaining ;
1032
1073
}
1033
1074
@@ -1046,11 +1087,20 @@ static s32_t gatt_proxy_advertise(void)
1046
1087
}
1047
1088
}
1048
1089
1049
- if (sub -> node_id == BT_MESH_NODE_IDENTITY_STOPPED &&
1050
- bt_mesh_gatt_proxy_get () == BT_MESH_GATT_PROXY_ENABLED ) {
1051
- net_id_adv (sub );
1090
+ if (sub -> node_id == BT_MESH_NODE_IDENTITY_STOPPED ) {
1091
+ if (bt_mesh_gatt_proxy_get () == BT_MESH_GATT_PROXY_ENABLED ) {
1092
+ net_id_adv (sub );
1093
+ } else {
1094
+ return gatt_proxy_advertise (next_sub ());
1095
+ }
1096
+ }
1097
+
1098
+ if (sub_count () > 1 && (remaining > K_SECONDS (10 ) || remaining < 0 )) {
1099
+ remaining = K_SECONDS (10 );
1052
1100
}
1053
1101
1102
+ BT_DBG ("Advertising %d ms for net_idx 0x%04x" , remaining , sub -> net_idx );
1103
+
1054
1104
return remaining ;
1055
1105
}
1056
1106
#endif /* GATT_PROXY */
@@ -1088,7 +1138,7 @@ s32_t bt_mesh_proxy_adv_start(void)
1088
1138
1089
1139
#if defined(CONFIG_BT_MESH_GATT_PROXY )
1090
1140
if (bt_mesh_is_provisioned ()) {
1091
- return gatt_proxy_advertise ();
1141
+ return gatt_proxy_advertise (next_sub () );
1092
1142
}
1093
1143
#endif /* GATT_PROXY */
1094
1144
0 commit comments