Skip to content

Commit

Permalink
Handle -k better on platforms that don't support it.
Browse files Browse the repository at this point in the history
Have ws80211_init() return an indication that channel setting isn't
supported on those platforms.

In dumpcap, try to set up ws80211 before checking the channel argument
and, if it fails, report the failure, rather than failing because the
"convert channel name to channel code" routine fails.

See

    https://ask.wireshark.org/question/15535/dumpcap-k-is-not-accepting-channel-type-values/

for an example of confusion caused by the previous behavior.

Change-Id: I303f560704700bbcd4f0ecea041f8632744212f3
Reviewed-on: https://code.wireshark.org/review/36659
Petri-Dish: Guy Harris <[email protected]>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <[email protected]>
  • Loading branch information
guyharris committed Apr 1, 2020
1 parent 8e50074 commit 0975bf7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
8 changes: 4 additions & 4 deletions caputils/ws80211_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int ws80211_init(void)
state->have_split_wiphy = TRUE;
#endif /* HAVE_NL80211_SPLIT_WIPHY_DUMP */

return 0;
return WS80211_INIT_OK;

out_handle_destroy:
nl_socket_free(state->nl_sock);
Expand Down Expand Up @@ -933,9 +933,9 @@ const char *ws80211_get_helper_path(void) {
int ws80211_init(void)
{
if (airpcap_get_dll_state() == AIRPCAP_DLL_OK) {
return 0;
return WS80211_INIT_OK;
}
return -1;
return WS80211_INIT_NOT_SUPPORTED;
}

static const char *airpcap_dev_prefix_ = "\\\\.\\";
Expand Down Expand Up @@ -1198,7 +1198,7 @@ const char *ws80211_get_helper_path(void)
#else /* Everyone else. */
int ws80211_init(void)
{
return -1;
return WS80211_INIT_NOT_SUPPORTED;
}

GArray* ws80211_find_interfaces(void)
Expand Down
7 changes: 6 additions & 1 deletion caputils/ws80211_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ struct ws80211_iface_info {
* On Windows this checks the AirPcap status. It does *not* load the
* AirPcap DLL. That happens when the program starts.
*
* @return 0 on success, an error value on failure.
* @return WS80211_INIT_OK on success, WS80211_INIT_NOT_SUPPORTED if the
* 802.11 environment isn't supported, or the negative of an errno value
* on failure.
*/
#define WS80211_INIT_OK 0
#define WS80211_INIT_NOT_SUPPORTED 1

int ws80211_init(void);

/** Build a list of 802.11 interfaces.
Expand Down
19 changes: 12 additions & 7 deletions dumpcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4464,7 +4464,18 @@ set_80211_channel(const char *iface, const char *opt)
gchar **options = NULL;

options = g_strsplit_set(opt, ",", 4);
for (args = 0; options[args]; args++);
for (args = 0; options[args]; args++)
;

ret = ws80211_init();
if (ret != WS80211_INIT_OK) {
if (ret == WS80211_INIT_NOT_SUPPORTED)
cmdarg_err("Setting 802.11 channels is not supported on this platform");
else
cmdarg_err("Failed to init ws80211: %s", g_strerror(abs(ret)));
ret = 2;
goto out;
}

if (options[0])
freq = get_nonzero_guint32(options[0], "802.11 channel frequency");
Expand All @@ -4484,12 +4495,6 @@ set_80211_channel(const char *iface, const char *opt)
if (args >= 3 && options[3])
center_freq2 = get_nonzero_guint32(options[3], "VHT center frequency 2");

ret = ws80211_init();
if (ret) {
cmdarg_err("%d: Failed to init ws80211: %s\n", abs(ret), g_strerror(abs(ret)));
ret = 2;
goto out;
}
ret = ws80211_set_freq(iface, freq, type, center_freq1, center_freq2);

if (ret) {
Expand Down
2 changes: 1 addition & 1 deletion ui/qt/wireless_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ WirelessFrame::WirelessFrame(QWidget *parent) :

ui->helperToolButton->hide();

if (ws80211_init() == 0) {
if (ws80211_init() == WS80211_INIT_OK) {
ui->stackedWidget->setEnabled(true);
ui->stackedWidget->setCurrentWidget(ui->interfacePage);

Expand Down

0 comments on commit 0975bf7

Please sign in to comment.