Commit 57b6e24e authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Code cleanup for utils

parent 27234770
......@@ -24,7 +24,6 @@
#include "common_defs.h"
#include "common_types.h"
#include "conversions.h"
#include "bstrlib.h"
#include "Ngap_NGAP-PDU.h"
......
......@@ -27,7 +27,6 @@ file(GLOB NAS_src_files
${SRC_TOP_DIR}/utils/conversions.c
${SRC_TOP_DIR}/utils/pid_file.c
${SRC_TOP_DIR}/utils/hashtable.c
${SRC_TOP_DIR}/utils/obj_hashtable.c
${SRC_TOP_DIR}/utils/TLVDecoder.c
${SRC_TOP_DIR}/utils/TLVEncoder.c
${SRC_TOP_DIR}/utils/dynamic_memory_check.c
......
......@@ -124,7 +124,6 @@ int encode_qos_rules(QOSRules qosrules, uint8_t iei, uint8_t *buffer,
int decode_qos_rules(QOSRules *qosrules, uint8_t iei, uint8_t *buffer,
uint32_t len) {
int decoded = 0;
uint16_t ielen = 0;
int decode_result = 0;
uint8_t bitstream = 0;
int i = 0, j = 0;
......
......@@ -1656,7 +1656,7 @@ void smf_context::handle_pdu_session_update_sm_context_request(
for (int i = 0; i < number_of_flow_descriptions; i++) {
if (qos_flow_description[i].qfi == NO_QOS_FLOW_IDENTIFIER_ASSIGNED) {
//TODO: generate new QFI
generated_qfi.qfi = (uint8_t) 77; //hardcoded for now
generated_qfi.qfi = (uint8_t) 60; //hardcoded for now
qos_flow_description_content = qos_flow_description[i];
qos_flow_description_content.qfi = generated_qfi.qfi;
break;
......
/*
* Copyright (c) 2015, EURECOM (www.eurecom.fr)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include "conversions.h"
//#include "log.h"
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
};
static const signed char ascii_to_hex_table[0x100] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
void
hexa_to_ascii (
uint8_t * from,
char *to,
size_t length)
{
size_t i;
for (i = 0; i < length; i++) {
uint8_t upper = (from[i] & 0xf0) >> 4;
uint8_t lower = from[i] & 0x0f;
to[2 * i] = hex_to_ascii_table[upper];
to[2 * i + 1] = hex_to_ascii_table[lower];
}
}
int
ascii_to_hex (
uint8_t * dst,
const char *h)
{
const unsigned char *hex = (const unsigned char *)h;
unsigned i = 0;
for (;;) {
int high,
low;
while (*hex && isspace (*hex))
hex++;
if (!*hex)
return 1;
high = ascii_to_hex_table[*hex++];
if (high < 0)
return 0;
while (*hex && isspace (*hex))
hex++;
if (!*hex)
return 0;
low = ascii_to_hex_table[*hex++];
if (low < 0)
return 0;
dst[i++] = (high << 4) | low;
}
}
int BIT_STRING_fromBuf(BIT_STRING_t *st, const uint8_t *str, unsigned int bit_len)
{
void *buf;
unsigned int len = bit_len / 8;
if (bit_len % 8)
len++;
if (!st || (!str && len)) {
errno = EINVAL;
return -1;
}
if (!str) {
free(st->buf);
st->buf = 0;
st->size = 0;
st->bits_unused = 0;
return 0;
}
buf = malloc(len);
if (!buf) {
errno = ENOMEM;
return -1;
}
memcpy(buf, str, len);
free(st->buf);
st->buf = buf;
st->size = len;
st->bits_unused = (len * 8) - bit_len;
return 0;
}
#define ASN1C_ASSERT(exp) \
if (!(exp)) { \
fprintf(stderr, "Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
abort(); \
}
uint32_t asn1str_to_u24(const OCTET_STRING_t *in)
{
uint32_t tac_Value = 0;
ASN1C_ASSERT(in && in->size == sizeof(uint32_t) - 1);
//OAILOG_DEBUG(LOG_NGAP,"buffer[0] %x\n",in->buf[0]);
//OAILOG_DEBUG(LOG_NGAP,"buffer[1] %x\n",in->buf[1]);
//OAILOG_DEBUG(LOG_NGAP,"buffer[2] %x\n",in->buf[2]);
tac_Value = in->buf[0] << 16 |
in->buf[1] << 8 |
in->buf[2];
return tac_Value;
}
......@@ -38,12 +38,6 @@
#ifndef FILE_CONVERSIONS_SEEN
#define FILE_CONVERSIONS_SEEN
int BIT_STRING_fromBuf(BIT_STRING_t *st, const uint8_t *str, unsigned int bit_len);
uint32_t asn1str_to_u32(const OCTET_STRING_t *in, uint32_t *tac_Value);
/* Endianness conversions for 16 and 32 bits integers from host to network order */
#if (BYTE_ORDER == LITTLE_ENDIAN)
# define hton_int32(x) \
......
This diff is collapsed.
/*
* Copyright (c) 2015, EURECOM (www.eurecom.fr)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
#ifndef FILE_HASH_TABLE_SEEN
#define FILE_HASH_TABLE_SEEN
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <pthread.h>
#include "bstrlib.h"
typedef size_t hash_size_t;
typedef uint64_t hash_key_t;
#define HASHTABLE_NOT_A_KEY_VALUE ((uint64_t)-1)
typedef enum hashtable_return_code_e {
HASH_TABLE_OK = 0,
HASH_TABLE_INSERT_OVERWRITTEN_DATA,
HASH_TABLE_KEY_NOT_EXISTS ,
HASH_TABLE_SEARCH_NO_RESULT ,
HASH_TABLE_KEY_ALREADY_EXISTS ,
HASH_TABLE_BAD_PARAMETER_HASHTABLE,
HASH_TABLE_BAD_PARAMETER_KEY,
HASH_TABLE_SYSTEM_ERROR ,
HASH_TABLE_CODE_MAX
} hashtable_rc_t;
#define HASH_TABLE_DEFAULT_HASH_FUNC NULL
#define HASH_TABLE_DEFAULT_free_wrapper_FUNC NULL
typedef struct hash_node_s {
hash_key_t key;
void *data;
struct hash_node_s *next;
} hash_node_t;
typedef struct hash_table_s {
hash_size_t size;
hash_size_t num_elements;
struct hash_node_s **nodes;
hash_size_t (*hashfunc)(const hash_key_t);
void (*freefunc)(void**);
bstring name;
bool is_allocated_by_malloc;
bool log_enabled;
} hash_table_t;
typedef struct hash_table_ts_s {
pthread_mutex_t mutex;
hash_size_t size;
hash_size_t num_elements;
struct hash_node_s **nodes;
pthread_mutex_t *lock_nodes;
hash_size_t (*hashfunc)(const hash_key_t);
void (*freefunc)(void**);
bstring name;
bool is_allocated_by_malloc;
bool log_enabled;
} hash_table_ts_t;
char* hashtable_rc_code2string(hashtable_rc_t rc);
void hash_free_int_func(void** memory);
hash_table_t * hashtable_init (hash_table_t * const hashtbl,const hash_size_t size,hash_size_t (*hashfunc) (const
hash_key_t),void (*freefunc) (void **),bstring display_name_p);
__attribute__ ((malloc)) hash_table_t *hashtable_create (const hash_size_t size, hash_size_t (*hashfunc)(const
hash_key_t ), void (*freefunc)(void**), bstring name_p);
hashtable_rc_t hashtable_destroy(hash_table_t * hashtbl);
hashtable_rc_t hashtable_is_key_exists (const hash_table_t * const hashtbl, const hash_key_t key) __attribute__ ((hot, warn_unused_result));
hashtable_rc_t hashtable_apply_callback_on_elements (hash_table_t * const hashtbl,
bool func_cb(hash_key_t key, void* element, void* parameter, void**result),
void* parameter,
void**result);
hashtable_rc_t hashtable_dump_content (const hash_table_t * const hashtbl, bstring str);
hashtable_rc_t hashtable_insert (hash_table_t * const hashtbl, const hash_key_t key, void *element);
hashtable_rc_t hashtable_free (hash_table_t * const hashtbl, const hash_key_t key);
hashtable_rc_t hashtable_remove(hash_table_t * const hashtbl, const hash_key_t key, void** element);
hashtable_rc_t hashtable_get (const hash_table_t * const hashtbl, const hash_key_t key, void **element) __attribute__ ((hot));
hashtable_rc_t hashtable_resize (hash_table_t * const hashtbl, const hash_size_t size);
// Thread-safe functions
hash_table_ts_t * hashtable_ts_init (hash_table_ts_t * const hashtbl,const hash_size_t size,hash_size_t (*hashfunc)
(const hash_key_t),void (*freefunc) (void **),bstring display_name_p);
__attribute__ ((malloc)) hash_table_ts_t *hashtable_ts_create (const hash_size_t size, hash_size_t (*hashfunc)
(const hash_key_t ), void (*freefunc)(void**), bstring name_p);
hashtable_rc_t hashtable_ts_destroy(hash_table_ts_t * hashtbl);
hashtable_rc_t hashtable_ts_is_key_exists (const hash_table_ts_t * const hashtbl, const hash_key_t key) __attribute__ ((hot, warn_unused_result));
hashtable_rc_t hashtable_ts_apply_callback_on_elements (hash_table_ts_t * const hashtbl,
bool func_cb(const hash_key_t key, void* const element, void* parameter, void**result),
void* parameter,
void**result);
hashtable_rc_t hashtable_ts_dump_content (const hash_table_ts_t * const hashtbl, bstring str);
hashtable_rc_t hashtable_ts_insert (hash_table_ts_t * const hashtbl, const hash_key_t key, void *element);
hashtable_rc_t hashtable_ts_free (hash_table_ts_t * const hashtbl, const hash_key_t key);
hashtable_rc_t hashtable_ts_remove(hash_table_ts_t * const hashtbl, const hash_key_t key, void** element);
hashtable_rc_t hashtable_ts_get (const hash_table_ts_t * const hashtbl, const hash_key_t key, void **element) __attribute__ ((hot));
hashtable_rc_t hashtable_ts_resize (hash_table_ts_t * const hashtbl, const hash_size_t size);
#endif
This diff is collapsed.
/*
* Copyright (c) 2015, EURECOM (www.eurecom.fr)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
#ifndef FILE_OBJ_HASHTABLE_SEEN
#define FILE_OBJ_HASHTABLE_SEEN
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <pthread.h>
#include "hashtable.h"
typedef struct obj_hash_node_s {
int key_size;
void *key;
void *data;
struct obj_hash_node_s *next;
} obj_hash_node_t;
typedef struct obj_hash_table_s {
pthread_mutex_t mutex;
hash_size_t size;
hash_size_t num_elements;
struct obj_hash_node_s **nodes;
pthread_mutex_t *lock_nodes;
hash_size_t (*hashfunc)(const void*, int);
void (*freekeyfunc)(void**);
void (*freedatafunc)(void**);
bstring name;
bool log_enabled;
} obj_hash_table_t;
void obj_hashtable_no_free_key_callback(void* param);
obj_hash_table_t *obj_hashtable_init (obj_hash_table_t * const hashtblP, const hash_size_t sizeP, hash_size_t
(*hashfuncP) (const void *,int),void (*freekeyfuncP) (void **),void (*freedatafuncP) (void **), bstring
display_name_pP);
obj_hash_table_t *obj_hashtable_create (const hash_size_t size, hash_size_t (*hashfunc)(const void*, int ), void
(*freekeyfunc)(void**), void (*freedatafunc)(void**), bstring display_name_pP);
hashtable_rc_t obj_hashtable_destroy (obj_hash_table_t * const hashtblP);
hashtable_rc_t obj_hashtable_is_key_exists (const obj_hash_table_t * const hashtblP, const void* const keyP, const int key_sizeP) __attribute__ ((hot, warn_unused_result));
hashtable_rc_t obj_hashtable_insert (obj_hash_table_t * const hashtblP, const void* const keyP, const int key_sizeP, void *dataP);
hashtable_rc_t obj_hashtable_dump_content (const obj_hash_table_t * const hashtblP, bstring str);
hashtable_rc_t obj_hashtable_free (obj_hash_table_t *hashtblP, const void* keyP, const int key_sizeP);
hashtable_rc_t obj_hashtable_remove(obj_hash_table_t *hashtblP, const void* keyP, const int key_sizeP, void** dataP);
hashtable_rc_t obj_hashtable_get (const obj_hash_table_t * const hashtblP, const void* const keyP, const int key_sizeP, void ** dataP) __attribute__ ((hot));
hashtable_rc_t obj_hashtable_get_keys(const obj_hash_table_t * const hashtblP, void ** keysP, unsigned int * sizeP);
hashtable_rc_t obj_hashtable_resize (obj_hash_table_t * const hashtblP, const hash_size_t sizeP);
// Thread-safe functions
obj_hash_table_t *obj_hashtable_ts_init (obj_hash_table_t * const hashtblP, const hash_size_t sizeP, hash_size_t
(*hashfuncP) (const void *,int),void (*freekeyfuncP) (void **),void (*freedatafuncP) (void **),bstring display_name_pP);
obj_hash_table_t *obj_hashtable_ts_create (const hash_size_t size, hash_size_t (*hashfunc)(const void*, int ),
void (*freekeyfunc)(void**), void (*freedatafunc)(void**), bstring
display_name_pP);
hashtable_rc_t obj_hashtable_ts_destroy (obj_hash_table_t * const hashtblP);
hashtable_rc_t obj_hashtable_ts_is_key_exists (const obj_hash_table_t * const hashtblP, const void* const keyP, const int key_sizeP) __attribute__ ((hot, warn_unused_result));
hashtable_rc_t obj_hashtable_ts_insert (obj_hash_table_t * const hashtblP, const void* const keyP, const int key_sizeP, void *dataP);
hashtable_rc_t obj_hashtable_ts_dump_content (const obj_hash_table_t * const hashtblP, bstring str);
hashtable_rc_t obj_hashtable_ts_free (obj_hash_table_t *hashtblP, const void* keyP, const int key_sizeP);
hashtable_rc_t obj_hashtable_ts_remove(obj_hash_table_t *hashtblP, const void* keyP, const int key_sizeP, void** dataP);
hashtable_rc_t obj_hashtable_ts_get (const obj_hash_table_t * const hashtblP, const void* const keyP, const int key_sizeP, void ** dataP) __attribute__ ((hot));
hashtable_rc_t obj_hashtable_ts_get_keys(const obj_hash_table_t * const hashtblP, void ** keysP, unsigned int * sizeP);
hashtable_rc_t obj_hashtable_ts_resize (obj_hash_table_t * const hashtblP, const hash_size_t sizeP);
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file pid_file.h
\brief
\author Lionel GAUTHIER
\date 2016
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_PID_FILE_SEEN
#define FILE_PID_FILE_SEEN
#include <stdbool.h>
/*
* Generate the exe absolute path using a specified basepath.
*
* @param basepath
* the root directory to use.
*
* @return a C string for the exe absolute path.
*/
char* get_exe_absolute_path(char const *basepath, unsigned int instance);
bool is_pid_file_lock_success(char const *pid_file_name);
void pid_file_unlock(void);
#endif
This diff is collapsed.
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