blob: d244fefde5acdfd2f54758a49d706fbb0f195cc4 [file] [log] [blame]
Harald Weltec4ac9e02021-04-22 23:07:44 +02001module OPCAP_Types {
2
3/* OPCAP_Types, defining abstract TTCN-3 data types for the osmo-pcap protocol.
4 *
5 * OPCAP is a non-standard protocol used between osmo-pcap-client and osmo-pcap-server.
6 *
7 * (C) 2021 by Harald Welte <laforge@gnumonks.org>
8 * All rights reserved.
9 *
10 * Released under the terms of GNU General Public License, Version 2 or
11 * (at your option) any later version.
12 */
13
14import from General_Types all;
15import from Osmocom_Types all;
16
17type enumerated OpcapMsgType {
18 PKT_LINK_HDR (0),
19 PKT_LINK_DATA (1)
20} with { variant "FIELDLENGTH(8)" };
21
22type record OPCAP_PDU {
23 OpcapMsgType msg_type,
24 uint8_t spare,
25 uint16_t len,
26 OpcapBodyUnion u
27} with {
28 variant (len) "LENGTHTO(u)"
29 variant (len) "BYTEORDER(last)"
30 variant (u) "CROSSTAG(
31 file, msg_type = PKT_LINK_HDR;
32 packet, msg_type = PKT_LINK_DATA;
33 )"
34};
35
36type union OpcapBodyUnion {
37 PcapFileHeader file,
38 OpcapPacket packet
39};
40
41/* header in front of a PKT_LINK_DATA */
42type record OpcapPacket {
43 uint32_t ts_sec,
44 uint32_t ts_usec,
45 uint32_t caplen,
46 uint32_t len,
47 octetstring payload
48} with {
49 variant (caplen) "LENGTHTO(payload)"
50};
51
52/* below definitions are from pcap/pcap.h */
53const uint16_t PCAP_VERSION_MAJOR := 2;
54const uint16_t PCAP_VERSION_MINOR := 4;
55const uint32_t PCAP_MAGIC := 2712847316; //0xA1B2C3D4;
56
57type record PcapFileHeader {
58 uint32_t magic,
59 uint16_t version_major,
60 uint16_t version_minor,
61 uint32_t thiszone,
62 uint32_t sigfigs,
63 uint32_t snaplen,
64 uint32_t linktype
65};
66
67/* below definitions are from pcap/dlt.h */
68const uint32_t DLT_LINUX_SLL := 113;
69const uint32_t DLT_EN10MB := 1;
70
71
72external function enc_OPCAP_PDU(in OPCAP_PDU msg) return octetstring
73 with { extension "prototype(convert) encode(RAW)" };
74
75external function dec_OPCAP_PDU(in octetstring msg) return OPCAP_PDU
76 with { extension "prototype(convert) decode(RAW)" };
77
78} with { encode "RAW"; variant "FIELDORDER(msb)"; variant "BYTEORDER(first)" };