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

Iterating through a SEQ OF with get_at method #195

Closed
dbressan2 opened this issue May 17, 2022 · 8 comments
Closed

Iterating through a SEQ OF with get_at method #195

dbressan2 opened this issue May 17, 2022 · 8 comments
Assignees
Labels

Comments

@dbressan2
Copy link

Hi

I am attempting to get an octet string object corresponding to each instance of ueCapabilityRAT-Container

I am getting unexpected results with get_at where it always returns the octet string corresponding to last instance of ueCapabilityRAT-Container, whereas I would like to iterate through each instance.
How can we use get_at for SEQ OF ?

I am trying the following code:

message0 = """
3e 03 08 19 2d db 80 50 30 9f bf 7e 0c 1f 83 f0
7e 0f df 83 76 26 80 08 0d cf 64 00 00 00 01 78
68 0c 0a 0c 77 c0 00 00 00 b2 f0 03 00 24 10 86
00 60 84 30 03 00 30 40 18 20 0c 20 84 30 42 18
21 0c 10 86 08 43 00 30 80 10 c2 00 43 04 01 82
00 c0 0c 00 c0 09 68 3e aa 30 e0 b8 18 40 00 82
07 f8 00 20 80 fe 10 00 ff 00 04 00 70 80 01 05
08 20 81 84 00 09 20 ff 80 02 0b f8 41 03 fc 00
12 40 ff 00 04 50 7f c0 01 01 fc 20 82 fe 10 3f
c0 01 04 2f f0 00 41 7f 08 2f e1 04 1f f0 00 49
7f 08 20 bf 84 9f f0 00 41 07 fc 00 11 5f c2 08
2f e1 17 fc 00 10 40 ff 00 04 d0 bf c0 01 01 fc
20 bf 84 10 9f c2 07 f8 00 20 bf 84 10 7f c0 01
01 fc 24 82 fe 10 3f c0 01 24 0c 20 10 49 03 fc
04 12 40 ff 00 84 52 e0 fc 1f 83 f0 7e 0f c1 f8
3f 07 e0 fc 1f 83 f0 7e 0f c1 f8 3f 07 e0 fc 1f
83 f0 7e 0f c1 f8 3f 07 ed 9d 00 00 11 97 08 b8
00 00 e5 c0 00 40 40 40 80 41 81 00 00 50 14 04
04 04 04 04 14 19 01 05 06 40 42 40 50 14 04 14
05 01 05 01 40 41 40 50 10 50 14 04 04 04 24 19
01 40 42 41 90 14 04 14 19 01 05 06 40 40 00 40
40 40 66 80 03 e6 57 9a 04 01 48 7f f9 a5 2e f1
c0 3a 00 16 08 00 64 92 00 00 40 00 a2 09 73 40
00 a1 e1 00 00 00 21 00 00 01 02 08 20 80 00 20
82 18 20 82 08 20 80 18 00 00 00 51 90 00 00 00
40 02 20 10 50 42 05 81 0c e1 20 10 00 07 4f 5a
13 02 00 02 01 40 48 24 c5 80 02 60 d4 0c 13 60
18 73 e6 18 f2 85 81 c1 30 08 0c 41 00 3a 0d 85
18 1a c1 18 43 41 02 0f 94 02 2c b6 4c 55 0d 0e
7c 47 1e 81 9f 60 4f 8c 73 e6 18 f2 85 81 c0 e1
e0 b8 00 27 80 0e 00 09 e0 00 38 01 c0 00 20 0a
01 47 27 80 22 03 01 f0 28 01 00 00 00 00 80 00
01 00 40 00 01 00 20 00 00 c0 10 00 00 60 08 00
00 40 04 00 00 28 02 00 00 18 01 00 00 04 00 80
00 07 00 40 00 04 01 0c a9 bc a9 ac 0c ac 0d ac
99 ac a5 ac 8d ac 04 ac 08 a0 48 20 00 01 2c a4
a0 80 00 0c b2 92 82 00 00 52 ca 48 08 00 01 cb
29 20 20 00 09 2c a4 80 80 00 2c b2 92 02 00 00
d2 ca 48 08 00 03 cb 29 20 20 00 11 2c a4 80 80
00 4c b2 92 01 2a 55 57 4a aa a8 1c 55 2a 8b a5
51 54 9a 2a 94 c5 52 38 aa 03 15 40 a2 80 87 40
2a 81 40 e0 70 28 14 0a 05 02 81 40 a0 08 50 18
12 0a 12 32 00 62 5a 10 7c 04 a1 60 40 1c 28 00
00 00 44 00 40 14 02 80 b0 03 a0 30 a7 42 d8 e7
c3 10 00 08 00 08 02 02 00 80 28 00
""".replace(" ", "").replace("\n", "")
dcch = lte_g80.EUTRA_RRC_Definitions.UL_DCCH_Message
dcch.from_uper(bytes.fromhex(message0))
print (dcch.to_asn1())
container_list = ['message', 'c1', 'ueCapabilityInformation', 'criticalExtensions', 'c1', 'ueCapabilityInformation-r8',
'ue-CapabilityRAT-ContainerList']

print (dcch.to_asn1())
num_tech = 3
for tech in range(num_tech):

tech_rat_container = dcch.get_val_at(container_list + [tech])
rat_info = tech_rat_container['rat-Type']
print(rat_info)
# this works 
container = tech_rat_container['ueCapabilityRAT-Container']
print (container)
# this does not work and returns last ueCapabilityRAT-Container regardless of tech value 
oct_str = dcch.get_at(container_list + [tech, 'ueCapabilityRAT-Container']) 
print ("oct str for rat info {0} = {1}".format(rat_info, oct_str._val.hex()))

Thanks

@p1-bmu
Copy link
Contributor

p1-bmu commented May 18, 2022

get_at() is for selecting a sub-object from a constructed one. Here, you better want to use get_val_at() to select a sub-value from a value assigned to the constructed object.

@p1-bmu p1-bmu self-assigned this May 18, 2022
@dbressan2
Copy link
Author

dbressan2 commented May 18, 2022 via email

@dbressan2
Copy link
Author

dbressan2 commented May 19, 2022 via email

@dbressan2
Copy link
Author

dbressan2 commented Jun 20, 2022 via email

@p1-bmu
Copy link
Contributor

p1-bmu commented Jun 27, 2022

The 1st level sub-object of a SEQUENCE OF (or SET OF) is not named in ASN.1. It's named _item_ in pycrate (because we still need one programmatically). And you don't need to pass any specific naming when selecting it with get_at().

See e.g. at the end of this section of the wiki: https://github.com/P1sec/pycrate/wiki/Using-the-pycrate-asn1-runtime#rrc-3g

@dbressan2
Copy link
Author

dbressan2 commented Jun 27, 2022 via email

@p1-bmu
Copy link
Contributor

p1-bmu commented Jun 27, 2022

Is this the same issue as in #203 ? If yes, I suggest you close one of the too. Looking at what you do:

containers.get_at([1, 'rat-Type']).get_val()

I guess this is the same. And again, get_at() if for object, and there is not such itemized / different sub-object within a SEQUENCE OF, only a single object, but eventually several different values to be retrieved with get_val_at().

Eventually, go through the source code (

def get_at(self, path):
). And if you are still lost, please ask for support internally at Qualcomm first.

@dbressan2
Copy link
Author

Hi
Thanks for comments. The issue is indeed similar as #203, I am closing this one and we can track the discussion further with #203

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