2 * Routines for NetBIOS protocol packet disassembly
3 * Jeff Foster <jfoste@woodward.com>
4 * Copyright 1999 Jeffrey C. Foster
6 * derived from the packet-nbns.c
8 * $Id: packet-netbios.c,v 1.57 2003/04/20 11:36:14 guy Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <epan/packet.h>
39 #include "reassemble.h"
41 #include "packet-netbios.h"
43 /* Netbios command numbers */
44 #define NB_ADD_GROUP 0x00
45 #define NB_ADD_NAME 0x01
46 #define NB_NAME_IN_CONFLICT 0x02
47 #define NB_STATUS_QUERY 0x03
48 #define NB_TERMINATE_TRACE_R 0x07
49 #define NB_DATAGRAM 0x08
50 #define NB_DATAGRAM_BCAST 0x09
51 #define NB_NAME_QUERY 0x0a
52 #define NB_ADD_NAME_RESP 0x0d
53 #define NB_NAME_RESP 0x0e
54 #define NB_STATUS_RESP 0x0f
55 #define NB_TERMINATE_TRACE_LR 0x13
56 #define NB_DATA_ACK 0x14
57 #define NB_DATA_FIRST_MIDDLE 0x15
58 #define NB_DATA_ONLY_LAST 0x16
59 #define NB_SESSION_CONFIRM 0x17
60 #define NB_SESSION_END 0x18
61 #define NB_SESSION_INIT 0x19
62 #define NB_NO_RECEIVE 0x1a
63 #define NB_RECEIVE_OUTSTANDING 0x1b
64 #define NB_RECEIVE_CONTINUE 0x1c
65 #define NB_KEEP_ALIVE 0x1f
67 /* Offsets of fields in the NetBIOS header. */
69 #define NB_DELIMITER 2
75 #define NB_CALL_NAME_TYPE 7
76 #define NB_XMIT_CORL 8
77 #define NB_RESP_CORL 10
79 #define NB_LOCAL_SES 13
80 #define NB_RECVER_NAME 12
81 #define NB_SENDER_NAME 28
84 static int proto_netbios = -1;
85 static int hf_netb_cmd = -1;
86 static int hf_netb_hdr_len = -1;
87 static int hf_netb_xmit_corrl = -1;
88 static int hf_netb_resp_corrl = -1;
89 static int hf_netb_call_name_type = -1;
90 static int hf_netb_ack = -1;
91 static int hf_netb_ack_with_data = -1;
92 static int hf_netb_ack_expected = -1;
93 static int hf_netb_recv_cont_req = -1;
94 static int hf_netb_send_no_ack = -1;
95 static int hf_netb_version = -1;
96 static int hf_netb_largest_frame = -1;
97 static int hf_netb_nb_name = -1;
98 static int hf_netb_nb_name_type = -1;
99 static int hf_netb_status_buffer_len = -1;
100 static int hf_netb_status = -1;
101 static int hf_netb_name_type = -1;
102 static int hf_netb_max_data_recv_size = -1;
103 static int hf_netb_termination_indicator = -1;
104 static int hf_netb_num_data_bytes_accepted = -1;
105 static int hf_netb_local_ses_no = -1;
106 static int hf_netb_remote_ses_no = -1;
107 static int hf_netb_data1 = -1;
108 static int hf_netb_data2 = -1;
109 static int hf_netb_fragments = -1;
110 static int hf_netb_fragment = -1;
111 static int hf_netb_fragment_overlap = -1;
112 static int hf_netb_fragment_overlap_conflict = -1;
113 static int hf_netb_fragment_multiple_tails = -1;
114 static int hf_netb_fragment_too_long_fragment = -1;
115 static int hf_netb_fragment_error = -1;
117 static gint ett_netb = -1;
118 static gint ett_netb_name = -1;
119 static gint ett_netb_flags = -1;
120 static gint ett_netb_status = -1;
121 static gint ett_netb_fragments = -1;
122 static gint ett_netb_fragment = -1;
124 static const fragment_items netbios_frag_items = {
129 &hf_netb_fragment_overlap,
130 &hf_netb_fragment_overlap_conflict,
131 &hf_netb_fragment_multiple_tails,
132 &hf_netb_fragment_too_long_fragment,
133 &hf_netb_fragment_error,
138 static dissector_handle_t data_handle;
140 /* The strings for the station type, used by get_netbios_name function;
141 many of them came from the file "NetBIOS.txt" in the Zip archive at
143 http://www.net3group.com/ftp/browser.zip
146 static const value_string nb_name_type_vals[] = {
147 {0x00, "Workstation/Redirector"},
149 {0x02, "Workstation/Redirector"},
150 /* not sure what 0x02 is, I'm seeing alot of them however */
151 /* i'm seeing them with workstation/redirection host
153 {0x03, "Messenger service/Main name"},
154 {0x05, "Forwarded name"},
155 {0x06, "RAS Server service"},
156 {0x1b, "Domain Master Browser"},
157 {0x1c, "Domain Controllers"},
158 {0x1d, "Local Master Browser"},
159 {0x1e, "Browser Election Service"},
160 {0x1f, "Net DDE Service"},
161 {0x20, "Server service"},
162 {0x21, "RAS client service"},
163 {0x22, "Exchange Interchange (MSMail Connector)"},
164 {0x23, "Exchange Store"},
165 {0x24, "Exchange Directory"},
166 {0x2b, "Lotus Notes Server service"},
167 {0x30, "Modem sharing server service"},
168 {0x31, "Modem sharing client service"},
169 {0x43, "SMS Clients Remote Control"},
170 {0x44, "SMS Administrators Remote Control Tool"},
171 {0x45, "SMS Clients Remote Chat"},
172 {0x46, "SMS Clients Remote Transfer"},
173 {0x4c, "DEC Pathworks TCP/IP Service on Windows NT"},
174 {0x52, "DEC Pathworks TCP/IP Service on Windows NT"},
175 {0x6a, "Microsoft Exchange IMC"},
176 {0x87, "Microsoft Exchange MTA"},
177 {0xbe, "Network Monitor Agent"},
178 {0xbf, "Network Monitor Analyzer"},
182 /* Tables for reassembly of fragments. */
183 static GHashTable *netbios_fragment_table = NULL;
184 static GHashTable *netbios_reassembled_table = NULL;
186 /* defragmentation of NetBIOS Frame */
187 static gboolean netbios_defragment = TRUE;
191 http://www.s390.ibm.com/bookmgr-cgi/bookmgr.cmd/BOOKS/BK8P7001/CCONTENTS
195 http://ourworld.compuserve.com/homepages/TimothyDEvans/contents.htm
197 for information about the NetBIOS Frame Protocol (which is what this
200 /* the strings for the command types */
202 static const value_string cmd_vals[] = {
203 { NB_ADD_GROUP, "Add Group Name Query" },
204 { NB_ADD_NAME, "Add Name Query" },
205 { NB_NAME_IN_CONFLICT, "Name In Conflict" },
206 { NB_STATUS_QUERY, "Status Query" },
207 { NB_TERMINATE_TRACE_R, "Terminate Trace" },
208 { NB_DATAGRAM, "Datagram" },
209 { NB_DATAGRAM_BCAST, "Broadcast Datagram" },
210 { NB_NAME_QUERY, "Name Query" },
211 { NB_ADD_NAME_RESP, "Add Name Response" },
212 { NB_NAME_RESP, "Name Recognized" },
213 { NB_STATUS_RESP, "Status Response" },
214 { NB_TERMINATE_TRACE_LR, "Terminate Trace" },
215 { NB_DATA_ACK, "Data Ack" },
216 { NB_DATA_FIRST_MIDDLE, "Data First Middle" },
217 { NB_DATA_ONLY_LAST, "Data Only Last" },
218 { NB_SESSION_CONFIRM, "Session Confirm" },
219 { NB_SESSION_END, "Session End" },
220 { NB_SESSION_INIT, "Session Initialize" },
221 { NB_NO_RECEIVE, "No Receive" },
222 { NB_RECEIVE_OUTSTANDING, "Receive Outstanding" },
223 { NB_RECEIVE_CONTINUE, "Receive Continue" },
224 { NB_KEEP_ALIVE, "Session Alive" },
228 static const value_string name_types[] = {
229 { 0, "Unique name" },
234 static const true_false_string flags_set = {
238 static const true_false_string flags_allowed = {
242 static const true_false_string flags_yes_no = {
247 static const true_false_string netb_version_str = {
252 static const value_string termination_indicator_vals[] = {
253 { 0x0000, "Normal session end" },
254 { 0x0001, "Abnormal session end" },
258 static const value_string status_vals[] = {
259 { 0, "Add name not in process" },
260 { 1, "Add name in process" },
264 static const value_string max_frame_size_vals[] = {
271 { 6, "17800" }, /* 17800 in TR spec, 17749 in NBF spec */
277 void capture_netbios(packet_counts *ld)
284 process_netbios_name(const guchar *name_ptr, char *name_ret)
287 int name_type = *(name_ptr + NETBIOS_NAME_LEN - 1);
289 static const char hex_digits[16] = "0123456789abcdef";
291 for (i = 0; i < NETBIOS_NAME_LEN - 1; i++) {
292 name_char = *name_ptr++;
293 if (name_char >= ' ' && name_char <= '~')
294 *name_ret++ = name_char;
296 /* It's not printable; show it as <XX>, where
297 XX is the value in hex. */
299 *name_ret++ = hex_digits[(name_char >> 4)];
300 *name_ret++ = hex_digits[(name_char & 0x0F)];
306 /* Remove trailing space characters from name. */
310 for (i = 0; i < NETBIOS_NAME_LEN - 1; i++) {
311 if (*name_ret != ' ') {
322 int get_netbios_name( tvbuff_t *tvb, int offset, char *name_ret)
324 {/* Extract the name string and name type. Return the name string in */
325 /* name_ret and return the name_type. */
327 return process_netbios_name( tvb_get_ptr( tvb, offset, NETBIOS_NAME_LEN ), name_ret);
332 * Get a string describing the type of a NetBIOS name.
335 netbios_name_type_descr(int name_type)
337 return val_to_str(name_type, nb_name_type_vals, "Unknown");
340 void netbios_add_name(char* label, tvbuff_t *tvb, int offset,
343 {/* add a name field display tree. Display the name and station type in sub-tree */
345 proto_tree *field_tree;
347 char name_str[(NETBIOS_NAME_LEN - 1)*4 + 1];
351 /* decode the name field */
352 name_type = get_netbios_name( tvb, offset, name_str);
353 name_type_str = netbios_name_type_descr(name_type);
354 tf = proto_tree_add_text( tree, tvb, offset, NETBIOS_NAME_LEN,
355 "%s: %s<%02x> (%s)", label, name_str, name_type, name_type_str);
357 field_tree = proto_item_add_subtree( tf, ett_netb_name);
358 proto_tree_add_string_format( field_tree, hf_netb_nb_name, tvb, offset,
359 15, name_str, "%s", name_str);
360 proto_tree_add_uint_format( field_tree, hf_netb_nb_name_type, tvb, offset + 15, 1, name_type,
361 "0x%02x (%s)", name_type, name_type_str);
365 static void netbios_data_first_middle_flags( tvbuff_t *tvb, proto_tree *tree, int offset)
368 proto_tree *field_tree;
370 guint flags = tvb_get_guint8( tvb, offset);
372 /* decode the flag field for Data First Middle packet*/
374 tf = proto_tree_add_text(tree, tvb, offset, 1,
375 "Flags: 0x%02x", flags);
376 field_tree = proto_item_add_subtree(tf, ett_netb_flags);
378 proto_tree_add_boolean( field_tree, hf_netb_ack, tvb, offset, 1, flags);
380 proto_tree_add_boolean( field_tree, hf_netb_ack_expected, tvb, offset, 1, flags);
382 proto_tree_add_boolean( field_tree, hf_netb_recv_cont_req, tvb, offset, 1, flags);
385 static void netbios_data_only_flags( tvbuff_t *tvb, proto_tree *tree,
388 proto_tree *field_tree;
390 guint flags = tvb_get_guint8( tvb, offset);
392 /* decode the flag field for Data Only Last packet*/
394 tf = proto_tree_add_text(tree, tvb, offset, 1,
395 "Flags: 0x%02x", flags);
396 field_tree = proto_item_add_subtree(tf, ett_netb_flags);
398 proto_tree_add_boolean( field_tree, hf_netb_ack, tvb, offset, 1, flags);
400 proto_tree_add_boolean( field_tree, hf_netb_ack_with_data, tvb, offset, 1, flags);
402 proto_tree_add_boolean( field_tree, hf_netb_ack_expected, tvb, offset, 1, flags);
407 static void netbios_add_ses_confirm_flags( tvbuff_t *tvb, proto_tree *tree,
410 proto_tree *field_tree;
412 guint flags = tvb_get_guint8( tvb, offset);
414 /* decode the flag field for Session Confirm packet */
415 tf = proto_tree_add_text(tree, tvb, offset, 1,
416 "Flags: 0x%02x", flags);
417 field_tree = proto_item_add_subtree( tf, ett_netb_flags);
419 proto_tree_add_boolean( field_tree, hf_netb_send_no_ack, tvb, offset, 1, flags);
421 proto_tree_add_boolean( field_tree, hf_netb_version, tvb, offset, 1, flags);
425 static void netbios_add_session_init_flags( tvbuff_t *tvb, proto_tree *tree,
428 proto_tree *field_tree;
430 guint flags = tvb_get_guint8( tvb, offset);
431 /* decode the flag field for Session Init packet */
433 tf = proto_tree_add_text(tree, tvb, offset, 1,
434 "Flags: 0x%02x", flags);
435 field_tree = proto_item_add_subtree(tf, ett_netb_flags);
437 proto_tree_add_boolean( field_tree, hf_netb_send_no_ack, tvb, offset, 1, flags);
439 proto_tree_add_uint( field_tree, hf_netb_largest_frame, tvb, offset, 1,
442 proto_tree_add_boolean( field_tree, hf_netb_version, tvb, offset, 1, flags);
446 static void netbios_no_receive_flags( tvbuff_t *tvb, proto_tree *tree,
450 proto_tree *field_tree;
452 guint flags = tvb_get_guint8( tvb, offset);
454 /* decode the flag field for No Receive packet*/
456 tf = proto_tree_add_text(tree, tvb, offset, 1,
457 "Flags: 0x%02x", flags);
460 field_tree = proto_item_add_subtree(tf, ett_netb_flags);
461 proto_tree_add_text(field_tree, tvb, offset, 1, "%s",
462 decode_boolean_bitfield(flags, 0x02, 8,
463 "SEND.NO.ACK data not received", NULL));
468 /************************************************************************/
470 /* The routines to display the netbios field values in the tree */
472 /************************************************************************/
475 static void nb_xmit_corrl( tvbuff_t *tvb, int offset, proto_tree *tree)
477 {/* display the transmit correlator */
479 proto_tree_add_item( tree, hf_netb_xmit_corrl, tvb, offset + NB_XMIT_CORL,
484 static void nb_resp_corrl( tvbuff_t *tvb, int offset, proto_tree *tree)
486 {/* display the response correlator */
488 proto_tree_add_item( tree, hf_netb_resp_corrl, tvb, offset + NB_RESP_CORL,
493 static void nb_call_name_type( tvbuff_t *tvb, int offset, proto_tree *tree)
495 {/* display the call name type */
497 proto_tree_add_item( tree, hf_netb_call_name_type, tvb, offset + NB_CALL_NAME_TYPE,
503 static guint8 nb_local_session( tvbuff_t *tvb, int offset, proto_tree *tree)
505 {/* add the local session to tree, and return its value */
507 guint8 local_session = tvb_get_guint8( tvb, offset + NB_LOCAL_SES);
509 proto_tree_add_uint( tree, hf_netb_local_ses_no, tvb, offset + NB_LOCAL_SES, 1,
512 return local_session;
516 static guint8 nb_remote_session( tvbuff_t *tvb, int offset, proto_tree *tree)
518 {/* add the remote session to tree, and return its value */
520 guint8 remote_session = tvb_get_guint8( tvb, offset + NB_RMT_SES);
522 proto_tree_add_uint( tree, hf_netb_remote_ses_no, tvb, offset + NB_RMT_SES, 1,
525 return remote_session;
529 static void nb_data1(int hf, tvbuff_t *tvb, int offset, proto_tree *tree)
531 {/* add the DATA1 to tree with specified hf_ value */
533 proto_tree_add_item( tree, hf, tvb, offset + NB_DATA1, 1, TRUE);
538 static void nb_data2(int hf, tvbuff_t *tvb, int offset, proto_tree *tree)
540 {/* add the DATA2 to tree with specified hf_ value */
542 proto_tree_add_item( tree, hf, tvb, offset + NB_DATA2, 2, TRUE);
547 static void nb_resync_indicator( tvbuff_t *tvb, int offset, proto_tree *tree, char *cmd_str)
549 guint16 resync_indicator = tvb_get_letohs( tvb, offset + NB_DATA2);
552 switch (resync_indicator) {
555 proto_tree_add_text(tree, tvb, offset + NB_DATA2, 2,
556 "Re-sync indicator: No re-sync");
560 proto_tree_add_text(tree, tvb, offset + NB_DATA2, 2,
561 "Re-sync indicator: First '%s' following 'Receive Outstanding'", cmd_str);
565 proto_tree_add_text(tree, tvb, offset + NB_DATA2, 2,
566 "Re-sync indicator: 0x%04x", resync_indicator);
571 /************************************************************************/
573 /* The routines called by the top level to handle individual commands */
575 /************************************************************************/
578 dissect_netb_unknown( tvbuff_t *tvb, int offset, proto_tree *tree)
580 {/* Handle any unknown commands, do nothing */
582 proto_tree_add_text(tree, tvb, offset + NB_COMMAND + 1, -1,
583 "Unknown NetBIOS command data");
590 dissect_netb_add_group_name( tvbuff_t *tvb, int offset, proto_tree *tree)
592 {/* Handle the ADD GROUP NAME QUERY command */
594 nb_resp_corrl( tvb, offset, tree);
596 netbios_add_name("Group name to add", tvb, offset + NB_SENDER_NAME,
604 dissect_netb_add_name( tvbuff_t *tvb, int offset, proto_tree *tree)
606 {/* Handle the ADD NAME QUERY command */
608 nb_resp_corrl( tvb, offset, tree);
610 netbios_add_name("Name to add", tvb, offset + NB_SENDER_NAME, tree);
617 dissect_netb_name_in_conflict( tvbuff_t *tvb, int offset, proto_tree *tree)
619 {/* Handle the NAME IN CONFLICT command */
621 netbios_add_name("Name In Conflict", tvb, offset + NB_RECVER_NAME,
623 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME, tree);
630 dissect_netb_status_query( tvbuff_t *tvb, int offset, proto_tree *tree)
632 {/* Handle the STATUS QUERY command */
634 guint8 status_request = tvb_get_guint8( tvb, offset + NB_DATA1);
636 switch (status_request) {
639 proto_tree_add_text(tree, tvb, offset + NB_DATA1, 1,
640 "Status request: NetBIOS 1.x or 2.0");
644 proto_tree_add_text(tree, tvb, offset + NB_DATA1, 1,
645 "Status request: NetBIOS 2.1, initial status request");
649 proto_tree_add_text(tree, tvb, offset + NB_DATA1, 1,
650 "Status request: NetBIOS 2.1, %u names received so far",
654 nb_data2( hf_netb_status_buffer_len, tvb, offset, tree);
655 nb_resp_corrl( tvb, offset, tree);
656 netbios_add_name("Receiver's Name", tvb, offset + NB_RECVER_NAME, tree);
657 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME, tree);
664 dissect_netb_terminate_trace( tvbuff_t *tvb _U_, int offset _U_, proto_tree *tree _U_)
666 {/* Handle the TERMINATE TRACE command */
669 * XXX - are any of the fields in this message significant?
670 * The IBM NetBIOS document shows them as "Reserved".
677 static guchar zeroes[10];
680 dissect_netb_datagram( tvbuff_t *tvb, int offset, proto_tree *tree)
682 {/* Handle the DATAGRAM command */
684 netbios_add_name("Receiver's Name", tvb, offset + NB_RECVER_NAME, tree);
685 /* Weird. In some datagrams, this is 10 octets of 0, followed
686 by a MAC address.... */
688 if (memcmp( tvb_get_ptr( tvb,offset + NB_SENDER_NAME, 10), zeroes, 10) == 0) {
689 proto_tree_add_text( tree, tvb, offset + NB_SENDER_NAME + 10, 6,
690 "Sender's MAC Address: %s",
691 ether_to_str( tvb_get_ptr( tvb,offset + NB_SENDER_NAME + 10, 6)));
693 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME,
702 dissect_netb_datagram_bcast( tvbuff_t *tvb, int offset, proto_tree *tree)
704 {/* Handle the DATAGRAM BROADCAST command */
706 /* We assume the same weirdness can happen here.... */
707 if ( memcmp( tvb_get_ptr( tvb,offset + NB_SENDER_NAME + 10, 6), zeroes, 10) == 0) {
708 proto_tree_add_text( tree, tvb, offset + NB_SENDER_NAME + 10, 6,
709 "Sender's Node Address: %s",
710 ether_to_str( tvb_get_ptr( tvb,offset + NB_SENDER_NAME + 10, 6)));
712 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME,
721 dissect_netb_name_query( tvbuff_t *tvb, int offset, proto_tree *tree)
723 {/* Handle the NAME QUERY command */
724 guint8 local_session_number = tvb_get_guint8( tvb, offset + NB_DATA2);
726 if (local_session_number == 0) {
727 proto_tree_add_text( tree, tvb, offset + NB_DATA2, 1,
728 "Local Session No.: 0 (FIND.NAME request)");
730 proto_tree_add_text( tree, tvb, offset + NB_DATA2, 1,
731 "Local Session No.: 0x%02x", local_session_number);
733 nb_call_name_type( tvb, offset, tree);
734 nb_resp_corrl( tvb, offset, tree);
735 netbios_add_name("Query Name", tvb, offset + NB_RECVER_NAME, tree);
736 if (local_session_number != 0) {
737 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME,
746 dissect_netb_add_name_resp( tvbuff_t *tvb, int offset, proto_tree *tree)
748 {/* Handle the ADD NAME RESPONSE command */
750 nb_data1( hf_netb_status, tvb, offset, tree);
751 nb_data2( hf_netb_name_type, tvb, offset, tree);
752 nb_xmit_corrl( tvb, offset, tree);
753 netbios_add_name("Name to be added", tvb, offset + NB_RECVER_NAME,
755 netbios_add_name("Name to be added", tvb, offset + NB_SENDER_NAME,
763 dissect_netb_name_resp( tvbuff_t *tvb, int offset, proto_tree *tree)
765 {/* Handle the NAME RECOGNIZED command */
766 guint8 local_session_number = tvb_get_guint8( tvb, offset + NB_DATA2);
768 switch (local_session_number) {
771 proto_tree_add_text( tree, tvb, offset + NB_DATA2, 1,
772 "State of name: No LISTEN pending, or FIND.NAME response");
776 proto_tree_add_text( tree, tvb, offset + NB_DATA2, 1,
777 "State of name: LISTEN pending, but insufficient resources to establish session");
781 proto_tree_add_text( tree, tvb, offset + NB_DATA2, 1,
782 "Local Session No.: 0x%02x", local_session_number);
785 nb_call_name_type( tvb, offset, tree);
786 nb_xmit_corrl( tvb, offset, tree);
787 if (local_session_number != 0x00 && local_session_number != 0xFF)
788 nb_resp_corrl(tvb, offset, tree);
789 netbios_add_name("Receiver's Name", tvb, offset + NB_RECVER_NAME, tree);
790 if (local_session_number != 0x00 && local_session_number != 0xFF) {
791 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME,
800 dissect_netb_status_resp( tvbuff_t *tvb, int offset, proto_tree *tree)
802 {/* Handle the STATUS RESPONSE command */
803 guint8 status_response = tvb_get_guint8( tvb, offset + NB_DATA1);
805 proto_tree *data2_tree;
808 nb_call_name_type( tvb, offset, tree);
809 if (status_response == 0) {
810 proto_tree_add_text(tree, tvb, offset + NB_DATA1, 1,
811 "Status response: NetBIOS 1.x or 2.0");
813 proto_tree_add_text(tree, tvb, offset + NB_DATA1, 1,
814 "Status response: NetBIOS 2.1, %u names sent so far",
817 data2 = tvb_get_letohs( tvb, offset + NB_DATA2);
819 td2 = proto_tree_add_text(tree, tvb, offset + NB_DATA2, 2, "Status: 0x%04x",
821 data2_tree = proto_item_add_subtree(td2, ett_netb_status);
822 if (data2 & 0x8000) {
823 proto_tree_add_text(data2_tree, tvb, offset, 2, "%s",
824 decode_boolean_bitfield(data2, 0x8000, 8*2,
825 "Data length exceeds maximum frame size", NULL));
827 if (data2 & 0x4000) {
828 proto_tree_add_text(data2_tree, tvb, offset, 2, "%s",
829 decode_boolean_bitfield(data2, 0x4000, 8*2,
830 "Data length exceeds user's buffer", NULL));
832 proto_tree_add_text(data2_tree, tvb, offset, 2, "%s",
833 decode_numeric_bitfield(data2, 0x3FFF, 2*8,
834 "Status data length = %u"));
835 nb_xmit_corrl( tvb, offset, tree);
836 netbios_add_name("Receiver's Name", tvb, offset + NB_RECVER_NAME, tree);
837 netbios_add_name("Sender's Name", tvb, offset + NB_SENDER_NAME,
845 dissect_netb_data_ack( tvbuff_t* tvb, int offset, proto_tree *tree)
847 {/* Handle the DATA ACK command */
849 nb_xmit_corrl( tvb, offset, tree);
850 nb_remote_session( tvb, offset, tree);
851 nb_local_session( tvb, offset, tree);
858 dissect_netb_data_first_middle( tvbuff_t *tvb, int offset, proto_tree *tree)
860 {/* Handle the DATA FIRST MIDDLE command */
862 guint8 remote_session, local_session;
865 * This is the first frame, or the middle frame, of a fragmented
868 * XXX - there are no sequence numbers, so we have to assume
869 * that fragments arrive in order with no duplicates.
870 * In fact, 802.2 LLC is supposed to handle that, so we
871 * might have to have the LLC dissector do so (but the TCP
872 * dissector doesn't currently handle out-of-order or duplicate
876 netbios_data_first_middle_flags( tvb, tree, offset + NB_FLAGS);
878 nb_resync_indicator( tvb, offset, tree, "DATA FIRST MIDDLE");
879 nb_xmit_corrl( tvb, offset, tree);
880 nb_resp_corrl( tvb, offset, tree);
881 remote_session = nb_remote_session( tvb, offset, tree);
882 local_session = nb_local_session( tvb, offset, tree);
885 * Return a combination of the remote and local session numbers,
886 * for use when reassembling.
888 return (remote_session << 8) + local_session;
893 dissect_netb_data_only_last( tvbuff_t *tvb, int offset, proto_tree *tree)
895 {/* Handle the DATA ONLY LAST command */
897 guint8 remote_session, local_session;
900 * This is a complete packet, or the last frame of a fragmented
904 netbios_data_only_flags( tvb, tree, offset + NB_FLAGS);
906 nb_resync_indicator( tvb, offset, tree, "DATA ONLY LAST");
907 nb_xmit_corrl( tvb, offset, tree);
908 nb_resp_corrl( tvb, offset, tree);
909 remote_session = nb_remote_session( tvb, offset, tree);
910 local_session = nb_local_session( tvb, offset, tree);
913 * Return a combination of the remote and local session numbers,
914 * for use when reassembling.
916 return (remote_session << 8) + local_session;
921 dissect_netb_session_confirm( tvbuff_t *tvb, int offset, proto_tree *tree)
923 {/* Handle the SESSION CONFIRM command */
925 netbios_add_ses_confirm_flags( tvb, tree, offset + NB_FLAGS);
927 nb_data2( hf_netb_max_data_recv_size, tvb, offset, tree);
928 nb_xmit_corrl( tvb, offset, tree);
929 nb_resp_corrl( tvb, offset, tree);
930 nb_remote_session( tvb, offset, tree);
931 nb_local_session( tvb, offset, tree);
938 dissect_netb_session_end( tvbuff_t *tvb, int offset, proto_tree *tree)
940 {/* Handle the SESSION END command */
942 nb_data2( hf_netb_termination_indicator, tvb, offset, tree);
943 nb_remote_session( tvb, offset, tree);
944 nb_local_session( tvb, offset, tree);
951 dissect_netb_session_init( tvbuff_t *tvb, int offset, proto_tree *tree)
953 {/* Handle the SESSION INITIALIZE command */
955 netbios_add_session_init_flags( tvb, tree, offset + NB_FLAGS);
957 nb_data2( hf_netb_max_data_recv_size, tvb, offset, tree);
958 nb_resp_corrl( tvb, offset, tree);
959 nb_xmit_corrl( tvb, offset, tree);
960 nb_remote_session( tvb, offset, tree);
961 nb_local_session( tvb, offset, tree);
967 dissect_netb_no_receive( tvbuff_t *tvb, int offset, proto_tree *tree)
969 {/* Handle the NO RECEIVE command */
971 netbios_no_receive_flags( tvb, tree, offset + NB_FLAGS);
973 nb_data2( hf_netb_num_data_bytes_accepted, tvb, offset, tree);
974 nb_remote_session( tvb, offset, tree);
975 nb_local_session( tvb, offset, tree);
982 dissect_netb_receive_outstanding( tvbuff_t *tvb, int offset, proto_tree *tree)
984 {/* Handle the RECEIVE OUTSTANDING command */
986 nb_data2( hf_netb_num_data_bytes_accepted, tvb, offset, tree);
987 nb_remote_session( tvb, offset, tree);
988 nb_local_session( tvb, offset, tree);
995 dissect_netb_receive_continue( tvbuff_t *tvb, int offset, proto_tree *tree)
997 {/* Handle the RECEIVE CONTINUE command */
999 nb_xmit_corrl( tvb, offset, tree);
1000 nb_remote_session( tvb, offset, tree);
1001 nb_local_session( tvb, offset, tree);
1008 dissect_netb_session_alive( tvbuff_t *tvb, int offset, proto_tree *tree)
1010 {/* Handle the SESSION ALIVE command */
1013 * XXX - all the fields are claimed to be "Reserved", but
1014 * the session numbers appear to be non-zero in at least
1015 * one capture, and they do appear to match session numbers
1016 * in other messages, and I'd expect that you had to identify
1017 * sessions in this message in any case.
1019 * We show only those fields.
1021 nb_remote_session( tvb, offset, tree);
1022 nb_local_session( tvb, offset, tree);
1028 /************************************************************************/
1030 /* The table routines called by the top level to handle commands */
1032 /************************************************************************/
1035 static guint32 (*dissect_netb[])(tvbuff_t *, int, proto_tree *) = {
1037 dissect_netb_add_group_name, /* Add Group Name 0x00 */
1038 dissect_netb_add_name, /* Add Name 0x01 */
1039 dissect_netb_name_in_conflict,/* Name In Conflict 0x02 */
1040 dissect_netb_status_query, /* Status Query 0x03 */
1041 dissect_netb_unknown, /* unknown 0x04 */
1042 dissect_netb_unknown, /* unknown 0x05 */
1043 dissect_netb_unknown, /* unknown 0x06 */
1044 dissect_netb_terminate_trace, /* Terminate Trace 0x07 */
1045 dissect_netb_datagram, /* Datagram 0x08 */
1046 dissect_netb_datagram_bcast, /* Datagram Broadcast 0x09 */
1047 dissect_netb_name_query, /* Name Query 0x0A */
1048 dissect_netb_unknown, /* unknown 0x0B */
1049 dissect_netb_unknown, /* unknown 0x0C */
1050 dissect_netb_add_name_resp, /* Add Name Response 0x0D */
1051 dissect_netb_name_resp, /* Name Recognized 0x0E */
1052 dissect_netb_status_resp, /* Status Response 0x0F */
1053 dissect_netb_unknown, /* unknown 0x10 */
1054 dissect_netb_unknown, /* unknown 0x11 */
1055 dissect_netb_unknown, /* unknown 0x12 */
1056 dissect_netb_terminate_trace, /* Terminate Trace 0x13 */
1057 dissect_netb_data_ack, /* Data Ack 0x14 */
1058 dissect_netb_data_first_middle,/* Data First Middle 0x15 */
1059 dissect_netb_data_only_last, /* Data Only Last 0x16 */
1060 dissect_netb_session_confirm, /* Session Confirm 0x17 */
1061 dissect_netb_session_end, /* Session End 0x18 */
1062 dissect_netb_session_init, /* Session Initialize 0x19 */
1063 dissect_netb_no_receive, /* No Receive 0x1A */
1064 dissect_netb_receive_outstanding,/* Receive Outstanding 0x1B */
1065 dissect_netb_receive_continue,/* Receive Continue 0x1C */
1066 dissect_netb_unknown, /* unknown 0x1D */
1067 dissect_netb_unknown, /* unknown 0x1E */
1068 dissect_netb_session_alive, /* Session Alive 0x1f */
1069 dissect_netb_unknown,
1072 static heur_dissector_list_t netbios_heur_subdissector_list;
1075 dissect_netbios_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1078 * Try the heuristic dissectors for NetBIOS; if none of them
1079 * accept the packet, dissect it as data.
1081 if (!dissector_try_heuristic(netbios_heur_subdissector_list,
1083 call_dissector(data_handle,tvb, pinfo, tree);
1087 dissect_netbios(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1090 proto_tree *netb_tree = NULL;
1092 guint16 hdr_len, command;
1094 char name[(NETBIOS_NAME_LEN - 1)*4 + 1];
1097 gboolean save_fragmented;
1099 fragment_data *fd_head;
1104 /* load the display labels */
1105 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1106 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NetBIOS");
1109 /* Find NetBIOS marker EFFF, this is done because I have seen an extra LLC */
1110 /* byte on our network. This only checks for one extra LLC byte. */
1112 if ( 0xefff != tvb_get_letohs(tvb, 2)){
1114 if ( 0xefff != tvb_get_letohs(tvb, 3)){
1116 if (check_col( pinfo->cinfo, COL_INFO)) /* print bad packet */
1117 col_set_str( pinfo->cinfo, COL_INFO, "Bad packet, no 0xEFFF marker");
1119 return; /* this is an unknow packet, no marker */
1124 hdr_len = tvb_get_letohs(tvb, offset + NB_LENGTH);
1125 command = tvb_get_guint8( tvb, offset + NB_COMMAND);
1126 /* limit command so no table overflows */
1127 command = MIN( command, sizeof( dissect_netb)/ sizeof(void *));
1129 if (check_col( pinfo->cinfo, COL_INFO)) { /* print command name */
1130 command_name = val_to_str(command, cmd_vals, "Unknown (0x%02x)");
1131 switch ( command ) {
1133 name_type = get_netbios_name( tvb, offset + 12, name);
1134 col_add_fstr( pinfo->cinfo, COL_INFO, "%s for %s<%02x>",
1135 command_name, name, name_type);
1141 name_type = get_netbios_name( tvb, offset + 28, name);
1142 col_add_fstr( pinfo->cinfo, COL_INFO, "%s - %s<%02x>",
1143 command_name, name, name_type);
1147 col_add_fstr( pinfo->cinfo, COL_INFO, "%s",
1154 ti = proto_tree_add_item(tree, proto_netbios, tvb, 0, hdr_len, FALSE);
1155 netb_tree = proto_item_add_subtree(ti, ett_netb);
1157 proto_tree_add_uint_format(netb_tree, hf_netb_hdr_len, tvb, offset, 2, hdr_len,
1158 "Length: %d bytes", hdr_len);
1160 proto_tree_add_text(netb_tree, tvb, offset + 2, 2,
1161 "Delimiter: EFFF (NetBIOS)");
1163 proto_tree_add_uint(netb_tree, hf_netb_cmd, tvb, offset + NB_COMMAND, 1, command);
1166 /* if command in table range */
1167 if ( command < sizeof( dissect_netb)/ sizeof(void *)) {
1169 /* branch to handle commands */
1170 session_id = (dissect_netb[ command])( tvb, offset, netb_tree);
1172 offset += hdr_len; /* move past header */
1174 save_fragmented = pinfo->fragmented;
1177 * Process user data in frames that have it.
1182 case NB_DATAGRAM_BCAST:
1184 * No fragmentation here.
1186 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1187 dissect_netbios_payload(next_tvb, pinfo, tree);
1190 case NB_DATA_FIRST_MIDDLE:
1191 case NB_DATA_ONLY_LAST:
1193 * Possibly fragmented.
1195 len = tvb_reported_length_remaining(tvb, offset);
1196 if (netbios_defragment &&
1197 tvb_bytes_exist(tvb, offset, len)) {
1198 fd_head = fragment_add_seq_next(tvb, offset,
1200 netbios_fragment_table,
1201 netbios_reassembled_table,
1202 len, command == NB_DATA_FIRST_MIDDLE);
1203 if (fd_head != NULL) {
1204 if (fd_head->next != NULL) {
1205 next_tvb = tvb_new_real_data(fd_head->data,
1206 fd_head->len, fd_head->len);
1207 tvb_set_child_real_data_tvbuff(tvb,
1209 add_new_data_source(pinfo,
1211 "Reassembled NetBIOS");
1212 /* Show all fragments. */
1214 show_fragment_seq_tree(fd_head,
1215 &netbios_frag_items,
1220 next_tvb = tvb_new_subset(tvb,
1228 * Dissect this, regardless of whether
1229 * it's NB_DATA_FIRST_MIDDLE or
1230 * NB_DATA_ONLY_LAST.
1232 * XXX - it'd be nice to show
1233 * NB_DATA_FIRST_MIDDLE as a fragment
1234 * if it's not the first fragment (i.e.,
1235 * MIDDLE rather than FIRST), and show
1236 * NB_DATA_ONLY_LAST as a fragment if
1237 * it's part of a fragmented datagram
1238 * (i.e, LAST rather than ONLY), but
1239 * we'd have to do reassembly to
1240 * be able to determine that.
1242 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1244 if (next_tvb != NULL)
1245 dissect_netbios_payload(next_tvb, pinfo, tree);
1247 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
1248 call_dissector(data_handle, next_tvb, pinfo,
1260 * Initialize the fragment and reassembly tables.
1262 fragment_table_init(&netbios_fragment_table);
1263 reassembled_table_init(&netbios_reassembled_table);
1266 void proto_register_netbios(void)
1268 static gint *ett[] = {
1273 &ett_netb_fragments,
1277 static hf_register_info hf_netb[] = {
1279 { "Command", "netbios.command", FT_UINT8, BASE_HEX, VALS(cmd_vals), 0x0,
1283 { "Header Length", "netbios.hdr_len", FT_UINT16, BASE_DEC, NULL, 0x0,
1286 { &hf_netb_xmit_corrl,
1287 { "Transmit Correlator", "netbios.xmit_corrl", FT_UINT16, BASE_HEX, NULL, 0x0,
1290 { &hf_netb_resp_corrl,
1291 { "Response Correlator", "netbios.resp_corrl", FT_UINT16, BASE_HEX, NULL, 0x0,
1294 { &hf_netb_call_name_type,
1295 { "Caller's Name Type", "netbios.call_name_type", FT_UINT8, BASE_HEX, VALS(name_types), 0x0,
1298 { &hf_netb_nb_name_type,
1299 { "NetBIOS Name Type", "netbios.nb_name_type", FT_UINT8, BASE_HEX, VALS(nb_name_type_vals), 0x0,
1303 { "NetBIOS Name", "netbios.nb_name", FT_STRING, BASE_NONE, NULL, 0x0,
1307 { "Acknowledge", "netbios.ack", FT_BOOLEAN, 8, TFS( &flags_set), 0x08,
1310 { &hf_netb_ack_with_data,
1311 { "Acknowledge with data", "netbios.ack_with_data", FT_BOOLEAN, 8, TFS( &flags_allowed), 0x04,
1314 { &hf_netb_ack_expected,
1315 { "Acknowledge expected", "netbios.ack_expected", FT_BOOLEAN, 8,
1316 TFS( &flags_yes_no), 0x02, "", HFILL }},
1318 { &hf_netb_recv_cont_req,
1319 { "RECEIVE_CONTINUE requested", "netbios.recv_cont_req", FT_BOOLEAN, 8,
1320 TFS( &flags_yes_no), 0x01, "", HFILL }},
1322 { &hf_netb_send_no_ack,
1323 { "Handle SEND.NO.ACK", "netbios.send_no_ack", FT_BOOLEAN, 8,
1324 TFS( &flags_yes_no), 0x80, "", HFILL }},
1327 { "NetBIOS Version", "netbios.version", FT_BOOLEAN, 8,
1328 TFS( &netb_version_str), 0x01, "", HFILL }},
1330 { &hf_netb_largest_frame,
1331 { "Largest Frame", "netbios.largest_frame", FT_UINT8, BASE_DEC, VALS(max_frame_size_vals), 0x0E,
1334 { &hf_netb_status_buffer_len,
1335 { "Length of status buffer", "netbios.status_buffer_len", FT_UINT16, BASE_DEC, NULL, 0x0,
1339 { "Status", "netbios.status", FT_UINT8, BASE_DEC, VALS(status_vals), 0x0,
1342 { &hf_netb_name_type,
1343 { "Name type", "netbios.name_type", FT_UINT16, BASE_DEC, VALS(name_types), 0x0,
1346 { &hf_netb_max_data_recv_size,
1347 { "Maximum data receive size", "netbios.max_data_recv_size", FT_UINT16, BASE_DEC, NULL, 0x0,
1350 { &hf_netb_termination_indicator,
1351 { "Termination indicator", "netbios.termination_indicator", FT_UINT16, BASE_HEX, VALS(termination_indicator_vals), 0x0,
1354 { &hf_netb_num_data_bytes_accepted,
1355 { "Number of data bytes accepted", "netbios.num_data_bytes_accepted", FT_UINT16, BASE_DEC, NULL, 0x0,
1358 { &hf_netb_local_ses_no,
1359 { "Local Session No.", "netbios.local_session", FT_UINT8, BASE_HEX, NULL, 0x0,
1362 { &hf_netb_remote_ses_no,
1363 { "Remote Session No.", "netbios.remote_session", FT_UINT8, BASE_HEX, NULL, 0x0,
1367 { "DATA1 value", "netbios.data1", FT_UINT8, BASE_HEX, NULL, 0x0,
1371 { "DATA2 value", "netbios.data2", FT_UINT16, BASE_HEX, NULL, 0x0,
1374 { &hf_netb_fragment_overlap,
1375 { "Fragment overlap", "netbios.fragment.overlap", FT_BOOLEAN, BASE_NONE,
1376 NULL, 0x0, "Fragment overlaps with other fragments", HFILL }},
1378 { &hf_netb_fragment_overlap_conflict,
1379 { "Conflicting data in fragment overlap", "netbios.fragment.overlap.conflict",
1380 FT_BOOLEAN, BASE_NONE,
1381 NULL, 0x0, "Overlapping fragments contained conflicting data", HFILL }},
1383 { &hf_netb_fragment_multiple_tails,
1384 { "Multiple tail fragments found", "netbios.fragment.multipletails",
1385 FT_BOOLEAN, BASE_NONE,
1386 NULL, 0x0, "Several tails were found when defragmenting the packet", HFILL }},
1388 { &hf_netb_fragment_too_long_fragment,
1389 { "Fragment too long", "netbios.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE,
1390 NULL, 0x0, "Fragment contained data past end of packet", HFILL }},
1392 { &hf_netb_fragment_error,
1393 {"Defragmentation error", "netbios.fragment.error", FT_FRAMENUM, BASE_NONE,
1394 NULL, 0x0, "Defragmentation error due to illegal fragments", HFILL }},
1396 { &hf_netb_fragment,
1397 { "NetBIOS Fragment", "netbios.fragment", FT_FRAMENUM, BASE_NONE,
1398 NULL, 0x0, "NetBIOS Fragment", HFILL }},
1400 { &hf_netb_fragments,
1401 { "NetBIOS Fragments", "netbios.fragments", FT_NONE, BASE_NONE,
1402 NULL, 0x0, "NetBIOS Fragments", HFILL }},
1404 module_t *netbios_module;
1406 proto_netbios = proto_register_protocol("NetBIOS", "NetBIOS", "netbios");
1407 proto_register_subtree_array(ett, array_length(ett));
1408 proto_register_field_array(proto_netbios, hf_netb, array_length(hf_netb));
1410 register_heur_dissector_list("netbios", &netbios_heur_subdissector_list);
1412 netbios_module = prefs_register_protocol(proto_netbios, NULL);
1413 prefs_register_bool_preference(netbios_module, "defragment",
1414 "Defragment all NetBIOS messages spanning multiple frames",
1415 "Whether the NetBIOS dissector should defragment all messages spanning multiple frames",
1416 &netbios_defragment);
1418 register_init_routine(netbios_init);
1422 proto_reg_handoff_netbios(void)
1424 dissector_handle_t netbios_handle;
1426 netbios_handle = create_dissector_handle(dissect_netbios,
1428 dissector_add("llc.dsap", SAP_NETBIOS, netbios_handle);
1429 data_handle = find_dissector("data");