Skip to content

Commit

Permalink
pmc: add a command to select the target port.
Browse files Browse the repository at this point in the history
This patch adds a new pmc command called "target" that lets the user
address a particular clock and port. Previously all management requests
were sent to the wild card address.

Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Jul 22, 2013
1 parent 923ff5b commit a3762c5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,19 @@ static int parse_id(char *s)
return index;
}

static int parse_target(const char *str)
{
struct PortIdentity pid;

if (str[0] == '*') {
memset(&pid, 0xff, sizeof(pid));
} else if (str2pid(str, &pid)) {
return -1;
}

return pmc_target(pmc, &pid);
}

static void print_help(FILE *fp)
{
int i;
Expand All @@ -608,6 +621,9 @@ static void print_help(FILE *fp)
fprintf(fp, "\tThe [action] can be GET, SET, CMD, or COMMAND\n");
fprintf(fp, "\tCommands are case insensitive and may be abbreviated.\n");
fprintf(fp, "\n");
fprintf(fp, "\tTARGET [portIdentity]\n");
fprintf(fp, "\tTARGET *\n");
fprintf(fp, "\n");
}

static int do_command(char *str)
Expand All @@ -623,6 +639,9 @@ static int do_command(char *str)
if (2 != sscanf(str, " %10s %64s", action_str, id_str))
return -1;

if (0 == strncasecmp(action_str, "TARGET", strlen(action_str)))
return parse_target(id_str);

action = parse_action(action_str);
id = parse_id(id_str);

Expand Down
16 changes: 16 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ char *pid2str(struct PortIdentity *id)
return buf;
}

int str2pid(const char *s, struct PortIdentity *result)
{
struct PortIdentity pid;
unsigned char *ptr = pid.clockIdentity.id;
int c;
c = sscanf(s, " %02hhx%02hhx%02hhx.%02hhx%02hhx.%02hhx%02hhx%02hhx-%hu",
&ptr[0], &ptr[1], &ptr[2], &ptr[3],
&ptr[4], &ptr[5], &ptr[6], &ptr[7],
&pid.portNumber);
if (c == 9) {
*result = pid;
return 0;
}
return -1;
}

int generate_clock_identity(struct ClockIdentity *ci, char *name)
{
unsigned char mac[6];
Expand Down
9 changes: 9 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ char *cid2str(struct ClockIdentity *id);
*/
char *pid2str(struct PortIdentity *id);

/**
* Scan a string containing a port identity and convert it into binary form.
*
* @param s String in human readable form.
* @param result Pointer to a buffer to hold the result.
* @return Zero on success, or -1 if the string is incorrectly formatted.
*/
int str2pid(const char *s, struct PortIdentity *result);

int generate_clock_identity(struct ClockIdentity *ci, char *name);

/**
Expand Down

0 comments on commit a3762c5

Please sign in to comment.