Commit 2eb11954 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Address build/clang-format warning

parent ff6ce4a4
......@@ -29,6 +29,8 @@
#ifndef FILE_3GPP_24_501_H_SEEN
#define FILE_3GPP_24_501_H_SEEN
#include <netinet/in.h>
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -220,7 +220,7 @@ void xgpp_conv::sm_context_create_from_openapi(
"PDU Session ID %d", context_data.getPduSessionId());
pcr.set_pdu_session_id(context_data.getPduSessionId());
} else {
Logger::smf_app().warn("No PDU Session ID available");
Logger::smf_app().warn("No PDU Session ID available");
}
// AMF ID (ServingNFId/NfInstanceId)
......
......@@ -48,7 +48,7 @@ int decode_bstring(
*bstr = blk2bstr(buffer, pdulen);
return pdulen;
} else {
*bstr = NULL;
if (bstr) *bstr = NULL;
return TLV_BUFFER_TOO_SHORT;
}
}
......
......@@ -2475,6 +2475,7 @@ bstring bjoinblk(const struct bstrList* bl, const void* blk, int len) {
* NULL is returned, otherwise a bstring with the correct result is returned.
*/
bstring bjoin(const struct bstrList* bl, const_bstring sep) {
if (sep == NULL) return NULL;
if (sep != NULL && (sep->slen < 0 || sep->data == NULL)) return NULL;
return bjoinblk(bl, sep->data, sep->slen);
}
......
......@@ -269,7 +269,6 @@
pLMN.mnc_digit2 * 10 + pLMN.mnc_digit1; \
} while (0)
/*
* TS 36.413 v10.9.0 section 9.2.1.37:
* Macro eNB ID:
......
......@@ -55,7 +55,8 @@ class conv {
static void hexa_to_ascii(uint8_t* from, char* to, size_t length);
static int ascii_to_hex(uint8_t* dst, const char* h);
static struct in_addr fromString(const std::string addr4);
static bool plmnFromString(plmn_t& p, const std::string mcc, const std::string mnc);
static bool plmnFromString(
plmn_t& p, const std::string mcc, const std::string mnc);
static std::string toString(const struct in_addr& inaddr);
static std::string toString(const struct in6_addr& in6addr);
static std::string mccToString(
......
......@@ -83,9 +83,7 @@ unsigned char* mime_parser::format_string_as_hex(const std::string& str) {
unsigned char* data_hex = (uint8_t*) malloc(str_len / 2 + 1);
conv::ascii_to_hex(data_hex, (const char*) data);
Logger::smf_app().debug(
"Input string (%d bytes): %s ", str_len,
str.c_str());
Logger::smf_app().debug("Input string (%d bytes): %s ", str_len, str.c_str());
Logger::smf_app().debug("Data (formatted):");
#if DEBUG_IS_ON
for (int i = 0; i < str_len / 2; i++) printf(" %02x ", data_hex[i]);
......
......@@ -37,7 +37,7 @@ typedef struct {
uint8_t spare : 5;
uint8_t pdu_session_type_value : 3;
bstring pdu_address_information;
} __attribute__((__packed__)) PDUAddress;
} PDUAddress;
int encode_pdu_address(
PDUAddress pduaddress, uint8_t iei, uint8_t* buffer, uint32_t len);
......
......@@ -214,8 +214,7 @@ int decode_qos_rules(
qosrulesie->packetfilterlist.create_modifyandadd_modifyandreplace[j]
.packetfilteridentifier = bitstream & 0x0f;
uint8_t lenghtofpacketfiltercontents =
*(buffer + decoded) - 1;
uint8_t lenghtofpacketfiltercontents = *(buffer + decoded) - 1;
decoded++;
DECODE_U8(buffer + decoded, bitstream, decoded);
......@@ -306,8 +305,7 @@ int decode_qos_rules(
.packetfilterlist.create_modifyandadd_modifyandreplace[j]
.packetfilteridentifier = bitstream & 0x0f;
uint8_t lenghtofpacketfiltercontents =
*(buffer + decoded) - 1;
uint8_t lenghtofpacketfiltercontents = *(buffer + decoded) - 1;
decoded++;
DECODE_U8(buffer + decoded, bitstream, decoded);
......
......@@ -75,7 +75,7 @@
typedef struct {
uint8_t spare : 4;
uint8_t packetfilteridentifier : 4;
} __attribute__((__packed__)) ModifyAndDelete;
} ModifyAndDelete;
typedef struct {
uint8_t component_type;
......@@ -89,7 +89,7 @@ typedef struct {
uint8_t lenghtofpacketfiltercontents;
PacketFilterContents packetfiltercontents;
} __attribute__((__packed__)) Create_ModifyAndAdd_ModifyAndReplace;
} Create_ModifyAndAdd_ModifyAndReplace;
typedef struct {
uint8_t qosruleidentifer;
......@@ -106,7 +106,7 @@ typedef struct {
uint8_t spare : 1;
uint8_t segregation : 1;
uint8_t qosflowidentifer : 6;
} __attribute__((__packed__)) QOSRulesIE;
} QOSRulesIE;
typedef struct {
uint16_t lengthofqosrulesie;
......
......@@ -31,30 +31,17 @@ int encode_security_header_type(
SecurityHeaderType securityheadertype, uint8_t iei, uint8_t* buffer,
uint32_t len) {
uint32_t encoded = 0;
int encode_result;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(
buffer, SECURITY_HEADER_TYPE_MINIMUM_LENGTH, len);
if ((encode_result = encode_bstring(
securityheadertype, buffer + encoded, len - encoded)) < 0)
return encode_result;
else
encoded += encode_result;
ENCODE_U8(buffer + encoded, securityheadertype, encoded);
return encoded;
}
int decode_security_header_type(
SecurityHeaderType* securityheadertype, uint8_t iei, uint8_t* buffer,
uint32_t len) {
int decoded = 0;
uint8_t ielen = 0;
int decode_result;
if ((decode_result = decode_bstring(
securityheadertype, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
int decoded = 0;
DECODE_U8(buffer + decoded, *securityheadertype, decoded);
return decoded;
}
......@@ -64,7 +64,6 @@ int decode__5gs_mobile_identity(
uint32_t len) {
int decoded = 0;
uint8_t ielen = 0;
int decode_result;
if (iei > 0) {
CHECK_IEI_DECODER(iei, *buffer);
......@@ -76,11 +75,15 @@ int decode__5gs_mobile_identity(
ielen = (ielen << 8) + *(buffer + decoded);
decoded++;
CHECK_LENGTH_DECODER(len - decoded, ielen);
/*
int decode_result;
//TODO: to be updated
if ((decode_result = decode_bstring(
_5gsmobileidentity, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
if ((decode_result = decode_bstring(
_5gsmobileidentity, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
*/
return decoded;
}
......@@ -36,7 +36,7 @@ int encode__pdu_session_type(
buffer, _PDU_SESSION_TYPE_MINIMUM_LENGTH, len);
if (iei > 0) {
bitStream |= (iei & 0xf0) ;
bitStream |= (iei & 0xf0);
}
bitStream |= ((_pdusessiontype.pdu_session_type_value & 0x07) | 0x10);
......
......@@ -447,99 +447,6 @@ static int _nas_message_encrypt(
unsigned char* dest, const unsigned char* src, uint8_t security_header_type,
uint32_t code, uint8_t seq, int const direction, size_t length,
fivegmm_security_context_t* const fivegmm_security_context) {
nas_stream_cipher_t stream_cipher = {0};
uint32_t count = 0;
if (!fivegmm_security_context) {
// OAILOG_ERROR(LOG_NAS, "No security context set for encryption protection
// algorithm\n"); OAILOG_FUNC_RETURN (LOG_NAS, 0);
}
switch (security_header_type) {
case SECURITY_HEADER_TYPE_NOT_PROTECTED:
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED:
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_NEW:
// OAILOG_DEBUG (LOG_NAS, "No encryption of message according to security
// header type 0x%02x\n", security_header_type);
memcpy(dest, src, length);
break;
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_CYPHERED:
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_CYPHERED_NEW:
switch (fivegmm_security_context->selected_algorithms.encryption) {
case NAS_SECURITY_ALGORITHMS_NEA1: {
if (direction == SECU_DIRECTION_UPLINK) {
count = 0x00000000 |
((fivegmm_security_context->ul_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->ul_count.seq_num & 0x000000FF);
} else {
count = 0x00000000 |
((fivegmm_security_context->dl_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->dl_count.seq_num & 0x000000FF);
}
stream_cipher.key = fivegmm_security_context->knas_enc;
stream_cipher.key_length = AUTH_KNAS_ENC_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00; // 33.401 section 8.1.1
stream_cipher.direction = direction;
stream_cipher.message = (uint8_t*) src;
/*
* length in bits
*/
stream_cipher.blength = length << 3;
// If the test or use encrypt opens the next line,otherwise close
// nas_stream_encrypt_nea1 (&stream_cipher, (uint8_t*)dest);
// OAILOG_FUNC_RETURN (LOG_NAS, length);
// Open the next line without testing or using encryption,otherwise
// close
memcpy(dest, src, length);
return length;
} break;
case NAS_SECURITY_ALGORITHMS_NEA2: {
if (direction == SECU_DIRECTION_UPLINK) {
count = 0x00000000 |
((fivegmm_security_context->ul_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->ul_count.seq_num & 0x000000FF);
} else {
count = 0x00000000 |
((fivegmm_security_context->dl_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->dl_count.seq_num & 0x000000FF);
}
stream_cipher.key = fivegmm_security_context->knas_enc;
stream_cipher.key_length = AUTH_KNAS_ENC_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00;
stream_cipher.direction = direction;
stream_cipher.message = (uint8_t*) src;
/*
* length in bits
*/
stream_cipher.blength = length << 3;
// nas_stream_encrypt_nea2 (&stream_cipher, (uint8_t*)dest);
// OAILOG_FUNC_RETURN (LOG_NAS, length);
} break;
case NAS_SECURITY_ALGORITHMS_NEA0: {
memcpy(dest, src, length);
// OAILOG_FUNC_RETURN (LOG_NAS, length);
} break;
default: {
// OAILOG_ERROR(LOG_NAS, "Unknown Cyphering protection algorithm
// %d\n", fivegmm_security_context->selected_algorithms.encryption);
} break;
}
break;
default: {
// OAILOG_ERROR(LOG_NAS, "Unknown security header type %u\n",
// security_header_type);
// OAILOG_FUNC_RETURN (LOG_NAS, 0);
} break;
}
return length;
}
......@@ -552,79 +459,6 @@ static uint32_t _nas_message_get_mac(
return 0;
}
switch (fivegmm_security_context->selected_algorithms.integrity) {
case NAS_SECURITY_ALGORITHMS_NIA1: {
uint8_t mac[4];
nas_stream_cipher_t stream_cipher = {0};
uint32_t count;
uint32_t* mac32;
if (direction == SECU_DIRECTION_UPLINK) {
count =
0x00000000 |
((fivegmm_security_context->ul_count.overflow & 0x0000FFFF) << 8) |
(fivegmm_security_context->ul_count.seq_num & 0x000000FF);
} else {
count =
0x00000000 |
((fivegmm_security_context->dl_count.overflow & 0x0000FFFF) << 8) |
(fivegmm_security_context->dl_count.seq_num & 0x000000FF);
}
stream_cipher.key = fivegmm_security_context->knas_int;
stream_cipher.key_length = AUTH_KNAS_INT_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00; // 33.401 section 8.1.1
stream_cipher.direction = direction;
stream_cipher.message = (uint8_t*) buffer;
/*
* length in bits
*/
stream_cipher.blength = length << 3;
nas_stream_encrypt_nia1(&stream_cipher, mac);
mac32 = (uint32_t*) &mac;
return ntohl(*mac32);
} break;
case NAS_SECURITY_ALGORITHMS_NIA2: {
uint8_t mac[4];
nas_stream_cipher_t stream_cipher = {0};
uint32_t count;
uint32_t* mac32;
if (direction == SECU_DIRECTION_UPLINK) {
count =
0x00000000 |
((fivegmm_security_context->ul_count.overflow & 0x0000FFFF) << 8) |
(fivegmm_security_context->ul_count.seq_num & 0x000000FF);
} else {
count =
0x00000000 |
((fivegmm_security_context->dl_count.overflow & 0x0000FFFF) << 8) |
(fivegmm_security_context->dl_count.seq_num & 0x000000FF);
}
stream_cipher.key = fivegmm_security_context->knas_int;
stream_cipher.key_length = AUTH_KNAS_INT_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00;
stream_cipher.direction = direction;
stream_cipher.message = (uint8_t*) buffer;
/*
* length in bits
*/
stream_cipher.blength = length << 3;
// nas_stream_encrypt_nia2 (&stream_cipher, mac);
mac32 = (uint32_t*) &mac;
// OAILOG_FUNC_RETURN (LOG_NAS, ntohl (*mac32));
} break;
case NAS_SECURITY_ALGORITHMS_NIA0: {
// OAILOG_FUNC_RETURN (LOG_NAS, 0);
} break;
default:
// OAILOG_ERROR(LOG_NAS, "Unknown integrity protection algorithm %d\n",
// fivegmm_security_context->selected_algorithms.integrity);
break;
}
return 0;
}
......@@ -714,161 +548,6 @@ static int _nas_message_decrypt(
uint8_t security_header_type, uint32_t code, uint8_t seq, size_t length,
fivegmm_security_context_t* const fivegmm_security_context,
nas_message_decode_status_t* status) {
nas_stream_cipher_t stream_cipher = {0};
uint32_t count = 0;
uint8_t direction = 0;
int size = 0;
nas_message_security_header_t header = {0};
#if TEST_MAC_ENCRYPT_DECRYPT__
direction = DIRECTION__;
#else
direction = SECU_DIRECTION_UPLINK;
#endif
switch (security_header_type) {
case SECURITY_HEADER_TYPE_NOT_PROTECTED:
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED:
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_NEW:
// OAILOG_DEBUG (LOG_NAS, "No decryption of message length %lu according
// to security header type 0x%02x\n", length, security_header_type);
memcpy(dest, src, length);
break;
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_CYPHERED:
case SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_CYPHERED_NEW:
if (fivegmm_security_context) {
switch (fivegmm_security_context->selected_algorithms.encryption) {
case NAS_SECURITY_ALGORITHMS_NEA1: {
if (0 == status->mac_matched) {
// OAILOG_ERROR(LOG_NAS, "MAC integrity failed\n");
// OAILOG_FUNC_RETURN (LOG_NAS, 0);
}
if (direction == SECU_DIRECTION_UPLINK) {
count =
0x00000000 |
((fivegmm_security_context->ul_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->ul_count.seq_num & 0x000000FF);
} else {
count =
0x00000000 |
((fivegmm_security_context->dl_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->dl_count.seq_num & 0x000000FF);
}
stream_cipher.key = fivegmm_security_context->knas_enc;
stream_cipher.key_length = AUTH_KNAS_ENC_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00;
stream_cipher.direction = direction;
// stream_cipher.message = (uint8_t*)src;
uint8_t* src_encrypt = NULL;
src_encrypt = (uint8_t*) calloc(1, length + 3);
memset(src_encrypt, 0, sizeof(uint8_t));
memcpy(src_encrypt, src, length);
stream_cipher.message = (uint8_t*) src_encrypt;
/*
* length in bits
*/
stream_cipher.blength = length << 3;
memcpy(dest, src, length);
/*
* Decode the first octet (security header type or EPS bearer
* identity,
* * * * and protocol discriminator)
*/
// DECODE_U8 (dest, *(uint8_t *) (&header), size);
// DECODE_U8(dest,header.extended_protocol_discriminator,size);
// DECODE_U8(dest+size,header.security_header_type,size);
// return header.extended_protocol_discriminator;
// OAILOG_FUNC_RETURN (LOG_NAS,
// header.extended_protocol_discriminator);
} break;
case NAS_SECURITY_ALGORITHMS_NEA2: {
if (0 == status->mac_matched) {
// OAILOG_ERROR(LOG_NAS, "MAC integrity failed\n");
// OAILOG_FUNC_RETURN (LOG_NAS, 0);
}
if (direction == SECU_DIRECTION_UPLINK) {
count =
0x00000000 |
((fivegmm_security_context->ul_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->ul_count.seq_num & 0x000000FF);
} else {
count =
0x00000000 |
((fivegmm_security_context->dl_count.overflow && 0x0000FFFF)
<< 8) |
(fivegmm_security_context->dl_count.seq_num & 0x000000FF);
}
stream_cipher.key = fivegmm_security_context->knas_enc;
stream_cipher.key_length = AUTH_KNAS_ENC_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00;
stream_cipher.direction = direction;
stream_cipher.message = (uint8_t*) src;
/*
* length in bits
*/
stream_cipher.blength = length << 3;
// nas_stream_encrypt_nea2 (&stream_cipher, (uint8_t*)dest);
/*
* Decode the first octet (security header type or EPS bearer
* identity, and protocol discriminator)
*/
DECODE_U8(dest, header.extended_protocol_discriminator, size);
DECODE_U8(dest + size, header.security_header_type, size);
// OAILOG_FUNC_RETURN (LOG_NAS,
// header.extended_protocol_discriminator);
} break;
case NAS_SECURITY_ALGORITHMS_NEA0:
// OAILOG_DEBUG (LOG_NAS, "NAS_SECURITY_ALGORITHMS_EEA0 dir %d
// ul_count.seq_num %d dl_count.seq_num %d\n", direction,
// fivegmm_security_context->ul_count.seq_num,
// fivegmm_security_context->dl_count.seq_num);
memcpy(dest, src, length);
/*
* Decode the first octet (security header type or EPS bearer
* identity, and protocol discriminator)
*/
DECODE_U8(dest, header.extended_protocol_discriminator, size);
DECODE_U8(dest + size, header.security_header_type, size);
// OAILOG_FUNC_RETURN (LOG_NAS,
// header.extended_protocol_discriminator);
break;
default:
// OAILOG_ERROR(LOG_NAS, "Unknown Cyphering protection algorithm
// %d\n", fivegmm_security_context->selected_algorithms.encryption);
memcpy(dest, src, length);
/*
* Decode the first octet (security header type or EPS bearer
* identity,
* * * * and protocol discriminator)
*/
DECODE_U8(dest, header.extended_protocol_discriminator, size);
DECODE_U8(dest + size, header.security_header_type, size);
// OAILOG_FUNC_RETURN (LOG_NAS,
// header.extended_protocol_discriminator);
break;
}
} else {
// OAILOG_ERROR(LOG_NAS, "No security context\n");
// OAILOG_FUNC_RETURN (LOG_NAS, 0);
}
break;
default: {
}
// OAILOG_ERROR(LOG_NAS, "Unknown security header type %u",
// security_header_type); OAILOG_FUNC_RETURN (LOG_NAS, 0);
};
return 0;
}
......
......@@ -215,7 +215,6 @@ int encode_pdu_session_establishment_accept(
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(
buffer, PDU_SESSION_ESTABLISHMENT_ACCEPT_MINIMUM_LENGTH, len);
if ((encoded_result = encode__pdu_session_type(
pdu_session_establishment_accept->_pdusessiontype, 0,
buffer + encoded, len - encoded)) < 0)
......
This diff is collapsed.
......@@ -5,17 +5,17 @@
#ifndef ASN_TYPE_ANY_H
#define ASN_TYPE_ANY_H
#include <OCTET_STRING.h> /* Implemented via OCTET STRING type */
#include <OCTET_STRING.h> /* Implemented via OCTET STRING type */
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ANY {
uint8_t *buf; /* BER-encoded ANY contents */
int size; /* Size of the above buffer */
uint8_t* buf; /* BER-encoded ANY contents */
int size; /* Size of the above buffer */
asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
} ANY_t;
extern asn_TYPE_descriptor_t asn_DEF_ANY;
......@@ -32,34 +32,34 @@ per_type_encoder_f ANY_encode_uper;
per_type_decoder_f ANY_decode_aper;
per_type_encoder_f ANY_encode_aper;
#define ANY_free OCTET_STRING_free
#define ANY_print OCTET_STRING_print
#define ANY_compare OCTET_STRING_compare
#define ANY_constraint asn_generic_no_constraint
#define ANY_decode_ber OCTET_STRING_decode_ber
#define ANY_encode_der OCTET_STRING_encode_der
#define ANY_decode_xer OCTET_STRING_decode_xer_hex
#define ANY_free OCTET_STRING_free
#define ANY_print OCTET_STRING_print
#define ANY_compare OCTET_STRING_compare
#define ANY_constraint asn_generic_no_constraint
#define ANY_decode_ber OCTET_STRING_decode_ber
#define ANY_encode_der OCTET_STRING_encode_der
#define ANY_decode_xer OCTET_STRING_decode_xer_hex
/******************************
* Handy conversion routines. *
******************************/
/* Convert another ASN.1 type into the ANY. This implies DER encoding. */
int ANY_fromType(ANY_t *, asn_TYPE_descriptor_t *td, void *struct_ptr);
int ANY_fromType_aper(ANY_t *st, asn_TYPE_descriptor_t *td, void *sptr);
ANY_t *ANY_new_fromType(asn_TYPE_descriptor_t *td, void *struct_ptr);
ANY_t *ANY_new_fromType_aper(asn_TYPE_descriptor_t *td, void *sptr);
int ANY_fromType(ANY_t*, asn_TYPE_descriptor_t* td, void* struct_ptr);
int ANY_fromType_aper(ANY_t* st, asn_TYPE_descriptor_t* td, void* sptr);
ANY_t* ANY_new_fromType(asn_TYPE_descriptor_t* td, void* struct_ptr);
ANY_t* ANY_new_fromType_aper(asn_TYPE_descriptor_t* td, void* sptr);
/* Convert the contents of the ANY type into the specified type. */
int ANY_to_type(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr);
int ANY_to_type_aper(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr);
int ANY_to_type(ANY_t*, asn_TYPE_descriptor_t* td, void** struct_ptr);