Ejemplo n.º 1
0
static int
dissect_extension(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
{
    guint8  extension_flag;
    guint8  extension_type;
    guint16 extension_length;
    guint8  type;

    proto_tree_add_item(tree, hf_btbnep_extension_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_btbnep_extension_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
    type = tvb_get_guint8(tvb, offset);
    extension_flag = type & 0x01;
    extension_type = type >> 1;
    offset += 1;

    proto_tree_add_item(tree, hf_btbnep_extension_length, tvb, offset, 1, ENC_BIG_ENDIAN);
    extension_length = tvb_get_ntohs(tvb, offset);
    offset += 2;

    if (extension_type == 0x00) {
        /* Extension Control */
        offset = dissect_control(tvb, pinfo, tree, offset);
    } else {
        offset += extension_length;
    }

    if (extension_flag) offset = dissect_extension(tvb, pinfo, tree, offset);

    return offset;
}
Ejemplo n.º 2
0
static void
dissect_btbnep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
    proto_item   *pi;
    proto_tree   *btbnep_tree;
    gint          offset = 0;
    guint         bnep_type;
    guint         extension_flag;
    guint         type = 0;
    proto_item   *addr_item;
    proto_tree   *addr_tree = NULL;
    const guint8 *src_addr;
    const guint8 *dst_addr;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "BNEP");
    col_clear(pinfo->cinfo, COL_INFO);

    switch (pinfo->p2p_dir) {
        case P2P_DIR_SENT:
            col_add_str(pinfo->cinfo, COL_INFO, "Sent ");
            break;
        case P2P_DIR_RECV:
            col_add_str(pinfo->cinfo, COL_INFO, "Rcvd ");
            break;
        default:
            col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ",
                pinfo->p2p_dir);
            break;
    }

    pi = proto_tree_add_item(tree, proto_btbnep, tvb, offset, -1, ENC_NA);
    btbnep_tree = proto_item_add_subtree(pi, ett_btbnep);

    proto_tree_add_item(btbnep_tree, hf_btbnep_extension_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(btbnep_tree, hf_btbnep_bnep_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    bnep_type = tvb_get_guint8(tvb, offset);
    extension_flag = bnep_type & 0x80;
    bnep_type = bnep_type & 0x7F;
    offset += 1;

    col_append_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str_const(bnep_type, bnep_type_vals,  "Unknown type"));
    if (extension_flag) col_append_fstr(pinfo->cinfo, COL_INFO, "+E");

    if (bnep_type == BNEP_TYPE_GENERAL_ETHERNET || bnep_type == BNEP_TYPE_COMPRESSED_ETHERNET_DESTINATION_ONLY) {
        dst_addr = tvb_get_ptr(tvb, offset, 6);
        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, dst_addr);
        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, dst_addr);

        addr_item = proto_tree_add_ether(btbnep_tree, hf_btbnep_dst, tvb, offset, 6, dst_addr);
        if (addr_item) addr_tree = proto_item_add_subtree(addr_item, ett_addr);
        proto_tree_add_ether(addr_tree, hf_btbnep_addr, tvb, offset, 6, dst_addr);
        proto_tree_add_item(addr_tree, hf_btbnep_lg, tvb, offset, 3, ENC_BIG_ENDIAN);
        proto_tree_add_item(addr_tree, hf_btbnep_ig, tvb, offset, 3, ENC_BIG_ENDIAN);
        offset += 6;
    }

    if (bnep_type == BNEP_TYPE_GENERAL_ETHERNET || bnep_type == BNEP_TYPE_COMPRESSED_ETHERNET_SOURCE_ONLY) {
        src_addr = tvb_get_ptr(tvb, offset, 6);
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src_addr);
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src_addr);


        addr_item = proto_tree_add_ether(btbnep_tree, hf_btbnep_src, tvb, offset, 6, src_addr);
        if (addr_item) {
            addr_tree = proto_item_add_subtree(addr_item, ett_addr);
            if (tvb_get_guint8(tvb, offset) & 0x01) {
                expert_add_info_format(pinfo, addr_item, PI_PROTOCOL, PI_WARN,
                        "Source MAC must not be a group address: IEEE 802.3-2002, Section 3.2.3(b)");
            }
        }
        proto_tree_add_ether(addr_tree, hf_btbnep_addr, tvb, offset, 6, src_addr);
        proto_tree_add_item(addr_tree, hf_btbnep_lg, tvb, offset, 3, ENC_BIG_ENDIAN);
        proto_tree_add_item(addr_tree, hf_btbnep_ig, tvb, offset, 3, ENC_BIG_ENDIAN);
        offset += 6;
    }

    if (bnep_type != BNEP_TYPE_CONTROL) {
        type = tvb_get_ntohs(tvb, offset);
        if (!top_dissect) {
            proto_tree_add_item(btbnep_tree, hf_btbnep_type, tvb, offset, 2, ENC_BIG_ENDIAN);
            col_append_fstr(pinfo->cinfo, COL_INFO, " - Type: %s", val_to_str_const(type, etype_vals, "unknown"));
        }
        offset += 2;
    } else {
        offset = dissect_control(tvb, pinfo, btbnep_tree, offset);
    }

    if (extension_flag) {
        offset = dissect_extension(tvb, pinfo, btbnep_tree, offset);
    }

    if (bnep_type != BNEP_TYPE_CONTROL) {
        /* dissect normal network */
       if (top_dissect) {
            ethertype(type, tvb, offset, pinfo, tree, btbnep_tree,
                    hf_btbnep_type, 0, 0);
       } else {
            tvbuff_t  *next_tvb;

            next_tvb = tvb_new_subset_remaining(tvb, offset);
            call_dissector(data_handle, next_tvb, pinfo, tree);
       }
    }
}