| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
packet-rf4ce-secur.h
1/* packet-rf4ce-secur.h
2 * Security related functions and objects for RF4CE dissector
3 * Copyright (C) Atmosic 2023
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12#ifndef PACKET_RF4CE_SECUR_H
13#define PACKET_RF4CE_SECUR_H
14
15#include <stdbool.h>
16#include <epan/packet.h>
17#include <epan/expert.h>
18#include <epan/uat.h>
19
20#define RF4CE_IEEE_ADDR_LEN 8
21#define RF4CE_SHORT_ADDR_LEN 2
22
23#define RF4CE_MIN_NWK_LENGTH 5
24#define RF4CE_MAX_NWK_LENGTH 148
25
26#define RF4CE_VENDOR_SECRET_STORAGE_SIZE 64
27#define RF4CE_NWK_KEY_STORAGE_SIZE 64
28#define RF4CE_ADDR_TABLE_SIZE (RF4CE_NWK_KEY_STORAGE_SIZE * 2)
29
30#define RF4CE_NWK_KEY_SEED_DATA_LENGTH 80
31
32#define RF4CE_CCM_M 4
33#define RF4CE_CCM_L 2
34#define RF4CE_CCM_NONCE_LEN (15 - RF4CE_CCM_L)
35#define RF4CE_SECUR_CONTROL 5
36#define SEC_STR_LEN 16
37#define KEY_LEN SEC_STR_LEN
38
39 typedef struct keypair_context_s {
40 uint8_t nwk_key_seed_latest[RF4CE_NWK_KEY_SEED_DATA_LENGTH];
41 uint8_t nwk_key_seed_prev[RF4CE_NWK_KEY_SEED_DATA_LENGTH];
42 uint8_t nwk_key_seed[RF4CE_NWK_KEY_SEED_DATA_LENGTH];
43 uint8_t controller_addr[RF4CE_IEEE_ADDR_LEN];
44 uint8_t target_addr[RF4CE_IEEE_ADDR_LEN];
45 uint8_t nwk_key_exchange_transfer_expected;
46 uint8_t nwk_key_exchange_transfer_received;
47} keypair_context_t;
48
49#define RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_A_LENGTH 8
50#define RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_B_LENGTH 8
51
52#define RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_AB_LENGTH \
53 (RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_A_LENGTH \
54 + RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_B_LENGTH)
55
56#define RF4CE_PROFILE_CMD_KEY_EXCHANGE_TAG_A_LENGTH 4
57#define RF4CE_PROFILE_CMD_KEY_EXCHANGE_TAG_B_LENGTH 4
58
59#define RF4CE_KEY_EXCHANGE_CONTEXT_LENGTH 9
60#define RF4CE_KEY_EXCHANGE_LABEL_LENGTH (2 * (RF4CE_IEEE_ADDR_LEN))
61
62#define RF4CE_CMAC_ARG_2_LENGTH \
63 (RF4CE_KEY_EXCHANGE_CONTEXT_LENGTH \
64 + RF4CE_KEY_EXCHANGE_LABEL_LENGTH \
65 + KEY_LEN)
66
67/* RF4CE GDP 2.0 spec, part 7.4.2 Key generation
68 * Context shall be set to the ASCII representation of the nine character string (including a space
69 * after "RF4CE" but without quotes and without null termination) "RF4CE GDP".
70 */
71#define CONTEXT_STR "RF4CE GDP"
72#define CONTEXT_STR_LEN 9
73
74 extern uint8_t DEFAULT_SECRET[SEC_STR_LEN];
75
76 typedef struct key_exchange_context_s {
77 uint8_t rand_a[RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_A_LENGTH];
78 uint8_t rand_b[RF4CE_PROFILE_CMD_KEY_EXCHANGE_RAND_B_LENGTH];
79 uint8_t mac_a[RF4CE_IEEE_ADDR_LEN]; /* target address */
80 uint8_t mac_b[RF4CE_IEEE_ADDR_LEN]; /* controller address */
81 bool is_proc_started;
82} key_exchange_context_t;
83
84 void rf4ce_aes_cmac(unsigned char *input, unsigned long length, unsigned char *key, unsigned char *mac_value);
85
86 typedef struct addr_entry_s {
87 uint8_t ieee_addr[RF4CE_IEEE_ADDR_LEN];
88 uint16_t short_addr;
89 bool is_used;
90} addr_entry_t;
91
92 typedef struct nwk_key_entry_s {
93 uint8_t nwk_key[KEY_LEN];
94 addr_entry_t *controller_addr_ent;
95 addr_entry_t *target_addr_ent;
96 bool key_from_gui;
97 bool is_used;
98 bool is_pairing_key;
99} nwk_key_entry_t;
100
101 typedef struct vendor_secret_entry_s {
102 uint8_t secret[SEC_STR_LEN];
103 bool is_used;
104} vendor_secret_entry_t;
105
106 typedef struct uat_security_record_s {
107 char *sec_str;
108 uint8_t type;
109 char *label;
110} uat_security_record_t;
111
112 void keypair_context_init(const uint8_t *controller_ieee, const uint8_t *target_ieee, uint8_t expected_transfer_count);
113 void keypair_context_update_seed(uint8_t *seed, uint8_t seed_seqn);
114
115 void nwk_key_storage_add_entry(uint8_t *nwk_key, addr_entry_t *controller_addr_ent, addr_entry_t *target_addr_ent, bool key_from_gui, bool is_pairing_key);
116 void nwk_key_storage_release_entry(uint8_t *nwk_key, bool key_from_gui);
117
118 void rf4ce_addr_table_add_addrs(const void *ieee_addr, uint16_t short_addr);
119 bool rf4ce_addr_table_get_ieee_addr(uint8_t *ieee_addr, packet_info *pinfo, bool is_src);
120 addr_entry_t *rf4ce_addr_table_get_addr_entry_by_ieee(uint8_t *ieee_addr);
121
122 void key_exchange_context_init(void);
123
124 void key_exchange_context_start_procedure(void);
125 void key_exchange_context_stop_procedure(void);
126 bool key_exchange_context_is_procedure_started(void);
127
128 void key_exchange_context_set_rand_a(uint8_t *rand_a);
129 void key_exchange_context_set_rand_b(uint8_t *rand_b);
130
131 void key_exchange_context_set_mac_a(uint8_t *mac_a);
132 void key_exchange_context_set_mac_b(uint8_t *mac_b);
133
134 void key_exchange_calc_key(uint32_t tag_b_pack);
135
136 void vendor_secret_storage_add_entry(uint8_t *secret);
137 void vendor_secret_storage_release_entry(uint8_t *secret);
138
139 void rf4ce_secur_cleanup(void);
140
141 bool decrypt_data(
142 const uint8_t *in,
143 uint8_t *out,
144 uint16_t payload_offset,
145 uint16_t *len,
146 uint8_t src_ieee[RF4CE_IEEE_ADDR_LEN],
147 uint8_t dst_ieee[RF4CE_IEEE_ADDR_LEN]);
148
149#endif /* PACKET_RF4CE_SECUR_H */
expert.h
packet.h
_packet_info
Definition packet_info.h:43
addr_entry_s
Definition packet-rf4ce-secur.h:86
decrypt_data
Definition packet-isakmp.c:2094
input
Definition tvbuff_lz77huff.c:32
key_exchange_context_s
Definition packet-rf4ce-secur.h:76
keypair_context_s
Definition packet-rf4ce-secur.h:39
nwk_key_entry_s
Definition packet-rf4ce-secur.h:92
uat_security_record_s
Definition packet-rf4ce-secur.h:106
vendor_secret_entry_s
Definition packet-rf4ce-secur.h:101
uat.h