zbee-zcl-se: Implemented zigbee zcl se metering dissector
[metze/wireshark/wip.git] / epan / dissectors / packet-zbee-zcl-se.c
1 /* packet-zbee-zcl-se.c
2  * Dissector routines for the ZigBee ZCL SE clusters like
3  * Messaging
4  * By Fabio Tarabelloni <fabio.tarabelloni@reloc.it>
5  * Copyright 2013 RELOC s.r.l.
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 /*  Include Files */
27 #include "config.h"
28
29
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
32 #include <epan/expert.h>
33 #include <epan/to_str.h>
34
35 #include "packet-zbee.h"
36 #include "packet-zbee-aps.h"
37 #include "packet-zbee-zcl.h"
38 #include "packet-zbee-security.h"
39
40 /* ########################################################################## */
41 /* #### common to all SE clusters ########################################### */
42 /* ########################################################################## */
43
44 #define ZBEE_ZCL_SE_ATTR_REPORT_PENDING                     0x00
45 #define ZBEE_ZCL_SE_ATTR_REPORT_COMPLETE                    0x01
46
47 static const value_string zbee_zcl_se_reporting_status_names[] = {
48     { ZBEE_ZCL_SE_ATTR_REPORT_PENDING,                   "Pending" },
49     { ZBEE_ZCL_SE_ATTR_REPORT_COMPLETE,                  "Complete" },
50     { 0, NULL }
51 };
52
53 /*************************/
54 /* Global Variables      */
55 /*************************/
56
57 /* ########################################################################## */
58 /* #### (0x0702) METERING CLUSTER ########################################## */
59 /* ########################################################################## */
60
61 /* Attributes */
62 #define zbee_zcl_met_attr_names_VALUE_STRING_LIST(XXX) \
63 /* Client: Notification AttributeSet / Server: Reading Information Set */ \
64     XXX(ZBEE_ZCL_ATTR_ID_MET_FUNC_NOTI_FLAGS_CUR_SUM_DEL,       0x0000, "Client: Functional Notification Flags / Server: Current Summation Delivered" ) \
65     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS2_CUR_SUM_RECV,           0x0001, "Client: Notification Flag 2 / Server: Current Summation Received" ) \
66     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS3_CUR_MAX_DE_DEL,         0x0002, "Client: Notification Flag 3 / Server: Current Max Demand Delivered" ) \
67     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS4_CUR_MAX_DE_RECV,        0x0003, "Client: Notification Flag 4 / Server: Current Max Demand Received" ) \
68     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS5_DFT_SUM,                0x0004, "Client: Notification Flag 5 / Server: DFTSummation" ) \
69     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS6_DAI_FREE_TIME,          0x0005, "Client: Notification Flag 6 / Server: Daily Freeze Time" ) \
70     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS7_POW_FAC,                0x0006, "Client: Notification Flag 7 / Server: Power Factor" ) \
71     XXX(ZBEE_ZCL_ATTR_ID_MET_NOT_FLAGS8_READ_SNAP_TIME,         0x0007, "Client: Notification Flag 8 / Server: Reading Snapshot Time" ) \
72     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_MAX_DEMAND_DEL_TIME,           0x0008, "Current Max Demand Delivered Time" ) \
73     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_MAX_DEMAND_RECV_TIME,          0x0009, "Current Max Demand Received Time" ) \
74     XXX(ZBEE_ZCL_ATTR_ID_MET_DEFAULT_UPDATE_PERIOD,             0x000A, "Default Update Period" ) \
75     XXX(ZBEE_ZCL_ATTR_ID_MET_FAST_POLL_UPDATE_PERIOD,           0x000B, "Fast Poll Update Period" ) \
76     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_BLOCK_PER_CON_DEL,             0x000C, "Current Block Period Consumption Delivered" ) \
77     XXX(ZBEE_ZCL_ATTR_ID_MET_DAILY_CON_TARGET,                  0x000D, "Daily Consumption Target" ) \
78     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_BLOCK,                     0x000E, "Current Block" ) \
79     XXX(ZBEE_ZCL_ATTR_ID_MET_PROFILE_INTERVAL_PERIOD,           0x000F, "Profile Interval Period" ) \
80 /*     XXX(ZBEE_ZCL_ATTR_ID_MET_DEPRECATED,                        0x0010, "Deprecated" }, */ \
81     XXX(ZBEE_ZCL_ATTR_ID_MET_PRESET_READING_TIME,               0x0011, "Preset Reading Time" ) \
82     XXX(ZBEE_ZCL_ATTR_ID_MET_VOLUME_PER_REPORT,                 0x0012, "Volume Per Report" ) \
83     XXX(ZBEE_ZCL_ATTR_ID_MET_FLOW_RESTRICTION,                  0x0013, "Flow Restriction" ) \
84     XXX(ZBEE_ZCL_ATTR_ID_MET_SUPPLY_STATUS,                     0x0014, "Supply Status" ) \
85     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_INLET_ENER_CAR_SUM,            0x0015, "Current Inlet Energy Carrier Summation" ) \
86     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_OUTLET_ENER_CAR_SUM,           0x0016, "Current Outlet Energy Carrier Summation" ) \
87     XXX(ZBEE_ZCL_ATTR_ID_MET_INLET_TEMPERATURE,                 0x0017, "Inlet Temperature" ) \
88     XXX(ZBEE_ZCL_ATTR_ID_MET_OUTLET_TEMPERATURE,                0x0018, "Outlet Temperature" ) \
89     XXX(ZBEE_ZCL_ATTR_ID_MET_CONTROL_TEMPERATURE,               0x0019, "Control Temperature" ) \
90     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_INLET_ENER_CAR_DEM,            0x001A, "Current Inlet Energy Carrier Demand" ) \
91     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_OUTLET_ENER_CAR_DEM,           0x001B, "Current Outlet Energy Carrier Demand" ) \
92     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_BLOCK_CON_DEL,                0x001C, "Previous Block Period Consumption Delivered" ) \
93     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_BLOCL_CON_RECV,               0x001D, "Current Block Period Consumption Received" ) \
94     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_BLOCK_RECEIVED,            0x001E, "Current Block Received" ) \
95     XXX(ZBEE_ZCL_ATTR_ID_MET_DFT_SUMMATION_RECEIVED,            0x001F, "DFT Summation Received" ) \
96     XXX(ZBEE_ZCL_ATTR_ID_MET_ACTIVE_REG_TIER_DEL,               0x0020, "Active Register Tier Delivered" ) \
97     XXX(ZBEE_ZCL_ATTR_ID_MET_ACTIVE_REG_TIER_RECV,              0x0021, "Active Register Tier Received" ) \
98     XXX(ZBEE_ZCL_ATTR_ID_MET_LAST_BLOCK_SWITCH_TIME,            0x0022, "Last Block Switch Time" ) \
99 /* Summation TOU Information Set */ \
100     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_TIER_1_SUM_DEL,            0x0100, "Current Tier 1 Summation Delivered" ) \
101     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_TIER_2_SUM_DEL,            0x0102, "Current Tier 2 Summation Delivered" ) \
102     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_TIER_3_SUM_DEL,            0x0104, "Current Tier 3 Summation Delivered" ) \
103     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_TIER_4_SUM_DEL,            0x0106, "Current Tier 4 Summation Delivered" ) \
104 /* Meter Status Attribute Set */ \
105     XXX(ZBEE_ZCL_ATTR_ID_MET_STATUS,                            0x0200, "Status" ) \
106     XXX(ZBEE_ZCL_ATTR_ID_MET_REMAIN_BAT_LIFE_DAYS,              0x0205, "Remaining Battery Life in Days" ) \
107     XXX(ZBEE_ZCL_ATTR_ID_MET_CURRENT_METER_ID,                  0x0206, "Current Meter ID" ) \
108     XXX(ZBEE_ZCL_ATTR_ID_MET_AMBIENT_CON_IND,                   0x0207, "Ambient Consumption Indicator" ) \
109 /* Formatting */ \
110     XXX(ZBEE_ZCL_ATTR_ID_MET_UNIT_OF_MEASURE,                   0x0300, "Unit of Measure" ) \
111     XXX(ZBEE_ZCL_ATTR_ID_MET_MULTIPLIER,                        0x0301, "Multiplier" ) \
112     XXX(ZBEE_ZCL_ATTR_ID_MET_DIVISOR,                           0x0302, "Divisor" ) \
113     XXX(ZBEE_ZCL_ATTR_ID_MET_SUMMATION_FORMATTING,              0x0303, "Summation Formatting" ) \
114     XXX(ZBEE_ZCL_ATTR_ID_MET_METERING_DEVICE_TYPE,              0x0306, "Metering Device Type" ) \
115     XXX(ZBEE_ZCL_ATTR_ID_MET_SITE_ID,                           0x0307, "Site ID" ) \
116     XXX(ZBEE_ZCL_ATTR_ID_MET_CUSTOMER_ID_NUMBER,                0x0311, "Customer ID Number" ) \
117     XXX(ZBEE_ZCL_ATTR_ID_MET_ALT_UNIT_OF_MEASURE,               0x0312, "Alternative Unit of Measure" ) \
118     XXX(ZBEE_ZCL_ATTR_ID_MET_ALT_CON_FORMATTING,                0x0314, "Alternative Consumption Formatting" ) \
119 /* Historical Consumption Attribute */ \
120     XXX(ZBEE_ZCL_ATTR_ID_MET_INSTANT_DEMAND,                    0x0400, "Instantaneous Demand" ) \
121     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_DAY_CON_DEL,                   0x0401, "Current Day Consumption Delivered" ) \
122     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_CON_DEL,                  0x0403, "Previous Day Consumption Delivered" ) \
123     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_2_DAY_CON_DEL,                0x0420, "Previous Day 2 Consumption Delivered" ) \
124     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_3_DAY_CON_DEL,                0x0422, "Previous Day 3 Consumption Delivered" ) \
125     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_4_DAY_CON_DEL,                0x0424, "Previous Day 4 Consumption Delivered" ) \
126     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_5_DAY_CON_DEL,                0x0426, "Previous Day 5 Consumption Delivered" ) \
127     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_6_DAY_CON_DEL,                0x0428, "Previous Day 6 Consumption Delivered" ) \
128     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_7_DAY_CON_DEL,                0x042A, "Previous Day 7 Consumption Delivered" ) \
129     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_8_DAY_CON_DEL,                0x042C, "Previous Day 8 Consumption Delivered" ) \
130     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_WEEK_CON_DEL,                  0x0430, "Current Week Consumption Delivered" ) \
131     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_CON_DEL,                 0x0432, "Previous Week Consumption Delivered" ) \
132     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_2_CON_DEL,               0x0434, "Previous Week 2 Consumption Delivered" ) \
133     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_3_CON_DEL,               0x0436, "Previous Week 3 Consumption Delivered" ) \
134     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_4_CON_DEL,               0x0438, "Previous Week 4 Consumption Delivered" ) \
135     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_5_CON_DEL,               0x043A, "Previous Week 5 Consumption Delivered" ) \
136     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_MONTH_CON_DEL,                 0x0440, "Current Month Consumption Delivered" ) \
137     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_CON_DEL,                0x0442, "Previous Month Consumption Delivered" ) \
138     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_2_CON_DEL,              0x0444, "Previous Month 2 Consumption Delivered" ) \
139     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_3_CON_DEL,              0x0446, "Previous Month 3 Consumption Delivered" ) \
140     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_4_CON_DEL,              0x0448, "Previous Month 4 Consumption Delivered" ) \
141     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_5_CON_DEL,              0x044A, "Previous Month 5 Consumption Delivered" ) \
142     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_6_CON_DEL,              0x044C, "Previous Month 6 Consumption Delivered" ) \
143     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_7_CON_DEL,              0x044E, "Previous Month 7 Consumption Delivered" ) \
144     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_8_CON_DEL,              0x0450, "Previous Month 8 Consumption Delivered" ) \
145     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_9_CON_DEL,              0x0452, "Previous Month 9 Consumption Delivered" ) \
146     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_10_CON_DEL,             0x0454, "Previous Month 10 Consumption Delivered" ) \
147     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_11_CON_DEL,             0x0456, "Previous Month 11 Consumption Delivered" ) \
148     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_12_CON_DEL,             0x0458, "Previous Month 12 Consumption Delivered" ) \
149     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_13_CON_DEL,             0x045A, "Previous Month 13 Consumption Delivered" ) \
150 /* Supply Limit Attributes */ \
151     XXX(ZBEE_ZCL_ATTR_ID_MET_SUPPLY_TAMPER_STATE,               0x0607, "Supply Tamper State" ) \
152     XXX(ZBEE_ZCL_ATTR_ID_MET_SUPPLY_DEPLETION_STATE,            0x0608, "Supply Depletion State" ) \
153 /* Block Information Attribute Set (Delivered) */ \
154     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_NO_TIER_BLOCK_1_SUM_DEL,       0x0700, "Current No Tier Block 1 Summation Delivered" ) \
155     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_NO_TIER_BLOCK_2_SUM_DEL,       0x0701, "Current No Tier Block 2 Summation Delivered" ) \
156     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_NO_TIER_BLOCK_3_SUM_DEL,       0x0702, "Current No Tier Block 3 Summation Delivered" ) \
157     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_NO_TIER_BLOCK_4_SUM_DEL,       0x0703, "Current No Tier Block 4 Summation Delivered" ) \
158     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_1_BLOCK_1_SUM_DEL,        0x0710, "Current Tier 1 Block 1 Summation Delivered" ) \
159     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_1_BLOCK_2_SUM_DEL,        0x0711, "Current Tier 1 Block 2 Summation Delivered" ) \
160     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_1_BLOCK_3_SUM_DEL,        0x0712, "Current Tier 1 Block 3 Summation Delivered" ) \
161     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_1_BLOCK_4_SUM_DEL,        0x0713, "Current Tier 1 Block 4 Summation Delivered" ) \
162     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_2_BLOCK_1_SUM_DEL,        0x0720, "Current Tier 2 Block 1 Summation Delivered" ) \
163     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_2_BLOCK_2_SUM_DEL,        0x0721, "Current Tier 2 Block 2 Summation Delivered" ) \
164     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_2_BLOCK_3_SUM_DEL,        0x0722, "Current Tier 2 Block 3 Summation Delivered" ) \
165     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_2_BLOCK_4_SUM_DEL,        0x0723, "Current Tier 2 Block 4 Summation Delivered" ) \
166     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_3_BLOCK_1_SUM_DEL,        0x0730, "Current Tier 3 Block 1 Summation Delivered" ) \
167     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_3_BLOCK_2_SUM_DEL,        0x0731, "Current Tier 3 Block 2 Summation Delivered" ) \
168     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_3_BLOCK_3_SUM_DEL,        0x0732, "Current Tier 3 Block 3 Summation Delivered" ) \
169     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_3_BLOCK_4_SUM_DEL,        0x0733, "Current Tier 3 Block 4 Summation Delivered" ) \
170     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_4_BLOCK_1_SUM_DEL,        0x0740, "Current Tier 4 Block 1 Summation Delivered" ) \
171     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_4_BLOCK_2_SUM_DEL,        0x0741, "Current Tier 4 Block 2 Summation Delivered" ) \
172     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_4_BLOCK_3_SUM_DEL,        0x0742, "Current Tier 4 Block 3 Summation Delivered" ) \
173     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_TIER_4_BLOCK_4_SUM_DEL,        0x0743, "Current Tier 4 Block 4 Summation Delivered" ) \
174 /* Meter Billing Attribute Set */ \
175     XXX(ZBEE_ZCL_ATTR_ID_MET_BILL_TO_DATE_DELIVERED,            0x0A00, "Bill To Date Delivered" ) \
176     XXX(ZBEE_ZCL_ATTR_ID_MET_BILL_TO_DATE_TIMESTAMP_DEL,        0x0A01, "BillToDateTimeStampDelivered" ) \
177     XXX(ZBEE_ZCL_ATTR_ID_MET_BILL_DELIVERED_TRAILING_DIGIT,     0x0A04, "Bill Delivered Trailing Digit" ) \
178 /* Alternative Historical Consumption Attribute Set */ \
179     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_DAY_ALT_CON_DEL,               0x0C01, "Current Day Alternative Consumption Delivered" ) \
180     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_ALT_CON_DEL,              0x0C03, "Previous Day Alternative Consumption Delivered" ) \
181     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_2_ALT_CON_DEL,            0x0C20, "Previous Day 2 Alternative Consumption Delivered" ) \
182     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_3_ALT_CON_DEL,            0x0C22, "Previous Day 3 Alternative Consumption Delivered" ) \
183     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_4_ALT_CON_DEL,            0x0C24, "Previous Day 4 Alternative Consumption Delivered" ) \
184     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_5_ALT_CON_DEL,            0x0C26, "Previous Day 5 Alternative Consumption Delivered" ) \
185     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_6_ALT_CON_DEL,            0x0C28, "Previous Day 6 Alternative Consumption Delivered" ) \
186     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_7_ALT_CON_DEL,            0x0C2A, "Previous Day 7 Alternative Consumption Delivered" ) \
187     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_DAY_8_ALT_CON_DEL,            0x0C2C, "Previous Day 8 Alternative Consumption Delivered" ) \
188     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_WEEK_ALT_CON_DEL,              0x0C30, "Current Week Alternative Consumption Delivered" ) \
189     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_ALT_CON_DEL,             0x0C32, "Previous Week Alternative Consumption Delivered" ) \
190     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_2_ALT_CON_DEL,           0x0C34, "Previous Week 2 Alternative Consumption Delivered" ) \
191     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_3_ALT_CON_DEL,           0x0C36, "Previous Week 3 Alternative Consumption Delivered" ) \
192     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_4_ALT_CON_DEL,           0x0C38, "Previous Week 4 Alternative Consumption Delivered" ) \
193     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_WEEK_5_ALT_CON_DEL,           0x0C3A, "Previous Week 5 Alternative Consumption Delivered" ) \
194     XXX(ZBEE_ZCL_ATTR_ID_MET_CUR_MONTH_ALT_CON_DEL,             0x0C40, "Current Month Alternative Consumption Delivered" ) \
195     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_ALT_CON_DEL,            0x0C42, "Previous Month Alternative Consumption Delivered" ) \
196     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_2_ALT_CON_DEL,          0x0C44, "Previous Month 2 Alternative Consumption Delivered" ) \
197     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_3_ALT_CON_DEL,          0x0C46, "Previous Month 3 Alternative Consumption Delivered" ) \
198     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_4_ALT_CON_DEL,          0x0C48, "Previous Month 4 Alternative Consumption Delivered" ) \
199     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_5_ALT_CON_DEL,          0x0C4A, "Previous Month 5 Alternative Consumption Delivered" ) \
200     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_6_ALT_CON_DEL,          0x0C4C, "Previous Month 6 Alternative Consumption Delivered" ) \
201     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_7_ALT_CON_DEL,          0x0C4E, "Previous Month 7 Alternative Consumption Delivered" ) \
202     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_8_ALT_CON_DEL,          0x0C50, "Previous Month 8 Alternative Consumption Delivered" ) \
203     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_9_ALT_CON_DEL,          0x0C52, "Previous Month 9 Alternative Consumption Delivered" ) \
204     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_10_ALT_CON_DEL,         0x0C54, "Previous Month 10 Alternative Consumption Delivered" ) \
205     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_11_ALT_CON_DEL,         0x0C56, "Previous Month 11 Alternative Consumption Delivered" ) \
206     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_12_ALT_CON_DEL,         0x0C58, "Previous Month 12 Alternative Consumption Delivered" ) \
207     XXX(ZBEE_ZCL_ATTR_ID_MET_PREV_MONTH_13_ALT_CON_DEL,         0x0C5A, "Previous Month 13 Alternative Consumption Delivered" ) \
208 /* Smart Energy */ \
209     XXX(ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_MET,             0xFFFE, "Attribute Reporting Status" )
210
211 VALUE_STRING_ENUM(zbee_zcl_met_attr_names);
212 VALUE_STRING_ARRAY(zbee_zcl_met_attr_names);
213 static value_string_ext zbee_zcl_met_attr_names_ext = VALUE_STRING_EXT_INIT(zbee_zcl_met_attr_names);
214
215 /* Server Commands Received */
216 #define zbee_zcl_met_srv_rx_cmd_names_VALUE_STRING_LIST(XXX) \
217     XXX(ZBEE_ZCL_CMD_ID_MET_REQUEST_MIRROR_RSP,                 0x01, "Request Mirror Response" ) \
218     XXX(ZBEE_ZCL_CMD_ID_MET_GET_SNAPSHOT,                       0x06, "Get Snapshot" ) \
219     XXX(ZBEE_ZCL_CMD_ID_MET_GET_SAMPLED_DATA,                   0x08, "Get Sampled Data" ) \
220     XXX(ZBEE_ZCL_CMD_ID_MET_LOCAL_CHANGE_SUPPLY,                0x0C, "Local Change Supply" )
221
222 VALUE_STRING_ENUM(zbee_zcl_met_srv_rx_cmd_names);
223 VALUE_STRING_ARRAY(zbee_zcl_met_srv_rx_cmd_names);
224
225 /* Server Commands Generated */
226 #define zbee_zcl_met_srv_tx_cmd_names_VALUE_STRING_LIST(XXX) \
227     XXX(ZBEE_ZCL_CMD_ID_MET_REQUEST_MIRROR,                     0x01, "Request Mirror" ) \
228     XXX(ZBEE_ZCL_CMD_ID_MET_PUBLISH_SNAPSHOT,                   0x06, "Publish Snapshot" ) \
229     XXX(ZBEE_ZCL_CMD_ID_MET_GET_SAMPLED_DATA_RSP,               0x07, "Get Sampled Data Response" ) \
230     XXX(ZBEE_ZCL_CMD_ID_MET_CONFIGURE_MIRROR,                   0x08, "Configure Mirror" ) \
231     XXX(ZBEE_ZCL_CMD_ID_MET_GET_NOTIFIED_MESSAGE,               0x0B, "Get Notified Message" )
232
233 VALUE_STRING_ENUM(zbee_zcl_met_srv_tx_cmd_names);
234 VALUE_STRING_ARRAY(zbee_zcl_met_srv_tx_cmd_names);
235
236 /*************************/
237 /* Function Declarations */
238 /*************************/
239 void proto_register_zbee_zcl_met(void);
240 void proto_reg_handoff_zbee_zcl_met(void);
241
242 /* Attribute Dissector Helpers */
243 static void dissect_zcl_met_attr_data  (proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type);
244
245 /* Command Dissector Helpers */
246 static void dissect_zcl_met_request_mirror_rsp      (tvbuff_t *tvb, proto_tree *tree, guint *offset);
247 static void dissect_zcl_met_get_snapshot            (tvbuff_t *tvb, proto_tree *tree, guint *offset);
248 static void dissect_zcl_met_get_sampled_data        (tvbuff_t *tvb, proto_tree *tree, guint *offset);
249 static void dissect_zcl_met_local_change_supply     (tvbuff_t *tvb, proto_tree *tree, guint *offset);
250 static void dissect_zcl_met_publish_snapshot        (tvbuff_t *tvb, proto_tree *tree, guint *offset);
251 static void dissect_zcl_met_get_sampled_data_rsp    (tvbuff_t *tvb, proto_tree *tree, guint *offset);
252 static void dissect_zcl_met_configure_mirror        (tvbuff_t *tvb, proto_tree *tree, guint *offset);
253 static void dissect_zcl_met_get_notified_msg        (tvbuff_t *tvb, proto_tree *tree, guint *offset);
254
255 /*************************/
256 /* Global Variables      */
257 /*************************/
258
259 static dissector_handle_t met_handle;
260
261 /* Initialize the protocol and registered fields */
262 static int proto_zbee_zcl_met = -1;
263
264 static int hf_zbee_zcl_met_srv_tx_cmd_id = -1;
265 static int hf_zbee_zcl_met_srv_rx_cmd_id = -1;
266 static int hf_zbee_zcl_met_attr_id = -1;
267 static int hf_zbee_zcl_met_attr_reporting_status = -1;
268 static int hf_zbee_zcl_met_request_mirror_rsp_endpoint_id = -1;
269 static int hf_zbee_zcl_met_get_snapshot_start_time = -1;
270 static int hf_zbee_zcl_met_get_snapshot_end_time = -1;
271 static int hf_zbee_zcl_met_get_snapshot_snapshot_offset = -1;
272 static int hf_zbee_zcl_met_get_snapshot_snapshot_cause = -1;
273 static int hf_zbee_zcl_met_get_sampled_data_sample_id = -1;
274 static int hf_zbee_zcl_met_get_sampled_data_sample_start_time = -1;
275 static int hf_zbee_zcl_met_get_sampled_data_sample_type = -1;
276 static int hf_zbee_zcl_met_get_sampled_data_number_of_samples = -1;
277 static int hf_zbee_zcl_met_local_change_supply_supply_status = -1;
278 static int hf_zbee_zcl_met_publish_snapshot_snapshot_id = -1;
279 static int hf_zbee_zcl_met_publish_snapshot_snapshot_time = -1;
280 static int hf_zbee_zcl_met_publish_snapshot_snapshots_found = -1;
281 static int hf_zbee_zcl_met_publish_snapshot_cmd_index = -1;
282 static int hf_zbee_zcl_met_publish_snapshot_total_commands = -1;
283 static int hf_zbee_zcl_met_publish_snapshot_snapshot_cause = -1;
284 static int hf_zbee_zcl_met_publish_snapshot_snapshot_payload_type = -1;
285 static int hf_zbee_zcl_met_publish_snapshot_snapshot_sub_payload = -1;
286 static int hf_zbee_zcl_met_get_sampled_data_rsp_sample_id = -1;
287 static int hf_zbee_zcl_met_get_sampled_data_rsp_sample_start_time = -1;
288 static int hf_zbee_zcl_met_get_sampled_data_rsp_sample_type = -1;
289 static int hf_zbee_zcl_met_get_sampled_data_rsp_sample_request_interval = -1;
290 static int hf_zbee_zcl_met_get_sampled_data_rsp_sample_number_of_samples = -1;
291 static int hf_zbee_zcl_met_get_sampled_data_rsp_sample_samples = -1;
292 static int hf_zbee_zcl_met_configure_mirror_issuer_event_id = -1;
293 static int hf_zbee_zcl_met_configure_mirror_reporting_interval = -1;
294 static int hf_zbee_zcl_met_configure_mirror_mirror_notification_reporting = -1;
295 static int hf_zbee_zcl_met_configure_mirror_notification_scheme = -1;
296 static int hf_zbee_zcl_met_get_notified_msg_notification_scheme = -1;
297 static int hf_zbee_zcl_met_get_notified_msg_notification_flag_attribute_id = -1;
298 static int hf_zbee_zcl_met_get_notified_msg_notification_flags = -1;
299
300 /* Initialize the subtree pointers */
301 static gint ett_zbee_zcl_met = -1;
302
303 /*************************/
304 /* Function Bodies       */
305 /*************************/
306
307 /**
308  *This function is called by ZCL foundation dissector in order to decode
309  *
310  *@param tree pointer to data tree Wireshark uses to display packet.
311  *@param tvb pointer to buffer containing raw packet.
312  *@param offset pointer to buffer offset
313  *@param attr_id attribute identifier
314  *@param data_type attribute data type
315 */
316 static void
317 dissect_zcl_met_attr_data(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type)
318 {
319     switch (attr_id) {
320         /* applies to all SE clusters */
321         case ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_MET:
322             proto_tree_add_item(tree, hf_zbee_zcl_met_attr_reporting_status, tvb, *offset, 1, ENC_NA);
323             *offset += 1;
324             break;
325
326         default: /* Catch all */
327             dissect_zcl_attr_data(tvb, tree, offset, data_type);
328             break;
329     }
330 } /*dissect_zcl_met_attr_data*/
331
332 /**
333  *ZigBee ZCL Metering cluster dissector for wireshark.
334  *
335  *@param tvb pointer to buffer containing raw packet.
336  *@param pinfo pointer to packet information fields
337  *@param tree pointer to data tree Wireshark uses to display packet.
338 */
339 static int
340 dissect_zbee_zcl_met(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
341 {
342     proto_tree        *payload_tree;
343     zbee_zcl_packet   *zcl;
344     guint             offset = 0;
345     guint8            cmd_id;
346     gint              rem_len;
347
348     /* Reject the packet if data is NULL */
349     if (data == NULL)
350         return 0;
351     zcl = (zbee_zcl_packet *)data;
352     cmd_id = zcl->cmd_id;
353
354     /*  Create a subtree for the ZCL Command frame, and add the command ID to it. */
355     if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) {
356         /* Append the command name to the info column. */
357         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
358             val_to_str_const(cmd_id, zbee_zcl_met_srv_rx_cmd_names, "Unknown Command"),
359             zcl->tran_seqno);
360
361         /* Add the command ID. */
362         proto_tree_add_uint(tree, hf_zbee_zcl_met_srv_rx_cmd_id, tvb, offset, 1, cmd_id);
363
364         /* Check is this command has a payload, than add the payload tree */
365         rem_len = tvb_reported_length_remaining(tvb, ++offset);
366         if (rem_len > 0) {
367             payload_tree = proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_met, NULL, "Payload");
368
369             /* Call the appropriate command dissector */
370             switch (cmd_id) {
371
372                 case ZBEE_ZCL_CMD_ID_MET_REQUEST_MIRROR_RSP:
373                     dissect_zcl_met_request_mirror_rsp(tvb, payload_tree, &offset);
374                     break;
375
376                 case ZBEE_ZCL_CMD_ID_MET_GET_SNAPSHOT:
377                     dissect_zcl_met_get_snapshot(tvb, payload_tree, &offset);
378                     break;
379
380                 case ZBEE_ZCL_CMD_ID_MET_GET_SAMPLED_DATA:
381                     dissect_zcl_met_get_sampled_data(tvb, payload_tree, &offset);
382                     break;
383
384                 case ZBEE_ZCL_CMD_ID_MET_LOCAL_CHANGE_SUPPLY:
385                     dissect_zcl_met_local_change_supply(tvb, payload_tree, &offset);
386                     break;
387
388                 default:
389                     break;
390             }
391         }
392     }
393     else { /* ZBEE_ZCL_FCF_TO_CLIENT */
394         /* Append the command name to the info column. */
395         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
396             val_to_str_const(cmd_id, zbee_zcl_met_srv_tx_cmd_names, "Unknown Command"),
397             zcl->tran_seqno);
398
399         /* Add the command ID. */
400         proto_tree_add_uint(tree, hf_zbee_zcl_met_srv_tx_cmd_id, tvb, offset, 1, cmd_id);
401
402         /* Check is this command has a payload, than add the payload tree */
403         rem_len = tvb_reported_length_remaining(tvb, ++offset);
404         if (rem_len > 0) {
405             payload_tree = proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_met, NULL, "Payload");
406
407             /* Call the appropriate command dissector */
408             switch (cmd_id) {
409
410                 case ZBEE_ZCL_CMD_ID_MET_REQUEST_MIRROR:
411                     /* No payload */
412                     break;
413
414                 case ZBEE_ZCL_CMD_ID_MET_PUBLISH_SNAPSHOT:
415                     dissect_zcl_met_publish_snapshot(tvb, payload_tree, &offset);
416                     break;
417
418                 case ZBEE_ZCL_CMD_ID_MET_GET_SAMPLED_DATA_RSP:
419                     dissect_zcl_met_get_sampled_data_rsp(tvb, payload_tree, &offset);
420                     break;
421
422                 case ZBEE_ZCL_CMD_ID_MET_CONFIGURE_MIRROR:
423                     dissect_zcl_met_configure_mirror(tvb, payload_tree, &offset);
424                     break;
425
426                 case ZBEE_ZCL_CMD_ID_MET_GET_NOTIFIED_MESSAGE:
427                     dissect_zcl_met_get_notified_msg(tvb, payload_tree, &offset);
428                     break;
429
430                 default:
431                     break;
432             }
433         }
434     }
435
436     return tvb_captured_length(tvb);
437 } /*dissect_zbee_zcl_met*/
438
439 /**
440  *This function manages the Request Mirror Response payload
441  *
442  *@param tvb pointer to buffer containing raw packet.
443  *@param tree pointer to data tree Wireshark uses to display packet.
444  *@param offset pointer to offset from caller
445 */
446 static void
447 dissect_zcl_met_request_mirror_rsp(tvbuff_t *tvb, proto_tree *tree, guint *offset)
448 {
449     /* EndPoint ID */
450     proto_tree_add_item(tree, hf_zbee_zcl_met_request_mirror_rsp_endpoint_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
451     *offset += 2;
452 } /*dissect_zcl_met_get_snapshot*/
453
454 /**
455  *This function manages the Get Snapshot payload
456  *
457  *@param tvb pointer to buffer containing raw packet.
458  *@param tree pointer to data tree Wireshark uses to display packet.
459  *@param offset pointer to offset from caller
460 */
461 static void
462 dissect_zcl_met_get_snapshot(tvbuff_t *tvb, proto_tree *tree, guint *offset)
463 {
464     nstime_t start_time;
465     nstime_t end_time;
466     gint rem_len = tvb_reported_length_remaining(tvb, *offset);
467
468     /* Start Time */
469     start_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
470     start_time.nsecs = 0;
471     proto_tree_add_time(tree, hf_zbee_zcl_met_get_snapshot_start_time, tvb, *offset, 4, &start_time);
472     *offset += 4;
473
474     if (rem_len > 9) {
475         /* End Time - not part of SE 1.1b specification */
476         end_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
477         end_time.nsecs = 0;
478         proto_tree_add_time(tree, hf_zbee_zcl_met_get_snapshot_end_time, tvb, *offset, 4, &end_time);
479         *offset += 4;
480     }
481
482     /* Snapshot Offset */
483     proto_tree_add_item(tree, hf_zbee_zcl_met_get_snapshot_snapshot_offset, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
484     *offset += 1;
485
486     /* Snapshot Cause */
487     proto_tree_add_item(tree, hf_zbee_zcl_met_get_snapshot_snapshot_cause, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
488     *offset += 4;
489 } /*dissect_zcl_met_get_snapshot*/
490
491 /**
492  *This function manages the Get Sampled Data payload
493  *
494  *@param tvb pointer to buffer containing raw packet.
495  *@param tree pointer to data tree Wireshark uses to display packet.
496  *@param offset pointer to offset from caller
497 */
498 static void
499 dissect_zcl_met_get_sampled_data(tvbuff_t *tvb, proto_tree *tree, guint *offset)
500 {
501     nstime_t sample_time;
502
503     /* Sample ID */
504     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_sample_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
505     *offset += 2;
506
507     /* Sample Start Time */
508     sample_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
509     sample_time.nsecs = 0;
510     proto_tree_add_time(tree, hf_zbee_zcl_met_get_sampled_data_sample_start_time, tvb, *offset, 4, &sample_time);
511     *offset += 4;
512
513     /* Sample Type */
514     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_sample_type, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
515     *offset += 1;
516
517     /* Number of Samples */
518     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_number_of_samples, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
519     *offset += 2;
520 } /*dissect_zcl_met_get_sampled_data*/
521
522 /**
523  *This function manages the Local Change Supply payload
524  *
525  *@param tvb pointer to buffer containing raw packet.
526  *@param tree pointer to data tree Wireshark uses to display packet.
527  *@param offset pointer to offset from caller
528 */
529 static void
530 dissect_zcl_met_local_change_supply(tvbuff_t *tvb, proto_tree *tree, guint *offset)
531 {
532     /* Proposed Supply Status */
533     proto_tree_add_item(tree, hf_zbee_zcl_met_local_change_supply_supply_status, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
534     *offset += 1;
535 } /*dissect_zcl_met_local_change_supply*/
536
537 /**
538  *This function manages the Publish Snapshot payload
539  *
540  *@param tvb pointer to buffer containing raw packet.
541  *@param tree pointer to data tree Wireshark uses to display packet.
542  *@param offset pointer to offset from caller
543 */
544 static void
545 dissect_zcl_met_publish_snapshot(tvbuff_t *tvb, proto_tree *tree, guint *offset)
546 {
547     nstime_t snapshot_time;
548     gint rem_len;
549
550     /* Snapshot ID */
551     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_snapshot_id, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
552     *offset += 4;
553
554     /* Snapshot Time */
555     snapshot_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
556     snapshot_time.nsecs = 0;
557     proto_tree_add_time(tree, hf_zbee_zcl_met_publish_snapshot_snapshot_time, tvb, *offset, 4, &snapshot_time);
558     *offset += 4;
559
560     /* Total Snapshots Found */
561     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_snapshots_found, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
562     *offset += 1;
563
564     /* Command Index */
565     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_cmd_index, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
566     *offset += 1;
567
568     /* Total Number of Commands */
569     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_total_commands, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
570     *offset += 1;
571
572     /* Snapshot Cause */
573     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_snapshot_cause, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
574     *offset += 4;
575
576     /* Snapshot Payload Type */
577     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_snapshot_payload_type, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
578     *offset += 1;
579
580     /* Snapshot Sub-Payload */
581     rem_len = tvb_reported_length_remaining(tvb, *offset);
582     proto_tree_add_item(tree, hf_zbee_zcl_met_publish_snapshot_snapshot_sub_payload, tvb, *offset, rem_len, ENC_NA);
583     *offset += rem_len;
584 } /*dissect_zcl_met_publish_snapshot*/
585
586 /**
587  *This function manages the Get Sampled Data Response payload
588  *
589  *@param tvb pointer to buffer containing raw packet.
590  *@param tree pointer to data tree Wireshark uses to display packet.
591  *@param offset pointer to offset from caller
592 */
593 static void
594 dissect_zcl_met_get_sampled_data_rsp(tvbuff_t *tvb, proto_tree *tree, guint *offset)
595 {
596     nstime_t sample_start_time;
597     gint rem_len;
598
599     /* Snapshot ID */
600     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_rsp_sample_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
601     *offset += 2;
602
603     /* Sample Start Time */
604     sample_start_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
605     sample_start_time.nsecs = 0;
606     proto_tree_add_time(tree, hf_zbee_zcl_met_get_sampled_data_rsp_sample_start_time, tvb, *offset, 4, &sample_start_time);
607     *offset += 4;
608
609     /* Sample Type */
610     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_rsp_sample_type, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
611     *offset += 1;
612
613     /* Sample Request Interval */
614     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_rsp_sample_request_interval, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
615     *offset += 2;
616
617     /* Number of Samples */
618     proto_tree_add_item(tree, hf_zbee_zcl_met_get_sampled_data_rsp_sample_number_of_samples, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
619     *offset += 2;
620
621     /* Samples */
622     rem_len = tvb_reported_length_remaining(tvb, *offset);
623     while (rem_len >= 3) {
624         guint32 val = tvb_get_guint24(tvb, *offset, ENC_LITTLE_ENDIAN);
625         proto_tree_add_uint(tree, hf_zbee_zcl_met_get_sampled_data_rsp_sample_samples, tvb, *offset, 3, val);
626         *offset += 3;
627         rem_len -= 3;
628     }
629 } /*dissect_zcl_met_get_sampled_data_rsp*/
630
631 /**
632  *This function manages the Configure Mirror payload
633  *
634  *@param tvb pointer to buffer containing raw packet.
635  *@param tree pointer to data tree Wireshark uses to display packet.
636  *@param offset pointer to offset from caller
637 */
638 static void
639 dissect_zcl_met_configure_mirror(tvbuff_t *tvb, proto_tree *tree, guint *offset)
640 {
641     /* Issuer Event ID */
642     proto_tree_add_item(tree, hf_zbee_zcl_met_configure_mirror_issuer_event_id, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
643     *offset += 4;
644
645     /* Reporting Interval */
646     proto_tree_add_item(tree, hf_zbee_zcl_met_configure_mirror_reporting_interval, tvb, *offset, 3, ENC_LITTLE_ENDIAN);
647     *offset += 3;
648
649     /* Mirror Notification Reporting */
650     proto_tree_add_item(tree, hf_zbee_zcl_met_configure_mirror_mirror_notification_reporting, tvb, *offset, 1, ENC_NA);
651     *offset += 1;
652
653     /* Notification Scheme */
654     proto_tree_add_item(tree, hf_zbee_zcl_met_configure_mirror_notification_scheme, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
655     *offset += 1;
656 } /*dissect_zcl_met_configure_mirror*/
657
658 /**
659  *This function manages the Get Notified Message payload
660  *
661  *@param tvb pointer to buffer containing raw packet.
662  *@param tree pointer to data tree Wireshark uses to display packet.
663  *@param offset pointer to offset from caller
664 */
665 static void
666 dissect_zcl_met_get_notified_msg(tvbuff_t *tvb, proto_tree *tree, guint *offset)
667 {
668     /* Notification Scheme */
669     proto_tree_add_item(tree, hf_zbee_zcl_met_get_notified_msg_notification_scheme, tvb, *offset, 1, ENC_LITTLE_ENDIAN);
670     *offset += 1;
671
672     /* Notification Flag attribute ID */
673     proto_tree_add_item(tree, hf_zbee_zcl_met_get_notified_msg_notification_flag_attribute_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
674     *offset += 2;
675
676     /* Notification Flags #N */
677     proto_tree_add_item(tree, hf_zbee_zcl_met_get_notified_msg_notification_flags, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
678     *offset += 4;
679 } /*dissect_zcl_met_get_notified_msg*/
680
681 /**
682  *This function registers the ZCL Metering dissector
683  *
684 */
685 void
686 proto_register_zbee_zcl_met(void)
687 {
688     static hf_register_info hf[] = {
689
690         { &hf_zbee_zcl_met_attr_id,
691             { "Attribute", "zbee_zcl_se.met.attr_id", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &zbee_zcl_met_attr_names_ext,
692             0x0, NULL, HFILL } },
693
694         { &hf_zbee_zcl_met_attr_reporting_status,                         /* common to all SE clusters */
695             { "Attribute Reporting Status", "zbee_zcl_se.met.attr.attr_reporting_status",
696             FT_UINT8, BASE_HEX, VALS(zbee_zcl_se_reporting_status_names), 0x00, NULL, HFILL } },
697
698         { &hf_zbee_zcl_met_srv_tx_cmd_id,
699             { "Command", "zbee_zcl_se.met.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_met_srv_tx_cmd_names),
700             0x00, NULL, HFILL } },
701
702         { &hf_zbee_zcl_met_srv_rx_cmd_id,
703             { "Command", "zbee_zcl_se.met.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_met_srv_rx_cmd_names),
704             0x00, NULL, HFILL } },
705
706         { &hf_zbee_zcl_met_request_mirror_rsp_endpoint_id,
707             { "EndPoint ID", "zbee_zcl_se.met.request_mirror_rsp.endpoint_id", FT_UINT16, BASE_DEC, NULL,
708             0x00, NULL, HFILL } },
709
710         { &hf_zbee_zcl_met_get_snapshot_start_time,
711             { "Start Time", "zbee_zcl_se.met.get_snapshot.start_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
712             0x00, NULL, HFILL } },
713
714         { &hf_zbee_zcl_met_get_snapshot_end_time,
715             { "End Time", "zbee_zcl_se.met.get_snapshot.end_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
716             0x00, NULL, HFILL } },
717
718         { &hf_zbee_zcl_met_get_snapshot_snapshot_offset,
719             { "Snapshot Offset", "zbee_zcl_se.met.get_snapshot.snapshot_offset", FT_UINT8, BASE_DEC, NULL,
720             0x00, NULL, HFILL } },
721
722         { &hf_zbee_zcl_met_get_snapshot_snapshot_cause,
723             { "Snapshot Cause", "zbee_zcl_se.met.get_snapshot.snapshot_cause", FT_UINT32, BASE_HEX, NULL,
724             0x00, NULL, HFILL } },
725
726         { &hf_zbee_zcl_met_get_sampled_data_sample_id,
727             { "Sample ID", "zbee_zcl_se.met.get_sampled_data.sample_id", FT_UINT16, BASE_DEC, NULL,
728             0x00, NULL, HFILL } },
729
730         { &hf_zbee_zcl_met_get_sampled_data_sample_start_time,
731             { "Sample Start Time", "zbee_zcl_se.met.get_sampled_data.sample_start_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
732             0x00, NULL, HFILL } },
733
734         { &hf_zbee_zcl_met_get_sampled_data_sample_type,
735             { "Sample Type", "zbee_zcl_se.met.get_sampled_data.sample_type", FT_UINT8, BASE_DEC, NULL,
736             0x00, NULL, HFILL } },
737
738         { &hf_zbee_zcl_met_get_sampled_data_number_of_samples,
739             { "Number of Samples", "zbee_zcl_se.met.get_sampled_data.number_of_samples", FT_UINT16, BASE_DEC, NULL,
740             0x00, NULL, HFILL } },
741
742         { &hf_zbee_zcl_met_local_change_supply_supply_status,
743             { "Proposed Supply Status", "zbee_zcl_se.met.local_change_supply.supply_status", FT_UINT8, BASE_DEC, NULL,
744             0x00, NULL, HFILL } },
745
746         { &hf_zbee_zcl_met_publish_snapshot_snapshot_id,
747             { "Snapshot ID", "zbee_zcl_se.met.publish_snapshot.snapshot_id", FT_UINT32, BASE_DEC, NULL,
748             0x00, NULL, HFILL } },
749
750         { &hf_zbee_zcl_met_publish_snapshot_snapshot_time,
751             { "Snapshot Time", "zbee_zcl_se.met.publish_snapshot.snapshot_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
752             0x00, NULL, HFILL } },
753
754         { &hf_zbee_zcl_met_publish_snapshot_snapshots_found,
755             { "Total Snapshots Found", "zbee_zcl_se.met.publish_snapshot.snapshots_found", FT_UINT8, BASE_DEC, NULL,
756             0x00, NULL, HFILL } },
757
758         { &hf_zbee_zcl_met_publish_snapshot_cmd_index,
759             { "Command Index", "zbee_zcl_se.met.publish_snapshot.command_index", FT_UINT8, BASE_DEC, NULL,
760             0x00, NULL, HFILL } },
761
762         { &hf_zbee_zcl_met_publish_snapshot_total_commands,
763             { "Total Number of Commands", "zbee_zcl_se.met.publish_snapshot.total_commands", FT_UINT8, BASE_DEC, NULL,
764             0x00, NULL, HFILL } },
765
766         { &hf_zbee_zcl_met_publish_snapshot_snapshot_cause,
767             { "Snapshot Cause", "zbee_zcl_se.met.publish_snapshot.snapshot_cause", FT_UINT32, BASE_HEX, NULL,
768             0x00, NULL, HFILL } },
769
770         { &hf_zbee_zcl_met_publish_snapshot_snapshot_payload_type,
771             { "Snapshot Payload Type", "zbee_zcl_se.met.publish_snapshot.payload_type", FT_UINT8, BASE_DEC, NULL,
772             0x00, NULL, HFILL } },
773
774         { &hf_zbee_zcl_met_publish_snapshot_snapshot_sub_payload,
775             { "Snapshot Sub-Payload", "zbee_zcl_se.met.publish_snapshot.payload_type", FT_BYTES, BASE_NONE, NULL,
776             0x00, NULL, HFILL } },
777
778         { &hf_zbee_zcl_met_get_sampled_data_rsp_sample_id,
779             { "Sample ID", "zbee_zcl_se.met.get_sampled_data_rsp.sample_id", FT_UINT16, BASE_DEC, NULL,
780             0x00, NULL, HFILL } },
781
782         { &hf_zbee_zcl_met_get_sampled_data_rsp_sample_start_time,
783             { "Sample Start Time", "zbee_zcl_se.met.get_sampled_data_rsp.sample_start_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
784             0x00, NULL, HFILL } },
785
786         { &hf_zbee_zcl_met_get_sampled_data_rsp_sample_type,
787             { "Sample Type", "zbee_zcl_se.met.get_sampled_data_rsp.sample_type", FT_UINT8, BASE_DEC, NULL,
788             0x00, NULL, HFILL } },
789
790         { &hf_zbee_zcl_met_get_sampled_data_rsp_sample_request_interval,
791             { "Sample Request Interval", "zbee_zcl_se.met.get_sampled_data_rsp.sample_request_interval", FT_UINT16, BASE_DEC, NULL,
792             0x00, NULL, HFILL } },
793
794         { &hf_zbee_zcl_met_get_sampled_data_rsp_sample_number_of_samples,
795             { "Number of Samples", "zbee_zcl_se.met.get_sampled_data_rsp.number_of_samples", FT_UINT16, BASE_DEC, NULL,
796             0x00, NULL, HFILL } },
797
798         { &hf_zbee_zcl_met_get_sampled_data_rsp_sample_samples,
799             { "Samples", "zbee_zcl_se.met.get_sampled_data_rsp.samples", FT_UINT24, BASE_DEC, NULL,
800             0x00, NULL, HFILL } },
801
802         { &hf_zbee_zcl_met_configure_mirror_issuer_event_id,
803             { "Issuer Event ID", "zbee_zcl_se.met.configure_mirror.issuer_event_id", FT_UINT32, BASE_DEC, NULL,
804             0x00, NULL, HFILL } },
805
806         { &hf_zbee_zcl_met_configure_mirror_reporting_interval,
807             { "Reporting Interval", "zbee_zcl_se.met.configure_mirror.reporting_interval", FT_UINT24, BASE_DEC, NULL,
808             0x00, NULL, HFILL } },
809
810         { &hf_zbee_zcl_met_configure_mirror_mirror_notification_reporting,
811             { "Mirror Notification Reporting", "zbee_zcl_se.met.configure_mirror.mirror_notification_reporting", FT_BOOLEAN, BASE_NONE, NULL,
812             0x00, NULL, HFILL } },
813
814         { &hf_zbee_zcl_met_configure_mirror_notification_scheme,
815             { "Notification Scheme", "zbee_zcl_se.met.configure_mirror.notification_scheme", FT_UINT8, BASE_DEC, NULL,
816             0x00, NULL, HFILL } },
817
818         { &hf_zbee_zcl_met_get_notified_msg_notification_scheme,
819             { "Notification Scheme", "zbee_zcl_se.met.get_notified_msg.notification_scheme", FT_UINT8, BASE_DEC, NULL,
820             0x00, NULL, HFILL } },
821
822         { &hf_zbee_zcl_met_get_notified_msg_notification_flag_attribute_id,
823             { "Notification Flag attribute ID", "zbee_zcl_se.met.get_notified_msg.notification_flag_attribute_id", FT_UINT16, BASE_DEC, NULL,
824             0x00, NULL, HFILL } },
825
826         { &hf_zbee_zcl_met_get_notified_msg_notification_flags,
827             { "Notification Flags", "zbee_zcl_se.met.get_notified_msg.notification_flags", FT_UINT32, BASE_HEX, NULL,
828             0x00, NULL, HFILL } }
829     };
830
831     /* ZCL Metering subtrees */
832     gint *ett[] = {
833         &ett_zbee_zcl_met,
834     };
835
836     /* Register the ZigBee ZCL Metering cluster protocol name and description */
837     proto_zbee_zcl_met = proto_register_protocol("ZigBee ZCL Metering", "ZCL Metering", ZBEE_PROTOABBREV_ZCL_MET);
838     proto_register_field_array(proto_zbee_zcl_met, hf, array_length(hf));
839     proto_register_subtree_array(ett, array_length(ett));
840
841     /* Register the ZigBee ZCL Metering dissector. */
842     met_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_MET, dissect_zbee_zcl_met, proto_zbee_zcl_met);
843 } /*proto_register_zbee_zcl_met*/
844
845 /**
846  *Hands off the Zcl Metering dissector.
847  *
848 */
849 void
850 proto_reg_handoff_zbee_zcl_met(void)
851 {
852     /* Register our dissector with the ZigBee application dissectors. */
853     dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_SIMPLE_METERING, met_handle);
854
855     zbee_zcl_init_cluster(  proto_zbee_zcl_met,
856                             ett_zbee_zcl_met,
857                             ZBEE_ZCL_CID_SIMPLE_METERING,
858                             hf_zbee_zcl_met_attr_id,
859                             hf_zbee_zcl_met_srv_rx_cmd_id,
860                             hf_zbee_zcl_met_srv_tx_cmd_id,
861                             (zbee_zcl_fn_attr_data)dissect_zcl_met_attr_data
862                          );
863 } /*proto_reg_handoff_zbee_zcl_met*/
864
865 /* ########################################################################## */
866 /* #### (0x0703) MESSAGING CLUSTER ########################################## */
867 /* ########################################################################## */
868
869 /* Attributes - None (other than Attribute Reporting Status) */
870 #define zbee_zcl_msg_attr_names_VALUE_STRING_LIST(XXX) \
871 /* Smart Energy */ \
872     XXX(ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_MSG,     0xFFFE, "Attribute Reporting Status" )
873
874 VALUE_STRING_ENUM(zbee_zcl_msg_attr_names);
875 VALUE_STRING_ARRAY(zbee_zcl_msg_attr_names);
876
877 /* Server Commands Received */
878 #define zbee_zcl_msg_srv_rx_cmd_names_VALUE_STRING_LIST(XXX) \
879     XXX(ZBEE_ZCL_CMD_ID_MSG_GET_LAST_MSG,               0x00, "Get Last Message" ) \
880     XXX(ZBEE_ZCL_CMD_ID_MSG_MSG_CONFIRM,                0x01, "Message Confirmation" ) \
881     XXX(ZBEE_ZCL_CMD_ID_MSG_GET_MESSAGE_CANCEL,         0x02, "Get Message Cancellation" )
882
883 VALUE_STRING_ENUM(zbee_zcl_msg_srv_rx_cmd_names);
884 VALUE_STRING_ARRAY(zbee_zcl_msg_srv_rx_cmd_names);
885
886 /* Server Commands Generated */
887 #define zbee_zcl_msg_srv_tx_cmd_names_VALUE_STRING_LIST(XXX) \
888     XXX(ZBEE_ZCL_CMD_ID_MSG_DISPLAY_MSG,                0x00, "Display Message" ) \
889     XXX(ZBEE_ZCL_CMD_ID_MSG_CANCEL_MSG,                 0x01, "Cancel Message" ) \
890     XXX(ZBEE_ZCL_CMD_ID_MSG_DISPLAY_PROTECTED_MSG,      0x02, "Display Protected Message" ) \
891     XXX(ZBEE_ZCL_CMD_ID_MSG_CANCEL_ALL_MSG,             0x03, "Cancel All Messages" )
892
893 VALUE_STRING_ENUM(zbee_zcl_msg_srv_tx_cmd_names);
894 VALUE_STRING_ARRAY(zbee_zcl_msg_srv_tx_cmd_names);
895
896 /* Message Control Field Bit Map */
897 #define ZBEE_ZCL_MSG_CTRL_TX_MASK                       0x03
898 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MASK               0x0C
899 #define ZBEE_ZCL_MSG_CTRL_RESERVED_MASK                 0x50
900 #define ZBEE_ZCL_MSG_CTRL_ENHANCED_CONFIRM_MASK         0x20
901 #define ZBEE_ZCL_MSG_CTRL_CONFIRM_MASK                  0x80
902
903 #define ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ONLY                0x00 /* Normal Transmission Only */
904 #define ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ANON_INTERPAN       0x01 /* Normal and Anonymous Inter-PAN Transmission Only */
905 #define ZBEE_ZCL_MSG_CTRL_TX_ANON_INTERPAN_ONLY         0x02 /* Anonymous Inter-PAN Transmission Only */
906
907 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_LOW                0x00 /* Low */
908 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MEDIUM             0x01 /* Medium */
909 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_HIGH               0x02 /* High */
910 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_CRITICAL           0x03 /* Critical */
911
912 #define ZBEE_ZCL_MSG_EXT_CTRL_STATUS_MASK               0x01
913
914 #define ZBEE_ZCL_MSG_CONFIRM_CTRL_MASK                  0x01
915
916 #define ZBEE_ZCL_MSG_START_TIME_NOW                     0x00000000 /* Now */
917
918 /*************************/
919 /* Function Declarations */
920 /*************************/
921 void proto_register_zbee_zcl_msg(void);
922 void proto_reg_handoff_zbee_zcl_msg(void);
923
924 /* Attribute Dissector Helpers */
925 static void dissect_zcl_msg_attr_data  (proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type);
926
927 /* Command Dissector Helpers */
928 static void dissect_zcl_msg_display             (tvbuff_t *tvb, proto_tree *tree, guint *offset);
929 static void dissect_zcl_msg_cancel              (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset);
930 static void dissect_zcl_msg_confirm             (tvbuff_t *tvb, proto_tree *tree, guint *offset);
931 static void dissect_zcl_msg_cancel_all          (tvbuff_t *tvb, proto_tree *tree, guint *offset);
932 static void dissect_zcl_msg_get_cancel          (tvbuff_t *tvb, proto_tree *tree, guint *offset);
933
934 /* Private functions prototype */
935 static void decode_zcl_msg_duration             (gchar *s, guint16 value);
936
937 /*************************/
938 /* Global Variables      */
939 /*************************/
940
941 static dissector_handle_t msg_handle;
942
943 /* Initialize the protocol and registered fields */
944 static int proto_zbee_zcl_msg = -1;
945
946 static int hf_zbee_zcl_msg_srv_tx_cmd_id = -1;
947 static int hf_zbee_zcl_msg_srv_rx_cmd_id = -1;
948 static int hf_zbee_zcl_msg_attr_id = -1;
949 static int hf_zbee_zcl_msg_attr_reporting_status = -1;
950 static int hf_zbee_zcl_msg_message_id = -1;
951 static int hf_zbee_zcl_msg_ctrl = -1;
952 static int hf_zbee_zcl_msg_ctrl_tx = -1;
953 static int hf_zbee_zcl_msg_ctrl_importance = -1;
954 static int hf_zbee_zcl_msg_ctrl_enh_confirm = -1;
955 static int hf_zbee_zcl_msg_ctrl_reserved = -1;
956 static int hf_zbee_zcl_msg_ctrl_confirm = -1;
957 static int hf_zbee_zcl_msg_ext_ctrl = -1;
958 static int hf_zbee_zcl_msg_ext_ctrl_status = -1;
959 static int hf_zbee_zcl_msg_start_time = -1;
960 static int hf_zbee_zcl_msg_duration = -1;
961 static int hf_zbee_zcl_msg_message_length = - 1;
962 static int hf_zbee_zcl_msg_message = -1;
963 static int hf_zbee_zcl_msg_confirm_time = -1;
964 static int hf_zbee_zcl_msg_confirm_ctrl = -1;
965 static int hf_zbee_zcl_msg_confirm_response = -1;
966 static int hf_zbee_zcl_msg_confirm_response_length = - 1;
967 static int hf_zbee_zcl_msg_implementation_time = -1;
968 static int hf_zbee_zcl_msg_earliest_time = -1;
969
970 /* Initialize the subtree pointers */
971 static gint ett_zbee_zcl_msg = -1;
972 static gint ett_zbee_zcl_msg_message_control = -1;
973 static gint ett_zbee_zcl_msg_ext_message_control = -1;
974
975 static expert_field ei_zbee_zcl_msg_msg_ctrl_depreciated = EI_INIT;
976
977 /* Message Control Transmission */
978 static const value_string zbee_zcl_msg_ctrl_tx_names[] = {
979     { ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ONLY,                 "Normal Transmission Only" },
980     { ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ANON_INTERPAN,        "Normal and Anonymous Inter-PAN Transmission Only" },
981     { ZBEE_ZCL_MSG_CTRL_TX_ANON_INTERPAN_ONLY,          "Anonymous Inter-PAN Transmission Only" },
982     { 0, NULL }
983 };
984
985 /* Message Control Importance */
986 static const value_string zbee_zcl_msg_ctrl_importance_names[] = {
987     { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_LOW,                 "Low" },
988     { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MEDIUM,              "Medium" },
989     { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_HIGH,                "High" },
990     { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_CRITICAL,            "Critical" },
991     { 0, NULL }
992 };
993
994 /*************************/
995 /* Function Bodies       */
996 /*************************/
997
998 /**
999  *This function is called by ZCL foundation dissector in order to decode
1000  *
1001  *@param tree pointer to data tree Wireshark uses to display packet.
1002  *@param tvb pointer to buffer containing raw packet.
1003  *@param offset pointer to buffer offset
1004  *@param attr_id attribute identifier
1005  *@param data_type attribute data type
1006 */
1007 static void
1008 dissect_zcl_msg_attr_data(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type)
1009 {
1010     switch (attr_id) {
1011         /* no cluster specific attributes */
1012
1013         /* applies to all SE clusters */
1014         case ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_MSG:
1015             proto_tree_add_item(tree, hf_zbee_zcl_msg_attr_reporting_status, tvb, *offset, 1, ENC_NA);
1016             *offset += 1;
1017             break;
1018
1019         default: /* Catch all */
1020             dissect_zcl_attr_data(tvb, tree, offset, data_type);
1021             break;
1022     }
1023 } /*dissect_zcl_ias_zone_attr_data*/
1024
1025 /**
1026  *ZigBee ZCL Messaging cluster dissector for wireshark.
1027  *
1028  *@param tvb pointer to buffer containing raw packet.
1029  *@param pinfo pointer to packet information fields
1030  *@param tree pointer to data tree Wireshark uses to display packet.
1031 */
1032 static int
1033 dissect_zbee_zcl_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
1034 {
1035     proto_tree        *payload_tree;
1036     zbee_zcl_packet   *zcl;
1037     guint             offset = 0;
1038     guint8            cmd_id;
1039     gint              rem_len;
1040
1041     /* Reject the packet if data is NULL */
1042     if (data == NULL)
1043         return 0;
1044     zcl = (zbee_zcl_packet *)data;
1045     cmd_id = zcl->cmd_id;
1046
1047     /*  Create a subtree for the ZCL Command frame, and add the command ID to it. */
1048     if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) {
1049         /* Append the command name to the info column. */
1050         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
1051             val_to_str_const(cmd_id, zbee_zcl_msg_srv_rx_cmd_names, "Unknown Command"),
1052             zcl->tran_seqno);
1053
1054         /* Add the command ID. */
1055         proto_tree_add_uint(tree, hf_zbee_zcl_msg_srv_rx_cmd_id, tvb, offset, 1, cmd_id);
1056
1057         /* Check is this command has a payload, than add the payload tree */
1058         rem_len = tvb_reported_length_remaining(tvb, ++offset);
1059         if (rem_len > 0) {
1060             payload_tree = proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_msg, NULL, "Payload");
1061
1062             /* Call the appropriate command dissector */
1063             switch (cmd_id) {
1064
1065                 case ZBEE_ZCL_CMD_ID_MSG_GET_LAST_MSG:
1066                     /* No payload */
1067                     break;
1068
1069                 case ZBEE_ZCL_CMD_ID_MSG_MSG_CONFIRM:
1070                     dissect_zcl_msg_confirm(tvb, payload_tree, &offset);
1071                     break;
1072
1073                 case ZBEE_ZCL_CMD_ID_MSG_GET_MESSAGE_CANCEL:
1074                     dissect_zcl_msg_get_cancel(tvb, payload_tree, &offset);
1075                     break;
1076
1077                 default:
1078                     break;
1079             }
1080         }
1081     }
1082     else { /* ZBEE_ZCL_FCF_TO_CLIENT */
1083         /* Append the command name to the info column. */
1084         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
1085             val_to_str_const(cmd_id, zbee_zcl_msg_srv_tx_cmd_names, "Unknown Command"),
1086             zcl->tran_seqno);
1087
1088         /* Add the command ID. */
1089         proto_tree_add_uint(tree, hf_zbee_zcl_msg_srv_tx_cmd_id, tvb, offset, 1, cmd_id);
1090
1091         /* Check is this command has a payload, than add the payload tree */
1092         rem_len = tvb_reported_length_remaining(tvb, ++offset);
1093         if (rem_len > 0) {
1094             payload_tree = proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_msg, NULL, "Payload");
1095
1096             /* Call the appropriate command dissector */
1097             switch (cmd_id) {
1098
1099                 case ZBEE_ZCL_CMD_ID_MSG_DISPLAY_MSG:
1100                     dissect_zcl_msg_display(tvb, payload_tree, &offset);
1101                     break;
1102
1103                 case ZBEE_ZCL_CMD_ID_MSG_CANCEL_MSG:
1104                     dissect_zcl_msg_cancel(tvb, pinfo, payload_tree, &offset);
1105                     break;
1106
1107                 case ZBEE_ZCL_CMD_ID_MSG_DISPLAY_PROTECTED_MSG:
1108                     dissect_zcl_msg_display(tvb, payload_tree, &offset);
1109                     break;
1110
1111                 case ZBEE_ZCL_CMD_ID_MSG_CANCEL_ALL_MSG:
1112                     dissect_zcl_msg_cancel_all(tvb, payload_tree, &offset);
1113                     break;
1114
1115                 default:
1116                     break;
1117             }
1118         }
1119     }
1120
1121     return tvb_captured_length(tvb);
1122 } /*dissect_zbee_zcl_msg*/
1123
1124 /**
1125  *This function manages the Display Message payload
1126  *
1127  *@param tvb pointer to buffer containing raw packet.
1128  *@param tree pointer to data tree Wireshark uses to display packet.
1129  *@param offset pointer to offset from caller
1130 */
1131 static void
1132 dissect_zcl_msg_display(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1133 {
1134     guint   msg_len;
1135     guint8 *msg_data;
1136
1137     static const int * message_ctrl_flags[] = {
1138         &hf_zbee_zcl_msg_ctrl_tx,
1139         &hf_zbee_zcl_msg_ctrl_importance,
1140         &hf_zbee_zcl_msg_ctrl_enh_confirm,
1141         &hf_zbee_zcl_msg_ctrl_reserved,
1142         &hf_zbee_zcl_msg_ctrl_confirm,
1143         NULL
1144     };
1145
1146     static const int * message_ext_ctrl_flags[] = {
1147         &hf_zbee_zcl_msg_ext_ctrl_status,
1148         NULL
1149     };
1150
1151     /* Message ID */
1152     proto_tree_add_item(tree, hf_zbee_zcl_msg_message_id, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
1153     *offset += 4;
1154
1155     /* Message Control */
1156     proto_tree_add_bitmask(tree, tvb, *offset, hf_zbee_zcl_msg_ctrl, ett_zbee_zcl_msg_message_control, message_ctrl_flags, ENC_NA);
1157     *offset += 1;
1158
1159     /* Start Time */
1160     proto_tree_add_item(tree, hf_zbee_zcl_msg_start_time, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
1161     *offset += 4;
1162
1163     /* Duration In Minutes*/
1164     proto_tree_add_item(tree, hf_zbee_zcl_msg_duration, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1165     *offset += 2;
1166
1167     /* Message Length */
1168     msg_len = tvb_get_guint8(tvb, *offset); /* string length */
1169     proto_tree_add_item(tree, hf_zbee_zcl_msg_message_length, tvb, *offset, 1, ENC_NA);
1170     *offset += 1;
1171
1172     /* Message */
1173     msg_data = tvb_get_string_enc(wmem_packet_scope(), tvb, *offset, msg_len, ENC_LITTLE_ENDIAN);
1174     proto_tree_add_string(tree, hf_zbee_zcl_msg_message, tvb, *offset, msg_len, msg_data);
1175     *offset += msg_len;
1176
1177     /* (Optional) Extended Message Control */
1178     if (tvb_reported_length_remaining(tvb, *offset) > 0) {
1179         proto_tree_add_bitmask(tree, tvb, *offset, hf_zbee_zcl_msg_ext_ctrl, ett_zbee_zcl_msg_ext_message_control, message_ext_ctrl_flags, ENC_NA);
1180         *offset += 1;
1181     }
1182
1183 } /*dissect_zcl_msg_display*/
1184
1185 /**
1186  *This function manages the Cancel Message payload
1187  *
1188  *@param tvb pointer to buffer containing raw packet.
1189  *@param tree pointer to data tree Wireshark uses to display packet.
1190  *@param offset pointer to offset from caller
1191 */
1192 static void
1193 dissect_zcl_msg_cancel(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset)
1194 {
1195     gint8 msg_ctrl;
1196
1197     /* Message ID */
1198     proto_tree_add_item(tree, hf_zbee_zcl_msg_message_id, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
1199     *offset += 4;
1200
1201     /* Message Control */
1202     msg_ctrl = tvb_get_guint8(tvb, *offset);
1203     proto_tree_add_item(tree, hf_zbee_zcl_msg_ctrl, tvb, *offset, 1, ENC_NA);
1204     *offset += 1;
1205
1206     if (msg_ctrl != 0x00) {
1207        expert_add_info(pinfo, tree, &ei_zbee_zcl_msg_msg_ctrl_depreciated);
1208     }
1209
1210 } /* dissect_zcl_msg_cancel */
1211
1212
1213 /**
1214  *Send Cancel All command
1215  *
1216  *@param tvb pointer to buffer containing raw packet.
1217  *@param tree pointer to data tree Wireshark uses to display packet.
1218  *@param offset pointer to offset from caller
1219 */
1220 static void
1221 dissect_zcl_msg_cancel_all(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1222 {
1223     nstime_t impl_time;
1224
1225     /* Retrieve "Confirmation Time" field */
1226     impl_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
1227     impl_time.nsecs = 0;
1228     proto_tree_add_time(tree, hf_zbee_zcl_msg_implementation_time, tvb, *offset, 4, &impl_time);
1229     *offset += 4;
1230
1231 } /* dissect_zcl_msg_cancel_all */
1232
1233 /**
1234  *Send Cancel All command
1235  *
1236  *@param tvb pointer to buffer containing raw packet.
1237  *@param tree pointer to data tree Wireshark uses to display packet.
1238  *@param offset pointer to offset from caller
1239 */
1240 static void
1241 dissect_zcl_msg_get_cancel(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1242 {
1243     nstime_t impl_time;
1244
1245     /* Earliest Implementation Time */
1246     impl_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
1247     impl_time.nsecs = 0;
1248     proto_tree_add_time(tree, hf_zbee_zcl_msg_earliest_time, tvb, *offset, 4, &impl_time);
1249     *offset += 4;
1250
1251 } /* dissect_zcl_msg_get_cancel */
1252
1253
1254 /**
1255  *This function manages the Message Confirmation payload
1256  *
1257  *@param tvb pointer to buffer containing raw packet.
1258  *@param tree pointer to data tree Wireshark uses to display packet.
1259  *@param offset pointer to offset from caller
1260 */
1261 static void
1262 dissect_zcl_msg_confirm(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1263 {
1264     guint   msg_len;
1265     guint8 *msg_data;
1266     nstime_t confirm_time;
1267
1268     /* Retrieve "Message ID" field */
1269     proto_tree_add_item(tree, hf_zbee_zcl_msg_message_id, tvb, *offset, 4, ENC_LITTLE_ENDIAN);
1270     *offset += 4;
1271
1272     /* Retrieve "Confirmation Time" field */
1273     confirm_time.secs = (time_t)tvb_get_letohl(tvb, *offset) + ZBEE_ZCL_NSTIME_UTC_OFFSET;
1274     confirm_time.nsecs = 0;
1275     proto_tree_add_time(tree, hf_zbee_zcl_msg_confirm_time, tvb, *offset, 4, &confirm_time);
1276     *offset += 4;
1277
1278     /* (Optional) Confirm Control */
1279     if ( tvb_reported_length_remaining(tvb, *offset) <= 0 ) return;
1280     proto_tree_add_item(tree, hf_zbee_zcl_msg_confirm_ctrl, tvb, *offset, 1, ENC_NA);
1281     *offset += 1;
1282
1283     /* (Optional) Response Text Length */
1284     if ( tvb_reported_length_remaining(tvb, *offset) <= 0 ) return;
1285     msg_len = tvb_get_guint8(tvb, *offset); /* string length */
1286     proto_tree_add_item(tree, hf_zbee_zcl_msg_confirm_response_length, tvb, *offset, 1, ENC_NA);
1287     *offset += 1;
1288
1289     /* (Optional) Response Text, but is we have a length we expect to find the subsequent string */
1290     if (msg_len > 0) {
1291         msg_data = tvb_get_string_enc(wmem_packet_scope(), tvb, *offset, msg_len, ENC_LITTLE_ENDIAN);
1292         proto_tree_add_string(tree, hf_zbee_zcl_msg_confirm_response, tvb, *offset, msg_len, msg_data);
1293         *offset += msg_len;
1294     }
1295
1296 } /* dissect_zcl_msg_confirm */
1297
1298 /**
1299  *This function decodes duration in minute type variable
1300  *
1301 */
1302 static void
1303 decode_zcl_msg_duration(gchar *s, guint16 value)
1304 {
1305     if (value == 0xffff)
1306         g_snprintf(s, ITEM_LABEL_LENGTH, "Until changed");
1307     else
1308         g_snprintf(s, ITEM_LABEL_LENGTH, "%d minutes", value);
1309     return;
1310 } /*decode_zcl_msg_duration*/
1311
1312 /**
1313  * This function decodes start time, with a special case for
1314  * ZBEE_ZCL_MSG_START_TIME_NOW.
1315  *
1316  * @param s string to display
1317  * @param value value to decode
1318 */
1319 static void
1320 decode_zcl_msg_start_time(gchar *s, guint32 value)
1321 {
1322     if (value == ZBEE_ZCL_MSG_START_TIME_NOW)
1323         g_snprintf(s, ITEM_LABEL_LENGTH, "Now");
1324     else {
1325         gchar *start_time;
1326         time_t epoch_time = (time_t)value + ZBEE_ZCL_NSTIME_UTC_OFFSET;
1327         start_time = abs_time_secs_to_str (NULL, epoch_time, ABSOLUTE_TIME_LOCAL, TRUE);
1328         g_snprintf(s, ITEM_LABEL_LENGTH, "%s", start_time);
1329         wmem_free(NULL, start_time);
1330     }
1331 } /* decode_zcl_msg_start_time */
1332
1333 /**
1334  *This function registers the ZCL Messaging dissector
1335  *
1336 */
1337 void
1338 proto_register_zbee_zcl_msg(void)
1339 {
1340     static hf_register_info hf[] = {
1341
1342         { &hf_zbee_zcl_msg_attr_id,
1343             { "Attribute", "zbee_zcl_se.msg.attr_id", FT_UINT16, BASE_HEX, VALS(zbee_zcl_msg_attr_names),
1344             0x0, NULL, HFILL } },
1345
1346         { &hf_zbee_zcl_msg_attr_reporting_status,                         /* common to all SE clusters */
1347             { "Attribute Reporting Status", "zbee_zcl_se.msg.attr.attr_reporting_status",
1348             FT_UINT8, BASE_HEX, VALS(zbee_zcl_se_reporting_status_names), 0x00, NULL, HFILL } },
1349
1350         { &hf_zbee_zcl_msg_srv_tx_cmd_id,
1351             { "Command", "zbee_zcl_se.msg.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_msg_srv_tx_cmd_names),
1352             0x00, NULL, HFILL } },
1353
1354         { &hf_zbee_zcl_msg_srv_rx_cmd_id,
1355             { "Command", "zbee_zcl_se.msg.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_msg_srv_rx_cmd_names),
1356             0x00, NULL, HFILL } },
1357
1358         { &hf_zbee_zcl_msg_message_id,
1359             { "Message ID", "zbee_zcl_se.msg.message.id", FT_UINT32, BASE_HEX, NULL,
1360             0x00, NULL, HFILL } },
1361
1362 /* Start of 'Message Control' fields */
1363         { &hf_zbee_zcl_msg_ctrl,
1364             { "Message Control", "zbee_zcl_se.msg.message.ctrl", FT_UINT8, BASE_HEX, NULL,
1365             0x0, NULL, HFILL } },
1366
1367         { &hf_zbee_zcl_msg_ctrl_tx,
1368             { "Transmission", "zbee_zcl_se.msg.message.ctrl.tx", FT_UINT8, BASE_HEX, VALS(zbee_zcl_msg_ctrl_tx_names),
1369             ZBEE_ZCL_MSG_CTRL_TX_MASK, NULL, HFILL } },
1370
1371         { &hf_zbee_zcl_msg_ctrl_importance,
1372             { "Importance", "zbee_zcl_se.msg.message.ctrl.importance", FT_UINT8, BASE_HEX, VALS(zbee_zcl_msg_ctrl_importance_names),
1373             ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MASK, NULL, HFILL } },
1374
1375         { &hf_zbee_zcl_msg_ctrl_enh_confirm,
1376             { "Confirmation", "zbee_zcl_se.msg.message.ctrl.enhconfirm", FT_BOOLEAN, 8, TFS(&tfs_required_not_required),
1377             ZBEE_ZCL_MSG_CTRL_ENHANCED_CONFIRM_MASK, NULL, HFILL } },
1378
1379         { &hf_zbee_zcl_msg_ctrl_reserved,
1380             { "Reserved", "zbee_zcl_se.msg.message.ctrl.reserved", FT_UINT8, BASE_HEX, NULL,
1381             ZBEE_ZCL_MSG_CTRL_RESERVED_MASK, NULL, HFILL } },
1382
1383         { &hf_zbee_zcl_msg_ctrl_confirm,
1384             { "Confirmation", "zbee_zcl_se.msg.message.ctrl.confirm", FT_BOOLEAN, 8, TFS(&tfs_required_not_required),
1385             ZBEE_ZCL_MSG_CTRL_CONFIRM_MASK, NULL, HFILL } },
1386 /* End of 'Message Control' fields */
1387
1388 /* Start of 'Extended Message Control' fields */
1389         { &hf_zbee_zcl_msg_ext_ctrl,
1390             { "Extended Message Control", "zbee_zcl_se.msg.message.ext.ctrl", FT_UINT8, BASE_HEX, NULL,
1391             0x0, NULL, HFILL } },
1392
1393         { &hf_zbee_zcl_msg_ext_ctrl_status,
1394             { "Message Confirmation Status", "zbee_zcl_se.msg.message.ext.ctrl.status", FT_BOOLEAN, 8, TFS(&tfs_confirmed_unconfirmed),
1395             ZBEE_ZCL_MSG_EXT_CTRL_STATUS_MASK, NULL, HFILL } },
1396 /* End of 'Extended Message Control' fields */
1397
1398         { &hf_zbee_zcl_msg_start_time,
1399             { "Start Time", "zbee_zcl_se.msg.message.start_time", FT_UINT32, BASE_CUSTOM, CF_FUNC(decode_zcl_msg_start_time),
1400             0x00, NULL, HFILL } },
1401
1402         { &hf_zbee_zcl_msg_duration,
1403             { "Duration", "zbee_zcl_se.msg.message.duration", FT_UINT16, BASE_CUSTOM, CF_FUNC(decode_zcl_msg_duration),
1404             0x00, NULL, HFILL } },
1405
1406         { &hf_zbee_zcl_msg_message_length,
1407             { "Message Length", "zbee_zcl_se.msg.message.length", FT_UINT8, BASE_DEC, NULL,
1408             0x00, NULL, HFILL } },
1409
1410         { &hf_zbee_zcl_msg_message,
1411             { "Message", "zbee_zcl_se.msg.message", FT_STRING, BASE_NONE, NULL,
1412             0x00, NULL, HFILL } },
1413
1414         { &hf_zbee_zcl_msg_confirm_time,
1415             { "Confirmation Time", "zbee_zcl_se.msg.message.confirm_time",  FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL,
1416             0x0, NULL, HFILL } },
1417
1418         { &hf_zbee_zcl_msg_confirm_ctrl,
1419             { "Confirmation Control", "zbee_zcl_se.msg.message.confirm.ctrl", FT_BOOLEAN, 8, TFS(&tfs_no_yes),
1420             ZBEE_ZCL_MSG_CONFIRM_CTRL_MASK, NULL, HFILL } },
1421
1422         { &hf_zbee_zcl_msg_confirm_response_length,
1423             { "Response Length", "zbee_zcl_se.msg.message.length", FT_UINT8, BASE_DEC, NULL,
1424             0x00, NULL, HFILL } },
1425
1426         { &hf_zbee_zcl_msg_confirm_response,
1427             { "Response", "zbee_zcl_se.msg.message", FT_STRING, BASE_NONE, NULL,
1428             0x00, NULL, HFILL } },
1429
1430         { &hf_zbee_zcl_msg_implementation_time,
1431             { "Implementation Time", "zbee_zcl_se.msg.impl_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
1432             0, NULL, HFILL } },
1433
1434         { &hf_zbee_zcl_msg_earliest_time,
1435             { "Earliest Implementation Time", "zbee_zcl_se.msg.earliest_impl_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
1436             0, NULL, HFILL } },
1437
1438     };
1439
1440     /* ZCL Messaging subtrees */
1441     gint *ett[] = {
1442         &ett_zbee_zcl_msg,
1443         &ett_zbee_zcl_msg_message_control,
1444         &ett_zbee_zcl_msg_ext_message_control,
1445     };
1446
1447     /* Expert Info */
1448     expert_module_t* expert_zbee_zcl_msg;
1449     static ei_register_info ei[] = {
1450         { &ei_zbee_zcl_msg_msg_ctrl_depreciated, { "zbee_zcl_se.msg.msg_ctrl.depreciated", PI_PROTOCOL, PI_WARN, "Message Control depreciated in this message, should be 0x00", EXPFILL }},
1451     };
1452
1453     /* Register the ZigBee ZCL Messaging cluster protocol name and description */
1454     proto_zbee_zcl_msg = proto_register_protocol("ZigBee ZCL Messaging", "ZCL Messaging", ZBEE_PROTOABBREV_ZCL_MSG);
1455     proto_register_field_array(proto_zbee_zcl_msg, hf, array_length(hf));
1456     proto_register_subtree_array(ett, array_length(ett));
1457
1458     expert_zbee_zcl_msg = expert_register_protocol(proto_zbee_zcl_msg);
1459     expert_register_field_array(expert_zbee_zcl_msg, ei, array_length(ei));
1460
1461     /* Register the ZigBee ZCL Messaging dissector. */
1462     msg_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_MSG, dissect_zbee_zcl_msg, proto_zbee_zcl_msg);
1463 } /*proto_register_zbee_zcl_msg*/
1464
1465 /**
1466  *Hands off the Zcl Messaging dissector.
1467  *
1468 */
1469 void
1470 proto_reg_handoff_zbee_zcl_msg(void)
1471 {
1472     /* Register our dissector with the ZigBee application dissectors. */
1473     dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_MESSAGE, msg_handle);
1474
1475     zbee_zcl_init_cluster(  proto_zbee_zcl_msg,
1476                             ett_zbee_zcl_msg,
1477                             ZBEE_ZCL_CID_MESSAGE,
1478                             hf_zbee_zcl_msg_attr_id,
1479                             hf_zbee_zcl_msg_srv_rx_cmd_id,
1480                             hf_zbee_zcl_msg_srv_tx_cmd_id,
1481                             (zbee_zcl_fn_attr_data)dissect_zcl_msg_attr_data
1482                          );
1483 } /*proto_reg_handoff_zbee_zcl_msg*/
1484
1485 /* ########################################################################## */
1486 /* #### (0x0704) TUNNELING CLUSTER ########################################### */
1487 /* ########################################################################## */
1488
1489 /* Attributes */
1490 #define zbee_zcl_tun_attr_names_VALUE_STRING_LIST(XXX) \
1491     XXX(ZBEE_ZCL_ATTR_ID_TUN_CLOSE_TIMEOUT,                     0x0000, "Close Tunnel Timeout" ) \
1492 /* Smart Energy */ \
1493     XXX(ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_TUN,             0xFFFE, "Attribute Reporting Status" )
1494
1495 VALUE_STRING_ENUM(zbee_zcl_tun_attr_names);
1496 VALUE_STRING_ARRAY(zbee_zcl_tun_attr_names);
1497
1498 /* Server Commands Received */
1499 #define zbee_zcl_tun_srv_rx_cmd_names_VALUE_STRING_LIST(XXX) \
1500     XXX(ZBEE_ZCL_CMD_ID_TUN_REQUEST_TUNNEL,                     0x00, "Request Tunnel" ) \
1501     XXX(ZBEE_ZCL_CMD_ID_TUN_CLOSE_TUNNEL,                       0x01, "Close Tunnel" ) \
1502     XXX(ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA,                      0x02, "Transfer Data" ) \
1503     XXX(ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA_ERROR,                0x03, "Transfer Data Error" ) \
1504     XXX(ZBEE_ZCL_CMD_ID_TUN_ACK_TRANSFER_DATA,                  0x04, "Ack Transfer Data" ) \
1505     XXX(ZBEE_ZCL_CMD_ID_TUN_READY_DATA,                         0x05, "Ready Data" ) \
1506     XXX(ZBEE_ZCL_CMD_ID_TUN_GET_SUPPORTED_PROTOCOLS,            0x06, "Get Supported Protocols" )
1507
1508 VALUE_STRING_ENUM(zbee_zcl_tun_srv_rx_cmd_names);
1509 VALUE_STRING_ARRAY(zbee_zcl_tun_srv_rx_cmd_names);
1510
1511 /* Server Commands Generated */
1512 #define zbee_zcl_tun_srv_tx_cmd_names_VALUE_STRING_LIST(XXX) \
1513     XXX(ZBEE_ZCL_CMD_ID_TUN_REQUEST_TUNNEL_RSP,                 0x00, "Request Tunnel Response" ) \
1514     XXX(ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA_TX,                   0x01, "Transfer Data" ) \
1515     XXX(ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA_ERROR_TX,             0x02, "Transfer Data Error" ) \
1516     XXX(ZBEE_ZCL_CMD_ID_TUN_ACK_TRANSFER_DATA_TX,               0x03, "Ack Transfer Data" ) \
1517     XXX(ZBEE_ZCL_CMD_ID_TUN_READY_DATA_TX,                      0x04, "Ready Data" ) \
1518     XXX(ZBEE_ZCL_CMD_ID_TUN_GET_SUPPORTED_PROTOCOLS_RSP,        0x05, "Get Supported Tunnel Protocols" ) \
1519     XXX(ZBEE_ZCL_CMD_ID_TUN_CLOSURE_NOTIFY,                     0x06, "Tunnel Closure Notification" )
1520
1521 VALUE_STRING_ENUM(zbee_zcl_tun_srv_tx_cmd_names);
1522 VALUE_STRING_ARRAY(zbee_zcl_tun_srv_tx_cmd_names);
1523
1524 /*************************/
1525 /* Function Declarations */
1526 /*************************/
1527 void proto_register_zbee_zcl_tun(void);
1528 void proto_reg_handoff_zbee_zcl_tun(void);
1529
1530 /* Attribute Dissector Helpers */
1531 static void dissect_zcl_tun_attr_data  (proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type);
1532
1533 /* Private functions prototype */
1534
1535 /*************************/
1536 /* Global Variables      */
1537 /*************************/
1538
1539 static dissector_handle_t tun_handle;
1540
1541 /* Initialize the protocol and registered fields */
1542 static int proto_zbee_zcl_tun = -1;
1543
1544 static int hf_zbee_zcl_tun_srv_tx_cmd_id = -1;
1545 static int hf_zbee_zcl_tun_srv_rx_cmd_id = -1;
1546 static int hf_zbee_zcl_tun_attr_id = -1;
1547 static int hf_zbee_zcl_tun_attr_reporting_status = -1;
1548 static int hf_zbee_zcl_tun_attr_close_timeout = -1;
1549 static int hf_zbee_zcl_tun_protocol_id = -1;
1550 static int hf_zbee_zcl_tun_manufacturer_code = -1;
1551 static int hf_zbee_zcl_tun_flow_control_support = -1;
1552 static int hf_zbee_zcl_tun_max_in_size = -1;
1553 static int hf_zbee_zcl_tun_tunnel_id = -1;
1554 static int hf_zbee_zcl_tun_num_octets_left = -1;
1555 static int hf_zbee_zcl_tun_protocol_offset = -1;
1556 static int hf_zbee_zcl_tun_protocol_list_complete = -1;
1557 static int hf_zbee_zcl_tun_protocol_count = -1;
1558 static int hf_zbee_zcl_tun_transfer_status = -1;
1559 static int hf_zbee_zcl_tun_transfer_data = -1;
1560 static int hf_zbee_zcl_tun_transfer_data_status = -1;
1561
1562 /* Initialize the subtree pointers */
1563 static gint ett_zbee_zcl_tun = -1;
1564
1565 /* Subdissector handles. */
1566 static dissector_handle_t       ipv4_handle;
1567 static dissector_handle_t       ipv6_handle;
1568
1569 #define zbee_zcl_tun_protocol_names_VALUE_STRING_LIST(XXX) \
1570     XXX(ZBEE_ZCL_TUN_PROTO_DLMS,                                0x00, "DLMS/COSEM (IEC 62056)" ) \
1571     XXX(ZBEE_ZCL_TUN_PROTO_IEC_61107,                           0x01, "IEC 61107" ) \
1572     XXX(ZBEE_ZCL_TUN_PROTO_ANSI_C12,                            0x02, "ANSI C12" ) \
1573     XXX(ZBEE_ZCL_TUN_PROTO_M_BUS,                               0x03, "M-BUS" ) \
1574     XXX(ZBEE_ZCL_TUN_PROTO_SML,                                 0x04, "SML" ) \
1575     XXX(ZBEE_ZCL_TUN_PROTO_CLIMATE_TALK,                        0x05, "ClimateTalk" ) \
1576     XXX(ZBEE_ZCL_TUN_PROTO_GB_HRGP,                             0x06, "GB-HRGP" ) \
1577     XXX(ZBEE_ZCL_TUN_PROTO_IPV6,                                0x07, "IPv6" ) \
1578     XXX(ZBEE_ZCL_TUN_PROTO_IPV4,                                0x08, "IPv4" ) \
1579     XXX(ZBEE_ZCL_TUN_PROTO_NULL,                                0x09, "null" ) \
1580     XXX(ZBEE_ZCL_TUN_PROTO_TEST,                                 199, "test" ) \
1581     XXX(ZBEE_ZCL_TUN_PROTO_MANUFACTURER,                         200, "Manufacturer Specific" ) \
1582     XXX(ZBEE_ZCL_TUN_PROTO_RESERVED,                            0xFF, "Reserved" )
1583
1584 VALUE_STRING_ENUM(zbee_zcl_tun_protocol_names);
1585 VALUE_STRING_ARRAY(zbee_zcl_tun_protocol_names);
1586
1587 #define zbee_zcl_tun_trans_data_status_names_VALUE_STRING_LIST(XXX) \
1588     XXX(ZBEE_ZCL_TUN_TRANS_STATUS_NO_TUNNEL,                    0x00, "Tunnel ID Does Not Exist" ) \
1589     XXX(ZBEE_ZCL_TUN_TRANS_STATUS_WRONG_DEV,                    0x01, "Wrong Device" ) \
1590     XXX(ZBEE_ZCL_TUN_TRANS_STATUS_OVERFLOW,                     0x02, "Data Overflow" )
1591
1592 VALUE_STRING_ENUM(zbee_zcl_tun_trans_data_status_names);
1593 VALUE_STRING_ARRAY(zbee_zcl_tun_trans_data_status_names);
1594
1595 #define zbee_zcl_tun_status_names_VALUE_STRING_LIST(XXX) \
1596     XXX(ZBEE_ZCL_TUN_STATUS_SUCCESS,                            0x00, "Success" ) \
1597     XXX(ZBEE_ZCL_TUN_STATUS_BUSY,                               0x01, "Busy" ) \
1598     XXX(ZBEE_ZCL_TUN_STATUS_NO_MORE_IDS,                        0x02, "No More Tunnel IDs" ) \
1599     XXX(ZBEE_ZCL_TUN_STATUS_PROTO_NOT_SUPP,                     0x03, "Protocol Not Supported" ) \
1600     XXX(ZBEE_ZCL_TUN_STATUS_FLOW_CONTROL_NOT_SUPP,              0x04, "Flow Control Not Supported" )
1601
1602 VALUE_STRING_ENUM(zbee_zcl_tun_status_names);
1603 VALUE_STRING_ARRAY(zbee_zcl_tun_status_names);
1604
1605 /*************************/
1606 /* Function Bodies       */
1607 /*************************/
1608
1609 /**
1610  *This function is called by ZCL foundation dissector in order to decode
1611  *
1612  *@param tree pointer to data tree Wireshark uses to display packet.
1613  *@param tvb pointer to buffer containing raw packet.
1614  *@param offset pointer to buffer offset
1615  *@param attr_id attribute identifier
1616  *@param data_type attribute data type
1617 */
1618 static void
1619 dissect_zcl_tun_attr_data(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type)
1620 {
1621     switch (attr_id) {
1622         /* cluster specific attributes */
1623         case ZBEE_ZCL_ATTR_ID_TUN_CLOSE_TIMEOUT:
1624             proto_tree_add_item(tree, hf_zbee_zcl_tun_attr_close_timeout, tvb, *offset, 2, ENC_NA);
1625             *offset += 2;
1626             break;
1627
1628         /* applies to all SE clusters */
1629         case ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_TUN:
1630             proto_tree_add_item(tree, hf_zbee_zcl_tun_attr_reporting_status, tvb, *offset, 1, ENC_NA);
1631             *offset += 1;
1632             break;
1633
1634         default: /* Catch all */
1635             dissect_zcl_attr_data(tvb, tree, offset, data_type);
1636             break;
1637     }
1638 } /*dissect_zcl_ias_zone_attr_data*/
1639
1640 /**
1641  *This function manages the Display Message payload
1642  *
1643  *@param tvb pointer to buffer containing raw packet.
1644  *@param tree pointer to data tree Wireshark uses to display packet.
1645  *@param offset pointer to offset from caller
1646 */
1647 static void
1648 dissect_zcl_tun_request_tunnel(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1649 {
1650     proto_tree_add_item(tree, hf_zbee_zcl_tun_protocol_id, tvb, *offset, 1, ENC_NA);
1651     *offset += 1;
1652
1653     proto_tree_add_item(tree, hf_zbee_zcl_tun_manufacturer_code, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1654     *offset += 2;
1655
1656     proto_tree_add_item(tree, hf_zbee_zcl_tun_flow_control_support, tvb, *offset, 1, ENC_NA);
1657     *offset += 1;
1658
1659     proto_tree_add_item(tree, hf_zbee_zcl_tun_max_in_size, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1660     *offset += 2;
1661 }
1662
1663 /**
1664  *This function manages the Display Message payload
1665  *
1666  *@param tvb pointer to buffer containing raw packet.
1667  *@param tree pointer to data tree Wireshark uses to display packet.
1668  *@param offset pointer to offset from caller
1669 */
1670 static void
1671 dissect_zcl_tun_close_tunnel(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1672 {
1673     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1674     *offset += 2;
1675 }
1676
1677 /**
1678  *This function manages the Display Message payload
1679  *
1680  *@param tvb pointer to buffer containing raw packet.
1681  *@param tree pointer to data tree Wireshark uses to display packet.
1682  *@param offset pointer to offset from caller
1683 */
1684 static void
1685 dissect_zcl_tun_transfer_data(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1686 {
1687     gint length;
1688
1689     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1690     *offset += 2;
1691
1692     length = tvb_reported_length_remaining(tvb, *offset);
1693     proto_tree_add_item(tree, hf_zbee_zcl_tun_transfer_data, tvb, *offset, length, ENC_NA);
1694     *offset += length;
1695 }
1696
1697 /**
1698  *This function manages the Display Message payload
1699  *
1700  *@param tvb pointer to buffer containing raw packet.
1701  *@param tree pointer to data tree Wireshark uses to display packet.
1702  *@param offset pointer to offset from caller
1703 */
1704 static void
1705 dissect_zcl_tun_transfer_data_error(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1706 {
1707     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1708     *offset += 2;
1709
1710     proto_tree_add_item(tree, hf_zbee_zcl_tun_transfer_data_status, tvb, *offset, 1, ENC_NA);
1711     *offset += 1;
1712 }
1713
1714 /**
1715  *This function manages the Display Message payload
1716  *
1717  *@param tvb pointer to buffer containing raw packet.
1718  *@param tree pointer to data tree Wireshark uses to display packet.
1719  *@param offset pointer to offset from caller
1720 */
1721 static void
1722 dissect_zcl_tun_ack_transfer_data(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1723 {
1724     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1725     *offset += 2;
1726
1727     proto_tree_add_item(tree, hf_zbee_zcl_tun_num_octets_left, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1728     *offset += 2;
1729 }
1730
1731 /**
1732  *This function manages the Display Message payload
1733  *
1734  *@param tvb pointer to buffer containing raw packet.
1735  *@param tree pointer to data tree Wireshark uses to display packet.
1736  *@param offset pointer to offset from caller
1737 */
1738 static void
1739 dissect_zcl_tun_ready_data(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1740 {
1741     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1742     *offset += 2;
1743
1744     proto_tree_add_item(tree, hf_zbee_zcl_tun_num_octets_left, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1745     *offset += 2;
1746 }
1747
1748 /**
1749  *This function manages the Display Message payload
1750  *
1751  *@param tvb pointer to buffer containing raw packet.
1752  *@param tree pointer to data tree Wireshark uses to display packet.
1753  *@param offset pointer to offset from caller
1754 */
1755 static void
1756 dissect_zcl_tun_get_supported(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1757 {
1758     proto_tree_add_item(tree, hf_zbee_zcl_tun_protocol_offset, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1759     *offset += 2;
1760 }
1761
1762 /**
1763  *This function manages the Display Message payload
1764  *
1765  *@param tvb pointer to buffer containing raw packet.
1766  *@param tree pointer to data tree Wireshark uses to display packet.
1767  *@param offset pointer to offset from caller
1768 */
1769 static void
1770 dissect_zcl_tun_request_tunnel_rsp(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1771 {
1772     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1773     *offset += 2;
1774
1775     proto_tree_add_item(tree, hf_zbee_zcl_tun_transfer_status, tvb, *offset, 1, ENC_NA);
1776     *offset += 1;
1777
1778     proto_tree_add_item(tree, hf_zbee_zcl_tun_max_in_size, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1779     *offset += 2;
1780 }
1781
1782 /**
1783  *This function manages the Display Message payload
1784  *
1785  *@param tvb pointer to buffer containing raw packet.
1786  *@param tree pointer to data tree Wireshark uses to display packet.
1787  *@param offset pointer to offset from caller
1788 */
1789 static void
1790 dissect_zcl_tun_get_supported_rsp(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1791 {
1792     guint16     mfg_code;
1793
1794     proto_tree_add_item(tree, hf_zbee_zcl_tun_protocol_list_complete, tvb, *offset, 1, ENC_NA);
1795     *offset += 1;
1796
1797     proto_tree_add_item(tree, hf_zbee_zcl_tun_protocol_count, tvb, *offset, 1, ENC_NA);
1798     *offset += 1;
1799
1800     while (tvb_reported_length_remaining(tvb, *offset) > 0) {
1801         mfg_code = tvb_get_letohs(tvb, *offset);
1802         if (mfg_code == 0xFFFF) {
1803             proto_tree_add_string(tree, hf_zbee_zcl_tun_manufacturer_code, tvb, *offset, 2, "Standard Protocol (Mfg Code 0xFFFF)");
1804         }
1805         else {
1806             proto_tree_add_item(tree, hf_zbee_zcl_tun_manufacturer_code, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1807         }
1808         *offset += 2;
1809
1810         proto_tree_add_item(tree, hf_zbee_zcl_tun_protocol_id, tvb, *offset, 1, ENC_NA);
1811         *offset += 1;
1812     }
1813 }
1814
1815 /**
1816  *This function manages the Display Message payload
1817  *
1818  *@param tvb pointer to buffer containing raw packet.
1819  *@param tree pointer to data tree Wireshark uses to display packet.
1820  *@param offset pointer to offset from caller
1821 */
1822 static void
1823 dissect_zcl_tun_closure_notify(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1824 {
1825     proto_tree_add_item(tree, hf_zbee_zcl_tun_tunnel_id, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
1826     *offset += 2;
1827 }
1828
1829 /**
1830  *ZigBee ZCL Messaging cluster dissector for wireshark.
1831  *
1832  *@param tvb pointer to buffer containing raw packet.
1833  *@param pinfo pointer to packet information fields
1834  *@param tree pointer to data tree Wireshark uses to display packet.
1835 */
1836 static int
1837 dissect_zbee_zcl_tun(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
1838 {
1839     proto_tree        *payload_tree;
1840     zbee_zcl_packet   *zcl;
1841     guint             offset = 0;
1842     guint8            cmd_id;
1843     gint              rem_len;
1844
1845     /* Reject the packet if data is NULL */
1846     if (data == NULL)
1847         return 0;
1848     zcl = (zbee_zcl_packet *)data;
1849     cmd_id = zcl->cmd_id;
1850
1851     /*  Create a subtree for the ZCL Command frame, and add the command ID to it. */
1852     if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) {
1853         /* Append the command name to the info column. */
1854         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
1855             val_to_str_const(cmd_id, zbee_zcl_tun_srv_rx_cmd_names, "Unknown Command"),
1856             zcl->tran_seqno);
1857
1858         /* Add the command ID. */
1859         proto_tree_add_uint(tree, hf_zbee_zcl_tun_srv_rx_cmd_id, tvb, offset, 1, cmd_id);
1860
1861         /* Check is this command has a payload, than add the payload tree */
1862         rem_len = tvb_reported_length_remaining(tvb, ++offset);
1863         if (rem_len > 0) {
1864             payload_tree = proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_tun, NULL, "Payload");
1865
1866             /* Call the appropriate command dissector */
1867             switch (cmd_id) {
1868
1869                 case ZBEE_ZCL_CMD_ID_TUN_REQUEST_TUNNEL:
1870                     dissect_zcl_tun_request_tunnel(tvb, payload_tree, &offset);
1871                     break;
1872
1873                 case ZBEE_ZCL_CMD_ID_TUN_CLOSE_TUNNEL:
1874                     dissect_zcl_tun_close_tunnel(tvb, payload_tree, &offset);
1875                     break;
1876
1877                 case ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA:
1878                     dissect_zcl_tun_transfer_data(tvb, payload_tree, &offset);
1879                     break;
1880
1881                 case ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA_ERROR:
1882                     dissect_zcl_tun_transfer_data_error(tvb, payload_tree, &offset);
1883                     break;
1884
1885                 case ZBEE_ZCL_CMD_ID_TUN_ACK_TRANSFER_DATA:
1886                     dissect_zcl_tun_ack_transfer_data(tvb, payload_tree, &offset);
1887                     break;
1888
1889                 case ZBEE_ZCL_CMD_ID_TUN_READY_DATA:
1890                     dissect_zcl_tun_ready_data(tvb, payload_tree, &offset);
1891                     break;
1892
1893                 case ZBEE_ZCL_CMD_ID_TUN_GET_SUPPORTED_PROTOCOLS:
1894                     dissect_zcl_tun_get_supported(tvb, payload_tree, &offset);
1895                     break;
1896
1897                 default:
1898                     break;
1899             }
1900         }
1901     }
1902     else { /* ZBEE_ZCL_FCF_TO_CLIENT */
1903         /* Append the command name to the info column. */
1904         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
1905             val_to_str_const(cmd_id, zbee_zcl_tun_srv_tx_cmd_names, "Unknown Command"),
1906             zcl->tran_seqno);
1907
1908         /* Add the command ID. */
1909         proto_tree_add_uint(tree, hf_zbee_zcl_tun_srv_tx_cmd_id, tvb, offset, 1, cmd_id);
1910
1911         /* Check is this command has a payload, than add the payload tree */
1912         rem_len = tvb_reported_length_remaining(tvb, ++offset);
1913         if (rem_len > 0) {
1914             payload_tree = proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_tun, NULL, "Payload");
1915
1916             /* Call the appropriate command dissector */
1917             switch (cmd_id) {
1918
1919                 case ZBEE_ZCL_CMD_ID_TUN_REQUEST_TUNNEL_RSP:
1920                     dissect_zcl_tun_request_tunnel_rsp(tvb, payload_tree, &offset);
1921                     break;
1922
1923                 case ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA_TX:
1924                     dissect_zcl_tun_transfer_data(tvb, payload_tree, &offset);
1925                     break;
1926
1927                 case ZBEE_ZCL_CMD_ID_TUN_TRANSFER_DATA_ERROR_TX:
1928                     dissect_zcl_tun_transfer_data_error(tvb, payload_tree, &offset);
1929                     break;
1930
1931                 case ZBEE_ZCL_CMD_ID_TUN_ACK_TRANSFER_DATA_TX:
1932                     dissect_zcl_tun_ack_transfer_data(tvb, payload_tree, &offset);
1933                     break;
1934
1935                 case ZBEE_ZCL_CMD_ID_TUN_READY_DATA_TX:
1936                     dissect_zcl_tun_ready_data(tvb, payload_tree, &offset);
1937                     break;
1938
1939                 case ZBEE_ZCL_CMD_ID_TUN_GET_SUPPORTED_PROTOCOLS_RSP:
1940                     dissect_zcl_tun_get_supported_rsp(tvb, payload_tree, &offset);
1941                     break;
1942
1943                 case ZBEE_ZCL_CMD_ID_TUN_CLOSURE_NOTIFY:
1944                     dissect_zcl_tun_closure_notify(tvb, payload_tree, &offset);
1945                     break;
1946
1947                 default:
1948                     break;
1949             }
1950         }
1951     }
1952
1953     return tvb_captured_length(tvb);
1954 } /*dissect_zbee_zcl_tun*/
1955
1956 /**
1957  *This function registers the ZCL Messaging dissector
1958  *
1959 */
1960 void
1961 proto_register_zbee_zcl_tun(void)
1962 {
1963     static hf_register_info hf[] = {
1964
1965         { &hf_zbee_zcl_tun_attr_id,
1966             { "Attribute", "zbee_zcl_se.tun.attr_id", FT_UINT16, BASE_HEX, VALS(zbee_zcl_tun_attr_names),
1967             0x0, NULL, HFILL } },
1968
1969         { &hf_zbee_zcl_tun_attr_reporting_status,                         /* common to all SE clusters */
1970             { "Attribute Reporting Status", "zbee_zcl_se.tun.attr.attr_reporting_status",
1971             FT_UINT8, BASE_HEX, VALS(zbee_zcl_se_reporting_status_names), 0x00, NULL, HFILL } },
1972
1973         { &hf_zbee_zcl_tun_attr_close_timeout,
1974             { "Close Tunnel Timeout", "zbee_zcl_se.tun.attr.close_tunnel", FT_UINT16, BASE_DEC, NULL,
1975             0x0, NULL, HFILL } },
1976
1977         { &hf_zbee_zcl_tun_srv_tx_cmd_id,
1978             { "Command", "zbee_zcl_se.tun.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_tun_srv_tx_cmd_names),
1979             0x00, NULL, HFILL } },
1980
1981         { &hf_zbee_zcl_tun_srv_rx_cmd_id,
1982             { "Command", "zbee_zcl_se.tun.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_tun_srv_rx_cmd_names),
1983             0x00, NULL, HFILL } },
1984
1985         { &hf_zbee_zcl_tun_protocol_id,
1986             { "Protocol ID", "zbee_zcl_se.tun.protocol_id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_tun_protocol_names),
1987             0x00, NULL, HFILL } },
1988
1989         { &hf_zbee_zcl_tun_manufacturer_code,
1990             { "Manufacturer Code", "zbee_zcl_se.tun.manufacturer_code", FT_UINT16, BASE_HEX, VALS(zbee_mfr_code_names),
1991             0x00, NULL, HFILL } },
1992
1993         { &hf_zbee_zcl_tun_flow_control_support,
1994             { "Flow Control Supported", "zbee_zcl_se.tun.flow_control_supported", FT_BOOLEAN, 8, TFS(&tfs_true_false),
1995             0x00, NULL, HFILL } },
1996
1997         { &hf_zbee_zcl_tun_max_in_size,
1998             { "Max Incoming Transfer Size", "zbee_zcl_se.tun.max_in_transfer_size", FT_UINT16, BASE_HEX, NULL,
1999             0x00, NULL, HFILL } },
2000
2001         { &hf_zbee_zcl_tun_tunnel_id,
2002             { "Tunnel Id", "zbee_zcl_se.tun.tunnel_id", FT_UINT16, BASE_HEX, NULL,
2003             0x00, NULL, HFILL } },
2004
2005         { &hf_zbee_zcl_tun_num_octets_left,
2006             { "Num Octets Left", "zbee_zcl_se.tun.octets_left", FT_UINT16, BASE_HEX, NULL,
2007             0x00, NULL, HFILL } },
2008
2009         { &hf_zbee_zcl_tun_protocol_offset,
2010             { "Protocol Offset", "zbee_zcl_se.tun.protocol_offset", FT_UINT8, BASE_HEX, NULL,
2011             0x00, NULL, HFILL } },
2012
2013         { &hf_zbee_zcl_tun_transfer_status,
2014             { "Transfer Status", "zbee_zcl_se.tun.transfer_status", FT_UINT8, BASE_HEX, VALS(zbee_zcl_tun_status_names),
2015             0x00, NULL, HFILL } },
2016
2017         { &hf_zbee_zcl_tun_transfer_data,
2018             { "Transfer Data", "zbee_zcl_se.tun.transfer_data", FT_BYTES, BASE_NONE, NULL,
2019             0, NULL, HFILL } },
2020
2021         { &hf_zbee_zcl_tun_transfer_data_status,
2022             { "Transfer Data Status", "zbee_zcl_se.tun.transfer_data_status", FT_UINT8, BASE_HEX, VALS(zbee_zcl_tun_trans_data_status_names),
2023             0x00, NULL, HFILL } },
2024
2025         { &hf_zbee_zcl_tun_protocol_count,
2026             { "Protocol Count", "zbee_zcl_se.tun.protocol_count", FT_UINT8, BASE_HEX, NULL,
2027             0x00, NULL, HFILL } },
2028
2029         { &hf_zbee_zcl_tun_protocol_list_complete,
2030             { "List Complete", "zbee_zcl_se.tun.protocol_list_complete", FT_BOOLEAN, 8, TFS(&tfs_true_false),
2031             0x00, NULL, HFILL } },
2032
2033     };
2034
2035     /* ZCL Messaging subtrees */
2036     gint *ett[] = {
2037         &ett_zbee_zcl_tun,
2038     };
2039
2040     /* Register the ZigBee ZCL Messaging cluster protocol name and description */
2041     proto_zbee_zcl_tun = proto_register_protocol("ZigBee ZCL Tunneling", "ZCL Tunneling", ZBEE_PROTOABBREV_ZCL_TUN);
2042     proto_register_field_array(proto_zbee_zcl_tun, hf, array_length(hf));
2043     proto_register_subtree_array(ett, array_length(ett));
2044
2045     /* Register the ZigBee ZCL Messaging dissector. */
2046     tun_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_TUN, dissect_zbee_zcl_tun, proto_zbee_zcl_tun);
2047
2048 } /* proto_register_zbee_zcl_tun */
2049
2050 /**
2051  *Hands off the Zcl Messaging dissector.
2052  *
2053 */
2054 void
2055 proto_reg_handoff_zbee_zcl_tun(void)
2056 {
2057     ipv4_handle = find_dissector("ipv4");
2058     ipv6_handle = find_dissector("ipv6");
2059
2060     /* Register our dissector with the ZigBee application dissectors. */
2061     dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_TUNNELING, tun_handle);
2062
2063     zbee_zcl_init_cluster(  proto_zbee_zcl_tun,
2064                             ett_zbee_zcl_tun,
2065                             ZBEE_ZCL_CID_TUNNELING,
2066                             hf_zbee_zcl_tun_attr_id,
2067                             hf_zbee_zcl_tun_srv_rx_cmd_id,
2068                             hf_zbee_zcl_tun_srv_tx_cmd_id,
2069                             (zbee_zcl_fn_attr_data)dissect_zcl_tun_attr_data
2070                          );
2071 } /* proto_reg_handoff_zbee_zcl_tun */
2072
2073
2074 /* ########################################################################## */
2075 /* #### (0x0705) PREPAYMENT CLUSTER ########################################## */
2076 /* ########################################################################## */
2077
2078 /* Attributes */
2079 #define zbee_zcl_pp_attr_names_VALUE_STRING_LIST(XXX) \
2080 /* Prepayment Information Set */ \
2081     XXX(ZBEE_ZCL_ATTR_ID_PP_PAYMENT_CONTROL_CONFIGURATION,      0x0000, "Payment Control Configuration" ) \
2082     XXX(ZBEE_ZCL_ATTR_ID_PP_CREDIT_REMAINING,                   0x0001, "Credit Remaining" ) \
2083     XXX(ZBEE_ZCL_ATTR_ID_PP_EMERGENCY_CREDIT_REMAINING,         0x0002, "Emergency Credit Remaining" ) \
2084     XXX(ZBEE_ZCL_ATTR_ID_PP_ACCUMULATED_DEBT,                   0x0005, "Accumulated Debt" ) \
2085     XXX(ZBEE_ZCL_ATTR_ID_PP_OVERALL_DEBT_CAP,                   0x0006, "Overall Debt Cap" ) \
2086     XXX(ZBEE_ZCL_ATTR_ID_PP_EMERGENCY_CREDIT_LIMIT,             0x0010, "Emergency Credit Limit / Allowance" ) \
2087     XXX(ZBEE_ZCL_ATTR_ID_PP_EMERGENCY_CREDIT_THRESHOLD,         0x0011, "Emergency Credit Threshold" ) \
2088     XXX(ZBEE_ZCL_ATTR_ID_PP_MAX_CREDIT_LIMIT,                   0x0021, "Max Credit Limit" ) \
2089     XXX(ZBEE_ZCL_ATTR_ID_PP_MAX_CREDIT_PER_TOPUP,               0x0022, "Max Credit Per Top Up" ) \
2090     XXX(ZBEE_ZCL_ATTR_ID_PP_LOW_CREDIT_WARNING,                 0x0031, "Low Credit Warning" ) \
2091     XXX(ZBEE_ZCL_ATTR_ID_PP_CUT_OFF_VALUE,                      0x0040, "Cut Off Value" ) \
2092 /* Debt Set */ \
2093     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_AMOUNT_1,                      0x0211, "Debt Amount 1" ) \
2094     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_FREQ_1,               0x0216, "Debt Recovery Frequency 1" ) \
2095     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_AMOUNT_1,             0x0217, "Debt Recovery Amount 1" ) \
2096     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_TOP_UP_PERCENTAGE_1,  0x0219, "Debt Recovery Top Up Percentage 1" ) \
2097     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_AMOUNT_2,                      0x0221, "Debt Amount 2" ) \
2098     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_FREQ_2,               0x0226, "Debt Recovery Frequency 2" ) \
2099     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_AMOUNT_2,             0x0227, "Debt Recovery Amount 2" ) \
2100     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_TOP_UP_PERCENTAGE_2,  0x0229, "Debt Recovery Top Up Percentage 2" ) \
2101     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_AMOUNT_3,                      0x0231, "Debt Amount 3" ) \
2102     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_FREQ_3,               0x0236, "Debt Recovery Frequency 3" ) \
2103     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_AMOUNT_3,             0x0237, "Debt Recovery Amount 3" ) \
2104     XXX(ZBEE_ZCL_ATTR_ID_PP_DEBT_RECOVERY_TOP_UP_PERCENTAGE_3,  0x0239, "Debt Recovery Top Up Percentage 3" ) \
2105 /* Alarm Set */ \
2106     XXX(ZBEE_ZCL_ATTR_ID_PP_PREPAYMENT_ALARM_STATUS,            0x0400, "Prepayment Alarm Status" ) \
2107 /* Historical Cost Consumption Information Set */ \
2108     XXX(ZBEE_ZCL_ATTR_ID_PP_HISTORICAL_COST_CON_FORMAT,         0x0500, "Historical Cost Consumption Formatting" ) \
2109     XXX(ZBEE_ZCL_ATTR_ID_PP_CONSUMPTION_UNIT_OF_MEASUREMENT,    0x0501, "Consumption Unit of Measurement" ) \
2110     XXX(ZBEE_ZCL_ATTR_ID_PP_CURRENCY_SCALING_FACTOR,            0x0502, "Currency Scaling Factor" ) \
2111     XXX(ZBEE_ZCL_ATTR_ID_PP_CURRENCY,                           0x0503, "Currency" ) \
2112     XXX(ZBEE_ZCL_ATTR_ID_PP_CURRENT_DAY_COST_CON_DELIVERED,     0x051C, "Current Day Cost Consumption Delivered" ) \
2113     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_COST_CON_DELIVERED,    0x051E, "Previous Day Cost Consumption Delivered" ) \
2114     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_2_COST_CON_DELIVERED,  0x0520, "Previous Day 2 Cost Consumption Delivered" ) \
2115     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_3_COST_CON_DELIVERED,  0x0522, "Previous Day 3 Cost Consumption Delivered" ) \
2116     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_4_COST_CON_DELIVERED,  0x0524, "Previous Day 4 Cost Consumption Delivered" ) \
2117     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_5_COST_CON_DELIVERED,  0x0526, "Previous Day 5 Cost Consumption Delivered" ) \
2118     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_6_COST_CON_DELIVERED,  0x0528, "Previous Day 6 Cost Consumption Delivered" ) \
2119     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_7_COST_CON_DELIVERED,  0x052A, "Previous Day 7 Cost Consumption Delivered" ) \
2120     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_DAY_8_COST_CON_DELIVERED,  0x052C, "Previous Day 8 Cost Consumption Delivered" ) \
2121     XXX(ZBEE_ZCL_ATTR_ID_PP_CURRENT_WEEK_COST_CON_DELIVERED,    0x0530, "Current Week Cost Consumption Delivered" ) \
2122     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_WEEK_COST_CON_DELIVERED,   0x0532, "Previous Week Cost Consumption Delivered" ) \
2123     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_WEEK_2_COST_CON_DELIVERED, 0x0534, "Previous Week 2 Cost Consumption Delivered" ) \
2124     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_WEEK_3_COST_CON_DELIVERED, 0x0536, "Previous Week 3 Cost Consumption Delivered" ) \
2125     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_WEEK_4_COST_CON_DELIVERED, 0x0538, "Previous Week 4 Cost Consumption Delivered" ) \
2126     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_WEEK_5_COST_CON_DELIVERED, 0x053A, "Previous Week 5 Cost Consumption Delivered" ) \
2127     XXX(ZBEE_ZCL_ATTR_ID_PP_CURRENT_MON_COST_CON_DELIVERED,     0x0540, "Current Month Cost Consumption Delivered" ) \
2128     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_COST_CON_DELIVERED,    0x0542, "Previous Month Cost Consumption Delivered" ) \
2129     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_2_COST_CON_DELIVERED,  0x0544, "Previous Month 2 Cost Consumption Delivered" ) \
2130     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_3_COST_CON_DELIVERED,  0x0546, "Previous Month 3 Cost Consumption Delivered" ) \
2131     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_4_COST_CON_DELIVERED,  0x0548, "Previous Month 4 Cost Consumption Delivered" ) \
2132     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_5_COST_CON_DELIVERED,  0x054A, "Previous Month 5 Cost Consumption Delivered" ) \
2133     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_6_COST_CON_DELIVERED,  0x054C, "Previous Month 6 Cost Consumption Delivered" ) \
2134     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_7_COST_CON_DELIVERED,  0x054E, "Previous Month 7 Cost Consumption Delivered" ) \
2135     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_8_COST_CON_DELIVERED,  0x0550, "Previous Month 8 Cost Consumption Delivered" ) \
2136     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_9_COST_CON_DELIVERED,  0x0552, "Previous Month 9 Cost Consumption Delivered" ) \
2137     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_10_COST_CON_DELIVERED, 0x0554, "Previous Month 10 Cost Consumption Delivered" ) \
2138     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_11_COST_CON_DELIVERED, 0x0556, "Previous Month 11 Cost Consumption Delivered" ) \
2139     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_12_COST_CON_DELIVERED, 0x0558, "Previous Month 12 Cost Consumption Delivered" ) \
2140     XXX(ZBEE_ZCL_ATTR_ID_PP_PREVIOUS_MON_13_COST_CON_DELIVERED, 0x055A, "Previous Month 13 Cost Consumption Delivered" ) \
2141     XXX(ZBEE_ZCL_ATTR_ID_PP_HISTORICAL_FREEZE_TIME,             0x055C, "Historical Freeze Time" ) \
2142 /* Smart Energy */ \
2143     XXX(ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_PP,              0xFFFE, "Attribute Reporting Status" )
2144
2145 VALUE_STRING_ENUM(zbee_zcl_pp_attr_names);
2146 VALUE_STRING_ARRAY(zbee_zcl_pp_attr_names);
2147 static value_string_ext zbee_zcl_pp_attr_names_ext = VALUE_STRING_EXT_INIT(zbee_zcl_pp_attr_names);
2148
2149 /* Server Commands Received */
2150 #define zbee_zcl_pp_srv_rx_cmd_names_VALUE_STRING_LIST(XXX) \
2151     XXX(ZBEE_ZCL_CMD_ID_PP_SELECT_AVAILABLE_EMERGENCY_CREDIT,   0x00, "Select Available Emergency Credit" ) \
2152     XXX(ZBEE_ZCL_CMD_ID_PP_CONSUMER_TOP_UP,                     0x04, "Consumer Top Up" ) \
2153     XXX(ZBEE_ZCL_CMD_ID_PP_GET_PREPAY_SNAPTSHOT,                0x07, "Get Prepay Snapshot" ) \
2154     XXX(ZBEE_ZCL_CMD_ID_PP_GET_TOP_UP_LOG,                      0x08, "Get Top Up Log" ) \
2155     XXX(ZBEE_ZCL_CMD_ID_PP_GET_DEBT_REPAYMENT_LOG,              0x0A, "Get Debt Repayment Log" )
2156
2157 VALUE_STRING_ENUM(zbee_zcl_pp_srv_rx_cmd_names);
2158 VALUE_STRING_ARRAY(zbee_zcl_pp_srv_rx_cmd_names);
2159
2160 /* Server Commands Generated */
2161 #define zbee_zcl_pp_srv_tx_cmd_names_VALUE_STRING_LIST(XXX) \
2162     XXX(ZBEE_ZCL_CMD_ID_PP_PUBLISH_PREPAY_SNAPSHOT,             0x01, "Publish Prepay Snapshot" ) \
2163     XXX(ZBEE_ZCL_CMD_ID_PP_CONSUMER_TOP_UP_RESPONSE,            0x03, "Consumer Top Up Response" ) \
2164     XXX(ZBEE_ZCL_CMD_ID_PP_PUBLISH_TOP_UP_LOG,                  0x05, "Publish Top Up Log" ) \
2165     XXX(ZBEE_ZCL_CMD_ID_PP_PUBLISH_DEBT_LOG,                    0x06, "Publish Debt Log" )
2166
2167 VALUE_STRING_ENUM(zbee_zcl_pp_srv_tx_cmd_names);
2168 VALUE_STRING_ARRAY(zbee_zcl_pp_srv_tx_cmd_names);
2169
2170 /*************************/
2171 /* Function Declarations */
2172 /*************************/
2173 void proto_register_zbee_zcl_pp(void);
2174 void proto_reg_handoff_zbee_zcl_pp(void);
2175
2176 /* Attribute Dissector Helpers */
2177 static void dissect_zcl_pp_attr_data  (proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type);
2178
2179 /*************************/
2180 /* Global Variables      */
2181 /*************************/
2182
2183 static dissector_handle_t pp_handle;
2184
2185 /* Initialize the protocol and registered fields */
2186 static int proto_zbee_zcl_pp = -1;
2187
2188 static int hf_zbee_zcl_pp_srv_tx_cmd_id = -1;
2189 static int hf_zbee_zcl_pp_srv_rx_cmd_id = -1;
2190 static int hf_zbee_zcl_pp_attr_id = -1;
2191 static int hf_zbee_zcl_pp_attr_reporting_status = -1;
2192
2193 /* Initialize the subtree pointers */
2194 static gint ett_zbee_zcl_pp = -1;
2195
2196 /*************************/
2197 /* Function Bodies       */
2198 /*************************/
2199
2200 /**
2201  *This function is called by ZCL foundation dissector in order to decode
2202  *
2203  *@param tree pointer to data tree Wireshark uses to display packet.
2204  *@param tvb pointer to buffer containing raw packet.
2205  *@param offset pointer to buffer offset
2206  *@param attr_id attribute identifier
2207  *@param data_type attribute data type
2208 */
2209 static void
2210 dissect_zcl_pp_attr_data(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type)
2211 {
2212     switch (attr_id) {
2213         /* applies to all SE clusters */
2214         case ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_PP:
2215             proto_tree_add_item(tree, hf_zbee_zcl_pp_attr_reporting_status, tvb, *offset, 1, ENC_NA);
2216             *offset += 1;
2217             break;
2218
2219         default: /* Catch all */
2220             dissect_zcl_attr_data(tvb, tree, offset, data_type);
2221             break;
2222     }
2223 } /*dissect_zcl_pp_attr_data*/
2224
2225 /**
2226  *ZigBee ZCL Prepayment cluster dissector for wireshark.
2227  *
2228  *@param tvb pointer to buffer containing raw packet.
2229  *@param pinfo pointer to packet information fields
2230  *@param tree pointer to data tree Wireshark uses to display packet.
2231 */
2232 static int
2233 dissect_zbee_zcl_pp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
2234 {
2235     zbee_zcl_packet   *zcl;
2236     guint             offset = 0;
2237     guint8            cmd_id;
2238     gint              rem_len;
2239
2240     /* Reject the packet if data is NULL */
2241     if (data == NULL)
2242         return 0;
2243     zcl = (zbee_zcl_packet *)data;
2244     cmd_id = zcl->cmd_id;
2245
2246     /*  Create a subtree for the ZCL Command frame, and add the command ID to it. */
2247     if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) {
2248         /* Append the command name to the info column. */
2249         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
2250             val_to_str_const(cmd_id, zbee_zcl_pp_srv_rx_cmd_names, "Unknown Command"),
2251             zcl->tran_seqno);
2252
2253         /* Add the command ID. */
2254         proto_tree_add_uint(tree, hf_zbee_zcl_pp_srv_rx_cmd_id, tvb, offset, 1, cmd_id);
2255
2256         /* Check is this command has a payload, than add the payload tree */
2257         rem_len = tvb_reported_length_remaining(tvb, ++offset);
2258         if (rem_len > 0) {
2259             proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_pp, NULL, "Payload");
2260
2261             /* Call the appropriate command dissector */
2262             switch (cmd_id) {
2263
2264                 case ZBEE_ZCL_CMD_ID_PP_SELECT_AVAILABLE_EMERGENCY_CREDIT:
2265                     /* Add function to dissect payload */
2266                     break;
2267
2268                 case ZBEE_ZCL_CMD_ID_PP_CONSUMER_TOP_UP:
2269                     /* Add function to dissect payload */
2270                     break;
2271
2272                 case ZBEE_ZCL_CMD_ID_PP_GET_PREPAY_SNAPTSHOT:
2273                     /* Add function to dissect payload */
2274                     break;
2275
2276                 case ZBEE_ZCL_CMD_ID_PP_GET_TOP_UP_LOG:
2277                     /* Add function to dissect payload */
2278                     break;
2279
2280                 case ZBEE_ZCL_CMD_ID_PP_GET_DEBT_REPAYMENT_LOG:
2281                     /* Add function to dissect payload */
2282                     break;
2283
2284                 default:
2285                     break;
2286             }
2287         }
2288     }
2289     else { /* ZBEE_ZCL_FCF_TO_CLIENT */
2290         /* Append the command name to the info column. */
2291         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
2292             val_to_str_const(cmd_id, zbee_zcl_pp_srv_tx_cmd_names, "Unknown Command"),
2293             zcl->tran_seqno);
2294
2295         /* Add the command ID. */
2296         proto_tree_add_uint(tree, hf_zbee_zcl_pp_srv_tx_cmd_id, tvb, offset, 1, cmd_id);
2297
2298         /* Check is this command has a payload, than add the payload tree */
2299         rem_len = tvb_reported_length_remaining(tvb, ++offset);
2300         if (rem_len > 0) {
2301             proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_pp, NULL, "Payload");
2302
2303             /* Call the appropriate command dissector */
2304             switch (cmd_id) {
2305
2306                 case ZBEE_ZCL_CMD_ID_PP_PUBLISH_PREPAY_SNAPSHOT:
2307                     /* Add function to dissect payload */
2308                     break;
2309
2310                 case ZBEE_ZCL_CMD_ID_PP_CONSUMER_TOP_UP_RESPONSE:
2311                     /* Add function to dissect payload */
2312                     break;
2313
2314                 case ZBEE_ZCL_CMD_ID_PP_PUBLISH_TOP_UP_LOG:
2315                     /* Add function to dissect payload */
2316                     break;
2317
2318                 case ZBEE_ZCL_CMD_ID_PP_PUBLISH_DEBT_LOG:
2319                     /* Add function to dissect payload */
2320                     break;
2321
2322                 default:
2323                     break;
2324             }
2325         }
2326     }
2327
2328     return tvb_captured_length(tvb);
2329 } /*dissect_zbee_zcl_pp*/
2330
2331 /**
2332  *This function registers the ZCL Prepayment dissector
2333  *
2334 */
2335 void
2336 proto_register_zbee_zcl_pp(void)
2337 {
2338     static hf_register_info hf[] = {
2339
2340         { &hf_zbee_zcl_pp_attr_id,
2341             { "Attribute", "zbee_zcl_se.pp.attr_id", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &zbee_zcl_pp_attr_names_ext,
2342             0x0, NULL, HFILL } },
2343
2344         { &hf_zbee_zcl_pp_attr_reporting_status,                         /* common to all SE clusters */
2345             { "Attribute Reporting Status", "zbee_zcl_se.pp.attr.attr_reporting_status",
2346             FT_UINT8, BASE_HEX, VALS(zbee_zcl_se_reporting_status_names), 0x00, NULL, HFILL } },
2347
2348         { &hf_zbee_zcl_pp_srv_tx_cmd_id,
2349             { "Command", "zbee_zcl_se.pp.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_pp_srv_tx_cmd_names),
2350             0x00, NULL, HFILL } },
2351
2352         { &hf_zbee_zcl_pp_srv_rx_cmd_id,
2353             { "Command", "zbee_zcl_se.pp.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_pp_srv_rx_cmd_names),
2354             0x00, NULL, HFILL } },
2355
2356     };
2357
2358     /* ZCL Prepayment subtrees */
2359     gint *ett[] = {
2360         &ett_zbee_zcl_pp,
2361     };
2362
2363     /* Register the ZigBee ZCL Prepayment cluster protocol name and description */
2364     proto_zbee_zcl_pp = proto_register_protocol("ZigBee ZCL Prepayment", "ZCL Prepayment", ZBEE_PROTOABBREV_ZCL_PRE_PAYMENT);
2365     proto_register_field_array(proto_zbee_zcl_pp, hf, array_length(hf));
2366     proto_register_subtree_array(ett, array_length(ett));
2367
2368     /* Register the ZigBee ZCL Prepayment dissector. */
2369     pp_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_PRE_PAYMENT, dissect_zbee_zcl_pp, proto_zbee_zcl_pp);
2370 } /*proto_register_zbee_zcl_pp*/
2371
2372 /**
2373  *Hands off the Zcl Prepayment dissector.
2374  *
2375 */
2376 void
2377 proto_reg_handoff_zbee_zcl_pp(void)
2378 {
2379     /* Register our dissector with the ZigBee application dissectors. */
2380     dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_PRE_PAYMENT, pp_handle);
2381
2382     zbee_zcl_init_cluster(  proto_zbee_zcl_pp,
2383                             ett_zbee_zcl_pp,
2384                             ZBEE_ZCL_CID_PRE_PAYMENT,
2385                             hf_zbee_zcl_pp_attr_id,
2386                             hf_zbee_zcl_pp_srv_rx_cmd_id,
2387                             hf_zbee_zcl_pp_srv_tx_cmd_id,
2388                             (zbee_zcl_fn_attr_data)dissect_zcl_pp_attr_data
2389                          );
2390 } /*proto_reg_handoff_zbee_zcl_pp*/
2391
2392 /* ########################################################################## */
2393 /* #### (0x0709) EVENTS CLUSTER ############################################# */
2394 /* ########################################################################## */
2395
2396 /* Attributes */
2397 #define zbee_zcl_events_attr_names_VALUE_STRING_LIST(XXX) \
2398 /* Smart Energy */ \
2399     XXX(ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_EVENTS,          0xFFFE, "Attribute Reporting Status" )
2400
2401 VALUE_STRING_ENUM(zbee_zcl_events_attr_names);
2402 VALUE_STRING_ARRAY(zbee_zcl_events_attr_names);
2403
2404 /* Server Commands Received */
2405 #define zbee_zcl_events_srv_rx_cmd_names_VALUE_STRING_LIST(XXX) \
2406     XXX(ZBEE_ZCL_CMD_ID_EVENTS_GET_EVENT_LOG,                   0x00, "Get Event Log" ) \
2407     XXX(ZBEE_ZCL_CMD_ID_EVENTS_CLEAR_EVENT_LOG_REQUEST,         0x01, "Clear Event Log Request" )
2408
2409 VALUE_STRING_ENUM(zbee_zcl_events_srv_rx_cmd_names);
2410 VALUE_STRING_ARRAY(zbee_zcl_events_srv_rx_cmd_names);
2411
2412 /* Server Commands Generated */
2413 #define zbee_zcl_events_srv_tx_cmd_names_VALUE_STRING_LIST(XXX) \
2414     XXX(ZBEE_ZCL_CMD_ID_EVENTS_PUBLISH_EVENT,                   0x00, "Publish Event" ) \
2415     XXX(ZBEE_ZCL_CMD_ID_EVENTS_PUBLISH_EVENT_LOG,               0x01, "Publish Event Log" ) \
2416     XXX(ZBEE_ZCL_CMD_ID_EVENTS_CLEAR_EVENT_LOG_RESPONSE,        0x02, "Clear Event Log Response" )
2417
2418 VALUE_STRING_ENUM(zbee_zcl_events_srv_tx_cmd_names);
2419 VALUE_STRING_ARRAY(zbee_zcl_events_srv_tx_cmd_names);
2420
2421 /*************************/
2422 /* Function Declarations */
2423 /*************************/
2424 void proto_register_zbee_zcl_events(void);
2425 void proto_reg_handoff_zbee_zcl_events(void);
2426
2427 /* Attribute Dissector Helpers */
2428 static void dissect_zcl_events_attr_data  (proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type);
2429
2430 /*************************/
2431 /* Global Variables      */
2432 /*************************/
2433
2434 static dissector_handle_t events_handle;
2435
2436 /* Initialize the protocol and registered fields */
2437 static int proto_zbee_zcl_events = -1;
2438
2439 static int hf_zbee_zcl_events_srv_tx_cmd_id = -1;
2440 static int hf_zbee_zcl_events_srv_rx_cmd_id = -1;
2441 static int hf_zbee_zcl_events_attr_id = -1;
2442 static int hf_zbee_zcl_events_attr_reporting_status = -1;
2443
2444 /* Initialize the subtree pointers */
2445 static gint ett_zbee_zcl_events = -1;
2446
2447 /*************************/
2448 /* Function Bodies       */
2449 /*************************/
2450
2451 /**
2452  *This function is called by ZCL foundation dissector in order to decode
2453  *
2454  *@param tree pointer to data tree Wireshark uses to display packet.
2455  *@param tvb pointer to buffer containing raw packet.
2456  *@param offset pointer to buffer offset
2457  *@param attr_id attribute identifier
2458  *@param data_type attribute data type
2459 */
2460 static void
2461 dissect_zcl_events_attr_data(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type)
2462 {
2463     switch (attr_id) {
2464         /* applies to all SE clusters */
2465         case ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_EVENTS:
2466             proto_tree_add_item(tree, hf_zbee_zcl_events_attr_reporting_status, tvb, *offset, 1, ENC_NA);
2467             *offset += 1;
2468             break;
2469
2470         default: /* Catch all */
2471             dissect_zcl_attr_data(tvb, tree, offset, data_type);
2472             break;
2473     }
2474 } /*dissect_zcl_events_attr_data*/
2475
2476 /**
2477  *ZigBee ZCL Events cluster dissector for wireshark.
2478  *
2479  *@param tvb pointer to buffer containing raw packet.
2480  *@param pinfo pointer to packet information fields
2481  *@param tree pointer to data tree Wireshark uses to display packet.
2482 */
2483 static int
2484 dissect_zbee_zcl_events(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
2485 {
2486     zbee_zcl_packet   *zcl;
2487     guint             offset = 0;
2488     guint8            cmd_id;
2489     gint              rem_len;
2490
2491     /* Reject the packet if data is NULL */
2492     if (data == NULL)
2493         return 0;
2494     zcl = (zbee_zcl_packet *)data;
2495     cmd_id = zcl->cmd_id;
2496
2497     /*  Create a subtree for the ZCL Command frame, and add the command ID to it. */
2498     if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) {
2499         /* Append the command name to the info column. */
2500         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
2501             val_to_str_const(cmd_id, zbee_zcl_events_srv_rx_cmd_names, "Unknown Command"),
2502             zcl->tran_seqno);
2503
2504         /* Add the command ID. */
2505         proto_tree_add_uint(tree, hf_zbee_zcl_events_srv_rx_cmd_id, tvb, offset, 1, cmd_id);
2506
2507         /* Check is this command has a payload, than add the payload tree */
2508         rem_len = tvb_reported_length_remaining(tvb, ++offset);
2509         if (rem_len > 0) {
2510             proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_events, NULL, "Payload");
2511
2512             /* Call the appropriate command dissector */
2513             switch (cmd_id) {
2514
2515                 case ZBEE_ZCL_CMD_ID_EVENTS_GET_EVENT_LOG:
2516                     /* Add function to dissect payload */
2517                     break;
2518
2519                 case ZBEE_ZCL_CMD_ID_EVENTS_CLEAR_EVENT_LOG_REQUEST:
2520                     /* Add function to dissect payload */
2521                     break;
2522
2523                 default:
2524                     break;
2525             }
2526         }
2527     }
2528     else { /* ZBEE_ZCL_FCF_TO_CLIENT */
2529         /* Append the command name to the info column. */
2530         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
2531             val_to_str_const(cmd_id, zbee_zcl_events_srv_tx_cmd_names, "Unknown Command"),
2532             zcl->tran_seqno);
2533
2534         /* Add the command ID. */
2535         proto_tree_add_uint(tree, hf_zbee_zcl_events_srv_tx_cmd_id, tvb, offset, 1, cmd_id);
2536
2537         /* Check is this command has a payload, than add the payload tree */
2538         rem_len = tvb_reported_length_remaining(tvb, ++offset);
2539         if (rem_len > 0) {
2540             proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_events, NULL, "Payload");
2541
2542             /* Call the appropriate command dissector */
2543             switch (cmd_id) {
2544
2545                 case ZBEE_ZCL_CMD_ID_EVENTS_PUBLISH_EVENT:
2546                     /* Add function to dissect payload */
2547                     break;
2548
2549                 case ZBEE_ZCL_CMD_ID_EVENTS_PUBLISH_EVENT_LOG:
2550                     /* Add function to dissect payload */
2551                     break;
2552
2553                 case ZBEE_ZCL_CMD_ID_EVENTS_CLEAR_EVENT_LOG_RESPONSE:
2554                     /* Add function to dissect payload */
2555                     break;
2556
2557                 default:
2558                     break;
2559             }
2560         }
2561     }
2562
2563     return tvb_captured_length(tvb);
2564 } /*dissect_zbee_zcl_events*/
2565
2566 /**
2567  *This function registers the ZCL Events dissector
2568  *
2569 */
2570 void
2571 proto_register_zbee_zcl_events(void)
2572 {
2573     static hf_register_info hf[] = {
2574
2575         { &hf_zbee_zcl_events_attr_id,
2576             { "Attribute", "zbee_zcl_se.events.attr_id", FT_UINT16, BASE_HEX, VALS(zbee_zcl_events_attr_names),
2577             0x0, NULL, HFILL } },
2578
2579         { &hf_zbee_zcl_events_attr_reporting_status,                         /* common to all SE clusters */
2580             { "Attribute Reporting Status", "zbee_zcl_se.events.attr.attr_reporting_status",
2581             FT_UINT8, BASE_HEX, VALS(zbee_zcl_se_reporting_status_names), 0x00, NULL, HFILL } },
2582
2583         { &hf_zbee_zcl_events_srv_tx_cmd_id,
2584             { "Command", "zbee_zcl_se.events.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_events_srv_tx_cmd_names),
2585             0x00, NULL, HFILL } },
2586
2587         { &hf_zbee_zcl_events_srv_rx_cmd_id,
2588             { "Command", "zbee_zcl_se.events.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_events_srv_rx_cmd_names),
2589             0x00, NULL, HFILL } },
2590
2591     };
2592
2593     /* ZCL Events subtrees */
2594     gint *ett[] = {
2595         &ett_zbee_zcl_events,
2596     };
2597
2598     /* Register the ZigBee ZCL Events cluster protocol name and description */
2599     proto_zbee_zcl_events = proto_register_protocol("ZigBee ZCL Events", "ZCL Events", ZBEE_PROTOABBREV_ZCL_EVENTS);
2600     proto_register_field_array(proto_zbee_zcl_events, hf, array_length(hf));
2601     proto_register_subtree_array(ett, array_length(ett));
2602
2603     /* Register the ZigBee ZCL Events dissector. */
2604     events_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_EVENTS, dissect_zbee_zcl_events, proto_zbee_zcl_events);
2605 } /*proto_register_zbee_zcl_events*/
2606
2607 /**
2608  *Hands off the Zcl Events dissector.
2609  *
2610 */
2611 void
2612 proto_reg_handoff_zbee_zcl_events(void)
2613 {
2614     /* Register our dissector with the ZigBee application dissectors. */
2615     dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_EVENTS, events_handle);
2616
2617     zbee_zcl_init_cluster(  proto_zbee_zcl_events,
2618                             ett_zbee_zcl_events,
2619                             ZBEE_ZCL_CID_EVENTS,
2620                             hf_zbee_zcl_events_attr_id,
2621                             hf_zbee_zcl_events_srv_rx_cmd_id,
2622                             hf_zbee_zcl_events_srv_tx_cmd_id,
2623                             (zbee_zcl_fn_attr_data)dissect_zcl_events_attr_data
2624                          );
2625 } /*proto_reg_handoff_zbee_zcl_events*/
2626
2627 /* ########################################################################## */
2628 /* #### (0x0800) KEY ESTABLISHMENT ########################################## */
2629 /* ########################################################################## */
2630
2631 /*************************/
2632 /* Defines               */
2633 /*************************/
2634
2635 #define ZBEE_ZCL_KE_USAGE_KEY_AGREEMENT                         0x08
2636 #define ZBEE_ZCL_KE_USAGE_DIGITAL_SIGNATURE                     0x80
2637
2638 /* Attributes */
2639 #define zbee_zcl_ke_attr_names_VALUE_STRING_LIST(XXX) \
2640     XXX(ZBEE_ZCL_ATTR_ID_KE_SUITE,                              0x0000, "Supported Key Establishment Suites" )
2641
2642 VALUE_STRING_ARRAY(zbee_zcl_ke_attr_names);
2643
2644 /* Server Commands Received and Generated */
2645 #define zbee_zcl_ke_srv_cmd_names_VALUE_STRING_LIST(XXX) \
2646     XXX(ZBEE_ZCL_CMD_ID_KE_INITIATE,                            0x00, "Initiate Key Establishment" ) \
2647     XXX(ZBEE_ZCL_CMD_ID_KE_EPHEMERAL,                           0x01, "Ephemeral Data" ) \
2648     XXX(ZBEE_ZCL_CMD_ID_KE_CONFIRM,                             0x02, "Confirm Key Data" ) \
2649     XXX(ZBEE_ZCL_CMD_ID_KE_TERMINATE,                           0x03, "Terminate Key Establishment" )
2650
2651 VALUE_STRING_ENUM(zbee_zcl_ke_srv_cmd_names);
2652 VALUE_STRING_ARRAY(zbee_zcl_ke_srv_cmd_names);
2653
2654 /* Suite Names */
2655 #define zbee_zcl_ke_suite_names_VALUE_STRING_LIST(XXX) \
2656     XXX(ZBEE_ZCL_KE_SUITE_1,                                    0x0001, "Crypto Suite 1 (CBKE K163)" ) \
2657     XXX(ZBEE_ZCL_KE_SUITE_2,                                    0x0002, "Crypto Suite 2 (CBKE K283)" )
2658
2659 VALUE_STRING_ENUM(zbee_zcl_ke_suite_names);
2660 VALUE_STRING_ARRAY(zbee_zcl_ke_suite_names);
2661
2662 /* Crypto Suite 2 Type Names */
2663 #define zbee_zcl_ke_type_names_VALUE_STRING_LIST(XXX) \
2664     XXX(ZBEE_ZCL_KE_TYPE_NO_EXT,                                0x00, "No Extensions" )
2665
2666 VALUE_STRING_ARRAY(zbee_zcl_ke_type_names);
2667
2668 /* Crypto Suite 2 Curve Names */
2669 #define zbee_zcl_ke_curve_names_VALUE_STRING_LIST(XXX) \
2670     XXX(ZBEE_ZCL_KE_CURVE_SECT283K1,                            0x0D, "sect283k1" )
2671
2672 VALUE_STRING_ARRAY(zbee_zcl_ke_curve_names);
2673
2674 /* Crypto Suite 2 Hash Names */
2675 #define zbee_zcl_ke_hash_names_VALUE_STRING_LIST(XXX) \
2676     XXX(ZBEE_ZCL_KE_HASH_AES_MMO,                               0x08, "AES MMO" )
2677
2678 VALUE_STRING_ARRAY(zbee_zcl_ke_hash_names);
2679
2680 #define zbee_zcl_ke_status_names_VALUE_STRING_LIST(XXX) \
2681     XXX(ZBEE_ZCL_KE_STATUS_RESERVED,                            0x00, "Reserved" ) \
2682     XXX(ZBEE_ZCL_KE_STATUS_UNKNOWN_ISSUER,                      0x01, "Unknown Issuer" ) \
2683     XXX(ZBEE_ZCL_KE_STATUS_BAD_KEY_CONFIRM,                     0x02, "Bad Key Confirm" ) \
2684     XXX(ZBEE_ZCL_KE_STATUS_BAD_MESSAGE,                         0x03, "Bad Message" ) \
2685     XXX(ZBEE_ZCL_KE_STATUS_NO_RESOURCES,                        0x04, "No Resources" ) \
2686     XXX(ZBEE_ZCL_KE_STATUS_UNSUPPORTED_SUITE,                   0x05, "Unsupported Suite" ) \
2687     XXX(ZBEE_ZCL_KE_STATUS_INVALID_CERTIFICATE,                 0x06, "Invalid Certificate" )
2688
2689 VALUE_STRING_ARRAY(zbee_zcl_ke_status_names);
2690
2691 /*************************/
2692 /* Function Declarations */
2693 /*************************/
2694
2695 void proto_register_zbee_zcl_ke(void);
2696 void proto_reg_handoff_zbee_zcl_ke(void);
2697
2698 /* Private functions prototype */
2699
2700 /*************************/
2701 /* Global Variables      */
2702 /*************************/
2703
2704 static dissector_handle_t ke_handle;
2705
2706 /* Initialize the protocol and registered fields */
2707 static int proto_zbee_zcl_ke = -1;
2708 static int hf_zbee_zcl_ke_srv_tx_cmd_id = -1;
2709 static int hf_zbee_zcl_ke_srv_rx_cmd_id = -1;
2710 static int hf_zbee_zcl_ke_attr_id = -1;
2711 static int hf_zbee_zcl_ke_suite = -1;
2712 static int hf_zbee_zcl_ke_ephemeral_time = -1;
2713 static int hf_zbee_zcl_ke_confirm_time = -1;
2714 static int hf_zbee_zcl_ke_status = -1;
2715 static int hf_zbee_zcl_ke_wait_time = -1;
2716 static int hf_zbee_zcl_ke_cert_reconstr = -1;
2717 static int hf_zbee_zcl_ke_cert_subject = -1;
2718 static int hf_zbee_zcl_ke_cert_issuer = -1;
2719 static int hf_zbee_zcl_ke_cert_profile_attr = -1;
2720 static int hf_zbee_zcl_ke_cert_type = -1;
2721 static int hf_zbee_zcl_ke_cert_serialno = -1;
2722 static int hf_zbee_zcl_ke_cert_curve = -1;
2723 static int hf_zbee_zcl_ke_cert_hash = -1;
2724 static int hf_zbee_zcl_ke_cert_valid_from = -1;
2725 static int hf_zbee_zcl_ke_cert_valid_to = -1;
2726 static int hf_zbee_zcl_ke_cert_key_usage_agreement = -1;
2727 static int hf_zbee_zcl_ke_cert_key_usage_signature = -1;
2728 static int hf_zbee_zcl_ke_ephemeral_qeu = -1;
2729 static int hf_zbee_zcl_ke_ephemeral_qev = -1;
2730 static int hf_zbee_zcl_ke_macu = -1;
2731 static int hf_zbee_zcl_ke_macv = -1;
2732
2733 /* Initialize the subtree pointers */
2734 static gint ett_zbee_zcl_ke = -1;
2735 static gint ett_zbee_zcl_ke_cert = -1;
2736 static gint ett_zbee_zcl_ke_key_usage = -1;
2737
2738 /*************************/
2739 /* Function Bodies       */
2740 /*************************/
2741
2742 /**
2743  *This function dissects the Suite 1 Certificate
2744  *
2745  *@param tvb pointer to buffer containing raw packet.
2746  *@param tree pointer to data tree Wireshark uses to display packet.
2747  *@param offset pointer to offset from caller
2748 */
2749 static void
2750 dissect_zcl_ke_suite1_certificate(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2751 {
2752     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_reconstr, tvb, *offset, 22, ENC_NA);
2753     *offset += 22;
2754
2755     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_subject, tvb, *offset, 8, ENC_NA);
2756     *offset += 8;
2757
2758     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_issuer, tvb, *offset, 8, ENC_NA);
2759     *offset += 8;
2760
2761     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_profile_attr, tvb, *offset, 10, ENC_NA);
2762     *offset += 10;
2763
2764 } /*dissect_zcl_ke_suite1_certificate*/
2765
2766 /**
2767  *This function dissects the Suite 2 Certificate
2768  *
2769  *@param tvb pointer to buffer containing raw packet.
2770  *@param tree pointer to data tree Wireshark uses to display packet.
2771  *@param offset pointer to offset from caller
2772 */
2773 static void
2774 dissect_zcl_ke_suite2_certificate(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2775 {
2776     nstime_t      valid_from_time;
2777     nstime_t      valid_to_time;
2778     guint32       valid_to;
2779     guint8        key_usage;
2780     proto_tree   *usage_tree;
2781
2782     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_type, tvb, *offset, 1, ENC_NA);
2783     *offset += 1;
2784
2785     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_serialno, tvb, *offset, 8, ENC_NA);
2786     *offset += 8;
2787
2788     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_curve, tvb, *offset, 1, ENC_NA);
2789     *offset += 1;
2790
2791     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_hash, tvb, *offset, 1, ENC_NA);
2792     *offset += 1;
2793
2794     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_issuer, tvb, *offset, 8, ENC_NA);
2795     *offset += 8;
2796
2797     valid_from_time.secs = (time_t)tvb_get_ntoh40(tvb, *offset);
2798     valid_from_time.nsecs = 0;
2799     proto_tree_add_time(tree, hf_zbee_zcl_ke_cert_valid_from, tvb, *offset, 5, &valid_from_time);
2800     *offset += 5;
2801
2802     valid_to = tvb_get_ntohl(tvb, *offset);
2803     if (valid_to == 0xFFFFFFFF) {
2804         proto_tree_add_time_format(tree, hf_zbee_zcl_ke_cert_valid_to, tvb, *offset, 4, &valid_to_time, "Valid To: does not expire (0xFFFFFFFF)");
2805     }
2806     else {
2807         valid_to_time.secs = valid_from_time.secs + valid_to;
2808         valid_to_time.nsecs = 0;
2809         proto_tree_add_time(tree, hf_zbee_zcl_ke_cert_valid_to, tvb, *offset, 4, &valid_to_time);
2810     }
2811     *offset += 4;
2812
2813     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_subject, tvb, *offset, 8, ENC_NA);
2814     *offset += 8;
2815
2816     key_usage = tvb_get_guint8(tvb, *offset);
2817     usage_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 1, ett_zbee_zcl_ke_key_usage, NULL, "Key Usage (0x%02x)", key_usage);
2818
2819     proto_tree_add_item(usage_tree, hf_zbee_zcl_ke_cert_key_usage_agreement, tvb, *offset, 1, ENC_NA);
2820     proto_tree_add_item(usage_tree, hf_zbee_zcl_ke_cert_key_usage_signature, tvb, *offset, 1, ENC_NA);
2821     *offset += 1;
2822
2823     proto_tree_add_item(tree, hf_zbee_zcl_ke_cert_reconstr, tvb, *offset, 37, ENC_NA);
2824     *offset += 37;
2825
2826 } /*dissect_zcl_ke_suite2_certificate*/
2827
2828 /**
2829  *This function manages the Initiate Key Establishment message
2830  *
2831  *@param tvb pointer to buffer containing raw packet.
2832  *@param tree pointer to data tree Wireshark uses to display packet.
2833  *@param offset pointer to offset from caller
2834 */
2835 static void
2836 dissect_zcl_ke_initiate(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2837 {
2838     gint               rem_len;
2839     proto_tree        *subtree;
2840     guint16            suite;
2841
2842     suite = tvb_get_letohs(tvb, *offset);
2843
2844     proto_tree_add_item(tree, hf_zbee_zcl_ke_suite, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
2845     *offset += 2;
2846
2847     proto_tree_add_item(tree, hf_zbee_zcl_ke_ephemeral_time, tvb, *offset, 1, ENC_NA);
2848     *offset += 1;
2849
2850     proto_tree_add_item(tree, hf_zbee_zcl_ke_confirm_time, tvb, *offset, 1, ENC_NA);
2851     *offset += 1;
2852
2853     rem_len = tvb_reported_length_remaining(tvb, *offset);
2854     subtree = proto_tree_add_subtree(tree, tvb, *offset, rem_len, ett_zbee_zcl_ke_cert, NULL, "Implicit Certificate");
2855
2856     switch (suite) {
2857         case ZBEE_ZCL_KE_SUITE_1:
2858             dissect_zcl_ke_suite1_certificate(tvb, subtree, offset);
2859             break;
2860
2861         case ZBEE_ZCL_KE_SUITE_2:
2862             dissect_zcl_ke_suite2_certificate(tvb, subtree, offset);
2863             break;
2864
2865         default:
2866             break;
2867     }
2868 } /* dissect_zcl_ke_initiate */
2869
2870 /**
2871  *This function dissects the Ephemeral Data QEU
2872  *
2873  *@param tvb pointer to buffer containing raw packet.
2874  *@param tree pointer to data tree Wireshark uses to display packet.
2875  *@param offset pointer to offset from caller
2876 */
2877 static int
2878 dissect_zcl_ke_ephemeral_qeu(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2879 {
2880     gint length;
2881
2882     /* size depends on suite but without a session we don't know that here */
2883     /* so just report what we have */
2884     length = tvb_reported_length_remaining(tvb, *offset);
2885     proto_tree_add_item(tree, hf_zbee_zcl_ke_ephemeral_qeu, tvb, *offset, length, ENC_NA);
2886     *offset += length;
2887     return tvb_captured_length(tvb);
2888 }
2889
2890 /**
2891  *This function dissects the Ephemeral Data QEV
2892  *
2893  *@param tvb pointer to buffer containing raw packet.
2894  *@param tree pointer to data tree Wireshark uses to display packet.
2895  *@param offset pointer to offset from caller
2896 */
2897 static int
2898 dissect_zcl_ke_ephemeral_qev(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2899 {
2900     gint length;
2901
2902     /* size depends on suite but without a session we don't know that here */
2903     /* so just report what we have */
2904     length = tvb_reported_length_remaining(tvb, *offset);
2905     proto_tree_add_item(tree, hf_zbee_zcl_ke_ephemeral_qev, tvb, *offset, length, ENC_NA);
2906     *offset += length;
2907     return tvb_captured_length(tvb);
2908 }
2909
2910 /**
2911  *This function dissects the Confirm MACU
2912  *
2913  *@param tvb pointer to buffer containing raw packet.
2914  *@param tree pointer to data tree Wireshark uses to display packet.
2915  *@param offset pointer to offset from caller
2916 */
2917 static int
2918 dissect_zcl_ke_confirm_macu(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2919 {
2920     proto_tree_add_item(tree, hf_zbee_zcl_ke_macu, tvb, *offset, ZBEE_SEC_CONST_BLOCKSIZE, ENC_NA);
2921     *offset += ZBEE_SEC_CONST_BLOCKSIZE;
2922     return tvb_captured_length(tvb);
2923 }
2924
2925 /**
2926  *This function dissects the Confirm MACV
2927  *
2928  *@param tvb pointer to buffer containing raw packet.
2929  *@param tree pointer to data tree Wireshark uses to display packet.
2930  *@param offset pointer to offset from caller
2931 */
2932 static int
2933 dissect_zcl_ke_confirm_macv(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2934 {
2935     proto_tree_add_item(tree, hf_zbee_zcl_ke_macv, tvb, *offset, ZBEE_SEC_CONST_BLOCKSIZE, ENC_NA);
2936     *offset += ZBEE_SEC_CONST_BLOCKSIZE;
2937     return tvb_captured_length(tvb);
2938 }
2939
2940 /**
2941  *This function dissects the Terminate Key Establishment message
2942  *
2943  *@param tvb pointer to buffer containing raw packet.
2944  *@param tree pointer to data tree Wireshark uses to display packet.
2945  *@param offset pointer to offset from caller
2946 */
2947 static void
2948 dissect_zcl_ke_terminate(tvbuff_t *tvb, proto_tree *tree, guint *offset)
2949 {
2950     proto_tree_add_item(tree, hf_zbee_zcl_ke_status, tvb, *offset, 1, ENC_NA);
2951     *offset += 1;
2952
2953     proto_tree_add_item(tree, hf_zbee_zcl_ke_wait_time, tvb, *offset, 1, ENC_NA);
2954     *offset += 1;
2955
2956     proto_tree_add_item(tree, hf_zbee_zcl_ke_suite, tvb, *offset, 2, ENC_LITTLE_ENDIAN);
2957     *offset += 2;
2958 }
2959
2960 /**
2961  *ZigBee ZCL Key Establishment cluster dissector for wireshark.
2962  *
2963  *@param tvb pointer to buffer containing raw packet.
2964  *@param pinfo pointer to packet information fields
2965  *@param tree pointer to data tree Wireshark uses to display packet.
2966 */
2967 static int
2968 dissect_zbee_zcl_ke(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
2969 {
2970     zbee_zcl_packet   *zcl;
2971     guint             offset = 0;
2972     guint8            cmd_id;
2973     gint              rem_len;
2974
2975     /* Reject the packet if data is NULL */
2976     if (data == NULL)
2977         return 0;
2978     zcl = (zbee_zcl_packet *)data;
2979     cmd_id = zcl->cmd_id;
2980
2981     /*  Create a subtree for the ZCL Command frame, and add the command ID to it. */
2982     if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) {
2983         /* Append the command name to the info column. */
2984         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
2985             val_to_str_const(cmd_id, zbee_zcl_ke_srv_cmd_names, "Unknown Command"),
2986             zcl->tran_seqno);
2987
2988         /* Add the command ID. */
2989         proto_tree_add_uint(tree, hf_zbee_zcl_ke_srv_rx_cmd_id, tvb, offset, 1, cmd_id);
2990
2991         /* Check is this command has a payload, than add the payload tree */
2992         rem_len = tvb_reported_length_remaining(tvb, offset);
2993         offset += 1; /* delay from last add_item */
2994         if (rem_len > 0) {
2995
2996             /* Call the appropriate command dissector */
2997             switch (cmd_id) {
2998                 case ZBEE_ZCL_CMD_ID_KE_INITIATE:
2999                     dissect_zcl_ke_initiate(tvb, tree, &offset);
3000                     break;
3001
3002                 case ZBEE_ZCL_CMD_ID_KE_EPHEMERAL:
3003                     return dissect_zcl_ke_ephemeral_qeu(tvb, tree, &offset);
3004
3005                 case ZBEE_ZCL_CMD_ID_KE_CONFIRM:
3006                     return dissect_zcl_ke_confirm_macu(tvb, tree, &offset);
3007
3008                 case ZBEE_ZCL_CMD_ID_KE_TERMINATE:
3009                     dissect_zcl_ke_terminate(tvb, tree, &offset);
3010                     break;
3011
3012                 default:
3013                     break;
3014             }
3015         }
3016     }
3017     else { /* ZBEE_ZCL_FCF_TO_CLIENT */
3018         /* Append the command name to the info column. */
3019         col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
3020             val_to_str_const(cmd_id, zbee_zcl_ke_srv_cmd_names, "Unknown Command"),
3021             zcl->tran_seqno);
3022
3023         /* Add the command ID. */
3024         proto_tree_add_uint(tree, hf_zbee_zcl_ke_srv_tx_cmd_id, tvb, offset, 1, cmd_id);
3025
3026         /* Check is this command has a payload, than add the payload tree */
3027         rem_len = tvb_reported_length_remaining(tvb, ++offset);
3028         if (rem_len > 0) {
3029             /* Call the appropriate command dissector */
3030             switch (cmd_id) {
3031                 case ZBEE_ZCL_CMD_ID_KE_INITIATE:
3032                     dissect_zcl_ke_initiate(tvb, tree, &offset);
3033                     break;
3034
3035                 case ZBEE_ZCL_CMD_ID_KE_EPHEMERAL:
3036                     return dissect_zcl_ke_ephemeral_qev(tvb, tree, &offset);
3037
3038                 case ZBEE_ZCL_CMD_ID_KE_CONFIRM:
3039                     return dissect_zcl_ke_confirm_macv(tvb, tree, &offset);
3040
3041                 case ZBEE_ZCL_CMD_ID_KE_TERMINATE:
3042                     dissect_zcl_ke_terminate(tvb, tree, &offset);
3043                     break;
3044
3045                 default:
3046                     break;
3047             }
3048         }
3049     }
3050
3051     return tvb_captured_length(tvb);
3052 } /*dissect_zbee_zcl_ke*/
3053
3054
3055 /**
3056  *This function registers the ZCL Messaging dissector
3057  *
3058 */
3059 void
3060 proto_register_zbee_zcl_ke(void)
3061 {
3062     static hf_register_info hf[] = {
3063
3064         { &hf_zbee_zcl_ke_attr_id,
3065             { "Attribute", "zbee_zcl_se.ke.attr_id", FT_UINT16, BASE_HEX, VALS(zbee_zcl_ke_attr_names),
3066             0x00, NULL, HFILL } },
3067
3068         { &hf_zbee_zcl_ke_srv_tx_cmd_id,
3069             { "Command", "zbee_zcl_se.ke.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_ke_srv_cmd_names),
3070             0x00, NULL, HFILL } },
3071
3072         { &hf_zbee_zcl_ke_srv_rx_cmd_id,
3073             { "Command", "zbee_zcl_se.ke.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_ke_srv_cmd_names),
3074             0x00, NULL, HFILL } },
3075
3076         { &hf_zbee_zcl_ke_suite,
3077             { "Key Establishment Suite", "zbee_zcl_se.ke.attr.suite", FT_UINT16, BASE_HEX, VALS(zbee_zcl_ke_suite_names),
3078             0x00, NULL, HFILL } },
3079
3080         { &hf_zbee_zcl_ke_ephemeral_time,
3081             { "Ephemeral Data Generate Time", "zbee_zcl_se.ke.init.ephemeral.time", FT_UINT8, BASE_DEC, NULL,
3082             0, NULL, HFILL } },
3083
3084         { &hf_zbee_zcl_ke_confirm_time,
3085             { "Confirm Key Generate Time", "zbee_zcl_se.ke.init.confirm.time", FT_UINT8, BASE_DEC, NULL,
3086             0, NULL, HFILL } },
3087
3088         { &hf_zbee_zcl_ke_status,
3089             { "Status", "zbee_zcl_se.ke.terminate.status", FT_UINT8, BASE_HEX, VALS(zbee_zcl_ke_status_names),
3090             0x00, NULL, HFILL } },
3091
3092         { &hf_zbee_zcl_ke_wait_time,
3093             { "Wait Time", "zbee_zcl_se.ke.terminate.wait.time", FT_UINT8, BASE_DEC, NULL,
3094             0, NULL, HFILL } },
3095
3096         { &hf_zbee_zcl_ke_cert_reconstr,
3097             { "Public Key", "zbee_zcl_se.ke.cert.reconst", FT_BYTES, BASE_NONE, NULL,
3098             0, NULL, HFILL } },
3099
3100         { &hf_zbee_zcl_ke_cert_subject,
3101             { "Subject", "zbee_zcl_se.ke.cert.subject", FT_BYTES, BASE_NONE, NULL,
3102             0, NULL, HFILL } },
3103
3104         { &hf_zbee_zcl_ke_cert_issuer,
3105             { "Issuer", "zbee_zcl_se.ke.cert.issuer", FT_BYTES, BASE_NONE, NULL,
3106             0, NULL, HFILL } },
3107
3108         { &hf_zbee_zcl_ke_cert_profile_attr,
3109             { "Profile Attribute Data", "zbee_zcl_se.ke.cert.profile", FT_BYTES, BASE_NONE, NULL,
3110             0, NULL, HFILL } },
3111
3112         { &hf_zbee_zcl_ke_cert_type,
3113             { "Type", "zbee_zcl_se.ke.cert.type", FT_UINT8, BASE_HEX, VALS(zbee_zcl_ke_type_names),
3114             0, NULL, HFILL } },
3115
3116         { &hf_zbee_zcl_ke_cert_serialno,
3117             { "Serial No", "zbee_zcl_se.ke.cert.serialno", FT_UINT64, BASE_HEX, NULL,
3118             0, NULL, HFILL } },
3119
3120         { &hf_zbee_zcl_ke_cert_curve,
3121             { "Curve", "zbee_zcl_se.ke.cert.curve", FT_UINT8, BASE_HEX, VALS(zbee_zcl_ke_curve_names),
3122             0, NULL, HFILL } },
3123
3124         { &hf_zbee_zcl_ke_cert_hash,
3125             { "Hash", "zbee_zcl_se.ke.cert.hash", FT_UINT8, BASE_HEX, VALS(zbee_zcl_ke_hash_names),
3126             0, NULL, HFILL } },
3127
3128         { &hf_zbee_zcl_ke_cert_valid_from,
3129             { "Valid From", "zbee_zcl_se.ke.cert.valid.from", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
3130             0, NULL, HFILL } },
3131
3132         { &hf_zbee_zcl_ke_cert_valid_to,
3133             { "Valid To", "zbee_zcl_se.ke.cert.valid.to", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL,
3134             0, NULL, HFILL } },
3135
3136         { &hf_zbee_zcl_ke_cert_key_usage_agreement,
3137             { "Key Agreement", "zbee_zcl_se.ke.cert.key.usage.agreement", FT_BOOLEAN, 8, TFS(&tfs_enabled_disabled),
3138             ZBEE_ZCL_KE_USAGE_KEY_AGREEMENT, NULL, HFILL }},
3139
3140         { &hf_zbee_zcl_ke_cert_key_usage_signature,
3141             { "Digital Signature", "zbee_zcl_se.ke.cert.key.usage.signature", FT_BOOLEAN, 8, TFS(&tfs_enabled_disabled),
3142             ZBEE_ZCL_KE_USAGE_DIGITAL_SIGNATURE, NULL, HFILL }},
3143
3144         { &hf_zbee_zcl_ke_ephemeral_qeu,
3145             { "Ephemeral Data (QEU)", "zbee_zcl_se.ke.qeu", FT_BYTES, BASE_NONE, NULL,
3146             0, NULL, HFILL } },
3147
3148         { &hf_zbee_zcl_ke_ephemeral_qev,
3149             { "Ephemeral Data (QEV)", "zbee_zcl_se.ke.qev", FT_BYTES, BASE_NONE, NULL,
3150             0, NULL, HFILL } },
3151
3152         { &hf_zbee_zcl_ke_macu,
3153             { "Message Authentication Code (MACU)", "zbee_zcl_se.ke.macu", FT_BYTES, BASE_NONE, NULL,
3154             0, NULL, HFILL } },
3155
3156         { &hf_zbee_zcl_ke_macv,
3157             { "Message Authentication Code (MACV)", "zbee_zcl_se.ke.macv", FT_BYTES, BASE_NONE, NULL,
3158             0, NULL, HFILL } },
3159     };
3160
3161     /* subtrees */
3162     gint *ett[] = {
3163         &ett_zbee_zcl_ke,
3164         &ett_zbee_zcl_ke_cert,
3165         &ett_zbee_zcl_ke_key_usage,
3166     };
3167
3168     /* Register the ZigBee ZCL Messaging cluster protocol name and description */
3169     proto_zbee_zcl_ke = proto_register_protocol("ZigBee ZCL Key Establishment", "ZCL Key Establishment", ZBEE_PROTOABBREV_ZCL_KE);
3170     proto_register_field_array(proto_zbee_zcl_ke, hf, array_length(hf));
3171     proto_register_subtree_array(ett, array_length(ett));
3172
3173     /* Register the ZigBee ZCL Messaging dissector. */
3174     ke_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_KE, dissect_zbee_zcl_ke, proto_zbee_zcl_ke);
3175 } /*proto_register_zbee_zcl_ke*/
3176
3177 /**
3178  *Hands off the Zcl Key Establishment dissector.
3179  *
3180 */
3181 void
3182 proto_reg_handoff_zbee_zcl_ke(void)
3183 {
3184     /* Register our dissector with the ZigBee application dissectors. */
3185     dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_KE, ke_handle);
3186
3187     zbee_zcl_init_cluster(  proto_zbee_zcl_ke,
3188                             ett_zbee_zcl_ke,
3189                             ZBEE_ZCL_CID_KE,
3190                             hf_zbee_zcl_ke_attr_id,
3191                             hf_zbee_zcl_ke_srv_rx_cmd_id,
3192                             hf_zbee_zcl_ke_srv_tx_cmd_id,
3193                             NULL
3194                          );
3195 } /*proto_reg_handoff_zbee_zcl_ke*/
3196
3197 /*
3198  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
3199  *
3200  * Local variables:
3201  * c-basic-offset: 4
3202  * tab-width: 8
3203  * indent-tabs-mode: nil
3204  * End:
3205  *
3206  * vi: set shiftwidth=4 tabstop=8 expandtab:
3207  * :indentSize=4:tabSize=8:noTabs=true:
3208  */