- Use /dev/fwX.Y rather than /dev/fwX.

- Add option -u to specify bus number.
- Try to open the device only if it's necessary.
This commit is contained in:
simokawa 2003-08-05 03:26:14 +00:00
parent 81a2a9698b
commit 23d1d988ed
2 changed files with 71 additions and 31 deletions

View File

@ -32,6 +32,7 @@
.Nd FireWire control utility .Nd FireWire control utility
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl u Ar bus_num
.Op Fl rt .Op Fl rt
.Op Fl c Ar node .Op Fl c Ar node
.Op Fl d Ar node .Op Fl d Ar node
@ -54,6 +55,8 @@ will output a list of devices that are/were connected to the bus.
.Pp .Pp
The following options are available: The following options are available:
.Bl -tag -width indent .Bl -tag -width indent
.It Fl u Ar bus_num
Specify the FireWire bus number to be operated.
.It Fl r .It Fl r
Initiate bus reset. Initiate bus reset.
.It Fl t .It Fl t
@ -123,7 +126,7 @@ with
.Dq Li bs=144000 . .Dq Li bs=144000 .
.Sh FILES .Sh FILES
.Bl -tag .Bl -tag
.It Pa /dev/fw0 .It Pa /dev/fw0.0
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr firewire 4 , .Xr firewire 4 ,

View File

@ -57,8 +57,10 @@ static void
usage(void) usage(void)
{ {
fprintf(stderr, fprintf(stderr,
"fwcontrol [-g gap_count] [-o node] [-b pri_req] [-c node]" "fwcontrol [-u bus_num] [-rt] [-g gap_count] [-o node] "
" [-r] [-t] [-d node] [-l file] [-R file] [-S file]\n" "[-b pri_req] [-c node] [-d node] [-l file] "
"[-R file] [-S file]\n"
"\t-u: specify bus number\n"
"\t-g: broadcast gap_count by phy_config packet\n" "\t-g: broadcast gap_count by phy_config packet\n"
"\t-o: send link-on packet to the node\n" "\t-o: send link-on packet to the node\n"
"\t-s: write RESET_START register on the node\n" "\t-s: write RESET_START register on the node\n"
@ -421,70 +423,105 @@ show_topology_map(int fd)
free(tmap); free(tmap);
} }
static void
open_dev(int *fd, char *devbase)
{
char devname[256];
int i;
if (*fd < 0) {
for (i = 0; i < 4; i++) {
snprintf(devname, sizeof(devname), "%s.%d", devbase, i);
if ((*fd = open(devname, O_RDWR)) >= 0)
break;
}
if (*fd < 0)
err(1, "open");
}
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char devname[256];
u_int32_t crom_buf[1024/4]; u_int32_t crom_buf[1024/4];
char devbase[1024] = "/dev/fw0";
int fd, i, tmp, ch, len=1024; int fd, i, tmp, ch, len=1024;
for (i = 0; i < 4; i++) { fd = -1;
snprintf(devname, sizeof(devname), "/dev/fw%d", i);
if ((fd = open(devname, O_RDWR)) >= 0)
break;
}
if (fd < 0)
err(1, "open");
if (argc < 2) { if (argc < 2) {
open_dev(&fd, devbase);
list_dev(fd); list_dev(fd);
} }
while ((ch = getopt(argc, argv, "g:o:s:b:rtc:d:l:R:S:")) != -1) while ((ch = getopt(argc, argv, "g:o:s:b:rtc:d:l:u:R:S:")) != -1)
switch(ch) { switch(ch) {
case 'g':
tmp = strtol(optarg, NULL, 0);
send_phy_config(fd, -1, tmp);
break;
case 'o':
tmp = strtol(optarg, NULL, 0);
send_link_on(fd, tmp);
break;
case 's':
tmp = strtol(optarg, NULL, 0);
reset_start(fd, tmp);
break;
case 'b': case 'b':
tmp = strtol(optarg, NULL, 0); tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
set_pri_req(fd, tmp); set_pri_req(fd, tmp);
break; break;
case 'r':
if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
err(1, "ioctl");
break;
case 't':
show_topology_map(fd);
break;
case 'c': case 'c':
tmp = strtol(optarg, NULL, 0); tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
get_crom(fd, tmp, crom_buf, len); get_crom(fd, tmp, crom_buf, len);
show_crom(crom_buf); show_crom(crom_buf);
break; break;
case 'd': case 'd':
tmp = strtol(optarg, NULL, 0); tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
get_crom(fd, tmp, crom_buf, len); get_crom(fd, tmp, crom_buf, len);
dump_crom(crom_buf); dump_crom(crom_buf);
break; break;
case 'g':
tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
send_phy_config(fd, -1, tmp);
break;
case 'l': case 'l':
load_crom(optarg, crom_buf); load_crom(optarg, crom_buf);
show_crom(crom_buf); show_crom(crom_buf);
break; break;
case 'o':
tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
send_link_on(fd, tmp);
break;
case 'r':
open_dev(&fd, devbase);
if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
err(1, "ioctl");
break;
case 's':
tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
reset_start(fd, tmp);
break;
case 't':
open_dev(&fd, devbase);
show_topology_map(fd);
break;
case 'u':
tmp = strtol(optarg, NULL, 0);
snprintf(devbase, sizeof(devbase), "/dev/fw%d", tmp);
if (fd > 0) {
close(fd);
fd = -1;
}
if (argc == optind) {
open_dev(&fd, devbase);
list_dev(fd);
}
break;
#define TAG (1<<6) #define TAG (1<<6)
#define CHANNEL 63 #define CHANNEL 63
case 'R': case 'R':
open_dev(&fd, devbase);
dvrecv(fd, optarg, TAG | CHANNEL, -1); dvrecv(fd, optarg, TAG | CHANNEL, -1);
break; break;
case 'S': case 'S':
open_dev(&fd, devbase);
dvsend(fd, optarg, TAG | CHANNEL, -1); dvsend(fd, optarg, TAG | CHANNEL, -1);
break; break;
default: default: