diff --git a/daemon/core.c b/daemon/core.c index 8505464..e0ed819 100644 --- a/daemon/core.c +++ b/daemon/core.c @@ -282,7 +282,8 @@ void awdl_switch_channel(struct ev_loop *loop, ev_timer *timer, int revents) { if (chan_num_new && (chan_num_new != chan_num_old)) { log_debug("switch channel to %d (slot %d)", chan_num_new, slot); - set_channel(state->io.wlan_ifindex, chan_num_new); + if (!state->io.wlan_is_file) + set_channel(state->io.wlan_ifindex, chan_num_new); awdl_state->channel.current = chan_new; } diff --git a/daemon/io.c b/daemon/io.c index 340bd33..06be564 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -104,6 +104,25 @@ static int open_nonblocking_device(const char *dev, pcap_t **pcap_handle, const return fd; } +static int open_savefile(const char *filename, pcap_t **pcap_handle) { + char errbuf[PCAP_ERRBUF_SIZE]; + int fd; + + pcap_t *handle = pcap_open_offline(filename, errbuf); + if (!handle) { + log_error("pcap: unable to open savefile (%s)", errbuf); + return -1; + } + + if ((fd = pcap_get_selectable_fd(handle)) == -1) { + log_error("pcap: unable to get fd"); + return -1; + } + + *pcap_handle = handle; + + return fd; +} static int open_tun(char *dev, const struct ether_addr *self) { #ifndef __APPLE__ @@ -240,12 +259,30 @@ static int open_tun(char *dev, const struct ether_addr *self) { #endif /* __APPLE__ */ } -int io_state_init(struct io_state *state, const char *wlan, const char *host, const struct ether_addr *bssid_filter) { +static int io_state_init_wlan_try_savefile(struct io_state *state) { + int err; + + state->wlan_fd = open_savefile(state->wlan_ifname, &state->wlan_handle); + if ((err = state->wlan_fd) < 0) { + log_trace("Could not open device or file: %s", state->wlan_ifname); + return err; + } + state->wlan_is_file = 1; + state->wlan_ifindex = 0; + + return 0; +} + +static int io_state_init_wlan(struct io_state *state, const char *wlan, const struct ether_addr *bssid_filter) { int err; - /* setup WLAN interface */ strcpy(state->wlan_ifname, wlan); + if (!io_state_init_wlan_try_savefile(state)) { + log_info("Using savefile instead of device"); + return 0; + } + state->wlan_ifindex = if_nametoindex(state->wlan_ifname); if (!state->wlan_ifindex) { log_error("No such interface exists %s", state->wlan_ifname); @@ -269,18 +306,22 @@ int io_state_init(struct io_state *state, const char *wlan, const char *host, co return err; } state->wlan_fd = open_nonblocking_device(state->wlan_ifname, &state->wlan_handle, bssid_filter); - if ((err = state->wlan_fd) < 0) { + if (state->wlan_fd < 0) { log_error("Could not open device: %s", state->wlan_ifname); return err; } - err = link_ether_addr_get(state->wlan_ifname, &state->if_ether_addr); if (err < 0) { log_error("Could not get LLC address from %s", state->wlan_ifname); return err; } - /* setup host interface */ + return 0; +} + +static int io_state_init_host(struct io_state *state, const char *host) { + int err; + if (strlen(host) > 0) { strcpy(state->host_ifname, host); /* Host interface needs to have same ether_addr, to make active (!) monitor mode work */ @@ -301,6 +342,18 @@ int io_state_init(struct io_state *state, const char *wlan, const char *host, co return 0; } +int io_state_init(struct io_state *state, const char *wlan, const char *host, const struct ether_addr *bssid_filter) { + int err; + + if (!(err = io_state_init_wlan(state, wlan, bssid_filter))) + return err; + + if (!(err = io_state_init_host(state, host))) + return err; + + return 0; +} + void io_state_free(struct io_state *state) { close(state->host_fd); pcap_close(state->wlan_handle); diff --git a/daemon/io.h b/daemon/io.h index 865e3ca..e02cd7e 100644 --- a/daemon/io.h +++ b/daemon/io.h @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef __APPLE__ #include @@ -32,7 +33,7 @@ struct io_state { pcap_t *wlan_handle; - char wlan_ifname[IFNAMSIZ]; /* name of WLAN iface */ + char wlan_ifname[PATH_MAX]; /* name of WLAN iface */ int wlan_ifindex; /* index of WLAN iface */ char host_ifname[IFNAMSIZ]; /* name of host iface */ int host_ifindex; /* index of host iface */ @@ -41,6 +42,7 @@ struct io_state { int host_fd; char *dumpfile; char wlan_no_monitor_mode; + int wlan_is_file; }; int io_state_init(struct io_state *state, const char *wlan, const char *host, const struct ether_addr *bssid_filter); diff --git a/daemon/owl.c b/daemon/owl.c index 6fecb16..7d8b67e 100644 --- a/daemon/owl.c +++ b/daemon/owl.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) { int filter_rssi = 1; int no_monitor_mode = 0; - char wlan[IFNAMSIZ]; + char wlan[PATH_MAX]; char host[IFNAMSIZ] = DEFAULT_AWDL_DEVICE; struct ev_loop *loop;