Coverage Report

Created: 2026-07-12 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-miwi-p2pstar.c
Line
Count
Source
1
/* packet-miwi-p2pstar.c
2
 * Dissector  routines for the Microchip MiWi_P2P_Star
3
 * Copyright 2013 Martin Leixner <info@sewio.net>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 *------------------------------------------------------------
11
*/
12
13
#include "config.h"
14
#include <epan/packet.h>
15
#include <epan/decode_as.h>
16
#include <epan/exceptions.h>
17
#include <epan/crc16-tvb.h>
18
#include <epan/crc32-tvb.h>
19
#include <epan/expert.h>
20
#include <epan/addr_resolv.h>
21
#include <epan/address_types.h>
22
#include <epan/conversation.h>
23
#include <epan/prefs.h>
24
#include <epan/uat.h>
25
#include <epan/strutil.h>
26
#include <epan/to_str.h>
27
#include <epan/show_exception.h>
28
#include <epan/proto_data.h>
29
#include <epan/etypes.h>
30
#include <epan/oui.h>
31
#include <wsutil/pint.h>
32
33
/* Use libgcrypt for cipher libraries. */
34
#include <wsutil/wsgcrypt.h>
35
36
#include <wsutil/filesystem.h>
37
#include "packet-ieee802154.h"
38
#include <epan/prefs.h>
39
#include <epan/strutil.h>
40
#include <wsutil/wsgcrypt.h>
41
42
/*  Function declarations */
43
void proto_register_miwi_p2pstar(void);
44
void proto_reg_handoff_miwi_p2pstar(void);
45
46
/*  MiWi MAC Header FCF fields */
47
15
#define MIWI_MAC_FCF_FRAME_TYPE         0x0007
48
15
#define MIWI_MAC_FCF_SECURITY_EN        0x0008
49
15
#define MIWI_MAC_FCF_FRAME_PENDING      0x0010
50
15
#define MIWI_MAC_FCF_ACK_REQUEST        0x0020
51
15
#define MIWI_MAC_FCF_PANID_COMP         0x0040
52
15
#define MIWI_MAC_FCF_RESERVED           0x0380
53
15
#define MIWI_MAC_FCF_DEST_ADDR_MODE     0x0C00
54
15
#define MIWI_MAC_FCF_FRAME_VERSION      0x3000
55
15
#define MIWI_MAC_FCF_SRC_ADDR_MODE      0xC000
56
57
/*  MiWi NWK Header FCF fields */
58
#define MIWI_NWK_FCF_FRAME_TYPE         0x0003
59
#define MIWI_NWK_FCF_SECURITY_EN        0x0004
60
#define MIWI_NWK_FCF_INFRA_CLUSTER      0x0008
61
#define MIWI_NWK_FCF_ACK_REQUEST        0x0010
62
#define MIWI_NWK_FCF_ADDR_SAME_AS_MAC   0x0020
63
#define MIWI_NWK_FCF_RESERVED           0x00C0
64
65
/* Address Mode Definitions */
66
#define MIWI_FCF_ADDR_NONE              0x0
67
#define MIWI_FCF_ADDR_RESERVED          0x1
68
#define MIWI_FCF_ADDR_SHORT             0x2
69
#define MIWI_FCF_ADDR_EXT               0x3
70
71
#define MIWI_SOURCE_ADDR_MODE           0x00 // to check
72
73
/*  MiWi NWK Header FCF fields */
74
15
#define MIWI_CAP_INFO_RCV_ON_IDLE       0x0001
75
15
#define MIWI_CAP_INFO_REQ_DATA_ON_WP    0x0002
76
15
#define MIWI_CAP_INFO_NEED_TIME_SYNC    0x0004
77
15
#define MIWI_CAP_INFO_SECURITY_CAP      0x0008
78
15
#define MIWI_CAP_INFO_RESERVED          0x00F0
79
80
/*Defined addresses*/
81
#define MIWI_BCAST_ADDR                 0xFFFF
82
83
/*Command IDs*/
84
0
#define MIWI_P2P_CMD_CONN_REQ           0x81
85
0
#define MIWI_P2P_CMD_CONN_REMOVAL_REQ   0x82
86
0
#define MIWI_P2P_CMD_DATA_REQ           0x83
87
0
#define MIWI_P2P_CMD_CHANNEL_HOP        0x84
88
0
#define MIWI_P2P_CMD_ACTIVE_SCAN_REQ    0x87
89
0
#define MIWI_P2P_CMD_CONN_RES           0x91
90
0
#define MIWI_P2P_CMD_CONN_REMOVAL_RES   0x92
91
0
#define MIWI_P2P_CMD_ACTIVE_SCAN_RES    0x97
92
93
0
#define MIWI_STAR_CMD_FORWARD_PACKET    0xCC
94
0
#define MIWI_STAR_CMD_SOFT_ACK          0xDA
95
0
#define MIWI_STAR_CMD_LINK_STATUS       0x7A
96
0
#define MIWI_STAR_CMD_CONN_TABLE        0x77
97
98
#define MIWI_CONN_STATUS_SUCCESS        0x00
99
#define MIWI_CONN_STATUS_EXISTS         0x01
100
#define MIWI_CONN_STATUS_ACTIVE_SCAN    0x02
101
#define MIWI_CONN_STATUS_ENTRY_NOT_EXIST    0xF0
102
#define MIWI_CONN_STATUS_NOT_ENOUGH_SPACE   0xF1
103
#define MIWI_CONN_STATUS_NOT_SAME_PA    0xF2
104
#define MIWI_CONN_STATUS_NOT_PERMITTED  0xF3
105
106
/* FCS Types used by user configuration */
107
15
#define MIWI_P2PSTAR_FCS_16_BIT         1/*  CRC16 */
108
109
/**MiWI  Type of MAC frame */
110
#define MIWI_MAC_FRAME_BEACON           0x00
111
#define MIWI_MAC_FRAME_DATA             0x01
112
#define MIWI_MAC_FRAME_ACK              0x02
113
#define MIWI_MAC_FRAME_CMD              0x03
114
#define MIWI_MAC_FRAME_RESERVED         0x04
115
116
/* User string with the decryption key. */
117
//static const char *miwi_p2pstar_key_str = NULL;
118
119
/*  Initialize protocol and registered fields. */
120
static int proto_miwi_p2pstar;
121
122
/* Initialize protocol subtrees. */
123
static int ett_miwi_p2pstar;
124
static int ett_miwi_p2pstar_fcf;
125
static int ett_miwi_p2pstar_cmd_tree;
126
static int ett_miwi_p2pstar_cap_info;
127
static int ett_miwi_fcs;
128
129
static dissector_handle_t miwi_p2pstar_handle;
130
131
static int hf_miwi_frame_length;
132
static int hf_miwi_fcf;
133
static int hf_miwi_fcf_frame_type;
134
static int hf_miwi_fcf_security_enabled;
135
static int hf_miwi_fcf_frame_pending;
136
static int hf_miwi_fcf_ack_req;
137
static int hf_miwi_fcf_panid_comp;
138
static int hf_miwi_fcf_reserved;
139
static int hf_miwi_fcf_dest_addr_mode;
140
static int hf_miwi_fcf_frame_version;
141
static int hf_miwi_fcf_src_addr_mode;
142
static int hf_miwi_seq;
143
static int hf_miwi_dst_panid;
144
static int hf_miwi_short_dst_addr;
145
static int hf_miwi_ext_dst_addr;
146
//static int hf_miwi_no_dst_addr;
147
//static int hf_miwi_no_src_addr;
148
static int hf_miwi_ext_src_addr;
149
static int hf_miwi_short_src_addr;
150
static int hf_miwi_addr16;
151
static int hf_miwi_addr64;
152
static int hf_miwi_src64_origin;
153
static int hf_miwi_src_panid;
154
static int hf_miwi_cmd_id;
155
//static int hf_miwi_fcs;
156
//static int hf_miwi_fcs_ok;
157
158
static int hf_miwi_oper_chan;
159
static int hf_miwi_cap_info;
160
static int hf_miwi_cap_info_rcv_on_idle;
161
static int hf_miwi_cap_info_rqst_data_on_wp;
162
static int hf_miwi_cap_info_need_time_sync;
163
static int hf_miwi_cap_info_security_cap;
164
static int hf_miwi_cap_info_reserved;
165
static int hf_miwi_conn_res_status;
166
167
//static int hf_miwi_conn_rmv_req;
168
static int hf_miwi_conn_rmv_res_status;
169
//static int hf_miwi_data_req;
170
//static int hf_miwi_chan_hop;
171
//static int hf_miwi_conn_res;
172
//static int hf_miwi_conn_rmv_res;
173
//static int hf_miwi_active_scan_req;
174
//static int hf_miwi_active_scan_cur_chan;
175
176
//static int hf_miwi_active_scan_res;
177
//static int hf_miwi_active_scan_res_node_id;
178
179
//static int hf_miwi_fwd_pkt_cmd;
180
static int hf_miwi_fwd_pkt_dst_addr;
181
//static int hf_miwi_conn_tbl_bcast_cmd;
182
static int hf_miwi_conn_tbl_size;
183
//static int hf_miwi_software_ack;
184
//static int hf_miwi_link_status;
185
186
/*Channel hopping frame*/
187
static int hf_miwi_current_op_channel;
188
static int hf_miwi_dst_channel_to_jump_to;
189
190
//static int hf_miwi_mic;
191
//static int hf_miwi_key_number;
192
193
static int miwi_short_address_type;
194
195
//static expert_field ei_miwi_empty_payload;
196
static expert_field ei_miwi_frame_ver;
197
static expert_field ei_miwi_dst;
198
static expert_field ei_miwi_src;
199
static expert_field ei_miwi_invalid_addressing;
200
static expert_field ei_miwi_invalid_panid_compression;
201
static expert_field ei_miwi_invalid_panid_compression2;
202
//static expert_field ei_miwi_fcs;
203
/* 802.15.4-2003 security */
204
//static int hf_miwi_sec_frame_counter;
205
//static int hf_miwi_sec_key_sequence_counter;
206
207
208
/* ethertype for 802.15.4 tag - encapsulating an Ethernet packet */
209
static unsigned int miwi_ethertype = 0x809A;
210
211
/* boolean value set if the FCS must be ok before payload is dissected */
212
static bool miwi_fcs_ok = true;
213
214
/* boolean value set to enable ack tracking */
215
static bool miwi_ack_tracking = false;
216
217
/* Preferences for 2003 security */
218
//static int miwi_sec_suite = SECURITY_LEVEL_ENC_MIC_64;
219
//static bool miwi_extend_auth = true;
220
221
//static wmem_tree_t* mac_key_hash_handlers;
222
223
/*
224
 * Address Hash Tables
225
 *
226
 */
