Skip to content

Commit

Permalink
Fix missing msisdn response in UDA
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkneipp committed Nov 16, 2023
1 parent dffb8d5 commit b4122c9
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions lib/diameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,46 +2207,59 @@ def Answer_16777217_306(self, packet_vars, avps):
msisdn = None
imsi = None
scscf = None
username = None
try:
user_identity_avp = self.get_avp_data(avps, 700)[0]
msisdn = self.get_avp_data(user_identity_avp, 701)[0] #Get MSISDN from AVP in request
self.logTool.log(service='HSS', level='debug', message="Got raw MSISDN with value " + str(msisdn), redisClient=self.redisMessaging)
msisdn = self.TBCD_decode(msisdn)
self.logTool.log(service='HSS', level='debug', message="Got MSISDN with value " + str(msisdn), redisClient=self.redisMessaging)
except:
self.logTool.log(service='HSS', level='error', message="No MSISDN", redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="No MSISDN", redisClient=self.redisMessaging)
try:
username = self.get_avp_data(avps, 601)[0]
except Exception as e:
self.logTool.log(service='HSS', level='error', message="No Username", redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="No Username", redisClient=self.redisMessaging)

if msisdn is not None:
self.logTool.log(service='HSS', level='debug', message="Getting susbcriber IMS info based on MSISDN", redisClient=self.redisMessaging)
subscriber_ims_details = self.database.Get_IMS_Subscriber(msisdn=msisdn)
self.logTool.log(service='HSS', level='debug', message="Got subscriber IMS details: " + str(subscriber_ims_details), redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting susbcriber info based on MSISDN", redisClient=self.redisMessaging)
subscriber_details = self.database.Get_Subscriber(msisdn=msisdn)
imsi = subscriber_details.get('imsi', None)
scscf = subscriber_ims_details.get('scscf', None)
if scscf is not None:
imsUserState = 1
else:
imsUserState = 0
self.logTool.log(service='HSS', level='debug', message="Got subscriber details: " + str(subscriber_details), redisClient=self.redisMessaging)
subscriber_details = {**subscriber_details, **subscriber_ims_details, 'imsUserState': imsUserState}
self.logTool.log(service='HSS', level='debug', message="Merged subscriber details: " + str(subscriber_details), redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting subscriber IMS info based on MSISDN", redisClient=self.redisMessaging)
try:
subscriber_ims_details = self.database.Get_IMS_Subscriber(msisdn=msisdn)
self.logTool.log(service='HSS', level='debug', message="Got subscriber IMS details: " + str(subscriber_ims_details), redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting subscriber info based on MSISDN", redisClient=self.redisMessaging)
subscriber_details = self.database.Get_Subscriber(msisdn=msisdn)
imsi = subscriber_details.get('imsi', None)
scscf = subscriber_ims_details.get('scscf', None)
if scscf is not None:
imsUserState = 1
else:
imsUserState = 0
self.logTool.log(service='HSS', level='debug', message="Got subscriber details: " + str(subscriber_details), redisClient=self.redisMessaging)
subscriber_details = {**subscriber_details, **subscriber_ims_details, 'imsUserState': imsUserState}
self.logTool.log(service='HSS', level='debug', message="Merged subscriber details: " + str(subscriber_details), redisClient=self.redisMessaging)
except Exception as e:
self.logTool.log(service='HSS', level='debug', message=f"No subscriber found for MSISDN {msisdn}", redisClient=self.redisMessaging)
result_code = 5005
#Experimental Result AVP
avp_experimental_result = ''
avp_experimental_result += self.generate_vendor_avp(266, 40, 10415, '') #AVP Vendor ID
avp_experimental_result += self.generate_avp(298, 40, self.int_to_hex(result_code, 4)) #AVP Experimental-Result-Code
avp += self.generate_avp(297, 40, avp_experimental_result) #AVP Experimental-Result(297)
response = self.generate_diameter_packet("01", "40", 306, 16777217, packet_vars['hop-by-hop-identifier'], packet_vars['end-to-end-identifier'], avp) #Generate Diameter packet
return response
else:
self.logTool.log(service='HSS', level='error', message="No MSISDN or IMSI in Answer_16777217_306() input", redisClient=self.redisMessaging)
self.redisMessaging.sendMetric(serviceName='diameter', metricName='prom_diam_auth_event_count',
metricType='counter', metricAction='inc',
metricValue=1.0,
metricLabels={
"diameter_application_id": 16777216,
"diameter_cmd_code": 306,
"event": "Unknown User",
"imsi_prefix": str(username[0:6])},
metricHelp='Diameter Authentication related Counters',
metricExpiry=60)
self.logTool.log(service='HSS', level='error', message="No MSISDN or IMSI in Sh User-Data-Answer input", redisClient=self.redisMessaging)
if username is not None:
self.redisMessaging.sendMetric(serviceName='diameter', metricName='prom_diam_auth_event_count',
metricType='counter', metricAction='inc',
metricValue=1.0,
metricLabels={
"diameter_application_id": 16777216,
"diameter_cmd_code": 306,
"event": "Unknown User",
"imsi_prefix": str(username[0:6])},
metricHelp='Diameter Authentication related Counters',
metricExpiry=60)
result_code = 5005
#Experimental Result AVP
avp_experimental_result = ''
Expand Down Expand Up @@ -2782,11 +2795,11 @@ def Answer_16777291_8388622(self, packet_vars, avps):

try:
if imsi is not None:
self.logTool.log(service='HSS', level='debug', message="Getting susbcriber location based on IMSI", redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting subscriber location based on IMSI", redisClient=self.redisMessaging)
subscriber_details = self.database.Get_Subscriber(imsi=imsi)
self.logTool.log(service='HSS', level='debug', message="Got subscriber_details from IMSI: " + str(subscriber_details), redisClient=self.redisMessaging)
elif msisdn is not None:
self.logTool.log(service='HSS', level='debug', message="Getting susbcriber location based on MSISDN", redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting subscriber location based on MSISDN", redisClient=self.redisMessaging)
subscriber_details = self.database.Get_Subscriber(msisdn=msisdn)
self.logTool.log(service='HSS', level='debug', message="Got subscriber_details from MSISDN: " + str(subscriber_details), redisClient=self.redisMessaging)
except Exception as E:
Expand Down Expand Up @@ -3530,18 +3543,17 @@ def Request_16777217_307(self, msisdn):
avp += self.generate_avp(283, 40, self.OriginRealm) #Destination Realm
avp += self.generate_avp(296, 40, self.OriginRealm) #Origin Realm

self.logTool.log(service='HSS', level='debug', message="Getting susbcriber IMS info based on MSISDN", redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting subscriber IMS info based on MSISDN", redisClient=self.redisMessaging)
subscriber_ims_details = self.database.Get_IMS_Subscriber(msisdn=msisdn)
self.logTool.log(service='HSS', level='debug', message="Got subscriber IMS details: " + str(subscriber_ims_details), redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting susbcriber info based on MSISDN", redisClient=self.redisMessaging)
self.logTool.log(service='HSS', level='debug', message="Getting subscriber info based on MSISDN", redisClient=self.redisMessaging)
subscriber_details = self.database.Get_Subscriber(msisdn=msisdn)
self.logTool.log(service='HSS', level='debug', message="Got subscriber details: " + str(subscriber_details), redisClient=self.redisMessaging)
subscriber_details = {**subscriber_details, **subscriber_ims_details}
self.logTool.log(service='HSS', level='debug', message="Merged subscriber details: " + str(subscriber_details), redisClient=self.redisMessaging)

avp += self.generate_avp(1, 40, str(binascii.hexlify(str.encode(subscriber_details['imsi'])),'ascii')) #Username AVP


#Sh-User-Data (XML)
#This loads a Jinja XML template containing the Sh-User-Data
templateLoader = jinja2.FileSystemLoader(searchpath="./")
Expand Down

0 comments on commit b4122c9

Please sign in to comment.