Instead of converting between 802.11 frequencies and channels umpteen
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 17 Aug 2007 19:34:14 +0000 (19:34 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 17 Aug 2007 19:34:14 +0000 (19:34 +0000)
different ways, add a set of common conversion routines.  Add a
"Frequency/Channel" column and fill it in where we can.  Fix RSSI column
printing in PPI.

Fix up whitespace along the way.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@22538 f5534014-38df-0310-8fa8-9805f1628bb7

16 files changed:
airpcap_loader.c
airpcap_loader.h
epan/Makefile.common
epan/column-utils.c
epan/column.c
epan/column_info.h
epan/dissectors/packet-ppi.c
epan/dissectors/packet-prism.c
epan/dissectors/packet-radiotap.c
epan/dissectors/packet-wlancap.c
epan/frequency-utils.c [new file with mode: 0644]
epan/frequency-utils.h [new file with mode: 0644]
epan/libwireshark.def
gtk/airpcap_dlg.c
gtk/airpcap_gui_utils.c
gtk/main.c

index a93354208d2eed7ea4126f358b5fbcdd638ec6ed..cad8500c73e96cd1b9e4d2657ff98dd6085efdc1 100644 (file)
@@ -46,6 +46,7 @@
 #include <epan/crypt/wep-wpadefs.h>
 #include <epan/crypt/airpdcap_ws.h>
 #include <epan/strutil.h>
+#include <epan/frequency-utils.h>
 #include "capture_ui_utils.h"
 
 #include "simple_dialog.h"
@@ -118,44 +119,6 @@ module_t *wlan_prefs = NULL;
 Dot11Channel *pSupportedChannels;
 ULONG numSupportedChannels;
 
-static Dot11Channel Dot11aChannels[] =
-{
-       {34,  5170, 0},
-       {36,  5180, 0},
-       {38,  5190, 0},
-       {40,  5200, 0},
-       {42,  5210, 0},
-       {44,  5220, 0},
-       {46,  5230, 0},
-       {48,  5240, 0},
-       {52,  5260, 0},
-       {56,  5280, 0},
-       {60,  5300, 0},
-       {64,  5320, 0},
-       {149, 5745, 0},
-       {153, 5765, 0},
-       {157, 5785, 0},
-       {161, 5805, 0},
-};
-
-static Dot11Channel Dot11bChannels[] =
-{
-       {1,  2412, 0},
-       {2,  2417, 0},
-       {3,  2422, 0},
-       {4,  2427, 0},
-       {5,  2432, 0},
-       {6,  2437, 0},
-       {7,  2442, 0},
-       {8,  2447, 0},
-  {9,  2452, 0},
-       {10, 2457, 0},
-       {11, 2462, 0},
-       {12, 2467, 0},
-       {13, 2472, 0},
-       {14, 2484, 0},
-};
-
 static AirpcapChannelInfo LegacyChannels[] =
 {
        {2412, 0, {0,0,0}},
@@ -816,194 +779,112 @@ airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo *
 Dot11Channel*
 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels)
 {
-       AirpcapChannelInfo *chanInfo;
-       ULONG i=0, j=0, numInfo = 0;
-       if (!AirpcapLoaded) return FALSE;
-  if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE) return NULL;
-       numSupportedChannels = 0;
-
-       /*
-        * allocate a bigger array
-        */
-       if (numInfo == 0)
-               return FALSE;
+    AirpcapChannelInfo *chanInfo;
+    ULONG i=0, j=0, numInfo = 0;
 
-       pSupportedChannels = malloc(numInfo * (sizeof *pSupportedChannels));
+    if (!AirpcapLoaded)
+        return FALSE;
+    if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
+        return NULL;
+    numSupportedChannels = 0;
 
-       for (i = 0; i < numInfo; i++)
-       {
-               ULONG supportedChannel = 0xFFFFFFFF;
+    /*
+     * allocate a bigger array
+     */
+    if (numInfo == 0)
+        return NULL;
 
-               /*
-                * search if we have it already
-                */
-               for (j = 0; j < numSupportedChannels; j++)
-               {
-                       if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
-                       {
-                               supportedChannel = j;
-                               break;
-                       }
-               }
+    pSupportedChannels = malloc(numInfo * (sizeof *pSupportedChannels));
 
-               if (supportedChannel == 0xFFFFFFFF)
-               {
-                       /*
-                        * not found, create a new item
-                        */
-                       pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
-
-                       switch(chanInfo[i].ExtChannel)
-                       {
-                       case -1: pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH; break;
-                       case +1: pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW; break;
-                       case 0:
-                       default: pSupportedChannels[numSupportedChannels].Flags = 0;
-                       }
-
-                       /*
-                        * match with the ABG channels
-                        */
-
-                       for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++)
-                       {
-                               if (pSupportedChannels[numSupportedChannels].Frequency == Dot11aChannels[j].Frequency)
-                               {
-                                       pSupportedChannels[numSupportedChannels].Flags |= FLAG_IS_A_CHANNEL;
-                                       pSupportedChannels[numSupportedChannels].Channel = Dot11aChannels[j].Channel;
-                                       break;
-                               }
-                       }
-
-                       for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++)
-                       {
-                               if (pSupportedChannels[numSupportedChannels].Frequency == Dot11bChannels[j].Frequency)
-                               {
-                                       pSupportedChannels[numSupportedChannels].Flags |= FLAG_IS_BG_CHANNEL;
-                                       pSupportedChannels[numSupportedChannels].Channel = Dot11bChannels[j].Channel;
-                                       break;
-                               }
-                       }
-
-                       if ((pSupportedChannels[numSupportedChannels].Flags & (FLAG_IS_BG_CHANNEL | FLAG_IS_A_CHANNEL)) == 0){
-                               pSupportedChannels[numSupportedChannels].Channel = 0;
-                       }
-
-                       numSupportedChannels++;
-               }
-               else
-               {
-                       /*
-                        * just update the ext channel flags
-                        */
-                       switch(chanInfo[i].ExtChannel)
-                       {
-                       case -1: pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH; break;
-                       case +1: pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW; break;
-                       case 0:
-                       default:
-                               break;
-                       }
-               }
-       }
+    for (i = 0; i < numInfo; i++)
+    {
+        ULONG supportedChannel = 0xFFFFFFFF;
+
+        /*
+         * search if we have it already
+         */
+        for (j = 0; j < numSupportedChannels; j++)
+        {
+            if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
+            {
+                supportedChannel = j;
+                break;
+            }
+        }
+
+        if (supportedChannel == 0xFFFFFFFF)
+        {
+            /*
+             * not found, create a new item
+             */
+            pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
+
+            switch(chanInfo[i].ExtChannel)
+            {
+                case -1:
+                    pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
+                    break;
+                case +1:
+                    pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
+                    break;
+                case 0:
+                default:
+                    pSupportedChannels[numSupportedChannels].Flags = 0;
+            }
+
+            /*
+             * Gather channel information
+             */
+
+            pSupportedChannels[numSupportedChannels].Flags |=
+                FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
+                    FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
+            pSupportedChannels[numSupportedChannels].Channel =
+                ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
+            numSupportedChannels++;
+        }
+        else
+        {
+            /*
+             * just update the ext channel flags
+             */
+            switch(chanInfo[i].ExtChannel)
+            {
+                case -1:
+                    pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
+                    break;
+                case +1:
+                    pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
+                    break;
+                case 0:
+                default:
+                    break;
+            }
+        }
+    }
 
