Deleted Added
sdiff udiff text old ( 146442 ) new ( 163712 )
full compact
1/*
2 * Copyright (C) 2002
3 * Hidetoshi Shimokawa. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 *
16 * This product includes software developed by Hidetoshi Shimokawa.
17 *
18 * 4. Neither the name of the author nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/usr.sbin/fwcontrol/fwcontrol.c 146442 2005-05-20 12:50:47Z charnier $");
37
38#include <sys/param.h>
39#include <sys/malloc.h>
40#include <sys/types.h>
41#include <sys/sysctl.h>
42#include <sys/socket.h>
43#include <sys/ioctl.h>
44#include <sys/errno.h>
45#include <sys/eui64.h>
46#include <dev/firewire/firewire.h>
47#include <dev/firewire/iec13213.h>
48#include <dev/firewire/fwphyreg.h>
49
50#include <netinet/in.h>
51#include <fcntl.h>
52#include <stdio.h>
53#include <err.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57
58extern int dvrecv(int, char *, char, int);
59extern int dvsend(int, char *, char, int);
60
61int sysctl_set_int(const char *, int);
62
63static void
64usage(void)
65{
66 fprintf(stderr,
67 "fwcontrol [-u bus_num] [-rt] [-g gap_count] [-o node] "
68 "[-b pri_req] [-c node] [-d node] [-l file] "
69 "[-R file] [-S file] [-m target]\n"
70 "\t-u: specify bus number\n"
71 "\t-g: broadcast gap_count by phy_config packet\n"
72 "\t-o: send link-on packet to the node\n"
73 "\t-s: write RESET_START register on the node\n"
74 "\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
75 "\t-c: read configuration ROM\n"
76 "\t-r: bus reset\n"
77 "\t-t: read topology map\n"
78 "\t-d: hex dump of configuration ROM\n"
79 "\t-l: load and parse hex dump file of configuration ROM\n"
80 "\t-R: Receive DV stream\n"
81 "\t-S: Send DV stream\n"
82 "\t-m: set fwmem target\n");
83 exit(0);
84}
85
86static void
87fweui2eui64(const struct fw_eui64 *fweui, struct eui64 *eui)
88{
89 *(u_int32_t*)&(eui->octet[0]) = htonl(fweui->hi);
90 *(u_int32_t*)&(eui->octet[4]) = htonl(fweui->lo);
91}
92
93static struct fw_devlstreq *
94get_dev(int fd)
95{
96 struct fw_devlstreq *data;
97
98 data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
99 if (data == NULL)
100 err(1, "malloc");
101 if( ioctl(fd, FW_GDEVLST, data) < 0) {
102 err(1, "ioctl");
103 }
104 return data;
105}
106
107static int
108str2node(int fd, const char *nodestr)
109{
110 struct eui64 eui, tmpeui;
111 struct fw_devlstreq *data;
112 char *endptr;
113 int i, node;
114
115 if (nodestr == '\0')
116 return (-1);
117
118 /*
119 * Deal with classic node specifications.
120 */
121 node = strtol(nodestr, &endptr, 0);
122 if (*endptr == '\0')
123 goto gotnode;
124
125 /*
126 * Try to get an eui and match it against available nodes.
127 */
128 if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
129 return (-1);
130
131 data = get_dev(fd);
132
133 for (i = 0; i < data->info_len; i++) {
134 fweui2eui64(&data->dev[i].eui, &tmpeui);
135 if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) {
136 node = data->dev[i].dst;
137 goto gotnode;
138 }
139 }
140 if (i >= data->info_len)
141 return (-1);
142
143gotnode:
144 if (node < 0 || node > 63)
145 return (-1);
146 else
147 return (node);
148}
149
150static void
151list_dev(int fd)
152{
153 struct fw_devlstreq *data;
154 struct fw_devinfo *devinfo;
155 struct eui64 eui;
156 char addr[EUI64_SIZ];
157 int i;
158
159 data = get_dev(fd);
160 printf("%d devices (info_len=%d)\n", data->n, data->info_len);
161 printf("node EUI64 status\n");
162 for (i = 0; i < data->info_len; i++) {
163 devinfo = &data->dev[i];
164 fweui2eui64(&devinfo->eui, &eui);
165 eui64_ntoa(&eui, addr, sizeof(addr));
166 printf("%4d %s %6d\n",
167 (devinfo->status || i == 0) ? devinfo->dst : -1,
168 addr,
169 devinfo->status
170 );
171 }
172 free((void *)data);
173}
174
175static u_int32_t
176read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_int32_t data)
177{
178 struct fw_asyreq *asyreq;
179 u_int32_t *qld, res;
180
181 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
182 asyreq->req.len = 16;
183#if 0
184 asyreq->req.type = FWASREQNODE;
185 asyreq->pkt.mode.rreqq.dst = FWLOCALBUS | node;
186#else
187 asyreq->req.type = FWASREQEUI;
188 asyreq->req.dst.eui = eui;
189#endif
190 asyreq->pkt.mode.rreqq.tlrt = 0;
191 if (readmode)
192 asyreq->pkt.mode.rreqq.tcode = FWTCODE_RREQQ;
193 else
194 asyreq->pkt.mode.rreqq.tcode = FWTCODE_WREQQ;
195
196 asyreq->pkt.mode.rreqq.dest_hi = 0xffff;
197 asyreq->pkt.mode.rreqq.dest_lo = addr_lo;
198
199 qld = (u_int32_t *)&asyreq->pkt;
200 if (!readmode)
201 asyreq->pkt.mode.wreqq.data = data;
202
203 if (ioctl(fd, FW_ASYREQ, asyreq) < 0) {
204 err(1, "ioctl");
205 }
206 res = qld[3];
207 free(asyreq);
208 if (readmode)
209 return ntohl(res);
210 else
211 return 0;
212}
213
214static void
215send_phy_config(int fd, int root_node, int gap_count)
216{
217 struct fw_asyreq *asyreq;
218
219 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
220 asyreq->req.len = 12;
221 asyreq->req.type = FWASREQNODE;
222 asyreq->pkt.mode.ld[0] = 0;
223 asyreq->pkt.mode.ld[1] = 0;
224 asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
225 if (root_node >= 0)
226 asyreq->pkt.mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
227 if (gap_count >= 0)
228 asyreq->pkt.mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
229 asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
230
231 printf("send phy_config root_node=%d gap_count=%d\n",
232 root_node, gap_count);
233
234 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
235 err(1, "ioctl");
236 free(asyreq);
237}
238
239static void
240send_link_on(int fd, int node)
241{
242 struct fw_asyreq *asyreq;
243
244 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
245 asyreq->req.len = 12;
246 asyreq->req.type = FWASREQNODE;
247 asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
248 asyreq->pkt.mode.ld[1] |= (1 << 30) | ((node & 0x3f) << 24);
249 asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
250
251 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
252 err(1, "ioctl");
253 free(asyreq);
254}
255
256static void
257reset_start(int fd, int node)
258{
259 struct fw_asyreq *asyreq;
260
261 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
262 asyreq->req.len = 16;
263 asyreq->req.type = FWASREQNODE;
264 asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f);
265 asyreq->pkt.mode.wreqq.tlrt = 0;
266 asyreq->pkt.mode.wreqq.tcode = FWTCODE_WREQQ;
267
268 asyreq->pkt.mode.wreqq.dest_hi = 0xffff;
269 asyreq->pkt.mode.wreqq.dest_lo = 0xf0000000 | RESET_START;
270
271 asyreq->pkt.mode.wreqq.data = htonl(0x1);
272
273 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
274 err(1, "ioctl");
275 free(asyreq);
276}
277
278static void
279set_pri_req(int fd, int pri_req)
280{
281 struct fw_devlstreq *data;
282 struct fw_devinfo *devinfo;
283 struct eui64 eui;
284 char addr[EUI64_SIZ];
285 u_int32_t max, reg, old;
286 int i;
287
288 data = get_dev(fd);
289#define BUGET_REG 0xf0000218
290 for (i = 0; i < data->info_len; i++) {
291 devinfo = &data->dev[i];
292 if (!devinfo->status)
293 continue;
294 reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0);
295 fweui2eui64(&devinfo->eui, &eui);
296 eui64_ntoa(&eui, addr, sizeof(addr));
297 printf("%d %s, %08x",
298 devinfo->dst, addr, reg);
299 if (reg > 0 && pri_req >= 0) {
300 old = (reg & 0x3f);
301 max = (reg & 0x3f00) >> 8;
302 if (pri_req > max)
303 pri_req = max;
304 printf(" 0x%x -> 0x%x\n", old, pri_req);
305 read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req);
306 } else {
307 printf("\n");
308 }
309 }
310 free((void *)data);
311}
312
313static void
314parse_bus_info_block(u_int32_t *p, int info_len)
315{
316 char addr[EUI64_SIZ];
317 struct bus_info *bi;
318 struct eui64 eui;
319
320 bi = (struct bus_info *)p;
321 fweui2eui64(&bi->eui64, &eui);
322 eui64_ntoa(&eui, addr, sizeof(addr));
323 printf("bus_name: 0x%04x\n"
324 "irmc:%d cmc:%d isc:%d bmc:%d pmc:%d\n"
325 "cyc_clk_acc:%d max_rec:%d max_rom:%d\n"
326 "generation:%d link_spd:%d\n"
327 "EUI64: %s\n",
328 bi->bus_name,
329 bi->irmc, bi->cmc, bi->isc, bi->bmc, bi->pmc,
330 bi->cyc_clk_acc, bi->max_rec, bi->max_rom,
331 bi->generation, bi->link_spd,
332 addr);
333}
334
335static int
336get_crom(int fd, int node, void *crom_buf, int len)
337{
338 struct fw_crom_buf buf;
339 int i, error;
340 struct fw_devlstreq *data;
341
342 data = get_dev(fd);
343
344 for (i = 0; i < data->info_len; i++) {
345 if (data->dev[i].dst == node && data->dev[i].eui.lo != 0)
346 break;
347 }
348 if (i == data->info_len)
349 errx(1, "no such node %d.", node);
350 else
351 buf.eui = data->dev[i].eui;
352 free((void *)data);
353
354 buf.len = len;
355 buf.ptr = crom_buf;
356 bzero(crom_buf, len);
357 if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) {
358 err(1, "ioctl");
359 }
360
361 return error;
362}
363
364static void
365show_crom(u_int32_t *crom_buf)
366{
367 int i;
368 struct crom_context cc;
369 char *desc, info[256];
370 static const char *key_types = "ICLD";
371 struct csrreg *reg;
372 struct csrdirectory *dir;
373 struct csrhdr *hdr;
374 u_int16_t crc;
375
376 printf("first quad: 0x%08x ", *crom_buf);
377 if (crom_buf[0] == 0) {
378 printf("(Invalid Configuration ROM)\n");
379 return;
380 }
381 hdr = (struct csrhdr *)crom_buf;
382 if (hdr->info_len == 1) {
383 /* minimum ROM */
384 reg = (struct csrreg *)hdr;
385 printf("verndor ID: 0x%06x\n", reg->val);
386 return;
387 }
388 printf("info_len=%d crc_len=%d crc=0x%04x",
389 hdr->info_len, hdr->crc_len, hdr->crc);
390 crc = crom_crc(crom_buf+1, hdr->crc_len);
391 if (crc == hdr->crc)
392 printf("(OK)\n");
393 else
394 printf("(NG)\n");
395 parse_bus_info_block(crom_buf+1, hdr->info_len);
396
397 crom_init_context(&cc, crom_buf);
398 dir = cc.stack[0].dir;
399 if (!dir) {
400 printf("no root directory - giving up\n");
401 return;
402 }
403 printf("root_directory: len=0x%04x(%d) crc=0x%04x",
404 dir->crc_len, dir->crc_len, dir->crc);
405 crc = crom_crc((u_int32_t *)&dir->entry[0], dir->crc_len);
406 if (crc == dir->crc)
407 printf("(OK)\n");
408 else
409 printf("(NG)\n");
410 if (dir->crc_len < 1)
411 return;
412 while (cc.depth >= 0) {
413 desc = crom_desc(&cc, info, sizeof(info));
414 reg = crom_get(&cc);
415 for (i = 0; i < cc.depth; i++)
416 printf("\t");
417 printf("%02x(%c:%02x) %06x %s: %s\n",
418 reg->key,
419 key_types[(reg->key & CSRTYPE_MASK)>>6],
420 reg->key & CSRKEY_MASK, reg->val,
421 desc, info);
422 crom_next(&cc);
423 }
424}
425
426#define DUMP_FORMAT "%08x %08x %08x %08x %08x %08x %08x %08x\n"
427
428static void
429dump_crom(u_int32_t *p)
430{
431 int len=1024, i;
432
433 for (i = 0; i < len/(4*8); i ++) {
434 printf(DUMP_FORMAT,
435 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
436 p += 8;
437 }
438}
439
440static void
441load_crom(char *filename, u_int32_t *p)
442{
443 FILE *file;
444 int len=1024, i;
445
446 if ((file = fopen(filename, "r")) == NULL)
447 err(1, "load_crom");
448 for (i = 0; i < len/(4*8); i ++) {
449 fscanf(file, DUMP_FORMAT,
450 p, p+1, p+2, p+3, p+4, p+5, p+6, p+7);
451 p += 8;
452 }
453}
454
455static void
456show_topology_map(int fd)
457{
458 struct fw_topology_map *tmap;
459 union fw_self_id sid;
460 int i;
461 static const char *port_status[] = {" ", "-", "P", "C"};
462 static const char *pwr_class[] = {" 0W", "15W", "30W", "45W",
463 "-1W", "-2W", "-5W", "-9W"};
464 static const char *speed[] = {"S100", "S200", "S400", "S800"};
465 tmap = malloc(sizeof(struct fw_topology_map));
466 if (tmap == NULL)
467 return;
468 if (ioctl(fd, FW_GTPMAP, tmap) < 0) {
469 err(1, "ioctl");
470 }
471 printf("crc_len: %d generation:%d node_count:%d sid_count:%d\n",
472 tmap->crc_len, tmap->generation,
473 tmap->node_count, tmap->self_id_count);
474 printf("id link gap_cnt speed delay cIRM power port0 port1 port2"
475 " ini more\n");
476 for (i = 0; i < tmap->crc_len - 2; i++) {
477 sid = tmap->self_id[i];
478 if (sid.p0.sequel) {
479 printf("%02d sequel packet\n", sid.p0.phy_id);
480 continue;
481 }
482 printf("%02d %2d %2d %4s %d %d %3s"
483 " %s %s %s %d %d\n",
484 sid.p0.phy_id,
485 sid.p0.link_active,
486 sid.p0.gap_count,
487 speed[sid.p0.phy_speed],
488 sid.p0.phy_delay,
489 sid.p0.contender,
490 pwr_class[sid.p0.power_class],
491 port_status[sid.p0.port0],
492 port_status[sid.p0.port1],
493 port_status[sid.p0.port2],
494 sid.p0.initiated_reset,
495 sid.p0.more_packets
496 );
497 }
498 free(tmap);
499}
500
501static void
502read_phy_registers(int fd, u_int8_t *buf, int offset, int len)
503{
504 struct fw_reg_req_t reg;
505 int i;
506
507 for (i = 0; i < len; i++) {
508 reg.addr = offset + i;
509 if (ioctl(fd, FWOHCI_RDPHYREG, &reg) < 0)
510 err(1, "ioctl");
511 buf[i] = (u_int8_t) reg.data;
512 printf("0x%02x ", reg.data);
513 }
514 printf("\n");
515}
516
517static void
518read_phy_page(int fd, u_int8_t *buf, int page, int port)
519{
520 struct fw_reg_req_t reg;
521
522 reg.addr = 0x7;
523 reg.data = ((page & 7) << 5) | (port & 0xf);
524 if (ioctl(fd, FWOHCI_WRPHYREG, &reg) < 0)
525 err(1, "ioctl");
526 read_phy_registers(fd, buf, 8, 8);
527}
528
529static void
530dump_phy_registers(int fd)
531{
532 struct phyreg_base b;
533 struct phyreg_page0 p;
534 struct phyreg_page1 v;
535 int i;
536
537 printf("=== base register ===\n");
538 read_phy_registers(fd, (u_int8_t *)&b, 0, 8);
539 printf(
540 "Physical_ID:%d R:%d CPS:%d\n"
541 "RHB:%d IBR:%d Gap_Count:%d\n"
542 "Extended:%d Num_Ports:%d\n"
543 "PHY_Speed:%d Delay:%d\n"
544 "LCtrl:%d C:%d Jitter:%d Pwr_Class:%d\n"
545 "WDIE:%d ISBR:%d CTOI:%d CPSI:%d STOI:%d PEI:%d EAA:%d EMC:%d\n"
546 "Max_Legacy_SPD:%d BLINK:%d Bridge:%d\n"
547 "Page_Select:%d Port_Select%d\n",
548 b.phy_id, b.r, b.cps,
549 b.rhb, b.ibr, b.gap_count,
550 b.extended, b.num_ports,
551 b.phy_speed, b.delay,
552 b.lctrl, b.c, b.jitter, b.pwr_class,
553 b.wdie, b.isbr, b.ctoi, b.cpsi, b.stoi, b.pei, b.eaa, b.emc,
554 b.legacy_spd, b.blink, b.bridge,
555 b.page_select, b.port_select
556 );
557
558 for (i = 0; i < b.num_ports; i ++) {
559 printf("\n=== page 0 port %d ===\n", i);
560 read_phy_page(fd, (u_int8_t *)&p, 0, i);
561 printf(
562 "Astat:%d BStat:%d Ch:%d Con:%d RXOK:%d Dis:%d\n"
563 "Negotiated_speed:%d PIE:%d Fault:%d Stanby_fault:%d Disscrm:%d B_Only:%d\n"
564 "DC_connected:%d Max_port_speed:%d LPP:%d Cable_speed:%d\n"
565 "Connection_unreliable:%d Beta_mode:%d\n"
566 "Port_error:0x%x\n"
567 "Loop_disable:%d In_standby:%d Hard_disable:%d\n",
568 p.astat, p.bstat, p.ch, p.con, p.rxok, p.dis,
569 p.negotiated_speed, p.pie, p.fault, p.stanby_fault, p.disscrm, p.b_only,
570 p.dc_connected, p.max_port_speed, p.lpp, p.cable_speed,
571 p.connection_unreliable, p.beta_mode,
572 p.port_error,
573 p.loop_disable, p.in_standby, p.hard_disable
574 );
575 }
576 printf("\n=== page 1 ===\n");
577 read_phy_page(fd, (u_int8_t *)&v, 1, 0);
578 printf(
579 "Compliance:%d\n"
580 "Vendor_ID:0x%06x\n"
581 "Product_ID:0x%06x\n",
582 v.compliance,
583 (v.vendor_id[0] << 16) | (v.vendor_id[1] << 8) | v.vendor_id[2],
584 (v.product_id[0] << 16) | (v.product_id[1] << 8) | v.product_id[2]
585 );
586}
587
588static void
589open_dev(int *fd, char *devbase)
590{
591 char name[256];
592 int i;
593
594 if (*fd < 0) {
595 for (i = 0; i < 4; i++) {
596 snprintf(name, sizeof(name), "%s.%d", devbase, i);
597 if ((*fd = open(name, O_RDWR)) >= 0)
598 break;
599 }
600 if (*fd < 0)
601 err(1, "open");
602
603 }
604}
605
606int
607sysctl_set_int(const char *name, int val)
608{
609 if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0)
610 err(1, "sysctl %s failed.", name);
611}
612
613int
614main(int argc, char **argv)
615{
616 u_int32_t crom_buf[1024/4];
617 char devbase[1024] = "/dev/fw0";
618 int fd, tmp, ch, len=1024;
619 struct fw_eui64 eui;
620 struct eui64 target;
621
622 fd = -1;
623
624 if (argc < 2) {
625 open_dev(&fd, devbase);
626 list_dev(fd);
627 }
628
629 while ((ch = getopt(argc, argv, "g:m:o:s:b:prtc:d:l:u:R:S:")) != -1)
630 switch(ch) {
631 case 'b':
632 tmp = strtol(optarg, NULL, 0);
633 open_dev(&fd, devbase);
634 set_pri_req(fd, tmp);
635 break;
636 case 'c':
637 open_dev(&fd, devbase);
638 tmp = str2node(fd, optarg);
639 get_crom(fd, tmp, crom_buf, len);
640 show_crom(crom_buf);
641 break;
642 case 'd':
643 open_dev(&fd, devbase);
644 tmp = str2node(fd, optarg);
645 get_crom(fd, tmp, crom_buf, len);
646 dump_crom(crom_buf);
647 break;
648 case 'g':
649 tmp = strtol(optarg, NULL, 0);
650 open_dev(&fd, devbase);
651 send_phy_config(fd, -1, tmp);
652 break;
653 case 'l':
654 load_crom(optarg, crom_buf);
655 show_crom(crom_buf);
656 break;
657 case 'm':
658 if (eui64_hostton(optarg, &target) != 0 &&
659 eui64_aton(optarg, &target) != 0)
660 errx(1, "invalid target: %s", optarg);
661 eui.hi = ntohl(*(u_int32_t*)&(target.octet[0]));
662 eui.lo = ntohl(*(u_int32_t*)&(target.octet[4]));
663 sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi);
664 sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo);
665 break;
666 case 'o':
667 open_dev(&fd, devbase);
668 tmp = str2node(fd, optarg);
669 send_link_on(fd, tmp);
670 break;
671 case 'p':
672 open_dev(&fd, devbase);
673 dump_phy_registers(fd);
674 break;
675 case 'r':
676 open_dev(&fd, devbase);
677 if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
678 err(1, "ioctl");
679 break;
680 case 's':
681 open_dev(&fd, devbase);
682 tmp = str2node(fd, optarg);
683 reset_start(fd, tmp);
684 break;
685 case 't':
686 open_dev(&fd, devbase);
687 show_topology_map(fd);
688 break;
689 case 'u':
690 tmp = strtol(optarg, NULL, 0);
691 snprintf(devbase, sizeof(devbase), "/dev/fw%d", tmp);
692 if (fd > 0) {
693 close(fd);
694 fd = -1;
695 }
696 if (argc == optind) {
697 open_dev(&fd, devbase);
698 list_dev(fd);
699 }
700 break;
701#define TAG (1<<6)
702#define CHANNEL 63
703 case 'R':
704 open_dev(&fd, devbase);
705 dvrecv(fd, optarg, TAG | CHANNEL, -1);
706 break;
707 case 'S':
708 open_dev(&fd, devbase);
709 dvsend(fd, optarg, TAG | CHANNEL, -1);
710 break;
711 default:
712 usage();
713 }
714 return 0;
715}