-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNASHelperS1AP_ServiceAccept.cpp
More file actions
111 lines (99 loc) · 3.96 KB
/
NASHelperS1AP_ServiceAccept.cpp
File metadata and controls
111 lines (99 loc) · 3.96 KB
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
#include "NASHelperS1AP.hpp"
#include <utility>
namespace {
bool appendTlvOptionalRange(const std::uint8_t* ie,
std::size_t n,
std::size_t& i,
std::uint8_t expectedIei,
std::size_t minTotalOctets,
std::size_t maxTotalOctets,
NASHelperS1AP::ServiceAcceptInformationElementsParse& out) {
if (i + 2U > n || ie[i] != expectedIei) {
return false;
}
const std::uint8_t len = ie[i + 1];
const std::size_t chunk = 2U + static_cast<std::size_t>(len);
if (chunk < minTotalOctets || chunk > maxTotalOctets || i + chunk > n) {
return false;
}
NASHelperS1AP::ServiceAcceptOptionalInformationElement opt{};
opt.iei = expectedIei;
opt.value.assign(ie + i + 2U, ie + i + chunk);
out.optionals.push_back(std::move(opt));
i += chunk;
return true;
}
bool appendTlvFixedTotalOptional(const std::uint8_t* ie,
std::size_t n,
std::size_t& i,
std::uint8_t expectedIei,
std::size_t totalOctets,
NASHelperS1AP::ServiceAcceptInformationElementsParse& out) {
if (i + totalOctets > n || ie[i] != expectedIei) {
return false;
}
const std::uint8_t len = ie[i + 1];
if (2U + static_cast<std::size_t>(len) != totalOctets) {
return false;
}
NASHelperS1AP::ServiceAcceptOptionalInformationElement opt{};
opt.iei = expectedIei;
opt.value.assign(ie + i + 2U, ie + i + totalOctets);
out.optionals.push_back(std::move(opt));
i += totalOctets;
return true;
}
} // namespace
bool NASHelperS1AP::tryParseServiceAcceptInformationElements(const std::uint8_t* const informationElements,
const std::size_t informationElementOctetCount,
ServiceAcceptInformationElementsParse& out) {
out = ServiceAcceptInformationElementsParse{};
if (informationElementOctetCount == 0U) {
out.ok = true;
return true;
}
if (informationElements == nullptr) {
return false;
}
std::size_t i = 0U;
while (i < informationElementOctetCount) {
const std::uint8_t b = informationElements[i];
bool consumed = false;
switch (b) {
case 0x57U:
consumed =
appendTlvFixedTotalOptional(informationElements, informationElementOctetCount, i, 0x57U, 4U, out);
break;
case 0x6BU:
consumed =
appendTlvFixedTotalOptional(informationElements, informationElementOctetCount, i, 0x6BU, 3U, out);
break;
case 0x37U:
consumed =
appendTlvFixedTotalOptional(informationElements, informationElementOctetCount, i, 0x37U, 3U, out);
break;
case 0x1DU:
consumed = appendTlvOptionalRange(informationElements, informationElementOctetCount, i, 0x1DU, 8U, 98U,
out);
break;
case 0x1EU:
consumed = appendTlvOptionalRange(informationElements, informationElementOctetCount, i, 0x1EU, 8U, 98U,
out);
break;
case 0x21U:
consumed = appendTlvOptionalRange(informationElements, informationElementOctetCount, i, 0x21U, 3U, 257U,
out);
break;
default:
break;
}
if (consumed) {
continue;
}
break;
}
out.unparsed_begin = informationElements + i;
out.unparsed_octet_count = informationElementOctetCount - i;
out.ok = true;
return true;
}