2 * Routines for ISO/OSI network and transport protocol packet disassembly
3 * Main entrance point and common functions
5 * Laurent Deniel <laurent.deniel@free.fr>
6 * Ralf Schneider <Ralf.Schneider@t-online.de>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
22 #include "osi-utils.h"
24 #include "address_types.h"
26 static void print_nsap_net_buf( const guint8 *, int, gchar *, int);
27 static void print_area_buf ( const guint8 *, int, gchar *, int);
28 static void print_address_prefix_buf ( const guint8 *, int, gchar *, int);
31 * XXX - shouldn't there be a centralized routine for dissecting NSAPs?
32 * See also "dissect_atm_nsap()" in epan/dissectors/packet-arp.c and
33 * "dissect_nsap()" in epan/dissectors/packet-isup.c.
36 print_nsap_net( tvbuff_t *tvb, const gint offset, int length )
40 cur = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_NSAP_LEN * 3 + 50);
41 print_nsap_net_buf( tvb_get_ptr(tvb, offset, length), length, cur, MAX_NSAP_LEN * 3 + 50);
46 print_nsap_net_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
50 /* to do : NSAP / NET decoding */
52 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
53 g_strlcpy(buf, "<Invalid length of NSAP>", buf_len);
57 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
58 print_area_buf(ad, RFC1237_FULLAREA_LEN, cur, buf_len);
60 print_system_id_buf( ad + RFC1237_FULLAREA_LEN, RFC1237_SYSTEMID_LEN, cur, (int) (buf_len-(cur-buf)));
62 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x]",
63 ad[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
64 if ( length == RFC1237_NSAP_LEN + 1 ) {
65 g_snprintf(cur, (int) (buf_len-(cur-buf)), "-%02x", ad[ length -1 ] );
68 else { /* probably format as standard */
69 /* XXX - this is an NSAP, not an area address/address prefix */
70 print_area_buf( ad, length, buf, buf_len);
75 print_system_id(wmem_allocator_t* scope, const guint8 *ad, int length )
79 cur = (gchar *)wmem_alloc(scope, MAX_SYSTEMID_LEN * 3 + 5);
80 print_system_id_buf(ad, length, cur, MAX_SYSTEMID_LEN * 3 + 5);
85 tvb_print_system_id( tvbuff_t *tvb, const gint offset, int length )
87 return( print_system_id(wmem_packet_scope(), tvb_get_ptr(tvb, offset, length), length) );
91 print_system_id_buf( const guint8 *ad, int length, gchar *buf, int buf_len)
96 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
97 g_strlcpy(buf, "<Invalid length of SYSTEM ID>", buf_len);
102 if ( ( 6 == length ) || /* System-ID */
103 ( 7 == length ) || /* LAN-ID */
104 ( 8 == length )) { /* LSP-ID */
105 cur += g_snprintf(cur, buf_len, "%02x%02x.%02x%02x.%02x%02x", ad[0], ad[1],
106 ad[2], ad[3], ad[4], ad[5] );
107 if ( ( 7 == length ) ||
109 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), ".%02x", ad[6] );
112 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-%02x", ad[7] );
117 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
118 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
119 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
120 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
121 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x.", ad[tmp++] );
123 if ( 1 == tmp ) { /* Special case for Designated IS */
125 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), ".%02x", ad[tmp] );
128 for ( ; tmp < length; ) { /* print the rest without dot */
129 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
136 print_area(tvbuff_t *tvb, const gint offset, int length)
140 cur = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_AREA_LEN * 3 + 20);
141 print_area_buf(tvb_get_ptr(tvb, offset, length), length, cur, MAX_AREA_LEN * 3 + 20);
146 * Note: length is in units of half-octets.
149 print_address_prefix(tvbuff_t *tvb, const gint offset, int length)
153 cur = (gchar *)wmem_alloc(wmem_packet_scope(), MAX_AREA_LEN * 3 + 20);
154 print_address_prefix_buf(tvb_get_ptr(tvb, offset, (length+1)/2), length, cur, MAX_AREA_LEN * 3 + 20);
159 * Note: length is in units of octets.
162 print_area_buf(const guint8 *ad, int length, gchar *buf, int buf_len)
164 print_address_prefix_buf(ad, length*2, buf, buf_len);
168 * Note: length is in units of half-octets.
171 print_address_prefix_buf(const guint8 *ad, int length, gchar *buf, int buf_len)
176 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
178 if (length <= 0 || length > MAX_AREA_LEN*2) {
179 g_strlcpy(buf, "<Invalid length of AREA>", buf_len);
184 /* Check the AFI and length. */
185 if ( ( ( NSAP_IDI_ISO_DCC_BIN == *ad )
186 || ( NSAP_IDI_ISO_6523_ICD_BIN == *ad )
189 ( ( RFC1237_FULLAREA_LEN*2 == length )
190 || ( (RFC1237_FULLAREA_LEN + 1)*2 == length )
192 ) { /* AFI is good and length is long enough */
194 /* The AFI is either ISO DCC, binary or ISO 6523-ICD, binary,
195 * and the area length corresponds either to the area length
196 * for RFC 1237 (GOSIP) addresses or that length + 1.
198 * XXX - RFC 1237 doesn't mention ISO DCC, binary, as a valid
199 * AFI; is that from GOSIP Version 1? If it's ISO DCC, binary,
200 * the IDI is 3 digits, i.e. 1 1/2 octets.
202 /* there used to be a check for (length > RFC1237_FULLAREA_LEN + 1) here,
203 * in order to report an invalied length of AREA for DCC / ISO 6523 AFI,
204 * but that can *never* be the case because the if() test above explicitly
205 * tests for (length == RFC1237_FULLAREA_LEN) or (length == RFC1237_FULLAREA_LEN + 1)
208 /* Show the one-octet AFI, the two-octet IDI, the one-octet DFI, the
209 * 3-octet AA, and the 2 reserved octets.
211 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
212 ad[0], ad[1], ad[2], ad[3], ad[4],
213 ad[5], ad[6], ad[7], ad[8] );
214 /* Show the 2-octet RD and the 2-octet Area. */
215 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "[%02x:%02x|%02x:%02x]",
216 ad[9], ad[10], ad[11], ad[12] );
217 /* Show whatever the heck this is; it's not specified by RFC 1237,
218 * but we also handle 14-octet areas. Is it the "Designated IS"
219 * stuff mentioned below? (I didn't find anything in the IS-IS
222 if ( (RFC1237_FULLAREA_LEN + 1)*2 == length )
223 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-[%02x]", ad[13] );
226 /* This doesn't look like a full RFC 1237 IS-IS area, so all we know
227 * is that the first octet is an AFI. Print it separately from all
230 if ( length == RFC1237_AREA_LEN*2 ) {
231 /* XXX - RFC1237_AREA_LEN, which is 3 octets, doesn't seem to
232 * correspond to anything in RFC 1237. Where did it come from?
234 g_snprintf(buf, buf_len, "%02x.%02x%02x", ad[0], ad[1], ad[2] );
237 if ( length == 4*2 ) {
238 g_snprintf(buf, buf_len, "%02x%02x%02x%02x", ad[0], ad[1], ad[2], ad[3] );
241 while ( tmp < length / 8 ) { /* 32/8==4 > four Octets left to print */
242 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
243 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
244 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
245 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x.", ad[tmp++] );
247 if ( 2 == tmp ) { /* Special case for Designated IS */
249 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "-%02x", ad[tmp] );
252 for ( ; tmp < length / 2; ) { /* print the rest without dot or dash */
253 cur += g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%02x", ad[tmp++] );
255 /* Odd half-octet? */
257 /* Yes - print it (it's the upper half-octet) */
258 g_snprintf(cur, (gulong) (buf_len-(cur-buf)), "%x", (ad[tmp] & 0xF0)>>4 );
262 } /* print_address_prefix_buf */
264 /******************************************************************************
266 ******************************************************************************/
267 static int osi_address_type = -1;
269 static int osi_address_to_str(const address* addr, gchar *buf, int buf_len)
271 print_nsap_net_buf((const guint8 *)addr->data, addr->len, buf, buf_len);
272 return (int)strlen(buf)+1;
275 static int osi_address_str_len(const address* addr _U_)
277 return MAX_NSAP_LEN * 3 + 50;
280 int get_osi_address_type(void)
282 return osi_address_type;
285 void register_osi_address_type(void)
287 if (osi_address_type != -1)
290 osi_address_type = address_type_dissector_register("AT_OSI", "OSI Address", osi_address_to_str, osi_address_str_len, NULL, NULL, NULL, NULL, NULL);
300 * indent-tabs-mode: nil
303 * ex: set shiftwidth=2 tabstop=8 expandtab:
304 * :indentSize=2:tabSize=8:noTabs=true: