summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2012-10-25 18:58:06 +0200
committerArron Wang <arron.wang@intel.com>2013-07-09 08:26:19 +0800
commit304e7dcaf536a11625a1694a19228e38babb3611 (patch)
treea99cf2b719471400ca490a79820a042288f26f76
parent04e9d5867181807acae3b89f8ebc1f517c246933 (diff)
downloadneard-304e7dcaf536a11625a1694a19228e38babb3611.tar.gz
neard-304e7dcaf536a11625a1694a19228e38babb3611.tar.bz2
neard-304e7dcaf536a11625a1694a19228e38babb3611.zip
ndef: Support RAW ndef writes
Change-Id: I21a341b2482556458e381b4a3033ef3e9313194c
-rw-r--r--doc/tag-api.txt2
-rw-r--r--src/ndef.c61
-rwxr-xr-xtest/write-tag11
3 files changed, 74 insertions, 0 deletions
diff --git a/doc/tag-api.txt b/doc/tag-api.txt
index b13a90c..579e02e 100644
--- a/doc/tag-api.txt
+++ b/doc/tag-api.txt
@@ -29,6 +29,8 @@ Method dict GetProperties()
record type and is described by the Record properties.
For example, one would add a type, a Language, an
Encoding and a Representation for a text record.
+ To push raw NDEF, one should use the NDEF key and use
+ an array of bytes for the NDEF stream.
Possible Errors: org.neard.Error.PermissionDenied
org.neard.Error.InvalidArguments
diff --git a/src/ndef.c b/src/ndef.c
index 641f5df..4cf5199 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -3339,6 +3339,64 @@ static struct near_ndef_message *build_mime_record(DBusMessage *msg)
return NULL;
}
+static struct near_ndef_message * build_raw_ndef(DBusMessage *msg)
+{
+ DBusMessageIter iter, arr_iter;
+ struct near_ndef_message *ndef;
+
+ DBG("");
+
+ ndef = NULL;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_recurse(&iter, &arr_iter);
+
+ while (dbus_message_iter_get_arg_type(&arr_iter) !=
+ DBUS_TYPE_INVALID) {
+ const char *key;
+ DBusMessageIter ent_iter;
+ DBusMessageIter var_iter;
+
+ dbus_message_iter_recurse(&arr_iter, &ent_iter);
+ dbus_message_iter_get_basic(&ent_iter, &key);
+ dbus_message_iter_next(&ent_iter);
+ dbus_message_iter_recurse(&ent_iter, &var_iter);
+
+ switch (dbus_message_iter_get_arg_type(&var_iter)) {
+ case DBUS_TYPE_ARRAY:
+ if (g_strcmp0(key, "NDEF") == 0) {
+ DBusMessageIter array;
+ uint8_t *data;
+ int data_size;
+
+ dbus_message_iter_recurse(&var_iter, &array);
+ dbus_message_iter_get_fixed_array(&array,
+ &data,
+ &data_size);
+
+ ndef = g_try_malloc0(data_size);
+ if (ndef == NULL)
+ break;
+
+ ndef->data = g_try_malloc0(data_size);
+ if (ndef->data == NULL) {
+ g_free(ndef);
+ break;
+ }
+
+ ndef->length = data_size;
+ memcpy(ndef->data, data, data_size);
+ }
+
+ break;
+ }
+
+ dbus_message_iter_next(&arr_iter);
+ }
+
+ return ndef;
+}
+
struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg)
{
DBusMessageIter iter;
@@ -3393,6 +3451,9 @@ struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg)
} else if (g_strcmp0(value, "MIME") == 0) {
ndef = build_mime_record(msg);
break;
+ } else if (g_strcmp0(value, "Raw") == 0) {
+ ndef = build_raw_ndef(msg);
+ break;
} else {
near_error("%s not supported", value);
ndef = NULL;
diff --git a/test/write-tag b/test/write-tag
index 3635ff7..32ce67a 100755
--- a/test/write-tag
+++ b/test/write-tag
@@ -21,6 +21,7 @@ def help_text():
print "e.g. < %s /org/neard/nfc0/tag0 E-Mail test@test.com >" % (sys.argv[0])
print "e.g. < %s /org/neard/nfc0/tag0 MIME wifi_wsc YourAPname passphrase >" % (sys.argv[0])
print "e.g. < %s /org/neard/nfc0/tag0 MIME wifi_wsc YourAPname >" % (sys.argv[0])
+ print "e.g. < %s /org/neard/nfc0/tag0 Raw <NDEF_file> >" % (sys.argv[0])
sys.exit(1)
@@ -72,5 +73,15 @@ elif sys.argv[2] in ["MIME"]:
else:
help_text()
+elif sys.argv[2] in ["Raw"]:
+ ndef = file(sys.argv[3]).read().rsplit(' ')
+ ndef_stream = bytearray()
+
+ for b in ndef:
+ ndef_stream.append(int(b, 16))
+
+ tag.Write(({ "Type" : "Raw",
+ "NDEF" : dbus.ByteArray(ndef_stream) }))
+
else:
help_text()