-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Octet string in UPER encoding of DSRCData.ApplicationList shifted 2 bits to the left #15
Comments
Could you please provide a reference for the specs you are mentioning? Or maybe they are not available publicly (eventually send them to me by email)? It will be hard to help if I don't have access to the comparison element. |
And thank you for the introductory message. It's OK ask questions in issues: as I am currently the only active maintainer / developer for the project, I prefer to keep the project management as simple as possible. |
Thanks for the answer, I was thinking the same! Sadly using the most recent version of a standard is not always the "most appropriate" choice. A device can use/implement an older version of a norm and still be accepted in most countries. And the most recent specification usually is not immediately widely adopted. Also, I work for a TSP so I have a few of the norms, but I don't think they are openly available. If you look in the webpage for the ISO 12813 (CCC), it states CCC is suitable for the Italian DSRC (UNI), and its norm is openly available: That is the only norm I know that can easily be found for free. |
You were right! I just had to compile the ASN1 specs and use them properly. Sorry for wasting your time. I was hesitant to use the most recent specs fearing they may not be backwards compatible with the 2011 version of ISO 14906. But all the UPER encodings I tested match with the informative examples provided in the ISO 14906 (2011) PDF document ! So here is a code snippet with some tests I did for whoever is interested: from efc import EfcDsrcGeneric, EfcDataDictionary
#from ccc import EfcDsrcGeneric, EfcDataDictionary
#from pycrate_asn1dir.ITS_CCC import EfcDsrcGeneric, EfcDataDictionary
BeaconID = EfcDsrcGeneric.BeaconID
BeaconID.set_val({
'manufacturerid': 0x1,
'individualid': 1052 #41C
})
print(BeaconID.to_asn1())
print("BeaconID UPER:", BeaconID.to_uper().hex().upper())
BST = EfcDsrcGeneric.BST
utc_ts = 1103790512
bst_value = {
'rsu': {
'manufacturerid': 0x1,
'individualid': 1052 #41C
},
'time':utc_ts,
'profile': 0,
'mandApplications': [
{
'aid': 3
}
],
'profileList': []
}
BST.set_val(bst_value)
print(f"BST encoded in UPER in hex: {BST.to_uper().hex().upper()}")
print()
contract_provider = "30C001"
toc = 0x0001
cv = 0x02
efc_cm_str = f"{contract_provider}{toc:04X}{cv:02X}"
print(f"EFC-CM: {efc_cm_str}")
EfcContextMark = EfcDataDictionary.EfcContextMark
EfcContextMark.from_uper(bytes.fromhex(f"{efc_cm_str}"))
print("EFC-CM from UPER encoding in JER:", EfcContextMark.to_jer())
efc_cm = {
'contractProvider': {
'countryCode': (195, 10),
'providerIdentifier': 1
},
'typeOfContract': b'\x00\x01',
'contextVersion': 2
}
EfcContextMark.set_val(efc_cm)
print(EfcContextMark.to_asn1())
print("EFC-CM in UPER encoding:", EfcContextMark.to_uper().hex().upper())
EfcContainer = EfcDsrcGeneric.EfcContainer
EfcContainer.set_val(('efccontext', EfcContextMark._val))
print(EfcContainer.to_asn1())
EfcContainer.set_val(('attrList', [
{
'attributeId': 0,
'attributeValue': ('octetstring', bytes.fromhex(efc_cm_str))
}
]))
print("EFC Container with AttrList encoded in UPER in hex:", EfcContainer.to_uper().hex().upper())
print(EfcContainer.to_asn1()) And here is the output after execution:
9 is the preamble/choice index for AttributeList for the EfcContainer CHOICE. Also AttributeList is a Parameterized type, so I learned I simply need to use a container to contain it. I lost a lot of time recompiling ASN1 specs thinking I was doing something wrong lol. I will do some tests with some actual DSRC devices and report back here to share whatever info I get! |
Thanks a lot for the feedback. Do not hesitate to update this issue with any new findings. |
I can't believe how easy to use this package is after understanding containers!! Parameterized types should just be put inside a container to contain them and everything works! In the EfcDsrcGeneric v10.1 ASN there is a Container called T-APDU. I am switching request with all the devices using it! Here is my follow-up. I have this data structure in Python: from efc import EfcDsrcGeneric, EfcDataDictionary
get_resp_t_apdu_bytes = b't\x04\x01 @\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0fY_\x00\x00'
print(f"T-APDU containing Get-Response encoded in UPER in hex: {get_resp_t_apdu_bytes.hex().upper()}")
EfcDsrcGeneric.T_APDUs.from_uper(get_resp_t_apdu_bytes)
print(f"Python T-APDU value:\n{EfcDsrcGeneric.T_APDUs._val}")
print(f"T-APDU encoded in JER: {EfcDsrcGeneric.T_APDUs.to_jer()}") Which outputs the following:
I love the AttributeList makes up a list of lists since they are defined like so in the ASN: Attributes{Container} ::= SEQUENCE { So I have to manually write a key-value mapping for the attributes. Which is easy in Python with dict comprehension, of course! |
One question, though. I already know how to add ASN specs to pycrate_asn1dir/ and compile them after updating the dicts in pycrate_asn1c/specdir.py. I simply put the DSRC, EFC, CCC and LAC ASNs into a folder called ETSI_ITS_EFC and then added a 'ITS_EFC': 'ETSI_ITS_EFC' key-value pair to the ASN_SPECS_ITS dict. My question is: what should I call this ASN spec bundle instead of the "ETSI_ITS_EFC" string I made up? I found a few details on arc-it: There are no "bundles" for these standards on arc-it.net. |
These ITS ASN.1 specs seem really to have spreaded, being reused and adapted in several countries and by multiple SDOs. I can't answer your question btw, choose the naming which you think is closest to the SDO in charge and domain addressed. |
First off, I love this repo!
And secondly, I believe this is not really an Issue, rather a question.
I think raising Issues for my questions probably annoys the maintainers.
Therefore, could someone enable Discussions for this repo?
Anyway, about my question...
ITS ISO 14906 and EN 15509 for EFC / DSRC use PER (Packed Encoding Rules). EN ISO 12813 for CCC / DSRC uses it as well.
But the encoding of an ApplicationList exemple I built using the Aligned and Unaligned PER codecs of pycrate do not match the examples provided in Annex B of the first 2 norms when I tried them.
Here is a small test example for encoding a BST and an ApplicationList (containing an EFC-CM):
And here is the output:
So the BST encoding is OK up to padding!
But for some reason, in the UPER encoding of the AttributeList, the octet string of length 6 (containing the EFC-CM) is shifted 2 bits to the left.
I also tried out the APER codec, but to no avail...
Does anyone have any idea what I may be doing wrong?
The text was updated successfully, but these errors were encountered: