Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / usr.sbin / fwctl / fwcontrol.c
blob6ac2a52f6863ca3c63d4a7351a5acd89d7b9c3ad
1 /* $NetBSD: fwcontrol.c,v 1.6 2007/11/06 17:02:15 kiyohara Exp $ */
2 /*
3 * Copyright (C) 2002
4 * Hidetoshi Shimokawa. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
17 * This product includes software developed by Hidetoshi Shimokawa.
19 * 4. Neither the name of the author nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 #if defined(__FreeBSD__)
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.c,v 1.23 2006/10/26 22:33:38 imp Exp $");
39 #endif
41 #include <sys/param.h>
42 #include <sys/malloc.h>
43 #include <sys/types.h>
44 #include <sys/sysctl.h>
45 #include <sys/socket.h>
46 #include <sys/ioctl.h>
47 #include <sys/errno.h>
48 #if defined(__FreeBSD__)
49 #include <sys/eui64.h>
50 #include <dev/firewire/firewire.h>
51 #include <dev/firewire/iec13213.h>
52 #include <dev/firewire/fwphyreg.h>
53 #include <dev/firewire/iec68113.h>
54 #elif defined(__NetBSD__)
55 #include "eui64.h"
56 #include <dev/ieee1394/firewire.h>
57 #include <dev/ieee1394/iec13213.h>
58 #include <dev/ieee1394/fwphyreg.h>
59 #include <dev/ieee1394/iec68113.h>
60 #endif
62 #include <netinet/in.h>
63 #include <fcntl.h>
64 #include <stdio.h>
65 #include <err.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #include <sysexits.h>
69 #include <unistd.h>
70 #include "fwmethods.h"
72 static void sysctl_set_int(const char *, int);
74 static void
75 usage(void)
77 fprintf(stderr,
78 "%s [-prt] [-b pri_req] [-c node] [-d node]"
79 " [-g gap_count] [-l file]\n"
80 "\t[-m EUI64 | hostname] [-o node] [-R filename]"
81 " [-S filename]\n"
82 "\t[-s node] [-u bus_num]\n"
83 "\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
84 "\t-c: read configuration ROM\n"
85 "\t-d: hex dump of configuration ROM\n"
86 "\t-g: broadcast gap_count by phy_config packet\n"
87 "\t-l: load and parse hex dump file of configuration ROM\n"
88 "\t-m: set fwmem target\n"
89 "\t-o: send link-on packet to the node\n"
90 "\t-p: dump PHY registers\n"
91 "\t-R: receive DV or MPEG TS stream\n"
92 "\t-r: bus reset\n"
93 "\t-S: send DV stream\n"
94 "\t-s: write RESET_START register on the node\n"
95 "\t-t: read topology map\n"
96 "\t-u: specify bus number\n", getprogname());
97 exit(EX_USAGE);
100 static void
101 fweui2eui64(const struct fw_eui64 *fweui, struct eui64 *eui)
103 *(u_int32_t*)&(eui->octet[0]) = htonl(fweui->hi);
104 *(u_int32_t*)&(eui->octet[4]) = htonl(fweui->lo);
107 static struct fw_devlstreq *
108 get_dev(int fd)
110 struct fw_devlstreq *data;
112 data = malloc(sizeof(*data));
113 if (data == NULL)
114 err(1, "malloc");
115 if( ioctl(fd, FW_GDEVLST, data) < 0) {
116 err(1, "ioctl");
118 return data;
121 static int
122 str2node(int fd, const char *nodestr)
124 struct eui64 eui, tmpeui;
125 struct fw_devlstreq *data;
126 char *endptr;
127 int i, node;
129 if (nodestr == '\0')
130 return (-1);
133 * Deal with classic node specifications.
135 node = strtol(nodestr, &endptr, 0);
136 if (*endptr == '\0')
137 goto gotnode;
140 * Try to get an eui and match it against available nodes.
142 if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
143 return (-1);
145 data = get_dev(fd);
147 for (i = 0; i < data->info_len; i++) {
148 fweui2eui64(&data->dev[i].eui, &tmpeui);
149 if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) {
150 node = data->dev[i].dst;
151 goto gotnode;
154 if (i >= data->info_len)
155 return (-1);
157 gotnode:
158 if (node < 0 || node > 63)
159 return (-1);
160 else
161 return (node);
164 static void
165 list_dev(int fd)
167 struct fw_devlstreq *data;
168 struct fw_devinfo *devinfo;
169 struct eui64 eui;
170 char addr[EUI64_SIZ];
171 int i;
173 data = get_dev(fd);
174 printf("%d devices (info_len=%d)\n", data->n, data->info_len);
175 printf("node EUI64 status\n");
176 for (i = 0; i < data->info_len; i++) {
177 devinfo = &data->dev[i];
178 fweui2eui64(&devinfo->eui, &eui);
179 eui64_ntoa(&eui, addr, sizeof(addr));
180 printf("%4d %s %6d\n",
181 (devinfo->status || i == 0) ? devinfo->dst : -1,
182 addr,
183 devinfo->status
186 free((void *)data);
189 static u_int32_t
190 read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_int32_t data)
192 struct fw_asyreq *asyreq;
193 u_int32_t *qld, res;
195 asyreq = malloc(sizeof(*asyreq));
196 if (asyreq == NULL)
197 err(1, "malloc");
198 asyreq->req.len = 16;
199 #if 0
200 asyreq->req.type = FWASREQNODE;
201 asyreq->pkt.mode.rreqq.dst = FWLOCALBUS | node;
202 #else
203 asyreq->req.type = FWASREQEUI;
204 asyreq->req.dst.eui = eui;
205 #endif
206 asyreq->pkt.mode.rreqq.tlrt = 0;
207 if (readmode)
208 asyreq->pkt.mode.rreqq.tcode = FWTCODE_RREQQ;
209 else
210 asyreq->pkt.mode.rreqq.tcode = FWTCODE_WREQQ;
212 asyreq->pkt.mode.rreqq.dest_hi = 0xffff;
213 asyreq->pkt.mode.rreqq.dest_lo = addr_lo;
215 qld = (u_int32_t *)&asyreq->pkt;
216 if (!readmode)
217 asyreq->pkt.mode.wreqq.data = data;
219 if (ioctl(fd, FW_ASYREQ, asyreq) < 0) {
220 err(1, "ioctl");
222 res = qld[3];
223 free(asyreq);
224 if (readmode)
225 return ntohl(res);
226 else
227 return 0;
230 static void
231 send_phy_config(int fd, int root_node, int gap_count)
233 struct fw_asyreq *asyreq;
235 asyreq = malloc(sizeof(*asyreq));
236 if (asyreq == NULL)
237 err(1, "malloc");
238 asyreq->req.len = 12;
239 asyreq->req.type = FWASREQNODE;
240 asyreq->pkt.mode.ld[0] = 0;
241 asyreq->pkt.mode.ld[1] = 0;
242 asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
243 if (root_node >= 0)
244 asyreq->pkt.mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
245 if (gap_count >= 0)
246 asyreq->pkt.mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
247 asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
249 printf("send phy_config root_node=%d gap_count=%d\n",
250 root_node, gap_count);
252 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
253 err(1, "ioctl");
254 free(asyreq);
257 static void
258 send_link_on(int fd, int node)
260 struct fw_asyreq *asyreq;
262 asyreq = malloc(sizeof(*asyreq));
263 if (asyreq == NULL)
264 err(1, "malloc");
265 asyreq->req.len = 12;
266 asyreq->req.type = FWASREQNODE;
267 asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
268 asyreq->pkt.mode.ld[1] |= (1 << 30) | ((node & 0x3f) << 24);
269 asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
271 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
272 err(1, "ioctl");
273 free(asyreq);
276 static void
277 reset_start(int fd, int node)
279 struct fw_asyreq *asyreq;
281 asyreq = malloc(sizeof(*asyreq));
282 if (asyreq == NULL)
283 err(1, "malloc");
284 asyreq->req.len = 16;
285 asyreq->req.type = FWASREQNODE;
286 asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f);
287 asyreq->pkt.mode.wreqq.tlrt = 0;
288 asyreq->pkt.mode.wreqq.tcode = FWTCODE_WREQQ;
290 asyreq->pkt.mode.wreqq.dest_hi = 0xffff;
291 asyreq->pkt.mode.wreqq.dest_lo = 0xf0000000 | RESET_START;
293 asyreq->pkt.mode.wreqq.data = htonl(0x1);
295 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
296 err(1, "ioctl");
297 free(asyreq);
300 static void
301 set_pri_req(int fd, u_int32_t pri_req)
303 struct fw_devlstreq *data;
304 struct fw_devinfo *devinfo;
305 struct eui64 eui;
306 char addr[EUI64_SIZ];
307 u_int32_t max, reg, old;
308 int i;
310 data = get_dev(fd);
311 #define BUGET_REG 0xf0000218
312 for (i = 0; i < data->info_len; i++) {
313 devinfo = &data->dev[i];
314 if (!devinfo->status)
315 continue;
316 reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0);
317 fweui2eui64(&devinfo->eui, &eui);
318 eui64_ntoa(&eui, addr, sizeof(addr));
319 printf("%d %s, %08x",
320 devinfo->dst, addr, reg);
321 if (reg > 0) {
322 old = (reg & 0x3f);
323 max = (reg & 0x3f00) >> 8;
324 if (pri_req > max)
325 pri_req = max;
326 printf(" 0x%x -> 0x%x\n", old, pri_req);
327 read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req);
328 } else {
329 printf("\n");
332 free((void *)data);
335 static void
336 parse_bus_info_block(u_int32_t *p)
338 char addr[EUI64_SIZ];
339 struct bus_info *bi;
340 struct eui64 eui;
342 bi = (struct bus_info *)p;
343 fweui2eui64(&bi->eui64, &eui);
344 eui64_ntoa(&eui, addr, sizeof(addr));
345 printf("bus_name: 0x%04x\n"
346 "irmc:%d cmc:%d isc:%d bmc:%d pmc:%d\n"
347 "cyc_clk_acc:%d max_rec:%d max_rom:%d\n"
348 "generation:%d link_spd:%d\n"
349 "EUI64: %s\n",
350 bi->bus_name,
351 bi->irmc, bi->cmc, bi->isc, bi->bmc, bi->pmc,
352 bi->cyc_clk_acc, bi->max_rec, bi->max_rom,
353 bi->generation, bi->link_spd,
354 addr);
357 static int
358 get_crom(int fd, int node, void *crom_buf, int len)
360 struct fw_crom_buf buf;
361 int i, error;
362 struct fw_devlstreq *data;
364 data = get_dev(fd);
366 for (i = 0; i < data->info_len; i++) {
367 if (data->dev[i].dst == node && data->dev[i].eui.lo != 0)
368 break;
370 if (i == data->info_len)
371 errx(1, "no such node %d.", node);
372 else
373 buf.eui = data->dev[i].eui;
374 free((void *)data);
376 buf.len = len;
377 buf.ptr = crom_buf;
378 bzero(crom_buf, len);
379 if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) {
380 err(1, "ioctl");
383 return error;
386 static void
387 show_crom(u_int32_t *crom_buf)
389 int i;
390 struct crom_context cc;
391 const char *desc;
392 char info[256];
393 static const char *key_types = "ICLD";
394 struct csrreg *reg;
395 struct csrdirectory *dir;
396 struct csrhdr *hdr;
397 u_int16_t crc;
399 printf("first quad: 0x%08x ", *crom_buf);
400 if (crom_buf[0] == 0) {
401 printf("(Invalid Configuration ROM)\n");
402 return;
404 hdr = (struct csrhdr *)crom_buf;
405 if (hdr->info_len == 1) {
406 /* minimum ROM */
407 reg = (struct csrreg *)hdr;
408 printf("verndor ID: 0x%06x\n", reg->val);
409 return;
411 printf("info_len=%d crc_len=%d crc=0x%04x",
412 hdr->info_len, hdr->crc_len, hdr->crc);
413 crc = crom_crc(crom_buf+1, hdr->crc_len);
414 if (crc == hdr->crc)
415 printf("(OK)\n");
416 else
417 printf("(NG)\n");
418 parse_bus_info_block(crom_buf+1);
420 crom_init_context(&cc, crom_buf);
421 dir = cc.stack[0].dir;
422 if (!dir) {
423 printf("no root directory - giving up\n");
424 return;
426 printf("root_directory: len=0x%04x(%d) crc=0x%04x",
427 dir->crc_len, dir->crc_len, dir->crc);
428 crc = crom_crc((u_int32_t *)&dir->entry[0], dir->crc_len);
429 if (crc == dir->crc)
430 printf("(OK)\n");
431 else
432 printf("(NG)\n");
433 if (dir->crc_len < 1)
434 return;
435 while (cc.depth >= 0) {
436 desc = crom_desc(&cc, info, sizeof(info));
437 reg = crom_get(&cc);
438 for (i = 0; i < cc.depth; i++)
439 printf("\t");
440 printf("%02x(%c:%02x) %06x %s: %s\n",
441 reg->key,
442 key_types[(reg->key & CSRTYPE_MASK)>>6],
443 reg->key & CSRKEY_MASK, reg->val,
444 desc, info);
445 crom_next(&cc);
449 #define DUMP_FORMAT "%08x %08x %08x %08x %08x %08x %08x %08x\n"
451 static void
452 dump_crom(u_int32_t *p)
454 int len=1024, i;
456 for (i = 0; i < len/(4*8); i ++) {
457 printf(DUMP_FORMAT,
458 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
459 p += 8;
463 static void
464 load_crom(char *filename, u_int32_t *p)
466 FILE *file;
467 int len=1024, i;
469 if ((file = fopen(filename, "r")) == NULL)
470 err(1, "load_crom");
471 for (i = 0; i < len/(4*8); i ++) {
472 fscanf(file, DUMP_FORMAT,
473 p, p+1, p+2, p+3, p+4, p+5, p+6, p+7);
474 p += 8;
476 (void)fclose(file);
479 static void
480 show_topology_map(int fd)
482 struct fw_topology_map *tmap;
483 union fw_self_id sid;
484 int i;
485 static const char *port_status[] = {" ", "-", "P", "C"};
486 static const char *pwr_class[] = {" 0W", "15W", "30W", "45W",
487 "-1W", "-2W", "-5W", "-9W"};
488 static const char *speed[] = {"S100", "S200", "S400", "S800"};
489 tmap = malloc(sizeof(*tmap));
490 if (tmap == NULL)
491 err(1, "malloc");
492 if (ioctl(fd, FW_GTPMAP, tmap) < 0) {
493 err(1, "ioctl");
495 printf("crc_len: %d generation:%d node_count:%d sid_count:%d\n",
496 tmap->crc_len, tmap->generation,
497 tmap->node_count, tmap->self_id_count);
498 printf("id link gap_cnt speed delay cIRM power port0 port1 port2"
499 " ini more\n");
500 for (i = 0; i < tmap->crc_len - 2; i++) {
501 sid = tmap->self_id[i];
502 if (sid.p0.sequel) {
503 printf("%02d sequel packet\n", sid.p0.phy_id);
504 continue;
506 printf("%02d %2d %2d %4s %d %d %3s"
507 " %s %s %s %d %d\n",
508 sid.p0.phy_id,
509 sid.p0.link_active,
510 sid.p0.gap_count,
511 speed[sid.p0.phy_speed],
512 sid.p0.phy_delay,
513 sid.p0.contender,
514 pwr_class[sid.p0.power_class],
515 port_status[sid.p0.port0],
516 port_status[sid.p0.port1],
517 port_status[sid.p0.port2],
518 sid.p0.initiated_reset,
519 sid.p0.more_packets
522 free(tmap);
525 static void
526 read_phy_registers(int fd, u_int8_t *buf, int offset, int len)
528 struct fw_reg_req_t reg;
529 int i;
531 for (i = 0; i < len; i++) {
532 reg.addr = offset + i;
533 if (ioctl(fd, FWOHCI_RDPHYREG, &reg) < 0)
534 err(1, "ioctl");
535 buf[i] = (u_int8_t) reg.data;
536 printf("0x%02x ", reg.data);
538 printf("\n");
541 static void
542 read_phy_page(int fd, u_int8_t *buf, int page, int port)
544 struct fw_reg_req_t reg;
546 reg.addr = 0x7;
547 reg.data = ((page & 7) << 5) | (port & 0xf);
548 if (ioctl(fd, FWOHCI_WRPHYREG, &reg) < 0)
549 err(1, "ioctl");
550 read_phy_registers(fd, buf, 8, 8);
553 static void
554 dump_phy_registers(int fd)
556 struct phyreg_base b;
557 struct phyreg_page0 p;
558 struct phyreg_page1 v;
559 int i;
561 printf("=== base register ===\n");
562 read_phy_registers(fd, (u_int8_t *)&b, 0, 8);
563 printf(
564 "Physical_ID:%d R:%d CPS:%d\n"
565 "RHB:%d IBR:%d Gap_Count:%d\n"
566 "Extended:%d Num_Ports:%d\n"
567 "PHY_Speed:%d Delay:%d\n"
568 "LCtrl:%d C:%d Jitter:%d Pwr_Class:%d\n"
569 "WDIE:%d ISBR:%d CTOI:%d CPSI:%d STOI:%d PEI:%d EAA:%d EMC:%d\n"
570 "Max_Legacy_SPD:%d BLINK:%d Bridge:%d\n"
571 "Page_Select:%d Port_Select%d\n",
572 b.phy_id, b.r, b.cps,
573 b.rhb, b.ibr, b.gap_count,
574 b.extended, b.num_ports,
575 b.phy_speed, b.delay,
576 b.lctrl, b.c, b.jitter, b.pwr_class,
577 b.wdie, b.isbr, b.ctoi, b.cpsi, b.stoi, b.pei, b.eaa, b.emc,
578 b.legacy_spd, b.blink, b.bridge,
579 b.page_select, b.port_select
582 for (i = 0; i < b.num_ports; i ++) {
583 printf("\n=== page 0 port %d ===\n", i);
584 read_phy_page(fd, (u_int8_t *)&p, 0, i);
585 printf(
586 "Astat:%d BStat:%d Ch:%d Con:%d RXOK:%d Dis:%d\n"
587 "Negotiated_speed:%d PIE:%d Fault:%d Stanby_fault:%d Disscrm:%d B_Only:%d\n"
588 "DC_connected:%d Max_port_speed:%d LPP:%d Cable_speed:%d\n"
589 "Connection_unreliable:%d Beta_mode:%d\n"
590 "Port_error:0x%x\n"
591 "Loop_disable:%d In_standby:%d Hard_disable:%d\n",
592 p.astat, p.bstat, p.ch, p.con, p.rxok, p.dis,
593 p.negotiated_speed, p.pie, p.fault, p.stanby_fault, p.disscrm, p.b_only,
594 p.dc_connected, p.max_port_speed, p.lpp, p.cable_speed,
595 p.connection_unreliable, p.beta_mode,
596 p.port_error,
597 p.loop_disable, p.in_standby, p.hard_disable
600 printf("\n=== page 1 ===\n");
601 read_phy_page(fd, (u_int8_t *)&v, 1, 0);
602 printf(
603 "Compliance:%d\n"
604 "Vendor_ID:0x%06x\n"
605 "Product_ID:0x%06x\n",
606 v.compliance,
607 (v.vendor_id[0] << 16) | (v.vendor_id[1] << 8) | v.vendor_id[2],
608 (v.product_id[0] << 16) | (v.product_id[1] << 8) | v.product_id[2]
612 static void
613 open_dev(int *fd, char *devbase)
615 char name[256];
616 int i;
618 if (*fd < 0) {
619 for (i = 0; i < 4; i++) {
620 snprintf(name, sizeof(name), "%s.%d", devbase, i);
621 if ((*fd = open(name, O_RDWR)) >= 0)
622 break;
624 if (*fd < 0)
625 err(1, "open");
630 static void
631 sysctl_set_int(const char *name, int val)
633 if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0)
634 err(1, "sysctl %s failed.", name);
637 static fwmethod *
638 detect_recv_fn(int fd, char ich)
640 char *buf;
641 struct fw_isochreq isoreq;
642 struct fw_isobufreq bufreq;
643 int len;
644 u_int32_t *ptr;
645 struct ciphdr *ciph;
646 fwmethod *retfn;
648 bufreq.rx.nchunk = 8;
649 bufreq.rx.npacket = 16;
650 bufreq.rx.psize = 1024;
651 bufreq.tx.nchunk = 0;
652 bufreq.tx.npacket = 0;
653 bufreq.tx.psize = 0;
655 if (ioctl(fd, FW_SSTBUF, &bufreq) < 0)
656 err(1, "ioctl FW_SSTBUF");
658 isoreq.ch = ich & 0x3f;
659 isoreq.tag = (ich >> 6) & 3;
661 if (ioctl(fd, FW_SRSTREAM, &isoreq) < 0)
662 err(1, "ioctl FW_SRSTREAM");
664 buf = (char *)malloc(1024*16);
665 len = read(fd, buf, 1024*16);
666 ptr = (u_int32_t *) buf;
667 ciph = (struct ciphdr *)(ptr + 1);
669 switch(ciph->fmt) {
670 case CIP_FMT_DVCR:
671 fprintf(stderr, "Detected DV format on input.\n");
672 retfn = dvrecv;
673 break;
674 case CIP_FMT_MPEG:
675 fprintf(stderr, "Detected MPEG TS format on input.\n");
676 retfn = mpegtsrecv;
677 break;
678 default:
679 errx(1, "Unsupported format for receiving: fmt=0x%x",
680 ciph->fmt);
682 free(buf);
683 return retfn;
687 main(int argc, char **argv)
689 u_int32_t crom_buf[1024/4];
690 char devbase[1024] = "/dev/fw0";
691 int fd, ch, len=1024;
692 long tmp;
693 struct fw_eui64 eui;
694 struct eui64 target;
695 fwmethod *recvfn = NULL;
697 fd = -1;
699 if (argc < 2) {
700 open_dev(&fd, devbase);
701 list_dev(fd);
704 while ((ch = getopt(argc, argv, "M:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1)
705 switch(ch) {
706 case 'b':
707 tmp = strtol(optarg, NULL, 0);
708 if (tmp < 0 || tmp > (long)0xffffffff)
709 errx(EX_USAGE, "invalid number: %s", optarg);
710 open_dev(&fd, devbase);
711 set_pri_req(fd, tmp);
712 break;
713 case 'c':
714 open_dev(&fd, devbase);
715 tmp = str2node(fd, optarg);
716 get_crom(fd, tmp, crom_buf, len);
717 show_crom(crom_buf);
718 break;
719 case 'd':
720 open_dev(&fd, devbase);
721 tmp = str2node(fd, optarg);
722 get_crom(fd, tmp, crom_buf, len);
723 dump_crom(crom_buf);
724 break;
725 case 'g':
726 tmp = strtol(optarg, NULL, 0);
727 open_dev(&fd, devbase);
728 send_phy_config(fd, -1, tmp);
729 break;
730 case 'l':
731 load_crom(optarg, crom_buf);
732 show_crom(crom_buf);
733 break;
734 case 'm':
735 if (eui64_hostton(optarg, &target) != 0 &&
736 eui64_aton(optarg, &target) != 0)
737 errx(EX_USAGE, "invalid target: %s", optarg);
738 eui.hi = ntohl(*(u_int32_t*)&(target.octet[0]));
739 eui.lo = ntohl(*(u_int32_t*)&(target.octet[4]));
740 sysctl_set_int("hw.fwmem.eui64_hi", eui.hi);
741 sysctl_set_int("hw.fwmem.eui64_lo", eui.lo);
742 break;
743 case 'o':
744 open_dev(&fd, devbase);
745 tmp = str2node(fd, optarg);
746 send_link_on(fd, tmp);
747 break;
748 case 'p':
749 open_dev(&fd, devbase);
750 dump_phy_registers(fd);
751 break;
752 case 'r':
753 open_dev(&fd, devbase);
754 if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
755 err(1, "ioctl");
756 break;
757 case 's':
758 open_dev(&fd, devbase);
759 tmp = str2node(fd, optarg);
760 reset_start(fd, tmp);
761 break;
762 case 't':
763 open_dev(&fd, devbase);
764 show_topology_map(fd);
765 break;
766 case 'u':
767 tmp = strtol(optarg, NULL, 0);
768 snprintf(devbase, sizeof(devbase), "/dev/fw%ld", tmp);
769 if (fd > 0) {
770 close(fd);
771 fd = -1;
773 if (argc == optind) {
774 open_dev(&fd, devbase);
775 list_dev(fd);
777 break;
778 #define TAG (1<<6)
779 #define CHANNEL 63
780 case 'M':
781 switch (optarg[0]) {
782 case 'm':
783 recvfn = mpegtsrecv;
784 break;
785 case 'd':
786 recvfn = dvrecv;
787 break;
788 default:
789 errx(EX_USAGE, "unrecognized method: %s",
790 optarg);
792 break;
793 case 'R':
794 open_dev(&fd, devbase);
795 if (recvfn == NULL) /* guess... */
796 recvfn = detect_recv_fn(fd, TAG | CHANNEL);
797 close(fd);
798 fd = -1;
799 open_dev(&fd, devbase);
800 (*recvfn)(fd, optarg, TAG | CHANNEL, -1);
801 break;
802 case 'S':
803 open_dev(&fd, devbase);
804 dvsend(fd, optarg, TAG | CHANNEL, -1);
805 break;
806 default:
807 usage();
809 return 0;