Skip to content

Commit 3f9ec21

Browse files
Add Bridge Endpoint Support
* Update peer structure to accomodate for Bridge Type Endpoints. * New Dbus argument in AssignStaticEndpoint dbus method to consider bridge/pool start eid. * update existing pytest methods to account for new signature of AssignEndpointStatic dbus method for pool start eid Signed-off-by: Faizan Ali <[email protected]>
1 parent b274f0d commit 3f9ec21

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

docs/mctpd.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,18 @@ Similar to SetupEndpoint, but will always assign an EID rather than querying for
123123
existing ones. Will return `new = false` when an endpoint is already known to
124124
`mctpd`.
125125

126-
#### `.AssignEndpointStatic`: `ayy``yisb`
126+
#### `.AssignEndpointStatic`: `ayyy``yisb`
127127

128128
Similar to AssignEndpoint, but takes an additional EID argument:
129129

130130
```
131-
AssignEndpointStatic <hwaddr> <static-EID>
131+
AssignEndpointStatic <hwaddr> <static-EID> <pool_start-EID>
132132
```
133133

134134
to assign `<static-EID>` to the endpoint with hardware address `hwaddr`.
135135

136+
For MCTP Bridges `<pool_start-EID>` will be starting eid assigned for downstream devices. For non-bridge devices this argument value will be zero.
137+
136138
This call will fail if the endpoint already has an EID, and that EID is
137139
different from `static-EID`, or if `static-EID` is already assigned to another
138140
endpoint.

src/mctpd.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ struct peer {
177177
uint8_t endpoint_type;
178178
uint8_t medium_spec;
179179
} recovery;
180+
181+
// Pool size
182+
uint8_t pool_size;
183+
uint8_t pool_start;
184+
180185
};
181186
typedef struct peer peer;
182187

@@ -1313,7 +1318,7 @@ static int endpoint_query_phys(ctx *ctx, const dest_phys *dest,
13131318
}
13141319

