Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at packet-ieee80211.c:6134

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

dissect_ieee80211_common

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-ieee80211.c)expand/collapse
Show more  
 6069  dissect_ieee80211_common (tvbuff_t * tvb, packet_info * pinfo,
 6070          proto_tree * tree, gboolean fixed_length_header, gint fcs_len,
 6071          gboolean wlan_broken_fc, gboolean datapad,
 6072          gboolean is_ht)
 6073  {
 6074    guint16 fcf, flags, frame_type_subtype, ctrl_fcf, ctrl_type_subtype;
 6075    guint16 seq_control;
 6076    guint32 seq_number, frag_number;
 6077    gboolean more_frags;
 6078    const guint8 *src = NULL;
 6079    const guint8 *dst = NULL;
 6080    const guint8 *bssid = NULL;
 6081    proto_item *ti = NULL;
 6082    proto_item *fcs_item = NULL;
 6083    proto_item *cw_item = NULL;
 6084    proto_item *hidden_item;
 6085    proto_tree *volatile hdr_tree = NULL;
 6086    proto_tree *fcs_tree = NULL;
 6087    proto_tree *cw_tree = NULL;
 6088    guint16 hdr_len, ohdr_len, htc_len = 0;
 6089    gboolean has_fcs, fcs_good, fcs_bad;
 6090    gint len, reported_len, ivlen;
 6091    gboolean is_amsdu = 0;
 6092    gboolean save_fragmented;
 6093    tvbuff_t *volatile next_tvb = NULL;
 6094    guint32 addr_type;
 6095    volatile encap_t encap_type;
 6096    guint8 octet1, octet2;
 6097    char out_buff[SHORT_STR];
 6098    gint is_iv_bad;
 6099    guchar iv_buff[4];
 6100    const char *addr1_str = NULL;
 6101    int addr1_hf = -1;
 6102    guint offset;
 6103    const gchar *fts_str;
 6104    gchar flag_str[] = "opmPRMFTC";
 6105    gint i;
 6106   
 6107    wlan_hdr *volatile whdr;
 6108    static wlan_hdr whdrs[4];
 6109    gboolean retransmitted;
 6110   
 6111    whdr= &whdrs[0];
 6112   
 6113    if (check_col (pinfo->cinfo, COL_PROTOCOL))
 6114      col_set_str (pinfo->cinfo, COL_PROTOCOL, "IEEE 802.11");
 6115    if (check_col (pinfo->cinfo, COL_INFO))
 6116      col_clear (pinfo->cinfo, COL_INFO);
 6117   
 6118    fcf = FETCH_FCF(0);
 6119    frame_type_subtype = COMPOSE_FRAME_TYPE(fcf);
 6120    if (frame_type_subtype == CTRL_CONTROL_WRAPPER)
 6121      ctrl_fcf = FETCH_FCF(10);
 6122    else 
 6123      ctrl_fcf = 0;
 6124   
 6125    if (fixed_length_header)
 6126      hdr_len = DATA_LONG_HDR_LEN;
 6127    else 
 6128      hdr_len = find_header_length (fcf, ctrl_fcf, is_ht);
 6129    ohdr_len = hdr_len;
 6130    if (datapad)
 6131      hdr_len = roundup2(hdr_len, 4);
 6132   
 6133    fts_str = val_to_str(frame_type_subtype, frame_type_subtype_vals,
 6134                "Unrecognized (Reserved frame)");
 6135    if (check_col (pinfo->cinfo, COL_INFO))
 6136        col_set_str (pinfo->cinfo, COL_INFO, fts_str);
 6137   
 6138   
 6139    flags = FCF_FLAGS (fcf);
 6140    more_frags = HAVE_FRAGMENTS (flags);
 6141   
 6142    for (i = 0; i < 8; i++) {
 6143      if (! (flags & 0x80 >> i)) {
 6144        flag_str[i] = '.';
 6145      }
 6146    }
 6147   
 6148    if (is_ht && IS_STRICTLY_ORDERED(flags) &&
 6149      ((FCF_FRAME_TYPE(fcf) == MGT_FRAME) || (FCF_FRAME_TYPE(fcf) == DATA_FRAME &&
 6150        DATA_FRAME_IS_QOS(frame_type_subtype)))) {
 6151      htc_len = 4;
 6152    }
 6153   
 6154    /* Add the FC to the current tree */
 6155    if (tree)
 6156      {
 6157        ti = proto_tree_add_protocol_format (tree, proto_wlan, tvb, 0, hdr_len,
 6158            "IEEE 802.11 %s", fts_str);
 6159        hdr_tree = proto_item_add_subtree (ti, ett_80211);
 6160   
 6161        dissect_frame_control(hdr_tree, tvb, wlan_broken_fc, 0);
 6162   
 6163        if (frame_type_subtype == CTRL_PS_POLL)
 6164          proto_tree_add_uint(hdr_tree, hf_assoc_id,tvb,2,2,
 6165              ASSOC_ID(tvb_get_letohs(tvb,2)));
 6166   
 6167        else 
 6168          proto_tree_add_uint (hdr_tree, hf_did_duration, tvb, 2, 2,
 6169              tvb_get_letohs (tvb, 2));
 6170      }
 6171   
 6172    /*
 6173     * Decode the part of the frame header that isn't the same for all
 6174     * frame types.
 6175     */
 6176    seq_control = 0;
 6177    frag_number = 0;
 6178    seq_number = 0;
 6179   
 6180    switch (FCF_FRAME_TYPE (fcf))
 6181    {
 6182   
 6183      case MGT_FRAME:
 6184        /*
 6185         * All management frame types have the same header.
 6186         */
 6187        src = tvb_get_ptr (tvb, 10, 6);
 6188        dst = tvb_get_ptr (tvb, 4, 6);
 6189   
 6190        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src);
 6191        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src);
 6192        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, dst);
 6193        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, dst);
 6194   
 6195        /* for tap */
 6196        SET_ADDRESS(&whdr->bssid, AT_ETHER, 6, tvb_get_ptr(tvb, 16,6));
 6197        SET_ADDRESS(&whdr->src, AT_ETHER, 6, src);
 6198        SET_ADDRESS(&whdr->dst, AT_ETHER, 6, dst);
 6199        whdr->type = frame_type_subtype;
 6200   
 6201        seq_control = tvb_get_letohs(tvb, 22);
 6202        frag_number = SEQCTL_FRAGMENT_NUMBER(seq_control);
 6203        seq_number = SEQCTL_SEQUENCE_NUMBER(seq_control);
 6204   
 6205        if (check_col (pinfo->cinfo, COL_INFO))
 6206        {
 6207          col_append_fstr(pinfo->cinfo, COL_INFO,
 6208              ", SN=%d", seq_number);
 6209   
 6210          col_append_fstr(pinfo->cinfo, COL_INFO,
 6211              ", FN=%d",frag_number);
 6212        }
 6213   
 6214        if (tree)
 6215        {
 6216          proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 4, 6, dst);
 6217   
 6218          proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 10, 6, src);
 6219   
 6220          /* add items for wlan.addr filter */
 6221          hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 4, 6, dst);
 6222          PROTO_ITEM_SET_HIDDEN(hidden_item);
 6223          hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 10, 6, src);
 6224          PROTO_ITEM_SET_HIDDEN(hidden_item);
 6225   
 6226          proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 16, 6,
 6227              tvb_get_ptr (tvb, 16, 6));
 6228   
 6229          proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
 6230              frag_number);
 6231   
 6232          proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
 6233              seq_number);
 6234        }
 6235        break;
 6236   
 6237      case CONTROL_FRAME:
 6238      {
 6239        /*
 6240         * Control Wrapper frames insert themselves between address 1
 6241         * and address 2 in a normal control frame.  Process address 1
 6242         * first, then handle the rest of the frame in dissect_control.
 6243         */
 6244        if (frame_type_subtype == CTRL_CONTROL_WRAPPER) {
 6245          offset = 10; /* FC + D/ID + Address 1 + CFC + HTC */
 6246          ctrl_fcf = FETCH_FCF(10);
 6247          ctrl_type_subtype = COMPOSE_FRAME_TYPE(ctrl_fcf);
 6248        } else {
 6249          offset = 10; /* FC + D/ID + Address 1 */
 6250          ctrl_fcf = fcf;
 6251          ctrl_type_subtype = frame_type_subtype;
 6252        }
 6253   
 6254        switch (ctrl_type_subtype)
 6255        {
 6256          case CTRL_PS_POLL:
 6257            addr1_str = "BSSID";
 6258            addr1_hf = hf_addr_bssid;
 6259            break;
 6260          case CTRL_RTS:
 6261          case CTRL_CTS:
 6262          case CTRL_ACKNOWLEDGEMENT:
 6263          case CTRL_CFP_END:
 6264          case CTRL_CFP_ENDACK:
 6265          case CTRL_BLOCK_ACK_REQ:
 6266          case CTRL_BLOCK_ACK:
 6267            addr1_str = "RA";
 6268            addr1_hf = hf_addr_ra;
 6269            break;
 6270          default:
 6271            break;
 6272        }
 6273   
 6274        if (!addr1_str) /* XXX - Should we throw some sort of error? */
 6275          break;
 6276   
 6277        /* Add address 1 */
 6278        dst = tvb_get_ptr(tvb, 4, 6);
 6279        set_dst_addr_cols(pinfo, dst, addr1_str);
 6280        if (tree) {
 6281          proto_tree_add_item(hdr_tree, addr1_hf, tvb, 4, 6, FALSE);
 6282        }
 6283   
 6284        /*
 6285         * Start shoving in other fields if needed.
 6286         * XXX - Should we look for is_ht as well?
 6287         */
 6288        if (frame_type_subtype == CTRL_CONTROL_WRAPPER && tree) {
 6289          cw_item = proto_tree_add_text(hdr_tree, tvb, offset, 2,
 6290            "Contained Frame Control");
 6291          cw_tree = proto_item_add_subtree (cw_item, ett_cntrl_wrapper_fc);
 6292          dissect_frame_control(cw_tree, tvb, FALSE, offset);
 6293          dissect_ht_control(hdr_tree, tvb, offset + 2);
 6294          offset+=6;
 6295          cw_item = proto_tree_add_text(hdr_tree, tvb, offset, 2,
 6296            "Carried Frame");
 6297          hdr_tree = proto_item_add_subtree (cw_item, ett_cntrl_wrapper_fc);
 6298        }
 6299   
 6300        switch (ctrl_type_subtype)
 6301        {
 6302          case CTRL_PS_POLL:
 6303          case CTRL_CFP_END:
 6304          case CTRL_CFP_ENDACK:
 6305          {
 6306            src = tvb_get_ptr (tvb, offset, 6);
 6307            set_src_addr_cols(pinfo, src, "BSSID");
 6308            if (tree) {
 6309              proto_tree_add_item(hdr_tree, hf_addr_ta, tvb, offset, 6, FALSE);
 6310            }
 6311            break;
 6312          }
 6313   
 6314          case CTRL_RTS:
 6315          {
 6316            src = tvb_get_ptr (tvb, offset, 6);
 6317            set_src_addr_cols(pinfo, src, "TA");
 6318            if (tree) {
 6319              proto_tree_add_item(hdr_tree, hf_addr_ta, tvb, offset, 6, FALSE);
 6320            }
 6321            break;
 6322          }
 6323   
 6324          case CTRL_CONTROL_WRAPPER:
 6325          {
 6326            /* XXX - We shouldn't see this.  Should we throw an error? */
 6327            break;
 6328          }
 6329   
 6330          /*** Begin: Block Ack Request - Dustin Johnson ***/
 6331          case CTRL_BLOCK_ACK_REQ:
 6332          {
 6333            src = tvb_get_ptr (tvb, offset, 6);
 6334            set_src_addr_cols(pinfo, src, "TA");
 6335   
 6336            if (tree)
 6337            {
 6338              guint16 bar_control;
 6339              guint8 block_ack_type;
 6340              proto_item *bar_parent_item;
 6341              proto_tree *bar_sub_tree;
 6342   
 6343              proto_tree_add_item(hdr_tree, hf_addr_ta, tvb, offset, 6, FALSE);
 6344              offset += 6;
 6345   
 6346              bar_control = tvb_get_letohs(tvb, offset);
 6347              block_ack_type = (bar_control & 0x0006) >> 1;
 6348              proto_tree_add_uint(hdr_tree, hf_block_ack_request_type, tvb,
 6349                offset, 1, block_ack_type);
 6350              bar_parent_item = proto_tree_add_uint_format(hdr_tree,
 6351                hf_block_ack_request_control, tvb, offset, 2, bar_control,
 6352                "Block Ack Request (BAR) Control: 0x%04X", bar_control);
 6353              bar_sub_tree = proto_item_add_subtree(bar_parent_item,
 6354                ett_block_ack);
 6355              proto_tree_add_boolean(bar_sub_tree,
 6356                hf_block_ack_control_ack_policy, tvb, offset, 1, bar_control);
 6357              proto_tree_add_boolean(bar_sub_tree, hf_block_ack_control_multi_tid,
 6358                tvb, offset, 1, bar_control);
 6359              proto_tree_add_boolean(bar_sub_tree,
 6360                hf_block_ack_control_compressed_bitmap, tvb, offset, 1,
 6361                bar_control);
 6362              proto_tree_add_uint(bar_sub_tree, hf_block_ack_control_reserved,
 6363                tvb, offset, 2, bar_control);
 6364   
 6365              switch (block_ack_type)
 6366              {
 6367                case 0: /*Basic BlockAckReq */
 6368                {
 6369                  proto_tree_add_uint(bar_sub_tree,
 6370                  hf_block_ack_control_basic_tid_info, tvb, offset+1, 1,
 6371                    bar_control);
 6372                  offset += 2;
 6373   
 6374                  offset += add_fixed_field(hdr_tree, tvb, offset,
 6375                    FIELD_BLOCK_ACK_SSC);
 6376                  break;
 6377                }
 6378                case 2: /* Compressed BlockAckReq */
 6379                {
 6380                  proto_tree_add_uint(bar_sub_tree,
 6381                  hf_block_ack_control_compressed_tid_info, tvb, offset+1, 1,
 6382                    bar_control);
 6383                  offset += 2;
 6384   
 6385                  offset += add_fixed_field(hdr_tree, tvb, offset,
 6386                    FIELD_BLOCK_ACK_SSC);
 6387                  break;
 6388                }
 6389                case 3: /* Multi-TID BlockAckReq */
 6390                {
 6391                  guint8 tid_count, i;
 6392                  proto_tree *bar_mtid_tree, *bar_mtid_sub_tree;
 6393   
 6394                  tid_count = ((bar_control & 0xF000) >> 12) + 1;
 6395                  proto_tree_add_uint_format(bar_sub_tree, hf_block_ack_control_compressed_tid_info, tvb, offset+1, 1, bar_control,
 6396                  decode_numeric_bitfield(bar_control, 0xF000, 16,"Number of TIDs Present: 0x%%X"), tid_count);
 6397                  offset += 2;
 6398   
 6399                  bar_parent_item = proto_tree_add_text (hdr_tree, tvb, offset, tid_count*4, "Per TID Info");
 6400                  bar_mtid_tree = proto_item_add_subtree(bar_parent_item, ett_block_ack);
 6401                  for (i = 1; i <= tid_count; i++) {
 6402                    bar_parent_item = proto_tree_add_uint(bar_mtid_tree, hf_block_ack_multi_tid_info, tvb, offset, 4, i);
 6403                    bar_mtid_sub_tree = proto_item_add_subtree(bar_parent_item, ett_block_ack);
 6404   
 6405                    bar_control = tvb_get_letohs(tvb, offset);
 6406                    proto_tree_add_uint(bar_mtid_sub_tree, hf_block_ack_multi_tid_reserved, tvb, offset, 2, bar_control);
 6407                    proto_tree_add_uint(bar_mtid_sub_tree, hf_block_ack_multi_tid_value, tvb, offset+1, 1, bar_control);
 6408                    offset += 2;
 6409   
 6410                    offset += add_fixed_field(bar_mtid_sub_tree, tvb, offset, FIELD_BLOCK_ACK_SSC);
 6411                  }
 6412                  break;
 6413                }
 6414              }
 6415            }
 6416            break;
 6417          }
 6418          /*** End: Block Ack Request - Dustin Johnson ***/
 6419   
 6420          /*** Begin: Block Ack - Dustin Johnson ***/
 6421          case CTRL_BLOCK_ACK:
 6422          {
 6423            src = tvb_get_ptr (tvb, offset, 6);
 6424            set_src_addr_cols(pinfo, src, "TA");
 6425   
 6426            if (tree)
 6427            {
 6428              guint16 ba_control;
 6429              guint8 block_ack_type;
 6430              proto_item *ba_parent_item;
 6431              proto_tree *ba_sub_tree;
 6432   
 6433              proto_tree_add_item(hdr_tree, hf_addr_ta, tvb, offset, 6, FALSE);
 6434              offset += 6;
 6435   
 6436              ba_control = tvb_get_letohs(tvb, offset);
 6437              block_ack_type = (ba_control & 0x0006) >> 1;
 6438              proto_tree_add_uint(hdr_tree, hf_block_ack_type, tvb, offset, 1, block_ack_type);
 6439              ba_parent_item = proto_tree_add_uint_format(hdr_tree,
 6440                hf_block_ack_control, tvb, offset, 2, ba_control,
 6441                "Block Ack (BA) Control: 0x%04X", ba_control);
 6442              ba_sub_tree = proto_item_add_subtree(ba_parent_item, ett_block_ack);
 6443              proto_tree_add_boolean(ba_sub_tree, hf_block_ack_control_ack_policy,
 6444                tvb, offset, 1, ba_control);
 6445              proto_tree_add_boolean(ba_sub_tree, hf_block_ack_control_multi_tid,
 6446                tvb, offset, 1, ba_control);
 6447              proto_tree_add_boolean(ba_sub_tree,
 6448                hf_block_ack_control_compressed_bitmap, tvb, offset, 1,
 6449                ba_control);
 6450              proto_tree_add_uint(ba_sub_tree, hf_block_ack_control_reserved, tvb,
 6451                offset, 2, ba_control);
 6452   
 6453              switch (block_ack_type)
 6454              {
 6455                case 0: /*Basic BlockAck */
 6456                {
 6457                  proto_tree_add_uint(ba_sub_tree,
 6458                  hf_block_ack_control_basic_tid_info, tvb, offset+1, 1,
 6459                    ba_control);
 6460                  offset += 2;
 6461   
 6462                  offset += add_fixed_field(hdr_tree, tvb, offset, FIELD_BLOCK_ACK_SSC);
 6463                  proto_tree_add_text(hdr_tree, tvb, offset, 128, "Block Ack Bitmap");
 6464                  offset += 128;
 6465                  break;
 6466                }
 6467                case 2: /* Compressed BlockAck */
 6468                {
 6469                  proto_tree_add_uint(ba_sub_tree, hf_block_ack_control_basic_tid_info, tvb, offset+1, 1, ba_control);
 6470                  offset += 2;
 6471   
 6472                  offset += add_fixed_field(hdr_tree, tvb, offset, FIELD_BLOCK_ACK_SSC);
 6473                  proto_tree_add_text(hdr_tree, tvb, offset, 8, "Block Ack Bitmap");
 6474                  offset += 8;
 6475                  break;
 6476                }
 6477                case 3:  /* Multi-TID BlockAck */
 6478                {
 6479                  guint8 tid_count, i;
 6480                  proto_tree *ba_mtid_tree, *ba_mtid_sub_tree;
 6481   
 6482                  tid_count = ((ba_control & 0xF000) >> 12) + 1;
 6483                  proto_tree_add_uint_format(ba_sub_tree,
 6484                  hf_block_ack_control_compressed_tid_info, tvb, offset+1, 1,
 6485                    ba_control, decode_numeric_bitfield(ba_control, 0xF000,
 6486                    16,"Number of TIDs Present: 0x%%X"), tid_count);
 6487                  offset += 2;
 6488   
 6489                  ba_parent_item = proto_tree_add_text (hdr_tree, tvb, offset, tid_count*4, "Per TID Info");
 6490                  ba_mtid_tree = proto_item_add_subtree(ba_parent_item, ett_block_ack);
 6491                  for (i=1; i<=tid_count; i++) {
 6492                    ba_parent_item = proto_tree_add_uint(ba_mtid_tree, hf_block_ack_multi_tid_info, tvb, offset, 4, i);
 6493                    ba_mtid_sub_tree = proto_item_add_subtree(ba_parent_item, ett_block_ack);
 6494   
 6495                    ba_control = tvb_get_letohs(tvb, offset);
 6496                    proto_tree_add_uint(ba_mtid_sub_tree, hf_block_ack_multi_tid_reserved, tvb, offset, 2, ba_control);
 6497                    proto_tree_add_uint(ba_mtid_sub_tree, hf_block_ack_multi_tid_value, tvb, offset+1, 1, ba_control);
 6498                    offset += 2;
 6499   
 6500                    offset += add_fixed_field(ba_mtid_sub_tree, tvb, offset, FIELD_BLOCK_ACK_SSC);
 6501                    proto_tree_add_text(ba_mtid_sub_tree, tvb, offset, 8, "Block Ack Bitmap");
 6502                    offset += 8;
 6503                  }
 6504                  break;
 6505                }
 6506              }
 6507            }
 6508            break;
 6509          }
 6510          /*** End: Block Ack - Dustin Johnson ***/
 6511        }
 6512        break;
 6513      }
 6514   
 6515      case DATA_FRAME:
 6516        addr_type = FCF_ADDR_SELECTOR (fcf);
 6517   
 6518        /* In order to show src/dst address we must always do the following */
 6519        switch (addr_type)
 6520        {
 6521   
 6522          case DATA_ADDR_T1:
 6523            src = tvb_get_ptr (tvb, 10, 6);
 6524            dst = tvb_get_ptr (tvb, 4, 6);
 6525            bssid = tvb_get_ptr (tvb, 16, 6);
 6526            break;
 6527   
 6528          case DATA_ADDR_T2:
 6529            src = tvb_get_ptr (tvb, 16, 6);
 6530            dst = tvb_get_ptr (tvb, 4, 6);
 6531            bssid = tvb_get_ptr (tvb, 10, 6);
 6532            break;
 6533   
 6534          case DATA_ADDR_T3:
 6535            src = tvb_get_ptr (tvb, 10, 6);
 6536            dst = tvb_get_ptr (tvb, 16, 6);
 6537            bssid = tvb_get_ptr (tvb, 4, 6);
 6538            break;
 6539   
 6540          case DATA_ADDR_T4:
 6541            src = tvb_get_ptr (tvb, 24, 6);
 6542            dst = tvb_get_ptr (tvb, 16, 6);
 6543            bssid = tvb_get_ptr (tvb, 16, 6);
 6544            break;
 6545        }
 6546   
 6547        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src);
 6548        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src);
 6549        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, dst);
 6550        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, dst);
 6551   
 6552        /* for tap */
 6553   
 6554        SET_ADDRESS(&whdr->bssid, AT_ETHER, 6, bssid);
 6555        SET_ADDRESS(&whdr->src, AT_ETHER, 6, src);
 6556        SET_ADDRESS(&whdr->dst, AT_ETHER, 6, dst);
 6557        whdr->type = frame_type_subtype;
 6558   
 6559        seq_control = tvb_get_letohs(tvb, 22);
 6560        frag_number = SEQCTL_FRAGMENT_NUMBER(seq_control);
 6561        seq_number = SEQCTL_SEQUENCE_NUMBER(seq_control);
 6562   
 6563        if (check_col (pinfo->cinfo, COL_INFO))
 6564        {
 6565          col_append_fstr(pinfo->cinfo, COL_INFO,
 6566              ", SN=%d, FN=%d", seq_number,frag_number);
 6567        }
 6568   
 6569        /* Now if we have a tree we start adding stuff */
 6570        if (tree)
 6571        {
 6572   
 6573          switch (addr_type)
 6574          {
 6575   
 6576            case DATA_ADDR_T1:
 6577              proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 4, 6, dst);
 6578              proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 10, 6, src);
 6579              proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 16, 6, bssid);
 6580              proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
 6581                 frag_number);
 6582              proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
 6583                 seq_number);
 6584   
 6585              /* add items for wlan.addr filter */
 6586              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 4, 6, dst);
 6587              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6588              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 10, 6, src);
 6589              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6590              break;
 6591   
 6592            case DATA_ADDR_T2:
 6593              proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 4, 6, dst);
 6594              proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 10, 6, bssid);
 6595              proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 16, 6, src);
 6596              proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
 6597                 frag_number);
 6598              proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
 6599                 seq_number);
 6600   
 6601              /* add items for wlan.addr filter */
 6602              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 4, 6, dst);
 6603              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6604              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 16, 6, src);
 6605              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6606              break;
 6607   
 6608            case DATA_ADDR_T3:
 6609              proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 4, 6, bssid);
 6610              proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 10, 6, src);
 6611              proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 16, 6, dst);
 6612   
 6613              proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
 6614                 frag_number);
 6615              proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
 6616                 seq_number);
 6617   
 6618              /* add items for wlan.addr filter */
 6619              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 10, 6, src);
 6620              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6621              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 16, 6, dst);
 6622              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6623              break;
 6624   
 6625            case DATA_ADDR_T4:
 6626              proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
 6627                  tvb_get_ptr (tvb, 4, 6));
 6628              proto_tree_add_ether (hdr_tree, hf_addr_ta, tvb, 10, 6,
 6629                  tvb_get_ptr (tvb, 10, 6));
 6630              proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 16, 6, dst);
 6631              proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
 6632                 frag_number);
 6633              proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
 6634                 seq_number);
 6635              proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 24, 6, src);
 6636   
 6637              /* add items for wlan.addr filter */
 6638              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 16, 6, dst);
 6639              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6640              hidden_item = proto_tree_add_ether (hdr_tree, hf_addr, tvb, 24, 6, src);
 6641              PROTO_ITEM_SET_HIDDEN(hidden_item);
 6642              break;
 6643          }
 6644   
 6645        }
 6646        break;
 6647    }
 6648   
 6649    len = tvb_length_remaining(tvb, hdr_len);
 6650    reported_len = tvb_reported_length_remaining(tvb, hdr_len);
 6651   
 6652    switch (fcs_len)
 6653      {
 6654        case 0: /* Definitely has no FCS */
 6655          has_fcs = FALSE;
 6656          break;
 6657   
 6658        case 4: /* Definitely has an FCS */
 6659          has_fcs = TRUE;
 6660          break;
 6661   
 6662        default: /* Don't know - use "wlan_check_fcs" */
 6663          has_fcs = wlan_check_fcs;
 6664          break;
 6665      }
 6666    if (has_fcs)
 6667      {
 6668        /*
 6669         * Well, this packet should, in theory, have an FCS.
 6670         * Do we have the entire packet, and does it have enough data for 
 6671         * the FCS?
 6672         */
 6673        if (reported_len < 4)
 6674        {
 6675          /*
 6676           * The packet is claimed not to even have enough data for a 4-byte
 6677           * FCS.
 6678           * Pretend it doesn't have an FCS.
 6679           */
 6680          ;
 6681        }
 6682        else if (len < reported_len)
 6683        {
 6684          /*
 6685           * The packet is claimed to have enough data for a 4-byte FCS, but 
 6686           * we didn't capture all of the packet.
 6687           * Slice off the 4-byte FCS from the reported length, and trim the 
 6688           * captured length so it's no more than the reported length; that 
 6689           * will slice off what of the FCS, if any, is in the captured
 6690           * length.
 6691           */
 6692          reported_len -= 4;
 6693          if (len > reported_len)
 6694              len = reported_len;
 6695        }
 6696        else 
 6697        {
 6698          /*
 6699           * We have the entire packet, and it includes a 4-byte FCS.
 6700           * Slice it off, and put it into the tree.
 6701           */
 6702          len -= 4;
 6703          reported_len -= 4;
 6704          if (tree)
 6705          {
 6706            guint32 sent_fcs = tvb_get_ntohl(tvb, hdr_len + len);
 6707            guint32 fcs;
 6708   
 6709            if (datapad)
 6710              fcs = crc32_802_tvb_padded(tvb, ohdr_len, hdr_len, len);
 6711            else 
 6712              fcs = crc32_802_tvb(tvb, hdr_len + len);
 6713            if (fcs == sent_fcs) {
 6714              fcs_good = TRUE;
 6715              fcs_bad = FALSE;
 6716            } else {
 6717              fcs_good = FALSE;
 6718              fcs_bad = TRUE;
 6719            }
 6720   
 6721            if(fcs_good) {
 6722              fcs_item = proto_tree_add_uint_format(hdr_tree, hf_fcs, tvb,
 6723                  hdr_len + len, 4, sent_fcs,
 6724                  "Frame check sequence: 0x%08x [correct]", sent_fcs);
 6725            } else {
 6726              fcs_item = proto_tree_add_uint_format(hdr_tree, hf_fcs, tvb,
 6727                  hdr_len + len, 4, sent_fcs,
 6728                  "Frame check sequence: 0x%08x [incorrect, should be 0x%08x]",
 6729                  sent_fcs, fcs);
 6730              flag_str[8] = '.';
 6731            }
 6732   
 6733            proto_tree_set_appendix(hdr_tree, tvb, hdr_len + len, 4);
 6734   
 6735            fcs_tree = proto_item_add_subtree(fcs_item, ett_fcs);
 6736   
 6737            fcs_item = proto_tree_add_boolean(fcs_tree,
 6738                hf_fcs_good, tvb,
 6739                hdr_len + len, 4,
 6740                fcs_good);
 6741            PROTO_ITEM_SET_GENERATED(fcs_item);
 6742   
 6743            fcs_item = proto_tree_add_boolean(fcs_tree,
 6744                hf_fcs_bad, tvb,
 6745                hdr_len + len, 4,
 6746                fcs_bad);
 6747            PROTO_ITEM_SET_GENERATED(fcs_item);
 6748          }
 6749        }
 6750      } else {
 6751        flag_str[8] = '\0';
 6752      }
 6753   
 6754      proto_item_append_text(ti, ", Flags: %s", flag_str);
 6755      if (check_col (pinfo->cinfo, COL_INFO))
 6756        col_append_fstr (pinfo->cinfo, COL_INFO, ", Flags=%s", flag_str);
 6757   
 6758   
 6759    /*
 6760     * Only management and data frames have a body, so we don't have 
 6761     * anything more to do for other types of frames.
 6762     */
 6763    switch (FCF_FRAME_TYPE (fcf))
 6764      {
 6765   
 6766      case MGT_FRAME:
 6767        if (htc_len == 4) {
 6768          dissect_ht_control(hdr_tree, tvb, ohdr_len - 4);
 6769        }
 6770        break;
 6771   
 6772      case DATA_FRAME:
 6773        if (tree && DATA_FRAME_IS_QOS(frame_type_subtype))
 6774        {
 6775          proto_item *qos_fields;
 6776          proto_tree *qos_tree;
 6777   
 6778          guint16 qosoff;
 6779          guint16 qos_control;
 6780          guint16 qos_priority;
 6781          guint16 qos_ack_policy;
 6782          guint16 qos_amsdu_present;
 6783          guint16 qos_eosp;
 6784          guint16 qos_field_content;
 6785   
 6786          /*
 6787           * We calculate the offset to the QoS header data as
 6788           * an offset relative to the end of the header.  But
 6789           * when the header has been padded to align the data
 6790           * this must be done relative to true header size, not 
 6791           * the padded/aligned value.  To simplify this work we
 6792           * stash the original header size in ohdr_len instead
 6793           * of recalculating it.
 6794           */
 6795          qosoff = ohdr_len - htc_len - 2;
 6796          qos_fields = proto_tree_add_text(hdr_tree, tvb, qosoff, 2,
 6797              "QoS Control");
 6798          qos_tree = proto_item_add_subtree (qos_fields, ett_qos_parameters);
 6799   
 6800          qos_control = tvb_get_letohs(tvb, qosoff + 0);
 6801          qos_priority = QOS_PRIORITY(qos_control);
 6802          qos_ack_policy = QOS_ACK_POLICY(qos_control);
 6803          qos_amsdu_present = QOS_AMSDU_PRESENT(qos_control);
 6804          qos_eosp = QOS_EOSP(qos_control);
 6805          qos_field_content = QOS_FIELD_CONTENT(qos_control);
 6806   
 6807          proto_tree_add_uint_format (qos_tree, hf_qos_priority, tvb,
 6808              qosoff, 1, qos_priority,
 6809              "Priority: %d (%s) (%s)",
 6810              qos_priority, qos_tags[qos_priority], qos_acs[qos_priority]);
 6811   
 6812          if (flags & FLAG_FROM_DS) {
 6813            proto_tree_add_boolean (qos_tree, hf_qos_eosp, tvb,
 6814                qosoff, 1, qos_control);
 6815          } else {
 6816            proto_tree_add_boolean (qos_tree, hf_qos_bit4, tvb,
 6817                qosoff, 1, qos_control);
 6818          }
 6819   
 6820          proto_tree_add_uint (qos_tree, hf_qos_ack_policy, tvb, qosoff, 1,
 6821              qos_ack_policy);
 6822   
 6823          if (flags & FLAG_FROM_DS) {
 6824            if (!DATA_FRAME_IS_NULL(frame_type_subtype)) {
 6825              proto_tree_add_boolean(qos_tree, hf_qos_amsdu_present, tvb,
 6826                  qosoff, 1, qos_amsdu_present);
 6827              is_amsdu = qos_amsdu_present;
 6828            }
 6829            if (DATA_FRAME_IS_CF_POLL(frame_type_subtype)) {
 6830              /* txop limit */
 6831              if (qos_field_content == 0) {
 6832                proto_tree_add_uint_format_value (qos_tree, hf_qos_txop_limit, tvb,
 6833                    qosoff + 1, 1, qos_field_content,
 6834                    "transmit one frame immediately (0)");
 6835              } else {
 6836                proto_tree_add_uint (qos_tree, hf_qos_txop_limit, tvb,
 6837                    qosoff + 1, 1, qos_field_content);
 6838              }
 6839            } else {
 6840              /* qap ps buffer state */
 6841              proto_item *qos_ps_buf_state_fields;
 6842              proto_tree *qos_ps_buf_state_tree;
 6843              guint8 qap_buf_load;
 6844   
 6845              qos_ps_buf_state_fields = proto_tree_add_text(qos_tree, tvb, qosoff + 1, 1,
 6846                  "QAP PS Buffer State: 0x%x", qos_field_content);
 6847              qos_ps_buf_state_tree = proto_item_add_subtree (qos_ps_buf_state_fields, ett_qos_ps_buf_state);
 6848   
 6849              proto_tree_add_boolean (qos_ps_buf_state_tree, hf_qos_buf_state_indicated,
 6850                  tvb, 1, 1, qos_field_content);
 6851   
 6852              if (QOS_PS_BUF_STATE_INDICATED(qos_field_content)) {
 6853                proto_tree_add_uint (qos_ps_buf_state_tree, hf_qos_highest_pri_buf_ac, tvb,
 6854                    qosoff + 1, 1, qos_field_content);
 6855   
 6856                qap_buf_load = QOS_PS_QAP_BUF_LOAD(qos_field_content);
 6857                switch (qap_buf_load) {
 6858   
 6859                case 0:
 6860                  proto_tree_add_uint_format_value (qos_ps_buf_state_tree, hf_qos_qap_buf_load, tvb,
 6861                      qosoff + 1, 1, qos_field_content,
 6862                      "no buffered traffic (0)");
 6863                  break;
 6864   
 6865                default:
 6866                  proto_tree_add_uint_format_value (qos_ps_buf_state_tree, hf_qos_qap_buf_load, tvb,
 6867                      qosoff + 1, 1, qos_field_content,
 6868                      "%d octets (%d)", qap_buf_load*4096, qap_buf_load);
 6869                  break;
 6870   
 6871                case 15:
 6872                  proto_tree_add_uint_format_value (qos_ps_buf_state_tree, hf_qos_qap_buf_load, tvb,
 6873                      qosoff + 1, 1, qos_field_content,
 6874                      "greater than 57344 octets (15)");
 6875                  break;
 6876                }
 6877              }
 6878            }
 6879          } else {
 6880            if (!DATA_FRAME_IS_NULL(frame_type_subtype)) {
 6881              proto_tree_add_boolean(qos_tree, hf_qos_amsdu_present, tvb,
 6882                  qosoff, 1, qos_amsdu_present);
 6883              is_amsdu = qos_amsdu_present;
 6884            }
 6885            if (qos_eosp) {
 6886              /* queue size */
 6887              switch (qos_field_content) {
 6888   
 6889              case 0:
 6890                proto_tree_add_uint_format_value (qos_tree, hf_qos_queue_size,
 6891                    tvb, qosoff + 1, 1, qos_field_content,
 6892                    "no buffered traffic in the queue (0)");
 6893                break;
 6894   
 6895              default:
 6896                proto_tree_add_uint_format_value (qos_tree, hf_qos_queue_size,
 6897                    tvb, qosoff + 1, 1, qos_field_content,
 6898                    "%u bytes (%u)", qos_field_content*256, qos_field_content);
 6899                break;
 6900   
 6901              case 254:
 6902                proto_tree_add_uint_format_value (qos_tree, hf_qos_queue_size,
 6903                    tvb, qosoff + 1, 1, qos_field_content,
 6904                    "more than 64768 octets (254)");
 6905                break;
 6906   
 6907              case 255:
 6908                proto_tree_add_uint_format_value (qos_tree, hf_qos_queue_size,
 6909                    tvb, qosoff + 1, 1, qos_field_content,
 6910                    "unspecified or unknown (256)");
 6911                break;
 6912              }
 6913            } else {
 6914              /* txop duration requested */
 6915              if (qos_field_content == 0) {
 6916                proto_tree_add_uint_format_value (qos_tree, hf_qos_txop_dur_req,
 6917                    tvb, qosoff + 1, 1, qos_field_content,
 6918                    "no TXOP requested (0)");
 6919              } else {
 6920                proto_tree_add_uint (qos_tree, hf_qos_txop_dur_req,
 6921                    tvb, qosoff + 1, 1, qos_field_content);
 6922              }
 6923            }
 6924          }
 6925   
 6926          /* Do we have +HTC? */
 6927          if (htc_len == 4) {
 6928            dissect_ht_control(hdr_tree, tvb, ohdr_len - 4);
 6929          }
 6930        } /* end of qos control field */
 6931   
 6932  #ifdef HAVE_AIRPDCAP 
 6933        /* Davide Schiera (2006-11-21): process handshake packet with AirPDcap    */
 6934        /* the processing will take care of 4-way handshake sessions for WPA    */
 6935        /* and WPA2 decryption                                  */
 6936        if (enable_decryption && !pinfo->fd->flags.visited) {
 6937          const guint8 *enc_data = tvb_get_ptr(tvb, 0, hdr_len+reported_len);
 6938          AirPDcapPacketProcess(&airpdcap_ctx, enc_data, hdr_len, hdr_len+reported_len, NULL, 0, NULL, TRUE, FALSE);
 6939        }
 6940        /* Davide Schiera --------------------------------------------------------  */
 6941  #endif
 6942   
 6943        /*
 6944         * No-data frames don't have a body.
 6945         */
 6946        if (DATA_FRAME_IS_NULL(frame_type_subtype))
 6947          return;
 6948   
 6949        if (!wlan_subdissector) {
 6950          guint fnum = 0;
 6951   
 6952          /* key: bssid:src
 6953           * data: last seq_control seen and frame number
 6954           */
 6955          retransmitted = FALSE;
 6956          if(!pinfo->fd->flags.visited){
 6957            retransmit_key key;
 6958            retransmit_key *result;
 6959   
 6960            memcpy(key.bssid, bssid, 6);
 6961            memcpy(key.src, src, 6);
 6962            key.seq_control = 0;
 6963            result = (retransmit_key *)g_hash_table_lookup(fc_analyse_retransmit_table, &key);
 6964            if (result && result->seq_control == seq_control) {
 6965                 /* keep a pointer to the first seen frame, could be done with proto data? */
 6966                 fnum = result->fnum;
 6967                 g_hash_table_insert(fc_first_frame_table, GINT_TO_POINTER( pinfo->fd->num),
 6968                    GINT_TO_POINTER(fnum));
 6969                 retransmitted = TRUE;
 6970            } else {
 6971                 /* first time or new seq*/
 6972                 if (!result) {
 6973                    result = se_alloc(sizeof(retransmit_key));
 6974                    *result = key;
 6975                    g_hash_table_insert(fc_analyse_retransmit_table, result, result);
 6976                 }
 6977                 result->seq_control = seq_control;
 6978                 result->fnum =  pinfo->fd->num;
 6979             }
 6980          }
 6981          else if ((fnum = GPOINTER_TO_UINT(g_hash_table_lookup(fc_first_frame_table, GINT_TO_POINTER( pinfo->fd->num))))) {
 6982             retransmitted = TRUE;
 6983          }
 6984   
 6985          if (retransmitted) {
 6986              if (check_col (pinfo->cinfo, COL_INFO))
 6987                  col_append_fstr(pinfo->cinfo, COL_INFO, " [retransmitted]");
 6988              if (tree) {
 6989                  proto_item *item;
 6990   
 6991                  item=proto_tree_add_none_format(hdr_tree, hf_fc_analysis_retransmission, tvb, 0, 0, "Retransmitted frame");
 6992                  PROTO_ITEM_SET_GENERATED(item);
 6993                  item=proto_tree_add_uint(hdr_tree, hf_fc_analysis_retransmission_frame,tvb, 0, 0, fnum);
 6994                  PROTO_ITEM_SET_GENERATED(item);
 6995              }
 6996              next_tvb = tvb_new_subset (tvb, hdr_len, len, reported_len);
 6997              call_dissector(data_handle, next_tvb, pinfo, tree);
 6998              goto end_of_wlan;
 6999          }
 7000        }
 7001   
 7002        break;
 7003   
 7004      case CONTROL_FRAME:
 7005        return;
 7006   
 7007      default:
 7008        return;
 7009      }
 7010   
 7011    if (IS_PROTECTED(FCF_FLAGS(fcf)) && wlan_ignore_wep != WLAN_IGNORE_WEP_WO_IV) {
 7012      /*
 7013       * It's a WEP or WPA encrypted frame; dissect the protections parameters
 7014       * and decrypt the data, if we have a matching key. Otherwise display it as data.
 7015       */
 7016   
 7017      gboolean can_decrypt = FALSE;
 7018      proto_tree *wep_tree = NULL;
 7019      guint32 iv;
 7020      guint8 key, keybyte;
 7021   
 7022      /* Davide Schiera (2006-11-27): define algorithms constants and macros  */
 7023  #ifdef HAVE_AIRPDCAP 
 7024  #define PROTECTION_ALG_TKIP  AIRPDCAP_KEY_TYPE_TKIP 
 7025  #define PROTECTION_ALG_CCMP  AIRPDCAP_KEY_TYPE_CCMP 
 7026  #define PROTECTION_ALG_WEP  AIRPDCAP_KEY_TYPE_WEP 
 7027  #define PROTECTION_ALG_RSNA  PROTECTION_ALG_CCMP | PROTECTION_ALG_TKIP 
 7028  #else
 7029  #define PROTECTION_ALG_WEP  0 
 7030  #define PROTECTION_ALG_TKIP  1 
 7031  #define PROTECTION_ALG_CCMP  2 
 7032  #define PROTECTION_ALG_RSNA  PROTECTION_ALG_CCMP | PROTECTION_ALG_TKIP 
 7033  #endif
 7034      guint8 algorithm=G_MAXUINT8;
 7035      /* Davide Schiera (2006-11-27): added macros to check the algorithm    */
 7036      /* used could be TKIP or CCMP                            */
 7037  #define IS_TKIP(tvb, hdr_len)  (tvb_get_guint8(tvb, hdr_len + 1) & 0x20)
 7038  #define IS_CCMP(tvb, hdr_len)  (tvb_get_guint8(tvb, hdr_len + 2) == 0)
 7039      /* Davide Schiera -----------------------------------------------------  */
 7040   
 7041  #ifdef  HAVE_AIRPDCAP
 7042      /* Davide Schiera (2006-11-21): recorded original lengths to pass them  */
 7043      /* to the packets process function                        */
 7044      guint32 sec_header=0;
 7045      guint32 sec_trailer=0;
 7046   
 7047      next_tvb = try_decrypt(tvb, hdr_len, reported_len, &algorithm, &sec_header, &sec_trailer);
 7048  #endif
 7049      /* Davide Schiera -----------------------------------------------------  */
 7050   
 7051      keybyte = tvb_get_guint8(tvb, hdr_len + 3);
 7052      key = KEY_OCTET_WEP_KEY(keybyte);
 7053      if ((keybyte & KEY_EXTIV) && (len >= EXTIV_LEN)) {
 7054        /* Extended IV; this frame is likely encrypted with TKIP or CCMP */
 7055   
 7056   
 7057        if (tree) {
 7058          proto_item *extiv_fields;
 7059   
 7060  #ifdef HAVE_AIRPDCAP 
 7061          /* Davide Schiera (2006-11-27): differentiated CCMP and TKIP if  */
 7062          /* it's possible                                */
 7063          if (algorithm==PROTECTION_ALG_TKIP)
 7064            extiv_fields = proto_tree_add_text(hdr_tree, tvb, hdr_len, 8,
 7065                "TKIP parameters");
 7066          else if (algorithm==PROTECTION_ALG_CCMP)
 7067            extiv_fields = proto_tree_add_text(hdr_tree, tvb, hdr_len, 8,
 7068              "CCMP parameters");
 7069          else {
 7070            /* Davide Schiera --------------------------------------------  */
 7071  #endif
 7072            /* Davide Schiera (2006-11-27): differentiated CCMP and TKIP if*/
 7073            /* it's possible                              */
 7074            if (IS_TKIP(tvb, hdr_len)) {
 7075              algorithm=PROTECTION_ALG_TKIP;
 7076              extiv_fields = proto_tree_add_text(hdr_tree, tvb, hdr_len, 8,
 7077                  "TKIP parameters");
 7078            } else if (IS_CCMP(tvb, hdr_len)) {
 7079              algorithm=PROTECTION_ALG_CCMP;
 7080              extiv_fields = proto_tree_add_text(hdr_tree, tvb, hdr_len, 8,
 7081                  "CCMP parameters");
 7082            } else 
 7083              extiv_fields = proto_tree_add_text(hdr_tree, tvb, hdr_len, 8,
 7084                  "TKIP/CCMP parameters");
 7085  #ifdef HAVE_AIRPDCAP 
 7086          }
 7087  #endif
 7088          proto_item_set_len (ti, hdr_len + 8);
 7089   
 7090          wep_tree = proto_item_add_subtree (extiv_fields, ett_wep_parameters);
 7091   
 7092          if (algorithm==PROTECTION_ALG_TKIP) {
 7093            g_snprintf(out_buff, SHORT_STR, "0x%08X%02X%02X",
 7094                tvb_get_letohl(tvb, hdr_len + 4),
 7095                tvb_get_guint8(tvb, hdr_len),
 7096                tvb_get_guint8(tvb, hdr_len + 2));
 7097            proto_tree_add_string(wep_tree, hf_tkip_extiv, tvb, hdr_len,
 7098                EXTIV_LEN, out_buff);
 7099          } else if (algorithm==PROTECTION_ALG_CCMP) {
 7100            g_snprintf(out_buff, SHORT_STR, "0x%08X%02X%02X",
 7101                tvb_get_letohl(tvb, hdr_len + 4),
 7102                tvb_get_guint8(tvb, hdr_len + 1),
 7103                tvb_get_guint8(tvb, hdr_len));
 7104            proto_tree_add_string(wep_tree, hf_ccmp_extiv, tvb, hdr_len,
 7105                EXTIV_LEN, out_buff);
 7106          }
 7107   
 7108          proto_tree_add_uint(wep_tree, hf_wep_key, tvb, hdr_len + 3, 1, key);
 7109        }
 7110   
 7111        /* Subtract out the length of the IV. */
 7112        len -= EXTIV_LEN;
 7113        reported_len -= EXTIV_LEN;
 7114        ivlen = EXTIV_LEN;
 7115        /* It is unknown whether this is TKIP or CCMP, so let's not even try to
 7116         * parse TKIP Michael MIC+ICV or CCMP MIC. */
 7117   
 7118  #ifdef HAVE_AIRPDCAP 
 7119        /* Davide Schiera (2006-11-21): enable TKIP and CCMP decryption      */
 7120        /* checking for the trailer                            */
 7121        if (next_tvb!=NULL) {
 7122          if (reported_len < (gint) sec_trailer) {
 7123            /* There is no space for a trailer, ignore it and don't decrypt  */
 7124            ;
 7125          } else if (len < reported_len) {
 7126            /* There is space for a trailer, but we haven't capture all the  */
 7127            /* packet. Slice off the trailer, but don't try to decrypt      */
 7128            reported_len -= sec_trailer;
 7129            if (len > reported_len)
 7130              len = reported_len;
 7131          } else {
 7132            /* Ok, we have a trailer and the whole packet. Decrypt it!      */
 7133            /* TODO: At the moment we won't add the trailer to the tree,    */
 7134            /* so don't remove the trailer from the packet              */
 7135            len -= sec_trailer;
 7136            reported_len -= sec_trailer;
 7137            can_decrypt = TRUE;
 7138          }
 7139        }
 7140        /* Davide Schiera --------------------------------------------------  */
 7141  #endif
 7142      } else {
 7143        /* No Ext. IV - WEP packet */
 7144        /*
 7145         * XXX - pass the IV and key to "try_decrypt_wep()", and have it pass
 7146         * them to "wep_decrypt()", rather than having "wep_decrypt()" extract 
 7147         * them itself.
 7148         *
 7149         * Also, just pass the data *following* the WEP parameters as the 
 7150         * buffer to decrypt.
 7151         */
 7152        iv = tvb_get_ntoh24(tvb, hdr_len);
 7153        if (tree) {
 7154          proto_item *wep_fields;
 7155   
 7156          wep_fields = proto_tree_add_text(hdr_tree, tvb, hdr_len, 4,
 7157              "WEP parameters");
 7158   
 7159          wep_tree = proto_item_add_subtree (wep_fields, ett_wep_parameters);
 7160          proto_tree_add_uint (wep_tree, hf_wep_iv, tvb, hdr_len, 3, iv);
 7161          tvb_memcpy(tvb, iv_buff, hdr_len, 3);
 7162          is_iv_bad = weak_iv(iv_buff);
 7163          if (is_iv_bad != -1) {
 7164            proto_tree_add_boolean_format (wep_tree, hf_wep_iv_weak,
 7165                tvb, 0, 0, TRUE,
 7166                "Weak IV for key byte %d",
 7167                is_iv_bad);
 7168          }
 7169        }
 7170        if (tree)
 7171          proto_tree_add_uint (wep_tree, hf_wep_key, tvb, hdr_len + 3, 1, key);
 7172   
 7173        /* Subtract out the length of the IV. */
 7174        len -= 4;
 7175        reported_len -= 4;
 7176        ivlen = 4;
 7177   
 7178        /* Davide Schiera (2006-11-27): Even if the decryption was not */
 7179        /* successful, set the algorithm                               */
 7180        algorithm=PROTECTION_ALG_WEP;
 7181   
 7182        /*
 7183         * Well, this packet should, in theory, have an ICV.
 7184         * Do we have the entire packet, and does it have enough data for 
 7185         * the ICV?
 7186         */
 7187        if (reported_len < 4) {
 7188          /*
 7189           * The packet is claimed not to even have enough data for a
 7190           * 4-byte ICV.
 7191           * Pretend it doesn't have an ICV.
 7192           */
 7193          ;
 7194        } else if (len < reported_len) {
 7195          /*
 7196           * The packet is claimed to have enough data for a 4-byte ICV,
 7197           * but we didn't capture all of the packet.
 7198           * Slice off the 4-byte ICV from the reported length, and trim
 7199           * the captured length so it's no more than the reported length;
 7200           * that will slice off what of the ICV, if any, is in the 
 7201           * captured length.
 7202           */
 7203          reported_len -= 4;
 7204          if (len > reported_len)
 7205            len = reported_len;
 7206        } else {
 7207          /*
 7208           * We have the entire packet, and it includes a 4-byte ICV.
 7209           * Slice it off, and put it into the tree.
 7210           *
 7211           * We only support decrypting if we have the the ICV.
 7212           *
 7213           * XXX - the ICV is encrypted; we're putting the encrypted 
 7214           * value, not the decrypted value, into the tree.
 7215           */
 7216          len -= 4;
 7217          reported_len -= 4;
 7218          can_decrypt = TRUE;
 7219        }
 7220      }
 7221   
 7222      if (algorithm == PROTECTION_ALG_WEP) {
 7223        g_strlcpy (wlan_stats.protection, "WEP", MAX_PROTECT_LEN);
 7224      } else if (algorithm == PROTECTION_ALG_TKIP) {
 7225        g_strlcpy (wlan_stats.protection, "TKIP", MAX_PROTECT_LEN);
 7226      } else if (algorithm == PROTECTION_ALG_CCMP) {
 7227        g_strlcpy (wlan_stats.protection, "CCMP", MAX_PROTECT_LEN);
 7228      } else {
 7229        g_strlcpy (wlan_stats.protection, "Unknown", MAX_PROTECT_LEN);
 7230      }
 7231   
 7232  #ifndef HAVE_AIRPDCAP 
 7233      if (can_decrypt)
 7234        next_tvb = try_decrypt_wep(tvb, hdr_len, reported_len + 8);
 7235  #else
 7236      /* Davide Schiera (2006-11-26): decrypted before parsing header and    */
 7237      /* protection header                                  */
 7238  #endif
 7239      if (!can_decrypt || next_tvb == NULL) {
 7240        /*
 7241         * WEP decode impossible or failed, treat payload as raw data 
 7242         * and don't attempt fragment reassembly or further dissection.
 7243         */
 7244        next_tvb = tvb_new_subset(tvb, hdr_len + ivlen, len, reported_len);
 7245   
 7246        if (tree) {
 7247          /* Davide Schiera (2006-11-21): added WEP or WPA separation      */
 7248          if (algorithm==PROTECTION_ALG_WEP) {
 7249            if (can_decrypt)
 7250              proto_tree_add_uint_format (wep_tree, hf_wep_icv, tvb,
 7251                  hdr_len + ivlen + len, 4,
 7252                  tvb_get_ntohl(tvb, hdr_len + ivlen + len),
 7253                  "WEP ICV: 0x%08x (not verified)",
 7254                  tvb_get_ntohl(tvb, hdr_len + ivlen + len));
 7255          } else if (algorithm==PROTECTION_ALG_CCMP) {
 7256          } else if (algorithm==PROTECTION_ALG_TKIP) {
 7257          }
 7258        }
 7259        /* Davide Schiera (2006-11-21) ----------------------------------  */
 7260   
 7261        if (pinfo->ethertype != ETHERTYPE_CENTRINO_PROMISC && wlan_ignore_wep == WLAN_IGNORE_WEP_NO) {
 7262          /* Some wireless drivers (such as Centrino) WEP payload already decrypted */
 7263          call_dissector(data_handle, next_tvb, pinfo, tree);
 7264          goto end_of_wlan;
 7265        }
 7266      } else {
 7267        /* Davide Schiera (2006-11-21): added WEP or WPA separation        */
 7268        if (algorithm==PROTECTION_ALG_WEP) {
 7269          if (tree)
 7270            proto_tree_add_uint_format (wep_tree, hf_wep_icv, tvb,
 7271                hdr_len + ivlen + len, 4,
 7272                tvb_get_ntohl(tvb, hdr_len + ivlen + len),
 7273                "WEP ICV: 0x%08x (correct)",
 7274                tvb_get_ntohl(tvb, hdr_len + ivlen + len));
 7275   
 7276          add_new_data_source(pinfo, next_tvb, "Decrypted WEP data");
 7277        } else if (algorithm==PROTECTION_ALG_CCMP) {
 7278          add_new_data_source(pinfo, next_tvb, "Decrypted CCMP data");
 7279        } else if (algorithm==PROTECTION_ALG_TKIP) {
 7280          add_new_data_source(pinfo, next_tvb, "Decrypted TKIP data");
 7281        }
 7282        /* Davide Schiera (2006-11-21) -------------------------------------  */
 7283        /* Davide Schiera (2006-11-27): undefine macros and definitions  */
 7284  #undef IS_TKIP 
 7285  #undef IS_CCMP 
 7286  #undef PROTECTION_ALG_CCMP 
 7287  #undef PROTECTION_ALG_TKIP 
 7288  #undef PROTECTION_ALG_WEP 
 7289        /* Davide Schiera --------------------------------------------------  */
 7290      }
 7291   
 7292      /*
 7293       * WEP decryption successful!
 7294       *
 7295       * Use the tvbuff we got back from the decryption; the data starts at
 7296       * the beginning.  The lengths are already correct for the decoded WEP
 7297       * payload.
 7298       */
 7299      hdr_len = 0;
 7300   
 7301    } else {
 7302      /*
 7303       * Not a WEP-encrypted frame; just use the data from the tvbuff 
 7304       * handed to us.
 7305       *
 7306       * The payload starts at "hdr_len" (i.e., just past the 802.11
 7307       * MAC header), the length of data in the tvbuff following the 
 7308       * 802.11 header is "len", and the length of data in the packet
 7309       * following the 802.11 header is "reported_len".
 7310       */
 7311      next_tvb = tvb;
 7312    }
 7313   
 7314    /*
 7315     * Do defragmentation if "wlan_defragment" is true, and we have more
 7316     * fragments or this isn't the first fragment.
 7317     *
 7318     * We have to do some special handling to catch frames that 
 7319     * have the "More Fragments" indicator not set but that 
 7320     * don't show up as reassembled and don't have any other 
 7321     * fragments present.  Some networking interfaces appear 
 7322     * to do reassembly even when you're capturing raw packets 
 7323     * *and* show the reassembled packet without the "More
 7324     * Fragments" indicator set *but* with a non-zero fragment 
 7325     * number.
 7326     *
 7327     * "fragment_add_seq_802_11()" handles that; we want to call it 
 7328     * even if we have a short frame, so that it does those checks - if 
 7329     * the frame is short, it doesn't do reassembly on it.
 7330     *
 7331     * (This could get some false positives if we really *did* only 
 7332     * capture the last fragment of a fragmented packet, but that's
 7333     * life.)
 7334     */
 7335    save_fragmented = pinfo->fragmented;
 7336    if (wlan_defragment && (more_frags || frag_number != 0)) {
 7337      fragment_data *fd_head;
 7338   
 7339      /*
 7340       * If we've already seen this frame, look it up in the 
 7341       * table of reassembled packets, otherwise add it to
 7342       * whatever reassembly is in progress, if any, and see
 7343       * if it's done.
 7344       */
 7345      if (reported_len < 0)
 7346        THROW(ReportedBoundsError);
 7347      fd_head = fragment_add_seq_802_11(next_tvb, hdr_len, pinfo, seq_number,
 7348          wlan_fragment_table,
 7349          wlan_reassembled_table,
 7350          frag_number,
 7351          reported_len,
 7352          more_frags);
 7353      next_tvb = process_reassembled_data(tvb, hdr_len, pinfo,
 7354          "Reassembled 802.11", fd_head,
 7355          &frag_items, NULL, hdr_tree);
 7356    } else {
 7357      /*
 7358       * If this is the first fragment, dissect its contents, otherwise 
 7359       * just show it as a fragment.
 7360       */
 7361      if (frag_number != 0) {
 7362        /* Not the first fragment - don't dissect it. */
 7363        next_tvb = NULL;
 7364      } else {
 7365        /* First fragment, or not fragmented.  Dissect what we have here. */
 7366   
 7367        /* Get a tvbuff for the payload. */
 7368        next_tvb = tvb_new_subset (next_tvb, hdr_len, len, reported_len);
 7369   
 7370        /*
 7371         * If this is the first fragment, but not the only fragment,
 7372         * tell the next protocol that.
 7373         */
 7374        if (more_frags)
 7375          pinfo->fragmented = TRUE;
 7376        else 
 7377          pinfo->fragmented = FALSE;
 7378      }
 7379    }
 7380   
 7381    if (next_tvb == NULL) {
 7382      /* Just show this as an incomplete fragment. */
 7383      if (check_col(pinfo->cinfo, COL_INFO))
 7384        col_set_str(pinfo->cinfo, COL_INFO, "Fragmented IEEE 802.11 frame");
 7385      next_tvb = tvb_new_subset (tvb, hdr_len, len, reported_len);
 7386      call_dissector(data_handle, next_tvb, pinfo, tree);
 7387      pinfo->fragmented = save_fragmented;
 7388      goto end_of_wlan;
 7389    }
 7390   
 7391    switch (FCF_FRAME_TYPE (fcf))
 7392      {
 7393   
 7394      case MGT_FRAME:
 7395        dissect_ieee80211_mgt (fcf, next_tvb, pinfo, tree);
 7396        break;
 7397   
 7398      case DATA_FRAME:
 7399        if (is_amsdu && tvb_reported_length_remaining(next_tvb, 0) > 4){
 7400          tvbuff_t *volatile msdu_tvb = NULL;
 7401          guint32 msdu_offset = 0;
 7402          guint16 i = 1;
 7403          const guint8 *src = NULL;
 7404          const guint8 *dst = NULL;
 7405          guint16 msdu_length;
 7406          proto_item *parent_item;
 7407          proto_tree *mpdu_tree;
 7408          proto_tree *subframe_tree;
 7409   
 7410          parent_item = proto_tree_add_protocol_format(tree, proto_aggregate, next_tvb, 0,
 7411                                      tvb_reported_length_remaining(next_tvb, 0), "IEEE 802.11 Aggregate MSDU");
 7412          mpdu_tree = proto_item_add_subtree(parent_item, ett_msdu_aggregation_parent_tree);
 7413   
 7414          do {
 7415            dst = tvb_get_ptr (next_tvb, msdu_offset, 6);
 7416            src = tvb_get_ptr (next_tvb, msdu_offset+6, 6);
 7417            msdu_length = tvb_get_ntohs (next_tvb, msdu_offset+12);
 7418   
 7419            parent_item = proto_tree_add_uint_format(mpdu_tree, amsdu_msdu_header_text, next_tvb,
 7420                              msdu_offset, roundup2(msdu_offset+14+msdu_length, 4),
 7421                              i, "A-MSDU Subframe #%u", i);
 7422            subframe_tree = proto_item_add_subtree(parent_item, ett_msdu_aggregation_subframe_tree);
 7423            i++;
 7424   
 7425            proto_tree_add_ether(subframe_tree, hf_addr_da, next_tvb, msdu_offset, 6, dst);
 7426            proto_tree_add_ether(subframe_tree, hf_addr_sa, next_tvb, msdu_offset+6, 6, src);
 7427            proto_tree_add_uint_format(subframe_tree, mcsset_highest_data_rate, next_tvb, msdu_offset+12, 2,
 7428            msdu_length, "MSDU length: 0x%04X", msdu_length);
 7429   
 7430            msdu_offset += 14;
 7431            msdu_tvb = tvb_new_subset(next_tvb, msdu_offset, msdu_length, -1);
 7432            call_dissector(llc_handle, msdu_tvb, pinfo, subframe_tree);
 7433            msdu_offset = roundup2(msdu_offset+msdu_length, 4);
 7434          } while (tvb_reported_length_remaining(next_tvb, msdu_offset) > 14);
 7435   
 7436          break;
 7437        }
 7438        /* I guess some bridges take Netware Ethernet_802_3 frames,
 7439           which are 802.3 frames (with a length field rather than 
 7440           a type field, but with no 802.2 header in the payload),
 7441           and just stick the payload into an 802.11 frame.  I've seen 
 7442           captures that show frames of that sort.
 7443   
 7444           We also handle some odd form of encapsulation in which a
 7445           complete Ethernet frame is encapsulated within an 802.11
 7446           data frame, with no 802.2 header.  This has been seen 
 7447
7458
Show [ Lines 7447 to 7458 omitted. ]
 7459             address from the 802.11 header or has 6 octets that match the
 7460             source address from the 802.11 header following the first 6 octets,
 7461             and, if so, treat it as an encapsulated Ethernet frame;
 7462   
 7463             otherwise, we use the same scheme that we use in the Ethernet 
 7464             dissector to recognize Netware 802.3 frames, namely checking
 7465             whether the packet starts with 0xff 0xff and, if so, treat it
 7466             as an encapsulated IPX frame, and then check whether the 
 7467             packet starts with 0x00 0x00 and, if so, treat it as an OLPC 
 7468             frame. */
 7469        encap_type = ENCAP_802_2;
 7470        TRY {
 7471          octet1 = tvb_get_guint8(next_tvb, 0);
 7472          octet2 = tvb_get_guint8(next_tvb, 1);
 7473          if (octet1 != 0xaa || octet2 != 0xaa) {
 7474            src = tvb_get_ptr (next_tvb, 6, 6);
 7475            dst = tvb_get_ptr (next_tvb, 0, 6);
 7476            if (memcmp(src, pinfo->dl_src.data, 6) == 0 ||
 7477                memcmp(dst, pinfo->dl_dst.data, 6) == 0)
 7478              encap_type = ENCAP_ETHERNET;
 7479            else if (octet1 == 0xff && octet2 == 0xff)
 7480              encap_type = ENCAP_IPX;
 7481            else if (octet1 == 0x00 && octet2 == 0x00) {
 7482              proto_tree_add_text(tree, next_tvb, 0, 2, "Mysterious OLPC stuff");
 7483              next_tvb = tvb_new_subset (next_tvb, 2, -1, -1);
 7484            }
 7485          }
 7486        }
 7487        CATCH2(BoundsError, ReportedBoundsError) {
 7488        ; /* do nothing */
 7489   
 7490        }
 7491        ENDTRY;
 7492   
 7493        switch (encap_type) {
 7494   
 7495        case ENCAP_802_2:
 7496          call_dissector(llc_handle, next_tvb, pinfo, tree);
 7497          break;
 7498   
 7499        case ENCAP_ETHERNET:
 7500          call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
 7501          break;
 7502   
 7503        case ENCAP_IPX:
 7504          call_dissector(ipx_handle, next_tvb, pinfo, tree);
 7505          break;
 7506        }
 7507        break;
 7508      }
 7509    pinfo->fragmented = save_fragmented;
 7510   
 7511    end_of_wlan:
 7512    whdr->stats = wlan_stats;
 7513    tap_queue_packet(wlan_tap, pinfo, whdr);
 7514    memset (&wlan_stats, 0, sizeof wlan_stats);
 7515  }
Show more  




Change Warning 5487.35701 : Ignored Return Value

Priority:
State:
Finding:
Owner:
Note: