Text   |  XML   |  ReML   |   Visible Warnings:

Unreachable Control Flow  at packet-zbee-aps.c:665

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

dissect_zbee_aps

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-zbee-aps.c)expand/collapse
Show more  
 289  dissect_zbee_aps(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 290  {
 291      tvbuff_t            *payload_tvb = NULL;
 292      dissector_handle_t  profile_handle = NULL;
 293   
 294      proto_tree      *aps_tree = NULL;
 295      proto_tree      *field_tree = NULL;
 296      proto_item      *proto_root = NULL;
 297      proto_item      *ti;
 298   
 299      zbee_aps_packet packet;
 300      zbee_nwk_packet *nwk = pinfo->private_data;
 301   
 302      guint8          fcf;
 303      guint8          offset = 0;
 304   
 305      /* Init. */
 306      memset(&packet, 0, sizeof(zbee_aps_packet));
 307   
 308      /*  Create the protocol tree */
 309      if(tree){
 310          proto_root = proto_tree_add_protocol_format(tree, proto_zbee_aps, tvb, offset, tvb_length(tvb), "ZigBee Application Support Layer");
 311          aps_tree = proto_item_add_subtree(proto_root, ett_zbee_aps);
 312      }
 313      /* Set the protocol column, if the NWK layer hasn't already done so. */
 314      if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
 315          col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZigBee");
 316      }
 317   
 318      /*  Get the FCF */
 319      fcf = tvb_get_guint8(tvb, offset);
 320      packet.type         = zbee_get_bit_field(fcf, ZBEE_APS_FCF_FRAME_TYPE);
 321      packet.delivery     = zbee_get_bit_field(fcf, ZBEE_APS_FCF_DELIVERY_MODE);
 322      packet.indirect_mode = zbee_get_bit_field(fcf, ZBEE_APS_FCF_INDIRECT_MODE);
 323      packet.ack_mode     = zbee_get_bit_field(fcf, ZBEE_APS_FCF_ACK_MODE);
 324      packet.security     = zbee_get_bit_field(fcf, ZBEE_APS_FCF_SECURITY);
 325      packet.ack_req      = zbee_get_bit_field(fcf, ZBEE_APS_FCF_ACK_REQ);
 326      packet.ext_header   = zbee_get_bit_field(fcf, ZBEE_APS_FCF_EXT_HEADER);
 327   
 328      /* Display the frame type to the proto root and info column. */
 329      if (tree) {
 330          proto_item_append_text(proto_root, " %s", val_to_str(packet.type, zbee_aps_frame_types, "Unknown Type"));
 331      }
 332      if (check_col(pinfo->cinfo, COL_INFO)) {
 333          col_clear(pinfo->cinfo, COL_INFO);
 334          col_append_str(pinfo->cinfo, COL_INFO, val_to_str(packet.type, zbee_aps_frame_types, "Unknown Frame Type"));
 335      }
 336   
 337      /*  Display the FCF */
 338      if (tree) {
 339          /* Create the subtree */
 340          ti = proto_tree_add_text(aps_tree, tvb, offset, sizeof(guint8), "Frame Control Field: %s (0x%02x)",
 341                      val_to_str(packet.type, zbee_aps_frame_types, "Unknown"), fcf);
 342          field_tree = proto_item_add_subtree(ti, ett_zbee_aps_fcf);
 343   
 344          /* Add the frame type and delivery mode. */
 345          proto_tree_add_uint(field_tree, hf_zbee_aps_fcf_frame_type, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_FRAME_TYPE);
 346          proto_tree_add_uint(field_tree, hf_zbee_aps_fcf_delivery, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_DELIVERY_MODE);
 347   
 348          if (pinfo->zbee_stack_vers >= ZBEE_VERSION_2007) {
 349              /* ZigBee 2007 and later uses an ack mode flag. */
 350              if (packet.type == ZBEE_APS_FCF_ACK) {
 351                  proto_tree_add_boolean(field_tree, hf_zbee_aps_fcf_ack_mode, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_ACK_MODE);
 352              }
 353          }
 354          else {
 355              /* ZigBee 2004, uses indirect mode. */
 356              if (packet.delivery == ZBEE_APS_FCF_INDIRECT) {
 357                  proto_tree_add_boolean(field_tree, hf_zbee_aps_fcf_indirect_mode, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_INDIRECT_MODE);
 358              }
 359          }
 360   
 361          /*  Add the rest of the flags */
 362          proto_tree_add_boolean(field_tree, hf_zbee_aps_fcf_security, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_SECURITY);
 363          proto_tree_add_boolean(field_tree, hf_zbee_aps_fcf_ack_req, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_ACK_REQ);
 364          proto_tree_add_boolean(field_tree, hf_zbee_aps_fcf_ext_header, tvb, offset, sizeof(guint8), fcf & ZBEE_APS_FCF_EXT_HEADER);
 365      }
 366      offset += sizeof(guint8);
 367   
 368      /* Check if the endpoint addressing fields are present. */
 369      switch (packet.type) {
 370          case ZBEE_APS_FCF_DATA:
 371              /* Endpoint addressing must exist to some extent on data frames. */
 372              break;
 373   
 374          case ZBEE_APS_FCF_ACK:
 375              if ((pinfo->zbee_stack_vers >= ZBEE_VERSION_2007) && (packet.ack_mode)) {
 376                  /* Command Ack: endpoint addressing does not exist. */
 377                  goto dissect_zbee_aps_no_endpt;
 378              }
 379              break;
 380   
 381          default:
 382          case ZBEE_APS_FCF_CMD:
 383              /* Endpoint addressing does not exist for these frames. */
 384              goto dissect_zbee_aps_no_endpt;
 385      } /* switch */
 386   
 387      /* Determine whether the source and/or destination endpoints are present.
 388       * We should only get here for endpoint-addressed data or ack frames.
 389       */
 390      if ((packet.delivery == ZBEE_APS_FCF_UNICAST) || (packet.delivery == ZBEE_APS_FCF_BCAST)) {
 391          /* Source and destination endpoints exist. (Although, I strongly
 392           * disagree with the presence of the endpoint in broadcast delivery
 393           * mode).
 394           */
 395          packet.dst_present = TRUE;
 396          packet.src_present = TRUE;
 397      }
 398      else if ((packet.delivery == ZBEE_APS_FCF_INDIRECT) && (pinfo->zbee_stack_vers <= ZBEE_VERSION_2004)) {
 399          /* Indirect addressing was removed in ZigBee 2006, basically because it 
 400           * was a useless, broken feature which only complicated things. Treat 
 401           * this mode as invalid for ZigBee 2006 and later. When using indirect 
 402           * addressing, only one of the source and destination endpoints exist,
 403           * and is controlled by the setting of indirect_mode.
 404           */
 405          packet.dst_present = (!packet.indirect_mode);
 406          packet.src_present = (packet.indirect_mode);
 407      }
 408      else if ((packet.delivery == ZBEE_APS_FCF_GROUP) && (pinfo->zbee_stack_vers >= ZBEE_VERSION_2007)) {
 409          /* Group addressing was added in ZigBee 2006, and contains only the
 410           * source endpoint. (IMO, Broacast deliveries should do the same).
 411           */
 412          packet.dst_present = FALSE;
 413          packet.src_present = TRUE;
 414      }
 415      else {
 416          /* Illegal Delivery Mode. */
 417          expert_add_info_format(pinfo, proto_root, PI_MALFORMED, PI_WARN, "Invalid Delivery Mode");
 418          return;
 419   
 420      }
 421   
 422      /* If the destination endpoint is present, get and display it. */
 423      if (packet.dst_present) {
 424          packet.dst = tvb_get_guint8(tvb, offset);
 425          if (tree) {
 426              proto_tree_add_uint(aps_tree, hf_zbee_aps_dst, tvb, offset, sizeof(guint8), packet.dst);
 427              proto_item_append_text(proto_root, ", Dst Endpt: %d", packet.dst);
 428          }
 429          offset += sizeof(guint8);
 430   
 431          /* Update the info column. */
 432          if (check_col(pinfo->cinfo, COL_INFO)) {
 433              col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst Endpt: %d", packet.dst);
 434          }
 435      }
 436   
 437      /* If the group address is present, display it. */
 438      if (packet.delivery == ZBEE_APS_FCF_GROUP) {
 439          packet.group = tvb_get_letohs(tvb, offset);
 440          if (tree) {
 441              proto_tree_add_uint(aps_tree, hf_zbee_aps_group, tvb, offset, sizeof(guint16), packet.group);
 442              proto_item_append_text(proto_root, ", Group: 0x%04x", packet.group);
 443          }
 444          offset += sizeof(guint16);
 445   
 446          /* Update the info column. */
 447          if (check_col(pinfo->cinfo, COL_INFO)) {
 448              col_append_fstr(pinfo->cinfo, COL_INFO, ", Group: 0x%04x", packet.group);
 449          }
 450      }
 451   
 452      /* Get and display the cluster ID. */
 453      if (pinfo->zbee_stack_vers >= ZBEE_VERSION_2007) {
 454          /* Cluster ID is 16-bits long in ZigBee 2007 and later. */
 455          pinfo->zbee_cluster_id = packet.cluster = tvb_get_letohs(tvb, offset);
 456          if (tree) {
 457              proto_tree_add_uint(aps_tree, hf_zbee_aps_cluster, tvb, offset, sizeof(guint16), packet.cluster);
 458          }
 459          offset += sizeof(guint16);
 460      }
 461      else {
 462          /* Cluster ID is 8-bits long in ZigBee 2004 and earlier. */
 463          pinfo->zbee_cluster_id = packet.cluster = tvb_get_guint8(tvb, offset);
 464          if (tree) {
 465  #if 0 
 466              proto_tree_add_uint(aps_tree, hf_zbee_aps_cluster, tvb, offset, sizeof(guint8), packet.cluster);
 467  #endif
 468              proto_tree_add_uint_format_value(aps_tree, hf_zbee_aps_cluster, tvb, offset, sizeof(guint8), packet.cluster, "0x%02x", packet.cluster);
 469          }
 470          offset += sizeof(guint8);
 471      }
 472   
 473      /* Get and display the profile ID if it exists. */
 474      packet.profile = tvb_get_letohs(tvb, offset);
 475      profile_handle = dissector_get_port_handle(zbee_aps_dissector_table, packet.profile);
 476      if (tree) {
 477          ti = proto_tree_add_uint(aps_tree, hf_zbee_aps_profile, tvb, offset, sizeof(guint16), packet.profile);
 478          if (profile_handle) {
 479              int proto = dissector_handle_get_protocol_index(profile_handle);
 480              proto_item_append_text(ti, " (%s)", proto_get_protocol_name(proto));
 481          }
 482          offset += sizeof(guint16);
 483          /* Update the protocol root and info column later, after the source endpoint
 484           * so that the source and destination will be back-to-back in the text.
 485           */
 486      }
 487   
 488      /* The source endpoint is present for all cases except indirect /w indirect_mode == FALSE */
 489      if ((packet.delivery != ZBEE_APS_FCF_INDIRECT) || (!packet.indirect_mode)) {
 490          packet.src = tvb_get_guint8(tvb, offset);
 491          if (tree) {
 492              proto_tree_add_uint(aps_tree, hf_zbee_aps_src, tvb, offset, sizeof(guint8), packet.src);
 493              proto_item_append_text(proto_root, ", Src Endpt: %d", packet.src);
 494          }
 495          offset += sizeof(guint8);
 496   
 497          /* Update the info column. */
 498          if (check_col(pinfo->cinfo, COL_INFO)) {
 499              col_append_fstr(pinfo->cinfo, COL_INFO, ", Src Endpt: %d", packet.src);
 500          }
 501      }
 502   
 503      /* Display the profile ID now that the source endpoint was listed. */
 504      if (packet.type == ZBEE_APS_FCF_DATA) {
 505          if (tree) {
 506              proto_item_append_text(proto_root, ", Profile: 0x%04x", packet.profile);
 507          }
 508          if (check_col(pinfo->cinfo, COL_INFO)) {
 509              col_append_fstr(pinfo->cinfo, COL_INFO, ", Profile: 0x%04x", packet.profile);
 510          }
 511      }
 512   
 513      /* Jump here if there is no endpoint addressing in this frame. */
 514  dissect_zbee_aps_no_endpt:
 515   
 516      /* Get and display the APS counter. Only present on ZigBee 2007 and later. */
 517      if (pinfo->zbee_stack_vers >= ZBEE_VERSION_2007) {
 518          packet.counter = tvb_get_guint8(tvb, offset);
 519          if (tree) {
 520              proto_tree_add_uint(aps_tree, hf_zbee_aps_counter, tvb, offset, sizeof(guint8), packet.counter);
 521          }
 522          offset += sizeof(guint8);
 523      }
 524   
 525   
 526      /* Get and display the extended header, if present. */
 527      if (packet.ext_header) {
 528          fcf = tvb_get_guint8(tvb, offset);
 529          packet.fragmentation = fcf & ZBEE_APS_EXT_FCF_FRAGMENT;
 530          if (tree) {
 531              /* Create a subtree */
 532              ti = proto_tree_add_text(aps_tree, tvb, offset, sizeof(guint8), "Extended Frame Control Field (0x%02x)", fcf);
 533              field_tree = proto_item_add_subtree(ti, ett_zbee_aps_fcf);
 534   
 535              /* Display the fragmentation sub-field. */
 536              proto_tree_add_uint(field_tree, hf_zbee_aps_fragmentation, tvb, offset, sizeof(guint8), packet.fragmentation);
 537          }
 538          offset += sizeof(guint8);
 539   
 540          /* If fragmentation is enabled, get and display the block number. */
 541          if (packet.fragmentation != ZBEE_APS_EXT_FCF_FRAGMENT_NONE) {
 542              packet.block_number = tvb_get_guint8(tvb, offset);
 543              if (tree) {
 544                  proto_tree_add_uint(field_tree, hf_zbee_aps_block_number, tvb, offset, sizeof(guint8), packet.block_number);
 545              }
 546              offset += sizeof(guint8);
 547          }
 548   
 549          /* If fragmentation is enabled, and this is an acknowledgement,
 550           * get and display the ack bitfield.
 551           */
 552          if ((packet.fragmentation != ZBEE_APS_EXT_FCF_FRAGMENT_NONE) && (packet.type == ZBEE_APS_FCF_ACK)) {
 553              packet.ack_bitfield = tvb_get_guint8(tvb, offset);
 554              if (tree) {
 555                  int     i, mask;
 556                  gchar   tmp[16];
 557                  for (i=0; i<8; i++) {
 558                      mask = (1<<i);
 559                      decode_bitfield_value(tmp, packet.ack_bitfield, mask, 8);
 560                      proto_tree_add_text(field_tree, tvb, offset, sizeof(guint8), "%sBlock %d: %s",
 561                              tmp, packet.block_number+i, (packet.ack_bitfield & mask)?"Acknowledged":"Not Acknowledged");
 562                  } /* for */
 563              }
 564              offset += sizeof(guint8);
 565          }
 566      }
 567      else {
 568          /* Ensure the fragmentation mode is set off, so that the reassembly handler 
 569           * doesn't get called.
 570           */
 571          packet.fragmentation = ZBEE_APS_EXT_FCF_FRAGMENT_NONE;
 572      }
 573   
 574      /* If a payload is present, and security is enabled, decrypt the payload. */
 575      if ((offset < tvb_length(tvb)) && packet.security) {
 576          payload_tvb = dissect_zbee_secure(tvb, pinfo, aps_tree, offset, 0);
 577          if (payload_tvb == NULL) {
 578              /* If Payload_tvb is NULL, then the security dissector cleaned up. */
 579              return;
 580          }
 581      }
 582      /* If the payload exists, create a tvb subset. */
 583      else if (offset < tvb_length(tvb)) {
 584          payload_tvb = tvb_new_subset(tvb, offset, -1, -1);
 585      }
 586   
 587      /* If the payload exstists, and the packet is fragmented, attempt reassembly. */
 588      if ((payload_tvb) && (packet.fragmentation != ZBEE_APS_EXT_FCF_FRAGMENT_NONE)) {
 589          guint32         msg_id;
 590          guint32         block_num;
 591          fragment_data   *frag_msg = NULL;
 592          tvbuff_t        *new_tvb;
 593   
 594          /* Set the fragmented flag. */
 595          pinfo->fragmented = TRUE;
 596   
 597          /* The source address and APS Counter pair form a unique identifier 
 598           * for each message (fragmented or not). Hash these two together to 
 599           * create the message id for the fragmentation handler.
 600           */
 601          msg_id = ((nwk->src)<<8) + packet.counter;
 602   
 603          /* If this is the first block of a fragmented message, than the block 
 604           * number field is the maximum number of blocks in the message. Otherwise 
 605           * the block number is the block being sent.
 606           */
 607          if (packet.fragmentation == ZBEE_APS_EXT_FCF_FRAGMENT_FIRST) {
 608              fragment_set_tot_len(pinfo, msg_id, zbee_aps_fragment_table, packet.block_number);
 609              block_num = 0;  /* first packet. */
 610          }
 611          else {
 612              block_num = packet.block_number;
 613          }
 614   
 615          /* Add this fragment to the reassembly handler. */
 616          frag_msg = fragment_add_seq_check(payload_tvb, 0, pinfo, msg_id, zbee_aps_fragment_table,
 617                  zbee_aps_reassembled_table, block_num, tvb_length(payload_tvb), TRUE);
 618   
 619          new_tvb = process_reassembled_data(payload_tvb, 0, pinfo, "Reassembled Packet" ,
 620                  frag_msg, &zbee_aps_frag_items, NULL, aps_tree);
 621   
 622          /* Update the info column regarding the fragmentation. */
 623          if (check_col(pinfo->cinfo, COL_INFO)) {
 624              if (frag_msg)   col_append_str(pinfo->cinfo, COL_INFO, " (Message Reassembled)");
 625              else            col_append_fstr(pinfo->cinfo, COL_INFO, " (Message fragment %u)", packet.counter);
 626          }
 627   
 628          if (new_tvb) {
 629              /* The reassembly handler defragmented the message, and created a new tvbuff. */
 630              payload_tvb = new_tvb;
 631          }
 632          else {
 633              /* The reassembly handler could not defragment the message. */
 634              call_dissector(data_handle, payload_tvb, pinfo, tree);
 635              return;
 636          }
 637      }
 638   
 639      /* Handle the packet type. */
 640      switch (packet.type) {
 641          case ZBEE_APS_FCF_DATA:
 642              if (!payload_tvb) {
 643                  break;
 644              }
 645              if (pinfo->zbee_stack_vers <= ZBEE_VERSION_2004) {
 646                  /*
 647                   * In ZigBee 2004, an "application framework" sits between the 
 648                   * APS and application. Call a subdissector to handle it.
 649                   */
 650                  pinfo->private_data = profile_handle;
 651                  profile_handle = zbee_apf_handle;
 652              }
 653              else if (profile_handle == NULL) {
 654                  /* Could not locate a profile dissector. */
 655                  break;
 656              }
 657              call_dissector(profile_handle, payload_tvb, pinfo, tree);
 658              return;
 659   
 660          case ZBEE_APS_FCF_CMD:
 661              if (!payload_tvb) {
 662                  /* Command packets MUST contain a payload. */
 663                  expert_add_info_format(pinfo, proto_root, PI_MALFORMED, PI_ERROR, "Missing Payload");
 664                  THROW(BoundsError);
 665                  return;
 666              }
 667              dissect_zbee_aps_cmd(payload_tvb, pinfo, aps_tree);
 668              return;
 669   
 670          case ZBEE_APS_FCF_ACK:
 671              /* Acks should never contain a payload. */
 672              break;
 673   
 674          default:
 675              /* Illegal frame type.  */
 676              break;
 677      } /* switch */
 678      /*
 679       * If we get this far, then no subdissectors have been called, use the data 
 680       * dissector to display the leftover bytes, if any.
 681       */
 682      if (payload_tvb) {
 683          call_dissector(data_handle, payload_tvb, pinfo, tree);
 684      }
 685  } /* dissect_zbee_aps */
Show more  




Change Warning 3090.34179 : Unreachable Control Flow

Priority:
State:
Finding:
Owner:
Note: