Ethereal-dev: [Ethereal-dev] [PATCH] Adding new columns for IEEE 802.11 use

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Jouni Malinen <jkmaline@xxxxxxxxx>
Date: Sat, 3 Jul 2004 23:57:14 -0700
Couple of new columns values would be useful when using Ethereal as a
wireless sniffer. The attached patch adds wireless meta data, TX rate
and RSSI, as new optional column values.

Are there any recommendations or instractions on how to select a format
string for new columns? Now, I just picked up two unique characters, but
this is not very scalable when the number of possible column data
increases.. I would like to add couple of new column fields from the
IEEE 802.11 header (BSSID, seq#, frag#). How should the format string be
selected for these?

-- 
Jouni Malinen                                            PGP id EFC895FA
Index: column.c
===================================================================
RCS file: /cvsroot/ethereal/column.c,v
retrieving revision 1.47
diff -u -p -r1.47 column.c
--- column.c	18 Mar 2004 19:04:30 -0000	1.47
+++ column.c	4 Jul 2004 06:50:32 -0000
@@ -53,7 +53,7 @@ col_format_to_string(gint fmt) {
                      "%rd", "%ud", "%hd", "%rhd", "%uhd", "%nd", "%rnd",
                      "%und", "%S", "%rS", "%uS", "%D", "%rD", "%uD", "%p",
                      "%i", "%L", "%B", "%XO", "%XR", "%I", "%c", "%Xs", 
-                     "%Xd", "%V" };
+                     "%Xd", "%V", "%x", "%e" };
                      
   if (fmt < 0 || fmt > NUM_COL_FMTS)
     return NULL;
@@ -105,6 +105,8 @@ static gchar *dlist[NUM_COL_FMTS] = {
 	"Src PortIdx",
 	"Dst PortIdx",
 	"VSAN",
+	"IEEE 802.11 TX rate",
+	"IEEE 802.11 RSSI",
 };
 
 gchar *
@@ -187,6 +189,12 @@ get_column_format_matches(gboolean *fmt_
     case COL_VSAN:
       fmt_list[COL_VSAN] = TRUE;
       break;
+    case COL_TX_RATE:
+      fmt_list[COL_TX_RATE] = TRUE;
+      break;
+    case COL_RSSI:
+      fmt_list[COL_RSSI] = TRUE;
+      break;
     default:
       break;
   }
@@ -283,6 +291,12 @@ get_column_longest_string(gint format)
     case COL_VSAN:
       return "000000";
       break;
+    case COL_TX_RATE:
+      return "108.0";
+      break;
+    case COL_RSSI:
+      return "100";
+      break;
     default: /* COL_INFO */
       return "Source port: kerberos-master  Destination port: kerberos-master";
       break;
@@ -414,6 +428,12 @@ get_column_format_from_str(gchar *str) {
       case 'V':
         return COL_VSAN;
         break;
+      case 'x':
+        return COL_TX_RATE;
+        break;
+      case 'e':
+        return COL_RSSI;
+        break;
     }
     cptr++;
   }
Index: packet-wlancap.c
===================================================================
RCS file: /cvsroot/ethereal/packet-wlancap.c,v
retrieving revision 1.4
diff -u -p -r1.4 packet-wlancap.c
--- packet-wlancap.c	29 Jan 2004 10:58:28 -0000	1.4
+++ packet-wlancap.c	4 Jul 2004 06:50:37 -0000
@@ -206,6 +206,16 @@ dissect_wlancap(tvbuff_t *tvb, packet_in
     if(check_col(pinfo->cinfo, COL_INFO))
         col_add_fstr(pinfo->cinfo, COL_INFO, "AVS WLAN Capture v%x, Length %d",version, length);
 
+    if (check_col(pinfo->cinfo, COL_TX_RATE)) {
+      guint32 txrate = tvb_get_ntohl(tvb, offset + 32);
+      col_add_fstr(pinfo->cinfo, COL_TX_RATE, "%d.%d",
+		   txrate / 10, txrate % 10);
+    }
+    if (check_col(pinfo->cinfo, COL_RSSI)) {
+      col_add_fstr(pinfo->cinfo, COL_RSSI, "%d",
+		   tvb_get_ntohl(tvb, offset + 48));
+    }
+
     /* Dissect the packet */
     if (tree) {
       ti = proto_tree_add_protocol_format(tree, proto_wlancap,
Index: epan/column_info.h
===================================================================
RCS file: /cvsroot/ethereal/epan/column_info.h,v
retrieving revision 1.12
diff -u -p -r1.12 column_info.h
--- epan/column_info.h	31 Jan 2004 04:10:04 -0000	1.12
+++ epan/column_info.h	4 Jul 2004 06:50:37 -0000
@@ -93,6 +93,8 @@ enum {
   COL_SRCIDX,         /* Src port idx - Cisco MDS-specific */
   COL_DSTIDX,         /* Dst port idx - Cisco MDS-specific */
   COL_VSAN,           /* VSAN - Cisco MDS-specific */
+  COL_TX_RATE,        /* IEEE 802.11 - TX rate in Mbps */
+  COL_RSSI,           /* IEEE 802.11 - received signal strength */
   NUM_COL_FMTS        /* Should always be last */
 };