]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-atm.c
NDOize AH, BEEP and DTP decoders
[tcpdump] / print-atm.c
index 4cbb475f1f2093c0e743546a58a1128e3dece5da..611f27cdebbb966dc09c654924db7e2112fe16b9 100644 (file)
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
-#ifndef lint
-static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.47 2006-02-08 16:50:16 hannes Exp $ (LBL)";
-#endif
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -43,18 +39,20 @@ static const char rcsid[] _U_ =
 
 #include "ether.h"
 
+static const char tstr[] = "[|atm]";
+
 #define OAM_CRC10_MASK 0x3ff
 #define OAM_PAYLOAD_LEN 48
 #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */
 #define OAM_CELLTYPE_FUNCTYPE_LEN 1
 
-struct tok oam_f_values[] = {
-    { OAMF4SC, "OAM F4 (segment)" },
-    { OAMF4EC, "OAM F4 (end)" },
+static const struct tok oam_f_values[] = {
+    { VCI_OAMF4SC, "OAM F4 (segment)" },
+    { VCI_OAMF4EC, "OAM F4 (end)" },
     { 0, NULL }
 };
 
-struct tok atm_pty_values[] = {
+static const struct tok atm_pty_values[] = {
     { 0x0, "user data, uncongested, SDU 0" },
     { 0x1, "user data, uncongested, SDU 1" },
     { 0x2, "user data, congested, SDU 0" },
@@ -70,7 +68,7 @@ struct tok atm_pty_values[] = {
 #define OAM_CELLTYPE_AD 0x8
 #define OAM_CELLTYPE_SM 0xf
 
-struct tok oam_celltype_values[] = {
+static const struct tok oam_celltype_values[] = {
     { OAM_CELLTYPE_FM, "Fault Management" },
     { OAM_CELLTYPE_PM, "Performance Management" },
     { OAM_CELLTYPE_AD, "activate/deactivate" },
@@ -83,7 +81,7 @@ struct tok oam_celltype_values[] = {
 #define OAM_FM_FUNCTYPE_CONTCHECK 0x4
 #define OAM_FM_FUNCTYPE_LOOPBACK  0x8
 
-struct tok oam_fm_functype_values[] = {
+static const struct tok oam_fm_functype_values[] = {
     { OAM_FM_FUNCTYPE_AIS, "AIS" },
     { OAM_FM_FUNCTYPE_RDI, "RDI" },
     { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" },
@@ -91,14 +89,14 @@ struct tok oam_fm_functype_values[] = {
     { 0, NULL }
 };
 
-struct tok oam_pm_functype_values[] = {
+static const struct tok oam_pm_functype_values[] = {
     { 0x0, "Forward Monitoring" },
     { 0x1, "Backward Reporting" },
     { 0x2, "Monitoring and Reporting" },
     { 0, NULL }
 };
 
-struct tok oam_ad_functype_values[] = {
+static const struct tok oam_ad_functype_values[] = {
     { 0x0, "Performance Monitoring" },
     { 0x1, "Continuity Check" },
     { 0, NULL }
@@ -106,7 +104,7 @@ struct tok oam_ad_functype_values[] = {
 
 #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1
 
-struct tok oam_fm_loopback_indicator_values[] = {
+static const struct tok oam_fm_loopback_indicator_values[] = {
     { 0x0, "Reply" },
     { 0x1, "Request" },
     { 0, NULL }
@@ -172,7 +170,7 @@ atm_if_print(const struct pcap_pkthdr *h, const u_char *p)
        u_int hdrlen = 0;
 
        if (caplen < 8) {
-               printf("[|atm]");
+               printf("%s", tstr);
                return (caplen);
        }
 
@@ -229,7 +227,7 @@ atm_if_print(const struct pcap_pkthdr *h, const u_char *p)
 /*
  * ATM signalling.
  */
-static struct tok msgtype2str[] = {
+static const struct tok msgtype2str[] = {
        { CALL_PROCEED,         "Call_proceeding" },
        { CONNECT,              "Connect" },
        { CONNECT_ACK,          "Connect_ack" },
@@ -254,26 +252,28 @@ sig_print(const u_char *p, int caplen)
        bpf_u_int32 call_ref;
 
        if (caplen < PROTO_POS) {
-               printf("[|atm]");
+               printf("%s", tstr);
                return;
        }
        if (p[PROTO_POS] == Q2931) {
                /*
-                * protocol:Q.2931 for User to Network Interface 
+                * protocol:Q.2931 for User to Network Interface
                 * (UNI 3.1) signalling
                 */
                printf("Q.2931");
                if (caplen < MSG_TYPE_POS) {
-                       printf(" [|atm]");
+                       printf(" %s", tstr);
                        return;
                }
                printf(":%s ",
                    tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS]));
 
-               if (caplen < CALL_REF_POS+3) {
-                       printf("[|atm]");
-                       return;
-               }
+               /*
+                * The call reference comes before the message type,
+                * so if we know we have the message type, which we
+                * do from the caplen test above, we also know we have
+                * the call reference.
+                */
                call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]);
                printf("CALL_REF:0x%06x", call_ref);
        } else {
@@ -295,24 +295,24 @@ atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
        if (vpi == 0) {
                switch (vci) {
 
-               case PPC:
+               case VCI_PPC:
                        sig_print(p, caplen);
                        return;
 
-               case BCC:
+               case VCI_BCC:
                        printf("broadcast sig: ");
                        return;
 
-               case OAMF4SC: /* fall through */
-               case OAMF4EC:
+               case VCI_OAMF4SC: /* fall through */
+               case VCI_OAMF4EC:
                         oam_print(p, length, ATM_OAM_HEC);
                        return;
 
-               case METAC:
+               case VCI_METAC:
                        printf("meta: ");
                        return;
 
-               case ILMIC:
+               case VCI_ILMIC:
                        printf("ilmi: ");
                        snmp_print(p, length);
                        return;
@@ -349,43 +349,7 @@ struct oam_fm_ais_rdi_t {
     u_int8_t unused[28];
 };
 
-
-#define CRC10_POLYNOMIAL 0x633
-static u_int16_t crc10_table[256];
-
-static void
-gen_crc10_table(void)
-{   
-    register int i, j;
-    register u_int16_t accum;
-    
-    for ( i = 0;  i < 256;  i++ )
-    {
-        accum = ((unsigned short) i << 2);
-        for ( j = 0;  j < 8;  j++ )
-        {
-            if ((accum <<= 1) & 0x400) accum ^= CRC10_POLYNOMIAL;
-        }
-        crc10_table[i] = accum;
-    }
-    return;
-}
-
-static u_int16_t
-verify_crc10_cksum(u_int16_t accum, const u_char *p, int length)
-{
-    register int i;
-
-    for ( i = 0;  i < length;  i++ )
-    {
-        accum = ((accum << 8) & 0x3ff)
-            ^ crc10_table[( accum >> 2) & 0xff]
-            ^ *p++;
-    }
-    return accum;
-}
-
-int 
+int
 oam_print (const u_char *p, u_int length, u_int hec) {
 
     u_int32_t cell_header;
@@ -437,7 +401,7 @@ oam_print (const u_char *p, u_int length, u_int hec) {
                tok2str(oam_fm_loopback_indicator_values,
                        "Unknown",
                        oam_ptr.oam_fm_loopback->loopback_indicator & OAM_FM_LOOPBACK_INDICATOR_MASK),
-               EXTRACT_LE_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag));
+               EXTRACT_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag));
         printf("\n\tLocation-ID ");
         for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) {
             if (idx % 2) {
@@ -465,6 +429,7 @@ oam_print (const u_char *p, u_int length, u_int hec) {
         break;
 
     case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK):
+        /* FIXME */
         break;
 
     default:
@@ -472,11 +437,10 @@ oam_print (const u_char *p, u_int length, u_int hec) {
     }
 
     /* crc10 checksum verification */
-    gen_crc10_table();
     cksum = EXTRACT_16BITS(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN)
         & OAM_CRC10_MASK;
     cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN);
-    
+
     printf("\n\tcksum 0x%03x (%scorrect)",
            cksum,
            cksum_shouldbe == 0 ? "" : "in");