summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-shicp.c
blob: 43e9a5ae619b5fa74bb31245d26a0171b8947835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
/* packet-shicp.c
 * Routines for Secure Host IP Configuration Protocol dissection
 * Copyright 2021, Filip Kågesson <exfik@hms.se>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <config.h>

#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/addr_resolv.h>
#include "packet-udp.h"

void proto_reg_handoff_shicp(void);
void proto_register_shicp(void);

/* Protocols and header fields */
static int proto_shicp = -1;
static int hf_shicp_header = -1;
static int hf_shicp_protocol_version = -1;
static int hf_shicp_dst = -1;
static int hf_shicp_src = -1;
static int hf_shicp_flags = -1;
static int hf_shicp_msgclass_flag = -1;
static int hf_shicp_error_flag = -1;
static int hf_shicp_reserved_flag = -1;
static int hf_shicp_msgtype = -1;
static int hf_shicp_error = -1;
static int hf_shicp_error_string = -1;
static int hf_shicp_auth_req = -1;
static int hf_shicp_module_version = -1;
static int hf_shicp_module_desc = -1;
static int hf_shicp_supported_msg = -1;
static int hf_shicp_ip = -1;
static int hf_shicp_sn = -1;
static int hf_shicp_gw = -1;
static int hf_shicp_dns1 = -1;
static int hf_shicp_dns2 = -1;
static int hf_shicp_dhcp = -1;
static int hf_shicp_hn = -1;
static int hf_shicp_hn_max_len = -1;
static int hf_shicp_pswd_max_len = -1;
static int hf_shicp_challenge = -1;
static int hf_shicp_validity_period = -1;
static int hf_shicp_token = -1;
static int hf_shicp_pswd = -1;
static int hf_shicp_wink_type = -1;
static int hf_shicp_restart_mode = -1;

static gint ett_shicp = -1;
static gint ett_shicp_flags = -1;

static expert_field ei_shicp_error = EI_INIT;
static expert_field ei_shicp_malformed = EI_INIT;

#define SHICP_UDP_PORT 3250

#define SHICP_MIN_LENGTH 2
#define SHICP_MAX_LENGTH 548
#define SHICP_HEADER_SIZE 2
#define SHICP_ADDRESS_SIZE 6
#define SHICP_FLAGS_SIZE 1
#define SHICP_MSG_TYPE_SIZE 1
#define SHICP_ERROR_SIZE 1
#define SHICP_CHALLENGE_SIZE 4
#define SHICP_VALIDITY_PERIOD_SIZE 1
#define SHICP_TOKEN_SIZE 36
#define SHICP_WINK_TYPE_SIZE 1
#define SHICP_RESTART_MODE_SIZE 1
#define SHICP_FIXED_LEN 18
#define SHICP_MSG_CLASS_FLAG 0x01
#define SHICP_ERROR_FLAG 0x02
#define SHICP_RESERVED_FLAG 0xFC

/* Values of the supported message types. */
#define SHICP_DISCOVER_MSG_TYPE 0x00
#define SHICP_AUTH_CHALLENGE_MSG_TYPE 0x01
#define SHICP_CONFIG_MSG_TYPE 0x02
#define SHICP_WINK_MSG_TYPE 0x03
#define SHICP_RESTART_MSG_TYPE 0x04
#define SHICP_MASS_RESTART_MSG_TYPE 0x05

/* Keys of the parameters associated with discover messages. */
#define SHICP_DISCOVER_AUTH_REQ_KEY 0x00
#define SHICP_DISCOVER_MODULE_VERSION_KEY 0x01
#define SHICP_DISCOVER_MODULE_DESC_KEY 0x02
#define SHICP_DISCOVER_SUPPORTED_MSG_KEY 0x03
#define SHICP_DISCOVER_IP_KEY 0x04
#define SHICP_DISCOVER_SN_KEY 0x05
#define SHICP_DISCOVER_GW_KEY 0x06
#define SHICP_DISCOVER_DNS1_KEY 0x07
#define SHICP_DISCOVER_DNS2_KEY 0x08
#define SHICP_DISCOVER_DHCP_KEY 0x09
#define SHICP_DISCOVER_HN_KEY 0x0A
#define SHICP_DISCOVER_HN_MAX_LEN_KEY 0x0B
#define SHICP_DISCOVER_PSWD_MAX_LEN_KEY 0x0C

/* Keys of the parameters associated with configuration messages. */
#define SHICP_CONFIG_IP_KEY 0x00
#define SHICP_CONFIG_SN_KEY 0x01
#define SHICP_CONFIG_GW_KEY 0x02
#define SHICP_CONFIG_DNS1_KEY 0x03
#define SHICP_CONFIG_DNS2_KEY 0x04
#define SHICP_CONFIG_DHCP_KEY 0x05
#define SHICP_CONFIG_HN_KEY 0x06
#define SHICP_CONFIG_PSWD_KEY 0x07

/* The types of messages supported. */
static const value_string message_types[] = {
    {SHICP_DISCOVER_MSG_TYPE, "Discover"},
    {SHICP_AUTH_CHALLENGE_MSG_TYPE, "Authentication challenge"},
    {SHICP_CONFIG_MSG_TYPE, "Configuration"},
    {SHICP_WINK_MSG_TYPE, "Wink"},
    {SHICP_RESTART_MSG_TYPE, "Restart"},
    {SHICP_MASS_RESTART_MSG_TYPE, "Mass-restart"},
    {0, NULL}
};
/* The error codes that are supported. */
static const value_string error_types[] = {
    {0x00, "Request was rejected"},
    {0x01, "Authentication failed"},
    {0x02, "Authentication required"},
    {0x03, "Unsupported message type"},
    {0x1F, "Hostname too long"},
    {0x20, "Password too long"},
    {0x21, "Bad config"},
    {0, NULL}
};
/* The types of restart mode that are supported. */
static const value_string restart_mode_types[] = {
    {0x00, "Immediate restart"},
    {0x01, "Delayed restart"},
    {0, NULL}
};

static gboolean
test_shicp(packet_info* pinfo, tvbuff_t* tvb, int offset, void* data _U_)
{
    /* Check that the port matches the port used by SHICP. */
    if (pinfo->destport != SHICP_UDP_PORT) {
        return FALSE;
    }

    /* Check that the length of the message is within allowed boundaries. */
    if (tvb_reported_length(tvb) < SHICP_MIN_LENGTH || tvb_reported_length(tvb) > SHICP_MAX_LENGTH) {
        return FALSE;
    }

    /* Check that the header tag starts with 0xABC0. */
    if ((tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN) & 0xFFF8) != 0xABC0) {
        return FALSE;
    }

    return TRUE;
}

