forked from P1sec/QCSuper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsmtap.py
141 lines (127 loc) · 4.31 KB
/
gsmtap.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python3
from struct import pack, unpack
# GSMTAP definition:
# - https://github.com/wireshark/wireshark/blob/wireshark-2.5.0/epan/dissectors/packet-gsmtap.h
# - https://github.com/wireshark/wireshark/blob/wireshark-2.5.0/epan/dissectors/packet-gsmtap.c#L82
# - http://osmocom.org/projects/baseband/wiki/GSMTAP
def build_gsmtap_ip(gsmtap_protocol, gsmtap_channel_type, payload, is_uplink):
packet = pack('>BBBxHxx4xBxxx',
2, # GSMTAP version
4, # Header words
gsmtap_protocol,
int(is_uplink) << 14,
gsmtap_channel_type
) + payload
# UDP:
packet = pack('>HHHH',
4729, # From GSMTAP UDP port
4729, # To GSMTAP UDP port
len(packet) + 8, # Total length
0 # Ignore checksum
) + packet
# IP:
return pack('>BBHHHBBH8B',
(4 << 4) | 5, # IPv4 version and header words
0, # DSCP
len(packet) + 20, # Total length
0, # Identification
0, # Fragment offset
64, # Time to live
17, # Protocol: UDP
0, # Ignore checksum
0,0,0,0, # From 0.0.0.0
0,0,0,0, # To 0.0.0.0
) + packet
GSMTAP_TYPE_UM = 0x01
GSMTAP_TYPE_ABIS = 0x02
GSMTAP_TYPE_UMTS_RRC = 0x0c
GSMTAP_TYPE_LTE_RRC = 0x0d
GSMTAP_TYPE_LTE_NAS = 0x12
GSMTAP_CHANNEL_UNKNOWN = 0x00
GSMTAP_CHANNEL_BCCH = 0x01
GSMTAP_CHANNEL_CCCH = 0x02
GSMTAP_CHANNEL_RACH = 0x03
GSMTAP_CHANNEL_AGCH = 0x04
GSMTAP_CHANNEL_PCH = 0x05
GSMTAP_CHANNEL_SDCCH = 0x06
GSMTAP_CHANNEL_SDCCH4 = 0x07
GSMTAP_CHANNEL_SDCCH8 = 0x08
GSMTAP_CHANNEL_TCH_F = 0x09
GSMTAP_CHANNEL_TCH_H = 0x0a
GSMTAP_CHANNEL_PACCH = 0x0b
GSMTAP_CHANNEL_CBCH52 = 0x0c
GSMTAP_CHANNEL_PDTCH = 0x0d
GSMTAP_CHANNEL_PTCCH = 0x0e
GSMTAP_CHANNEL_CBCH51 = 0x0f
GSMTAP_CHANNEL_ACCH = 0x80 # To be combined, ACCH + SDCCH = SACCH
GSMTAP_RRC_SUB_DL_DCCH_Message = 0
GSMTAP_RRC_SUB_UL_DCCH_Message = 1
GSMTAP_RRC_SUB_DL_CCCH_Message = 2
GSMTAP_RRC_SUB_UL_CCCH_Message = 3
GSMTAP_RRC_SUB_PCCH_Message = 4
GSMTAP_RRC_SUB_DL_SHCCH_Message = 5
GSMTAP_RRC_SUB_UL_SHCCH_Message = 6
GSMTAP_RRC_SUB_BCCH_FACH_Message = 7
GSMTAP_RRC_SUB_BCCH_BCH_Message = 8
GSMTAP_RRC_SUB_MCCH_Message = 9
GSMTAP_RRC_SUB_MSCH_Message = 10
GSMTAP_RRC_SUB_HandoverToUTRANCommand = 11
GSMTAP_RRC_SUB_InterRATHandoverInfo = 12
GSMTAP_RRC_SUB_SystemInformation_BCH = 13
GSMTAP_RRC_SUB_System_Information_Container = 14
GSMTAP_RRC_SUB_UE_RadioAccessCapabilityInfo = 15
GSMTAP_RRC_SUB_MasterInformationBlock = 16
GSMTAP_RRC_SUB_SysInfoType1 = 17
GSMTAP_RRC_SUB_SysInfoType2 = 18
GSMTAP_RRC_SUB_SysInfoType3 = 19
GSMTAP_RRC_SUB_SysInfoType4 = 20
GSMTAP_RRC_SUB_SysInfoType5 = 21
GSMTAP_RRC_SUB_SysInfoType5bis = 22
GSMTAP_RRC_SUB_SysInfoType6 = 23
GSMTAP_RRC_SUB_SysInfoType7 = 24
GSMTAP_RRC_SUB_SysInfoType8 = 25
GSMTAP_RRC_SUB_SysInfoType9 = 26
GSMTAP_RRC_SUB_SysInfoType10 = 27
GSMTAP_RRC_SUB_SysInfoType11 = 28
GSMTAP_RRC_SUB_SysInfoType11bis = 29
GSMTAP_RRC_SUB_SysInfoType12 = 30
GSMTAP_RRC_SUB_SysInfoType13 = 31
GSMTAP_RRC_SUB_SysInfoType13_1 = 32
GSMTAP_RRC_SUB_SysInfoType13_2 = 33
GSMTAP_RRC_SUB_SysInfoType13_3 = 34
GSMTAP_RRC_SUB_SysInfoType13_4 = 35
GSMTAP_RRC_SUB_SysInfoType14 = 36
GSMTAP_RRC_SUB_SysInfoType15 = 37
GSMTAP_RRC_SUB_SysInfoType15bis = 38
GSMTAP_RRC_SUB_SysInfoType15_1 = 39
GSMTAP_RRC_SUB_SysInfoType15_1bis = 40
GSMTAP_RRC_SUB_SysInfoType15_2 = 41
GSMTAP_RRC_SUB_SysInfoType15_2bis = 42
GSMTAP_RRC_SUB_SysInfoType15_2ter = 43
GSMTAP_RRC_SUB_SysInfoType15_3 = 44
GSMTAP_RRC_SUB_SysInfoType15_3bis = 45
GSMTAP_RRC_SUB_SysInfoType15_4 = 46
GSMTAP_RRC_SUB_SysInfoType15_5 = 47
GSMTAP_RRC_SUB_SysInfoType15_6 = 48
GSMTAP_RRC_SUB_SysInfoType15_7 = 49
GSMTAP_RRC_SUB_SysInfoType15_8 = 50
GSMTAP_RRC_SUB_SysInfoType16 = 51
GSMTAP_RRC_SUB_SysInfoType17 = 52
GSMTAP_RRC_SUB_SysInfoType18 = 53
GSMTAP_RRC_SUB_SysInfoType19 = 54
GSMTAP_RRC_SUB_SysInfoType20 = 55
GSMTAP_RRC_SUB_SysInfoType21 = 56
GSMTAP_RRC_SUB_SysInfoType22 = 57
GSMTAP_RRC_SUB_SysInfoTypeSB1 = 58
GSMTAP_RRC_SUB_SysInfoTypeSB2 = 59
GSMTAP_RRC_SUB_ToTargetRNC_Container = 60
GSMTAP_RRC_SUB_TargetRNC_ToSourceRNC_Container = 61
GSMTAP_LTE_RRC_SUB_DL_CCCH_Message = 0
GSMTAP_LTE_RRC_SUB_DL_DCCH_Message = 1
GSMTAP_LTE_RRC_SUB_UL_CCCH_Message = 2
GSMTAP_LTE_RRC_SUB_UL_DCCH_Message = 3
GSMTAP_LTE_RRC_SUB_BCCH_BCH_Message = 4
GSMTAP_LTE_RRC_SUB_BCCH_DL_SCH_Message = 5
GSMTAP_LTE_RRC_SUB_PCCH_Message = 6
GSMTAP_LTE_RRC_SUB_MCCH_Message = 7
GSMTAP_LTE_NAS_PLAIN = 0