13151320
/* returns -ECONNREFUSED if the endpoint returns failure. */
1316-
static int endpoint_send_set_endpoint_id(const peer *peer, mctp_eid_t *new_eid)
1321+
static int endpoint_send_set_endpoint_id(peer *peer, mctp_eid_t *new_eid)
13171322
{
13181323
struct sockaddr_mctp_ext addr;
13191324
struct mctp_ctrl_cmd_set_eid req = {0};
@@ -1360,9 +1365,11 @@ static int endpoint_send_set_endpoint_id(const peer *peer, mctp_eid_t *new_eid)
13601365

13611366
alloc = resp->status & 0x3;
13621367
if (alloc != 0) {
1363-
// TODO for bridges
1364-
warnx("%s requested allocation pool, unimplemented",
1365-
dest_phys_tostr(dest));
1368+
peer->pool_size = resp->eid_pool_size;
1369+
if (peer->ctx->verbose) {
1370+
warnx("%s requested allocation of pool size = %d",
1371+
dest_phys_tostr(dest), peer->pool_size);
1372+
}
13661373
}
13671374

13681375
rc = 0;
@@ -2114,7 +2121,7 @@ static int method_assign_endpoint_static(sd_bus_message *call, void *data,
21142121
char *peer_path = NULL;
21152122
peer *peer = NULL;
21162123
ctx *ctx = data;
2117-
uint8_t eid;
2124+
uint8_t eid, start_eid;
21182125
int rc;
21192126

21202127
dest->ifindex = interface_call_to_ifindex_busowner(ctx, call);
@@ -2130,6 +2137,10 @@ static int method_assign_endpoint_static(sd_bus_message *call, void *data,
21302137
if (rc < 0)
21312138
goto err;
21322139

2140+
rc = sd_bus_message_read(call, "y", &start_eid);
2141+
if (rc < 0)
2142+
goto err;
2143+
21332144
rc = validate_dest_phys(ctx, dest);
21342145
if (rc < 0)
21352146
return sd_bus_error_setf(berr, SD_BUS_ERROR_INVALID_ARGS,
@@ -2173,6 +2184,11 @@ static int method_assign_endpoint_static(sd_bus_message *call, void *data,
21732184
}
21742185
dfree(peer_path);
21752186

2187+
/* MCTP Bridge Support */
2188+
if(peer->pool_size > 0) {
2189+
peer->pool_start = start_eid;
2190+
}
2191+
21762192
return sd_bus_reply_method_return(call, "yisb",
21772193
peer->eid, peer->net, peer_path, 1);
21782194
err:
@@ -2852,9 +2868,10 @@ static const sd_bus_vtable bus_owner_vtable[] = {
28522868
0),
28532869

28542870
SD_BUS_METHOD_WITH_NAMES("AssignEndpointStatic",
2855-
"ayy",
2871+
"ayyy",
28562872
SD_BUS_PARAM(physaddr)
2857-
SD_BUS_PARAM(eid),
2873+
SD_BUS_PARAM(eid)
2874+
SD_BUS_PARAM(start_eid),
28582875
"yisb",
28592876
SD_BUS_PARAM(eid)
28602877
SD_BUS_PARAM(net)

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ def to_buf(self):
248248
return bytes([flags, self.cmd]) + self.data
249249

250250
class Endpoint:
251-
def __init__(self, iface, lladdr, ep_uuid = None, eid = 0, types = None):
251+
def __init__(self, iface, lladdr, ep_uuid = None, eid = 0, types = None, pool_size = 0):
252252
self.iface = iface
253253
self.lladdr = lladdr
254254
self.uuid = ep_uuid or uuid.uuid1()
255255
self.eid = eid
256256
self.types = types or [0]
257+
self.pool_size = pool_size
257258
# keyed by (type, type-specific-instance)
258259
self.commands = {}
259260

@@ -291,6 +292,10 @@ async def handle_mctp_control(self, sock, addr, data):
291292
(op, eid) = data[2:]
292293
self.eid = eid
293294
data = bytes(hdr + [0x00, 0x00, self.eid, 0x00])
295+
if (self.pool_size):
296+
data = bytes(hdr + [0x00, 0x01, self.eid, self.pool_size])
297+
else:
298+
data = bytes(hdr + [0x00, 0x00, self.eid, 0x00])
294299
await sock.send(raddr, data)
295300

296301
elif opcode == 2:

tests/test_mctpd.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,12 @@ async def test_assign_endpoint_static(dbus, mctpd):
287287
dev = mctpd.network.endpoints[0]
288288
mctp = await mctpd_mctp_iface_obj(dbus, iface)
289289
static_eid = 12
290+
start_eid = 0
290291

291292
(eid, _, _, new) = await mctp.call_assign_endpoint_static(
292293
dev.lladdr,
293-
static_eid
294+
static_eid,
295+
start_eid
294296
)
295297

296298
assert eid == static_eid
@@ -309,10 +311,12 @@ async def test_assign_endpoint_static_allocated(dbus, mctpd):
309311
mctp = await mctpd_mctp_iface_obj(dbus, iface)
310312
dev = mctpd.network.endpoints[0]
311313
static_eid = 12
314+
start_eid = 0
312315

313316
(eid, _, _, new) = await mctp.call_assign_endpoint_static(
314317
dev.lladdr,
315318
static_eid,
319+
start_eid
316320
)
317321

318322
assert eid == static_eid
@@ -322,6 +326,7 @@ async def test_assign_endpoint_static_allocated(dbus, mctpd):
322326
(eid, _, _, new) = await mctp.call_assign_endpoint_static(
323327
dev.lladdr,
324328
static_eid,
329+
start_eid
325330
)
326331

327332
assert eid == static_eid
@@ -345,7 +350,7 @@ async def test_assign_endpoint_static_conflict(dbus, mctpd):
345350

346351
# try to assign dev2 with the dev1's existing EID
347352
with pytest.raises(asyncdbus.errors.DBusError) as ex:
348-
await mctp.call_assign_endpoint_static(dev2.lladdr, eid)
353+
await mctp.call_assign_endpoint_static(dev2.lladdr, eid, 0)
349354

350355
assert str(ex.value) == "Address in use"
351356

@@ -356,17 +361,19 @@ async def test_assign_endpoint_static_varies(dbus, mctpd):
356361
dev = mctpd.network.endpoints[0]
357362
mctp = await mctpd_mctp_iface_obj(dbus, iface)
358363
static_eid = 12
364+
start_eid = 0
359365

360366
(eid, _, _, new) = await mctp.call_assign_endpoint_static(
361367
dev.lladdr,
362-
static_eid
368+
static_eid,
369+
start_eid
363370
)
364371

365372
assert eid == static_eid
366373
assert new
367374

368375
with pytest.raises(asyncdbus.errors.DBusError) as ex:
369-
await mctp.call_assign_endpoint_static(dev.lladdr, 13)
376+
await mctp.call_assign_endpoint_static(dev.lladdr, 13, 0)
370377

371378
assert str(ex.value) == "Already assigned a different EID"
372379

0 commit comments

Comments
 (0)