227
static ieee802154_map_tab_t miwi_map = {NULL, NULL};
228
229
//static ieee802154_key_t *miwi_keys = NULL;
230
//static unsigned num_miwi_keys = 0;
231
232
static int miwi_fcs_type = MIWI_P2PSTAR_FCS_16_BIT;
233
234
static int* const fields[] = {
235
    &hf_miwi_fcf_frame_type,
236
    &hf_miwi_fcf_security_enabled,
237
    &hf_miwi_fcf_frame_pending,
238
    &hf_miwi_fcf_ack_req,
239
    &hf_miwi_fcf_panid_comp,
240
    &hf_miwi_fcf_reserved,
241
    &hf_miwi_fcf_dest_addr_mode,
242
    &hf_miwi_fcf_frame_version,
243
    &hf_miwi_fcf_src_addr_mode,
244
    NULL
245
};
246
247
static const value_string miwi_p2pstar_cmd_names[] ={
248
    { MIWI_P2P_CMD_CONN_REQ,          " Connection Request"},
249
    { MIWI_P2P_CMD_CONN_REMOVAL_REQ,  " Connection Removal Request"},
250
    { MIWI_P2P_CMD_DATA_REQ,          " Data Request"},
251
    { MIWI_P2P_CMD_CHANNEL_HOP,       " Channel Hopping"},
252
    { MIWI_P2P_CMD_ACTIVE_SCAN_REQ,   " Active Scan Request"},
253
    { MIWI_P2P_CMD_CONN_RES,          " Connection Response"},
254
    { MIWI_P2P_CMD_CONN_REMOVAL_RES,  " Connection Removal Response"},
255
    { MIWI_P2P_CMD_ACTIVE_SCAN_RES,   " Active Scan Response"},
256
    { MIWI_STAR_CMD_FORWARD_PACKET,   " Forward packet"},
257
    { MIWI_STAR_CMD_SOFT_ACK,         " Soft Acknowledgement"},
258
    { MIWI_STAR_CMD_LINK_STATUS,      " Link Status"},
259
    { MIWI_STAR_CMD_CONN_TABLE,       " Connection Table"},
260
    { 0, NULL}
261
};
262
263
/* MAC Frame Types */
264
static const value_string miwi_mac_frame_types[] = {
265
    { MIWI_MAC_FRAME_BEACON,          "Beacon"},
266
    { MIWI_MAC_FRAME_DATA,            "Data"},
267
    { MIWI_MAC_FRAME_ACK,             "Acknowledgement"},
268
    { MIWI_MAC_FRAME_CMD,             "Command"},
269
    {MIWI_MAC_FRAME_RESERVED,         "Reserved"},
270
    { 0, NULL}
271
};
272
273
static const value_string miwi_addr_modes[] = {
274
    { MIWI_FCF_ADDR_NONE,             "None"},
275
    { MIWI_FCF_ADDR_RESERVED,         "Reserved"},
276
    { MIWI_FCF_ADDR_SHORT,            "Short/16-bit"},
277
    { MIWI_FCF_ADDR_EXT,              "Long/64-bit"},
278
    { 0, NULL}
279
};
280
281
/* Versions */
282
static const value_string miwi_frame_versions[] = {
283
    { IEEE802154_VERSION_2003,        "IEEE Std 802.15.4-2003"},
284
    { IEEE802154_VERSION_2006,        "IEEE Std 802.15.4-2006"},
285
    { IEEE802154_VERSION_2015,        "IEEE Std 802.15.4-2015"},
286
    { IEEE802154_VERSION_RESERVED,    "Reserved" },
287
    { 0, NULL}
288
};
289
290
static const value_string miwi_p2pstar_conn_status[] = {
291
    { MIWI_CONN_STATUS_SUCCESS,          " (Successful)"},
292
    { MIWI_CONN_STATUS_EXISTS,           " (Already Exists)"},
293
    { MIWI_CONN_STATUS_ACTIVE_SCAN,      " (Active Scan State)"},
294
    { MIWI_CONN_STATUS_ENTRY_NOT_EXIST,  " (Entry Not Exist)"},
295
    { MIWI_CONN_STATUS_NOT_ENOUGH_SPACE, " (Not Enough Space)"},
296
    { MIWI_CONN_STATUS_NOT_SAME_PA,      " (PANID Mismatch)"},
297
    { MIWI_CONN_STATUS_NOT_PERMITTED,    " (Not Permitted)"},
298
    { 0, NULL}
299
};
300
301
0
#define miwi_packet ieee802154_packet
302
303
   /* CRC definitions. IEEE 802.15.4 CRCs vary from ITU-T by using an initial value of
304
 * 0x0000, and no XOR out. IEEE802154_CRC_XOR is defined as 0xFFFF in order to un-XOR
305
 * the output from the ITU-T (CCITT) CRC routines in Wireshark. */
306
0
#define MIWI_CRC_SEED     0x0000
307
0
#define MIWI_CRC_XOROUT   0xFFFF
308
0
#define miwi_crc_tvb(tvb, offset)   (crc16_ccitt_tvb_seed(tvb, offset, MIWI_CRC_SEED) ^ MIWI_CRC_XOROUT)
309
/* For the 32-bit CRC, IEEE 802.15.4 uses ITU-T (CCITT) CRC-32. */
310
0
#define miwi_crc32_tvb(tvb, offset) (crc32_ccitt_tvb(tvb, offset))
311
   /**
312
 * Verify the 16/32 bit IEEE 802.15.4 FCS
313
 * @param tvb the IEEE 802.15.4 frame from the FCF up to and including the FCS
314
 * @return if the computed FCS matches the transmitted FCS
315
 */
316
static bool
317
is_fcs_ok(tvbuff_t *tvb, unsigned fcs_len)
318
0
{
319
0
    if(fcs_len == 2){
320
        /* The FCS is in the last two bytes of the packet. */
321
0
        uint16_t fcs = tvb_get_letohs(tvb, tvb_reported_length(tvb)-2);
322
0
        uint16_t fcs_calc = (uint16_t) miwi_crc_tvb(tvb, tvb_reported_length(tvb)-2);
323
0
        return fcs == fcs_calc;
324
0
    }
325
0
    else{
326
        /* The FCS is in the last four bytes of the packet. */
327
0
        uint32_t fcs = tvb_get_letohl(tvb, tvb_reported_length(tvb)-4);
328
0
        uint32_t fcs_calc = miwi_crc32_tvb(tvb, tvb_reported_length(tvb)-4);
329
0
        return fcs == fcs_calc;
330
0
    }
331
0
}/* is_fcs_ok */
332
333
/* Returns the prompt string for the Decode-As dialog. */
334
static void miwi_da_prompt(packet_info *pinfo _U_, char* result)
335
0
{
336
0
    ieee802154_hints_t *hints;
337
0
    hints = (ieee802154_hints_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_miwi_p2pstar, 0);
338
0
    if(hints)
339
0
        snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "MIWI P2P STAR PAN 0x%04x as", hints->src_pan);
340
0
    else
341
0
        snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "MIWI P2P STAR PAN Unknown");
342
0
}/* miwi_da_prompt */
343
/* Returns the value to index the panid decode table with (source PAN)*/
344
static void *miwi_da_value(packet_info *pinfo _U_)
345
0
{
346
0
    ieee802154_hints_t *hints;
347
0
    hints = (ieee802154_hints_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_miwi_p2pstar, 0);
348
0
    if(hints)
349
0
        return GUINT_TO_POINTER((unsigned)(hints->src_pan));
350
0
    else
351
0
        return NULL;
352
0
}/* miwi_da_value */
353
static int miwi_short_address_to_str(const address* addr, char *buf, int buf_len)
354
0
{
355
0
    uint16_t miwi_short_addr = pletohu16(addr->data);
356
357
0
    if (miwi_short_addr == 0xffff)
358
0
    {
359
0
        (void) g_strlcpy(buf, "Broadcast", buf_len);
360
0
        return 10;
361
0
    }
362
363
0
    *buf++ = '0';
364
0
    *buf++ = 'x';
365
0
    buf = word_to_hex(buf, miwi_short_addr);
366
0
    *buf = '\0'; /* NULL terminate */
367
368
0
    return 7;
369
0
} /* miwi_short_address_to_str */
370
static int miwi_short_to_str(uint16_t miwi_short_addr, char *buf, int buf_len)
371
0
{
372
0
    if(miwi_short_addr == 0xffff)
373
0
    {
374
0
        (void) g_strlcpy(buf, "Broadcast", buf_len);
375
0
        return 10;
376
0
    }
377
378
0
    *buf++ = '0';
379
0
    *buf++ = 'x';
380
0
    buf = word_to_hex(buf, miwi_short_addr);
381
0
    *buf = '\0'; /* NULL terminate */
382
383
0
    return 7;
384
0
}/* miwi_short_to_str */
385
386
static int miwi_short_address_str_len(const address* addr _U_)
387
0
{
388
0
    return 11;
389
0
}
390
391
static int miwi_short_address_len(void)
392
0
{
393
0
    return 2;
394
0
}
395
396
/**
397
 *Extracts an integer sub-field from an int with a given mask
398
 *
399
*/
400
#if 0
401
static unsigned miwi_get_bit_field(unsigned input, unsigned mask)
402
{
403
    /* Sanity Check, don't want infinite loops. */
404
    if(mask == 0) return 0;
405
    /* Shift input and mask together. */
406
    while (!(mask & 0x1)){
407
        input >>= 1;
408
        mask >>=1;
409
    }/* while */
410
    return (input & mask);
411
}/* miwi_get_bit_field */
412
#endif
413
414
/* Return the length in octets for the user configured
415
 * FCS/metadata following the PHY Payload */
416
static unsigned miwi_fcs_type_len(unsigned i)
417
0
{
418
0
    unsigned fcs_type_lengths[] = { 2, 2, 4 };
419
0
    if(i < array_length(fcs_type_lengths)){
420
0
        return fcs_type_lengths[i];
421
0
    }
422
0
    return 0;
423
0
}/* miwi_fcs_type_len */
424
425
#if 0
426
/* Set MAC key function. */
427
static unsigned miwi_set_mac_key(miwi_packet *packet, unsigned char *key, unsigned char *alt_key, ieee802154_key_t *uat_key)
428
{
429
    ieee802154_set_key_func func = (ieee802154_set_key_func)wmem_tree_lookup32(mac_key_hash_handlers, uat_key->hash_type);
430
431
    if(func != NULL)
432
        return func(packet, key, alt_key, uat_key);
433
434
    /* Right now, KEY_HASH_NONE and KEY_HASH_ZIP are not registered because they
435
        work with this "default" behavior */
436
    if(packet->key_index == uat_key->key_index)
437
    {
438
        memcpy(key, uat_key->key, IEEE802154_CIPHER_SIZE);
439
        return 1;
440
    }
441
442
    return 0;
443
}/* miwi_set_mac_key */
444
#endif
445
/**
446
 * Dissector helper, parses and displays the frame control field.
447
 *
448
 * @param tvb pointer to buffer containing raw packet.
449
 * @param pinfo pointer to packet information fields
450
 * @param tree pointer to data tree wireshark uses to display packet.
451
 * @param packet Miwi P2PStar packet information.
452
 * @param offset offset into the tvb to find the FCF.
453
 *
454
 */
455
static void
456
dissect_miwi_fcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
457
0
{
458
0
    uint16_t    miwi_fcf;
459
460
    /*Frame control fields*/
461
0
    miwi_fcf = tvb_get_letohs(tvb, (const int)*offset);
462
0
    packet->frame_type = (miwi_fcf & MIWI_MAC_FCF_FRAME_TYPE);
463
0
    packet->security_enable = (miwi_fcf & MIWI_MAC_FCF_SECURITY_EN) >> 3;
464
0
    packet->frame_pending = (miwi_fcf & MIWI_MAC_FCF_FRAME_PENDING) >> 4;
465
0
    packet->ack_request = (miwi_fcf & MIWI_MAC_FCF_ACK_REQUEST) >> 5;
466
0
    packet->pan_id_compression = (miwi_fcf & MIWI_MAC_FCF_PANID_COMP) >> 6;
467
    /*packet->reserved = (miwi_fcf & MIWI_MAC_FCF_RESERVED) >> 7;*/
468
0
    packet->dst_addr_mode = (miwi_fcf & MIWI_MAC_FCF_DEST_ADDR_MODE) >> 10;
469
0
    packet->version = (miwi_fcf & MIWI_MAC_FCF_FRAME_VERSION) >> 12;
470
0
    packet->src_addr_mode = (miwi_fcf & MIWI_MAC_FCF_SRC_ADDR_MODE) >> 14;
471
472
0
    proto_item_append_text(tree, " %s", val_to_str_const(packet->frame_type, miwi_mac_frame_types, "Reserved"));
473
0
    col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet->frame_type, miwi_mac_frame_types, "Reserved"));
474
475
0
    proto_tree_add_bitmask(tree, tvb,(const int)*offset, hf_miwi_fcf,
476
0
               ett_miwi_p2pstar_fcf, fields, ENC_LITTLE_ENDIAN);
477
478
0
    *offset += 2;
479
0
}/* dissect_miwi_fcf */
480
481
/**
482
 * Command subdissector routine for the Association request command.
483
 *
484
 * @param tvb pointer to buffer containing raw packet.
485
 * @param pinfo pointer to packet information fields.
486
 * @param tree pointer to protocol tree.
487
 * @param packet Miwi P2PStar packet information.
488
 * @param offset offset into the tvb to find the packet information.
489
 */
