2 * Routines for Baseline Privacy Key Management Attributes dissection
3 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
5 * $Id: packet-bpkmattr.c,v 1.6 2003/09/09 07:17:00 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "plugins/plugin_api.h"
31 #include "plugins/plugin_api_defs.h"
32 #include "moduleinfo.h"
40 #include <epan/packet.h>
42 /* BPKM Attributes defined in:
43 * http://www.cablemodem.com/downloads/specs/SP-BPI+_I10-030730.pdf
45 #define BPKM_RESERVED 0
46 #define BPKM_SERIAL_NUM 1
47 #define BPKM_MANUFACTURER_ID 2
48 #define BPKM_MAC_ADDR 3
49 #define BPKM_RSA_PUB_KEY 4
51 #define BPKM_DISPLAY_STR 6
52 #define BPKM_AUTH_KEY 7
54 #define BPKM_KEY_LIFETIME 9
55 #define BPKM_KEY_SEQ_NUM 10
56 #define BPKM_HMAC_DIGEST 11
58 #define BPKM_TEK_PARAM 13
59 #define BPKM_OBSOLETED 14
60 #define BPKM_CBC_IV 15
61 #define BPKM_ERROR_CODE 16
62 #define BPKM_CA_CERT 17
63 #define BPKM_CM_CERT 18
64 #define BPKM_SEC_CAPABILITIES 19
65 #define BPKM_CRYPTO_SUITE 20
66 #define BPKM_CRYPTO_SUITE_LIST 21
67 #define BPKM_BPI_VERSION 22
68 #define BPKM_SA_DESCRIPTOR 23
69 #define BPKM_SA_TYPE 24
70 #define BPKM_SA_QUERY 25
71 #define BPKM_SA_QUERY_TYPE 26
72 #define BPKM_IP_ADDRESS 27
73 #define BPKM_DNLD_PARAMS 28
74 #define BPKM_VENDOR_DEFINED 127
76 /* Initialize the protocol and registered fields */
77 static int proto_docsis_bpkmattr = -1;
78 static int hf_docsis_bpkmattr = -1;
79 static int hf_docsis_bpkmattr_serial_num = -1;
80 static int hf_docsis_bpkmattr_manf_id = -1;
81 static int hf_docsis_bpkmattr_mac_addr = -1;
82 static int hf_docsis_bpkmattr_rsa_pub_key = -1;
83 static int hf_docsis_bpkmattr_cm_id = -1;
84 static int hf_docsis_bpkmattr_display_str = -1;
85 static int hf_docsis_bpkmattr_auth_key = -1;
86 static int hf_docsis_bpkmattr_tek = -1;
87 static int hf_docsis_bpkmattr_key_life = -1;
88 static int hf_docsis_bpkmattr_key_seq = -1;
89 static int hf_docsis_bpkmattr_hmac_digest = -1;
90 static int hf_docsis_bpkmattr_said = -1;
91 static int hf_docsis_bpkmattr_tek_params = -1;
92 static int hf_docsis_bpkmattr_cbc_iv = -1;
93 static int hf_docsis_bpkmattr_error_code = -1;
94 static int hf_docsis_bpkmattr_vendor_def = -1;
95 static int hf_docsis_bpkmattr_ca_cert = -1;
96 static int hf_docsis_bpkmattr_cm_cert = -1;
97 static int hf_docsis_bpkmattr_security_cap = -1;
98 static int hf_docsis_bpkmattr_crypto_suite = -1;
99 static int hf_docsis_bpkmattr_crypto_suite_list = -1;
100 static int hf_docsis_bpkmattr_bpi_version = -1;
101 static int hf_docsis_bpkmattr_sa_descr = -1;
102 static int hf_docsis_bpkmattr_sa_type = -1;
103 static int hf_docsis_bpkmattr_sa_query = -1;
104 static int hf_docsis_bpkmattr_sa_query_type = -1;
105 static int hf_docsis_bpkmattr_ip_address = -1;
106 static int hf_docsis_bpkmattr_download_param = -1;
110 /* Initialize the subtree pointers */
111 static gint ett_docsis_bpkmattr = -1;
112 static gint ett_docsis_bpkmattr_cmid = -1;
113 static gint ett_docsis_bpkmattr_scap = -1;
114 static gint ett_docsis_bpkmattr_tekp = -1;
115 static gint ett_docsis_bpkmattr_sadsc = -1;
116 static gint ett_docsis_bpkmattr_saqry = -1;
117 static gint ett_docsis_bpkmattr_dnld = -1;
120 static const value_string error_code_vals[] = {
121 {0, "no information"},
122 {1, "Unauthorized CM"},
123 {2, "Unauthorized SAID"},
125 {4, "Invalid Key Sequence Number"},
126 {5, "Key Request authentication failure"},
127 {6, "Permanent Authorization Failure"},
128 {7, "Not authorized for requested downstream traffic flow"},
129 {8, "Downstream traffic flow not mapped to BPI+ SAID"},
130 {9, "Time of day not acquired"},
134 static const value_string crypto_suite_attr_vals[] = {
135 {0x0100, "CBC Mode, 56 Bit DES & no Data Authentication"},
136 {0x0200, "CBC Mode, 40 Bit DES & no Data Authentication"},
140 static const value_string bpi_ver_vals[] = {
146 /* Code to actually dissect the packets */
148 /* The dissect_attrs() function does the actual work to dissect the
149 * attributes. It's called recursively, to dissect embedded attributes
152 dissect_attrs (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
158 proto_item *cmid_it, *tekp_it, *scap_it;
159 proto_item *saqry_it, *dnld_it, *sadsc_it;
160 proto_tree *cmid_tree, *tekp_tree, *scap_tree;
161 proto_tree *saqry_tree, *dnld_tree, *sadsc_tree;
162 tvbuff_t *cmid_tvb, *tekp_tvb, *scap_tvb;
163 tvbuff_t *saqry_tvb, *dnld_tvb, *sadsc_tvb;
165 total_len = tvb_length_remaining (tvb, 0);
166 while (pos < total_len)
168 type = tvb_get_guint8 (tvb, pos++);
169 length = tvb_get_ntohs (tvb, pos);
175 case BPKM_SERIAL_NUM:
176 proto_tree_add_item (tree, hf_docsis_bpkmattr_serial_num, tvb, pos,
179 case BPKM_MANUFACTURER_ID:
181 proto_tree_add_item (tree, hf_docsis_bpkmattr_manf_id, tvb, pos,
184 THROW (ReportedBoundsError);
188 proto_tree_add_item (tree, hf_docsis_bpkmattr_mac_addr, tvb, pos,
191 THROW (ReportedBoundsError);
193 case BPKM_RSA_PUB_KEY:
194 proto_tree_add_item (tree, hf_docsis_bpkmattr_rsa_pub_key, tvb, pos,
199 proto_tree_add_text (tree, tvb, pos, length,
200 "5 CM Identification");
202 proto_item_add_subtree (cmid_it, ett_docsis_bpkmattr_cmid);
203 cmid_tvb = tvb_new_subset (tvb, pos, length, length);
204 dissect_attrs (cmid_tvb, pinfo, cmid_tree);
206 case BPKM_DISPLAY_STR:
207 proto_tree_add_item (tree, hf_docsis_bpkmattr_display_str, tvb, pos,
211 if ((length == 96) || (length == 128))
212 proto_tree_add_item (tree, hf_docsis_bpkmattr_auth_key, tvb, pos,
215 THROW (ReportedBoundsError);
219 proto_tree_add_item (tree, hf_docsis_bpkmattr_tek, tvb, pos,
222 THROW (ReportedBoundsError);
224 case BPKM_KEY_LIFETIME:
226 proto_tree_add_item (tree, hf_docsis_bpkmattr_key_life, tvb, pos,
229 THROW (ReportedBoundsError);
231 case BPKM_KEY_SEQ_NUM:
233 proto_tree_add_item (tree, hf_docsis_bpkmattr_key_seq, tvb, pos,
236 THROW (ReportedBoundsError);
238 case BPKM_HMAC_DIGEST:
240 proto_tree_add_item (tree, hf_docsis_bpkmattr_hmac_digest, tvb,
243 THROW (ReportedBoundsError);
247 proto_tree_add_item (tree, hf_docsis_bpkmattr_said, tvb, pos,
250 THROW (ReportedBoundsError);
254 proto_tree_add_text (tree, tvb, pos, length, "13 TEK Parameters");
256 proto_item_add_subtree (tekp_it, ett_docsis_bpkmattr_tekp);
257 tekp_tvb = tvb_new_subset (tvb, pos, length, length);
258 dissect_attrs (tekp_tvb, pinfo, tekp_tree);
264 proto_tree_add_item (tree, hf_docsis_bpkmattr_cbc_iv, tvb, pos,
267 THROW (ReportedBoundsError);
269 case BPKM_ERROR_CODE:
271 proto_tree_add_item (tree, hf_docsis_bpkmattr_error_code, tvb,
274 THROW (ReportedBoundsError);
277 proto_tree_add_item (tree, hf_docsis_bpkmattr_ca_cert, tvb, pos,
281 proto_tree_add_item (tree, hf_docsis_bpkmattr_cm_cert, tvb, pos,
284 case BPKM_SEC_CAPABILITIES:
286 proto_tree_add_text (tree, tvb, pos, length,
287 "19 Security Capabilities");
289 proto_item_add_subtree (scap_it, ett_docsis_bpkmattr_scap);
290 scap_tvb = tvb_new_subset (tvb, pos, length, length);
291 dissect_attrs (scap_tvb, pinfo, scap_tree);
293 case BPKM_CRYPTO_SUITE:
295 proto_tree_add_item (tree, hf_docsis_bpkmattr_crypto_suite, tvb,
298 THROW (ReportedBoundsError);
300 case BPKM_CRYPTO_SUITE_LIST:
301 proto_tree_add_item (tree, hf_docsis_bpkmattr_crypto_suite_list,
302 tvb, pos, length, FALSE);
304 case BPKM_BPI_VERSION:
306 proto_tree_add_item (tree, hf_docsis_bpkmattr_bpi_version, tvb,
309 THROW (ReportedBoundsError);
311 case BPKM_SA_DESCRIPTOR:
313 proto_tree_add_text (tree, tvb, pos, length, "23 SA Descriptor");
315 proto_item_add_subtree (sadsc_it, ett_docsis_bpkmattr_sadsc);
316 sadsc_tvb = tvb_new_subset (tvb, pos, length, length);
317 dissect_attrs (sadsc_tvb, pinfo, sadsc_tree);
321 proto_tree_add_item (tree, hf_docsis_bpkmattr_sa_type, tvb, pos,
324 THROW (ReportedBoundsError);
328 proto_tree_add_text (tree, tvb, pos, length, "25 SA Query");
330 proto_item_add_subtree (saqry_it, ett_docsis_bpkmattr_saqry);
331 saqry_tvb = tvb_new_subset (tvb, pos, length, length);
332 dissect_attrs (saqry_tvb, pinfo, saqry_tree);
334 case BPKM_SA_QUERY_TYPE:
336 proto_tree_add_item (tree, hf_docsis_bpkmattr_sa_query_type, tvb,
339 THROW (ReportedBoundsError);
341 case BPKM_IP_ADDRESS:
343 proto_tree_add_item (tree, hf_docsis_bpkmattr_ip_address, tvb,
346 THROW (ReportedBoundsError);
348 case BPKM_VENDOR_DEFINED:
349 proto_tree_add_item (tree, hf_docsis_bpkmattr_vendor_def, tvb, pos,
351 case BPKM_DNLD_PARAMS:
353 proto_tree_add_text (tree, tvb, pos, length,
354 "28 Download Parameters");
356 proto_item_add_subtree (dnld_it, ett_docsis_bpkmattr_dnld);
357 dnld_tvb = tvb_new_subset (tvb, pos, length, length);
358 dissect_attrs (dnld_tvb, pinfo, dnld_tree);
361 proto_tree_add_item (tree, hf_docsis_bpkmattr_vendor_def, tvb, pos,
365 pos += length; /* switch */
370 dissect_bpkmattr (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
374 proto_tree *bpkmattr_tree;
379 proto_tree_add_protocol_format (tree, proto_docsis_bpkmattr, tvb, 0,
380 tvb_length_remaining (tvb, 0),
382 bpkmattr_tree = proto_item_add_subtree (it, ett_docsis_bpkmattr);
383 dissect_attrs (tvb, pinfo, bpkmattr_tree);
390 /* Register the protocol with Ethereal */
392 /* this format is require because a script is used to build the C function
393 that calls all the protocol registration.
398 proto_register_docsis_bpkmattr (void)
401 /* Setup list of header fields See Section 1.6.1 for details*/
402 static hf_register_info hf[] = {
403 {&hf_docsis_bpkmattr,
404 {"BPKM Attributes", "docsis.bpkmattr",
405 FT_BYTES, BASE_HEX, NULL, 0x0,
406 "BPKM Attributes", HFILL}
408 {&hf_docsis_bpkmattr_serial_num,
409 {"1 Serial Number", "docsis.bpkmattr.serialnum",
410 FT_STRING, BASE_DEC, NULL, 0x0,
411 "Serial Number", HFILL}
413 {&hf_docsis_bpkmattr_manf_id,
414 {"2 Manufacturer Id", "docsis.bpkmattr.manfid",
415 FT_BYTES, BASE_HEX, NULL, 0x0,
416 "Manufacturer Id", HFILL}
418 {&hf_docsis_bpkmattr_mac_addr,
419 {"3 Mac Address", "docsis.bpkmattr.macaddr",
420 FT_ETHER, BASE_HEX, NULL, 0x0,
421 "Mac Address", HFILL}
423 {&hf_docsis_bpkmattr_rsa_pub_key,
424 {"4 RSA Public Key", "docsis.bpkmattr.rsa_pub_key",
425 FT_BYTES, BASE_HEX, NULL, 0x0,
426 "RSA Public Key", HFILL}
428 {&hf_docsis_bpkmattr_cm_id,
429 {"5 CM Identification", "docsis.bpkmattr.cmid",
430 FT_BYTES, BASE_HEX, NULL, 0x0,
431 "CM Identification", HFILL}
433 {&hf_docsis_bpkmattr_display_str,
434 {"6 Display String", "docsis.bpkmattr.dispstr",
435 FT_STRING, BASE_DEC, NULL, 0x0,
436 "Display String", HFILL}
438 {&hf_docsis_bpkmattr_auth_key,
439 {"7 Auth Key", "docsis.bpkmattr.auth_key",
440 FT_BYTES, BASE_HEX, NULL, 0x0,
443 {&hf_docsis_bpkmattr_tek,
444 {"8 Traffic Encryption Key", "docsis.bpkmattr.tek",
445 FT_BYTES, BASE_HEX, NULL, 0x0,
446 "Traffic Encryption Key", HFILL}
448 {&hf_docsis_bpkmattr_key_life,
449 {"9 Key Lifetime (s)", "docsis.bpkmattr.keylife",
450 FT_UINT32, BASE_DEC, NULL, 0x0,
451 "Key Lifetime (s)", HFILL}
453 {&hf_docsis_bpkmattr_key_seq,
454 {"10 Key Sequence Number", "docsis.bpkmattr.keyseq",
455 FT_UINT8, BASE_DEC, NULL, 0x0,
456 "Key Sequence Number", HFILL}
458 {&hf_docsis_bpkmattr_hmac_digest,
459 {"11 HMAC Digest", "docsis.bpkmattr.hmacdigest",
460 FT_BYTES, BASE_HEX, NULL, 0x0,
461 "HMAC Digest", HFILL}
463 {&hf_docsis_bpkmattr_said,
464 {"12 SAID", "docsis.bpkmattr.said",
465 FT_UINT16, BASE_DEC, NULL, 0x0,
466 "Security Association ID", HFILL}
468 {&hf_docsis_bpkmattr_tek_params,
469 {"13 TEK Parameters", "docsis.bpkmattr.tekparams",
470 FT_BYTES, BASE_HEX, NULL, 0x0,
471 "TEK Parameters", HFILL}
473 {&hf_docsis_bpkmattr_cbc_iv,
474 {"14 CBC IV", "docsis.bpkmattr.cbciv",
475 FT_BYTES, BASE_HEX, NULL, 0x0,
476 "Cypher Block Chaining", HFILL}
478 {&hf_docsis_bpkmattr_error_code,
479 {"16 Error Code", "docsis.bpkmattr.errcode",
480 FT_UINT8, BASE_DEC, VALS (error_code_vals), 0x0,
483 {&hf_docsis_bpkmattr_vendor_def,
484 {"127 Vendor Defined", "docsis.bpkmattr.vendordef",
485 FT_BYTES, BASE_HEX, NULL, 0x0,
486 "Vendor Defined", HFILL}
488 {&hf_docsis_bpkmattr_ca_cert,
489 {"17 CA Certificate", "docsis.bpkmattr.cacert",
490 FT_BYTES, BASE_HEX, NULL, 0x0,
491 "CA Certificate", HFILL}
493 {&hf_docsis_bpkmattr_cm_cert,
494 {"18 CM Certificate", "docsis.bpkmattr.cmcert",
495 FT_BYTES, BASE_HEX, NULL, 0x0,
496 "CM Certificate", HFILL}
498 {&hf_docsis_bpkmattr_security_cap,
499 {"19 Security Capabilities", "docsis.bpkmattr.seccap",
500 FT_BYTES, BASE_HEX, NULL, 0x0,
501 "Security Capabilities", HFILL}
503 {&hf_docsis_bpkmattr_crypto_suite,
504 {"20 Cryptographic Suite", "docsis.bpkmattr.cryptosuite",
505 FT_UINT16, BASE_HEX, VALS(crypto_suite_attr_vals), 0x0,
506 "Cryptographic Suite", HFILL}
508 {&hf_docsis_bpkmattr_crypto_suite_list,
509 {"21 Cryptographic Suite List", "docsis.bpkmattr.crypto_suite_lst",
510 FT_BYTES, BASE_HEX, NULL, 0x0,
511 "Cryptographic Suite", HFILL}
513 {&hf_docsis_bpkmattr_bpi_version,
514 {"22 BPI Version", "docsis.bpkmattr.bpiver",
515 FT_UINT8, BASE_DEC, VALS (bpi_ver_vals), 0x0,
516 "BPKM Attributes", HFILL}
518 {&hf_docsis_bpkmattr_sa_descr,
519 {"23 SA Descriptor", "docsis.bpkmattr.sadescr",
520 FT_BYTES, BASE_HEX, NULL, 0x0,
521 "SA Descriptor", HFILL}
523 {&hf_docsis_bpkmattr_sa_type,
524 {"24 SA Type", "docsis.bpkmattr.satype",
525 FT_UINT8, BASE_DEC, NULL, 0x0,
528 {&hf_docsis_bpkmattr_sa_query,
529 {"25 SA Query", "docsis.bpkmattr.saquery",
530 FT_BYTES, BASE_HEX, NULL, 0x0,
533 {&hf_docsis_bpkmattr_sa_query_type,
534 {"26 SA Query Type", "docsis.bpkmattr.saquery_type",
535 FT_UINT8, BASE_HEX, NULL, 0x0,
536 "SA Query Type", HFILL}
538 {&hf_docsis_bpkmattr_ip_address,
539 {"27 IP Address", "docsis.bpkmattr.ipaddr",
540 FT_IPv4, BASE_DEC, NULL, 0x0,
543 {&hf_docsis_bpkmattr_download_param,
544 {"28 Download Parameters", "docsis.bpkmattr.dnld_params",
545 FT_BYTES, BASE_HEX, NULL, 0x0,
546 "Download Parameters", HFILL}
550 /* Setup protocol subtree array */
551 static gint *ett[] = {
552 &ett_docsis_bpkmattr,
553 &ett_docsis_bpkmattr_cmid,
554 &ett_docsis_bpkmattr_scap,
555 &ett_docsis_bpkmattr_tekp,
556 &ett_docsis_bpkmattr_sadsc,
557 &ett_docsis_bpkmattr_saqry,
558 &ett_docsis_bpkmattr_dnld
561 /* Register the protocol name and description */
562 proto_docsis_bpkmattr =
563 proto_register_protocol
564 ("DOCSIS Baseline Privacy Key Management Attributes", "DOCSIS BPKM-ATTR",
567 /* Required function calls to register the header fields and subtrees used */
568 proto_register_field_array (proto_docsis_bpkmattr, hf, array_length (hf));
569 proto_register_subtree_array (ett, array_length (ett));
571 register_dissector ("docsis_bpkmattr", dissect_bpkmattr,
572 proto_docsis_bpkmattr);
576 /* If this dissector uses sub-dissector registration add a registration routine.
577 This format is required because a script is used to find these routines and
578 create the code that calls these routines.
581 proto_reg_handoff_docsis_bpkmattr (void)
583 dissector_handle_t docsis_bpkmattr_handle;
585 docsis_bpkmattr_handle = find_dissector ("docsis_bpkmattr");
586 dissector_add ("docsis", 0xFE, docsis_bpkmattr_handle);