提取3GPP TS中RRC ASN.1模式及编译

本文介绍了如何将3GPP协议文档转换为ASN.1格式,并利用asn1c编译器生成C源代码。首先,通过txt2asn1和extract_asn1_from_spec.pl工具提取RRC协议的ASN.1定义,然后使用asn1c进行编译,支持BER和PER编码。在编译过程中,解决可能出现的链接问题,如未定义的asn_DEF_PDU符号,可以通过设置-DPDU标志来解决。
摘要由CSDN通过智能技术生成

整体流程图

image-20211006095545911

ASN.1 标准简介

在电信和计算机网络领域,ASN.1Abstract Syntax Notation One) 是一套标准,是描述数据、编码、传输、解码的灵活的抽象语义记法。它提供了一套正式、无歧义和精确的规则以描述独立于特定计算机硬件的对象结构。

3GPP协议

5G NR 的无线资源控制(RRC)协议是 38.331

38.331

image-20211005113541974

LTE 的无线资源控制(RRC)协议是 36.331

36.331

image-20211005113603915

提取RRC,ASN1样式

image-20211005113918113

转换工具下载

将下载后的3GPP协议Word 文档去掉页眉页脚后转换成纯文本txt, 编码选择UTF-8

使用txt2asn1 转换

txt2asn1

请下载ZIP格式并解压,避免出现exe权限无法运行问题

在同目录下终端运行 得到xxx.asn1文件

./txt2asn1.exe XXX.txt

image-20211005115104278

使用extract_asn1_from_spec.pl

extract_asn1_from_spec

下载文件后, 源文件同目录终端运行

perl extract_asn1_from_spec xxxx.txt

得到 EUTRA-RRC-Definitions.asn, EUTRA-UE-Variables.asn ,EUTRA-InterNodeDefinitions 三个文件

image-20211005115415629

ASN1C编译ASN.1文件

ASN1C 是将 ASN.1 规范转换为 C 源代码的免费开源编译器。 它支持一系列 ASN.1 语法,包括 ISO/IEC/ITU ASN.1 1988、'94、'97、2002 和以后的修正。 支持的编码规则集是

  • BER: ITU-T Rec. X.690 | ISO/IEC 8825-1 (2002) (BER/DER/CER)
  • PER: X.691|8825-2 (2002) (PER).
  • XER: X.693|8825-3 (2001) (BASIC-XER/CXER).

asn1c官网

asn1c源码

ubuntu 可直接通过 sudo apt-get install asn1c 进行安装

sudo apt update
sudo apt install asn1c

image-20211005115807407

image-20211005115922220

使用asn1c 编译

asn1c -S /usr/share/asn1c -fcompound-names -gen-PER -pdu=auto 36331-f40.asn1
# -pdu=auto  产生pdu_colletion.c文件
# -fcompound-names 去除重定义
# -gen-PER 使用PER编码
# -S /usr/share/asn1c 指定asn1c库文件位置, 通过使用whereis asn1c命令查看其库位置

FAQ

Q.: Does asn1c support BER encoding? I see only DER encoding in documentation.
A.: Yes, the asn1c compiler fully supports BER encoding. Any DER encoded data is, by definition, a valid BER data, from the receiver’s point of view.

If you want data to be BER or DER encoded, just invoke der_encode().

Q.: My linker complains: Undefined symbols: _asn_DEF_PDU.
A.: If you have your own file with main() routine, just delete the converter-sample.cfile, you won’t need it. If you haven’t created the main() routine yourself and wish to rely on converter-sample.c for your transcoding needs, add -DPDU=YourPdu to the list of compiler flags.

Q.: How to compile the 3GPP Radio Resource Control specification?
A.: The asn1c distribution includes an RRC 25.331 (version 7.1.0) example, check out https://github.com/vlm/asn1c/tree/master/examples/sample.source.RRC. You can also use the pre-compiled rrc-dump.exe program, which is part of Windows ASN.1 compiler installer.

Q.: How to compile the ISO 13522 (MHEG-5) specification?
A.: The ASN.1 compiler comes with a MHEG-5 decoder. Follow the https://github.com/vlm/asn1c/tree/master/examples/sample.source.MHEG5 README file instructions. You can also use the pre-compiled mheg5dump.exe program, which is part of Windows ASN.1 compiler installer.

Q.: How to compile the XYZ decoder?
A.: If XYZ is one of MEGACO (Media Gateway Control), PKIX1/X.509, LDAP, GSM TAP3 or OAM ULP, just go to examples/sample.source.XYZ and run make. The Windows ASN.1 compiler installer already contains the pre-compiled decoders for these encoding formats.

If you have something else, you should either use the Online ASN.1 compiler, or download the ASN.1 compiler source code.

如果不使用自己的main()函数, 直接使用converter-sample.c的化, 需要在其中添加一个目标PDU

#include <asn_application.h>
#include <asn_internal.h>	/* for ASN__DEFAULT_STACK_MAX */

#define PDU BCCH_BCH_Message
/* Convert "Type" defined by -DPDU into "asn_DEF_Type" */
#define	ASN_DEF_PDU(t)	asn_DEF_ ## t
#define	DEF_PDU_Type(t)	ASN_DEF_PDU(t)
#define	PDU_Type	DEF_PDU_Type(PDU)

或者在Makefile.am.sample 文件中, 修改 CFLAGS 添加 -DPDU= 选项

CFLAGS += -DHAVE_CONFIG_H -DJUNKTEST -D_DEFAULT_SOURCE  -DPDU=BCCH_BCH_Message -DASN_PDU_COLLECTION -I.
OBJS=${ASN_MODULE_SRCS:.c=.o} ${ASN_CONVERTER_SOURCES:.c=.o}

all: $(TARGET)

$(TARGET): ${OBJS}
	$(CC) $(CFLAGS) -o $(TARGET) ${OBJS} $(LDFLAGS) $(LIBS)
