1 /* packet-zbee-nwk.h
2  * Dissector routines for the ZigBee Network Layer (NWK)
3  * By Owen Kirby <osk@exegin.com>
4  * Copyright 2009 Exegin Technologies Limited
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12 #ifndef PACKET_ZBEE_NWK_H
13 #define PACKET_ZBEE_NWK_H
14 
15 /*  ZigBee NWK FCF fields */
16 #define ZBEE_NWK_FCF_FRAME_TYPE             0x0003
17 #define ZBEE_NWK_FCF_VERSION                0x003C
18 #define ZBEE_NWK_FCF_DISCOVER_ROUTE         0x00C0
19 #define ZBEE_NWK_FCF_MULTICAST              0x0100  /* ZigBee 2006 and Later */
20 #define ZBEE_NWK_FCF_SECURITY               0x0200
21 #define ZBEE_NWK_FCF_SOURCE_ROUTE           0x0400  /* ZigBee 2006 and Later */
22 #define ZBEE_NWK_FCF_EXT_DEST               0x0800  /* ZigBee 2006 and Later */
23 #define ZBEE_NWK_FCF_EXT_SOURCE             0x1000  /* ZigBee 2006 and Later */
24 #define ZBEE_NWK_FCF_END_DEVICE_INITIATOR   0x2000  /* ZigBee PRO r21 */
25 
26 /*  ZigBee NWK FCF Frame Types */
27 #define ZBEE_NWK_FCF_DATA                   0x0000
28 #define ZBEE_NWK_FCF_CMD                    0x0001
29 #define ZBEE_NWK_FCF_INTERPAN               0x0003
30 
31 /* ZigBee NWK Discovery Modes. */
32 #define ZBEE_NWK_FCF_DISCOVERY_SUPPRESS     0x0000
33 #define ZBEE_NWK_FCF_DISCOVERY_ENABLE       0x0001
34 #define ZBEE_NWK_FCF_DISCOVERY_FORCE        0x0003
35 
36 /* Multicast Control */
37 #define ZBEE_NWK_MCAST_MODE                 0x03    /* ZigBee 2006 and later */
38 #define ZBEE_NWK_MCAST_RADIUS               0x1c    /* ZigBee 2006 and later */
39 #define ZBEE_NWK_MCAST_MAX_RADIUS           0xe0    /* ZigBee 2006 and later */
40 #define ZBEE_NWK_MCAST_MODE_NONMEMBER       0x00    /* ZigBee 2006 and later */
41 #define ZBEE_NWK_MCAST_MODE_MEMBER          0x01    /* ZigBee 2006 and later */
42 
43 /*  ZigBee NWK Command Types */
44 #define ZBEE_NWK_CMD_ROUTE_REQ                  0x01
45 #define ZBEE_NWK_CMD_ROUTE_REPLY                0x02
46 #define ZBEE_NWK_CMD_NWK_STATUS                 0x03
47 #define ZBEE_NWK_CMD_LEAVE                      0x04    /* ZigBee 2006 and Later */
48 #define ZBEE_NWK_CMD_ROUTE_RECORD               0x05    /* ZigBee 2006 and later */
49 #define ZBEE_NWK_CMD_REJOIN_REQ                 0x06    /* ZigBee 2006 and later */
50 #define ZBEE_NWK_CMD_REJOIN_RESP                0x07    /* ZigBee 2006 and later */
51 #define ZBEE_NWK_CMD_LINK_STATUS                0x08    /* ZigBee 2007 and later */
52 #define ZBEE_NWK_CMD_NWK_REPORT                 0x09    /* ZigBee 2007 and later */
53 #define ZBEE_NWK_CMD_NWK_UPDATE                 0x0a    /* ZigBee 2007 and later */
54 #define ZBEE_NWK_CMD_ED_TIMEOUT_REQUEST         0x0b    /* r21 */
55 #define ZBEE_NWK_CMD_ED_TIMEOUT_RESPONSE        0x0c    /* r21 */
56 #define ZBEE_NWK_CMD_LINK_PWR_DELTA             0x0d    /* r22 */
57 
58 /*  ZigBee NWK Route Options Flags */
59 #define ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR        0x80    /* ZigBee 2004 only. */
60 #define ZBEE_NWK_CMD_ROUTE_OPTION_MCAST         0x40    /* ZigBee 2006 and later */
61 #define ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT      0x20    /* ZigBee 2007 and later (route request only). */
62 #define ZBEE_NWK_CMD_ROUTE_OPTION_MANY_MASK     0x18    /* ZigBee 2007 and later (route request only). */
63 #define ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT      0x20    /* ZigBee 2007 and layer (route reply only). */
64 #define ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT      0x10    /* ZigBee 2007 and later (route reply only). */
65 
66 /* Many-to-One modes, ZigBee 2007 and later (route request only). */
67 #define ZBEE_NWK_CMD_ROUTE_OPTION_MANY_NONE     0x00
68 #define ZBEE_NWK_CMD_ROUTE_OPTION_MANY_REC      0x01
69 #define ZBEE_NWK_CMD_ROUTE_OPTION_MANY_NOREC    0x02
70 
71 /*  ZigBee NWK Leave Options Flags */
72 #define ZBEE_NWK_CMD_LEAVE_OPTION_CHILDREN      0x80
73 #define ZBEE_NWK_CMD_LEAVE_OPTION_REQUEST       0x40
74 #define ZBEE_NWK_CMD_LEAVE_OPTION_REJOIN        0x20
75 
76 /* ZigBee NWK Link Status Options. */
77 #define ZBEE_NWK_CMD_LINK_OPTION_LAST_FRAME     0x40
78 #define ZBEE_NWK_CMD_LINK_OPTION_FIRST_FRAME    0x20
79 #define ZBEE_NWK_CMD_LINK_OPTION_COUNT_MASK     0x1f
80 
81 /* ZigBee NWK Link Status cost fields. */
82 #define ZBEE_NWK_CMD_LINK_INCOMMING_COST_MASK   0x07
83 #define ZBEE_NWK_CMD_LINK_OUTGOING_COST_MASK    0x70
84 
85 /* ZigBee NWK Report Options. */
86 #define ZBEE_NWK_CMD_NWK_REPORT_COUNT_MASK      0x1f
87 #define ZBEE_NWK_CMD_NWK_REPORT_ID_MASK         0xe0
88 #define ZBEE_NWK_CMD_NWK_REPORT_ID_PAN_CONFLICT 0x00
89 #define ZBEE_NWK_CMD_NWK_REPORT_ID_ZBOSS_KEY_TRACE 6
90 
91 /* ZigBee NWK Update Options. */
92 #define ZBEE_NWK_CMD_NWK_UPDATE_COUNT_MASK      0x1f
93 #define ZBEE_NWK_CMD_NWK_UPDATE_ID_MASK         0xe0
94 #define ZBEE_NWK_CMD_NWK_UPDATE_ID_PAN_UPDATE   0x00
95 
96 /* ZigBee NWK Values of the Parent Information Bitmask (Table 3.47) */
97 #define ZBEE_NWK_CMD_ED_TIMEO_RSP_PRNT_INFO_MAC_DATA_POLL_KEEPAL_SUPP  0x01
98 #define ZBEE_NWK_CMD_ED_TIMEO_RSP_PRNT_INFO_ED_TIMOU_REQ_KEEPAL_SUPP   0x02
99 #define ZBEE_NWK_CMD_ED_TIMEO_RSP_PRNT_INFO_PWR_NEG_SUPP               0x04
100 
101 /* ZigBee NWK Link Power Delta Options */
102 #define ZBEE_NWK_CMD_NWK_LINK_PWR_DELTA_TYPE_MASK   0x03
103 
104 /* Network Status Code Definitions. */
105 #define ZBEE_NWK_STATUS_NO_ROUTE_AVAIL      0x00
106 #define ZBEE_NWK_STATUS_TREE_LINK_FAIL      0x01
107 #define ZBEE_NWK_STATUS_NON_TREE_LINK_FAIL  0x02
108 #define ZBEE_NWK_STATUS_LOW_BATTERY         0x03
109 #define ZBEE_NWK_STATUS_NO_ROUTING          0x04
110 #define ZBEE_NWK_STATUS_NO_INDIRECT         0x05
111 #define ZBEE_NWK_STATUS_INDIRECT_EXPIRE     0x06
112 #define ZBEE_NWK_STATUS_DEVICE_UNAVAIL      0x07
113 #define ZBEE_NWK_STATUS_ADDR_UNAVAIL        0x08
114 #define ZBEE_NWK_STATUS_PARENT_LINK_FAIL    0x09
115 #define ZBEE_NWK_STATUS_VALIDATE_ROUTE      0x0a
116 #define ZBEE_NWK_STATUS_SOURCE_ROUTE_FAIL   0x0b
117 #define ZBEE_NWK_STATUS_MANY_TO_ONE_FAIL    0x0c
118 #define ZBEE_NWK_STATUS_ADDRESS_CONFLICT    0x0d
119 #define ZBEE_NWK_STATUS_VERIFY_ADDRESS      0x0e
120 #define ZBEE_NWK_STATUS_PANID_UPDATE        0x0f
121 #define ZBEE_NWK_STATUS_ADDRESS_UPDATE      0x10
122 #define ZBEE_NWK_STATUS_BAD_FRAME_COUNTER   0x11
123 #define ZBEE_NWK_STATUS_BAD_KEY_SEQNO       0x12
124 #define ZBEE_NWK_STATUS_UNKNOWN_COMMAND     0x13
125 
126 #define ZBEE_SEC_CONST_KEYSIZE              16
127 
128 typedef struct{
129     gboolean    security;
130     gboolean    discovery;
131     gboolean    multicast;          /* ZigBee 2006 and Later */
132     gboolean    route;              /* ZigBee 2006 and Later */
133     gboolean    ext_dst;            /* ZigBee 2006 and Later */
134     gboolean    ext_src;            /* ZigBee 2006 and Later */
135     guint16     type;
136     guint8      version;
137 
138     guint16     dst;
139     guint16     src;
140     guint64     dst64;              /* ZigBee 2006 and Later */
141     guint64     src64;              /* ZigBee 2006 and Later */
142     guint8      radius;
143     guint8      seqno;
144 
145     guint8      mcast_mode;         /* ZigBee 2006 and Later */
146     guint8      mcast_radius;       /* ZigBee 2006 and Later */
147     guint8      mcast_max_radius;   /* ZigBee 2006 and Later */
148 
149     guint8      payload_offset;
150     guint8      payload_len;
151 
152     guint16     cluster_id;     /* an application-specific message identifier that
153                                  * happens to be included in the transport (APS) layer header.
154                                  */
155 
156     void        *private_data;  /* For ZigBee (sub)dissector specific data */
157 } zbee_nwk_packet;
158 
159 /* Key used for link key hash table. */
160 typedef struct {
161     guint64     lt_addr64; /* lesser than address */
162     guint64     gt_addr64; /* greater than address */
163 } table_link_key_t;
164 
165 /* Values in the key rings. */
166 typedef struct {
167     guint       frame_num;
168     gchar      *label;
169     guint8      key[ZBEE_SEC_CONST_KEYSIZE];
170 } key_record_t;
171 
172 typedef struct {
173     gint                    src_pan;    /* source pan */
174     gint                    src;        /* short source address from nwk */
175 #if 0
176     gint                    ieee_src;   /* short source address from mac */
177 #endif
178     ieee802154_map_rec     *map_rec;    /* extended src from nwk */
179     key_record_t           *nwk;        /* Network key found for this packet */
180     key_record_t           *link;       /* Link key found for this packet */
181 } zbee_nwk_hints_t;
182 
183 extern ieee802154_map_tab_t zbee_nwk_map;
184 extern GHashTable *zbee_table_nwk_keyring;
185 extern GHashTable *zbee_table_link_keyring;
186 
187 /* Key Types */
188 #define ZBEE_USER_KEY 0x01
189 
190 /* ZigBee PRO beacons */
191 #define ZBEE_NWK_BEACON_PROTOCOL_ID            0x00
192 #define ZBEE_NWK_BEACON_STACK_PROFILE        0x000f
193 #define ZBEE_NWK_BEACON_PROTOCOL_VERSION     0x00f0
194 #define ZBEE_NWK_BEACON_ROUTER_CAPACITY      0x0400
195 #define ZBEE_NWK_BEACON_NETWORK_DEPTH        0x7800
196 #define ZBEE_NWK_BEACON_END_DEVICE_CAPACITY  0x8000
197 #define ZBEE_NWK_BEACON_LENGTH                   15
198 
199 /* ZigBee IP beacons */
200 #define ZBEE_IP_BEACON_PROTOCOL_ID             0x02
201 #define ZBEE_IP_BEACON_ALLOW_JOIN              0x01
202 #define ZBEE_IP_BEACON_ROUTER_CAPACITY         0x02
203 #define ZBEE_IP_BEACON_HOST_CAPACITY           0x04
204 #define ZBEE_IP_BEACON_UNSECURE                0x80 /* Undocumented bit for test networks. */
205 
206 #define ZBEE_IP_BEACON_TLV_LENGTH_MASK         0x0f
207 #define ZBEE_IP_BEACON_TLV_TYPE_MASK           0xf0
208 #define ZBEE_IP_BEACON_TLV_TYPE_LFDI           0x0
209 
210 #endif /* PACKET_ZBEE_NWK_H */
211 
212 /*
213  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
214  *
215  * Local variables:
216  * c-basic-offset: 4
217  * tab-width: 8
218  * indent-tabs-mode: nil
219  * End:
220  *
221  * vi: set shiftwidth=4 tabstop=8 expandtab:
222  * :indentSize=4:tabSize=8:noTabs=true:
223  */
224