aboutsummaryrefslogtreecommitdiffstats
path: root/library/OPCAP_Types.ttcn
blob: d244fefde5acdfd2f54758a49d706fbb0f195cc4 (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
module OPCAP_Types {

/* OPCAP_Types, defining abstract TTCN-3 data types for the osmo-pcap protocol.
 *
 * OPCAP is a non-standard protocol used between osmo-pcap-client and osmo-pcap-server.
 *
 * (C) 2021 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 */

import from General_Types all;
import from Osmocom_Types all;

type enumerated OpcapMsgType {
	PKT_LINK_HDR	(0),
	PKT_LINK_DATA	(1)
} with { variant "FIELDLENGTH(8)" };

type record OPCAP_PDU {
	OpcapMsgType msg_type,
	uint8_t spare,
	uint16_t len,
	OpcapBodyUnion u
} with {
	variant (len) "LENGTHTO(u)"
	variant (len) "BYTEORDER(last)"
	variant (u) "CROSSTAG(
		file,	msg_type = PKT_LINK_HDR;
		packet,	msg_type = PKT_LINK_DATA;
			)"
};

type union OpcapBodyUnion {
	PcapFileHeader file,
	OpcapPacket packet
};

/* header in front of a PKT_LINK_DATA */
type record OpcapPacket {
	uint32_t ts_sec,
	uint32_t ts_usec,
	uint32_t caplen,
	uint32_t len,
	octetstring payload
} with {
	variant (caplen) "LENGTHTO(payload)"
};

/* below definitions are from pcap/pcap.h */
const uint16_t PCAP_VERSION_MAJOR := 2;
const uint16_t PCAP_VERSION_MINOR := 4;
const uint32_t PCAP_MAGIC := 2712847316; //0xA1B2C3D4;

type record PcapFileHeader {
	uint32_t magic,
	uint16_t version_major,
	uint16_t version_minor,
	uint32_t thiszone,
	uint32_t sigfigs,
	uint32_t snaplen,
	uint32_t linktype
};

/* below definitions are from pcap/dlt.h */
const uint32_t DLT_LINUX_SLL := 113;
const uint32_t DLT_EN10MB := 1;


external function enc_OPCAP_PDU(in OPCAP_PDU msg) return octetstring
	with { extension "prototype(convert) encode(RAW)" };

external function dec_OPCAP_PDU(in octetstring msg) return OPCAP_PDU
	with { extension "prototype(convert) decode(RAW)" };

} with { encode "RAW"; variant "FIELDORDER(msb)"; variant "BYTEORDER(first)" };