nfctool: sniffer: Output the MIME type value
authorSamuel Ortiz <sameo@linux.intel.com>
Thu, 13 Jun 2013 14:45:55 +0000 (16:45 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 13 Jun 2013 15:16:26 +0000 (17:16 +0200)
This is needed for handover sniffing.

tools/nfctool/ndef-decode.c

index 8910f56..94694bc 100644 (file)
 
 #define ndef_printf_error(fmt, ...) print_indent(NDEF_MSG_INDENT, COLOR_ERROR, \
                                                fmt, ## __VA_ARGS__)
+enum record_tnf {
+       RECORD_TNF_EMPTY     = 0x00,
+       RECORD_TNF_WELLKNOWN = 0x01,
+       RECORD_TNF_MIME      = 0x02,
+       RECORD_TNF_URI       = 0x03,
+       RECORD_TNF_EXTERNAL  = 0x04,
+       RECORD_TNF_UNKNOWN   = 0x05,
+       RECORD_TNF_UNCHANGED = 0x06,
+};
 
 static gchar *tnf_str[] = {
        "Empty (0x00)",
@@ -53,7 +62,8 @@ static gchar *tnf_str[] = {
 int ndef_print_records(guint8 *data, guint32 data_len)
 {
        gboolean mb, me, cf, sr, il;
-       guint8 tnf;
+       enum record_tnf tnf;
+       char *mime_string;
        guint8 type_len;
        guint8 *type;
        guint32 payload_len;
@@ -162,10 +172,25 @@ int ndef_print_records(guint8 *data, guint32 data_len)
                        ndef_printf_msg("ID Length: %u", id_len);
 
                if (type) {
-                       ndef_printf_msg("Type:");
-
-                       sniffer_print_hexdump(stdout, type, type_len,
-                                             NDEF_HEX_INDENT, FALSE);
+                       switch (tnf) {
+                       case RECORD_TNF_MIME:
+                               mime_string = g_try_malloc(type_len + 1);
+                               if (mime_string != NULL) {
+                                       g_snprintf(mime_string,
+                                               type_len + 1, "%s", type);
+
+                                       ndef_printf_msg("Type: %s", mime_string);
+                                       g_free(mime_string);
+                                       break;
+                               }
+
+                       default:
+                               ndef_printf_msg("Type:");
+                               sniffer_print_hexdump(stdout, type, type_len,
+                                                       NDEF_HEX_INDENT, FALSE);
+
+                               break;
+                       }
                }
 
                if (id) {