490
491
static void
492
dissect_miwi_connect_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
493
0
{
494
0
    uint8_t cap,oper_chan;
495
0
    proto_tree *subtree;
496
0
    static int* const capability[] = {
497
0
        &hf_miwi_cap_info_rcv_on_idle,
498
0
        &hf_miwi_cap_info_rqst_data_on_wp,
499
0
        &hf_miwi_cap_info_need_time_sync,
500
0
        &hf_miwi_cap_info_security_cap,
501
0
        &hf_miwi_cap_info_reserved,
502
0
        NULL
503
0
    };
504
505
    /* Create a subtree for this command frame. */
506
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
507
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
508
0
    oper_chan = tvb_get_uint8(tvb, *offset);
509
0
    proto_tree_add_uint(subtree, hf_miwi_oper_chan, tvb, *offset, 1, oper_chan);
510
0
    *offset += 1;
511
512
    /* Get and display capability info. */
513
0
    cap = tvb_get_uint8(tvb, *offset);
514
0
    proto_tree_add_uint(subtree, hf_miwi_cap_info, tvb, *offset, 1, cap);
515
0
    proto_tree_add_bitmask_list(subtree, tvb, *offset, 1, capability, ENC_NA);
516
0
    *offset += 1;
517
518
    /* Call the data dissector for any leftover bytes. */
519
0
    if(tvb_captured_length(tvb) > *offset){
520
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
521
0
    }
522
0
}/* dissect_miwi_connect_req */
523
524
/**
525
 * Command subdissector routine for the Association response command.
526
 *
527
 * @param tvb pointer to buffer containing raw packet.
528
 * @param pinfo pointer to packet information fields.
529
 * @param tree pointer to protocol tree.
530
 * @param packet Miwi P2PStar packet information.
531
 * @param offset offset into the tvb to find the packet information.
532
 */
