-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNASHelperNGAP_ServiceAccept.cpp
More file actions
98 lines (86 loc) · 3.19 KB
/
NASHelperNGAP_ServiceAccept.cpp
File metadata and controls
98 lines (86 loc) · 3.19 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
#include "NASHelperNGAP.hpp"
namespace {
bool serviceAcceptOptionalIsTlvE(std::uint8_t iei) {
switch (iei) {
case 0x72:
case 0x78:
return true;
default:
return false;
}
}
bool serviceAcceptOptionalIsTlv(std::uint8_t iei) {
switch (iei) {
case 0x50:
case 0x26:
case 0x6B:
case 0x34:
case 0x1D:
case 0x1E:
return true;
default:
return false;
}
}
} // namespace
bool NASHelperNGAP::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];
if (serviceAcceptOptionalIsTlvE(b)) {
if (i + 3U > informationElementOctetCount) {
break;
}
const std::uint16_t len =
static_cast<std::uint16_t>((static_cast<unsigned>(informationElements[i + 1]) << 8U) |
static_cast<unsigned>(informationElements[i + 2]));
const std::size_t chunk = 3U + static_cast<std::size_t>(len);
if (i + chunk > informationElementOctetCount || i + chunk < i) {
break;
}
ServiceAcceptOptionalInformationElement opt{};
opt.iei = b;
opt.encoding = ServiceAcceptOptionalInformationElement::Encoding::TlvE;
opt.value.assign(informationElements + i + 3, informationElements + i + 3 + len);
out.optionals.push_back(std::move(opt));
i += chunk;
continue;
}
if (serviceAcceptOptionalIsTlv(b)) {
if (i + 2U > informationElementOctetCount) {
break;
}
const std::uint8_t len = informationElements[i + 1];
const std::size_t chunk = 2U + static_cast<std::size_t>(len);
if (i + chunk > informationElementOctetCount || i + chunk < i) {
break;
}
ServiceAcceptOptionalInformationElement opt{};
opt.iei = b;
opt.encoding = ServiceAcceptOptionalInformationElement::Encoding::Tlv;
opt.value.assign(informationElements + i + 2, informationElements + i + 2 + len);
out.optionals.push_back(std::move(opt));
i += chunk;
continue;
}
out.unparsed_begin = informationElements + i;
out.unparsed_octet_count = informationElementOctetCount - i;
break;
}
if (i < informationElementOctetCount && out.unparsed_begin == nullptr) {
out.unparsed_begin = informationElements + i;
out.unparsed_octet_count = informationElementOctetCount - i;
}
out.ok = true;
return true;
}