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.7 2003/12/13 03:18:37 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_reported_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, -1,
381 bpkmattr_tree = proto_item_add_subtree (it, ett_docsis_bpkmattr);
382 dissect_attrs (tvb, pinfo, bpkmattr_tree);
389 /* Register the protocol with Ethereal */
391 /* this format is require because a script is used to build the C function
392 that calls all the protocol registration.
397 proto_register_docsis_bpkmattr (void)
400 /* Setup list of header fields See Section 1.6.1 for details*/
401 static hf_register_info hf[] = {
402 {&hf_docsis_bpkmattr,
403 {"BPKM Attributes", "docsis.bpkmattr",
404 FT_BYTES, BASE_HEX, NULL, 0x0,
405 "BPKM Attributes", HFILL}
407 {&hf_docsis_bpkmattr_serial_num,
408 {"1 Serial Number", "docsis.bpkmattr.serialnum",
409 FT_STRING, BASE_DEC, NULL, 0x0,
410 "Serial Number", HFILL}
412 {&hf_docsis_bpkmattr_manf_id,
413 {"2 Manufacturer Id", "docsis.bpkmattr.manfid",
414 FT_BYTES, BASE_HEX, NULL, 0x0,
415 "Manufacturer Id", HFILL}
417 {&hf_docsis_bpkmattr_mac_addr,
418 {"3 Mac Address", "docsis.bpkmattr.macaddr",
419 FT_ETHER, BASE_HEX, NULL, 0x0,
420 "Mac Address", HFILL}
422 {&hf_docsis_bpkmattr_rsa_pub_key,
423 {"4 RSA Public Key", "docsis.bpkmattr.rsa_pub_key",
424 FT_BYTES, BASE_HEX, NULL, 0x0,
425 "RSA Public Key", HFILL}
427 {&hf_docsis_bpkmattr_cm_id,
428 {"5 CM Identification", "docsis.bpkmattr.cmid",
429 FT_BYTES, BASE_HEX, NULL, 0x0,
430 "CM Identification", HFILL}
432 {&hf_docsis_bpkmattr_display_str,
433 {"6 Display String", "docsis.bpkmattr.dispstr",
434 FT_STRING, BASE_DEC, NULL, 0x0,
435 "Display String", HFILL}
437 {&hf_docsis_bpkmattr_auth_key,
438 {"7 Auth Key", "docsis.bpkmattr.auth_key",
439 FT_BYTES, BASE_HEX, NULL, 0x0,
442 {&hf_docsis_bpkmattr_tek,
443 {"8 Traffic Encryption Key", "docsis.bpkmattr.tek",
444 FT_BYTES, BASE_HEX, NULL, 0x0,
445 "Traffic Encryption Key", HFILL}
447 {&hf_docsis_bpkmattr_key_life,
448 {"9 Key Lifetime (s)", "docsis.bpkmattr.keylife",
449 FT_UINT32, BASE_DEC, NULL, 0x0,
450 "Key Lifetime (s)", HFILL}
452 {&hf_docsis_bpkmattr_key_seq,
453 {"10 Key Sequence Number", "docsis.bpkmattr.keyseq",
454 FT_UINT8, BASE_DEC, NULL, 0x0,
455 "Key Sequence Number", HFILL}
457 {&hf_docsis_bpkmattr_hmac_digest,
458 {"11 HMAC Digest", "docsis.bpkmattr.hmacdigest",
459 FT_BYTES, BASE_HEX, NULL, 0x0,
460 "HMAC Digest", HFILL}
462 {&hf_docsis_bpkmattr_said,
463 {"12 SAID", "docsis.bpkmattr.said",
464 FT_UINT16, BASE_DEC, NULL, 0x0,
465 "Security Association ID", HFILL}
467 {&hf_docsis_bpkmattr_tek_params,
468 {"13 TEK Parameters", "docsis.bpkmattr.tekparams",
469 FT_BYTES, BASE_HEX, NULL, 0x0,
470 "TEK Parameters", HFILL}
472 {&hf_docsis_bpkmattr_cbc_iv,
473 {"14 CBC IV", "docsis.bpkmattr.cbciv",
474 FT_BYTES, BASE_HEX, NULL, 0x0,
475 "Cypher Block Chaining", HFILL}
477 {&hf_docsis_bpkmattr_error_code,
478 {"16 Error Code", "docsis.bpkmattr.errcode",
479 FT_UINT8, BASE_DEC, VALS (error_code_vals), 0x0,
482 {&hf_docsis_bpkmattr_vendor_def,
483 {"127 Vendor Defined", "docsis.bpkmattr.vendordef",
484 FT_BYTES, BASE_HEX, NULL, 0x0,
485 "Vendor Defined", HFILL}
487 {&hf_docsis_bpkmattr_ca_cert,
488 {"17 CA Certificate", "docsis.bpkmattr.cacert",
489 FT_BYTES, BASE_HEX, NULL, 0x0,
490 "CA Certificate", HFILL}
492 {&hf_docsis_bpkmattr_cm_cert,
493 {"18 CM Certificate", "docsis.bpkmattr.cmcert",
494 FT_BYTES, BASE_HEX, NULL, 0x0,
495 "CM Certificate", HFILL}
497 {&hf_docsis_bpkmattr_security_cap,
498 {"19 Security Capabilities", "docsis.bpkmattr.seccap",
499 FT_BYTES, BASE_HEX, NULL, 0x0,
500 "Security Capabilities", HFILL}
502 {&hf_docsis_bpkmattr_crypto_suite,
503 {"20 Cryptographic Suite", "docsis.bpkmattr.cryptosuite",
504 FT_UINT16, BASE_HEX, VALS(crypto_suite_attr_vals), 0x0,
505 "Cryptographic Suite", HFILL}
507 {&hf_docsis_bpkmattr_crypto_suite_list,
508 {"21 Cryptographic Suite List", "docsis.bpkmattr.crypto_suite_lst",
509 FT_BYTES, BASE_HEX, NULL, 0x0,
510 "Cryptographic Suite", HFILL}
512 {&hf_docsis_bpkmattr_bpi_version,
513 {"22 BPI Version", "docsis.bpkmattr.bpiver",
514 FT_UINT8, BASE_DEC, VALS (bpi_ver_vals), 0x0,
515 "BPKM Attributes", HFILL}
517 {&hf_docsis_bpkmattr_sa_descr,
518 {"23 SA Descriptor", "docsis.bpkmattr.sadescr",
519 FT_BYTES, BASE_HEX, NULL, 0x0,
520 "SA Descriptor", HFILL}
522 {&hf_docsis_bpkmattr_sa_type,
523 {"24 SA Type", "docsis.bpkmattr.satype",
524 FT_UINT8, BASE_DEC, NULL, 0x0,
527 {&hf_docsis_bpkmattr_sa_query,
528 {"25 SA Query", "docsis.bpkmattr.saquery",
529 FT_BYTES, BASE_HEX, NULL, 0x0,
532 {&hf_docsis_bpkmattr_sa_query_type,
533 {"26 SA Query Type", "docsis.bpkmattr.saquery_type",
534 FT_UINT8, BASE_HEX, NULL, 0x0,
535 "SA Query Type", HFILL}
537 {&hf_docsis_bpkmattr_ip_address,
538 {"27 IP Address", "docsis.bpkmattr.ipaddr",
539 FT_IPv4, BASE_DEC, NULL, 0x0,
542 {&hf_docsis_bpkmattr_download_param,
543 {"28 Download Parameters", "docsis.bpkmattr.dnld_params",
544 FT_BYTES, BASE_HEX, NULL, 0x0,
545 "Download Parameters", HFILL}
549 /* Setup protocol subtree array */
550 static gint *ett[] = {
551 &ett_docsis_bpkmattr,
552 &ett_docsis_bpkmattr_cmid,
553 &ett_docsis_bpkmattr_scap,
554 &ett_docsis_bpkmattr_tekp,
555 &ett_docsis_bpkmattr_sadsc,
556 &ett_docsis_bpkmattr_saqry,
557 &ett_docsis_bpkmattr_dnld
560 /* Register the protocol name and description */
561 proto_docsis_bpkmattr =
562 proto_register_protocol
563 ("DOCSIS Baseline Privacy Key Management Attributes", "DOCSIS BPKM-ATTR",
566 /* Required function calls to register the header fields and subtrees used */
567 proto_register_field_array (proto_docsis_bpkmattr, hf, array_length (hf));
568 proto_register_subtree_array (ett, array_length (ett));
570 register_dissector ("docsis_bpkmattr", dissect_bpkmattr,
571 proto_docsis_bpkmattr);
575 /* If this dissector uses sub-dissector registration add a registration routine.
576 This format is required because a script is used to find these routines and
577 create the code that calls these routines.
580 proto_reg_handoff_docsis_bpkmattr (void)
582 dissector_handle_t docsis_bpkmattr_handle;
584 docsis_bpkmattr_handle = find_dissector ("docsis_bpkmattr");
585 dissector_add ("docsis", 0xFE, docsis_bpkmattr_handle);