From d53939d41ef09a8902edc077e29cd4577c37944d Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Tue, 21 Mar 2017 13:50:40 +0900 Subject: [PATCH] NAS parsing done --- lib/nas/Makefile.am | 2 +- lib/nas/nas_decoder.c | 701 +++++++++------ lib/nas/nas_encoder.c | 649 ++++++++++---- lib/nas/nas_ies.c | 1331 ++++++++++++++++------------ lib/nas/nas_ies.h | 1004 +++------------------ lib/nas/nas_message.h | 418 +++++---- lib/nas/nas_types.h | 740 ++++++++++++++++ lib/nas/support/cache/type_list.py | 29 + lib/nas/support/nas_message.py | 49 +- 9 files changed, 2833 insertions(+), 2090 deletions(-) create mode 100644 lib/nas/nas_types.h diff --git a/lib/nas/Makefile.am b/lib/nas/Makefile.am index e9ea60933..a6369d5ce 100644 --- a/lib/nas/Makefile.am +++ b/lib/nas/Makefile.am @@ -3,7 +3,7 @@ noinst_LTLIBRARIES = libnas.la libnas_la_SOURCES = \ - nas_message.h nas_ies.h + nas_message.h nas_ies.h nas_types.h nodist_libnas_la_SOURCES = \ nas_decoder.c nas_encoder.c nas_ies.c diff --git a/lib/nas/nas_decoder.c b/lib/nas/nas_decoder.c index 4025377c8..352c5b6ae 100644 --- a/lib/nas/nas_decoder.c +++ b/lib/nas/nas_decoder.c @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2017, CellWire Group + * 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. + */ + +/******************************************************************************* + * 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-03-21 13:49:52.087297 by acetcom + * from 24301-d80.docx + ******************************************************************************/ + #define TRACE_MODULE _nasdec #include "core_debug.h" @@ -6,25 +38,22 @@ c_int32_t nas_decode_attach_request(nas_message_t *message, pkbuf_t *pkbuf) { nas_attach_request_t *attach_request = &message->attach_request; - c_uint16_t decoded = 0; + c_int32_t decoded = 0; c_int32_t size = 0; size = nas_decode_eps_attach_type(&attach_request->eps_attach_type, pkbuf); d_assert(size >= 0, return -1, "decode failed"); decoded += size; - size = nas_decode_eps_mobile_identity( - &attach_request->eps_mobile_identity, pkbuf); + size = nas_decode_eps_mobile_identity(&attach_request->eps_mobile_identity, pkbuf); d_assert(size >= 0, return -1, "decode failed"); decoded += size; - size = nas_decode_ue_network_capability( - &attach_request->ue_network_capability, pkbuf); + size = nas_decode_ue_network_capability(&attach_request->ue_network_capability, pkbuf); d_assert(size >= 0, return -1, "decode failed"); decoded += size; - size = nas_decode_esm_message_container( - &attach_request->esm_message_container, pkbuf); + size = nas_decode_esm_message_container(&attach_request->esm_message_container, pkbuf); d_assert(size >= 0, return -1, "decode failed"); decoded += size; @@ -40,163 +69,245 @@ c_int32_t nas_decode_attach_request(nas_message_t *message, pkbuf_t *pkbuf) switch(type) { - case NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_TYPE: - size = nas_decode_p_tmsi_signature( - &attach_request->old_p_tmsi_signature, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_TYPE: - size = nas_decode_eps_mobile_identity( - &attach_request->additional_guti, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_TYPE: - size = nas_decode_tracking_area_identity( - &attach_request->last_visited_registered_tai, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_TYPE; - decoded += size; - break; - case NAS_ATTACH_REQUEST_DRX_PARAMETER_TYPE: - size = nas_decode_drx_parameter( - &attach_request->drx_parameter, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_DRX_PARAMETER_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_TYPE: - size = nas_decode_ms_network_capability( - &attach_request->ms_network_capability, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_TYPE: - size = nas_decode_location_area_identification( - &attach_request->old_location_area_identification, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_TMSI_STATUS_TYPE: - size = nas_decode_tmsi_status( - &attach_request->tmsi_status, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_TMSI_STATUS_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_TYPE: - size = nas_decode_mobile_station_classmark_2( - &attach_request->mobile_station_classmark_2, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_TYPE: - size = nas_decode_mobile_station_classmark_3( - &attach_request->mobile_station_classmark_3, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_SUPPORTED_CODECS_TYPE: - size = nas_decode_supported_codec_list( - &attach_request->supported_codecs, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_SUPPORTED_CODECS_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE: - size = nas_decode_additional_update_type( - &attach_request->additional_update_type, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_TYPE: - size = nas_decode_voice_domain_preference_and_ue_usage_setting( - &attach_request->voice_domain_preference_and_ue_usage_setting, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_TYPE: - size = nas_decode_device_properties( - &attach_request->device_properties, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_TYPE: - size = nas_decode_guti_type( - &attach_request->old_guti_type, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE: - size = nas_decode_ms_network_feature_support( - &attach_request->ms_network_feature_support, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_TYPE: - size = nas_decode_network_resource_identifier_container( - &attach_request->tmsi_based_nri_container, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_T3324_VALUE_TYPE: - size = nas_decode_gprs_timer_2( - &attach_request->t3324_value, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_T3324_VALUE_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_TYPE: - size = nas_decode_gprs_timer_3( - &attach_request->t3412_extended_value, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_PRESENT; - decoded += size; - break; - case NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_TYPE: - size = nas_decode_extended_drx_parameters( - &attach_request->extended_drx_parameters, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - attach_request->presencemask |= - NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_PRESENT; - decoded += size; - break; - default: + case NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_TYPE: + size = nas_decode_p_tmsi_signature(&attach_request->old_p_tmsi_signature, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_TYPE: + size = nas_decode_eps_mobile_identity(&attach_request->additional_guti, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_TYPE: + size = nas_decode_tracking_area_identity(&attach_request->last_visited_registered_tai, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_DRX_PARAMETER_TYPE: + size = nas_decode_drx_parameter(&attach_request->drx_parameter, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_DRX_PARAMETER_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_TYPE: + size = nas_decode_ms_network_capability(&attach_request->ms_network_capability, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_TYPE: + size = nas_decode_location_area_identification(&attach_request->old_location_area_identification, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_TMSI_STATUS_TYPE: + size = nas_decode_tmsi_status(&attach_request->tmsi_status, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_TMSI_STATUS_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_TYPE: + size = nas_decode_mobile_station_classmark_2(&attach_request->mobile_station_classmark_2, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_TYPE: + size = nas_decode_mobile_station_classmark_3(&attach_request->mobile_station_classmark_3, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_SUPPORTED_CODECS_TYPE: + size = nas_decode_supported_codec_list(&attach_request->supported_codecs, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_SUPPORTED_CODECS_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE: + size = nas_decode_additional_update_type(&attach_request->additional_update_type, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_TYPE: + size = nas_decode_voice_domain_preference_and_ue_usage_setting(&attach_request->voice_domain_preference_and_ue_usage_setting, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_TYPE: + size = nas_decode_device_properties(&attach_request->device_properties, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_TYPE: + size = nas_decode_guti_type(&attach_request->old_guti_type, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE: + size = nas_decode_ms_network_feature_support(&attach_request->ms_network_feature_support, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_TYPE: + size = nas_decode_network_resource_identifier_container(&attach_request->tmsi_based_nri_container, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_T3324_VALUE_TYPE: + size = nas_decode_gprs_timer_2(&attach_request->t3324_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_T3324_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_TYPE: + size = nas_decode_gprs_timer_3(&attach_request->t3412_extended_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_TYPE: + size = nas_decode_extended_drx_parameters(&attach_request->extended_drx_parameters, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_request->presencemask |= NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_PRESENT; + decoded += size; + break; + default: d_error("Unknown type(0x%x) or not implemented\n", type); return -1; } + } + return decoded; +} + +c_int32_t nas_decode_attach_accept(nas_message_t *message, pkbuf_t *pkbuf) +{ + nas_attach_accept_t *attach_accept = &message->attach_accept; + c_int32_t decoded = 0; + c_int32_t size = 0; + + size = nas_decode_eps_attach_result(&attach_accept->eps_attach_result, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + size = nas_decode_gprs_timer(&attach_accept->t3412_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + size = nas_decode_tracking_area_identity_list(&attach_accept->tai_list, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + size = nas_decode_esm_message_container(&attach_accept->esm_message_container, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + while(pkbuf->len > 0) + { + c_uint8_t *buffer = pkbuf->payload; + c_uint8_t type = (*buffer) >= 0x80 ? ((*buffer) & 0xf0) : (*buffer); + + size = sizeof(c_uint8_t); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, + "pkbuf_header error"); + decoded += size; + + switch(type) + { + case NAS_ATTACH_ACCEPT_GUTI_TYPE: + size = nas_decode_eps_mobile_identity(&attach_accept->guti, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_GUTI_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_TYPE: + size = nas_decode_location_area_identification(&attach_accept->location_area_identification, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_MS_IDENTITY_TYPE: + size = nas_decode_mobile_identity(&attach_accept->ms_identity, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_MS_IDENTITY_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_EMM_CAUSE_TYPE: + size = nas_decode_emm_cause(&attach_accept->emm_cause, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_EMM_CAUSE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_T3402_VALUE_TYPE: + size = nas_decode_gprs_timer(&attach_accept->t3402_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_T3402_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_T3423_VALUE_TYPE: + size = nas_decode_gprs_timer(&attach_accept->t3423_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_T3423_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_EQUIVALENT_PLMNS_TYPE: + size = nas_decode_plmn_list(&attach_accept->equivalent_plmns, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_EQUIVALENT_PLMNS_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_EMERGENCY_NUMBER_LIST_TYPE: + size = nas_decode_emergency_number_list(&attach_accept->emergency_number_list, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_EMERGENCY_NUMBER_LIST_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_TYPE: + size = nas_decode_eps_network_feature_support(&attach_accept->eps_network_feature_support, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_TYPE: + size = nas_decode_additional_update_result(&attach_accept->additional_update_result, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_TYPE: + size = nas_decode_gprs_timer_3(&attach_accept->t3412_extended_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_T3324_VALUE_TYPE: + size = nas_decode_gprs_timer_2(&attach_accept->t3324_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_T3324_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_TYPE: + size = nas_decode_extended_drx_parameters(&attach_accept->extended_drx_parameters, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_accept->presencemask |= NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_PRESENT; + decoded += size; + break; + default: + d_error("Unknown type(0x%x) or not implemented\n", type); + return -1; + } } return decoded; @@ -205,23 +316,109 @@ c_int32_t nas_decode_attach_request(nas_message_t *message, pkbuf_t *pkbuf) c_int32_t nas_decode_attach_complete(nas_message_t *message, pkbuf_t *pkbuf) { nas_attach_complete_t *attach_complete = &message->attach_complete; - c_uint16_t decoded = 0; + c_int32_t decoded = 0; c_int32_t size = 0; - size = nas_decode_esm_message_container( - &attach_complete->esm_message_container, pkbuf); + size = nas_decode_esm_message_container(&attach_complete->esm_message_container, pkbuf); d_assert(size >= 0, return -1, "decode failed"); decoded += size; return decoded; } -c_int32_t nas_decode_authentication_failure(nas_message_t *message, - pkbuf_t *pkbuf) +c_int32_t nas_decode_attach_reject(nas_message_t *message, pkbuf_t *pkbuf) { - nas_authentication_failure_t *authentication_failure = - &message->authentication_failure; - c_uint16_t decoded = 0; + nas_attach_reject_t *attach_reject = &message->attach_reject; + c_int32_t decoded = 0; + c_int32_t size = 0; + + size = nas_decode_emm_cause(&attach_reject->emm_cause, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + while(pkbuf->len > 0) + { + c_uint8_t *buffer = pkbuf->payload; + c_uint8_t type = (*buffer) >= 0x80 ? ((*buffer) & 0xf0) : (*buffer); + + size = sizeof(c_uint8_t); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, + "pkbuf_header error"); + decoded += size; + + switch(type) + { + case NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_TYPE: + size = nas_decode_esm_message_container(&attach_reject->esm_message_container, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_reject->presencemask |= NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REJECT_T3346_VALUE_TYPE: + size = nas_decode_gprs_timer_2(&attach_reject->t3346_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_reject->presencemask |= NAS_ATTACH_REJECT_T3346_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REJECT_T3402_VALUE_TYPE: + size = nas_decode_gprs_timer_2(&attach_reject->t3402_value, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_reject->presencemask |= NAS_ATTACH_REJECT_T3402_VALUE_PRESENT; + decoded += size; + break; + case NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_TYPE: + size = nas_decode_extended_emm_cause(&attach_reject->extended_emm_cause, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + attach_reject->presencemask |= NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_PRESENT; + decoded += size; + break; + default: + d_error("Unknown type(0x%x) or not implemented\n", type); + return -1; + } + } + + return decoded; +} + +c_int32_t nas_decode_authentication_request(nas_message_t *message, pkbuf_t *pkbuf) +{ + nas_authentication_request_t *authentication_request = &message->authentication_request; + c_int32_t decoded = 0; + c_int32_t size = 0; + + size = nas_decode_key_set_identifier(&authentication_request->nas_key_set_identifierasme, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + size = nas_decode_authentication_parameter_rand(&authentication_request->authentication_parameter_rand, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + size = nas_decode_authentication_parameter_autn(&authentication_request->authentication_parameter_autn, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + return decoded; +} + +c_int32_t nas_decode_authentication_response(nas_message_t *message, pkbuf_t *pkbuf) +{ + nas_authentication_response_t *authentication_response = &message->authentication_response; + c_int32_t decoded = 0; + c_int32_t size = 0; + + size = nas_decode_authentication_response_parameter(&authentication_response->authentication_response_parameter, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + return decoded; +} + +c_int32_t nas_decode_authentication_failure(nas_message_t *message, pkbuf_t *pkbuf) +{ + nas_authentication_failure_t *authentication_failure = &message->authentication_failure; + c_int32_t decoded = 0; c_int32_t size = 0; size = nas_decode_emm_cause(&authentication_failure->emm_cause, pkbuf); @@ -240,47 +437,82 @@ c_int32_t nas_decode_authentication_failure(nas_message_t *message, switch(type) { - case NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_TYPE: - size = nas_decode_authentication_failure_parameter( - &authentication_failure-> - authentication_failure_parameter, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - authentication_failure->presencemask |= - NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT; - decoded += size; - break; - default: + case NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_TYPE: + size = nas_decode_authentication_failure_parameter(&authentication_failure->authentication_failure_parameter, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + authentication_failure->presencemask |= NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT; + decoded += size; + break; + default: d_error("Unknown type(0x%x) or not implemented\n", type); return -1; } - } return decoded; } -c_int32_t nas_decode_authentication_response(nas_message_t *message, - pkbuf_t *pkbuf) +c_int32_t nas_decode_security_mode_command(nas_message_t *message, pkbuf_t *pkbuf) { - nas_authentication_response_t *authentication_response = - &message->authentication_response; - c_uint16_t decoded = 0; + nas_security_mode_command_t *security_mode_command = &message->security_mode_command; + c_int32_t decoded = 0; c_int32_t size = 0; - size = nas_decode_authentication_response_parameter( - &authentication_response->authentication_response_parameter, pkbuf); + size = nas_decode_security_algorithms(&security_mode_command->selected_nas_security_algorithms, pkbuf); d_assert(size >= 0, return -1, "decode failed"); decoded += size; + size = nas_decode_key_set_identifier(&security_mode_command->nas_key_set_identifier, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + size = nas_decode_ue_security_capability(&security_mode_command->replayed_ue_security_capabilities, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + decoded += size; + + while(pkbuf->len > 0) + { + c_uint8_t *buffer = pkbuf->payload; + c_uint8_t type = (*buffer) >= 0x80 ? ((*buffer) & 0xf0) : (*buffer); + + size = sizeof(c_uint8_t); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, + "pkbuf_header error"); + decoded += size; + + switch(type) + { + case NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_TYPE: + size = nas_decode_imeisv_request(&security_mode_command->imeisv_request, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + security_mode_command->presencemask |= NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_PRESENT; + decoded += size; + break; + case NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCEUE_TYPE: + size = nas_decode_nonce(&security_mode_command->replayed_nonceue, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + security_mode_command->presencemask |= NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCEUE_PRESENT; + decoded += size; + break; + case NAS_SECURITY_MODE_COMMAND_NONCEMME_TYPE: + size = nas_decode_nonce(&security_mode_command->noncemme, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + security_mode_command->presencemask |= NAS_SECURITY_MODE_COMMAND_NONCEMME_PRESENT; + decoded += size; + break; + default: + d_error("Unknown type(0x%x) or not implemented\n", type); + return -1; + } + } + return decoded; } -c_int32_t nas_decode_security_mode_complete(nas_message_t *message, - pkbuf_t *pkbuf) +c_int32_t nas_decode_security_mode_complete(nas_message_t *message, pkbuf_t *pkbuf) { - nas_security_mode_complete_t *security_mode_complete = - &message->security_mode_complete; - c_uint16_t decoded = 0; + nas_security_mode_complete_t *security_mode_complete = &message->security_mode_complete; + c_int32_t decoded = 0; c_int32_t size = 0; while(pkbuf->len > 0) @@ -295,30 +527,25 @@ c_int32_t nas_decode_security_mode_complete(nas_message_t *message, switch(type) { - case NAS_SECURITY_MODE_COMPLETE_IMEISV_TYPE: - size = nas_decode_mobile_identity( - &security_mode_complete->imeisv, pkbuf); - d_assert(size >= 0, return -1, "decode failed"); - security_mode_complete->presencemask |= - NAS_SECURITY_MODE_COMPLETE_IMEISV_PRESENT; - decoded += size; - break; - default: + case NAS_SECURITY_MODE_COMPLETE_IMEISV_TYPE: + size = nas_decode_mobile_identity(&security_mode_complete->imeisv, pkbuf); + d_assert(size >= 0, return -1, "decode failed"); + security_mode_complete->presencemask |= NAS_SECURITY_MODE_COMPLETE_IMEISV_PRESENT; + decoded += size; + break; + default: d_error("Unknown type(0x%x) or not implemented\n", type); return -1; } - } return decoded; } -c_int32_t nas_decode_security_mode_reject(nas_message_t *message, - pkbuf_t *pkbuf) +c_int32_t nas_decode_security_mode_reject(nas_message_t *message, pkbuf_t *pkbuf) { - nas_security_mode_reject_t *security_mode_reject = - &message->security_mode_reject; - c_uint16_t decoded = 0; + nas_security_mode_reject_t *security_mode_reject = &message->security_mode_reject; + c_int32_t decoded = 0; c_int32_t size = 0; size = nas_decode_emm_cause(&security_mode_reject->emm_cause, pkbuf); @@ -353,6 +580,9 @@ status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf) decoded += size; break; case NAS_ATTACH_ACCEPT: + size = nas_decode_attach_accept(message, pkbuf); + d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); + decoded += size; break; case NAS_ATTACH_COMPLETE: size = nas_decode_attach_complete(message, pkbuf); @@ -360,38 +590,30 @@ status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf) decoded += size; break; case NAS_ATTACH_REJECT: + size = nas_decode_attach_reject(message, pkbuf); + d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); + decoded += size; break; - case NAS_DETACH_REQUEST: - case NAS_DETACH_ACCEPT: - case NAS_TRACKING_AREA_UPDATE_REQUEST: - case NAS_TRACKING_AREA_UPDATE_ACCEPT: - case NAS_TRACKING_AREA_UPDATE_COMPLETE: - case NAS_TRACKING_AREA_UPDATE_REJECT: - case NAS_EXTENDED_SERVICE_REQUEST: - case NAS_SERVICE_REJECT: - case NAS_GUTI_REALLOCATION_COMMAND: - case NAS_GUTI_REALLOCATION_COMPLETE: - d_error("Not implemented(0x%x)", message->h.message_type); - return CORE_ERROR; case NAS_AUTHENTICATION_REQUEST: + size = nas_decode_authentication_request(message, pkbuf); + d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); + decoded += size; break; case NAS_AUTHENTICATION_RESPONSE: size = nas_decode_authentication_response(message, pkbuf); d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); decoded += size; break; - case NAS_AUTHENTICATION_REJECT: - break; case NAS_AUTHENTICATION_FAILURE: size = nas_decode_authentication_failure(message, pkbuf); d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); decoded += size; break; - case NAS_IDENTITY_REQUEST: - case NAS_IDENTITY_RESPONSE: case NAS_SECURITY_MODE_COMMAND: - d_error("Not implemented(0x%x)", message->h.message_type); - return CORE_ERROR; + size = nas_decode_security_mode_command(message, pkbuf); + d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); + decoded += size; + break; case NAS_SECURITY_MODE_COMPLETE: size = nas_decode_security_mode_complete(message, pkbuf); d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); @@ -402,36 +624,6 @@ status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf) d_assert(size >= CORE_OK, return CORE_ERROR, "decode error"); decoded += size; break; - case NAS_EMM_STATUS: - case NAS_EMM_INFORMATION: - case NAS_DOWNLINK_NAS_TRANSPORT: - case NAS_UPLINK_NAS_TRANSPORT: - case NAS_CS_SERVICE_NOTIFICATION: - case NAS_DOWNLINK_GENERIC_NAS_TRANSPORT: - case NAS_UPLINK_GENERIC_NAS_TRANSPORT: - - case NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST: - case NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT: - case NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST: - case NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT: - case NAS_MODIFY_EPS_BEARER_CONTEXT_REQUEST: - case NAS_MODIFY_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_MODIFY_EPS_BEARER_CONTEXT_REJECT: - case NAS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST: - case NAS_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_PDN_CONNECTIVITY_REQUEST: - case NAS_PDN_CONNECTIVITY_REJECT: - case NAS_PDN_DISCONNECT_REQUEST: - case NAS_PDN_DISCONNECT_REJECT: - case NAS_BEARER_RESOURCE_ALLOCATION_REQUEST: - case NAS_BEARER_RESOURCE_ALLOCATION_REJECT: - case NAS_BEARER_RESOURCE_MODIFICATION_REQUEST: - case NAS_BEARER_RESOURCE_MODIFICATION_REJECT: - case NAS_ESM_INFORMATION_REQUEST: - case NAS_ESM_INFORMATION_RESPONSE: - case NAS_ESM_STATUS: default: d_error("Unknown message type (0x%x) or not implemented", message->h.message_type); @@ -443,4 +635,3 @@ status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf) return CORE_OK; } - diff --git a/lib/nas/nas_encoder.c b/lib/nas/nas_encoder.c index f4fc7e428..ec2cc975c 100644 --- a/lib/nas/nas_encoder.c +++ b/lib/nas/nas_encoder.c @@ -1,30 +1,284 @@ -#define TRACE_MODULE _nasmsg +/* + * Copyright (c) 2017, CellWire Group + * 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. + */ + +/******************************************************************************* + * 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-03-21 13:49:52.092391 by acetcom + * from 24301-d80.docx + ******************************************************************************/ + +#define TRACE_MODULE _nasenc #include "core_debug.h" #include "nas_message.h" +c_int32_t nas_encode_attach_request(pkbuf_t *pkbuf, nas_message_t *message) +{ + nas_attach_request_t *attach_request = &message->attach_request; + c_int32_t encoded = 0; + c_int32_t size = 0; + + size = nas_encode_eps_attach_type(pkbuf, &attach_request->eps_attach_type); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + size = nas_encode_eps_mobile_identity(pkbuf, &attach_request->eps_mobile_identity); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + size = nas_encode_ue_network_capability(pkbuf, &attach_request->ue_network_capability); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + size = nas_encode_esm_message_container(pkbuf, &attach_request->esm_message_container); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_p_tmsi_signature(pkbuf, &attach_request->old_p_tmsi_signature); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_eps_mobile_identity(pkbuf, &attach_request->additional_guti); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_tracking_area_identity(pkbuf, &attach_request->last_visited_registered_tai); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_DRX_PARAMETER_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_DRX_PARAMETER_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_drx_parameter(pkbuf, &attach_request->drx_parameter); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_ms_network_capability(pkbuf, &attach_request->ms_network_capability); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_location_area_identification(pkbuf, &attach_request->old_location_area_identification); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_TMSI_STATUS_PRESENT) + { + attach_request->tmsi_status.type = (NAS_ATTACH_REQUEST_TMSI_STATUS_TYPE >> 4); + + size = nas_encode_tmsi_status(pkbuf, &attach_request->tmsi_status); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_mobile_station_classmark_2(pkbuf, &attach_request->mobile_station_classmark_2); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_mobile_station_classmark_3(pkbuf, &attach_request->mobile_station_classmark_3); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_SUPPORTED_CODECS_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_SUPPORTED_CODECS_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_supported_codec_list(pkbuf, &attach_request->supported_codecs); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT) + { + attach_request->additional_update_type.type = (NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE >> 4); + + size = nas_encode_additional_update_type(pkbuf, &attach_request->additional_update_type); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_voice_domain_preference_and_ue_usage_setting(pkbuf, &attach_request->voice_domain_preference_and_ue_usage_setting); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_PRESENT) + { + attach_request->device_properties.type = (NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_TYPE >> 4); + + size = nas_encode_device_properties(pkbuf, &attach_request->device_properties); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT) + { + attach_request->old_guti_type.type = (NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_TYPE >> 4); + + size = nas_encode_guti_type(pkbuf, &attach_request->old_guti_type); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT) + { + attach_request->ms_network_feature_support.type = (NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE >> 4); + + size = nas_encode_ms_network_feature_support(pkbuf, &attach_request->ms_network_feature_support); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_network_resource_identifier_container(pkbuf, &attach_request->tmsi_based_nri_container); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_T3324_VALUE_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_T3324_VALUE_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_gprs_timer_2(pkbuf, &attach_request->t3324_value); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_gprs_timer_3(pkbuf, &attach_request->t3412_extended_value); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_request->presencemask & NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_extended_drx_parameters(pkbuf, &attach_request->extended_drx_parameters); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + return encoded; +} + c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) { nas_attach_accept_t *attach_accept = &message->attach_accept; - c_int32_t size = 0; c_int32_t encoded = 0; + c_int32_t size = 0; size = nas_encode_eps_attach_result(pkbuf, &attach_accept->eps_attach_result); - d_assert(size >= 0, return encoded, "decode failed"); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; size = nas_encode_gprs_timer(pkbuf, &attach_accept->t3412_value); - d_assert(size >= 0, return encoded, "decode failed"); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - size = nas_encode_tracking_area_identity_list(pkbuf, - &attach_accept->tai_list); - d_assert(size >= 0, return encoded, "decode failed"); + size = nas_encode_tracking_area_identity_list(pkbuf, &attach_accept->tai_list); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - size = nas_encode_esm_message_container(pkbuf, - &attach_accept->esm_message_container); - d_assert(size >= 0, return encoded, "decode failed"); + size = nas_encode_esm_message_container(pkbuf, &attach_accept->esm_message_container); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_GUTI_PRESENT) @@ -37,35 +291,32 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_PRESENT) + + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_location_area_identification(pkbuf, - &attach_accept->location_area_identification); + size = nas_encode_location_area_identification(pkbuf, &attach_accept->location_area_identification); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_MS_IDENTITY_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_MS_IDENTITY_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_MS_IDENTITY_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_mobile_identity(pkbuf, - &attach_accept->ms_identity); + size = nas_encode_mobile_identity(pkbuf, &attach_accept->ms_identity); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_EMM_CAUSE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_EMM_CAUSE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_EMM_CAUSE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -73,10 +324,10 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_T3402_VALUE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_T3402_VALUE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_T3402_VALUE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -84,10 +335,10 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_T3423_VALUE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_T3423_VALUE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_T3423_VALUE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -95,11 +346,10 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_EQUIVALENT_PLMNS_PRESENT) + + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_EQUIVALENT_PLMNS_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_EQUIVALENT_PLMNS_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_EQUIVALENT_PLMNS_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -107,55 +357,52 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - /* 9.9.3.37 Emergency number list - * See subclause 10.5.3.13 in 3GPP TS 24.008 [13]. - * O TLV 5-50 - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_EMERGENCY_NUMBER_LIST_PRESENT) + + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_EMERGENCY_NUMBER_LIST_PRESENT) { - } - */ - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_PRESENT) - { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_EMERGENCY_NUMBER_LIST_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_eps_network_feature_support(pkbuf, - &attach_accept->eps_network_feature_support); + size = nas_encode_emergency_number_list(pkbuf, &attach_accept->emergency_number_list); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_PRESENT) - { - attach_accept->additional_update_result.type = - (NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_TYPE >> 4); - size = nas_encode_additional_update_result(pkbuf, - &attach_accept->additional_update_result); - d_assert(size >= 0, return encoded, "decode failed"); - encoded += size; - } - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_PRESENT) + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_gprs_timer_3(pkbuf, - &attach_accept->t3412_extended_value); + size = nas_encode_eps_network_feature_support(pkbuf, &attach_accept->eps_network_feature_support); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } + + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_PRESENT) + { + attach_accept->additional_update_result.type = (NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_TYPE >> 4); + + size = nas_encode_additional_update_result(pkbuf, &attach_accept->additional_update_result); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_gprs_timer_3(pkbuf, &attach_accept->t3412_extended_value); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_T3324_VALUE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_T3324_VALUE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_T3324_VALUE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -163,16 +410,14 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - if (attach_accept->presencemask & - NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_PRESENT) + + if (attach_accept->presencemask & NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_extended_drx_parameters(pkbuf, - &attach_accept->extended_drx_parameters); + size = nas_encode_extended_drx_parameters(pkbuf, &attach_accept->extended_drx_parameters); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } @@ -180,34 +425,43 @@ c_int32_t nas_encode_attach_accept(pkbuf_t *pkbuf, nas_message_t *message) return encoded; } +c_int32_t nas_encode_attach_complete(pkbuf_t *pkbuf, nas_message_t *message) +{ + nas_attach_complete_t *attach_complete = &message->attach_complete; + c_int32_t encoded = 0; + c_int32_t size = 0; + + size = nas_encode_esm_message_container(pkbuf, &attach_complete->esm_message_container); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + return encoded; +} + c_int32_t nas_encode_attach_reject(pkbuf_t *pkbuf, nas_message_t *message) { nas_attach_reject_t *attach_reject = &message->attach_reject; - c_int32_t size = 0; c_int32_t encoded = 0; + c_int32_t size = 0; size = nas_encode_emm_cause(pkbuf, &attach_reject->emm_cause); - d_assert(size >= 0, return encoded, "decode failed"); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - if (attach_reject->presencemask & - NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT) + if (attach_reject->presencemask & NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_esm_message_container(pkbuf, - &attach_reject->esm_message_container); + size = nas_encode_esm_message_container(pkbuf, &attach_reject->esm_message_container); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } if (attach_reject->presencemask & NAS_ATTACH_REJECT_T3346_VALUE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_REJECT_T3346_VALUE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REJECT_T3346_VALUE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -218,8 +472,7 @@ c_int32_t nas_encode_attach_reject(pkbuf_t *pkbuf, nas_message_t *message) if (attach_reject->presencemask & NAS_ATTACH_REJECT_T3402_VALUE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_ATTACH_REJECT_T3402_VALUE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_ATTACH_REJECT_T3402_VALUE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; @@ -228,14 +481,11 @@ c_int32_t nas_encode_attach_reject(pkbuf_t *pkbuf, nas_message_t *message) encoded += size; } - if (attach_reject->presencemask & - NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_PRESENT) + if (attach_reject->presencemask & NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_PRESENT) { - attach_reject->extended_emm_cause.type = - (NAS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_TYPE >> 4); + attach_reject->extended_emm_cause.type = (NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_TYPE >> 4); - size = nas_encode_extended_emm_cause(pkbuf, - &attach_reject->extended_emm_cause); + size = nas_encode_extended_emm_cause(pkbuf, &attach_reject->extended_emm_cause); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } @@ -243,93 +493,146 @@ c_int32_t nas_encode_attach_reject(pkbuf_t *pkbuf, nas_message_t *message) return encoded; } -c_int32_t nas_encode_authentication_request( - pkbuf_t *pkbuf, nas_message_t *message) +c_int32_t nas_encode_authentication_request(pkbuf_t *pkbuf, nas_message_t *message) { - nas_authentication_request_t *authentication_request = - &message->authentication_request; - c_int32_t size = 0; + nas_authentication_request_t *authentication_request = &message->authentication_request; c_int32_t encoded = 0; + c_int32_t size = 0; - size = nas_encode_nas_key_set_identifier(pkbuf, - &authentication_request->nas_key_set_identifier); - d_assert(size >= 0, return encoded, "decode failed"); + size = nas_encode_key_set_identifier(pkbuf, &authentication_request->nas_key_set_identifierasme); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - size = nas_encode_authentication_parameter_rand(pkbuf, - &authentication_request->authentication_parameter_rand); - d_assert(size >= 0, return encoded, "decode failed"); + size = nas_encode_authentication_parameter_rand(pkbuf, &authentication_request->authentication_parameter_rand); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - size = nas_encode_authentication_parameter_autn(pkbuf, - &authentication_request->authentication_parameter_autn); - d_assert(size >= 0, return encoded, "decode failed"); + size = nas_encode_authentication_parameter_autn(pkbuf, &authentication_request->authentication_parameter_autn); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; return encoded; } -c_int32_t nas_encode_security_mode_command( - pkbuf_t *pkbuf, nas_message_t *message) +c_int32_t nas_encode_authentication_response(pkbuf_t *pkbuf, nas_message_t *message) { - nas_security_mode_command_t *security_mode_command = - &message->security_mode_command; - c_int32_t size = 0; + nas_authentication_response_t *authentication_response = &message->authentication_response; c_int32_t encoded = 0; + c_int32_t size = 0; - size = nas_encode_nas_security_algorithms( - pkbuf, &security_mode_command->selected_nas_security_algorithms); - d_assert(size >= 0, return encoded, "decode failed"); + size = nas_encode_authentication_response_parameter(pkbuf, &authentication_response->authentication_response_parameter); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - size = nas_encode_nas_key_set_identifier( - pkbuf, &security_mode_command->nas_key_set_identifier); - d_assert(size >= 0, return encoded, "decode failed"); + return encoded; +} + +c_int32_t nas_encode_authentication_failure(pkbuf_t *pkbuf, nas_message_t *message) +{ + nas_authentication_failure_t *authentication_failure = &message->authentication_failure; + c_int32_t encoded = 0; + c_int32_t size = 0; + + size = nas_encode_emm_cause(pkbuf, &authentication_failure->emm_cause); + d_assert(size >= 0, return -1, "encode failed"); encoded += size; - size = nas_encode_ue_security_capability( - pkbuf, &security_mode_command->replayed_ue_security_capabilities); - d_assert(size >= 0, return encoded, "decode failed"); - encoded += size; - - if (security_mode_command->presencemask & - NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_PRESENT) + if (authentication_failure->presencemask & NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_imeisv_request(pkbuf, - &security_mode_command->imeisv_request); + size = nas_encode_authentication_failure_parameter(pkbuf, &authentication_failure->authentication_failure_parameter); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - if (security_mode_command->presencemask & - NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCE_PRESENT) - { - size = nas_encode_optional_type(pkbuf, - NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCE_TYPE); - d_assert(size >= 0, return encoded, "decode failed"); - encoded += size; - size = nas_encode_nonce(pkbuf, &security_mode_command->replayed_nonce); + return encoded; +} + +c_int32_t nas_encode_security_mode_command(pkbuf_t *pkbuf, nas_message_t *message) +{ + nas_security_mode_command_t *security_mode_command = &message->security_mode_command; + c_int32_t encoded = 0; + c_int32_t size = 0; + + size = nas_encode_security_algorithms(pkbuf, &security_mode_command->selected_nas_security_algorithms); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + size = nas_encode_key_set_identifier(pkbuf, &security_mode_command->nas_key_set_identifier); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + size = nas_encode_ue_security_capability(pkbuf, &security_mode_command->replayed_ue_security_capabilities); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + + if (security_mode_command->presencemask & NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_PRESENT) + { + security_mode_command->imeisv_request.type = (NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_TYPE >> 4); + + size = nas_encode_imeisv_request(pkbuf, &security_mode_command->imeisv_request); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } - if (security_mode_command->presencemask & - NAS_SECURITY_MODE_COMMAND_NONCE_PRESENT) + + if (security_mode_command->presencemask & NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCEUE_PRESENT) { - size = nas_encode_optional_type(pkbuf, - NAS_SECURITY_MODE_COMMAND_NONCE_TYPE); + size = nas_encode_optional_type(pkbuf, NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCEUE_TYPE); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; - size = nas_encode_nonce(pkbuf, &security_mode_command->nonce); + size = nas_encode_nonce(pkbuf, &security_mode_command->replayed_nonceue); d_assert(size >= 0, return encoded, "decode failed"); encoded += size; } + if (security_mode_command->presencemask & NAS_SECURITY_MODE_COMMAND_NONCEMME_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_SECURITY_MODE_COMMAND_NONCEMME_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_nonce(pkbuf, &security_mode_command->noncemme); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + return encoded; +} + +c_int32_t nas_encode_security_mode_complete(pkbuf_t *pkbuf, nas_message_t *message) +{ + nas_security_mode_complete_t *security_mode_complete = &message->security_mode_complete; + c_int32_t encoded = 0; + c_int32_t size = 0; + + if (security_mode_complete->presencemask & NAS_SECURITY_MODE_COMPLETE_IMEISV_PRESENT) + { + size = nas_encode_optional_type(pkbuf, NAS_SECURITY_MODE_COMPLETE_IMEISV_TYPE); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + + size = nas_encode_mobile_identity(pkbuf, &security_mode_complete->imeisv); + d_assert(size >= 0, return encoded, "decode failed"); + encoded += size; + } + + return encoded; +} + +c_int32_t nas_encode_security_mode_reject(pkbuf_t *pkbuf, nas_message_t *message) +{ + nas_security_mode_reject_t *security_mode_reject = &message->security_mode_reject; + c_int32_t encoded = 0; + c_int32_t size = 0; + + size = nas_encode_emm_cause(pkbuf, &security_mode_reject->emm_cause); + d_assert(size >= 0, return -1, "encode failed"); + encoded += size; + return encoded; } @@ -357,84 +660,55 @@ status_t nas_plain_encode(pkbuf_t **pkbuf, nas_message_t *message) switch(message->h.message_type) { case NAS_ATTACH_REQUEST: - d_error("Not implemented(0x%x)", message->h.message_type); - pkbuf_free((*pkbuf)); - return CORE_ERROR; + size = nas_encode_attach_request(*pkbuf, message); + d_assert(size >= 0, return CORE_ERROR, "decode error"); + encoded += size; + break; case NAS_ATTACH_ACCEPT: size = nas_encode_attach_accept(*pkbuf, message); d_assert(size >= 0, return CORE_ERROR, "decode error"); encoded += size; break; case NAS_ATTACH_COMPLETE: - d_error("Not implemented(0x%x)", message->h.message_type); - pkbuf_free((*pkbuf)); - return CORE_ERROR; + size = nas_encode_attach_complete(*pkbuf, message); + d_assert(size >= 0, return CORE_ERROR, "decode error"); + encoded += size; + break; case NAS_ATTACH_REJECT: size = nas_encode_attach_reject(*pkbuf, message); d_assert(size >= 0, return CORE_ERROR, "decode error"); encoded += size; break; - case NAS_DETACH_REQUEST: - case NAS_DETACH_ACCEPT: - case NAS_TRACKING_AREA_UPDATE_REQUEST: - case NAS_TRACKING_AREA_UPDATE_ACCEPT: - case NAS_TRACKING_AREA_UPDATE_COMPLETE: - case NAS_TRACKING_AREA_UPDATE_REJECT: - case NAS_EXTENDED_SERVICE_REQUEST: - case NAS_SERVICE_REJECT: - case NAS_GUTI_REALLOCATION_COMMAND: - case NAS_GUTI_REALLOCATION_COMPLETE: case NAS_AUTHENTICATION_REQUEST: size = nas_encode_authentication_request(*pkbuf, message); d_assert(size >= 0, return CORE_ERROR, "decode error"); encoded += size; break; case NAS_AUTHENTICATION_RESPONSE: - d_error("Not implemented(0x%x)", message->h.message_type); - pkbuf_free((*pkbuf)); - return CORE_ERROR; - case NAS_AUTHENTICATION_REJECT: + size = nas_encode_authentication_response(*pkbuf, message); + d_assert(size >= 0, return CORE_ERROR, "decode error"); + encoded += size; break; case NAS_AUTHENTICATION_FAILURE: - case NAS_IDENTITY_REQUEST: - case NAS_IDENTITY_RESPONSE: + size = nas_encode_authentication_failure(*pkbuf, message); + d_assert(size >= 0, return CORE_ERROR, "decode error"); + encoded += size; + break; case NAS_SECURITY_MODE_COMMAND: size = nas_encode_security_mode_command(*pkbuf, message); d_assert(size >= 0, return CORE_ERROR, "decode error"); encoded += size; break; case NAS_SECURITY_MODE_COMPLETE: + size = nas_encode_security_mode_complete(*pkbuf, message); + d_assert(size >= 0, return CORE_ERROR, "decode error"); + encoded += size; + break; case NAS_SECURITY_MODE_REJECT: - case NAS_EMM_STATUS: - case NAS_EMM_INFORMATION: - case NAS_DOWNLINK_NAS_TRANSPORT: - case NAS_UPLINK_NAS_TRANSPORT: - case NAS_CS_SERVICE_NOTIFICATION: - case NAS_DOWNLINK_GENERIC_NAS_TRANSPORT: - case NAS_UPLINK_GENERIC_NAS_TRANSPORT: - - case NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST: - case NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT: - case NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST: - case NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT: - case NAS_MODIFY_EPS_BEARER_CONTEXT_REQUEST: - case NAS_MODIFY_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_MODIFY_EPS_BEARER_CONTEXT_REJECT: - case NAS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST: - case NAS_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT: - case NAS_PDN_CONNECTIVITY_REQUEST: - case NAS_PDN_CONNECTIVITY_REJECT: - case NAS_PDN_DISCONNECT_REQUEST: - case NAS_PDN_DISCONNECT_REJECT: - case NAS_BEARER_RESOURCE_ALLOCATION_REQUEST: - case NAS_BEARER_RESOURCE_ALLOCATION_REJECT: - case NAS_BEARER_RESOURCE_MODIFICATION_REQUEST: - case NAS_BEARER_RESOURCE_MODIFICATION_REJECT: - case NAS_ESM_INFORMATION_REQUEST: - case NAS_ESM_INFORMATION_RESPONSE: - case NAS_ESM_STATUS: + size = nas_encode_security_mode_reject(*pkbuf, message); + d_assert(size >= 0, return CORE_ERROR, "decode error"); + encoded += size; + break; default: d_error("Unknown message type (0x%x) or not implemented", message->h.message_type); @@ -449,3 +723,4 @@ status_t nas_plain_encode(pkbuf_t **pkbuf, nas_message_t *message) return CORE_OK; } + diff --git a/lib/nas/nas_ies.c b/lib/nas/nas_ies.c index a25994d4d..6e1c26ed7 100644 --- a/lib/nas/nas_ies.c +++ b/lib/nas/nas_ies.c @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2017, CellWire Group + * 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. + */ + +/******************************************************************************* + * 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-03-21 13:49:52.075822 by acetcom + * from 24301-d80.docx + ******************************************************************************/ + #define TRACE_MODULE _nasies #include "core_debug.h" @@ -6,95 +38,91 @@ c_int16_t nas_encode_optional_type(pkbuf_t *pkbuf, c_uint8_t type) { - c_uint16_t size = 0; + c_uint16_t size = sizeof(c_uint8_t); - size = sizeof(c_uint8_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, &type, size); return size; } - /* 9.9.2.0A Device properties - * See subclause 10.5.7.8 in 3GPP TS 24.008 [13]. * O TV 1 */ -c_int16_t nas_decode_device_properties( - nas_device_properties_t *device_properties, pkbuf_t *pkbuf) +c_int16_t nas_decode_device_properties(nas_device_properties_t *device_properties, pkbuf_t *pkbuf) { memcpy(device_properties, pkbuf->payload - 1, 1); + return 0; } -/* 9.9.2.2 Location area identification - * See subclause 10.5.1.3 in 3GPP TS 24.008 [13] - * O TV 6 */ -c_int16_t nas_decode_location_area_identification( - nas_location_area_identification_t *location_area_identification, - pkbuf_t *pkbuf) +c_int16_t nas_encode_device_properties(pkbuf_t *pkbuf, nas_device_properties_t *device_properties) { - c_uint16_t size = 0; + c_uint16_t size = sizeof(nas_device_properties_t); - size = sizeof(nas_location_area_identification_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(location_area_identification, pkbuf->payload - size, size); - - location_area_identification->lac = - ntohs(location_area_identification->lac); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, device_properties, size); return size; } -c_int16_t nas_encode_location_area_identification( - pkbuf_t *pkbuf, - nas_location_area_identification_t *location_area_identification) +/* 9.9.2.10 Supported Codec List + * O TLV 5-n */ +c_int16_t nas_decode_supported_codec_list(nas_supported_codec_list_t *supported_codec_list, pkbuf_t *pkbuf) { c_uint16_t size = 0; + nas_supported_codec_list_t *source = pkbuf->payload; + + supported_codec_list->length = source->length; + size = supported_codec_list->length + sizeof(supported_codec_list->length); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(supported_codec_list, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_supported_codec_list(pkbuf_t *pkbuf, nas_supported_codec_list_t *supported_codec_list) +{ + c_uint16_t size = supported_codec_list->length + sizeof(supported_codec_list->length); + nas_supported_codec_list_t target; + + memcpy(&target, supported_codec_list, sizeof(nas_supported_codec_list_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.2.2 Location area identification + * O TV 6 */ +c_int16_t nas_decode_location_area_identification(nas_location_area_identification_t *location_area_identification, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_location_area_identification_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(location_area_identification, pkbuf->payload - size, size); + + location_area_identification->lac = ntohs(location_area_identification->lac); + + return size; +} + +c_int16_t nas_encode_location_area_identification(pkbuf_t *pkbuf, nas_location_area_identification_t *location_area_identification) +{ + c_uint16_t size = sizeof(nas_location_area_identification_t); nas_location_area_identification_t target; - d_assert(location_area_identification, return -1, "Null param"); - memcpy(&target, location_area_identification, - sizeof(nas_location_area_identification_t)); - - size = sizeof(nas_location_area_identification_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - + memcpy(&target, location_area_identification, size); target.lac = htons(location_area_identification->lac); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, &target, size); return size; } /* 9.9.2.3 Mobile identity - * See subclause 10.5.1.4 in 3GPP TS 24.008 [13]. * O TLV 7-10 */ -c_int16_t nas_encode_mobile_identity( - pkbuf_t *pkbuf, nas_mobile_identity_t *mobile_identity) -{ - c_uint16_t size = 0; - nas_mobile_identity_t target; - - d_assert(mobile_identity, return -1, "Null param"); - memcpy(&target, mobile_identity, sizeof(nas_mobile_identity_t)); - - size = mobile_identity->length + sizeof(mobile_identity->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - if (mobile_identity->tmsi.type_of_identity == NAS_MOBILE_IDENTITY_TMSI) - { - target.tmsi.tmsi = htonl(mobile_identity->tmsi.tmsi); - target.tmsi.spare = 0xf; - } - memcpy(pkbuf->payload - size, &target, size); - - return size; -} - -c_int16_t nas_decode_mobile_identity( - nas_mobile_identity_t *mobile_identity, pkbuf_t *pkbuf) +c_int16_t nas_decode_mobile_identity(nas_mobile_identity_t *mobile_identity, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_mobile_identity_t *source = pkbuf->payload; @@ -102,284 +130,238 @@ c_int16_t nas_decode_mobile_identity( mobile_identity->length = source->length; size = mobile_identity->length + sizeof(mobile_identity->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(mobile_identity, pkbuf->payload - size, size); - + + if (mobile_identity->tmsi.type_of_identity == NAS_MOBILE_IDENTITY_TMSI) + { + if (mobile_identity->tmsi.spare != 0xf) + d_warn("Spec warning : mobile_identity->tmsi.spare = 0x%x", mobile_identity->tmsi.spare); + mobile_identity->tmsi.tmsi = ntohl(mobile_identity->tmsi.tmsi); + } + + return size; +} + +c_int16_t nas_encode_mobile_identity(pkbuf_t *pkbuf, nas_mobile_identity_t *mobile_identity) +{ + c_uint16_t size = mobile_identity->length + sizeof(mobile_identity->length); + nas_mobile_identity_t target; + + memcpy(&target, mobile_identity, sizeof(nas_mobile_identity_t)); + if (mobile_identity->tmsi.type_of_identity == NAS_MOBILE_IDENTITY_TMSI) + { + target.tmsi.tmsi = htonl(mobile_identity->tmsi.tmsi); + target.tmsi.spare = 0xf; + } + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + return size; } /* 9.9.2.4 Mobile station classmark 2 - * See subclause 10.5.1.6 in 3GPP TS 24.008 * O TLV 5 */ -c_int16_t nas_decode_mobile_station_classmark_2( - nas_mobile_station_classmark_2_t *mobile_station_classmark_2, - pkbuf_t *pkbuf) +c_int16_t nas_decode_mobile_station_classmark_2(nas_mobile_station_classmark_2_t *mobile_station_classmark_2, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_mobile_station_classmark_2_t *source = pkbuf->payload; mobile_station_classmark_2->length = source->length; - size = mobile_station_classmark_2->length + - sizeof(mobile_station_classmark_2->length); + size = mobile_station_classmark_2->length + sizeof(mobile_station_classmark_2->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(mobile_station_classmark_2, pkbuf->payload - size, size); - + return size; } -/*9.9.2.5 Mobile station classmark 3 - * See subclause 10.5.1.7 in 3GPP TS 24.008 [13]. +c_int16_t nas_encode_mobile_station_classmark_2(pkbuf_t *pkbuf, nas_mobile_station_classmark_2_t *mobile_station_classmark_2) +{ + c_uint16_t size = mobile_station_classmark_2->length + sizeof(mobile_station_classmark_2->length); + nas_mobile_station_classmark_2_t target; + + memcpy(&target, mobile_station_classmark_2, sizeof(nas_mobile_station_classmark_2_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.2.5 Mobile station classmark 3 * O TLV 2-34 */ -c_int16_t nas_decode_mobile_station_classmark_3( - nas_mobile_station_classmark_3_t *mobile_station_classmark_3, - pkbuf_t *pkbuf) +c_int16_t nas_decode_mobile_station_classmark_3(nas_mobile_station_classmark_3_t *mobile_station_classmark_3, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_mobile_station_classmark_3_t *source = pkbuf->payload; mobile_station_classmark_3->length = source->length; - size = mobile_station_classmark_3->length + - sizeof(mobile_station_classmark_3->length); + size = mobile_station_classmark_3->length + sizeof(mobile_station_classmark_3->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - /* TODO + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(mobile_station_classmark_3, pkbuf->payload - size, size); - */ - + + return size; +} + +c_int16_t nas_encode_mobile_station_classmark_3(pkbuf_t *pkbuf, nas_mobile_station_classmark_3_t *mobile_station_classmark_3) +{ + c_uint16_t size = mobile_station_classmark_3->length + sizeof(mobile_station_classmark_3->length); + nas_mobile_station_classmark_3_t target; + + memcpy(&target, mobile_station_classmark_3, sizeof(nas_mobile_station_classmark_3_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + return size; } /* 9.9.2.8 PLMN list - * See subclause 10.5.1.13 in 3GPP TS 24.008 [13]. * O TLV 5-47 */ -c_int16_t nas_encode_plmn_list( - pkbuf_t *pkbuf, nas_plmn_list_t *plmn_list) +c_int16_t nas_decode_plmn_list(nas_plmn_list_t *plmn_list, pkbuf_t *pkbuf) { c_uint16_t size = 0; + nas_plmn_list_t *source = pkbuf->payload; - d_assert(plmn_list, return -1, "Null param"); - + plmn_list->length = source->length; size = plmn_list->length + sizeof(plmn_list->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, plmn_list, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(plmn_list, pkbuf->payload - size, size); return size; } -/* 9.9.2.10 Supported codec list - * See subclause 10.5.4.32 in 3GPP TS 24.008 [13]. - * O TLV 5-n */ -c_int16_t nas_decode_supported_codec_list( - nas_supported_codec_list_t *supported_codec_list, pkbuf_t *pkbuf) +c_int16_t nas_encode_plmn_list(pkbuf_t *pkbuf, nas_plmn_list_t *plmn_list) { - c_uint16_t size = 0; - nas_supported_codec_list_t *source = pkbuf->payload; + c_uint16_t size = plmn_list->length + sizeof(plmn_list->length); + nas_plmn_list_t target; - supported_codec_list->length = source->length; - size = supported_codec_list->length + - sizeof(supported_codec_list->length); - - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - memcpy(supported_codec_list, pkbuf->payload - size, - c_min(size, sizeof(nas_supported_codec_list_t))); + memcpy(&target, plmn_list, sizeof(nas_plmn_list_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } -c_int16_t nas_decode_additional_update_type( - nas_additional_update_type_t *additional_update_type, pkbuf_t *pkbuf) -{ - memcpy(additional_update_type, pkbuf->payload - 1, 1); - return 0; -} - /* 9.9.3.0A Additional update result - * O TV 1 */ -c_int16_t nas_encode_additional_update_result( - pkbuf_t *pkbuf, - nas_additional_update_result_t *additional_update_result) + * O TV 1 */ +c_int16_t nas_decode_additional_update_result(nas_additional_update_result_t *additional_update_result, pkbuf_t *pkbuf) { - c_uint16_t size = 0; + memcpy(additional_update_result, pkbuf->payload - 1, 1); - d_assert(additional_update_result, return -1, "Null param"); + return 0; +} - size = sizeof(nas_additional_update_result_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); +c_int16_t nas_encode_additional_update_result(pkbuf_t *pkbuf, nas_additional_update_result_t *additional_update_result) +{ + c_uint16_t size = sizeof(nas_additional_update_result_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, additional_update_result, size); return size; } +/* 9.9.3.0B Additional update type + * O TV 1 */ +c_int16_t nas_decode_additional_update_type(nas_additional_update_type_t *additional_update_type, pkbuf_t *pkbuf) +{ + memcpy(additional_update_type, pkbuf->payload - 1, 1); + + return 0; +} + +c_int16_t nas_encode_additional_update_type(pkbuf_t *pkbuf, nas_additional_update_type_t *additional_update_type) +{ + c_uint16_t size = sizeof(nas_additional_update_type_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, additional_update_type, size); + + return size; +} + /* 9.9.3.1 Authentication failure parameter - * See subclause 10.5.3.2.2 in 3GPP TS 24.008 [13]. * O TLV 16 */ -c_int16_t nas_decode_authentication_failure_parameter( - nas_authentication_failure_parameter_t *authentication_failure_parameter, - pkbuf_t *pkbuf) +c_int16_t nas_decode_authentication_failure_parameter(nas_authentication_failure_parameter_t *authentication_failure_parameter, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_authentication_failure_parameter_t *source = pkbuf->payload; authentication_failure_parameter->length = source->length; - size = authentication_failure_parameter->length + - sizeof(authentication_failure_parameter->length); + size = authentication_failure_parameter->length + sizeof(authentication_failure_parameter->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(authentication_failure_parameter, pkbuf->payload - size, size); - + return size; } -/* 9.9.3.2 Authentication parameter AUTN - * See subclause 10.5.3.1.1 in 3GPP TS 24.008 [13]. - * M LV 17 */ -c_int16_t nas_encode_authentication_parameter_autn(pkbuf_t *pkbuf, - nas_authentication_parameter_autn_t *authentication_parameter_autn) +c_int16_t nas_encode_authentication_failure_parameter(pkbuf_t *pkbuf, nas_authentication_failure_parameter_t *authentication_failure_parameter) { - c_uint16_t size = 0; + c_uint16_t size = authentication_failure_parameter->length + sizeof(authentication_failure_parameter->length); + nas_authentication_failure_parameter_t target; - d_assert(authentication_parameter_autn, return -1, "Null param"); - - size = authentication_parameter_autn->length + - sizeof(authentication_parameter_autn->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - memcpy(pkbuf->payload - size, authentication_parameter_autn, size); + memcpy(&target, authentication_failure_parameter, sizeof(nas_authentication_failure_parameter_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } -/* 9.9.3.3 Authentication parameter RAND - * See subclause 10.5.3.1 in 3GPP TS 24.008 [13]. - * M V 16 */ -c_int16_t nas_encode_authentication_parameter_rand(pkbuf_t *pkbuf, - nas_authentication_parameter_rand_t *authentication_parameter_rand) -{ - c_uint16_t size = 0; - - d_assert(authentication_parameter_rand, return -1, "Null param"); - - size = sizeof(nas_authentication_parameter_rand_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, authentication_parameter_rand, size); - - return size; -} - -/* 9.9.3.4 Authentication response parameter - * M LV 5-17 */ -c_int16_t nas_decode_authentication_response_parameter( - nas_authentication_response_parameter_t *authentication_response_parameter, - pkbuf_t *pkbuf) -{ - c_uint16_t size = 0; - nas_authentication_response_parameter_t *source = pkbuf->payload; - - authentication_response_parameter->length = source->length; - size = authentication_response_parameter->length + - sizeof(authentication_response_parameter->length); - - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(authentication_response_parameter, pkbuf->payload - size, size); - - return size; -} - -/* 9.9.3.8 DRX parameter - * See subclause 10.5.5.6 in 3GPP TS 24.008 - * O TV 3 */ -c_int16_t nas_decode_drx_parameter( - nas_drx_parameter_t *drx_parameter, pkbuf_t *pkbuf) -{ - c_uint16_t size = 0; - - size = sizeof(nas_drx_parameter_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(drx_parameter, pkbuf->payload - size, size); - - return size; -} - -/* 9.9.3.9 EMM cause - * O TV 2 */ -c_int16_t nas_encode_emm_cause(pkbuf_t *pkbuf, nas_emm_cause_t *emm_cause) -{ - c_uint16_t size = 0; - - d_assert(emm_cause, return -1, "Null param"); - - size = sizeof(nas_emm_cause_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, emm_cause, size); - - return size; -} - -c_int16_t nas_decode_emm_cause(nas_emm_cause_t *emm_cause, pkbuf_t *pkbuf) -{ - c_uint16_t size = 0; - - size = sizeof(nas_emm_cause_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(emm_cause, pkbuf->payload - size, size); - - return size; -} - -/* 9.9.3.10 * EPS attach result +/* 9.9.3.10 EPS attach result * M V 1/2 */ -c_int16_t nas_encode_eps_attach_result( - pkbuf_t *pkbuf, nas_eps_attach_result_t *eps_attach_result) +c_int16_t nas_decode_eps_attach_result(nas_eps_attach_result_t *eps_attach_result, pkbuf_t *pkbuf) { - c_uint16_t size = 0; + c_uint16_t size = sizeof(nas_eps_attach_result_t); - d_assert(eps_attach_result, return -1, "Null param"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(eps_attach_result, pkbuf->payload - size, size); - size = sizeof(nas_eps_attach_result_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, eps_attach_result, size); + return size; +} + +c_int16_t nas_encode_eps_attach_result(pkbuf_t *pkbuf, nas_eps_attach_result_t *eps_attach_result) +{ + c_uint16_t size = sizeof(nas_eps_attach_result_t); + nas_eps_attach_result_t target; + + memcpy(&target, eps_attach_result, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } /* 9.9.3.11 EPS attach type - * M V 1/2 - * 9.9.3.21 NAS key set identifier * M V 1/2 */ -c_int16_t nas_decode_eps_attach_type( - nas_eps_attach_type_t *eps_attach_type, pkbuf_t *pkbuf) +c_int16_t nas_decode_eps_attach_type(nas_eps_attach_type_t *eps_attach_type, pkbuf_t *pkbuf) { - c_uint16_t size = 0; + c_uint16_t size = sizeof(nas_eps_attach_type_t); - size = sizeof(nas_eps_attach_type_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(eps_attach_type, pkbuf->payload - size, size); return size; } +c_int16_t nas_encode_eps_attach_type(pkbuf_t *pkbuf, nas_eps_attach_type_t *eps_attach_type) +{ + c_uint16_t size = sizeof(nas_eps_attach_type_t); + nas_eps_attach_type_t target; + + memcpy(&target, eps_attach_type, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + /* 9.9.3.12 EPS mobile identity * M LV 5-12 */ -c_int16_t nas_decode_eps_mobile_identity( - nas_eps_mobile_identity_t *eps_mobile_identity, pkbuf_t *pkbuf) +c_int16_t nas_decode_eps_mobile_identity(nas_eps_mobile_identity_t *eps_mobile_identity, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_eps_mobile_identity_t *source = pkbuf->payload; @@ -387,94 +369,84 @@ c_int16_t nas_decode_eps_mobile_identity( eps_mobile_identity->length = source->length; size = eps_mobile_identity->length + sizeof(eps_mobile_identity->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(eps_mobile_identity, pkbuf->payload - size, size); - if (eps_mobile_identity->guti.type_of_identity == - NAS_EPS_MOBILE_IDENTITY_GUTI) + + if (eps_mobile_identity->guti.type_of_identity == NAS_EPS_MOBILE_IDENTITY_GUTI) { if (eps_mobile_identity->guti.spare != 0xf) - { - d_warn("Spec warning : eps_mobile_identy->spare = 0x%x", - eps_mobile_identity->guti.spare); - } - eps_mobile_identity->guti.mme_group_id = - ntohs(eps_mobile_identity->guti.mme_group_id); - eps_mobile_identity->guti.m_tmsi = - ntohl(eps_mobile_identity->guti.m_tmsi); + d_warn("Spec warning : eps_mobile_identy->spare = 0x%x", eps_mobile_identity->guti.spare); + eps_mobile_identity->guti.mme_group_id = ntohs(eps_mobile_identity->guti.mme_group_id); + eps_mobile_identity->guti.m_tmsi = ntohl(eps_mobile_identity->guti.m_tmsi); } - + return size; } -c_int16_t nas_encode_eps_mobile_identity( - pkbuf_t *pkbuf, nas_eps_mobile_identity_t *eps_mobile_identity) +c_int16_t nas_encode_eps_mobile_identity(pkbuf_t *pkbuf, nas_eps_mobile_identity_t *eps_mobile_identity) { - c_uint16_t size = 0; + c_uint16_t size = eps_mobile_identity->length + sizeof(eps_mobile_identity->length); nas_eps_mobile_identity_t target; - d_assert(eps_mobile_identity, return -1, "Null param"); memcpy(&target, eps_mobile_identity, sizeof(nas_eps_mobile_identity_t)); - - size = eps_mobile_identity->length + sizeof(eps_mobile_identity->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - if (target.guti.type_of_identity == NAS_EPS_MOBILE_IDENTITY_GUTI) { target.guti.spare = 0xf; - target.guti.mme_group_id = - htons(eps_mobile_identity->guti.mme_group_id); - target.guti.m_tmsi = - htonl(eps_mobile_identity->guti.m_tmsi); + target.guti.mme_group_id = htons(eps_mobile_identity->guti.mme_group_id); + target.guti.m_tmsi = htonl(eps_mobile_identity->guti.m_tmsi); } + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, &target, size); - + return size; } -/* 9.9.3.12A EPS network feature support +/* 9.9.3.12A EPS network feature support * O TLV 3 */ -c_int16_t nas_encode_eps_network_feature_support( - pkbuf_t *pkbuf, - nas_eps_network_feature_support_t *eps_network_feature_support) +c_int16_t nas_decode_eps_network_feature_support(nas_eps_network_feature_support_t *eps_network_feature_support, pkbuf_t *pkbuf) { c_uint16_t size = 0; + nas_eps_network_feature_support_t *source = pkbuf->payload; - d_assert(eps_network_feature_support, return -1, "Null param"); + eps_network_feature_support->length = source->length; + size = eps_network_feature_support->length + sizeof(eps_network_feature_support->length); - size = eps_network_feature_support->length + - sizeof(eps_network_feature_support->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(eps_network_feature_support, pkbuf->payload - size, size); - memcpy(pkbuf->payload - size, eps_network_feature_support, size); + return size; +} + +c_int16_t nas_encode_eps_network_feature_support(pkbuf_t *pkbuf, nas_eps_network_feature_support_t *eps_network_feature_support) +{ + c_uint16_t size = eps_network_feature_support->length + sizeof(eps_network_feature_support->length); + nas_eps_network_feature_support_t target; + + memcpy(&target, eps_network_feature_support, sizeof(nas_eps_network_feature_support_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } /* 9.9.3.15 ESM message container * M LV-E 5-n */ -c_int16_t nas_decode_esm_message_container( - nas_esm_message_container_t *esm_message_container, pkbuf_t *pkbuf) +c_int16_t nas_decode_esm_message_container(nas_esm_message_container_t *esm_message_container, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_esm_message_container_t *source = pkbuf->payload; esm_message_container->length = ntohs(source->length); - size = esm_message_container->length + - sizeof(esm_message_container->length); + size = esm_message_container->length + sizeof(esm_message_container->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - esm_message_container->buffer = pkbuf->payload - size + - sizeof(esm_message_container->length); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + esm_message_container->buffer = pkbuf->payload - size + sizeof(esm_message_container->length); return size; } -c_int16_t nas_encode_esm_message_container( - pkbuf_t *pkbuf, nas_esm_message_container_t *esm_message_container) +c_int16_t nas_encode_esm_message_container(pkbuf_t *pkbuf, nas_esm_message_container_t *esm_message_container) { c_uint16_t size = 0; c_uint16_t target; @@ -483,45 +455,44 @@ c_int16_t nas_encode_esm_message_container( d_assert(esm_message_container->buffer, return -1, "Null param"); size = sizeof(esm_message_container->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); target = htons(esm_message_container->length); memcpy(pkbuf->payload - size, &target, size); size = esm_message_container->length; - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, esm_message_container->buffer, size); - return esm_message_container->length + - sizeof(esm_message_container->length); + return esm_message_container->length + sizeof(esm_message_container->length); } /* 9.9.3.16 GPRS timer - * See subclause 10.5.7.3 in 3GPP TS 24.008 [13]. - * M V 1 or O TV 2 - * - * Note : Other values shall be interpreted as multiples of 1 minute - * in this version of the protocol. */ + * M V 1 */ +c_int16_t nas_decode_gprs_timer(nas_gprs_timer_t *gprs_timer, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_gprs_timer_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(gprs_timer, pkbuf->payload - size, size); + + return size; +} + c_int16_t nas_encode_gprs_timer(pkbuf_t *pkbuf, nas_gprs_timer_t *gprs_timer) { - c_uint16_t size = 0; + c_uint16_t size = sizeof(nas_gprs_timer_t); + nas_gprs_timer_t target; - d_assert(gprs_timer, return -1, "Null param"); - - size = sizeof(nas_gprs_timer_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, gprs_timer, size); + memcpy(&target, gprs_timer, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } /* 9.9.3.16A GPRS timer 2 - * See subclause 10.5.7.4 in 3GPP TS 24.008 [13]. * O TLV 3 */ -c_int16_t nas_decode_gprs_timer_2( - nas_gprs_timer_2_t *gprs_timer_2, pkbuf_t *pkbuf) +c_int16_t nas_decode_gprs_timer_2(nas_gprs_timer_2_t *gprs_timer_2, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_gprs_timer_2_t *source = pkbuf->payload; @@ -529,33 +500,27 @@ c_int16_t nas_decode_gprs_timer_2( gprs_timer_2->length = source->length; size = gprs_timer_2->length + sizeof(gprs_timer_2->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(gprs_timer_2, pkbuf->payload - size, size); return size; } -c_int16_t nas_encode_gprs_timer_2( - pkbuf_t *pkbuf, nas_gprs_timer_2_t *gprs_timer_2) + +c_int16_t nas_encode_gprs_timer_2(pkbuf_t *pkbuf, nas_gprs_timer_2_t *gprs_timer_2) { - c_uint16_t size = 0; + c_uint16_t size = gprs_timer_2->length + sizeof(gprs_timer_2->length); + nas_gprs_timer_2_t target; - d_assert(gprs_timer_2, return -1, "Null param"); - - size = gprs_timer_2->length + sizeof(gprs_timer_2->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - memcpy(pkbuf->payload - size, gprs_timer_2, size); + memcpy(&target, gprs_timer_2, sizeof(nas_gprs_timer_2_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } /* 9.9.3.16B GPRS timer 3 - * See subclause 10.5.7.4a in 3GPP TS 24.008 [13]. * O TLV 3 */ -c_int16_t nas_decode_gprs_timer_3( - nas_gprs_timer_3_t *gprs_timer_3, pkbuf_t *pkbuf) +c_int16_t nas_decode_gprs_timer_3(nas_gprs_timer_3_t *gprs_timer_3, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_gprs_timer_3_t *source = pkbuf->payload; @@ -563,43 +528,74 @@ c_int16_t nas_decode_gprs_timer_3( gprs_timer_3->length = source->length; size = gprs_timer_3->length + sizeof(gprs_timer_3->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(gprs_timer_3, pkbuf->payload - size, size); return size; } -c_int16_t nas_encode_gprs_timer_3( - pkbuf_t *pkbuf, nas_gprs_timer_3_t *gprs_timer_3) + +c_int16_t nas_encode_gprs_timer_3(pkbuf_t *pkbuf, nas_gprs_timer_3_t *gprs_timer_3) { - c_uint16_t size = 0; + c_uint16_t size = gprs_timer_3->length + sizeof(gprs_timer_3->length); + nas_gprs_timer_3_t target; - d_assert(gprs_timer_3, return -1, "Null param"); - - size = gprs_timer_3->length + sizeof(gprs_timer_3->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - memcpy(pkbuf->payload - size, gprs_timer_3, size); + memcpy(&target, gprs_timer_3, sizeof(nas_gprs_timer_3_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } /* 9.9.3.18 IMEISV request - * See subclause 10.5.5.10 in 3GPP TS 24.008 [13]. * O TV 1 */ -c_int16_t nas_encode_imeisv_request( - pkbuf_t *pkbuf, nas_imeisv_request_t *imeisv_request) +c_int16_t nas_decode_imeisv_request(nas_imeisv_request_t *imeisv_request, pkbuf_t *pkbuf) { memcpy(imeisv_request, pkbuf->payload - 1, 1); + return 0; } +c_int16_t nas_encode_imeisv_request(pkbuf_t *pkbuf, nas_imeisv_request_t *imeisv_request) +{ + c_uint16_t size = sizeof(nas_imeisv_request_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, imeisv_request, size); + + return size; +} + +/* 9.9.3.2 Authentication parameter AUTN + * M LV 17 */ +c_int16_t nas_decode_authentication_parameter_autn(nas_authentication_parameter_autn_t *authentication_parameter_autn, pkbuf_t *pkbuf) +{ + c_uint16_t size = 0; + nas_authentication_parameter_autn_t *source = pkbuf->payload; + + authentication_parameter_autn->length = source->length; + size = authentication_parameter_autn->length + sizeof(authentication_parameter_autn->length); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(authentication_parameter_autn, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_authentication_parameter_autn(pkbuf_t *pkbuf, nas_authentication_parameter_autn_t *authentication_parameter_autn) +{ + c_uint16_t size = authentication_parameter_autn->length + sizeof(authentication_parameter_autn->length); + nas_authentication_parameter_autn_t target; + + memcpy(&target, authentication_parameter_autn, sizeof(nas_authentication_parameter_autn_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + /* 9.9.3.20 MS network capability - * See subclause 10.5.5.12 in 3GPP TS 24.008 * O TLV 4-10 */ -c_int16_t nas_decode_ms_network_capability( - nas_ms_network_capability_t *ms_network_capability, pkbuf_t *pkbuf) +c_int16_t nas_decode_ms_network_capability(nas_ms_network_capability_t *ms_network_capability, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_ms_network_capability_t *source = pkbuf->payload; @@ -607,209 +603,316 @@ c_int16_t nas_decode_ms_network_capability( ms_network_capability->length = source->length; size = ms_network_capability->length + sizeof(ms_network_capability->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(ms_network_capability, pkbuf->payload - size, size); return size; } -/* 9.9.3.20A MS network feature support - * See subclause 10.5.1.15 in 3GPP TS 24.008 [13]. - * O TV 1 */ -c_int16_t nas_decode_ms_network_feature_support( - nas_ms_network_feature_support_t *ms_network_feature_support, - pkbuf_t *pkbuf) +c_int16_t nas_encode_ms_network_capability(pkbuf_t *pkbuf, nas_ms_network_capability_t *ms_network_capability) { - memcpy(ms_network_feature_support, pkbuf->payload - 1, 1); - return 0; -} + c_uint16_t size = ms_network_capability->length + sizeof(ms_network_capability->length); + nas_ms_network_capability_t target; -/* 9.9.3.21 NAS key set identifier - * M V 1/2 - * 9.9.2.9 Spare half octet - * M V 1/2 */ -c_int16_t nas_encode_nas_key_set_identifier( - pkbuf_t *pkbuf, nas_key_set_identifier_t *nas_key_set_identifier) -{ - c_uint16_t size = 0; - - d_assert(nas_key_set_identifier, return -1, "Null param"); - - size = sizeof(nas_key_set_identifier_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, nas_key_set_identifier, size); - - return size; -} - -/* 9.9.3.23 NAS security algorithms - * M V 1 */ -c_int16_t nas_encode_nas_security_algorithms( - pkbuf_t *pkbuf, nas_security_algorithms_t *nas_security_algorithms) -{ - c_uint16_t size = 0; - - d_assert(nas_security_algorithms, return -1, "Null param"); - - size = sizeof(nas_security_algorithms_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(pkbuf->payload - size, nas_security_algorithms, size); - - return size; -} - -/* 9.9.3.24A Network resource identifier container - * See subclause 10.5.5.31 in 3GPP TS 24.008 [13]. - * O TLV 4 */ -c_int16_t nas_decode_network_resource_identifier_container( - nas_network_resource_identifier_container_t *network_resource_identifier_container, - pkbuf_t *pkbuf) -{ - c_uint16_t size = 0; - nas_network_resource_identifier_container_t *source = pkbuf->payload; - - network_resource_identifier_container->length = source->length; - size = network_resource_identifier_container->length + - sizeof(network_resource_identifier_container->length); - - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(network_resource_identifier_container, pkbuf->payload - size, size); - - return size; -} - -/* 9.9.3.25 Nonce - * O TV 5 */ -c_int16_t nas_encode_nonce(pkbuf_t *pkbuf, nas_nonce_t *nonce) -{ - c_uint16_t size = 0; - c_uint32_t target; - - d_assert(nonce, return -1, "Null param"); - - size = sizeof(nas_nonce_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - target = htonl(*nonce); + memcpy(&target, ms_network_capability, sizeof(nas_ms_network_capability_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, &target, size); return size; } -/* 9.9.3.26 P-TMSI signature - * See subclause 10.5.5.8 in 3GPP TS 24.008 - * O TV 4 */ -c_int16_t nas_decode_p_tmsi_signature( - nas_p_tmsi_signature_t *p_tmsi_signature, pkbuf_t *pkbuf) +/* 9.9.3.20A MS network feature support + * O TV 1 */ +c_int16_t nas_decode_ms_network_feature_support(nas_ms_network_feature_support_t *ms_network_feature_support, pkbuf_t *pkbuf) { - c_uint16_t size = 0; + memcpy(ms_network_feature_support, pkbuf->payload - 1, 1); - size = 3; - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(p_tmsi_signature, pkbuf->payload - size, size); + return 0; +} - *p_tmsi_signature = ntohl(*p_tmsi_signature); +c_int16_t nas_encode_ms_network_feature_support(pkbuf_t *pkbuf, nas_ms_network_feature_support_t *ms_network_feature_support) +{ + c_uint16_t size = sizeof(nas_ms_network_feature_support_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, ms_network_feature_support, size); return size; } -/* 9.9.3.26A Extended EMM cause - * O TV 1 */ -c_int16_t nas_encode_extended_emm_cause( - pkbuf_t *pkbuf, nas_extended_emm_cause_t *extended_emm_cause) +/* 9.9.3.21 key set identifier + * M V 1/2 */ +c_int16_t nas_decode_key_set_identifier(nas_key_set_identifier_t *key_set_identifier, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_key_set_identifier_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(key_set_identifier, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_key_set_identifier(pkbuf_t *pkbuf, nas_key_set_identifier_t *key_set_identifier) +{ + c_uint16_t size = sizeof(nas_key_set_identifier_t); + nas_key_set_identifier_t target; + + memcpy(&target, key_set_identifier, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.23 security algorithms + * M V 1 */ +c_int16_t nas_decode_security_algorithms(nas_security_algorithms_t *security_algorithms, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_security_algorithms_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(security_algorithms, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_security_algorithms(pkbuf_t *pkbuf, nas_security_algorithms_t *security_algorithms) +{ + c_uint16_t size = sizeof(nas_security_algorithms_t); + nas_security_algorithms_t target; + + memcpy(&target, security_algorithms, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.24A Network resource identifier container + * O TLV 4 */ +c_int16_t nas_decode_network_resource_identifier_container(nas_network_resource_identifier_container_t *network_resource_identifier_container, pkbuf_t *pkbuf) { c_uint16_t size = 0; + nas_network_resource_identifier_container_t *source = pkbuf->payload; - d_assert(extended_emm_cause, return -1, "Null param"); + network_resource_identifier_container->length = source->length; + size = network_resource_identifier_container->length + sizeof(network_resource_identifier_container->length); - size = sizeof(nas_extended_emm_cause_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(network_resource_identifier_container, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_network_resource_identifier_container(pkbuf_t *pkbuf, nas_network_resource_identifier_container_t *network_resource_identifier_container) +{ + c_uint16_t size = network_resource_identifier_container->length + sizeof(network_resource_identifier_container->length); + nas_network_resource_identifier_container_t target; + + memcpy(&target, network_resource_identifier_container, sizeof(nas_network_resource_identifier_container_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.25 Nonce + * O TV 5 */ +c_int16_t nas_decode_nonce(nas_nonce_t *nonce, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_nonce_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(nonce, pkbuf->payload - size, size); + + *nonce = ntohl(*nonce); + + return size; +} + +c_int16_t nas_encode_nonce(pkbuf_t *pkbuf, nas_nonce_t *nonce) +{ + c_uint16_t size = sizeof(nas_nonce_t); + nas_nonce_t target; + + memcpy(&target, nonce, size); + target = htonl(*nonce); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.26 P-TMSI signature + * O TV 4 */ +c_int16_t nas_decode_p_tmsi_signature(nas_p_tmsi_signature_t *p_tmsi_signature, pkbuf_t *pkbuf) +{ + c_uint16_t size = 3; + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(p_tmsi_signature, pkbuf->payload - size, size); + + *p_tmsi_signature = htonl(*p_tmsi_signature); + + return size; +} + +c_int16_t nas_encode_p_tmsi_signature(pkbuf_t *pkbuf, nas_p_tmsi_signature_t *p_tmsi_signature) +{ + c_uint16_t size = 3; + nas_p_tmsi_signature_t target; + + memcpy(&target, p_tmsi_signature, size); + *p_tmsi_signature = ntohl(*p_tmsi_signature); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.26A Extended EMM cause + * O TV 1 */ +c_int16_t nas_decode_extended_emm_cause(nas_extended_emm_cause_t *extended_emm_cause, pkbuf_t *pkbuf) +{ + memcpy(extended_emm_cause, pkbuf->payload - 1, 1); + + return 0; +} + +c_int16_t nas_encode_extended_emm_cause(pkbuf_t *pkbuf, nas_extended_emm_cause_t *extended_emm_cause) +{ + c_uint16_t size = sizeof(nas_extended_emm_cause_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, extended_emm_cause, size); return size; } +/* 9.9.3.3 Authentication parameter RAND + * M V 16 */ +c_int16_t nas_decode_authentication_parameter_rand(nas_authentication_parameter_rand_t *authentication_parameter_rand, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_authentication_parameter_rand_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(authentication_parameter_rand, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_authentication_parameter_rand(pkbuf_t *pkbuf, nas_authentication_parameter_rand_t *authentication_parameter_rand) +{ + c_uint16_t size = sizeof(nas_authentication_parameter_rand_t); + nas_authentication_parameter_rand_t target; + + memcpy(&target, authentication_parameter_rand, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + /* 9.9.3.31 TMSI status - * See subclause 10.5.5.4 in 3GPP TS 24.008 [13] * O TV 1 */ -c_int16_t nas_decode_tmsi_status( - nas_tmsi_status_t *tmsi_status, pkbuf_t *pkbuf) +c_int16_t nas_decode_tmsi_status(nas_tmsi_status_t *tmsi_status, pkbuf_t *pkbuf) { memcpy(tmsi_status, pkbuf->payload - 1, 1); return 0; } +c_int16_t nas_encode_tmsi_status(pkbuf_t *pkbuf, nas_tmsi_status_t *tmsi_status) +{ + c_uint16_t size = sizeof(nas_tmsi_status_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, tmsi_status, size); + + return size; +} + /* 9.9.3.32 Tracking area identity * O TV 6 */ -c_int16_t nas_decode_tracking_area_identity( - nas_tracking_area_identity_t *tracking_area_identity, pkbuf_t *pkbuf) +c_int16_t nas_decode_tracking_area_identity(nas_tracking_area_identity_t *tracking_area_identity, pkbuf_t *pkbuf) { - c_uint16_t size = 0; + c_uint16_t size = sizeof(nas_tracking_area_identity_t); - size = sizeof(nas_tracking_area_identity_t); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(tracking_area_identity, pkbuf->payload - size, size); - + tracking_area_identity->tac = ntohs(tracking_area_identity->tac); return size; } +c_int16_t nas_encode_tracking_area_identity(pkbuf_t *pkbuf, nas_tracking_area_identity_t *tracking_area_identity) +{ + c_uint16_t size = sizeof(nas_tracking_area_identity_t); + nas_tracking_area_identity_t target; + + memcpy(&target, tracking_area_identity, size); + target.tac = htons(tracking_area_identity->tac); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + /* 9.9.3.33 Tracking area identity list * M LV 7-97 */ -c_int16_t nas_encode_tracking_area_identity_list( - pkbuf_t *pkbuf, - nas_tracking_area_identity_list_t *tracking_area_identity_list) +c_int16_t nas_decode_tracking_area_identity_list(nas_tracking_area_identity_list_t *tracking_area_identity_list, pkbuf_t *pkbuf) { c_uint16_t size = 0; + nas_tracking_area_identity_list_t *source = pkbuf->payload; + + tracking_area_identity_list->length = source->length; + size = tracking_area_identity_list->length + sizeof(tracking_area_identity_list->length); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(tracking_area_identity_list, pkbuf->payload - size, size); + int i = 0; + { + if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS) + for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++) + tracking_area_identity_list->type0.tac[i] = ntohs(tracking_area_identity_list->type0.tac[i]); + else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS) + tracking_area_identity_list->type1.tac = ntohs(tracking_area_identity_list->type1.tac); + else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS) + for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++) + tracking_area_identity_list->type2.tai[i].tac = ntohs(tracking_area_identity_list->type2.tai[i].tac); + else + return -1; + } + + return size; +} + +c_int16_t nas_encode_tracking_area_identity_list(pkbuf_t *pkbuf, nas_tracking_area_identity_list_t *tracking_area_identity_list) +{ + c_uint16_t size = tracking_area_identity_list->length + sizeof(tracking_area_identity_list->length); nas_tracking_area_identity_list_t target; - d_assert(tracking_area_identity_list, return -1, "Null param"); - memcpy(&target, tracking_area_identity_list, - sizeof(nas_tracking_area_identity_list_t)); + memcpy(&target, tracking_area_identity_list, sizeof(nas_tracking_area_identity_list_t)); + int i = 0; + { + if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS) + for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++) + target.type0.tac[i] = htons(tracking_area_identity_list->type0.tac[i]); + else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS) + target.type1.tac = htons(tracking_area_identity_list->type1.tac); + else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS) + for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++) + target.type2.tai[i].tac = htons(tracking_area_identity_list->type2.tai[i].tac); + else + return -1; + } - size = tracking_area_identity_list->length + - sizeof(tracking_area_identity_list->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - if (tracking_area_identity_list->type_of_list == - NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS) - { - for (i = 0; i < tracking_area_identity_list->number_of_elements + 1&& - i < NAS_MAX_TRACKING_AREA_IDENTITY; i++) - { - target.type0.tac[i] = - htons(tracking_area_identity_list->type0.tac[i]); - } - } - else if (tracking_area_identity_list->type_of_list == - NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS) - { - target.type1.tac = htons(tracking_area_identity_list->type1.tac); - } - else if (tracking_area_identity_list->type_of_list == - NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS) - { - for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && - i < NAS_MAX_TRACKING_AREA_IDENTITY; i++) - { - target.type2.tai[i].tac = - htons(tracking_area_identity_list->type2.tai[i].tac); - } - } - else - return -1; + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, &target, size); return size; @@ -817,126 +920,236 @@ c_int16_t nas_encode_tracking_area_identity_list( /* 9.9.3.34 UE network capability * M LV 3-14 */ -c_int16_t nas_decode_ue_network_capability( - nas_ue_network_capability_t *ue_network_capability, pkbuf_t *pkbuf) +c_int16_t nas_decode_ue_network_capability(nas_ue_network_capability_t *ue_network_capability, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_ue_network_capability_t *source = pkbuf->payload; ue_network_capability->length = source->length; - size = ue_network_capability->length + - sizeof(ue_network_capability->length); + size = ue_network_capability->length + sizeof(ue_network_capability->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(ue_network_capability, pkbuf->payload - size, size); return size; } +c_int16_t nas_encode_ue_network_capability(pkbuf_t *pkbuf, nas_ue_network_capability_t *ue_network_capability) +{ + c_uint16_t size = ue_network_capability->length + sizeof(ue_network_capability->length); + nas_ue_network_capability_t target; + + memcpy(&target, ue_network_capability, sizeof(nas_ue_network_capability_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + /* 9.9.3.36 UE security capability * M LV 3-6 */ -c_int16_t nas_encode_ue_security_capability( - pkbuf_t *pkbuf, nas_ue_security_capability_t *ue_security_capability) +c_int16_t nas_decode_ue_security_capability(nas_ue_security_capability_t *ue_security_capability, pkbuf_t *pkbuf) { c_uint16_t size = 0; + nas_ue_security_capability_t *source = pkbuf->payload; - d_assert(ue_security_capability, return -1, "Null param"); + ue_security_capability->length = source->length; + size = ue_security_capability->length + sizeof(ue_security_capability->length); - size = ue_security_capability->length + - sizeof(ue_security_capability->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - memcpy(pkbuf->payload - size, ue_security_capability, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(ue_security_capability, pkbuf->payload - size, size); return size; } -/* TODO : 9.9.3.37 Emergency number list - * See subclause 10.5.3.13 in 3GPP TS 24.008 [13]. - * O TLV 5-50 */ -c_int16_t nas_encode_emergency_number_list( - pkbuf_t *pkbuf, nas_emergency_number_list_t *emergency_number_list) +c_int16_t nas_encode_ue_security_capability(pkbuf_t *pkbuf, nas_ue_security_capability_t *ue_security_capability) { - c_uint16_t size = 0; - nas_emergency_number_list_t target; - - d_assert(emergency_number_list, return -1, "Null param"); - memcpy(&target, emergency_number_list, sizeof(nas_emergency_number_list_t)); - - size = emergency_number_list->length + sizeof(emergency_number_list->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + c_uint16_t size = ue_security_capability->length + sizeof(ue_security_capability->length); + nas_ue_security_capability_t target; + memcpy(&target, ue_security_capability, sizeof(nas_ue_security_capability_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(pkbuf->payload - size, &target, size); return size; } -/* 9.9.3.44 Voice domain preference and UE's usage setting - * See subclause 10.5.5.28 in 3GPP TS 24.008 [13]. +/* 9.9.3.37 Emergency number list + * O TLV 5-50 */ +c_int16_t nas_decode_emergency_number_list(nas_emergency_number_list_t *emergency_number_list, pkbuf_t *pkbuf) +{ + c_uint16_t size = 0; + nas_emergency_number_list_t *source = pkbuf->payload; + + emergency_number_list->length = source->length; + size = emergency_number_list->length + sizeof(emergency_number_list->length); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(emergency_number_list, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_emergency_number_list(pkbuf_t *pkbuf, nas_emergency_number_list_t *emergency_number_list) +{ + c_uint16_t size = emergency_number_list->length + sizeof(emergency_number_list->length); + nas_emergency_number_list_t target; + + memcpy(&target, emergency_number_list, sizeof(nas_emergency_number_list_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.4 Authentication response parameter + * M LV 5-17 */ +c_int16_t nas_decode_authentication_response_parameter(nas_authentication_response_parameter_t *authentication_response_parameter, pkbuf_t *pkbuf) +{ + c_uint16_t size = 0; + nas_authentication_response_parameter_t *source = pkbuf->payload; + + authentication_response_parameter->length = source->length; + size = authentication_response_parameter->length + sizeof(authentication_response_parameter->length); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(authentication_response_parameter, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_authentication_response_parameter(pkbuf_t *pkbuf, nas_authentication_response_parameter_t *authentication_response_parameter) +{ + c_uint16_t size = authentication_response_parameter->length + sizeof(authentication_response_parameter->length); + nas_authentication_response_parameter_t target; + + memcpy(&target, authentication_response_parameter, sizeof(nas_authentication_response_parameter_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.44 Voice domain preference and UE usage setting * O TLV 3 */ -c_int16_t nas_decode_voice_domain_preference_and_ue_usage_setting( - nas_voice_domain_preference_and_ue_usage_setting_t * - voice_domain_preference_and_ue_usage_setting, - pkbuf_t *pkbuf) +c_int16_t nas_decode_voice_domain_preference_and_ue_usage_setting(nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_voice_domain_preference_and_ue_usage_setting_t *source = pkbuf->payload; voice_domain_preference_and_ue_usage_setting->length = source->length; - size = voice_domain_preference_and_ue_usage_setting->length + - sizeof(voice_domain_preference_and_ue_usage_setting->length); + size = voice_domain_preference_and_ue_usage_setting->length + sizeof(voice_domain_preference_and_ue_usage_setting->length); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(voice_domain_preference_and_ue_usage_setting, pkbuf->payload - size, size); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - memcpy(voice_domain_preference_and_ue_usage_setting, - pkbuf->payload - size, size); - return size; } -/* 9.9.3.45 GUTI type +c_int16_t nas_encode_voice_domain_preference_and_ue_usage_setting(pkbuf_t *pkbuf, nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting) +{ + c_uint16_t size = voice_domain_preference_and_ue_usage_setting->length + sizeof(voice_domain_preference_and_ue_usage_setting->length); + nas_voice_domain_preference_and_ue_usage_setting_t target; + + memcpy(&target, voice_domain_preference_and_ue_usage_setting, sizeof(nas_voice_domain_preference_and_ue_usage_setting_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.45 GUTI type * O TV 1 */ c_int16_t nas_decode_guti_type(nas_guti_type_t *guti_type, pkbuf_t *pkbuf) { memcpy(guti_type, pkbuf->payload - 1, 1); + return 0; } +c_int16_t nas_encode_guti_type(pkbuf_t *pkbuf, nas_guti_type_t *guti_type) +{ + c_uint16_t size = sizeof(nas_guti_type_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, guti_type, size); + + return size; +} + /* 9.9.3.46 Extended DRX parameters - * See subclause 10.5.5.32 in 3GPP TS 24.008 [13]. * O TLV 3 */ -c_int16_t nas_decode_extended_drx_parameters( - nas_extended_drx_parameters_t *extended_drx_parameters, pkbuf_t *pkbuf) +c_int16_t nas_decode_extended_drx_parameters(nas_extended_drx_parameters_t *extended_drx_parameters, pkbuf_t *pkbuf) { c_uint16_t size = 0; nas_extended_drx_parameters_t *source = pkbuf->payload; extended_drx_parameters->length = source->length; - size = extended_drx_parameters->length + - sizeof(extended_drx_parameters->length); + size = extended_drx_parameters->length + sizeof(extended_drx_parameters->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); memcpy(extended_drx_parameters, pkbuf->payload - size, size); - + return size; } -c_int16_t nas_encode_extended_drx_parameters( - pkbuf_t *pkbuf, nas_extended_drx_parameters_t *extended_drx_parameters) + +c_int16_t nas_encode_extended_drx_parameters(pkbuf_t *pkbuf, nas_extended_drx_parameters_t *extended_drx_parameters) { - c_uint16_t size = 0; + c_uint16_t size = extended_drx_parameters->length + sizeof(extended_drx_parameters->length); + nas_extended_drx_parameters_t target; - d_assert(extended_drx_parameters, return -1, "Null param"); - - size = extended_drx_parameters->length + - sizeof(extended_drx_parameters->length); - d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, - return -1, "pkbuf_header error"); - - memcpy(pkbuf->payload - size, extended_drx_parameters, size); + memcpy(&target, extended_drx_parameters, sizeof(nas_extended_drx_parameters_t)); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); return size; } + +/* 9.9.3.8 DRX parameter + * O TV 3 */ +c_int16_t nas_decode_drx_parameter(nas_drx_parameter_t *drx_parameter, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_drx_parameter_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(drx_parameter, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_drx_parameter(pkbuf_t *pkbuf, nas_drx_parameter_t *drx_parameter) +{ + c_uint16_t size = sizeof(nas_drx_parameter_t); + nas_drx_parameter_t target; + + memcpy(&target, drx_parameter, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + +/* 9.9.3.9 EMM cause + * O TV 2 */ +c_int16_t nas_decode_emm_cause(nas_emm_cause_t *emm_cause, pkbuf_t *pkbuf) +{ + c_uint16_t size = sizeof(nas_emm_cause_t); + + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(emm_cause, pkbuf->payload - size, size); + + return size; +} + +c_int16_t nas_encode_emm_cause(pkbuf_t *pkbuf, nas_emm_cause_t *emm_cause) +{ + c_uint16_t size = sizeof(nas_emm_cause_t); + nas_emm_cause_t target; + + memcpy(&target, emm_cause, size); + d_assert(pkbuf_header(pkbuf, -size) == CORE_OK, return -1, "pkbuf_header error"); + memcpy(pkbuf->payload - size, &target, size); + + return size; +} + diff --git a/lib/nas/nas_ies.h b/lib/nas/nas_ies.h index e9c3dcd25..b8b3780dc 100644 --- a/lib/nas/nas_ies.h +++ b/lib/nas/nas_ies.h @@ -1,898 +1,134 @@ -#ifndef _NAS_IES_H__ -#define _NAS_IES_H__ +/* + * Copyright (c) 2017, CellWire Group + * 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. + */ + +/******************************************************************************* + * 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-03-21 13:49:52.073350 by acetcom + * from 24301-d80.docx + ******************************************************************************/ + +#ifndef __NAS_IES_H__ +#define __NAS_IES_H__ #include "core_pkbuf.h" - -#include "3gpp_message.h" +#include "nas_types.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -typedef struct _nas_plmn_t { -ED2(c_uint8_t mcc_digit2:4;, - c_uint8_t mcc_digit1:4;) -ED2(c_uint8_t mnc_digit3:4;, - c_uint8_t mcc_digit3:4;) -ED2(c_uint8_t mnc_digit2:4;, - c_uint8_t mnc_digit1:4;) -} __attribute__ ((packed)) nas_plmn_t; - -CORE_DECLARE(c_int16_t) nas_encode_optional_type( - pkbuf_t *pkbuf, c_uint8_t type); - -/* 9.9.2.0A Device properties - * See subclause 10.5.7.8 in 3GPP TS 24.008 [13]. - * O TV 1 */ -typedef struct _nas_device_properties_t { -ED3(c_uint8_t type:4;, - c_uint8_t spare:3;, - c_uint8_t low_priority:1;) -} __attribute__ ((packed)) nas_device_properties_t; - -CORE_DECLARE(c_int16_t) nas_decode_device_properties( - nas_device_properties_t *device_properties, pkbuf_t *pkbuf); - -/* 9.9.2.2 Location area identification - * See subclause 10.5.1.3 in 3GPP TS 24.008 [13] - * O TV 6 */ -typedef struct _nas_location_area_identification_t { - nas_plmn_t plmn; - c_uint16_t lac; -} __attribute__ ((packed)) nas_location_area_identification_t; - -CORE_DECLARE(c_int16_t) nas_decode_location_area_identification( - nas_location_area_identification_t *location_area_identification, - pkbuf_t *pkbuf); - -CORE_DECLARE(c_int16_t) nas_encode_location_area_identification( - pkbuf_t *pkbuf, - nas_location_area_identification_t *location_area_identification); - -/* 9.9.2.3 Mobile identity - * See subclause 10.5.1.4 in 3GPP TS 24.008 [13]. - * O TLV 7-10 */ -#define NAS_MOBILE_IDENTITY_NONE 0 -#define NAS_MOBILE_IDENTITY_IMSI 1 -#define NAS_MOBILE_IDENTITY_IMEI 2 -#define NAS_MOBILE_IDENTITY_IMEISV 3 -#define NAS_MOBILE_IDENTITY_TMSI 4 -#define NAS_MOBILE_IDENTITY_TMGI 5 -#define NAS_MOBILE_IDENTITY_GUTI 6 -typedef struct _nas_mobile_identity_imsi { -ED3(c_uint8_t digit1:4;, - c_uint8_t odd_even:1;, - c_uint8_t type_of_identity:3;) -ED2(c_uint8_t digit3:4;, - c_uint8_t digit2:4;) -ED2(c_uint8_t digit5:4;, - c_uint8_t digit4:4;) -ED2(c_uint8_t digit7:4;, - c_uint8_t digit6:4;) -ED2(c_uint8_t digit9:4;, - c_uint8_t digit8:4;) -ED2(c_uint8_t digit11:4;, - c_uint8_t digit10:4;) -ED2(c_uint8_t digit13:4;, - c_uint8_t digit12:4;) -ED2(c_uint8_t digit15:4;, - c_uint8_t digit14:4;) -} __attribute__ ((packed)) nas_mobile_identity_imsi_t; - -typedef struct _nas_mobile_identity_tmsi { -ED3(c_uint8_t spare:4;, - c_uint8_t odd_even:1;, - c_uint8_t type_of_identity:3;) - c_uint32_t tmsi; -} __attribute__ ((packed)) nas_mobile_identity_tmsi_t; - -typedef struct _nas_mobile_identity_tmgi { -ED5(c_uint8_t spare:2;, - c_uint8_t mbms_session_id:1;, - c_uint8_t mcc_mnc:1;, - c_uint8_t odd_even:1;, - c_uint8_t type_of_identity:3;) - c_uint8_t mbms_servicec_id[3]; - nas_plmn_t plmn; - c_uint8_t mbms_session_identity; -} __attribute__ ((packed)) nas_mobile_identity_tmgi_t; - -typedef struct _nas_mobile_identity_t { - c_uint8_t length; - union { - nas_mobile_identity_imsi_t imsi; - nas_mobile_identity_tmsi_t tmsi; - nas_mobile_identity_tmgi_t tmgi; - }; -} nas_mobile_identity_t; - -CORE_DECLARE(c_int16_t) nas_encode_mobile_identity( - pkbuf_t *pkbuf, nas_mobile_identity_t *mobile_identity); -CORE_DECLARE(c_int16_t) nas_decode_mobile_identity( - nas_mobile_identity_t *mobile_identity, pkbuf_t *pkbuf); - -/* 9.9.2.4 Mobile station classmark 2 - * See subclause 10.5.1.6 in 3GPP TS 24.008 - * O TLV 5 */ -#define NAS_MS_CLASSMARK_2_REVISION_GSM_PHASE1 0 -#define NAS_MS_CLASSMARK_2_REVISION_GSM_PHASE2 1 -#define NAS_MS_CLASSMARK_2_REVISION_R99 2 -#define NAS_MS_CLASSMARK_2_REVISION_RESERVED 2 - -#define NAS_MS_CLASSMARK_2_RF_CLASS1 0 -#define NAS_MS_CLASSMARK_2_RF_CLASS2 1 -#define NAS_MS_CLASSMARK_2_RF_CLASS3 2 -#define NAS_MS_CLASSMARK_2_RF_CLASS4 3 -#define NAS_MS_CLASSMARK_2_RF_CLASS5 4 -#define NAS_MS_CLASSMARK_2_RF_IRRELEVANT 7 -typedef struct nas_mobile_station_classmark_2_t { - c_uint8_t length; -ED5(c_uint8_t spare1:1;, - c_uint8_t revision_level:2;, - c_uint8_t es_ind:1;, - c_uint8_t a5_1:1;, - c_uint8_t rf_power_capability:3;) -ED7(c_uint8_t spare:1;, - c_uint8_t ps_capa:1;, - c_uint8_t ss_screen_indicator:2;, - c_uint8_t sm_capabi:1;, - c_uint8_t vbs:1;, - c_uint8_t vgcs:1;, - c_uint8_t fc:1;) -ED8(c_uint8_t cm3:1;, - c_uint8_t spare2:1;, - c_uint8_t lcsva_cap:1;, - c_uint8_t ucs2:1;, - c_uint8_t solsa:1;, - c_uint8_t cmsp:1;, - c_uint8_t a5_3:1;, - c_uint8_t a5_2:1;) -} __attribute__ ((packed)) nas_mobile_station_classmark_2_t; - -CORE_DECLARE(c_int16_t) nas_decode_mobile_station_classmark_2( - nas_mobile_station_classmark_2_t *mobile_station_classmark_2, - pkbuf_t *pkbuf); - -/*9.9.2.5 Mobile station classmark 3 - * See subclause 10.5.1.7 in 3GPP TS 24.008 [13]. - * O TLV 2-34 */ -typedef struct _nas_mobile_station_classmark_3_t { - c_uint8_t length; - c_uint8_t todo[34]; -} __attribute__ ((packed)) nas_mobile_station_classmark_3_t; - -CORE_DECLARE(c_int16_t) nas_decode_mobile_station_classmark_3( - nas_mobile_station_classmark_3_t *mobile_station_classmark_3, - pkbuf_t *pkbuf); - -/* 9.9.2.8 PLMN list - * See subclause 10.5.1.13 in 3GPP TS 24.008 [13]. - * O TLV 5-47 */ -#define NAS_MAX_PLMN 15 -typedef struct _nas_plmn_list_t { - c_uint8_t length; - nas_plmn_t plmn[NAS_MAX_PLMN]; -} __attribute__ ((packed)) nas_plmn_list_t; - -CORE_DECLARE(c_int16_t) nas_encode_plmn_list( - pkbuf_t *pkbuf, nas_plmn_list_t *plmn_list); - -/* 9.9.2.10 Supported codec list - * See subclause 10.5.4.32 in 3GPP TS 24.008 [13]. - * O TLV 5-n */ -typedef struct _nas_supported_codec_item_t { - c_uint8_t system_identification; - c_uint8_t length_of_bitmap; - c_uint16_t codec_bitmap; -} __attribute__ ((packed)) nas_supported_codec_item_t; - -#define NAS_MAX_SUPPORTED_CODECS 8 -typedef struct _nas_supported_codec_list_t { - c_uint8_t length; - nas_supported_codec_item_t item[NAS_MAX_SUPPORTED_CODECS]; -} __attribute__ ((packed)) nas_supported_codec_list_t; - -CORE_DECLARE(c_int16_t) nas_decode_supported_codec_list( - nas_supported_codec_list_t *supported_codec_list, pkbuf_t *pkbuf); - -/* 9.9.3.0A Additional update result - * O TV 1 */ -typedef struct _nas_additional_update_result_t { -ED3(c_uint8_t type:4;, - c_uint8_t spare:2;, - c_uint8_t additional_update_result_value:2;) -} __attribute__ ((packed)) nas_additional_update_result_t; - -CORE_DECLARE(c_int16_t) nas_encode_additional_update_result( - pkbuf_t *pkbuf, - nas_additional_update_result_t *additional_update_result); - -/* 9.9.3.0B Additional update type - * O TV 1 */ -#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_NONE 0 -#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_CONTROL_PLANE 1 -#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_DATA_PLANE 2 -#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_RESERVED 3 -typedef struct _nas_additional_update_type_t { -ED4(c_uint8_t type:4;, - c_uint8_t pnb_ciot:2;, - c_uint8_t saf:1;, - c_uint8_t autv:1;) -} __attribute__ ((packed)) nas_additional_update_type_t; - -CORE_DECLARE(c_int16_t) nas_decode_additional_update_type( - nas_additional_update_type_t *additional_update_type, pkbuf_t *pkbuf); - -/* 9.9.3.1 Authentication failure parameter - * See subclause 10.5.3.2.2 in 3GPP TS 24.008 [13]. - * O TLV 16 */ -typedef struct _nas_authentication_failure_parameter_t { - c_uint8_t length; - c_uint8_t parameter[14]; -} __attribute__ ((packed)) nas_authentication_failure_parameter_t; - -CORE_DECLARE(c_int16_t) nas_decode_authentication_failure_parameter( - nas_authentication_failure_parameter_t *authentication_failure_parameter, - pkbuf_t *pkbuf); - -/* 9.9.3.2 Authentication parameter AUTN - * See subclause 10.5.3.1.1 in 3GPP TS 24.008 [13]. - * M LV 17 */ -typedef struct _nas_authentication_parameter_autn_t { - c_uint8_t length; - c_uint8_t autn[MAX_AUTN_LEN]; -} nas_authentication_parameter_autn_t; - -CORE_DECLARE(c_int16_t) nas_encode_authentication_parameter_autn(pkbuf_t *pkbuf, - nas_authentication_parameter_autn_t *authentication_parameter_autn); - -/* 9.9.3.3 Authentication parameter RAND - * See subclause 10.5.3.1 in 3GPP TS 24.008 [13]. - * M V 16 */ -typedef struct _nas_authentication_parameter_rand_t { - c_uint8_t rand[MAX_RAND_LEN]; -} nas_authentication_parameter_rand_t; - -CORE_DECLARE(c_int16_t) nas_encode_authentication_parameter_rand(pkbuf_t *pkbuf, - nas_authentication_parameter_rand_t *authentication_parameter_rand); - -/* 9.9.3.4 Authentication response parameter - * M LV 5-17 */ -typedef struct _nas_authentication_response_parameter_t { - c_uint8_t length; - c_uint8_t res[MAX_RES_LEN]; -} nas_authentication_response_parameter_t; - -CORE_DECLARE(c_int16_t) nas_decode_authentication_response_parameter( - nas_authentication_response_parameter_t *authentication_response_parameter, - pkbuf_t *pkbuf); - -/* 9.9.3.8 DRX parameter - * See subclause 10.5.5.6 in 3GPP TS 24.008 - * O TV 3 */ -#define NAS_DRX_PARAMETER_TIMER_MAX_1SEC 1 -#define NAS_DRX_PARAMETER_TIMER_MAX_2SEC 2 -#define NAS_DRX_PARAMETER_TIMER_MAX_4SEC 3 -#define NAS_DRX_PARAMETER_TIMER_MAX_8SEC 4 -#define NAS_DRX_PARAMETER_TIMER_MAX_16SEC 5 -#define NAS_DRX_PARAMETER_TIMER_MAX_32SEC 6 -#define NAS_DRX_PARAMETER_TIMER_MAX_64SEC 7 - -#define NAS_DRX_PARAMETER_COEFFICIENT_T_NOT_SPECIFIED_BY_MS 0 -#define NAS_DRX_PARAMETER_COEFFICIENT_6_T_32 6 -#define NAS_DRX_PARAMETER_COEFFICIENT_7_T_64 7 -#define NAS_DRX_PARAMETER_COEFFICIENT_8_T_128 8 -#define NAS_DRX_PARAMETER_COEFFICIENT_9_T_256 9 -typedef struct _nas_drx_parameter_t { - c_uint8_t split_pg_cycle_code; -ED3(c_uint8_t cn_specific_drx_cycle_length_coefficient_and_drx_value_for_s1_mode:4;, - c_uint8_t split_on_ccch:1;, - c_uint8_t non_DRX_timer:3;) -} __attribute__ ((packed)) nas_drx_parameter_t; - -CORE_DECLARE(c_int16_t) nas_decode_drx_parameter( - nas_drx_parameter_t *drx_parameter, pkbuf_t *pkbuf); - -/* 9.9.3.9 EMM cause - * O TV 2 */ -#define NAS_EMM_CAUSE_IMSI_UNKNOWN_IN_HSS 0b00000010 -#define NAS_EMM_CAUSE_ILLEGAL_UE 0b00000011 -#define NAS_EMM_CAUSE_IMEI_NOT_ACCEPTED 0b00000101 -#define NAS_EMM_CAUSE_ILLEGAL_ME 0b00000110 -#define NAS_EMM_CAUSE_EPS_SERVICES_NOT_ALLOWED 0b00000111 -#define NAS_EMM_CAUSE_EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED 0b00001000 -#define NAS_EMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK 0b00001001 -#define NAS_EMM_CAUSE_IMPLICITLY_DETACHED 0b00001010 -#define NAS_EMM_CAUSE_PLMN_NOT_ALLOWED 0b00001011 -#define NAS_EMM_CAUSE_TRACKING_AREA_NOT_ALLOWED 0b00001100 -#define NAS_EMM_CAUSE_ROAMING_NOT_ALLOWED_IN_THIS_TRACKING_AREA 0b00001101 -#define NAS_EMM_CAUSE_EPS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN 0b00001110 -#define NAS_EMM_CAUSE_NO_SUITABLE_CELLS_IN_TRACKING_AREA 0b00001111 -#define NAS_EMM_CAUSE_MSC_TEMPORARILY_NOT_REACHABLE 0b00010000 -#define NAS_EMM_CAUSE_NETWORK_FAILURE 0b00010001 -#define NAS_EMM_CAUSE_CS_DOMAIN_NOT_AVAILABLE 0b00010010 -#define NAS_EMM_CAUSE_ESM_FAILURE 0b00010011 -#define NAS_EMM_CAUSE_MAC_FAILURE 0b00010100 -#define NAS_EMM_CAUSE_SYNCH_FAILURE 0b00010101 -#define NAS_EMM_CAUSE_CONGESTION 0b00010110 -#define NAS_EMM_CAUSE_UE_SECURITY_CAPABILITIES_MISMATCH 0b00010111 -#define NAS_EMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED 0b00011000 -#define NAS_EMM_CAUSE_NOT_AUTHORIZED_FOR_THIS_CSG 0b00011001 -#define NAS_EMM_CAUSE_NON_EPS_AUTHENTICATION_UNACCEPTABLE 0b00011010 -#define NAS_EMM_CAUSE_REQUESTED_SERVICE_OPTION_NOT_AUTHORIZED_IN_THIS_PLMN 0b00100011 -#define NAS_EMM_CAUSE_CS_SERVICE_TEMPORARILY_NOT_AVAILABLE 0b00100111 -#define NAS_EMM_CAUSE_NO_EPS_BEARER_CONTEXT_ACTIVATED 0b00101000 -#define NAS_EMM_CAUSE_SEVERE_NETWORK_FAILURE 0b00101010 -#define NAS_EMM_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE 0b01011111 -#define NAS_EMM_CAUSE_INVALID_MANDATORY_INFORMATION 0b01100000 -#define NAS_EMM_CAUSE_MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED 0b01100001 -#define NAS_EMM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_THE_PROTOCOL_STATE 0b01100010 -#define NAS_EMM_CAUSE_INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED 0b01100011 -#define NAS_EMM_CAUSE_CONDITIONAL_IE_ERROR 0b01100100 -#define NAS_EMM_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_THE_PROTOCOL_STATE 0b01100101 -#define NAS_EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED 0b01101111 -typedef c_uint8_t nas_emm_cause_t; - -CORE_DECLARE(c_int16_t) nas_encode_emm_cause( - pkbuf_t *pkbuf, nas_emm_cause_t *emm_cause); -CORE_DECLARE(c_int16_t) nas_decode_emm_cause( - nas_emm_cause_t *emm_cause, pkbuf_t *pkbuf); - -/* 9.9.3.10 * EPS attach result - * M V 1/2 */ -#define NAS_ATTACH_RESULT_EPS_ONLY 1 -#define NAS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH 2 -typedef struct _nas_eps_attach_result_t { -ED2(c_uint8_t spare:5;, - c_uint8_t result:3;) -} __attribute__ ((packed)) nas_eps_attach_result_t; - -CORE_DECLARE(c_int16_t) nas_encode_eps_attach_result( - pkbuf_t *pkbuf, nas_eps_attach_result_t *eps_attach_result); - -/* 9.9.3.11 EPS attach type - * M V 1/2 - * 9.9.3.21 NAS key set identifier - * M V 1/2 */ -#define NAS_KEY_SET_IDENTIFIER_NATIVE 0 -#define NAS_KEY_SET_IDENTIFIER_MAPPED 1 -#define NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE 0x111 - -#define NAS_ATTACH_TYPE_EPS_ATTACH 1 -#define NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTAACH 2 -#define NAS_ATTACH_TYPE_EPS_ERMERGENCY_ATTCH 3 -#define NAS_ATTACH_TYPE_RESERVED 4 -typedef struct _nas_eps_attach_type_t { -ED4(c_uint8_t tsc:1;, - c_uint8_t nas_key_set_identifier:3;, - c_uint8_t spare:1;, - c_uint8_t attach_type:3;) -} __attribute__ ((packed)) nas_eps_attach_type_t; - -CORE_DECLARE(c_int16_t) nas_decode_eps_attach_type( - nas_eps_attach_type_t *eps_attach_type, pkbuf_t *pkbuf); - -/* 9.9.3.12 EPS mobile identity - * M LV 5-12 */ -#define NAS_EPS_MOBILE_IDENTITY_IMSI 1 -#define NAS_EPS_MOBILE_IDENTITY_GUTI 6 -#define NAS_EPS_MOBILE_IDENTITY_IMEI 3 - -#define NAS_EPS_MOBILE_IDENTITY_EVEN 0 -#define NAS_EPS_MOBILE_IDENTITY_ODD 1 -typedef struct _nas_eps_mobile_identity_guti_t { -ED3(c_uint8_t spare:4;, - c_uint8_t odd_even:1;, - c_uint8_t type_of_identity:3;) - nas_plmn_t plmn; - c_uint16_t mme_group_id; - c_uint8_t mme_code; - c_uint32_t m_tmsi; -} __attribute__ ((packed)) nas_eps_mobile_identity_guti_t; - -typedef nas_mobile_identity_imsi_t nas_eps_mobile_identity_imsi_t; -typedef nas_eps_mobile_identity_imsi_t nas_eps_mobile_identity_imei_t; - -typedef struct _nas_eps_mobile_identity_t { - c_uint8_t length; - union { - nas_eps_mobile_identity_imsi_t imsi; - nas_eps_mobile_identity_guti_t guti; - nas_eps_mobile_identity_imei_t imei; - }; -} __attribute__ ((packed)) nas_eps_mobile_identity_t; - -CORE_DECLARE(c_int16_t) nas_decode_eps_mobile_identity( - nas_eps_mobile_identity_t *eps_mobile_identity, pkbuf_t *pkbuf); -CORE_DECLARE(c_int16_t) nas_encode_eps_mobile_identity( - pkbuf_t *pkbuf, nas_eps_mobile_identity_t *eps_mobile_identity); - -/* 9.9.3.12A EPS network feature support - * O TLV 3 */ -typedef struct _nas_eps_network_feature_support_t { - c_uint8_t length; -ED7(c_uint8_t cp_ciot:1;, - c_uint8_t erw_opdn:1;, - c_uint8_t esr_ps:1;, - c_uint8_t cs_lcs:2;, - c_uint8_t epc_lcs:1;, - c_uint8_t emc_bs:1;, - c_uint8_t ims_vops:1;) -ED5(c_uint8_t spare:4;, - c_uint8_t e_pco:1;, - c_uint8_t hc_cp_ciot:1;, - c_uint8_t s1_u_data:1;, - c_uint8_t up_ciot :1;) -} __attribute__ ((packed)) nas_eps_network_feature_support_t; - -CORE_DECLARE(c_int16_t) nas_encode_eps_network_feature_support( - pkbuf_t *pkbuf, - nas_eps_network_feature_support_t *eps_network_feature_support); - -/* 9.9.3.15 ESM message container - * M LV-E 5-n */ -typedef struct _nas_esm_message_container_t { - c_uint16_t length; - c_uint8_t *buffer; -} nas_esm_message_container_t; - -CORE_DECLARE(c_int16_t) nas_decode_esm_message_container( - nas_esm_message_container_t *esm_message_container, pkbuf_t *pkbuf); -CORE_DECLARE(c_int16_t) nas_encode_esm_message_container( - pkbuf_t *pkbuf, nas_esm_message_container_t *esm_message_container); - -/* 9.9.3.16 GPRS timer - * See subclause 10.5.7.3 in 3GPP TS 24.008 [13]. - * M V 1 or O TV 2 */ -#define NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_2_SS 0 -#define NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_1_MM 1 -#define NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_DECI_HH 2 -#define NAS_GRPS_TIMER_UNIT_DEACTIVATED 7 -typedef struct _nas_gprs_timer_t { -ED2(c_uint8_t unit:3;, - c_uint8_t timer_value:5;) -} __attribute__ ((packed)) nas_gprs_timer_t; - -CORE_DECLARE(c_int16_t) nas_encode_gprs_timer( - pkbuf_t *pkbuf, nas_gprs_timer_t *gprs_timer); - -/* 9.9.3.16A GPRS timer 2 - * See subclause 10.5.7.4 in 3GPP TS 24.008 [13]. - * O TLV 3 */ -typedef struct _nas_gprs_timer_2_t { - c_uint8_t length; - c_uint8_t gprs_timer_2_value; -} __attribute__ ((packed)) nas_gprs_timer_2_t; - -CORE_DECLARE(c_int16_t) nas_decode_gprs_timer_2( - nas_gprs_timer_2_t *gprs_timer_2, pkbuf_t *pkbuf); -CORE_DECLARE(c_int16_t) nas_encode_gprs_timer_2( - pkbuf_t *pkbuf, nas_gprs_timer_2_t *gprs_timer_2); - -/* 9.9.3.16B GPRS timer 3 - * See subclause 10.5.7.4a in 3GPP TS 24.008 [13]. - * O TLV 3 */ -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_10_MM 0 -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_1_HH 1 -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_10_HH 2 -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_2_SS 3 -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_30_SS 4 -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_1_MM 5 -#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_320_HH 6 -#define NAS_GRPS_TIMER_3_UNIT_DEACTIVATED 7 - -typedef struct _nas_gprs_timer_3_t { - c_uint8_t length; -ED2(c_uint8_t unit:3;, - c_uint8_t timer_value:5;) -} __attribute__ ((packed)) nas_gprs_timer_3_t; - -CORE_DECLARE(c_int16_t) nas_decode_gprs_timer_3( - nas_gprs_timer_3_t *gprs_timer_3, pkbuf_t *pkbuf); -CORE_DECLARE(c_int16_t) nas_encode_gprs_timer_3( - pkbuf_t *pkbuf, nas_gprs_timer_3_t *gprs_timer_3); - -/* 9.9.3.18 IMEISV request - * See subclause 10.5.5.10 in 3GPP TS 24.008 [13]. - * O TV 1 */ -typedef struct _nas_imeisv_request_t { -ED3(c_uint8_t type:4;, - c_uint8_t spare:1;, - c_uint8_t imeisv_request_value:3;) -} __attribute__ ((packed)) nas_imeisv_request_t; - -CORE_DECLARE(c_int16_t) nas_encode_imeisv_request( - pkbuf_t *pkbuf, nas_imeisv_request_t *imeisv_request); - -/* 9.9.3.20 MS network capability - * See subclause 10.5.5.12 in 3GPP TS 24.008 - * O TLV 4-10 */ -#define NAS_MS_NETWORK_CAPABILITY_GEA2 0b01000000 -#define NAS_MS_NETWORK_CAPABILITY_GEA3 0b00100000 -#define NAS_MS_NETWORK_CAPABILITY_GEA4 0b00010000 -#define NAS_MS_NETWORK_CAPABILITY_GEA5 0b00001000 -#define NAS_MS_NETWORK_CAPABILITY_GEA6 0b00000100 -#define NAS_MS_NETWORK_CAPABILITY_GEA7 0b00000010 -typedef struct _nas_ms_network_capability_t { - c_uint8_t length; -ED7(c_uint8_t gea1:1;, - c_uint8_t sm_capabilities_via_dedicated_channels:1;, - c_uint8_t sm_capabilities_via_gprs_channels:1;, - c_uint8_t ucs2:1;, - c_uint8_t ss_screening_indicator:2;, - c_uint8_t solsa_capability:1;, - c_uint8_t revision_level_indicator:1;) -ED3(c_uint8_t pfc_feature_mode:1;, - c_uint8_t extended_gea:6;, - c_uint8_t lcs_va_capability:1;) -ED8(c_uint8_t ps_inter_rat_ho_from_geran_to_utran_iu_mode_capability:1;, - c_uint8_t ps_inter_rat_ho_from_geran_to_e_utran_s1_mode_capability:1;, - c_uint8_t emm_combined_procedures_capability:1;, - c_uint8_t isr_support:1;, - c_uint8_t srvcc_to_geran_utran_capability:1;, - c_uint8_t epc_capability:1;, - c_uint8_t nf_capability:1;, - c_uint8_t geran_network_sharing_capability:1;) -ED6(c_uint8_t user_plane_integrity_protection_support:1;, - c_uint8_t gia4:1;, - c_uint8_t gia5:1;, - c_uint8_t gia6:1;, - c_uint8_t gia7:1;, - c_uint8_t spare:3;) -} __attribute__ ((packed)) nas_ms_network_capability_t; - -CORE_DECLARE(c_int16_t) nas_decode_ms_network_capability( - nas_ms_network_capability_t *ms_network_capability, pkbuf_t *pkbuf); - -/* 9.9.3.20A MS network feature support - * See subclause 10.5.1.15 in 3GPP TS 24.008 [13]. - * O TV 1 */ -typedef struct _nas_ms_network_feature_support_t { -ED3(c_uint8_t type:4;, - c_uint8_t spare:3;, - c_uint8_t extended_periodic_timers:1;) -} __attribute__ ((packed)) nas_ms_network_feature_support_t; - -CORE_DECLARE(c_int16_t) nas_decode_ms_network_feature_support( - nas_ms_network_feature_support_t *ms_network_feature_support, - pkbuf_t *pkbuf); - -/* 9.9.3.21 NAS key set identifier - * M V 1/2 - * 9.9.2.9 Spare half octet - * M V 1/2 */ -typedef struct _nas_key_set_identifier_t { -ED3(c_uint8_t spare:4;, - c_uint8_t tsc:1;, - c_uint8_t nas_key_set_identifier:3;) -} __attribute__ ((packed)) nas_key_set_identifier_t; - -CORE_DECLARE(c_int16_t) nas_encode_nas_key_set_identifier( - pkbuf_t *pkbuf, nas_key_set_identifier_t *nas_key_set_identifier); - -/* 9.9.3.23 NAS security algorithms - * M V 1 */ -#define NAS_SECURITY_ALGORITHMS_EIA0 0 -#define NAS_SECURITY_ALGORITHMS_128_EIA1 1 -#define NAS_SECURITY_ALGORITHMS_128_EIA2 2 -#define NAS_SECURITY_ALGORITHMS_128_EIA3 3 -#define NAS_SECURITY_ALGORITHMS_EEA0 0 -#define NAS_SECURITY_ALGORITHMS_128_EEA1 1 -#define NAS_SECURITY_ALGORITHMS_128_EEA2 2 -#define NAS_SECURITY_ALGORITHMS_128_EEA3 3 -typedef struct _nas_security_algorithms_t { -ED4(c_uint8_t spare1:1;, - c_uint8_t type_of_ciphering_algorithm:3;, - c_uint8_t spare2:1;, - c_uint8_t type_of_integrity_protection_algorithm:3;) -} __attribute__ ((packed)) nas_security_algorithms_t; - -CORE_DECLARE(c_int16_t) nas_encode_nas_security_algorithms( - pkbuf_t *pkbuf, nas_security_algorithms_t *nas_security_algorithms); - -/* 9.9.3.24A Network resource identifier container - * See subclause 10.5.5.31 in 3GPP TS 24.008 [13]. - * O TLV 4 */ -typedef struct _nas_network_resource_identifier_container_t { - c_uint8_t length; - c_uint8_t nri_container_value1; -ED2(c_uint8_t nri_container_value2:2;, - c_uint8_t spare:6;) -} __attribute__ ((packed)) nas_network_resource_identifier_container_t; - -CORE_DECLARE(c_int16_t) nas_decode_network_resource_identifier_container( - nas_network_resource_identifier_container_t * - network_resource_identifier_container, - pkbuf_t *pkbuf); - -/* 9.9.3.25 Nonce - * O TV 5 */ -typedef c_uint32_t nas_nonce_t; - +CORE_DECLARE(c_int16_t) nas_encode_optional_type(pkbuf_t *pkbuf, c_uint8_t type); + +CORE_DECLARE(c_int16_t) nas_decode_device_properties(nas_device_properties_t *device_properties, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_supported_codec_list(nas_supported_codec_list_t *supported_codec_list, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_location_area_identification(nas_location_area_identification_t *location_area_identification, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_mobile_identity(nas_mobile_identity_t *mobile_identity, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_mobile_station_classmark_2(nas_mobile_station_classmark_2_t *mobile_station_classmark_2, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_mobile_station_classmark_3(nas_mobile_station_classmark_3_t *mobile_station_classmark_3, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_plmn_list(nas_plmn_list_t *plmn_list, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_additional_update_result(nas_additional_update_result_t *additional_update_result, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_additional_update_type(nas_additional_update_type_t *additional_update_type, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_authentication_failure_parameter(nas_authentication_failure_parameter_t *authentication_failure_parameter, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_eps_attach_result(nas_eps_attach_result_t *eps_attach_result, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_eps_attach_type(nas_eps_attach_type_t *eps_attach_type, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_eps_mobile_identity(nas_eps_mobile_identity_t *eps_mobile_identity, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_eps_network_feature_support(nas_eps_network_feature_support_t *eps_network_feature_support, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_esm_message_container(nas_esm_message_container_t *esm_message_container, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_gprs_timer(nas_gprs_timer_t *gprs_timer, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_gprs_timer_2(nas_gprs_timer_2_t *gprs_timer_2, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_gprs_timer_3(nas_gprs_timer_3_t *gprs_timer_3, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_imeisv_request(nas_imeisv_request_t *imeisv_request, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_authentication_parameter_autn(nas_authentication_parameter_autn_t *authentication_parameter_autn, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_ms_network_capability(nas_ms_network_capability_t *ms_network_capability, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_ms_network_feature_support(nas_ms_network_feature_support_t *ms_network_feature_support, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_key_set_identifier(nas_key_set_identifier_t *key_set_identifier, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_security_algorithms(nas_security_algorithms_t *security_algorithms, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_network_resource_identifier_container(nas_network_resource_identifier_container_t *network_resource_identifier_container, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_nonce(nas_nonce_t *nonce, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_p_tmsi_signature(nas_p_tmsi_signature_t *p_tmsi_signature, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_extended_emm_cause(nas_extended_emm_cause_t *extended_emm_cause, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_authentication_parameter_rand(nas_authentication_parameter_rand_t *authentication_parameter_rand, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_tmsi_status(nas_tmsi_status_t *tmsi_status, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_tracking_area_identity(nas_tracking_area_identity_t *tracking_area_identity, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_tracking_area_identity_list(nas_tracking_area_identity_list_t *tracking_area_identity_list, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_ue_network_capability(nas_ue_network_capability_t *ue_network_capability, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_ue_security_capability(nas_ue_security_capability_t *ue_security_capability, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_emergency_number_list(nas_emergency_number_list_t *emergency_number_list, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_authentication_response_parameter(nas_authentication_response_parameter_t *authentication_response_parameter, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_voice_domain_preference_and_ue_usage_setting(nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_guti_type(nas_guti_type_t *guti_type, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_extended_drx_parameters(nas_extended_drx_parameters_t *extended_drx_parameters, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_drx_parameter(nas_drx_parameter_t *drx_parameter, pkbuf_t *pkbuf); +CORE_DECLARE(c_int16_t) nas_decode_emm_cause(nas_emm_cause_t *emm_cause, pkbuf_t *pkbuf); + +CORE_DECLARE(c_int16_t) nas_encode_device_properties(pkbuf_t *pkbuf, nas_device_properties_t *device_properties); +CORE_DECLARE(c_int16_t) nas_encode_supported_codec_list(pkbuf_t *pkbuf, nas_supported_codec_list_t *supported_codec_list); +CORE_DECLARE(c_int16_t) nas_encode_location_area_identification(pkbuf_t *pkbuf, nas_location_area_identification_t *location_area_identification); +CORE_DECLARE(c_int16_t) nas_encode_mobile_identity(pkbuf_t *pkbuf, nas_mobile_identity_t *mobile_identity); +CORE_DECLARE(c_int16_t) nas_encode_mobile_station_classmark_2(pkbuf_t *pkbuf, nas_mobile_station_classmark_2_t *mobile_station_classmark_2); +CORE_DECLARE(c_int16_t) nas_encode_mobile_station_classmark_3(pkbuf_t *pkbuf, nas_mobile_station_classmark_3_t *mobile_station_classmark_3); +CORE_DECLARE(c_int16_t) nas_encode_plmn_list(pkbuf_t *pkbuf, nas_plmn_list_t *plmn_list); +CORE_DECLARE(c_int16_t) nas_encode_additional_update_result(pkbuf_t *pkbuf, nas_additional_update_result_t *additional_update_result); +CORE_DECLARE(c_int16_t) nas_encode_additional_update_type(pkbuf_t *pkbuf, nas_additional_update_type_t *additional_update_type); +CORE_DECLARE(c_int16_t) nas_encode_authentication_failure_parameter(pkbuf_t *pkbuf, nas_authentication_failure_parameter_t *authentication_failure_parameter); +CORE_DECLARE(c_int16_t) nas_encode_eps_attach_result(pkbuf_t *pkbuf, nas_eps_attach_result_t *eps_attach_result); +CORE_DECLARE(c_int16_t) nas_encode_eps_attach_type(pkbuf_t *pkbuf, nas_eps_attach_type_t *eps_attach_type); +CORE_DECLARE(c_int16_t) nas_encode_eps_mobile_identity(pkbuf_t *pkbuf, nas_eps_mobile_identity_t *eps_mobile_identity); +CORE_DECLARE(c_int16_t) nas_encode_eps_network_feature_support(pkbuf_t *pkbuf, nas_eps_network_feature_support_t *eps_network_feature_support); +CORE_DECLARE(c_int16_t) nas_encode_esm_message_container(pkbuf_t *pkbuf, nas_esm_message_container_t *esm_message_container); +CORE_DECLARE(c_int16_t) nas_encode_gprs_timer(pkbuf_t *pkbuf, nas_gprs_timer_t *gprs_timer); +CORE_DECLARE(c_int16_t) nas_encode_gprs_timer_2(pkbuf_t *pkbuf, nas_gprs_timer_2_t *gprs_timer_2); +CORE_DECLARE(c_int16_t) nas_encode_gprs_timer_3(pkbuf_t *pkbuf, nas_gprs_timer_3_t *gprs_timer_3); +CORE_DECLARE(c_int16_t) nas_encode_imeisv_request(pkbuf_t *pkbuf, nas_imeisv_request_t *imeisv_request); +CORE_DECLARE(c_int16_t) nas_encode_authentication_parameter_autn(pkbuf_t *pkbuf, nas_authentication_parameter_autn_t *authentication_parameter_autn); +CORE_DECLARE(c_int16_t) nas_encode_ms_network_capability(pkbuf_t *pkbuf, nas_ms_network_capability_t *ms_network_capability); +CORE_DECLARE(c_int16_t) nas_encode_ms_network_feature_support(pkbuf_t *pkbuf, nas_ms_network_feature_support_t *ms_network_feature_support); +CORE_DECLARE(c_int16_t) nas_encode_key_set_identifier(pkbuf_t *pkbuf, nas_key_set_identifier_t *key_set_identifier); +CORE_DECLARE(c_int16_t) nas_encode_security_algorithms(pkbuf_t *pkbuf, nas_security_algorithms_t *security_algorithms); +CORE_DECLARE(c_int16_t) nas_encode_network_resource_identifier_container(pkbuf_t *pkbuf, nas_network_resource_identifier_container_t *network_resource_identifier_container); CORE_DECLARE(c_int16_t) nas_encode_nonce(pkbuf_t *pkbuf, nas_nonce_t *nonce); - -/* 9.9.3.26 P-TMSI signature - * See subclause 10.5.5.8 in 3GPP TS 24.008 - * O TV 4 */ -typedef c_uint32_t nas_p_tmsi_signature_t; /* TV : 4bytes */ - -CORE_DECLARE(c_int16_t) nas_decode_p_tmsi_signature( - nas_p_tmsi_signature_t *p_tmsi_signature, pkbuf_t *pkbuf); - -/* 9.9.3.26A Extended EMM cause - * O TV 1 */ -typedef struct _nas_extended_emm_cause_t { -ED4(c_uint8_t type:4;, - c_uint8_t spare:2;, - c_uint8_t eps_optimization_info:1;, - c_uint8_t e_utran_allowed:1;) -} nas_extended_emm_cause_t; - -CORE_DECLARE(c_int16_t) nas_encode_extended_emm_cause( - pkbuf_t *pkbuf, nas_extended_emm_cause_t *extended_emm_cause); - -/* 9.9.3.31 TMSI status - * See subclause 10.5.5.4 in 3GPP TS 24.008 [13] - * O TV 1 */ -typedef struct _nas_tmsi_status_t { -ED3(c_uint8_t type:4;, - c_uint8_t spare:3;, - c_uint8_t tmsi_flag:1;) -} __attribute__ ((packed)) nas_tmsi_status_t; - -CORE_DECLARE(c_int16_t) nas_decode_tmsi_status( - nas_tmsi_status_t *tmsi_status, pkbuf_t *pkbuf); - -/* 9.9.3.32 Tracking area identity - * O TV 6 */ -typedef struct _nas_tracking_area_identity_t { - nas_plmn_t plmn; - c_uint16_t tac; -} __attribute__ ((packed)) nas_tracking_area_identity_t; - -CORE_DECLARE(c_int16_t) nas_decode_tracking_area_identity( - nas_tracking_area_identity_t *tracking_area_identity, pkbuf_t *pkbuf); - -/* 9.9.3.33 Tracking area identity list - * M LV 7-97 */ -#define NAS_MAX_TRACKING_AREA_IDENTITY 16 -#define NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS 0 -#define NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS 1 -#define NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS 2 -typedef struct _nas_tracking_area_identity_type0 { - nas_plmn_t plmn; - c_uint16_t tac[NAS_MAX_TRACKING_AREA_IDENTITY]; -} __attribute__ ((packed)) nas_tracking_area_identity_type0; - -typedef nas_tracking_area_identity_t nas_tracking_area_identity_type1; - -typedef struct _nas_tracking_area_identity_type2 { - nas_tracking_area_identity_type1 tai[NAS_MAX_TRACKING_AREA_IDENTITY]; -} __attribute__ ((packed)) nas_tracking_area_identity_type2; - -typedef struct nas_tracking_area_identity_list_t { - c_uint8_t length; -ED3(c_uint8_t spare:1;, - c_uint8_t type_of_list:2;, - c_uint8_t number_of_elements:5;) - union { - nas_tracking_area_identity_type0 type0; - nas_tracking_area_identity_type1 type1; - nas_tracking_area_identity_type2 type2; - }; -} __attribute__ ((packed)) nas_tracking_area_identity_list_t; - -CORE_DECLARE(c_int16_t) nas_encode_tracking_area_identity_list( - pkbuf_t *pkbuf, - nas_tracking_area_identity_list_t *tracking_area_identity_list); - -/* 9.9.3.34 UE network capability - * M LV 3-14 */ -typedef struct _nas_ue_network_capability_t { - c_uint8_t length; - union { - struct { - ED8(c_uint8_t eea0:1;, - c_uint8_t eea1:1;, - c_uint8_t eea2:1;, - c_uint8_t eea3:1;, - c_uint8_t eea4:1;, - c_uint8_t eea5:1;, - c_uint8_t eea6:1;, - c_uint8_t eea7:1;) - }; - c_uint8_t eea; - }; - union { - struct { - ED8(c_uint8_t eia0:1;, - c_uint8_t eia1:1;, - c_uint8_t eia2:1;, - c_uint8_t eia3:1;, - c_uint8_t eia4:1;, - c_uint8_t eia5:1;, - c_uint8_t eia6:1;, - c_uint8_t eia7:1;) - }; - c_uint8_t eia; - }; - union { - struct { - ED8(c_uint8_t uea0:1;, - c_uint8_t uea1:1;, - c_uint8_t uea2:1;, - c_uint8_t uea3:1;, - c_uint8_t uea4:1;, - c_uint8_t uea5:1;, - c_uint8_t uea6:1;, - c_uint8_t uea7:1;) - }; - c_uint8_t uea; - }; - union { - struct { - ED8(c_uint8_t ucs2:1;, - c_uint8_t uia1:1;, - c_uint8_t uia2:1;, - c_uint8_t uia3:1;, - c_uint8_t uia4:1;, - c_uint8_t uia5:1;, - c_uint8_t uia6:1;, - c_uint8_t uia7:1;) - }; - c_uint8_t uia; - }; -ED8(c_uint8_t prose_dd:1;, - c_uint8_t prose:1;, - c_uint8_t h_245_ash:1;, - c_uint8_t acc_csfb:1;, - c_uint8_t lpp:1;, - c_uint8_t lcs:1;, - c_uint8_t srvcc:1;, - c_uint8_t nf:1;) -ED8(c_uint8_t epco:1;, - c_uint8_t hc_cp_ciot:1;, - c_uint8_t erw_opdn:1;, - c_uint8_t s1u_data:1;, - c_uint8_t up_ciot:1;, - c_uint8_t cp_ciot:1;, - c_uint8_t prose_relay:1;, - c_uint8_t prose_dc:1;) -ED2(c_uint8_t spare:7;, - c_uint8_t multiple_drb:1;) -} __attribute__ ((packed)) nas_ue_network_capability_t; - -CORE_DECLARE(c_int16_t) nas_decode_ue_network_capability( - nas_ue_network_capability_t *ue_network_capability, pkbuf_t *pkbuf); - -/* 9.9.3.36 UE security capability - * M LV 3-6 */ -typedef struct _nas_ue_security_capability_t { - c_uint8_t length; - union { - struct { - ED8(c_uint8_t eea0:1;, - c_uint8_t eea1:1;, - c_uint8_t eea2:1;, - c_uint8_t eea3:1;, - c_uint8_t eea4:1;, - c_uint8_t eea5:1;, - c_uint8_t eea6:1;, - c_uint8_t eea7:1;) - }; - c_uint8_t eea; - }; - union { - struct { - ED8(c_uint8_t eia0:1;, - c_uint8_t eia1:1;, - c_uint8_t eia2:1;, - c_uint8_t eia3:1;, - c_uint8_t eia4:1;, - c_uint8_t eia5:1;, - c_uint8_t eia6:1;, - c_uint8_t eia7:1;) - }; - c_uint8_t eia; - }; - union { - struct { - ED8(c_uint8_t uea0:1;, - c_uint8_t uea1:1;, - c_uint8_t uea2:1;, - c_uint8_t uea3:1;, - c_uint8_t uea4:1;, - c_uint8_t uea5:1;, - c_uint8_t uea6:1;, - c_uint8_t uea7:1;) - }; - c_uint8_t uea; - }; - union { - struct { - ED8(c_uint8_t spare1:1;, - c_uint8_t uia1:1;, - c_uint8_t uia2:1;, - c_uint8_t uia3:1;, - c_uint8_t uia4:1;, - c_uint8_t uia5:1;, - c_uint8_t uia6:1;, - c_uint8_t uia7:1;) - }; - c_uint8_t uia; - }; - union { - struct { - ED8(c_uint8_t spare2:1;, - c_uint8_t gea1:1;, - c_uint8_t gea2:1;, - c_uint8_t gea3:1;, - c_uint8_t gea4:1;, - c_uint8_t gea5:1;, - c_uint8_t gea6:1;, - c_uint8_t gea7:1;) - }; - c_uint8_t gea; - }; -} __attribute__ ((packed)) nas_ue_security_capability_t; - -CORE_DECLARE(c_int16_t) nas_encode_ue_security_capability( - pkbuf_t *pkbuf, nas_ue_security_capability_t *ue_security_capability); - -/* TODO : 9.9.3.37 Emergency number list - * See subclause 10.5.3.13 in 3GPP TS 24.008 [13]. - * O TLV 5-50 */ -typedef struct _nas_emergency_number_list_t { - c_uint16_t length; - c_uint8_t todo[50]; -} __attribute__ ((packed)) nas_emergency_number_list_t; - -CORE_DECLARE(c_int16_t) nas_encode_emergency_number_list( - pkbuf_t *pkbuf, nas_emergency_number_list_t *emergency_number_list); - -/* 9.9.3.44 Voice domain preference and UE's usage setting - * See subclause 10.5.5.28 in 3GPP TS 24.008 [13]. - * O TLV 3 */ -typedef struct _nas_voice_domain_preference_and_ue_usage_setting_t { - c_uint8_t length; -ED3(c_uint8_t spare:5;, - c_uint8_t ue_usage_setting:1;, - c_uint8_t voice_domain_preference_for_e_utran:2;) -} __attribute__ ((packed)) nas_voice_domain_preference_and_ue_usage_setting_t; - -CORE_DECLARE(c_int16_t) nas_decode_voice_domain_preference_and_ue_usage_setting( - nas_voice_domain_preference_and_ue_usage_setting_t * - voice_domain_preference_and_ue_usage_setting, - pkbuf_t *pkbuf); - -/* 9.9.3.45 GUTI type - * O TV 1 */ -typedef struct _nas_guti_type_t { -ED3(c_uint8_t type:4;, - c_uint8_t spare:3;, - c_uint8_t guti_type:1;) -} __attribute__ ((packed)) nas_guti_type_t; - -CORE_DECLARE(c_int16_t) nas_decode_guti_type( - nas_guti_type_t *guti_type, pkbuf_t *pkbuf); - -/* 9.9.3.46 Extended DRX parameters - * See subclause 10.5.5.32 in 3GPP TS 24.008 [13]. - * O TLV 3 */ -typedef struct _nas_extended_drx_parameters_t { - c_uint8_t length; -ED2(c_uint8_t paging_time_window:4;, - c_uint8_t e_drx_value:4;) -} __attribute__ ((packed)) nas_extended_drx_parameters_t; - -CORE_DECLARE(c_int16_t) nas_decode_extended_drx_parameters( - nas_extended_drx_parameters_t *extended_drx_parameters, pkbuf_t *pkbuf); -CORE_DECLARE(c_int16_t) nas_encode_extended_drx_parameters( - pkbuf_t *pkbuf, nas_extended_drx_parameters_t *extended_drx_parameters); +CORE_DECLARE(c_int16_t) nas_encode_p_tmsi_signature(pkbuf_t *pkbuf, nas_p_tmsi_signature_t *p_tmsi_signature); +CORE_DECLARE(c_int16_t) nas_encode_extended_emm_cause(pkbuf_t *pkbuf, nas_extended_emm_cause_t *extended_emm_cause); +CORE_DECLARE(c_int16_t) nas_encode_authentication_parameter_rand(pkbuf_t *pkbuf, nas_authentication_parameter_rand_t *authentication_parameter_rand); +CORE_DECLARE(c_int16_t) nas_encode_tmsi_status(pkbuf_t *pkbuf, nas_tmsi_status_t *tmsi_status); +CORE_DECLARE(c_int16_t) nas_encode_tracking_area_identity(pkbuf_t *pkbuf, nas_tracking_area_identity_t *tracking_area_identity); +CORE_DECLARE(c_int16_t) nas_encode_tracking_area_identity_list(pkbuf_t *pkbuf, nas_tracking_area_identity_list_t *tracking_area_identity_list); +CORE_DECLARE(c_int16_t) nas_encode_ue_network_capability(pkbuf_t *pkbuf, nas_ue_network_capability_t *ue_network_capability); +CORE_DECLARE(c_int16_t) nas_encode_ue_security_capability(pkbuf_t *pkbuf, nas_ue_security_capability_t *ue_security_capability); +CORE_DECLARE(c_int16_t) nas_encode_emergency_number_list(pkbuf_t *pkbuf, nas_emergency_number_list_t *emergency_number_list); +CORE_DECLARE(c_int16_t) nas_encode_authentication_response_parameter(pkbuf_t *pkbuf, nas_authentication_response_parameter_t *authentication_response_parameter); +CORE_DECLARE(c_int16_t) nas_encode_voice_domain_preference_and_ue_usage_setting(pkbuf_t *pkbuf, nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting); +CORE_DECLARE(c_int16_t) nas_encode_guti_type(pkbuf_t *pkbuf, nas_guti_type_t *guti_type); +CORE_DECLARE(c_int16_t) nas_encode_extended_drx_parameters(pkbuf_t *pkbuf, nas_extended_drx_parameters_t *extended_drx_parameters); +CORE_DECLARE(c_int16_t) nas_encode_drx_parameter(pkbuf_t *pkbuf, nas_drx_parameter_t *drx_parameter); +CORE_DECLARE(c_int16_t) nas_encode_emm_cause(pkbuf_t *pkbuf, nas_emm_cause_t *emm_cause); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif +#endif /* __NAS_IES_H__ */ diff --git a/lib/nas/nas_message.h b/lib/nas/nas_message.h index e9a24ee32..db6aa7471 100644 --- a/lib/nas/nas_message.h +++ b/lib/nas/nas_message.h @@ -1,5 +1,37 @@ -#ifndef _NAS_MESSAGE_H__ -#define _NAS_MESSAGE_H__ +/* + * Copyright (c) 2017, CellWire Group + * 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. + */ + +/******************************************************************************* + * 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-03-21 13:49:52.081225 by acetcom + * from 24301-d80.docx + ******************************************************************************/ + +#ifndef __NAS_MESSAGE_H__ +#define __NAS_MESSAGE_H__ #include "3gpp_message.h" #include "nas_ies.h" @@ -36,63 +68,136 @@ ED2(c_uint8_t security_header_type:4;, c_uint8_t sequence_number; } __attribute__ ((packed)) nas_security_header_t; -#define NAS_ATTACH_REQUEST 65 -#define NAS_ATTACH_ACCEPT 66 -#define NAS_ATTACH_COMPLETE 67 -#define NAS_ATTACH_REJECT 68 -#define NAS_DETACH_REQUEST 69 -#define NAS_DETACH_ACCEPT 70 -#define NAS_TRACKING_AREA_UPDATE_REQUEST 72 -#define NAS_TRACKING_AREA_UPDATE_ACCEPT 73 -#define NAS_TRACKING_AREA_UPDATE_COMPLETE 74 -#define NAS_TRACKING_AREA_UPDATE_REJECT 75 -#define NAS_EXTENDED_SERVICE_REQUEST 76 -#define NAS_SERVICE_REJECT 78 -#define NAS_GUTI_REALLOCATION_COMMAND 80 -#define NAS_GUTI_REALLOCATION_COMPLETE 81 -#define NAS_AUTHENTICATION_REQUEST 82 -#define NAS_AUTHENTICATION_RESPONSE 83 -#define NAS_AUTHENTICATION_REJECT 84 -#define NAS_AUTHENTICATION_FAILURE 92 -#define NAS_IDENTITY_REQUEST 85 -#define NAS_IDENTITY_RESPONSE 86 -#define NAS_SECURITY_MODE_COMMAND 93 -#define NAS_SECURITY_MODE_COMPLETE 94 -#define NAS_SECURITY_MODE_REJECT 95 -#define NAS_EMM_STATUS 96 -#define NAS_EMM_INFORMATION 97 -#define NAS_DOWNLINK_NAS_TRANSPORT 98 -#define NAS_UPLINK_NAS_TRANSPORT 99 -#define NAS_CS_SERVICE_NOTIFICATION 100 -#define NAS_DOWNLINK_GENERIC_NAS_TRANSPORT 104 -#define NAS_UPLINK_GENERIC_NAS_TRANSPORT 101 +#define NAS_ATTACH_REQUEST 65 +#define NAS_ATTACH_ACCEPT 66 +#define NAS_ATTACH_COMPLETE 67 +#define NAS_ATTACH_REJECT 68 +#define NAS_DETACH_REQUEST 69 +#define NAS_DETACH_ACCEPT 70 +#define NAS_TRACKING_AREA_UPDATE_REQUEST 72 +#define NAS_TRACKING_AREA_UPDATE_ACCEPT 73 +#define NAS_TRACKING_AREA_UPDATE_COMPLETE 74 +#define NAS_TRACKING_AREA_UPDATE_REJECT 75 +#define NAS_EXTENDED_SERVICE_REQUEST 76 +#define NAS_SERVICE_REJECT 78 +#define NAS_GUTI_REALLOCATION_COMMAND 80 +#define NAS_GUTI_REALLOCATION_COMPLETE 81 +#define NAS_AUTHENTICATION_REQUEST 82 +#define NAS_AUTHENTICATION_RESPONSE 83 +#define NAS_AUTHENTICATION_REJECT 84 +#define NAS_IDENTITY_REQUEST 85 +#define NAS_IDENTITY_RESPONSE 86 +#define NAS_AUTHENTICATION_FAILURE 92 +#define NAS_SECURITY_MODE_COMMAND 93 +#define NAS_SECURITY_MODE_COMPLETE 94 +#define NAS_SECURITY_MODE_REJECT 95 +#define NAS_EMM_STATUS 96 +#define NAS_EMM_INFORMATION 97 +#define NAS_DOWNLINK_NAS_TRANSPORT 98 +#define NAS_UPLINK_NAS_TRANSPORT 99 +#define NAS_CS_SERVICE_NOTIFICATION 100 +#define NAS_UPLINK_GENERIC_NAS_TRANSPORT 101 +#define NAS_DOWNLINK_GENERIC_NAS_TRANSPORT 104 +#define NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST 193 +#define NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT 194 +#define NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT 195 +#define NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST 197 +#define NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT 198 +#define NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT 199 +#define NAS_MODIFY_EPS_BEARER_CONTEXT_REQUEST 201 +#define NAS_MODIFY_EPS_BEARER_CONTEXT_ACCEPT 202 +#define NAS_MODIFY_EPS_BEARER_CONTEXT_REJECT 203 +#define NAS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST 205 +#define NAS_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT 206 +#define NAS_PDN_CONNECTIVITY_REQUEST 208 +#define NAS_PDN_CONNECTIVITY_REJECT 209 +#define NAS_PDN_DISCONNECT_REQUEST 210 +#define NAS_PDN_DISCONNECT_REJECT 211 +#define NAS_BEARER_RESOURCE_ALLOCATION_REQUEST 212 +#define NAS_BEARER_RESOURCE_ALLOCATION_REJECT 213 +#define NAS_BEARER_RESOURCE_MODIFICATION_REQUEST 214 +#define NAS_BEARER_RESOURCE_MODIFICATION_REJECT 215 +#define NAS_ESM_INFORMATION_REQUEST 217 +#define NAS_ESM_INFORMATION_RESPONSE 218 +#define NAS_ESM_STATUS 232 -#define NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST 193 -#define NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT 194 -#define NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT 195 -#define NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST 197 -#define NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT 198 -#define NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT 199 -#define NAS_MODIFY_EPS_BEARER_CONTEXT_REQUEST 201 -#define NAS_MODIFY_EPS_BEARER_CONTEXT_ACCEPT 202 -#define NAS_MODIFY_EPS_BEARER_CONTEXT_REJECT 203 -#define NAS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST 205 -#define NAS_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT 206 -#define NAS_PDN_CONNECTIVITY_REQUEST 208 -#define NAS_PDN_CONNECTIVITY_REJECT 209 -#define NAS_PDN_DISCONNECT_REQUEST 210 -#define NAS_PDN_DISCONNECT_REJECT 211 -#define NAS_BEARER_RESOURCE_ALLOCATION_REQUEST 212 -#define NAS_BEARER_RESOURCE_ALLOCATION_REJECT 213 -#define NAS_BEARER_RESOURCE_MODIFICATION_REQUEST 214 -#define NAS_BEARER_RESOURCE_MODIFICATION_REJECT 215 -#define NAS_ESM_INFORMATION_REQUEST 217 -#define NAS_ESM_INFORMATION_RESPONSE 218 -#define NAS_ESM_STATUS 232 -/************************ - * 8.2.1 Attach accept - ************************/ +/******************************************************* + * ATTACH REQUEST + ******************************************************/ +#define NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_PRESENT (1<<0) +#define NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_PRESENT (1<<1) +#define NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT (1<<2) +#define NAS_ATTACH_REQUEST_DRX_PARAMETER_PRESENT (1<<3) +#define NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_PRESENT (1<<4) +#define NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT (1<<5) +#define NAS_ATTACH_REQUEST_TMSI_STATUS_PRESENT (1<<6) +#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT (1<<7) +#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT (1<<8) +#define NAS_ATTACH_REQUEST_SUPPORTED_CODECS_PRESENT (1<<9) +#define NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT (1<<10) +#define NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT (1<<11) +#define NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_PRESENT (1<<12) +#define NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT (1<<13) +#define NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT (1<<14) +#define NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT (1<<15) +#define NAS_ATTACH_REQUEST_T3324_VALUE_PRESENT (1<<16) +#define NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_PRESENT (1<<17) +#define NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_PRESENT (1<<18) +#define NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_TYPE 0x19 +#define NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_TYPE 0x50 +#define NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_TYPE 0x52 +#define NAS_ATTACH_REQUEST_DRX_PARAMETER_TYPE 0x5C +#define NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_TYPE 0x31 +#define NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_TYPE 0x13 +#define NAS_ATTACH_REQUEST_TMSI_STATUS_TYPE 0x90 +#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_TYPE 0x11 +#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_TYPE 0x20 +#define NAS_ATTACH_REQUEST_SUPPORTED_CODECS_TYPE 0x40 +#define NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE 0xF0 +#define NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_TYPE 0x5D +#define NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_TYPE 0xD0 +#define NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_TYPE 0xE0 +#define NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE 0xC0 +#define NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_TYPE 0x10 +#define NAS_ATTACH_REQUEST_T3324_VALUE_TYPE 0x6A +#define NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_TYPE 0x5E +#define NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_TYPE 0x6E + +typedef struct _nas_attach_request_t { + /* Mandatory fields */ + nas_eps_attach_type_t eps_attach_type; + nas_eps_mobile_identity_t eps_mobile_identity; + nas_ue_network_capability_t ue_network_capability; + nas_esm_message_container_t esm_message_container; + + /* Optional fields */ + c_uint32_t presencemask; + nas_p_tmsi_signature_t old_p_tmsi_signature; + nas_eps_mobile_identity_t additional_guti; + nas_tracking_area_identity_t last_visited_registered_tai; + nas_drx_parameter_t drx_parameter; + nas_ms_network_capability_t ms_network_capability; + nas_location_area_identification_t old_location_area_identification; + nas_tmsi_status_t tmsi_status; + nas_mobile_station_classmark_2_t mobile_station_classmark_2; + nas_mobile_station_classmark_3_t mobile_station_classmark_3; + nas_supported_codec_list_t supported_codecs; + nas_additional_update_type_t additional_update_type; + nas_voice_domain_preference_and_ue_usage_setting_t voice_domain_preference_and_ue_usage_setting; + nas_device_properties_t device_properties; + nas_guti_type_t old_guti_type; + nas_ms_network_feature_support_t ms_network_feature_support; + nas_network_resource_identifier_container_t tmsi_based_nri_container; + nas_gprs_timer_2_t t3324_value; + nas_gprs_timer_3_t t3412_extended_value; + nas_extended_drx_parameters_t extended_drx_parameters; +} nas_attach_request_t; + + +/******************************************************* + * ATTACH ACCEPT + ******************************************************/ #define NAS_ATTACH_ACCEPT_GUTI_PRESENT (1<<0) #define NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_PRESENT (1<<1) #define NAS_ATTACH_ACCEPT_MS_IDENTITY_PRESENT (1<<2) @@ -106,7 +211,6 @@ ED2(c_uint8_t security_header_type:4;, #define NAS_ATTACH_ACCEPT_T3412_EXTENDED_VALUE_PRESENT (1<<10) #define NAS_ATTACH_ACCEPT_T3324_VALUE_PRESENT (1<<11) #define NAS_ATTACH_ACCEPT_EXTENDED_DRX_PARAMETERS_PRESENT (1<<12) - #define NAS_ATTACH_ACCEPT_GUTI_TYPE 0x50 #define NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_TYPE 0x13 #define NAS_ATTACH_ACCEPT_MS_IDENTITY_TYPE 0x23 @@ -137,8 +241,7 @@ typedef struct _nas_attach_accept_t { nas_gprs_timer_t t3402_value; nas_gprs_timer_t t3423_value; nas_plmn_list_t equivalent_plmns; - - nas_emergency_number_list_t emergency_number_list; + nas_emergency_number_list_t emergency_number_list; nas_eps_network_feature_support_t eps_network_feature_support; nas_additional_update_result_t additional_update_result; nas_gprs_timer_3_t t3412_extended_value; @@ -146,117 +249,67 @@ typedef struct _nas_attach_accept_t { nas_extended_drx_parameters_t extended_drx_parameters; } nas_attach_accept_t; -/************************ - * 8.2.2 Attach complete - ************************/ -typedef struct _nas_attach_complete { + +/******************************************************* + * ATTACH COMPLETE + ******************************************************/ + +typedef struct _nas_attach_complete_t { /* Mandatory fields */ nas_esm_message_container_t esm_message_container; - } nas_attach_complete_t; -/************************ - * 8.2.3 Attach rejct - ************************/ -#define NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT (1 << 0) -#define NAS_ATTACH_REJECT_T3346_VALUE_PRESENT (1 << 1) -#define NAS_ATTACH_REJECT_T3402_VALUE_PRESENT (1 << 2) -#define NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_PRESENT (1 << 3) +/******************************************************* + * ATTACH REJECT + ******************************************************/ +#define NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT (1<<0) +#define NAS_ATTACH_REJECT_T3346_VALUE_PRESENT (1<<1) +#define NAS_ATTACH_REJECT_T3402_VALUE_PRESENT (1<<2) +#define NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_PRESENT (1<<3) #define NAS_ATTACH_REJECT_ESM_MESSAGE_CONTAINER_TYPE 0x78 #define NAS_ATTACH_REJECT_T3346_VALUE_TYPE 0x5F #define NAS_ATTACH_REJECT_T3402_VALUE_TYPE 0x16 #define NAS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_TYPE 0xA0 -typedef struct _nas_attach_reject { + +typedef struct _nas_attach_reject_t { /* Mandatory fields */ nas_emm_cause_t emm_cause; - + /* Optional fields */ c_uint32_t presencemask; nas_esm_message_container_t esm_message_container; nas_gprs_timer_2_t t3346_value; nas_gprs_timer_2_t t3402_value; nas_extended_emm_cause_t extended_emm_cause; - } nas_attach_reject_t; -/************************ - * 8.2.4 Attach request - ************************/ -#define NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_PRESENT (1<<0) -#define NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_PRESENT (1<<1) -#define NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT (1<<2) -#define NAS_ATTACH_REQUEST_DRX_PARAMETER_PRESENT (1<<3) -#define NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_PRESENT (1<<4) -#define NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT (1<<5) -#define NAS_ATTACH_REQUEST_TMSI_STATUS_PRESENT (1<<6) -#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT (1<<7) -#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT (1<<8) -#define NAS_ATTACH_REQUEST_SUPPORTED_CODECS_PRESENT (1<<9) -#define NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT (1<<10) -#define NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT (1<<11) -#define NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_PRESENT (1<<12) -#define NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT (1<<13) -#define NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT (1<<14) -#define NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT (1<<15) -#define NAS_ATTACH_REQUEST_T3324_VALUE_PRESENT (1<<16) -#define NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_PRESENT (1<<17) -#define NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_PRESENT (1<<18) -#define NAS_ATTACH_REQUEST_OLD_P_TMSI_SIGNATURE_TYPE 0x19 -#define NAS_ATTACH_REQUEST_ADDITIONAL_GUTI_TYPE 0x50 -#define NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_TYPE 0x52 -#define NAS_ATTACH_REQUEST_DRX_PARAMETER_TYPE 0x5C -#define NAS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_TYPE 0x31 -#define NAS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_TYPE 0x13 -#define NAS_ATTACH_REQUEST_TMSI_STATUS_TYPE 0x90 -#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_TYPE 0x11 -#define NAS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_TYPE 0x20 -#define NAS_ATTACH_REQUEST_SUPPORTED_CODECS_TYPE 0x40 -#define NAS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE 0xF0 -#define NAS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_TYPE 0x5D -#define NAS_ATTACH_REQUEST_DEVICE_PROPERTIES_TYPE 0xD0 -#define NAS_ATTACH_REQUEST_OLD_GUTI_TYPE_TYPE 0xE0 -#define NAS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE 0xC0 -#define NAS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_TYPE 0x10 -#define NAS_ATTACH_REQUEST_T3324_VALUE_TYPE 0x6A -#define NAS_ATTACH_REQUEST_T3412_EXTENDED_VALUE_TYPE 0x5E -#define NAS_ATTACH_REQUEST_EXTENDED_DRX_PARAMETERS_TYPE 0x6E +/******************************************************* + * AUTHENTICATION REQUEST + ******************************************************/ -typedef struct _nas_attach_request_t { +typedef struct _nas_authentication_request_t { /* Mandatory fields */ - nas_eps_attach_type_t eps_attach_type; - nas_eps_mobile_identity_t eps_mobile_identity; - nas_ue_network_capability_t ue_network_capability; - nas_esm_message_container_t esm_message_container; + nas_key_set_identifier_t nas_key_set_identifierasme; + nas_authentication_parameter_rand_t authentication_parameter_rand; + nas_authentication_parameter_autn_t authentication_parameter_autn; +} nas_authentication_request_t; - /* Optional fields */ - c_uint32_t presencemask; - nas_p_tmsi_signature_t old_p_tmsi_signature; - nas_eps_mobile_identity_t additional_guti; - nas_tracking_area_identity_t last_visited_registered_tai; - nas_drx_parameter_t drx_parameter; - nas_ms_network_capability_t ms_network_capability; - nas_location_area_identification_t old_location_area_identification; - nas_tmsi_status_t tmsi_status; - nas_mobile_station_classmark_2_t mobile_station_classmark_2; - nas_mobile_station_classmark_3_t mobile_station_classmark_3; - nas_supported_codec_list_t supported_codecs; - nas_additional_update_type_t additional_update_type; - nas_voice_domain_preference_and_ue_usage_setting_t - voice_domain_preference_and_ue_usage_setting; - nas_device_properties_t device_properties; - nas_guti_type_t old_guti_type; - nas_ms_network_feature_support_t ms_network_feature_support; - nas_network_resource_identifier_container_t tmsi_based_nri_container; - nas_gprs_timer_2_t t3324_value; - nas_gprs_timer_3_t t3412_extended_value; - nas_extended_drx_parameters_t extended_drx_parameters; -} nas_attach_request_t; -/****************************** - * 8.2.5 Authentication failure - ******************************/ +/******************************************************* + * AUTHENTICATION RESPONSE + ******************************************************/ + +typedef struct _nas_authentication_response_t { + /* Mandatory fields */ + nas_authentication_response_parameter_t authentication_response_parameter; +} nas_authentication_response_t; + + +/******************************************************* + * AUTHENTICATION FAILURE + ******************************************************/ #define NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT (1<<0) #define NAS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_TYPE 0x30 @@ -269,42 +322,16 @@ typedef struct _nas_authentication_failure_t { nas_authentication_failure_parameter_t authentication_failure_parameter; } nas_authentication_failure_t; -/****************************** - * 8.2.6 Authentication reject - ******************************/ -/****************************** - * 8.2.7 Authentication request - ******************************/ -typedef struct _nas_authentication_request_t { - /* Mandatory fields */ - nas_key_set_identifier_t nas_key_set_identifier; - nas_authentication_parameter_rand_t authentication_parameter_rand; - nas_authentication_parameter_autn_t authentication_parameter_autn; - - /* Optional fields */ -} nas_authentication_request_t; - -/******************************* - * 8.2.7 Authentication response - *******************************/ -typedef struct _nas_authentication_response_t { - /* Mandatory fields */ - nas_authentication_response_parameter_t authentication_response_parameter; - - /* Optional fields */ -} nas_authentication_response_t; - -/****************************** - * 8.2.20 Security mode command - ******************************/ +/******************************************************* + * SECURITY MODE COMMAND + ******************************************************/ #define NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_PRESENT (1<<0) -#define NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCE_PRESENT (1<<1) -#define NAS_SECURITY_MODE_COMMAND_NONCE_PRESENT (1<<2) - +#define NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCEUE_PRESENT (1<<1) +#define NAS_SECURITY_MODE_COMMAND_NONCEMME_PRESENT (1<<2) #define NAS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_TYPE 0xC0 -#define NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCE_TYPE 0x55 -#define NAS_SECURITY_MODE_COMMAND_NONCE_TYPE 0x56 +#define NAS_SECURITY_MODE_COMMAND_REPLAYED_NONCEUE_TYPE 0x55 +#define NAS_SECURITY_MODE_COMMAND_NONCEMME_TYPE 0x56 typedef struct _nas_security_mode_command_t { /* Mandatory fields */ @@ -315,41 +342,45 @@ typedef struct _nas_security_mode_command_t { /* Optional fields */ c_uint32_t presencemask; nas_imeisv_request_t imeisv_request; - nas_nonce_t replayed_nonce; - nas_nonce_t nonce; + nas_nonce_t replayed_nonceue; + nas_nonce_t noncemme; } nas_security_mode_command_t; -/******************************* - * 8.2.21 Security mode complete - *******************************/ + +/******************************************************* + * SECURITY MODE COMPLETE + ******************************************************/ #define NAS_SECURITY_MODE_COMPLETE_IMEISV_PRESENT (1<<0) #define NAS_SECURITY_MODE_COMPLETE_IMEISV_TYPE 0x23 + typedef struct _nas_security_mode_complete_t { + /* Optional fields */ c_uint32_t presencemask; nas_mobile_identity_t imeisv; } nas_security_mode_complete_t; -/****************************** - * 8.2.22 Security mode reject - ******************************/ + +/******************************************************* + * SECURITY MODE REJECT + ******************************************************/ + typedef struct _nas_security_mode_reject_t { /* Mandatory fields */ nas_emm_cause_t emm_cause; - - /* Optional fields */ } nas_security_mode_reject_t; + typedef struct _nas_message_t { nas_header_t h; union { + nas_attach_request_t attach_request; nas_attach_accept_t attach_accept; nas_attach_complete_t attach_complete; nas_attach_reject_t attach_reject; - nas_attach_request_t attach_request; - nas_authentication_failure_t authentication_failure; nas_authentication_request_t authentication_request; nas_authentication_response_t authentication_response; + nas_authentication_failure_t authentication_failure; nas_security_mode_command_t security_mode_command; nas_security_mode_complete_t security_mode_complete; nas_security_mode_reject_t security_mode_reject; @@ -363,5 +394,4 @@ CORE_DECLARE(int) nas_plain_encode(pkbuf_t **pkbuf, nas_message_t *message); } #endif /* __cplusplus */ -#endif - +#endif /* __NAS_MESSAGE_H__ */ diff --git a/lib/nas/nas_types.h b/lib/nas/nas_types.h new file mode 100644 index 000000000..4d47a1f38 --- /dev/null +++ b/lib/nas/nas_types.h @@ -0,0 +1,740 @@ +#ifndef _NAS_TYPES_H__ +#define _NAS_TYPES_H__ + +#include "3gpp_message.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct _nas_plmn_t { +ED2(c_uint8_t mcc_digit2:4;, + c_uint8_t mcc_digit1:4;) +ED2(c_uint8_t mnc_digit3:4;, + c_uint8_t mcc_digit3:4;) +ED2(c_uint8_t mnc_digit2:4;, + c_uint8_t mnc_digit1:4;) +} __attribute__ ((packed)) nas_plmn_t; + +/* 9.9.2.0A Device properties + * See subclause 10.5.7.8 in 3GPP TS 24.008 [13]. + * O TV 1 */ +typedef struct _nas_device_properties_t { +ED3(c_uint8_t type:4;, + c_uint8_t spare:3;, + c_uint8_t low_priority:1;) +} __attribute__ ((packed)) nas_device_properties_t; + +/* 9.9.2.2 Location area identification + * See subclause 10.5.1.3 in 3GPP TS 24.008 [13] + * O TV 6 */ +typedef struct _nas_location_area_identification_t { + nas_plmn_t plmn; + c_uint16_t lac; +} __attribute__ ((packed)) nas_location_area_identification_t; + +/* 9.9.2.3 Mobile identity + * See subclause 10.5.1.4 in 3GPP TS 24.008 [13]. + * O TLV 7-10 */ +#define NAS_MOBILE_IDENTITY_NONE 0 +#define NAS_MOBILE_IDENTITY_IMSI 1 +#define NAS_MOBILE_IDENTITY_IMEI 2 +#define NAS_MOBILE_IDENTITY_IMEISV 3 +#define NAS_MOBILE_IDENTITY_TMSI 4 +#define NAS_MOBILE_IDENTITY_TMGI 5 +#define NAS_MOBILE_IDENTITY_GUTI 6 +typedef struct _nas_mobile_identity_imsi { +ED3(c_uint8_t digit1:4;, + c_uint8_t odd_even:1;, + c_uint8_t type_of_identity:3;) +ED2(c_uint8_t digit3:4;, + c_uint8_t digit2:4;) +ED2(c_uint8_t digit5:4;, + c_uint8_t digit4:4;) +ED2(c_uint8_t digit7:4;, + c_uint8_t digit6:4;) +ED2(c_uint8_t digit9:4;, + c_uint8_t digit8:4;) +ED2(c_uint8_t digit11:4;, + c_uint8_t digit10:4;) +ED2(c_uint8_t digit13:4;, + c_uint8_t digit12:4;) +ED2(c_uint8_t digit15:4;, + c_uint8_t digit14:4;) +} __attribute__ ((packed)) nas_mobile_identity_imsi_t; + +typedef struct _nas_mobile_identity_tmsi { +ED3(c_uint8_t spare:4;, + c_uint8_t odd_even:1;, + c_uint8_t type_of_identity:3;) + c_uint32_t tmsi; +} __attribute__ ((packed)) nas_mobile_identity_tmsi_t; + +typedef struct _nas_mobile_identity_tmgi { +ED5(c_uint8_t spare:2;, + c_uint8_t mbms_session_id:1;, + c_uint8_t mcc_mnc:1;, + c_uint8_t odd_even:1;, + c_uint8_t type_of_identity:3;) + c_uint8_t mbms_servicec_id[3]; + nas_plmn_t plmn; + c_uint8_t mbms_session_identity; +} __attribute__ ((packed)) nas_mobile_identity_tmgi_t; + +typedef struct _nas_mobile_identity_t { + c_uint8_t length; + union { + nas_mobile_identity_imsi_t imsi; + nas_mobile_identity_tmsi_t tmsi; + nas_mobile_identity_tmgi_t tmgi; + }; +} nas_mobile_identity_t; + +/* 9.9.2.4 Mobile station classmark 2 + * See subclause 10.5.1.6 in 3GPP TS 24.008 + * O TLV 5 */ +#define NAS_MS_CLASSMARK_2_REVISION_GSM_PHASE1 0 +#define NAS_MS_CLASSMARK_2_REVISION_GSM_PHASE2 1 +#define NAS_MS_CLASSMARK_2_REVISION_R99 2 +#define NAS_MS_CLASSMARK_2_REVISION_RESERVED 2 + +#define NAS_MS_CLASSMARK_2_RF_CLASS1 0 +#define NAS_MS_CLASSMARK_2_RF_CLASS2 1 +#define NAS_MS_CLASSMARK_2_RF_CLASS3 2 +#define NAS_MS_CLASSMARK_2_RF_CLASS4 3 +#define NAS_MS_CLASSMARK_2_RF_CLASS5 4 +#define NAS_MS_CLASSMARK_2_RF_IRRELEVANT 7 +typedef struct nas_mobile_station_classmark_2_t { + c_uint8_t length; +ED5(c_uint8_t spare1:1;, + c_uint8_t revision_level:2;, + c_uint8_t es_ind:1;, + c_uint8_t a5_1:1;, + c_uint8_t rf_power_capability:3;) +ED7(c_uint8_t spare:1;, + c_uint8_t ps_capa:1;, + c_uint8_t ss_screen_indicator:2;, + c_uint8_t sm_capabi:1;, + c_uint8_t vbs:1;, + c_uint8_t vgcs:1;, + c_uint8_t fc:1;) +ED8(c_uint8_t cm3:1;, + c_uint8_t spare2:1;, + c_uint8_t lcsva_cap:1;, + c_uint8_t ucs2:1;, + c_uint8_t solsa:1;, + c_uint8_t cmsp:1;, + c_uint8_t a5_3:1;, + c_uint8_t a5_2:1;) +} __attribute__ ((packed)) nas_mobile_station_classmark_2_t; + +/*9.9.2.5 Mobile station classmark 3 + * See subclause 10.5.1.7 in 3GPP TS 24.008 [13]. + * O TLV 2-34 */ +typedef struct _nas_mobile_station_classmark_3_t { + c_uint8_t length; + c_uint8_t todo[34]; +} __attribute__ ((packed)) nas_mobile_station_classmark_3_t; + +/* 9.9.2.8 PLMN list + * See subclause 10.5.1.13 in 3GPP TS 24.008 [13]. + * O TLV 5-47 */ +#define NAS_MAX_PLMN 15 +typedef struct _nas_plmn_list_t { + c_uint8_t length; + nas_plmn_t plmn[NAS_MAX_PLMN]; +} __attribute__ ((packed)) nas_plmn_list_t; + +/* 9.9.2.10 Supported codec list + * See subclause 10.5.4.32 in 3GPP TS 24.008 [13]. + * O TLV 5-n */ +typedef struct _nas_supported_codec_item_t { + c_uint8_t system_identification; + c_uint8_t length_of_bitmap; + c_uint16_t codec_bitmap; +} __attribute__ ((packed)) nas_supported_codec_item_t; + +#define NAS_MAX_SUPPORTED_CODECS 8 +typedef struct _nas_supported_codec_list_t { + c_uint8_t length; + nas_supported_codec_item_t item[NAS_MAX_SUPPORTED_CODECS]; +} __attribute__ ((packed)) nas_supported_codec_list_t; + +/* 9.9.3.0A Additional update result + * O TV 1 */ +typedef struct _nas_additional_update_result_t { +ED3(c_uint8_t type:4;, + c_uint8_t spare:2;, + c_uint8_t additional_update_result_value:2;) +} __attribute__ ((packed)) nas_additional_update_result_t; + +/* 9.9.3.0B Additional update type + * O TV 1 */ +#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_NONE 0 +#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_CONTROL_PLANE 1 +#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_DATA_PLANE 2 +#define NAS_ADDITIONAL_UPDATE_TYPE_CIOT_RESERVED 3 +typedef struct _nas_additional_update_type_t { +ED4(c_uint8_t type:4;, + c_uint8_t pnb_ciot:2;, + c_uint8_t saf:1;, + c_uint8_t autv:1;) +} __attribute__ ((packed)) nas_additional_update_type_t; + +/* 9.9.3.1 Authentication failure parameter + * See subclause 10.5.3.2.2 in 3GPP TS 24.008 [13]. + * O TLV 16 */ +typedef struct _nas_authentication_failure_parameter_t { + c_uint8_t length; + c_uint8_t parameter[14]; +} __attribute__ ((packed)) nas_authentication_failure_parameter_t; + +/* 9.9.3.2 Authentication parameter AUTN + * See subclause 10.5.3.1.1 in 3GPP TS 24.008 [13]. + * M LV 17 */ +typedef struct _nas_authentication_parameter_autn_t { + c_uint8_t length; + c_uint8_t autn[MAX_AUTN_LEN]; +} nas_authentication_parameter_autn_t; + +/* 9.9.3.3 Authentication parameter RAND + * See subclause 10.5.3.1 in 3GPP TS 24.008 [13]. + * M V 16 */ +typedef struct _nas_authentication_parameter_rand_t { + c_uint8_t rand[MAX_RAND_LEN]; +} nas_authentication_parameter_rand_t; + +/* 9.9.3.4 Authentication response parameter + * M LV 5-17 */ +typedef struct _nas_authentication_response_parameter_t { + c_uint8_t length; + c_uint8_t res[MAX_RES_LEN]; +} nas_authentication_response_parameter_t; + +/* 9.9.3.8 DRX parameter + * See subclause 10.5.5.6 in 3GPP TS 24.008 + * O TV 3 */ +#define NAS_DRX_PARAMETER_TIMER_MAX_1SEC 1 +#define NAS_DRX_PARAMETER_TIMER_MAX_2SEC 2 +#define NAS_DRX_PARAMETER_TIMER_MAX_4SEC 3 +#define NAS_DRX_PARAMETER_TIMER_MAX_8SEC 4 +#define NAS_DRX_PARAMETER_TIMER_MAX_16SEC 5 +#define NAS_DRX_PARAMETER_TIMER_MAX_32SEC 6 +#define NAS_DRX_PARAMETER_TIMER_MAX_64SEC 7 + +#define NAS_DRX_PARAMETER_COEFFICIENT_T_NOT_SPECIFIED_BY_MS 0 +#define NAS_DRX_PARAMETER_COEFFICIENT_6_T_32 6 +#define NAS_DRX_PARAMETER_COEFFICIENT_7_T_64 7 +#define NAS_DRX_PARAMETER_COEFFICIENT_8_T_128 8 +#define NAS_DRX_PARAMETER_COEFFICIENT_9_T_256 9 +typedef struct _nas_drx_parameter_t { + c_uint8_t split_pg_cycle_code; +ED3(c_uint8_t cn_specific_drx_cycle_length_coefficient_and_drx_value_for_s1_mode:4;, + c_uint8_t split_on_ccch:1;, + c_uint8_t non_DRX_timer:3;) +} __attribute__ ((packed)) nas_drx_parameter_t; + +/* 9.9.3.9 EMM cause + * O TV 2 */ +#define NAS_EMM_CAUSE_IMSI_UNKNOWN_IN_HSS 0b00000010 +#define NAS_EMM_CAUSE_ILLEGAL_UE 0b00000011 +#define NAS_EMM_CAUSE_IMEI_NOT_ACCEPTED 0b00000101 +#define NAS_EMM_CAUSE_ILLEGAL_ME 0b00000110 +#define NAS_EMM_CAUSE_EPS_SERVICES_NOT_ALLOWED 0b00000111 +#define NAS_EMM_CAUSE_EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED 0b00001000 +#define NAS_EMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK 0b00001001 +#define NAS_EMM_CAUSE_IMPLICITLY_DETACHED 0b00001010 +#define NAS_EMM_CAUSE_PLMN_NOT_ALLOWED 0b00001011 +#define NAS_EMM_CAUSE_TRACKING_AREA_NOT_ALLOWED 0b00001100 +#define NAS_EMM_CAUSE_ROAMING_NOT_ALLOWED_IN_THIS_TRACKING_AREA 0b00001101 +#define NAS_EMM_CAUSE_EPS_SERVICES_NOT_ALLOWED_IN_THIS_PLMN 0b00001110 +#define NAS_EMM_CAUSE_NO_SUITABLE_CELLS_IN_TRACKING_AREA 0b00001111 +#define NAS_EMM_CAUSE_MSC_TEMPORARILY_NOT_REACHABLE 0b00010000 +#define NAS_EMM_CAUSE_NETWORK_FAILURE 0b00010001 +#define NAS_EMM_CAUSE_CS_DOMAIN_NOT_AVAILABLE 0b00010010 +#define NAS_EMM_CAUSE_ESM_FAILURE 0b00010011 +#define NAS_EMM_CAUSE_MAC_FAILURE 0b00010100 +#define NAS_EMM_CAUSE_SYNCH_FAILURE 0b00010101 +#define NAS_EMM_CAUSE_CONGESTION 0b00010110 +#define NAS_EMM_CAUSE_UE_SECURITY_CAPABILITIES_MISMATCH 0b00010111 +#define NAS_EMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED 0b00011000 +#define NAS_EMM_CAUSE_NOT_AUTHORIZED_FOR_THIS_CSG 0b00011001 +#define NAS_EMM_CAUSE_NON_EPS_AUTHENTICATION_UNACCEPTABLE 0b00011010 +#define NAS_EMM_CAUSE_REQUESTED_SERVICE_OPTION_NOT_AUTHORIZED_IN_THIS_PLMN 0b00100011 +#define NAS_EMM_CAUSE_CS_SERVICE_TEMPORARILY_NOT_AVAILABLE 0b00100111 +#define NAS_EMM_CAUSE_NO_EPS_BEARER_CONTEXT_ACTIVATED 0b00101000 +#define NAS_EMM_CAUSE_SEVERE_NETWORK_FAILURE 0b00101010 +#define NAS_EMM_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE 0b01011111 +#define NAS_EMM_CAUSE_INVALID_MANDATORY_INFORMATION 0b01100000 +#define NAS_EMM_CAUSE_MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED 0b01100001 +#define NAS_EMM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_THE_PROTOCOL_STATE 0b01100010 +#define NAS_EMM_CAUSE_INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED 0b01100011 +#define NAS_EMM_CAUSE_CONDITIONAL_IE_ERROR 0b01100100 +#define NAS_EMM_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_THE_PROTOCOL_STATE 0b01100101 +#define NAS_EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED 0b01101111 +typedef c_uint8_t nas_emm_cause_t; + +/* 9.9.3.10 * EPS attach result + * M V 1/2 */ +#define NAS_ATTACH_RESULT_EPS_ONLY 1 +#define NAS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH 2 +typedef struct _nas_eps_attach_result_t { +ED2(c_uint8_t spare:5;, + c_uint8_t result:3;) +} __attribute__ ((packed)) nas_eps_attach_result_t; + +/* 9.9.3.11 EPS attach type + * M V 1/2 + * 9.9.3.21 NAS key set identifier + * M V 1/2 */ +#define NAS_KEY_SET_IDENTIFIER_NATIVE 0 +#define NAS_KEY_SET_IDENTIFIER_MAPPED 1 +#define NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE 0x111 + +#define NAS_ATTACH_TYPE_EPS_ATTACH 1 +#define NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTAACH 2 +#define NAS_ATTACH_TYPE_EPS_ERMERGENCY_ATTCH 3 +#define NAS_ATTACH_TYPE_RESERVED 4 +typedef struct _nas_eps_attach_type_t { +ED4(c_uint8_t tsc:1;, + c_uint8_t nas_key_set_identifier:3;, + c_uint8_t spare:1;, + c_uint8_t attach_type:3;) +} __attribute__ ((packed)) nas_eps_attach_type_t; + +/* 9.9.3.12 EPS mobile identity + * M LV 5-12 */ +#define NAS_EPS_MOBILE_IDENTITY_IMSI 1 +#define NAS_EPS_MOBILE_IDENTITY_GUTI 6 +#define NAS_EPS_MOBILE_IDENTITY_IMEI 3 + +#define NAS_EPS_MOBILE_IDENTITY_EVEN 0 +#define NAS_EPS_MOBILE_IDENTITY_ODD 1 +typedef struct _nas_eps_mobile_identity_guti_t { +ED3(c_uint8_t spare:4;, + c_uint8_t odd_even:1;, + c_uint8_t type_of_identity:3;) + nas_plmn_t plmn; + c_uint16_t mme_group_id; + c_uint8_t mme_code; + c_uint32_t m_tmsi; +} __attribute__ ((packed)) nas_eps_mobile_identity_guti_t; + +typedef nas_mobile_identity_imsi_t nas_eps_mobile_identity_imsi_t; +typedef nas_eps_mobile_identity_imsi_t nas_eps_mobile_identity_imei_t; + +typedef struct _nas_eps_mobile_identity_t { + c_uint8_t length; + union { + nas_eps_mobile_identity_imsi_t imsi; + nas_eps_mobile_identity_guti_t guti; + nas_eps_mobile_identity_imei_t imei; + }; +} __attribute__ ((packed)) nas_eps_mobile_identity_t; + +/* 9.9.3.12A EPS network feature support + * O TLV 3 */ +typedef struct _nas_eps_network_feature_support_t { + c_uint8_t length; +ED7(c_uint8_t cp_ciot:1;, + c_uint8_t erw_opdn:1;, + c_uint8_t esr_ps:1;, + c_uint8_t cs_lcs:2;, + c_uint8_t epc_lcs:1;, + c_uint8_t emc_bs:1;, + c_uint8_t ims_vops:1;) +ED5(c_uint8_t spare:4;, + c_uint8_t e_pco:1;, + c_uint8_t hc_cp_ciot:1;, + c_uint8_t s1_u_data:1;, + c_uint8_t up_ciot :1;) +} __attribute__ ((packed)) nas_eps_network_feature_support_t; + +/* 9.9.3.15 ESM message container + * M LV-E 5-n */ +typedef struct _nas_esm_message_container_t { + c_uint16_t length; + c_uint8_t *buffer; +} nas_esm_message_container_t; + +/* 9.9.3.16 GPRS timer + * See subclause 10.5.7.3 in 3GPP TS 24.008 [13]. + * M V 1 or O TV 2 */ +#define NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_2_SS 0 +#define NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_1_MM 1 +#define NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_DECI_HH 2 +#define NAS_GRPS_TIMER_UNIT_DEACTIVATED 7 +typedef struct _nas_gprs_timer_t { +ED2(c_uint8_t unit:3;, + c_uint8_t timer_value:5;) +} __attribute__ ((packed)) nas_gprs_timer_t; + +/* 9.9.3.16A GPRS timer 2 + * See subclause 10.5.7.4 in 3GPP TS 24.008 [13]. + * O TLV 3 */ +typedef struct _nas_gprs_timer_2_t { + c_uint8_t length; + c_uint8_t gprs_timer_2_value; +} __attribute__ ((packed)) nas_gprs_timer_2_t; + +/* 9.9.3.16B GPRS timer 3 + * See subclause 10.5.7.4a in 3GPP TS 24.008 [13]. + * O TLV 3 */ +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_10_MM 0 +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_1_HH 1 +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_10_HH 2 +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_2_SS 3 +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_30_SS 4 +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_1_MM 5 +#define NAS_GRPS_TIMER_3_UNIT_MULTIPLES_OF_320_HH 6 +#define NAS_GRPS_TIMER_3_UNIT_DEACTIVATED 7 + +typedef struct _nas_gprs_timer_3_t { + c_uint8_t length; +ED2(c_uint8_t unit:3;, + c_uint8_t timer_value:5;) +} __attribute__ ((packed)) nas_gprs_timer_3_t; + +/* 9.9.3.18 IMEISV request + * See subclause 10.5.5.10 in 3GPP TS 24.008 [13]. + * O TV 1 */ +typedef struct _nas_imeisv_request_t { +ED3(c_uint8_t type:4;, + c_uint8_t spare:1;, + c_uint8_t imeisv_request_value:3;) +} __attribute__ ((packed)) nas_imeisv_request_t; + +/* 9.9.3.20 MS network capability + * See subclause 10.5.5.12 in 3GPP TS 24.008 + * O TLV 4-10 */ +#define NAS_MS_NETWORK_CAPABILITY_GEA2 0b01000000 +#define NAS_MS_NETWORK_CAPABILITY_GEA3 0b00100000 +#define NAS_MS_NETWORK_CAPABILITY_GEA4 0b00010000 +#define NAS_MS_NETWORK_CAPABILITY_GEA5 0b00001000 +#define NAS_MS_NETWORK_CAPABILITY_GEA6 0b00000100 +#define NAS_MS_NETWORK_CAPABILITY_GEA7 0b00000010 +typedef struct _nas_ms_network_capability_t { + c_uint8_t length; +ED7(c_uint8_t gea1:1;, + c_uint8_t sm_capabilities_via_dedicated_channels:1;, + c_uint8_t sm_capabilities_via_gprs_channels:1;, + c_uint8_t ucs2:1;, + c_uint8_t ss_screening_indicator:2;, + c_uint8_t solsa_capability:1;, + c_uint8_t revision_level_indicator:1;) +ED3(c_uint8_t pfc_feature_mode:1;, + c_uint8_t extended_gea:6;, + c_uint8_t lcs_va_capability:1;) +ED8(c_uint8_t ps_inter_rat_ho_from_geran_to_utran_iu_mode_capability:1;, + c_uint8_t ps_inter_rat_ho_from_geran_to_e_utran_s1_mode_capability:1;, + c_uint8_t emm_combined_procedures_capability:1;, + c_uint8_t isr_support:1;, + c_uint8_t srvcc_to_geran_utran_capability:1;, + c_uint8_t epc_capability:1;, + c_uint8_t nf_capability:1;, + c_uint8_t geran_network_sharing_capability:1;) +ED6(c_uint8_t user_plane_integrity_protection_support:1;, + c_uint8_t gia4:1;, + c_uint8_t gia5:1;, + c_uint8_t gia6:1;, + c_uint8_t gia7:1;, + c_uint8_t spare:3;) +} __attribute__ ((packed)) nas_ms_network_capability_t; + +/* 9.9.3.20A MS network feature support + * See subclause 10.5.1.15 in 3GPP TS 24.008 [13]. + * O TV 1 */ +typedef struct _nas_ms_network_feature_support_t { +ED3(c_uint8_t type:4;, + c_uint8_t spare:3;, + c_uint8_t extended_periodic_timers:1;) +} __attribute__ ((packed)) nas_ms_network_feature_support_t; + +/* 9.9.3.21 NAS key set identifier + * M V 1/2 + * 9.9.2.9 Spare half octet + * M V 1/2 */ +typedef struct _nas_key_set_identifier_t { +ED3(c_uint8_t spare:4;, + c_uint8_t tsc:1;, + c_uint8_t nas_key_set_identifier:3;) +} __attribute__ ((packed)) nas_key_set_identifier_t; + +/* 9.9.3.23 NAS security algorithms + * M V 1 */ +#define NAS_SECURITY_ALGORITHMS_EIA0 0 +#define NAS_SECURITY_ALGORITHMS_128_EIA1 1 +#define NAS_SECURITY_ALGORITHMS_128_EIA2 2 +#define NAS_SECURITY_ALGORITHMS_128_EIA3 3 +#define NAS_SECURITY_ALGORITHMS_EEA0 0 +#define NAS_SECURITY_ALGORITHMS_128_EEA1 1 +#define NAS_SECURITY_ALGORITHMS_128_EEA2 2 +#define NAS_SECURITY_ALGORITHMS_128_EEA3 3 +typedef struct _nas_security_algorithms_t { +ED4(c_uint8_t spare1:1;, + c_uint8_t type_of_ciphering_algorithm:3;, + c_uint8_t spare2:1;, + c_uint8_t type_of_integrity_protection_algorithm:3;) +} __attribute__ ((packed)) nas_security_algorithms_t; + +/* 9.9.3.24A Network resource identifier container + * See subclause 10.5.5.31 in 3GPP TS 24.008 [13]. + * O TLV 4 */ +typedef struct _nas_network_resource_identifier_container_t { + c_uint8_t length; + c_uint8_t nri_container_value1; +ED2(c_uint8_t nri_container_value2:2;, + c_uint8_t spare:6;) +} __attribute__ ((packed)) nas_network_resource_identifier_container_t; + +/* 9.9.3.25 Nonce + * O TV 5 */ +typedef c_uint32_t nas_nonce_t; + +/* 9.9.3.26 P-TMSI signature + * See subclause 10.5.5.8 in 3GPP TS 24.008 + * O TV 4 */ +typedef c_uint32_t nas_p_tmsi_signature_t; /* TV : 4bytes */ + +/* 9.9.3.26A Extended EMM cause + * O TV 1 */ +typedef struct _nas_extended_emm_cause_t { +ED4(c_uint8_t type:4;, + c_uint8_t spare:2;, + c_uint8_t eps_optimization_info:1;, + c_uint8_t e_utran_allowed:1;) +} nas_extended_emm_cause_t; + +/* 9.9.3.31 TMSI status + * See subclause 10.5.5.4 in 3GPP TS 24.008 [13] + * O TV 1 */ +typedef struct _nas_tmsi_status_t { +ED3(c_uint8_t type:4;, + c_uint8_t spare:3;, + c_uint8_t tmsi_flag:1;) +} __attribute__ ((packed)) nas_tmsi_status_t; + +/* 9.9.3.32 Tracking area identity + * O TV 6 */ +typedef struct _nas_tracking_area_identity_t { + nas_plmn_t plmn; + c_uint16_t tac; +} __attribute__ ((packed)) nas_tracking_area_identity_t; + +/* 9.9.3.33 Tracking area identity list + * M LV 7-97 */ +#define NAS_MAX_TRACKING_AREA_IDENTITY 16 +#define NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS 0 +#define NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS 1 +#define NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS 2 +typedef struct _nas_tracking_area_identity_type0 { + nas_plmn_t plmn; + c_uint16_t tac[NAS_MAX_TRACKING_AREA_IDENTITY]; +} __attribute__ ((packed)) nas_tracking_area_identity_type0; + +typedef nas_tracking_area_identity_t nas_tracking_area_identity_type1; + +typedef struct _nas_tracking_area_identity_type2 { + nas_tracking_area_identity_type1 tai[NAS_MAX_TRACKING_AREA_IDENTITY]; +} __attribute__ ((packed)) nas_tracking_area_identity_type2; + +typedef struct nas_tracking_area_identity_list_t { + c_uint8_t length; +ED3(c_uint8_t spare:1;, + c_uint8_t type_of_list:2;, + c_uint8_t number_of_elements:5;) + union { + nas_tracking_area_identity_type0 type0; + nas_tracking_area_identity_type1 type1; + nas_tracking_area_identity_type2 type2; + }; +} __attribute__ ((packed)) nas_tracking_area_identity_list_t; + +/* 9.9.3.34 UE network capability + * M LV 3-14 */ +typedef struct _nas_ue_network_capability_t { + c_uint8_t length; + union { + struct { + ED8(c_uint8_t eea0:1;, + c_uint8_t eea1:1;, + c_uint8_t eea2:1;, + c_uint8_t eea3:1;, + c_uint8_t eea4:1;, + c_uint8_t eea5:1;, + c_uint8_t eea6:1;, + c_uint8_t eea7:1;) + }; + c_uint8_t eea; + }; + union { + struct { + ED8(c_uint8_t eia0:1;, + c_uint8_t eia1:1;, + c_uint8_t eia2:1;, + c_uint8_t eia3:1;, + c_uint8_t eia4:1;, + c_uint8_t eia5:1;, + c_uint8_t eia6:1;, + c_uint8_t eia7:1;) + }; + c_uint8_t eia; + }; + union { + struct { + ED8(c_uint8_t uea0:1;, + c_uint8_t uea1:1;, + c_uint8_t uea2:1;, + c_uint8_t uea3:1;, + c_uint8_t uea4:1;, + c_uint8_t uea5:1;, + c_uint8_t uea6:1;, + c_uint8_t uea7:1;) + }; + c_uint8_t uea; + }; + union { + struct { + ED8(c_uint8_t ucs2:1;, + c_uint8_t uia1:1;, + c_uint8_t uia2:1;, + c_uint8_t uia3:1;, + c_uint8_t uia4:1;, + c_uint8_t uia5:1;, + c_uint8_t uia6:1;, + c_uint8_t uia7:1;) + }; + c_uint8_t uia; + }; +ED8(c_uint8_t prose_dd:1;, + c_uint8_t prose:1;, + c_uint8_t h_245_ash:1;, + c_uint8_t acc_csfb:1;, + c_uint8_t lpp:1;, + c_uint8_t lcs:1;, + c_uint8_t srvcc:1;, + c_uint8_t nf:1;) +ED8(c_uint8_t epco:1;, + c_uint8_t hc_cp_ciot:1;, + c_uint8_t erw_opdn:1;, + c_uint8_t s1u_data:1;, + c_uint8_t up_ciot:1;, + c_uint8_t cp_ciot:1;, + c_uint8_t prose_relay:1;, + c_uint8_t prose_dc:1;) +ED2(c_uint8_t spare:7;, + c_uint8_t multiple_drb:1;) +} __attribute__ ((packed)) nas_ue_network_capability_t; + +/* 9.9.3.36 UE security capability + * M LV 3-6 */ +typedef struct _nas_ue_security_capability_t { + c_uint8_t length; + union { + struct { + ED8(c_uint8_t eea0:1;, + c_uint8_t eea1:1;, + c_uint8_t eea2:1;, + c_uint8_t eea3:1;, + c_uint8_t eea4:1;, + c_uint8_t eea5:1;, + c_uint8_t eea6:1;, + c_uint8_t eea7:1;) + }; + c_uint8_t eea; + }; + union { + struct { + ED8(c_uint8_t eia0:1;, + c_uint8_t eia1:1;, + c_uint8_t eia2:1;, + c_uint8_t eia3:1;, + c_uint8_t eia4:1;, + c_uint8_t eia5:1;, + c_uint8_t eia6:1;, + c_uint8_t eia7:1;) + }; + c_uint8_t eia; + }; + union { + struct { + ED8(c_uint8_t uea0:1;, + c_uint8_t uea1:1;, + c_uint8_t uea2:1;, + c_uint8_t uea3:1;, + c_uint8_t uea4:1;, + c_uint8_t uea5:1;, + c_uint8_t uea6:1;, + c_uint8_t uea7:1;) + }; + c_uint8_t uea; + }; + union { + struct { + ED8(c_uint8_t spare1:1;, + c_uint8_t uia1:1;, + c_uint8_t uia2:1;, + c_uint8_t uia3:1;, + c_uint8_t uia4:1;, + c_uint8_t uia5:1;, + c_uint8_t uia6:1;, + c_uint8_t uia7:1;) + }; + c_uint8_t uia; + }; + union { + struct { + ED8(c_uint8_t spare2:1;, + c_uint8_t gea1:1;, + c_uint8_t gea2:1;, + c_uint8_t gea3:1;, + c_uint8_t gea4:1;, + c_uint8_t gea5:1;, + c_uint8_t gea6:1;, + c_uint8_t gea7:1;) + }; + c_uint8_t gea; + }; +} __attribute__ ((packed)) nas_ue_security_capability_t; + +/* TODO : 9.9.3.37 Emergency number list + * See subclause 10.5.3.13 in 3GPP TS 24.008 [13]. + * O TLV 5-50 */ +typedef struct _nas_emergency_number_list_t { + c_uint16_t length; + c_uint8_t todo[50]; +} __attribute__ ((packed)) nas_emergency_number_list_t; + +/* 9.9.3.44 Voice domain preference and UE's usage setting + * See subclause 10.5.5.28 in 3GPP TS 24.008 [13]. + * O TLV 3 */ +typedef struct _nas_voice_domain_preference_and_ue_usage_setting_t { + c_uint8_t length; +ED3(c_uint8_t spare:5;, + c_uint8_t ue_usage_setting:1;, + c_uint8_t voice_domain_preference_for_e_utran:2;) +} __attribute__ ((packed)) nas_voice_domain_preference_and_ue_usage_setting_t; + +/* 9.9.3.45 GUTI type + * O TV 1 */ +typedef struct _nas_guti_type_t { +ED3(c_uint8_t type:4;, + c_uint8_t spare:3;, + c_uint8_t guti_type:1;) +} __attribute__ ((packed)) nas_guti_type_t; + +/* 9.9.3.46 Extended DRX parameters + * See subclause 10.5.5.32 in 3GPP TS 24.008 [13]. + * O TLV 3 */ +typedef struct _nas_extended_drx_parameters_t { + c_uint8_t length; +ED2(c_uint8_t paging_time_window:4;, + c_uint8_t e_drx_value:4;) +} __attribute__ ((packed)) nas_extended_drx_parameters_t; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/lib/nas/support/cache/type_list.py b/lib/nas/support/cache/type_list.py index 9d95d5a05..4e70e4ef3 100644 --- a/lib/nas/support/cache/type_list.py +++ b/lib/nas/support/cache/type_list.py @@ -13,6 +13,35 @@ type_list["Tracking area identity"]["decode"] = \ type_list["Tracking area identity"]["encode"] = \ " target.tac = htons(tracking_area_identity->tac);\n\n" +type_list["Tracking area identity list"]["decode"] = \ +" int i = 0;\n" \ +" {\n" \ +" if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS)\n" \ +" for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++)\n" \ +" tracking_area_identity_list->type0.tac[i] = ntohs(tracking_area_identity_list->type0.tac[i]);\n" \ +" else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS)\n" \ +" tracking_area_identity_list->type1.tac = ntohs(tracking_area_identity_list->type1.tac);\n" \ +" else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS)\n" \ +" for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++)\n" \ +" tracking_area_identity_list->type2.tai[i].tac = ntohs(tracking_area_identity_list->type2.tai[i].tac);\n" \ +" else\n" \ +" return -1;\n" \ +" }\n\n" +type_list["Tracking area identity list"]["encode"] = \ +" int i = 0;\n" \ +" {\n" \ +" if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS)\n" \ +" for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++)\n" \ +" target.type0.tac[i] = htons(tracking_area_identity_list->type0.tac[i]);\n" \ +" else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS)\n" \ +" target.type1.tac = htons(tracking_area_identity_list->type1.tac);\n" \ +" else if (tracking_area_identity_list->type_of_list == NAS_TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS)\n" \ +" for (i = 0; i < tracking_area_identity_list->number_of_elements + 1 && i < NAS_MAX_TRACKING_AREA_IDENTITY; i++)\n" \ +" target.type2.tai[i].tac = htons(tracking_area_identity_list->type2.tai[i].tac);\n" \ +" else\n" \ +" return -1;\n" \ +" }\n\n" + type_list["Mobile identity"]["decode"] = \ " if (mobile_identity->tmsi.type_of_identity == NAS_MOBILE_IDENTITY_TMSI)\n" \ " {\n" \ diff --git a/lib/nas/support/nas_message.py b/lib/nas/support/nas_message.py index 499e88db9..bb41ada79 100644 --- a/lib/nas/support/nas_message.py +++ b/lib/nas/support/nas_message.py @@ -282,6 +282,40 @@ if os.path.isfile(cachefile) and os.access(cachefile, os.R_OK): tmp = [(k, v["reference"]) for k, v in type_list.items()] sorted_type_list = sorted(tmp, key=lambda tup: tup[1]) +f = open(outdir + 'nas_ies.h', 'w') +output_header_to_file(f) +f.write("""#ifndef __NAS_IES_H__ +#define __NAS_IES_H__ + +#include "core_pkbuf.h" +#include "nas_types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +CORE_DECLARE(c_int16_t) nas_encode_optional_type(pkbuf_t *pkbuf, c_uint8_t type); + +""") + +for (k, v) in sorted_type_list: + f.write("CORE_DECLARE(c_int16_t) nas_decode_%s(nas_%s_t *%s, pkbuf_t *pkbuf);\n" % (v_lower(k), v_lower(k), v_lower(k))) +f.write("\n") + +for (k, v) in sorted_type_list: + f.write("CORE_DECLARE(c_int16_t) nas_encode_%s(pkbuf_t *pkbuf, nas_%s_t *%s);\n" % (v_lower(k), v_lower(k), v_lower(k))) +f.write("\n") + + +f.write("""#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __NAS_IES_H__ */ + +""") +f.close() + f = open(outdir + 'nas_ies.c', 'w') output_header_to_file(f) f.write("""#define TRACE_MODULE _nasies @@ -305,7 +339,7 @@ for (k, v) in sorted_type_list: # d_print("%s = %s\n" % (k, type_list[k])) f.write("/* %s %s\n" % (type_list[k]["reference"], k)) f.write(" * %s %s %s */\n" % (type_list[k]["presence"], type_list[k]["format"], type_list[k]["length"])) - if type_list[k]["length"] == "1/2" or (type_list[k]["format"] == "TV" and type_list[k]["length"] == "1"): + if type_list[k]["format"] == "TV" and type_list[k]["length"] == "1": f.write("c_int16_t nas_decode_%s(nas_%s_t *%s, pkbuf_t *pkbuf)\n" % (v_lower(k), v_lower(k), v_lower(k))) f.write("{\n") f.write(" memcpy(%s, pkbuf->payload - 1, 1);\n\n" % v_lower(k)) @@ -439,14 +473,6 @@ ED2(c_uint8_t security_header_type:4;, """) -for (k, v) in sorted_type_list: - f.write("CORE_DECLARE(c_int16_t) nas_decode_%s(nas_%s_t *%s, pkbuf_t *pkbuf);\n" % (v_lower(k), v_lower(k), v_lower(k))) -f.write("\n") - -for (k, v) in sorted_type_list: - f.write("CORE_DECLARE(c_int16_t) nas_encode_%s(pkbuf_t *pkbuf, nas_%s_t *%s);\n" % (v_lower(k), v_lower(k), v_lower(k))) -f.write("\n") - for (k, v) in sorted_msg_list: f.write("#define NAS_" + v_upper(k) + " " + v + "\n") f.write("\n") @@ -511,10 +537,13 @@ CORE_DECLARE(int) nas_plain_encode(pkbuf_t **pkbuf, nas_message_t *message); } #endif /* __cplusplus */ -#endif /* __GTPV2C_MESSAGE_H__ */ +#endif /* __NAS_MESSAGE_H__ */ """) + f.close() + + f = open(outdir + 'nas_decoder.c', 'w') output_header_to_file(f) f.write("""#define TRACE_MODULE _nasdec