@Override public boolean hasTgpp2MEID() { Avp terminalInfoAvp = super.message.getAvps().getAvp(Avp.TERMINAL_INFORMATION); if (terminalInfoAvp != null) { try { return terminalInfoAvp.getGrouped().getAvp(Avp.TGPP2_MEID) != null; } catch (AvpDataException ex) { logger.debug("Failure trying to obtain (Terminal-Information) MEID AVP value", ex); } } return false; }
@Override public boolean hasIMEI() { Avp terminalInfoAvp = super.message.getAvps().getAvp(Avp.TERMINAL_INFORMATION); if (terminalInfoAvp != null) { try { return terminalInfoAvp.getGrouped().getAvp(Avp.TGPP_IMEI) != null; } catch (AvpDataException ex) { logger.debug("Failure trying to obtain (Terminal-Information) IMEI AVP value", ex); } } return false; }
@Override public boolean hasSoftwareVersion() { Avp terminalInfoAvp = super.message.getAvps().getAvp(Avp.TERMINAL_INFORMATION); if (terminalInfoAvp != null) { try { return terminalInfoAvp.getGrouped().getAvp(Avp.SOFTWARE_VERSION) != null; } catch (AvpDataException ex) { logger.debug("Failure trying to obtain (Terminal-Information) Software-Version AVP value", ex); } } return false; }
@Override public void validate(Avp avp) throws AvpNotAllowedException { if (isGrouped()) { try { AvpSet avpAsGrouped = avp.getGrouped(); validate(avpAsGrouped); } catch (AvpDataException e) { throw new AvpNotAllowedException("Failed to parse AVP to grouped!", e, code, vendor); } } else { // dont care } }
@Override public String getIMEI() { Avp terminalInfoAvp = super.message.getAvps().getAvp(Avp.TERMINAL_INFORMATION); if (terminalInfoAvp != null) { try { Avp imei = terminalInfoAvp.getGrouped().getAvp(Avp.TGPP_IMEI); if (imei != null) { return imei.getUTF8String(); } } catch (AvpDataException ex) { logger.debug("Failure trying to obtain (Terminal-Information) IMEI AVP value", ex); } } return null; }
@Override public String getSoftwareVersion() { Avp terminalInfoAvp = super.message.getAvps().getAvp(Avp.TERMINAL_INFORMATION); if (terminalInfoAvp != null) { try { Avp softwareVersion = terminalInfoAvp.getGrouped().getAvp(Avp.SOFTWARE_VERSION); if (softwareVersion != null) { return softwareVersion.getUTF8String(); } } catch (AvpDataException ex) { logger.debug("Failure trying to obtain (Terminal-Information) Software-Version AVP value", ex); } } return null; }
@Override public byte[] getTgpp2MEID() { Avp terminalInfoAvp = super.message.getAvps().getAvp(Avp.TERMINAL_INFORMATION); if (terminalInfoAvp != null) { try { Avp meid = terminalInfoAvp.getGrouped().getAvp(Avp.TGPP2_MEID); if (meid != null) { return meid.getOctetString(); } } catch (AvpDataException ex) { logger.debug("Failure trying to obtain (Terminal-Information) MEID AVP value", ex); } } return null; }
private boolean isSuccess(IMessage message) throws AvpDataException { Avp resultAvp = message.getResultCode(); if (resultAvp == null) { resultAvp = message.getAvps().getAvp(Avp.EXPERIMENTAL_RESULT); if (resultAvp == null) { // bad message, ignore if (logger.isDebugEnabled()) { logger.debug("Discarding message since SSL handshake has not been performed on [{}], dropped message [{}]. No result type avp.", socketDescription, message); } // TODO: anything else? return false; } resultAvp = resultAvp.getGrouped().getAvp(Avp.EXPERIMENTAL_RESULT_CODE); if (resultAvp == null) { // bad message, ignore if (logger.isDebugEnabled()) { logger.debug("Discarding message since SSL handshake has not been performed on [{}], dropped message [{}]. No result avp.", socketDescription, message); } } } long resultCode = resultAvp.getUnsigned32(); return resultCode >= 2000 && resultCode < 3000; }
for (Avp subAvp : avp.getGrouped()) { avpStringSB.append(printAvp(subAvp, indent + " "));
public byte[] encodeAvpSet(AvpSet avps) { //ByteArrayOutputStream out = new ByteArrayOutputStream(); DynamicByteArray dba = new DynamicByteArray(0); try { //DataOutputStream data = new DataOutputStream(out); for (Avp a : avps) { if (a instanceof AvpImpl) { AvpImpl aImpl = (AvpImpl) a; if (aImpl.rawData.length == 0 && aImpl.groupedData != null) { aImpl.rawData = encodeAvpSet(a.getGrouped()); } //data.write(newEncodeAvp(aImpl)); dba.add(encodeAvp(aImpl)); } } } catch (Exception e) { e.printStackTrace(); logger.debug("Error during encode avps", e); } return dba.getResult(); }
AvpImpl(Avp avp) { avpCode = avp.getCode(); vendorID = avp.getVendorId(); isMandatory = avp.isMandatory(); isEncrypted = avp.isEncrypted(); isVendorSpecific = avp.isVendorId(); try { rawData = avp.getRaw(); if (rawData == null || rawData.length == 0) { groupedData = avp.getGrouped(); } } catch (AvpDataException e) { logger.debug("Can not create Avp", e); } }
@Override public Avp getResultCodeAvp() throws AvpDataException { Avp resultCodeAvp = message.getAvps().getAvp(Avp.RESULT_CODE); if (resultCodeAvp != null) { return resultCodeAvp; } resultCodeAvp = message.getAvps().getAvp(Avp.EXPERIMENTAL_RESULT); if (resultCodeAvp != null) { return resultCodeAvp.getGrouped().getAvp(Avp.EXPERIMENTAL_RESULT_CODE); } return null; } }
/** * Identifies if a certain message is of Acct or Auth type. * * @param message * @param type * @return */ private boolean isMessageOfType(Message message, int type) { try { Avp vendorSpecificAvp = null; if(message.getAvps().getAvp(type) != null) { return true; } else if((vendorSpecificAvp = message.getAvps().getAvp(DiameterAvpCodes.VENDOR_SPECIFIC_APPLICATION_ID)) != null) { // 6.11. Vendor-Specific-Application-Id AVP // The Vendor-Specific-Application-Id AVP (AVP Code 260) is of type Grouped and is used to // advertise support of a vendor-specific Diameter Application. // Exactly one of the Auth-Application-Id and Acct-Application-Id AVPs MAY be present. return vendorSpecificAvp.getGrouped().getAvp(type) != null; } } catch (Exception ignore) { // ignore this... say it isn't } return false; }
/** * Identifies if a certain message is of Acct or Auth type. * * @param message * @param type * @return */ private boolean isMessageOfType(Message message, int type) { try { Avp vendorSpecificAvp = null; if(message.getAvps().getAvp(type) != null) { return true; } else if((vendorSpecificAvp = message.getAvps().getAvp(DiameterAvpCodes.VENDOR_SPECIFIC_APPLICATION_ID)) != null) { // 6.11. Vendor-Specific-Application-Id AVP // The Vendor-Specific-Application-Id AVP (AVP Code 260) is of type Grouped and is used to // advertise support of a vendor-specific Diameter Application. // Exactly one of the Auth-Application-Id and Acct-Application-Id AVPs MAY be present. return vendorSpecificAvp.getGrouped().getAvp(type) != null; } } catch (Exception ignore) { // ignore this... say it isn't } return false; }
for (Avp aSpecAppId : specAppId) { long vendorId = 0, acctApplicationId = 0, authApplicationId = 0; AvpSet avps = (aSpecAppId).getGrouped(); for (Avp localAvp : avps) { if (localAvp.getCode() == Avp.VENDOR_ID) {
private DiameterAvp[] getAvpsInternal(AvpSet set) throws Exception { List<DiameterAvp> avps = new ArrayList<DiameterAvp>(); for (Avp a : set) { AvpRepresentation avpRep = AvpDictionary.INSTANCE.getAvp(a.getCode(), a.getVendorId()); if (avpRep == null) { //log.error("Avp with code: " + a.getCode() + " VendorId: " + a.getVendorId() + " is not listed in dictionary, skipping!"); continue; } else { if (avpRep.getType().equals("Grouped")) { // TODO: There's no info about if AVP has mandatory or protected flags set... GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw()); gAVP.setExtensionAvps(getAvpsInternal(a.getGrouped())); // This is a grouped AVP... let's make it like that. avps.add(gAVP); } else { // TODO: There's no info about if AVP has mandatory or protected flags set... avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw(), DiameterAvpType.fromString(avpRep.getType()))); } } } return avps.toArray(new DiameterAvp[avps.size()]); }
private DiameterAvp[] getAvpsInternal(AvpSet set) throws Exception { List<DiameterAvp> avps = new ArrayList<DiameterAvp>(); for (Avp a : set) { AvpRepresentation avpRep = AvpDictionary.INSTANCE.getAvp(a.getCode(), a.getVendorId()); if (avpRep == null) { //log.error("Avp with code: " + a.getCode() + " VendorId: " + a.getVendorId() + " is not listed in dictionary, skipping!"); continue; } else { if (avpRep.getType().equals("Grouped")) { // TODO: There's no info about if AVP has mandatory or protected flags set... GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw()); gAVP.setExtensionAvps(getAvpsInternal(a.getGrouped())); // This is a grouped AVP... let's make it like that. avps.add(gAVP); } else { // TODO: There's no info about if AVP has mandatory or protected flags set... avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw(), DiameterAvpType.fromString(avpRep.getType()))); } } } return avps.toArray(new DiameterAvp[avps.size()]); }
if(avpRep != null) { if(avpRep.isGrouped()) { AvpSet grouped = a.getGrouped(); // warning, this changes getRaw to return byte[0] if successful GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw()); AvpSet grouped = a.getGrouped(); // warning, this changes getRaw to return byte[0] if successful GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
if(avpRep != null) { if(avpRep.isGrouped()) { AvpSet grouped = a.getGrouped(); // warning, this changes getRaw to return byte[0] if successful GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw()); AvpSet grouped = a.getGrouped(); // warning, this changes getRaw to return byte[0] if successful GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
getGrouped().getAvp(Avp.VENDOR_ID).getUnsigned32());