Chinaunix首页 | 论坛 | 博客
  • 博客访问: 201185
  • 博文数量: 5
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 435
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-07 16:10
文章分类

全部博文(5)

文章存档

2009年(1)

2008年(4)

我的朋友

分类: C/C++

2008-03-13 17:38:17

CSN.1 ("Concrete Syntax Notation 1") is a notation used for the description of the encoding of signalling messages. A kernel of it was originally designed for specific needs of the GSM standard, as a tool for the description of bit-efficient messages.

Among its features, it enables, for a given signalling protocol:

to define the set of correctly encoded messages ;

to label parts of correctly encoded messages, enabling easy reference within the semantic description of the protocol ;

to ease the taking into account of compatibility between versions ;

to define specific strings for test purposes.

CSN.1 is fully compilable.

 

Although their acronyms are similar, CSN.1 is substantially different from ASN.1.

ASN.1 defines an abstract data structure: in other words, an ASN.1 specification tells you, for example, that we have a structure with some fields in it, or a union, an array and so on.

In ASN.1 we describe our data structure as we do when we are declaring C structs.

When we need to actually send the data over the network, we follow the encoding rules we have choosen. These encoding rules, like BER o PER, tell us that a structure is always coded in a given way, an integer is always coded in another way and so on.

[see ]

Therefore any ASN.1 tools can easily generate a C data structure and some C code able to take a BER or PER coded binary stream and decode it into that C structure.

CSN.1, instead, defines at bit-level the encoded stream. A CSN.1 definition says, for example, that we expect a 1 followed by 8 more bits or a 0 followed by 4 bits and another 0:

 

< my data > ::= 1 | 0 0;

 

Most of the CSN.1 tools read the CSN.1 specification file and produce a CSN.1 parser; this parser, once compiled, reads the encoded binary stream and when it recognize some valid elements in it invokes a user defined callback function.

In other words, it generates code that will say to you: hey, I found the 1 followed by the 8 bits you were expecting: the 8 bits are 11001001; do whatever you like.

This is better than decoding manually, but it still means that for every CSN.1 definition, you have to manually:

define your data structure

define a function that copies the values into the right field of the structure

This means reading and understanding thoroughly each CSN.1 specification and manually updating the data structures and call back functions everytime the CSN.1 source changes.

 

Rules:

1     The Basic Rules

A "bit string" is an ordered sequence of symbols, each belonging to a two-value set.

The character "0" and "1" are used to indicate one bit, respectively of one or the other value.

 

Where needed, the word "null" call be used to indicate the null string, i.e., the string of no symbols.

Formally, the notation « null » denote the set composed of a single bit string, the empty string.

 

A succession of two string descriptions describe the concatenation of the strings.

For instance:    00

This denotes the set composed of the single bit string of length 2 composed of two zeros.

 

The concatenation has a higher precedence than the choice.

Examples:        0 | 1

Denotes the same set as "bit".

The characters "{" and "}" are used for delimiting a string set description from what follows and/or precedes.         0 {0|1}

This indicates the same set of bit strings as in the previous case.

 

The characters "<" and ">" are used to delimit a reference to the description of a string set. This can be used inside a string set description, to refer to a string set described elsewhere.

Example:         

 

A reference followed by the character sequence "::=" followed by a string set description is used to associate the description with the reference, terminated when needed to separate it from a following definition and when compilability is looked for, by a semi-colon ' ;.

Recursive definition is allowed. To avoid too much difficulties for would-be-compilers, only tail recursivity should be used.

Examples:        ::= 00 | 01 | 10 | 11 ;

This could have been noted as well: ::= {00 | 01 | 10 | 11} ;

or     ::= {0|1} {0|1} ;

Recursive example:   ::= null | { {0 | 1} } ;

 

The following construction:               

describes a 0 when emitted and a bit (0 or 1) in reception.

 

Padding is then necessary to fill up the message up to the desired length. Moreover, the padding uses a particular sequence of bits, of fixed position, i.e., the value of a padding bit depends on its position relative to the start of the message. The padding sequence is protocol-specific. In most cases it is constituted of all 0 values.

 

Comments can be added, starting with the term "--" and ended by the end of line.

 

2          Advanced rules

Delimited names as defined by Rule B6 identify sets of sub strings. In many cases this can be used within the context of a message to refer to the specific part of the message. However, this is not of general application, since it may happen that two parts of a message follow the same structure, and economy of notation requires that the structure is described but once.

The general syntax that follows allows to refer to a part inside a description:

                   <name1 : string description>

 

An arithmetic expression used as exponent after a delimited string description is used to indicate repetitions.

A numerical expression between parentheses indicates a fixed number of repetitions.               ::= {0 | 1}(8) ;

is equivalent to ::= {0 | 1} {0 | 1} {0 | 1} {0 | 1} {0 | 1} {0 | 1} {0 | 1} {0 | 1} ;

This could also be written:       ::= bit(8) ;

When the exponent is negative or equal to 0, the exponentiated construction is equivalent to the null string.
An example of a common construction is the following:   

Simple arithmetic, using numbers, terms "+", "-", "*" and "/", and parentheses are allowed in expressions.

A star used alone between parentheses, or a double star, indicates a finite, possibly null, but indeterminate, number of repetitions. (The star used as an exponent can be understood also as meaning the union of all the sets obtained by replacing the star by zero or some positive integer).

::= {0 |1}(*) ;

 ::= {0 |1}** ;

This allows a shorter notation of recursive constructions such as:

::= {0|1}  | null;

 

A shorter notation is allowed when the expression has a single term, consisting of a star followed by the term:         ::= {0 | 1}*8 ;

::= *(8*(4+1)) ;

::= bit**;

 

References:

[1] 3GPP TS 24.007

阅读(1254) | 评论(1) | 转发(0) |
0

上一篇:ASN.1学习笔记

下一篇:物理层形象说明

给主人留下些什么吧!~~

chinaunix网友2008-04-28 20:18:11

你好,最近做GSM相关的项目。用到CSN.1,希望能交流一下