533
static void
534
dissect_miwi_connect_rsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
535
0
{
536
0
    proto_tree *subtree;
537
0
    proto_item *ti;
538
0
    uint8_t     status;
539
0
    uint8_t cap;
540
0
    static int* const capability[] = {
541
0
        &hf_miwi_cap_info_rcv_on_idle,
542
0
        &hf_miwi_cap_info_rqst_data_on_wp,
543
0
        &hf_miwi_cap_info_need_time_sync,
544
0
        &hf_miwi_cap_info_security_cap,
545
0
        &hf_miwi_cap_info_reserved,
546
0
        NULL
547
0
    };
548
549
    /* Create a subtree for this command frame. */
550
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 3, ett_miwi_p2pstar_cmd_tree, NULL,
551
0
                    val_to_str_const((const uint32_t)packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
552
553
    /* Get and display the status. */
554
0
    status = tvb_get_uint8(tvb, *offset);
555
0
    if(tree){
556
0
        ti = proto_tree_add_uint(subtree, hf_miwi_conn_res_status, tvb, *offset, 1, status);
557
0
        proto_item_append_text(ti, "%s", val_to_str_const(status, miwi_p2pstar_conn_status, " (Reserved)"));
558
0
    }
559
0
    *offset += 1;
560
0
    col_append_str(pinfo->cinfo, COL_INFO, " Connection Response");
561
562
    /* Update the info column. */
563
0
    if(status == IEEE802154_CMD_ASRSP_AS_SUCCESS){
564
        /* Association was successful. */
565
0
        if(packet->src_addr_mode != IEEE802154_FCF_ADDR_SHORT){
566
0
            col_append_fstr(pinfo->cinfo, COL_INFO, ", PAN: 0x%04x", packet->dst_pan);
567
0
        }
568
0
        if(packet->src16 != IEEE802154_NO_ADDR16){
569
0
            col_append_fstr(pinfo->cinfo, COL_INFO, " Addr: 0x%04x", packet->src16);
570
0
        }
571
0
    }
572
0
    else{
573
        /* Association was unsuccessful. */
574
0
        col_append_str(pinfo->cinfo, COL_INFO, ", Unsuccessful");
575
0
    }
576
577
    /* Update the address table. */
578
0
    if((status == IEEE802154_CMD_ASRSP_AS_SUCCESS) && (packet->src16 != IEEE802154_NO_ADDR16)){
579
0
        ieee802154_addr_update(&miwi_map, packet->src16, packet->dst_pan, packet->dst64,
580
0
                pinfo->current_proto, pinfo->num);
581
0
    }
582
583
    /* Get and display capability info. */
584
0
    cap = tvb_get_uint8(tvb, *offset);
585
0
    proto_tree_add_uint(subtree, hf_miwi_cap_info, tvb, *offset, 1, cap);
586
0
    proto_tree_add_bitmask_list(subtree, tvb, *offset, 1, capability, ENC_NA);
587
0
    *offset += 1;
588
589
    /* Call the data dissector for any leftover bytes. */
590
0
    if(tvb_captured_length(tvb) > *offset){
591
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
592
0
    }
593
0
}/* dissect_miwi_connect_rsp */
594
/**
595
 * Command subdissector routine for the Channel Hopping command.
596
 *
597
 * @param tvb pointer to buffer containing raw packet.
598
 * @param pinfo pointer to packet information fields.
599
 * @param tree pointer to protocol tree.
600
 * @param packet Miwi P2PStar packet information.
601
 * @param offset offset into the tvb to find the packet information.
602
 */
603
static void
604
dissect_miwi_channel_hop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
605
0
{
606
0
    uint8_t current_op_channel,dst_channel_to_jump_to;
607
0
    proto_tree *subtree;
608
0
    proto_item *ti;
609
610
    /* Create a subtree for this command frame. */
611
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
612
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
613
0
    current_op_channel = tvb_get_uint8(tvb, *offset);
614
0
    ti = proto_tree_add_uint(subtree, hf_miwi_current_op_channel, tvb, *offset, 1, current_op_channel);
615
0
    proto_item_append_text(ti, ", Current Operating Channel: %i", current_op_channel);
616
0
   *offset +=1;
617
618
0
    dst_channel_to_jump_to = tvb_get_uint8(tvb, *offset);
619
0
    ti = proto_tree_add_uint(subtree, hf_miwi_dst_channel_to_jump_to, tvb, *offset, 1, dst_channel_to_jump_to);
620
0
    proto_item_append_text(ti, ", Destination Channel to Jump to: %i", dst_channel_to_jump_to);
621
0
    *offset +=1;
622
623
    /* Call the data dissector for any leftover bytes. */
624
0
    if(tvb_captured_length(tvb) > *offset){
625
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
626
0
    }
627
0
}/* dissect_miwi_channel_hop */
628
629
/**
630
 * Command subdissector routine for the Connection removal response command.
631
 *
632
 * @param tvb pointer to buffer containing raw packet.
633
 * @param pinfo pointer to packet information fields.
634
 * @param tree pointer to protocol tree.
635
 * @param packet Miwi P2PStar packet information.
636
 * @param offset offset into the tvb to find the packet information.
637
 */
638
static void
639
dissect_miwi_connect_removal_res(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
640
0
{
641
0
    uint8_t conn_rmv_res_status;
642
0
    proto_tree *subtree;
643
0
    proto_item *ti;
644
645
   /* Create a subtree for this command frame. */
646
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
647
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
648
0
    conn_rmv_res_status = tvb_get_uint8(tvb, *offset);
649
0
    ti = proto_tree_add_uint(subtree, hf_miwi_conn_rmv_res_status, tvb, *offset, 1, conn_rmv_res_status);
650
0
    *offset +=1;
651
0
    if(conn_rmv_res_status == 0x00){
652
0
        proto_item_append_text(ti, ", Successful [Status: %i]", conn_rmv_res_status);
653
0
    } else
654
0
        proto_item_append_text(ti, ", Failed [Error Code: %i]", conn_rmv_res_status);
655
656
    /* Call the data dissector for any leftover bytes. */
657
0
    if(tvb_captured_length(tvb) > *offset){
658
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
659
0
    }
660
0
}/* dissect_miwi_connect_removal_res */
661
662
/**
663
 * Command subdissector routine for the Scan request command.
664
 *
665
 * @param tvb pointer to buffer containing raw packet.
666
 * @param pinfo pointer to packet information fields.
667
 * @param tree pointer to protocol tree.
668
 * @param packet Miwi P2PStar packet information.
669
 * @param offset offset into the tvb to find the packet information.
670
 */
671
static void
672
dissect_miwi_active_scan_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
673
0
{
674
0
    uint8_t scan_cur_chan;
675
0
    proto_tree *subtree;
676
0
    proto_item *ti;
677
678
   /* Create a subtree for this command frame. */
679
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
680
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
681
0
    scan_cur_chan = tvb_get_uint8(tvb, *offset);
682
0
    ti = proto_tree_add_uint(subtree, hf_miwi_current_op_channel, tvb, *offset, 1, scan_cur_chan);
683
0
    proto_item_append_text(ti, ", Current operating Channel %i", scan_cur_chan);
684
0
    *offset +=1;
685
686
    /* Call the data dissector for any leftover bytes. */
687
0
    if(tvb_captured_length(tvb) > *offset){
688
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
689
0
    }
690
0
}/* dissect_miwi_active_scan_req */
691
/**
692
 * Command subdissector routine for the Scan response command.
693
 *
694
 * @param tvb pointer to buffer containing raw packet.
695
 * @param pinfo pointer to packet information fields.
696
 * @param tree pointer to protocol tree.
697
 * @param packet Miwi P2PStar packet information.
698
 * @param offset offset into the tvb to find the packet information.
699
 */
700
701
static void
702
dissect_miwi_active_scan_res(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
703
0
{
704
0
    uint8_t cap,scan_res_node_id;
705
0
    proto_tree *subtree;
706
0
    static int* const capability[] = {
707
0
        &hf_miwi_cap_info_rcv_on_idle,
708
0
        &hf_miwi_cap_info_rqst_data_on_wp,
709
0
        &hf_miwi_cap_info_need_time_sync,
710
0
        &hf_miwi_cap_info_security_cap,
711
0
        &hf_miwi_cap_info_reserved,
712
0
        NULL
713
0
    };
714
715
    /* Create a subtree for this command frame. */
716
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
717
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
718
719
    /* Get and display capability info. */
720
0
    cap = tvb_get_uint8(tvb, *offset);
721
0
    proto_tree_add_uint(subtree, hf_miwi_cap_info, tvb, *offset, 1, cap);
722
0
    proto_tree_add_bitmask_list(subtree, tvb, *offset, 1, capability, ENC_NA);
723
0
    *offset += 1;
724
725
0
    scan_res_node_id = tvb_get_uint8(tvb, *offset);
726
0
    proto_tree_add_uint(subtree, hf_miwi_oper_chan, tvb, *offset, 1, scan_res_node_id);
727
0
    *offset += 1;
728
729
    /* Call the data dissector for any leftover bytes. */
730
0
    if(tvb_captured_length(tvb) > *offset){
731
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
732
0
    }
733
0
}/* dissect_miwi_active_scan_res */
734
/**
735
 * Command subdissector routine for the forward Packet command.
736
 *
737
 * @param tvb pointer to buffer containing raw packet.
738
 * @param pinfo pointer to packet information fields.
739
 * @param tree pointer to protocol tree.
740
 * @param packet Miwi P2PStar packet information.
741
 * @param offset offset into the tvb to find the packet information.
742
 */
743
static void
744
dissect_miwi_fwd_packet_cmd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
745
0
{
746
0
    uint8_t fwd_pkt_dst_addr;
747
0
    proto_tree *subtree;
748
749
   /* Create a subtree for this command frame. */
750
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
751
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
752
0
    fwd_pkt_dst_addr = tvb_get_uint8(tvb, *offset);
753
0
    proto_tree_add_uint(subtree, hf_miwi_fwd_pkt_dst_addr, tvb, *offset, 1, fwd_pkt_dst_addr);
754
0
    *offset +=1;
755
756
    /* Call the data dissector for any leftover bytes. */
757
0
    if(tvb_captured_length(tvb) > *offset){
758
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
759
0
    }
760
0
}/* dissect_miwi_fwd_packet_cmd */
761
/**
762
 * Command subdissector routine for the Connection table broadcast command.
763
 *
764
 * @param tvb pointer to buffer containing raw packet.
765
 * @param pinfo pointer to packet information fields.
766
 * @param tree pointer to protocol tree.
767
 * @param packet Miwi P2PStar packet information.
768
 * @param offset offset into the tvb to find the packet information.
769
 */
770
771
static void
772
dissect_miwi_connect_tbl_bcast_cmd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
773
0
{
774
0
    uint8_t conn_tbl_size;
775
0
    proto_tree *subtree;
776
777
   /* Create a subtree for this command frame. */
778
0
    subtree = proto_tree_add_subtree(tree, tvb, *offset, 1,ett_miwi_p2pstar_cmd_tree, NULL,
779
0
                    val_to_str_const(packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
780
0
    conn_tbl_size = tvb_get_uint8(tvb, *offset);
781
0
    proto_tree_add_uint(subtree, hf_miwi_conn_tbl_size, tvb, *offset, 1, conn_tbl_size);
782
0
    *offset +=1;
783
784
    /* Call the data dissector for any leftover bytes. */
785
0
    if(tvb_captured_length(tvb) > *offset){
786
0
        call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
787
0
    }
788
0
}/* dissect_miwi_connect_tbl_bcast_cmd */
789
790
/**
791
 * Subdissector routine for MiWi P2P Star commands
792
 *
793
 * @param tvb pointer to buffer containing the command payload
794
 * @param pinfo pointer to packet information fields
795
 * @param tree pointer to the protocol tree
796
 * @param packet Miwi P2P Star packet information
797
 * @param offset offset into the tvb to find the packet information.
798
 */
799
static void
800
dissect_miwi_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, miwi_packet *packet, unsigned *offset)
801
0
{
802
0
    col_append_str(pinfo->cinfo, COL_INFO, val_to_str_const((const uint32_t)packet->command_id, miwi_p2pstar_cmd_names, "Unknown Command"));
803
804
0
    switch (packet->command_id){
805
0
        case MIWI_P2P_CMD_CONN_REQ:
806
0
            dissect_miwi_connect_req(tvb, pinfo, tree, packet,offset);
807
0
        break;
808
0
        case MIWI_P2P_CMD_CONN_RES:
809
0
            dissect_miwi_connect_rsp(tvb, pinfo, tree, packet,offset);
810
0
        break;
811
0
        case MIWI_P2P_CMD_CHANNEL_HOP:
812
0
            dissect_miwi_channel_hop(tvb, pinfo, tree, packet,offset);
813
0
        break;
814
0
        case MIWI_P2P_CMD_ACTIVE_SCAN_REQ:
815
0
            dissect_miwi_active_scan_req(tvb, pinfo, tree, packet,offset);
816
0
        break;
817
0
        case MIWI_P2P_CMD_CONN_REMOVAL_RES:
818
0
            dissect_miwi_connect_removal_res(tvb, pinfo, tree, packet,offset);
819
0
        break;
820
0
        case MIWI_P2P_CMD_ACTIVE_SCAN_RES:
821
0
            dissect_miwi_active_scan_res(tvb, pinfo, tree, packet,offset);
822
0
        break;
823
0
        case MIWI_STAR_CMD_FORWARD_PACKET:
824
0
            dissect_miwi_fwd_packet_cmd(tvb, pinfo, tree, packet,offset);
825
0
        break;
826
0
        case MIWI_STAR_CMD_CONN_TABLE:
827
0
            dissect_miwi_connect_tbl_bcast_cmd(tvb, pinfo, tree, packet,offset);
828
0
        break;
829
0
        case MIWI_P2P_CMD_DATA_REQ:
830
0
        case MIWI_P2P_CMD_CONN_REMOVAL_REQ:
831
0
        case MIWI_STAR_CMD_SOFT_ACK:
832
0
        case MIWI_STAR_CMD_LINK_STATUS:
833
            /* No payload expected. */
834
0
        break;
835
0
        default:
836
0
            proto_item_append_text(tree, ", Unknown Command");
837
0
              if(tvb_captured_length_remaining(tvb, 0) > 0){
838
0
                call_data_dissector(tvb, pinfo, tree);
839
0
        break;
840
0
            }
841
0
    }/* switch */
842
0
}/* dissect_miwi_command */
843
844
/**
845
 * Subdissector routine for MiWi P2P Star header parsing
846
 *
847
 * @param tvb pointer to buffer containing the command payload
848
 * @param pinfo pointer to packet information fields
849
 * @param tree pointer to the protocol tree
850
 * @param created_header_tree new tree to parse the MiWi packet .
851
 * @param parsed_info Miwi P2P Star packet information
852
 */
853
static unsigned
854
miwi_dissect_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree **created_header_tree, miwi_packet **parsed_info)
855
0
{
856
0
    proto_tree              *miwi_tree = NULL;
857
0
    proto_item              *proto_root = NULL;
858
0
    proto_item              *hidden_item;
859
0
    proto_item              *ti;
860
0
    unsigned                offset = 0;
861
0
    bool                    dstPanPresent = false;
862
0
    bool                    srcPanPresent = false;
863
0
    miwi_packet      *packet = wmem_new0(pinfo->pool, miwi_packet);
864
0
    ieee802154_short_addr   addr16;
865
0
    ieee802154_hints_t     *ieee_hints;
866
867
0
    packet->short_table = miwi_map.short_table;
868
869
    /* Allocate frame data with hints for upper layers */
870
0
    if(!PINFO_FD_VISITED(pinfo) ||
871
0
        (ieee_hints = (ieee802154_hints_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_miwi_p2pstar, 0)) == NULL){
872
0
        ieee_hints = wmem_new0(wmem_file_scope(), ieee802154_hints_t);
873
0
        p_add_proto_data(wmem_file_scope(), pinfo, proto_miwi_p2pstar, 0, ieee_hints);
874
0
    }
875
876
    /* Save a pointer to the whole packet */
877
0
    ieee_hints->packet = packet;
878
879
    /* Create the protocol tree. */
880
0
    proto_root = proto_tree_add_protocol_format(tree, proto_miwi_p2pstar, tvb, 0, tvb_captured_length(tvb), "IEEE 802.15.4-MiWi");
881
0
    miwi_tree = proto_item_add_subtree(proto_root, ett_miwi_p2pstar);
882
    /* Add the protocol name. */
883
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MiWi P2P Star");
884
885
    /* Set out parameters */
886
0
    *created_header_tree = miwi_tree;
887
0
    *parsed_info = packet;
888
889
    /* Add the packet length to the filter field */
890
0
    hidden_item = proto_tree_add_uint(miwi_tree, hf_miwi_frame_length, NULL, 0, 0, tvb_reported_length(tvb));
891
0
    proto_item_set_hidden(hidden_item);
892
893
    /* Frame Control Field */
894
0
    dissect_miwi_fcf(tvb, pinfo, miwi_tree, packet, &offset);
895
896
    /* Sequence Number */
897
    /* IEEE 802.15.4 Sequence Number Suppression */
898
0
    packet->seqno = tvb_get_uint8(tvb, offset);
899
0
    proto_tree_add_uint(miwi_tree, hf_miwi_seq, tvb, offset, 1, packet->seqno);
900
    /* For Ack packets display this in the root. */
901
0
    if(packet->frame_type == IEEE802154_FCF_ACK){
902
0
        proto_item_append_text(proto_root, ", Sequence Number: %u", packet->seqno);
903
0
    }
904
0
    offset += 1;
905
906
    /*
907
     * ADDRESSING FIELDS
908
     */
909
    /* Clear out the addressing strings. */
910
0
    clear_address(&pinfo->net_dst);
911
0
    clear_address(&pinfo->dl_dst);
912
0
    clear_address(&pinfo->dst);
913
0
    clear_address(&pinfo->net_src);
914
0
    clear_address(&pinfo->dl_src);
915
0
    clear_address(&pinfo->src);
916
917
0
    if(packet->dst_addr_mode == IEEE802154_FCF_ADDR_RESERVED){
918
        /* Invalid Destination Address Mode. Abort Dissection. */
919
0
        expert_add_info(pinfo, proto_root, &ei_miwi_dst);
920
0
        return 0;
921
0
    }
922
923
0
    if(packet->src_addr_mode == IEEE802154_FCF_ADDR_RESERVED){
924
        /* Invalid Source Address Mode. Abort Dissection. */
925
0
        expert_add_info(pinfo, proto_root, &ei_miwi_src);
926
0
        return 0;
927
0
    }
928
929
0
    if(packet->version == IEEE802154_VERSION_RESERVED){
930
        /* Unknown Frame Version. Abort Dissection. */
931
0
        expert_add_info(pinfo, proto_root, &ei_miwi_frame_ver);
932
0
        return 0;
933
0
    }
934
0
    else if((packet->version == IEEE802154_VERSION_2003) ||  /* For Frame Version 0b00 and */
935
0
             (packet->version == IEEE802154_VERSION_2006))  { /* 0b01 effect defined in section 7.2.1.5 */
936
937
0
        if((packet->dst_addr_mode != IEEE802154_FCF_ADDR_NONE) && /* if both destination and source */
938
0
            (packet->src_addr_mode != IEEE802154_FCF_ADDR_NONE)){ /* addressing information is present */
939
0
            if(packet->pan_id_compression == 1){ /* PAN IDs are identical */
940
0
                dstPanPresent = true;
941
0
                srcPanPresent = false; /* source PAN ID is omitted */
942
0
            }
943
0
            else{ /* PAN IDs are different, both shall be included in the frame */
944
0
                dstPanPresent = true;
945
0
                srcPanPresent = true;
946
0
            }
947
0
        }
948
0
        else{
949
0
            if(packet->pan_id_compression == 1){ /* all remaining cases pan_id_compression must be zero */
950
0
                expert_add_info(pinfo, proto_root, &ei_miwi_invalid_panid_compression);
951
0
                return 0;
952
0
            }
953
0
            else{
954
                /* only either the destination or the source addressing information is present */
955
0
                if((packet->dst_addr_mode != IEEE802154_FCF_ADDR_NONE) &&        /*   Present   */
956
0
                    (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE)){        /* Not Present */
957
0
                    dstPanPresent = true;
958
0
                    srcPanPresent = false;
959
0
                }
960
0
                else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_NONE) &&   /* Not Present */
961
0
                         (packet->src_addr_mode != IEEE802154_FCF_ADDR_NONE)){   /*   Present   */
962
0
                    dstPanPresent = false;
963
0
                    srcPanPresent = true;
964
0
                }
965
0
                else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_NONE) &&   /* Not Present */
966
0
                         (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE)){   /* Not Present */
967
0
                    dstPanPresent = false;
968
0
                    srcPanPresent = false;
969
0
                }
970
0
                else{
971
0
                    expert_add_info(pinfo, proto_root, &ei_miwi_invalid_addressing);
972
0
                    return 0;
973
0
                }
974
0
            }
975
0
        }
976
0
    }
977
0
    else if(packet->version == IEEE802154_VERSION_2015){
978
        /* for Frame Version 0b10 PAN Id Compression only applies to these frame types */
979
0
        if((packet->frame_type == IEEE802154_FCF_BEACON) ||
980
0
            (packet->frame_type == IEEE802154_FCF_DATA)   ||
981
0
            (packet->frame_type == IEEE802154_FCF_ACK)    ||
982
0
            (packet->frame_type == IEEE802154_FCF_CMD)       ){
983
984
            /* Implements Table 7-6 of IEEE 802.15.4-2015
985
             *
986
             *      Destination Address  Source Address  Destination PAN ID  Source PAN ID   PAN ID Compression
987
             *-------------------------------------------------------------------------------------------------
988
             *  1.  Not Present          Not Present     Not Present         Not Present     0
989
             *  2.  Not Present          Not Present     Present             Not Present     1
990
             *  3.  Present              Not Present     Present             Not Present     0
991
             *  4.  Present              Not Present     Not Present         Not Present     1
992
             *
993
             *  5.  Not Present          Present         Not Present         Present         0
994
             *  6.  Not Present          Present         Not Present         Not Present     1
995
             *
996
             *  7.  Extended             Extended        Present             Not Present     0
997
             *  8.  Extended             Extended        Not Present         Not Present     1
998
             *
999
             *  9.  Short                Short           Present             Present         0
1000
             * 10.  Short                Extended        Present             Present         0
1001
             * 11.  Extended             Short           Present             Present         0
1002
             *
1003
             * 12.  Short                Extended        Present             Not Present     1
1004
             * 13.  Extended             Short           Present             Not Present     1
1005
             * 14.  Short                Short           Present             Not Present     1
1006
             */
1007
1008
            /* Row 1 */
1009
0
            if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_NONE) &&      /* Not Present */
1010
0
                (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE) &&      /* Not Present */
1011
0
                (packet->pan_id_compression == 0)){
1012
0
                        dstPanPresent = false;
1013
0
                        srcPanPresent = false;
1014
0
            }
