Skip to content

Commit a15115a

Browse files
author
Khang Nguyen
committed
mctpd: Send Discovery Notify on Endpoint role set
Implement the first step of partial discovery, which is notifying the bus owner of our presence on the bus. Tested: Discovery Notify message is sent when setting role on interface. Jul 15 08:33:42 evb-endpoint mctpd[3322]: mctpd: read_message got from sockaddr_mctp_ext eid 8 net 1 type 0x00 if 2 hw len 2 0x80:08 len 3 Jul 15 08:33:42 evb-endpoint mctpd[3322]: mctpd: Failure completion code 0x05 from physaddr if 2 hw len 2 0x00:00 Jul 15 08:33:42 evb-endpoint mctpd[3322]: mctpd: Warning: discovery notify on interface 'mctppcie0' failed: Connection refused (My Root Complex does not handle Discovery Notify message yet, but can confirm that the message is sent) Signed-off-by: Khang Nguyen Duy <[email protected]>
1 parent f84314f commit a15115a

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
5. mctpd: New test infrastructure for control procotol messaging to mctpd
1616
6. mctpd: Add a configuration file facility, defaulting to /etc/mctpd.conf.
1717
7. mctpd: Add mctp/interfaces/<name> D-Bus object
18+
8. mctpd: Send Discovery Notify on Endpoint role set
1819

1920
### Changed
2021

src/mctpd.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,49 @@ static int bus_link_get_prop(sd_bus *bus,
28932893
return rc;
28942894
}
28952895

2896+
static int notify_discovery(ctx *ctx, int ifindex)
2897+
{
2898+
int rc = 0;
2899+
dest_phys desti = { 0 }, *dest = &desti;
2900+
struct mctp_ctrl_cmd_discovery_notify req = { 0 };
2901+
struct mctp_ctrl_resp_discovery_notify *resp;
2902+
uint8_t *buf;
2903+
size_t buf_size;
2904+
struct sockaddr_mctp_ext resp_addr;
2905+
2906+
dest->ifindex = ifindex;
2907+
assert(mctp_nl_ifaddr_byindex(ctx->nl, dest->ifindex,
2908+
&dest->hwaddr_len));
2909+
memset(dest->hwaddr, 0, sizeof dest->hwaddr);
2910+
2911+
req.ctrl_hdr.command_code = MCTP_CTRL_CMD_DISCOVERY_NOTIFY;
2912+
req.ctrl_hdr.rq_dgram_inst = RQDI_REQ;
2913+
2914+
rc = endpoint_query_phys(ctx, dest, MCTP_CTRL_HDR_MSG_TYPE, &req,
2915+
sizeof(req), &buf, &buf_size, &resp_addr);
2916+
if (rc < 0)
2917+
goto free_buf;
2918+
2919+
if (buf_size != sizeof(*resp)) {
2920+
warnx("%s: wrong reply length %zu bytes. dest %s", __func__,
2921+
buf_size, dest_phys_tostr(dest));
2922+
rc = -ENOMSG;
2923+
goto free_buf;
2924+
}
2925+
resp = (void *)buf;
2926+
2927+
if (resp->completion_code != 0) {
2928+
// TODO: make this a debug message?
2929+
warnx("Failure completion code 0x%02x from %s",
2930+
resp->completion_code, dest_phys_tostr(dest));
2931+
rc = -ECONNREFUSED;
2932+
goto free_buf;
2933+
}
2934+
free_buf:
2935+
free(buf);
2936+
return rc;
2937+
}
2938+
28962939
static int bus_link_set_prop(sd_bus *bus,
28972940
const char *path, const char *interface, const char *property,
28982941
sd_bus_message *value, void *userdata, sd_bus_error *berr)
@@ -2904,6 +2947,7 @@ static int bus_link_set_prop(sd_bus *bus,
29042947
link_userdata *lmUserData;
29052948
int rc;
29062949
struct role role;
2950+
int ifindex;
29072951

29082952
if (!is_interfaces_path(path)) {
29092953
sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
@@ -2919,11 +2963,13 @@ static int bus_link_set_prop(sd_bus *bus,
29192963
goto out;
29202964
}
29212965

2922-
lmUserData = mctp_nl_get_link_userdata_byname(ctx->nl, link_name);
2923-
if (!lmUserData) {
2966+
ifindex = mctp_nl_ifindex_byname(ctx->nl, link_name);
2967+
if (!ifindex) {
29242968
rc = -ENOENT;
29252969
goto out;
29262970
}
2971+
lmUserData = mctp_nl_get_link_userdata(ctx->nl, ifindex);
2972+
assert(lmUserData);
29272973

29282974
if (strcmp(property, "Role") != 0) {
29292975
printf("Unknown property '%s' for %s iface %s\n", property, path, interface);
@@ -2954,6 +3000,16 @@ static int bus_link_set_prop(sd_bus *bus,
29543000
}
29553001
lmUserData->role = role.role;
29563002

3003+
// Announce on the bus we are endpoint, print warning and ignore error if failed
3004+
if (lmUserData->role == ENDPOINT_ROLE_ENDPOINT) {
3005+
rc = notify_discovery(ctx, ifindex);
3006+
if (rc) {
3007+
warnx("Warning: discovery notify on interface '%s' failed: %s", link_name,
3008+
strerror(-rc));
3009+
rc = 0;
3010+
}
3011+
}
3012+
29573013
out:
29583014
set_berr(ctx, rc, berr);
29593015
return rc;

0 commit comments

Comments
 (0)