3GPP TS 23.285 V14.2.0 (2017-03) 3rd Generation Partnership Project; Technical Specification Group Services and System Aspects; Architecture enhancements for V2X services (Release 14) 官网下载 需要凑够五十个字,在写一些吧。 V2X从2019年火了,看下载量,就看出来了。 全体降价为1,希望大家给一些留言,不胜感激额 本人拥有3GPP R14相关标注你文档如下: │ 3GPP TR 22.885 V14.0.0 (2015-12).doc │ 3GPP TR 22.886 V15.1.0 (2017-03)-f10.doc │ 3GPP TR 22.886 V15.1.0 (2017-03).doc │ 3GPP TR 23.785 V14.0.0 (2016-09).doc │ 3GPP TR 33.885 V14.0.0 (2017-06).doc │ 3GPP TR 36.785 V14.0.0 (2016-10).doc │ 3GPP TR 36.786 V14.0.0 (2017-03).doc │ 3GPP TR 36.885 V14.0.0 (2016-06).doc │ 3GPP TR 38.913 V14.2.0 (2017-03)-e20.doc │ 3GPP TS 21.905 V14.1.1 (2017-06).doc │ 3GPP TS 22.185 V14.3.0 (2017-03).doc │ 3GPP TS 22.278 V15.1.0 (2017-03).doc │ 3GPP TS 23.003 V15.0.0 (2017-06).doc │ 3GPP TS 23.007 V14.3.0 (2017-06).doc │ 3GPP TS 23.008 V15.0.0 (2017-06).doc │ 3GPP TS 23.009 V14.0.0 (2017-03).doc │ 3GPP TS 23.122 V15.0.0 (2017-06).doc │ 3GPP TS 23.285 V14.2.0 (2017-03).doc │ 3GPP TS 23.285 V14.2.0 (2017-03).pdf │ 3GPP TS 23.285 V14.3.0 (2017-06).doc │ 3GPP TS 24.301 V14.4.0 (2017-06).doc │ 3GPP TS 24.334 V14.0.0 (2016-12).doc │ 3GPP TS 24.385 V14.1.0 (2017-06).doc │ 3GPP TS 24.386 V14.1.0 (2017-06)-e10.doc │ 3GPP TS 29.212 V14.4.0 (2017-06).doc │ 3GPP TS 29.272 V15.0.0 (2017-06).doc │ 3GPP TS 29.338 V14.2.0 (2017-06).doc │ 3GPP TS 29.387 V0.1.0 (2016-10).doc │ 3GPP TS 29.388 V1.0.0 (2017-03).doc │ 3GPP TS 29.388 V14.1.0 (2017-06).doc │ 3GPP TS 29.389 V1.0.0 (2017-03).doc │ 3GPP TS 29.389 V14.1.0 (2017-06).doc │ 3GPP TS 29.468 V15.0.0 (2017-06).doc │ 3GPP TS 31.102 V14.3.0 (2017-06).doc │ 3GPP TS 31.111 V14.3.0 (2017-06).doc │ 3GPP TS 33.185 V14.0.0.(2017-06).doc │ ts_122185v140300p.pdf │ ts_132277v120000p.pdf │
3GPP TS 23.285 V14.3.0 (2017-06) 3rd Generation Partnership Project; Technical Specification Group Services and System Aspects; Architecture enhancements for V2X services (Release 14) 官网下载 需要凑够五十个字,在写一些吧。 V2X从2019年火了,看下载量,就看出来了。 全体降价为1,希望大家给一些留言,不胜感激额 本人拥有3GPP R14相关标注你文档如下: │ 3GPP TR 22.885 V14.0.0 (2015-12).doc │ 3GPP TR 22.886 V15.1.0 (2017-03)-f10.doc │ 3GPP TR 22.886 V15.1.0 (2017-03).doc │ 3GPP TR 23.785 V14.0.0 (2016-09).doc │ 3GPP TR 33.885 V14.0.0 (2017-06).doc │ 3GPP TR 36.785 V14.0.0 (2016-10).doc │ 3GPP TR 36.786 V14.0.0 (2017-03).doc │ 3GPP TR 36.885 V14.0.0 (2016-06).doc │ 3GPP TR 38.913 V14.2.0 (2017-03)-e20.doc │ 3GPP TS 21.905 V14.1.1 (2017-06).doc │ 3GPP TS 22.185 V14.3.0 (2017-03).doc │ 3GPP TS 22.278 V15.1.0 (2017-03).doc │ 3GPP TS 23.003 V15.0.0 (2017-06).doc │ 3GPP TS 23.007 V14.3.0 (2017-06).doc │ 3GPP TS 23.008 V15.0.0 (2017-06).doc │ 3GPP TS 23.009 V14.0.0 (2017-03).doc │ 3GPP TS 23.122 V15.0.0 (2017-06).doc │ 3GPP TS 23.285 V14.2.0 (2017-03).doc │ 3GPP TS 23.285 V14.2.0 (2017-03).pdf │ 3GPP TS 23.285 V14.3.0 (2017-06).doc │ 3GPP TS 24.301 V14.4.0 (2017-06).doc │ 3GPP TS 24.334 V14.0.0 (2016-12).doc │ 3GPP TS 24.385 V14.1.0 (2017-06).doc │ 3GPP TS 24.386 V14.1.0 (2017-06)-e10.doc │ 3GPP TS 29.212 V14.4.0 (2017-06).doc │ 3GPP TS 29.272 V15.0.0 (2017-06).doc │ 3GPP TS 29.338 V14.2.0 (2017-06).doc │ 3GPP TS 29.387 V0.1.0 (2016-10).doc │ 3GPP TS 29.388 V1.0.0 (2017-03).doc │ 3GPP TS 29.388 V14.1.0 (2017-06).doc │ 3GPP TS 29.389 V1.0.0 (2017-03).doc │ 3GPP TS 29.389 V14.1.0 (2017-06).doc │ 3GPP TS 29.468 V15.0.0 (2017-06).doc │ 3GPP TS 31.102 V14.3.0 (2017-06).doc │ 3GPP TS 31.111 V14.3.0 (2017-06).doc │ 3GPP TS 33.185 V14.0.0.(2017-06).doc │ ts_122185v140300p.pdf │ ts_132277v120000p.pdf │
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值