Closed Marc-Egli closed 1 year ago
Thanks for your feedback. CSN.1 fields are quite painful to manage unfortunately... Below, we can see that the get_len()
method for them are not exactly aligned with get_bl()
(i.e. for getting the length in bits), as it returns the round length in bytes, omitting the trailing / padding bits required for the NAS IE to align.
In [49]: MSNetCap.set_val([1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, []])
In [50]: MSNetCap.get_len()
Out[50]: 3
In [51]: MSNetCap.get_bl()
Out[51]: 29
In [52]: MSNetCap.set_val([1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, [0, 0, 0]])
In [53]: MSNetCap.get_bl()
Out[53]: 32
In [54]: MSNetCap.get_len()
Out[54]: 4
In [55]: m = EMMTrackingAreaUpdateRequest(val={'MSNetCap': [1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, [0, 0, 0]], 'AddInfoReq': {'CipherKey': 1}})
In [56]: m, e = parse_NAS_MO(m.to_bytes())
In [57]: e
Out[57]: 0
The workaround is to insert the padding at the end of the MSNetCap
value explicitely. I need to check how easy it is to fix the get_len()
method for the CSN1 objects.
OK, that one was easy to fix: https://github.com/P1sec/pycrate/commit/7e904f993c97aebc299792e9c4f2d98947403a21
Thank you very much ! Works for me now.
I am trying to add a
MSNetCap
and aAddInfoReq
field to aEMMTrackingAreaUpdateRequest
Here is a small snippet of code describing what I do :
The
parse_NAS_MT
function fails with error96
, which means I am missing a mandatory field. I do not understand why as I generate theMSNetCap
according to the specifications. I noticed in the wiki that there was an explanation about decoding and encodingMSNetCap
fields. I tried using the values from there instead of my own values. The difference is that the value from the wiki which is:[1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0]
, misses the last four single bit fields and the spare bit reference. To my surprise using the wiki value worked and the message was correctly re-encoded. I then tried the following value:[1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, [0,0,0,0]]
which also worked but the decoding was wrong as shown below.The
spare_bits
field contains only 3 bits whereas in myMSNetCap
field I specified 4 bits set to 0 in thespare_bits
reference field.Another observation I made is that removing the
AddinfoReq
will solve the issue and make the 4th bit reappear in the message.When I try to manually decode an
EMMTrackingAreaUpdateRequest
usingfrom_bytes
is get the following error :Note that the following values also crash but in different locations :
[1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0]
[1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0]
[1, 1, 1, 0, 1, 0, 1, 1, [1, 1, 1, 1, 1, 1], 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, [0, 0]]
I am still looking into the source code to find out why this happens. I think there is an issue with overlapping fields.
Edit
line 222, in _dec_unk_ie
in the error log is the computation of the Length for aType4TLV
.Thanks in advance.