Skip to content

Commit d441a00

Browse files
ThuBaNguyenjk-ozlabs
authored andcommitted
mctpd: enumerate /networks and /endpoints object paths
Enumerate the parent D-Bus object path `.../mctp1/networks` for the network paths `.../mctp1/networks/<NetID>` and `.../mctp1/networks/<NetID>/endpoints` for the endpoints path `.../mctp1/networks/<NetID>/endpoints/<EID>`. Tested: Check the MCTP D-Bus interface: ``` busctl tree au.com.codeconstruct.MCTP1 `- /au `- /au/com `- /au/com/codeconstruct `- /au/com/codeconstruct/mctp1 `- /au/com/codeconstruct/mctp1/networks `- /au/com/codeconstruct/mctp1/networks/1 `- /au/com/codeconstruct/mctp1/networks/1/endpoints `- /au/com/codeconstruct/mctp1/networks/1/endpoints/8 ``` Signed-off-by: Thu Nguyen <[email protected]> Signed-off-by: Jeremy Kerr <[email protected]>
1 parent 9b4eabc commit d441a00

File tree

1 file changed

+64
-13
lines changed

1 file changed

+64
-13
lines changed

src/mctpd.c

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define min(a, b) ((a) < (b) ? (a) : (b))
4242

4343
#define MCTP_DBUS_PATH "/au/com/codeconstruct/mctp1"
44+
#define MCTP_DBUS_PATH_NETWORKS "/au/com/codeconstruct/mctp1/networks"
4445
#define CC_MCTP_DBUS_IFACE_BUSOWNER "au.com.codeconstruct.MCTP.BusOwner1.DRAFT"
4546
#define CC_MCTP_DBUS_IFACE_ENDPOINT "au.com.codeconstruct.MCTP.Endpoint1"
4647
#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,
29082909
return 0;
29092910
}
29102911

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+
29112926
static char* net_path(int net)
29122927
{
29132928
size_t l;
@@ -3005,29 +3020,75 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path,
30053020

30063021
// NULL terminator
30073022
num_nodes = 1;
3008-
// .../mctp object
3023+
// .../mctp1 object
3024+
num_nodes++;
3025+
// .../mctp1/networks object
30093026
num_nodes++;
30103027

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
30113041
for (i = 0; i < ctx->size_peers; i++)
30123042
if (ctx->peers[i].published)
30133043
num_nodes++;
30143044

3015-
num_nodes += ctx->num_nets;
3016-
30173045
nodes = malloc(sizeof(*nodes) * num_nodes);
30183046
if (!nodes) {
30193047
rc = -ENOMEM;
30203048
goto out;
30213049
}
30223050

30233051
j = 0;
3052+
// .../mctp1
30243053
nodes[j] = strdup(MCTP_DBUS_PATH);
30253054
if (!nodes[j]) {
30263055
rc = -ENOMEM;
30273056
goto out;
30283057
}
30293058
j++;
30303059

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+
30313092
// Peers
30323093
for (i = 0; i < ctx->size_peers; i++) {
30333094
peer *peer = &ctx->peers[i];
@@ -3041,16 +3102,6 @@ static int mctpd_dbus_enumerate(sd_bus *bus, const char* path,
30413102
j++;
30423103
}
30433104

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-
30543105
// NULL terminator
30553106
nodes[j] = NULL;
30563107
j++;

0 commit comments

Comments
 (0)