static int
dissect_shicp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        void *data _U_)
{
    proto_item* ti;
    proto_item* flags_pi;
    proto_item* error_pi;
    proto_tree* shicp_tree;
    guint offset = 0;
    guint payload_end;
    guint keyvalue_key = 0;
    guint keyvalue_length = 0;
    guint keyvalue_offset = 0;
    guint keyvalue_end = 0;
    guint8 supported_message_value = 0;
    guint16 payload_length = 0;
    guint32 version = 0;
    guint32 msgtype_value = 0;
    guint32 error_value = 0;
    guint64 flags_value = 0;

    wmem_strbuf_t* supported_messages = wmem_strbuf_new(pinfo->pool, "");
    wmem_strbuf_t* module_addr_strbuf = wmem_strbuf_new(pinfo->pool, "");

    static int* flags[] = {
        &hf_shicp_reserved_flag,
        &hf_shicp_error_flag,
        &hf_shicp_msgclass_flag,
        NULL
    };

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "SHICP");
    col_clear(pinfo->cinfo, COL_INFO);

    ti = proto_tree_add_item(tree, proto_shicp, tvb, offset, -1, ENC_NA);

    shicp_tree = proto_item_add_subtree(ti, ett_shicp);
    proto_item_append_text(ti,
        ", Src:%s, Dst:%s",
        address_with_resolution_to_str(pinfo->pool, &pinfo->dl_src),
        address_with_resolution_to_str(pinfo->pool, &pinfo->dl_dst));
    proto_tree_add_item_ret_uint(shicp_tree, hf_shicp_header, tvb, offset, SHICP_HEADER_SIZE, ENC_LITTLE_ENDIAN, &version);
    proto_tree_add_uint(shicp_tree, hf_shicp_protocol_version, tvb, offset, SHICP_HEADER_SIZE, version & 0x07);
    offset += SHICP_HEADER_SIZE;
    proto_tree_add_item(shicp_tree, hf_shicp_dst, tvb, offset, SHICP_ADDRESS_SIZE, ENC_NA);
    gchar* dst = tvb_address_to_str(pinfo->pool, tvb, AT_ETHER, offset);
    offset += SHICP_ADDRESS_SIZE;
    proto_tree_add_item(shicp_tree, hf_shicp_src, tvb, offset, SHICP_ADDRESS_SIZE, ENC_NA);
    gchar* src = tvb_address_to_str(pinfo->pool, tvb, AT_ETHER, offset);
    offset += SHICP_ADDRESS_SIZE;
    flags_pi = proto_tree_add_bitmask_ret_uint64(shicp_tree, tvb, offset, hf_shicp_flags, ett_shicp_flags, flags, ENC_LITTLE_ENDIAN, &flags_value);
    offset += SHICP_FLAGS_SIZE;
    proto_tree_add_item_ret_uint(shicp_tree, hf_shicp_msgtype, tvb, offset, SHICP_MSG_TYPE_SIZE, ENC_LITTLE_ENDIAN, &msgtype_value);
    offset += SHICP_MSG_TYPE_SIZE;
    payload_length = tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN);
    offset += 1;
    if (flags_value & SHICP_ERROR_FLAG) {
        proto_item_set_text(flags_pi,
            "Message flags: 0x%02x (%s, %s)",
            (guint)flags_value,
            tfs_get_string(flags_value & SHICP_MSG_CLASS_FLAG, &tfs_response_request), "Error");
        if (payload_length != 1) {
            error_pi = proto_tree_add_string(shicp_tree, hf_shicp_error_string, tvb, offset, 0, "Malformed message");
            expert_add_info(pinfo, error_pi, &ei_shicp_malformed);
            col_append_str(pinfo->cinfo, COL_INFO, "Error: Malformed message");
        }
        else {
            error_pi = proto_tree_add_item_ret_uint(shicp_tree, hf_shicp_error, tvb, offset, SHICP_ERROR_SIZE, ENC_LITTLE_ENDIAN, &error_value);
            expert_add_info(pinfo, error_pi, &ei_shicp_error);
            col_append_fstr(pinfo->cinfo, COL_INFO, "Error: %s", val_to_str(error_value, error_types, "%d"));
        }
    }
    else {
        proto_item_set_text(flags_pi,
            "Message flags: 0x%02x (%s)",
            (guint)flags_value,
            tfs_get_string(flags_value & SHICP_MSG_CLASS_FLAG, &tfs_response_request));
        col_append_fstr(pinfo->cinfo,
            COL_INFO,
            "%s, Type: %s",
            tfs_get_string(flags_value & SHICP_MSG_CLASS_FLAG, &tfs_response_request),
            val_to_str(msgtype_value, message_types, "%d"));
        payload_end = offset + payload_length;
        switch (msgtype_value)
        {
        case SHICP_DISCOVER_MSG_TYPE:
            while (offset < payload_end) {
                keyvalue_key = tvb_get_guint8(tvb, offset);
                offset += 1;
                keyvalue_length = tvb_get_guint8(tvb, offset);
                offset += 1;
                switch (keyvalue_key)
                {
                case SHICP_DISCOVER_AUTH_REQ_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_auth_req, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_MODULE_VERSION_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_module_version, tvb, offset, keyvalue_length, ENC_ASCII | ENC_NA);
                    break;
                case SHICP_DISCOVER_MODULE_DESC_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_module_desc, tvb, offset, keyvalue_length, ENC_ASCII | ENC_NA);
                    break;
                case SHICP_DISCOVER_SUPPORTED_MSG_KEY:
                    keyvalue_end = offset + keyvalue_length;
                    keyvalue_offset = offset;
                    supported_message_value = tvb_get_guint8(tvb, keyvalue_offset);
                    wmem_strbuf_append(supported_messages, val_to_str(supported_message_value, message_types, "%d"));
                    keyvalue_offset += 1;
                    while (keyvalue_offset < keyvalue_end) {
                        supported_message_value = tvb_get_guint8(tvb, keyvalue_offset);
                        wmem_strbuf_append_printf(supported_messages, ", %s", val_to_str(supported_message_value, message_types, "%d"));
                        keyvalue_offset += 1;
                    }
                    proto_tree_add_string(shicp_tree, hf_shicp_supported_msg, tvb, offset, keyvalue_length, wmem_strbuf_get_str(supported_messages));
                    break;
                case SHICP_DISCOVER_IP_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_ip, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_SN_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_sn, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_GW_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_gw, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_DNS1_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_dns1, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_DNS2_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_dns2, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_DHCP_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_dhcp, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_HN_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_hn, tvb, offset, keyvalue_length, ENC_ASCII | ENC_NA);
                    break;
                case SHICP_DISCOVER_HN_MAX_LEN_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_hn_max_len, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_DISCOVER_PSWD_MAX_LEN_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_pswd_max_len, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                default:
                    break;
                }
                offset += keyvalue_length;
            }
            break;
        case SHICP_AUTH_CHALLENGE_MSG_TYPE:
            if (payload_length >= 5) {
                proto_tree_add_item(shicp_tree, hf_shicp_challenge, tvb, offset, SHICP_CHALLENGE_SIZE, ENC_LITTLE_ENDIAN);
                offset += SHICP_CHALLENGE_SIZE;
                proto_tree_add_item(shicp_tree, hf_shicp_validity_period, tvb, offset, SHICP_VALIDITY_PERIOD_SIZE, ENC_LITTLE_ENDIAN);
            }
            break;
        case SHICP_CONFIG_MSG_TYPE:
            if (payload_length >= SHICP_TOKEN_SIZE) {
                proto_tree_add_item(shicp_tree, hf_shicp_token, tvb, offset, SHICP_TOKEN_SIZE, ENC_NA);
                offset += SHICP_TOKEN_SIZE;
            }
            else if (payload_length == SHICP_ERROR_SIZE) {
                proto_tree_add_item(shicp_tree, hf_shicp_error, tvb, offset, SHICP_ERROR_SIZE, ENC_ASCII | ENC_NA);
                break;
            }
            while (offset < payload_end) {
                keyvalue_key = tvb_get_guint8(tvb, offset);
                offset += 1;
                keyvalue_length = tvb_get_guint8(tvb, offset);
                offset += 1;
                switch (keyvalue_key)
                {
                case SHICP_CONFIG_IP_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_ip, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_CONFIG_SN_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_sn, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_CONFIG_GW_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_gw, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_CONFIG_DNS1_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_dns1, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_CONFIG_DNS2_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_dns2, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_CONFIG_DHCP_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_dhcp, tvb, offset, keyvalue_length, ENC_LITTLE_ENDIAN);
                    break;
                case SHICP_CONFIG_HN_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_hn, tvb, offset, keyvalue_length, ENC_ASCII | ENC_NA);
                    break;
                case SHICP_CONFIG_PSWD_KEY:
                    proto_tree_add_item(shicp_tree, hf_shicp_pswd, tvb, offset, keyvalue_length, ENC_ASCII | ENC_NA);
                    break;
                default:
                    break;
                }
                offset += keyvalue_length;
            }
            break;
        case SHICP_WINK_MSG_TYPE:
            if (payload_length >= SHICP_TOKEN_SIZE + SHICP_WINK_TYPE_SIZE) {
                proto_tree_add_item(shicp_tree, hf_shicp_token, tvb, offset, SHICP_TOKEN_SIZE, ENC_NA);
                offset += SHICP_TOKEN_SIZE;
                proto_tree_add_item(shicp_tree, hf_shicp_wink_type, tvb, offset, SHICP_WINK_TYPE_SIZE, ENC_LITTLE_ENDIAN);
            }
            break;
        case SHICP_RESTART_MSG_TYPE:
            if (payload_length >= SHICP_TOKEN_SIZE + SHICP_RESTART_MODE_SIZE) {
                proto_tree_add_item(shicp_tree, hf_shicp_token, tvb, offset, SHICP_TOKEN_SIZE, ENC_NA);
                offset += SHICP_TOKEN_SIZE;
                proto_tree_add_item(shicp_tree, hf_shicp_restart_mode, tvb, offset, SHICP_RESTART_MODE_SIZE, ENC_LITTLE_ENDIAN);
            }
            break;
        default:
            break;
        }
    }

    wmem_strbuf_append(module_addr_strbuf, (flags_value & SHICP_MSG_CLASS_FLAG) ? src : dst);
    if (strcmp(wmem_strbuf_get_str(module_addr_strbuf), "ff:ff:ff:ff:ff:ff") != 0) {
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Module MAC address: %s", wmem_strbuf_get_str(module_addr_strbuf));
    }

    return tvb_captured_length(tvb);
}

