Coverage Report

Created: 2026-04-04 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/iec62056.c
Line
Count
Source
1
/*
2
 * iec62056.c
3
 *
4
 * IEC 62056-4-7 DLMS/COSEM transport layer for IP networks
5
 * 
6
 * Copyright (C) 2023 - ntop.org
7
 * Copyright (C) 2023 - V.G <v.gavrilov@securitycode.ru>
8
 *
9
 * This file is part of nDPI, an open source deep packet inspection
10
 * library based on the OpenDPI and PACE technology by ipoque GmbH
11
 *
12
 * nDPI is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Lesser General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * nDPI is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Lesser General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Lesser General Public License
23
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
24
 * 
25
 */
26
27
#include "ndpi_protocol_ids.h"
28
29
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IEC62056
30
31
#include "ndpi_api.h"
32
#include "ndpi_private.h"
33
34
static void ndpi_int_iec62056_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
35
                                             struct ndpi_flow_struct *flow)
36
0
{
37
0
  NDPI_LOG_INFO(ndpi_struct, "found IEC62056\n");
38
0
  ndpi_set_detected_protocol(ndpi_struct, flow,
39
0
                             NDPI_PROTOCOL_IEC62056, NDPI_PROTOCOL_UNKNOWN,
40
0
                             NDPI_CONFIDENCE_DPI);
41
0
}
42
43
static void ndpi_search_iec62056(struct ndpi_detection_module_struct *ndpi_struct,
44
                                 struct ndpi_flow_struct *flow)
45
0
{
46
0
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
47
48
0
  NDPI_LOG_DBG(ndpi_struct, "search IEC62056\n");
49
50
0
  if (packet->payload_packet_len > 8 && /* Smallest suitable packet (SNRM request) is 9 bytes long */
51
0
      packet->payload[0] == 0x7E && packet->payload[1] == 0xA0 && /* HDLC frame start */
52
0
      packet->payload[packet->payload_packet_len-1] == 0x7E) /* HDLC frame end */
53
0
  {
54
0
    u_int16_t fcs = le16toh(ndpi_crc16_x25(&packet->payload[1], packet->payload_packet_len-4));
55
0
    if (fcs == get_u_int16_t(packet->payload, packet->payload_packet_len-3)) {
56
0
      ndpi_int_iec62056_add_connection(ndpi_struct,  flow);
57
0
      return;
58
0
    }
59
0
  }
60
61
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
62
0
}
63
64
void init_iec62056_dissector(struct ndpi_detection_module_struct *ndpi_struct)
65
0
{
66
0
  ndpi_register_dissector("IEC62056", ndpi_struct,
67
0
                     ndpi_search_iec62056,
68
0
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
69
0
                     1, NDPI_PROTOCOL_IEC62056);
70
0
}