@@ -189,6 +189,11 @@ struct peer {
189
189
uint8_t endpoint_type ;
190
190
uint8_t medium_spec ;
191
191
} recovery ;
192
+
193
+ // Pool size
194
+ uint8_t pool_size ;
195
+ uint8_t pool_start ;
196
+
192
197
};
193
198
194
199
struct ctx {
@@ -1299,7 +1304,7 @@ static int endpoint_query_phys(struct ctx *ctx, const dest_phys *dest,
1299
1304
}
1300
1305
1301
1306
/* returns -ECONNREFUSED if the endpoint returns failure. */
1302
- static int endpoint_send_set_endpoint_id (const struct peer * peer , mctp_eid_t * new_eid )
1307
+ static int endpoint_send_set_endpoint_id (struct peer * peer , mctp_eid_t * new_eid )
1303
1308
{
1304
1309
struct sockaddr_mctp_ext addr ;
1305
1310
struct mctp_ctrl_cmd_set_eid req = {0 };
@@ -1346,9 +1351,11 @@ static int endpoint_send_set_endpoint_id(const struct peer *peer, mctp_eid_t *ne
1346
1351
1347
1352
alloc = resp -> status & 0x3 ;
1348
1353
if (alloc != 0 ) {
1349
- // TODO for bridges
1350
- warnx ("%s requested allocation pool, unimplemented" ,
1351
- dest_phys_tostr (dest ));
1354
+ peer -> pool_size = resp -> eid_pool_size ;
1355
+ if (peer -> ctx -> verbose ) {
1356
+ warnx ("%s requested allocation of pool size = %d" ,
1357
+ dest_phys_tostr (dest ), peer -> pool_size );
1358
+ }
1352
1359
}
1353
1360
1354
1361
rc = 0 ;
@@ -2201,6 +2208,95 @@ static int method_learn_endpoint(sd_bus_message *call, void *data, sd_bus_error
2201
2208
return rc ;
2202
2209
}
2203
2210
2211
+ static int method_assign_bridge_static (sd_bus_message * call , void * data ,
2212
+ sd_bus_error * berr )
2213
+ {
2214
+ char * peer_path = NULL ;
2215
+ dest_phys desti , * dest = & desti ;
2216
+ struct link * link = data ;
2217
+ struct ctx * ctx = link -> ctx ;
2218
+ struct peer * peer = NULL ;
2219
+ uint8_t eid , pool_start , pool_size ;
2220
+ int rc ;
2221
+
2222
+ dest -> ifindex = link -> ifindex ;
2223
+ if (dest -> ifindex <= 0 )
2224
+ return sd_bus_error_setf (berr , SD_BUS_ERROR_INVALID_ARGS ,
2225
+ "Unknown MCTP interface" );
2226
+
2227
+ rc = message_read_hwaddr (call , dest );
2228
+ if (rc < 0 )
2229
+ goto err ;
2230
+
2231
+ rc = sd_bus_message_read (call , "y" , & eid );
2232
+ if (rc < 0 )
2233
+ goto err ;
2234
+
2235
+ rc = sd_bus_message_read (call , "y" , & pool_start );
2236
+ if (rc < 0 )
2237
+ goto err ;
2238
+
2239
+ rc = sd_bus_message_read (call , "y" , & pool_size );
2240
+ if (rc < 0 )
2241
+ goto err ;
2242
+
2243
+ rc = validate_dest_phys (ctx , dest );
2244
+ if (rc < 0 )
2245
+ return sd_bus_error_setf (berr , SD_BUS_ERROR_INVALID_ARGS ,
2246
+ "Bad physaddr" );
2247
+
2248
+ peer = find_peer_by_phys (ctx , dest );
2249
+ if (peer ) {
2250
+ if (peer -> eid != eid ) {
2251
+ return sd_bus_error_setf (berr , SD_BUS_ERROR_INVALID_ARGS ,
2252
+ "Already assigned a different EID" );
2253
+ }
2254
+
2255
+ // Return existing record.
2256
+ peer_path = path_from_peer (peer );
2257
+ if (!peer_path )
2258
+ goto err ;
2259
+
2260
+ return sd_bus_reply_method_return (call , "yisb" ,
2261
+ peer -> eid , peer -> net , peer_path , 0 );
2262
+ } else {
2263
+ uint32_t netid ;
2264
+
2265
+ // is the requested EID already in use? if so, reject
2266
+ netid = mctp_nl_net_byindex (ctx -> nl , dest -> ifindex );
2267
+ peer = find_peer_by_addr (ctx , eid , netid );
2268
+ if (peer ) {
2269
+ return sd_bus_error_setf (berr , SD_BUS_ERROR_INVALID_ARGS ,
2270
+ "Address in use" );
2271
+ }
2272
+ }
2273
+
2274
+ rc = endpoint_assign_eid (ctx , berr , dest , & peer , eid );
2275
+ if (rc < 0 ) {
2276
+ goto err ;
2277
+ }
2278
+
2279
+ peer_path = path_from_peer (peer );
2280
+ if (!peer_path ) {
2281
+ goto err ;
2282
+ }
2283
+
2284
+ if (peer -> pool_size > 0 ) {
2285
+ peer -> pool_start = pool_start ;
2286
+ if (peer -> pool_size && peer -> pool_size > pool_size ) {
2287
+ peer -> pool_size = pool_size ;
2288
+
2289
+ //call for Allocate EndpointID
2290
+ }
2291
+ }
2292
+
2293
+ return sd_bus_reply_method_return (call , "yisb" ,
2294
+ peer -> eid , peer -> net , peer_path , 1 );
2295
+ err :
2296
+ set_berr (ctx , rc , berr );
2297
+ return rc ;
2298
+ }
2299
+
2204
2300
// Query various properties of a peer.
2205
2301
// To be called when a new peer is discovered/assigned, once an EID is known
2206
2302
// and routable.
@@ -2760,6 +2856,19 @@ static const sd_bus_vtable bus_link_owner_vtable[] = {
2760
2856
SD_BUS_PARAM (found ),
2761
2857
method_learn_endpoint ,
2762
2858
0 ),
2859
+ SD_BUS_METHOD_WITH_NAMES ("AssignBridgeStatic" ,
2860
+ "ayyyy" ,
2861
+ SD_BUS_PARAM (physaddr )
2862
+ SD_BUS_PARAM (eid )
2863
+ SD_BUS_PARAM (pool_start )
2864
+ SD_BUS_PARAM (pool_size ),
2865
+ "yisb" ,
2866
+ SD_BUS_PARAM (eid )
2867
+ SD_BUS_PARAM (net )
2868
+ SD_BUS_PARAM (path )
2869
+ SD_BUS_PARAM (new ),
2870
+ method_assign_bridge_static ,
2871
+ 0 ),
2763
2872
SD_BUS_VTABLE_END ,
2764
2873
2765
2874
};
0 commit comments