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
382 stars 132 forks source link

Encoding NAS5G messages - syntax help needed #97

Closed slashTPA closed 4 years ago

slashTPA commented 4 years ago

Hi there,

I somehow struggle to instantiate NAS5G messages. E.g. trying:

Msg = 5GMMRegistrationAccept()

gives only back : SyntaxError: invalid syntax

I failed to find the right syntax in 5G case (working well in 3G). Any hint would be appreciated. Thx. Do I need to define myself in TS24501_FGSM.py this mapping (?)

all = [

]

p1-bmu commented 4 years ago

Hello, in Python, variables cannot start with an alphanumeric character. Therefore, all "5G" related structures and classes are prefixed "FG", as you can see from the source code, e.g.: https://github.com/P1sec/pycrate/blob/383fd140a60ab5ada688aaec73a122117c879b80/pycrate_mobile/TS24501_FGMM.py#L152

Otherwise, there is no specific difference compared to 2-3-4G NAS protocols, as you can see from the wiki: https://github.com/P1sec/pycrate/wiki/Mobile-nas-messages

slashTPA commented 4 years ago

Well, still I don't see the relation. If I do a:

Msg, err = parse_NAS5G(unhexlify('2e0501c1ffff91a1')) print(Msg.show()) I get a decoding as 5GSMPDUSessionEstabRequest

Running then something like: Msg = FGSMPDUSessionEstabRequest() ends up in: NameError: name 'FGSMPDUSessionEstabRequest' is not defined

while in the 'old' world it worked like: Msg = MMLocationUpdatingRequest() print(Msg.show()) and I get the default MMLocationUpdatingRequest (with with mandatory IEs)

That is what I'd like to achive for 5G as well...

p1-bmu commented 4 years ago

As you can see from the source code: https://github.com/P1sec/pycrate/blob/383fd140a60ab5ada688aaec73a122117c879b80/pycrate_mobile/NAS5G.py#L32 Only FGMMTypeClasses and co. are imported in the NAS5G module.

If you want to access all 5G NAS message classes directly, you can import them explicitly:

from pycrate_mobile.TS24501_FGMM import *
from pycrate_mobile.TS24501_FGSM import *
slashTPA commented 4 years ago

Thank you very much. This was the missing piece of info for me.