]> git.ipfire.org Git - thirdparty/iw.git/blobdiff - util.c
iw: free memory on scan parse errors
[thirdparty/iw.git] / util.c
diff --git a/util.c b/util.c
index 39a533e64819eca6ae3434e375119f0625cd14ca..411fea1b7d818cfcdb277804feb9ec49bc902124 100644 (file)
--- a/util.c
+++ b/util.c
@@ -133,6 +133,7 @@ static const char *ifmodes[NL80211_IFTYPE_MAX + 1] = {
        "P2P-client",
        "P2P-GO",
        "P2P-device",
+       "outside context of a BSS",
 };
 
 static char modebuf[100];
@@ -240,6 +241,25 @@ static const char *commands[NL80211_CMD_MAX + 1] = {
        [NL80211_CMD_START_P2P_DEVICE] = "start_p2p_device",
        [NL80211_CMD_STOP_P2P_DEVICE] = "stop_p2p_device",
        [NL80211_CMD_CONN_FAILED] = "conn_failed",
+       [NL80211_CMD_SET_MCAST_RATE] = "set_mcast_rate",
+       [NL80211_CMD_SET_MAC_ACL] = "set_mac_acl",
+       [NL80211_CMD_RADAR_DETECT] = "radar_detect",
+       [NL80211_CMD_GET_PROTOCOL_FEATURES] = "get_protocol_features",
+       [NL80211_CMD_UPDATE_FT_IES] = "update_ft_ies",
+       [NL80211_CMD_FT_EVENT] = "ft_event",
+       [NL80211_CMD_CRIT_PROTOCOL_START] = "crit_protocol_start",
+       [NL80211_CMD_CRIT_PROTOCOL_STOP] = "crit_protocol_stop",
+       [NL80211_CMD_GET_COALESCE] = "get_coalesce",
+       [NL80211_CMD_SET_COALESCE] = "set_coalesce",
+       [NL80211_CMD_CHANNEL_SWITCH] = "channel_switch",
+       [NL80211_CMD_VENDOR] = "vendor",
+       [NL80211_CMD_SET_QOS_MAP] = "set_qos_map",
+       [NL80211_CMD_ADD_TX_TS] = "add_tx_ts",
+       [NL80211_CMD_DEL_TX_TS] = "del_tx_ts",
+       [NL80211_CMD_GET_MPP] = "get_mpp",
+       [NL80211_CMD_JOIN_OCB] = "join_ocb",
+       [NL80211_CMD_LEAVE_OCB] = "leave_ocb",
+       [NL80211_CMD_CH_SWITCH_STARTED_NOTIFY] = "ch_switch_started_notify",
 };
 
 static char cmdbuf[100];
@@ -252,34 +272,50 @@ const char *command_name(enum nl80211_commands cmd)
        return cmdbuf;
 }
 
-int ieee80211_channel_to_frequency(int chan)
+int ieee80211_channel_to_frequency(int chan, enum nl80211_band band)
 {
-       if (chan < 14)
-               return 2407 + chan * 5;
-
-       if (chan == 14)
-               return 2484;
-
-       /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
-       return (chan + 1000) * 5;
+       /* see 802.11 17.3.8.3.2 and Annex J
+        * there are overlapping channel numbers in 5GHz and 2GHz bands */
+       if (chan <= 0)
+               return 0; /* not supported */
+       switch (band) {
+       case NL80211_BAND_2GHZ:
+               if (chan == 14)
+                       return 2484;
+               else if (chan < 14)
+                       return 2407 + chan * 5;
+               break;
+       case NL80211_BAND_5GHZ:
+               if (chan >= 182 && chan <= 196)
+                       return 4000 + chan * 5;
+               else
+                       return 5000 + chan * 5;
+               break;
+       case NL80211_BAND_60GHZ:
+               if (chan < 5)
+                       return 56160 + chan * 2160;
+               break;
+       default:
+               ;
+       }
+       return 0; /* not supported */
 }
 
 int ieee80211_frequency_to_channel(int freq)
 {
+       /* see 802.11-2007 17.3.8.3.2 and Annex J */
        if (freq == 2484)
                return 14;
-
-       if (freq < 2484)
+       else if (freq < 2484)
                return (freq - 2407) / 5;
-
-       /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
-       if (freq < 45000)
-               return freq/5 - 1000;
-
-       if (freq >= 58320 && freq <= 64800)
+       else if (freq >= 4910 && freq <= 4980)
+               return (freq - 4000) / 5;
+       else if (freq <= 45000) /* DMG band lower limit */
+               return (freq - 5000) / 5;
+       else if (freq >= 58320 && freq <= 64800)
                return (freq - 56160) / 2160;
-
-       return 0;
+       else
+               return 0;
 }
 
 void print_ssid_escaped(const uint8_t len, const uint8_t *data)
@@ -566,7 +602,7 @@ void print_ht_mcs(const __u8 *mcs)
        unsigned int tx_max_num_spatial_streams, max_rx_supp_data_rate;
        bool tx_mcs_set_defined, tx_mcs_set_equal, tx_unequal_modulation;
 
-       max_rx_supp_data_rate = ((mcs[10] >> 8) & ((mcs[11] & 0x3) << 8));
+       max_rx_supp_data_rate = (mcs[10] | ((mcs[11] & 0x3) << 8));
        tx_mcs_set_defined = !!(mcs[12] & (1 << 0));
        tx_mcs_set_equal = !(mcs[12] & (1 << 1));
        tx_max_num_spatial_streams = ((mcs[12] >> 2) & 3) + 1;
@@ -600,3 +636,90 @@ void print_ht_mcs(const __u8 *mcs)
                printf("\t\tHT TX MCS rate indexes are undefined\n");
        }
 }
+
+void print_vht_info(__u32 capa, const __u8 *mcs)
+{
+       __u16 tmp;
+       int i;
+
+       printf("\t\tVHT Capabilities (0x%.8x):\n", capa);
+
+#define PRINT_VHT_CAPA(_bit, _str) \
+       do { \
+               if (capa & BIT(_bit)) \
+                       printf("\t\t\t" _str "\n"); \
+       } while (0)
+
+       printf("\t\t\tMax MPDU length: ");
+       switch (capa & 3) {
+       case 0: printf("3895\n"); break;
+       case 1: printf("7991\n"); break;
+       case 2: printf("11454\n"); break;
+       case 3: printf("(reserved)\n");
+       }
+       printf("\t\t\tSupported Channel Width: ");
+       switch ((capa >> 2) & 3) {
+       case 0: printf("neither 160 nor 80+80\n"); break;
+       case 1: printf("160 MHz\n"); break;
+       case 2: printf("160 MHz, 80+80 MHz\n"); break;
+       case 3: printf("(reserved)\n");
+       }
+       PRINT_VHT_CAPA(4, "RX LDPC");
+       PRINT_VHT_CAPA(5, "short GI (80 MHz)");
+       PRINT_VHT_CAPA(6, "short GI (160/80+80 MHz)");
+       PRINT_VHT_CAPA(7, "TX STBC");
+       /* RX STBC */
+       PRINT_VHT_CAPA(11, "SU Beamformer");
+       PRINT_VHT_CAPA(12, "SU Beamformee");
+       /* compressed steering */
+       /* # of sounding dimensions */
+       PRINT_VHT_CAPA(19, "MU Beamformer");
+       PRINT_VHT_CAPA(20, "MU Beamformee");
+       PRINT_VHT_CAPA(21, "VHT TXOP PS");
+       PRINT_VHT_CAPA(22, "+HTC-VHT");
+       /* max A-MPDU */
+       /* VHT link adaptation */
+       PRINT_VHT_CAPA(28, "RX antenna pattern consistency");
+       PRINT_VHT_CAPA(29, "TX antenna pattern consistency");
+
+       printf("\t\tVHT RX MCS set:\n");
+       tmp = mcs[0] | (mcs[1] << 8);
+       for (i = 1; i <= 8; i++) {
+               printf("\t\t\t%d streams: ", i);
+               switch ((tmp >> ((i-1)*2) ) & 3) {
+               case 0: printf("MCS 0-7\n"); break;
+               case 1: printf("MCS 0-8\n"); break;
+               case 2: printf("MCS 0-9\n"); break;
+               case 3: printf("not supported\n"); break;
+               }
+       }
+       tmp = mcs[2] | (mcs[3] << 8);
+       printf("\t\tVHT RX highest supported: %d Mbps\n", tmp & 0x1fff);
+
+       printf("\t\tVHT TX MCS set:\n");
+       tmp = mcs[4] | (mcs[5] << 8);
+       for (i = 1; i <= 8; i++) {
+               printf("\t\t\t%d streams: ", i);
+               switch ((tmp >> ((i-1)*2) ) & 3) {
+               case 0: printf("MCS 0-7\n"); break;
+               case 1: printf("MCS 0-8\n"); break;
+               case 2: printf("MCS 0-9\n"); break;
+               case 3: printf("not supported\n"); break;
+               }
+       }
+       tmp = mcs[6] | (mcs[7] << 8);
+       printf("\t\tVHT TX highest supported: %d Mbps\n", tmp & 0x1fff);
+}
+
+void iw_hexdump(const char *prefix, const __u8 *buf, size_t size)
+{
+       int i;
+
+       printf("%s: ", prefix);
+       for (i = 0; i < size; i++) {
+               if (i && i % 16 == 0)
+                       printf("\n%s: ", prefix);
+               printf("%02x ", buf[i]);
+       }
+       printf("\n\n");
+}