2 * Routines for sap packet dissection
5 * Heikki Vatiainen <hessu@cs.tut.fi>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * Copied from packet-tftp.c
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/packet.h>
34 #include <epan/expert.h>
36 #define UDP_PORT_SAP 9875
38 #define MCAST_SAP_VERSION_MASK 0xE0 /* 3 bits for SAP version*/
39 #define MCAST_SAP_VERSION_SHIFT 5 /* Right shift 5 bits to get the version */
40 #define MCAST_SAP_VER0 0 /* Version 0 */
41 #define MCAST_SAP_VER1PLUS 1 /* Version 1 or later */
42 static const value_string mcast_sap_ver
[] = {
43 { MCAST_SAP_VER0
, "SAPv0"},
44 { MCAST_SAP_VER1PLUS
, "SAPv1 or later"},
48 static const true_false_string mcast_sap_address_type
= {"IPv6", "IPv4"};
49 static const true_false_string mcast_sap_message_type
= { "Deletion", "Announcement"};
50 static const true_false_string mcast_sap_crypt_type
= { "Payload encrypted", "Payload not encrypted "};
51 static const true_false_string mcast_sap_comp_type
= { "Payload compressed", "Payload not compressed"};
53 static const value_string mcast_sap_auth_ver
[] = {
54 { 1, "SAP authentication header v1"},
58 static const true_false_string mcast_sap_auth_pad
= {
59 "Authentication subheader padded to 32 bits",
60 "No padding required for the authentication subheader"
63 #define MCAST_SAP_AUTH_TYPE_MASK 0x0F /* 4 bits for the type of the authentication header */
64 #define MCAST_SAP_AUTH_TYPE_PGP 0
65 #define MCAST_SAP_AUTH_TYPE_CMS 1
66 static const value_string mcast_sap_auth_type
[] = {
67 { MCAST_SAP_AUTH_TYPE_PGP
, "PGP"},
68 { MCAST_SAP_AUTH_TYPE_CMS
, "CMS"},
72 #define MCAST_SAP_BIT_A 0x10 /* Address type: 0 IPv4, 1 IPv6 */
73 #define MCAST_SAP_BIT_R 0x08 /* Reserved: Must be 0 */
74 #define MCAST_SAP_BIT_T 0x04 /* Message Type: 0 announcement, 1 deletion */
75 #define MCAST_SAP_BIT_E 0x02 /* Encryption Bit: 1 payload encrypted */
76 #define MCAST_SAP_BIT_C 0x01 /* Compressed Bit: 1 payload zlib compressed */
78 #define MCAST_SAP_AUTH_BIT_P 0x10 /* Padding required for the authentication header */
81 static int proto_sap
= -1;
82 static int hf_sap_flags
= -1;
83 static int hf_sap_flags_v
= -1;
84 static int hf_sap_flags_a
= -1;
85 static int hf_sap_flags_r
= -1;
86 static int hf_sap_flags_t
= -1;
87 static int hf_sap_flags_e
= -1;
88 static int hf_sap_flags_c
= -1;
89 static int hf_auth_data
= -1;
90 static int hf_auth_flags
= -1;
91 static int hf_auth_flags_v
= -1;
92 static int hf_auth_flags_p
= -1;
93 static int hf_auth_flags_t
= -1;
94 /* Generated from convert_proto_tree_add_text.pl */
95 static int hf_sap_auth_len
= -1;
96 static int hf_sap_originating_source_ipv4
= -1;
97 static int hf_sap_auth_data_padding
= -1;
98 static int hf_sap_auth_subheader
= -1;
99 static int hf_sap_originating_source_ipv6
= -1;
100 static int hf_sap_message_identifier_hash
= -1;
101 static int hf_sap_auth_data_padding_len
= -1;
102 static int hf_sap_payload_type
= -1;
104 static gint ett_sap
= -1;
105 static gint ett_sap_flags
= -1;
106 static gint ett_sap_auth
= -1;
107 static gint ett_sap_authf
= -1;
109 static expert_field ei_sap_compressed_and_encrypted
= EI_INIT
;
110 static expert_field ei_sap_encrypted
= EI_INIT
;
111 static expert_field ei_sap_compressed
= EI_INIT
;
112 /* Generated from convert_proto_tree_add_text.pl */
113 static expert_field ei_sap_bogus_authentication_or_pad_length
= EI_INIT
;
115 static dissector_handle_t sdp_handle
;
118 dissect_sap(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
121 int sap_version
, is_ipv6
, is_del
, is_enc
, is_comp
, addr_len
;
127 proto_item
*si
, *sif
;
128 proto_tree
*sap_tree
= NULL
, *sap_flags_tree
;
130 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "SAP");
131 col_clear(pinfo
->cinfo
, COL_INFO
);
133 vers_flags
= tvb_get_guint8(tvb
, offset
);
134 is_ipv6
= vers_flags
&MCAST_SAP_BIT_A
;
135 is_del
= vers_flags
&MCAST_SAP_BIT_T
;
136 is_enc
= vers_flags
&MCAST_SAP_BIT_E
;
137 is_comp
= vers_flags
&MCAST_SAP_BIT_C
;
139 sap_version
= (vers_flags
&MCAST_SAP_VERSION_MASK
)>>MCAST_SAP_VERSION_SHIFT
;
140 addr_len
= (is_ipv6
) ? (int)sizeof(struct e_in6_addr
) : 4;
142 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s (v%u)",
143 (is_del
) ? "Deletion" : "Announcement", sap_version
);
146 si
= proto_tree_add_item(tree
, proto_sap
, tvb
, offset
, -1, ENC_NA
);
147 sap_tree
= proto_item_add_subtree(si
, ett_sap
);
149 sif
= proto_tree_add_item(sap_tree
, hf_sap_flags
, tvb
, offset
, 1, ENC_NA
);
150 sap_flags_tree
= proto_item_add_subtree(sif
, ett_sap_flags
);
151 proto_tree_add_item(sap_flags_tree
, hf_sap_flags_v
, tvb
, offset
, 1, ENC_NA
);
152 proto_tree_add_item(sap_flags_tree
, hf_sap_flags_a
, tvb
, offset
, 1, ENC_NA
);
153 proto_tree_add_item(sap_flags_tree
, hf_sap_flags_r
, tvb
, offset
, 1, ENC_NA
);
154 proto_tree_add_item(sap_flags_tree
, hf_sap_flags_t
, tvb
, offset
, 1, ENC_NA
);
155 proto_tree_add_item(sap_flags_tree
, hf_sap_flags_e
, tvb
, offset
, 1, ENC_NA
);
156 proto_tree_add_item(sap_flags_tree
, hf_sap_flags_c
, tvb
, offset
, 1, ENC_NA
);
161 auth_len
= tvb_get_guint8(tvb
, offset
);
162 proto_tree_add_item(sap_tree
, hf_sap_auth_len
, tvb
, offset
, 1, ENC_NA
);
165 proto_tree_add_item(sap_tree
, hf_sap_message_identifier_hash
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
169 proto_tree_add_item(sap_tree
, hf_sap_originating_source_ipv4
, tvb
, offset
, addr_len
, ENC_BIG_ENDIAN
);
171 proto_tree_add_item(sap_tree
, hf_sap_originating_source_ipv6
, tvb
, offset
, addr_len
, ENC_BIG_ENDIAN
);
174 /* Authentication data lives in its own subtree */
176 guint32 auth_data_len
;
177 proto_item
*sdi
, *sai
;
178 proto_tree
*sa_tree
, *saf_tree
;
182 auth_data_len
= (guint32
)(auth_len
* sizeof(guint32
));
184 sdi
= proto_tree_add_item(sap_tree
, hf_auth_data
, tvb
, offset
, auth_data_len
, ENC_NA
);
185 sa_tree
= proto_item_add_subtree(sdi
, ett_sap_auth
);
187 auth_flags
= tvb_get_guint8(tvb
, offset
);
188 sai
= proto_tree_add_item(sa_tree
, hf_auth_flags
, tvb
, offset
, 1, ENC_NA
);
189 saf_tree
= proto_item_add_subtree(sai
, ett_sap_authf
);
190 proto_tree_add_item(saf_tree
, hf_auth_flags_v
, tvb
, offset
, 1, ENC_NA
);
191 proto_tree_add_item(saf_tree
, hf_auth_flags_p
, tvb
, offset
, 1, ENC_NA
);
192 proto_tree_add_item(saf_tree
, hf_auth_flags_t
, tvb
, offset
, 1, ENC_NA
);
194 has_pad
= auth_flags
&MCAST_SAP_AUTH_BIT_P
;
196 pad_len
= tvb_get_guint8(tvb
, offset
+auth_data_len
-1);
199 if ((int) auth_data_len
- pad_len
- 1 < 0) {
200 expert_add_info_format(pinfo
, sai
, &ei_sap_bogus_authentication_or_pad_length
,
201 "Bogus authentication length (%d) or pad length (%d)", auth_len
, pad_len
);
206 proto_tree_add_item(sa_tree
, hf_sap_auth_subheader
, tvb
, offset
+1, auth_data_len
-pad_len
-1, ENC_NA
);
208 proto_tree_add_item(sa_tree
, hf_sap_auth_data_padding_len
, tvb
, offset
+auth_data_len
-1, 1, ENC_NA
);
209 proto_tree_add_item(sa_tree
, hf_sap_auth_data_padding
, tvb
, offset
+auth_data_len
-pad_len
, pad_len
, ENC_NA
);
212 offset
+= auth_data_len
;
215 if (is_enc
|| is_comp
) {
216 expert_field
*mangle
;
217 if (is_enc
&& is_comp
)
218 mangle
= &ei_sap_compressed_and_encrypted
;
220 mangle
= &ei_sap_encrypted
;
222 mangle
= &ei_sap_compressed
;
224 proto_tree_add_expert(sap_tree
, pinfo
, mangle
, tvb
, offset
, -1);
229 /* Do we have the optional payload type aka. MIME content specifier */
230 if (tvb_strneql(tvb
, offset
, "v=", strlen("v="))) {
236 remaining_len
= tvb_length_remaining(tvb
, offset
);
237 if (remaining_len
== 0) {
239 * "tvb_strneql()" failed because there was no
240 * data left in the packet.
242 * Set the remaining length to 1, so that
243 * we throw the appropriate exception in
244 * "tvb_get_ptr()", rather than displaying
250 pt_string_len
= tvb_strnlen(tvb
, offset
, remaining_len
);
251 if (pt_string_len
== -1) {
253 * We didn't find a terminating '\0'; run to the
256 pt_string_len
= remaining_len
;
257 pt_len
= pt_string_len
;
260 * Include the '\0' in the total item length.
262 pt_len
= pt_string_len
+ 1;
265 pt_str
= tvb_get_string(wmem_packet_scope(), tvb
, offset
, pt_string_len
);
266 proto_tree_add_string_format_value(sap_tree
, hf_sap_payload_type
, tvb
, offset
, pt_len
,
267 pt_str
, "%.*s", pt_string_len
, pt_str
);
273 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
274 call_dissector(sdp_handle
, next_tvb
, pinfo
, tree
);
277 void proto_register_sap(void)
280 static hf_register_info hf
[] = {
282 { "Flags", "sap.flags",
283 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
284 "Bits in the beginning of the SAP header", HFILL
}},
287 { "Version Number", "sap.flags.v",
288 FT_UINT8
, BASE_DEC
, VALS(mcast_sap_ver
), MCAST_SAP_VERSION_MASK
,
289 "3 bit version field in the SAP header", HFILL
}},
292 { "Address Type", "sap.flags.a",
293 FT_BOOLEAN
, 8, TFS(&mcast_sap_address_type
), MCAST_SAP_BIT_A
,
294 "Originating source address type", HFILL
}},
297 { "Reserved", "sap.flags.r",
298 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), MCAST_SAP_BIT_R
,
302 { "Message Type", "sap.flags.t",
303 FT_BOOLEAN
, 8, TFS(&mcast_sap_message_type
), MCAST_SAP_BIT_T
,
304 "Announcement type", HFILL
}},
307 { "Encryption Bit", "sap.flags.e",
308 FT_BOOLEAN
, 8, TFS(&mcast_sap_crypt_type
), MCAST_SAP_BIT_E
,
312 { "Compression Bit", "sap.flags.c",
313 FT_BOOLEAN
, 8, TFS(&mcast_sap_comp_type
), MCAST_SAP_BIT_C
,
317 { "Authentication data", "sap.auth",
318 FT_NONE
, BASE_NONE
, NULL
, 0x0,
322 { "Authentication data flags", "sap.auth.flags",
323 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
327 { "Version Number", "sap.auth.flags.v",
328 FT_UINT8
, BASE_DEC
, VALS(mcast_sap_auth_ver
), MCAST_SAP_VERSION_MASK
,
332 { "Padding Bit", "sap.auth.flags.p",
333 FT_BOOLEAN
, 8, TFS(&mcast_sap_auth_pad
), MCAST_SAP_AUTH_BIT_P
,
337 { "Authentication Type", "sap.auth.flags.t",
338 FT_UINT8
, BASE_DEC
, VALS(mcast_sap_auth_type
), MCAST_SAP_AUTH_TYPE_MASK
,
341 /* Generated from convert_proto_tree_add_text.pl */
342 { &hf_sap_auth_len
, { "Authentication Length", "sap.auth.len", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
343 { &hf_sap_message_identifier_hash
, { "Message Identifier Hash", "sap.message_identifier_hash", FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
344 { &hf_sap_originating_source_ipv4
, { "Originating Source", "sap.originating_source", FT_IPv4
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
345 { &hf_sap_originating_source_ipv6
, { "Originating Source", "sap.originating_source", FT_IPv6
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
346 { &hf_sap_auth_subheader
, { "Authentication subheader", "sap.auth.subheader", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
347 { &hf_sap_auth_data_padding
, { "Authentication data padding", "sap.auth.data_padding", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
348 { &hf_sap_auth_data_padding_len
, { "Authentication data pad count (bytes)", "sap.auth.data_padding.len", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
349 { &hf_sap_payload_type
, { "Payload type", "sap.payload_type", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
352 static gint
*ett
[] = {
359 static ei_register_info ei
[] = {
360 { &ei_sap_compressed_and_encrypted
, { "sap.compressed_and_encrypted", PI_UNDECODED
, PI_WARN
, "The rest of the packet is compressed and encrypted", EXPFILL
}},
361 { &ei_sap_encrypted
, { "sap.encrypted", PI_UNDECODED
, PI_WARN
, "The rest of the packet is encrypted", EXPFILL
}},
362 { &ei_sap_compressed
, { "sap.compressed", PI_UNDECODED
, PI_WARN
, "The rest of the packet is compressed", EXPFILL
}},
364 /* Generated from convert_proto_tree_add_text.pl */
365 { &ei_sap_bogus_authentication_or_pad_length
, { "sap.bogus_authentication_or_pad_length", PI_PROTOCOL
, PI_WARN
, "Bogus authentication length", EXPFILL
}},
368 expert_module_t
* expert_sap
;
370 proto_sap
= proto_register_protocol("Session Announcement Protocol", "SAP", "sap");
372 proto_register_field_array(proto_sap
, hf
, array_length(hf
));
373 proto_register_subtree_array(ett
, array_length(ett
));
374 expert_sap
= expert_register_protocol(proto_sap
);
375 expert_register_field_array(expert_sap
, ei
, array_length(ei
));
379 proto_reg_handoff_sap(void)
381 dissector_handle_t sap_handle
;
383 sap_handle
= create_dissector_handle(dissect_sap
, proto_sap
);
384 dissector_add_uint("udp.port", UDP_PORT_SAP
, sap_handle
);
387 * Get a handle for the SDP dissector.
389 sdp_handle
= find_dissector("sdp");