Ethereal-dev: [Ethereal-dev] Dissector for MATIP Type A Host-to-Host

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Geoffroy DU_BOUAYS_DE_COUESBOUC <Geoffroy.Du_bouays_de_couesbouc@xxxxxxxxxxx>
Date: Fri, 20 Jan 2006 11:30:30 +0100
Hello,
This is a dissector for MATIP traffic (Mapping of Airline Reservation,
Ticketing, and Messaging Traffic over IP)  (RFC 2351).
I have a problem when the session open packet is the first of the frame. The
data are not associated the conversation. I don’t understand why.
Best regards,

Geoffroy

/* packet-matip.c
 * Routines for MATIP (Mapping of Airline Reservation, Ticketing, and Messaging
Traffic over IP)
 * [ RFC 2351 ]
 * The code below is only for MATIP format for Type A Host-to-Host
 *
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@xxxxxxxxxxxx>
 * Copyright 1999 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "moduleinfo.h"

#include <gmodule.h>
#include <string.h>
#include <epan/packet.h>
#include <epan/conversation.h>

#ifndef ENABLE_STATIC
G_MODULE_EXPORT const gchar version[] = VERSION;
#endif


#define TCP_PORT_MATIP 350
#define MATIP_INIT_COUNT 10

/* the GMemChunk base structure */
static GMemChunk *matip_vals = NULL;

typedef struct _matip_entry_t
{
  guint8 hdr_val;
  guint8 h1_val;
  guint8 h2_val;
}matip_entry_t;


void proto_reg_handoff_matip(void);

/* Define the matip proto */
static int proto_matip                      = -1;

/* Define headers in subtree for matip */
static int hf_matip_so_ver                  = -1;
static int hf_matip_so_length               = -1;
static int hf_matip_so_cd                   = -1;
static int hf_matip_so_styp                 = -1;
static int hf_matip_so_rfu8                 = -1;
static int hf_matip_so_mpx                  = -1;
static int hf_matip_so_hdr                  = -1;
static int hf_matip_so_h1                   = -1;
static int hf_matip_so_h2                   = -1;
static int hf_matip_so_rfu16                = -1;
static int hf_matip_so_flow_id              = -1;

static int hf_matip_oc_ver                  = -1;
static int hf_matip_oc_length               = -1;
static int hf_matip_oc_cause                = -1;

static int hf_matip_sc_ver                  = -1;
static int hf_matip_sc_length               = -1;
static int hf_matip_sc_close_cause          = -1;

static int hf_matip_dp_ver                  = -1;
static int hf_matip_dp_length               = -1;
static int hf_matip_dp_h1                   = -1;
static int hf_matip_dp_h2                   = -1;
static int hf_matip_dp_flow_id              = -1;

static int hf_matip_ssq_ver                 = -1;
static int hf_matip_ssq_length              = -1;

static int hf_matip_ssr_ver                 = -1;
static int hf_matip_ssr_length              = -1;


/* Define the trees for matip */
static int ett_matip                        = -1;

/* Some useful information */
static const value_string packet_type_names[] = {
  {254, "Session Open"},
  {253, "Open Confirm"},
  {252, "Session Close"},
  {251, "Session Status Query"},
  {250, "Session Status Response"},
  {000, "Data Packet"},
  {0,   NULL}
};

static const value_string matip_oc_cause[] = {
  {000, "[Connection accepted]"},
  {001, "[Connection refused] No traffic type matching between sender &
recipient"},
  {002, "[Connection refused] Information in so header incoherent"},
  {132, "[Connection refused] Coding refused"},
  {133, "[Connection refused] Unknown identifier"},
  {0,   NULL}
};

static const value_string matip_cd[] = {
  {0, "(padded baudot)"},
  {2, "(IPARS)"},
  {4, "(ASCII)"},
  {6, "(EBCDIC)"},
  {0, NULL}
};

static void dissect_matip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
static void dissect_matip_session_open(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree);
static void dissect_matip_open_confirm(tvbuff_t *tvb, packet_info
*pinfo,proto_tree *tree);
static void dissect_matip_session_close(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree);
static void dissect_matip_data_packet(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree);
static void dissect_matip_ss_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree
*tree);
static void dissect_matip_ss_response(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree);
static void matip_dissector_init( void);


