android: Add measurement collector for Product Information
authorTobias Brunner <tobias@strongswan.org>
Fri, 26 Apr 2013 12:29:00 +0000 (14:29 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:27 +0000 (18:49 +0200)
src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java
src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java
src/frontends/android/src/org/strongswan/android/logic/imc/attributes/ProductInformationAttribute.java [new file with mode: 0644]
src/frontends/android/src/org/strongswan/android/logic/imc/collectors/ProductInformationCollector.java [new file with mode: 0644]

index 2aec690..828b99d 100644 (file)
@@ -18,6 +18,7 @@ package org.strongswan.android.logic.imc;
 import org.strongswan.android.logic.imc.attributes.Attribute;
 import org.strongswan.android.logic.imc.attributes.AttributeType;
 import org.strongswan.android.logic.imc.collectors.Collector;
+import org.strongswan.android.logic.imc.collectors.ProductInformationCollector;
 import org.strongswan.android.logic.imc.collectors.StringVersionCollector;
 
 import android.content.Context;
@@ -46,6 +47,9 @@ public class AndroidImc
 
                switch (attributeType)
                {
+                       case IETF_PRODUCT_INFORMATION:
+                               collector = new ProductInformationCollector();
+                               break;
                        case IETF_STRING_VERSION:
                                collector = new StringVersionCollector();
                                break;
index f014d69..5af20a8 100644 (file)
@@ -18,6 +18,7 @@ package org.strongswan.android.logic.imc.attributes;
 public enum PrivateEnterpriseNumber
 {
        IETF(0x000000),
+       GOOGLE(0x002B79),
        UNASSIGNED(0xfffffe),
        RESERVED(0xffffff);
 
diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/ProductInformationAttribute.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/ProductInformationAttribute.java
new file mode 100644 (file)
index 0000000..cace18d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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;
+
+import org.strongswan.android.utils.BufferedByteWriter;
+
+/**
+ * PA-TNC Product Information attribute (see section 4.2.2 of RFC 5792)
+ *
+ *                       1                   2                   3
+ *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |               Product Vendor ID               |  Product ID   |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  |  Product ID   |         Product Name (Variable Length)        |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+public class ProductInformationAttribute implements Attribute
+{
+       private final String PRODUCT_NAME = "Android";
+       private final short PRODUCT_ID = 0;
+
+       @Override
+       public byte[] getEncoding()
+       {
+               BufferedByteWriter writer = new BufferedByteWriter();
+               writer.put24(PrivateEnterpriseNumber.GOOGLE.getValue());
+               writer.put16(PRODUCT_ID);
+               writer.put(PRODUCT_NAME.getBytes());
+               return writer.toByteArray();
+       }
+}
diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/ProductInformationCollector.java b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/ProductInformationCollector.java
new file mode 100644 (file)
index 0000000..c377e90
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.collectors;
+
+import org.strongswan.android.logic.imc.attributes.Attribute;
+import org.strongswan.android.logic.imc.attributes.ProductInformationAttribute;
+
+public class ProductInformationCollector implements Collector
+{
+       @Override
+       public Attribute getMeasurement()
+       {       /* this is currently hardcoded in the attribute */
+               return new ProductInformationAttribute();
+       }
+}