mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
5.2 KiB
C
158 lines
5.2 KiB
C
4 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2012-2014 Ben Wojtowicz
|
||
|
*
|
||
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
|
*
|
||
|
*/
|
||
8 years ago
|
|
||
4 years ago
|
#ifndef SRSRAN_LIBLTE_COMMON_H
|
||
|
#define SRSRAN_LIBLTE_COMMON_H
|
||
8 years ago
|
|
||
|
/*******************************************************************************
|
||
|
INCLUDES
|
||
|
*******************************************************************************/
|
||
|
|
||
|
#include <stddef.h>
|
||
5 years ago
|
#include <stdint.h>
|
||
8 years ago
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
/*******************************************************************************
|
||
|
DEFINES
|
||
|
*******************************************************************************/
|
||
|
|
||
5 years ago
|
// TODO: This was chosen arbitrarily
|
||
8 years ago
|
#define LIBLTE_ASN1_OID_MAXSUBIDS 128
|
||
7 years ago
|
|
||
4 years ago
|
// Caution these values must match SRSRAN_ ones in common.h
|
||
5 years ago
|
#define LIBLTE_MAX_MSG_SIZE_BITS 102048
|
||
4 years ago
|
#define LIBLTE_MAX_MSG_SIZE_BYTES 12237
|
||
5 years ago
|
#define LIBLTE_MSG_HEADER_OFFSET 1020
|
||
8 years ago
|
|
||
5 years ago
|
// Macro to make it easier to convert defines into strings
|
||
|
#define LIBLTE_CASE_STR(code) \
|
||
|
case code: \
|
||
|
return #code
|
||
6 years ago
|
|
||
8 years ago
|
/*******************************************************************************
|
||
|
TYPEDEFS
|
||
|
*******************************************************************************/
|
||
|
|
||
5 years ago
|
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;
|
||
8 years ago
|
|
||
5 years ago
|
typedef enum {
|
||
8 years ago
|
LIBLTE_SUCCESS = 0,
|
||
|
LIBLTE_ERROR_INVALID_INPUTS,
|
||
|
LIBLTE_ERROR_ENCODE_FAIL,
|
||
|
LIBLTE_ERROR_DECODE_FAIL,
|
||
|
LIBLTE_ERROR_INVALID_CRC,
|
||
|
LIBLTE_ERROR_N_ITEMS
|
||
5 years ago
|
} LIBLTE_ERROR_ENUM;
|
||
8 years ago
|
static const char liblte_error_text[LIBLTE_ERROR_N_ITEMS][64] = {
|
||
5 years ago
|
"Invalid inputs",
|
||
|
"Encode failure",
|
||
|
"Decode failure",
|
||
8 years ago
|
};
|
||
|
|
||
7 years ago
|
#define LIBLTE_STRING_LEN 128
|
||
|
|
||
8 years ago
|
typedef void* LIBLTE_ASN1_OPEN_TYPE_STRUCT;
|
||
|
|
||
|
typedef struct {
|
||
5 years ago
|
uint32_t numids; // number of subidentifiers
|
||
|
uint32_t subid[LIBLTE_ASN1_OID_MAXSUBIDS]; // subidentifier values
|
||
8 years ago
|
} LIBLTE_ASN1_OID_STRUCT;
|
||
|
|
||
5 years ago
|
typedef struct {
|
||
|
bool data_valid;
|
||
|
bool data;
|
||
|
} LIBLTE_BOOL_MSG_STRUCT;
|
||
8 years ago
|
|
||
5 years ago
|
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)));
|
||
8 years ago
|
|
||
4 years ago
|
struct alignas(8) LIBLTE_BYTE_MSG_STRUCT
|
||
|
{
|
||
5 years ago
|
uint32 N_bytes;
|
||
|
uint8 header[LIBLTE_MSG_HEADER_OFFSET];
|
||
|
uint8 msg[LIBLTE_MAX_MSG_SIZE_BYTES];
|
||
4 years ago
|
};
|
||
8 years ago
|
|
||
|
/*******************************************************************************
|
||
|
DECLARATIONS
|
||
|
*******************************************************************************/
|
||
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_value_2_bits
|
||
|
|
||
|
Description: Converts a value to a bit string
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_value_2_bits(uint32 value, uint8** bits, uint32 N_bits);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_bits_2_value
|
||
|
|
||
|
Description: Converts a bit string to a value
|
||
|
*********************************************************************/
|
||
5 years ago
|
uint32 liblte_bits_2_value(uint8** bits, uint32 N_bits);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_pack
|
||
|
|
||
|
Description: Pack a bit array into a byte array
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_pack(LIBLTE_BIT_MSG_STRUCT* bits, LIBLTE_BYTE_MSG_STRUCT* bytes);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_unpack
|
||
|
|
||
|
Description: Unpack a byte array into a bit array
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_unpack(LIBLTE_BYTE_MSG_STRUCT* bytes, LIBLTE_BIT_MSG_STRUCT* bits);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_pack
|
||
|
|
||
|
Description: Pack a bit array into a byte array
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_pack(uint8_t* bits, uint32_t n_bits, uint8_t* bytes);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_unpack
|
||
|
|
||
|
Description: Unpack a byte array into a bit array
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_unpack(uint8_t* bytes, uint32_t n_bytes, uint8_t* bits);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_align_up
|
||
|
|
||
|
Description: Aligns a pointer to a multibyte boundary
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_align_up(uint8_t** ptr, uint32_t align);
|
||
8 years ago
|
|
||
|
/*********************************************************************
|
||
|
Name: liblte_align_up_zero
|
||
|
|
||
|
Description: Aligns a pointer to a multibyte boundary and zeros
|
||
|
bytes skipped
|
||
|
*********************************************************************/
|
||
5 years ago
|
void liblte_align_up_zero(uint8_t** ptr, uint32_t align);
|
||
8 years ago
|
|
||
4 years ago
|
#endif // SRSRAN_LIBLTE_COMMON_H
|