capsight 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
capsight/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """capsight: plain-English diagnosis of mobile-core packet captures."""
2
+
3
+ __version__ = "0.2.0"
capsight/cli.py ADDED
@@ -0,0 +1,171 @@
1
+ """capsight: plain-English diagnosis of mobile-core packet captures."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import sys
8
+ from dataclasses import asdict
9
+ from pathlib import Path
10
+
11
+ from capsight import __version__
12
+ from capsight.decode import TsharkError
13
+ from capsight.engine import Report, analyze
14
+ from capsight.redact import Redactor
15
+ from capsight.summary import build_summary, render_summary
16
+
17
+ SUMMARY_HINT_OCCURRENCES = 100
18
+
19
+
20
+ def render_text(report: Report, summary: dict | None = None) -> str:
21
+ lines = [
22
+ f"capture {report.capture}",
23
+ f"packets {report.packets} ({report.duration_s} s)",
24
+ ]
25
+ protos = report.core_protocols
26
+ lines.append(
27
+ "protocols "
28
+ + (
29
+ ", ".join(f"{p}={n}" for p, n in protos.items())
30
+ if protos
31
+ else "no mobile-core signalling found"
32
+ )
33
+ )
34
+ if report.subscriber is not None:
35
+ lines += render_timeline(report)
36
+ if not report.timeline:
37
+ return "\n".join(lines)
38
+ if summary is not None:
39
+ return "\n".join(lines + render_summary(summary))
40
+ problems = [f for f in report.findings if f.severity != "info"]
41
+ if not problems:
42
+ lines += ["", "No known failure patterns found."]
43
+ if not report.findings:
44
+ return "\n".join(lines)
45
+ for finding in report.findings:
46
+ lines += ["", f"{finding.severity.upper():<9} {finding.verdict}"]
47
+ lines.append(f"{'WHY':<9} {finding.why}")
48
+ if finding.subscribers:
49
+ shown = ", ".join(finding.subscribers[:3])
50
+ more = (
51
+ f" (+{len(finding.subscribers) - 3} more)" if len(finding.subscribers) > 3 else ""
52
+ )
53
+ lines.append(f"{'WHO':<9} {shown}{more}")
54
+ lines.append(f"{'WHERE':<9} packets " + ", ".join(f"#{n}" for n in finding.evidence))
55
+ if finding.fix:
56
+ lines.append(f"{'FIX':<9} {finding.fix}")
57
+ if sum(f.count for f in problems) >= SUMMARY_HINT_OCCURRENCES:
58
+ lines += ["", "tip: add --summary for top problems, most affected subscribers and timing."]
59
+ return "\n".join(lines)
60
+
61
+
62
+ STATUS_MARK = {"ok": "ok", "failed": "FAILED", "no answer": "NO ANSWER", "info": "note"}
63
+
64
+
65
+ def render_timeline(report: Report) -> list[str]:
66
+ lines = ["", f"subscriber {report.subscriber}"]
67
+ steps = report.timeline or []
68
+ if not steps:
69
+ lines.append(" not found in this capture.")
70
+ seen = report.subscribers_seen or []
71
+ if seen:
72
+ shown = ", ".join(seen[:10])
73
+ more = f" (+{len(seen) - 10} more)" if len(seen) > 10 else ""
74
+ lines.append(f" subscribers in this capture: {shown}{more}")
75
+ else:
76
+ lines.append(" no subscriber identities were found in this capture.")
77
+ return lines
78
+ t0 = steps[0].time
79
+ for step in steps:
80
+ where = "#" + ",#".join(str(n) for n in step.packets)
81
+ mark = STATUS_MARK.get(step.status, step.status)
82
+ line = f" +{step.time - t0:8.3f}s {where:<11} {step.protocol:<9} {step.name:<44} {mark}"
83
+ if step.detail:
84
+ line += f" {step.detail}"
85
+ lines.append(line.rstrip())
86
+ broken = next((s for s in steps if s.status in ("failed", "no answer")), None)
87
+ if broken is None:
88
+ lines.append(" every step above completed.")
89
+ else:
90
+ lines.append(
91
+ f" stopped at: {broken.name} (packet #{broken.packets[-1]})"
92
+ + (f", {broken.detail}" if broken.detail else "")
93
+ )
94
+ return lines
95
+
96
+
97
+ def main(argv: list[str] | None = None) -> int:
98
+ parser = argparse.ArgumentParser(prog="capsight", description=__doc__)
99
+ parser.add_argument("--version", action="version", version=f"capsight {__version__}")
100
+ sub = parser.add_subparsers(dest="command", required=True)
101
+ analyze_cmd = sub.add_parser("analyze", help="analyze a capture file")
102
+ analyze_cmd.add_argument("capture", type=Path)
103
+ analyze_cmd.add_argument("--format", choices=("text", "json"), default="text")
104
+ analyze_cmd.add_argument(
105
+ "--timeout",
106
+ type=float,
107
+ default=5.0,
108
+ help="seconds without an answer before a request counts as unanswered (default 5)",
109
+ )
110
+ analyze_cmd.add_argument(
111
+ "--imsi",
112
+ help="show one subscriber's steps in order and only the findings about it",
113
+ )
114
+ analyze_cmd.add_argument(
115
+ "--summary",
116
+ action="store_true",
117
+ help="busy captures: top problems, most affected subscribers, problems over time",
118
+ )
119
+ analyze_cmd.add_argument(
120
+ "--redact",
121
+ action="store_true",
122
+ help="mask subscriber numbers, IP addresses and host/realm names in the output",
123
+ )
124
+ analyze_cmd.add_argument(
125
+ "--redact-all",
126
+ action="store_true",
127
+ help="like --redact, and also hide the home network (MCC/MNC) of each IMSI",
128
+ )
129
+ analyze_cmd.add_argument(
130
+ "--fail-on",
131
+ choices=("failure", "warning", "never"),
132
+ default="never",
133
+ help="exit with code 1 if a finding at this severity or worse is found (for CI/scripts)",
134
+ )
135
+ args = parser.parse_args(argv)
136
+
137
+ try:
138
+ report = analyze(args.capture, answer_timeout=args.timeout, imsi=args.imsi)
139
+ except TsharkError as exc:
140
+ print(f"error: {exc}", file=sys.stderr)
141
+ return 2
142
+ summary = build_summary(report) if args.summary else None
143
+ redactor = Redactor(keep_plmn=not args.redact_all) if args.redact or args.redact_all else None
144
+ if redactor is not None:
145
+ # file names often carry hosts, IMSIs or dates: keep only the extension
146
+ report.capture = "capture" + Path(report.capture).suffix
147
+ if args.format == "json":
148
+ doc = asdict(report)
149
+ if summary is not None:
150
+ doc["summary"] = summary
151
+ if redactor is not None:
152
+ doc = redactor.data(doc)
153
+ doc["redacted"] = True
154
+ print(json.dumps(doc, indent=2))
155
+ else:
156
+ text = render_text(report, summary)
157
+ if redactor is not None:
158
+ text = redactor.text(text) + "\n\n" + redactor.counts()
159
+ print(text)
160
+ return 1 if _should_fail(report, args.fail_on) else 0
161
+
162
+
163
+ def _should_fail(report: Report, fail_on: str) -> bool:
164
+ if fail_on == "never":
165
+ return False
166
+ levels = {"failure"} if fail_on == "failure" else {"failure", "warning"}
167
+ return any(f.severity in levels for f in report.findings)
168
+
169
+
170
+ if __name__ == "__main__":
171
+ sys.exit(main())
capsight/codes.py ADDED
@@ -0,0 +1,257 @@
1
+ """Protocol code tables: names plus a short, actionable hint.
2
+
3
+ Sources: RFC 6733 (Diameter base), 3GPP TS 29.272 (S6a/S6d), TS 29.274 (GTPv2-C),
4
+ TS 24.301 (EPS NAS).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import NamedTuple
10
+
11
+
12
+ class Code(NamedTuple):
13
+ name: str
14
+ hint: str = ""
15
+
16
+
17
+ DIAMETER_COMMANDS: dict[int, tuple[str, str]] = {
18
+ # code: (request abbreviation, answer abbreviation)
19
+ 257: ("CER", "CEA"),
20
+ 280: ("DWR", "DWA"),
21
+ 282: ("DPR", "DPA"),
22
+ 316: ("ULR", "ULA"),
23
+ 317: ("CLR", "CLA"),
24
+ 318: ("AIR", "AIA"),
25
+ 319: ("IDR", "IDA"),
26
+ 320: ("DSR", "DSA"),
27
+ 321: ("PUR", "PUA"),
28
+ 322: ("RSR", "RSA"),
29
+ 323: ("NOR", "NOA"),
30
+ 272: ("CCR", "CCA"),
31
+ 265: ("AAR", "AAA"),
32
+ 258: ("RAR", "RAA"),
33
+ 275: ("STR", "STA"),
34
+ 300: ("UAR", "UAA"),
35
+ 301: ("SAR", "SAA"),
36
+ 302: ("LIR", "LIA"),
37
+ 303: ("MAR", "MAA"),
38
+ 304: ("RTR", "RTA"),
39
+ 305: ("PPR", "PPA"),
40
+ 306: ("UDR", "UDA"),
41
+ 307: ("PUR", "PUA"),
42
+ 308: ("SNR", "SNA"),
43
+ 309: ("PNR", "PNA"),
44
+ 8388620: ("PLR", "PLA"),
45
+ 8388622: ("LRR", "LRA"),
46
+ }
47
+
48
+ # Base protocol Result-Code values (RFC 6733, RFC 4006).
49
+ DIAMETER_RESULT: dict[int, Code] = {
50
+ 2001: Code("DIAMETER_SUCCESS"),
51
+ 3001: Code("DIAMETER_COMMAND_UNSUPPORTED", "The peer does not support this command."),
52
+ 3002: Code(
53
+ "DIAMETER_UNABLE_TO_DELIVER",
54
+ "No route to the destination. Check Destination-Realm/Host and the routing agent's "
55
+ "peer and realm table.",
56
+ ),
57
+ 3003: Code("DIAMETER_REALM_NOT_SERVED", "The destination realm is not configured on the peer."),
58
+ 3004: Code("DIAMETER_TOO_BUSY", "The peer is overloaded. Check its load and retry policy."),
59
+ 3005: Code("DIAMETER_LOOP_DETECTED", "Routing loop between agents. Check Route-Record AVPs."),
60
+ 3010: Code("DIAMETER_UNKNOWN_PEER", "The peer has no connection configured for the sender."),
61
+ 4010: Code("DIAMETER_END_USER_SERVICE_DENIED", "Charging/policy denied service to the user."),
62
+ 4012: Code("DIAMETER_CREDIT_LIMIT_REACHED", "The user has no credit left."),
63
+ 5001: Code("DIAMETER_AVP_UNSUPPORTED", "A mandatory AVP is not understood by the peer."),
64
+ 5004: Code("DIAMETER_INVALID_AVP_VALUE", "An AVP value was rejected. See the Failed-AVP."),
65
+ 5005: Code("DIAMETER_MISSING_AVP", "A required AVP is missing. See the Failed-AVP."),
66
+ 5012: Code("DIAMETER_UNABLE_TO_COMPLY", "Generic failure on the peer. Check its logs."),
67
+ 5030: Code("DIAMETER_USER_UNKNOWN", "The charging/policy server does not know this user."),
68
+ }
69
+
70
+ # 3GPP Experimental-Result-Code values (TS 29.272, TS 29.229).
71
+ DIAMETER_EXPERIMENTAL: dict[int, Code] = {
72
+ 2001: Code("DIAMETER_FIRST_REGISTRATION"),
73
+ 2002: Code("DIAMETER_SUBSEQUENT_REGISTRATION"),
74
+ 4181: Code(
75
+ "DIAMETER_AUTHENTICATION_DATA_UNAVAILABLE",
76
+ "The HSS could not produce authentication vectors. Check the subscriber's keys.",
77
+ ),
78
+ 5001: Code(
79
+ "DIAMETER_ERROR_USER_UNKNOWN",
80
+ "The subscriber is not provisioned in the HSS/UDM, or the IMSI on the SIM does not "
81
+ "match the provisioned one.",
82
+ ),
83
+ 5002: Code("DIAMETER_ERROR_IDENTITIES_DONT_MATCH", "IMPI and IMPU are not associated."),
84
+ 5003: Code("DIAMETER_ERROR_IDENTITY_NOT_REGISTERED", "The IMS identity is not registered."),
85
+ 5004: Code(
86
+ "DIAMETER_ERROR_ROAMING_NOT_ALLOWED",
87
+ "The subscription does not allow roaming in the visited network.",
88
+ ),
89
+ 5420: Code(
90
+ "DIAMETER_ERROR_UNKNOWN_EPS_SUBSCRIPTION",
91
+ "The subscriber exists but has no EPS (4G) subscription data.",
92
+ ),
93
+ 5421: Code(
94
+ "DIAMETER_ERROR_RAT_NOT_ALLOWED",
95
+ "The subscription does not allow the radio access type in use.",
96
+ ),
97
+ 5422: Code("DIAMETER_ERROR_EQUIPMENT_UNKNOWN", "The device IMEI is unknown or blocked."),
98
+ 5423: Code("DIAMETER_ERROR_UNKOWN_SERVING_NODE", "The serving node is not known to the HSS."),
99
+ }
100
+
101
+ # GTPv2-C Cause values (TS 29.274 section 8.4). 16-63 are acceptance causes.
102
+ GTPV2_CAUSE: dict[int, Code] = {
103
+ 16: Code("Request accepted"),
104
+ 17: Code("Request accepted partially"),
105
+ 64: Code("Context Not Found", "The receiver has no session for this TEID."),
106
+ 65: Code("Invalid Message Format"),
107
+ 66: Code("Version not supported by next peer"),
108
+ 67: Code("Invalid length"),
109
+ 68: Code("Service not supported"),
110
+ 69: Code("Mandatory IE incorrect", "An IE was present but its value was rejected."),
111
+ 70: Code("Mandatory IE missing", "The sender omitted a required IE."),
112
+ 72: Code("System failure", "Internal failure on the responding node. Check its logs."),
113
+ 73: Code("No resources available", "The gateway is out of capacity."),
114
+ 78: Code(
115
+ "Missing or unknown APN",
116
+ "The APN requested by the device is not configured on the gateway or not resolvable.",
117
+ ),
118
+ 83: Code("Preferred PDN Type not supported", "Check the device's IPv4/IPv6 setting."),
119
+ 84: Code("All dynamic addresses are occupied", "The IP pool for this APN is exhausted."),
120
+ 89: Code("Service denied"),
121
+ 92: Code("User authentication failed", "The PGW (or its AAA) rejected the user."),
122
+ 93: Code(
123
+ "APN access denied - no subscription",
124
+ "The subscriber is not subscribed to this APN.",
125
+ ),
126
+ 94: Code("Request rejected (reason not specified)"),
127
+ 96: Code("IMSI/IMEI not known"),
128
+ 100: Code("Remote peer not responding", "A downstream node (often the PGW) did not answer."),
129
+ 110: Code("Temporarily rejected due to handover/TAU/RAU procedure in progress"),
130
+ 113: Code("APN Congestion"),
131
+ }
132
+
133
+ GTPV2_MESSAGES: dict[int, str] = {
134
+ 1: "Echo Request",
135
+ 2: "Echo Response",
136
+ 32: "Create Session Request",
137
+ 33: "Create Session Response",
138
+ 34: "Modify Bearer Request",
139
+ 35: "Modify Bearer Response",
140
+ 36: "Delete Session Request",
141
+ 37: "Delete Session Response",
142
+ 95: "Create Bearer Request",
143
+ 96: "Create Bearer Response",
144
+ 97: "Update Bearer Request",
145
+ 98: "Update Bearer Response",
146
+ 99: "Delete Bearer Request",
147
+ 100: "Delete Bearer Response",
148
+ 170: "Release Access Bearers Request",
149
+ 171: "Release Access Bearers Response",
150
+ 176: "Downlink Data Notification",
151
+ 177: "Downlink Data Notification Acknowledge",
152
+ }
153
+
154
+ # request type -> response type
155
+ GTPV2_PAIRS: dict[int, int] = {
156
+ 1: 2,
157
+ 32: 33,
158
+ 34: 35,
159
+ 36: 37,
160
+ 95: 96,
161
+ 97: 98,
162
+ 99: 100,
163
+ 170: 171,
164
+ 176: 177,
165
+ }
166
+
167
+ # EPS Mobility Management message types (TS 24.301 table 9.8.1).
168
+ EMM_MESSAGES: dict[int, str] = {
169
+ 0x41: "Attach Request",
170
+ 0x42: "Attach Accept",
171
+ 0x43: "Attach Complete",
172
+ 0x44: "Attach Reject",
173
+ 0x45: "Detach Request",
174
+ 0x46: "Detach Accept",
175
+ 0x48: "Tracking Area Update Request",
176
+ 0x49: "Tracking Area Update Accept",
177
+ 0x4A: "Tracking Area Update Complete",
178
+ 0x4B: "Tracking Area Update Reject",
179
+ 0x4C: "Extended Service Request",
180
+ 0x4E: "Service Reject",
181
+ 0x50: "GUTI Reallocation Command",
182
+ 0x51: "GUTI Reallocation Complete",
183
+ 0x52: "Authentication Request",
184
+ 0x53: "Authentication Response",
185
+ 0x54: "Authentication Reject",
186
+ 0x55: "Identity Request",
187
+ 0x56: "Identity Response",
188
+ 0x5C: "Authentication Failure",
189
+ 0x5D: "Security Mode Command",
190
+ 0x5E: "Security Mode Complete",
191
+ 0x5F: "Security Mode Reject",
192
+ 0x60: "EMM Status",
193
+ 0x61: "EMM Information",
194
+ 0x62: "Downlink NAS Transport",
195
+ 0x63: "Uplink NAS Transport",
196
+ }
197
+
198
+ EMM_REJECTS = {0x44, 0x4B, 0x4E}
199
+
200
+ # EMM cause values (TS 24.301 section 9.9.3.9).
201
+ EMM_CAUSE: dict[int, Code] = {
202
+ 3: Code("Illegal UE", "The network failed to authenticate the SIM. Check its keys."),
203
+ 6: Code("Illegal ME", "The device (IMEI) is blocked."),
204
+ 7: Code("EPS services not allowed", "The subscription has no 4G service."),
205
+ 8: Code(
206
+ "EPS services and non-EPS services not allowed",
207
+ "The subscriber is unknown or barred in the home network.",
208
+ ),
209
+ 9: Code(
210
+ "UE identity cannot be derived by the network",
211
+ "The GUTI is stale; the device should re-attach with its IMSI.",
212
+ ),
213
+ 10: Code("Implicitly detached"),
214
+ 11: Code("PLMN not allowed", "The subscription does not allow this network."),
215
+ 12: Code("Tracking area not allowed"),
216
+ 13: Code("Roaming not allowed in this tracking area"),
217
+ 14: Code("EPS services not allowed in this PLMN"),
218
+ 15: Code("No suitable cells in tracking area"),
219
+ 17: Code("Network failure", "A core node failed during the procedure. Check the HSS/MME."),
220
+ 19: Code("ESM failure", "The default bearer could not be created. See the ESM cause."),
221
+ 22: Code("Congestion"),
222
+ 111: Code("Protocol error, unspecified"),
223
+ }
224
+
225
+ # Authentication Failure causes sent by the UE.
226
+ AUTH_FAILURE_CAUSE: dict[int, Code] = {
227
+ 20: Code(
228
+ "MAC failure",
229
+ "The SIM could not verify the network: the keys (Ki/OPc) in the HSS do not match the SIM.",
230
+ ),
231
+ 21: Code(
232
+ "Synch failure",
233
+ "Sequence numbers are out of sync. Normally self-healing via re-synchronisation; "
234
+ "repeated failures point at the HSS SQN handling.",
235
+ ),
236
+ 26: Code("Non-EPS authentication unacceptable"),
237
+ }
238
+
239
+ # ESM cause values (TS 24.301 section 9.9.4.4).
240
+ ESM_CAUSE: dict[int, Code] = {
241
+ 26: Code("Insufficient resources"),
242
+ 27: Code("Missing or unknown APN", "The APN set on the device is not valid on this network."),
243
+ 28: Code("Unknown PDN type"),
244
+ 29: Code("User authentication failed"),
245
+ 30: Code("Request rejected by Serving GW or PDN GW"),
246
+ 31: Code("Request rejected, unspecified"),
247
+ 32: Code("Service option not supported"),
248
+ 33: Code("Requested service option not subscribed", "The APN is not in the subscription."),
249
+ 38: Code("Network failure"),
250
+ 50: Code("PDN type IPv4 only allowed"),
251
+ 51: Code("PDN type IPv6 only allowed"),
252
+ 55: Code("Multiple PDN connections for a given APN not allowed"),
253
+ }
254
+
255
+
256
+ def lookup(table: dict[int, Code], value: int) -> Code:
257
+ return table.get(value, Code(f"code {value}"))
capsight/codes_5g.py ADDED
@@ -0,0 +1,258 @@
1
+ """5G SA code tables: NGAP, 5GMM/5GSM (TS 24.501), PFCP (TS 29.244)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from capsight.codes import Code
6
+
7
+ # ---- 5GMM ------------------------------------------------------------------------------
8
+
9
+ MM_MESSAGES: dict[int, str] = {
10
+ 0x41: "Registration Request",
11
+ 0x42: "Registration Accept",
12
+ 0x43: "Registration Complete",
13
+ 0x44: "Registration Reject",
14
+ 0x45: "Deregistration Request",
15
+ 0x47: "Deregistration Request (network)",
16
+ 0x4C: "Service Request",
17
+ 0x4D: "Service Reject",
18
+ 0x4E: "Service Accept",
19
+ 0x54: "Configuration Update Command",
20
+ 0x56: "Authentication Request",
21
+ 0x57: "Authentication Response",
22
+ 0x58: "Authentication Reject",
23
+ 0x59: "Authentication Failure",
24
+ 0x5D: "Security Mode Command",
25
+ 0x5E: "Security Mode Complete",
26
+ 0x5F: "Security Mode Reject",
27
+ 0x64: "5GMM Status",
28
+ 0x67: "UL NAS Transport",
29
+ 0x68: "DL NAS Transport",
30
+ }
31
+
32
+ MM_REGISTRATION_REQUEST = 0x41
33
+ MM_REGISTRATION_ACCEPT = 0x42
34
+ MM_REJECTS = {0x44, 0x4D, 0x5F}
35
+ MM_AUTH_RESPONSE = 0x57
36
+ MM_AUTH_REJECT = 0x58
37
+ MM_AUTH_FAILURE = 0x59
38
+ MM_STATUS = 0x64
39
+ MM_DL_NAS_TRANSPORT = 0x68
40
+
41
+ # 5GMM cause (TS 24.501 section 9.11.3.2).
42
+ MM_CAUSE: dict[int, Code] = {
43
+ 3: Code("Illegal UE", "The network could not authenticate the SIM. Check its keys."),
44
+ 5: Code("PEI not accepted", "The device identity (IMEI) was rejected."),
45
+ 6: Code("Illegal ME", "The device (IMEI) is blocked."),
46
+ 7: Code("5GS services not allowed", "The subscription has no 5G service."),
47
+ 9: Code(
48
+ "UE identity cannot be derived by the network",
49
+ "The 5G-GUTI is stale; the device should register again with its SUCI.",
50
+ ),
51
+ 10: Code("Implicitly de-registered"),
52
+ 11: Code("PLMN not allowed", "The subscription does not allow this network."),
53
+ 12: Code("Tracking area not allowed"),
54
+ 13: Code("Roaming not allowed in this tracking area"),
55
+ 15: Code("No suitable cells in tracking area"),
56
+ 20: Code(
57
+ "MAC failure",
58
+ "The SIM could not verify the network: the keys (K/OPc) in the UDM do not match the SIM.",
59
+ ),
60
+ 21: Code("Synch failure", "Sequence numbers are out of sync between SIM and UDM."),
61
+ 22: Code("Congestion"),
62
+ 23: Code("UE security capabilities mismatch"),
63
+ 24: Code("Security mode rejected, unspecified"),
64
+ 26: Code("Non-5G authentication unacceptable"),
65
+ 27: Code("N1 mode not allowed"),
66
+ 28: Code("Restricted service area"),
67
+ 31: Code("Redirection to EPC required"),
68
+ 62: Code(
69
+ "No network slices available",
70
+ "None of the requested slices (S-NSSAI) are allowed. Check the subscription's "
71
+ "slices and the AMF's supported slice list.",
72
+ ),
73
+ 65: Code("Maximum number of PDU sessions reached"),
74
+ 67: Code("Insufficient resources for specific slice and DNN"),
75
+ 69: Code("Insufficient resources for specific slice"),
76
+ 71: Code("ngKSI already in use"),
77
+ 73: Code(
78
+ "Serving network not authorized",
79
+ "The home network refused authentication for this serving network name.",
80
+ ),
81
+ 90: Code(
82
+ "Payload was not forwarded",
83
+ "The AMF could not forward the session request to an SMF. Check SMF selection "
84
+ "(NRF, slice and DNN configuration).",
85
+ ),
86
+ 91: Code(
87
+ "DNN not supported or not subscribed in the slice",
88
+ "The DNN (APN) the device asked for is not subscribed for this subscriber in this "
89
+ "slice, or not configured on the core. Fix the device's DNN or add it to the "
90
+ "subscription.",
91
+ ),
92
+ 92: Code("Insufficient user-plane resources for the PDU session"),
93
+ 95: Code("Semantically incorrect message"),
94
+ 96: Code("Invalid mandatory information"),
95
+ 97: Code("Message type non-existent or not implemented"),
96
+ 111: Code("Protocol error, unspecified"),
97
+ }
98
+
99
+ # ---- 5GSM ------------------------------------------------------------------------------
100
+
101
+ SM_ESTABLISHMENT_REQUEST = 0xC1
102
+ SM_ESTABLISHMENT_ACCEPT = 0xC2
103
+ SM_REJECTS: dict[int, str] = {
104
+ 0xC3: "PDU Session Establishment Reject",
105
+ 0xCB: "PDU Session Modification Reject",
106
+ 0xD2: "PDU Session Release Reject",
107
+ }
108
+
109
+ # 5GSM cause (TS 24.501 section 9.11.4.2).
110
+ SM_CAUSE: dict[int, Code] = {
111
+ 8: Code("Operator determined barring"),
112
+ 26: Code("Insufficient resources"),
113
+ 27: Code("Missing or unknown DNN", "The DNN set on the device is not valid on this network."),
114
+ 28: Code("Unknown PDU session type"),
115
+ 29: Code(
116
+ "User authentication or authorization failed",
117
+ "The SMF or its AAA/DN-AAA refused the session.",
118
+ ),
119
+ 31: Code("Request rejected, unspecified"),
120
+ 32: Code("Service option not supported"),
121
+ 33: Code("Requested service option not subscribed", "The DNN is not in the subscription."),
122
+ 38: Code("Network failure"),
123
+ 43: Code("Invalid PDU session identity"),
124
+ 46: Code("Out of LADN service area"),
125
+ 50: Code("PDU session type IPv4 only allowed"),
126
+ 51: Code("PDU session type IPv6 only allowed"),
127
+ 54: Code("PDU session does not exist"),
128
+ 57: Code("PDU session type IPv4v6 only allowed"),
129
+ 59: Code("Unsupported 5QI value"),
130
+ 67: Code("Insufficient resources for specific slice and DNN"),
131
+ 68: Code("Not supported SSC mode"),
132
+ 69: Code("Insufficient resources for specific slice"),
133
+ 70: Code(
134
+ "Missing or unknown DNN in a slice",
135
+ "The DNN is not configured for the requested slice (S-NSSAI).",
136
+ ),
137
+ 111: Code("Protocol error, unspecified"),
138
+ }
139
+
140
+ # ---- NGAP ------------------------------------------------------------------------------
141
+
142
+ NGAP_PROCEDURES: dict[int, str] = {
143
+ 0: "AMF Configuration Update",
144
+ 4: "Downlink NAS Transport",
145
+ 12: "Handover Preparation",
146
+ 13: "Handover Resource Allocation",
147
+ 14: "Initial Context Setup",
148
+ 15: "Initial UE Message",
149
+ 20: "NG Reset",
150
+ 21: "NG Setup",
151
+ 25: "Path Switch Request",
152
+ 26: "PDU Session Resource Modify",
153
+ 28: "PDU Session Resource Release",
154
+ 29: "PDU Session Resource Setup",
155
+ 35: "RAN Configuration Update",
156
+ 40: "UE Context Modification",
157
+ 41: "UE Context Release",
158
+ 42: "UE Context Release Request",
159
+ 46: "Uplink NAS Transport",
160
+ }
161
+
162
+ NGAP_UNSUCCESSFUL_OUTCOME = 2
163
+ NGAP_CAUSE_GROUPS = ("radioNetwork", "transport", "nas", "protocol", "misc")
164
+
165
+ NGAP_CAUSE: dict[str, dict[int, Code]] = {
166
+ "misc": {
167
+ 0: Code("control-processing-overload", "The AMF is overloaded."),
168
+ 1: Code("not-enough-user-plane-processing-resources"),
169
+ 2: Code("hardware-failure"),
170
+ 3: Code("om-intervention"),
171
+ 4: Code(
172
+ "unknown-PLMN-or-SNPN",
173
+ "The AMF does not serve what the gNB announced: check that the gNB's PLMN "
174
+ "(MCC/MNC) and its tracking area codes (TAC) are in the AMF's served PLMN and "
175
+ "TAI lists, and that the slice list matches.",
176
+ ),
177
+ 5: Code("unspecified"),
178
+ },
179
+ "nas": {
180
+ 0: Code("normal-release"),
181
+ 1: Code("authentication-failure"),
182
+ 2: Code("deregister"),
183
+ 3: Code("unspecified"),
184
+ },
185
+ "transport": {
186
+ 0: Code("transport-resource-unavailable"),
187
+ 1: Code("unspecified"),
188
+ },
189
+ "protocol": {
190
+ 0: Code("transfer-syntax-error"),
191
+ 1: Code("abstract-syntax-error-reject"),
192
+ 2: Code("abstract-syntax-error-ignore-and-notify"),
193
+ 3: Code("message-not-compatible-with-receiver-state"),
194
+ 4: Code("semantic-error"),
195
+ 5: Code("abstract-syntax-error-falsely-constructed-message"),
196
+ 6: Code("unspecified"),
197
+ },
198
+ "radioNetwork": {
199
+ 0: Code("unspecified"),
200
+ 21: Code("radio-connection-with-ue-lost"),
201
+ 26: Code("unknown-PDU-session-ID"),
202
+ 27: Code("unknown-qos-flow-ID"),
203
+ 30: Code("multiple-PDU-session-ID-instances"),
204
+ 41: Code("slice-not-supported", "The gNB or AMF does not support the requested slice."),
205
+ },
206
+ }
207
+
208
+ # ---- PFCP ------------------------------------------------------------------------------
209
+
210
+ PFCP_MESSAGES: dict[int, str] = {
211
+ 1: "Heartbeat Request",
212
+ 2: "Heartbeat Response",
213
+ 5: "Association Setup Request",
214
+ 6: "Association Setup Response",
215
+ 7: "Association Update Request",
216
+ 8: "Association Update Response",
217
+ 9: "Association Release Request",
218
+ 10: "Association Release Response",
219
+ 12: "Node Report Request",
220
+ 13: "Node Report Response",
221
+ 50: "Session Establishment Request",
222
+ 51: "Session Establishment Response",
223
+ 52: "Session Modification Request",
224
+ 53: "Session Modification Response",
225
+ 54: "Session Deletion Request",
226
+ 55: "Session Deletion Response",
227
+ 56: "Session Report Request",
228
+ 57: "Session Report Response",
229
+ }
230
+
231
+ PFCP_PAIRS: dict[int, int] = {1: 2, 5: 6, 7: 8, 9: 10, 12: 13, 50: 51, 52: 53, 54: 55, 56: 57}
232
+
233
+ # PFCP Cause (TS 29.244 section 8.2.1). 1 = Request accepted.
234
+ PFCP_CAUSE: dict[int, Code] = {
235
+ 1: Code("Request accepted"),
236
+ 64: Code("Request rejected (reason not specified)"),
237
+ 65: Code("Session context not found", "The UPF has no session for this SEID."),
238
+ 66: Code("Mandatory IE missing"),
239
+ 67: Code("Conditional IE missing"),
240
+ 68: Code("Invalid length"),
241
+ 69: Code("Mandatory IE incorrect"),
242
+ 70: Code("Invalid Forwarding Policy"),
243
+ 71: Code("Invalid F-TEID allocation option"),
244
+ 72: Code(
245
+ "No established PFCP Association",
246
+ "The SMF and UPF have no PFCP association. Check that the association setup "
247
+ "succeeded and heartbeats are answered.",
248
+ ),
249
+ 73: Code(
250
+ "Rule creation/modification Failure",
251
+ "The UPF could not install a PDR/FAR/QER. Check the rule contents and the UPF logs.",
252
+ ),
253
+ 74: Code("PFCP entity in congestion"),
254
+ 75: Code("No resources available", "The UPF is out of capacity (e.g. TEIDs or UE IPs)."),
255
+ 76: Code("Service not supported"),
256
+ 77: Code("System failure", "Internal failure on the UPF. Check its logs."),
257
+ 78: Code("Redirection Requested"),
258
+ }