Coverage Report

Created: 2026-08-03 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/ieee-c37118.c
Line
Count
Source
1
/*
2
 * ieee-c37118.c
3
 *
4
 * IEEE C37.118 Synchrophasor Protocol
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_IEEE_C37118
30
31
#include "ndpi_api.h"
32
#include "ndpi_private.h"
33
34
static void ndpi_int_ieee_c37118_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
35
                                            struct ndpi_flow_struct *flow)
36
619
{
37
619
  NDPI_LOG_INFO(ndpi_struct, "found IEEE C37.118\n");
38
619
  ndpi_set_detected_protocol(ndpi_struct, flow,
39
619
                             NDPI_PROTOCOL_IEEE_C37118, NDPI_PROTOCOL_UNKNOWN,
40
619
                             NDPI_CONFIDENCE_DPI);
41
619
}
42
43
static void ndpi_search_ieee_c37118(struct ndpi_detection_module_struct *ndpi_struct,
44
                                    struct ndpi_flow_struct *flow)
45
4.37M
{
46
4.37M
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
47
48
4.37M
  NDPI_LOG_DBG(ndpi_struct, "search IEEE C37.118\n");
49
50
  /* A little bit of heuristics. Check the minimum length, 
51
   * version (0xAA) and frame type (0 to 5) */
52
4.37M
  if ((packet->payload_packet_len >= 17) && (packet->payload[0] == 0xAA) &&
53
9.90k
      ((packet->payload[1] >> 4) < 6))
54
5.47k
  {
55
5.47k
    u_int16_t frame_size = ntohs(get_u_int16_t(packet->payload, 2));
56
5.47k
    u_int16_t crc = ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len-2));
57
58
5.47k
    if ((frame_size == packet->payload_packet_len) &&
59
1.88k
        (crc == ndpi_crc16_ccit_false(packet->payload, packet->payload_packet_len-2)))
60
619
    {
61
619
      ndpi_int_ieee_c37118_add_connection(ndpi_struct, flow);
62
619
      return;
63
619
    }
64
5.47k
  }
65
66
4.37M
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
67
4.37M
}
68
69
void init_ieee_c37118_dissector(struct ndpi_detection_module_struct *ndpi_struct)
70
17.6k
{
71
17.6k
  ndpi_register_dissector("IEEE-C37118", ndpi_struct,
72
17.6k
                     ndpi_search_ieee_c37118,
73
17.6k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
74
17.6k
                     1, NDPI_PROTOCOL_IEEE_C37118);
75
17.6k
}