1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License Version 2 as 4 * published by the Free Software Foundation. You may not use, modify or 5 * distribute this program under any other version of the GNU General 6 * Public License. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 * 17 * Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved. 18 * 19 * Authors: Jeffrey Gu <jgu@cisco.com>, Pradeep Damodharan <prdamodh@cisco.com> 20 * 21 * Dynamic preprocessor for the S7commplus protocol 22 * 23 */ 24 25 #ifndef SPP_S7COMM_H 26 #define SPP_S7COMM_H 27 28 #include "sf_types.h" 29 #include "sfPolicy.h" 30 #include "sfPolicyUserData.h" 31 32 #define MAX_PORTS 65536 33 34 /* Default S7commplus port */ 35 #define S7COMMPLUS_PORT 102 36 37 /* Convert port value into an index for the s7comm_config->ports array */ 38 #define PORT_INDEX(port) port/8 39 40 /* Convert port value into a value for bitwise operations */ 41 #define CONV_PORT(port) 1<<(port%8) 42 43 /* S7commplus preprocessor configuration */ 44 typedef struct _s7commplus_config 45 { 46 uint8_t ports[MAX_PORTS/8]; 47 48 int ref_count; 49 } s7commplus_config_t; 50 51 /* S7commplus session data */ 52 typedef struct _s7commplus_session_data 53 { 54 uint8_t s7commplus_proto_id; 55 uint8_t s7commplus_proto_version; 56 uint16_t s7commplus_data_len; 57 uint8_t s7commplus_opcode; 58 uint16_t s7commplus_function, s7commplus_reserved_1, s7commplus_reserved_2; 59 60 tSfPolicyId policy_id; 61 tSfPolicyUserContextId context_id; 62 } s7commplus_session_data_t; 63 64 #define S7COMMPLUS_PORTS_KEYWORD "ports" 65 #define S7COMMPLUS_MEMCAP_KEYWORD "memcap" 66 67 #define TPKT_MIN_HDR_LEN 7 /* length field in TPKT header for S7commplus */ 68 #define TPKT_MIN_DATA_HDR_LEN 11 /* length field in TPKT header for S7commplus */ 69 #define INTEGRITY_PART_LEN 33 /* length of Integrity part in V3 Header packets */ 70 #define S7COMMPLUS_MIN_HDR_LEN 4 71 72 #define S7COMMPLUS_PROTOCOL_ID 0x72 73 74 #endif /* SPP_S7COMM_H */ 75