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
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;
} 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;
print " Type is MIME, parameters are wifi_wsc <ssid> <passphrase>"
print " If type is MIME, and WiFi AP is open network"
print " Type is MIME, parameters are wifi_wsc <ssid>"
+ print " If type is RAW, parameters are Raw <NDEF_file>"
print "e.g. < %s /org/neard/nfc0/tag0 Text UTF-8 en-US hello,NFC! >" % (sys.argv[0])
print "e.g. < %s /org/neard/nfc0/tag0 URI http://www.nfc-forum.com >" % (sys.argv[0])
print "e.g. < %s /org/neard/nfc0/tag0 SmartPoster http://www.nfc-forum.com >" % (sys.argv[0])
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)
"MIME" : "application/vnd.wfa.wsc",
"SSID" : sys.argv[5],
"Passphrase" : sys.argv[6] }))
+
+ elif sys.argv[3] in ["Raw"]:
+ ndef = file(sys.argv[4]).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:
usage()