/*******************************************************************************************
 * dissect_matip - The dissector for the Mapping of Airline Traffic over
Internet Protocol *
 *******************************************************************************************/

static void dissect_matip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{

   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   if (check_col(pinfo->cinfo, COL_PROTOCOL))
                col_set_str(pinfo->cinfo, COL_PROTOCOL, "MATIP");


   switch (pkt_type){

   case 254 :
        dissect_matip_session_open(tvb, pinfo, tree);
        break;

   case 253 :
        dissect_matip_open_confirm(tvb, pinfo, tree);
        break;

   case 252 :
        dissect_matip_session_close(tvb, pinfo, tree);
        break;

   case 251 :
        dissect_matip_ss_query(tvb, pinfo, tree);
        break;

    case 250 :
         dissect_matip_ss_response(tvb, pinfo, tree);
         break;

    case 000 :
         dissect_matip_data_packet(tvb, pinfo, tree);
         break;

    default :
         proto_tree_add_text(tree, tvb, 1, 1, "Unknown MATIP type : %d",
pkt_type);
         break;
    }
}


static void dissect_matip_session_open(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree)
{

   guint16 length;
   guint8 cd,mpx,hdr,mpx_hdr,styp,version,h1,h2;
   gchar *cdtypename;
   conversation_t *conv = NULL;
   matip_entry_t *data_matip = NULL;
   proto_tree *ti = NULL;
   proto_tree *matip_tree = NULL;
   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   mpx_hdr = tvb_get_guint8(tvb, 7);
   mpx = (mpx_hdr & 0xc0);
   mpx = mpx/64;
   hdr = (mpx_hdr & 0x30);
   hdr = hdr/16;
   h1 = tvb_get_guint8(tvb, 8);
   h2 = tvb_get_guint8(tvb, 9);

   if (conv == NULL){

      /* create the conversation with the data pointer  */
      conv = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
   }

   if (data_matip == NULL){

      data_matip = g_mem_chunk_alloc(matip_vals);
      data_matip->hdr_val = hdr;
      data_matip->h1_val = h1;
      data_matip->h2_val = h2;

      conversation_add_proto_data(conv, proto_matip, data_matip);
   }

   if (check_col(pinfo->cinfo, COL_INFO)){
                col_clear(pinfo->cinfo, COL_INFO);
   }
   if (check_col(pinfo->cinfo, COL_INFO)){
      col_add_fstr(pinfo->cinfo, COL_INFO, "%s", packettypename);
      col_append_fstr(pinfo->cinfo, COL_INFO, ", H1=0x%x, H2=0x%x", h1, h2);
   }

   if (tree){

      ti = proto_tree_add_item(tree, proto_matip, tvb, 0 , -1, FALSE);
      proto_item_append_text(ti, ", %s", packettypename);

      proto_item_append_text(ti, ", H1=0x%x, H2=0x%x", h1, h2);

      matip_tree = proto_item_add_subtree(ti, ett_matip);

      if (matip_tree){

         version = tvb_get_guint8(tvb, 0);
         if (version == 1){
            proto_tree_add_item(matip_tree, hf_matip_so_ver, tvb, 0, 1, FALSE);
         }
         else proto_item_append_text(matip_tree, ", Unknow version %d: incorrect
packet", version);

         proto_tree_add_item_hidden(matip_tree, hf_matip_session_open, tvb, 1,
1, FALSE);
         proto_tree_add_text(matip_tree, tvb, 1, 1, "Packet type: %s",
packettypename);
         length = tvb_get_ntohs(tvb, 2);
         proto_tree_add_uint_format(matip_tree, hf_matip_so_length, tvb, 2, 2,
length, "Length: %d bytes", length);

         cd = tvb_get_guint8(tvb, 4);
         cd = (cd & 0x07);
         cdtypename = val_to_str(cd, matip_cd, "Unknown coding");
         proto_tree_add_uint_format(matip_tree, hf_matip_so_cd, tvb, 4, 1, cd,
"Coding (CD): %d %s", cd, cdtypename);

         styp = tvb_get_guint8(tvb, 5);
         styp = (styp & 0xf0);
         styp = styp/16;

         switch (styp){

         case 2 :
              proto_tree_add_uint_format(matip_tree, hf_matip_so_styp, tvb, 5,
1, styp, "Traffic subtype (STYP): %d, TYPE A HTH (IATA)", styp);
              break;

         case 8 :
              proto_tree_add_uint_format(matip_tree, hf_matip_so_styp, tvb, 5,
1, styp, "Traffic subtype (STYP): %d, TYPE A HTH (SITA)", styp);
              break;

         default :
              proto_tree_add_text(matip_tree, tvb, 5, 1, "Unknown MATIP subtype:
%d", styp);
              break;
         }

         proto_tree_add_item(matip_tree, hf_matip_so_rfu8, tvb, 6, 1, FALSE);

         proto_tree_add_uint(matip_tree, hf_matip_so_mpx, tvb, 7, 1, mpx);
         proto_tree_add_uint(matip_tree, hf_matip_so_hdr, tvb, 7, 1, hdr);

         proto_tree_add_item(matip_tree, hf_matip_so_h1, tvb, 8, 1, FALSE);
         proto_tree_add_item(matip_tree, hf_matip_so_h2, tvb, 9, 1, FALSE);

         proto_tree_add_item(matip_tree, hf_matip_so_rfu16, tvb, 10, 2, FALSE);

         if (mpx == 1){
            proto_tree_add_item(matip_tree, hf_matip_so_flow_id, tvb, 12, 1,
FALSE);
         }
      }
   }
}


static void dissect_matip_open_confirm(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree)
{

   guint16 length;
   guint8 caus,version,h1=0,h2=0;
   conversation_t *conv = NULL;
   matip_entry_t *data_matip1 = NULL;
   gchar *caustypename;
   proto_tree *ti = NULL;
   proto_tree *matip_tree = NULL;
   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   /* look up the conversation */
   conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);

   if (conv != NULL){

      /* check if we have any data for this conversation */
      data_matip1=conversation_get_proto_data(conv, proto_matip);
   }

   if (data_matip1 != NULL){

      h1 = data_matip1->h1_val;
      h2 = data_matip1->h2_val;
   }

   if (check_col(pinfo->cinfo, COL_INFO)){
                col_clear(pinfo->cinfo, COL_INFO);
   }
   if (check_col(pinfo->cinfo, COL_INFO)){
      col_add_fstr(pinfo->cinfo, COL_INFO, "%s", packettypename);
      col_append_fstr(pinfo->cinfo, COL_INFO, ", H1=0x%x, H2=0x%x", h1, h2);
   }

   if (tree){

      ti = proto_tree_add_item(tree, proto_matip, tvb, 0 , -1, FALSE);
      proto_item_append_text(ti, ", %s", packettypename);
      proto_item_append_text(ti, ", H1=0x%x, H2=0x%x", h1, h2);

      matip_tree = proto_item_add_subtree(ti, ett_matip);

      if (matip_tree){

         version = tvb_get_guint8(tvb, 0);
         if (version == 1){
         proto_tree_add_item(matip_tree, hf_matip_oc_ver, tvb, 0, 1, FALSE);
         }
         else proto_item_append_text(matip_tree, ", Unknow version %d: incorrect
packet", version);

         proto_tree_add_item_hidden(matip_tree, hf_matip_open_confirm, tvb, 1,
1,FALSE);
         proto_tree_add_text(matip_tree, tvb, 1, 1, "Packet type: %s",
packettypename);
         length = tvb_get_ntohs(tvb, 2);
         proto_tree_add_uint_format(matip_tree, hf_matip_so_length, tvb, 2, 2,
length, "Length: %d bytes", length);

         caus = tvb_get_guint8(tvb, 4);
         caustypename = val_to_str(caus, matip_oc_cause, "[Connection refused]
Unknown refused cause");
         proto_tree_add_uint_format(matip_tree, hf_matip_oc_cause, tvb, 4, 1,
caus, "Connection state: %d %s", caus, caustypename);
      }
   }
}


static void dissect_matip_session_close(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree)
{

   guint16 length;
   guint8 cause_close,version,h1=0,h2=0;
   conversation_t *conv = NULL;
   matip_entry_t *data_matip1 = NULL;
   proto_tree *ti = NULL;
   proto_tree *matip_tree = NULL;
   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   /* look up the conversation */
   conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);

   if (conv != NULL){

      /* check if we have any data for this conversation */
      data_matip1=conversation_get_proto_data(conv, proto_matip);
   }

   if (data_matip1 != NULL){

      h1 = data_matip1->h1_val;
      h2 = data_matip1->h2_val;
   }

   if (check_col(pinfo->cinfo, COL_INFO)){
                col_clear(pinfo->cinfo, COL_INFO);
   }
   if (check_col(pinfo->cinfo, COL_INFO)){
      col_add_fstr(pinfo->cinfo, COL_INFO, "%s", packettypename);
      col_append_fstr(pinfo->cinfo, COL_INFO, ", H1=0x%x, H2=0x%x", h1, h2);
   }

   if (tree){

      ti = proto_tree_add_item(tree, proto_matip, tvb, 0 , -1, FALSE);
      proto_item_append_text(ti, ", %s", packettypename);
      proto_item_append_text(ti, ", H1=0x%x, H2=0x%x", h1, h2);

      matip_tree = proto_item_add_subtree(ti, ett_matip);

      if (matip_tree){

         version = tvb_get_guint8(tvb, 0);
         if (version == 1){
         proto_tree_add_item(matip_tree, hf_matip_sc_ver, tvb, 0, 1, FALSE);
         }
         else proto_item_append_text(matip_tree, ", Unknow version %d: incorrect
packet", version);

         proto_tree_add_item_hidden(matip_tree, hf_matip_session_close, tvb, 1,
1,FALSE);
         proto_tree_add_text(matip_tree, tvb, 1, 1, "Packet type: %s",
packettypename);
         length = tvb_get_ntohs(tvb, 2);
         proto_tree_add_uint_format(matip_tree, hf_matip_so_length, tvb, 2, 2,
length, "Length: %d bytes", length);

         cause_close = tvb_get_guint8(tvb, 4);
         if (cause_close == 0){

            proto_tree_add_uint_format(matip_tree, hf_matip_sc_close_cause, tvb,
4, 1, cause_close, "Close cause : %d (Normal close)", cause_close);
         }
         else
         proto_tree_add_text(matip_tree, tvb, 4, 1, "Unknown cause close");

      }
   }
}


static void dissect_matip_data_packet(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree)
{

   guint16 length;
   guint8 hdr=2,version,h1=0,h2=0;
   conversation_t *conv = NULL;
   matip_entry_t *data_matip1 = NULL;
   proto_tree *ti = NULL;
   proto_tree *matip_tree = NULL;
   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   /* look up the conversation */
   conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);

   if (conv != NULL){

      /* check if we have any data for this conversation */
      data_matip1=conversation_get_proto_data(conv, proto_matip);
   }

   if (data_matip1 != NULL){

      hdr = data_matip1->hdr_val;
      h1 = data_matip1->h1_val;
      h2 = data_matip1->h2_val;
   }

   if (check_col(pinfo->cinfo, COL_INFO)){
                col_clear(pinfo->cinfo, COL_INFO);
   }
   if (check_col(pinfo->cinfo, COL_INFO)){
      col_add_fstr(pinfo->cinfo, COL_INFO, "%s", packettypename);
      col_append_fstr(pinfo->cinfo, COL_INFO, ", H1=0x%x, H2=0x%x", h1, h2);
   }

   if (tree){

      ti = proto_tree_add_item(tree, proto_matip, tvb, 0 , -1, FALSE);
      proto_item_append_text(ti, ", %s", packettypename);

      proto_item_append_text(ti, ", H1=0x%x, H2=0x%x", h1, h2);

      matip_tree = proto_item_add_subtree(ti, ett_matip);

      if (matip_tree){

         version = tvb_get_guint8(tvb, 0);
         if (version == 1){
         proto_tree_add_item(matip_tree, hf_matip_dp_ver, tvb, 0, 1, FALSE);
         }
         else proto_item_append_text(matip_tree, ", Unknow version %d: incorrect
packet", version);

         proto_tree_add_item_hidden(matip_tree, hf_matip_data_packet, tvb, 1,
1,FALSE);
         proto_tree_add_text(matip_tree, tvb, 1, 1, "Packet type: %s",
packettypename);
         length = tvb_get_ntohs(tvb, 2);
         proto_tree_add_uint_format(matip_tree, hf_matip_so_length, tvb, 2, 2,
length, "Length: %d bytes", length);

         if (hdr == 0){

            proto_tree_add_item(matip_tree, hf_matip_dp_h1, tvb, 4, 1, FALSE);
            proto_tree_add_item(matip_tree, hf_matip_dp_h2, tvb, 5, 1, FALSE);
            proto_tree_add_item(matip_tree, hf_matip_dp_flow_id, tvb, 6, 1,
FALSE);
            if (length > 7){
               proto_tree_add_text(matip_tree, tvb, 7, -1, "Data (%d bytes)",
tvb_reported_length_remaining(tvb, 7));
            }
         }

         if (hdr == 1){

            proto_tree_add_item(matip_tree, hf_matip_dp_flow_id, tvb, 4, 1,
FALSE);
            if (length > 5){
               proto_tree_add_text(matip_tree, tvb, 5, -1, "Data (%d bytes)",
tvb_reported_length_remaining(tvb, 5));
            }
         }

         if (hdr > 1){

            if (length > 4){
               proto_tree_add_text(matip_tree, tvb, 4, -1, "Data (%d bytes)",
tvb_reported_length_remaining(tvb, 4));
            }
         }
      }
   }
}

static void dissect_matip_ss_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree
*tree)
{

   guint16 length;
   guint8 version,h1=0,h2=0;
   conversation_t *conv = NULL;
   matip_entry_t *data_matip1 = NULL;
   proto_tree *ti = NULL;
   proto_tree *matip_tree = NULL;
   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   /* look up the conversation */
   conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);

   if (conv != NULL){

      /* check if we have any data for this conversation */
      data_matip1=conversation_get_proto_data(conv, proto_matip);
   }

   if (data_matip1 != NULL){

      h1 = data_matip1->h1_val;
      h2 = data_matip1->h2_val;

   }

   if (check_col(pinfo->cinfo, COL_INFO)){
                col_clear(pinfo->cinfo, COL_INFO);
   }
   if (check_col(pinfo->cinfo, COL_INFO)){
      col_add_fstr(pinfo->cinfo, COL_INFO, "%s", packettypename);
      col_append_fstr(pinfo->cinfo, COL_INFO, ", H1=0x%x, H2=0x%x", h1, h2);
   }

   if (tree){

      ti = proto_tree_add_item(tree, proto_matip, tvb, 0 , -1, FALSE);
      proto_item_append_text(ti, ", %s", packettypename);
      proto_item_append_text(ti, ", H1=0x%x, H2=0x%x", h1, h2);

      matip_tree = proto_item_add_subtree(ti, ett_matip);

      if (matip_tree){

         version = tvb_get_guint8(tvb, 0);
         if (version == 1){
         proto_tree_add_item(matip_tree, hf_matip_ssq_ver, tvb, 0, 1, FALSE);
         }
         else proto_item_append_text(matip_tree, ", Unknow version %d: incorrect
packet", version);

         proto_tree_add_item_hidden(matip_tree, hf_matip_session_status_query,
tvb, 1, 1,FALSE);
         proto_tree_add_text(matip_tree, tvb, 1, 1, "Packet type: %s",
packettypename);
         length = tvb_get_ntohs(tvb, 2);
         proto_tree_add_uint_format(matip_tree, hf_matip_ssq_length, tvb, 2, 2,
length, "Length: %d bytes", length);
      }
   }
}

static void dissect_matip_ss_response(tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree)
{

   guint16 length;
   guint8 version,h1=0,h2=0;
   conversation_t *conv = NULL;
   matip_entry_t *data_matip1 = NULL;
   proto_tree *ti = NULL;
   proto_tree *matip_tree = NULL;
   guint pkt_type;
   gchar *packettypename;

   pkt_type = tvb_get_guint8(tvb, 1);

   packettypename = val_to_str(pkt_type, packet_type_names, "Unknown Packet");

   /* look up the conversation */
   conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
   if (conv != NULL){

      /* check if we have any data for this conversation */
      data_matip1 = conversation_get_proto_data(conv, proto_matip);
   }

   if (data_matip1 != NULL){

      h1 = data_matip1->h1_val;
      h2 = data_matip1->h2_val;
   }

   if (check_col(pinfo->cinfo, COL_INFO)){
                col_clear(pinfo->cinfo, COL_INFO);
   }
   if (check_col(pinfo->cinfo, COL_INFO)){
      col_add_fstr(pinfo->cinfo, COL_INFO, "%s", packettypename);
      col_append_fstr(pinfo->cinfo, COL_INFO, ", H1=0x%x, H2=0x%x", h1, h2);
   }

   if (tree){

      ti = proto_tree_add_item(tree, proto_matip, tvb, 0 , -1, FALSE);
      proto_item_append_text(ti, ", %s", packettypename);
      proto_item_append_text(ti, ", H1=0x%x, H2=0x%x", h1, h2);

      matip_tree = proto_item_add_subtree(ti, ett_matip);

      if (matip_tree){

         version = tvb_get_guint8(tvb, 0);
         if (version == 1){
         proto_tree_add_item(matip_tree, hf_matip_ssr_ver, tvb, 0, 1, FALSE);
         }
         else proto_item_append_text(matip_tree, ", Unknow version %d: incorrect
packet", version);

         proto_tree_add_item_hidden(matip_tree,
hf_matip_session_status_response, tvb, 1, 1,FALSE);
         proto_tree_add_text(matip_tree, tvb, 1, 1, "Packet type: %s",
packettypename);
         length = tvb_get_ntohs(tvb, 2);
         proto_tree_add_uint_format(matip_tree, hf_matip_ssr_length, tvb, 2, 2,
length, "Length: %d bytes", length);
      }
   }
}


static void matip_dissector_init( void)
{

    /* destroy memory chunks if needed */

    if ( matip_vals)
            g_mem_chunk_destroy(matip_vals);

       /* now create memory chunks */
       matip_vals = g_mem_chunk_new( "matip_vals", sizeof( matip_entry_t),
MATIP_INIT_COUNT * sizeof( matip_entry_t), G_ALLOC_AND_FREE);
}


/* Register all the bits needed with the filtering engine */
void proto_register_matip(void)
{
    static hf_register_info hf[] =
    {
        { &hf_matip_so_ver,
          { "Version", "matip.so_ver", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The version of the MATIP packet", HFILL }},
        { &hf_matip_so_length,
          { "Length", "matip.so_length", FT_UINT16, BASE_DEC, NULL, 0x0,
            "The length of the MATIP packet", HFILL }},
        { &hf_matip_so_cd,
          { "Coding (CD)", "matip.so_cd", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The type of coding", HFILL }},
        { &hf_matip_so_styp,
          { "Traffic subtype (STYP)", "matip.so_styp", FT_UINT8, BASE_DEC, NULL,
0x0,
            "The traffic subtype", HFILL }},
        { &hf_matip_so_rfu8,
          { "RFU", "matip.so_rfu8", FT_UINT8, BASE_DEC, NULL, 0x0,
            "Reserved for future use", HFILL }},
        { &hf_matip_so_mpx,
          { "Multiplexing (MPX)", "matip.so_mpx", FT_UINT8, BASE_DEC, NULL, 0x0,
            "Specifies the multiplexing used in TCP sessions", HFILL }},
        { &hf_matip_so_hdr,
          { "Header (HDR)", "matip.so_hdr", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The airline's specific address", HFILL }},
        { &hf_matip_so_h1,
          { "H1", "matip.so_h1", FT_UINT8, BASE_HEX, NULL, 0x0,
            "Identifier H1", HFILL }},
        { &hf_matip_so_h2,
          { "H2", "matip.so_h2", FT_UINT8, BASE_HEX, NULL, 0x0,
            "Identifier H2", HFILL }},
        { &hf_matip_so_rfu16,
          { "RFU", "matip.so_rfu16", FT_UINT16, BASE_DEC, NULL, 0x0,
            "Reserved for future use", HFILL }},
        { &hf_matip_so_flow_id,
          { "Flow ID", "matip.so_flow_id", FT_UINT8, BASE_DEC, NULL, 0x0,
            "Identify the multiplexing used", HFILL }},
        { &hf_matip_oc_ver,
          { "Version", "matip.oc_ver", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The version of the MATIP packet", HFILL }},
        { &hf_matip_oc_length,
          { "Length", "matip.oc_length", FT_UINT16, BASE_DEC, NULL, 0x0,
            "The length of the MATIP open confirm packet", HFILL }},
        { &hf_matip_oc_cause,
          { "Cause", "matip.oc_cause", FT_UINT8, BASE_DEC, NULL, 0x0,
            "Acceptance  or refusal cause of connection", HFILL }},
        { &hf_matip_sc_ver,
          { "Version", "matip.sc_ver", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The version of the MATIP packet", HFILL }},
        { &hf_matip_sc_length,
          { "Length", "matip.sc_length", FT_UINT16, BASE_DEC, NULL, 0x0,
            "The length of the MATIP session close packet", HFILL }},
        { &hf_matip_sc_close_cause,
          { "Close cause", "matip.sc_close_cause", FT_UINT8, BASE_DEC, NULL,
0x0,
            "Reason for session closure", HFILL }},
        { &hf_matip_dp_ver,
          { "Version", "matip.dp_ver", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The version of the MATIP packet", HFILL }},
        { &hf_matip_dp_length,
          { "Length", "matip.dp_length", FT_UINT16, BASE_DEC, NULL, 0x0,
            "The length of the MATIP data packet", HFILL }},
        { &hf_matip_dp_h1,
          { "H1", "matip.dp_h1", FT_UINT8, BASE_HEX, NULL, 0x0,
            "H1", HFILL }},
        { &hf_matip_dp_h2,
          { "H2", "matip.dp_h2", FT_UINT8, BASE_HEX, NULL, 0x0,
            "H2", HFILL }},
        { &hf_matip_dp_flow_id,
          { "Flow ID", "matip.dp_flow_id", FT_UINT8, BASE_DEC, NULL, 0x0,
            "ID", HFILL }},
        { &hf_matip_ssq_ver,
          { "Version", "matip.ssq_ver", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The version of the MATIP packet", HFILL }},
        { &hf_matip_ssq_length,
          { "Length", "matip.ssq_length", FT_UINT16, BASE_DEC, NULL, 0x0,
            "The length of the MATIP session status query packet", HFILL }},
        { &hf_matip_ssr_ver,
          { "Version", "matip.ssr_ver", FT_UINT8, BASE_DEC, NULL, 0x0,
            "The version of the MATIP packet", HFILL }},
        { &hf_matip_ssr_length,
          { "Length", "matip.ssr_length", FT_UINT16, BASE_DEC, NULL, 0x0,
            "The length of the MATIP session status response packet", HFILL }},
    };

    static guint *ett[] =
    {
           &ett_matip
    };

    /* Register protocol */
    proto_matip = proto_register_protocol("Mapping of Airline Traffic over
Internet Protocol", "MATIP", "matip");
    proto_register_field_array(proto_matip, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
    register_init_routine( &matip_dissector_init);
}


/* The registration hand-off routine */
void proto_reg_handoff_matip(void)
{
        static int matip_initialized = FALSE;
        static dissector_handle_t matip_handle;

   if (!matip_initialized){

      matip_handle = create_dissector_handle(dissect_matip, proto_matip);
      dissector_add("tcp.port", TCP_PORT_MATIP, matip_handle);
      matip_initialized = TRUE;
   }
}

/* Start the functions we need for the plugin stuff */

#ifndef ENABLE_STATIC

G_MODULE_EXPORT void
plugin_register(void)
{
        /* Register the new protocol, protocol fields, and subtrees */
        if (proto_matip == -1)
        {
                /* Execute protocol initialization only once */
                proto_register_matip();
        }
}

G_MODULE_EXPORT void
plugin_reg_handoff(void)
{
        proto_reg_handoff_matip();
}

#endif

/* End the functions we need for plugin stuff */





----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.