Skip to content

Commit 2370286

Browse files
author
Khang Nguyen
committed
mctpd: Add bus owner and endpoint switch using arguments
Currently, mctpd defaults to run as a bus owner, so ctx->bus_owner is always true. This commit adds a role argument so that we can change the role without editing the source code. Tested: Send a Get EID command to mctpd. See the response: - Running as Bus Owner (no flag): 00 00 02 00 ee 12 00 - Running as Endpoint (-r endpoint): 00 00 02 00 ee 02 00 The second to last byte signifies the endpoint type. (0xee is the EID assigned to mctpd) Signed-off-by: Khang Nguyen <[email protected]>
1 parent 237fa96 commit 2370286

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/mctpd.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -3074,10 +3074,11 @@ static int setup_testing(ctx *ctx) {
30743074

30753075
static void print_usage(ctx *ctx)
30763076
{
3077-
fprintf(stderr, "mctpd [-v] [-N] [-t usecs]\n");
3077+
fprintf(stderr, "mctpd [-v] [-N] [-t usecs] [-r {bus-owner,endpoint}]\n");
30783078
fprintf(stderr, " -v verbose\n");
30793079
fprintf(stderr, " -N testing mode. Not safe for production\n");
30803080
fprintf(stderr, " -t timeout in usecs\n");
3081+
fprintf(stderr, " -r role of mctpd in the network\n");
30813082
}
30823083

30833084
static int parse_args(ctx *ctx, int argc, char **argv)
@@ -3087,15 +3088,17 @@ static int parse_args(ctx *ctx, int argc, char **argv)
30873088
{ .name = "verbose", .has_arg = no_argument, .val = 'v' },
30883089
{ .name = "testing", .has_arg = no_argument, .val = 'N' },
30893090
{ .name = "timeout", .has_arg = required_argument, .val = 't' },
3091+
{ .name = "role", .has_arg = required_argument, .val = 'r' },
30903092
{ 0 },
30913093
};
30923094
int c;
30933095

30943096
// default values
30953097
ctx->mctp_timeout = 250000; // 250ms
3098+
ctx->bus_owner = true;
30963099

30973100
for (;;) {
3098-
c = getopt_long(argc, argv, "+hvNt:", options, NULL);
3101+
c = getopt_long(argc, argv, "+hvNt:r:", options, NULL);
30993102
if (c == -1)
31003103
break;
31013104

@@ -3113,6 +3116,16 @@ static int parse_args(ctx *ctx, int argc, char **argv)
31133116
return errno;
31143117
}
31153118
break;
3119+
case 'r':
3120+
if (!strcmp(optarg, "bus-owner"))
3121+
ctx->bus_owner = true;
3122+
else if (!strcmp(optarg, "endpoint"))
3123+
ctx->bus_owner = false;
3124+
else {
3125+
warnx("Role can only be one of: bus-owner, endpoint");
3126+
return -EINVAL;
3127+
}
3128+
break;
31163129
case 'h':
31173130
default:
31183131
print_usage(ctx);
@@ -3149,8 +3162,6 @@ static int fill_uuid(ctx *ctx)
31493162
static int setup_config(ctx *ctx)
31503163
{
31513164
int rc;
3152-
// TODO: this will go in a config file or arguments.
3153-
ctx->bus_owner = true;
31543165
rc = fill_uuid(ctx);
31553166
if (rc < 0)
31563167
return rc;

0 commit comments

Comments
 (0)