Fix APN message build/parse bugs

This commit is contained in:
Sukchan Lee 2017-08-19 20:16:00 +09:00
parent 9b523b043f
commit eb8f9c66ed
11 changed files with 52 additions and 22 deletions

View File

@ -1,6 +1,8 @@
#define TRACE_MODULE _types
#include "core_debug.h"
#include "core_lib.h"
#include "types.h"
#define PLMN_ID_DIGIT1(x) (((x) / 100) % 10)
@ -39,6 +41,28 @@ void *plmn_id_build(plmn_id_t *plmn_id,
return plmn_id;
}
c_int16_t apn_build(c_int8_t *dst, c_int8_t *src, c_int16_t len)
{
char *dot = NULL;
core_cpystrn(dst+1, src, c_min(len, MAX_APN_LEN)+1);
dot = strchr(src, '.');
if (dot)
dst[0] = src - dot;
else
dst[0] = len;
return len+1;
}
c_int16_t apn_parse(c_int8_t *dst, c_int8_t *src, c_int16_t len)
{
core_cpystrn(dst, src+1, c_min(len, MAX_APN_LEN)+1);
return len-1;
}
/* 8.13 Protocol Configuration Options (PCO)
* 10.5.6.3 Protocol configuration options in 3GPP TS 24.008 */
c_int16_t pco_parse(pco_t *pco, void *data, int data_len)

View File

@ -150,6 +150,9 @@ typedef struct _pdn_t {
qos_t qos;
} pdn_t;
CORE_DECLARE(c_int16_t) apn_build(c_int8_t *dst, c_int8_t *src, c_int16_t len);
CORE_DECLARE(c_int16_t) apn_parse(c_int8_t *dst, c_int8_t *src, c_int16_t len);
/**************************************************
* Protocol Configuration Options Structure
* 8.13 Protocol Configuration Options (PCO)

View File

@ -26,7 +26,7 @@
/*******************************************************************************
* This file had been created by gtpv2c_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-08-19 16:43:29.568100 by acetcom
* Created on: 2017-08-19 20:12:24.377058 by acetcom
* from 24301-d80.docx
******************************************************************************/

View File

@ -26,7 +26,7 @@
/*******************************************************************************
* This file had been created by gtpv2c_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-08-19 16:43:29.597664 by acetcom
* Created on: 2017-08-19 20:12:24.408238 by acetcom
* from 24301-d80.docx
******************************************************************************/

View File