1015
            /* Row 2 */
1016
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_NONE) && /* Not Present */
1017
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE) && /* Not Present */
1018
0
                     (packet->pan_id_compression == 1)){
1019
0
                        dstPanPresent = true;
1020
0
                        srcPanPresent = false;
1021
0
            }
1022
            /* Row 3 */
1023
0
            else if((packet->dst_addr_mode != IEEE802154_FCF_ADDR_NONE) && /*  Present    */
1024
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE) && /* Not Present */
1025
0
                     (packet->pan_id_compression == 0)){
1026
0
                        dstPanPresent = true;
1027
0
                        srcPanPresent = false;
1028
0
            }
1029
            /* Row 4 */
1030
0
            else if((packet->dst_addr_mode != IEEE802154_FCF_ADDR_NONE) && /*  Present    */
1031
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_NONE) && /* Not Present */
1032
0
                     (packet->pan_id_compression == 1)){
1033
0
                        dstPanPresent = false;
1034
0
                        srcPanPresent = false;
1035
0
            }
1036
            /* Row 5 */
1037
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_NONE) && /* Not Present */
1038
0
                     (packet->src_addr_mode != IEEE802154_FCF_ADDR_NONE) && /*  Present    */
1039
0
                     (packet->pan_id_compression == 0)){
1040
0
                        dstPanPresent = false;
1041
0
                        srcPanPresent = true;
1042
0
            }
1043
            /* Row 6 */
1044
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_NONE) && /* Not Present */
1045
0
                     (packet->src_addr_mode != IEEE802154_FCF_ADDR_NONE) && /*  Present    */
1046
0
                     (packet->pan_id_compression == 1)){
1047
0
                        dstPanPresent = false;
1048
0
                        srcPanPresent = false;
1049
0
            }
1050
            /* Row 7 */
1051
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_EXT) && /*  Extended    */
1052
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_EXT) && /*  Extended    */
1053
0
                     (packet->pan_id_compression == 0)){
1054
0
                        dstPanPresent = true;
1055
0
                        srcPanPresent = false;
1056
0
            }
1057
            /* Row 8 */
1058
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_EXT) && /*  Extended    */
1059
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_EXT) && /*  Extended    */
1060
0
                     (packet->pan_id_compression == 1)){
1061
0
                        dstPanPresent = false;
1062
0
                        srcPanPresent = false;
1063
0
            }
1064
            /* Row 9 */
1065
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_SHORT) && /*  Short     */
1066
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_SHORT) && /*  Short     */
1067
0
                     (packet->pan_id_compression == 0)){
1068
0
                        dstPanPresent = true;
1069
0
                        srcPanPresent = true;
1070
0
            }
1071
            /* Row 10 */
1072
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_SHORT) && /*  Short    */
1073
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_EXT) &&   /*  Extended */
1074
0
                     (packet->pan_id_compression == 0)){
1075
0
                        dstPanPresent = true;
1076
0
                        srcPanPresent = true;
1077
0
            }
1078
            /* Row 11 */
1079
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_EXT)   &&   /*  Extended */
1080
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_SHORT) &&   /*  Short    */
1081
0
                     (packet->pan_id_compression == 0)){
1082
0
                        dstPanPresent = true;
1083
0
                        srcPanPresent = true;
1084
0
            }
1085
            /* Row 12 */
1086
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_SHORT) &&   /*  Short    */
1087
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_EXT)   &&   /*  Extended */
1088
0
                     (packet->pan_id_compression == 1)){
1089
0
                        dstPanPresent = true;
1090
0
                        srcPanPresent = false;
1091
0
            }
1092
            /* Row 13 */
1093
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_EXT)   &&   /*  Extended */
1094
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_SHORT) &&   /*  Short    */
1095
0
                     (packet->pan_id_compression == 1)){
1096
0
                        dstPanPresent = true;
1097
0
                        srcPanPresent = false;
1098
0
            }
1099
            /* Row 14 */
1100
0
            else if((packet->dst_addr_mode == IEEE802154_FCF_ADDR_SHORT) &&   /*  Short    */
1101
0
                     (packet->src_addr_mode == IEEE802154_FCF_ADDR_SHORT) &&   /*  Short    */
1102
0
                     (packet->pan_id_compression == 1)){
1103
0
                        dstPanPresent = true;
1104
0
                        srcPanPresent = false;
1105
0
            }
1106
0
            else{
1107
0
                expert_add_info(pinfo, proto_root, &ei_miwi_invalid_panid_compression2);
1108
0
                return 0;
1109
0
            }
1110
0
        }
1111
0
        else{ /* Frame Type is neither Beacon, Data, Ack, nor Command: PAN ID Compression is not used */
1112
0
            dstPanPresent = false; /* no PAN ID will */
1113
0
            srcPanPresent = false; /* be present     */
1114
0
        }
1115
0
    }
1116
0
    else{
1117
        /* Unknown Frame Version. Abort Dissection. */
1118
0
        expert_add_info(pinfo, proto_root, &ei_miwi_frame_ver);
1119
0
        return 0;
1120
0
    }
1121
1122
    /*
1123
     * Addressing Fields
1124
     */
1125
1126
    /* Destination PAN Id */
1127
0
    if(dstPanPresent){
1128
0
        char* pan_id = (char *)wmem_new(pinfo->pool, uint64_t);
1129
1130
0
        packet->dst_pan = tvb_get_letohs(tvb, offset);
1131
0
        miwi_short_to_str(packet->dst_pan,pan_id,10);
1132
1133
0
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Pan ID: %s", pan_id);
1134
0
        proto_tree_add_uint(miwi_tree, hf_miwi_dst_panid, tvb, offset, 2, packet->dst_pan);
1135
0
        offset += 2;
1136
0
    }
1137
1138
    /* Destination Address  */
1139
0
    if(packet->dst_addr_mode == IEEE802154_FCF_ADDR_SHORT){
1140
0
        char* dst_addr = (char *)wmem_new(pinfo->pool, uint64_t);
1141
1142
        /* Get the address. */
1143
0
        packet->dst16 = tvb_get_letohs(tvb, offset);
1144
1145
        /* Provide address hints to higher layers that need it. */
1146
0
        if(ieee_hints){
1147
0
            ieee_hints->dst16 = packet->dst16;
1148
0
        }
1149
1150
0
        set_address_tvb(&pinfo->dl_dst, miwi_short_address_type, 2, tvb, offset);
1151
0
        copy_address_shallow(&pinfo->dst, &pinfo->dl_dst);
1152
0
        miwi_short_to_str(packet->dst16,dst_addr,10);
1153
1154
0
        proto_tree_add_uint(miwi_tree, hf_miwi_short_dst_addr, tvb, offset, 2, packet->dst16);
1155
0
        proto_item_append_text(proto_root, ", Dst: %s", dst_addr);
1156
0
        ti = proto_tree_add_uint(miwi_tree, hf_miwi_addr16, tvb, offset, 2, packet->dst16);
1157
0
        proto_item_set_generated(ti);
1158
0
        proto_item_set_hidden(ti);
1159
1160
0
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: %s", dst_addr);
1161
0
        offset += 2;
1162
0
    }
