2 * Routines for Baseline Privacy Key Management Attributes dissection
3 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "moduleinfo.h"
38 #include <epan/packet.h>
40 /* BPKM Attributes defined in:
41 * http://www.cablemodem.com/downloads/specs/SP-BPI+_I10-030730.pdf
43 #define BPKM_RESERVED 0
44 #define BPKM_SERIAL_NUM 1
45 #define BPKM_MANUFACTURER_ID 2
46 #define BPKM_MAC_ADDR 3
47 #define BPKM_RSA_PUB_KEY 4
49 #define BPKM_DISPLAY_STR 6
50 #define BPKM_AUTH_KEY 7
52 #define BPKM_KEY_LIFETIME 9
53 #define BPKM_KEY_SEQ_NUM 10
54 #define BPKM_HMAC_DIGEST 11
56 #define BPKM_TEK_PARAM 13
57 #define BPKM_OBSOLETED 14
58 #define BPKM_CBC_IV 15
59 #define BPKM_ERROR_CODE 16
60 #define BPKM_CA_CERT 17
61 #define BPKM_CM_CERT 18
62 #define BPKM_SEC_CAPABILITIES 19
63 #define BPKM_CRYPTO_SUITE 20
64 #define BPKM_CRYPTO_SUITE_LIST 21
65 #define BPKM_BPI_VERSION 22
66 #define BPKM_SA_DESCRIPTOR 23
67 #define BPKM_SA_TYPE 24
68 #define BPKM_SA_QUERY 25
69 #define BPKM_SA_QUERY_TYPE 26
70 #define BPKM_IP_ADDRESS 27
71 #define BPKM_DNLD_PARAMS 28
72 #define BPKM_VENDOR_DEFINED 127
74 /* Initialize the protocol and registered fields */
75 static int proto_docsis_bpkmattr = -1;
76 static int hf_docsis_bpkmattr = -1;
77 static int hf_docsis_bpkmattr_serial_num = -1;
78 static int hf_docsis_bpkmattr_manf_id = -1;
79 static int hf_docsis_bpkmattr_mac_addr = -1;
80 static int hf_docsis_bpkmattr_rsa_pub_key = -1;
81 static int hf_docsis_bpkmattr_cm_id = -1;
82 static int hf_docsis_bpkmattr_display_str = -1;
83 static int hf_docsis_bpkmattr_auth_key = -1;
84 static int hf_docsis_bpkmattr_tek = -1;
85 static int hf_docsis_bpkmattr_key_life = -1;
86 static int hf_docsis_bpkmattr_key_seq = -1;
87 static int hf_docsis_bpkmattr_hmac_digest = -1;
88 static int hf_docsis_bpkmattr_said = -1;
89 static int hf_docsis_bpkmattr_tek_params = -1;
90 static int hf_docsis_bpkmattr_cbc_iv = -1;
91 static int hf_docsis_bpkmattr_error_code = -1;
92 static int hf_docsis_bpkmattr_vendor_def = -1;
93 static int hf_docsis_bpkmattr_ca_cert = -1;
94 static int hf_docsis_bpkmattr_cm_cert = -1;
95 static int hf_docsis_bpkmattr_security_cap = -1;
96 static int hf_docsis_bpkmattr_crypto_suite = -1;
97 static int hf_docsis_bpkmattr_crypto_suite_list = -1;
98 static int hf_docsis_bpkmattr_bpi_version = -1;
99 static int hf_docsis_bpkmattr_sa_descr = -1;
100 static int hf_docsis_bpkmattr_sa_type = -1;
101 static int hf_docsis_bpkmattr_sa_query = -1;
102 static int hf_docsis_bpkmattr_sa_query_type = -1;
103 static int hf_docsis_bpkmattr_ip_address = -1;
104 static int hf_docsis_bpkmattr_download_param = -1;
108 /* Initialize the subtree pointers */
109 static gint ett_docsis_bpkmattr = -1;
110 static gint ett_docsis_bpkmattr_cmid = -1;
111 static gint ett_docsis_bpkmattr_scap = -1;
112 static gint ett_docsis_bpkmattr_tekp = -1;
113 static gint ett_docsis_bpkmattr_sadsc = -1;
114 static gint ett_docsis_bpkmattr_saqry = -1;
115 static gint ett_docsis_bpkmattr_dnld = -1;
118 static const value_string error_code_vals[] = {
119 {0, "no information"},
120 {1, "Unauthorized CM"},
121 {2, "Unauthorized SAID"},
123 {4, "Invalid Key Sequence Number"},
124 {5, "Key Request authentication failure"},
125 {6, "Permanent Authorization Failure"},
126 {7, "Not authorized for requested downstream traffic flow"},
127 {8, "Downstream traffic flow not mapped to BPI+ SAID"},
128 {9, "Time of day not acquired"},
132 static const value_string crypto_suite_attr_vals[] = {
133 {0x0100, "CBC Mode, 56 Bit DES & no Data Authentication"},
134 {0x0200, "CBC Mode, 40 Bit DES & no Data Authentication"},
138 static const value_string bpi_ver_vals[] = {
144 /* Code to actually dissect the packets */
146 /* The dissect_attrs() function does the actual work to dissect the
147 * attributes. It's called recursively, to dissect embedded attributes
150 dissect_attrs (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
156 proto_item *cmid_it, *tekp_it, *scap_it;
157 proto_item *saqry_it, *dnld_it, *sadsc_it;
158 proto_tree *cmid_tree, *tekp_tree, *scap_tree;
159 proto_tree *saqry_tree, *dnld_tree, *sadsc_tree;
160 tvbuff_t *cmid_tvb, *tekp_tvb, *scap_tvb;
161 tvbuff_t *saqry_tvb, *dnld_tvb, *sadsc_tvb;
163 total_len = tvb_reported_length_remaining (tvb, 0);
164 while (pos < total_len)
166 type = tvb_get_guint8 (tvb, pos++);
167 length = tvb_get_ntohs (tvb, pos);
173 case BPKM_SERIAL_NUM:
174 proto_tree_add_item (tree, hf_docsis_bpkmattr_serial_num, tvb, pos,
177 case BPKM_MANUFACTURER_ID:
179 proto_tree_add_item (tree, hf_docsis_bpkmattr_manf_id, tvb, pos,
182 THROW (ReportedBoundsError);
186 proto_tree_add_item (tree, hf_docsis_bpkmattr_mac_addr, tvb, pos,
189 THROW (ReportedBoundsError);
191 case BPKM_RSA_PUB_KEY:
192 proto_tree_add_item (tree, hf_docsis_bpkmattr_rsa_pub_key, tvb, pos,
197 proto_tree_add_text (tree, tvb, pos, length,
198 "5 CM Identification");
200 proto_item_add_subtree (cmid_it, ett_docsis_bpkmattr_cmid);
201 cmid_tvb = tvb_new_subset (tvb, pos, length, length);
202 dissect_attrs (cmid_tvb, pinfo, cmid_tree);
204 case BPKM_DISPLAY_STR:
205 proto_tree_add_item (tree, hf_docsis_bpkmattr_display_str, tvb, pos,
209 if ((length == 96) || (length == 128))
210 proto_tree_add_item (tree, hf_docsis_bpkmattr_auth_key, tvb, pos,
213 THROW (ReportedBoundsError);
217 proto_tree_add_item (tree, hf_docsis_bpkmattr_tek, tvb, pos,
220 THROW (ReportedBoundsError);
222 case BPKM_KEY_LIFETIME:
224 proto_tree_add_item (tree, hf_docsis_bpkmattr_key_life, tvb, pos,
227 THROW (ReportedBoundsError);
229 case BPKM_KEY_SEQ_NUM:
231 proto_tree_add_item (tree, hf_docsis_bpkmattr_key_seq, tvb, pos,
234 THROW (ReportedBoundsError);
236 case BPKM_HMAC_DIGEST:
238 proto_tree_add_item (tree, hf_docsis_bpkmattr_hmac_digest, tvb,
241 THROW (ReportedBoundsError);
245 proto_tree_add_item (tree, hf_docsis_bpkmattr_said, tvb, pos,
248 THROW (ReportedBoundsError);
252 proto_tree_add_text (tree, tvb, pos, length, "13 TEK Parameters");
254 proto_item_add_subtree (tekp_it, ett_docsis_bpkmattr_tekp);
255 tekp_tvb = tvb_new_subset (tvb, pos, length, length);
256 dissect_attrs (tekp_tvb, pinfo, tekp_tree);
262 proto_tree_add_item (tree, hf_docsis_bpkmattr_cbc_iv, tvb, pos,
265 THROW (ReportedBoundsError);
267 case BPKM_ERROR_CODE:
269 proto_tree_add_item (tree, hf_docsis_bpkmattr_error_code, tvb,
272 THROW (ReportedBoundsError);
275 proto_tree_add_item (tree, hf_docsis_bpkmattr_ca_cert, tvb, pos,
279 proto_tree_add_item (tree, hf_docsis_bpkmattr_cm_cert, tvb, pos,
282 case BPKM_SEC_CAPABILITIES:
284 proto_tree_add_text (tree, tvb, pos, length,
285 "19 Security Capabilities");
287 proto_item_add_subtree (scap_it, ett_docsis_bpkmattr_scap);
288 scap_tvb = tvb_new_subset (tvb, pos, length, length);
289 dissect_attrs (scap_tvb, pinfo, scap_tree);
291 case BPKM_CRYPTO_SUITE:
293 proto_tree_add_item (tree, hf_docsis_bpkmattr_crypto_suite, tvb,
296 THROW (ReportedBoundsError);
298 case BPKM_CRYPTO_SUITE_LIST:
299 proto_tree_add_item (tree, hf_docsis_bpkmattr_crypto_suite_list,
300 tvb, pos, length, FALSE);
302 case BPKM_BPI_VERSION:
304 proto_tree_add_item (tree, hf_docsis_bpkmattr_bpi_version, tvb,
307 THROW (ReportedBoundsError);
309 case BPKM_SA_DESCRIPTOR:
311 proto_tree_add_text (tree, tvb, pos, length, "23 SA Descriptor");
313 proto_item_add_subtree (sadsc_it, ett_docsis_bpkmattr_sadsc);
314 sadsc_tvb = tvb_new_subset (tvb, pos, length, length);
315 dissect_attrs (sadsc_tvb, pinfo, sadsc_tree);
319 proto_tree_add_item (tree, hf_docsis_bpkmattr_sa_type, tvb, pos,
322 THROW (ReportedBoundsError);
326 proto_tree_add_text (tree, tvb, pos, length, "25 SA Query");
328 proto_item_add_subtree (saqry_it, ett_docsis_bpkmattr_saqry);
329 saqry_tvb = tvb_new_subset (tvb, pos, length, length);
330 dissect_attrs (saqry_tvb, pinfo, saqry_tree);
332 case BPKM_SA_QUERY_TYPE:
334 proto_tree_add_item (tree, hf_docsis_bpkmattr_sa_query_type, tvb,
337 THROW (ReportedBoundsError);
339 case BPKM_IP_ADDRESS:
341 proto_tree_add_item (tree, hf_docsis_bpkmattr_ip_address, tvb,
344 THROW (ReportedBoundsError);
346 case BPKM_VENDOR_DEFINED:
347 proto_tree_add_item (tree, hf_docsis_bpkmattr_vendor_def, tvb, pos,
349 case BPKM_DNLD_PARAMS:
351 proto_tree_add_text (tree, tvb, pos, length,
352 "28 Download Parameters");
354 proto_item_add_subtree (dnld_it, ett_docsis_bpkmattr_dnld);
355 dnld_tvb = tvb_new_subset (tvb, pos, length, length);
356 dissect_attrs (dnld_tvb, pinfo, dnld_tree);
359 proto_tree_add_item (tree, hf_docsis_bpkmattr_vendor_def, tvb, pos,
363 pos += length; /* switch */
368 dissect_bpkmattr (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
372 proto_tree *bpkmattr_tree;
377 proto_tree_add_protocol_format (tree, proto_docsis_bpkmattr, tvb, 0, -1,
379 bpkmattr_tree = proto_item_add_subtree (it, ett_docsis_bpkmattr);
380 dissect_attrs (tvb, pinfo, bpkmattr_tree);
387 /* Register the protocol with Ethereal */
389 /* this format is require because a script is used to build the C function
390 that calls all the protocol registration.
395 proto_register_docsis_bpkmattr (void)
398 /* Setup list of header fields See Section 1.6.1 for details*/
399 static hf_register_info hf[] = {
400 {&hf_docsis_bpkmattr,
401 {"BPKM Attributes", "docsis.bpkmattr",
402 FT_BYTES, BASE_HEX, NULL, 0x0,
403 "BPKM Attributes", HFILL}
405 {&hf_docsis_bpkmattr_serial_num,
406 {"1 Serial Number", "docsis.bpkmattr.serialnum",
407 FT_STRING, BASE_DEC, NULL, 0x0,
408 "Serial Number", HFILL}
410 {&hf_docsis_bpkmattr_manf_id,
411 {"2 Manufacturer Id", "docsis.bpkmattr.manfid",
412 FT_BYTES, BASE_HEX, NULL, 0x0,
413 "Manufacturer Id", HFILL}
415 {&hf_docsis_bpkmattr_mac_addr,
416 {"3 Mac Address", "docsis.bpkmattr.macaddr",
417 FT_ETHER, BASE_HEX, NULL, 0x0,
418 "Mac Address", HFILL}
420 {&hf_docsis_bpkmattr_rsa_pub_key,
421 {"4 RSA Public Key", "docsis.bpkmattr.rsa_pub_key",
422 FT_BYTES, BASE_HEX, NULL, 0x0,
423 "RSA Public Key", HFILL}
425 {&hf_docsis_bpkmattr_cm_id,
426 {"5 CM Identification", "docsis.bpkmattr.cmid",
427 FT_BYTES, BASE_HEX, NULL, 0x0,
428 "CM Identification", HFILL}
430 {&hf_docsis_bpkmattr_display_str,
431 {"6 Display String", "docsis.bpkmattr.dispstr",
432 FT_STRING, BASE_DEC, NULL, 0x0,
433 "Display String", HFILL}
435 {&hf_docsis_bpkmattr_auth_key,
436 {"7 Auth Key", "docsis.bpkmattr.auth_key",
437 FT_BYTES, BASE_HEX, NULL, 0x0,
440 {&hf_docsis_bpkmattr_tek,
441 {"8 Traffic Encryption Key", "docsis.bpkmattr.tek",
442 FT_BYTES, BASE_HEX, NULL, 0x0,
443 "Traffic Encryption Key", HFILL}
445 {&hf_docsis_bpkmattr_key_life,
446 {"9 Key Lifetime (s)", "docsis.bpkmattr.keylife",
447 FT_UINT32, BASE_DEC, NULL, 0x0,
448 "Key Lifetime (s)", HFILL}
450 {&hf_docsis_bpkmattr_key_seq,
451 {"10 Key Sequence Number", "docsis.bpkmattr.keyseq",
452 FT_UINT8, BASE_DEC, NULL, 0x0,
453 "Key Sequence Number", HFILL}
455 {&hf_docsis_bpkmattr_hmac_digest,
456 {"11 HMAC Digest", "docsis.bpkmattr.hmacdigest",
457 FT_BYTES, BASE_HEX, NULL, 0x0,
458 "HMAC Digest", HFILL}
460 {&hf_docsis_bpkmattr_said,
461 {"12 SAID", "docsis.bpkmattr.said",
462 FT_UINT16, BASE_DEC, NULL, 0x0,
463 "Security Association ID", HFILL}
465 {&hf_docsis_bpkmattr_tek_params,
466 {"13 TEK Parameters", "docsis.bpkmattr.tekparams",
467 FT_BYTES, BASE_HEX, NULL, 0x0,
468 "TEK Parameters", HFILL}
470 {&hf_docsis_bpkmattr_cbc_iv,
471 {"14 CBC IV", "docsis.bpkmattr.cbciv",
472 FT_BYTES, BASE_HEX, NULL, 0x0,
473 "Cypher Block Chaining", HFILL}
475 {&hf_docsis_bpkmattr_error_code,
476 {"16 Error Code", "docsis.bpkmattr.errcode",
477 FT_UINT8, BASE_DEC, VALS (error_code_vals), 0x0,
480 {&hf_docsis_bpkmattr_vendor_def,
481 {"127 Vendor Defined", "docsis.bpkmattr.vendordef",
482 FT_BYTES, BASE_HEX, NULL, 0x0,
483 "Vendor Defined", HFILL}
485 {&hf_docsis_bpkmattr_ca_cert,
486 {"17 CA Certificate", "docsis.bpkmattr.cacert",
487 FT_BYTES, BASE_HEX, NULL, 0x0,
488 "CA Certificate", HFILL}
490 {&hf_docsis_bpkmattr_cm_cert,
491 {"18 CM Certificate", "docsis.bpkmattr.cmcert",
492 FT_BYTES, BASE_HEX, NULL, 0x0,
493 "CM Certificate", HFILL}
495 {&hf_docsis_bpkmattr_security_cap,
496 {"19 Security Capabilities", "docsis.bpkmattr.seccap",
497 FT_BYTES, BASE_HEX, NULL, 0x0,
498 "Security Capabilities", HFILL}
500 {&hf_docsis_bpkmattr_crypto_suite,
501 {"20 Cryptographic Suite", "docsis.bpkmattr.cryptosuite",
502 FT_UINT16, BASE_HEX, VALS(crypto_suite_attr_vals), 0x0,
503 "Cryptographic Suite", HFILL}
505 {&hf_docsis_bpkmattr_crypto_suite_list,
506 {"21 Cryptographic Suite List", "docsis.bpkmattr.crypto_suite_lst",
507 FT_BYTES, BASE_HEX, NULL, 0x0,
508 "Cryptographic Suite", HFILL}
510 {&hf_docsis_bpkmattr_bpi_version,
511 {"22 BPI Version", "docsis.bpkmattr.bpiver",
512 FT_UINT8, BASE_DEC, VALS (bpi_ver_vals), 0x0,
513 "BPKM Attributes", HFILL}
515 {&hf_docsis_bpkmattr_sa_descr,
516 {"23 SA Descriptor", "docsis.bpkmattr.sadescr",
517 FT_BYTES, BASE_HEX, NULL, 0x0,
518 "SA Descriptor", HFILL}
520 {&hf_docsis_bpkmattr_sa_type,
521 {"24 SA Type", "docsis.bpkmattr.satype",
522 FT_UINT8, BASE_DEC, NULL, 0x0,
525 {&hf_docsis_bpkmattr_sa_query,
526 {"25 SA Query", "docsis.bpkmattr.saquery",
527 FT_BYTES, BASE_HEX, NULL, 0x0,
530 {&hf_docsis_bpkmattr_sa_query_type,
531 {"26 SA Query Type", "docsis.bpkmattr.saquery_type",
532 FT_UINT8, BASE_HEX, NULL, 0x0,
533 "SA Query Type", HFILL}
535 {&hf_docsis_bpkmattr_ip_address,
536 {"27 IP Address", "docsis.bpkmattr.ipaddr",
537 FT_IPv4, BASE_DEC, NULL, 0x0,
540 {&hf_docsis_bpkmattr_download_param,
541 {"28 Download Parameters", "docsis.bpkmattr.dnld_params",
542 FT_BYTES, BASE_HEX, NULL, 0x0,
543 "Download Parameters", HFILL}
547 /* Setup protocol subtree array */
548 static gint *ett[] = {
549 &ett_docsis_bpkmattr,
550 &ett_docsis_bpkmattr_cmid,
551 &ett_docsis_bpkmattr_scap,
552 &ett_docsis_bpkmattr_tekp,
553 &ett_docsis_bpkmattr_sadsc,
554 &ett_docsis_bpkmattr_saqry,
555 &ett_docsis_bpkmattr_dnld
558 /* Register the protocol name and description */
559 proto_docsis_bpkmattr =
560 proto_register_protocol
561 ("DOCSIS Baseline Privacy Key Management Attributes", "DOCSIS BPKM-ATTR",
564 /* Required function calls to register the header fields and subtrees used */
565 proto_register_field_array (proto_docsis_bpkmattr, hf, array_length (hf));
566 proto_register_subtree_array (ett, array_length (ett));
568 register_dissector ("docsis_bpkmattr", dissect_bpkmattr,
569 proto_docsis_bpkmattr);
573 /* If this dissector uses sub-dissector registration add a registration routine.
574 This format is required because a script is used to find these routines and
575 create the code that calls these routines.
578 proto_reg_handoff_docsis_bpkmattr (void)
580 dissector_handle_t docsis_bpkmattr_handle;
582 docsis_bpkmattr_handle = find_dissector ("docsis_bpkmattr");
583 dissector_add ("docsis", 0xFE, docsis_bpkmattr_handle);