2 * Routines for sap packet dissection
3 * <draft-ietf-mmusic-sap-v2-03.txt>
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-sap.c,v 1.4 2000/01/07 22:05:36 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
45 #include "packet-ipv6.h"
48 #define MCAST_SAP_VERSION_MASK 0xE0 /* 3 bits for SAP version*/
49 #define MCAST_SAP_VERSION_SHIFT 5 /* Right shift 5 bits to get the version */
50 #define MCAST_SAP_VER0 0 /* Version 0 */
51 #define MCAST_SAP_VER1PLUS 1 /* Version 1 or later */
52 static const value_string mcast_sap_ver[] = {
53 { MCAST_SAP_VER0, "SAPv0"},
54 { MCAST_SAP_VER1PLUS, "SAPv1 or later"},
57 static const true_false_string mcast_sap_address_type = {
62 static const true_false_string flags_set_truth = {
67 static const true_false_string mcast_sap_message_type = {
72 static const true_false_string mcast_sap_crypt_type = {
74 "Payload not encrypted "
77 static const true_false_string mcast_sap_comp_type = {
79 "Payload not compressed"
82 static const value_string mcast_sap_auth_ver[] = {
83 { 1, "SAP authentication header v1"},
86 static const true_false_string mcast_sap_auth_pad = {
87 "Authentication subheader padded to 32 bits",
88 "No padding required for the authentication subheader"
91 #define MCAST_SAP_AUTH_TYPE_MASK 0x0F /* 4 bits for the type of the authentication header */
92 #define MCAST_SAP_AUTH_TYPE_PGP 0
93 #define MCAST_SAP_AUTH_TYPE_CMS 1
94 static const value_string mcast_sap_auth_type[] = {
95 { MCAST_SAP_AUTH_TYPE_PGP, "PGP"},
96 { MCAST_SAP_AUTH_TYPE_CMS, "CMS"},
99 #define MCAST_SAP_BIT_A 0x10 /* Address type: 0 IPv4, 1 IPv6 */
100 #define MCAST_SAP_BIT_R 0x08 /* Reserved: Must be 0 */
101 #define MCAST_SAP_BIT_T 0x04 /* Message Type: 0 announcement, 1 deletion */
102 #define MCAST_SAP_BIT_E 0x02 /* Encryption Bit: 1 payload encrypted */
103 #define MCAST_SAP_BIT_C 0x01 /* Compressed Bit: 1 payload zlib compressed */
105 #define MCAST_SAP_AUTH_BIT_P 0x10 /* Padding required for the authentication header */
108 static int proto_sap = -1;
109 static int hf_sap_flags = -1;
110 static int hf_sap_flags_v = -1;
111 static int hf_sap_flags_a = -1;
112 static int hf_sap_flags_r = -1;
113 static int hf_sap_flags_t = -1;
114 static int hf_sap_flags_e = -1;
115 static int hf_sap_flags_c = -1;
116 static int hf_auth_data = -1;
117 static int hf_auth_flags = -1;
118 static int hf_auth_flags_v = -1;
119 static int hf_auth_flags_p = -1;
120 static int hf_auth_flags_t = -1;
122 static gint ett_sap = -1;
123 static gint ett_sap_flags = -1;
124 static gint ett_sap_auth = -1;
125 static gint ett_sap_authf = -1;
127 void dissect_sap(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
129 int sap_version, is_ipv6, is_del, is_enc, is_comp, addr_len;
134 proto_item *si, *sif;
135 proto_tree *sap_tree, *sap_flags_tree;
137 is_ipv6 = pd[offset]&MCAST_SAP_BIT_A;
138 is_del = pd[offset]&MCAST_SAP_BIT_T;
139 is_enc = pd[offset]&MCAST_SAP_BIT_E;
140 is_comp = pd[offset]&MCAST_SAP_BIT_C;
142 sap_version = (pd[offset]&MCAST_SAP_VERSION_MASK)>>MCAST_SAP_VERSION_SHIFT;
143 addr_len = (is_ipv6) ? sizeof(struct e_in6_addr) : 4;
145 if (check_col(fd, COL_PROTOCOL))
146 col_add_str(fd, COL_PROTOCOL, "SAP");
148 if (check_col(fd, COL_INFO)) {
149 col_add_fstr(fd, COL_INFO, "%s (v%u)",
150 (is_del) ? "Deletion" : "Announcement", sap_version);
154 si = proto_tree_add_item(tree, proto_sap, offset, END_OF_FRAME, NULL);
155 sap_tree = proto_item_add_subtree(si, ett_sap);
157 sif = proto_tree_add_item(sap_tree, hf_sap_flags, offset, 1, pd[offset]);
158 sap_flags_tree = proto_item_add_subtree(sif, ett_sap_flags);
159 proto_tree_add_item(sap_flags_tree, hf_sap_flags_v, offset, 1, pd[offset]);
160 proto_tree_add_item(sap_flags_tree, hf_sap_flags_a, offset, 1, pd[offset]);
161 proto_tree_add_item(sap_flags_tree, hf_sap_flags_r, offset, 1, pd[offset]);
162 proto_tree_add_item(sap_flags_tree, hf_sap_flags_t, offset, 1, pd[offset]);
163 proto_tree_add_item(sap_flags_tree, hf_sap_flags_e, offset, 1, pd[offset]);
164 proto_tree_add_item(sap_flags_tree, hf_sap_flags_c, offset, 1, pd[offset]);
167 proto_tree_add_text(sap_tree, offset, 1, "Authentication Length: %u", pd[offset]);
168 auth_len = pd[offset];
171 tmp1 = pntohs(pd+offset);
172 proto_tree_add_text(sap_tree, offset, 2, "Message Identifier Hash: 0x%x", tmp1);
175 proto_tree_add_text(sap_tree, offset, addr_len, "Originating Source: %s",
176 (is_ipv6) ? ip6_to_str((struct e_in6_addr*)(pd+offset)) : ip_to_str(pd+offset));
179 /* Authentication data lives in its own subtree */
181 guint32 auth_data_len;
182 proto_item *sdi, *sai;
183 proto_tree *sa_tree, *saf_tree;
187 auth_data_len = auth_len * sizeof(guint32);
189 sdi = proto_tree_add_item(sap_tree, hf_auth_data, offset, auth_data_len, pd[offset]);
190 sa_tree = proto_item_add_subtree(sdi, ett_sap_auth);
192 sai = proto_tree_add_item(sa_tree, hf_auth_flags, offset, 1, pd[offset]);
193 saf_tree = proto_item_add_subtree(sai, ett_sap_authf);
194 proto_tree_add_item(saf_tree, hf_auth_flags_v, offset, 1, pd[offset]);
195 proto_tree_add_item(saf_tree, hf_auth_flags_p, offset, 1, pd[offset]);
196 proto_tree_add_item(saf_tree, hf_auth_flags_t, offset, 1, pd[offset]);
198 has_pad = pd[offset]&MCAST_SAP_AUTH_BIT_P;
199 if (has_pad) pad_len = *(pd+offset+auth_data_len-1);
201 proto_tree_add_text(sa_tree, offset+1, auth_data_len-pad_len-1,
202 "Authentication subheader: (%u byte%s)",
203 auth_data_len-1, plurality(auth_data_len-1, "", "s"));
205 proto_tree_add_text(sa_tree, offset+auth_data_len-pad_len, pad_len,
206 "Authentication data padding: (%u byte%s)",
207 pad_len, plurality(pad_len, "", "s"));
208 proto_tree_add_text(sa_tree, offset+auth_data_len-1, 1,
209 "Authentication data pad count: %u byte%s",
210 pad_len, plurality(pad_len, "", "s"));
213 offset += auth_data_len;
216 if (is_enc) { /* Encrypted payload implies valid timeout in the SAP header */
217 tmp2 = pntohl(pd+offset);
218 proto_tree_add_text(sap_tree, offset, 4, "Timeout: %u", tmp2);
219 offset += sizeof(guint32);
222 if (is_enc || is_comp) {
223 proto_tree_add_text(sap_tree, offset, END_OF_FRAME,
224 "Rest of the packet is encrypted or compressed");
228 /* Do we have the optional payload type aka. MIME content specifier */
229 if (strncasecmp(pd+offset, "v=", strlen("v="))) {
230 guint32 pt_len = strlen(pd+offset); /* BUG: should use strnlen */
231 proto_tree_add_text(sap_tree, offset, pt_len, "Payload type: %s", pd+offset);
233 if (pd[offset] == '\0')
234 offset++; /* Skip possible '\0' */
238 dissect_sdp(pd, offset, fd, tree);
244 void proto_register_sap(void)
247 static hf_register_info hf[] = {
249 { "Flags", "sap.flags",
250 FT_UINT8, BASE_HEX, NULL, 0x0,
251 "Bits in the beginning of the SAP header" }},
254 { "Version Number", "sap.flags.v",
255 FT_UINT8, BASE_DEC, VALS(mcast_sap_ver), MCAST_SAP_VERSION_MASK,
256 "3 bit version field in the SAP header" }},
259 { "Address Type", "sap.flags.a",
260 FT_BOOLEAN, 8, TFS(&mcast_sap_address_type), MCAST_SAP_BIT_A,
261 "Originating source address type" }},
264 { "Reserved", "sap.flags.r",
265 FT_BOOLEAN, 8, TFS(&flags_set_truth), MCAST_SAP_BIT_R,
269 { "Message Type", "sap.flags.t",
270 FT_BOOLEAN, 8, TFS(&mcast_sap_message_type), MCAST_SAP_BIT_T,
271 "Announcement type" }},
274 { "Encryption Bit", "sap.flags.e",
275 FT_BOOLEAN, 8, TFS(&mcast_sap_crypt_type), MCAST_SAP_BIT_E,
279 { "Compression Bit", "sap.flags.c",
280 FT_BOOLEAN, 8, TFS(&mcast_sap_comp_type), MCAST_SAP_BIT_C,
284 { "Authentication data", "sap.auth",
285 FT_NONE, BASE_NONE, NULL, 0x0,
289 { "Authentication data flags", "sap.auth.flags",
290 FT_UINT8, BASE_HEX, NULL, 0x0,
294 { "Version Number", "sap.auth.flags.v",
295 FT_UINT8, BASE_DEC, VALS(&mcast_sap_auth_ver), MCAST_SAP_VERSION_MASK,
299 { "Padding Bit", "sap.auth.flags.p",
300 FT_BOOLEAN, 8, TFS(&mcast_sap_auth_pad), MCAST_SAP_AUTH_BIT_P,
304 { "Authentication Type", "sap.auth.flags.t",
305 FT_UINT8, BASE_DEC, VALS(&mcast_sap_auth_type), MCAST_SAP_AUTH_TYPE_MASK,
308 static gint *ett[] = {
315 proto_sap = proto_register_protocol("Session Announcement Protocol", "sap");
316 proto_register_field_array(proto_sap, hf, array_length(hf));
317 proto_register_subtree_array(ett, array_length(ett));