Commit 6c897504 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

First version for Mobile Identity

parent d2eff68f
...@@ -36,9 +36,8 @@ _5GSMobileIdentity::_5GSMobileIdentity() { ...@@ -36,9 +36,8 @@ _5GSMobileIdentity::_5GSMobileIdentity() {
_5g_guti = std::nullopt; _5g_guti = std::nullopt;
_imei = std::nullopt; _imei = std::nullopt;
supi_format_imsi = std::nullopt; supi_format_imsi = std::nullopt;
_5g_s_tmsi = nullptr; _5g_s_tmsi = std::nullopt;
_IMEISV = std::nullopt; _IMEISV = std::nullopt;
is_no_identity = false;
length = 0; length = 0;
typeOfIdentity = 0; typeOfIdentity = 0;
} }
...@@ -46,48 +45,22 @@ _5GSMobileIdentity::_5GSMobileIdentity() { ...@@ -46,48 +45,22 @@ _5GSMobileIdentity::_5GSMobileIdentity() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
_5GSMobileIdentity::_5GSMobileIdentity( _5GSMobileIdentity::_5GSMobileIdentity(
uint8_t _iei, const uint16_t amfSetId, const uint8_t amfPointer, uint8_t _iei, const uint16_t amfSetId, const uint8_t amfPointer,
const string tmsi) { const string tmsi) { // TODO-> set5G-S-TMSI
_5G_S_TMSI_t _5g_s_tmsi_tmp = {};
iei = _iei; iei = _iei;
typeOfIdentity = _5G_S_TMSI; typeOfIdentity = _5G_S_TMSI;
_5g_s_tmsi = (_5G_S_TMSI_t*) calloc(1, sizeof(_5G_S_TMSI_t)); _5g_s_tmsi_tmp.amf_set_id = amfSetId;
_5g_s_tmsi->amf_set_id = amfSetId; _5g_s_tmsi_tmp.amf_pointer = amfPointer;
_5g_s_tmsi->amf_pointer = amfPointer; _5g_s_tmsi_tmp._5g_tmsi = tmsi;
_5g_s_tmsi->_5g_tmsi = tmsi;
is_no_identity = false; _5g_s_tmsi = std::optional<_5G_S_TMSI_t>(_5g_s_tmsi_tmp);
length = 0;
_5g_guti = std::nullopt;
_imei = std::nullopt;
supi_format_imsi = std::nullopt;
_IMEISV = std::nullopt;
}
//------------------------------------------------------------------------------
_5GSMobileIdentity::_5GSMobileIdentity(
const string mcc, const string mnc, const string routingInd,
uint8_t protection_sch_id, const string msin) {
SUCI_imsi_t supi_format_imsi_tmp = {};
iei = 0;
typeOfIdentity = SUCI;
supi_format_imsi_tmp.supi_format = SUPI_FORMAT_IMSI;
supi_format_imsi_tmp.mcc = mcc;
supi_format_imsi_tmp.mnc = mnc;
supi_format_imsi_tmp.routingIndicator = routingInd;
supi_format_imsi_tmp.protectionSchemeId = protection_sch_id;
supi_format_imsi_tmp.homeNetworkPKI = HOME_NETWORK_PKI_0_WHEN_PSI_0;
supi_format_imsi_tmp.msin = msin;
length = 10 + ceil(msin.length() / 2);
is_no_identity = false;
supi_format_imsi = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp);
length = 0;
// Clear the other types // Clear the other types
_5g_s_tmsi = nullptr;
_5g_guti = std::nullopt; _5g_guti = std::nullopt;
_imei = std::nullopt; _imei = std::nullopt;
supi_format_imsi = std::nullopt;
_IMEISV = std::nullopt; _IMEISV = std::nullopt;
} }
...@@ -101,79 +74,96 @@ void _5GSMobileIdentity::setIEI(uint8_t _iei) { ...@@ -101,79 +74,96 @@ void _5GSMobileIdentity::setIEI(uint8_t _iei) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int _5GSMobileIdentity::_5g_s_tmsi_encode2buffer(uint8_t* buf, int len) { int _5GSMobileIdentity::_5g_s_tmsi_encode2buffer(uint8_t* buf, int len) {
if (!_5g_s_tmsi.has_value()) return KEncodeDecodeError;
int encoded_size = 0; int encoded_size = 0;
if (iei) { if (iei) {
*buf = iei; ENCODE_U8(buf + encoded_size, iei, encoded_size);
encoded_size++;
} }
*(buf + encoded_size) = 0x00;
encoded_size++; // LENGTH
*(buf + encoded_size) = 0x07; ENCODE_U8(buf + encoded_size, 0x00, encoded_size);
encoded_size++; ENCODE_U8(buf + encoded_size, 0x07, encoded_size);
*(buf + encoded_size) = 0xf0 | _5G_S_TMSI;
encoded_size++; // Type of identity
*(buf + encoded_size) = ((_5g_s_tmsi->amf_set_id) & 0x03fc) >> 8; ENCODE_U8(buf + encoded_size, 0xf0 | _5G_S_TMSI, encoded_size);
encoded_size++;
*(buf + encoded_size) = (((_5g_s_tmsi->amf_set_id) & 0x0003) << 6) | // AMF Set ID and AMF Pointer
((_5g_s_tmsi->amf_pointer) & 0x3f); ENCODE_U8(
encoded_size++; buf + encoded_size, ((_5g_s_tmsi.value().amf_set_id) & 0x03fc) >> 8,
int tmsi = fromString<int>(_5g_s_tmsi->_5g_tmsi); encoded_size);
*(buf + encoded_size) = tmsi & 0x000000ff; ENCODE_U8(
encoded_size += 1; buf + encoded_size,
*(buf + encoded_size) = (tmsi & 0x0000ff00) >> 8; (((_5g_s_tmsi.value().amf_set_id) & 0x0003) << 6) |
encoded_size += 1; ((_5g_s_tmsi.value().amf_pointer) & 0x3f),
*(buf + encoded_size) = (tmsi & 0x00ff0000) >> 16; encoded_size);
encoded_size += 1;
*(buf + encoded_size) = (tmsi & 0xff000000) >> 24; // 5G-TMSI
encoded_size += 1; int tmsi = fromString<int>(_5g_s_tmsi.value()._5g_tmsi);
ENCODE_U32(buf + encoded_size, tmsi, encoded_size);
return encoded_size; return encoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int _5GSMobileIdentity::_5g_s_tmsi_decodefrombuffer(uint8_t* buf, int len) { int _5GSMobileIdentity::_5g_s_tmsi_decodefrombuffer(uint8_t* buf, int len) {
int decoded_size = 0; int decoded_size = 0;
if (!_5g_s_tmsi) _5g_s_tmsi = (_5G_S_TMSI_t*) calloc(1, sizeof(_5G_S_TMSI_t)); _5G_S_TMSI_t _5g_s_tmsi_tmp = {};
decoded_size++; // type of identity decoded_size++; // type of identity
uint8_t octet = *(buf + decoded_size);
decoded_size++; // AMF Set ID and AMF Pointer
_5g_s_tmsi->amf_set_id = 0x0000 | ((uint16_t) octet) << 2; uint8_t octet = 0;
octet = *(buf + decoded_size);
decoded_size++; //*(buf + decoded_size);
_5g_s_tmsi->amf_set_id |= (octet & 0xc0) >> 6; // decoded_size++;
_5g_s_tmsi->amf_pointer = octet & 0x3f; DECODE_U8(buf + decoded_size, octet, decoded_size);
_5g_s_tmsi_tmp.amf_set_id = 0x0000 | ((uint16_t) octet) << 2;
// octet = *(buf + decoded_size);
// decoded_size++;
DECODE_U8(buf + decoded_size, octet, decoded_size);
_5g_s_tmsi_tmp.amf_set_id |= (octet & 0xc0) >> 6;
_5g_s_tmsi_tmp.amf_pointer = octet & 0x3f;
// 5G TMSI
uint32_t tmsi = 0; uint32_t tmsi = 0;
DECODE_U32(buf + decoded_size, tmsi, decoded_size);
/*
uint8_t digit[4]; uint8_t digit[4];
octet = *(buf + decoded_size); // octet = *(buf + decoded_size);
decoded_size++; // decoded_size++;
Logger::nas_mm().debug("Octet 0x%x", octet); Logger::nas_mm().debug("Octet 0x%x", octet);
digit[0] = octet; digit[0] = octet;
tmsi |= octet; tmsi |= octet;
octet = *(buf + decoded_size); //octet = *(buf + decoded_size);
decoded_size++; //decoded_size++;
Logger::nas_mm().debug("Octet 0x%x", octet); Logger::nas_mm().debug("Octet 0x%x", octet);
digit[1] = octet; digit[1] = octet;
tmsi |= octet << 8; tmsi |= octet << 8;
octet = *(buf + decoded_size); //octet = *(buf + decoded_size);
decoded_size++; //decoded_size++;
Logger::nas_mm().debug("Octet 0x%x", octet); Logger::nas_mm().debug("Octet 0x%x", octet);
digit[2] = octet; digit[2] = octet;
tmsi |= octet << 16; tmsi |= octet << 16;
octet = *(buf + decoded_size); //octet = *(buf + decoded_size);
decoded_size++; //decoded_size++;
Logger::nas_mm().debug("Octet 0x%x", octet); Logger::nas_mm().debug("Octet 0x%x", octet);
digit[3] = octet; digit[3] = octet;
tmsi |= octet << 24; tmsi |= octet << 24;
_5g_s_tmsi->_5g_tmsi = conv::tmsi_to_string(tmsi); */
_5g_s_tmsi_tmp._5g_tmsi = conv::tmsi_to_string(tmsi);
_5g_s_tmsi = std::optional<_5G_S_TMSI_t>(_5g_s_tmsi_tmp);
return decoded_size; return decoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool _5GSMobileIdentity::get5G_S_TMSI( bool _5GSMobileIdentity::get5G_S_TMSI(
uint16_t& amfSetId, uint8_t& amfPointer, string& tmsi) { uint16_t& amfSetId, uint8_t& amfPointer, string& tmsi) {
if (!_5g_s_tmsi) return false; if (!_5g_s_tmsi.has_value()) return false;
amfSetId = _5g_s_tmsi->amf_set_id; amfSetId = _5g_s_tmsi.value().amf_set_id;
amfPointer = _5g_s_tmsi->amf_pointer; amfPointer = _5g_s_tmsi.value().amf_pointer;
tmsi = _5g_s_tmsi->_5g_tmsi; tmsi = _5g_s_tmsi.value()._5g_tmsi;
return true; return true;
} }
...@@ -198,7 +188,7 @@ void _5GSMobileIdentity::set5GGUTI( ...@@ -198,7 +188,7 @@ void _5GSMobileIdentity::set5GGUTI(
void _5GSMobileIdentity::get5GGUTI(std::optional<_5G_GUTI_t>& guti) const { void _5GSMobileIdentity::get5GGUTI(std::optional<_5G_GUTI_t>& guti) const {
guti = _5g_guti; guti = _5g_guti;
} }
/*
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void _5GSMobileIdentity::setSuciWithSupiImsi( void _5GSMobileIdentity::setSuciWithSupiImsi(
const string& mcc, const string& mnc, const string& routingInd, const string& mcc, const string& mnc, const string& routingInd,
...@@ -214,6 +204,33 @@ void _5GSMobileIdentity::setSuciWithSupiImsi( ...@@ -214,6 +204,33 @@ void _5GSMobileIdentity::setSuciWithSupiImsi(
supi_format_imsi_tmp.msin = msin_digits; supi_format_imsi_tmp.msin = msin_digits;
supi_format_imsi = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp); supi_format_imsi = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp);
} }
*/
//------------------------------------------------------------------------------
void _5GSMobileIdentity::setSuciWithSupiImsi(
const string mcc, const string mnc, const string routingInd,
uint8_t protection_sch_id, const string msin) {
// TODO: Set SUCI...
SUCI_imsi_t supi_format_imsi_tmp = {};
iei = 0;
typeOfIdentity = SUCI;
supi_format_imsi_tmp.supi_format = SUPI_FORMAT_IMSI;
supi_format_imsi_tmp.mcc = mcc;
supi_format_imsi_tmp.mnc = mnc;
supi_format_imsi_tmp.routingIndicator = routingInd;
supi_format_imsi_tmp.protectionSchemeId = protection_sch_id;
supi_format_imsi_tmp.homeNetworkPKI = HOME_NETWORK_PKI_0_WHEN_PSI_0;
supi_format_imsi_tmp.msin = msin;
length = 10 + ceil(msin.length() / 2);
supi_format_imsi = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp);
// Clear the other types
_5g_s_tmsi = std::nullopt;
_5g_guti = std::nullopt;
_imei = std::nullopt;
_IMEISV = std::nullopt;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void _5GSMobileIdentity::setSuciWithSupiImsi( void _5GSMobileIdentity::setSuciWithSupiImsi(
...@@ -225,6 +242,7 @@ void _5GSMobileIdentity::setSuciWithSupiImsi( ...@@ -225,6 +242,7 @@ void _5GSMobileIdentity::setSuciWithSupiImsi(
supi_format_imsi_tmp.mcc = mcc; supi_format_imsi_tmp.mcc = mcc;
supi_format_imsi_tmp.mnc = mnc; supi_format_imsi_tmp.mnc = mnc;
supi_format_imsi = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp); supi_format_imsi = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp);
// TODO: clear the other types
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -238,9 +256,6 @@ bool _5GSMobileIdentity::getSuciWithSupiImsi(SUCI_imsi_t& ptr) { ...@@ -238,9 +256,6 @@ bool _5GSMobileIdentity::getSuciWithSupiImsi(SUCI_imsi_t& ptr) {
void _5GSMobileIdentity::setIMEISV(const IMEISV_t& imeisv) { void _5GSMobileIdentity::setIMEISV(const IMEISV_t& imeisv) {
typeOfIdentity = IMEISV; typeOfIdentity = IMEISV;
// TODO: clear the other types // TODO: clear the other types
// imei_imeisv->odd_even_indic = 1;
// imei_imeisv->identity = ((uint8_t*)imeisv.identity->data[0] & 0xf0) >> 4;
length = blength(imeisv.identity) - 1 + 4; length = blength(imeisv.identity) - 1 + 4;
IMEISV_t IMEISV_tmp = {}; IMEISV_t IMEISV_tmp = {};
IMEISV_tmp.identity = bstrcpy(imeisv.identity); IMEISV_tmp.identity = bstrcpy(imeisv.identity);
......
...@@ -81,55 +81,61 @@ class _5GSMobileIdentity { ...@@ -81,55 +81,61 @@ class _5GSMobileIdentity {
_5GSMobileIdentity( _5GSMobileIdentity(
uint8_t _iei, const uint16_t amfSetId, const uint8_t amfPointer, uint8_t _iei, const uint16_t amfSetId, const uint8_t amfPointer,
const string tmsi); // 5G-S-TMSI const string tmsi); // 5G-S-TMSI
_5GSMobileIdentity(
const string mcc, const string mnc, const string routingInd,
uint8_t protection_sch_id,
const string msin); // TODO: SetSUCI, SUCI and SUPI format IMSI
_5GSMobileIdentity(); _5GSMobileIdentity();
~_5GSMobileIdentity(); ~_5GSMobileIdentity();
// Common
uint8_t getTypeOfIdentity() const { return typeOfIdentity; }; uint8_t getTypeOfIdentity() const { return typeOfIdentity; };
void setIEI(uint8_t _iei); void setIEI(uint8_t _iei);
int encode2Buffer(uint8_t* buf, int len); int encode2Buffer(uint8_t* buf, int len);
int _5g_guti_encode2buffer(uint8_t* buf, int len); int decodeFromBuffer(uint8_t* buf, int len, bool is_option);
int suci_encode2buffer(uint8_t* buf, int len);
int encodeMccMnc2buffer( int encodeMccMnc2buffer(
const std::string& mcc_str, const std::string& mnc_str, uint8_t* buf); const std::string& mcc_str, const std::string& mnc_str, uint8_t* buf);
int encodeRoutid2buffer(string routid, uint8_t* buf); // 5G GUTI
int encodeMSIN2buffer(string msinstr, uint8_t* buf);
int _5g_s_tmsi_encode2buffer(uint8_t* buf, int len);
int _5g_s_tmsi_decodefrombuffer(uint8_t* buf, int len);
int imeisv_encode2buffer(uint8_t* buf, int len);
int imeisv_decodefrombuffer(uint8_t* buf, int len);
int decodeFromBuffer(uint8_t* buf, int len, bool is_option);
int suci_decodefrombuffer(uint8_t* buf, int len, int length);
int _5g_guti_decodefrombuffer(uint8_t* buf, int len); int _5g_guti_decodefrombuffer(uint8_t* buf, int len);
int _5g_guti_encode2buffer(uint8_t* buf, int len);
void set5GGUTI( void set5GGUTI(
const string& mcc, const string& mnc, const uint8_t& amf_region_id, const string& mcc, const string& mnc, const uint8_t& amf_region_id,
const uint16_t& amf_set_id, const uint8_t& amf_pointer, const uint16_t& amf_set_id, const uint8_t& amf_pointer,
const uint32_t& _5g_tmsi); const uint32_t& _5g_tmsi);
void get5GGUTI(std::optional<_5G_GUTI_t>&) const; void get5GGUTI(std::optional<_5G_GUTI_t>&) const;
// SUCI
int suci_decodefrombuffer(uint8_t* buf, int len, int length);
int suci_encode2buffer(uint8_t* buf, int len);
void setSuciWithSupiImsi(
const string mcc, const string mnc, const string routingInd,
uint8_t protection_sch_id,
const string msin); // TODO: SetSUCI, SUCI and SUPI format IMSI
void setSuciWithSupiImsi( void setSuciWithSupiImsi(
const string& mcc, const string& mnc, const string& routingInd, const string& mcc, const string& mnc, const string& routingInd,
uint8_t protecSchId, uint8_t home_pki, const string& msin_digits); uint8_t protecSchId, uint8_t home_pki, const string& msin_digits);
/*
void setSuciWithSupiImsi( void setSuciWithSupiImsi(
const string& mcc, const string& mnc, const string& routingInd, const string& mcc, const string& mnc, const string& routingInd,
uint8_t protecSchId, const string& msin_digits); uint8_t protecSchId, const string& msin_digits);
*/
bool getSuciWithSupiImsi(SUCI_imsi_t&); bool getSuciWithSupiImsi(SUCI_imsi_t&);
int encodeRoutid2buffer(string routid, uint8_t* buf);
int encodeMSIN2buffer(string msinstr, uint8_t* buf);
// TMSI
int _5g_s_tmsi_encode2buffer(uint8_t* buf, int len);
int _5g_s_tmsi_decodefrombuffer(uint8_t* buf, int len);
bool get5G_S_TMSI(uint16_t& amfSetId, uint8_t& amfPointer, string& tmsi); bool get5G_S_TMSI(uint16_t& amfSetId, uint8_t& amfPointer, string& tmsi);
// IMEISV
int imeisv_encode2buffer(uint8_t* buf, int len);
int imeisv_decodefrombuffer(uint8_t* buf, int len);
void setIMEISV(const IMEISV_t& imeisv); void setIMEISV(const IMEISV_t& imeisv);
bool getIMEISV(IMEISV_t& imeisv); bool getIMEISV(IMEISV_t& imeisv);
...@@ -143,8 +149,7 @@ class _5GSMobileIdentity { ...@@ -143,8 +149,7 @@ class _5GSMobileIdentity {
std::optional<IMEI_IMEISV_t> _imei; // TODO: std::optional<IMEI_IMEISV_t> _imei; // TODO:
std::optional<IMEISV_t> _IMEISV; std::optional<IMEISV_t> _IMEISV;
_5G_S_TMSI_t* _5g_s_tmsi; std::optional<_5G_S_TMSI_t> _5g_s_tmsi;
bool is_no_identity;
}; };
} // namespace nas } // namespace nas
......
...@@ -105,8 +105,9 @@ void DeregistrationRequest::setSUCI_SUPI_format_IMSI( ...@@ -105,8 +105,9 @@ void DeregistrationRequest::setSUCI_SUPI_format_IMSI(
"protection scheme"); "protection scheme");
return; return;
} else { } else {
ie_5gs_mobility_id = ie_5gs_mobility_id = new _5GSMobileIdentity();
new _5GSMobileIdentity(mcc, mnc, routingInd, protection_sch_id, msin); ie_5gs_mobility_id->setSuciWithSupiImsi(
mcc, mnc, routingInd, protection_sch_id, msin);
} }
} }
......
...@@ -60,8 +60,9 @@ void IdentityResponse::setSUCI_SUPI_format_IMSI( ...@@ -60,8 +60,9 @@ void IdentityResponse::setSUCI_SUPI_format_IMSI(
"interface"); "interface");
return; return;
} else { } else {
ie_mobility_id = ie_mobility_id = new _5GSMobileIdentity();
new _5GSMobileIdentity(mcc, mnc, routingInd, protection_sch_id, msin); ie_mobility_id->setSuciWithSupiImsi(
mcc, mnc, routingInd, protection_sch_id, msin);
} }
} }
......
...@@ -94,8 +94,9 @@ void RegistrationAccept::setSUCI_SUPI_format_IMSI( ...@@ -94,8 +94,9 @@ void RegistrationAccept::setSUCI_SUPI_format_IMSI(
"interface"); "interface");
return; return;
} else { } else {
ie_5g_guti = ie_5g_guti = new _5GSMobileIdentity();
new _5GSMobileIdentity(mcc, mnc, routingInd, protection_sch_id, msin); ie_5g_guti->setSuciWithSupiImsi(
mcc, mnc, routingInd, protection_sch_id, msin);
ie_5g_guti->setIEI(0x77); ie_5g_guti->setIEI(0x77);
} }
} }
......
...@@ -104,8 +104,9 @@ void RegistrationRequest::setSUCI_SUPI_format_IMSI( ...@@ -104,8 +104,9 @@ void RegistrationRequest::setSUCI_SUPI_format_IMSI(
"interface"); "interface");
return; return;
} else { } else {
ie_5gs_mobility_id = ie_5gs_mobility_id = new _5GSMobileIdentity();
new _5GSMobileIdentity(mcc, mnc, routingInd, protection_sch_id, msin); ie_5gs_mobility_id->setSuciWithSupiImsi(
mcc, mnc, routingInd, protection_sch_id, msin);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment