From: Tobias Brunner Date: Thu, 25 Apr 2013 15:31:54 +0000 (+0200) Subject: android: Add enum types for PENs and attribute types X-Git-Tag: 5.1.0dr2~2^2~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=28c268d7073d2c5d6ce81dd4bed23d3439aa14fd;p=thirdparty%2Fstrongswan.git android: Add enum types for PENs and attribute types --- diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java new file mode 100644 index 0000000000..8d915142a0 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2013 Tobias Brunner + * Copyright (C) 2012 Christoph Buehler + * Copyright (C) 2012 Patrick Loetscher + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package org.strongswan.android.logic.imc.attributes; + +public enum AttributeType +{ + IETF_TESTING(PrivateEnterpriseNumber.IETF, 0), + IETF_ATTRIBUTE_REQUEST(PrivateEnterpriseNumber.IETF, 1), + IETF_PRODUCT_INFORMATION(PrivateEnterpriseNumber.IETF, 2), + IETF_NUMERIC_VERSION(PrivateEnterpriseNumber.IETF, 3), + IETF_STRING_VERSION(PrivateEnterpriseNumber.IETF, 4), + IETF_OPERATIONAL_STATUS(PrivateEnterpriseNumber.IETF, 5), + IETF_PORT_FILTER(PrivateEnterpriseNumber.IETF, 6), + IETF_INSTALLED_PACKAGES(PrivateEnterpriseNumber.IETF, 7), + IETF_PA_TNC_ERROR(PrivateEnterpriseNumber.IETF, 8), + IETF_ASSESSMENT_RESULT(PrivateEnterpriseNumber.IETF, 9), + IETF_REMEDIATION_INSTRUCTIONS(PrivateEnterpriseNumber.IETF, 10), + IETF_FORWARDING_ENABLED(PrivateEnterpriseNumber.IETF, 11), + IETF_FACTORY_DEFAULT_PWD_ENABLED(PrivateEnterpriseNumber.IETF, 12), + IETF_RESERVED(PrivateEnterpriseNumber.IETF, 0xffffffff); + + private PrivateEnterpriseNumber mVendor; + private int mType; + + /** + * Enum type for vendor specific attributes (defined in their namespace) + * + * @param vendor private enterprise number of vendor + * @param type vendor specific attribute type + */ + private AttributeType(PrivateEnterpriseNumber vendor, int type) + { + mVendor = vendor; + mType = type; + } + + /** + * Get private enterprise number of vendor + * + * @return PEN + */ + public PrivateEnterpriseNumber getVendor() + { + return mVendor; + } + + /** + * Get vendor specific type + * + * @return type + */ + public int getType() + { + return mType; + } + + /** + * Get the enum entry from the given numeric values, if defined + * + * @param vendor vendor id + * @param type vendor specific type + * @return enum entry or null + */ + public static AttributeType fromValues(int vendor, int type) + { + PrivateEnterpriseNumber pen = PrivateEnterpriseNumber.fromValue(vendor); + + if (pen == null) + { + return null; + } + for (AttributeType attr : AttributeType.values()) + { + if (attr.mVendor == pen && attr.mType == type) + { + return attr; + } + } + return null; + } +} diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java new file mode 100644 index 0000000000..f014d69a77 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 Tobias Brunner + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package org.strongswan.android.logic.imc.attributes; + +public enum PrivateEnterpriseNumber +{ + IETF(0x000000), + UNASSIGNED(0xfffffe), + RESERVED(0xffffff); + + private int mValue; + + /** + * Enum for private enterprise numbers (PEN) as allocated by IANA + * + * @param value numeric value + */ + private PrivateEnterpriseNumber(int value) + { + mValue = value; + } + + /** + * Get the numeric value of a PEN + * + * @return numeric value + */ + public int getValue() + { + return mValue; + } + + /** + * Get the enum entry from a numeric value, if defined + * + * @param value numeric value + * @return the enum entry or null + */ + public static PrivateEnterpriseNumber fromValue(int value) + { + for (PrivateEnterpriseNumber pen : PrivateEnterpriseNumber.values()) + { + if (pen.mValue == value) + { + return pen; + } + } + return null; + } +}