-       /*
-        * Now sort the list by frequency
-        */
-       for (i = 0 ; i < numSupportedChannels - 1; i++)
-       {
-               for (j = i + 1; j < numSupportedChannels; j++)
-               {
-                       if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
-                       {
-                               Dot11Channel temp = pSupportedChannels[i];
-                               pSupportedChannels[i] = pSupportedChannels[j];
-                               pSupportedChannels[j] = temp;
-                       }
-               }
-       }
+    if (numSupportedChannels < 1)
+        return NULL;
+    /*
+     * Now sort the list by frequency
+     */
+    for (i = 0 ; i < numSupportedChannels - 1; i++)
+    {
+        for (j = i + 1; j < numSupportedChannels; j++)
+        {
+            if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
+            {
+                Dot11Channel temp = pSupportedChannels[i];
+                pSupportedChannels[i] = pSupportedChannels[j];
+                pSupportedChannels[j] = temp;
+            }
+        }
+    }
 
-       *pNumSupportedChannels = numSupportedChannels;
+    *pNumSupportedChannels = numSupportedChannels;
     return pSupportedChannels;
 }
 
-/*
- * Get channel representation string given a Frequency
- */
-gchar*
-airpcap_get_channelstr_from_freq(ULONG chan_freq){
-       gchar *channelstr;
-       guint j;
-
-       channelstr = (gchar*)g_malloc(sizeof(gchar)*20);
-       for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++)
-       {
-               if (chan_freq == Dot11aChannels[j].Frequency)
-               {
-                       sprintf(channelstr, "%u MHz [A %u]", chan_freq, Dot11aChannels[j].Channel);
-                       return channelstr;
-               }
-       }
-
-       for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++)
-       {
-               if (chan_freq == Dot11bChannels[j].Frequency)
-               {
-                       sprintf(channelstr, "%u MHz [BG %u]", chan_freq, Dot11bChannels[j].Channel);
-                       return channelstr;
-               }
-       }
-
-       sprintf(channelstr, "%u MHz", chan_freq);
-
-       return channelstr;
-}
-
-/*
- * Get channel number given a Frequency
- */
-guint
-airpcap_get_channel_number_from_freq(ULONG chan_freq){
-       guint j;
-
-  for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++){
-               if (chan_freq == Dot11bChannels[j].Frequency){
-                       return Dot11bChannels[j].Channel;
-               }
-       }
-
-       for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++){
-               if (chan_freq == Dot11aChannels[j].Frequency){
-                       return Dot11aChannels[j].Channel;
-               }
-       }
-
-       return 0;
-}
-
-/*
- * Get Frequency given a Channel number
- */
-ULONG
-airpcap_get_freq_from_channel_number(guint chan_number){
-       guint j;
-
-  for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++){
-               if (chan_number == Dot11bChannels[j].Channel){
-                       return Dot11bChannels[j].Frequency;
-               }
-       }
-
-       for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++){
-               if (chan_number == Dot11aChannels[j].Channel){
-                       return Dot11aChannels[j].Frequency;
-               }
-       }
-
-       return 0;
-}
-
-
 /*
  * Airpcap wrapper, used to set the channel of an airpcap adapter
  */
@@ -1023,9 +904,9 @@ airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelIn
     if (!AirpcapLoaded) return FALSE;
     if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
       guint channel = 0;
-      channel = airpcap_get_channel_number_from_freq(ChannelInfo.Frequency);
+      channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
 
-      if (channel == 0){
+      if (channel < 0){
         return FALSE;
       } else {
         return airpcap_if_set_device_channel(ah, channel);
@@ -1057,7 +938,7 @@ airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannel
 
       if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
 
-      chan_freq = airpcap_get_freq_from_channel_number(channel);
+      chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
       if (chan_freq == 0) return FALSE;
       pChannelInfo->Frequency = chan_freq;
 
index 98de26a5f25e69f9f5e59d7736550464df3629ee..f974800dcdef27b856061aab8e0eda4d04577bf2 100644 (file)
@@ -292,24 +292,6 @@ airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo *
 Dot11Channel*
 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels);
 
-/*
- * Get channel representation string given a Frequency
- */
-gchar*
-airpcap_get_channelstr_from_freq(ULONG chan_freq);
-
-/*
- * Get channel number given a Frequency
- */
-guint
-airpcap_get_channel_number_from_freq(ULONG chan_freq);
-
-/*
- * Get Frequency given a Channel number
- */
-ULONG
-airpcap_get_freq_from_channel_number(guint chan_number);
-
 /*
  * Airpcap wrapper, used to set the channel of an airpcap adapter
  */
index 919ebebf257eee54f9cd1257f9ff251226975f60..319651710993260373b596ca003e4ec97a914544 100644 (file)
@@ -52,6 +52,7 @@ LIBWIRESHARK_SRC =            \
        filesystem.c            \
        follow.c                \
        frame_data.c            \
+       frequency-utils.c       \
        funnel.c                \
        gcp.c                   \
        guid-utils.c            \
@@ -167,6 +168,7 @@ LIBWIRESHARK_INCLUDES =     \
        filesystem.h            \
        follow.h                \
        frame_data.h            \
+       frequency-utils.h       \
        funnel.h                \
        garrayfix.h             \
        gcp.h                   \
index 17314931fbe86e5514d1888f62d42cf0973c56e4..2e6d58b197e73161d776431c34207228eb21907b 100644 (file)
@@ -917,10 +917,10 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
 
   pinfo->cinfo->col_expr[col][0] = '\0';
   pinfo->cinfo->col_expr_val[col][0] = '\0';
-  
+
   if (addr->type == AT_NONE)
     return;    /* no address, nothing to do */
-  
+
   if (is_res) {
     get_addr_name_buf(addr, pinfo->cinfo->col_buf[col],COL_MAX_LEN-1);
   } else {
@@ -1329,11 +1329,11 @@ col_fill_in(packet_info *pinfo)
       pinfo->cinfo->col_buf[i][COL_MAX_LEN - 1] = '\0';
       pinfo->cinfo->col_data[i] = pinfo->cinfo->col_buf[i];
       break;
-        
+
     case COL_HPUX_SUBSYS: /* done by nettl disector */
     case COL_HPUX_DEVID:  /* done by nettl disector */
       break;
-        
+
     case COL_DCE_CALL: /* done by dcerpc */
       break;
 
@@ -1342,7 +1342,7 @@ col_fill_in(packet_info *pinfo)
 
     case COL_8021Q_VLAN_ID:
         break;
-    
+
     case COL_DSCP_VALUE:       /* done by packet-ip.c */
        break;
 
@@ -1356,6 +1356,9 @@ col_fill_in(packet_info *pinfo)
     case COL_EXPERT:    /* done by expert.c */
         break;
 
+    case COL_FREQ_CHAN:    /* done by radio dissectors */
+        break;
+
     case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */
       g_assert_not_reached();
       break;
index b6a95c5c0d6cf0444a2a687fd908aca7be1ae803..cc2842a4cb5c8d59ae0940dc6a8a4fcbeb6d3008 100644 (file)
 const gchar *
 col_format_to_string(gint fmt) {
   const gchar *slist[] = {
-       "%m", 
-       "%t",
-       "%Rt",
-       "%At",
-       "%Yt",
-       "%Tt",
-       "%Gt",
-       "%s",
-       "%rs",
-       "%us",
-       "%hs",
-       "%rhs",
-       "%uhs",
-       "%ns",
-       "%rns",
-       "%uns",
-       "%d",
-       "%rd",
-       "%ud",
-       "%hd",
-       "%rhd",
+    "%m",
+    "%t",
+    "%Rt",
+    "%At",
+    "%Yt",
+    "%Tt",
+    "%Gt",
+    "%s",
+    "%rs",
+    "%us",
+    "%hs",
+    "%rhs",
+    "%uhs",
+    "%ns",
+    "%rns",
+    "%uns",
+    "%d",
+    "%rd",
+    "%ud",
+    "%hd",
+    "%rhd",
     "%uhd",
-    "%nd", 
+    "%nd",
     "%rnd",
-       "%und", 
-    "%S", 
-    "%rS", 
-    "%uS", 
-    "%D", 
-    "%rD", 
-    "%uD", 
+    "%und",
+    "%S",
+    "%rS",
+    "%uS",
+    "%D",
+    "%rD",
+    "%uD",
     "%p",
-       "%i", 
-    "%L", 
-    "%B", 
-    "%XO", 
-    "%XR", 
-    "%I", 
-    "%c", 
-    "%Xs", 
-       "%Xd", 
-    "%V", 
-    "%x", 
-    "%e", 
-    "%H", 
-    "%P", 
-    "%y", 
-       "%z",
-       "%q",
-       "%f",
-    "%U",  
+    "%i",
+    "%L",
+    "%B",
+    "%XO",
+    "%XR",
+    "%I",
+    "%c",
+    "%Xs",
+    "%Xd",
+    "%V",
+    "%x",
+    "%e",
+    "%H",
+    "%P",
+    "%y",
+    "%z",
+    "%q",
+    "%f",
+    "%U",
     "%E",
-       "%C",
-       "%l",
-       "%a"
+    "%C",
+    "%l",
+    "%a",
+    "%F"
 };
-                     
+
   if (fmt < 0 || fmt >= NUM_COL_FMTS)
     return NULL;
 
@@ -163,12 +164,13 @@ static const gchar *dlist[NUM_COL_FMTS] = {
        "DCE/RPC call (cn_call_id / dg_seqnum)",    /* COL_DCE_CALL */
        "DCE/RPC context ID (cn_ctx_id)",           /* COL_DCE_CTX */
        "802.1Q VLAN id",                           /* COL_8021Q_VLAN_ID */
-       "IP DSCP Value",                            /* COL_DSCP_VALUE */
-       "L2 COS Value (802.1p)",                    /* COL_COS_VALUE */
+       "IP DSCP Value",                            /* COL_DSCP_VALUE */
+       "L2 COS Value (802.1p)",                    /* COL_COS_VALUE */
        "TEI",                                      /* XXX - why is it missing in column_utils.c and elsewhere? */
-       "Frame Relay DLCI",                                                     /* COL_FR_DLCI */
-       "GPRS BSSGP TLLI",                                                      /* COL_BSSGP_TLLI */
-       "Expert Info Severity",                                     /* COL_EXPERT */
+       "Frame Relay DLCI",                         /* COL_FR_DLCI */
+       "GPRS BSSGP TLLI",                          /* COL_BSSGP_TLLI */
+       "Expert Info Severity",                     /* COL_EXPERT */
+       "Frequency/Channel"                         /* COL_FREQ_CHAN */
 };
 
 const gchar *
@@ -290,12 +292,15 @@ get_column_format_matches(gboolean *fmt_list, gint format) {
     case COL_EXPERT:
       fmt_list[COL_EXPERT] = TRUE;
       break;
+    case COL_FREQ_CHAN:
+      fmt_list[COL_FREQ_CHAN] = TRUE;
+      break;
     default:
       break;
   }
 }
 
-/* Returns a string representing the longest possible value for 
+/* Returns a string representing the longest possible value for
    a timestamp column type. */
 static const char *
 get_timestamp_column_longest_string(gint type, gint precision)
@@ -436,7 +441,7 @@ get_timestamp_column_longest_string(gint type, gint precision)
        return "";
 }
 
-/* Returns the longer string of the column title or the hard-coded width of 
+/* Returns the longer string of the column title or the hard-coded width of
  * its contents for building the packet list layout. */
 const gchar *
 get_column_width_string(gint format, gint col)
@@ -578,6 +583,9 @@ get_column_longest_string(gint format)
     case COL_EXPERT:
       return "ERROR";
       break;
+    case COL_FREQ_CHAN:
+      return "9999 MHz [A 999]";
+      break;
     default: /* COL_INFO */
       return "Source port: kerberos-master  Destination port: kerberos-master";
       break;
@@ -750,6 +758,9 @@ get_column_format_from_str(gchar *str) {
       case 'a':
        return COL_EXPERT;
        break;
+      case 'F':
+       return COL_FREQ_CHAN;
+       break;
     }
     cptr++;
   }