@ -26,7 +26,7 @@
/*******************************************************************************
* This file had been created by gtpv2c_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-08-19 16:43:29.530361 by acetcom
* Created on: 2017-08-19 20:12:24.335882 by acetcom
* from 24301-d80.docx
******************************************************************************/
@ -2156,8 +2156,11 @@ c_int16_t nas_decode_access_point_name(nas_access_point_name_t *access_point_nam
d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error");
memcpy(access_point_name, pkbuf->payload - size, size);
memmove(&access_point_name->apn[0], &access_point_name->apn[1], access_point_name->length);
access_point_name->length--;
{
c_int8_t apn[MAX_APN_LEN];
access_point_name->length = apn_parse(apn, access_point_name->apn, access_point_name->length);
core_cpystrn(access_point_name->apn, apn, c_min(access_point_name->length, MAX_APN_LEN) + 1);
}
d_trace(5, " ACCESS_POINT_NAME - ");
d_trace_hex(5, pkbuf->payload - size, size);
@ -2171,9 +2174,8 @@ c_int16_t nas_encode_access_point_name(pkbuf_t *pkbuf, nas_access_point_name_t *
nas_access_point_name_t target;
memcpy(&target, access_point_name, sizeof(nas_access_point_name_t));
core_cpystrn(&target.apn[1], &access_point_name->apn[0], c_min(access_point_name->length, MAX_APN_LEN) + 1);
target.apn[0] = access_point_name->length;
target.length++; size++;
target.length = apn_build(target.apn, access_point_name->apn, access_point_name->length);
size = target.length + sizeof(target.length);
d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error");
memcpy(pkbuf->payload - size, &target, size);

View File

@ -26,7 +26,7 @@
/*******************************************************************************
* This file had been created by gtpv2c_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-08-19 16:43:29.525216 by acetcom
* Created on: 2017-08-19 20:12:24.329018 by acetcom
* from 24301-d80.docx
******************************************************************************/

View File

@ -26,7 +26,7 @@
/*******************************************************************************
* This file had been created by gtpv2c_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-08-19 16:43:29.546027 by acetcom
* Created on: 2017-08-19 20:12:24.353303 by acetcom
* from 24301-d80.docx
******************************************************************************/

View File

@ -88,10 +88,12 @@ type_list["Short MAC"]["encode"] = \
" target = htons(*short_mac);\n\n"
type_list["Access point name"]["decode"] = \
" memmove(&access_point_name->apn[0], &access_point_name->apn[1], access_point_name->length);\n" \
" access_point_name->length--;\n\n"
" {\n" \
" c_int8_t apn[MAX_APN_LEN];\n" \
" access_point_name->length = apn_parse(apn, access_point_name->apn, access_point_name->length);\n" \
" core_cpystrn(access_point_name->apn, apn, c_min(access_point_name->length, MAX_APN_LEN) + 1);\n" \
" }\n\n"
type_list["Access point name"]["encode"] = \
" core_cpystrn(&target.apn[1], &access_point_name->apn[0], c_min(access_point_name->length, MAX_APN_LEN) + 1);\n" \
" target.apn[0] = access_point_name->length;\n" \
" target.length++; size++;\n\n"
" target.length = apn_build(target.apn, access_point_name->apn, access_point_name->length);\n" \
" size = target.length + sizeof(target.length);\n\n"

View File

@ -1725,9 +1725,7 @@ pdn_t* mme_pdn_find_by_apn(mme_ue_t *mme_ue, c_int8_t *apn)
{
pdn = &mme_ue->pdn[i];
if (strcmp(pdn->apn, apn) == 0)
{
return pdn;
}
}
return NULL;

View File

@ -25,6 +25,7 @@ status_t mme_s11_build_create_session_request(pkbuf_t **pkbuf, mme_sess_t *sess)
gtp_bearer_qos_t bearer_qos;
char bearer_qos_buf[GTP_BEARER_QOS_LEN];
gtp_ue_timezone_t ue_timezone;
c_int8_t apn[MAX_APN_LEN];
d_assert(sess, return CORE_ERROR, "Null param");
sgw = sess->sgw;
@ -86,8 +87,8 @@ status_t mme_s11_build_create_session_request(pkbuf_t **pkbuf, mme_sess_t *sess)
req->pgw_s5_s8_address_for_control_plane_or_pmip.len = GTP_F_TEID_IPV4_LEN;
req->access_point_name.presence = 1;
req->access_point_name.data = pdn->apn;
req->access_point_name.len = strlen(pdn->apn);
req->access_point_name.len = apn_build(apn, pdn->apn, strlen(pdn->apn));
req->access_point_name.data = apn;
req->selection_mode.presence = 1;
req->selection_mode.u8 =

View File

@ -1,6 +1,7 @@
#define TRACE_MODULE _pgw_sm
#include "core_debug.h"
#include "core_lib.h"
#include "fd_lib.h"
#include "gx_lib.h"
@ -94,15 +95,14 @@ void pgw_state_operational(fsm_t *s, event_t *e)
break;
}
memcpy(apn,
apn_parse(apn,
req->access_point_name.data, req->access_point_name.len);
apn[req->access_point_name.len] = 0;
sess = pgw_sess_find_by_apn(apn);
if (!sess)
{
pgw_bearer_t *bearer = NULL;
bearer = pgw_sess_add(apn,
req->bearer_contexts_to_be_created.eps_bearer_id.u8);
req->bearer_contexts_to_be_created.eps_bearer_id.u8);
d_assert(bearer, pkbuf_free(pkbuf); break,
"No Bearer Context");
sess = bearer->sess;