Commit 689a27e6 authored by Frédéric Leroy's avatar Frédéric Leroy

UE/USIM/API: fix interface for storing usim_data

parent 77155996
...@@ -100,6 +100,16 @@ int main (int argc, const char* argv[]) ...@@ -100,6 +100,16 @@ int main (int argc, const char* argv[])
unsigned char gen_data; unsigned char gen_data;
/* Get USIM application pathname */
char* path = memory_get_path(USIM_API_NVRAM_DIRNAME,
USIM_API_NVRAM_FILENAME);
if (path == NULL) {
fprintf(stderr, "USIM-API - Failed to get USIM pathname");
free(path);
exit(EXIT_FAILURE);
}
/* /*
* Read command line parameters * Read command line parameters
*/ */
...@@ -415,7 +425,7 @@ int main (int argc, const char* argv[]) ...@@ -415,7 +425,7 @@ int main (int argc, const char* argv[])
/* /*
* Write USIM application data * Write USIM application data
*/ */
rc = usim_api_write(&usim_data); rc = usim_api_write(path, &usim_data);
if (rc != RETURNok) { if (rc != RETURNok) {
perror("ERROR\t: usim_api_write() failed"); perror("ERROR\t: usim_api_write() failed");
...@@ -427,7 +437,7 @@ int main (int argc, const char* argv[]) ...@@ -427,7 +437,7 @@ int main (int argc, const char* argv[])
* Read USIM application data * Read USIM application data
*/ */
memset(&usim_data, 0, sizeof(usim_data_t)); memset(&usim_data, 0, sizeof(usim_data_t));
rc = usim_api_read(&usim_data); rc = usim_api_read(path, &usim_data);
if (rc != RETURNok) { if (rc != RETURNok) {
perror("ERROR\t: usim_api_read() failed"); perror("ERROR\t: usim_api_read() failed");
...@@ -443,7 +453,6 @@ int main (int argc, const char* argv[]) ...@@ -443,7 +453,6 @@ int main (int argc, const char* argv[])
/* /*
* Display USIM file location * Display USIM file location
*/ */
char* path = memory_get_path("USIM_DIR", ".usim.nvram");
printf("\nUSIM data file: %s\n", path); printf("\nUSIM data file: %s\n", path);
free(path); free(path);
......
...@@ -47,6 +47,7 @@ Description Implements the API used by the NAS layer to read/write ...@@ -47,6 +47,7 @@ Description Implements the API used by the NAS layer to read/write
#include "aka_functions.h" #include "aka_functions.h"
#include <string.h> // memcpy, memset #include <string.h> // memcpy, memset
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
#include <stdio.h>
/****************************************************************************/ /****************************************************************************/
/**************** E X T E R N A L D E F I N I T I O N S ****************/ /**************** E X T E R N A L D E F I N I T I O N S ****************/
...@@ -56,17 +57,6 @@ Description Implements the API used by the NAS layer to read/write ...@@ -56,17 +57,6 @@ Description Implements the API used by the NAS layer to read/write
/******************* L O C A L D E F I N I T I O N S *******************/ /******************* L O C A L D E F I N I T I O N S *******************/
/****************************************************************************/ /****************************************************************************/
/*
* The name of the file where are stored data of the USIM application
*/
#define USIM_API_NVRAM_FILENAME ".usim.nvram"
/*
* The name of the environment variable which defines the directory
* where the USIM application file is located
*/
#define USIM_API_NVRAM_DIRNAME "USIM_DIR"
static int _usim_api_check_sqn(uint32_t seq, uint8_t ind); static int _usim_api_check_sqn(uint32_t seq, uint8_t ind);
/****************************************************************************/ /****************************************************************************/
...@@ -87,24 +77,14 @@ static int _usim_api_check_sqn(uint32_t seq, uint8_t ind); ...@@ -87,24 +77,14 @@ static int _usim_api_check_sqn(uint32_t seq, uint8_t ind);
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int usim_api_read(usim_data_t* data) int usim_api_read(const char *filename, usim_data_t* data)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
/* Get USIM application pathname */
char* path = memory_get_path(USIM_API_NVRAM_DIRNAME,
USIM_API_NVRAM_FILENAME);
if (path == NULL) {
LOG_TRACE(ERROR, "USIM-API - Failed to get USIM pathname");
LOG_FUNC_RETURN (RETURNerror);
}
/* Read USIM application data */ /* Read USIM application data */
if (memory_read(path, data, sizeof(usim_data_t)) != RETURNok) { if (memory_read(filename, data, sizeof(usim_data_t)) != RETURNok) {
LOG_TRACE(ERROR, "USIM-API - %s file is either not valid " LOG_TRACE(ERROR, "USIM-API - %s file is either not valid "
"or not present", path); "or not present", filename);
free(path);
LOG_FUNC_RETURN (RETURNerror); LOG_FUNC_RETURN (RETURNerror);
} }
...@@ -123,7 +103,7 @@ int usim_api_read(usim_data_t* data) ...@@ -123,7 +103,7 @@ int usim_api_read(usim_data_t* data)
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 }; 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };
#endif #endif
memcpy(data->keys.op, _op, sizeof(_op)); memcpy(data->keys.op, _op, sizeof(_op));
free(path);
LOG_FUNC_RETURN (RETURNok); LOG_FUNC_RETURN (RETURNok);
} }
...@@ -141,28 +121,17 @@ int usim_api_read(usim_data_t* data) ...@@ -141,28 +121,17 @@ int usim_api_read(usim_data_t* data)
** Others: None ** ** Others: None **
** ** ** **
***************************************************************************/ ***************************************************************************/
int usim_api_write(const usim_data_t* data) int usim_api_write(const char *filename, const usim_data_t* data)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
/* Get USIM application pathname */
char* path = memory_get_path(USIM_API_NVRAM_DIRNAME,
USIM_API_NVRAM_FILENAME);
if (path == NULL) {
LOG_TRACE(ERROR, "USIM-API - Failed to get USIM pathname");
LOG_FUNC_RETURN (RETURNerror);
}
/* Write USIM application data */ /* Write USIM application data */
if (memory_write(path, data, sizeof(usim_data_t)) != RETURNok) { if (memory_write(filename, data, sizeof(usim_data_t)) != RETURNok) {
LOG_TRACE(ERROR, "USIM-API - Unable to write USIM file %s", path); LOG_TRACE(ERROR, "USIM-API - Unable to write USIM file %s", filename);
free(path);
LOG_FUNC_RETURN (RETURNerror); LOG_FUNC_RETURN (RETURNerror);
} }
free(path);
LOG_FUNC_RETURN (RETURNok); LOG_FUNC_RETURN (RETURNok);
} }
......
...@@ -54,6 +54,17 @@ Description Implements the API used by the NAS layer to read/write ...@@ -54,6 +54,17 @@ Description Implements the API used by the NAS layer to read/write
#define USIM_API_K_SIZE 16 #define USIM_API_K_SIZE 16
#define USIM_API_K_VALUE "fec86ba6eb707ed08905757b1bb44b8f" #define USIM_API_K_VALUE "fec86ba6eb707ed08905757b1bb44b8f"
/*
* The name of the file where are stored data of the USIM application
*/
#define USIM_API_NVRAM_FILENAME ".usim.nvram"
/*
* The name of the environment variable which defines the directory
* where the USIM application file is located
*/
#define USIM_API_NVRAM_DIRNAME "USIM_DIR"
/****************************************************************************/ /****************************************************************************/
/************************ G L O B A L T Y P E S ************************/ /************************ G L O B A L T Y P E S ************************/
/****************************************************************************/ /****************************************************************************/
...@@ -366,9 +377,9 @@ typedef struct { ...@@ -366,9 +377,9 @@ typedef struct {
/****************** E X P O R T E D F U N C T I O N S ******************/ /****************** E X P O R T E D F U N C T I O N S ******************/
/****************************************************************************/ /****************************************************************************/
int usim_api_read(usim_data_t* data); int usim_api_read(const char *filename, usim_data_t* data);
int usim_api_write(const usim_data_t* data); int usim_api_write(const char *filename, const usim_data_t* data);
int usim_api_authenticate(usim_data_t *usim_data, const OctetString* rand_pP, const OctetString* autn_pP, int usim_api_authenticate(usim_data_t *usim_data, const OctetString* rand_pP, const OctetString* autn_pP,
OctetString* auts, OctetString* res, OctetString* auts, OctetString* res,
......
...@@ -193,7 +193,7 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c ...@@ -193,7 +193,7 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c
/* /*
* Get USIM application data * Get USIM application data
*/ */
if ( usim_api_read(&user->usim_data) != RETURNok ) { if ( usim_api_read(user->usim_data_store, &user->usim_data) != RETURNok ) {
/* The USIM application may not be present or not valid */ /* The USIM application may not be present or not valid */
LOG_TRACE(WARNING, "EMM-MAIN - Failed to read USIM application data"); LOG_TRACE(WARNING, "EMM-MAIN - Failed to read USIM application data");
} else { } else {
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
# include "nas_parser.h" # include "nas_parser.h"
# include "nas_proc.h" # include "nas_proc.h"
# include "msc.h" # include "msc.h"
# include "memory.h"
#include "nas_user.h" #include "nas_user.h"
...@@ -94,6 +95,13 @@ void *nas_ue_task(void *args_p) ...@@ -94,6 +95,13 @@ void *nas_ue_task(void *args_p)
MSC_START_USE(); MSC_START_USE();
/* Initialize UE NAS (EURECOM-NAS) */ /* Initialize UE NAS (EURECOM-NAS) */
{ {
/* Get USIM data application filename */
user->usim_data_store = memory_get_path(USIM_API_NVRAM_DIRNAME, USIM_API_NVRAM_FILENAME);
if ( user->usim_data_store == NULL ) {
LOG_E(NAS, "[UE %d] - Failed to get USIM data application filename", user->ueid);
exit(EXIT_FAILURE);
}
/* Initialize user interface (to exchange AT commands with user process) */ /* Initialize user interface (to exchange AT commands with user process) */
nas_user_api_id_initialize(user); nas_user_api_id_initialize(user);
user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t)); user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t));
......
...@@ -75,6 +75,7 @@ typedef struct { ...@@ -75,6 +75,7 @@ typedef struct {
security_data_t *security_data; //Internal data used for security mode control procedure security_data_t *security_data; //Internal data used for security mode control procedure
// Hardware persistent storage // Hardware persistent storage
usim_data_t usim_data; // USIM application data usim_data_t usim_data; // USIM application data
const char *usim_data_store; // USIM application data filename
user_nvdata_t *nas_user_nvdata; //UE parameters stored in the UE's non-volatile memory device user_nvdata_t *nas_user_nvdata; //UE parameters stored in the UE's non-volatile memory device
// //
nas_user_context_t *nas_user_context; nas_user_context_t *nas_user_context;
......
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