@@ -795,12 +806,12 @@ build_column_format_array(capture_file *cfile, gboolean reset_fences)
     cfile->cinfo.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) *
                                                     COL_MAX_LEN);
   }
-    
+
   for (i = 0; i < cfile->cinfo.num_cols; i++) {
     for (j = 0; j < NUM_COL_FMTS; j++) {
       if (!cfile->cinfo.fmt_matx[i][j])
              continue;
-                   
+
       if (cfile->cinfo.col_first[j] == -1)
         cfile->cinfo.col_first[j] = i;
 
index 4976c3e285f3ad60ac364b97be912752bee394fb..dcc6b0ab29fea4510f1d6ea7fe2834299e26b033 100644 (file)
@@ -112,6 +112,7 @@ enum {
   COL_FR_DLCI,       /* Frame Relay DLCI */
   COL_BSSGP_TLLI,     /* GPRS BSSGP IE TLLI */
   COL_EXPERT,         /* Expert Info */
+  COL_FREQ_CHAN,      /* IEEE 802.11 (and WiMax?) - Channel */
   NUM_COL_FMTS        /* Should always be last */
 };
 
index 7f186fccab1324a53ed6004bc03d456a54d2f1b8..6183fdc73309943e2d59a132c4c82c538324adcc 100644 (file)
@@ -50,6 +50,7 @@
 #include <epan/prefs.h>
 #include <epan/reassemble.h>
 #include <epan/range.h>
+#include <epan/frequency-utils.h>
 
 /* Needed for wtap_pcap_encap_to_wtap_encap().  Should we move it somewhere
  * else? */
 #define IEEE80211_CHAN_2GHZ     0x0080  /* 2 GHz spectrum channel. */
 #define IEEE80211_CHAN_5GHZ     0x0100  /* 5 GHz spectrum channel */
 #define IEEE80211_CHAN_PASSIVE  0x0200  /* Only passive scan allowed */
-#define        IEEE80211_CHAN_DYN      0x0400  /* Dynamic CCK-OFDM channel */
-#define        IEEE80211_CHAN_GFSK     0x0800  /* GFSK channel (FHSS PHY) */
+#define IEEE80211_CHAN_DYN      0x0400  /* Dynamic CCK-OFDM channel */
+#define IEEE80211_CHAN_GFSK     0x0800  /* GFSK channel (FHSS PHY) */
 
 /*
  * Useful combinations of channel characteristics.
@@ -315,41 +316,6 @@ static const value_string vs_80211_common_phy_type[] = {
 };
 /* XXX - End - Copied from packet-radiotap.c */
 
-/* Useful frequency to channel pairings */
-static const value_string vs_80211_chan_freq_flags[] = {
-    {2412, "BG 1"},
-    {2417, "BG 2"},
-    {2422, "BG 3"},
-    {2427, "BG 4"},
-    {2432, "BG 5"},
-    {2437, "BG 6"},
-    {2442, "BG 7"},
-    {2447, "BG 8"},
-    {2452, "BG 9"},
-    {2457, "BG 10"},
-    {2462, "BG 11"},
-    {2467, "BG 12"},
-    {2472, "BG 13"},
-    {2484, "BG 14"},
-    {5170, "A 34"},
-    {5180, "A 36"},
-    {5190, "A 38"},
-    {5200, "A 40"},
-    {5210, "A 42"},
-    {5220, "A 44"},
-    {5230, "A 46"},
-    {5240, "A 48"},
-    {5260, "A 52"},
-    {5280, "A 56"},
-    {5300, "A 60"},
-    {5320, "A 64"},
-    {5745, "A 149"},
-    {5765, "A 153"},
-    {5785, "A 157"},
-    {5805, "A 161"},
-    {0, NULL}
-};
-
 /* Tables for A-MPDU reassembly */
 static GHashTable *ampdu_fragment_table = NULL;
 static GHashTable *ampdu_reassembled_table = NULL;
@@ -461,6 +427,7 @@ dissect_80211_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int of
     gint rate_kbps;
     guint32 common_flags;
     guint16 common_frequency;
+    gchar *chan_str;
 
     if (!tree)
         return;
@@ -504,9 +471,13 @@ dissect_80211_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int of
     ptvcursor_advance(csr, 2);
 
     common_frequency = tvb_get_letohs(ptvcursor_tvbuff(csr), ptvcursor_current_offset(csr));
+    chan_str = ieee80211_mhz_to_str(common_frequency);
     proto_tree_add_uint_format(ptvcursor_tree(csr), hf_80211_common_chan_freq, ptvcursor_tvbuff(csr),
-       ptvcursor_current_offset(csr), 2, common_frequency, "Channel frequency: %u [%s]", common_frequency,
-       val_to_str(common_frequency, (const value_string *) &vs_80211_chan_freq_flags, "Not Defined"));
+       ptvcursor_current_offset(csr), 2, common_frequency, "Channel frequency: %s", chan_str);
+    if (check_col(pinfo->cinfo, COL_FREQ_CHAN)) {
+        col_add_fstr(pinfo->cinfo, COL_FREQ_CHAN, "%s", chan_str);
+    }
+    g_free(chan_str);
     ptvcursor_advance(csr, 2);
 
     ptvcursor_add_with_subtree(csr, hf_80211_common_chan_flags, 2, TRUE,
@@ -525,6 +496,10 @@ dissect_80211_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int of
     ptvcursor_add(csr, hf_80211_common_fhss_hopset, 1, TRUE);
     ptvcursor_add(csr, hf_80211_common_fhss_pattern, 1, TRUE);
 
+    if (check_col(pinfo->cinfo, COL_RSSI)) {
+        col_add_fstr(pinfo->cinfo, COL_RSSI, "%d",
+            (gint8) tvb_get_guint8(tvb, ptvcursor_current_offset(csr)));
+    }
     ptvcursor_add_invalid_check(csr, hf_80211_common_dbm_antsignal, 1, 0x80); /* -128 */
     ptvcursor_add_invalid_check(csr, hf_80211_common_dbm_antnoise, 1, 0x80);
 
@@ -611,10 +586,6 @@ static void dissect_80211n_mac_phy(tvbuff_t *tvb, packet_info *pinfo, proto_tree
     ti = ptvcursor_add(csr, hf_80211n_mac_phy_num_streams, 1, TRUE);
     if (tvb_get_guint8(tvb, ptvcursor_current_offset(csr) - 1) == 0)
         proto_item_append_text(ti, " (unknown)");
-    if (check_col(pinfo->cinfo, COL_RSSI)) {
-        col_add_fstr(pinfo->cinfo, COL_RSSI, "%d",
-            tvb_get_guint8(tvb, ptvcursor_current_offset(csr)));
-    }
     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_combined, 1, 255);
     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant0_ctl, 1, 255);
     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant1_ctl, 1, 255);