1163
0
    else if(packet->dst_addr_mode == IEEE802154_FCF_ADDR_EXT){
1164
0
        uint64_t *p_addr = (uint64_t *)wmem_new(pinfo->pool, uint64_t);
1165
1166
        /* Get the address */
1167
0
        packet->dst64 = tvb_get_letoh64(tvb, offset);
1168
1169
        /* Copy and convert the address to network byte order. */
1170
0
        *p_addr = pntohu64(&(packet->dst64));
1171
1172
        /* Display the destination address. */
1173
        /* XXX - OUI resolution doesn't happen when displaying resolved
1174
         * EUI64 addresses; that should probably be fixed in
1175
         * epan/addr_resolv.c.
1176
         */
1177
0
        set_address(&pinfo->dl_dst, AT_EUI64, 8, p_addr);
1178
0
        copy_address_shallow(&pinfo->dst, &pinfo->dl_dst);
1179
0
        proto_tree_add_item(miwi_tree, hf_miwi_ext_dst_addr, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1180
0
        proto_item_append_text(proto_root, ", Dst: %s", eui64_to_display(pinfo->pool, packet->dst64));
1181
0
        ti = proto_tree_add_item(miwi_tree, hf_miwi_addr64, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1182
0
        proto_item_set_generated(ti);
1183
0
        proto_item_set_hidden(ti);
1184
0
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: %s", eui64_to_display(pinfo->pool, packet->dst64));
1185
0
        offset += 8;
1186
0
    }
1187
1188
    /* Source PAN Id */
1189
0
    if(srcPanPresent){
1190
0
        char* pan_id = (char *)wmem_new(pinfo->pool, uint64_t);
1191
0
        packet->src_pan = tvb_get_letohs(tvb, offset);
1192
0
        miwi_short_to_str(packet->src_pan,pan_id,10);
1193
0
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Src Pan ID: %s", pan_id);
1194
0
        proto_tree_add_uint(miwi_tree, hf_miwi_src_panid, tvb, offset, 2, packet->src_pan);
1195
0
        offset += 2;
1196
0
    }
1197
0
    else{
1198
0
        if(dstPanPresent){
1199
0
            packet->src_pan = packet->dst_pan;
1200
0
        }
1201
0
        else{
1202
0
            packet->src_pan = IEEE802154_BCAST_PAN;
1203
0
        }
1204
0
    }
1205
0
    if(ieee_hints){
1206
0
        ieee_hints->src_pan = packet->src_pan;
1207
0
    }
1208
1209
    /* Source Address */
1210
0
    if(packet->src_addr_mode == IEEE802154_FCF_ADDR_SHORT){
1211
0
        char* src_addr = (char *)wmem_new(pinfo->pool, uint64_t);
1212
1213
        /* Get the address. */
1214
0
        packet->src16 = tvb_get_letohs(tvb, offset);
1215
1216
0
        if(!PINFO_FD_VISITED(pinfo)){
1217
            /* If we know our extended source address from previous packets,
1218
                * provide a pointer to it in a hint for upper layers */
1219
0
            addr16.addr = packet->src16;
1220
0
            addr16.pan = packet->src_pan;
1221
1222
0
            if(ieee_hints){
1223
0
                ieee_hints->src16 = packet->src16;
1224
0
                ieee_hints->map_rec = (ieee802154_map_rec *)
1225
0
                    g_hash_table_lookup(miwi_map.short_table, &addr16);
1226
0
            }
1227
0
        }
1228
1229
0
        set_address_tvb(&pinfo->dl_src, miwi_short_address_type, 2, tvb, offset);
1230
0
        copy_address_shallow(&pinfo->src, &pinfo->dl_src);
1231
0
        miwi_short_to_str(packet->src16,src_addr,10);
1232
1233
        /* Add the addressing info to the tree. */
1234
0
        proto_tree_add_uint(miwi_tree, hf_miwi_short_src_addr, tvb, offset, 2, packet->src16);
1235
0
        proto_item_append_text(proto_root, ", Src: %s", src_addr);
1236
0
        ti = proto_tree_add_uint(miwi_tree, hf_miwi_addr16, tvb, offset, 2, packet->src16);
1237
0
        proto_item_set_generated(ti);
1238
0
        proto_item_set_hidden(ti);
1239
1240
0
        if(ieee_hints && ieee_hints->map_rec){
1241
            /* Display inferred source address info */
1242
0
            ti = proto_tree_add_eui64(miwi_tree, hf_miwi_short_src_addr, tvb, offset, 0,
1243
0
                    ieee_hints->map_rec->addr64);
1244
0
            proto_item_set_generated(ti);
1245
0
            ti = proto_tree_add_eui64(miwi_tree, hf_miwi_addr64, tvb, offset, 0, ieee_hints->map_rec->addr64);
1246
0
            proto_item_set_generated(ti);
1247
0
            proto_item_set_hidden(ti);
1248
1249
0
            if( ieee_hints->map_rec->start_fnum ){
1250
0
                ti = proto_tree_add_uint(miwi_tree, hf_miwi_src64_origin, tvb, 0, 0,
1251
0
                    ieee_hints->map_rec->start_fnum);
1252
0
            }
1253
0
            else{
1254
0
                ti = proto_tree_add_uint_format_value(miwi_tree, hf_miwi_src64_origin, tvb, 0, 0,
1255
0
                    ieee_hints->map_rec->start_fnum, "Pre-configured");
1256
0
            }
1257
0
            proto_item_set_generated(ti);
1258
0
        }
1259
1260
0
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Src: %s", src_addr);
1261
1262
0
        offset += 2;
1263
0
    }
1264
0
    else if(packet->src_addr_mode == IEEE802154_FCF_ADDR_EXT){
1265
0
        uint64_t *p_addr = (uint64_t *)wmem_new(pinfo->pool, uint64_t);
1266
1267
        /* Get the address. */
1268
0
        packet->src64 = tvb_get_letoh64(tvb, offset);
1269
1270
        /* Copy and convert the address to network byte order. */
1271
0
        *p_addr = pntohu64(&(packet->src64));
1272
1273
        /* Display the source address. */
1274
        /* XXX - OUI resolution doesn't happen when displaying resolved
1275
         * EUI64 addresses; that should probably be fixed in
1276
         * epan/addr_resolv.c.
1277
         */
1278
0
        set_address(&pinfo->dl_src, AT_EUI64, 8, p_addr);
1279
0
        copy_address_shallow(&pinfo->src, &pinfo->dl_src);
1280
0
        proto_tree_add_item(miwi_tree, hf_miwi_ext_src_addr, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1281
0
        proto_item_append_text(proto_root, ", Src: %s", eui64_to_display(pinfo->pool, packet->src64));
1282
0
        ti = proto_tree_add_item(miwi_tree, hf_miwi_addr64, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1283
0
        proto_item_set_generated(ti);
1284
0
        proto_item_set_hidden(ti);
1285
1286
0
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Src: %s", eui64_to_display(pinfo->pool, packet->src64));
1287
0
        offset += 8;
1288
0
    }
1289
1290
    /* All of the beacon fields, except the beacon payload are considered nonpayload. */
1291
0
    if((packet->version == IEEE802154_VERSION_2003) || (packet->version == IEEE802154_VERSION_2006)){
1292
1293
0
        if(packet->frame_type == IEEE802154_FCF_CMD){
1294
            /**
1295
             * In IEEE802.15.4-2003 and 2006 the command identifier is considered to be part of the header
1296
             * and is thus not encrypted. For IEEE802.15.4-2012e and later the command id is considered to be
1297
             * part of the payload, is encrypted, and follows the payload IEs. Thus we only parse the command id
1298
             * here for 2006 and earlier frames. */
1299
0
            packet->command_id = tvb_get_uint8(tvb, offset);
1300
0
            proto_tree_add_uint(miwi_tree, hf_miwi_cmd_id, tvb, offset, 1, packet->command_id);
1301
0
            offset++;
1302
0
        }
1303
0
    }
1304
0
    return offset;
1305
0
}/*miwi_dissect_header*/
1306
1307
/**
1308
 * Subdissector routine for MiWi P2P Star frame payload parsing
1309
 *
1310
 * @param tvb pointer to buffer containing the command payload
1311
 * @param pinfo pointer to packet information fields
1312
 * @param ieee802154_tree pointer to the protocol tree
1313
 * @param packet Miwi P2P Star packet information
1314
 * @param fcs_ok set to false to indicate FCS verification failed
1315
 * @param offset offset into the tvb to find the packet information.
1316
 */
1317
static unsigned miwi_dissect_frame_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ieee802154_tree, miwi_packet *packet, bool fcs_ok, unsigned *offset)
1318
0
{
1319
0
    tvbuff_t *payload_tvb = tvb;
1320
0
    proto_tree *tree = proto_tree_get_parent_tree(ieee802154_tree);
1321
    //heur_dtbl_entry_t *hdtbl_entry;
1322
1323
    /* There are commands without payload */
1324
0
    if(tvb_captured_length(payload_tvb) > 0 || packet->frame_type == IEEE802154_FCF_CMD){
1325
        /*
1326
         * Wrap the sub-dissection in a try/catch block in case the payload is
1327
         * broken. First we store the current protocol so we can fix it if an
1328
         * exception is thrown by the subdissectors.
1329
         */
1330
0
        const char* saved_proto = pinfo->current_proto;
1331
        /* Try to dissect the payload. */
1332
0
        TRY {
1333
0
            switch (packet->frame_type){
1334
0
            case IEEE802154_FCF_BEACON:
1335
0
                     call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
1336
0
            break;
1337
1338
0
            case IEEE802154_FCF_CMD:
1339
0
                dissect_miwi_command(payload_tvb, pinfo, ieee802154_tree, packet,offset);
1340
0
            break;
1341
1342
0
            case IEEE802154_FCF_DATA:
1343
                /* Sanity-check. */
1344
0
               if((!fcs_ok && miwi_fcs_ok) || !tvb_reported_length(payload_tvb)){
1345
0
                    call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
1346
0
                }
1347
0
            break;
1348
0
            default:
1349
                /* Could not subdissect, call the data dissector instead. */
1350
0
                call_data_dissector(tvb_new_subset_remaining(tvb, *offset), pinfo, tree);
1351
0
            break;
1352
0
            }/* switch */
1353
0
        }
1354
0
        CATCH_ALL {
1355
            /*
1356
             * Someone encountered an error while dissecting the payload. But
1357
             * we haven't yet finished processing all of our layer. Catch and
1358
             * display the exception, then fall-through to finish displaying
1359
             * the FCS (which we display last so the frame is ordered correctly
1360
             * in the tree).
1361
             */
1362
0
            show_exception(payload_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
1363
0
            pinfo->current_proto = saved_proto;
1364
0
        }
1365
0
        ENDTRY;
1366
0
    }
1367
0
    return tvb_captured_length(tvb);
1368
0
}
1369
1370
#if 0
1371
/**
1372
 * Dissect the FCS at the end of the frame.
1373
 * That is only displayed if the included length of the tvb encompasses it.
1374
 *
1375
 * @param tvb the MiWi P2P Star frame tvb
1376
 * @param ieee802154_tree the MiWi P2P Star protocol tree
1377
 * @param fcs_len length of the FCS field
1378
 * @param fcs_ok set to false to indicate FCS verification failed
1379
 */
1380
static void
1381
miwi_dissect_fcs(tvbuff_t *tvb, proto_tree *ieee802154_tree, unsigned fcs_len, bool fcs_ok)
1382
{
1383
    proto_item *ti;
1384
    /* The FCS should be the last bytes of the reported packet. */
1385
    unsigned offset = tvb_reported_length(tvb)-fcs_len;
1386
    /* Dissect the FCS only if it exists (captures which don't or can't get the
1387
     * FCS will simply truncate the packet to omit it, but should still set the
1388
     * reported length to cover the original packet length), so if the snapshot
1389
     * is too short for an FCS don't make a fuss.
1390
     */
1391
    if(ieee802154_tree){
1392
        if(fcs_len == 2){
1393
            uint16_t    fcs = tvb_get_letohs(tvb, offset);
1394
1395
            ti = proto_tree_add_uint(ieee802154_tree, hf_miwi_fcs, tvb, offset, 2, fcs);
1396
            if(fcs_ok){
1397
                proto_item_append_text(ti, " (Correct)");
1398
            }
1399
            else{
1400
                proto_item_append_text(ti, " (Incorrect, expected FCS=0x%04x)", miwi_crc_tvb(tvb, offset));
1401
            }
1402
            /* To Help with filtering, add the fcs_ok field to the tree.  */
1403
            ti = proto_tree_add_boolean(ieee802154_tree, hf_miwi_fcs_ok, tvb, offset, 2, (uint32_t) fcs_ok);
1404
            proto_item_set_hidden(ti);
1405
        }
1406
    }
1407
}/* miwi_dissect_fcs */
1408
#endif
1409
1410
/**
1411
 * MiWi P2P Star packet dissection routine for Wireshark.
1412
 *
1413
 * This function extracts all the information first before displaying.
1414
 * If payload exists, that portion will be passed into another dissector
1415
 * for further processing.
1416
 *
1417
 * This is called after the individual dissect_p2pstar* functions
1418
 * have been called to determine what sort of FCS is present, if any.
1419
 *
1420
 * @param tvb pointer to buffer containing raw packet.
1421
 * @param pinfo pointer to packet information fields
1422
 * @param fcs_len length of the FCS field
1423
 */
1424
static void
1425
dissect_miwi_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned fcs_len)
1426
0
{
1427
0
    proto_tree *miwi_tree;
1428
0
    miwi_packet *packet;
1429
    //bool fcs_present;
1430
0
    bool fcs_ok;
1431
0
    tvbuff_t* no_fcs_tvb;
1432
0
    unsigned  offset = 0;
1433
1434
0
    if(fcs_len != 0){
1435
        /*
1436
         * Well, this packet should, in theory, have an FCS or CC24xx
1437
         * metadata.
1438
         * Do we have the entire packet, and does it have enough data for
1439
         * the FCS/metadata?
1440
         */
1441
0
        unsigned reported_len = tvb_reported_length(tvb);
1442
1443
0
        if(reported_len < fcs_len){
1444
            /*
1445
             * The packet is claimed not to even have enough data
1446
             * for the FCS/metadata.  Pretend it doesn't have one.
1447
             */
1448
0
            no_fcs_tvb = tvb;
1449
            //fcs_present = false;
1450
0
            fcs_ok = true;  // assume OK if not present
1451
0
        } else{
1452
            /*
1453
             * The packet is claimed to have enough data for the
1454
             * FCS/metadata.
1455
             * Slice it off from the reported length.
1456
             */
1457
0
            reported_len -= fcs_len;
1458
0
            no_fcs_tvb = tvb_new_subset_length(tvb, 0, reported_len);
1459
1460
            /*
1461
             * Is the FCS/metadata present in the captured data?
1462
             * reported_len is now the length of the packet without the
1463
             * FCS/metadata, so the FCS/metadata begins at an offset of
1464
             * reported_len.
1465
             */
1466
0
            if(tvb_bytes_exist(tvb, reported_len, fcs_len)){
1467
                /*
1468
                 * Yes.  Check whether the FCS was OK.
1469
                 *
1470
                 * If we have an FCS, check it.
1471
                 * If we have metadata, check its "FCS OK" flag.
1472
                 */
1473
                //fcs_present = true;
1474
0
                fcs_ok = is_fcs_ok(tvb, fcs_len);
1475
0
            } else{
1476
                /*
1477
                 * No.
1478
                 *
1479
                 * Either 1) this means that there was a snapshot length
1480
                 * in effect when the capture was done, and that sliced
1481
                 * some or all of the FCS/metadata off or 2) this is a
1482
                 * capture with no FCS/metadata, using the same link-layer
1483
                 * header type value as captures with the FCS/metadata,
1484
                 * and indicating the lack of the FCS/metadata by having
1485
                 * the captured length be the length of the packet minus
1486
                 * the length of the FCS/metadata and the actual length
1487
                 * being the length of the packet including the FCS/metadata,
1488
                 * rather than by using the "no FCS" link-layer header type.
1489
                 *
1490
                 * We could try to distinguish between them by checking
1491
                 * for a captured length that's exactly fcs_len bytes
1492
                 * less than the actual length.  That would allow us to
1493
                 * report packets that are cut short just before, or in
1494
                 * the middle of, the FCS as having been cut short by the
1495
                 * snapshot length.
1496
                 *
1497
                 * However, we can't distinguish between a packet that
1498
                 * happened to be cut fcs_len bytes short due to a
1499
                 * snapshot length being in effect when the capture was
1500
                 * done and a packet that *wasn't* cut short by a snapshot
1501
                 * length but that doesn't include the FCS/metadata.
1502
                 * Let's hope that rarely happens.
1503
                 */
1504
                //fcs_present = false;
1505
0
                fcs_ok = true;  // assume OK if not present
1506
0
            }
1507
0
        }
1508
0
    } else{
1509
0
        no_fcs_tvb = tvb;
1510
        //fcs_present = false;
1511
0
        fcs_ok = true;  // assume OK if not present
1512
0
    }
1513
1514
0
    unsigned mhr_len = miwi_dissect_header(no_fcs_tvb, pinfo, tree, &miwi_tree, &packet);
1515
0
    offset = mhr_len;
1516
0
    if(!mhr_len){
1517
0
        return;
1518
0
    }
1519
1520
0
        if(packet->frame_type == IEEE802154_FCF_DATA){
1521
0
            if((!fcs_ok && miwi_fcs_ok)){
1522
0
                call_data_dissector(tvb, pinfo, tree);
1523
0
            }
1524
0
        } else{
1525
0
            miwi_dissect_frame_payload(tvb, pinfo, miwi_tree, packet, fcs_ok, &offset);
1526
0
        }
1527
0
}
1528
1529
/**
1530
 * Dissector for MiWi P2P Star packet with an FCS containing a 16/32-bit
1531
 * CRC value at the end.
1532
 *
1533
 * @param tvb pointer to buffer containing raw packet.
1534
 * @param pinfo pointer to packet information fields.
1535
 * @param tree pointer to data tree wireshark uses to display packet.
1536
 */
1537
static int
1538
dissect_miwi_p2pstar(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1539
0
{
1540
0
    unsigned fcs_len;
1541
1542
    /* Set the default FCS length based on the FCS type in the configuration */
1543
  //  fcs_len = miwi_fcs_type_len(miwi_fcs_type);
1544
   // unsigned offset = 0;
1545
0
    proto_tree              *miwi_tree = NULL;
1546
0
    proto_item              *proto_root = NULL;
1547
   // miwi_packet      *packet = wmem_new0(pinfo->pool, miwi_packet);
1548
1549
    /* Set the default FCS length based on the FCS type in the configuration */
1550
0
    fcs_len = miwi_fcs_type_len(miwi_fcs_type);
1551
1552
    /* Call the common dissector. */
1553
   // dissect_miwi_common1(tvb, pinfo, tree);//, fcs_len);
1554
    /* Create the protocol tree. */
1555
0
    if (tree) {
1556
0
        proto_root = proto_tree_add_protocol_format(tree, proto_miwi_p2pstar, tvb, 0, tvb_captured_length(tvb), "MiWi P2PStar Protocol");
1557
0
        miwi_tree = proto_item_add_subtree(proto_root, ett_miwi_p2pstar);
1558
0
    }
1559
    /*Enter name of protocol to info field*/
1560
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MiWi P2PStar");
1561
    /* Call the common dissector. */
1562
0
    dissect_miwi_common(tvb, pinfo, miwi_tree, fcs_len);
1563
0
    return tvb_captured_length(tvb);
1564
0
}/* dissect_miwi_p2pstar */
1565
1566
/*FUNCTION:------------------------------------------------------
1567
 *  NAME
1568
 *      dissect_miwimesh_heur
1569
 *  DESCRIPTION
1570
 *      Heuristic interpreter for the Lightweight Mesh.
1571
 *  PARAMETERS
1572
 *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1573
 *      packet_into *pinfo  - pointer to packet information fields
1574
 *      proto_tree *tree    - pointer to data tree Wireshark uses to display packet.
1575
 *  RETURNS
1576
 *      Boolean value, whether it handles the packet or not.
1577
 *---------------------------------------------------------------
1578
 */
1579
static bool
1580
dissect_miwi_p2pstar_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1581
0
{
1582
#if 0
1583
    uint8_t endpt, srcep, dstep;
1584
1585
    /* 1) first byte must have bits 0000xxxx */
1586
    if(tvb_get_uint8(tvb, 0) & LWM_FCF_RESERVED)
1587
        return (false);
1588
1589
    /* The header should be at least long enough for the base header. */
1590
    if (tvb_reported_length(tvb) < LWM_HEADER_BASE_LEN)
1591
        return (false);
1592
1593
    /* The endpoints should either both be zero, or both non-zero. */
1594
    endpt = tvb_get_uint8(tvb, 6);
1595
    srcep = (endpt & LWM_SRC_ENDP_MASK) >> LWM_SRC_ENDP_OFFSET;
1596
    dstep = (endpt & LWM_DST_ENDP_MASK) >> LWM_DST_ENDP_OFFSET;
1597
    if ((srcep == 0) && (dstep != 0))
1598
        return (false);
1599
    if ((srcep != 0) && (dstep == 0))
1600
        return (false);
1601
#endif
1602
0
    dissect_miwi_p2pstar(tvb, pinfo, tree, data);
1603
0
    return (true);
1604
0
} /* dissect_lwm_heur */
1605
1606
/*FUNCTION:------------------------------------------------------
1607
 *  NAME
1608
 *      proto_register_miwi_p2pstar
1609
 *  DESCRIPTION
1610
 *      MiWi P2P Star protocol registration routine.
1611
 *  PARAMETERS
1612
 *      none
1613
 *  RETURNS
1614
 *      void
1615
 *---------------------------------------------------------------
1616
 */
1617
void proto_register_miwi_p2pstar(void)
1618
15
{
1619
1620
15
    static hf_register_info hf[] = {
1621
1622
15
        { &hf_miwi_frame_length,
1623
15
        { "Frame Length", "miwi_p2pstar.frame_length", FT_UINT8, BASE_DEC, NULL, 0x0,
1624
15
            "Frame Length as reported from lower layer", HFILL }},
1625
1626
15
        { &hf_miwi_fcf,
1627
15
        { "Frame Control Field", "miwi_p2pstar.fcf", FT_UINT16, BASE_HEX, NULL,
1628
15
            0x0, NULL, HFILL }},
1629
1630
15
        { &hf_miwi_fcf_frame_type,
1631
15
        { "Frame Type", "miwi_p2pstar.type", FT_UINT16, BASE_HEX, VALS(miwi_mac_frame_types),
1632
15
            MIWI_MAC_FCF_FRAME_TYPE, NULL, HFILL }},
1633
1634
15
        { &hf_miwi_fcf_security_enabled,
1635
15
        { "Security Enabled", "miwi_p2pstar.security_enable", FT_BOOLEAN, 16, NULL, MIWI_MAC_FCF_SECURITY_EN,
1636
15
            "Whether security operations are performed at the MAC layer or not.", HFILL }},
1637
1638
15
        { &hf_miwi_fcf_frame_pending,
1639
15
        { "Frame Pending", "miwi_p2pstar.pending", FT_BOOLEAN, 16, NULL, MIWI_MAC_FCF_FRAME_PENDING,
1640
15
            "Indication of additional packets waiting to be transferred from the source device.", HFILL }},
1641
1642
15
        { &hf_miwi_fcf_ack_req,
1643
15
        { "Acknowledge Request", "miwi_p2pstar.ack_request", FT_BOOLEAN, 16, NULL, MIWI_MAC_FCF_ACK_REQUEST,
1644
15
            "Whether the sender of this packet requests acknowledgment or not.", HFILL }},
1645
1646
15
        { &hf_miwi_fcf_panid_comp,
1647
15
        { "PAN ID Compression", "miwi_p2pstar.pan_id_compression", FT_BOOLEAN, 16, NULL, MIWI_MAC_FCF_PANID_COMP,
1648
15
            "Whether this packet contains the PAN ID or not.", HFILL }},
1649
1650
15
        { &hf_miwi_fcf_reserved,
1651
15
        { "Reserved", "miwi_p2pstar.fcf.reserved", FT_UINT16, BASE_HEX, NULL, MIWI_MAC_FCF_RESERVED,
1652
15
            NULL, HFILL }},
1653
1654
15
        { &hf_miwi_seq,
1655
15
        { "Sequence Number", "miwi_p2pstar.seq_no", FT_UINT8, BASE_DEC, NULL, 0x0,
1656
15
            NULL, HFILL }},
1657
1658
15
        { &hf_miwi_fcf_dest_addr_mode,
1659
15
        { "Destination Addressing Mode", "miwi_p2pstar.dst_addr_mode", FT_UINT16, BASE_HEX, VALS(miwi_addr_modes),
1660
15
            MIWI_MAC_FCF_DEST_ADDR_MODE, NULL, HFILL }},
1661
1662
15
        { &hf_miwi_fcf_src_addr_mode,
1663
15
        { "Source Addressing Mode", "miwi_p2pstar.src_addr_mode", FT_UINT16, BASE_HEX, VALS(miwi_addr_modes),
1664
15
            MIWI_MAC_FCF_SRC_ADDR_MODE, NULL, HFILL }},
1665
1666
15
        { &hf_miwi_fcf_frame_version,
1667
15
        { "Frame Version", "miwi_p2pstar.version", FT_UINT16, BASE_DEC, VALS(miwi_frame_versions),
1668
15
            MIWI_MAC_FCF_FRAME_VERSION, NULL, HFILL }},
1669
1670
15
        { &hf_miwi_dst_panid,
1671
15
        { "Destination PAN", "miwi_p2pstar.dst_pan", FT_UINT16, BASE_HEX, NULL, 0x0,
1672
15
            NULL, HFILL }},
1673
1674
15
        { &hf_miwi_short_dst_addr,
1675
15
        { "Destination", "miwi_p2pstar.dst16", FT_UINT16, BASE_HEX, NULL, 0x0,
1676
15
            NULL, HFILL }},
1677
1678
15
        { &hf_miwi_ext_dst_addr,
1679
15
        { "Destination", "miwi_p2pstar.dst64", FT_EUI64, BASE_NONE, NULL, 0x0,
1680
15
            NULL, HFILL }},
1681
1682
15
        { &hf_miwi_src_panid,
1683
15
        { "Source PAN", "miwi_p2pstar.src_pan", FT_UINT16, BASE_HEX, NULL, 0x0,
1684
15
            NULL, HFILL }},
1685
1686
15
        { &hf_miwi_short_src_addr,
1687
15
        { "Source", "miwi_p2pstar.src16", FT_UINT16, BASE_HEX, NULL, 0x0,
1688
15
            NULL, HFILL }},
1689
1690
15
        { &hf_miwi_ext_src_addr,
1691
15
        { "Extended Source", "miwi_p2pstar.src64", FT_EUI64, BASE_NONE, NULL, 0x0,
1692
15
            NULL, HFILL }},
1693
1694
15
        { &hf_miwi_addr16,
1695
15
        { "Address", "miwi_p2pstar.addr16", FT_UINT16, BASE_HEX, NULL, 0x0,
1696
15
            NULL, HFILL }},
1697
1698
15
        { &hf_miwi_addr64,
1699
15
        { "Extended Address", "miwi_p2pstar.addr64", FT_EUI64, BASE_NONE, NULL, 0x0,
1700
15
            NULL, HFILL }},
1701
1702
15
        { &hf_miwi_src64_origin,
1703
15
        { "Origin", "miwi_p2pstar.src64.origin", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1704
15
            NULL, HFILL }},
1705
1706
#if 0
1707
        { &hf_miwi_fcs,
1708
        { "FCS", "miwi_p2pstar.fcs", FT_UINT16, BASE_HEX, NULL, 0x0,
1709
            NULL, HFILL }},
1710
1711
        { &hf_miwi_fcs_ok,
1712
        { "FCS Valid", "miwi_p2pstar.fcs_ok", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1713
            NULL, HFILL }},
1714
#endif
1715
1716
15
        { &hf_miwi_cmd_id,
1717
15
        { "Command Identifier", "miwi_p2pstar.cmd", FT_UINT8, BASE_HEX, VALS(miwi_p2pstar_cmd_names), 0x0,
1718
15
            NULL, HFILL }},
1719
1720
15
        { &hf_miwi_cap_info,
1721
15
        { "Capability Information", "miwi_p2pstar.cap_info", FT_UINT8, BASE_HEX, NULL, 0x0,
1722
15
            NULL, HFILL }},
1723
1724
15
        { &hf_miwi_cap_info_rcv_on_idle,
1725
15
        { "Receiver On When Idle", "miwi_p2pstar.recv_on_when_idle", FT_BOOLEAN, 16, NULL, MIWI_CAP_INFO_RCV_ON_IDLE,
1726
15
            NULL, HFILL }},
1727
1728
15
        { &hf_miwi_cap_info_rqst_data_on_wp,
1729
15
        { "Request Data On Wake-up", "miwi_p2pstar.req_data_on_wakeup", FT_BOOLEAN, 16, NULL, MIWI_CAP_INFO_REQ_DATA_ON_WP,
1730
15
            NULL, HFILL }},
1731
1732
15
        { &hf_miwi_cap_info_need_time_sync,
1733
15
        { "Need Time Synchronization", "miwi_p2pstar.need_time_sync", FT_BOOLEAN, 16, NULL, MIWI_CAP_INFO_NEED_TIME_SYNC,
1734
15
            NULL, HFILL }},
1735
1736
15
        { &hf_miwi_cap_info_security_cap,
1737
15
        { "Security Capable", "miwi_p2pstar.security_capable", FT_BOOLEAN, 16, NULL, MIWI_CAP_INFO_SECURITY_CAP,
1738
15
            NULL, HFILL }},
1739
1740
15
        { &hf_miwi_cap_info_reserved,
1741
15
        { "Reserved", "miwi_p2pstar.cap_info.reserved", FT_UINT16, BASE_HEX, NULL, MIWI_CAP_INFO_RESERVED,
1742
15
            NULL, HFILL }},
1743
1744
15
        { &hf_miwi_oper_chan,
1745
15
        { "Connection Request Operating Channel", "miwi_p2pstar.con_req_chan", FT_UINT8, BASE_DEC, NULL, 0x0,
1746
15
            NULL, HFILL }},
1747
1748
15
        { &hf_miwi_conn_res_status,
1749
15
        { "Connection Response Status", "miwi_p2pstar.con_res_status", FT_UINT8, BASE_DEC, NULL, 0x0,
1750
15
            NULL, HFILL }},
1751
1752
15
        { &hf_miwi_current_op_channel,
1753
15
        { "Channel Hop Current Operating Channel", "miwi_p2pstar.hop_op_chan", FT_UINT8, BASE_DEC, NULL, 0x0,
1754
15
            NULL, HFILL }},
1755
1756
15
        { &hf_miwi_dst_channel_to_jump_to,
1757
15
        { "Destination Channel to Jump to", "miwi_p2pstar.chan_jump_to", FT_UINT8, BASE_DEC, NULL, 0x0,
1758
15
            NULL, HFILL }},
1759
1760
15
        { &hf_miwi_conn_rmv_res_status,
1761
15
        { "Connection Removal Response Status", "miwi_p2pstar.con_rmvl_res_status", FT_UINT8, BASE_DEC, NULL, 0x0,
1762
15
            NULL, HFILL }},
1763
1764
15
        { &hf_miwi_fwd_pkt_dst_addr,
1765
15
        { "Forward Packet Command Destination Address", "miwi_p2pstar.fwd_pkt_dst-addr", FT_UINT8, BASE_DEC, NULL, 0x0,
1766
15
            NULL, HFILL }},
1767
1768
15
        { &hf_miwi_conn_tbl_size,
1769
15
        { "Connection Table Size", "miwi_p2pstar.conn_tbl_size", FT_UINT8, BASE_DEC, NULL, 0x0,
1770
15
            NULL, HFILL }},
1771
15
        };
1772
1773
1774
    /* Subtrees */
1775
15
    static int *ett[] = {
1776
15
        &ett_miwi_p2pstar,
1777
15
        &ett_miwi_p2pstar_fcf,
1778
15
        &ett_miwi_p2pstar_cmd_tree,
1779
15
        &ett_miwi_p2pstar_cap_info,
1780
15
        &ett_miwi_fcs,
1781
15
    };
1782
1783
15
    static ei_register_info ei[] = {
1784
        //{ &ei_miwi_empty_payload,     { "miwi_p2pstar.empty_payload",   PI_MALFORMED,      PI_ERROR, "Empty MiWi Payload!", EXPFILL }},
1785
15
        { &ei_miwi_frame_ver,   { "miwi_p2pstar.frame_version_error", PI_COMMENTS_GROUP, PI_NOTE,  "Source address can not be broadcast address !", EXPFILL }},
1786
15
        { &ei_miwi_dst, { "miwi_p2pstar.dst_addr_error",     PI_COMMENTS_GROUP, PI_WARN,  "destination address Error", EXPFILL }},
1787
15
        { &ei_miwi_src, { "miwi_p2pstar.src_addr_error",     PI_COMMENTS_GROUP, PI_WARN,  "Source address Error", EXPFILL }},
1788
15
        { &ei_miwi_invalid_addressing, { "miwi_p2pstar.invalid_addr_error", PI_PROTOCOL,   PI_NOTE,  "Invalid Address Error", EXPFILL }},
1789
15
        { &ei_miwi_invalid_panid_compression, { "miwi_p2pstar.invalid_panid_comp_error", PI_PROTOCOL,   PI_WARN,  "Panid compression error", EXPFILL }},
1790
15
        { &ei_miwi_invalid_panid_compression2, { "miwi_p2pstar.invalid_panid_comp2_error", PI_PROTOCOL,   PI_WARN,  "Panid2 compression error", EXPFILL }},
1791
//        { &ei_miwi_fcs, { "miwi_p2pstar.fcs.bad", PI_CHECKSUM, PI_WARN, "Bad FCS", EXPFILL }},
1792
15
    };
1793
1794
15
    static const enum_val_t fcs_type_vals[] = {
1795
15
        {"16",     "CRC -16 BIT",          MIWI_P2PSTAR_FCS_16_BIT},
1796
15
        {NULL, NULL, -1}
1797
15
    };
1798
1799
15
    static build_valid_func     miwi_da_build_value[1] = {miwi_da_value};
1800
15
    static decode_as_value_t    miwi_da_values = {miwi_da_prompt, 1, miwi_da_build_value};
1801
15
    static decode_as_t         miwi_da = {
1802
15
        IEEE802154_PROTOABBREV_WPAN, IEEE802154_PROTOABBREV_WPAN_PANID,
1803
15
        1, 0, &miwi_da_values, NULL, NULL,
1804
15
        decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change,NULL,NULL,NULL
1805
15
    };
1806
1807
15
    module_t *miwi_p2pstar_module;
1808
15
    expert_module_t* expert_miwi_p2pstar;
1809
1810
    /* Register the protocol name and description */
1811
15
    proto_miwi_p2pstar = proto_register_protocol("MiWi P2P Star (v6.4)", "MiWi_P2PStar", "miwi_p2pstar");
1812
1813
    /* Required function calls to register the header fields and subtree used */
1814
15
    proto_register_field_array(proto_miwi_p2pstar, hf, array_length(hf));
1815
15
    proto_register_subtree_array(ett, array_length(ett));
1816
1817
15
    expert_miwi_p2pstar = expert_register_protocol(proto_miwi_p2pstar);
1818
15
    expert_register_field_array(expert_miwi_p2pstar, ei, array_length(ei));
1819
1820
15
    miwi_short_address_type = address_type_dissector_register("AT_IEEE_802_15_4_SHORT", "IEEE 802.15.4 16-bit short address",                    miwi_short_address_to_str, miwi_short_address_str_len, NULL, NULL, miwi_short_address_len, NULL, NULL);
1821
1822
    /* add a user preference to set the 802.15.4 ethertype */
1823
15
    miwi_p2pstar_module = prefs_register_protocol(proto_miwi_p2pstar,
1824
15
                                   proto_reg_handoff_miwi_p2pstar);
1825
15
    prefs_register_uint_preference(miwi_p2pstar_module, "miwi_ethertype",
1826
15
                                   "802.15.4 Ethertype (in hex)",
1827
15
                                   "(Hexadecimal) Ethertype used to indicate IEEE 802.15.4 frame.",
1828
15
                                   16, &miwi_ethertype);
1829
15
    prefs_register_enum_preference(miwi_p2pstar_module, "fcs_format",
1830
15
                                   "FCS format",
1831
15
                                   "The FCS format in the captured payload",
1832
15
                                   &miwi_fcs_type, fcs_type_vals, false);
1833
15
    prefs_register_bool_preference(miwi_p2pstar_module, "miwi_fcs_ok",
1834
15
                                   "Dissect only good FCS",
1835
15
                                   "Dissect payload only if FCS is valid.",
1836
15
                                   &miwi_fcs_ok);
1837
15
    prefs_register_bool_preference(miwi_p2pstar_module, "miwi_ack_tracking",
1838
15
                                   "Enable ACK tracking",
1839
15
                                   "Match frames with ACK request to ACK packets",
1840
15
                                   &miwi_ack_tracking);
1841
1842
15
    miwi_p2pstar_handle = register_dissector("miwi_p2pstar", dissect_miwi_p2pstar, proto_miwi_p2pstar);
1843
    /* Register a Decode-As handler */
1844
15
    register_decode_as(&miwi_da);
1845
15
}/* proto_register_miwi_p2pstar */
1846
1847
/*FUNCTION:------------------------------------------------------
1848
 *  NAME
1849
 *      proto_reg_handoff_miwi_p2pstar
1850
 *  DESCRIPTION
1851
 *      Registers the miwi_p2pstar dissector with Wireshark.
1852
 *      Will be called during Wireshark startup.
1853
 *  PARAMETERS
1854
 *      none
1855
 *  RETURNS
1856
 *      void
1857
 *---------------------------------------------------------------
1858
 */
1859
void proto_reg_handoff_miwi_p2pstar(void)
1860
15
{
1861
#if 0
1862
    static bool                prefs_initialized = false;
1863
    static unsigned int        old_miwi_ethertype;
1864
1865
    if(!prefs_initialized){
1866
        dissector_add_uint("wtap_encap", WTAP_ENCAP_IEEE802_15_4, miwi_p2pstar_handle);
1867
1868
        prefs_initialized = true;
1869
    } else{
1870
        dissector_delete_uint("ethertype", old_miwi_ethertype, miwi_p2pstar_handle);
1871
    }
1872
1873
    old_miwi_ethertype = miwi_ethertype;
1874
1875
    /* Register dissector handles. */
1876
    dissector_add_uint("ethertype", miwi_ethertype, miwi_p2pstar_handle);
1877
#endif
1878
    /* Register our dissector with IEEE 802.15.4 */
1879
15
    dissector_add_for_decode_as(IEEE802154_PROTOABBREV_WPAN_PANID, miwi_p2pstar_handle);
1880
15
    heur_dissector_add(IEEE802154_PROTOABBREV_WPAN, dissect_miwi_p2pstar_heur, "Miwi P2PStar over IEEE 802.15.4", "miwip2pstar", proto_miwi_p2pstar, HEURISTIC_DISABLE);
1881
15
}/* proto_reg_handoff_miwi_p2pstar */
1882
1883
/*
1884
 * Editor modelines
1885
 *
1886
 * Local Variables:
1887
 * c-basic-offset: 4
1888
 * tab-width: 8
1889
 * indent-tabs-mode: nil
1890
 * End:
1891
 *
1892
 * ex: set shiftwidth=4 tabstop=8 expandtab:
1893
 * :indentSize=4:tabSize=8:noTabs=true:
1894
 */