Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

ASN1 decoding of grouped extension with all group components OPTIONAL and component with implicit value #243

Open
luiscpgh opened this issue Aug 14, 2023 · 3 comments
Assignees
Labels

Comments

@luiscpgh
Copy link

Hi,

I encountered an issue encoding a message containing IEs in the "..." extension (sorry, I am not sure what this extension is actually called)...

Decoding works great. Encoding is the problem.

Here is a minimal example:

from pycrate_asn1dir import RRCNR
from binascii import unhexlify, hexlify

# decode
rrc = RRCNR.NR_RRC_Definitions.UE_MRDC_Capability
hexstr = '''a107c058161601c41000000122200402c2340410b003a030a74ed8e7c310000800040202008008'''
unhex = unhexlify(hexstr)
rrc.from_uper(unhexlify(hexstr))
decoded  = rrc()
decodedMsg = rrc.to_asn1()
print(decodedMsg)

# now encode it
en_rrc = RRCNR.NR_RRC_Definitions.UE_MRDC_Capability
en_rrc.from_asn1(decodedMsg) # error:  unknown extension, 'supportedBandCombinationList-v1540 {\n...
en_unhex = en_rrc.to_uper()
en_hex = bytes.hex(en_unhex)

print('encoded {}'.format(en_hex))

In the example above, I think the issue is that the supportedBandCombinationList-v1540 IE is past the "..." extension in the 3GPP spec:

RF-ParametersMRDC ::=                   SEQUENCE {
    supportedBandCombinationList            BandCombinationList                             OPTIONAL,
    appliedFreqBandListFilter               FreqBandList                                    OPTIONAL,
    ...,
    [[
    srs-SwitchingTimeRequested              ENUMERATED {true}                               OPTIONAL,
    supportedBandCombinationList-v1540      BandCombinationList-v1540                       OPTIONAL
    ]],

Any tips with how to tell the encoder that the IE is past the "..." extension?

@p1-bmu p1-bmu self-assigned this Aug 28, 2023
@p1-bmu
Copy link
Contributor

p1-bmu commented Aug 28, 2023

Actually here, this is not an encoding but a decoding issue. The error happens when you try to decode the textual string corresponding to the value in ASN.1 notation, into the object structure.
There is no issue when you set the direct value into the object:

en_rrc.set_val(decoded)

I'll need to investigate what is the exact issue with decoding the ASN.1 value string.

@p1-bmu
Copy link
Contributor

p1-bmu commented Aug 28, 2023

We have grouped extensions in the sub-object RF-ParametersMRDC:

RF-ParametersMRDC ::=                   SEQUENCE {
    supportedBandCombinationList            BandCombinationList                             OPTIONAL,
    appliedFreqBandListFilter               FreqBandList                                    OPTIONAL,
    ...,
    [[
    srs-SwitchingTimeRequested              ENUMERATED {true}                               OPTIONAL,
    supportedBandCombinationList-v1540      BandCombinationList-v1540                       OPTIONAL
    ]],

And the group components are all OPTIONAL, plus the srs-SwitchingTimeRequested can only have one value forced to True. Hence, we may have additionally an issue here with canonical PER. As a first remark, I see the UPER re-encoding from pycrate differs from the provided buffer.

@luiscpgh : has this buffer been observed from a commercial handset implementation ?

@p1-bmu p1-bmu changed the title ASN1 encoding error when ... extension ASN1 decoding of grouped extension with all group components OPTIONAL and component with implicit value Aug 28, 2023
@p1-bmu p1-bmu added the bug label Aug 28, 2023
@luiscpgh
Copy link
Author

@p1-bmu : Thank you for looking into this. Yes, the message is sent by a OnePlus N200 phone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants