This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
herlesupreeth gerrit-no-reply at lists.osmocom.orgherlesupreeth has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/18194 ) Change subject: Import TLV parsing related function from https://github.com/mitshell/card ...................................................................... Import TLV parsing related function from https://github.com/mitshell/card The functions are imported from the git commit 2a81963790e27eb6b188359af169c45afb6d3aaf from master branch Change-Id: I5c7fdbd122e696d272f7480785d0c17ad2af138c --- M pySim/utils.py 1 file changed, 39 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/94/18194/1 diff --git a/pySim/utils.py b/pySim/utils.py index 1980685..eb7a56b 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -359,3 +359,42 @@ avail_st += '\tService %d - %s\n' % ((8*i) + j, lookup_map[(8*i) + j]) byte = byte >> 1 return avail_st + +def first_TLV_parser(bytelist): + ''' + first_TLV_parser([0xAA, 0x02, 0xAB, 0xCD, 0xFF, 0x00]) -> (170, 2, [171, 205]) + + parses first TLV format record in a list of bytelist + returns a 3-Tuple: Tag, Length, Value + Value is a list of bytes + parsing of length is ETSI'style 101.220 + ''' + Tag = bytelist[0] + if bytelist[1] == 0xFF: + Len = bytelist[2]*256 + bytelist[3] + Val = bytelist[4:4+Len] + else: + Len = bytelist[1] + Val = bytelist[2:2+Len] + return (Tag, Len, Val) + +def TLV_parser(bytelist): + ''' + TLV_parser([0xAA, ..., 0xFF]) -> [(T, L, [V]), (T, L, [V]), ...] + + loops on the input list of bytes with the "first_TLV_parser()" function + returns a list of 3-Tuples + ''' + ret = [] + while len(bytelist) > 0: + T, L, V = first_TLV_parser(bytelist) + if T == 0xFF: + # padding bytes + break + ret.append( (T, L, V) ) + # need to manage length of L + if L > 0xFE: + bytelist = bytelist[ L+4 : ] + else: + bytelist = bytelist[ L+2 : ] + return ret -- To view, visit https://gerrit.osmocom.org/c/pysim/+/18194 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I5c7fdbd122e696d272f7480785d0c17ad2af138c Gerrit-Change-Number: 18194 Gerrit-PatchSet: 1 Gerrit-Owner: herlesupreeth <herlesupreeth at gmail.com> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200511/41f6e291/attachment.htm>