41
41
#define min (a , b ) ((a) < (b) ? (a) : (b))
42
42
43
43
#define MCTP_DBUS_PATH "/au/com/codeconstruct/mctp1"
44
+ #define MCTP_DBUS_PATH_NETWORKS "/au/com/codeconstruct/mctp1/networks"
44
45
#define CC_MCTP_DBUS_IFACE_BUSOWNER "au.com.codeconstruct.MCTP.BusOwner1.DRAFT"
45
46
#define CC_MCTP_DBUS_IFACE_ENDPOINT "au.com.codeconstruct.MCTP.Endpoint1"
46
47
#define CC_MCTP_DBUS_IFACE_TESTING "au.com.codeconstruct.MCTPTesting"
@@ -2908,6 +2909,20 @@ static int bus_endpoint_find_uuid(sd_bus *bus, const char *path,
2908
2909
return 0 ;
2909
2910
}
2910
2911
2912
+ static char * root_endpoints_path (int net )
2913
+ {
2914
+ size_t l ;
2915
+ char * buf = NULL ;
2916
+
2917
+ l = strlen (MCTP_DBUS_PATH ) + 30 ;
2918
+ buf = malloc (l );
2919
+ if (!buf ) {
2920
+ return NULL ;
2921
+ }
2922
+ snprintf (buf , l , "%s/networks/%d/endpoints" , MCTP_DBUS_PATH , net );
2923
+ return buf ;
2924
+ }
2925
+
2911
2926
static char * net_path (int net )
2912
2927
{
2913
2928
size_t l ;
@@ -3005,29 +3020,75 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path,
3005
3020
3006
3021
// NULL terminator
3007
3022
num_nodes = 1 ;
3008
- // .../mctp object
3023
+ // .../mctp1 object
3024
+ num_nodes ++ ;
3025
+ // .../mctp1/networks object
3009
3026
num_nodes ++ ;
3010
3027
3028
+ // .../mctp1/networks/<NetID>
3029
+ for (i = 0 ; i < ctx -> num_nets ; i ++ ) {
3030
+ num_nodes ++ ;
3031
+ for (size_t t = 0 ; t < 256 ; t ++ ) {
3032
+ if (ctx -> nets [i ].peeridx [t ] != -1 ) {
3033
+ // .../mctp1/networks/<NetID>/endpoints object
3034
+ num_nodes ++ ;
3035
+ break ;
3036
+ }
3037
+ }
3038
+ }
3039
+
3040
+ // .../mctp1/networks/<NetID>/endpoints/<EID> object
3011
3041
for (i = 0 ; i < ctx -> size_peers ; i ++ )
3012
3042
if (ctx -> peers [i ].published )
3013
3043
num_nodes ++ ;
3014
3044
3015
- num_nodes += ctx -> num_nets ;
3016
-
3017
3045
nodes = malloc (sizeof (* nodes ) * num_nodes );
3018
3046
if (!nodes ) {
3019
3047
rc = - ENOMEM ;
3020
3048
goto out ;
3021
3049
}
3022
3050
3023
3051
j = 0 ;
3052
+ // .../mctp1
3024
3053
nodes [j ] = strdup (MCTP_DBUS_PATH );
3025
3054
if (!nodes [j ]) {
3026
3055
rc = - ENOMEM ;
3027
3056
goto out ;
3028
3057
}
3029
3058
j ++ ;
3030
3059
3060
+ // .../mctp1/networks
3061
+ nodes [j ] = strdup (MCTP_DBUS_PATH_NETWORKS );
3062
+ if (!nodes [j ]) {
3063
+ rc = - ENOMEM ;
3064
+ goto out ;
3065
+ }
3066
+ j ++ ;
3067
+
3068
+ for (i = 0 ; i < ctx -> num_nets ; i ++ ) {
3069
+ // .../mctp1/networks/<NetId>
3070
+ nodes [j ] = net_path (ctx -> nets [i ].net );
3071
+ if (nodes [j ] == NULL ) {
3072
+ rc = - ENOMEM ;
3073
+ goto out ;
3074
+ }
3075
+ j ++ ;
3076
+
3077
+ for (size_t t = 0 ; t < 256 ; t ++ ) {
3078
+ if (ctx -> nets [i ].peeridx [t ] == -1 ) {
3079
+ continue ;
3080
+ }
3081
+ // .../mctp1/networks/<NetID>/endpoints object
3082
+ nodes [j ] = root_endpoints_path (ctx -> nets [i ].net );
3083
+ if (nodes [j ] == NULL ) {
3084
+ rc = - ENOMEM ;
3085
+ goto out ;
3086
+ }
3087
+ j ++ ;
3088
+ break ;
3089
+ }
3090
+ }
3091
+
3031
3092
// Peers
3032
3093
for (i = 0 ; i < ctx -> size_peers ; i ++ ) {
3033
3094
peer * peer = & ctx -> peers [i ];
@@ -3041,16 +3102,6 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path,
3041
3102
j ++ ;
3042
3103
}
3043
3104
3044
- // Nets
3045
- for (i = 0 ; i < ctx -> num_nets ; i ++ ) {
3046
- nodes [j ] = net_path (ctx -> nets [i ].net );
3047
- if (nodes [j ] == NULL ) {
3048
- rc = - ENOMEM ;
3049
- goto out ;
3050
- }
3051
- j ++ ;
3052
- }
3053
-
3054
3105
// NULL terminator
3055
3106
nodes [j ] = NULL ;
3056
3107
j ++ ;
0 commit comments