Commit 45fccb02 authored by FredericLeroy's avatar FredericLeroy

UE/API/USIM: move hex functions to common/utils.c

parent 9af35991
......@@ -27,6 +27,7 @@ set(usim_SRC
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/nas_log.c
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/OctetString.c
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/TLVEncoder.c
${OPENAIR_DIR}/common/utils/utils.c
)
set(usim_HDR
${OPENAIR_DIR}/openair3/NAS/TOOLS/network.h
......@@ -36,8 +37,11 @@ set(usim_HDR
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/nas_log.h
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/OctetString.h
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/TLVEncoder.h
${OPENAIR_DIR}/common/utils/utils.h
)
include_directories(
${OPENAIR_DIR}/common/utils
${OPENAIR_DIR}/openair3/NAS/UE
${OPENAIR_DIR}/openair3/NAS/COMMON
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM
${OPENAIR_DIR}/openair3/NAS/UE/EMM/
......
......@@ -21,3 +21,54 @@ void *malloc_or_fail(size_t size) {
}
return ptr;
}
/****************************************************************************
** **
** Name: hex_char_to_hex_value() **
** **
** Description: Converts an hexadecimal ASCII coded digit into its value. **
** **
** Inputs: c: A char holding the ASCII coded value **
** Others: None **
** **
** Outputs: None **
** Return: Converted value **
** Others: None **
** **
***************************************************************************/
uint8_t hex_char_to_hex_value (char c)
{
if (c >= 'A') {
/* Remove case bit */
c &= ~('a' ^ 'A');
return (c - 'A' + 10);
} else {
return (c - '0');
}
}
/****************************************************************************
** **
** Name: hex_string_to_hex_value() **
** **
** Description: Converts an hexadecimal ASCII coded string into its value.**
** **
** Inputs: hex_value: A pointer to the location to store the **
** conversion result **
** size: The size of hex_value in bytes **
** Others: None **
** **
** Outputs: hex_value: Converted value **
** Return: None **
** Others: None **
** **
***************************************************************************/
void hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int size)
{
int i;
for (i=0; i < size; i++) {
hex_value[i] = (hex_char_to_hex_value(hex_string[2 * i]) << 4) | hex_char_to_hex_value(hex_string[2 * i + 1]);
}
}
#ifndef _UTILS_H
#define _UTILS_H
#include <stdint.h>
#include <sys/types.h>
void *calloc_or_fail(size_t size);
void *malloc_or_fail(size_t size);
// Converts an hexadecimal ASCII coded digit into its value. **
uint8_t hex_char_to_hex_value (char c);
// Converts an hexadecimal ASCII coded string into its value.**
void hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int size);
#endif
......@@ -41,6 +41,7 @@ Description Implements the API used by the NAS layer to read/write
#include "usim_api.h"
#include "nas_log.h"
#include "utils.h"
#include "memory.h"
#include <stdio.h>
#include "aka_functions.h"
......@@ -66,8 +67,6 @@ Description Implements the API used by the NAS layer to read/write
*/
#define USIM_API_NVRAM_DIRNAME "USIM_DIR"
static uint8_t _usim_api_hex_char_to_hex_value (char c);
static void _usim_api_hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int size);
static int _usim_api_check_sqn(uint32_t seq, uint8_t ind);
/****************************************************************************/
......@@ -110,7 +109,7 @@ int usim_api_read(usim_data_t* data)
}
/* initialize the subscriber authentication security key */
_usim_api_hex_string_to_hex_value(data->keys.usim_api_k, USIM_API_K_VALUE, USIM_API_K_SIZE);
hex_string_to_hex_value(data->keys.usim_api_k, USIM_API_K_VALUE, USIM_API_K_SIZE);
// initialize OP
/* PFT OP used currently in HSS (OPENAIRHSS/auc/kdf.c) */
......@@ -497,57 +496,6 @@ int usim_api_authenticate(usim_data_t *usim_data, const OctetString* rand_pP, co
/********************* L O C A L F U N C T I O N S *********************/
/****************************************************************************/
/****************************************************************************
** **
** Name: _usim_api_hex_char_to_hex_value() **
** **
** Description: Converts an hexadecimal ASCII coded digit into its value. **
** **
** Inputs: c: A char holding the ASCII coded value **
** Others: None **
** **
** Outputs: None **
** Return: Converted value **
** Others: None **
** **
***************************************************************************/
static uint8_t _usim_api_hex_char_to_hex_value (char c)
{
if (c >= 'A') {
/* Remove case bit */
c &= ~('a' ^ 'A');
return (c - 'A' + 10);
} else {
return (c - '0');
}
}
/****************************************************************************
** **
** Name: _usim_api_hex_string_to_hex_value() **
** **
** Description: Converts an hexadecimal ASCII coded string into its value.**
** **
** Inputs: hex_value: A pointer to the location to store the **
** conversion result **
** size: The size of hex_value in bytes **
** Others: None **
** **
** Outputs: hex_value: Converted value **
** Return: None **
** Others: None **
** **
***************************************************************************/
static void _usim_api_hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int size)
{
int i;
for (i=0; i < size; i++) {
hex_value[i] = (_usim_api_hex_char_to_hex_value(hex_string[2 * i]) << 4) | _usim_api_hex_char_to_hex_value(hex_string[2 * i + 1]);
}
}
/****************************************************************************
** **
** Name: _usim_api_check_sqn() **
......
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