Commit f71c0368 authored by garciay's avatar garciay
Browse files

Enhance secured part of GN dissectors

Bug fixed on GnTrigger
parent 93546fb5
Loading
Loading
Loading
Loading
+108 −29
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@ static gint ett_depv = -1;
static gint ett_depv_addr = -1;
static gint ett_st = -1;
static gint ett_secdata = -1;
static gint ett_2dlocation = -1;
static gint ett_3dlocation = -1;

/* Basic Header fields */
static int hf_gn_basicheader = -1;
@@ -153,9 +155,10 @@ static int hf_gn_reserved2 = -1;
/* GeoUnicast fields */
static int hf_gn_guc = -1;

/* GeoArea fields */
/* GeoArea fields, 2D/3DLocation */
static int hf_gn_area_lat = -1;
static int hf_gn_area_long = -1;
static int hf_gn_area_elev = -1;
static int hf_gn_area_a = -1;
static int hf_gn_area_b = -1;
static int hf_gn_area_angle = -1;
@@ -214,12 +217,16 @@ static int hf_gn_sh_field_type = -1;
static int hf_gn_sh_field_cert_chain = -1;
static int hf_gn_sh_field_cert_chain_length = -1;
static int hf_gn_sh_field_sig = -1;
static int hf_gn_sh_2dlocation = -1;
static int hf_gn_sh_3dlocation = -1;
static int hf_gn_sh_field_pubkey = -1;
static int hf_gn_sh_field_gentime = -1;
static int hf_gn_sh_field_gentimestddev = -1;
static int hf_gn_sh_field_exptime = -1;
static int hf_gn_sh_field_starttime = -1;
static int hf_gn_sh_field_endtime = -1;
static int hf_gn_sh_field_startendtime = -1;
static int hf_gn_sh_field_startduration = -1;
static int hf_gn_sh_field_elev = -1;
static int hf_gn_sh_field_hashedid3 = -1;
static int hf_gn_sh_field_hashedid8 = -1;
@@ -548,6 +555,59 @@ static int tree_gn_cert_time32(tvbuff_t *tvb, proto_tree *ext_tree, int hf_gn_ty
  return 4;
}

/* Interpret 3D location */
static int tree_gn_3dpos(tvbuff_t *tvb, proto_tree *ext_tree, int offset)
{
  double coordinate = 0.0;
  guint16 elevation = 0;
  gint32 tmp_ll = 0;
  guint16 offset_extra = 0;

  proto_item *ti = NULL;
  proto_tree *loc_tree = NULL;

  ti = proto_tree_add_item(ext_tree, hf_gn_sh_3dlocation, tvb, offset, 10, FALSE); 
  loc_tree = proto_item_add_subtree(ti, ett_3dlocation);

  /* Latitude */
  tmp_ll = (gint32)tvb_get_ntohl(tvb, offset);
  coordinate = tmp_ll / 10000000.0;
  proto_tree_add_int_format_value(loc_tree, hf_gn_area_lat, tvb, offset, 4, FALSE,
				  "%02d°%02d'%02.2f\"%c (%d)",
				  abs((int)coordinate),
				  abs((int)((coordinate - (int)coordinate) * 60)),
				  fabs(fmod((coordinate - (int)coordinate) * 3600,60)),
				  (coordinate >= 0.0)?'N':'S',
				  tmp_ll
				  );
  offset_extra += 4;
  offset += 4;

  /* Longitude */
  tmp_ll = (gint32)tvb_get_ntohl(tvb, offset);
  coordinate = tmp_ll / 10000000.0;
  proto_tree_add_int_format_value(loc_tree, hf_gn_area_long, tvb, offset, 4, FALSE,
				  "%02d°%02d'%02.2f\"%c (%d)",
				  abs((int)coordinate),
				  abs((int)((coordinate - (int)coordinate) * 60)),
				  fabs(fmod((coordinate - (int)coordinate) * 3600,60)),
				  (coordinate >= 0.0)?'E':'W',
				  tmp_ll
				  );
  offset_extra += 4;
  offset += 4;

  elevation = (guint16)(tvb_get_guint8(tvb, offset) << 8) | (guint16)tvb_get_guint8(tvb, offset + 1);
  proto_tree_add_uint_format_value(loc_tree, hf_gn_area_elev, tvb, offset, 2, FALSE,
				  "%d meter(s)",
				  elevation
				  );
  offset_extra += 2;
  offset += 2;
  
  return offset_extra;
}

/* Interpret 2D location */
static int tree_gn_2dpos(tvbuff_t *tvb, proto_tree *ext_tree, int offset)
{
@@ -555,10 +615,16 @@ static int tree_gn_2dpos(tvbuff_t *tvb, proto_tree *ext_tree, int offset)
  gint32 tmp_ll = 0;
  guint16 offset_extra = 0;

  proto_item *ti = NULL;
  proto_tree *loc_tree = NULL;

  ti = proto_tree_add_item(ext_tree, hf_gn_sh_2dlocation, tvb, offset, 8, FALSE); 
  loc_tree = proto_item_add_subtree(ti, ett_2dlocation);

  /* Latitude */
  tmp_ll = (gint32)tvb_get_ntohl(tvb, offset);
  coordinate = tmp_ll / 10000000.0;
  proto_tree_add_int_format_value(ext_tree, hf_gn_area_lat, tvb, offset, 4, FALSE,
  proto_tree_add_int_format_value(loc_tree, hf_gn_area_lat, tvb, offset, 4, FALSE,
				  "%02d°%02d'%02.2f\"%c (%d)",
				  abs((int)coordinate),
				  abs((int)((coordinate - (int)coordinate) * 60)),
@@ -572,7 +638,7 @@ static int tree_gn_2dpos(tvbuff_t *tvb, proto_tree *ext_tree, int offset)
  /* Longitude */
  tmp_ll = (gint32)tvb_get_ntohl(tvb, offset);
  coordinate = tmp_ll / 10000000.0;
  proto_tree_add_int_format_value(ext_tree, hf_gn_area_long, tvb, offset, 4, FALSE,
  proto_tree_add_int_format_value(loc_tree, hf_gn_area_long, tvb, offset, 4, FALSE,
				  "%02d°%02d'%02.2f\"%c (%d)",
				  abs((int)coordinate),
				  abs((int)((coordinate - (int)coordinate) * 60)),
@@ -1234,7 +1300,7 @@ static int tree_gn_cert(tvbuff_t *tvb, proto_tree *ext_tree, int offset)
	    break;
	  case 1:
	    // time start and end
	    tree_gn_cert_time32(tvb, shfc_tree, hf_gn_sh_field_starttime, offset);
	    tree_gn_cert_time32(tvb, shfc_tree, hf_gn_sh_field_startendtime, offset);
	    offset += 4;
	    hdrlen -= 4;
	    validr_len -= 4;
@@ -1245,7 +1311,7 @@ static int tree_gn_cert(tvbuff_t *tvb, proto_tree *ext_tree, int offset)
	    break;
	  case 2:
	    // time start and duration
	    tree_gn_cert_time32(tvb, shfc_tree, hf_gn_sh_field_starttime, offset);
	    tree_gn_cert_time32(tvb, shfc_tree, hf_gn_sh_field_startduration, offset);
	    offset += 4;
	    hdrlen -= 4;
	    validr_len -= 4;
@@ -1749,6 +1815,7 @@ dissect_secured_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int
      int extraoffset;
      int validr_len;
      int validr_len_size;
      int off_size;
    
      /* Header Field Type */
      hdrfld_type = tvb_get_guint8(tvb, offset);
@@ -1781,15 +1848,9 @@ dissect_secured_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int
	break;
      case 3:
	// gen location
	proto_tree_add_item(shf_tree, hf_gn_area_lat, tvb, offset, 4, FALSE);     
	offset += 4;
	hdrlen -= 4;
	proto_tree_add_item(shf_tree, hf_gn_area_long, tvb, offset, 4, FALSE);     
	offset += 4;
	hdrlen -= 4;
	proto_tree_add_item(shf_tree, hf_gn_sh_field_elev, tvb, offset, 2, FALSE);     
	offset += 2;
	hdrlen -= 2;
    off_size = tree_gn_3dpos(tvb, shf_tree, offset);
	offset += off_size;
	hdrlen -= off_size;
	break;
      case 4: {
	// req unrecognised certificate
@@ -1868,13 +1929,13 @@ dissect_secured_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int
	  proto_tree_add_item(shfc_tree, hf_gn_sh_field_signinfo_type, tvb, offset, 1, FALSE);
	  offset += 1;
	  hdrlen -= 1;
	  extralen -= 1;
	  //extralen -= 1;
	
	  switch (signinfo_type) {
	  case 0:
	    // self
	    offset += extralen;
	    hdrlen -= extralen;
	    //offset += extralen;
	    //hdrlen -= extralen;
	    break;
	  case 1:
	    // cert digest with ecdsap256
@@ -1884,24 +1945,24 @@ dissect_secured_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int
	    break;
	  case 2:
	    // cert
	    offset += extralen;
	    hdrlen -= extralen;
	    //offset += extralen;
	    //hdrlen -= extralen;
	    break;
	  case 3:
	    // cert chain
	    offset += extralen;
	    hdrlen -= extralen;
	    //offset += extralen;
	    //hdrlen -= extralen;
	    break;
	  case 4:
	    // cert digest with other alg
	    offset += extralen;
	    hdrlen -= extralen;
	    //offset += extralen;
	    //hdrlen -= extralen;
	    break;
	  default:
	    offset += extralen;
	    hdrlen -= extralen;
	    //offset += extralen;
	    //hdrlen -= extralen;
	    break;
	  }
	  } // End of 'switch' statement
	
	  // subject info
	  proto_tree_add_item(shfc_tree, hf_gn_sh_field_subject_type, tvb, offset, 1, FALSE);
@@ -2128,7 +2189,7 @@ dissect_secured_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int
	      offset += 4;
	      hdrlen -= 4;
	      validr_len -= 4;
	      tree_gn_cert_time32(tvb, shfc_tree, hf_gn_sh_field_endtime, offset);
	      tree_gn_cert_time32(tvb, shfc_tree, hf_gn_sh_field_startendtime, offset);
	      offset += 4;
	      hdrlen -= 4;
	      validr_len -= 4;
@@ -2442,6 +2503,12 @@ proto_register_gn(void)
    { &hf_gn_sh_field_sig,
      {"Signature", "gn.sh.sig", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_2dlocation,
      {"2DLocation", "gn.sh.2dlocation", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_3dlocation,
      {"3DLocation", "gn.sh.3dlocation", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_field_gentime,
      {"Generation Time", "gn.sh.gentime", FT_UINT64, BASE_DEC, NULL, 0x00, NULL, HFILL}
    },
@@ -2454,9 +2521,15 @@ proto_register_gn(void)
    { &hf_gn_sh_field_starttime,
      {"Start Time", "gn.sh.starttime", FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_field_startduration,
      {"Start Time", "gn.sh.startduration", FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_field_endtime,
      {"End Time", "gn.sh.endtime", FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_field_startendtime,
      {"End Time", "gn.sh.startendtime", FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_sh_field_elev,
      {"Elevation", "gn.sh.elev", FT_UINT16, BASE_HEX, NULL, 0x00, NULL, HFILL}
    },
@@ -2647,6 +2720,9 @@ proto_register_gn(void)
    { &hf_gn_area_long,
      {"Longitude", "gn.area.long", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL}
    },
    { &hf_gn_area_elev,
      {"Elevation", "gn.area.elev", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}
    },
    { &hf_gn_area_a,
      {"Distance A", "gn.area.a", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL}
    },
@@ -2753,7 +2829,7 @@ proto_register_gn(void)
    },
    { &hf_gn_de_long,
      {"Longitude", "gn.depv.long", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL}
    }
    },

  };
  
@@ -2783,6 +2859,8 @@ proto_register_gn(void)
    &ett_depv,
    &ett_depv_addr,
    &ett_secdata,
    &ett_2dlocation,
    &ett_3dlocation
  };

  /* Register the protocol name and description */
@@ -2799,7 +2877,8 @@ proto_register_gn(void)

  /* Register preferences module */
  gn_module = prefs_register_protocol(proto_gn, proto_reg_handoff_gn);
  new_register_dissector("gn", dissect_gn, proto_gn);
//  new_register_dissector("gn", dissect_gn, proto_gn);
  register_dissector("gn", dissect_gn, proto_gn);

  /* Register a sample port preference   */
  prefs_register_uint_preference(gn_module, "ethertype", "GeoNetworking Ethertype (in hex)",
+21 −25
Original line number Diff line number Diff line
@@ -174,8 +174,6 @@ void proto_reg_handoff_ut(void);
/* Initialize the protocol and registered fields */
static int proto_ut = -1;
static int hf_command = -1;
/* Set to 0xff is UtInitialise detects a secured mode */
static guint8 SecuredMode = 0;

/* UT Initialise */
static int hf_initialize = -1;
@@ -350,6 +348,7 @@ static int hf_repetition_interval = -1;
static int hf_alacarte_length = -1;
static int hf_alacarte = -1;
/* GN Parameters */
static int hf_gn_address = -1;
static int hf_shape = -1;
static int hf_lifetime = -1;
static int hf_trafficclass = -1;
@@ -527,17 +526,12 @@ static int dissect_ut_initialise(tvbuff_t *tvb, proto_tree *header_tree, int off
  proto_tree *tree = NULL;
  proto_item *ti = NULL;
  guint64 hashedId8;
  int l_ut_initialise = L_UT_INITIALISE;

  /* Extract HashedId8 value */
  hashedId8 = tvb_get_ntoh64(tvb, offset + 1);
  if ((tvb_length(tvb) - offset) != L_UT_INITIALISE) {
    SecuredMode = 0xff;
    l_ut_initialise += (tvb_length(tvb) - offset);
  }
  
  /* UT command tree */
  ti = proto_tree_add_item(header_tree, hf_initialize, tvb, offset, l_ut_initialise, FALSE);
  proto_item_append_text(ti, ": Secured mode: %s", val_to_str(SecuredMode, ut_securedmode_names, "Unknown (0x%02x)"));
  ti = proto_tree_add_item(header_tree, hf_initialize, tvb, offset, L_UT_INITIALISE, FALSE);
  tree = proto_item_add_subtree(ti, ett_ut_command);

  /* UtInitialize */
@@ -548,14 +542,6 @@ static int dissect_ut_initialise(tvbuff_t *tvb, proto_tree *header_tree, int off
  proto_tree_add_item(tree, hf_hashed_id8, tvb, offset, L_HASHEDID8, FALSE);
  offset += L_HASHEDID8; 

  if (SecuredMode == 0xff) {
    // Extract the certificate
    int l_certificate;
    
    l_certificate = tvb_length(tvb) - (L_UT_COMMAND + L_HASHEDID8); // Length in bytes
    proto_tree_add_item(tree, hf_hashed_id8, tvb, offset, l_certificate, FALSE);
    offset += l_certificate; 
  }
  return offset;
} // End of function dissect_ut_initialise

@@ -1251,15 +1237,16 @@ static int dissect_ut_gn_geounicast(tvbuff_t *tvb, proto_tree *header_tree, int

  /* GnGenerateGeoUnicast tree */
  /* DstGnAddr */
  proto_tree_add_item(tree, hf_station_id, tvb, offset, L_SHAPE, FALSE);
  proto_tree_add_item(tree, hf_gn_address, tvb, offset, L_DSTGNADDR, FALSE);
  offset += L_DSTGNADDR;
  /* Lifetime */
  proto_tree_add_item(tree, hf_lifetime, tvb, offset, L_DSTGNADDR, FALSE);
  proto_tree_add_item(tree, hf_lifetime, tvb, offset, L_LIFETIME, FALSE);
  offset += L_LIFETIME;
  /* TrafficClass */
  proto_tree_add_item(tree, hf_trafficclass, tvb, offset, L_TRAFFICCLASS, FALSE);
  offset += L_TRAFFICCLASS;
  /* PayloadLength */
  if (offset < (int)tvb_length(tvb)) {
  payload_length = (guint16)((tvb_get_guint8(tvb, offset) << 8) & 0xff00) | (guint16)(tvb_get_guint8(tvb, offset + 1) & 0x00ff);
  proto_tree_add_item(tree, hf_payloadlength, tvb, offset, L_PAYLOADLENGTH, FALSE);
  offset += L_PAYLOADLENGTH;
@@ -1267,6 +1254,7 @@ static int dissect_ut_gn_geounicast(tvbuff_t *tvb, proto_tree *header_tree, int
    proto_tree_add_item(tree, hf_payload, tvb, offset, payload_length, FALSE);
    offset += payload_length;
  }
  }
  
  return offset;
} // End of function dissect_ut_gn_geounicast
@@ -1315,6 +1303,7 @@ static int dissect_ut_gn_geobroadcast(tvbuff_t *tvb, proto_tree *header_tree, in
  proto_tree_add_item(tree, hf_angle, tvb, offset, L_ANGLE, FALSE);
  offset += L_ANGLE;
  /* PayloadLength */
  if (offset < (int)tvb_length(tvb)) {
  payload_length = (guint16)((tvb_get_guint8(tvb, offset) << 8) & 0xff00) | (guint16)(tvb_get_guint8(tvb, offset + 1) & 0x00ff);
  proto_tree_add_item(tree, hf_payloadlength, tvb, offset, L_PAYLOADLENGTH, FALSE);
  offset += L_PAYLOADLENGTH;
@@ -1322,7 +1311,7 @@ static int dissect_ut_gn_geobroadcast(tvbuff_t *tvb, proto_tree *header_tree, in
    proto_tree_add_item(tree, hf_payload, tvb, offset, payload_length, FALSE);
    offset += payload_length;
  }
  
  }
  return offset;
} // End of function dissect_ut_gn_geobroadcast

@@ -1370,6 +1359,7 @@ static int dissect_ut_gn_geoanycast(tvbuff_t *tvb, proto_tree *header_tree, int
  proto_tree_add_item(tree, hf_angle, tvb, offset, L_ANGLE, FALSE);
  offset += L_ANGLE;
  /* PayloadLength */
  if (offset < (int)tvb_length(tvb)) {
  payload_length = (guint16)((tvb_get_guint8(tvb, offset) << 8) & 0xff00) | (guint16)(tvb_get_guint8(tvb, offset + 1) & 0x00ff);
  proto_tree_add_item(tree, hf_payloadlength, tvb, offset, L_PAYLOADLENGTH, FALSE);
  offset += L_PAYLOADLENGTH;
@@ -1377,6 +1367,7 @@ static int dissect_ut_gn_geoanycast(tvbuff_t *tvb, proto_tree *header_tree, int
    proto_tree_add_item(tree, hf_payload, tvb, offset, payload_length, FALSE);
    offset += payload_length;
  }
  }
  
  return offset;
} // End of function dissect_ut_gn_geobroadcast
@@ -1435,6 +1426,7 @@ static int dissect_ut_gn_geotsb(tvbuff_t *tvb, proto_tree *header_tree, int offs
  proto_tree_add_item(tree, hf_trafficclass, tvb, offset, L_TRAFFICCLASS, FALSE);
  offset += L_TRAFFICCLASS;
  /* PayloadLength */
  if (offset < (int)tvb_length(tvb)) {
  payload_length = (guint16)((tvb_get_guint8(tvb, offset) << 8) & 0xff00) | (guint16)(tvb_get_guint8(tvb, offset + 1) & 0x00ff);
  proto_tree_add_item(tree, hf_payloadlength, tvb, offset, L_PAYLOADLENGTH, FALSE);
  offset += L_PAYLOADLENGTH;
@@ -1442,6 +1434,7 @@ static int dissect_ut_gn_geotsb(tvbuff_t *tvb, proto_tree *header_tree, int offs
    proto_tree_add_item(tree, hf_payload, tvb, offset, payload_length, FALSE);
    offset += payload_length;
  }
  }
  
  return offset;
} // End of function dissect_ut_gn_geotsb
@@ -1678,7 +1671,7 @@ static int dissect_ut_gn_trigger_result(tvbuff_t *tvb, proto_tree *header_tree,
} // End of function dissect_ut_gn_trigger_result

/* Code to actually dissect the UT packets */
static int dissect_ut(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
static int dissect_ut_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
  guint32 offset = 0;
  guint8 ut_command = -1;
@@ -1822,7 +1815,7 @@ static int dissect_ut(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void
  }
  
  return 0;
} // End of function dissect_ut
} // End of function dissect_ut_packet

/* Register the protocol with Wireshark */
void
@@ -2214,6 +2207,9 @@ proto_register_ut(void)
    { &hf_alacarte,
      {"alacarte", "ut.denm.flags.alacarte", FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL}
    },
    { &hf_gn_address,
      {"GnAddress", "ut.gn.geoxxxcast.gnaddress", FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL}
    },
    { &hf_shape,
      {"Shape", "ut.gn.geoxxxcast.shape", FT_UINT8, BASE_DEC, VALS(ut_shape_names), 0x00, NULL, HFILL}
    },
@@ -2310,8 +2306,8 @@ proto_register_ut(void)
				       "UT",                            /* short name */
				       "ut"                             /* abbrev     */
				       );
//  new_register_dissector("ut", dissect_ut, proto_ut);
  register_dissector("ut", dissect_ut, proto_ut);
//  new_register_dissector("ut", dissect_ut_packet, proto_ut);
  register_dissector("ut", dissect_ut_packet, proto_ut);

  /* Required function calls to register the header fields and subtrees used */
  proto_register_field_array(proto_ut, hf, array_length(hf));
@@ -2326,6 +2322,6 @@ void
proto_reg_handoff_ut(void)
{
  dissector_handle_t ut_handle;
  ut_handle = new_create_dissector_handle(dissect_ut, proto_ut);
  ut_handle = new_create_dissector_handle(dissect_ut_packet, proto_ut);
  dissector_add_uint("udp.port", UT_PROTOCOL_PORT, ut_handle);
}