renamed openair-cn to openair3
git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7886 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@@ -0,0 +1,22 @@
|
||||
ifndef PROJDIR
|
||||
PROJDIR = $(PWD)/../../..
|
||||
INCLUDES = -I. -I$(INCDIR) -I$(UTILDIR) -I$(IESDIR) -I$(EMMMSGDIR) -I$(ESMMSGDIR)
|
||||
endif
|
||||
|
||||
include $(PROJDIR)/Makerules
|
||||
include $(PROJDIR)/Makefile.inc
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
%.o: %.c Makefile
|
||||
@echo Compiling $<
|
||||
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) *.bak *~
|
||||
|
||||
depend:
|
||||
makedepend -- ${CFLAGS} -- ${SRCS}
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
|
||||
Source as_message.c
|
||||
|
||||
Version 0.1
|
||||
|
||||
Date 2012/11/06
|
||||
|
||||
Product NAS stack
|
||||
|
||||
Subsystem Application Programming Interface
|
||||
|
||||
Author Frederic Maurel
|
||||
|
||||
Description Defines the messages supported by the Access Stratum sublayer
|
||||
protocol (usually RRC and S1AP for E-UTRAN) and functions used
|
||||
to encode and decode
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "as_message.h"
|
||||
#include "commonDef.h"
|
||||
#include "nas_log.h"
|
||||
|
||||
#include <string.h> // memcpy
|
||||
#include <stdlib.h> // free
|
||||
|
||||
/****************************************************************************/
|
||||
/**************** E X T E R N 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 *******************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/****************** E X P O R T E D F U N C T I O N S ******************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: as_message_decode() **
|
||||
** **
|
||||
** Description: Decode AS message and accordingly fills data structure **
|
||||
** **
|
||||
** Inputs: buffer: Pointer to the buffer containing the **
|
||||
** message **
|
||||
** length: Number of bytes that should be decoded **
|
||||
** Others: None **
|
||||
** **
|
||||
** Outputs: msg: AS message structure to be filled **
|
||||
** Return: The AS message identifier when the buffer **
|
||||
** has been successfully decoded; **
|
||||
** RETURNerror otherwise. **
|
||||
** Others: None **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int as_message_decode(const char* buffer, as_message_t* msg, int length)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
int bytes;
|
||||
Byte_t** data = NULL;
|
||||
|
||||
/* Get the message type */
|
||||
msg->msgID = *(uint16_t*)(buffer);
|
||||
bytes = sizeof(uint16_t);
|
||||
|
||||
switch (msg->msgID) {
|
||||
case AS_NAS_ESTABLISH_REQ:
|
||||
/* NAS signalling connection establish request */
|
||||
bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.nas_establish_req.initialNasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_IND:
|
||||
/* NAS signalling connection establishment indication */
|
||||
bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.nas_establish_ind.initialNasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_RSP:
|
||||
/* NAS signalling connection establishment response */
|
||||
bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.nas_establish_rsp.nasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_CNF:
|
||||
/* NAS signalling connection establishment confirm */
|
||||
bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.nas_establish_cnf.nasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_UL_INFO_TRANSFER_REQ:
|
||||
/* Uplink L3 data transfer request */
|
||||
bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.ul_info_transfer_req.nasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_UL_INFO_TRANSFER_IND:
|
||||
/* Uplink L3 data transfer indication */
|
||||
bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.ul_info_transfer_ind.nasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_DL_INFO_TRANSFER_REQ:
|
||||
/* Downlink L3 data transfer request */
|
||||
bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.dl_info_transfer_req.nasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_DL_INFO_TRANSFER_IND:
|
||||
/* Downlink L3 data transfer indication */
|
||||
bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*);
|
||||
data = &msg->msg.dl_info_transfer_ind.nasMsg.data;
|
||||
break;
|
||||
|
||||
case AS_BROADCAST_INFO_IND:
|
||||
case AS_CELL_INFO_REQ:
|
||||
case AS_CELL_INFO_CNF:
|
||||
case AS_CELL_INFO_IND:
|
||||
case AS_PAGING_REQ:
|
||||
case AS_PAGING_IND:
|
||||
case AS_NAS_RELEASE_REQ:
|
||||
case AS_UL_INFO_TRANSFER_CNF:
|
||||
case AS_DL_INFO_TRANSFER_CNF:
|
||||
case AS_NAS_RELEASE_IND:
|
||||
case AS_RAB_ESTABLISH_REQ:
|
||||
case AS_RAB_ESTABLISH_IND:
|
||||
case AS_RAB_ESTABLISH_RSP:
|
||||
case AS_RAB_ESTABLISH_CNF:
|
||||
case AS_RAB_RELEASE_REQ:
|
||||
case AS_RAB_RELEASE_IND:
|
||||
/* Messages without dedicated NAS information */
|
||||
bytes = length;
|
||||
break;
|
||||
|
||||
default:
|
||||
bytes = 0;
|
||||
LOG_TRACE(WARNING, "NET-API - AS message 0x%x is not valid",
|
||||
msg->msgID);
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytes > 0) {
|
||||
if (data) {
|
||||
/* Set the pointer to dedicated NAS information */
|
||||
*data = (Byte_t*)(buffer + bytes);
|
||||
}
|
||||
|
||||
/* Decode the message */
|
||||
memcpy(msg, (as_message_t*)buffer, bytes);
|
||||
LOG_FUNC_RETURN (msg->msgID);
|
||||
}
|
||||
|
||||
LOG_TRACE(WARNING, "NET-API - Failed to decode AS message 0x%x",
|
||||
msg->msgID);
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: as_message_encode() **
|
||||
** **
|
||||
** Description: Encode AS message **
|
||||
** **
|
||||
** Inputs: msg: AS message structure to encode **
|
||||
** length: Maximal capacity of the output buffer **
|
||||
** Others: None **
|
||||
** **
|
||||
** Outputs: buffer: Pointer to the encoded data buffer **
|
||||
** Return: The number of characters in the buffer **
|
||||
** when data have been successfully encoded; **
|
||||
** RETURNerror otherwise. **
|
||||
** Others: None **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int as_message_encode(char* buffer, as_message_t* msg, int length)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
int bytes = sizeof(msg->msgID);
|
||||
as_nas_info_t* nas_msg = NULL;
|
||||
|
||||
switch (msg->msgID) {
|
||||
case AS_BROADCAST_INFO_IND:
|
||||
/* Broadcast information */
|
||||
bytes += sizeof(broadcast_info_ind_t);
|
||||
break;
|
||||
|
||||
case AS_CELL_INFO_REQ:
|
||||
/* Cell information request */
|
||||
bytes += sizeof(cell_info_req_t);
|
||||
break;
|
||||
|
||||
case AS_CELL_INFO_CNF:
|
||||
/* Cell information response */
|
||||
bytes += sizeof(cell_info_cnf_t);
|
||||
break;
|
||||
|
||||
case AS_CELL_INFO_IND:
|
||||
/* Cell information indication */
|
||||
bytes += sizeof(cell_info_ind_t);
|
||||
break;
|
||||
|
||||
case AS_PAGING_REQ:
|
||||
/* Paging information request */
|
||||
bytes += sizeof(paging_req_t);
|
||||
break;
|
||||
|
||||
case AS_PAGING_IND:
|
||||
/* Paging information indication */
|
||||
bytes += sizeof(paging_ind_t);
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_REQ:
|
||||
/* NAS signalling connection establish request */
|
||||
bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.nas_establish_req.initialNasMsg;
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_IND:
|
||||
/* NAS signalling connection establish indication */
|
||||
bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.nas_establish_ind.initialNasMsg;
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_RSP:
|
||||
/* NAS signalling connection establish response */
|
||||
bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.nas_establish_rsp.nasMsg;
|
||||
break;
|
||||
|
||||
case AS_NAS_ESTABLISH_CNF:
|
||||
/* NAS signalling connection establish confirm */
|
||||
bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.nas_establish_cnf.nasMsg;
|
||||
break;
|
||||
|
||||
case AS_NAS_RELEASE_REQ:
|
||||
/* NAS signalling connection release request */
|
||||
bytes += sizeof(nas_release_req_t);
|
||||
break;
|
||||
|
||||
case AS_NAS_RELEASE_IND:
|
||||
/* NAS signalling connection release indication */
|
||||
bytes += sizeof(nas_release_ind_t);
|
||||
break;
|
||||
|
||||
case AS_UL_INFO_TRANSFER_REQ:
|
||||
/* Uplink L3 data transfer request */
|
||||
bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.ul_info_transfer_req.nasMsg;
|
||||
break;
|
||||
|
||||
case AS_UL_INFO_TRANSFER_CNF:
|
||||
/* Uplink L3 data transfer confirm */
|
||||
bytes += sizeof(ul_info_transfer_cnf_t);
|
||||
break;
|
||||
|
||||
case AS_UL_INFO_TRANSFER_IND:
|
||||
/* Uplink L3 data transfer indication */
|
||||
bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.ul_info_transfer_ind.nasMsg;
|
||||
break;
|
||||
|
||||
case AS_DL_INFO_TRANSFER_REQ:
|
||||
/* Downlink L3 data transfer */
|
||||
bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.dl_info_transfer_req.nasMsg;
|
||||
break;
|
||||
|
||||
case AS_DL_INFO_TRANSFER_CNF:
|
||||
/* Downlink L3 data transfer confirm */
|
||||
bytes += sizeof(dl_info_transfer_cnf_t);
|
||||
break;
|
||||
|
||||
case AS_DL_INFO_TRANSFER_IND:
|
||||
/* Downlink L3 data transfer indication */
|
||||
bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*);
|
||||
nas_msg = &msg->msg.dl_info_transfer_ind.nasMsg;
|
||||
break;
|
||||
|
||||
case AS_RAB_ESTABLISH_REQ:
|
||||
/* Radio Access Bearer establishment request */
|
||||
bytes += sizeof(rab_establish_req_t);
|
||||
break;
|
||||
|
||||
case AS_RAB_ESTABLISH_IND:
|
||||
/* Radio Access Bearer establishment indication */
|
||||
bytes += sizeof(rab_establish_ind_t);
|
||||
break;
|
||||
|
||||
case AS_RAB_ESTABLISH_RSP:
|
||||
/* Radio Access Bearer establishment response */
|
||||
bytes += sizeof(rab_establish_rsp_t);
|
||||
break;
|
||||
|
||||
case AS_RAB_ESTABLISH_CNF:
|
||||
/* Radio Access Bearer establishment confirm */
|
||||
bytes += sizeof(rab_establish_cnf_t);
|
||||
break;
|
||||
|
||||
case AS_RAB_RELEASE_REQ:
|
||||
/* Radio Access Bearer release request */
|
||||
bytes += sizeof(rab_release_req_t);
|
||||
break;
|
||||
|
||||
case AS_RAB_RELEASE_IND:
|
||||
/* Radio Access Bearer release indication */
|
||||
bytes += sizeof(rab_release_ind_t);
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_TRACE(WARNING, "NET-API - AS message 0x%x is not valid",
|
||||
msg->msgID);
|
||||
bytes = length;
|
||||
break;
|
||||
}
|
||||
|
||||
if (length > bytes) {
|
||||
/* Encode the AS message */
|
||||
memcpy(buffer, (unsigned char*)msg, bytes);
|
||||
|
||||
if ( nas_msg && (nas_msg->length > 0) ) {
|
||||
/* Copy the NAS message */
|
||||
memcpy(buffer + bytes, nas_msg->data, nas_msg->length);
|
||||
bytes += nas_msg->length;
|
||||
/* Release NAS message memory */
|
||||
free(nas_msg->data);
|
||||
nas_msg->length = 0;
|
||||
nas_msg->data = NULL;
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN (bytes);
|
||||
}
|
||||
|
||||
LOG_TRACE(WARNING, "NET-API - Failed to encode AS message 0x%x",
|
||||
msg->msgID);
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/********************* L O C A L F U N C T I O N S *********************/
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../openair2/COMMON/as_message.h
|
||||
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
|
||||
Source as_message.h
|
||||
|
||||
Version 0.1
|
||||
|
||||
Date 2012/10/18
|
||||
|
||||
Product NAS stack
|
||||
|
||||
Subsystem Application Programming Interface
|
||||
|
||||
Author Frederic Maurel
|
||||
|
||||
Description Defines the messages supported by the Access Stratum sublayer
|
||||
protocol (usually RRC and S1AP for E-UTRAN) and functions used
|
||||
to encode and decode
|
||||
|
||||
*****************************************************************************/
|
||||
#ifndef __AS_MESSAGE_H__
|
||||
#define __AS_MESSAGE_H__
|
||||
|
||||
#include "commonDef.h"
|
||||
#include "networkDef.h"
|
||||
|
||||
/****************************************************************************/
|
||||
/********************* G L O B A L C O N S T A N T S *******************/
|
||||
/****************************************************************************/
|
||||
|
||||
/* Access Stratum Message types */
|
||||
#define AS_REQUEST 0x0100
|
||||
#define AS_RESPONSE 0x0200
|
||||
#define AS_INDICATION 0x0400
|
||||
#define AS_CONFIRM 0x0800
|
||||
|
||||
/*
|
||||
* Access Stratum Message identifiers
|
||||
* ----------------------------------
|
||||
*/
|
||||
|
||||
/* Cell information relevant for cell selection processing */
|
||||
#define AS_CELL_INFO 0x01
|
||||
#define AS_CELL_INFO_REQ (AS_CELL_INFO | AS_REQUEST)
|
||||
#define AS_CELL_INFO_RSP (AS_CELL_INFO | AS_RESPONSE)
|
||||
#define AS_CELL_INFO_IND (AS_CELL_INFO | AS_INDICATION)
|
||||
|
||||
/* Security mode control */
|
||||
#define AS_SECURITY 0x02
|
||||
#define AS_SECURITY_REQ (AS_SECURITY | AS_REQUEST)
|
||||
#define AS_SECURITY_RSP (AS_SECURITY | AS_RESPONSE)
|
||||
|
||||
/* Paging information */
|
||||
#define AS_PAGING 0x03
|
||||
#define AS_PAGING_IND (AS_PAGING | AS_INDICATION)
|
||||
|
||||
/* NAS signalling connection establishment */
|
||||
#define AS_NAS_ESTABLISH 0x04
|
||||
#define AS_NAS_ESTABLISH_REQ (AS_NAS_ESTABLISH | AS_REQUEST)
|
||||
#define AS_NAS_ESTABLISH_RSP (AS_NAS_ESTABLISH | AS_RESPONSE)
|
||||
|
||||
/* NAS signalling connection release */
|
||||
#define AS_NAS_RELEASE 0x05
|
||||
#define AS_NAS_RELEASE_REQ (AS_NAS_RELEASE | AS_REQUEST)
|
||||
#define AS_NAS_RELEASE_IND (AS_NAS_RELEASE | AS_INDICATION)
|
||||
|
||||
/* NAS information transfer */
|
||||
#define AS_INFO_TRANSFER 0x10
|
||||
#define AS_UL_INFO_TRANSFER (AS_INFO_TRANSFER | AS_REQUEST)
|
||||
#define AS_DL_INFO_TRANSFER (AS_INFO_TRANSFER | AS_INDICATION)
|
||||
|
||||
/****************************************************************************/
|
||||
/************************ G L O B A L T Y P E S ************************/
|
||||
/****************************************************************************/
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* Available PLMNs and cell Information
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* Radio access technologies supported by the network */
|
||||
#define AS_GSM (1 << NET_ACCESS_GSM)
|
||||
#define AS_COMPACT (1 << NET_ACCESS_COMPACT)
|
||||
#define AS_UTRAN (1 << NET_ACCESS_UTRAN)
|
||||
#define AS_EGPRS (1 << NET_ACCESS_EGPRS)
|
||||
#define AS_HSDPA (1 << NET_ACCESS_HSDPA)
|
||||
#define AS_HSUPA (1 << NET_ACCESS_HSUPA)
|
||||
#define AS_HSDUPA (1 << NET_ACCESS_HSDUPA)
|
||||
#define AS_EUTRAN (1 << NET_ACCESS_EUTRAN)
|
||||
|
||||
/*
|
||||
* NAS->AS - Cell Information request
|
||||
* NAS request AS to search for a suitable cell belonging to the selected
|
||||
* PLMN to camp on.
|
||||
*/
|
||||
typedef struct {
|
||||
plmn_t plmnID; /* PLMN identifier */
|
||||
Byte_t rat; /* Bitmap - set of radio access technologies */
|
||||
} cell_info_req_t;
|
||||
|
||||
/*
|
||||
* AS->NAS - Cell Information response
|
||||
* AS search for a suitable cell and respond to NAS. If found, the cell
|
||||
* is selected to camp on.
|
||||
*/
|
||||
typedef struct {
|
||||
plmn_t plmnID; /* PLMN identifier */
|
||||
TAC_t tac; /* identifies a tracking area the PLMN belongs to */
|
||||
CI_t cellID; /* identifies a cell within a PLMN */
|
||||
AcT_t rat; /* radio access technology supported by the cell */
|
||||
} cell_info_rsp_t;
|
||||
|
||||
/*
|
||||
* AS->NAS - Cell Information indication
|
||||
* AS Reports available PLMNs with associated Radio Access Technologies
|
||||
* to NAS on request from NAS or autonomously.
|
||||
*/
|
||||
typedef struct {
|
||||
#define PLMN_LIST_MAX_SIZE 6
|
||||
PLMN_LIST_T(PLMN_LIST_MAX_SIZE) plmnIDs; /* List of PLMN identifiers */
|
||||
Byte_t rat[PLMN_LIST_MAX_SIZE]; /* Radio access technologies */
|
||||
TAC_t tac; /* identifies a tracking area within a scope of PLMNs */
|
||||
CI_t cellID; /* identifies a cell within a PLMN */
|
||||
} cell_info_ind_t;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* Security mode control
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO: NAS->AS - Security command request
|
||||
*/
|
||||
typedef struct {} security_req_t;
|
||||
|
||||
|
||||
/*
|
||||
* TODO: AS->NAS - Security command response
|
||||
*/
|
||||
typedef struct {} security_rsp_t;
|
||||
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* Paging information
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO: AS->NAS - Paging Information indication
|
||||
*/
|
||||
typedef struct {} paging_ind_t;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* NAS signalling connection establishment
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* Cause of RRC connection establishment */
|
||||
#define AS_CAUSE_EMERGENCY (NET_ESTABLISH_CAUSE_EMERGENCY)
|
||||
#define AS_CAUSE_HIGH_PRIO (NET_ESTABLISH_CAUSE_HIGH_PRIO)
|
||||
#define AS_CAUSE_MT_ACCESS (NET_ESTABLISH_CAUSE_MT_ACCESS)
|
||||
#define AS_CAUSE_MO_SIGNAL (NET_ESTABLISH_CAUSE_MO_SIGNAL)
|
||||
#define AS_CAUSE_MO_DATA (NET_ESTABLISH_CAUSE_MO_DATA)
|
||||
#define AS_CAUSE_V1020 (NET_ESTABLISH_CAUSE_V1020)
|
||||
|
||||
/* Type of the call associated to the RRC connection establishment */
|
||||
#define AS_TYPE_ORIGINATING_SIGNAL (NET_ESTABLISH_TYPE_ORIGINATING_SIGNAL)
|
||||
#define AS_TYPE_EMERGENCY_CALLS (NET_ESTABLISH_TYPE_EMERGENCY_CALLS)
|
||||
#define AS_TYPE_ORIGINATING_CALLS (NET_ESTABLISH_TYPE_ORIGINATING_CALLS)
|
||||
#define AS_TYPE_TERMINATING_CALLS (NET_ESTABLISH_TYPE_TERMINATING_CALLS)
|
||||
#define AS_TYPE_MO_CS_FALLBACK (NET_ESTABLISH_TYPE_MO_CS_FALLBACK)
|
||||
|
||||
|
||||
/* Structure of the SAE Temporary Mobile Subscriber Identity */
|
||||
typedef struct {
|
||||
uint8_t MMEcode; /* MME code that allocated the GUTI */
|
||||
uint32_t m_tmsi; /* M-Temporary Mobile Subscriber Identity */
|
||||
} as_stmsi_t;
|
||||
|
||||
/* Structure of the dedicated NAS information */
|
||||
typedef struct {
|
||||
uint32_t length; /* Length of the NAS information data */
|
||||
Byte_t* data; /* Dedicated NAS information data container */
|
||||
} as_nas_info_t;
|
||||
|
||||
/*
|
||||
* NAS->AS - NAS signalling connection establishment request
|
||||
* NAS request AS to perform the RRC connection establishment procedure
|
||||
* to transfer initial NAS message to the network while UE is in IDLE mode.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t cause; /* Connection establishment cause */
|
||||
uint8_t type; /* Associated call type */
|
||||
plmn_t plmnID; /* Identifier of the selected PLMN */
|
||||
as_stmsi_t s_tmsi; /* SAE Temporary Mobile Subscriber Identity */
|
||||
as_nas_info_t initialNasMsg;/* Initial NAS message to transfer */
|
||||
} nas_establish_req_t;
|
||||
|
||||
/*
|
||||
* TODO: AS->NAS - NAS signalling connection establishment response
|
||||
*/
|
||||
typedef struct {} nas_establish_rsp_t;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* NAS signalling connection release
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO: NAS->AS - NAS signalling connection release request
|
||||
*/
|
||||
typedef struct {} nas_release_req_t;
|
||||
|
||||
/*
|
||||
* TODO: AS->NAS - NAS signalling connection release indication
|
||||
*/
|
||||
typedef struct {} nas_release_ind_t;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* NAS information transfer
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* AS->NAS - Downlink data transfer
|
||||
* AS notifies upper layer that NAS or non-3GPP dedicated downlink information
|
||||
* has to be transfered to NAS.
|
||||
*/
|
||||
typedef as_nas_info_t dl_info_transfer_t;
|
||||
|
||||
/*
|
||||
* NAS->AS - Uplink data transfer request
|
||||
* NAS requests under layer to transfer NAS or non-3GPP dedicated uplink
|
||||
* information to AS.
|
||||
*/
|
||||
typedef as_nas_info_t ul_info_transfer_t;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* Structure of the AS messages handled by the network sublayer
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t msgID;
|
||||
union {
|
||||
cell_info_req_t cell_info_req;
|
||||
cell_info_rsp_t cell_info_rsp;
|
||||
cell_info_ind_t cell_info_ind;
|
||||
security_req_t security_req;
|
||||
security_rsp_t security_rsp;
|
||||
paging_ind_t paging_ind;
|
||||
nas_establish_req_t nas_establish_req;
|
||||
nas_establish_rsp_t nas_establish_rsp;
|
||||
nas_release_req_t nas_release_req;
|
||||
nas_release_ind_t nas_release_ind;
|
||||
ul_info_transfer_t ul_info_transfer;
|
||||
dl_info_transfer_t dl_info_transfer;
|
||||
} __attribute__((__packed__)) msg;
|
||||
} as_message_t;
|
||||
|
||||
/****************************************************************************/
|
||||
/******************** G L O B A L V A R I A B L E S ********************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/****************** E X P O R T E D F U N C T I O N S ******************/
|
||||
/****************************************************************************/
|
||||
|
||||
int as_message_decode(const char* buffer, int length, as_message_t* msg);
|
||||
|
||||
int as_message_encode(char* buffer, int length, const as_message_t* msg);
|
||||
|
||||
/* Implemented in the network_api.c body file */
|
||||
int as_message_send(as_message_t* as_msg, const void* nas_msg);
|
||||
|
||||
#endif /* __AS_MESSAGE_H__*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
|
||||
Source nas_message.h
|
||||
|
||||
Version 0.1
|
||||
|
||||
Date 2012/26/09
|
||||
|
||||
Product NAS stack
|
||||
|
||||
Subsystem Application Programming Interface
|
||||
|
||||
Author Frederic Maurel
|
||||
|
||||
Description Defines the layer 3 messages supported by the NAS sublayer
|
||||
protocol and functions used to encode and decode
|
||||
|
||||
*****************************************************************************/
|
||||
#ifndef __NAS_MESSAGE_H__
|
||||
#define __NAS_MESSAGE_H__
|
||||
|
||||
#include "commonDef.h"
|
||||
#include "emm_msg.h"
|
||||
#if defined(NAS_BUILT_IN_EPC)
|
||||
#include "emmData.h"
|
||||
#endif
|
||||
#include "esm_msg.h"
|
||||
|
||||
/****************************************************************************/
|
||||
/********************* G L O B A L C O N S T A N T S *******************/
|
||||
/****************************************************************************/
|
||||
|
||||
#define NAS_MESSAGE_SECURITY_HEADER_SIZE 6
|
||||
|
||||
/****************************************************************************/
|
||||
/************************ G L O B A L T Y P E S ************************/
|
||||
/****************************************************************************/
|
||||
|
||||
/* Structure of security protected header */
|
||||
typedef struct {
|
||||
#ifdef __LITTLE_ENDIAN_BITFIELD
|
||||
eps_protocol_discriminator_t protocol_discriminator:4;
|
||||
uint8_t security_header_type:4;
|
||||
#endif
|
||||
#ifdef __BIG_ENDIAN_BITFIELD
|
||||
uint8_t security_header_type:4;
|
||||
uint8_t protocol_discriminator:4;
|
||||
#endif
|
||||
uint32_t message_authentication_code;
|
||||
uint8_t sequence_number;
|
||||
} nas_message_security_header_t;
|
||||
|
||||
/* Structure of plain NAS message */
|
||||
typedef union {
|
||||
EMM_msg emm; /* EPS Mobility Management messages */
|
||||
ESM_msg esm; /* EPS Session Management messages */
|
||||
} nas_message_plain_t;
|
||||
|
||||
/* Structure of security protected NAS message */
|
||||
typedef struct {
|
||||
nas_message_security_header_t header;
|
||||
nas_message_plain_t plain;
|
||||
} nas_message_security_protected_t;
|
||||
|
||||
/*
|
||||
* Structure of a layer 3 NAS message
|
||||
*/
|
||||
typedef union {
|
||||
nas_message_security_header_t header;
|
||||
nas_message_security_protected_t security_protected;
|
||||
nas_message_plain_t plain;
|
||||
} nas_message_t;
|
||||
|
||||
/****************************************************************************/
|
||||
/******************** G L O B A L V A R I A B L E S ********************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/****************** E X P O R T E D F U N C T I O N S ******************/
|
||||
/****************************************************************************/
|
||||
|
||||
int nas_message_encrypt(
|
||||
const char *inbuf,
|
||||
char *outbuf,
|
||||
const nas_message_security_header_t *header,
|
||||
int length,
|
||||
void *security);
|
||||
|
||||
int nas_message_decrypt(const char *inbuf,
|
||||
char *outbuf,
|
||||
nas_message_security_header_t *header,
|
||||
int length,
|
||||
void *security);
|
||||
|
||||
int nas_message_decode(
|
||||
const char * const buffer,
|
||||
nas_message_t *msg,
|
||||
int length,
|
||||
void *security);
|
||||
|
||||
int nas_message_encode(
|
||||
char *buffer,
|
||||
const nas_message_t * const msg,
|
||||
int length,
|
||||
void *security);
|
||||
|
||||
#endif /* __NAS_MESSAGE_H__*/
|
||||
@@ -0,0 +1,447 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
|
||||
Source network_api.c
|
||||
|
||||
Version 0.1
|
||||
|
||||
Date 2012/03/01
|
||||
|
||||
Product NAS stack
|
||||
|
||||
Subsystem Application Programming Interface
|
||||
|
||||
Author Frederic Maurel
|
||||
|
||||
Description Implements the API used by the NAS layer to send/receive
|
||||
message to/from the network sublayer
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "network_api.h"
|
||||
#include "commonDef.h"
|
||||
#include "nas_log.h"
|
||||
#include "socket.h"
|
||||
|
||||
#include "as_message.h"
|
||||
|
||||
#include <string.h> // strerror, memset
|
||||
#include <netdb.h> // gai_strerror
|
||||
#include <errno.h> // errno
|
||||
#include <unistd.h> // gethostname
|
||||
|
||||
/****************************************************************************/
|
||||
/**************** E X T E R N 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 *******************/
|
||||
/****************************************************************************/
|
||||
|
||||
/* -------------------
|
||||
* Connection endpoint
|
||||
* -------------------
|
||||
* The connection endpoint is used to send/receive data to/from the
|
||||
* network sublayer. Its definition depends on the underlaying mechanism
|
||||
* chosen to communicate (network socket, I/O terminal device, async FIFO).
|
||||
* A connection endpoint is handled using an identifier, and functions
|
||||
* used to retreive the file descriptor actually allocated by the system,
|
||||
* to receive data, to send data, and to perform clean up when connection
|
||||
* is shut down.
|
||||
* Only one single end to end connection with the network sublayer is
|
||||
* managed at a time.
|
||||
*/
|
||||
static struct {
|
||||
/* Connection endpoint reference */
|
||||
void* endpoint;
|
||||
/* Connection endpoint handlers */
|
||||
void* (*open) (int, const char*, const char*);
|
||||
int (*getfd)(const void*);
|
||||
ssize_t (*recv) (void*, char*, size_t);
|
||||
ssize_t (*send) (const void*, const char*, size_t);
|
||||
void (*close)(void*);
|
||||
} _network_api_id;
|
||||
|
||||
#define NETWORK_API_OPEN(a, b, c) _network_api_id.open(a, b, c)
|
||||
#define NETWORK_API_GETFD() _network_api_id.getfd(_network_api_id.endpoint)
|
||||
#define NETWORK_API_RECV(a, b) _network_api_id.recv(_network_api_id.endpoint, a, b)
|
||||
#define NETWORK_API_SEND(a, b) _network_api_id.send(_network_api_id.endpoint, a, b)
|
||||
#define NETWORK_API_CLOSE() _network_api_id.close(_network_api_id.endpoint)
|
||||
|
||||
/*
|
||||
* The buffer used to receive data from the network sublayer
|
||||
*/
|
||||
#define NETWORK_API_RECV_BUFFER_SIZE 4096
|
||||
static char _network_api_recv_buffer[NETWORK_API_RECV_BUFFER_SIZE];
|
||||
|
||||
/*
|
||||
* The buffer used to send data to the network sublayer
|
||||
*/
|
||||
#define NETWORK_API_SEND_BUFFER_SIZE NETWORK_API_RECV_BUFFER_SIZE
|
||||
static char _network_api_send_buffer[NETWORK_API_SEND_BUFFER_SIZE];
|
||||
|
||||
/*
|
||||
* The decoded data received from the network sublayer
|
||||
*/
|
||||
static as_message_t _as_data = {}; /* Access Stratum message */
|
||||
|
||||
/****************************************************************************/
|
||||
/****************** E X P O R T E D F U N C T I O N S ******************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_initialize() **
|
||||
** **
|
||||
** Description: Initializes the network API from which the NAS layer **
|
||||
** will send/receive messages to/from the network sublayer **
|
||||
** **
|
||||
** Inputs: host: The name of the host from which the net- **
|
||||
** work sublayer will connect **
|
||||
** port: The local port number **
|
||||
** Others: None **
|
||||
** **
|
||||
** Outputs: Return: RETURNerror, RETURNok **
|
||||
** Others: _network_api_id **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int network_api_initialize(const char* host, const char* port)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
/* Initialize network socket handlers */
|
||||
_network_api_id.open = socket_udp_open;
|
||||
_network_api_id.getfd = socket_get_fd;
|
||||
_network_api_id.recv = socket_recv;
|
||||
_network_api_id.send = socket_send;
|
||||
_network_api_id.close = socket_close;
|
||||
/* Initialize UDP communication channel with the network layer */
|
||||
#ifdef NAS_UE
|
||||
_network_api_id.endpoint = NETWORK_API_OPEN(SOCKET_CLIENT, host, port);
|
||||
#endif
|
||||
#ifdef NAS_MME
|
||||
_network_api_id.endpoint = NETWORK_API_OPEN(SOCKET_SERVER, NULL, port);
|
||||
#endif
|
||||
|
||||
if (_network_api_id.endpoint == NULL) {
|
||||
const char* error = ( (errno < 0) ?
|
||||
gai_strerror(errno) : strerror(errno) );
|
||||
LOG_TRACE(ERROR, "NET-API - Failed to open connection endpoint, %s",
|
||||
error);
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
}
|
||||
|
||||
gethostname(_network_api_send_buffer, NETWORK_API_SEND_BUFFER_SIZE);
|
||||
LOG_TRACE(INFO, "NET-API - Network's UDP socket %d is BOUND to %s/%s",
|
||||
network_api_get_fd(), _network_api_send_buffer, port);
|
||||
|
||||
LOG_FUNC_RETURN (RETURNok);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_get_fd() **
|
||||
** **
|
||||
** Description: Get the file descriptor of the connection endpoint used **
|
||||
** to send/receive messages to/from the network sublayer **
|
||||
** **
|
||||
** Inputs: None **
|
||||
** Others: _network_api_id **
|
||||
** **
|
||||
** Outputs: Return: The file descriptor of the connection end- **
|
||||
** point used by the network sublayer **
|
||||
** Others: None **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int network_api_get_fd(void)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
LOG_FUNC_RETURN (NETWORK_API_GETFD());
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_get_data() **
|
||||
** **
|
||||
** Description: Get a generic pointer to the network data structure. **
|
||||
** Casting to the proper type is necessary before its usage. **
|
||||
** **
|
||||
** Inputs: None **
|
||||
** Others: _as_data **
|
||||
** **
|
||||
** Outputs: Return: A generic pointer to the network data **
|
||||
** structure **
|
||||
** Others: None **
|
||||
** **
|
||||
***************************************************************************/
|
||||
const void* network_api_get_data(void)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
LOG_FUNC_RETURN ((void*)(&_as_data));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_read_data() **
|
||||
** **
|
||||
** Description: Read data received from the network sublayer **
|
||||
** **
|
||||
** Inputs: fd: File descriptor of the connection endpoint **
|
||||
** from which data have been received **
|
||||
** Others: _network_api_id **
|
||||
** **
|
||||
** Outputs: Return: The number of bytes read when success; **
|
||||
** RETURNerror otherwise **
|
||||
** Others: _network_api_recv_buffer, _network_api_id **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int network_api_read_data(int fd)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
int rbytes;
|
||||
|
||||
/* Sanity check */
|
||||
int sfd = network_api_get_fd();
|
||||
|
||||
if (fd != sfd) {
|
||||
LOG_TRACE(ERROR, "NET-API - Endpoint %d is not the one created for communication with the network sublayer (%d)", fd, sfd);
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
}
|
||||
|
||||
memset(_network_api_recv_buffer, 0, NETWORK_API_RECV_BUFFER_SIZE);
|
||||
|
||||
/* Receive data from the network sublayer */
|
||||
rbytes = NETWORK_API_RECV(_network_api_recv_buffer,
|
||||
NETWORK_API_RECV_BUFFER_SIZE);
|
||||
|
||||
if (rbytes == RETURNerror) {
|
||||
LOG_TRACE(ERROR, "NET-API - recv() failed, %s", strerror(errno));
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
} else if (rbytes == 0) {
|
||||
LOG_TRACE(WARNING, "NET-API - A signal was caught");
|
||||
} else {
|
||||
LOG_TRACE(INFO, "NET-API - %d bytes received from the network "
|
||||
"sublayer", rbytes);
|
||||
LOG_DUMP(_network_api_recv_buffer, rbytes);
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN (rbytes);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_send_data() **
|
||||
** **
|
||||
** Description: Send data to the network sublayer **
|
||||
** **
|
||||
** Inputs: fd: File descriptor of the connection endpoint **
|
||||
** to which data have to be sent **
|
||||
** length: Number of bytes to send **
|
||||
** Others: _network_api_send_buffer, _network_api_id **
|
||||
** **
|
||||
** Outputs: Return: The number of bytes sent when success; **
|
||||
** RETURNerror otherwise **
|
||||
** Others: None **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int network_api_send_data(int fd, int length)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
int sbytes;
|
||||
|
||||
/* Sanity check */
|
||||
int sfd = network_api_get_fd();
|
||||
|
||||
if (fd != sfd) {
|
||||
LOG_TRACE(ERROR, "NET-API - Endpoint %d is not the one created for communication with the network sublayer (%d)", fd, sfd);
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
}
|
||||
|
||||
/* Send data to the network sublayer */
|
||||
sbytes = NETWORK_API_SEND(_network_api_send_buffer, length);
|
||||
|
||||
if (sbytes == RETURNerror) {
|
||||
LOG_TRACE(ERROR, "NET-API - send() failed, %s", strerror(errno));
|
||||
LOG_FUNC_RETURN (RETURNerror);
|
||||
} else if (sbytes == 0) {
|
||||
LOG_TRACE(WARNING, "NET-API - A signal was caught");
|
||||
} else {
|
||||
LOG_TRACE(INFO, "NET-API - %d bytes sent to the network sublayer",
|
||||
sbytes);
|
||||
LOG_DUMP(_network_api_send_buffer, sbytes);
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN (sbytes);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_close() **
|
||||
** **
|
||||
** Description: Clean the network API from which the NAS layer sent/recei-**
|
||||
** ved messages to/from the network sublayer **
|
||||
** **
|
||||
** Inputs: fd: File descriptor of the connection endpoint **
|
||||
** allocated by the system to communicate **
|
||||
** with the network sublayer **
|
||||
** Others: None **
|
||||
** **
|
||||
** Outputs: Return: None **
|
||||
** Others: _network_api_id **
|
||||
** **
|
||||
***************************************************************************/
|
||||
void network_api_close(int fd)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
/* Sanity check */
|
||||
int sfd = network_api_get_fd();
|
||||
|
||||
if (fd != sfd) {
|
||||
LOG_TRACE(ERROR, "NET-API - Endpoint %d is not the one created for communication with the network sublayer (%d)", fd, sfd);
|
||||
LOG_FUNC_OUT;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Cleanup the connection endpoint */
|
||||
NETWORK_API_CLOSE();
|
||||
_network_api_id.endpoint = NULL;
|
||||
|
||||
LOG_FUNC_OUT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_decode_data() **
|
||||
** **
|
||||
** Description: Decodes the message received from the network and fills **
|
||||
** the corresponding network data structure. **
|
||||
** **
|
||||
** Inputs: length: Number of bytes to decode **
|
||||
** Others: _network_api_recv_buffer **
|
||||
** **
|
||||
** Outputs: Return: The identifier of the received AS **
|
||||
** message when successfully decoded; **
|
||||
** RETURNerror otherwise **
|
||||
** Others: _as_data **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int network_api_decode_data(int length)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
/* Decode the Access Stratum message received from the network */
|
||||
int as_id = as_message_decode(_network_api_recv_buffer, &_as_data, length);
|
||||
|
||||
if (as_id != RETURNerror) {
|
||||
LOG_TRACE(INFO, "NET-API - AS message id=0x%x successfully decoded",
|
||||
as_id);
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN (as_id);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: network_api_encode_data() **
|
||||
** **
|
||||
** Description: Encodes Access Stratum message to be sent to the network **
|
||||
** **
|
||||
** Inputs data: Generic pointer to the AS data to encode **
|
||||
** Others: None **
|
||||
** **
|
||||
** Outputs: Return: The number of characters that have been **
|
||||
** successfully encoded; **
|
||||
** RETURNerror otherwise. **
|
||||
** Others: _network_api_send_buffer **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int network_api_encode_data(void* data)
|
||||
{
|
||||
LOG_FUNC_IN;
|
||||
|
||||
/* Encode the Access Stratum message */
|
||||
int bytes = as_message_encode(_network_api_send_buffer,
|
||||
(as_message_t*)(data),
|
||||
NETWORK_API_SEND_BUFFER_SIZE);
|
||||
|
||||
if (bytes != RETURNerror) {
|
||||
LOG_TRACE(INFO, "NET-API - %d bytes encoded", bytes);
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN (bytes);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** **
|
||||
** Name: as_message_send() **
|
||||
** **
|
||||
** Description: Service provided to the EPS Mobility Management protocol **
|
||||
** at the EMMAS Access Point (EMMAS-SAP) to send AS messages **
|
||||
** to the Access Stratum sublayer. **
|
||||
** **
|
||||
** Inputs: as_msg: The AS message to send **
|
||||
** Others: _network_api_send_buffer, _network_api_id **
|
||||
** **
|
||||
** Outputs: Return: The number of bytes sent when success; **
|
||||
** RETURNerror Otherwise **
|
||||
** Others: _network_api_send_buffer **
|
||||
** **
|
||||
***************************************************************************/
|
||||
int as_message_send(as_message_t* as_msg)
|
||||
{
|
||||
int bytes;
|
||||
LOG_FUNC_IN;
|
||||
|
||||
LOG_TRACE(INFO, "NET-API - Send message 0x%.4x to the Access Stratum "
|
||||
"layer", as_msg->msgID);
|
||||
|
||||
/* Encode the AS message */
|
||||
bytes = network_api_encode_data(as_msg);
|
||||
|
||||
if (bytes > 0) {
|
||||
/* Get the network file descriptor */
|
||||
int fd = network_api_get_fd();
|
||||
|
||||
if (fd != RETURNerror) {
|
||||
/* Send the AS message to the network */
|
||||
bytes = network_api_send_data(fd, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN (bytes);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/********************* L O C A L F U N C T I O N S *********************/
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
|
||||
Source network_api.h
|
||||
|
||||
Version 0.1
|
||||
|
||||
Date 2012/03/01
|
||||
|
||||
Product NAS stack
|
||||
|
||||
Subsystem Application Programming Interface
|
||||
|
||||
Author Frederic Maurel
|
||||
|
||||
Description Implements the API used by the NAS layer to send/receive
|
||||
message to/from the network layer
|
||||
|
||||
*****************************************************************************/
|
||||
#ifndef __NETWORK_API_H__
|
||||
#define __NETWORK_API_H__
|
||||
|
||||
/****************************************************************************/
|
||||
/********************* G L O B A L C O N S T A N T S *******************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/************************ G L O B A L T Y P E S ************************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/******************** G L O B A L V A R I A B L E S ********************/
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/****************** E X P O R T E D F U N C T I O N S ******************/
|
||||
/****************************************************************************/
|
||||
|
||||
int network_api_initialize(const char* host, const char* port);
|
||||
|
||||
int network_api_get_fd(void);
|
||||
const void* network_api_get_data(void);
|
||||
|
||||
int network_api_read_data(int fd);
|
||||
int network_api_send_data(int fd, int length);
|
||||
void network_api_close(int fd);
|
||||
|
||||
int network_api_decode_data(int length);
|
||||
int network_api_encode_data(void* data);
|
||||
|
||||
#endif /* __NETWORK_API_H__*/
|
||||
Reference in New Issue
Block a user