@@ -627,8 +598,7 @@ static void dissect_80211n_mac_phy(tvbuff_t *tvb, packet_info *pinfo, proto_tree
 
     ext_frequency = tvb_get_letohs(ptvcursor_tvbuff(csr), ptvcursor_current_offset(csr));
     proto_tree_add_uint_format(ptvcursor_tree(csr), hf_80211n_mac_phy_ext_chan_freq, ptvcursor_tvbuff(csr),
-       ptvcursor_current_offset(csr), 2, ext_frequency, "Ext. Channel frequency: %u [%s]", ext_frequency,
-       val_to_str(ext_frequency, (const value_string *) &vs_80211_chan_freq_flags, "Not Defined"));
+       ptvcursor_current_offset(csr), 2, ext_frequency, "Ext. Channel frequency: %s", ieee80211_mhz_to_str(ext_frequency));
     ptvcursor_advance(csr, 2);
 
     ptvcursor_add_with_subtree(csr, hf_80211n_mac_phy_ext_chan_flags, 2, TRUE,
index 52673afeb3dd6ece5326ef32bda6e7d684549c18..1c37c85f2796711b0bd6f6553b39b4d8c6ce8bbe 100644 (file)
@@ -139,7 +139,7 @@ capture_prism(const guchar *pd, int offset, int len, packet_counts *ld)
     length = pntohl(pd+sizeof(guint32));
 
     /* Handle the new type of capture format */
-    if ((cookie == WLANCAP_MAGIC_COOKIE_V1) || 
+    if ((cookie == WLANCAP_MAGIC_COOKIE_V1) ||
        (cookie == WLANCAP_MAGIC_COOKIE_V2)) {
       if(!BYTES_ARE_IN_FRAME(offset, len, length)) {
         ld->other++;
@@ -163,6 +163,7 @@ capture_prism(const guchar *pd, int offset, int len, packet_counts *ld)
 /*
  * yah, I know, macros, ugh, but it makes the code
  * below more readable
+ * XXX - This should be rewritten to use ptvcursors, then.
  */
 #define IFHELP(size, name, var, str) \
         if(tree) {                                               \
@@ -197,12 +198,12 @@ dissect_prism(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
     /* handle the new capture type. */
     msgcode = tvb_get_ntohl(tvb, offset);
-    if ((msgcode == WLANCAP_MAGIC_COOKIE_V1) || 
+    if ((msgcode == WLANCAP_MAGIC_COOKIE_V1) ||
        (msgcode == WLANCAP_MAGIC_COOKIE_V2)) {
            call_dissector(wlancap_handle, tvb, pinfo, tree);
            return;
     }
-      
+
     tvb_memcpy(tvb, (guint8 *)&hdr, offset, sizeof(hdr));
 
     if(check_col(pinfo->cinfo, COL_PROTOCOL))
@@ -231,6 +232,10 @@ dissect_prism(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
     VALFIELD(hosttime, "Host Time");
     VALFIELD(mactime, "MAC Time");
+    if (hdr.channel.status == 0) {
+      if (check_col(pinfo->cinfo, COL_FREQ_CHAN))
+        col_add_fstr(pinfo->cinfo, COL_FREQ_CHAN, "%u", hdr.channel.data);
+    }
     VALFIELD(channel, "Channel");
     if (hdr.rate.status == 0) {
       if (check_col(pinfo->cinfo, COL_RSSI))
index 211e5a419b304f559e346b26e2e3193402ac1f3a..2aa952b068ab16967cf6329b6c0903275f729274 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <epan/packet.h>
 #include <epan/crc32.h>
+#include <epan/frequency-utils.h>
 #include "packet-ieee80211.h"
 #include "packet-radiotap.h"
 
@@ -637,45 +638,6 @@ proto_register_radiotap(void)
 
 }
 
-/*
- * Convert MHz frequency to IEEE channel number.
- */
-static int
-ieee80211_mhz2ieee(int freq, int flags)
-{
-#define IS_CHAN_IN_PUBLIC_SAFETY_BAND(_c) ((_c) > 4940 && (_c) < 4990)
-    if (flags & IEEE80211_CHAN_2GHZ) {         /* 2GHz band */
-       if (freq == 2484)
-           return 14;
-       if (freq < 2484)
-           return (freq - 2407) / 5;
-       else
-           return 15 + ((freq - 2512) / 20);
-    } else if (flags & IEEE80211_CHAN_5GHZ) {  /* 5Ghz band */
-       if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq))
-           return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400) / 5;
-       if (freq <= 5000)
-           return (freq - 4000) / 5;
-       else
-           return (freq - 5000) / 5;
-    } else {                                   /* either, guess */
-       if (freq == 2484)
-           return 14;
-       if (freq < 2484)
-           return (freq - 2407) / 5;
-       if (freq < 5000) {
-           if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq))
-               return ((freq * 10) + (((freq % 5) == 2) ? 5 : 0) - 49400)/5;
-           else if (freq > 4900)
-               return (freq - 4000) / 5;
-           else
-               return 15 + ((freq - 2512) / 20);
-       }
-       return (freq - 5000) / 5;
-    }
-#undef IS_CHAN_IN_PUBLIC_SAFETY_BAND
-}
-
 static void
 dissect_radiotap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
@@ -695,7 +657,7 @@ dissect_radiotap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     gint8 dbm;
     guint8 db, rflags;
     guint32 present, next_present;
-    int bit, channel;
+    int bit;
 
     if(check_col(pinfo->cinfo, COL_PROTOCOL))
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "WLAN");
@@ -913,6 +875,8 @@ dissect_radiotap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        {
            proto_item *it;
            proto_tree *flags_tree;
+           gchar *chan_str;
+
            align_offset = ALIGN_OFFSET(offset, 2);
            offset += align_offset;
            length_remaining -= align_offset;
@@ -921,17 +885,14 @@ dissect_radiotap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
            if (tree) {
                freq = tvb_get_letohs(tvb, offset);
                flags = tvb_get_letohs(tvb, offset+2);
-               channel = ieee80211_mhz2ieee(freq, flags);
-               if (channel < 1) {
-                       proto_tree_add_uint_format(radiotap_tree, hf_radiotap_channel_frequency,
-                               tvb, offset, 2, freq,
-                               "Channel frequency: %u (invalid)", freq);
-               } else {
-                       proto_tree_add_uint(radiotap_tree, hf_radiotap_channel,
-                               tvb, offset, 2, (guint32) channel);
-                       proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_frequency,
-                               tvb, offset, 2, freq);
+               chan_str = ieee80211_mhz_to_str(freq);
+               if (check_col(pinfo->cinfo, COL_FREQ_CHAN)) {
+                   col_add_fstr(pinfo->cinfo, COL_FREQ_CHAN, "%s", chan_str);
                }
+               proto_tree_add_uint_format(radiotap_tree, hf_radiotap_channel_frequency,
+                               tvb, offset, 2, freq,
+                               "Channel frequency: %s", chan_str);
+               g_free(chan_str);
                /* We're already 2-byte aligned. */
                it = proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_flags,
                        tvb, offset+2, 2, flags);
index 77ba20095ff485bc1c87749bda55ee4e33538bd2..c67a76d17d6d69352b6e0fc999543824ec21b234 100644 (file)
@@ -2,16 +2,16 @@
  *  packet-wlancap.c
  *     Decode packets with a AVS-WLAN header
  *
- *  AVS linux-wlan-based products use a new sniff header to replace the 
+ *  AVS linux-wlan-based products use a new sniff header to replace the
  *  old prism2-specific one dissected in packet-prism2.c.  This one has
- *  additional fields, is designed to be non-hardware-specific, and more 
- *  importantly, version and length fields so it can be extended later 
+ *  additional fields, is designed to be non-hardware-specific, and more
+ *  importantly, version and length fields so it can be extended later
  *  without breaking anything.
  *
  *  See
  *
  *     https://mail.shaftnet.org/chora/browse.php?rt=wlanng&f=trunk%2Fdoc%2Fcapturefrm.txt
- * 
+ *
  * By Solomon Peachy
  *
  * $Id$
@@ -128,10 +128,10 @@ proto_register_wlancap(void)
   static const value_string phy_type[] = {
     { 0, "Unknown" },
     { 1, "FHSS 802.11 '97" },
-    { 2, "DSSS 802.11 '97" }, 
+    { 2, "DSSS 802.11 '97" },
     { 3, "IR Baseband" },
     { 4, "DSSS 802.11b" },
-    { 5, "PBCC 802.11b" }, 
+    { 5, "PBCC 802.11b" },
     { 6, "OFDM 802.11g" },
     { 7, "PBCC 802.11g" },
     { 8, "OFDM 802.11a" },
@@ -167,21 +167,21 @@ proto_register_wlancap(void)
   };
 
   static hf_register_info hf[] = {
-    { &hf_wlan_magic, { "Header magic", "wlancap.magic", FT_UINT32, 
+    { &hf_wlan_magic, { "Header magic", "wlancap.magic", FT_UINT32,
                          BASE_HEX, NULL, 0xFFFFFFF0, "", HFILL } },
-    { &hf_wlan_version, { "Header revision", "wlancap.version", FT_UINT32, 
+    { &hf_wlan_version, { "Header revision", "wlancap.version", FT_UINT32,
                          BASE_DEC, NULL, 0xF, "", HFILL } },
-    { &hf_wlan_length, { "Header length", "wlancap.length", FT_UINT32, 
+    { &hf_wlan_length, { "Header length", "wlancap.length", FT_UINT32,
                         BASE_DEC, NULL, 0x0, "", HFILL } },
-    { &hf_wlan_mactime, { "MAC timestamp", "wlancap.mactime", FT_UINT64, 
+    { &hf_wlan_mactime, { "MAC timestamp", "wlancap.mactime", FT_UINT64,
                          BASE_DEC, NULL, 0x0, "", HFILL } },
-    { &hf_wlan_hosttime, { "Host timestamp", "wlancap.hosttime", FT_UINT64, 
+    { &hf_wlan_hosttime, { "Host timestamp", "wlancap.hosttime", FT_UINT64,
                           BASE_DEC, NULL, 0x0, "", HFILL } },
     { &hf_wlan_phytype, { "PHY type", "wlancap.phytype", FT_UINT32, BASE_DEC,
                          VALS(phy_type), 0x0, "", HFILL } },
     { &hf_wlan_channel, { "Channel", "wlancap.channel", FT_UINT32, BASE_DEC,
                          NULL, 0x0, "", HFILL } },
-    { &hf_wlan_datarate, { "Data rate", "wlancap.datarate", FT_UINT32, 
+    { &hf_wlan_datarate, { "Data rate", "wlancap.datarate", FT_UINT32,
                           BASE_DEC, NULL, 0x0, "", HFILL } },
     { &hf_wlan_antenna, { "Antenna", "wlancap.antenna", FT_UINT32, BASE_DEC,
                          NULL, 0x0, "", HFILL } },
@@ -189,21 +189,21 @@ proto_register_wlancap(void)
                           NULL, 0x0, "", HFILL } },
     { &hf_wlan_ssi_type, { "SSI Type", "wlancap.ssi_type", FT_UINT32, BASE_DEC,
                           VALS(ssi_type), 0x0, "", HFILL } },
-    { &hf_wlan_ssi_signal, { "SSI Signal", "wlancap.ssi_signal", FT_INT32, 
+    { &hf_wlan_ssi_signal, { "SSI Signal", "wlancap.ssi_signal", FT_INT32,
                             BASE_DEC, NULL, 0x0, "", HFILL } },
-    { &hf_wlan_ssi_noise, { "SSI Noise", "wlancap.ssi_noise", FT_INT32, 
+    { &hf_wlan_ssi_noise, { "SSI Noise", "wlancap.ssi_noise", FT_INT32,
                            BASE_DEC, NULL, 0x0, "", HFILL } },
-    { &hf_wlan_preamble, { "Preamble", "wlancap.preamble", FT_UINT32, 
+    { &hf_wlan_preamble, { "Preamble", "wlancap.preamble", FT_UINT32,
                           BASE_DEC, VALS(preamble_type), 0x0, "", HFILL } },
-    { &hf_wlan_encoding, { "Encoding Type", "wlancap.encoding", FT_UINT32, 
+    { &hf_wlan_encoding, { "Encoding Type", "wlancap.encoding", FT_UINT32,
                           BASE_DEC, VALS(encoding_type), 0x0, "", HFILL } },
-    { &hf_wlan_sequence, { "Receive sequence", "wlancap.sequence", FT_UINT32, 
+    { &hf_wlan_sequence, { "Receive sequence", "wlancap.sequence", FT_UINT32,
                           BASE_DEC, NULL, 0x0, "", HFILL } },
-    { &hf_wlan_drops, { "Known Dropped Frames", "wlancap.drops", FT_UINT32, 
+    { &hf_wlan_drops, { "Known Dropped Frames", "wlancap.drops", FT_UINT32,
                           BASE_DEC, NULL, 0x0, "", HFILL } },
-    { &hf_wlan_sniffer_addr, { "Sniffer Address", "wlancap.sniffer_addr", FT_ETHER, 
+    { &hf_wlan_sniffer_addr, { "Sniffer Address", "wlancap.sniffer_addr", FT_ETHER,
                               BASE_NONE, NULL, 0x0, "Sniffer Hardware Address", HFILL } },
-    { &hf_wlan_padding, { "Padding", "wlancap.padding", FT_BYTES, 
+    { &hf_wlan_padding, { "Padding", "wlancap.padding", FT_BYTES,
                          BASE_NONE, NULL, 0x0, "", HFILL } },
   };
   static gint *ett[] = {
@@ -240,14 +240,18 @@ dissect_wlancap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     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_FREQ_CHAN)) {
+      col_add_fstr(pinfo->cinfo, COL_FREQ_CHAN, "%u",
+                  tvb_get_ntohl(tvb, offset + 28));
+    }
     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",
+      col_add_fstr(pinfo->cinfo, COL_TX_RATE, "%u.%u",
                   txrate / 10, txrate % 10);
     }
     if (check_col(pinfo->cinfo, COL_RSSI)) {
       /* XXX cook ssi_signal (Based on type; ie format) */
-      col_add_fstr(pinfo->cinfo, COL_RSSI, "%d",
+      col_add_fstr(pinfo->cinfo, COL_RSSI, "%u",
                   tvb_get_ntohl(tvb, offset + 48));
     }
 
@@ -273,8 +277,8 @@ dissect_wlancap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
       /* XXX - all other 802.11 pseudo-headers use 500Kb/s, not 100Kb/s,
          as the units. */
       datarate = tvb_get_ntohl(tvb, offset);
-      proto_tree_add_uint_format(wlan_tree, hf_wlan_datarate, tvb, offset, 
-                                4, datarate * 100, 
+      proto_tree_add_uint_format(wlan_tree, hf_wlan_datarate, tvb, offset,
+                                4, datarate * 100,
                                 "Data Rate: %u Kb/s", datarate * 100);
       offset+=4;
       proto_tree_add_item(wlan_tree, hf_wlan_antenna, tvb, offset, 4, FALSE);
diff --git a/epan/frequency-utils.c b/epan/frequency-utils.c
new file mode 100644 (file)
index 0000000..aa04f1d
--- /dev/null
@@ -0,0 +1,110 @@
+/* frequency-utils.c
+ * Frequency conversion utility definitions
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2007 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+
+#include "frequency-utils.h"
+
+typedef struct freq_cvt_s {
+    guint fmin;         /* Minimum frequency in MHz */
+    guint fmax;         /* Maximum frequency in MHz */
+    gint cmin;          /* Minimum/base channel */
+    gboolean is_bg;     /* B/G channel? */
+} freq_cvt_t;
+
+#define FREQ_STEP 5     /* MHz. This seems to be consistent, thankfully */
+
+static freq_cvt_t freq_cvt[] = {
+    { 2412, 2472,   1, TRUE },
+    { 2484, 2484,  14, TRUE },
+    { 5000, 5995,   0, FALSE },
+    { 4920, 4995, 240, FALSE }
+};
+
+#define NUM_FREQ_CVT (sizeof(freq_cvt) / sizeof(freq_cvt_t))
+#define MAX_CHANNEL(fc) ( (gint) ((fc.fmax - fc.fmin) / FREQ_STEP) + fc.cmin )
+
+/*
+ * Get channel number given a Frequency
+ */
+gint
+ieee80211_mhz_to_chan(guint freq) {
+    int i;
+
+    for (i = 0; i < NUM_FREQ_CVT; i++) {
+        if (freq >= freq_cvt[i].fmin && freq <= freq_cvt[i].fmax) {
+            return ((freq - freq_cvt[i].fmin) / FREQ_STEP) + freq_cvt[i].cmin;
+        }
+    }
+    return -1;
+}
+
+/*
+ * Get Frequency given a Channel number
+ */
+guint
+ieee80211_chan_to_mhz(gint chan, gboolean is_bg) {
+    int i;
+
+    for (i = 0; i < NUM_FREQ_CVT; i++) {
+        if (is_bg == freq_cvt[i].is_bg &&
+                chan >= freq_cvt[i].cmin && chan <= MAX_CHANNEL(freq_cvt[i])) {
+            return ((chan - freq_cvt[i].cmin) * FREQ_STEP) + freq_cvt[i].fmin;
+        }
+    }
+    return 0;
+}
+
+/*
+ * Get channel representation string given a Frequency
+ */
+gchar*
+ieee80211_mhz_to_str(guint freq){
+    gint chan = ieee80211_mhz_to_chan(freq);
+    gboolean is_bg = FREQ_IS_BG(freq);
+
+    if (chan < 0) {
+        return g_strdup_printf("%u", freq);
+    } else {
+        return g_strdup_printf("%u [%s %u]", freq, is_bg ? "BG" : "A",
+            chan);
+    }
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/epan/frequency-utils.h b/epan/frequency-utils.h
new file mode 100644 (file)
index 0000000..e06c2ea
--- /dev/null
@@ -0,0 +1,73 @@
+/* frequency-utils.h
+ * Frequency conversion utility definitions
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2007 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef __FREQUENCY_UTILS_H__
+#define __FREQUENCY_UTILS_H__
+
+/** @file
+ * Frequency and channel conversion utilities.
+ */
+
+/**
+ * Given a center frequency in MHz, return a channel number.
+ * @param freq Frequency in MHz.
+ * @return The equivalent channel or -1 if no match is found.
+ */
+gint
+ieee80211_mhz_to_chan(guint freq);
+
+/**
+ * Given a channel number and a band type, return a center frequency.
+ * @param chan Channel number
+ * @param is_bg TRUE if the channel is a b/g channel, FALSE otherwise.
+ * @return The equivalent frequency or 0 if no match is found.
+ */
+guint
+ieee80211_chan_to_mhz(gint chan, gboolean is_bg);
+
+/**
+ * Given a frequency in MHz, return a string representation.
+ * @param freq Frequench in MHz.
+ * @return A string showing the frequency, channel number, and type.  The string must be freed with g_free() after use.
+ */
+gchar*
+ieee80211_mhz_to_str(guint freq);
+
+#define FREQ_IS_BG(freq) (freq <= 2484)
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
+
+#endif /* __FREQUENCY_UTILS_H__ */
+
index 2527ac302d6b909a2fb87b881e31b9216b3c5dbe..0755282bdddb93eaa4c74e40a77f702e77569f40 100644 (file)
@@ -470,6 +470,9 @@ host_ip_af
 host_name_lookup_process
 http_dissector_add
 ieee802a_add_oui
+ieee80211_chan_to_mhz
+ieee80211_mhz_to_chan
+ieee80211_mhz_to_str
 incomplete_tcp_stream           DATA
 InfoRequestNakReason_vals       DATA
 init_dissection
index c9c6387f13e4bf31f1f46f153dc74960eb0fa7b3..81f41ea356d6fb8eb3e54680c0b2f07064bea4c0 100644 (file)
@@ -40,6 +40,7 @@
 #include <epan/filesystem.h>
 #include <epan/prefs.h>
 #include <epan/prefs-int.h>
+#include <epan/frequency-utils.h>
 #include <epan/crypt/wep-wpadefs.h>
 
 #include <pcap.h>
@@ -2163,30 +2164,30 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
                       0, 0);
     gtk_misc_set_alignment (GTK_MISC (capture_type_lb), 0, 0.5);
 
-       /* Start: Channel offset label */
-       channel_offset_lb = gtk_label_new ("Channel Offset:");
+    /* Start: Channel offset label */
+    channel_offset_lb = gtk_label_new ("Channel Offset:");
     gtk_widget_set_name (channel_offset_lb, "channel_offset_lb");
     gtk_widget_show (channel_offset_lb);
     gtk_table_attach (GTK_TABLE (basic_parameters_tb), channel_offset_lb, 0, 1, 1, 2,
                       (GtkAttachOptions) (GTK_FILL),
                       (GtkAttachOptions) (0), 0, 0);
     gtk_misc_set_alignment (GTK_MISC (channel_offset_lb), 0, 0.5);
-       /* End: Channel offset label */
+    /* End: Channel offset label */
 
-       /* Start: Channel offset combo box */
-       channel_offset_cb = gtk_combo_new();
-       gtk_widget_set_name (channel_offset_cb, "channel_offset_cb");
-       gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(channel_offset_cb)->entry),FALSE);
+    /* Start: Channel offset combo box */
+    channel_offset_cb = gtk_combo_new();
+    gtk_widget_set_name (channel_offset_cb, "channel_offset_cb");
+    gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(channel_offset_cb)->entry),FALSE);
 
-       airpcap_update_channel_offset_cb(airpcap_if_selected, airpcap_if_selected->channelInfo.Frequency, channel_offset_cb);
-       airpcap_update_channel_offset_combo_entry(channel_offset_cb, airpcap_if_selected->channelInfo.ExtChannel);
+    airpcap_update_channel_offset_cb(airpcap_if_selected, airpcap_if_selected->channelInfo.Frequency, channel_offset_cb);
+    airpcap_update_channel_offset_combo_entry(channel_offset_cb, airpcap_if_selected->channelInfo.ExtChannel);
 
-       gtk_widget_show(channel_offset_cb);
+    gtk_widget_show(channel_offset_cb);
 
-       gtk_table_attach (GTK_TABLE (basic_parameters_tb), channel_offset_cb, 1, 2, 1, 2,
-                      (GtkAttachOptions) (GTK_FILL),
-                      (GtkAttachOptions) (0), 0, 0);
-       /* End: Channel offset combo box */
+    gtk_table_attach (GTK_TABLE (basic_parameters_tb), channel_offset_cb, 1, 2, 1, 2,
+                  (GtkAttachOptions) (GTK_FILL),
+                  (GtkAttachOptions) (0), 0, 0);
+    /* End: Channel offset combo box */
 
     channel_cm = gtk_combo_new ();
     gtk_widget_set_name (channel_cm, "channel_cm");
@@ -2195,12 +2196,12 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
                       (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                       (GtkAttachOptions) (0), 0, 0);
 
-       if (airpcap_if_selected != NULL && airpcap_if_selected->pSupportedChannels != NULL && airpcap_if_selected->numSupportedChannels > 0){
-               for (i = 0; i<(airpcap_if_selected->numSupportedChannels); i++){
-                       channel_cm_items = g_list_append(channel_cm_items, airpcap_get_channelstr_from_freq(airpcap_if_selected->pSupportedChannels[i].Frequency));
-               }
-               gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_cm_items) ;
-       }
+    if (airpcap_if_selected != NULL && airpcap_if_selected->pSupportedChannels != NULL && airpcap_if_selected->numSupportedChannels > 0){
+        for (i = 0; i<(airpcap_if_selected->numSupportedChannels); i++){
+            channel_cm_items = g_list_append(channel_cm_items, ieee80211_mhz_to_str(airpcap_if_selected->pSupportedChannels[i].Frequency));
+        }
+        gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_cm_items);
+    }
 
     /* Select the first entry */
     if (airpcap_if_selected != NULL)
@@ -2227,8 +2228,8 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data)
         g_list_append (capture_type_cm_items, (gpointer) AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO);
 
     if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
-      capture_type_cm_items =
-          g_list_append (capture_type_cm_items, (gpointer) AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI);
+        capture_type_cm_items =
+            g_list_append (capture_type_cm_items, (gpointer) AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI);
     }
     gtk_combo_set_popdown_strings (GTK_COMBO (capture_type_cm),
                                    capture_type_cm_items);
index 27f7a931e37ce52ccc12e4de388e41eb3159dbe1..92316761e3dae927e42d4bc3f0252ea420f0200d 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <epan/filesystem.h>
 #include <epan/strutil.h>
+#include <epan/frequency-utils.h>
 #include <epan/crypt/airpdcap_ws.h>
 
 #include "gtk/main.h"
@@ -63,19 +64,15 @@ gboolean change_airpcap_settings = FALSE;
  * if the adapter passed as parameter is "Any" ... if not,
  * this function returns the only channel number string.
  */
-gchar*
+static gchar*
 airpcap_get_all_channels_list(airpcap_if_info_t* if_info)
 {
     gchar *frequencies;
-    gchar *tmp;
     guint n,i;
     GList *current_item;
     airpcap_if_info_t* current_adapter;
-
-    /* Allocate the string used to store the ASCII representation of the WEP key */
-    frequencies = (gchar*)g_malloc(sizeof(gchar)*128);
-    /* Make sure that the first char is '\0' in order to make g_strlcat() work */
-    frequencies[0]='\0';
+    GString *freq_str = g_string_new("");
+    gchar *sep = "";
 
     if(airpcap_if_is_any(if_info))
     {
@@ -83,23 +80,19 @@ airpcap_get_all_channels_list(airpcap_if_info_t* if_info)
 
         for(i = 0; i < n; i++)
         {
-               current_item = g_list_nth(airpcap_if_list,i);
-               current_adapter = (airpcap_if_info_t*)current_item->data;
-               if(current_adapter != if_info && g_strncasecmp("AirPcap USB wireless capture adapter nr.", current_adapter->description, 40) == 0)
-               {
-                       if (airpcap_get_channel_number_from_freq(current_adapter->channelInfo.Frequency) != 0){
-                               tmp = g_strdup_printf("%d",airpcap_get_channel_number_from_freq(current_adapter->channelInfo.Frequency));
-                       }else{
-                               tmp = g_strdup_printf("%d MHz",current_adapter->channelInfo.Frequency);
-                       }
-                       g_strlcat(frequencies,tmp,128);
-                       g_free(tmp);
-
-                       if(i<(n-1)) g_strlcat(frequencies,",",128);
-               }
-             }
+            current_item = g_list_nth(airpcap_if_list,i);
+            current_adapter = (airpcap_if_info_t*)current_item->data;
+            if(current_adapter != if_info && g_strncasecmp("AirPcap USB wireless capture adapter nr.", current_adapter->description, 40) == 0)
+            {
+                g_string_sprintfa(freq_str, "%s%s", sep,
+                    ieee80211_mhz_to_str(current_adapter->channelInfo.Frequency));
+                sep = ", ";
+            }
+        }
     }
 
+    frequencies = freq_str->str;
+    g_string_free(freq_str, FALSE);
     return frequencies;
 }
 
@@ -170,7 +163,7 @@ airpcap_set_toolbar_start_capture(airpcap_if_info_t* if_info)
                        GList     *channel_list = NULL;
 
                        for (; i<if_info->numSupportedChannels; i++){
-                               channel_list = g_list_append(channel_list, airpcap_get_channelstr_from_freq(if_info->pSupportedChannels[i].Frequency));
+                               channel_list = g_list_append(channel_list, ieee80211_mhz_to_str(if_info->pSupportedChannels[i].Frequency));
                        }
                        gtk_combo_set_popdown_strings( GTK_COMBO(airpcap_toolbar_channel), channel_list);
                        g_list_free(channel_list);
@@ -270,7 +263,7 @@ airpcap_set_toolbar_stop_capture(airpcap_if_info_t* if_info)
                        GList     *channel_list = NULL;
 
                        for (; i<if_info->numSupportedChannels; i++){
-                               channel_list = g_list_append(channel_list, airpcap_get_channelstr_from_freq(if_info->pSupportedChannels[i].Frequency));
+                               channel_list = g_list_append(channel_list, ieee80211_mhz_to_str(if_info->pSupportedChannels[i].Frequency));
                        }
                        gtk_combo_set_popdown_strings( GTK_COMBO(airpcap_toolbar_channel), channel_list);
                        g_list_free(channel_list);
@@ -602,8 +595,8 @@ airpcap_channel_combo_set_by_number(GtkWidget* w,UINT chan_freq)
 {
        gchar *entry_text;
 
-       entry_text = airpcap_get_channelstr_from_freq(chan_freq);
-    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),airpcap_get_channelstr_from_freq(chan_freq));
+       entry_text = ieee80211_mhz_to_str(chan_freq);
+       gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),ieee80211_mhz_to_str(chan_freq));
        g_free(entry_text);
 }
 
@@ -697,21 +690,21 @@ airpcap_if_is_any(airpcap_if_info_t* if_info)
 void
 airpcap_update_channel_combo(GtkWidget* w, airpcap_if_info_t* if_info)
 {
-       gchar* frequency_list;
+    gchar* frequency_list;
 
     if(airpcap_if_is_any(if_info))
     {
-               frequency_list = airpcap_get_all_channels_list(if_info);
-               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),frequency_list);
-               g_free(frequency_list);
-    change_airpcap_settings = FALSE;
-               gtk_widget_set_sensitive(GTK_WIDGET(w),FALSE);
+        frequency_list = airpcap_get_all_channels_list(if_info);
+        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),frequency_list);
+        g_free(frequency_list);
+        change_airpcap_settings = FALSE;
+        gtk_widget_set_sensitive(GTK_WIDGET(w),FALSE);
     }
     else
     {
-               airpcap_channel_combo_set_by_number(w,if_info->channelInfo.Frequency);
-    change_airpcap_settings = TRUE;
-               gtk_widget_set_sensitive(GTK_WIDGET(w),TRUE);
+        airpcap_channel_combo_set_by_number(w,if_info->channelInfo.Frequency);
+        change_airpcap_settings = TRUE;
+        gtk_widget_set_sensitive(GTK_WIDGET(w),TRUE);
     }
 }
 
@@ -721,15 +714,15 @@ airpcap_update_channel_combo(GtkWidget* w, airpcap_if_info_t* if_info)
 void
 airpcap_update_channel_offset_combo_entry(GtkWidget* w, gchar extChannel)
 {
-       gchar channel_offset_value[3];
+    gchar channel_offset_value[3];
 
-       if (extChannel > 0){
-               sprintf(channel_offset_value, "+%d", extChannel);
-       }else{
-               sprintf(channel_offset_value, "%d", extChannel);
-       }
+    if (extChannel > 0){
+        sprintf(channel_offset_value, "+%d", extChannel);
+    }else{
+        sprintf(channel_offset_value, "%d", extChannel);
+    }
 
-       gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry), channel_offset_value);
+    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry), channel_offset_value);
 }
 
 /*
@@ -738,29 +731,29 @@ airpcap_update_channel_offset_combo_entry(GtkWidget* w, gchar extChannel)
 ULONG
 airpcap_load_channel_offset_cb(airpcap_if_info_t* if_info, GtkWidget* channel_offset_cb, ULONG chan_freq)
 {
-       GList *channel_offset_list = NULL;
-
-       if (if_info != NULL && if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
-               guint i = 0;
-
-               for (; i<if_info->numSupportedChannels; i++){
-                       if (if_info->pSupportedChannels[i].Frequency == chan_freq){
-                               if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)){
-                                       channel_offset_list = g_list_append(channel_offset_list, "-1");
-                               }
-                               channel_offset_list = g_list_append(channel_offset_list, "0");
-                               if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)){
-                                       channel_offset_list = g_list_append(channel_offset_list, "+1");
-                               }
-                               gtk_combo_set_popdown_strings( GTK_COMBO(channel_offset_cb), channel_offset_list) ;
-        gtk_widget_set_sensitive(channel_offset_cb, g_list_length(channel_offset_list) > 1);
-                               g_list_free(channel_offset_list);
-                               return if_info->pSupportedChannels[i].Flags;
-                       }
-               }
-       }
+    GList *channel_offset_list = NULL;
+
+    if (if_info != NULL && if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){
+        guint i = 0;
+
+        for (; i<if_info->numSupportedChannels; i++){
+            if (if_info->pSupportedChannels[i].Frequency == chan_freq){
+                if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)){
+                    channel_offset_list = g_list_append(channel_offset_list, "-1");
+                }
+                channel_offset_list = g_list_append(channel_offset_list, "0");
+                if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)){
+                    channel_offset_list = g_list_append(channel_offset_list, "+1");
+                }
+                gtk_combo_set_popdown_strings( GTK_COMBO(channel_offset_cb), channel_offset_list) ;
+                gtk_widget_set_sensitive(channel_offset_cb, g_list_length(channel_offset_list) > 1);
+                g_list_free(channel_offset_list);
+                return if_info->pSupportedChannels[i].Flags;
+            }
+        }
+    }
 
-       return NULL;
+    return NULL;
 }
 
 /*
index 344c24f87cd754a59c495805df293a457746c467..0c0ebbe4ee51a3b796a58f4f04aeda3991e26de0 100644 (file)
@@ -71,6 +71,7 @@
 #include <epan/ex-opt.h>
 #include <epan/funnel.h>
 #include <epan/expert.h>
+#include <epan/frequency-utils.h>
 
 /* general (not GTK specific) */
 #include "file.h"
@@ -4449,23 +4450,23 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
     gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(channel_cm)->entry),FALSE);
     OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY,channel_cm);
 
-       if (airpcap_if_active != NULL && airpcap_if_active->pSupportedChannels != NULL && airpcap_if_active->numSupportedChannels > 0){
-               guint i = 0;
-               for (; i<airpcap_if_active->numSupportedChannels; i++){
-                       channel_list = g_list_append(channel_list, airpcap_get_channelstr_from_freq(airpcap_if_active->pSupportedChannels[i].Frequency));
-               }
-               gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_list) ;
-       }
+    if (airpcap_if_active != NULL && airpcap_if_active->pSupportedChannels != NULL && airpcap_if_active->numSupportedChannels > 0){
+        guint i = 0;
+        for (; i<airpcap_if_active->numSupportedChannels; i++){
+            channel_list = g_list_append(channel_list, ieee80211_mhz_to_str(airpcap_if_active->pSupportedChannels[i].Frequency));
+        }
+        gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_list);
+    }
 
     gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(GTK_COMBO(channel_cm)->entry),
                "Change the 802.11 RF channel", NULL);
 
     WIDGET_SET_SIZE(channel_cm, 120, 28);
 
-       if(airpcap_if_active != NULL)
-        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry), airpcap_get_channelstr_from_freq(airpcap_if_active->channelInfo.Frequency));
-       else
-        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry),"");
+    if(airpcap_if_active != NULL)
+    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry), ieee80211_mhz_to_str(airpcap_if_active->channelInfo.Frequency));
+    else
+    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry),"");
 
     gtk_widget_show(channel_cm);