MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-opsi.c
blobdfe82b6a3223d8d9e5054ea0d5392c8999e2526d
1 /* packet-opsi.c
2 * Routines for OPSI protocol dissection
3 * Copyright 2004, Laurent Rabret (France Telecom R&D) <laurent.rabret@i.hate.spams.org>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
32 #include <epan/expert.h>
34 #include "packet-tcp.h"
36 /* TCP destination port dedicated to the OPSI protocol */
37 #define TCP_PORT_OPSI 4002
39 /* Information position in OPSI header */
40 #define MAJOR_VERSION_OFFSET 0
41 #define MINOR_VERSION_OFFSET 1
42 #define CODE_OFFSET 2
43 #define HOOK_ID_OFFSET 3
44 #define PACKET_LENGTH_OFFSET 4
45 #define SESSION_OFFSET 6
47 #define HEADER_LENGTH 8
50 /* Valid OPSI code values */
51 #define DISCOVER_REQUEST 1
52 #define DISCOVER_RESPONSE 2
53 #define SERVICE_REQUEST 3
54 #define SERVICE_ACCEPT 4
55 #define SERVICE_REJECT 5
56 #define TERMINATE_REQUEST 6
58 /* Internal structure to dissect attributes */
59 typedef struct {
60 guint16 attribute_type; /* attribute code */
61 const char *tree_text; /* text for fold out */
62 gint *tree_id; /* id for add_item */
63 int* hf_type_attribute; /* id for seach option */
64 void (*dissect)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item,
65 int* hfValue, int offset, int length);
66 } opsi_attribute_handle_t;
69 /* Attributes codes */
70 #define USER_NAME_ATTRIBUTE 1
71 #define USER_PASSWD_ATTRIBUTE 2
72 #define CHAP_PASSWD_ATTRIBUTE 3
73 #define NAS_IP_ADDRESS_ATTRIBUTE 4
74 #define NAS_PORT_ATTRIBUTE 5
75 #define SERVICE_TYPE_ATTRIBUTE 6
76 #define FRAMED_PROTOCOL_ATTRIBUTE 7
77 #define FRAMED_ADDRESS_ATTRIBUTE 8
78 #define FRAMED_NETMASK_ATTRIBUTE 9
79 #define FRAMED_ROUTING_ATTRIBUTE 10
80 #define FRAMED_FILTER_ATTRIBUTE 11
81 #define FRAMED_MTU_ATTRIBUTE 12
82 #define FRAMED_COMPRESSION_ATTRIBUTE 13
83 #define CALLED_STATION_ID_ATTRIBUTE 30
84 #define CALLING_STATION_ID_ATTRIBUTE 31
85 #define NAS_IDENTIFIER 32
86 #define ACCOUNTING_40_ATTRIBUTE 40
87 #define ACCOUNTING_41_ATTRIBUTE 41
88 #define ACCOUNTING_42_ATTRIBUTE 42
89 #define ACCOUNTING_43_ATTRIBUTE 43
90 #define ACCOUNTING_SESSION_ID_ATTRIBUTE 44
91 #define ACCOUNTING_45_ATTRIBUTE 45
92 #define ACCOUNTING_46_ATTRIBUTE 46
93 #define ACCOUNTING_47_ATTRIBUTE 47
94 #define ACCOUNTING_48_ATTRIBUTE 48
95 #define ACCOUNTING_49_ATTRIBUTE 49
96 #define ACCOUNTING_50_ATTRIBUTE 50
97 #define ACCOUNTING_51_ATTRIBUTE 51
98 #define ACCOUNTING_52_ATTRIBUTE 52
99 #define ACCOUNTING_53_ATTRIBUTE 53
100 #define ACCOUNTING_54_ATTRIBUTE 54
101 #define ACCOUNTING_55_ATTRIBUTE 55
102 #define ACCOUNTING_56_ATTRIBUTE 56
103 #define ACCOUNTING_57_ATTRIBUTE 57
104 #define ACCOUNTING_58_ATTRIBUTE 58
105 #define ACCOUNTING_59_ATTRIBUTE 59
106 #define CHAP_CHALLENGE_ATTRIBUTE 60
107 #define NAS_PORT_TYPE_ATTRIBUTE 61
108 #define DESIGNATION_NUMBER_ATTRIBUTE 77
109 #define NAS_PORT_ID_ATTRIBUTE 87
111 #define SMC_AAAID_ATTRIBUTE 651
112 #define SMC_VPNID_ATTRIBUTE 652
113 #define SMC_VPNNAME_ATTRIBUTE 653
114 #define SMC_RANID_ATTRIBUTE 654
115 #define SMC_RANIP_ATTRIBUTE 655
116 #define SMC_RANNAME_ATTRIBUTE 656
117 #define SMC_POPID_ATTRIBUTE 657
118 #define SMC_POPNAME_ATTRIBUTE 658
119 #define SMC_SMCID_ATTRIBUTE 659
120 #define SMC_RECEIVE_TIME_ATTRIBUTE 660
121 #define SMC_STAT_TIME_ATTRIBUTE 661
123 #define OPSI_FLAGS_ATTRIBUTE 674
124 #define OPSI_APPLICATION_NAME_ATTRIBUTE 675
127 * Published API functions. NOTE, "local" API functions
128 * only valid from the packet-opsi file.
130 static void decode_string_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length);
131 static void decode_ipv4_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length);
132 static void decode_longint_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length);
133 static void decode_value_string_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length);
134 static void decode_time_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length);
135 /******* *******/
137 /* Initialize the protocol and registered fields */
138 static int proto_opsi = -1;
139 static int hf_opsi_major_version = -1;
140 static int hf_opsi_minor_version = -1;
141 static int hf_opsi_opcode = -1;
142 static int hf_opsi_hook_id = -1;
143 static int hf_opsi_length = -1;
144 static int hf_opsi_session_id = -1;
145 static int hf_user_name_att = -1;
146 static int hf_password_att = -1;
147 static int hf_chap_password_att = -1;
148 static int hf_nas_ip_add_att = -1;
149 static int hf_nas_port_att = -1;
150 static int hf_service_type_att = -1;
151 static int hf_framed_protocol_att = -1;
152 static int hf_framed_address_att = -1;
153 static int hf_framed_netmask_att = -1;
154 static int hf_framed_routing_att = -1;
155 static int hf_framed_filter_att = -1;
156 static int hf_framed_mtu_att = -1;
157 static int hf_framed_compression_att = -1;
158 static int hf_called_station_att = -1;
159 static int hf_calling_station_att = -1;
160 static int hf_nas_identifier_att = -1;
161 static int hf_accounting_att = -1;
162 static int hf_acct_session_id_att = -1;
163 static int hf_chap_challenge_att = -1;
164 static int hf_nas_port_type_att = -1;
165 static int hf_designation_num_att = -1;
166 static int hf_nas_port_id_att = -1;
167 static int hf_smc_aaa_id_att = -1;
168 static int hf_smc_vpn_id_att = -1;
169 static int hf_smc_vpn_name_att = -1;
170 static int hf_smc_ran_id_att = -1;
171 static int hf_smc_ran_ip_att = -1;
172 static int hf_smc_ran_name_att = -1;
173 static int hf_smc_pop_id_att = -1;
174 static int hf_smc_pop_name_att = -1;
175 static int hf_smc_id_att = -1;
176 static int hf_smc_receive_time_att = -1;
177 static int hf_smc_stat_time_att = -1;
178 static int hf_opsi_flags_att = -1;
179 static int hf_opsi_application_name_att = -1;
180 static int hf_opsi_attribute_length = -1;
182 /* Initialize the subtree pointers */
183 static gint ett_opsi = -1;
184 static gint ett_opsi_user_name = -1;
185 static gint ett_opsi_user_password = -1;
186 static gint ett_opsi_chap_password = -1;
187 static gint ett_opsi_nas_ip_address = -1;
188 static gint ett_opsi_nas_port = -1;
189 static gint ett_opsi_service_type = -1;
190 static gint ett_opsi_framed_protocol = -1;
191 static gint ett_opsi_framed_address = -1;
192 static gint ett_opsi_framed_netmask = -1;
193 static gint ett_opsi_framed_routing = -1;
194 static gint ett_opsi_framed_filter = -1;
195 static gint ett_opsi_framed_mtu = -1;
196 static gint ett_opsi_framed_compression = -1;
197 static gint ett_opsi_called_station_id = -1;
198 static gint ett_opsi_calling_station_id = -1;
199 static gint ett_opsi_nas_identifier = -1;
200 static gint ett_opsi_accounting = -1;
201 static gint ett_opsi_acct_session_id = -1;
202 static gint ett_opsi_chap_challenge = -1;
203 static gint ett_opsi_nas_port_type = -1;
204 static gint ett_opsi_designation_number = -1;
205 static gint ett_opsi_nas_port_id = -1;
206 static gint ett_opsi_smc_aaa_id = -1;
207 static gint ett_opsi_smc_vpn_id = -1;
208 static gint ett_opsi_smc_vpn_name = -1;
209 static gint ett_opsi_smc_ran_id = -1;
210 static gint ett_opsi_smc_ran_ip = -1;
211 static gint ett_opsi_smc_ran_name = -1;
212 static gint ett_opsi_smc_pop_id = -1;
213 static gint ett_opsi_smc_pop_name = -1;
214 static gint ett_opsi_smc_id = -1;
215 static gint ett_opsi_smc_receive_time = -1;
216 static gint ett_opsi_smc_stat_time = -1;
217 static gint ett_opsi_flags = -1;
218 static gint ett_opsi_application_name = -1;
220 static expert_field ei_opsi_unknown_attribute = EI_INIT;
221 static expert_field ei_opsi_short_attribute = EI_INIT;
222 static expert_field ei_opsi_short_frame = EI_INIT;
224 /* Code mapping */
225 static const value_string opsi_opcode[] = {
226 { DISCOVER_REQUEST, "Discover Request" },
227 { DISCOVER_RESPONSE, "Discover Response" },
228 { SERVICE_REQUEST, "Service Request" },
229 { SERVICE_ACCEPT, "Service Accept" },
230 { SERVICE_REJECT, "Service Reject" },
231 { TERMINATE_REQUEST, "Terminate Request" },
232 { 0, NULL }
235 static const value_string opsi_service_type_code[] = {
236 { 1, "Login" },
237 { 2, "Framed" },
238 { 3, "Callback Login" },
239 { 4, "Callback Framed" },
240 { 5, "Outbound" },
241 { 6, "Administrative" },
242 { 7, "NAS Prompt" },
243 { 8, "Authenticate Only" },
244 { 9, "Callback NAS Prompt" },
245 { 0, NULL }
248 static const value_string opsi_framed_protocol_code[] = {
249 { 1, "PPP" },
250 { 2, "SLIP" },
251 { 3, "AppleTalk Remote Access Protocol (ARAP)" },
252 { 4, "Gandalf proprietary SingleLink/MultiLink protocol" },
253 { 5, "Xylogics proprietary IPX/SLIP" },
254 { 255, "Ascend ARA" },
255 { 256, "MPP" },
256 { 257, "EURAW" },
257 { 258, "EUUI" },
258 { 259, "X25" },
259 { 260, "COMB" },
260 { 261, "FR" },
261 { 262, "MP" },
262 { 263, "FR-CIR"},
263 { 0, NULL }
266 static const value_string opsi_framed_routing_code[] = {
267 { 0, "None" },
268 { 1, "Broadcast" },
269 { 2, "Listen" },
270 { 3, "Broadcast-Listen" },
271 { 4, "Broadcast V2" },
272 { 5, "Listen V2" },
273 { 6, "Broadcast-Listen V2" },
274 { 0, NULL },
277 static const value_string opsi_framed_compression_code[] = {
278 { 0, "None" },
279 { 1, "Van Jacobsen TCP/IP" },
280 { 2, "IPX header compression" },
281 { 0, NULL }
284 static const value_string opsi_nas_port_type_code[] = {
285 { 0, "Async" },
286 { 1, "Sync" },
287 { 2, "ISDN Sync" },
288 { 3, "ISDN Async V.120" },
289 { 4, "ISDN Async V.110" },
290 { 5, "Virtual" },
291 { 6, "PIAFS" },
292 { 7, "HDLC Clear Channel" },
293 { 8, "X.25" },
294 { 9, "X.75" },
295 { 10, "G.3 Fax" },
296 { 11, "SDSL - Symmetric DSL" },
297 { 12, "ADSL-CAP - Asymmetric DSL, Carrierless Amplitude Phase Modulation" },
298 { 13, "ADSL-DMT - Asymmetric DSL, Discrete Multi-Tone" },
299 { 14, "IDSL - ISDN Digital Subscriber Line" },
300 { 15, "Ethernet" },
301 { 16, "xDSL - Digital Subscriber Line of unknown type" },
302 { 17, "Cable" },
303 { 18, "Wireless - Other" },
304 { 19, "Wireless - IEEE 802.11" },
305 { 201,"Voice over IP" },
306 { 0, NULL }
310 /* Structure used to decode OPSI frame attributes */
311 /* CAUTION : it is compulsory to sort this array */
312 /* (first argument of the opsi_attribute_handle_t) */
313 /* in ascending order */
314 /* */
315 static opsi_attribute_handle_t opsi_attributes[] = {
316 { USER_NAME_ATTRIBUTE, /* 1 */
317 "User name attribute", &ett_opsi_user_name, &hf_user_name_att, decode_string_attribute },
318 { USER_PASSWD_ATTRIBUTE, /* 2 */
319 "User password attribute" , &ett_opsi_user_password, &hf_password_att, decode_string_attribute },
320 { CHAP_PASSWD_ATTRIBUTE, /* 3 */
321 "CHAP password attribute", &ett_opsi_chap_password, &hf_chap_password_att, decode_string_attribute },
322 { NAS_IP_ADDRESS_ATTRIBUTE, /* 4 */
323 "NAS IP address attribute", &ett_opsi_nas_ip_address, &hf_nas_ip_add_att, decode_ipv4_attribute },
324 {NAS_PORT_ATTRIBUTE, /* 5 */
325 "NAS port attribute", &ett_opsi_nas_port, &hf_nas_port_att, decode_longint_attribute },
326 {SERVICE_TYPE_ATTRIBUTE, /* 6 */
327 "Service type attribute", &ett_opsi_service_type, &hf_service_type_att, decode_value_string_attribute },
328 {FRAMED_PROTOCOL_ATTRIBUTE, /* 7 */
329 "Framed protocol attribute", &ett_opsi_framed_protocol, &hf_framed_protocol_att, decode_value_string_attribute },
330 {FRAMED_ADDRESS_ATTRIBUTE, /* 8 */
331 "Framed address attribute", &ett_opsi_framed_address, &hf_framed_address_att, decode_ipv4_attribute },
332 {FRAMED_NETMASK_ATTRIBUTE, /* 9 */
333 "Framed netmask attribute", &ett_opsi_framed_netmask, &hf_framed_netmask_att, decode_ipv4_attribute },
334 {FRAMED_ROUTING_ATTRIBUTE, /* 10 */
335 "Framed routing attribute", &ett_opsi_framed_routing, &hf_framed_routing_att, decode_value_string_attribute },
336 {FRAMED_FILTER_ATTRIBUTE, /* 11 */
337 "Framed filter attribute", &ett_opsi_framed_filter, &hf_framed_filter_att, decode_string_attribute },
338 {FRAMED_MTU_ATTRIBUTE, /* 12 */
339 "Framed MTU attribute", &ett_opsi_framed_mtu, &hf_framed_mtu_att, decode_longint_attribute },
340 {FRAMED_COMPRESSION_ATTRIBUTE, /* 13 */
341 "Framed compression attribute", &ett_opsi_framed_compression, &hf_framed_compression_att, decode_value_string_attribute },
342 {CALLED_STATION_ID_ATTRIBUTE, /* 30 */
343 "Called station ID attribute", &ett_opsi_called_station_id, &hf_called_station_att, decode_string_attribute },
344 {CALLING_STATION_ID_ATTRIBUTE, /* 31 */
345 "Calling station ID attribute", &ett_opsi_calling_station_id, &hf_calling_station_att, decode_string_attribute },
346 {NAS_IDENTIFIER, /* 32 */
347 "NAS Identifier attribute", &ett_opsi_nas_identifier, &hf_nas_identifier_att, decode_string_attribute },
348 {ACCOUNTING_40_ATTRIBUTE, /* 40 */
349 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
350 {ACCOUNTING_41_ATTRIBUTE, /* 41 */
351 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
352 {ACCOUNTING_42_ATTRIBUTE, /* 42 */
353 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
354 {ACCOUNTING_43_ATTRIBUTE, /* 43 */
355 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
356 {ACCOUNTING_SESSION_ID_ATTRIBUTE, /* 44 */
357 "Accounting session ID attribute", &ett_opsi_acct_session_id, &hf_acct_session_id_att, decode_string_attribute },
358 {ACCOUNTING_45_ATTRIBUTE, /* 45 */
359 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
360 {ACCOUNTING_46_ATTRIBUTE, /* 46 */
361 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
362 {ACCOUNTING_47_ATTRIBUTE, /* 47 */
363 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
364 {ACCOUNTING_48_ATTRIBUTE, /* 48 */
365 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
366 {ACCOUNTING_49_ATTRIBUTE, /* 49 */
367 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
368 {ACCOUNTING_50_ATTRIBUTE, /* 50 */
369 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
370 {ACCOUNTING_51_ATTRIBUTE, /* 51 */
371 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
372 {ACCOUNTING_52_ATTRIBUTE, /* 52 */
373 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
374 {ACCOUNTING_53_ATTRIBUTE, /* 53 */
375 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
376 {ACCOUNTING_54_ATTRIBUTE, /* 54 */
377 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
378 {ACCOUNTING_55_ATTRIBUTE, /* 55 */
379 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
380 {ACCOUNTING_56_ATTRIBUTE, /* 56 */
381 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
382 {ACCOUNTING_57_ATTRIBUTE, /* 57 */
383 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
384 {ACCOUNTING_58_ATTRIBUTE, /* 58 */
385 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
386 {ACCOUNTING_59_ATTRIBUTE, /* 59 */
387 "Accounting attribute", &ett_opsi_accounting, &hf_accounting_att, decode_string_attribute },
388 {CHAP_CHALLENGE_ATTRIBUTE, /* 60 */
389 "CHAP challenge", &ett_opsi_chap_challenge, &hf_chap_challenge_att, decode_string_attribute },
390 {NAS_PORT_TYPE_ATTRIBUTE, /* 61 */
391 "NAS port type attribute", &ett_opsi_nas_port_type, &hf_nas_port_type_att, decode_value_string_attribute },
392 {DESIGNATION_NUMBER_ATTRIBUTE, /* 77 */
393 "Designation number attribute", &ett_opsi_designation_number, &hf_designation_num_att, decode_string_attribute },
394 {NAS_PORT_ID_ATTRIBUTE, /* 87 */
395 "NAS port ID attribute", &ett_opsi_nas_port_id, &hf_nas_port_id_att, decode_string_attribute },
396 {SMC_AAAID_ATTRIBUTE, /* 651 */
397 "SMC AAA ID attribute", &ett_opsi_smc_aaa_id, &hf_smc_aaa_id_att, decode_longint_attribute },
398 {SMC_VPNID_ATTRIBUTE, /* 652 */
399 "SMC VPN ID attribute", &ett_opsi_smc_vpn_id, &hf_smc_vpn_id_att, decode_longint_attribute },
400 {SMC_VPNNAME_ATTRIBUTE, /* 653 */
401 "SMC VPN name attribute", &ett_opsi_smc_vpn_name, &hf_smc_vpn_name_att, decode_string_attribute },
402 {SMC_RANID_ATTRIBUTE, /* 654 */
403 "SMC RAN ID attribute", &ett_opsi_smc_ran_id, &hf_smc_ran_id_att, decode_longint_attribute },
404 {SMC_RANIP_ATTRIBUTE, /* 655 */
405 "SMC RAN IP attribute", &ett_opsi_smc_ran_ip, &hf_smc_ran_ip_att, decode_ipv4_attribute },
406 {SMC_RANNAME_ATTRIBUTE, /* 656 */
407 "SMC RAN name attribute", &ett_opsi_smc_ran_name, &hf_smc_ran_name_att, decode_string_attribute },
408 {SMC_POPID_ATTRIBUTE, /* 657 */
409 "SMC POP ID attribute", &ett_opsi_smc_pop_id, &hf_smc_pop_id_att, decode_longint_attribute },
410 {SMC_POPNAME_ATTRIBUTE, /* 658 */
411 "SMC POP name attribute", &ett_opsi_smc_pop_name, &hf_smc_pop_name_att, decode_string_attribute },
412 {SMC_SMCID_ATTRIBUTE, /* 659 */
413 "SMC ID attribute", &ett_opsi_smc_id, &hf_smc_id_att, decode_longint_attribute },
414 {SMC_RECEIVE_TIME_ATTRIBUTE, /* 660 */
415 "SMC receive time attribute", &ett_opsi_smc_receive_time, &hf_smc_receive_time_att, decode_time_attribute },
416 {SMC_STAT_TIME_ATTRIBUTE, /* 661 */
417 "SMC stat time attribute", &ett_opsi_smc_stat_time, &hf_smc_stat_time_att, decode_longint_attribute },
418 {OPSI_FLAGS_ATTRIBUTE, /* 674 */
419 "OPSI flags attribute", &ett_opsi_flags, &hf_opsi_flags_att, decode_longint_attribute },
420 {OPSI_APPLICATION_NAME_ATTRIBUTE,/* 675 */
421 "OPSI application name attribute", &ett_opsi_application_name, &hf_opsi_application_name_att, decode_string_attribute },
424 #define OPSI_ATTRIBUTES_COUNT (sizeof(opsi_attributes)/sizeof(opsi_attribute_handle_t))
426 /* Desegmentation of OPSI (over TCP) */
427 static gboolean opsi_desegment = TRUE;
429 static void
430 decode_string_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length)
432 guint8* pbuffer;
433 if (length < 4) {
434 expert_add_info(pinfo, item, &ei_opsi_short_attribute);
435 return;
438 pbuffer=tvb_get_string(wmem_packet_scope(), tvb, offset+4, length-4);
439 proto_tree_add_string(tree, *hfValue, tvb, offset+4, length-4, pbuffer);
443 static void
444 decode_ipv4_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length)
446 guint32 ip_address;
447 if (length < 8) {
448 expert_add_info(pinfo, item, &ei_opsi_short_attribute);
449 return;
451 ip_address = tvb_get_ipv4(tvb, offset+4);
452 proto_tree_add_ipv4(tree, *hfValue, tvb, offset+4, 4, ip_address);
455 static void
456 decode_longint_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length)
458 if (length < 8) {
459 expert_add_info(pinfo, item, &ei_opsi_short_attribute);
460 return;
462 proto_tree_add_uint(tree, *hfValue, tvb, offset+4, 4, tvb_get_ntohl(tvb, offset+4));
465 static void
466 decode_value_string_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length)
468 if (length < 8) {
469 expert_add_info(pinfo, item, &ei_opsi_short_attribute);
470 return;
472 proto_tree_add_item(tree, *hfValue, tvb, offset+4, 4, ENC_BIG_ENDIAN);
475 static void
476 decode_time_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item, int* hfValue, int offset, int length)
478 nstime_t ns;
480 if (length < 8) {
481 expert_add_info(pinfo, item, &ei_opsi_short_attribute);
482 return;
484 ns.secs = tvb_get_ntohl(tvb, offset+4);
485 ns.nsecs = 0;
486 proto_tree_add_time(tree, *hfValue, tvb, offset+4, 4, &ns);
489 /****************************************************************************/
490 /********** End of attribute decoding ***************************************/
491 /****************************************************************************/
493 /* To find the correct size of the PDU. Needed by the desegmentation feature*/
494 static guint
495 get_opsi_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
498 * Get the length of the OPSI packet.
499 * We are guaranteed there're enough chars in tvb in order to
500 * extract the length value. No exception thrown !!
502 return tvb_get_ntohs(tvb, offset + 4);
505 static int
506 get_opsi_attribute_index(int min, int max, int attribute_type)
508 int middle, at;
510 middle = (min+max)/2;
511 at = opsi_attributes[middle].attribute_type;
512 if (at == attribute_type) return middle;
513 if (attribute_type > at) {
514 return (middle == max) ? -1 : get_opsi_attribute_index(middle+1, max, attribute_type);
516 return (middle == min) ? -1 : get_opsi_attribute_index(min, middle-1, attribute_type);
520 static void
521 dissect_attributes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *opsi_tree, int offset, int length)
523 int i;
524 int attribute_type;
525 int attribute_length;
526 proto_item *ti;
527 proto_tree *ntree = NULL;
529 while (length >= 4) {
530 attribute_type = tvb_get_ntohs(tvb, offset);
531 attribute_length = tvb_get_ntohs(tvb, offset+2);
532 if (attribute_length > length) break;
533 /* We perform a standard log(n) lookup */
534 i = get_opsi_attribute_index(0, OPSI_ATTRIBUTES_COUNT-1, attribute_type);
535 if (i == -1) {
536 proto_tree_add_expert_format(opsi_tree, pinfo, &ei_opsi_unknown_attribute, tvb, offset, attribute_length,
537 "Unknown attribute (%d)", attribute_type);
539 else {
540 ti = proto_tree_add_text(opsi_tree, tvb, offset, attribute_length, "%s (%d)", opsi_attributes[i].tree_text, attribute_type);
541 ntree = proto_item_add_subtree(ti, *opsi_attributes[i].tree_id);
542 proto_tree_add_item(ntree, hf_opsi_attribute_length, tvb, offset+2, 2, ENC_BIG_ENDIAN);
543 opsi_attributes[i].dissect(tvb, pinfo, ntree, ti, opsi_attributes[i].hf_type_attribute, offset, attribute_length);
545 if (attribute_length < 4) {
546 /* Length must be at least 4, for the type and length. */
547 break;
549 offset += attribute_length;
550 length -= attribute_length;
552 if (length) {
553 proto_tree_add_expert(opsi_tree, pinfo, &ei_opsi_short_frame, tvb, offset, -1);
557 static int
558 dissect_opsi_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
560 proto_item *ti;
561 proto_tree *opsi_tree;
563 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OPSI");
564 col_clear(pinfo->cinfo, COL_INFO);
566 col_append_sep_fstr(pinfo->cinfo, COL_INFO, ", ", "%s",
567 val_to_str(tvb_get_guint8(tvb, CODE_OFFSET), opsi_opcode,
568 "<Unknown opcode %d>"));
569 col_set_fence(pinfo->cinfo, COL_INFO);
571 ti = proto_tree_add_item(tree, proto_opsi, tvb, 0, -1, ENC_NA);
572 opsi_tree = proto_item_add_subtree(ti, ett_opsi);
574 if (opsi_tree) {
575 proto_tree_add_item(opsi_tree, hf_opsi_major_version, tvb, MAJOR_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
576 proto_tree_add_item(opsi_tree, hf_opsi_minor_version, tvb, MINOR_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
577 proto_tree_add_item(opsi_tree, hf_opsi_opcode, tvb, CODE_OFFSET, 1, ENC_BIG_ENDIAN);
578 proto_tree_add_item(opsi_tree, hf_opsi_hook_id, tvb, HOOK_ID_OFFSET, 1, ENC_BIG_ENDIAN);
579 proto_tree_add_item(opsi_tree, hf_opsi_length, tvb, PACKET_LENGTH_OFFSET, 2, ENC_BIG_ENDIAN);
580 proto_tree_add_item(opsi_tree, hf_opsi_session_id, tvb, SESSION_OFFSET, 2, ENC_BIG_ENDIAN);
583 dissect_attributes(tvb, pinfo, opsi_tree, HEADER_LENGTH, MIN(((int)tvb_reported_length(tvb)-HEADER_LENGTH), (tvb_get_ntohs(tvb, PACKET_LENGTH_OFFSET)-HEADER_LENGTH)));
584 return tvb_length(tvb);
588 static int
589 dissect_opsi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
591 /* We should mimimally grab the header */
592 tcp_dissect_pdus(tvb, pinfo, tree, opsi_desegment, HEADER_LENGTH, get_opsi_pdu_len,
593 dissect_opsi_pdu, data);
594 return tvb_length(tvb);
598 void
599 proto_register_opsi(void)
602 /* Setup list of header fields See Section 1.6.1 for details*/
603 static hf_register_info hf[] = {
604 { &hf_opsi_major_version,
605 { "Major version", "opsi.major",
606 FT_UINT8, BASE_DEC, NULL, 0x0,
607 NULL, HFILL }
609 { &hf_opsi_minor_version,
610 { "Minor version", "opsi.minor",
611 FT_UINT8, BASE_DEC, NULL, 0x0,
612 NULL, HFILL }
614 { &hf_opsi_opcode,
615 { "Operation code", "opsi.opcode",
616 FT_UINT8, BASE_DEC, VALS(opsi_opcode), 0x0,
617 NULL, HFILL }
619 { &hf_opsi_hook_id,
620 { "Hook ID", "opsi.hook",
621 FT_UINT8, BASE_DEC, NULL, 0x0,
622 NULL, HFILL }
624 { &hf_opsi_length,
625 { "Message length", "opsi.length",
626 FT_UINT16, BASE_DEC, NULL, 0x0,
627 NULL, HFILL }
629 { &hf_opsi_session_id,
630 { "Session ID", "opsi.session_id",
631 FT_UINT16, BASE_DEC, NULL, 0x0,
632 NULL, HFILL }
634 { &hf_user_name_att,
635 { "User name", "opsi.attr.user_name",
636 FT_STRING, BASE_NONE, NULL, 0x00,
637 NULL, HFILL }
639 { &hf_password_att,
640 { "User password", "opsi.attr.password",
641 FT_STRING, BASE_NONE, NULL, 0x00,
642 NULL, HFILL }
644 { &hf_chap_password_att,
645 { "CHAP password attribute", "opsi.attr.chap_password",
646 FT_STRING, BASE_NONE, NULL, 0x00,
647 NULL, HFILL }
649 { &hf_nas_ip_add_att,
650 { "NAS IP address", "opsi.attr.nas_ip_addr",
651 FT_IPv4, BASE_NONE, NULL, 0x00,
652 NULL, HFILL }
654 { &hf_nas_port_att,
655 { "NAS port", "opsi.attr.nas_port",
656 FT_UINT32, BASE_HEX, NULL, 0x00,
657 NULL, HFILL }
659 { &hf_service_type_att,
660 { "Service type", "opsi.attr.service_type",
661 FT_UINT32, BASE_DEC, VALS(opsi_service_type_code), 0x0,
662 NULL, HFILL }
664 { &hf_framed_protocol_att,
665 { "Framed protocol", "opsi.attr.framed_protocol",
666 FT_UINT32, BASE_DEC, VALS(opsi_framed_protocol_code), 0x0,
667 NULL, HFILL }
669 { &hf_framed_address_att,
670 { "Framed address", "opsi.attr.framed_address",
671 FT_IPv4, BASE_NONE, NULL, 0x00,
672 NULL, HFILL }
674 { &hf_framed_netmask_att,
675 { "Framed netmask", "opsi.attr.framed_netmask",
676 FT_IPv4, BASE_NONE, NULL, 0x00,
677 NULL, HFILL }
679 { &hf_framed_routing_att,
680 { "Framed routing", "opsi.attr.framed_routing",
681 FT_UINT32, BASE_DEC, VALS(opsi_framed_routing_code), 0x0,
682 NULL, HFILL }
684 { &hf_framed_filter_att,
685 { "Framed filter", "opsi.attr.framed_filter",
686 FT_STRING, BASE_NONE, NULL, 0x00,
687 NULL, HFILL }
689 { &hf_framed_mtu_att,
690 { "Framed MTU", "opsi.attr.framed_mtu",
691 FT_UINT32, BASE_DEC, NULL, 0x00,
692 NULL, HFILL }
694 { &hf_framed_compression_att,
695 { "Framed compression", "opsi.attr.framed_compression",
696 FT_UINT32, BASE_DEC, VALS(opsi_framed_compression_code), 0x0,
697 NULL, HFILL }
699 { &hf_called_station_att,
700 { "Called station ID", "opsi.attr.called_station_id",
701 FT_STRING, BASE_NONE, NULL, 0x00,
702 NULL, HFILL }
704 { &hf_calling_station_att,
705 { "Calling station ID", "opsi.attr.calling_station_id",
706 FT_STRING, BASE_NONE, NULL, 0x00,
707 NULL, HFILL }
709 { &hf_nas_identifier_att,
710 { "NAS ID", "opsi.attr.nas_id",
711 FT_STRING, BASE_NONE, NULL, 0x00,
712 NULL, HFILL }
714 { &hf_accounting_att,
715 { "Accounting", "opsi.attr.accounting",
716 FT_STRING, BASE_NONE, NULL, 0x00,
717 NULL, HFILL }
719 { &hf_acct_session_id_att,
720 { "Accounting session ID", "opsi.attr.acct.session_id",
721 FT_STRING, BASE_NONE, NULL, 0x00,
722 NULL, HFILL }
724 { &hf_chap_challenge_att,
725 { "CHAP challenge", "opsi.attr.chap_challenge",
726 FT_STRING, BASE_NONE, NULL, 0x00,
727 NULL, HFILL }
729 { &hf_nas_port_type_att,
730 { "NAS port type", "opsi.attr.nas_port_type",
731 FT_UINT32, BASE_DEC, VALS(opsi_nas_port_type_code), 0x0,
732 NULL, HFILL }
734 { &hf_designation_num_att,
735 { "Designation number", "opsi.attr.designation_number",
736 FT_STRING, BASE_NONE, NULL, 0x00,
737 NULL, HFILL }
739 { &hf_nas_port_id_att,
740 { "NAS port ID", "opsi.attr.nas_port_id",
741 FT_STRING, BASE_NONE, NULL, 0x00,
742 NULL, HFILL }
744 { &hf_smc_aaa_id_att,
745 { "SMC AAA ID", "opsi.attr.smc_aaa_id",
746 FT_UINT32, BASE_DEC, NULL, 0x00,
747 NULL, HFILL }
749 { &hf_smc_vpn_id_att,
750 { "SMC VPN ID", "opsi.attr.smc_vpn_id",
751 FT_UINT32, BASE_DEC, NULL, 0x00,
752 NULL, HFILL }
754 { &hf_smc_vpn_name_att,
755 { "SMC VPN name", "opsi.attr.smc_vpn_name",
756 FT_STRING, BASE_NONE, NULL, 0x00,
757 NULL, HFILL }
759 { &hf_smc_ran_id_att,
760 { "SMC RAN ID", "opsi.attr.smc_ran_id",
761 FT_UINT32, BASE_DEC, NULL, 0x00,
762 NULL, HFILL }
764 { &hf_smc_ran_ip_att,
765 { "SMC RAN IP address", "opsi.attr.smc_ran_ip",
766 FT_IPv4, BASE_NONE, NULL, 0x00,
767 NULL, HFILL }
769 { &hf_smc_ran_name_att,
770 { "SMC RAN name", "opsi.attr.smc_ran_name",
771 FT_STRING, BASE_NONE, NULL, 0x00,
772 NULL, HFILL }
774 { &hf_smc_pop_id_att,
775 { "SMC POP id", "opsi.attr.smc_pop_id",
776 FT_UINT32, BASE_DEC, NULL, 0x00,
777 NULL, HFILL }
779 { &hf_smc_pop_name_att,
780 { "SMC POP name", "opsi.attr.smc_pop_name",
781 FT_STRING, BASE_NONE, NULL, 0x00,
782 NULL, HFILL }
784 { &hf_smc_id_att,
785 { "SMC ID", "opsi.attr.smc_id",
786 FT_UINT32, BASE_DEC, NULL, 0x00,
787 NULL, HFILL }
789 { &hf_smc_receive_time_att,
790 { "SMC receive time", "opsi.attr.smc_receive_time",
791 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
792 NULL, HFILL }
794 { &hf_smc_stat_time_att,
795 { "SMC stat time", "opsi.attr.smc_stat_time",
796 FT_UINT32, BASE_DEC, NULL, 0x00,
797 NULL, HFILL }
799 { &hf_opsi_flags_att,
800 { "OPSI flags", "opsi.attr.flags",
801 FT_UINT32, BASE_DEC, NULL, 0x00,
802 NULL, HFILL }
804 { &hf_opsi_application_name_att,
805 { "OPSI application name", "opsi.attr.application_name",
806 FT_STRING, BASE_NONE, NULL, 0x00,
807 NULL, HFILL }
809 { &hf_opsi_attribute_length,
810 { "Length", "opsi.attr_length",
811 FT_UINT16, BASE_DEC, NULL, 0x00,
812 NULL, HFILL }
816 /* Setup protocol subtree array */
817 static gint *ett[] = {
818 &ett_opsi,
819 &ett_opsi_user_name,
820 &ett_opsi_user_password,
821 &ett_opsi_chap_password,
822 &ett_opsi_nas_ip_address,
823 &ett_opsi_nas_port,
824 &ett_opsi_service_type,
825 &ett_opsi_framed_protocol,
826 &ett_opsi_framed_address,
827 &ett_opsi_framed_netmask,
828 &ett_opsi_framed_routing,
829 &ett_opsi_framed_filter,
830 &ett_opsi_framed_mtu,
831 &ett_opsi_framed_compression,
832 &ett_opsi_called_station_id,
833 &ett_opsi_calling_station_id,
834 &ett_opsi_nas_identifier,
835 &ett_opsi_accounting,
836 &ett_opsi_acct_session_id,
837 &ett_opsi_chap_challenge,
838 &ett_opsi_nas_port_type,
839 &ett_opsi_designation_number,
840 &ett_opsi_nas_port_id,
841 &ett_opsi_smc_aaa_id,
842 &ett_opsi_smc_vpn_id,
843 &ett_opsi_smc_vpn_name,
844 &ett_opsi_smc_ran_id,
845 &ett_opsi_smc_ran_ip,
846 &ett_opsi_smc_ran_name,
847 &ett_opsi_smc_pop_id,
848 &ett_opsi_smc_pop_name,
849 &ett_opsi_smc_id,
850 &ett_opsi_smc_receive_time,
851 &ett_opsi_smc_stat_time,
852 &ett_opsi_flags,
853 &ett_opsi_application_name,
856 static ei_register_info ei[] = {
857 { &ei_opsi_unknown_attribute, { "opsi.attr_unknown", PI_PROTOCOL, PI_WARN, "Unknown attribute", EXPFILL }},
858 { &ei_opsi_short_attribute, { "opsi.attr_too_short", PI_MALFORMED, PI_WARN, "Too short attribute!", EXPFILL }},
859 { &ei_opsi_short_frame, { "opsi.short_frame", PI_MALFORMED, PI_WARN, "Short frame", EXPFILL }},
862 /* For desegmentation / reassembly */
863 module_t *opsi_module;
864 expert_module_t* expert_opsi;
866 /* Register the protocol name and description */
867 proto_opsi = proto_register_protocol("Open Policy Service Interface",
868 "OPSI", "opsi");
870 /* Required function calls to register the header fields and subtrees used */
871 proto_register_field_array(proto_opsi, hf, array_length(hf));
872 proto_register_subtree_array(ett, array_length(ett));
873 expert_opsi = expert_register_protocol(proto_opsi);
874 expert_register_field_array(expert_opsi, ei, array_length(ei));
876 /* We activate the desegmentation / reassembly feature */
877 opsi_module = prefs_register_protocol(proto_opsi, NULL);
878 prefs_register_bool_preference(opsi_module, "desegment_opsi_messages",
879 "Reassemble OPSI messages spanning multiple TCP segments",
880 "Whether the OPSI dissector should desegment all messages spanning multiple TCP segments",
881 &opsi_desegment);
885 void
886 proto_reg_handoff_opsi(void)
888 dissector_handle_t opsi_handle;
889 opsi_handle = new_create_dissector_handle(dissect_opsi, proto_opsi);
890 dissector_add_uint("tcp.port", TCP_PORT_OPSI, opsi_handle);