示例#1
0
 def setEfEcc(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         number = types.getParamValue(record, "number")
         if not number:
             return False
         category = types.getParamValue(record, "cat")
         number = number.replace('F', '')
         if number:
             numberBcd = hextools.encode_BCD(number)
             numberBcd = hextools.bytes2hex(numberBcd)
             numberBcd = types.addTrailingBytes(numberBcd, 0xFF, 3)
         else:
             numberBcd = "FFFFFF"
         dataTmp = numberBcd
         if category:
             raise Exception("Not implemented")
             #TODO: move it to the last byte
             dataTmp += "%02X" % int(category)
         if dataNew:
             dataNew = "%s;%s" % (dataNew, dataTmp)
         else:
             dataNew = dataTmp
     return dataNew
示例#2
0
 def setEfEcc(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         number = types.getParamValue(record, "number")
         if not number:
             return False
         category = types.getParamValue(record, "cat")
         number = number.replace('F','')
         if number:
             numberBcd = hextools.encode_BCD(number)
             numberBcd = hextools.bytes2hex(numberBcd)
             numberBcd = types.addTrailingBytes(numberBcd, 0xFF, 3)
         else:
             numberBcd = "FFFFFF"
         dataTmp = numberBcd
         if category:
             raise Exception("Not implemented")
             #TODO: move it to the last byte
             dataTmp += "%02X" %int(category)
         if dataNew:
             dataNew = "%s;%s" %(dataNew, dataTmp)
         else:
             dataNew = dataTmp
     return dataNew
示例#3
0
 def setEfOpl(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         if not record:
             continue
         mccMnc = types.getParamValue(record, "mcc_mnc")
         if not mccMnc:
             raise Exception("mcc_mnc not provided")
         if len(mccMnc) != 6:
             mnc3 = 'F'
         else:
             mnc3 = mccMnc[5]
         mccMnc = "%s%s%s" % (mccMnc[0:3], mnc3, mccMnc[3:5])
         lacRange = types.getParamValue(record, "lac")
         if not lacRange:
             lacRange = '0000-FFFE'
         lacStart = lacRange.split("-")[0]
         lacEnd = lacRange.split("-")[1]
         pnnId = int(types.getParamValue(record, "pnnId"), 16)
         lai = "%s%04X%04X" % (hextools.bytes2hex(
             hextools.encode_BCD(mccMnc)), int(lacStart, 16), int(
                 lacEnd, 16))
         dataNew += "%s%02X;" % (lai, pnnId)
     return dataNew
示例#4
0
 def setEfPnn(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         if not record:
             continue
         tmpData = []
         infoFull = types.getParamValue(record, "info_full")
         fullName = types.getParamValue(record, "full_name")
         infoShort = types.getParamValue(record, "info_short")
         shortName = types.getParamValue(record, "short_name")
         additionalInfo = types.getParamValue(record, "additional_info")
         if fullName:
             fullNameGsm7 = coder.encodeGsm7(fullName)
             if infoFull:
                 infoByte = int(infoFull, 16)
                 spareBits = infoByte & 0b00000111
                 ci = infoByte >> 3 & 0b00000001
                 dcs = infoByte >> 4 & 0b00000111
                 if dcs != 0x00:
                     raise Exception("Only GSM coding is supported in DCS")
                 ext = infoByte >> 7 & 0b00000001
             else:
                 spareBits = len(fullName) % 8
                 ci = 0  #don't add the letters for the Country's Initials
                 dcs = 0  #GSM
                 ext = 1  #?
                 infoByte = ext << 7 | dcs << 3 | ci << 2 | spareBits
             fullNameGsm7 = "%02X%s" % (infoByte, fullNameGsm7)
             types.addTlv(tmpData, types.FULL_NW_NAME_TAG,
                          hextools.hex2bytes(fullNameGsm7))
         if shortName:
             shortNameGsm7 = coder.encodeGsm7(shortName)
             if infoShort:
                 infoByte = int(infoShort, 16)
                 spareBits = infoByte & 0b00000111
                 ci = infoByte >> 3 & 0b00000001
                 dcs = infoByte >> 4 & 0b00000111
                 if dcs != 0x00:
                     raise Exception("Only GSM coding is supported in DCS")
                 ext = infoByte >> 7 & 0b00000001
             else:
                 spareBits = len(shortName) % 8
                 ci = 0  #don't add the letters for the Country's Initials
                 dcs = 0  #GSM
                 ext = 1  #?
                 infoByte = ext << 7 | dcs << 3 | ci << 2 | spareBits
             shortNameGsm7 = "%02X%s" % (infoByte, shortNameGsm7)
             types.addTlv(tmpData, types.SHORT_NW_NAME_TAG,
                          hextools.hex2bytes(shortNameGsm7))
         if additionalInfo:
             types.addTlv(tmpData, types.ADDITIONAL_INFORMATION_PLMN_TAG,
                          hextools.hex2bytes(additionalInfo))
         dataNew += "%s;" % hextools.bytes2hex(tmpData)
     return dataNew
示例#5
0
 def setEfSpn(self, value):
     name = types.getParamValue(value, "name")
     if not name:
         raise Exception("Name not provided")
     displayByte = types.getParamValue(value, "display")
     if displayByte:
         displayByte = int(displayByte)
     else:
         #display is not provided, set default value
         displayByte = 0x00
     value = "%02X%s" % (displayByte, name.encode('hex'))
     return value
示例#6
0
 def setEfSpn(self, value):
     name = types.getParamValue(value, "name")
     if not name:
         raise Exception("Name not provided")
     displayByte = types.getParamValue(value, "display")
     if displayByte:
         displayByte = int(displayByte)
     else:
         #display is not provided, set default value
         displayByte = 0x00
     value = "%02X%s" %(displayByte, name.encode('hex'))
     return value
示例#7
0
 def setEfPnn(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         if not record:
             continue
         tmpData = []
         infoFull = types.getParamValue(record, "info_full")
         fullName = types.getParamValue(record, "full_name")
         infoShort = types.getParamValue(record, "info_short")
         shortName = types.getParamValue(record, "short_name")
         additionalInfo = types.getParamValue(record, "additional_info")
         if fullName:
             fullNameGsm7 = coder.encodeGsm7(fullName)
             if infoFull:
                 infoByte = int(infoFull, 16)
                 spareBits = infoByte & 0b00000111
                 ci = infoByte >> 3 & 0b00000001
                 dcs = infoByte >> 4 & 0b00000111
                 if dcs != 0x00:
                     raise Exception("Only GSM coding is supported in DCS")
                 ext = infoByte >> 7 & 0b00000001
             else:
                 spareBits = len(fullName) % 8
                 ci = 0 #don't add the letters for the Country's Initials
                 dcs = 0 #GSM
                 ext = 1 #?
                 infoByte = ext << 7 | dcs << 3 | ci << 2 | spareBits
             fullNameGsm7 = "%02X%s" %(infoByte, fullNameGsm7)
             types.addTlv(tmpData, types.FULL_NW_NAME_TAG, hextools.hex2bytes(fullNameGsm7))
         if shortName:
             shortNameGsm7 = coder.encodeGsm7(shortName)
             if infoShort:
                 infoByte = int(infoShort, 16)
                 spareBits = infoByte & 0b00000111
                 ci = infoByte >> 3 & 0b00000001
                 dcs = infoByte >> 4 & 0b00000111
                 if dcs != 0x00:
                     raise Exception("Only GSM coding is supported in DCS")
                 ext = infoByte >> 7 & 0b00000001
             else:
                 spareBits = len(shortName) % 8
                 ci = 0 #don't add the letters for the Country's Initials
                 dcs = 0 #GSM
                 ext = 1 #?
                 infoByte = ext << 7 | dcs << 3 | ci << 2 | spareBits
             shortNameGsm7 = "%02X%s" %(infoByte, shortNameGsm7)
             types.addTlv(tmpData, types.SHORT_NW_NAME_TAG, hextools.hex2bytes(shortNameGsm7))
         if additionalInfo:
             types.addTlv(tmpData, types.ADDITIONAL_INFORMATION_PLMN_TAG, hextools.hex2bytes(additionalInfo))
         dataNew += "%s;" %hextools.bytes2hex(tmpData)
     return dataNew
示例#8
0
 def setEfImpi(self, data):
     impi = types.getParamValue(data, "impi")
     if not impi:
         raise Exception("impi not provided")
     tag = 0x80
     length = len(impi)
     value = "%02X%02X%s" % (tag, length, impi.encode('hex'))
     return value
示例#9
0
 def setEfImpi(self, data):
     impi = types.getParamValue(data, "impi")
     if not impi:
         raise Exception("impi not provided")
     tag = 0x80
     length = len(impi)
     value = "%02X%02X%s" %(tag, length, impi.encode('hex'))
     return value
示例#10
0
 def setEfOpl(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         if not record:
             continue
         mccMnc = types.getParamValue(record, "mcc_mnc")
         if not mccMnc:
             raise Exception("mcc_mnc not provided")
         if len(mccMnc) != 6:
             mnc3 = 'F'
         else:
             mnc3 = mccMnc[5]
         mccMnc = "%s%s%s" %(mccMnc[0:3], mnc3, mccMnc[3:5])
         lacRange = types.getParamValue(record, "lac")
         if not lacRange:
             lacRange = '0000-FFFE'
         lacStart = lacRange.split("-")[0]
         lacEnd = lacRange.split("-")[1]
         pnnId = int(types.getParamValue(record, "pnnId"), 16)
         lai = "%s%04X%04X" %(hextools.bytes2hex(hextools.encode_BCD(mccMnc)), int(lacStart, 16), int(lacEnd, 16))
         dataNew += "%s%02X;" %(lai, pnnId)
     return dataNew
示例#11
0
 def setEfPcscf(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         cscf = types.getParamValue(record, "cscf")
         if not cscf:
             raise Exception("cscf not provided")
         tag = 0x80
         length = len(cscf) + 1
         '''
         Value | Name
         ============
         '00'  | FQDN
         '01'  | IPv4
         '02'  | IPv6
         '''
         addrType = 0x00
         value = "%02X%02X%02X%s" %(tag, length, addrType, cscf.encode('hex'))
         if dataNew:
             dataNew += ";"
         dataNew += value
     return dataNew
示例#12
0
 def setEfPcscf(self, data):
     data = data.split(';')
     dataNew = ''
     for record in data:
         cscf = types.getParamValue(record, "cscf")
         if not cscf:
             raise Exception("cscf not provided")
         tag = 0x80
         length = len(cscf) + 1
         '''
         Value | Name
         ============
         '00'  | FQDN
         '01'  | IPv4
         '02'  | IPv6
         '''
         addrType = 0x00
         value = "%02X%02X%02X%s" % (tag, length, addrType,
                                     cscf.encode('hex'))
         if dataNew:
             dataNew += ";"
         dataNew += value
     return dataNew
示例#13
0
    def setEfLoci(self, data):
        param = "tmsi"
        tmsi = types.getParamValue(data, param)
        if not tmsi:
            raise Exception("%s not provided" % param)

        param = "lai"
        lai = types.getParamValue(data, param)
        if not lai:
            #if lai is not provided, check mcc_mnc and lac
            param = "mcc_mnc"
            mccMnc = types.getParamValue(data, param)
            if not mccMnc:
                raise Exception("%s not provided" % param)
            if len(mccMnc) != 6:
                mnc3 = 'F'
            else:
                mnc3 = mccMnc[5]
            mccMnc = "%s%s%s" % (mccMnc[0:3], mnc3, mccMnc[3:5])

            param = "lac"
            lac = types.getParamValue(data, param)
            if not lac:
                raise Exception("%s not provided" % param)
            lai = "%s%04X" % (hextools.bytes2hex(
                hextools.encode_BCD(mccMnc)), int(lac, 16))
        param = "rfu"
        rfu = types.getParamValue(data, param)
        if not rfu:
            rfu = "FF"

        param = "loc_status"
        locStatus = types.getParamValue(data, param)
        if not locStatus:
            locStatus = "00"

        loci = "%s%s%s%s" % (tmsi, lai, rfu, locStatus)
        return loci
示例#14
0
    def setEfLoci(self, data):
        param = "tmsi"
        tmsi = types.getParamValue(data, param)
        if not tmsi:
            raise Exception("%s not provided" %param)

        param = "lai"
        lai = types.getParamValue(data, param)
        if not lai:
            #if lai is not provided, check mcc_mnc and lac
            param = "mcc_mnc"
            mccMnc = types.getParamValue(data, param)
            if not mccMnc:
                raise Exception("%s not provided" %param)
            if len(mccMnc) != 6:
                mnc3 = 'F'
            else:
                mnc3 = mccMnc[5]
            mccMnc = "%s%s%s" %(mccMnc[0:3], mnc3, mccMnc[3:5])

            param = "lac"
            lac = types.getParamValue(data, param)
            if not lac:
                raise Exception("%s not provided" %param)
            lai = "%s%04X" %(hextools.bytes2hex(hextools.encode_BCD(mccMnc)), int(lac, 16))
        param = "rfu"
        rfu = types.getParamValue(data, param)
        if not rfu:
            rfu = "FF"

        param = "loc_status"
        locStatus = types.getParamValue(data, param)
        if not locStatus:
            locStatus = "00"

        loci = "%s%s%s%s" %(tmsi, lai, rfu, locStatus)
        return loci