/*  Common function for dissecting 3-byte (ANSI or China) PCs. */
void
dissect_mtp3_3byte_pc(tvbuff_t *tvb, guint offset, proto_tree *tree, gint ett_pc, int hf_pc_string, int hf_pc_network,
		      int hf_pc_cluster, int hf_pc_member, int hf_dpc, int hf_pc)
{
    guint32 pc;
    proto_item *pc_item, *hidden_item;
    proto_tree *pc_tree;
    char pc_string[MAX_STRUCTURED_PC_LENGTH];

    pc = tvb_get_letoh24(tvb, offset);
    mtp3_pc_to_str_buf(pc, pc_string, sizeof(pc_string));

    pc_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);

    /* Add alternate formats of the PC
     * NOTE: each of these formats is shown to the user,
     * so I think that using hidden fields in this case is OK.
     */
    g_snprintf(pc_string, sizeof(pc_string), "%u", pc);
    proto_item_append_text(pc_item, " (%s)", pc_string);
    hidden_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);
    PROTO_ITEM_SET_HIDDEN(hidden_item);
    g_snprintf(pc_string, sizeof(pc_string), "0x%x", pc);
    proto_item_append_text(pc_item, " (%s)", pc_string);
    hidden_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);
    PROTO_ITEM_SET_HIDDEN(hidden_item);

    pc_tree = proto_item_add_subtree(pc_item, ett_pc);

    proto_tree_add_uint(pc_tree, hf_pc_network, tvb, offset + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH, pc);
    proto_tree_add_uint(pc_tree, hf_pc_cluster, tvb, offset + ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH, pc);
    proto_tree_add_uint(pc_tree, hf_pc_member,  tvb, offset + ANSI_MEMBER_OFFSET,  ANSI_NCM_LENGTH, pc);

    /* add full integer values of DPC as hidden for filtering purposes */
    if (hf_dpc) {
	hidden_item = proto_tree_add_uint(pc_tree, hf_dpc, tvb, offset, ANSI_PC_LENGTH, pc);
	PROTO_ITEM_SET_HIDDEN(hidden_item);
    }
    if (hf_pc) {
	hidden_item = proto_tree_add_uint(pc_tree, hf_pc,  tvb, offset, ANSI_PC_LENGTH, pc);
	PROTO_ITEM_SET_HIDDEN(hidden_item);
    }
}
Exemple #2
0
static void
mtp3_addr_to_str_buf(const mtp3_addr_pc_t  *addr_pc_p,
                     gchar *buf, int buf_len)
{
  switch (mtp3_addr_fmt)
  {
    case MTP3_ADDR_FMT_DEC:
      switch (addr_pc_p->type)
      {
        case ITU_STANDARD:
          g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & ITU_PC_MASK);
          break;
        case JAPAN_STANDARD:
          g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & JAPAN_PC_MASK);
          break;
        default:
          /* assuming 24-bit */
          g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & ANSI_PC_MASK);
          break;
      }
      break;

    case MTP3_ADDR_FMT_HEX:
      switch (addr_pc_p->type)
      {
        case ITU_STANDARD:
          g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & ITU_PC_MASK);
          break;
        case JAPAN_STANDARD:
          g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & JAPAN_PC_MASK);
          break;
        default:
          /* assuming 24-bit */
          g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & ANSI_PC_MASK);
          break;
      }
      break;

    case MTP3_ADDR_FMT_NI_DEC:
      switch (addr_pc_p->type)
      {
        case ITU_STANDARD:
          g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
          break;
        case JAPAN_STANDARD:
          g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & JAPAN_PC_MASK);
          break;
        default:
          /* assuming 24-bit */
          g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
          break;
      }
      break;

    case MTP3_ADDR_FMT_NI_HEX:
      switch (addr_pc_p->type)
      {
        case ITU_STANDARD:
          g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
          break;
        case JAPAN_STANDARD:
          g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & JAPAN_PC_MASK);
          break;
        default:
          /* assuming 24-bit */
          g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
          break;
      }
      break;

    default:
      /* FALLTHRU */

    case MTP3_ADDR_FMT_DASHED:
      mtp3_pc_to_str_buf(addr_pc_p->pc, buf, buf_len);
      break;
  }
}