static guint
get_shicp_len(packet_info* pinfo _U_, tvbuff_t* tvb, int offset _U_, void* data _U_)
{
    return (guint)tvb_reported_length(tvb);
}

static gboolean
dissect_shicp_heur_udp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data)
{
        return (udp_dissect_pdus(tvb, pinfo, tree, SHICP_FIXED_LEN, test_shicp,
            get_shicp_len, dissect_shicp, data) != 0);
}

void
proto_register_shicp(void)
{
    expert_module_t* expert_shicp;

    static hf_register_info hf[] = {
        { &hf_shicp_header,
          { "Header", "shicp.header",
            FT_UINT16, BASE_HEX,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_protocol_version,
          { "Protocol version", "shicp.protocolversion",
            FT_UINT8, BASE_DEC,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_dst,
          { "Destination", "shicp.dst",
            FT_ETHER, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_src,
          { "Source", "shicp.src",
            FT_ETHER, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_flags,
          { "Message flags", "shicp.flags",
            FT_UINT8, BASE_HEX,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_reserved_flag,
          { "Reserved", "shicp.flags.reserved",
            FT_BOOLEAN, 8,
            TFS(&tfs_set_notset), 0xFC,
            NULL, HFILL }
        },
        { &hf_shicp_error_flag,
          { "Error", "shicp.flags.error",
            FT_BOOLEAN, 8,
            TFS(&tfs_set_notset), 0x02,
            NULL, HFILL }
        },
        { &hf_shicp_msgclass_flag,
          { "Class", "shicp.flags.msgclass",
            FT_BOOLEAN, 8,
            TFS(&tfs_response_request), 0x01,
            NULL, HFILL }
        },
        { &hf_shicp_msgtype,
          { "Message type", "shicp.msgtype",
            FT_UINT8, BASE_HEX,
            VALS(message_types), 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_error,
          { "Error", "shicp.error",
            FT_UINT8, BASE_HEX,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_error_string,
          { "Error", "shicp.error.string",
            FT_STRINGZ, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_auth_req,
          { "Authentication required", "shicp.authreq",
            FT_BOOLEAN, 8,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_module_version,
          { "Module version", "shicp.moduleversion",
            FT_STRINGZ, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_module_desc,
          { "Module description", "shicp.moduledesc",
            FT_STRINGZ, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_supported_msg,
          { "Supported messages", "shicp.supportedmsg",
            FT_STRINGZ, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_ip,
          { "IP address", "shicp.ip",
            FT_IPv4, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_sn,
          { "Subnet mask", "shicp.sn",
            FT_IPv4, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_gw,
          { "Gateway address", "shicp.gw",
            FT_IPv4, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_dns1,
          { "Primary DNS address", "shicp.dns1",
            FT_IPv4, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_dns2,
          { "Secondary DNS address", "shicp.dns2",
            FT_IPv4, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_dhcp,
          { "DHCP", "shicp.dhcp",
            FT_BOOLEAN, 8,
            TFS(&tfs_enabled_disabled), 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_hn,
          { "Hostname", "shicp.hn",
            FT_STRINGZ, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_hn_max_len,
          { "Hostname max length", "shicp.hnmaxlen",
            FT_UINT8, BASE_DEC,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_pswd_max_len,
          { "Password max length", "shicp.pswdmaxlen",
            FT_UINT8, BASE_DEC,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_challenge,
          { "Challenge", "shicp.challenge",
            FT_UINT32, BASE_HEX,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_validity_period,
          { "Validity period (seconds)", "shicp.validityperiod",
            FT_UINT8, BASE_DEC,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_token,
          { "Authentication token", "shicp.token",
            FT_BYTES, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_pswd,
          { "Password", "shicp.pswd",
            FT_STRINGZ, BASE_NONE,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_wink_type,
          { "Wink type", "shicp.winktype",
            FT_UINT8, BASE_HEX,
            NULL, 0x0,
            NULL, HFILL }
        },
        { &hf_shicp_restart_mode,
          { "Restart mode", "shicp.restartmode",
            FT_UINT8, BASE_HEX,
            VALS(restart_mode_types), 0x0,
            NULL, HFILL }
        }
    };

    static gint *ett[] = {
        &ett_shicp,
        &ett_shicp_flags
    };

    /* Setup protocol expert items */
    static ei_register_info ei[] = {
        { &ei_shicp_error,
          { "shicp.expert.error", PI_RESPONSE_CODE, PI_NOTE,
            "Message contains an error code", EXPFILL }
        },
        { &ei_shicp_malformed,
          { "shicp.malformed", PI_MALFORMED, PI_WARN,
            "Malformed message", EXPFILL }
        }
    };

    proto_shicp = proto_register_protocol("Secure Host IP Configuration Protocol", "SHICP", "shicp");

    proto_register_field_array(proto_shicp, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    expert_shicp = expert_register_protocol(proto_shicp);
    expert_register_field_array(expert_shicp, ei, array_length(ei));
}

void
proto_reg_handoff_shicp(void)
{
    heur_dissector_add("udp", dissect_shicp_heur_udp, "SHICP over UDP", "shicp_udp", proto_shicp, HEURISTIC_ENABLE);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */