adapter: Export protocols property
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 27 Apr 2011 15:21:28 +0000 (17:21 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 21 Oct 2011 06:54:01 +0000 (23:54 -0700)
src/adapter.c
test/list-adapters

index a6d4631..56fd917 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <gdbus.h>
 
+#include <linux/nfc.h>
+
 #include "near.h"
 
 static DBusConnection *connection = NULL;
@@ -76,6 +78,50 @@ void __near_adapter_list(DBusMessageIter *iter, void *user_data)
        g_hash_table_foreach(adapter_hash, append_path, iter);
 }
 
+static void append_protocols(DBusMessageIter *iter, void *user_data)
+{
+       struct near_adapter *adapter = user_data;
+       const char *str;
+
+       DBG("protocols 0x%x", adapter->protocols);
+
+       if (adapter->protocols & NFC_PROTO_FELICA) {
+               str = "Felica";
+
+               dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_STRING, &str);
+       }
+
+       if (adapter->protocols & NFC_PROTO_MIFARE) {
+               str = "MIFARE";
+
+               dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_STRING, &str);
+       }
+
+       if (adapter->protocols & NFC_PROTO_JEWEL) {
+               str = "Jewel";
+
+               dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_STRING, &str);
+       }
+
+       if (adapter->protocols & NFC_PROTO_ISO14443_4) {
+               str = "ISO-DEP";
+
+               dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_STRING, &str);
+       }
+
+       if (adapter->protocols & NFC_PROTO_NFC_DEP) {
+               str = "NFC-DEP";
+
+               dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_STRING, &str);
+       }
+}
+
+
 static DBusMessage *get_properties(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -96,6 +142,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
        near_dbus_dict_append_basic(&dict, "Powered",
                                    DBUS_TYPE_BOOLEAN, &adapter->powered);
 
+       near_dbus_dict_append_array(&dict, "Protocols",
+                               DBUS_TYPE_STRING, append_protocols, adapter);
+
        near_dbus_dict_close(&array, &dict);
 
        return reply;
index 23a9ef2..5f10e1a 100755 (executable)
@@ -2,6 +2,14 @@
 
 import dbus
 
+
+def extract_list(list):
+       val = "["
+       for i in list:
+               val += " " + str(i)
+       val += " ]"
+       return val
+
 bus = dbus.SessionBus()
 
 manager = dbus.Interface(bus.get_object("org.neard", "/"),
@@ -24,6 +32,8 @@ for path in properties["Adapters"]:
                 val = "true"
             else:
                 val = "false"
+        elif key in ["Protocols"]:
+            val = extract_list(properties[key])
         else:
             val = str(properties[key])