P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
381 stars 132 forks source link

Capturing Need OR/ON/OP and Cond 3GPP RRC ASN.1 #160

Closed grant-h closed 2 years ago

grant-h commented 2 years ago

3GPP has a loosely followed convention of annotating OPTIONAL fields in the RRC UE downlink messages to indicate to implementors what action should be taken (if any) when a field is not present. Here's an example:

ParentType :: = SEQUENCE {
  field1 FieldType1 OPTIONAL, -- Need OP
  field2 FieldType2 OPTIONAL, -- Need ON
  field3 FieldType3 OPTIONAL, -- Need OR
  field4 FieldType4 OPTIONAL -- Cond someCondition
}

Since this is a bit of a hack on the 3GPP's part, I'm not sure what the best way is for pycrate to handle this metadata (if at all). I do believe it would be useful to capture this information during ASN.1 compilation though or maybe provide some guidance/script to walk the ASN.1 AST to capture and associate this information with types. Frankly grep would probably get pretty far on its own, but having it be typed would be a bonus.

See 3GPP TS 36.331 version 16.2.1, rel 16, Section 6, Table 6.1-1 for more details.

p1-bmu commented 2 years ago

Thanks for your feedback. Unfortunately, comments are stripped early in the text processing, while calling clean_text() defined in https://github.com/P1sec/pycrate/blob/93ab3bfbd7176ce64fefb6707085c48d4156cb0a/pycrate_asn1c/utils.py#L471

I agree that catching those kind of meta-definition would be nice. However, comments notation and formatting are..... unspecified, and there is no common rules on how to catch them ! What I would personally do is to develop an adhoc routine (eventually just with grep / awk) to catch those and write them in a file in a simple format. Then in Python, after you load the LTE RRC module, you can use this file to retrieve those meta-definition and apply further checks on ASN.1 objects.