If boot verbose, print asicrev, chiprev and bus type.
[dragonfly.git] / sbin / atm / atm / atm_print.c
blob4133f94220d155ecd66a44cfa5804b20c7ee93de
1 /*
3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sbin/atm/atm/atm_print.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
27 * @(#) $DragonFly: src/sbin/atm/atm/atm_print.c,v 1.5 2006/10/16 00:15:35 pavalos Exp $
31 * User configuration and display program
32 * --------------------------------------
34 * Print routines for "show" subcommand
38 #include <sys/param.h>
39 #include <sys/socket.h>
40 #include <net/if.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <netatm/port.h>
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sigmgr.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_vc.h>
50 #include <netatm/atm_ioctl.h>
51 #include <netatm/ipatm/ipatm_var.h>
52 #include <netatm/sigpvc/sigpvc_var.h>
53 #include <netatm/spans/spans_var.h>
54 #include <netatm/uni/uniip_var.h>
55 #include <netatm/uni/unisig_var.h>
57 #include <errno.h>
58 #include <libatm.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
63 #include "atm.h"
65 #define ARP_HDR \
66 "Net Intf Flags Age Origin\n"
68 #define ASRV_HDR \
69 "Net Intf State ATM Address\n"
71 #define CFG_HDR \
72 "Intf Vendor Model Media Bus Serial No\n"
74 #define IP_VCC_HDR \
75 "Net Intf VPI VCI State Flags IP Address\n"
77 #define INTF_HDR \
78 "Interface Sigmgr State\n"
80 #define NETIF_HDR \
81 "Net Intf Phy Intf IP Address\n"
83 #define VCC_HDR \
84 "Interface VPI VCI AAL Type Dir State Encaps Owner\n"
86 #define VCC_STATS_HDR \
87 " Input Input Input Output Output Output\n\
88 Interface VPI VCI PDUs Bytes Errs PDUs Bytes Errs\n"
90 #define VERSION_HDR \
91 "Version\n"
93 #define PHY_STATS_HDR \
94 " Input Input Input Output Output Output Cmd\n\
95 Interface PDUs Bytes Errs PDUs Bytes Errs Errs\n"
98 * External references
100 extern struct proto protos[];
101 extern struct aal aals[];
102 extern struct encaps encaps[];
105 * Local variables
107 static int arp_hdr = 0;
108 static int asrv_hdr = 0;
109 static int cfg_hdr = 0;
110 static int ip_vcc_hdr = 0;
111 static int netif_hdr = 0;
112 static int vcc_hdr = 0;
113 static int vcc_stats_hdr = 0;
114 static int phy_stats_hdr = 0;
115 static int version_hdr = 0;
118 * SIGPVC state definitions
120 static const struct state sigpvc_states[] = {
121 { "ACTIVE", SIGPVC_ACTIVE },
122 { "DETACH", SIGPVC_DETACH },
123 { 0, 0 }
127 * SPANS state definitions
129 static const struct state spans_states[] = {
130 { "ACTIVE", SPANS_ACTIVE },
131 { "DETACH", SPANS_DETACH },
132 { "INIT", SPANS_INIT },
133 { "PROBE", SPANS_PROBE },
134 { 0, 0 }
138 * UNISIG state definitions
140 static const struct state unisig_states[] = {
141 { "NULL", UNISIG_NULL },
142 { "ADR_WAIT", UNISIG_ADDR_WAIT },
143 { "INIT", UNISIG_INIT },
144 { "ACTIVE", UNISIG_ACTIVE },
145 { "DETACH", UNISIG_DETACH },
146 { 0, 0 }
150 * SIGPVC VCC state definitions
152 static const struct state sigpvc_vcc_states[] = {
153 { "NULL", VCCS_NULL },
154 { "ACTIVE", VCCS_ACTIVE },
155 { "FREE", VCCS_FREE },
156 { 0, 0 }
160 * SPANS VCC state definitions
162 static const struct state spans_vcc_states[] = {
163 { "NULL", SPANS_VC_NULL },
164 { "ACTIVE", SPANS_VC_ACTIVE },
165 { "ACT_DOWN", SPANS_VC_ACT_DOWN },
166 { "POPEN", SPANS_VC_POPEN },
167 { "R_POPEN", SPANS_VC_R_POPEN },
168 { "OPEN", SPANS_VC_OPEN },
169 { "CLOSE", SPANS_VC_CLOSE },
170 { "ABORT", SPANS_VC_ABORT },
171 { "FREE", SPANS_VC_FREE },
172 {0, 0 }
176 * UNISIG VCC state definitions
178 static const struct state unisig_vcc_states[] = {
179 { "NULL", UNI_NULL },
180 { "C_INIT", UNI_CALL_INITIATED },
181 { "C_OUT_PR", UNI_CALL_OUT_PROC },
182 { "C_DELIV", UNI_CALL_DELIVERED },
183 { "C_PRES", UNI_CALL_PRESENT },
184 { "C_REC", UNI_CALL_RECEIVED },
185 { "CONN_REQ", UNI_CONNECT_REQUEST },
186 { "C_IN_PR", UNI_CALL_IN_PROC },
187 { "ACTIVE", UNI_ACTIVE },
188 { "REL_REQ", UNI_RELEASE_REQUEST },
189 { "REL_IND", UNI_RELEASE_IND },
190 { "SSCF_REC", UNI_SSCF_RECOV },
191 { "FREE", UNI_FREE },
192 { "ACTIVE", UNI_PVC_ACTIVE },
193 { "ACT_DOWN", UNI_PVC_ACT_DOWN },
194 {0, 0 }
198 * IP VCC state definitions
200 static const struct state ip_vcc_states[] = {
201 { "FREE", IPVCC_FREE },
202 { "PMAP", IPVCC_PMAP },
203 { "POPEN", IPVCC_POPEN },
204 { "PACCEPT", IPVCC_PACCEPT },
205 { "ACTPENT", IPVCC_ACTPENT },
206 { "ACTIVE", IPVCC_ACTIVE },
207 { "CLOSED", IPVCC_CLOSED },
208 { 0, 0 }
212 * ARP server state definitions
214 static const struct state arpserver_states[] = {
215 { "NOT_CONF", UIAS_NOTCONF },
216 { "SERVER", UIAS_SERVER_ACTIVE },
217 { "PEND_ADR", UIAS_CLIENT_PADDR },
218 { "POPEN", UIAS_CLIENT_POPEN },
219 { "REGISTER", UIAS_CLIENT_REGISTER },
220 { "ACTIVE", UIAS_CLIENT_ACTIVE },
221 { 0, 0 }
225 * Supported signalling managers
227 static const struct proto_state proto_states[] = {
228 { "SIGPVC", sigpvc_states, sigpvc_vcc_states, ATM_SIG_PVC },
229 { "SPANS", spans_states, spans_vcc_states, ATM_SIG_SPANS },
230 { "UNI 3.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI30 },
231 { "UNI 3.1", unisig_states, unisig_vcc_states, ATM_SIG_UNI31 },
232 { "UNI 4.0", unisig_states, unisig_vcc_states, ATM_SIG_UNI40 },
233 { 0, 0, 0, 0 }
237 * ATMARP origin values
239 static const struct state arp_origins[] = {
240 { "LOCAL", UAO_LOCAL },
241 { "PERM", UAO_PERM },
242 { "REG", UAO_REGISTER },
243 { "SCSP", UAO_SCSP },
244 { "LOOKUP", UAO_LOOKUP },
245 { "PEER_RSP", UAO_PEER_RSP },
246 { "PEER_REQ", UAO_PEER_REQ },
247 { 0, 0 }
252 * Print ARP table information
254 * Arguments:
255 * ai pointer to a struct air_arp_rsp
257 * Returns:
258 * none
261 void
262 print_arp_info(struct air_arp_rsp *ai)
264 int i;
265 const char *atm_addr, *ip_addr, *origin;
266 char age[8], flags[32];
267 struct sockaddr_in *sin;
270 * Print a header if it hasn't been done yet.
272 if (!arp_hdr) {
273 printf(ARP_HDR);
274 arp_hdr = 1;
278 * Format the addresses
280 atm_addr = format_atm_addr(&ai->aap_addr);
281 sin = (struct sockaddr_in *)&ai->aap_arp_addr;
282 ip_addr = format_ip_addr(&sin->sin_addr);
285 * Decode the flags
287 UM_ZERO(flags, sizeof(flags));
288 if (ai->aap_flags & ARPF_VALID) {
289 strcat(flags, "V");
291 if (ai->aap_flags & ARPF_REFRESH) {
292 strcat(flags, "R");
296 * Format the origin
298 for (i=0; arp_origins[i].s_name != NULL &&
299 ai->aap_origin != arp_origins[i].s_id;
300 i++);
301 if (arp_origins[i].s_name) {
302 origin = arp_origins[i].s_name;
303 } else {
304 origin = "-";
308 * Format the age
310 UM_ZERO(age, sizeof(age));
311 if (!(ai->aap_flags & ARPF_VALID)) {
312 strcpy(age, "-");
313 } else {
314 sprintf(age, "%d", ai->aap_age);
318 * Print the ARP information
320 printf("%-8s %-5s %3s %s\n ATM address = %s\n IP address = %s\n",
321 ai->aap_intf,
322 flags,
323 age,
324 origin,
325 atm_addr,
326 ip_addr);
331 * Print ARP server information
333 * Arguments:
334 * si pointer to a struct air_asrv_rsp
336 * Returns:
337 * none
340 void
341 print_asrv_info(struct air_asrv_rsp *si)
343 int i;
344 const char *atm_addr, *state;
345 struct in_addr *addr;
348 * Print a header if it hasn't been done yet.
350 if (!asrv_hdr) {
351 printf(ASRV_HDR);
352 asrv_hdr = 1;
356 * Format the ATM address of the ARP server
358 atm_addr = format_atm_addr(&si->asp_addr);
361 * Format the server state
363 for (i=0; arpserver_states[i].s_name != NULL &&
364 si->asp_state != arpserver_states[i].s_id;
365 i++);
366 if (arpserver_states[i].s_name) {
367 state = arpserver_states[i].s_name;
368 } else {
369 state = "-";
373 * Print the ARP server information
375 printf("%-8s %-8s %s\n",
376 si->asp_intf,
377 state,
378 atm_addr);
381 * Format and print the LIS prefixes
383 if (si->asp_nprefix) {
384 addr = (struct in_addr *)((u_long)si +
385 sizeof(struct air_asrv_rsp));
386 printf(" LIS = ");
387 for (i = 0; i < si->asp_nprefix; i++) {
388 printf("%s", inet_ntoa(*addr));
389 addr++;
390 printf("/0x%0lx", (unsigned long)ntohl(addr->s_addr));
391 addr++;
392 if (i < si->asp_nprefix -1)
393 printf(", ");
395 printf("\n");
401 * Print adapter configuration information
403 * Arguments:
404 * si pointer to a struct air_cfg_rsp
406 * Returns:
407 * none
410 void
411 print_cfg_info(struct air_cfg_rsp *si)
413 const char *adapter, *bus, *media, *vendor;
416 * Print a header if it hasn't been done yet.
418 if (!cfg_hdr) {
419 printf(CFG_HDR);
420 cfg_hdr = 1;
424 * Format the vendor name and adapter type
426 vendor = get_vendor(si->acp_vendor);
427 adapter = get_adapter(si->acp_device);
430 * Format the communications medium
432 media = get_media_type(si->acp_media);
433 bus = get_bus_type(si->acp_bustype);
436 * Print the ARP server information
438 printf("%-8s %-8s %-8s %-14s %-4s %ld\n",
439 si->acp_intf,
440 vendor,
441 adapter,
442 media,
443 bus,
444 si->acp_serial);
445 printf(" MAC address = %s\n",
446 format_mac_addr(&si->acp_macaddr));
447 printf(" Hardware version = %s\n", si->acp_hard_vers);
448 printf(" Firmware version = %s\n", si->acp_firm_vers);
453 * Print interface information
455 * Arguments:
456 * ni pointer to a struct air_int_rsp
458 * Returns:
459 * none
462 void
463 print_intf_info(struct air_int_rsp *ni)
465 int i;
466 char nif_names[(IFNAMSIZ *2)+4];
467 char *atm_addr;
468 const char *sigmgr = "-", *state_name = "-";
469 const struct state *s_t;
472 * Print a header
474 printf(INTF_HDR);
477 * Translate signalling manager name
479 for (i=0; proto_states[i].p_state != NULL; i++)
480 if (ni->anp_sig_proto == proto_states[i].p_id)
481 break;
482 if (proto_states[i].p_state != NULL)
483 sigmgr = proto_states[i].p_name;
486 * Get the signalling manager state
488 if (proto_states[i].p_state != NULL) {
489 s_t = proto_states[i].p_state;
490 for (i=0; s_t[i].s_name != NULL; i++)
491 if (ni->anp_sig_state == s_t[i].s_id)
492 break;
493 if (s_t[i].s_name != NULL)
494 state_name = s_t[i].s_name;
498 * Format the ATM address
500 atm_addr = format_atm_addr(&ni->anp_addr);
503 * Get the range of NIFs on the physical interface
505 UM_ZERO(nif_names, sizeof(nif_names));
506 if (strlen(ni->anp_nif_pref) == 0) {
507 strcpy(nif_names, "-");
508 } else {
509 strcpy(nif_names, ni->anp_nif_pref);
510 strcat(nif_names, "0");
511 if (ni->anp_nif_cnt > 1) {
512 strcat(nif_names, " - ");
513 strcat(nif_names, ni->anp_nif_pref);
514 sprintf(&nif_names[strlen(nif_names)], "%d",
515 ni->anp_nif_cnt-1);
521 * Print the interface information
523 printf("%-9s %-7s %s\n",
524 ni->anp_intf,
525 sigmgr,
526 state_name);
527 printf(" ATM address = %s\n", atm_addr);
528 printf(" Network interfaces: %s\n", nif_names);
533 * Print IP address map information
535 * Arguments:
536 * ai pointer to a struct air_arp_rsp
538 * Returns:
539 * none
542 void
543 print_ip_vcc_info(struct air_ip_vcc_rsp *ai)
545 int i;
546 const char *ip_addr, *state;
547 char flags[32], vpi_vci[16];
548 struct sockaddr_in *sin;
551 * Print a header if it hasn't been done yet.
553 if (!ip_vcc_hdr) {
554 printf(IP_VCC_HDR);
555 ip_vcc_hdr = 1;
559 * Format the IP address
561 sin = (struct sockaddr_in *)&ai->aip_dst_addr;
562 ip_addr = format_ip_addr(&sin->sin_addr);
565 * Format the VPI/VCI
567 if (ai->aip_vpi == 0 && ai->aip_vci == 0) {
568 strcpy(vpi_vci, " - -");
569 } else {
570 sprintf(vpi_vci, "%3d %5d", ai->aip_vpi, ai->aip_vci);
574 * Decode VCC flags
576 UM_ZERO(flags, sizeof(flags));
577 if (ai->aip_flags & IVF_PVC) {
578 strcat(flags, "P");
580 if (ai->aip_flags & IVF_SVC) {
581 strcat(flags, "S");
583 if (ai->aip_flags & IVF_LLC) {
584 strcat(flags, "L");
586 if (ai->aip_flags & IVF_MAPOK) {
587 strcat(flags, "M");
589 if (ai->aip_flags & IVF_NOIDLE) {
590 strcat(flags, "N");
594 * Get the state of the VCC
596 for (i=0; ip_vcc_states[i].s_name != NULL &&
597 ai->aip_state != ip_vcc_states[i].s_id;
598 i++);
599 if (ip_vcc_states[i].s_name) {
600 state = ip_vcc_states[i].s_name;
601 } else {
602 state = "-";
606 * Print the IP VCC information
608 printf("%-8s %9s %-7s %-5s %s\n",
609 ai->aip_intf,
610 vpi_vci,
611 state,
612 flags,
613 ip_addr);
618 * Print network interface information
620 * Arguments:
621 * ni pointer to a struct air_int_rsp
623 * Returns:
624 * none
627 void
628 print_netif_info(struct air_netif_rsp *ni)
630 const char *ip_addr;
631 struct sockaddr_in *sin;
634 * Print a header
636 if (!netif_hdr) {
637 netif_hdr++;
638 printf(NETIF_HDR);
642 * Format the protocol address
644 sin = (struct sockaddr_in *)&ni->anp_proto_addr;
645 ip_addr = format_ip_addr(&sin->sin_addr);
648 * Print the network interface information
650 printf("%-8s %-8s %s\n",
651 ni->anp_intf,
652 ni->anp_phy_intf,
653 ip_addr);
658 * Print physical interface statistics
660 * Arguments:
661 * pi pointer to a struct air_phy_stat_rsp
663 * Returns:
664 * none
667 void
668 print_intf_stats(struct air_phy_stat_rsp *pi)
671 * Print a header if it hasn't already been done
673 if (!phy_stats_hdr) {
674 printf(PHY_STATS_HDR);
675 phy_stats_hdr = 1;
679 * Print the interface statistics
681 printf("%-9s %7ld %8ld %5ld %7ld %8ld %5ld %5ld\n",
682 pi->app_intf,
683 pi->app_ipdus,
684 pi->app_ibytes,
685 pi->app_ierrors,
686 pi->app_opdus,
687 pi->app_obytes,
688 pi->app_oerrors,
689 pi->app_cmderrors);
694 * Print VCC statistics
696 * Arguments:
697 * vi pointer to VCC statistics to print
699 * Returns:
700 * none
703 void
704 print_vcc_stats(struct air_vcc_rsp *vi)
708 * Print a header if it hasn't already been done
710 if (!vcc_stats_hdr) {
711 printf(VCC_STATS_HDR);
712 vcc_stats_hdr = 1;
716 * Print the VCC statistics
718 printf("%-9s %3d %4d",
719 vi->avp_intf,
720 vi->avp_vpi,
721 vi->avp_vci);
722 if ( vi->avp_type & VCC_IN )
723 printf ( " %7ld %8ld %5ld",
724 vi->avp_ipdus,
725 vi->avp_ibytes,
726 vi->avp_ierrors);
727 else
728 printf ( " - - -" );
730 if ( vi->avp_type & VCC_OUT )
731 printf ( " %7ld %8ld %5ld\n",
732 vi->avp_opdus,
733 vi->avp_obytes,
734 vi->avp_oerrors);
735 else
736 printf ( " - - -\n" );
741 * Print VCC information
743 * Arguments:
744 * vi pointer to a struct air_vcc_rsp
746 * Returns:
747 * none
750 void
751 print_vcc_info(struct air_vcc_rsp *vi)
753 int i;
754 const char *aal_name = "-" , *encaps_name = "-", *owner_name = "-";
755 const char *state_name = "-", *type_name = "-";
756 char dir_name[10];
757 const struct state *s_t;
760 * Print a header if it hasn't already been done
762 if (!vcc_hdr) {
763 printf(VCC_HDR);
764 vcc_hdr = 1;
768 * Translate AAL
770 for (i=0; aals[i].a_name != NULL; i++)
771 if (vi->avp_aal == aals[i].a_id)
772 break;
773 if (aals[i].a_name)
774 aal_name = aals[i].a_name;
777 * Translate VCC type
779 if (vi->avp_type & VCC_PVC)
780 type_name = "PVC";
781 else if (vi->avp_type & VCC_SVC)
782 type_name = "SVC";
784 * Translate VCC direction
786 UM_ZERO(dir_name, sizeof(dir_name));
787 if (vi->avp_type & VCC_IN)
788 strcat(dir_name, "In");
789 if (vi->avp_type & VCC_OUT)
790 strcat(dir_name, "Out");
791 if (strlen(dir_name) == 0)
792 strcpy(dir_name, "-");
795 * Translate state
797 for (i=0; proto_states[i].p_state != NULL; i++)
798 if (vi->avp_sig_proto == proto_states[i].p_id)
799 break;
800 if (proto_states[i].p_state) {
801 s_t = proto_states[i].v_state;
802 for (i=0; s_t[i].s_name != NULL; i++)
803 if (vi->avp_state == s_t[i].s_id)
804 break;
805 if (s_t[i].s_name)
806 state_name = s_t[i].s_name;
810 * Translate encapsulation
812 for (i=0; encaps[i].e_name != NULL; i++)
813 if (vi->avp_encaps == encaps[i].e_id)
814 break;
815 if (encaps[i].e_name)
816 encaps_name = encaps[i].e_name;
819 * Print the VCC information
821 printf("%-9s %3d %5d %-4s %-4s %-5s %-8s %-8s ",
822 vi->avp_intf,
823 vi->avp_vpi,
824 vi->avp_vci,
825 aal_name,
826 type_name,
827 dir_name,
828 state_name,
829 encaps_name);
832 * Print VCC owners' names
834 for (i = 0, owner_name = vi->avp_owners;
835 i < O_CNT - 1 && strlen(owner_name);
836 i++, owner_name += (T_ATM_APP_NAME_LEN + 1)) {
837 if (i > 0)
838 printf(", ");
839 printf("%s", owner_name);
841 if (i == 0)
842 printf("-");
843 printf("\n");
846 * Print destination address if it's an SVC
848 if (vi->avp_type & VCC_SVC) {
849 printf(" Dest = %s\n",
850 format_atm_addr(&vi->avp_daddr));
856 * Print network interface information
858 * Arguments:
859 * ni pointer to a struct air_int_rsp
861 * Returns:
862 * none
865 void
866 print_version_info(struct air_version_rsp *vi)
868 char version_str[80];
871 * Print a header
873 if (!version_hdr) {
874 version_hdr++;
875 printf(VERSION_HDR);
879 * Print the interface information
881 sprintf(version_str, "%d.%d",
882 ATM_VERS_MAJ(vi->avp_version),
883 ATM_VERS_MIN(vi->avp_version));
884 printf("%7s\n", version_str);