From Rolf Fiedler: support for writing EyeSDN trace files.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 5 Jun 2010 22:59:20 +0000 (22:59 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 5 Jun 2010 22:59:20 +0000 (22:59 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@33107 f5534014-38df-0310-8fa8-9805f1628bb7

AUTHORS
wiretap/eyesdn.c
wiretap/eyesdn.h
wiretap/file_access.c

diff --git a/AUTHORS b/AUTHORS
index 59aa1325abb7c73bc38fd56232dd5fb05dc29fb5..6903a617040653b9c6a7b405fb2916d017a344d9 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -2096,7 +2096,7 @@ Chris Wilson            <chris [AT] mxtelecom.com> {
 
 Rolf Fiedler            <Rolf.Fiedler [AT] Innoventif.com> {
        ISDN TEI management frame support
-       Support for reading EyeSDN USB S0 trace files
+       Support for reading and writing EyeSDN USB S0 trace files
 }
 
 Alastair Maw            <ethereal [AT] almaw.com> {
index c8bd71be0b5d8692b10dd8d8bc3714e074779097..60bc60115ee333fdebdc0c6c30ab9125cfb1c618 100644 (file)
@@ -395,3 +395,143 @@ parse_eyesdn_packet_data(FILE_T fh, int pkt_len, guint8* buf, int *err,
        }
        return TRUE;
 }
+
+
+struct header {
+    int usecs;
+    time_t secs;
+    int channel;
+    int origin;
+    int protocol;
+    int size;
+};
+
+static int write_esc(const guchar *buf, int len, FILE *file)
+{
+    int i, byte;
+    
+    for(i=0; i<len; i++) {
+       byte=buf[i];
+       if(byte == 0xff || byte == 0xfe) {
+           fputc(0xfe, file);
+           byte-=2;
+       }
+       fputc(byte, file);
+    }
+    if(ferror(file)) return -1;
+    else return len;
+}
+
+static int write_header(FILE *file, struct header *hp)
+{
+    unsigned char buf[12];
+    
+    buf[0] = (unsigned char)(0xff & (hp->usecs >> 16));
+    buf[1] = (unsigned char)(0xff & (hp->usecs >> 8));
+    buf[2] = (unsigned char)(0xff & (hp->usecs >> 0));
+    buf[3] = (unsigned char)0;
+    buf[4] = (unsigned char)(0xff & (hp->secs >> 24));
+    buf[5] = (unsigned char)(0xff & (hp->secs >> 16));
+    buf[6] = (unsigned char)(0xff & (hp->secs >> 8));
+    buf[7] = (unsigned char)(0xff & (hp->secs >> 0));
+    buf[8] = (unsigned char) hp->channel;
+    buf[9] = (unsigned char) (hp->origin?1:0) + (hp->protocol << 1);
+    buf[10]= (unsigned char)(0xff &(hp->size >> 8));
+    buf[11]= (unsigned char)(0xff &(hp->size >> 0));
+    
+    return write_esc(buf, 12, file);
+}
+
+static void writeToTrc(FILE *file, struct header *hdr, 
+                      const guchar *buf)
+{
+    fputc(0xff, file); /* start flag */
+    write_header(file, hdr);
+    write_esc(buf, hdr->size, file);
+}
+
+static gboolean eyesdn_dump(wtap_dumper *wdh,
+                           const struct wtap_pkthdr *phdr,
+                           const union wtap_pseudo_header *pseudo_header _U_,
+                           const guchar *pd, int *err);
+
+gboolean eyesdn_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err)
+{
+    wdh->subtype_write=eyesdn_dump;
+    wdh->subtype_close=NULL;
+
+    wdh->bytes_dumped += fprintf(wdh->fh, "EyeSDN");
+    *err=0;
+    return TRUE;
+}
+
+int eyesdn_dump_can_write_encap(int encap)
+{
+    switch (encap) {
+    case WTAP_ENCAP_ISDN:
+    case WTAP_ENCAP_LAYER1_EVENT:
+    case WTAP_ENCAP_DPNSS:
+    case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
+    case WTAP_ENCAP_LAPB:
+    case WTAP_ENCAP_MTP2:
+    case WTAP_ENCAP_BACNET_MS_TP:
+    case WTAP_ENCAP_PER_PACKET:
+       return 0;
+    default:
+       return WTAP_ERR_UNSUPPORTED_ENCAP;
+    }
+}
+
+/* Write a record for a packet to a dump file.
+ *    Returns TRUE on success, FALSE on failure. */
+static gboolean eyesdn_dump(wtap_dumper *wdh,
+                           const struct wtap_pkthdr *phdr,
+                           const union wtap_pseudo_header *pseudo_header _U_,
+                           const guchar *pd, int *err)
+{
+    struct header hdr;    
+
+    hdr.usecs=phdr->ts.nsecs/1000;
+    hdr.secs=phdr->ts.secs;
+    hdr.size=phdr->caplen;
+    hdr.origin = pseudo_header->isdn.uton;
+    hdr.channel = pseudo_header->isdn.channel;
+
+    switch(phdr->pkt_encap) {
+    case WTAP_ENCAP_ISDN:
+       hdr.protocol=EYESDN_ENCAP_ISDN; /* set depending on decoder format and mode */
+       break;
+    case WTAP_ENCAP_LAYER1_EVENT:
+       hdr.protocol=EYESDN_ENCAP_MSG;
+       break;
+    case WTAP_ENCAP_DPNSS:
+       hdr.protocol=EYESDN_ENCAP_DPNSS;
+       break;
+#if 0
+    case WTAP_ENCAP_DASS2:
+       hdr.protocol=EYESDN_ENCAP_DASS2;
+       break;
+#endif
+    case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED:
+       hdr.protocol=EYESDN_ENCAP_ATM;
+       hdr.channel=0x80;
+       break;
+    case WTAP_ENCAP_LAPB:
+       hdr.protocol=EYESDN_ENCAP_LAPB;
+       break;
+    case WTAP_ENCAP_MTP2:
+       hdr.protocol=EYESDN_ENCAP_MTP2;
+       break;
+    case WTAP_ENCAP_BACNET_MS_TP:
+       hdr.protocol=EYESDN_ENCAP_BACNET;
+       break;
+    default:
+       *err=-1;
+       return FALSE;
+    }
+
+    writeToTrc(wdh->fh, &hdr, pd);
+
+    *err=0;
+    return TRUE;
+}
index 5fc74e660e5b7b1f9daa17ad1fb09b70da7153f6..5df4419c0d307e0dded1f2d0d11273a4b5bc0563 100644 (file)
@@ -37,4 +37,7 @@ enum EyeSDN_TYPES {
     EYESDN_ENCAP_BACNET
 };
 
+gboolean eyesdn_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err);
+int eyesdn_dump_can_write_encap(int encap);
+
 #endif
index 333daff7b7cf5d4e78a152374692f970bf4fa301..e424f4ff866bdea5a5655fd0a464838838f36dce 100644 (file)
@@ -476,8 +476,8 @@ static const struct file_type_info dump_open_table_base[] = {
          NULL, NULL },
 
        /* WTAP_FILE_EYESDN */
-       { "EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "*.*", NULL, FALSE,
-               NULL, NULL },
+       { "EyeSDN USB S0/E1 ISDN trace format", "eyesdn", "*.trc", ".trc", FALSE,
+          eyesdn_dump_can_write_encap, eyesdn_dump_open },
 
        /* WTAP_FILE_NETTL */
        { "HP-UX nettl trace", "nettl", "*.TRC0;*.TRC1", ".TRC0", FALSE,