Clang-formated liblte_*

master
Pedro Alvarez 6 years ago committed by Andre Puschmann
parent b46a71c2d8
commit 9597cc4c14

@ -40,8 +40,8 @@
INCLUDES
*******************************************************************************/
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -53,38 +53,40 @@
#define LIBLTE_ASN1_OID_MAXSUBIDS 128
// Caution these values must match SRSLTE_ ones in common.h
#define LIBLTE_MAX_MSG_SIZE_BITS 102048
#define LIBLTE_MAX_MSG_SIZE_BITS 102048
#define LIBLTE_MAX_MSG_SIZE_BYTES 12756
#define LIBLTE_MSG_HEADER_OFFSET 1020
#define LIBLTE_MSG_HEADER_OFFSET 1020
//Macro to make it easier to convert defines into strings
#define LIBLTE_CASE_STR(code) case code: return #code
// Macro to make it easier to convert defines into strings
#define LIBLTE_CASE_STR(code) \
case code: \
return #code
/*******************************************************************************
TYPEDEFS
*******************************************************************************/
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef enum{
typedef enum {
LIBLTE_SUCCESS = 0,
LIBLTE_ERROR_INVALID_INPUTS,
LIBLTE_ERROR_ENCODE_FAIL,
LIBLTE_ERROR_DECODE_FAIL,
LIBLTE_ERROR_INVALID_CRC,
LIBLTE_ERROR_N_ITEMS
}LIBLTE_ERROR_ENUM;
} LIBLTE_ERROR_ENUM;
static const char liblte_error_text[LIBLTE_ERROR_N_ITEMS][64] = {
"Invalid inputs",
"Encode failure",
"Decode failure",
"Invalid inputs",
"Encode failure",
"Decode failure",
};
#define LIBLTE_STRING_LEN 128
@ -92,27 +94,26 @@ static const char liblte_error_text[LIBLTE_ERROR_N_ITEMS][64] = {
typedef void* LIBLTE_ASN1_OPEN_TYPE_STRUCT;
typedef struct {
uint32_t numids; // number of subidentifiers
uint32_t subid[LIBLTE_ASN1_OID_MAXSUBIDS]; // subidentifier values
uint32_t numids; // number of subidentifiers
uint32_t subid[LIBLTE_ASN1_OID_MAXSUBIDS]; // subidentifier values
} LIBLTE_ASN1_OID_STRUCT;
typedef struct{
bool data_valid;
bool data;
}LIBLTE_BOOL_MSG_STRUCT;
typedef struct{
uint32 N_bits;
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BITS];
}LIBLTE_BIT_MSG_STRUCT __attribute__ ((aligned (8)));
typedef struct {
bool data_valid;
bool data;
} LIBLTE_BOOL_MSG_STRUCT;
typedef struct{
uint32 N_bytes;
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BYTES];
}LIBLTE_BYTE_MSG_STRUCT;
typedef struct {
uint32 N_bits;
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BITS];
} LIBLTE_BIT_MSG_STRUCT __attribute__((aligned(8)));
typedef struct {
uint32 N_bytes;
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
uint8 msg[LIBLTE_MAX_MSG_SIZE_BYTES];
} LIBLTE_BYTE_MSG_STRUCT;
/*******************************************************************************
DECLARATIONS
@ -123,54 +124,49 @@ typedef struct{
Description: Converts a value to a bit string
*********************************************************************/
void liblte_value_2_bits(uint32 value,
uint8 **bits,
uint32 N_bits);
void liblte_value_2_bits(uint32 value, uint8** bits, uint32 N_bits);
/*********************************************************************
Name: liblte_bits_2_value
Description: Converts a bit string to a value
*********************************************************************/
uint32 liblte_bits_2_value(uint8 **bits,
uint32 N_bits);
uint32 liblte_bits_2_value(uint8** bits, uint32 N_bits);
/*********************************************************************
Name: liblte_pack
Description: Pack a bit array into a byte array
*********************************************************************/
void liblte_pack(LIBLTE_BIT_MSG_STRUCT *bits,
LIBLTE_BYTE_MSG_STRUCT *bytes);
void liblte_pack(LIBLTE_BIT_MSG_STRUCT* bits, LIBLTE_BYTE_MSG_STRUCT* bytes);
/*********************************************************************
Name: liblte_unpack
Description: Unpack a byte array into a bit array
*********************************************************************/
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT *bytes,
LIBLTE_BIT_MSG_STRUCT *bits);
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT* bytes, LIBLTE_BIT_MSG_STRUCT* bits);
/*********************************************************************
Name: liblte_pack
Description: Pack a bit array into a byte array
*********************************************************************/
void liblte_pack(uint8_t *bits, uint32_t n_bits, uint8_t *bytes);
void liblte_pack(uint8_t* bits, uint32_t n_bits, uint8_t* bytes);
/*********************************************************************
Name: liblte_unpack
Description: Unpack a byte array into a bit array
*********************************************************************/
void liblte_unpack(uint8_t *bytes, uint32_t n_bytes, uint8_t *bits);
void liblte_unpack(uint8_t* bytes, uint32_t n_bytes, uint8_t* bits);
/*********************************************************************
Name: liblte_align_up
Description: Aligns a pointer to a multibyte boundary
*********************************************************************/
void liblte_align_up(uint8_t **ptr, uint32_t align);
void liblte_align_up(uint8_t** ptr, uint32_t align);
/*********************************************************************
Name: liblte_align_up_zero
@ -178,6 +174,6 @@ void liblte_align_up(uint8_t **ptr, uint32_t align);
Description: Aligns a pointer to a multibyte boundary and zeros
bytes skipped
*********************************************************************/
void liblte_align_up_zero(uint8_t **ptr, uint32_t align);
void liblte_align_up_zero(uint8_t** ptr, uint32_t align);
#endif // SRSLTE_LIBLTE_COMMON_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -42,12 +42,10 @@
DEFINES
*******************************************************************************/
/*******************************************************************************
TYPEDEFS
*******************************************************************************/
/*******************************************************************************
DECLARATIONS
*******************************************************************************/
@ -59,9 +57,7 @@
Document Reference: 35.206 v10.0.0 Annex 3
*********************************************************************/
LIBLTE_ERROR_ENUM liblte_compute_opc(uint8 *k,
uint8 *op,
uint8 *op_c);
LIBLTE_ERROR_ENUM liblte_compute_opc(uint8* k, uint8* op, uint8* op_c);
/*********************************************************************
Name: liblte_security_generate_k_asme
@ -74,13 +70,8 @@ LIBLTE_ERROR_ENUM liblte_compute_opc(uint8 *k,
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_asme(uint8 *ck,
uint8 *ik,
uint8 *ak,
uint8 *sqn,
uint16 mcc,
uint16 mnc,
uint8 *k_asme);
LIBLTE_ERROR_ENUM
liblte_security_generate_k_asme(uint8* ck, uint8* ik, uint8* ak, uint8* sqn, uint16 mcc, uint16 mnc, uint8* k_asme);
/*********************************************************************
Name: liblte_security_generate_k_enb
@ -93,18 +84,11 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_asme(uint8 *ck,
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_enb(uint8 *k_asme,
uint32 nas_count,
uint8 *k_enb);
LIBLTE_ERROR_ENUM liblte_security_generate_k_enb(uint8* k_asme, uint32 nas_count, uint8* k_enb);
LIBLTE_ERROR_ENUM liblte_security_generate_k_enb_star(uint8 *k_enb,
uint32 pci,
uint32_t earfcn,
uint8 *k_enb_star);
LIBLTE_ERROR_ENUM liblte_security_generate_k_enb_star(uint8* k_enb, uint32 pci, uint32_t earfcn, uint8* k_enb_star);
LIBLTE_ERROR_ENUM liblte_security_generate_nh( uint8_t *k_asme,
uint8_t *sync,
uint8_t *nh);
LIBLTE_ERROR_ENUM liblte_security_generate_nh(uint8_t* k_asme, uint8_t* sync, uint8_t* nh);
/*********************************************************************
Name: liblte_security_generate_k_nas
@ -115,33 +99,29 @@ LIBLTE_ERROR_ENUM liblte_security_generate_nh( uint8_t *k_asme,
*********************************************************************/
// Defines
// Enums
typedef enum{
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_EEA0 = 0,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA1,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA2,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS,
}LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM;
static const char liblte_security_ciphering_algorithm_id_text[LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS][20] = {"EEA0",
"128-EEA1",
"128-EEA2"};
typedef enum{
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_EIA0 = 0,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA1,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA2,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS,
}LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM;
static const char liblte_security_integrity_algorithm_id_text[LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {"EIA0",
"128-EIA1",
"128-EIA2"};
typedef enum {
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_EEA0 = 0,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA1,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_128_EEA2,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS,
} LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM;
static const char liblte_security_ciphering_algorithm_id_text[LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS][20] = {
"EEA0", "128-EEA1", "128-EEA2"};
typedef enum {
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_EIA0 = 0,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA1,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA2,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS,
} LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM;
static const char liblte_security_integrity_algorithm_id_text[LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {
"EIA0", "128-EIA1", "128-EIA2"};
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8 *k_asme,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8 *k_nas_enc,
uint8 *k_nas_int);
LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8* k_asme,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8* k_nas_enc,
uint8* k_nas_int);
/*********************************************************************
Name: liblte_security_generate_k_rrc
@ -154,11 +134,11 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_rrc(uint8 *k_enb,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8 *k_rrc_enc,
uint8 *k_rrc_int);
LIBLTE_ERROR_ENUM liblte_security_generate_k_rrc(uint8* k_enb,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8* k_rrc_enc,
uint8* k_rrc_int);
/*********************************************************************
Name: liblte_security_generate_k_up
@ -172,11 +152,11 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_rrc(uint8
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8 *k_enb,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8 *k_up_enc,
uint8 *k_up_int);
LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8* k_enb,
LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM enc_alg_id,
LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM int_alg_id,
uint8* k_up_enc,
uint8* k_up_int);
/*********************************************************************
Name: liblte_security_128_eia2
@ -188,24 +168,15 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8
RFC4493
*********************************************************************/
// Defines
#define LIBLTE_SECURITY_DIRECTION_UPLINK 0
#define LIBLTE_SECURITY_DIRECTION_UPLINK 0
#define LIBLTE_SECURITY_DIRECTION_DOWNLINK 1
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
uint8 *msg,
uint32 msg_len,
uint8 *mac);
LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
LIBLTE_BIT_MSG_STRUCT *msg,
uint8 *mac);
LIBLTE_ERROR_ENUM liblte_security_128_eia2(
uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* mac);
LIBLTE_ERROR_ENUM liblte_security_128_eia2(
uint8* key, uint32 count, uint8 bearer, uint8 direction, LIBLTE_BIT_MSG_STRUCT* msg, uint8* mac);
/*********************************************************************
Name: liblte_security_encryption_eea1
@ -217,13 +188,8 @@ LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8 *key,
Specification of the 3GPP Confidentiality and
Integrity Algorithms UEA2 & UIA2 D1 v2.1
*********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
uint8 *msg,
uint32 msg_len,
uint8 *out);
LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(
uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out);
/*********************************************************************
Name: liblte_security_decryption_eea1
@ -235,13 +201,8 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8 *key,
Specification of the 3GPP Confidentiality and
Integrity Algorithms UEA2 & UIA2 D1 v2.1
*********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
uint8 *ct,
uint32 ct_len,
uint8 *out);
LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(
uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out);
/*********************************************************************
Name: liblte_security_encryption_eea2
@ -250,13 +211,8 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(uint8 *key,
Document Reference: 33.401 v13.1.0 Annex B.1.3
*********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
uint8 *msg,
uint32 msg_len,
uint8 *out);
LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(
uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out);
/*********************************************************************
Name: liblte_security_decryption_eea2
@ -265,14 +221,8 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(uint8 *key,
Document Reference: 33.401 v13.1.0 Annex B.1.3
*********************************************************************/
LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(uint8 *key,
uint32 count,
uint8 bearer,
uint8 direction,
uint8 *ct,
uint32 ct_len,
uint8 *out);
LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(
uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out);
/*********************************************************************
Name: liblte_security_milenage_f1
@ -288,12 +238,7 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(uint8 *key,
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f1(uint8 *k,
uint8 *op,
uint8 *rand,
uint8 *sqn,
uint8 *amf,
uint8 *mac_a);
LIBLTE_ERROR_ENUM liblte_security_milenage_f1(uint8* k, uint8* op, uint8* rand, uint8* sqn, uint8* amf, uint8* mac_a);
/*********************************************************************
Name: liblte_security_milenage_f1_star
@ -309,12 +254,8 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f1(uint8 *k,
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f1_star(uint8 *k,
uint8 *op,
uint8 *rand,
uint8 *sqn,
uint8 *amf,
uint8 *mac_s);
LIBLTE_ERROR_ENUM
liblte_security_milenage_f1_star(uint8* k, uint8* op, uint8* rand, uint8* sqn, uint8* amf, uint8* mac_s);
/*********************************************************************
Name: liblte_security_milenage_f2345
@ -330,13 +271,8 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f1_star(uint8 *k,
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f2345(uint8 *k,
uint8 *op,
uint8 *rand,
uint8 *res,
uint8 *ck,
uint8 *ik,
uint8 *ak);
LIBLTE_ERROR_ENUM
liblte_security_milenage_f2345(uint8* k, uint8* op, uint8* rand, uint8* res, uint8* ck, uint8* ik, uint8* ak);
/*********************************************************************
Name: liblte_security_milenage_f5_star
@ -351,9 +287,6 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f2345(uint8 *k,
// Enums
// Structs
// Functions
LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8 *k,
uint8 *op,
uint8 *rand,
uint8 *ak);
LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8* k, uint8* op, uint8* rand, uint8* ak);
#endif // SRSLTE_LIBLTE_SECURITY_H

@ -24,12 +24,15 @@
#ifdef HAVE_POLARSSL
#include "polarssl/sha256.h"
#include "polarssl/aes.h"
#include "polarssl/sha256.h"
void sha256(const unsigned char *key, size_t keylen,
const unsigned char *input, size_t ilen,
unsigned char output[32], int is224 )
void sha256(const unsigned char* key,
size_t keylen,
const unsigned char* input,
size_t ilen,
unsigned char output[32],
int is224)
{
sha256_hmac(key, keylen, input, ilen, output, is224);
}
@ -38,47 +41,43 @@ void sha256(const unsigned char *key, size_t keylen,
#ifdef HAVE_MBEDTLS
#include "mbedtls/md.h"
#include "mbedtls/aes.h"
#include "mbedtls/md.h"
typedef mbedtls_aes_context aes_context;
#define AES_ENCRYPT 1
#define AES_DECRYPT 0
#define AES_ENCRYPT 1
#define AES_DECRYPT 0
int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize )
int aes_setkey_enc(aes_context* ctx, const unsigned char* key, unsigned int keysize)
{
return mbedtls_aes_setkey_enc(ctx, key, keysize);
}
int aes_crypt_ecb( aes_context *ctx,
int mode,
const unsigned char input[16],
unsigned char output[16] )
int aes_crypt_ecb(aes_context* ctx, int mode, const unsigned char input[16], unsigned char output[16])
{
return mbedtls_aes_crypt_ecb(ctx, mode, input, output);
}
int aes_crypt_ctr(aes_context *ctx,
size_t length,
size_t *nc_off,
unsigned char nonce_counter[16],
unsigned char stream_block[16],
const unsigned char *input,
unsigned char *output )
int aes_crypt_ctr(aes_context* ctx,
size_t length,
size_t* nc_off,
unsigned char nonce_counter[16],
unsigned char stream_block[16],
const unsigned char* input,
unsigned char* output)
{
return mbedtls_aes_crypt_ctr(ctx, length, nc_off, nonce_counter,
stream_block, input, output);
return mbedtls_aes_crypt_ctr(ctx, length, nc_off, nonce_counter, stream_block, input, output);
}
void sha256(const unsigned char *key, size_t keylen,
const unsigned char *input, size_t ilen,
unsigned char output[32], int is224 )
void sha256(const unsigned char* key,
size_t keylen,
const unsigned char* input,
size_t ilen,
unsigned char output[32],
int is224)
{
mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
key, keylen,
input, ilen,
output );
mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), key, keylen, input, ilen, output);
}
#endif // HAVE_MBEDTLS

@ -39,17 +39,14 @@
DEFINES
*******************************************************************************/
/*******************************************************************************
TYPEDEFS
*******************************************************************************/
/*******************************************************************************
GLOBAL VARIABLES
*******************************************************************************/
/*******************************************************************************
FUNCTIONS
*******************************************************************************/
@ -59,17 +56,14 @@
Description: Converts a value to a bit string
*********************************************************************/
void liblte_value_2_bits(uint32 value,
uint8 **bits,
uint32 N_bits)
void liblte_value_2_bits(uint32 value, uint8** bits, uint32 N_bits)
{
uint32 i;
uint32 i;
for(i=0; i<N_bits; i++)
{
(*bits)[i] = (value >> (N_bits-i-1)) & 0x1;
}
*bits += N_bits;
for (i = 0; i < N_bits; i++) {
(*bits)[i] = (value >> (N_bits - i - 1)) & 0x1;
}
*bits += N_bits;
}
/*********************************************************************
@ -77,19 +71,17 @@ void liblte_value_2_bits(uint32 value,
Description: Converts a bit string to a value
*********************************************************************/
uint32 liblte_bits_2_value(uint8 **bits,
uint32 N_bits)
uint32 liblte_bits_2_value(uint8** bits, uint32 N_bits)
{
uint32 value = 0;
uint32 i;
uint32 value = 0;
uint32 i;
for(i=0; i<N_bits; i++)
{
value |= (*bits)[i] << (N_bits-i-1);
}
*bits += N_bits;
for (i = 0; i < N_bits; i++) {
value |= (*bits)[i] << (N_bits - i - 1);
}
*bits += N_bits;
return(value);
return (value);
}
/*********************************************************************
@ -97,22 +89,19 @@ uint32 liblte_bits_2_value(uint8 **bits,
Description: Pack a bit array into a byte array
*********************************************************************/
void liblte_pack(LIBLTE_BIT_MSG_STRUCT *bits,
LIBLTE_BYTE_MSG_STRUCT *bytes)
void liblte_pack(LIBLTE_BIT_MSG_STRUCT* bits, LIBLTE_BYTE_MSG_STRUCT* bytes)
{
uint8_t* bit_ptr = bits->msg;
uint32_t i;
for(i=0; i<bits->N_bits/8; i++)
{
bytes->msg[i] = liblte_bits_2_value(&bit_ptr, 8);
}
bytes->N_bytes = bits->N_bits/8;
if(bits->N_bits%8 > 0)
{
bytes->msg[bytes->N_bytes] = liblte_bits_2_value(&bit_ptr, bits->N_bits%8);
bytes->N_bytes++;
}
uint8_t* bit_ptr = bits->msg;
uint32_t i;
for (i = 0; i < bits->N_bits / 8; i++) {
bytes->msg[i] = liblte_bits_2_value(&bit_ptr, 8);
}
bytes->N_bytes = bits->N_bits / 8;
if (bits->N_bits % 8 > 0) {
bytes->msg[bytes->N_bytes] = liblte_bits_2_value(&bit_ptr, bits->N_bits % 8);
bytes->N_bytes++;
}
}
/*********************************************************************
@ -120,17 +109,15 @@ void liblte_pack(LIBLTE_BIT_MSG_STRUCT *bits,
Description: Unpack a byte array into a bit array
*********************************************************************/
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT *bytes,
LIBLTE_BIT_MSG_STRUCT *bits)
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT* bytes, LIBLTE_BIT_MSG_STRUCT* bits)
{
uint8_t *bit_ptr = bits->msg;
uint32_t i;
for(i=0; i<bytes->N_bytes; i++)
{
liblte_value_2_bits(bytes->msg[i], &bit_ptr, 8);
}
bits->N_bits = bytes->N_bytes*8;
uint8_t* bit_ptr = bits->msg;
uint32_t i;
for (i = 0; i < bytes->N_bytes; i++) {
liblte_value_2_bits(bytes->msg[i], &bit_ptr, 8);
}
bits->N_bits = bytes->N_bytes * 8;
}
/*********************************************************************
@ -138,19 +125,17 @@ void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT *bytes,
Description: Pack a bit array into a byte array
*********************************************************************/
void liblte_pack(uint8_t *bits, uint32_t n_bits, uint8_t *bytes)
void liblte_pack(uint8_t* bits, uint32_t n_bits, uint8_t* bytes)
{
uint8_t* bit_ptr = bits;
uint32_t i;
for(i=0; i<n_bits/8; i++)
{
bytes[i] = liblte_bits_2_value(&bit_ptr, 8);
}
if(n_bits%8 > 0)
{
bytes[n_bits/8] = liblte_bits_2_value(&bit_ptr, n_bits%8);
}
uint8_t* bit_ptr = bits;
uint32_t i;
for (i = 0; i < n_bits / 8; i++) {
bytes[i] = liblte_bits_2_value(&bit_ptr, 8);
}
if (n_bits % 8 > 0) {
bytes[n_bits / 8] = liblte_bits_2_value(&bit_ptr, n_bits % 8);
}
}
/*********************************************************************
@ -158,15 +143,14 @@ void liblte_pack(uint8_t *bits, uint32_t n_bits, uint8_t *bytes)
Description: Unpack a byte array into a bit array
*********************************************************************/
void liblte_unpack(uint8_t *bytes, uint32_t n_bytes, uint8_t *bits)
void liblte_unpack(uint8_t* bytes, uint32_t n_bytes, uint8_t* bits)
{
uint8_t *bit_ptr = bits;
uint32_t i;
uint8_t* bit_ptr = bits;
uint32_t i;
for(i=0; i<n_bytes; i++)
{
liblte_value_2_bits(bytes[i], &bit_ptr, 8);
}
for (i = 0; i < n_bytes; i++) {
liblte_value_2_bits(bytes[i], &bit_ptr, 8);
}
}
/*********************************************************************
@ -174,10 +158,9 @@ void liblte_unpack(uint8_t *bytes, uint32_t n_bytes, uint8_t *bits)
Description: Aligns a pointer to a multibyte boundary
*********************************************************************/
void liblte_align_up(uint8_t **ptr, uint32_t align)
void liblte_align_up(uint8_t** ptr, uint32_t align)
{
while( (uint64_t)(*ptr) % align > 0)
{
while ((uint64_t)(*ptr) % align > 0) {
(*ptr)++;
}
}
@ -188,10 +171,9 @@ void liblte_align_up(uint8_t **ptr, uint32_t align)
Description: Aligns a pointer to a multibyte boundary and zeros
bytes skipped
*********************************************************************/
void liblte_align_up_zero(uint8_t **ptr, uint32_t align)
void liblte_align_up_zero(uint8_t** ptr, uint32_t align)
{
while( (uint64_t)(*ptr) % align > 0)
{
while ((uint64_t)(*ptr) % align > 0) {
**ptr = 0;
(*ptr)++;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save